@kungal/editor-vue 0.31.1 → 0.32.1
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/CHANGELOG.md +32 -0
- package/dist/active-marks.d.ts +12 -0
- package/dist/active-marks.d.ts.map +1 -0
- package/dist/components/EditorToolbar.vue.d.ts.map +1 -1
- package/dist/components/KunEditor.vue.d.ts +1 -0
- package/dist/components/KunEditor.vue.d.ts.map +1 -1
- package/dist/components/MilkdownEditor.vue.d.ts.map +1 -1
- package/dist/components/SelectionTooltip.vue.d.ts.map +1 -1
- package/dist/components/ToolbarHost.vue.d.ts +1 -0
- package/dist/components/ToolbarHost.vue.d.ts.map +1 -1
- package/dist/context.d.ts +7 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +361 -307
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,38 +1,68 @@
|
|
|
1
|
-
import { Fragment as e, computed as t, createBlock as n, createCommentVNode as r, createElementBlock as i, createElementVNode as a, createVNode as o, defineComponent as s, guardReactiveProps as c, inject as l, nextTick as u, normalizeProps as d, onBeforeUnmount as f, onMounted as p, openBlock as m, provide as h,
|
|
2
|
-
import { Milkdown as
|
|
3
|
-
import { ProsemirrorAdapterProvider as
|
|
4
|
-
import { parseHeadings as
|
|
5
|
-
import { Editor as
|
|
6
|
-
import { listenerCtx as
|
|
7
|
-
import { SlashProvider as
|
|
8
|
-
import { TooltipProvider as
|
|
9
|
-
import { callCommand as
|
|
10
|
-
import { TextSelection as
|
|
11
|
-
import { createCodeBlockCommand as
|
|
12
|
-
import { createKunEditorPlugins as
|
|
13
|
-
import { toggleStrikethroughCommand as
|
|
14
|
-
import { Annotation as
|
|
1
|
+
import { Fragment as e, computed as t, createBlock as n, createCommentVNode as r, createElementBlock as i, createElementVNode as a, createVNode as o, defineComponent as s, guardReactiveProps as c, inject as l, nextTick as u, normalizeProps as d, onBeforeUnmount as f, onMounted as p, openBlock as m, provide as h, reactive as g, ref as _, renderList as v, renderSlot as y, toDisplayString as b, unref as x, vShow as S, watch as C, withCtx as w, withDirectives as T, withModifiers as E } from "vue";
|
|
2
|
+
import { Milkdown as D, MilkdownProvider as O, useEditor as k, useInstance as A } from "@milkdown/vue";
|
|
3
|
+
import { ProsemirrorAdapterProvider as j, usePluginViewContext as M, usePluginViewFactory as N } from "@prosemirror-adapter/vue";
|
|
4
|
+
import { parseHeadings as P, parseHeadings as ee } from "@kungal/editor-core";
|
|
5
|
+
import { Editor as F, defaultValueCtx as I, editorViewCtx as L, editorViewOptionsCtx as R, rootCtx as z } from "@milkdown/kit/core";
|
|
6
|
+
import { listenerCtx as B } from "@milkdown/kit/plugin/listener";
|
|
7
|
+
import { SlashProvider as V, slashFactory as H } from "@milkdown/kit/plugin/slash";
|
|
8
|
+
import { TooltipProvider as te, tooltipFactory as U } from "@milkdown/kit/plugin/tooltip";
|
|
9
|
+
import { $prose as ne, callCommand as W, replaceAll as G } from "@milkdown/kit/utils";
|
|
10
|
+
import { Plugin as K, PluginKey as q, TextSelection as re } from "@milkdown/kit/prose/state";
|
|
11
|
+
import { createCodeBlockCommand as ie, emphasisSchema as ae, inlineCodeSchema as J, insertHrCommand as oe, insertImageCommand as se, strongSchema as ce, toggleEmphasisCommand as le, toggleInlineCodeCommand as ue, toggleStrongCommand as de, wrapInBlockquoteCommand as fe, wrapInBulletListCommand as pe, wrapInOrderedListCommand as me } from "@milkdown/kit/preset/commonmark";
|
|
12
|
+
import { createKunEditorPlugins as he, insertKunSpoilerCommand as ge, insertLinkCommand as _e, insertMentionCommand as ve, insertQuoteCommand as ye, kunCM as be, mentionId as xe, setHeadingCommand as Se, startImageUpload as Ce } from "@kungal/editor-core/preset";
|
|
13
|
+
import { strikethroughSchema as we, toggleStrikethroughCommand as Te } from "@milkdown/kit/preset/gfm";
|
|
14
|
+
import { Annotation as Ee, EditorState as De } from "@codemirror/state";
|
|
15
15
|
import { EditorView as Y } from "@codemirror/view";
|
|
16
|
-
import { markdown as
|
|
17
|
-
import { basicSetup as
|
|
18
|
-
//#region src/
|
|
19
|
-
var
|
|
16
|
+
import { markdown as Oe } from "@codemirror/lang-markdown";
|
|
17
|
+
import { basicSetup as ke } from "codemirror";
|
|
18
|
+
//#region src/active-marks.ts
|
|
19
|
+
var Ae = [
|
|
20
|
+
"bold",
|
|
21
|
+
"italic",
|
|
22
|
+
"strike",
|
|
23
|
+
"code"
|
|
24
|
+
], je = {
|
|
25
|
+
bold: ce,
|
|
26
|
+
italic: ae,
|
|
27
|
+
strike: we,
|
|
28
|
+
code: J
|
|
29
|
+
}, Me = () => ({
|
|
30
|
+
bold: !1,
|
|
31
|
+
italic: !1,
|
|
32
|
+
strike: !1,
|
|
33
|
+
code: !1
|
|
34
|
+
}), Ne = Object.freeze(Me()), Pe = (e, t) => {
|
|
35
|
+
let { from: n, $from: r, to: i, empty: a } = e.selection, o = Me();
|
|
36
|
+
for (let s of Ae) {
|
|
37
|
+
let c = je[s].type(t);
|
|
38
|
+
o[s] = a ? !!c.isInSet(e.storedMarks ?? r.marks()) : e.doc.rangeHasMark(n, i, c);
|
|
39
|
+
}
|
|
40
|
+
return o;
|
|
41
|
+
}, Fe = (e, t, n) => {
|
|
42
|
+
let r = Pe(e, t);
|
|
43
|
+
for (let e of Ae) n[e] !== r[e] && (n[e] = r[e]);
|
|
44
|
+
}, Ie = new q("KUN_ACTIVE_MARKS"), Le = (e) => ne((t) => new K({
|
|
45
|
+
key: Ie,
|
|
46
|
+
view: (n) => (Fe(n.state, t, e), { update(n) {
|
|
47
|
+
Fe(n.state, t, e);
|
|
48
|
+
} })
|
|
49
|
+
})), X = Symbol("kun-editor-context"), Re = [
|
|
20
50
|
"data-active",
|
|
21
51
|
"onMousedown",
|
|
22
52
|
"onMouseenter"
|
|
23
|
-
],
|
|
53
|
+
], ze = ["src", "alt"], Be = {
|
|
24
54
|
key: 1,
|
|
25
55
|
class: "kun-mention-dropdown__avatar kun-mention-dropdown__avatar--fallback"
|
|
26
|
-
},
|
|
56
|
+
}, Ve = { class: "kun-mention-dropdown__name" }, He = {
|
|
27
57
|
key: 1,
|
|
28
58
|
class: "kun-mention-dropdown__hint"
|
|
29
|
-
},
|
|
59
|
+
}, Ue = {
|
|
30
60
|
key: 2,
|
|
31
61
|
class: "kun-mention-dropdown__hint"
|
|
32
|
-
},
|
|
62
|
+
}, We = {
|
|
33
63
|
key: 3,
|
|
34
64
|
class: "kun-mention-dropdown__hint"
|
|
35
|
-
},
|
|
65
|
+
}, Ge = /* @__PURE__ */ s({
|
|
36
66
|
__name: "MentionDropdown",
|
|
37
67
|
setup(n) {
|
|
38
68
|
let r = /(?:^|\s)@([^\s@]{0,30})$/, o = l(X), s = o?.adapters.searchMentionUsers, c = t(() => (o?.locale ?? "zh-cn").toLowerCase().startsWith("en")), u = t(() => c.value ? {
|
|
@@ -43,8 +73,8 @@ var X = Symbol("kun-editor-context"), Se = [
|
|
|
43
73
|
searching: "搜索中…",
|
|
44
74
|
empty: "无匹配用户",
|
|
45
75
|
prompt: "输入用户名以搜索"
|
|
46
|
-
}), { view: d, prevState: h } =
|
|
47
|
-
A &&= (clearTimeout(A), null),
|
|
76
|
+
}), { view: d, prevState: h } = M(), g = _(null), y, x = _(!1), S = _(""), w = _([]), T = _(0), D = _(!1), O = null, k = 0, A = null, j = () => {
|
|
77
|
+
A &&= (clearTimeout(A), null), S.value = "", w.value = [], T.value = 0, D.value = !1, O = null;
|
|
48
78
|
}, N = (e) => {
|
|
49
79
|
if (A &&= (clearTimeout(A), null), !e || !s) {
|
|
50
80
|
w.value = [], D.value = !1;
|
|
@@ -57,88 +87,88 @@ var X = Symbol("kun-editor-context"), Se = [
|
|
|
57
87
|
} catch {
|
|
58
88
|
n = [];
|
|
59
89
|
}
|
|
60
|
-
t === k && (w.value = n ?? [],
|
|
90
|
+
t === k && (w.value = n ?? [], T.value = 0, D.value = !1);
|
|
61
91
|
}, 180);
|
|
62
|
-
},
|
|
92
|
+
}, P = (e) => {
|
|
63
93
|
let { selection: t } = e.state;
|
|
64
94
|
if (!t.empty) return null;
|
|
65
95
|
let { $from: n } = t, i = n.parent.textBetween(Math.max(0, n.parentOffset - 100), n.parentOffset, void 0, "").match(r);
|
|
66
96
|
return i ? i[1] ?? "" : null;
|
|
67
|
-
},
|
|
68
|
-
let t =
|
|
97
|
+
}, ee = (e) => {
|
|
98
|
+
let t = P(e);
|
|
69
99
|
if (t === null) return !1;
|
|
70
100
|
let n = e.state.selection.$from.pos;
|
|
71
101
|
return O = {
|
|
72
102
|
from: n - (t.length + 1),
|
|
73
103
|
to: n
|
|
74
|
-
}, t !==
|
|
75
|
-
},
|
|
104
|
+
}, t !== S.value && (S.value = t, N(t)), !0;
|
|
105
|
+
}, F = (e) => {
|
|
76
106
|
let t = d.value;
|
|
77
107
|
if (!t || !O) return;
|
|
78
|
-
let n = t.state.schema.nodes[
|
|
108
|
+
let n = t.state.schema.nodes[xe];
|
|
79
109
|
if (!n) return;
|
|
80
110
|
let r = n.create({
|
|
81
111
|
userId: e.id,
|
|
82
112
|
name: e.name
|
|
83
113
|
}), { from: i, to: a } = O, o = t.state.tr.replaceWith(i, a, r), s = i + r.nodeSize;
|
|
84
|
-
o.insertText(" ", s), o.setSelection(
|
|
85
|
-
},
|
|
114
|
+
o.insertText(" ", s), o.setSelection(re.create(o.doc, s + 1)), t.dispatch(o.scrollIntoView()), t.focus(), y.hide();
|
|
115
|
+
}, I = (e) => {
|
|
86
116
|
if (!x.value || !w.value.length) {
|
|
87
|
-
x.value && e.key === "Escape" && (e.preventDefault(),
|
|
117
|
+
x.value && e.key === "Escape" && (e.preventDefault(), y.hide());
|
|
88
118
|
return;
|
|
89
119
|
}
|
|
90
120
|
let t = w.value.length - 1;
|
|
91
121
|
switch (e.key) {
|
|
92
122
|
case "ArrowDown":
|
|
93
|
-
e.preventDefault(), e.stopPropagation(),
|
|
123
|
+
e.preventDefault(), e.stopPropagation(), T.value = T.value >= t ? 0 : T.value + 1;
|
|
94
124
|
break;
|
|
95
125
|
case "ArrowUp":
|
|
96
|
-
e.preventDefault(), e.stopPropagation(),
|
|
126
|
+
e.preventDefault(), e.stopPropagation(), T.value = T.value <= 0 ? t : T.value - 1;
|
|
97
127
|
break;
|
|
98
128
|
case "Enter":
|
|
99
129
|
case "Tab": {
|
|
100
|
-
let t = w.value[
|
|
101
|
-
t && (e.preventDefault(), e.stopPropagation(),
|
|
130
|
+
let t = w.value[T.value];
|
|
131
|
+
t && (e.preventDefault(), e.stopPropagation(), F(t));
|
|
102
132
|
break;
|
|
103
133
|
}
|
|
104
134
|
case "Escape":
|
|
105
|
-
e.preventDefault(), e.stopPropagation(),
|
|
135
|
+
e.preventDefault(), e.stopPropagation(), y.hide();
|
|
106
136
|
break;
|
|
107
137
|
}
|
|
108
138
|
};
|
|
109
139
|
return p(() => {
|
|
110
|
-
|
|
111
|
-
content:
|
|
140
|
+
y = new V({
|
|
141
|
+
content: g.value,
|
|
112
142
|
trigger: "@",
|
|
113
|
-
shouldShow:
|
|
143
|
+
shouldShow: ee,
|
|
114
144
|
debounce: 0
|
|
115
|
-
}),
|
|
145
|
+
}), y.onShow = () => {
|
|
116
146
|
x.value = !0;
|
|
117
|
-
},
|
|
118
|
-
x.value = !1,
|
|
119
|
-
},
|
|
120
|
-
}),
|
|
121
|
-
|
|
147
|
+
}, y.onHide = () => {
|
|
148
|
+
x.value = !1, j();
|
|
149
|
+
}, y.update(d.value, h.value), window.addEventListener("keydown", I, !0);
|
|
150
|
+
}), C([d, h], () => {
|
|
151
|
+
y?.update(d.value, h.value);
|
|
122
152
|
}), f(() => {
|
|
123
|
-
A && clearTimeout(A), window.removeEventListener("keydown",
|
|
153
|
+
A && clearTimeout(A), window.removeEventListener("keydown", I, !0), y?.destroy();
|
|
124
154
|
}), (t, n) => (m(), i("div", {
|
|
125
155
|
ref_key: "divRef",
|
|
126
|
-
ref:
|
|
156
|
+
ref: g,
|
|
127
157
|
class: "kun-mention-dropdown",
|
|
128
158
|
"data-show": "false"
|
|
129
|
-
}, [w.value.length ? (m(!0), i(e, { key: 0 },
|
|
159
|
+
}, [w.value.length ? (m(!0), i(e, { key: 0 }, v(w.value, (e, t) => (m(), i("button", {
|
|
130
160
|
key: e.id,
|
|
131
161
|
type: "button",
|
|
132
162
|
class: "kun-mention-dropdown__item",
|
|
133
|
-
"data-active": t ===
|
|
134
|
-
onMousedown:
|
|
135
|
-
onMouseenter: (e) =>
|
|
163
|
+
"data-active": t === T.value,
|
|
164
|
+
onMousedown: E((t) => F(e), ["prevent"]),
|
|
165
|
+
onMouseenter: (e) => T.value = t
|
|
136
166
|
}, [e.avatar ? (m(), i("img", {
|
|
137
167
|
key: 0,
|
|
138
168
|
src: e.avatar,
|
|
139
169
|
alt: e.name,
|
|
140
170
|
class: "kun-mention-dropdown__avatar"
|
|
141
|
-
}, null, 8,
|
|
171
|
+
}, null, 8, ze)) : (m(), i("span", Be, b(e.name.charAt(0)), 1)), a("span", Ve, b(e.name), 1)], 40, Re))), 128)) : D.value ? (m(), i("div", He, b(u.value.searching), 1)) : S.value ? (m(), i("div", Ue, b(u.value.empty), 1)) : (m(), i("div", We, b(u.value.prompt), 1))], 512));
|
|
142
172
|
}
|
|
143
173
|
}), Z = (e) => `<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${e}</svg>`, Q = (e, t = 13) => `<svg viewBox="0 0 24 24" width="18" height="18" aria-hidden="true"><text x="12" y="12" dominant-baseline="central" text-anchor="middle" font-size="${t}" font-weight="700" font-family="ui-sans-serif, system-ui, sans-serif" fill="currentColor">${e}</text></svg>`, $ = {
|
|
144
174
|
bold: Z("<path d=\"M6 4h8a4 4 0 0 1 0 8H6z\"/><path d=\"M6 12h9a4 4 0 0 1 0 8H6z\"/>"),
|
|
@@ -158,56 +188,62 @@ var X = Symbol("kun-editor-context"), Se = [
|
|
|
158
188
|
link: Z("<path d=\"M10 13a5 5 0 0 0 7.07 0l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71\"/><path d=\"M14 11a5 5 0 0 0-7.07 0l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71\"/>"),
|
|
159
189
|
latex: Q("Σ", 15),
|
|
160
190
|
smile: Z("<circle cx=\"12\" cy=\"12\" r=\"9\"/><path d=\"M8 14s1.5 2 4 2 4-2 4-2\"/><line x1=\"9\" y1=\"9\" x2=\"9.01\" y2=\"9\"/><line x1=\"15\" y1=\"9\" x2=\"15.01\" y2=\"9\"/>")
|
|
161
|
-
},
|
|
191
|
+
}, Ke = {
|
|
162
192
|
key: 0,
|
|
163
193
|
class: "kun-editor__toolbar-divider",
|
|
164
194
|
"aria-hidden": "true"
|
|
165
|
-
},
|
|
195
|
+
}, qe = [
|
|
166
196
|
"title",
|
|
167
197
|
"aria-label",
|
|
198
|
+
"aria-pressed",
|
|
199
|
+
"data-active",
|
|
168
200
|
"onMousedown"
|
|
169
|
-
],
|
|
201
|
+
], Je = ["innerHTML"], Ye = /* @__PURE__ */ s({
|
|
170
202
|
__name: "SelectionTooltip",
|
|
171
203
|
setup(n) {
|
|
172
|
-
let { view: r, prevState: o } =
|
|
173
|
-
s()?.action(
|
|
174
|
-
},
|
|
204
|
+
let { view: r, prevState: o } = M(), [, s] = A(), c = l(X), u = c?.activeMarks ?? Ne, d = t(() => (c?.locale ?? "zh-cn").toLowerCase().startsWith("en")), h = _(null), g, y = (e, t) => {
|
|
205
|
+
s()?.action(W(e, t));
|
|
206
|
+
}, b = async () => {
|
|
175
207
|
let e = r.value, { from: t, to: n } = e?.state.selection ?? {
|
|
176
208
|
from: 0,
|
|
177
209
|
to: 0
|
|
178
|
-
}, i = e ? e.state.doc.textBetween(t, n, " ") : "", a = c?.adapters.linkPrompt, o = (a ? await a({ text: i }) : window.prompt(
|
|
179
|
-
o &&
|
|
180
|
-
},
|
|
181
|
-
let e =
|
|
210
|
+
}, i = e ? e.state.doc.textBetween(t, n, " ") : "", a = c?.adapters.linkPrompt, o = (a ? await a({ text: i }) : window.prompt(d.value ? "Link URL" : "链接 URL"))?.trim();
|
|
211
|
+
o && y(_e.key, { href: o });
|
|
212
|
+
}, S = t(() => {
|
|
213
|
+
let e = d.value;
|
|
182
214
|
return {
|
|
183
215
|
bold: {
|
|
184
216
|
svg: $.bold,
|
|
185
217
|
title: e ? "Bold" : "加粗",
|
|
186
|
-
run: () =>
|
|
218
|
+
run: () => y(de.key),
|
|
219
|
+
mark: "bold"
|
|
187
220
|
},
|
|
188
221
|
italic: {
|
|
189
222
|
svg: $.italic,
|
|
190
223
|
title: e ? "Italic" : "斜体",
|
|
191
|
-
run: () =>
|
|
224
|
+
run: () => y(le.key),
|
|
225
|
+
mark: "italic"
|
|
192
226
|
},
|
|
193
227
|
strike: {
|
|
194
228
|
svg: $.strike,
|
|
195
229
|
title: e ? "Strikethrough" : "删除线",
|
|
196
|
-
run: () =>
|
|
230
|
+
run: () => y(Te.key),
|
|
231
|
+
mark: "strike"
|
|
197
232
|
},
|
|
198
233
|
code: {
|
|
199
234
|
svg: $.code,
|
|
200
235
|
title: e ? "Inline code" : "行内代码",
|
|
201
|
-
run: () =>
|
|
236
|
+
run: () => y(ue.key),
|
|
237
|
+
mark: "code"
|
|
202
238
|
},
|
|
203
239
|
link: {
|
|
204
240
|
svg: $.link,
|
|
205
241
|
title: e ? "Link" : "链接",
|
|
206
|
-
run:
|
|
242
|
+
run: b
|
|
207
243
|
}
|
|
208
244
|
};
|
|
209
|
-
}),
|
|
210
|
-
let e =
|
|
245
|
+
}), w = t(() => {
|
|
246
|
+
let e = S.value, t = (c?.selectionToolbarItems ?? [
|
|
211
247
|
"bold",
|
|
212
248
|
"italic",
|
|
213
249
|
"strike",
|
|
@@ -222,32 +258,34 @@ var X = Symbol("kun-editor-context"), Se = [
|
|
|
222
258
|
return n;
|
|
223
259
|
});
|
|
224
260
|
return p(() => {
|
|
225
|
-
|
|
226
|
-
content:
|
|
261
|
+
g = new te({
|
|
262
|
+
content: h.value,
|
|
227
263
|
offset: 8
|
|
228
|
-
}),
|
|
229
|
-
}),
|
|
230
|
-
|
|
264
|
+
}), g.update(r.value, o.value);
|
|
265
|
+
}), C([r, o], () => {
|
|
266
|
+
g?.update(r.value, o.value);
|
|
231
267
|
}), f(() => {
|
|
232
|
-
|
|
268
|
+
g?.destroy();
|
|
233
269
|
}), (t, n) => (m(), i("div", {
|
|
234
270
|
ref_key: "divRef",
|
|
235
|
-
ref:
|
|
271
|
+
ref: h,
|
|
236
272
|
class: "kun-editor__bubble",
|
|
237
273
|
"data-show": "false"
|
|
238
|
-
}, [(m(!0), i(e, null,
|
|
274
|
+
}, [(m(!0), i(e, null, v(w.value, (t, n) => (m(), i(e, { key: n }, [t.divider ? (m(), i("span", Ke)) : (m(), i("button", {
|
|
239
275
|
key: 1,
|
|
240
276
|
type: "button",
|
|
241
277
|
class: "kun-editor__bubble-btn",
|
|
242
278
|
title: t.title,
|
|
243
279
|
"aria-label": t.title,
|
|
244
|
-
|
|
280
|
+
"aria-pressed": t.mark ? x(u)[t.mark] : void 0,
|
|
281
|
+
"data-active": t.mark ? x(u)[t.mark] : void 0,
|
|
282
|
+
onMousedown: E((e) => t.run(), ["prevent"])
|
|
245
283
|
}, [a("span", {
|
|
246
284
|
class: "kun-editor__icon",
|
|
247
285
|
innerHTML: t.svg
|
|
248
|
-
}, null, 8,
|
|
286
|
+
}, null, 8, Je)], 40, qe))], 64))), 128))], 512));
|
|
249
287
|
}
|
|
250
|
-
}),
|
|
288
|
+
}), Xe = /* @__PURE__ */ s({
|
|
251
289
|
__name: "MilkdownEditor",
|
|
252
290
|
props: {
|
|
253
291
|
modelValue: {},
|
|
@@ -262,94 +300,94 @@ var X = Symbol("kun-editor-context"), Se = [
|
|
|
262
300
|
},
|
|
263
301
|
emits: ["update:modelValue", "update:loading"],
|
|
264
302
|
setup(e, { expose: t, emit: r }) {
|
|
265
|
-
let i = e, a = r, o = i.modelValue, s = !1, c =
|
|
266
|
-
let t =
|
|
267
|
-
t.set(
|
|
303
|
+
let i = e, a = r, o = i.modelValue, s = !1, c = l(X), u = N(), d = H("kunMention"), f = i.features.mention !== !1 && !!i.adapters.searchMentionUsers && !!u, p = U("kunSelectionTooltip"), h = i.selectionToolbar && !!u, g = k((e) => {
|
|
304
|
+
let t = F.make().config((t) => {
|
|
305
|
+
t.set(z, e), t.set(I, i.modelValue), t.get(B).markdownUpdated((e, t, n) => {
|
|
268
306
|
!i.active || s || t === n || (o = t, a("update:modelValue", t));
|
|
269
|
-
}), t.update(
|
|
307
|
+
}), t.update(R, (e) => ({
|
|
270
308
|
...e,
|
|
271
309
|
editable: () => !i.readonly
|
|
272
|
-
})),
|
|
273
|
-
}).use(
|
|
310
|
+
})), f && t.set(d.key, { view: u({ component: Ge }) }), h && t.set(p.key, { view: u({ component: Ye }) });
|
|
311
|
+
}).use(he(i.adapters, i.features, {
|
|
274
312
|
locale: i.locale,
|
|
275
313
|
placeholder: i.placeholder,
|
|
276
314
|
placeholderMode: i.placeholderMode
|
|
277
315
|
}));
|
|
278
|
-
return
|
|
316
|
+
return f && t.use(d), h && t.use(p), c && t.use(Le(c.activeMarks)), t;
|
|
279
317
|
});
|
|
280
|
-
|
|
318
|
+
C(g.loading, (e) => a("update:loading", e), { immediate: !0 }), C(() => i.modelValue, (e) => {
|
|
281
319
|
if (e === o) return;
|
|
282
320
|
o = e;
|
|
283
|
-
let t =
|
|
284
|
-
t && (s = !0, t.action(
|
|
285
|
-
}),
|
|
286
|
-
|
|
287
|
-
let t = e.get(
|
|
321
|
+
let t = g.get();
|
|
322
|
+
t && (s = !0, t.action(G(e)), s = !1);
|
|
323
|
+
}), C(() => i.readonly, () => {
|
|
324
|
+
g.get()?.action((e) => {
|
|
325
|
+
let t = e.get(L);
|
|
288
326
|
t.dispatch(t.state.tr);
|
|
289
327
|
});
|
|
290
328
|
});
|
|
291
|
-
let
|
|
292
|
-
|
|
329
|
+
let _ = () => {
|
|
330
|
+
g.get()?.action((e) => e.get(L).focus());
|
|
293
331
|
};
|
|
294
332
|
return t({
|
|
295
333
|
insertQuote: (e) => {
|
|
296
|
-
|
|
334
|
+
g.get()?.action(W(ye.key, e)), _();
|
|
297
335
|
},
|
|
298
336
|
insertMention: (e) => {
|
|
299
|
-
|
|
337
|
+
g.get()?.action(W(ve.key, e)), _();
|
|
300
338
|
},
|
|
301
339
|
insertImage: (e) => {
|
|
302
|
-
|
|
340
|
+
g.get()?.action(W(se.key, {
|
|
303
341
|
src: e.src,
|
|
304
342
|
alt: e.alt ?? "",
|
|
305
343
|
title: e.title ?? ""
|
|
306
|
-
})),
|
|
344
|
+
})), _();
|
|
307
345
|
},
|
|
308
346
|
uploadImage: (e) => {
|
|
309
|
-
let t = i.adapters.uploadImage, n =
|
|
347
|
+
let t = i.adapters.uploadImage, n = g.get();
|
|
310
348
|
!t || !n || n.action((n) => {
|
|
311
|
-
|
|
349
|
+
Ce(n.get(L), e, {
|
|
312
350
|
uploadImage: t,
|
|
313
351
|
notify: i.adapters.notify,
|
|
314
352
|
locale: i.locale
|
|
315
353
|
});
|
|
316
354
|
});
|
|
317
355
|
},
|
|
318
|
-
focus:
|
|
356
|
+
focus: _,
|
|
319
357
|
scrollToHeading: (e) => {
|
|
320
|
-
|
|
321
|
-
let n = t.get(
|
|
358
|
+
g.get()?.action((t) => {
|
|
359
|
+
let n = t.get(L), r = 0, i = -1;
|
|
322
360
|
if (n.state.doc.forEach((t, n) => {
|
|
323
361
|
t.type.name === "heading" && (r === e && (i = n), r += 1);
|
|
324
362
|
}), !(i < 0) && (n.nodeDOM(i)?.scrollIntoView({
|
|
325
363
|
behavior: "smooth",
|
|
326
364
|
block: "start"
|
|
327
365
|
}), n.editable)) {
|
|
328
|
-
let e =
|
|
366
|
+
let e = re.near(n.state.doc.resolve(i + 1));
|
|
329
367
|
n.dispatch(n.state.tr.setSelection(e)), n.focus();
|
|
330
368
|
}
|
|
331
369
|
});
|
|
332
370
|
}
|
|
333
|
-
}), (e, t) => (m(), n(
|
|
371
|
+
}), (e, t) => (m(), n(x(D)));
|
|
334
372
|
}
|
|
335
|
-
}),
|
|
373
|
+
}), Ze = /* @__PURE__ */ "😀.😃.😄.😁.😆.😅.🤣.😂.🙂.🙃.😉.😊.😇.🥰.😍.🤩.😘.😗.😚.😋.😛.😜.🤪.😝.🤗.🤭.🤔.🤐.😐.😑.😶.😏.😒.🙄.😬.😌.😔.😪.🤤.😴.😷.🤒.🤕.🥵.🥶.🥴.😵.🤯.🤠.🥳.😎.🤓.🧐.😕.😟.🙁.😮.😯.😲.😳.🥺.😦.😧.😨.😰.😥.😢.😭.😱.😖.😣.😞.😓.😩.😫.🥱.😤.😡.😠.🤬.😈.👿.💀.💩.🤡.👻.👽.🤖.😺.😸.👍.👎.👌.🤌.🤏.✌️.🤞.🤟.🤘.👋.🤚.🖐️.✋.👏.🙌.🤝.🙏.💪.👀.👁️.❤️.🧡.💛.💚.💙.💜.🖤.🤍.💔.💕.💞.💓.💗.💖.💘.💝.💯.✨.⭐.🌟.🔥.💥.💫.⚡.☀️.🌈.🎉.🎊.🎁.🏆.🐶.🐱.🐭.🦊.🐻.🐼.🐨.🦄.🐢.🐳.🍎.🍑.🍓.🍉.🍰.🍺.🍵.☕.🍜.🍙.✅.❌.❓.❗.💤.👑.🎮.🎵.📌.🔖".split("."), Qe = [
|
|
336
374
|
"title",
|
|
337
375
|
"aria-label",
|
|
338
376
|
"aria-expanded"
|
|
339
|
-
],
|
|
377
|
+
], $e = ["innerHTML"], et = { class: "kun-editor__picker-panel" }, tt = {
|
|
340
378
|
key: 0,
|
|
341
379
|
class: "kun-editor__picker-tabs",
|
|
342
380
|
role: "tablist"
|
|
343
|
-
},
|
|
381
|
+
}, nt = ["data-active"], rt = ["data-active"], it = { class: "kun-editor__emoji-grid" }, at = ["onClick"], ot = {
|
|
344
382
|
key: 1,
|
|
345
383
|
class: "kun-editor__sticker-body"
|
|
346
|
-
},
|
|
384
|
+
}, st = { class: "kun-editor__pack-name" }, ct = { class: "kun-editor__sticker-grid" }, lt = ["title", "onClick"], ut = ["src", "alt"], dt = {
|
|
347
385
|
key: 1,
|
|
348
386
|
class: "kun-editor__picker-hint"
|
|
349
|
-
},
|
|
387
|
+
}, ft = /* @__PURE__ */ s({
|
|
350
388
|
__name: "StickerPicker",
|
|
351
389
|
setup(n) {
|
|
352
|
-
let [, o] =
|
|
390
|
+
let [, o] = A(), s = l(X), c = s?.adapters.stickerSource, u = !!c, d = t(() => (s?.locale ?? "zh-cn").toLowerCase().startsWith("en")), h = t(() => d.value ? {
|
|
353
391
|
trigger: "Emoji & stickers",
|
|
354
392
|
emoji: "Emoji",
|
|
355
393
|
sticker: "Stickers",
|
|
@@ -361,28 +399,28 @@ var X = Symbol("kun-editor-context"), Se = [
|
|
|
361
399
|
sticker: "贴纸",
|
|
362
400
|
empty: "暂无贴纸",
|
|
363
401
|
failed: "贴纸加载失败"
|
|
364
|
-
}),
|
|
402
|
+
}), g = _(!1), y = _(null), C = _("emoji"), w = _([]), E = _(!1), D = _(!1), O = async () => {
|
|
365
403
|
if (!(E.value || !c)) {
|
|
366
404
|
E.value = !0;
|
|
367
405
|
try {
|
|
368
|
-
|
|
406
|
+
w.value = await c();
|
|
369
407
|
} catch {
|
|
370
408
|
D.value = !0;
|
|
371
409
|
}
|
|
372
410
|
}
|
|
373
|
-
},
|
|
374
|
-
|
|
411
|
+
}, k = () => {
|
|
412
|
+
g.value = !g.value, g.value && u && O();
|
|
375
413
|
}, j = (e) => {
|
|
376
|
-
|
|
414
|
+
g.value && y.value && !y.value.contains(e.target) && (g.value = !1);
|
|
377
415
|
};
|
|
378
416
|
p(() => document.addEventListener("click", j)), f(() => document.removeEventListener("click", j));
|
|
379
417
|
let M = (e) => {
|
|
380
418
|
o()?.action((t) => {
|
|
381
|
-
let n = t.get(
|
|
419
|
+
let n = t.get(L), { state: r } = n;
|
|
382
420
|
n.dispatch(r.tr.insertText(e, r.selection.from));
|
|
383
421
|
});
|
|
384
422
|
}, N = (e, t) => {
|
|
385
|
-
o()?.action(
|
|
423
|
+
o()?.action(W(se.key, {
|
|
386
424
|
src: e,
|
|
387
425
|
title: t,
|
|
388
426
|
alt: t
|
|
@@ -390,40 +428,40 @@ var X = Symbol("kun-editor-context"), Se = [
|
|
|
390
428
|
};
|
|
391
429
|
return (t, n) => (m(), i("div", {
|
|
392
430
|
ref_key: "rootRef",
|
|
393
|
-
ref:
|
|
431
|
+
ref: y,
|
|
394
432
|
class: "kun-editor__picker"
|
|
395
433
|
}, [a("button", {
|
|
396
434
|
type: "button",
|
|
397
435
|
class: "kun-editor__tool",
|
|
398
436
|
title: h.value.trigger,
|
|
399
437
|
"aria-label": h.value.trigger,
|
|
400
|
-
"aria-expanded":
|
|
401
|
-
onClick:
|
|
438
|
+
"aria-expanded": g.value,
|
|
439
|
+
onClick: k
|
|
402
440
|
}, [a("span", {
|
|
403
441
|
class: "kun-editor__icon",
|
|
404
|
-
innerHTML:
|
|
405
|
-
}, null, 8,
|
|
406
|
-
u ? (m(), i("div",
|
|
442
|
+
innerHTML: x($).smile
|
|
443
|
+
}, null, 8, $e)], 8, Qe), T(a("div", et, [
|
|
444
|
+
u ? (m(), i("div", tt, [a("button", {
|
|
407
445
|
type: "button",
|
|
408
446
|
class: "kun-editor__picker-tab",
|
|
409
447
|
"data-active": C.value === "emoji",
|
|
410
448
|
onClick: n[0] ||= (e) => C.value = "emoji"
|
|
411
|
-
},
|
|
449
|
+
}, b(h.value.emoji), 9, nt), a("button", {
|
|
412
450
|
type: "button",
|
|
413
451
|
class: "kun-editor__picker-tab",
|
|
414
452
|
"data-active": C.value === "sticker",
|
|
415
453
|
onClick: n[1] ||= (e) => C.value = "sticker"
|
|
416
|
-
},
|
|
417
|
-
|
|
454
|
+
}, b(h.value.sticker), 9, rt)])) : r("", !0),
|
|
455
|
+
T(a("div", it, [(m(!0), i(e, null, v(x(Ze), (e, t) => (m(), i("button", {
|
|
418
456
|
key: t,
|
|
419
457
|
type: "button",
|
|
420
458
|
class: "kun-editor__emoji",
|
|
421
459
|
onClick: (t) => M(e)
|
|
422
|
-
},
|
|
423
|
-
u ?
|
|
460
|
+
}, b(e), 9, at))), 128))], 512), [[S, !u || C.value === "emoji"]]),
|
|
461
|
+
u ? T((m(), i("div", ot, [w.value.length ? (m(!0), i(e, { key: 0 }, v(w.value, (t) => (m(), i("div", {
|
|
424
462
|
key: t.name,
|
|
425
463
|
class: "kun-editor__pack"
|
|
426
|
-
}, [a("div",
|
|
464
|
+
}, [a("div", st, b(t.name), 1), a("div", ct, [(m(!0), i(e, null, v(t.stickers, (e, t) => (m(), i("button", {
|
|
427
465
|
key: t,
|
|
428
466
|
type: "button",
|
|
429
467
|
class: "kun-editor__sticker",
|
|
@@ -433,35 +471,37 @@ var X = Symbol("kun-editor-context"), Se = [
|
|
|
433
471
|
src: e.src,
|
|
434
472
|
alt: e.name,
|
|
435
473
|
loading: "lazy"
|
|
436
|
-
}, null, 8,
|
|
437
|
-
], 512), [[
|
|
474
|
+
}, null, 8, ut)], 8, lt))), 128))])]))), 128)) : (m(), i("div", dt, b(D.value ? h.value.failed : h.value.empty), 1))], 512)), [[S, C.value === "sticker"]]) : r("", !0)
|
|
475
|
+
], 512), [[S, g.value]])], 512));
|
|
438
476
|
}
|
|
439
|
-
}),
|
|
477
|
+
}), pt = {
|
|
440
478
|
class: "kun-editor__format-toolbar",
|
|
441
479
|
role: "toolbar"
|
|
442
|
-
},
|
|
480
|
+
}, mt = ["aria-label"], ht = {
|
|
443
481
|
value: "",
|
|
444
482
|
disabled: "",
|
|
445
483
|
selected: ""
|
|
446
|
-
},
|
|
484
|
+
}, gt = ["value"], _t = [
|
|
447
485
|
"title",
|
|
448
486
|
"aria-label",
|
|
487
|
+
"aria-pressed",
|
|
488
|
+
"data-active",
|
|
449
489
|
"onClick"
|
|
450
|
-
],
|
|
490
|
+
], vt = ["innerHTML"], yt = ["title", "aria-label"], bt = ["innerHTML"], xt = /* @__PURE__ */ s({
|
|
451
491
|
__name: "EditorToolbar",
|
|
452
492
|
setup(n) {
|
|
453
|
-
let [, s] =
|
|
454
|
-
s()?.action(
|
|
455
|
-
},
|
|
493
|
+
let [, s] = A(), c = l(X), u = c?.activeMarks ?? Ne, d = t(() => c?.adapters.uploadImage), f = t(() => c?.features.sticker !== !1), p = t(() => (c?.locale ?? "zh-cn").toLowerCase().startsWith("en")), h = (e, t) => {
|
|
494
|
+
s()?.action(W(e, t));
|
|
495
|
+
}, g = async () => {
|
|
456
496
|
let e = "";
|
|
457
497
|
s()?.action((t) => {
|
|
458
|
-
let n = t.get(
|
|
498
|
+
let n = t.get(L), { from: r, to: i } = n.state.selection;
|
|
459
499
|
e = n.state.doc.textBetween(r, i, " ");
|
|
460
500
|
});
|
|
461
|
-
let t = c?.adapters.linkPrompt, n = (t ? await t({ text: e }) : window.prompt(
|
|
462
|
-
n &&
|
|
463
|
-
},
|
|
464
|
-
let e =
|
|
501
|
+
let t = c?.adapters.linkPrompt, n = (t ? await t({ text: e }) : window.prompt(p.value ? "Link URL" : "链接 URL"))?.trim();
|
|
502
|
+
n && h(_e.key, { href: n });
|
|
503
|
+
}, y = t(() => {
|
|
504
|
+
let e = p.value;
|
|
465
505
|
return {
|
|
466
506
|
textSize: e ? "Text size" : "文本大小",
|
|
467
507
|
bold: e ? "Bold" : "加粗",
|
|
@@ -477,8 +517,8 @@ var X = Symbol("kun-editor-context"), Se = [
|
|
|
477
517
|
spoiler: e ? "Spoiler" : "隐藏文本",
|
|
478
518
|
image: e ? "Upload image" : "上传图片"
|
|
479
519
|
};
|
|
480
|
-
}),
|
|
481
|
-
let e =
|
|
520
|
+
}), S = t(() => {
|
|
521
|
+
let e = p.value;
|
|
482
522
|
return [
|
|
483
523
|
"正文",
|
|
484
524
|
"一级标题",
|
|
@@ -491,105 +531,111 @@ var X = Symbol("kun-editor-context"), Se = [
|
|
|
491
531
|
level: n,
|
|
492
532
|
label: e ? n === 0 ? "Paragraph" : `Heading ${n}` : t
|
|
493
533
|
}));
|
|
494
|
-
}),
|
|
534
|
+
}), C = (e) => {
|
|
495
535
|
let t = e.target;
|
|
496
|
-
|
|
497
|
-
},
|
|
536
|
+
h(Se.key, Number(t.value)), t.selectedIndex = 0;
|
|
537
|
+
}, w = t(() => [
|
|
498
538
|
[
|
|
499
539
|
{
|
|
500
540
|
svg: $.bold,
|
|
501
|
-
title:
|
|
502
|
-
run: () =>
|
|
541
|
+
title: y.value.bold,
|
|
542
|
+
run: () => h(de.key),
|
|
543
|
+
mark: "bold"
|
|
503
544
|
},
|
|
504
545
|
{
|
|
505
546
|
svg: $.italic,
|
|
506
|
-
title:
|
|
507
|
-
run: () =>
|
|
547
|
+
title: y.value.italic,
|
|
548
|
+
run: () => h(le.key),
|
|
549
|
+
mark: "italic"
|
|
508
550
|
},
|
|
509
551
|
{
|
|
510
552
|
svg: $.strike,
|
|
511
|
-
title:
|
|
512
|
-
run: () =>
|
|
553
|
+
title: y.value.strike,
|
|
554
|
+
run: () => h(Te.key),
|
|
555
|
+
mark: "strike"
|
|
513
556
|
},
|
|
514
557
|
{
|
|
515
558
|
svg: $.code,
|
|
516
|
-
title:
|
|
517
|
-
run: () =>
|
|
559
|
+
title: y.value.code,
|
|
560
|
+
run: () => h(ue.key),
|
|
561
|
+
mark: "code"
|
|
518
562
|
},
|
|
519
563
|
{
|
|
520
564
|
svg: $.link,
|
|
521
|
-
title:
|
|
522
|
-
run:
|
|
565
|
+
title: y.value.link,
|
|
566
|
+
run: g
|
|
523
567
|
}
|
|
524
568
|
],
|
|
525
569
|
[
|
|
526
570
|
{
|
|
527
571
|
svg: $.bulletList,
|
|
528
|
-
title:
|
|
529
|
-
run: () =>
|
|
572
|
+
title: y.value.bulletList,
|
|
573
|
+
run: () => h(pe.key)
|
|
530
574
|
},
|
|
531
575
|
{
|
|
532
576
|
svg: $.orderedList,
|
|
533
|
-
title:
|
|
534
|
-
run: () =>
|
|
577
|
+
title: y.value.orderedList,
|
|
578
|
+
run: () => h(me.key)
|
|
535
579
|
},
|
|
536
580
|
{
|
|
537
581
|
svg: $.quote,
|
|
538
|
-
title:
|
|
539
|
-
run: () =>
|
|
582
|
+
title: y.value.quote,
|
|
583
|
+
run: () => h(fe.key)
|
|
540
584
|
},
|
|
541
585
|
{
|
|
542
586
|
svg: $.codeBlock,
|
|
543
|
-
title:
|
|
544
|
-
run: () =>
|
|
587
|
+
title: y.value.codeBlock,
|
|
588
|
+
run: () => h(ie.key, "")
|
|
545
589
|
},
|
|
546
590
|
{
|
|
547
591
|
svg: $.hr,
|
|
548
|
-
title:
|
|
549
|
-
run: () =>
|
|
592
|
+
title: y.value.hr,
|
|
593
|
+
run: () => h(oe.key)
|
|
550
594
|
}
|
|
551
595
|
],
|
|
552
596
|
[{
|
|
553
597
|
svg: $.spoiler,
|
|
554
|
-
title:
|
|
555
|
-
run: () =>
|
|
598
|
+
title: y.value.spoiler,
|
|
599
|
+
run: () => h(ge.key)
|
|
556
600
|
}]
|
|
557
|
-
]),
|
|
601
|
+
]), T = _(null), E = () => T.value?.click(), D = (e) => {
|
|
558
602
|
let t = e.target, n = t.files?.[0];
|
|
559
603
|
t.value = "";
|
|
560
|
-
let r =
|
|
604
|
+
let r = d.value;
|
|
561
605
|
!n || !r || s()?.action((e) => {
|
|
562
|
-
|
|
606
|
+
Ce(e.get(L), n, {
|
|
563
607
|
uploadImage: r,
|
|
564
608
|
notify: c?.adapters.notify,
|
|
565
609
|
locale: c?.locale
|
|
566
610
|
});
|
|
567
611
|
});
|
|
568
612
|
};
|
|
569
|
-
return (t, n) => (m(), i("div",
|
|
613
|
+
return (t, n) => (m(), i("div", pt, [
|
|
570
614
|
a("select", {
|
|
571
615
|
class: "kun-editor__heading-select",
|
|
572
|
-
"aria-label":
|
|
573
|
-
onChange:
|
|
574
|
-
}, [a("option",
|
|
616
|
+
"aria-label": y.value.textSize,
|
|
617
|
+
onChange: C
|
|
618
|
+
}, [a("option", ht, b(y.value.textSize), 1), (m(!0), i(e, null, v(S.value, (e) => (m(), i("option", {
|
|
575
619
|
key: e.level,
|
|
576
620
|
value: e.level
|
|
577
|
-
},
|
|
578
|
-
(m(!0), i(e, null,
|
|
621
|
+
}, b(e.label), 9, gt))), 128))], 40, mt),
|
|
622
|
+
(m(!0), i(e, null, v(w.value, (t, r) => (m(), i(e, { key: r }, [n[0] ||= a("span", {
|
|
579
623
|
class: "kun-editor__toolbar-divider",
|
|
580
624
|
"aria-hidden": "true"
|
|
581
|
-
}, null, -1), (m(!0), i(e, null,
|
|
625
|
+
}, null, -1), (m(!0), i(e, null, v(t, (e, t) => (m(), i("button", {
|
|
582
626
|
key: t,
|
|
583
627
|
type: "button",
|
|
584
628
|
class: "kun-editor__tool",
|
|
585
629
|
title: e.title,
|
|
586
630
|
"aria-label": e.title,
|
|
631
|
+
"aria-pressed": e.mark ? x(u)[e.mark] : void 0,
|
|
632
|
+
"data-active": e.mark ? x(u)[e.mark] : void 0,
|
|
587
633
|
onClick: (t) => e.run()
|
|
588
634
|
}, [a("span", {
|
|
589
635
|
class: "kun-editor__icon",
|
|
590
636
|
innerHTML: e.svg
|
|
591
|
-
}, null, 8,
|
|
592
|
-
|
|
637
|
+
}, null, 8, vt)], 8, _t))), 128))], 64))), 128)),
|
|
638
|
+
d.value ? (m(), i(e, { key: 0 }, [
|
|
593
639
|
n[1] ||= a("span", {
|
|
594
640
|
class: "kun-editor__toolbar-divider",
|
|
595
641
|
"aria-hidden": "true"
|
|
@@ -597,47 +643,50 @@ var X = Symbol("kun-editor-context"), Se = [
|
|
|
597
643
|
a("button", {
|
|
598
644
|
type: "button",
|
|
599
645
|
class: "kun-editor__tool",
|
|
600
|
-
title:
|
|
601
|
-
"aria-label":
|
|
602
|
-
onClick:
|
|
646
|
+
title: y.value.image,
|
|
647
|
+
"aria-label": y.value.image,
|
|
648
|
+
onClick: E
|
|
603
649
|
}, [a("span", {
|
|
604
650
|
class: "kun-editor__icon",
|
|
605
|
-
innerHTML:
|
|
606
|
-
}, null, 8,
|
|
651
|
+
innerHTML: x($).image
|
|
652
|
+
}, null, 8, bt)], 8, yt),
|
|
607
653
|
a("input", {
|
|
608
654
|
ref_key: "fileInput",
|
|
609
|
-
ref:
|
|
655
|
+
ref: T,
|
|
610
656
|
type: "file",
|
|
611
657
|
accept: ".jpg,.jpeg,.png,.webp,.gif",
|
|
612
658
|
hidden: "",
|
|
613
|
-
onChange:
|
|
659
|
+
onChange: D
|
|
614
660
|
}, null, 544)
|
|
615
661
|
], 64)) : r("", !0),
|
|
616
|
-
|
|
662
|
+
f.value ? (m(), i(e, { key: 1 }, [n[2] ||= a("span", {
|
|
617
663
|
class: "kun-editor__toolbar-divider",
|
|
618
664
|
"aria-hidden": "true"
|
|
619
|
-
}, null, -1), o(
|
|
665
|
+
}, null, -1), o(ft)], 64)) : r("", !0)
|
|
620
666
|
]));
|
|
621
667
|
}
|
|
622
|
-
}),
|
|
668
|
+
}), St = /* @__PURE__ */ s({
|
|
623
669
|
__name: "ToolbarHost",
|
|
624
670
|
setup(e) {
|
|
625
|
-
let [, t] =
|
|
626
|
-
t()?.action(
|
|
671
|
+
let [, t] = A(), n = l(X, void 0), r = (e, n) => {
|
|
672
|
+
t()?.action(W(e, n));
|
|
627
673
|
}, i = () => {
|
|
628
|
-
t()?.action((e) => e.get(
|
|
674
|
+
t()?.action((e) => e.get(L).focus());
|
|
629
675
|
}, a = {
|
|
630
676
|
run: r,
|
|
677
|
+
get activeMarks() {
|
|
678
|
+
return n?.activeMarks ?? Ne;
|
|
679
|
+
},
|
|
631
680
|
insertText: (e) => {
|
|
632
681
|
t()?.action((t) => {
|
|
633
|
-
let n = t.get(
|
|
682
|
+
let n = t.get(L);
|
|
634
683
|
n.dispatch(n.state.tr.insertText(e));
|
|
635
684
|
}), i();
|
|
636
685
|
},
|
|
637
686
|
uploadImage: (e) => {
|
|
638
687
|
let r = n?.adapters.uploadImage, i = t();
|
|
639
688
|
!r || !i || i.action((t) => {
|
|
640
|
-
|
|
689
|
+
Ce(t.get(L), e, {
|
|
641
690
|
uploadImage: r,
|
|
642
691
|
notify: n?.adapters.notify,
|
|
643
692
|
locale: n?.locale
|
|
@@ -645,20 +694,20 @@ var X = Symbol("kun-editor-context"), Se = [
|
|
|
645
694
|
});
|
|
646
695
|
},
|
|
647
696
|
insertLink: (e) => {
|
|
648
|
-
r(
|
|
697
|
+
r(_e.key, e), i();
|
|
649
698
|
},
|
|
650
699
|
insertImage: (e) => {
|
|
651
|
-
r(
|
|
700
|
+
r(se.key, {
|
|
652
701
|
src: e.src,
|
|
653
702
|
alt: e.alt ?? "",
|
|
654
703
|
title: e.title ?? ""
|
|
655
704
|
}), i();
|
|
656
705
|
},
|
|
657
706
|
insertQuote: (e) => {
|
|
658
|
-
r(
|
|
707
|
+
r(ye.key, e), i();
|
|
659
708
|
},
|
|
660
709
|
insertMention: (e) => {
|
|
661
|
-
r(
|
|
710
|
+
r(ve.key, e), i();
|
|
662
711
|
},
|
|
663
712
|
focus: i,
|
|
664
713
|
get adapters() {
|
|
@@ -671,9 +720,9 @@ var X = Symbol("kun-editor-context"), Se = [
|
|
|
671
720
|
return n?.locale ?? "zh-cn";
|
|
672
721
|
}
|
|
673
722
|
};
|
|
674
|
-
return (e, t) =>
|
|
723
|
+
return (e, t) => y(e.$slots, "default", d(c(a)));
|
|
675
724
|
}
|
|
676
|
-
}),
|
|
725
|
+
}), Ct = /* @__PURE__ */ s({
|
|
677
726
|
__name: "MarkdownSource",
|
|
678
727
|
props: {
|
|
679
728
|
modelValue: {},
|
|
@@ -681,13 +730,13 @@ var X = Symbol("kun-editor-context"), Se = [
|
|
|
681
730
|
},
|
|
682
731
|
emits: ["update:modelValue"],
|
|
683
732
|
setup(e, { expose: t, emit: n }) {
|
|
684
|
-
let r = e, a = n, o =
|
|
733
|
+
let r = e, a = n, o = _(null), s = null, c = Ee.define(), l = (e) => De.create({
|
|
685
734
|
doc: e,
|
|
686
735
|
extensions: [
|
|
687
|
-
pe(),
|
|
688
|
-
Y.lineWrapping,
|
|
689
|
-
xe,
|
|
690
736
|
be(),
|
|
737
|
+
Y.lineWrapping,
|
|
738
|
+
ke,
|
|
739
|
+
Oe(),
|
|
691
740
|
Y.editable.of(!r.readonly),
|
|
692
741
|
Y.updateListener.of((e) => {
|
|
693
742
|
e.docChanged && !e.transactions.some((e) => e.annotation(c)) && a("update:modelValue", e.state.doc.toString());
|
|
@@ -724,7 +773,7 @@ var X = Symbol("kun-editor-context"), Se = [
|
|
|
724
773
|
selection: { anchor: i },
|
|
725
774
|
scrollIntoView: !0
|
|
726
775
|
}), s.focus());
|
|
727
|
-
} }),
|
|
776
|
+
} }), C(() => r.modelValue, (e) => {
|
|
728
777
|
if (!s || s.state.doc.toString() === e) return;
|
|
729
778
|
let { anchor: t, head: n } = s.state.selection.main, r = e.length;
|
|
730
779
|
s.dispatch({
|
|
@@ -745,23 +794,23 @@ var X = Symbol("kun-editor-context"), Se = [
|
|
|
745
794
|
class: "kun-editor__source"
|
|
746
795
|
}, null, 512));
|
|
747
796
|
}
|
|
748
|
-
}),
|
|
797
|
+
}), wt = ["data-mode"], Tt = {
|
|
749
798
|
key: 0,
|
|
750
799
|
class: "kun-editor__toolbar",
|
|
751
800
|
role: "tablist"
|
|
752
|
-
},
|
|
801
|
+
}, Et = [
|
|
753
802
|
"aria-selected",
|
|
754
803
|
"data-active",
|
|
755
804
|
"onClick"
|
|
756
|
-
],
|
|
805
|
+
], Dt = ["title", "aria-label"], Ot = [
|
|
757
806
|
"data-active",
|
|
758
807
|
"title",
|
|
759
808
|
"aria-pressed"
|
|
760
|
-
],
|
|
809
|
+
], kt = ["data-swap"], At = { class: "kun-editor__wysiwyg kun-editor__pane" }, jt = {
|
|
761
810
|
key: 1,
|
|
762
811
|
class: "kun-editor__loading",
|
|
763
812
|
"aria-hidden": "true"
|
|
764
|
-
},
|
|
813
|
+
}, Mt = /* @__PURE__ */ s({
|
|
765
814
|
__name: "KunEditor",
|
|
766
815
|
props: {
|
|
767
816
|
modelValue: {},
|
|
@@ -793,49 +842,54 @@ var X = Symbol("kun-editor-context"), Se = [
|
|
|
793
842
|
"update:headings",
|
|
794
843
|
"update:loading"
|
|
795
844
|
],
|
|
796
|
-
setup(s, { expose: l, emit:
|
|
797
|
-
let
|
|
845
|
+
setup(s, { expose: l, emit: E }) {
|
|
846
|
+
let D = [
|
|
798
847
|
"bold",
|
|
799
848
|
"italic",
|
|
800
849
|
"strike",
|
|
801
850
|
"code",
|
|
802
851
|
"link"
|
|
803
|
-
],
|
|
852
|
+
], k = s, A = E, M = _(!1);
|
|
804
853
|
p(() => {
|
|
805
|
-
|
|
854
|
+
M.value = !0;
|
|
806
855
|
});
|
|
807
|
-
let
|
|
808
|
-
|
|
856
|
+
let N = _(!0), P = (e) => {
|
|
857
|
+
N.value = e, A("update:loading", e);
|
|
809
858
|
};
|
|
810
|
-
|
|
859
|
+
C(() => k.modelValue, (e) => A("update:headings", ee(e)), { immediate: !0 });
|
|
860
|
+
let F = g(Me());
|
|
861
|
+
h(X, {
|
|
811
862
|
get adapters() {
|
|
812
|
-
return
|
|
863
|
+
return k.adapters;
|
|
813
864
|
},
|
|
814
865
|
get features() {
|
|
815
|
-
return
|
|
866
|
+
return k.features;
|
|
816
867
|
},
|
|
817
868
|
get locale() {
|
|
818
|
-
return
|
|
869
|
+
return k.locale;
|
|
819
870
|
},
|
|
820
871
|
get selectionToolbarItems() {
|
|
821
|
-
return Array.isArray(
|
|
872
|
+
return Array.isArray(k.selectionToolbar) ? k.selectionToolbar : D;
|
|
873
|
+
},
|
|
874
|
+
get activeMarks() {
|
|
875
|
+
return F;
|
|
822
876
|
}
|
|
823
877
|
});
|
|
824
|
-
let
|
|
825
|
-
|
|
878
|
+
let I = t(() => k.selectionToolbar !== !1), L = _(k.views.includes("wysiwyg") ? "wysiwyg" : k.views[0] ?? "wysiwyg"), R = (e) => {
|
|
879
|
+
L.value = e;
|
|
826
880
|
};
|
|
827
|
-
|
|
828
|
-
e.includes(
|
|
881
|
+
C(() => k.views, (e) => {
|
|
882
|
+
e.includes(L.value) || (L.value = e[0] ?? "wysiwyg");
|
|
829
883
|
});
|
|
830
|
-
let
|
|
831
|
-
|
|
832
|
-
},
|
|
833
|
-
|
|
834
|
-
|
|
884
|
+
let z = _(!1), B = () => {
|
|
885
|
+
z.value = !z.value;
|
|
886
|
+
}, V = _(k.scrollSync);
|
|
887
|
+
C(() => k.scrollSync, (e) => {
|
|
888
|
+
V.value = e;
|
|
835
889
|
});
|
|
836
|
-
let
|
|
837
|
-
|
|
838
|
-
},
|
|
890
|
+
let H = () => {
|
|
891
|
+
V.value = !V.value;
|
|
892
|
+
}, te = t(() => k.locale.toLowerCase().startsWith("en")), U = t(() => te.value ? {
|
|
839
893
|
wysiwyg: "Preview",
|
|
840
894
|
source: "Markdown",
|
|
841
895
|
split: "Split",
|
|
@@ -847,104 +901,104 @@ var X = Symbol("kun-editor-context"), Se = [
|
|
|
847
901
|
split: "分栏",
|
|
848
902
|
swap: "左右互换",
|
|
849
903
|
scrollSync: "同步滚动"
|
|
850
|
-
}),
|
|
851
|
-
|
|
852
|
-
},
|
|
853
|
-
|
|
854
|
-
let e =
|
|
904
|
+
}), ne = _(null), W = null, G = null, K = null, q = () => {
|
|
905
|
+
W?.(), W = null, G = null;
|
|
906
|
+
}, re = () => {
|
|
907
|
+
q();
|
|
908
|
+
let e = ne.value;
|
|
855
909
|
if (!e) return;
|
|
856
910
|
let t = e.querySelector(".cm-scroller"), n = e.querySelector(".kun-editor__wysiwyg");
|
|
857
911
|
if (!t || !n) return;
|
|
858
912
|
let r = (e, t) => () => {
|
|
859
|
-
if (
|
|
860
|
-
|
|
913
|
+
if (G && G !== e) return;
|
|
914
|
+
G = e;
|
|
861
915
|
let n = e.scrollHeight - e.clientHeight, r = n > 0 ? e.scrollTop / n : 0, i = t.scrollHeight - t.clientHeight;
|
|
862
|
-
t.scrollTop = r * (i > 0 ? i : 0),
|
|
863
|
-
|
|
916
|
+
t.scrollTop = r * (i > 0 ? i : 0), K && clearTimeout(K), K = setTimeout(() => {
|
|
917
|
+
G = null;
|
|
864
918
|
}, 120);
|
|
865
919
|
}, i = r(t, n), a = r(n, t);
|
|
866
|
-
t.addEventListener("scroll", i, { passive: !0 }), n.addEventListener("scroll", a, { passive: !0 }),
|
|
920
|
+
t.addEventListener("scroll", i, { passive: !0 }), n.addEventListener("scroll", a, { passive: !0 }), W = () => {
|
|
867
921
|
t.removeEventListener("scroll", i), n.removeEventListener("scroll", a);
|
|
868
922
|
};
|
|
869
923
|
};
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
}), f(
|
|
873
|
-
let
|
|
924
|
+
C([L, V], ([e, t]) => {
|
|
925
|
+
q(), e === "split" && t && u(re);
|
|
926
|
+
}), f(q);
|
|
927
|
+
let ie = t(() => k.readonly || L.value === "split"), ae = (e) => A("update:modelValue", e), J = _(null), oe = _(null);
|
|
874
928
|
return l({
|
|
875
|
-
insertQuote: (e) =>
|
|
876
|
-
insertMention: (e) =>
|
|
877
|
-
insertImage: (e) =>
|
|
878
|
-
uploadImage: (e) =>
|
|
879
|
-
focus: () =>
|
|
929
|
+
insertQuote: (e) => J.value?.insertQuote(e),
|
|
930
|
+
insertMention: (e) => J.value?.insertMention(e),
|
|
931
|
+
insertImage: (e) => J.value?.insertImage(e),
|
|
932
|
+
uploadImage: (e) => J.value?.uploadImage(e),
|
|
933
|
+
focus: () => J.value?.focus(),
|
|
880
934
|
scrollToHeading: (e) => {
|
|
881
|
-
|
|
935
|
+
L.value === "source" || L.value === "split" ? oe.value?.scrollToHeading(e) : J.value?.scrollToHeading(e);
|
|
882
936
|
}
|
|
883
937
|
}), (t, l) => (m(), i("div", {
|
|
884
938
|
ref_key: "rootEl",
|
|
885
|
-
ref:
|
|
939
|
+
ref: ne,
|
|
886
940
|
class: "kun-editor",
|
|
887
941
|
"data-kun-editor": "",
|
|
888
|
-
"data-mode":
|
|
889
|
-
}, [
|
|
890
|
-
mode:
|
|
891
|
-
setMode:
|
|
892
|
-
labels:
|
|
942
|
+
"data-mode": L.value
|
|
943
|
+
}, [M.value ? (m(), i(e, { key: 0 }, [y(t.$slots, "view-switch", {
|
|
944
|
+
mode: L.value,
|
|
945
|
+
setMode: R,
|
|
946
|
+
labels: U.value,
|
|
893
947
|
views: s.views,
|
|
894
|
-
swapped:
|
|
895
|
-
swap:
|
|
896
|
-
scrollSync:
|
|
897
|
-
toggleScrollSync:
|
|
898
|
-
}, () => [s.views.length > 1 ? (m(), i("div",
|
|
948
|
+
swapped: z.value,
|
|
949
|
+
swap: B,
|
|
950
|
+
scrollSync: V.value,
|
|
951
|
+
toggleScrollSync: H
|
|
952
|
+
}, () => [s.views.length > 1 ? (m(), i("div", Tt, [(m(!0), i(e, null, v(s.views, (e) => (m(), i("button", {
|
|
899
953
|
key: e,
|
|
900
954
|
type: "button",
|
|
901
955
|
class: "kun-editor__tab",
|
|
902
|
-
"aria-selected":
|
|
903
|
-
"data-active":
|
|
904
|
-
onClick: (t) =>
|
|
905
|
-
},
|
|
956
|
+
"aria-selected": L.value === e,
|
|
957
|
+
"data-active": L.value === e,
|
|
958
|
+
onClick: (t) => R(e)
|
|
959
|
+
}, b(U.value[e]), 9, Et))), 128)), L.value === "split" ? (m(), i(e, { key: 0 }, [a("button", {
|
|
906
960
|
type: "button",
|
|
907
961
|
class: "kun-editor__tab kun-editor__swap",
|
|
908
|
-
title:
|
|
909
|
-
"aria-label":
|
|
910
|
-
onClick: l[0] ||= (e) =>
|
|
911
|
-
}, " ⇄ ", 8,
|
|
962
|
+
title: U.value.swap,
|
|
963
|
+
"aria-label": U.value.swap,
|
|
964
|
+
onClick: l[0] ||= (e) => B()
|
|
965
|
+
}, " ⇄ ", 8, Dt), a("button", {
|
|
912
966
|
type: "button",
|
|
913
967
|
class: "kun-editor__tab",
|
|
914
|
-
"data-active":
|
|
915
|
-
title:
|
|
916
|
-
"aria-pressed":
|
|
917
|
-
onClick: l[1] ||= (e) =>
|
|
918
|
-
},
|
|
919
|
-
default:
|
|
920
|
-
default:
|
|
921
|
-
default:
|
|
968
|
+
"data-active": V.value,
|
|
969
|
+
title: U.value.scrollSync,
|
|
970
|
+
"aria-pressed": V.value,
|
|
971
|
+
onClick: l[1] ||= (e) => H()
|
|
972
|
+
}, b(U.value.scrollSync), 9, Ot)], 64)) : r("", !0)])) : r("", !0)]), o(x(O), null, {
|
|
973
|
+
default: w(() => [o(x(j), null, {
|
|
974
|
+
default: w(() => [T(a("div", null, [o(St, null, {
|
|
975
|
+
default: w((e) => [y(t.$slots, "toolbar", d(c(e)), () => [o(xt)])]),
|
|
922
976
|
_: 3
|
|
923
|
-
})], 512), [[
|
|
977
|
+
})], 512), [[S, L.value === "wysiwyg" && !s.readonly]]), a("div", {
|
|
924
978
|
class: "kun-editor__panes",
|
|
925
|
-
"data-swap":
|
|
926
|
-
}, [
|
|
979
|
+
"data-swap": z.value
|
|
980
|
+
}, [L.value === "source" || L.value === "split" ? (m(), n(Ct, {
|
|
927
981
|
key: 0,
|
|
928
982
|
ref_key: "source",
|
|
929
|
-
ref:
|
|
983
|
+
ref: oe,
|
|
930
984
|
class: "kun-editor__pane",
|
|
931
985
|
"model-value": s.modelValue,
|
|
932
986
|
readonly: s.readonly,
|
|
933
|
-
"onUpdate:modelValue":
|
|
934
|
-
}, null, 8, ["model-value", "readonly"])) : r("", !0),
|
|
987
|
+
"onUpdate:modelValue": ae
|
|
988
|
+
}, null, 8, ["model-value", "readonly"])) : r("", !0), T(a("div", At, [o(Xe, {
|
|
935
989
|
ref_key: "inner",
|
|
936
|
-
ref:
|
|
990
|
+
ref: J,
|
|
937
991
|
"model-value": s.modelValue,
|
|
938
992
|
adapters: s.adapters,
|
|
939
993
|
features: s.features,
|
|
940
994
|
locale: s.locale,
|
|
941
|
-
readonly:
|
|
995
|
+
readonly: ie.value,
|
|
942
996
|
placeholder: s.placeholder,
|
|
943
997
|
"placeholder-mode": s.placeholderMode,
|
|
944
|
-
active:
|
|
945
|
-
"selection-toolbar":
|
|
946
|
-
"onUpdate:modelValue":
|
|
947
|
-
"onUpdate:loading":
|
|
998
|
+
active: L.value === "wysiwyg" && !s.readonly,
|
|
999
|
+
"selection-toolbar": I.value,
|
|
1000
|
+
"onUpdate:modelValue": ae,
|
|
1001
|
+
"onUpdate:loading": P
|
|
948
1002
|
}, null, 8, [
|
|
949
1003
|
"model-value",
|
|
950
1004
|
"adapters",
|
|
@@ -955,18 +1009,18 @@ var X = Symbol("kun-editor-context"), Se = [
|
|
|
955
1009
|
"placeholder-mode",
|
|
956
1010
|
"active",
|
|
957
1011
|
"selection-toolbar"
|
|
958
|
-
])], 512), [[
|
|
1012
|
+
])], 512), [[S, L.value === "wysiwyg" || L.value === "split"]])], 8, kt)]),
|
|
959
1013
|
_: 3
|
|
960
1014
|
})]),
|
|
961
1015
|
_: 3
|
|
962
|
-
})], 64)) : r("", !0), !
|
|
1016
|
+
})], 64)) : r("", !0), !M.value || N.value ? (m(), i("div", jt, [y(t.$slots, "loading", {}, () => [
|
|
963
1017
|
l[2] ||= a("div", { class: "kun-editor__skeleton" }, null, -1),
|
|
964
1018
|
l[3] ||= a("div", { class: "kun-editor__skeleton" }, null, -1),
|
|
965
1019
|
l[4] ||= a("div", { class: "kun-editor__skeleton" }, null, -1)
|
|
966
|
-
])])) : r("", !0)], 8,
|
|
1020
|
+
])])) : r("", !0)], 8, wt));
|
|
967
1021
|
}
|
|
968
|
-
}),
|
|
969
|
-
e.component("KunEditor",
|
|
1022
|
+
}), Nt = { install(e) {
|
|
1023
|
+
e.component("KunEditor", Mt);
|
|
970
1024
|
} };
|
|
971
1025
|
//#endregion
|
|
972
|
-
export {
|
|
1026
|
+
export { Ze as EMOJI, Mt as KunEditor, Nt as KunEditorPlugin, P as parseHeadings };
|