@rspress/core 2.0.21 → 2.0.22

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 (153) hide show
  1. package/dist/cli/index.js +12 -13
  2. package/dist/config/loadConfigFile.d.ts +3 -4
  3. package/dist/config/loadConfigFile.js +13 -17
  4. package/dist/{7748~0.js → d~0.js} +0 -2
  5. package/dist/eject-theme/components/Llms/LlmsHint.test.tsx +8 -0
  6. package/dist/eject-theme/components/Llms/LlmsHint.tsx +11 -3
  7. package/dist/eject-theme/components/Nav/NavMenu.scss +4 -0
  8. package/dist/eject-theme/components/Nav/NavMenu.tsx +20 -13
  9. package/dist/eject-theme/components/Nav/index.tsx +30 -4
  10. package/dist/eject-theme/components/NavHamburger/index.tsx +11 -3
  11. package/dist/eject-theme/components/NavList/context.ts +3 -0
  12. package/dist/eject-theme/components/NavList/index.tsx +24 -0
  13. package/dist/eject-theme/components/NavScreen/NavScreenMenu.test.tsx +59 -0
  14. package/dist/eject-theme/components/NavScreen/NavScreenMenu.tsx +43 -2
  15. package/dist/eject-theme/components/NavScreen/index.scss +0 -6
  16. package/dist/eject-theme/components/NavScreen/index.tsx +20 -3
  17. package/dist/eject-theme/components/ReadPercent/useReadPercent.ts +1 -1
  18. package/dist/eject-theme/components/Search/SearchButton.scss +1 -0
  19. package/dist/eject-theme/components/Search/SearchPanel.scss +51 -12
  20. package/dist/eject-theme/components/Search/SearchPanel.tsx +54 -212
  21. package/dist/eject-theme/components/Search/logic/providers/LocalProvider.ts +38 -16
  22. package/dist/eject-theme/components/Search/useSearchPanel.ts +216 -0
  23. package/dist/eject-theme/components/Steps/index.scss +1 -1
  24. package/dist/eject-theme/components/SwitchAppearance/getClipPath.test.ts +15 -0
  25. package/dist/eject-theme/components/SwitchAppearance/getClipPath.ts +26 -0
  26. package/dist/eject-theme/components/SwitchAppearance/index.tsx +22 -26
  27. package/dist/eject-theme/components/Tabs/index.tsx +14 -14
  28. package/dist/index.js +1 -1
  29. package/dist/node/PluginDriver.d.ts +1 -1
  30. package/dist/node/PluginDriver.js +5 -9
  31. package/dist/node/auto-nav-sidebar/index.js +1 -1
  32. package/dist/node/auto-nav-sidebar/locales.js +1 -1
  33. package/dist/node/auto-nav-sidebar/normalize.js +6 -6
  34. package/dist/node/auto-nav-sidebar/utils.js +1 -1
  35. package/dist/node/auto-nav-sidebar/walk.js +1 -1
  36. package/dist/node/build.d.ts +3 -2
  37. package/dist/node/build.js +9 -3
  38. package/dist/node/constants.js +1 -1
  39. package/dist/node/dev.d.ts +4 -4
  40. package/dist/node/dev.js +8 -6
  41. package/dist/node/eject.js +5 -5
  42. package/dist/node/initRsbuild.d.ts +2 -3
  43. package/dist/node/initRsbuild.js +9 -7
  44. package/dist/node/last-updated/index.js +2 -2
  45. package/dist/node/logger/hint.js +4 -4
  46. package/dist/node/mdx/options.js +1 -1
  47. package/dist/node/mdx/processor.js +3 -3
  48. package/dist/node/mdx/rehypePlugins/codeMeta.js +1 -1
  49. package/dist/node/mdx/rehypePlugins/headerAnchor.js +1 -1
  50. package/dist/node/mdx/rehypePlugins/shiki.js +1 -1
  51. package/dist/node/mdx/remarkPlugins/builtin.js +1 -1
  52. package/dist/node/mdx/remarkPlugins/containerSyntax.js +6 -5
  53. package/dist/node/mdx/remarkPlugins/fileCodeBlock.js +5 -5
  54. package/dist/node/mdx/remarkPlugins/image.js +5 -5
  55. package/dist/node/mdx/remarkPlugins/link.js +5 -5
  56. package/dist/node/mdx/remarkPlugins/toc.js +1 -1
  57. package/dist/node/medium-zoom/index.js +1 -1
  58. package/dist/node/route/RoutePage.js +6 -4
  59. package/dist/node/route/RouteService.js +3 -3
  60. package/dist/node/route/extractPageData.js +20 -7
  61. package/dist/node/route/normalizeRoutePath.js +1 -1
  62. package/dist/node/runtimeModule/i18n.js +5 -5
  63. package/dist/node/runtimeModule/pageData/createPageData.js +1 -1
  64. package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
  65. package/dist/node/runtimeModule/searchHooks.js +1 -1
  66. package/dist/node/runtimeModule/siteData/createSiteData.js +1 -1
  67. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
  68. package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +1 -1
  69. package/dist/node/serve.d.ts +3 -3
  70. package/dist/node/serve.js +10 -4
  71. package/dist/node/ssg/alternateLinks.js +1 -1
  72. package/dist/node/ssg/htmlFile.js +1 -1
  73. package/dist/node/ssg/renderHtmlTemplate.js +1 -1
  74. package/dist/node/ssg/renderPage.js +5 -5
  75. package/dist/node/ssg/renderPageWorker.js +2 -2
  76. package/dist/node/ssg/renderPages.js +6 -6
  77. package/dist/node/ssg/rsbuildPluginSSG.js +1 -1
  78. package/dist/node/ssg/ssgEnv.js +1 -1
  79. package/dist/node/ssg-md/llms/emitLlmsTxt.js +1 -1
  80. package/dist/node/ssg-md/llms/llmsTxt.js +1 -1
  81. package/dist/node/ssg-md/remarkSplitMdx.js +1 -1
  82. package/dist/node/ssg-md/renderPage.js +5 -5
  83. package/dist/node/ssg-md/renderPages.js +6 -6
  84. package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
  85. package/dist/node/utils/checkLanguageParity.js +5 -7
  86. package/dist/node/utils/createHash.js +1 -1
  87. package/dist/node/utils/error.js +4 -4
  88. package/dist/node/utils/flattenMdxContent.js +2 -2
  89. package/dist/node/utils/fs.js +1 -1
  90. package/dist/node/utils/getPageKey.js +1 -1
  91. package/dist/node/utils/index.d.ts +1 -1
  92. package/dist/node/utils/reactAlias.js +5 -5
  93. package/dist/node/utils/slash.d.ts +1 -0
  94. package/dist/node/utils/slash.js +4 -0
  95. package/dist/{864~0.js → n~0.js} +41 -41
  96. package/dist/{2711~0.js → o~0.js} +90 -56
  97. package/dist/rslib-runtime~0.js +27 -35
  98. package/dist/theme/components/Link/useLinkNavigate.js +1 -1
  99. package/dist/theme/components/Llms/LlmsHint.js +23 -6
  100. package/dist/theme/components/Nav/NavMenu.css +4 -0
  101. package/dist/theme/components/Nav/NavMenu.d.ts +4 -2
  102. package/dist/theme/components/Nav/NavMenu.js +17 -9
  103. package/dist/theme/components/Nav/index.d.ts +7 -1
  104. package/dist/theme/components/Nav/index.js +13 -4
  105. package/dist/theme/components/NavHamburger/index.d.ts +2 -1
  106. package/dist/theme/components/NavHamburger/index.js +8 -2
  107. package/dist/theme/components/NavList/context.d.ts +1 -0
  108. package/dist/theme/components/NavList/context.js +3 -0
  109. package/dist/theme/components/NavList/index.d.ts +6 -0
  110. package/dist/theme/components/NavList/index.js +17 -0
  111. package/dist/theme/components/NavScreen/NavScreenMenu.d.ts +3 -2
  112. package/dist/theme/components/NavScreen/NavScreenMenu.js +42 -6
  113. package/dist/theme/components/NavScreen/index.css +0 -10
  114. package/dist/theme/components/NavScreen/index.d.ts +2 -1
  115. package/dist/theme/components/NavScreen/index.js +11 -3
  116. package/dist/theme/components/PackageManagerTabs/index.js +2 -2
  117. package/dist/theme/components/ReadPercent/useReadPercent.js +1 -0
  118. package/dist/theme/components/Search/SearchButton.css +1 -0
  119. package/dist/theme/components/Search/SearchPanel.css +47 -9
  120. package/dist/theme/components/Search/SearchPanel.js +97 -205
  121. package/dist/theme/components/Search/logic/providers/LocalProvider.d.ts +1 -0
  122. package/dist/theme/components/Search/logic/providers/LocalProvider.js +23 -13
  123. package/dist/theme/components/Search/logic/search.js +1 -1
  124. package/dist/theme/components/Search/useSearchPanel.d.ts +23 -0
  125. package/dist/theme/components/Search/useSearchPanel.js +155 -0
  126. package/dist/theme/components/Steps/index.css +3 -3
  127. package/dist/theme/components/SwitchAppearance/getClipPath.d.ts +8 -0
  128. package/dist/theme/components/SwitchAppearance/getClipPath.js +13 -0
  129. package/dist/theme/components/SwitchAppearance/index.js +9 -7
  130. package/dist/theme/components/Tabs/index.js +4 -4
  131. package/dist/theme/components/Tag/index.js +2 -2
  132. package/dist/theme/index.d.ts +1 -0
  133. package/dist/theme/index.js +1 -0
  134. package/dist/theme/layout/DocLayout/index.js +2 -2
  135. package/dist/theme/layout/Layout/index.js +12 -4
  136. package/dist/theme/logic/useFullTextSearch.js +6 -1
  137. package/dist/theme/styles/vars/shiki-vars.css +1 -1
  138. package/dist/tinypool~0.js +5 -3
  139. package/dist/{4538~0.js → t~0.js} +2 -2
  140. package/dist/{8472~0.js → v~0.js} +1 -1
  141. package/package.json +11 -12
  142. package/dist/eject-theme/components/NavScreen/NavScreenMenuOthers.tsx +0 -29
  143. package/dist/node/utils/normalizePath.d.ts +0 -3
  144. package/dist/node/utils/normalizePath.js +0 -10
  145. package/dist/theme/components/NavScreen/NavScreenMenuOthers.d.ts +0 -2
  146. package/dist/theme/components/NavScreen/NavScreenMenuOthers.js +0 -30
  147. package/dist/theme/logic/useHandler.d.ts +0 -6
  148. package/dist/theme/logic/useHandler.js +0 -7
  149. /package/dist/{9857~0.js → 4~0.js} +0 -0
  150. /package/dist/{8016~0.js → i~0.js} +0 -0
  151. /package/dist/{5357~0.js → r~0.js} +0 -0
  152. /package/dist/{102~0.js → t2~0.js} +0 -0
  153. /package/dist/{9940~0.js → tx~0.js} +0 -0
