@kungal/editor-vue 0.22.0 → 0.24.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/CHANGELOG.md CHANGED
@@ -1,5 +1,68 @@
1
1
  # @kungal/editor-vue
2
2
 
3
+ ## 0.24.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 5c981df: The selection bubble toolbar's buttons are now configurable.
8
+
9
+ `<KunEditor>`'s `selectionToolbar` prop now accepts `boolean | KunSelectionItem[]`:
10
+
11
+ ```vue
12
+ <KunEditor v-model="md" />
13
+ <!-- default 4 buttons -->
14
+ <KunEditor v-model="md" :selection-toolbar="['bold', 'italic']" />
15
+ <!-- reorder / subset -->
16
+ <KunEditor v-model="md" :selection-toolbar="false" />
17
+ <!-- off -->
18
+ ```
19
+
20
+ `KunSelectionItem` is `'bold' | 'italic' | 'strike' | 'code' | '|'` (`'|'` a
21
+ divider), exported from `@kungal/editor-vue`. The resolved items reach the bubble
22
+ (a plugin view) through the editor context; dividers collapse around removed
23
+ items. The bubble's **look** is (and was) styled via the `.kun-editor__bubble` /
24
+ `.kun-editor__bubble-btn` class hooks — headless, no new API.
25
+
26
+ Verified in the docs production build: an editor with
27
+ `:selection-toolbar="['bold','italic']"` shows a 2-button bubble while the default
28
+ shows 4; 0 console errors.
29
+
30
+ ### Patch Changes
31
+
32
+ - @kungal/editor-core@0.24.0
33
+
34
+ ## 0.23.0
35
+
36
+ ### Minor Changes
37
+
38
+ - 78e637e: `<KunEditor>` gains a `views` prop to control which view modes the switch offers.
39
+
40
+ The split view is great on a full editor but heavy in a small reply/comment box —
41
+ and there was no way to opt out per-editor (all or nothing). Now pass `views`:
42
+
43
+ ```vue
44
+ <!-- edit page: all three (default) -->
45
+ <KunEditor v-model="md" />
46
+ <!-- reply / comment: no split -->
47
+ <KunEditor v-model="md" :views="['wysiwyg', 'source']" />
48
+ <!-- just WYSIWYG: the switch bar is hidden entirely -->
49
+ <KunEditor v-model="md" :views="['wysiwyg']" />
50
+ ```
51
+
52
+ - Default `['wysiwyg', 'source', 'split']`. The view switch renders only the
53
+ offered modes, and disappears when a single mode is offered. If `views` changes
54
+ to exclude the active mode, it falls back to the first offered.
55
+ - `KunEditorViewSwitchApi` gains `views`; the default view switch and
56
+ `<KunEditorViewSwitch>` (editor-nuxt) both render from it.
57
+
58
+ Verified in the docs production build: an editor with `:views="['wysiwyg','source']"`
59
+ shows only 预览/Markdown (no 分栏), while default editors still show all three; 0
60
+ console errors.
61
+
62
+ ### Patch Changes
63
+
64
+ - @kungal/editor-core@0.23.0
65
+
3
66
  ## 0.22.0
4
67
 
5
68
  ### Minor Changes
@@ -1,5 +1,6 @@
1
1
  import type { KunEditorAdapters, KunEditorFeatures, KunEditorLocale } from '@kungal/editor-core';
