md-editor-v3 4.0.4 → 4.1.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,11 @@
1
1
  import { inject as I, onMounted as C, watch as $, toRef as W, nextTick as A, shallowRef as R, ref as L, computed as M, defineComponent as Z, createVNode as H, Fragment as le, reactive as J, provide as F, onBeforeUnmount as ie } from "vue";
2
2
  import { p as g, a as S, m as ce, k as N, e as B, h as se, f as j, i as ue, g as O, j as U, l as de, b as me, d as fe } from "./config.mjs";
3
- import { u as he, g as pe, b } from "./index4.mjs";
3
+ import { u as he, g as pe, b as y } from "./index4.mjs";
4
4
  import { a as P, u as ge } from "./dom.mjs";
5
5
  import ve from "medium-zoom";
6
6
  import { debounce as X } from "@vavt/util";
7
- import be from "copy-to-clipboard";
8
- import ye from "markdown-it";
7
+ import ye from "copy-to-clipboard";
8
+ import be from "markdown-it";
9
9
  import we from "markdown-it-image-figures";
10
10
  import ke from "markdown-it-task-lists";
11
11
  import $e from "lru-cache";
@@ -27,7 +27,7 @@ const Q = "onSave", Y = "changeCatalogVisible", Ce = "changeFullscreen", V = "pa
27
27
  r.setAttribute("class", "copy-button"), r.dataset.tips = s, r.innerHTML = `<svg class="${g}-icon" aria-hidden="true"><use xlink:href="#${g}-icon-copy"></use></svg>`, r.addEventListener("click", () => {
28
28
  var k, v;
29
29
  clearTimeout(u);
30
- const w = i.querySelector("code").innerText, m = be(e.formatCopiedText(w)), p = ((k = t.value.copyCode) == null ? void 0 : k.successTips) || "已复制!", h = ((v = t.value.copyCode) == null ? void 0 : v.failTips) || "已复制!";
30
+ const w = i.querySelector("code").innerText, m = ye(e.formatCopiedText(w)), p = ((k = t.value.copyCode) == null ? void 0 : k.successTips) || "已复制!", h = ((v = t.value.copyCode) == null ? void 0 : v.failTips) || "已复制!";
31
31
  r.dataset.tips = m ? p : h, u = window.setTimeout(() => {
32
32
  r.dataset.tips = s;
33
33
  }, 1500);
@@ -99,7 +99,12 @@ const Q = "onSave", Y = "changeCatalogVisible", Ce = "changeFullscreen", V = "pa
99
99
  ).forEach(async (r) => {
100
100
  let d = c.get(r.innerText);
101
101
  if (!d) {
102
- const w = he(), p = await (n.value.renderAsync || n.value.render)(w, r.innerText);
102
+ const w = he(), m = n.value.renderAsync || n.value.render;
103
+ let p = "";
104
+ try {
105
+ p = await m(w, r.innerText);
106
+ } catch {
107
+ }
103
108
  d = typeof p == "string" ? p : p.svg, c.set(r.innerText, d);
104
109
  }
105
110
  const f = document.createElement("p");
@@ -205,23 +210,23 @@ const Q = "onSave", Y = "changeCatalogVisible", Ce = "changeFullscreen", V = "pa
205
210
  "code",
206
211
  "admonition",
207
212
  (r, d, f, w) => {
208
- let m, p, h, k = !1, v = r.bMarks[d] + r.tShift[d], y = r.eMarks[d];
213
+ let m, p, h, k = !1, v = r.bMarks[d] + r.tShift[d], b = r.eMarks[d];
209
214
  if (n !== r.src.charCodeAt(v))
210
215
  return !1;
211
- for (m = v + 1; m <= y && t[(m - v) % o] === r.src[m]; m++)
216
+ for (m = v + 1; m <= b && t[(m - v) % o] === r.src[m]; m++)
212
217
  ;
213
218
  const T = Math.floor((m - v) / o);
214
219
  if (T !== l)
215
220
  return !1;
216
221
  m -= (m - v) % o;
217
- const _ = r.src.slice(v, m), E = r.src.slice(m, y);
222
+ const _ = r.src.slice(v, m), E = r.src.slice(m, b);
218
223
  if (s(E), w)
219
224
  return !0;
220
- for (p = d; p++, !(p >= f || (v = r.bMarks[p] + r.tShift[p], y = r.eMarks[p], v < y && r.sCount[p] < r.blkIndent)); )
225
+ for (p = d; p++, !(p >= f || (v = r.bMarks[p] + r.tShift[p], b = r.eMarks[p], v < b && r.sCount[p] < r.blkIndent)); )
221
226
  if (n === r.src.charCodeAt(v) && !(r.sCount[p] - r.blkIndent >= 4)) {
222
- for (m = v + 1; m <= y && t[(m - v) % o] === r.src[m]; m++)
227
+ for (m = v + 1; m <= b && t[(m - v) % o] === r.src[m]; m++)
223
228
  ;
224
- if (!(Math.floor((m - v) / o) < T) && (m -= (m - v) % o, m = r.skipSpaces(m), !(m < y))) {
229
+ if (!(Math.floor((m - v) / o) < T) && (m -= (m - v) % o, m = r.skipSpaces(m), !(m < b))) {
225
230
  k = !0;
226
231
  break;
227
232
  }
@@ -266,10 +271,10 @@ const Q = "onSave", Y = "changeCatalogVisible", Ce = "changeFullscreen", V = "pa
266
271
  const [m, p] = c(s[r]);
267
272
  if (m === null)
268
273
  return l(s, r, d, f, w);
269
- let h, k, v, y, T = "", _ = "";
274
+ let h, k, v, b, T = "", _ = "";
270
275
  for (let E = r; E < s.length && (h = s[E], [k, v] = c(h), k === m); E++)
271
- h.info = h.info.replace(n, ""), h.hidden = !0, y = E - r > 0 ? "" : " checked", T += `<li><input type="radio" name="label-group-${a.editorId}-${r}"${y}><label for="group-${a.editorId}-${r}-tab-${E - r}" onclick="this.previousElementSibling.click()">${v || i(h)}</label></li>
272
- `, _ += `<input type="radio" id="group-${a.editorId}-${r}-tab-${E - r}" name="group-${a.editorId}-${r}"${y}>
276
+ h.info = h.info.replace(n, ""), h.hidden = !0, b = E - r > 0 ? "" : " checked", T += `<li><input type="radio" name="label-group-${a.editorId}-${r}"${b}><label for="group-${a.editorId}-${r}-tab-${E - r}" onclick="this.previousElementSibling.click()">${v || i(h)}</label></li>
277
+ `, _ += `<input type="radio" id="group-${a.editorId}-${r}-tab-${E - r}" name="group-${a.editorId}-${r}"${b}>
273
278
  ` + l(s, E, d, f, w);
274
279
  return `<div class="code-tabs">
275
280
  <ul>
@@ -299,23 +304,23 @@ const Q = "onSave", Y = "changeCatalogVisible", Ce = "changeFullscreen", V = "pa
299
304
  };
300
305
  });
301
306
  }, We = (e, a) => {
302
- const { editorConfig: l, markdownItConfig: t } = S, n = I("editorId"), o = I("showCodeRowNumber"), c = I("theme"), i = L([]), u = Fe(e), s = xe(e), { reRenderRef: r, replaceMermaid: d } = Me(e), f = ye({
307
+ const { editorConfig: l, markdownItConfig: t } = S, n = I("editorId"), o = I("showCodeRowNumber"), c = I("theme"), i = L([]), u = Fe(e), s = xe(e), { reRenderRef: r, replaceMermaid: d } = Me(e), f = be({
303
308
  html: !0,
304
309
  breaks: !0
305
310
  });
306
311
  t(f), f.use(Oe, { katexRef: s }), f.use(we, { figcaption: !0 }), f.use(Ve), f.use(ke), f.use(De, { mdHeadingId: e.mdHeadingId, headsRef: i }), f.use(Ke, { editorId: n }), e.noMermaid || f.use(Le, { themeRef: c }), f.set({
307
312
  highlight: (k, v) => {
308
- let y;
309
- !e.noHighlight && u.value ? u.value.getLanguage(v) ? y = u.value.highlight(k, {
313
+ let b;
314
+ !e.noHighlight && u.value ? u.value.getLanguage(v) ? b = u.value.highlight(k, {
310
315
  language: v,
311
316
  ignoreIllegals: !0
312
- }).value : y = u.value.highlightAuto(k).value : y = f.utils.escapeHtml(k);
313
- const T = o ? pe(y.trim()) : `<span class="code-block">${y.trim()}</span>`;
317
+ }).value : b = u.value.highlightAuto(k).value : b = f.utils.escapeHtml(k);
318
+ const T = o ? pe(b.trim()) : `<span class="code-block">${b.trim()}</span>`;
314
319
  return `<pre><code class="language-${v}" language=${v}>${T}</code></pre>`;
315
320
  }
316
321
  }), qe(f);
317
322
  const w = L(e.sanitize(f.render(e.modelValue))), m = () => {
318
- b.emit(n, "buildFinished", w.value), e.onHtmlChanged(w.value), e.onGetCatalog(i.value), b.emit(n, "catalogChanged", i.value), d();
323
+ y.emit(n, "buildFinished", w.value), e.onHtmlChanged(w.value), e.onGetCatalog(i.value), y.emit(n, "catalogChanged", i.value), d();
319
324
  };
320
325
  C(m);
321
326
  const p = X(
@@ -325,10 +330,10 @@ const Q = "onSave", Y = "changeCatalogVisible", Ce = "changeFullscreen", V = "pa
325
330
  (l == null ? void 0 : l.renderDelay) !== void 0 ? l == null ? void 0 : l.renderDelay : a ? 0 : 500
326
331
  ), h = M(() => (e.noKatex || s.value) && (e.noHighlight || u.value));
327
332
  return $([W(e, "modelValue"), h, r], p), C(() => {
328
- b.on(n, {
333
+ y.on(n, {
329
334
  name: "pushCatalog",
330
335
  callback() {
331
- b.emit(n, "catalogChanged", i.value);
336
+ y.emit(n, "catalogChanged", i.value);
332
337
  }
333
338
  });
334
339
  }), { html: w };
@@ -418,12 +423,12 @@ const Q = "onSave", Y = "changeCatalogVisible", Ce = "changeFullscreen", V = "pa
418
423
  t.buildFinished = !1;
419
424
  }
420
425
  ), C(() => {
421
- b.on(l, {
426
+ y.on(l, {
422
427
  name: "buildFinished",
423
428
  callback(n) {
424
429
  t.buildFinished = !0, t.html = n;
425
430
  }
426
- }), b.on(l, {
431
+ }), y.on(l, {
427
432
  name: Q,
428
433
  callback() {
429
434
  const n = new Promise((o) => {
@@ -431,9 +436,9 @@ const Q = "onSave", Y = "changeCatalogVisible", Ce = "changeFullscreen", V = "pa
431
436
  o(t.html);
432
437
  else {
433
438
  const c = (i) => {
434
- o(i), b.remove(l, "buildFinished", c);
439
+ o(i), y.remove(l, "buildFinished", c);
435
440
  };
436
- b.on(l, {
441
+ y.on(l, {
437
442
  name: "buildFinished",
438
443
  callback: c
439
444
  });
@@ -486,11 +491,11 @@ const Q = "onSave", Y = "changeCatalogVisible", Ce = "changeFullscreen", V = "pa
486
491
  var i, u, s, r, d, f;
487
492
  const { noPrettier: a, noUploadImg: l } = e, { editorExtensions: t } = S, n = a || !!((u = (i = S.editorExtensions) == null ? void 0 : i.prettier) != null && u.prettierInstance), o = a || !!((r = (s = S.editorExtensions) == null ? void 0 : s.prettier) != null && r.parserMarkdownInstance), c = l || !!((f = (d = S.editorExtensions) == null ? void 0 : d.cropper) != null && f.instance);
488
493
  C(() => {
489
- var k, v, y, T;
494
+ var k, v, b, T;
490
495
  const w = document.createElement("script"), m = document.createElement("script");
491
496
  w.src = ((k = t == null ? void 0 : t.prettier) == null ? void 0 : k.standaloneJs) || O.main, w.id = `${g}-prettier`, m.src = ((v = t == null ? void 0 : t.prettier) == null ? void 0 : v.parserMarkdownJs) || O.markdown, m.id = `${g}-prettierMD`;
492
497
  const p = document.createElement("link");
493
- p.rel = "stylesheet", p.href = ((y = t == null ? void 0 : t.cropper) == null ? void 0 : y.css) || U.css, p.id = `${g}-cropperCss`;
498
+ p.rel = "stylesheet", p.href = ((b = t == null ? void 0 : t.cropper) == null ? void 0 : b.css) || U.css, p.id = `${g}-cropperCss`;
494
499
  const h = document.createElement("script");
495
500
  h.src = ((T = t == null ? void 0 : t.cropper) == null ? void 0 : T.js) || U.js, h.id = `${g}-cropper`, c || (P(p), P(h)), n || P(w), o || P(m);
496
501
  }), te(e);
@@ -508,11 +513,11 @@ const Q = "onSave", Y = "changeCatalogVisible", Ce = "changeFullscreen", V = "pa
508
513
  t.pageFullscreen || t.fullscreen ? document.body.style.overflow = "hidden" : document.body.style.overflow = o;
509
514
  };
510
515
  return $(() => [t.pageFullscreen, t.fullscreen], c), C(() => {
511
- b.on(l, {
516
+ y.on(l, {
512
517
  name: "uploadImage",
513
518
  callback(i, u) {
514
519
  const s = (r) => {
515
- b.emit(l, "replace", "image", {
520
+ y.emit(l, "replace", "image", {
516
521
  desc: "",
517
522
  urls: r
518
523
  }), u && u();
@@ -524,7 +529,7 @@ const Q = "onSave", Y = "changeCatalogVisible", Ce = "changeFullscreen", V = "pa
524
529
  }, pt = (e) => {
525
530
  const { editorId: a } = e, l = L(!1);
526
531
  return C(() => {
527
- b.on(a, {
532
+ y.on(a, {
528
533
  name: Y,
529
534
  callback: (n) => {
530
535
  n === void 0 ? l.value = !l.value : l.value = n;
@@ -536,31 +541,31 @@ const Q = "onSave", Y = "changeCatalogVisible", Ce = "changeFullscreen", V = "pa
536
541
  $(
537
542
  () => t.pageFullscreen,
538
543
  (i) => {
539
- b.emit(o, V, i);
544
+ y.emit(o, V, i);
540
545
  }
541
546
  ), $(
542
547
  () => t.fullscreen,
543
548
  (i) => {
544
- b.emit(o, G, i);
549
+ y.emit(o, G, i);
545
550
  }
546
551
  ), $(
547
552
  () => t.preview,
548
553
  (i) => {
549
- b.emit(o, D, i);
554
+ y.emit(o, D, i);
550
555
  }
551
556
  ), $(
552
557
  () => t.htmlPreview,
553
558
  (i) => {
554
- b.emit(o, z, i);
559
+ y.emit(o, z, i);
555
560
  }
556
561
  ), $(l, (i) => {
557
- b.emit(o, K, i);
562
+ y.emit(o, K, i);
558
563
  });
559
564
  const c = {
560
565
  on(i, u) {
561
566
  switch (i) {
562
567
  case "pageFullscreen": {
563
- b.on(o, {
568
+ y.on(o, {
564
569
  name: V,
565
570
  callback(s) {
566
571
  u(s);
@@ -569,7 +574,7 @@ const Q = "onSave", Y = "changeCatalogVisible", Ce = "changeFullscreen", V = "pa
569
574
  break;
570
575
  }
571
576
  case "fullscreen": {
572
- b.on(o, {
577
+ y.on(o, {
573
578
  name: G,
574
579
  callback(s) {
575
580
  u(s);
@@ -578,7 +583,7 @@ const Q = "onSave", Y = "changeCatalogVisible", Ce = "changeFullscreen", V = "pa
578
583
  break;
579
584
  }
580
585
  case "preview": {
581
- b.on(o, {
586
+ y.on(o, {
582
587
  name: D,
583
588
  callback(s) {
584
589
  u(s);
@@ -587,7 +592,7 @@ const Q = "onSave", Y = "changeCatalogVisible", Ce = "changeFullscreen", V = "pa
587
592
  break;
588
593
  }
589
594
  case "htmlPreview": {
590
- b.on(o, {
595
+ y.on(o, {
591
596
  name: z,
592
597
  callback(s) {
593
598
  u(s);
@@ -596,7 +601,7 @@ const Q = "onSave", Y = "changeCatalogVisible", Ce = "changeFullscreen", V = "pa
596
601
  break;
597
602
  }
598
603
  case "catalog": {
599
- b.on(o, {
604
+ y.on(o, {
600
605
  name: K,
601
606
  callback(s) {
602
607
  u(s);
@@ -610,7 +615,7 @@ const Q = "onSave", Y = "changeCatalogVisible", Ce = "changeFullscreen", V = "pa
610
615
  n("pageFullscreen", i);
611
616
  },
612
617
  toggleFullscreen(i) {
613
- b.emit(o, Ce, i);
618
+ y.emit(o, Ce, i);
614
619
  },
615
620
  togglePreview(i) {
616
621
  n("preview", i);
@@ -619,16 +624,16 @@ const Q = "onSave", Y = "changeCatalogVisible", Ce = "changeFullscreen", V = "pa
619
624
  n("htmlPreview", i);
620
625
  },
621
626
  toggleCatalog(i) {
622
- b.emit(o, Y, i);
627
+ y.emit(o, Y, i);
623
628
  },
624
629
  triggerSave() {
625
- b.emit(o, Q);
630
+ y.emit(o, Q);
626
631
  },
627
632
  insert(i) {
628
- b.emit(o, "replace", "universal", { generate: i });
633
+ y.emit(o, "replace", "universal", { generate: i });
629
634
  },
630
635
  focus() {
631
- b.emit(o, Se);
636
+ y.emit(o, Se);
632
637
  }
633
638
  };
634
639
  a.expose(c);
@@ -1006,8 +1011,21 @@ const Q = "onSave", Y = "changeCatalogVisible", Ce = "changeFullscreen", V = "pa
1006
1011
  */
1007
1012
  onFocus: {
1008
1013
  type: Function
1014
+ },
1015
+ /**
1016
+ * @codemirror/autocomplete匹配关键词的方法列表
1017
+ *
1018
+ * 它会被像下面这样嵌入编辑器
1019
+ *
1020
+ * import { autocompletion } from '@codemirror/autocomplete';
1021
+ * autocompletion({
1022
+ * override: [...completions]
1023
+ * })
1024
+ */
1025
+ completions: {
1026
+ type: Array
1009
1027
  }
1010
- }, re = ["onHtmlChanged", "onGetCatalog"], bt = [
1028
+ }, re = ["onHtmlChanged", "onGetCatalog"], yt = [
1011
1029
  ...re,
1012
1030
  "onChange",
1013
1031
  "onSave",
@@ -1028,7 +1046,7 @@ const Q = "onSave", Y = "changeCatalogVisible", Ce = "changeFullscreen", V = "pa
1028
1046
  noHighlight: o
1029
1047
  } = e;
1030
1048
  return ee(e), te(e), ie(() => {
1031
- b.clear(l);
1049
+ y.clear(l);
1032
1050
  }), () => H("div", {
1033
1051
  id: l,
1034
1052
  class: [g, e.class, e.theme === "dark" && `${g}-dark`, `${g}-previewOnly`],
@@ -1059,7 +1077,7 @@ export {
1059
1077
  Se as T,
1060
1078
  Y as a,
1061
1079
  Xe as b,
1062
- bt as c,
1080
+ yt as c,
1063
1081
  mt as d,
1064
1082
  vt as e,
1065
1083
  ft as f,
package/lib/es/index.mjs CHANGED
@@ -1,10 +1,10 @@
1
- import { default as D } from "./MdEditor.mjs";
2
- import { M as C } from "./chunks/index.mjs";
3
- import { default as N } from "./NormalToolbar.mjs";
4
- import { D as h } from "./chunks/index2.mjs";
5
- import { M as k } from "./chunks/index3.mjs";
6
- import { default as y } from "./MdCatalog.mjs";
7
- import { c as A } from "./chunks/config.mjs";
1
+ import { default as v } from "./MdEditor.mjs";
2
+ import { M as E } from "./chunks/index.mjs";
3
+ import { default as P } from "./NormalToolbar.mjs";
4
+ import { D as j } from "./chunks/index2.mjs";
5
+ import { M as q } from "./chunks/index3.mjs";
6
+ import { default as z } from "./MdCatalog.mjs";
7
+ import { c as B } from "./chunks/config.mjs";
8
8
  import "vue";
9
9
  import "./chunks/index4.mjs";
10
10
  import "@vavt/util";
@@ -17,6 +17,7 @@ import "@codemirror/commands";
17
17
  import "@codemirror/language";
18
18
  import "@lezer/highlight";
19
19
  import "@codemirror/state";
20
+ import "@codemirror/autocomplete";
20
21
  import "./chunks/vue-tsx.mjs";
21
22
  import "medium-zoom";
22
23
  import "copy-to-clipboard";
@@ -25,11 +26,11 @@ import "markdown-it-image-figures";
25
26
  import "markdown-it-task-lists";
26
27
  import "lru-cache";
27
28
  export {
28
- h as DropdownToolbar,
29
- y as MdCatalog,
30
- D as MdEditor,
31
- C as MdPreview,
32
- k as ModalToolbar,
33
- N as NormalToolbar,
34
- A as config
29
+ j as DropdownToolbar,
30
+ z as MdCatalog,
31
+ v as MdEditor,
32
+ E as MdPreview,
33
+ q as ModalToolbar,
34
+ P as NormalToolbar,
35
+ B as config
35
36
  };