@arcblock/ux 3.1.43 → 3.1.45

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.
@@ -5,7 +5,7 @@ import { RequestAppInfo, CurrentAppInfo } from './auth-apps-info';
5
5
  /**
6
6
  * @example app/connect-to-did-space?appPid=zNKp8tdZUanWKnvhwZWvF2hKRutwM9ykLaY8&appDid=zNKp8tdZUanWKnvhwZWvF2hKRutwM9ykLaY8&appName=233&appDescription=456&appUrl=https://bbqaw5mgxc6fnihrwqcejcxvukkdgkk4anwxwk5msvm.did.abtnet.io/zh
7
7
  */
8
- export default function AuthApps({ session, requestAppInfo, currentAppInfo, children, userInfo, hideSwitchConnect, hideAuthorize, hideCancel, hideButton, notThisText, authorizeText, connectText, cancelText, useAnotherText, slotProps, onConnect, onAuthorize, onSwitchConnect, onCancel, ref, }: {
8
+ export default function AuthApps({ session, requestAppInfo, currentAppInfo, children, userInfo, hideSwitchConnect, hideAuthorize, hideCancel, hideButton, notThisText, authorizeText, connectText, cancelText, useAnotherText, slotProps, onConnect, onAuthorize, onSwitchConnect, onSwitchPassport, onCancel, ref, disableAuthorizeButton, }: {
9
9
  session: any;
10
10
  requestAppInfo: RequestAppInfo;
11
11
  currentAppInfo: CurrentAppInfo;
@@ -28,8 +28,10 @@ export default function AuthApps({ session, requestAppInfo, currentAppInfo, chil
28
28
  onConnect?: (done: () => void) => void;
29
29
  onAuthorize?: (done: () => void) => void;
30
30
  onSwitchConnect?: (done: () => void) => void;
31
+ onSwitchPassport?: (done: () => void) => void;
31
32
  onCancel?: () => void;
32
33
  ref: Ref<{
33
34
  closeLoading: () => void;
34
35
  }>;
36
+ disableAuthorizeButton?: boolean;
35
37
  }): import("react/jsx-runtime").JSX.Element;
@@ -1,18 +1,19 @@
1
- import { jsx as e, jsxs as o, Fragment as m } from "react/jsx-runtime";
2
- import { CircularProgress as u, Box as l, Stack as q, Button as h, Typography as E, Link as G } from "@mui/material";
3
- import { useReactive as J, useMemoizedFn as i } from "ahooks";
1
+ import { jsx as e, jsxs as o, Fragment as p } from "react/jsx-runtime";
2
+ import { CircularProgress as u, Box as d, Stack as G, Button as h, Typography as J, Link as K } from "@mui/material";
3
+ import { useReactive as O, useMemoizedFn as r } from "ahooks";
4
4
  import c from "lodash/noop";
5
- import { useImperativeHandle as K } from "react";
6
- import O from "../did-connect-container.js";
7
- import Q from "./auth-apps-info.js";
8
- import V from "../../Center/index.js";
9
- import X from "../landing-page.js";
10
- import { translate as Y } from "../../Locale/util.js";
11
- import { useLocaleContext as Z } from "../../Locale/context.js";
12
- import _ from "../../UserCard/index.js";
13
- import { InfoType as $, CardType as P } from "../../UserCard/types.js";
14
- import { mergeSx as p } from "../../Util/style.js";
15
- const ee = {
5
+ import { useImperativeHandle as Q } from "react";
6
+ import V from "../did-connect-container.js";
7
+ import X from "./auth-apps-info.js";
8
+ import Y from "../../Center/index.js";
9
+ import Z from "../landing-page.js";
10
+ import { translate as _ } from "../../Locale/util.js";
11
+ import { useLocaleContext as $ } from "../../Locale/context.js";
12
+ import ee from "../../UserCard/index.js";
13
+ import { InfoType as ne, CardType as oe } from "../../UserCard/types.js";
14
+ import { mergeSx as f } from "../../Util/style.js";
15
+ import re from "./switch-role.js";
16
+ const ie = {
16
17
  en: {
17
18
  notThis: "Not you?",
18
19
  useAnother: "Use another account",
@@ -28,62 +29,66 @@ const ee = {
28
29
  cancel: "取消"
29
30
  }
30
31
  };
31
- function fe({
32
+ function ye({
32
33
  session: s,
33
- requestAppInfo: f,
34
- currentAppInfo: g,
35
- children: x = null,
36
- userInfo: C = void 0,
37
- hideSwitchConnect: v = !1,
38
- hideAuthorize: y = !1,
39
- hideCancel: z = !1,
34
+ requestAppInfo: g,
35
+ currentAppInfo: x,
36
+ children: C = null,
37
+ userInfo: v = void 0,
38
+ hideSwitchConnect: y = !1,
39
+ hideAuthorize: z = !1,
40
+ hideCancel: w = !1,
40
41
  hideButton: A = !1,
41
- notThisText: b = void 0,
42
- authorizeText: k = void 0,
43
- connectText: T = void 0,
44
- cancelText: w = void 0,
42
+ notThisText: T = void 0,
43
+ authorizeText: b = void 0,
44
+ connectText: k = void 0,
45
+ cancelText: S = void 0,
45
46
  useAnotherText: D = void 0,
46
- slotProps: r = void 0,
47
+ slotProps: i = void 0,
47
48
  onConnect: I = c,
48
49
  onAuthorize: L = c,
49
- onSwitchConnect: S = c,
50
- onCancel: W = c,
51
- ref: j
50
+ onSwitchConnect: R = c,
51
+ onSwitchPassport: W = c,
52
+ onCancel: j = c,
53
+ ref: B,
54
+ disableAuthorizeButton: m = !1
52
55
  }) {
53
- const n = J({
56
+ const n = O({
54
57
  loading: !1
55
- }), { locale: B = "en" } = Z() || {}, t = i((H, N = {}) => Y(ee, H, B, "en", N)), a = i(() => {
58
+ }), { locale: F = "en" } = $() || {}, t = r((q, E = {}) => _(ie, q, F, "en", E)), l = r(() => {
56
59
  n.loading = !1;
57
- }), F = i(() => {
58
- n.loading = !0, I?.(a);
59
- }), M = i(() => {
60
- n.loading = !0, S?.(a);
61
- }), R = i(() => {
62
- n.loading = !0, L?.(a);
63
- }), U = i(() => {
64
- W?.();
60
+ }), M = r(() => {
61
+ n.loading = !0, I?.(l);
62
+ }), U = r(() => {
63
+ n.loading = !0, R?.(l);
64
+ }), H = r(() => {
65
+ n.loading = !0, L?.(l);
66
+ }), N = r(() => {
67
+ n.loading = !0, W?.(l);
68
+ }), P = r(() => {
69
+ j?.();
65
70
  });
66
- if (K(j, () => ({
67
- closeLoading: a
71
+ if (Q(B, () => ({
72
+ closeLoading: l
68
73
  })), s.loading || !s.initialized)
69
- return /* @__PURE__ */ e(V, { children: /* @__PURE__ */ e(u, {}) });
70
- const d = C ?? s?.user;
71
- return /* @__PURE__ */ e(X, { did: window.blocklet?.appPid, standalone: !0, children: /* @__PURE__ */ e(
72
- l,
74
+ return /* @__PURE__ */ e(Y, { children: /* @__PURE__ */ e(u, {}) });
75
+ const a = v ?? s?.user;
76
+ return /* @__PURE__ */ e(Z, { did: window.blocklet?.appPid, standalone: !0, children: /* @__PURE__ */ e(
77
+ d,
73
78
  {
74
- ...r?.root,
75
- sx: p(
79
+ ...i?.root,
80
+ sx: f(
76
81
  {
77
82
  width: 420,
78
83
  maxWidth: "100%"
79
84
  },
80
- r?.root?.sx
85
+ i?.root?.sx
81
86
  ),
82
- children: /* @__PURE__ */ e(O, { hideCloseButton: !0, ...r?.didConnectContainer, children: /* @__PURE__ */ o(
83
- l,
87
+ children: /* @__PURE__ */ e(V, { hideCloseButton: !0, ...i?.didConnectContainer, children: /* @__PURE__ */ o(
88
+ d,
84
89
  {
85
- ...r?.contentContainer,
86
- sx: p(
90
+ ...i?.contentContainer,
91
+ sx: f(
87
92
  {
88
93
  display: "flex",
89
94
  flexDirection: "column",
@@ -99,18 +104,27 @@ function fe({
99
104
  },
100
105
  bgcolor: "background.paper"
101
106
  },
102
- r?.contentContainer?.sx
107
+ i?.contentContainer?.sx
103
108
  ),
104
109
  children: [
105
- /* @__PURE__ */ e(Q, { requestAppInfo: f, currentAppInfo: g }),
106
- d ? /* @__PURE__ */ o(m, { children: [
107
- /* @__PURE__ */ e(_, { user: d, showDid: !0, cardType: P.Detailed, infoType: $.Minimal }),
108
- /* @__PURE__ */ e(l, {})
110
+ /* @__PURE__ */ e(X, { requestAppInfo: g, currentAppInfo: x }),
111
+ a ? /* @__PURE__ */ o(p, { children: [
112
+ /* @__PURE__ */ e(
113
+ ee,
114
+ {
115
+ user: a,
116
+ showDid: !0,
117
+ cardType: oe.Detailed,
118
+ infoType: ne.Minimal,
119
+ renderTopRightContent: () => /* @__PURE__ */ e(re, { user: a, switchPassport: N })
120
+ }
121
+ ),
122
+ /* @__PURE__ */ e(d, {})
109
123
  ] }) : null,
110
- x,
111
- A ? null : /* @__PURE__ */ o(m, { children: [
124
+ C,
125
+ A ? null : /* @__PURE__ */ o(p, { children: [
112
126
  /* @__PURE__ */ e(
113
- l,
127
+ d,
114
128
  {
115
129
  sx: {
116
130
  border: "1px solid",
@@ -121,32 +135,32 @@ function fe({
121
135
  }
122
136
  }
123
137
  ),
124
- /* @__PURE__ */ o(q, { direction: "row", spacing: 2, children: [
125
- z ? null : /* @__PURE__ */ e(
138
+ /* @__PURE__ */ o(G, { direction: "row", spacing: 2, children: [
139
+ w ? null : /* @__PURE__ */ e(
126
140
  h,
127
141
  {
128
142
  color: "inherit",
129
143
  variant: "outlined",
130
144
  size: "large",
131
145
  fullWidth: !0,
132
- onClick: U,
146
+ onClick: P,
133
147
  sx: {
134
148
  color: "grey.500"
135
149
  },
136
- children: w || t("cancel")
150
+ children: S || t("cancel")
137
151
  }
138
152
  ),
139
- d && !y ? /* @__PURE__ */ o(
153
+ a && !z ? /* @__PURE__ */ o(
140
154
  h,
141
155
  {
142
156
  variant: "contained",
143
157
  size: "large",
144
158
  fullWidth: !0,
145
- onClick: R,
146
- disabled: n.loading,
159
+ onClick: H,
160
+ disabled: n.loading || m,
147
161
  children: [
148
162
  n.loading ? /* @__PURE__ */ e(u, { size: 20, sx: { mr: 1 } }) : null,
149
- k || t("authorize")
163
+ b || t("authorize")
150
164
  ]
151
165
  }
152
166
  ) : /* @__PURE__ */ o(
@@ -155,18 +169,18 @@ function fe({
155
169
  variant: "contained",
156
170
  size: "large",
157
171
  fullWidth: !0,
158
- disabled: n.loading,
159
- onClick: F,
172
+ disabled: n.loading || m,
173
+ onClick: M,
160
174
  children: [
161
175
  n.loading ? /* @__PURE__ */ e(u, { size: 20, sx: { mr: 1 } }) : null,
162
- T || t("connect")
176
+ k || t("connect")
163
177
  ]
164
178
  }
165
179
  )
166
180
  ] })
167
181
  ] }),
168
- v || !d ? null : /* @__PURE__ */ e(l, { sx: { textAlign: "center" }, children: /* @__PURE__ */ o(
169
- E,
182
+ y || !a ? null : /* @__PURE__ */ e(d, { sx: { textAlign: "center" }, children: /* @__PURE__ */ o(
183
+ J,
170
184
  {
171
185
  variant: "body2",
172
186
  sx: {
@@ -176,13 +190,13 @@ function fe({
176
190
  gap: 1
177
191
  },
178
192
  children: [
179
- b || t("notThis"),
193
+ T || t("notThis"),
180
194
  " ",
181
195
  /* @__PURE__ */ e(
182
- G,
196
+ K,
183
197
  {
184
198
  underline: "hover",
185
- onClick: M,
199
+ onClick: U,
186
200
  sx: {
187
201
  cursor: "pointer"
188
202
  },
@@ -199,5 +213,5 @@ function fe({
199
213
  ) });
200
214
  }
201
215
  export {
202
- fe as default
216
+ ye as default
203
217
  };
@@ -0,0 +1,13 @@
1
+ import { UserPublicInfo } from '@blocklet/js-sdk';
2
+ declare function SwitchRole({ user, switchPassport, }: {
3
+ user: UserPublicInfo & {
4
+ passports: {
5
+ name: string;
6
+ title: string;
7
+ role: string;
8
+ }[];
9
+ };
10
+ switchPassport: () => void;
11
+ }): import("react/jsx-runtime").JSX.Element;
12
+ declare const _default: import('react').MemoExoticComponent<typeof SwitchRole>;
13
+ export default _default;
@@ -0,0 +1,45 @@
1
+ import { jsx as t } from "react/jsx-runtime";
2
+ import { memo as n } from "react";
3
+ import { Chip as i } from "@mui/material";
4
+ import { Icon as a } from "@iconify/react";
5
+ import p from "@iconify-icons/material-symbols/swap-horiz-rounded";
6
+ import { useCreation as c } from "ahooks";
7
+ function m({
8
+ user: o,
9
+ switchPassport: r
10
+ }) {
11
+ const l = c(
12
+ () => (o?.passports || [])?.find((e) => e.name === o.role || e.role === o.role),
13
+ [o?.passports, o?.role]
14
+ );
15
+ return /* @__PURE__ */ t(
16
+ i,
17
+ {
18
+ label: l?.title || o?.role || "Guest",
19
+ size: "small",
20
+ variant: "outlined",
21
+ sx: {
22
+ flexShrink: 0,
23
+ fontWeight: "bold",
24
+ fontSize: "12px",
25
+ color: "text.primary",
26
+ borderColor: "grey.100",
27
+ backgroundColor: "transparent",
28
+ textTransform: "capitalize",
29
+ pr: 1,
30
+ pl: 0.5,
31
+ "&:active": {
32
+ boxShadow: "none"
33
+ }
34
+ },
35
+ clickable: !0,
36
+ deleteIcon: /* @__PURE__ */ t(a, { icon: p, color: "inherit" }),
37
+ onDelete: r,
38
+ onClick: r
39
+ }
40
+ );
41
+ }
42
+ const S = n(m);
43
+ export {
44
+ S as default
45
+ };
@@ -87,7 +87,7 @@ function A({ ...s }) {
87
87
  ) : null
88
88
  ] })
89
89
  ] }),
90
- i && (l || o.showSocialActions) ? /* @__PURE__ */ t(C, { sx: { width: "100%" } }) : null,
90
+ i && !l && o.showSocialActions ? /* @__PURE__ */ t(C, { sx: { width: "100%" } }) : null,
91
91
  l ? null : /* @__PURE__ */ t(
92
92
  j,
93
93
  {
@@ -1,4 +1,4 @@
1
- const e = "3.1.43", s = { "@blocklet/js-sdk": "^1.16.49-beta-20250823-082650-626c1473" }, t = {
1
+ const e = "3.1.45", s = { "@blocklet/js-sdk": "^1.16.49-beta-20250823-082650-626c1473" }, t = {
2
2
  version: e,
3
3
  dependencies: s
4
4
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/ux",
3
- "version": "3.1.43",
3
+ "version": "3.1.45",
4
4
  "description": "Common used react components for arcblock products",
5
5
  "keywords": [
6
6
  "react",
@@ -68,16 +68,16 @@
68
68
  "react": "^19.0.0",
69
69
  "react-router-dom": "^6.22.3"
70
70
  },
71
- "gitHead": "f8ee8cbf1c349c55a31ed833de014f4db6222976",
71
+ "gitHead": "6706a870c69720bc0beae69a2c380247d4d0efaa",
72
72
  "dependencies": {
73
- "@arcblock/bridge": "3.1.43",
73
+ "@arcblock/bridge": "3.1.45",
74
74
  "@arcblock/did": "^1.21.3",
75
75
  "@arcblock/did-motif": "^1.1.14",
76
- "@arcblock/icons": "3.1.43",
77
- "@arcblock/nft-display": "3.1.43",
78
- "@arcblock/react-hooks": "3.1.43",
76
+ "@arcblock/icons": "3.1.45",
77
+ "@arcblock/nft-display": "3.1.45",
78
+ "@arcblock/react-hooks": "3.1.45",
79
79
  "@blocklet/js-sdk": "^1.16.49-beta-20250823-082650-626c1473",
80
- "@blocklet/theme": "3.1.43",
80
+ "@blocklet/theme": "3.1.45",
81
81
  "@fontsource/roboto": "~5.1.1",
82
82
  "@fontsource/ubuntu-mono": "^5.2.6",
83
83
  "@iconify-icons/logos": "^1.2.36",
@@ -13,6 +13,7 @@ import { useLocaleContext } from '../../Locale/context';
13
13
  import UserCard from '../../UserCard';
14
14
  import { CardType, InfoType } from '../../UserCard/types';
15
15
  import { mergeSx } from '../../Util/style';
16
+ import SwitchRole from './switch-role';
16
17
 
17
18
  const translations = {
18
19
  en: {
@@ -57,8 +58,11 @@ export default function AuthApps({
57
58
  onConnect = noop,
58
59
  onAuthorize = noop,
59
60
  onSwitchConnect = noop,
61
+ onSwitchPassport = noop,
60
62
  onCancel = noop,
61
63
  ref,
64
+
65
+ disableAuthorizeButton = false,
62
66
  }: {
63
67
  session: any;
64
68
  requestAppInfo: RequestAppInfo;
@@ -86,8 +90,11 @@ export default function AuthApps({
86
90
  onConnect?: (done: () => void) => void;
87
91
  onAuthorize?: (done: () => void) => void;
88
92
  onSwitchConnect?: (done: () => void) => void;
93
+ onSwitchPassport?: (done: () => void) => void;
89
94
  onCancel?: () => void;
90
95
  ref: Ref<{ closeLoading: () => void }>;
96
+
97
+ disableAuthorizeButton?: boolean;
91
98
  }) {
92
99
  const currentState = useReactive({
93
100
  loading: false,
@@ -111,6 +118,10 @@ export default function AuthApps({
111
118
  currentState.loading = true;
112
119
  onAuthorize?.(handleCloseLoading);
113
120
  });
121
+ const handleSwitchPassport = useMemoizedFn(() => {
122
+ currentState.loading = true;
123
+ onSwitchPassport?.(handleCloseLoading);
124
+ });
114
125
  const handleCancel = useMemoizedFn(() => {
115
126
  onCancel?.();
116
127
  });
@@ -165,7 +176,13 @@ export default function AuthApps({
165
176
 
166
177
  {user ? (
167
178
  <>
168
- <UserCard user={user} showDid cardType={CardType.Detailed} infoType={InfoType.Minimal} />
179
+ <UserCard
180
+ user={user}
181
+ showDid
182
+ cardType={CardType.Detailed}
183
+ infoType={InfoType.Minimal}
184
+ renderTopRightContent={() => <SwitchRole user={user} switchPassport={handleSwitchPassport} />}
185
+ />
169
186
  <Box />
170
187
  </>
171
188
  ) : null}
@@ -204,7 +221,7 @@ export default function AuthApps({
204
221
  size="large"
205
222
  fullWidth
206
223
  onClick={handleAuthorize}
207
- disabled={currentState.loading}>
224
+ disabled={currentState.loading || disableAuthorizeButton}>
208
225
  {currentState.loading ? <CircularProgress size={20} sx={{ mr: 1 }} /> : null}
209
226
  {authorizeText || t('authorize')}
210
227
  </Button>
@@ -213,7 +230,7 @@ export default function AuthApps({
213
230
  variant="contained"
214
231
  size="large"
215
232
  fullWidth
216
- disabled={currentState.loading}
233
+ disabled={currentState.loading || disableAuthorizeButton}
217
234
  onClick={handleConnect}>
218
235
  {currentState.loading ? <CircularProgress size={20} sx={{ mr: 1 }} /> : null}
219
236
  {connectText || t('connect')}
@@ -0,0 +1,47 @@
1
+ import { memo } from 'react';
2
+ import { Chip } from '@mui/material';
3
+ import { Icon } from '@iconify/react';
4
+ import SwapHorizRoundedIcon from '@iconify-icons/material-symbols/swap-horiz-rounded';
5
+ import { useCreation } from 'ahooks';
6
+ import type { UserPublicInfo } from '@blocklet/js-sdk';
7
+
8
+ function SwitchRole({
9
+ user,
10
+ switchPassport,
11
+ }: {
12
+ user: UserPublicInfo & { passports: { name: string; title: string; role: string }[] };
13
+ switchPassport: () => void;
14
+ }) {
15
+ const currentRole = useCreation(
16
+ () => (user?.passports || [])?.find((item) => item.name === user.role || item.role === user.role),
17
+ [user?.passports, user?.role]
18
+ );
19
+
20
+ return (
21
+ <Chip
22
+ label={currentRole?.title || user?.role || 'Guest'}
23
+ size="small"
24
+ variant="outlined"
25
+ sx={{
26
+ flexShrink: 0,
27
+ fontWeight: 'bold',
28
+ fontSize: '12px',
29
+ color: 'text.primary',
30
+ borderColor: 'grey.100',
31
+ backgroundColor: 'transparent',
32
+ textTransform: 'capitalize',
33
+ pr: 1,
34
+ pl: 0.5,
35
+ '&:active': {
36
+ boxShadow: 'none',
37
+ },
38
+ }}
39
+ clickable
40
+ deleteIcon={<Icon icon={SwapHorizRoundedIcon} color="inherit" />}
41
+ onDelete={switchPassport}
42
+ onClick={switchPassport}
43
+ />
44
+ );
45
+ }
46
+
47
+ export default memo(SwitchRole);
@@ -93,7 +93,7 @@ function MinimalContent({ ...props }: MinimalContentProps) {
93
93
  ) : null}
94
94
  </Box>
95
95
  </Box>
96
- {isSmallScreen && (renderTopRightContent || rest.showSocialActions) ? <Divider sx={{ width: '100%' }} /> : null}
96
+ {isSmallScreen && !renderTopRightContent && rest.showSocialActions ? <Divider sx={{ width: '100%' }} /> : null}
97
97
  {!renderTopRightContent ? (
98
98
  <SocialActions
99
99
  onFollowClick={rest.onFollowClick}