@flexiui/svelte-rich-text 0.0.81 → 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.
- package/dist/RichText.svelte +55 -18
- package/package.json +1 -1
package/dist/RichText.svelte
CHANGED
|
@@ -509,17 +509,49 @@
|
|
|
509
509
|
}
|
|
510
510
|
},
|
|
511
511
|
transformPastedText(text) {
|
|
512
|
-
return text
|
|
512
|
+
return text;
|
|
513
513
|
},
|
|
514
514
|
transformPastedHTML(html: string) {
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
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
|
+
};
|
|
518
549
|
|
|
519
|
-
|
|
520
|
-
|
|
550
|
+
Array.from(div.children).forEach((child) =>
|
|
551
|
+
cleanNode(child as HTMLElement),
|
|
552
|
+
);
|
|
521
553
|
|
|
522
|
-
return
|
|
554
|
+
return div.innerHTML;
|
|
523
555
|
},
|
|
524
556
|
},
|
|
525
557
|
onTransaction: ({ editor, transaction }) => {
|
|
@@ -615,13 +647,21 @@
|
|
|
615
647
|
onBlur({ editor, event }) {
|
|
616
648
|
const relatedTarget = event.relatedTarget as HTMLElement;
|
|
617
649
|
|
|
618
|
-
const isSameEditor = relatedTarget?.closest(`#${id}`);
|
|
619
|
-
|
|
620
|
-
const isBubbleMenu =
|
|
621
|
-
|
|
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
|
+
);
|
|
622
658
|
const isFontSizeEditor = relatedTarget?.closest(".fl-font-size-editor");
|
|
623
659
|
|
|
624
|
-
if (
|
|
660
|
+
if (
|
|
661
|
+
relatedTarget?.classList.contains("fl-bubble-menu-mark-button") ||
|
|
662
|
+
isFontSizeEditor ||
|
|
663
|
+
isBubbleMenu
|
|
664
|
+
) {
|
|
625
665
|
return;
|
|
626
666
|
}
|
|
627
667
|
|
|
@@ -835,15 +875,12 @@
|
|
|
835
875
|
}
|
|
836
876
|
}
|
|
837
877
|
|
|
838
|
-
|
|
839
878
|
function clearSelection(editor) {
|
|
840
879
|
const { state, view } = editor;
|
|
841
880
|
|
|
842
881
|
const pos = state.selection.to;
|
|
843
882
|
|
|
844
|
-
const tr = state.tr.setSelection(
|
|
845
|
-
TextSelection.create(state.doc, pos)
|
|
846
|
-
);
|
|
883
|
+
const tr = state.tr.setSelection(TextSelection.create(state.doc, pos));
|
|
847
884
|
|
|
848
885
|
view.dispatch(tr);
|
|
849
886
|
}
|
|
@@ -866,7 +903,7 @@
|
|
|
866
903
|
{/if}
|
|
867
904
|
{:else}
|
|
868
905
|
<div
|
|
869
|
-
|
|
906
|
+
{id}
|
|
870
907
|
class="fl-rich-text {className}"
|
|
871
908
|
class:editable
|
|
872
909
|
style="
|
|
@@ -1340,7 +1377,7 @@
|
|
|
1340
1377
|
{/if}
|
|
1341
1378
|
</div>
|
|
1342
1379
|
|
|
1343
|
-
|
|
1380
|
+
{#if editor && focused}
|
|
1344
1381
|
<div class="hidden">
|
|
1345
1382
|
<BubbleMenu
|
|
1346
1383
|
options={mergedBubbleMenuOptions}
|