@arcblock/ux 2.7.15 → 2.7.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/es/Dialog/confirm.js +10 -8
  2. package/es/Img/index.js +7 -7
  3. package/es/SessionManager/account-item.js +132 -0
  4. package/es/SessionManager/add-account-item.js +118 -0
  5. package/es/SessionManager/federated-login-detecter.js +5 -7
  6. package/es/SessionManager/index.js +117 -244
  7. package/es/SessionManager/manage-accounts.js +143 -0
  8. package/es/SessionManager/manage-blocklet.js +62 -0
  9. package/es/SessionManager/menu-accordion.js +95 -0
  10. package/es/SessionManager/translation.js +52 -0
  11. package/es/SessionManager/use-accounts.js +19 -0
  12. package/es/SessionManager/user-info.js +139 -0
  13. package/es/SessionManager/user-popper.js +10 -36
  14. package/es/SessionManager/utils.js +2 -0
  15. package/es/Util/index.js +7 -0
  16. package/lib/Dialog/confirm.js +9 -7
  17. package/lib/Img/index.js +7 -7
  18. package/lib/SessionManager/account-item.js +140 -0
  19. package/lib/SessionManager/add-account-item.js +126 -0
  20. package/lib/SessionManager/federated-login-detecter.js +5 -7
  21. package/lib/SessionManager/index.js +120 -257
  22. package/lib/SessionManager/manage-accounts.js +155 -0
  23. package/lib/SessionManager/manage-blocklet.js +78 -0
  24. package/lib/SessionManager/menu-accordion.js +103 -0
  25. package/lib/SessionManager/translation.js +59 -0
  26. package/lib/SessionManager/use-accounts.js +25 -0
  27. package/lib/SessionManager/user-info.js +155 -0
  28. package/lib/SessionManager/user-popper.js +8 -3
  29. package/lib/SessionManager/utils.js +16 -0
  30. package/lib/Util/index.js +11 -2
  31. package/package.json +8 -5
  32. package/src/Dialog/confirm.js +9 -6
  33. package/src/Img/index.js +5 -5
  34. package/src/SessionManager/account-item.jsx +111 -0
  35. package/src/SessionManager/add-account-item.jsx +115 -0
  36. package/src/SessionManager/federated-login-detecter.jsx +3 -3
  37. package/src/SessionManager/index.jsx +130 -238
  38. package/src/SessionManager/manage-accounts.jsx +143 -0
  39. package/src/SessionManager/manage-blocklet.jsx +64 -0
  40. package/src/SessionManager/menu-accordion.jsx +87 -0
  41. package/src/SessionManager/translation.js +52 -0
  42. package/src/SessionManager/use-accounts.js +18 -0
  43. package/src/SessionManager/user-info.jsx +116 -0
  44. package/src/SessionManager/user-popper.jsx +6 -36
  45. package/src/SessionManager/utils.js +3 -0
  46. package/src/Util/index.js +8 -0
  47. /package/src/Avatar/{did-motif.js → did-motif.jsx} +0 -0
  48. /package/src/Avatar/{index.js → index.jsx} +0 -0
  49. /package/src/Header/{auto-hidden.js → auto-hidden.jsx} +0 -0
  50. /package/src/Header/{header.js → header.jsx} +0 -0
  51. /package/src/Header/{responsive-header.js → responsive-header.jsx} +0 -0
