@rspress/plugin-playground 1.43.0-canary-20240224 → 1.43.0-canary-202503021457
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/cjs/index.js +10 -13
- package/dist/cli/esm/index.mjs +16 -15
- package/dist/web/cjs/index.js +16 -6
- package/dist/web/esm/index.d.ts +3 -2
- package/dist/web/esm/index.mjs +51 -34
- package/package.json +6 -4
- package/static/global-components/Playground.tsx +3 -2
package/dist/cli/cjs/index.js
CHANGED
|
@@ -207,6 +207,7 @@ var __webpack_exports__ = {};
|
|
|
207
207
|
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
208
208
|
const external_node_path_namespaceObject = require("node:path");
|
|
209
209
|
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
210
|
+
const node_utils_namespaceObject = require("@rspress/shared/node-utils");
|
|
210
211
|
const external_rspack_plugin_virtual_module_namespaceObject = require("rspack-plugin-virtual-module");
|
|
211
212
|
const DEFAULT_BABEL_URL = 'https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/7.22.20/babel.min.js';
|
|
212
213
|
const DEFAULT_MONACO_URL = 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.43.0/min/vs';
|
|
@@ -229,15 +230,11 @@ var __webpack_exports__ = {};
|
|
|
229
230
|
});
|
|
230
231
|
return result;
|
|
231
232
|
};
|
|
232
|
-
const getNodeAttribute = (node, attrName)=>{
|
|
233
|
-
var _node_attributes_find;
|
|
234
|
-
return null === (_node_attributes_find = node.attributes.find((attr)=>attr.name === attrName)) || void 0 === _node_attributes_find ? void 0 : _node_attributes_find.value;
|
|
235
|
-
};
|
|
236
233
|
const getNodeMeta = (node, metaName)=>{
|
|
237
234
|
if (!node.meta) return;
|
|
238
235
|
const meta = node.meta.split(' ');
|
|
239
236
|
const item = meta.find((x)=>x.startsWith(metaName));
|
|
240
|
-
if (null == item ? void 0 : item.startsWith(`${metaName}=`)) return item.
|
|
237
|
+
if (null == item ? void 0 : item.startsWith(`${metaName}=`)) return item.slice(metaName.length + 1);
|
|
241
238
|
return item;
|
|
242
239
|
};
|
|
243
240
|
function createPlaygroundNode(currentNode, attrs) {
|
|
@@ -258,15 +255,15 @@ var __webpack_exports__ = {};
|
|
|
258
255
|
if (!route) return;
|
|
259
256
|
(0, lib.Vn)(tree, 'mdxJsxFlowElement', (node)=>{
|
|
260
257
|
if ('code' === node.name) {
|
|
261
|
-
const src = getNodeAttribute(node, 'src');
|
|
262
|
-
if (
|
|
258
|
+
const src = (0, node_utils_namespaceObject.getNodeAttribute)(node, 'src');
|
|
259
|
+
if ('string' != typeof src) return;
|
|
263
260
|
const demoPath = (0, external_node_path_namespaceObject.join)((0, external_node_path_namespaceObject.dirname)(route.absolutePath), src);
|
|
264
261
|
if (!external_node_fs_default().existsSync(demoPath)) return;
|
|
265
|
-
const direction = getNodeAttribute(node, 'direction') || '';
|
|
262
|
+
const direction = (0, node_utils_namespaceObject.getNodeAttribute)(node, 'direction') || '';
|
|
266
263
|
const code = external_node_fs_default().readFileSync(demoPath, {
|
|
267
264
|
encoding: 'utf8'
|
|
268
265
|
});
|
|
269
|
-
const language = src.
|
|
266
|
+
const language = src.slice(src.lastIndexOf('.') + 1);
|
|
270
267
|
createPlaygroundNode(node, [
|
|
271
268
|
[
|
|
272
269
|
'code',
|
|
@@ -290,8 +287,8 @@ var __webpack_exports__ = {};
|
|
|
290
287
|
(0, lib.Vn)(tree, 'code', (node)=>{
|
|
291
288
|
if ('jsx' === node.lang || 'tsx' === node.lang) {
|
|
292
289
|
var _node_meta, _node_meta1;
|
|
293
|
-
const hasPureMeta = null
|
|
294
|
-
const hasPlaygroundMeta = null
|
|
290
|
+
const hasPureMeta = null === (_node_meta = node.meta) || void 0 === _node_meta ? void 0 : _node_meta.includes('pure');
|
|
291
|
+
const hasPlaygroundMeta = null === (_node_meta1 = node.meta) || void 0 === _node_meta1 ? void 0 : _node_meta1.includes('playground');
|
|
295
292
|
let noTransform;
|
|
296
293
|
switch(defaultRenderMode){
|
|
297
294
|
case 'pure':
|
|
@@ -367,8 +364,8 @@ var __webpack_exports__ = {};
|
|
|
367
364
|
const ast = processor.parse(source);
|
|
368
365
|
visit(ast, 'mdxJsxFlowElement', (node)=>{
|
|
369
366
|
if ('code' === node.name) {
|
|
370
|
-
const src = getNodeAttribute(node, 'src');
|
|
371
|
-
if (
|
|
367
|
+
const src = (0, node_utils_namespaceObject.getNodeAttribute)(node, 'src');
|
|
368
|
+
if ('string' != typeof src) return;
|
|
372
369
|
const demoPath = (0, external_node_path_namespaceObject.join)(external_node_path_default().dirname(filepath), src);
|
|
373
370
|
if (!external_node_fs_default().existsSync(demoPath)) return;
|
|
374
371
|
const code = external_node_fs_default().readFileSync(demoPath, {
|
package/dist/cli/esm/index.mjs
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { fileURLToPath as __webpack_fileURLToPath__ } from "node:url";
|
|
2
|
+
import { dirname as __webpack_dirname__ } from "node:path";
|
|
1
3
|
import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs";
|
|
2
4
|
import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
|
|
5
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__ from "@rspress/shared/node-utils";
|
|
3
6
|
import * as __WEBPACK_EXTERNAL_MODULE_rspack_plugin_virtual_module_609978fd__ from "rspack-plugin-virtual-module";
|
|
4
7
|
import * as __WEBPACK_EXTERNAL_MODULE__oxidation_compiler_napi_5e24345a__ from "@oxidation-compiler/napi";
|
|
5
8
|
var __webpack_modules__ = {
|
|
@@ -200,7 +203,8 @@ const DEFAULT_MONACO_URL = 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor
|
|
|
200
203
|
function normalizeUrl(u) {
|
|
201
204
|
return u.replace(/\/\//g, '/');
|
|
202
205
|
}
|
|
203
|
-
|
|
206
|
+
var constant_dirname = __webpack_dirname__(__webpack_fileURLToPath__(import.meta.url));
|
|
207
|
+
const staticPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(constant_dirname, '../../../static');
|
|
204
208
|
var lib = __webpack_require__("../../node_modules/.pnpm/unist-util-visit@4.1.2/node_modules/unist-util-visit/lib/index.js");
|
|
205
209
|
const parseImports = (code, sourceExt)=>{
|
|
206
210
|
const parsed = __WEBPACK_EXTERNAL_MODULE__oxidation_compiler_napi_5e24345a__["default"].parseSync(code, {
|
|
@@ -214,15 +218,11 @@ const parseImports = (code, sourceExt)=>{
|
|
|
214
218
|
});
|
|
215
219
|
return result;
|
|
216
220
|
};
|
|
217
|
-
const getNodeAttribute = (node, attrName)=>{
|
|
218
|
-
var _node_attributes_find;
|
|
219
|
-
return null === (_node_attributes_find = node.attributes.find((attr)=>attr.name === attrName)) || void 0 === _node_attributes_find ? void 0 : _node_attributes_find.value;
|
|
220
|
-
};
|
|
221
221
|
const getNodeMeta = (node, metaName)=>{
|
|
222
222
|
if (!node.meta) return;
|
|
223
223
|
const meta = node.meta.split(' ');
|
|
224
224
|
const item = meta.find((x)=>x.startsWith(metaName));
|
|
225
|
-
if (null == item ? void 0 : item.startsWith(`${metaName}=`)) return item.
|
|
225
|
+
if (null == item ? void 0 : item.startsWith(`${metaName}=`)) return item.slice(metaName.length + 1);
|
|
226
226
|
return item;
|
|
227
227
|
};
|
|
228
228
|
function createPlaygroundNode(currentNode, attrs) {
|
|
@@ -243,15 +243,15 @@ const remarkPlugin = ({ getRouteMeta, editorPosition, defaultRenderMode })=>{
|
|
|
243
243
|
if (!route) return;
|
|
244
244
|
(0, lib.Vn)(tree, 'mdxJsxFlowElement', (node)=>{
|
|
245
245
|
if ('code' === node.name) {
|
|
246
|
-
const src = getNodeAttribute(node, 'src');
|
|
247
|
-
if (
|
|
246
|
+
const src = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.getNodeAttribute)(node, 'src');
|
|
247
|
+
if ('string' != typeof src) return;
|
|
248
248
|
const demoPath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.dirname)(route.absolutePath), src);
|
|
249
249
|
if (!__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].existsSync(demoPath)) return;
|
|
250
|
-
const direction = getNodeAttribute(node, 'direction') || '';
|
|
250
|
+
const direction = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.getNodeAttribute)(node, 'direction') || '';
|
|
251
251
|
const code = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].readFileSync(demoPath, {
|
|
252
252
|
encoding: 'utf8'
|
|
253
253
|
});
|
|
254
|
-
const language = src.
|
|
254
|
+
const language = src.slice(src.lastIndexOf('.') + 1);
|
|
255
255
|
createPlaygroundNode(node, [
|
|
256
256
|
[
|
|
257
257
|
'code',
|
|
@@ -275,8 +275,8 @@ const remarkPlugin = ({ getRouteMeta, editorPosition, defaultRenderMode })=>{
|
|
|
275
275
|
(0, lib.Vn)(tree, 'code', (node)=>{
|
|
276
276
|
if ('jsx' === node.lang || 'tsx' === node.lang) {
|
|
277
277
|
var _node_meta, _node_meta1;
|
|
278
|
-
const hasPureMeta = null
|
|
279
|
-
const hasPlaygroundMeta = null
|
|
278
|
+
const hasPureMeta = null === (_node_meta = node.meta) || void 0 === _node_meta ? void 0 : _node_meta.includes('pure');
|
|
279
|
+
const hasPlaygroundMeta = null === (_node_meta1 = node.meta) || void 0 === _node_meta1 ? void 0 : _node_meta1.includes('playground');
|
|
280
280
|
let noTransform;
|
|
281
281
|
switch(defaultRenderMode){
|
|
282
282
|
case 'pure':
|
|
@@ -312,6 +312,7 @@ const remarkPlugin = ({ getRouteMeta, editorPosition, defaultRenderMode })=>{
|
|
|
312
312
|
});
|
|
313
313
|
};
|
|
314
314
|
};
|
|
315
|
+
var cli_rslib_entry_dirname = __webpack_dirname__(__webpack_fileURLToPath__(import.meta.url));
|
|
315
316
|
let cli_rslib_entry_routeMeta;
|
|
316
317
|
function pluginPlayground(options) {
|
|
317
318
|
var _monacoLoader_paths;
|
|
@@ -352,8 +353,8 @@ function pluginPlayground(options) {
|
|
|
352
353
|
const ast = processor.parse(source);
|
|
353
354
|
visit(ast, 'mdxJsxFlowElement', (node)=>{
|
|
354
355
|
if ('code' === node.name) {
|
|
355
|
-
const src = getNodeAttribute(node, 'src');
|
|
356
|
-
if (
|
|
356
|
+
const src = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.getNodeAttribute)(node, 'src');
|
|
357
|
+
if ('string' != typeof src) return;
|
|
357
358
|
const demoPath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname(filepath), src);
|
|
358
359
|
if (!__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].existsSync(demoPath)) return;
|
|
359
360
|
const code = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].readFileSync(demoPath, {
|
|
@@ -427,7 +428,7 @@ function pluginPlayground(options) {
|
|
|
427
428
|
__PLAYGROUND_BABEL_URL__: JSON.stringify(babelUrl)
|
|
428
429
|
},
|
|
429
430
|
include: [
|
|
430
|
-
(0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(
|
|
431
|
+
(0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(cli_rslib_entry_dirname, '..', '..', '..')
|
|
431
432
|
]
|
|
432
433
|
},
|
|
433
434
|
html: {
|
package/dist/web/cjs/index.js
CHANGED
|
@@ -59,14 +59,14 @@ function initLoader() {
|
|
|
59
59
|
try {
|
|
60
60
|
const keys = Object.keys(__PLAYGROUND_MONACO_LOADER__);
|
|
61
61
|
if (keys.length > 0) loaderConfig = __PLAYGROUND_MONACO_LOADER__;
|
|
62
|
-
} catch (
|
|
62
|
+
} catch (_e) {}
|
|
63
63
|
react_namespaceObject.loader.config(loaderConfig);
|
|
64
64
|
}
|
|
65
65
|
initLoader();
|
|
66
66
|
function getMonacoOptions() {
|
|
67
67
|
try {
|
|
68
68
|
return __PLAYGROUND_MONACO_OPTIONS__;
|
|
69
|
-
} catch (
|
|
69
|
+
} catch (_e) {}
|
|
70
70
|
return {};
|
|
71
71
|
}
|
|
72
72
|
function Editor(props) {
|
|
@@ -79,9 +79,9 @@ function Editor(props) {
|
|
|
79
79
|
themeProp,
|
|
80
80
|
dark
|
|
81
81
|
]);
|
|
82
|
-
return /*#__PURE__*/
|
|
82
|
+
return /*#__PURE__*/ React.createElement("div", {
|
|
83
83
|
className: `rspress-playground-editor ${className}`
|
|
84
|
-
}, /*#__PURE__*/
|
|
84
|
+
}, /*#__PURE__*/ React.createElement(react_default(), {
|
|
85
85
|
...rest,
|
|
86
86
|
theme: theme,
|
|
87
87
|
options: {
|
|
@@ -187,6 +187,16 @@ async function getBabel() {
|
|
|
187
187
|
throw e;
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
|
+
function _define_property(obj, key, value) {
|
|
191
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
192
|
+
value: value,
|
|
193
|
+
enumerable: true,
|
|
194
|
+
configurable: true,
|
|
195
|
+
writable: true
|
|
196
|
+
});
|
|
197
|
+
else obj[key] = value;
|
|
198
|
+
return obj;
|
|
199
|
+
}
|
|
190
200
|
const DEBOUNCE_TIME = 800;
|
|
191
201
|
class Runner extends external_react_namespaceObject.Component {
|
|
192
202
|
static getDerivedStateFromError(error) {
|
|
@@ -197,7 +207,7 @@ class Runner extends external_react_namespaceObject.Component {
|
|
|
197
207
|
}
|
|
198
208
|
waitCompile(targetCode) {
|
|
199
209
|
if (this.timer) clearTimeout(this.timer);
|
|
200
|
-
this.timer = setTimeout(()=>{
|
|
210
|
+
this.timer = window.setTimeout(()=>{
|
|
201
211
|
this.timer = null;
|
|
202
212
|
this.doCompile(targetCode);
|
|
203
213
|
}, DEBOUNCE_TIME);
|
|
@@ -303,7 +313,7 @@ class Runner extends external_react_namespaceObject.Component {
|
|
|
303
313
|
}, error.message));
|
|
304
314
|
}
|
|
305
315
|
constructor(props){
|
|
306
|
-
super(props);
|
|
316
|
+
super(props), _define_property(this, "timer", null);
|
|
307
317
|
this.state = {
|
|
308
318
|
error: void 0,
|
|
309
319
|
comp: null
|
package/dist/web/esm/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { default as MonacoEditor } from '@monaco-editor/react';
|
|
|
5
5
|
import { loader as MonacoEditorLoader } from '@monaco-editor/react';
|
|
6
6
|
import { EditorProps as MonacoEditorProps } from '@monaco-editor/react';
|
|
7
7
|
import { default as React_2 } from 'react';
|
|
8
|
+
import { ReactElement } from 'react';
|
|
8
9
|
|
|
9
10
|
export declare function Editor(props: EditorProps): JSX_2.Element;
|
|
10
11
|
|
|
@@ -21,7 +22,7 @@ export declare class Runner extends Component<RunnerProps, RunnerState> {
|
|
|
21
22
|
error: Error;
|
|
22
23
|
comp: null;
|
|
23
24
|
};
|
|
24
|
-
timer:
|
|
25
|
+
timer: number | null;
|
|
25
26
|
constructor(props: RunnerProps);
|
|
26
27
|
waitCompile(targetCode: string): void;
|
|
27
28
|
doCompile(targetCode: string): Promise<void>;
|
|
@@ -39,7 +40,7 @@ declare interface RunnerProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
39
40
|
|
|
40
41
|
declare interface RunnerState {
|
|
41
42
|
error?: Error;
|
|
42
|
-
comp:
|
|
43
|
+
comp: ReactElement | null;
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
export { }
|
package/dist/web/esm/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as __WEBPACK_EXTERNAL_MODULE__monaco_editor_react_be42f315__ from "@monaco-editor/react";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__ from "react/jsx-runtime";
|
|
2
3
|
import * as __WEBPACK_EXTERNAL_MODULE__rspress_core_runtime_7dc96146__ from "@rspress/core/runtime";
|
|
3
4
|
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
|
|
4
5
|
const DEFAULT_MONACO_URL = 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.43.0/min/vs';
|
|
@@ -11,14 +12,14 @@ function initLoader() {
|
|
|
11
12
|
try {
|
|
12
13
|
const keys = Object.keys(__PLAYGROUND_MONACO_LOADER__);
|
|
13
14
|
if (keys.length > 0) loaderConfig = __PLAYGROUND_MONACO_LOADER__;
|
|
14
|
-
} catch (
|
|
15
|
+
} catch (_e) {}
|
|
15
16
|
__WEBPACK_EXTERNAL_MODULE__monaco_editor_react_be42f315__.loader.config(loaderConfig);
|
|
16
17
|
}
|
|
17
18
|
initLoader();
|
|
18
19
|
function getMonacoOptions() {
|
|
19
20
|
try {
|
|
20
21
|
return __PLAYGROUND_MONACO_OPTIONS__;
|
|
21
|
-
} catch (
|
|
22
|
+
} catch (_e) {}
|
|
22
23
|
return {};
|
|
23
24
|
}
|
|
24
25
|
function Editor(props) {
|
|
@@ -31,31 +32,32 @@ function Editor(props) {
|
|
|
31
32
|
themeProp,
|
|
32
33
|
dark
|
|
33
34
|
]);
|
|
34
|
-
return /*#__PURE__*/
|
|
35
|
-
className: `rspress-playground-editor ${className}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
35
|
+
return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("div", {
|
|
36
|
+
className: `rspress-playground-editor ${className}`,
|
|
37
|
+
children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__monaco_editor_react_be42f315__["default"], {
|
|
38
|
+
...rest,
|
|
39
|
+
theme: theme,
|
|
40
|
+
options: {
|
|
41
|
+
minimap: {
|
|
42
|
+
enabled: true,
|
|
43
|
+
autohide: true
|
|
44
|
+
},
|
|
45
|
+
fontSize: 14,
|
|
46
|
+
lineNumbersMinChars: 7,
|
|
47
|
+
scrollBeyondLastLine: false,
|
|
48
|
+
automaticLayout: true,
|
|
49
|
+
wordBasedSuggestions: true,
|
|
50
|
+
quickSuggestions: true,
|
|
51
|
+
scrollbar: {
|
|
52
|
+
verticalScrollbarSize: 8,
|
|
53
|
+
horizontalScrollbarSize: 8
|
|
54
|
+
},
|
|
55
|
+
scrollPredominantAxis: false,
|
|
56
|
+
...getMonacoOptions(),
|
|
57
|
+
...options
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
});
|
|
59
61
|
}
|
|
60
62
|
function createVariableDeclaration(id, init) {
|
|
61
63
|
return {
|
|
@@ -139,6 +141,16 @@ async function getBabel() {
|
|
|
139
141
|
throw e;
|
|
140
142
|
}
|
|
141
143
|
}
|
|
144
|
+
function _define_property(obj, key, value) {
|
|
145
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
146
|
+
value: value,
|
|
147
|
+
enumerable: true,
|
|
148
|
+
configurable: true,
|
|
149
|
+
writable: true
|
|
150
|
+
});
|
|
151
|
+
else obj[key] = value;
|
|
152
|
+
return obj;
|
|
153
|
+
}
|
|
142
154
|
const DEBOUNCE_TIME = 800;
|
|
143
155
|
class Runner extends __WEBPACK_EXTERNAL_MODULE_react__.Component {
|
|
144
156
|
static getDerivedStateFromError(error) {
|
|
@@ -149,7 +161,7 @@ class Runner extends __WEBPACK_EXTERNAL_MODULE_react__.Component {
|
|
|
149
161
|
}
|
|
150
162
|
waitCompile(targetCode) {
|
|
151
163
|
if (this.timer) clearTimeout(this.timer);
|
|
152
|
-
this.timer = setTimeout(()=>{
|
|
164
|
+
this.timer = window.setTimeout(()=>{
|
|
153
165
|
this.timer = null;
|
|
154
166
|
this.doCompile(targetCode);
|
|
155
167
|
}, DEBOUNCE_TIME);
|
|
@@ -247,15 +259,20 @@ class Runner extends __WEBPACK_EXTERNAL_MODULE_react__.Component {
|
|
|
247
259
|
render() {
|
|
248
260
|
const { className = '', code, language, getImport, ...rest } = this.props;
|
|
249
261
|
const { error, comp } = this.state;
|
|
250
|
-
return /*#__PURE__*/
|
|
262
|
+
return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("div", {
|
|
251
263
|
className: `rspress-playground-runner ${className}`,
|
|
252
|
-
...rest
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
264
|
+
...rest,
|
|
265
|
+
children: [
|
|
266
|
+
comp,
|
|
267
|
+
error && /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("pre", {
|
|
268
|
+
className: "rspress-playground-error",
|
|
269
|
+
children: error.message
|
|
270
|
+
})
|
|
271
|
+
]
|
|
272
|
+
});
|
|
256
273
|
}
|
|
257
274
|
constructor(props){
|
|
258
|
-
super(props);
|
|
275
|
+
super(props), _define_property(this, "timer", null);
|
|
259
276
|
this.state = {
|
|
260
277
|
error: void 0,
|
|
261
278
|
comp: null
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspress/plugin-playground",
|
|
3
|
-
"version": "1.43.0-canary-
|
|
3
|
+
"version": "1.43.0-canary-202503021457",
|
|
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": {
|
|
@@ -34,11 +34,12 @@
|
|
|
34
34
|
"@oxidation-compiler/napi": "^0.2.0",
|
|
35
35
|
"remark-gfm": "3.0.1",
|
|
36
36
|
"rspack-plugin-virtual-module": "0.1.13",
|
|
37
|
-
"@rspress/shared": "1.43.0-canary-
|
|
37
|
+
"@rspress/shared": "1.43.0-canary-202503021457"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@babel/types": "^7.26.7",
|
|
41
|
-
"@
|
|
41
|
+
"@rsbuild/plugin-react": "~1.1.0",
|
|
42
|
+
"@rslib/core": "0.5.2",
|
|
42
43
|
"@types/babel__core": "^7.20.5",
|
|
43
44
|
"@types/babel__standalone": "^7.1.9",
|
|
44
45
|
"@types/babel__traverse": "^7.20.6",
|
|
@@ -46,6 +47,7 @@
|
|
|
46
47
|
"@types/node": "^18.11.17",
|
|
47
48
|
"@types/react": "^18.3.18",
|
|
48
49
|
"@types/react-dom": "^18.3.5",
|
|
50
|
+
"mdast-util-mdx-jsx": "^2.1.4",
|
|
49
51
|
"react": "^18.3.1",
|
|
50
52
|
"react-dom": "^18.3.1",
|
|
51
53
|
"react-router-dom": "^6.29.0",
|
|
@@ -54,7 +56,7 @@
|
|
|
54
56
|
"unist-util-visit": "^4.1.2"
|
|
55
57
|
},
|
|
56
58
|
"peerDependencies": {
|
|
57
|
-
"@rspress/core": "^1.
|
|
59
|
+
"@rspress/core": "^1.43.0-canary-202503021457",
|
|
58
60
|
"react": ">=17.0.0",
|
|
59
61
|
"react-router-dom": "^6.8.1"
|
|
60
62
|
},
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { usePageData } from '@rspress/core/runtime';
|
|
2
|
+
// @ts-ignore Cannot find module _rspress_playground_imports
|
|
2
3
|
import getImport from '_rspress_playground_imports';
|
|
3
4
|
import React, {
|
|
4
5
|
type HTMLAttributes,
|
|
@@ -10,7 +11,7 @@ import { Editor, Runner } from '../../dist/web/esm';
|
|
|
10
11
|
|
|
11
12
|
// inject by builder in cli/index.ts
|
|
12
13
|
declare global {
|
|
13
|
-
const __PLAYGROUND_DIRECTION__:
|
|
14
|
+
const __PLAYGROUND_DIRECTION__: Direction;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
type Direction = 'horizontal' | 'vertical';
|
|
@@ -45,7 +46,7 @@ function useDirection(props: PlaygroundProps): Direction {
|
|
|
45
46
|
// inject by config
|
|
46
47
|
try {
|
|
47
48
|
return __PLAYGROUND_DIRECTION__;
|
|
48
|
-
} catch (
|
|
49
|
+
} catch (_e) {
|
|
49
50
|
// ignore
|
|
50
51
|
}
|
|
51
52
|
|