md-editor-v3 2.0.0-beta.9 → 2.0.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.
@@ -17,19 +17,20 @@ var __spreadValues = (a, b) => {
17
17
  return a;
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- import { onMounted, onBeforeUnmount, provide, computed, defineComponent, createVNode, reactive, ref, watch, cloneVNode, nextTick, inject, Fragment, toRef, isVNode } from "vue";
20
+ import { onMounted, onBeforeUnmount, provide, computed, reactive, watch, ref, defineComponent, createVNode, cloneVNode, nextTick, inject, Fragment, toRef, isVNode } from "vue";
21
21
  const prefix = "md";
22
22
  const iconfontUrl = "https://at.alicdn.com/t/font_2605852_pqekijay2ij.js";
23
- const highlightUrl = "https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.2.0/build/highlight.min.js";
23
+ const cdnBase = "https://cdnjs.cloudflare.com/ajax/libs";
24
+ const highlightUrl = `${cdnBase}/highlight.js/11.5.1/highlight.min.js`;
24
25
  const prettierUrl = {
25
- main: "https://cdn.jsdelivr.net/npm/prettier@2.4.0/standalone.js",
26
- markdown: "https://cdn.jsdelivr.net/npm/prettier@2.4.0/parser-markdown.js"
26
+ main: `${cdnBase}/prettier/2.4.0/standalone.js`,
27
+ markdown: `${cdnBase}/prettier/2.4.0/parser-markdown.js`
27
28
  };
28
29
  const cropperUrl = {
29
- css: "https://cdn.jsdelivr.net/npm/cropperjs@1.5.12/dist/cropper.min.css",
30
- js: "https://cdn.jsdelivr.net/npm/cropperjs@1.5.12/dist/cropper.min.js"
30
+ css: `${cdnBase}/cropperjs/1.5.12/cropper.min.css`,
31
+ js: `${cdnBase}/cropperjs/1.5.12/cropper.min.js`
31
32
  };
32
- const screenfullUrl = "https://cdn.jsdelivr.net/npm/screenfull@5.1.0/dist/screenfull.js";
33
+ const screenfullUrl = `${cdnBase}/screenfull.js/5.1.0/screenfull.min.js`;
33
34
  const allToolbar = [
34
35
  "bold",
35
36
  "underline",
@@ -215,43 +216,43 @@ const staticTextDefault = {
215
216
  }
216
217
  }
217
218
  };
218
- const mermaidUrl = "https://cdn.jsdelivr.net/npm/mermaid@8.13.5/dist/mermaid.min.js";
219
+ const mermaidUrl = `${cdnBase}/mermaid/8.13.5/mermaid.min.js`;
219
220
  const katexUrl = {
220
- js: "https://cdn.jsdelivr.net/npm/katex@0.15.1/dist/katex.min.js",
221
- css: "https://cdn.jsdelivr.net/npm/katex@0.15.1/dist/katex.min.css"
221
+ js: `${cdnBase}/KaTeX/0.15.1/katex.min.js`,
222
+ css: `${cdnBase}/KaTeX/0.15.1/katex.min.css`
222
223
  };
