@yl_lowcode/docs-theme 0.0.2 → 0.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/demo.vue +3 -4
- package/package.json +1 -1
- package/playground.vue +3 -3
- package/plugins/shiki-raw.js +7 -0
package/demo.vue
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
// @ts-nocheck
|
|
3
|
+
import React from "react";
|
|
4
|
+
import * as ReactDOMClient from "react-dom/client";
|
|
3
5
|
import { ref, onMounted, onBeforeUnmount } from "vue";
|
|
4
6
|
import { withBase } from 'vitepress'
|
|
5
7
|
|
|
@@ -17,11 +19,8 @@ let copyTimer: ReturnType<typeof setTimeout> | null = null;
|
|
|
17
19
|
|
|
18
20
|
function mountPreview() {
|
|
19
21
|
if (!previewRef.value) return;
|
|
20
|
-
const React = (window as any).React;
|
|
21
|
-
const ReactDOM = (window as any).ReactDOM;
|
|
22
|
-
if (!React || !ReactDOM) return;
|
|
23
22
|
previewRoot?.unmount();
|
|
24
|
-
previewRoot =
|
|
23
|
+
previewRoot = ReactDOMClient.createRoot(previewRef.value);
|
|
25
24
|
previewRoot.render(React.createElement(props.component));
|
|
26
25
|
}
|
|
27
26
|
function openLive() {
|
package/package.json
CHANGED
package/playground.vue
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
// @ts-nocheck
|
|
3
|
+
import React from "react";
|
|
4
|
+
import * as ReactDOMClient from "react-dom/client";
|
|
3
5
|
import { ref, inject, onMounted, onBeforeUnmount } from "vue";
|
|
4
6
|
/**
|
|
5
7
|
* 通用 Playground 组件
|
|
@@ -30,8 +32,6 @@ onMounted(async () => {
|
|
|
30
32
|
if (!matchKey) return;
|
|
31
33
|
|
|
32
34
|
const rawCode = (await config.codeGlobs[matchKey]()).raw as string;
|
|
33
|
-
const React = (window as any).React;
|
|
34
|
-
const ReactDOM = (window as any).ReactDOM;
|
|
35
35
|
const { transform } = await import("sucrase");
|
|
36
36
|
const userModules = await config.loadModules();
|
|
37
37
|
|
|
@@ -202,7 +202,7 @@ onMounted(async () => {
|
|
|
202
202
|
);
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
-
reactRoot =
|
|
205
|
+
reactRoot = ReactDOMClient.createRoot(containerRef.value);
|
|
206
206
|
reactRoot.render(React.createElement(App));
|
|
207
207
|
});
|
|
208
208
|
|
package/plugins/shiki-raw.js
CHANGED
|
@@ -10,6 +10,11 @@ function getMd(srcDir, options) {
|
|
|
10
10
|
return mdPromise;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
// 配置文件变更时 VitePress 会重新加载插件,重置单例避免引用已销毁的 Shiki 实例
|
|
14
|
+
export function resetMd() {
|
|
15
|
+
mdPromise = null;
|
|
16
|
+
}
|
|
17
|
+
|
|
13
18
|
export function shikiRawPlugin(options) {
|
|
14
19
|
let srcDir = process.cwd();
|
|
15
20
|
|
|
@@ -18,6 +23,8 @@ export function shikiRawPlugin(options) {
|
|
|
18
23
|
enforce: "pre",
|
|
19
24
|
configResolved(config) {
|
|
20
25
|
srcDir = config.root;
|
|
26
|
+
// 每次配置重新解析时重置 markdown renderer,避免 Shiki disposed 错误
|
|
27
|
+
resetMd();
|
|
21
28
|
},
|
|
22
29
|
async load(id) {
|
|
23
30
|
if (!id.endsWith("?raw")) return null;
|