@@ -0,0 +1,95 @@
1
+ import PropTypes from 'prop-types';
2
+ import { Accordion, AccordionDetails, AccordionSummary, MenuItem } from '@mui/material';
3
+ import ExpandMoreIcon from '@iconify-icons/mdi/expand-more';
4
+ import { Icon } from '@iconify/react';
5
+ import isEmpty from 'lodash/isEmpty';
6
+ import isNil from 'lodash/isNil';
7
+ import { useCreation, useMemoizedFn } from 'ahooks';
8
+ import { translate } from '../Locale/util';
9
+ import { translations } from './translation';
10
+ import { jsx as _jsx } from "react/jsx-runtime";
11
+ import { jsxs as _jsxs } from "react/jsx-runtime";
12
+ function isEmptyNode(node) {
13
+ if (isNil(node)) {
14
+ return true;
15
+ }
16
+ if (isEmpty(node)) {
17
+ return true;
18
+ }
19
+ if (Array.isArray(node)) {
20
+ return node.every(item => isEmptyNode(item));
21
+ }
22
+ return false;
23
+ }
24
+ export default function MenuAccordion({
25
+ title,
26
+ children,
27
+ locale
28
+ }) {
29
+ const isEmptyChildren = useCreation(() => isEmptyNode(children), [children]);
30
+ const t = useMemoizedFn((key, data = {}) => {
31
+ return translate(translations, key, locale, 'en', data);
32
+ });
33
+ return /*#__PURE__*/_jsxs(Accordion, {
34
+ defaultExpanded: true,
35
+ disableGutters: true,
36
+ elevation: 0,
37
+ sx: {
38
+ '&.MuiAccordion-root:before': {
39
+ content: 'unset'
40
+ },
41
+ '.MuiAccordionSummary-root': {
42
+ minHeight: 'auto',
43
+ width: '100%'
44
+ },
45
+ '.MuiAccordionSummary-content': {
46
+ margin: 0
47
+ },
48
+ '.MuiAccordionDetails-root': {
49
+ padding: 0,
50
+ paddingLeft: '30px',
51
+ '.session-manager-menu-item': {
52
+ fontSize: '15px',
53
+ padding: '12px 20px',
54
+ whiteSpace: 'normal'
55
+ },
56
+ '.session-manager-menu-icon': {
57
+ height: '21px',
58
+ widht: '21px'
59
+ }
60
+ }
61
+ },
62
+ children: [/*#__PURE__*/_jsx(MenuItem, {
63
+ sx: {
64
+ padding: 0,
65
+ width: '100%'
66
+ },
67
+ children: /*#__PURE__*/_jsx(AccordionSummary, {
68
+ className: "session-manager-menu-item",
69
+ expandIcon: /*#__PURE__*/_jsx(Icon, {
70
+ icon: ExpandMoreIcon,
71
+ width: 24,
72
+ height: 24
73
+ }),
74
+ children: title
75
+ })
76
+ }), /*#__PURE__*/_jsx(AccordionDetails, {
77
+ children: isEmptyChildren ? /*#__PURE__*/_jsx(MenuItem, {
78
+ disabled: true,
79
+ className: "session-manager-menu-item",
80
+ sx: {
81
+ justifyContent: 'center'
82
+ },
83
+ children: t('noneMenu')
84
+ }, "empty") : children
85
+ })]
86
+ });
87
+ }
88
+ MenuAccordion.propTypes = {
89
+ title: PropTypes.any.isRequired,
90
+ children: PropTypes.any.isRequired,
91
+ locale: PropTypes.string
92
+ };
93
+ MenuAccordion.defaultProps = {
94
+ locale: 'en'
95
+ };
@@ -0,0 +1,52 @@
1
+ /* eslint-disable import/prefer-default-export */
2
+ export const translations = {
3
+ en: {
4
+ edit: 'Edit',
5
+ account: 'account',
6
+ switchDid: 'Switch DID',
7
+ switchTo: 'Switch to',
8
+ switchProfile: 'Switch Profile',
9
+ switchPassport: 'Switch Passport',
10
+ disconnect: 'Disconnect',
11
+ connect: 'Connect',
12
+ openInWallet: 'Open DID Wallet',
13
+ alreadyBindOAuth: 'Already bind Auth0',
14
+ bind: 'Bind ',
15
+ thirdParty: 'Third Party Login',
16
+ connectedWith: 'Connected with',
17
+ manageAccounts: 'Manage Accounts',
18
+ manageBlocklet: 'Manage Blocklet',
19
+ from: 'From',
20
+ addAnotherAccount: 'Add another account',
21
+ deleteAccountTitle: 'Remove this account ?',
22
+ deleteAccountContent: 'After delete account, you can add it agian',
23
+ confirm: 'Confirm',
24
+ cancel: 'Cancel',
25
+ noneMenu: 'Empty menu, maybe you should switch to another role'
26
+ },
27
+ zh: {
28
+ edit: '编辑',
29
+ account: '账号',
30
+ switchDid: '切换账户',
31
+ switchTo: '切换至',
32
+ switchProfile: '切换用户信息',
33
+ switchPassport: '切换通行证',
34
+ disconnect: '退出',
35
+ connect: '登录',
36
+ openInWallet: '打开 DID 钱包',
37
+ // NOTE: 目前只有 Auth0,展示出具体的第三方名字会更好
38
+ alreadyBindOAuth: '已绑定 Auth0 账号',
39
+ bind: '绑定',
40
+ thirdParty: '第三方登录',
41
+ connectedWith: '连接至',
42
+ manageAccounts: '管理账户',
43
+ manageBlocklet: '管理应用',
44
+ from: '连接至',
45
+ addAnotherAccount: '添加一个账号',
46
+ deleteAccountTitle: '是否删除账户?',
47
+ deleteAccountContent: '账户删除后,可再次添加',
48
+ confirm: '确认',
49
+ cancel: '取消',
50
+ noneMenu: '无操作项,请尝试切换角色'
51
+ }
52
+ };
@@ -0,0 +1,19 @@
1
+ import { useLocalStorageState, useMemoizedFn } from 'ahooks';
2
+ export default function useAccounts() {
3
+ const [accounts, setAccounts] = useLocalStorageState('blocklet:sessionManager:accounts', {
4
+ defaultValue: []
5
+ });
6
+ const connectAccount = useMemoizedFn(account => {
7
+ const accountIndex = accounts.findIndex(x => x.did === account.did);
8
+ if (accountIndex >= 0) {
9
+ accounts.splice(accountIndex, 1);
10
+ }
11
+ accounts.unshift(account);
12
+ setAccounts(accounts);
13
+ });
14
+ return {
15
+ accounts,
16
+ setAccounts,
17
+ connectAccount
18
+ };
19
+ }
@@ -0,0 +1,139 @@
1
+ /* eslint-disable react/jsx-no-bind */
2
+ /* eslint-disable react/prop-types */
3
+ import { Box, Chip, Typography } from '@mui/material';
4
+ import ShieldCheckIcon from '@iconify-icons/mdi/shield-check';
5
+ import ExpandMoreIcon from '@iconify-icons/mdi/expand-more';
6
+ import { Icon } from '@iconify/react';
7
+ import { useCreation, useMemoizedFn } from 'ahooks';
8
+ import DidAvatar from '../Avatar';
9
+ import DidAddress from '../Address';
10
+ import DID from '../DID';
11
+ import { getUserAvatar } from '../Util';
12
+ import { t as translate } from '../Locale/util';
13
+ import { translations } from './translation';
14
+ import { jsx as _jsx } from "react/jsx-runtime";
15
+ import { jsxs as _jsxs } from "react/jsx-runtime";
16
+ export default function UserInfo({
17
+ session,
18
+ locale,
19
+ onEditUser,
20
+ onSwitchPassport,
21
+ switchProfile,
22
+ hasBindWallet
23
+ }) {
24
+ const t = (key, data = {}) => {
25
+ return translate(translations, key, locale, 'en', data);
26
+ };
27
+ const avatar = getUserAvatar(session.user?.avatar?.replace(/\s/g, encodeURIComponent(' ')));
28
+ const {
29
+ walletDid
30
+ } = session.useDid({
31
+ session
32
+ });
33
+ const currentRole = useCreation(() => session.user?.passports?.find(item => item.name === session.user.role), [session?.user?.passports, session?.user?.role]);
34
+ const userEmail = useCreation(() => session.user?.email || 'lancelot_lewis@163.com', [session?.user]);
35
+ const canEdit = useCreation(() => {
36
+ if (onEditUser instanceof Function) {
37
+ if (switchProfile && hasBindWallet && session.provider !== 'federated') {
38
+ return true;
39
+ }
40
+ }
41
+ return false;
42
+ }, [onEditUser, switchProfile, hasBindWallet, session.provider]);
43
+ const _onEditUser = useMemoizedFn(() => {
44
+ if (canEdit) {
45
+ onEditUser();
46
+ }
47
+ });
48
+ return /*#__PURE__*/_jsxs(Box, {
49
+ sx: {
50
+ display: 'flex',
51
+ alignItems: 'center',
52
+ gap: '16px',
53
+ padding: '15px 20px'
54
+ },
55
+ children: [/*#__PURE__*/_jsx(Box, {
56
+ onClick: _onEditUser,
57
+ "data-cy": "sessionManager-switch-profile-trigger",
58
+ sx: {
59
+ cursor: canEdit ? 'pointer' : 'default',
60
+ position: 'relative',
61
+ borderRadius: '100%',
62
+ overflow: 'hidden',
63
+ fontSize: 0,
64
+ '&:hover': canEdit ? {
65
+ '&::after': {
66
+ content: `"${t('edit')}"`,
67
+ position: 'absolute',
68
+ bottom: 0,
69
+ background: 'rgba(0, 0, 0, 0.2)',
70
+ left: 0,
71
+ right: 0,
72
+ height: '2.2em',
73
+ color: 'white',
74
+ textAlign: 'center',
75
+ fontSize: '12px',
76
+ lineHeight: '2em'
77
+ }
78
+ } : {}
79
+ },
80
+ children: /*#__PURE__*/_jsx(DidAvatar, {
81
+ variant: "circle",
82
+ did: session.user.did,
83
+ src: avatar,
84
+ size: 64,
85
+ shape: "circle"
86
+ })
87
+ }), /*#__PURE__*/_jsxs(Box, {
88
+ sx: {
89
+ flex: 1,
90
+ position: 'static',
91
+ overflow: 'hidden',
92
+ fontSize: '14px'
93
+ },
94
+ children: [/*#__PURE__*/_jsx(Typography, {
95
+ variant: "h5",
96
+ fontWeight: "bold",
97
+ mb: 1,
98
+ children: session.user.fullName
99
+ }), session.provider === 'auth0' ? walletDid ? /*#__PURE__*/_jsx(DID, {
100
+ responsive: false,
101
+ compact: true,
102
+ did: walletDid
103
+ }) : null : /*#__PURE__*/_jsx(DID, {
104
+ responsive: false,
105
+ compact: true,
106
+ did: session.user.did
107
+ }), userEmail ? /*#__PURE__*/_jsx(DidAddress, {
108
+ responsive: false,
109
+ children: userEmail
110
+ }) : null, /*#__PURE__*/_jsx(Chip, {
111
+ label: currentRole?.title || session.user?.role.toUpperCase(),
112
+ size: "small",
113
+ variant: "outlined",
114
+ sx: {
115
+ height: 'auto',
116
+ marginRight: 0,
117
+ position: 'absolute',
118
+ top: 20,
119
+ right: 15,
120
+ fontWeight: 'bold',
121
+ fontSize: '12px'
122
+ },
123
+ icon: /*#__PURE__*/_jsx(Icon, {
124
+ icon: ShieldCheckIcon,
125
+ height: "0.8em"
126
+ }),
127
+ deleteIcon: /*#__PURE__*/_jsx(Icon, {
128
+ icon: ExpandMoreIcon,
129
+ height: "1em"
130
+ })
131
+ // HACK: 必须设置 onDelete 函数,deleteIcon 才能显示出来
132
+ ,
133
+ onDelete: onSwitchPassport,
134
+ onClick: onSwitchPassport,
135
+ "data-cy": "sessionManager-switch-passport-trigger"
136
+ })]
137
+ })]
138
+ });
139
+ }
@@ -1,6 +1,7 @@
1
1
  import PropTypes from 'prop-types';