223
224
  const codeCss = {
224
225
  a11y: {
225
- light: "https://cdn.jsdelivr.net/npm/highlight.js@11.2.0/styles/a11y-light.css",
226
- dark: "https://cdn.jsdelivr.net/npm/highlight.js@11.2.0/styles/a11y-dark.css"
226
+ light: `${cdnBase}/highlight.js/11.5.1/styles/a11y-light.min.css`,
227
+ dark: `${cdnBase}/highlight.js/11.5.1/styles/a11y-dark.min.css`
227
228
  },
228
229
  atom: {
229
- light: "https://cdn.jsdelivr.net/npm/highlight.js@11.2.0/styles/atom-one-light.css",
230
- dark: "https://cdn.jsdelivr.net/npm/highlight.js@11.2.0/styles/atom-one-dark.css"
230
+ light: `${cdnBase}/highlight.js/11.5.1/styles/atom-one-light.min.css`,
231
+ dark: `${cdnBase}/highlight.js/11.5.1/styles/atom-one-dark.min.css`
231
232
  },
232
233
  github: {
233
- light: "https://cdn.jsdelivr.net/npm/highlight.js@11.2.0/styles/github.css",
234
- dark: "https://cdn.jsdelivr.net/npm/highlight.js@11.2.0/styles/github-dark.css"
234
+ light: `${cdnBase}/highlight.js/11.5.1/styles/github.min.css`,
235
+ dark: `${cdnBase}/highlight.js/11.5.1/styles/github-dark.min.css`
235
236
  },
236
237
  gradient: {
237
- light: "https://cdn.jsdelivr.net/npm/highlight.js@11.2.0/styles/gradient-light.css",
238
- dark: "https://cdn.jsdelivr.net/npm/highlight.js@11.2.0/styles/gradient-dark.css"
238
+ light: `${cdnBase}/highlight.js/11.5.1/styles/gradient-light.min.css`,
239
+ dark: `${cdnBase}/highlight.js/11.5.1/styles/gradient-dark.min.css`
239
240
  },
240
241
  kimbie: {
241
- light: "https://cdn.jsdelivr.net/npm/highlight.js@11.2.0/styles/kimbie-light.css",
242
- dark: "https://cdn.jsdelivr.net/npm/highlight.js@11.2.0/styles/kimbie-dark.css"
242
+ light: `${cdnBase}/highlight.js/11.5.1/styles/kimbie-light.min.css`,
243
+ dark: `${cdnBase}/highlight.js/11.5.1/styles/kimbie-dark.min.css`
243
244
  },
244
245
  paraiso: {
245
- light: "https://cdn.jsdelivr.net/npm/highlight.js@11.2.0/styles/paraiso-light.css",
246
- dark: "https://cdn.jsdelivr.net/npm/highlight.js@11.2.0/styles/paraiso-dark.css"
246
+ light: `${cdnBase}/highlight.js/11.5.1/styles/paraiso-light.min.css`,
247
+ dark: `${cdnBase}/highlight.js/11.5.1/styles/paraiso-dark.min.css`
247
248
  },
248
249
  qtcreator: {
249
- light: "https://cdn.jsdelivr.net/npm/highlight.js@11.2.0/styles/qtcreator-light.css",
250
- dark: "https://cdn.jsdelivr.net/npm/highlight.js@11.2.0/styles/qtcreator-dark.css"
250
+ light: `${cdnBase}/highlight.js/11.5.1/styles/qtcreator-light.min.css`,
251
+ dark: `${cdnBase}/highlight.js/11.5.1/styles/qtcreator-dark.min.css`
251
252
  },
252
253
  stackoverflow: {
253
- light: "https://cdn.jsdelivr.net/npm/highlight.js@11.2.0/styles/stackoverflow-light.css",
254
- dark: "https://cdn.jsdelivr.net/npm/highlight.js@11.2.0/styles/stackoverflow-dark.css"
254
+ light: `${cdnBase}/highlight.js/11.5.1/styles/stackoverflow-light.min.css`,
255
+ dark: `${cdnBase}/highlight.js/11.5.1/styles/stackoverflow-dark.min.css`
255
256
  }
256
257
  };
257
258
  class Bus {
@@ -497,10 +498,10 @@ const updateHandler = debounce((id, attr, value) => {
497
498
  }
498
499
  }, 10);
