md-editor-v3 5.2.1 → 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 +293 -264
- 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 +295 -266
- 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/layouts/Content/codemirror/index.d.ts +1 -6
- package/lib/types/MdEditor/static/event-name.d.ts +2 -0
- package/lib/types/MdEditor/type.d.ts +1 -0
- package/lib/types/MdEditor/utils/content-help.d.ts +22 -1
- package/lib/umd/index.js +113 -140
- package/package.json +1 -1
|
@@ -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);
|