@mekari/pixel3-rich-text-editor 0.1.1 → 0.1.2-dev.0
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/{chunk-TNDDXUVW.mjs → chunk-7BEXEMOE.mjs} +6 -0
- package/dist/{chunk-7RMCTPMN.mjs → chunk-MKTM47RO.mjs} +1 -1
- package/dist/{chunk-NKNFA3DF.mjs → chunk-XNM3YX37.mjs} +40 -23
- package/dist/{chunk-3CWKDY4T.mjs → chunk-YE6FEVD4.mjs} +13 -3
- package/dist/{chunk-H4GW25PU.mjs → chunk-ZO6THAT6.mjs} +38 -4
- package/dist/editor-toolbar.d.mts +18 -0
- package/dist/editor-toolbar.d.ts +18 -0
- package/dist/editor-toolbar.js +49 -5
- package/dist/editor-toolbar.mjs +2 -2
- package/dist/extensions/index.js +37 -3
- package/dist/extensions/index.mjs +1 -1
- package/dist/extensions/link-extension.d.mts +18 -0
- package/dist/extensions/link-extension.d.ts +18 -0
- package/dist/extensions/link-extension.js +37 -3
- package/dist/extensions/link-extension.mjs +1 -1
- package/dist/index.js +92 -25
- package/dist/index.mjs +5 -5
- package/dist/metafile-cjs.json +1 -1
- package/dist/metafile-esm.json +1 -1
- package/dist/modules/rich-text-editor.props.d.mts +9 -0
- package/dist/modules/rich-text-editor.props.d.ts +9 -0
- package/dist/modules/rich-text-editor.props.js +6 -0
- package/dist/modules/rich-text-editor.props.mjs +1 -1
- package/dist/modules/rich-text-editor.types.d.mts +5 -0
- package/dist/modules/rich-text-editor.types.d.ts +5 -0
- package/dist/rich-text-editor.d.mts +18 -0
- package/dist/rich-text-editor.d.ts +18 -0
- package/dist/rich-text-editor.js +92 -25
- package/dist/rich-text-editor.mjs +5 -5
- package/dist/rte-style-provider.mjs +2 -2
- package/package.json +9 -9
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
EditorToolbar
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-YE6FEVD4.mjs";
|
|
4
4
|
import {
|
|
5
5
|
MpRTEStyleProvider
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-MKTM47RO.mjs";
|
|
7
7
|
import {
|
|
8
8
|
useRichTextEditor
|
|
9
9
|
} from "./chunk-ZRAXSVO5.mjs";
|
|
10
10
|
import {
|
|
11
11
|
richTextEditorEmits,
|
|
12
12
|
richTextEditorProps
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-7BEXEMOE.mjs";
|
|
14
14
|
import {
|
|
15
15
|
createMentionSuggestion
|
|
16
16
|
} from "./chunk-4KJOYLJI.mjs";
|
|
@@ -57,25 +57,40 @@ var MpRichTextEditor = defineComponent({
|
|
|
57
57
|
return false;
|
|
58
58
|
}
|
|
59
59
|
},
|
|
60
|
-
extensions: [
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
60
|
+
extensions: [
|
|
61
|
+
StarterKit.configure({
|
|
62
|
+
heading: {
|
|
63
|
+
levels: [1, 2, 3]
|
|
64
|
+
}
|
|
65
|
+
}),
|
|
66
|
+
Underline,
|
|
67
|
+
TextAlign.configure({
|
|
68
|
+
types: ["heading", "paragraph"]
|
|
69
|
+
}),
|
|
70
|
+
TextStyle,
|
|
71
|
+
Color.configure({
|
|
72
|
+
types: ["textStyle"]
|
|
73
|
+
}),
|
|
74
|
+
Highlight.configure({
|
|
75
|
+
multicolor: true
|
|
76
|
+
}),
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
78
|
+
Link.configure({
|
|
79
|
+
openOnClick: false,
|
|
80
|
+
...props.validateLink && {
|
|
81
|
+
isAllowedUri: props.validateLink
|
|
82
|
+
}
|
|
83
|
+
}),
|
|
84
|
+
Placeholder.configure({
|
|
85
|
+
placeholder: api.value.placeholder || ""
|
|
86
|
+
}),
|
|
87
|
+
CharacterCount.configure({
|
|
88
|
+
limit: api.value.maxlength
|
|
89
|
+
}),
|
|
90
|
+
...props.suggestions && props.suggestions.length > 0 ? [Mention.configure({
|
|
91
|
+
suggestion: createMentionSuggestion(() => props.suggestions || [])
|
|
92
|
+
})] : []
|
|
93
|
+
],
|
|
79
94
|
onFocus({
|
|
80
95
|
editor: editor2,
|
|
81
96
|
event
|
|
@@ -116,7 +131,9 @@ var MpRichTextEditor = defineComponent({
|
|
|
116
131
|
}
|
|
117
132
|
}), [_createVNode(EditorToolbar, _mergeProps({
|
|
118
133
|
"editor": editor,
|
|
119
|
-
"options": api.value.options
|
|
134
|
+
"options": api.value.options,
|
|
135
|
+
"validateLink": props.validateLink,
|
|
136
|
+
"transformLink": props.transformLink
|
|
120
137
|
}, api.value.toolbarProps, toolbarActionHandlers), null), _createVNode(MpRTEStyleProvider, {
|
|
121
138
|
"id": `${api.value.id}-style-provider`
|
|
122
139
|
}, {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
LinkExtension
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-ZO6THAT6.mjs";
|
|
4
4
|
import {
|
|
5
5
|
SingleExtention
|
|
6
6
|
} from "./chunk-25RKPG44.mjs";
|
|
@@ -32,11 +32,19 @@ var EditorToolbar = defineComponent({
|
|
|
32
32
|
},
|
|
33
33
|
options: {
|
|
34
34
|
type: Array
|
|
35
|
+
},
|
|
36
|
+
validateLink: {
|
|
37
|
+
type: Function
|
|
38
|
+
},
|
|
39
|
+
transformLink: {
|
|
40
|
+
type: Function
|
|
35
41
|
}
|
|
36
42
|
},
|
|
37
43
|
setup({
|
|
38
44
|
editor,
|
|
39
|
-
options
|
|
45
|
+
options,
|
|
46
|
+
validateLink,
|
|
47
|
+
transformLink
|
|
40
48
|
}, {
|
|
41
49
|
emit
|
|
42
50
|
}) {
|
|
@@ -174,7 +182,9 @@ var EditorToolbar = defineComponent({
|
|
|
174
182
|
case "textLink":
|
|
175
183
|
return _createVNode(LinkExtension, {
|
|
176
184
|
"tooltipLabel": tooltipLabel,
|
|
177
|
-
"editor": editor
|
|
185
|
+
"editor": editor,
|
|
186
|
+
"validateLink": validateLink,
|
|
187
|
+
"transformLink": transformLink
|
|
178
188
|
}, null);
|
|
179
189
|
default:
|
|
180
190
|
return _createVNode(SingleExtention, {
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
|
|
8
8
|
// src/extensions/link-extension.tsx
|
|
9
9
|
import { withDirectives as _withDirectives, resolveDirective as _resolveDirective, createVNode as _createVNode, Fragment as _Fragment } from "vue";
|
|
10
|
-
import { defineComponent, ref, onMounted, onBeforeUnmount, nextTick, Teleport } from "vue";
|
|
10
|
+
import { defineComponent, ref, onMounted, onBeforeUnmount, nextTick, Teleport, computed } from "vue";
|
|
11
11
|
import { createPopper } from "@popperjs/core";
|
|
12
12
|
import { css } from "@mekari/pixel3-styled-system/css";
|
|
13
13
|
import { MpInput } from "@mekari/pixel3-input";
|
|
@@ -21,11 +21,19 @@ var LinkExtension = defineComponent({
|
|
|
21
21
|
},
|
|
22
22
|
editor: {
|
|
23
23
|
type: Object
|
|
24
|
+
},
|
|
25
|
+
validateLink: {
|
|
26
|
+
type: Function
|
|
27
|
+
},
|
|
28
|
+
transformLink: {
|
|
29
|
+
type: Function
|
|
24
30
|
}
|
|
25
31
|
},
|
|
26
32
|
setup({
|
|
27
33
|
tooltipLabel,
|
|
28
|
-
editor
|
|
34
|
+
editor,
|
|
35
|
+
validateLink,
|
|
36
|
+
transformLink
|
|
29
37
|
}) {
|
|
30
38
|
const {
|
|
31
39
|
isNextTheme
|
|
@@ -38,6 +46,26 @@ var LinkExtension = defineComponent({
|
|
|
38
46
|
let popperInstance = null;
|
|
39
47
|
let linkElement = null;
|
|
40
48
|
let lastClickedElement = null;
|
|
49
|
+
const defaultValidate = /* @__PURE__ */ __name((urlString) => {
|
|
50
|
+
if (!urlString)
|
|
51
|
+
return false;
|
|
52
|
+
return /^(https?:\/\/|mailto:|tel:|\/)/i.test(urlString) || /^[^\s]+\.[^\s]+/.test(urlString);
|
|
53
|
+
}, "defaultValidate");
|
|
54
|
+
const isUrlInvalid = computed(() => {
|
|
55
|
+
if (!url.value || isEditLink.value)
|
|
56
|
+
return false;
|
|
57
|
+
let urlToValidate = url.value;
|
|
58
|
+
if (transformLink) {
|
|
59
|
+
urlToValidate = transformLink(url.value);
|
|
60
|
+
}
|
|
61
|
+
if (validateLink) {
|
|
62
|
+
return !validateLink(urlToValidate, {
|
|
63
|
+
defaultValidate,
|
|
64
|
+
protocols: ["http", "https", "mailto", "tel"]
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return !defaultValidate(urlToValidate);
|
|
68
|
+
});
|
|
41
69
|
const onClickOutside = /* @__PURE__ */ __name((event) => {
|
|
42
70
|
if (popoverRef.value && !popoverRef.value.contains(event.target) && event.target !== lastClickedElement) {
|
|
43
71
|
onClosePopover();
|
|
@@ -107,9 +135,13 @@ var LinkExtension = defineComponent({
|
|
|
107
135
|
}, "onUnlink");
|
|
108
136
|
const onSetLink = /* @__PURE__ */ __name(() => {
|
|
109
137
|
if (url.value && editor) {
|
|
138
|
+
let finalUrl = url.value;
|
|
139
|
+
if (transformLink) {
|
|
140
|
+
finalUrl = transformLink(url.value);
|
|
141
|
+
}
|
|
110
142
|
;
|
|
111
143
|
editor.chain().focus().extendMarkRange("link").setLink({
|
|
112
|
-
href:
|
|
144
|
+
href: finalUrl
|
|
113
145
|
}).run();
|
|
114
146
|
}
|
|
115
147
|
onClosePopover();
|
|
@@ -140,7 +172,7 @@ var LinkExtension = defineComponent({
|
|
|
140
172
|
if (link) {
|
|
141
173
|
event.preventDefault();
|
|
142
174
|
linkElement = link;
|
|
143
|
-
url.value = linkElement.href;
|
|
175
|
+
url.value = linkElement.getAttribute("href") || "";
|
|
144
176
|
onOpenPopover(linkElement);
|
|
145
177
|
}
|
|
146
178
|
});
|
|
@@ -189,6 +221,7 @@ var LinkExtension = defineComponent({
|
|
|
189
221
|
"onUpdate:modelValue": ($event) => url.value = $event,
|
|
190
222
|
"placeholder": "Insert URL here",
|
|
191
223
|
"isDisabled": isEditLink.value,
|
|
224
|
+
"isInvalid": isUrlInvalid.value,
|
|
192
225
|
"onKeyup": (event) => {
|
|
193
226
|
if (event.key === "Enter")
|
|
194
227
|
onSetLink();
|
|
@@ -199,6 +232,7 @@ var LinkExtension = defineComponent({
|
|
|
199
232
|
"onClick": onEditLink
|
|
200
233
|
}, null) : _createVNode(MpButton, {
|
|
201
234
|
"leftIcon": "check",
|
|
235
|
+
"isDisabled": isUrlInvalid.value,
|
|
202
236
|
"onClick": onSetLink
|
|
203
237
|
}, null), isEditLink.value && _createVNode(MpButton, {
|
|
204
238
|
"leftIcon": "newtab",
|
|
@@ -12,6 +12,15 @@ declare const EditorToolbar: vue.DefineComponent<{
|
|
|
12
12
|
options: {
|
|
13
13
|
type: PropType<ToolbarOption[][]>;
|
|
14
14
|
};
|
|
15
|
+
validateLink: {
|
|
16
|
+
type: PropType<(url: string, ctx: {
|
|
17
|
+
defaultValidate: (url: string) => boolean;
|
|
18
|
+
protocols: string[];
|
|
19
|
+
}) => boolean>;
|
|
20
|
+
};
|
|
21
|
+
transformLink: {
|
|
22
|
+
type: PropType<(url: string) => string>;
|
|
23
|
+
};
|
|
15
24
|
}, () => vue_jsx_runtime.JSX.Element, unknown, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, ("clickImage" | "clickFile" | "clickAudio" | "clickMention" | "clickLocation")[], "clickImage" | "clickFile" | "clickAudio" | "clickMention" | "clickLocation", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
16
25
|
editor: {
|
|
17
26
|
type: PropType<Editor>;
|
|
@@ -19,6 +28,15 @@ declare const EditorToolbar: vue.DefineComponent<{
|
|
|
19
28
|
options: {
|
|
20
29
|
type: PropType<ToolbarOption[][]>;
|
|
21
30
|
};
|
|
31
|
+
validateLink: {
|
|
32
|
+
type: PropType<(url: string, ctx: {
|
|
33
|
+
defaultValidate: (url: string) => boolean;
|
|
34
|
+
protocols: string[];
|
|
35
|
+
}) => boolean>;
|
|
36
|
+
};
|
|
37
|
+
transformLink: {
|
|
38
|
+
type: PropType<(url: string) => string>;
|
|
39
|
+
};
|
|
22
40
|
}>> & {
|
|
23
41
|
onClickImage?: ((...args: any[]) => any) | undefined;
|
|
24
42
|
onClickFile?: ((...args: any[]) => any) | undefined;
|
package/dist/editor-toolbar.d.ts
CHANGED
|
@@ -12,6 +12,15 @@ declare const EditorToolbar: vue.DefineComponent<{
|
|
|
12
12
|
options: {
|
|
13
13
|
type: PropType<ToolbarOption[][]>;
|
|
14
14
|
};
|
|
15
|
+
validateLink: {
|
|
16
|
+
type: PropType<(url: string, ctx: {
|
|
17
|
+
defaultValidate: (url: string) => boolean;
|
|
18
|
+
protocols: string[];
|
|
19
|
+
}) => boolean>;
|
|
20
|
+
};
|
|
21
|
+
transformLink: {
|
|
22
|
+
type: PropType<(url: string) => string>;
|
|
23
|
+
};
|
|
15
24
|
}, () => vue_jsx_runtime.JSX.Element, unknown, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, ("clickImage" | "clickFile" | "clickAudio" | "clickMention" | "clickLocation")[], "clickImage" | "clickFile" | "clickAudio" | "clickMention" | "clickLocation", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
16
25
|
editor: {
|
|
17
26
|
type: PropType<Editor>;
|
|
@@ -19,6 +28,15 @@ declare const EditorToolbar: vue.DefineComponent<{
|
|
|
19
28
|
options: {
|
|
20
29
|
type: PropType<ToolbarOption[][]>;
|
|
21
30
|
};
|
|
31
|
+
validateLink: {
|
|
32
|
+
type: PropType<(url: string, ctx: {
|
|
33
|
+
defaultValidate: (url: string) => boolean;
|
|
34
|
+
protocols: string[];
|
|
35
|
+
}) => boolean>;
|
|
36
|
+
};
|
|
37
|
+
transformLink: {
|
|
38
|
+
type: PropType<(url: string) => string>;
|
|
39
|
+
};
|
|
22
40
|
}>> & {
|
|
23
41
|
onClickImage?: ((...args: any[]) => any) | undefined;
|
|
24
42
|
onClickFile?: ((...args: any[]) => any) | undefined;
|
package/dist/editor-toolbar.js
CHANGED
|
@@ -805,11 +805,19 @@ var LinkExtension = (0, import_vue12.defineComponent)({
|
|
|
805
805
|
},
|
|
806
806
|
editor: {
|
|
807
807
|
type: Object
|
|
808
|
+
},
|
|
809
|
+
validateLink: {
|
|
810
|
+
type: Function
|
|
811
|
+
},
|
|
812
|
+
transformLink: {
|
|
813
|
+
type: Function
|
|
808
814
|
}
|
|
809
815
|
},
|
|
810
816
|
setup({
|
|
811
817
|
tooltipLabel,
|
|
812
|
-
editor
|
|
818
|
+
editor,
|
|
819
|
+
validateLink,
|
|
820
|
+
transformLink
|
|
813
821
|
}) {
|
|
814
822
|
const {
|
|
815
823
|
isNextTheme
|
|
@@ -822,6 +830,26 @@ var LinkExtension = (0, import_vue12.defineComponent)({
|
|
|
822
830
|
let popperInstance = null;
|
|
823
831
|
let linkElement = null;
|
|
824
832
|
let lastClickedElement = null;
|
|
833
|
+
const defaultValidate = /* @__PURE__ */ __name((urlString) => {
|
|
834
|
+
if (!urlString)
|
|
835
|
+
return false;
|
|
836
|
+
return /^(https?:\/\/|mailto:|tel:|\/)/i.test(urlString) || /^[^\s]+\.[^\s]+/.test(urlString);
|
|
837
|
+
}, "defaultValidate");
|
|
838
|
+
const isUrlInvalid = (0, import_vue12.computed)(() => {
|
|
839
|
+
if (!url.value || isEditLink.value)
|
|
840
|
+
return false;
|
|
841
|
+
let urlToValidate = url.value;
|
|
842
|
+
if (transformLink) {
|
|
843
|
+
urlToValidate = transformLink(url.value);
|
|
844
|
+
}
|
|
845
|
+
if (validateLink) {
|
|
846
|
+
return !validateLink(urlToValidate, {
|
|
847
|
+
defaultValidate,
|
|
848
|
+
protocols: ["http", "https", "mailto", "tel"]
|
|
849
|
+
});
|
|
850
|
+
}
|
|
851
|
+
return !defaultValidate(urlToValidate);
|
|
852
|
+
});
|
|
825
853
|
const onClickOutside = /* @__PURE__ */ __name((event) => {
|
|
826
854
|
if (popoverRef.value && !popoverRef.value.contains(event.target) && event.target !== lastClickedElement) {
|
|
827
855
|
onClosePopover();
|
|
@@ -891,9 +919,13 @@ var LinkExtension = (0, import_vue12.defineComponent)({
|
|
|
891
919
|
}, "onUnlink");
|
|
892
920
|
const onSetLink = /* @__PURE__ */ __name(() => {
|
|
893
921
|
if (url.value && editor) {
|
|
922
|
+
let finalUrl = url.value;
|
|
923
|
+
if (transformLink) {
|
|
924
|
+
finalUrl = transformLink(url.value);
|
|
925
|
+
}
|
|
894
926
|
;
|
|
895
927
|
editor.chain().focus().extendMarkRange("link").setLink({
|
|
896
|
-
href:
|
|
928
|
+
href: finalUrl
|
|
897
929
|
}).run();
|
|
898
930
|
}
|
|
899
931
|
onClosePopover();
|
|
@@ -924,7 +956,7 @@ var LinkExtension = (0, import_vue12.defineComponent)({
|
|
|
924
956
|
if (link) {
|
|
925
957
|
event.preventDefault();
|
|
926
958
|
linkElement = link;
|
|
927
|
-
url.value = linkElement.href;
|
|
959
|
+
url.value = linkElement.getAttribute("href") || "";
|
|
928
960
|
onOpenPopover(linkElement);
|
|
929
961
|
}
|
|
930
962
|
});
|
|
@@ -973,6 +1005,7 @@ var LinkExtension = (0, import_vue12.defineComponent)({
|
|
|
973
1005
|
"onUpdate:modelValue": ($event) => url.value = $event,
|
|
974
1006
|
"placeholder": "Insert URL here",
|
|
975
1007
|
"isDisabled": isEditLink.value,
|
|
1008
|
+
"isInvalid": isUrlInvalid.value,
|
|
976
1009
|
"onKeyup": (event) => {
|
|
977
1010
|
if (event.key === "Enter")
|
|
978
1011
|
onSetLink();
|
|
@@ -983,6 +1016,7 @@ var LinkExtension = (0, import_vue12.defineComponent)({
|
|
|
983
1016
|
"onClick": onEditLink
|
|
984
1017
|
}, null) : (0, import_vue11.createVNode)(import_pixel3_button.MpButton, {
|
|
985
1018
|
"leftIcon": "check",
|
|
1019
|
+
"isDisabled": isUrlInvalid.value,
|
|
986
1020
|
"onClick": onSetLink
|
|
987
1021
|
}, null), isEditLink.value && (0, import_vue11.createVNode)(import_pixel3_button.MpButton, {
|
|
988
1022
|
"leftIcon": "newtab",
|
|
@@ -1012,11 +1046,19 @@ var EditorToolbar = (0, import_vue14.defineComponent)({
|
|
|
1012
1046
|
},
|
|
1013
1047
|
options: {
|
|
1014
1048
|
type: Array
|
|
1049
|
+
},
|
|
1050
|
+
validateLink: {
|
|
1051
|
+
type: Function
|
|
1052
|
+
},
|
|
1053
|
+
transformLink: {
|
|
1054
|
+
type: Function
|
|
1015
1055
|
}
|
|
1016
1056
|
},
|
|
1017
1057
|
setup({
|
|
1018
1058
|
editor,
|
|
1019
|
-
options
|
|
1059
|
+
options,
|
|
1060
|
+
validateLink,
|
|
1061
|
+
transformLink
|
|
1020
1062
|
}, {
|
|
1021
1063
|
emit
|
|
1022
1064
|
}) {
|
|
@@ -1154,7 +1196,9 @@ var EditorToolbar = (0, import_vue14.defineComponent)({
|
|
|
1154
1196
|
case "textLink":
|
|
1155
1197
|
return (0, import_vue13.createVNode)(LinkExtension, {
|
|
1156
1198
|
"tooltipLabel": tooltipLabel,
|
|
1157
|
-
"editor": editor
|
|
1199
|
+
"editor": editor,
|
|
1200
|
+
"validateLink": validateLink,
|
|
1201
|
+
"transformLink": transformLink
|
|
1158
1202
|
}, null);
|
|
1159
1203
|
default:
|
|
1160
1204
|
return (0, import_vue13.createVNode)(SingleExtention, {
|
package/dist/editor-toolbar.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
EditorToolbar
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-YE6FEVD4.mjs";
|
|
4
4
|
import "./chunk-VYCDVS5I.mjs";
|
|
5
|
-
import "./chunk-
|
|
5
|
+
import "./chunk-ZO6THAT6.mjs";
|
|
6
6
|
import "./chunk-25RKPG44.mjs";
|
|
7
7
|
import "./chunk-UBJOZ2IA.mjs";
|
|
8
8
|
import "./chunk-5S2LSGJV.mjs";
|
package/dist/extensions/index.js
CHANGED
|
@@ -804,11 +804,19 @@ var LinkExtension = (0, import_vue12.defineComponent)({
|
|
|
804
804
|
},
|
|
805
805
|
editor: {
|
|
806
806
|
type: Object
|
|
807
|
+
},
|
|
808
|
+
validateLink: {
|
|
809
|
+
type: Function
|
|
810
|
+
},
|
|
811
|
+
transformLink: {
|
|
812
|
+
type: Function
|
|
807
813
|
}
|
|
808
814
|
},
|
|
809
815
|
setup({
|
|
810
816
|
tooltipLabel,
|
|
811
|
-
editor
|
|
817
|
+
editor,
|
|
818
|
+
validateLink,
|
|
819
|
+
transformLink
|
|
812
820
|
}) {
|
|
813
821
|
const {
|
|
814
822
|
isNextTheme
|
|
@@ -821,6 +829,26 @@ var LinkExtension = (0, import_vue12.defineComponent)({
|
|
|
821
829
|
let popperInstance = null;
|
|
822
830
|
let linkElement = null;
|
|
823
831
|
let lastClickedElement = null;
|
|
832
|
+
const defaultValidate = /* @__PURE__ */ __name((urlString) => {
|
|
833
|
+
if (!urlString)
|
|
834
|
+
return false;
|
|
835
|
+
return /^(https?:\/\/|mailto:|tel:|\/)/i.test(urlString) || /^[^\s]+\.[^\s]+/.test(urlString);
|
|
836
|
+
}, "defaultValidate");
|
|
837
|
+
const isUrlInvalid = (0, import_vue12.computed)(() => {
|
|
838
|
+
if (!url.value || isEditLink.value)
|
|
839
|
+
return false;
|
|
840
|
+
let urlToValidate = url.value;
|
|
841
|
+
if (transformLink) {
|
|
842
|
+
urlToValidate = transformLink(url.value);
|
|
843
|
+
}
|
|
844
|
+
if (validateLink) {
|
|
845
|
+
return !validateLink(urlToValidate, {
|
|
846
|
+
defaultValidate,
|
|
847
|
+
protocols: ["http", "https", "mailto", "tel"]
|
|
848
|
+
});
|
|
849
|
+
}
|
|
850
|
+
return !defaultValidate(urlToValidate);
|
|
851
|
+
});
|
|
824
852
|
const onClickOutside = /* @__PURE__ */ __name((event) => {
|
|
825
853
|
if (popoverRef.value && !popoverRef.value.contains(event.target) && event.target !== lastClickedElement) {
|
|
826
854
|
onClosePopover();
|
|
@@ -890,9 +918,13 @@ var LinkExtension = (0, import_vue12.defineComponent)({
|
|
|
890
918
|
}, "onUnlink");
|
|
891
919
|
const onSetLink = /* @__PURE__ */ __name(() => {
|
|
892
920
|
if (url.value && editor) {
|
|
921
|
+
let finalUrl = url.value;
|
|
922
|
+
if (transformLink) {
|
|
923
|
+
finalUrl = transformLink(url.value);
|
|
924
|
+
}
|
|
893
925
|
;
|
|
894
926
|
editor.chain().focus().extendMarkRange("link").setLink({
|
|
895
|
-
href:
|
|
927
|
+
href: finalUrl
|
|
896
928
|
}).run();
|
|
897
929
|
}
|
|
898
930
|
onClosePopover();
|
|
@@ -923,7 +955,7 @@ var LinkExtension = (0, import_vue12.defineComponent)({
|
|
|
923
955
|
if (link) {
|
|
924
956
|
event.preventDefault();
|
|
925
957
|
linkElement = link;
|
|
926
|
-
url.value = linkElement.href;
|
|
958
|
+
url.value = linkElement.getAttribute("href") || "";
|
|
927
959
|
onOpenPopover(linkElement);
|
|
928
960
|
}
|
|
929
961
|
});
|
|
@@ -972,6 +1004,7 @@ var LinkExtension = (0, import_vue12.defineComponent)({
|
|
|
972
1004
|
"onUpdate:modelValue": ($event) => url.value = $event,
|
|
973
1005
|
"placeholder": "Insert URL here",
|
|
974
1006
|
"isDisabled": isEditLink.value,
|
|
1007
|
+
"isInvalid": isUrlInvalid.value,
|
|
975
1008
|
"onKeyup": (event) => {
|
|
976
1009
|
if (event.key === "Enter")
|
|
977
1010
|
onSetLink();
|
|
@@ -982,6 +1015,7 @@ var LinkExtension = (0, import_vue12.defineComponent)({
|
|
|
982
1015
|
"onClick": onEditLink
|
|
983
1016
|
}, null) : (0, import_vue11.createVNode)(import_pixel3_button.MpButton, {
|
|
984
1017
|
"leftIcon": "check",
|
|
1018
|
+
"isDisabled": isUrlInvalid.value,
|
|
985
1019
|
"onClick": onSetLink
|
|
986
1020
|
}, null), isEditLink.value && (0, import_vue11.createVNode)(import_pixel3_button.MpButton, {
|
|
987
1021
|
"leftIcon": "newtab",
|
|
@@ -10,6 +10,15 @@ declare const LinkExtension: vue.DefineComponent<{
|
|
|
10
10
|
editor: {
|
|
11
11
|
type: PropType<Editor>;
|
|
12
12
|
};
|
|
13
|
+
validateLink: {
|
|
14
|
+
type: PropType<(url: string, ctx: {
|
|
15
|
+
defaultValidate: (url: string) => boolean;
|
|
16
|
+
protocols: string[];
|
|
17
|
+
}) => boolean>;
|
|
18
|
+
};
|
|
19
|
+
transformLink: {
|
|
20
|
+
type: PropType<(url: string) => string>;
|
|
21
|
+
};
|
|
13
22
|
}, () => vue_jsx_runtime.JSX.Element, unknown, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
14
23
|
tooltipLabel: {
|
|
15
24
|
type: StringConstructor;
|
|
@@ -17,6 +26,15 @@ declare const LinkExtension: vue.DefineComponent<{
|
|
|
17
26
|
editor: {
|
|
18
27
|
type: PropType<Editor>;
|
|
19
28
|
};
|
|
29
|
+
validateLink: {
|
|
30
|
+
type: PropType<(url: string, ctx: {
|
|
31
|
+
defaultValidate: (url: string) => boolean;
|
|
32
|
+
protocols: string[];
|
|
33
|
+
}) => boolean>;
|
|
34
|
+
};
|
|
35
|
+
transformLink: {
|
|
36
|
+
type: PropType<(url: string) => string>;
|
|
37
|
+
};
|
|
20
38
|
}>>, {}, {}>;
|
|
21
39
|
|
|
22
40
|
export { LinkExtension };
|
|
@@ -10,6 +10,15 @@ declare const LinkExtension: vue.DefineComponent<{
|
|
|
10
10
|
editor: {
|
|
11
11
|
type: PropType<Editor>;
|
|
12
12
|
};
|
|
13
|
+
validateLink: {
|
|
14
|
+
type: PropType<(url: string, ctx: {
|
|
15
|
+
defaultValidate: (url: string) => boolean;
|
|
16
|
+
protocols: string[];
|
|
17
|
+
}) => boolean>;
|
|
18
|
+
};
|
|
19
|
+
transformLink: {
|
|
20
|
+
type: PropType<(url: string) => string>;
|
|
21
|
+
};
|
|
13
22
|
}, () => vue_jsx_runtime.JSX.Element, unknown, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
14
23
|
tooltipLabel: {
|
|
15
24
|
type: StringConstructor;
|
|
@@ -17,6 +26,15 @@ declare const LinkExtension: vue.DefineComponent<{
|
|
|
17
26
|
editor: {
|
|
18
27
|
type: PropType<Editor>;
|
|
19
28
|
};
|
|
29
|
+
validateLink: {
|
|
30
|
+
type: PropType<(url: string, ctx: {
|
|
31
|
+
defaultValidate: (url: string) => boolean;
|
|
32
|
+
protocols: string[];
|
|
33
|
+
}) => boolean>;
|
|
34
|
+
};
|
|
35
|
+
transformLink: {
|
|
36
|
+
type: PropType<(url: string) => string>;
|
|
37
|
+
};
|
|
20
38
|
}>>, {}, {}>;
|
|
21
39
|
|
|
22
40
|
export { LinkExtension };
|