499
500
  const useKeyBoard = (props2, context) => {
500
- const { editorId } = props2;
501
+ const { editorId, noPrettier } = props2;
501
502
  const initFunc = (name) => {
502
503
  var _a, _b;
503
- return ((_a = props2.toolbars) == null ? void 0 : _a.includes(name)) && !((_b = props2.toolbarsExclude) == null ? void 0 : _b.includes(name));
504
+ return ((_a = props2.toolbars) == null ? void 0 : _a.includes(name)) && !((_b = props2.toolbarsExclude) == null ? void 0 : _b.includes(name)) && !noPrettier;
504
505
  };
505
506
  const keyDownHandler = (event) => {
506
507
  if (event.target !== document.querySelector(`#${props2.editorId}-textarea`)) {
@@ -823,6 +824,72 @@ const useExpansion = (props2, extension) => {
823
824
  }
824
825
  });
825
826
  };
827
+ const useConfig = (props2, context) => {
828
+ const { editorId } = props2;
829
+ const setting = reactive({
830
+ pageFullScreen: props2.pageFullScreen,
831
+ fullscreen: false,
832
+ preview: props2.preview,
833
+ htmlPreview: props2.preview ? false : props2.htmlPreview
834
+ });
835
+ const updateSetting = (v, k) => {
836
+ setting[k] = v;
837
+ if (k === "preview" && setting.preview) {
838
+ setting.htmlPreview = false;
839
+ } else if (k === "htmlPreview" && setting.htmlPreview) {
840
+ setting.preview = false;
841
+ }
842
+ };
843
+ let bodyOverflowHistory = "";
844
+ const adjustBody = () => {
845
+ if (setting.pageFullScreen || setting.fullscreen) {
846
+ document.body.style.overflow = "hidden";
847
+ } else {
848
+ document.body.style.overflow = bodyOverflowHistory;
849
+ }
850
+ };
851
+ watch(() => [setting.pageFullScreen, setting.fullscreen], adjustBody);
852
+ onMounted(() => {
853
+ if (!props2.previewOnly) {
854
+ bus.on(editorId, {
855
+ name: "uploadImage",
856
+ callback(files, cb) {
857
+ const insertHanlder = (urls) => {
858
+ bus.emit(editorId, "replace", "image", {
859
+ desc: "",
860
+ urls
861
+ });
862
+ cb && cb();
863
+ };
864
+ if (props2.onUploadImg) {
865
+ props2.onUploadImg(files, insertHanlder);
866
+ } else {
867
+ context.emit("onUploadImg", files, insertHanlder);
868
+ }
869
+ }
870
+ });
871
+ }
872
+ bodyOverflowHistory = document.body.style.overflow;
873
+ adjustBody();
874
+ });
875
+ return [setting, updateSetting];
876
+ };
877
+ const useCatalog = (props2) => {
878
+ const { editorId } = props2;
879
+ const catalogVisible = ref(false);
880
+ onMounted(() => {
881
+ bus.on(editorId, {
882
+ name: "catalogShow",
883
+ callback: () => {
884
+ catalogVisible.value = !catalogVisible.value;
885
+ }
886
+ });
887
+ });
888
+ const catalogShow = computed(() => {
889
+ return !props2.toolbarsExclude.includes("catalog") && props2.toolbars.includes("catalog");
890
+ });
891
+ return [catalogVisible, catalogShow];
892
+ };
826
893
  var index$1 = "";