2
2
  import { IconButton, Paper, Popper, ClickAwayListener } from '@mui/material';
3
- import { Close as CloseIcon } from '@mui/icons-material';
3
+ import CloseIcon from '@iconify-icons/mdi/close';
4
+ import { Icon } from '@iconify/react';
4
5
  import { styled } from '../Theme';
5
6
  import { jsx as _jsx } from "react/jsx-runtime";
6
7
  import { Fragment as _Fragment } from "react/jsx-runtime";
@@ -58,7 +59,11 @@ export default function UserPopper({
58
59
  zIndex: 1
59
60
  },
60
61
  onClick: onClose,
61
- children: /*#__PURE__*/_jsx(CloseIcon, {})
62
+ children: /*#__PURE__*/_jsx(Icon, {
63
+ icon: CloseIcon,
64
+ width: 20,
65
+ height: 20
66
+ })
62
67
  }), children]
63
68
  })
64
69
  })
@@ -86,8 +91,7 @@ const StyledPopper = styled(Popper)`
86
91
  return theme.zIndex.tooltip;
87
92
  }};
88
93
  .MuiList-root {
89
- /* HACK: 需要288px 才能将 did 展示完整 */
90
- width: 290px;
94
+ width: 320px;
91
95
  }
92
96
  .session-manager-user {
93
97
  font-size: 12px;
@@ -106,38 +110,8 @@ const StyledPopper = styled(Popper)`
106
110
  align-items: center;
