@blocklet/ui-react 3.1.48 → 3.1.49

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 (98) hide show
  1. package/.aigne/doc-smith/config.yaml +76 -0
  2. package/.aigne/doc-smith/history.yaml +9 -0
  3. package/.aigne/doc-smith/output/structure-plan.json +249 -0
  4. package/.aigne/doc-smith/upload-cache.yaml +528 -0
  5. package/docs/_sidebar.md +19 -0
  6. package/docs/components-component-management-blocklet-studio.ja.md +194 -0
  7. package/docs/components-component-management-blocklet-studio.md +194 -0
  8. package/docs/components-component-management-blocklet-studio.zh-TW.md +194 -0
  9. package/docs/components-component-management-blocklet-studio.zh.md +194 -0
  10. package/docs/components-component-management-component-installer.ja.md +256 -0
  11. package/docs/components-component-management-component-installer.md +256 -0
  12. package/docs/components-component-management-component-installer.zh-TW.md +256 -0
  13. package/docs/components-component-management-component-installer.zh.md +256 -0
  14. package/docs/components-component-management.ja.md +59 -0
  15. package/docs/components-component-management.md +59 -0
  16. package/docs/components-component-management.zh-TW.md +59 -0
  17. package/docs/components-component-management.zh.md +59 -0
  18. package/docs/components-layout-dashboard.ja.md +231 -0
  19. package/docs/components-layout-dashboard.md +231 -0
  20. package/docs/components-layout-dashboard.zh-TW.md +231 -0
  21. package/docs/components-layout-dashboard.zh.md +231 -0
  22. package/docs/components-layout-footer.ja.md +165 -0
  23. package/docs/components-layout-footer.md +165 -0
  24. package/docs/components-layout-footer.zh-TW.md +165 -0
  25. package/docs/components-layout-footer.zh.md +165 -0
  26. package/docs/components-layout-header.ja.md +233 -0
  27. package/docs/components-layout-header.md +233 -0
  28. package/docs/components-layout-header.zh-TW.md +233 -0
  29. package/docs/components-layout-header.zh.md +233 -0
  30. package/docs/components-layout.ja.md +50 -0
  31. package/docs/components-layout.md +50 -0
  32. package/docs/components-layout.zh-TW.md +50 -0
  33. package/docs/components-layout.zh.md +50 -0
  34. package/docs/components-notifications.ja.md +173 -0
  35. package/docs/components-notifications.md +173 -0
  36. package/docs/components-notifications.zh-TW.md +174 -0
  37. package/docs/components-notifications.zh.md +173 -0
  38. package/docs/components-user-management-user-center.ja.md +183 -0
  39. package/docs/components-user-management-user-center.md +183 -0
  40. package/docs/components-user-management-user-center.zh-TW.md +183 -0
  41. package/docs/components-user-management-user-center.zh.md +183 -0
  42. package/docs/components-user-management-user-sessions.ja.md +164 -0
  43. package/docs/components-user-management-user-sessions.md +164 -0
  44. package/docs/components-user-management-user-sessions.zh-TW.md +164 -0
  45. package/docs/components-user-management-user-sessions.zh.md +164 -0
  46. package/docs/components-user-management.ja.md +76 -0
  47. package/docs/components-user-management.md +76 -0
  48. package/docs/components-user-management.zh-TW.md +76 -0
  49. package/docs/components-user-management.zh.md +76 -0
  50. package/docs/components-utilities-icon.ja.md +106 -0
  51. package/docs/components-utilities-icon.md +106 -0
  52. package/docs/components-utilities-icon.zh-TW.md +106 -0
  53. package/docs/components-utilities-icon.zh.md +106 -0
  54. package/docs/components-utilities.ja.md +136 -0
  55. package/docs/components-utilities.md +136 -0
  56. package/docs/components-utilities.zh-TW.md +136 -0
  57. package/docs/components-utilities.zh.md +136 -0
  58. package/docs/components.ja.md +27 -0
  59. package/docs/components.md +27 -0
  60. package/docs/components.zh-TW.md +27 -0
  61. package/docs/components.zh.md +27 -0
  62. package/docs/core-concepts.ja.md +164 -0
  63. package/docs/core-concepts.md +164 -0
  64. package/docs/core-concepts.zh-TW.md +164 -0
  65. package/docs/core-concepts.zh.md +164 -0
  66. package/docs/getting-started.ja.md +132 -0
  67. package/docs/getting-started.md +132 -0
  68. package/docs/getting-started.zh-TW.md +132 -0
  69. package/docs/getting-started.zh.md +132 -0
  70. package/docs/hooks-api.ja.md +214 -0
  71. package/docs/hooks-api.md +214 -0
  72. package/docs/hooks-api.zh-TW.md +214 -0
  73. package/docs/hooks-api.zh.md +214 -0
  74. package/docs/how-to-guides.ja.md +413 -0
  75. package/docs/how-to-guides.md +413 -0
  76. package/docs/how-to-guides.zh-TW.md +413 -0
  77. package/docs/how-to-guides.zh.md +413 -0
  78. package/docs/overview.ja.md +91 -0
  79. package/docs/overview.md +91 -0
  80. package/docs/overview.zh-TW.md +91 -0
  81. package/docs/overview.zh.md +91 -0
  82. package/glossary.md +12 -0
  83. package/lib/Dashboard/index.js +46 -42
  84. package/lib/Footer/index.js +51 -36
  85. package/lib/Header/index.js +48 -44
  86. package/lib/UserCenter/components/settings.js +1 -0
  87. package/lib/UserCenter/components/user-center.js +133 -133
  88. package/lib/blocklets.d.ts +13 -2
  89. package/lib/blocklets.js +40 -40
  90. package/lib/common/header-addons.js +37 -33
  91. package/package.json +7 -7
  92. package/src/Dashboard/index.jsx +8 -3
  93. package/src/Footer/index.jsx +22 -4
  94. package/src/Header/index.tsx +7 -2
  95. package/src/UserCenter/components/settings.tsx +1 -0
  96. package/src/UserCenter/components/user-center.tsx +6 -6
  97. package/src/blocklets.js +18 -9
  98. package/src/common/header-addons.jsx +7 -2
