@rspress/plugin-preview 2.0.0-beta.3 → 2.0.0-beta.30

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/README.md CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  > Preview plugin for rspress
4
4
 
5
- [Documentation](https://rspress.dev/plugin/official-plugins/preview)
5
+ [Documentation](https://rspress.rs/plugin/official-plugins/preview)
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { RsbuildConfig } from '@rsbuild/core';
2
- import { RspressPlugin } from '@rspress/shared';
2
+ import { RspressPlugin } from '@rspress/core';
3
3
 
4
4
  declare interface CustomEntry {
5
5
  entryCssPath: string;
package/dist/index.js CHANGED
@@ -1,16 +1,15 @@
1
- import * as __WEBPACK_EXTERNAL_MODULE_node_net_0373943e__ from "node:net";
2
- import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
3
- import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ from "@rsbuild/core";
4
- import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_babel_2a5a8b08__ from "@rsbuild/plugin-babel";
5
- import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_react_7b149ee4__ from "@rsbuild/plugin-react";
6
- import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_solid_0a0a2645__ from "@rsbuild/plugin-solid";
7
- import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__ from "@rspress/shared";
8
- import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash";
9
- import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs";
10
- import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__ from "@rspress/shared/node-utils";
11
- const staticPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(__dirname, '..', 'static');
12
- const demoBlockComponentPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(staticPath, 'global-components', 'DemoBlock.tsx');
13
- const virtualDir = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(process.cwd(), 'node_modules', __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.RSPRESS_TEMP_DIR, 'virtual-demo');
1
+ import node_net from "node:net";
2
+ import node_path, { dirname, join, resolve as external_node_path_resolve } from "node:path";
3
+ import { createRsbuild, mergeRsbuildConfig } from "@rsbuild/core";
4
+ import { pluginBabel } from "@rsbuild/plugin-babel";
5
+ import { pluginReact } from "@rsbuild/plugin-react";
6
+ import { pluginSolid } from "@rsbuild/plugin-solid";
7
+ import { RSPRESS_TEMP_DIR, normalizePosixPath, removeTrailingSlash } from "@rspress/core";
8
+ import { cloneDeep, isEqual } from "lodash";
9
+ import node_fs, { writeFileSync } from "node:fs";
10
+ const staticPath = node_path.join(__dirname, '..', 'static');
11
+ const demoBlockComponentPath = node_path.join(staticPath, 'global-components', 'DemoBlock.tsx');
12
+ const virtualDir = node_path.join(process.cwd(), 'node_modules', RSPRESS_TEMP_DIR, 'virtual-demo');
14
13
  const toValidVarName = (str)=>{
15
14
  if (/^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(str)) return str;
16
15
  return str.replace(/[^0-9a-zA-Z_$]/g, '_').replace(/^([0-9])/, '_$1');
@@ -33,11 +32,11 @@ const getLangFileExt = (lang)=>{
33
32
  };
34
33
  function generateEntry(demos, framework, position, customEntry) {
35
34
  const sourceEntry = {};
36
- const entryCssPath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(staticPath, 'global-styles', 'entry.css');
35
+ const entryCssPath = join(staticPath, 'global-styles', 'entry.css');
37
36
  if ('follow' === position) Object.values(demos).forEach((routes)=>{
38
37
  routes.forEach((route)=>{
39
38
  const { id, path: demoPath } = route;
40
- const entry = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(virtualDir, `${id}.entry.tsx`);
39
+ const entry = join(virtualDir, `${id}.entry.tsx`);
41
40
  const solidEntry = `
42
41
  import { render } from 'solid-js/web';
43
42
  import ${JSON.stringify(entryCssPath)};
@@ -55,7 +54,7 @@ function generateEntry(demos, framework, position, customEntry) {
55
54
  entryCssPath,
56
55
  demoPath
57
56
  }) : 'react' === framework ? reactEntry : solidEntry;
58
- (0, __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.writeFileSync)(entry, entryContent);
57
+ writeFileSync(entry, entryContent);
59
58
  sourceEntry[id] = entry;
60
59
  });
61
60
  });
@@ -92,8 +91,8 @@ function generateEntry(demos, framework, position, customEntry) {
92
91
  `;
93
92
  const renderContent = 'solid' === framework ? solidContent : reactContent;
94
93
  const id = `_${toValidVarName(key)}`;
95
- const entry = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(virtualDir, `${id}.entry.tsx`);
96
- (0, __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.writeFileSync)(entry, renderContent);
94
+ const entry = join(virtualDir, `${id}.entry.tsx`);
95
+ writeFileSync(entry, renderContent);
97
96
  sourceEntry[id] = entry;
98
97
  });
99
98
  return sourceEntry;
@@ -304,26 +303,25 @@ const getExternalDemoContent = (tempVar)=>({
304
303
  const remarkPlugin_demos = {};
305
304
  const remarkCodeToDemo = function({ getRouteMeta, previewMode, defaultRenderMode, position, previewLanguages, previewCodeTransform }) {
306
305
  const routeMeta = getRouteMeta();
307
- __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].mkdirSync(virtualDir, {
306
+ node_fs.mkdirSync(virtualDir, {
308
307
  recursive: true
309
308
  });
310
309
  const data = this.data();
311
310
  return (tree, vfile)=>{
312
311
  const demoMdx = [];
313
- const route = routeMeta.find((meta)=>(0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.normalizePosixPath)(meta.absolutePath) === (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.normalizePosixPath)(vfile.path || vfile.history[0]));
312
+ const route = routeMeta.find((meta)=>normalizePosixPath(meta.absolutePath) === normalizePosixPath(vfile.path || vfile.history[0]));
314
313
  if (!route) return;
315
314
  const { pageName } = route;
316
315
  remarkPlugin_demos[pageName] = [];
317
316
  let title = pageName;
318
317
  let index = 1;
319
- let externalDemoIndex = 0;
320
318
  function constructDemoNode(demoId, demoPath, currentNode, isMobileMode, externalDemoIndex) {
321
319
  if (isMobileMode) {
322
320
  const relativePathReg = new RegExp(/^\.\.?\/.*$/);
323
321
  remarkPlugin_demos[pageName].push({
324
322
  title,
325
323
  id: demoId,
326
- path: relativePathReg.test(demoPath) ? (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.resolve)(vfile.dirname || (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.dirname)(vfile.path), demoPath) : demoPath
324
+ path: relativePathReg.test(demoPath) ? external_node_path_resolve(vfile.dirname || dirname(vfile.path), demoPath) : demoPath
327
325
  });
328
326
  } else demoMdx.push(getASTNodeImport(`Demo${demoId}`, demoPath));
329
327
  const tempVar = `externalDemoContent${externalDemoIndex}`;
@@ -365,18 +363,6 @@ const remarkCodeToDemo = function({ getRouteMeta, previewMode, defaultRenderMode
365
363
  title = firstChild && 'value' in firstChild && firstChild.value || title;
366
364
  }
367
365
  });
368
- lib_visit(tree, 'mdxJsxFlowElement', (node)=>{
369
- if ('code' === node.name) {
370
- const src = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.getNodeAttribute)(node, 'src');
371
- if ('string' != typeof src) return;
372
- const currentMode = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.getNodeAttribute)(node, 'previewMode') ?? previewMode;
373
- const isMobileAttr = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.getNodeAttribute)(node, 'isMobile');
374
- let isMobileMode = false;
375
- isMobileMode = void 0 === isMobileAttr ? 'iframe' === currentMode : null === isMobileAttr ? true : 'object' == typeof isMobileAttr ? 'false' !== isMobileAttr.value : 'false' !== isMobileAttr;
376
- const id = generateId(pageName, index++);
377
- constructDemoNode(id, src, node, isMobileMode, externalDemoIndex++);
378
- }
379
- });
380
366
  lib_visit(tree, 'code', (node)=>{
381
367
  if ('hasVisited' in node) return;
382
368
  if (node.lang && previewLanguages.includes(node.lang)) {
@@ -391,13 +377,13 @@ const remarkCodeToDemo = function({ getRouteMeta, previewMode, defaultRenderMode
391
377
  });
392
378
  const isMobileMode = node.meta?.includes('mobile') || node.meta?.includes('iframe') || !node.meta?.includes('web') && !node.meta?.includes('internal') && 'iframe' === previewMode;
393
379
  const id = generateId(pageName, index++);
394
- const virtualModulePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(virtualDir, `${id}.${getLangFileExt(node.lang)}`);
380
+ const virtualModulePath = join(virtualDir, `${id}.${getLangFileExt(node.lang)}`);
395
381
  constructDemoNode(id, virtualModulePath, node, isMobileMode);
396
- if (__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].existsSync(virtualModulePath)) {
397
- const content = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].readFileSync(virtualModulePath, 'utf-8');
382
+ if (node_fs.existsSync(virtualModulePath)) {
383
+ const content = node_fs.readFileSync(virtualModulePath, 'utf-8');
398
384
  if (content === value) return;
399
385
  }
400
- __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].writeFileSync(virtualModulePath, value);
386
+ node_fs.writeFileSync(virtualModulePath, value);
401
387
  }
402
388
  });
403
389
  tree.children.unshift(...demoMdx);
@@ -414,7 +400,7 @@ function pluginPreview(options) {
414
400
  const previewMode = options?.previewMode ?? (isMobile ? 'iframe' : 'internal');
415
401
  const { devPort = 7890, framework = 'react', position = iframePosition, builderConfig = {}, customEntry } = iframeOptions;
416
402
  const globalUIComponents = 'fixed' === position ? [
417
- (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(staticPath, 'global-components', 'Device.tsx')
403
+ join(staticPath, 'global-components', 'Device.tsx')
418
404
  ] : [];
419
405
  const getRouteMeta = ()=>src_routeMeta;
420
406
  let lastDemos;
@@ -433,7 +419,7 @@ function pluginPreview(options) {
433
419
  async beforeBuild (_, isProd) {
434
420
  if (!isProd) try {
435
421
  await new Promise((resolve, reject)=>{
436
- const server = __WEBPACK_EXTERNAL_MODULE_node_net_0373943e__["default"].createServer();
422
+ const server = node_net.createServer();
437
423
  server.unref();
438
424
  server.on('error', reject);
439
425
  server.listen({
@@ -449,26 +435,27 @@ function pluginPreview(options) {
449
435
  }
450
436
  },
451
437
  async afterBuild (config, isProd) {
452
- if ((0, __WEBPACK_EXTERNAL_MODULE_lodash__.isEqual)(remarkPlugin_demos, lastDemos)) return;
453
- lastDemos = (0, __WEBPACK_EXTERNAL_MODULE_lodash__.cloneDeep)(remarkPlugin_demos);
438
+ if (isEqual(remarkPlugin_demos, lastDemos)) return;
439
+ lastDemos = cloneDeep(remarkPlugin_demos);
454
440
  await devServer?.server?.close();
455
441
  devServer = void 0;
456
442
  const sourceEntry = generateEntry(remarkPlugin_demos, framework, position, customEntry);
457
- const outDir = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(config.outDir ?? 'doc_build', '~demo');
443
+ const outDir = join(config.outDir ?? 'doc_build', '~demo');
458
444
  if (0 === Object.keys(sourceEntry).length) return;
459
445
  const { html, source, output, performance } = clientConfig ?? {};
460
- const rsbuildConfig = (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.mergeRsbuildConfig)({
461
- dev: {
462
- progressBar: false
463
- },
446
+ const rsbuildConfig = mergeRsbuildConfig({
464
447
  server: {
465
448
  port: devPort,
466
449
  printUrls: ()=>void 0,
467
450
  strictPort: true
468
451
  },
452
+ dev: {
453
+ lazyCompilation: false
454
+ },
469
455
  performance: {
470
456
  ...performance,
471
- printFileSize: false
457
+ printFileSize: false,
458
+ buildCache: false
472
459
  },
473
460
  html,
474
461
  source: {
@@ -477,31 +464,25 @@ function pluginPreview(options) {
477
464
  },
478
465
  output: {
479
466
  ...output,
480
- assetPrefix: output?.assetPrefix ? `${(0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.removeTrailingSlash)(output.assetPrefix)}/~demo` : '/~demo',
467
+ assetPrefix: output?.assetPrefix ? `${removeTrailingSlash(output.assetPrefix)}/~demo` : '/~demo',
481
468
  distPath: {
482
469
  root: outDir
483
470
  },
484
471
  copy: void 0
485
- },
486
- plugins: config?.builderPlugins
472
+ }
487
473
  }, builderConfig);
488
- const rsbuildInstance = await (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.createRsbuild)({
474
+ const rsbuildInstance = await createRsbuild({
475
+ callerName: 'rspress',
489
476
  rsbuildConfig
490
477
  });
491
- const { pluginSass } = await import("@rsbuild/plugin-sass");
492
- const { pluginLess } = await import("@rsbuild/plugin-less");
493
- rsbuildInstance.addPlugins([
494
- pluginSass(),
495
- pluginLess()
496
- ]);
497
478
  if ('solid' === framework) rsbuildInstance.addPlugins([
498
- (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_babel_2a5a8b08__.pluginBabel)({
479
+ pluginBabel({
499
480
  include: /\.(?:jsx|tsx)$/
500
481
  }),
501
- (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_solid_0a0a2645__.pluginSolid)()
482
+ pluginSolid()
502
483
  ]);
503
484
  if ('react' === framework) rsbuildInstance.addPlugins([
504
- (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_react_7b149ee4__.pluginReact)()
485
+ pluginReact()
505
486
  ]);
506
487
  if (isProd) rsbuildInstance.build();
507
488
  else devServer = await rsbuildInstance.startDevServer();
@@ -509,7 +490,7 @@ function pluginPreview(options) {
509
490
  builderConfig: {
510
491
  source: {
511
492
  include: [
512
- (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(__dirname, '..')
493
+ join(__dirname, '..')
513
494
  ]
514
495
  },
515
496
  tools: {
@@ -540,7 +521,6 @@ function pluginPreview(options) {
540
521
  },
541
522
  extendPageData (pageData, isProd) {
542
523
  if (!isProd) pageData.devPort = port;
543
- pageData.extraHighlightLanguages = previewLanguages;
544
524
  },
545
525
  markdown: {
546
526
  remarkPlugins: [
@@ -557,11 +537,11 @@ function pluginPreview(options) {
557
537
  ]
558
538
  ],
559
539
  globalComponents: [
560
- (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(staticPath, 'global-components', 'Container.tsx')
540
+ join(staticPath, 'global-components', 'Container.tsx')
561
541
  ]
562
542
  },
563
543
  globalUIComponents,
564
- globalStyles: (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(staticPath, 'global-styles', `${previewMode}.css`)
544
+ globalStyles: join(staticPath, 'global-styles', `${previewMode}.css`)
565
545
  };
566
546
  }
567
547
  export { pluginPreview };
package/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- declare module '@rspress/shared' {
1
+ declare module '@rspress/core' {
2
2
  interface PageIndexInfo {
3
3
  devPort?: number;
4
- extraHighlightLanguages?: string[];
5
4
  }
6
5
  }
7
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspress/plugin-preview",
3
- "version": "2.0.0-beta.3",
3
+ "version": "2.0.0-beta.30",
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": {
@@ -23,36 +23,32 @@
23
23
  "static"
24
24
  ],
25
25
  "dependencies": {
26
- "@rsbuild/core": "1.3.13",
27
- "@rsbuild/plugin-babel": "~1.0.5",
28
- "@rsbuild/plugin-less": "~1.2.2",
29
- "@rsbuild/plugin-react": "~1.1.1",
30
- "@rsbuild/plugin-sass": "~1.3.1",
31
- "@rsbuild/plugin-solid": "~1.0.5",
26
+ "@rsbuild/core": "~1.5.3",
27
+ "@rsbuild/plugin-babel": "~1.0.6",
28
+ "@rsbuild/plugin-react": "~1.4.0",
29
+ "@rsbuild/plugin-solid": "~1.0.6",
32
30
  "lodash": "4.17.21",
33
- "qrcode.react": "^4.2.0",
34
- "@rspress/shared": "2.0.0-beta.3",
35
- "@rspress/theme-default": "2.0.0-beta.3"
31
+ "qrcode.react": "^4.2.0"
36
32
  },
37
33
  "devDependencies": {
38
- "@rslib/core": "0.6.7",
39
- "@types/lodash": "^4.17.16",
34
+ "@rslib/core": "0.12.4",
35
+ "@types/lodash": "^4.17.20",
40
36
  "@types/mdast": "^4.0.4",
41
- "@types/node": "^18.11.17",
42
- "@types/react": "^18.3.20",
43
- "@types/react-dom": "^18.3.6",
37
+ "@types/node": "^22.8.1",
38
+ "@types/react": "^19.1.12",
39
+ "@types/react-dom": "^19.1.9",
44
40
  "mdast-util-mdx-jsx": "^3.2.0",
45
41
  "mdast-util-mdxjs-esm": "^2.0.1",
46
- "react": "^19.1.0",
47
- "react-dom": "^19.1.0",
48
- "react-router-dom": "^6.29.0",
49
- "rsbuild-plugin-publint": "^0.3.1",
42
+ "react": "^19.1.1",
43
+ "react-dom": "^19.1.1",
44
+ "react-router-dom": "^6.30.1",
45
+ "rsbuild-plugin-publint": "^0.3.3",
50
46
  "typescript": "^5.8.2",
51
47
  "unified": "^11.0.5",
52
48
  "unist-util-visit": "^5.0.0"
53
49
  },
54
50
  "peerDependencies": {
55
- "@rspress/core": "^2.0.0-beta.3",
51
+ "@rspress/core": "^2.0.0-beta.30",
56
52
  "react": ">=18.0.0",
57
53
  "react-router-dom": "^6.8.1"
58
54
  },
@@ -61,7 +57,6 @@
61
57
  },
62
58
  "publishConfig": {
63
59
  "access": "public",
64
- "provenance": true,
65
60
  "registry": "https://registry.npmjs.org/"
66
61
  },
67
62
  "scripts": {
@@ -5,7 +5,7 @@ import {
5
5
  withBase,
6
6
  } from '@rspress/core/runtime';
7
7
  import { useCallback, useEffect, useState } from 'react';
8
- // @ts-ignore
8
+ // @ts-expect-error
9
9
  import { normalizeId } from '../../dist/utils';
10
10
  import MobileOperation from './common/mobile-operation';
11
11
  import './Device.css';
@@ -1,12 +1,30 @@
1
- @import url(@rspress/theme-default/bundle.css);
2
-
3
1
  :root {
4
- --rp-iframe-bg: var(--rp-code-block-bg);
2
+ --rp-iframe-bg: #f6f8fa;
3
+ --rp-iframe-nav-bg: #ffffff;
5
4
  }
6
5
 
6
+ /* TODO: support dark mode */
7
+ /* .dark {
8
+ --rp-iframe-bg: #242424;
9
+ --rp-iframe-nav-bg: #191d24;
10
+ } */
11
+
7
12
  body {
8
- background-color: var(--rp-iframe-bg);
13
+ background-color: var(--rp-iframe-bg) !important;
14
+ margin: 0px; /* copied from preflight.css */
15
+ }
16
+
17
+ /* #region copied from preflight.css */
18
+ @layer rp-base {
19
+ *,
20
+ ::before,
21
+ ::after {
22
+ box-sizing: border-box; /* 1 */
23
+ border-width: 0; /* 2 */
24
+ border-style: solid; /* 2 */
25
+ }
9
26
  }
27
+ /* #endregion copied from preflight.css */
10
28
 
11
29
  .preview-nav {
12
30
  position: relative;
@@ -14,7 +32,7 @@ body {
14
32
  align-items: center;
15
33
  justify-content: center;
16
34
  height: 56px;
17
- background-color: var(--rp-c-bg);
35
+ background-color: var(--rp-iframe-nav-bg) !important;
18
36
  font-weight: 600;
19
37
  font-size: 17px;
20
38
  }