@arcblock/ux 2.8.26 → 2.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. package/es/Address/did-address.js +33 -21
  2. package/es/AnimationWaiter/index.js +2 -1
  3. package/es/Avatar/index.js +1 -1
  4. package/es/BlockletContext/index.js +1 -1
  5. package/es/CardSelector/index.js +2 -1
  6. package/es/Colors/index.js +2 -1
  7. package/es/Colors/themes/temp.js +17 -0
  8. package/es/Datatable/TableSearch.js +2 -1
  9. package/es/Img/index.js +7 -6
  10. package/es/Locale/selector.js +15 -13
  11. package/es/NFTDisplay/index.js +2 -1
  12. package/es/QRCode/index.js +2 -1
  13. package/es/SessionBlocklet/index.js +169 -0
  14. package/es/SessionManager/index.js +2 -381
  15. package/es/SessionPermission/index.js +28 -0
  16. package/es/SessionUser/components/logged-in.js +224 -0
  17. package/es/SessionUser/components/session-user-item.js +148 -0
  18. package/es/SessionUser/components/session-user-switch.js +213 -0
  19. package/es/SessionUser/components/un-login.js +64 -0
  20. package/es/SessionUser/components/user-info.js +163 -0
  21. package/es/SessionUser/index.js +49 -0
  22. package/es/SessionUser/libs/translation.js +19 -0
  23. package/es/SessionUser/libs/utils.js +4 -0
  24. package/es/SplitButton/index.js +2 -1
  25. package/es/Toast/index.js +1 -1
  26. package/es/Util/constant.js +10 -0
  27. package/es/Util/index.js +11 -0
  28. package/lib/Address/did-address.js +36 -22
  29. package/lib/AnimationWaiter/index.js +2 -1
  30. package/lib/Avatar/index.js +1 -1
  31. package/lib/BlockletContext/index.js +1 -1
  32. package/lib/CardSelector/index.js +2 -1
  33. package/lib/Colors/index.js +7 -0
  34. package/lib/Colors/themes/temp.js +24 -0
  35. package/lib/Datatable/TableSearch.js +2 -1
  36. package/lib/Img/index.js +7 -6
  37. package/lib/Locale/selector.js +14 -13
  38. package/lib/NFTDisplay/index.js +2 -1
  39. package/lib/QRCode/index.js +2 -1
  40. package/lib/SessionBlocklet/index.js +187 -0
  41. package/lib/SessionManager/index.js +2 -390
  42. package/lib/SessionPermission/index.js +38 -0
  43. package/lib/SessionUser/components/logged-in.js +243 -0
  44. package/lib/SessionUser/components/session-user-item.js +163 -0
  45. package/lib/SessionUser/components/session-user-switch.js +232 -0
  46. package/lib/SessionUser/components/un-login.js +72 -0
  47. package/lib/SessionUser/components/user-info.js +175 -0
  48. package/lib/SessionUser/index.js +57 -0
  49. package/lib/SessionUser/libs/translation.js +26 -0
  50. package/lib/{SessionManager → SessionUser}/libs/utils.js +8 -1
  51. package/lib/SplitButton/index.js +2 -1
  52. package/lib/Toast/index.js +5 -5
  53. package/lib/Util/constant.js +26 -0
  54. package/lib/Util/index.js +16 -3
  55. package/package.json +19 -7
  56. package/src/Address/did-address.jsx +34 -20
  57. package/src/AnimationWaiter/index.js +2 -1
  58. package/src/Avatar/index.jsx +1 -1
  59. package/src/BlockletContext/index.jsx +1 -1
  60. package/src/CardSelector/index.jsx +2 -1
  61. package/src/Colors/index.js +1 -0
  62. package/src/Colors/themes/temp.js +18 -0
  63. package/src/Datatable/TableSearch.js +3 -1
  64. package/src/Img/{index.js → index.jsx} +8 -6
  65. package/src/Locale/selector.jsx +11 -8
  66. package/src/NFTDisplay/index.js +2 -1
  67. package/src/QRCode/index.js +2 -1
  68. package/src/SessionBlocklet/index.jsx +181 -0
  69. package/src/SessionManager/index.jsx +2 -369
  70. package/src/SessionPermission/index.jsx +28 -0
  71. package/src/SessionUser/components/logged-in.jsx +194 -0
  72. package/src/SessionUser/components/session-user-item.jsx +96 -0
  73. package/src/SessionUser/components/session-user-switch.jsx +222 -0
  74. package/src/SessionUser/components/un-login.jsx +55 -0
  75. package/src/SessionUser/components/user-info.jsx +165 -0
  76. package/src/SessionUser/index.jsx +38 -0
  77. package/src/SessionUser/libs/translation.js +19 -0
  78. package/src/{SessionManager → SessionUser}/libs/utils.js +4 -0
  79. package/src/SplitButton/index.js +2 -1
  80. package/src/Toast/index.js +1 -1
  81. package/src/Util/constant.js +12 -0
  82. package/src/Util/index.js +13 -0
  83. package/es/SessionManager/components/account-item.js +0 -212
  84. package/es/SessionManager/components/add-account-item.js +0 -57
  85. package/es/SessionManager/components/federated-login-detecter.js +0 -183
  86. package/es/SessionManager/components/manage-accounts.js +0 -219
  87. package/es/SessionManager/components/manage-blocklet.js +0 -70
  88. package/es/SessionManager/components/menu-accordion.js +0 -103
  89. package/es/SessionManager/components/responsive-popper.js +0 -24
  90. package/es/SessionManager/components/user-drawer.js +0 -68
  91. package/es/SessionManager/components/user-info.js +0 -143
  92. package/es/SessionManager/components/user-popper.js +0 -110
  93. package/es/SessionManager/hooks/use-config.js +0 -34
  94. package/es/SessionManager/libs/translation.js +0 -52
  95. package/es/SessionManager/libs/utils.js +0 -2
  96. package/lib/SessionManager/components/account-item.js +0 -219
  97. package/lib/SessionManager/components/add-account-item.js +0 -66
  98. package/lib/SessionManager/components/federated-login-detecter.js +0 -193
  99. package/lib/SessionManager/components/manage-accounts.js +0 -232
  100. package/lib/SessionManager/components/manage-blocklet.js +0 -86
  101. package/lib/SessionManager/components/menu-accordion.js +0 -111
  102. package/lib/SessionManager/components/responsive-popper.js +0 -34
  103. package/lib/SessionManager/components/user-drawer.js +0 -75
  104. package/lib/SessionManager/components/user-info.js +0 -160
  105. package/lib/SessionManager/components/user-popper.js +0 -104
  106. package/lib/SessionManager/hooks/use-config.js +0 -41
  107. package/lib/SessionManager/libs/translation.js +0 -59
  108. package/src/SessionManager/components/account-item.jsx +0 -156
  109. package/src/SessionManager/components/add-account-item.jsx +0 -49
  110. package/src/SessionManager/components/federated-login-detecter.jsx +0 -167
  111. package/src/SessionManager/components/manage-accounts.jsx +0 -228
  112. package/src/SessionManager/components/manage-blocklet.jsx +0 -70
  113. package/src/SessionManager/components/menu-accordion.jsx +0 -93
  114. package/src/SessionManager/components/responsive-popper.jsx +0 -26
  115. package/src/SessionManager/components/user-drawer.jsx +0 -57
  116. package/src/SessionManager/components/user-info.jsx +0 -117
  117. package/src/SessionManager/components/user-popper.jsx +0 -95
  118. package/src/SessionManager/hooks/use-config.js +0 -33
  119. package/src/SessionManager/libs/translation.js +0 -52
