md-editor-v3 5.2.3 → 5.3.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.
@@ -2659,6 +2659,13 @@ const useCodeMirror = (props2) => {
2659
2659
  );
2660
2660
  }
2661
2661
  });
2662
+ eventName.bus.on(editorId, {
2663
+ name: eventName.SEND_EDITOR_VIEW,
2664
+ callback() {
2665
+ eventName.bus.emit(editorId, eventName.GET_EDITOR_VIEW, view2);
2666
+ }
2667
+ });
2668
+ eventName.bus.emit(editorId, eventName.GET_EDITOR_VIEW, view2);
2662
2669
  });
2663
2670
  vue.watch(
2664
2671
  theme,
@@ -2748,7 +2755,6 @@ const useResize = (props2, contentRef, resizeRef) => {
2748
2755
  left: props2.inputBoxWidth,
2749
2756
  display: "initial"
2750
2757
  });
2751
- const showPreviewWrapper = vue.ref(props2.setting.preview || props2.setting.htmlPreview);
2752
2758
  const resizeMousemove = (e) => {
2753
2759
  var _a, _b, _c;
2754
2760
  const maxWidth = ((_a = contentRef.value) == null ? void 0 : _a.offsetWidth) || 0;
@@ -2807,23 +2813,24 @@ const useResize = (props2, contentRef, resizeRef) => {
2807
2813
  if (props2.setting.previewOnly) {
2808
2814
  inputWrapperStyle.width = "0%";
2809
2815
  resizeOperateStyle.display = "none";
2810
- showPreviewWrapper.value = true;
2811
2816
  } else if (!props2.setting.htmlPreview && !props2.setting.preview) {
2812
2817
  inputWrapperStyle.width = "100%";
2813
2818
  resizeOperateStyle.display = "none";
2814
- showPreviewWrapper.value = false;
2815
2819
  } else {
2816
2820
  inputWrapperStyle.width = state2.resizedWidth;
2817
2821
  resizeOperateStyle.display = "initial";
2818
- showPreviewWrapper.value = true;
2819
2822
  }
2820
2823
  },
2821
2824
  {
2822
2825
  immediate: true
2823
2826
  }
2824
2827
  );
2825
- return { inputWrapperStyle, resizeOperateStyle, showPreviewWrapper };
2828
+ return {
2829
+ inputWrapperStyle,
2830
+ resizeOperateStyle
2831
+ };
2826
2832
  };
