@rspress/plugin-playground 2.0.0-beta.14 → 2.0.0-beta.16
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/dist/cli/index.js +16 -16
- package/dist/web/index.js +5 -5
- package/package.json +6 -6
package/dist/cli/index.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { fileURLToPath as __webpack_fileURLToPath__ } from "node:url";
|
|
2
2
|
import { dirname as __webpack_dirname__ } from "node:path";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import node_fs from "node:fs";
|
|
4
|
+
import node_path, { dirname, join, resolve } from "node:path";
|
|
5
5
|
import { getNodeAttribute } from "@rspress/shared/node-utils";
|
|
6
6
|
import { RspackVirtualModulePlugin } from "rspack-plugin-virtual-module";
|
|
7
7
|
import { visit as external_unist_util_visit_visit } from "unist-util-visit";
|
|
8
|
-
import
|
|
8
|
+
import napi from "@oxidation-compiler/napi";
|
|
9
9
|
const DEFAULT_BABEL_URL = 'https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/7.22.20/babel.min.js';
|
|
10
10
|
const DEFAULT_MONACO_URL = 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.43.0/min/vs';
|
|
11
11
|
function normalizeUrl(u) {
|
|
12
12
|
return u.replace(/\/\//g, '/');
|
|
13
13
|
}
|
|
14
14
|
const parseImports = (code, sourceExt)=>{
|
|
15
|
-
const parsed =
|
|
15
|
+
const parsed = napi.parseSync(code, {
|
|
16
16
|
sourceType: 'module',
|
|
17
17
|
sourceFilename: `index.${sourceExt}`
|
|
18
18
|
});
|
|
@@ -51,9 +51,9 @@ const remarkPlugin = ({ getRouteMeta, editorPosition, defaultRenderMode })=>{
|
|
|
51
51
|
const src = getNodeAttribute(node, 'src');
|
|
52
52
|
if ('string' != typeof src) return;
|
|
53
53
|
const demoPath = join(dirname(route.absolutePath), src);
|
|
54
|
-
if (!
|
|
54
|
+
if (!node_fs.existsSync(demoPath)) return;
|
|
55
55
|
const direction = getNodeAttribute(node, 'direction') || '';
|
|
56
|
-
const code =
|
|
56
|
+
const code = node_fs.readFileSync(demoPath, {
|
|
57
57
|
encoding: 'utf8'
|
|
58
58
|
});
|
|
59
59
|
const language = src.slice(src.lastIndexOf('.') + 1);
|
|
@@ -117,8 +117,8 @@ const remarkPlugin = ({ getRouteMeta, editorPosition, defaultRenderMode })=>{
|
|
|
117
117
|
};
|
|
118
118
|
};
|
|
119
119
|
var cli_dirname = __webpack_dirname__(__webpack_fileURLToPath__(import.meta.url));
|
|
120
|
-
const pkgRootPath =
|
|
121
|
-
const staticPath =
|
|
120
|
+
const pkgRootPath = node_path.join(cli_dirname, '../../');
|
|
121
|
+
const staticPath = node_path.join(pkgRootPath, 'static');
|
|
122
122
|
let cli_routeMeta;
|
|
123
123
|
function pluginPlayground(options) {
|
|
124
124
|
const { render = '', include, defaultDirection = 'horizontal', editorPosition = 'left', babelUrl = DEFAULT_BABEL_URL, monacoLoader = {}, monacoOptions = {}, defaultRenderMode = 'playground' } = options || {};
|
|
@@ -148,23 +148,23 @@ function pluginPlayground(options) {
|
|
|
148
148
|
const { default: remarkGFM } = await import("remark-gfm");
|
|
149
149
|
try {
|
|
150
150
|
const processor = createProcessor({
|
|
151
|
-
format:
|
|
151
|
+
format: node_path.extname(filepath).slice(1),
|
|
152
152
|
remarkPlugins: [
|
|
153
153
|
remarkGFM
|
|
154
154
|
]
|
|
155
155
|
});
|
|
156
|
-
const source = await
|
|
156
|
+
const source = await node_fs.promises.readFile(filepath, 'utf-8');
|
|
157
157
|
const ast = processor.parse(source);
|
|
158
158
|
visit(ast, 'mdxJsxFlowElement', (node)=>{
|
|
159
159
|
if ('code' === node.name) {
|
|
160
160
|
const src = getNodeAttribute(node, 'src');
|
|
161
161
|
if ('string' != typeof src) return;
|
|
162
|
-
const demoPath = join(
|
|
163
|
-
if (!
|
|
164
|
-
const code =
|
|
162
|
+
const demoPath = join(node_path.dirname(filepath), src);
|
|
163
|
+
if (!node_fs.existsSync(demoPath)) return;
|
|
164
|
+
const code = node_fs.readFileSync(demoPath, {
|
|
165
165
|
encoding: 'utf8'
|
|
166
166
|
});
|
|
167
|
-
const thisImports = parseImports(code,
|
|
167
|
+
const thisImports = parseImports(code, node_path.extname(demoPath));
|
|
168
168
|
thisImports.forEach((x)=>{
|
|
169
169
|
if (void 0 === imports[x]) imports[x] = x;
|
|
170
170
|
});
|
|
@@ -266,10 +266,10 @@ function pluginPlayground(options) {
|
|
|
266
266
|
]
|
|
267
267
|
],
|
|
268
268
|
globalComponents: [
|
|
269
|
-
render ? render :
|
|
269
|
+
render ? render : node_path.join(staticPath, 'global-components', 'Playground.tsx')
|
|
270
270
|
]
|
|
271
271
|
},
|
|
272
|
-
globalStyles:
|
|
272
|
+
globalStyles: node_path.join(staticPath, 'global-styles', 'web.css')
|
|
273
273
|
};
|
|
274
274
|
}
|
|
275
275
|
export { pluginPlayground, cli_routeMeta as routeMeta };
|
package/dist/web/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import react, { loader } from "@monaco-editor/react";
|
|
2
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useDark } from "@rspress/core/runtime";
|
|
4
|
-
import
|
|
4
|
+
import react_0, { Component, useMemo } from "react";
|
|
5
5
|
const DEFAULT_MONACO_URL = 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.43.0/min/vs';
|
|
6
6
|
function initLoader() {
|
|
7
7
|
let loaderConfig = {
|
|
@@ -34,7 +34,7 @@ function Editor(props) {
|
|
|
34
34
|
]);
|
|
35
35
|
return /*#__PURE__*/ jsx("div", {
|
|
36
36
|
className: `rspress-playground-editor ${className}`,
|
|
37
|
-
children: /*#__PURE__*/ jsx(
|
|
37
|
+
children: /*#__PURE__*/ jsx(react, {
|
|
38
38
|
...rest,
|
|
39
39
|
theme: theme,
|
|
40
40
|
options: {
|
|
@@ -228,7 +228,7 @@ class Runner extends Component {
|
|
|
228
228
|
func(getImport, runExports);
|
|
229
229
|
if (runExports.default) return void this.setState({
|
|
230
230
|
error: void 0,
|
|
231
|
-
comp: /*#__PURE__*/
|
|
231
|
+
comp: /*#__PURE__*/ react_0.createElement(runExports.default)
|
|
232
232
|
});
|
|
233
233
|
this.setState({
|
|
234
234
|
error: new Error('No default export')
|
|
@@ -267,4 +267,4 @@ class Runner extends Component {
|
|
|
267
267
|
});
|
|
268
268
|
}
|
|
269
269
|
}
|
|
270
|
-
export { Editor,
|
|
270
|
+
export { Editor, react as MonacoEditor, loader as MonacoEditorLoader, Runner };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspress/plugin-playground",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.16",
|
|
4
4
|
"description": "A plugin for rspress to preview the code block in markdown/mdx file.",
|
|
5
5
|
"bugs": "https://github.com/web-infra-dev/rspress/issues",
|
|
6
6
|
"repository": {
|
|
@@ -33,18 +33,18 @@
|
|
|
33
33
|
"remark-gfm": "^4.0.1",
|
|
34
34
|
"rspack-plugin-virtual-module": "1.0.1",
|
|
35
35
|
"unist-util-visit": "^5.0.0",
|
|
36
|
-
"@rspress/shared": "2.0.0-beta.
|
|
36
|
+
"@rspress/shared": "2.0.0-beta.16"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@babel/types": "^7.27.6",
|
|
40
40
|
"@rsbuild/plugin-react": "~1.3.2",
|
|
41
|
-
"@rslib/core": "0.
|
|
41
|
+
"@rslib/core": "0.10.0",
|
|
42
42
|
"@types/babel__core": "^7.20.5",
|
|
43
43
|
"@types/babel__standalone": "^7.1.9",
|
|
44
44
|
"@types/babel__traverse": "^7.20.7",
|
|
45
45
|
"@types/mdast": "^4.0.4",
|
|
46
46
|
"@types/node": "^22.8.1",
|
|
47
|
-
"@types/react": "^19.1.
|
|
47
|
+
"@types/react": "^19.1.8",
|
|
48
48
|
"@types/react-dom": "^19.1.6",
|
|
49
49
|
"mdast-util-mdx-jsx": "^3.2.0",
|
|
50
50
|
"react": "^19.1.0",
|
|
@@ -53,10 +53,10 @@
|
|
|
53
53
|
"rsbuild-plugin-publint": "^0.3.2",
|
|
54
54
|
"typescript": "^5.8.2",
|
|
55
55
|
"unified": "^11.0.5",
|
|
56
|
-
"@rspress/plugin-playground": "2.0.0-beta.
|
|
56
|
+
"@rspress/plugin-playground": "2.0.0-beta.16"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"@rspress/core": "^2.0.0-beta.
|
|
59
|
+
"@rspress/core": "^2.0.0-beta.16",
|
|
60
60
|
"react": ">=18.0.0",
|
|
61
61
|
"react-router-dom": "^6.8.1"
|
|
62
62
|
},
|