From cc603bf50eb0c87db1594b0a857408fd43c8c4aa Mon Sep 17 00:00:00 2001 From: koplenov Date: Tue, 6 Feb 2024 17:51:07 +0300 Subject: [PATCH 1/2] $mol_button_copy: hide fallback error --- button/copy/copy.view.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/button/copy/copy.view.ts b/button/copy/copy.view.ts index e615b9df8d3..e88898ed701 100644 --- a/button/copy/copy.view.ts +++ b/button/copy/copy.view.ts @@ -24,8 +24,13 @@ namespace $.$$ { click( event?: Event ) { const cb = $mol_wire_sync( this.$.$mol_dom_context.navigator.clipboard ) - cb.writeText( this.text() ) // fallback - cb.write( this.attachments() ) + + if( cb.writeText ) cb.writeText( this.text() ) + if( cb.write ) cb.write( this.attachments() ) + + if( cb.writeText === undefined && cb.write === undefined ) { + throw new Error( "Browser cannot support write functions" ) + } } } From 9a0f443d0b99861e9b1e72fb9a1874b0c9b94852 Mon Sep 17 00:00:00 2001 From: koplenov Date: Tue, 6 Feb 2024 18:07:13 +0300 Subject: [PATCH 2/2] $mol_button_copy: simplify --- button/copy/copy.view.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/button/copy/copy.view.ts b/button/copy/copy.view.ts index e88898ed701..9788a11d90b 100644 --- a/button/copy/copy.view.ts +++ b/button/copy/copy.view.ts @@ -24,12 +24,12 @@ namespace $.$$ { click( event?: Event ) { const cb = $mol_wire_sync( this.$.$mol_dom_context.navigator.clipboard ) - - if( cb.writeText ) cb.writeText( this.text() ) - if( cb.write ) cb.write( this.attachments() ) + + cb.writeText?.( this.text() ) + cb.write?.( this.attachments() ) if( cb.writeText === undefined && cb.write === undefined ) { - throw new Error( "Browser cannot support write functions" ) + throw new Error( "doesn't support copy to clipoard" ) } }