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