@kungal/editor-vue 0.32.0 → 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 +11 -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.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.map +1 -1
- package/dist/context.d.ts +7 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/index.js +318 -302
- package/dist/types.d.ts +4 -4
- package/package.json +3 -3
- package/dist/composables/useActiveMarks.d.ts +0 -10
- package/dist/composables/useActiveMarks.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,38 +1,68 @@
|
|
|
1
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
2
|
import { Milkdown as D, MilkdownProvider as O, useEditor as k, useInstance as A } from "@milkdown/vue";
|
|
3
3
|
import { ProsemirrorAdapterProvider as j, usePluginViewContext as M, usePluginViewFactory as N } from "@prosemirror-adapter/vue";
|
|
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 ie, emphasisSchema as ae, inlineCodeSchema as
|
|
12
|
-
import { createKunEditorPlugins as
|
|
13
|
-
import { strikethroughSchema as
|
|
14
|
-
import { Annotation as
|
|
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 ? {
|
|
@@ -59,30 +89,30 @@ var X = Symbol("kun-editor-context"), De = [
|
|
|
59
89
|
}
|
|
60
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
104
|
}, t !== S.value && (S.value = t, N(t)), !0;
|
|
75
|
-
},
|
|
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
117
|
x.value && e.key === "Escape" && (e.preventDefault(), y.hide());
|
|
88
118
|
return;
|
|
@@ -98,7 +128,7 @@ var X = Symbol("kun-editor-context"), De = [
|
|
|
98
128
|
case "Enter":
|
|
99
129
|
case "Tab": {
|
|
100
130
|
let t = w.value[T.value];
|
|
101
|
-
t && (e.preventDefault(), e.stopPropagation(),
|
|
131
|
+
t && (e.preventDefault(), e.stopPropagation(), F(t));
|
|
102
132
|
break;
|
|
103
133
|
}
|
|
104
134
|
case "Escape":
|
|
@@ -107,20 +137,20 @@ var X = Symbol("kun-editor-context"), De = [
|
|
|
107
137
|
}
|
|
108
138
|
};
|
|
109
139
|
return p(() => {
|
|
110
|
-
y = new
|
|
140
|
+
y = new V({
|
|
111
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
147
|
}, y.onHide = () => {
|
|
118
148
|
x.value = !1, j();
|
|
119
|
-
}, y.update(d.value, h.value), window.addEventListener("keydown",
|
|
149
|
+
}, y.update(d.value, h.value), window.addEventListener("keydown", I, !0);
|
|
120
150
|
}), C([d, h], () => {
|
|
121
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
156
|
ref: g,
|
|
@@ -131,14 +161,14 @@ var X = Symbol("kun-editor-context"), De = [
|
|
|
131
161
|
type: "button",
|
|
132
162
|
class: "kun-mention-dropdown__item",
|
|
133
163
|
"data-active": t === T.value,
|
|
134
|
-
onMousedown: E((t) =>
|
|
164
|
+
onMousedown: E((t) => F(e), ["prevent"]),
|
|
135
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"), De = [
|
|
|
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 } = M(), [, s] = A(), c = l(X), u = t(() => (c?.locale ?? "zh-cn").toLowerCase().startsWith("en")),
|
|
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"), De = [
|
|
|
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
|
-
}),
|
|
264
|
+
}), g.update(r.value, o.value);
|
|
229
265
|
}), C([r, o], () => {
|
|
230
|
-
|
|
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, v(
|
|
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,
|
|
280
|
+
"aria-pressed": t.mark ? x(u)[t.mark] : void 0,
|
|
281
|
+
"data-active": t.mark ? x(u)[t.mark] : void 0,
|
|
244
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,120 +300,91 @@ var X = Symbol("kun-editor-context"), De = [
|
|
|
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 = N(),
|
|
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
|
-
C(
|
|
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(
|
|
321
|
+
let t = g.get();
|
|
322
|
+
t && (s = !0, t.action(G(e)), s = !1);
|
|
285
323
|
}), C(() => i.readonly, () => {
|
|
286
|
-
|
|
287
|
-
let t = e.get(
|
|
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
371
|
}), (e, t) => (m(), n(x(D)));
|
|
334
372
|
}
|
|
335
|
-
}),
|
|
336
|
-
bold: oe,
|
|
337
|
-
italic: ae,
|
|
338
|
-
strike: xe,
|
|
339
|
-
code: G
|
|
340
|
-
}, Ve = () => {
|
|
341
|
-
let [e, t] = A(), n = g({
|
|
342
|
-
bold: !1,
|
|
343
|
-
italic: !1,
|
|
344
|
-
strike: !1,
|
|
345
|
-
code: !1
|
|
346
|
-
}), r = () => {
|
|
347
|
-
t()?.action((e) => {
|
|
348
|
-
let t = e.get(I).state, { from: r, $from: i, to: a, empty: o } = t.selection;
|
|
349
|
-
Object.keys(Be).forEach((s) => {
|
|
350
|
-
let c = Be[s].type(e);
|
|
351
|
-
n[s] = o ? !!c.isInSet(t.storedMarks ?? i.marks()) : t.doc.rangeHasMark(r, a, c);
|
|
352
|
-
});
|
|
353
|
-
});
|
|
354
|
-
};
|
|
355
|
-
return C(e, (e) => {
|
|
356
|
-
e || (t()?.action((e) => {
|
|
357
|
-
let t = e.get(R);
|
|
358
|
-
t.selectionUpdated(r), t.updated(r);
|
|
359
|
-
}), r());
|
|
360
|
-
}, { immediate: !0 }), {
|
|
361
|
-
activeMarks: n,
|
|
362
|
-
refresh: r
|
|
363
|
-
};
|
|
364
|
-
}, He = /* @__PURE__ */ "😀.😃.😄.😁.😆.😅.🤣.😂.🙂.🙃.😉.😊.😇.🥰.😍.🤩.😘.😗.😚.😋.😛.😜.🤪.😝.🤗.🤭.🤔.🤐.😐.😑.😶.😏.😒.🙄.😬.😌.😔.😪.🤤.😴.😷.🤒.🤕.🥵.🥶.🥴.😵.🤯.🤠.🥳.😎.🤓.🧐.😕.😟.🙁.😮.😯.😲.😳.🥺.😦.😧.😨.😰.😥.😢.😭.😱.😖.😣.😞.😓.😩.😫.🥱.😤.😡.😠.🤬.😈.👿.💀.💩.🤡.👻.👽.🤖.😺.😸.👍.👎.👌.🤌.🤏.✌️.🤞.🤟.🤘.👋.🤚.🖐️.✋.👏.🙌.🤝.🙏.💪.👀.👁️.❤️.🧡.💛.💚.💙.💜.🖤.🤍.💔.💕.💞.💓.💗.💖.💘.💝.💯.✨.⭐.🌟.🔥.💥.💫.⚡.☀️.🌈.🎉.🎊.🎁.🏆.🐶.🐱.🐭.🦊.🐻.🐼.🐨.🦄.🐢.🐳.🍎.🍑.🍓.🍉.🍰.🍺.🍵.☕.🍜.🍙.✅.❌.❓.❗.💤.👑.🎮.🎵.📌.🔖".split("."), Ue = [
|
|
373
|
+
}), Ze = /* @__PURE__ */ "😀.😃.😄.😁.😆.😅.🤣.😂.🙂.🙃.😉.😊.😇.🥰.😍.🤩.😘.😗.😚.😋.😛.😜.🤪.😝.🤗.🤭.🤔.🤐.😐.😑.😶.😏.😒.🙄.😬.😌.😔.😪.🤤.😴.😷.🤒.🤕.🥵.🥶.🥴.😵.🤯.🤠.🥳.😎.🤓.🧐.😕.😟.🙁.😮.😯.😲.😳.🥺.😦.😧.😨.😰.😥.😢.😭.😱.😖.😣.😞.😓.😩.😫.🥱.😤.😡.😠.🤬.😈.👿.💀.💩.🤡.👻.👽.🤖.😺.😸.👍.👎.👌.🤌.🤏.✌️.🤞.🤟.🤘.👋.🤚.🖐️.✋.👏.🙌.🤝.🙏.💪.👀.👁️.❤️.🧡.💛.💚.💙.💜.🖤.🤍.💔.💕.💞.💓.💗.💖.💘.💝.💯.✨.⭐.🌟.🔥.💥.💫.⚡.☀️.🌈.🎉.🎊.🎁.🏆.🐶.🐱.🐭.🦊.🐻.🐼.🐨.🦄.🐢.🐳.🍎.🍑.🍓.🍉.🍰.🍺.🍵.☕.🍜.🍙.✅.❌.❓.❗.💤.👑.🎮.🎵.📌.🔖".split("."), Qe = [
|
|
365
374
|
"title",
|
|
366
375
|
"aria-label",
|
|
367
376
|
"aria-expanded"
|
|
368
|
-
],
|
|
377
|
+
], $e = ["innerHTML"], et = { class: "kun-editor__picker-panel" }, tt = {
|
|
369
378
|
key: 0,
|
|
370
379
|
class: "kun-editor__picker-tabs",
|
|
371
380
|
role: "tablist"
|
|
372
|
-
},
|
|
381
|
+
}, nt = ["data-active"], rt = ["data-active"], it = { class: "kun-editor__emoji-grid" }, at = ["onClick"], ot = {
|
|
373
382
|
key: 1,
|
|
374
383
|
class: "kun-editor__sticker-body"
|
|
375
|
-
},
|
|
384
|
+
}, st = { class: "kun-editor__pack-name" }, ct = { class: "kun-editor__sticker-grid" }, lt = ["title", "onClick"], ut = ["src", "alt"], dt = {
|
|
376
385
|
key: 1,
|
|
377
386
|
class: "kun-editor__picker-hint"
|
|
378
|
-
},
|
|
387
|
+
}, ft = /* @__PURE__ */ s({
|
|
379
388
|
__name: "StickerPicker",
|
|
380
389
|
setup(n) {
|
|
381
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 ? {
|
|
@@ -407,11 +416,11 @@ var X = Symbol("kun-editor-context"), De = [
|
|
|
407
416
|
p(() => document.addEventListener("click", j)), f(() => document.removeEventListener("click", j));
|
|
408
417
|
let M = (e) => {
|
|
409
418
|
o()?.action((t) => {
|
|
410
|
-
let n = t.get(
|
|
419
|
+
let n = t.get(L), { state: r } = n;
|
|
411
420
|
n.dispatch(r.tr.insertText(e, r.selection.from));
|
|
412
421
|
});
|
|
413
422
|
}, N = (e, t) => {
|
|
414
|
-
o()?.action(
|
|
423
|
+
o()?.action(W(se.key, {
|
|
415
424
|
src: e,
|
|
416
425
|
title: t,
|
|
417
426
|
alt: t
|
|
@@ -431,28 +440,28 @@ var X = Symbol("kun-editor-context"), De = [
|
|
|
431
440
|
}, [a("span", {
|
|
432
441
|
class: "kun-editor__icon",
|
|
433
442
|
innerHTML: x($).smile
|
|
434
|
-
}, null, 8,
|
|
435
|
-
u ? (m(), i("div",
|
|
443
|
+
}, null, 8, $e)], 8, Qe), T(a("div", et, [
|
|
444
|
+
u ? (m(), i("div", tt, [a("button", {
|
|
436
445
|
type: "button",
|
|
437
446
|
class: "kun-editor__picker-tab",
|
|
438
447
|
"data-active": C.value === "emoji",
|
|
439
448
|
onClick: n[0] ||= (e) => C.value = "emoji"
|
|
440
|
-
}, b(h.value.emoji), 9,
|
|
449
|
+
}, b(h.value.emoji), 9, nt), a("button", {
|
|
441
450
|
type: "button",
|
|
442
451
|
class: "kun-editor__picker-tab",
|
|
443
452
|
"data-active": C.value === "sticker",
|
|
444
453
|
onClick: n[1] ||= (e) => C.value = "sticker"
|
|
445
|
-
}, b(h.value.sticker), 9,
|
|
446
|
-
T(a("div",
|
|
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", {
|
|
447
456
|
key: t,
|
|
448
457
|
type: "button",
|
|
449
458
|
class: "kun-editor__emoji",
|
|
450
459
|
onClick: (t) => M(e)
|
|
451
|
-
}, b(e), 9,
|
|
452
|
-
u ? T((m(), i("div",
|
|
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", {
|
|
453
462
|
key: t.name,
|
|
454
463
|
class: "kun-editor__pack"
|
|
455
|
-
}, [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", {
|
|
456
465
|
key: t,
|
|
457
466
|
type: "button",
|
|
458
467
|
class: "kun-editor__sticker",
|
|
@@ -462,37 +471,37 @@ var X = Symbol("kun-editor-context"), De = [
|
|
|
462
471
|
src: e.src,
|
|
463
472
|
alt: e.name,
|
|
464
473
|
loading: "lazy"
|
|
465
|
-
}, null, 8,
|
|
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)
|
|
466
475
|
], 512), [[S, g.value]])], 512));
|
|
467
476
|
}
|
|
468
|
-
}),
|
|
477
|
+
}), pt = {
|
|
469
478
|
class: "kun-editor__format-toolbar",
|
|
470
479
|
role: "toolbar"
|
|
471
|
-
},
|
|
480
|
+
}, mt = ["aria-label"], ht = {
|
|
472
481
|
value: "",
|
|
473
482
|
disabled: "",
|
|
474
483
|
selected: ""
|
|
475
|
-
},
|
|
484
|
+
}, gt = ["value"], _t = [
|
|
476
485
|
"title",
|
|
477
486
|
"aria-label",
|
|
478
487
|
"aria-pressed",
|
|
479
488
|
"data-active",
|
|
480
489
|
"onClick"
|
|
481
|
-
],
|
|
490
|
+
], vt = ["innerHTML"], yt = ["title", "aria-label"], bt = ["innerHTML"], xt = /* @__PURE__ */ s({
|
|
482
491
|
__name: "EditorToolbar",
|
|
483
492
|
setup(n) {
|
|
484
|
-
let [, s] = A(), c = l(X),
|
|
485
|
-
s()?.action(
|
|
486
|
-
},
|
|
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 () => {
|
|
487
496
|
let e = "";
|
|
488
497
|
s()?.action((t) => {
|
|
489
|
-
let n = t.get(
|
|
498
|
+
let n = t.get(L), { from: r, to: i } = n.state.selection;
|
|
490
499
|
e = n.state.doc.textBetween(r, i, " ");
|
|
491
500
|
});
|
|
492
|
-
let t = c?.adapters.linkPrompt, n = (t ? await t({ text: e }) : window.prompt(
|
|
493
|
-
n &&
|
|
494
|
-
},
|
|
495
|
-
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;
|
|
496
505
|
return {
|
|
497
506
|
textSize: e ? "Text size" : "文本大小",
|
|
498
507
|
bold: e ? "Bold" : "加粗",
|
|
@@ -508,8 +517,8 @@ var X = Symbol("kun-editor-context"), De = [
|
|
|
508
517
|
spoiler: e ? "Spoiler" : "隐藏文本",
|
|
509
518
|
image: e ? "Upload image" : "上传图片"
|
|
510
519
|
};
|
|
511
|
-
}),
|
|
512
|
-
let e =
|
|
520
|
+
}), S = t(() => {
|
|
521
|
+
let e = p.value;
|
|
513
522
|
return [
|
|
514
523
|
"正文",
|
|
515
524
|
"一级标题",
|
|
@@ -522,95 +531,95 @@ var X = Symbol("kun-editor-context"), De = [
|
|
|
522
531
|
level: n,
|
|
523
532
|
label: e ? n === 0 ? "Paragraph" : `Heading ${n}` : t
|
|
524
533
|
}));
|
|
525
|
-
}),
|
|
534
|
+
}), C = (e) => {
|
|
526
535
|
let t = e.target;
|
|
527
|
-
|
|
528
|
-
},
|
|
536
|
+
h(Se.key, Number(t.value)), t.selectedIndex = 0;
|
|
537
|
+
}, w = t(() => [
|
|
529
538
|
[
|
|
530
539
|
{
|
|
531
540
|
svg: $.bold,
|
|
532
|
-
title:
|
|
533
|
-
run: () =>
|
|
541
|
+
title: y.value.bold,
|
|
542
|
+
run: () => h(de.key),
|
|
534
543
|
mark: "bold"
|
|
535
544
|
},
|
|
536
545
|
{
|
|
537
546
|
svg: $.italic,
|
|
538
|
-
title:
|
|
539
|
-
run: () =>
|
|
547
|
+
title: y.value.italic,
|
|
548
|
+
run: () => h(le.key),
|
|
540
549
|
mark: "italic"
|
|
541
550
|
},
|
|
542
551
|
{
|
|
543
552
|
svg: $.strike,
|
|
544
|
-
title:
|
|
545
|
-
run: () =>
|
|
553
|
+
title: y.value.strike,
|
|
554
|
+
run: () => h(Te.key),
|
|
546
555
|
mark: "strike"
|
|
547
556
|
},
|
|
548
557
|
{
|
|
549
558
|
svg: $.code,
|
|
550
|
-
title:
|
|
551
|
-
run: () =>
|
|
559
|
+
title: y.value.code,
|
|
560
|
+
run: () => h(ue.key),
|
|
552
561
|
mark: "code"
|
|
553
562
|
},
|
|
554
563
|
{
|
|
555
564
|
svg: $.link,
|
|
556
|
-
title:
|
|
557
|
-
run:
|
|
565
|
+
title: y.value.link,
|
|
566
|
+
run: g
|
|
558
567
|
}
|
|
559
568
|
],
|
|
560
569
|
[
|
|
561
570
|
{
|
|
562
571
|
svg: $.bulletList,
|
|
563
|
-
title:
|
|
564
|
-
run: () =>
|
|
572
|
+
title: y.value.bulletList,
|
|
573
|
+
run: () => h(pe.key)
|
|
565
574
|
},
|
|
566
575
|
{
|
|
567
576
|
svg: $.orderedList,
|
|
568
|
-
title:
|
|
569
|
-
run: () =>
|
|
577
|
+
title: y.value.orderedList,
|
|
578
|
+
run: () => h(me.key)
|
|
570
579
|
},
|
|
571
580
|
{
|
|
572
581
|
svg: $.quote,
|
|
573
|
-
title:
|
|
574
|
-
run: () =>
|
|
582
|
+
title: y.value.quote,
|
|
583
|
+
run: () => h(fe.key)
|
|
575
584
|
},
|
|
576
585
|
{
|
|
577
586
|
svg: $.codeBlock,
|
|
578
|
-
title:
|
|
579
|
-
run: () =>
|
|
587
|
+
title: y.value.codeBlock,
|
|
588
|
+
run: () => h(ie.key, "")
|
|
580
589
|
},
|
|
581
590
|
{
|
|
582
591
|
svg: $.hr,
|
|
583
|
-
title:
|
|
584
|
-
run: () =>
|
|
592
|
+
title: y.value.hr,
|
|
593
|
+
run: () => h(oe.key)
|
|
585
594
|
}
|
|
586
595
|
],
|
|
587
596
|
[{
|
|
588
597
|
svg: $.spoiler,
|
|
589
|
-
title:
|
|
590
|
-
run: () =>
|
|
598
|
+
title: y.value.spoiler,
|
|
599
|
+
run: () => h(ge.key)
|
|
591
600
|
}]
|
|
592
|
-
]),
|
|
601
|
+
]), T = _(null), E = () => T.value?.click(), D = (e) => {
|
|
593
602
|
let t = e.target, n = t.files?.[0];
|
|
594
603
|
t.value = "";
|
|
595
|
-
let r =
|
|
604
|
+
let r = d.value;
|
|
596
605
|
!n || !r || s()?.action((e) => {
|
|
597
|
-
|
|
606
|
+
Ce(e.get(L), n, {
|
|
598
607
|
uploadImage: r,
|
|
599
608
|
notify: c?.adapters.notify,
|
|
600
609
|
locale: c?.locale
|
|
601
610
|
});
|
|
602
611
|
});
|
|
603
612
|
};
|
|
604
|
-
return (t, n) => (m(), i("div",
|
|
613
|
+
return (t, n) => (m(), i("div", pt, [
|
|
605
614
|
a("select", {
|
|
606
615
|
class: "kun-editor__heading-select",
|
|
607
|
-
"aria-label":
|
|
608
|
-
onChange:
|
|
609
|
-
}, [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", {
|
|
610
619
|
key: e.level,
|
|
611
620
|
value: e.level
|
|
612
|
-
}, b(e.label), 9,
|
|
613
|
-
(m(!0), i(e, null, v(
|
|
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", {
|
|
614
623
|
class: "kun-editor__toolbar-divider",
|
|
615
624
|
"aria-hidden": "true"
|
|
616
625
|
}, null, -1), (m(!0), i(e, null, v(t, (e, t) => (m(), i("button", {
|
|
@@ -625,8 +634,8 @@ var X = Symbol("kun-editor-context"), De = [
|
|
|
625
634
|
}, [a("span", {
|
|
626
635
|
class: "kun-editor__icon",
|
|
627
636
|
innerHTML: e.svg
|
|
628
|
-
}, null, 8,
|
|
629
|
-
|
|
637
|
+
}, null, 8, vt)], 8, _t))), 128))], 64))), 128)),
|
|
638
|
+
d.value ? (m(), i(e, { key: 0 }, [
|
|
630
639
|
n[1] ||= a("span", {
|
|
631
640
|
class: "kun-editor__toolbar-divider",
|
|
632
641
|
"aria-hidden": "true"
|
|
@@ -634,48 +643,50 @@ var X = Symbol("kun-editor-context"), De = [
|
|
|
634
643
|
a("button", {
|
|
635
644
|
type: "button",
|
|
636
645
|
class: "kun-editor__tool",
|
|
637
|
-
title:
|
|
638
|
-
"aria-label":
|
|
639
|
-
onClick:
|
|
646
|
+
title: y.value.image,
|
|
647
|
+
"aria-label": y.value.image,
|
|
648
|
+
onClick: E
|
|
640
649
|
}, [a("span", {
|
|
641
650
|
class: "kun-editor__icon",
|
|
642
651
|
innerHTML: x($).image
|
|
643
|
-
}, null, 8,
|
|
652
|
+
}, null, 8, bt)], 8, yt),
|
|
644
653
|
a("input", {
|
|
645
654
|
ref_key: "fileInput",
|
|
646
|
-
ref:
|
|
655
|
+
ref: T,
|
|
647
656
|
type: "file",
|
|
648
657
|
accept: ".jpg,.jpeg,.png,.webp,.gif",
|
|
649
658
|
hidden: "",
|
|
650
|
-
onChange:
|
|
659
|
+
onChange: D
|
|
651
660
|
}, null, 544)
|
|
652
661
|
], 64)) : r("", !0),
|
|
653
|
-
|
|
662
|
+
f.value ? (m(), i(e, { key: 1 }, [n[2] ||= a("span", {
|
|
654
663
|
class: "kun-editor__toolbar-divider",
|
|
655
664
|
"aria-hidden": "true"
|
|
656
|
-
}, null, -1), o(
|
|
665
|
+
}, null, -1), o(ft)], 64)) : r("", !0)
|
|
657
666
|
]));
|
|
658
667
|
}
|
|
659
|
-
}),
|
|
668
|
+
}), St = /* @__PURE__ */ s({
|
|
660
669
|
__name: "ToolbarHost",
|
|
661
670
|
setup(e) {
|
|
662
|
-
let [, t] = A(), n = l(X, void 0),
|
|
663
|
-
t()?.action(
|
|
664
|
-
},
|
|
665
|
-
t()?.action((e) => e.get(
|
|
666
|
-
},
|
|
667
|
-
run:
|
|
668
|
-
activeMarks
|
|
671
|
+
let [, t] = A(), n = l(X, void 0), r = (e, n) => {
|
|
672
|
+
t()?.action(W(e, n));
|
|
673
|
+
}, i = () => {
|
|
674
|
+
t()?.action((e) => e.get(L).focus());
|
|
675
|
+
}, a = {
|
|
676
|
+
run: r,
|
|
677
|
+
get activeMarks() {
|
|
678
|
+
return n?.activeMarks ?? Ne;
|
|
679
|
+
},
|
|
669
680
|
insertText: (e) => {
|
|
670
681
|
t()?.action((t) => {
|
|
671
|
-
let n = t.get(
|
|
682
|
+
let n = t.get(L);
|
|
672
683
|
n.dispatch(n.state.tr.insertText(e));
|
|
673
|
-
}),
|
|
684
|
+
}), i();
|
|
674
685
|
},
|
|
675
686
|
uploadImage: (e) => {
|
|
676
687
|
let r = n?.adapters.uploadImage, i = t();
|
|
677
688
|
!r || !i || i.action((t) => {
|
|
678
|
-
|
|
689
|
+
Ce(t.get(L), e, {
|
|
679
690
|
uploadImage: r,
|
|
680
691
|
notify: n?.adapters.notify,
|
|
681
692
|
locale: n?.locale
|
|
@@ -683,22 +694,22 @@ var X = Symbol("kun-editor-context"), De = [
|
|
|
683
694
|
});
|
|
684
695
|
},
|
|
685
696
|
insertLink: (e) => {
|
|
686
|
-
|
|
697
|
+
r(_e.key, e), i();
|
|
687
698
|
},
|
|
688
699
|
insertImage: (e) => {
|
|
689
|
-
|
|
700
|
+
r(se.key, {
|
|
690
701
|
src: e.src,
|
|
691
702
|
alt: e.alt ?? "",
|
|
692
703
|
title: e.title ?? ""
|
|
693
|
-
}),
|
|
704
|
+
}), i();
|
|
694
705
|
},
|
|
695
706
|
insertQuote: (e) => {
|
|
696
|
-
|
|
707
|
+
r(ye.key, e), i();
|
|
697
708
|
},
|
|
698
709
|
insertMention: (e) => {
|
|
699
|
-
|
|
710
|
+
r(ve.key, e), i();
|
|
700
711
|
},
|
|
701
|
-
focus:
|
|
712
|
+
focus: i,
|
|
702
713
|
get adapters() {
|
|
703
714
|
return n?.adapters ?? {};
|
|
704
715
|
},
|
|
@@ -709,9 +720,9 @@ var X = Symbol("kun-editor-context"), De = [
|
|
|
709
720
|
return n?.locale ?? "zh-cn";
|
|
710
721
|
}
|
|
711
722
|
};
|
|
712
|
-
return (e, t) => y(e.$slots, "default", d(c(
|
|
723
|
+
return (e, t) => y(e.$slots, "default", d(c(a)));
|
|
713
724
|
}
|
|
714
|
-
}),
|
|
725
|
+
}), Ct = /* @__PURE__ */ s({
|
|
715
726
|
__name: "MarkdownSource",
|
|
716
727
|
props: {
|
|
717
728
|
modelValue: {},
|
|
@@ -719,13 +730,13 @@ var X = Symbol("kun-editor-context"), De = [
|
|
|
719
730
|
},
|
|
720
731
|
emits: ["update:modelValue"],
|
|
721
732
|
setup(e, { expose: t, emit: n }) {
|
|
722
|
-
let r = e, a = n, o = _(null), s = null, c =
|
|
733
|
+
let r = e, a = n, o = _(null), s = null, c = Ee.define(), l = (e) => De.create({
|
|
723
734
|
doc: e,
|
|
724
735
|
extensions: [
|
|
725
|
-
|
|
736
|
+
be(),
|
|
726
737
|
Y.lineWrapping,
|
|
727
|
-
|
|
728
|
-
|
|
738
|
+
ke,
|
|
739
|
+
Oe(),
|
|
729
740
|
Y.editable.of(!r.readonly),
|
|
730
741
|
Y.updateListener.of((e) => {
|
|
731
742
|
e.docChanged && !e.transactions.some((e) => e.annotation(c)) && a("update:modelValue", e.state.doc.toString());
|
|
@@ -783,23 +794,23 @@ var X = Symbol("kun-editor-context"), De = [
|
|
|
783
794
|
class: "kun-editor__source"
|
|
784
795
|
}, null, 512));
|
|
785
796
|
}
|
|
786
|
-
}),
|
|
797
|
+
}), wt = ["data-mode"], Tt = {
|
|
787
798
|
key: 0,
|
|
788
799
|
class: "kun-editor__toolbar",
|
|
789
800
|
role: "tablist"
|
|
790
|
-
},
|
|
801
|
+
}, Et = [
|
|
791
802
|
"aria-selected",
|
|
792
803
|
"data-active",
|
|
793
804
|
"onClick"
|
|
794
|
-
],
|
|
805
|
+
], Dt = ["title", "aria-label"], Ot = [
|
|
795
806
|
"data-active",
|
|
796
807
|
"title",
|
|
797
808
|
"aria-pressed"
|
|
798
|
-
],
|
|
809
|
+
], kt = ["data-swap"], At = { class: "kun-editor__wysiwyg kun-editor__pane" }, jt = {
|
|
799
810
|
key: 1,
|
|
800
811
|
class: "kun-editor__loading",
|
|
801
812
|
"aria-hidden": "true"
|
|
802
|
-
},
|
|
813
|
+
}, Mt = /* @__PURE__ */ s({
|
|
803
814
|
__name: "KunEditor",
|
|
804
815
|
props: {
|
|
805
816
|
modelValue: {},
|
|
@@ -831,49 +842,54 @@ var X = Symbol("kun-editor-context"), De = [
|
|
|
831
842
|
"update:headings",
|
|
832
843
|
"update:loading"
|
|
833
844
|
],
|
|
834
|
-
setup(s, { expose: l, emit:
|
|
835
|
-
let
|
|
845
|
+
setup(s, { expose: l, emit: E }) {
|
|
846
|
+
let D = [
|
|
836
847
|
"bold",
|
|
837
848
|
"italic",
|
|
838
849
|
"strike",
|
|
839
850
|
"code",
|
|
840
851
|
"link"
|
|
841
|
-
],
|
|
852
|
+
], k = s, A = E, M = _(!1);
|
|
842
853
|
p(() => {
|
|
843
|
-
|
|
854
|
+
M.value = !0;
|
|
844
855
|
});
|
|
845
|
-
let
|
|
846
|
-
|
|
856
|
+
let N = _(!0), P = (e) => {
|
|
857
|
+
N.value = e, A("update:loading", e);
|
|
847
858
|
};
|
|
848
|
-
C(() =>
|
|
859
|
+
C(() => k.modelValue, (e) => A("update:headings", ee(e)), { immediate: !0 });
|
|
860
|
+
let F = g(Me());
|
|
861
|
+
h(X, {
|
|
849
862
|
get adapters() {
|
|
850
|
-
return
|
|
863
|
+
return k.adapters;
|
|
851
864
|
},
|
|
852
865
|
get features() {
|
|
853
|
-
return
|
|
866
|
+
return k.features;
|
|
854
867
|
},
|
|
855
868
|
get locale() {
|
|
856
|
-
return
|
|
869
|
+
return k.locale;
|
|
857
870
|
},
|
|
858
871
|
get selectionToolbarItems() {
|
|
859
|
-
return Array.isArray(
|
|
872
|
+
return Array.isArray(k.selectionToolbar) ? k.selectionToolbar : D;
|
|
873
|
+
},
|
|
874
|
+
get activeMarks() {
|
|
875
|
+
return F;
|
|
860
876
|
}
|
|
861
877
|
});
|
|
862
|
-
let
|
|
863
|
-
|
|
878
|
+
let I = t(() => k.selectionToolbar !== !1), L = _(k.views.includes("wysiwyg") ? "wysiwyg" : k.views[0] ?? "wysiwyg"), R = (e) => {
|
|
879
|
+
L.value = e;
|
|
864
880
|
};
|
|
865
|
-
C(() =>
|
|
866
|
-
e.includes(
|
|
881
|
+
C(() => k.views, (e) => {
|
|
882
|
+
e.includes(L.value) || (L.value = e[0] ?? "wysiwyg");
|
|
867
883
|
});
|
|
868
|
-
let
|
|
869
|
-
|
|
870
|
-
},
|
|
871
|
-
C(() =>
|
|
872
|
-
|
|
884
|
+
let z = _(!1), B = () => {
|
|
885
|
+
z.value = !z.value;
|
|
886
|
+
}, V = _(k.scrollSync);
|
|
887
|
+
C(() => k.scrollSync, (e) => {
|
|
888
|
+
V.value = e;
|
|
873
889
|
});
|
|
874
|
-
let
|
|
875
|
-
|
|
876
|
-
},
|
|
890
|
+
let H = () => {
|
|
891
|
+
V.value = !V.value;
|
|
892
|
+
}, te = t(() => k.locale.toLowerCase().startsWith("en")), U = t(() => te.value ? {
|
|
877
893
|
wysiwyg: "Preview",
|
|
878
894
|
source: "Markdown",
|
|
879
895
|
split: "Split",
|
|
@@ -885,104 +901,104 @@ var X = Symbol("kun-editor-context"), De = [
|
|
|
885
901
|
split: "分栏",
|
|
886
902
|
swap: "左右互换",
|
|
887
903
|
scrollSync: "同步滚动"
|
|
888
|
-
}),
|
|
889
|
-
|
|
890
|
-
},
|
|
891
|
-
|
|
892
|
-
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;
|
|
893
909
|
if (!e) return;
|
|
894
910
|
let t = e.querySelector(".cm-scroller"), n = e.querySelector(".kun-editor__wysiwyg");
|
|
895
911
|
if (!t || !n) return;
|
|
896
912
|
let r = (e, t) => () => {
|
|
897
|
-
if (
|
|
898
|
-
|
|
913
|
+
if (G && G !== e) return;
|
|
914
|
+
G = e;
|
|
899
915
|
let n = e.scrollHeight - e.clientHeight, r = n > 0 ? e.scrollTop / n : 0, i = t.scrollHeight - t.clientHeight;
|
|
900
|
-
t.scrollTop = r * (i > 0 ? i : 0),
|
|
901
|
-
|
|
916
|
+
t.scrollTop = r * (i > 0 ? i : 0), K && clearTimeout(K), K = setTimeout(() => {
|
|
917
|
+
G = null;
|
|
902
918
|
}, 120);
|
|
903
919
|
}, i = r(t, n), a = r(n, t);
|
|
904
|
-
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 = () => {
|
|
905
921
|
t.removeEventListener("scroll", i), n.removeEventListener("scroll", a);
|
|
906
922
|
};
|
|
907
923
|
};
|
|
908
|
-
C([
|
|
909
|
-
|
|
910
|
-
}), f(
|
|
911
|
-
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);
|
|
912
928
|
return l({
|
|
913
|
-
insertQuote: (e) =>
|
|
914
|
-
insertMention: (e) =>
|
|
915
|
-
insertImage: (e) =>
|
|
916
|
-
uploadImage: (e) =>
|
|
917
|
-
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(),
|
|
918
934
|
scrollToHeading: (e) => {
|
|
919
|
-
|
|
935
|
+
L.value === "source" || L.value === "split" ? oe.value?.scrollToHeading(e) : J.value?.scrollToHeading(e);
|
|
920
936
|
}
|
|
921
937
|
}), (t, l) => (m(), i("div", {
|
|
922
938
|
ref_key: "rootEl",
|
|
923
|
-
ref:
|
|
939
|
+
ref: ne,
|
|
924
940
|
class: "kun-editor",
|
|
925
941
|
"data-kun-editor": "",
|
|
926
|
-
"data-mode":
|
|
927
|
-
}, [
|
|
928
|
-
mode:
|
|
929
|
-
setMode:
|
|
930
|
-
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,
|
|
931
947
|
views: s.views,
|
|
932
|
-
swapped:
|
|
933
|
-
swap:
|
|
934
|
-
scrollSync:
|
|
935
|
-
toggleScrollSync:
|
|
936
|
-
}, () => [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", {
|
|
937
953
|
key: e,
|
|
938
954
|
type: "button",
|
|
939
955
|
class: "kun-editor__tab",
|
|
940
|
-
"aria-selected":
|
|
941
|
-
"data-active":
|
|
942
|
-
onClick: (t) =>
|
|
943
|
-
}, b(
|
|
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", {
|
|
944
960
|
type: "button",
|
|
945
961
|
class: "kun-editor__tab kun-editor__swap",
|
|
946
|
-
title:
|
|
947
|
-
"aria-label":
|
|
948
|
-
onClick: l[0] ||= (e) =>
|
|
949
|
-
}, " ⇄ ", 8,
|
|
962
|
+
title: U.value.swap,
|
|
963
|
+
"aria-label": U.value.swap,
|
|
964
|
+
onClick: l[0] ||= (e) => B()
|
|
965
|
+
}, " ⇄ ", 8, Dt), a("button", {
|
|
950
966
|
type: "button",
|
|
951
967
|
class: "kun-editor__tab",
|
|
952
|
-
"data-active":
|
|
953
|
-
title:
|
|
954
|
-
"aria-pressed":
|
|
955
|
-
onClick: l[1] ||= (e) =>
|
|
956
|
-
}, b(
|
|
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, {
|
|
957
973
|
default: w(() => [o(x(j), null, {
|
|
958
|
-
default: w(() => [T(a("div", null, [o(
|
|
959
|
-
default: w((e) => [y(t.$slots, "toolbar", d(c(e)), () => [o(
|
|
974
|
+
default: w(() => [T(a("div", null, [o(St, null, {
|
|
975
|
+
default: w((e) => [y(t.$slots, "toolbar", d(c(e)), () => [o(xt)])]),
|
|
960
976
|
_: 3
|
|
961
|
-
})], 512), [[S,
|
|
977
|
+
})], 512), [[S, L.value === "wysiwyg" && !s.readonly]]), a("div", {
|
|
962
978
|
class: "kun-editor__panes",
|
|
963
|
-
"data-swap":
|
|
964
|
-
}, [
|
|
979
|
+
"data-swap": z.value
|
|
980
|
+
}, [L.value === "source" || L.value === "split" ? (m(), n(Ct, {
|
|
965
981
|
key: 0,
|
|
966
982
|
ref_key: "source",
|
|
967
|
-
ref:
|
|
983
|
+
ref: oe,
|
|
968
984
|
class: "kun-editor__pane",
|
|
969
985
|
"model-value": s.modelValue,
|
|
970
986
|
readonly: s.readonly,
|
|
971
|
-
"onUpdate:modelValue":
|
|
972
|
-
}, null, 8, ["model-value", "readonly"])) : r("", !0), T(a("div",
|
|
987
|
+
"onUpdate:modelValue": ae
|
|
988
|
+
}, null, 8, ["model-value", "readonly"])) : r("", !0), T(a("div", At, [o(Xe, {
|
|
973
989
|
ref_key: "inner",
|
|
974
|
-
ref:
|
|
990
|
+
ref: J,
|
|
975
991
|
"model-value": s.modelValue,
|
|
976
992
|
adapters: s.adapters,
|
|
977
993
|
features: s.features,
|
|
978
994
|
locale: s.locale,
|
|
979
|
-
readonly:
|
|
995
|
+
readonly: ie.value,
|
|
980
996
|
placeholder: s.placeholder,
|
|
981
997
|
"placeholder-mode": s.placeholderMode,
|
|
982
|
-
active:
|
|
983
|
-
"selection-toolbar":
|
|
984
|
-
"onUpdate:modelValue":
|
|
985
|
-
"onUpdate:loading":
|
|
998
|
+
active: L.value === "wysiwyg" && !s.readonly,
|
|
999
|
+
"selection-toolbar": I.value,
|
|
1000
|
+
"onUpdate:modelValue": ae,
|
|
1001
|
+
"onUpdate:loading": P
|
|
986
1002
|
}, null, 8, [
|
|
987
1003
|
"model-value",
|
|
988
1004
|
"adapters",
|
|
@@ -993,18 +1009,18 @@ var X = Symbol("kun-editor-context"), De = [
|
|
|
993
1009
|
"placeholder-mode",
|
|
994
1010
|
"active",
|
|
995
1011
|
"selection-toolbar"
|
|
996
|
-
])], 512), [[S,
|
|
1012
|
+
])], 512), [[S, L.value === "wysiwyg" || L.value === "split"]])], 8, kt)]),
|
|
997
1013
|
_: 3
|
|
998
1014
|
})]),
|
|
999
1015
|
_: 3
|
|
1000
|
-
})], 64)) : r("", !0), !
|
|
1016
|
+
})], 64)) : r("", !0), !M.value || N.value ? (m(), i("div", jt, [y(t.$slots, "loading", {}, () => [
|
|
1001
1017
|
l[2] ||= a("div", { class: "kun-editor__skeleton" }, null, -1),
|
|
1002
1018
|
l[3] ||= a("div", { class: "kun-editor__skeleton" }, null, -1),
|
|
1003
1019
|
l[4] ||= a("div", { class: "kun-editor__skeleton" }, null, -1)
|
|
1004
|
-
])])) : r("", !0)], 8,
|
|
1020
|
+
])])) : r("", !0)], 8, wt));
|
|
1005
1021
|
}
|
|
1006
|
-
}),
|
|
1007
|
-
e.component("KunEditor",
|
|
1022
|
+
}), Nt = { install(e) {
|
|
1023
|
+
e.component("KunEditor", Mt);
|
|
1008
1024
|
} };
|
|
1009
1025
|
//#endregion
|
|
1010
|
-
export {
|
|
1026
|
+
export { Ze as EMOJI, Mt as KunEditor, Nt as KunEditorPlugin, P as parseHeadings };
|