@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,70 @@
|
|
1
|
+
/* eslint-disable react/no-array-index-key */
|
2
|
+
import PropTypes from 'prop-types';
|
3
|
+
import { useMemoizedFn } from 'ahooks';
|
4
|
+
import { Icon } from '@iconify/react';
|
5
|
+
import AppsIcon from '@iconify-icons/mdi/apps';
|
6
|
+
import { MenuItem, SvgIcon } from '@mui/material';
|
7
|
+
import MenuAccordion from './menu-accordion';
|
8
|
+
import { translate } from '../Locale/util';
|
9
|
+
import { translations } from './translation';
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
11
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
12
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
13
|
+
export default function ManageBlocklet({
|
14
|
+
menu,
|
15
|
+
menuRender,
|
16
|
+
locale,
|
17
|
+
expanded,
|
18
|
+
onExpand
|
19
|
+
}) {
|
20
|
+
const t = useMemoizedFn((key, data = {}) => {
|
21
|
+
return translate(translations, key, locale, 'en', data);
|
22
|
+
});
|
23
|
+
return /*#__PURE__*/_jsxs(MenuAccordion, {
|
24
|
+
expanded: expanded,
|
25
|
+
locale: locale,
|
26
|
+
onChange: onExpand,
|
27
|
+
title: /*#__PURE__*/_jsxs(_Fragment, {
|
28
|
+
children: [/*#__PURE__*/_jsx(Icon, {
|
29
|
+
icon: AppsIcon,
|
30
|
+
width: 24,
|
31
|
+
height: 24,
|
32
|
+
className: "session-manager-menu-icon"
|
33
|
+
}), t('blocklet')]
|
34
|
+
}),
|
35
|
+
children: [Array.isArray(menu) && menu.map((menuItem, index) => {
|
36
|
+
const {
|
37
|
+
svgIcon,
|
38
|
+
...menuProps
|
39
|
+
} = menuItem;
|
40
|
+
return /*#__PURE__*/_jsxs(MenuItem, {
|
41
|
+
className: "session-manager-menu-item",
|
42
|
+
...menuProps,
|
43
|
+
icon: undefined,
|
44
|
+
label: undefined,
|
45
|
+
children: [svgIcon ? svgIcon && /*#__PURE__*/_jsx(SvgIcon, {
|
46
|
+
component: svgIcon,
|
47
|
+
className: "session-manager-menu-icon"
|
48
|
+
}) : menuItem.icon, menuItem.label]
|
49
|
+
}, index);
|
50
|
+
}), menuRender({
|
51
|
+
classes: {
|
52
|
+
menuItem: 'session-manager-menu-item',
|
53
|
+
menuIcon: 'session-manager-menu-icon'
|
54
|
+
}
|
55
|
+
})]
|
56
|
+
});
|
57
|
+
}
|
58
|
+
ManageBlocklet.propTypes = {
|
59
|
+
menu: PropTypes.array,
|
60
|
+
menuRender: PropTypes.func,
|
61
|
+
locale: PropTypes.string.isRequired,
|
62
|
+
expanded: PropTypes.bool,
|
63
|
+
onExpand: PropTypes.func
|
64
|
+
};
|
65
|
+
ManageBlocklet.defaultProps = {
|
66
|
+
menu: [],
|
67
|
+
menuRender: () => {},
|
68
|
+
expanded: true,
|
69
|
+
onExpand: () => {}
|
70
|
+
};
|
@@ -0,0 +1,104 @@
|
|
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
|
+
expanded,
|
29
|
+
onChange
|
30
|
+
}) {
|
31
|
+
const isEmptyChildren = useCreation(() => isEmptyNode(children), [children]);
|
32
|
+
const t = useMemoizedFn((key, data = {}) => {
|
33
|
+
return translate(translations, key, locale, 'en', data);
|
34
|
+
});
|
35
|
+
return /*#__PURE__*/_jsxs(Accordion, {
|
36
|
+
expanded: expanded,
|
37
|
+
disableGutters: true,
|
38
|
+
elevation: 0,
|
39
|
+
onChange: (e, value) => {
|
40
|
+
onChange(value);
|
41
|
+
},
|
42
|
+
sx: {
|
43
|
+
'&.MuiAccordion-root:before': {
|
44
|
+
content: 'unset'
|
45
|
+
},
|
46
|
+
'.MuiAccordionSummary-root': {
|
47
|
+
minHeight: 'auto',
|
48
|
+
width: '100%'
|
49
|
+
},
|
50
|
+
'.MuiAccordionSummary-content': {
|
51
|
+
margin: 0
|
52
|
+
},
|
53
|
+
'.MuiAccordionDetails-root': {
|
54
|
+
padding: 0,
|
55
|
+
paddingLeft: '30px',
|
56
|
+
'.session-manager-menu-item': {
|
57
|
+
fontSize: '15px',
|
58
|
+
padding: '12px 15px',
|
59
|
+
whiteSpace: 'normal'
|
60
|
+
},
|
61
|
+
'.session-manager-menu-icon': {
|
62
|
+
height: '21px',
|
63
|
+
widht: '21px'
|
64
|
+
}
|
65
|
+
}
|
66
|
+
},
|
67
|
+
children: [/*#__PURE__*/_jsx(MenuItem, {
|
68
|
+
sx: {
|
69
|
+
padding: 0,
|
70
|
+
width: '100%'
|
71
|
+
},
|
72
|
+
children: /*#__PURE__*/_jsx(AccordionSummary, {
|
73
|
+
className: "session-manager-menu-item",
|
74
|
+
expandIcon: /*#__PURE__*/_jsx(Icon, {
|
75
|
+
icon: ExpandMoreIcon,
|
76
|
+
width: 24,
|
77
|
+
height: 24
|
78
|
+
}),
|
79
|
+
children: title
|
80
|
+
})
|
81
|
+
}), /*#__PURE__*/_jsx(AccordionDetails, {
|
82
|
+
children: isEmptyChildren ? /*#__PURE__*/_jsx(MenuItem, {
|
83
|
+
disabled: true,
|
84
|
+
className: "session-manager-menu-item",
|
85
|
+
sx: {
|
86
|
+
justifyContent: 'center'
|
87
|
+
},
|
88
|
+
children: t('noneMenu')
|
89
|
+
}, "empty") : children
|
90
|
+
})]
|
91
|
+
});
|
92
|
+
}
|
93
|
+
MenuAccordion.propTypes = {
|
94
|
+
title: PropTypes.any.isRequired,
|
95
|
+
children: PropTypes.any.isRequired,
|
96
|
+
locale: PropTypes.string,
|
97
|
+
expanded: PropTypes.bool,
|
98
|
+
onChange: PropTypes.func
|
99
|
+
};
|
100
|
+
MenuAccordion.defaultProps = {
|
101
|
+
locale: 'en',
|
102
|
+
expanded: true,
|
103
|
+
onChange: () => {}
|
104
|
+
};
|
@@ -0,0 +1,52 @@
|
|
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 agian',
|
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
|
+
};
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import { useLocalStorageState, useMemoizedFn } from 'ahooks';
|
2
|
+
import cloneDeep from 'lodash/cloneDeep';
|
3
|
+
export default function useConfig() {
|
4
|
+
const [config, setConfig] = useLocalStorageState('blocklet:sessionManager:config', {
|
5
|
+
defaultValue: {
|
6
|
+
accounts: [],
|
7
|
+
expandAccount: true,
|
8
|
+
expandBlocklet: true
|
9
|
+
}
|
10
|
+
});
|
11
|
+
const connectAccount = useMemoizedFn(account => {
|
12
|
+
const cloneConfig = cloneDeep(config);
|
13
|
+
const accountIndex = cloneConfig.accounts.findIndex(x => x.did === account.did);
|
14
|
+
if (accountIndex >= 0) {
|
15
|
+
cloneConfig.accounts.splice(accountIndex, 1);
|
16
|
+
}
|
17
|
+
cloneConfig.accounts.unshift(account);
|
18
|
+
setConfig(cloneConfig);
|
19
|
+
});
|
20
|
+
const deleteAccount = useMemoizedFn(account => {
|
21
|
+
const cloneConfig = cloneDeep(config);
|
22
|
+
const findIndex = cloneConfig.accounts.findIndex(item => item.did === account.did);
|
23
|
+
if (findIndex >= 0) {
|
24
|
+
cloneConfig.accounts.splice(findIndex, 1);
|
25
|
+
}
|
26
|
+
setConfig(cloneConfig);
|
27
|
+
});
|
28
|
+
return {
|
29
|
+
config,
|
30
|
+
setConfig,
|
31
|
+
connectAccount,
|
32
|
+
deleteAccount
|
33
|
+
};
|
34
|
+
}
|
@@ -0,0 +1,147 @@
|
|
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
|
+
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 Typography from '../Typography';
|
15
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
16
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
17
|
+
export default function UserInfo({
|
18
|
+
session,
|
19
|
+
locale,
|
20
|
+
onSwitchProfile,
|
21
|
+
onSwitchPassport,
|
22
|
+
switchProfile,
|
23
|
+
hasBindWallet
|
24
|
+
}) {
|
25
|
+
const t = (key, data = {}) => {
|
26
|
+
return translate(translations, key, locale, 'en', data);
|
27
|
+
};
|
28
|
+
const avatar = getUserAvatar(session.user?.avatar?.replace(/\s/g, encodeURIComponent(' ')));
|
29
|
+
const {
|
30
|
+
walletDid
|
31
|
+
} = session.useDid({
|
32
|
+
session
|
33
|
+
});
|
34
|
+
const currentRole = useCreation(() => session.user?.passports?.find(item => item.name === session.user.role), [session?.user?.passports, session?.user?.role]);
|
35
|
+
const userEmail = useCreation(() => session.user?.email || 'lancelot_lewis@163.com', [session?.user]);
|
36
|
+
const canEdit = useCreation(() => {
|
37
|
+
if (onSwitchProfile instanceof Function) {
|
38
|
+
if (switchProfile && hasBindWallet) {
|
39
|
+
return true;
|
40
|
+
}
|
41
|
+
}
|
42
|
+
return false;
|
43
|
+
}, [onSwitchProfile, switchProfile, hasBindWallet, session.provider]);
|
44
|
+
const _onSwitchProfile = useMemoizedFn(() => {
|
45
|
+
if (canEdit) {
|
46
|
+
onSwitchProfile();
|
47
|
+
}
|
48
|
+
});
|
49
|
+
return /*#__PURE__*/_jsxs(Box, {
|
50
|
+
sx: {
|
51
|
+
display: 'flex',
|
52
|
+
alignItems: 'center',
|
53
|
+
gap: '12px',
|
54
|
+
padding: '15px'
|
55
|
+
},
|
56
|
+
children: [/*#__PURE__*/_jsx(Box, {
|
57
|
+
onClick: _onSwitchProfile,
|
58
|
+
"data-cy": "sessionManager-switch-profile-trigger",
|
59
|
+
sx: {
|
60
|
+
cursor: canEdit ? 'pointer' : 'default',
|
61
|
+
position: 'relative',
|
62
|
+
borderRadius: '100%',
|
63
|
+
overflow: 'hidden',
|
64
|
+
fontSize: 0,
|
65
|
+
'&:hover': canEdit ? {
|
66
|
+
'&::after': {
|
67
|
+
content: `"${t('switch')}"`,
|
68
|
+
position: 'absolute',
|
69
|
+
bottom: 0,
|
70
|
+
background: 'rgba(0, 0, 0, 0.2)',
|
71
|
+
left: 0,
|
72
|
+
right: 0,
|
73
|
+
height: '2.2em',
|
74
|
+
color: 'white',
|
75
|
+
textAlign: 'center',
|
76
|
+
fontSize: '12px',
|
77
|
+
lineHeight: '2em'
|
78
|
+
}
|
79
|
+
} : {}
|
80
|
+
},
|
81
|
+
children: /*#__PURE__*/_jsx(DidAvatar, {
|
82
|
+
variant: "circle",
|
83
|
+
did: session.user.did,
|
84
|
+
src: avatar,
|
85
|
+
size: 64,
|
86
|
+
shape: "circle"
|
87
|
+
})
|
88
|
+
}), /*#__PURE__*/_jsxs(Box, {
|
89
|
+
sx: {
|
90
|
+
flex: 1,
|
91
|
+
position: 'static',
|
92
|
+
overflow: 'hidden',
|
93
|
+
fontSize: '14px'
|
94
|
+
},
|
95
|
+
children: [/*#__PURE__*/_jsxs(Box, {
|
96
|
+
display: "flex",
|
97
|
+
alignItems: "center",
|
98
|
+
gap: "4px",
|
99
|
+
mb: 0.5,
|
100
|
+
children: [/*#__PURE__*/_jsx(Typography, {
|
101
|
+
variant: "h5",
|
102
|
+
fontWeight: "bold",
|
103
|
+
fontSize: "auto",
|
104
|
+
sx: {
|
105
|
+
flex: 1,
|
106
|
+
wordBreak: 'break-all'
|
107
|
+
},
|
108
|
+
children: session.user.fullName
|
109
|
+
}), /*#__PURE__*/_jsx(Chip, {
|
110
|
+
label: currentRole?.title || session.user?.role.toUpperCase(),
|
111
|
+
size: "small",
|
112
|
+
variant: "outlined",
|
113
|
+
sx: {
|
114
|
+
height: 'auto',
|
115
|
+
marginRight: 0,
|
116
|
+
fontWeight: 'bold',
|
117
|
+
fontSize: '12px'
|
118
|
+
},
|
119
|
+
icon: /*#__PURE__*/_jsx(Icon, {
|
120
|
+
icon: ShieldCheckIcon,
|
121
|
+
height: "0.8em"
|
122
|
+
}),
|
123
|
+
deleteIcon: /*#__PURE__*/_jsx(Icon, {
|
124
|
+
icon: ExpandMoreIcon,
|
125
|
+
height: "1em"
|
126
|
+
})
|
127
|
+
// HACK: 必须设置 onDelete 函数,deleteIcon 才能显示出来
|
128
|
+
,
|
129
|
+
onDelete: onSwitchPassport,
|
130
|
+
onClick: onSwitchPassport,
|
131
|
+
"data-cy": "sessionManager-switch-passport-trigger"
|
132
|
+
})]
|
133
|
+
}), session.provider === 'auth0' ? walletDid ? /*#__PURE__*/_jsx(DID, {
|
134
|
+
responsive: false,
|
135
|
+
compact: true,
|
136
|
+
did: walletDid
|
137
|
+
}) : null : /*#__PURE__*/_jsx(DID, {
|
138
|
+
responsive: false,
|
139
|
+
compact: true,
|
140
|
+
did: session.user.did
|
141
|
+
}), userEmail ? /*#__PURE__*/_jsx(DidAddress, {
|
142
|
+
responsive: false,
|
143
|
+
children: userEmail
|
144
|
+
}) : null]
|
145
|
+
})]
|
146
|
+
});
|
147
|
+
}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import PropTypes from 'prop-types';
|
2
2
|
import { IconButton, Paper, Popper, ClickAwayListener } from '@mui/material';
|
3
|
-
import
|
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(
|
62
|
+
children: /*#__PURE__*/_jsx(Icon, {
|
63
|
+
icon: CloseIcon,
|
64
|
+
width: 20,
|
65
|
+
height: 20
|
66
|
+
})
|
62
67
|
}), children]
|
63
68
|
})
|
64
69
|
})
|
@@ -86,58 +91,10 @@ const StyledPopper = styled(Popper)`
|
|
86
91
|
return theme.zIndex.tooltip;
|
87
92
|
}};
|
88
93
|
.MuiList-root {
|
89
|
-
|
90
|
-
width: 290px;
|
91
|
-
}
|
92
|
-
.session-manager-user {
|
93
|
-
font-size: 12px;
|
94
|
-
flex-direction: column;
|
95
|
-
align-items: flex-start;
|
96
|
-
padding: 24px 24px 10px;
|
97
|
-
}
|
98
|
-
.session-manager-user-name {
|
99
|
-
font-size: 20px;
|
100
|
-
color: ${({
|
101
|
-
$dark
|
102
|
-
}) => $dark ? '#aaa' : '#222'};
|
103
|
-
font-weight: bold;
|
104
|
-
margin-bottom: 10px;
|
105
|
-
display: flex;
|
106
|
-
align-items: center;
|
107
|
-
justify-content: space-between;
|
108
|
-
}
|
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
|
-
}
|
94
|
+
width: 320px;
|
138
95
|
}
|
139
96
|
.session-manager-menu-item {
|
140
|
-
padding:
|
97
|
+
padding: 15px;
|
141
98
|
color: #777;
|
142
99
|
font-size: 16px;
|
143
100
|
&:hover {
|
@@ -146,6 +103,6 @@ const StyledPopper = styled(Popper)`
|
|
146
103
|
}
|
147
104
|
.session-manager-menu-icon {
|
148
105
|
color: #999;
|
149
|
-
margin-right:
|
106
|
+
margin-right: 8px;
|
150
107
|
}
|
151
108
|
`;
|
@@ -0,0 +1,89 @@
|
|
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
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
6
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
7
|
+
export default function Typography({
|
8
|
+
minFontSize,
|
9
|
+
fontSize,
|
10
|
+
children,
|
11
|
+
sx,
|
12
|
+
...rest
|
13
|
+
}) {
|
14
|
+
const refMock = useRef(null);
|
15
|
+
const refContainer = useRef(null);
|
16
|
+
const state = useReactive({
|
17
|
+
fontSize,
|
18
|
+
loading: true,
|
19
|
+
initialSize: undefined
|
20
|
+
});
|
21
|
+
const mockSize = useSize(refMock.current);
|
22
|
+
const containerSize = useSize(refContainer.current);
|
23
|
+
useEffect(() => {
|
24
|
+
if (state.loading) {
|
25
|
+
if (fontSize === 'auto') {
|
26
|
+
if (mockSize && !state.initialSize) {
|
27
|
+
const styleSize = getComputedStyle(refMock.current).fontSize;
|
28
|
+
state.initialSize = Number(styleSize.replace('px', ''));
|
29
|
+
state.fontSize = state.initialSize;
|
30
|
+
}
|
31
|
+
if (containerSize && mockSize) {
|
32
|
+
if (containerSize.width < mockSize.width && state.fontSize > minFontSize) {
|
33
|
+
state.fontSize--;
|
34
|
+
} else {
|
35
|
+
state.loading = false;
|
36
|
+
}
|
37
|
+
}
|
38
|
+
} else {
|
39
|
+
state.loading = false;
|
40
|
+
}
|
41
|
+
}
|
42
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
43
|
+
}, [fontSize, mockSize?.width, containerSize?.width]);
|
44
|
+
return state.loading ? /*#__PURE__*/_jsxs(Box, {
|
45
|
+
ref: refContainer,
|
46
|
+
flex: 1,
|
47
|
+
children: [/*#__PURE__*/_jsx(MuiTypography, {
|
48
|
+
...rest,
|
49
|
+
sx: sx,
|
50
|
+
noWrap: true,
|
51
|
+
children: /*#__PURE__*/_jsx(Skeleton, {
|
52
|
+
variant: "text",
|
53
|
+
sx: {
|
54
|
+
fontSize: '1rem'
|
55
|
+
}
|
56
|
+
})
|
57
|
+
}), /*#__PURE__*/_jsx(MuiTypography, {
|
58
|
+
ref: refMock,
|
59
|
+
...rest,
|
60
|
+
sx: {
|
61
|
+
...sx,
|
62
|
+
fontSize: `${state.fontSize}px !important`,
|
63
|
+
position: 'fixed',
|
64
|
+
top: -1000,
|
65
|
+
left: -1000
|
66
|
+
},
|
67
|
+
noWrap: true,
|
68
|
+
children: children
|
69
|
+
})]
|
70
|
+
}) : /*#__PURE__*/_jsx(MuiTypography, {
|
71
|
+
...rest,
|
72
|
+
sx: {
|
73
|
+
...sx,
|
74
|
+
fontSize: `${state.fontSize}px !important`
|
75
|
+
},
|
76
|
+
children: children
|
77
|
+
});
|
78
|
+
}
|
79
|
+
Typography.propTypes = {
|
80
|
+
fontSize: PropTyps.oneOfType([PropTyps.string, PropTyps.number]),
|
81
|
+
children: PropTyps.any.isRequired,
|
82
|
+
minFontSize: PropTyps.number,
|
83
|
+
sx: PropTyps.object
|
84
|
+
};
|
85
|
+
Typography.defaultProps = {
|
86
|
+
fontSize: undefined,
|
87
|
+
minFontSize: 12,
|
88
|
+
sx: {}
|
89
|
+
};
|
@@ -0,0 +1,65 @@
|
|
1
|
+
import isEmpty from 'lodash/isEmpty';
|
2
|
+
export function getMaster(blocklet = window.blocklet) {
|
3
|
+
const federated = blocklet?.settings?.federated || {};
|
4
|
+
return federated.master;
|
5
|
+
}
|
6
|
+
export function getConfig(blocklet = window.blocklet) {
|
7
|
+
const federated = blocklet?.settings?.federated || {};
|
8
|
+
return federated.config;
|
9
|
+
}
|
10
|
+
export function getAutoLoginFederated(blocklet = window.blocklet) {
|
11
|
+
const config = getConfig(blocklet);
|
12
|
+
return Boolean(config?.autoLogin) && config?.status === 'approved';
|
13
|
+
}
|
14
|
+
export function getSourceAppPid(blocklet = window.blocklet) {
|
15
|
+
const master = getMaster(blocklet);
|
16
|
+
return master?.appPid;
|
17
|
+
}
|
18
|
+
export function getFederatedApp(blocklet = window.blocklet) {
|
19
|
+
const master = getMaster(blocklet);
|
20
|
+
const isFederatedMode = !isEmpty(master);
|
21
|
+
return isFederatedMode ? {
|
22
|
+
appId: master.appId,
|
23
|
+
appName: master.appName,
|
24
|
+
appDescription: master.appDescription,
|
25
|
+
appLogo: master.appLogo,
|
26
|
+
appPid: master.appPid,
|
27
|
+
appUrl: master.appUrl,
|
28
|
+
version: master.version,
|
29
|
+
sourceAppPid: master.appPid,
|
30
|
+
provider: 'wallet'
|
31
|
+
} : null;
|
32
|
+
}
|
33
|
+
export function getCurrentApp(blocklet = window.blocklet) {
|
34
|
+
// 适用于 blocklet 项目
|
35
|
+
if (blocklet) {
|
36
|
+
return {
|
37
|
+
appId: blocklet.appId,
|
38
|
+
appName: blocklet.appName,
|
39
|
+
appDescription: blocklet.appDescription,
|
40
|
+
appLogo: blocklet.appLogo,
|
41
|
+
appPid: blocklet.appPid,
|
42
|
+
appUrl: blocklet.appUrl,
|
43
|
+
version: blocklet.version,
|
44
|
+
// NOTICE: null 代表该值置空
|
45
|
+
sourceAppPid: null,
|
46
|
+
provider: 'wallet'
|
47
|
+
};
|
48
|
+
}
|
49
|
+
// HACK: 适用于 blockelt-server
|
50
|
+
if (window.env) {
|
51
|
+
// eslint-disable-next-line no-param-reassign
|
52
|
+
blocklet = window.env;
|
53
|
+
return {
|
54
|
+
appId: blocklet.appId,
|
55
|
+
appName: blocklet.appName,
|
56
|
+
appDescription: blocklet.appDescription,
|
57
|
+
appUrl: blocklet.baseUrl,
|
58
|
+
// NOTICE: null 代表该值置空
|
59
|
+
sourceAppPid: null,
|
60
|
+
provider: 'wallet',
|
61
|
+
type: 'server'
|
62
|
+
};
|
63
|
+
}
|
64
|
+
return null;
|
65
|
+
}
|
package/es/Util/index.js
CHANGED