827
894
  var Divider = defineComponent({
828
895
  setup() {
@@ -5263,6 +5330,7 @@ const useHistory = (props2, textAreaRef, completeStatus) => {
5263
5330
  endPos
5264
5331
  });
5265
5332
  history.curr = history.list.length - 1;
5333
+ saveHistoryPos();
5266
5334
  } else {
5267
5335
  history.userUpdated = true;
5268
5336
  }
@@ -5272,14 +5340,11 @@ const useHistory = (props2, textAreaRef, completeStatus) => {
5272
5340
  var _a2, _b2;
5273
5341
  historyPos = [(_a2 = textAreaRef.value) == null ? void 0 : _a2.selectionStart, (_b2 = textAreaRef.value) == null ? void 0 : _b2.selectionEnd];
5274
5342
  };
5275
- watch(() => props2.value, (val) => {
5343
+ watch([toRef(props2, "value"), completeStatus], () => {
5276
5344
  if (completeStatus.value) {
5277
- saveHistory(val);
5345
+ saveHistory(props2.value);
5278
5346
  }
5279
5347
  });
5280
- watch(() => completeStatus.value, () => {
5281
- saveHistory(props2.value);
5282
- });
5283
5348
  onMounted(() => {
5284
5349
  bus.on(editorId, {
5285
5350
  name: "ctrlZ",
@@ -5293,7 +5358,6 @@ const useHistory = (props2, textAreaRef, completeStatus) => {
5293
5358
  keyZCallback(history.curr + 1 === history.list.length ? history.curr : history.curr + 1);
5294
5359
  }
5295
5360
  });
5296
- textAreaRef.value.addEventListener("keydown", saveHistoryPos);
5297
5361
  textAreaRef.value.addEventListener("click", saveHistoryPos);
5298
5362
  });
5299
5363
  };
@@ -5346,7 +5410,7 @@ const useMarked = (props2, mermaidData) => {
5346
5410
  }
5347
5411
  return markedCode.call(renderer, code, language, isEscaped);
5348
5412
  };
5349
- renderer.image = (href, title, desc) => {
5413
+ renderer.image = (href, title = "", desc = "") => {
5350
5414
  return `<span class="figure"><img src="${href}" title="${title}" alt="${desc}"><span class="figcaption">${desc}</span></span>`;
5351
5415
  };
5352
5416
  renderer.listitem = (text, task) => {
@@ -5570,15 +5634,15 @@ ${nextOrder}. `, {}));
5570
5634
  });
5571
5635
  }
5572
5636
  });
5637
+ watch(() => props2.value, () => {
5638
+ selectedText.value = "";
5639
+ });
5573
5640
  bus.on(editorId, {
5574
5641
  name: "selectTextChange",
5575
5642
  callback() {
5576
5643
  selectedText.value = getSelectionText(textAreaRef.value);
5577
5644
  }
5578
5645
  });
5579
- return {
5580
- selectedText
5581
- };
5582
5646
  };
5583
5647
  const useMermaid = (props2) => {
5584
5648
  const theme = inject("theme");
@@ -5725,15 +5789,13 @@ var Content = defineComponent({
5725
5789
  html
5726
5790
  } = useMarked(props2, mermaidData);
5727
5791
  useAutoScroll(props2, html, textAreaRef, previewRef, htmlRef);
5728
- const {
5729
- selectedText
5730
- } = useAutoGenrator(props2, textAreaRef);
5792
+ useAutoGenrator(props2, textAreaRef);
5731
5793
  useHistory(props2, textAreaRef, completeStatus);
5732
5794
  usePasteUpload(textAreaRef);
5733
5795
  userZoom(html);
5734
5796
  return () => {
5735
5797
  return createVNode(Fragment, null, [createVNode("div", {
5736
- "class": [`${prefix}-content`]
5798
+ "class": `${prefix}-content`
5737
5799
  }, [!previewOnly && createVNode("div", {
5738
5800
  "class": `${prefix}-input-wrapper`
5739
5801
  }, [createVNode("textarea", {
@@ -5744,7 +5806,6 @@ var Content = defineComponent({
5744
5806
  completeStatus.value = false;
5745
5807
  },
5746
5808
  "onInput": (e) => {
5747
- selectedText.value = "";
5748
5809
  props2.onChange(e.target.value);
5749
5810
  },
5750
5811
  "onCompositionend": () => {
@@ -6034,7 +6095,7 @@ const props = {
6034
6095
  const Editor = defineComponent({
6035
6096
  name: "MdEditorV3",
6036
6097
  props,
6037
- emits: ["onChange", "onSave", "onUploadImg", "onHtmlChanged", "onGetCatalog", "onError"],
6098
+ emits: ["onChange", "onSave", "onUploadImg", "onHtmlChanged", "onGetCatalog", "onError", "update:modelValue"],
6038
6099
  setup(props2, context) {
6039
6100
  const {
6040
6101
  editorId
@@ -6043,79 +6104,11 @@ const Editor = defineComponent({
6043
6104
  useKeyBoard(props2, context);
6044
6105
  useProvide(props2, extension);
6045
6106
  useExpansion(props2, extension);
6046
- const state = reactive({
6047
- catalogVisible: false
6048
- });
6049
- const setting = reactive({
6050
- pageFullScreen: props2.pageFullScreen,
6051
- fullscreen: false,
6052
- preview: props2.preview,
6053
- htmlPreview: props2.preview ? false : props2.htmlPreview
6054
- });
6055
- const updateSetting = (v, k) => {
6056
- setting[k] = v;
6057
- if (k === "preview" && setting.preview) {
6058
- setting.htmlPreview = false;
6059
- } else if (k === "htmlPreview" && setting.htmlPreview) {
6060
- setting.preview = false;
6061
- }
6062
- };
6063
- let bodyOverflowHistory = "";
6064
- const adjustBody = () => {
6065
- if (setting.pageFullScreen || setting.fullscreen) {
6066
- document.body.style.overflow = "hidden";
6067
- } else {
6068
- document.body.style.overflow = bodyOverflowHistory;
6069
- }
6070
- };
6071
- watch(() => [setting.pageFullScreen, setting.fullscreen], adjustBody);
6072
- onMounted(() => {
6073
- if (!props2.previewOnly) {
6074
- bus.on(editorId, {
6075
- name: "uploadImage",
6076
- callback(files, cb) {
6077
- const insertHanlder = (urls) => {
6078
- bus.emit(editorId, "replace", "image", {
6079
- desc: "",
6080
- urls
6081
- });
6082
- cb && cb();
6083
- };
6084
- if (props2.onUploadImg) {
6085
- props2.onUploadImg(files, insertHanlder);
6086
- } else {
6087
- context.emit("onUploadImg", files, insertHanlder);
6088
- }
6089
- }
6090
- });
6091
- }
6092
- bodyOverflowHistory = document.body.style.overflow;
6093
- adjustBody();
6094
- bus.on(editorId, {
6095
- name: "catalogShow",
6096
- callback: () => {
6097
- state.catalogVisible = !state.catalogVisible;
6098
- }
6099
- });
6100
- });
6107
+ const [setting, updateSetting] = useConfig(props2, context);
6108
+ const [catalogVisible, catalogShow] = useCatalog(props2);
6101
6109
  onBeforeUnmount(() => {
6102
6110
  bus.clear(editorId);
6103
6111
  });
6104
- const catalogShow = computed(() => {
6105
- return !props2.toolbarsExclude.includes("catalog") && props2.toolbars.includes("catalog");
6106
- });
6107
- onMounted(() => {
6108
- bus.on(editorId, {
6109
- name: "errorCatcher",
6110
- callback: (err) => {
6111
- if (props2.onError instanceof Function) {
6112
- props2.onError(err);
6113
- } else {
6114
- context.emit("onError", err);
6115
- }
6116
- }
6117
- });
6118
- });
6119
6112
  return () => {
6120
6113
  var _a;
6121
6114
  const defToolbars = getSlot({
@@ -6168,7 +6161,7 @@ const Editor = defineComponent({
6168
6161
  }, null), catalogShow.value && createVNode(MdCatalog, {
6169
6162
  "theme": props2.theme,
6170
6163
  "style": {
6171
- display: state.catalogVisible ? "block" : "none"
6164
+ display: catalogVisible.value ? "block" : "none"
6172
6165
  },
6173
6166
  "class": `${prefix}-catalog-editor`,
6174
6167
  "editorId": editorId,