@arsedizioni/ars-utils 21.0.40 → 21.0.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -915,6 +915,9 @@ class ClipperDocumentComponent extends ClipperDocumentManager {
915
915
  this.relevants.hits = data.total;
916
916
  this.updateRelevants();
917
917
  break;
918
+ case 'copy':
919
+ this.copy(data.html);
920
+ break;
918
921
  }
919
922
  this.changeDetector.markForCheck();
920
923
  }
@@ -1324,33 +1327,32 @@ class ClipperDocumentComponent extends ClipperDocumentManager {
1324
1327
  }
1325
1328
  /**
1326
1329
  * Copy to clipboard
1330
+ * @param data : the data to copy. If null, request from iframe
1327
1331
  */
1328
- async copy() {
1329
- console.log("siiiii");
1330
- let f = document.getElementById('clipper-document-iframe');
1331
- if (!f)
1332
- return;
1333
- console.log("1:" + f.innerHTML);
1334
- console.log("2:" + f.contentDocument?.body?.innerHTML);
1335
- console.log("3:" + f.contentWindow?.document?.body?.innerHTML);
1336
- const html = f.contentWindow?.document?.body?.innerHTML;
1337
- const htmlBlob = new Blob([html], { type: 'text/html' });
1338
- const textBlob = new Blob([html], { type: 'text/plain' });
1339
- try {
1340
- const data = [
1341
- new ClipboardItem({
1342
- 'text/html': htmlBlob,
1343
- 'text/plain': textBlob
1344
- })
1345
- ];
1346
- setTimeout(async () => {
1347
- window.focus();
1348
- await navigator.clipboard.write(data);
1349
- }, 0);
1350
- this.dialogService.toast("Copiato negli appunti.");
1351
- }
1352
- catch (err) {
1353
- this.dialogService.toast("Errore copiando negli appunti: " + err);
1332
+ async copy(data = null) {
1333
+ if (!data) {
1334
+ let f = document.getElementById('clipper-document-iframe');
1335
+ f?.contentWindow.postMessage('{"type": "copy", "value":""}', '*');
1336
+ }
1337
+ else {
1338
+ const htmlBlob = new Blob([data], { type: 'text/html' });
1339
+ const textBlob = new Blob([data], { type: 'text/plain' });
1340
+ try {
1341
+ const data = [
1342
+ new ClipboardItem({
1343
+ 'text/html': htmlBlob,
1344
+ 'text/plain': textBlob
1345
+ })
1346
+ ];
1347
+ setTimeout(async () => {
1348
+ window.focus();
1349
+ await navigator.clipboard.write(data);
1350
+ }, 0);
1351
+ this.dialogService.toast("Copiato negli appunti.");
1352
+ }
1353
+ catch (err) {
1354
+ this.dialogService.toast("Errore copiando negli appunti: " + err);
1355
+ }
1354
1356
  }
1355
1357
  }
1356
1358
  /**