md-editor-v3 4.19.0-2 → 4.19.0-4

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 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
 
@@ -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 = document.getElementById(id);
48
- const scrollContainer = scrollElement instanceof Element ? scrollElement : document.querySelector(scrollElement);
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 || `#${editorId}-preview-wrapper`
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
- const scrollElement = state.scrollElement instanceof HTMLElement ? state.scrollElement : document.querySelector(state.scrollElement);
186
- return scrollElement;
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
- const linkEle = document.getElementById(props2.mdHeadingId(link.text, link.level, index$1 + 1));
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 scrollElement = getScrollElement();
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,32 @@ const MdCatalog = /* @__PURE__ */ vue.defineComponent({
226
244
  }
227
245
  });
228
246
  vue.onMounted(() => {
229
- let scrollContainer = window;
230
- const findScrollContainer = () => {
231
- const scrollElement_ = getScrollElement();
232
- scrollContainer = scrollElement_ === document.documentElement ? window : scrollElement_;
233
- };
247
+ rootNodeRef.value = catalogRef.value.getRootNode();
248
+ const scrollElement = getScrollElement();
249
+ scrollElementRef.value = scrollElement;
234
250
  eventName.bus.on(editorId, {
235
251
  name: eventName.CATALOG_CHANGED,
236
252
  callback: (_list) => {
237
- scrollContainer == null ? void 0 : scrollContainer.removeEventListener("scroll", scrollHandler);
253
+ scrollElement == null ? void 0 : scrollElement.removeEventListener("scroll", scrollHandler);
238
254
  findActiveHeading(_list);
239
- findScrollContainer();
240
- scrollContainer == null ? void 0 : scrollContainer.addEventListener("scroll", scrollHandler);
255
+ scrollElement == null ? void 0 : scrollElement.addEventListener("scroll", scrollHandler);
241
256
  }
242
257
  });
243
258
  eventName.bus.emit(editorId, eventName.PUSH_CATALOG);
244
- findScrollContainer();
245
- scrollContainer == null ? void 0 : scrollContainer.addEventListener("scroll", scrollHandler);
259
+ scrollElement == null ? void 0 : scrollElement.addEventListener("scroll", scrollHandler);
246
260
  });
247
261
  vue.onBeforeUnmount(() => {
248
262
  var _a;
249
- const scrollElement = getScrollElement();
250
- (_a = scrollElement === document.documentElement ? window : scrollElement) == null ? void 0 : _a.removeEventListener("scroll", scrollHandler);
263
+ (_a = scrollElementRef.value) == null ? void 0 : _a.removeEventListener("scroll", scrollHandler);
251
264
  });
