@@ -31,6 +31,7 @@ export class WcStylingComponent implements OnDestroy, OnInit {
3131 @ViewChild ( "styleInputElement" ) styleInputElement : ElementRef ;
3232 @ViewChild ( "fontInputElement" ) fontInputElement : ElementRef ;
3333 @ViewChild ( "styleSection" ) styleSection : ElementRef ;
34+ canUseClipBoard = false ;
3435
3536 constructor (
3637 private toastr : ToastrService ,
@@ -51,6 +52,20 @@ export class WcStylingComponent implements OnDestroy, OnInit {
5152 //this.collapsed = false;
5253 }
5354 } ) ;
55+ //check if clipboard access is allowed
56+ navigator . permissions
57+ . query ( { name : "clipboard-write" as PermissionName } )
58+ . then ( ( result ) => {
59+ if ( result . state === "granted" || result . state === "prompt" ) {
60+ this . canUseClipBoard = true ;
61+ } else {
62+ this . canUseClipBoard = false ;
63+ }
64+ } )
65+ . catch ( ( err ) => {
66+ console . error ( "Failed to query clipboard permissions" , err ) ;
67+ this . canUseClipBoard = false ;
68+ } ) ;
5469 }
5570 onFontSelected ( event : any ) {
5671 const file : File = event . target . files [ 0 ] ;
@@ -107,6 +122,7 @@ export class WcStylingComponent implements OnDestroy, OnInit {
107122 . text ( )
108123 . then ( ( val ) => {
109124 this . styleText$ . next ( val ) ;
125+
110126 this . wcStylingService . $wcStyleInput . next ( val ) ;
111127 this . inputType = "edit" ;
112128 this . toastr . success (
@@ -179,7 +195,6 @@ span.theme--dark.sentence__text {
179195 }
180196 toggleStyleInput ( event : any ) {
181197 this . inputType = event . value ;
182- this . collapsed$ . next ( false ) ;
183198 }
184199 async ngOnInit ( ) {
185200 this . wcStylingService . $wcStyleInput
@@ -206,6 +221,60 @@ span.theme--dark.sentence__text {
206221 toggleCollapse ( ) {
207222 this . collapsed$ . next ( ! this . collapsed$ . getValue ( ) ) ;
208223 }
224+ pasteStyle ( ) {
225+ if ( this . canUseClipBoard ) {
226+ navigator . clipboard
227+ . readText ( )
228+ . then ( ( text ) => {
229+ this . styleText$ . next ( text ) ;
230+ this . wcStylingService . $wcStyleInput . next ( text ) ;
231+ this . inputType = "edit" ;
232+ this . toastr . success (
233+ $localize `Style sheet pasted from clipboard.` ,
234+ undefined ,
235+ { timeOut : 10000 } ,
236+ ) ;
237+ } )
238+ . catch ( ( err ) => {
239+ this . toastr . error ( $localize `Failed to read clipboard content.` , err , {
240+ timeOut : 2000 ,
241+ } ) ;
242+ } ) ;
243+ } else {
244+ this . toastr . error (
245+ $localize `Clipboard access is not allowed.` ,
246+ $localize `Error` ,
247+ ) ;
248+ }
249+ }
250+
251+ copyStyle ( ) {
252+ if ( this . canUseClipBoard ) {
253+ navigator . clipboard
254+ . writeText ( this . styleText$ . getValue ( ) )
255+ . then ( ( ) => {
256+ this . toastr . success (
257+ $localize `Style sheet copied to clipboard.` ,
258+ undefined ,
259+ { timeOut : 10000 } ,
260+ ) ;
261+ } )
262+ . catch ( ( err ) => {
263+ this . toastr . error (
264+ $localize `Failed to copy style sheet to clipboard.` ,
265+ err ,
266+ {
267+ timeOut : 2000 ,
268+ } ,
269+ ) ;
270+ } ) ;
271+ } else {
272+ this . toastr . error (
273+ $localize `Clipboard access is not allowed.` ,
274+ $localize `Error` ,
275+ ) ;
276+ }
277+ }
209278}
210279
211280@Component ( {
0 commit comments