@kungal/editor-vue 0.32.0 → 0.33.0

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