@rspress-theme-anatole/theme-default 0.7.22-alpha2 → 0.7.22-alpha3

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 +43 -2
  2. package/package.json +68 -68
package/dist/bundle.js CHANGED
@@ -375,13 +375,54 @@ function useSidebarData() {
375
375
  const { sidebar } = useLocaleSiteData();
376
376
  const { pathname: rawPathname } = (0, __WEBPACK_EXTERNAL_MODULE__rspress_runtime_0abd3046__.useLocation)();
377
377
  const pathname = decodeURIComponent(rawPathname);
378
+ const [roleVersion, setRoleVersion] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(0);
379
+ (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(() => {
380
+ if ('undefined' == typeof window) return;
381
+ const handler = () => setRoleVersion((v) => v + 1);
382
+ window.addEventListener('MetaRolesReady', handler);
383
+ return () => window.removeEventListener('MetaRolesReady', handler);
384
+ }, []);
378
385
  const sidebarData = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(() => {
379
386
  const data = getSidebarDataGroup(sidebar, pathname);
380
387
  const userRoles = getUserRoles();
381
- return filterSidebarItems(data, userRoles);
388
+ let dataWithRoles = data;
389
+ try {
390
+ const roleMap = 'undefined' != typeof window ? window.__META_ROLE_MAP__ : null;
391
+ if (roleMap) {
392
+ const applyRoles = (items) => {
393
+ if (!Array.isArray(items)) return items;
394
+ return items.map((item) => {
395
+ if (!item) return item;
396
+ let nextItem = item;
397
+ const key = item._fileKey;
398
+ if (key && roleMap[key]) {
399
+ nextItem = {
400
+ ...nextItem,
401
+ roles: roleMap[key]
402
+ };
403
+ }
404
+ if ('items' in nextItem && Array.isArray(nextItem.items)) {
405
+ const nextItems = applyRoles(nextItem.items);
406
+ if (nextItems !== nextItem.items) {
407
+ nextItem = {
408
+ ...nextItem,
409
+ items: nextItems
410
+ };
411
+ }
412
+ }
413
+ return nextItem;
414
+ });
415
+ };
416
+ dataWithRoles = applyRoles(data);
417
+ }
418
+ } catch (e) {
419
+ }
420
+ console.log('[sidebar] data:', dataWithRoles);
421
+ return filterSidebarItems(dataWithRoles, userRoles);
382
422
  }, [
383
423
  sidebar,
384
- pathname
424
+ pathname,
425
+ roleVersion
385
426
  ]);
386
427
  return sidebarData;
387
428
  }
package/package.json CHANGED
@@ -1,69 +1,69 @@
1
- {
2
- "name": "@rspress-theme-anatole/theme-default",
3
- "author": "Anatole Tong",
4
- "version": "0.7.22-alpha2",
5
- "license": "MIT",
6
- "sideEffects": [
7
- "*.css",
8
- "*.less",
9
- "*.sass",
10
- "*.scss",
11
- "**/virtual-global-styles.js",
12
- "virtual-global-styles",
13
- "./src/styles/index.ts",
14
- "./dist/index.js"
15
- ],
16
- "type": "module",
17
- "imports": {
18
- "#theme/*": "./src/*"
19
- },
20
- "main": "./dist/index.js",
21
- "types": "./dist/bundle.d.ts",
22
- "dependencies": {
23
- "@mdx-js/react": "2.3.0",
24
- "@rspress-theme-anatole/rspress-plugin-mermaid": "0.7.22-alpha2",
25
- "@rspress-theme-anatole/shared": "0.7.22-alpha2",
26
- "@rspress/runtime": "1.43.8",
27
- "body-scroll-lock": "4.0.0-beta.0",
28
- "copy-to-clipboard": "^3.3.3",
29
- "flexsearch": "0.7.43",
30
- "github-slugger": "^2.0.0",
31
- "html2pdf.js": "^0.10.3",
32
- "htmr": "^1.0.2",
33
- "lodash-es": "^4.17.21",
34
- "nprogress": "^0.2.0",
35
- "react": "^18.3.1",
36
- "react-dom": "^18.3.1",
37
- "react-helmet-async": "^1.3.0",
38
- "react-router-dom": "6.29.0",
39
- "react-syntax-highlighter": "^15.6.1"
40
- },
41
- "devDependencies": {
42
- "@microsoft/api-extractor": "^7.49.2",
43
- "@modern-js/tsconfig": "2.64.0",
44
- "@rsbuild/plugin-react": "~1.1.0",
45
- "@rsbuild/plugin-sass": "~1.2.0",
46
- "@rsbuild/plugin-svgr": "^1.0.6",
47
- "@rslib/core": "0.5.2",
48
- "@types/body-scroll-lock": "^3.1.2",
49
- "@types/hast": "^2.3.10",
50
- "@types/jest": "~29.5.14",
51
- "@types/lodash-es": "^4.17.12",
52
- "@types/mdast": "^3.0.15",
53
- "@types/nprogress": "^0.2.3",
54
- "@types/react": "^18.3.18",
55
- "@types/react-dom": "^18.3.5",
56
- "@types/react-syntax-highlighter": "^15.5.13",
57
- "gray-matter": "4.0.3",
58
- "tailwindcss": "^3.4.17",
59
- "typescript": "^5.5.3"
60
- },
61
- "keywords": [
62
- "rspress",
63
- "theme",
64
- "rspress-theme"
65
- ],
66
- "publishConfig": {
67
- "access": "public"
68
- }
1
+ {
2
+ "name": "@rspress-theme-anatole/theme-default",
3
+ "author": "Anatole Tong",
4
+ "version": "0.7.22-alpha3",
5
+ "license": "MIT",
6
+ "sideEffects": [
7
+ "*.css",
8
+ "*.less",
9
+ "*.sass",
10
+ "*.scss",
11
+ "**/virtual-global-styles.js",
12
+ "virtual-global-styles",
13
+ "./src/styles/index.ts",
14
+ "./dist/index.js"
15
+ ],
16
+ "type": "module",
17
+ "imports": {
18
+ "#theme/*": "./src/*"
19
+ },
20
+ "main": "./dist/index.js",
21
+ "types": "./dist/bundle.d.ts",
22
+ "dependencies": {
23
+ "@mdx-js/react": "2.3.0",
24
+ "@rspress-theme-anatole/rspress-plugin-mermaid": "0.7.22-alpha3",
25
+ "@rspress-theme-anatole/shared": "0.7.22-alpha3",
26
+ "@rspress/runtime": "1.43.8",
27
+ "body-scroll-lock": "4.0.0-beta.0",
28
+ "copy-to-clipboard": "^3.3.3",
29
+ "flexsearch": "0.7.43",
30
+ "github-slugger": "^2.0.0",
31
+ "html2pdf.js": "^0.10.3",
32
+ "htmr": "^1.0.2",
33
+ "lodash-es": "^4.17.21",
34
+ "nprogress": "^0.2.0",
35
+ "react": "^18.3.1",
36
+ "react-dom": "^18.3.1",
37
+ "react-helmet-async": "^1.3.0",
38
+ "react-router-dom": "6.29.0",
39
+ "react-syntax-highlighter": "^15.6.1"
40
+ },
41
+ "devDependencies": {
42
+ "@microsoft/api-extractor": "^7.49.2",
43
+ "@modern-js/tsconfig": "2.64.0",
44
+ "@rsbuild/plugin-react": "~1.1.0",
45
+ "@rsbuild/plugin-sass": "~1.2.0",
46
+ "@rsbuild/plugin-svgr": "^1.0.6",
47
+ "@rslib/core": "0.5.2",
48
+ "@types/body-scroll-lock": "^3.1.2",
49
+ "@types/hast": "^2.3.10",
50
+ "@types/jest": "~29.5.14",
51
+ "@types/lodash-es": "^4.17.12",
52
+ "@types/mdast": "^3.0.15",
53
+ "@types/nprogress": "^0.2.3",
54
+ "@types/react": "^18.3.18",
55
+ "@types/react-dom": "^18.3.5",
56
+ "@types/react-syntax-highlighter": "^15.5.13",
57
+ "gray-matter": "4.0.3",
58
+ "tailwindcss": "^3.4.17",
59
+ "typescript": "^5.5.3"
60
+ },
61
+ "keywords": [
62
+ "rspress",
63
+ "theme",
64
+ "rspress-theme"
65
+ ],
66
+ "publishConfig": {
67
+ "access": "public"
68
+ }
69
69
  }