@flexiui/svelte-rich-text 0.0.80 → 0.0.82

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.
@@ -508,6 +508,51 @@
508
508
  }, 200);
509
509
  }
510
510
  },
511
+ transformPastedText(text) {
512
+ return text;
513
+ },
514
+ transformPastedHTML(html: string) {
515
+ const div = document.createElement("div");
516
+ div.innerHTML = html;
517
+
518
+ const cleanNode = (node: HTMLElement) => {
519
+ // 1. Eliminar atributos que generan "basura"
520
+ node.removeAttribute("style");
521
+ node.removeAttribute("class");
522
+ node.removeAttribute("id");
523
+
524
+ // 2. Opcional: eliminar atributos específicos
525
+ [...node.attributes].forEach((attr) => {
526
+ if (
527
+ attr.name.startsWith("data-") ||
528
+ attr.name.startsWith("aria-")
529
+ ) {
530
+ node.removeAttribute(attr.name);
531
+ }
532
+ });
533
+
534
+ // 3. Reemplazar tags innecesarios (span, font...) por su contenido
535
+ if (["SPAN", "FONT"].includes(node.tagName)) {
536
+ const parent = node.parentNode;
537
+ while (node.firstChild) {
538
+ parent?.insertBefore(node.firstChild, node);
539
+ }
540
+ parent?.removeChild(node);
541
+ return;
542
+ }
543
+
544
+ // 4. Recursivo
545
+ Array.from(node.children).forEach((child) =>
546
+ cleanNode(child as HTMLElement),
547
+ );
548
+ };
549
+
550
+ Array.from(div.children).forEach((child) =>
551
+ cleanNode(child as HTMLElement),
552
+ );
553
+
554
+ return div.innerHTML;
555
+ },
511
556
  },
512
557
  onTransaction: ({ editor, transaction }) => {
513
558
  // Actualizar contador de nodos
@@ -602,13 +647,21 @@
602
647
  onBlur({ editor, event }) {
603
648
  const relatedTarget = event.relatedTarget as HTMLElement;
604
649
 
605
- const isSameEditor = relatedTarget?.closest(`#${id}`); // usa el id del editor actual
606
-
607
- const isBubbleMenu = relatedTarget?.closest(".fl-bubble-menu");
608
- const isToolbarDropdown = relatedTarget?.closest(".fl-toolbar-dropdown-panel");
650
+ const isSameEditor = relatedTarget?.closest(`#${id}`); // usa el id del editor actual
651
+
652
+ const isBubbleMenu =
653
+ relatedTarget?.closest(".fl-bubble-menu") ||
654
+ relatedTarget?.classList.contains("fl-bubble-menu-mark-button");
655
+ const isToolbarDropdown = relatedTarget?.closest(
656
+ ".fl-toolbar-dropdown-panel",
657
+ );
609
658
  const isFontSizeEditor = relatedTarget?.closest(".fl-font-size-editor");
610
659
 
611
- if (relatedTarget?.classList.contains("fl-bubble-menu-mark-button") || isFontSizeEditor) {
660
+ if (
661
+ relatedTarget?.classList.contains("fl-bubble-menu-mark-button") ||
662
+ isFontSizeEditor ||
663
+ isBubbleMenu
664
+ ) {
612
665
  return;
613
666
  }
614
667
 
@@ -822,15 +875,12 @@
822
875
  }
823
876
  }
824
877
 
825
-
826
878
  function clearSelection(editor) {
827
879
  const { state, view } = editor;
828
880
 
829
881
  const pos = state.selection.to;
830
882
 
831
- const tr = state.tr.setSelection(
832
- TextSelection.create(state.doc, pos)
833
- );
883
+ const tr = state.tr.setSelection(TextSelection.create(state.doc, pos));
834
884
 
835
885
  view.dispatch(tr);
836
886
  }
@@ -853,7 +903,7 @@
853
903
  {/if}
854
904
  {:else}
855
905
  <div
856
- id={id}
906
+ {id}
857
907
  class="fl-rich-text {className}"
858
908
  class:editable
859
909
  style="
@@ -1327,7 +1377,7 @@
1327
1377
  {/if}
1328
1378
  </div>
1329
1379
 
1330
- {#if editor && focused}
1380
+ {#if editor && focused}
1331
1381
  <div class="hidden">
1332
1382
  <BubbleMenu
1333
1383
  options={mergedBubbleMenuOptions}
@@ -100,7 +100,7 @@ export function getRichTextExtensions(options) {
100
100
  listKeymap: false,
101
101
  }),
102
102
  EnhancedLink,
103
- Image.configure({ inline: true }),
103
+ Image.configure({ inline: false }),
104
104
  Audio.configure({
105
105
  HTMLAttributes: { class: "audio-player" },
106
106
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flexiui/svelte-rich-text",
3
- "version": "0.0.80",
3
+ "version": "0.0.82",
4
4
  "description": "A lightweight and flexible rich text editor component for Svelte",
5
5
  "keywords": [
6
6
  "svelte",