@blocklet/ui-react 2.11.7 → 2.11.9

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.
@@ -54,10 +54,12 @@ export default function Passport({ user, ...rest }) {
54
54
  ...rest,
55
55
  sx: {
56
56
  display: "grid",
57
+ justifyItems: "start",
57
58
  gridTemplateColumns: {
58
59
  xs: "repeat(2, 1fr)",
59
- sm: "repeat(3, 1fr)",
60
- md: "repeat(4, 1fr)"
60
+ sm: "repeat(2, 1fr)",
61
+ md: "repeat(3, 1fr)",
62
+ lg: "repeat(5, 1fr)"
61
63
  },
62
64
  gap: 2.5,
63
65
  ...rest.sx
@@ -20,11 +20,13 @@ import Footer from "../../Footer/index.js";
20
20
  import Header from "../../Header/index.js";
21
21
  import { translations } from "../libs/locales.js";
22
22
  import { UserInfo, UserBasicInfo, SwitchRole } from "./user-info/index.js";
23
- import { formatBlockletInfo, getLocalizedNavigation } from "../../blocklets.js";
23
+ import { formatBlockletInfo, getLink, getLocalizedNavigation } from "../../blocklets.js";
24
24
  import Passport from "./passport.js";
25
25
  import Settings from "./settings.js";
26
26
  import { client } from "../../libs/client.js";
27
27
  import useMobile from "../../hooks/use-mobile.js";
28
+ const profileLink = joinURL(PROFILE_URL, "/profile");
29
+ const settingsLink = joinURL(PROFILE_URL, "/settings");
28
30
  export default function UserCenter({
29
31
  children,
30
32
  notLoginContent = null,
@@ -127,7 +129,8 @@ export default function UserCenter({
127
129
  {
128
130
  label: t("common.profile"),
129
131
  protected: false,
130
- url: joinURL(PROFILE_URL, "/profile")
132
+ value: profileLink,
133
+ url: getLink(profileLink, locale)
131
134
  }
132
135
  ];
133
136
  if (isMyself) {
@@ -135,17 +138,18 @@ export default function UserCenter({
135
138
  label: t("common.setting"),
136
139
  protected: true,
137
140
  isPrivate: true,
138
- url: joinURL(PROFILE_URL, "/settings")
141
+ value: settingsLink,
142
+ url: getLink(settingsLink, locale)
139
143
  });
140
144
  }
141
145
  return tabs;
142
- }, [isMyself]);
146
+ }, [isMyself, locale]);
143
147
  const userCenterTabs = useCreation(() => {
144
148
  const menus = formattedBlocklet?.navigation?.userCenter || [];
145
149
  const localizedMenus = getLocalizedNavigation(menus, locale) || [];
146
150
  const allMenus = localizedMenus.concat(defaultTabs);
147
151
  return allMenus.map((x) => {
148
- const value = x._rawLink ?? x.link ?? x.url;
152
+ const value = x.value ?? x._rawLink ?? x.link ?? x.url;
149
153
  return {
150
154
  value,
151
155
  label: x.title || x.label,
@@ -215,13 +219,24 @@ export default function UserCenter({
215
219
  top: (theme) => stickySidebar ? theme.spacing(3) : "unset"
216
220
  },
217
221
  children: [
218
- /* @__PURE__ */ jsxs(Box, { children: [
219
- /* @__PURE__ */ jsxs(Box, { display: "flex", justifyContent: "space-between", children: [
220
- /* @__PURE__ */ jsx(Typography, { sx: { fontWeight: 600, mb: 1.5 }, children: isMyself ? t("myInfo") : t("hisInfo") }),
221
- isMyself ? /* @__PURE__ */ jsx(SwitchRole, { user: userState.data, switchPassport: session.switchPassport }) : null
222
- ] }),
223
- /* @__PURE__ */ jsx(UserInfo, { user: userState.data, isMySelf: isMyself })
224
- ] }),
222
+ /* @__PURE__ */ jsxs(
223
+ Box,
224
+ {
225
+ sx: {
226
+ width: {
227
+ sx: "100%",
228
+ md: 420
229
+ }
230
+ },
231
+ children: [
232
+ /* @__PURE__ */ jsxs(Box, { display: "flex", justifyContent: "space-between", children: [
233
+ /* @__PURE__ */ jsx(Typography, { sx: { fontWeight: 600, mb: 1.5 }, children: isMyself ? t("myInfo") : t("hisInfo") }),
234
+ isMyself ? /* @__PURE__ */ jsx(SwitchRole, { user: userState.data, switchPassport: session.switchPassport }) : null
235
+ ] }),
236
+ /* @__PURE__ */ jsx(UserInfo, { user: userState.data, isMySelf: isMyself })
237
+ ]
238
+ }
239
+ ),
225
240
  isMyself ? /* @__PURE__ */ jsxs(Box, { children: [
226
241
  /* @__PURE__ */ jsx(Typography, { sx: { fontWeight: 600, mb: 1.5 }, children: t("passport") }),
227
242
  /* @__PURE__ */ jsx(Passport, { user: userState.data })
@@ -322,6 +337,8 @@ export default function UserCenter({
322
337
  onChange: handleChangeTab,
323
338
  sx: {
324
339
  width: isMobile ? "100%" : 180,
340
+ marginBottom: isMobile ? "8px" : 0,
341
+ flexShrink: 0,
325
342
  ".MuiTabs-flexContainer": {
326
343
  gap: 1.5,
327
344
  ".MuiButtonBase-root": {
@@ -345,7 +362,8 @@ export default function UserCenter({
345
362
  minHeight: "160px",
346
363
  display: "flex",
347
364
  justifyContent: "center",
348
- alignItems: "center"
365
+ alignItems: "center",
366
+ flex: 1
349
367
  },
350
368
  children: /* @__PURE__ */ jsx(CircularProgress, { sx: { color: colors.primary100 } })
351
369
  }
@@ -391,8 +409,8 @@ export default function UserCenter({
391
409
  }
392
410
  return currentActiveTab?.isPrivate;
393
411
  }, [isMyself, currentActiveTab]);
394
- if (!disableAutoRedirect && !currentTab && formattedBlocklet?.navigation?.userCenter?.length > 0 || !currentActiveTab || isPrivateActive) {
395
- const firstUserCenterUrl = formattedBlocklet?.navigation?.userCenter[0]?.link;
412
+ if (!disableAutoRedirect && !currentTab && userCenterTabs?.length > 0 || !currentActiveTab || isPrivateActive) {
413
+ const firstUserCenterUrl = userCenterTabs[0]?.url;
396
414
  const firstTab = userCenterTabs.find((x) => x.value === firstUserCenterUrl);
397
415
  if (firstUserCenterUrl && !firstTab?.isPrivate) {
398
416
  window.location.replace(
@@ -260,6 +260,9 @@ export default function UserSessions({
260
260
  ".MuiTableCell-head": {
261
261
  whiteSpace: "nowrap",
262
262
  fontWeight: "bold"
263
+ },
264
+ ".MuiTableCell-root": {
265
+ paddingRight: "16px"
263
266
  }
264
267
  },
265
268
  children: [
@@ -1,5 +1,6 @@
1
1
  export const publicPath: any;
2
2
  export function formatTheme(theme: any): any;
3
+ export function getLink(link: any, locale?: string): any;
3
4
  export function getLocalizedNavigation(navigation: any, locale?: string): any;
4
5
  export function formatNavigation(navigation: any): any;
5
6
  export function parseNavigation(navigation: any): {
package/lib/blocklets.js CHANGED
@@ -20,6 +20,24 @@ export const formatTheme = (theme) => {
20
20
  return formatted;
21
21
  };
22
22
 
23
+ export const getLink = (link, locale = 'en') => {
24
+ if (typeof link === 'string') {
25
+ // http[s] 开头的 url
26
+ if (isUrl(link)) {
27
+ const url = new URL(link);
28
+ url.searchParams.set('locale', locale);
29
+ return url.href;
30
+ }
31
+ const url = new URL(link, window.location.origin);
32
+ url.searchParams.set('locale', locale);
33
+ return url.pathname + url.search;
34
+ }
35
+ if (typeof link === 'object') {
36
+ return link[locale] || link?.en || link?.zh;
37
+ }
38
+ return link;
39
+ };
40
+
23
41
  /**
24
42
  * 获取指定 locale 对应的 navigation 数据, 仅考虑 zh/en
25
43
  */
@@ -37,24 +55,7 @@ export const getLocalizedNavigation = (navigation, locale = 'en') => {
37
55
  }
38
56
  return title;
39
57
  };
40
- // eslint-disable-next-line no-shadow
41
- const getLink = (link, _locale) => {
42
- if (typeof link === 'string') {
43
- // http[s] 开头的 url
44
- if (isUrl(link)) {
45
- const url = new URL(link);
46
- url.searchParams.set('locale', _locale);
47
- return url.href;
48
- }
49
- const url = new URL(link, window.location.origin);
50
- url.searchParams.set('locale', _locale);
51
- return url.pathname + url.search;
52
- }
53
- if (typeof link === 'object') {
54
- return link[_locale] || link?.en || link?.zh;
55
- }
56
- return link;
57
- };
58
+
58
59
  return mapRecursive(
59
60
  navigation,
60
61
  (item) => {
@@ -23,7 +23,6 @@ export default function NotificationAddon({ session = {} }) {
23
23
  href: viewAllUrl,
24
24
  sx: {
25
25
  borderRadius: 2,
26
- color: "rgba(0, 0, 0, 0.6)",
27
26
  borderColor: colors.lineBorderStrong,
28
27
  "&:hover": {
29
28
  borderRadius: "50%"
@@ -7,7 +7,7 @@ import bridge from '@arcblock/bridge';
7
7
  export const useWalletHiddenTopbar = () => {
8
8
  const browser = useBrowser();
9
9
  useEffect(() => {
10
- if (browser.wallet) {
10
+ if (browser.wallet || browser.arcSphere) {
11
11
  bridge.call('arcHideTopBar', '{}');
12
12
  }
13
13
  }, [browser]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/ui-react",
3
- "version": "2.11.7",
3
+ "version": "2.11.9",
4
4
  "description": "Some useful front-end web components that can be used in Blocklets.",
5
5
  "keywords": [
6
6
  "react",
@@ -32,8 +32,8 @@
32
32
  "url": "https://github.com/ArcBlock/ux/issues"
33
33
  },
34
34
  "dependencies": {
35
- "@arcblock/bridge": "^2.11.7",
36
- "@arcblock/react-hooks": "^2.11.7",
35
+ "@arcblock/bridge": "^2.11.9",
36
+ "@arcblock/react-hooks": "^2.11.9",
37
37
  "@blocklet/did-space-react": "^0.5.83",
38
38
  "@iconify-icons/logos": "^1.2.36",
39
39
  "@iconify-icons/material-symbols": "^1.2.58",
@@ -81,5 +81,5 @@
81
81
  "jest": "^29.7.0",
82
82
  "unbuild": "^2.0.0"
83
83
  },
84
- "gitHead": "1561a224b2ac2e0f8ec38fdaa4983d0582b418ba"
84
+ "gitHead": "cc71a9dd666287cb70d1a7bd487d1930294b9765"
85
85
  }
@@ -65,10 +65,12 @@ export default function Passport({ user, ...rest }: { user: User } & BoxProps) {
65
65
  {...rest}
66
66
  sx={{
67
67
  display: 'grid',
68
+ justifyItems: 'start',
68
69
  gridTemplateColumns: {
69
70
  xs: 'repeat(2, 1fr)',
70
- sm: 'repeat(3, 1fr)',
71
- md: 'repeat(4, 1fr)',
71
+ sm: 'repeat(2, 1fr)',
72
+ md: 'repeat(3, 1fr)',
73
+ lg: 'repeat(5, 1fr)',
72
74
  },
73
75
  gap: 2.5,
74
76
  ...rest.sx,
@@ -26,12 +26,15 @@ import { translations } from '../libs/locales';
26
26
  import { UserInfo, UserBasicInfo, SwitchRole } from './user-info';
27
27
  import type { SessionContext as TSessionContext, User, UserCenterTab } from '../../@types';
28
28
  // @ts-ignore
29
- import { formatBlockletInfo, getLocalizedNavigation } from '../../blocklets';
29
+ import { formatBlockletInfo, getLink, getLocalizedNavigation } from '../../blocklets';
30
30
  import Passport from './passport';
31
31
  import Settings from './settings';
32
32
  import { client } from '../../libs/client';
33
33
  import useMobile from '../../hooks/use-mobile';
34
34
 
35
+ const profileLink = joinURL(PROFILE_URL, '/profile');
36
+ const settingsLink = joinURL(PROFILE_URL, '/settings');
37
+
35
38
  export default function UserCenter({
36
39
  children,
37
40
  notLoginContent = null,
@@ -155,7 +158,8 @@ export default function UserCenter({
155
158
  {
156
159
  label: t('common.profile'),
157
160
  protected: false,
158
- url: joinURL(PROFILE_URL, '/profile'),
161
+ value: profileLink,
162
+ url: getLink(profileLink, locale),
159
163
  },
160
164
  ];
161
165
  if (isMyself) {
@@ -163,11 +167,12 @@ export default function UserCenter({
163
167
  label: t('common.setting'),
164
168
  protected: true,
165
169
  isPrivate: true,
166
- url: joinURL(PROFILE_URL, '/settings'),
170
+ value: settingsLink,
171
+ url: getLink(settingsLink, locale),
167
172
  });
168
173
  }
169
174
  return tabs;
170
- }, [isMyself]);
175
+ }, [isMyself, locale]);
171
176
 
172
177
  const userCenterTabs = useCreation<UserCenterTab[]>(() => {
173
178
  const menus = formattedBlocklet?.navigation?.userCenter || [];
@@ -175,7 +180,7 @@ export default function UserCenter({
175
180
  const allMenus = localizedMenus.concat(defaultTabs);
176
181
  return allMenus
177
182
  .map((x: any) => {
178
- const value = x._rawLink ?? x.link ?? x.url;
183
+ const value = x.value ?? x._rawLink ?? x.link ?? x.url;
179
184
 
180
185
  return {
181
186
  value,
@@ -249,7 +254,13 @@ export default function UserCenter({
249
254
  },
250
255
  top: (theme) => (stickySidebar ? theme.spacing(3) : 'unset'),
251
256
  }}>
252
- <Box>
257
+ <Box
258
+ sx={{
259
+ width: {
260
+ sx: '100%',
261
+ md: 420,
262
+ },
263
+ }}>
253
264
  <Box display="flex" justifyContent="space-between">
254
265
  <Typography sx={{ fontWeight: 600, mb: 1.5 }}>{isMyself ? t('myInfo') : t('hisInfo')}</Typography>
255
266
  {isMyself ? <SwitchRole user={userState.data as User} switchPassport={session.switchPassport} /> : null}
@@ -364,6 +375,8 @@ export default function UserCenter({
364
375
  onChange={handleChangeTab}
365
376
  sx={{
366
377
  width: isMobile ? '100%' : 180,
378
+ marginBottom: isMobile ? '8px' : 0,
379
+ flexShrink: 0,
367
380
  '.MuiTabs-flexContainer': {
368
381
  gap: 1.5,
369
382
  '.MuiButtonBase-root': {
@@ -386,6 +399,7 @@ export default function UserCenter({
386
399
  display: 'flex',
387
400
  justifyContent: 'center',
388
401
  alignItems: 'center',
402
+ flex: 1,
389
403
  }}>
390
404
  <CircularProgress sx={{ color: colors.primary100 }} />
391
405
  </Box>
@@ -438,12 +452,8 @@ export default function UserCenter({
438
452
  }, [isMyself, currentActiveTab]);
439
453
 
440
454
  // TODO 过滤 !mySelf 是的URL跳转
441
- if (
442
- (!disableAutoRedirect && !currentTab && formattedBlocklet?.navigation?.userCenter?.length > 0) ||
443
- !currentActiveTab ||
444
- isPrivateActive
445
- ) {
446
- const firstUserCenterUrl = formattedBlocklet?.navigation?.userCenter[0]?.link;
455
+ if ((!disableAutoRedirect && !currentTab && userCenterTabs?.length > 0) || !currentActiveTab || isPrivateActive) {
456
+ const firstUserCenterUrl = userCenterTabs[0]?.url;
447
457
  const firstTab = userCenterTabs.find((x) => x.value === firstUserCenterUrl);
448
458
  if (firstUserCenterUrl && !firstTab?.isPrivate) {
449
459
  window.location.replace(
@@ -312,6 +312,9 @@ export default function UserSessions({
312
312
  whiteSpace: 'nowrap',
313
313
  fontWeight: 'bold',
314
314
  },
315
+ '.MuiTableCell-root': {
316
+ paddingRight: '16px',
317
+ },
315
318
  }}>
316
319
  {confirmHolder}
317
320
  <Datatable
package/src/blocklets.js CHANGED
@@ -20,6 +20,24 @@ export const formatTheme = (theme) => {
20
20
  return formatted;
21
21
  };
22
22
 
23
+ export const getLink = (link, locale = 'en') => {
24
+ if (typeof link === 'string') {
25
+ // http[s] 开头的 url
26
+ if (isUrl(link)) {
27
+ const url = new URL(link);
28
+ url.searchParams.set('locale', locale);
29
+ return url.href;
30
+ }
31
+ const url = new URL(link, window.location.origin);
32
+ url.searchParams.set('locale', locale);
33
+ return url.pathname + url.search;
34
+ }
35
+ if (typeof link === 'object') {
36
+ return link[locale] || link?.en || link?.zh;
37
+ }
38
+ return link;
39
+ };
40
+
23
41
  /**
24
42
  * 获取指定 locale 对应的 navigation 数据, 仅考虑 zh/en
25
43
  */
@@ -37,24 +55,7 @@ export const getLocalizedNavigation = (navigation, locale = 'en') => {
37
55
  }
38
56
  return title;
39
57
  };
40
- // eslint-disable-next-line no-shadow
41
- const getLink = (link, _locale) => {
42
- if (typeof link === 'string') {
43
- // http[s] 开头的 url
44
- if (isUrl(link)) {
45
- const url = new URL(link);
46
- url.searchParams.set('locale', _locale);
47
- return url.href;
48
- }
49
- const url = new URL(link, window.location.origin);
50
- url.searchParams.set('locale', _locale);
51
- return url.pathname + url.search;
52
- }
53
- if (typeof link === 'object') {
54
- return link[_locale] || link?.en || link?.zh;
55
- }
56
- return link;
57
- };
58
+
58
59
  return mapRecursive(
59
60
  navigation,
60
61
  (item) => {
@@ -27,7 +27,6 @@ export default function NotificationAddon({ session = {} }) {
27
27
  href={viewAllUrl}
28
28
  sx={{
29
29
  borderRadius: 2,
30
- color: 'rgba(0, 0, 0, 0.6)',
31
30
  borderColor: colors.lineBorderStrong,
32
31
  '&:hover': {
33
32
  borderRadius: '50%',
@@ -7,7 +7,7 @@ import bridge from '@arcblock/bridge';
7
7
  export const useWalletHiddenTopbar = () => {
8
8
  const browser = useBrowser();
9
9
  useEffect(() => {
10
- if (browser.wallet) {
10
+ if (browser.wallet || browser.arcSphere) {
11
11
  bridge.call('arcHideTopBar', '{}');
12
12
  }
13
13
  }, [browser]);