blob: 6d3e577bd15e32c5a1c82f8b01c25b8fcffe4a34 [file] [log] [blame]
{"version":3,"file":"cdk-clipboard.umd.js","sources":["../../../../../src/cdk/clipboard/pending-copy.ts","../../../../../src/cdk/clipboard/clipboard.ts","../../../../../src/cdk/clipboard/copy-to-clipboard.ts","../../../../../src/cdk/clipboard/clipboard-module.ts","../../../../../src/cdk/clipboard/public-api.ts","../../../../../src/cdk/clipboard/index.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\n/**\n * A pending copy-to-clipboard operation.\n *\n * The implementation of copying text to the clipboard modifies the DOM and\n * forces a relayout. This relayout can take too long if the string is large,\n * causing the execCommand('copy') to happen too long after the user clicked.\n * This results in the browser refusing to copy. This object lets the\n * relayout happen in a separate tick from copying by providing a copy function\n * that can be called later.\n *\n * Destroy must be called when no longer in use, regardless of whether `copy` is\n * called.\n */\nexport class PendingCopy {\n private _textarea: HTMLTextAreaElement|undefined;\n\n constructor(text: string, private readonly _document: Document) {\n const textarea = this._textarea = this._document.createElement('textarea');\n const styles = textarea.style;\n\n // Hide the element for display and accessibility. Set a fixed position so the page layout\n // isn't affected. We use `fixed` with `top: 0`, because focus is moved into the textarea\n // for a split second and if it's off-screen, some browsers will attempt to scroll it into view.\n styles.position = 'fixed';\n styles.top = styles.opacity = '0';\n styles.left = '-999em';\n textarea.setAttribute('aria-hidden', 'true');\n textarea.value = text;\n this._document.body.appendChild(textarea);\n }\n\n /** Finishes copying the text. */\n copy(): boolean {\n const textarea = this._textarea;\n let successful = false;\n\n try { // Older browsers could throw if copy is not supported.\n if (textarea) {\n const currentFocus = this._document.activeElement as HTMLOrSVGElement | null;\n\n textarea.select();\n textarea.setSelectionRange(0, textarea.value.length);\n successful = this._document.execCommand('copy');\n\n if (currentFocus) {\n currentFocus.focus();\n }\n }\n } catch {\n // Discard error.\n // Initial setting of {@code successful} will represent failure here.\n }\n\n return successful;\n }\n\n /** Cleans up DOM changes used to perform the copy operation. */\n destroy() {\n const textarea = this._textarea;\n\n if (textarea) {\n if (textarea.parentNode) {\n textarea.parentNode.removeChild(textarea);\n }\n\n this._textarea = undefined;\n }\n }\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {DOCUMENT} from '@angular/common';\nimport {Inject, Injectable} from '@angular/core';\nimport {PendingCopy} from './pending-copy';\n\n\n/**\n * A service for copying text to the clipboard.\n */\n@Injectable({providedIn: 'root'})\nexport class Clipboard {\n private readonly _document: Document;\n\n constructor(@Inject(DOCUMENT) document: any) {\n this._document = document;\n }\n\n /**\n * Copies the provided text into the user's clipboard.\n *\n * @param text The string to copy.\n * @returns Whether the operation was successful.\n */\n copy(text: string): boolean {\n const pendingCopy = this.beginCopy(text);\n const successful = pendingCopy.copy();\n pendingCopy.destroy();\n\n return successful;\n }\n\n /**\n * Prepares a string to be copied later. This is useful for large strings\n * which take too long to successfully render and be copied in the same tick.\n *\n * The caller must call `destroy` on the returned `PendingCopy`.\n *\n * @param text The string to copy.\n * @returns the pending copy operation.\n */\n beginCopy(text: string): PendingCopy {\n return new PendingCopy(text, this._document);\n }\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {\n Directive,\n EventEmitter,\n Input,\n Output,\n NgZone,\n InjectionToken,\n Inject,\n Optional,\n OnDestroy,\n} from '@angular/core';\nimport {Clipboard} from './clipboard';\nimport {PendingCopy} from './pending-copy';\n\n/** Object that can be used to configure the default options for `CdkCopyToClipboard`. */\nexport interface CdkCopyToClipboardConfig {\n /** Default number of attempts to make when copying text to the clipboard. */\n attempts?: number;\n}\n\n/** Injection token that can be used to provide the default options to `CdkCopyToClipboard`. */\nexport const CDK_COPY_TO_CLIPBOARD_CONFIG =\n new InjectionToken<CdkCopyToClipboardConfig>('CDK_COPY_TO_CLIPBOARD_CONFIG');\n\n/**\n * @deprecated Use `CDK_COPY_TO_CLIPBOARD_CONFIG` instead.\n * @breaking-change 13.0.0\n */\nexport const CKD_COPY_TO_CLIPBOARD_CONFIG = CDK_COPY_TO_CLIPBOARD_CONFIG;\n\n/**\n * Provides behavior for a button that when clicked copies content into user's\n * clipboard.\n */\n@Directive({\n selector: '[cdkCopyToClipboard]',\n host: {\n '(click)': 'copy()',\n }\n})\nexport class CdkCopyToClipboard implements OnDestroy {\n /** Content to be copied. */\n @Input('cdkCopyToClipboard') text: string = '';\n\n /**\n * How many times to attempt to copy the text. This may be necessary for longer text, because\n * the browser needs time to fill an intermediate textarea element and copy the content.\n */\n @Input('cdkCopyToClipboardAttempts') attempts: number = 1;\n\n /**\n * Emits when some text is copied to the clipboard. The\n * emitted value indicates whether copying was successful.\n */\n @Output('cdkCopyToClipboardCopied') copied = new EventEmitter<boolean>();\n\n /** Copies that are currently being attempted. */\n private _pending = new Set<PendingCopy>();\n\n /** Whether the directive has been destroyed. */\n private _destroyed: boolean;\n\n /** Timeout for the current copy attempt. */\n private _currentTimeout: any;\n\n constructor(\n private _clipboard: Clipboard,\n private _ngZone: NgZone,\n @Optional() @Inject(CKD_COPY_TO_CLIPBOARD_CONFIG) config?: CdkCopyToClipboardConfig) {\n\n if (config && config.attempts != null) {\n this.attempts = config.attempts;\n }\n }\n\n /** Copies the current text to the clipboard. */\n copy(attempts: number = this.attempts): void {\n if (attempts > 1) {\n let remainingAttempts = attempts;\n const pending = this._clipboard.beginCopy(this.text);\n this._pending.add(pending);\n\n const attempt = () => {\n const successful = pending.copy();\n if (!successful && --remainingAttempts && !this._destroyed) {\n // We use 1 for the timeout since it's more predictable when flushing in unit tests.\n this._currentTimeout = this._ngZone.runOutsideAngular(() => setTimeout(attempt, 1));\n } else {\n this._currentTimeout = null;\n this._pending.delete(pending);\n pending.destroy();\n this.copied.emit(successful);\n }\n };\n attempt();\n } else {\n this.copied.emit(this._clipboard.copy(this.text));\n }\n }\n\n ngOnDestroy() {\n if (this._currentTimeout) {\n clearTimeout(this._currentTimeout);\n }\n\n this._pending.forEach(copy => copy.destroy());\n this._pending.clear();\n this._destroyed = true;\n }\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {NgModule} from '@angular/core';\n\nimport {CdkCopyToClipboard} from './copy-to-clipboard';\n\n@NgModule({\n declarations: [CdkCopyToClipboard],\n exports: [CdkCopyToClipboard],\n})\nexport class ClipboardModule {\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nexport * from './clipboard';\nexport * from './clipboard-module';\nexport * from './copy-to-clipboard';\nexport * from './pending-copy';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["Injectable","Inject","DOCUMENT","InjectionToken","EventEmitter","Directive","NgZone","Optional","Input","Output","NgModule"],"mappings":";;;;;;IAAA;;;;;;;IAQA;;;;;;;;;;;;;AAaA;QAGE,qBAAY,IAAY,EAAmB,SAAmB;YAAnB,cAAS,GAAT,SAAS,CAAU;YAC5D,IAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;YAC3E,IAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC;;;;YAK9B,MAAM,CAAC,QAAQ,GAAG,OAAO,CAAC;YAC1B,MAAM,CAAC,GAAG,GAAG,MAAM,CAAC,OAAO,GAAG,GAAG,CAAC;YAClC,MAAM,CAAC,IAAI,GAAG,QAAQ,CAAC;YACvB,QAAQ,CAAC,YAAY,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;YAC7C,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC;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