2
- import type { KunEditorExpose } from '../types';
2
+ import type { KunEditorExpose, KunSelectionItem } from '../types';
3
+ type ViewMode = 'wysiwyg' | 'source' | 'split';
3
4
  type __VLS_Props = {
4
5
  /** Bound markdown (v-model). */
5
6
  modelValue: string;
@@ -13,13 +14,23 @@ type __VLS_Props = {
13
14
  readonly?: boolean;
14
15
  /** Placeholder text shown while the editor is empty. */
15
16
  placeholder?: string;
17
+ /**
18
+ * Which view modes to offer in the switch. Default all three. Drop `'split'`
19
+ * (or use just `['wysiwyg']`) for compact editors like a reply/comment box —
20
+ * a single-mode `views` hides the switch bar entirely.
21
+ */
22
+ views?: ViewMode[];
16
23
  /** Sync scrolling between the split panes. Default `true`; set `false` to
17
24
  * disable (or toggle it at runtime via the view-switch API). */
18
25
  scrollSync?: boolean;
19
- /** Show a floating format toolbar on text selection. Default `true`. */
20
- selectionToolbar?: boolean;
26
+ /**
27
+ * The floating toolbar shown on text selection. `true` (default) = the
28
+ * standard buttons; `false` = off; or pass an ordered `KunSelectionItem[]`
29
+ * to reorder / subset them (`'|'` is a divider). Its look is styled via the
30
+ * `.kun-editor__bubble` / `.kun-editor__bubble-btn` class hooks.
31
+ */
32
+ selectionToolbar?: boolean | KunSelectionItem[];
21
33
  };
22
- type ViewMode = 'wysiwyg' | 'source' | 'split';
23
34
  declare var __VLS_1: {
24
35
  mode: ViewMode;
25
36
  setMode: (m: ViewMode) => void;
@@ -30,6 +41,7 @@ declare var __VLS_1: {
30
41
  swap: string;
31
42
  scrollSync: string;
32
43
  };
44
+ views: ViewMode[];
33
45
  swapped: boolean;
34
46
  swap: () => void;
35
47
  scrollSync: boolean;
@@ -66,7 +78,8 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, KunEditorEx
66
78
  locale: KunEditorLocale;
67
79
  readonly: boolean;
68
80
  placeholder: string;
69
- selectionToolbar: boolean;
81
+ selectionToolbar: boolean | KunSelectionItem[];
82
+ views: ViewMode[];
70
83
  scrollSync: boolean;
71
84
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
72
85
  declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
@@ -1 +1 @@
1
- {"version":3,"file":"KunEditor.vue.d.ts","sourceRoot":"","sources":["../../src/components/KunEditor.vue"],"names":[],"mappings":"AAiUA,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EAChB,MAAM,qBAAqB,CAAA;AAM5B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAE/C,KAAK,WAAW,GAAG;IACf,gCAAgC;IAChC,UAAU,EAAE,MAAM,CAAA;IAClB,uEAAuE;IACvE,QAAQ,CAAC,EAAE,iBAAiB,CAAA;IAC5B,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,iBAAiB,CAAA;IAC5B,qDAAqD;IACrD,MAAM,CAAC,EAAE,eAAe,CAAA;IACxB,qCAAqC;IACrC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,wDAAwD;IACxD,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;oEACgE;IAChE,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,wEAAwE;IACxE,gBAAgB,CAA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../../src/components/SelectionTooltip.vue"],"names":[],"mappings":"AAyMA,QAAA,MAAM,YAAY,+QAChB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
1
+ {"version":3,"file":"SelectionTooltip.vue.d.ts","sourceRoot":"","sources":["../../src/components/SelectionTooltip.vue"],"names":[],"mappings":"AA2RA,QAAA,MAAM,YAAY,+QAChB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
@@ -1 +1 @@
1
- {"version":3,"file":"ToolbarHost.vue.d.ts","sourceRoot":"","sources":["../../src/components/ToolbarHost.vue"],"names":[],"mappings":"AAyFA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAuFhD,QAAA,IAAI,OAAO;oCAxFX,CA9DM;;;;;;;;;;;;;;;CAsJgB,CAAE;AACxB,KAAK,WAAW,GAAG,EAAE,GACnB;IAAE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,OAAO,KAAK,GAAG,CAAA;CAAE,CAAC;AAG/C,QAAA,MAAM,UAAU,+QACd,CAAC;AACH,QAAA,MAAM,YAAY,EAAS,eAAe,CAAC,OAAO,UAAU,EAAE,WAAW,CAAC,CAAC;wBACtD,OAAO,YAAY;AAAxC,wBAAyC;AACzC,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
1
+ {"version":3,"file":"ToolbarHost.vue.d.ts","sourceRoot":"","sources":["../../src/components/ToolbarHost.vue"],"names":[],"mappings":"AAyFA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAuFhD,QAAA,IAAI,OAAO;oCAxFX,CArDQ;;;;;;;;;;;;;;;CA6Ic,CAAE;AACxB,KAAK,WAAW,GAAG,EAAE,GACnB;IAAE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,OAAO,KAAK,GAAG,CAAA;CAAE,CAAC;AAG/C,QAAA,MAAM,UAAU,+QACd,CAAC;AACH,QAAA,MAAM,YAAY,EAAS,eAAe,CAAC,OAAO,UAAU,EAAE,WAAW,CAAC,CAAC;wBACtD,OAAO,YAAY;AAAxC,wBAAyC;AACzC,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
package/dist/context.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { InjectionKey } from 'vue';
2
2
  import type { KunEditorAdapters, KunEditorFeatures, KunEditorLocale } from '@kungal/editor-core';
3
+ import type { KunSelectionItem } from './types';
3
4
  export interface KunEditorContext {
4
5
  /** The host policy bundle (searchMentionUsers, stickerSource, notify, …). */
5
6
  readonly adapters: KunEditorAdapters;
@@ -7,6 +8,8 @@ export interface KunEditorContext {
7
8
  readonly features: KunEditorFeatures;
8
9
  /** UI language, for view chrome (dropdown hints, picker tabs, etc.). */
9
10
  readonly locale: KunEditorLocale;
11
+ /** Ordered buttons for the selection bubble toolbar (a plugin view reads it). */
12
+ readonly selectionToolbarItems: KunSelectionItem[];
10
13
  }
11
14
  export declare const KUN_EDITOR_CONTEXT: InjectionKey<KunEditorContext>;
12
15
  //# sourceMappingURL=context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,KAAK,CAAA;AACvC,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EAChB,MAAM,qBAAqB,CAAA;AAE5B,MAAM,WAAW,gBAAgB;IAC/B,6EAA6E;IAC7E,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,CAAA;IACpC,gDAAgD;IAChD,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,CAAA;IACpC,wEAAwE;IACxE,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAA;CACjC;AAED,eAAO,MAAM,kBAAkB,EAAE,YAAY,CAAC,gBAAgB,CAChC,CAAA"}
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,KAAK,CAAA;AACvC,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EAChB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C,MAAM,WAAW,gBAAgB;IAC/B,6EAA6E;IAC7E,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,CAAA;IACpC,gDAAgD;IAChD,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,CAAA;IACpC,wEAAwE;IACxE,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAA;IAChC,iFAAiF;IACjF,QAAQ,CAAC,qBAAqB,EAAE,gBAAgB,EAAE,CAAA;CACnD;AAED,eAAO,MAAM,kBAAkB,EAAE,YAAY,CAAC,gBAAgB,CAChC,CAAA"}
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ export { KunEditor };
4
4
  export type { KunEditorExpose } from './types';
5
5
  export type { KunEditorToolbarApi } from './types';
6
6
  export type { KunToolbarItem } from './types';
7
+ export type { KunSelectionItem } from './types';
7
8
  export type { KunEditorViewSwitchApi } from './types';
8
9
  export { EMOJI } from './emoji';
9
10
  export type { KunEditorAdapters, KunEditorFeatures, KunEditorLocale, UploadImage, SearchMentionUsers, StickerSource, Notify, NotifyLevel, MentionUser, StickerItem, StickerPack } from '@kungal/editor-core';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAO,MAAM,EAAE,MAAM,KAAK,CAAA;AACtC,OAAO,SAAS,MAAM,4BAA4B,CAAA;AAElD,OAAO,EAAE,SAA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/index.js CHANGED
@@ -6,9 +6,9 @@ import { listenerCtx as R } from "@milkdown/kit/plugin/listener";
6
6
  import { SlashProvider as z, slashFactory as B } from "@milkdown/kit/plugin/slash";
7
7
  import { TooltipProvider as V, tooltipFactory as H } from "@milkdown/kit/plugin/tooltip";
8
8
  import { callCommand as U, replaceAll as W } from "@milkdown/kit/utils";
9
- import { createKunEditorPlugins as ee, insertKunSpoilerCommand as te, insertMentionCommand as G, insertQuoteCommand as K, kunCM as ne, mentionId as re, setHeadingCommand as ie, startImageUpload as q } from "@kungal/editor-core/preset";
10
- import { TextSelection as ae } from "@milkdown/kit/prose/state";
11
- import { createCodeBlockCommand as oe, insertHrCommand as se, insertImageCommand as ce, toggleEmphasisCommand as J, toggleInlineCodeCommand as le, toggleStrongCommand as ue, wrapInBlockquoteCommand as de, wrapInBulletListCommand as fe, wrapInOrderedListCommand as pe } from "@milkdown/kit/preset/commonmark";
9
+ import { createKunEditorPlugins as G, insertKunSpoilerCommand as K, insertMentionCommand as q, insertQuoteCommand as J, kunCM as ee, mentionId as te, setHeadingCommand as ne, startImageUpload as re } from "@kungal/editor-core/preset";
10
+ import { TextSelection as ie } from "@milkdown/kit/prose/state";
11
+ import { createCodeBlockCommand as ae, insertHrCommand as oe, insertImageCommand as se, toggleEmphasisCommand as ce, toggleInlineCodeCommand as le, toggleStrongCommand as ue, wrapInBlockquoteCommand as de, wrapInBulletListCommand as fe, wrapInOrderedListCommand as pe } from "@milkdown/kit/preset/commonmark";
12
12
  import { toggleStrikethroughCommand as me } from "@milkdown/kit/preset/gfm";
13
13
  import { EditorState as he } from "@codemirror/state";
14
14
  import { EditorView as Y } from "@codemirror/view";
@@ -74,13 +74,13 @@ var X = Symbol("kun-editor-context"), ve = [
74
74
  }, I = (e) => {
75
75
  let t = d.value;
76
76
  if (!t || !O) return;
77
- let n = t.state.schema.nodes[re];
77
+ let n = t.state.schema.nodes[te];
78
78
  if (!n) return;
79
79
  let r = n.create({
80
80
  userId: e.id,
81
81
  name: e.name
82
82
  }), { from: i, to: a } = O, o = t.state.tr.replaceWith(i, a, r), s = i + r.nodeSize;
83
- o.insertText(" ", s), o.setSelection(ae.create(o.doc, s + 1)), t.dispatch(o.scrollIntoView()), t.focus(), b.hide();
83
+ o.insertText(" ", s), o.setSelection(ie.create(o.doc, s + 1)), t.dispatch(o.scrollIntoView()), t.focus(), b.hide();
84
84
  }, L = (e) => {
85
85
  if (!x.value || !w.value.length) {
86
86
  x.value && e.key === "Escape" && (e.preventDefault(), b.hide());
@@ -156,39 +156,56 @@ var X = Symbol("kun-editor-context"), ve = [
156
156
  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\"/>"),
157
157
  latex: Q("Σ", 15),
158
158
  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\"/>")
159
- }, Ee = [
159
+ }, Ee = {
160
+ key: 0,
161
+ class: "kun-editor__toolbar-divider",
162
+ "aria-hidden": "true"
163
+ }, De = [
160
164
  "title",
161
165
  "aria-label",
162
166
  "onMousedown"
163
- ], De = ["innerHTML"], Oe = /* @__PURE__ */ s({
167
+ ], Oe = ["innerHTML"], ke = /* @__PURE__ */ s({
164
168
  __name: "SelectionTooltip",
165
169
  setup(n) {
166
170
  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) => {
167
171
  s()?.action(U(e, t));
168
172
  }, y = t(() => {
169
173
  let e = u.value;
170
- return [
171
- {
174
+ return {
175
+ bold: {
172
176
  svg: $.bold,
173
177
  title: e ? "Bold" : "加粗",
174
178
  run: () => v(ue.key)
175
179
  },
176
- {
180
+ italic: {
177
181
  svg: $.italic,
178
182
  title: e ? "Italic" : "斜体",
179
- run: () => v(J.key)
183
+ run: () => v(ce.key)
180
184
  },
181
- {
185
+ strike: {
182
186
  svg: $.strike,
183
187
  title: e ? "Strikethrough" : "删除线",
184
188
  run: () => v(me.key)
185
189
  },
186
- {
190
+ code: {
187
191
  svg: $.code,
188
192
  title: e ? "Inline code" : "行内代码",
189
193
  run: () => v(le.key)
190
194
  }
191
- ];
195
+ };
196
+ }), b = t(() => {
197
+ let e = y.value, t = (c?.selectionToolbarItems ?? [
198
+ "bold",
199
+ "italic",
200
+ "strike",
201
+ "code"
202
+ ]).map((t) => t === "|" ? { divider: !0 } : e[t] ? {
203
+ divider: !1,
204
+ ...e[t]
205
+ } : null).filter((e) => e !== null), n = [];
206
+ for (let e of t) e.divider && (n.length === 0 || n[n.length - 1]?.divider) || n.push(e);
207
+ for (; n.length && n[n.length - 1]?.divider;) n.pop();
208
+ return n;
192
209
  });
193
210
  return p(() => {
194
211
  h = new V({
@@ -204,19 +221,19 @@ var X = Symbol("kun-editor-context"), ve = [
204
221
  ref: d,
205
222
  class: "kun-editor__bubble",
206
223
  "data-show": "false"
207
- }, [(m(!0), i(e, null, _(y.value, (e, t) => (m(), i("button", {
208
- key: t,
224
+ }, [(m(!0), i(e, null, _(b.value, (t, n) => (m(), i(e, { key: n }, [t.divider ? (m(), i("span", Ee)) : (m(), i("button", {
225
+ key: 1,
209
226
  type: "button",
210
227
  class: "kun-editor__bubble-btn",
211
- title: e.title,
212
- "aria-label": e.title,
213
- onMousedown: T((t) => e.run(), ["prevent"])
228
+ title: t.title,
229
+ "aria-label": t.title,
230
+ onMousedown: T((e) => t.run(), ["prevent"])
214
231
  }, [a("span", {
215
232
  class: "kun-editor__icon",
216
- innerHTML: e.svg
217
- }, null, 8, De)], 40, Ee))), 128))], 512));
233
+ innerHTML: t.svg
234
+ }, null, 8, Oe)], 40, De))], 64))), 128))], 512));
218
235
  }
219
- }), ke = /* @__PURE__ */ s({
236
+ }), Ae = /* @__PURE__ */ s({
220
237
  __name: "MilkdownEditor",
221
238
  props: {
222
239
  modelValue: {},
@@ -236,8 +253,8 @@ var X = Symbol("kun-editor-context"), ve = [
236
253
  }), t.update(I, (e) => ({
237
254
  ...e,
238
255
  editable: () => !i.readonly
239
- })), l && t.set(c.key, { view: s({ component: Te }) }), d && t.set(u.key, { view: s({ component: Oe }) });
240
- }).use(ee(i.adapters, i.features, {
256
+ })), l && t.set(c.key, { view: s({ component: Te }) }), d && t.set(u.key, { view: s({ component: ke }) });
257
+ }).use(G(i.adapters, i.features, {
241
258
  locale: i.locale,
242
259
  placeholder: i.placeholder
243
260
  }));
@@ -256,29 +273,29 @@ var X = Symbol("kun-editor-context"), ve = [
256
273
  };
257
274
  return t({
258
275
  insertQuote: (e) => {
259
- f.get()?.action(U(K.key, e)), p();
276
+ f.get()?.action(U(J.key, e)), p();
260
277
  },
261
278
  insertMention: (e) => {
262
- f.get()?.action(U(G.key, e)), p();
279
+ f.get()?.action(U(q.key, e)), p();
263
280
  },
264
281
  focus: p
265
282
  }), (e, t) => (m(), n(b(E)));
266
283
  }
267
- }), Ae = /* @__PURE__ */ "😀.😃.😄.😁.😆.😅.🤣.😂.🙂.🙃.😉.😊.😇.🥰.😍.🤩.😘.😗.😚.😋.😛.😜.🤪.😝.🤗.🤭.🤔.🤐.😐.😑.😶.😏.😒.🙄.😬.😌.😔.😪.🤤.😴.😷.🤒.🤕.🥵.🥶.🥴.😵.🤯.🤠.🥳.😎.🤓.🧐.😕.😟.🙁.😮.😯.😲.😳.🥺.😦.😧.😨.😰.😥.😢.😭.😱.😖.😣.😞.😓.😩.😫.🥱.😤.😡.😠.🤬.😈.👿.💀.💩.🤡.👻.👽.🤖.😺.😸.👍.👎.👌.🤌.🤏.✌️.🤞.🤟.🤘.👋.🤚.🖐️.✋.👏.🙌.🤝.🙏.💪.👀.👁️.❤️.🧡.💛.💚.💙.💜.🖤.🤍.💔.💕.💞.💓.💗.💖.💘.💝.💯.✨.⭐.🌟.🔥.💥.💫.⚡.☀️.🌈.🎉.🎊.🎁.🏆.🐶.🐱.🐭.🦊.🐻.🐼.🐨.🦄.🐢.🐳.🍎.🍑.🍓.🍉.🍰.🍺.🍵.☕.🍜.🍙.✅.❌.❓.❗.💤.👑.🎮.🎵.📌.🔖".split("."), je = [
284
+ }), je = /* @__PURE__ */ "😀.😃.😄.😁.😆.😅.🤣.😂.🙂.🙃.😉.😊.😇.🥰.😍.🤩.😘.😗.😚.😋.😛.😜.🤪.😝.🤗.🤭.🤔.🤐.😐.😑.😶.😏.😒.🙄.😬.😌.😔.😪.🤤.😴.😷.🤒.🤕.🥵.🥶.🥴.😵.🤯.🤠.🥳.😎.🤓.🧐.😕.😟.🙁.😮.😯.😲.😳.🥺.😦.😧.😨.😰.😥.😢.😭.😱.😖.😣.😞.😓.😩.😫.🥱.😤.😡.😠.🤬.😈.👿.💀.💩.🤡.👻.👽.🤖.😺.😸.👍.👎.👌.🤌.🤏.✌️.🤞.🤟.🤘.👋.🤚.🖐️.✋.👏.🙌.🤝.🙏.💪.👀.👁️.❤️.🧡.💛.💚.💙.💜.🖤.🤍.💔.💕.💞.💓.💗.💖.💘.💝.💯.✨.⭐.🌟.🔥.💥.💫.⚡.☀️.🌈.🎉.🎊.🎁.🏆.🐶.🐱.🐭.🦊.🐻.🐼.🐨.🦄.🐢.🐳.🍎.🍑.🍓.🍉.🍰.🍺.🍵.☕.🍜.🍙.✅.❌.❓.❗.💤.👑.🎮.🎵.📌.🔖".split("."), Me = [
268
285
  "title",
269
286
  "aria-label",
270
287
  "aria-expanded"
271
- ], Me = ["innerHTML"], Ne = { class: "kun-editor__picker-panel" }, Pe = {
288
+ ], Ne = ["innerHTML"], Pe = { class: "kun-editor__picker-panel" }, Fe = {
272
289
  key: 0,
273
290
  class: "kun-editor__picker-tabs",
274
291
  role: "tablist"
275
- }, Fe = ["data-active"], Ie = ["data-active"], Le = { class: "kun-editor__emoji-grid" }, Re = ["onClick"], ze = {
292
+ }, Ie = ["data-active"], Le = ["data-active"], Re = { class: "kun-editor__emoji-grid" }, ze = ["onClick"], Be = {
276
293
  key: 1,
277
294
  class: "kun-editor__sticker-body"
278
- }, Be = { class: "kun-editor__pack-name" }, Ve = { class: "kun-editor__sticker-grid" }, He = ["title", "onClick"], Ue = ["src", "alt"], We = {
295
+ }, Ve = { class: "kun-editor__pack-name" }, He = { class: "kun-editor__sticker-grid" }, Ue = ["title", "onClick"], We = ["src", "alt"], Ge = {
279
296
  key: 1,
280
297
  class: "kun-editor__picker-hint"
281
- }, Ge = /* @__PURE__ */ s({
298
+ }, Ke = /* @__PURE__ */ s({
282
299
  __name: "StickerPicker",
283
300
  setup(n) {
284
301
  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 ? {
@@ -314,7 +331,7 @@ var X = Symbol("kun-editor-context"), ve = [
314
331
  n.dispatch(r.tr.insertText(e, r.selection.from));
315
332
  });
316
333
  }, N = (e, t) => {
317
- o()?.action(U(ce.key, {
334
+ o()?.action(U(se.key, {
318
335
  src: e,
319
336
  title: t,
320
337
  alt: t
@@ -334,28 +351,28 @@ var X = Symbol("kun-editor-context"), ve = [
334
351
  }, [a("span", {
335
352
  class: "kun-editor__icon",
336
353
  innerHTML: b($).smile
337
- }, null, 8, Me)], 8, je), w(a("div", Ne, [
338
- u ? (m(), i("div", Pe, [a("button", {
354
+ }, null, 8, Ne)], 8, Me), w(a("div", Pe, [
355
+ u ? (m(), i("div", Fe, [a("button", {
339
356
  type: "button",
340
357
  class: "kun-editor__picker-tab",
341
358
  "data-active": C.value === "emoji",
342
359
  onClick: n[0] ||= (e) => C.value = "emoji"
343
- }, y(h.value.emoji), 9, Fe), a("button", {
360
+ }, y(h.value.emoji), 9, Ie), a("button", {
344
361
  type: "button",
345
362
  class: "kun-editor__picker-tab",
346
363
  "data-active": C.value === "sticker",
347
364
  onClick: n[1] ||= (e) => C.value = "sticker"
348
- }, y(h.value.sticker), 9, Ie)])) : r("", !0),
349
- w(a("div", Le, [(m(!0), i(e, null, _(b(Ae), (e, t) => (m(), i("button", {
365
+ }, y(h.value.sticker), 9, Le)])) : r("", !0),
366
+ w(a("div", Re, [(m(!0), i(e, null, _(b(je), (e, t) => (m(), i("button", {
350
367
  key: t,
351
368
  type: "button",
352
369
  class: "kun-editor__emoji",
353
370
  onClick: (t) => M(e)
354
- }, y(e), 9, Re))), 128))], 512), [[x, !u || C.value === "emoji"]]),
355
- u ? w((m(), i("div", ze, [T.value.length ? (m(!0), i(e, { key: 0 }, _(T.value, (t) => (m(), i("div", {
371
+ }, y(e), 9, ze))), 128))], 512), [[x, !u || C.value === "emoji"]]),
372
+ u ? w((m(), i("div", Be, [T.value.length ? (m(!0), i(e, { key: 0 }, _(T.value, (t) => (m(), i("div", {
356
373
  key: t.name,
357
374
  class: "kun-editor__pack"
358
- }, [a("div", Be, y(t.name), 1), a("div", Ve, [(m(!0), i(e, null, _(t.stickers, (e, t) => (m(), i("button", {
375
+ }, [a("div", Ve, y(t.name), 1), a("div", He, [(m(!0), i(e, null, _(t.stickers, (e, t) => (m(), i("button", {
359
376
  key: t,
360
377
  type: "button",
361
378
  class: "kun-editor__sticker",
@@ -365,21 +382,21 @@ var X = Symbol("kun-editor-context"), ve = [
365
382
  src: e.src,
366
383
  alt: e.name,
367
384
  loading: "lazy"
368
- }, null, 8, Ue)], 8, He))), 128))])]))), 128)) : (m(), i("div", We, y(D.value ? h.value.failed : h.value.empty), 1))], 512)), [[x, C.value === "sticker"]]) : r("", !0)
385
+ }, null, 8, We)], 8, Ue))), 128))])]))), 128)) : (m(), i("div", Ge, y(D.value ? h.value.failed : h.value.empty), 1))], 512)), [[x, C.value === "sticker"]]) : r("", !0)
369
386
  ], 512), [[x, v.value]])], 512));
370
387
  }
371
- }), Ke = {
388
+ }), qe = {
372
389
  class: "kun-editor__format-toolbar",
373
390
  role: "toolbar"
374
- }, qe = ["aria-label"], Je = {
391
+ }, Je = ["aria-label"], Ye = {
375
392
  value: "",
376
393
  disabled: "",
377
394
  selected: ""
378
- }, Ye = ["value"], Xe = [
395
+ }, Xe = ["value"], Ze = [
379
396
  "title",
380
397
  "aria-label",
381
398
  "onClick"
382
- ], Ze = ["innerHTML"], Qe = ["title", "aria-label"], $e = ["innerHTML"], et = /* @__PURE__ */ s({
399
+ ], Qe = ["innerHTML"], $e = ["title", "aria-label"], et = ["innerHTML"], tt = /* @__PURE__ */ s({
383
400
  __name: "EditorToolbar",
384
401
  setup(n) {
385
402
  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) => {
@@ -416,7 +433,7 @@ var X = Symbol("kun-editor-context"), ve = [
416
433
  }));
417
434
  }), x = (e) => {
418
435
  let t = e.target;
419
- p(ie.key, Number(t.value)), t.selectedIndex = 0;
436
+ p(ne.key, Number(t.value)), t.selectedIndex = 0;
420
437
  }, S = t(() => [
421
438
  [
422
439
  {
@@ -427,7 +444,7 @@ var X = Symbol("kun-editor-context"), ve = [
427
444
  {
428
445
  svg: $.italic,
429
446
  title: h.value.italic,
430
- run: () => p(J.key)
447
+ run: () => p(ce.key)
431
448
  },
432
449
  {
433
450
  svg: $.strike,
@@ -459,40 +476,40 @@ var X = Symbol("kun-editor-context"), ve = [
459
476
  {
460
477
  svg: $.codeBlock,
461
478
  title: h.value.codeBlock,
462
- run: () => p(oe.key, "")
479
+ run: () => p(ae.key, "")
463
480
  },
464
481
  {
465
482
  svg: $.hr,
466
483
  title: h.value.hr,
467
- run: () => p(se.key)
484
+ run: () => p(oe.key)
468
485
  }
469
486
  ],
470
487
  [{
471
488
  svg: $.spoiler,
472
489
  title: h.value.spoiler,
473
- run: () => p(te.key)
490
+ run: () => p(K.key)
474
491
  }]
475
492
  ]), C = g(null), w = () => C.value?.click(), T = (e) => {
476
493
  let t = e.target, n = t.files?.[0];
477
494
  t.value = "";
478
495
  let r = u.value;
479
496
  !n || !r || s()?.action((e) => {
480
- q(e.get(F), n, {
497
+ re(e.get(F), n, {
481
498
  uploadImage: r,
482
499
  notify: c?.adapters.notify,
483
500
  locale: c?.locale
484
501
  });
485
502
  });
486
503
  };
487
- return (t, n) => (m(), i("div", Ke, [
504
+ return (t, n) => (m(), i("div", qe, [
488
505
  a("select", {
489
506
  class: "kun-editor__heading-select",
490
507
  "aria-label": h.value.textSize,
491
508
  onChange: x
492
- }, [a("option", Je, y(h.value.textSize), 1), (m(!0), i(e, null, _(v.value, (e) => (m(), i("option", {
509
+ }, [a("option", Ye, y(h.value.textSize), 1), (m(!0), i(e, null, _(v.value, (e) => (m(), i("option", {
493
510
  key: e.level,
494
511
  value: e.level
495
- }, y(e.label), 9, Ye))), 128))], 40, qe),
512
+ }, y(e.label), 9, Xe))), 128))], 40, Je),
496
513
  (m(!0), i(e, null, _(S.value, (t, r) => (m(), i(e, { key: r }, [n[0] ||= a("span", {
497
514
  class: "kun-editor__toolbar-divider",
498
515
  "aria-hidden": "true"
@@ -506,7 +523,7 @@ var X = Symbol("kun-editor-context"), ve = [
506
523
  }, [a("span", {
507
524
  class: "kun-editor__icon",
508
525
  innerHTML: e.svg
509
- }, null, 8, Ze)], 8, Xe))), 128))], 64))), 128)),
526
+ }, null, 8, Qe)], 8, Ze))), 128))], 64))), 128)),
510
527
  u.value ? (m(), i(e, { key: 0 }, [
511
528
  n[1] ||= a("span", {
512
529
  class: "kun-editor__toolbar-divider",
@@ -521,7 +538,7 @@ var X = Symbol("kun-editor-context"), ve = [
521
538
  }, [a("span", {
522
539
  class: "kun-editor__icon",
523
540
  innerHTML: b($).image
524
- }, null, 8, $e)], 8, Qe),
541
+ }, null, 8, et)], 8, $e),
525
542
  a("input", {
526
543
  ref_key: "fileInput",
527
544
  ref: C,
@@ -534,10 +551,10 @@ var X = Symbol("kun-editor-context"), ve = [
534
551
  d.value ? (m(), i(e, { key: 1 }, [n[2] ||= a("span", {
535
552
  class: "kun-editor__toolbar-divider",
536
553
  "aria-hidden": "true"
537
- }, null, -1), o(Ge)], 64)) : r("", !0)
554
+ }, null, -1), o(Ke)], 64)) : r("", !0)
538
555
  ]));
