@rspress-theme-anatole/theme-default 0.7.52 → 0.7.54

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 +90 -53
  2. package/package.json +3 -3
package/dist/bundle.js CHANGED
@@ -395,8 +395,8 @@ function isItemLocked(item, userContext) {
395
395
  const requiredRoles = normalizeRoleList(item?.roles);
396
396
  // No roles required = public content (not locked)
397
397
  if (!requiredRoles.length) return false;
398
- // User is authenticated with valid userId = unlocked (regardless of roles)
399
- if (userContext?.isAuthenticated && userContext?.userId) return false;
398
+ // User is authenticated = unlocked (regardless of roles)
399
+ if (userContext?.isAuthenticated) return false;
400
400
  // Has roles required but user is not authenticated = locked
401
401
  return true;
402
402
  }
@@ -7044,56 +7044,93 @@ function SearchPanel({ focused, setFocused }) {
7044
7044
  const handleQueryChangedImpl = async (value) => {
7045
7045
  let newQuery = value;
7046
7046
  setQuery(newQuery);
7047
- if (search && 'remote' === search.mode && search.searchLoading) setIsSearching(true);
7048
- if (newQuery) setIsSearching(true);
7049
- if (newQuery) {
7050
- try {
7051
- await ensureSearcherReady();
7052
- } catch (_error) {
7053
- setIsSearching(false);
7054
- return;
7055
- }
7056
- const searchResult = [];
7057
- if ('beforeSearch' in __WEBPACK_EXTERNAL_MODULE_virtual_search_hooks_9d01d01f__) {
7058
- const key = 'beforeSearch';
7059
- const transformedQuery = await __WEBPACK_EXTERNAL_MODULE_virtual_search_hooks_9d01d01f__[key](newQuery);
7060
- if (transformedQuery) newQuery = transformedQuery;
7061
- }
7062
- let defaultSearchResult = await pageSearcherRef.current?.match(newQuery, getScopedSearchLimit(searchScope));
7063
- let filteredDefaultSearchResult = filterResultsByScope(
7064
- defaultSearchResult || DEFAULT_RESULT,
7065
- searchScope,
7066
- base,
7067
- lang
7068
- );
7069
- if (searchScope?.scopeType && !hasSearchResults(filteredDefaultSearchResult)) {
7070
- defaultSearchResult = await pageSearcherRef.current?.match(newQuery, getScopedSearchLimit(searchScope, true));
7071
- }
7072
- if (defaultSearchResult) searchResult.push(...defaultSearchResult);
7073
- if ('onSearch' in __WEBPACK_EXTERNAL_MODULE_virtual_search_hooks_9d01d01f__) {
7074
- const key = 'onSearch';
7075
- const customSearchResult = await __WEBPACK_EXTERNAL_MODULE_virtual_search_hooks_9d01d01f__[key](newQuery, searchResult, searchScope);
7076
- if (customSearchResult) searchResult.push(...customSearchResult.map((item) => ({
7077
- renderType: types_RenderType.Custom,
7078
- ...item
7079
- })));
7080
- }
7081
- if ('afterSearch' in __WEBPACK_EXTERNAL_MODULE_virtual_search_hooks_9d01d01f__) {
7082
- const key = 'afterSearch';
7083
- await __WEBPACK_EXTERNAL_MODULE_virtual_search_hooks_9d01d01f__[key](newQuery, searchResult);
7084
- }
7085
- const currQuery = searchInputRef.current?.value;
7086
- if (currQuery === newQuery) {
7087
- const filteredResult = filterResultsByScope(
7088
- searchResult || DEFAULT_RESULT,
7089
- searchScope,
7090
- base,
7091
- lang
7092
- );
7093
- setSearchResult(filteredResult);
7094
- setIsSearching(false);
7095
- }
7047
+
7048
+ if (!newQuery) {
7049
+ setIsSearching(false);
7050
+ return;
7096
7051
  }
7052
+
7053
+ setIsSearching(true);
7054
+
7055
+ // Kick off local searcher init in background (non-blocking)
7056
+ const searcherPromise = ensureSearcherReady().catch(() => null);
7057
+
7058
+ // === TYPESENSE FIRST (not wait local searcher) ===
7059
+ const typesenseResult = [...DEFAULT_RESULT];
7060
+
7061
+ if ('beforeSearch' in __WEBPACK_EXTERNAL_MODULE_virtual_search_hooks_9d01d01f__) {
7062
+ const key = 'beforeSearch';
7063
+ const transformedQuery = await __WEBPACK_EXTERNAL_MODULE_virtual_search_hooks_9d01d01f__[key](newQuery);
7064
+ if (transformedQuery) newQuery = transformedQuery;
7065
+ }
7066
+
7067
+ if ('onSearch' in __WEBPACK_EXTERNAL_MODULE_virtual_search_hooks_9d01d01f__) {
7068
+ const key = 'onSearch';
7069
+ await __WEBPACK_EXTERNAL_MODULE_virtual_search_hooks_9d01d01f__[key](newQuery, typesenseResult, searchScope);
7070
+ }
7071
+
7072
+ if ('afterSearch' in __WEBPACK_EXTERNAL_MODULE_virtual_search_hooks_9d01d01f__) {
7073
+ const key = 'afterSearch';
7074
+ await __WEBPACK_EXTERNAL_MODULE_virtual_search_hooks_9d01d01f__[key](newQuery, typesenseResult);
7075
+ }
7076
+
7077
+ // If the query has changed while waiting → skip
7078
+ if (searchInputRef.current?.value !== value) return;
7079
+
7080
+ const typesenseHasResults = hasSearchResults(typesenseResult);
7081
+
7082
+ if (typesenseHasResults) {
7083
+ // Typesense has results → display immediately, do not wait for local
7084
+ const filtered = filterResultsByScope(typesenseResult, searchScope, base, lang);
7085
+ setSearchResult(filtered);
7086
+ setIsSearching(false);
7087
+ // Local searcher still warms up in the background for the next time
7088
+ return;
7089
+ }
7090
+
7091
+ // === FALLBACK: wait for local FlexSearch searcher ===
7092
+ const searcher = await searcherPromise;
7093
+
7094
+ if (searchInputRef.current?.value !== value) return;
7095
+
7096
+ if (!searcher) {
7097
+ // Local searcher also failed → show empty
7098
+ setSearchResult(DEFAULT_RESULT);
7099
+ setIsSearching(false);
7100
+ return;
7101
+ }
7102
+
7103
+ const localResult = [];
7104
+ let defaultSearchResult = await searcher.match(newQuery, getScopedSearchLimit(searchScope));
7105
+ let filteredDefaultSearchResult = filterResultsByScope(
7106
+ defaultSearchResult || DEFAULT_RESULT,
7107
+ searchScope,
7108
+ base,
7109
+ lang
7110
+ );
7111
+
7112
+ if (searchScope?.scopeType && !hasSearchResults(filteredDefaultSearchResult)) {
7113
+ defaultSearchResult = await searcher.match(newQuery, getScopedSearchLimit(searchScope, true));
7114
+ }
7115
+
7116
+ if (defaultSearchResult) localResult.push(...defaultSearchResult);
7117
+
7118
+ // Re-run onSearch/afterSearch với local result
7119
+ if ('onSearch' in __WEBPACK_EXTERNAL_MODULE_virtual_search_hooks_9d01d01f__) {
7120
+ const key = 'onSearch';
7121
+ await __WEBPACK_EXTERNAL_MODULE_virtual_search_hooks_9d01d01f__[key](newQuery, localResult, searchScope);
7122
+ }
7123
+
7124
+ if ('afterSearch' in __WEBPACK_EXTERNAL_MODULE_virtual_search_hooks_9d01d01f__) {
7125
+ const key = 'afterSearch';
7126
+ await __WEBPACK_EXTERNAL_MODULE_virtual_search_hooks_9d01d01f__[key](newQuery, localResult);
7127
+ }
7128
+
7129
+ if (searchInputRef.current?.value !== value) return;
7130
+
7131
+ const filtered = filterResultsByScope(localResult || DEFAULT_RESULT, searchScope, base, lang);
7132
+ setSearchResult(filtered);
7133
+ setIsSearching(false);
7097
7134
  };
7098
7135
  const handleQueryChange = useDebounce(handleQueryChangedImpl);
7099
7136
  const normalizeSuggestions = (suggestions) => suggestions.reduce((groups, item) => {
@@ -7237,8 +7274,8 @@ function SearchPanel({ focused, setFocused }) {
7237
7274
  "aria-label": "SearchPanelInput",
7238
7275
  autoComplete: "off",
7239
7276
  autoFocus: true,
7240
- // onChange: (e) => handleQueryChange(e.target.value)
7241
- onKeyUp: (e) => handleQueryChange(e.target.value)
7277
+ onChange: (e) => handleQueryChange(e.target.value)
7278
+ // onKeyUp: (e) => handleQueryChange(e.target.value)
7242
7279
  }),
7243
7280
  (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("label", {
7244
7281
  children: (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(SvgWrapper, {
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.52",
4
+ "version": "0.7.54",
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.52",
25
- "@rspress-theme-anatole/shared": "0.7.52",
24
+ "@rspress-theme-anatole/rspress-plugin-mermaid": "0.7.54",
25
+ "@rspress-theme-anatole/shared": "0.7.54",
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",