@arcblock/ux 2.7.16 → 2.7.18
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 +11 -7
- 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
@@ -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
|
-
}
|