@flexiui/svelte-rich-text 0.0.66 → 0.0.67
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 +104 -23
- package/package.json +1 -1
package/dist/RichText.svelte
CHANGED
|
@@ -667,10 +667,10 @@
|
|
|
667
667
|
|
|
668
668
|
let colorValueRgb = $state(colorValue);
|
|
669
669
|
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
670
|
+
function onChange(value: any) {
|
|
671
|
+
colorValue = value.hex;
|
|
672
|
+
colorValueRgb = value.rgb;
|
|
673
|
+
}
|
|
674
674
|
|
|
675
675
|
let prevSelection: { from: number; to: number } | null = null;
|
|
676
676
|
let prevColorValueRgb: string | null = null;
|
|
@@ -723,6 +723,65 @@ function onOpenChange(open: boolean) {
|
|
|
723
723
|
}
|
|
724
724
|
}
|
|
725
725
|
}
|
|
726
|
+
|
|
727
|
+
|
|
728
|
+
// Highlight colorPicker
|
|
729
|
+
let highlightColorValue = $state(null);
|
|
730
|
+
let highlightColorValueRgb = $state(null);
|
|
731
|
+
let prevSelectionHighlight: { from: number; to: number } | null = null;
|
|
732
|
+
let prevHighlightColorValueRgb: string | null = null;
|
|
733
|
+
|
|
734
|
+
function onChangeHighlight(value: any) {
|
|
735
|
+
highlightColorValue = value.hex;
|
|
736
|
+
highlightColorValueRgb = value.rgb;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
function onOpenChangeHighlight(open: boolean) {
|
|
740
|
+
if (open) {
|
|
741
|
+
const { from, to } = $editor.state.selection;
|
|
742
|
+
prevSelectionHighlight = { from, to };
|
|
743
|
+
prevColorValueRgb = $editor?.getAttributes("highlight")?.color;
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
if (!open) {
|
|
748
|
+
if(highlightColorValue === defaultColor) return;
|
|
749
|
+
|
|
750
|
+
if(highlightColorValueRgb === prevHighlightColorValueRgb) {
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
// Guardar color reciente
|
|
755
|
+
const included = recentCustomColors.includes(highlightColorValueRgb);
|
|
756
|
+
if (!included) {
|
|
757
|
+
recentCustomColors = [
|
|
758
|
+
...recentCustomColors,
|
|
759
|
+
highlightColorValueRgb,
|
|
760
|
+
];
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
// Aplicar color al rango previo
|
|
764
|
+
if (prevSelectionHighlight) {
|
|
765
|
+
const { from, to } = prevSelectionHighlight;
|
|
766
|
+
const { state, view } = $editor;
|
|
767
|
+
|
|
768
|
+
const highlight = state.schema.marks.highlight;
|
|
769
|
+
|
|
770
|
+
const tr = state.tr.addMark(
|
|
771
|
+
from,
|
|
772
|
+
to,
|
|
773
|
+
highlight.create({ color: highlightColorValueRgb })
|
|
774
|
+
);
|
|
775
|
+
|
|
776
|
+
view.dispatch(tr);
|
|
777
|
+
|
|
778
|
+
|
|
779
|
+
highlightColorValue = defaultColor;
|
|
780
|
+
highlightColorValueRgb = defaultColor;
|
|
781
|
+
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
}
|
|
726
785
|
</script>
|
|
727
786
|
|
|
728
787
|
<div
|
|
@@ -903,25 +962,23 @@ function onOpenChange(open: boolean) {
|
|
|
903
962
|
</div>
|
|
904
963
|
{:else if activeDropdownType === "text-color-dropdown"}
|
|
905
964
|
<div class="fl-editor-color-palette">
|
|
906
|
-
<div class="color-picker-wrapper">
|
|
965
|
+
<div class="color-picker-wrapper" id="color-picker-text-color">
|
|
907
966
|
<ColorPicker
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
</ColorPickerTrigger>
|
|
924
|
-
</ColorPicker>
|
|
967
|
+
value={$editor?.getAttributes("textStyle")?.color || colorValue}
|
|
968
|
+
defaultFormat="rgb"
|
|
969
|
+
onFormatChange={onFormatChange}
|
|
970
|
+
onChange={onChange}
|
|
971
|
+
onOpenChange={onOpenChange}
|
|
972
|
+
portalElement={"#color-picker-text-color"}
|
|
973
|
+
>
|
|
974
|
+
<ColorPickerTrigger class="font-mono">
|
|
975
|
+
<button
|
|
976
|
+
class="fl-color-swatch fl-color-picker-btn"
|
|
977
|
+
aria-label="Text color picker"
|
|
978
|
+
type="button"
|
|
979
|
+
></button>
|
|
980
|
+
</ColorPickerTrigger>
|
|
981
|
+
</ColorPicker>
|
|
925
982
|
</div>
|
|
926
983
|
|
|
927
984
|
{#each TEXT_COLOR_PALETTE as color}
|
|
@@ -933,6 +990,11 @@ function onOpenChange(open: boolean) {
|
|
|
933
990
|
onclick={() => {
|
|
934
991
|
$editor?.chain().focus().setColor(color).run();
|
|
935
992
|
hideDropdown();
|
|
993
|
+
|
|
994
|
+
setTimeout(() => {
|
|
995
|
+
colorValue = defaultColor;
|
|
996
|
+
colorValueRgb = null;
|
|
997
|
+
}, 100);
|
|
936
998
|
}}
|
|
937
999
|
style="background-color: {color};"
|
|
938
1000
|
aria-label={color}
|
|
@@ -1061,12 +1123,31 @@ function onOpenChange(open: boolean) {
|
|
|
1061
1123
|
.run();
|
|
1062
1124
|
hideDropdown();
|
|
1063
1125
|
}}
|
|
1064
|
-
value={rgbToHex($editor?.getAttributes("
|
|
1126
|
+
value={rgbToHex(rgbToHex($editor?.getAttributes("highlight")?.color))}
|
|
1065
1127
|
data-testid="setHiglight"
|
|
1066
1128
|
id="colorPicker"
|
|
1067
1129
|
/>
|
|
1068
1130
|
</button>
|
|
1069
1131
|
|
|
1132
|
+
<div class="color-picker-wrapper" id="color-picker-highlight-color">
|
|
1133
|
+
<ColorPicker
|
|
1134
|
+
value={$editor?.getAttributes("highlight")?.color || highlightColorValue}
|
|
1135
|
+
defaultFormat="rgb"
|
|
1136
|
+
onFormatChange={onFormatChange}
|
|
1137
|
+
onChange={onChangeHighlight}
|
|
1138
|
+
onOpenChange={onOpenChangeHighlight}
|
|
1139
|
+
portalElement={"#color-picker-highlight-color"}
|
|
1140
|
+
>
|
|
1141
|
+
<ColorPickerTrigger class="font-mono">
|
|
1142
|
+
<button
|
|
1143
|
+
class="fl-color-swatch fl-color-picker-btn"
|
|
1144
|
+
aria-label="Text color picker"
|
|
1145
|
+
type="button"
|
|
1146
|
+
></button>
|
|
1147
|
+
</ColorPickerTrigger>
|
|
1148
|
+
</ColorPicker>
|
|
1149
|
+
</div>
|
|
1150
|
+
|
|
1070
1151
|
{#each HIGHLIGHT_COLOR_PALETTE as color}
|
|
1071
1152
|
<button
|
|
1072
1153
|
class="fl-color-swatch"
|