@rspress/core 2.1.2 → 2.1.4

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.
Files changed (65) hide show
  1. package/dist/{p~0.js → 8~0.js} +1 -0
  2. package/dist/cli/index.js +1 -1
  3. package/dist/config/loadConfigFile.js +1 -1
  4. package/dist/eject-theme/components/Callout/index.test.tsx +52 -0
  5. package/dist/eject-theme/components/Callout/index.tsx +11 -0
  6. package/dist/eject-theme/components/CodeBlock/index.tsx +1 -1
  7. package/dist/eject-theme/components/HomeHero/index.scss +4 -1
  8. package/dist/eject-theme/components/PageTabs/index.test.tsx +45 -0
  9. package/dist/eject-theme/components/PageTabs/index.tsx +24 -17
  10. package/dist/eject-theme/components/Prompt/index.test.tsx +91 -0
  11. package/dist/eject-theme/components/Prompt/index.tsx +33 -1
  12. package/dist/eject-theme/components/Tabs/index.test.tsx +57 -12
  13. package/dist/eject-theme/components/Tabs/index.tsx +8 -5
  14. package/dist/node/PluginDriver.js +1 -1
  15. package/dist/node/auto-nav-sidebar/index.js +1 -1
  16. package/dist/node/auto-nav-sidebar/locales.js +1 -1
  17. package/dist/node/auto-nav-sidebar/normalize.js +1 -1
  18. package/dist/node/auto-nav-sidebar/utils.js +1 -1
  19. package/dist/node/auto-nav-sidebar/walk.js +1 -1
  20. package/dist/node/eject.js +1 -1
  21. package/dist/node/initRsbuild.js +6 -1
  22. package/dist/node/route/RoutePage.js +1 -1
  23. package/dist/node/route/RouteService.js +1 -1
  24. package/dist/node/route/extractPageData.js +19 -3
  25. package/dist/node/route/normalizeRoutePath.js +1 -1
  26. package/dist/node/route/routeChunkAssets.d.ts +2 -0
  27. package/dist/node/route/routeChunkAssets.js +6 -0
  28. package/dist/node/runtimeModule/i18n/getI18nData.js +1 -1
  29. package/dist/node/runtimeModule/i18n/rsbuildPlugin.js +1 -1
  30. package/dist/node/runtimeModule/pageData/createPageData.js +1 -1
  31. package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
  32. package/dist/node/runtimeModule/searchHooks.js +1 -1
  33. package/dist/node/runtimeModule/siteData/createSiteData.js +1 -1
  34. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
  35. package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +1 -1
  36. package/dist/node/serve.js +1 -1
  37. package/dist/node/sitemap.js +1 -1
  38. package/dist/node/ssg/alternateLinks.js +1 -1
  39. package/dist/node/ssg/renderHtmlTemplate.js +5 -1
  40. package/dist/node/ssg/renderPageWorker.js +1 -1
  41. package/dist/node/ssg/renderPages.js +1 -1
  42. package/dist/node/ssg/rsbuildPluginSSG.js +1 -1
  43. package/dist/node/ssg/ssgEnv.js +1 -1
  44. package/dist/node/ssg-md/llms/emitLlmsTxt.js +1 -1
  45. package/dist/node/ssg-md/llms/llmsTxt.js +1 -1
  46. package/dist/node/ssg-md/renderPage.js +1 -1
  47. package/dist/node/ssg-md/renderPages.js +1 -1
  48. package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
  49. package/dist/node/utils/checkLanguageParity.js +1 -1
  50. package/dist/node/utils/createHash.js +1 -1
  51. package/dist/node/utils/flattenMdxContent.js +1 -1
  52. package/dist/node/utils/getPageKey.js +1 -1
  53. package/dist/node/utils/reactAlias.js +3 -1
  54. package/dist/n~0.js +1 -1
  55. package/dist/theme/components/Callout/index.js +10 -0
  56. package/dist/theme/components/CodeBlock/index.d.ts +1 -1
  57. package/dist/theme/components/HomeHero/index.css +5 -1
  58. package/dist/theme/components/PageTabs/index.js +22 -14
  59. package/dist/theme/components/Prompt/index.js +30 -2
  60. package/dist/theme/components/Tabs/index.js +8 -5
  61. package/dist/theme/hooks/useDynamicToc.js +21 -9
  62. package/dist/theme/logic/useStorageValue.js +1 -0
  63. package/dist/tinypool~0.js +2 -2
  64. package/dist/y~0.js +1 -1
  65. package/package.json +6 -6
