md-editor-v3 4.12.0-beta.2 → 4.12.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.
Files changed (43) hide show
  1. package/README.md +12 -0
  2. package/lib/cjs/DropdownToolbar.cjs +3 -1
  3. package/lib/cjs/MdCatalog.cjs +270 -1
  4. package/lib/cjs/MdEditor.cjs +3101 -58
  5. package/lib/cjs/MdModal.cjs +3 -1
  6. package/lib/cjs/MdPreview.cjs +3 -1
  7. package/lib/cjs/ModalToolbar.cjs +124 -1
  8. package/lib/cjs/NormalToolbar.cjs +61 -1
  9. package/lib/cjs/chunks/config.cjs +290 -1
  10. package/lib/cjs/chunks/dom.cjs +64 -1
  11. package/lib/cjs/chunks/index.cjs +1863 -8
  12. package/lib/cjs/chunks/index2.cjs +198 -1
  13. package/lib/cjs/chunks/index3.cjs +270 -1
  14. package/lib/cjs/chunks/index4.cjs +141 -2
  15. package/lib/cjs/chunks/vue-tsx.cjs +10 -1
  16. package/lib/cjs/config.cjs +12 -1
  17. package/lib/cjs/index.cjs +25 -1
  18. package/lib/es/DropdownToolbar.mjs +2 -2
  19. package/lib/es/MdCatalog.mjs +164 -114
  20. package/lib/es/MdEditor.mjs +2297 -1654
  21. package/lib/es/MdModal.mjs +2 -2
  22. package/lib/es/MdPreview.mjs +2 -2
  23. package/lib/es/ModalToolbar.mjs +55 -38
  24. package/lib/es/NormalToolbar.mjs +26 -18
  25. package/lib/es/chunks/config.mjs +73 -54
  26. package/lib/es/chunks/dom.mjs +57 -24
  27. package/lib/es/chunks/index.mjs +1099 -609
  28. package/lib/es/chunks/index2.mjs +126 -78
  29. package/lib/es/chunks/index3.mjs +185 -111
  30. package/lib/es/chunks/index4.mjs +124 -72
  31. package/lib/es/chunks/vue-tsx.mjs +8 -8
  32. package/lib/es/config.mjs +11 -10
  33. package/lib/es/index.mjs +23 -23
  34. package/lib/preview.css +200 -1
  35. package/lib/style.css +592 -1
  36. package/lib/types/MdEditor/components/Modal/Modal.d.ts +1 -1
  37. package/lib/types/MdEditor/components/Modal/index.d.ts +3 -3
  38. package/lib/types/MdEditor/layouts/Content/index.d.ts +9 -0
  39. package/lib/types/MdEditor/layouts/Content/props.d.ts +4 -0
  40. package/lib/types/MdEditor/static/event-name.d.ts +1 -0
  41. package/lib/types/MdEditor/type.d.ts +10 -1
  42. package/lib/umd/index.js +75625 -114
  43. package/package.json +1 -1