107
111
  justify-content: space-between;
108
112
  }
109
- .session-manager-id-item {
110
- position: relative;
111
- padding-left: 8px;
112
- /* HACK: 当前元素既是第一个,也是最后一个,即只有一个同级元素 */
113
- &:first-of-type:last-of-type {
114
- padding-left: 0;
115
- &:before,
116
- &:after {
117
- content: unset;
118
- }
119
- }
120
- &:before {
121
- position: absolute;
122
- content: '';
123
- left: 0px;
124
- top: 50%;
125
- width: 6px;
126
- height: 1px;
127
- background-color: #aeaeae;
128
- }
129
- &:not(:last-of-type):after {
130
- position: absolute;
131
- content: '';
132
- left: 0px;
133
- top: 50%;
134
- height: 100%;
135
- width: 1px;
136
- background-color: #aeaeae;
137
- }
138
- }
139
113
  .session-manager-menu-item {
140
- padding: 18.5px 24px;
114
+ padding: 18px 20px;
141
115
  color: #777;
142
116
  font-size: 16px;
143
117
  &:hover {
@@ -146,6 +120,6 @@ const StyledPopper = styled(Popper)`
146
120
  }
147
121
  .session-manager-menu-icon {
148
122
  color: #999;
149
- margin-right: 16px;
123
+ margin-right: 8px;
150
124
  }
151
125
  `;
@@ -0,0 +1,2 @@
1
+ export const getSourceProvider = user => user?.sourceProvider || user?.extraConfigs?.sourceProvider || 'wallet';
2
+ export const getConnectedAccounts = user => user?.connectedAccounts || user?.extraConfigs?.connectedAccounts || [];
package/es/Util/index.js CHANGED
@@ -295,4 +295,11 @@ export const getUserAvatar = (avatar, size = 48) => {
295
295
  });
296
296
  }
