md-editor-v3 5.2.2 → 5.3.0-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.
- package/lib/cjs/MdEditor.cjs +24 -2
- package/lib/cjs/chunks/event-name.cjs +4 -0
- package/lib/cjs/chunks/index.cjs +2 -1
- package/lib/cjs/chunks/index3.cjs +57 -17
- package/lib/es/MdEditor.mjs +26 -4
- package/lib/es/chunks/event-name.mjs +4 -0
- package/lib/es/chunks/index.mjs +2 -1
- package/lib/es/chunks/index3.mjs +58 -18
- package/lib/types/MdCatalog/MdCatalog.d.ts +3 -0
- package/lib/types/MdEditor/static/event-name.d.ts +2 -0
- package/lib/types/MdEditor/type.d.ts +1 -0
- package/lib/umd/index.js +93 -93
- package/package.json +1 -1
package/lib/cjs/MdEditor.cjs
CHANGED
|
@@ -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,
|
|
@@ -2824,6 +2831,7 @@ const useResize = (props2, contentRef, resizeRef) => {
|
|
|
2824
2831
|
);
|
|
2825
2832
|
return { inputWrapperStyle, resizeOperateStyle, showPreviewWrapper };
|
|
2826
2833
|
};
|
|
2834
|
+
const smoothScroll = util.createSmoothScroll();
|
|
2827
2835
|
const Content = /* @__PURE__ */ vue.defineComponent({
|
|
2828
2836
|
name: "MDEditorContent",
|
|
2829
2837
|
props: MdPreview.contentProps,
|
|
@@ -2870,7 +2878,7 @@ const Content = /* @__PURE__ */ vue.defineComponent({
|
|
|
2870
2878
|
"class": `${config.prefix}-resize-operate`,
|
|
2871
2879
|
"style": resizeOperateStyle,
|
|
2872
2880
|
"ref": resizeRef
|
|
2873
|
-
}, null),
|
|
2881
|
+
}, null), vue.createVNode(MdPreview.ContentPreview, {
|
|
2874
2882
|
"modelValue": props2.modelValue,
|
|
2875
2883
|
"onChange": props2.onChange,
|
|
2876
2884
|
"setting": props2.setting,
|
|
@@ -2895,7 +2903,21 @@ const Content = /* @__PURE__ */ vue.defineComponent({
|
|
|
2895
2903
|
"editorId": editorId,
|
|
2896
2904
|
"mdHeadingId": props2.mdHeadingId,
|
|
2897
2905
|
"key": "internal-catalog",
|
|
2898
|
-
"scrollElementOffsetTop": 2
|
|
2906
|
+
"scrollElementOffsetTop": 2,
|
|
2907
|
+
"syncWith": !props2.setting.preview ? "editor" : "preview",
|
|
2908
|
+
"onClick": (e, toc) => {
|
|
2909
|
+
var _a, _b;
|
|
2910
|
+
if (!props2.setting.preview && toc.line !== void 0) {
|
|
2911
|
+
e.preventDefault();
|
|
2912
|
+
const view2 = (_a = codeMirrorUt.value) == null ? void 0 : _a.view;
|
|
2913
|
+
if (view2) {
|
|
2914
|
+
const line = view2.state.doc.line(toc.line + 1);
|
|
2915
|
+
const top = (_b = view2.lineBlockAt(line.from)) == null ? void 0 : _b.top;
|
|
2916
|
+
const scroller = view2.scrollDOM;
|
|
2917
|
+
smoothScroll(scroller, top);
|
|
2918
|
+
}
|
|
2919
|
+
}
|
|
2920
|
+
}
|
|
2899
2921
|
}, null)]);
|
|
2900
2922
|
};
|
|
2901
2923
|
}
|
|
@@ -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;
|
package/lib/cjs/chunks/index.cjs
CHANGED
|
@@ -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
|
-
|
|
520
|
-
if (
|
|
521
|
-
const
|
|
522
|
-
if (
|
|
523
|
-
|
|
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
|
-
(
|
|
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);
|
package/lib/es/MdEditor.mjs
CHANGED
|
@@ -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,
|
|
@@ -2823,6 +2830,7 @@ const useResize = (props2, contentRef, resizeRef) => {
|
|
|
2823
2830
|
);
|
|
2824
2831
|
return { inputWrapperStyle, resizeOperateStyle, showPreviewWrapper };
|
|
2825
2832
|
};
|
|
2833
|
+
const smoothScroll = createSmoothScroll();
|
|
2826
2834
|
const Content = /* @__PURE__ */ defineComponent({
|
|
2827
2835
|
name: "MDEditorContent",
|
|
2828
2836
|
props: contentProps,
|
|
@@ -2869,7 +2877,7 @@ const Content = /* @__PURE__ */ defineComponent({
|
|
|
2869
2877
|
"class": `${prefix}-resize-operate`,
|
|
2870
2878
|
"style": resizeOperateStyle,
|
|
2871
2879
|
"ref": resizeRef
|
|
2872
|
-
}, null),
|
|
2880
|
+
}, null), createVNode(ContentPreview, {
|
|
2873
2881
|
"modelValue": props2.modelValue,
|
|
2874
2882
|
"onChange": props2.onChange,
|
|
2875
2883
|
"setting": props2.setting,
|
|
@@ -2894,7 +2902,21 @@ const Content = /* @__PURE__ */ defineComponent({
|
|
|
2894
2902
|
"editorId": editorId,
|
|
2895
2903
|
"mdHeadingId": props2.mdHeadingId,
|
|
2896
2904
|
"key": "internal-catalog",
|
|
2897
|
-
"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 view = (_a = codeMirrorUt.value) == null ? void 0 : _a.view;
|
|
2912
|
+
if (view) {
|
|
2913
|
+
const line = view.state.doc.line(toc.line + 1);
|
|
2914
|
+
const top = (_b = view.lineBlockAt(line.from)) == null ? void 0 : _b.top;
|
|
2915
|
+
const scroller = view.scrollDOM;
|
|
2916
|
+
smoothScroll(scroller, top);
|
|
2917
|
+
}
|
|
2918
|
+
}
|
|
2919
|
+
}
|
|
2898
2920
|
}, null)]);
|
|
2899
2921
|
};
|
|
2900
2922
|
}
|
|
@@ -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,
|
package/lib/es/chunks/index.mjs
CHANGED
package/lib/es/chunks/index3.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineComponent, inject, ref, watch, nextTick, createVNode, reactive, shallowRef, provide, computed, onMounted, onBeforeUnmount, Fragment } from "vue";
|
|
2
2
|
import { p as prefix } from "./config.mjs";
|
|
3
3
|
import { a as getRelativeTop } from "./index5.mjs";
|
|
4
|
-
import { b as bus, g as CATALOG_CHANGED, P as PUSH_CATALOG } from "./event-name.mjs";
|
|
4
|
+
import { b as bus, g as CATALOG_CHANGED, G as GET_EDITOR_VIEW, P as PUSH_CATALOG, S as SEND_EDITOR_VIEW } from "./event-name.mjs";
|
|
5
5
|
import { debounce, createSmoothScroll } from "@vavt/util";
|
|
6
6
|
const DATA_LINE_SELECTOR = `.${prefix}-preview > [data-line]`;
|
|
7
7
|
const getComputedStyleNum = (ele, key) => {
|
|
@@ -329,8 +329,11 @@ const CatalogLink = /* @__PURE__ */ defineComponent({
|
|
|
329
329
|
"ref": currRef,
|
|
330
330
|
"class": [`${prefix}-catalog-link`, tocItem.active && `${prefix}-catalog-active`],
|
|
331
331
|
"onClick": (e) => {
|
|
332
|
-
onClick(e, tocItem);
|
|
333
332
|
e.stopPropagation();
|
|
333
|
+
onClick(e, tocItem);
|
|
334
|
+
if (e.defaultPrevented) {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
334
337
|
const id = mdHeadingId(tocItem.text, tocItem.level, tocItem.index);
|
|
335
338
|
const targetHeadEle = rootNodeRef.value.getElementById(id);
|
|
336
339
|
const scrollContainer = scrollElementRef.value;
|
|
@@ -433,6 +436,15 @@ const props = {
|
|
|
433
436
|
isScrollElementInShadow: {
|
|
434
437
|
type: Boolean,
|
|
435
438
|
default: false
|
|
439
|
+
},
|
|
440
|
+
/**
|
|
441
|
+
* 设置与哪个区域同步,默认与内容区域同步
|
|
442
|
+
*
|
|
443
|
+
* >= v5.3.0
|
|
444
|
+
*/
|
|
445
|
+
syncWith: {
|
|
446
|
+
type: String,
|
|
447
|
+
default: "preview"
|
|
436
448
|
}
|
|
437
449
|
};
|
|
438
450
|
const MdCatalog = /* @__PURE__ */ defineComponent({
|
|
@@ -452,6 +464,7 @@ const MdCatalog = /* @__PURE__ */ defineComponent({
|
|
|
452
464
|
const scrollElementRef = ref();
|
|
453
465
|
const scrollContainerRef = ref();
|
|
454
466
|
const rootNodeRef = ref();
|
|
467
|
+
const editorViewRef = shallowRef();
|
|
455
468
|
const indicatorStyles = ref({});
|
|
456
469
|
provide("scrollElementRef", scrollElementRef);
|
|
457
470
|
provide("roorNodeRef", rootNodeRef);
|
|
@@ -460,11 +473,13 @@ const MdCatalog = /* @__PURE__ */ defineComponent({
|
|
|
460
473
|
state.list.forEach((listItem, index) => {
|
|
461
474
|
const {
|
|
462
475
|
text,
|
|
463
|
-
level
|
|
476
|
+
level,
|
|
477
|
+
line
|
|
464
478
|
} = listItem;
|
|
465
479
|
const item = {
|
|
466
480
|
level,
|
|
467
481
|
text,
|
|
482
|
+
line,
|
|
468
483
|
index: index + 1,
|
|
469
484
|
active: activeItem.value === listItem
|
|
470
485
|
};
|
|
@@ -515,15 +530,25 @@ const MdCatalog = /* @__PURE__ */ defineComponent({
|
|
|
515
530
|
activeHead
|
|
516
531
|
} = list.reduce((activeData, link, index) => {
|
|
517
532
|
var _a;
|
|
518
|
-
|
|
519
|
-
if (
|
|
520
|
-
const
|
|
521
|
-
if (
|
|
522
|
-
|
|
523
|
-
activeHead: link,
|
|
524
|
-
minTop: relativeTop
|
|
525
|
-
};
|
|
533
|
+
let relativeTop = 0;
|
|
534
|
+
if (props2.syncWith === "preview") {
|
|
535
|
+
const linkEle = (_a = rootNodeRef.value) == null ? void 0 : _a.getElementById(props2.mdHeadingId(link.text, link.level, index + 1));
|
|
536
|
+
if (linkEle instanceof HTMLElement) {
|
|
537
|
+
relativeTop = getRelativeTop(linkEle, scrollElementRef.value);
|
|
526
538
|
}
|
|
539
|
+
} else {
|
|
540
|
+
const view = editorViewRef.value;
|
|
541
|
+
if (view) {
|
|
542
|
+
const top = view.lineBlockAt(view.state.doc.line(link.line + 1).from).top;
|
|
543
|
+
const scrollTop = view.scrollDOM.scrollTop;
|
|
544
|
+
relativeTop = top - scrollTop;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
if (relativeTop < props2.offsetTop && relativeTop > activeData.minTop) {
|
|
548
|
+
return {
|
|
549
|
+
activeHead: link,
|
|
550
|
+
minTop: relativeTop
|
|
551
|
+
};
|
|
527
552
|
}
|
|
528
553
|
return activeData;
|
|
529
554
|
}, {
|
|
@@ -545,25 +570,41 @@ const MdCatalog = /* @__PURE__ */ defineComponent({
|
|
|
545
570
|
findActiveHeading(state.list);
|
|
546
571
|
};
|
|
547
572
|
const catalogChangedHandler = (_list) => {
|
|
548
|
-
var _a, _b;
|
|
549
|
-
const scrollElement = getScrollElement();
|
|
550
|
-
scrollElementRef.value = scrollElement;
|
|
551
|
-
scrollContainerRef.value = scrollElement === document.documentElement ? document : scrollElement;
|
|
573
|
+
var _a, _b, _c;
|
|
552
574
|
(_a = scrollContainerRef.value) == null ? void 0 : _a.removeEventListener("scroll", scrollHandler);
|
|
575
|
+
if (props2.syncWith === "editor") {
|
|
576
|
+
scrollContainerRef.value = (_b = editorViewRef.value) == null ? void 0 : _b.scrollDOM;
|
|
577
|
+
} else {
|
|
578
|
+
const scrollElement = getScrollElement();
|
|
579
|
+
scrollElementRef.value = scrollElement;
|
|
580
|
+
scrollContainerRef.value = scrollElement === document.documentElement ? document : scrollElement;
|
|
581
|
+
}
|
|
553
582
|
findActiveHeading(_list);
|
|
554
|
-
(
|
|
583
|
+
(_c = scrollContainerRef.value) == null ? void 0 : _c.addEventListener("scroll", scrollHandler);
|
|
584
|
+
};
|
|
585
|
+
const getEditorView = (view) => {
|
|
586
|
+
editorViewRef.value = view;
|
|
555
587
|
};
|
|
588
|
+
watch(() => props2.syncWith, () => {
|
|
589
|
+
catalogChangedHandler(state.list);
|
|
590
|
+
});
|
|
556
591
|
onMounted(() => {
|
|
557
592
|
rootNodeRef.value = catalogRef.value.getRootNode();
|
|
558
593
|
bus.on(editorId, {
|
|
559
594
|
name: CATALOG_CHANGED,
|
|
560
595
|
callback: catalogChangedHandler
|
|
561
596
|
});
|
|
597
|
+
bus.on(editorId, {
|
|
598
|
+
name: GET_EDITOR_VIEW,
|
|
599
|
+
callback: getEditorView
|
|
600
|
+
});
|
|
562
601
|
bus.emit(editorId, PUSH_CATALOG);
|
|
602
|
+
bus.emit(editorId, SEND_EDITOR_VIEW);
|
|
563
603
|
});
|
|
564
604
|
onBeforeUnmount(() => {
|
|
565
605
|
var _a;
|
|
566
606
|
bus.remove(editorId, CATALOG_CHANGED, catalogChangedHandler);
|
|
607
|
+
bus.remove(editorId, GET_EDITOR_VIEW, getEditorView);
|
|
567
608
|
(_a = scrollContainerRef.value) == null ? void 0 : _a.removeEventListener("scroll", scrollHandler);
|
|
568
609
|
});
|
|
569
610
|
return () => createVNode("div", {
|
|
@@ -583,9 +624,8 @@ const MdCatalog = /* @__PURE__ */ defineComponent({
|
|
|
583
624
|
"onClick": (e, t) => {
|
|
584
625
|
if (props2.onClick) {
|
|
585
626
|
props2.onClick(e, t);
|
|
586
|
-
} else {
|
|
587
|
-
ctx.emit("onClick", e, t);
|
|
588
627
|
}
|
|
628
|
+
ctx.emit("onClick", e, t);
|
|
589
629
|
},
|
|
590
630
|
"scrollElementOffsetTop": props2.scrollElementOffsetTop
|
|
591
631
|
}, null);
|
|
@@ -10,6 +10,7 @@ declare const MdCatalog: import("vue").DefineComponent<{
|
|
|
10
10
|
readonly offsetTop: number;
|
|
11
11
|
readonly scrollElementOffsetTop: number;
|
|
12
12
|
readonly isScrollElementInShadow: boolean;
|
|
13
|
+
readonly syncWith: "preview" | "editor";
|
|
13
14
|
readonly onClick: ((e: MouseEvent, t: TocItem) => void) | undefined;
|
|
14
15
|
readonly editorId: string | undefined;
|
|
15
16
|
readonly onActive: ((heading: HeadList | undefined, activeElement: HTMLDivElement) => void) | undefined;
|
|
@@ -21,6 +22,7 @@ declare const MdCatalog: import("vue").DefineComponent<{
|
|
|
21
22
|
readonly offsetTop: number;
|
|
22
23
|
readonly scrollElementOffsetTop: number;
|
|
23
24
|
readonly isScrollElementInShadow: boolean;
|
|
25
|
+
readonly syncWith: "preview" | "editor";
|
|
24
26
|
readonly onClick: ((e: MouseEvent, t: TocItem) => void) | undefined;
|
|
25
27
|
readonly editorId: string | undefined;
|
|
26
28
|
readonly onActive: ((heading: HeadList | undefined, activeElement: HTMLDivElement) => void) | undefined;
|
|
@@ -39,5 +41,6 @@ declare const MdCatalog: import("vue").DefineComponent<{
|
|
|
39
41
|
scrollElementOffsetTop: number;
|
|
40
42
|
scrollElement: string | HTMLElement;
|
|
41
43
|
isScrollElementInShadow: boolean;
|
|
44
|
+
syncWith: "preview" | "editor";
|
|
42
45
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
43
46
|
export default MdCatalog;
|
|
@@ -20,3 +20,5 @@ export declare const PUSH_CATALOG = "pushCatalog";
|
|
|
20
20
|
export declare const RERENDER = "rerender";
|
|
21
21
|
export declare const EVENT_LISTENER = "eventListener";
|
|
22
22
|
export declare const TASK_STATE_CHANGED = "taskStateChanged";
|
|
23
|
+
export declare const SEND_EDITOR_VIEW = "sendEditorView";
|
|
24
|
+
export declare const GET_EDITOR_VIEW = "getEditorView";
|