@@ -1,34 +1,38 @@
1
- var Ot = Object.defineProperty;
2
- var Pt = (e, o, l) => o in e ? Ot(e, o, { enumerable: !0, configurable: !0, writable: !0, value: l }) : e[o] = l;
3
- var z = (e, o, l) => (Pt(e, typeof o != "symbol" ? o + "" : o, l), l);
4
- import { defineComponent as P, createVNode as t, inject as I, ref as O, onMounted as Y, reactive as _, computed as Ce, watch as H, nextTick as de, Fragment as Mt, cloneVNode as gt, toRef as Q, shallowRef as Wt, onBeforeUnmount as Et } from "vue";
5
- import { p as a, e as X, l as zt, b as Ut, M as se, d as _t } from "./chunks/config.mjs";
6
- import { draggingScroll as qt, linkTo as Gt, debounce as Kt, createSmoothScroll as jt, throttle as Zt } from "@vavt/util";
7
- import { a as ae, D as Xt } from "./chunks/index2.mjs";
8
- import { b as v, i as Yt, E as ee, U as $e, k as Jt, l as ke, h as L, c as Qt, O as Ht, m as Dt, n as Nt } from "./chunks/index4.mjs";
9
- import { a as el } from "./chunks/dom.mjs";
10
- import { M as Bt, I as x } from "./chunks/index3.mjs";
11
- import { EditorView as ce } from "codemirror";
12
- import { EditorView as pe, placeholder as tl, keymap as ll } from "@codemirror/view";
13
- import { languages as ol } from "@codemirror/language-data";
14
- import { markdown as al } from "@codemirror/lang-markdown";
15
- import { EditorSelection as U, EditorState as fe, Compartment as ne, StateEffect as nl } from "@codemirror/state";
16
- import { deleteLine as il, defaultKeymap as rl, historyKeymap as sl, indentWithTab as cl, history as ft, undo as ul, redo as dl } from "@codemirror/commands";
17
- import { HighlightStyle as Vt, syntaxHighlighting as Ft, indentUnit as ml } from "@codemirror/language";
18
- import { tags as c } from "@lezer/highlight";
19
- import { autocompletion as gl } from "@codemirror/autocomplete";
20
- import { c as fl, C as hl, e as bl, a as vl, u as kl, b as Cl, d as $l, f as pl, g as yl, h as Tl, i as wl, M as xl } from "./chunks/index.mjs";
21
- import Rt from "./MdCatalog.mjs";
22
- import { g as ht } from "./chunks/vue-tsx.mjs";
23
- import Sl from "./NormalToolbar.mjs";
24
- import Al from "./ModalToolbar.mjs";
25
- const Ll = /* @__PURE__ */ P({
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ import { defineComponent, createVNode, inject, ref, onMounted, reactive, computed, watch, nextTick, Fragment, cloneVNode, toRef, shallowRef, onBeforeUnmount } from "vue";
8
+ import { p as prefix, e as configOption, l as screenfullUrl, b as allToolbar, M as MinInputBoxWidth, d as allFooter } from "./chunks/config.mjs";
9
+ import { draggingScroll, linkTo, debounce, createSmoothScroll, throttle } from "@vavt/util";
10
+ import { a as Dropdown, D as DropdownToolbar } from "./chunks/index2.mjs";
11
+ import { b as bus, i as CHANGE_FULL_SCREEN, E as ERROR_CATCHER, U as UPLOAD_IMAGE, l as base642File, m as OPEN_MODALS, h as REPLACE, c as CHANGE_CATALOG_VISIBLE, O as ON_SAVE, n as CTRL_SHIFT_Z, o as CTRL_Z, j as EVENT_LISTENER } from "./chunks/index4.mjs";
12
+ import { a as appendHandler } from "./chunks/dom.mjs";
13
+ import { M as MdModal, I as Icon } from "./chunks/index3.mjs";
14
+ import { EditorView as EditorView$1 } from "codemirror";
15
+ import { EditorView, placeholder, keymap } from "@codemirror/view";
16
+ import { languages } from "@codemirror/language-data";
17
+ import { markdown } from "@codemirror/lang-markdown";
18
+ import { EditorSelection, EditorState, Compartment, StateEffect } from "@codemirror/state";
19
+ import { deleteLine, defaultKeymap, historyKeymap, indentWithTab, history, undo, redo } from "@codemirror/commands";
20
+ import { HighlightStyle, syntaxHighlighting, indentUnit } from "@codemirror/language";
21
+ import { tags } from "@lezer/highlight";
22
+ import { autocompletion } from "@codemirror/autocomplete";
23
+ import { c as contentProps, C as ContentPreview, e as editorProps, a as editorEmits, u as useOnSave, b as useProvide, d as useExpansion, f as useErrorCatcher, g as useConfig, h as useCatalog, i as useExpose, M as MdPreview } from "./chunks/index.mjs";
24
+ import MdCatalog from "./MdCatalog.mjs";
25
+ import { g as getSlot } from "./chunks/vue-tsx.mjs";
26
+ import NormalToolbar from "./NormalToolbar.mjs";
27
+ import ModalToolbar from "./ModalToolbar.mjs";
28
+ const Divider = /* @__PURE__ */ defineComponent({
26
29
  setup() {
27
- return () => t("div", {
28
- class: `${a}-divider`
30
+ return () => createVNode("div", {
31
+ "class": `${prefix}-divider`
29
32
  }, null);
30
33
  }
31
- }), Il = {
34
+ });
35
+ const toolbarProps = {
32
36
  noPrettier: {
33
37
  type: Boolean
34
38
  },
@@ -77,38 +81,66 @@ const Ll = /* @__PURE__ */ P({
77
81
  showToolbarName: {
78
82
  type: Boolean
79
83
  }
80
- }, Ml = (e) => {
81
- var d, s, g, w;
82
- const o = I("editorId");
83
- let l = (s = (d = X.editorExtensions) == null ? void 0 : d.screenfull) == null ? void 0 : s.instance;
84
- const n = (w = (g = X.editorExtensions) == null ? void 0 : g.screenfull) == null ? void 0 : w.js, r = O(!1), i = ($) => {
85
- if (!l) {
86
- v.emit(o, ee, {
84
+ };
85
+ const useSreenfull = (props2) => {
86
+ var _a, _b, _c, _d;
87
+ const editorId = inject("editorId");
88
+ let screenfull = (_b = (_a = configOption.editorExtensions) == null ? void 0 : _a.screenfull) == null ? void 0 : _b.instance;
89
+ const screenfullJs = (_d = (_c = configOption.editorExtensions) == null ? void 0 : _c.screenfull) == null ? void 0 : _d.js;
90
+ const screenfullMe = ref(false);
91
+ const fullscreenHandler = (status) => {
92
+ if (!screenfull) {
93
+ bus.emit(editorId, ERROR_CATCHER, {
87
94
  name: "fullscreen",
88
95
  message: "fullscreen is undefined"
89
96
  });
90
97
  return;
91
98
  }
92
- l.isEnabled ? (r.value = !0, ($ === void 0 ? !l.isFullscreen : $) ? l.request() : l.exit()) : console.error("browser does not support screenfull!");
93
- }, h = () => {
94
- l && l.isEnabled && l.on("change", () => {
95
- (r.value || e.setting.fullscreen) && (r.value = !1, e.updateSetting("fullscreen"));
96
- });
97
- }, f = () => {
98
- l = window.screenfull, h();
99
+ if (screenfull.isEnabled) {
100
+ screenfullMe.value = true;
101
+ const targetStatus = status === void 0 ? !screenfull.isFullscreen : status;
102
+ if (targetStatus) {
103
+ screenfull.request();
104
+ } else {
105
+ screenfull.exit();
106
+ }
107
+ } else {
108
+ console.error("browser does not support screenfull!");
109
+ }
110
+ };
111
+ const onScreenfullEvent = () => {
112
+ if (screenfull && screenfull.isEnabled) {
113
+ screenfull.on("change", () => {
114
+ if (screenfullMe.value || props2.setting.fullscreen) {
115
+ screenfullMe.value = false;
116
+ props2.updateSetting("fullscreen");
117
+ }
118
+ });
119
+ }
120
+ };
121
+ const screenfullLoad = () => {
122
+ screenfull = window.screenfull;
123
+ onScreenfullEvent();
99
124
  };
100
- return Y(() => {
101
- if (h(), !l) {
102
- const $ = document.createElement("script");
103
- $.src = n || zt, $.onload = f, $.id = `${a}-screenfull`, el($, "screenfull");
104
- }
105
- }), Y(() => {
106
- v.on(o, {
107
- name: Yt,
108
- callback: i
125
+ onMounted(() => {
126
+ onScreenfullEvent();
127
+ if (!screenfull) {
128
+ const screenScript = document.createElement("script");
129
+ screenScript.src = screenfullJs || screenfullUrl;
130
+ screenScript.onload = screenfullLoad;
131
+ screenScript.id = `${prefix}-screenfull`;
132
+ appendHandler(screenScript, "screenfull");
133
+ }
134
+ });
135
+ onMounted(() => {
136
+ bus.on(editorId, {
137
+ name: CHANGE_FULL_SCREEN,
138
+ callback: fullscreenHandler
109
139
  });
110
- }), { fullscreenHandler: i };
111
- }, El = {
140
+ });
141
+ return { fullscreenHandler };
142
+ };
143
+ const props$6 = {
112
144
  tableShape: {
113
145
  type: Array,
114
146
  default: () => [6, 4]
@@ -118,43 +150,48 @@ const Ll = /* @__PURE__ */ P({
118
150
  default: () => {
119
151
  }
120
152
  }
121
- }, Hl = /* @__PURE__ */ P({
153
+ };
154
+ const TableShape = /* @__PURE__ */ defineComponent({
122
155
  name: "TableShape",
123
- props: El,
124
- setup(e) {
125
- const o = _({
156
+ props: props$6,
157
+ setup(props2) {
158
+ const hoverPosition = reactive({
126
159
  x: -1,
127
160
  y: -1
128
161
  });
129
- return () => t("div", {
130
- class: `${a}-table-shape`,
131
- onMouseleave: () => {
132
- o.x = -1, o.y = -1;
133
- }
134
- }, [new Array(e.tableShape[1]).fill("").map((l, n) => t("div", {
135
- class: `${a}-table-shape-row`,
136
- key: `table-shape-row-${n}`
137
- }, [new Array(e.tableShape[0]).fill("").map((r, i) => t("div", {
138
- class: `${a}-table-shape-col`,
139
- key: `table-shape-col-${i}`,
140
- onMouseenter: () => {
141
- o.x = n, o.y = i;
162
+ return () => createVNode("div", {
163
+ "class": `${prefix}-table-shape`,
164
+ "onMouseleave": () => {
165
+ hoverPosition.x = -1;
166
+ hoverPosition.y = -1;
167
+ }
168
+ }, [new Array(props2.tableShape[1]).fill("").map((_, rowIndex) => createVNode("div", {
169
+ "class": `${prefix}-table-shape-row`,
170
+ "key": `table-shape-row-${rowIndex}`
171
+ }, [new Array(props2.tableShape[0]).fill("").map((_2, colIndex) => createVNode("div", {
172
+ "class": `${prefix}-table-shape-col`,
173
+ "key": `table-shape-col-${colIndex}`,
174
+ "onMouseenter": () => {
175
+ hoverPosition.x = rowIndex;
176
+ hoverPosition.y = colIndex;
142
177
  },
143
- onClick: () => {
144
- e.onSelected(o);
178
+ "onClick": () => {
179
+ props2.onSelected(hoverPosition);
145
180
  }
146
- }, [t("div", {
147
- class: [`${a}-table-shape-col-default`, n <= o.x && i <= o.y && `${a}-table-shape-col-include`]
181
+ }, [createVNode("div", {
182
+ "class": [`${prefix}-table-shape-col-default`, rowIndex <= hoverPosition.x && colIndex <= hoverPosition.y && `${prefix}-table-shape-col-include`]
148
183
  }, null)]))]))]);
149
184
  }
150
- }), Dl = Hl, Nl = {
185
+ });
186
+ const TableShape$1 = TableShape;
187
+ const props$5 = {
151
188
  type: {
152
189
  type: String,
153
190
  default: "link"
154
191
  },
155
192
  visible: {
156
193
  type: Boolean,
157
- default: !1
194
+ default: false
158
195
  },
159
196
  onCancel: {
160
197
  type: Function,
@@ -166,80 +203,94 @@ const Ll = /* @__PURE__ */ P({
166
203
  default: () => {
167
204
  }
168
205
  }
169
- }, Bl = /* @__PURE__ */ P({
170
- props: Nl,
171
- setup(e) {
172
- const o = I("usedLanguageText"), l = I("editorId"), n = Ce(() => {
173
- var i, h;
174
- switch (e.type) {
175
- case "link":
176
- return (i = o.value.linkModalTips) == null ? void 0 : i.linkTitle;
177
- case "image":
178
- return (h = o.value.linkModalTips) == null ? void 0 : h.imageTitle;
179
- default:
206
+ };
207
+ const LinkModal = /* @__PURE__ */ defineComponent({
208
+ props: props$5,
209
+ setup(props2) {
210
+ const ult = inject("usedLanguageText");
211
+ const editorId = inject("editorId");
212
+ const title = computed(() => {
213
+ var _a, _b;
214
+ switch (props2.type) {
215
+ case "link": {
216
+ return (_a = ult.value.linkModalTips) == null ? void 0 : _a.linkTitle;
217
+ }
218
+ case "image": {
219
+ return (_b = ult.value.linkModalTips) == null ? void 0 : _b.imageTitle;
220
+ }
221
+ default: {
180
222
  return "";
223
+ }
181
224
  }
182
- }), r = _({
225
+ });
226
+ const linkData = reactive({
183
227
  desc: "",
184
228
  url: ""
185
229
  });
186
- return H(() => e.visible, (i) => {
187
- i || setTimeout(() => {
188
- r.desc = "", r.url = "";
189
- }, 200);
190
- }), () => t(Bt, {
191
- title: n.value,
192
- visible: e.visible,
193
- onClose: e.onCancel
230
+ watch(() => props2.visible, (nVal) => {
231
+ if (!nVal) {
232
+ setTimeout(() => {
233
+ linkData.desc = "";
234
+ linkData.url = "";
235
+ }, 200);
236
+ }
237
+ });
238
+ return () => createVNode(MdModal, {
239
+ "title": title.value,
240
+ "visible": props2.visible,
241
+ "onClose": props2.onCancel
194
242
  }, {
195
243
  default: () => {
196
- var i, h, f, d, s;
197
- return [t("div", {
198
- class: `${a}-form-item`
199
- }, [t("label", {
200
- class: `${a}-label`,
201
- for: `link-desc-${l}`
202
- }, [(i = o.value.linkModalTips) == null ? void 0 : i.descLabel]), t("input", {
203
- placeholder: (h = o.value.linkModalTips) == null ? void 0 : h.descLabelPlaceHolder,
204
- class: `${a}-input`,
205
- id: `link-desc-${l}`,
206
- type: "text",
207
- value: r.desc,
208
- onChange: (g) => {
209
- r.desc = g.target.value;
244
+ var _a, _b, _c, _d, _e;
245
+ return [createVNode("div", {
246
+ "class": `${prefix}-form-item`
247
+ }, [createVNode("label", {
248
+ "class": `${prefix}-label`,
249
+ "for": `link-desc-${editorId}`
250
+ }, [(_a = ult.value.linkModalTips) == null ? void 0 : _a.descLabel]), createVNode("input", {
251
+ "placeholder": (_b = ult.value.linkModalTips) == null ? void 0 : _b.descLabelPlaceHolder,
252
+ "class": `${prefix}-input`,
253
+ "id": `link-desc-${editorId}`,
254
+ "type": "text",
255
+ "value": linkData.desc,
256
+ "onChange": (e) => {
257
+ linkData.desc = e.target.value;
210
258
  },
211
- autocomplete: "off"
212
- }, null)]), t("div", {
213
- class: `${a}-form-item`
214
- }, [t("label", {
215
- class: `${a}-label`,
216
- for: `link-url-${l}`
217
- }, [(f = o.value.linkModalTips) == null ? void 0 : f.urlLabel]), t("input", {
218
- placeholder: (d = o.value.linkModalTips) == null ? void 0 : d.urlLabelPlaceHolder,
219
- class: `${a}-input`,
220
- id: `link-url-${l}`,
221
- type: "text",
222
- value: r.url,
223
- onChange: (g) => {
224
- r.url = g.target.value;
259
+ "autocomplete": "off"
260
+ }, null)]), createVNode("div", {
261
+ "class": `${prefix}-form-item`
262
+ }, [createVNode("label", {
263
+ "class": `${prefix}-label`,
264
+ "for": `link-url-${editorId}`
265
+ }, [(_c = ult.value.linkModalTips) == null ? void 0 : _c.urlLabel]), createVNode("input", {
266
+ "placeholder": (_d = ult.value.linkModalTips) == null ? void 0 : _d.urlLabelPlaceHolder,
267
+ "class": `${prefix}-input`,
268
+ "id": `link-url-${editorId}`,
269
+ "type": "text",
270
+ "value": linkData.url,
271
+ "onChange": (e) => {
272
+ linkData.url = e.target.value;
225
273
  },
226
- autocomplete: "off"
227
- }, null)]), t("div", {
228
- class: `${a}-form-item`
229
- }, [t("button", {
230
- class: [`${a}-btn`, `${a}-btn-row`],
231
- type: "button",
232
- onClick: () => {
233
- e.onOk(r), r.desc = "", r.url = "";
274
+ "autocomplete": "off"
275
+ }, null)]), createVNode("div", {
276
+ "class": `${prefix}-form-item`
277
+ }, [createVNode("button", {
278
+ "class": [`${prefix}-btn`, `${prefix}-btn-row`],
279
+ "type": "button",
280
+ "onClick": () => {
281
+ props2.onOk(linkData);
282
+ linkData.desc = "";
283
+ linkData.url = "";
234
284
  }
235
- }, [(s = o.value.linkModalTips) == null ? void 0 : s.buttonOK])])];
285
+ }, [(_e = ult.value.linkModalTips) == null ? void 0 : _e.buttonOK])])];
236
286
  }
237
287
  });
238
288
  }
239
- }), Vl = {
289
+ });
290
+ const props$4 = {
240
291
  visible: {
241
292
  type: Boolean,
242
- default: !1
293
+ default: false
243
294
  },
244
295
  onCancel: {
245
296
  type: Function,
@@ -251,121 +302,143 @@ const Ll = /* @__PURE__ */ P({
251
302
  default: () => {
252
303
  }
253
304
  }
254
- }, Fl = /* @__PURE__ */ P({
255
- props: Vl,
256
- setup(e) {
257
- var g, w, $;
258
- const o = I("usedLanguageText"), l = I("editorId");
259
- let n = ($ = (w = (g = X) == null ? void 0 : g.editorExtensions) == null ? void 0 : w.cropper) == null ? void 0 : $.instance;
260
- const r = O(), i = O(), h = O(), f = _({
261
- cropperInited: !1,
262
- imgSelected: !1,
305
+ };
306
+ const ClipModal = /* @__PURE__ */ defineComponent({
307
+ props: props$4,
308
+ setup(props2) {
309
+ var _a, _b, _c;
310
+ const ult = inject("usedLanguageText");
311
+ const editorId = inject("editorId");
312
+ let Cropper = (_c = (_b = (_a = configOption) == null ? void 0 : _a.editorExtensions) == null ? void 0 : _b.cropper) == null ? void 0 : _c.instance;
313
+ const uploadRef = ref();
314
+ const uploadImgRef = ref();
315
+ const previewTargetRef = ref();
316
+ const data = reactive({
317
+ cropperInited: false,
318
+ imgSelected: false,
263
319
  imgSrc: "",
264
320
  // 是否全屏
265
- isFullscreen: !1
321
+ isFullscreen: false
266
322
  });
267
- let d = null;
268
- H(() => e.visible, () => {
269
- e.visible && !f.cropperInited && (n = n || window.Cropper, r.value.onchange = () => {
270
- if (!n) {
271
- v.emit(l, ee, {
272
- name: "Cropper",
273
- message: "Cropper is undefined"
274
- });
275
- return;
276
- }
277
- const S = r.value.files || [];
278
- if (f.imgSelected = !0, (S == null ? void 0 : S.length) > 0) {
279
- const m = new FileReader();
280
- m.onload = (C) => {
281
- f.imgSrc = C.target.result, de(() => {
282
- d = new n(i.value, {
283
- viewMode: 2,
284
- preview: `.${a}-clip-preview-target`
285
- // aspectRatio: 16 / 9,
286
- });
323
+ let cropper = null;
324
+ watch(() => props2.visible, () => {
325
+ if (props2.visible && !data.cropperInited) {
326
+ Cropper = Cropper || window.Cropper;
327
+ uploadRef.value.onchange = () => {
328
+ if (!Cropper) {
329
+ bus.emit(editorId, ERROR_CATCHER, {
330
+ name: "Cropper",
331
+ message: "Cropper is undefined"
287
332
  });
288
- }, m.readAsDataURL(S[0]);
333
+ return;
334
+ }
335
+ const fileList = uploadRef.value.files || [];
336
+ data.imgSelected = true;
337
+ if ((fileList == null ? void 0 : fileList.length) > 0) {
338
+ const fileReader = new FileReader();
339
+ fileReader.onload = (e) => {
340
+ data.imgSrc = e.target.result;
341
+ nextTick(() => {
342
+ cropper = new Cropper(uploadImgRef.value, {
343
+ viewMode: 2,
344
+ preview: `.${prefix}-clip-preview-target`
345
+ // aspectRatio: 16 / 9,
346
+ });
347
+ });
348
+ };
349
+ fileReader.readAsDataURL(fileList[0]);
350
+ }
351
+ };
352
+ }
353
+ });
354
+ watch(() => [data.imgSelected], () => {
355
+ previewTargetRef.value.style = "";
356
+ });
357
+ watch(() => data.isFullscreen, () => {
358
+ nextTick(() => {
359
+ cropper == null ? void 0 : cropper.destroy();
360
+ previewTargetRef.value.style = "";
361
+ if (uploadImgRef.value) {
362
+ cropper = new Cropper(uploadImgRef.value, {
363
+ viewMode: 2,
364
+ preview: `.${prefix}-clip-preview-target`
365
+ // aspectRatio: 16 / 9,
366
+ });
289
367
  }
290
368
  });
291
- }), H(() => [f.imgSelected], () => {
292
- h.value.style = "";
293
- }), H(() => f.isFullscreen, () => {
294
- de(() => {
295
- d == null || d.destroy(), h.value.style = "", i.value && (d = new n(i.value, {
296
- viewMode: 2,
297
- preview: `.${a}-clip-preview-target`
298
- // aspectRatio: 16 / 9,
299
- }));
300
- });
301
369
  });
302
- const s = () => {
303
- d.clear(), d.destroy(), d = null, r.value.value = "", f.imgSelected = !1;
370
+ const reset = () => {
371
+ cropper.clear();
372
+ cropper.destroy();
373
+ cropper = null;
374
+ uploadRef.value.value = "";
375
+ data.imgSelected = false;
304
376
  };
305
377
  return () => {
306
- var S;
307
- return t(Bt, {
308
- class: `${a}-modal-clip`,
309
- title: (S = o.value.clipModalTips) == null ? void 0 : S.title,
310
- visible: e.visible,
311
- onClose: e.onCancel,
312
- showAdjust: !0,
313
- isFullscreen: f.isFullscreen,
314
- onAdjust: (m) => {
315
- f.isFullscreen = m;
378
+ var _a2;
379
+ return createVNode(MdModal, {
380
+ "class": `${prefix}-modal-clip`,
381
+ "title": (_a2 = ult.value.clipModalTips) == null ? void 0 : _a2.title,
382
+ "visible": props2.visible,
383
+ "onClose": props2.onCancel,
384
+ "showAdjust": true,
385
+ "isFullscreen": data.isFullscreen,
386
+ "onAdjust": (val) => {
387
+ data.isFullscreen = val;
316
388
  },
317
- width: "668px",
318
- height: "421px"
389
+ "width": "668px",
390
+ "height": "421px"
319
391
  }, {
320
392
  default: () => {
321
- var m, C;
322
- return [t("div", {
323
- class: `${a}-form-item ${a}-clip`
324
- }, [t("div", {
325
- class: `${a}-clip-main`
326
- }, [f.imgSelected ? t("div", {
327
- class: `${a}-clip-cropper`
328
- }, [t("img", {
329
- src: f.imgSrc,
330
- ref: i,
331
- style: {
393
+ var _a3, _b2;
394
+ return [createVNode("div", {
395
+ "class": `${prefix}-form-item ${prefix}-clip`
396
+ }, [createVNode("div", {
397
+ "class": `${prefix}-clip-main`
398
+ }, [data.imgSelected ? createVNode("div", {
399
+ "class": `${prefix}-clip-cropper`
400
+ }, [createVNode("img", {
401
+ "src": data.imgSrc,
402
+ "ref": uploadImgRef,
403
+ "style": {
332
404
  display: "none"
333
405
  },
334
- alt: ""
335
- }, null), t("div", {
336
- class: `${a}-clip-delete`,
337
- onClick: s
338
- }, [t(x, {
339
- name: "delete"
340
- }, null)])]) : t("div", {
341
- class: `${a}-clip-upload`,
342
- onClick: () => {
343
- r.value.click();
406
+ "alt": ""
407
+ }, null), createVNode("div", {
408
+ "class": `${prefix}-clip-delete`,
409
+ "onClick": reset
410
+ }, [createVNode(Icon, {
411
+ "name": "delete"
412
+ }, null)])]) : createVNode("div", {
413
+ "class": `${prefix}-clip-upload`,
414
+ "onClick": () => {
415
+ uploadRef.value.click();
344
416
  }
345
- }, [t(x, {
346
- name: "upload"
347
- }, null)])]), t("div", {
348
- class: `${a}-clip-preview`
349
- }, [t("div", {
350
- class: `${a}-clip-preview-target`,
351
- ref: h
352
- }, null)])]), t("div", {
353
- class: `${a}-form-item`
354
- }, [t("button", {
355
- class: `${a}-btn`,
356
- type: "button",
357
- onClick: () => {
358
- if (d) {
359
- const u = d.getCroppedCanvas();
360
- v.emit(l, $e, [Jt(u.toDataURL("image/png"))], e.onOk), s();
417
+ }, [createVNode(Icon, {
418
+ "name": "upload"
419
+ }, null)])]), createVNode("div", {
420
+ "class": `${prefix}-clip-preview`
421
+ }, [createVNode("div", {
422
+ "class": `${prefix}-clip-preview-target`,
423
+ "ref": previewTargetRef
424
+ }, null)])]), createVNode("div", {
425
+ "class": `${prefix}-form-item`
426
+ }, [createVNode("button", {
427
+ "class": `${prefix}-btn`,
428
+ "type": "button",
429
+ "onClick": () => {
430
+ if (cropper) {
431
+ const cvs = cropper.getCroppedCanvas();
432
+ bus.emit(editorId, UPLOAD_IMAGE, [base642File(cvs.toDataURL("image/png"))], props2.onOk);
433
+ reset();
361
434
  }
362
435
  }
363
- }, [((m = o.value.clipModalTips) == null ? void 0 : m.buttonUpload) || ((C = o.value.linkModalTips) == null ? void 0 : C.buttonOK)])]), t("input", {
364
- ref: r,
365
- accept: "image/*",
366
- type: "file",
367
- multiple: !1,
368
- style: {
436
+ }, [((_a3 = ult.value.clipModalTips) == null ? void 0 : _a3.buttonUpload) || ((_b2 = ult.value.linkModalTips) == null ? void 0 : _b2.buttonOK)])]), createVNode("input", {
437
+ "ref": uploadRef,
438
+ "accept": "image/*",
439
+ "type": "file",
440
+ "multiple": false,
441
+ "style": {
369
442
  display: "none"
370
443
  }
371
444
  }, null)];
@@ -373,18 +446,19 @@ const Ll = /* @__PURE__ */ P({
373
446
  });
374
447
  };
375
448
  }
376
- }), Rl = {
449
+ });
450
+ const props$3 = {
377
451
  type: {
378
452
  type: String,
379
453
  default: "link"
380
454
  },
381
455
  linkVisible: {
382
456
  type: Boolean,
383
- default: !1
457
+ default: false
384
458
  },
385
459
  clipVisible: {
386
460
  type: Boolean,
387
- default: !1
461
+ default: false
388
462
  },
389
463
  onCancel: {
390
464
  type: Function,
@@ -396,1046 +470,1291 @@ const Ll = /* @__PURE__ */ P({
396
470
  default: () => {
397
471
  }
398
472
  }
399
- }, Ol = /* @__PURE__ */ P({
400
- props: Rl,
401
- setup(e) {
402
- return () => t(Mt, null, [t(Bl, {
403
- type: e.type,
404
- visible: e.linkVisible,
405
- onOk: e.onOk,
406
- onCancel: e.onCancel
407
- }, null), t(Fl, {
408
- visible: e.clipVisible,
409
- onOk: e.onOk,
410
- onCancel: e.onCancel
473
+ };
474
+ const Modals = /* @__PURE__ */ defineComponent({
475
+ props: props$3,
476
+ setup(props2) {
477
+ return () => createVNode(Fragment, null, [createVNode(LinkModal, {
478
+ "type": props2.type,
479
+ "visible": props2.linkVisible,
480
+ "onOk": props2.onOk,
481
+ "onCancel": props2.onCancel
482
+ }, null), createVNode(ClipModal, {
483
+ "visible": props2.clipVisible,
484
+ "onOk": props2.onOk,
485
+ "onCancel": props2.onCancel
411
486
  }, null)]);
412
487
  }
413
- }), Pl = /* @__PURE__ */ P({
488
+ });
489
+ const ToolBar = /* @__PURE__ */ defineComponent({
414
490
  name: "MDEditorToolbar",
415
- props: Il,
416
- setup(e) {
417
- const o = I("editorId"), l = I("usedLanguageText"), n = I("theme"), r = I("language"), {
418
- fullscreenHandler: i
419
- } = Ml(e), h = `${o}-toolbar-wrapper`, f = O(), d = _({
420
- title: !1,
421
- catalog: !1,
491
+ props: toolbarProps,
492
+ setup(props2) {
493
+ const editorId = inject("editorId");
494
+ const ult = inject("usedLanguageText");
495
+ const theme = inject("theme");
496
+ const language = inject("language");
497
+ const {
498
+ fullscreenHandler
499
+ } = useSreenfull(props2);
500
+ const wrapperId = `${editorId}-toolbar-wrapper`;
501
+ const wrapperRef = ref();
502
+ const visible = reactive({
503
+ title: false,
504
+ catalog: false,
422
505
  // 图片上传下拉
423
- image: !1,
506
+ image: false,
424
507
  // 表格预选
425
- table: !1,
508
+ table: false,
426
509
  // mermaid
427
- mermaid: !1,
428
- katex: !1
429
- }), s = (u, b) => {
430
- v.emit(o, L, u, b);
431
- }, g = _({
510
+ mermaid: false,
511
+ katex: false
512
+ });
513
+ const emitHandler = (direct, params) => {
514
+ bus.emit(editorId, REPLACE, direct, params);
515
+ };
516
+ const modalData = reactive({
432
517
  type: "link",
433
- linkVisible: !1,
434
- clipVisible: !1
435
- }), w = O();
436
- Y(() => {
437
- v.on(o, {
438
- name: ke,
439
- callback(u) {
440
- g.type = u, g.linkVisible = !0;
518
+ linkVisible: false,
519
+ clipVisible: false
520
+ });
521
+ const toolbarLeftRef = ref();
522
+ onMounted(() => {
523
+ bus.on(editorId, {
524
+ name: OPEN_MODALS,
525
+ callback(type) {
526
+ modalData.type = type;
527
+ modalData.linkVisible = true;
441
528
  }
442
529
  });
443
530
  });
444
- const $ = Ce(() => {
445
- const u = e.toolbars.filter((k) => !e.toolbarsExclude.includes(k)), b = u.indexOf("="), p = b === -1 ? u : u.slice(0, b + 1), y = b === -1 ? [] : u.slice(b, Number.MAX_SAFE_INTEGER);
446
- return [p, y];
447
- }), S = O(), m = () => {
448
- v.emit(o, $e, Array.from(S.value.files || [])), S.value.value = "";
531
+ const splitedbar = computed(() => {
532
+ const excluedBars = props2.toolbars.filter((barItem) => !props2.toolbarsExclude.includes(barItem));
533
+ const moduleSplitIndex = excluedBars.indexOf("=");
534
+ const barLeft = moduleSplitIndex === -1 ? excluedBars : excluedBars.slice(0, moduleSplitIndex + 1);
535
+ const barRight = moduleSplitIndex === -1 ? [] : excluedBars.slice(moduleSplitIndex, Number.MAX_SAFE_INTEGER);
536
+ return [barLeft, barRight];
537
+ });
538
+ const uploadRef = ref();
539
+ const uploadHandler = () => {
540
+ bus.emit(editorId, UPLOAD_IMAGE, Array.from(uploadRef.value.files || []));
541
+ uploadRef.value.value = "";
449
542
  };
450
- Y(() => {
451
- S.value.addEventListener("change", m);
543
+ onMounted(() => {
544
+ uploadRef.value.addEventListener("change", uploadHandler);
452
545
  });
453
- const C = (u) => {
454
- var b, p, y, k, A, F, D, W, q, R, N, B, Z, G, K, te, le, oe, j, V, M, me, ye, Te, we, xe, Se, Ae, Le, Ie, Me, Ee, He, De, Ne, Be, Ve, Fe, Re, Oe, Pe, We, ze, Ue, _e, qe, Ge, Ke, je, Ze, Xe, Ye, Je, Qe, et, tt, lt, ot, at, nt, it, rt, st, ct, ut, dt, mt;
455
- if (Ut.includes(u))
456
- switch (u) {
457
- case "-":
458
- return t(Ll, null, null);
459
- case "bold":
460
- return t("div", {
461
- class: `${a}-toolbar-item`,
462
- title: (b = l.value.toolbarTips) == null ? void 0 : b.bold,
463
- onClick: () => {
464
- s("bold");
546
+ const barRender = (barItem) => {
547
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma;
548
+ if (allToolbar.includes(barItem)) {
549
+ switch (barItem) {
550
+ case "-": {
551
+ return createVNode(Divider, null, null);
552
+ }
553
+ case "bold": {
554
+ return createVNode("div", {
555
+ "class": `${prefix}-toolbar-item`,
556
+ "title": (_a = ult.value.toolbarTips) == null ? void 0 : _a.bold,
557
+ "onClick": () => {
558
+ emitHandler("bold");
465
559
  }
466
- }, [t(x, {
467
- name: "bold"
468
- }, null), e.showToolbarName && t("div", {
469
- class: `${a}-toolbar-item-name`
470
- }, [(p = l.value.toolbarTips) == null ? void 0 : p.bold])]);
471
- case "underline":
472
- return t("div", {
473
- class: `${a}-toolbar-item`,
474
- title: (y = l.value.toolbarTips) == null ? void 0 : y.underline,
475
- onClick: () => {
476
- s("underline");
560
+ }, [createVNode(Icon, {
561
+ "name": "bold"
562
+ }, null), props2.showToolbarName && createVNode("div", {
563
+ "class": `${prefix}-toolbar-item-name`
564
+ }, [(_b = ult.value.toolbarTips) == null ? void 0 : _b.bold])]);
565
+ }
566
+ case "underline": {
567
+ return createVNode("div", {
568
+ "class": `${prefix}-toolbar-item`,
569
+ "title": (_c = ult.value.toolbarTips) == null ? void 0 : _c.underline,
570
+ "onClick": () => {
571
+ emitHandler("underline");
477
572
  }
478
- }, [t(x, {
479
- name: "underline"
480
- }, null), e.showToolbarName && t("div", {
481
- class: `${a}-toolbar-item-name`
482
- }, [(k = l.value.toolbarTips) == null ? void 0 : k.underline])]);
483
- case "italic":
484
- return t("div", {
485
- class: `${a}-toolbar-item`,
486
- title: (A = l.value.toolbarTips) == null ? void 0 : A.italic,
487
- onClick: () => {
488
- s("italic");
573
+ }, [createVNode(Icon, {
574
+ "name": "underline"
575
+ }, null), props2.showToolbarName && createVNode("div", {
576
+ "class": `${prefix}-toolbar-item-name`
577
+ }, [(_d = ult.value.toolbarTips) == null ? void 0 : _d.underline])]);
578
+ }
579
+ case "italic": {
580
+ return createVNode("div", {
581
+ "class": `${prefix}-toolbar-item`,
582
+ "title": (_e = ult.value.toolbarTips) == null ? void 0 : _e.italic,
583
+ "onClick": () => {
584
+ emitHandler("italic");
489
585
  }
490
- }, [t(x, {
491
- name: "italic"
492
- }, null), e.showToolbarName && t("div", {
493
- class: `${a}-toolbar-item-name`
494
- }, [(F = l.value.toolbarTips) == null ? void 0 : F.italic])]);
495
- case "strikeThrough":
496
- return t("div", {
497
- class: `${a}-toolbar-item`,
498
- title: (D = l.value.toolbarTips) == null ? void 0 : D.strikeThrough,
499
- onClick: () => {
500
- s("strikeThrough");
586
+ }, [createVNode(Icon, {
587
+ "name": "italic"
588
+ }, null), props2.showToolbarName && createVNode("div", {
589
+ "class": `${prefix}-toolbar-item-name`
590
+ }, [(_f = ult.value.toolbarTips) == null ? void 0 : _f.italic])]);
591
+ }
592
+ case "strikeThrough": {
593
+ return createVNode("div", {
594
+ "class": `${prefix}-toolbar-item`,
595
+ "title": (_g = ult.value.toolbarTips) == null ? void 0 : _g.strikeThrough,
596
+ "onClick": () => {
597
+ emitHandler("strikeThrough");
501
598
  }
502
- }, [t(x, {
503
- name: "strike-through"
504
- }, null), e.showToolbarName && t("div", {
505
- class: `${a}-toolbar-item-name`
506
- }, [(W = l.value.toolbarTips) == null ? void 0 : W.strikeThrough])]);
507
- case "title":
508
- return t(ae, {
509
- relative: `#${h}`,
510
- visible: d.title,
511
- onChange: (T) => {
512
- d.title = T;
599
+ }, [createVNode(Icon, {
600
+ "name": "strike-through"
601
+ }, null), props2.showToolbarName && createVNode("div", {
602
+ "class": `${prefix}-toolbar-item-name`
603
+ }, [(_h = ult.value.toolbarTips) == null ? void 0 : _h.strikeThrough])]);
604
+ }
605
+ case "title": {
606
+ return createVNode(Dropdown, {
607
+ "relative": `#${wrapperId}`,
608
+ "visible": visible.title,
609
+ "onChange": (v) => {
610
+ visible.title = v;
513
611
  },
514
- overlay: t("ul", {
515
- class: `${a}-menu`,
516
- onClick: () => {
517
- d.title = !1;
612
+ "overlay": createVNode("ul", {
613
+ "class": `${prefix}-menu`,
614
+ "onClick": () => {
615
+ visible.title = false;
518
616
  }
519
- }, [t("li", {
520
- class: `${a}-menu-item ${a}-menu-item-title`,
521
- onClick: () => {
522
- s("h1");
617
+ }, [createVNode("li", {
618
+ "class": `${prefix}-menu-item ${prefix}-menu-item-title`,
619
+ "onClick": () => {
620
+ emitHandler("h1");
523
621
  }
524
- }, [(q = l.value.titleItem) == null ? void 0 : q.h1]), t("li", {
525
- class: `${a}-menu-item ${a}-menu-item-title`,
526
- onClick: () => {
527
- s("h2");
622
+ }, [(_i = ult.value.titleItem) == null ? void 0 : _i.h1]), createVNode("li", {
623
+ "class": `${prefix}-menu-item ${prefix}-menu-item-title`,
624
+ "onClick": () => {
625
+ emitHandler("h2");
528
626
  }
529
- }, [(R = l.value.titleItem) == null ? void 0 : R.h2]), t("li", {
530
- class: `${a}-menu-item ${a}-menu-item-title`,
531
- onClick: () => {
532
- s("h3");
627
+ }, [(_j = ult.value.titleItem) == null ? void 0 : _j.h2]), createVNode("li", {
628
+ "class": `${prefix}-menu-item ${prefix}-menu-item-title`,
629
+ "onClick": () => {
630
+ emitHandler("h3");
533
631
  }
534
- }, [(N = l.value.titleItem) == null ? void 0 : N.h3]), t("li", {
535
- class: `${a}-menu-item ${a}-menu-item-title`,
536
- onClick: () => {
537
- s("h4");
632
+ }, [(_k = ult.value.titleItem) == null ? void 0 : _k.h3]), createVNode("li", {
633
+ "class": `${prefix}-menu-item ${prefix}-menu-item-title`,
634
+ "onClick": () => {
635
+ emitHandler("h4");
538
636
  }
539
- }, [(B = l.value.titleItem) == null ? void 0 : B.h4]), t("li", {
540
- class: `${a}-menu-item ${a}-menu-item-title`,
541
- onClick: () => {
542
- s("h5");
637
+ }, [(_l = ult.value.titleItem) == null ? void 0 : _l.h4]), createVNode("li", {
638
+ "class": `${prefix}-menu-item ${prefix}-menu-item-title`,
639
+ "onClick": () => {
640
+ emitHandler("h5");
543
641
  }
544
- }, [(Z = l.value.titleItem) == null ? void 0 : Z.h5]), t("li", {
545
- class: `${a}-menu-item ${a}-menu-item-title`,
546
- onClick: () => {
547
- s("h6");
642
+ }, [(_m = ult.value.titleItem) == null ? void 0 : _m.h5]), createVNode("li", {
643
+ "class": `${prefix}-menu-item ${prefix}-menu-item-title`,
644
+ "onClick": () => {
645
+ emitHandler("h6");
548
646
  }
549
- }, [(G = l.value.titleItem) == null ? void 0 : G.h6])])
647
+ }, [(_n = ult.value.titleItem) == null ? void 0 : _n.h6])])
550
648
  }, {
551
649
  default: () => {
552
- var T, E;
553
- return [t("div", {
554
- class: `${a}-toolbar-item`,
555
- title: (T = l.value.toolbarTips) == null ? void 0 : T.title
556
- }, [t(x, {
557
- name: "title"
558
- }, null), e.showToolbarName && t("div", {
559
- class: `${a}-toolbar-item-name`
560
- }, [(E = l.value.toolbarTips) == null ? void 0 : E.title])])];
650
+ var _a2, _b2;
651
+ return [createVNode("div", {
652
+ "class": `${prefix}-toolbar-item`,
653
+ "title": (_a2 = ult.value.toolbarTips) == null ? void 0 : _a2.title
654
+ }, [createVNode(Icon, {
655
+ "name": "title"
656
+ }, null), props2.showToolbarName && createVNode("div", {
657
+ "class": `${prefix}-toolbar-item-name`
658
+ }, [(_b2 = ult.value.toolbarTips) == null ? void 0 : _b2.title])])];
561
659
  }
562
660
  });
563
- case "sub":
564
- return t("div", {
565
- class: `${a}-toolbar-item`,
566
- title: (K = l.value.toolbarTips) == null ? void 0 : K.sub,
567
- onClick: () => {
568
- s("sub");
661
+ }
662
+ case "sub": {
663
+ return createVNode("div", {
664
+ "class": `${prefix}-toolbar-item`,
665
+ "title": (_o = ult.value.toolbarTips) == null ? void 0 : _o.sub,
666
+ "onClick": () => {
667
+ emitHandler("sub");
569
668
  }
570
- }, [t(x, {
571
- name: "sub"
572
- }, null), e.showToolbarName && t("div", {
573
- class: `${a}-toolbar-item-name`
574
- }, [(te = l.value.toolbarTips) == null ? void 0 : te.sub])]);
575
- case "sup":
576
- return t("div", {
577
- class: `${a}-toolbar-item`,
578
- title: (le = l.value.toolbarTips) == null ? void 0 : le.sup,
579
- onClick: () => {
580
- s("sup");
669
+ }, [createVNode(Icon, {
670
+ "name": "sub"
671
+ }, null), props2.showToolbarName && createVNode("div", {
672
+ "class": `${prefix}-toolbar-item-name`
673
+ }, [(_p = ult.value.toolbarTips) == null ? void 0 : _p.sub])]);
674
+ }
675
+ case "sup": {
676
+ return createVNode("div", {
677
+ "class": `${prefix}-toolbar-item`,
678
+ "title": (_q = ult.value.toolbarTips) == null ? void 0 : _q.sup,
679
+ "onClick": () => {
680
+ emitHandler("sup");
581
681
  }
582
- }, [t(x, {
583
- name: "sup"
584
- }, null), e.showToolbarName && t("div", {
585
- class: `${a}-toolbar-item-name`
586
- }, [(oe = l.value.toolbarTips) == null ? void 0 : oe.sup])]);
587
- case "quote":
588
- return t("div", {
589
- class: `${a}-toolbar-item`,
590
- title: (j = l.value.toolbarTips) == null ? void 0 : j.quote,
591
- onClick: () => {
592
- s("quote");
682
+ }, [createVNode(Icon, {
683
+ "name": "sup"
684
+ }, null), props2.showToolbarName && createVNode("div", {
685
+ "class": `${prefix}-toolbar-item-name`
686
+ }, [(_r = ult.value.toolbarTips) == null ? void 0 : _r.sup])]);
687
+ }
688
+ case "quote": {
689
+ return createVNode("div", {
690
+ "class": `${prefix}-toolbar-item`,
691
+ "title": (_s = ult.value.toolbarTips) == null ? void 0 : _s.quote,
692
+ "onClick": () => {
693
+ emitHandler("quote");
593
694
  }
594
- }, [t(x, {
595
- name: "quote"
596
- }, null), e.showToolbarName && t("div", {
597
- class: `${a}-toolbar-item-name`
598
- }, [(V = l.value.toolbarTips) == null ? void 0 : V.quote])]);
599
- case "unorderedList":
600
- return t("div", {
601
- class: `${a}-toolbar-item`,
602
- title: (M = l.value.toolbarTips) == null ? void 0 : M.unorderedList,
603
- onClick: () => {
604
- s("unorderedList");
695
+ }, [createVNode(Icon, {
696
+ "name": "quote"
697
+ }, null), props2.showToolbarName && createVNode("div", {
698
+ "class": `${prefix}-toolbar-item-name`
699
+ }, [(_t = ult.value.toolbarTips) == null ? void 0 : _t.quote])]);
700
+ }
701
+ case "unorderedList": {
702
+ return createVNode("div", {
703
+ "class": `${prefix}-toolbar-item`,
704
+ "title": (_u = ult.value.toolbarTips) == null ? void 0 : _u.unorderedList,
705
+ "onClick": () => {
706
+ emitHandler("unorderedList");
605
707
  }
606
- }, [t(x, {
607
- name: "unordered-list"
608
- }, null), e.showToolbarName && t("div", {
609
- class: `${a}-toolbar-item-name`
610
- }, [(me = l.value.toolbarTips) == null ? void 0 : me.unorderedList])]);
611
- case "orderedList":
612
- return t("div", {
613
- class: `${a}-toolbar-item`,
614
- title: (ye = l.value.toolbarTips) == null ? void 0 : ye.orderedList,
615
- onClick: () => {
616
- s("orderedList");
708
+ }, [createVNode(Icon, {
709
+ "name": "unordered-list"
710
+ }, null), props2.showToolbarName && createVNode("div", {
711
+ "class": `${prefix}-toolbar-item-name`
712
+ }, [(_v = ult.value.toolbarTips) == null ? void 0 : _v.unorderedList])]);
713
+ }
714
+ case "orderedList": {
715
+ return createVNode("div", {
716
+ "class": `${prefix}-toolbar-item`,
717
+ "title": (_w = ult.value.toolbarTips) == null ? void 0 : _w.orderedList,
718
+ "onClick": () => {
719
+ emitHandler("orderedList");
617
720
  }
618
- }, [t(x, {
619
- name: "ordered-list"
620
- }, null), e.showToolbarName && t("div", {
621
- class: `${a}-toolbar-item-name`
622
- }, [(Te = l.value.toolbarTips) == null ? void 0 : Te.orderedList])]);
623
- case "task":
624
- return t("div", {
625
- class: `${a}-toolbar-item`,
626
- title: (we = l.value.toolbarTips) == null ? void 0 : we.task,
627
- onClick: () => {
628
- s("task");
721
+ }, [createVNode(Icon, {
722
+ "name": "ordered-list"
723
+ }, null), props2.showToolbarName && createVNode("div", {
724
+ "class": `${prefix}-toolbar-item-name`
725
+ }, [(_x = ult.value.toolbarTips) == null ? void 0 : _x.orderedList])]);
726
+ }
727
+ case "task": {
728
+ return createVNode("div", {
729
+ "class": `${prefix}-toolbar-item`,
730
+ "title": (_y = ult.value.toolbarTips) == null ? void 0 : _y.task,
731
+ "onClick": () => {
732
+ emitHandler("task");
629
733
  }
630
- }, [t(x, {
631
- name: "task"
632
- }, null), e.showToolbarName && t("div", {
633
- class: `${a}-toolbar-item-name`
634
- }, [(xe = l.value.toolbarTips) == null ? void 0 : xe.task])]);
635
- case "codeRow":
636
- return t("div", {
637
- class: `${a}-toolbar-item`,
638
- title: (Se = l.value.toolbarTips) == null ? void 0 : Se.codeRow,
639
- onClick: () => {
640
- s("codeRow");
734
+ }, [createVNode(Icon, {
735
+ "name": "task"
736
+ }, null), props2.showToolbarName && createVNode("div", {
737
+ "class": `${prefix}-toolbar-item-name`
738
+ }, [(_z = ult.value.toolbarTips) == null ? void 0 : _z.task])]);
739
+ }
740
+ case "codeRow": {
741
+ return createVNode("div", {
742
+ "class": `${prefix}-toolbar-item`,
743
+ "title": (_A = ult.value.toolbarTips) == null ? void 0 : _A.codeRow,
744
+ "onClick": () => {
745
+ emitHandler("codeRow");
641
746
  }
642
- }, [t(x, {
643
- name: "code-row"
644
- }, null), e.showToolbarName && t("div", {
645
- class: `${a}-toolbar-item-name`
646
- }, [(Ae = l.value.toolbarTips) == null ? void 0 : Ae.codeRow])]);
647
- case "code":
648
- return t("div", {
649
- class: `${a}-toolbar-item`,
650
- title: (Le = l.value.toolbarTips) == null ? void 0 : Le.code,
651
- onClick: () => {
652
- s("code");
747
+ }, [createVNode(Icon, {
748
+ "name": "code-row"
749
+ }, null), props2.showToolbarName && createVNode("div", {
750
+ "class": `${prefix}-toolbar-item-name`
751
+ }, [(_B = ult.value.toolbarTips) == null ? void 0 : _B.codeRow])]);
752
+ }
753
+ case "code": {
754
+ return createVNode("div", {
755
+ "class": `${prefix}-toolbar-item`,
756
+ "title": (_C = ult.value.toolbarTips) == null ? void 0 : _C.code,
757
+ "onClick": () => {
758
+ emitHandler("code");
653
759
  }
654
- }, [t(x, {
655
- name: "code"
656
- }, null), e.showToolbarName && t("div", {
657
- class: `${a}-toolbar-item-name`
658
- }, [(Ie = l.value.toolbarTips) == null ? void 0 : Ie.code])]);
659
- case "link":
660
- return t("div", {
661
- class: `${a}-toolbar-item`,
662
- title: (Me = l.value.toolbarTips) == null ? void 0 : Me.link,
663
- onClick: () => {
664
- g.type = "link", g.linkVisible = !0;
760
+ }, [createVNode(Icon, {
761
+ "name": "code"
762
+ }, null), props2.showToolbarName && createVNode("div", {
763
+ "class": `${prefix}-toolbar-item-name`
764
+ }, [(_D = ult.value.toolbarTips) == null ? void 0 : _D.code])]);
765
+ }
766
+ case "link": {
767
+ return createVNode("div", {
768
+ "class": `${prefix}-toolbar-item`,
769
+ "title": (_E = ult.value.toolbarTips) == null ? void 0 : _E.link,
770
+ "onClick": () => {
771
+ modalData.type = "link";
772
+ modalData.linkVisible = true;
665
773
  }
666
- }, [t(x, {
667
- name: "link"
668
- }, null), e.showToolbarName && t("div", {
669
- class: `${a}-toolbar-item-name`
670
- }, [(Ee = l.value.toolbarTips) == null ? void 0 : Ee.link])]);
671
- case "image":
672
- return e.noUploadImg ? t("div", {
673
- class: `${a}-toolbar-item`,
674
- title: (He = l.value.toolbarTips) == null ? void 0 : He.image,
675
- onClick: () => {
676
- g.type = "image", g.linkVisible = !0;
774
+ }, [createVNode(Icon, {
775
+ "name": "link"
776
+ }, null), props2.showToolbarName && createVNode("div", {
777
+ "class": `${prefix}-toolbar-item-name`
778
+ }, [(_F = ult.value.toolbarTips) == null ? void 0 : _F.link])]);
779
+ }
780
+ case "image": {
781
+ return props2.noUploadImg ? createVNode("div", {
782
+ "class": `${prefix}-toolbar-item`,
783
+ "title": (_G = ult.value.toolbarTips) == null ? void 0 : _G.image,
784
+ "onClick": () => {
785
+ modalData.type = "image";
786
+ modalData.linkVisible = true;
677
787
  }
678
- }, [t(x, {
679
- name: "image"
680
- }, null), e.showToolbarName && t("div", {
681
- class: `${a}-toolbar-item-name`
682
- }, [(De = l.value.toolbarTips) == null ? void 0 : De.image])]) : t(ae, {
683
- relative: `#${h}`,
684
- visible: d.image,
685
- onChange: (T) => {
686
- d.image = T;
788
+ }, [createVNode(Icon, {
789
+ "name": "image"
790
+ }, null), props2.showToolbarName && createVNode("div", {
791
+ "class": `${prefix}-toolbar-item-name`
792
+ }, [(_H = ult.value.toolbarTips) == null ? void 0 : _H.image])]) : createVNode(Dropdown, {
793
+ "relative": `#${wrapperId}`,
794
+ "visible": visible.image,
795
+ "onChange": (v) => {
796
+ visible.image = v;
687
797
  },
688
- overlay: t("ul", {
689
- class: `${a}-menu`,
690
- onClick: () => {
691
- d.title = !1;
798
+ "overlay": createVNode("ul", {
799
+ "class": `${prefix}-menu`,
800
+ "onClick": () => {
801
+ visible.title = false;
692
802
  }
693
- }, [t("li", {
694
- class: `${a}-menu-item ${a}-menu-item-image`,
695
- onClick: () => {
696
- g.type = "image", g.linkVisible = !0;
803
+ }, [createVNode("li", {
804
+ "class": `${prefix}-menu-item ${prefix}-menu-item-image`,
805
+ "onClick": () => {
806
+ modalData.type = "image";
807
+ modalData.linkVisible = true;
697
808
  }
698
- }, [(Ne = l.value.imgTitleItem) == null ? void 0 : Ne.link]), t("li", {
699
- class: `${a}-menu-item ${a}-menu-item-image`,
700
- onClick: () => {
701
- S.value.click();
809
+ }, [(_I = ult.value.imgTitleItem) == null ? void 0 : _I.link]), createVNode("li", {
810
+ "class": `${prefix}-menu-item ${prefix}-menu-item-image`,
811
+ "onClick": () => {
812
+ uploadRef.value.click();
702
813
  }
703
- }, [(Be = l.value.imgTitleItem) == null ? void 0 : Be.upload]), t("li", {
704
- class: `${a}-menu-item ${a}-menu-item-image`,
705
- onClick: () => {
706
- g.clipVisible = !0;
814
+ }, [(_J = ult.value.imgTitleItem) == null ? void 0 : _J.upload]), createVNode("li", {
815
+ "class": `${prefix}-menu-item ${prefix}-menu-item-image`,
816
+ "onClick": () => {
817
+ modalData.clipVisible = true;
707
818
  }
708
- }, [(Ve = l.value.imgTitleItem) == null ? void 0 : Ve.clip2upload])])
819
+ }, [(_K = ult.value.imgTitleItem) == null ? void 0 : _K.clip2upload])])
709
820
  }, {
710
821
  default: () => {
711
- var T, E;
712
- return [t("div", {
713
- class: `${a}-toolbar-item`,
714
- title: (T = l.value.toolbarTips) == null ? void 0 : T.image
715
- }, [t(x, {
716
- name: "image"
717
- }, null), e.showToolbarName && t("div", {
718
- class: `${a}-toolbar-item-name`
719
- }, [(E = l.value.toolbarTips) == null ? void 0 : E.image])])];
822
+ var _a2, _b2;
823
+ return [createVNode("div", {
824
+ "class": `${prefix}-toolbar-item`,
825
+ "title": (_a2 = ult.value.toolbarTips) == null ? void 0 : _a2.image
826
+ }, [createVNode(Icon, {
827
+ "name": "image"
828
+ }, null), props2.showToolbarName && createVNode("div", {
829
+ "class": `${prefix}-toolbar-item-name`
830
+ }, [(_b2 = ult.value.toolbarTips) == null ? void 0 : _b2.image])])];
720
831
  }
721
832
  });
722
- case "table":
723
- return t(ae, {
724
- relative: `#${h}`,
725
- visible: d.table,
726
- onChange: (T) => {
727
- d.table = T;
833
+ }
834
+ case "table": {
835
+ return createVNode(Dropdown, {
836
+ "relative": `#${wrapperId}`,
837
+ "visible": visible.table,
838
+ "onChange": (v) => {
839
+ visible.table = v;
728
840
  },
729
- key: "bar-table",
730
- overlay: t(Dl, {
731
- tableShape: e.tableShape,
732
- onSelected: (T) => {
733
- s("table", {
734
- selectedShape: T
841
+ "key": "bar-table",
842
+ "overlay": createVNode(TableShape$1, {
843
+ "tableShape": props2.tableShape,
844
+ "onSelected": (selectedShape) => {
845
+ emitHandler("table", {
846
+ selectedShape
735
847
  });
736
848
  }
737
849
  }, null)
738
850
  }, {
739
851
  default: () => {
740
- var T, E;
741
- return [t("div", {
742
- class: `${a}-toolbar-item`,
743
- title: (T = l.value.toolbarTips) == null ? void 0 : T.table
744
- }, [t(x, {
745
- name: "table"
746
- }, null), e.showToolbarName && t("div", {
747
- class: `${a}-toolbar-item-name`
748
- }, [(E = l.value.toolbarTips) == null ? void 0 : E.table])])];
852
+ var _a2, _b2;
853
+ return [createVNode("div", {
854
+ "class": `${prefix}-toolbar-item`,
855
+ "title": (_a2 = ult.value.toolbarTips) == null ? void 0 : _a2.table
856
+ }, [createVNode(Icon, {
857
+ "name": "table"
858
+ }, null), props2.showToolbarName && createVNode("div", {
859
+ "class": `${prefix}-toolbar-item-name`
860
+ }, [(_b2 = ult.value.toolbarTips) == null ? void 0 : _b2.table])])];
749
861
  }
750
862
  });
751
- case "revoke":
752
- return t("div", {
753
- class: `${a}-toolbar-item`,
754
- title: (Fe = l.value.toolbarTips) == null ? void 0 : Fe.revoke,
755
- onClick: () => {
756
- v.emit(o, Nt);
863
+ }
864
+ case "revoke": {
865
+ return createVNode("div", {
866
+ "class": `${prefix}-toolbar-item`,
867
+ "title": (_L = ult.value.toolbarTips) == null ? void 0 : _L.revoke,
868
+ "onClick": () => {
869
+ bus.emit(editorId, CTRL_Z);
757
870
  }
758
- }, [t(x, {
759
- name: "revoke"
760
- }, null), e.showToolbarName && t("div", {
761
- class: `${a}-toolbar-item-name`
762
- }, [(Re = l.value.toolbarTips) == null ? void 0 : Re.revoke])]);
763
- case "next":
764
- return t("div", {
765
- class: `${a}-toolbar-item`,
766
- title: (Oe = l.value.toolbarTips) == null ? void 0 : Oe.next,
767
- onClick: () => {
768
- v.emit(o, Dt);
871
+ }, [createVNode(Icon, {
872
+ "name": "revoke"
873
+ }, null), props2.showToolbarName && createVNode("div", {
874
+ "class": `${prefix}-toolbar-item-name`
875
+ }, [(_M = ult.value.toolbarTips) == null ? void 0 : _M.revoke])]);
876
+ }
877
+ case "next": {
878
+ return createVNode("div", {
879
+ "class": `${prefix}-toolbar-item`,
880
+ "title": (_N = ult.value.toolbarTips) == null ? void 0 : _N.next,
881
+ "onClick": () => {
882
+ bus.emit(editorId, CTRL_SHIFT_Z);
769
883
  }
770
- }, [t(x, {
771
- name: "next"
772
- }, null), e.showToolbarName && t("div", {
773
- class: `${a}-toolbar-item-name`
774
- }, [(Pe = l.value.toolbarTips) == null ? void 0 : Pe.next])]);
775
- case "save":
776
- return t("div", {
777
- class: `${a}-toolbar-item`,
778
- title: (We = l.value.toolbarTips) == null ? void 0 : We.save,
779
- onClick: () => {
780
- v.emit(o, Ht);
884
+ }, [createVNode(Icon, {
885
+ "name": "next"
886
+ }, null), props2.showToolbarName && createVNode("div", {
887
+ "class": `${prefix}-toolbar-item-name`
888
+ }, [(_O = ult.value.toolbarTips) == null ? void 0 : _O.next])]);
889
+ }
890
+ case "save": {
891
+ return createVNode("div", {
892
+ "class": `${prefix}-toolbar-item`,
893
+ "title": (_P = ult.value.toolbarTips) == null ? void 0 : _P.save,
894
+ "onClick": () => {
895
+ bus.emit(editorId, ON_SAVE);
781
896
  }
782
- }, [t(x, {
783
- name: "baocun"
784
- }, null), e.showToolbarName && t("div", {
785
- class: `${a}-toolbar-item-name`
786
- }, [(ze = l.value.toolbarTips) == null ? void 0 : ze.save])]);
787
- case "prettier":
788
- return e.noPrettier ? "" : t("div", {
789
- class: `${a}-toolbar-item`,
790
- title: (Ue = l.value.toolbarTips) == null ? void 0 : Ue.prettier,
791
- onClick: () => {
792
- s("prettier");
897
+ }, [createVNode(Icon, {
898
+ "name": "baocun"
899
+ }, null), props2.showToolbarName && createVNode("div", {
900
+ "class": `${prefix}-toolbar-item-name`
901
+ }, [(_Q = ult.value.toolbarTips) == null ? void 0 : _Q.save])]);
902
+ }
903
+ case "prettier": {
904
+ return !props2.noPrettier ? createVNode("div", {
905
+ "class": `${prefix}-toolbar-item`,
906
+ "title": (_R = ult.value.toolbarTips) == null ? void 0 : _R.prettier,
907
+ "onClick": () => {
908
+ emitHandler("prettier");
793
909
  }
794
- }, [t(x, {
795
- name: "prettier"
796
- }, null), e.showToolbarName && t("div", {
797
- class: `${a}-toolbar-item-name`
798
- }, [(_e = l.value.toolbarTips) == null ? void 0 : _e.prettier])]);
799
- case "pageFullscreen":
800
- return !e.setting.fullscreen && t("div", {
801
- class: `${a}-toolbar-item`,
802
- title: (qe = l.value.toolbarTips) == null ? void 0 : qe.pageFullscreen,
803
- onClick: () => {
804
- e.updateSetting("pageFullscreen");
910
+ }, [createVNode(Icon, {
911
+ "name": "prettier"
912
+ }, null), props2.showToolbarName && createVNode("div", {
913
+ "class": `${prefix}-toolbar-item-name`
914
+ }, [(_S = ult.value.toolbarTips) == null ? void 0 : _S.prettier])]) : "";
915
+ }
916
+ case "pageFullscreen": {
917
+ return !props2.setting.fullscreen && createVNode("div", {
918
+ "class": `${prefix}-toolbar-item`,
919
+ "title": (_T = ult.value.toolbarTips) == null ? void 0 : _T.pageFullscreen,
920
+ "onClick": () => {
921
+ props2.updateSetting("pageFullscreen");
805
922
  }
806
- }, [t(x, {
807
- name: e.setting.pageFullscreen ? "suoxiao" : "fangda"
808
- }, null), e.showToolbarName && t("div", {
809
- class: `${a}-toolbar-item-name`
810
- }, [(Ge = l.value.toolbarTips) == null ? void 0 : Ge.pageFullscreen])]);
811
- case "fullscreen":
812
- return t("div", {
813
- class: `${a}-toolbar-item`,
814
- title: (Ke = l.value.toolbarTips) == null ? void 0 : Ke.fullscreen,
815
- onClick: () => {
816
- i();
923
+ }, [createVNode(Icon, {
924
+ "name": props2.setting.pageFullscreen ? "suoxiao" : "fangda"
925
+ }, null), props2.showToolbarName && createVNode("div", {
926
+ "class": `${prefix}-toolbar-item-name`
927
+ }, [(_U = ult.value.toolbarTips) == null ? void 0 : _U.pageFullscreen])]);
928
+ }
929
+ case "fullscreen": {
930
+ return createVNode("div", {
931
+ "class": `${prefix}-toolbar-item`,
932
+ "title": (_V = ult.value.toolbarTips) == null ? void 0 : _V.fullscreen,
933
+ "onClick": () => {
934
+ fullscreenHandler();
817
935
  }
818
- }, [t(x, {
819
- name: e.setting.fullscreen ? "fullscreen-exit" : "fullscreen"
820
- }, null), e.showToolbarName && t("div", {
821
- class: `${a}-toolbar-item-name`
822
- }, [(je = l.value.toolbarTips) == null ? void 0 : je.fullscreen])]);
823
- case "preview":
824
- return t("div", {
825
- class: `${a}-toolbar-item`,
826
- title: (Ze = l.value.toolbarTips) == null ? void 0 : Ze.preview,
827
- onClick: () => {
828
- e.updateSetting("preview");
936
+ }, [createVNode(Icon, {
937
+ "name": props2.setting.fullscreen ? "fullscreen-exit" : "fullscreen"
938
+ }, null), props2.showToolbarName && createVNode("div", {
939
+ "class": `${prefix}-toolbar-item-name`
940
+ }, [(_W = ult.value.toolbarTips) == null ? void 0 : _W.fullscreen])]);
941
+ }
942
+ case "preview": {
943
+ return createVNode("div", {
944
+ "class": `${prefix}-toolbar-item`,
945
+ "title": (_X = ult.value.toolbarTips) == null ? void 0 : _X.preview,
946
+ "onClick": () => {
947
+ props2.updateSetting("preview");
829
948
  }
830
- }, [t(x, {
831
- name: "preview"
832
- }, null), e.showToolbarName && t("div", {
833
- class: `${a}-toolbar-item-name`
834
- }, [(Xe = l.value.toolbarTips) == null ? void 0 : Xe.preview])]);
835
- case "htmlPreview":
836
- return t("div", {
837
- class: `${a}-toolbar-item`,
838
- title: (Ye = l.value.toolbarTips) == null ? void 0 : Ye.htmlPreview,
839
- onClick: () => {
840
- e.updateSetting("htmlPreview");
949
+ }, [createVNode(Icon, {
950
+ "name": "preview"
951
+ }, null), props2.showToolbarName && createVNode("div", {
952
+ "class": `${prefix}-toolbar-item-name`
953
+ }, [(_Y = ult.value.toolbarTips) == null ? void 0 : _Y.preview])]);
954
+ }
955
+ case "htmlPreview": {
956
+ return createVNode("div", {
957
+ "class": `${prefix}-toolbar-item`,
958
+ "title": (_Z = ult.value.toolbarTips) == null ? void 0 : _Z.htmlPreview,
959
+ "onClick": () => {
960
+ props2.updateSetting("htmlPreview");
841
961
  }
842
- }, [t(x, {
843
- name: "coding"
844
- }, null), e.showToolbarName && t("div", {
845
- class: `${a}-toolbar-item-name`
846
- }, [(Je = l.value.toolbarTips) == null ? void 0 : Je.htmlPreview])]);
847
- case "catalog":
848
- return t("div", {
849
- class: `${a}-toolbar-item`,
850
- title: (Qe = l.value.toolbarTips) == null ? void 0 : Qe.catalog,
851
- onClick: () => {
852
- v.emit(o, Qt);
962
+ }, [createVNode(Icon, {
963
+ "name": "coding"
964
+ }, null), props2.showToolbarName && createVNode("div", {
965
+ "class": `${prefix}-toolbar-item-name`
966
+ }, [(__ = ult.value.toolbarTips) == null ? void 0 : __.htmlPreview])]);
967
+ }
968
+ case "catalog": {
969
+ return createVNode("div", {
970
+ "class": `${prefix}-toolbar-item`,
971
+ "title": (_$ = ult.value.toolbarTips) == null ? void 0 : _$.catalog,
972
+ "onClick": () => {
973
+ bus.emit(editorId, CHANGE_CATALOG_VISIBLE);
853
974
  },
854
- key: "bar-catalog"
855
- }, [t(x, {
856
- name: "catalog"
857
- }, null), e.showToolbarName && t("div", {
858
- class: `${a}-toolbar-item-name`
859
- }, [(et = l.value.toolbarTips) == null ? void 0 : et.catalog])]);
860
- case "github":
861
- return t("div", {
862
- class: `${a}-toolbar-item`,
863
- title: (tt = l.value.toolbarTips) == null ? void 0 : tt.github,
864
- onClick: () => Gt("https://github.com/imzbf/md-editor-v3")
865
- }, [t(x, {
866
- name: "github"
867
- }, null), e.showToolbarName && t("div", {
868
- class: `${a}-toolbar-item-name`
869
- }, [(lt = l.value.toolbarTips) == null ? void 0 : lt.github])]);
870
- case "mermaid":
871
- return t(ae, {
872
- relative: `#${h}`,
873
- visible: d.mermaid,
874
- onChange: (T) => {
875
- d.mermaid = T;
975
+ "key": "bar-catalog"
976
+ }, [createVNode(Icon, {
977
+ "name": "catalog"
978
+ }, null), props2.showToolbarName && createVNode("div", {
979
+ "class": `${prefix}-toolbar-item-name`
980
+ }, [(_aa = ult.value.toolbarTips) == null ? void 0 : _aa.catalog])]);
981
+ }
982
+ case "github": {
983
+ return createVNode("div", {
984
+ "class": `${prefix}-toolbar-item`,
985
+ "title": (_ba = ult.value.toolbarTips) == null ? void 0 : _ba.github,
986
+ "onClick": () => linkTo("https://github.com/imzbf/md-editor-v3")
987
+ }, [createVNode(Icon, {
988
+ "name": "github"
989
+ }, null), props2.showToolbarName && createVNode("div", {
990
+ "class": `${prefix}-toolbar-item-name`
991
+ }, [(_ca = ult.value.toolbarTips) == null ? void 0 : _ca.github])]);
992
+ }
993
+ case "mermaid": {
994
+ return createVNode(Dropdown, {
995
+ "relative": `#${wrapperId}`,
996
+ "visible": visible.mermaid,
997
+ "onChange": (v) => {
998
+ visible.mermaid = v;
876
999
  },
877
- overlay: t("ul", {
878
- class: `${a}-menu`,
879
- onClick: () => {
880
- d.mermaid = !1;
1000
+ "overlay": createVNode("ul", {
1001
+ "class": `${prefix}-menu`,
1002
+ "onClick": () => {
1003
+ visible.mermaid = false;
881
1004
  }
882
- }, [t("li", {
883
- class: `${a}-menu-item ${a}-menu-item-mermaid`,
884
- onClick: () => {
885
- s("flow");
1005
+ }, [createVNode("li", {
1006
+ "class": `${prefix}-menu-item ${prefix}-menu-item-mermaid`,
1007
+ "onClick": () => {
1008
+ emitHandler("flow");
886
1009
  }
887
- }, [(ot = l.value.mermaid) == null ? void 0 : ot.flow]), t("li", {
888
- class: `${a}-menu-item ${a}-menu-item-mermaid`,
889
- onClick: () => {
890
- s("sequence");
1010
+ }, [(_da = ult.value.mermaid) == null ? void 0 : _da.flow]), createVNode("li", {
1011
+ "class": `${prefix}-menu-item ${prefix}-menu-item-mermaid`,
1012
+ "onClick": () => {
1013
+ emitHandler("sequence");
891
1014
  }
892
- }, [(at = l.value.mermaid) == null ? void 0 : at.sequence]), t("li", {
893
- class: `${a}-menu-item ${a}-menu-item-mermaid`,
894
- onClick: () => {
895
- s("gantt");
1015
+ }, [(_ea = ult.value.mermaid) == null ? void 0 : _ea.sequence]), createVNode("li", {
1016
+ "class": `${prefix}-menu-item ${prefix}-menu-item-mermaid`,
1017
+ "onClick": () => {
1018
+ emitHandler("gantt");
896
1019
  }
897
- }, [(nt = l.value.mermaid) == null ? void 0 : nt.gantt]), t("li", {
898
- class: `${a}-menu-item ${a}-menu-item-mermaid`,
899
- onClick: () => {
900
- s("class");
1020
+ }, [(_fa = ult.value.mermaid) == null ? void 0 : _fa.gantt]), createVNode("li", {
1021
+ "class": `${prefix}-menu-item ${prefix}-menu-item-mermaid`,
1022
+ "onClick": () => {
1023
+ emitHandler("class");
901
1024
  }
902
- }, [(it = l.value.mermaid) == null ? void 0 : it.class]), t("li", {
903
- class: `${a}-menu-item ${a}-menu-item-mermaid`,
904
- onClick: () => {
905
- s("state");
1025
+ }, [(_ga = ult.value.mermaid) == null ? void 0 : _ga.class]), createVNode("li", {
1026
+ "class": `${prefix}-menu-item ${prefix}-menu-item-mermaid`,
1027
+ "onClick": () => {
1028
+ emitHandler("state");
906
1029
  }
907
- }, [(rt = l.value.mermaid) == null ? void 0 : rt.state]), t("li", {
908
- class: `${a}-menu-item ${a}-menu-item-mermaid`,
909
- onClick: () => {
910
- s("pie");
1030
+ }, [(_ha = ult.value.mermaid) == null ? void 0 : _ha.state]), createVNode("li", {
1031
+ "class": `${prefix}-menu-item ${prefix}-menu-item-mermaid`,
1032
+ "onClick": () => {
1033
+ emitHandler("pie");
911
1034
  }
912
- }, [(st = l.value.mermaid) == null ? void 0 : st.pie]), t("li", {
913
- class: `${a}-menu-item ${a}-menu-item-mermaid`,
914
- onClick: () => {
915
- s("relationship");
1035
+ }, [(_ia = ult.value.mermaid) == null ? void 0 : _ia.pie]), createVNode("li", {
1036
+ "class": `${prefix}-menu-item ${prefix}-menu-item-mermaid`,
1037
+ "onClick": () => {
1038
+ emitHandler("relationship");
916
1039
  }
917
- }, [(ct = l.value.mermaid) == null ? void 0 : ct.relationship]), t("li", {
918
- class: `${a}-menu-item ${a}-menu-item-mermaid`,
919
- onClick: () => {
920
- s("journey");
1040
+ }, [(_ja = ult.value.mermaid) == null ? void 0 : _ja.relationship]), createVNode("li", {
1041
+ "class": `${prefix}-menu-item ${prefix}-menu-item-mermaid`,
1042
+ "onClick": () => {
1043
+ emitHandler("journey");
921
1044
  }
922
- }, [(ut = l.value.mermaid) == null ? void 0 : ut.journey])]),
923
- key: "bar-mermaid"
1045
+ }, [(_ka = ult.value.mermaid) == null ? void 0 : _ka.journey])]),
1046
+ "key": "bar-mermaid"
924
1047
  }, {
925
1048
  default: () => {
926
- var T, E;
927
- return [t("div", {
928
- class: `${a}-toolbar-item`,
929
- title: (T = l.value.toolbarTips) == null ? void 0 : T.mermaid
930
- }, [t(x, {
931
- name: "mermaid"
932
- }, null), e.showToolbarName && t("div", {
933
- class: `${a}-toolbar-item-name`
934
- }, [(E = l.value.toolbarTips) == null ? void 0 : E.mermaid])])];
1049
+ var _a2, _b2;
1050
+ return [createVNode("div", {
1051
+ "class": `${prefix}-toolbar-item`,
1052
+ "title": (_a2 = ult.value.toolbarTips) == null ? void 0 : _a2.mermaid
1053
+ }, [createVNode(Icon, {
1054
+ "name": "mermaid"
1055
+ }, null), props2.showToolbarName && createVNode("div", {
1056
+ "class": `${prefix}-toolbar-item-name`
1057
+ }, [(_b2 = ult.value.toolbarTips) == null ? void 0 : _b2.mermaid])])];
935
1058
  }
936
1059
  });
937
- case "katex":
938
- return t(ae, {
939
- relative: `#${h}`,
940
- visible: d.katex,
941
- onChange: (T) => {
942
- d.katex = T;
1060
+ }
1061
+ case "katex": {
1062
+ return createVNode(Dropdown, {
1063
+ "relative": `#${wrapperId}`,
1064
+ "visible": visible.katex,
1065
+ "onChange": (v) => {
1066
+ visible.katex = v;
943
1067
  },
944
- overlay: t("ul", {
945
- class: `${a}-menu`,
946
- onClick: () => {
947
- d.katex = !1;
1068
+ "overlay": createVNode("ul", {
1069
+ "class": `${prefix}-menu`,
1070
+ "onClick": () => {
1071
+ visible.katex = false;
948
1072
  }
949
- }, [t("li", {
950
- class: `${a}-menu-item ${a}-menu-item-katex`,
951
- onClick: () => {
952
- s("katexInline");
1073
+ }, [createVNode("li", {
1074
+ "class": `${prefix}-menu-item ${prefix}-menu-item-katex`,
1075
+ "onClick": () => {
1076
+ emitHandler("katexInline");
953
1077
  }
954
- }, [(dt = l.value.katex) == null ? void 0 : dt.inline]), t("li", {
955
- class: `${a}-menu-item ${a}-menu-item-katex`,
956
- onClick: () => {
957
- s("katexBlock");
1078
+ }, [(_la = ult.value.katex) == null ? void 0 : _la.inline]), createVNode("li", {
1079
+ "class": `${prefix}-menu-item ${prefix}-menu-item-katex`,
1080
+ "onClick": () => {
1081
+ emitHandler("katexBlock");
958
1082
  }
959
- }, [(mt = l.value.katex) == null ? void 0 : mt.block])]),
960
- key: "bar-katex"
1083
+ }, [(_ma = ult.value.katex) == null ? void 0 : _ma.block])]),
1084
+ "key": "bar-katex"
961
1085
  }, {
962
1086
  default: () => {
963
- var T, E;
964
- return [t("div", {
965
- class: `${a}-toolbar-item`,
966
- title: (T = l.value.toolbarTips) == null ? void 0 : T.katex
967
- }, [t(x, {
968
- name: "formula"
969
- }, null), e.showToolbarName && t("div", {
970
- class: `${a}-toolbar-item-name`
971
- }, [(E = l.value.toolbarTips) == null ? void 0 : E.katex])])];
1087
+ var _a2, _b2;
1088
+ return [createVNode("div", {
1089
+ "class": `${prefix}-toolbar-item`,
1090
+ "title": (_a2 = ult.value.toolbarTips) == null ? void 0 : _a2.katex
1091
+ }, [createVNode(Icon, {
1092
+ "name": "formula"
1093
+ }, null), props2.showToolbarName && createVNode("div", {
1094
+ "class": `${prefix}-toolbar-item-name`
1095
+ }, [(_b2 = ult.value.toolbarTips) == null ? void 0 : _b2.katex])])];
972
1096
  }
973
1097
  });
974
- }
975
- else if (e.defToolbars instanceof Array) {
976
- const T = e.defToolbars[u];
977
- return T ? gt(T, {
978
- theme: n.value,
979
- language: r.value,
980
- insert(ge) {
981
- v.emit(o, L, "universal", {
982
- generate: ge
983
- });
984
- }
985
- }) : "";
986
- } else if (e.defToolbars && e.defToolbars.children instanceof Array) {
987
- const T = e.defToolbars.children[u];
988
- return T ? gt(T, {
989
- theme: n.value,
990
- language: r.value,
991
- insert(ge) {
992
- v.emit(o, L, "universal", {
993
- generate: ge
994
- });
995
1098
  }
996
- }) : "";
997
- } else
1099
+ }
1100
+ } else if (props2.defToolbars instanceof Array) {
1101
+ const defItem = props2.defToolbars[barItem];
1102
+ if (defItem) {
1103
+ const defItemCloned = cloneVNode(defItem, {
1104
+ theme: theme.value,
1105
+ language: language.value,
1106
+ insert(generate) {
1107
+ bus.emit(editorId, REPLACE, "universal", {
1108
+ generate
1109
+ });
1110
+ }
1111
+ });
1112
+ return defItemCloned;
1113
+ }
998
1114
  return "";
1115
+ } else if (props2.defToolbars && props2.defToolbars.children instanceof Array) {
1116
+ const defItem = props2.defToolbars.children[barItem];
1117
+ if (defItem) {
1118
+ const defItemCloned = cloneVNode(defItem, {
1119
+ theme: theme.value,
1120
+ language: language.value,
1121
+ insert(generate) {
1122
+ bus.emit(editorId, REPLACE, "universal", {
1123
+ generate
1124
+ });
1125
+ }
1126
+ });
1127
+ return defItemCloned;
1128
+ }
1129
+ return "";
1130
+ } else {
1131
+ return "";
1132
+ }
999
1133
  };
1000
- return H(() => e.toolbars, () => {
1001
- de(() => {
1002
- f.value && qt(f.value);
1134
+ watch(() => props2.toolbars, () => {
1135
+ nextTick(() => {
1136
+ if (wrapperRef.value) {
1137
+ draggingScroll(wrapperRef.value);
1138
+ }
1003
1139
  });
1004
1140
  }, {
1005
- immediate: !0
1006
- }), () => {
1007
- const u = $.value[0].map((p) => C(p)), b = $.value[1].map((p) => C(p));
1008
- return t(Mt, null, [e.toolbars.length > 0 && t("div", {
1009
- class: `${a}-toolbar-wrapper`,
1010
- ref: f,
1011
- id: h
1012
- }, [t("div", {
1013
- class: [`${a}-toolbar`, e.showToolbarName && `${a}-stn`]
1014
- }, [t("div", {
1015
- class: `${a}-toolbar-left`,
1016
- ref: w
1017
- }, [u]), t("div", {
1018
- class: `${a}-toolbar-right`
1019
- }, [b])])]), t("input", {
1020
- ref: S,
1021
- accept: "image/*",
1022
- type: "file",
1023
- multiple: !0,
1024
- style: {
1141
+ immediate: true
1142
+ });
1143
+ return () => {
1144
+ const LeftBar = splitedbar.value[0].map((barItem) => barRender(barItem));
1145
+ const RightBar = splitedbar.value[1].map((barItem) => barRender(barItem));
1146
+ return createVNode(Fragment, null, [props2.toolbars.length > 0 && createVNode("div", {
1147
+ "class": `${prefix}-toolbar-wrapper`,
1148
+ "ref": wrapperRef,
1149
+ "id": wrapperId
1150
+ }, [createVNode("div", {
1151
+ "class": [`${prefix}-toolbar`, props2.showToolbarName && `${prefix}-stn`]
1152
+ }, [createVNode("div", {
1153
+ "class": `${prefix}-toolbar-left`,
1154
+ "ref": toolbarLeftRef
1155
+ }, [LeftBar]), createVNode("div", {
1156
+ "class": `${prefix}-toolbar-right`
1157
+ }, [RightBar])])]), createVNode("input", {
1158
+ "ref": uploadRef,
1159
+ "accept": "image/*",
1160
+ "type": "file",
1161
+ "multiple": true,
1162
+ "style": {
1025
1163
  display: "none"
1026
1164
  }
1027
- }, null), t(Ol, {
1028
- linkVisible: g.linkVisible,
1029
- clipVisible: g.clipVisible,
1030
- type: g.type,
1031
- onCancel: () => {
1032
- g.linkVisible = !1, g.clipVisible = !1;
1165
+ }, null), createVNode(Modals, {
1166
+ "linkVisible": modalData.linkVisible,
1167
+ "clipVisible": modalData.clipVisible,
1168
+ "type": modalData.type,
1169
+ "onCancel": () => {
1170
+ modalData.linkVisible = false;
1171
+ modalData.clipVisible = false;
1033
1172
  },
1034
- onOk: (p) => {
1035
- p && s(g.type, {
1036
- desc: p.desc,
1037
- url: p.url
1038
- }), g.linkVisible = !1, g.clipVisible = !1;
1173
+ "onOk": (data) => {
1174
+ if (data) {
1175
+ emitHandler(modalData.type, {
1176
+ desc: data.desc,
1177
+ url: data.url
1178
+ });
1179
+ }
1180
+ modalData.linkVisible = false;
1181
+ modalData.clipVisible = false;
1039
1182
  }
1040
1183
  }, null)]);
1041
1184
  };
1042
1185
  }
1043
- }), Wl = `.${a}-preview > [data-line]`, zl = (e, o) => {
1044
- const l = Kt(() => {
1045
- e.removeEventListener("scroll", n), e.addEventListener("scroll", n), o.removeEventListener("scroll", n), o.addEventListener("scroll", n);
1046
- }, 50), n = (r) => {
1047
- const i = e.clientHeight, h = o.clientHeight, f = e.scrollHeight, d = o.scrollHeight, s = (f - i) / (d - h);
1048
- r.target === e ? (o.removeEventListener("scroll", n), o.scrollTo({
1049
- top: e.scrollTop / s
1050
- // behavior: 'smooth'
1051
- }), l()) : (e.removeEventListener("scroll", n), e.scrollTo({
1052
- top: o.scrollTop * s
1053
- // behavior: 'smooth'
1054
- }), l());
1186
+ });
1187
+ const DATA_LINE_SELECTOR = `.${prefix}-preview > [data-line]`;
1188
+ const scrollAutoWithScale = (pEle, cEle) => {
1189
+ const addEvent = debounce(() => {
1190
+ pEle.removeEventListener("scroll", scrollHandler);
1191
+ pEle.addEventListener("scroll", scrollHandler);
1192
+ cEle.removeEventListener("scroll", scrollHandler);
1193
+ cEle.addEventListener("scroll", scrollHandler);
1194
+ }, 50);
1195
+ const scrollHandler = (e) => {
1196
+ const pHeight = pEle.clientHeight;
1197
+ const cHeight = cEle.clientHeight;
1198
+ const pScrollHeight = pEle.scrollHeight;
1199
+ const cScrollHeight = cEle.scrollHeight;
1200
+ const scale = (pScrollHeight - pHeight) / (cScrollHeight - cHeight);
1201
+ if (e.target === pEle) {
1202
+ cEle.removeEventListener("scroll", scrollHandler);
1203
+ cEle.scrollTo({
1204
+ top: pEle.scrollTop / scale
1205
+ // behavior: 'smooth'
1206
+ });
1207
+ addEvent();
1208
+ } else {
1209
+ pEle.removeEventListener("scroll", scrollHandler);
1210
+ pEle.scrollTo({
1211
+ top: cEle.scrollTop * scale
1212
+ // behavior: 'smooth'
1213
+ });
1214
+ addEvent();
1215
+ }
1055
1216
  };
1056
1217
  return [
1057
1218
  () => {
1058
- l().finally(() => {
1059
- e.dispatchEvent(new Event("scroll"));
1219
+ addEvent().finally(() => {
1220
+ pEle.dispatchEvent(new Event("scroll"));
1060
1221
  });
1061
1222
  },
1062
1223
  () => {
1063
- e.removeEventListener("scroll", n), o.removeEventListener("scroll", n);
1224
+ pEle.removeEventListener("scroll", scrollHandler);
1225
+ cEle.removeEventListener("scroll", scrollHandler);
1064
1226
  }
1065
1227
  ];
1066
- }, Ul = (e, o, l) => {
1067
- const { view: n } = l, r = jt(), i = (u) => n.lineBlockAt(n.state.doc.line(u).from).top, h = (u) => n.lineBlockAt(n.state.doc.line(u).from).height;
1068
- let f = [], d = [], s = [];
1069
- const g = () => {
1070
- f = [], d = [], s = [], d = d.concat(
1071
- Array.from(o.querySelectorAll(Wl))
1228
+ };
1229
+ const scrollAuto = (pEle, cEle, codeMirrorUt) => {
1230
+ const { view } = codeMirrorUt;
1231
+ const smoothScroll = createSmoothScroll();
1232
+ const getTopByLine = (line) => {
1233
+ return view.lineBlockAt(view.state.doc.line(line).from).top;
1234
+ };
1235
+ const getHeightByLine = (line) => {
1236
+ return view.lineBlockAt(view.state.doc.line(line).from).height;
1237
+ };
1238
+ let blockMap = [];
1239
+ let elesHasLineNumber = [];
1240
+ let startLines = [];
1241
+ const buildMap = () => {
1242
+ blockMap = [];
1243
+ elesHasLineNumber = [];
1244
+ startLines = [];
1245
+ elesHasLineNumber = elesHasLineNumber.concat(
1246
+ Array.from(cEle.querySelectorAll(DATA_LINE_SELECTOR))
1072
1247
  );
1073
- const u = d.map((k) => Number(k.dataset.line) + 1);
1074
- s = s.concat(u);
1075
- const { lines: b } = n.state.doc;
1076
- let p = 1, y = u.shift() ?? b;
1077
- for (let k = 1; k <= b; k++)
1078
- k === y && (p = k, y = u.shift() || b + 1), f.push({
1079
- start: p,
1080
- end: y - 1
1248
+ const startLinesCalc = elesHasLineNumber.map((item) => Number(item.dataset.line) + 1);
1249
+ startLines = startLines.concat(startLinesCalc);
1250
+ const { lines } = view.state.doc;
1251
+ let start = 1;
1252
+ let end = startLinesCalc.shift() ?? lines;
1253
+ for (let i = 1; i <= lines; i++) {
1254
+ if (i === end) {
1255
+ start = i;
1256
+ end = startLinesCalc.shift() || lines + 1;
1257
+ }
1258
+ blockMap.push({
1259
+ start,
1260
+ end: end - 1
1081
1261
  });
1262
+ }
1082
1263
  };
1083
- let w = 0, $ = 0;
1084
- const S = () => {
1085
- var G, K;
1086
- if ($ !== 0)
1087
- return !1;
1088
- w++;
1089
- const { scrollDOM: u, contentHeight: b } = n;
1090
- let p = +getComputedStyle(o).paddingTop.replace("px", "");
1091
- const y = n.lineBlockAtHeight(u.scrollTop), { number: k } = n.state.doc.lineAt(y.from), A = f[k - 1];
1092
- if (!A)
1093
- return !1;
1094
- let F = i(A.end) + h(A.end), D = 0;
1095
- const W = i(A.start), q = o.querySelector(`[data-line="${A.start - 1}"]`) || ((G = o.firstElementChild) == null ? void 0 : G.firstElementChild), R = o.querySelector(`[data-line="${A.end}"]`) || ((K = o.lastElementChild) == null ? void 0 : K.lastElementChild);
1096
- let N = 0, B = 0;
1097
- W === 0 ? (D = u.scrollTop / F, q === R ? (p = 0, F = b - u.offsetHeight, N = R.offsetTop + R.offsetHeight - o.clientHeight) : N = R.offsetTop) : (D = (u.scrollTop - W) / (F - W), B = q.offsetTop, N = R.offsetTop - B), F > u.scrollHeight - u.clientHeight && (D = (u.scrollTop - W) / (u.scrollHeight - u.clientHeight - W), B = q.offsetTop, N = o.scrollHeight - o.clientHeight - B + 10);
1098
- const Z = B - p + N * D;
1099
- r(o, Z, () => {
1100
- w--;
1264
+ let pLock = 0;
1265
+ let cLock = 0;
1266
+ const pEleHandler = () => {
1267
+ var _a, _b;
1268
+ if (cLock !== 0) {
1269
+ return false;
1270
+ }
1271
+ pLock++;
1272
+ const { scrollDOM, contentHeight } = view;
1273
+ let cElePaddingTop = +getComputedStyle(cEle).paddingTop.replace("px", "");
1274
+ const blockInfo = view.lineBlockAtHeight(scrollDOM.scrollTop);
1275
+ const { number: currLine } = view.state.doc.lineAt(blockInfo.from);
1276
+ const blockData = blockMap[currLine - 1];
1277
+ if (!blockData) {
1278
+ return false;
1279
+ }
1280
+ let endLinePosition = getTopByLine(blockData.end) + getHeightByLine(blockData.end);
1281
+ let scale = 0;
1282
+ const startTop = getTopByLine(blockData.start);
1283
+ const startEle = cEle.querySelector(`[data-line="${blockData.start - 1}"]`) || ((_a = cEle.firstElementChild) == null ? void 0 : _a.firstElementChild);
1284
+ const endEle = cEle.querySelector(`[data-line="${blockData.end}"]`) || ((_b = cEle.lastElementChild) == null ? void 0 : _b.lastElementChild);
1285
+ let blockHeight = 0;
1286
+ let startEleOffetTop = 0;
1287
+ if (startTop === 0) {
1288
+ scale = scrollDOM.scrollTop / endLinePosition;
1289
+ if (startEle === endEle) {
1290
+ cElePaddingTop = 0;
1291
+ endLinePosition = contentHeight - scrollDOM.offsetHeight;
1292
+ blockHeight = endEle.offsetTop + endEle.offsetHeight - cEle.clientHeight;
1293
+ } else {
1294
+ blockHeight = endEle.offsetTop;
1295
+ }
1296
+ } else {
1297
+ scale = (scrollDOM.scrollTop - startTop) / (endLinePosition - startTop);
1298
+ startEleOffetTop = startEle.offsetTop;
1299
+ blockHeight = endEle.offsetTop - startEleOffetTop;
1300
+ }
1301
+ if (endLinePosition > scrollDOM.scrollHeight - scrollDOM.clientHeight) {
1302
+ scale = (scrollDOM.scrollTop - startTop) / (scrollDOM.scrollHeight - scrollDOM.clientHeight - startTop);
1303
+ startEleOffetTop = startEle.offsetTop;
1304
+ blockHeight = cEle.scrollHeight - cEle.clientHeight - startEleOffetTop + 10;
1305
+ }
1306
+ const scrollToTop = startEleOffetTop - cElePaddingTop + blockHeight * scale;
1307
+ smoothScroll(cEle, scrollToTop, () => {
1308
+ pLock--;
1101
1309
  });
1102
- }, m = () => {
1103
- var Z, G, K, te, le, oe;
1104
- if (w !== 0)
1310
+ };
1311
+ const cEleHandler = () => {
1312
+ var _a, _b, _c, _d, _e, _f;
1313
+ if (pLock !== 0) {
1105
1314
  return;
1106
- $++;
1107
- const { scrollDOM: u } = n, b = o.scrollTop, p = o.scrollHeight;
1108
- let y = (Z = o.firstElementChild) == null ? void 0 : Z.firstElementChild, k = (G = o.firstElementChild) == null ? void 0 : G.lastElementChild;
1109
- if (s.length > 0) {
1110
- let j = Math.ceil(
1111
- Number(s[s.length - 1]) * (b / p)
1112
- ), V = s.findLastIndex((M) => M <= j);
1113
- V = V === -1 ? 0 : V, j = s[V];
1114
- for (let M = V; M >= 0 && M < s.length; )
1115
- if (d[M].offsetTop > b) {
1116
- if (M - 1 >= 0) {
1117
- M--;
1315
+ }
1316
+ cLock++;
1317
+ const { scrollDOM } = view;
1318
+ const cScrollTop = cEle.scrollTop;
1319
+ const cScrollHeight = cEle.scrollHeight;
1320
+ let realEleStart = (_a = cEle.firstElementChild) == null ? void 0 : _a.firstElementChild;
1321
+ let realEleEnd = (_b = cEle.firstElementChild) == null ? void 0 : _b.lastElementChild;
1322
+ if (startLines.length > 0) {
1323
+ let virtualLine = Math.ceil(
1324
+ Number(startLines[startLines.length - 1]) * (cScrollTop / cScrollHeight)
1325
+ );
1326
+ let startLineIndex = startLines.findLastIndex((value) => value <= virtualLine);
1327
+ startLineIndex = startLineIndex === -1 ? 0 : startLineIndex;
1328
+ virtualLine = startLines[startLineIndex];
1329
+ for (let i = startLineIndex; i >= 0 && i < startLines.length; ) {
1330
+ const currentElementTop = elesHasLineNumber[i].offsetTop;
1331
+ if (currentElementTop > cScrollTop) {
1332
+ if (i - 1 >= 0) {
1333
+ i--;
1118
1334
  continue;
1119
1335
  }
1120
- j = -1, V = M;
1336
+ virtualLine = -1;
1337
+ startLineIndex = i;
1121
1338
  break;
1122
1339
  } else {
1123
- if (M + 1 <= s.length && d[M + 1].offsetTop < b) {
1124
- M++;
1340
+ if (i + 1 <= startLines.length && elesHasLineNumber[i + 1].offsetTop < cScrollTop) {
1341
+ i++;
1125
1342
  continue;
1126
1343
  }
1127
- j = s[M], V = M;
1344
+ virtualLine = startLines[i];
1345
+ startLineIndex = i;
1128
1346
  break;
1129
1347
  }
1130
- switch (j) {
1348
+ }
1349
+ switch (virtualLine) {
1131
1350
  case -1: {
1132
- y = (K = o.firstElementChild) == null ? void 0 : K.firstElementChild, k = d[V];
1351
+ realEleStart = (_c = cEle.firstElementChild) == null ? void 0 : _c.firstElementChild;
1352
+ realEleEnd = elesHasLineNumber[startLineIndex];
1133
1353
  break;
1134
1354
  }
1135
- case s.length - 1: {
1136
- y = d[V], k = (te = o.firstElementChild) == null ? void 0 : te.lastElementChild;
1355
+ case startLines.length - 1: {
1356
+ realEleStart = elesHasLineNumber[startLineIndex];
1357
+ realEleEnd = (_d = cEle.firstElementChild) == null ? void 0 : _d.lastElementChild;
1137
1358
  break;
1138
1359
  }
1139
- default:
1140
- y = d[V], k = d[V + 1];
1141
- }
1142
- }
1143
- const A = y === ((le = o.firstElementChild) == null ? void 0 : le.firstElementChild) ? 0 : y.offsetTop;
1144
- let F = k.offsetTop, D = 0;
1145
- const { start: W, end: q } = f[Number(y.dataset.line || 0)], R = i(W);
1146
- let N = i(q + 1), B = 0;
1147
- N > u.scrollHeight - u.clientHeight || k.scrollTop > o.scrollHeight - o.clientHeight ? (D = Math.max(
1148
- (b - A) / (o.scrollHeight - A - o.clientHeight),
1149
- 0
1150
- ), N = i(n.state.doc.lines) + h(n.state.doc.lines), B = 8 + N - R - e.clientHeight) : y === ((oe = o.firstElementChild) == null ? void 0 : oe.firstElementChild) ? (y === k && (F = k.offsetTop + k.offsetHeight + +getComputedStyle(k).marginBottom.replace("px", "")), B = N, D = Math.max(b / F, 0)) : (D = Math.max(
1151
- (b - A) / (F - A),
1152
- 0
1153
- ), B = N - R), r(e, R + B * D, () => {
1154
- $--;
1360
+ default: {
1361
+ realEleStart = elesHasLineNumber[startLineIndex];
1362
+ realEleEnd = elesHasLineNumber[startLineIndex + 1];
1363
+ }
1364
+ }
1365
+ }
1366
+ const eleStartOffsetTop = realEleStart === ((_e = cEle.firstElementChild) == null ? void 0 : _e.firstElementChild) ? 0 : realEleStart.offsetTop;
1367
+ let eleEndOffsetTop = realEleEnd.offsetTop;
1368
+ let scale = 0;
1369
+ const { start, end } = blockMap[Number(realEleStart.dataset.line || 0)];
1370
+ const firstLineScrollTop = getTopByLine(start);
1371
+ let endLineScrollTop = getTopByLine(end + 1);
1372
+ let blockHeight = 0;
1373
+ if (endLineScrollTop > scrollDOM.scrollHeight - scrollDOM.clientHeight || realEleEnd.scrollTop > cEle.scrollHeight - cEle.clientHeight) {
1374
+ scale = Math.max(
1375
+ (cScrollTop - eleStartOffsetTop) / (cEle.scrollHeight - eleStartOffsetTop - cEle.clientHeight),
1376
+ 0
1377
+ );
1378
+ endLineScrollTop = getTopByLine(view.state.doc.lines) + getHeightByLine(view.state.doc.lines);
1379
+ blockHeight = 8 + endLineScrollTop - firstLineScrollTop - pEle.clientHeight;
1380
+ } else if (realEleStart === ((_f = cEle.firstElementChild) == null ? void 0 : _f.firstElementChild)) {
1381
+ if (realEleStart === realEleEnd) {
1382
+ eleEndOffsetTop = realEleEnd.offsetTop + realEleEnd.offsetHeight + +getComputedStyle(realEleEnd).marginBottom.replace("px", "");
1383
+ blockHeight = endLineScrollTop;
1384
+ } else {
1385
+ blockHeight = endLineScrollTop;
1386
+ }
1387
+ scale = Math.max(cScrollTop / eleEndOffsetTop, 0);
1388
+ } else {
1389
+ scale = Math.max(
1390
+ (cScrollTop - eleStartOffsetTop) / (eleEndOffsetTop - eleStartOffsetTop),
1391
+ 0
1392
+ );
1393
+ blockHeight = endLineScrollTop - firstLineScrollTop;
1394
+ }
1395
+ smoothScroll(pEle, firstLineScrollTop + blockHeight * scale, () => {
1396
+ cLock--;
1155
1397
  });
1156
- }, C = Zt((u) => {
1157
- var k;
1158
- const { scrollDOM: b, contentHeight: p } = n, y = b.clientHeight;
1159
- if (p <= y || o.firstElementChild.clientHeight <= o.clientHeight || n.state.doc.lines < ((k = f[f.length - 1]) == null ? void 0 : k.end))
1160
- return !1;
1161
- u.target === e ? S() : m();
1398
+ };
1399
+ const scrollHandler = throttle((e) => {
1400
+ var _a;
1401
+ const { scrollDOM, contentHeight } = view;
1402
+ const scrollDomHeight = scrollDOM.clientHeight;
1403
+ if (contentHeight <= scrollDomHeight || cEle.firstElementChild.clientHeight <= cEle.clientHeight) {
1404
+ return false;
1405
+ }
1406
+ if (view.state.doc.lines < ((_a = blockMap[blockMap.length - 1]) == null ? void 0 : _a.end)) {
1407
+ return false;
1408
+ }
1409
+ if (e.target === pEle) {
1410
+ pEleHandler();
1411
+ } else {
1412
+ cEleHandler();
1413
+ }
1162
1414
  }, 8);
1163
1415
  return [
1164
1416
  () => {
1165
- g(), e.addEventListener("scroll", C), o.addEventListener("scroll", C), e.dispatchEvent(new Event("scroll"));
1417
+ buildMap();
1418
+ pEle.addEventListener("scroll", scrollHandler);
1419
+ cEle.addEventListener("scroll", scrollHandler);
1420
+ pEle.dispatchEvent(new Event("scroll"));
1166
1421
  },
1167
1422
  () => {
1168
- e.removeEventListener("scroll", C), o.removeEventListener("scroll", C);
1423
+ pEle.removeEventListener("scroll", scrollHandler);
1424
+ cEle.removeEventListener("scroll", scrollHandler);
1169
1425
  }
1170
1426
  ];
1171
- }, _l = (e, o, l) => {
1172
- const n = I("editorId");
1173
- let r = () => {
1174
- }, i = () => {
1427
+ };
1428
+ const useAutoScroll = (props2, html, codeMirrorUt) => {
1429
+ const editorId = inject("editorId");
1430
+ let clearScrollAuto = () => {
1175
1431
  };
1176
- const h = () => {
1177
- r();
1178
- const f = document.querySelector(
1179
- `#${n} .cm-scroller`
1180
- ), d = document.querySelector(
1181
- `[id="${n}-preview-wrapper"]`
1182
- ), s = document.querySelector(
1183
- `[id="${n}-html-wrapper"]`
1432
+ let initScrollAuto = () => {
1433
+ };
1434
+ const rebindEvent = () => {
1435
+ clearScrollAuto();
1436
+ const cmScroller = document.querySelector(
1437
+ `#${editorId} .cm-scroller`
1438
+ );
1439
+ const previewEle = document.querySelector(
1440
+ `[id="${editorId}-preview-wrapper"]`
1441
+ );
1442
+ const htmlEle = document.querySelector(
1443
+ `[id="${editorId}-html-wrapper"]`
1184
1444
  );
1185
- (d || s) && ([i, r] = (d ? Ul : zl)(
1186
- f,
1187
- d || s,
1188
- l.value
1189
- )), e.scrollAuto && i();
1445
+ if (previewEle || htmlEle) {
1446
+ const scrollHandler = previewEle ? scrollAuto : scrollAutoWithScale;
1447
+ const cEle = previewEle || htmlEle;
1448
+ [initScrollAuto, clearScrollAuto] = scrollHandler(
1449
+ cmScroller,
1450
+ cEle,
1451
+ codeMirrorUt.value
1452
+ );
1453
+ }
1454
+ if (props2.scrollAuto) {
1455
+ initScrollAuto();
1456
+ }
1190
1457
  };
1191
- H(
1458
+ watch(
1192
1459
  [
1193
- o,
1194
- Q(e.setting, "preview"),
1195
- Q(e.setting, "htmlPreview"),
1196
- Q(e.setting, "fullscreen"),
1197
- Q(e.setting, "pageFullscreen")
1460
+ html,
1461
+ toRef(props2.setting, "preview"),
1462
+ toRef(props2.setting, "htmlPreview"),
1463
+ toRef(props2.setting, "fullscreen"),
1464
+ toRef(props2.setting, "pageFullscreen")
1198
1465
  ],
1199
1466
  () => {
1200
- de(h);
1201
- }
1202
- ), H(
1203
- () => e.scrollAuto,
1204
- (f) => {
1205
- f ? i() : r();
1206
- }
1207
- ), Y(h);
1208
- }, ql = (e, o, l) => {
1209
- var g, w, $, S, m, C;
1210
- let n = "", r = 0, i = 0, h = !0, f = !1;
1211
- const d = o.getSelectedText(), s = (g = X.editorConfig) == null ? void 0 : g.mermaidTemplate;
1212
- if (/^h[1-6]{1}$/.test(e)) {
1213
- const u = e.replace(/^h(\d)/, (b, p) => new Array(Number(p)).fill("#", 0, p).join(""));
1214
- n = `${u} ${d}`, r = u.length + 1;
1215
- } else if (e === "prettier") {
1216
- const u = window.prettier || (($ = (w = X.editorExtensions) == null ? void 0 : w.prettier) == null ? void 0 : $.prettierInstance), b = [
1217
- ((S = window.prettierPlugins) == null ? void 0 : S.markdown) || ((C = (m = X.editorExtensions) == null ? void 0 : m.prettier) == null ? void 0 : C.parserMarkdownInstance)
1467
+ nextTick(rebindEvent);
1468
+ }
1469
+ );
1470
+ watch(
1471
+ () => props2.scrollAuto,
1472
+ (sa) => {
1473
+ if (sa) {
1474
+ initScrollAuto();
1475
+ } else {
1476
+ clearScrollAuto();
1477
+ }
1478
+ }
1479
+ );
1480
+ onMounted(rebindEvent);
1481
+ };
1482
+ const directive2flag = (direct, codeMirrorUt, params) => {
1483
+ var _a, _b, _c, _d, _e, _f;
1484
+ let targetValue = "";
1485
+ let deviationStart = 0;
1486
+ let deviationEnd = 0;
1487
+ let select = true;
1488
+ let replaceAll = false;
1489
+ const selectedText = codeMirrorUt.getSelectedText();
1490
+ const mermaidTemplate = (_a = configOption.editorConfig) == null ? void 0 : _a.mermaidTemplate;
1491
+ if (/^h[1-6]{1}$/.test(direct)) {
1492
+ const pix = direct.replace(/^h(\d)/, (_, num) => {
1493
+ return new Array(Number(num)).fill("#", 0, num).join("");
1494
+ });
1495
+ targetValue = `${pix} ${selectedText}`;
1496
+ deviationStart = pix.length + 1;
1497
+ } else if (direct === "prettier") {
1498
+ const prettier = window.prettier || ((_c = (_b = configOption.editorExtensions) == null ? void 0 : _b.prettier) == null ? void 0 : _c.prettierInstance);
1499
+ const prettierPlugins = [
1500
+ ((_d = window.prettierPlugins) == null ? void 0 : _d.markdown) || ((_f = (_e = configOption.editorExtensions) == null ? void 0 : _e.prettier) == null ? void 0 : _f.parserMarkdownInstance)
1218
1501
  ];
1219
- !u || b[0] === void 0 ? (v.emit(l.editorId, ee, {
1220
- name: "prettier",
1221
- message: "prettier is undefined"
1222
- }), n = o.getValue()) : n = u.format(o.getValue(), {
1223
- parser: "markdown",
1224
- plugins: b
1225
- }), h = !1, f = !0;
1226
- } else
1227
- switch (e) {
1502
+ if (!prettier || prettierPlugins[0] === void 0) {
1503
+ bus.emit(params.editorId, ERROR_CATCHER, {
1504
+ name: "prettier",
1505
+ message: "prettier is undefined"
1506
+ });
1507
+ targetValue = codeMirrorUt.getValue();
1508
+ } else {
1509
+ targetValue = prettier.format(codeMirrorUt.getValue(), {
1510
+ parser: "markdown",
1511
+ plugins: prettierPlugins
1512
+ });
1513
+ }
1514
+ select = false;
1515
+ replaceAll = true;
1516
+ } else {
1517
+ switch (direct) {
1228
1518
  case "bold": {
1229
- n = `**${d}**`, r = 2, i = -2;
1519
+ targetValue = `**${selectedText}**`;
1520
+ deviationStart = 2;
1521
+ deviationEnd = -2;
1230
1522
  break;
1231
1523
  }
1232
1524
  case "underline": {
1233
- n = `<u>${d}</u>`, r = 3, i = -4;
1525
+ targetValue = `<u>${selectedText}</u>`;
1526
+ deviationStart = 3;
1527
+ deviationEnd = -4;
1234
1528
  break;
1235
1529
  }
1236
1530
  case "italic": {
1237
- n = `*${d}*`, r = 1, i = -1;
1531
+ targetValue = `*${selectedText}*`;
1532
+ deviationStart = 1;
1533
+ deviationEnd = -1;
1238
1534
  break;
1239
1535
  }
1240
1536
  case "strikeThrough": {
1241
- n = `~~${d}~~`, r = 2, i = -2;
1537
+ targetValue = `~~${selectedText}~~`;
1538
+ deviationStart = 2;
1539
+ deviationEnd = -2;
1242
1540
  break;
1243
1541
  }
1244
1542
  case "sub": {
1245
- n = `<sub>${d}</sub>`, r = 5, i = -6;
1543
+ targetValue = `<sub>${selectedText}</sub>`;
1544
+ deviationStart = 5;
1545
+ deviationEnd = -6;
1246
1546
  break;
1247
1547
  }
1248
1548
  case "sup": {
1249
- n = `<sup>${d}</sup>`, r = 5, i = -6;
1549
+ targetValue = `<sup>${selectedText}</sup>`;
1550
+ deviationStart = 5;
1551
+ deviationEnd = -6;
1250
1552
  break;
1251
1553
  }
1252
1554
  case "codeRow": {
1253
- n = "`" + d + "`", r = 1, i = -1;
1555
+ targetValue = "`" + selectedText + "`";
1556
+ deviationStart = 1;
1557
+ deviationEnd = -1;
1254
1558
  break;
1255
1559
  }
1256
1560
  case "quote": {
1257
- n = `> ${d}`, r = 2;
1561
+ targetValue = `> ${selectedText}`;
1562
+ deviationStart = 2;
1258
1563
  break;
1259
1564
  }
1260
1565
  case "orderedList": {
1261
- n = `1. ${d}`, r = 3;
1566
+ targetValue = `1. ${selectedText}`;
1567
+ deviationStart = 3;
1262
1568
  break;
1263
1569
  }
1264
1570
  case "unorderedList": {
1265
- n = `- ${d}`, r = 2;
1571
+ targetValue = `- ${selectedText}`;
1572
+ deviationStart = 2;
1266
1573
  break;
1267
1574
  }
1268
1575
  case "task": {
1269
- n = `- [ ] ${d}`, r = 6;
1576
+ targetValue = `- [ ] ${selectedText}`;
1577
+ deviationStart = 6;
1270
1578
  break;
1271
1579
  }
1272
1580
  case "code": {
1273
- const u = l.text || d || "", b = l.mode || "language";
1274
- n = `\`\`\`${b}
1275
- ${u}
1581
+ const text = params.text || selectedText || "";
1582
+ const mode = params.mode || "language";
1583
+ targetValue = `\`\`\`${mode}
1584
+ ${text}
1276
1585
  \`\`\`
1277
- `, r = 3, i = 3 + b.length - n.length;
1586
+ `;
1587
+ deviationStart = 3;
1588
+ deviationEnd = 3 + mode.length - targetValue.length;
1278
1589
  break;
1279
1590
  }
1280
1591
  case "table": {
1281
- n = "|";
1282
- const { selectedShape: u = { x: 1, y: 1 } } = l, { x: b, y: p } = u;
1283
- for (let y = 0; y <= p; y++)
1284
- n += " col |";
1285
- n += `
1286
- |`;
1287
- for (let y = 0; y <= p; y++)
1288
- n += " - |";
1289
- for (let y = 0; y <= b; y++) {
1290
- n += `
1291
- |`;
1292
- for (let k = 0; k <= p; k++)
1293
- n += " content |";
1592
+ targetValue = "|";
1593
+ const { selectedShape = { x: 1, y: 1 } } = params;
1594
+ const { x, y } = selectedShape;
1595
+ for (let i = 0; i <= y; i++) {
1596
+ targetValue += " col |";
1294
1597
  }
1295
- r = 2, i = 5 - n.length;
1598
+ targetValue += "\n|";
1599
+ for (let i = 0; i <= y; i++) {
1600
+ targetValue += " - |";
1601
+ }
1602
+ for (let row = 0; row <= x; row++) {
1603
+ targetValue += "\n|";
1604
+ for (let col = 0; col <= y; col++) {
1605
+ targetValue += " content |";
1606
+ }
1607
+ }
1608
+ deviationStart = 2;
1609
+ deviationEnd = 5 - targetValue.length;
1296
1610
  break;
1297
1611
  }
1298
1612
  case "link": {
1299
- const { desc: u, url: b } = l;
1300
- n = `[${u}](${b})`, h = !1;
1613
+ const { desc, url } = params;
1614
+ targetValue = `[${desc}](${url})`;
1615
+ select = false;
1301
1616
  break;
1302
1617
  }
1303
1618
  case "image": {
1304
- const { desc: u, url: b, urls: p } = l;
1305
- p instanceof Array ? n = p.reduce((y, k) => {
1306
- const {
1307
- url: A = "",
1308
- alt: F = "",
1309
- title: D = ""
1310
- } = typeof k == "object" ? k : { url: k };
1311
- return y + `![${F}](${A}${D ? " '" + D + "'" : ""})
1619
+ const { desc, url, urls } = params;
1620
+ if (urls instanceof Array) {
1621
+ targetValue = urls.reduce((pVal, _url) => {
1622
+ const {
1623
+ url: url2 = "",
1624
+ alt = "",
1625
+ title = ""
1626
+ } = typeof _url === "object" ? _url : { url: _url };
1627
+ return pVal + `![${alt}](${url2}${title ? " '" + title + "'" : ""})
1628
+ `;
1629
+ }, "");
1630
+ } else {
1631
+ targetValue = `![${desc}](${url})
1312
1632
  `;
1313
- }, "") : n = `![${u}](${b})
1314
- `, h = !1;
1633
+ }
1634
+ select = false;
1315
1635
  break;
1316
1636
  }
1317
1637
  case "flow": {
1318
- n = `\`\`\`mermaid
1319
- ${(s == null ? void 0 : s.flow) || `flowchart TD
1320
- Start --> Stop`}
1638
+ targetValue = `\`\`\`mermaid
1639
+ ${(mermaidTemplate == null ? void 0 : mermaidTemplate.flow) || "flowchart TD \n Start --> Stop"}
1321
1640
  \`\`\`
1322
- `, r = 3, i = 10 - n.length;
1641
+ `;
1642
+ deviationStart = 3;
1643
+ deviationEnd = 10 - targetValue.length;
1323
1644
  break;
1324
1645
  }
1325
1646
  case "sequence": {
1326
- n = `\`\`\`mermaid
1327
- ${(s == null ? void 0 : s.sequence) || `sequenceDiagram
1328
- A->>B: hello!
1329
- B-->>A: hi!
1330
- A-)B: bye!`}
1647
+ targetValue = `\`\`\`mermaid
1648
+ ${(mermaidTemplate == null ? void 0 : mermaidTemplate.sequence) || "sequenceDiagram\n A->>B: hello!\n B-->>A: hi!\n A-)B: bye!"}
1331
1649
  \`\`\`
1332
- `, r = 3, i = 10 - n.length;
1650
+ `;
1651
+ deviationStart = 3;
1652
+ deviationEnd = 10 - targetValue.length;
1333
1653
  break;
1334
1654
  }
1335
1655
  case "gantt": {
1336
- n = `\`\`\`mermaid
1337
- ${(s == null ? void 0 : s.gantt) || `gantt
1338
- title A Gantt Diagram
1339
- dateFormat YYYY-MM-DD
1340
- section Section
1341
- A task :a1, 2014-01-01, 30d
1342
- Another task :after a1, 20d`}
1656
+ targetValue = `\`\`\`mermaid
1657
+ ${(mermaidTemplate == null ? void 0 : mermaidTemplate.gantt) || "gantt\ntitle A Gantt Diagram\ndateFormat YYYY-MM-DD\nsection Section\nA task :a1, 2014-01-01, 30d\nAnother task :after a1, 20d"}
1343
1658
  \`\`\`
1344
- `, r = 3, i = 10 - n.length;
1659
+ `;
1660
+ deviationStart = 3;
1661
+ deviationEnd = 10 - targetValue.length;
1345
1662
  break;
1346
1663
  }
1347
1664
  case "class": {
1348
- n = `\`\`\`mermaid
1349
- ${(s == null ? void 0 : s.class) || `classDiagram
1350
- class Animal
1351
- Vehicle <|-- Car`}
1665
+ targetValue = `\`\`\`mermaid
1666
+ ${(mermaidTemplate == null ? void 0 : mermaidTemplate.class) || "classDiagram\n class Animal\n Vehicle <|-- Car"}
1352
1667
  \`\`\`
1353
- `, r = 3, i = 10 - n.length;
1668
+ `;
1669
+ deviationStart = 3;
1670
+ deviationEnd = 10 - targetValue.length;
1354
1671
  break;
1355
1672
  }
1356
1673
  case "state": {
1357
- n = `\`\`\`mermaid
1358
- ${(s == null ? void 0 : s.state) || `stateDiagram-v2
1359
- s1 --> s2`}
1674
+ targetValue = `\`\`\`mermaid
1675
+ ${(mermaidTemplate == null ? void 0 : mermaidTemplate.state) || "stateDiagram-v2\n s1 --> s2"}
1360
1676
  \`\`\`
1361
- `, r = 3, i = 10 - n.length;
1677
+ `;
1678
+ deviationStart = 3;
1679
+ deviationEnd = 10 - targetValue.length;
1362
1680
  break;
1363
1681
  }
1364
1682
  case "pie": {
1365
- n = `\`\`\`mermaid
1366
- ${(s == null ? void 0 : s.pie) || `pie title Pets adopted by volunteers
1367
- "Dogs" : 386
1368
- "Cats" : 85
1369
- "Rats" : 15`}
1683
+ targetValue = `\`\`\`mermaid
1684
+ ${(mermaidTemplate == null ? void 0 : mermaidTemplate.pie) || 'pie title Pets adopted by volunteers\n "Dogs" : 386\n "Cats" : 85\n "Rats" : 15'}
1370
1685
  \`\`\`
1371
- `, r = 3, i = 10 - n.length;
1686
+ `;
1687
+ deviationStart = 3;
1688
+ deviationEnd = 10 - targetValue.length;
1372
1689
  break;
1373
1690
  }
1374
1691
  case "relationship": {
1375
- n = `\`\`\`mermaid
1376
- ${(s == null ? void 0 : s.relationship) || `erDiagram
1377
- CAR ||--o{ NAMED-DRIVER : allows
1378
- PERSON ||--o{ NAMED-DRIVER : is`}
1692
+ targetValue = `\`\`\`mermaid
1693
+ ${(mermaidTemplate == null ? void 0 : mermaidTemplate.relationship) || "erDiagram\n CAR ||--o{ NAMED-DRIVER : allows\n PERSON ||--o{ NAMED-DRIVER : is"}
1379
1694
  \`\`\`
1380
- `, r = 3, i = 10 - n.length;
1695
+ `;
1696
+ deviationStart = 3;
1697
+ deviationEnd = 10 - targetValue.length;
1381
1698
  break;
1382
1699
  }
1383
1700
  case "journey": {
1384
- n = `\`\`\`mermaid
1385
- ${(s == null ? void 0 : s.journey) || `journey
1386
- title My working day
1387
- section Go to work
1388
- Make tea: 5: Me
1389
- Go upstairs: 3: Me
1390
- Do work: 1: Me, Cat
1391
- section Go home
1392
- Go downstairs: 5: Me
1393
- Sit down: 5: Me`}
1701
+ targetValue = `\`\`\`mermaid
1702
+ ${(mermaidTemplate == null ? void 0 : mermaidTemplate.journey) || "journey\n title My working day\n section Go to work\n Make tea: 5: Me\n Go upstairs: 3: Me\n Do work: 1: Me, Cat\n section Go home\n Go downstairs: 5: Me\n Sit down: 5: Me"}
1394
1703
  \`\`\`
1395
- `, r = 3, i = 10 - n.length;
1704
+ `;
1705
+ deviationStart = 3;
1706
+ deviationEnd = 10 - targetValue.length;
1396
1707
  break;
1397
1708
  }
1398
1709
  case "katexInline": {
1399
- n = "$$", r = 1, i = -1;
1710
+ targetValue = "$$";
1711
+ deviationStart = 1;
1712
+ deviationEnd = -1;
1400
1713
  break;
1401
1714
  }
1402
1715
  case "katexBlock": {
1403
- n = `$$
1404
-
1405
- $$
1406
- `, r = 3, i = -4;
1716
+ targetValue = "$$\n\n$$\n";
1717
+ deviationStart = 3;
1718
+ deviationEnd = -4;
1407
1719
  break;
1408
1720
  }
1409
1721
  case "universal": {
1410
- const { generate: u } = l, b = u(d);
1411
- n = b.targetValue, h = b.select ?? !0, r = b.deviationStart || 0, i = b.deviationEnd || 0;
1722
+ const { generate } = params;
1723
+ const insertOptions = generate(selectedText);
1724
+ targetValue = insertOptions.targetValue;
1725
+ select = insertOptions.select ?? true;
1726
+ deviationStart = insertOptions.deviationStart || 0;
1727
+ deviationEnd = insertOptions.deviationEnd || 0;
1412
1728
  }
1413
1729
  }
1730
+ }
1414
1731
  return {
1415
- text: n,
1732
+ text: targetValue,
1416
1733
  options: {
1417
1734
  // 是否选中
1418
- select: h,
1735
+ select,
1419
1736
  // 选中时,开始位置的偏移量
1420
- deviationStart: r,
1737
+ deviationStart,
1421
1738
  // 结束的偏移量
1422
- deviationEnd: i,
1739
+ deviationEnd,
1423
1740
  // 是否整个替换
1424
- replaceAll: f
1741
+ replaceAll
1425
1742
  }
1426
1743
  };
1427
- }, Gl = "#e5c07b", bt = "var(--md-color)", Kl = "#56b6c2", jl = "#ffffff", ie = "var(--md-color)", vt = "#e5c07b", Zl = "#e5c07b", Xl = "var(--md-color)", kt = "#d19a66", Yl = "#c678dd", Jl = "#21252b", Ql = "#2c313a", Ct = "var(--md-bk-color)", he = "var(--md-bk-color)", eo = "#ceedfa33", $t = "#528bff", to = pe.theme(
1744
+ };
1745
+ const chalky$1 = "#e5c07b", coral$1 = "var(--md-color)", cyan$1 = "#56b6c2", invalid$1 = "#ffffff", ivory$1 = "var(--md-color)", stone$1 = "#e5c07b", malibu$1 = "#e5c07b", sage$1 = "var(--md-color)", whiskey$1 = "#d19a66", violet$1 = "#c678dd", darkBackground$1 = "#21252b", highlightBackground$1 = "#2c313a", background$1 = "var(--md-bk-color)", tooltipBackground$1 = "var(--md-bk-color)", selection$1 = "#ceedfa33", cursor$1 = "#528bff";
1746
+ const oneDarkTheme = EditorView.theme(
1428
1747
  {
1429
1748
  "&": {
1430
- color: ie,
1431
- backgroundColor: Ct
1749
+ color: ivory$1,
1750
+ backgroundColor: background$1
1432
1751
  },
1433
1752
  ".cm-content": {
1434
- caretColor: $t
1753
+ caretColor: cursor$1
1435
1754
  },
1436
- ".cm-cursor, .cm-dropCursor": { borderLeftColor: $t },
1437
- "&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": { backgroundColor: eo },
1438
- ".cm-panels": { backgroundColor: Jl, color: ie },
1755
+ ".cm-cursor, .cm-dropCursor": { borderLeftColor: cursor$1 },
1756
+ "&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": { backgroundColor: selection$1 },
1757
+ ".cm-panels": { backgroundColor: darkBackground$1, color: ivory$1 },
1439
1758
  ".cm-panels.cm-panels-top": { borderBottom: "2px solid black" },
1440
1759
  ".cm-panels.cm-panels-bottom": { borderTop: "2px solid black" },
1441
1760
  ".cm-searchMatch": {
@@ -1451,13 +1770,13 @@ $$
1451
1770
  backgroundColor: "#bad0f847"
1452
1771
  },
1453
1772
  ".cm-gutters": {
1454
- backgroundColor: Ct,
1455
- color: ie,
1773
+ backgroundColor: background$1,
1774
+ color: ivory$1,
1456
1775
  borderRight: "1px solid",
1457
1776
  borderColor: "var(--md-border-color)"
1458
1777
  },
1459
1778
  ".cm-activeLineGutter": {
1460
- backgroundColor: Ql
1779
+ backgroundColor: highlightBackground$1
1461
1780
  },
1462
1781
  ".cm-foldPlaceholder": {
1463
1782
  backgroundColor: "transparent",
@@ -1466,78 +1785,82 @@ $$
1466
1785
  },
1467
1786
  ".cm-tooltip": {
1468
1787
  border: "1px solid var(--md-border-color)",
1469
- backgroundColor: he
1788
+ backgroundColor: tooltipBackground$1
1470
1789
  },
1471
1790
  ".cm-tooltip .cm-tooltip-arrow:before": {
1472
1791
  borderTopColor: "transparent",
1473
1792
  borderBottomColor: "transparent"
1474
1793
  },
1475
1794
  ".cm-tooltip .cm-tooltip-arrow:after": {
1476
- borderTopColor: he,
1477
- borderBottomColor: he
1795
+ borderTopColor: tooltipBackground$1,
1796
+ borderBottomColor: tooltipBackground$1
1478
1797
  },
1479
1798
  ".cm-tooltip-autocomplete": {
1480
1799
  "& > ul > li[aria-selected]": {
1481
- color: ie
1800
+ color: ivory$1
1482
1801
  }
1483
1802
  }
1484
1803
  },
1485
- { dark: !0 }
1486
- ), lo = Vt.define([
1487
- { tag: c.keyword, color: Yl },
1488
- { tag: [c.name, c.deleted, c.character, c.propertyName, c.macroName], color: bt },
1489
- { tag: [c.function(c.variableName), c.labelName], color: Zl },
1490
- { tag: [c.color, c.constant(c.name), c.standard(c.name)], color: kt },
1491
- { tag: [c.definition(c.name), c.separator], color: ie },
1804
+ { dark: true }
1805
+ );
1806
+ const oneDarkHighlightStyle = HighlightStyle.define([
1807
+ { tag: tags.keyword, color: violet$1 },
1808
+ { tag: [tags.name, tags.deleted, tags.character, tags.propertyName, tags.macroName], color: coral$1 },
1809
+ { tag: [tags.function(tags.variableName), tags.labelName], color: malibu$1 },
1810
+ { tag: [tags.color, tags.constant(tags.name), tags.standard(tags.name)], color: whiskey$1 },
1811
+ { tag: [tags.definition(tags.name), tags.separator], color: ivory$1 },
1492
1812
  {
1493
1813
  tag: [
1494
- c.typeName,
1495
- c.className,
1496
- c.number,
1497
- c.changed,
1498
- c.annotation,
1499
- c.modifier,
1500
- c.self,
1501
- c.namespace
1814
+ tags.typeName,
1815
+ tags.className,
1816
+ tags.number,
1817
+ tags.changed,
1818
+ tags.annotation,
1819
+ tags.modifier,
1820
+ tags.self,
1821
+ tags.namespace
1502
1822
  ],
1503
- color: Gl
1823
+ color: chalky$1
1504
1824
  },
1505
1825
  {
1506
1826
  tag: [
1507
- c.operator,
1508
- c.operatorKeyword,
1509
- c.url,
1510
- c.escape,
1511
- c.regexp,
1512
- c.link,
1513
- c.special(c.string)
1827
+ tags.operator,
1828
+ tags.operatorKeyword,
1829
+ tags.url,
1830
+ tags.escape,
1831
+ tags.regexp,
1832
+ tags.link,
1833
+ tags.special(tags.string)
1514
1834
  ],
1515
- color: Kl
1835
+ color: cyan$1
1516
1836
  },
1517
- { tag: [c.meta, c.comment], color: vt },
1518
- { tag: c.strong, fontWeight: "bold" },
1519
- { tag: c.emphasis, fontStyle: "italic" },
1520
- { tag: c.strikethrough, textDecoration: "line-through" },
1521
- { tag: c.link, color: vt, textDecoration: "underline" },
1522
- { tag: c.heading, fontWeight: "bold", color: bt },
1523
- { tag: [c.atom, c.bool, c.special(c.variableName)], color: kt },
1524
- { tag: [c.processingInstruction, c.string, c.inserted], color: Xl },
1525
- { tag: c.invalid, color: jl }
1526
- ]), pt = [
1527
- to,
1528
- Ft(lo)
1529
- ], oo = "#e5c07b", yt = "#3f4a54", ao = "#56b6c2", no = "#fff", re = "#3f4a54", Tt = "#2d8cf0", io = "#2d8cf0", ro = "#3f4a54", wt = "#d19a66", so = "#c678dd", co = "#21252b", uo = "#ceedfa33", xt = "var(--md-bk-color)", be = "var(--md-bk-color)", mo = "#bad5fa", St = "#3f4a54", go = pe.theme(
1837
+ { tag: [tags.meta, tags.comment], color: stone$1 },
1838
+ { tag: tags.strong, fontWeight: "bold" },
1839
+ { tag: tags.emphasis, fontStyle: "italic" },
1840
+ { tag: tags.strikethrough, textDecoration: "line-through" },
1841
+ { tag: tags.link, color: stone$1, textDecoration: "underline" },
1842
+ { tag: tags.heading, fontWeight: "bold", color: coral$1 },
1843
+ { tag: [tags.atom, tags.bool, tags.special(tags.variableName)], color: whiskey$1 },
1844
+ { tag: [tags.processingInstruction, tags.string, tags.inserted], color: sage$1 },
1845
+ { tag: tags.invalid, color: invalid$1 }
1846
+ ]);
1847
+ const oneDark = [
1848
+ oneDarkTheme,
1849
+ syntaxHighlighting(oneDarkHighlightStyle)
1850
+ ];
1851
+ const chalky = "#e5c07b", coral = "#3f4a54", cyan = "#56b6c2", invalid = "#fff", ivory = "#3f4a54", stone = "#2d8cf0", malibu = "#2d8cf0", sage = "#3f4a54", whiskey = "#d19a66", violet = "#c678dd", darkBackground = "#21252b", highlightBackground = "#ceedfa33", background = "var(--md-bk-color)", tooltipBackground = "var(--md-bk-color)", selection = "#bad5fa", cursor = "#3f4a54";
1852
+ const oneLightTheme = EditorView.theme(
1530
1853
  {
1531
1854
  "&": {
1532
- color: re,
1533
- backgroundColor: xt
1855
+ color: ivory,
1856
+ backgroundColor: background
1534
1857
  },
1535
1858
  ".cm-content": {
1536
- caretColor: St
1859
+ caretColor: cursor
1537
1860
  },
1538
- ".cm-cursor, .cm-dropCursor": { borderLeftColor: St },
1539
- "&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": { backgroundColor: mo },
1540
- ".cm-panels": { backgroundColor: co, color: re },
1861
+ ".cm-cursor, .cm-dropCursor": { borderLeftColor: cursor },
1862
+ "&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": { backgroundColor: selection },
1863
+ ".cm-panels": { backgroundColor: darkBackground, color: ivory },
1541
1864
  ".cm-panels.cm-panels-top": { borderBottom: "2px solid black" },
1542
1865
  ".cm-panels.cm-panels-bottom": { borderTop: "2px solid black" },
1543
1866
  ".cm-searchMatch": {
@@ -1553,13 +1876,13 @@ $$
1553
1876
  backgroundColor: "#bad0f847"
1554
1877
  },
1555
1878
  ".cm-gutters": {
1556
- backgroundColor: xt,
1557
- color: re,
1879
+ backgroundColor: background,
1880
+ color: ivory,
1558
1881
  borderRight: "1px solid",
1559
1882
  borderColor: "var(--md-border-color)"
1560
1883
  },
1561
1884
  ".cm-activeLineGutter": {
1562
- backgroundColor: uo
1885
+ backgroundColor: highlightBackground
1563
1886
  },
1564
1887
  ".cm-foldPlaceholder": {
1565
1888
  backgroundColor: "transparent",
@@ -1568,109 +1891,122 @@ $$
1568
1891
  },
1569
1892
  ".cm-tooltip": {
1570
1893
  border: "1px solid var(--md-border-color)",
1571
- backgroundColor: be
1894
+ backgroundColor: tooltipBackground
1572
1895
  },
1573
1896
  ".cm-tooltip .cm-tooltip-arrow:before": {
1574
1897
  borderTopColor: "transparent",
1575
1898
  borderBottomColor: "transparent"
1576
1899
  },
1577
1900
  ".cm-tooltip .cm-tooltip-arrow:after": {
1578
- borderTopColor: be,
1579
- borderBottomColor: be
1901
+ borderTopColor: tooltipBackground,
1902
+ borderBottomColor: tooltipBackground
1580
1903
  },
1581
1904
  ".cm-tooltip-autocomplete": {
1582
1905
  "& > ul > li[aria-selected]": {
1583
- color: re
1906
+ color: ivory
1584
1907
  }
1585
1908
  }
1586
1909
  }
1587
1910
  // { dark: true }
1588
- ), fo = Vt.define([
1589
- { tag: c.keyword, color: so },
1590
- { tag: [c.name, c.deleted, c.character, c.propertyName, c.macroName], color: yt },
1591
- { tag: [c.function(c.variableName), c.labelName], color: io },
1592
- { tag: [c.color, c.constant(c.name), c.standard(c.name)], color: wt },
1593
- { tag: [c.definition(c.name), c.separator], color: re },
1911
+ );
1912
+ const oneLightHighlightStyle = HighlightStyle.define([
1913
+ { tag: tags.keyword, color: violet },
1914
+ { tag: [tags.name, tags.deleted, tags.character, tags.propertyName, tags.macroName], color: coral },
1915
+ { tag: [tags.function(tags.variableName), tags.labelName], color: malibu },
1916
+ { tag: [tags.color, tags.constant(tags.name), tags.standard(tags.name)], color: whiskey },
1917
+ { tag: [tags.definition(tags.name), tags.separator], color: ivory },
1594
1918
  {
1595
1919
  tag: [
1596
- c.typeName,
1597
- c.className,
1598
- c.number,
1599
- c.changed,
1600
- c.annotation,
1601
- c.modifier,
1602
- c.self,
1603
- c.namespace
1920
+ tags.typeName,
1921
+ tags.className,
1922
+ tags.number,
1923
+ tags.changed,
1924
+ tags.annotation,
1925
+ tags.modifier,
1926
+ tags.self,
1927
+ tags.namespace
1604
1928
  ],
1605
- color: oo
1929
+ color: chalky
1606
1930
  },
1607
1931
  {
1608
1932
  tag: [
1609
- c.operator,
1610
- c.operatorKeyword,
1611
- c.url,
1612
- c.escape,
1613
- c.regexp,
1614
- c.link,
1615
- c.special(c.string)
1933
+ tags.operator,
1934
+ tags.operatorKeyword,
1935
+ tags.url,
1936
+ tags.escape,
1937
+ tags.regexp,
1938
+ tags.link,
1939
+ tags.special(tags.string)
1616
1940
  ],
1617
- color: ao
1941
+ color: cyan
1618
1942
  },
1619
- { tag: [c.meta, c.comment], color: Tt },
1620
- { tag: c.strong, fontWeight: "bold" },
1621
- { tag: c.emphasis, fontStyle: "italic" },
1622
- { tag: c.strikethrough, textDecoration: "line-through" },
1623
- { tag: c.link, color: Tt, textDecoration: "underline" },
1624
- { tag: c.heading, fontWeight: "bold", color: yt },
1625
- { tag: [c.atom, c.bool, c.special(c.variableName)], color: wt },
1626
- { tag: [c.processingInstruction, c.string, c.inserted], color: ro },
1627
- { tag: c.invalid, color: no }
1628
- ]), At = [
1629
- go,
1630
- Ft(fo)
1631
- ], ue = (e, o, l, n, r) => (i, h, f, d) => {
1632
- const s = `${e}${o}`.slice(d - f);
1633
- i.dispatch(i.state.replaceSelection(`${s}${l}${n}`));
1634
- const g = f + h.label.length + (r === "title" ? l.length : 0);
1635
- i.dispatch({
1636
- selection: U.create(
1637
- [
1638
- U.range(
1639
- f + h.label.length + (r === "title" ? 1 : -o.length),
1640
- g
1641
- ),
1642
- U.cursor(g)
1643
- ],
1644
- 1
1645
- )
1646
- }), i.focus();
1647
- }, Lt = (e) => (o, l, n, r) => {
1648
- const i = e.slice(r - n);
1649
- o.dispatch(o.state.replaceSelection(`${i} `));
1650
- }, It = (e) => {
1651
- const o = (l) => {
1652
- const n = l.matchBefore(
1943
+ { tag: [tags.meta, tags.comment], color: stone },
1944
+ { tag: tags.strong, fontWeight: "bold" },
1945
+ { tag: tags.emphasis, fontStyle: "italic" },
1946
+ { tag: tags.strikethrough, textDecoration: "line-through" },
1947
+ { tag: tags.link, color: stone, textDecoration: "underline" },
1948
+ { tag: tags.heading, fontWeight: "bold", color: coral },
1949
+ { tag: [tags.atom, tags.bool, tags.special(tags.variableName)], color: whiskey },
1950
+ { tag: [tags.processingInstruction, tags.string, tags.inserted], color: sage },
1951
+ { tag: tags.invalid, color: invalid }
1952
+ ]);
1953
+ const oneLight = [
1954
+ oneLightTheme,
1955
+ syntaxHighlighting(oneLightHighlightStyle)
1956
+ ];
1957
+ const getPairApply = (flag, type, title, suffix, selectType) => {
1958
+ return (view, _completion, from, to) => {
1959
+ const label = `${flag}${type}`.slice(to - from);
1960
+ view.dispatch(view.state.replaceSelection(`${label}${title}${suffix}`));
1961
+ const newTo = from + _completion.label.length + (selectType === "title" ? title.length : 0);
1962
+ view.dispatch({
1963
+ selection: EditorSelection.create(
1964
+ [
1965
+ EditorSelection.range(
1966
+ from + _completion.label.length + (selectType === "title" ? 1 : -type.length),
1967
+ newTo
1968
+ ),
1969
+ EditorSelection.cursor(newTo)
1970
+ ],
1971
+ 1
1972
+ )
1973
+ });
1974
+ view.focus();
1975
+ };
1976
+ };
1977
+ const getApply = (_label) => {
1978
+ return (view, _completion, from, to) => {
1979
+ const label = _label.slice(to - from);
1980
+ view.dispatch(view.state.replaceSelection(`${label} `));
1981
+ };
1982
+ };
1983
+ const createAutocompletion = (completions) => {
1984
+ const defaultCompletion = (context) => {
1985
+ const word = context.matchBefore(
1653
1986
  /^#+|^-\s*\[*\s*\]*|`+|\[|!\[*|^\|\s?\|?|^\$\$?|!+\s*\w*/
1654
1987
  );
1655
- return n === null || n.from == n.to && l.explicit ? null : {
1656
- from: n.from,
1988
+ if (word === null || word.from == word.to && context.explicit) {
1989
+ return null;
1990
+ }
1991
+ return {
1992
+ from: word.from,
1657
1993
  options: [
1658
1994
  // 标题
1659
- ...["h1", "h2", "h3", "h4", "h5", "h6"].map((r, i) => {
1660
- const h = new Array(i + 1).fill("#").join("");
1995
+ ...["h1", "h2", "h3", "h4", "h5", "h6"].map((key, index) => {
1996
+ const label = new Array(index + 1).fill("#").join("");
1661
1997
  return {
1662
- label: h,
1998
+ label,
1663
1999
  type: "text",
1664
- apply: Lt(h)
2000
+ apply: getApply(label)
1665
2001
  };
1666
2002
  }),
1667
2003
  // 任务列表
1668
- ...["unchecked", "checked"].map((r) => {
1669
- const i = r === "checked" ? "- [x]" : "- [ ]";
2004
+ ...["unchecked", "checked"].map((key) => {
2005
+ const label = key === "checked" ? "- [x]" : "- [ ]";
1670
2006
  return {
1671
- label: i,
2007
+ label,
1672
2008
  type: "text",
1673
- apply: Lt(i)
2009
+ apply: getApply(label)
1674
2010
  };
1675
2011
  }),
1676
2012
  // 代码
@@ -1678,11 +2014,13 @@ $$
1678
2014
  ["`", ""],
1679
2015
  ["```", "language"],
1680
2016
  ["```mermaid\n", ""]
1681
- ].map((r) => ({
1682
- label: `${r[0]}${r[1]}`,
1683
- type: "text",
1684
- apply: ue(r[0], r[1], "", r[0] === "`" ? "`" : "\n```", "type")
1685
- })),
2017
+ ].map((c) => {
2018
+ return {
2019
+ label: `${c[0]}${c[1]}`,
2020
+ type: "text",
2021
+ apply: getPairApply(c[0], c[1], "", c[0] === "`" ? "`" : "\n```", "type")
2022
+ };
2023
+ }),
1686
2024
  // 链接
1687
2025
  {
1688
2026
  label: "[]()",
@@ -1697,23 +2035,18 @@ $$
1697
2035
  label: "| |",
1698
2036
  type: "text",
1699
2037
  detail: "table",
1700
- apply: `| col | col | col |
1701
- | - | - | - |
1702
- | content | content | content |
1703
- | content | content | content |`
2038
+ apply: "| col | col | col |\n| - | - | - |\n| content | content | content |\n| content | content | content |"
1704
2039
  },
1705
2040
  // 公式
1706
2041
  {
1707
2042
  label: "$",
1708
2043
  type: "text",
1709
- apply: ue("$", "", "", "$", "type")
2044
+ apply: getPairApply("$", "", "", "$", "type")
1710
2045
  },
1711
2046
  {
1712
2047
  label: "$$",
1713
2048
  type: "text",
1714
- apply: ue("$$", "", `
1715
- `, `
1716
- $$`, "title")
2049
+ apply: getPairApply("$$", "", "\n", "\n$$", "title")
1717
2050
  },
1718
2051
  // 那啥?
1719
2052
  ...[
@@ -1733,40 +2066,52 @@ $$`, "title")
1733
2066
  "caution",
1734
2067
  "error",
1735
2068
  "attention"
1736
- ].map((r) => ({
1737
- label: `!!! ${r}`,
1738
- type: "text",
1739
- apply: ue("!!!", ` ${r}`, " Title", `
1740
-
1741
- !!!`, "title")
1742
- }))
2069
+ ].map((key) => {
2070
+ const label = `!!! ${key}`;
2071
+ return {
2072
+ label,
2073
+ type: "text",
2074
+ apply: getPairApply("!!!", ` ${key}`, " Title", "\n\n!!!", "title")
2075
+ };
2076
+ })
1743
2077
  ]
1744
2078
  };
1745
2079
  };
1746
- return gl({
1747
- override: e ? [o, ...e] : [o]
2080
+ return autocompletion({
2081
+ override: completions ? [defaultCompletion, ...completions] : [defaultCompletion]
1748
2082
  });
1749
- }, J = (e) => {
1750
- const o = new ne();
1751
- return (n) => (o.get(e.state) ? e.dispatch({ effects: o.reconfigure(n) }) : e.dispatch({
1752
- effects: nl.appendConfig.of(o.of(n))
1753
- }), !0);
1754
2083
  };
1755
- class ho {
1756
- constructor(o) {
1757
- z(this, "view");
1758
- z(this, "maxLength", Number.MAX_SAFE_INTEGER);
2084
+ const toggleWith = (view) => {
2085
+ const mc = new Compartment();
2086
+ const toggle = (extension) => {
2087
+ mc.get(view.state) ? view.dispatch({ effects: mc.reconfigure(extension) }) : view.dispatch({
2088
+ effects: StateEffect.appendConfig.of(mc.of(extension))
2089
+ });
2090
+ return true;
2091
+ };
2092
+ return toggle;
2093
+ };
2094
+ class CodeMirrorUt {
2095
+ constructor(view) {
2096
+ __publicField(this, "view");
2097
+ __publicField(this, "maxLength", Number.MAX_SAFE_INTEGER);
1759
2098
  // 切换tabSize的执行方法。切换时,Compartment实例需要相同
1760
- z(this, "toggleTabSize");
1761
- z(this, "togglePlaceholder");
2099
+ __publicField(this, "toggleTabSize");
2100
+ __publicField(this, "togglePlaceholder");
1762
2101
  /**
1763
2102
  * 设置全部的扩展
1764
2103
  */
1765
- z(this, "setExtensions");
1766
- z(this, "toggleDisabled");
1767
- z(this, "toggleReadOnly");
1768
- z(this, "toggleMaxlength");
1769
- this.view = o, this.toggleTabSize = J(this.view), this.togglePlaceholder = J(this.view), this.setExtensions = J(this.view), this.toggleDisabled = J(this.view), this.toggleReadOnly = J(this.view), this.toggleMaxlength = J(this.view);
2104
+ __publicField(this, "setExtensions");
2105
+ __publicField(this, "toggleDisabled");
2106
+ __publicField(this, "toggleReadOnly");
2107
+ __publicField(this, "toggleMaxlength");
2108
+ this.view = view;
2109
+ this.toggleTabSize = toggleWith(this.view);
2110
+ this.togglePlaceholder = toggleWith(this.view);
2111
+ this.setExtensions = toggleWith(this.view);
2112
+ this.toggleDisabled = toggleWith(this.view);
2113
+ this.toggleReadOnly = toggleWith(this.view);
2114
+ this.toggleMaxlength = toggleWith(this.view);
1770
2115
  }
1771
2116
  getValue() {
1772
2117
  return this.view.state.doc.toString();
@@ -1778,12 +2123,12 @@ class ho {
1778
2123
  * @param from 插入开始位置
1779
2124
  * @param to 插入结束位置
1780
2125
  */
1781
- setValue(o, l = 0, n = this.view.state.doc.length) {
2126
+ setValue(insert, from = 0, to = this.view.state.doc.length) {
1782
2127
  this.view.dispatch({
1783
2128
  changes: {
1784
- from: l,
1785
- to: n,
1786
- insert: o
2129
+ from,
2130
+ to,
2131
+ insert
1787
2132
  }
1788
2133
  });
1789
2134
  }
@@ -1791,8 +2136,8 @@ class ho {
1791
2136
  * 获取选中的文本
1792
2137
  */
1793
2138
  getSelectedText() {
1794
- const { from: o, to: l } = this.view.state.selection.main;
1795
- return this.view.state.sliceDoc(o, l);
2139
+ const { from, to } = this.view.state.selection.main;
2140
+ return this.view.state.sliceDoc(from, to);
1796
2141
  }
1797
2142
  /**
1798
2143
  * 使用新的内容替换选中的内容
@@ -1800,47 +2145,52 @@ class ho {
1800
2145
  * @param text 待替换内容
1801
2146
  * @param options 替换后是否选中
1802
2147
  */
1803
- replaceSelectedText(o, l = {
2148
+ replaceSelectedText(text, options = {
1804
2149
  // 是否选中
1805
- select: !0,
2150
+ select: true,
1806
2151
  // 选中时,开始位置的偏移量
1807
2152
  deviationStart: 0,
1808
2153
  // 结束的偏移量
1809
2154
  deviationEnd: 0,
1810
2155
  // 直接替换所有文本
1811
- replaceAll: !1
1812
- }, n) {
2156
+ replaceAll: false
2157
+ }, editorId) {
1813
2158
  try {
1814
- if (l.replaceAll) {
1815
- if (this.setValue(o), o.length > this.maxLength)
2159
+ if (options.replaceAll) {
2160
+ this.setValue(text);
2161
+ if (text.length > this.maxLength) {
1816
2162
  throw new Error("The input text is too long");
2163
+ }
1817
2164
  return;
1818
2165
  }
1819
- if (this.view.state.doc.length - this.getSelectedText().length + o.length > this.maxLength)
2166
+ if (this.view.state.doc.length - this.getSelectedText().length + text.length > this.maxLength) {
1820
2167
  throw new Error("The input text is too long");
1821
- const { from: r } = this.view.state.selection.main;
1822
- if (this.view.dispatch(this.view.state.replaceSelection(o)), l.select) {
1823
- const i = r + o.length + l.deviationEnd;
2168
+ }
2169
+ const { from } = this.view.state.selection.main;
2170
+ this.view.dispatch(this.view.state.replaceSelection(text));
2171
+ if (options.select) {
2172
+ const to = from + text.length + options.deviationEnd;
1824
2173
  this.view.dispatch({
1825
- selection: U.create(
2174
+ selection: EditorSelection.create(
1826
2175
  [
1827
- U.range(r + l.deviationStart, i),
1828
- U.cursor(i)
2176
+ EditorSelection.range(from + options.deviationStart, to),
2177
+ EditorSelection.cursor(to)
1829
2178
  ],
1830
2179
  1
1831
2180
  )
1832
2181
  });
1833
2182
  }
1834
2183
  this.view.focus();
1835
- } catch (r) {
1836
- if (r.message === "The input text is too long")
1837
- v.emit(n, ee, {
2184
+ } catch (e) {
2185
+ if (e.message === "The input text is too long") {
2186
+ bus.emit(editorId, ERROR_CATCHER, {
1838
2187
  name: "overlength",
1839
- message: r.message,
1840
- data: o
2188
+ message: e.message,
2189
+ data: text
1841
2190
  });
1842
- else
1843
- throw r;
2191
+ } else {
2192
+ throw e;
2193
+ }
1844
2194
  }
1845
2195
  }
1846
2196
  /**
@@ -1848,10 +2198,10 @@ class ho {
1848
2198
  *
1849
2199
  * @param tabSize 需要切换的大小
1850
2200
  */
1851
- setTabSize(o) {
2201
+ setTabSize(tabSize) {
1852
2202
  this.toggleTabSize([
1853
- fe.tabSize.of(o),
1854
- ml.of(" ".repeat(o))
2203
+ EditorState.tabSize.of(tabSize),
2204
+ indentUnit.of(" ".repeat(tabSize))
1855
2205
  ]);
1856
2206
  }
1857
2207
  /**
@@ -1859,428 +2209,666 @@ class ho {
1859
2209
  *
1860
2210
  * @param t 目标内容
1861
2211
  */
1862
- setPlaceholder(o) {
1863
- this.togglePlaceholder(tl(o));
2212
+ setPlaceholder(t) {
2213
+ this.togglePlaceholder(placeholder(t));
1864
2214
  }
1865
- focus(o) {
1866
- if (this.view.focus(), !o)
2215
+ focus(options) {
2216
+ this.view.focus();
2217
+ if (!options) {
1867
2218
  return;
1868
- let l = 0, n = 0, r = 0;
1869
- switch (o) {
1870
- case "start":
2219
+ }
2220
+ let anchor = 0;
2221
+ let head = 0;
2222
+ let pos = 0;
2223
+ switch (options) {
2224
+ case "start": {
1871
2225
  break;
2226
+ }
1872
2227
  case "end": {
1873
- l = n = r = this.getValue().length;
2228
+ const length = this.getValue().length;
2229
+ anchor = head = pos = length;
1874
2230
  break;
1875
2231
  }
1876
- default:
1877
- l = o.rangeAnchor || o.cursorPos, n = o.rangeHead || o.cursorPos, r = o.cursorPos;
2232
+ default: {
2233
+ anchor = options.rangeAnchor || options.cursorPos;
2234
+ head = options.rangeHead || options.cursorPos;
2235
+ pos = options.cursorPos;
2236
+ }
1878
2237
  }
1879
2238
  this.view.dispatch({
1880
- scrollIntoView: !0,
1881
- selection: U.create(
1882
- [U.range(l, n), U.cursor(r)],
2239
+ scrollIntoView: true,
2240
+ selection: EditorSelection.create(
2241
+ [EditorSelection.range(anchor, head), EditorSelection.cursor(pos)],
1883
2242
  1
1884
2243
  )
1885
2244
  });
1886
2245
  }
1887
- setDisabled(o) {
1888
- this.toggleDisabled([pe.editable.of(!o)]);
2246
+ setDisabled(d) {
2247
+ this.toggleDisabled([EditorView.editable.of(!d)]);
1889
2248
  }
1890
- setReadOnly(o) {
1891
- this.toggleReadOnly([fe.readOnly.of(o)]);
2249
+ setReadOnly(r) {
2250
+ this.toggleReadOnly([EditorState.readOnly.of(r)]);
1892
2251
  }
1893
- setMaxLength(o) {
1894
- this.maxLength = o, this.toggleMaxlength([
1895
- fe.changeFilter.of((l) => l.newDoc.length <= o)
2252
+ setMaxLength(ml) {
2253
+ this.maxLength = ml;
2254
+ this.toggleMaxlength([
2255
+ EditorState.changeFilter.of((tr) => {
2256
+ return tr.newDoc.length <= ml;
2257
+ })
1896
2258
  ]);
1897
2259
  }
1898
2260
  }
1899
- const bo = (e) => {
1900
- const o = I("editorId");
1901
- return (n) => {
1902
- if (!n.clipboardData)
2261
+ const usePasteUpload = (props2) => {
2262
+ const editorId = inject("editorId");
2263
+ const pasteHandler = (e) => {
2264
+ if (!e.clipboardData) {
1903
2265
  return;
1904
- if (n.clipboardData.files.length > 0) {
1905
- const { files: i } = n.clipboardData;
1906
- v.emit(
1907
- o,
1908
- $e,
1909
- Array.from(i).filter((h) => /image\/.*/.test(h.type))
1910
- ), n.preventDefault();
2266
+ }
2267
+ if (e.clipboardData.files.length > 0) {
2268
+ const { files } = e.clipboardData;
2269
+ bus.emit(
2270
+ editorId,
2271
+ UPLOAD_IMAGE,
2272
+ Array.from(files).filter((file) => {
2273
+ return /image\/.*/.test(file.type);
2274
+ })
2275
+ );
2276
+ e.preventDefault();
1911
2277
  return;
1912
2278
  }
1913
- if (e.autoDetectCode && n.clipboardData.types.includes("vscode-editor-data")) {
1914
- const i = JSON.parse(n.clipboardData.getData("vscode-editor-data"));
1915
- v.emit(o, L, "code", {
1916
- mode: i.mode,
1917
- text: n.clipboardData.getData("text/plain")
1918
- }), n.preventDefault();
2279
+ if (props2.autoDetectCode && e.clipboardData.types.includes("vscode-editor-data")) {
2280
+ const vscCoodInfo = JSON.parse(e.clipboardData.getData("vscode-editor-data"));
2281
+ bus.emit(editorId, REPLACE, "code", {
2282
+ mode: vscCoodInfo.mode,
2283
+ text: e.clipboardData.getData("text/plain")
2284
+ });
2285
+ e.preventDefault();
1919
2286
  return;
1920
2287
  }
1921
- const r = n.clipboardData.getData("text/plain");
1922
- e.maxlength && r.length + e.modelValue.length > e.maxlength && v.emit(o, ee, {
1923
- name: "overlength",
1924
- message: "The input text is too long",
1925
- data: r
1926
- });
2288
+ const targetValue = e.clipboardData.getData("text/plain");
2289
+ if (props2.maxlength && targetValue.length + props2.modelValue.length > props2.maxlength) {
2290
+ bus.emit(editorId, ERROR_CATCHER, {
2291
+ name: "overlength",
2292
+ message: "The input text is too long",
2293
+ data: targetValue
2294
+ });
2295
+ }
1927
2296
  };
1928
- }, vo = (e, o) => [
1929
- {
2297
+ return pasteHandler;
2298
+ };
2299
+ const createCommands = (id, contentProps2) => {
2300
+ const CtrlB = {
1930
2301
  key: "Ctrl-b",
1931
2302
  mac: "Cmd-b",
1932
- run: () => (v.emit(e, L, "bold"), !0)
1933
- },
1934
- {
1935
- key: "Ctrl-d",
1936
- mac: "Cmd-d",
1937
- run: il,
1938
- preventDefault: !0
1939
- },
1940
- {
2303
+ run: () => {
2304
+ bus.emit(id, REPLACE, "bold");
2305
+ return true;
2306
+ }
2307
+ };
2308
+ const CtrlS = {
1941
2309
  key: "Ctrl-s",
1942
2310
  mac: "Cmd-s",
1943
- run: (k) => (v.emit(e, Ht, k.state.doc.toString()), !0),
1944
- shift: () => (v.emit(e, L, "strikeThrough"), !0)
1945
- },
1946
- {
2311
+ run: (view) => {
2312
+ bus.emit(id, ON_SAVE, view.state.doc.toString());
2313
+ return true;
2314
+ },
2315
+ shift: () => {
2316
+ bus.emit(id, REPLACE, "strikeThrough");
2317
+ return true;
2318
+ }
2319
+ };
2320
+ const CtrlU = {
1947
2321
  key: "Ctrl-u",
1948
2322
  mac: "Cmd-u",
1949
- run: () => (v.emit(e, L, "underline"), !0),
1950
- shift: () => (v.emit(e, L, "unorderedList"), !0)
1951
- },
1952
- {
2323
+ run: () => {
2324
+ bus.emit(id, REPLACE, "underline");
2325
+ return true;
2326
+ },
2327
+ shift: () => {
2328
+ bus.emit(id, REPLACE, "unorderedList");
2329
+ return true;
2330
+ }
2331
+ };
2332
+ const CtrlI = {
1953
2333
  key: "Ctrl-i",
1954
2334
  mac: "Cmd-i",
1955
- run: () => (v.emit(e, L, "italic"), !0),
1956
- shift: () => (v.emit(e, ke, "image"), !0)
1957
- },
1958
- {
2335
+ run: () => {
2336
+ bus.emit(id, REPLACE, "italic");
2337
+ return true;
2338
+ },
2339
+ shift: () => {
2340
+ bus.emit(id, OPEN_MODALS, "image");
2341
+ return true;
2342
+ }
2343
+ };
2344
+ const Ctrl1 = {
1959
2345
  key: "Ctrl-1",
1960
2346
  mac: "Cmd-1",
1961
- run: () => (v.emit(e, L, "h1"), !0)
1962
- },
1963
- {
2347
+ run: () => {
2348
+ bus.emit(id, REPLACE, "h1");
2349
+ return true;
2350
+ }
2351
+ };
2352
+ const Ctrl2 = {
1964
2353
  key: "Ctrl-2",
1965
2354
  mac: "Cmd-2",
1966
- run: () => (v.emit(e, L, "h2"), !0)
1967
- },
1968
- {
2355
+ run: () => {
2356
+ bus.emit(id, REPLACE, "h2");
2357
+ return true;
2358
+ }
2359
+ };
2360
+ const Ctrl3 = {
1969
2361
  key: "Ctrl-3",
1970
2362
  mac: "Cmd-3",
1971
- run: () => (v.emit(e, L, "h3"), !0)
1972
- },
1973
- {
2363
+ run: () => {
2364
+ bus.emit(id, REPLACE, "h3");
2365
+ return true;
2366
+ }
2367
+ };
2368
+ const Ctrl4 = {
1974
2369
  key: "Ctrl-4",
1975
2370
  mac: "Cmd-4",
1976
- run: () => (v.emit(e, L, "h4"), !0)
1977
- },
1978
- {
2371
+ run: () => {
2372
+ bus.emit(id, REPLACE, "h4");
2373
+ return true;
2374
+ }
2375
+ };
2376
+ const Ctrl5 = {
1979
2377
  key: "Ctrl-5",
1980
2378
  mac: "Cmd-5",
1981
- run: () => (v.emit(e, L, "h5"), !0)
1982
- },
1983
- {
2379
+ run: () => {
2380
+ bus.emit(id, REPLACE, "h5");
2381
+ return true;
2382
+ }
2383
+ };
2384
+ const Ctrl6 = {
1984
2385
  key: "Ctrl-6",
1985
2386
  mac: "Cmd-6",
1986
- run: () => (v.emit(e, L, "h6"), !0)
1987
- },
1988
- {
2387
+ run: () => {
2388
+ bus.emit(id, REPLACE, "h6");
2389
+ return true;
2390
+ }
2391
+ };
2392
+ const CtrlArrowUp = {
1989
2393
  key: "Ctrl-ArrowUp",
1990
2394
  mac: "Cmd-ArrowUp",
1991
- run: () => (v.emit(e, L, "sup"), !0)
1992
- },
1993
- {
2395
+ run: () => {
2396
+ bus.emit(id, REPLACE, "sup");
2397
+ return true;
2398
+ }
2399
+ };
2400
+ const CtrlArrowDown = {
1994
2401
  key: "Ctrl-ArrowDown",
1995
2402
  mac: "Cmd-ArrowDown",
1996
- run: () => (v.emit(e, L, "sub"), !0)
1997
- },
1998
- {
2403
+ run: () => {
2404
+ bus.emit(id, REPLACE, "sub");
2405
+ return true;
2406
+ }
2407
+ };
2408
+ const CtrlO = {
1999
2409
  key: "Ctrl-o",
2000
2410
  mac: "Cmd-o",
2001
- run: () => (v.emit(e, L, "orderedList"), !0)
2002
- },
2003
- {
2411
+ run: () => {
2412
+ bus.emit(id, REPLACE, "orderedList");
2413
+ return true;
2414
+ }
2415
+ };
2416
+ const CtrlC = {
2004
2417
  key: "Ctrl-c",
2005
2418
  mac: "Cmd-c",
2006
- shift: () => (v.emit(e, L, "code"), !0),
2007
- any(k, A) {
2008
- return (A.ctrlKey || A.metaKey) && A.altKey && A.code === "KeyC" ? (v.emit(e, L, "codeRow"), !0) : !1;
2419
+ shift: () => {
2420
+ bus.emit(id, REPLACE, "code");
2421
+ return true;
2422
+ },
2423
+ any(_view, e) {
2424
+ if ((e.ctrlKey || e.metaKey) && e.altKey && e.code === "KeyC") {
2425
+ bus.emit(id, REPLACE, "codeRow");
2426
+ return true;
2427
+ }
2428
+ return false;
2009
2429
  }
2010
- },
2011
- {
2430
+ };
2431
+ const CtrlL = {
2012
2432
  key: "Ctrl-l",
2013
2433
  mac: "Cmd-l",
2014
- run: () => (v.emit(e, ke, "link"), !0)
2015
- },
2016
- {
2434
+ run: () => {
2435
+ bus.emit(id, OPEN_MODALS, "link");
2436
+ return true;
2437
+ }
2438
+ };
2439
+ const CtrlF = {
2017
2440
  key: "Ctrl-f",
2018
2441
  mac: "Cmd-f",
2019
- shift: () => o.noPrettier ? !1 : (v.emit(e, L, "prettier"), !0)
2020
- },
2021
- {
2022
- any: (k, A) => (A.ctrlKey || A.metaKey) && A.altKey && A.shiftKey && A.code === "KeyT" ? (v.emit(e, L, "table"), !0) : !1
2023
- }
2024
- ], ko = (e) => {
2025
- const o = I("tabWidth"), l = I("editorId"), n = I("theme"), r = O(), i = Wt(), h = new ne(), f = new ne(), d = new ne(), s = new ne(), g = vo(l, e), w = bo(e), $ = [
2026
- ll.of([...rl, ...sl, ...g, cl]),
2027
- s.of(ft()),
2028
- h.of(al({ codeLanguages: ol })),
2029
- // 横向换行
2030
- ce.lineWrapping,
2031
- ce.updateListener.of((m) => {
2032
- m.docChanged && e.onChange(m.state.doc.toString());
2033
- }),
2034
- ce.domEventHandlers({
2035
- paste: w,
2036
- blur: e.onBlur,
2037
- focus: e.onFocus,
2038
- drop: e.onDrop,
2039
- input: (m) => {
2040
- e.onInput && e.onInput(m);
2041
- const { data: C } = m;
2042
- e.maxlength && e.modelValue.length + C.length > e.maxlength && v.emit(l, ee, {
2442
+ shift: () => {
2443
+ if (!contentProps2.noPrettier) {
2444
+ bus.emit(id, REPLACE, "prettier");
2445
+ return true;
2446
+ }
2447
+ return false;
2448
+ }
2449
+ };
2450
+ const CtrlT = {
2451
+ any: (_view, e) => {
2452
+ if ((e.ctrlKey || e.metaKey) && e.altKey && e.shiftKey && e.code === "KeyT") {
2453
+ bus.emit(id, REPLACE, "table");
2454
+ return true;
2455
+ }
2456
+ return false;
2457
+ }
2458
+ };
2459
+ const CtrlD = {
2460
+ key: "Ctrl-d",
2461
+ mac: "Cmd-d",
2462
+ run: deleteLine,
2463
+ preventDefault: true
2464
+ };
2465
+ return [
2466
+ CtrlB,
2467
+ CtrlD,
2468
+ CtrlS,
2469
+ CtrlU,
2470
+ CtrlI,
2471
+ Ctrl1,
2472
+ Ctrl2,
2473
+ Ctrl3,
2474
+ Ctrl4,
2475
+ Ctrl5,
2476
+ Ctrl6,
2477
+ CtrlArrowUp,
2478
+ CtrlArrowDown,
2479
+ CtrlO,
2480
+ CtrlC,
2481
+ CtrlL,
2482
+ CtrlF,
2483
+ CtrlT
2484
+ ];
2485
+ };
2486
+ const useCodeMirror = (props2) => {
2487
+ const tabWidth = inject("tabWidth");
2488
+ const editorId = inject("editorId");
2489
+ const theme = inject("theme");
2490
+ const inputWrapperRef = ref();
2491
+ const codeMirrorUt = shallowRef();
2492
+ const languageComp = new Compartment(), themeComp = new Compartment(), autocompletionComp = new Compartment(), historyComp = new Compartment(), eventComp = new Compartment();
2493
+ const mdEditorCommands = createCommands(editorId, props2);
2494
+ const spelling = ref(false);
2495
+ const pasteHandler = usePasteUpload(props2);
2496
+ const domEventHandlers = {
2497
+ paste: pasteHandler,
2498
+ blur: props2.onBlur,
2499
+ focus: props2.onFocus,
2500
+ drop: props2.onDrop,
2501
+ compositionstart: () => {
2502
+ console.log("compositionstart");
2503
+ spelling.value = true;
2504
+ },
2505
+ compositionend: (_e, view) => {
2506
+ console.log("compositionend");
2507
+ spelling.value = false;
2508
+ props2.updateModelValue(view.state.doc.toString());
2509
+ },
2510
+ input: (e) => {
2511
+ if (props2.onInput) {
2512
+ props2.onInput(e);
2513
+ }
2514
+ const { data } = e;
2515
+ if (props2.maxlength && props2.modelValue.length + data.length > props2.maxlength) {
2516
+ bus.emit(editorId, ERROR_CATCHER, {
2043
2517
  name: "overlength",
2044
2518
  message: "The input text is too long",
2045
- data: C
2519
+ data
2046
2520
  });
2047
2521
  }
2048
- })
2049
- ], S = () => {
2050
- const m = [
2051
- ...$,
2052
- f.of(n.value === "light" ? At : pt),
2053
- d.of(It(e.completions))
2522
+ }
2523
+ };
2524
+ const defaultExtensions = [
2525
+ keymap.of([...defaultKeymap, ...historyKeymap, ...mdEditorCommands, indentWithTab]),
2526
+ historyComp.of(history()),
2527
+ languageComp.of(markdown({ codeLanguages: languages })),
2528
+ // 横向换行
2529
+ EditorView$1.lineWrapping,
2530
+ EditorView$1.updateListener.of((update) => {
2531
+ if (update.docChanged) {
2532
+ props2.onChange(update.state.doc.toString());
2533
+ if (!spelling.value) {
2534
+ props2.updateModelValue(update.state.doc.toString());
2535
+ }
2536
+ }
2537
+ }),
2538
+ eventComp.of(EditorView$1.domEventHandlers(domEventHandlers))
2539
+ ];
2540
+ const getExtensions = () => {
2541
+ const extensions = [
2542
+ ...defaultExtensions,
2543
+ themeComp.of(theme.value === "light" ? oneLight : oneDark),
2544
+ autocompletionComp.of(createAutocompletion(props2.completions))
2054
2545
  ];
2055
- return X.codeMirrorExtensions(n.value, m, [
2056
- ...g
2546
+ return configOption.codeMirrorExtensions(theme.value, extensions, [
2547
+ ...mdEditorCommands
2057
2548
  ]);
2058
2549
  };
2059
- return Y(() => {
2060
- const m = new ce({
2061
- doc: e.modelValue,
2062
- parent: r.value,
2063
- extensions: [S()]
2064
- }), C = new ho(m);
2065
- i.value = C, setTimeout(() => {
2066
- C.setTabSize(o), C.setDisabled(e.disabled), C.setReadOnly(e.readonly), e.placeholder && C.setPlaceholder(e.placeholder), typeof e.maxlength == "number" && C.setMaxLength(e.maxlength), e.autofocus && m.focus();
2067
- }, 0), v.on(l, {
2068
- name: Nt,
2550
+ onMounted(() => {
2551
+ const view = new EditorView$1({
2552
+ doc: props2.modelValue,
2553
+ parent: inputWrapperRef.value,
2554
+ extensions: [getExtensions()]
2555
+ });
2556
+ const nc = new CodeMirrorUt(view);
2557
+ codeMirrorUt.value = nc;
2558
+ setTimeout(() => {
2559
+ nc.setTabSize(tabWidth);
2560
+ nc.setDisabled(props2.disabled);
2561
+ nc.setReadOnly(props2.readonly);
2562
+ props2.placeholder && nc.setPlaceholder(props2.placeholder);
2563
+ typeof props2.maxlength === "number" && nc.setMaxLength(props2.maxlength);
2564
+ props2.autofocus && view.focus();
2565
+ }, 0);
2566
+ bus.on(editorId, {
2567
+ name: CTRL_Z,
2069
2568
  callback() {
2070
- ul(m);
2569
+ undo(view);
2071
2570
  }
2072
- }), v.on(l, {
2073
- name: Dt,
2571
+ });
2572
+ bus.on(editorId, {
2573
+ name: CTRL_SHIFT_Z,
2074
2574
  callback() {
2075
- dl(m);
2575
+ redo(view);
2576
+ }
2577
+ });
2578
+ bus.on(editorId, {
2579
+ name: REPLACE,
2580
+ callback(direct, params = {}) {
2581
+ var _a;
2582
+ const { text, options } = directive2flag(direct, codeMirrorUt.value, params);
2583
+ (_a = codeMirrorUt.value) == null ? void 0 : _a.replaceSelectedText(text, options, editorId);
2076
2584
  }
2077
- }), v.on(l, {
2078
- name: L,
2079
- callback(u, b = {}) {
2080
- var k;
2081
- const { text: p, options: y } = ql(u, i.value, b);
2082
- (k = i.value) == null || k.replaceSelectedText(p, y, l);
2585
+ });
2586
+ bus.on(editorId, {
2587
+ name: EVENT_LISTENER,
2588
+ callback(handlers) {
2589
+ var _a;
2590
+ const nextDomEventHandlers = {
2591
+ ...domEventHandlers
2592
+ };
2593
+ const defaultEventNames = Object.keys(domEventHandlers);
2594
+ for (const eventName in handlers) {
2595
+ const en = eventName;
2596
+ if (defaultEventNames.includes(en)) {
2597
+ nextDomEventHandlers[en] = (e, v) => {
2598
+ handlers[en](e, v);
2599
+ if (!e.defaultPrevented) {
2600
+ domEventHandlers[en](e, v);
2601
+ }
2602
+ };
2603
+ } else {
2604
+ nextDomEventHandlers[en] = handlers[en];
2605
+ }
2606
+ }
2607
+ (_a = codeMirrorUt.value) == null ? void 0 : _a.view.dispatch({
2608
+ effects: eventComp.reconfigure(
2609
+ EditorView$1.domEventHandlers(nextDomEventHandlers)
2610
+ )
2611
+ });
2083
2612
  }
2084
2613
  });
2085
- }), H(
2086
- n,
2614
+ });
2615
+ watch(
2616
+ theme,
2087
2617
  () => {
2088
- var m;
2089
- (m = i.value) == null || m.view.dispatch({
2090
- effects: f.reconfigure(n.value === "light" ? At : pt)
2618
+ var _a;
2619
+ (_a = codeMirrorUt.value) == null ? void 0 : _a.view.dispatch({
2620
+ effects: themeComp.reconfigure(theme.value === "light" ? oneLight : oneDark)
2091
2621
  });
2092
2622
  },
2093
2623
  {
2094
- deep: !0
2624
+ deep: true
2095
2625
  }
2096
- ), H(
2097
- () => e.completions,
2626
+ );
2627
+ watch(
2628
+ () => props2.completions,
2098
2629
  () => {
2099
- var m;
2100
- (m = i.value) == null || m.view.dispatch({
2101
- effects: d.reconfigure(It(e.completions))
2630
+ var _a;
2631
+ (_a = codeMirrorUt.value) == null ? void 0 : _a.view.dispatch({
2632
+ effects: autocompletionComp.reconfigure(createAutocompletion(props2.completions))
2102
2633
  });
2103
2634
  },
2104
2635
  {
2105
- deep: !0
2636
+ deep: true
2106
2637
  }
2107
- ), H(
2108
- () => e.modelValue,
2638
+ );
2639
+ watch(
2640
+ () => props2.modelValue,
2109
2641
  () => {
2110
- var m, C;
2111
- ((m = i.value) == null ? void 0 : m.getValue()) !== e.modelValue && ((C = i.value) == null || C.setValue(e.modelValue));
2642
+ var _a, _b;
2643
+ if (((_a = codeMirrorUt.value) == null ? void 0 : _a.getValue()) !== props2.modelValue) {
2644
+ (_b = codeMirrorUt.value) == null ? void 0 : _b.setValue(props2.modelValue);
2645
+ }
2112
2646
  }
2113
- ), H(
2114
- () => e.placeholder,
2647
+ );
2648
+ watch(
2649
+ () => props2.placeholder,
2115
2650
  () => {
2116
- var m;
2117
- (m = i.value) == null || m.setPlaceholder(e.placeholder);
2651
+ var _a;
2652
+ (_a = codeMirrorUt.value) == null ? void 0 : _a.setPlaceholder(props2.placeholder);
2118
2653
  }
2119
- ), H(
2120
- () => e.disabled,
2654
+ );
2655
+ watch(
2656
+ () => props2.disabled,
2121
2657
  () => {
2122
- var m;
2123
- (m = i.value) == null || m.setDisabled(e.disabled);
2658
+ var _a;
2659
+ (_a = codeMirrorUt.value) == null ? void 0 : _a.setDisabled(props2.disabled);
2124
2660
  }
2125
- ), H(
2126
- () => e.readonly,
2661
+ );
2662
+ watch(
2663
+ () => props2.readonly,
2127
2664
  () => {
2128
- var m;
2129
- (m = i.value) == null || m.setDisabled(e.readonly);
2665
+ var _a;
2666
+ (_a = codeMirrorUt.value) == null ? void 0 : _a.setDisabled(props2.readonly);
2130
2667
  }
2131
- ), H(
2132
- () => e.maxlength,
2668
+ );
2669
+ watch(
2670
+ () => props2.maxlength,
2133
2671
  () => {
2134
- var m;
2135
- e.maxlength && ((m = i.value) == null || m.setMaxLength(e.maxlength));
2672
+ var _a;
2673
+ if (props2.maxlength) {
2674
+ (_a = codeMirrorUt.value) == null ? void 0 : _a.setMaxLength(props2.maxlength);
2675
+ }
2136
2676
  }
2137
- ), {
2138
- inputWrapperRef: r,
2139
- codeMirrorUt: i,
2677
+ );
2678
+ return {
2679
+ inputWrapperRef,
2680
+ codeMirrorUt,
2140
2681
  resetHistory() {
2141
- var m, C;
2142
- (m = i.value) == null || m.view.dispatch({
2143
- effects: s.reconfigure([])
2144
- }), (C = i.value) == null || C.view.dispatch({
2145
- effects: s.reconfigure(ft())
2682
+ var _a, _b;
2683
+ (_a = codeMirrorUt.value) == null ? void 0 : _a.view.dispatch({
2684
+ effects: historyComp.reconfigure([])
2685
+ });
2686
+ (_b = codeMirrorUt.value) == null ? void 0 : _b.view.dispatch({
2687
+ effects: historyComp.reconfigure(history())
2146
2688
  });
2147
2689
  }
2148
2690
  };
2149
- }, Co = (e, o, l) => {
2150
- const n = _({
2151
- resizedWidth: e.inputBoxWitdh
2152
- }), r = _({
2153
- width: e.inputBoxWitdh
2154
- }), i = _({
2155
- left: e.inputBoxWitdh,
2691
+ };
2692
+ const useResize = (props2, contentRef, resizeRef) => {
2693
+ const state = reactive({
2694
+ resizedWidth: props2.inputBoxWitdh
2695
+ });
2696
+ const inputWrapperStyle = reactive({
2697
+ width: props2.inputBoxWitdh
2698
+ });
2699
+ const resizeOperateStyle = reactive({
2700
+ left: props2.inputBoxWitdh,
2156
2701
  display: "initial"
2157
- }), h = (s) => {
2158
- var m, C, u;
2159
- const g = ((m = o.value) == null ? void 0 : m.offsetWidth) || 0, w = ((C = o.value) == null ? void 0 : C.getBoundingClientRect().x) || 0;
2160
- let $ = s.x - w;
2161
- $ < se ? $ = se : $ > g - se && ($ = g - se);
2162
- const S = `${$}px`;
2163
- r.width = S, i.left = S, n.resizedWidth = S, (u = e.onInputBoxWitdhChange) == null || u.call(e, S);
2164
- }, f = () => {
2165
- document.addEventListener("mousemove", h);
2166
- }, d = () => {
2167
- document.removeEventListener("mousemove", h);
2702
+ });
2703
+ const resizeMousemove = (e) => {
2704
+ var _a, _b, _c;
2705
+ const maxWidth = ((_a = contentRef.value) == null ? void 0 : _a.offsetWidth) || 0;
2706
+ const contentX = ((_b = contentRef.value) == null ? void 0 : _b.getBoundingClientRect().x) || 0;
2707
+ let nextWidth = e.x - contentX;
2708
+ if (nextWidth < MinInputBoxWidth) {
2709
+ nextWidth = MinInputBoxWidth;
2710
+ } else if (nextWidth > maxWidth - MinInputBoxWidth) {
2711
+ nextWidth = maxWidth - MinInputBoxWidth;
2712
+ }
2713
+ const ibw = `${nextWidth}px`;
2714
+ inputWrapperStyle.width = ibw;
2715
+ resizeOperateStyle.left = ibw;
2716
+ state.resizedWidth = ibw;
2717
+ (_c = props2.onInputBoxWitdhChange) == null ? void 0 : _c.call(props2, ibw);
2168
2718
  };
2169
- return Y(() => {
2170
- var s;
2171
- (s = l.value) == null || s.addEventListener("mousedown", f), document.addEventListener("mouseup", d);
2172
- }), Et(() => {
2173
- var s, g;
2174
- (s = l.value) == null || s.removeEventListener("mousedown", f), (g = l.value) == null || g.removeEventListener("mouseup", d);
2175
- }), H(
2176
- () => e.inputBoxWitdh,
2177
- (s) => {
2178
- s && (r.width = s, i.left = s);
2179
- }
2180
- ), H(
2181
- [Q(e.setting, "htmlPreview"), Q(e.setting, "preview")],
2719
+ const resizeMousedown = () => {
2720
+ document.addEventListener("mousemove", resizeMousemove);
2721
+ };
2722
+ const resizeMouseup = () => {
2723
+ document.removeEventListener("mousemove", resizeMousemove);
2724
+ };
2725
+ onMounted(() => {
2726
+ var _a;
2727
+ (_a = resizeRef.value) == null ? void 0 : _a.addEventListener("mousedown", resizeMousedown);
2728
+ document.addEventListener("mouseup", resizeMouseup);
2729
+ });
2730
+ onBeforeUnmount(() => {
2731
+ var _a, _b;
2732
+ (_a = resizeRef.value) == null ? void 0 : _a.removeEventListener("mousedown", resizeMousedown);
2733
+ (_b = resizeRef.value) == null ? void 0 : _b.removeEventListener("mouseup", resizeMouseup);
2734
+ });
2735
+ watch(
2736
+ () => props2.inputBoxWitdh,
2737
+ (nVal) => {
2738
+ if (nVal) {
2739
+ inputWrapperStyle.width = nVal;
2740
+ resizeOperateStyle.left = nVal;
2741
+ }
2742
+ }
2743
+ );
2744
+ watch(
2745
+ [toRef(props2.setting, "htmlPreview"), toRef(props2.setting, "preview")],
2182
2746
  () => {
2183
- !e.setting.htmlPreview && !e.setting.preview ? (r.width = "100%", i.display = "none") : (r.width = n.resizedWidth, i.display = "initial");
2747
+ if (!props2.setting.htmlPreview && !props2.setting.preview) {
2748
+ inputWrapperStyle.width = "100%";
2749
+ resizeOperateStyle.display = "none";
2750
+ } else {
2751
+ inputWrapperStyle.width = state.resizedWidth;
2752
+ resizeOperateStyle.display = "initial";
2753
+ }
2184
2754
  },
2185
2755
  {
2186
- immediate: !0
2756
+ immediate: true
2187
2757
  }
2188
- ), { inputWrapperStyle: r, resizeOperateStyle: i };
2189
- }, $o = /* @__PURE__ */ P({
2758
+ );
2759
+ return { inputWrapperStyle, resizeOperateStyle };
2760
+ };
2761
+ const Content = /* @__PURE__ */ defineComponent({
2190
2762
  name: "MDEditorContent",
2191
- props: fl,
2192
- setup(e, o) {
2193
- const l = I("editorId"), n = O(""), r = O(), i = O(), {
2194
- inputWrapperRef: h,
2195
- codeMirrorUt: f,
2196
- resetHistory: d
2197
- } = ko(e), {
2198
- inputWrapperStyle: s,
2199
- resizeOperateStyle: g
2200
- } = Co(e, r, i);
2201
- return _l(e, n, f), o.expose({
2763
+ props: contentProps,
2764
+ setup(props2, ctx) {
2765
+ const editorId = inject("editorId");
2766
+ const html = ref("");
2767
+ const contentRef = ref();
2768
+ const resizeRef = ref();
2769
+ const {
2770
+ inputWrapperRef,
2771
+ codeMirrorUt,
2772
+ resetHistory
2773
+ } = useCodeMirror(props2);
2774
+ const {
2775
+ inputWrapperStyle,
2776
+ resizeOperateStyle
2777
+ } = useResize(props2, contentRef, resizeRef);
2778
+ useAutoScroll(props2, html, codeMirrorUt);
2779
+ ctx.expose({
2202
2780
  getSelectedText() {
2203
- var w;
2204
- return (w = f.value) == null ? void 0 : w.getSelectedText();
2205
- },
2206
- focus(w) {
2207
- var $;
2208
- ($ = f.value) == null || $.focus(w);
2781
+ var _a;
2782
+ return (_a = codeMirrorUt.value) == null ? void 0 : _a.getSelectedText();
2209
2783
  },
2210
- resetHistory: d
2211
- }), () => t("div", {
2212
- class: `${a}-content${e.setting.htmlPreview || e.setting.preview ? " has-preview" : ""}`,
2213
- ref: r
2214
- }, [t("div", {
2215
- class: `${a}-input-wrapper`,
2216
- style: s,
2217
- ref: h
2218
- }, null), (e.setting.htmlPreview || e.setting.preview) && t("div", {
2219
- class: `${a}-resize-operate`,
2220
- style: g,
2221
- ref: i
2222
- }, null), t(hl, {
2223
- modelValue: e.modelValue,
2224
- setting: e.setting,
2225
- onHtmlChanged: (w) => {
2226
- n.value = w, e.onHtmlChanged(w);
2784
+ focus(options) {
2785
+ var _a;
2786
+ (_a = codeMirrorUt.value) == null ? void 0 : _a.focus(options);
2227
2787
  },
2228
- onGetCatalog: e.onGetCatalog,
2229
- mdHeadingId: e.mdHeadingId,
2230
- noMermaid: e.noMermaid,
2231
- sanitize: e.sanitize,
2232
- noKatex: e.noKatex,
2233
- formatCopiedText: e.formatCopiedText,
2234
- noHighlight: e.noHighlight,
2235
- noImgZoomIn: e.noImgZoomIn,
2236
- sanitizeMermaid: e.sanitizeMermaid
2237
- }, null), e.catalogVisible && t(Rt, {
2238
- theme: e.theme,
2239
- class: `${a}-catalog-editor`,
2240
- editorId: l,
2241
- mdHeadingId: e.mdHeadingId,
2242
- key: "internal-catalog"
2243
- }, null)]);
2788
+ resetHistory
2789
+ });
2790
+ return () => {
2791
+ return createVNode("div", {
2792
+ "class": `${prefix}-content${props2.setting.htmlPreview || props2.setting.preview ? " has-preview" : ""}`,
2793
+ "ref": contentRef
2794
+ }, [createVNode("div", {
2795
+ "class": `${prefix}-input-wrapper`,
2796
+ "style": inputWrapperStyle,
2797
+ "ref": inputWrapperRef
2798
+ }, null), (props2.setting.htmlPreview || props2.setting.preview) && createVNode("div", {
2799
+ "class": `${prefix}-resize-operate`,
2800
+ "style": resizeOperateStyle,
2801
+ "ref": resizeRef
2802
+ }, null), createVNode(ContentPreview, {
2803
+ "modelValue": props2.modelValue,
2804
+ "setting": props2.setting,
2805
+ "onHtmlChanged": (html_) => {
2806
+ html.value = html_;
2807
+ props2.onHtmlChanged(html_);
2808
+ },
2809
+ "onGetCatalog": props2.onGetCatalog,
2810
+ "mdHeadingId": props2.mdHeadingId,
2811
+ "noMermaid": props2.noMermaid,
2812
+ "sanitize": props2.sanitize,
2813
+ "noKatex": props2.noKatex,
2814
+ "formatCopiedText": props2.formatCopiedText,
2815
+ "noHighlight": props2.noHighlight,
2816
+ "noImgZoomIn": props2.noImgZoomIn,
2817
+ "sanitizeMermaid": props2.sanitizeMermaid
2818
+ }, null), props2.catalogVisible && createVNode(MdCatalog, {
2819
+ "theme": props2.theme,
2820
+ "class": `${prefix}-catalog-editor`,
2821
+ "editorId": editorId,
2822
+ "mdHeadingId": props2.mdHeadingId,
2823
+ "key": "internal-catalog"
2824
+ }, null)]);
2825
+ };
2244
2826
  }
2245
- }), po = /* @__PURE__ */ P({
2827
+ });
2828
+ const MarkdownTotal = /* @__PURE__ */ defineComponent({
2246
2829
  props: {
2247
2830
  modelValue: {
2248
2831
  type: String,
2249
2832
  default: ""
2250
2833
  }
2251
2834
  },
2252
- setup(e) {
2253
- const o = I("usedLanguageText");
2835
+ setup(props2) {
2836
+ const ult = inject("usedLanguageText");
2254
2837
  return () => {
2255
- var l, n;
2256
- return t("div", {
2257
- class: `${a}-footer-item`
2258
- }, [t("label", {
2259
- class: `${a}-footer-label`
2260
- }, [`${(l = o.value.footer) == null ? void 0 : l.markdownTotal}:`]), t("span", null, [((n = e.modelValue) == null ? void 0 : n.length) || 0])]);
2838
+ var _a, _b;
2839
+ return createVNode("div", {
2840
+ "class": `${prefix}-footer-item`
2841
+ }, [createVNode("label", {
2842
+ "class": `${prefix}-footer-label`
2843
+ }, [`${(_a = ult.value.footer) == null ? void 0 : _a.markdownTotal}:`]), createVNode("span", null, [((_b = props2.modelValue) == null ? void 0 : _b.length) || 0])]);
2261
2844
  };
2262
2845
  }
2263
- }), yo = {
2846
+ });
2847
+ const props$2 = {
2264
2848
  checked: {
2265
2849
  type: Boolean,
2266
- default: !1
2850
+ default: false
2267
2851
  },
2268
2852
  onChange: {
2269
2853
  type: Function,
2270
2854
  default: () => {
2271
2855
  }
2272
2856
  }
2273
- }, To = /* @__PURE__ */ P({
2274
- props: yo,
2275
- setup(e) {
2276
- return () => t("div", {
2277
- class: [`${a}-checkbox`, e.checked && `${a}-checkbox-checked`],
2278
- onClick: () => {
2279
- e.onChange(!e.checked);
2280
- }
2281
- }, null);
2857
+ };
2858
+ const Checkbox = /* @__PURE__ */ defineComponent({
2859
+ props: props$2,
2860
+ setup(props2) {
2861
+ return () => {
2862
+ return createVNode("div", {
2863
+ "class": [`${prefix}-checkbox`, props2.checked && `${prefix}-checkbox-checked`],
2864
+ "onClick": () => {
2865
+ props2.onChange(!props2.checked);
2866
+ }
2867
+ }, null);
2868
+ };
2282
2869
  }
2283
- }), wo = {
2870
+ });
2871
+ const props$1 = {
2284
2872
  scrollAuto: {
2285
2873
  type: Boolean
2286
2874
  },
@@ -2289,26 +2877,28 @@ const bo = (e) => {
2289
2877
  default: () => {
2290
2878
  }
2291
2879
  }
2292
- }, xo = /* @__PURE__ */ P({
2293
- props: wo,
2294
- setup(e) {
2295
- const o = I("usedLanguageText");
2880
+ };
2881
+ const ScrollAuto = /* @__PURE__ */ defineComponent({
2882
+ props: props$1,
2883
+ setup(props2) {
2884
+ const ult = inject("usedLanguageText");
2296
2885
  return () => {
2297
- var l;
2298
- return t("div", {
2299
- class: `${a}-footer-item`
2300
- }, [t("label", {
2301
- class: `${a}-footer-label`,
2302
- onClick: () => {
2303
- e.onScrollAutoChange(!e.scrollAuto);
2886
+ var _a;
2887
+ return createVNode("div", {
2888
+ "class": `${prefix}-footer-item`
2889
+ }, [createVNode("label", {
2890
+ "class": `${prefix}-footer-label`,
2891
+ "onClick": () => {
2892
+ props2.onScrollAutoChange(!props2.scrollAuto);
2304
2893
  }
2305
- }, [(l = o.value.footer) == null ? void 0 : l.scrollAuto]), t(To, {
2306
- checked: e.scrollAuto,
2307
- onChange: e.onScrollAutoChange
2894
+ }, [(_a = ult.value.footer) == null ? void 0 : _a.scrollAuto]), createVNode(Checkbox, {
2895
+ "checked": props2.scrollAuto,
2896
+ "onChange": props2.onScrollAutoChange
2308
2897
  }, null)]);
2309
2898
  };
2310
2899
  }
2311
- }), So = {
2900
+ });
2901
+ const props = {
2312
2902
  modelValue: {
2313
2903
  type: String,
2314
2904
  default: ""
@@ -2328,141 +2918,194 @@ const bo = (e) => {
2328
2918
  defFooters: {
2329
2919
  type: Object
2330
2920
  }
2331
- }, Ao = /* @__PURE__ */ P({
2921
+ };
2922
+ const Footer = /* @__PURE__ */ defineComponent({
2332
2923
  name: "MDEditorFooter",
2333
- props: So,
2334
- setup(e) {
2335
- const o = Ce(() => {
2336
- const n = e.footers.indexOf("="), r = n === -1 ? e.footers : e.footers.slice(0, n), i = n === -1 ? [] : e.footers.slice(n, Number.MAX_SAFE_INTEGER);
2337
- return [r, i];
2338
- }), l = (n) => {
2339
- if (_t.includes(n))
2340
- switch (n) {
2341
- case "markdownTotal":
2342
- return t(po, {
2343
- modelValue: e.modelValue
2924
+ props,
2925
+ setup(props2) {
2926
+ const splitedItems = computed(() => {
2927
+ const moduleSplitIndex = props2.footers.indexOf("=");
2928
+ const barLeft = moduleSplitIndex === -1 ? props2.footers : props2.footers.slice(0, moduleSplitIndex);
2929
+ const barRight = moduleSplitIndex === -1 ? [] : props2.footers.slice(moduleSplitIndex, Number.MAX_SAFE_INTEGER);
2930
+ return [barLeft, barRight];
2931
+ });
2932
+ const footerRender = (name) => {
2933
+ if (allFooter.includes(name)) {
2934
+ switch (name) {
2935
+ case "markdownTotal": {
2936
+ return createVNode(MarkdownTotal, {
2937
+ "modelValue": props2.modelValue
2344
2938
  }, null);
2345
- case "scrollSwitch":
2346
- return t(xo, {
2347
- scrollAuto: e.scrollAuto,
2348
- onScrollAutoChange: e.onScrollAutoChange
2939
+ }
2940
+ case "scrollSwitch": {
2941
+ return createVNode(ScrollAuto, {
2942
+ "scrollAuto": props2.scrollAuto,
2943
+ "onScrollAutoChange": props2.onScrollAutoChange
2349
2944
  }, null);
2945
+ }
2350
2946
  }
2351
- else
2352
- return e.defFooters instanceof Array ? e.defFooters[n] || "" : e.defFooters && e.defFooters.children instanceof Array && e.defFooters.children[n] || "";
2947
+ } else if (props2.defFooters instanceof Array) {
2948
+ return props2.defFooters[name] || "";
2949
+ } else if (props2.defFooters && props2.defFooters.children instanceof Array) {
2950
+ return props2.defFooters.children[name] || "";
2951
+ } else {
2952
+ return "";
2953
+ }
2353
2954
  };
2354
2955
  return () => {
2355
- const n = o.value[0].map((i) => l(i)), r = o.value[1].map((i) => l(i));
2356
- return t("div", {
2357
- class: `${a}-footer`
2358
- }, [t("div", {
2359
- class: `${a}-footer-left`
2360
- }, [n]), t("div", {
2361
- class: `${a}-footer-right`
2362
- }, [r])]);
2956
+ const LeftFooter = splitedItems.value[0].map((name) => footerRender(name));
2957
+ const RightFooter = splitedItems.value[1].map((name) => footerRender(name));
2958
+ return createVNode("div", {
2959
+ "class": `${prefix}-footer`
2960
+ }, [createVNode("div", {
2961
+ "class": `${prefix}-footer-left`
2962
+ }, [LeftFooter]), createVNode("div", {
2963
+ "class": `${prefix}-footer-right`
2964
+ }, [RightFooter])]);
2363
2965
  };
2364
2966
  }
2365
- }), ve = /* @__PURE__ */ P({
2967
+ });
2968
+ const Editor = /* @__PURE__ */ defineComponent({
2366
2969
  name: "MdEditorV3",
2367
- props: bl,
2368
- emits: vl,
2369
- setup(e, o) {
2970
+ props: editorProps,
2971
+ emits: editorEmits,
2972
+ setup(props2, ctx) {
2370
2973
  const {
2371
- editorId: l,
2372
- noKatex: n,
2373
- noMermaid: r,
2374
- noPrettier: i,
2375
- noUploadImg: h,
2376
- noHighlight: f
2377
- } = e, d = _({
2378
- scrollAuto: e.scrollAuto
2379
- }), s = O();
2380
- kl(e, o), Cl(e), $l(e), pl(e, o);
2381
- const [g, w] = yl(e, o), $ = Tl(e);
2382
- return Et(() => {
2383
- v.clear(l);
2384
- }), wl(e, o, $, g, w, s), () => {
2385
- var C;
2386
- const S = ht({
2387
- props: e,
2388
- ctx: o
2389
- }, "defToolbars"), m = ht({
2390
- props: e,
2391
- ctx: o
2974
+ editorId,
2975
+ noKatex,
2976
+ noMermaid,
2977
+ noPrettier,
2978
+ noUploadImg,
2979
+ noHighlight
2980
+ } = props2;
2981
+ const state = reactive({
2982
+ scrollAuto: props2.scrollAuto
2983
+ });
2984
+ const codeRef = ref();
2985
+ useOnSave(props2, ctx);
2986
+ useProvide(props2);
2987
+ useExpansion(props2);
2988
+ useErrorCatcher(props2, ctx);
2989
+ const [setting, updateSetting] = useConfig(props2, ctx);
2990
+ const catalogVisible = useCatalog(props2);
2991
+ onBeforeUnmount(() => {
2992
+ bus.clear(editorId);
2993
+ });
2994
+ useExpose(props2, ctx, catalogVisible, setting, updateSetting, codeRef);
2995
+ return () => {
2996
+ var _a;
2997
+ const defToolbars = getSlot({
2998
+ props: props2,
2999
+ ctx
3000
+ }, "defToolbars");
3001
+ const defFooters = getSlot({
3002
+ props: props2,
3003
+ ctx
2392
3004
  }, "defFooters");
2393
- return t("div", {
2394
- id: l,
2395
- class: [a, e.class, e.theme === "dark" && `${a}-dark`, g.fullscreen || g.pageFullscreen ? `${a}-fullscreen` : ""],
2396
- style: e.style
2397
- }, [t(Pl, {
2398
- noPrettier: i,
2399
- toolbars: e.toolbars,
2400
- toolbarsExclude: e.toolbarsExclude,
2401
- setting: g,
2402
- updateSetting: w,
2403
- tableShape: e.tableShape,
2404
- defToolbars: S,
2405
- noUploadImg: h,
2406
- showToolbarName: e.showToolbarName
2407
- }, null), t($o, {
2408
- ref: s,
2409
- modelValue: e.modelValue,
2410
- setting: g,
2411
- mdHeadingId: e.mdHeadingId,
2412
- noMermaid: r,
2413
- noPrettier: i,
2414
- sanitize: e.sanitize,
2415
- placeholder: e.placeholder,
2416
- noKatex: n,
2417
- scrollAuto: d.scrollAuto,
2418
- formatCopiedText: e.formatCopiedText,
2419
- autofocus: e.autoFocus,
2420
- disabled: e.disabled,
2421
- readonly: e.readOnly,
2422
- maxlength: e.maxLength,
2423
- autoDetectCode: e.autoDetectCode,
2424
- noHighlight: f,
2425
- onChange: (u) => {
2426
- e.onChange && e.onChange(u), o.emit("update:modelValue", u), o.emit("onChange", u);
3005
+ return createVNode("div", {
3006
+ "id": editorId,
3007
+ "class": [prefix, props2.class, props2.theme === "dark" && `${prefix}-dark`, setting.fullscreen || setting.pageFullscreen ? `${prefix}-fullscreen` : ""],
3008
+ "style": props2.style
3009
+ }, [createVNode(ToolBar, {
3010
+ "noPrettier": noPrettier,
3011
+ "toolbars": props2.toolbars,
3012
+ "toolbarsExclude": props2.toolbarsExclude,
3013
+ "setting": setting,
3014
+ "updateSetting": updateSetting,
3015
+ "tableShape": props2.tableShape,
3016
+ "defToolbars": defToolbars,
3017
+ "noUploadImg": noUploadImg,
3018
+ "showToolbarName": props2.showToolbarName
3019
+ }, null), createVNode(Content, {
3020
+ "ref": codeRef,
3021
+ "modelValue": props2.modelValue,
3022
+ "setting": setting,
3023
+ "mdHeadingId": props2.mdHeadingId,
3024
+ "noMermaid": noMermaid,
3025
+ "noPrettier": noPrettier,
3026
+ "sanitize": props2.sanitize,
3027
+ "placeholder": props2.placeholder,
3028
+ "noKatex": noKatex,
3029
+ "scrollAuto": state.scrollAuto,
3030
+ "formatCopiedText": props2.formatCopiedText,
3031
+ "autofocus": props2.autoFocus,
3032
+ "disabled": props2.disabled,
3033
+ "readonly": props2.readOnly,
3034
+ "maxlength": props2.maxLength,
3035
+ "autoDetectCode": props2.autoDetectCode,
3036
+ "noHighlight": noHighlight,
3037
+ "updateModelValue": (value) => {
3038
+ ctx.emit("update:modelValue", value);
2427
3039
  },
2428
- onHtmlChanged: (u) => {
2429
- e.onHtmlChanged && e.onHtmlChanged(u), o.emit("onHtmlChanged", u);
3040
+ "onChange": (value) => {
3041
+ if (props2.onChange) {
3042
+ props2.onChange(value);
3043
+ }
3044
+ ctx.emit("onChange", value);
2430
3045
  },
2431
- onGetCatalog: (u) => {
2432
- e.onGetCatalog && e.onGetCatalog(u), o.emit("onGetCatalog", u);
3046
+ "onHtmlChanged": (html) => {
3047
+ if (props2.onHtmlChanged) {
3048
+ props2.onHtmlChanged(html);
3049
+ }
3050
+ ctx.emit("onHtmlChanged", html);
2433
3051
  },
2434
- onBlur: (u) => {
2435
- e.onBlur && e.onBlur(u), o.emit("onBlur", u);
3052
+ "onGetCatalog": (list) => {
3053
+ if (props2.onGetCatalog) {
3054
+ props2.onGetCatalog(list);
3055
+ }
3056
+ ctx.emit("onGetCatalog", list);
3057
+ },
3058
+ "onBlur": (e) => {
3059
+ if (props2.onBlur) {
3060
+ props2.onBlur(e);
3061
+ }
3062
+ ctx.emit("onBlur", e);
2436
3063
  },
2437
- onFocus: (u) => {
2438
- e.onFocus && e.onFocus(u), o.emit("onFocus", u);
3064
+ "onFocus": (e) => {
3065
+ if (props2.onFocus) {
3066
+ props2.onFocus(e);
3067
+ }
3068
+ ctx.emit("onFocus", e);
2439
3069
  },
2440
- onInput: (u) => {
2441
- e.onInput && e.onInput(u), o.emit("onInput", u);
3070
+ "onInput": (e) => {
3071
+ if (props2.onInput) {
3072
+ props2.onInput(e);
3073
+ }
3074
+ ctx.emit("onInput", e);
2442
3075
  },
2443
- completions: e.completions,
2444
- catalogVisible: $.value,
2445
- theme: e.theme,
2446
- noImgZoomIn: e.noImgZoomIn,
2447
- onDrop: (u) => {
2448
- e.onDrop && e.onDrop(u), o.emit("onDrop", u);
3076
+ "completions": props2.completions,
3077
+ "catalogVisible": catalogVisible.value,
3078
+ "theme": props2.theme,
3079
+ "noImgZoomIn": props2.noImgZoomIn,
3080
+ "onDrop": (e) => {
3081
+ if (props2.onDrop) {
3082
+ props2.onDrop(e);
3083
+ }
3084
+ ctx.emit("onDrop", e);
2449
3085
  },
2450
- inputBoxWitdh: e.inputBoxWitdh,
2451
- onInputBoxWitdhChange: (u) => {
2452
- e.onInputBoxWitdhChange && e.onInputBoxWitdhChange(u), o.emit("onInputBoxWitdhChange", u);
3086
+ "inputBoxWitdh": props2.inputBoxWitdh,
3087
+ "onInputBoxWitdhChange": (width) => {
3088
+ if (props2.onInputBoxWitdhChange) {
3089
+ props2.onInputBoxWitdhChange(width);
3090
+ }
3091
+ ctx.emit("onInputBoxWitdhChange", width);
2453
3092
  },
2454
- sanitizeMermaid: e.sanitizeMermaid
2455
- }, null), ((C = e.footers) == null ? void 0 : C.length) > 0 && t(Ao, {
2456
- modelValue: e.modelValue,
2457
- footers: e.footers,
2458
- defFooters: m,
2459
- scrollAuto: d.scrollAuto,
2460
- onScrollAutoChange: (u) => d.scrollAuto = u
3093
+ "sanitizeMermaid": props2.sanitizeMermaid
3094
+ }, null), ((_a = props2.footers) == null ? void 0 : _a.length) > 0 && createVNode(Footer, {
3095
+ "modelValue": props2.modelValue,
3096
+ "footers": props2.footers,
3097
+ "defFooters": defFooters,
3098
+ "scrollAuto": state.scrollAuto,
3099
+ "onScrollAutoChange": (v) => state.scrollAuto = v
2461
3100
  }, null)]);
2462
3101
  };
2463
3102
  }
2464
3103
  });
2465
- ve.install = (e) => (e.component(ve.name, ve), e.use(Sl).use(Xt).use(Al).use(Rt).use(xl), e);
3104
+ Editor.install = (app) => {
3105
+ app.component(Editor.name, Editor);
3106
+ app.use(NormalToolbar).use(DropdownToolbar).use(ModalToolbar).use(MdCatalog).use(MdPreview);
3107
+ return app;
3108
+ };
2466
3109
  export {
2467
- ve as default
3110
+ Editor as default
2468
3111
  };