@@ -1,42 +1,46 @@
1
- import { jsx as i, Fragment as A } from "react/jsx-runtime";
1
+ import { jsx as i, Fragment as b } from "react/jsx-runtime";
2
2
  import "iconify-icon";
3
3
  import a from "prop-types";
4
- import { use as b, createElement as L } from "react";
5
- import { SessionContext as v } from "@arcblock/did-connect-react/lib/Session";
6
- import N from "@arcblock/ux/lib/Config/theme-mode-toggle";
7
- import { useLocaleContext as T } from "@arcblock/ux/lib/Locale/context";
8
- import k from "@arcblock/ux/lib/Locale/selector";
9
- import C from "@arcblock/ux/lib/SessionBlocklet";
10
- import S from "@arcblock/ux/lib/SessionUser";
11
- import { WELLKNOWN_BLOCKLET_ADMIN_PATH as D } from "@abtnode/constant";
12
- import { getLocalizedNavigation as E, filterNavByRole as M } from "../blocklets.js";
13
- import { SessionManagerProps as O } from "../types.js";
14
- import R from "./domain-warning.js";
15
- import W from "./notification-addon.js";
16
- import P from "./org-switch/index.js";
17
- const B = () => !!(window?.blocklet?.navigation ?? []).find((o) => o.id === "/userCenter/notification"), _ = (n) => {
4
+ import { use as L, createElement as v } from "react";
5
+ import { SessionContext as N } from "@arcblock/did-connect-react/lib/Session";
6
+ import T from "@arcblock/ux/lib/Config/theme-mode-toggle";
7
+ import { useLocaleContext as k } from "@arcblock/ux/lib/Locale/context";
8
+ import C from "@arcblock/ux/lib/Locale/selector";
9
+ import S from "@arcblock/ux/lib/SessionBlocklet";
10
+ import D from "@arcblock/ux/lib/SessionUser";
11
+ import { WELLKNOWN_BLOCKLET_ADMIN_PATH as E } from "@abtnode/constant";
12
+ import { getLocalizedNavigation as M, filterNavByRole as O } from "../blocklets.js";
13
+ import { SessionManagerProps as R } from "../types.js";
14
+ import W from "./domain-warning.js";
15
+ import P from "./notification-addon.js";
16
+ import B from "./org-switch/index.js";
17
+ const _ = () => !!(window?.blocklet?.navigation ?? []).find((o) => o.id === "/userCenter/notification"), j = (n) => {
18
18
  const { settings: o = {} } = n ?? window?.blocklet ?? {};
19
19
  return o?.org?.enabled || !1;
20
- }, j = () => {
20
+ }, x = () => {
21
21
  const { pathname: n = "" } = window.location || {};
22
- return n.startsWith(D);
22
+ return n.startsWith(E);
23
23
  };
24
- function x({
24
+ function z({
25
25
  formattedBlocklet: n,
26
26
  addons: o = null,
27
27
  showDomainWarningDialog: m = !0,
28
28
  sessionManagerProps: u = { showRole: !0 }
29
29
  }) {
30
- const e = b(v), { locale: t, languages: p } = T() || {}, { enableConnect: g = !0, enableLocale: d = !0 } = n, h = !!e?.session?.user;
31
- let l = E(n?.navigation?.sessionManager, t) || [];
32
- l = M(l, e?.session?.user?.role);
30
+ const e = L(N), { locale: t, languages: p, defaultLocale: g } = k() || {}, { enableConnect: d = !0, enableLocale: h = !0 } = n, y = !!e?.session?.user;
31
+ let l = M({
32
+ navigation: n?.navigation?.sessionManager,
33
+ locale: t,
34
+ defaultLocale: g
35
+ }) || [];
36
+ l = O(l, e?.session?.user?.role);
33
37
  const c = (() => {
34
38
  if (o && typeof o != "function")
35
39
  return Array.isArray(o) ? o : [o];
36
40
  let s = [];
37
- if (B() && s.push(/* @__PURE__ */ i(W, { session: e.session }, "notification-addon")), d && t && p.length > 1 && s.push(/* @__PURE__ */ i(k, { showText: !1 }, "locale-selector")), s.push(/* @__PURE__ */ i(N, {}, "theme-mode-toggle")), g && e) {
41
+ if (_() && s.push(/* @__PURE__ */ i(P, { session: e.session }, "notification-addon")), h && t && p.length > 1 && s.push(/* @__PURE__ */ i(C, { showText: !1 }, "locale-selector")), s.push(/* @__PURE__ */ i(T, {}, "theme-mode-toggle")), d && e) {
38
42
  const f = [];
39
- h && (l ? l.slice(0, 5) : []).forEach((r) => {
43
+ y && (l ? l.slice(0, 5) : []).forEach((r) => {
40
44
  f.push({
41
45
  label: r.title,
42
46
  icon: r.icon ? /* @__PURE__ */ i("iconify-icon", { icon: r.icon, height: 24, style: { marginRight: 8 } }) : null,
@@ -44,9 +48,9 @@ function x({
44
48
  href: r.link,
45
49
  key: r.link
46
50
  });
47
- }), s.push(/* @__PURE__ */ i(C, { session: e.session, locale: t }, "session-blocklet")), s.push(
51
+ }), s.push(/* @__PURE__ */ i(S, { session: e.session, locale: t }, "session-blocklet")), s.push(
48
52
  /* @__PURE__ */ i(
49
- S,
53
+ D,
50
54
  {
51
55
  session: e.session,
52
56
  locale: t,
@@ -58,22 +62,22 @@ function x({
58
62
  )
59
63
  );
60
64
  }
61
- return !j() && _(n) && e?.session?.user && s.unshift(/* @__PURE__ */ i(P, { session: e.session, locale: t }, "orgs-switch")), typeof o == "function" && (s = o(s) || []), s;
62
- })(), y = Array.isArray(c) ? c : [c], w = [
63
- m ? /* @__PURE__ */ i(R, { session: e?.session, locale: t }) : null,
64
- ...y
65
+ return !x() && j(n) && e?.session?.user && s.unshift(/* @__PURE__ */ i(B, { session: e.session, locale: t }, "orgs-switch")), typeof o == "function" && (s = o(s) || []), s;
66
+ })(), w = Array.isArray(c) ? c : [c], A = [
67
+ m ? /* @__PURE__ */ i(W, { session: e?.session, locale: t }) : null,
68
+ ...w
65
69
  ].filter(Boolean);
66
- return L(A, null, ...w);
70
+ return v(b, null, ...A);
67
71
  }
68
- x.propTypes = {
72
+ z.propTypes = {
69
73
  formattedBlocklet: a.object.isRequired,
70
74
  // 需要考虑 定制的 addons 与内置的 连接钱包/选择语言 addons 共存的情况
71
75
  // - PropTypes.func: 可以把自定义 addons 插在 session-manager 或 locale-selector (如果存在的话) 前/中/后
72
76
  // - PropTypes.node: 将 addons 原样传给 UX Header 组件
73
77
  addons: a.oneOfType([a.func, a.node]),
74
- sessionManagerProps: O,
78
+ sessionManagerProps: R,
75
79
  showDomainWarningDialog: a.bool
76
80
  };
77
81
  export {
78
- x as default
82
+ z as default
79
83
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/ui-react",
3
- "version": "3.1.48",
3
+ "version": "3.1.49",
4
4
  "description": "Some useful front-end web components that can be used in Blocklets.",
5
5
  "keywords": [
6
6
  "react",
@@ -9,7 +9,7 @@
9
9
  "blocklet"
10
10
  ],
11
11
  "author": "wangshijun<wangshijun2010@gmail.com>",
12
- "homepage": "https://github.com/ArcBlock/ux#readme",
12
+ "homepage": "https://www.arcblock.io/docs/blocklet-ui-react",
13
13
  "license": "Apache-2.0",
14
14
  "main": "lib/index.js",
15
15
  "module": "lib/index.js",
@@ -35,9 +35,9 @@
35
35
  "dependencies": {
36
36
  "@abtnode/constant": "1.16.52",
37
37
  "@abtnode/util": "1.16.52",
38
- "@arcblock/bridge": "3.1.48",
39
- "@arcblock/icons": "3.1.48",
40
- "@arcblock/react-hooks": "3.1.48",
38
+ "@arcblock/bridge": "3.1.49",
39
+ "@arcblock/icons": "3.1.49",
40
+ "@arcblock/react-hooks": "3.1.49",
41
41
  "@arcblock/ws": "^1.25.6",
42
42
  "@blocklet/constant": "1.16.52",
43
43
  "@blocklet/did-space-react": "^1.1.32",
@@ -83,7 +83,7 @@
83
83
  "access": "public"
84
84
  },
85
85
  "devDependencies": {
86
- "@arcblock/did-connect-react": "3.1.48",
86
+ "@arcblock/did-connect-react": "3.1.49",
87
87
  "@types/dompurify": "^3.2.0",
88
88
  "@types/ua-parser-js": "^0.7.39",
89
89
  "@types/validator": "^13.15.2",
@@ -91,5 +91,5 @@
91
91
  "jest": "^29.7.0",
92
92
  "unbuild": "^2.0.0"
93
93
  },
94
- "gitHead": "49a6dabae8a06667e517c6811f5f7939ff907ce1"
94
+ "gitHead": "4612b57a1452bd4330755b53d093505a6ae7dea5"
95
95
  }
@@ -38,7 +38,7 @@ function Dashboard({
38
38
  const sessionCtx = use(SessionContext);
39
39
  const user = sessionCtx?.session?.user;
40
40
  const userRole = user?.role;
41
- const { locale } = useLocaleContext() || {};
41
+ const { locale, defaultLocale } = useLocaleContext() || {};
42
42
  const formattedBlocklet = useMemo(() => {
43
43
  const blocklet = Object.assign({}, window.blocklet, meta);
44
44
  try {
@@ -50,7 +50,12 @@ function Dashboard({
50
50
  }, [meta]);
51
51
  const { localizedNav, flattened, matchedIndex } = useMemo(() => {
52
52
  // eslint-disable-next-line @typescript-eslint/no-shadow
53
- let localizedNav = getLocalizedNavigation(formattedBlocklet?.navigation?.dashboard, locale) || [];
53
+ let localizedNav =
54
+ getLocalizedNavigation({
55
+ navigation: formattedBlocklet?.navigation?.dashboard,
56
+ locale,
57
+ defaultLocale,
58
+ }) || [];
54
59
  // 根据 role 筛选 nav 数据
55
60
  localizedNav = filterNavByRole(localizedNav, userRole);
56
61
  // 将 nav 数据处理成 ux dashboard 需要的格式
@@ -88,7 +93,7 @@ function Dashboard({
88
93
  flattened[matchedIndex].active = true;
89
94
  }
90
95
  return { localizedNav, flattened, matchedIndex };
91
- }, [formattedBlocklet, locale, userRole]);
96
+ }, [formattedBlocklet, locale, defaultLocale, userRole]);
92
97
 
93
98
  const allLinks = typeof links === 'function' ? links(localizedNav) : [...localizedNav, ...links];
94
99
  const appLogo = useBlockletLogo({
@@ -17,7 +17,7 @@ import withHideWhenEmbed from '../libs/with-hide-when-embed';
17
17
  * 专门用于 (composable) blocklet 的 Footer 组件, 基于 blocklet meta 中的数据渲染
18
18
  */
19
19
  function Footer({ meta = {}, theme: themeOverrides = {}, ...rest }) {
20
- const { locale } = useLocaleContext() || {};
20
+ const { locale, defaultLocale } = useLocaleContext() || {};
21
21
  const parentTheme = useTheme();
22
22
  const formattedBlocklet = useMemo(() => {
23
23
  const blocklet = Object.assign({}, window.blocklet, meta);
@@ -44,9 +44,27 @@ function Footer({ meta = {}, theme: themeOverrides = {}, ...rest }) {
44
44
  const $bgColor = mergeTheme.palette.background.default;
45
45
 
46
46
  const localized = {
47
- footerNav: getLocalizedNavigation(formattedBlocklet?.navigation?.footer, locale, 'footer') || [],
48
- socialMedia: getLocalizedNavigation(formattedBlocklet?.navigation?.social, locale, 'footer') || [],
49
- links: getLocalizedNavigation(formattedBlocklet?.navigation?.bottom, locale, 'footer') || [],
47
+ footerNav:
48
+ getLocalizedNavigation({
49
+ navigation: formattedBlocklet?.navigation?.footer,
50
+ locale,
51
+ defaultLocale,
52
+ section: 'footer',
53
+ }) || [],
54
+ socialMedia:
55
+ getLocalizedNavigation({
56
+ navigation: formattedBlocklet?.navigation?.social,
57
+ locale,
58
+ defaultLocale,
59
+ section: 'footer',
60
+ }) || [],
61
+ links:
62
+ getLocalizedNavigation({
63
+ navigation: formattedBlocklet?.navigation?.bottom,
64
+ locale,
65
+ defaultLocale,
66
+ section: 'footer',
67
+ }) || [],
50
68
  };
51
69
 
52
70
  const props = {
@@ -121,7 +121,7 @@ function Header({
121
121
  }: HeaderProps & Omit<BoxProps, keyof HeaderProps>) {
122
122
  useWalletHiddenTopbar();
123
123
  const parentTheme = useTheme();
124
- const { locale } = useLocaleContext() || {};
124
+ const { locale, defaultLocale } = useLocaleContext() || {};
125
125
  const t = useMemoizedFn((key, data = {}) => {
126
126
  return translate(translations, key, locale, 'en', data);
127
127
  });
@@ -171,7 +171,12 @@ function Header({
171
171
  if (!formattedBlocklet.appName) {
172
172
  return null;
173
173
  }
174
- const navigation = getLocalizedNavigation(formattedBlocklet?.navigation?.header, locale);
174
+ const navigation = getLocalizedNavigation({
175
+ navigation: formattedBlocklet?.navigation?.header,
176
+ locale,
177
+ defaultLocale,
178
+ });
179
+
175
180
  const parsedNavigation = parseNavigation(navigation);
176
181
  const { navItems, activeId } = parsedNavigation;
177
182
 
@@ -76,6 +76,7 @@ export default function Settings({
76
76
  {
77
77
  label: t('privacyManagement'),
78
78
  value: 'privacy',
79
+ // @ts-ignore
79
80
  content: <Privacy configList={privacyConfigList} onSave={onSave} />,
80
81
  },
81
82
  {
@@ -113,7 +113,7 @@ export default function UserCenter({
113
113
  readonly onlyProfile?: boolean;
114
114
  readonly onDestroySelf?: () => void;
115
115
  }) {
116
- const { locale } = useLocaleContext();
116
+ const { locale, defaultLocale } = useLocaleContext();
117
117
  const isMobile = useMobile({ key: 'md' });
118
118
  const t = useMemoizedFn((key, data = {}) => {
119
119
  return translate(translations, key, locale, 'en', data);
@@ -223,14 +223,14 @@ export default function UserCenter({
223
223
  protected: false,
224
224
  isPrivate: false, // true: 隐私数据,仅自己可见
225
225
  value: nftsLink,
226
- url: getLink(nftsLink, locale),
226
+ url: getLink(nftsLink, locale, defaultLocale),
227
227
  };
228
228
  const userFollowersTab = {
229
229
  label: t('userFollowers'),
230
230
  protected: false,
231
231
  isPrivate: false,
232
232
  value: userFollowersLink,
233
- url: getLink(userFollowersLink, locale),
233
+ url: getLink(userFollowersLink, locale, defaultLocale),
234
234
  };
235
235
  let tabs: NavigationTabProps[] = isShowSocialActions ? [nftTab, userFollowersTab] : [nftTab];
236
236
  if (isMyself) {
@@ -241,14 +241,14 @@ export default function UserCenter({
241
241
  protected: true,
242
242
  isPrivate: true,
243
243
  value: settingsLink,
244
- url: getLink(settingsLink, locale),
244
+ url: getLink(settingsLink, locale, defaultLocale),
245
245
  },
246
246
  {
247
247
  label: t('storageManagement'),
248
248
  protected: true,
249
249
  isPrivate: true,
250
250
  value: didSpacesLink,
251
- url: getLink(didSpacesLink, locale),
251
+ url: getLink(didSpacesLink, locale, defaultLocale),
252
252
  },
253
253
  ];
254
254
  tabs = isShowSocialActions ? [...restTabs, userFollowersTab] : restTabs;
@@ -258,7 +258,7 @@ export default function UserCenter({
258
258
 
259
259
  const userCenterTabs = useCreation<UserCenterTab[]>(() => {
260
260
  const menus = formattedBlocklet?.navigation?.userCenter || [];
261
- const localizedMenus = getLocalizedNavigation(menus, locale) || [];
261
+ const localizedMenus = getLocalizedNavigation({ navigation: menus, locale, defaultLocale }) || [];
262
262
  const allMenus = localizedMenus.concat(defaultTabs);
263
263
  return allMenus
264
264
  .map((x: any) => {
package/src/blocklets.js CHANGED
@@ -21,7 +21,7 @@ export const formatTheme = (theme) => {
21
21
  return formatted;
22
22
  };
23
23
 
24
- export const getLink = (link, locale = 'en') => {
24
+ export const getLink = (link, locale = 'en', defaultLocale = 'en') => {
25
25
  if (typeof link === 'string') {
26
26
  // http[s] 开头的 url
27
27
  if (isUrl(link)) {
@@ -38,25 +38,34 @@ export const getLink = (link, locale = 'en') => {
38
38
  return url.pathname + url.search;
39
39
  }
40
40
  if (typeof link === 'object') {
41
- return link[locale] || link?.en || link?.zh;
41
+ return link[locale] || link[defaultLocale] || link.en;
42
42
  }
43
43
  return link;
44
44
  };
45
45
 
46
46
  /**
47
+ * 获取本地化后的导航菜单
47
48
  *
48
- * @param {any[]} navigation 导航菜单数据
49
- * @param {string} locale 语言
50
- * @param {'header' | 'footer'} section 导航区域
51
- * 获取指定 locale 对应的 navigation 数据, 仅考虑 zh/en
49
+ * @param {Object} params
50
+ * @param {Array<{
51
+ * title?: string | Record<string, string>,
52
+ * description?: string | Record<string, string>,
53
+ * link?: string | Record<string, string>,
54
+ * items?: any[],
55
+ * [key: string]: any
56
+ * }>} params.navigation - 导航菜单数据
57
+ * @param {string} params.locale - 当前语言
58
+ * @param {string} params.defaultLocale - 默认语言
59
+ * @param {'header' | 'footer'} [params.section='header'] - 导航区域,可选
60
+ * @returns {Array} 本地化处理后的导航数据
52
61
  */
53
- export const getLocalizedNavigation = (navigation, locale = 'en', section = 'header') => {
62
+ export const getLocalizedNavigation = ({ navigation, locale, defaultLocale, section = 'header' }) => {
54
63
  if (!navigation?.length) {
55
64
  return navigation;
56
65
  }
57
66
  const trans = (text, _locale) => {
58
67
  if (text && typeof text === 'object') {
59
- return text[_locale] || text?.en || text?.zh;
68
+ return text[_locale] || text[defaultLocale] || text.en;
60
69
  }
61
70
 
62
71
  return text;
@@ -70,7 +79,7 @@ export const getLocalizedNavigation = (navigation, locale = 'en', section = 'hea
70
79
  title: trans(item.title, locale),
71
80
  description: trans(item.description, locale),
72
81
  // 仅对叶结点进行处理
73
- link: getUTMUrl(!item.items?.length ? getLink(item.link, locale) : item.link, section),
82
+ link: getUTMUrl(!item.items?.length ? getLink(item.link, locale, defaultLocale) : item.link, section),
74
83
  _rawLink: item.link,
75
84
  };
76
85
  },
@@ -42,10 +42,15 @@ export default function HeaderAddons({
42
42
  sessionManagerProps = { showRole: true },
43
43
  }) {
44
44
  const sessionCtx = use(SessionContext);
45
- const { locale, languages } = useLocaleContext() || {};
45
+ const { locale, languages, defaultLocale } = useLocaleContext() || {};
46
46
  const { enableConnect = true, enableLocale = true } = formattedBlocklet;
47
47
  const authenticated = !!sessionCtx?.session?.user;
48
- let localizedNav = getLocalizedNavigation(formattedBlocklet?.navigation?.sessionManager, locale) || [];
48
+ let localizedNav =
49
+ getLocalizedNavigation({
50
+ navigation: formattedBlocklet?.navigation?.sessionManager,
51
+ locale,
52
+ defaultLocale,
53
+ }) || [];
49
54
  // 根据 role 筛选 nav 数据
50
55
  localizedNav = filterNavByRole(localizedNav, sessionCtx?.session?.user?.role);
51
56