@arcblock/ux 2.7.16 → 2.7.18
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.
- package/es/SessionManager/account-item.js +5 -4
- package/es/SessionManager/add-account-item.js +13 -31
- package/es/SessionManager/federated-login-detecter.js +32 -26
- package/es/SessionManager/index.js +44 -57
- package/es/SessionManager/manage-accounts.js +30 -17
- package/es/SessionManager/manage-blocklet.js +12 -4
- package/es/SessionManager/menu-accordion.js +14 -5
- package/es/SessionManager/translation.js +10 -10
- package/es/SessionManager/use-config.js +34 -0
- package/es/SessionManager/user-info.js +51 -43
- package/es/SessionManager/user-popper.js +1 -18
- package/es/Typography/index.js +89 -0
- package/es/Util/federated.js +65 -0
- package/lib/SessionManager/account-item.js +5 -4
- package/lib/SessionManager/add-account-item.js +14 -32
- package/lib/SessionManager/federated-login-detecter.js +33 -26
- package/lib/SessionManager/index.js +45 -58
- package/lib/SessionManager/manage-accounts.js +29 -16
- package/lib/SessionManager/manage-blocklet.js +12 -4
- package/lib/SessionManager/menu-accordion.js +14 -5
- package/lib/SessionManager/translation.js +10 -10
- package/lib/SessionManager/use-config.js +41 -0
- package/lib/SessionManager/user-info.js +50 -42
- package/lib/SessionManager/user-popper.js +1 -6
- package/lib/Typography/index.js +100 -0
- package/lib/Util/federated.js +85 -0
- package/package.json +11 -7
- package/src/SessionManager/account-item.jsx +6 -8
- package/src/SessionManager/add-account-item.jsx +12 -30
- package/src/SessionManager/federated-login-detecter.jsx +39 -26
- package/src/SessionManager/index.jsx +48 -68
- package/src/SessionManager/manage-accounts.jsx +27 -13
- package/src/SessionManager/manage-blocklet.jsx +8 -2
- package/src/SessionManager/menu-accordion.jsx +10 -3
- package/src/SessionManager/translation.js +10 -10
- package/src/SessionManager/use-config.js +33 -0
- package/src/SessionManager/user-info.jsx +34 -34
- package/src/SessionManager/user-popper.jsx +1 -16
- package/src/Typography/index.jsx +79 -0
- package/src/Util/federated.js +73 -0
- package/es/SessionManager/use-accounts.js +0 -19
- package/lib/SessionManager/use-accounts.js +0 -25
- package/src/SessionManager/use-accounts.js +0 -18
@@ -8,9 +8,8 @@ var _react = require("react");
|
|
8
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
9
9
|
var _material = require("@mui/material");
|
10
10
|
var _Account = _interopRequireDefault(require("@arcblock/icons/lib/Account"));
|
11
|
-
var _Disconnect = _interopRequireDefault(require("@arcblock/icons/lib/Disconnect"));
|
12
11
|
var _noop = _interopRequireDefault(require("lodash/noop"));
|
13
|
-
var
|
12
|
+
var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
|
14
13
|
var _ahooks = require("ahooks");
|
15
14
|
var _Avatar = _interopRequireDefault(require("../Avatar"));
|
16
15
|
var _Util = require("../Util");
|
@@ -22,9 +21,10 @@ var _manageAccounts = _interopRequireDefault(require("./manage-accounts"));
|
|
22
21
|
var _manageBlocklet = _interopRequireDefault(require("./manage-blocklet"));
|
23
22
|
var _translation = require("./translation");
|
24
23
|
var _utils = require("./utils");
|
25
|
-
var
|
24
|
+
var _useConfig = _interopRequireDefault(require("./use-config"));
|
25
|
+
var _federated = require("../Util/federated");
|
26
26
|
var _jsxRuntime = require("react/jsx-runtime");
|
27
|
-
const _excluded = ["session", "locale", "showText", "showRole", "switchDid", "switchProfile", "switchPassport", "disableLogout", "onLogin", "onLogout", "onSwitchDid", "onSwitchProfile", "onSwitchPassport", "onBindWallet", "menu", "menuRender", "dark", "size"];
|
27
|
+
const _excluded = ["session", "locale", "showText", "showRole", "switchDid", "switchProfile", "switchPassport", "disableLogout", "onLogin", "onLogout", "onSwitchDid", "onSwitchProfile", "onSwitchPassport", "onBindWallet", "menu", "menuRender", "dark", "size", "showManageBlocklet"];
|
28
28
|
/* eslint-disable react/prop-types */
|
29
29
|
/* eslint-disable react/jsx-no-bind */
|
30
30
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
@@ -55,13 +55,16 @@ function SessionManager(_ref) {
|
|
55
55
|
menu,
|
56
56
|
menuRender,
|
57
57
|
dark,
|
58
|
-
size
|
58
|
+
size,
|
59
|
+
showManageBlocklet
|
59
60
|
} = _ref,
|
60
61
|
rest = _objectWithoutProperties(_ref, _excluded);
|
61
62
|
const latestSession = (0, _ahooks.useLatest)(session);
|
62
63
|
const {
|
63
|
-
connectAccount
|
64
|
-
|
64
|
+
connectAccount,
|
65
|
+
config,
|
66
|
+
setConfig
|
67
|
+
} = (0, _useConfig.default)();
|
65
68
|
const t = (0, _ahooks.useMemoizedFn)(function (key) {
|
66
69
|
let data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
67
70
|
return (0, _util.translate)(_translation.translations, key, locale, 'en', data);
|
@@ -80,8 +83,6 @@ function SessionManager(_ref) {
|
|
80
83
|
const isFirstLoading = (0, _react.useMemo)(() => {
|
81
84
|
return (session === null || session === void 0 ? void 0 : session.initialized) === false && (session === null || session === void 0 ? void 0 : session.loading) === true;
|
82
85
|
}, [session === null || session === void 0 ? void 0 : session.initialized, session === null || session === void 0 ? void 0 : session.loading]);
|
83
|
-
|
84
|
-
// const federatedAccount = connectedAccounts.find((item) => item.provider === 'federated');
|
85
86
|
let hasBindWallet = false;
|
86
87
|
let hasBindAccount = false;
|
87
88
|
if (isRawWalletAccount) {
|
@@ -94,7 +95,7 @@ function SessionManager(_ref) {
|
|
94
95
|
hasBindWallet = true;
|
95
96
|
}
|
96
97
|
const _connectAccount = (0, _ahooks.useMemoizedFn)(async () => {
|
97
|
-
var _latestSession$curren, _window
|
98
|
+
var _latestSession$curren, _window;
|
98
99
|
// HACK: 强制等待组件渲染一轮,以拿到最新的 session 值
|
99
100
|
await (0, _Util.sleep)();
|
100
101
|
if (!((_latestSession$curren = latestSession.current) !== null && _latestSession$curren !== void 0 && _latestSession$curren.user)) {
|
@@ -104,36 +105,17 @@ function SessionManager(_ref) {
|
|
104
105
|
return;
|
105
106
|
}
|
106
107
|
const blocklet = (_window = window) === null || _window === void 0 ? void 0 : _window.blocklet;
|
107
|
-
|
108
|
-
|
108
|
+
const currentApp = (0, _federated.getCurrentApp)(blocklet);
|
109
|
+
const masterApp = (0, _federated.getFederatedApp)(blocklet);
|
110
|
+
const targetApp = latestSession.current.user.sourceAppPid ? masterApp : currentApp;
|
111
|
+
if (targetApp) {
|
112
|
+
const loginAccount = _objectSpread({
|
113
|
+
did: latestSession.current.user.did,
|
114
|
+
avatar: latestSession.current.user.avatar,
|
115
|
+
provider: latestSession.current.provider
|
116
|
+
}, targetApp);
|
117
|
+
connectAccount(loginAccount);
|
109
118
|
}
|
110
|
-
const currentApp = {
|
111
|
-
appId: blocklet.appId,
|
112
|
-
appPid: blocklet.appPid,
|
113
|
-
appName: blocklet.appName,
|
114
|
-
appDescription: blocklet.appDescription,
|
115
|
-
appLogo: blocklet.appLogo,
|
116
|
-
appUrl: blocklet.appUrl,
|
117
|
-
version: blocklet.version,
|
118
|
-
provider: 'wallet'
|
119
|
-
};
|
120
|
-
const federatedMaster = (_blocklet$settings = blocklet.settings) === null || _blocklet$settings === void 0 ? void 0 : (_blocklet$settings$fe = _blocklet$settings.federated) === null || _blocklet$settings$fe === void 0 ? void 0 : _blocklet$settings$fe.master;
|
121
|
-
const masterApp = (0, _isEmpty.default)(federatedMaster) ? null : {
|
122
|
-
appId: federatedMaster.appId,
|
123
|
-
appName: federatedMaster.appName,
|
124
|
-
appDescription: federatedMaster.appDescription,
|
125
|
-
appLogo: federatedMaster.appLogo,
|
126
|
-
appPid: federatedMaster.appPid,
|
127
|
-
appUrl: federatedMaster.appUrl,
|
128
|
-
version: federatedMaster.version,
|
129
|
-
provider: 'federated'
|
130
|
-
};
|
131
|
-
const loginAccount = _objectSpread({
|
132
|
-
did: latestSession.current.user.did,
|
133
|
-
avatar: latestSession.current.user.avatar,
|
134
|
-
provider: latestSession.current.provider
|
135
|
-
}, latestSession.current.provider === 'federated' ? masterApp : currentApp);
|
136
|
-
connectAccount(loginAccount);
|
137
119
|
});
|
138
120
|
|
139
121
|
// HACK: 用于处理 统一登录 的自动登录情况,添加一个已连接的账号
|
@@ -255,7 +237,7 @@ function SessionManager(_ref) {
|
|
255
237
|
user,
|
256
238
|
provider
|
257
239
|
} = session;
|
258
|
-
if (
|
240
|
+
if (['auth0'].includes(provider)) {
|
259
241
|
switchOAuthPassport(user);
|
260
242
|
} else {
|
261
243
|
close();
|
@@ -297,7 +279,7 @@ function SessionManager(_ref) {
|
|
297
279
|
session: session,
|
298
280
|
size: size,
|
299
281
|
locale: locale,
|
300
|
-
|
282
|
+
onSwitchProfile: () => {
|
301
283
|
close();
|
302
284
|
_onSwitchProfile();
|
303
285
|
},
|
@@ -315,22 +297,25 @@ function SessionManager(_ref) {
|
|
315
297
|
onSwitchDid: onSwitchDid,
|
316
298
|
connectAccount: _connectAccount,
|
317
299
|
close: close,
|
318
|
-
hasBindAccount: hasBindAccount
|
319
|
-
|
300
|
+
hasBindAccount: hasBindAccount,
|
301
|
+
onLogout: _onLogout,
|
302
|
+
expanded: config.expandAccount,
|
303
|
+
onExpand: value => {
|
304
|
+
const cloneConfig = (0, _cloneDeep.default)(config);
|
305
|
+
cloneConfig.expandAccount = value;
|
306
|
+
setConfig(cloneConfig);
|
307
|
+
}
|
308
|
+
}), showManageBlocklet ? [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Divider, {}, "divider"), /*#__PURE__*/(0, _jsxRuntime.jsx)(_manageBlocklet.default, {
|
320
309
|
menu: menu,
|
321
310
|
menuRender: menuRender,
|
322
|
-
locale: locale
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
component: _Disconnect.default,
|
331
|
-
className: "session-manager-menu-icon"
|
332
|
-
}), t('disconnect')]
|
333
|
-
})]
|
311
|
+
locale: locale,
|
312
|
+
expanded: config.expandBlocklet,
|
313
|
+
onExpand: value => {
|
314
|
+
const cloneConfig = (0, _cloneDeep.default)(config);
|
315
|
+
cloneConfig.expandBlocklet = value;
|
316
|
+
setConfig(cloneConfig);
|
317
|
+
}
|
318
|
+
}, "manageBlocklet")] : null]
|
334
319
|
})
|
335
320
|
})]
|
336
321
|
});
|
@@ -338,7 +323,7 @@ function SessionManager(_ref) {
|
|
338
323
|
SessionManager.propTypes = {
|
339
324
|
session: _propTypes.default.shape({
|
340
325
|
federatedMaster: _propTypes.default.object,
|
341
|
-
provider: _propTypes.default.oneOf(['wallet', '
|
326
|
+
provider: _propTypes.default.oneOf(['wallet', 'auth0', '']),
|
342
327
|
user: _propTypes.default.shape({
|
343
328
|
did: _propTypes.default.string.isRequired,
|
344
329
|
role: _propTypes.default.string.isRequired,
|
@@ -382,7 +367,8 @@ SessionManager.propTypes = {
|
|
382
367
|
menu: _propTypes.default.array,
|
383
368
|
menuRender: _propTypes.default.func,
|
384
369
|
dark: _propTypes.default.bool,
|
385
|
-
size: _propTypes.default.number
|
370
|
+
size: _propTypes.default.number,
|
371
|
+
showManageBlocklet: _propTypes.default.bool
|
386
372
|
};
|
387
373
|
SessionManager.defaultProps = {
|
388
374
|
locale: 'en',
|
@@ -401,7 +387,8 @@ SessionManager.defaultProps = {
|
|
401
387
|
onSwitchPassport: _noop.default,
|
402
388
|
onBindWallet: _noop.default,
|
403
389
|
dark: false,
|
404
|
-
size: 24
|
390
|
+
size: 24,
|
391
|
+
showManageBlocklet: true
|
405
392
|
};
|
406
393
|
var _default = SessionManager;
|
407
394
|
exports.default = _default;
|
@@ -9,6 +9,7 @@ var _material = require("@mui/material");
|
|
9
9
|
var _react = require("@iconify/react");
|
10
10
|
var _Account = _interopRequireDefault(require("@arcblock/icons/lib/Account"));
|
11
11
|
var _link = _interopRequireDefault(require("@iconify-icons/mdi/link"));
|
12
|
+
var _Disconnect = _interopRequireDefault(require("@arcblock/icons/lib/Disconnect"));
|
12
13
|
var _accountItem = _interopRequireDefault(require("./account-item"));
|
13
14
|
var _menuAccordion = _interopRequireDefault(require("./menu-accordion"));
|
14
15
|
var _translation = require("./translation");
|
@@ -16,7 +17,7 @@ var _util = require("../Locale/util");
|
|
16
17
|
var _confirm = require("../Dialog/confirm");
|
17
18
|
var _utils = require("./utils");
|
18
19
|
var _addAccountItem = _interopRequireDefault(require("./add-account-item"));
|
19
|
-
var
|
20
|
+
var _useConfig = _interopRequireDefault(require("./use-config"));
|
20
21
|
var _jsxRuntime = require("react/jsx-runtime");
|
21
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
22
23
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
@@ -32,7 +33,11 @@ function ManageAccounts(_ref) {
|
|
32
33
|
onSwitchDid,
|
33
34
|
connectAccount,
|
34
35
|
close,
|
35
|
-
hasBindAccount
|
36
|
+
hasBindAccount,
|
37
|
+
disableLogout,
|
38
|
+
onLogout,
|
39
|
+
expanded,
|
40
|
+
onExpand
|
36
41
|
} = _ref;
|
37
42
|
const {
|
38
43
|
bindOAuth,
|
@@ -47,9 +52,9 @@ function ManageAccounts(_ref) {
|
|
47
52
|
confirmHolder
|
48
53
|
} = (0, _confirm.useConfirm)();
|
49
54
|
const {
|
50
|
-
|
51
|
-
|
52
|
-
} = (0,
|
55
|
+
deleteAccount,
|
56
|
+
config
|
57
|
+
} = (0, _useConfig.default)();
|
53
58
|
const update = (0, _ahooks.useUpdate)();
|
54
59
|
const onChoose = (0, _ahooks.useMemoizedFn)((account, _ref2) => {
|
55
60
|
let {
|
@@ -64,7 +69,7 @@ function ManageAccounts(_ref) {
|
|
64
69
|
onSwitchDid(...arguments);
|
65
70
|
}, {
|
66
71
|
provider: account.provider,
|
67
|
-
|
72
|
+
sourceAppPid: account.sourceAppPid
|
68
73
|
});
|
69
74
|
});
|
70
75
|
const oauthConfigList = Object.entries(oauthConfigs).map(_ref3 => {
|
@@ -87,11 +92,7 @@ function ManageAccounts(_ref) {
|
|
87
92
|
confirmButtonText: t('confirm'),
|
88
93
|
cancelButtonText: t('cancel'),
|
89
94
|
onConfirm(done) {
|
90
|
-
|
91
|
-
if (findIndex >= 0) {
|
92
|
-
accounts.splice(findIndex, 1);
|
93
|
-
}
|
94
|
-
setAccounts(accounts);
|
95
|
+
deleteAccount(account);
|
95
96
|
update();
|
96
97
|
done();
|
97
98
|
}
|
@@ -104,8 +105,8 @@ function ManageAccounts(_ref) {
|
|
104
105
|
update();
|
105
106
|
onSwitchDid(...arguments);
|
106
107
|
}, {
|
107
|
-
|
108
|
-
|
108
|
+
sourceAppPid: app.sourceAppPid,
|
109
|
+
provider: app.provider
|
109
110
|
});
|
110
111
|
});
|
111
112
|
function _onBindWallet() {
|
@@ -119,6 +120,8 @@ function ManageAccounts(_ref) {
|
|
119
120
|
}
|
120
121
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
121
122
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_menuAccordion.default, {
|
123
|
+
expanded: expanded,
|
124
|
+
onChange: onExpand,
|
122
125
|
locale: locale,
|
123
126
|
title: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
124
127
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Account.default, {
|
@@ -127,9 +130,9 @@ function ManageAccounts(_ref) {
|
|
127
130
|
width: 24,
|
128
131
|
height: 24
|
129
132
|
}
|
130
|
-
}), t('
|
133
|
+
}), t('accounts')]
|
131
134
|
}),
|
132
|
-
children: [accounts.map(item => /*#__PURE__*/(0, _jsxRuntime.jsx)(_accountItem.default, {
|
135
|
+
children: [config.accounts.map(item => /*#__PURE__*/(0, _jsxRuntime.jsx)(_accountItem.default, {
|
133
136
|
account: item,
|
134
137
|
locale: locale,
|
135
138
|
active: session.user.did === item.did,
|
@@ -138,7 +141,7 @@ function ManageAccounts(_ref) {
|
|
138
141
|
}, item.did)), /*#__PURE__*/(0, _jsxRuntime.jsx)(_addAccountItem.default, {
|
139
142
|
locale: locale,
|
140
143
|
onAdd: onAdd
|
141
|
-
}), oauthConfigList.length > 0 && !hasBindAccount &&
|
144
|
+
}), oauthConfigList.length > 0 && !hasBindAccount && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, {
|
142
145
|
className: "session-manager-menu-item",
|
143
146
|
onClick: _onBindWallet,
|
144
147
|
"aria-label": !isRawWalletAccount ? "".concat(t('bind'), "DID Wallet") : "".concat(t('bind')).concat(t('thirdParty')),
|
@@ -149,6 +152,16 @@ function ManageAccounts(_ref) {
|
|
149
152
|
height: 24,
|
150
153
|
className: "session-manager-menu-icon"
|
151
154
|
}), !isRawWalletAccount ? "".concat(t('bind'), "DID Wallet") : "".concat(t('bind')).concat(t('thirdParty'))]
|
155
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, {
|
156
|
+
className: "session-manager-menu-item",
|
157
|
+
onClick: onLogout,
|
158
|
+
disabled: disableLogout,
|
159
|
+
"aria-label": "Logout account",
|
160
|
+
"data-cy": "sessionManager-logout-trigger",
|
161
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.SvgIcon, {
|
162
|
+
component: _Disconnect.default,
|
163
|
+
className: "session-manager-menu-icon"
|
164
|
+
}), t('disconnect')]
|
152
165
|
})]
|
153
166
|
}), confirmHolder]
|
154
167
|
});
|
@@ -27,21 +27,25 @@ function ManageBlocklet(_ref) {
|
|
27
27
|
let {
|
28
28
|
menu,
|
29
29
|
menuRender,
|
30
|
-
locale
|
30
|
+
locale,
|
31
|
+
expanded,
|
32
|
+
onExpand
|
31
33
|
} = _ref;
|
32
34
|
const t = (0, _ahooks.useMemoizedFn)(function (key) {
|
33
35
|
let data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
34
36
|
return (0, _util.translate)(_translation.translations, key, locale, 'en', data);
|
35
37
|
});
|
36
38
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_menuAccordion.default, {
|
39
|
+
expanded: expanded,
|
37
40
|
locale: locale,
|
41
|
+
onChange: onExpand,
|
38
42
|
title: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
39
43
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Icon, {
|
40
44
|
icon: _apps.default,
|
41
45
|
width: 24,
|
42
46
|
height: 24,
|
43
47
|
className: "session-manager-menu-icon"
|
44
|
-
}), t('
|
48
|
+
}), t('blocklet')]
|
45
49
|
}),
|
46
50
|
children: [Array.isArray(menu) && menu.map((menuItem, index) => {
|
47
51
|
const {
|
@@ -70,9 +74,13 @@ function ManageBlocklet(_ref) {
|
|
70
74
|
ManageBlocklet.propTypes = {
|
71
75
|
menu: _propTypes.default.array,
|
72
76
|
menuRender: _propTypes.default.func,
|
73
|
-
locale: _propTypes.default.string.isRequired
|
77
|
+
locale: _propTypes.default.string.isRequired,
|
78
|
+
expanded: _propTypes.default.bool,
|
79
|
+
onExpand: _propTypes.default.func
|
74
80
|
};
|
75
81
|
ManageBlocklet.defaultProps = {
|
76
82
|
menu: [],
|
77
|
-
menuRender: () => {}
|
83
|
+
menuRender: () => {},
|
84
|
+
expanded: true,
|
85
|
+
onExpand: () => {}
|
78
86
|
};
|
@@ -31,7 +31,9 @@ function MenuAccordion(_ref) {
|
|
31
31
|
let {
|
32
32
|
title,
|
33
33
|
children,
|
34
|
-
locale
|
34
|
+
locale,
|
35
|
+
expanded,
|
36
|
+
onChange: _onChange
|
35
37
|
} = _ref;
|
36
38
|
const isEmptyChildren = (0, _ahooks.useCreation)(() => isEmptyNode(children), [children]);
|
37
39
|
const t = (0, _ahooks.useMemoizedFn)(function (key) {
|
@@ -39,9 +41,12 @@ function MenuAccordion(_ref) {
|
|
39
41
|
return (0, _util.translate)(_translation.translations, key, locale, 'en', data);
|
40
42
|
});
|
41
43
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Accordion, {
|
42
|
-
|
44
|
+
expanded: expanded,
|
43
45
|
disableGutters: true,
|
44
46
|
elevation: 0,
|
47
|
+
onChange: (e, value) => {
|
48
|
+
_onChange(value);
|
49
|
+
},
|
45
50
|
sx: {
|
46
51
|
'&.MuiAccordion-root:before': {
|
47
52
|
content: 'unset'
|
@@ -58,7 +63,7 @@ function MenuAccordion(_ref) {
|
|
58
63
|
paddingLeft: '30px',
|
59
64
|
'.session-manager-menu-item': {
|
60
65
|
fontSize: '15px',
|
61
|
-
padding: '12px
|
66
|
+
padding: '12px 15px',
|
62
67
|
whiteSpace: 'normal'
|
63
68
|
},
|
64
69
|
'.session-manager-menu-icon': {
|
@@ -96,8 +101,12 @@ function MenuAccordion(_ref) {
|
|
96
101
|
MenuAccordion.propTypes = {
|
97
102
|
title: _propTypes.default.any.isRequired,
|
98
103
|
children: _propTypes.default.any.isRequired,
|
99
|
-
locale: _propTypes.default.string
|
104
|
+
locale: _propTypes.default.string,
|
105
|
+
expanded: _propTypes.default.bool,
|
106
|
+
onChange: _propTypes.default.func
|
100
107
|
};
|
101
108
|
MenuAccordion.defaultProps = {
|
102
|
-
locale: 'en'
|
109
|
+
locale: 'en',
|
110
|
+
expanded: true,
|
111
|
+
onChange: () => {}
|
103
112
|
};
|
@@ -7,7 +7,7 @@ exports.translations = void 0;
|
|
7
7
|
/* eslint-disable import/prefer-default-export */
|
8
8
|
const translations = {
|
9
9
|
en: {
|
10
|
-
|
10
|
+
switch: 'Switch',
|
11
11
|
account: 'account',
|
12
12
|
switchDid: 'Switch DID',
|
13
13
|
switchTo: 'Switch to',
|
@@ -19,9 +19,9 @@ const translations = {
|
|
19
19
|
alreadyBindOAuth: 'Already bind Auth0',
|
20
20
|
bind: 'Bind ',
|
21
21
|
thirdParty: 'Third Party Login',
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
addAppAccount: 'Add {appName} account',
|
23
|
+
accounts: 'Accounts',
|
24
|
+
blocklet: 'Blocklet',
|
25
25
|
from: 'From',
|
26
26
|
addAnotherAccount: 'Add another account',
|
27
27
|
deleteAccountTitle: 'Remove this account ?',
|
@@ -31,24 +31,24 @@ const translations = {
|
|
31
31
|
noneMenu: 'Empty menu, maybe you should switch to another role'
|
32
32
|
},
|
33
33
|
zh: {
|
34
|
-
|
34
|
+
switch: '切换',
|
35
35
|
account: '账号',
|
36
36
|
switchDid: '切换账户',
|
37
37
|
switchTo: '切换至',
|
38
38
|
switchProfile: '切换用户信息',
|
39
39
|
switchPassport: '切换通行证',
|
40
|
-
disconnect: '
|
40
|
+
disconnect: '退出登录',
|
41
41
|
connect: '登录',
|
42
42
|
openInWallet: '打开 DID 钱包',
|
43
43
|
// NOTE: 目前只有 Auth0,展示出具体的第三方名字会更好
|
44
44
|
alreadyBindOAuth: '已绑定 Auth0 账号',
|
45
45
|
bind: '绑定',
|
46
46
|
thirdParty: '第三方登录',
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
addAppAccount: '添加 {appName} 账户',
|
48
|
+
accounts: '账户',
|
49
|
+
blocklet: '应用',
|
50
50
|
from: '连接至',
|
51
|
-
addAnotherAccount: '
|
51
|
+
addAnotherAccount: '添加账号',
|
52
52
|
deleteAccountTitle: '是否删除账户?',
|
53
53
|
deleteAccountContent: '账户删除后,可再次添加',
|
54
54
|
confirm: '确认',
|
@@ -0,0 +1,41 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = useConfig;
|
7
|
+
var _ahooks = require("ahooks");
|
8
|
+
var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
10
|
+
function useConfig() {
|
11
|
+
const [config, setConfig] = (0, _ahooks.useLocalStorageState)('blocklet:sessionManager:config', {
|
12
|
+
defaultValue: {
|
13
|
+
accounts: [],
|
14
|
+
expandAccount: true,
|
15
|
+
expandBlocklet: true
|
16
|
+
}
|
17
|
+
});
|
18
|
+
const connectAccount = (0, _ahooks.useMemoizedFn)(account => {
|
19
|
+
const cloneConfig = (0, _cloneDeep.default)(config);
|
20
|
+
const accountIndex = cloneConfig.accounts.findIndex(x => x.did === account.did);
|
21
|
+
if (accountIndex >= 0) {
|
22
|
+
cloneConfig.accounts.splice(accountIndex, 1);
|
23
|
+
}
|
24
|
+
cloneConfig.accounts.unshift(account);
|
25
|
+
setConfig(cloneConfig);
|
26
|
+
});
|
27
|
+
const deleteAccount = (0, _ahooks.useMemoizedFn)(account => {
|
28
|
+
const cloneConfig = (0, _cloneDeep.default)(config);
|
29
|
+
const findIndex = cloneConfig.accounts.findIndex(item => item.did === account.did);
|
30
|
+
if (findIndex >= 0) {
|
31
|
+
cloneConfig.accounts.splice(findIndex, 1);
|
32
|
+
}
|
33
|
+
setConfig(cloneConfig);
|
34
|
+
});
|
35
|
+
return {
|
36
|
+
config,
|
37
|
+
setConfig,
|
38
|
+
connectAccount,
|
39
|
+
deleteAccount
|
40
|
+
};
|
41
|
+
}
|
@@ -15,6 +15,7 @@ var _DID = _interopRequireDefault(require("../DID"));
|
|
15
15
|
var _Util = require("../Util");
|
16
16
|
var _util = require("../Locale/util");
|
17
17
|
var _translation = require("./translation");
|
18
|
+
var _Typography = _interopRequireDefault(require("../Typography"));
|
18
19
|
var _jsxRuntime = require("react/jsx-runtime");
|
19
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
20
21
|
/* eslint-disable react/jsx-no-bind */
|
@@ -25,7 +26,7 @@ function UserInfo(_ref) {
|
|
25
26
|
let {
|
26
27
|
session,
|
27
28
|
locale,
|
28
|
-
|
29
|
+
onSwitchProfile,
|
29
30
|
onSwitchPassport,
|
30
31
|
switchProfile,
|
31
32
|
hasBindWallet
|
@@ -49,27 +50,27 @@ function UserInfo(_ref) {
|
|
49
50
|
return ((_session$user5 = session.user) === null || _session$user5 === void 0 ? void 0 : _session$user5.email) || 'lancelot_lewis@163.com';
|
50
51
|
}, [session === null || session === void 0 ? void 0 : session.user]);
|
51
52
|
const canEdit = (0, _ahooks.useCreation)(() => {
|
52
|
-
if (
|
53
|
-
if (switchProfile && hasBindWallet
|
53
|
+
if (onSwitchProfile instanceof Function) {
|
54
|
+
if (switchProfile && hasBindWallet) {
|
54
55
|
return true;
|
55
56
|
}
|
56
57
|
}
|
57
58
|
return false;
|
58
|
-
}, [
|
59
|
-
const
|
59
|
+
}, [onSwitchProfile, switchProfile, hasBindWallet, session.provider]);
|
60
|
+
const _onSwitchProfile = (0, _ahooks.useMemoizedFn)(() => {
|
60
61
|
if (canEdit) {
|
61
|
-
|
62
|
+
onSwitchProfile();
|
62
63
|
}
|
63
64
|
});
|
64
65
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
|
65
66
|
sx: {
|
66
67
|
display: 'flex',
|
67
68
|
alignItems: 'center',
|
68
|
-
gap: '
|
69
|
-
padding: '15px
|
69
|
+
gap: '12px',
|
70
|
+
padding: '15px'
|
70
71
|
},
|
71
72
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
|
72
|
-
onClick:
|
73
|
+
onClick: _onSwitchProfile,
|
73
74
|
"data-cy": "sessionManager-switch-profile-trigger",
|
74
75
|
sx: {
|
75
76
|
cursor: canEdit ? 'pointer' : 'default',
|
@@ -79,7 +80,7 @@ function UserInfo(_ref) {
|
|
79
80
|
fontSize: 0,
|
80
81
|
'&:hover': canEdit ? {
|
81
82
|
'&::after': {
|
82
|
-
content: "\"".concat(t('
|
83
|
+
content: "\"".concat(t('switch'), "\""),
|
83
84
|
position: 'absolute',
|
84
85
|
bottom: 0,
|
85
86
|
background: 'rgba(0, 0, 0, 0.2)',
|
@@ -107,11 +108,44 @@ function UserInfo(_ref) {
|
|
107
108
|
overflow: 'hidden',
|
108
109
|
fontSize: '14px'
|
109
110
|
},
|
110
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
111
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
|
112
|
+
display: "flex",
|
113
|
+
alignItems: "center",
|
114
|
+
gap: "4px",
|
115
|
+
mb: 0.5,
|
116
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
|
117
|
+
variant: "h5",
|
118
|
+
fontWeight: "bold",
|
119
|
+
fontSize: "auto",
|
120
|
+
sx: {
|
121
|
+
flex: 1,
|
122
|
+
wordBreak: 'break-all'
|
123
|
+
},
|
124
|
+
children: session.user.fullName
|
125
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Chip, {
|
126
|
+
label: (currentRole === null || currentRole === void 0 ? void 0 : currentRole.title) || ((_session$user6 = session.user) === null || _session$user6 === void 0 ? void 0 : _session$user6.role.toUpperCase()),
|
127
|
+
size: "small",
|
128
|
+
variant: "outlined",
|
129
|
+
sx: {
|
130
|
+
height: 'auto',
|
131
|
+
marginRight: 0,
|
132
|
+
fontWeight: 'bold',
|
133
|
+
fontSize: '12px'
|
134
|
+
},
|
135
|
+
icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Icon, {
|
136
|
+
icon: _shieldCheck.default,
|
137
|
+
height: "0.8em"
|
138
|
+
}),
|
139
|
+
deleteIcon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Icon, {
|
140
|
+
icon: _expandMore.default,
|
141
|
+
height: "1em"
|
142
|
+
})
|
143
|
+
// HACK: 必须设置 onDelete 函数,deleteIcon 才能显示出来
|
144
|
+
,
|
145
|
+
onDelete: onSwitchPassport,
|
146
|
+
onClick: onSwitchPassport,
|
147
|
+
"data-cy": "sessionManager-switch-passport-trigger"
|
148
|
+
})]
|
115
149
|
}), session.provider === 'auth0' ? walletDid ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_DID.default, {
|
116
150
|
responsive: false,
|
117
151
|
compact: true,
|
@@ -123,33 +157,7 @@ function UserInfo(_ref) {
|
|
123
157
|
}), userEmail ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Address.default, {
|
124
158
|
responsive: false,
|
125
159
|
children: userEmail
|
126
|
-
}) : null
|
127
|
-
label: (currentRole === null || currentRole === void 0 ? void 0 : currentRole.title) || ((_session$user6 = session.user) === null || _session$user6 === void 0 ? void 0 : _session$user6.role.toUpperCase()),
|
128
|
-
size: "small",
|
129
|
-
variant: "outlined",
|
130
|
-
sx: {
|
131
|
-
height: 'auto',
|
132
|
-
marginRight: 0,
|
133
|
-
position: 'absolute',
|
134
|
-
top: 20,
|
135
|
-
right: 15,
|
136
|
-
fontWeight: 'bold',
|
137
|
-
fontSize: '12px'
|
138
|
-
},
|
139
|
-
icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Icon, {
|
140
|
-
icon: _shieldCheck.default,
|
141
|
-
height: "0.8em"
|
142
|
-
}),
|
143
|
-
deleteIcon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Icon, {
|
144
|
-
icon: _expandMore.default,
|
145
|
-
height: "1em"
|
146
|
-
})
|
147
|
-
// HACK: 必须设置 onDelete 函数,deleteIcon 才能显示出来
|
148
|
-
,
|
149
|
-
onDelete: onSwitchPassport,
|
150
|
-
onClick: onSwitchPassport,
|
151
|
-
"data-cy": "sessionManager-switch-passport-trigger"
|
152
|
-
})]
|
160
|
+
}) : null]
|
153
161
|
})]
|
154
162
|
});
|
155
163
|
}
|
@@ -92,14 +92,9 @@ UserPopper.defaultProps = {
|
|
92
92
|
onClose: () => {},
|
93
93
|
autoClose: true
|
94
94
|
};
|
95
|
-
const StyledPopper = (0, _Theme.styled)(_material.Popper)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n z-index: ", ";\n .MuiList-root {\n width: 320px;\n }\n .session-manager-
|
95
|
+
const StyledPopper = (0, _Theme.styled)(_material.Popper)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n z-index: ", ";\n .MuiList-root {\n width: 320px;\n }\n .session-manager-menu-item {\n padding: 15px;\n color: #777;\n font-size: 16px;\n &:hover {\n background-color: #fbfbfb;\n }\n }\n .session-manager-menu-icon {\n color: #999;\n margin-right: 8px;\n }\n"])), _ref2 => {
|
96
96
|
let {
|
97
97
|
theme
|
98
98
|
} = _ref2;
|
99
99
|
return theme.zIndex.tooltip;
|
100
|
-
}, _ref3 => {
|
101
|
-
let {
|
102
|
-
$dark
|
103
|
-
} = _ref3;
|
104
|
-
return $dark ? '#aaa' : '#222';
|
105
100
|
});
|