@rspress-theme-anatole/theme-default 0.7.34 → 0.7.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/bundle.js +18 -1
  2. package/package.json +3 -3
package/dist/bundle.js CHANGED
@@ -6738,6 +6738,9 @@ function SearchPanel({ focused, setFocused }) {
6738
6738
  version,
6739
6739
  versionedSearch
6740
6740
  ]);
6741
+ const DEFAULT_SEARCH_LIMIT = 7;
6742
+ const SCOPED_SEARCH_LIMIT = 50;
6743
+ const SCOPED_SEARCH_RETRY_LIMIT = 100;
6741
6744
  const filterResultsByScope = (results, scope, basePath, currentLang) => {
6742
6745
  if (!scope || !scope.scopeType) {
6743
6746
  return results;
@@ -6801,6 +6804,11 @@ function SearchPanel({ focused, setFocused }) {
6801
6804
  };
6802
6805
  });
6803
6806
  };
6807
+ const hasSearchResults = (results) => results.some((resultGroup) => (resultGroup?.result?.length ?? 0) > 0);
6808
+ const getScopedSearchLimit = (scope, retry = false) => {
6809
+ if (!scope?.scopeType) return DEFAULT_SEARCH_LIMIT;
6810
+ return retry ? SCOPED_SEARCH_RETRY_LIMIT : SCOPED_SEARCH_LIMIT;
6811
+ };
6804
6812
  const handleQueryChangedImpl = async (value) => {
6805
6813
  let newQuery = value;
6806
6814
  setQuery(newQuery);
@@ -6818,7 +6826,16 @@ function SearchPanel({ focused, setFocused }) {
6818
6826
  const transformedQuery = await __WEBPACK_EXTERNAL_MODULE_virtual_search_hooks_9d01d01f__[key](newQuery);
6819
6827
  if (transformedQuery) newQuery = transformedQuery;
6820
6828
  }
6821
- const defaultSearchResult = await pageSearcherRef.current?.match(newQuery);
6829
+ let defaultSearchResult = await pageSearcherRef.current?.match(newQuery, getScopedSearchLimit(searchScope));
6830
+ let filteredDefaultSearchResult = filterResultsByScope(
6831
+ defaultSearchResult || DEFAULT_RESULT,
6832
+ searchScope,
6833
+ base,
6834
+ lang
6835
+ );
6836
+ if (searchScope?.scopeType && !hasSearchResults(filteredDefaultSearchResult)) {
6837
+ defaultSearchResult = await pageSearcherRef.current?.match(newQuery, getScopedSearchLimit(searchScope, true));
6838
+ }
6822
6839
  if (defaultSearchResult) searchResult.push(...defaultSearchResult);
6823
6840
  if ('onSearch' in __WEBPACK_EXTERNAL_MODULE_virtual_search_hooks_9d01d01f__) {
6824
6841
  const key = 'onSearch';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rspress-theme-anatole/theme-default",
3
3
  "author": "Anatole Tong",
4
- "version": "0.7.34",
4
+ "version": "0.7.35",
5
5
  "license": "MIT",
6
6
  "sideEffects": [
7
7
  "*.css",
@@ -21,8 +21,8 @@
21
21
  "types": "./dist/bundle.d.ts",
22
22
  "dependencies": {
23
23
  "@mdx-js/react": "2.3.0",
24
- "@rspress-theme-anatole/rspress-plugin-mermaid": "0.7.34",
25
- "@rspress-theme-anatole/shared": "0.7.34",
24
+ "@rspress-theme-anatole/rspress-plugin-mermaid": "0.7.35",
25
+ "@rspress-theme-anatole/shared": "0.7.35",
26
26
  "@rspress/runtime": "1.43.8",
27
27
  "body-scroll-lock": "4.0.0-beta.0",
28
28
  "copy-to-clipboard": "^3.3.3",