@adminforth/markdown 1.9.1 → 1.10.0

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.
package/build.log CHANGED
@@ -12,5 +12,5 @@ custom/tsconfig.json
12
12
  custom/utils/
13
13
  custom/utils/monacoMarkdownToggle.ts
14
14
 
15
- sent 37,202 bytes received 146 bytes 74,696.00 bytes/sec
16
- total size is 36,649 speedup is 0.98
15
+ sent 38,446 bytes received 146 bytes 77,184.00 bytes/sec
16
+ total size is 37,901 speedup is 0.98
@@ -447,6 +447,50 @@ async function uploadFileAndGetMarkdownTag(file: File): Promise<string | undefin
447
447
  return;
448
448
  }
449
449
  }
450
+ function getSelectedPlainText(): string {
451
+ if (!editor || !model) return '';
452
+
453
+ const sels = editor.getSelections() || [];
454
+ if (!sels.length) return '';
455
+ return sels
456
+ .map((sel) => model!.getValueInRange(sel))
457
+ .join('\n');
458
+ }
459
+
460
+ const onEditorCopy = (e: ClipboardEvent) => {
461
+ if (!editor || !model) return;
462
+ if (!e.clipboardData) return;
463
+
464
+ if (!(editor.hasTextFocus?.() || isFocused.value)) return;
465
+
466
+ const text = getSelectedPlainText();
467
+ if (!text) return;
468
+
469
+ e.clipboardData.setData('text/plain', text);
470
+ e.clipboardData.setData('text/html', '');
471
+ e.preventDefault();
472
+ e.stopPropagation();
473
+ };
474
+
475
+ const onEditorCut = (e: ClipboardEvent) => {
476
+ if (!editor || !model) return;
477
+ if (!e.clipboardData) return;
478
+ if (!(editor.hasTextFocus?.() || isFocused.value)) return;
479
+
480
+ const text = getSelectedPlainText();
481
+ if (!text) return;
482
+
483
+ e.clipboardData.setData('text/plain', text);
484
+ e.clipboardData.setData('text/html', '');
485
+ e.preventDefault();
486
+ e.stopPropagation();
487
+
488
+ const sels = editor.getSelections() || [];
489
+ editor.executeEdits(
490
+ 'cut',
491
+ sels.map((range) => ({ range, text: '' })),
492
+ );
493
+ };
450
494
 
451
495
  onMounted(async () => {
452
496
  if (!editorContainer.value) return;
@@ -577,7 +621,8 @@ onMounted(async () => {
577
621
  insertAtCursor(`${markdownTags.join('\n\n')}\n`);
578
622
  }
579
623
  };
580
-
624
+ domNode.addEventListener('copy', onEditorCopy, true);
625
+ domNode.addEventListener('cut', onEditorCut, true);
581
626
  domNode.addEventListener('dragover', onDragOver, true);
582
627
  domNode.addEventListener('drop', onDrop, true);
583
628
  removeDragOverListener = () => domNode.removeEventListener('dragover', onDragOver, true);
@@ -710,7 +755,7 @@ async function uploadFileToS3(file: File): Promise<string | undefined> {
710
755
  return;
711
756
  }
712
757
 
713
- const originalFilename = file.name.split('.').slice(0, -1).join('.');
758
+ const originalFilename = file.name.split('.').slice(0, -1).join('.') + `_${Date.now()}`;
714
759
  const originalExtension = file.name.split('.').pop();
715
760
 
716
761
  const { uploadUrl, tagline, previewUrl, error } = await callAdminForthApi({
@@ -447,6 +447,50 @@ async function uploadFileAndGetMarkdownTag(file: File): Promise<string | undefin
447
447
  return;
448
448
  }
449
449
  }
450
+ function getSelectedPlainText(): string {
451
+ if (!editor || !model) return '';
452
+
453
+ const sels = editor.getSelections() || [];
454
+ if (!sels.length) return '';
455
+ return sels
456
+ .map((sel) => model!.getValueInRange(sel))
457
+ .join('\n');
458
+ }
459
+
460
+ const onEditorCopy = (e: ClipboardEvent) => {
461
+ if (!editor || !model) return;
462
+ if (!e.clipboardData) return;
463
+
464
+ if (!(editor.hasTextFocus?.() || isFocused.value)) return;
465
+
466
+ const text = getSelectedPlainText();
467
+ if (!text) return;
468
+
469
+ e.clipboardData.setData('text/plain', text);
470
+ e.clipboardData.setData('text/html', '');
471
+ e.preventDefault();
472
+ e.stopPropagation();
473
+ };
474
+
475
+ const onEditorCut = (e: ClipboardEvent) => {
476
+ if (!editor || !model) return;
477
+ if (!e.clipboardData) return;
478
+ if (!(editor.hasTextFocus?.() || isFocused.value)) return;
479
+
480
+ const text = getSelectedPlainText();
481
+ if (!text) return;
482
+
483
+ e.clipboardData.setData('text/plain', text);
484
+ e.clipboardData.setData('text/html', '');
485
+ e.preventDefault();
486
+ e.stopPropagation();
487
+
488
+ const sels = editor.getSelections() || [];
489
+ editor.executeEdits(
490
+ 'cut',
491
+ sels.map((range) => ({ range, text: '' })),
492
+ );
493
+ };
450
494
 
451
495
  onMounted(async () => {
452
496
  if (!editorContainer.value) return;
@@ -577,7 +621,8 @@ onMounted(async () => {
577
621
  insertAtCursor(`${markdownTags.join('\n\n')}\n`);
578
622
  }
579
623
  };
580
-
624
+ domNode.addEventListener('copy', onEditorCopy, true);
625
+ domNode.addEventListener('cut', onEditorCut, true);
581
626
  domNode.addEventListener('dragover', onDragOver, true);
582
627
  domNode.addEventListener('drop', onDrop, true);
583
628
  removeDragOverListener = () => domNode.removeEventListener('dragover', onDragOver, true);
@@ -710,7 +755,7 @@ async function uploadFileToS3(file: File): Promise<string | undefined> {
710
755
  return;
711
756
  }
712
757
 
713
- const originalFilename = file.name.split('.').slice(0, -1).join('.');
758
+ const originalFilename = file.name.split('.').slice(0, -1).join('.') + `_${Date.now()}`;
714
759
  const originalExtension = file.name.split('.').pop();
715
760
 
716
761
  const { uploadUrl, tagline, previewUrl, error } = await callAdminForthApi({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/markdown",
3
- "version": "1.9.1",
3
+ "version": "1.10.0",
4
4
  "description": "Markdown plugin for adminforth",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",