@arcblock/ux 2.7.16 → 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/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 +8 -4
- 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
@@ -1,10 +1,11 @@
|
|
1
1
|
/* eslint-disable react/prop-types */
|
2
2
|
/* eslint-disable react/jsx-no-bind */
|
3
3
|
import { useMemoizedFn, useUpdate } from 'ahooks';
|
4
|
-
import { MenuItem } from '@mui/material';
|
4
|
+
import { MenuItem, SvgIcon } from '@mui/material';
|
5
5
|
import { Icon } from '@iconify/react';
|
6
6
|
import AccountIcon from '@arcblock/icons/lib/Account';
|
7
7
|
import LinkIcon from '@iconify-icons/mdi/link';
|
8
|
+
import DisconnectIcon from '@arcblock/icons/lib/Disconnect';
|
8
9
|
|
9
10
|
import AccountItem from './account-item';
|
10
11
|
import MenuAccordion from './menu-accordion';
|
@@ -13,7 +14,7 @@ import { translate } from '../Locale/util';
|
|
13
14
|
import { useConfirm } from '../Dialog/confirm';
|
14
15
|
import { getSourceProvider } from './utils';
|
15
16
|
import AddAccountItem from './add-account-item';
|
16
|
-
import
|
17
|
+
import useConfig from './use-config';
|
17
18
|
|
18
19
|
export default function ManageAccounts({
|
19
20
|
session,
|
@@ -23,6 +24,10 @@ export default function ManageAccounts({
|
|
23
24
|
connectAccount,
|
24
25
|
close,
|
25
26
|
hasBindAccount,
|
27
|
+
disableLogout,
|
28
|
+
onLogout,
|
29
|
+
expanded,
|
30
|
+
onExpand,
|
26
31
|
}) {
|
27
32
|
const { bindOAuth, configs: oauthConfigs } = session.useOAuth();
|
28
33
|
const t = useMemoizedFn((key, data = {}) => {
|
@@ -30,7 +35,7 @@ export default function ManageAccounts({
|
|
30
35
|
});
|
31
36
|
|
32
37
|
const { confirmApi, confirmHolder } = useConfirm();
|
33
|
-
const {
|
38
|
+
const { deleteAccount, config } = useConfig();
|
34
39
|
const update = useUpdate();
|
35
40
|
|
36
41
|
const onChoose = useMemoizedFn((account, { active }) => {
|
@@ -45,7 +50,7 @@ export default function ManageAccounts({
|
|
45
50
|
},
|
46
51
|
{
|
47
52
|
provider: account.provider,
|
48
|
-
|
53
|
+
sourceAppPid: account.sourceAppPid,
|
49
54
|
}
|
50
55
|
);
|
51
56
|
});
|
@@ -68,11 +73,8 @@ export default function ManageAccounts({
|
|
68
73
|
confirmButtonText: t('confirm'),
|
69
74
|
cancelButtonText: t('cancel'),
|
70
75
|
onConfirm(done) {
|
71
|
-
|
72
|
-
|
73
|
-
accounts.splice(findIndex, 1);
|
74
|
-
}
|
75
|
-
setAccounts(accounts);
|
76
|
+
deleteAccount(account);
|
77
|
+
|
76
78
|
update();
|
77
79
|
done();
|
78
80
|
},
|
@@ -88,8 +90,8 @@ export default function ManageAccounts({
|
|
88
90
|
onSwitchDid(...args);
|
89
91
|
},
|
90
92
|
{
|
93
|
+
sourceAppPid: app.sourceAppPid,
|
91
94
|
provider: app.provider,
|
92
|
-
providerMode: 'paramsFirst',
|
93
95
|
}
|
94
96
|
);
|
95
97
|
});
|
@@ -107,14 +109,16 @@ export default function ManageAccounts({
|
|
107
109
|
return (
|
108
110
|
<>
|
109
111
|
<MenuAccordion
|
112
|
+
expanded={expanded}
|
113
|
+
onChange={onExpand}
|
110
114
|
locale={locale}
|
111
115
|
title={
|
112
116
|
<>
|
113
117
|
<AccountIcon className="session-manager-menu-icon" style={{ width: 24, height: 24 }} />
|
114
|
-
{t('
|
118
|
+
{t('accounts')}
|
115
119
|
</>
|
116
120
|
}>
|
117
|
-
{accounts.map((item) => (
|
121
|
+
{config.accounts.map((item) => (
|
118
122
|
<AccountItem
|
119
123
|
key={item.did}
|
120
124
|
account={item}
|
@@ -126,7 +130,7 @@ export default function ManageAccounts({
|
|
126
130
|
))}
|
127
131
|
<AddAccountItem locale={locale} onAdd={onAdd} />
|
128
132
|
|
129
|
-
{oauthConfigList.length > 0 && !hasBindAccount &&
|
133
|
+
{oauthConfigList.length > 0 && !hasBindAccount && (
|
130
134
|
<MenuItem
|
131
135
|
className="session-manager-menu-item"
|
132
136
|
onClick={_onBindWallet}
|
@@ -136,6 +140,16 @@ export default function ManageAccounts({
|
|
136
140
|
{!isRawWalletAccount ? `${t('bind')}DID Wallet` : `${t('bind')}${t('thirdParty')}`}
|
137
141
|
</MenuItem>
|
138
142
|
)}
|
143
|
+
|
144
|
+
<MenuItem
|
145
|
+
className="session-manager-menu-item"
|
146
|
+
onClick={onLogout}
|
147
|
+
disabled={disableLogout}
|
148
|
+
aria-label="Logout account"
|
149
|
+
data-cy="sessionManager-logout-trigger">
|
150
|
+
<SvgIcon component={DisconnectIcon} className="session-manager-menu-icon" />
|
151
|
+
{t('disconnect')}
|
152
|
+
</MenuItem>
|
139
153
|
</MenuAccordion>
|
140
154
|
{confirmHolder}
|
141
155
|
</>
|
@@ -9,18 +9,20 @@ import MenuAccordion from './menu-accordion';
|
|
9
9
|
import { translate } from '../Locale/util';
|
10
10
|
import { translations } from './translation';
|
11
11
|
|
12
|
-
export default function ManageBlocklet({ menu, menuRender, locale }) {
|
12
|
+
export default function ManageBlocklet({ menu, menuRender, locale, expanded, onExpand }) {
|
13
13
|
const t = useMemoizedFn((key, data = {}) => {
|
14
14
|
return translate(translations, key, locale, 'en', data);
|
15
15
|
});
|
16
16
|
|
17
17
|
return (
|
18
18
|
<MenuAccordion
|
19
|
+
expanded={expanded}
|
19
20
|
locale={locale}
|
21
|
+
onChange={onExpand}
|
20
22
|
title={
|
21
23
|
<>
|
22
24
|
<Icon icon={AppsIcon} width={24} height={24} className="session-manager-menu-icon" />
|
23
|
-
{t('
|
25
|
+
{t('blocklet')}
|
24
26
|
</>
|
25
27
|
}>
|
26
28
|
{Array.isArray(menu) &&
|
@@ -56,9 +58,13 @@ ManageBlocklet.propTypes = {
|
|
56
58
|
menu: PropTypes.array,
|
57
59
|
menuRender: PropTypes.func,
|
58
60
|
locale: PropTypes.string.isRequired,
|
61
|
+
expanded: PropTypes.bool,
|
62
|
+
onExpand: PropTypes.func,
|
59
63
|
};
|
60
64
|
|
61
65
|
ManageBlocklet.defaultProps = {
|
62
66
|
menu: [],
|
63
67
|
menuRender: () => {},
|
68
|
+
expanded: true,
|
69
|
+
onExpand: () => {},
|
64
70
|
};
|
@@ -21,7 +21,7 @@ function isEmptyNode(node) {
|
|
21
21
|
return false;
|
22
22
|
}
|
23
23
|
|
24
|
-
export default function MenuAccordion({ title, children, locale }) {
|
24
|
+
export default function MenuAccordion({ title, children, locale, expanded, onChange }) {
|
25
25
|
const isEmptyChildren = useCreation(() => isEmptyNode(children), [children]);
|
26
26
|
const t = useMemoizedFn((key, data = {}) => {
|
27
27
|
return translate(translations, key, locale, 'en', data);
|
@@ -29,9 +29,12 @@ export default function MenuAccordion({ title, children, locale }) {
|
|
29
29
|
|
30
30
|
return (
|
31
31
|
<Accordion
|
32
|
-
|
32
|
+
expanded={expanded}
|
33
33
|
disableGutters
|
34
34
|
elevation={0}
|
35
|
+
onChange={(e, value) => {
|
36
|
+
onChange(value);
|
37
|
+
}}
|
35
38
|
sx={{
|
36
39
|
'&.MuiAccordion-root:before': {
|
37
40
|
content: 'unset',
|
@@ -48,7 +51,7 @@ export default function MenuAccordion({ title, children, locale }) {
|
|
48
51
|
paddingLeft: '30px',
|
49
52
|
'.session-manager-menu-item': {
|
50
53
|
fontSize: '15px',
|
51
|
-
padding: '12px
|
54
|
+
padding: '12px 15px',
|
52
55
|
whiteSpace: 'normal',
|
53
56
|
},
|
54
57
|
'.session-manager-menu-icon': {
|
@@ -81,7 +84,11 @@ MenuAccordion.propTypes = {
|
|
81
84
|
title: PropTypes.any.isRequired,
|
82
85
|
children: PropTypes.any.isRequired,
|
83
86
|
locale: PropTypes.string,
|
87
|
+
expanded: PropTypes.bool,
|
88
|
+
onChange: PropTypes.func,
|
84
89
|
};
|
85
90
|
MenuAccordion.defaultProps = {
|
86
91
|
locale: 'en',
|
92
|
+
expanded: true,
|
93
|
+
onChange: () => {},
|
87
94
|
};
|
@@ -1,7 +1,7 @@
|
|
1
1
|
/* eslint-disable import/prefer-default-export */
|
2
2
|
export const translations = {
|
3
3
|
en: {
|
4
|
-
|
4
|
+
switch: 'Switch',
|
5
5
|
account: 'account',
|
6
6
|
switchDid: 'Switch DID',
|
7
7
|
switchTo: 'Switch to',
|
@@ -13,9 +13,9 @@ export const translations = {
|
|
13
13
|
alreadyBindOAuth: 'Already bind Auth0',
|
14
14
|
bind: 'Bind ',
|
15
15
|
thirdParty: 'Third Party Login',
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
addAppAccount: 'Add {appName} account',
|
17
|
+
accounts: 'Accounts',
|
18
|
+
blocklet: 'Blocklet',
|
19
19
|
from: 'From',
|
20
20
|
addAnotherAccount: 'Add another account',
|
21
21
|
deleteAccountTitle: 'Remove this account ?',
|
@@ -25,24 +25,24 @@ export const translations = {
|
|
25
25
|
noneMenu: 'Empty menu, maybe you should switch to another role',
|
26
26
|
},
|
27
27
|
zh: {
|
28
|
-
|
28
|
+
switch: '切换',
|
29
29
|
account: '账号',
|
30
30
|
switchDid: '切换账户',
|
31
31
|
switchTo: '切换至',
|
32
32
|
switchProfile: '切换用户信息',
|
33
33
|
switchPassport: '切换通行证',
|
34
|
-
disconnect: '
|
34
|
+
disconnect: '退出登录',
|
35
35
|
connect: '登录',
|
36
36
|
openInWallet: '打开 DID 钱包',
|
37
37
|
// NOTE: 目前只有 Auth0,展示出具体的第三方名字会更好
|
38
38
|
alreadyBindOAuth: '已绑定 Auth0 账号',
|
39
39
|
bind: '绑定',
|
40
40
|
thirdParty: '第三方登录',
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
addAppAccount: '添加 {appName} 账户',
|
42
|
+
accounts: '账户',
|
43
|
+
blocklet: '应用',
|
44
44
|
from: '连接至',
|
45
|
-
addAnotherAccount: '
|
45
|
+
addAnotherAccount: '添加账号',
|
46
46
|
deleteAccountTitle: '是否删除账户?',
|
47
47
|
deleteAccountContent: '账户删除后,可再次添加',
|
48
48
|
confirm: '确认',
|
@@ -0,0 +1,33 @@
|
|
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,6 +1,6 @@
|
|
1
1
|
/* eslint-disable react/jsx-no-bind */
|
2
2
|
/* eslint-disable react/prop-types */
|
3
|
-
import { Box, Chip
|
3
|
+
import { Box, Chip } from '@mui/material';
|
4
4
|
import ShieldCheckIcon from '@iconify-icons/mdi/shield-check';
|
5
5
|
import ExpandMoreIcon from '@iconify-icons/mdi/expand-more';
|
6
6
|
import { Icon } from '@iconify/react';
|
@@ -12,8 +12,9 @@ import DID from '../DID';
|
|
12
12
|
import { getUserAvatar } from '../Util';
|
13
13
|
import { t as translate } from '../Locale/util';
|
14
14
|
import { translations } from './translation';
|
15
|
+
import Typography from '../Typography';
|
15
16
|
|
16
|
-
export default function UserInfo({ session, locale,
|
17
|
+
export default function UserInfo({ session, locale, onSwitchProfile, onSwitchPassport, switchProfile, hasBindWallet }) {
|
17
18
|
const t = (key, data = {}) => {
|
18
19
|
return translate(translations, key, locale, 'en', data);
|
19
20
|
};
|
@@ -26,17 +27,17 @@ export default function UserInfo({ session, locale, onEditUser, onSwitchPassport
|
|
26
27
|
const userEmail = useCreation(() => session.user?.email || 'lancelot_lewis@163.com', [session?.user]);
|
27
28
|
|
28
29
|
const canEdit = useCreation(() => {
|
29
|
-
if (
|
30
|
-
if (switchProfile && hasBindWallet
|
30
|
+
if (onSwitchProfile instanceof Function) {
|
31
|
+
if (switchProfile && hasBindWallet) {
|
31
32
|
return true;
|
32
33
|
}
|
33
34
|
}
|
34
35
|
return false;
|
35
|
-
}, [
|
36
|
+
}, [onSwitchProfile, switchProfile, hasBindWallet, session.provider]);
|
36
37
|
|
37
|
-
const
|
38
|
+
const _onSwitchProfile = useMemoizedFn(() => {
|
38
39
|
if (canEdit) {
|
39
|
-
|
40
|
+
onSwitchProfile();
|
40
41
|
}
|
41
42
|
});
|
42
43
|
|
@@ -45,11 +46,11 @@ export default function UserInfo({ session, locale, onEditUser, onSwitchPassport
|
|
45
46
|
sx={{
|
46
47
|
display: 'flex',
|
47
48
|
alignItems: 'center',
|
48
|
-
gap: '
|
49
|
-
padding: '15px
|
49
|
+
gap: '12px',
|
50
|
+
padding: '15px',
|
50
51
|
}}>
|
51
52
|
<Box
|
52
|
-
onClick={
|
53
|
+
onClick={_onSwitchProfile}
|
53
54
|
data-cy="sessionManager-switch-profile-trigger"
|
54
55
|
sx={{
|
55
56
|
cursor: canEdit ? 'pointer' : 'default',
|
@@ -60,7 +61,7 @@ export default function UserInfo({ session, locale, onEditUser, onSwitchPassport
|
|
60
61
|
'&:hover': canEdit
|
61
62
|
? {
|
62
63
|
'&::after': {
|
63
|
-
content: `"${t('
|
64
|
+
content: `"${t('switch')}"`,
|
64
65
|
position: 'absolute',
|
65
66
|
bottom: 0,
|
66
67
|
background: 'rgba(0, 0, 0, 0.2)',
|
@@ -78,9 +79,28 @@ export default function UserInfo({ session, locale, onEditUser, onSwitchPassport
|
|
78
79
|
<DidAvatar variant="circle" did={session.user.did} src={avatar} size={64} shape="circle" />
|
79
80
|
</Box>
|
80
81
|
<Box sx={{ flex: 1, position: 'static', overflow: 'hidden', fontSize: '14px' }}>
|
81
|
-
<
|
82
|
-
{
|
83
|
-
|
82
|
+
<Box display="flex" alignItems="center" gap="4px" mb={0.5}>
|
83
|
+
<Typography variant="h5" fontWeight="bold" fontSize="auto" sx={{ flex: 1, wordBreak: 'break-all' }}>
|
84
|
+
{session.user.fullName}
|
85
|
+
</Typography>
|
86
|
+
<Chip
|
87
|
+
label={currentRole?.title || session.user?.role.toUpperCase()}
|
88
|
+
size="small"
|
89
|
+
variant="outlined"
|
90
|
+
sx={{
|
91
|
+
height: 'auto',
|
92
|
+
marginRight: 0,
|
93
|
+
fontWeight: 'bold',
|
94
|
+
fontSize: '12px',
|
95
|
+
}}
|
96
|
+
icon={<Icon icon={ShieldCheckIcon} height="0.8em" />}
|
97
|
+
deleteIcon={<Icon icon={ExpandMoreIcon} height="1em" />}
|
98
|
+
// HACK: 必须设置 onDelete 函数,deleteIcon 才能显示出来
|
99
|
+
onDelete={onSwitchPassport}
|
100
|
+
onClick={onSwitchPassport}
|
101
|
+
data-cy="sessionManager-switch-passport-trigger"
|
102
|
+
/>
|
103
|
+
</Box>
|
84
104
|
{/* eslint-disable-next-line no-nested-ternary */}
|
85
105
|
{session.provider === 'auth0' ? (
|
86
106
|
walletDid ? (
|
@@ -90,26 +110,6 @@ export default function UserInfo({ session, locale, onEditUser, onSwitchPassport
|
|
90
110
|
<DID responsive={false} compact did={session.user.did} />
|
91
111
|
)}
|
92
112
|
{userEmail ? <DidAddress responsive={false}>{userEmail}</DidAddress> : null}
|
93
|
-
<Chip
|
94
|
-
label={currentRole?.title || session.user?.role.toUpperCase()}
|
95
|
-
size="small"
|
96
|
-
variant="outlined"
|
97
|
-
sx={{
|
98
|
-
height: 'auto',
|
99
|
-
marginRight: 0,
|
100
|
-
position: 'absolute',
|
101
|
-
top: 20,
|
102
|
-
right: 15,
|
103
|
-
fontWeight: 'bold',
|
104
|
-
fontSize: '12px',
|
105
|
-
}}
|
106
|
-
icon={<Icon icon={ShieldCheckIcon} height="0.8em" />}
|
107
|
-
deleteIcon={<Icon icon={ExpandMoreIcon} height="1em" />}
|
108
|
-
// HACK: 必须设置 onDelete 函数,deleteIcon 才能显示出来
|
109
|
-
onDelete={onSwitchPassport}
|
110
|
-
onClick={onSwitchPassport}
|
111
|
-
data-cy="sessionManager-switch-passport-trigger"
|
112
|
-
/>
|
113
113
|
</Box>
|
114
114
|
</Box>
|
115
115
|
);
|
@@ -78,23 +78,8 @@ const StyledPopper = styled(Popper)`
|
|
78
78
|
.MuiList-root {
|
79
79
|
width: 320px;
|
80
80
|
}
|
81
|
-
.session-manager-user {
|
82
|
-
font-size: 12px;
|
83
|
-
flex-direction: column;
|
84
|
-
align-items: flex-start;
|
85
|
-
padding: 24px 24px 10px;
|
86
|
-
}
|
87
|
-
.session-manager-user-name {
|
88
|
-
font-size: 20px;
|
89
|
-
color: ${({ $dark }) => ($dark ? '#aaa' : '#222')};
|
90
|
-
font-weight: bold;
|
91
|
-
margin-bottom: 10px;
|
92
|
-
display: flex;
|
93
|
-
align-items: center;
|
94
|
-
justify-content: space-between;
|
95
|
-
}
|
96
81
|
.session-manager-menu-item {
|
97
|
-
padding:
|
82
|
+
padding: 15px;
|
98
83
|
color: #777;
|
99
84
|
font-size: 16px;
|
100
85
|
&:hover {
|
@@ -0,0 +1,79 @@
|
|
1
|
+
import PropTyps from 'prop-types';
|
2
|
+
import { Box, Typography as MuiTypography, Skeleton } from '@mui/material';
|
3
|
+
import { useReactive, useSize } from 'ahooks';
|
4
|
+
import { useEffect, useRef } from 'react';
|
5
|
+
|
6
|
+
export default function Typography({ minFontSize, fontSize, children, sx, ...rest }) {
|
7
|
+
const refMock = useRef(null);
|
8
|
+
const refContainer = useRef(null);
|
9
|
+
const state = useReactive({
|
10
|
+
fontSize,
|
11
|
+
loading: true,
|
12
|
+
initialSize: undefined,
|
13
|
+
});
|
14
|
+
const mockSize = useSize(refMock.current);
|
15
|
+
const containerSize = useSize(refContainer.current);
|
16
|
+
useEffect(() => {
|
17
|
+
if (state.loading) {
|
18
|
+
if (fontSize === 'auto') {
|
19
|
+
if (mockSize && !state.initialSize) {
|
20
|
+
const styleSize = getComputedStyle(refMock.current).fontSize;
|
21
|
+
state.initialSize = Number(styleSize.replace('px', ''));
|
22
|
+
state.fontSize = state.initialSize;
|
23
|
+
}
|
24
|
+
if (containerSize && mockSize) {
|
25
|
+
if (containerSize.width < mockSize.width && state.fontSize > minFontSize) {
|
26
|
+
state.fontSize--;
|
27
|
+
} else {
|
28
|
+
state.loading = false;
|
29
|
+
}
|
30
|
+
}
|
31
|
+
} else {
|
32
|
+
state.loading = false;
|
33
|
+
}
|
34
|
+
}
|
35
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
36
|
+
}, [fontSize, mockSize?.width, containerSize?.width]);
|
37
|
+
|
38
|
+
return state.loading ? (
|
39
|
+
<Box ref={refContainer} flex={1}>
|
40
|
+
<MuiTypography {...rest} sx={sx} noWrap>
|
41
|
+
<Skeleton variant="text" sx={{ fontSize: '1rem' }} />
|
42
|
+
</MuiTypography>
|
43
|
+
<MuiTypography
|
44
|
+
ref={refMock}
|
45
|
+
{...rest}
|
46
|
+
sx={{
|
47
|
+
...sx,
|
48
|
+
fontSize: `${state.fontSize}px !important`,
|
49
|
+
position: 'fixed',
|
50
|
+
top: -1000,
|
51
|
+
left: -1000,
|
52
|
+
}}
|
53
|
+
noWrap>
|
54
|
+
{children}
|
55
|
+
</MuiTypography>
|
56
|
+
</Box>
|
57
|
+
) : (
|
58
|
+
<MuiTypography
|
59
|
+
{...rest}
|
60
|
+
sx={{
|
61
|
+
...sx,
|
62
|
+
fontSize: `${state.fontSize}px !important`,
|
63
|
+
}}>
|
64
|
+
{children}
|
65
|
+
</MuiTypography>
|
66
|
+
);
|
67
|
+
}
|
68
|
+
|
69
|
+
Typography.propTypes = {
|
70
|
+
fontSize: PropTyps.oneOfType([PropTyps.string, PropTyps.number]),
|
71
|
+
children: PropTyps.any.isRequired,
|
72
|
+
minFontSize: PropTyps.number,
|
73
|
+
sx: PropTyps.object,
|
74
|
+
};
|
75
|
+
Typography.defaultProps = {
|
76
|
+
fontSize: undefined,
|
77
|
+
minFontSize: 12,
|
78
|
+
sx: {},
|
79
|
+
};
|
@@ -0,0 +1,73 @@
|
|
1
|
+
import isEmpty from 'lodash/isEmpty';
|
2
|
+
|
3
|
+
export function getMaster(blocklet = window.blocklet) {
|
4
|
+
const federated = blocklet?.settings?.federated || {};
|
5
|
+
return federated.master;
|
6
|
+
}
|
7
|
+
|
8
|
+
export function getConfig(blocklet = window.blocklet) {
|
9
|
+
const federated = blocklet?.settings?.federated || {};
|
10
|
+
return federated.config;
|
11
|
+
}
|
12
|
+
|
13
|
+
export function getAutoLoginFederated(blocklet = window.blocklet) {
|
14
|
+
const config = getConfig(blocklet);
|
15
|
+
return Boolean(config?.autoLogin) && config?.status === 'approved';
|
16
|
+
}
|
17
|
+
|
18
|
+
export function getSourceAppPid(blocklet = window.blocklet) {
|
19
|
+
const master = getMaster(blocklet);
|
20
|
+
return master?.appPid;
|
21
|
+
}
|
22
|
+
|
23
|
+
export function getFederatedApp(blocklet = window.blocklet) {
|
24
|
+
const master = getMaster(blocklet);
|
25
|
+
const isFederatedMode = !isEmpty(master);
|
26
|
+
return isFederatedMode
|
27
|
+
? {
|
28
|
+
appId: master.appId,
|
29
|
+
appName: master.appName,
|
30
|
+
appDescription: master.appDescription,
|
31
|
+
appLogo: master.appLogo,
|
32
|
+
appPid: master.appPid,
|
33
|
+
appUrl: master.appUrl,
|
34
|
+
version: master.version,
|
35
|
+
sourceAppPid: master.appPid,
|
36
|
+
provider: 'wallet',
|
37
|
+
}
|
38
|
+
: null;
|
39
|
+
}
|
40
|
+
|
41
|
+
export function getCurrentApp(blocklet = window.blocklet) {
|
42
|
+
// 适用于 blocklet 项目
|
43
|
+
if (blocklet) {
|
44
|
+
return {
|
45
|
+
appId: blocklet.appId,
|
46
|
+
appName: blocklet.appName,
|
47
|
+
appDescription: blocklet.appDescription,
|
48
|
+
appLogo: blocklet.appLogo,
|
49
|
+
appPid: blocklet.appPid,
|
50
|
+
appUrl: blocklet.appUrl,
|
51
|
+
version: blocklet.version,
|
52
|
+
// NOTICE: null 代表该值置空
|
53
|
+
sourceAppPid: null,
|
54
|
+
provider: 'wallet',
|
55
|
+
};
|
56
|
+
}
|
57
|
+
// HACK: 适用于 blockelt-server
|
58
|
+
if (window.env) {
|
59
|
+
// eslint-disable-next-line no-param-reassign
|
60
|
+
blocklet = window.env;
|
61
|
+
return {
|
62
|
+
appId: blocklet.appId,
|
63
|
+
appName: blocklet.appName,
|
64
|
+
appDescription: blocklet.appDescription,
|
65
|
+
appUrl: blocklet.baseUrl,
|
66
|
+
// NOTICE: null 代表该值置空
|
67
|
+
sourceAppPid: null,
|
68
|
+
provider: 'wallet',
|
69
|
+
type: 'server',
|
70
|
+
};
|
71
|
+
}
|
72
|
+
return null;
|
73
|
+
}
|
@@ -1,19 +0,0 @@
|
|
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
|
-
}
|
@@ -1,25 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.default = useAccounts;
|
7
|
-
var _ahooks = require("ahooks");
|
8
|
-
function useAccounts() {
|
9
|
-
const [accounts, setAccounts] = (0, _ahooks.useLocalStorageState)('blocklet:sessionManager:accounts', {
|
10
|
-
defaultValue: []
|
11
|
-
});
|
12
|
-
const connectAccount = (0, _ahooks.useMemoizedFn)(account => {
|
13
|
-
const accountIndex = accounts.findIndex(x => x.did === account.did);
|
14
|
-
if (accountIndex >= 0) {
|
15
|
-
accounts.splice(accountIndex, 1);
|
16
|
-
}
|
17
|
-
accounts.unshift(account);
|
18
|
-
setAccounts(accounts);
|
19
|
-
});
|
20
|
-
return {
|
21
|
-
accounts,
|
22
|
-
setAccounts,
|
23
|
-
connectAccount
|
24
|
-
};
|
25
|
-
}
|
@@ -1,18 +0,0 @@
|
|
1
|
-
import { useLocalStorageState, useMemoizedFn } from 'ahooks';
|
2
|
-
|
3
|
-
export default function useAccounts() {
|
4
|
-
const [accounts, setAccounts] = useLocalStorageState('blocklet:sessionManager:accounts', {
|
5
|
-
defaultValue: [],
|
6
|
-
});
|
7
|
-
|
8
|
-
const connectAccount = useMemoizedFn((account) => {
|
9
|
-
const accountIndex = accounts.findIndex((x) => x.did === account.did);
|
10
|
-
if (accountIndex >= 0) {
|
11
|
-
accounts.splice(accountIndex, 1);
|
12
|
-
}
|
13
|
-
accounts.unshift(account);
|
14
|
-
setAccounts(accounts);
|
15
|
-
});
|
16
|
-
|
17
|
-
return { accounts, setAccounts, connectAccount };
|
18
|
-
}
|