index.d.ts 4.3 KB

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