@rspress/plugin-preview 1.46.1 → 1.46.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/package.json +4 -4
- package/static/global-components/ContainerFixedPerComp.tsx +0 -2
- package/static/global-components/Device.scss +4 -10
- package/static/global-components/Device.tsx +17 -51
- package/static/global-components/DeviceFixedPerComp.tsx +18 -52
- package/static/global-styles/entry.css +3 -3
- package/static/global-styles/iframe.css +0 -22
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspress/plugin-preview",
|
|
3
|
-
"version": "1.46.
|
|
3
|
+
"version": "1.46.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": {
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"@rsbuild/plugin-solid": "~1.0.5",
|
|
26
26
|
"lodash": "4.17.21",
|
|
27
27
|
"qrcode.react": "^3.2.0",
|
|
28
|
-
"@rspress/shared": "1.46.
|
|
29
|
-
"@rspress/theme-default": "1.46.
|
|
28
|
+
"@rspress/shared": "1.46.2",
|
|
29
|
+
"@rspress/theme-default": "1.46.2"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@rslib/core": "~0.6.9",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"unist-util-visit": "^4.1.2"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"@rspress/core": "^1.46.
|
|
48
|
+
"@rspress/core": "^1.46.2",
|
|
49
49
|
"react": ">=17.0.0",
|
|
50
50
|
"react-router-dom": "^6.8.1"
|
|
51
51
|
},
|
|
@@ -27,8 +27,6 @@ const MobileContainerFixedPerComp: React.FC<ContainerProps> = props => {
|
|
|
27
27
|
|
|
28
28
|
const setIframeUrl = () => {
|
|
29
29
|
const url = getPageUrl();
|
|
30
|
-
const fixedIframe = document.querySelector('.rspress-fixed-iframe');
|
|
31
|
-
fixedIframe?.setAttribute('src', url);
|
|
32
30
|
publishIframeUrl(url);
|
|
33
31
|
};
|
|
34
32
|
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
.rspress-fixed-device {
|
|
2
2
|
display: none;
|
|
3
3
|
position: fixed;
|
|
4
|
-
top: calc(
|
|
4
|
+
top: calc(
|
|
5
|
+
var(--rp-nav-height) + var(--rp-preview-padding) +
|
|
6
|
+
var(--rp-sidebar-menu-height)
|
|
7
|
+
);
|
|
5
8
|
overflow: hidden;
|
|
6
9
|
}
|
|
7
10
|
|
|
@@ -32,17 +35,8 @@
|
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
@media (min-width: 960px) {
|
|
35
|
-
.rspress-fixed-device {
|
|
36
|
-
display: inline;
|
|
37
|
-
left: calc(1280px - var(--rp-device-width) - var(--rp-preview-padding));
|
|
38
|
-
right: auto;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
@media (min-width: 1280px) {
|
|
43
38
|
.rspress-fixed-device {
|
|
44
39
|
display: inline;
|
|
45
40
|
right: var(--rp-preview-padding);
|
|
46
|
-
left: auto;
|
|
47
41
|
}
|
|
48
42
|
}
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
usePageData,
|
|
4
|
-
useWindowSize,
|
|
5
|
-
withBase,
|
|
6
|
-
} from '@rspress/core/runtime';
|
|
7
|
-
import { useCallback, useEffect, useState } from 'react';
|
|
1
|
+
import { NoSSR, usePageData, withBase } from '@rspress/core/runtime';
|
|
2
|
+
import { useCallback, useState } from 'react';
|
|
8
3
|
// @ts-ignore
|
|
9
4
|
import { normalizeId } from '../../dist/utils';
|
|
10
5
|
import MobileOperation from './common/mobile-operation';
|
|
@@ -21,58 +16,29 @@ export default () => {
|
|
|
21
16
|
if (page?.devPort) {
|
|
22
17
|
return `http://localhost:${page.devPort}/${demoId}`;
|
|
23
18
|
}
|
|
24
|
-
|
|
25
|
-
return `${window.location.origin}${withBase(url)}`;
|
|
26
|
-
}
|
|
27
|
-
// Do nothing in ssr
|
|
28
|
-
return '';
|
|
19
|
+
return withBase(url);
|
|
29
20
|
};
|
|
30
|
-
const [asideWidth, setAsideWidth] = useState('0px');
|
|
31
|
-
const { width: innerWidth } = useWindowSize();
|
|
32
21
|
const [iframeKey, setIframeKey] = useState(0);
|
|
33
22
|
const refresh = useCallback(() => {
|
|
34
23
|
setIframeKey(Math.random());
|
|
35
24
|
}, []);
|
|
36
25
|
|
|
37
|
-
// get default value from root
|
|
38
|
-
// listen resize and re-render
|
|
39
|
-
useEffect(() => {
|
|
40
|
-
const root = document.querySelector(':root');
|
|
41
|
-
if (root) {
|
|
42
|
-
const defaultAsideWidth =
|
|
43
|
-
getComputedStyle(root).getPropertyValue('--rp-aside-width');
|
|
44
|
-
setAsideWidth(defaultAsideWidth);
|
|
45
|
-
}
|
|
46
|
-
}, []);
|
|
47
|
-
|
|
48
|
-
useEffect(() => {
|
|
49
|
-
const node = document.querySelector('.rspress-doc-container');
|
|
50
|
-
const { style } = document.documentElement;
|
|
51
|
-
if (haveDemos) {
|
|
52
|
-
if (innerWidth > 1280) {
|
|
53
|
-
node?.setAttribute(
|
|
54
|
-
'style',
|
|
55
|
-
'padding-right: calc(var(--rp-device-width) + var(--rp-preview-padding) * 2)',
|
|
56
|
-
);
|
|
57
|
-
} else if (innerWidth > 960) {
|
|
58
|
-
node?.setAttribute(
|
|
59
|
-
'style',
|
|
60
|
-
`padding-right: calc(${
|
|
61
|
-
innerWidth - 1280
|
|
62
|
-
}px + var(--rp-device-width) + var(--rp-preview-padding) * 2)`,
|
|
63
|
-
);
|
|
64
|
-
} else {
|
|
65
|
-
node?.removeAttribute('style');
|
|
66
|
-
}
|
|
67
|
-
style.setProperty('--rp-aside-width', '0px');
|
|
68
|
-
} else {
|
|
69
|
-
node?.removeAttribute('style');
|
|
70
|
-
style.setProperty('--rp-aside-width', asideWidth);
|
|
71
|
-
}
|
|
72
|
-
}, [haveDemos, asideWidth, innerWidth]);
|
|
73
|
-
|
|
74
26
|
return haveDemos ? (
|
|
75
27
|
<div className="rspress-fixed-device">
|
|
28
|
+
<style>
|
|
29
|
+
{`
|
|
30
|
+
body {
|
|
31
|
+
--rp-aside-width: 0px;
|
|
32
|
+
}
|
|
33
|
+
@media (min-width: 960px) {
|
|
34
|
+
.rspress-doc-container {
|
|
35
|
+
padding-right: calc(var(--rp-device-width) + var(--rp-preview-padding) * 2);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
`
|
|
39
|
+
.split('\n')
|
|
40
|
+
.join(' ')}
|
|
41
|
+
</style>
|
|
76
42
|
<NoSSR>
|
|
77
43
|
<iframe
|
|
78
44
|
// refresh when load the iframe, then remove NoSSR
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
NoSSR,
|
|
3
|
-
usePageData,
|
|
4
|
-
useWindowSize,
|
|
5
|
-
withBase,
|
|
6
|
-
} from '@rspress/core/runtime';
|
|
1
|
+
import { NoSSR, usePageData, withBase } from '@rspress/core/runtime';
|
|
7
2
|
import { useCallback, useEffect, useState } from 'react';
|
|
8
3
|
// @ts-ignore
|
|
9
4
|
import { normalizeId } from '../../dist/utils';
|
|
@@ -22,11 +17,7 @@ export default () => {
|
|
|
22
17
|
if (page?.devPort) {
|
|
23
18
|
return `http://localhost:${page.devPort}/${demoId}`;
|
|
24
19
|
}
|
|
25
|
-
|
|
26
|
-
return `${window.location.origin}${withBase(url)}`;
|
|
27
|
-
}
|
|
28
|
-
// Do nothing in ssr
|
|
29
|
-
return '';
|
|
20
|
+
return withBase(url);
|
|
30
21
|
};
|
|
31
22
|
|
|
32
23
|
const initialUrl = getPageUrl(url);
|
|
@@ -35,58 +26,33 @@ export default () => {
|
|
|
35
26
|
|
|
36
27
|
const resetIframeUrl = useCallback(() => {
|
|
37
28
|
publishIframeUrl(initialUrl);
|
|
38
|
-
}, [initialUrl
|
|
29
|
+
}, [initialUrl]);
|
|
39
30
|
|
|
40
31
|
useEffect(() => {
|
|
41
32
|
publishIframeUrl(initialUrl);
|
|
42
|
-
}, []);
|
|
33
|
+
}, [initialUrl]);
|
|
43
34
|
|
|
44
|
-
const [asideWidth, setAsideWidth] = useState('0px');
|
|
45
|
-
const { width: innerWidth } = useWindowSize();
|
|
46
35
|
const [iframeKey, setIframeKey] = useState(0);
|
|
47
36
|
const refresh = useCallback(() => {
|
|
48
37
|
setIframeKey(Math.random());
|
|
49
38
|
}, []);
|
|
50
39
|
|
|
51
|
-
// get default value from root
|
|
52
|
-
// listen resize and re-render
|
|
53
|
-
useEffect(() => {
|
|
54
|
-
const root = document.querySelector(':root');
|
|
55
|
-
if (root) {
|
|
56
|
-
const defaultAsideWidth =
|
|
57
|
-
getComputedStyle(root).getPropertyValue('--rp-aside-width');
|
|
58
|
-
setAsideWidth(defaultAsideWidth);
|
|
59
|
-
}
|
|
60
|
-
}, []);
|
|
61
|
-
|
|
62
|
-
useEffect(() => {
|
|
63
|
-
const node = document.querySelector('.rspress-doc-container');
|
|
64
|
-
const { style } = document.documentElement;
|
|
65
|
-
if (haveDemos) {
|
|
66
|
-
if (innerWidth > 1280) {
|
|
67
|
-
node?.setAttribute(
|
|
68
|
-
'style',
|
|
69
|
-
'padding-right: calc(var(--rp-device-width) + var(--rp-preview-padding) * 2)',
|
|
70
|
-
);
|
|
71
|
-
} else if (innerWidth > 960) {
|
|
72
|
-
node?.setAttribute(
|
|
73
|
-
'style',
|
|
74
|
-
`padding-right: calc(${
|
|
75
|
-
innerWidth - 1280
|
|
76
|
-
}px + var(--rp-device-width) + var(--rp-preview-padding) * 2)`,
|
|
77
|
-
);
|
|
78
|
-
} else {
|
|
79
|
-
node?.removeAttribute('style');
|
|
80
|
-
}
|
|
81
|
-
style.setProperty('--rp-aside-width', '0px');
|
|
82
|
-
} else {
|
|
83
|
-
node?.removeAttribute('style');
|
|
84
|
-
style.setProperty('--rp-aside-width', asideWidth);
|
|
85
|
-
}
|
|
86
|
-
}, [haveDemos, asideWidth, innerWidth]);
|
|
87
|
-
|
|
88
40
|
return haveDemos ? (
|
|
89
41
|
<div className="rspress-fixed-device">
|
|
42
|
+
<style>
|
|
43
|
+
{`
|
|
44
|
+
body {
|
|
45
|
+
--rp-aside-width: 0px;
|
|
46
|
+
}
|
|
47
|
+
@media (min-width: 960px) {
|
|
48
|
+
.rspress-doc-container {
|
|
49
|
+
padding-right: calc(var(--rp-device-width) + var(--rp-preview-padding) * 2);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
`
|
|
53
|
+
.split('\n')
|
|
54
|
+
.join(' ')}
|
|
55
|
+
</style>
|
|
90
56
|
<NoSSR>
|
|
91
57
|
<iframe
|
|
92
58
|
// refresh when load the iframe, then remove NoSSR
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
--rp-iframe-nav-bg: #ffffff;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
/*
|
|
6
|
+
.dark {
|
|
7
|
+
/* TODO: support sync dark mode state */
|
|
8
8
|
--rp-iframe-bg: #242424;
|
|
9
9
|
--rp-iframe-nav-bg: #191d24;
|
|
10
|
-
}
|
|
10
|
+
}
|
|
11
11
|
|
|
12
12
|
body {
|
|
13
13
|
background-color: var(--rp-iframe-bg) !important;
|
|
@@ -7,25 +7,3 @@
|
|
|
7
7
|
:root {
|
|
8
8
|
--rp-preview-padding: 32px;
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
@media (min-width: 1280px) {
|
|
12
|
-
.rspress-doc-layout {
|
|
13
|
-
width: calc(100% - var(--rp-preview-padding));
|
|
14
|
-
margin-left: var(--rp-preview-padding);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
.rspress-sidebar {
|
|
18
|
-
margin-left: var(--rp-preview-padding);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
.rspress-doc-nav-container {
|
|
22
|
-
max-width: 100%;
|
|
23
|
-
margin-left: var(--rp-preview-padding);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
.rspress-doc {
|
|
27
|
-
width: 100%;
|
|
28
|
-
padding-left: var(--rp-preview-padding);
|
|
29
|
-
padding-right: var(--rp-preview-padding);
|
|
30
|
-
}
|
|
31
|
-
}
|