@flexiui/svelte-rich-text 0.0.74 → 0.0.75
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 +123 -124
- package/package.json +1 -1
package/dist/RichText.svelte
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { onMount, onDestroy } from "svelte";
|
|
6
6
|
import type { Readable } from "svelte/store";
|
|
7
7
|
import { computePosition, offset, autoUpdate } from "@floating-ui/dom";
|
|
8
|
+
import { TextSelection } from "prosemirror-state";
|
|
8
9
|
import {
|
|
9
10
|
ColorPicker,
|
|
10
11
|
ColorPickerSwatch,
|
|
@@ -578,6 +579,15 @@
|
|
|
578
579
|
},
|
|
579
580
|
onBlur({ editor, event }) {
|
|
580
581
|
focused = false;
|
|
582
|
+
|
|
583
|
+
const { state, view } = editor;
|
|
584
|
+
|
|
585
|
+
const pos = state.selection.to;
|
|
586
|
+
|
|
587
|
+
const tr = state.tr.setSelection(TextSelection.create(state.doc, pos));
|
|
588
|
+
|
|
589
|
+
view.dispatch(tr);
|
|
590
|
+
|
|
581
591
|
editorEvents.onBlur({ editor, event });
|
|
582
592
|
},
|
|
583
593
|
onDestroy() {
|
|
@@ -666,150 +676,132 @@
|
|
|
666
676
|
}
|
|
667
677
|
}
|
|
668
678
|
|
|
669
|
-
let defaultColor = "#fafafa"
|
|
679
|
+
let defaultColor = "#fafafa";
|
|
670
680
|
let colorValue = $derived(defaultColor);
|
|
671
681
|
|
|
672
|
-
function onFormatChange(e) {
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
}
|
|
682
|
+
function onFormatChange(e) {}
|
|
676
683
|
|
|
677
684
|
let colorValueRgb = $state(colorValue);
|
|
678
685
|
|
|
679
|
-
function onChange(value: any) {
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
let prevSelection: { from: number; to: number } | null = null;
|
|
685
|
-
let prevColorValueRgb: string | null = null;
|
|
686
|
-
|
|
687
|
-
function onOpenChange(open: boolean) {
|
|
688
|
-
|
|
689
|
-
if (open) {
|
|
690
|
-
const { from, to } = $editor.state.selection;
|
|
691
|
-
prevSelection = { from, to };
|
|
692
|
-
prevColorValueRgb = $editor?.getAttributes("textStyle")?.color;
|
|
693
|
-
return;
|
|
686
|
+
function onChange(value: any) {
|
|
687
|
+
colorValue = value.hex;
|
|
688
|
+
colorValueRgb = value.rgb;
|
|
694
689
|
}
|
|
695
690
|
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
if(colorValue === defaultColor) return;
|
|
691
|
+
let prevSelection: { from: number; to: number } | null = null;
|
|
692
|
+
let prevColorValueRgb: string | null = null;
|
|
699
693
|
|
|
700
|
-
|
|
694
|
+
function onOpenChange(open: boolean) {
|
|
695
|
+
if (open) {
|
|
696
|
+
const { from, to } = $editor.state.selection;
|
|
697
|
+
prevSelection = { from, to };
|
|
698
|
+
prevColorValueRgb = $editor?.getAttributes("textStyle")?.color;
|
|
701
699
|
return;
|
|
702
700
|
}
|
|
703
701
|
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
if (!included) {
|
|
707
|
-
recentCustomColors = [
|
|
708
|
-
...recentCustomColors,
|
|
709
|
-
colorValueRgb,
|
|
710
|
-
];
|
|
711
|
-
}
|
|
702
|
+
if (!open) {
|
|
703
|
+
if (colorValue === defaultColor) return;
|
|
712
704
|
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
const { state, view } = $editor;
|
|
705
|
+
if (colorValueRgb === prevColorValueRgb) {
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
717
708
|
|
|
718
|
-
|
|
709
|
+
// Guardar color reciente
|
|
710
|
+
const included = recentCustomColors.includes(colorValueRgb);
|
|
711
|
+
if (!included) {
|
|
712
|
+
recentCustomColors = [...recentCustomColors, colorValueRgb];
|
|
713
|
+
}
|
|
719
714
|
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
to
|
|
723
|
-
|
|
724
|
-
);
|
|
715
|
+
// Aplicar color al rango previo
|
|
716
|
+
if (prevSelection) {
|
|
717
|
+
const { from, to } = prevSelection;
|
|
718
|
+
const { state, view } = $editor;
|
|
725
719
|
|
|
726
|
-
|
|
720
|
+
const textStyle = state.schema.marks.textStyle;
|
|
727
721
|
|
|
722
|
+
const tr = state.tr.addMark(
|
|
723
|
+
from,
|
|
724
|
+
to,
|
|
725
|
+
textStyle.create({ color: colorValueRgb }),
|
|
726
|
+
);
|
|
728
727
|
|
|
729
|
-
|
|
730
|
-
colorValueRgb = defaultColor;
|
|
728
|
+
view.dispatch(tr);
|
|
731
729
|
|
|
730
|
+
colorValue = defaultColor;
|
|
731
|
+
colorValueRgb = defaultColor;
|
|
732
|
+
}
|
|
732
733
|
}
|
|
733
734
|
}
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
// Highlight colorPicker
|
|
738
|
-
let highlightColorValue = $state(null);
|
|
739
|
-
let highlightColorValueRgb = $state(null);
|
|
740
|
-
let prevSelectionHighlight: { from: number; to: number } | null = null;
|
|
741
|
-
let prevHighlightColorValueRgb: string | null = null;
|
|
742
|
-
|
|
743
|
-
function onChangeHighlight(value: any) {
|
|
744
|
-
highlightColorValue = value.hex;
|
|
745
|
-
highlightColorValueRgb = value.rgb;
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
function onOpenChangeHighlight(open: boolean) {
|
|
749
|
-
if (open) {
|
|
750
|
-
const { from, to } = $editor.state.selection;
|
|
751
|
-
prevSelectionHighlight = { from, to };
|
|
752
|
-
prevColorValueRgb = $editor?.getAttributes("highlight")?.color;
|
|
753
|
-
return;
|
|
754
|
-
}
|
|
755
735
|
|
|
756
|
-
|
|
757
|
-
|
|
736
|
+
// Highlight colorPicker
|
|
737
|
+
let highlightColorValue = $state(null);
|
|
738
|
+
let highlightColorValueRgb = $state(null);
|
|
739
|
+
let prevSelectionHighlight: { from: number; to: number } | null = null;
|
|
740
|
+
let prevHighlightColorValueRgb: string | null = null;
|
|
741
|
+
|
|
742
|
+
function onChangeHighlight(value: any) {
|
|
743
|
+
highlightColorValue = value.hex;
|
|
744
|
+
highlightColorValueRgb = value.rgb;
|
|
745
|
+
}
|
|
758
746
|
|
|
759
|
-
|
|
747
|
+
function onOpenChangeHighlight(open: boolean) {
|
|
748
|
+
if (open) {
|
|
749
|
+
const { from, to } = $editor.state.selection;
|
|
750
|
+
prevSelectionHighlight = { from, to };
|
|
751
|
+
prevColorValueRgb = $editor?.getAttributes("highlight")?.color;
|
|
760
752
|
return;
|
|
761
753
|
}
|
|
762
754
|
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
if (!included) {
|
|
766
|
-
recentCustomColors = [
|
|
767
|
-
...recentCustomColors,
|
|
768
|
-
highlightColorValueRgb,
|
|
769
|
-
];
|
|
770
|
-
}
|
|
755
|
+
if (!open) {
|
|
756
|
+
if (highlightColorValue === defaultColor) return;
|
|
771
757
|
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
const { state, view } = $editor;
|
|
758
|
+
if (highlightColorValueRgb === prevHighlightColorValueRgb) {
|
|
759
|
+
return;
|
|
760
|
+
}
|
|
776
761
|
|
|
777
|
-
|
|
762
|
+
// Guardar color reciente
|
|
763
|
+
const included = recentCustomColors.includes(highlightColorValueRgb);
|
|
764
|
+
if (!included) {
|
|
765
|
+
recentCustomColors = [...recentCustomColors, highlightColorValueRgb];
|
|
766
|
+
}
|
|
778
767
|
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
to
|
|
782
|
-
|
|
783
|
-
);
|
|
768
|
+
// Aplicar color al rango previo
|
|
769
|
+
if (prevSelectionHighlight) {
|
|
770
|
+
const { from, to } = prevSelectionHighlight;
|
|
771
|
+
const { state, view } = $editor;
|
|
784
772
|
|
|
785
|
-
|
|
773
|
+
const highlight = state.schema.marks.highlight;
|
|
786
774
|
|
|
775
|
+
const tr = state.tr.addMark(
|
|
776
|
+
from,
|
|
777
|
+
to,
|
|
778
|
+
highlight.create({ color: highlightColorValueRgb }),
|
|
779
|
+
);
|
|
787
780
|
|
|
788
|
-
|
|
789
|
-
highlightColorValueRgb = defaultColor;
|
|
781
|
+
view.dispatch(tr);
|
|
790
782
|
|
|
783
|
+
highlightColorValue = defaultColor;
|
|
784
|
+
highlightColorValueRgb = defaultColor;
|
|
785
|
+
}
|
|
791
786
|
}
|
|
792
787
|
}
|
|
793
|
-
}
|
|
794
788
|
</script>
|
|
795
789
|
|
|
796
790
|
{#if cleanMode}
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
{
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
{/if}
|
|
812
|
-
|
|
791
|
+
<EditorContent
|
|
792
|
+
as={contentWrapperAs}
|
|
793
|
+
editor={$editor}
|
|
794
|
+
class={className}
|
|
795
|
+
{...rest}
|
|
796
|
+
/>
|
|
797
|
+
|
|
798
|
+
<!-- Warning message for node limit -->
|
|
799
|
+
{#if showLimitWarning && nodesLimit}
|
|
800
|
+
<div class="fl-node-limit-warning">
|
|
801
|
+
{limitWarningMessage ||
|
|
802
|
+
` No se pueden añadir más nodos a este editor. Max: ${nodesLimit}`}
|
|
803
|
+
</div>
|
|
804
|
+
{/if}
|
|
813
805
|
{:else}
|
|
814
806
|
<div
|
|
815
807
|
class="fl-rich-text {className}"
|
|
@@ -858,7 +850,10 @@ function onOpenChangeHighlight(open: boolean) {
|
|
|
858
850
|
{currentNodeCount}
|
|
859
851
|
accentSoft={isAccentSoft}
|
|
860
852
|
{fontSize}
|
|
861
|
-
onToggleDropdown={(
|
|
853
|
+
onToggleDropdown={(
|
|
854
|
+
e: MouseEvent,
|
|
855
|
+
dropdownName: string,
|
|
856
|
+
) => {
|
|
862
857
|
toogleDropdown(
|
|
863
858
|
e.currentTarget as HTMLElement,
|
|
864
859
|
dropdownName,
|
|
@@ -874,7 +869,10 @@ function onOpenChangeHighlight(open: boolean) {
|
|
|
874
869
|
{currentNodeCount}
|
|
875
870
|
accentSoft={isAccentSoft}
|
|
876
871
|
{fontSize}
|
|
877
|
-
onToggleDropdown={(
|
|
872
|
+
onToggleDropdown={(
|
|
873
|
+
e: MouseEvent,
|
|
874
|
+
dropdownName: string,
|
|
875
|
+
) => {
|
|
878
876
|
toogleDropdown(
|
|
879
877
|
e.currentTarget as HTMLElement,
|
|
880
878
|
dropdownName,
|
|
@@ -994,16 +992,16 @@ function onOpenChangeHighlight(open: boolean) {
|
|
|
994
992
|
<ColorPicker
|
|
995
993
|
value={$editor?.getAttributes("textStyle")?.color || colorValue}
|
|
996
994
|
defaultFormat="rgb"
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
995
|
+
{onFormatChange}
|
|
996
|
+
{onChange}
|
|
997
|
+
{onOpenChange}
|
|
1000
998
|
portalElement={"#color-picker-text-color"}
|
|
1001
999
|
>
|
|
1002
1000
|
<ColorPickerTrigger class="font-mono">
|
|
1003
1001
|
<button
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1002
|
+
class="fl-color-swatch fl-color-picker-btn"
|
|
1003
|
+
aria-label="Text color picker"
|
|
1004
|
+
type="button"
|
|
1007
1005
|
></button>
|
|
1008
1006
|
</ColorPickerTrigger>
|
|
1009
1007
|
</ColorPicker>
|
|
@@ -1018,7 +1016,7 @@ function onOpenChangeHighlight(open: boolean) {
|
|
|
1018
1016
|
onclick={() => {
|
|
1019
1017
|
$editor?.chain().focus().setColor(color).run();
|
|
1020
1018
|
hideDropdown();
|
|
1021
|
-
|
|
1019
|
+
|
|
1022
1020
|
setTimeout(() => {
|
|
1023
1021
|
colorValue = defaultColor;
|
|
1024
1022
|
colorValueRgb = null;
|
|
@@ -1159,18 +1157,19 @@ function onOpenChangeHighlight(open: boolean) {
|
|
|
1159
1157
|
|
|
1160
1158
|
<div class="color-picker-wrapper" id="color-picker-highlight-color">
|
|
1161
1159
|
<ColorPicker
|
|
1162
|
-
value={$editor?.getAttributes("highlight")?.color ||
|
|
1160
|
+
value={$editor?.getAttributes("highlight")?.color ||
|
|
1161
|
+
highlightColorValue}
|
|
1163
1162
|
defaultFormat="rgb"
|
|
1164
|
-
|
|
1163
|
+
{onFormatChange}
|
|
1165
1164
|
onChange={onChangeHighlight}
|
|
1166
1165
|
onOpenChange={onOpenChangeHighlight}
|
|
1167
1166
|
portalElement={"#color-picker-highlight-color"}
|
|
1168
1167
|
>
|
|
1169
1168
|
<ColorPickerTrigger class="font-mono">
|
|
1170
1169
|
<button
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1170
|
+
class="fl-color-swatch fl-color-picker-btn"
|
|
1171
|
+
aria-label="Text color picker"
|
|
1172
|
+
type="button"
|
|
1174
1173
|
></button>
|
|
1175
1174
|
</ColorPickerTrigger>
|
|
1176
1175
|
</ColorPicker>
|
|
@@ -1315,9 +1314,9 @@ function onOpenChangeHighlight(open: boolean) {
|
|
|
1315
1314
|
appendTo={document.body}
|
|
1316
1315
|
>
|
|
1317
1316
|
<div
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1317
|
+
data-test-id="bubble-menu"
|
|
1318
|
+
class="fl-bubble-menu flex"
|
|
1319
|
+
style="
|
|
1321
1320
|
--fl-editor-accent-color: {editorConfig.editorAccentColor};
|
|
1322
1321
|
"
|
|
1323
1322
|
>
|