md-editor-v3 4.16.9 → 4.17.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.
@@ -1312,7 +1312,7 @@ const scrollAuto = (pEle, cEle, codeMirrorUt) => {
1312
1312
  }
1313
1313
  };
1314
1314
  const getLineNumber = (pMaxScrollLength, cMaxScrollLength) => {
1315
- let lineNumer = 0;
1315
+ let lineNumer = 1;
1316
1316
  for (let i = elesHasLineNumber.length - 1; i - 1 >= 0; i--) {
1317
1317
  const curr = elesHasLineNumber[i];
1318
1318
  const sibling = elesHasLineNumber[i - 1];
@@ -1371,7 +1371,7 @@ const scrollAuto = (pEle, cEle, codeMirrorUt) => {
1371
1371
  const lineNumer = getLineNumber(pMaxScrollLength, cMaxScrollLength);
1372
1372
  startTop = getTopByLine(lineNumer);
1373
1373
  scale = (scrollDOM.scrollTop - startTop) / (pMaxScrollLength - startTop);
1374
- startEleOffetTop = (_c = document.querySelector(`[data-line="${lineNumer}"]`)) == null ? void 0 : _c.offsetTop;
1374
+ startEleOffetTop = ((_c = document.querySelector(`[data-line="${lineNumer}"]`)) == null ? void 0 : _c.offsetTop) || startEleOffetTop;
1375
1375
  blockHeight = cMaxScrollLength - startEleOffetTop + getComputedStyleNum(cEle, "padding-top");
1376
1376
  }
1377
1377
  const scrollToTop = startEleOffetTop - cElePaddingTop + blockHeight * scale;
@@ -1447,9 +1447,7 @@ const scrollAuto = (pEle, cEle, codeMirrorUt) => {
1447
1447
  let blockHeight = 0;
1448
1448
  if (endLineScrollTop > pMaxScrollLength || realEleEnd.offsetTop + realEleEnd.offsetHeight > cMaxScrollLength) {
1449
1449
  const lineNumer = getLineNumber(pMaxScrollLength, cMaxScrollLength);
1450
- eleStartOffsetTop = (_f = document.querySelector(
1451
- `[data-line="${lineNumer}"]`
1452
- )) == null ? void 0 : _f.offsetTop;
1450
+ eleStartOffsetTop = ((_f = document.querySelector(`[data-line="${lineNumer}"]`)) == null ? void 0 : _f.offsetTop) || eleStartOffsetTop;
1453
1451
  firstLineScrollTop = getTopByLine(lineNumer);
1454
1452
  scale = (cScrollTop - eleStartOffsetTop) / (cMaxScrollLength - eleStartOffsetTop);
1455
1453
  blockHeight = pMaxScrollLength - firstLineScrollTop;
@@ -2911,9 +2909,16 @@ const useResize = (props2, contentRef, resizeRef) => {
2911
2909
  }
2912
2910
  );
2913
2911
  vue.watch(
2914
- [vue.toRef(props2.setting, "htmlPreview"), vue.toRef(props2.setting, "preview")],
2912
+ [
2913
+ vue.toRef(props2.setting, "htmlPreview"),
2914
+ vue.toRef(props2.setting, "preview"),
2915
+ vue.toRef(props2.setting, "previewOnly")
2916
+ ],
2915
2917
  () => {
2916
- if (!props2.setting.htmlPreview && !props2.setting.preview) {
2918
+ if (props2.setting.previewOnly) {
2919
+ inputWrapperStyle.width = "0%";
2920
+ resizeOperateStyle.display = "none";
2921
+ } else if (!props2.setting.htmlPreview && !props2.setting.preview) {
2917
2922
  inputWrapperStyle.width = "100%";
2918
2923
  resizeOperateStyle.display = "none";
2919
2924
  } else {
@@ -2925,18 +2930,6 @@ const useResize = (props2, contentRef, resizeRef) => {
2925
2930
  immediate: true
2926
2931
  }
2927
2932
  );
2928
- vue.watch(
2929
- () => props2.setting.previewOnly,
2930
- (po) => {
2931
- if (po) {
2932
- inputWrapperStyle.width = "0%";
2933
- resizeOperateStyle.display = "none";
2934
- } else {
2935
- inputWrapperStyle.width = state2.resizedWidth;
2936
- resizeOperateStyle.display = "initial";
2937
- }
2938
- }
2939
- );
2940
2933
  return { inputWrapperStyle, resizeOperateStyle };
2941
2934
  };
2942
2935
  const Content = /* @__PURE__ */ vue.defineComponent({
@@ -4,8 +4,7 @@ const keyMove = (trigger, moveHandler) => {
4
4
  const parent = trigger.parentElement || document.body;
5
5
  const width = parent.offsetWidth;
6
6
  const height = parent.offsetHeight;
7
- const { clientWidth } = document.documentElement;
8
- const { clientHeight } = document.documentElement;
7
+ const { clientWidth, clientHeight } = document.documentElement;
9
8
  const x = mdown.offsetX;
10
9
  const y = mdown.offsetY;
11
10
  const mouseMoveHandler = (e) => {
@@ -125,6 +125,9 @@ const useHighlight = (props) => {
125
125
  vue.watch(
126
126
  () => highlight.value.css,
127
127
  () => {
128
+ if (props.noHighlight) {
129
+ return;
130
+ }
128
131
  dom.updateHandler("link", {
129
132
  ...highlight.value.css,
130
133
  rel: "stylesheet",
@@ -164,14 +167,14 @@ const useMermaid = (props) => {
164
167
  }
165
168
  );
166
169
  vue.onMounted(() => {
167
- var _a, _b, _c;
168
- if (props.noMermaid || ((_a = mermaidRef.value) == null ? void 0 : _a.instance)) {
170
+ var _a, _b;
171
+ if (props.noMermaid || mermaidRef.value) {
169
172
  return;
170
173
  }
171
174
  const jsSrc = editorExtensions.mermaid.js;
172
175
  if (/\.mjs/.test(jsSrc)) {
173
176
  dom.appendHandler("link", {
174
- ...(_b = editorExtensionsAttrs.mermaid) == null ? void 0 : _b.js,
177
+ ...(_a = editorExtensionsAttrs.mermaid) == null ? void 0 : _a.js,
175
178
  rel: "modulepreload",
176
179
  href: jsSrc,
177
180
  id: `${config.prefix}-mermaid-m`
@@ -188,7 +191,7 @@ const useMermaid = (props) => {
188
191
  dom.appendHandler(
189
192
  "script",
190
193
  {
191
- ...(_c = editorExtensionsAttrs.mermaid) == null ? void 0 : _c.js,
194
+ ...(_b = editorExtensionsAttrs.mermaid) == null ? void 0 : _b.js,
192
195
  src: jsSrc,
193
196
  id: `${config.prefix}-mermaid`,
194
197
  onload() {
@@ -615,7 +618,7 @@ const StrIcon = (name, customIcon) => {
615
618
  };
616
619
  const StrIcon$1 = StrIcon;
617
620
  const codetabs = (md, _opts) => {
618
- const defaultRender = md.renderer.rules.fence, unescapeAll = md.utils.unescapeAll, re = /\[(\w*)(?::([\w ]*))?\]/, mandatoryRe = /::close/;
621
+ const defaultRender = md.renderer.rules.fence, unescapeAll = md.utils.unescapeAll, re = /\[(\w*)(?::([\w ]*))?\]/, mandatoryRe = /::(open|close)/;
619
622
  const getInfo = (token) => {
620
623
  return token.info ? unescapeAll(token.info).trim() : "";
621
624
  };
@@ -628,9 +631,9 @@ const codetabs = (md, _opts) => {
628
631
  return info ? info.split(/(\s+)/g)[0] : "";
629
632
  };
630
633
  const getTagType = (token) => {
631
- const mandatory = mandatoryRe.test(token.info);
632
- const open = !mandatory && token.content.trim().split("\n").length < _opts.autoFoldThreshold;
633
- const tagContainer = mandatory || _opts.codeFoldable ? "details" : "div", tagHeader = mandatory || _opts.codeFoldable ? "summary" : "div";
634
+ const mandatory = token.info.match(mandatoryRe) || [];
635
+ const open = mandatory[1] === "open" || mandatory[1] !== "close" && _opts.codeFoldable && token.content.trim().split("\n").length < _opts.autoFoldThreshold;
636
+ const tagContainer = mandatory[1] || _opts.codeFoldable ? "details" : "div", tagHeader = mandatory[1] || _opts.codeFoldable ? "summary" : "div";
634
637
  return { open, tagContainer, tagHeader };
635
638
  };
636
639
  const fenceGroup = (tokens, idx, options, env, slf) => {
@@ -2572,17 +2575,38 @@ const useConfig = (props, context) => {
2572
2575
  htmlPreview: props.preview ? false : props.htmlPreview,
2573
2576
  previewOnly: false
2574
2577
  });
2578
+ const cacheSetting = vue.reactive({ ...setting });
2575
2579
  const updateSetting = (k, v) => {
2576
- setting[k] = v === void 0 ? !setting[k] : v;
2577
- if (k === "preview") {
2578
- setting.htmlPreview = false;
2579
- setting.previewOnly = false;
2580
- } else if (k === "htmlPreview") {
2581
- setting.preview = false;
2582
- setting.previewOnly = false;
2583
- } else if (k === "previewOnly" && !setting.preview && !setting.htmlPreview) {
2584
- setting.preview = true;
2580
+ const realValue = v === void 0 ? !setting[k] : v;
2581
+ switch (k) {
2582
+ case "preview": {
2583
+ setting.htmlPreview = false;
2584
+ setting.previewOnly = false;
2585
+ break;
2586
+ }
2587
+ case "htmlPreview": {
2588
+ setting.preview = false;
2589
+ setting.previewOnly = false;
2590
+ break;
2591
+ }
2592
+ case "previewOnly": {
2593
+ if (realValue) {
2594
+ if (!setting.preview && !setting.htmlPreview) {
2595
+ setting.preview = true;
2596
+ }
2597
+ } else {
2598
+ if (!cacheSetting.preview) {
2599
+ setting.preview = false;
2600
+ }
2601
+ if (!cacheSetting.htmlPreview) {
2602
+ setting.htmlPreview = false;
2603
+ }
2604
+ }
2605
+ break;
2606
+ }
2585
2607
  }
2608
+ cacheSetting[k] = realValue;
2609
+ setting[k] = realValue;
2586
2610
  };
2587
2611
  let bodyOverflowHistory = "";
2588
2612
  const adjustBody = () => {
@@ -1311,7 +1311,7 @@ const scrollAuto = (pEle, cEle, codeMirrorUt) => {
1311
1311
  }
1312
1312
  };
1313
1313
  const getLineNumber = (pMaxScrollLength, cMaxScrollLength) => {
1314
- let lineNumer = 0;
1314
+ let lineNumer = 1;
1315
1315
  for (let i = elesHasLineNumber.length - 1; i - 1 >= 0; i--) {
1316
1316
  const curr = elesHasLineNumber[i];
1317
1317
  const sibling = elesHasLineNumber[i - 1];
@@ -1370,7 +1370,7 @@ const scrollAuto = (pEle, cEle, codeMirrorUt) => {
1370
1370
  const lineNumer = getLineNumber(pMaxScrollLength, cMaxScrollLength);
1371
1371
  startTop = getTopByLine(lineNumer);
1372
1372
  scale = (scrollDOM.scrollTop - startTop) / (pMaxScrollLength - startTop);
1373
- startEleOffetTop = (_c = document.querySelector(`[data-line="${lineNumer}"]`)) == null ? void 0 : _c.offsetTop;
1373
+ startEleOffetTop = ((_c = document.querySelector(`[data-line="${lineNumer}"]`)) == null ? void 0 : _c.offsetTop) || startEleOffetTop;
1374
1374
  blockHeight = cMaxScrollLength - startEleOffetTop + getComputedStyleNum(cEle, "padding-top");
1375
1375
  }
1376
1376
  const scrollToTop = startEleOffetTop - cElePaddingTop + blockHeight * scale;
@@ -1446,9 +1446,7 @@ const scrollAuto = (pEle, cEle, codeMirrorUt) => {
1446
1446
  let blockHeight = 0;
1447
1447
  if (endLineScrollTop > pMaxScrollLength || realEleEnd.offsetTop + realEleEnd.offsetHeight > cMaxScrollLength) {
1448
1448
  const lineNumer = getLineNumber(pMaxScrollLength, cMaxScrollLength);
1449
- eleStartOffsetTop = (_f = document.querySelector(
1450
- `[data-line="${lineNumer}"]`
1451
- )) == null ? void 0 : _f.offsetTop;
1449
+ eleStartOffsetTop = ((_f = document.querySelector(`[data-line="${lineNumer}"]`)) == null ? void 0 : _f.offsetTop) || eleStartOffsetTop;
1452
1450
  firstLineScrollTop = getTopByLine(lineNumer);
1453
1451
  scale = (cScrollTop - eleStartOffsetTop) / (cMaxScrollLength - eleStartOffsetTop);
1454
1452
  blockHeight = pMaxScrollLength - firstLineScrollTop;
@@ -2910,9 +2908,16 @@ const useResize = (props2, contentRef, resizeRef) => {
2910
2908
  }
2911
2909
  );
2912
2910
  watch(
2913
- [toRef(props2.setting, "htmlPreview"), toRef(props2.setting, "preview")],
2911
+ [
2912
+ toRef(props2.setting, "htmlPreview"),
2913
+ toRef(props2.setting, "preview"),
2914
+ toRef(props2.setting, "previewOnly")
2915
+ ],
2914
2916
  () => {
2915
- if (!props2.setting.htmlPreview && !props2.setting.preview) {
2917
+ if (props2.setting.previewOnly) {
2918
+ inputWrapperStyle.width = "0%";
2919
+ resizeOperateStyle.display = "none";
2920
+ } else if (!props2.setting.htmlPreview && !props2.setting.preview) {
2916
2921
  inputWrapperStyle.width = "100%";
2917
2922
  resizeOperateStyle.display = "none";
2918
2923
  } else {
@@ -2924,18 +2929,6 @@ const useResize = (props2, contentRef, resizeRef) => {
2924
2929
  immediate: true
2925
2930
  }
2926
2931
  );
2927
- watch(
2928
- () => props2.setting.previewOnly,
2929
- (po) => {
2930
- if (po) {
2931
- inputWrapperStyle.width = "0%";
2932
- resizeOperateStyle.display = "none";
2933
- } else {
2934
- inputWrapperStyle.width = state.resizedWidth;
2935
- resizeOperateStyle.display = "initial";
2936
- }
2937
- }
2938
- );
2939
2932
  return { inputWrapperStyle, resizeOperateStyle };
2940
2933
  };
2941
2934
  const Content = /* @__PURE__ */ defineComponent({
@@ -3,8 +3,7 @@ const keyMove = (trigger, moveHandler) => {
3
3
  const parent = trigger.parentElement || document.body;
4
4
  const width = parent.offsetWidth;
5
5
  const height = parent.offsetHeight;
6
- const { clientWidth } = document.documentElement;
7
- const { clientHeight } = document.documentElement;
6
+ const { clientWidth, clientHeight } = document.documentElement;
8
7
  const x = mdown.offsetX;
9
8
  const y = mdown.offsetY;
10
9
  const mouseMoveHandler = (e) => {
@@ -124,6 +124,9 @@ const useHighlight = (props) => {
124
124
  watch(
125
125
  () => highlight.value.css,
126
126
  () => {
127
+ if (props.noHighlight) {
128
+ return;
129
+ }
127
130
  updateHandler("link", {
128
131
  ...highlight.value.css,
129
132
  rel: "stylesheet",
@@ -163,14 +166,14 @@ const useMermaid = (props) => {
163
166
  }
164
167
  );
165
168
  onMounted(() => {
166
- var _a, _b, _c;
167
- if (props.noMermaid || ((_a = mermaidRef.value) == null ? void 0 : _a.instance)) {
169
+ var _a, _b;
170
+ if (props.noMermaid || mermaidRef.value) {
168
171
  return;
169
172
  }
170
173
  const jsSrc = editorExtensions.mermaid.js;
171
174
  if (/\.mjs/.test(jsSrc)) {
172
175
  appendHandler("link", {
173
- ...(_b = editorExtensionsAttrs.mermaid) == null ? void 0 : _b.js,
176
+ ...(_a = editorExtensionsAttrs.mermaid) == null ? void 0 : _a.js,
174
177
  rel: "modulepreload",
175
178
  href: jsSrc,
176
179
  id: `${prefix}-mermaid-m`
@@ -187,7 +190,7 @@ const useMermaid = (props) => {
187
190
  appendHandler(
188
191
  "script",
189
192
  {
190
- ...(_c = editorExtensionsAttrs.mermaid) == null ? void 0 : _c.js,
193
+ ...(_b = editorExtensionsAttrs.mermaid) == null ? void 0 : _b.js,
191
194
  src: jsSrc,
192
195
  id: `${prefix}-mermaid`,
193
196
  onload() {
@@ -614,7 +617,7 @@ const StrIcon = (name, customIcon) => {
614
617
  };
615
618
  const StrIcon$1 = StrIcon;
616
619
  const codetabs = (md, _opts) => {
617
- const defaultRender = md.renderer.rules.fence, unescapeAll = md.utils.unescapeAll, re = /\[(\w*)(?::([\w ]*))?\]/, mandatoryRe = /::close/;
620
+ const defaultRender = md.renderer.rules.fence, unescapeAll = md.utils.unescapeAll, re = /\[(\w*)(?::([\w ]*))?\]/, mandatoryRe = /::(open|close)/;
618
621
  const getInfo = (token) => {
619
622
  return token.info ? unescapeAll(token.info).trim() : "";
620
623
  };
@@ -627,9 +630,9 @@ const codetabs = (md, _opts) => {
627
630
  return info ? info.split(/(\s+)/g)[0] : "";
628
631
  };
629
632
  const getTagType = (token) => {
630
- const mandatory = mandatoryRe.test(token.info);
631
- const open = !mandatory && token.content.trim().split("\n").length < _opts.autoFoldThreshold;
632
- const tagContainer = mandatory || _opts.codeFoldable ? "details" : "div", tagHeader = mandatory || _opts.codeFoldable ? "summary" : "div";
633
+ const mandatory = token.info.match(mandatoryRe) || [];
634
+ const open = mandatory[1] === "open" || mandatory[1] !== "close" && _opts.codeFoldable && token.content.trim().split("\n").length < _opts.autoFoldThreshold;
635
+ const tagContainer = mandatory[1] || _opts.codeFoldable ? "details" : "div", tagHeader = mandatory[1] || _opts.codeFoldable ? "summary" : "div";
633
636
  return { open, tagContainer, tagHeader };
634
637
  };
635
638
  const fenceGroup = (tokens, idx, options, env, slf) => {
@@ -2571,17 +2574,38 @@ const useConfig = (props, context) => {
2571
2574
  htmlPreview: props.preview ? false : props.htmlPreview,
2572
2575
  previewOnly: false
2573
2576
  });
2577
+ const cacheSetting = reactive({ ...setting });
2574
2578
  const updateSetting = (k, v) => {
2575
- setting[k] = v === void 0 ? !setting[k] : v;
2576
- if (k === "preview") {
2577
- setting.htmlPreview = false;
2578
- setting.previewOnly = false;
2579
- } else if (k === "htmlPreview") {
2580
- setting.preview = false;
2581
- setting.previewOnly = false;
2582
- } else if (k === "previewOnly" && !setting.preview && !setting.htmlPreview) {
2583
- setting.preview = true;
2579
+ const realValue = v === void 0 ? !setting[k] : v;
2580
+ switch (k) {
2581
+ case "preview": {
2582
+ setting.htmlPreview = false;
2583
+ setting.previewOnly = false;
2584
+ break;
2585
+ }
2586
+ case "htmlPreview": {
2587
+ setting.preview = false;
2588
+ setting.previewOnly = false;
2589
+ break;
2590
+ }
2591
+ case "previewOnly": {
2592
+ if (realValue) {
2593
+ if (!setting.preview && !setting.htmlPreview) {
2594
+ setting.preview = true;
2595
+ }
2596
+ } else {
2597
+ if (!cacheSetting.preview) {
2598
+ setting.preview = false;
2599
+ }
2600
+ if (!cacheSetting.htmlPreview) {
2601
+ setting.htmlPreview = false;
2602
+ }
2603
+ }
2604
+ break;
2605
+ }
2584
2606
  }
2607
+ cacheSetting[k] = realValue;
2608
+ setting[k] = realValue;
2585
2609
  };
2586
2610
  let bodyOverflowHistory = "";
2587
2611
  const adjustBody = () => {