@rspress/core 2.0.0-rc.4 → 2.0.0-rc.6

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 (181) hide show
  1. package/dist/{0~7675.723d12b2.js → 0~7675.d236b058.js} +3 -3
  2. package/dist/{5485.9fc7f63d.js → 5485.7586c86a.js} +1 -1
  3. package/dist/{3521.9eb6b114.js → 7786.421b464f.js} +2 -2
  4. package/dist/9348.1beb3e25.js +11 -0
  5. package/dist/_private/react/render.js +1 -1
  6. package/dist/cli/index.js +2 -2
  7. package/dist/config/defineConfig.d.ts +40 -0
  8. package/dist/{cli/config → config}/loadConfigFile.js +2 -2
  9. package/dist/eject-theme/components/Callout/index.scss +6 -6
  10. package/dist/eject-theme/components/CodeBlock/index.tsx +1 -1
  11. package/dist/eject-theme/components/DocContent/docComponents/title.tsx +21 -2
  12. package/dist/eject-theme/components/FallbackHeading/index.tsx +4 -0
  13. package/dist/eject-theme/components/HomeBackground/useNavTransparent.tsx +2 -1
  14. package/dist/eject-theme/components/HomeHero/index.scss +8 -0
  15. package/dist/eject-theme/components/HomeHero/index.tsx +11 -2
  16. package/dist/eject-theme/components/Llms/LlmsContainer.scss +6 -0
  17. package/dist/eject-theme/components/Llms/LlmsContainer.tsx +9 -0
  18. package/dist/eject-theme/components/Llms/LlmsCopyButton.scss +57 -0
  19. package/dist/eject-theme/components/Llms/LlmsCopyButton.tsx +94 -0
  20. package/dist/eject-theme/components/Llms/LlmsViewOptions.scss +98 -0
  21. package/dist/eject-theme/components/Llms/LlmsViewOptions.tsx +259 -0
  22. package/dist/eject-theme/components/Llms/index.scss +42 -0
  23. package/dist/eject-theme/components/Llms/index.tsx +4 -0
  24. package/dist/eject-theme/components/Llms/useMdUrl.ts +14 -0
  25. package/dist/eject-theme/components/Nav/index.scss +3 -0
  26. package/dist/eject-theme/components/Nav/index.tsx +7 -2
  27. package/dist/eject-theme/components/{Nav/NavTitle.tsx → NavTitle/index.tsx} +15 -6
  28. package/dist/eject-theme/components/Overview/index.tsx +8 -62
  29. package/dist/eject-theme/components/OverviewGroup/index.tsx +46 -0
  30. package/dist/eject-theme/components/Steps/index.scss +1 -0
  31. package/dist/index.d.ts +2 -1
  32. package/dist/index.js +3 -4
  33. package/dist/node/PluginDriver.js +1 -1
  34. package/dist/node/auto-nav-sidebar/index.js +1 -1
  35. package/dist/node/auto-nav-sidebar/normalize.js +1 -1
  36. package/dist/node/auto-nav-sidebar/utils.js +1 -1
  37. package/dist/node/auto-nav-sidebar/walk.js +1 -1
  38. package/dist/node/constants.js +1 -1
  39. package/dist/node/eject.js +1 -0
  40. package/dist/node/initRsbuild.js +6 -6
  41. package/dist/node/last-updated/index.js +1 -1
  42. package/dist/node/mdx/{loader.7c249a26.js → loader.15e0b2d2.js} +0 -5
  43. package/dist/node/mdx/options.js +2 -2
  44. package/dist/node/mdx/processor.js +1 -1
  45. package/dist/node/mdx/rehypePlugins/codeMeta.js +1 -1
  46. package/dist/node/mdx/rehypePlugins/headerAnchor.js +2 -3
  47. package/dist/node/mdx/rehypePlugins/shiki.js +1 -1
  48. package/dist/node/mdx/remarkPlugins/fileCodeBlock.js +1 -2
  49. package/dist/node/mdx/remarkPlugins/image.js +1 -3
  50. package/dist/node/mdx/remarkPlugins/link.js +1 -2
  51. package/dist/node/mdx/remarkPlugins/toc.d.ts +4 -3
  52. package/dist/node/mdx/remarkPlugins/toc.js +14 -11
  53. package/dist/node/route/RoutePage.d.ts +3 -1
  54. package/dist/node/route/RoutePage.js +4 -0
  55. package/dist/node/route/RouteService.js +2 -2
  56. package/dist/node/route/extractPageData.d.ts +5 -0
  57. package/dist/node/route/extractPageData.js +88 -58
  58. package/dist/node/route/normalizeRoutePath.js +2 -2
  59. package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.d.ts +21 -0
  60. package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.js +21 -0
  61. package/dist/node/runtimeModule/i18n.js +4 -3
  62. package/dist/node/runtimeModule/pageData/createPageData.js +9 -6
  63. package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +20 -14
  64. package/dist/node/runtimeModule/siteData/createSiteData.js +2 -1
  65. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
  66. package/dist/node/serve.js +1 -1
  67. package/dist/node/ssg/renderPage.js +1 -1
  68. package/dist/node/ssg/renderPageWorker.js +1 -1
  69. package/dist/node/ssg/renderPages.js +7 -3
  70. package/dist/node/ssg/rsbuildPluginSSG.js +1 -1
  71. package/dist/node/ssg/ssgEnv.js +1 -1
  72. package/dist/node/ssg-md/llms/emitLlmsTxt.js +2 -2
  73. package/dist/node/ssg-md/llms/llmsTxt.js +12 -2
  74. package/dist/node/ssg-md/remarkSplitMdx.js +2 -2
  75. package/dist/node/ssg-md/renderPage.js +1 -1
  76. package/dist/node/ssg-md/renderPages.js +1 -1
  77. package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
  78. package/dist/node/utils/createHash.js +1 -1
  79. package/dist/node/utils/flattenMdxContent.js +2 -3
  80. package/dist/node/utils/getPageKey.js +1 -1
  81. package/dist/node/utils/normalizePath.js +1 -1
  82. package/dist/node/utils/reactAlias.js +1 -1
  83. package/dist/runtime/Content.d.ts +4 -0
  84. package/dist/runtime/Content.js +18 -0
  85. package/dist/runtime/NoSSR.d.ts +3 -0
  86. package/dist/runtime/NoSSR.js +14 -0
  87. package/dist/runtime/getSidebarDataGroup.test.js +68 -0
  88. package/dist/runtime/hooks/useActiveMatcher.d.ts +1 -0
  89. package/dist/runtime/hooks/useActiveMatcher.js +14 -0
  90. package/dist/runtime/hooks/useDark.d.ts +7 -0
  91. package/dist/runtime/hooks/useDark.js +7 -0
  92. package/dist/runtime/hooks/useFrontmatter.d.ts +4 -0
  93. package/dist/runtime/hooks/useFrontmatter.js +9 -0
  94. package/dist/runtime/hooks/useI18n.d.ts +2 -0
  95. package/dist/runtime/hooks/useI18n.js +14 -0
  96. package/dist/runtime/hooks/useLang.d.ts +1 -0
  97. package/dist/runtime/hooks/useLang.js +6 -0
  98. package/dist/runtime/hooks/useLocaleSiteData.d.ts +18 -0
  99. package/dist/runtime/hooks/useLocaleSiteData.js +20 -0
  100. package/dist/runtime/hooks/useNav.d.ts +1 -0
  101. package/dist/runtime/hooks/useNav.js +12 -0
  102. package/dist/runtime/hooks/usePage.d.ts +10 -0
  103. package/dist/runtime/hooks/usePage.js +9 -0
  104. package/dist/runtime/hooks/usePageData.d.ts +5 -0
  105. package/dist/runtime/hooks/usePageData.js +16 -0
  106. package/dist/runtime/hooks/usePages.d.ts +4 -0
  107. package/dist/runtime/hooks/usePages.js +7 -0
  108. package/dist/runtime/hooks/useSidebar.d.ts +16 -0
  109. package/dist/runtime/hooks/useSidebar.js +67 -0
  110. package/dist/runtime/hooks/useSite.d.ts +4 -0
  111. package/dist/runtime/hooks/useSite.js +7 -0
  112. package/dist/runtime/hooks/useVersion.d.ts +1 -0
  113. package/dist/runtime/hooks/useVersion.js +6 -0
  114. package/dist/runtime/hooks/useWindowSize.d.ts +9 -0
  115. package/dist/runtime/hooks/useWindowSize.js +31 -0
  116. package/dist/runtime/hooks/useWindowSize.test.js +36 -0
  117. package/dist/runtime/index.d.ts +21 -0
  118. package/dist/runtime/index.js +22 -0
  119. package/dist/runtime/route.d.ts +36 -0
  120. package/dist/runtime/route.js +53 -0
  121. package/dist/runtime/route.test.js +154 -0
  122. package/dist/runtime/ssrMdServerEntry.js +1 -1
  123. package/dist/runtime/utils.d.ts +12 -0
  124. package/dist/runtime/utils.js +34 -0
  125. package/dist/runtime/utils.test.js +34 -0
  126. package/dist/theme/components/Callout/index.css +6 -6
  127. package/dist/theme/components/CodeBlock/index.js +1 -1
  128. package/dist/theme/components/DocContent/docComponents/title.js +25 -5
  129. package/dist/theme/components/FallbackHeading/index.js +4 -1
  130. package/dist/theme/components/HomeBackground/useNavTransparent.js +1 -1
  131. package/dist/theme/components/HomeHero/index.css +16 -10
  132. package/dist/theme/components/HomeHero/index.js +10 -3
  133. package/dist/theme/components/Llms/LlmsContainer.css +7 -0
  134. package/dist/theme/components/Llms/LlmsContainer.d.ts +5 -0
  135. package/dist/theme/components/Llms/LlmsContainer.js +9 -0
  136. package/dist/theme/components/Llms/LlmsCopyButton.css +57 -0
  137. package/dist/theme/components/Llms/LlmsCopyButton.d.ts +20 -0
  138. package/dist/theme/components/Llms/LlmsCopyButton.js +73 -0
  139. package/dist/theme/components/Llms/LlmsCopyButton.js.LICENSE.txt +5 -0
  140. package/dist/theme/components/Llms/LlmsViewOptions.css +93 -0
  141. package/dist/theme/components/Llms/LlmsViewOptions.d.ts +34 -0
  142. package/dist/theme/components/Llms/LlmsViewOptions.js +206 -0
  143. package/dist/theme/components/Llms/LlmsViewOptions.js.LICENSE.txt +5 -0
  144. package/dist/theme/components/Llms/index.css +32 -0
  145. package/dist/theme/components/Llms/index.d.ts +4 -0
  146. package/dist/theme/components/Llms/index.js +5 -0
  147. package/dist/theme/components/Llms/useMdUrl.d.ts +6 -0
  148. package/dist/theme/components/Llms/useMdUrl.js +15 -0
  149. package/dist/theme/components/Nav/index.css +1 -0
  150. package/dist/theme/components/Nav/index.js +1 -2
  151. package/dist/theme/components/{Nav/NavTitle.d.ts → NavTitle/index.d.ts} +1 -1
  152. package/dist/theme/components/{Nav/NavTitle.js → NavTitle/index.js} +11 -6
  153. package/dist/theme/components/Overview/index.js +11 -43
  154. package/dist/theme/components/OverviewGroup/index.js +33 -0
  155. package/dist/theme/components/PageTabs/index.css +1 -1
  156. package/dist/theme/components/Steps/index.css +1 -0
  157. package/dist/theme/components/Tabs/index.css +4 -4
  158. package/dist/theme/hooks/useDynamicToc.d.ts +2 -0
  159. package/dist/theme/hooks/useDynamicToc.js +3 -1
  160. package/dist/theme/index.d.ts +3 -1
  161. package/dist/theme/index.js +4 -2
  162. package/dist/theme/layout/Layout/index.js +1 -1
  163. package/dist/theme/logic/useScrollAfterNav.js +2 -2
  164. package/dist/theme/logic/useScrollReset.js +2 -2
  165. package/dist/theme/logic/{useAppearance.d.ts → useThemeState.d.ts} +4 -1
  166. package/dist/theme/logic/useThemeState.js +50 -0
  167. package/dist/theme/styles/scrollbar.css +14 -2
  168. package/package.json +18 -20
  169. package/static/MediumZoom.tsx +1 -1
  170. package/dist/4669.69cb6b18.js +0 -1
  171. package/dist/8813.4b28f4bb.js +0 -1
  172. package/dist/9643.2dff683e.js +0 -4
  173. package/dist/cli/config/index.d.ts +0 -2
  174. package/dist/runtime.72d450ac.js +0 -1
  175. package/dist/runtime.d.ts +0 -2
  176. package/dist/runtime.js +0 -3
  177. package/dist/theme/logic/useAppearance.js +0 -64
  178. /package/dist/{cli/config/index.js → config/defineConfig.js} +0 -0
  179. /package/dist/{cli/config → config}/loadConfigFile.d.ts +0 -0
  180. /package/dist/eject-theme/components/{Nav/NavTitle.scss → NavTitle/index.scss} +0 -0
  181. /package/dist/theme/components/{Nav/NavTitle.css → NavTitle/index.css} +0 -0
