@rspress/core 2.0.23 → 2.1.0-beta.1
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/b~0.js +1 -3
- package/dist/cli/index.js +1 -1
- package/dist/{common-Qw-RoVFD.js → common-Bo3KCGim.js} +4 -1
- package/dist/config/loadConfigFile.js +1 -1
- package/dist/eject-theme/components/Link/getHref.ts +1 -0
- package/dist/eject-theme/components/Link/index.tsx +0 -3
- package/dist/eject-theme/components/Link/useLinkNavigate.ts +29 -54
- 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/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/{a~0.js → h~0.js} +18 -15
- package/dist/index.d.ts +1 -1
- package/dist/node/PluginDriver.js +8 -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/eject.js +1 -1
- package/dist/node/initRsbuild.js +8 -4
- 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/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 +28 -0
- package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.js +28 -0
- package/dist/node/runtimeModule/i18n.js +1 -1
- 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.js +1 -1
- package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
- package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +1 -1
- package/dist/node/serve.js +1 -1
- package/dist/node/sitemap.d.ts +2 -0
- package/dist/node/sitemap.js +103 -0
- package/dist/node/ssg/alternateLinks.js +1 -1
- package/dist/node/ssg/renderPages.js +1 -1
- 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 +1 -1
- 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 +5 -2
- package/dist/runtime/App.js +12 -25
- package/dist/runtime/ClientApp.d.ts +3 -2
- package/dist/runtime/ClientApp.js +27 -21
- package/dist/runtime/ErrorRoute.d.ts +1 -0
- package/dist/runtime/ErrorRoute.js +30 -0
- package/dist/runtime/PageRoute.d.ts +2 -0
- package/dist/runtime/PageRoute.js +58 -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 +3 -1
- package/dist/runtime/index.js +3 -1
- 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/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/components/Link/index.js +0 -4
- package/dist/theme/components/Link/useLinkNavigate.d.ts +2 -2
- package/dist/theme/components/Link/useLinkNavigate.js +13 -35
- package/dist/theme/components/Search/logic/providers/LocalProvider.js +4 -1
- package/dist/theme/components/Search/useSearchPanel.js +74 -26
- package/dist/theme/components/SocialLinks/GithubStars.js +1 -1
- 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/index.d.ts +5 -0
- package/dist/theme/index.js +5 -0
- 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/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/tu~0.js +3 -0
- package/package.json +12 -12
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
2
|
+
import nprogress from "nprogress";
|
|
3
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
4
|
+
import { 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
|
+
id: PAGE_ROUTE_ID,
|
|
50
|
+
path: '*',
|
|
51
|
+
loader: pageDataLoader,
|
|
52
|
+
element: /*#__PURE__*/ jsx(PageRoute, {}),
|
|
53
|
+
errorElement: /*#__PURE__*/ jsx(ErrorRoute, {}),
|
|
54
|
+
hydrateFallbackElement: /*#__PURE__*/ jsx(Fragment, {})
|
|
55
|
+
}
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
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,8 +17,9 @@ 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
24
|
export { safePreconnect, safePreload } from './reactDom.js';
|
|
23
25
|
export { isActive, pathnameToRouteService, preloadLink } from './route.js';
|
package/dist/runtime/index.js
CHANGED
|
@@ -9,6 +9,7 @@ export { useActiveMatcher } from "./hooks/useActiveMatcher.js";
|
|
|
9
9
|
export { ThemeContext, useDark } from "./hooks/useDark.js";
|
|
10
10
|
export { useFrontmatter } from "./hooks/useFrontmatter.js";
|
|
11
11
|
export { useI18n } from "./hooks/useI18n.js";
|
|
12
|
+
export { useI18nText } from "./hooks/useI18nText.js";
|
|
12
13
|
export { useLang } from "./hooks/useLang.js";
|
|
13
14
|
export { useLocaleSiteData } from "./hooks/useLocaleSiteData.js";
|
|
14
15
|
export { useNav } from "./hooks/useNav.js";
|
|
@@ -18,8 +19,9 @@ export { searchIndexHash, usePages } from "./hooks/usePages.js";
|
|
|
18
19
|
export { getSidebarDataGroup, useSidebar, useSidebarDynamic } from "./hooks/useSidebar.js";
|
|
19
20
|
export { useSite } from "./hooks/useSite.js";
|
|
20
21
|
export { useVersion } from "./hooks/useVersion.js";
|
|
22
|
+
export { useWebMcp } from "./hooks/useWebMcp.js";
|
|
21
23
|
export { useWindowSize } from "./hooks/useWindowSize.js";
|
|
22
|
-
export { initPageData
|
|
24
|
+
export { initPageData } from "./initPageData.js";
|
|
23
25
|
export { NoSSR } from "./NoSSR.js";
|
|
24
26
|
export { safePreconnect, safePreload } from "./reactDom.js";
|
|
25
27
|
export { isActive, pathnameToRouteService, preloadLink } from "./route.js";
|
|
@@ -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 };
|
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { removeBase } from "@rspress/core/runtime";
|
|
3
3
|
import { startTransition } from "react";
|
|
4
|
-
import { hydrateRoot } from "react-dom/client";
|
|
5
|
-
import { ClientApp } from "./ClientApp.js";
|
|
6
|
-
import { initPageData
|
|
4
|
+
import { createRoot, hydrateRoot } from "react-dom/client";
|
|
5
|
+
import { ClientApp, createClientRouter } from "./ClientApp.js";
|
|
6
|
+
import { initPageData } from "./initPageData.js";
|
|
7
7
|
import { redirectToCleanUrl } from "./route.js";
|
|
8
8
|
async function renderInBrowser() {
|
|
9
9
|
redirectToCleanUrl(window.location, window.history);
|
|
10
10
|
const container = document.getElementById('__rspress_root');
|
|
11
11
|
const pathname = removeBase(window.location.pathname);
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
let initialPageData;
|
|
13
|
+
try {
|
|
14
|
+
initialPageData = await initPageData(pathname);
|
|
15
|
+
} catch {
|
|
16
|
+
createRoot(container).render(/*#__PURE__*/ jsx(ClientApp, {
|
|
17
|
+
router: createClientRouter()
|
|
18
|
+
}));
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const router = createClientRouter(initialPageData);
|
|
14
22
|
startTransition(()=>{
|
|
15
23
|
hydrateRoot(container, /*#__PURE__*/ jsx(ClientApp, {
|
|
16
|
-
|
|
24
|
+
router: router
|
|
17
25
|
}), {
|
|
18
26
|
onRecoverableError (error, errorInfo) {
|
|
19
27
|
if (error instanceof Error) console.warn('hydrateRoot recoverable error:', error, errorInfo);
|
|
@@ -1,33 +1,22 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { ThemeContext } from "@rspress/core/runtime";
|
|
3
3
|
import { UnheadProvider } from "@unhead/react/server";
|
|
4
4
|
import { renderToMarkdownString } from "react-render-to-markdown";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { initPageData } from "./initPageData.js";
|
|
5
|
+
import { StaticRouterProvider } from "virtual-react-router-server";
|
|
6
|
+
import { createServerRouter } from "./createServerRouter.js";
|
|
8
7
|
const DEFAULT_THEME = 'light';
|
|
9
|
-
async function preloadRoute(pathname) {
|
|
10
|
-
const route = pathnameToRouteService(pathname);
|
|
11
|
-
await route?.preload();
|
|
12
|
-
}
|
|
13
8
|
async function render(routePath, head) {
|
|
14
|
-
const
|
|
15
|
-
await preloadRoute(routePath);
|
|
9
|
+
const { router, context } = await createServerRouter(routePath);
|
|
16
10
|
const appMd = await renderToMarkdownString(/*#__PURE__*/ jsx(ThemeContext.Provider, {
|
|
17
11
|
value: {
|
|
18
12
|
theme: DEFAULT_THEME
|
|
19
13
|
},
|
|
20
|
-
children: /*#__PURE__*/ jsx(
|
|
21
|
-
value:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
basename: removeTrailingSlash(withBase('/')),
|
|
27
|
-
children: /*#__PURE__*/ jsx(UnheadProvider, {
|
|
28
|
-
value: head,
|
|
29
|
-
children: /*#__PURE__*/ jsx(App, {})
|
|
30
|
-
})
|
|
14
|
+
children: /*#__PURE__*/ jsx(UnheadProvider, {
|
|
15
|
+
value: head,
|
|
16
|
+
children: /*#__PURE__*/ jsx(StaticRouterProvider, {
|
|
17
|
+
router: router,
|
|
18
|
+
context: context,
|
|
19
|
+
hydrate: false
|
|
31
20
|
})
|
|
32
21
|
})
|
|
33
22
|
}));
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { PassThrough } from "node:stream";
|
|
3
3
|
import { text as consumers_text } from "node:stream/consumers";
|
|
4
|
-
import {
|
|
4
|
+
import { ThemeContext } from "@rspress/core/runtime";
|
|
5
5
|
import { UnheadProvider } from "@unhead/react/server";
|
|
6
6
|
import { renderToPipeableStream } from "react-dom/server";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { initPageData } from "./initPageData.js";
|
|
7
|
+
import { StaticRouterProvider } from "virtual-react-router-server";
|
|
8
|
+
import { createServerRouter } from "./createServerRouter.js";
|
|
10
9
|
const DEFAULT_THEME = 'light';
|
|
11
|
-
async function preloadRoute(pathname) {
|
|
12
|
-
const route = pathnameToRouteService(pathname);
|
|
13
|
-
await route?.preload();
|
|
14
|
-
}
|
|
15
10
|
function renderToHtml(app) {
|
|
16
11
|
return new Promise((resolve, reject)=>{
|
|
17
12
|
const passThrough = new PassThrough();
|
|
@@ -28,23 +23,17 @@ function renderToHtml(app) {
|
|
|
28
23
|
});
|
|
29
24
|
}
|
|
30
25
|
async function render(routePath, head) {
|
|
31
|
-
const
|
|
32
|
-
await preloadRoute(routePath);
|
|
26
|
+
const { router, context } = await createServerRouter(routePath);
|
|
33
27
|
const appHtml = await renderToHtml(/*#__PURE__*/ jsx(ThemeContext.Provider, {
|
|
34
28
|
value: {
|
|
35
29
|
theme: DEFAULT_THEME
|
|
36
30
|
},
|
|
37
|
-
children: /*#__PURE__*/ jsx(
|
|
38
|
-
value:
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
basename: removeTrailingSlash(withBase('/')),
|
|
44
|
-
children: /*#__PURE__*/ jsx(UnheadProvider, {
|
|
45
|
-
value: head,
|
|
46
|
-
children: /*#__PURE__*/ jsx(App, {})
|
|
47
|
-
})
|
|
31
|
+
children: /*#__PURE__*/ jsx(UnheadProvider, {
|
|
32
|
+
value: head,
|
|
33
|
+
children: /*#__PURE__*/ jsx(StaticRouterProvider, {
|
|
34
|
+
router: router,
|
|
35
|
+
context: context,
|
|
36
|
+
hydrate: false
|
|
48
37
|
})
|
|
49
38
|
})
|
|
50
39
|
}));
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tinypool",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "2.2.0",
|
|
5
|
+
"description": "A minimal and tiny Node.js Worker Thread Pool implementation, a fork of piscina, but with fewer features",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/tinylibs/tinypool#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/tinylibs/tinypool.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/tinylibs/tinypool/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"fast",
|
|
17
|
+
"worker threads",
|
|
18
|
+
"thread pool"
|
|
19
|
+
],
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"default": "./dist/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./package.json": "./package.json"
|
|
26
|
+
},
|
|
27
|
+
"main": "./dist/index.js",
|
|
28
|
+
"module": "./dist/index.js",
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"files": [
|
|
31
|
+
"dist"
|
|
32
|
+
],
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": "^20.0.0 || >=22.0.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/node": "^20.12.8",
|
|
38
|
+
"clean-publish": "^3.4.4",
|
|
39
|
+
"eslint": "^9.4.0",
|
|
40
|
+
"eslint-config-prettier": "^9.1.0",
|
|
41
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
42
|
+
"eslint-plugin-unicorn": "^53.0.0",
|
|
43
|
+
"prettier": "^3.3.2",
|
|
44
|
+
"tsdown": "^0.11.3",
|
|
45
|
+
"typescript": "^5.4.5",
|
|
46
|
+
"typescript-eslint": "^7.13.0",
|
|
47
|
+
"vite": "^5.2.11",
|
|
48
|
+
"vitest": "^4.0.1"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"test": "vitest",
|
|
52
|
+
"bench": "vitest bench",
|
|
53
|
+
"dev": "tsdown --watch ./src",
|
|
54
|
+
"build": "tsdown",
|
|
55
|
+
"lint": "eslint --max-warnings=0",
|
|
56
|
+
"typecheck": "tsc --noEmit"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { preloadLink } from "@rspress/core/runtime";
|
|
3
3
|
import clsx from "clsx";
|
|
4
|
-
import nprogress from "nprogress";
|
|
5
4
|
import { forwardRef } from "react";
|
|
6
5
|
import "./index.css";
|
|
7
6
|
import { getHref } from "./getHref.js";
|
|
8
7
|
import { useLinkNavigate } from "./useLinkNavigate.js";
|
|
9
|
-
nprogress.configure({
|
|
10
|
-
showSpinner: false
|
|
11
|
-
});
|
|
12
8
|
const Link = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
13
9
|
const { href = '/', children, className = '', onClick, onMouseEnter, startTransition, ...otherProps } = props;
|
|
14
10
|
const { linkType, removeBaseHref, routePath, withBaseHref } = getHref(href);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type TransitionStartFunction } from 'react';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* Navigate with Rspress link normalization. The router loader handles page
|
|
4
|
+
* loading for both this helper and the native useNavigate hook.
|
|
5
5
|
*/
|
|
6
6
|
export declare function useLinkNavigate({ startTransition, }?: {
|
|
7
7
|
startTransition?: TransitionStartFunction;
|
|
@@ -1,48 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import { startTransition as external_react_startTransition, useCallback } from "react";
|
|
1
|
+
import { isActive, pathnameToRouteService, useLocation, useNavigate, useSite } from "@rspress/core/runtime";
|
|
2
|
+
import { useCallback } from "react";
|
|
4
3
|
import { getHref } from "./getHref.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
});
|
|
8
|
-
function useLinkNavigate({ startTransition = external_react_startTransition } = {
|
|
9
|
-
startTransition: external_react_startTransition
|
|
10
|
-
}) {
|
|
11
|
-
const { pathname: currPagePathname } = useLocation();
|
|
4
|
+
function useLinkNavigate({ startTransition } = {}) {
|
|
5
|
+
const { pathname } = useLocation();
|
|
12
6
|
const navigate = useNavigate();
|
|
13
7
|
const { site } = useSite();
|
|
14
8
|
const useTransitions = site?.route?.useTransitions;
|
|
15
9
|
return useCallback(async (href)=>{
|
|
16
10
|
const { linkType, removeBaseHref, routePath, withBaseHref } = getHref(href);
|
|
17
11
|
if ('external' === linkType || 'hashOnly' === linkType) return void window.location.assign(href);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
else {
|
|
25
|
-
const timer = setTimeout(()=>{
|
|
26
|
-
nprogress.start();
|
|
27
|
-
}, 200);
|
|
28
|
-
const data = await initPageData(routePath);
|
|
29
|
-
warmPageData(routePath, data);
|
|
30
|
-
clearTimeout(timer);
|
|
31
|
-
nprogress.done();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
if (isTransitionable) startTransition(()=>navigate(removeBaseHref, {
|
|
35
|
-
replace: false
|
|
36
|
-
}));
|
|
37
|
-
else navigate(removeBaseHref, {
|
|
38
|
-
replace: false
|
|
12
|
+
if (!isActive(removeBaseHref, pathname) && !pathnameToRouteService(routePath)) return void window.location.assign(withBaseHref);
|
|
13
|
+
if (useTransitions && startTransition) {
|
|
14
|
+
let navigation;
|
|
15
|
+
startTransition(()=>{
|
|
16
|
+
navigation = navigate(removeBaseHref);
|
|
17
|
+
return navigation;
|
|
39
18
|
});
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
else preloadChunkThenNavigate();
|
|
19
|
+
await navigation;
|
|
20
|
+
} else await navigate(removeBaseHref);
|
|
43
21
|
}, [
|
|
44
22
|
useTransitions,
|
|
45
|
-
|
|
23
|
+
pathname,
|
|
46
24
|
navigate,
|
|
47
25
|
startTransition
|
|
48
26
|
]);
|
|
@@ -47,7 +47,10 @@ class LocalProvider {
|
|
|
47
47
|
if (this.#fetchPromise) return this.#fetchPromise;
|
|
48
48
|
const { currentLang, currentVersion } = options;
|
|
49
49
|
const versioned = options.versioned ?? true;
|
|
50
|
-
this.#fetchPromise = this.#getPages(currentLang, versioned ? currentVersion : '')
|
|
50
|
+
this.#fetchPromise = this.#getPages(currentLang, versioned ? currentVersion : '').catch((error)=>{
|
|
51
|
+
this.#fetchPromise = void 0;
|
|
52
|
+
throw error;
|
|
53
|
+
});
|
|
51
54
|
return this.#fetchPromise;
|
|
52
55
|
}
|
|
53
56
|
async init(options) {
|