@rspress/plugin-preview 2.0.0-alpha.0 → 2.0.0-alpha.10

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
@@ -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 = function(exports1) {
41
+ __webpack_require__.r = (exports1)=>{
42
42
  if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
43
43
  value: 'Module'
44
44
  });
@@ -142,9 +142,9 @@ var __webpack_exports__ = {};
142
142
  const node_utils_namespaceObject = require("@rspress/shared/node-utils");
143
143
  const convert = function(test) {
144
144
  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
145
  if ('function' == typeof test) return castFactory(test);
146
+ if ('object' == typeof test) return Array.isArray(test) ? anyFactory(test) : propsFactory(test);
147
+ if ('string' == typeof test) return typeFactory(test);
148
148
  throw new Error('Expected function, string, or object as test');
149
149
  };
150
150
  function anyFactory(tests) {
@@ -154,15 +154,17 @@ var __webpack_exports__ = {};
154
154
  return castFactory(any);
155
155
  function any(...parameters) {
156
156
  let index = -1;
157
- while(++index < checks.length)if (checks[index].call(this, ...parameters)) return true;
157
+ while(++index < checks.length)if (checks[index].apply(this, parameters)) return true;
158
158
  return false;
159
159
  }
160
160
  }
161
161
  function propsFactory(check) {
162
+ const checkAsRecord = check;
162
163
  return castFactory(all);
163
164
  function all(node) {
165
+ const nodeAsRecord = node;
164
166
  let key;
165
- for(key in check)if (node[key] !== check[key]) return false;
167
+ for(key in check)if (nodeAsRecord[key] !== checkAsRecord[key]) return false;
166
168
  return true;
167
169
  }
168
170
  }
@@ -172,28 +174,32 @@ var __webpack_exports__ = {};
172
174
  return node && node.type === check;
173
175
  }
174
176
  }
175
- function castFactory(check) {
176
- return assertion;
177
- function assertion(node, ...parameters) {
178
- return Boolean(node && 'object' == typeof node && 'type' in node && Boolean(check.call(this, node, ...parameters)));
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));
179
181
  }
180
182
  }
181
183
  function ok() {
182
184
  return true;
183
185
  }
186
+ function looksLikeANode(value) {
187
+ return null !== value && 'object' == typeof value && 'type' in value;
188
+ }
184
189
  function color(d) {
185
190
  return '\u001B[33m' + d + '\u001B[39m';
186
191
  }
192
+ const empty = [];
187
193
  const CONTINUE = true;
188
194
  const EXIT = false;
189
195
  const SKIP = 'skip';
190
- const visitParents = function(tree, test, visitor, reverse) {
196
+ function visitParents(tree, test, visitor, reverse) {
197
+ let check;
191
198
  if ('function' == typeof test && 'function' != typeof visitor) {
192
199
  reverse = visitor;
193
200
  visitor = test;
194
- test = null;
195
- }
196
- const is = convert(test);
201
+ } else check = test;
202
+ const is = convert(check);
197
203
  const step = reverse ? -1 : 1;
198
204
  factory(tree, void 0, [])();
199
205
  function factory(node, index, parents) {
@@ -206,49 +212,61 @@ var __webpack_exports__ = {};
206
212
  }
207
213
  return visit;
208
214
  function visit() {
209
- let result = [];
215
+ let result = empty;
210
216
  let subresult;
211
217
  let offset;
212
218
  let grandparents;
213
- if (!test || is(node, index, parents[parents.length - 1] || null)) {
219
+ if (!test || is(node, index, parents[parents.length - 1] || void 0)) {
214
220
  result = toResult(visitor(node, parents));
215
221
  if (result[0] === EXIT) return result;
216
222
  }
217
- if (node.children && result[0] !== SKIP) {
218
- offset = (reverse ? node.children.length : -1) + step;
219
- grandparents = parents.concat(node);
220
- while(offset > -1 && offset < node.children.length){
221
- subresult = factory(node.children[offset], offset, grandparents)();
222
- if (subresult[0] === EXIT) return subresult;
223
- offset = 'number' == typeof subresult[1] ? subresult[1] : offset + step;
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
+ }
224
234
  }
225
235
  }
226
236
  return result;
227
237
  }
228
238
  }
