@flexiui/svelte-rich-text 0.0.73 → 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 +128 -125
- 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,
|
|
@@ -227,6 +228,8 @@
|
|
|
227
228
|
editorConfig.toolbarJustifyContent = "flex-end";
|
|
228
229
|
}
|
|
229
230
|
|
|
231
|
+
let focused = $state(false);
|
|
232
|
+
|
|
230
233
|
let bubbleOffset =
|
|
231
234
|
$editor?.storage.tableCell.customTableSelection === "column" ? 18 : 8;
|
|
232
235
|
|
|
@@ -571,9 +574,20 @@
|
|
|
571
574
|
},
|
|
572
575
|
|
|
573
576
|
onFocus({ editor, event }) {
|
|
577
|
+
focused = true;
|
|
574
578
|
editorEvents.onFocus({ editor, event });
|
|
575
579
|
},
|
|
576
580
|
onBlur({ editor, event }) {
|
|
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
|
+
|
|
577
591
|
editorEvents.onBlur({ editor, event });
|
|
578
592
|
},
|
|
579
593
|
onDestroy() {
|
|
@@ -662,150 +676,132 @@
|
|
|
662
676
|
}
|
|
663
677
|
}
|
|
664
678
|
|
|
665
|
-
let defaultColor = "#fafafa"
|
|
679
|
+
let defaultColor = "#fafafa";
|
|
666
680
|
let colorValue = $derived(defaultColor);
|
|
667
681
|
|
|
668
|
-
function onFormatChange(e) {
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
}
|
|
682
|
+
function onFormatChange(e) {}
|
|
672
683
|
|
|
673
684
|
let colorValueRgb = $state(colorValue);
|
|
674
685
|
|
|
675
|
-
function onChange(value: any) {
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
let prevSelection: { from: number; to: number } | null = null;
|
|
681
|
-
let prevColorValueRgb: string | null = null;
|
|
682
|
-
|
|
683
|
-
function onOpenChange(open: boolean) {
|
|
684
|
-
|
|
685
|
-
if (open) {
|
|
686
|
-
const { from, to } = $editor.state.selection;
|
|
687
|
-
prevSelection = { from, to };
|
|
688
|
-
prevColorValueRgb = $editor?.getAttributes("textStyle")?.color;
|
|
689
|
-
return;
|
|
686
|
+
function onChange(value: any) {
|
|
687
|
+
colorValue = value.hex;
|
|
688
|
+
colorValueRgb = value.rgb;
|
|
690
689
|
}
|
|
691
690
|
|
|
692
|
-
|
|
691
|
+
let prevSelection: { from: number; to: number } | null = null;
|
|
692
|
+
let prevColorValueRgb: string | null = null;
|
|
693
693
|
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
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;
|
|
697
699
|
return;
|
|
698
700
|
}
|
|
699
701
|
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
if (!included) {
|
|
703
|
-
recentCustomColors = [
|
|
704
|
-
...recentCustomColors,
|
|
705
|
-
colorValueRgb,
|
|
706
|
-
];
|
|
707
|
-
}
|
|
702
|
+
if (!open) {
|
|
703
|
+
if (colorValue === defaultColor) return;
|
|
708
704
|
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
const { state, view } = $editor;
|
|
705
|
+
if (colorValueRgb === prevColorValueRgb) {
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
713
708
|
|
|
714
|
-
|
|
709
|
+
// Guardar color reciente
|
|
710
|
+
const included = recentCustomColors.includes(colorValueRgb);
|
|
711
|
+
if (!included) {
|
|
712
|
+
recentCustomColors = [...recentCustomColors, colorValueRgb];
|
|
713
|
+
}
|
|
715
714
|
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
to
|
|
719
|
-
|
|
720
|
-
);
|
|
715
|
+
// Aplicar color al rango previo
|
|
716
|
+
if (prevSelection) {
|
|
717
|
+
const { from, to } = prevSelection;
|
|
718
|
+
const { state, view } = $editor;
|
|
721
719
|
|
|
722
|
-
|
|
720
|
+
const textStyle = state.schema.marks.textStyle;
|
|
723
721
|
|
|
722
|
+
const tr = state.tr.addMark(
|
|
723
|
+
from,
|
|
724
|
+
to,
|
|
725
|
+
textStyle.create({ color: colorValueRgb }),
|
|
726
|
+
);
|
|
724
727
|
|
|
725
|
-
|
|
726
|
-
colorValueRgb = defaultColor;
|
|
728
|
+
view.dispatch(tr);
|
|
727
729
|
|
|
730
|
+
colorValue = defaultColor;
|
|
731
|
+
colorValueRgb = defaultColor;
|
|
732
|
+
}
|
|
728
733
|
}
|
|
729
734
|
}
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
// Highlight colorPicker
|
|
734
|
-
let highlightColorValue = $state(null);
|
|
735
|
-
let highlightColorValueRgb = $state(null);
|
|
736
|
-
let prevSelectionHighlight: { from: number; to: number } | null = null;
|
|
737
|
-
let prevHighlightColorValueRgb: string | null = null;
|
|
738
|
-
|
|
739
|
-
function onChangeHighlight(value: any) {
|
|
740
|
-
highlightColorValue = value.hex;
|
|
741
|
-
highlightColorValueRgb = value.rgb;
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
function onOpenChangeHighlight(open: boolean) {
|
|
745
|
-
if (open) {
|
|
746
|
-
const { from, to } = $editor.state.selection;
|
|
747
|
-
prevSelectionHighlight = { from, to };
|
|
748
|
-
prevColorValueRgb = $editor?.getAttributes("highlight")?.color;
|
|
749
|
-
return;
|
|
750
|
-
}
|
|
751
735
|
|
|
752
|
-
|
|
753
|
-
|
|
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;
|
|
754
741
|
|
|
755
|
-
|
|
742
|
+
function onChangeHighlight(value: any) {
|
|
743
|
+
highlightColorValue = value.hex;
|
|
744
|
+
highlightColorValueRgb = value.rgb;
|
|
745
|
+
}
|
|
746
|
+
|
|
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;
|
|
756
752
|
return;
|
|
757
753
|
}
|
|
758
754
|
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
if (!included) {
|
|
762
|
-
recentCustomColors = [
|
|
763
|
-
...recentCustomColors,
|
|
764
|
-
highlightColorValueRgb,
|
|
765
|
-
];
|
|
766
|
-
}
|
|
755
|
+
if (!open) {
|
|
756
|
+
if (highlightColorValue === defaultColor) return;
|
|
767
757
|
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
const { state, view } = $editor;
|
|
758
|
+
if (highlightColorValueRgb === prevHighlightColorValueRgb) {
|
|
759
|
+
return;
|
|
760
|
+
}
|
|
772
761
|
|
|
773
|
-
|
|
762
|
+
// Guardar color reciente
|
|
763
|
+
const included = recentCustomColors.includes(highlightColorValueRgb);
|
|
764
|
+
if (!included) {
|
|
765
|
+
recentCustomColors = [...recentCustomColors, highlightColorValueRgb];
|
|
766
|
+
}
|
|
774
767
|
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
to
|
|
778
|
-
|
|
779
|
-
);
|
|
768
|
+
// Aplicar color al rango previo
|
|
769
|
+
if (prevSelectionHighlight) {
|
|
770
|
+
const { from, to } = prevSelectionHighlight;
|
|
771
|
+
const { state, view } = $editor;
|
|
780
772
|
|
|
781
|
-
|
|
773
|
+
const highlight = state.schema.marks.highlight;
|
|
782
774
|
|
|
775
|
+
const tr = state.tr.addMark(
|
|
776
|
+
from,
|
|
777
|
+
to,
|
|
778
|
+
highlight.create({ color: highlightColorValueRgb }),
|
|
779
|
+
);
|
|
783
780
|
|
|
784
|
-
|
|
785
|
-
highlightColorValueRgb = defaultColor;
|
|
781
|
+
view.dispatch(tr);
|
|
786
782
|
|
|
783
|
+
highlightColorValue = defaultColor;
|
|
784
|
+
highlightColorValueRgb = defaultColor;
|
|
785
|
+
}
|
|
787
786
|
}
|
|
788
787
|
}
|
|
789
|
-
}
|
|
790
788
|
</script>
|
|
791
789
|
|
|
792
790
|
{#if cleanMode}
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
{
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
{/if}
|
|
808
|
-
|
|
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}
|
|
809
805
|
{:else}
|
|
810
806
|
<div
|
|
811
807
|
class="fl-rich-text {className}"
|
|
@@ -854,7 +850,10 @@ function onOpenChangeHighlight(open: boolean) {
|
|
|
854
850
|
{currentNodeCount}
|
|
855
851
|
accentSoft={isAccentSoft}
|
|
856
852
|
{fontSize}
|
|
857
|
-
onToggleDropdown={(
|
|
853
|
+
onToggleDropdown={(
|
|
854
|
+
e: MouseEvent,
|
|
855
|
+
dropdownName: string,
|
|
856
|
+
) => {
|
|
858
857
|
toogleDropdown(
|
|
859
858
|
e.currentTarget as HTMLElement,
|
|
860
859
|
dropdownName,
|
|
@@ -870,7 +869,10 @@ function onOpenChangeHighlight(open: boolean) {
|
|
|
870
869
|
{currentNodeCount}
|
|
871
870
|
accentSoft={isAccentSoft}
|
|
872
871
|
{fontSize}
|
|
873
|
-
onToggleDropdown={(
|
|
872
|
+
onToggleDropdown={(
|
|
873
|
+
e: MouseEvent,
|
|
874
|
+
dropdownName: string,
|
|
875
|
+
) => {
|
|
874
876
|
toogleDropdown(
|
|
875
877
|
e.currentTarget as HTMLElement,
|
|
876
878
|
dropdownName,
|
|
@@ -990,16 +992,16 @@ function onOpenChangeHighlight(open: boolean) {
|
|
|
990
992
|
<ColorPicker
|
|
991
993
|
value={$editor?.getAttributes("textStyle")?.color || colorValue}
|
|
992
994
|
defaultFormat="rgb"
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
995
|
+
{onFormatChange}
|
|
996
|
+
{onChange}
|
|
997
|
+
{onOpenChange}
|
|
996
998
|
portalElement={"#color-picker-text-color"}
|
|
997
999
|
>
|
|
998
1000
|
<ColorPickerTrigger class="font-mono">
|
|
999
1001
|
<button
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1002
|
+
class="fl-color-swatch fl-color-picker-btn"
|
|
1003
|
+
aria-label="Text color picker"
|
|
1004
|
+
type="button"
|
|
1003
1005
|
></button>
|
|
1004
1006
|
</ColorPickerTrigger>
|
|
1005
1007
|
</ColorPicker>
|
|
@@ -1014,7 +1016,7 @@ function onOpenChangeHighlight(open: boolean) {
|
|
|
1014
1016
|
onclick={() => {
|
|
1015
1017
|
$editor?.chain().focus().setColor(color).run();
|
|
1016
1018
|
hideDropdown();
|
|
1017
|
-
|
|
1019
|
+
|
|
1018
1020
|
setTimeout(() => {
|
|
1019
1021
|
colorValue = defaultColor;
|
|
1020
1022
|
colorValueRgb = null;
|
|
@@ -1155,18 +1157,19 @@ function onOpenChangeHighlight(open: boolean) {
|
|
|
1155
1157
|
|
|
1156
1158
|
<div class="color-picker-wrapper" id="color-picker-highlight-color">
|
|
1157
1159
|
<ColorPicker
|
|
1158
|
-
value={$editor?.getAttributes("highlight")?.color ||
|
|
1160
|
+
value={$editor?.getAttributes("highlight")?.color ||
|
|
1161
|
+
highlightColorValue}
|
|
1159
1162
|
defaultFormat="rgb"
|
|
1160
|
-
|
|
1163
|
+
{onFormatChange}
|
|
1161
1164
|
onChange={onChangeHighlight}
|
|
1162
1165
|
onOpenChange={onOpenChangeHighlight}
|
|
1163
1166
|
portalElement={"#color-picker-highlight-color"}
|
|
1164
1167
|
>
|
|
1165
1168
|
<ColorPickerTrigger class="font-mono">
|
|
1166
1169
|
<button
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
+
class="fl-color-swatch fl-color-picker-btn"
|
|
1171
|
+
aria-label="Text color picker"
|
|
1172
|
+
type="button"
|
|
1170
1173
|
></button>
|
|
1171
1174
|
</ColorPickerTrigger>
|
|
1172
1175
|
</ColorPicker>
|
|
@@ -1274,7 +1277,7 @@ function onOpenChangeHighlight(open: boolean) {
|
|
|
1274
1277
|
{/if}
|
|
1275
1278
|
</div>
|
|
1276
1279
|
|
|
1277
|
-
{#if editor}
|
|
1280
|
+
{#if editor && focused}
|
|
1278
1281
|
<div class="hidden">
|
|
1279
1282
|
<BubbleMenu
|
|
1280
1283
|
options={{
|
|
@@ -1311,9 +1314,9 @@ function onOpenChangeHighlight(open: boolean) {
|
|
|
1311
1314
|
appendTo={document.body}
|
|
1312
1315
|
>
|
|
1313
1316
|
<div
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
+
data-test-id="bubble-menu"
|
|
1318
|
+
class="fl-bubble-menu flex"
|
|
1319
|
+
style="
|
|
1317
1320
|
--fl-editor-accent-color: {editorConfig.editorAccentColor};
|
|
1318
1321
|
"
|
|
1319
1322
|
>
|