252
265
  return () => vue.createVNode("div", {
253
- "class": `${config.prefix}-catalog${props2.theme === "dark" ? "-dark" : ""} ${props2.class}`
266
+ "class": [`${config.prefix}-catalog${props2.theme === "dark" ? "-dark" : ""}`, `${props2.class}`],
267
+ "ref": catalogRef
254
268
  }, [catalogs.value.map((item) => {
255
269
  return vue.createVNode(CatalogLink$1, {
256
270
  "mdHeadingId": props2.mdHeadingId,
257
271
  "tocItem": item,
258
272
  "key": `link-${item.level}-${item.text}`,
259
- "scrollElement": state.scrollElement,
260
273
  "onClick": (e, t) => {
261
274
  if (props2.onClick) {
262
275
  props2.onClick(e, t);
@@ -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();
@@ -379,7 +380,7 @@ const ClipModal = /* @__PURE__ */ vue.defineComponent({
379
380
  vue.nextTick(() => {
380
381
  cropper = new Cropper(uploadImgRef.value, {
381
382
  viewMode: 2,
382
- preview: `.${config.prefix}-clip-preview-target`
383
+ preview: rootRef.value.querySelector(`.${config.prefix}-clip-preview-target`)
383
384
  // aspectRatio: 16 / 9,
384
385
  });
385
386
  });
@@ -1378,7 +1379,7 @@ const scrollAuto = (pEle, cEle, codeMirrorUt) => {
1378
1379
  const lineNumer = getLineNumber(pMaxScrollLength, cMaxScrollLength);
1379
1380
  startTop = getTopByLine(lineNumer);
1380
1381
  scale = (scrollDOM.scrollTop - startTop) / (pMaxScrollLength - startTop);
1381
- const _startEle = document.querySelector(`[data-line="${lineNumer}"]`);
1382
+ const _startEle = cEle.querySelector(`[data-line="${lineNumer}"]`);
1382
1383
  if (startTop > 0 && _startEle) {
1383
1384
  startEleOffetTop = _startEle.offsetTop;
1384
1385
  }
@@ -1457,7 +1458,7 @@ const scrollAuto = (pEle, cEle, codeMirrorUt) => {
1457
1458
  let blockHeight = 0;
1458
1459
  if (endLineScrollTop > pMaxScrollLength || realEleEnd.offsetTop + realEleEnd.offsetHeight > cMaxScrollLength) {
1459
1460
  const lineNumer = getLineNumber(pMaxScrollLength, cMaxScrollLength);
1460
- const _startEle = document.querySelector(`[data-line="${lineNumer}"]`);
1461
+ const _startEle = cEle.querySelector(`[data-line="${lineNumer}"]`);
1461
1462
  eleStartOffsetTop = _startEle ? _startEle.offsetTop - getComputedStyleNum(_startEle, "margin-top") : eleStartOffsetTop;
1462
1463
  firstLineScrollTop = getTopByLine(lineNumer);
1463
1464
  scale = (cScrollTop - eleStartOffsetTop) / (cMaxScrollLength - eleStartOffsetTop);
@@ -1517,14 +1518,16 @@ const useAutoScroll = (props2, html, codeMirrorUt) => {
1517
1518
  let initScrollAuto = () => {
1518
1519
  };
1519
1520
  const rebindEvent = () => {
1521
+ var _a;
1520
1522
  clearScrollAuto();
1521
- const cmScroller = document.querySelector(
1523
+ const rootNode = (_a = codeMirrorUt.value) == null ? void 0 : _a.view.contentDOM.getRootNode();
1524
+ const cmScroller = rootNode.querySelector(
1522
1525
  `#${editorId} .cm-scroller`
1523
1526
  );
1524
- const previewEle = document.querySelector(
1527
+ const previewEle = rootNode.querySelector(
1525
1528
  `[id="${editorId}-preview-wrapper"]`
1526
1529
  );
1527
- const htmlEle = document.querySelector(
1530
+ const htmlEle = rootNode.querySelector(
1528
1531
  `[id="${editorId}-html-wrapper"]`
1529
1532
  );
1530
1533
  if (previewEle || htmlEle) {
@@ -1734,8 +1737,8 @@ ${text}
1734
1737
  ${(mermaidTemplate == null ? void 0 : mermaidTemplate.flow) || "flowchart TD \n Start --> Stop"}
1735
1738
  \`\`\`
1736
1739
  `;
1737
- deviationStart = 3;
1738
- deviationEnd = 10 - targetValue.length;
1740
+ deviationStart = 11;
1741
+ deviationEnd = -5;
1739
1742
  break;
1740
1743
  }
1741
1744
  case "sequence": {
@@ -1743,8 +1746,8 @@ ${(mermaidTemplate == null ? void 0 : mermaidTemplate.flow) || "flowchart TD \n
1743
1746
  ${(mermaidTemplate == null ? void 0 : mermaidTemplate.sequence) || "sequenceDiagram\n A->>B: hello!\n B-->>A: hi!\n A-)B: bye!"}
1744
1747
  \`\`\`
1745
1748
  `;
1746
- deviationStart = 3;
1747
- deviationEnd = 10 - targetValue.length;
1749
+ deviationStart = 11;
1750
+ deviationEnd = -5;
1748
1751
  break;
1749
1752
  }
1750
1753
  case "gantt": {
@@ -1752,8 +1755,8 @@ ${(mermaidTemplate == null ? void 0 : mermaidTemplate.sequence) || "sequenceDiag
1752
1755
  ${(mermaidTemplate == null ? void 0 : mermaidTemplate.gantt) || "gantt\ntitle A Gantt Diagram\ndateFormat YYYY-MM-DD\nsection Section\nA task :a1, 2014-01-01, 30d\nAnother task :after a1, 20d"}
1753
1756
  \`\`\`
1754
1757
  `;
1755
- deviationStart = 3;
1756
- deviationEnd = 10 - targetValue.length;
1758
+ deviationStart = 11;
1759
+ deviationEnd = -5;
1757
1760
  break;
1758
1761
  }
1759
1762
  case "class": {
@@ -1761,8 +1764,8 @@ ${(mermaidTemplate == null ? void 0 : mermaidTemplate.gantt) || "gantt\ntitle A
1761
1764
  ${(mermaidTemplate == null ? void 0 : mermaidTemplate.class) || "classDiagram\n class Animal\n Vehicle <|-- Car"}
1762
1765
  \`\`\`
1763
1766
  `;
1764
- deviationStart = 3;
1765
- deviationEnd = 10 - targetValue.length;
1767
+ deviationStart = 11;
1768
+ deviationEnd = -5;
1766
1769
  break;
1767
1770
  }
1768
1771
  case "state": {
@@ -1770,8 +1773,8 @@ ${(mermaidTemplate == null ? void 0 : mermaidTemplate.class) || "classDiagram\n
1770
1773
  ${(mermaidTemplate == null ? void 0 : mermaidTemplate.state) || "stateDiagram-v2\n s1 --> s2"}
1771
1774
  \`\`\`
1772
1775
  `;
1773
- deviationStart = 3;
1774
- deviationEnd = 10 - targetValue.length;
1776
+ deviationStart = 11;
1777
+ deviationEnd = -5;
1775
1778
  break;
1776
1779
  }
1777
1780
  case "pie": {
@@ -1779,8 +1782,8 @@ ${(mermaidTemplate == null ? void 0 : mermaidTemplate.state) || "stateDiagram-v2
1779
1782
  ${(mermaidTemplate == null ? void 0 : mermaidTemplate.pie) || 'pie title Pets adopted by volunteers\n "Dogs" : 386\n "Cats" : 85\n "Rats" : 15'}
1780
1783
  \`\`\`
1781
1784
  `;
1782
- deviationStart = 3;
1783
- deviationEnd = 10 - targetValue.length;
1785
+ deviationStart = 11;
1786
+ deviationEnd = -5;
1784
1787
  break;
1785
1788
  }
1786
1789
  case "relationship": {
@@ -1788,8 +1791,8 @@ ${(mermaidTemplate == null ? void 0 : mermaidTemplate.pie) || 'pie title Pets ad
1788
1791
  ${(mermaidTemplate == null ? void 0 : mermaidTemplate.relationship) || "erDiagram\n CAR ||--o{ NAMED-DRIVER : allows\n PERSON ||--o{ NAMED-DRIVER : is"}
1789
1792
  \`\`\`
1790
1793
  `;
1791
- deviationStart = 3;
1792
- deviationEnd = 10 - targetValue.length;
1794
+ deviationStart = 11;
1795
+ deviationEnd = -5;
1793
1796
  break;
1794
1797
  }
1795
1798
  case "journey": {
@@ -1797,8 +1800,8 @@ ${(mermaidTemplate == null ? void 0 : mermaidTemplate.relationship) || "erDiagra
1797
1800
  ${(mermaidTemplate == null ? void 0 : mermaidTemplate.journey) || "journey\n title My working day\n section Go to work\n Make tea: 5: Me\n Go upstairs: 3: Me\n Do work: 1: Me, Cat\n section Go home\n Go downstairs: 5: Me\n Sit down: 5: Me"}
1798
1801
  \`\`\`
1799
1802
  `;
1800
- deviationStart = 3;
1801
- deviationEnd = 10 - targetValue.length;
1803
+ deviationStart = 11;
1804
+ deviationEnd = -5;
1802
1805
  break;
1803
1806
  }
1804
1807
  case "katexInline": {
@@ -2266,13 +2269,10 @@ class CodeMirrorUt {
2266
2269
  if (options.select) {
2267
2270
  const to = from + text.length + options.deviationEnd;
2268
2271
  this.view.dispatch({
2269
- selection: state.EditorSelection.create(
2270
- [
2271
- state.EditorSelection.range(from + options.deviationStart, to),
2272
- state.EditorSelection.cursor(to)
2273
- ],
2274
- 1
2275
- )
2272
+ selection: {
2273
+ anchor: from + options.deviationStart,
2274
+ head: to
2275
+ }
2276
2276
  });
2277
2277
  }
2278
2278
  this.view.focus();
@@ -3021,7 +3021,8 @@ const Content = /* @__PURE__ */ vue.defineComponent({
3021
3021
  "class": `${config.prefix}-catalog-editor`,
3022
3022
  "editorId": editorId,
3023
3023
  "mdHeadingId": props2.mdHeadingId,
3024
- "key": "internal-catalog"
3024
+ "key": "internal-catalog",
3025
+ "scrollElementOffsetTop": 2
3025
3026
  }, null)]);
3026
3027
  };
3027
3028
  }
@@ -3182,9 +3183,10 @@ const Editor = /* @__PURE__ */ vue.defineComponent({
3182
3183
  const state2 = vue.reactive({
3183
3184
  scrollAuto: props2.scrollAuto
3184
3185
  });
3186
+ const rootRef = vue.ref();
3185
3187
  const codeRef = vue.ref();
3186
3188
  MdPreview.useOnSave(props2, ctx);
3187
- MdPreview.useProvide(props2);
3189
+ MdPreview.useProvide(props2, rootRef);
3188
3190
  MdPreview.useExpansion(props2);
3189
3191
  MdPreview.useErrorCatcher(props2, ctx);
3190
3192
  const [setting, updateSetting] = MdPreview.useConfig(props2, ctx);
@@ -3205,7 +3207,8 @@ const Editor = /* @__PURE__ */ vue.defineComponent({
3205
3207
  return vue.createVNode("div", {
3206
3208
  "id": editorId,
3207
3209
  "class": [config.prefix, props2.class, props2.theme === "dark" && `${config.prefix}-dark`, setting.fullscreen || setting.pageFullscreen ? `${config.prefix}-fullscreen` : ""],
3208
- "style": props2.style
3210
+ "style": props2.style,
3211
+ "ref": rootRef
3209
3212
  }, [props2.toolbars.length > 0 && vue.createVNode(ToolBar, {
3210
3213
  "noPrettier": noPrettier,
3211
3214
  "toolbars": props2.toolbars,
@@ -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
- document.querySelectorAll(`#${editorId} .${config.prefix}-preview .${config.prefix}-code`).forEach((codeBlock) => {
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 = document.querySelectorAll(
214
+ const mermaidSourceEles = rootRef.value.querySelectorAll(
213
215
  `div.${config.prefix}-mermaid`
214
216
  );
215
217
  const svgContainingElement = document.createElement("div");
@@ -225,7 +227,7 @@ const useMermaid = (props) => {
225
227
  mermaidSourceEles.forEach(async (item) => {
226
228
  let mermaidHtml = mermaidCache.get(item.innerText);
227
229
  if (!mermaidHtml) {
228
- const idRand = util$2.uuid();
230
+ const idRand = util$2.randomId();
229
231
  const render = mermaidRef.value.renderAsync || mermaidRef.value.render;
230
232
  let svg = "";
231
233
  try {
@@ -235,12 +237,13 @@ const useMermaid = (props) => {
235
237
  mermaidHtml = await props.sanitizeMermaid(
236
238
  typeof svg === "string" ? svg : svg.svg
237
239
  );
238
- mermaidCache.set(item.innerText, mermaidHtml);
239
240
  }
240
241
  const p = document.createElement("p");
241
242
  p.className = `${config.prefix}-mermaid`;
242
243
  p.setAttribute("data-processed", "");
243
244
  p.innerHTML = mermaidHtml;
245
+ p.children[0].removeAttribute("height");
246
+ mermaidCache.set(item.innerText, p.innerHTML);
244
247
  if (item.dataset.line !== void 0) {
245
248
  p.dataset.line = item.dataset.line;
246
249
  }
@@ -680,7 +683,7 @@ const codetabs = (md, _opts) => {
680
683
  checked = i - idx > 0 ? "" : "checked";
681
684
  labels += `<li>
682
685
  <input type="radio" name="${config.prefix}-codetab-label-${_opts.editorId}-${idx}" class="${className}" ${checked}>
683
- <label onclick="document.querySelectorAll('.${className}').forEach(e => e.click())">${tab || getLangName(token)}</label>
686
+ <label onclick="this.getRootNode().querySelectorAll('.${className}').forEach(e => e.click())">${tab || getLangName(token)}</label>
684
687
  </li>`;
685
688
  pres += `<input type="radio" name="${config.prefix}-codetab-pre-${_opts.editorId}-${idx}" class="${className}" ${checked}>
686
689
  ${defaultRender(tokens, i, options, env, slf)}`;
@@ -2246,7 +2249,7 @@ const useMarkdownIt = (props, previewOnly) => {
2246
2249
  }
2247
2250
  });
2248
2251
  initLineNumber(md);
2249
- const key = vue.ref(`_article-key_${util$2.uuid()}`);
2252
+ const key = vue.ref(`_article-key_${util$2.randomId()}`);
2250
2253
  const html = vue.ref(props.sanitize(md.render(props.modelValue)));
2251
2254
  const updatedTodo = () => {
2252
2255
  eventName.bus.emit(editorId, eventName.BUILD_FINISHED, html.value);
@@ -2273,6 +2276,7 @@ const useMarkdownIt = (props, previewOnly) => {
2273
2276
  () => {
2274
2277
  if (props.setting.preview) {
2275
2278
  vue.nextTick(() => {
2279
+ replaceMermaid();
2276
2280
  eventName.bus.emit(editorId, eventName.CATALOG_CHANGED, headsRef.value);
2277
2281
  });
2278
2282
  }
@@ -2288,7 +2292,7 @@ const useMarkdownIt = (props, previewOnly) => {
2288
2292
  eventName.bus.on(editorId, {
2289
2293
  name: eventName.RERENDER,
2290
2294
  callback: () => {
2291
- key.value = `_article-key_${util$2.uuid()}`;
2295
+ key.value = `_article-key_${util$2.randomId()}`;
2292
2296
  markHtml();
2293
2297
  }
2294
2298
  });
@@ -2308,10 +2312,11 @@ const template = {
2308
2312
  };
2309
2313
  const useTaskState = (props, html) => {
2310
2314
  const editorId = vue.inject("editorId");
2315
+ const rootRef = vue.inject("rootRef");
2311
2316
  let removeListener = () => {
2312
2317
  };
2313
2318
  const addListener = () => {
2314
- const tasks = document.querySelectorAll(`#${editorId} .task-list-item.enabled`);
2319
+ const tasks = rootRef.value.querySelectorAll(".task-list-item.enabled");
2315
2320
  const listener = (e) => {
2316
2321
  var _a;
2317
2322
  e.preventDefault();
@@ -2581,11 +2586,12 @@ const useOnSave = (props, context) => {
2581
2586
  });
2582
2587
  });
2583
2588
  };
2584
- const useProvidePreview = (props) => {
2589
+ const useProvidePreview = (props, rootRef) => {
2585
2590
  const { editorId } = props;
2586
2591
  const hljsUrls = config.configOption.editorExtensions.highlight;
2587
2592
  const hljsAttrs = config.configOption.editorExtensionsAttrs.highlight;
2588
2593
  vue.provide("editorId", editorId);
2594
+ vue.provide("rootRef", rootRef);
2589
2595
  vue.provide(
2590
2596
  "theme",
2591
2597
  vue.computed(() => props.theme)
@@ -2639,8 +2645,8 @@ const useProvidePreview = (props) => {
2639
2645
  vue.computed(() => props.customIcon)
2640
2646
  );
2641
2647
  };
2642
- const useProvide = (props) => {
2643
- useProvidePreview(props);
2648
+ const useProvide = (props, rootRef) => {
2649
+ useProvidePreview(props, rootRef);
2644
2650
  vue.provide("tabWidth", props.tabWidth);
2645
2651
  };
2646
2652
  const useExpansionPreview = (props) => {
@@ -3466,7 +3472,8 @@ const MdPreview = /* @__PURE__ */ vue.defineComponent({
3466
3472
  noMermaid,
3467
3473
  noHighlight
3468
3474
  } = props;
3469
- useProvidePreview(props);
3475
+ const rootRef = vue.ref();
3476
+ useProvidePreview(props, rootRef);
3470
3477
  useExpansionPreview(props);
3471
3478
  useExpose(props, ctx);
3472
3479
  vue.onBeforeUnmount(() => {
@@ -3476,7 +3483,8 @@ const MdPreview = /* @__PURE__ */ vue.defineComponent({
3476
3483
  return vue.createVNode("div", {
3477
3484
  "id": editorId,
3478
3485
  "class": [config.prefix, props.class, props.theme === "dark" && `${config.prefix}-dark`, `${config.prefix}-previewOnly`],
3479
- "style": props.style
3486
+ "style": props.style,
3487
+ "ref": rootRef
3480
3488
  }, [vue.createVNode(ContentPreview, {
3481
3489
  "modelValue": props.modelValue,
3482
3490
  "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 relativecrollLeft = ((_a = document.querySelector(props2.relative)) == null ? void 0 : _a.scrollLeft) || 0;
51
- const relativeWidth = ((_b = document.querySelector(props2.relative)) == null ? void 0 : _b.clientWidth) || 0;
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
- bodyRef.value = document.body;
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({