UNPKG

4.41 kBTypeScriptView Raw
1import { EventEmitter } from '@angular/core';
2import * as i0 from '@angular/core';
3import { InjectionToken } from '@angular/core';
4import { NgZone } from '@angular/core';
5import { OnDestroy } from '@angular/core';
6
7/** Injection token that can be used to provide the default options to `CdkCopyToClipboard`. */
8export declare const CDK_COPY_TO_CLIPBOARD_CONFIG: InjectionToken<CdkCopyToClipboardConfig>;
9
10/**
11 * Provides behavior for a button that when clicked copies content into user's
12 * clipboard.
13 */
14export declare class CdkCopyToClipboard implements OnDestroy {
15 private _clipboard;
16 private _ngZone;
17 /** Content to be copied. */
18 text: string;
19 /**
20 * How many times to attempt to copy the text. This may be necessary for longer text, because
21 * the browser needs time to fill an intermediate textarea element and copy the content.
22 */
23 attempts: number;
24 /**
25 * Emits when some text is copied to the clipboard. The
26 * emitted value indicates whether copying was successful.
27 */
28 readonly copied: EventEmitter<boolean>;
29 /** Copies that are currently being attempted. */
30 private _pending;
31 /** Whether the directive has been destroyed. */
32 private _destroyed;
33 /** Timeout for the current copy attempt. */
34 private _currentTimeout;
35 constructor(_clipboard: Clipboard_2, _ngZone: NgZone, config?: CdkCopyToClipboardConfig);
36 /** Copies the current text to the clipboard. */
37 copy(attempts?: number): void;
38 ngOnDestroy(): void;
39 static ɵfac: i0.ɵɵFactoryDeclaration<CdkCopyToClipboard, [null, null, { optional: true; }]>;
40 static ɵdir: i0.ɵɵDirectiveDeclaration<CdkCopyToClipboard, "[cdkCopyToClipboard]", never, { "text": { "alias": "cdkCopyToClipboard"; "required": false; }; "attempts": { "alias": "cdkCopyToClipboardAttempts"; "required": false; }; }, { "copied": "cdkCopyToClipboardCopied"; }, never, never, false, never>;
41}
42
43/** Object that can be used to configure the default options for `CdkCopyToClipboard`. */
44export declare interface CdkCopyToClipboardConfig {
45 /** Default number of attempts to make when copying text to the clipboard. */
46 attempts?: number;
47}
48
49/**
50 * A service for copying text to the clipboard.
51 */
52declare class Clipboard_2 {
53 private readonly _document;
54 constructor(document: any);
55 /**
56 * Copies the provided text into the user's clipboard.
57 *
58 * @param text The string to copy.
59 * @returns Whether the operation was successful.
60 */
61 copy(text: string): boolean;
62 /**
63 * Prepares a string to be copied later. This is useful for large strings
64 * which take too long to successfully render and be copied in the same tick.
65 *
66 * The caller must call `destroy` on the returned `PendingCopy`.
67 *
68 * @param text The string to copy.
69 * @returns the pending copy operation.
70 */
71 beginCopy(text: string): PendingCopy;
72 static ɵfac: i0.ɵɵFactoryDeclaration<Clipboard_2, never>;
73 static ɵprov: i0.ɵɵInjectableDeclaration<Clipboard_2>;
74}
75export { Clipboard_2 as Clipboard }
76
77export declare class ClipboardModule {
78 static ɵfac: i0.ɵɵFactoryDeclaration<ClipboardModule, never>;
79 static ɵmod: i0.ɵɵNgModuleDeclaration<ClipboardModule, [typeof i1.CdkCopyToClipboard], never, [typeof i1.CdkCopyToClipboard]>;
80 static ɵinj: i0.ɵɵInjectorDeclaration<ClipboardModule>;
81}
82
83declare namespace i1 {
84 export {
85 CdkCopyToClipboardConfig,
86 CDK_COPY_TO_CLIPBOARD_CONFIG,
87 CdkCopyToClipboard
88 }
89}
90
91
92/**
93 * A pending copy-to-clipboard operation.
94 *
95 * The implementation of copying text to the clipboard modifies the DOM and
96 * forces a re-layout. This re-layout can take too long if the string is large,
97 * causing the execCommand('copy') to happen too long after the user clicked.
98 * This results in the browser refusing to copy. This object lets the
99 * re-layout happen in a separate tick from copying by providing a copy function
100 * that can be called later.
101 *
102 * Destroy must be called when no longer in use, regardless of whether `copy` is
103 * called.
104 */
105export declare class PendingCopy {
106 private readonly _document;
107 private _textarea;
108 constructor(text: string, _document: Document);
109 /** Finishes copying the text. */
110 copy(): boolean;
111 /** Cleans up DOM changes used to perform the copy operation. */
112 destroy(): void;
113}
114
115export { }