@rspress/core 2.1.1 → 2.1.3

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 (27) hide show
  1. package/dist/eject-theme/components/Llms/LlmsOpenRow.tsx +14 -3
  2. package/dist/eject-theme/components/Llms/LlmsViewOptions.tsx +18 -2
  3. package/dist/eject-theme/components/PageTabs/index.tsx +8 -18
  4. package/dist/eject-theme/components/Prompt/index.test.tsx +91 -0
  5. package/dist/eject-theme/components/Prompt/index.tsx +31 -0
  6. package/dist/eject-theme/components/Search/useSearchPanel.ts +85 -81
  7. package/dist/eject-theme/components/Sidebar/SidebarItem.scss +10 -7
  8. package/dist/eject-theme/components/Sidebar/SidebarItem.tsx +2 -2
  9. package/dist/eject-theme/components/Tabs/index.test.tsx +31 -8
  10. package/dist/node/runtimeModule/i18n/DEFAULT_I18N_TEXT.d.ts +463 -0
  11. package/dist/node/runtimeModule/i18n/DEFAULT_I18N_TEXT.js +497 -34
  12. package/dist/theme/assets/markdown.js +22 -0
  13. package/dist/theme/components/Llms/LlmsOpenRow.js +11 -2
  14. package/dist/theme/components/Llms/LlmsViewOptions.d.ts +4 -2
  15. package/dist/theme/components/Llms/LlmsViewOptions.js +14 -2
  16. package/dist/theme/components/PageTabs/index.js +10 -14
  17. package/dist/theme/components/Prompt/index.js +29 -1
  18. package/dist/theme/components/Search/useSearchPanel.js +66 -65
  19. package/dist/theme/components/Sidebar/SidebarItem.css +9 -11
  20. package/dist/theme/components/Sidebar/SidebarItem.js +2 -2
  21. package/dist/theme/hooks/useDynamicToc.js +21 -9
  22. package/dist/theme/icons.d.ts +5 -0
  23. package/dist/theme/icons.js +3 -1
  24. package/dist/theme/logic/useStorageValue.d.ts +2 -1
  25. package/dist/theme/logic/useStorageValue.js +51 -34
  26. package/dist/y~0.js +1 -1
  27. package/package.json +5 -5
@@ -1,50 +1,67 @@
1
- import { useCallback, useEffect, useState } from "react";
1
+ import { useCallback, useSyncExternalStore } from "react";
2
2
  const SYNC_STORAGE_EVENT_NAME = 'RSPRESS_SYNC_STORAGE_EVENT_NAME';
