@rspress/plugin-preview 1.43.0-canary-20240224 → 1.43.0-canary-202503021457
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
@@ -117,7 +117,7 @@ var __webpack_exports__ = {};
|
|
117
117
|
return (
|
118
118
|
<div className="preview-container">
|
119
119
|
<div className="preview-nav">{"${routes[0].title}"}</div>
|
120
|
-
${routes.map((
|
120
|
+
${routes.map((_demo, index)=>`<Demo_${index} />`).join('\n')}
|
121
121
|
</div>
|
122
122
|
)
|
123
123
|
}
|
@@ -145,6 +145,7 @@ var __webpack_exports__ = {};
|
|
145
145
|
});
|
146
146
|
return sourceEntry;
|
147
147
|
}
|
148
|
+
const node_utils_namespaceObject = require("@rspress/shared/node-utils");
|
148
149
|
const convert = function(test) {
|
149
150
|
if (null == test) return ok;
|
150
151
|
if ('string' == typeof test) return typeFactory(test);
|
@@ -390,20 +391,18 @@ var __webpack_exports__ = {};
|
|
390
391
|
}
|
391
392
|
lib_visit(tree, 'heading', (node)=>{
|
392
393
|
if (1 === node.depth) {
|
393
|
-
|
394
|
-
|
395
|
-
title = (null === (_node_children_ = node.children[0]) || void 0 === _node_children_ ? void 0 : _node_children_.value) || title;
|
396
|
-
}
|
394
|
+
const firstChild = node.children[0];
|
395
|
+
title = firstChild && 'value' in firstChild && firstChild.value || title;
|
397
396
|
}
|
398
397
|
});
|
399
398
|
lib_visit(tree, 'mdxJsxFlowElement', (node)=>{
|
400
399
|
if ('code' === node.name) {
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
const
|
405
|
-
let isMobileMode =
|
406
|
-
isMobileMode = void 0 ===
|
400
|
+
const src = (0, node_utils_namespaceObject.getNodeAttribute)(node, 'src');
|
401
|
+
if ('string' != typeof src) return;
|
402
|
+
const currentMode = (0, node_utils_namespaceObject.getNodeAttribute)(node, 'previewMode') ?? previewMode;
|
403
|
+
const isMobileAttr = (0, node_utils_namespaceObject.getNodeAttribute)(node, 'isMobile');
|
404
|
+
let isMobileMode = false;
|
405
|
+
isMobileMode = void 0 === isMobileAttr ? 'iframe' === currentMode : null === isMobileAttr ? true : 'object' == typeof isMobileAttr ? 'false' !== isMobileAttr.value : 'false' !== isMobileAttr;
|
407
406
|
const id = generateId(pageName, index++);
|
408
407
|
constructDemoNode(id, src, node, isMobileMode, externalDemoIndex++);
|
409
408
|
}
|
@@ -412,12 +411,12 @@ var __webpack_exports__ = {};
|
|
412
411
|
if ('hasVisited' in node) return;
|
413
412
|
if (node.lang && previewLanguages.includes(node.lang)) {
|
414
413
|
var _node_meta, _node_meta1, _node_meta2, _node_meta3, _node_meta4, _node_meta5;
|
415
|
-
if ((null
|
414
|
+
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;
|
416
415
|
const value = injectDemoBlockImport(previewCodeTransform({
|
417
416
|
language: node.lang,
|
418
417
|
code: node.value
|
419
418
|
}), demoBlockComponentPath);
|
420
|
-
const isMobileMode = (null
|
419
|
+
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;
|
421
420
|
const id = generateId(pageName, index++);
|
422
421
|
const virtualModulePath = (0, external_node_path_namespaceObject.join)(virtualDir, `${id}.tsx`);
|
423
422
|
constructDemoNode(id, virtualModulePath, node, isMobileMode);
|
@@ -473,7 +472,7 @@ var __webpack_exports__ = {};
|
|
473
472
|
});
|
474
473
|
});
|
475
474
|
} catch (e) {
|
476
|
-
if ('EADDRINUSE' !== e.code) throw e;
|
475
|
+
if (!!e && 'object' == typeof e && 'code' in e && 'EADDRINUSE' !== e.code) throw e;
|
477
476
|
throw new Error(`Port "${port}" is occupied, please choose another one.`);
|
478
477
|
}
|
479
478
|
},
|
package/index.d.ts
ADDED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@rspress/plugin-preview",
|
3
|
-
"version": "1.43.0-canary-
|
3
|
+
"version": "1.43.0-canary-202503021457",
|
4
4
|
"description": "A plugin for rspress to preview the code block in markdown/mdx file.",
|
5
5
|
"bugs": "https://github.com/web-infra-dev/rspress/issues",
|
6
6
|
"repository": {
|
@@ -10,8 +10,9 @@
|
|
10
10
|
},
|
11
11
|
"license": "MIT",
|
12
12
|
"main": "./dist/index.js",
|
13
|
-
"types": "./
|
13
|
+
"types": "./index.d.ts",
|
14
14
|
"files": [
|
15
|
+
"index.d.ts",
|
15
16
|
"dist",
|
16
17
|
"static"
|
17
18
|
],
|
@@ -24,16 +25,17 @@
|
|
24
25
|
"@rsbuild/plugin-solid": "~1.0.4",
|
25
26
|
"lodash": "4.17.21",
|
26
27
|
"qrcode.react": "^3.2.0",
|
27
|
-
"@rspress/shared": "1.43.0-canary-
|
28
|
-
"@rspress/theme-default": "1.43.0-canary-
|
28
|
+
"@rspress/shared": "1.43.0-canary-202503021457",
|
29
|
+
"@rspress/theme-default": "1.43.0-canary-202503021457"
|
29
30
|
},
|
30
31
|
"devDependencies": {
|
31
|
-
"@rslib/core": "0.
|
32
|
+
"@rslib/core": "0.5.2",
|
32
33
|
"@types/lodash": "^4.17.15",
|
33
34
|
"@types/mdast": "^3.0.15",
|
34
35
|
"@types/node": "^18.11.17",
|
35
36
|
"@types/react": "^18.3.18",
|
36
37
|
"@types/react-dom": "^18.3.5",
|
38
|
+
"mdast-util-mdx-jsx": "^2.1.4",
|
37
39
|
"mdast-util-mdxjs-esm": "^1.3.1",
|
38
40
|
"react": "^18.3.1",
|
39
41
|
"react-dom": "^18.3.1",
|
@@ -43,7 +45,7 @@
|
|
43
45
|
"unist-util-visit": "^4.1.2"
|
44
46
|
},
|
45
47
|
"peerDependencies": {
|
46
|
-
"@rspress/core": "^1.
|
48
|
+
"@rspress/core": "^1.43.0-canary-202503021457",
|
47
49
|
"react": ">=17.0.0",
|
48
50
|
"react-router-dom": "^6.8.1"
|
49
51
|
},
|
@@ -55,7 +57,6 @@
|
|
55
57
|
"provenance": true,
|
56
58
|
"registry": "https://registry.npmjs.org/"
|
57
59
|
},
|
58
|
-
"jsnext:source": "./src/index.ts",
|
59
60
|
"scripts": {
|
60
61
|
"build": "rslib build",
|
61
62
|
"dev": "rslib build -w",
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { NoSSR, useLang, usePageData, withBase } from '@rspress/core/runtime';
|
2
|
-
import { useCallback, useState } from 'react';
|
2
|
+
import { type MouseEvent, useCallback, useState } from 'react';
|
3
3
|
import MobileOperation from './common/mobile-operation';
|
4
4
|
import IconCode from './icons/Code';
|
5
5
|
|
@@ -26,12 +26,15 @@ const Container: React.FC<ContainerProps> = props => {
|
|
26
26
|
// Do nothing in ssr
|
27
27
|
return '';
|
28
28
|
};
|
29
|
-
const toggleCode = (
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
29
|
+
const toggleCode = useCallback(
|
30
|
+
(ev: MouseEvent<HTMLButtonElement>) => {
|
31
|
+
if (!showCode) {
|
32
|
+
ev.currentTarget.blur();
|
33
|
+
}
|
34
|
+
setShowCode(!showCode);
|
35
|
+
},
|
36
|
+
[showCode],
|
37
|
+
);
|
35
38
|
|
36
39
|
const [iframeKey, setIframeKey] = useState(0);
|
37
40
|
const refresh = useCallback(() => {
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { NoSSR, usePageData, withBase } from '@rspress/core/runtime';
|
2
|
-
import { useCallback, useEffect,
|
2
|
+
import { useCallback, useEffect, useState } from 'react';
|
3
3
|
// @ts-ignore
|
4
4
|
import { normalizeId } from '../../dist/utils';
|
5
5
|
import MobileOperation from './common/mobile-operation';
|
@@ -1,6 +1,12 @@
|
|
1
1
|
import { useLang } from '@rspress/core/runtime';
|
2
2
|
import { QRCodeSVG } from 'qrcode.react';
|
3
|
-
import {
|
3
|
+
import {
|
4
|
+
type MouseEventHandler,
|
5
|
+
useCallback,
|
6
|
+
useEffect,
|
7
|
+
useRef,
|
8
|
+
useState,
|
9
|
+
} from 'react';
|
4
10
|
import IconLaunch from '../icons/Launch';
|
5
11
|
import IconQrcode from '../icons/Qrcode';
|
6
12
|
import IconRefresh from '../icons/Refresh';
|
@@ -28,9 +34,9 @@ export default (props: {
|
|
28
34
|
const triggerRef = useRef(null);
|
29
35
|
const t = lang === 'zh' ? locales.zh : locales.en;
|
30
36
|
|
31
|
-
const toggleQRCode =
|
37
|
+
const toggleQRCode: MouseEventHandler<HTMLButtonElement> = e => {
|
32
38
|
if (!showQRCode) {
|
33
|
-
e.
|
39
|
+
e.currentTarget.blur();
|
34
40
|
}
|
35
41
|
setShowQRCode(!showQRCode);
|
36
42
|
};
|
@@ -38,7 +44,7 @@ export default (props: {
|
|
38
44
|
window.open(url);
|
39
45
|
};
|
40
46
|
|
41
|
-
const contains = function (root: HTMLElement | null, ele:
|
47
|
+
const contains = function (root: HTMLElement | null, ele: Node | null) {
|
42
48
|
if (!root) {
|
43
49
|
return false;
|
44
50
|
}
|
@@ -56,8 +62,8 @@ export default (props: {
|
|
56
62
|
};
|
57
63
|
|
58
64
|
const onClickOutside = useCallback(
|
59
|
-
(
|
60
|
-
if (!contains(triggerRef.current,
|
65
|
+
(ev: MouseEvent) => {
|
66
|
+
if (!contains(triggerRef.current, ev.target as Node)) {
|
61
67
|
setShowQRCode(false);
|
62
68
|
}
|
63
69
|
},
|