@rspress/plugin-playground 1.40.1 → 1.40.3-cannary-20250126
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/301.js +14 -0
- package/dist/cli/cjs/index.js +479 -591
- package/dist/cli/esm/301.mjs +13 -0
- package/dist/cli/esm/index.d.ts +28 -24
- package/dist/cli/esm/index.mjs +471 -0
- package/dist/web/cjs/index.js +289 -355
- package/dist/web/esm/index.d.ts +45 -37
- package/dist/web/esm/index.mjs +269 -0
- package/package.json +8 -7
- package/dist/cli/cjs/index.js.map +0 -1
- package/dist/cli/esm/index.js +0 -577
- package/dist/cli/esm/index.js.map +0 -1
- package/dist/web/cjs/index.js.map +0 -1
- package/dist/web/esm/index.js +0 -354
- package/dist/web/esm/index.js.map +0 -1
package/dist/web/cjs/index.js
CHANGED
|
@@ -1,385 +1,319 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
));
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = function(module) {
|
|
5
|
+
var getter = module && module.__esModule ? function() {
|
|
6
|
+
return module['default'];
|
|
7
|
+
} : function() {
|
|
8
|
+
return module;
|
|
9
|
+
};
|
|
10
|
+
__webpack_require__.d(getter, {
|
|
11
|
+
a: getter
|
|
12
|
+
});
|
|
13
|
+
return getter;
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
(()=>{
|
|
17
|
+
__webpack_require__.d = function(exports1, definition) {
|
|
18
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: definition[key]
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
(()=>{
|
|
25
|
+
__webpack_require__.o = function(obj, prop) {
|
|
26
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
27
|
+
};
|
|
28
|
+
})();
|
|
29
|
+
(()=>{
|
|
30
|
+
__webpack_require__.r = function(exports1) {
|
|
31
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
32
|
+
value: 'Module'
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
35
|
+
value: true
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
var __webpack_exports__ = {};
|
|
40
|
+
__webpack_require__.r(__webpack_exports__);
|
|
41
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
42
|
+
Editor: ()=>Editor,
|
|
43
|
+
MonacoEditor: ()=>react_default(),
|
|
44
|
+
MonacoEditorLoader: ()=>react_namespaceObject.loader,
|
|
45
|
+
Runner: ()=>Runner
|
|
42
46
|
});
|
|
43
|
-
|
|
44
|
-
var
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
var
|
|
48
|
-
|
|
49
|
-
var import_react2 = require("react");
|
|
50
|
-
|
|
51
|
-
// src/web/constant.ts
|
|
52
|
-
var DEFAULT_MONACO_URL = "https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.43.0/min/vs";
|
|
53
|
-
|
|
54
|
-
// src/web/editor.tsx
|
|
55
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
47
|
+
const react_namespaceObject = require("@monaco-editor/react");
|
|
48
|
+
var react_default = /*#__PURE__*/ __webpack_require__.n(react_namespaceObject);
|
|
49
|
+
const runtime_namespaceObject = require("@rspress/core/runtime");
|
|
50
|
+
const external_react_namespaceObject = require("react");
|
|
51
|
+
var external_react_default = /*#__PURE__*/ __webpack_require__.n(external_react_namespaceObject);
|
|
52
|
+
const DEFAULT_MONACO_URL = 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.43.0/min/vs';
|
|
56
53
|
function initLoader() {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
} catch (e) {
|
|
68
|
-
}
|
|
69
|
-
import_react.loader.config(loaderConfig);
|
|
54
|
+
let loaderConfig = {
|
|
55
|
+
paths: {
|
|
56
|
+
vs: DEFAULT_MONACO_URL
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
try {
|
|
60
|
+
const keys = Object.keys(__PLAYGROUND_MONACO_LOADER__);
|
|
61
|
+
if (keys.length > 0) loaderConfig = __PLAYGROUND_MONACO_LOADER__;
|
|
62
|
+
} catch (e) {}
|
|
63
|
+
react_namespaceObject.loader.config(loaderConfig);
|
|
70
64
|
}
|
|
71
65
|
initLoader();
|
|
72
66
|
function getMonacoOptions() {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return {};
|
|
67
|
+
try {
|
|
68
|
+
return __PLAYGROUND_MONACO_OPTIONS__;
|
|
69
|
+
} catch (e) {}
|
|
70
|
+
return {};
|
|
78
71
|
}
|
|
79
72
|
function Editor(props) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
73
|
+
const { options, className = '', theme: themeProp, ...rest } = props || {};
|
|
74
|
+
const dark = (0, runtime_namespaceObject.useDark)();
|
|
75
|
+
const theme = (0, external_react_namespaceObject.useMemo)(()=>{
|
|
76
|
+
if (themeProp) return themeProp;
|
|
77
|
+
return dark ? 'vs-dark' : 'light';
|
|
78
|
+
}, [
|
|
79
|
+
themeProp,
|
|
80
|
+
dark
|
|
81
|
+
]);
|
|
82
|
+
return /*#__PURE__*/ external_react_default().createElement("div", {
|
|
83
|
+
className: `rspress-playground-editor ${className}`
|
|
84
|
+
}, /*#__PURE__*/ external_react_default().createElement(react_default(), {
|
|
85
|
+
...rest,
|
|
86
|
+
theme: theme,
|
|
87
|
+
options: {
|
|
88
|
+
minimap: {
|
|
89
|
+
enabled: true,
|
|
90
|
+
autohide: true
|
|
91
|
+
},
|
|
92
|
+
fontSize: 14,
|
|
93
|
+
lineNumbersMinChars: 7,
|
|
94
|
+
scrollBeyondLastLine: false,
|
|
95
|
+
automaticLayout: true,
|
|
96
|
+
wordBasedSuggestions: true,
|
|
97
|
+
quickSuggestions: true,
|
|
98
|
+
scrollbar: {
|
|
99
|
+
verticalScrollbarSize: 8,
|
|
100
|
+
horizontalScrollbarSize: 8
|
|
101
|
+
},
|
|
102
|
+
scrollPredominantAxis: false,
|
|
103
|
+
...getMonacoOptions(),
|
|
104
|
+
...options
|
|
105
|
+
}
|
|
106
|
+
}));
|
|
114
107
|
}
|
|
115
|
-
|
|
116
|
-
// src/web/runner.tsx
|
|
117
|
-
var import_react3 = __toESM(require("react"));
|
|
118
|
-
|
|
119
|
-
// src/web/ast.ts
|
|
120
108
|
function createVariableDeclaration(id, init) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
109
|
+
return {
|
|
110
|
+
type: 'VariableDeclaration',
|
|
111
|
+
declarations: [
|
|
112
|
+
{
|
|
113
|
+
type: 'VariableDeclarator',
|
|
114
|
+
id: 'string' == typeof id ? {
|
|
115
|
+
type: 'Identifier',
|
|
116
|
+
name: id
|
|
117
|
+
} : id,
|
|
118
|
+
init
|
|
119
|
+
}
|
|
120
|
+
],
|
|
121
|
+
kind: 'const'
|
|
122
|
+
};
|
|
135
123
|
}
|
|
136
124
|
function createIdentifier(name) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
125
|
+
return {
|
|
126
|
+
type: 'Identifier',
|
|
127
|
+
name
|
|
128
|
+
};
|
|
141
129
|
}
|
|
142
130
|
function createObjectProperty(key, value) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
131
|
+
return {
|
|
132
|
+
type: 'ObjectProperty',
|
|
133
|
+
key: createIdentifier(key),
|
|
134
|
+
computed: false,
|
|
135
|
+
shorthand: key === value,
|
|
136
|
+
value: createIdentifier(value)
|
|
137
|
+
};
|
|
150
138
|
}
|
|
151
139
|
function createObjectPattern(names) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
)
|
|
157
|
-
};
|
|
140
|
+
return {
|
|
141
|
+
type: 'ObjectPattern',
|
|
142
|
+
properties: names.map((name)=>Array.isArray(name) ? createObjectProperty(name[0], name[1]) : createObjectProperty(name, name))
|
|
143
|
+
};
|
|
158
144
|
}
|
|
159
145
|
function createGetImport(name, getDefault) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
146
|
+
return {
|
|
147
|
+
type: 'CallExpression',
|
|
148
|
+
callee: {
|
|
149
|
+
type: 'Identifier',
|
|
150
|
+
name: '__get_import'
|
|
151
|
+
},
|
|
152
|
+
arguments: [
|
|
153
|
+
{
|
|
154
|
+
type: 'StringLiteral',
|
|
155
|
+
value: name
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
type: 'BooleanLiteral',
|
|
159
|
+
value: Boolean(getDefault)
|
|
160
|
+
}
|
|
161
|
+
]
|
|
162
|
+
};
|
|
177
163
|
}
|
|
178
|
-
|
|
179
|
-
// src/web/babel.ts
|
|
180
164
|
async function loadUmdBabelModule() {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
const require2 = () => {
|
|
192
|
-
};
|
|
193
|
-
run(exports, module2, require2);
|
|
194
|
-
return exports;
|
|
165
|
+
const data = await fetch(__PLAYGROUND_BABEL_URL__);
|
|
166
|
+
const umdSourceCode = await data.text();
|
|
167
|
+
const run = new Function('exports', 'module', 'require', `with(exports, module, require) {${umdSourceCode}}`);
|
|
168
|
+
const exports1 = {};
|
|
169
|
+
const module = {
|
|
170
|
+
exports: exports1
|
|
171
|
+
};
|
|
172
|
+
const require1 = ()=>{};
|
|
173
|
+
run(exports1, module, require1);
|
|
174
|
+
return exports1;
|
|
195
175
|
}
|
|
196
|
-
|
|
176
|
+
let loadBabelPromise = null;
|
|
197
177
|
async function getBabel() {
|
|
198
|
-
|
|
199
|
-
return
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
} catch (e) {
|
|
210
|
-
loadBabelPromise = null;
|
|
211
|
-
throw e;
|
|
212
|
-
}
|
|
178
|
+
if (window.Babel) return window.Babel;
|
|
179
|
+
if (loadBabelPromise) return loadBabelPromise;
|
|
180
|
+
loadBabelPromise = loadUmdBabelModule();
|
|
181
|
+
try {
|
|
182
|
+
const Babel = await loadBabelPromise;
|
|
183
|
+
window.Babel = Babel;
|
|
184
|
+
return Babel;
|
|
185
|
+
} catch (e) {
|
|
186
|
+
loadBabelPromise = null;
|
|
187
|
+
throw e;
|
|
188
|
+
}
|
|
213
189
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
__publicField(this, "timer");
|
|
222
|
-
this.state = {
|
|
223
|
-
error: void 0,
|
|
224
|
-
comp: null
|
|
225
|
-
};
|
|
226
|
-
this.doCompile = this.doCompile.bind(this);
|
|
227
|
-
this.waitCompile = this.waitCompile.bind(this);
|
|
228
|
-
}
|
|
229
|
-
static getDerivedStateFromError(error) {
|
|
230
|
-
return {
|
|
231
|
-
error,
|
|
232
|
-
comp: null
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
waitCompile(targetCode) {
|
|
236
|
-
if (this.timer) {
|
|
237
|
-
clearTimeout(this.timer);
|
|
190
|
+
const DEBOUNCE_TIME = 800;
|
|
191
|
+
class Runner extends external_react_namespaceObject.Component {
|
|
192
|
+
static getDerivedStateFromError(error) {
|
|
193
|
+
return {
|
|
194
|
+
error,
|
|
195
|
+
comp: null
|
|
196
|
+
};
|
|
238
197
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
}
|
|
259
|
-
]);
|
|
260
|
-
}
|
|
261
|
-
const result = babel.transform(targetCode, {
|
|
262
|
-
sourceType: "module",
|
|
263
|
-
sourceMaps: "inline",
|
|
264
|
-
presets,
|
|
265
|
-
plugins: [
|
|
266
|
-
{
|
|
267
|
-
pre() {
|
|
268
|
-
this.hasReactImported = false;
|
|
269
|
-
},
|
|
270
|
-
visitor: {
|
|
271
|
-
ImportDeclaration(path) {
|
|
272
|
-
const pkg = path.node.source.value;
|
|
273
|
-
const code = [];
|
|
274
|
-
const specifiers = [];
|
|
275
|
-
for (const specifier of path.node.specifiers) {
|
|
276
|
-
if (specifier.local.name === "React") {
|
|
277
|
-
this.hasReactImported = true;
|
|
278
|
-
}
|
|
279
|
-
if (specifier.type === "ImportDefaultSpecifier") {
|
|
280
|
-
code.push(
|
|
281
|
-
createVariableDeclaration(
|
|
282
|
-
specifier.local.name,
|
|
283
|
-
createGetImport(pkg, true)
|
|
284
|
-
)
|
|
285
|
-
);
|
|
286
|
-
}
|
|
287
|
-
if (specifier.type === "ImportNamespaceSpecifier") {
|
|
288
|
-
code.push(
|
|
289
|
-
createVariableDeclaration(
|
|
290
|
-
specifier.local.name,
|
|
291
|
-
createGetImport(pkg)
|
|
292
|
-
)
|
|
293
|
-
);
|
|
294
|
-
}
|
|
295
|
-
if (specifier.type === "ImportSpecifier") {
|
|
296
|
-
if ("name" in specifier.imported && specifier.imported.name !== specifier.local.name) {
|
|
297
|
-
specifiers.push([
|
|
298
|
-
specifier.imported.name,
|
|
299
|
-
specifier.local.name
|
|
300
|
-
]);
|
|
301
|
-
} else {
|
|
302
|
-
specifiers.push(specifier.local.name);
|
|
198
|
+
waitCompile(targetCode) {
|
|
199
|
+
if (this.timer) clearTimeout(this.timer);
|
|
200
|
+
this.timer = setTimeout(()=>{
|
|
201
|
+
this.timer = null;
|
|
202
|
+
this.doCompile(targetCode);
|
|
203
|
+
}, DEBOUNCE_TIME);
|
|
204
|
+
}
|
|
205
|
+
async doCompile(targetCode) {
|
|
206
|
+
const { language, getImport } = this.props;
|
|
207
|
+
const babel = await getBabel();
|
|
208
|
+
try {
|
|
209
|
+
const presets = [
|
|
210
|
+
[
|
|
211
|
+
babel.availablePresets.react
|
|
212
|
+
],
|
|
213
|
+
[
|
|
214
|
+
babel.availablePresets.env,
|
|
215
|
+
{
|
|
216
|
+
modules: 'commonjs'
|
|
303
217
|
}
|
|
304
|
-
|
|
218
|
+
]
|
|
219
|
+
];
|
|
220
|
+
if ('tsx' === language || 'ts' === language) presets.unshift([
|
|
221
|
+
babel.availablePresets.typescript,
|
|
222
|
+
{
|
|
223
|
+
allExtensions: true,
|
|
224
|
+
isTSX: 'tsx' === language
|
|
305
225
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
226
|
+
]);
|
|
227
|
+
const result = babel.transform(targetCode, {
|
|
228
|
+
sourceType: 'module',
|
|
229
|
+
sourceMaps: 'inline',
|
|
230
|
+
presets,
|
|
231
|
+
plugins: [
|
|
232
|
+
{
|
|
233
|
+
pre () {
|
|
234
|
+
this.hasReactImported = false;
|
|
235
|
+
},
|
|
236
|
+
visitor: {
|
|
237
|
+
ImportDeclaration (path) {
|
|
238
|
+
const pkg = path.node.source.value;
|
|
239
|
+
const code = [];
|
|
240
|
+
const specifiers = [];
|
|
241
|
+
for (const specifier of path.node.specifiers){
|
|
242
|
+
if ('React' === specifier.local.name) this.hasReactImported = true;
|
|
243
|
+
if ('ImportDefaultSpecifier' === specifier.type) code.push(createVariableDeclaration(specifier.local.name, createGetImport(pkg, true)));
|
|
244
|
+
if ('ImportNamespaceSpecifier' === specifier.type) code.push(createVariableDeclaration(specifier.local.name, createGetImport(pkg)));
|
|
245
|
+
if ('ImportSpecifier' === specifier.type) {
|
|
246
|
+
if ('name' in specifier.imported && specifier.imported.name !== specifier.local.name) specifiers.push([
|
|
247
|
+
specifier.imported.name,
|
|
248
|
+
specifier.local.name
|
|
249
|
+
]);
|
|
250
|
+
else specifiers.push(specifier.local.name);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (specifiers.length > 0) code.push(createVariableDeclaration(createObjectPattern(specifiers), createGetImport(pkg)));
|
|
254
|
+
path.replaceWithMultiple(code);
|
|
255
|
+
}
|
|
256
|
+
},
|
|
257
|
+
post (file) {
|
|
258
|
+
if (!this.hasReactImported) file.ast.program.body.unshift(createVariableDeclaration('React', createGetImport('react', true)));
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
]
|
|
262
|
+
});
|
|
263
|
+
if (targetCode !== this.props.code || !result || !result.code) return;
|
|
264
|
+
const runExports = {};
|
|
265
|
+
const func = new Function('__get_import', 'exports', result.code);
|
|
266
|
+
func(getImport, runExports);
|
|
267
|
+
if (runExports.default) {
|
|
268
|
+
this.setState({
|
|
269
|
+
error: void 0,
|
|
270
|
+
comp: /*#__PURE__*/ external_react_default().createElement(runExports.default)
|
|
271
|
+
});
|
|
272
|
+
return;
|
|
326
273
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
error: new Error("No default export")
|
|
345
|
-
});
|
|
346
|
-
} catch (e) {
|
|
347
|
-
if (targetCode !== this.props.code) {
|
|
348
|
-
return;
|
|
349
|
-
}
|
|
350
|
-
console.error(e);
|
|
351
|
-
this.setState({
|
|
352
|
-
error: e
|
|
353
|
-
});
|
|
274
|
+
this.setState({
|
|
275
|
+
error: new Error('No default export')
|
|
276
|
+
});
|
|
277
|
+
} catch (e) {
|
|
278
|
+
if (targetCode !== this.props.code) return;
|
|
279
|
+
console.error(e);
|
|
280
|
+
this.setState({
|
|
281
|
+
error: e
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
componentDidCatch(error, errorInfo) {
|
|
286
|
+
console.error(error);
|
|
287
|
+
console.error(errorInfo);
|
|
288
|
+
}
|
|
289
|
+
componentDidMount() {
|
|
290
|
+
this.doCompile(this.props.code);
|
|
354
291
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
console.error(error);
|
|
358
|
-
console.error(errorInfo);
|
|
359
|
-
}
|
|
360
|
-
componentDidMount() {
|
|
361
|
-
this.doCompile(this.props.code);
|
|
362
|
-
}
|
|
363
|
-
componentDidUpdate(prevProps) {
|
|
364
|
-
if (prevProps.code !== this.props.code) {
|
|
365
|
-
this.waitCompile(this.props.code);
|
|
292
|
+
componentDidUpdate(prevProps) {
|
|
293
|
+
if (prevProps.code !== this.props.code) this.waitCompile(this.props.code);
|
|
366
294
|
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
295
|
+
render() {
|
|
296
|
+
const { className = '', code, language, getImport, ...rest } = this.props;
|
|
297
|
+
const { error, comp } = this.state;
|
|
298
|
+
return /*#__PURE__*/ external_react_default().createElement("div", {
|
|
299
|
+
className: `rspress-playground-runner ${className}`,
|
|
300
|
+
...rest
|
|
301
|
+
}, comp, error && /*#__PURE__*/ external_react_default().createElement("pre", {
|
|
302
|
+
className: "rspress-playground-error"
|
|
303
|
+
}, error.message));
|
|
304
|
+
}
|
|
305
|
+
constructor(props){
|
|
306
|
+
super(props);
|
|
307
|
+
this.state = {
|
|
308
|
+
error: void 0,
|
|
309
|
+
comp: null
|
|
310
|
+
};
|
|
311
|
+
this.doCompile = this.doCompile.bind(this);
|
|
312
|
+
this.waitCompile = this.waitCompile.bind(this);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
var __webpack_export_target__ = exports;
|
|
316
|
+
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
317
|
+
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
|
|
318
|
+
value: true
|
|
383
319
|
});
|
|
384
|
-
|
|
385
|
-
//# sourceMappingURL=index.js.map
|