@@ -1,4 +1,4 @@
1
- import { mergeRsbuildConfig } from "../3521.9eb6b114.js";
1
+ import { mergeRsbuildConfig } from "../7786.421b464f.js";
2
2
  import { PluginDriver } from "./PluginDriver.js";
3
3
  import { initRsbuild } from "./initRsbuild.js";
4
4
  import { RouteService } from "./route/RouteService.js";
@@ -1,4 +1,4 @@
1
- import { transformHtmlTemplate, pathToFileURL, createHead } from "../../5485.9fc7f63d.js";
1
+ import { transformHtmlTemplate, pathToFileURL, createHead } from "../../5485.7586c86a.js";
2
2
  import { logger, picocolors } from "../../6289.29817fb4.js";
3
3
  import { hintSSGFailed } from "../logger/hint.js";
4
4
  import { renderHtmlTemplate } from "./renderHtmlTemplate.js";
@@ -1,6 +1,6 @@
1
1
  import { workerData } from "./renderPageWorker.165b5d46.js";
2
2
  import { createError } from "../utils/error.js";
3
- import { pMap } from "../../5485.9fc7f63d.js";
3
+ import { pMap } from "../../5485.7586c86a.js";
4
4
  import { renderPage } from "./renderPage.js";
5
5
  const params = workerData?.[1]?.params;
