@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.
Files changed (43) hide show
  1. package/es/SessionManager/account-item.js +5 -4
  2. package/es/SessionManager/add-account-item.js +13 -31
  3. package/es/SessionManager/federated-login-detecter.js +32 -26
  4. package/es/SessionManager/index.js +44 -57
  5. package/es/SessionManager/manage-accounts.js +30 -17
  6. package/es/SessionManager/manage-blocklet.js +12 -4
  7. package/es/SessionManager/menu-accordion.js +14 -5
  8. package/es/SessionManager/translation.js +10 -10
  9. package/es/SessionManager/use-config.js +34 -0
  10. package/es/SessionManager/user-info.js +51 -43
  11. package/es/SessionManager/user-popper.js +1 -18
  12. package/es/Typography/index.js +89 -0
  13. package/es/Util/federated.js +65 -0
  14. package/lib/SessionManager/account-item.js +5 -4
  15. package/lib/SessionManager/add-account-item.js +14 -32
  16. package/lib/SessionManager/federated-login-detecter.js +33 -26
  17. package/lib/SessionManager/index.js +45 -58
  18. package/lib/SessionManager/manage-accounts.js +29 -16
  19. package/lib/SessionManager/manage-blocklet.js +12 -4
  20. package/lib/SessionManager/menu-accordion.js +14 -5
  21. package/lib/SessionManager/translation.js +10 -10
  22. package/lib/SessionManager/use-config.js +41 -0
  23. package/lib/SessionManager/user-info.js +50 -42
  24. package/lib/SessionManager/user-popper.js +1 -6
  25. package/lib/Typography/index.js +100 -0
  26. package/lib/Util/federated.js +85 -0
  27. package/package.json +11 -7
  28. package/src/SessionManager/account-item.jsx +6 -8
  29. package/src/SessionManager/add-account-item.jsx +12 -30
  30. package/src/SessionManager/federated-login-detecter.jsx +39 -26
  31. package/src/SessionManager/index.jsx +48 -68
  32. package/src/SessionManager/manage-accounts.jsx +27 -13
  33. package/src/SessionManager/manage-blocklet.jsx +8 -2
  34. package/src/SessionManager/menu-accordion.jsx +10 -3
  35. package/src/SessionManager/translation.js +10 -10
  36. package/src/SessionManager/use-config.js +33 -0
  37. package/src/SessionManager/user-info.jsx +34 -34
  38. package/src/SessionManager/user-popper.jsx +1 -16
  39. package/src/Typography/index.jsx +79 -0
  40. package/src/Util/federated.js +73 -0
  41. package/es/SessionManager/use-accounts.js +0 -19
  42. package/lib/SessionManager/use-accounts.js +0 -25
  43. package/src/SessionManager/use-accounts.js +0 -18
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable import/prefer-default-export */
2
2
  export const translations = {
3
3
  en: {
4
- edit: 'Edit',
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
- connectedWith: 'Connected with',
17
- manageAccounts: 'Manage Accounts',
18
- manageBlocklet: 'Manage Blocklet',
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
- edit: '编辑',
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
- connectedWith: '连接至',
42
- manageAccounts: '管理账户',
43
- manageBlocklet: '管理应用',
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,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
+ }
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable react/jsx-no-bind */
2
2
  /* eslint-disable react/prop-types */
3
- import { Box, Chip, Typography } from '@mui/material';
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';
@@ -11,12 +11,13 @@ import DID from '../DID';
11
11
  import { getUserAvatar } from '../Util';
12
12
  import { t as translate } from '../Locale/util';
13
13
  import { translations } from './translation';
14
+ import Typography from '../Typography';
14
15
  import { jsx as _jsx } from "react/jsx-runtime";
15
16
  import { jsxs as _jsxs } from "react/jsx-runtime";
16
17
  export default function UserInfo({
17
18
  session,
18
19
  locale,
19
- onEditUser,
20
+ onSwitchProfile,
20
21
  onSwitchPassport,
21
22
  switchProfile,
22
23
  hasBindWallet
@@ -33,27 +34,27 @@ export default function UserInfo({
33
34
  const currentRole = useCreation(() => session.user?.passports?.find(item => item.name === session.user.role), [session?.user?.passports, session?.user?.role]);
34
35
  const userEmail = useCreation(() => session.user?.email || 'lancelot_lewis@163.com', [session?.user]);
35
36
  const canEdit = useCreation(() => {
36
- if (onEditUser instanceof Function) {
37
- if (switchProfile && hasBindWallet && session.provider !== 'federated') {
37
+ if (onSwitchProfile instanceof Function) {
38
+ if (switchProfile && hasBindWallet) {
38
39
  return true;
39
40
  }
40
41
  }
41
42
  return false;
42
- }, [onEditUser, switchProfile, hasBindWallet, session.provider]);
43
- const _onEditUser = useMemoizedFn(() => {
43
+ }, [onSwitchProfile, switchProfile, hasBindWallet, session.provider]);
44
+ const _onSwitchProfile = useMemoizedFn(() => {
44
45
  if (canEdit) {
45
- onEditUser();
46
+ onSwitchProfile();
46
47
  }
47
48
  });
48
49
  return /*#__PURE__*/_jsxs(Box, {
49
50
  sx: {
50
51
  display: 'flex',
51
52
  alignItems: 'center',
52
- gap: '16px',
53
- padding: '15px 20px'
53
+ gap: '12px',
54
+ padding: '15px'
54
55
  },
55
56
  children: [/*#__PURE__*/_jsx(Box, {
56
- onClick: _onEditUser,
57
+ onClick: _onSwitchProfile,
57
58
  "data-cy": "sessionManager-switch-profile-trigger",
58
59
  sx: {
59
60
  cursor: canEdit ? 'pointer' : 'default',
@@ -63,7 +64,7 @@ export default function UserInfo({
63
64
  fontSize: 0,
64
65
  '&:hover': canEdit ? {
65
66
  '&::after': {
66
- content: `"${t('edit')}"`,
67
+ content: `"${t('switch')}"`,
67
68
  position: 'absolute',
68
69
  bottom: 0,
69
70
  background: 'rgba(0, 0, 0, 0.2)',
@@ -91,11 +92,44 @@ export default function UserInfo({
91
92
  overflow: 'hidden',
92
93
  fontSize: '14px'
93
94
  },
94
- children: [/*#__PURE__*/_jsx(Typography, {
95
- variant: "h5",
96
- fontWeight: "bold",
97
- mb: 1,
98
- children: session.user.fullName
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
+ })]
99
133
  }), session.provider === 'auth0' ? walletDid ? /*#__PURE__*/_jsx(DID, {
100
134
  responsive: false,
101
135
  compact: true,
@@ -107,33 +141,7 @@ export default function UserInfo({
107
141
  }), userEmail ? /*#__PURE__*/_jsx(DidAddress, {
108
142
  responsive: false,
109
143
  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
- })]
144
+ }) : null]
137
145
  })]
138
146
  });
139
147
  }
@@ -93,25 +93,8 @@ const StyledPopper = styled(Popper)`
93
93
  .MuiList-root {
94
94
  width: 320px;
95
95
  }
96
- .session-manager-user {
97
- font-size: 12px;
98
- flex-direction: column;
99
- align-items: flex-start;
100
- padding: 24px 24px 10px;
101
- }
102
- .session-manager-user-name {
103
- font-size: 20px;
104
- color: ${({
105
- $dark
106
- }) => $dark ? '#aaa' : '#222'};
107
- font-weight: bold;
108
- margin-bottom: 10px;
109
- display: flex;
110
- align-items: center;
111
- justify-content: space-between;
112
- }
113
96
  .session-manager-menu-item {
114
- padding: 18px 20px;
97
+ padding: 15px;
115
98
  color: #777;
116
99
  font-size: 16px;
117
100
  &:hover {
@@ -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
+ }
@@ -68,7 +68,8 @@ function AccountItem(_ref) {
68
68
  },
69
69
  className: "session-manager-menu-item",
70
70
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Avatar.default, {
71
- did: account.did
71
+ did: account.did,
72
+ size: 42
72
73
  }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
73
74
  sx: {
74
75
  flex: 1,
@@ -87,14 +88,14 @@ function AccountItem(_ref) {
87
88
  sx: {
88
89
  lineHeight: 1
89
90
  }
90
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Typography, {
91
+ }), account.sourceAppPid && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Typography, {
91
92
  variant: "caption",
92
- children: [t('from'), ' ', account.provider === 'federated' ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Link, {
93
+ children: [t('from'), ' ', /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Link, {
93
94
  href: account.appUrl,
94
95
  target: "_blank",
95
96
  underline: "none",
96
97
  children: account.appName
97
- }) : account.appName]
98
+ })]
98
99
  })]
99
100
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
100
101
  className: "account-item-actions",
@@ -8,11 +8,11 @@ var _react = require("@iconify/react");
8
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
9
  var _material = require("@mui/material");
10
10
  var _iosAddCircleOutline = _interopRequireDefault(require("@iconify-icons/ion/ios-add-circle-outline"));
11
- var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
12
11
  var _ahooks = require("ahooks");
13
12
  var _react2 = require("react");
14
13
  var _util = require("../Locale/util");
15
14
  var _translation = require("./translation");
15
+ var _federated = require("../Util/federated");
16
16
  var _jsxRuntime = require("react/jsx-runtime");
17
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
18
  function AddAccountItem(_ref) {
@@ -29,42 +29,22 @@ function AddAccountItem(_ref) {
29
29
  return (0, _util.translate)(_translation.translations, key, locale, 'en', data);
30
30
  });
31
31
  const apps = (0, _ahooks.useCreation)(() => {
32
- var _window, _blocklet$settings, _blocklet$settings$fe;
32
+ var _window;
33
33
  const appList = [];
34
34
  if (typeof window === 'undefined') {
35
35
  return appList;
36
36
  }
37
37
  const blocklet = (_window = window) === null || _window === void 0 ? void 0 : _window.blocklet;
38
- if (!blocklet) {
39
- return appList;
38
+ const masterApp = (0, _federated.getFederatedApp)(blocklet);
39
+ const currentApp = (0, _federated.getCurrentApp)(blocklet);
40
+ if (currentApp) {
41
+ appList.push(currentApp);
40
42
  }
41
- const currentApp = {
42
- appId: blocklet.appId,
43
- appName: blocklet.appName,
44
- appDescription: blocklet.appDescription,
45
- appLogo: blocklet.appLogo,
46
- appPid: blocklet.appPid,
47
- appUrl: blocklet.appUrl,
48
- version: blocklet.version,
49
- provider: 'wallet'
50
- };
51
- appList.push(currentApp);
52
- const isFederatedMember = !(0, _isEmpty.default)((_blocklet$settings = blocklet.settings) === null || _blocklet$settings === void 0 ? void 0 : (_blocklet$settings$fe = _blocklet$settings.federated) === null || _blocklet$settings$fe === void 0 ? void 0 : _blocklet$settings$fe.master);
53
- if (isFederatedMember) {
54
- const federatedMaster = blocklet.settings.federated.master;
55
- const masterApp = {
56
- appId: federatedMaster.appId,
57
- appName: federatedMaster.appName,
58
- appDescription: federatedMaster.appDescription,
59
- appLogo: federatedMaster.appLogo,
60
- appPid: federatedMaster.appPid,
61
- appUrl: federatedMaster.appUrl,
62
- version: federatedMaster.version,
63
- provider: 'federated'
64
- };
65
- return [masterApp, currentApp];
43
+ if (masterApp && (masterApp === null || masterApp === void 0 ? void 0 : masterApp.appId) !== (currentApp === null || currentApp === void 0 ? void 0 : currentApp.appId)) {
44
+ appList.push(masterApp);
66
45
  }
67
- return appList;
46
+ // NOTICE: masterApp 应该排在前面
47
+ return appList.reverse();
68
48
  }, [window.blocklet]);
69
49
  const _onAdd = (0, _ahooks.useMemoizedFn)(() => {
70
50
  if (apps.length <= 1) {
@@ -109,9 +89,11 @@ function AddAccountItem(_ref) {
109
89
  vertical: 'top',
110
90
  horizontal: 'left'
111
91
  },
112
- children: apps.map(app => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, {
92
+ children: apps.map(app => /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.MenuItem, {
113
93
  onClick: () => onAdd(app),
114
- children: ["Connect with ", app.appName, " account"]
94
+ children: t('connectWithAccount', {
95
+ name: app.appName
96
+ })
115
97
  }, app.appId))
116
98
  }) : null]
117
99
  });
@@ -11,6 +11,7 @@ var _Chip = _interopRequireDefault(require("@mui/material/Chip"));
11
11
  var _Divider = _interopRequireDefault(require("@mui/material/Divider"));
12
12
  var _shieldCheck = _interopRequireDefault(require("@iconify-icons/mdi/shield-check"));
13
13
  var _react2 = require("@iconify/react");
14
+ var _ahooks = require("ahooks");
14
15
  var _userPopper = _interopRequireDefault(require("./user-popper"));
15
16
  var _Avatar = _interopRequireDefault(require("../Avatar"));
16
17
  var _Address = _interopRequireDefault(require("../Address"));
@@ -48,54 +49,60 @@ const translations = {
48
49
  }
49
50
  };
50
51
  function FederatedLoginDetecter(_ref3) {
51
- var _session$federatedMas, _session$federatedMas2, _userInfo$role, _userInfo$role2;
52
+ var _federatedMaster$site2, _federatedMaster$user, _federatedMaster$user2;
52
53
  let {
53
54
  session,
54
55
  anchorEl,
55
56
  dark,
56
57
  locale: _locale
57
58
  } = _ref3;
58
- const [federatedLoginOpen, setFederatedLoginOpen] = (0, _react.useState)(true);
59
- const siteInfo = (_session$federatedMas = session.federatedMaster) === null || _session$federatedMas === void 0 ? void 0 : _session$federatedMas.site;
60
- const userInfo = (_session$federatedMas2 = session.federatedMaster) === null || _session$federatedMas2 === void 0 ? void 0 : _session$federatedMas2.user;
59
+ const state = (0, _ahooks.useReactive)({
60
+ open: true
61
+ });
62
+ const federatedMaster = (0, _ahooks.useCreation)(() => {
63
+ return session.federatedMaster;
64
+ }, [session === null || session === void 0 ? void 0 : session.federatedMaster]);
61
65
  const localeList = Object.keys(translations);
62
66
  const locale = localeList.includes(_locale) ? _locale : localeList[0];
63
67
  const onLoginFederated = (0, _react.useCallback)(() => {
68
+ var _federatedMaster$site;
64
69
  session === null || session === void 0 ? void 0 : session.login(err => {
65
70
  if (err) {
66
71
  _Toast.default.error(err || translations[_locale].loginFederatedFailed);
67
72
  } else {
68
- setFederatedLoginOpen(false);
73
+ state.open = false;
69
74
  }
70
75
  }, {
71
- provider: 'federated',
72
- mode: userInfo ? 'auto' : 'manual'
76
+ sourceAppPid: federatedMaster === null || federatedMaster === void 0 ? void 0 : (_federatedMaster$site = federatedMaster.site) === null || _federatedMaster$site === void 0 ? void 0 : _federatedMaster$site.appPid,
77
+ mode: federatedMaster !== null && federatedMaster !== void 0 && federatedMaster.user ? 'auto' : 'manual'
73
78
  });
74
- }, [session, userInfo, _locale]);
79
+ }, [session, federatedMaster === null || federatedMaster === void 0 ? void 0 : (_federatedMaster$site2 = federatedMaster.site) === null || _federatedMaster$site2 === void 0 ? void 0 : _federatedMaster$site2.appPid, federatedMaster === null || federatedMaster === void 0 ? void 0 : federatedMaster.user, _locale, state]);
75
80
  let appLogoUrl;
76
- if (siteInfo) {
77
- appLogoUrl = new URL(siteInfo.appLogo, siteInfo.appUrl);
81
+ if (federatedMaster !== null && federatedMaster !== void 0 && federatedMaster.site) {
82
+ appLogoUrl = new URL(federatedMaster.site.appLogo, federatedMaster.site.appUrl);
78
83
  appLogoUrl.searchParams.set('imageFilter', 'resize');
79
84
  // HACK: 保持跟其他地方使用的尺寸一致,可以复用同一资源的缓存,减少网络请求
80
85
  appLogoUrl.searchParams.set('w', '80');
81
86
  appLogoUrl.searchParams.set('h', '80');
82
87
  }
83
- return siteInfo && /*#__PURE__*/(0, _jsxRuntime.jsx)(_userPopper.default, {
84
- open: federatedLoginOpen,
88
+ return (federatedMaster === null || federatedMaster === void 0 ? void 0 : federatedMaster.site) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_userPopper.default, {
89
+ open: state.open,
85
90
  anchorEl: anchorEl,
86
91
  dark: dark,
87
92
  autoClose: false,
88
- onClose: () => setFederatedLoginOpen(false),
93
+ onClose: () => {
94
+ state.open = false;
95
+ },
89
96
  children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
90
97
  p: 2,
91
- children: [siteInfo && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
98
+ children: [federatedMaster.site && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
92
99
  display: "flex",
93
100
  alignItems: "center",
94
101
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
95
102
  component: "img",
96
103
  mr: 2,
97
104
  src: appLogoUrl.href,
98
- alt: siteInfo.appName,
105
+ alt: federatedMaster.site.appName,
99
106
  width: "30px",
100
107
  height: "30px"
101
108
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
@@ -105,7 +112,7 @@ function FederatedLoginDetecter(_ref3) {
105
112
  children: translations[locale].useToConnect({
106
113
  master: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
107
114
  component: "a",
108
- href: siteInfo.appUrl,
115
+ href: federatedMaster.site.appUrl,
109
116
  target: "_blank",
110
117
  sx: {
111
118
  textDecoration: 'none',
@@ -113,22 +120,22 @@ function FederatedLoginDetecter(_ref3) {
113
120
  color: 'primary.main',
114
121
  fontSize: '1.2em'
115
122
  },
116
- children: siteInfo.appName
123
+ children: federatedMaster.site.appName
117
124
  }),
118
125
  member: window.blocklet.appName
119
126
  })
120
127
  })]
121
- }), siteInfo && userInfo && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Divider.default, {
128
+ }), (federatedMaster === null || federatedMaster === void 0 ? void 0 : federatedMaster.site) && (federatedMaster === null || federatedMaster === void 0 ? void 0 : federatedMaster.user) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Divider.default, {
122
129
  style: {
123
130
  margin: '15px 0 10px 0'
124
131
  }
125
- }), userInfo && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
132
+ }), (federatedMaster === null || federatedMaster === void 0 ? void 0 : federatedMaster.user) && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
126
133
  display: "flex",
127
134
  alignItems: "center",
128
135
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Avatar.default, {
129
136
  variant: "circle",
130
- did: userInfo.did,
131
- src: (0, _Util.getUserAvatar)(userInfo.avatar),
137
+ did: federatedMaster.user.did,
138
+ src: (0, _Util.getUserAvatar)(federatedMaster.user.avatar),
132
139
  size: 28,
133
140
  shape: "circle"
134
141
  }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
@@ -139,9 +146,9 @@ function FederatedLoginDetecter(_ref3) {
139
146
  alignItems: "center",
140
147
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
141
148
  fontSize: 18,
142
- children: userInfo.fullName
143
- }), ((_userInfo$role = userInfo.role) === null || _userInfo$role === void 0 ? void 0 : _userInfo$role.toUpperCase()) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Chip.default, {
144
- label: (_userInfo$role2 = userInfo.role) === null || _userInfo$role2 === void 0 ? void 0 : _userInfo$role2.toUpperCase(),
149
+ children: federatedMaster.user.fullName
150
+ }), ((_federatedMaster$user = federatedMaster.user.role) === null || _federatedMaster$user === void 0 ? void 0 : _federatedMaster$user.toUpperCase()) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Chip.default, {
151
+ label: (_federatedMaster$user2 = federatedMaster.user.role) === null || _federatedMaster$user2 === void 0 ? void 0 : _federatedMaster$user2.toUpperCase(),
145
152
  size: "small",
146
153
  variant: "outlined",
147
154
  sx: {
@@ -156,10 +163,10 @@ function FederatedLoginDetecter(_ref3) {
156
163
  })]
157
164
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Address.default, {
158
165
  responsive: false,
159
- children: userInfo.did
166
+ children: federatedMaster.user.did
160
167
  })]
161
168
  })]
162
- }), siteInfo && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
169
+ }), (federatedMaster === null || federatedMaster === void 0 ? void 0 : federatedMaster.site) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
163
170
  display: "flex",
164
171
  justifyContent: "center",
165
172
  mt: 2,