UNPKG

@andreasnicolaou/ngx-copy-to-clipboard

Version:

A lightweight, standalone Angular directive for copying text to the clipboard using the Clipboard API.

72 lines (66 loc) 3.37 kB
import * as i0 from '@angular/core'; import { EventEmitter, HostListener, Output, Input, Directive, NgModule } from '@angular/core'; class NgxCopyToClipboardDirective { constructor() { this.textToCopy = null; this.successMessage = 'Successfully copied'; this.errorMessage = 'Could not copy'; this.onCopyEvent = new EventEmitter(); this.onErrorEvent = new EventEmitter(); } async onClick() { if (typeof document === 'undefined' || this.textToCopy == null) { this.onErrorEvent.emit(this.errorMessage); return; } try { await navigator.clipboard.writeText(this.textToCopy); this.onCopyEvent.emit(this.successMessage); } catch { this.onErrorEvent.emit(this.errorMessage); } } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.10", ngImport: i0, type: NgxCopyToClipboardDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); } static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.10", type: NgxCopyToClipboardDirective, isStandalone: true, selector: "[ngxCopyToClipboard]", inputs: { textToCopy: "textToCopy", successMessage: "successMessage", errorMessage: "errorMessage" }, outputs: { onCopyEvent: "onCopyEvent", onErrorEvent: "onErrorEvent" }, host: { listeners: { "click": "onClick()" } }, ngImport: i0 }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.10", ngImport: i0, type: NgxCopyToClipboardDirective, decorators: [{ type: Directive, args: [{ standalone: true, selector: '[ngxCopyToClipboard]', }] }], propDecorators: { textToCopy: [{ type: Input }], successMessage: [{ type: Input }], errorMessage: [{ type: Input }], onCopyEvent: [{ type: Output }], onErrorEvent: [{ type: Output }], onClick: [{ type: HostListener, args: ['click'] }] } }); class NgxCopyToClipboardModule { static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.10", ngImport: i0, type: NgxCopyToClipboardModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); } static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.10", ngImport: i0, type: NgxCopyToClipboardModule, imports: [NgxCopyToClipboardDirective], exports: [NgxCopyToClipboardDirective] }); } static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.10", ngImport: i0, type: NgxCopyToClipboardModule }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.10", ngImport: i0, type: NgxCopyToClipboardModule, decorators: [{ type: NgModule, args: [{ imports: [NgxCopyToClipboardDirective], exports: [NgxCopyToClipboardDirective], }] }] }); /* * Public API Surface of ngx-copy-to-clipboard */ /** * Generated bundle index. Do not edit. */ export { NgxCopyToClipboardDirective, NgxCopyToClipboardModule }; //# sourceMappingURL=andreasnicolaou-ngx-copy-to-clipboard.mjs.map