3
+ const getStorageItem = (key)=>{
4
+ if ("u" < typeof window) return null;
5
+ try {
6
+ return window.localStorage.getItem(key);
7
+ } catch {
8
+ return null;
9
+ }
10
+ };
11
+ const setStorageItem = (key, value)=>{
12
+ if ("u" < typeof window) return;
13
+ try {
14
+ if (null == value) window.localStorage.removeItem(key);
15
+ else window.localStorage.setItem(key, value);
16
+ } catch (error) {
17
+ console.warn(`[useStorageValue] Failed to set localStorage key "${key}":`, error);
18
+ }
19
+ };
3
20
  const useStorageValue = (key, defaultValue)=>{
4
- const [value, setValueInternal] = useState(defaultValue);
5
- useEffect(()=>{
6
- if ("u" < typeof window) return;
7
- const storedValue = localStorage.getItem(key);
8
- if (null != storedValue) setValueInternal(storedValue);
21
+ const subscribe = useCallback((onStoreChange)=>{
22
+ if ("u" < typeof window) return ()=>{};
23
+ const handleStorage = (event)=>{
24
+ if (event.key === key || null === event.key) onStoreChange();
25
+ };
26
+ const handleCustomEvent = (event)=>{
27
+ const customEvent = event;
28
+ if (customEvent.detail?.key === key) onStoreChange();
29
+ };
30
+ window.addEventListener('storage', handleStorage);
31
+ window.addEventListener(SYNC_STORAGE_EVENT_NAME, handleCustomEvent);
32
+ return ()=>{
33
+ window.removeEventListener('storage', handleStorage);
34
+ window.removeEventListener(SYNC_STORAGE_EVENT_NAME, handleCustomEvent);
35
+ };
9
36
  }, [
10
37
  key
11
38
  ]);
12
- const setValue = useCallback((value)=>{
13
- const next = value;
14
- if (null == next) localStorage.removeItem(key);
15
- else localStorage.setItem(key, next.toString());
16
- setValueInternal(next);
17
- dispatchEvent(new CustomEvent(SYNC_STORAGE_EVENT_NAME, {
39
+ const getSnapshot = useCallback(()=>{
40
+ const raw = getStorageItem(key);
41
+ return null !== raw ? raw : defaultValue;
42
+ }, [
43
+ key,
44
+ defaultValue
45
+ ]);
46
+ const getServerSnapshot = useCallback(()=>defaultValue, [
47
+ defaultValue
48
+ ]);
49
+ const value = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
50
+ const setValue = useCallback((action)=>{
51
+ const currentStored = getStorageItem(key);
52
+ const currentValue = null !== currentStored ? currentStored : defaultValue;
53
+ const nextValue = 'function' == typeof action ? action(currentValue) : action;
54
+ null == nextValue ? setStorageItem(key, null) : setStorageItem(key, String(nextValue));
55
+ if ("u" > typeof window) window.dispatchEvent(new CustomEvent(SYNC_STORAGE_EVENT_NAME, {
18
56
  detail: {
19
57
  key,
20
- newValue: next
58
+ newValue: nextValue
21
59
  }
22
60
  }));
23
- }, [
24
- key
25
- ]);
26
- useEffect(()=>{
27
- const listener = (e)=>{
28
- if (e.key === key) setValueInternal(localStorage.getItem(key) ?? defaultValue);
29
- };
30
- window.addEventListener('storage', listener);
31
- return ()=>{
32
- window.removeEventListener('storage', listener);
33
- };
34
61
  }, [
35
62
  key,
36
63
  defaultValue
37
64
  ]);
38
- useEffect(()=>{
39
- const listener = (e)=>{
40
- const { key: eventKey, newValue } = e.detail;
41
- if (eventKey === key) setValueInternal(newValue ?? defaultValue);
42
- };
43
- window.addEventListener(SYNC_STORAGE_EVENT_NAME, listener);
44
- return ()=>{
45
- window.removeEventListener(SYNC_STORAGE_EVENT_NAME, listener);
46
- };
47
- }, []);
48
65
  return [
49
66
  value,
50
67
  setValue
package/dist/y~0.js CHANGED
@@ -1,5 +1,5 @@
1
1
  var package_namespaceObject = {
2
- rE: "2.1.1"
2
+ rE: "2.1.3"
3
3
  };
4
4
  function pMap(iterable, mapper, options) {
5
5
  return mapConcurrently(iterable, mapper, options, false);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspress/core",
3
- "version": "2.1.1",
3
+ "version": "2.1.3",
4
4
  "description": "The Rspress Documentation Framework",
5
5
  "bugs": "https://github.com/web-infra-dev/rspress/issues",
6
6
  "repository": {
@@ -62,7 +62,7 @@
62
62
  "@mdx-js/react": "^3.1.1",
63
63
  "@rsbuild/core": "^2.2.14",
64
64
  "@rsbuild/plugin-react": "~2.1.1",
65
- "@rspress/shared": "2.1.1",
65
+ "@rspress/shared": "2.1.3",
66
66
  "@shikijs/rehype": "^4.2.0",
67
67
  "@shikijs/transformers": "^4.2.0",
68
68
  "@types/mdast": "^4.0.4",
@@ -85,8 +85,8 @@
85
85
  "react-router-dom": "^7.18.5",
86
86
  "rehype-external-links": "^3.0.0",
87
87
  "rehype-raw": "^7.0.0",
88
- "remark-cjk-friendly": "^2.3.3",
89
- "remark-cjk-friendly-gfm-strikethrough": "^2.3.2",
88
+ "remark-cjk-friendly": "^2.3.4",
89
+ "remark-cjk-friendly-gfm-strikethrough": "^2.3.3",
90
90
  "remark-gfm": "^4.0.1",
91
91
  "remark-mdx": "^3.1.1",
92
92
  "remark-parse": "^11.0.0",
@@ -108,7 +108,7 @@
108
108
  "@types/node": "^22.8.1",
109
109
  "@types/nprogress": "^0.2.3",
110
110
  "@types/react-dom": "^19.3.0",
111
- "@types/web": "^0.0.359",
111
+ "@types/web": "^0.0.362",
112
112
  "cac": "^7.1.0",
113
113
  "execa": "8.0.1",
114
114
  "mdast-util-directive": "^3.1.1",