6
6
  if (!params) throw createError('SSG Worker Thread workerData params missing');
@@ -1,8 +1,8 @@
1
1
  /*! For license information please see renderPages.js.LICENSE.txt */
2
2
  import { logger, picocolors } from "../../6289.29817fb4.js";
3
- import { chunk } from "../../3521.9eb6b114.js";
3
+ import { chunk } from "../../7786.421b464f.js";
4
4
  import { SSGWorkerThreadTaskSize, getNumberOfThreads, SSGWorkerThreadRecyclerMaxMemory, SSGConcurrency } from "./ssgEnv.js";
5
- import { pMap } from "../../5485.9fc7f63d.js";
5
+ import { pMap } from "../../5485.7586c86a.js";
6
6
  import { renderPage } from "./renderPage.js";
7
7
  import { hintSSGFailed } from "../logger/hint.js";
8
8
  import { renderHtmlTemplate } from "./renderHtmlTemplate.js";
@@ -33,7 +33,11 @@ async function renderPages(routeService, config, ssrBundlePath, htmlTemplate, em
33
33
  promiseList.push(renderCSRPage(config.head, route, htmlTemplate, emitAsset));
34
34
  } else ssgRoutes.push(route);
35
35
  if (csrRoutes.length > 0) {
36
- logger.warn(`Some routes are ignored in SSG and fallback to CSR via \`ssg.experimentalExcludeRoutePaths\`: ${picocolors.yellow(csrRoutes.map((r)=>r.routePath).join(', '))}`);
36
+ const csrRoutePaths = csrRoutes.map((r)=>r.routePath);
37
+ const MAX_DISPLAY_ROUTES = 10;
38
+ const displayedRoutes = csrRoutePaths.slice(0, MAX_DISPLAY_ROUTES);
39
+ const remainingCount = csrRoutePaths.length - MAX_DISPLAY_ROUTES;
40
+ logger.info(`Some routes (${picocolors.yellow(csrRoutePaths.length)} total) are ignored in SSG and fallback to CSR via \`ssg.experimentalExcludeRoutePaths\`: ${picocolors.yellow(displayedRoutes.join(', '))}${remainingCount > 0 ? picocolors.dim(` ... and ${remainingCount} more`) : ''}`);
37
41
  await Promise.all(promiseList);
38
42
  routes.length = 0;
39
43
  routes.push(...ssgRoutes);
@@ -1,5 +1,5 @@
1
1
  import { logger, writeFile, mkdir, rm, join } from "../../6289.29817fb4.js";
2
- import { isDebugMode } from "../../4669.69cb6b18.js";
2
+ import { isDebugMode } from "../../9348.1beb3e25.js";
3
3
  import { NODE_SSG_BUNDLE_FOLDER, NODE_SSG_BUNDLE_NAME } from "../constants.js";
4
4
  import { renderPages } from "./renderPages.js";
5
5
  const rsbuildPluginSSG = ({ routeService, config })=>({
@@ -1,5 +1,5 @@
1
1
  /*! For license information please see ssgEnv.js.LICENSE.txt */
2
- import { node_os } from "../../9643.2dff683e.js";
2
+ import { node_os } from "../../9348.1beb3e25.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,5 +1,5 @@
1
- import { getSidebarDataGroup } from "../../../4669.69cb6b18.js";
2
- import { matchPath } from "../../../3521.9eb6b114.js";
1
+ import { getSidebarDataGroup } from "../../../9348.1beb3e25.js";
2
+ import { matchPath } from "../../../7786.421b464f.js";
3
3
  import { generateLlmsTxt, generateLlmsFullTxt } from "./llmsTxt.js";
4
4
  async function emitLlmsTxt(config, routeService, emitAsset, mdContents) {
5
5
  const base = config.base ?? '/';
@@ -1,4 +1,4 @@
1
- import { normalizeHref, withBase } from "../../../4669.69cb6b18.js";
1
+ import { normalizeHref, withBase } from "../../../9348.1beb3e25.js";
2
2
  import { extractInfoFromFrontmatterWithAbsolutePath } from "../../auto-nav-sidebar/utils.js";
3
3
  function routePathToMdPath(routePath, base) {
4
4
  let url = routePath;
@@ -17,7 +17,17 @@ async function generateLlmsTxt(routeGroups, others, navList, title, description,
17
17
  const routePage = routeService.getRoutePageByRoutePath(route);
18
18
  const { lang, routePath, absolutePath } = routePage.routeMeta;
19
19
  if ('/' === routePath || routePath === `/${lang}/`) return;
20
- const { title, description } = await extractInfoFromFrontmatterWithAbsolutePath(absolutePath, routeService.getDocsDir());
20
+ const pageInfo = routePage.pageIndexInfo;
21
+ let title;
22
+ let description;
23
+ if (pageInfo) {
24
+ title = pageInfo.title;
25
+ description = pageInfo.description;
26
+ } else {
27
+ const info = await extractInfoFromFrontmatterWithAbsolutePath(absolutePath, routeService.getDocsDir());
28
+ title = info.title;
29
+ description = info.description;
30
+ }
21
31
  return `- [${title}](${routePathToMdPath(routePath, base)})${description ? `: ${description}` : ''}`;
22
32
  }))).filter((i)=>Boolean(i));
23
33
  if (routeLines.length > 0) {
@@ -1,5 +1,5 @@
1
- import { unified, remark_gfm, remark_mdx, remark_stringify } from "../mdx/loader.7c249a26.js";
2
- import { visit } from "../../8813.4b28f4bb.js";
1
+ import { unified, visit, remark_gfm, remark_stringify } from "../../9348.1beb3e25.js";
2
+ import { remark_mdx } from "../mdx/loader.15e0b2d2.js";
3
3
  function remarkSplitMdx(options = {}) {
4
4
  return (tree)=>{
5
5
  const newChildren = [];
@@ -1,4 +1,4 @@
1
- import { pathToFileURL, createHead } from "../../5485.9fc7f63d.js";
1
+ import { pathToFileURL, createHead } from "../../5485.7586c86a.js";
2
2
  import { logger, picocolors } from "../../6289.29817fb4.js";
3
3
  import { hintSSGFailed } from "../logger/hint.js";
4
4
  async function renderPage(route, ssrBundlePath) {
@@ -1,5 +1,5 @@
1
1
  import { logger, picocolors } from "../../6289.29817fb4.js";
2
- import { pMap } from "../../5485.9fc7f63d.js";
2
+ import { pMap } from "../../5485.7586c86a.js";
3
3
  import { renderPage } from "./renderPage.js";
4
4
  import { SSGConcurrency } from "../ssg/ssgEnv.js";
5
5
  const routePage2MdFilename = (routePath)=>{
@@ -1,5 +1,5 @@
1
1
  import { writeFile, mkdir, rm, join } from "../../6289.29817fb4.js";
2
- import { isDebugMode } from "../../4669.69cb6b18.js";
2
+ import { isDebugMode } from "../../9348.1beb3e25.js";
3
3
  import { NODE_SSG_MD_BUNDLE_FOLDER, NODE_SSG_MD_BUNDLE_NAME } from "../constants.js";
4
4
  import { renderPages } from "./renderPages.js";
5
5
  import { emitLlmsTxt } from "./llms/emitLlmsTxt.js";
@@ -1,4 +1,4 @@
1
- import { createHash as external_node_crypto_createHash } from "../../3521.9eb6b114.js";
1
+ import { createHash as external_node_crypto_createHash } from "../../7786.421b464f.js";
2
2
  function createHash(str) {
3
3
  return external_node_crypto_createHash('sha256').update(str).digest('hex').slice(0, 8);
4
4
  }
@@ -1,7 +1,6 @@
1
- import { node_fs, core_rspack } from "../../3521.9eb6b114.js";
1
+ import { node_fs, core_rspack } from "../../7786.421b464f.js";
2
2
  import { node_path, logger } from "../../6289.29817fb4.js";
3
- import { createProcessor } from "../../9643.2dff683e.js";
4
- import { MDX_OR_MD_REGEXP } from "../../4669.69cb6b18.js";
3
+ import { createProcessor, MDX_OR_MD_REGEXP } from "../../9348.1beb3e25.js";
5
4
  import { createError } from "./error.js";
6
5
  import { importStatementRegex } from "../constants.js";
7
6
  const RspackResolveFactory = core_rspack.experiments.resolver.ResolverFactory;
@@ -1,4 +1,4 @@
1
- import { removeLeadingSlash } from "../../4669.69cb6b18.js";
1
+ import { removeLeadingSlash } from "../../9348.1beb3e25.js";
2
2
  function getPageKey(route) {
3
3
  const cleanRoute = removeLeadingSlash(route);
4
4
  return cleanRoute.replace(/\//g, '_').replace(/\.[^.]+$/, '') || 'index';
@@ -1,4 +1,4 @@
1
- import { node_os } from "../../9643.2dff683e.js";
1
+ import { node_os } from "../../9348.1beb3e25.js";
2
2
  import { node_path } from "../../6289.29817fb4.js";
3
3
  const isWindows = 'win32' === node_os.platform();
4
4
  function slash(p) {
@@ -1,5 +1,5 @@
1
1
  import { node_path, logger, picocolors } from "../../6289.29817fb4.js";
2
- import { core_rspack } from "../../3521.9eb6b114.js";
2
+ import { core_rspack } from "../../7786.421b464f.js";
3
3
  import { pathExists, readJson } from "./fs.js";
4
4
  import { PACKAGE_ROOT } from "../constants.js";
5
5
  import { hintReactVersion } from "../logger/hint.js";
@@ -0,0 +1,4 @@
1
+ import { type ReactNode } from 'react';
2
+ export declare const Content: ({ fallback }: {
3
+ fallback?: ReactNode;
4
+ }) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,18 @@
1
+ import { Fragment, jsx } from "react/jsx-runtime";
2
+ import { Suspense, useMemo } from "react";
3
+ import { useLocation } from "react-router-dom";
4
+ import { pathnameToRouteService } from "./route.js";
5
+ const Content = ({ fallback = /*#__PURE__*/ jsx(Fragment, {}) })=>{
6
+ const { pathname } = useLocation();
7
+ const matchedElement = useMemo(()=>{
8
+ const route = pathnameToRouteService(pathname);
9
+ return route?.element;
10
+ }, [
11
+ pathname
12
+ ]);
13
+ return /*#__PURE__*/ jsx(Suspense, {
14
+ fallback: fallback,
15
+ children: matchedElement
16
+ });
17
+ };
18
+ export { Content };
@@ -0,0 +1,3 @@
1
+ export declare function NoSSR(props: {
2
+ children: React.ReactNode;
3
+ }): import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,14 @@
1
+ import { Fragment, jsx } from "react/jsx-runtime";
2
+ import { useEffect, useState } from "react";
3
+ function NoSSR(props) {
4
+ const { children } = props;
5
+ const [isMounted, setIsMounted] = useState(false);
6
+ useEffect(()=>{
7
+ setIsMounted(true);
8
+ }, []);
9
+ if (!isMounted) return null;
10
+ return /*#__PURE__*/ jsx(Fragment, {
11
+ children: children
12
+ });
13
+ }
14
+ export { NoSSR };
@@ -0,0 +1,68 @@
1
+ import { describe, expect, it, rs } from "@rstest/core";
2
+ import { getSidebarDataGroup } from "./hooks/useSidebar.js";
3
+ import { isActive } from "./route.js";
4
+ rs.mock('virtual-i18n-text', ()=>({
5
+ default: {}
6
+ }));
7
+ rs.mock('virtual-site-data', ()=>({
8
+ default: {
9
+ base: '/'
10
+ }
11
+ }));
12
+ rs.mock('virtual-routes', ()=>({
13
+ routes: []
14
+ }));
15
+ describe('getSidebarDataGroup', ()=>{
16
+ it('when using "/"', async ()=>{
17
+ expect(getSidebarDataGroup({
18
+ '/': [],
19
+ '/guide': [
20
+ {
21
+ text: 'Getting Started',
22
+ link: '/guide/getting-started'
23
+ }
24
+ ]
25
+ }, '/guide/getting-started')).toMatchInlineSnapshot(`
26
+ [
27
+ {
28
+ "link": "/guide/getting-started",
29
+ "text": "Getting Started",
30
+ },
31
+ ]
32
+ `);
33
+ });
34
+ it('when using api-extractor', async ()=>{
35
+ expect(getSidebarDataGroup({
36
+ '/api/react': [
37
+ {
38
+ link: '/api/react.use',
39
+ text: 'react.use'
40
+ }
41
+ ]
42
+ }, '/api/react.use.html')).toMatchInlineSnapshot(`
43
+ [
44
+ {
45
+ "link": "/api/react.use",
46
+ "text": "react.use",
47
+ },
48
+ ]
49
+ `);
50
+ });
51
+ });
52
+ describe('isActive', ()=>{
53
+ it('pass cases', ()=>{
54
+ const routes = [
55
+ '/api/config',
56
+ '/api/config.html',
57
+ '/api/config/',
58
+ '/api/config/index',
59
+ '/api/config/index.html'
60
+ ];
61
+ for (const route of routes)for (const route2 of routes)expect(isActive(route, route2)).toBeTruthy();
62
+ });
63
+ it('failed cases', ()=>{
64
+ expect(isActive('/api/config', '/api/config2')).toBeFalsy();
65
+ expect(isActive('/api/config', '/api/config/config2')).toBeFalsy();
66
+ expect(isActive('/api/config/index', '/api/config/config2')).toBeFalsy();
67
+ });
68
+ });
@@ -0,0 +1 @@
1
+ export declare const useActiveMatcher: () => (link: string) => boolean;
@@ -0,0 +1,14 @@
1
+ import { useCallback } from "react";
2
+ import { useLocation } from "react-router-dom";
3
+ import { isActive } from "../route.js";
4
+ const useActiveMatcher = ()=>{
5
+ const { pathname: rawPathname } = useLocation();
6
+ const activeMatcher = useCallback((link)=>{
7
+ const pathname = decodeURIComponent(rawPathname);
8
+ return isActive(link, pathname);
9
+ }, [
10
+ rawPathname
11
+ ]);
12
+ return activeMatcher;
13
+ };
14
+ export { useActiveMatcher };
@@ -0,0 +1,7 @@
1
+ interface IThemeContext {
2
+ theme: 'light' | 'dark';
3
+ setTheme?: (theme: 'light' | 'dark') => void;
4
+ }
5
+ export declare const ThemeContext: import("react").Context<IThemeContext>;
6
+ export declare function useDark(): boolean;
7
+ export {};
@@ -0,0 +1,7 @@
1
+ import { createContext, useContext } from "react";
2
+ const ThemeContext = createContext({});
3
+ function useDark() {
4
+ const ctx = useContext(ThemeContext);
5
+ return 'dark' === ctx.theme;
6
+ }
7
+ export { ThemeContext, useDark };
@@ -0,0 +1,4 @@
1
+ import type { FrontMatterMeta } from '@rspress/shared';
2
+ export declare const useFrontmatter: () => {
3
+ frontmatter: FrontMatterMeta;
4
+ };
@@ -0,0 +1,9 @@
1
+ import { usePage } from "./usePage.js";
2
+ const useFrontmatter = ()=>{
3
+ const { page } = usePage();
4
+ const { frontmatter = {} } = page;
5
+ return {
6
+ frontmatter
7
+ };
8
+ };
9
+ export { useFrontmatter };
@@ -0,0 +1,2 @@
1
+ import type { I18nText } from '@rspress/shared';
2
+ export declare function useI18n<T>(): (key: keyof (T & I18nText), params?: Record<string, string>) => string;
@@ -0,0 +1,14 @@
1
+ import { useCallback } from "react";
2
+ import virtual_i18n_text from "virtual-i18n-text";
3
+ import { useLang } from "./useLang.js";
4
+ function useI18n() {
5
+ const lang = useLang();
6
+ return useCallback((key, params)=>{
7
+ const text = virtual_i18n_text[key]?.[lang];
8
+ if ('string' != typeof text) throw new Error(`i18n key "${key}" not found for language "${lang}"`);
9
+ return text.replace(/\{\{(\w+)\}\}/g, (_, p1)=>params?.[p1] ?? `${p1}`);
10
+ }, [
11
+ lang
12
+ ]);
13
+ }
14
+ export { useI18n };
@@ -0,0 +1 @@
1
+ export declare function useLang(): string;
@@ -0,0 +1,6 @@
1
+ import { usePage } from "./usePage.js";
2
+ function useLang() {
3
+ const { page } = usePage();
4
+ return page.lang || '';
5
+ }
6
+ export { useLang };
@@ -0,0 +1,18 @@
1
+ import { type NormalizedLocales } from '@rspress/shared';
2
+ /**
3
+ * @deprecated should use useSite and useLang instead
4
+ *
5
+ * ```ts
6
+ * const site = useSite();
7
+ * const lang = useLang();
8
+ * const locales = site.themeConfig.locales;
9
+ * const localeInfo = locales?.find((locale) => locale.lang === lang);
10
+ * ```
11
+ *
12
+ * For i18n text:
13
+ * ```ts
14
+ * const t = useI18n();
15
+ * <div>{t('outlineTitle')}</div>;
16
+ * ```
17
+ */
18
+ export declare function useLocaleSiteData(): NormalizedLocales;
@@ -0,0 +1,20 @@
1
+ import { addTrailingSlash } from "@rspress/shared";
2
+ import { useLang } from "./useLang.js";
3
+ import { useSite } from "./useSite.js";
4
+ function useLocaleSiteData() {
5
+ const { site } = useSite();
6
+ const lang = useLang();
7
+ const themeConfig = site?.themeConfig ?? {};
8
+ const defaultLang = site.lang ?? '';
9
+ const locales = themeConfig?.locales;
10
+ if (!locales || 0 === locales.length) return {
11
+ nav: themeConfig.nav,
12
+ sidebar: themeConfig.sidebar
13
+ };
14
+ const localeInfo = locales.find((locale)=>locale.lang === lang);
15
+ return {
16
+ ...localeInfo,
17
+ langRoutePrefix: lang === defaultLang ? '/' : addTrailingSlash(lang)
18
+ };
19
+ }
20
+ export { useLocaleSiteData };
@@ -0,0 +1 @@
1
+ export declare function useNav(): import("@rspress/shared").NavItem[];
@@ -0,0 +1,12 @@
1
+ import { useLocaleSiteData } from "./useLocaleSiteData.js";
2
+ import { useVersion } from "./useVersion.js";
3
+ function useNav() {
4
+ const { nav } = useLocaleSiteData();
5
+ const version = useVersion();
6
+ if (Array.isArray(nav)) return nav;
7
+ const navKey = version.length > 0 ? version : 'default';
8
+ return [
9
+ ...nav[navKey]
10
+ ];
11
+ }
12
+ export { useNav };
@@ -0,0 +1,10 @@
1
+ import type { PageDataLegacy } from '@rspress/shared';
2
+ interface IPageContext {
3
+ data: PageDataLegacy['page'];
4
+ setData?: (data: PageDataLegacy['page']) => void;
5
+ }
6
+ export declare const PageContext: import("react").Context<IPageContext>;
7
+ export declare function usePage(): {
8
+ page: PageDataLegacy['page'];
9
+ };
10
+ export {};
@@ -0,0 +1,9 @@
1
+ import { createContext, useContext } from "react";
2
+ const PageContext = createContext({});
3
+ function usePage() {
4
+ const ctx = useContext(PageContext);
5
+ return {
6
+ page: ctx.data
7
+ };
8
+ }
9
+ export { PageContext, usePage };
@@ -0,0 +1,5 @@
1
+ import type { PageDataLegacy } from '@rspress/shared';
2
+ /**
3
+ * should use `usePage` and `useSite` instead
4
+ */
5
+ export declare function usePageData(): PageDataLegacy;
@@ -0,0 +1,16 @@
1
+ import { usePage } from "./usePage.js";
2
+ import { usePages } from "./usePages.js";
3
+ import { useSite } from "./useSite.js";
4
+ function usePageData() {
5
+ const { page } = usePage();
6
+ const { pages } = usePages();
7
+ const { site } = useSite();
8
+ return {
9
+ page,
10
+ siteData: {
11
+ ...site,
12
+ pages
13
+ }
14
+ };
15
+ }
16
+ export { usePageData };
@@ -0,0 +1,4 @@
1
+ import type { PageData } from '@rspress/shared';
2
+ export declare function usePages(): {
3
+ pages: PageData['pages'];
4
+ };
@@ -0,0 +1,7 @@
1
+ import { pageData } from "virtual-page-data";
2
+ function usePages() {
3
+ return {
4
+ pages: pageData.pages
5
+ };
6
+ }
7
+ export { usePages };
@@ -0,0 +1,16 @@
1
+ import { type NormalizedSidebar, type SidebarData } from '@rspress/shared';
2
+ /**
3
+ * get the sidebar group for the current page
4
+ * @param sidebar const { sidebar } = useLocaleSiteData();
5
+ * @param currentPathname
6
+ * @returns
7
+ */
8
+ export declare const getSidebarDataGroup: (sidebar: NormalizedSidebar, currentPathname: string) => SidebarData;
9
+ export declare function useSidebar(): SidebarData;
10
+ /**
11
+ * handle the collapsed state of the sidebar groups
12
+ */
13
+ export declare function useSidebarDynamic(): [
14
+ SidebarData,
15
+ React.Dispatch<React.SetStateAction<SidebarData>>
16
+ ];
@@ -0,0 +1,67 @@
1
+ import { matchSidebar } from "@rspress/shared";
2
+ import { useLayoutEffect, useMemo, useState } from "react";
3
+ import { useLocation } from "react-router-dom";
4
+ import { useActiveMatcher } from "./useActiveMatcher.js";
5
+ import { useLocaleSiteData } from "./useLocaleSiteData.js";
6
+ const getSidebarDataGroup = (sidebar, currentPathname)=>{
7
+ const navRoutes = Object.keys(sidebar).sort((a, b)=>b.length - a.length);
8
+ for (const name of navRoutes)if (matchSidebar(name, currentPathname)) {
9
+ const sidebarGroup = sidebar[name];
10
+ return sidebarGroup;
11
+ }
12
+ return [];
13
+ };
14
+ function useSidebar() {
15
+ const { sidebar } = useLocaleSiteData();
16
+ const { pathname: rawPathname } = useLocation();
17
+ const pathname = decodeURIComponent(rawPathname);
18
+ const sidebarData = useMemo(()=>getSidebarDataGroup(sidebar, pathname), [
19
+ sidebar,
20
+ pathname
21
+ ]);
22
+ return sidebarData;
23
+ }
24
+ function createInitialSidebar(rawSidebarData, activeMatcher) {
25
+ const matchCache = new WeakMap();
26
+ const match = (item)=>{
27
+ if (matchCache.has(item)) return matchCache.get(item);
28
+ if ('link' in item && item.link && activeMatcher(item.link)) {
29
+ matchCache.set(item, true);
30
+ return true;
31
+ }
32
+ if ('items' in item) {
33
+ const result = item.items.some((child)=>match(child));
34
+ if (result) {
35
+ matchCache.set(item, true);
36
+ return true;
37
+ }
38
+ }
39
+ matchCache.set(item, false);
40
+ return false;
41
+ };
42
+ const traverse = (item)=>{
43
+ if ('items' in item) {
44
+ item.items.forEach(traverse);
45
+ if (match(item)) item.collapsed = false;
46
+ }
47
+ };
48
+ const newSidebarData = rawSidebarData.filter(Boolean).flat();
49
+ newSidebarData.forEach(traverse);
50
+ return newSidebarData;
51
+ }
52
+ function useSidebarDynamic() {
53
+ const rawSidebarData = useSidebar();
54
+ const activeMatcher = useActiveMatcher();
55
+ const [sidebar, setSidebar] = useState(()=>createInitialSidebar(structuredClone(rawSidebarData), activeMatcher));
56
+ useLayoutEffect(()=>{
57
+ setSidebar(createInitialSidebar(rawSidebarData, activeMatcher));
58
+ }, [
59
+ activeMatcher,
60
+ rawSidebarData
61
+ ]);
62
+ return [
63
+ sidebar,
64
+ setSidebar
65
+ ];
66
+ }
67
+ export { getSidebarDataGroup, useSidebar, useSidebarDynamic };
@@ -0,0 +1,4 @@
1
+ import type { SiteData } from '@rspress/shared';
2
+ export declare function useSite(): {
3
+ site: SiteData;
4
+ };
@@ -0,0 +1,7 @@
1
+ import virtual_site_data from "virtual-site-data";
2
+ function useSite() {
3
+ return {
4
+ site: virtual_site_data
5
+ };
6
+ }
7
+ export { useSite };
@@ -0,0 +1 @@
1
+ export declare function useVersion(): string;
@@ -0,0 +1,6 @@
1
+ import { usePage } from "./usePage.js";
2
+ function useVersion() {
3
+ const { page } = usePage();
4
+ return page.version || '';
5
+ }
6
+ export { useVersion };
@@ -0,0 +1,9 @@
1
+ declare global {
2
+ interface Window {
3
+ __MODERN_PAGE_DATA__: any;
4
+ }
5
+ }
6
+ export declare function useWindowSize(initialWidth?: number, initialHeight?: number): {
7
+ width: number;
8
+ height: number;
9
+ };