2833
+ const smoothScroll = util.createSmoothScroll();
2827
2834
  const Content = /* @__PURE__ */ vue.defineComponent({
2828
2835
  name: "MDEditorContent",
2829
2836
  props: MdPreview.contentProps,
@@ -2839,8 +2846,7 @@ const Content = /* @__PURE__ */ vue.defineComponent({
2839
2846
  } = useCodeMirror(props2);
2840
2847
  const {
2841
2848
  inputWrapperStyle,
2842
- resizeOperateStyle,
2843
- showPreviewWrapper
2849
+ resizeOperateStyle
2844
2850
  } = useResize(props2, contentRef, resizeRef);
2845
2851
  useAutoScroll(props2, html, codeMirrorUt);
2846
2852
  ctx.expose({
@@ -2860,7 +2866,7 @@ const Content = /* @__PURE__ */ vue.defineComponent({
2860
2866
  });
2861
2867
  return () => {
2862
2868
  return vue.createVNode("div", {
2863
- "class": `${config.prefix}-content${showPreviewWrapper.value ? " has-preview" : ""}`,
2869
+ "class": `${config.prefix}-content`,
2864
2870
  "ref": contentRef
2865
2871
  }, [vue.createVNode("div", {
2866
2872
  "class": `${config.prefix}-input-wrapper`,
@@ -2870,7 +2876,7 @@ const Content = /* @__PURE__ */ vue.defineComponent({
2870
2876
  "class": `${config.prefix}-resize-operate`,
2871
2877
  "style": resizeOperateStyle,
2872
2878
  "ref": resizeRef
2873
- }, null), showPreviewWrapper.value && vue.createVNode(MdPreview.ContentPreview, {
2879
+ }, null), vue.createVNode(MdPreview.ContentPreview, {
2874
2880
  "modelValue": props2.modelValue,
2875
2881
  "onChange": props2.onChange,
2876
2882
  "setting": props2.setting,
@@ -2888,14 +2894,29 @@ const Content = /* @__PURE__ */ vue.defineComponent({
2888
2894
  "noImgZoomIn": props2.noImgZoomIn,
2889
2895
  "sanitizeMermaid": props2.sanitizeMermaid,
2890
2896
  "codeFoldable": props2.codeFoldable,
2891
- "autoFoldThreshold": props2.autoFoldThreshold
2897
+ "autoFoldThreshold": props2.autoFoldThreshold,
2898
+ "onRemount": props2.onRemount
2892
2899
  }, null), props2.catalogVisible && vue.createVNode(MdCatalog.MdCatalog, {
2893
2900
  "theme": props2.theme,
2894
2901
  "class": `${config.prefix}-catalog-editor`,
2895
2902
  "editorId": editorId,
2896
2903
  "mdHeadingId": props2.mdHeadingId,
2897
2904
  "key": "internal-catalog",
2898
- "scrollElementOffsetTop": 2
2905
+ "scrollElementOffsetTop": 2,
2906
+ "syncWith": !props2.setting.preview ? "editor" : "preview",
2907
+ "onClick": (e, toc) => {
2908
+ var _a, _b;
2909
+ if (!props2.setting.preview && toc.line !== void 0) {
2910
+ e.preventDefault();
2911
+ const view2 = (_a = codeMirrorUt.value) == null ? void 0 : _a.view;
2912
+ if (view2) {
2913
+ const line = view2.state.doc.line(toc.line + 1);
2914
+ const top = (_b = view2.lineBlockAt(line.from)) == null ? void 0 : _b.top;
2915
+ const scroller = view2.scrollDOM;
2916
+ smoothScroll(scroller, top);
2917
+ }
2918
+ }
2919
+ }
2899
2920
  }, null)]);
2900
2921
  };
2901
2922
  }
@@ -3220,7 +3241,13 @@ const Editor = /* @__PURE__ */ vue.defineComponent({
3220
3241
  "sanitizeMermaid": props2.sanitizeMermaid,
3221
3242
  "transformImgUrl": props2.transformImgUrl,
3222
3243
  "codeFoldable": props2.codeFoldable,
3223
- "autoFoldThreshold": props2.autoFoldThreshold
3244
+ "autoFoldThreshold": props2.autoFoldThreshold,
3245
+ "onRemount": () => {
3246
+ if (props2.onRemount) {
3247
+ props2.onRemount();
3248
+ }
3249
+ ctx.emit("onRemount");
3250
+ }
3224
3251
  }, null), props2.footers.length > 0 && vue.createVNode(Footer, {
3225
3252
  "modelValue": props2.modelValue,
3226
3253
  "footers": props2.footers,
@@ -70,6 +70,8 @@ const PUSH_CATALOG = "pushCatalog";
70
70
  const RERENDER = "rerender";
71
71
  const EVENT_LISTENER = "eventListener";
72
72
  const TASK_STATE_CHANGED = "taskStateChanged";
73
+ const SEND_EDITOR_VIEW = "sendEditorView";
74
+ const GET_EDITOR_VIEW = "getEditorView";
73
75
  exports.BUILD_FINISHED = BUILD_FINISHED;
74
76
  exports.CATALOG_CHANGED = CATALOG_CHANGED;
75
77
  exports.CATALOG_VISIBLE_CHANGED = CATALOG_VISIBLE_CHANGED;
@@ -80,6 +82,7 @@ exports.CTRL_Z = CTRL_Z;
80
82
  exports.ERROR_CATCHER = ERROR_CATCHER;
81
83
  exports.EVENT_LISTENER = EVENT_LISTENER;
82
84
  exports.FULL_SCREEN_CHANGED = FULL_SCREEN_CHANGED;
85
+ exports.GET_EDITOR_VIEW = GET_EDITOR_VIEW;
83
86
  exports.HTML_PREVIEW_CHANGED = HTML_PREVIEW_CHANGED;
84
87
  exports.ON_SAVE = ON_SAVE;
85
88
  exports.OPEN_MODALS = OPEN_MODALS;
@@ -89,6 +92,7 @@ exports.PREVIEW_ONLY_CHANGED = PREVIEW_ONLY_CHANGED;
89
92
  exports.PUSH_CATALOG = PUSH_CATALOG;
90
93
  exports.REPLACE = REPLACE;
91
94
  exports.RERENDER = RERENDER;
95
+ exports.SEND_EDITOR_VIEW = SEND_EDITOR_VIEW;
92
96
  exports.TASK_STATE_CHANGED = TASK_STATE_CHANGED;
93
97
  exports.UPLOAD_IMAGE = UPLOAD_IMAGE;
94
98
  exports.bus = bus;
@@ -95,7 +95,6 @@ const useCopyCode = (props, html, key) => {
95
95
  vue.watch([html, key], htmlChanged);
96
96
  vue.watch(() => props.setting.preview, settingPreviewChanged);
97
97
  vue.watch(() => props.setting.htmlPreview, settingPreviewChanged);
98
- vue.watch(() => ult.value, initCopyEntry);
99
98
  vue.onMounted(initCopyEntry);
100
99
  };
101
100
  const useHighlight = (props) => {
@@ -585,7 +584,8 @@ const HeadingPlugin = (md, options) => {
585
584
  const level = token.markup.length;
586
585
  options.headsRef.value.push({
587
586
  text,
588
- level
587
+ level,
588
+ line: token.map[0]
589
589
  });
590
590
  if (token.map && token.level === 0) {
591
591
  token.attrSet(
@@ -655,6 +655,7 @@ const codetabs = (md, _opts) => {
655
655
  <div class="${config.prefix}-code-action">
656
656
  <span class="${config.prefix}-code-lang">${tokens[idx].info.trim()}</span>
657
657
  <span class="${config.prefix}-copy-button" data-tips="${codeCodeText}"${isIcon ? " data-is-icon=true" : ""}>${copyBtnHtml}</span>
658
+ ${_opts.extraTools || ""}
658
659
  ${tagContainer2 === "details" ? collapseTips : ""}
659
660
  </div>
660
661
  </${tagHeader2}>
@@ -723,6 +724,7 @@ const codetabs = (md, _opts) => {
723
724
  <div class="${config.prefix}-code-action">
724
725
  <span class="${config.prefix}-codetab-lang">${langs}</span>
725
726
  <span class="${config.prefix}-copy-button" data-tips="${codeCodeText}"${isIcon ? " data-is-icon=true" : ""}>${copyBtnHtml}</span>
727
+ ${_opts.extraTools || ""}
726
728
  ${tagContainer === "details" ? collapseTips : ""}
727
729
  </div>
728
730
  </${tagHeader}>
@@ -1088,6 +1090,23 @@ const useTaskState = (props, html) => {
1088
1090
  }
1089
1091
  );
1090
1092
  };
1093
+ const useRemount = (props, html, key) => {
1094
+ const handler = () => {
1095
+ vue.nextTick(() => {
1096
+ var _a;
1097
+ (_a = props.onRemount) == null ? void 0 : _a.call(props);
1098
+ });
1099
+ };
1100
+ const settingPreviewChanged = (nVal) => {
1101
+ if (nVal) {
1102
+ handler();
1103
+ }
1104
+ };
1105
+ vue.watch([html, key], handler);
1106
+ vue.watch(() => props.setting.preview, settingPreviewChanged);
1107
+ vue.watch(() => props.setting.htmlPreview, settingPreviewChanged);
1108
+ vue.onMounted(handler);
1109
+ };
1091
1110
  const contentPreviewProps = {
1092
1111
  modelValue: {
1093
1112
  type: String,
@@ -1152,6 +1171,9 @@ const contentPreviewProps = {
1152
1171
  },
1153
1172
  autoFoldThreshold: {
1154
1173
  type: Number
1174
+ },
1175
+ onRemount: {
1176
+ type: Function
1155
1177
  }
1156
1178
  };
1157
1179
  const contentProps = {
@@ -1245,6 +1267,7 @@ const ContentPreview = /* @__PURE__ */ vue.defineComponent({
1245
1267
  useCopyCode(props, html, key);
1246
1268
  userZoom(props, html);
1247
1269
  useTaskState(props, html);
1270
+ useRemount(props, html, key);
1248
1271
  return () => {
1249
1272
  return vue.createVNode(vue.Fragment, null, [props.setting.preview && vue.createVNode("div", {
1250
1273
  "id": `${editorId}-preview-wrapper`,
@@ -1894,6 +1917,15 @@ const mdPreviewProps = {
1894
1917
  autoFoldThreshold: {
1895
1918
  type: Number,
1896
1919
  default: 30
1920
+ },
1921
+ /**
1922
+ * 内容重新挂载事件
1923
+ *
1924
+ * 相比起onHtmlChanged,onRemount会在重新挂载后触发
1925
+ */
1926
+ onRemount: {
1927
+ type: Function,
1928
+ default: void 0
1897
1929
  }
1898
1930
  };
1899
1931
  const editorProps = {
@@ -2187,7 +2219,8 @@ const editorEmits = [
2187
2219
  "onFocus",
2188
2220
  "onInput",
2189
2221
  "onDrop",
2190
- "oninputBoxWidthChange"
2222
+ "oninputBoxWidthChange",
2223
+ "onRemount"
2191
2224
  ];
2192
2225
  const useExpose = (props, ctx, options) => {
2193
2226
  const { editorId } = options;
@@ -2257,7 +2290,8 @@ const MdPreview = /* @__PURE__ */ vue.defineComponent({
2257
2290
  "previewOnly": true,
2258
2291
  "sanitizeMermaid": props.sanitizeMermaid,
2259
2292
  "codeFoldable": props.codeFoldable,
2260
- "autoFoldThreshold": props.autoFoldThreshold
2293
+ "autoFoldThreshold": props.autoFoldThreshold,
2294
+ "onRemount": props.onRemount
2261
2295
  }, null)]);
2262
2296
  };
2263
2297
  }
@@ -330,8 +330,11 @@ const CatalogLink = /* @__PURE__ */ vue.defineComponent({
330
330
  "ref": currRef,
331
331
  "class": [`${config.prefix}-catalog-link`, tocItem.active && `${config.prefix}-catalog-active`],
332
332
  "onClick": (e) => {
333
- onClick(e, tocItem);
334
333
  e.stopPropagation();
334
+ onClick(e, tocItem);
335
+ if (e.defaultPrevented) {
336
+ return;
337
+ }
335
338
  const id = mdHeadingId(tocItem.text, tocItem.level, tocItem.index);
336
339
  const targetHeadEle = rootNodeRef.value.getElementById(id);
337
340
  const scrollContainer = scrollElementRef.value;
@@ -434,6 +437,15 @@ const props = {
434
437
  isScrollElementInShadow: {
435
438
  type: Boolean,
436
439
  default: false
440
+ },
441
+ /**
442
+ * 设置与哪个区域同步,默认与内容区域同步
443
+ *
444
+ * >= v5.3.0
445
+ */
446
+ syncWith: {
447
+ type: String,
448
+ default: "preview"
437
449
  }
438
450
  };
439
451
  const MdCatalog = /* @__PURE__ */ vue.defineComponent({
@@ -453,6 +465,7 @@ const MdCatalog = /* @__PURE__ */ vue.defineComponent({
453
465
  const scrollElementRef = vue.ref();
454
466
  const scrollContainerRef = vue.ref();
455
467
  const rootNodeRef = vue.ref();
468
+ const editorViewRef = vue.shallowRef();
456
469
  const indicatorStyles = vue.ref({});
457
470
  vue.provide("scrollElementRef", scrollElementRef);
458
471
  vue.provide("roorNodeRef", rootNodeRef);
@@ -461,11 +474,13 @@ const MdCatalog = /* @__PURE__ */ vue.defineComponent({
461
474
  state.list.forEach((listItem, index2) => {
462
475
  const {
463
476
  text,
464
- level
477
+ level,
478
+ line
465
479
  } = listItem;
466
480
  const item = {
467
481
  level,
468
482
  text,
483
+ line,
469
484
  index: index2 + 1,
470
485
  active: activeItem.value === listItem
471
486
  };
@@ -516,15 +531,25 @@ const MdCatalog = /* @__PURE__ */ vue.defineComponent({
516
531
  activeHead
517
532
  } = list.reduce((activeData, link, index$1) => {
518
533
  var _a;
519
- const linkEle = (_a = rootNodeRef.value) == null ? void 0 : _a.getElementById(props2.mdHeadingId(link.text, link.level, index$1 + 1));
520
- if (linkEle instanceof HTMLElement) {
521
- const relativeTop = index.getRelativeTop(linkEle, scrollElementRef.value);
522
- if (relativeTop < props2.offsetTop && relativeTop > activeData.minTop) {
523
- return {
524
- activeHead: link,
525
- minTop: relativeTop
526
- };
534
+ let relativeTop = 0;
535
+ if (props2.syncWith === "preview") {
536
+ const linkEle = (_a = rootNodeRef.value) == null ? void 0 : _a.getElementById(props2.mdHeadingId(link.text, link.level, index$1 + 1));
537
+ if (linkEle instanceof HTMLElement) {
538
+ relativeTop = index.getRelativeTop(linkEle, scrollElementRef.value);
527
539
  }
540
+ } else {
541
+ const view = editorViewRef.value;
542
+ if (view) {
543
+ const top = view.lineBlockAt(view.state.doc.line(link.line + 1).from).top;
544
+ const scrollTop = view.scrollDOM.scrollTop;
545
+ relativeTop = top - scrollTop;
546
+ }
547
+ }
548
+ if (relativeTop < props2.offsetTop && relativeTop > activeData.minTop) {
549
+ return {
550
+ activeHead: link,
551
+ minTop: relativeTop
552
+ };
528
553
  }
529
554
  return activeData;
530
555
  }, {
@@ -546,25 +571,41 @@ const MdCatalog = /* @__PURE__ */ vue.defineComponent({
546
571
  findActiveHeading(state.list);
547
572
  };
548
573
  const catalogChangedHandler = (_list) => {
549
- var _a, _b;
550
- const scrollElement = getScrollElement();
551
- scrollElementRef.value = scrollElement;
552
- scrollContainerRef.value = scrollElement === document.documentElement ? document : scrollElement;
574
+ var _a, _b, _c;
553
575
  (_a = scrollContainerRef.value) == null ? void 0 : _a.removeEventListener("scroll", scrollHandler);
576
+ if (props2.syncWith === "editor") {
577
+ scrollContainerRef.value = (_b = editorViewRef.value) == null ? void 0 : _b.scrollDOM;
578
+ } else {
579
+ const scrollElement = getScrollElement();
580
+ scrollElementRef.value = scrollElement;
581
+ scrollContainerRef.value = scrollElement === document.documentElement ? document : scrollElement;
582
+ }
554
583
  findActiveHeading(_list);
555
- (_b = scrollContainerRef.value) == null ? void 0 : _b.addEventListener("scroll", scrollHandler);
584
+ (_c = scrollContainerRef.value) == null ? void 0 : _c.addEventListener("scroll", scrollHandler);
585
+ };
586
+ const getEditorView = (view) => {
587
+ editorViewRef.value = view;
556
588
  };
589
+ vue.watch(() => props2.syncWith, () => {
590
+ catalogChangedHandler(state.list);
591
+ });
557
592
  vue.onMounted(() => {
558
593
  rootNodeRef.value = catalogRef.value.getRootNode();
559
594
  eventName.bus.on(editorId, {
560
595
  name: eventName.CATALOG_CHANGED,
561
596
  callback: catalogChangedHandler
562
597
  });
598
+ eventName.bus.on(editorId, {
599
+ name: eventName.GET_EDITOR_VIEW,
600
+ callback: getEditorView
601
+ });
563
602
  eventName.bus.emit(editorId, eventName.PUSH_CATALOG);
603
+ eventName.bus.emit(editorId, eventName.SEND_EDITOR_VIEW);
564
604
  });
565
605
  vue.onBeforeUnmount(() => {
566
606
  var _a;
567
607
  eventName.bus.remove(editorId, eventName.CATALOG_CHANGED, catalogChangedHandler);
608
+ eventName.bus.remove(editorId, eventName.GET_EDITOR_VIEW, getEditorView);
568
609
  (_a = scrollContainerRef.value) == null ? void 0 : _a.removeEventListener("scroll", scrollHandler);
569
610
  });
570
611
  return () => vue.createVNode("div", {
@@ -584,9 +625,8 @@ const MdCatalog = /* @__PURE__ */ vue.defineComponent({
584
625
  "onClick": (e, t) => {
585
626
  if (props2.onClick) {
586
627
  props2.onClick(e, t);
587
- } else {
588
- ctx.emit("onClick", e, t);
589
628
  }
629
+ ctx.emit("onClick", e, t);
590
630
  },
591
631
  "scrollElementOffsetTop": props2.scrollElementOffsetTop
592
632
  }, null);
@@ -3,9 +3,9 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
4
  import { defineComponent, createVNode, inject, ref, onMounted, reactive, computed, watch, toRef, nextTick, Fragment, cloneVNode, shallowRef, onBeforeUnmount } from "vue";
5
5
  import { p as prefix, d as configOption, a as allToolbar, M as MinInputBoxWidth, b as allFooter } from "./chunks/config.mjs";
6
- import { draggingScroll, linkTo, throttle } from "@vavt/util";
6
+ import { draggingScroll, linkTo, throttle, createSmoothScroll } from "@vavt/util";
7
7
  import { a as Dropdown, D as DropdownToolbar } from "./chunks/index2.mjs";
8
- import { b as bus, C as CHANGE_FULL_SCREEN, E as ERROR_CATCHER, U as UPLOAD_IMAGE, O as OPEN_MODALS, R as REPLACE, a as CHANGE_CATALOG_VISIBLE, c as ON_SAVE, d as CTRL_SHIFT_Z, e as CTRL_Z, f as EVENT_LISTENER, T as TASK_STATE_CHANGED } from "./chunks/event-name.mjs";
8
+ import { b as bus, C as CHANGE_FULL_SCREEN, E as ERROR_CATCHER, U as UPLOAD_IMAGE, O as OPEN_MODALS, R as REPLACE, a as CHANGE_CATALOG_VISIBLE, c as ON_SAVE, d as CTRL_SHIFT_Z, e as CTRL_Z, f as EVENT_LISTENER, T as TASK_STATE_CHANGED, S as SEND_EDITOR_VIEW, G as GET_EDITOR_VIEW } from "./chunks/event-name.mjs";
9
9
  import { a as appendHandler } from "./chunks/dom.mjs";
10
10
  import { C as CDN_IDS, c as contentProps, a as ContentPreview, e as editorProps, b as editorEmits, u as useProvide, d as useConfig, f as useCatalog, g as useOnSave, h as useExpansion, i as useErrorCatcher, j as useExpose, M as MdPreview } from "./chunks/index.mjs";
11
11
  import { M as MdModal, I as Icon } from "./chunks/index4.mjs";
@@ -2658,6 +2658,13 @@ const useCodeMirror = (props2) => {
2658
2658
  );
2659
2659
  }
2660
2660
  });
2661
+ bus.on(editorId, {
2662
+ name: SEND_EDITOR_VIEW,
2663
+ callback() {
2664
+ bus.emit(editorId, GET_EDITOR_VIEW, view);
2665
+ }
2666
+ });
2667
+ bus.emit(editorId, GET_EDITOR_VIEW, view);
2661
2668
  });
2662
2669
  watch(
2663
2670
  theme,
@@ -2747,7 +2754,6 @@ const useResize = (props2, contentRef, resizeRef) => {
2747
2754
  left: props2.inputBoxWidth,
2748
2755
  display: "initial"
2749
2756
  });
2750
- const showPreviewWrapper = ref(props2.setting.preview || props2.setting.htmlPreview);
2751
2757
  const resizeMousemove = (e) => {
2752
2758
  var _a, _b, _c;
2753
2759
  const maxWidth = ((_a = contentRef.value) == null ? void 0 : _a.offsetWidth) || 0;
@@ -2806,23 +2812,24 @@ const useResize = (props2, contentRef, resizeRef) => {
2806
2812
  if (props2.setting.previewOnly) {
2807
2813
  inputWrapperStyle.width = "0%";
2808
2814
  resizeOperateStyle.display = "none";
2809
- showPreviewWrapper.value = true;
2810
2815
  } else if (!props2.setting.htmlPreview && !props2.setting.preview) {
2811
2816
  inputWrapperStyle.width = "100%";
2812
2817
  resizeOperateStyle.display = "none";
2813
- showPreviewWrapper.value = false;
2814
2818
  } else {
2815
2819
  inputWrapperStyle.width = state.resizedWidth;
2816
2820
  resizeOperateStyle.display = "initial";
2817
- showPreviewWrapper.value = true;
2818
2821
  }
2819
2822
  },
2820
2823
  {
2821
2824
  immediate: true
2822
2825
  }
2823
2826
  );
2824
- return { inputWrapperStyle, resizeOperateStyle, showPreviewWrapper };
2827
+ return {
2828
+ inputWrapperStyle,
2829
+ resizeOperateStyle
2830
+ };
2825
2831
  };
2832
+ const smoothScroll = createSmoothScroll();
2826
2833
  const Content = /* @__PURE__ */ defineComponent({
2827
2834
  name: "MDEditorContent",
2828
2835
  props: contentProps,
@@ -2838,8 +2845,7 @@ const Content = /* @__PURE__ */ defineComponent({
2838
2845
  } = useCodeMirror(props2);
2839
2846
  const {
2840
2847
  inputWrapperStyle,
2841
- resizeOperateStyle,
2842
- showPreviewWrapper
2848
+ resizeOperateStyle
2843
2849
  } = useResize(props2, contentRef, resizeRef);
2844
2850
  useAutoScroll(props2, html, codeMirrorUt);
2845
2851
  ctx.expose({
@@ -2859,7 +2865,7 @@ const Content = /* @__PURE__ */ defineComponent({
2859
2865
  });
2860
2866
  return () => {
2861
2867
  return createVNode("div", {
2862
- "class": `${prefix}-content${showPreviewWrapper.value ? " has-preview" : ""}`,
2868
+ "class": `${prefix}-content`,
2863
2869
  "ref": contentRef
2864
2870
  }, [createVNode("div", {
2865
2871
  "class": `${prefix}-input-wrapper`,
@@ -2869,7 +2875,7 @@ const Content = /* @__PURE__ */ defineComponent({
2869
2875
  "class": `${prefix}-resize-operate`,
2870
2876
  "style": resizeOperateStyle,
2871
2877
  "ref": resizeRef
2872
- }, null), showPreviewWrapper.value && createVNode(ContentPreview, {
2878
+ }, null), createVNode(ContentPreview, {
2873
2879
  "modelValue": props2.modelValue,
2874
2880
  "onChange": props2.onChange,
2875
2881
  "setting": props2.setting,
@@ -2887,14 +2893,29 @@ const Content = /* @__PURE__ */ defineComponent({
2887
2893
  "noImgZoomIn": props2.noImgZoomIn,
2888
2894
  "sanitizeMermaid": props2.sanitizeMermaid,
2889
2895
  "codeFoldable": props2.codeFoldable,
2890
- "autoFoldThreshold": props2.autoFoldThreshold
2896
+ "autoFoldThreshold": props2.autoFoldThreshold,
2897
+ "onRemount": props2.onRemount
2891
2898
  }, null), props2.catalogVisible && createVNode(MdCatalog, {
2892
2899
  "theme": props2.theme,
2893
2900
  "class": `${prefix}-catalog-editor`,
2894
2901
  "editorId": editorId,
2895
2902
  "mdHeadingId": props2.mdHeadingId,
2896
2903
  "key": "internal-catalog",
2897
- "scrollElementOffsetTop": 2
2904
+ "scrollElementOffsetTop": 2,
2905
+ "syncWith": !props2.setting.preview ? "editor" : "preview",
2906
+ "onClick": (e, toc) => {
2907
+ var _a, _b;
2908
+ if (!props2.setting.preview && toc.line !== void 0) {
2909
+ e.preventDefault();
2910
+ const view = (_a = codeMirrorUt.value) == null ? void 0 : _a.view;
2911
+ if (view) {
2912
+ const line = view.state.doc.line(toc.line + 1);
2913
+ const top = (_b = view.lineBlockAt(line.from)) == null ? void 0 : _b.top;
2914
+ const scroller = view.scrollDOM;
2915
+ smoothScroll(scroller, top);
2916
+ }
2917
+ }
2918
+ }
2898
2919
  }, null)]);
2899
2920
  };
2900
2921
  }
@@ -3219,7 +3240,13 @@ const Editor = /* @__PURE__ */ defineComponent({
3219
3240
  "sanitizeMermaid": props2.sanitizeMermaid,
3220
3241
  "transformImgUrl": props2.transformImgUrl,
3221
3242
  "codeFoldable": props2.codeFoldable,
3222
- "autoFoldThreshold": props2.autoFoldThreshold
3243
+ "autoFoldThreshold": props2.autoFoldThreshold,
3244
+ "onRemount": () => {
3245
+ if (props2.onRemount) {
3246
+ props2.onRemount();
3247
+ }
3248
+ ctx.emit("onRemount");
3249
+ }
3223
3250
  }, null), props2.footers.length > 0 && createVNode(Footer, {
3224
3251
  "modelValue": props2.modelValue,
3225
3252
  "footers": props2.footers,
@@ -69,15 +69,19 @@ const PUSH_CATALOG = "pushCatalog";
69
69
  const RERENDER = "rerender";
70
70
  const EVENT_LISTENER = "eventListener";
71
71
  const TASK_STATE_CHANGED = "taskStateChanged";
72
+ const SEND_EDITOR_VIEW = "sendEditorView";
73
+ const GET_EDITOR_VIEW = "getEditorView";
72
74
  export {
73
75
  BUILD_FINISHED as B,
74
76
  CHANGE_FULL_SCREEN as C,
75
77
  ERROR_CATCHER as E,
76
78
  FULL_SCREEN_CHANGED as F,
79
+ GET_EDITOR_VIEW as G,
77
80
  HTML_PREVIEW_CHANGED as H,
78
81
  OPEN_MODALS as O,
79
82
  PUSH_CATALOG as P,
80
83
  REPLACE as R,
84
+ SEND_EDITOR_VIEW as S,
81
85
  TASK_STATE_CHANGED as T,
82
86
  UPLOAD_IMAGE as U,
83
87
  CHANGE_CATALOG_VISIBLE as a,
@@ -94,7 +94,6 @@ const useCopyCode = (props, html, key) => {
94
94
  watch([html, key], htmlChanged);
95
95
  watch(() => props.setting.preview, settingPreviewChanged);
96
96
  watch(() => props.setting.htmlPreview, settingPreviewChanged);
97
- watch(() => ult.value, initCopyEntry);
98
97
  onMounted(initCopyEntry);
99
98
  };
100
99
  const useHighlight = (props) => {
@@ -584,7 +583,8 @@ const HeadingPlugin = (md, options) => {
584
583
  const level = token.markup.length;
585
584
  options.headsRef.value.push({
586
585
  text,
587
- level
586
+ level,
587
+ line: token.map[0]
588
588
  });
589
589
  if (token.map && token.level === 0) {
590
590
  token.attrSet(
@@ -654,6 +654,7 @@ const codetabs = (md, _opts) => {
654
654
  <div class="${prefix}-code-action">
655
655
  <span class="${prefix}-code-lang">${tokens[idx].info.trim()}</span>
656
656
  <span class="${prefix}-copy-button" data-tips="${codeCodeText}"${isIcon ? " data-is-icon=true" : ""}>${copyBtnHtml}</span>
657
+ ${_opts.extraTools || ""}
657
658
  ${tagContainer2 === "details" ? collapseTips : ""}
658
659
  </div>
659
660
  </${tagHeader2}>
@@ -722,6 +723,7 @@ const codetabs = (md, _opts) => {
722
723
  <div class="${prefix}-code-action">
723
724
  <span class="${prefix}-codetab-lang">${langs}</span>
724
725
  <span class="${prefix}-copy-button" data-tips="${codeCodeText}"${isIcon ? " data-is-icon=true" : ""}>${copyBtnHtml}</span>
726
+ ${_opts.extraTools || ""}
725
727
  ${tagContainer === "details" ? collapseTips : ""}
726
728
  </div>
727
729
  </${tagHeader}>
@@ -1087,6 +1089,23 @@ const useTaskState = (props, html) => {
1087
1089
  }
1088
1090
  );
1089
1091
  };
1092
+ const useRemount = (props, html, key) => {
1093
+ const handler = () => {
1094
+ nextTick(() => {
1095
+ var _a;
1096
+ (_a = props.onRemount) == null ? void 0 : _a.call(props);
1097
+ });
1098
+ };
1099
+ const settingPreviewChanged = (nVal) => {
1100
+ if (nVal) {
1101
+ handler();
1102
+ }
1103
+ };
1104
+ watch([html, key], handler);
1105
+ watch(() => props.setting.preview, settingPreviewChanged);
1106
+ watch(() => props.setting.htmlPreview, settingPreviewChanged);
1107
+ onMounted(handler);
1108
+ };
1090
1109
  const contentPreviewProps = {
1091
1110
  modelValue: {
1092
1111
  type: String,
@@ -1151,6 +1170,9 @@ const contentPreviewProps = {
1151
1170
  },
1152
1171
  autoFoldThreshold: {
1153
1172
  type: Number
1173
+ },
1174
+ onRemount: {
1175
+ type: Function
1154
1176
  }
1155
1177
  };
1156
1178
  const contentProps = {
@@ -1244,6 +1266,7 @@ const ContentPreview = /* @__PURE__ */ defineComponent({
1244
1266
  useCopyCode(props, html, key);
1245
1267
  userZoom(props, html);
1246
1268
  useTaskState(props, html);
1269
+ useRemount(props, html, key);
1247
1270
  return () => {
1248
1271
  return createVNode(Fragment, null, [props.setting.preview && createVNode("div", {
1249
1272
  "id": `${editorId}-preview-wrapper`,
@@ -1893,6 +1916,15 @@ const mdPreviewProps = {
1893
1916
  autoFoldThreshold: {
1894
1917
  type: Number,
1895
1918
  default: 30
1919
+ },
1920
+ /**
1921
+ * 内容重新挂载事件
1922
+ *
1923
+ * 相比起onHtmlChanged,onRemount会在重新挂载后触发
1924
+ */
1925
+ onRemount: {
1926
+ type: Function,
1927
+ default: void 0
1896
1928
  }
1897
1929
  };
1898
1930
  const editorProps = {
@@ -2186,7 +2218,8 @@ const editorEmits = [
2186
2218
  "onFocus",
2187
2219
  "onInput",
2188
2220
  "onDrop",
2189
- "oninputBoxWidthChange"
2221
+ "oninputBoxWidthChange",
2222
+ "onRemount"
2190
2223
  ];
2191
2224
  const useExpose = (props, ctx, options) => {
2192
2225
  const { editorId } = options;
@@ -2256,7 +2289,8 @@ const MdPreview = /* @__PURE__ */ defineComponent({
2256
2289
  "previewOnly": true,
2257
2290
  "sanitizeMermaid": props.sanitizeMermaid,
2258
2291
  "codeFoldable": props.codeFoldable,
2259
- "autoFoldThreshold": props.autoFoldThreshold
2292
+ "autoFoldThreshold": props.autoFoldThreshold,
2293
+ "onRemount": props.onRemount
2260
2294
  }, null)]);
2261
2295
  };
2262
2296
  }