539
556
  }
540
- }), tt = /* @__PURE__ */ s({
557
+ }), nt = /* @__PURE__ */ s({
541
558
  __name: "ToolbarHost",
542
559
  setup(e) {
543
560
  let [, t] = k(), n = l(X, void 0), r = (e, n) => {
@@ -555,7 +572,7 @@ var X = Symbol("kun-editor-context"), ve = [
555
572
  uploadImage: (e) => {
556
573
  let r = n?.adapters.uploadImage, i = t();
557
574
  !r || !i || i.action((t) => {
558
- q(t.get(F), e, {
575
+ re(t.get(F), e, {
559
576
  uploadImage: r,
560
577
  notify: n?.adapters.notify,
561
578
  locale: n?.locale
@@ -563,10 +580,10 @@ var X = Symbol("kun-editor-context"), ve = [
563
580
  });
564
581
  },
565
582
  insertQuote: (e) => {
566
- r(K.key, e), i();
583
+ r(J.key, e), i();
567
584
  },
568
585
  insertMention: (e) => {
569
- r(G.key, e), i();
586
+ r(q.key, e), i();
570
587
  },
571
588
  focus: i,
572
589
  get adapters() {
@@ -581,7 +598,7 @@ var X = Symbol("kun-editor-context"), ve = [
581
598
  };
582
599
  return (e, t) => v(e.$slots, "default", d(c(a)));
583
600
  }
584
- }), nt = /* @__PURE__ */ s({
601
+ }), rt = /* @__PURE__ */ s({
585
602
  __name: "MarkdownSource",
586
603
  props: {
587
604
  modelValue: {},
@@ -592,7 +609,7 @@ var X = Symbol("kun-editor-context"), ve = [
592
609
  let n = e, r = t, a = g(null), o = null, s = (e) => he.create({
593
610
  doc: e,
594
611
  extensions: [
595
- ne(),
612
+ ee(),
596
613
  Y.lineWrapping,
597
614
  _e,
598
615
  ge(),
@@ -617,14 +634,19 @@ var X = Symbol("kun-editor-context"), ve = [
617
634
  class: "kun-editor__source"
618
635
  }, null, 512));
619
636
  }
620
- }), rt = ["data-mode"], it = {
637
+ }), it = ["data-mode"], at = {
638
+ key: 0,
621
639
  class: "kun-editor__toolbar",
622
640
  role: "tablist"
623
- }, at = ["aria-selected", "data-active"], ot = ["aria-selected", "data-active"], st = ["aria-selected", "data-active"], ct = ["title", "aria-label"], lt = [
641
+ }, ot = [
642
+ "aria-selected",
643
+ "data-active",
644
+ "onClick"
645
+ ], st = ["title", "aria-label"], ct = [
624
646
  "data-active",
625
647
  "title",
626
648
  "aria-pressed"
627
- ], ut = ["data-swap"], dt = { class: "kun-editor__wysiwyg kun-editor__pane" }, ft = /* @__PURE__ */ s({
649
+ ], lt = ["data-swap"], ut = { class: "kun-editor__wysiwyg kun-editor__pane" }, dt = /* @__PURE__ */ s({
628
650
  __name: "KunEditor",
629
651
  props: {
630
652
  modelValue: {},
@@ -636,40 +658,57 @@ var X = Symbol("kun-editor-context"), ve = [
636
658
  default: !1
637
659
  },
638
660
  placeholder: { default: "" },
661
+ views: { default: () => [
662
+ "wysiwyg",
663
+ "source",
664
+ "split"
665
+ ] },
639
666
  scrollSync: {
640
667
  type: Boolean,
641
668
  default: !0
642
669
  },
643
670
  selectionToolbar: {
644
- type: Boolean,
671
+ type: [Boolean, Array],
645
672
  default: !0
646
673
  }
647
674
  },
648
675
  emits: ["update:modelValue"],
649
676
  setup(s, { expose: l, emit: p }) {
650
- let _ = s, T = p;
677
+ let T = [
678
+ "bold",
679
+ "italic",
680
+ "strike",
681
+ "code"
682
+ ], E = s, O = p;
651
683
  h(X, {
652
684
  get adapters() {
653
- return _.adapters;
685
+ return E.adapters;
654
686
  },
655
687
  get features() {
656
- return _.features;
688
+ return E.features;
657
689
  },
658
690
  get locale() {
659
- return _.locale;
691
+ return E.locale;
692
+ },
693
+ get selectionToolbarItems() {
694
+ return Array.isArray(E.selectionToolbar) ? E.selectionToolbar : T;
660
695
  }
661
696
  });
662
- let E = g("wysiwyg"), O = (e) => {
663
- E.value = e;
664
- }, k = g(!1), j = () => {
665
- k.value = !k.value;
666
- }, M = g(_.scrollSync);
667
- S(() => _.scrollSync, (e) => {
668
- M.value = e;
697
+ let k = t(() => E.selectionToolbar !== !1), j = g(E.views.includes("wysiwyg") ? "wysiwyg" : E.views[0] ?? "wysiwyg"), M = (e) => {
698
+ j.value = e;
699
+ };
700
+ S(() => E.views, (e) => {
701
+ e.includes(j.value) || (j.value = e[0] ?? "wysiwyg");
702
+ });
703
+ let N = g(!1), P = () => {
704
+ N.value = !N.value;
705
+ }, F = g(E.scrollSync);
706
+ S(() => E.scrollSync, (e) => {
707
+ F.value = e;
669
708
  });
670
- let N = () => {
671
- M.value = !M.value;
672
- }, P = t(() => _.locale.toLowerCase().startsWith("en")), F = t(() => P.value ? {
709
+ let I = () => {
710
+ F.value = !F.value;
711
+ }, L = t(() => E.locale.toLowerCase().startsWith("en")), R = t(() => L.value ? {
673
712
  wysiwyg: "Preview",
674
713
  source: "Markdown",
675
714
  split: "Split",
@@ -681,109 +720,94 @@ var X = Symbol("kun-editor-context"), ve = [
681
720
  split: "分栏",
682
721
  swap: "左右互换",
683
722
  scrollSync: "同步滚动"
684
- }), I = g(null), L = null, R = null, z = null, B = () => {
685
- L?.(), L = null, R = null;
686
- }, V = () => {
687
- B();
688
- let e = I.value;
723
+ }), z = g(null), B = null, V = null, H = null, U = () => {
724
+ B?.(), B = null, V = null;
725
+ }, W = () => {
726
+ U();
727
+ let e = z.value;
689
728
  if (!e) return;
690
729
  let t = e.querySelector(".cm-scroller"), n = e.querySelector(".kun-editor__wysiwyg");
691
730
  if (!t || !n) return;
692
731
  let r = (e, t) => () => {
693
- if (R && R !== e) return;
694
- R = e;
732
+ if (V && V !== e) return;
733
+ V = e;
695
734
  let n = e.scrollHeight - e.clientHeight, r = n > 0 ? e.scrollTop / n : 0, i = t.scrollHeight - t.clientHeight;
696
- t.scrollTop = r * (i > 0 ? i : 0), z && clearTimeout(z), z = setTimeout(() => {
697
- R = null;
735
+ t.scrollTop = r * (i > 0 ? i : 0), H && clearTimeout(H), H = setTimeout(() => {
736
+ V = null;
698
737
  }, 120);
699
738
  }, i = r(t, n), a = r(n, t);
700
- t.addEventListener("scroll", i, { passive: !0 }), n.addEventListener("scroll", a, { passive: !0 }), L = () => {
739
+ t.addEventListener("scroll", i, { passive: !0 }), n.addEventListener("scroll", a, { passive: !0 }), B = () => {
701
740
  t.removeEventListener("scroll", i), n.removeEventListener("scroll", a);
702
741
  };
703
742
  };
704
- S([E, M], ([e, t]) => {
705
- B(), e === "split" && t && u(V);
706
- }), f(B);
707
- let H = t(() => _.readonly || E.value === "split"), U = (e) => T("update:modelValue", e), W = g(null);
743
+ S([j, F], ([e, t]) => {
744
+ U(), e === "split" && t && u(W);
745
+ }), f(U);
746
+ let G = t(() => E.readonly || j.value === "split"), K = (e) => O("update:modelValue", e), q = g(null);
708
747
  return l({
709
- insertQuote: (e) => W.value?.insertQuote(e),
710
- insertMention: (e) => W.value?.insertMention(e),
711
- focus: () => W.value?.focus()
748
+ insertQuote: (e) => q.value?.insertQuote(e),
749
+ insertMention: (e) => q.value?.insertMention(e),
750
+ focus: () => q.value?.focus()
712
751
  }), (t, l) => (m(), i("div", {
713
752
  ref_key: "rootEl",
714
- ref: I,
753
+ ref: z,
715
754
  class: "kun-editor",
716
755
  "data-kun-editor": "",
717
- "data-mode": E.value
756
+ "data-mode": j.value
718
757
  }, [v(t.$slots, "view-switch", {
719
- mode: E.value,
720
- setMode: O,
721
- labels: F.value,
722
- swapped: k.value,
723
- swap: j,
724
- scrollSync: M.value,
725
- toggleScrollSync: N
726
- }, () => [a("div", it, [
727
- a("button", {
728
- type: "button",
729
- class: "kun-editor__tab",
730
- "aria-selected": E.value === "wysiwyg",
731
- "data-active": E.value === "wysiwyg",
732
- onClick: l[0] ||= (e) => O("wysiwyg")
733
- }, y(F.value.wysiwyg), 9, at),
734
- a("button", {
735
- type: "button",
736
- class: "kun-editor__tab",
737
- "aria-selected": E.value === "source",
738
- "data-active": E.value === "source",
739
- onClick: l[1] ||= (e) => O("source")
740
- }, y(F.value.source), 9, ot),
741
- a("button", {
742
- type: "button",
743
- class: "kun-editor__tab",
744
- "aria-selected": E.value === "split",
745
- "data-active": E.value === "split",
746
- onClick: l[2] ||= (e) => O("split")
747
- }, y(F.value.split), 9, st),
748
- E.value === "split" ? (m(), i(e, { key: 0 }, [a("button", {
749
- type: "button",
750
- class: "kun-editor__tab kun-editor__swap",
751
- title: F.value.swap,
752
- "aria-label": F.value.swap,
753
- onClick: l[3] ||= (e) => j()
754
- }, " ⇄ ", 8, ct), a("button", {
755
- type: "button",
756
- class: "kun-editor__tab",
757
- "data-active": M.value,
758
- title: F.value.scrollSync,
759
- "aria-pressed": M.value,
760
- onClick: l[4] ||= (e) => N()
761
- }, y(F.value.scrollSync), 9, lt)], 64)) : r("", !0)
762
- ])]), o(b(D), null, {
758
+ mode: j.value,
759
+ setMode: M,
760
+ labels: R.value,
761
+ views: s.views,
762
+ swapped: N.value,
763
+ swap: P,
764
+ scrollSync: F.value,
765
+ toggleScrollSync: I
766
+ }, () => [s.views.length > 1 ? (m(), i("div", at, [(m(!0), i(e, null, _(s.views, (e) => (m(), i("button", {
767
+ key: e,
768
+ type: "button",
769
+ class: "kun-editor__tab",
770
+ "aria-selected": j.value === e,
771
+ "data-active": j.value === e,
772
+ onClick: (t) => M(e)
773
+ }, y(R.value[e]), 9, ot))), 128)), j.value === "split" ? (m(), i(e, { key: 0 }, [a("button", {
774
+ type: "button",
775
+ class: "kun-editor__tab kun-editor__swap",
776
+ title: R.value.swap,
777
+ "aria-label": R.value.swap,
778
+ onClick: l[0] ||= (e) => P()
779
+ }, " ⇄ ", 8, st), a("button", {
780
+ type: "button",
781
+ class: "kun-editor__tab",
782
+ "data-active": F.value,
783
+ title: R.value.scrollSync,
784
+ "aria-pressed": F.value,
785
+ onClick: l[1] ||= (e) => I()
786
+ }, y(R.value.scrollSync), 9, ct)], 64)) : r("", !0)])) : r("", !0)]), o(b(D), null, {
763
787
  default: C(() => [o(b(A), null, {
764
- default: C(() => [w(a("div", null, [o(tt, null, {
765
- default: C((e) => [v(t.$slots, "toolbar", d(c(e)), () => [o(et)])]),
788
+ default: C(() => [w(a("div", null, [o(nt, null, {
789
+ default: C((e) => [v(t.$slots, "toolbar", d(c(e)), () => [o(tt)])]),
766
790
  _: 3
767
- })], 512), [[x, E.value === "wysiwyg" && !s.readonly]]), a("div", {
791
+ })], 512), [[x, j.value === "wysiwyg" && !s.readonly]]), a("div", {
768
792
  class: "kun-editor__panes",
769
- "data-swap": k.value
770
- }, [E.value === "source" || E.value === "split" ? (m(), n(nt, {
793
+ "data-swap": N.value
794
+ }, [j.value === "source" || j.value === "split" ? (m(), n(rt, {
771
795
  key: 0,
772
796
  class: "kun-editor__pane",
773
797
  "model-value": s.modelValue,
774
798
  readonly: s.readonly,
775
- "onUpdate:modelValue": U
776
- }, null, 8, ["model-value", "readonly"])) : r("", !0), w(a("div", dt, [o(ke, {
799
+ "onUpdate:modelValue": K
800
+ }, null, 8, ["model-value", "readonly"])) : r("", !0), w(a("div", ut, [o(Ae, {
777
801
  ref_key: "inner",
778
- ref: W,
802
+ ref: q,
779
803
  "model-value": s.modelValue,
780
804
  adapters: s.adapters,
781
805
  features: s.features,
782
806
  locale: s.locale,
783
- readonly: H.value,
807
+ readonly: G.value,
784
808
  placeholder: s.placeholder,
785
- "selection-toolbar": s.selectionToolbar,
786
- "onUpdate:modelValue": U
809
+ "selection-toolbar": k.value,
810
+ "onUpdate:modelValue": K
787
811
  }, null, 8, [
788
812
  "model-value",
789
813
  "adapters",
@@ -792,14 +816,14 @@ var X = Symbol("kun-editor-context"), ve = [
792
816
  "readonly",
793
817
  "placeholder",
794
818
  "selection-toolbar"
795
- ])], 512), [[x, E.value === "wysiwyg" || E.value === "split"]])], 8, ut)]),
819
+ ])], 512), [[x, j.value === "wysiwyg" || j.value === "split"]])], 8, lt)]),
796
820
  _: 3
797
821
  })]),
798
822
  _: 3
799
- })], 8, rt));
823
+ })], 8, it));
800
824
  }
801
- }), pt = { install(e) {
802
- e.component("KunEditor", ft);
825
+ }), ft = { install(e) {
826
+ e.component("KunEditor", dt);
803
827
  } };
804
828
  //#endregion
805
- export { Ae as EMOJI, ft as KunEditor, pt as KunEditorPlugin };
829
+ export { je as EMOJI, dt as KunEditor, ft as KunEditorPlugin };
package/dist/types.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { CmdKey } from '@milkdown/kit/core';
2
2
  import type { KunEditorAdapters, KunEditorFeatures, KunEditorLocale } from '@kungal/editor-core';
3
3
  export type KunToolbarItem = 'heading' | 'bold' | 'italic' | 'strike' | 'code' | 'bulletList' | 'orderedList' | 'quote' | 'codeBlock' | 'hr' | 'spoiler' | 'image' | 'picker' | '|';
4
+ export type KunSelectionItem = 'bold' | 'italic' | 'strike' | 'code' | '|';
4
5
  export interface KunEditorToolbarApi {
5
6
  /** Run a Milkdown command (import its key from the preset/commonmark/gfm). */
6
7
  run: <T>(key: CmdKey<T>, payload?: T) => void;
@@ -36,6 +37,8 @@ export interface KunEditorViewSwitchApi {
36
37
  mode: 'wysiwyg' | 'source' | 'split';
37
38
  /** Switch the active view. */
38
39
  setMode: (mode: 'wysiwyg' | 'source' | 'split') => void;
40
+ /** The view modes offered (from the `views` prop) — render tabs for these. */
41
+ views: ('wysiwyg' | 'source' | 'split')[];
39
42
  /** Localized labels (respects the `locale` prop). */
40
43
  labels: {
41
44
  wysiwyg: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EAChB,MAAM,qBAAqB,CAAA;AAK5B,MAAM,MAAM,cAAc,GACtB,SAAS,GACT,MAAM,GACN,QAAQ,GACR,QAAQ,GACR,MAAM,GACN,YAAY,GACZ,aAAa,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AAM,IAAI,CAAA;IAChB,4CAA4C;IAC5C,UAAU,EAAE,OAAO,CAAA;IACnB,qCAAqC;IACrC,gBAAgB,EAAE,MAAM,IAAI,CAAA;CAC7B;AASD,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,WAAW,CAAC,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAA;IAC5D;;;OAGG;IACH,aAAa,CAAC,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAA;IAC9D,gCAAgC;IAChC,KAAK,IAAI,IAAI,CAAA;CACd"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kungal/editor-vue",
3
- "version": "0.22.0",
3
+ "version": "0.24.0",
4
4
  "description": "KunEditor Vue 3 layer — the headless <KunEditor> component (dual WYSIWYG / markdown-source), toolbar and plugin views. Ships zero CSS and no UI-kit dependency; consumes @kungal/editor-core, and pairs with @kungal/editor-nuxt for optional KunUI chrome.",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -40,7 +40,7 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "@prosemirror-adapter/vue": "^0.4.6",
43
- "@kungal/editor-core": "0.22.0"
43
+ "@kungal/editor-core": "0.24.0"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "@codemirror/lang-markdown": "^6.0.0",
@@ -80,7 +80,7 @@
80
80
  "vite": "^8.0.16",
81
81
  "vue": "^3.5.35",
82
82
  "vue-tsc": "^3.3.3",
83
- "@kungal/editor-core": "0.22.0"
83
+ "@kungal/editor-core": "0.24.0"
84
84
  },
85
85
  "scripts": {
86
86
  "build": "vite build && vue-tsc -p tsconfig.build.json",