@@ -1,117 +0,0 @@
1
- /* eslint-disable react/jsx-no-bind */
2
- /* eslint-disable react/prop-types */
3
- import { Box, Chip } 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
-
9
- import DidAvatar from '../../Avatar';
10
- import DidAddress from '../../Address';
11
- import DID from '../../DID';
12
- import { getUserAvatar } from '../../Util';
13
- import { t as translate } from '../../Locale/util';
14
- import { translations } from '../libs/translation';
15
- import Typography from '../../Typography';
16
-
17
- export default function UserInfo({ session, locale, onSwitchProfile, onSwitchPassport, switchProfile, hasBindWallet }) {
18
- const t = (key, data = {}) => {
19
- return translate(translations, key, locale, 'en', data);
20
- };
21
- const avatar = getUserAvatar(session.user?.avatar?.replace(/\s/g, encodeURIComponent(' ')), 64);
22
- const { walletDid } = session.useDid({ session });
23
- const currentRole = useCreation(
24
- () => session.user?.passports?.find((item) => item.name === session.user.role),
25
- [session?.user?.passports, session?.user?.role]
26
- );
27
- const userEmail = useCreation(() => session.user?.email, [session?.user]);
28
-
29
- const canEdit = useCreation(() => {
30
- if (onSwitchProfile instanceof Function) {
31
- if (switchProfile && hasBindWallet) {
32
- return true;
33
- }
34
- }
35
- return false;
36
- }, [onSwitchProfile, switchProfile, hasBindWallet, session.provider]);
37
-
38
- const _onSwitchProfile = useMemoizedFn(() => {
39
- if (window.blocklet?.appPid) {
40
- window.location.href = '/.well-known/service/user/profile';
41
- } else if (canEdit) {
42
- onSwitchProfile();
43
- }
44
- });
45
-
46
- return (
47
- <Box
48
- sx={{
49
- display: 'flex',
50
- alignItems: 'center',
51
- gap: '12px',
52
- padding: '15px',
53
- }}>
54
- <Box
55
- onClick={_onSwitchProfile}
56
- data-cy="sessionManager-switch-profile-trigger"
57
- sx={{
58
- cursor: canEdit ? 'pointer' : 'default',
59
- position: 'relative',
60
- borderRadius: '100%',
61
- overflow: 'hidden',
62
- fontSize: 0,
63
- '&:hover': canEdit
64
- ? {
65
- '&::after': {
66
- content: `"${t('switch')}"`,
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
- }}>
81
- <DidAvatar variant="circle" did={session.user.did} src={avatar} size={64} shape="circle" />
82
- </Box>
83
- <Box sx={{ flex: 1, position: 'static', overflow: 'hidden', fontSize: '14px' }}>
84
- <Typography variant="h5" fontWeight="bold" sx={{ wordBreak: 'break-all', lineHeight: 1 }}>
85
- {session.user.fullName}
86
- </Typography>
87
- <Chip
88
- label={currentRole?.title || session.user?.role.toUpperCase()}
89
- size="small"
90
- variant="outlined"
91
- sx={{
92
- height: 'auto',
93
- marginRight: 0,
94
- fontWeight: 'bold',
95
- fontSize: '12px',
96
- margin: '6px 0 4px 0',
97
- }}
98
- icon={<Icon icon={ShieldCheckIcon} height="0.8em" />}
99
- deleteIcon={<Icon icon={ExpandMoreIcon} height="1em" />}
100
- // HACK: 必须设置 onDelete 函数,deleteIcon 才能显示出来
101
- onDelete={onSwitchPassport}
102
- onClick={onSwitchPassport}
103
- data-cy="sessionManager-switch-passport-trigger"
104
- />
105
- {/* eslint-disable-next-line no-nested-ternary */}
106
- {session.provider === 'auth0' ? (
107
- walletDid ? (
108
- <DID responsive={false} compact did={walletDid} />
109
- ) : null
110
- ) : (
111
- <DID responsive={false} compact did={session.user.did} />
112
- )}
113
- {userEmail ? <DidAddress responsive={false}>{userEmail}</DidAddress> : null}
114
- </Box>
115
- </Box>
116
- );
117
- }
@@ -1,95 +0,0 @@
1
- import PropTypes from 'prop-types';
2
- import { IconButton, Paper, Popper, ClickAwayListener } from '@mui/material';
3
- import CloseIcon from '@iconify-icons/mdi/close';
4
- import { Icon } from '@iconify/react';
5
- import { styled } from '../../Theme';
6
-
7
- export default function UserPopper({ anchorEl, dark, children, open, onClose, autoClose }) {
8
- return (
9
- anchorEl && (
10
- <StyledPopper open={open} disablePortal anchorEl={anchorEl} placement="bottom-end" $dark={dark}>
11
- <Paper
12
- sx={[
13
- (theme) => ({
14
- borderColor: '#F0F0F0',
15
- boxShadow: '0px 8px 12px rgba(92, 92, 92, 0.04)',
16
- borderRadius: theme.spacing(2),
17
- overflow: 'auto',
18
- maxWidth: 'calc(100vw - 10px)',
19
- maxHeight: 'calc(100vh - 80px)',
20
- '& .MuiChip-root .MuiChip-icon': {
21
- color: theme.palette.success.main,
22
- },
23
- '& .MuiList-root': {
24
- width: '320px',
25
- },
26
- }),
27
- dark && {
28
- backgroundColor: '#27282c',
29
- color: '#fff',
30
- border: 0,
31
- '& .MuiChip-root': {
32
- borderColor: '#aaa',
33
- },
34
- '& .MuiListItem-root, & .MuiChip-label': {
35
- color: '#aaa',
36
- },
37
- '& .MuiListItem-root:hover': {
38
- backgroundColor: '#363434',
39
- },
40
- },
41
- ]}
42
- variant="outlined">
43
- {autoClose ? (
44
- <ClickAwayListener onClickAway={onClose}>{children}</ClickAwayListener>
45
- ) : (
46
- <>
47
- <IconButton
48
- size="small"
49
- sx={{ cursor: 'pointer', position: 'absolute', right: 0, top: 0, zIndex: 1 }}
50
- onClick={onClose}>
51
- <Icon icon={CloseIcon} width={20} height={20} />
52
- </IconButton>
53
- {children}
54
- </>
55
- )}
56
- </Paper>
57
- </StyledPopper>
58
- )
59
- );
60
- }
61
-
62
- UserPopper.propTypes = {
63
- anchorEl: PropTypes.instanceOf(Element),
64
- dark: PropTypes.bool,
65
- open: PropTypes.bool,
66
- children: PropTypes.any.isRequired,
67
- onClose: PropTypes.func,
68
- autoClose: PropTypes.bool,
69
- };
70
- UserPopper.defaultProps = {
71
- anchorEl: null,
72
- dark: false,
73
- open: false,
74
- onClose: () => {},
75
- autoClose: true,
76
- };
77
-
78
- const StyledPopper = styled(Popper)`
79
- z-index: ${({ theme }) => {
80
- return theme.zIndex.tooltip;
81
- }};
82
-
83
- .session-manager-menu-item {
84
- padding: 15px;
85
- color: #777;
86
- font-size: 16px;
87
- &:hover {
88
- background-color: #fbfbfb;
89
- }
90
- }
91
- .session-manager-menu-icon {
92
- color: #999;
93
- margin-right: 8px;
94
- }
95
- `;
@@ -1,33 +0,0 @@
1
- import { useLocalStorageState, useMemoizedFn } from 'ahooks';
2
- import cloneDeep from 'lodash/cloneDeep';
3
-
4
- export default function useConfig() {
5
- const [config, setConfig] = useLocalStorageState('blocklet:sessionManager:config', {
6
- defaultValue: {
7
- accounts: [],
8
- expandAccount: true,
9
- expandBlocklet: true,
10
- },
11
- });
12
-
13
- const connectAccount = useMemoizedFn((account) => {
14
- const cloneConfig = cloneDeep(config);
15
- const accountIndex = cloneConfig.accounts.findIndex((x) => x.did === account.did);
16
- if (accountIndex >= 0) {
17
- cloneConfig.accounts.splice(accountIndex, 1);
18
- }
19
- cloneConfig.accounts.unshift(account);
20
- setConfig(cloneConfig);
21
- });
22
-
23
- const deleteAccount = useMemoizedFn((account) => {
24
- const cloneConfig = cloneDeep(config);
25
- const findIndex = cloneConfig.accounts.findIndex((item) => item.did === account.did);
26
- if (findIndex >= 0) {
27
- cloneConfig.accounts.splice(findIndex, 1);
28
- }
29
- setConfig(cloneConfig);
30
- });
31
-
32
- return { config, setConfig, connectAccount, deleteAccount };
33
- }
@@ -1,52 +0,0 @@
1
- /* eslint-disable import/prefer-default-export */
2
- export const translations = {
3
- en: {
4
- switch: 'Switch',
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
- addAppAccount: 'Add {appName} account',
17
- accounts: 'Accounts',
18
- blocklet: 'Blocklet',
19
- from: 'From',
20
- addAnotherAccount: 'Add another account',
21
- deleteAccountTitle: 'Remove this account ?',
22
- deleteAccountContent: 'After delete account, you can add it again',
23
- confirm: 'Confirm',
24
- cancel: 'Cancel',
25
- noneMenu: 'Empty menu, maybe you should switch to another role',
26
- },
27
- zh: {
28
- switch: '切换',
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
- addAppAccount: '添加 {appName} 账户',
42
- accounts: '账户',
43
- blocklet: '应用',
44
- from: '连接至',
45
- addAnotherAccount: '添加账号',
46
- deleteAccountTitle: '是否删除账户?',
47
- deleteAccountContent: '账户删除后,可再次添加',
48
- confirm: '确认',
49
- cancel: '取消',
50
- noneMenu: '无操作项,请尝试切换角色',
51
- },
52
- };