md-editor-v3 4.19.0-3 → 4.19.0-5
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/README.md +1 -0
- package/lib/cjs/MdCatalog.cjs +43 -28
- package/lib/cjs/MdEditor.cjs +44 -36
- package/lib/cjs/chunks/index.cjs +19 -9
- package/lib/cjs/chunks/index2.cjs +3 -2
- package/lib/cjs/chunks/index3.cjs +4 -1
- package/lib/es/MdCatalog.mjs +44 -29
- package/lib/es/MdEditor.mjs +45 -37
- package/lib/es/chunks/index.mjs +19 -9
- package/lib/es/chunks/index2.mjs +3 -2
- package/lib/es/chunks/index3.mjs +4 -1
- package/lib/preview.css +4 -6
- package/lib/style.css +28 -30
- package/lib/types/MdCatalog/CatalogLink.d.ts +0 -13
- package/lib/types/MdCatalog/MdCatalog.d.ts +19 -0
- package/lib/types/MdCatalog/index.d.ts +19 -0
- package/lib/types/MdEditor/composition.d.ts +2 -2
- package/lib/types/MdEditor/utils/content-help.d.ts +2 -2
- package/lib/umd/index.js +35 -35
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -900,6 +900,7 @@ On-demand import. For more examples, refer to [document](https://imzbf.github.io
|
|
|
900
900
|
- `theme`: `'light' | 'dark'`, not necessary, provide it when you want to change theme online, it is the same as Editor `theme`.
|
|
901
901
|
- `offsetTop`: `number`, not necessary, highlight current item of catalogs when title is `offsetTop` pixels from the top, default 20.
|
|
902
902
|
- `scrollElementOffsetTop`: `number`, not necessary, offsetTop of the scroll container,default 0.
|
|
903
|
+
- `isScrollElementInShadow`: `boolean`, whether the scroll container is in web component, default false.
|
|
903
904
|
|
|
904
905
|
- **events**
|
|
905
906
|
|
package/lib/cjs/MdCatalog.cjs
CHANGED
|
@@ -13,10 +13,6 @@ const props$1 = {
|
|
|
13
13
|
default: () => {
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
|
-
scrollElement: {
|
|
17
|
-
type: [String, Object],
|
|
18
|
-
default: ""
|
|
19
|
-
},
|
|
20
16
|
onClick: {
|
|
21
17
|
type: Function,
|
|
22
18
|
default: () => {
|
|
@@ -30,11 +26,12 @@ const props$1 = {
|
|
|
30
26
|
const CatalogLink = /* @__PURE__ */ vue.defineComponent({
|
|
31
27
|
props: props$1,
|
|
32
28
|
setup(props2) {
|
|
29
|
+
const scrollElementRef = vue.inject("scrollElementRef");
|
|
30
|
+
const rootNodeRef = vue.inject("roorNodeRef");
|
|
33
31
|
return () => {
|
|
34
32
|
const {
|
|
35
33
|
tocItem,
|
|
36
34
|
mdHeadingId,
|
|
37
|
-
scrollElement,
|
|
38
35
|
onClick,
|
|
39
36
|
scrollElementOffsetTop
|
|
40
37
|
} = props2;
|
|
@@ -44,8 +41,8 @@ const CatalogLink = /* @__PURE__ */ vue.defineComponent({
|
|
|
44
41
|
onClick(e, tocItem);
|
|
45
42
|
e.stopPropagation();
|
|
46
43
|
const id = mdHeadingId(tocItem.text, tocItem.level, tocItem.index);
|
|
47
|
-
const targetHeadEle =
|
|
48
|
-
const scrollContainer =
|
|
44
|
+
const targetHeadEle = rootNodeRef.value.getElementById(id);
|
|
45
|
+
const scrollContainer = scrollElementRef.value;
|
|
49
46
|
if (targetHeadEle && scrollContainer) {
|
|
50
47
|
let par = targetHeadEle.offsetParent;
|
|
51
48
|
let offsetTop = targetHeadEle.offsetTop;
|
|
@@ -69,7 +66,6 @@ const CatalogLink = /* @__PURE__ */ vue.defineComponent({
|
|
|
69
66
|
"mdHeadingId": mdHeadingId,
|
|
70
67
|
"key": `${tocItem.text}-link-${item.level}-${item.text}`,
|
|
71
68
|
"tocItem": item,
|
|
72
|
-
"scrollElement": scrollElement,
|
|
73
69
|
"onClick": onClick,
|
|
74
70
|
"scrollElementOffsetTop": scrollElementOffsetTop
|
|
75
71
|
}, null))])]);
|
|
@@ -128,6 +124,15 @@ const props = {
|
|
|
128
124
|
},
|
|
129
125
|
onActive: {
|
|
130
126
|
type: Function
|
|
127
|
+
},
|
|
128
|
+
/**
|
|
129
|
+
* 滚动容器是否在web component中,默认不在
|
|
130
|
+
*
|
|
131
|
+
* 在其中的话通过document查询不到
|
|
132
|
+
*/
|
|
133
|
+
isScrollElementInShadow: {
|
|
134
|
+
type: Boolean,
|
|
135
|
+
default: false
|
|
131
136
|
}
|
|
132
137
|
};
|
|
133
138
|
const MdCatalog = /* @__PURE__ */ vue.defineComponent({
|
|
@@ -136,12 +141,18 @@ const MdCatalog = /* @__PURE__ */ vue.defineComponent({
|
|
|
136
141
|
emits: ["onClick", "onActive"],
|
|
137
142
|
setup(props2, ctx) {
|
|
138
143
|
const editorId = props2.editorId;
|
|
144
|
+
const defaultScrollElement = `#${editorId}-preview-wrapper`;
|
|
139
145
|
const state = vue.reactive({
|
|
140
146
|
list: [],
|
|
141
147
|
show: false,
|
|
142
|
-
scrollElement: props2.scrollElement ||
|
|
148
|
+
scrollElement: props2.scrollElement || defaultScrollElement
|
|
143
149
|
});
|
|
144
150
|
const activeItem = vue.shallowRef();
|
|
151
|
+
const catalogRef = vue.ref();
|
|
152
|
+
const scrollElementRef = vue.ref();
|
|
153
|
+
const rootNodeRef = vue.ref();
|
|
154
|
+
vue.provide("scrollElementRef", scrollElementRef);
|
|
155
|
+
vue.provide("roorNodeRef", rootNodeRef);
|
|
145
156
|
const catalogs = vue.computed(() => {
|
|
146
157
|
const tocItems = [];
|
|
147
158
|
state.list.forEach((listItem, index2) => {
|
|
@@ -182,8 +193,15 @@ const MdCatalog = /* @__PURE__ */ vue.defineComponent({
|
|
|
182
193
|
return tocItems;
|
|
183
194
|
});
|
|
184
195
|
const getScrollElement = () => {
|
|
185
|
-
|
|
186
|
-
|
|
196
|
+
var _a;
|
|
197
|
+
if (state.scrollElement instanceof HTMLElement) {
|
|
198
|
+
return state.scrollElement;
|
|
199
|
+
}
|
|
200
|
+
let scrollRoot = document;
|
|
201
|
+
if (state.scrollElement === defaultScrollElement || props2.isScrollElementInShadow) {
|
|
202
|
+
scrollRoot = (_a = catalogRef.value) == null ? void 0 : _a.getRootNode();
|
|
203
|
+
}
|
|
204
|
+
return scrollRoot.querySelector(state.scrollElement);
|
|
187
205
|
};
|
|
188
206
|
const findActiveHeading = (list) => {
|
|
189
207
|
if (list.length === 0) {
|
|
@@ -193,10 +211,10 @@ const MdCatalog = /* @__PURE__ */ vue.defineComponent({
|
|
|
193
211
|
const {
|
|
194
212
|
activeHead
|
|
195
213
|
} = list.reduce((activeData, link, index$1) => {
|
|
196
|
-
|
|
214
|
+
var _a;
|
|
215
|
+
const linkEle = (_a = rootNodeRef.value) == null ? void 0 : _a.getElementById(props2.mdHeadingId(link.text, link.level, index$1 + 1));
|
|
197
216
|
if (linkEle instanceof HTMLElement) {
|
|
198
|
-
const
|
|
199
|
-
const relativeTop = index.getRelativeTop(linkEle, scrollElement);
|
|
217
|
+
const relativeTop = index.getRelativeTop(linkEle, scrollElementRef.value);
|
|
200
218
|
if (relativeTop < props2.offsetTop && relativeTop > activeData.minTop) {
|
|
201
219
|
return {
|
|
202
220
|
activeHead: link,
|
|
@@ -226,37 +244,34 @@ const MdCatalog = /* @__PURE__ */ vue.defineComponent({
|
|
|
226
244
|
}
|
|
227
245
|
});
|
|
228
246
|
vue.onMounted(() => {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
scrollContainer = scrollElement_ === document.documentElement ? window : scrollElement_;
|
|
233
|
-
};
|
|
247
|
+
rootNodeRef.value = catalogRef.value.getRootNode();
|
|
248
|
+
let scrollElement = getScrollElement();
|
|
249
|
+
scrollElementRef.value = scrollElement;
|
|
234
250
|
eventName.bus.on(editorId, {
|
|
235
251
|
name: eventName.CATALOG_CHANGED,
|
|
236
252
|
callback: (_list) => {
|
|
237
|
-
|
|
253
|
+
scrollElement = getScrollElement();
|
|
254
|
+
scrollElementRef.value = scrollElement;
|
|
255
|
+
scrollElement == null ? void 0 : scrollElement.removeEventListener("scroll", scrollHandler);
|
|
238
256
|
findActiveHeading(_list);
|
|
239
|
-
|
|
240
|
-
scrollContainer == null ? void 0 : scrollContainer.addEventListener("scroll", scrollHandler);
|
|
257
|
+
scrollElement == null ? void 0 : scrollElement.addEventListener("scroll", scrollHandler);
|
|
241
258
|
}
|
|
242
259
|
});
|
|
243
260
|
eventName.bus.emit(editorId, eventName.PUSH_CATALOG);
|
|
244
|
-
|
|
245
|
-
scrollContainer == null ? void 0 : scrollContainer.addEventListener("scroll", scrollHandler);
|
|
261
|
+
scrollElement == null ? void 0 : scrollElement.addEventListener("scroll", scrollHandler);
|
|
246
262
|
});
|
|
247
263
|
vue.onBeforeUnmount(() => {
|
|
248
264
|
var _a;
|
|
249
|
-
|
|
250
|
-
(_a = scrollElement === document.documentElement ? window : scrollElement) == null ? void 0 : _a.removeEventListener("scroll", scrollHandler);
|
|
265
|
+
(_a = scrollElementRef.value) == null ? void 0 : _a.removeEventListener("scroll", scrollHandler);
|
|
251
266
|
});
|
|
252
267
|
return () => vue.createVNode("div", {
|
|
253
|
-
"class": `${config.prefix}-catalog${props2.theme === "dark" ? "-dark" : ""}
|
|
268
|
+
"class": [`${config.prefix}-catalog${props2.theme === "dark" ? "-dark" : ""}`, `${props2.class}`],
|
|
269
|
+
"ref": catalogRef
|
|
254
270
|
}, [catalogs.value.map((item) => {
|
|
255
271
|
return vue.createVNode(CatalogLink$1, {
|
|
256
272
|
"mdHeadingId": props2.mdHeadingId,
|
|
257
273
|
"tocItem": item,
|
|
258
274
|
"key": `link-${item.level}-${item.text}`,
|
|
259
|
-
"scrollElement": state.scrollElement,
|
|
260
275
|
"onClick": (e, t) => {
|
|
261
276
|
if (props2.onClick) {
|
|
262
277
|
props2.onClick(e, t);
|
package/lib/cjs/MdEditor.cjs
CHANGED
|
@@ -347,6 +347,7 @@ const ClipModal = /* @__PURE__ */ vue.defineComponent({
|
|
|
347
347
|
setup(props2) {
|
|
348
348
|
const ult = vue.inject("usedLanguageText");
|
|
349
349
|
const editorId = vue.inject("editorId");
|
|
350
|
+
const rootRef = vue.inject("rootRef");
|
|
350
351
|
let Cropper = config.configOption.editorExtensions.cropper.instance;
|
|
351
352
|
const uploadRef = vue.ref();
|
|
352
353
|
const uploadImgRef = vue.ref();
|
|
@@ -376,13 +377,6 @@ const ClipModal = /* @__PURE__ */ vue.defineComponent({
|
|
|
376
377
|
const fileReader = new FileReader();
|
|
377
378
|
fileReader.onload = (e) => {
|
|
378
379
|
data.imgSrc = e.target.result;
|
|
379
|
-
vue.nextTick(() => {
|
|
380
|
-
cropper = new Cropper(uploadImgRef.value, {
|
|
381
|
-
viewMode: 2,
|
|
382
|
-
preview: `.${config.prefix}-clip-preview-target`
|
|
383
|
-
// aspectRatio: 16 / 9,
|
|
384
|
-
});
|
|
385
|
-
});
|
|
386
380
|
};
|
|
387
381
|
fileReader.readAsDataURL(fileList[0]);
|
|
388
382
|
}
|
|
@@ -392,18 +386,20 @@ const ClipModal = /* @__PURE__ */ vue.defineComponent({
|
|
|
392
386
|
vue.watch(() => [data.imgSelected], () => {
|
|
393
387
|
previewTargetRef.value.style = "";
|
|
394
388
|
});
|
|
395
|
-
vue.watch(() => data.isFullscreen, () => {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
389
|
+
vue.watch([vue.toRef(() => data.isFullscreen), vue.toRef(() => data.imgSrc)], () => {
|
|
390
|
+
if (data.imgSrc) {
|
|
391
|
+
vue.nextTick(() => {
|
|
392
|
+
cropper == null ? void 0 : cropper.destroy();
|
|
393
|
+
previewTargetRef.value.style = "";
|
|
394
|
+
if (uploadImgRef.value) {
|
|
395
|
+
cropper = new Cropper(uploadImgRef.value, {
|
|
396
|
+
viewMode: 2,
|
|
397
|
+
preview: rootRef.value.getRootNode().querySelector(`.${config.prefix}-clip-preview-target`)
|
|
398
|
+
// aspectRatio: 16 / 9,
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
}
|
|
407
403
|
});
|
|
408
404
|
const reset = () => {
|
|
409
405
|
cropper.clear();
|
|
@@ -1378,7 +1374,7 @@ const scrollAuto = (pEle, cEle, codeMirrorUt) => {
|
|
|
1378
1374
|
const lineNumer = getLineNumber(pMaxScrollLength, cMaxScrollLength);
|
|
1379
1375
|
startTop = getTopByLine(lineNumer);
|
|
1380
1376
|
scale = (scrollDOM.scrollTop - startTop) / (pMaxScrollLength - startTop);
|
|
1381
|
-
const _startEle =
|
|
1377
|
+
const _startEle = cEle.querySelector(`[data-line="${lineNumer}"]`);
|
|
1382
1378
|
if (startTop > 0 && _startEle) {
|
|
1383
1379
|
startEleOffetTop = _startEle.offsetTop;
|
|
1384
1380
|
}
|
|
@@ -1457,7 +1453,7 @@ const scrollAuto = (pEle, cEle, codeMirrorUt) => {
|
|
|
1457
1453
|
let blockHeight = 0;
|
|
1458
1454
|
if (endLineScrollTop > pMaxScrollLength || realEleEnd.offsetTop + realEleEnd.offsetHeight > cMaxScrollLength) {
|
|
1459
1455
|
const lineNumer = getLineNumber(pMaxScrollLength, cMaxScrollLength);
|
|
1460
|
-
const _startEle =
|
|
1456
|
+
const _startEle = cEle.querySelector(`[data-line="${lineNumer}"]`);
|
|
1461
1457
|
eleStartOffsetTop = _startEle ? _startEle.offsetTop - getComputedStyleNum(_startEle, "margin-top") : eleStartOffsetTop;
|
|
1462
1458
|
firstLineScrollTop = getTopByLine(lineNumer);
|
|
1463
1459
|
scale = (cScrollTop - eleStartOffsetTop) / (cMaxScrollLength - eleStartOffsetTop);
|
|
@@ -1517,14 +1513,16 @@ const useAutoScroll = (props2, html, codeMirrorUt) => {
|
|
|
1517
1513
|
let initScrollAuto = () => {
|
|
1518
1514
|
};
|
|
1519
1515
|
const rebindEvent = () => {
|
|
1516
|
+
var _a;
|
|
1520
1517
|
clearScrollAuto();
|
|
1521
|
-
const
|
|
1518
|
+
const rootNode = (_a = codeMirrorUt.value) == null ? void 0 : _a.view.contentDOM.getRootNode();
|
|
1519
|
+
const cmScroller = rootNode.querySelector(
|
|
1522
1520
|
`#${editorId} .cm-scroller`
|
|
1523
1521
|
);
|
|
1524
|
-
const previewEle =
|
|
1522
|
+
const previewEle = rootNode.querySelector(
|
|
1525
1523
|
`[id="${editorId}-preview-wrapper"]`
|
|
1526
1524
|
);
|
|
1527
|
-
const htmlEle =
|
|
1525
|
+
const htmlEle = rootNode.querySelector(
|
|
1528
1526
|
`[id="${editorId}-html-wrapper"]`
|
|
1529
1527
|
);
|
|
1530
1528
|
if (previewEle || htmlEle) {
|
|
@@ -1574,7 +1572,7 @@ const useAutoScroll = (props2, html, codeMirrorUt) => {
|
|
|
1574
1572
|
);
|
|
1575
1573
|
vue.onMounted(rebindEvent);
|
|
1576
1574
|
};
|
|
1577
|
-
const directive2flag = (direct, codeMirrorUt, params) => {
|
|
1575
|
+
const directive2flag = async (direct, codeMirrorUt, params) => {
|
|
1578
1576
|
var _a;
|
|
1579
1577
|
let targetValue = "";
|
|
1580
1578
|
let deviationStart = 0;
|
|
@@ -1601,7 +1599,7 @@ const directive2flag = (direct, codeMirrorUt, params) => {
|
|
|
1601
1599
|
});
|
|
1602
1600
|
targetValue = codeMirrorUt.getValue();
|
|
1603
1601
|
} else {
|
|
1604
|
-
targetValue = prettier.format(codeMirrorUt.getValue(), {
|
|
1602
|
+
targetValue = await prettier.format(codeMirrorUt.getValue(), {
|
|
1605
1603
|
parser: "markdown",
|
|
1606
1604
|
plugins: prettierPlugins
|
|
1607
1605
|
});
|
|
@@ -2725,30 +2723,38 @@ const useCodeMirror = (props2) => {
|
|
|
2725
2723
|
});
|
|
2726
2724
|
eventName.bus.on(editorId, {
|
|
2727
2725
|
name: eventName.REPLACE,
|
|
2728
|
-
callback(direct, params = {}) {
|
|
2726
|
+
async callback(direct, params = {}) {
|
|
2729
2727
|
var _a, _b;
|
|
2730
2728
|
if (direct === "image" && params.transform) {
|
|
2731
2729
|
const tv = props2.transformImgUrl(params.url);
|
|
2732
2730
|
if (tv instanceof Promise) {
|
|
2733
|
-
tv.then((url) => {
|
|
2731
|
+
tv.then(async (url) => {
|
|
2734
2732
|
var _a2;
|
|
2735
|
-
const { text, options } = directive2flag(
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2733
|
+
const { text, options } = await directive2flag(
|
|
2734
|
+
direct,
|
|
2735
|
+
codeMirrorUt.value,
|
|
2736
|
+
{
|
|
2737
|
+
...params,
|
|
2738
|
+
url
|
|
2739
|
+
}
|
|
2740
|
+
);
|
|
2739
2741
|
(_a2 = codeMirrorUt.value) == null ? void 0 : _a2.replaceSelectedText(text, options, editorId);
|
|
2740
2742
|
}).catch((err) => {
|
|
2741
2743
|
console.error(err);
|
|
2742
2744
|
});
|
|
2743
2745
|
} else {
|
|
2744
|
-
const { text, options } = directive2flag(direct, codeMirrorUt.value, {
|
|
2746
|
+
const { text, options } = await directive2flag(direct, codeMirrorUt.value, {
|
|
2745
2747
|
...params,
|
|
2746
2748
|
url: tv
|
|
2747
2749
|
});
|
|
2748
2750
|
(_a = codeMirrorUt.value) == null ? void 0 : _a.replaceSelectedText(text, options, editorId);
|
|
2749
2751
|
}
|
|
2750
2752
|
} else {
|
|
2751
|
-
const { text, options } = directive2flag(
|
|
2753
|
+
const { text, options } = await directive2flag(
|
|
2754
|
+
direct,
|
|
2755
|
+
codeMirrorUt.value,
|
|
2756
|
+
params
|
|
2757
|
+
);
|
|
2752
2758
|
(_b = codeMirrorUt.value) == null ? void 0 : _b.replaceSelectedText(text, options, editorId);
|
|
2753
2759
|
}
|
|
2754
2760
|
}
|
|
@@ -3180,9 +3186,10 @@ const Editor = /* @__PURE__ */ vue.defineComponent({
|
|
|
3180
3186
|
const state2 = vue.reactive({
|
|
3181
3187
|
scrollAuto: props2.scrollAuto
|
|
3182
3188
|
});
|
|
3189
|
+
const rootRef = vue.ref();
|
|
3183
3190
|
const codeRef = vue.ref();
|
|
3184
3191
|
MdPreview.useOnSave(props2, ctx);
|
|
3185
|
-
MdPreview.useProvide(props2);
|
|
3192
|
+
MdPreview.useProvide(props2, rootRef);
|
|
3186
3193
|
MdPreview.useExpansion(props2);
|
|
3187
3194
|
MdPreview.useErrorCatcher(props2, ctx);
|
|
3188
3195
|
const [setting, updateSetting] = MdPreview.useConfig(props2, ctx);
|
|
@@ -3203,7 +3210,8 @@ const Editor = /* @__PURE__ */ vue.defineComponent({
|
|
|
3203
3210
|
return vue.createVNode("div", {
|
|
3204
3211
|
"id": editorId,
|
|
3205
3212
|
"class": [config.prefix, props2.class, props2.theme === "dark" && `${config.prefix}-dark`, setting.fullscreen || setting.pageFullscreen ? `${config.prefix}-fullscreen` : ""],
|
|
3206
|
-
"style": props2.style
|
|
3213
|
+
"style": props2.style,
|
|
3214
|
+
"ref": rootRef
|
|
3207
3215
|
}, [props2.toolbars.length > 0 && vue.createVNode(ToolBar, {
|
|
3208
3216
|
"noPrettier": noPrettier,
|
|
3209
3217
|
"toolbars": props2.toolbars,
|
package/lib/cjs/chunks/index.cjs
CHANGED
|
@@ -56,9 +56,10 @@ const userZoom = (props, html) => {
|
|
|
56
56
|
};
|
|
57
57
|
const useCopyCode = (props, html, key) => {
|
|
58
58
|
const editorId = vue.inject("editorId");
|
|
59
|
+
const rootRef = vue.inject("rootRef");
|
|
59
60
|
const ult = vue.inject("usedLanguageText");
|
|
60
61
|
const initCopyEntry = () => {
|
|
61
|
-
|
|
62
|
+
rootRef.value.querySelectorAll(`#${editorId} .${config.prefix}-preview .${config.prefix}-code`).forEach((codeBlock) => {
|
|
62
63
|
let clearTimer = -1;
|
|
63
64
|
const copyButton = codeBlock.querySelector(
|
|
64
65
|
`.${config.prefix}-copy-button`
|
|
@@ -147,6 +148,7 @@ const mermaidCache = new lruCache.LRUCache({
|
|
|
147
148
|
});
|
|
148
149
|
const useMermaid = (props) => {
|
|
149
150
|
const theme = vue.inject("theme");
|
|
151
|
+
const rootRef = vue.inject("rootRef");
|
|
150
152
|
const { editorExtensions, editorExtensionsAttrs, mermaidConfig } = config.configOption;
|
|
151
153
|
const mermaidRef = vue.shallowRef(editorExtensions.mermaid.instance);
|
|
152
154
|
const reRenderRef = vue.shallowRef(-1);
|
|
@@ -209,7 +211,7 @@ const useMermaid = (props) => {
|
|
|
209
211
|
const replaceMermaid = () => {
|
|
210
212
|
vue.nextTick(() => {
|
|
211
213
|
if (!props.noMermaid && mermaidRef.value) {
|
|
212
|
-
const mermaidSourceEles =
|
|
214
|
+
const mermaidSourceEles = rootRef.value.querySelectorAll(
|
|
213
215
|
`div.${config.prefix}-mermaid`
|
|
214
216
|
);
|
|
215
217
|
const svgContainingElement = document.createElement("div");
|
|
@@ -681,7 +683,7 @@ const codetabs = (md, _opts) => {
|
|
|
681
683
|
checked = i - idx > 0 ? "" : "checked";
|
|
682
684
|
labels += `<li>
|
|
683
685
|
<input type="radio" name="${config.prefix}-codetab-label-${_opts.editorId}-${idx}" class="${className}" ${checked}>
|
|
684
|
-
<label onclick="
|
|
686
|
+
<label onclick="this.getRootNode().querySelectorAll('.${className}').forEach(e => e.click())">${tab || getLangName(token)}</label>
|
|
685
687
|
</li>`;
|
|
686
688
|
pres += `<input type="radio" name="${config.prefix}-codetab-pre-${_opts.editorId}-${idx}" class="${className}" ${checked}>
|
|
687
689
|
${defaultRender(tokens, i, options, env, slf)}`;
|
|
@@ -2274,6 +2276,7 @@ const useMarkdownIt = (props, previewOnly) => {
|
|
|
2274
2276
|
() => {
|
|
2275
2277
|
if (props.setting.preview) {
|
|
2276
2278
|
vue.nextTick(() => {
|
|
2279
|
+
replaceMermaid();
|
|
2277
2280
|
eventName.bus.emit(editorId, eventName.CATALOG_CHANGED, headsRef.value);
|
|
2278
2281
|
});
|
|
2279
2282
|
}
|
|
@@ -2309,10 +2312,14 @@ const template = {
|
|
|
2309
2312
|
};
|
|
2310
2313
|
const useTaskState = (props, html) => {
|
|
2311
2314
|
const editorId = vue.inject("editorId");
|
|
2315
|
+
const rootRef = vue.inject("rootRef");
|
|
2312
2316
|
let removeListener = () => {
|
|
2313
2317
|
};
|
|
2314
2318
|
const addListener = () => {
|
|
2315
|
-
|
|
2319
|
+
if (!rootRef.value) {
|
|
2320
|
+
return false;
|
|
2321
|
+
}
|
|
2322
|
+
const tasks = rootRef.value.querySelectorAll(".task-list-item.enabled");
|
|
2316
2323
|
const listener = (e) => {
|
|
2317
2324
|
var _a;
|
|
2318
2325
|
e.preventDefault();
|
|
@@ -2582,11 +2589,12 @@ const useOnSave = (props, context) => {
|
|
|
2582
2589
|
});
|
|
2583
2590
|
});
|
|
2584
2591
|
};
|
|
2585
|
-
const useProvidePreview = (props) => {
|
|
2592
|
+
const useProvidePreview = (props, rootRef) => {
|
|
2586
2593
|
const { editorId } = props;
|
|
2587
2594
|
const hljsUrls = config.configOption.editorExtensions.highlight;
|
|
2588
2595
|
const hljsAttrs = config.configOption.editorExtensionsAttrs.highlight;
|
|
2589
2596
|
vue.provide("editorId", editorId);
|
|
2597
|
+
vue.provide("rootRef", rootRef);
|
|
2590
2598
|
vue.provide(
|
|
2591
2599
|
"theme",
|
|
2592
2600
|
vue.computed(() => props.theme)
|
|
@@ -2640,8 +2648,8 @@ const useProvidePreview = (props) => {
|
|
|
2640
2648
|
vue.computed(() => props.customIcon)
|
|
2641
2649
|
);
|
|
2642
2650
|
};
|
|
2643
|
-
const useProvide = (props) => {
|
|
2644
|
-
useProvidePreview(props);
|
|
2651
|
+
const useProvide = (props, rootRef) => {
|
|
2652
|
+
useProvidePreview(props, rootRef);
|
|
2645
2653
|
vue.provide("tabWidth", props.tabWidth);
|
|
2646
2654
|
};
|
|
2647
2655
|
const useExpansionPreview = (props) => {
|
|
@@ -3467,7 +3475,8 @@ const MdPreview = /* @__PURE__ */ vue.defineComponent({
|
|
|
3467
3475
|
noMermaid,
|
|
3468
3476
|
noHighlight
|
|
3469
3477
|
} = props;
|
|
3470
|
-
|
|
3478
|
+
const rootRef = vue.ref();
|
|
3479
|
+
useProvidePreview(props, rootRef);
|
|
3471
3480
|
useExpansionPreview(props);
|
|
3472
3481
|
useExpose(props, ctx);
|
|
3473
3482
|
vue.onBeforeUnmount(() => {
|
|
@@ -3477,7 +3486,8 @@ const MdPreview = /* @__PURE__ */ vue.defineComponent({
|
|
|
3477
3486
|
return vue.createVNode("div", {
|
|
3478
3487
|
"id": editorId,
|
|
3479
3488
|
"class": [config.prefix, props.class, props.theme === "dark" && `${config.prefix}-dark`, `${config.prefix}-previewOnly`],
|
|
3480
|
-
"style": props.style
|
|
3489
|
+
"style": props.style,
|
|
3490
|
+
"ref": rootRef
|
|
3481
3491
|
}, [vue.createVNode(ContentPreview, {
|
|
3482
3492
|
"modelValue": props.modelValue,
|
|
3483
3493
|
"onChange": (value) => {
|
|
@@ -47,8 +47,9 @@ const Dropdown = /* @__PURE__ */ vue.defineComponent({
|
|
|
47
47
|
const triggerLeft = triggerEle.offsetLeft;
|
|
48
48
|
const triggerHeight = triggerInfo.height;
|
|
49
49
|
const triggerWidth = triggerInfo.width;
|
|
50
|
-
const
|
|
51
|
-
const
|
|
50
|
+
const rootNode = triggerEle.getRootNode();
|
|
51
|
+
const relativecrollLeft = ((_a = rootNode.querySelector(props2.relative)) == null ? void 0 : _a.scrollLeft) || 0;
|
|
52
|
+
const relativeWidth = ((_b = rootNode.querySelector(props2.relative)) == null ? void 0 : _b.clientWidth) || 0;
|
|
52
53
|
let left = triggerLeft - overlayEle.offsetWidth / 2 + triggerWidth / 2 - relativecrollLeft;
|
|
53
54
|
if (left + overlayEle.offsetWidth > relativecrollLeft + relativeWidth) {
|
|
54
55
|
left = relativecrollLeft + relativeWidth - overlayEle.offsetWidth;
|
|
@@ -97,6 +97,7 @@ const MdModal = /* @__PURE__ */ vue.defineComponent({
|
|
|
97
97
|
emits: ["onClose"],
|
|
98
98
|
setup(props2, ctx) {
|
|
99
99
|
const themeRef = vue.inject("theme");
|
|
100
|
+
const rootRef = vue.inject("rootRef");
|
|
100
101
|
const modalVisible = vue.ref(props2.visible);
|
|
101
102
|
const modalClass = vue.ref([`${config.prefix}-modal`]);
|
|
102
103
|
const modalRef = vue.ref();
|
|
@@ -194,7 +195,9 @@ const MdModal = /* @__PURE__ */ vue.defineComponent({
|
|
|
194
195
|
}
|
|
195
196
|
});
|
|
196
197
|
vue.onMounted(() => {
|
|
197
|
-
|
|
198
|
+
var _a;
|
|
199
|
+
const rootNode = (_a = rootRef.value) == null ? void 0 : _a.getRootNode();
|
|
200
|
+
bodyRef.value = rootNode instanceof Document ? document.body : rootNode;
|
|
198
201
|
});
|
|
199
202
|
return () => {
|
|
200
203
|
const slotDefault = vueTsx.getSlot({
|
package/lib/es/MdCatalog.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineComponent, createVNode, reactive, shallowRef, computed, watch, onMounted, onBeforeUnmount } from "vue";
|
|
1
|
+
import { defineComponent, inject, createVNode, reactive, shallowRef, ref, provide, computed, watch, onMounted, onBeforeUnmount } from "vue";
|
|
2
2
|
import { p as prefix } from "./chunks/config.mjs";
|
|
3
3
|
import { g as getRelativeTop } from "./chunks/index4.mjs";
|
|
4
4
|
import { b as bus, C as CATALOG_CHANGED, P as PUSH_CATALOG } from "./chunks/event-name.mjs";
|
|
@@ -12,10 +12,6 @@ const props$1 = {
|
|
|
12
12
|
default: () => {
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
|
-
scrollElement: {
|
|
16
|
-
type: [String, Object],
|
|
17
|
-
default: ""
|
|
18
|
-
},
|
|
19
15
|
onClick: {
|
|
20
16
|
type: Function,
|
|
21
17
|
default: () => {
|
|
@@ -29,11 +25,12 @@ const props$1 = {
|
|
|
29
25
|
const CatalogLink = /* @__PURE__ */ defineComponent({
|
|
30
26
|
props: props$1,
|
|
31
27
|
setup(props2) {
|
|
28
|
+
const scrollElementRef = inject("scrollElementRef");
|
|
29
|
+
const rootNodeRef = inject("roorNodeRef");
|
|
32
30
|
return () => {
|
|
33
31
|
const {
|
|
34
32
|
tocItem,
|
|
35
33
|
mdHeadingId,
|
|
36
|
-
scrollElement,
|
|
37
34
|
onClick,
|
|
38
35
|
scrollElementOffsetTop
|
|
39
36
|
} = props2;
|
|
@@ -43,8 +40,8 @@ const CatalogLink = /* @__PURE__ */ defineComponent({
|
|
|
43
40
|
onClick(e, tocItem);
|
|
44
41
|
e.stopPropagation();
|
|
45
42
|
const id = mdHeadingId(tocItem.text, tocItem.level, tocItem.index);
|
|
46
|
-
const targetHeadEle =
|
|
47
|
-
const scrollContainer =
|
|
43
|
+
const targetHeadEle = rootNodeRef.value.getElementById(id);
|
|
44
|
+
const scrollContainer = scrollElementRef.value;
|
|
48
45
|
if (targetHeadEle && scrollContainer) {
|
|
49
46
|
let par = targetHeadEle.offsetParent;
|
|
50
47
|
let offsetTop = targetHeadEle.offsetTop;
|
|
@@ -68,7 +65,6 @@ const CatalogLink = /* @__PURE__ */ defineComponent({
|
|
|
68
65
|
"mdHeadingId": mdHeadingId,
|
|
69
66
|
"key": `${tocItem.text}-link-${item.level}-${item.text}`,
|
|
70
67
|
"tocItem": item,
|
|
71
|
-
"scrollElement": scrollElement,
|
|
72
68
|
"onClick": onClick,
|
|
73
69
|
"scrollElementOffsetTop": scrollElementOffsetTop
|
|
74
70
|
}, null))])]);
|
|
@@ -127,6 +123,15 @@ const props = {
|
|
|
127
123
|
},
|
|
128
124
|
onActive: {
|
|
129
125
|
type: Function
|
|
126
|
+
},
|
|
127
|
+
/**
|
|
128
|
+
* 滚动容器是否在web component中,默认不在
|
|
129
|
+
*
|
|
130
|
+
* 在其中的话通过document查询不到
|
|
131
|
+
*/
|
|
132
|
+
isScrollElementInShadow: {
|
|
133
|
+
type: Boolean,
|
|
134
|
+
default: false
|
|
130
135
|
}
|
|
131
136
|
};
|
|
132
137
|
const MdCatalog = /* @__PURE__ */ defineComponent({
|
|
@@ -135,12 +140,18 @@ const MdCatalog = /* @__PURE__ */ defineComponent({
|
|
|
135
140
|
emits: ["onClick", "onActive"],
|
|
136
141
|
setup(props2, ctx) {
|
|
137
142
|
const editorId = props2.editorId;
|
|
143
|
+
const defaultScrollElement = `#${editorId}-preview-wrapper`;
|
|
138
144
|
const state = reactive({
|
|
139
145
|
list: [],
|
|
140
146
|
show: false,
|
|
141
|
-
scrollElement: props2.scrollElement ||
|
|
147
|
+
scrollElement: props2.scrollElement || defaultScrollElement
|
|
142
148
|
});
|
|
143
149
|
const activeItem = shallowRef();
|
|
150
|
+
const catalogRef = ref();
|
|
151
|
+
const scrollElementRef = ref();
|
|
152
|
+
const rootNodeRef = ref();
|
|
153
|
+
provide("scrollElementRef", scrollElementRef);
|
|
154
|
+
provide("roorNodeRef", rootNodeRef);
|
|
144
155
|
const catalogs = computed(() => {
|
|
145
156
|
const tocItems = [];
|
|
146
157
|
state.list.forEach((listItem, index) => {
|
|
@@ -181,8 +192,15 @@ const MdCatalog = /* @__PURE__ */ defineComponent({
|
|
|
181
192
|
return tocItems;
|
|
182
193
|
});
|
|
183
194
|
const getScrollElement = () => {
|
|
184
|
-
|
|
185
|
-
|
|
195
|
+
var _a;
|
|
196
|
+
if (state.scrollElement instanceof HTMLElement) {
|
|
197
|
+
return state.scrollElement;
|
|
198
|
+
}
|
|
199
|
+
let scrollRoot = document;
|
|
200
|
+
if (state.scrollElement === defaultScrollElement || props2.isScrollElementInShadow) {
|
|
201
|
+
scrollRoot = (_a = catalogRef.value) == null ? void 0 : _a.getRootNode();
|
|
202
|
+
}
|
|
203
|
+
return scrollRoot.querySelector(state.scrollElement);
|
|
186
204
|
};
|
|
187
205
|
const findActiveHeading = (list) => {
|
|
188
206
|
if (list.length === 0) {
|
|
@@ -192,10 +210,10 @@ const MdCatalog = /* @__PURE__ */ defineComponent({
|
|
|
192
210
|
const {
|
|
193
211
|
activeHead
|
|
194
212
|
} = list.reduce((activeData, link, index) => {
|
|
195
|
-
|
|
213
|
+
var _a;
|
|
214
|
+
const linkEle = (_a = rootNodeRef.value) == null ? void 0 : _a.getElementById(props2.mdHeadingId(link.text, link.level, index + 1));
|
|
196
215
|
if (linkEle instanceof HTMLElement) {
|
|
197
|
-
const
|
|
198
|
-
const relativeTop = getRelativeTop(linkEle, scrollElement);
|
|
216
|
+
const relativeTop = getRelativeTop(linkEle, scrollElementRef.value);
|
|
199
217
|
if (relativeTop < props2.offsetTop && relativeTop > activeData.minTop) {
|
|
200
218
|
return {
|
|
201
219
|
activeHead: link,
|
|
@@ -225,37 +243,34 @@ const MdCatalog = /* @__PURE__ */ defineComponent({
|
|
|
225
243
|
}
|
|
226
244
|
});
|
|
227
245
|
onMounted(() => {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
scrollContainer = scrollElement_ === document.documentElement ? window : scrollElement_;
|
|
232
|
-
};
|
|
246
|
+
rootNodeRef.value = catalogRef.value.getRootNode();
|
|
247
|
+
let scrollElement = getScrollElement();
|
|
248
|
+
scrollElementRef.value = scrollElement;
|
|
233
249
|
bus.on(editorId, {
|
|
234
250
|
name: CATALOG_CHANGED,
|
|
235
251
|
callback: (_list) => {
|
|
236
|
-
|
|
252
|
+
scrollElement = getScrollElement();
|
|
253
|
+
scrollElementRef.value = scrollElement;
|
|
254
|
+
scrollElement == null ? void 0 : scrollElement.removeEventListener("scroll", scrollHandler);
|
|
237
255
|
findActiveHeading(_list);
|
|
238
|
-
|
|
239
|
-
scrollContainer == null ? void 0 : scrollContainer.addEventListener("scroll", scrollHandler);
|
|
256
|
+
scrollElement == null ? void 0 : scrollElement.addEventListener("scroll", scrollHandler);
|
|
240
257
|
}
|
|
241
258
|
});
|
|
242
259
|
bus.emit(editorId, PUSH_CATALOG);
|
|
243
|
-
|
|
244
|
-
scrollContainer == null ? void 0 : scrollContainer.addEventListener("scroll", scrollHandler);
|
|
260
|
+
scrollElement == null ? void 0 : scrollElement.addEventListener("scroll", scrollHandler);
|
|
245
261
|
});
|
|
246
262
|
onBeforeUnmount(() => {
|
|
247
263
|
var _a;
|
|
248
|
-
|
|
249
|
-
(_a = scrollElement === document.documentElement ? window : scrollElement) == null ? void 0 : _a.removeEventListener("scroll", scrollHandler);
|
|
264
|
+
(_a = scrollElementRef.value) == null ? void 0 : _a.removeEventListener("scroll", scrollHandler);
|
|
250
265
|
});
|
|
251
266
|
return () => createVNode("div", {
|
|
252
|
-
"class": `${prefix}-catalog${props2.theme === "dark" ? "-dark" : ""}
|
|
267
|
+
"class": [`${prefix}-catalog${props2.theme === "dark" ? "-dark" : ""}`, `${props2.class}`],
|
|
268
|
+
"ref": catalogRef
|
|
253
269
|
}, [catalogs.value.map((item) => {
|
|
254
270
|
return createVNode(CatalogLink$1, {
|
|
255
271
|
"mdHeadingId": props2.mdHeadingId,
|
|
256
272
|
"tocItem": item,
|
|
257
273
|
"key": `link-${item.level}-${item.text}`,
|
|
258
|
-
"scrollElement": state.scrollElement,
|
|
259
274
|
"onClick": (e, t) => {
|
|
260
275
|
if (props2.onClick) {
|
|
261
276
|
props2.onClick(e, t);
|