@rspress/core 2.0.23 → 2.1.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.js +2 -2
- package/dist/{common-Qw-RoVFD.js → common-Bo3KCGim.js} +4 -1
- package/dist/config/loadConfigFile.js +1 -1
- package/dist/eject-theme/components/CdnTabs/index.test.tsx +71 -0
- package/dist/eject-theme/components/CdnTabs/index.tsx +175 -0
- package/dist/eject-theme/components/DocContent/index.tsx +0 -3
- package/dist/eject-theme/components/FallbackHeading/index.tsx +6 -1
- package/dist/eject-theme/components/Link/getHref.ts +1 -0
- package/dist/eject-theme/components/Link/index.tsx +9 -21
- package/dist/eject-theme/components/Link/useLinkNavigate.ts +43 -54
- package/dist/eject-theme/components/NavTitle/index.test.tsx +78 -0
- package/dist/eject-theme/components/NavTitle/index.tsx +9 -5
- package/dist/eject-theme/components/PackageManagerTabs/index.test.tsx +79 -1
- package/dist/eject-theme/components/PackageManagerTabs/index.tsx +25 -12
- package/dist/eject-theme/components/Search/NoSearchResult.scss +1 -2
- package/dist/eject-theme/components/Search/SearchPanel.scss +75 -63
- package/dist/eject-theme/components/Search/SuggestItem.scss +28 -41
- package/dist/eject-theme/components/Search/logic/providers/LocalProvider.ts +4 -1
- package/dist/eject-theme/components/Search/useSearchPanel.ts +103 -36
- package/dist/eject-theme/components/Sidebar/SidebarItem.scss +8 -0
- package/dist/eject-theme/components/Sidebar/SidebarSectionHeader.scss +3 -0
- package/dist/eject-theme/components/SocialLinks/GithubStars.test.tsx +4 -1
- package/dist/eject-theme/components/SocialLinks/GithubStars.tsx +1 -1
- package/dist/entry/worker.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/node/PluginDriver.d.ts +5 -0
- package/dist/node/PluginDriver.js +17 -2
- package/dist/node/auto-nav-sidebar/index.js +1 -1
- package/dist/node/auto-nav-sidebar/locales.js +1 -1
- package/dist/node/auto-nav-sidebar/normalize.js +1 -1
- package/dist/node/auto-nav-sidebar/utils.js +1 -1
- package/dist/node/auto-nav-sidebar/walk.js +1 -1
- package/dist/node/constants.js +1 -1
- package/dist/node/eject.js +1 -1
- package/dist/node/initRsbuild.js +19 -7
- package/dist/node/llms.d.ts +1 -1
- package/dist/node/llms.js +2 -2
- package/dist/node/logger/hint.d.ts +1 -0
- package/dist/node/logger/hint.js +8 -2
- package/dist/node/mdx/rehypePlugins/headerAnchor.js +1 -0
- package/dist/node/mdx/remarkPlugins/link.js +1 -1
- package/dist/node/route/RoutePage.js +1 -1
- package/dist/node/route/RouteService.js +1 -1
- package/dist/node/route/extractPageData.js +1 -1
- package/dist/node/route/normalizeRoutePath.js +1 -1
- package/dist/node/runtimeModule/{DEFAULT_I18N_TEXT.d.ts → i18n/DEFAULT_I18N_TEXT.d.ts} +28 -0
- package/dist/node/runtimeModule/{DEFAULT_I18N_TEXT.js → i18n/DEFAULT_I18N_TEXT.js} +28 -0
- package/dist/node/runtimeModule/i18n/getI18nData.d.ts +11 -0
- package/dist/node/runtimeModule/{i18n.js → i18n/getI18nData.js} +35 -22
- package/dist/node/runtimeModule/i18n/rsbuildPlugin.d.ts +5 -0
- package/dist/node/runtimeModule/i18n/rsbuildPlugin.js +21 -0
- package/dist/node/runtimeModule/pageData/createPageData.js +1 -1
- package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
- package/dist/node/runtimeModule/searchHooks.js +2 -2
- package/dist/node/runtimeModule/siteData/createSiteData.d.ts +2 -1
- package/dist/node/runtimeModule/siteData/createSiteData.js +3 -3
- package/dist/node/runtimeModule/siteData/normalizeThemeConfig.d.ts +2 -1
- package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +3 -4
- package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +2 -2
- package/dist/node/serve.js +1 -1
- package/dist/node/sitemap.d.ts +7 -0
- package/dist/node/sitemap.js +86 -0
- package/dist/node/ssg/alternateLinks.js +1 -1
- package/dist/node/ssg/htmlFile.js +1 -1
- package/dist/node/ssg/renderHtmlTemplate.js +1 -1
- package/dist/node/ssg/renderPage.js +1 -1
- package/dist/node/ssg/renderPageWorker.js +1 -1
- package/dist/node/ssg/renderPages.js +2 -2
- package/dist/node/ssg/rsbuildPluginSSG.js +1 -1
- package/dist/node/ssg/ssgEnv.js +1 -1
- package/dist/node/ssg-md/llms/emitLlmsTxt.js +1 -1
- package/dist/node/ssg-md/llms/llmsTxt.js +1 -1
- package/dist/node/ssg-md/renderPage.js +5 -4
- package/dist/node/ssg-md/renderPages.js +2 -2
- package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
- package/dist/node/utils/checkLanguageParity.js +1 -1
- package/dist/node/utils/createHash.js +1 -1
- package/dist/node/utils/flattenMdxContent.js +1 -1
- package/dist/node/utils/getPageKey.js +1 -1
- package/dist/node/utils/reactAlias.js +6 -3
- package/dist/{a~0.js → p~0.js} +23 -18
- package/dist/runtime/App.js +20 -29
- package/dist/runtime/BrowserOnly.d.ts +1 -1
- package/dist/runtime/BrowserOnly.js +53 -20
- package/dist/runtime/ClientApp.d.ts +3 -2
- package/dist/runtime/ClientApp.js +31 -21
- package/dist/runtime/ErrorRoute.d.ts +1 -0
- package/dist/runtime/ErrorRoute.js +30 -0
- package/dist/runtime/NoSSR.d.ts +7 -3
- package/dist/runtime/NoSSR.js +30 -9
- package/dist/runtime/PageRoute.d.ts +2 -0
- package/dist/runtime/PageRoute.js +70 -0
- package/dist/runtime/createServerRouter.d.ts +4 -0
- package/dist/runtime/createServerRouter.js +17 -0
- package/dist/runtime/csrClientEntry.js +5 -2
- package/dist/runtime/hooks/useWebMcp.d.ts +36 -0
- package/dist/runtime/hooks/useWebMcp.js +80 -0
- package/dist/runtime/index.d.ts +6 -3
- package/dist/runtime/index.js +6 -5
- package/dist/runtime/initPageData.d.ts +0 -3
- package/dist/runtime/initPageData.js +9 -45
- package/dist/runtime/pageDataLoader.d.ts +11 -0
- package/dist/runtime/pageDataLoader.js +7 -0
- package/dist/runtime/react.d.ts +5 -0
- package/dist/runtime/react.js +4 -0
- package/dist/runtime/reactDom.d.ts +6 -0
- package/dist/runtime/reactDom.js +2 -1
- package/dist/runtime/socialLinks.d.ts +1 -0
- package/dist/runtime/socialLinks.js +3 -0
- package/dist/runtime/ssrClientEntry.js +14 -6
- package/dist/runtime/ssrMdServerEntry.js +10 -21
- package/dist/runtime/ssrServerEntry.js +10 -21
- package/dist/static/assets/package.json +58 -0
- package/dist/theme/assets/bun.js +101 -0
- package/dist/theme/assets/deno.js +15 -0
- package/dist/theme/assets/jsdelivr.js +53 -0
- package/dist/theme/{components/PackageManagerTabs/icons/Npm.js → assets/npm.js} +4 -4
- package/dist/theme/{components/PackageManagerTabs/icons/Pnpm.js → assets/pnpm.js} +4 -4
- package/dist/theme/assets/unpkg.js +15 -0
- package/dist/theme/assets/yarn.js +22 -0
- package/dist/theme/components/CdnTabs/index.d.ts +10 -0
- package/dist/theme/components/CdnTabs/index.js +146 -0
- package/dist/theme/components/DocContent/index.js +1 -2
- package/dist/theme/components/FallbackHeading/index.js +1 -0
- package/dist/theme/components/Link/index.js +4 -17
- package/dist/theme/components/Link/useLinkNavigate.d.ts +2 -2
- package/dist/theme/components/Link/useLinkNavigate.js +22 -36
- package/dist/theme/components/NavTitle/index.js +10 -5
- package/dist/theme/components/PackageManagerTabs/index.d.ts +2 -0
- package/dist/theme/components/PackageManagerTabs/index.js +22 -12
- package/dist/theme/components/Search/NoSearchResult.css +1 -2
- package/dist/theme/components/Search/SearchPanel.css +72 -51
- package/dist/theme/components/Search/SuggestItem.css +21 -34
- package/dist/theme/components/Search/logic/providers/LocalProvider.js +4 -1
- package/dist/theme/components/Search/useSearchPanel.js +74 -26
- package/dist/theme/components/Sidebar/SidebarItem.css +5 -0
- package/dist/theme/components/Sidebar/SidebarSectionHeader.css +1 -0
- package/dist/theme/components/SocialLinks/GithubStars.js +1 -1
- package/dist/theme/hooks/useDynamicToc.js +27 -34
- package/dist/theme/hooks/useWebMcpNavigation.d.ts +6 -0
- package/dist/theme/hooks/useWebMcpNavigation.js +123 -0
- package/dist/theme/hooks/useWebMcpPageList.d.ts +6 -0
- package/dist/theme/hooks/useWebMcpPageList.js +25 -0
- package/dist/theme/hooks/useWebMcpPageReading.d.ts +7 -0
- package/dist/theme/hooks/useWebMcpPageReading.js +23 -0
- package/dist/theme/hooks/useWebMcpSiteInfo.d.ts +6 -0
- package/dist/theme/hooks/useWebMcpSiteInfo.js +22 -0
- package/dist/theme/icons.d.ts +7 -0
- package/dist/theme/icons.js +15 -1
- package/dist/theme/index.d.ts +6 -2
- package/dist/theme/index.js +6 -2
- package/dist/theme/layout/ErrorLayout/index.css +52 -0
- package/dist/theme/layout/ErrorLayout/index.d.ts +8 -0
- package/dist/theme/layout/ErrorLayout/index.js +76 -0
- package/dist/theme/layout/Layout/index.js +1 -2
- package/dist/theme/webMcp/tools.d.ts +56 -0
- package/dist/theme/webMcp/tools.js +122 -0
- package/dist/theme/webMcp/types.d.ts +35 -0
- package/dist/theme/webMcp/types.js +0 -0
- package/dist/tinypool~0.js +19 -49
- package/dist/y~0.js +166 -0
- package/package.json +18 -18
- package/dist/b~0.js +0 -106
- package/dist/eject-theme/components/PackageManagerTabs/icons/Bun.tsx +0 -101
- package/dist/eject-theme/components/PackageManagerTabs/icons/Deno.tsx +0 -18
- package/dist/eject-theme/components/PackageManagerTabs/icons/Npm.tsx +0 -16
- package/dist/eject-theme/components/PackageManagerTabs/icons/Pnpm.tsx +0 -22
- package/dist/eject-theme/components/PackageManagerTabs/icons/Yarn.tsx +0 -18
- package/dist/node/runtimeModule/i18n.d.ts +0 -8
- package/dist/theme/components/PackageManagerTabs/icons/Bun.d.ts +0 -2
- package/dist/theme/components/PackageManagerTabs/icons/Bun.js +0 -137
- package/dist/theme/components/PackageManagerTabs/icons/Deno.d.ts +0 -2
- package/dist/theme/components/PackageManagerTabs/icons/Deno.js +0 -15
- package/dist/theme/components/PackageManagerTabs/icons/Npm.d.ts +0 -2
- package/dist/theme/components/PackageManagerTabs/icons/Pnpm.d.ts +0 -2
- package/dist/theme/components/PackageManagerTabs/icons/Yarn.d.ts +0 -2
- package/dist/theme/components/PackageManagerTabs/icons/Yarn.js +0 -22
- package/dist/theme/logic/useScrollAfterNav.d.ts +0 -5
- package/dist/theme/logic/useScrollAfterNav.js +0 -35
- package/dist/theme/logic/useScrollReset.d.ts +0 -5
- package/dist/theme/logic/useScrollReset.js +0 -12
|
@@ -1,39 +1,72 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
});
|
|
1
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Suspense, useEffect, useMemo, useState } from "react";
|
|
3
|
+
import { safeUse } from "./react.js";
|
|
4
|
+
import { safeBrowserOnly } from "./reactDom.js";
|
|
5
|
+
function DeferredBrowserOnly({ source, fallback = null }) {
|
|
6
|
+
const [state, setState] = useState();
|
|
8
7
|
useEffect(()=>{
|
|
9
8
|
let isMounted = true;
|
|
10
|
-
setState(
|
|
11
|
-
|
|
12
|
-
children
|
|
13
|
-
});
|
|
14
|
-
Promise.resolve().then(()=>children()).then((content)=>{
|
|
9
|
+
setState(void 0);
|
|
10
|
+
Promise.resolve().then(()=>'function' == typeof source ? source() : source).then((content)=>{
|
|
15
11
|
if (isMounted) setState({
|
|
16
|
-
|
|
17
|
-
children,
|
|
12
|
+
source,
|
|
18
13
|
content
|
|
19
14
|
});
|
|
20
15
|
}, (error)=>{
|
|
21
16
|
if (isMounted) setState({
|
|
22
|
-
|
|
23
|
-
children,
|
|
17
|
+
source,
|
|
24
18
|
error
|
|
25
19
|
});
|
|
26
20
|
});
|
|
27
21
|
return ()=>{
|
|
28
22
|
isMounted = false;
|
|
29
23
|
};
|
|
24
|
+
}, [
|
|
25
|
+
source
|
|
26
|
+
]);
|
|
27
|
+
if (!state || state.source !== source) return fallback;
|
|
28
|
+
if ('error' in state) throw state.error;
|
|
29
|
+
return state.content;
|
|
30
|
+
}
|
|
31
|
+
function ModernBrowserOnly({ children, fallback }) {
|
|
32
|
+
safeUse(safeBrowserOnly('This content is only rendered in the browser.'));
|
|
33
|
+
const result = useMemo(()=>{
|
|
34
|
+
const content = children();
|
|
35
|
+
if (null !== content && 'object' == typeof content && 'then' in content && 'function' == typeof content.then) {
|
|
36
|
+
const promise = Promise.resolve(content);
|
|
37
|
+
promise.catch(()=>{});
|
|
38
|
+
return {
|
|
39
|
+
promise
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
content
|
|
44
|
+
};
|
|
30
45
|
}, [
|
|
31
46
|
children
|
|
32
47
|
]);
|
|
33
|
-
if (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
48
|
+
if (result.promise) return /*#__PURE__*/ jsx(DeferredBrowserOnly, {
|
|
49
|
+
source: result.promise,
|
|
50
|
+
fallback: fallback
|
|
51
|
+
});
|
|
52
|
+
return /*#__PURE__*/ jsx(Fragment, {
|
|
53
|
+
children: result.content
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function BrowserOnly(props) {
|
|
57
|
+
const { fallback = null } = props;
|
|
58
|
+
if (import.meta.env.SSG_MD) return /*#__PURE__*/ jsx(Fragment, {
|
|
59
|
+
children: fallback
|
|
60
|
+
});
|
|
61
|
+
return /*#__PURE__*/ jsx(Suspense, {
|
|
62
|
+
fallback: fallback,
|
|
63
|
+
children: 'function' == typeof safeBrowserOnly ? /*#__PURE__*/ jsx(ModernBrowserOnly, {
|
|
64
|
+
...props
|
|
65
|
+
}) : /*#__PURE__*/ jsx(DeferredBrowserOnly, {
|
|
66
|
+
source: props.children,
|
|
67
|
+
fallback: fallback
|
|
68
|
+
})
|
|
69
|
+
});
|
|
37
70
|
}
|
|
38
71
|
const runtime_BrowserOnly = BrowserOnly;
|
|
39
72
|
export default runtime_BrowserOnly;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Page } from './initPageData.js';
|
|
2
|
-
export declare function
|
|
3
|
-
|
|
2
|
+
export declare function createClientRouter(initialPageData?: Page): import("react-router-dom").DataRouter;
|
|
3
|
+
export declare function ClientApp({ router, }: {
|
|
4
|
+
router: ReturnType<typeof createClientRouter>;
|
|
4
5
|
}): import("react").JSX.Element;
|
|
@@ -1,14 +1,34 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { RouterProvider, ThemeContext, createBrowserRouter, removeTrailingSlash, useSite, withBase } from "@rspress/core/runtime";
|
|
3
3
|
import { useThemeState } from "@rspress/core/theme";
|
|
4
4
|
import { UnheadProvider, createHead } from "@unhead/react/client";
|
|
5
|
-
import { useMemo
|
|
6
|
-
import {
|
|
5
|
+
import { useMemo } from "react";
|
|
6
|
+
import { PAGE_ROUTE_ID } from "./pageDataLoader.js";
|
|
7
|
+
import { createPageRoutes } from "./PageRoute.js";
|
|
7
8
|
const head = createHead();
|
|
8
|
-
function
|
|
9
|
-
|
|
9
|
+
function createClientRouter(initialPageData) {
|
|
10
|
+
if (!window.history.state?.key) window.history.replaceState({
|
|
11
|
+
...window.history.state,
|
|
12
|
+
key: Math.random().toString(36).slice(2, 10)
|
|
13
|
+
}, '');
|
|
14
|
+
return createBrowserRouter(createPageRoutes(), {
|
|
15
|
+
basename: removeTrailingSlash(withBase('/')),
|
|
16
|
+
hydrationData: initialPageData ? {
|
|
17
|
+
loaderData: {
|
|
18
|
+
[PAGE_ROUTE_ID]: initialPageData
|
|
19
|
+
}
|
|
20
|
+
} : void 0
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
function ClientApp({ router }) {
|
|
10
24
|
const [theme, setTheme] = useThemeState();
|
|
11
25
|
const { site } = useSite();
|
|
26
|
+
const transitionOptions = {
|
|
27
|
+
useTransitions: site.route.useTransitions,
|
|
28
|
+
future: {
|
|
29
|
+
v7_startTransition: site.route.useTransitions
|
|
30
|
+
}
|
|
31
|
+
};
|
|
12
32
|
return /*#__PURE__*/ jsx(ThemeContext.Provider, {
|
|
13
33
|
value: useMemo(()=>({
|
|
14
34
|
theme,
|
|
@@ -17,23 +37,13 @@ function ClientApp({ initialPageData = null }) {
|
|
|
17
37
|
theme,
|
|
18
38
|
setTheme
|
|
19
39
|
]),
|
|
20
|
-
children: /*#__PURE__*/ jsx(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
data,
|
|
26
|
-
setData
|
|
27
|
-
]),
|
|
28
|
-
children: /*#__PURE__*/ jsx(BrowserRouter, {
|
|
29
|
-
basename: removeTrailingSlash(withBase('/')),
|
|
30
|
-
useTransitions: site.route.useTransitions,
|
|
31
|
-
children: /*#__PURE__*/ jsx(UnheadProvider, {
|
|
32
|
-
head: head,
|
|
33
|
-
children: /*#__PURE__*/ jsx(App, {})
|
|
34
|
-
})
|
|
40
|
+
children: /*#__PURE__*/ jsx(UnheadProvider, {
|
|
41
|
+
head: head,
|
|
42
|
+
children: /*#__PURE__*/ jsx(RouterProvider, {
|
|
43
|
+
router: router,
|
|
44
|
+
...transitionOptions
|
|
35
45
|
})
|
|
36
46
|
})
|
|
37
47
|
});
|
|
38
48
|
}
|
|
39
|
-
export { ClientApp };
|
|
49
|
+
export { ClientApp, createClientRouter };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function ErrorRoute(): import("react").JSX.Element;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { ErrorLayout } from "@rspress/core/theme";
|
|
3
|
+
import { useEffect } from "react";
|
|
4
|
+
import { useLocation, useRouteError } from "react-router-dom";
|
|
5
|
+
import { useSite } from "./hooks/useSite.js";
|
|
6
|
+
import { withBase } from "./utils.js";
|
|
7
|
+
function ErrorRoute() {
|
|
8
|
+
const error = useRouteError();
|
|
9
|
+
const { pathname } = useLocation();
|
|
10
|
+
const { site } = useSite();
|
|
11
|
+
const segments = pathname.split('/').filter(Boolean);
|
|
12
|
+
const version = site.multiVersion.versions.find((v)=>v === segments[0]);
|
|
13
|
+
const lang = site.locales.find((locale)=>locale.lang === segments[version ? 1 : 0])?.lang || site.lang;
|
|
14
|
+
const prefix = [
|
|
15
|
+
version !== site.multiVersion.default ? version : void 0,
|
|
16
|
+
lang !== site.lang ? lang : void 0
|
|
17
|
+
].filter(Boolean);
|
|
18
|
+
const homeHref = withBase(prefix.length ? `/${prefix.join('/')}/` : '/');
|
|
19
|
+
useEffect(()=>{
|
|
20
|
+
console.error('[rspress] Failed to render page:', error);
|
|
21
|
+
}, [
|
|
22
|
+
error
|
|
23
|
+
]);
|
|
24
|
+
return /*#__PURE__*/ jsx(ErrorLayout, {
|
|
25
|
+
error: error,
|
|
26
|
+
lang: lang,
|
|
27
|
+
homeHref: homeHref
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
export { ErrorRoute };
|
package/dist/runtime/NoSSR.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
export interface NoSSRProps {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
fallback?: ReactNode;
|
|
5
|
+
}
|
|
6
|
+
export declare function LegacyNoSSR({ children, fallback }: NoSSRProps): import("react").JSX.Element;
|
|
7
|
+
export declare function NoSSR(props: NoSSRProps): import("react").JSX.Element;
|
package/dist/runtime/NoSSR.js
CHANGED
|
@@ -1,14 +1,35 @@
|
|
|
1
1
|
import { Fragment, jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
setIsMounted(true);
|
|
8
|
-
}, []);
|
|
9
|
-
if (!isMounted) return null;
|
|
2
|
+
import { Suspense, useSyncExternalStore } from "react";
|
|
3
|
+
import { safeBrowserOnly } from "./reactDom.js";
|
|
4
|
+
import { safeUse } from "./react.js";
|
|
5
|
+
function ModernNoSSR({ children }) {
|
|
6
|
+
safeUse(safeBrowserOnly('This content is only rendered in the browser.'));
|
|
10
7
|
return /*#__PURE__*/ jsx(Fragment, {
|
|
11
8
|
children: children
|
|
12
9
|
});
|
|
13
10
|
}
|
|
14
|
-
|
|
11
|
+
const emptySubscribe = ()=>()=>{};
|
|
12
|
+
const getSnapshot = ()=>true;
|
|
13
|
+
const getServerSnapshot = ()=>false;
|
|
14
|
+
function LegacyNoSSR({ children, fallback = null }) {
|
|
15
|
+
const isMounted = useSyncExternalStore(emptySubscribe, getSnapshot, getServerSnapshot);
|
|
16
|
+
return /*#__PURE__*/ jsx(Fragment, {
|
|
17
|
+
children: isMounted ? children : fallback
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function NoSSR(props) {
|
|
21
|
+
const { fallback = null } = props;
|
|
22
|
+
if (import.meta.env.SSG_MD) return /*#__PURE__*/ jsx(Fragment, {
|
|
23
|
+
children: fallback
|
|
24
|
+
});
|
|
25
|
+
if ('function' == typeof safeBrowserOnly) return /*#__PURE__*/ jsx(Suspense, {
|
|
26
|
+
fallback: fallback,
|
|
27
|
+
children: /*#__PURE__*/ jsx(ModernNoSSR, {
|
|
28
|
+
...props
|
|
29
|
+
})
|
|
30
|
+
});
|
|
31
|
+
return /*#__PURE__*/ jsx(LegacyNoSSR, {
|
|
32
|
+
...props
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
export { LegacyNoSSR, NoSSR };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import nprogress from "nprogress";
|
|
3
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
4
|
+
import { Outlet, ScrollRestoration, useLoaderData, useNavigation } from "react-router-dom";
|
|
5
|
+
import { App } from "./App.js";
|
|
6
|
+
import { ErrorRoute } from "./ErrorRoute.js";
|
|
7
|
+
import { PageContext } from "./hooks/usePage.js";
|
|
8
|
+
import { PAGE_ROUTE_ID, pageDataLoader } from "./pageDataLoader.js";
|
|
9
|
+
nprogress.configure({
|
|
10
|
+
showSpinner: false
|
|
11
|
+
});
|
|
12
|
+
function PageRoute() {
|
|
13
|
+
const page = useLoaderData();
|
|
14
|
+
const { state } = useNavigation();
|
|
15
|
+
const [override, setOverride] = useState();
|
|
16
|
+
const data = override?.source === page ? override.data : page;
|
|
17
|
+
const setData = useCallback((data)=>{
|
|
18
|
+
setOverride({
|
|
19
|
+
source: page,
|
|
20
|
+
data
|
|
21
|
+
});
|
|
22
|
+
}, [
|
|
23
|
+
page
|
|
24
|
+
]);
|
|
25
|
+
useEffect(()=>{
|
|
26
|
+
if ('idle' === state) return;
|
|
27
|
+
const timer = setTimeout(()=>nprogress.start(), 200);
|
|
28
|
+
return ()=>{
|
|
29
|
+
clearTimeout(timer);
|
|
30
|
+
nprogress.done();
|
|
31
|
+
};
|
|
32
|
+
}, [
|
|
33
|
+
state
|
|
34
|
+
]);
|
|
35
|
+
return /*#__PURE__*/ jsx(PageContext.Provider, {
|
|
36
|
+
value: useMemo(()=>({
|
|
37
|
+
data,
|
|
38
|
+
setData
|
|
39
|
+
}), [
|
|
40
|
+
data,
|
|
41
|
+
setData
|
|
42
|
+
]),
|
|
43
|
+
children: /*#__PURE__*/ jsx(App, {})
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function createPageRoutes() {
|
|
47
|
+
return [
|
|
48
|
+
{
|
|
49
|
+
hydrateFallbackElement: /*#__PURE__*/ jsx(Fragment, {}),
|
|
50
|
+
element: /*#__PURE__*/ jsxs(Fragment, {
|
|
51
|
+
children: [
|
|
52
|
+
/*#__PURE__*/ jsx(Outlet, {}),
|
|
53
|
+
/*#__PURE__*/ jsx(ScrollRestoration, {
|
|
54
|
+
storageKey: "rspress-scroll-positions"
|
|
55
|
+
})
|
|
56
|
+
]
|
|
57
|
+
}),
|
|
58
|
+
children: [
|
|
59
|
+
{
|
|
60
|
+
id: PAGE_ROUTE_ID,
|
|
61
|
+
path: '*',
|
|
62
|
+
loader: pageDataLoader,
|
|
63
|
+
element: /*#__PURE__*/ jsx(PageRoute, {}),
|
|
64
|
+
errorElement: /*#__PURE__*/ jsx(ErrorRoute, {})
|
|
65
|
+
}
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
export { createPageRoutes };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createStaticHandler, createStaticRouter } from "virtual-react-router-server";
|
|
2
|
+
import { createPageRoutes } from "./PageRoute.js";
|
|
3
|
+
import { removeTrailingSlash, withBase } from "./utils.js";
|
|
4
|
+
async function createServerRouter(routePath) {
|
|
5
|
+
const basename = removeTrailingSlash(withBase('/'));
|
|
6
|
+
const { query, dataRoutes } = createStaticHandler(createPageRoutes(), {
|
|
7
|
+
basename
|
|
8
|
+
});
|
|
9
|
+
const context = await query(new Request(new URL(`${basename}${routePath}`, 'http://rspress.local')));
|
|
10
|
+
if (context instanceof Response) throw new Error(`Unexpected response while rendering ${routePath}: ${context.status}`);
|
|
11
|
+
if (context.errors) throw Object.values(context.errors)[0];
|
|
12
|
+
return {
|
|
13
|
+
router: createStaticRouter(dataRoutes, context),
|
|
14
|
+
context
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export { createServerRouter };
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { createRoot } from "react-dom/client";
|
|
3
|
-
import { ClientApp } from "./ClientApp.js";
|
|
3
|
+
import { ClientApp, createClientRouter } from "./ClientApp.js";
|
|
4
4
|
import { redirectToCleanUrl } from "./route.js";
|
|
5
5
|
function renderInBrowser() {
|
|
6
6
|
redirectToCleanUrl(window.location, window.history);
|
|
7
7
|
const container = document.getElementById('__rspress_root');
|
|
8
|
-
|
|
8
|
+
const router = createClientRouter();
|
|
9
|
+
createRoot(container).render(/*#__PURE__*/ jsx(ClientApp, {
|
|
10
|
+
router: router
|
|
11
|
+
}));
|
|
9
12
|
}
|
|
10
13
|
renderInBrowser();
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface WebMcpExecuteOptions {
|
|
2
|
+
/** Cancellation requested by the browser or agent. */
|
|
3
|
+
signal?: AbortSignal;
|
|
4
|
+
}
|
|
5
|
+
export interface WebMcpOptions<TInput = unknown, TResult = unknown> {
|
|
6
|
+
name: string;
|
|
7
|
+
title?: string;
|
|
8
|
+
description: string;
|
|
9
|
+
/** JSON Schema describing the input. Validate untrusted inputs in execute. */
|
|
10
|
+
inputSchema?: Record<string, unknown>;
|
|
11
|
+
annotations?: {
|
|
12
|
+
readOnlyHint?: boolean;
|
|
13
|
+
untrustedContentHint?: boolean;
|
|
14
|
+
consequentialHint?: boolean;
|
|
15
|
+
debugging?: boolean;
|
|
16
|
+
};
|
|
17
|
+
execute(input: TInput, options: WebMcpExecuteOptions): TResult | Promise<TResult>;
|
|
18
|
+
/** Register only while enabled. Defaults to true. */
|
|
19
|
+
enabled?: boolean;
|
|
20
|
+
/** Additional secure origins allowed to discover this tool. */
|
|
21
|
+
exposedTo?: string[];
|
|
22
|
+
}
|
|
23
|
+
export interface WebMcpState {
|
|
24
|
+
supported: boolean;
|
|
25
|
+
registered: boolean;
|
|
26
|
+
/** Registration error. Execution errors are returned to the caller. */
|
|
27
|
+
error: Error | null;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Registers a component-owned tool with the native browser WebMCP API.
|
|
31
|
+
* Calls use the latest committed handler; disabling or unmounting unregisters
|
|
32
|
+
* the tool. Safe during SSR and in browsers without WebMCP support.
|
|
33
|
+
* @returns Browser support, registration status, and any registration error.
|
|
34
|
+
* @unstable
|
|
35
|
+
*/
|
|
36
|
+
export declare function useWebMcp<TInput = unknown, TResult = unknown>(options: WebMcpOptions<TInput, TResult>): WebMcpState;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
2
|
+
const useCommittedEffect = "u" < typeof window ? useEffect : useLayoutEffect;
|
|
3
|
+
const toError = (error)=>error instanceof Error ? error : new Error(String(error));
|
|
4
|
+
function useWebMcp(options) {
|
|
5
|
+
const { execute, enabled = true, exposedTo, ...descriptor } = options;
|
|
6
|
+
const current = useRef(execute);
|
|
7
|
+
useCommittedEffect(()=>{
|
|
8
|
+
current.current = execute;
|
|
9
|
+
});
|
|
10
|
+
let key = '';
|
|
11
|
+
let preparationError = null;
|
|
12
|
+
try {
|
|
13
|
+
key = JSON.stringify({
|
|
14
|
+
descriptor,
|
|
15
|
+
exposedTo
|
|
16
|
+
});
|
|
17
|
+
} catch (error) {
|
|
18
|
+
preparationError = toError(error);
|
|
19
|
+
}
|
|
20
|
+
const preparationMessage = preparationError?.message;
|
|
21
|
+
const [state, setState] = useState({
|
|
22
|
+
supported: false,
|
|
23
|
+
registered: false,
|
|
24
|
+
error: null
|
|
25
|
+
});
|
|
26
|
+
useEffect(()=>{
|
|
27
|
+
const context = "u" < typeof document ? void 0 : document.modelContext;
|
|
28
|
+
const supported = 'function' == typeof context?.registerTool;
|
|
29
|
+
if (!supported || !enabled || void 0 !== preparationMessage) return void setState({
|
|
30
|
+
supported,
|
|
31
|
+
registered: false,
|
|
32
|
+
error: void 0 === preparationMessage ? null : new Error(preparationMessage)
|
|
33
|
+
});
|
|
34
|
+
const controller = new AbortController();
|
|
35
|
+
const metadata = JSON.parse(key);
|
|
36
|
+
setState({
|
|
37
|
+
supported: true,
|
|
38
|
+
registered: false,
|
|
39
|
+
error: null
|
|
40
|
+
});
|
|
41
|
+
const failed = (error)=>{
|
|
42
|
+
if (controller.signal.aborted) return;
|
|
43
|
+
controller.abort();
|
|
44
|
+
setState({
|
|
45
|
+
supported: true,
|
|
46
|
+
registered: false,
|
|
47
|
+
error: toError(error)
|
|
48
|
+
});
|
|
49
|
+
console.error(`[Rspress] Failed to register ${metadata.descriptor.name}:`, error);
|
|
50
|
+
};
|
|
51
|
+
try {
|
|
52
|
+
const registration = context.registerTool({
|
|
53
|
+
...metadata.descriptor,
|
|
54
|
+
execute: (input, executionOptions)=>{
|
|
55
|
+
executionOptions?.signal?.throwIfAborted();
|
|
56
|
+
return current.current(input, executionOptions ?? {});
|
|
57
|
+
}
|
|
58
|
+
}, {
|
|
59
|
+
signal: controller.signal,
|
|
60
|
+
exposedTo: metadata.exposedTo
|
|
61
|
+
});
|
|
62
|
+
Promise.resolve(registration).then(()=>{
|
|
63
|
+
if (!controller.signal.aborted) setState({
|
|
64
|
+
supported: true,
|
|
65
|
+
registered: true,
|
|
66
|
+
error: null
|
|
67
|
+
});
|
|
68
|
+
}, failed);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
failed(error);
|
|
71
|
+
}
|
|
72
|
+
return ()=>controller.abort();
|
|
73
|
+
}, [
|
|
74
|
+
key,
|
|
75
|
+
enabled,
|
|
76
|
+
preparationMessage
|
|
77
|
+
]);
|
|
78
|
+
return state;
|
|
79
|
+
}
|
|
80
|
+
export { useWebMcp };
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export { useActiveMatcher } from './hooks/useActiveMatcher.js';
|
|
|
7
7
|
export { ThemeContext, useDark } from './hooks/useDark.js';
|
|
8
8
|
export { useFrontmatter } from './hooks/useFrontmatter.js';
|
|
9
9
|
export { useI18n } from './hooks/useI18n.js';
|
|
10
|
+
export { useI18nText } from './hooks/useI18nText.js';
|
|
10
11
|
export { useLang } from './hooks/useLang.js';
|
|
11
12
|
export { useLocaleSiteData } from './hooks/useLocaleSiteData.js';
|
|
12
13
|
export { useNav } from './hooks/useNav.js';
|
|
@@ -16,11 +17,13 @@ export { usePages, searchIndexHash } from './hooks/usePages.js';
|
|
|
16
17
|
export { getSidebarDataGroup, useSidebar, useSidebarDynamic, } from './hooks/useSidebar.js';
|
|
17
18
|
export { useSite } from './hooks/useSite.js';
|
|
18
19
|
export { useVersion } from './hooks/useVersion.js';
|
|
20
|
+
export { useWebMcp, type WebMcpOptions, type WebMcpState, type WebMcpExecuteOptions, } from './hooks/useWebMcp.js';
|
|
19
21
|
export { useWindowSize } from './hooks/useWindowSize.js';
|
|
20
|
-
export { initPageData
|
|
22
|
+
export { initPageData } from './initPageData.js';
|
|
21
23
|
export { NoSSR } from './NoSSR.js';
|
|
22
|
-
export {
|
|
24
|
+
export { safeUse } from './react.js';
|
|
25
|
+
export { safePreconnect, safePreload, safeBrowserOnly } from './reactDom.js';
|
|
23
26
|
export { isActive, pathnameToRouteService, preloadLink } from './route.js';
|
|
24
27
|
export { addLeadingSlash, addTrailingSlash, cleanUrlByConfig, isEqualPath, isProduction, normalizeHrefInRuntime, normalizeImagePath, removeBase, removeTrailingSlash, routePathToMdPath, withBase, withSiteOrigin, } from './utils.js';
|
|
25
|
-
export
|
|
28
|
+
export { socialLinks } from './socialLinks.js';
|
|
26
29
|
export { useSearchHooks, type SearchHooks } from './hooks/useSearchHooks.js';
|
package/dist/runtime/index.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import virtual_social_links from "virtual-social-links";
|
|
2
1
|
export * from "react-router-dom";
|
|
3
|
-
const socialLinks = virtual_social_links;
|
|
4
2
|
export { isDataUrl, isExternalUrl, matchNavbar, matchSidebar, normalizeHref } from "@rspress/shared";
|
|
5
3
|
export { Head, useHead } from "@unhead/react";
|
|
6
4
|
export { BrowserOnly } from "./BrowserOnly.js";
|
|
@@ -9,6 +7,7 @@ export { useActiveMatcher } from "./hooks/useActiveMatcher.js";
|
|
|
9
7
|
export { ThemeContext, useDark } from "./hooks/useDark.js";
|
|
10
8
|
export { useFrontmatter } from "./hooks/useFrontmatter.js";
|
|
11
9
|
export { useI18n } from "./hooks/useI18n.js";
|
|
10
|
+
export { useI18nText } from "./hooks/useI18nText.js";
|
|
12
11
|
export { useLang } from "./hooks/useLang.js";
|
|
13
12
|
export { useLocaleSiteData } from "./hooks/useLocaleSiteData.js";
|
|
14
13
|
export { useNav } from "./hooks/useNav.js";
|
|
@@ -18,11 +17,13 @@ export { searchIndexHash, usePages } from "./hooks/usePages.js";
|
|
|
18
17
|
export { getSidebarDataGroup, useSidebar, useSidebarDynamic } from "./hooks/useSidebar.js";
|
|
19
18
|
export { useSite } from "./hooks/useSite.js";
|
|
20
19
|
export { useVersion } from "./hooks/useVersion.js";
|
|
20
|
+
export { useWebMcp } from "./hooks/useWebMcp.js";
|
|
21
21
|
export { useWindowSize } from "./hooks/useWindowSize.js";
|
|
22
|
-
export { initPageData
|
|
22
|
+
export { initPageData } from "./initPageData.js";
|
|
23
23
|
export { NoSSR } from "./NoSSR.js";
|
|
24
|
-
export {
|
|
24
|
+
export { safeUse } from "./react.js";
|
|
25
|
+
export { safeBrowserOnly, safePreconnect, safePreload } from "./reactDom.js";
|
|
25
26
|
export { isActive, pathnameToRouteService, preloadLink } from "./route.js";
|
|
26
27
|
export { addLeadingSlash, addTrailingSlash, cleanUrlByConfig, isEqualPath, isProduction, normalizeHrefInRuntime, normalizeImagePath, removeBase, removeTrailingSlash, routePathToMdPath, withBase, withSiteOrigin } from "./utils.js";
|
|
28
|
+
export { socialLinks } from "./socialLinks.js";
|
|
27
29
|
export { useSearchHooks } from "./hooks/useSearchHooks.js";
|
|
28
|
-
export { socialLinks };
|
|
@@ -1,6 +1,3 @@
|
|
|
1
1
|
import { type PageDataLegacy } from '@rspress/shared';
|
|
2
2
|
export type Page = PageDataLegacy['page'];
|
|
3
|
-
export declare function warmPageData(routePath: string, data: Page): void;
|
|
4
|
-
export declare function consumeCachedPageData(routePath: string): Page | undefined;
|
|
5
|
-
export declare function setCurrentPageData(routePath: string, data: Page): void;
|
|
6
3
|
export declare function initPageData(routePath: string): Promise<Page>;
|
|
@@ -3,40 +3,6 @@ import { pageData } from "./hooks/usePages.js";
|
|
|
3
3
|
import { pathnameToRouteService } from "./route.js";
|
|
4
4
|
import { siteData } from "./hooks/useSite.js";
|
|
5
5
|
import { isEqualPath } from "./utils.js";
|
|
6
|
-
const slots = [
|
|
7
|
-
void 0,
|
|
8
|
-
void 0,
|
|
9
|
-
void 0
|
|
10
|
-
];
|
|
11
|
-
function warmPageData(routePath, data) {
|
|
12
|
-
slots[0] = {
|
|
13
|
-
routePath,
|
|
14
|
-
data
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
function consumeCachedPageData(routePath) {
|
|
18
|
-
if (slots[0]?.routePath === routePath) {
|
|
19
|
-
const data = slots[0].data;
|
|
20
|
-
slots[2] = slots[1];
|
|
21
|
-
slots[1] = slots[0];
|
|
22
|
-
slots[0] = void 0;
|
|
23
|
-
return data;
|
|
24
|
-
}
|
|
25
|
-
if (slots[2]?.routePath === routePath) {
|
|
26
|
-
const data = slots[2].data;
|
|
27
|
-
slots[0] = slots[1];
|
|
28
|
-
slots[1] = slots[2];
|
|
29
|
-
slots[2] = void 0;
|
|
30
|
-
return data;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
function setCurrentPageData(routePath, data) {
|
|
34
|
-
slots[2] = slots[1];
|
|
35
|
-
slots[1] = {
|
|
36
|
-
routePath,
|
|
37
|
-
data
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
6
|
async function initPageData(routePath) {
|
|
41
7
|
const matchedRoute = pathnameToRouteService(routePath);
|
|
42
8
|
if (matchedRoute) {
|
|
@@ -59,16 +25,14 @@ async function initPageData(routePath) {
|
|
|
59
25
|
}
|
|
60
26
|
let lang = siteData.lang || '';
|
|
61
27
|
let version = siteData.multiVersion?.default || '';
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (result) version = result;
|
|
71
|
-
}
|
|
28
|
+
const path = routePath.replace(/^\//, '').split('/').slice(0, 2);
|
|
29
|
+
if (siteData.locales.length) {
|
|
30
|
+
const result = siteData.locales.find(({ lang })=>path.includes(lang));
|
|
31
|
+
if (result) lang = result.lang;
|
|
32
|
+
}
|
|
33
|
+
if (siteData.multiVersion.versions) {
|
|
34
|
+
const result = siteData.multiVersion.versions.find((version)=>path.includes(version));
|
|
35
|
+
if (result) version = result;
|
|
72
36
|
}
|
|
73
37
|
return {
|
|
74
38
|
pagePath: '',
|
|
@@ -83,4 +47,4 @@ async function initPageData(routePath) {
|
|
|
83
47
|
_relativePath: ''
|
|
84
48
|
};
|
|
85
49
|
}
|
|
86
|
-
export {
|
|
50
|
+
export { initPageData };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { LoaderFunctionArgs } from 'react-router-dom';
|
|
2
|
+
export declare const PAGE_ROUTE_ID = "rspress-page";
|
|
3
|
+
export declare function pageDataLoader({ request }: LoaderFunctionArgs): Promise<import("@rspress/shared").BaseRuntimePageInfo & {
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
headingTitle?: string;
|
|
6
|
+
pagePath: string;
|
|
7
|
+
lastUpdatedTime?: string;
|
|
8
|
+
lastUpdatedAuthor?: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
pageType: import("@rspress/shared").PageType;
|
|
11
|
+
}>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { initPageData } from "./initPageData.js";
|
|
2
|
+
import { removeBase } from "./utils.js";
|
|
3
|
+
const PAGE_ROUTE_ID = 'rspress-page';
|
|
4
|
+
function pageDataLoader({ request }) {
|
|
5
|
+
return initPageData(removeBase(new URL(request.url).pathname));
|
|
6
|
+
}
|
|
7
|
+
export { PAGE_ROUTE_ID, pageDataLoader };
|