diff --git a/package.json b/package.json index b929b90..d9936de 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "@clr/icons": "^2.3.7", "@clr/ui": "^2.3.7", "core-js": "^2.5.4", - "ngx-clipboard": "13.0.0-beta06", + "ngx-clipboard": "^13.0.1", "ngx-window-token": "3.0.0-beta01", "rxjs": "~6.5.4", "tslib": "^1.10.0", diff --git a/projects/ngx-clipboard/package.json b/projects/ngx-clipboard/package.json index aee316f..981121f 100644 --- a/projects/ngx-clipboard/package.json +++ b/projects/ngx-clipboard/package.json @@ -1,7 +1,7 @@ { "name": "ngx-clipboard", "description": "angular 2 clipboard", - "version": "13.0.0", + "version": "13.0.1", "author": { "name": "Sam Lin", "email": "maxisam@gmail.com" @@ -22,7 +22,7 @@ "copy" ], "dependencies": { - "ngx-window-token": ">= 3.0.0-beta01 || >= 3.0.0" + "ngx-window-token": ">=3.0.0" }, "peerDependencies": { "@angular/common": ">=9.0.0", diff --git a/projects/ngx-clipboard/src/lib/ngx-clipboard.directive.ts b/projects/ngx-clipboard/src/lib/ngx-clipboard.directive.ts index 8cc563c..ed28b8a 100644 --- a/projects/ngx-clipboard/src/lib/ngx-clipboard.directive.ts +++ b/projects/ngx-clipboard/src/lib/ngx-clipboard.directive.ts @@ -7,14 +7,15 @@ import { ClipboardService } from './ngx-clipboard.service'; selector: '[ngxClipboard]' }) export class ClipboardDirective implements OnInit, OnDestroy { + // https://github.com/maxisam/ngx-clipboard/issues/239#issuecomment-623330624 // tslint:disable-next-line:no-input-rename @Input('ngxClipboard') - public targetElm: HTMLInputElement | HTMLTextAreaElement; + public targetElm: HTMLInputElement | HTMLTextAreaElement | undefined | ''; @Input() public container: HTMLElement; @Input() - public cbContent: string; + public cbContent: string | undefined; @Input() public cbSuccessMsg: string; diff --git a/projects/ngx-clipboard/src/lib/ngx-clipboard.service.ts b/projects/ngx-clipboard/src/lib/ngx-clipboard.service.ts index 0a1cf38..15d823c 100644 --- a/projects/ngx-clipboard/src/lib/ngx-clipboard.service.ts +++ b/projects/ngx-clipboard/src/lib/ngx-clipboard.service.ts @@ -81,7 +81,7 @@ export class ClipboardService { // check if the temp textarea still belongs to the current container. // In case we have multiple places using ngx-clipboard, one is in a modal using container but the other one is not. if (this.tempTextArea && !container.contains(this.tempTextArea)) { - this.destroy(this.tempTextArea.parentElement); + this.destroy(this.tempTextArea.parentElement || undefined); } if (!this.tempTextArea) { @@ -96,7 +96,7 @@ export class ClipboardService { const toReturn = this.copyFromInputElement(this.tempTextArea, false); if (this.config.cleanUpAfterCopy) { - this.destroy(this.tempTextArea.parentElement); + this.destroy(this.tempTextArea.parentElement || undefined); } return toReturn; } @@ -128,9 +128,9 @@ export class ClipboardService { /** * Moves focus away from `target` and back to the trigger, removes current selection. */ - private clearSelection(inputElement: HTMLInputElement | HTMLTextAreaElement, window: Window): void { + private clearSelection(inputElement: HTMLInputElement | HTMLTextAreaElement | undefined, window: Window): void { inputElement && inputElement.focus(); - window.getSelection().removeAllRanges(); + window.getSelection()?.removeAllRanges(); } /** diff --git a/tsconfig.json b/tsconfig.json index 40a185c..f9c63cc 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,6 +10,7 @@ "module": "esnext", "moduleResolution": "node", "importHelpers": true, + "strictNullChecks": true, "target": "es2015", "typeRoots": ["node_modules/@types"], "lib": ["es2018", "dom"], @@ -19,6 +20,7 @@ }, "angularCompilerOptions": { "fullTemplateTypeCheck": true, - "strictInjectionParameters": true + "strictInjectionParameters": true, + "strictTemplates": true } } diff --git a/yarn.lock b/yarn.lock index f667a99..28ad096 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6767,18 +6767,23 @@ ng-packagr@^9.0.0: terser "^4.3.8" update-notifier "^4.0.0" -ngx-clipboard@13.0.0-beta06: - version "13.0.0-beta06" - resolved "https://registry.yarnpkg.com/ngx-clipboard/-/ngx-clipboard-13.0.0-beta06.tgz#97e0dc6864c65c2222c278917cabbf35982a1924" - integrity sha512-sT2ZSHUczXhjxBxhtpry2BPn55LUOfk6Cz0i2Cc43SLYurMw3Q5W432mUu5kiRWIIB/zg/TVEacRFcSq2umx8w== +ngx-clipboard@^13.0.1: + version "13.0.1" + resolved "https://registry.yarnpkg.com/ngx-clipboard/-/ngx-clipboard-13.0.1.tgz#393239d1a8f0ada8b99ef2d3ac80bc245c9ba3fe" + integrity sha512-e7QBsw7bX5ajhVR2++NAaYZYw90hKeEBlb006TW85WDUA3kmlrXpMDwOvVJuRewU6Nh+U1QiQMJq5a0ivk0zWg== dependencies: - ngx-window-token ">= 3.0.0-beta01 || >= 3.0.0" + ngx-window-token ">=3.0.0" -ngx-window-token@3.0.0-beta01, "ngx-window-token@>= 3.0.0-beta01 || >= 3.0.0": +ngx-window-token@3.0.0-beta01: version "3.0.0-beta01" resolved "https://registry.yarnpkg.com/ngx-window-token/-/ngx-window-token-3.0.0-beta01.tgz#8cd0e9103b435f3b0da72e4d039988b62989c2fc" integrity sha512-EOH0SMhqwl4916W9rAo4o58egqbWSMeIhNhO2zDaLT5YfTtULjhFf+kWeOrgT1MLnNo0fRt5XvWxZtimB1hETw== +ngx-window-token@>=3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/ngx-window-token/-/ngx-window-token-3.0.0.tgz#a5419befb133c6226e3e570737a247e66c825ab7" + integrity sha512-MDVIQB2SqFCbpoTqEXhO2529hsvpCYyw/iogjU6uskKqUKh79XVKWSMpRH9S1yTr0Ucgh8nFeNcpv2DnFdikJA== + nice-try@^1.0.4: version "1.0.5" resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366"