@rspress/core 2.0.22 → 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/bin/rspress.js +3 -1
- package/dist/{v~0.js → b~0.js} +19 -16
- 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/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/SearchPanel.tsx +9 -5
- package/dist/eject-theme/components/Search/logic/providers/LocalProvider.ts +5 -2
- package/dist/eject-theme/components/Search/useSearchPanel.ts +105 -37
- package/dist/eject-theme/components/SocialLinks/GithubStars.test.tsx +4 -1
- package/dist/eject-theme/components/SocialLinks/GithubStars.tsx +1 -1
- package/dist/eject-theme/components/SocialLinks/SocialLink.tsx +2 -2
- package/dist/eject-theme/components/SourceCode/index.tsx +1 -1
- package/dist/entry/worker.js +1 -1
- package/dist/{o~0.js → h~0.js} +18 -29
- 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/constants.js +1 -1
- package/dist/node/eject.js +1 -1
- package/dist/node/initRsbuild.js +9 -5
- 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/htmlFile.js +1 -1
- package/dist/node/ssg/renderHtmlTemplate.js +4 -3
- 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 +5 -2
- package/dist/n~0.js +11 -10
- package/dist/runtime/App.js +15 -27
- 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/createExternalStore.d.ts +4 -0
- package/dist/runtime/hooks/createExternalStore.js +20 -0
- package/dist/runtime/hooks/useGlobalComponents.d.ts +1 -0
- package/dist/runtime/hooks/useGlobalComponents.js +10 -0
- package/dist/runtime/hooks/useI18n.js +5 -3
- package/dist/runtime/hooks/useI18nText.d.ts +1 -0
- package/dist/runtime/hooks/useI18nText.js +10 -0
- package/dist/runtime/hooks/usePages.d.ts +2 -0
- package/dist/runtime/hooks/usePages.js +12 -3
- package/dist/runtime/hooks/useSearchHooks.d.ts +8 -0
- package/dist/runtime/hooks/useSearchHooks.js +14 -0
- package/dist/runtime/hooks/useSite.d.ts +1 -0
- package/dist/runtime/hooks/useSite.js +9 -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 -2
- package/dist/runtime/index.js +8 -2
- package/dist/runtime/initPageData.d.ts +0 -3
- package/dist/runtime/initPageData.js +13 -49
- package/dist/runtime/pageDataLoader.d.ts +11 -0
- package/dist/runtime/pageDataLoader.js +7 -0
- package/dist/runtime/route.js +5 -5
- package/dist/runtime/ssrClientEntry.js +14 -6
- package/dist/runtime/ssrMdServerEntry.js +10 -21
- package/dist/runtime/ssrServerEntry.js +10 -21
- package/dist/runtime/utils.js +6 -6
- 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/SearchPanel.js +8 -6
- package/dist/theme/components/Search/logic/providers/LocalProvider.js +5 -2
- package/dist/theme/components/Search/useSearchPanel.js +75 -27
- package/dist/theme/components/SocialLinks/GithubStars.js +1 -1
- package/dist/theme/components/SocialLinks/SocialLink.js +2 -2
- package/dist/theme/components/SourceCode/index.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/logic/utils.d.ts +0 -2
- package/dist/theme/logic/utils.js +56 -6
- 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 +17 -17
|
@@ -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
|
]);
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Head, useI18n } from "@rspress/core/runtime";
|
|
2
|
+
import { Head, useI18n, useSearchHooks } from "@rspress/core/runtime";
|
|
3
3
|
import { IconClose, IconSearch, SvgWrapper, Tab, Tabs, useLinkNavigate } from "@rspress/core/theme";
|
|
4
4
|
import { useEffect, useRef, useState } from "react";
|
|
5
5
|
import { createPortal } from "react-dom";
|
|
6
|
-
import * as __rspack_external_virtual_search_hooks_705b6e40 from "virtual-search-hooks";
|
|
7
6
|
import { RenderType } from "./logic/types.js";
|
|
8
7
|
import { NoSearchResult } from "./NoSearchResult.js";
|
|
9
8
|
import "./SearchPanel.css";
|
|
@@ -46,6 +45,7 @@ function SearchPanel({ focused, setFocused }) {
|
|
|
46
45
|
}
|
|
47
46
|
};
|
|
48
47
|
const t = useI18n();
|
|
48
|
+
const userSearchHooks = useSearchHooks();
|
|
49
49
|
const navigate = useLinkNavigate();
|
|
50
50
|
const { currentRenderType, currentSuggestions, currentSuggestionIndex, clearQuery, handleQueryInput, initStatus, isSearching, query, resultTabIndex, searchError, searchIndexURL, searchResult, searchEnabled, setCurrentSuggestionIndex, setResultTabIndex } = useSearchPanel({
|
|
51
51
|
focused,
|
|
@@ -89,11 +89,13 @@ function SearchPanel({ focused, setFocused }) {
|
|
|
89
89
|
break;
|
|
90
90
|
case KEY_CODE.ENTER:
|
|
91
91
|
if (e.isComposing) return;
|
|
92
|
-
if (currentSuggestionIndex >= 0 && currentRenderType === RenderType.Default) {
|
|
92
|
+
if (focused && currentSuggestionIndex >= 0 && currentRenderType === RenderType.Default) {
|
|
93
93
|
const flatSuggestions = Array.from(normalizeSuggestions(currentSuggestions).values()).flat();
|
|
94
94
|
const suggestion = flatSuggestions[currentSuggestionIndex];
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
if (suggestion) {
|
|
96
|
+
navigate(suggestion.link);
|
|
97
|
+
clearSearchState();
|
|
98
|
+
}
|
|
97
99
|
}
|
|
98
100
|
break;
|
|
99
101
|
case KEY_CODE.ESC:
|
|
@@ -136,7 +138,7 @@ function SearchPanel({ focused, setFocused }) {
|
|
|
136
138
|
label: item.group,
|
|
137
139
|
children: [
|
|
138
140
|
item.renderType === RenderType.Default && renderSearchResultItem(item.result),
|
|
139
|
-
item.renderType === RenderType.Custom &&
|
|
141
|
+
item.renderType === RenderType.Custom && userSearchHooks[renderKey]?.(item.result)
|
|
140
142
|
]
|
|
141
143
|
}, item.group))
|
|
142
144
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SEARCH_INDEX_NAME, removeTrailingSlash } from "@rspress/shared";
|
|
2
2
|
import { Document } from "flexsearch";
|
|
3
|
-
import { searchIndexHash } from "
|
|
3
|
+
import { searchIndexHash } from "@rspress/core/runtime";
|
|
4
4
|
import { LOCAL_INDEX } from "../Provider.js";
|
|
5
5
|
import { normalizeTextCase } from "../util.js";
|
|
6
6
|
function getSearchIndexURL(lang, version) {
|
|
@@ -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) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { usePageData } 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
|
|
7
|
+
import { defineTool, queryField, toWebMcpSearchResults } from "../../webMcp/tools.js";
|
|
8
8
|
const useDebounce = (cb)=>{
|
|
9
9
|
const cbRef = useRef(cb);
|
|
10
10
|
cbRef.current = cb;
|
|
@@ -12,6 +12,7 @@ const useDebounce = (cb)=>{
|
|
|
12
12
|
};
|
|
13
13
|
function useSearchPanel({ focused, searchInputRef }) {
|
|
14
14
|
const { siteData, page: { lang, version } } = usePageData();
|
|
15
|
+
const userSearchHooks = useSearchHooks();
|
|
15
16
|
const { search, title: siteTitle } = siteData;
|
|
16
17
|
const [query, setQuery] = useState('');
|
|
17
18
|
const [searchResult, setSearchResult] = useState([]);
|
|
@@ -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);
|
|
@@ -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,5 +1,5 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
2
|
+
import { socialLinks } from "@rspress/core/runtime";
|
|
3
3
|
import "./index.css";
|
|
4
4
|
import { GithubStars } from "./GithubStars.js";
|
|
5
5
|
import { useHoverGroup } from "../HoverGroup/useHoverGroup.js";
|
|
@@ -8,7 +8,7 @@ const SocialLink = (props)=>{
|
|
|
8
8
|
const { icon, mode = 'link', content } = link;
|
|
9
9
|
let IconComp = /*#__PURE__*/ jsx(Fragment, {});
|
|
10
10
|
if (icon) {
|
|
11
|
-
const html = 'string' == typeof icon ?
|
|
11
|
+
const html = 'string' == typeof icon ? socialLinks[icon] : icon.svg;
|
|
12
12
|
IconComp = /*#__PURE__*/ jsx("div", {
|
|
13
13
|
className: "rp-social-links__icon",
|
|
14
14
|
dangerouslySetInnerHTML: {
|
|
@@ -6,7 +6,7 @@ function SourceCode(props) {
|
|
|
6
6
|
const { href, platform = 'github' } = props;
|
|
7
7
|
const t = useI18n();
|
|
8
8
|
return /*#__PURE__*/ jsx("div", {
|
|
9
|
-
className: "rp-not-doc rp-source-code",
|
|
9
|
+
className: "rp-not-doc rp-source-code rp-toc-exclude",
|
|
10
10
|
children: /*#__PURE__*/ jsxs("a", {
|
|
11
11
|
href: href,
|
|
12
12
|
target: "_blank",
|
|
@@ -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/index.d.ts
CHANGED
|
@@ -54,11 +54,16 @@ export { Tag } from './components/Tag/index.js';
|
|
|
54
54
|
export { Toc } from './components/Toc/index.js';
|
|
55
55
|
export { useActiveAnchor } from './hooks/useActiveAnchor.js';
|
|
56
56
|
export { useDynamicToc, useWatchToc } from './hooks/useDynamicToc.js';
|
|
57
|
+
export { useWebMcpNavigation } from './hooks/useWebMcpNavigation.js';
|
|
58
|
+
export { useWebMcpPageList } from './hooks/useWebMcpPageList.js';
|
|
59
|
+
export { useWebMcpPageReading } from './hooks/useWebMcpPageReading.js';
|
|
60
|
+
export { useWebMcpSiteInfo } from './hooks/useWebMcpSiteInfo.js';
|
|
57
61
|
export * from './icons.js';
|
|
58
62
|
export { DocLayout, type DocLayoutProps } from './layout/DocLayout/index.js';
|
|
59
63
|
export { HomeLayout, type HomeLayoutProps } from './layout/HomeLayout/index.js';
|
|
60
64
|
export { Layout, type LayoutProps } from './layout/Layout/index.js';
|
|
61
65
|
export { NotFoundLayout } from './layout/NotFountLayout/index.js';
|
|
66
|
+
export { ErrorLayout, type ErrorLayoutProps } from './layout/ErrorLayout/index.js';
|
|
62
67
|
export { copyToClipboard } from './logic/copyToClipboard.js';
|
|
63
68
|
export { getCopyableText } from './logic/getCopyableText.js';
|
|
64
69
|
export { mergeRefs } from './logic/mergeRefs.js';
|
package/dist/theme/index.js
CHANGED
|
@@ -53,10 +53,15 @@ export { Tag } from "./components/Tag/index.js";
|
|
|
53
53
|
export { Toc } from "./components/Toc/index.js";
|
|
54
54
|
export { useActiveAnchor } from "./hooks/useActiveAnchor.js";
|
|
55
55
|
export { useDynamicToc, useWatchToc } from "./hooks/useDynamicToc.js";
|
|
56
|
+
export { useWebMcpNavigation } from "./hooks/useWebMcpNavigation.js";
|
|
57
|
+
export { useWebMcpPageList } from "./hooks/useWebMcpPageList.js";
|
|
58
|
+
export { useWebMcpPageReading } from "./hooks/useWebMcpPageReading.js";
|
|
59
|
+
export { useWebMcpSiteInfo } from "./hooks/useWebMcpSiteInfo.js";
|
|
56
60
|
export { DocLayout } from "./layout/DocLayout/index.js";
|
|
57
61
|
export { HomeLayout } from "./layout/HomeLayout/index.js";
|
|
58
62
|
export { Layout } from "./layout/Layout/index.js";
|
|
59
63
|
export { NotFoundLayout } from "./layout/NotFountLayout/index.js";
|
|
64
|
+
export { ErrorLayout } from "./layout/ErrorLayout/index.js";
|
|
60
65
|
export { copyToClipboard } from "./logic/copyToClipboard.js";
|
|
61
66
|
export { getCopyableText } from "./logic/getCopyableText.js";
|
|
62
67
|
export { mergeRefs } from "./logic/mergeRefs.js";
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
.rp-error {
|
|
2
|
+
min-height: 100dvh;
|
|
3
|
+
padding-top: 20vh;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.rp-error__description {
|
|
7
|
+
max-width: 28rem;
|
|
8
|
+
color: var(--rp-c-text-2);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.rp-error__actions {
|
|
12
|
+
flex-wrap: wrap;
|
|
13
|
+
justify-content: center;
|
|
14
|
+
gap: .75rem;
|
|
15
|
+
display: flex;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.rp-error__actions button {
|
|
19
|
+
font: inherit;
|
|
20
|
+
cursor: pointer;
|
|
21
|
+
background: none;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.rp-error__actions :focus-visible {
|
|
25
|
+
outline: 2px solid var(--rp-c-brand);
|
|
26
|
+
outline-offset: 4px;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.rp-error__details {
|
|
30
|
+
border: 1px solid var(--rp-c-divider);
|
|
31
|
+
background: var(--rp-c-bg-soft);
|
|
32
|
+
text-align: left;
|
|
33
|
+
border-radius: .75rem;
|
|
34
|
+
width: 100%;
|
|
35
|
+
max-width: 56rem;
|
|
36
|
+
margin-top: 2.5rem;
|
|
37
|
+
padding: 1rem 1.25rem;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.rp-error__details summary {
|
|
41
|
+
cursor: pointer;
|
|
42
|
+
font-weight: 500;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.rp-error__details pre {
|
|
46
|
+
max-height: 20rem;
|
|
47
|
+
margin-top: 1rem;
|
|
48
|
+
font-size: .8125rem;
|
|
49
|
+
line-height: 1.7;
|
|
50
|
+
overflow: auto;
|
|
51
|
+
}
|
|
52
|
+
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import '../NotFountLayout/index.scss';
|
|
2
|
+
import './index.scss';
|
|
3
|
+
export interface ErrorLayoutProps {
|
|
4
|
+
error: unknown;
|
|
5
|
+
lang: string;
|
|
6
|
+
homeHref: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function ErrorLayout({ error, lang, homeHref }: ErrorLayoutProps): import("react").JSX.Element;
|