297
297
  return avatar;
298
+ };
299
+ export const sleep = (time = 0) => {
300
+ return new Promise(resolve => {
301
+ setTimeout(() => {
302
+ resolve();
303
+ }, time);
304
+ });
298
305
  };
@@ -9,7 +9,6 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
9
9
  var _react = require("react");
10
10
  var _ahooks = require("ahooks");
11
11
  var _noop = _interopRequireDefault(require("lodash/noop"));
12
- var _context = require("../Locale/context");
13
12
  var _Button = _interopRequireDefault(require("../Button"));
14
13
  var _dialog = _interopRequireDefault(require("./dialog"));
15
14
  var _jsxRuntime = require("react/jsx-runtime");
@@ -106,16 +105,15 @@ Confirm.defaultProps = {
106
105
  PaperProps: {}
107
106
  };
108
107
  const ConfirmHolder = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
109
- const {
110
- t
111
- } = (0, _react.useContext)(_context.LocaleContext);
112
108
  const state = (0, _ahooks.useReactive)({
113
109
  show: false,
114
110
  title: '',
115
111
  content: '',
116
112
  onConfirm: _noop.default,
117
113
  onCancel: _noop.default,
118
- loading: false
114
+ loading: false,
115
+ confirmButtonText: 'Confirm',
116
+ cancelButtonText: 'Cancel'
119
117
  });