229
- };
239
+ }
230
240
  function toResult(value) {
231
241
  if (Array.isArray(value)) return value;
232
242
  if ('number' == typeof value) return [
233
243
  CONTINUE,
234
244
  value
235
245
  ];
236
- return [
246
+ return null == value ? empty : [
237
247
  value
238
248
  ];
239
249
  }
240
- const lib_visit = function(tree, test, visitor, reverse) {
241
- if ('function' == typeof test && 'function' != typeof visitor) {
242
- reverse = visitor;
243
- visitor = test;
244
- test = null;
250
+ function lib_visit(tree, testOrVisitor, visitorOrReverse, maybeReverse) {
251
+ let reverse;
252
+ let test;
253
+ let visitor;
254
+ if ('function' == typeof testOrVisitor && 'function' != typeof visitorOrReverse) {
255
+ test = void 0;
256
+ visitor = testOrVisitor;
257
+ reverse = visitorOrReverse;
258
+ } else {
259
+ test = testOrVisitor;
260
+ visitor = visitorOrReverse;
261
+ reverse = maybeReverse;
245
262
  }
246
263
  visitParents(tree, test, overload, reverse);
247
264
  function overload(node, parents) {
248
265
  const parent = parents[parents.length - 1];
249
- return visitor(node, parent ? parent.children.indexOf(node) : null, parent);
266
+ const index = parent ? parent.children.indexOf(node) : void 0;
267
+ return visitor(node, index, parent);
250
268
  }
251
- };
269
+ }
252
270
  const getASTNodeImport = (name, from)=>({
253
271
  type: 'mdxjsEsm',
254
272
  value: `import ${name} from ${JSON.stringify(from)}`,
@@ -590,8 +608,10 @@ var __webpack_exports__ = {};
590
608
  };
591
609
  }
592
610
  })();
593
- var __webpack_export_target__ = exports;
594
- for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
595
- if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
611
+ exports.pluginPreview = __webpack_exports__.pluginPreview;
612
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
613
+ "pluginPreview"
614
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
615
+ Object.defineProperty(exports, '__esModule', {
596
616
  value: true
597
617
  });
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 = function(exports1) {
15
+ __webpack_require__.r = (exports1)=>{
16
16
  if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
17
  value: 'Module'
18
18
  });
@@ -42,8 +42,16 @@ const injectDemoBlockImport = (str, path)=>`
42
42
  import DemoBlock from ${JSON.stringify(path)};
43
43
  ${str}
44
44
  `;
45
- var __webpack_export_target__ = exports;
46
- for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
47
- if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
45
+ exports.generateId = __webpack_exports__.generateId;
46
+ exports.injectDemoBlockImport = __webpack_exports__.injectDemoBlockImport;
47
+ exports.normalizeId = __webpack_exports__.normalizeId;
48
+ exports.toValidVarName = __webpack_exports__.toValidVarName;
49
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
50
+ "generateId",
51
+ "injectDemoBlockImport",
52
+ "normalizeId",
53
+ "toValidVarName"
54
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
55
+ Object.defineProperty(exports, '__esModule', {
48
56
  value: true
49
57
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspress/plugin-preview",
3
- "version": "2.0.0-alpha.0",
3
+ "version": "2.0.0-alpha.10",
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.2.15",
20
+ "@rsbuild/core": "1.3.4",
21
21
  "@rsbuild/plugin-babel": "~1.0.4",
22
- "@rsbuild/plugin-less": "~1.1.1",
22
+ "@rsbuild/plugin-less": "~1.2.2",
23
23
  "@rsbuild/plugin-react": "~1.1.1",
24
- "@rsbuild/plugin-sass": "~1.2.2",
24
+ "@rsbuild/plugin-sass": "~1.3.1",
25
25
  "@rsbuild/plugin-solid": "~1.0.5",
26
26
  "lodash": "4.17.21",
27
- "qrcode.react": "^3.2.0",
28
- "@rspress/shared": "2.0.0-alpha.0",
29
- "@rspress/theme-default": "2.0.0-alpha.0"
27
+ "qrcode.react": "^4.2.0",
28
+ "@rspress/shared": "2.0.0-alpha.10",
29
+ "@rspress/theme-default": "2.0.0-alpha.10"
30
30
  },
31
31
  "devDependencies": {
32
- "@rslib/core": "0.5.3",
32
+ "@rslib/core": "0.6.1",
33
33
  "@types/lodash": "^4.17.16",
34
- "@types/mdast": "^3.0.15",
34
+ "@types/mdast": "^4.0.4",
35
35
  "@types/node": "^18.11.17",
36
- "@types/react": "^18.3.18",
37
- "@types/react-dom": "^18.3.5",
38
- "mdast-util-mdx-jsx": "^2.1.4",
39
- "mdast-util-mdxjs-esm": "^1.3.1",
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.5.3",
44
- "unified": "^10.1.2",
45
- "unist-util-visit": "^4.1.2"
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.0",
48
+ "@rspress/core": "^2.0.0-alpha.10",
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
- &-title {
13
- padding: 12px 12px 8px;
14
- color: #697b8c;
15
- font-size: 14px;
16
- }
17
- &-main {
18
- border-right: none;
19
- border-left: none;
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,4 +1,4 @@
1
- import './DemoBlock.scss';
1
+ import './DemoBlock.css';
2
2
 
3
3
  interface Props {
4
4
  title: string;
@@ -1,9 +1,14 @@
1
- import { NoSSR, usePageData, withBase } from '@rspress/core/runtime';
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.scss';
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 [innerWidth, setInnerWidth] = useState(initialInnerWidth);
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
+ }
@@ -10,7 +10,7 @@ import {
10
10
  import IconLaunch from '../icons/Launch';
11
11
  import IconQrcode from '../icons/Qrcode';
12
12
  import IconRefresh from '../icons/Refresh';
13
- import './index.scss';
13
+ import './index.css';
14
14
 
15
15
  const locales = {
16
16
  zh: {
@@ -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
- }