UNPKG

@blackbaud/skyux-lib-clipboard

Version:

This library was generated with [Nx](https://nx.dev).

137 lines (130 loc) 10.1 kB
import { CommonModule } from '@angular/common'; import * as i0 from '@angular/core'; import { NgModule, Injectable, input, Input, Component } from '@angular/core'; import * as i1 from '@skyux/core'; import { SkyAppWindowRef } from '@skyux/core'; import * as i3 from '@skyux/icon'; import { SkyIconModule } from '@skyux/icon'; import * as i4 from '@skyux/i18n'; import { SkyLibResourcesService, SkyI18nModule } from '@skyux/i18n'; /* istanbul ignore file */ /** * NOTICE: DO NOT MODIFY THIS FILE! * The contents of this file were automatically generated by * the 'ng generate @skyux/i18n:lib-resources-module lib/modules/shared/sky-clipboard' schematic. * To update this file, simply rerun the command. */ const RESOURCES = { 'EN-US': { sky_copy_to_clipboard_button_title: { message: 'Copy to clipboard' }, }, }; SkyLibResourcesService.addResources(RESOURCES); /** * Import into any component library module that needs to use resource strings. */ class SkyClipboardResourcesModule { static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.7", ngImport: i0, type: SkyClipboardResourcesModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); } static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.2.7", ngImport: i0, type: SkyClipboardResourcesModule, exports: [SkyI18nModule] }); } static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "21.2.7", ngImport: i0, type: SkyClipboardResourcesModule, imports: [SkyI18nModule] }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.7", ngImport: i0, type: SkyClipboardResourcesModule, decorators: [{ type: NgModule, args: [{ exports: [SkyI18nModule], }] }] }); // adapted from ngx-clipboard class SkyCopyToClipboardService { #windowRef; constructor(windowRef) { this.#windowRef = windowRef; } copyContent(element) { const copyText = this.#getTextFromElement(element); this.#windowRef.nativeWindow.navigator.clipboard.writeText(copyText); } #getTextFromElement(element) { if (this.#isValidInputElement(element)) { const targetEl = element; return targetEl.value; } return element.textContent?.trim(); } #isValidInputElement(element) { return (element instanceof HTMLTextAreaElement || element instanceof HTMLInputElement); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.7", ngImport: i0, type: SkyCopyToClipboardService, deps: [{ token: i1.SkyAppWindowRef }], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.7", ngImport: i0, type: SkyCopyToClipboardService }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.7", ngImport: i0, type: SkyCopyToClipboardService, decorators: [{ type: Injectable }], ctorParameters: () => [{ type: i1.SkyAppWindowRef }] }); class SkyCopyToClipboardComponent { #changeDetector; #clipboardSvc; #timeout; #window; constructor(changeDetector, clipboardSvc, windowRef) { /** * Specifies the type of button to display. Valid values are `"default"` and `"icon-borderless"`. * @default "default" */ this.buttonType = input('default', ...(ngDevMode ? [{ debugName: "buttonType" }] : /* istanbul ignore next */ [])); this.buttonActive = false; this.#changeDetector = changeDetector; this.#clipboardSvc = clipboardSvc; this.#window = windowRef.nativeWindow; } copyToClipboard() { if (this.copyTarget) { this.buttonActive = true; this.#clipboardSvc.copyContent(this.copyTarget); if (this.#timeout !== undefined) { this.#window.clearTimeout(this.#timeout); } this.#timeout = this.#window.setTimeout(() => { this.buttonActive = false; this.#changeDetector.markForCheck(); }, 1000); } } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.7", ngImport: i0, type: SkyCopyToClipboardComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: SkyCopyToClipboardService }, { token: i1.SkyAppWindowRef }], target: i0.ɵɵFactoryTarget.Component }); } static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.7", type: SkyCopyToClipboardComponent, isStandalone: false, selector: "sky-copy-to-clipboard", inputs: { ariaLabel: { classPropertyName: "ariaLabel", publicName: "ariaLabel", isSignal: false, isRequired: false, transformFunction: null }, ariaLabelledBy: { classPropertyName: "ariaLabelledBy", publicName: "ariaLabelledBy", isSignal: false, isRequired: false, transformFunction: null }, copyTarget: { classPropertyName: "copyTarget", publicName: "copyTarget", isSignal: false, isRequired: false, transformFunction: null }, buttonText: { classPropertyName: "buttonText", publicName: "buttonText", isSignal: false, isRequired: false, transformFunction: null }, buttonClickedText: { classPropertyName: "buttonClickedText", publicName: "buttonClickedText", isSignal: false, isRequired: false, transformFunction: null }, title: { classPropertyName: "title", publicName: "title", isSignal: false, isRequired: false, transformFunction: null }, buttonType: { classPropertyName: "buttonType", publicName: "buttonType", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0, template: "<button\n type=\"button\"\n [class]=\"'sky-btn sky-btn-' + buttonType()\"\n [attr.title]=\"\n title ? title : ('sky_copy_to_clipboard_button_title' | skyLibResources)\n \"\n [attr.aria-label]=\"\n !ariaLabelledBy\n ? ariaLabel\n ? ariaLabel\n : ('sky_copy_to_clipboard_button_title' | skyLibResources)\n : undefined\n \"\n [attr.aria-labelledby]=\"ariaLabelledBy ? ariaLabelledBy : undefined\"\n (click)=\"copyToClipboard()\"\n>\n @if (!buttonActive) {\n <sky-icon iconName=\"clipboard-multiple\" />\n }\n @if (buttonActive) {\n <sky-icon iconName=\"checkmark\" />\n }\n @if (buttonType() !== 'icon-borderless') {\n @if (!buttonActive || (buttonActive && !buttonClickedText)) {\n <span>\n {{ buttonText }}\n </span>\n }\n @if (buttonActive && buttonClickedText) {\n <span>\n {{ buttonClickedText }}\n </span>\n }\n }\n</button>\n", dependencies: [{ kind: "component", type: i3.λ1, selector: "sky-icon", inputs: ["iconName", "variant", "iconSize"] }, { kind: "pipe", type: i4.SkyLibResourcesPipe, name: "skyLibResources" }] }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.7", ngImport: i0, type: SkyCopyToClipboardComponent, decorators: [{ type: Component, args: [{ selector: 'sky-copy-to-clipboard', standalone: false, template: "<button\n type=\"button\"\n [class]=\"'sky-btn sky-btn-' + buttonType()\"\n [attr.title]=\"\n title ? title : ('sky_copy_to_clipboard_button_title' | skyLibResources)\n \"\n [attr.aria-label]=\"\n !ariaLabelledBy\n ? ariaLabel\n ? ariaLabel\n : ('sky_copy_to_clipboard_button_title' | skyLibResources)\n : undefined\n \"\n [attr.aria-labelledby]=\"ariaLabelledBy ? ariaLabelledBy : undefined\"\n (click)=\"copyToClipboard()\"\n>\n @if (!buttonActive) {\n <sky-icon iconName=\"clipboard-multiple\" />\n }\n @if (buttonActive) {\n <sky-icon iconName=\"checkmark\" />\n }\n @if (buttonType() !== 'icon-borderless') {\n @if (!buttonActive || (buttonActive && !buttonClickedText)) {\n <span>\n {{ buttonText }}\n </span>\n }\n @if (buttonActive && buttonClickedText) {\n <span>\n {{ buttonClickedText }}\n </span>\n }\n }\n</button>\n" }] }], ctorParameters: () => [{ type: i0.ChangeDetectorRef }, { type: SkyCopyToClipboardService }, { type: i1.SkyAppWindowRef }], propDecorators: { ariaLabel: [{ type: Input }], ariaLabelledBy: [{ type: Input }], copyTarget: [{ type: Input }], buttonText: [{ type: Input }], buttonClickedText: [{ type: Input }], title: [{ type: Input }], buttonType: [{ type: i0.Input, args: [{ isSignal: true, alias: "buttonType", required: false }] }] } }); class SkyClipboardModule { static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.7", ngImport: i0, type: SkyClipboardModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); } static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.2.7", ngImport: i0, type: SkyClipboardModule, declarations: [SkyCopyToClipboardComponent], imports: [CommonModule, SkyClipboardResourcesModule, SkyIconModule], exports: [SkyCopyToClipboardComponent] }); } static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "21.2.7", ngImport: i0, type: SkyClipboardModule, providers: [SkyCopyToClipboardService, SkyAppWindowRef], imports: [CommonModule, SkyClipboardResourcesModule, SkyIconModule] }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.7", ngImport: i0, type: SkyClipboardModule, decorators: [{ type: NgModule, args: [{ declarations: [SkyCopyToClipboardComponent], imports: [CommonModule, SkyClipboardResourcesModule, SkyIconModule], exports: [SkyCopyToClipboardComponent], providers: [SkyCopyToClipboardService, SkyAppWindowRef], }] }] }); /** * Generated bundle index. Do not edit. */ export { SkyClipboardModule, SkyCopyToClipboardService, SkyCopyToClipboardComponent as λ1 }; //# sourceMappingURL=blackbaud-skyux-lib-clipboard.mjs.map