@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,9 +1,10 @@
|
|
|
1
|
-
import { usePageData, useSearchHooks } from "@rspress/core/runtime";
|
|
1
|
+
import { usePageData, useSearchHooks, useWebMcp } from "@rspress/core/runtime";
|
|
2
2
|
import { debounce } from "@rspress/shared/lodash-es";
|
|
3
3
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
4
4
|
import { getSearchIndexURL } from "./logic/providers/LocalProvider.js";
|
|
5
5
|
import { PageSearcher } from "./logic/search.js";
|
|
6
6
|
import { RenderType } from "./logic/types.js";
|
|
7
|
+
import { defineTool, queryField, toWebMcpSearchResults } from "../../webMcp/tools.js";
|
|
7
8
|
const useDebounce = (cb)=>{
|
|
8
9
|
const cbRef = useRef(cb);
|
|
9
10
|
cbRef.current = cb;
|
|
@@ -22,6 +23,8 @@ function useSearchPanel({ focused, searchInputRef }) {
|
|
|
22
23
|
const [searchError, setSearchError] = useState();
|
|
23
24
|
const pageSearcherRef = useRef(null);
|
|
24
25
|
const pageSearcherConfigRef = useRef(null);
|
|
26
|
+
const pageSearcherURLRef = useRef(void 0);
|
|
27
|
+
const initializationRef = useRef(void 0);
|
|
25
28
|
const searchEnabled = false !== search;
|
|
26
29
|
const searchOptions = false === search ? {} : search;
|
|
27
30
|
const versionedSearch = searchEnabled && (search?.versioned ?? true);
|
|
@@ -34,7 +37,8 @@ function useSearchPanel({ focused, searchInputRef }) {
|
|
|
34
37
|
}
|
|
35
38
|
];
|
|
36
39
|
const createSearcher = ()=>{
|
|
37
|
-
|
|
40
|
+
const previous = pageSearcherConfigRef.current;
|
|
41
|
+
if (pageSearcherRef.current && previous?.currentLang === lang && (!versionedSearch || previous.currentVersion === version) && pageSearcherURLRef.current === searchIndexURL) return pageSearcherRef.current;
|
|
38
42
|
const pageSearcherConfig = {
|
|
39
43
|
currentLang: lang,
|
|
40
44
|
currentVersion: version
|
|
@@ -46,15 +50,62 @@ function useSearchPanel({ focused, searchInputRef }) {
|
|
|
46
50
|
});
|
|
47
51
|
pageSearcherRef.current = pageSearcher;
|
|
48
52
|
pageSearcherConfigRef.current = pageSearcherConfig;
|
|
53
|
+
pageSearcherURLRef.current = searchIndexURL;
|
|
49
54
|
return pageSearcher;
|
|
50
55
|
};
|
|
56
|
+
const initializeSearcher = (searcher)=>{
|
|
57
|
+
if (initializationRef.current?.searcher === searcher) return initializationRef.current.promise;
|
|
58
|
+
const promise = searcher.init().catch((error)=>{
|
|
59
|
+
if (initializationRef.current?.searcher === searcher) initializationRef.current = void 0;
|
|
60
|
+
throw error;
|
|
61
|
+
});
|
|
62
|
+
initializationRef.current = {
|
|
63
|
+
searcher,
|
|
64
|
+
promise
|
|
65
|
+
};
|
|
66
|
+
return promise;
|
|
67
|
+
};
|
|
68
|
+
const searchDocs = async (value, limit)=>{
|
|
69
|
+
const searcher = createSearcher();
|
|
70
|
+
let newQuery = value;
|
|
71
|
+
const result = [];
|
|
72
|
+
if (userSearchHooks.beforeSearch) {
|
|
73
|
+
const transformedQuery = await userSearchHooks.beforeSearch(newQuery);
|
|
74
|
+
if (transformedQuery) newQuery = transformedQuery;
|
|
75
|
+
}
|
|
76
|
+
await initializeSearcher(searcher);
|
|
77
|
+
const defaultSearchResult = await searcher.match(newQuery, limit);
|
|
78
|
+
result.push(...defaultSearchResult);
|
|
79
|
+
if (userSearchHooks.onSearch) {
|
|
80
|
+
const customSearchResult = await userSearchHooks.onSearch(newQuery, result);
|
|
81
|
+
if (customSearchResult) result.push(...customSearchResult.map((item)=>({
|
|
82
|
+
renderType: RenderType.Custom,
|
|
83
|
+
...item
|
|
84
|
+
})));
|
|
85
|
+
}
|
|
86
|
+
await userSearchHooks.afterSearch?.(newQuery, result);
|
|
87
|
+
return result;
|
|
88
|
+
};
|
|
89
|
+
if (import.meta.env.ENABLE_WEBMCP) useWebMcp({
|
|
90
|
+
...defineTool('search_docs', 'Search documentation through the active local search component.', {
|
|
91
|
+
query: queryField,
|
|
92
|
+
limit: {
|
|
93
|
+
type: 'integer',
|
|
94
|
+
minimum: 1,
|
|
95
|
+
maximum: 20
|
|
96
|
+
}
|
|
97
|
+
}, [
|
|
98
|
+
'query'
|
|
99
|
+
], async (args)=>toWebMcpSearchResults(await searchDocs(args.query, args.limit ?? 10))),
|
|
100
|
+
enabled: searchEnabled && Boolean(searchIndexURL || userSearchHooks.onSearch)
|
|
101
|
+
});
|
|
51
102
|
const initSearch = async ()=>{
|
|
52
103
|
if ('initial' !== initStatus) return;
|
|
53
104
|
const searcher = createSearcher();
|
|
54
105
|
setSearchError(void 0);
|
|
55
106
|
setInitStatus('initing');
|
|
56
107
|
try {
|
|
57
|
-
await searcher
|
|
108
|
+
await initializeSearcher(searcher);
|
|
58
109
|
} catch (error) {
|
|
59
110
|
if (pageSearcherRef.current !== searcher) return;
|
|
60
111
|
setSearchError(error instanceof Error ? error.message : String(error));
|
|
@@ -87,42 +138,39 @@ function useSearchPanel({ focused, searchInputRef }) {
|
|
|
87
138
|
const { currentLang, currentVersion } = pageSearcherConfigRef.current ?? {};
|
|
88
139
|
const isLangChanged = lang !== currentLang;
|
|
89
140
|
const isVersionChanged = versionedSearch && version !== currentVersion;
|
|
90
|
-
|
|
141
|
+
const isIndexChanged = pageSearcherURLRef.current !== searchIndexURL;
|
|
142
|
+
if (isLangChanged || isVersionChanged || isIndexChanged) {
|
|
91
143
|
setInitStatus('initial');
|
|
92
144
|
setSearchError(void 0);
|
|
93
145
|
setIsSearching(false);
|
|
94
146
|
pageSearcherRef.current = null;
|
|
95
|
-
createSearcher().fetchSearchIndex().catch(()=>{});
|
|
96
147
|
}
|
|
97
148
|
}, [
|
|
98
149
|
lang,
|
|
99
150
|
version,
|
|
100
151
|
versionedSearch,
|
|
101
|
-
searchEnabled
|
|
152
|
+
searchEnabled,
|
|
153
|
+
searchIndexURL
|
|
102
154
|
]);
|
|
103
155
|
const handleQueryChangedImpl = async (value)=>{
|
|
104
|
-
|
|
156
|
+
const newQuery = value;
|
|
105
157
|
setQuery(newQuery);
|
|
106
158
|
if (!newQuery) return void setIsSearching(false);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (searchInputRef.current?.value === newQuery) {
|
|
123
|
-
setCurrentSuggestionIndex(0);
|
|
124
|
-
setSearchResult(result || DEFAULT_RESULT);
|
|
125
|
-
setIsSearching(false);
|
|
159
|
+
try {
|
|
160
|
+
const result = await searchDocs(value);
|
|
161
|
+
if (searchInputRef.current?.value === newQuery) {
|
|
162
|
+
setSearchError(void 0);
|
|
163
|
+
setInitStatus('inited');
|
|
164
|
+
setCurrentSuggestionIndex(0);
|
|
165
|
+
setSearchResult(result || DEFAULT_RESULT);
|
|
166
|
+
setIsSearching(false);
|
|
167
|
+
}
|
|
168
|
+
} catch (error) {
|
|
169
|
+
if (searchInputRef.current?.value === newQuery) {
|
|
170
|
+
setSearchError(error instanceof Error ? error.message : String(error));
|
|
171
|
+
setInitStatus('error');
|
|
172
|
+
setIsSearching(false);
|
|
173
|
+
}
|
|
126
174
|
}
|
|
127
175
|
};
|
|
128
176
|
const handleQueryChange = useDebounce(handleQueryChangedImpl);
|
|
@@ -65,11 +65,16 @@
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
.rp-sidebar-item__left {
|
|
68
|
+
overflow-wrap: anywhere;
|
|
68
69
|
align-items: center;
|
|
69
70
|
gap: 4px;
|
|
70
71
|
display: flex;
|
|
71
72
|
}
|
|
72
73
|
|
|
74
|
+
.rp-sidebar-item__left > .rp-doc code {
|
|
75
|
+
overflow-wrap: anywhere;
|
|
76
|
+
}
|
|
77
|
+
|
|
73
78
|
.rp-sidebar-item__icon {
|
|
74
79
|
object-fit: contain;
|
|
75
80
|
flex: 0 0 16px;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useStorageValue } from "@rspress/core/theme";
|
|
2
3
|
import { useEffect, useState } from "react";
|
|
3
|
-
import { useStorageValue } from "../../logic/useStorageValue.js";
|
|
4
4
|
const TTL_MS = 3600000;
|
|
5
5
|
function storageKey(repo) {
|
|
6
6
|
return `rp-github-stars:${repo}`;
|
|
@@ -1,29 +1,18 @@
|
|
|
1
|
-
import { usePage } from "@rspress/core/runtime";
|
|
2
|
-
import { useCallback, useEffect, useState } from "react";
|
|
1
|
+
import { useLocation, usePage } from "@rspress/core/runtime";
|
|
2
|
+
import { useCallback, useEffect, useState, useSyncExternalStore } from "react";
|
|
3
3
|
import { processTitleElement } from "./processTitleElement.js";
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const distributeUpdate = ()=>{
|
|
10
|
-
for (const fn of Object.values(updateFns))fn();
|
|
11
|
-
};
|
|
12
|
-
const useSubScribe = ()=>{
|
|
13
|
-
const forceUpdate = useForceUpdate();
|
|
14
|
-
useEffect(()=>{
|
|
15
|
-
const id = Math.random().toString(36).slice(2);
|
|
16
|
-
updateFns[id] = forceUpdate;
|
|
17
|
-
return ()=>{
|
|
18
|
-
delete updateFns[id];
|
|
19
|
-
};
|
|
20
|
-
}, [
|
|
21
|
-
forceUpdate
|
|
22
|
-
]);
|
|
23
|
-
};
|
|
24
|
-
const headers = {
|
|
25
|
-
current: []
|
|
4
|
+
let tocSnapshot;
|
|
5
|
+
const listeners = new Set();
|
|
6
|
+
const subscribe = (listener)=>{
|
|
7
|
+
listeners.add(listener);
|
|
8
|
+
return ()=>listeners.delete(listener);
|
|
26
9
|
};
|
|
10
|
+
const getSnapshot = ()=>tocSnapshot;
|
|
11
|
+
const getServerSnapshot = ()=>void 0;
|
|
12
|
+
function setSnapshot(snapshot) {
|
|
13
|
+
tocSnapshot = snapshot;
|
|
14
|
+
for (const listener of listeners)listener();
|
|
15
|
+
}
|
|
27
16
|
function isElementOnlyVisible(element) {
|
|
28
17
|
const style = window.getComputedStyle(element);
|
|
29
18
|
return 'none' !== style.display && '0' !== style.opacity && 'hidden' !== style.visibility;
|
|
@@ -40,10 +29,11 @@ function isElementVisible(element) {
|
|
|
40
29
|
}
|
|
41
30
|
const useDynamicToc = ()=>{
|
|
42
31
|
const { page: { toc = [] } } = usePage();
|
|
43
|
-
|
|
44
|
-
|
|
32
|
+
const { pathname } = useLocation();
|
|
33
|
+
const snapshot = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
34
|
+
return snapshot?.pathname === pathname ? snapshot.headers : toc;
|
|
45
35
|
};
|
|
46
|
-
function updateHeaders(target) {
|
|
36
|
+
function updateHeaders(target, pathname) {
|
|
47
37
|
const collectedHeaders = [];
|
|
48
38
|
const elements = target?.querySelectorAll('.rspress-doc h2.rp-toc-include, h3.rp-toc-include, h4.rp-toc-include');
|
|
49
39
|
elements?.forEach((el)=>{
|
|
@@ -54,10 +44,10 @@ function updateHeaders(target) {
|
|
|
54
44
|
charIndex: 0
|
|
55
45
|
});
|
|
56
46
|
});
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
47
|
+
setSnapshot({
|
|
48
|
+
pathname,
|
|
49
|
+
headers: collectedHeaders
|
|
50
|
+
});
|
|
61
51
|
}
|
|
62
52
|
const TOC_HEADING_TAGS = new Set([
|
|
63
53
|
'H2',
|
|
@@ -66,10 +56,11 @@ const TOC_HEADING_TAGS = new Set([
|
|
|
66
56
|
]);
|
|
67
57
|
const useWatchToc = ()=>{
|
|
68
58
|
const [innerRef, setRef] = useState(null);
|
|
59
|
+
const { pathname } = useLocation();
|
|
69
60
|
useEffect(()=>{
|
|
70
61
|
let observer = null;
|
|
71
62
|
const target = innerRef;
|
|
72
|
-
if (target) updateHeaders(target);
|
|
63
|
+
if (target) updateHeaders(target, pathname);
|
|
73
64
|
if (target && !observer) {
|
|
74
65
|
observer = new MutationObserver((mutationList)=>{
|
|
75
66
|
let needUpdate = false;
|
|
@@ -86,7 +77,7 @@ const useWatchToc = ()=>{
|
|
|
86
77
|
break check;
|
|
87
78
|
}
|
|
88
79
|
}
|
|
89
|
-
needUpdate && updateHeaders(target);
|
|
80
|
+
needUpdate && updateHeaders(target, pathname);
|
|
90
81
|
});
|
|
91
82
|
observer.observe(target, {
|
|
92
83
|
childList: true,
|
|
@@ -96,9 +87,11 @@ const useWatchToc = ()=>{
|
|
|
96
87
|
return ()=>{
|
|
97
88
|
observer?.disconnect();
|
|
98
89
|
observer = null;
|
|
90
|
+
setSnapshot(void 0);
|
|
99
91
|
};
|
|
100
92
|
}, [
|
|
101
|
-
innerRef
|
|
93
|
+
innerRef,
|
|
94
|
+
pathname
|
|
102
95
|
]);
|
|
103
96
|
const rspressDocRef = useCallback((ref)=>{
|
|
104
97
|
setRef(ref);
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { useCallback, useLayoutEffect, useRef } from "react";
|
|
2
|
+
import { useLocation, useNavigate, useNavigation } from "react-router-dom";
|
|
3
|
+
import { normalizeHrefInRuntime, pathnameToRouteService, usePage, useWebMcp } from "@rspress/core/runtime";
|
|
4
|
+
import { usePrevNextPage } from "../logic/usePrevNextPage.js";
|
|
5
|
+
import { defineTool, resolveInternalRoute, routePathField } from "../webMcp/tools.js";
|
|
6
|
+
function useAwaitedNavigation(result) {
|
|
7
|
+
const location = useLocation();
|
|
8
|
+
const navigation = useNavigation();
|
|
9
|
+
const navigate = useNavigate();
|
|
10
|
+
const snapshot = useRef({
|
|
11
|
+
result,
|
|
12
|
+
location,
|
|
13
|
+
state: navigation.state
|
|
14
|
+
});
|
|
15
|
+
const pending = useRef(void 0);
|
|
16
|
+
const settle = useCallback(()=>{
|
|
17
|
+
const request = pending.current;
|
|
18
|
+
const current = snapshot.current;
|
|
19
|
+
if (!request?.done || 'idle' !== current.state || current.location.key === request.startKey) return;
|
|
20
|
+
pending.current = void 0;
|
|
21
|
+
request.cleanup();
|
|
22
|
+
if (current.result.routePath === request.target) request.resolve(current.result);
|
|
23
|
+
else request.reject(new Error('Navigation was superseded by another route.'));
|
|
24
|
+
}, []);
|
|
25
|
+
useLayoutEffect(()=>{
|
|
26
|
+
snapshot.current = {
|
|
27
|
+
result,
|
|
28
|
+
location,
|
|
29
|
+
state: navigation.state
|
|
30
|
+
};
|
|
31
|
+
settle();
|
|
32
|
+
});
|
|
33
|
+
useLayoutEffect(()=>()=>{
|
|
34
|
+
pending.current?.cleanup();
|
|
35
|
+
pending.current?.reject(new Error('Navigation failed or the page runtime was unmounted.'));
|
|
36
|
+
pending.current = void 0;
|
|
37
|
+
}, []);
|
|
38
|
+
return useCallback((target, signal)=>{
|
|
39
|
+
signal?.throwIfAborted();
|
|
40
|
+
pending.current?.cleanup();
|
|
41
|
+
pending.current?.reject(new Error('Navigation was superseded by another tool call.'));
|
|
42
|
+
pending.current = void 0;
|
|
43
|
+
return new Promise((resolve, reject)=>{
|
|
44
|
+
const cancel = ()=>{
|
|
45
|
+
if (pending.current === request) pending.current = void 0;
|
|
46
|
+
request.cleanup();
|
|
47
|
+
reject(signal?.reason ?? new DOMException('Navigation cancelled.', 'AbortError'));
|
|
48
|
+
};
|
|
49
|
+
const request = {
|
|
50
|
+
target,
|
|
51
|
+
startKey: snapshot.current.location.key,
|
|
52
|
+
done: false,
|
|
53
|
+
resolve,
|
|
54
|
+
reject,
|
|
55
|
+
cleanup: ()=>signal?.removeEventListener('abort', cancel)
|
|
56
|
+
};
|
|
57
|
+
pending.current = request;
|
|
58
|
+
signal?.addEventListener('abort', cancel, {
|
|
59
|
+
once: true
|
|
60
|
+
});
|
|
61
|
+
Promise.resolve().then(()=>{
|
|
62
|
+
if (pending.current === request) return navigate(normalizeHrefInRuntime(target));
|
|
63
|
+
}).then(()=>{
|
|
64
|
+
if (pending.current !== request) return;
|
|
65
|
+
request.done = true;
|
|
66
|
+
settle();
|
|
67
|
+
}).catch((error)=>{
|
|
68
|
+
if (pending.current === request) pending.current = void 0;
|
|
69
|
+
request.cleanup();
|
|
70
|
+
reject(error);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
}, [
|
|
74
|
+
navigate,
|
|
75
|
+
settle
|
|
76
|
+
]);
|
|
77
|
+
}
|
|
78
|
+
function useWebMcpNavigation() {
|
|
79
|
+
const { page } = usePage();
|
|
80
|
+
const location = useLocation();
|
|
81
|
+
const resolveRoute = (pathname)=>pathnameToRouteService(pathname)?.path;
|
|
82
|
+
const { prevPage, nextPage } = usePrevNextPage();
|
|
83
|
+
const toLink = (item)=>{
|
|
84
|
+
if (!item?.link) return null;
|
|
85
|
+
try {
|
|
86
|
+
return {
|
|
87
|
+
title: item.text,
|
|
88
|
+
routePath: resolveInternalRoute(item.link, {
|
|
89
|
+
origin: window.location.origin,
|
|
90
|
+
resolveRoute
|
|
91
|
+
})
|
|
92
|
+
};
|
|
93
|
+
} catch {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const result = {
|
|
98
|
+
routePath: `${page.routePath}${location.search}${location.hash}`,
|
|
99
|
+
page: {
|
|
100
|
+
title: page.title,
|
|
101
|
+
description: page.description,
|
|
102
|
+
lang: page.lang,
|
|
103
|
+
version: page.version
|
|
104
|
+
},
|
|
105
|
+
sections: page.toc.map((section)=>({
|
|
106
|
+
title: section.text,
|
|
107
|
+
depth: section.depth,
|
|
108
|
+
routePath: `${page.routePath}${location.search}#${section.id}`
|
|
109
|
+
})),
|
|
110
|
+
previousPage: toLink(prevPage),
|
|
111
|
+
nextPage: toLink(nextPage)
|
|
112
|
+
};
|
|
113
|
+
const navigate = useAwaitedNavigation(result);
|
|
114
|
+
useWebMcp(defineTool('navigate', 'Navigate to a known internal documentation route and return the rendered page metadata, section routes and adjacent pages. Paths are relative to the site base and may include a query or hash.', {
|
|
115
|
+
routePath: routePathField
|
|
116
|
+
}, [
|
|
117
|
+
'routePath'
|
|
118
|
+
], (args, signal)=>navigate(resolveInternalRoute(args.routePath, {
|
|
119
|
+
origin: window.location.origin,
|
|
120
|
+
resolveRoute
|
|
121
|
+
}), signal)));
|
|
122
|
+
}
|
|
123
|
+
export { useWebMcpNavigation };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { usePage, usePages, useWebMcp } from "@rspress/core/runtime";
|
|
2
|
+
import { defineTool, listPages, queryField } from "../webMcp/tools.js";
|
|
3
|
+
function useWebMcpPageList() {
|
|
4
|
+
const { page } = usePage();
|
|
5
|
+
const { pages } = usePages();
|
|
6
|
+
useWebMcp(defineTool('list_pages', "List documentation pages, optionally filtering titles, descriptions and headings. Defaults to the active language and version.", {
|
|
7
|
+
query: queryField,
|
|
8
|
+
lang: {
|
|
9
|
+
type: 'string'
|
|
10
|
+
},
|
|
11
|
+
version: {
|
|
12
|
+
type: 'string'
|
|
13
|
+
},
|
|
14
|
+
limit: {
|
|
15
|
+
type: 'integer',
|
|
16
|
+
minimum: 1,
|
|
17
|
+
maximum: 100
|
|
18
|
+
},
|
|
19
|
+
offset: {
|
|
20
|
+
type: 'integer',
|
|
21
|
+
minimum: 0
|
|
22
|
+
}
|
|
23
|
+
}, [], (args)=>listPages(pages, page, args)));
|
|
24
|
+
}
|
|
25
|
+
export { useWebMcpPageList };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Registers `rspress_get_page` and `rspress_get_current_page` to read page
|
|
3
|
+
* metadata and generated SSG-MD without navigating. The app registers these
|
|
4
|
+
* tools when Markdown generation is enabled, independently of the theme UI.
|
|
5
|
+
* @unstable
|
|
6
|
+
*/
|
|
7
|
+
export declare function useWebMcpPageReading(): void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { pathnameToRouteService, usePage, usePages, useSite, useWebMcp } from "@rspress/core/runtime";
|
|
2
|
+
import { defineTool, readPage, resolveInternalRoute, routePathField } from "../webMcp/tools.js";
|
|
3
|
+
function useWebMcpPageReading() {
|
|
4
|
+
const { page } = usePage();
|
|
5
|
+
const { site } = useSite();
|
|
6
|
+
const { pages } = usePages();
|
|
7
|
+
useWebMcp(defineTool('get_page', 'Read metadata and generated Markdown for a known documentation route without navigating. Paths are relative to the site base.', {
|
|
8
|
+
routePath: routePathField
|
|
9
|
+
}, [
|
|
10
|
+
'routePath'
|
|
11
|
+
], (args, signal)=>{
|
|
12
|
+
const target = resolveInternalRoute(args.routePath, {
|
|
13
|
+
origin: window.location.origin,
|
|
14
|
+
resolveRoute: (pathname)=>pathnameToRouteService(pathname)?.path
|
|
15
|
+
});
|
|
16
|
+
const path = pathnameToRouteService(new URL(target, window.location.origin).pathname)?.path;
|
|
17
|
+
const targetPage = pages.find((page)=>page.routePath === path);
|
|
18
|
+
if (!targetPage) throw new TypeError(`Unknown internal route: ${path}`);
|
|
19
|
+
return readPage(targetPage, site.base, signal);
|
|
20
|
+
}));
|
|
21
|
+
useWebMcp(defineTool('get_current_page', 'Read metadata, frontmatter, table of contents and generated Markdown for the current documentation page.', {}, [], (_args, signal)=>readPage(page, site.base, signal)));
|
|
22
|
+
}
|
|
23
|
+
export { useWebMcpPageReading };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useNav, usePage, useSidebar, useSite, useWebMcp } from "@rspress/core/runtime";
|
|
2
|
+
import { defineTool } from "../webMcp/tools.js";
|
|
3
|
+
function useWebMcpSiteInfo() {
|
|
4
|
+
const { site } = useSite();
|
|
5
|
+
const { page } = usePage();
|
|
6
|
+
const nav = useNav();
|
|
7
|
+
const sidebar = useSidebar();
|
|
8
|
+
useWebMcp(defineTool('get_site_info', 'Get documentation site metadata, languages, versions, navigation and the active sidebar.', {}, [], ()=>({
|
|
9
|
+
title: site.title,
|
|
10
|
+
description: site.description,
|
|
11
|
+
base: site.base,
|
|
12
|
+
siteOrigin: site.siteOrigin,
|
|
13
|
+
lang: page.lang,
|
|
14
|
+
version: page.version,
|
|
15
|
+
locales: site.locales,
|
|
16
|
+
versions: site.multiVersion.versions,
|
|
17
|
+
defaultVersion: site.multiVersion.default,
|
|
18
|
+
nav,
|
|
19
|
+
sidebar
|
|
20
|
+
})));
|
|
21
|
+
}
|
|
22
|
+
export { useWebMcpSiteInfo };
|
package/dist/theme/icons.d.ts
CHANGED
|
@@ -6,8 +6,10 @@ export declare const IconOpenInChat: Icon;
|
|
|
6
6
|
export declare const IconArrowDown: Icon;
|
|
7
7
|
export declare const IconArrowRight: Icon;
|
|
8
8
|
export declare const IconAnthropic: Icon;
|
|
9
|
+
export declare const IconBun: Icon;
|
|
9
10
|
export declare const IconClose: Icon;
|
|
10
11
|
export declare const IconCopy: Icon;
|
|
12
|
+
export declare const IconDeno: Icon;
|
|
11
13
|
export declare const IconDown: Icon;
|
|
12
14
|
export declare const IconEdit: Icon;
|
|
13
15
|
export declare const IconEmpty: Icon;
|
|
@@ -15,18 +17,23 @@ export declare const IconFile: Icon;
|
|
|
15
17
|
export declare const IconGithub: Icon;
|
|
16
18
|
export declare const IconGitlab: Icon;
|
|
17
19
|
export declare const IconHeader: Icon;
|
|
20
|
+
export declare const IconJsdelivr: Icon;
|
|
18
21
|
export declare const IconJump: Icon;
|
|
19
22
|
export declare const IconLoading: Icon;
|
|
20
23
|
export declare const IconMenu: Icon;
|
|
21
24
|
export declare const IconMoon: Icon;
|
|
25
|
+
export declare const IconNpm: Icon;
|
|
22
26
|
export declare const IconOpenAI: Icon;
|
|
27
|
+
export declare const IconPnpm: Icon;
|
|
23
28
|
export declare const IconScrollToTop: Icon;
|
|
24
29
|
export declare const IconSearch: Icon;
|
|
25
30
|
export declare const IconSmallMenu: Icon;
|
|
26
31
|
export declare const IconSuccess: Icon;
|
|
27
32
|
export declare const IconSun: Icon;
|
|
28
33
|
export declare const IconTitle: Icon;
|
|
34
|
+
export declare const IconUnpkg: Icon;
|
|
29
35
|
export declare const IconWrap: Icon;
|
|
30
36
|
export declare const IconWrapped: Icon;
|
|
37
|
+
export declare const IconYarn: Icon;
|
|
31
38
|
export declare const IconLink: Icon;
|
|
32
39
|
export {};
|
package/dist/theme/icons.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import arrow_down from "./assets/arrow-down.js";
|
|
2
2
|
import arrow_right from "./assets/arrow-right.js";
|
|
3
3
|
import anthropic from "./assets/anthropic.js";
|
|
4
|
+
import bun from "./assets/bun.js";
|
|
4
5
|
import assets_close from "./assets/close.js";
|
|
5
6
|
import copy from "./assets/copy.js";
|
|
6
7
|
import deprecated from "./assets/deprecated.js";
|
|
8
|
+
import deno from "./assets/deno.js";
|
|
7
9
|
import down from "./assets/down.js";
|
|
8
10
|
import edit from "./assets/edit.js";
|
|
9
11
|
import empty from "./assets/empty.js";
|
|
@@ -14,20 +16,25 @@ import file from "./assets/file.js";
|
|
|
14
16
|
import github from "./assets/github.js";
|
|
15
17
|
import gitlab from "./assets/gitlab.js";
|
|
16
18
|
import header from "./assets/header.js";
|
|
19
|
+
import jsdelivr from "./assets/jsdelivr.js";
|
|
17
20
|
import jump from "./assets/jump.js";
|
|
18
21
|
import assets_link from "./assets/link.js";
|
|
19
22
|
import loading from "./assets/loading.js";
|
|
20
23
|
import menu from "./assets/menu.js";
|
|
21
24
|
import moon from "./assets/moon.js";
|
|
25
|
+
import npm from "./assets/npm.js";
|
|
22
26
|
import openai from "./assets/openai.js";
|
|
27
|
+
import pnpm from "./assets/pnpm.js";
|
|
23
28
|
import scroll_to_top from "./assets/scroll-to-top.js";
|
|
24
29
|
import search from "./assets/search.js";
|
|
25
30
|
import small_menu from "./assets/small-menu.js";
|
|
26
31
|
import success from "./assets/success.js";
|
|
27
32
|
import sun from "./assets/sun.js";
|
|
28
33
|
import title from "./assets/title.js";
|
|
34
|
+
import unpkg from "./assets/unpkg.js";
|
|
29
35
|
import wrap from "./assets/wrap.js";
|
|
30
36
|
import wrapped from "./assets/wrapped.js";
|
|
37
|
+
import yarn from "./assets/yarn.js";
|
|
31
38
|
const IconDeprecated = deprecated;
|
|
32
39
|
const IconExperimental = experimental;
|
|
33
40
|
const IconExternalLink = external_link;
|
|
@@ -35,8 +42,10 @@ const IconOpenInChat = open_in_chat;
|
|
|
35
42
|
const IconArrowDown = arrow_down;
|
|
36
43
|
const IconArrowRight = arrow_right;
|
|
37
44
|
const IconAnthropic = anthropic;
|
|
45
|
+
const IconBun = bun;
|
|
38
46
|
const IconClose = assets_close;
|
|
39
47
|
const IconCopy = copy;
|
|
48
|
+
const IconDeno = deno;
|
|
40
49
|
const IconDown = down;
|
|
41
50
|
const IconEdit = edit;
|
|
42
51
|
const IconEmpty = empty;
|
|
@@ -44,18 +53,23 @@ const IconFile = file;
|
|
|
44
53
|
const IconGithub = github;
|
|
45
54
|
const IconGitlab = gitlab;
|
|
46
55
|
const IconHeader = header;
|
|
56
|
+
const IconJsdelivr = jsdelivr;
|
|
47
57
|
const IconJump = jump;
|
|
48
58
|
const IconLoading = loading;
|
|
49
59
|
const IconMenu = menu;
|
|
50
60
|
const IconMoon = moon;
|
|
61
|
+
const IconNpm = npm;
|
|
51
62
|
const IconOpenAI = openai;
|
|
63
|
+
const IconPnpm = pnpm;
|
|
52
64
|
const IconScrollToTop = scroll_to_top;
|
|
53
65
|
const IconSearch = search;
|
|
54
66
|
const IconSmallMenu = small_menu;
|
|
55
67
|
const IconSuccess = success;
|
|
56
68
|
const IconSun = sun;
|
|
57
69
|
const IconTitle = title;
|
|
70
|
+
const IconUnpkg = unpkg;
|
|
58
71
|
const IconWrap = wrap;
|
|
59
72
|
const IconWrapped = wrapped;
|
|
73
|
+
const IconYarn = yarn;
|
|
60
74
|
const IconLink = assets_link;
|
|
61
|
-
export { IconAnthropic, IconArrowDown, IconArrowRight, IconClose, IconCopy, IconDeprecated, IconDown, IconEdit, IconEmpty, IconExperimental, IconExternalLink, IconFile, IconGithub, IconGitlab, IconHeader, IconJump, IconLink, IconLoading, IconMenu, IconMoon, IconOpenAI, IconOpenInChat, IconScrollToTop, IconSearch, IconSmallMenu, IconSuccess, IconSun, IconTitle, IconWrap, IconWrapped };
|
|
75
|
+
export { IconAnthropic, IconArrowDown, IconArrowRight, IconBun, IconClose, IconCopy, IconDeno, IconDeprecated, IconDown, IconEdit, IconEmpty, IconExperimental, IconExternalLink, IconFile, IconGithub, IconGitlab, IconHeader, IconJsdelivr, IconJump, IconLink, IconLoading, IconMenu, IconMoon, IconNpm, IconOpenAI, IconOpenInChat, IconPnpm, IconScrollToTop, IconSearch, IconSmallMenu, IconSuccess, IconSun, IconTitle, IconUnpkg, IconWrap, IconWrapped, IconYarn };
|