@blackbaud/skyux-lib-clipboard
Version:
This library was generated with [Nx](https://nx.dev).
131 lines (124 loc) • 8.63 kB
JavaScript
import * as i3 from '@angular/common';
import { CommonModule } from '@angular/common';
import * as i0 from '@angular/core';
import { NgModule, Injectable, Input, Component } from '@angular/core';
import * as i1 from '@skyux/core';
import { SkyAppWindowRef } from '@skyux/core';
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: "19.2.4", ngImport: i0, type: SkyClipboardResourcesModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.4", ngImport: i0, type: SkyClipboardResourcesModule, exports: [SkyI18nModule] }); }
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: SkyClipboardResourcesModule, imports: [SkyI18nModule] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", 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: "19.2.4", ngImport: i0, type: SkyCopyToClipboardService, deps: [{ token: i1.SkyAppWindowRef }], target: i0.ɵɵFactoryTarget.Injectable }); }
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: SkyCopyToClipboardService }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: SkyCopyToClipboardService, decorators: [{
type: Injectable
}], ctorParameters: () => [{ type: i1.SkyAppWindowRef }] });
class SkyCopyToClipboardComponent {
#changeDetector;
#clipboardSvc;
#timeout;
#window;
constructor(changeDetector, clipboardSvc, windowRef) {
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: "19.2.4", ngImport: i0, type: SkyCopyToClipboardComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: SkyCopyToClipboardService }, { token: i1.SkyAppWindowRef }], target: i0.ɵɵFactoryTarget.Component }); }
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.4", type: SkyCopyToClipboardComponent, isStandalone: false, selector: "sky-copy-to-clipboard", inputs: { ariaLabel: "ariaLabel", ariaLabelledBy: "ariaLabelledBy", copyTarget: "copyTarget", buttonText: "buttonText", buttonClickedText: "buttonClickedText", title: "title" }, ngImport: i0, template: "<button\n type=\"button\"\n class=\"sky-btn sky-btn-default\"\n (click)=\"copyToClipboard()\"\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>\n <i *ngIf=\"!buttonActive\" aria-hidden=\"true\" class=\"fa fa-clipboard\"></i>\n <i *ngIf=\"buttonActive\" aria-hidden=\"true\" class=\"fa fa-check\"></i>\n <span *ngIf=\"!buttonActive || (buttonActive && !buttonClickedText)\">\n {{ buttonText }}\n </span>\n <span *ngIf=\"buttonActive && buttonClickedText\">\n {{ buttonClickedText }}\n </span>\n</button>\n", dependencies: [{ kind: "directive", type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "pipe", type: i4.SkyLibResourcesPipe, name: "skyLibResources" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", 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-default\"\n (click)=\"copyToClipboard()\"\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>\n <i *ngIf=\"!buttonActive\" aria-hidden=\"true\" class=\"fa fa-clipboard\"></i>\n <i *ngIf=\"buttonActive\" aria-hidden=\"true\" class=\"fa fa-check\"></i>\n <span *ngIf=\"!buttonActive || (buttonActive && !buttonClickedText)\">\n {{ buttonText }}\n </span>\n <span *ngIf=\"buttonActive && buttonClickedText\">\n {{ buttonClickedText }}\n </span>\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
}] } });
class SkyClipboardModule {
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: SkyClipboardModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.4", ngImport: i0, type: SkyClipboardModule, declarations: [SkyCopyToClipboardComponent], imports: [CommonModule, SkyClipboardResourcesModule], exports: [SkyCopyToClipboardComponent] }); }
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: SkyClipboardModule, providers: [SkyCopyToClipboardService, SkyAppWindowRef], imports: [CommonModule, SkyClipboardResourcesModule] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: SkyClipboardModule, decorators: [{
type: NgModule,
args: [{
declarations: [SkyCopyToClipboardComponent],
imports: [CommonModule, SkyClipboardResourcesModule],
exports: [SkyCopyToClipboardComponent],
providers: [SkyCopyToClipboardService, SkyAppWindowRef],
}]
}] });
/**
* Generated bundle index. Do not edit.
*/
export { SkyClipboardModule, SkyCopyToClipboardService, SkyCopyToClipboardComponent as λ1 };
//# sourceMappingURL=blackbaud-skyux-lib-clipboard.mjs.map