@kungal/editor-vue 0.31.1 → 0.32.1

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