index.d.ts 4.0 KB

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