@arcblock/ux 2.7.15 → 2.7.17
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/Dialog/confirm.js +10 -8
- package/es/Img/index.js +7 -7
- package/es/SessionManager/account-item.js +133 -0
- package/es/SessionManager/add-account-item.js +100 -0
- package/es/SessionManager/federated-login-detecter.js +37 -33
- package/es/SessionManager/index.js +119 -259
- package/es/SessionManager/manage-accounts.js +156 -0
- package/es/SessionManager/manage-blocklet.js +70 -0
- package/es/SessionManager/menu-accordion.js +104 -0
- package/es/SessionManager/translation.js +52 -0
- package/es/SessionManager/use-config.js +34 -0
- package/es/SessionManager/user-info.js +147 -0
- package/es/SessionManager/user-popper.js +10 -53
- package/es/SessionManager/utils.js +2 -0
- package/es/Typography/index.js +89 -0
- package/es/Util/federated.js +65 -0
- package/es/Util/index.js +7 -0
- package/lib/Dialog/confirm.js +9 -7
- package/lib/Img/index.js +7 -7
- package/lib/SessionManager/account-item.js +141 -0
- package/lib/SessionManager/add-account-item.js +108 -0
- package/lib/SessionManager/federated-login-detecter.js +38 -33
- package/lib/SessionManager/index.js +122 -272
- package/lib/SessionManager/manage-accounts.js +168 -0
- package/lib/SessionManager/manage-blocklet.js +86 -0
- package/lib/SessionManager/menu-accordion.js +112 -0
- package/lib/SessionManager/translation.js +59 -0
- package/lib/SessionManager/use-config.js +41 -0
- package/lib/SessionManager/user-info.js +163 -0
- package/lib/SessionManager/user-popper.js +8 -8
- package/lib/SessionManager/utils.js +16 -0
- package/lib/Typography/index.js +100 -0
- package/lib/Util/federated.js +85 -0
- package/lib/Util/index.js +11 -2
- package/package.json +12 -5
- package/src/Dialog/confirm.js +9 -6
- package/src/Img/index.js +5 -5
- package/src/SessionManager/account-item.jsx +109 -0
- package/src/SessionManager/add-account-item.jsx +97 -0
- package/src/SessionManager/federated-login-detecter.jsx +42 -29
- package/src/SessionManager/index.jsx +131 -259
- package/src/SessionManager/manage-accounts.jsx +157 -0
- package/src/SessionManager/manage-blocklet.jsx +70 -0
- package/src/SessionManager/menu-accordion.jsx +94 -0
- package/src/SessionManager/translation.js +52 -0
- package/src/SessionManager/use-config.js +33 -0
- package/src/SessionManager/user-info.jsx +116 -0
- package/src/SessionManager/user-popper.jsx +6 -51
- package/src/SessionManager/utils.js +3 -0
- package/src/Typography/index.jsx +79 -0
- package/src/Util/federated.js +73 -0
- package/src/Util/index.js +8 -0
- /package/src/Avatar/{did-motif.js → did-motif.jsx} +0 -0
- /package/src/Avatar/{index.js → index.jsx} +0 -0
- /package/src/Header/{auto-hidden.js → auto-hidden.jsx} +0 -0
- /package/src/Header/{header.js → header.jsx} +0 -0
- /package/src/Header/{responsive-header.js → responsive-header.jsx} +0 -0
@@ -0,0 +1,168 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = ManageAccounts;
|
7
|
+
var _ahooks = require("ahooks");
|
8
|
+
var _material = require("@mui/material");
|
9
|
+
var _react = require("@iconify/react");
|
10
|
+
var _Account = _interopRequireDefault(require("@arcblock/icons/lib/Account"));
|
11
|
+
var _link = _interopRequireDefault(require("@iconify-icons/mdi/link"));
|
12
|
+
var _Disconnect = _interopRequireDefault(require("@arcblock/icons/lib/Disconnect"));
|
13
|
+
var _accountItem = _interopRequireDefault(require("./account-item"));
|
14
|
+
var _menuAccordion = _interopRequireDefault(require("./menu-accordion"));
|
15
|
+
var _translation = require("./translation");
|
16
|
+
var _util = require("../Locale/util");
|
17
|
+
var _confirm = require("../Dialog/confirm");
|
18
|
+
var _utils = require("./utils");
|
19
|
+
var _addAccountItem = _interopRequireDefault(require("./add-account-item"));
|
20
|
+
var _useConfig = _interopRequireDefault(require("./use-config"));
|
21
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
22
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
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; }
|
24
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
25
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
26
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
27
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /* eslint-disable react/prop-types */ /* eslint-disable react/jsx-no-bind */
|
28
|
+
function ManageAccounts(_ref) {
|
29
|
+
let {
|
30
|
+
session,
|
31
|
+
locale,
|
32
|
+
onBindWallet,
|
33
|
+
onSwitchDid,
|
34
|
+
connectAccount,
|
35
|
+
close,
|
36
|
+
hasBindAccount,
|
37
|
+
disableLogout,
|
38
|
+
onLogout,
|
39
|
+
expanded,
|
40
|
+
onExpand
|
41
|
+
} = _ref;
|
42
|
+
const {
|
43
|
+
bindOAuth,
|
44
|
+
configs: oauthConfigs
|
45
|
+
} = session.useOAuth();
|
46
|
+
const t = (0, _ahooks.useMemoizedFn)(function (key) {
|
47
|
+
let data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
48
|
+
return (0, _util.translate)(_translation.translations, key, locale, 'en', data);
|
49
|
+
});
|
50
|
+
const {
|
51
|
+
confirmApi,
|
52
|
+
confirmHolder
|
53
|
+
} = (0, _confirm.useConfirm)();
|
54
|
+
const {
|
55
|
+
deleteAccount,
|
56
|
+
config
|
57
|
+
} = (0, _useConfig.default)();
|
58
|
+
const update = (0, _ahooks.useUpdate)();
|
59
|
+
const onChoose = (0, _ahooks.useMemoizedFn)((account, _ref2) => {
|
60
|
+
let {
|
61
|
+
active
|
62
|
+
} = _ref2;
|
63
|
+
if (active) {
|
64
|
+
return;
|
65
|
+
}
|
66
|
+
close();
|
67
|
+
session.switchDid(function () {
|
68
|
+
connectAccount();
|
69
|
+
onSwitchDid(...arguments);
|
70
|
+
}, {
|
71
|
+
provider: account.provider,
|
72
|
+
sourceAppPid: account.sourceAppPid
|
73
|
+
});
|
74
|
+
});
|
75
|
+
const oauthConfigList = Object.entries(oauthConfigs).map(_ref3 => {
|
76
|
+
let [key, value] = _ref3;
|
77
|
+
return _objectSpread(_objectSpread({}, value), {}, {
|
78
|
+
provider: key
|
79
|
+
});
|
80
|
+
}).filter(item => item.enabled);
|
81
|
+
const isRawWalletAccount = (0, _utils.getSourceProvider)(session.user) === 'wallet';
|
82
|
+
const onDelete = (0, _ahooks.useMemoizedFn)((account, _ref4) => {
|
83
|
+
let {
|
84
|
+
active
|
85
|
+
} = _ref4;
|
86
|
+
if (active) {
|
87
|
+
return;
|
88
|
+
}
|
89
|
+
confirmApi.open({
|
90
|
+
title: t('deleteAccountTitle'),
|
91
|
+
content: t('deleteAccountContent'),
|
92
|
+
confirmButtonText: t('confirm'),
|
93
|
+
cancelButtonText: t('cancel'),
|
94
|
+
onConfirm(done) {
|
95
|
+
deleteAccount(account);
|
96
|
+
update();
|
97
|
+
done();
|
98
|
+
}
|
99
|
+
});
|
100
|
+
});
|
101
|
+
const onAdd = (0, _ahooks.useMemoizedFn)(app => {
|
102
|
+
close();
|
103
|
+
session.switchDid(function () {
|
104
|
+
connectAccount();
|
105
|
+
update();
|
106
|
+
onSwitchDid(...arguments);
|
107
|
+
}, {
|
108
|
+
sourceAppPid: app.sourceAppPid,
|
109
|
+
provider: app.provider
|
110
|
+
});
|
111
|
+
});
|
112
|
+
function _onBindWallet() {
|
113
|
+
close();
|
114
|
+
// FIXME: @zhanghan 暂时切换回 isRawWalletAccount 的方式来判断,在 did-connect 改版时,简化这里的关系判断
|
115
|
+
if (!isRawWalletAccount) {
|
116
|
+
session.bindWallet(onBindWallet);
|
117
|
+
} else {
|
118
|
+
bindOAuth();
|
119
|
+
}
|
120
|
+
}
|
121
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
122
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_menuAccordion.default, {
|
123
|
+
expanded: expanded,
|
124
|
+
onChange: onExpand,
|
125
|
+
locale: locale,
|
126
|
+
title: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
127
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Account.default, {
|
128
|
+
className: "session-manager-menu-icon",
|
129
|
+
style: {
|
130
|
+
width: 24,
|
131
|
+
height: 24
|
132
|
+
}
|
133
|
+
}), t('accounts')]
|
134
|
+
}),
|
135
|
+
children: [config.accounts.map(item => /*#__PURE__*/(0, _jsxRuntime.jsx)(_accountItem.default, {
|
136
|
+
account: item,
|
137
|
+
locale: locale,
|
138
|
+
active: session.user.did === item.did,
|
139
|
+
onDelete: onDelete,
|
140
|
+
onChoose: onChoose
|
141
|
+
}, item.did)), /*#__PURE__*/(0, _jsxRuntime.jsx)(_addAccountItem.default, {
|
142
|
+
locale: locale,
|
143
|
+
onAdd: onAdd
|
144
|
+
}), oauthConfigList.length > 0 && !hasBindAccount && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, {
|
145
|
+
className: "session-manager-menu-item",
|
146
|
+
onClick: _onBindWallet,
|
147
|
+
"aria-label": !isRawWalletAccount ? "".concat(t('bind'), "DID Wallet") : "".concat(t('bind')).concat(t('thirdParty')),
|
148
|
+
"data-cy": "sessionManager-bind-trigger",
|
149
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Icon, {
|
150
|
+
icon: _link.default,
|
151
|
+
width: 24,
|
152
|
+
height: 24,
|
153
|
+
className: "session-manager-menu-icon"
|
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')]
|
165
|
+
})]
|
166
|
+
}), confirmHolder]
|
167
|
+
});
|
168
|
+
}
|
@@ -0,0 +1,86 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = ManageBlocklet;
|
7
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
8
|
+
var _ahooks = require("ahooks");
|
9
|
+
var _react = require("@iconify/react");
|
10
|
+
var _apps = _interopRequireDefault(require("@iconify-icons/mdi/apps"));
|
11
|
+
var _material = require("@mui/material");
|
12
|
+
var _menuAccordion = _interopRequireDefault(require("./menu-accordion"));
|
13
|
+
var _util = require("../Locale/util");
|
14
|
+
var _translation = require("./translation");
|
15
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
16
|
+
const _excluded = ["svgIcon"];
|
17
|
+
/* eslint-disable react/no-array-index-key */
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
19
|
+
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; }
|
20
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
21
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
22
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
23
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
24
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
25
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
26
|
+
function ManageBlocklet(_ref) {
|
27
|
+
let {
|
28
|
+
menu,
|
29
|
+
menuRender,
|
30
|
+
locale,
|
31
|
+
expanded,
|
32
|
+
onExpand
|
33
|
+
} = _ref;
|
34
|
+
const t = (0, _ahooks.useMemoizedFn)(function (key) {
|
35
|
+
let data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
36
|
+
return (0, _util.translate)(_translation.translations, key, locale, 'en', data);
|
37
|
+
});
|
38
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_menuAccordion.default, {
|
39
|
+
expanded: expanded,
|
40
|
+
locale: locale,
|
41
|
+
onChange: onExpand,
|
42
|
+
title: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
43
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Icon, {
|
44
|
+
icon: _apps.default,
|
45
|
+
width: 24,
|
46
|
+
height: 24,
|
47
|
+
className: "session-manager-menu-icon"
|
48
|
+
}), t('blocklet')]
|
49
|
+
}),
|
50
|
+
children: [Array.isArray(menu) && menu.map((menuItem, index) => {
|
51
|
+
const {
|
52
|
+
svgIcon
|
53
|
+
} = menuItem,
|
54
|
+
menuProps = _objectWithoutProperties(menuItem, _excluded);
|
55
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, _objectSpread(_objectSpread({
|
56
|
+
className: "session-manager-menu-item"
|
57
|
+
}, _objectSpread(_objectSpread({}, menuProps), {}, {
|
58
|
+
icon: undefined,
|
59
|
+
label: undefined
|
60
|
+
})), {}, {
|
61
|
+
children: [svgIcon ? svgIcon && /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.SvgIcon, {
|
62
|
+
component: svgIcon,
|
63
|
+
className: "session-manager-menu-icon"
|
64
|
+
}) : menuItem.icon, menuItem.label]
|
65
|
+
}), index);
|
66
|
+
}), menuRender({
|
67
|
+
classes: {
|
68
|
+
menuItem: 'session-manager-menu-item',
|
69
|
+
menuIcon: 'session-manager-menu-icon'
|
70
|
+
}
|
71
|
+
})]
|
72
|
+
});
|
73
|
+
}
|
74
|
+
ManageBlocklet.propTypes = {
|
75
|
+
menu: _propTypes.default.array,
|
76
|
+
menuRender: _propTypes.default.func,
|
77
|
+
locale: _propTypes.default.string.isRequired,
|
78
|
+
expanded: _propTypes.default.bool,
|
79
|
+
onExpand: _propTypes.default.func
|
80
|
+
};
|
81
|
+
ManageBlocklet.defaultProps = {
|
82
|
+
menu: [],
|
83
|
+
menuRender: () => {},
|
84
|
+
expanded: true,
|
85
|
+
onExpand: () => {}
|
86
|
+
};
|
@@ -0,0 +1,112 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = MenuAccordion;
|
7
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
8
|
+
var _material = require("@mui/material");
|
9
|
+
var _expandMore = _interopRequireDefault(require("@iconify-icons/mdi/expand-more"));
|
10
|
+
var _react = require("@iconify/react");
|
11
|
+
var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
|
12
|
+
var _isNil = _interopRequireDefault(require("lodash/isNil"));
|
13
|
+
var _ahooks = require("ahooks");
|
14
|
+
var _util = require("../Locale/util");
|
15
|
+
var _translation = require("./translation");
|
16
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
17
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
18
|
+
function isEmptyNode(node) {
|
19
|
+
if ((0, _isNil.default)(node)) {
|
20
|
+
return true;
|
21
|
+
}
|
22
|
+
if ((0, _isEmpty.default)(node)) {
|
23
|
+
return true;
|
24
|
+
}
|
25
|
+
if (Array.isArray(node)) {
|
26
|
+
return node.every(item => isEmptyNode(item));
|
27
|
+
}
|
28
|
+
return false;
|
29
|
+
}
|
30
|
+
function MenuAccordion(_ref) {
|
31
|
+
let {
|
32
|
+
title,
|
33
|
+
children,
|
34
|
+
locale,
|
35
|
+
expanded,
|
36
|
+
onChange: _onChange
|
37
|
+
} = _ref;
|
38
|
+
const isEmptyChildren = (0, _ahooks.useCreation)(() => isEmptyNode(children), [children]);
|
39
|
+
const t = (0, _ahooks.useMemoizedFn)(function (key) {
|
40
|
+
let data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
41
|
+
return (0, _util.translate)(_translation.translations, key, locale, 'en', data);
|
42
|
+
});
|
43
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Accordion, {
|
44
|
+
expanded: expanded,
|
45
|
+
disableGutters: true,
|
46
|
+
elevation: 0,
|
47
|
+
onChange: (e, value) => {
|
48
|
+
_onChange(value);
|
49
|
+
},
|
50
|
+
sx: {
|
51
|
+
'&.MuiAccordion-root:before': {
|
52
|
+
content: 'unset'
|
53
|
+
},
|
54
|
+
'.MuiAccordionSummary-root': {
|
55
|
+
minHeight: 'auto',
|
56
|
+
width: '100%'
|
57
|
+
},
|
58
|
+
'.MuiAccordionSummary-content': {
|
59
|
+
margin: 0
|
60
|
+
},
|
61
|
+
'.MuiAccordionDetails-root': {
|
62
|
+
padding: 0,
|
63
|
+
paddingLeft: '30px',
|
64
|
+
'.session-manager-menu-item': {
|
65
|
+
fontSize: '15px',
|
66
|
+
padding: '12px 15px',
|
67
|
+
whiteSpace: 'normal'
|
68
|
+
},
|
69
|
+
'.session-manager-menu-icon': {
|
70
|
+
height: '21px',
|
71
|
+
widht: '21px'
|
72
|
+
}
|
73
|
+
}
|
74
|
+
},
|
75
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.MenuItem, {
|
76
|
+
sx: {
|
77
|
+
padding: 0,
|
78
|
+
width: '100%'
|
79
|
+
},
|
80
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.AccordionSummary, {
|
81
|
+
className: "session-manager-menu-item",
|
82
|
+
expandIcon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Icon, {
|
83
|
+
icon: _expandMore.default,
|
84
|
+
width: 24,
|
85
|
+
height: 24
|
86
|
+
}),
|
87
|
+
children: title
|
88
|
+
})
|
89
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.AccordionDetails, {
|
90
|
+
children: isEmptyChildren ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.MenuItem, {
|
91
|
+
disabled: true,
|
92
|
+
className: "session-manager-menu-item",
|
93
|
+
sx: {
|
94
|
+
justifyContent: 'center'
|
95
|
+
},
|
96
|
+
children: t('noneMenu')
|
97
|
+
}, "empty") : children
|
98
|
+
})]
|
99
|
+
});
|
100
|
+
}
|
101
|
+
MenuAccordion.propTypes = {
|
102
|
+
title: _propTypes.default.any.isRequired,
|
103
|
+
children: _propTypes.default.any.isRequired,
|
104
|
+
locale: _propTypes.default.string,
|
105
|
+
expanded: _propTypes.default.bool,
|
106
|
+
onChange: _propTypes.default.func
|
107
|
+
};
|
108
|
+
MenuAccordion.defaultProps = {
|
109
|
+
locale: 'en',
|
110
|
+
expanded: true,
|
111
|
+
onChange: () => {}
|
112
|
+
};
|
@@ -0,0 +1,59 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.translations = void 0;
|
7
|
+
/* eslint-disable import/prefer-default-export */
|
8
|
+
const translations = {
|
9
|
+
en: {
|
10
|
+
switch: 'Switch',
|
11
|
+
account: 'account',
|
12
|
+
switchDid: 'Switch DID',
|
13
|
+
switchTo: 'Switch to',
|
14
|
+
switchProfile: 'Switch Profile',
|
15
|
+
switchPassport: 'Switch Passport',
|
16
|
+
disconnect: 'Disconnect',
|
17
|
+
connect: 'Connect',
|
18
|
+
openInWallet: 'Open DID Wallet',
|
19
|
+
alreadyBindOAuth: 'Already bind Auth0',
|
20
|
+
bind: 'Bind ',
|
21
|
+
thirdParty: 'Third Party Login',
|
22
|
+
addAppAccount: 'Add {appName} account',
|
23
|
+
accounts: 'Accounts',
|
24
|
+
blocklet: 'Blocklet',
|
25
|
+
from: 'From',
|
26
|
+
addAnotherAccount: 'Add another account',
|
27
|
+
deleteAccountTitle: 'Remove this account ?',
|
28
|
+
deleteAccountContent: 'After delete account, you can add it agian',
|
29
|
+
confirm: 'Confirm',
|
30
|
+
cancel: 'Cancel',
|
31
|
+
noneMenu: 'Empty menu, maybe you should switch to another role'
|
32
|
+
},
|
33
|
+
zh: {
|
34
|
+
switch: '切换',
|
35
|
+
account: '账号',
|
36
|
+
switchDid: '切换账户',
|
37
|
+
switchTo: '切换至',
|
38
|
+
switchProfile: '切换用户信息',
|
39
|
+
switchPassport: '切换通行证',
|
40
|
+
disconnect: '退出登录',
|
41
|
+
connect: '登录',
|
42
|
+
openInWallet: '打开 DID 钱包',
|
43
|
+
// NOTE: 目前只有 Auth0,展示出具体的第三方名字会更好
|
44
|
+
alreadyBindOAuth: '已绑定 Auth0 账号',
|
45
|
+
bind: '绑定',
|
46
|
+
thirdParty: '第三方登录',
|
47
|
+
addAppAccount: '添加 {appName} 账户',
|
48
|
+
accounts: '账户',
|
49
|
+
blocklet: '应用',
|
50
|
+
from: '连接至',
|
51
|
+
addAnotherAccount: '添加账号',
|
52
|
+
deleteAccountTitle: '是否删除账户?',
|
53
|
+
deleteAccountContent: '账户删除后,可再次添加',
|
54
|
+
confirm: '确认',
|
55
|
+
cancel: '取消',
|
56
|
+
noneMenu: '无操作项,请尝试切换角色'
|
57
|
+
}
|
58
|
+
};
|
59
|
+
exports.translations = translations;
|
@@ -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
|
+
}
|
@@ -0,0 +1,163 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = UserInfo;
|
7
|
+
var _material = require("@mui/material");
|
8
|
+
var _shieldCheck = _interopRequireDefault(require("@iconify-icons/mdi/shield-check"));
|
9
|
+
var _expandMore = _interopRequireDefault(require("@iconify-icons/mdi/expand-more"));
|
10
|
+
var _react = require("@iconify/react");
|
11
|
+
var _ahooks = require("ahooks");
|
12
|
+
var _Avatar = _interopRequireDefault(require("../Avatar"));
|
13
|
+
var _Address = _interopRequireDefault(require("../Address"));
|
14
|
+
var _DID = _interopRequireDefault(require("../DID"));
|
15
|
+
var _Util = require("../Util");
|
16
|
+
var _util = require("../Locale/util");
|
17
|
+
var _translation = require("./translation");
|
18
|
+
var _Typography = _interopRequireDefault(require("../Typography"));
|
19
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
21
|
+
/* eslint-disable react/jsx-no-bind */
|
22
|
+
/* eslint-disable react/prop-types */
|
23
|
+
|
24
|
+
function UserInfo(_ref) {
|
25
|
+
var _session$user, _session$user$avatar, _session$user3, _session$user4, _session$user6;
|
26
|
+
let {
|
27
|
+
session,
|
28
|
+
locale,
|
29
|
+
onSwitchProfile,
|
30
|
+
onSwitchPassport,
|
31
|
+
switchProfile,
|
32
|
+
hasBindWallet
|
33
|
+
} = _ref;
|
34
|
+
const t = function t(key) {
|
35
|
+
let data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
36
|
+
return (0, _util.t)(_translation.translations, key, locale, 'en', data);
|
37
|
+
};
|
38
|
+
const avatar = (0, _Util.getUserAvatar)((_session$user = session.user) === null || _session$user === void 0 ? void 0 : (_session$user$avatar = _session$user.avatar) === null || _session$user$avatar === void 0 ? void 0 : _session$user$avatar.replace(/\s/g, encodeURIComponent(' ')));
|
39
|
+
const {
|
40
|
+
walletDid
|
41
|
+
} = session.useDid({
|
42
|
+
session
|
43
|
+
});
|
44
|
+
const currentRole = (0, _ahooks.useCreation)(() => {
|
45
|
+
var _session$user2, _session$user2$passpo;
|
46
|
+
return (_session$user2 = session.user) === null || _session$user2 === void 0 ? void 0 : (_session$user2$passpo = _session$user2.passports) === null || _session$user2$passpo === void 0 ? void 0 : _session$user2$passpo.find(item => item.name === session.user.role);
|
47
|
+
}, [session === null || session === void 0 ? void 0 : (_session$user3 = session.user) === null || _session$user3 === void 0 ? void 0 : _session$user3.passports, session === null || session === void 0 ? void 0 : (_session$user4 = session.user) === null || _session$user4 === void 0 ? void 0 : _session$user4.role]);
|
48
|
+
const userEmail = (0, _ahooks.useCreation)(() => {
|
49
|
+
var _session$user5;
|
50
|
+
return ((_session$user5 = session.user) === null || _session$user5 === void 0 ? void 0 : _session$user5.email) || 'lancelot_lewis@163.com';
|
51
|
+
}, [session === null || session === void 0 ? void 0 : session.user]);
|
52
|
+
const canEdit = (0, _ahooks.useCreation)(() => {
|
53
|
+
if (onSwitchProfile instanceof Function) {
|
54
|
+
if (switchProfile && hasBindWallet) {
|
55
|
+
return true;
|
56
|
+
}
|
57
|
+
}
|
58
|
+
return false;
|
59
|
+
}, [onSwitchProfile, switchProfile, hasBindWallet, session.provider]);
|
60
|
+
const _onSwitchProfile = (0, _ahooks.useMemoizedFn)(() => {
|
61
|
+
if (canEdit) {
|
62
|
+
onSwitchProfile();
|
63
|
+
}
|
64
|
+
});
|
65
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
|
66
|
+
sx: {
|
67
|
+
display: 'flex',
|
68
|
+
alignItems: 'center',
|
69
|
+
gap: '12px',
|
70
|
+
padding: '15px'
|
71
|
+
},
|
72
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
|
73
|
+
onClick: _onSwitchProfile,
|
74
|
+
"data-cy": "sessionManager-switch-profile-trigger",
|
75
|
+
sx: {
|
76
|
+
cursor: canEdit ? 'pointer' : 'default',
|
77
|
+
position: 'relative',
|
78
|
+
borderRadius: '100%',
|
79
|
+
overflow: 'hidden',
|
80
|
+
fontSize: 0,
|
81
|
+
'&:hover': canEdit ? {
|
82
|
+
'&::after': {
|
83
|
+
content: "\"".concat(t('switch'), "\""),
|
84
|
+
position: 'absolute',
|
85
|
+
bottom: 0,
|
86
|
+
background: 'rgba(0, 0, 0, 0.2)',
|
87
|
+
left: 0,
|
88
|
+
right: 0,
|
89
|
+
height: '2.2em',
|
90
|
+
color: 'white',
|
91
|
+
textAlign: 'center',
|
92
|
+
fontSize: '12px',
|
93
|
+
lineHeight: '2em'
|
94
|
+
}
|
95
|
+
} : {}
|
96
|
+
},
|
97
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Avatar.default, {
|
98
|
+
variant: "circle",
|
99
|
+
did: session.user.did,
|
100
|
+
src: avatar,
|
101
|
+
size: 64,
|
102
|
+
shape: "circle"
|
103
|
+
})
|
104
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
|
105
|
+
sx: {
|
106
|
+
flex: 1,
|
107
|
+
position: 'static',
|
108
|
+
overflow: 'hidden',
|
109
|
+
fontSize: '14px'
|
110
|
+
},
|
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
|
+
})]
|
149
|
+
}), session.provider === 'auth0' ? walletDid ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_DID.default, {
|
150
|
+
responsive: false,
|
151
|
+
compact: true,
|
152
|
+
did: walletDid
|
153
|
+
}) : null : /*#__PURE__*/(0, _jsxRuntime.jsx)(_DID.default, {
|
154
|
+
responsive: false,
|
155
|
+
compact: true,
|
156
|
+
did: session.user.did
|
157
|
+
}), userEmail ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Address.default, {
|
158
|
+
responsive: false,
|
159
|
+
children: userEmail
|
160
|
+
}) : null]
|
161
|
+
})]
|
162
|
+
});
|
163
|
+
}
|
@@ -6,7 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
exports.default = UserPopper;
|
7
7
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
8
8
|
var _material = require("@mui/material");
|
9
|
-
var
|
9
|
+
var _close = _interopRequireDefault(require("@iconify-icons/mdi/close"));
|
10
|
+
var _react = require("@iconify/react");
|
10
11
|
var _Theme = require("../Theme");
|
11
12
|
var _jsxRuntime = require("react/jsx-runtime");
|
12
13
|
var _templateObject;
|
@@ -66,7 +67,11 @@ function UserPopper(_ref) {
|
|
66
67
|
zIndex: 1
|
67
68
|
},
|
68
69
|
onClick: onClose,
|
69
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(
|
70
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Icon, {
|
71
|
+
icon: _close.default,
|
72
|
+
width: 20,
|
73
|
+
height: 20
|
74
|
+
})
|
70
75
|
}), children]
|
71
76
|
})
|
72
77
|
})
|
@@ -87,14 +92,9 @@ UserPopper.defaultProps = {
|
|
87
92
|
onClose: () => {},
|
88
93
|
autoClose: true
|
89
94
|
};
|
90
|
-
const StyledPopper = (0, _Theme.styled)(_material.Popper)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n z-index: ", ";\n .MuiList-root {\n
|
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 => {
|
91
96
|
let {
|
92
97
|
theme
|
93
98
|
} = _ref2;
|
94
99
|
return theme.zIndex.tooltip;
|
95
|
-
}, _ref3 => {
|
96
|
-
let {
|
97
|
-
$dark
|
98
|
-
} = _ref3;
|
99
|
-
return $dark ? '#aaa' : '#222';
|
100
100
|
});
|