@rspress/core 1.2.0 → 1.3.0

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 (158) hide show
  1. package/dist/index.d.ts +2 -0
  2. package/dist/index.js +53 -40
  3. package/dist/index.js.map +1 -1
  4. package/dist/loader.d.ts +1 -1
  5. package/dist/loader.js.map +1 -1
  6. package/dist/runtime/App.js +8 -4
  7. package/dist/runtime/clientEntry.js +7 -4
  8. package/dist/runtime/ssrEntry.js +2 -2
  9. package/package.json +19 -15
  10. package/runtime.ts +1 -1
  11. package/src/runtime/App.tsx +8 -4
  12. package/src/runtime/clientEntry.tsx +7 -4
  13. package/src/runtime/ssrEntry.tsx +2 -2
  14. package/theme.ts +2 -2
  15. package/dist/runtime/Content.d.ts +0 -6
  16. package/dist/runtime/Content.js +0 -33
  17. package/dist/runtime/NoSSR.d.ts +0 -4
  18. package/dist/runtime/NoSSR.js +0 -17
  19. package/dist/runtime/hooks.d.ts +0 -39
  20. package/dist/runtime/hooks.js +0 -54
  21. package/dist/runtime/index.d.ts +0 -6
  22. package/dist/runtime/index.js +0 -34
  23. package/dist/runtime/utils.d.ts +0 -8
  24. package/dist/runtime/utils.js +0 -45
  25. package/dist/theme/bundle.css +0 -2691
  26. package/dist/theme/bundle.d.ts +0 -176
  27. package/dist/theme/bundle.js +0 -4433
  28. package/dist/theme/bundle.js.map +0 -1
  29. package/dist/theme/index.js +0 -6
  30. package/src/runtime/Content.tsx +0 -43
  31. package/src/runtime/NoSSR.tsx +0 -16
  32. package/src/runtime/hooks.ts +0 -110
  33. package/src/runtime/index.ts +0 -17
  34. package/src/runtime/utils.ts +0 -46
  35. package/src/theme-default/assets/arrow-down.svg +0 -1
  36. package/src/theme-default/assets/arrow-right.svg +0 -1
  37. package/src/theme-default/assets/copy.svg +0 -1
  38. package/src/theme-default/assets/down.svg +0 -1
  39. package/src/theme-default/assets/github.svg +0 -1
  40. package/src/theme-default/assets/loading.svg +0 -1
  41. package/src/theme-default/assets/menu.svg +0 -1
  42. package/src/theme-default/assets/moon.svg +0 -3
  43. package/src/theme-default/assets/right.svg +0 -1
  44. package/src/theme-default/assets/small-menu.svg +0 -1
  45. package/src/theme-default/assets/success.svg +0 -1
  46. package/src/theme-default/assets/sun.svg +0 -11
  47. package/src/theme-default/assets/translator.svg +0 -1
  48. package/src/theme-default/components/Aside/index.css +0 -22
  49. package/src/theme-default/components/Aside/index.tsx +0 -75
  50. package/src/theme-default/components/BackDrop/index.module.scss +0 -14
  51. package/src/theme-default/components/BackDrop/index.tsx +0 -13
  52. package/src/theme-default/components/Button/index.module.scss +0 -68
  53. package/src/theme-default/components/Button/index.tsx +0 -40
  54. package/src/theme-default/components/DocFooter/index.module.scss +0 -60
  55. package/src/theme-default/components/DocFooter/index.tsx +0 -66
  56. package/src/theme-default/components/EditLink/index.module.scss +0 -11
  57. package/src/theme-default/components/EditLink/index.tsx +0 -18
  58. package/src/theme-default/components/HomeFeatures/index.module.scss +0 -50
  59. package/src/theme-default/components/HomeFeatures/index.tsx +0 -65
  60. package/src/theme-default/components/HomeFooter/index.tsx +0 -15
  61. package/src/theme-default/components/HomeHero/index.module.scss +0 -42
  62. package/src/theme-default/components/HomeHero/index.tsx +0 -75
  63. package/src/theme-default/components/Link/index.module.scss +0 -9
  64. package/src/theme-default/components/Link/index.tsx +0 -90
  65. package/src/theme-default/components/LocalSideBar/index.scss +0 -40
  66. package/src/theme-default/components/LocalSideBar/index.tsx +0 -39
  67. package/src/theme-default/components/Nav/NavBarTitle.tsx +0 -43
  68. package/src/theme-default/components/Nav/NavMenuGroup.tsx +0 -156
  69. package/src/theme-default/components/Nav/NavMenuSingleItem.tsx +0 -40
  70. package/src/theme-default/components/Nav/NavTranslations.tsx +0 -16
  71. package/src/theme-default/components/Nav/NavVersions.tsx +0 -16
  72. package/src/theme-default/components/Nav/index.module.scss +0 -115
  73. package/src/theme-default/components/Nav/index.tsx +0 -150
  74. package/src/theme-default/components/Nav/menuDataHooks.tsx +0 -75
  75. package/src/theme-default/components/NavHambmger/index.module.scss +0 -81
  76. package/src/theme-default/components/NavHambmger/index.tsx +0 -39
  77. package/src/theme-default/components/NavScreen/NavScreenMenuGroup.tsx +0 -95
  78. package/src/theme-default/components/NavScreen/index.module.scss +0 -88
  79. package/src/theme-default/components/NavScreen/index.tsx +0 -123
  80. package/src/theme-default/components/Overview/index.module.scss +0 -154
  81. package/src/theme-default/components/Overview/index.tsx +0 -136
  82. package/src/theme-default/components/PackageManagerTabs/icons/Bun.tsx +0 -101
  83. package/src/theme-default/components/PackageManagerTabs/icons/Npm.tsx +0 -16
  84. package/src/theme-default/components/PackageManagerTabs/icons/Pnpm.tsx +0 -22
  85. package/src/theme-default/components/PackageManagerTabs/icons/Yarn.tsx +0 -18
  86. package/src/theme-default/components/PackageManagerTabs/index.scss +0 -5
  87. package/src/theme-default/components/PackageManagerTabs/index.tsx +0 -110
  88. package/src/theme-default/components/Search/NoSearchResult.tsx +0 -13
  89. package/src/theme-default/components/Search/SearchPanel.tsx +0 -340
  90. package/src/theme-default/components/Search/SuggestItem.tsx +0 -135
  91. package/src/theme-default/components/Search/assets/close.svg +0 -1
  92. package/src/theme-default/components/Search/assets/file.svg +0 -1
  93. package/src/theme-default/components/Search/assets/header.svg +0 -1
  94. package/src/theme-default/components/Search/assets/jump.svg +0 -1
  95. package/src/theme-default/components/Search/assets/loading.svg +0 -1
  96. package/src/theme-default/components/Search/assets/search.svg +0 -1
  97. package/src/theme-default/components/Search/assets/title.svg +0 -1
  98. package/src/theme-default/components/Search/empty.svg +0 -4
  99. package/src/theme-default/components/Search/index.module.scss +0 -236
  100. package/src/theme-default/components/Search/index.tsx +0 -39
  101. package/src/theme-default/components/Search/logic/Provider.ts +0 -35
  102. package/src/theme-default/components/Search/logic/providers/LocalProvider.ts +0 -102
  103. package/src/theme-default/components/Search/logic/providers/RemoteProvider.ts +0 -40
  104. package/src/theme-default/components/Search/logic/search.ts +0 -341
  105. package/src/theme-default/components/Search/logic/util.test.ts +0 -21
  106. package/src/theme-default/components/Search/logic/util.ts +0 -127
  107. package/src/theme-default/components/Sidebar/SidebarGroup.tsx +0 -180
  108. package/src/theme-default/components/Sidebar/SidebarItem.tsx +0 -61
  109. package/src/theme-default/components/Sidebar/index.module.scss +0 -142
  110. package/src/theme-default/components/Sidebar/index.tsx +0 -156
  111. package/src/theme-default/components/SocialLinks/HiddenLinks.tsx +0 -30
  112. package/src/theme-default/components/SocialLinks/LinkContent.tsx +0 -90
  113. package/src/theme-default/components/SocialLinks/ShownLinks.tsx +0 -32
  114. package/src/theme-default/components/SocialLinks/index.module.scss +0 -18
  115. package/src/theme-default/components/SocialLinks/index.tsx +0 -36
  116. package/src/theme-default/components/SocialLinks/presetIcons.tsx +0 -165
  117. package/src/theme-default/components/SwitchAppearance/index.module.scss +0 -15
  118. package/src/theme-default/components/SwitchAppearance/index.tsx +0 -35
  119. package/src/theme-default/components/Tabs/index.module.scss +0 -46
  120. package/src/theme-default/components/Tabs/index.tsx +0 -123
  121. package/src/theme-default/components/Tag/index.tsx +0 -18
  122. package/src/theme-default/components/Toc/index.css +0 -18
  123. package/src/theme-default/components/Toc/index.tsx +0 -42
  124. package/src/theme-default/index.ts +0 -26
  125. package/src/theme-default/layout/DocLayout/docComponents/code.tsx +0 -112
  126. package/src/theme-default/layout/DocLayout/docComponents/hr.tsx +0 -10
  127. package/src/theme-default/layout/DocLayout/docComponents/index.module.scss +0 -69
  128. package/src/theme-default/layout/DocLayout/docComponents/index.tsx +0 -33
  129. package/src/theme-default/layout/DocLayout/docComponents/link.tsx +0 -22
  130. package/src/theme-default/layout/DocLayout/docComponents/list.tsx +0 -13
  131. package/src/theme-default/layout/DocLayout/docComponents/paragraph.tsx +0 -19
  132. package/src/theme-default/layout/DocLayout/docComponents/pre.tsx +0 -37
  133. package/src/theme-default/layout/DocLayout/docComponents/prisim-theme.ts +0 -73
  134. package/src/theme-default/layout/DocLayout/docComponents/table.tsx +0 -37
  135. package/src/theme-default/layout/DocLayout/docComponents/title.tsx +0 -40
  136. package/src/theme-default/layout/DocLayout/index.module.scss +0 -138
  137. package/src/theme-default/layout/DocLayout/index.tsx +0 -125
  138. package/src/theme-default/layout/HomeLayout/index.css +0 -18
  139. package/src/theme-default/layout/HomeLayout/index.tsx +0 -39
  140. package/src/theme-default/layout/Layout/index.tsx +0 -176
  141. package/src/theme-default/layout/NotFountLayout/index.tsx +0 -40
  142. package/src/theme-default/logic/TabDataContext.ts +0 -14
  143. package/src/theme-default/logic/index.ts +0 -8
  144. package/src/theme-default/logic/sideEffects.ts +0 -174
  145. package/src/theme-default/logic/useAppearance.ts +0 -57
  146. package/src/theme-default/logic/useEditLink.ts +0 -33
  147. package/src/theme-default/logic/useHiddenNav.ts +0 -58
  148. package/src/theme-default/logic/useLocaleSiteData.ts +0 -26
  149. package/src/theme-default/logic/useNav.ts +0 -36
  150. package/src/theme-default/logic/usePathUtils.ts +0 -73
  151. package/src/theme-default/logic/usePrevNextPage.ts +0 -40
  152. package/src/theme-default/logic/useSidebarData.ts +0 -73
  153. package/src/theme-default/logic/utils.ts +0 -38
  154. package/src/theme-default/styles/base.css +0 -102
  155. package/src/theme-default/styles/code.css +0 -177
  156. package/src/theme-default/styles/index.ts +0 -7
  157. package/src/theme-default/styles/scrollbar.css +0 -28
  158. package/src/theme-default/styles/vars.css +0 -81
