@rspress/plugin-preview 2.0.0-beta.0 → 2.0.0-beta.2
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/index.js +487 -561
- package/dist/utils.js +1 -47
- package/package.json +15 -8
- package/static/global-components/Container.tsx +1 -1
package/dist/index.js
CHANGED
@@ -1,128 +1,67 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_net_0373943e__ from "node:net";
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
|
3
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ from "@rsbuild/core";
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_babel_2a5a8b08__ from "@rsbuild/plugin-babel";
|
5
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_react_7b149ee4__ from "@rsbuild/plugin-react";
|
6
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_solid_0a0a2645__ from "@rsbuild/plugin-solid";
|
7
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__ from "@rspress/shared";
|
8
|
+
import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash";
|
9
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs";
|
10
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__ from "@rspress/shared/node-utils";
|
11
|
+
const staticPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(__dirname, '..', 'static');
|
12
|
+
const demoBlockComponentPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(staticPath, 'global-components', 'DemoBlock.tsx');
|
13
|
+
const virtualDir = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(process.cwd(), 'node_modules', __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.RSPRESS_TEMP_DIR, 'virtual-demo');
|
14
|
+
const toValidVarName = (str)=>{
|
15
|
+
if (/^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(str)) return str;
|
16
|
+
return str.replace(/[^0-9a-zA-Z_$]/g, '_').replace(/^([0-9])/, '_$1');
|
13
17
|
};
|
14
|
-
|
15
|
-
|
16
|
-
var cachedModule = __webpack_module_cache__[moduleId];
|
17
|
-
if (void 0 !== cachedModule) return cachedModule.exports;
|
18
|
-
var module = __webpack_module_cache__[moduleId] = {
|
19
|
-
exports: {}
|
20
|
-
};
|
21
|
-
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
22
|
-
return module.exports;
|
23
|
-
}
|
24
|
-
(()=>{
|
25
|
-
__webpack_require__.n = (module)=>{
|
26
|
-
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
27
|
-
__webpack_require__.d(getter, {
|
28
|
-
a: getter
|
29
|
-
});
|
30
|
-
return getter;
|
31
|
-
};
|
32
|
-
})();
|
33
|
-
(()=>{
|
34
|
-
__webpack_require__.d = (exports1, definition)=>{
|
35
|
-
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
36
|
-
enumerable: true,
|
37
|
-
get: definition[key]
|
38
|
-
});
|
39
|
-
};
|
40
|
-
})();
|
41
|
-
(()=>{
|
42
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
43
|
-
})();
|
44
|
-
(()=>{
|
45
|
-
__webpack_require__.r = (exports1)=>{
|
46
|
-
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
47
|
-
value: 'Module'
|
48
|
-
});
|
49
|
-
Object.defineProperty(exports1, '__esModule', {
|
50
|
-
value: true
|
51
|
-
});
|
52
|
-
};
|
53
|
-
})();
|
54
|
-
var __webpack_exports__ = {};
|
55
|
-
(()=>{
|
56
|
-
__webpack_require__.r(__webpack_exports__);
|
57
|
-
__webpack_require__.d(__webpack_exports__, {
|
58
|
-
pluginPreview: ()=>pluginPreview
|
59
|
-
});
|
60
|
-
const external_node_net_namespaceObject = require("node:net");
|
61
|
-
var external_node_net_default = /*#__PURE__*/ __webpack_require__.n(external_node_net_namespaceObject);
|
62
|
-
const external_node_path_namespaceObject = require("node:path");
|
63
|
-
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
64
|
-
const core_namespaceObject = require("@rsbuild/core");
|
65
|
-
const plugin_babel_namespaceObject = require("@rsbuild/plugin-babel");
|
66
|
-
const plugin_react_namespaceObject = require("@rsbuild/plugin-react");
|
67
|
-
const plugin_solid_namespaceObject = require("@rsbuild/plugin-solid");
|
68
|
-
const shared_namespaceObject = require("@rspress/shared");
|
69
|
-
const external_lodash_namespaceObject = require("lodash");
|
70
|
-
const staticPath = external_node_path_default().join(__dirname, '..', 'static');
|
71
|
-
const demoBlockComponentPath = external_node_path_default().join(staticPath, 'global-components', 'DemoBlock.tsx');
|
72
|
-
const virtualDir = external_node_path_default().join(process.cwd(), 'node_modules', shared_namespaceObject.RSPRESS_TEMP_DIR, 'virtual-demo');
|
73
|
-
const external_node_fs_namespaceObject = require("node:fs");
|
74
|
-
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
75
|
-
const toValidVarName = (str)=>{
|
76
|
-
if (/^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(str)) return str;
|
77
|
-
return str.replace(/[^0-9a-zA-Z_$]/g, '_').replace(/^([0-9])/, '_$1');
|
78
|
-
};
|
79
|
-
const generateId = (pageName, index)=>`_${toValidVarName(pageName)}_${index}`;
|
80
|
-
const injectDemoBlockImport = (str, path)=>`
|
18
|
+
const generateId = (pageName, index)=>`_${toValidVarName(pageName)}_${index}`;
|
19
|
+
const injectDemoBlockImport = (str, path)=>`
|
81
20
|
import DemoBlock from ${JSON.stringify(path)};
|
82
21
|
${str}
|
83
22
|
`;
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
23
|
+
const getLangFileExt = (lang)=>{
|
24
|
+
switch(lang){
|
25
|
+
case 'jsx':
|
26
|
+
case 'tsx':
|
27
|
+
return 'tsx';
|
28
|
+
case 'json':
|
29
|
+
return 'tsx';
|
30
|
+
default:
|
31
|
+
return lang;
|
32
|
+
}
|
33
|
+
};
|
34
|
+
function generateEntry(demos, framework, position, customEntry) {
|
35
|
+
const sourceEntry = {};
|
36
|
+
const entryCssPath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(staticPath, 'global-styles', 'entry.css');
|
37
|
+
if ('follow' === position) Object.values(demos).forEach((routes)=>{
|
38
|
+
routes.forEach((route)=>{
|
39
|
+
const { id, path: demoPath } = route;
|
40
|
+
const entry = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(virtualDir, `${id}.entry.tsx`);
|
41
|
+
const solidEntry = `
|
103
42
|
import { render } from 'solid-js/web';
|
104
43
|
import ${JSON.stringify(entryCssPath)};
|
105
44
|
import Demo from ${JSON.stringify(demoPath)};
|
106
45
|
render(() => <Demo />, document.getElementById('root'));
|
107
46
|
`;
|
108
|
-
|
47
|
+
const reactEntry = `
|
109
48
|
import { createRoot } from 'react-dom/client';
|
110
49
|
import ${JSON.stringify(entryCssPath)};
|
111
50
|
import Demo from ${JSON.stringify(demoPath)};
|
112
51
|
const container = document.getElementById('root');
|
113
52
|
createRoot(container).render(<Demo />);
|
114
53
|
`;
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
});
|
54
|
+
const entryContent = customEntry ? customEntry({
|
55
|
+
entryCssPath,
|
56
|
+
demoPath
|
57
|
+
}) : 'react' === framework ? reactEntry : solidEntry;
|
58
|
+
(0, __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.writeFileSync)(entry, entryContent);
|
59
|
+
sourceEntry[id] = entry;
|
122
60
|
});
|
123
|
-
|
124
|
-
|
125
|
-
|
61
|
+
});
|
62
|
+
else Object.entries(demos).forEach(([key, routes])=>{
|
63
|
+
if (0 === routes.length) return;
|
64
|
+
const reactContent = `
|
126
65
|
import { createRoot } from 'react-dom/client';
|
127
66
|
import ${JSON.stringify(entryCssPath)};
|
128
67
|
${routes.map((demo, index)=>`import Demo_${index} from ${JSON.stringify(demo.path)}`).join('\n')}
|
@@ -137,7 +76,7 @@ var __webpack_exports__ = {};
|
|
137
76
|
const container = document.getElementById('root');
|
138
77
|
createRoot(container).render(<App />);
|
139
78
|
`;
|
140
|
-
|
79
|
+
const solidContent = `
|
141
80
|
import { render } from 'solid-js/web';
|
142
81
|
import ${JSON.stringify(entryCssPath)};
|
143
82
|
${routes.map((demo, index)=>`import Demo_${index} from ${JSON.stringify(demo.path)}`).join('\n')}
|
@@ -151,491 +90,478 @@ var __webpack_exports__ = {};
|
|
151
90
|
}
|
152
91
|
render(() => <App /> , document.getElementById('root'));
|
153
92
|
`;
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
93
|
+
const renderContent = 'solid' === framework ? solidContent : reactContent;
|
94
|
+
const id = `_${toValidVarName(key)}`;
|
95
|
+
const entry = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(virtualDir, `${id}.entry.tsx`);
|
96
|
+
(0, __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.writeFileSync)(entry, renderContent);
|
97
|
+
sourceEntry[id] = entry;
|
98
|
+
});
|
99
|
+
return sourceEntry;
|
100
|
+
}
|
101
|
+
const convert = function(test) {
|
102
|
+
if (null == test) return ok;
|
103
|
+
if ('function' == typeof test) return castFactory(test);
|
104
|
+
if ('object' == typeof test) return Array.isArray(test) ? anyFactory(test) : propsFactory(test);
|
105
|
+
if ('string' == typeof test) return typeFactory(test);
|
106
|
+
throw new Error('Expected function, string, or object as test');
|
107
|
+
};
|
108
|
+
function anyFactory(tests) {
|
109
|
+
const checks = [];
|
110
|
+
let index = -1;
|
111
|
+
while(++index < tests.length)checks[index] = convert(tests[index]);
|
112
|
+
return castFactory(any);
|
113
|
+
function any(...parameters) {
|
172
114
|
let index = -1;
|
173
|
-
while(++index <
|
174
|
-
return
|
175
|
-
function any(...parameters) {
|
176
|
-
let index = -1;
|
177
|
-
while(++index < checks.length)if (checks[index].apply(this, parameters)) return true;
|
178
|
-
return false;
|
179
|
-
}
|
180
|
-
}
|
181
|
-
function propsFactory(check) {
|
182
|
-
const checkAsRecord = check;
|
183
|
-
return castFactory(all);
|
184
|
-
function all(node) {
|
185
|
-
const nodeAsRecord = node;
|
186
|
-
let key;
|
187
|
-
for(key in check)if (nodeAsRecord[key] !== checkAsRecord[key]) return false;
|
188
|
-
return true;
|
189
|
-
}
|
190
|
-
}
|
191
|
-
function typeFactory(check) {
|
192
|
-
return castFactory(type);
|
193
|
-
function type(node) {
|
194
|
-
return node && node.type === check;
|
195
|
-
}
|
196
|
-
}
|
197
|
-
function castFactory(testFunction) {
|
198
|
-
return check;
|
199
|
-
function check(value, index, parent) {
|
200
|
-
return Boolean(looksLikeANode(value) && testFunction.call(this, value, 'number' == typeof index ? index : void 0, parent || void 0));
|
201
|
-
}
|
115
|
+
while(++index < checks.length)if (checks[index].apply(this, parameters)) return true;
|
116
|
+
return false;
|
202
117
|
}
|
203
|
-
|
118
|
+
}
|
119
|
+
function propsFactory(check) {
|
120
|
+
const checkAsRecord = check;
|
121
|
+
return castFactory(all);
|
122
|
+
function all(node) {
|
123
|
+
const nodeAsRecord = node;
|
124
|
+
let key;
|
125
|
+
for(key in check)if (nodeAsRecord[key] !== checkAsRecord[key]) return false;
|
204
126
|
return true;
|
205
127
|
}
|
206
|
-
|
207
|
-
|
128
|
+
}
|
129
|
+
function typeFactory(check) {
|
130
|
+
return castFactory(type);
|
131
|
+
function type(node) {
|
132
|
+
return node && node.type === check;
|
208
133
|
}
|
209
|
-
|
210
|
-
|
134
|
+
}
|
135
|
+
function castFactory(testFunction) {
|
136
|
+
return check;
|
137
|
+
function check(value, index, parent) {
|
138
|
+
return Boolean(looksLikeANode(value) && testFunction.call(this, value, 'number' == typeof index ? index : void 0, parent || void 0));
|
211
139
|
}
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
140
|
+
}
|
141
|
+
function ok() {
|
142
|
+
return true;
|
143
|
+
}
|
144
|
+
function looksLikeANode(value) {
|
145
|
+
return null !== value && 'object' == typeof value && 'type' in value;
|
146
|
+
}
|
147
|
+
function color(d) {
|
148
|
+
return '\u001B[33m' + d + '\u001B[39m';
|
149
|
+
}
|
150
|
+
const empty = [];
|
151
|
+
const CONTINUE = true;
|
152
|
+
const EXIT = false;
|
153
|
+
const SKIP = 'skip';
|
154
|
+
function visitParents(tree, test, visitor, reverse) {
|
155
|
+
let check;
|
156
|
+
if ('function' == typeof test && 'function' != typeof visitor) {
|
157
|
+
reverse = visitor;
|
158
|
+
visitor = test;
|
159
|
+
} else check = test;
|
160
|
+
const is = convert(check);
|
161
|
+
const step = reverse ? -1 : 1;
|
162
|
+
factory(tree, void 0, [])();
|
163
|
+
function factory(node, index, parents) {
|
164
|
+
const value = node && 'object' == typeof node ? node : {};
|
165
|
+
if ('string' == typeof value.type) {
|
166
|
+
const name = 'string' == typeof value.tagName ? value.tagName : 'string' == typeof value.name ? value.name : void 0;
|
167
|
+
Object.defineProperty(visit, 'name', {
|
168
|
+
value: 'node (' + color(node.type + (name ? '<' + name + '>' : '')) + ')'
|
169
|
+
});
|
170
|
+
}
|
171
|
+
return visit;
|
172
|
+
function visit() {
|
173
|
+
let result = empty;
|
174
|
+
let subresult;
|
175
|
+
let offset;
|
176
|
+
let grandparents;
|
177
|
+
if (!test || is(node, index, parents[parents.length - 1] || void 0)) {
|
178
|
+
result = toResult(visitor(node, parents));
|
179
|
+
if (result[0] === EXIT) return result;
|
232
180
|
}
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
if ('children' in node && node.children) {
|
244
|
-
const nodeAsParent = node;
|
245
|
-
if (nodeAsParent.children && result[0] !== SKIP) {
|
246
|
-
offset = (reverse ? nodeAsParent.children.length : -1) + step;
|
247
|
-
grandparents = parents.concat(nodeAsParent);
|
248
|
-
while(offset > -1 && offset < nodeAsParent.children.length){
|
249
|
-
const child = nodeAsParent.children[offset];
|
250
|
-
subresult = factory(child, offset, grandparents)();
|
251
|
-
if (subresult[0] === EXIT) return subresult;
|
252
|
-
offset = 'number' == typeof subresult[1] ? subresult[1] : offset + step;
|
253
|
-
}
|
181
|
+
if ('children' in node && node.children) {
|
182
|
+
const nodeAsParent = node;
|
183
|
+
if (nodeAsParent.children && result[0] !== SKIP) {
|
184
|
+
offset = (reverse ? nodeAsParent.children.length : -1) + step;
|
185
|
+
grandparents = parents.concat(nodeAsParent);
|
186
|
+
while(offset > -1 && offset < nodeAsParent.children.length){
|
187
|
+
const child = nodeAsParent.children[offset];
|
188
|
+
subresult = factory(child, offset, grandparents)();
|
189
|
+
if (subresult[0] === EXIT) return subresult;
|
190
|
+
offset = 'number' == typeof subresult[1] ? subresult[1] : offset + step;
|
254
191
|
}
|
255
192
|
}
|
256
|
-
return result;
|
257
193
|
}
|
194
|
+
return result;
|
258
195
|
}
|
259
196
|
}
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
197
|
+
}
|
198
|
+
function toResult(value) {
|
199
|
+
if (Array.isArray(value)) return value;
|
200
|
+
if ('number' == typeof value) return [
|
201
|
+
CONTINUE,
|
202
|
+
value
|
203
|
+
];
|
204
|
+
return null == value ? empty : [
|
205
|
+
value
|
206
|
+
];
|
207
|
+
}
|
208
|
+
function lib_visit(tree, testOrVisitor, visitorOrReverse, maybeReverse) {
|
209
|
+
let reverse;
|
210
|
+
let test;
|
211
|
+
let visitor;
|
212
|
+
if ('function' == typeof testOrVisitor && 'function' != typeof visitorOrReverse) {
|
213
|
+
test = void 0;
|
214
|
+
visitor = testOrVisitor;
|
215
|
+
reverse = visitorOrReverse;
|
216
|
+
} else {
|
217
|
+
test = testOrVisitor;
|
218
|
+
visitor = visitorOrReverse;
|
219
|
+
reverse = maybeReverse;
|
269
220
|
}
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
test = void 0;
|
276
|
-
visitor = testOrVisitor;
|
277
|
-
reverse = visitorOrReverse;
|
278
|
-
} else {
|
279
|
-
test = testOrVisitor;
|
280
|
-
visitor = visitorOrReverse;
|
281
|
-
reverse = maybeReverse;
|
282
|
-
}
|
283
|
-
visitParents(tree, test, overload, reverse);
|
284
|
-
function overload(node, parents) {
|
285
|
-
const parent = parents[parents.length - 1];
|
286
|
-
const index = parent ? parent.children.indexOf(node) : void 0;
|
287
|
-
return visitor(node, index, parent);
|
288
|
-
}
|
221
|
+
visitParents(tree, test, overload, reverse);
|
222
|
+
function overload(node, parents) {
|
223
|
+
const parent = parents[parents.length - 1];
|
224
|
+
const index = parent ? parent.children.indexOf(node) : void 0;
|
225
|
+
return visitor(node, index, parent);
|
289
226
|
}
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
227
|
+
}
|
228
|
+
const getASTNodeImport = (name, from)=>({
|
229
|
+
type: 'mdxjsEsm',
|
230
|
+
value: `import ${name} from ${JSON.stringify(from)}`,
|
231
|
+
data: {
|
232
|
+
estree: {
|
233
|
+
type: 'Program',
|
234
|
+
sourceType: 'module',
|
235
|
+
body: [
|
236
|
+
{
|
237
|
+
type: 'ImportDeclaration',
|
238
|
+
specifiers: [
|
239
|
+
{
|
240
|
+
type: 'ImportDefaultSpecifier',
|
241
|
+
local: {
|
242
|
+
type: 'Identifier',
|
243
|
+
name
|
307
244
|
}
|
308
|
-
],
|
309
|
-
source: {
|
310
|
-
type: 'Literal',
|
311
|
-
value: from,
|
312
|
-
raw: `${JSON.stringify(from)}`
|
313
245
|
}
|
246
|
+
],
|
247
|
+
source: {
|
248
|
+
type: 'Literal',
|
249
|
+
value: from,
|
250
|
+
raw: `${JSON.stringify(from)}`
|
314
251
|
}
|
315
|
-
|
316
|
-
|
252
|
+
}
|
253
|
+
]
|
317
254
|
}
|
318
|
-
}
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
255
|
+
}
|
256
|
+
});
|
257
|
+
const getExternalDemoContent = (tempVar)=>({
|
258
|
+
type: 'mdxJsxFlowElement',
|
259
|
+
name: '',
|
260
|
+
attributes: [],
|
261
|
+
children: [
|
262
|
+
{
|
263
|
+
type: 'mdxJsxFlowElement',
|
264
|
+
name: 'pre',
|
265
|
+
attributes: [],
|
266
|
+
children: [
|
267
|
+
{
|
268
|
+
type: 'mdxJsxFlowElement',
|
269
|
+
name: 'code',
|
270
|
+
attributes: [
|
271
|
+
{
|
272
|
+
type: 'mdxJsxAttribute',
|
273
|
+
name: 'className',
|
274
|
+
value: 'language-tsx'
|
275
|
+
},
|
276
|
+
{
|
277
|
+
type: 'mdxJsxAttribute',
|
278
|
+
name: 'children',
|
279
|
+
value: {
|
280
|
+
type: 'mdxJsxExpressionAttribute',
|
281
|
+
value: tempVar,
|
282
|
+
data: {
|
283
|
+
estree: {
|
284
|
+
type: 'Program',
|
285
|
+
body: [
|
286
|
+
{
|
287
|
+
type: 'ExpressionStatement',
|
288
|
+
expression: {
|
289
|
+
type: 'Identifier',
|
290
|
+
name: tempVar
|
354
291
|
}
|
355
|
-
|
356
|
-
|
292
|
+
}
|
293
|
+
]
|
357
294
|
}
|
358
295
|
}
|
359
296
|
}
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
297
|
+
}
|
298
|
+
]
|
299
|
+
}
|
300
|
+
]
|
301
|
+
}
|
302
|
+
]
|
303
|
+
});
|
304
|
+
const remarkPlugin_demos = {};
|
305
|
+
const remarkCodeToDemo = function({ getRouteMeta, previewMode, defaultRenderMode, position, previewLanguages, previewCodeTransform }) {
|
306
|
+
const routeMeta = getRouteMeta();
|
307
|
+
__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].mkdirSync(virtualDir, {
|
308
|
+
recursive: true
|
309
|
+
});
|
310
|
+
const data = this.data();
|
311
|
+
return (tree, vfile)=>{
|
312
|
+
const demoMdx = [];
|
313
|
+
const route = routeMeta.find((meta)=>(0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.normalizePosixPath)(meta.absolutePath) === (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.normalizePosixPath)(vfile.path || vfile.history[0]));
|
314
|
+
if (!route) return;
|
315
|
+
const { pageName } = route;
|
316
|
+
remarkPlugin_demos[pageName] = [];
|
317
|
+
let title = pageName;
|
318
|
+
let index = 1;
|
319
|
+
let externalDemoIndex = 0;
|
320
|
+
function constructDemoNode(demoId, demoPath, currentNode, isMobileMode, externalDemoIndex) {
|
321
|
+
if (isMobileMode) {
|
322
|
+
const relativePathReg = new RegExp(/^\.\.?\/.*$/);
|
323
|
+
remarkPlugin_demos[pageName].push({
|
324
|
+
title,
|
325
|
+
id: demoId,
|
326
|
+
path: relativePathReg.test(demoPath) ? (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.resolve)(vfile.dirname || (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.dirname)(vfile.path), demoPath) : demoPath
|
327
|
+
});
|
328
|
+
} else demoMdx.push(getASTNodeImport(`Demo${demoId}`, demoPath));
|
329
|
+
const tempVar = `externalDemoContent${externalDemoIndex}`;
|
330
|
+
if (void 0 !== externalDemoIndex) demoMdx.push(getASTNodeImport(tempVar, `!!${demoPath}?raw`));
|
331
|
+
if (isMobileMode && 'fixed' === position) void 0 !== externalDemoIndex && Object.assign(currentNode, getExternalDemoContent(tempVar));
|
332
|
+
else Object.assign(currentNode, {
|
333
|
+
type: 'mdxJsxFlowElement',
|
334
|
+
name: 'Container',
|
335
|
+
attributes: [
|
336
|
+
{
|
337
|
+
type: 'mdxJsxAttribute',
|
338
|
+
name: 'isMobile',
|
339
|
+
value: isMobileMode
|
340
|
+
},
|
341
|
+
{
|
342
|
+
type: 'mdxJsxAttribute',
|
343
|
+
name: 'demoId',
|
344
|
+
value: demoId
|
345
|
+
}
|
346
|
+
],
|
347
|
+
children: [
|
348
|
+
void 0 === externalDemoIndex ? {
|
349
|
+
...currentNode,
|
350
|
+
hasVisited: true
|
351
|
+
} : getExternalDemoContent(tempVar),
|
352
|
+
isMobileMode ? {
|
353
|
+
type: 'mdxJsxFlowElement',
|
354
|
+
name: null
|
355
|
+
} : {
|
356
|
+
type: 'mdxJsxFlowElement',
|
357
|
+
name: `Demo${demoId}`
|
358
|
+
}
|
359
|
+
]
|
360
|
+
});
|
361
|
+
}
|
362
|
+
lib_visit(tree, 'heading', (node)=>{
|
363
|
+
if (1 === node.depth) {
|
364
|
+
const firstChild = node.children[0];
|
365
|
+
title = firstChild && 'value' in firstChild && firstChild.value || title;
|
366
|
+
}
|
365
367
|
});
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
368
|
+
lib_visit(tree, 'mdxJsxFlowElement', (node)=>{
|
369
|
+
if ('code' === node.name) {
|
370
|
+
const src = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.getNodeAttribute)(node, 'src');
|
371
|
+
if ('string' != typeof src) return;
|
372
|
+
const currentMode = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.getNodeAttribute)(node, 'previewMode') ?? previewMode;
|
373
|
+
const isMobileAttr = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.getNodeAttribute)(node, 'isMobile');
|
374
|
+
let isMobileMode = false;
|
375
|
+
isMobileMode = void 0 === isMobileAttr ? 'iframe' === currentMode : null === isMobileAttr ? true : 'object' == typeof isMobileAttr ? 'false' !== isMobileAttr.value : 'false' !== isMobileAttr;
|
376
|
+
const id = generateId(pageName, index++);
|
377
|
+
constructDemoNode(id, src, node, isMobileMode, externalDemoIndex++);
|
378
|
+
}
|
371
379
|
});
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
if (isMobileMode) {
|
384
|
-
const relativePathReg = new RegExp(/^\.\.?\/.*$/);
|
385
|
-
remarkPlugin_demos[pageName].push({
|
386
|
-
title,
|
387
|
-
id: demoId,
|
388
|
-
path: relativePathReg.test(demoPath) ? (0, external_node_path_namespaceObject.resolve)(vfile.dirname || (0, external_node_path_namespaceObject.dirname)(vfile.path), demoPath) : demoPath
|
389
|
-
});
|
390
|
-
} else demoMdx.push(getASTNodeImport(`Demo${demoId}`, demoPath));
|
391
|
-
const tempVar = `externalDemoContent${externalDemoIndex}`;
|
392
|
-
if (void 0 !== externalDemoIndex) demoMdx.push(getASTNodeImport(tempVar, `!!${demoPath}?raw`));
|
393
|
-
if (isMobileMode && 'fixed' === position) void 0 !== externalDemoIndex && Object.assign(currentNode, getExternalDemoContent(tempVar));
|
394
|
-
else Object.assign(currentNode, {
|
395
|
-
type: 'mdxJsxFlowElement',
|
396
|
-
name: 'Container',
|
397
|
-
attributes: [
|
398
|
-
{
|
399
|
-
type: 'mdxJsxAttribute',
|
400
|
-
name: 'isMobile',
|
401
|
-
value: isMobileMode
|
402
|
-
},
|
403
|
-
{
|
404
|
-
type: 'mdxJsxAttribute',
|
405
|
-
name: 'demoId',
|
406
|
-
value: demoId
|
407
|
-
}
|
408
|
-
],
|
409
|
-
children: [
|
410
|
-
void 0 === externalDemoIndex ? {
|
411
|
-
...currentNode,
|
412
|
-
hasVisited: true
|
413
|
-
} : getExternalDemoContent(tempVar),
|
414
|
-
isMobileMode ? {
|
415
|
-
type: 'mdxJsxFlowElement',
|
416
|
-
name: null
|
417
|
-
} : {
|
418
|
-
type: 'mdxJsxFlowElement',
|
419
|
-
name: `Demo${demoId}`
|
420
|
-
}
|
421
|
-
]
|
380
|
+
lib_visit(tree, 'code', (node)=>{
|
381
|
+
if ('hasVisited' in node) return;
|
382
|
+
if (node.lang && previewLanguages.includes(node.lang)) {
|
383
|
+
if (node.meta?.includes('pure') || !node.meta?.includes('preview') && 'pure' === defaultRenderMode) return;
|
384
|
+
const isJsx = 'jsx' === node.lang || 'tsx' === node.lang;
|
385
|
+
const value = isJsx ? injectDemoBlockImport(previewCodeTransform({
|
386
|
+
language: node.lang,
|
387
|
+
code: node.value
|
388
|
+
}), demoBlockComponentPath) : previewCodeTransform({
|
389
|
+
language: node.lang,
|
390
|
+
code: node.value
|
422
391
|
});
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
lib_visit(tree, 'mdxJsxFlowElement', (node)=>{
|
431
|
-
if ('code' === node.name) {
|
432
|
-
const src = (0, node_utils_namespaceObject.getNodeAttribute)(node, 'src');
|
433
|
-
if ('string' != typeof src) return;
|
434
|
-
const currentMode = (0, node_utils_namespaceObject.getNodeAttribute)(node, 'previewMode') ?? previewMode;
|
435
|
-
const isMobileAttr = (0, node_utils_namespaceObject.getNodeAttribute)(node, 'isMobile');
|
436
|
-
let isMobileMode = false;
|
437
|
-
isMobileMode = void 0 === isMobileAttr ? 'iframe' === currentMode : null === isMobileAttr ? true : 'object' == typeof isMobileAttr ? 'false' !== isMobileAttr.value : 'false' !== isMobileAttr;
|
438
|
-
const id = generateId(pageName, index++);
|
439
|
-
constructDemoNode(id, src, node, isMobileMode, externalDemoIndex++);
|
392
|
+
const isMobileMode = node.meta?.includes('mobile') || node.meta?.includes('iframe') || !node.meta?.includes('web') && !node.meta?.includes('internal') && 'iframe' === previewMode;
|
393
|
+
const id = generateId(pageName, index++);
|
394
|
+
const virtualModulePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(virtualDir, `${id}.${getLangFileExt(node.lang)}`);
|
395
|
+
constructDemoNode(id, virtualModulePath, node, isMobileMode);
|
396
|
+
if (__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].existsSync(virtualModulePath)) {
|
397
|
+
const content = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].readFileSync(virtualModulePath, 'utf-8');
|
398
|
+
if (content === value) return;
|
440
399
|
}
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
if ((null == (_node_meta = node.meta) ? void 0 : _node_meta.includes('pure')) || !(null == (_node_meta1 = node.meta) ? void 0 : _node_meta1.includes('preview')) && 'pure' === defaultRenderMode) return;
|
447
|
-
const isJsx = 'jsx' === node.lang || 'tsx' === node.lang;
|
448
|
-
const value = isJsx ? injectDemoBlockImport(previewCodeTransform({
|
449
|
-
language: node.lang,
|
450
|
-
code: node.value
|
451
|
-
}), demoBlockComponentPath) : previewCodeTransform({
|
452
|
-
language: node.lang,
|
453
|
-
code: node.value
|
454
|
-
});
|
455
|
-
const isMobileMode = (null == (_node_meta2 = node.meta) ? void 0 : _node_meta2.includes('mobile')) || (null == (_node_meta3 = node.meta) ? void 0 : _node_meta3.includes('iframe')) || !(null == (_node_meta4 = node.meta) ? void 0 : _node_meta4.includes('web')) && !(null == (_node_meta5 = node.meta) ? void 0 : _node_meta5.includes('internal')) && 'iframe' === previewMode;
|
456
|
-
const id = generateId(pageName, index++);
|
457
|
-
const virtualModulePath = (0, external_node_path_namespaceObject.join)(virtualDir, `${id}.${getLangFileExt(node.lang)}`);
|
458
|
-
constructDemoNode(id, virtualModulePath, node, isMobileMode);
|
459
|
-
if (external_node_fs_default().existsSync(virtualModulePath)) {
|
460
|
-
const content = external_node_fs_default().readFileSync(virtualModulePath, 'utf-8');
|
461
|
-
if (content === value) return;
|
462
|
-
}
|
463
|
-
external_node_fs_default().writeFileSync(virtualModulePath, value);
|
464
|
-
}
|
465
|
-
});
|
466
|
-
tree.children.unshift(...demoMdx);
|
467
|
-
if (remarkPlugin_demos[pageName].length > 0) data.pageMeta.haveDemos = true;
|
468
|
-
};
|
400
|
+
__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].writeFileSync(virtualModulePath, value);
|
401
|
+
}
|
402
|
+
});
|
403
|
+
tree.children.unshift(...demoMdx);
|
404
|
+
if (remarkPlugin_demos[pageName].length > 0) data.pageMeta.haveDemos = true;
|
469
405
|
};
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
});
|
406
|
+
};
|
407
|
+
let src_routeMeta;
|
408
|
+
const DEFAULT_PREVIEW_LANGUAGES = [
|
409
|
+
'jsx',
|
410
|
+
'tsx'
|
411
|
+
];
|
412
|
+
function pluginPreview(options) {
|
413
|
+
const { isMobile = false, iframeOptions = {}, iframePosition = 'follow', defaultRenderMode = 'preview', previewLanguages = DEFAULT_PREVIEW_LANGUAGES, previewCodeTransform = ({ code })=>code } = options ?? {};
|
414
|
+
const previewMode = options?.previewMode ?? (isMobile ? 'iframe' : 'internal');
|
415
|
+
const { devPort = 7890, framework = 'react', position = iframePosition, builderConfig = {}, customEntry } = iframeOptions;
|
416
|
+
const globalUIComponents = 'fixed' === position ? [
|
417
|
+
(0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(staticPath, 'global-components', 'Device.tsx')
|
418
|
+
] : [];
|
419
|
+
const getRouteMeta = ()=>src_routeMeta;
|
420
|
+
let lastDemos;
|
421
|
+
let devServer;
|
422
|
+
let clientConfig;
|
423
|
+
const port = devPort;
|
424
|
+
return {
|
425
|
+
name: '@rspress/plugin-preview',
|
426
|
+
config (config) {
|
427
|
+
config.markdown = config.markdown || {};
|
428
|
+
return config;
|
429
|
+
},
|
430
|
+
routeGenerated (routes) {
|
431
|
+
src_routeMeta = routes;
|
432
|
+
},
|
433
|
+
async beforeBuild (_, isProd) {
|
434
|
+
if (!isProd) try {
|
435
|
+
await new Promise((resolve, reject)=>{
|
436
|
+
const server = __WEBPACK_EXTERNAL_MODULE_node_net_0373943e__["default"].createServer();
|
437
|
+
server.unref();
|
438
|
+
server.on('error', reject);
|
439
|
+
server.listen({
|
440
|
+
port,
|
441
|
+
host: '0.0.0.0'
|
442
|
+
}, ()=>{
|
443
|
+
server.close(resolve);
|
509
444
|
});
|
510
|
-
} catch (e) {
|
511
|
-
if (!!e && 'object' == typeof e && 'code' in e && 'EADDRINUSE' !== e.code) throw e;
|
512
|
-
throw new Error(`Port "${port}" is occupied, please choose another one.`);
|
513
|
-
}
|
514
|
-
},
|
515
|
-
async afterBuild (config, isProd) {
|
516
|
-
var _devServer_server;
|
517
|
-
if ((0, external_lodash_namespaceObject.isEqual)(remarkPlugin_demos, lastDemos)) return;
|
518
|
-
lastDemos = (0, external_lodash_namespaceObject.cloneDeep)(remarkPlugin_demos);
|
519
|
-
await (null == devServer ? void 0 : null == (_devServer_server = devServer.server) ? void 0 : _devServer_server.close());
|
520
|
-
devServer = void 0;
|
521
|
-
const sourceEntry = generateEntry(remarkPlugin_demos, framework, position, customEntry);
|
522
|
-
const outDir = (0, external_node_path_namespaceObject.join)(config.outDir ?? 'doc_build', '~demo');
|
523
|
-
if (0 === Object.keys(sourceEntry).length) return;
|
524
|
-
const { html, source, output, performance } = clientConfig ?? {};
|
525
|
-
const rsbuildConfig = (0, core_namespaceObject.mergeRsbuildConfig)({
|
526
|
-
dev: {
|
527
|
-
progressBar: false
|
528
|
-
},
|
529
|
-
server: {
|
530
|
-
port: devPort,
|
531
|
-
printUrls: ()=>void 0,
|
532
|
-
strictPort: true
|
533
|
-
},
|
534
|
-
performance: {
|
535
|
-
...performance,
|
536
|
-
printFileSize: false
|
537
|
-
},
|
538
|
-
html,
|
539
|
-
source: {
|
540
|
-
...source,
|
541
|
-
entry: sourceEntry
|
542
|
-
},
|
543
|
-
output: {
|
544
|
-
...output,
|
545
|
-
assetPrefix: (null == output ? void 0 : output.assetPrefix) ? `${(0, shared_namespaceObject.removeTrailingSlash)(output.assetPrefix)}/~demo` : '/~demo',
|
546
|
-
distPath: {
|
547
|
-
root: outDir
|
548
|
-
},
|
549
|
-
copy: void 0
|
550
|
-
},
|
551
|
-
plugins: null == config ? void 0 : config.builderPlugins
|
552
|
-
}, builderConfig);
|
553
|
-
const rsbuildInstance = await (0, core_namespaceObject.createRsbuild)({
|
554
|
-
rsbuildConfig
|
555
445
|
});
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
446
|
+
} catch (e) {
|
447
|
+
if (!!e && 'object' == typeof e && 'code' in e && 'EADDRINUSE' !== e.code) throw e;
|
448
|
+
throw new Error(`Port "${port}" is occupied, please choose another one.`);
|
449
|
+
}
|
450
|
+
},
|
451
|
+
async afterBuild (config, isProd) {
|
452
|
+
if ((0, __WEBPACK_EXTERNAL_MODULE_lodash__.isEqual)(remarkPlugin_demos, lastDemos)) return;
|
453
|
+
lastDemos = (0, __WEBPACK_EXTERNAL_MODULE_lodash__.cloneDeep)(remarkPlugin_demos);
|
454
|
+
await devServer?.server?.close();
|
455
|
+
devServer = void 0;
|
456
|
+
const sourceEntry = generateEntry(remarkPlugin_demos, framework, position, customEntry);
|
457
|
+
const outDir = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(config.outDir ?? 'doc_build', '~demo');
|
458
|
+
if (0 === Object.keys(sourceEntry).length) return;
|
459
|
+
const { html, source, output, performance } = clientConfig ?? {};
|
460
|
+
const rsbuildConfig = (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.mergeRsbuildConfig)({
|
461
|
+
dev: {
|
462
|
+
progressBar: false
|
463
|
+
},
|
464
|
+
server: {
|
465
|
+
port: devPort,
|
466
|
+
printUrls: ()=>void 0,
|
467
|
+
strictPort: true
|
468
|
+
},
|
469
|
+
performance: {
|
470
|
+
...performance,
|
471
|
+
printFileSize: false
|
472
|
+
},
|
473
|
+
html,
|
575
474
|
source: {
|
576
|
-
|
577
|
-
|
578
|
-
]
|
475
|
+
...source,
|
476
|
+
entry: sourceEntry
|
579
477
|
},
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
478
|
+
output: {
|
479
|
+
...output,
|
480
|
+
assetPrefix: output?.assetPrefix ? `${(0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.removeTrailingSlash)(output.assetPrefix)}/~demo` : '/~demo',
|
481
|
+
distPath: {
|
482
|
+
root: outDir
|
584
483
|
},
|
585
|
-
|
586
|
-
watchOptions: {
|
587
|
-
ignored: /\.git/
|
588
|
-
}
|
589
|
-
}
|
484
|
+
copy: void 0
|
590
485
|
},
|
591
|
-
plugins:
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
486
|
+
plugins: config?.builderPlugins
|
487
|
+
}, builderConfig);
|
488
|
+
const rsbuildInstance = await (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.createRsbuild)({
|
489
|
+
rsbuildConfig
|
490
|
+
});
|
491
|
+
const { pluginSass } = await import("@rsbuild/plugin-sass");
|
492
|
+
const { pluginLess } = await import("@rsbuild/plugin-less");
|
493
|
+
rsbuildInstance.addPlugins([
|
494
|
+
pluginSass(),
|
495
|
+
pluginLess()
|
496
|
+
]);
|
497
|
+
if ('solid' === framework) rsbuildInstance.addPlugins([
|
498
|
+
(0, __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_babel_2a5a8b08__.pluginBabel)({
|
499
|
+
include: /\.(?:jsx|tsx)$/
|
500
|
+
}),
|
501
|
+
(0, __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_solid_0a0a2645__.pluginSolid)()
|
502
|
+
]);
|
503
|
+
if ('react' === framework) rsbuildInstance.addPlugins([
|
504
|
+
(0, __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_react_7b149ee4__.pluginReact)()
|
505
|
+
]);
|
506
|
+
if (isProd) rsbuildInstance.build();
|
507
|
+
else devServer = await rsbuildInstance.startDevServer();
|
508
|
+
},
|
509
|
+
builderConfig: {
|
510
|
+
source: {
|
511
|
+
include: [
|
512
|
+
(0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(__dirname, '..')
|
606
513
|
]
|
607
514
|
},
|
608
|
-
|
609
|
-
|
610
|
-
|
515
|
+
tools: {
|
516
|
+
bundlerChain (chain) {
|
517
|
+
chain.module.rule('Raw').resourceQuery(/raw/).type('asset/source').end();
|
518
|
+
chain.resolve.extensions.prepend('.md').prepend('.mdx');
|
519
|
+
},
|
520
|
+
rspack: {
|
521
|
+
watchOptions: {
|
522
|
+
ignored: /\.git/
|
523
|
+
}
|
524
|
+
}
|
611
525
|
},
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
{
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
526
|
+
plugins: [
|
527
|
+
{
|
528
|
+
name: 'close-demo-server',
|
529
|
+
setup: (api)=>{
|
530
|
+
api.modifyRsbuildConfig((config)=>{
|
531
|
+
if (config.output?.target === 'web') clientConfig = config;
|
532
|
+
});
|
533
|
+
api.onCloseDevServer(async ()=>{
|
534
|
+
await devServer?.server?.close();
|
535
|
+
devServer = void 0;
|
536
|
+
});
|
537
|
+
}
|
538
|
+
}
|
539
|
+
]
|
540
|
+
},
|
541
|
+
extendPageData (pageData, isProd) {
|
542
|
+
if (!isProd) pageData.devPort = port;
|
543
|
+
pageData.extraHighlightLanguages = previewLanguages;
|
544
|
+
},
|
545
|
+
markdown: {
|
546
|
+
remarkPlugins: [
|
547
|
+
[
|
548
|
+
remarkCodeToDemo,
|
549
|
+
{
|
550
|
+
getRouteMeta,
|
551
|
+
position,
|
552
|
+
previewMode,
|
553
|
+
defaultRenderMode,
|
554
|
+
previewLanguages,
|
555
|
+
previewCodeTransform
|
556
|
+
}
|
628
557
|
]
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
Object.defineProperty(exports, '__esModule', {
|
640
|
-
value: true
|
641
|
-
});
|
558
|
+
],
|
559
|
+
globalComponents: [
|
560
|
+
(0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(staticPath, 'global-components', 'Container.tsx')
|
561
|
+
]
|
562
|
+
},
|
563
|
+
globalUIComponents,
|
564
|
+
globalStyles: (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(staticPath, 'global-styles', `${previewMode}.css`)
|
565
|
+
};
|
566
|
+
}
|
567
|
+
export { pluginPreview };
|
package/dist/utils.js
CHANGED
@@ -1,35 +1,3 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __webpack_require__ = {};
|
3
|
-
(()=>{
|
4
|
-
__webpack_require__.d = (exports1, definition)=>{
|
5
|
-
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
6
|
-
enumerable: true,
|
7
|
-
get: definition[key]
|
8
|
-
});
|
9
|
-
};
|
10
|
-
})();
|
11
|
-
(()=>{
|
12
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
13
|
-
})();
|
14
|
-
(()=>{
|
15
|
-
__webpack_require__.r = (exports1)=>{
|
16
|
-
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
17
|
-
value: 'Module'
|
18
|
-
});
|
19
|
-
Object.defineProperty(exports1, '__esModule', {
|
20
|
-
value: true
|
21
|
-
});
|
22
|
-
};
|
23
|
-
})();
|
24
|
-
var __webpack_exports__ = {};
|
25
|
-
__webpack_require__.r(__webpack_exports__);
|
26
|
-
__webpack_require__.d(__webpack_exports__, {
|
27
|
-
generateId: ()=>generateId,
|
28
|
-
getLangFileExt: ()=>getLangFileExt,
|
29
|
-
injectDemoBlockImport: ()=>injectDemoBlockImport,
|
30
|
-
normalizeId: ()=>normalizeId,
|
31
|
-
toValidVarName: ()=>toValidVarName
|
32
|
-
});
|
33
1
|
const toValidVarName = (str)=>{
|
34
2
|
if (/^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(str)) return str;
|
35
3
|
return str.replace(/[^0-9a-zA-Z_$]/g, '_').replace(/^([0-9])/, '_$1');
|
@@ -54,18 +22,4 @@ const getLangFileExt = (lang)=>{
|
|
54
22
|
return lang;
|
55
23
|
}
|
56
24
|
};
|
57
|
-
|
58
|
-
exports.getLangFileExt = __webpack_exports__.getLangFileExt;
|
59
|
-
exports.injectDemoBlockImport = __webpack_exports__.injectDemoBlockImport;
|
60
|
-
exports.normalizeId = __webpack_exports__.normalizeId;
|
61
|
-
exports.toValidVarName = __webpack_exports__.toValidVarName;
|
62
|
-
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
63
|
-
"generateId",
|
64
|
-
"getLangFileExt",
|
65
|
-
"injectDemoBlockImport",
|
66
|
-
"normalizeId",
|
67
|
-
"toValidVarName"
|
68
|
-
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
69
|
-
Object.defineProperty(exports, '__esModule', {
|
70
|
-
value: true
|
71
|
-
});
|
25
|
+
export { generateId, getLangFileExt, injectDemoBlockImport, normalizeId, toValidVarName };
|
package/package.json
CHANGED
@@ -1,15 +1,21 @@
|
|
1
1
|
{
|
2
2
|
"name": "@rspress/plugin-preview",
|
3
|
-
"version": "2.0.0-beta.
|
3
|
+
"version": "2.0.0-beta.2",
|
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": {
|
7
7
|
"type": "git",
|
8
|
-
"url": "https://github.com/web-infra-dev/rspress",
|
8
|
+
"url": "git+https://github.com/web-infra-dev/rspress.git",
|
9
9
|
"directory": "packages/plugin-preview"
|
10
10
|
},
|
11
11
|
"license": "MIT",
|
12
|
-
"
|
12
|
+
"type": "module",
|
13
|
+
"exports": {
|
14
|
+
".": {
|
15
|
+
"types": "./index.d.ts",
|
16
|
+
"default": "./dist/index.js"
|
17
|
+
}
|
18
|
+
},
|
13
19
|
"types": "./index.d.ts",
|
14
20
|
"files": [
|
15
21
|
"index.d.ts",
|
@@ -25,8 +31,8 @@
|
|
25
31
|
"@rsbuild/plugin-solid": "~1.0.5",
|
26
32
|
"lodash": "4.17.21",
|
27
33
|
"qrcode.react": "^4.2.0",
|
28
|
-
"@rspress/shared": "2.0.0-beta.
|
29
|
-
"@rspress/theme-default": "2.0.0-beta.
|
34
|
+
"@rspress/shared": "2.0.0-beta.2",
|
35
|
+
"@rspress/theme-default": "2.0.0-beta.2"
|
30
36
|
},
|
31
37
|
"devDependencies": {
|
32
38
|
"@rslib/core": "0.6.5",
|
@@ -40,17 +46,18 @@
|
|
40
46
|
"react": "^19.1.0",
|
41
47
|
"react-dom": "^19.1.0",
|
42
48
|
"react-router-dom": "^6.29.0",
|
49
|
+
"rsbuild-plugin-publint": "^0.3.0",
|
43
50
|
"typescript": "^5.8.2",
|
44
51
|
"unified": "^11.0.5",
|
45
52
|
"unist-util-visit": "^5.0.0"
|
46
53
|
},
|
47
54
|
"peerDependencies": {
|
48
|
-
"@rspress/core": "^2.0.0-beta.
|
49
|
-
"react": ">=
|
55
|
+
"@rspress/core": "^2.0.0-beta.2",
|
56
|
+
"react": ">=18.0.0",
|
50
57
|
"react-router-dom": "^6.8.1"
|
51
58
|
},
|
52
59
|
"engines": {
|
53
|
-
"node": ">=
|
60
|
+
"node": ">=18.0.0"
|
54
61
|
},
|
55
62
|
"publishConfig": {
|
56
63
|
"access": "public",
|
@@ -45,7 +45,7 @@ const Container: React.FC<ContainerProps> = props => {
|
|
45
45
|
<NoSSR>
|
46
46
|
<div className="rspress-preview">
|
47
47
|
{isMobile === 'true' ? (
|
48
|
-
<div className="rspress-preview-wrapper flex">
|
48
|
+
<div className="rspress-preview-wrapper rp-flex">
|
49
49
|
<div className="rspress-preview-code">{children?.[0]}</div>
|
50
50
|
<div className="rspress-preview-device">
|
51
51
|
<iframe src={getPageUrl()} key={iframeKey}></iframe>
|