@@ -3,6 +3,8 @@ import type { RouteMeta } from '@rspress/shared';
3
3
  import type { RouteService } from './RouteService.js';
4
4
  export interface RouteChunkAssetsManifest {
5
5
  assetPrefix: string;
6
+ isModule: boolean;
7
+ crossOriginLoading: false | 'anonymous' | 'use-credentials';
6
8
  assets: Record<string, string[]>;
7
9
  }
8
10
  export declare function getRouteChunkName(route: RouteMeta): string;
@@ -8,12 +8,16 @@ function getRouteChunkName(route) {
8
8
  class RouteChunkAssetsPlugin {
9
9
  routeService;
10
10
  #assetPrefix = '/';
11
+ #isModule = false;
12
+ #crossOriginLoading = false;
11
13
  #chunks = new Map();
12
14
  constructor(routeService){
13
15
  this.routeService = routeService;
14
16
  }
15
17
  apply(compiler) {
16
18
  compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation)=>{
19
+ this.#isModule = Boolean(compilation.outputOptions.module);
20
+ this.#crossOriginLoading = compilation.outputOptions.crossOriginLoading ?? false;
17
21
  this.#assetPrefix = 'string' == typeof compilation.outputOptions.publicPath ? compilation.outputOptions.publicPath : '/';
18
22
  this.#chunks.clear();
19
23
  const routePathsByChunkName = new Map();
@@ -38,6 +42,8 @@ class RouteChunkAssetsPlugin {
38
42
  getManifest() {
39
43
  return {
40
44
  assetPrefix: this.#assetPrefix,
45
+ isModule: this.#isModule,
46
+ crossOriginLoading: this.#crossOriginLoading,
41
47
  assets: Object.fromEntries([
42
48
  ...this.#chunks
43
49
  ].map(([routePath, chunks])=>{
@@ -1,6 +1,6 @@
1
1
  import { rspackRequire, compatGetDefaultExport } from "../../../rslib-runtime~0.js";
2
2
  import "../../../t~0.js";
3
- import { logger, join, readFile } from "../../../p~0.js";
3
+ import { logger, join, readFile } from "../../../8~0.js";
4
4
  import { pathExists } from "../../utils/fs.js";
5
5
  import { DEFAULT_I18N_TEXT } from "./DEFAULT_I18N_TEXT.js";
6
6
  import { createError } from "../../utils/error.js";
@@ -1,4 +1,4 @@
1
- import { pluginVirtualModule } from "../../../p~0.js";
1
+ import { pluginVirtualModule } from "../../../8~0.js";
2
2
  const rsbuildPluginI18n = ({ pluginDriver })=>[
3
3
  {
4
4
  name: 'rspress:i18n',
@@ -1,4 +1,4 @@
1
- import { SEARCH_INDEX_NAME, groupBy } from "../../../p~0.js";
1
+ import { SEARCH_INDEX_NAME, groupBy } from "../../../8~0.js";
2
2
  import { extractPageData } from "../../route/extractPageData.js";
3
3
  import { createHash } from "../../utils/createHash.js";
4
4
  function deletePrivateField(obj) {
@@ -1,4 +1,4 @@
1
- import { logger, pluginVirtualModule } from "../../../p~0.js";
1
+ import { logger, pluginVirtualModule } from "../../../8~0.js";
2
2
  import { createPageData } from "./createPageData.js";
3
3
  const rsbuildPluginDocVM = async ({ config, userDocRoot, routeService, pluginDriver })=>{
4
4
  const ref = {
@@ -1,4 +1,4 @@
1
- import { node_path } from "../../p~0.js";
1
+ import { node_path } from "../../8~0.js";
2
2
  const searchHookVMPlugin = (context)=>({
3
3
  ["virtual-search-hooks"]: ()=>{
4
4
  const { config } = context;
@@ -1,4 +1,4 @@
1
- import { getIconUrlPath } from "../../../p~0.js";
1
+ import { getIconUrlPath } from "../../../8~0.js";
2
2
  import { normalizeThemeConfig } from "./normalizeThemeConfig.js";
3
3
  async function createSiteData(userConfig, pluginDriver) {
4
4
  const tempSearchObj = Object.assign({}, userConfig.search);
@@ -1,4 +1,4 @@
1
- import { isExternalUrl, slash, addLeadingSlash, normalizeHref } from "../../../p~0.js";
1
+ import { isExternalUrl, slash, addLeadingSlash, normalizeHref } from "../../../8~0.js";
2
2
  import { applyReplaceRules } from "../../utils/applyReplaceRules.js";
3
3
  async function normalizeThemeConfig(docConfig, pluginDriver) {
4
4
  const { locales: siteLocales, lang, replaceRules = [], multiVersion } = docConfig;
@@ -1,4 +1,4 @@
1
- import { isProduction, logger } from "../../../p~0.js";
1
+ import { isProduction, logger } from "../../../8~0.js";
2
2
  import { modifyConfigWithAutoNavSide } from "../../auto-nav-sidebar/index.js";
3
3
  import { createSiteData } from "./createSiteData.js";
4
4
  const siteDataVMPlugin = (context)=>{
@@ -1,4 +1,4 @@
1
- import { mergeRsbuildConfig } from "../p~0.js";
1
+ import { mergeRsbuildConfig } from "../8~0.js";
2
2
  import { normalizeConfigResult } from "../config/loadConfigFile.js";
3
3
  import { PluginDriver } from "./PluginDriver.js";
4
4
  import { initRsbuild } from "./initRsbuild.js";
@@ -1,4 +1,4 @@
1
- import { withSiteOrigin, logger, glob, promises_stat, withBase } from "../p~0.js";
1
+ import { withSiteOrigin, logger, glob, promises_stat, withBase } from "../8~0.js";
2
2
  import { routePath2HtmlFileName } from "./ssg/htmlFile.js";
3
3
  function ensureTrailingSlash(url) {
4
4
  return url.endsWith('/') ? url : `${url}/`;
@@ -1,4 +1,4 @@
1
- import { normalizeHref, removeTrailingSlash, addLeadingSlash, normalizePosixPath, withSiteOrigin } from "../../p~0.js";
1
+ import { normalizeHref, removeTrailingSlash, addLeadingSlash, normalizePosixPath, withSiteOrigin } from "../../8~0.js";
2
2
  function createAlternateLinksByRoute(routes, config) {
3
3
  const routeGroups = new Map();
4
4
  for (const route of routes){
@@ -37,7 +37,11 @@ function renderRoutePreloadLinks(route, manifest) {
37
37
  if (!assets) return '';
38
38
  return assets.map((asset)=>{
39
39
  const href = 'auto' === manifest.assetPrefix ? posix.relative(posix.dirname(routePath2HtmlFileName(route.routePath)), asset) : `${manifest.assetPrefix}${asset}`;
40
- return `<link rel="preload" href="${escapeHtmlAttribute(href)}" as="script">`;
40
+ const rel = manifest.isModule ? 'modulepreload' : 'preload';
41
+ const as = manifest.isModule ? '' : ' as="script"';
42
+ const crossOrigin = manifest.crossOriginLoading;
43
+ const crossorigin = crossOrigin && (manifest.isModule || 'use-credentials' === crossOrigin || /^(?:[a-z][a-z\d+.-]*:)?\/\//i.test(href)) ? ` crossorigin="${crossOrigin}"` : '';
44
+ return `<link rel="${rel}" href="${escapeHtmlAttribute(href)}"${as}${crossorigin}>`;
41
45
  }).join('');
42
46
  }
43
47
  function escapeHtmlAttribute(value) {
@@ -5,7 +5,7 @@ import { pMap } from "../../y~0.js";
5
5
  import { renderPage } from "./renderPage.js";
6
6
  const params = workerData?.[1]?.params;
7
7
  if (!params) throw createError('SSG Worker Thread workerData params missing');
8
- const { htmlTemplate: htmlTemplate, head: head, ssrBundlePath: ssrBundlePath, alternateLinksByRoute: alternateLinksByRoute, distPath: distPath, routeChunkAssets: routeChunkAssets } = params;
8
+ const { htmlTemplate, head, ssrBundlePath, alternateLinksByRoute, distPath, routeChunkAssets } = params;
9
9
  async function writeHtmlFile(routePath, html) {
10
10
  if (!distPath) return;
11
11
  const fileAbsolutePath = resolveHtmlFilePath(distPath, routePath);
@@ -1,7 +1,7 @@
1
1
  /*! LICENSE: renderPages.js.LICENSE.txt */
2
2
  import { rspackRequire, compatGetDefaultExport } from "../../rslib-runtime~0.js";
3
3
  import "../../t~0.js";
4
- import { node_path, fileURLToPath, logger, chunk } from "../../p~0.js";
4
+ import { node_path, fileURLToPath, logger, chunk } from "../../8~0.js";
5
5
  import { createAlternateLinksByRoute } from "./alternateLinks.js";
6
6
  import { SSGWorkerThreadTaskSize, getNumberOfThreads, SSGWorkerThreadRecyclerMaxMemory, SSGConcurrency } from "./ssgEnv.js";
7
7
  import { routePath2HtmlFileName } from "./htmlFile.js";
@@ -1,4 +1,4 @@
1
- import { logger, writeFile, mkdir, rm, join, isDebugMode } from "../../p~0.js";
1
+ import { logger, writeFile, mkdir, rm, join, isDebugMode } from "../../8~0.js";
2
2
  import { NODE_SSG_BUNDLE_FOLDER, NODE_SSG_BUNDLE_NAME } from "../constants.js";
3
3
  import { renderPages } from "./renderPages.js";
4
4
  const rsbuildPluginSSG = ({ routeService, config, routeChunkAssets })=>({
@@ -1,5 +1,5 @@
1
1
  /*! LICENSE: ssgEnv.js.LICENSE.txt */
2
- import { node_os } from "../../p~0.js";
2
+ import { node_os } from "../../8~0.js";
3
3
  /**
4
4
  * these codes are copied from
5
5
  * @link https://github.com/facebook/docusaurus/blob/45065e8d2b5831117b8d69fec1be28f5520cf105/packages/docusaurus/src/ssg/ssgEnv.ts#L11
@@ -1,4 +1,4 @@
1
- import { matchPath, getSidebarDataGroup } from "../../../p~0.js";
1
+ import { matchPath, getSidebarDataGroup } from "../../../8~0.js";
2
2
  import { generateLlmsTxt, generateLlmsFullTxt } from "./llmsTxt.js";
3
3
  async function emitLlmsTxt(config, routeService, emitAsset, mdContents) {
4
4
  const base = config.base ?? '/';
@@ -1,4 +1,4 @@
1
- import { normalizeHref, withSiteOrigin, logger, withBase } from "../../../p~0.js";
1
+ import { normalizeHref, withSiteOrigin, logger, withBase } from "../../../8~0.js";
2
2
  import { extractInfoFromFrontmatterWithAbsolutePath } from "../../auto-nav-sidebar/utils.js";
3
3
  function routePathToMdPath(routePath, base, siteOrigin) {
4
4
  let url = routePath;
@@ -1,6 +1,6 @@
1
1
  import { rspackRequire, compatGetDefaultExport } from "../../rslib-runtime~0.js";
2
2
  import "../../t~0.js";
3
- import { createHead, pathToFileURL, logger } from "../../p~0.js";
3
+ import { createHead, pathToFileURL, logger } from "../../8~0.js";
4
4
  import { hintSSGMDFailed } from "../logger/hint.js";
5
5
  const picocolors = rspackRequire("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
6
6
  var picocolors_default = /*#__PURE__*/ compatGetDefaultExport(picocolors);
@@ -1,6 +1,6 @@
1
1
  import { rspackRequire, compatGetDefaultExport } from "../../rslib-runtime~0.js";
2
2
  import "../../t~0.js";
3
- import { logger } from "../../p~0.js";
3
+ import { logger } from "../../8~0.js";
4
4
  import { pMap } from "../../y~0.js";
5
5
  import { renderPage } from "./renderPage.js";
6
6
  import { SSGConcurrency } from "../ssg/ssgEnv.js";
@@ -1,4 +1,4 @@
1
- import { writeFile, mkdir, rm, join, isDebugMode } from "../../p~0.js";
1
+ import { writeFile, mkdir, rm, join, isDebugMode } from "../../8~0.js";
2
2
  import { NODE_SSG_MD_BUNDLE_FOLDER, NODE_SSG_MD_BUNDLE_NAME } from "../constants.js";
3
3
  import { renderPages } from "./renderPages.js";
4
4
  import { emitLlmsTxt } from "./llms/emitLlmsTxt.js";
@@ -1,4 +1,4 @@
1
- import { node_path, logger, promises } from "../../p~0.js";
1
+ import { node_path, logger, promises } from "../../8~0.js";
2
2
  import { slash } from "./slash.js";
3
3
  import { createError } from "./error.js";
4
4
  async function getAllMarkdownFilesFrom(dirPath) {
@@ -1,4 +1,4 @@
1
- import { createHash as external_node_crypto_createHash } from "../../p~0.js";
1
+ import { createHash as external_node_crypto_createHash } from "../../8~0.js";
2
2
  function createHash(str, length = 8) {
3
3
  return external_node_crypto_createHash('sha256').update(str).digest('hex').slice(0, length);
4
4
  }
@@ -1,4 +1,4 @@
1
- import { node_fs, node_path, core_rspack, logger, createProcessor, MDX_OR_MD_REGEXP } from "../../p~0.js";
1
+ import { node_fs, node_path, core_rspack, logger, createProcessor, MDX_OR_MD_REGEXP } from "../../8~0.js";
2
2
  import { createError } from "./error.js";
3
3
  import { importStatementRegex } from "../constants.js";
4
4
  const RspackResolveFactory = core_rspack.experiments.resolver.ResolverFactory;
@@ -1,4 +1,4 @@
1
- import { removeLeadingSlash } from "../../p~0.js";
1
+ import { removeLeadingSlash } from "../../8~0.js";
2
2
  function getPageKey(route) {
3
3
  const cleanRoute = removeLeadingSlash(route);
4
4
  return cleanRoute.replace(/\//g, '_').replace(/\.[^.]+$/, '') || 'index';
@@ -1,6 +1,6 @@
1
1
  import { rspackRequire, compatGetDefaultExport } from "../../rslib-runtime~0.js";
2
2
  import "../../t~0.js";
3
- import { node_path, core_rspack, logger } from "../../p~0.js";
3
+ import { node_path, core_rspack, logger } from "../../8~0.js";
4
4
  import { pathExists, readJson } from "./fs.js";
5
5
  import { PACKAGE_ROOT } from "../constants.js";
6
6
  import { hintReactVersion } from "../logger/hint.js";
@@ -54,6 +54,7 @@ async function resolveReactAlias(isSSR) {
54
54
  'react',
55
55
  'react/jsx-runtime',
56
56
  'react/jsx-dev-runtime',
57
+ 'react/compiler-runtime',
57
58
  'react/package.json',
58
59
  'react-dom',
59
60
  'react-dom/client',
@@ -83,6 +84,7 @@ async function resolveReactAlias(isSSR) {
83
84
  if (resolved.error || !resolved.path) throw Error(resolved.error);
84
85
  alias[lib] = resolved.path;
85
86
  } catch (e) {
87
+ if ('react/compiler-runtime' === lib) return;
86
88
  if (e instanceof Error) {
87
89
  logger.warn(`${lib} not found: \n ${picocolors_default().gray(e.toString())}`);
88
90
  hintReactVersion();
package/dist/n~0.js CHANGED
@@ -1117,7 +1117,7 @@ class SignalExit extends SignalExitBase {
1117
1117
  }
1118
1118
  }
1119
1119
  const mjs_process = globalThis.process;
1120
- const { onExit: onExit, load: mjs_load, unload: unload } = signalExitWrap(processOk(mjs_process) ? new SignalExit(mjs_process) : new SignalExitFallback());
1120
+ const { onExit, load: mjs_load, unload } = signalExitWrap(processOk(mjs_process) ? new SignalExit(mjs_process) : new SignalExitFallback());
1121
1121
  const DEFAULT_FORCE_KILL_TIMEOUT = 5000;
1122
1122
  const spawnedKill = (kill, signal = 'SIGTERM', options = {})=>{
1123
1123
  const killResult = kill(signal);
@@ -4,6 +4,16 @@ function capitalize(type) {
4
4
  return type.charAt(0).toUpperCase() + type.slice(1);
5
5
  }
6
6
  function Callout({ type, title, children }) {
7
+ if (import.meta.env.SSG_MD) return /*#__PURE__*/ jsxs("blockquote", {
8
+ children: [
9
+ /*#__PURE__*/ jsx("p", {
10
+ children: /*#__PURE__*/ jsx("strong", {
11
+ children: title ?? capitalize(type)
12
+ })
13
+ }),
14
+ children
15
+ ]
16
+ });
7
17
  const isDetails = 'details' === type;
8
18
  if (isDetails) return /*#__PURE__*/ jsxs("details", {
9
19
  className: `rp-callout rp-callout--${type}`,
@@ -17,7 +17,7 @@ export type CodeBlockProps = {
17
17
  fold?: boolean;
18
18
  height?: number;
19
19
  containerElementClassName?: string;
20
- codeButtonGroupProps?: Omit<CodeButtonGroupProps, 'preElementRef' | 'wrapCode' | 'toggleWrapCode'>;
20
+ codeButtonGroupProps?: Omit<CodeButtonGroupProps, 'copyElementRef' | 'wrapCode' | 'toggleWrapCode'>;
21
21
  children?: React.ReactNode;
22
22
  };
23
23
  /**
@@ -23,7 +23,11 @@
23
23
 
24
24
  @media (width <= 600px) {
25
25
  .rp-home-hero {
26
- padding: 10px;
26
+ padding: 10px 20px;
27
+ }
28
+
29
+ .rp-home-hero .rp-home-hero__container {
30
+ gap: 18px;
27
31
  }
28
32
 
29
33
  .rp-home-hero .rp-home-hero__title {
@@ -1,5 +1,5 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import { useSearchParams } from "@rspress/core/runtime";
2
+ import { useLocation, useSearchParams } from "@rspress/core/runtime";
3
3
  import clsx from "clsx";
4
4
  import { Children, forwardRef, isValidElement, useEffect, useMemo } from "react";
5
5
  import "./index.css";
@@ -17,19 +17,22 @@ function getTabValuesFromChildren(children) {
17
17
  }
18
18
  function usePageTabs(id, children) {
19
19
  const [searchParams, setSearchParams] = useSearchParams();
20
+ const { search } = useLocation();
20
21
  const tabValues = useMemo(()=>getTabValuesFromChildren(children), [
21
22
  children
22
23
  ]);
23
24
  function navigateToTab(index) {
24
- if (0 === index) searchParams.delete(id);
25
- else searchParams.set(id, String(index));
26
- setSearchParams(searchParams);
25
+ const nextSearchParams = new URLSearchParams(searchParams);
26
+ if (0 === index) nextSearchParams.delete(id);
27
+ else nextSearchParams.set(id, String(index));
28
+ setSearchParams(nextSearchParams);
27
29
  }
28
30
  useEffect(()=>{
29
- const currIndex = Number(searchParams.get(id) ?? '0');
31
+ const currIndex = Number(new URLSearchParams(search).get(id) ?? '0');
30
32
  if (!Number.isNaN(currIndex)) document.body.dataset.pageTabsActiveIndex = currIndex.toString();
31
33
  }, [
32
- searchParams
34
+ id,
35
+ search
33
36
  ]);
34
37
  const injectScript = `(function () {
35
38
  var searchParams = new URLSearchParams(window.location.search);
@@ -44,12 +47,22 @@ function usePageTabs(id, children) {
44
47
  injectScript
45
48
  };
46
49
  }
47
- let renderCountForTocUpdate = 0;
48
50
  const PageTabs = /*#__PURE__*/ forwardRef((props, ref)=>{
49
51
  const { children: rawChildren, tabPosition = 'left', className, id = 'page' } = props;
50
52
  const children = Children.toArray(rawChildren).filter((child)=>!('string' == typeof child && '' === child.trim()) && /*#__PURE__*/ isValidElement(child));
51
53
  const { tabValues, navigateToTab, injectScript } = usePageTabs(id, children);
52
- renderCountForTocUpdate++;
54
+ if (import.meta.env.SSG_MD) return /*#__PURE__*/ jsx(Fragment, {
55
+ children: tabValues.map(({ label, content }, index)=>/*#__PURE__*/ jsxs("div", {
56
+ children: [
57
+ null != label && /*#__PURE__*/ jsx("p", {
58
+ children: /*#__PURE__*/ jsx("strong", {
59
+ children: label
60
+ })
61
+ }),
62
+ content
63
+ ]
64
+ }, index))
65
+ });
53
66
  return /*#__PURE__*/ jsxs(Fragment, {
54
67
  children: [
55
68
  /*#__PURE__*/ jsx("script", {
@@ -85,12 +98,7 @@ const PageTabs = /*#__PURE__*/ forwardRef((props, ref)=>{
85
98
  }, 'string' == typeof label ? label : index))
86
99
  })
87
100
  ]
88
- }),
89
- renderCountForTocUpdate % 2 === 0 ? /*#__PURE__*/ jsx("h2", {
90
- style: {
91
- display: 'none'
92
- }
93
- }) : null
101
+ })
94
102
  ]
95
103
  });
96
104
  });
@@ -1,4 +1,4 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import { useI18n } from "@rspress/core/runtime";
3
3
  import { IconArrowDown, IconCopy, IconSuccess, SvgWrapper, copyToClipboard, renderInlineMarkdown } from "@rspress/core/theme";
4
4
  import clsx from "clsx";
@@ -133,7 +133,7 @@ function CopyablePrompt({ className, defaultCollapsed = true, description, eyebr
133
133
  return /*#__PURE__*/ jsxs("div", {
134
134
  ...props,
135
135
  ref: cardRef,
136
- className: clsx('rp-prompt', className),
136
+ className: clsx('rp-prompt', 'rp-not-doc', className),
137
137
  style: {
138
138
  '--rp-prompt-accent': AGENT_ICONS[iconIndex].color,
139
139
  ...style
@@ -251,6 +251,34 @@ function CopyablePrompt({ className, defaultCollapsed = true, description, eyebr
251
251
  });
252
252
  }
253
253
  function Prompt({ custom = false, ...props }) {
254
+ if (import.meta.env.SSG_MD) {
255
+ const { children, description, eyebrow = 'For your Agent', prompt, title = 'Agent Prompt' } = props;
256
+ if (custom) return /*#__PURE__*/ jsxs(Fragment, {
257
+ children: [
258
+ /*#__PURE__*/ jsx("p", {
259
+ children: /*#__PURE__*/ jsx("strong", {
260
+ children: eyebrow
261
+ })
262
+ }),
263
+ children
264
+ ]
265
+ });
266
+ return /*#__PURE__*/ jsxs(Fragment, {
267
+ children: [
268
+ /*#__PURE__*/ jsx("p", {
269
+ children: /*#__PURE__*/ jsx("strong", {
270
+ children: title
271
+ })
272
+ }),
273
+ description ? /*#__PURE__*/ jsx("p", {
274
+ children: description
275
+ }) : null,
276
+ prompt ? /*#__PURE__*/ jsx("pre", {
277
+ children: `<prompt>\n${prompt}\n</prompt>`
278
+ }) : null
279
+ ]
280
+ });
281
+ }
254
282
  return custom ? /*#__PURE__*/ jsx(CustomPrompt, {
255
283
  ...props
256
284
  }) : /*#__PURE__*/ jsx(CopyablePrompt, {
@@ -37,13 +37,16 @@ const Tabs = /*#__PURE__*/ forwardRef((props, ref)=>{
37
37
  const [activeIndex, setActiveIndex] = useState(initialActiveIndex);
38
38
  const [storageIndex, setStorageIndex] = useStorageValue(`${groupIdPrefix}${groupId}`, initialActiveIndex.toString());
39
39
  if (import.meta.env.SSG_MD) return /*#__PURE__*/ jsx(Fragment, {
40
- children: tabValues.map(({ label, content })=>/*#__PURE__*/ jsxs(Fragment, {
40
+ children: tabValues.map(({ label, content }, index)=>/*#__PURE__*/ jsxs("div", {
41
41
  children: [
42
- `\n**${label}**\n\n`,
43
- content,
44
- `\n`
42
+ null != label && /*#__PURE__*/ jsx("p", {
43
+ children: /*#__PURE__*/ jsx("strong", {
44
+ children: label
45
+ })
46
+ }),
47
+ content
45
48
  ]
46
- }))
49
+ }, index))
47
50
  });
48
51
  const currentIndex = groupId ? Number(storageIndex) : activeIndex;
49
52
  return /*#__PURE__*/ jsxs("div", {
@@ -64,17 +64,23 @@ const useWatchToc = ()=>{
64
64
  if (target && !observer) {
65
65
  observer = new MutationObserver((mutationList)=>{
66
66
  let needUpdate = false;
67
- check: for (const mutation of mutationList)for (const nodes of [
68
- mutation.addedNodes,
69
- mutation.removedNodes
70
- ])for (const node of nodes){
71
- if (TOC_HEADING_TAGS.has(node.tagName) || node.parentElement?.closest('h2,h3,h4')) {
67
+ check: for (const mutation of mutationList){
68
+ if ('attributes' === mutation.type) {
72
69
  needUpdate = true;
73
- break check;
70
+ break;
74
71
  }
75
- for (const child of node.childNodes)if (TOC_HEADING_TAGS.has(child.tagName)) {
76
- needUpdate = true;
77
- break check;
72
+ for (const nodes of [
73
+ mutation.addedNodes,
74
+ mutation.removedNodes
75
+ ])for (const node of nodes){
76
+ if (TOC_HEADING_TAGS.has(node.tagName) || node.parentElement?.closest('h2,h3,h4')) {
77
+ needUpdate = true;
78
+ break check;
79
+ }
80
+ for (const child of node.childNodes)if (TOC_HEADING_TAGS.has(child.tagName)) {
81
+ needUpdate = true;
82
+ break check;
83
+ }
78
84
  }
79
85
  }
80
86
  needUpdate && updateHeaders(target, pathname);
@@ -83,6 +89,12 @@ const useWatchToc = ()=>{
83
89
  childList: true,
84
90
  subtree: true
85
91
  });
92
+ observer.observe(document.body, {
93
+ attributes: true,
94
+ attributeFilter: [
95
+ 'data-page-tabs-active-index'
96
+ ]
97
+ });
86
98
  }
87
99
  return ()=>{
88
100
  observer?.disconnect();
@@ -19,6 +19,7 @@ const setStorageItem = (key, value)=>{
19
19
  };
20
20
  const useStorageValue = (key, defaultValue)=>{
21
21
  const subscribe = useCallback((onStoreChange)=>{
22
+ if ("u" < typeof window) return ()=>{};
22
23
  const handleStorage = (event)=>{
23
24
  if (event.key === key || null === event.key) onStoreChange();
24
25
  };
@@ -124,12 +124,12 @@ var ProcessWorker = class {
124
124
  if (this.port) this.port.on("message", (message$1)=>this.send({
125
125
  ...message$1,
126
126
  source: "port",
127
- __tinypool_worker_message__: __tinypool_worker_message__
127
+ __tinypool_worker_message__
128
128
  }));
129
129
  return this.send({
130
130
  ...message,
131
131
  source: "pool",
132
- __tinypool_worker_message__: __tinypool_worker_message__
132
+ __tinypool_worker_message__
133
133
  });
134
134
  }
135
135
  on(event, callback) {
package/dist/y~0.js CHANGED
@@ -1,5 +1,5 @@
1
1
  var package_namespaceObject = {
2
- rE: "2.1.2"
2
+ rE: "2.1.4"
3
3
  };
4
4
  function pMap(iterable, mapper, options) {
5
5
  return mapConcurrently(iterable, mapper, options, false);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspress/core",
3
- "version": "2.1.2",
3
+ "version": "2.1.4",
4
4
  "description": "The Rspress Documentation Framework",
5
5
  "bugs": "https://github.com/web-infra-dev/rspress/issues",
6
6
  "repository": {
@@ -60,9 +60,9 @@
60
60
  "dependencies": {
61
61
  "@mdx-js/mdx": "^3.1.1",
62
62
  "@mdx-js/react": "^3.1.1",
63
- "@rsbuild/core": "^2.2.14",
63
+ "@rsbuild/core": "^2.3.3",
64
64
  "@rsbuild/plugin-react": "~2.1.1",
65
- "@rspress/shared": "2.1.2",
65
+ "@rspress/shared": "2.1.4",
66
66
  "@shikijs/rehype": "^4.2.0",
67
67
  "@shikijs/transformers": "^4.2.0",
68
68
  "@types/mdast": "^4.0.4",
@@ -108,15 +108,15 @@
108
108
  "@types/node": "^22.8.1",
109
109
  "@types/nprogress": "^0.2.3",
110
110
  "@types/react-dom": "^19.3.0",
111
- "@types/web": "^0.0.362",
111
+ "@types/web": "^0.0.367",
112
112
  "cac": "^7.1.0",
113
113
  "execa": "8.0.1",
114
114
  "mdast-util-directive": "^3.1.1",
115
115
  "mdast-util-mdx-expression": "^2.0.1",
116
- "memfs": "^4.80.0",
116
+ "memfs": "^4.80.1",
117
117
  "p-map": "^7.1.1",
118
118
  "picocolors": "^1.1.1",
119
- "postcss": "8.5.32",
119
+ "postcss": "8.5.33",
120
120
  "remark-directive": "^4.0.0",
121
121
  "rsbuild-plugin-publint": "^1.0.0",
122
122
  "rsbuild-plugin-virtual-module": "0.4.5",