120
118
  const open = (0, _ahooks.useMemoizedFn)(function () {
121
119
  let params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
@@ -124,6 +122,8 @@ const ConfirmHolder = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
124
122
  state.content = params.content;
125
123
  state.onConfirm = params.onConfirm || _noop.default;
126
124
  state.onCancel = params.onCancel || _noop.default;
125
+ if (params.confirmButtonText) state.confirmButtonText = params.confirmButtonText;
126
+ if (params.cancelButtonText) state.cancelButtonText = params.cancelButtonText;
127
127
  state.loading = false;
128
128
  });
129
129
  const reset = (0, _ahooks.useMemoizedFn)(() => {
@@ -131,6 +131,8 @@ const ConfirmHolder = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
131
131
  state.content = '';
132
132
  state.onConfirm = _noop.default;
133
133
  state.onCancel = _noop.default;
134
+ state.confirmButtonText = 'Confirm';
135
+ state.cancelButtonText = 'Cancel';
134
136
  });
135
137
  const close = (0, _ahooks.useMemoizedFn)(() => {
136
138
  state.show = false;
@@ -162,7 +164,7 @@ const ConfirmHolder = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
162
164
  onConfirm: onConfirm,
163
165
  onCancel: onCancel,
164
166
  confirmButton: {
165
- text: t('common.confirm'),
167
+ text: state.confirmButtonText,
166
168
  props: {
167
169
  variant: 'contained',
168
170
  color: 'primary',
@@ -170,7 +172,7 @@ const ConfirmHolder = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
170
172
  }
171
173
  },
172
174
  cancelButton: {
173
- text: t('common.cancel'),
175
+ text: state.cancelButtonText,
174
176
  props: {
175
177
  variant: 'outlined',
176
178
  color: 'primary'
package/lib/Img/index.js CHANGED
@@ -6,10 +6,10 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _react = require("react");
8
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
- var _SvgIcon = _interopRequireDefault(require("@mui/material/SvgIcon"));
10
9
  var _reactIntersectionObserver = require("react-intersection-observer");
11
- var _Alert = _interopRequireDefault(require("mdi-material-ui/Alert"));
12
- var _Image = _interopRequireDefault(require("mdi-material-ui/Image"));
10
+ var _alert = _interopRequireDefault(require("@iconify-icons/mdi/alert"));
11
+ var _image = _interopRequireDefault(require("@iconify-icons/mdi/image"));
12
+ var _react2 = require("@iconify/react");
13
13
  var _Theme = require("../Theme");
14
14
  var _jsxRuntime = require("react/jsx-runtime");
15
15
  const _excluded = ["lazy", "width", "height", "repeat", "ratio", "alt", "size", "position", "src", "placeholder", "fallback", "style", "className", "onError", "onSuccess"];
@@ -173,15 +173,15 @@ function Img(_ref) {
173
173
  children: [!fallback && imgState === 'error' && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
174
174
  className: "image--state",
175
175
  title: "loading image",
176
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_SvgIcon.default, {
177
- component: _Alert.default,
176
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.Icon, {
177
+ icon: _alert.default,
178
178
  className: "image--icon"
179
179
  })
180
180
  }), !placeholder && imgState === 'loading' && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
181
181
  className: "image--state",
182
182
  title: "Image load error",
183
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_SvgIcon.default, {
184
- component: _Image.default,
183
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.Icon, {
184
+ icon: _image.default,
185
185
  className: "image--icon"
186
186
  })
187
187
  }), imgState === 'loaded' && /*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = AccountItem;
7
+ var _material = require("@mui/material");
8
+ var _propTypes = _interopRequireDefault(require("prop-types"));
9
+ var _react = require("@iconify/react");
10
+ var _check = _interopRequireDefault(require("@iconify-icons/mdi/check"));
11
+ var _trashCanOutline = _interopRequireDefault(require("@iconify-icons/mdi/trash-can-outline"));
12
+ var _ahooks = require("ahooks");
13
+ var _Avatar = _interopRequireDefault(require("../Avatar"));
14
+ var _DID = _interopRequireDefault(require("../DID"));
15
+ var _util = require("../Locale/util");
16
+ var _translation = require("./translation");
17
+ var _jsxRuntime = require("react/jsx-runtime");
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+ function AccountItem(_ref) {
20
+ let {
21
+ account,
22
+ active,
23
+ onDelete,
24
+ onChoose,
25
+ locale
26
+ } = _ref;
27
+ const t = (0, _ahooks.useMemoizedFn)(function (key) {
28
+ let data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
29
+ return (0, _util.translate)(_translation.translations, key, locale, 'en', data);
30
+ });
31
+ const _onChoose = (0, _ahooks.useMemoizedFn)(() => onChoose(account, {
32
+ active
33
+ }));
34
+ const _onDelete = (0, _ahooks.useMemoizedFn)(e => {
35
+ e.preventDefault();
36
+ e.stopPropagation();
37
+ onDelete(account, {
38
+ active
39
+ });
40
+ });
41
+ if (!(account !== null && account !== void 0 && account.did) || !(account !== null && account !== void 0 && account.appName)) {
42
+ return null;
43
+ }
44
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, {
45
+ onClick: _onChoose,
46
+ sx: {
47
+ display: 'flex',
48
+ alignItems: 'center',
49
+ overflow: 'hidden',
50
+ gap: '8px',
51
+ position: 'relative',
52
+ '.account-item-actions': {
53
+ position: 'absolute',
54
+ right: 0,
55
+ top: 0,
56
+ bottom: 0,
57
+ marginRight: '12px',
58
+ display: 'flex',
59
+ alignItems: 'center'
60
+ },
61
+ '.account-item-action': {
62
+ alignItems: 'center',
63
+ display: 'none'
64
+ },
65
+ '&:hover .account-item-action': {
66
+ display: 'flex'
67
+ }
68
+ },
69
+ className: "session-manager-menu-item",
70
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Avatar.default, {
71
+ did: account.did
72
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
73
+ sx: {
74
+ flex: 1,
75
+ overflow: 'hidden',
76
+ fontSize: 0,
77
+ '.did-address-avatar': {
78
+ display: 'none !important'
79
+ }
80
+ },
81
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_DID.default, {
82
+ did: account.did,
83
+ copyable: false,
84
+ size: 14,
85
+ responsive: false,
86
+ compact: true,
87
+ sx: {
88
+ lineHeight: 1
89
+ }
90
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Typography, {
91
+ variant: "caption",
92
+ children: [t('from'), ' ', account.provider === 'federated' ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Link, {
93
+ href: account.appUrl,
94
+ target: "_blank",
95
+ underline: "none",
96
+ children: account.appName
97
+ }) : account.appName]
98
+ })]
99
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
100
+ className: "account-item-actions",
101
+ children: active ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
102
+ className: "account-item-action",
103
+ style: {
104
+ display: 'flex'
105
+ },
106
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.IconButton, {
107
+ color: "success",
108
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Icon, {
109
+ icon: _check.default,
110
+ color: "success"
111
+ })
112
+ })
113
+ }, "CheckIcon") : /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
114
+ className: "account-item-action",
115
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.IconButton, {
116
+ color: "error",
117
+ onClick: _onDelete,
118
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Icon, {
119
+ icon: _trashCanOutline.default,
120
+ color: "error"
121
+ })
122
+ })
123
+ }, "TrashCanOutlineIcon")
124
+ })]
125
+ });
126
+ }
127
+ AccountItem.propTypes = {
128
+ account: _propTypes.default.object,
129
+ active: _propTypes.default.bool,
130
+ locale: _propTypes.default.string,
131
+ onChoose: _propTypes.default.func,
132
+ onDelete: _propTypes.default.func
133
+ };
134
+ AccountItem.defaultProps = {
135
+ account: null,
136
+ active: false,
137
+ locale: 'en',
138
+ onChoose: () => {},
139
+ onDelete: () => {}
140
+ };