@rspress/plugin-preview 2.0.0-rc.0 → 2.0.0-rc.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.
@@ -1,92 +0,0 @@
1
- import { NoSSR, useLang, usePageData, withBase } from '@rspress/core/runtime';
2
- import { type MouseEvent, useCallback, useState } from 'react';
3
- import MobileOperation from './common/mobile-operation';
4
- import IconCode from './icons/Code';
5
-
6
- type ContainerProps = {
7
- children: React.ReactNode[];
8
- isMobile: 'true' | 'false';
9
- demoId: string;
10
- };
11
-
12
- const Container: React.FC<ContainerProps> = props => {
13
- const { children, isMobile, demoId } = props;
14
- const { page } = usePageData();
15
- const [showCode, setShowCode] = useState(false);
16
- const lang = useLang();
17
- const url = `/~demo/${demoId}`;
18
-
19
- const getPageUrl = () => {
20
- if (page?.devPort) {
21
- return `http://localhost:${page.devPort}/${demoId}`;
22
- }
23
- if (typeof window !== 'undefined') {
24
- return `${window.location.origin}${withBase(url)}`;
25
- }
26
- // Do nothing in ssr
27
- return '';
28
- };
29
- const toggleCode = useCallback(
30
- (ev: MouseEvent<HTMLButtonElement>) => {
31
- if (!showCode) {
32
- ev.currentTarget.blur();
33
- }
34
- setShowCode(!showCode);
35
- },
36
- [showCode],
37
- );
38
-
39
- const [iframeKey, setIframeKey] = useState(0);
40
- const refresh = useCallback(() => {
41
- setIframeKey(Math.random());
42
- }, []);
43
-
44
- return (
45
- <NoSSR>
46
- <div className="rspress-preview rp-not-doc">
47
- {isMobile === 'true' ? (
48
- <div className="rspress-preview-wrapper" style={{ display: 'flex' }}>
49
- <div className="rspress-preview-code">{children?.[0]}</div>
50
- <div className="rspress-preview-device">
51
- <iframe src={getPageUrl()} key={iframeKey}></iframe>
52
- <MobileOperation url={getPageUrl()} refresh={refresh} />
53
- </div>
54
- </div>
55
- ) : (
56
- <div>
57
- <div className="rspress-preview-card">
58
- <div
59
- style={{
60
- overflow: 'auto',
61
- flex: 'auto',
62
- }}
63
- >
64
- {children?.[1]}
65
- </div>
66
- <div className="rspress-preview-operations web">
67
- <button
68
- onClick={toggleCode}
69
- aria-label={lang === 'zh' ? '收起代码' : 'Collapse Code'}
70
- className={showCode ? 'button-expanded' : ''}
71
- >
72
- <IconCode />
73
- </button>
74
- </div>
75
- </div>
76
- <div
77
- className={`${
78
- showCode
79
- ? 'rspress-preview-code-show'
80
- : 'rspress-preview-code-hide'
81
- }`}
82
- >
83
- {children?.[0]}
84
- </div>
85
- </div>
86
- )}
87
- </div>
88
- </NoSSR>
89
- );
90
- };
91
-
92
- export default Container;
@@ -1,23 +0,0 @@
1
- :root {
2
- --rp-demo-block-bg: #f7f8fa;
3
- }
4
-
5
- .dark {
6
- --rp-demo-block-bg: #1a1a1a;
7
- }
8
-
9
- .rspress-demo-block {
10
- padding-bottom: 12px;
11
- background-color: var(--rp-demo-block-bg);
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;
23
- }
@@ -1,16 +0,0 @@
1
- import './DemoBlock.css';
2
-
3
- interface Props {
4
- title: string;
5
- children?: React.ReactNode;
6
- }
7
-
8
- export default (props: Props) => {
9
- const { title, children } = props;
10
- return (
11
- <div className="rspress-demo-block">
12
- <div className="rspress-demo-block-title">{title}</div>
13
- <div className="rspress-demo-block-main">{children}</div>
14
- </div>
15
- );
16
- };
@@ -1,76 +0,0 @@
1
- import {
2
- NoSSR,
3
- usePageData,
4
- useWindowSize,
5
- withBase,
6
- } from '@rspress/core/runtime';
7
- import { useCallback, useEffect, useState } from 'react';
8
- // @ts-expect-error
9
- import { normalizeId } from '../../dist/utils';
10
- import MobileOperation from './common/mobile-operation';
11
- import './Device.css';
12
-
13
- export default () => {
14
- const { page } = usePageData();
15
- const pageName = `${normalizeId(page.pagePath)}`;
16
- const demoId = `_${pageName}`;
17
- const url = `~demo/${demoId}`;
18
- const { haveDemos } = page;
19
-
20
- const getPageUrl = (url: string) => {
21
- if (page?.devPort) {
22
- return `http://localhost:${page.devPort}/${demoId}`;
23
- }
24
- if (typeof window !== 'undefined') {
25
- return `${window.location.origin}${withBase(url)}`;
26
- }
27
- // Do nothing in ssr
28
- return '';
29
- };
30
- const { width: innerWidth } = useWindowSize();
31
- const [iframeKey, setIframeKey] = useState(0);
32
- const refresh = useCallback(() => {
33
- setIframeKey(Math.random());
34
- }, []);
35
-
36
- useEffect(() => {
37
- const node = document.querySelector('.rspress-doc-container');
38
- if (haveDemos) {
39
- if (innerWidth > 1280) {
40
- node?.setAttribute(
41
- 'style',
42
- 'padding-right: calc(var(--rp-device-width) + var(--rp-preview-padding) * 2)',
43
- );
44
- } else if (innerWidth > 960) {
45
- node?.setAttribute(
46
- 'style',
47
- `padding-right: calc(${
48
- innerWidth - 1280
49
- }px + var(--rp-device-width) + var(--rp-preview-padding) * 2)`,
50
- );
51
- } else {
52
- node?.removeAttribute('style');
53
- }
54
- } else {
55
- node?.removeAttribute('style');
56
- }
57
- }, [haveDemos, innerWidth]);
58
-
59
- return haveDemos ? (
60
- <div className="fixed-device">
61
- <NoSSR>
62
- <iframe
63
- // refresh when load the iframe, then remove NoSSR
64
- src={getPageUrl(url)}
65
- className="fixed-iframe"
66
- key={iframeKey}
67
- ></iframe>
68
- </NoSSR>
69
- <MobileOperation
70
- url={getPageUrl(url)}
71
- className="fixed-operation"
72
- refresh={refresh}
73
- />
74
- </div>
75
- ) : null;
76
- };
@@ -1,103 +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
-
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
- }
@@ -1,31 +0,0 @@
1
- :root .rspress-preview div[class*='language-'] {
2
- margin: 0;
3
- border-radius: 0;
4
- height: 100%;
5
- }
6
-
7
- :root {
8
- --rp-preview-padding: 32px;
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
- }
@@ -1,5 +0,0 @@
1
- :root .rspress-preview div[class*='language-'] {
2
- margin: 0;
3
- border-radius: 0;
4
- height: 100%;
5
- }