@flexiui/svelte-rich-text 0.0.66 → 0.0.68
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/dist/Toolbar/action-buttons/nodes/HeadingBtn.svelte +22 -1
- package/dist/Toolbar/dropdown-buttons/HeadingsDropdownBtn.svelte +23 -14
- package/dist/extensions/NodeFontSize.js +1 -1
- package/dist/extensions/NodeLineHeight.js +1 -1
- package/dist/extensions/SemanticHeadings.js +3 -3
- package/dist/extensions/extensions.js +6 -0
- package/dist/getExtensions.d.ts +15 -0
- package/dist/getExtensions.js +63 -3
- package/dist/utils.js +1 -1
- 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"
|
|
@@ -51,6 +51,15 @@
|
|
|
51
51
|
function canCreateSubheading(editor) {
|
|
52
52
|
return !hasH1AfterCursor(editor);
|
|
53
53
|
}
|
|
54
|
+
|
|
55
|
+
const headingActions = {
|
|
56
|
+
"1": () => $editor.chain().focus().toggleH1().run(),
|
|
57
|
+
"2": () => $editor.chain().focus().toggleH2().run(),
|
|
58
|
+
"3": () => $editor.chain().focus().toggleH3().run(),
|
|
59
|
+
"4": () => $editor.chain().focus().toggleH4().run(),
|
|
60
|
+
"5": () => $editor.chain().focus().toggleH5().run(),
|
|
61
|
+
"6": () => $editor.chain().focus().toggleH6().run(),
|
|
62
|
+
};
|
|
54
63
|
</script>
|
|
55
64
|
|
|
56
65
|
{#if level === 1}
|
|
@@ -65,7 +74,7 @@
|
|
|
65
74
|
{@html icons[level]}
|
|
66
75
|
</button>
|
|
67
76
|
{:else}
|
|
68
|
-
<button
|
|
77
|
+
<!-- <button
|
|
69
78
|
type="button"
|
|
70
79
|
onclick={() => $editor.chain().focus().toggleHeading({ level }).run()}
|
|
71
80
|
class:is-active={$editor.isActive("heading", { level })}
|
|
@@ -74,5 +83,17 @@
|
|
|
74
83
|
disabled={!canCreateSubheading($editor)}
|
|
75
84
|
>
|
|
76
85
|
{@html icons[level]}
|
|
86
|
+
</button> -->
|
|
87
|
+
<button
|
|
88
|
+
type="button"
|
|
89
|
+
onclick={() => {
|
|
90
|
+
headingActions[level]();
|
|
91
|
+
}}
|
|
92
|
+
class:is-active={$editor.isActive("h"+level)}
|
|
93
|
+
class:accent-soft={accenSoft}
|
|
94
|
+
aria-label={`Heading ${level}`}
|
|
95
|
+
disabled={!canCreateSubheading($editor)}
|
|
96
|
+
>
|
|
97
|
+
{@html icons[level]}
|
|
77
98
|
</button>
|
|
78
99
|
{/if}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
<button
|
|
13
13
|
type="button"
|
|
14
14
|
onclick={handleClick}
|
|
15
|
-
class:is-active={$editor.isActive("heading") || $editor.isActive("h1")}
|
|
15
|
+
class:is-active={$editor.isActive("heading") || $editor.isActive("h1") || $editor.isActive("h2") || $editor.isActive("h3") || $editor.isActive("h4") || $editor.isActive("h5") || $editor.isActive("h6")}
|
|
16
16
|
class:accent-soft={accentSoft}
|
|
17
17
|
aria-label={ariaLabel}
|
|
18
18
|
>
|
|
@@ -24,21 +24,30 @@
|
|
|
24
24
|
{/each}
|
|
25
25
|
{:else if $editor.isActive("h1")}
|
|
26
26
|
{@html HEADINGS[0].icon}
|
|
27
|
-
{
|
|
27
|
+
{:else if $editor.isActive("h2")}
|
|
28
|
+
{@html HEADINGS[1].icon}
|
|
29
|
+
{:else if $editor.isActive("h3")}
|
|
30
|
+
{@html HEADINGS[2].icon}
|
|
31
|
+
{:else if $editor.isActive("h4")}
|
|
32
|
+
{@html HEADINGS[3].icon}
|
|
33
|
+
{:else if $editor.isActive("h5")}
|
|
34
|
+
{@html HEADINGS[4].icon}
|
|
35
|
+
{:else if $editor.isActive("h6")}
|
|
36
|
+
{@html HEADINGS[5].icon}
|
|
28
37
|
|
|
29
|
-
{
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
fill="currentColor"
|
|
36
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
37
|
-
><path
|
|
38
|
-
d="M6 3C6.55228 3 7 3.44772 7 4V11H17V4C17 3.44772 17.4477 3 18 3C18.5523 3 19 3.44772 19 4V20C19 20.5523 18.5523 21 18 21C17.4477 21 17 20.5523 17 20V13H7V20C7 20.5523 6.55228 21 6 21C5.44772 21 5 20.5523 5 20V4C5 3.44772 5.44772 3 6 3Z"
|
|
38
|
+
{:else}
|
|
39
|
+
<svg
|
|
40
|
+
width="24"
|
|
41
|
+
height="24"
|
|
42
|
+
class="tiptap-button-icon"
|
|
43
|
+
viewBox="0 0 24 24"
|
|
39
44
|
fill="currentColor"
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
46
|
+
><path
|
|
47
|
+
d="M6 3C6.55228 3 7 3.44772 7 4V11H17V4C17 3.44772 17.4477 3 18 3C18.5523 3 19 3.44772 19 4V20C19 20.5523 18.5523 21 18 21C17.4477 21 17 20.5523 17 20V13H7V20C7 20.5523 6.55228 21 6 21C5.44772 21 5 20.5523 5 20V4C5 3.44772 5.44772 3 6 3Z"
|
|
48
|
+
fill="currentColor"
|
|
49
|
+
></path></svg
|
|
50
|
+
>
|
|
42
51
|
{/if}
|
|
43
52
|
|
|
44
53
|
<svg
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Extension } from "@tiptap/core";
|
|
2
|
-
const allowedTypes = ["paragraph", "heading", "h1"];
|
|
2
|
+
const allowedTypes = ["paragraph", "heading", "h1", "h2", "h3", "h4", "h5", "h6"];
|
|
3
3
|
export const NodeFontSize = Extension.create({
|
|
4
4
|
name: "nodeFontSize",
|
|
5
5
|
addGlobalAttributes() {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Extension } from "@tiptap/core";
|
|
2
|
-
const allowedTypes = ["paragraph", "heading", "h1"];
|
|
2
|
+
const allowedTypes = ["paragraph", "heading", "h1", "h2", "h3", "h4", "h5", "h6"];
|
|
3
3
|
export const NodeLineHeight = Extension.create({
|
|
4
4
|
name: "nodeLineHeight",
|
|
5
5
|
addGlobalAttributes() {
|
|
@@ -16,7 +16,7 @@ export const SemanticHeadings = Extension.create({
|
|
|
16
16
|
let h1Count = 0;
|
|
17
17
|
// Recolectar todos los headings en orden
|
|
18
18
|
doc.descendants((node, pos) => {
|
|
19
|
-
if (node.type.name === 'heading') {
|
|
19
|
+
if (node.type.name === 'heading' || node.type.name === 'h1' || node.type.name === 'h2' || node.type.name === 'h3' || node.type.name === 'h4' || node.type.name === 'h5' || node.type.name === 'h6') {
|
|
20
20
|
headings.push({
|
|
21
21
|
level: node.attrs.level,
|
|
22
22
|
pos: pos
|
|
@@ -68,7 +68,7 @@ export const SemanticHeadings = Extension.create({
|
|
|
68
68
|
let hasH1 = false;
|
|
69
69
|
// Buscar el último heading y verificar si ya existe h1
|
|
70
70
|
doc.descendants((node) => {
|
|
71
|
-
if (node.type.name === 'heading') {
|
|
71
|
+
if (node.type.name === 'heading' || node.type.name === 'h1' || node.type.name === 'h2' || node.type.name === 'h3' || node.type.name === 'h4' || node.type.name === 'h5' || node.type.name === 'h6') {
|
|
72
72
|
lastHeadingLevel = node.attrs.level;
|
|
73
73
|
if (node.attrs.level === 1) {
|
|
74
74
|
hasH1 = true;
|
|
@@ -97,7 +97,7 @@ export const SemanticHeadings = Extension.create({
|
|
|
97
97
|
let lastHeadingLevel = null;
|
|
98
98
|
let hasH1 = false;
|
|
99
99
|
doc.descendants((node) => {
|
|
100
|
-
if (node.type.name === 'heading') {
|
|
100
|
+
if (node.type.name === 'heading' || node.type.name === 'h1' || node.type.name === 'h2' || node.type.name === 'h3' || node.type.name === 'h4' || node.type.name === 'h5' || node.type.name === 'h6') {
|
|
101
101
|
lastHeadingLevel = node.attrs.level;
|
|
102
102
|
if (node.attrs.level === 1) {
|
|
103
103
|
hasH1 = true;
|
package/dist/getExtensions.d.ts
CHANGED
|
@@ -3,6 +3,21 @@ declare module '@tiptap/core' {
|
|
|
3
3
|
h1: {
|
|
4
4
|
toggleH1: () => ReturnType;
|
|
5
5
|
};
|
|
6
|
+
h2: {
|
|
7
|
+
toggleH2: () => ReturnType;
|
|
8
|
+
};
|
|
9
|
+
h3: {
|
|
10
|
+
toggleH3: () => ReturnType;
|
|
11
|
+
};
|
|
12
|
+
h4: {
|
|
13
|
+
toggleH4: () => ReturnType;
|
|
14
|
+
};
|
|
15
|
+
h5: {
|
|
16
|
+
toggleH5: () => ReturnType;
|
|
17
|
+
};
|
|
18
|
+
h6: {
|
|
19
|
+
toggleH6: () => ReturnType;
|
|
20
|
+
};
|
|
6
21
|
}
|
|
7
22
|
}
|
|
8
23
|
export declare function getRichTextExtensions(options?: {
|
package/dist/getExtensions.js
CHANGED
|
@@ -17,7 +17,7 @@ import { CustomTableHeader } from "./extensions/Table/CustomTableHeader";
|
|
|
17
17
|
import { EnhancedLink } from "./extensions/EnhancedLink";
|
|
18
18
|
import { SemanticHeadings } from "./extensions/SemanticHeadings";
|
|
19
19
|
import { Heading } from "@tiptap/extension-heading";
|
|
20
|
-
const
|
|
20
|
+
const H1 = Heading.extend({
|
|
21
21
|
name: "h1",
|
|
22
22
|
addCommands() {
|
|
23
23
|
return {
|
|
@@ -27,11 +27,66 @@ const DocHeading = Heading.extend({
|
|
|
27
27
|
};
|
|
28
28
|
},
|
|
29
29
|
}).configure({ levels: [1] });
|
|
30
|
+
const H2 = Heading.extend({
|
|
31
|
+
name: "h2",
|
|
32
|
+
addCommands() {
|
|
33
|
+
return {
|
|
34
|
+
toggleH2: () => ({ commands }) => {
|
|
35
|
+
return commands.toggleNode('h2', 'paragraph');
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
}).configure({ levels: [2] });
|
|
40
|
+
const H3 = Heading.extend({
|
|
41
|
+
name: "h3",
|
|
42
|
+
addCommands() {
|
|
43
|
+
return {
|
|
44
|
+
toggleH3: () => ({ commands }) => {
|
|
45
|
+
return commands.toggleNode('h3', 'paragraph');
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
}).configure({ levels: [3] });
|
|
50
|
+
const H4 = Heading.extend({
|
|
51
|
+
name: "h4",
|
|
52
|
+
addCommands() {
|
|
53
|
+
return {
|
|
54
|
+
toggleH4: () => ({ commands }) => {
|
|
55
|
+
return commands.toggleNode('h4', 'paragraph');
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
}).configure({ levels: [4] });
|
|
60
|
+
const H5 = Heading.extend({
|
|
61
|
+
name: "h5",
|
|
62
|
+
addCommands() {
|
|
63
|
+
return {
|
|
64
|
+
toggleH5: () => ({ commands }) => {
|
|
65
|
+
return commands.toggleNode('h5', 'paragraph');
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
}).configure({ levels: [5] });
|
|
70
|
+
const H6 = Heading.extend({
|
|
71
|
+
name: "h6",
|
|
72
|
+
addCommands() {
|
|
73
|
+
return {
|
|
74
|
+
toggleH6: () => ({ commands }) => {
|
|
75
|
+
return commands.toggleNode('h6', 'paragraph');
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
},
|
|
79
|
+
}).configure({ levels: [6] });
|
|
30
80
|
export function getRichTextExtensions(options) {
|
|
31
81
|
const { editable = false, trailingNode = true, customExtensions = [] } = options ?? {};
|
|
32
82
|
return [
|
|
33
|
-
|
|
34
|
-
|
|
83
|
+
H1,
|
|
84
|
+
H2,
|
|
85
|
+
H3,
|
|
86
|
+
H4,
|
|
87
|
+
H5,
|
|
88
|
+
H6,
|
|
89
|
+
// Heading.configure({ levels: [2, 3, 4, 5, 6] }),
|
|
35
90
|
Highlight.configure({ multicolor: true }),
|
|
36
91
|
TextStyleKit.configure({
|
|
37
92
|
// fontSize: false
|
|
@@ -53,6 +108,11 @@ export function getRichTextExtensions(options) {
|
|
|
53
108
|
TextAlign.configure({
|
|
54
109
|
types: [
|
|
55
110
|
"h1",
|
|
111
|
+
"h2",
|
|
112
|
+
"h3",
|
|
113
|
+
"h4",
|
|
114
|
+
"h5",
|
|
115
|
+
"h6",
|
|
56
116
|
"heading",
|
|
57
117
|
"paragraph",
|
|
58
118
|
"bulletList",
|
package/dist/utils.js
CHANGED