package/dist/cli/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { logger, cac } from "../2711~0.js";
2
- import { package_namespaceObject } from "../8472~0.js";
1
+ import { logger, cac } from "../o~0.js";
2
+ import { package_namespaceObject } from "../v~0.js";
3
3
  import { loadConfigFile, resolveDocRoot } from "../config/loadConfigFile.js";
4
4
  import { dev } from "../node/dev.js";
5
5
  import { build } from "../node/build.js";
@@ -19,15 +19,14 @@ function runCLI({ argv = process.argv } = {}) {
19
19
  let devServer;
20
20
  const startDevServer = async ()=>{
21
21
  const { port, host } = options || {};
22
- const { config, configFilePath } = await loadConfigFile(options?.config);
22
+ const configResult = await loadConfigFile(options?.config);
23
+ const { content: config } = configResult;
23
24
  config.root = resolveDocRoot(cwd, root, config.root);
24
25
  if (options?.base) config.base = options.base;
25
26
  const docDirectory = config.root;
26
27
  devServer = await dev({
27
- appDirectory: cwd,
28
28
  docDirectory,
29
- config,
30
- configFilePath,
29
+ config: configResult,
31
30
  extraBuilderConfig: {
32
31
  server: {
33
32
  port,
@@ -60,15 +59,15 @@ function runCLI({ argv = process.argv } = {}) {
60
59
  cli.command('build [root]', 'Build the documentation site for production').option('--base <base>', 'Set the base path and override config.base').action(async (root, options)=>{
61
60
  setNodeEnv('production');
62
61
  const cwd = process.cwd();
63
- const { config, configFilePath } = await loadConfigFile(options.config);
62
+ const configResult = await loadConfigFile(options.config);
63
+ const { content: config } = configResult;
64
64
  config.root = resolveDocRoot(cwd, root, config.root);
65
65
  if (options.base) config.base = options.base;
66
66
  const docDirectory = config.root;
67
67
  try {
68
68
  await build({
69
69
  docDirectory,
70
- config,
71
- configFilePath
70
+ config: configResult
72
71
  });
73
72
  } catch (err) {
74
73
  logger.error(err);
@@ -79,14 +78,14 @@ function runCLI({ argv = process.argv } = {}) {
79
78
  setNodeEnv('production');
80
79
  const cwd = process.cwd();
81
80
  const { port, host } = options || {};
82
- const { config, configFilePath } = await loadConfigFile(options?.config);
81
+ const configResult = await loadConfigFile(options?.config);
82
+ const { content: config } = configResult;
83
83
  config.root = resolveDocRoot(cwd, root, config.root);
84
84
  if (options?.base) config.base = options.base;
85
85
  await serve({
86
- config,
86
+ config: configResult,
87
87
  host,
88
- port,
89
- configFilePath
88
+ port
90
89
  });
91
90
  });
92
91
  cli.command('eject [component]', 'Eject a theme component for customization').action(async (component)=>{
@@ -1,6 +1,5 @@
1
+ import type { LoadConfigResult } from '@rsbuild/core';
1
2
  import type { UserConfig } from '@rspress/shared';
2
- export declare function loadConfigFile(customConfigFile?: string): Promise<{
3
- config: UserConfig;
4
- configFilePath: string;
5
- }>;
3
+ export declare function loadConfigFile(customConfigFile?: string): Promise<LoadConfigResult<UserConfig>>;
4
+ export declare function normalizeConfigResult(config: UserConfig | LoadConfigResult<UserConfig>, configFilePath?: string): LoadConfigResult<UserConfig>;
6
5
  export declare function resolveDocRoot(cwd: string, cliRoot?: string, configRoot?: string): string;
@@ -1,23 +1,19 @@
1
- import { node_fs, node_path, logger, DEFAULT_CONFIG_NAME, DEFAULT_CONFIG_EXTENSIONS } from "../2711~0.js";
2
- const findConfig = (basePath)=>DEFAULT_CONFIG_EXTENSIONS.map((ext)=>basePath + ext).find(node_fs.existsSync);
1
+ import { node_path, logger, DEFAULT_CONFIG_NAME, DEFAULT_CONFIG_EXTENSIONS } from "../o~0.js";
3
2
  async function loadConfigFile(customConfigFile) {
4
- const baseDir = process.cwd();
5
- const configFilePath = customConfigFile ? node_path.isAbsolute(customConfigFile) ? customConfigFile : node_path.join(baseDir, customConfigFile) : findConfig(node_path.join(baseDir, DEFAULT_CONFIG_NAME));
6
- if (!configFilePath) {
7
- logger.info(`No config file found in ${baseDir}`);
8
- return {
9
- config: {},
10
- configFilePath: ''
11
- };
12
- }
13
3
  const { loadConfig } = await import("@rsbuild/core");
14
- const { content } = await loadConfig({
15
- cwd: node_path.dirname(configFilePath),
16
- path: configFilePath
4
+ const result = await loadConfig({
5
+ path: customConfigFile,
6
+ configFileNames: DEFAULT_CONFIG_EXTENSIONS.map((ext)=>DEFAULT_CONFIG_NAME + ext)
17
7
  });
8
+ if (!result.filePath) logger.info(`No config file found in ${process.cwd()}`);
9
+ return result;
10
+ }
11
+ function normalizeConfigResult(config, configFilePath) {
12
+ if ('content' in config && 'filePath' in config && 'dependencies' in config) return config;
18
13
  return {
19
- config: content,
20
- configFilePath
14
+ content: config,
15
+ filePath: configFilePath || null,
16
+ dependencies: []
21
17
  };
22
18
  }
23
19
  function resolveDocRoot(cwd, cliRoot, configRoot) {
@@ -25,4 +21,4 @@ function resolveDocRoot(cwd, cliRoot, configRoot) {
25
21
  if (configRoot) return node_path.isAbsolute(configRoot) ? configRoot : node_path.join(cwd, configRoot);
26
22
  return node_path.join(cwd, 'docs');
27
23
  }
28
- export { loadConfigFile, resolveDocRoot };
24
+ export { loadConfigFile, normalizeConfigResult, resolveDocRoot };
@@ -1,5 +1,3 @@
1
1
  export { default as github_slugger, slug } from "@rspress/shared/github-slugger";
2
2
  export { extractTextAndId } from "@rspress/shared/node-utils";
3
3
  export { visitChildren } from "unist-util-visit-children";
4
- export { default as node_os } from "node:os";
5
- export { default as node_path } from "node:path";
@@ -1,3 +1,4 @@
1
+ import type React from 'react';
1
2
  import { afterEach, describe, expect, it, rs } from '@rstest/core';
2
3
  import { renderToStaticMarkup } from 'react-dom/server';
3
4
  import { renderToMarkdownString } from 'react-render-to-markdown';
@@ -21,6 +22,7 @@ let page = defaultPage;
21
22
  let site = defaultSite;
22
23
 
23
24
  rs.mock('@rspress/core/runtime', () => ({
25
+ Head: ({ children }: { children?: React.ReactNode }) => <>{children}</>,
24
26
  routePathToMdPath: (path: string) => `/docs${path}index.md`,
25
27
  usePage: () => ({ page }),
26
28
  useSite: () => ({ site }),
@@ -58,6 +60,12 @@ describe('LlmsHint', () => {
58
60
  expect(html).toContain(
59
61
  'For AI agents: the complete documentation index is available at https://example.com/docs/llms.txt, the full documentation bundle is available at https://example.com/docs/llms-full.txt, and this page is available as Markdown at https://example.com/docs/guide/index.md.',
60
62
  );
63
+ expect(html).toContain(
64
+ '<link rel="alternate" type="text/markdown" href="https://example.com/docs/guide/index.md"/>',
65
+ );
66
+ expect(html).toContain(
67
+ '<link rel="describedby" href="https://example.com/docs/llms.txt"/>',
68
+ );
61
69
  });
62
70
 
63
71
  it('renders a blockquote string when SSG_MD is enabled', async () => {
@@ -4,7 +4,9 @@ import {
4
4
  useSite,
5
5
  withBase,
6
6
  withSiteOrigin,
7
+ Head,
7
8
  } from '@rspress/core/runtime';
9
+
8
10
  import type React from 'react';
9
11
 
10
12
  const visuallyHiddenStyle: React.CSSProperties = {
@@ -67,8 +69,14 @@ export function LlmsHint() {
67
69
  });
68
70
 
69
71
  return (
70
- <div className="rp-llms-hint" style={visuallyHiddenStyle}>
71
- {hintText}
72
- </div>
72
+ <>
73
+ <Head>
74
+ <link rel="alternate" type="text/markdown" href={pageMdUrl} />
75
+ <link rel="describedby" href={llmsTxtUrl} />
76
+ </Head>
77
+ <div className="rp-llms-hint" style={visuallyHiddenStyle}>
78
+ {hintText}
79
+ </div>
80
+ </>
73
81
  );
74
82
  }
@@ -6,6 +6,10 @@
6
6
  height: 100%;
7
7
  list-style: none;
8
8
 
9
+ &:empty {
10
+ display: none;
11
+ }
12
+
9
13
  @media (max-width: 1279px) {
10
14
  --rp-nav-menu-item-gap: 24px;
11
15
  }
@@ -15,9 +15,9 @@ import {
15
15
  } from '@rspress/core/theme';
16
16
  import cls from 'clsx';
17
17
  import { type ReactNode, useMemo } from 'react';
18
+ import { NavListContext } from '../NavList/context';
18
19
  import { useLangsMenu, useVersionsMenu } from './hooks';
19
20
  import './NavMenu.scss';
20
- import clsx from 'clsx';
21
21
 
22
22
  export const SvgDown = (props: React.SVGProps<SVGSVGElement>) => {
23
23
  return <SvgWrapper icon={IconArrowDown} {...props} />;
@@ -168,25 +168,32 @@ export function NavVersions() {
168
168
  export function NavMenu({
169
169
  menuItems,
170
170
  position,
171
+ beforeNavItems,
172
+ afterNavItems,
171
173
  }: {
172
174
  menuItems: NavItem[];
173
- position: 'left' | 'right';
175
+ position?: 'left' | 'right';
176
+ beforeNavItems?: ReactNode;
177
+ afterNavItems?: ReactNode;
174
178
  }) {
175
- const getPosition = (menuItem: NavItem) => menuItem.position ?? 'right';
179
+ const items = useMemo(() => {
180
+ return position
181
+ ? menuItems.filter(item => (item.position ?? 'right') === position)
182
+ : menuItems;
183
+ }, [menuItems, position]);
176
184
 
177
- const leftOrRightMenuItems = useMemo(() => {
178
- return menuItems.filter(item => getPosition(item) === position);
179
- }, [menuItems]);
180
-
181
- if (leftOrRightMenuItems.length === 0) {
185
+ if (!items.length && beforeNavItems == null && afterNavItems == null)
182
186
  return null;
183
- }
184
187
 
185
188
  return (
186
- <ul className={clsx('rp-nav-menu', `rp-nav-menu--${position}`)}>
187
- {leftOrRightMenuItems.map((item, index) => {
188
- return <NavMenuItem key={index} menuItem={item} />;
189
- })}
189
+ <ul className={cls('rp-nav-menu', position && `rp-nav-menu--${position}`)}>
190
+ <NavListContext.Provider value="items">
191
+ {beforeNavItems}
192
+ {items.map((item, index) => (
193
+ <NavMenuItem key={index} menuItem={item} />
194
+ ))}
195
+ {afterNavItems}
196
+ </NavListContext.Provider>
190
197
  </ul>
191
198
  );
192
199
  }
@@ -10,7 +10,14 @@ import { isDarkModeSwitchEnabled } from '@rspress/shared';
10
10
  import './index.scss';
11
11
  import { NavLangs, NavMenu, NavMenuDivider, NavVersions } from './NavMenu';
12
12
 
13
- export interface NavProps {
13
+ export interface NavItemsSlots {
14
+ beforeLeftNavItems?: React.ReactNode;
15
+ afterLeftNavItems?: React.ReactNode;
16
+ beforeRightNavItems?: React.ReactNode;
17
+ afterRightNavItems?: React.ReactNode;
18
+ }
19
+
20
+ export interface NavProps extends NavItemsSlots {
14
21
  beforeNavTitle?: React.ReactNode;
15
22
  navTitle?: React.ReactNode;
16
23
  afterNavTitle?: React.ReactNode;
@@ -26,6 +33,10 @@ export function Nav(props: NavProps) {
26
33
  beforeNavMenu,
27
34
  afterNavMenu,
28
35
  navTitle,
36
+ beforeLeftNavItems,
37
+ afterLeftNavItems,
38
+ beforeRightNavItems,
39
+ afterRightNavItems,
29
40
  } = props;
30
41
  const navList = useNav();
31
42
  const { site } = useSite();
@@ -39,7 +50,12 @@ export function Nav(props: NavProps) {
39
50
  {beforeNavTitle}
40
51
  {navTitle ?? <NavTitle />}
41
52
  {/* only in desktop */}
42
- <NavMenu menuItems={navList} position="left" />
53
+ <NavMenu
54
+ menuItems={navList}
55
+ position="left"
56
+ beforeNavItems={beforeLeftNavItems}
57
+ afterNavItems={afterLeftNavItems}
58
+ />
43
59
  {afterNavTitle}
44
60
  </div>
45
61
 
@@ -48,7 +64,12 @@ export function Nav(props: NavProps) {
48
64
  <Search />
49
65
 
50
66
  {/* only in desktop */}
51
- <NavMenu menuItems={navList} position="right" />
67
+ <NavMenu
68
+ menuItems={navList}
69
+ position="right"
70
+ beforeNavItems={beforeRightNavItems}
71
+ afterNavItems={afterRightNavItems}
72
+ />
52
73
  <div className="rp-nav__others">
53
74
  <NavMenuDivider />
54
75
  <NavLangs />
@@ -58,7 +79,12 @@ export function Nav(props: NavProps) {
58
79
  </div>
59
80
 
60
81
  {/* only in mobile */}
61
- <NavHamburger />
82
+ <NavHamburger
83
+ beforeLeftNavItems={beforeLeftNavItems}
84
+ afterLeftNavItems={afterLeftNavItems}
85
+ beforeRightNavItems={beforeRightNavItems}
86
+ afterRightNavItems={afterRightNavItems}
87
+ />
62
88
  {afterNavMenu}
63
89
  </div>
64
90
  </header>
@@ -6,6 +6,7 @@ import {
6
6
  } from '@rspress/core/theme';
7
7
  import clsx from 'clsx';
8
8
  import { createPortal } from 'react-dom';
9
+ import type { NavItemsSlots } from '../Nav';
9
10
  import { NavVersions } from '../Nav/NavMenu';
10
11
  import { NavScreen, NavScreenDivider } from '../NavScreen';
11
12
  import { NavScreenAppearance } from '../NavScreen/NavScreenAppearance';
@@ -13,7 +14,7 @@ import { NavScreenLangs } from '../NavScreen/NavScreenLangs';
13
14
  import './index.scss';
14
15
  import { useNavScreen } from './useNavScreen';
15
16
 
16
- export function NavHamburger() {
17
+ export function NavHamburger(props: NavItemsSlots) {
17
18
  const items = (
18
19
  <div className="rp-nav-hamburger__md__hover-group">
19
20
  <NavScreenAppearance />
@@ -36,7 +37,14 @@ export function NavHamburger() {
36
37
  <>
37
38
  {isScreenOpen &&
38
39
  createPortal(
39
- <NavScreen isScreenOpen={isScreenOpen} toggleScreen={toggleScreen} />,
40
+ <NavScreen
41
+ beforeLeftNavItems={props.beforeLeftNavItems}
42
+ afterLeftNavItems={props.afterLeftNavItems}
43
+ beforeRightNavItems={props.beforeRightNavItems}
44
+ afterRightNavItems={props.afterRightNavItems}
45
+ isScreenOpen={isScreenOpen}
46
+ toggleScreen={toggleScreen}
47
+ />,
40
48
  document.getElementById('__rspress_modal_container')!,
41
49
  )}
42
50
 
@@ -47,7 +55,7 @@ export function NavHamburger() {
47
55
  'rp-nav-hamburger--active': isScreenOpen,
48
56
  })}
49
57
  >
50
- <SvgWrapper icon={IconSmallMenu} />
58
+ <SvgWrapper icon={IconSmallMenu} width={20} height={20} />
51
59
  </button>
52
60
 
53
61
  <button
@@ -0,0 +1,3 @@
1
+ import { createContext } from 'react';
2
+
3
+ export const NavListContext = createContext<'bar' | 'items' | 'screen'>('bar');
@@ -0,0 +1,24 @@
1
+ import type { NavItem } from '@rspress/core';
2
+ import { useContext } from 'react';
3
+ import { NavMenu, NavMenuItem } from '../Nav/NavMenu';
4
+ import { NavScreenMenu } from '../NavScreen/NavScreenMenu';
5
+ import { NavListContext } from './context';
6
+
7
+ export interface NavListProps {
8
+ items: NavItem[];
9
+ }
10
+
11
+ /** Renders navigation items using the surrounding navigation's presentation. */
12
+ export function NavList({ items }: NavListProps) {
13
+ const presentation = useContext(NavListContext);
14
+ if (presentation === 'items') {
15
+ return items.map((item, index) => (
16
+ <NavMenuItem key={index} menuItem={item} />
17
+ ));
18
+ }
19
+ return presentation === 'screen' ? (
20
+ <NavScreenMenu menuItems={items} />
21
+ ) : (
22
+ <NavMenu menuItems={items} />
23
+ );
24
+ }
@@ -0,0 +1,59 @@
1
+ import type { NavItem } from '@rspress/core';
2
+ import { describe, expect, it, rs } from '@rstest/core';
3
+ import { renderToStaticMarkup } from 'react-dom/server';
4
+ import { NavScreenMenu } from './NavScreenMenu';
5
+
6
+ rs.mock('./NavScreenMenuItem', () => ({
7
+ NavScreenMenuItem: ({ menuItem }: { menuItem: NavItem }) => (
8
+ <span>{menuItem.text}</span>
9
+ ),
10
+ }));
11
+
12
+ function renderOrder(items: NavItem[]) {
13
+ return renderToStaticMarkup(
14
+ <NavScreenMenu
15
+ menuItems={items}
16
+ beforeLeftNavItems={<span>BL</span>}
17
+ afterLeftNavItems={<span>AL</span>}
18
+ beforeRightNavItems={<span>BR</span>}
19
+ afterRightNavItems={<span>AR</span>}
20
+ />,
21
+ ).match(/(?<=>)[^<]+(?=<)/g);
22
+ }
23
+
24
+ describe('mobile navigation slot placement', () => {
25
+ it('preserves interleaved navigation order and wraps each position at its boundaries', () => {
26
+ expect(
27
+ renderOrder([
28
+ { text: 'R1', link: '/' },
29
+ { text: 'L1', link: '/', position: 'left' },
30
+ { text: 'R2', link: '/', position: 'right' },
31
+ { text: 'L2', link: '/', position: 'left' },
32
+ ]),
33
+ ).toEqual(['BR', 'R1', 'BL', 'L1', 'R2', 'AR', 'L2', 'AL']);
34
+ });
35
+
36
+ it('renders left slots before a right-only list', () => {
37
+ expect(renderOrder([{ text: 'R', link: '/' }])).toEqual([
38
+ 'BL',
39
+ 'AL',
40
+ 'BR',
41
+ 'R',
42
+ 'AR',
43
+ ]);
44
+ });
45
+
46
+ it('renders right slots after a left-only list', () => {
47
+ expect(renderOrder([{ text: 'L', link: '/', position: 'left' }])).toEqual([
48
+ 'BL',
49
+ 'L',
50
+ 'AL',
51
+ 'BR',
52
+ 'AR',
53
+ ]);
54
+ });
55
+
56
+ it('keeps all slots when no navigation items are configured', () => {
57
+ expect(renderOrder([])).toEqual(['BL', 'AL', 'BR', 'AR']);
58
+ });
59
+ });
@@ -1,13 +1,54 @@
1
1
  import type { NavItem } from '@rspress/core';
2
+ import { Fragment } from 'react';
3
+ import type { NavItemsSlots } from '../Nav';
2
4
  import { NavScreenMenuItem } from './NavScreenMenuItem';
3
5
  import './NavScreenMenu.scss';
4
6
 
5
- export function NavScreenMenu({ menuItems }: { menuItems: NavItem[] }) {
7
+ export function NavScreenMenu({
8
+ menuItems,
9
+ beforeLeftNavItems,
10
+ afterLeftNavItems,
11
+ beforeRightNavItems,
12
+ afterRightNavItems,
13
+ }: { menuItems: NavItem[] } & NavItemsSlots) {
14
+ let firstLeft = -1;
15
+ let lastLeft = -1;
16
+ let firstRight = -1;
17
+ let lastRight = -1;
18
+ menuItems.forEach((item, index) => {
19
+ if (item.position === 'left') {
20
+ if (firstLeft === -1) firstLeft = index;
21
+ lastLeft = index;
22
+ } else {
23
+ if (firstRight === -1) firstRight = index;
24
+ lastRight = index;
25
+ }
26
+ });
27
+
6
28
  return (
7
29
  <>
30
+ {/* Keep configured item order, including interleaved left/right items. */}
31
+ {firstLeft === -1 ? (
32
+ <>
33
+ {beforeLeftNavItems}
34
+ {afterLeftNavItems}
35
+ </>
36
+ ) : null}
8
37
  {menuItems.map((item, index) => (
9
- <NavScreenMenuItem menuItem={item} key={index} />
38
+ <Fragment key={index}>
39
+ {index === firstLeft ? beforeLeftNavItems : null}
40
+ {index === firstRight ? beforeRightNavItems : null}
41
+ <NavScreenMenuItem menuItem={item} />
42
+ {index === lastLeft ? afterLeftNavItems : null}
43
+ {index === lastRight ? afterRightNavItems : null}
44
+ </Fragment>
10
45
  ))}
46
+ {firstRight === -1 ? (
47
+ <>
48
+ {beforeRightNavItems}
49
+ {afterRightNavItems}
50
+ </>
51
+ ) : null}
11
52
  </>
12
53
  );
13
54
  }
@@ -21,12 +21,6 @@
21
21
  align-items: center;
22
22
  gap: 2px;
23
23
  }
24
- &__others {
25
- display: flex;
26
- @media (max-width: 1280px) {
27
- display: none;
28
- }
29
- }
30
24
  }
31
25
 
32
26
  .rp-nav-screen-divider {
@@ -4,12 +4,14 @@ import { clearAllBodyScrollLocks, disableBodyScroll } from 'body-scroll-lock';
4
4
  import clsx from 'clsx';
5
5
  import { useEffect, useRef } from 'react';
6
6
  import './index.scss';
7
+ import type { NavItemsSlots } from '../Nav';
8
+ import { NavListContext } from '../NavList/context';
7
9
  import { NavScreenAppearance } from './NavScreenAppearance';
8
10
  import { NavScreenLangs } from './NavScreenLangs';
9
11
  import { NavScreenMenu } from './NavScreenMenu';
10
12
  import { NavScreenVersions } from './NavScreenVersions';
11
13
 
12
- export interface NavScreenProps {
14
+ export interface NavScreenProps extends NavItemsSlots {
13
15
  isScreenOpen: boolean;
14
16
  toggleScreen: () => void;
15
17
  }
@@ -19,7 +21,14 @@ export function NavScreenDivider() {
19
21
  }
20
22
 
21
23
  export function NavScreen(props: NavScreenProps) {
22
- const { isScreenOpen, toggleScreen } = props;
24
+ const {
25
+ isScreenOpen,
26
+ toggleScreen,
27
+ beforeLeftNavItems,
28
+ afterLeftNavItems,
29
+ beforeRightNavItems,
30
+ afterRightNavItems,
31
+ } = props;
23
32
  const screen = useRef<HTMLDivElement | null>(null);
24
33
  const menuItems = useNav();
25
34
 
@@ -53,7 +62,15 @@ export function NavScreen(props: NavScreenProps) {
53
62
  className="rp-nav-screen__container"
54
63
  onClick={e => e.stopPropagation()}
55
64
  >
56
- <NavScreenMenu menuItems={menuItems} />
65
+ <NavListContext.Provider value="screen">
66
+ <NavScreenMenu
67
+ menuItems={menuItems}
68
+ beforeLeftNavItems={beforeLeftNavItems}
69
+ afterLeftNavItems={afterLeftNavItems}
70
+ beforeRightNavItems={beforeRightNavItems}
71
+ afterRightNavItems={afterRightNavItems}
72
+ />
73
+ </NavListContext.Provider>
57
74
  <NavScreenDivider />
58
75
  <NavScreenAppearance />
59
76
  <NavScreenLangs />
@@ -31,7 +31,7 @@ export const useReadPercent = () => {
31
31
  Math.min(Math.max(0, ((scrollTop - 50 + deltaHeight) / h) * 100), 100),
32
32
  ) || 0
33
33
  );
34
- }, [scrollTop, height]);
34
+ }, [h, scrollTop, height]);
35
35
 
36
36
  return [readPercent, scrollTop];
37
37
  };
@@ -53,6 +53,7 @@
53
53
  display: none;
54
54
  align-items: center;
55
55
  justify-content: center;
56
+ font-size: 20px;
56
57
  font-weight: 500;
57
58
  cursor: pointer;
58
59
  }