@@ -1,14 +1,18 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import siteData from "virtual-site-data";
3
- import { matchRoutes, useLocation } from "react-router-dom";
3
+ import {
4
+ matchRoutes,
5
+ useLocation,
6
+ isEqualPath,
7
+ normalizeRoutePath,
8
+ DataContext
9
+ } from "@rspress/runtime";
4
10
  import { HelmetProvider } from "react-helmet-async";
5
11
  import React, { useContext, useLayoutEffect } from "react";
6
12
  import { cleanUrl, isProduction } from "@rspress/shared";
7
13
  import globalComponents from "virtual-global-components";
8
- import { isEqualPath, normalizeRoutePath } from "./utils";
9
- import { DataContext } from "./hooks";
10
14
  import "virtual-global-styles";
11
- const { default: Theme } = require("@theme");
15
+ const { default: Theme } = require("@rspress/theme-default");
12
16
  async function initPageData(routePath) {
13
17
  const { routes } = process.env.__SSR__ ? require("virtual-routes-ssr") : require("virtual-routes");
14
18
  const matched = matchRoutes(routes, routePath);
@@ -1,13 +1,16 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { useState } from "react";
3
- import { BrowserRouter } from "react-router-dom";
4
3
  import { isProduction } from "@rspress/shared";
5
4
  import siteData from "virtual-site-data";
5
+ import {
6
+ DataContext,
7
+ ThemeContext,
8
+ normalizeRoutePath,
9
+ BrowserRouter
10
+ } from "@rspress/runtime";
6
11
  import { App, initPageData } from "./App";
7
- import { DataContext, ThemeContext } from "./hooks";
8
- import { normalizeRoutePath } from "./utils";
9
12
  const enableSSG = siteData.ssg;
10
- const { default: Theme } = require("@theme");
13
+ const { default: Theme } = require("@rspress/theme-default");
11
14
  async function renderInBrowser() {
12
15
  const container = document.getElementById("root");
13
16
  const enhancedApp = async () => {
@@ -1,8 +1,8 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { renderToString } from "react-dom/server";
3
- import { StaticRouter } from "react-router-dom/server";
3
+ import { DataContext, ThemeContext } from "@rspress/runtime";
4
+ import { StaticRouter } from "@rspress/runtime/server";
4
5
  import { App, initPageData } from "./App";
5
- import { DataContext, ThemeContext } from "./hooks";
6
6
  const DEFAULT_THEME = "light";
7
7
  async function render(pagePath, helmetContext) {
8
8
  const initialPageData = await initPageData(pagePath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspress/core",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "The Rspress Documentation Framework",
5
5
  "bugs": "https://github.com/web-infra-dev/rspress/issues",
6
6
  "repository": {
@@ -40,10 +40,11 @@
40
40
  "@mdx-js/loader": "2.2.1",
41
41
  "@mdx-js/mdx": "2.2.1",
42
42
  "@mdx-js/react": "2.2.1",
43
- "@modern-js/builder": "2.37.1",
44
- "@modern-js/builder-rspack-provider": "2.37.1",
43
+ "@modern-js/utils": "2.39.0",
44
+ "@rsbuild/core": "0.0.10",
45
+ "@rsbuild/plugin-react": "0.0.10",
46
+ "@rsbuild/plugin-svgr": "0.0.10",
45
47
  "@rspress/mdx-rs": "0.4.1",
46
- "@modern-js/utils": "2.37.1",
47
48
  "@types/compression": "^1.7.2",
48
49
  "@types/polka": "^0.5.4",
49
50
  "autoprefixer": "10.4.13",
@@ -57,6 +58,8 @@
57
58
  "globby": "11.1.0",
58
59
  "hast-util-from-html": "^1.0.0",
59
60
  "html-to-text": "^9.0.3",
61
+ "htmr": "^1.0.2",
62
+ "is-html": "^3.0.0",
60
63
  "jsdom": "20.0.3",
61
64
  "lodash-es": "^4.17.21",
62
65
  "mdast-util-mdxjs-esm": "^1.3.0",
@@ -69,7 +72,6 @@
69
72
  "react-dom": "^18.2.0",
70
73
  "react-helmet-async": "^1.3.0",
71
74
  "react-lazy-with-preload": "^2.2.1",
72
- "react-router-dom": "^6.8.1",
73
75
  "react-syntax-highlighter": "^15.5.0",
74
76
  "rehype-autolink-headings": "6.1.1",
75
77
  "rehype-external-links": "^2.0.1",
@@ -80,6 +82,7 @@
80
82
  "remark-html": "^15.0.1",
81
83
  "remark-parse": "^10.0.1",
82
84
  "remark-rehype": "^10.1.0",
85
+ "rspack-plugin-virtual-module": "0.1.12",
83
86
  "sirv": "^2.0.2",
84
87
  "source-map": "0.7.4",
85
88
  "string-replace-loader": "^3.1.0",
@@ -88,18 +91,19 @@
88
91
  "unist-util-visit": "^4.1.1",
89
92
  "unist-util-visit-children": "^2.0.1",
90
93
  "yaml-front-matter": "^4.1.1",
91
- "rspack-plugin-virtual-module": "0.1.12",
92
- "@rspress/shared": "1.2.0",
93
- "@rspress/plugin-medium-zoom": "1.2.0",
94
- "@rspress/plugin-last-updated": "1.2.0",
95
- "@rspress/plugin-auto-nav-sidebar": "1.2.0",
96
- "@rspress/plugin-container-syntax": "1.2.0"
94
+ "@rspress/theme-default": "1.3.0",
95
+ "@rspress/runtime": "1.3.0",
96
+ "@rspress/plugin-medium-zoom": "1.3.0",
97
+ "@rspress/plugin-last-updated": "1.3.0",
98
+ "@rspress/plugin-auto-nav-sidebar": "1.3.0",
99
+ "@rspress/shared": "1.3.0",
100
+ "@rspress/plugin-container-syntax": "1.3.0"
97
101
  },
98
102
  "devDependencies": {
99
- "@modern-js/plugin-tailwindcss": "2.37.1",
100
- "@modern-js/plugin-testing": "2.37.1",
101
- "@modern-js/tsconfig": "2.37.1",
102
- "@modern-js/types": "2.37.1",
103
+ "@modern-js/plugin-tailwindcss": "2.39.0",
104
+ "@modern-js/plugin-testing": "2.39.0",
105
+ "@modern-js/tsconfig": "2.39.0",
106
+ "@modern-js/types": "2.39.0",
103
107
  "@types/body-scroll-lock": "^3.1.0",
104
108
  "@types/fs-extra": "^9.0.13",
105
109
  "@types/hast": "^2.3.4",
package/runtime.ts CHANGED
@@ -1 +1 @@
1
- export * from './dist/runtime';
1
+ export * from '@rspress/runtime';
@@ -1,15 +1,19 @@
1
1
  import siteData from 'virtual-site-data';
2
- import { matchRoutes, useLocation } from 'react-router-dom';
2
+ import {
3
+ matchRoutes,
4
+ useLocation,
5
+ isEqualPath,
6
+ normalizeRoutePath,
7
+ DataContext,
8
+ } from '@rspress/runtime';
3
9
  import { HelmetProvider } from 'react-helmet-async';
4
10
  import React, { useContext, useLayoutEffect } from 'react';
5
11
  import { Header, PageData, cleanUrl, isProduction } from '@rspress/shared';
6
12
  import globalComponents from 'virtual-global-components';
7
- import { isEqualPath, normalizeRoutePath } from './utils';
8
- import { DataContext } from './hooks';
9
13
  import 'virtual-global-styles';
10
14
 
11
15
  // eslint-disable-next-line import/no-commonjs
12
- const { default: Theme } = require('@theme');
16
+ const { default: Theme } = require('@rspress/theme-default');
13
17
 
14
18
  type RspressPageMeta = Record<
15
19
  string,
@@ -1,15 +1,18 @@
1
1
  import { useState } from 'react';
2
- import { BrowserRouter } from 'react-router-dom';
3
2
  import { isProduction } from '@rspress/shared';
4
3
  import siteData from 'virtual-site-data';
4
+ import {
5
+ DataContext,
6
+ ThemeContext,
7
+ normalizeRoutePath,
8
+ BrowserRouter,
9
+ } from '@rspress/runtime';
5
10
  import { App, initPageData } from './App';
6
- import { DataContext, ThemeContext } from './hooks';
7
- import { normalizeRoutePath } from './utils';
8
11
 
9
12
  const enableSSG = siteData.ssg;
10
13
 
11
14
  // eslint-disable-next-line import/no-commonjs
12
- const { default: Theme } = require('@theme');
15
+ const { default: Theme } = require('@rspress/theme-default');
13
16
 
14
17
  export async function renderInBrowser() {
15
18
  const container = document.getElementById('root')!;
@@ -1,8 +1,8 @@
1
1
  import { renderToString } from 'react-dom/server';
2
- import { StaticRouter } from 'react-router-dom/server';
3
2
  import { PageData } from '@rspress/shared';
3
+ import { DataContext, ThemeContext } from '@rspress/runtime';
4
+ import { StaticRouter } from '@rspress/runtime/server';
4
5
  import { App, initPageData } from './App';
5
- import { DataContext, ThemeContext } from './hooks';
6
6
 
7
7
  const DEFAULT_THEME = 'light';
8
8
 
package/theme.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from './dist/theme/index';
2
- export { default } from './dist/theme/index';
1
+ export * from '@rspress/theme-default';
2
+ export { default } from '@rspress/theme-default';
@@ -1,6 +0,0 @@
1
- import { ReactNode } from 'react';
2
- export declare const Content: ({
3
- fallback
4
- }: {
5
- fallback?: ReactNode;
6
- }) => any;
@@ -1,33 +0,0 @@
1
- import { Fragment, jsx } from "react/jsx-runtime";
2
- import { Suspense, memo } from "react";
3
- import { matchRoutes, useLocation } from "react-router-dom";
4
- import siteData from "virtual-site-data";
5
- import { normalizeRoutePath } from "./utils";
6
- import { useViewTransition } from "./hooks";
7
- const { routes } = process.env.__SSR__ ? require("virtual-routes-ssr") : require("virtual-routes");
8
- function TransitionContentImpl(props) {
9
- let element = props.el;
10
- if (siteData?.themeConfig?.enableContentAnimation) {
11
- element = useViewTransition(props.el);
12
- }
13
- return element;
14
- }
15
- const TransitionContent = memo(
16
- TransitionContentImpl,
17
- (prevProps, nextProps) => prevProps.el === nextProps.el
18
- );
19
- const Content = ({ fallback = /* @__PURE__ */ jsx(Fragment, {}) }) => {
20
- const { pathname } = useLocation();
21
- const matched = matchRoutes(routes, normalizeRoutePath(pathname));
22
- if (!matched) {
23
- return /* @__PURE__ */ jsx("div", {});
24
- }
25
- const routesElement = matched[0].route.element;
26
- if (!process.env.__IS_REACT_18__ && process.env.__SSR__) {
27
- return routesElement;
28
- }
29
- return /* @__PURE__ */ jsx(Suspense, { fallback, children: /* @__PURE__ */ jsx(TransitionContent, { el: routesElement }) });
30
- };
31
- export {
32
- Content
33
- };
@@ -1,4 +0,0 @@
1
- /// <reference types="react" />
2
- export declare function NoSSR(props: {
3
- children: React.ReactNode;
4
- }): JSX.Element;
@@ -1,17 +0,0 @@
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) {
10
- return null;
11
- } else {
12
- return /* @__PURE__ */ jsx(Fragment, { children });
13
- }
14
- }
15
- export {
16
- NoSSR
17
- };
@@ -1,39 +0,0 @@
1
- /// <reference types="react" />
2
- import { PageData } from '@rspress/shared';
3
- declare global {
4
- interface Window {
5
- __MODERN_PAGE_DATA__: any;
6
- }
7
- }
8
- interface IDataContext {
9
- data: PageData;
10
- setData?: (data: PageData) => void;
11
- }
12
- interface IThemeContext {
13
- theme: 'light' | 'dark';
14
- setTheme?: (theme: 'light' | 'dark') => void;
15
- }
16
- export declare const DataContext: import("react").Context<IDataContext>;
17
- export declare const ThemeContext: import("react").Context<IThemeContext>;
18
- export declare function usePageData(): PageData;
19
- export declare function useLang(): string;
20
- export declare function useVersion(): string;
21
- export declare function useDark(): boolean;
22
- export declare function useI18n<T = Record<string, Record<string, string>>>(): (key: keyof T) => any;
23
- declare global {
24
- interface Document {
25
- startViewTransition: (callback: () => void) => void;
26
- }
27
- }
28
- /**
29
- * There is a pitfall.
30
- * I was working on the navigation between pages with hash. eg. from `guide/start` -> `config/repress#nav`
31
- * I need a time to dispatch an event so that the sideEffect.ts would know that
32
- * the dom is attached to the browser. Otherwise the scroll position and the
33
- * animation would be incorrect. You can search for `RspressReloadContent` in this codebase
34
- * to findout the logic that are consuming the event.
35
- * The reason I didn't write it here is that I hope the logic of handling scroll and position
36
- * could be in one place so that people wouldn't be confused.
37
- */
38
- export declare function useViewTransition(dom: any): any;
39
- export {};
@@ -1,54 +0,0 @@
1
- import { createContext, useContext, useLayoutEffect, useState } from "react";
2
- import i18nTextData from "virtual-i18n-text";
3
- import { flushSync } from "react-dom";
4
- const DataContext = createContext({});
5
- const ThemeContext = createContext({});
6
- function usePageData() {
7
- const ctx = useContext(DataContext);
8
- return ctx.data;
9
- }
10
- function useLang() {
11
- const ctx = useContext(DataContext);
12
- return ctx.data.page.lang || "";
13
- }
14
- function useVersion() {
15
- const ctx = useContext(DataContext);
16
- return ctx.data.page.version || "";
17
- }
18
- function useDark() {
19
- const ctx = useContext(ThemeContext);
20
- return ctx.theme === "dark";
21
- }
22
- function useI18n() {
23
- const lang = useLang();
24
- return (key) => i18nTextData[key][lang];
25
- }
26
- function useViewTransition(dom) {
27
- const [element, setElement] = useState(dom);
28
- useLayoutEffect(() => {
29
- if (document.startViewTransition && element !== dom) {
30
- document.startViewTransition(() => {
31
- flushSync(() => {
32
- setElement(dom);
33
- });
34
- window.dispatchEvent(new Event("RspressReloadContent"));
35
- });
36
- } else {
37
- flushSync(() => {
38
- setElement(dom);
39
- });
40
- window.dispatchEvent(new Event("RspressReloadContent"));
41
- }
42
- }, [dom]);
43
- return element;
44
- }
45
- export {
46
- DataContext,
47
- ThemeContext,
48
- useDark,
49
- useI18n,
50
- useLang,
51
- usePageData,
52
- useVersion,
53
- useViewTransition
54
- };
@@ -1,6 +0,0 @@
1
- export * from './hooks';
2
- export * from './Content';
3
- export { normalizeHrefInRuntime, normalizeImagePath, withBase, removeBase, addLeadingSlash, removeTrailingSlash, normalizeSlash, isProduction, normalizeRoutePath, isEqualPath } from './utils';
4
- export { useLocation, useNavigate, matchRoutes } from 'react-router-dom';
5
- export { Helmet } from 'react-helmet-async';
6
- export { NoSSR } from './NoSSR';
@@ -1,34 +0,0 @@
1
- export * from "./hooks";
2
- export * from "./Content";
3
- import {
4
- normalizeHrefInRuntime,
5
- normalizeImagePath,
6
- withBase,
7
- removeBase,
8
- addLeadingSlash,
9
- removeTrailingSlash,
10
- normalizeSlash,
11
- isProduction,
12
- normalizeRoutePath,
13
- isEqualPath
14
- } from "./utils";
15
- import { useLocation, useNavigate, matchRoutes } from "react-router-dom";
16
- import { Helmet } from "react-helmet-async";
17
- import { NoSSR } from "./NoSSR";
18
- export {
19
- Helmet,
20
- NoSSR,
21
- addLeadingSlash,
22
- isEqualPath,
23
- isProduction,
24
- matchRoutes,
25
- normalizeHrefInRuntime,
26
- normalizeImagePath,
27
- normalizeRoutePath,
28
- normalizeSlash,
29
- removeBase,
30
- removeTrailingSlash,
31
- useLocation,
32
- useNavigate,
33
- withBase
34
- };
@@ -1,8 +0,0 @@
1
- import { addLeadingSlash, removeTrailingSlash, normalizeSlash, isProduction } from '@rspress/shared';
2
- export declare function normalizeRoutePath(routePath: string): string;
3
- export declare function withBase(url?: string): string;
4
- export declare function removeBase(url: string): string;
5
- export declare function isEqualPath(a: string, b: string): boolean;
6
- export declare function normalizeHrefInRuntime(a: string): string;
7
- export declare function normalizeImagePath(imagePath: string): string;
8
- export { addLeadingSlash, removeTrailingSlash, normalizeSlash, isProduction };
@@ -1,45 +0,0 @@
1
- import siteData from "virtual-site-data";
2
- import {
3
- addLeadingSlash,
4
- removeTrailingSlash,
5
- normalizeSlash,
6
- isProduction,
7
- normalizeHref,
8
- withBase as rawWithBase,
9
- removeBase as rawRemoveBase,
10
- isExternalUrl
11
- } from "@rspress/shared";
12
- function normalizeRoutePath(routePath) {
13
- return decodeURIComponent(routePath).replace(/\.html$/, "").replace(/\/index$/, "/");
14
- }
15
- function withBase(url = "/") {
16
- return rawWithBase(url, siteData.base);
17
- }
18
- function removeBase(url) {
19
- return rawRemoveBase(url, siteData.base);
20
- }
21
- function isEqualPath(a, b) {
22
- return withBase(normalizeHrefInRuntime(a)) === withBase(normalizeHrefInRuntime(b));
23
- }
24
- function normalizeHrefInRuntime(a) {
25
- const cleanUrls = Boolean(siteData?.route?.cleanUrls);
26
- return normalizeHref(a, cleanUrls);
27
- }
28
- function normalizeImagePath(imagePath) {
29
- if (isExternalUrl(imagePath)) {
30
- return imagePath;
31
- }
32
- return withBase(imagePath);
33
- }
34
- export {
35
- addLeadingSlash,
36
- isEqualPath,
37
- isProduction,
38
- normalizeHrefInRuntime,
39
- normalizeImagePath,
40
- normalizeRoutePath,
41
- normalizeSlash,
42
- removeBase,
43
- removeTrailingSlash,
44
- withBase
45
- };