@rspress/plugin-preview 2.0.0-alpha.7 → 2.0.0-alpha.9
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 +53 -33
- package/dist/utils.js +11 -3
- package/package.json +15 -15
- package/static/global-components/Device.tsx +7 -9
package/dist/index.js
CHANGED
@@ -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].
|
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 (
|
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(
|
176
|
-
return
|
177
|
-
function
|
178
|
-
return Boolean(
|
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
|
-
|
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
|
-
|
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] ||
|
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 (
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
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
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
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
|
-
|
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
|
-
|
594
|
-
for(var __webpack_i__ in __webpack_exports__)
|
595
|
-
|
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
@@ -42,8 +42,16 @@ const injectDemoBlockImport = (str, path)=>`
|
|
42
42
|
import DemoBlock from ${JSON.stringify(path)};
|
43
43
|
${str}
|
44
44
|
`;
|
45
|
-
|
46
|
-
|
47
|
-
|
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.
|
3
|
+
"version": "2.0.0-alpha.9",
|
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.
|
20
|
+
"@rsbuild/core": "1.3.4",
|
21
21
|
"@rsbuild/plugin-babel": "~1.0.4",
|
22
|
-
"@rsbuild/plugin-less": "~1.
|
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
27
|
"qrcode.react": "^4.2.0",
|
28
|
-
"@rspress/
|
29
|
-
"@rspress/
|
28
|
+
"@rspress/shared": "2.0.0-alpha.9",
|
29
|
+
"@rspress/theme-default": "2.0.0-alpha.9"
|
30
30
|
},
|
31
31
|
"devDependencies": {
|
32
|
-
"@rslib/core": "0.
|
32
|
+
"@rslib/core": "0.6.1",
|
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
43
|
"typescript": "^5.8.2",
|
44
|
-
"unified": "^
|
45
|
-
"unist-util-visit": "^
|
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.9",
|
49
49
|
"react": ">=17.0.0",
|
50
50
|
"react-router-dom": "^6.8.1"
|
51
51
|
},
|
@@ -1,4 +1,9 @@
|
|
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';
|
@@ -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(() => {
|