@rspress/plugin-preview 2.0.0-alpha.1 → 2.0.0-alpha.11
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 +87 -49
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +26 -4
- package/package.json +18 -18
- package/static/global-components/{DemoBlock.scss → DemoBlock.css} +11 -9
- package/static/global-components/DemoBlock.tsx +1 -1
- package/static/global-components/Device.tsx +8 -10
- package/static/global-components/common/index.css +103 -0
- package/static/global-components/common/mobile-operation.tsx +1 -1
- package/static/global-styles/iframe.css +1 -5
- package/static/global-components/common/index.scss +0 -104
- /package/static/global-components/{Device.scss → Device.css} +0 -0
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
@@ -38,7 +38,7 @@ function __webpack_require__(moduleId) {
|
|
38
38
|
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
39
39
|
})();
|
40
40
|
(()=>{
|
41
|
-
__webpack_require__.r =
|
41
|
+
__webpack_require__.r = (exports1)=>{
|
42
42
|
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
43
43
|
value: 'Module'
|
44
44
|
});
|
@@ -77,7 +77,18 @@ var __webpack_exports__ = {};
|
|
77
77
|
import DemoBlock from ${JSON.stringify(path)};
|
78
78
|
${str}
|
79
79
|
`;
|
80
|
-
|
80
|
+
const getLangFileExt = (lang)=>{
|
81
|
+
switch(lang){
|
82
|
+
case 'jsx':
|
83
|
+
case 'tsx':
|
84
|
+
return 'tsx';
|
85
|
+
case 'json':
|
86
|
+
return 'tsx';
|
87
|
+
default:
|
88
|
+
return lang;
|
89
|
+
}
|
90
|
+
};
|
91
|
+
function generateEntry(demos, framework, position, customEntry) {
|
81
92
|
const sourceEntry = {};
|
82
93
|
const entryCssPath = (0, external_node_path_namespaceObject.join)(staticPath, 'global-styles', 'entry.css');
|
83
94
|
if ('follow' === position) Object.values(demos).forEach((routes)=>{
|
@@ -96,7 +107,10 @@ var __webpack_exports__ = {};
|
|
96
107
|
import Demo from ${JSON.stringify(demoPath)};
|
97
108
|
render(<Demo />, document.getElementById('root'));
|
98
109
|
`;
|
99
|
-
const entryContent =
|
110
|
+
const entryContent = customEntry ? customEntry({
|
111
|
+
entryCssPath,
|
112
|
+
demoPath
|
113
|
+
}) : 'react' === framework ? reactEntry : solidEntry;
|
100
114
|
(0, external_node_fs_namespaceObject.writeFileSync)(entry, entryContent);
|
101
115
|
sourceEntry[id] = entry;
|
102
116
|
});
|
@@ -142,9 +156,9 @@ var __webpack_exports__ = {};
|
|
142
156
|
const node_utils_namespaceObject = require("@rspress/shared/node-utils");
|
143
157
|
const convert = function(test) {
|
144
158
|
if (null == test) return ok;
|
145
|
-
if ('string' == typeof test) return typeFactory(test);
|
146
|
-
if ('object' == typeof test) return Array.isArray(test) ? anyFactory(test) : propsFactory(test);
|
147
159
|
if ('function' == typeof test) return castFactory(test);
|
160
|
+
if ('object' == typeof test) return Array.isArray(test) ? anyFactory(test) : propsFactory(test);
|
161
|
+
if ('string' == typeof test) return typeFactory(test);
|
148
162
|
throw new Error('Expected function, string, or object as test');
|
149
163
|
};
|
150
164
|
function anyFactory(tests) {
|
@@ -154,15 +168,17 @@ var __webpack_exports__ = {};
|
|
154
168
|
return castFactory(any);
|
155
169
|
function any(...parameters) {
|
156
170
|
let index = -1;
|
157
|
-
while(++index < checks.length)if (checks[index].
|
171
|
+
while(++index < checks.length)if (checks[index].apply(this, parameters)) return true;
|
158
172
|
return false;
|
159
173
|
}
|
160
174
|
}
|
161
175
|
function propsFactory(check) {
|
176
|
+
const checkAsRecord = check;
|
162
177
|
return castFactory(all);
|
163
178
|
function all(node) {
|
179
|
+
const nodeAsRecord = node;
|
164
180
|
let key;
|
165
|
-
for(key in check)if (
|
181
|
+
for(key in check)if (nodeAsRecord[key] !== checkAsRecord[key]) return false;
|
166
182
|
return true;
|
167
183
|
}
|
168
184
|
}
|
@@ -172,28 +188,32 @@ var __webpack_exports__ = {};
|
|
172
188
|
return node && node.type === check;
|
173
189
|
}
|
174
190
|
}
|
175
|
-
function castFactory(
|
176
|
-
return
|
177
|
-
function
|
178
|
-
return Boolean(
|
191
|
+
function castFactory(testFunction) {
|
192
|
+
return check;
|
193
|
+
function check(value, index, parent) {
|
194
|
+
return Boolean(looksLikeANode(value) && testFunction.call(this, value, 'number' == typeof index ? index : void 0, parent || void 0));
|
179
195
|
}
|
180
196
|
}
|
181
197
|
function ok() {
|
182
198
|
return true;
|
183
199
|
}
|
200
|
+
function looksLikeANode(value) {
|
201
|
+
return null !== value && 'object' == typeof value && 'type' in value;
|
202
|
+
}
|
184
203
|
function color(d) {
|
185
204
|
return '\u001B[33m' + d + '\u001B[39m';
|
186
205
|
}
|
206
|
+
const empty = [];
|
187
207
|
const CONTINUE = true;
|
188
208
|
const EXIT = false;
|
189
209
|
const SKIP = 'skip';
|
190
|
-
|
210
|
+
function visitParents(tree, test, visitor, reverse) {
|
211
|
+
let check;
|
191
212
|
if ('function' == typeof test && 'function' != typeof visitor) {
|
192
213
|
reverse = visitor;
|
193
214
|
visitor = test;
|
194
|
-
|
195
|
-
|
196
|
-
const is = convert(test);
|
215
|
+
} else check = test;
|
216
|
+
const is = convert(check);
|
197
217
|
const step = reverse ? -1 : 1;
|
198
218
|
factory(tree, void 0, [])();
|
199
219
|
function factory(node, index, parents) {
|
@@ -206,49 +226,61 @@ var __webpack_exports__ = {};
|
|
206
226
|
}
|
207
227
|
return visit;
|
208
228
|
function visit() {
|
209
|
-
let result =
|
229
|
+
let result = empty;
|
210
230
|
let subresult;
|
211
231
|
let offset;
|
212
232
|
let grandparents;
|
213
|
-
if (!test || is(node, index, parents[parents.length - 1] ||
|
233
|
+
if (!test || is(node, index, parents[parents.length - 1] || void 0)) {
|
214
234
|
result = toResult(visitor(node, parents));
|
215
235
|
if (result[0] === EXIT) return result;
|
216
236
|
}
|
217
|
-
if (
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
237
|
+
if ('children' in node && node.children) {
|
238
|
+
const nodeAsParent = node;
|
239
|
+
if (nodeAsParent.children && result[0] !== SKIP) {
|
240
|
+
offset = (reverse ? nodeAsParent.children.length : -1) + step;
|
241
|
+
grandparents = parents.concat(nodeAsParent);
|
242
|
+
while(offset > -1 && offset < nodeAsParent.children.length){
|
243
|
+
const child = nodeAsParent.children[offset];
|
244
|
+
subresult = factory(child, offset, grandparents)();
|
245
|
+
if (subresult[0] === EXIT) return subresult;
|
246
|
+
offset = 'number' == typeof subresult[1] ? subresult[1] : offset + step;
|
247
|
+
}
|
224
248
|
}
|
225
249
|
}
|
226
250
|
return result;
|
227
251
|
}
|
228
252
|
}
|
229
|
-
}
|
253
|
+
}
|
230
254
|
function toResult(value) {
|
231
255
|
if (Array.isArray(value)) return value;
|
232
256
|
if ('number' == typeof value) return [
|
233
257
|
CONTINUE,
|
234
258
|
value
|
235
259
|
];
|
236
|
-
return [
|
260
|
+
return null == value ? empty : [
|
237
261
|
value
|
238
262
|
];
|
239
263
|
}
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
264
|
+
function lib_visit(tree, testOrVisitor, visitorOrReverse, maybeReverse) {
|
265
|
+
let reverse;
|
266
|
+
let test;
|
267
|
+
let visitor;
|
268
|
+
if ('function' == typeof testOrVisitor && 'function' != typeof visitorOrReverse) {
|
269
|
+
test = void 0;
|
270
|
+
visitor = testOrVisitor;
|
271
|
+
reverse = visitorOrReverse;
|
272
|
+
} else {
|
273
|
+
test = testOrVisitor;
|
274
|
+
visitor = visitorOrReverse;
|
275
|
+
reverse = maybeReverse;
|
245
276
|
}
|
246
277
|
visitParents(tree, test, overload, reverse);
|
247
278
|
function overload(node, parents) {
|
248
279
|
const parent = parents[parents.length - 1];
|
249
|
-
|
280
|
+
const index = parent ? parent.children.indexOf(node) : void 0;
|
281
|
+
return visitor(node, index, parent);
|
250
282
|
}
|
251
|
-
}
|
283
|
+
}
|
252
284
|
const getASTNodeImport = (name, from)=>({
|
253
285
|
type: 'mdxjsEsm',
|
254
286
|
value: `import ${name} from ${JSON.stringify(from)}`,
|
@@ -405,14 +437,18 @@ var __webpack_exports__ = {};
|
|
405
437
|
if ('hasVisited' in node) return;
|
406
438
|
if (node.lang && previewLanguages.includes(node.lang)) {
|
407
439
|
var _node_meta, _node_meta1, _node_meta2, _node_meta3, _node_meta4, _node_meta5;
|
408
|
-
if ((null
|
409
|
-
const
|
440
|
+
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;
|
441
|
+
const isJsx = 'jsx' === node.lang || 'tsx' === node.lang;
|
442
|
+
const value = isJsx ? injectDemoBlockImport(previewCodeTransform({
|
443
|
+
language: node.lang,
|
444
|
+
code: node.value
|
445
|
+
}), demoBlockComponentPath) : previewCodeTransform({
|
410
446
|
language: node.lang,
|
411
447
|
code: node.value
|
412
|
-
})
|
413
|
-
const isMobileMode = (null
|
448
|
+
});
|
449
|
+
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;
|
414
450
|
const id = generateId(pageName, index++);
|
415
|
-
const virtualModulePath = (0, external_node_path_namespaceObject.join)(virtualDir, `${id}.
|
451
|
+
const virtualModulePath = (0, external_node_path_namespaceObject.join)(virtualDir, `${id}.${getLangFileExt(node.lang)}`);
|
416
452
|
constructDemoNode(id, virtualModulePath, node, isMobileMode);
|
417
453
|
if (external_node_fs_default().existsSync(virtualModulePath)) {
|
418
454
|
const content = external_node_fs_default().readFileSync(virtualModulePath, 'utf-8');
|
@@ -425,7 +461,7 @@ var __webpack_exports__ = {};
|
|
425
461
|
if (remarkPlugin_demos[pageName].length > 0) data.pageMeta.haveDemos = true;
|
426
462
|
};
|
427
463
|
};
|
428
|
-
let
|
464
|
+
let src_routeMeta;
|
429
465
|
const DEFAULT_PREVIEW_LANGUAGES = [
|
430
466
|
'jsx',
|
431
467
|
'tsx'
|
@@ -433,11 +469,11 @@ var __webpack_exports__ = {};
|
|
433
469
|
function pluginPreview(options) {
|
434
470
|
const { isMobile = false, iframeOptions = {}, iframePosition = 'follow', defaultRenderMode = 'preview', previewLanguages = DEFAULT_PREVIEW_LANGUAGES, previewCodeTransform = ({ code })=>code } = options ?? {};
|
435
471
|
const previewMode = (null == options ? void 0 : options.previewMode) ?? (isMobile ? 'iframe' : 'internal');
|
436
|
-
const { devPort = 7890, framework = 'react', position = iframePosition, builderConfig = {} } = iframeOptions;
|
472
|
+
const { devPort = 7890, framework = 'react', position = iframePosition, builderConfig = {}, customEntry } = iframeOptions;
|
437
473
|
const globalUIComponents = 'fixed' === position ? [
|
438
474
|
(0, external_node_path_namespaceObject.join)(staticPath, 'global-components', 'Device.tsx')
|
439
475
|
] : [];
|
440
|
-
const getRouteMeta = ()=>
|
476
|
+
const getRouteMeta = ()=>src_routeMeta;
|
441
477
|
let lastDemos;
|
442
478
|
let devServer;
|
443
479
|
let clientConfig;
|
@@ -450,7 +486,7 @@ var __webpack_exports__ = {};
|
|
450
486
|
return config;
|
451
487
|
},
|
452
488
|
routeGenerated (routes) {
|
453
|
-
|
489
|
+
src_routeMeta = routes;
|
454
490
|
},
|
455
491
|
async beforeBuild (_, isProd) {
|
456
492
|
if (!isProd) try {
|
@@ -474,9 +510,9 @@ var __webpack_exports__ = {};
|
|
474
510
|
var _devServer_server;
|
475
511
|
if ((0, external_lodash_namespaceObject.isEqual)(remarkPlugin_demos, lastDemos)) return;
|
476
512
|
lastDemos = (0, external_lodash_namespaceObject.cloneDeep)(remarkPlugin_demos);
|
477
|
-
await (null == devServer ? void 0 : null
|
513
|
+
await (null == devServer ? void 0 : null == (_devServer_server = devServer.server) ? void 0 : _devServer_server.close());
|
478
514
|
devServer = void 0;
|
479
|
-
const sourceEntry = generateEntry(remarkPlugin_demos, framework, position);
|
515
|
+
const sourceEntry = generateEntry(remarkPlugin_demos, framework, position, customEntry);
|
480
516
|
const outDir = (0, external_node_path_namespaceObject.join)(config.outDir ?? 'doc_build', '~demo');
|
481
517
|
if (0 === Object.keys(sourceEntry).length) return;
|
482
518
|
const { html, source, output, performance } = clientConfig ?? {};
|
@@ -552,11 +588,11 @@ var __webpack_exports__ = {};
|
|
552
588
|
setup: (api)=>{
|
553
589
|
api.modifyRsbuildConfig((config)=>{
|
554
590
|
var _config_output;
|
555
|
-
if ((null
|
591
|
+
if ((null == (_config_output = config.output) ? void 0 : _config_output.target) === 'web') clientConfig = config;
|
556
592
|
});
|
557
593
|
api.onCloseDevServer(async ()=>{
|
558
594
|
var _devServer_server;
|
559
|
-
await (null == devServer ? void 0 : null
|
595
|
+
await (null == devServer ? void 0 : null == (_devServer_server = devServer.server) ? void 0 : _devServer_server.close());
|
560
596
|
devServer = void 0;
|
561
597
|
});
|
562
598
|
}
|
@@ -590,8 +626,10 @@ var __webpack_exports__ = {};
|
|
590
626
|
};
|
591
627
|
}
|
592
628
|
})();
|
593
|
-
|
594
|
-
for(var __webpack_i__ in __webpack_exports__)
|
595
|
-
|
629
|
+
exports.pluginPreview = __webpack_exports__.pluginPreview;
|
630
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
631
|
+
"pluginPreview"
|
632
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
633
|
+
Object.defineProperty(exports, '__esModule', {
|
596
634
|
value: true
|
597
635
|
});
|
package/dist/utils.d.ts
CHANGED
package/dist/utils.js
CHANGED
@@ -12,7 +12,7 @@ var __webpack_require__ = {};
|
|
12
12
|
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
13
13
|
})();
|
14
14
|
(()=>{
|
15
|
-
__webpack_require__.r =
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
16
16
|
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
17
17
|
value: 'Module'
|
18
18
|
});
|
@@ -25,6 +25,7 @@ var __webpack_exports__ = {};
|
|
25
25
|
__webpack_require__.r(__webpack_exports__);
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
27
27
|
generateId: ()=>generateId,
|
28
|
+
getLangFileExt: ()=>getLangFileExt,
|
28
29
|
injectDemoBlockImport: ()=>injectDemoBlockImport,
|
29
30
|
normalizeId: ()=>normalizeId,
|
30
31
|
toValidVarName: ()=>toValidVarName
|
@@ -42,8 +43,29 @@ const injectDemoBlockImport = (str, path)=>`
|
|
42
43
|
import DemoBlock from ${JSON.stringify(path)};
|
43
44
|
${str}
|
44
45
|
`;
|
45
|
-
|
46
|
-
|
47
|
-
|
46
|
+
const getLangFileExt = (lang)=>{
|
47
|
+
switch(lang){
|
48
|
+
case 'jsx':
|
49
|
+
case 'tsx':
|
50
|
+
return 'tsx';
|
51
|
+
case 'json':
|
52
|
+
return 'tsx';
|
53
|
+
default:
|
54
|
+
return lang;
|
55
|
+
}
|
56
|
+
};
|
57
|
+
exports.generateId = __webpack_exports__.generateId;
|
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', {
|
48
70
|
value: true
|
49
71
|
});
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@rspress/plugin-preview",
|
3
|
-
"version": "2.0.0-alpha.
|
3
|
+
"version": "2.0.0-alpha.11",
|
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": {
|
@@ -17,35 +17,35 @@
|
|
17
17
|
"static"
|
18
18
|
],
|
19
19
|
"dependencies": {
|
20
|
-
"@rsbuild/core": "1.
|
21
|
-
"@rsbuild/plugin-babel": "~1.0.
|
22
|
-
"@rsbuild/plugin-less": "~1.
|
20
|
+
"@rsbuild/core": "1.3.6",
|
21
|
+
"@rsbuild/plugin-babel": "~1.0.5",
|
22
|
+
"@rsbuild/plugin-less": "~1.2.2",
|
23
23
|
"@rsbuild/plugin-react": "~1.1.1",
|
24
|
-
"@rsbuild/plugin-sass": "~1.
|
24
|
+
"@rsbuild/plugin-sass": "~1.3.1",
|
25
25
|
"@rsbuild/plugin-solid": "~1.0.5",
|
26
26
|
"lodash": "4.17.21",
|
27
|
-
"qrcode.react": "^
|
28
|
-
"@rspress/shared": "2.0.0-alpha.
|
29
|
-
"@rspress/theme-default": "2.0.0-alpha.
|
27
|
+
"qrcode.react": "^4.2.0",
|
28
|
+
"@rspress/shared": "2.0.0-alpha.11",
|
29
|
+
"@rspress/theme-default": "2.0.0-alpha.11"
|
30
30
|
},
|
31
31
|
"devDependencies": {
|
32
|
-
"@rslib/core": "0.
|
32
|
+
"@rslib/core": "0.6.3",
|
33
33
|
"@types/lodash": "^4.17.16",
|
34
|
-
"@types/mdast": "^
|
34
|
+
"@types/mdast": "^4.0.4",
|
35
35
|
"@types/node": "^18.11.17",
|
36
|
-
"@types/react": "^18.3.
|
37
|
-
"@types/react-dom": "^18.3.
|
38
|
-
"mdast-util-mdx-jsx": "^2.
|
39
|
-
"mdast-util-mdxjs-esm": "^
|
36
|
+
"@types/react": "^18.3.20",
|
37
|
+
"@types/react-dom": "^18.3.6",
|
38
|
+
"mdast-util-mdx-jsx": "^3.2.0",
|
39
|
+
"mdast-util-mdxjs-esm": "^2.0.1",
|
40
40
|
"react": "^18.3.1",
|
41
41
|
"react-dom": "^18.3.1",
|
42
42
|
"react-router-dom": "^6.29.0",
|
43
|
-
"typescript": "^5.
|
44
|
-
"unified": "^
|
45
|
-
"unist-util-visit": "^
|
43
|
+
"typescript": "^5.8.2",
|
44
|
+
"unified": "^11.0.5",
|
45
|
+
"unist-util-visit": "^5.0.0"
|
46
46
|
},
|
47
47
|
"peerDependencies": {
|
48
|
-
"@rspress/core": "^2.0.0-alpha.
|
48
|
+
"@rspress/core": "^2.0.0-alpha.11",
|
49
49
|
"react": ">=17.0.0",
|
50
50
|
"react-router-dom": "^6.8.1"
|
51
51
|
},
|
@@ -9,13 +9,15 @@
|
|
9
9
|
.rspress-demo-block {
|
10
10
|
padding-bottom: 12px;
|
11
11
|
background-color: var(--rp-demo-block-bg);
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
12
|
+
}
|
13
|
+
|
14
|
+
.rspress-demo-block-title {
|
15
|
+
padding: 12px 12px 8px;
|
16
|
+
color: #697b8c;
|
17
|
+
font-size: 14px;
|
18
|
+
}
|
19
|
+
|
20
|
+
.rspress-demo-block-main {
|
21
|
+
border-right: none;
|
22
|
+
border-left: none;
|
21
23
|
}
|
@@ -1,9 +1,14 @@
|
|
1
|
-
import {
|
1
|
+
import {
|
2
|
+
NoSSR,
|
3
|
+
usePageData,
|
4
|
+
useWindowSize,
|
5
|
+
withBase,
|
6
|
+
} from '@rspress/core/runtime';
|
2
7
|
import { useCallback, useEffect, useState } from 'react';
|
3
8
|
// @ts-ignore
|
4
9
|
import { normalizeId } from '../../dist/utils';
|
5
10
|
import MobileOperation from './common/mobile-operation';
|
6
|
-
import './Device.
|
11
|
+
import './Device.css';
|
7
12
|
|
8
13
|
export default () => {
|
9
14
|
const { page } = usePageData();
|
@@ -22,10 +27,8 @@ export default () => {
|
|
22
27
|
// Do nothing in ssr
|
23
28
|
return '';
|
24
29
|
};
|
25
|
-
const initialInnerWidth =
|
26
|
-
typeof window !== 'undefined' ? window.innerWidth : 0;
|
27
30
|
const [asideWidth, setAsideWidth] = useState('0px');
|
28
|
-
const
|
31
|
+
const { width: innerWidth } = useWindowSize();
|
29
32
|
const [iframeKey, setIframeKey] = useState(0);
|
30
33
|
const refresh = useCallback(() => {
|
31
34
|
setIframeKey(Math.random());
|
@@ -40,11 +43,6 @@ export default () => {
|
|
40
43
|
getComputedStyle(root).getPropertyValue('--rp-aside-width');
|
41
44
|
setAsideWidth(defaultAsideWidth);
|
42
45
|
}
|
43
|
-
const handleResize = () => {
|
44
|
-
setInnerWidth(window.innerWidth);
|
45
|
-
};
|
46
|
-
window.addEventListener('resize', handleResize);
|
47
|
-
return () => window.removeEventListener('resize', handleResize);
|
48
46
|
}, []);
|
49
47
|
|
50
48
|
useEffect(() => {
|
@@ -0,0 +1,103 @@
|
|
1
|
+
:root {
|
2
|
+
--rp-preview-button-hover-bg: #e5e6eb;
|
3
|
+
--rp-preview-button-bg: #e5e6eb;
|
4
|
+
}
|
5
|
+
|
6
|
+
.dark {
|
7
|
+
--rp-preview-button-hover-bg: #c5c5c5;
|
8
|
+
--rp-preview-button-bg: #c5c5c5;
|
9
|
+
}
|
10
|
+
|
11
|
+
.rspress-preview {
|
12
|
+
padding: 16px 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
.rspress-preview-wrapper {
|
16
|
+
border: 1px solid var(--rp-container-details-border);
|
17
|
+
border-radius: var(--rp-radius-small);
|
18
|
+
}
|
19
|
+
|
20
|
+
.rspress-preview-card {
|
21
|
+
padding: 16px;
|
22
|
+
position: relative;
|
23
|
+
border: 1px solid var(--rp-container-details-border);
|
24
|
+
border-radius: var(--rp-radius-small);
|
25
|
+
display: flex;
|
26
|
+
}
|
27
|
+
|
28
|
+
.rspress-preview-qrcode {
|
29
|
+
background-color: #fff;
|
30
|
+
width: 120px;
|
31
|
+
height: 120px;
|
32
|
+
position: absolute;
|
33
|
+
top: -132px;
|
34
|
+
right: -46px;
|
35
|
+
padding: 12px;
|
36
|
+
}
|
37
|
+
|
38
|
+
.rspress-preview-code {
|
39
|
+
position: relative;
|
40
|
+
overflow: hidden;
|
41
|
+
flex: 1 1;
|
42
|
+
max-height: 700px;
|
43
|
+
}
|
44
|
+
|
45
|
+
.rspress-preview-code-hide {
|
46
|
+
position: relative;
|
47
|
+
overflow: hidden;
|
48
|
+
display: none;
|
49
|
+
}
|
50
|
+
|
51
|
+
.rspress-preview-code-show {
|
52
|
+
margin-top: 16px;
|
53
|
+
display: block;
|
54
|
+
}
|
55
|
+
|
56
|
+
.rspress-preview-device {
|
57
|
+
position: relative;
|
58
|
+
flex: 0 0;
|
59
|
+
border-left: 1px solid #e6e6e6;
|
60
|
+
display: flex;
|
61
|
+
flex-direction: column;
|
62
|
+
}
|
63
|
+
|
64
|
+
.rspress-preview-device iframe {
|
65
|
+
border-bottom: 1px solid #e6e6e6;
|
66
|
+
width: 360px;
|
67
|
+
height: 100%;
|
68
|
+
flex: auto;
|
69
|
+
}
|
70
|
+
|
71
|
+
.rspress-preview-operations button {
|
72
|
+
width: 28px;
|
73
|
+
height: 28px;
|
74
|
+
padding: 0;
|
75
|
+
text-align: center;
|
76
|
+
border-radius: 50%;
|
77
|
+
border: 1px solid transparent;
|
78
|
+
background-color: var(--rp-c-bg-soft);
|
79
|
+
margin-left: 14px;
|
80
|
+
}
|
81
|
+
|
82
|
+
.rspress-preview-operations button:hover {
|
83
|
+
background-color: var(--rp-preview-button-hover-bg);
|
84
|
+
}
|
85
|
+
|
86
|
+
.rspress-preview-operations svg {
|
87
|
+
display: inline-block;
|
88
|
+
vertical-align: -2px;
|
89
|
+
}
|
90
|
+
|
91
|
+
.rspress-preview-operations.mobile {
|
92
|
+
display: flex;
|
93
|
+
justify-content: flex-end;
|
94
|
+
width: 100%;
|
95
|
+
padding: 6px;
|
96
|
+
}
|
97
|
+
|
98
|
+
.rspress-preview-operations.web {
|
99
|
+
display: flex;
|
100
|
+
justify-content: center;
|
101
|
+
align-items: center;
|
102
|
+
flex: none;
|
103
|
+
}
|
@@ -23,13 +23,9 @@
|
|
23
23
|
margin-left: var(--rp-preview-padding);
|
24
24
|
}
|
25
25
|
|
26
|
-
.rspress-doc-container {
|
27
|
-
padding-right: var(--rp-preview-padding);
|
28
|
-
padding-left: var(--rp-preview-padding);
|
29
|
-
}
|
30
|
-
|
31
26
|
.rspress-doc {
|
32
27
|
width: 100%;
|
28
|
+
padding-left: var(--rp-preview-padding);
|
33
29
|
padding-right: var(--rp-preview-padding);
|
34
30
|
}
|
35
31
|
}
|
@@ -1,104 +0,0 @@
|
|
1
|
-
:root {
|
2
|
-
--rp-preview-button-hover-bg: #e5e6eb;
|
3
|
-
--rp-preview-button-bg: #e5e6eb;
|
4
|
-
}
|
5
|
-
|
6
|
-
.dark {
|
7
|
-
--rp-preview-button-hover-bg: #c5c5c5;
|
8
|
-
--rp-preview-button-bg: #c5c5c5;
|
9
|
-
}
|
10
|
-
|
11
|
-
.rspress-preview {
|
12
|
-
padding: 16px 0;
|
13
|
-
|
14
|
-
&-wrapper {
|
15
|
-
border: 1px solid var(--rp-container-details-border);
|
16
|
-
border-radius: var(--rp-radius-small);
|
17
|
-
}
|
18
|
-
|
19
|
-
&-card {
|
20
|
-
padding: 16px;
|
21
|
-
position: relative;
|
22
|
-
border: 1px solid var(--rp-container-details-border);
|
23
|
-
border-radius: var(--rp-radius-small);
|
24
|
-
display: flex;
|
25
|
-
}
|
26
|
-
|
27
|
-
&-qrcode {
|
28
|
-
background-color: #fff;
|
29
|
-
width: 120px;
|
30
|
-
height: 120px;
|
31
|
-
position: absolute;
|
32
|
-
top: -132px;
|
33
|
-
right: -46px;
|
34
|
-
padding: 12px;
|
35
|
-
}
|
36
|
-
|
37
|
-
&-code {
|
38
|
-
position: relative;
|
39
|
-
overflow: hidden;
|
40
|
-
flex: 1 1;
|
41
|
-
max-height: 700px;
|
42
|
-
}
|
43
|
-
|
44
|
-
&-code-hide {
|
45
|
-
position: relative;
|
46
|
-
overflow: hidden;
|
47
|
-
display: none;
|
48
|
-
}
|
49
|
-
|
50
|
-
&-code-show {
|
51
|
-
margin-top: 16px;
|
52
|
-
display: block;
|
53
|
-
}
|
54
|
-
|
55
|
-
&-device {
|
56
|
-
position: relative;
|
57
|
-
flex: 0 0;
|
58
|
-
border-left: 1px solid #e6e6e6;
|
59
|
-
display: flex;
|
60
|
-
flex-direction: column;
|
61
|
-
iframe {
|
62
|
-
border-bottom: 1px solid #e6e6e6;
|
63
|
-
width: 360px;
|
64
|
-
height: 100%;
|
65
|
-
flex: auto;
|
66
|
-
}
|
67
|
-
}
|
68
|
-
|
69
|
-
&-operations {
|
70
|
-
button {
|
71
|
-
width: 28px;
|
72
|
-
height: 28px;
|
73
|
-
padding: 0;
|
74
|
-
text-align: center;
|
75
|
-
border-radius: 50%;
|
76
|
-
border: 1px solid transparent;
|
77
|
-
background-color: var(--rp-c-bg-soft);
|
78
|
-
margin-left: 14px;
|
79
|
-
|
80
|
-
&:hover {
|
81
|
-
background-color: var(--rp-preview-button-hover-bg);
|
82
|
-
}
|
83
|
-
}
|
84
|
-
|
85
|
-
svg {
|
86
|
-
display: inline-block;
|
87
|
-
vertical-align: -2px;
|
88
|
-
}
|
89
|
-
|
90
|
-
&.mobile {
|
91
|
-
display: flex;
|
92
|
-
justify-content: flex-end;
|
93
|
-
width: 100%;
|
94
|
-
padding: 6px;
|
95
|
-
}
|
96
|
-
|
97
|
-
&.web {
|
98
|
-
display: flex;
|
99
|
-
justify-content: center;
|
100
|
-
align-items: center;
|
101
|
-
flex: none;
|
102
|
-
}
|
103
|
-
}
|
104
|
-
}
|
File without changes
|