md-editor-v3 2.0.1-beta.0 → 2.1.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.
@@ -17,7 +17,7 @@ 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, reactive, watch, ref, defineComponent, createVNode, cloneVNode, nextTick, inject, Fragment, toRef, isVNode } from "vue";
20
+ import { onMounted, onBeforeUnmount, provide, computed, reactive, watch, ref, defineComponent, createVNode, cloneVNode, nextTick, inject, Fragment, toRef, createTextVNode, isVNode } from "vue";
21
21
  const prefix = "md";
22
22
  const iconfontUrl = "https://at.alicdn.com/t/font_2605852_pqekijay2ij.js";
23
23
  const cdnBase = "https://cdnjs.cloudflare.com/ajax/libs";
@@ -64,6 +64,7 @@ const allToolbar = [
64
64
  "catalog",
65
65
  "github"
66
66
  ];
67
+ const allFooter = ["markdownTotal", "=", "scrollSwitch"];
67
68
  const staticTextDefault = {
68
69
  "zh-CN": {
69
70
  toolbarTips: {
@@ -138,6 +139,10 @@ const staticTextDefault = {
138
139
  katex: {
139
140
  inline: "\u884C\u5185\u516C\u5F0F",
140
141
  block: "\u5757\u7EA7\u516C\u5F0F"
142
+ },
143
+ footer: {
144
+ markdownTotal: "\u5B57\u6570",
145
+ scrollAuto: "\u540C\u6B65\u6EDA\u52A8"
141
146
  }
142
147
  },
143
148
  "en-US": {
@@ -213,6 +218,10 @@ const staticTextDefault = {
213
218
  katex: {
214
219
  inline: "inline",
215
220
  block: "block"
221
+ },
222
+ footer: {
223
+ markdownTotal: "Word Count",
224
+ scrollAuto: "Scroll Auto"
216
225
  }
217
226
  }
218
227
  };
@@ -906,7 +915,7 @@ const getSlot = ({
906
915
  const targetSlot = (instance == null ? void 0 : instance.$slots[name]) || (ctx == null ? void 0 : ctx.slots[name]);
907
916
  return (targetSlot ? targetSlot(instance) : "") || props2[name];
908
917
  };
909
- var style$3 = "";
918
+ var style$4 = "";
910
919
  var Dropdown = defineComponent({
911
920
  props: {
912
921
  trigger: {
@@ -1035,7 +1044,7 @@ var Dropdown = defineComponent({
1035
1044
  };
1036
1045
  }
1037
1046
  });
1038
- var style$2 = "";
1047
+ var style$3 = "";
1039
1048
  var Modal = defineComponent({
1040
1049
  props: {
1041
1050
  title: {
@@ -1308,7 +1317,7 @@ var LinkModal = defineComponent({
1308
1317
  });
1309
1318
  }
1310
1319
  });
1311
- var style$1 = "";
1320
+ var style$2 = "";
1312
1321
  var ClipModal = defineComponent({
1313
1322
  props: {
1314
1323
  visible: {
@@ -5246,7 +5255,7 @@ var kaTexExtensions = {
5246
5255
  return (_a = text.match(/\$[^\n]*/)) == null ? void 0 : _a.index;
5247
5256
  },
5248
5257
  tokenizer(text) {
5249
- if (/^\$[^\n]*/.test(text)) {
5258
+ if (/^\$[^\n]*\$/.test(text)) {
5250
5259
  const match = splitKatexValue(text);
5251
5260
  const token = {
5252
5261
  type: "KaTexInlineExtension",
@@ -5411,7 +5420,7 @@ const useMarked = (props2, mermaidData) => {
5411
5420
  return markedCode.call(renderer, code, language, isEscaped);
5412
5421
  };
5413
5422
  renderer.image = (href, title = "", desc = "") => {
5414
- return `<span class="figure"><img src="${href}" title="${title}" alt="${desc}"><span class="figcaption">${desc}</span></span>`;
5423
+ return `<span class="figure"><img src="${href}" title="${title}" alt="${desc}" zoom><span class="figcaption">${desc}</span></span>`;
5415
5424
  };
5416
5425
  renderer.listitem = (text, task) => {
5417
5426
  if (task) {
@@ -5430,7 +5439,7 @@ const useMarked = (props2, mermaidData) => {
5430
5439
  if (isNewHeading) {
5431
5440
  return newHeading.call(renderer, text, level, raw, slugger);
5432
5441
  }
5433
- const id = props2.markedHeadingId(raw, level);
5442
+ const id = props2.markedHeadingId(raw, level, heads.value.length);
5434
5443
  if (text !== raw) {
5435
5444
  return `<h${level} id="${id}">${text}</h${level}>`;
5436
5445
  } else {
@@ -5559,14 +5568,9 @@ const useAutoScroll = (props2, html, textAreaRef, previewRef, htmlRef) => {
5559
5568
  pre.appendChild(copyButton);
5560
5569
  });
5561
5570
  };
5562
- onMounted(() => {
5563
- if (previewRef.value || htmlRef.value) {
5564
- [initScrollAuto, clearScrollAuto] = scrollAuto(textAreaRef.value, previewRef.value || htmlRef.value);
5565
- }
5566
- });
5567
5571
  const htmlChanged = () => {
5568
5572
  nextTick(() => {
5569
- if (props2.setting.preview && !previewOnly) {
5573
+ if (props2.setting.preview && !previewOnly && props2.scrollAuto) {
5570
5574
  clearScrollAuto();
5571
5575
  initScrollAuto();
5572
5576
  }
@@ -5585,7 +5589,19 @@ const useAutoScroll = (props2, html, textAreaRef, previewRef, htmlRef) => {
5585
5589
  watch(() => html.value, htmlChanged);
5586
5590
  watch(() => props2.setting.preview, settingPreviewChanged);
5587
5591
  watch(() => props2.setting.htmlPreview, settingPreviewChanged);
5588
- onMounted(htmlChanged);
5592
+ watch(() => props2.scrollAuto, (sa) => {
5593
+ if (sa) {
5594
+ initScrollAuto();
5595
+ } else {
5596
+ clearScrollAuto();
5597
+ }
5598
+ });
5599
+ onMounted(() => {
5600
+ initCopyEntry();
5601
+ if (!previewOnly && props2.scrollAuto && (previewRef.value || htmlRef.value)) {
5602
+ [initScrollAuto, clearScrollAuto] = scrollAuto(textAreaRef.value, previewRef.value || htmlRef.value);
5603
+ }
5604
+ });
5589
5605
  };
5590
5606
  const useAutoGenrator = (props2, textAreaRef) => {
5591
5607
  const previewOnly = inject("previewOnly");
@@ -5713,7 +5729,7 @@ const usePasteUpload = (textAreaRef) => {
5713
5729
  const userZoom = (html) => {
5714
5730
  const editorId = inject("editorId");
5715
5731
  const zoomHander = debounce(() => {
5716
- const imgs = document.querySelectorAll(`#${editorId}-preview img`);
5732
+ const imgs = document.querySelectorAll(`#${editorId}-preview img[zoom]`);
5717
5733
  if (imgs.length === 0) {
5718
5734
  return;
5719
5735
  }
@@ -5773,6 +5789,9 @@ var Content = defineComponent({
5773
5789
  mermaidTemplate: {
5774
5790
  type: Object,
5775
5791
  default: () => ({})
5792
+ },
5793
+ scrollAuto: {
5794
+ type: Boolean
5776
5795
  }
5777
5796
  },
5778
5797
  setup(props2) {
@@ -5832,6 +5851,144 @@ var Content = defineComponent({
5832
5851
  };
5833
5852
  }
5834
5853
  });
5854
+ var MarkdownTotal = defineComponent({
5855
+ props: {
5856
+ modelValue: {
5857
+ type: String,
5858
+ default: ""
5859
+ }
5860
+ },
5861
+ setup(props2) {
5862
+ const ult = inject("usedLanguageText");
5863
+ return () => {
5864
+ var _a;
5865
+ return createVNode("div", {
5866
+ "class": `${prefix}-footer-item`
5867
+ }, [createVNode("label", {
5868
+ "class": `${prefix}-footer-label`
5869
+ }, [(_a = ult.value.footer) == null ? void 0 : _a.markdownTotal, createTextVNode(":")]), createVNode("span", null, [props2.modelValue.length])]);
5870
+ };
5871
+ }
5872
+ });
5873
+ var style$1 = "";
5874
+ var Checkbox = defineComponent({
5875
+ props: {
5876
+ checked: {
5877
+ type: Boolean,
5878
+ default: false
5879
+ },
5880
+ onChange: {
5881
+ type: Function,
5882
+ default: () => () => {
5883
+ }
5884
+ }
5885
+ },
5886
+ setup(props2) {
5887
+ return () => {
5888
+ return createVNode("div", {
5889
+ "class": [`${prefix}-checkbox`, props2.checked && `${prefix}-checkbox-checked`],
5890
+ "onClick": () => {
5891
+ props2.onChange(!props2.checked);
5892
+ }
5893
+ }, null);
5894
+ };
5895
+ }
5896
+ });
5897
+ var ScrollAuto = defineComponent({
5898
+ props: {
5899
+ scrollAuto: {
5900
+ type: Boolean
5901
+ },
5902
+ onScrollAutoChange: {
5903
+ type: Function,
5904
+ default: () => () => {
5905
+ }
5906
+ }
5907
+ },
5908
+ setup(props2) {
5909
+ const ult = inject("usedLanguageText");
5910
+ return () => {
5911
+ var _a;
5912
+ return createVNode("div", {
5913
+ "class": `${prefix}-footer-item`
5914
+ }, [createVNode("label", {
5915
+ "class": `${prefix}-footer-label`,
5916
+ "onClick": () => {
5917
+ props2.onScrollAutoChange(!props2.scrollAuto);
5918
+ }
5919
+ }, [(_a = ult.value.footer) == null ? void 0 : _a.scrollAuto]), createVNode(Checkbox, {
5920
+ "checked": props2.scrollAuto,
5921
+ "onChange": props2.onScrollAutoChange
5922
+ }, null)]);
5923
+ };
5924
+ }
5925
+ });
5926
+ var Footer = defineComponent({
5927
+ name: "MDEditorFooter",
5928
+ props: {
5929
+ modelValue: {
5930
+ type: String,
5931
+ default: ""
5932
+ },
5933
+ footers: {
5934
+ type: Array,
5935
+ default: []
5936
+ },
5937
+ scrollAuto: {
5938
+ type: Boolean
5939
+ },
5940
+ onScrollAutoChange: {
5941
+ type: Function,
5942
+ default: () => () => {
5943
+ }
5944
+ },
5945
+ defFooters: {
5946
+ type: Object
5947
+ }
5948
+ },
5949
+ setup(props2) {
5950
+ const splitedItems = computed(() => {
5951
+ const moduleSplitIndex = props2.footers.indexOf("=");
5952
+ const barLeft = moduleSplitIndex === -1 ? props2.footers : props2.footers.slice(0, moduleSplitIndex);
5953
+ const barRight = moduleSplitIndex === -1 ? [] : props2.footers.slice(moduleSplitIndex, Number.MAX_SAFE_INTEGER);
5954
+ return [barLeft, barRight];
5955
+ });
5956
+ const footerRender = (name) => {
5957
+ if (allFooter.includes(name)) {
5958
+ switch (name) {
5959
+ case "markdownTotal": {
5960
+ return createVNode(MarkdownTotal, {
5961
+ "modelValue": props2.modelValue
5962
+ }, null);
5963
+ }
5964
+ case "scrollSwitch": {
5965
+ return createVNode(ScrollAuto, {
5966
+ "scrollAuto": props2.scrollAuto,
5967
+ "onScrollAutoChange": props2.onScrollAutoChange
5968
+ }, null);
5969
+ }
5970
+ }
5971
+ } else if (props2.defFooters instanceof Array) {
5972
+ return props2.defFooters[name] || "";
5973
+ } else if (props2.defFooters && props2.defFooters.children instanceof Array) {
5974
+ return props2.defFooters.children[name] || "";
5975
+ } else {
5976
+ return "";
5977
+ }
5978
+ };
5979
+ return () => {
5980
+ const LeftFooter = splitedItems.value[0].map((name) => footerRender(name));
5981
+ const RightFooter = splitedItems.value[1].map((name) => footerRender(name));
5982
+ return createVNode("div", {
5983
+ "class": `${prefix}-footer`
5984
+ }, [createVNode("div", {
5985
+ "class": `${prefix}-footer-left`
5986
+ }, [LeftFooter]), createVNode("div", {
5987
+ "class": `${prefix}-footer-right`
5988
+ }, [RightFooter])]);
5989
+ };
5990
+ }
5991
+ });
5835
5992
  const CatalogLink = defineComponent({
5836
5993
  props: {
5837
5994
  tocItem: {
@@ -5848,14 +6005,18 @@ const CatalogLink = defineComponent({
5848
6005
  default: ""
5849
6006
  }
5850
6007
  },
5851
- setup(props2) {
6008
+ setup({
6009
+ tocItem,
6010
+ markedHeadingId: markedHeadingId2,
6011
+ scrollElement
6012
+ }) {
5852
6013
  return () => createVNode("div", {
5853
6014
  "class": `${prefix}-catalog-link`,
5854
6015
  "onClick": (e) => {
5855
6016
  e.stopPropagation();
5856
- const id = props2.markedHeadingId(props2.tocItem.text, props2.tocItem.level);
6017
+ const id = markedHeadingId2(tocItem.text, tocItem.level, tocItem.index);
5857
6018
  const targetHeadEle = document.getElementById(id);
5858
- const scrollContainer = props2.scrollElement instanceof Element ? props2.scrollElement : document.querySelector(props2.scrollElement);
6019
+ const scrollContainer = scrollElement instanceof Element ? scrollElement : document.querySelector(scrollElement);
5859
6020
  if (targetHeadEle && scrollContainer) {
5860
6021
  let par = targetHeadEle.offsetParent;
5861
6022
  let offsetTop = targetHeadEle.offsetTop;
@@ -5872,14 +6033,14 @@ const CatalogLink = defineComponent({
5872
6033
  }
5873
6034
  }
5874
6035
  }, [createVNode("span", {
5875
- "title": props2.tocItem.text
5876
- }, [props2.tocItem.text]), createVNode("div", {
6036
+ "title": tocItem.text
6037
+ }, [tocItem.text]), createVNode("div", {
5877
6038
  "class": `${prefix}-catalog-wrapper`
5878
- }, [props2.tocItem.children && props2.tocItem.children.map((item) => createVNode(CatalogLink, {
5879
- "markedHeadingId": props2.markedHeadingId,
6039
+ }, [tocItem.children && tocItem.children.map((item) => createVNode(CatalogLink, {
6040
+ "markedHeadingId": markedHeadingId2,
5880
6041
  "key": item.text,
5881
6042
  "tocItem": item,
5882
- "scrollElement": props2.scrollElement
6043
+ "scrollElement": scrollElement
5883
6044
  }, null))])]);
5884
6045
  }
5885
6046
  });
@@ -5918,10 +6079,11 @@ const MdCatalog = defineComponent({
5918
6079
  state.list.forEach(({
5919
6080
  text,
5920
6081
  level
5921
- }) => {
6082
+ }, index2) => {
5922
6083
  const item = {
5923
6084
  level,
5924
- text
6085
+ text,
6086
+ index: index2 + 1
5925
6087
  };
5926
6088
  if (tocItems.length === 0) {
5927
6089
  tocItems.push(item);
@@ -6090,6 +6252,17 @@ const props = {
6090
6252
  codeTheme: {
6091
6253
  type: String,
6092
6254
  default: "atom"
6255
+ },
6256
+ footers: {
6257
+ type: Array,
6258
+ default: allFooter
6259
+ },
6260
+ scrollAuto: {
6261
+ type: Boolean,
6262
+ default: true
6263
+ },
6264
+ defFooters: {
6265
+ type: [String, Object]
6093
6266
  }
6094
6267
  };
6095
6268
  const Editor = defineComponent({
@@ -6101,6 +6274,9 @@ const Editor = defineComponent({
6101
6274
  editorId
6102
6275
  } = props2;
6103
6276
  const extension = Editor.extension || {};
6277
+ const state = reactive({
6278
+ scrollAuto: props2.scrollAuto
6279
+ });
6104
6280
  useKeyBoard(props2, context);
6105
6281
  useProvide(props2, extension);
6106
6282
  useExpansion(props2, extension);
@@ -6110,11 +6286,15 @@ const Editor = defineComponent({
6110
6286
  bus.clear(editorId);
6111
6287
  });
6112
6288
  return () => {
6113
- var _a;
6289
+ var _a, _b;
6114
6290
  const defToolbars = getSlot({
6115
6291
  props: props2,
6116
6292
  ctx: context
6117
6293
  }, "defToolbars");
6294
+ const defFooters = getSlot({
6295
+ props: props2,
6296
+ ctx: context
6297
+ }, "defFooters");
6118
6298
  return createVNode("div", {
6119
6299
  "id": editorId,
6120
6300
  "class": [prefix, props2.class, props2.theme === "dark" && `${prefix}-dark`, setting.fullscreen || setting.pageFullScreen ? `${prefix}-fullscreen` : "", props2.previewOnly && `${prefix}-previewOnly`],
@@ -6157,7 +6337,14 @@ const Editor = defineComponent({
6157
6337
  "sanitize": props2.sanitize,
6158
6338
  "placeholder": props2.placeholder,
6159
6339
  "noKatex": props2.noKatex,
6160
- "mermaidTemplate": (_a = extension == null ? void 0 : extension.editorConfig) == null ? void 0 : _a.mermaidTemplate
6340
+ "mermaidTemplate": (_a = extension == null ? void 0 : extension.editorConfig) == null ? void 0 : _a.mermaidTemplate,
6341
+ "scrollAuto": state.scrollAuto
6342
+ }, null), !props2.previewOnly && ((_b = props2.footers) == null ? void 0 : _b.length) > 0 && createVNode(Footer, {
6343
+ "modelValue": props2.modelValue,
6344
+ "footers": props2.footers,
6345
+ "defFooters": defFooters,
6346
+ "scrollAuto": state.scrollAuto,
6347
+ "onScrollAutoChange": (v) => state.scrollAuto = v
6161
6348
  }, null), catalogShow.value && createVNode(MdCatalog, {
6162
6349
  "theme": props2.theme,
6163
6350
  "style": {