@arcblock/ux 2.13.28 → 2.13.29
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/lib/DIDConnect/did-connect-container.d.ts +2 -1
- package/lib/DIDConnect/did-connect-container.js +4 -2
- package/lib/DIDConnect/index.d.ts +1 -0
- package/lib/DIDConnect/index.js +2 -1
- package/lib/DIDConnect/request-storage-access-api-dialog.d.ts +12 -0
- package/lib/DIDConnect/request-storage-access-api-dialog.js +325 -0
- package/lib/SessionUser/components/un-login.js +29 -37
- package/lib/SharedBridge/index.d.ts +5 -6
- package/lib/SharedBridge/index.js +34 -48
- package/package.json +6 -6
- package/src/DIDConnect/did-connect-container.tsx +4 -1
- package/src/DIDConnect/index.ts +1 -0
- package/src/DIDConnect/request-storage-access-api-dialog.tsx +280 -0
- package/src/SessionUser/components/un-login.tsx +21 -29
- package/src/SharedBridge/index.tsx +91 -97
- package/lib/LoginButton/index.d.ts +0 -12
- package/lib/LoginButton/index.js +0 -74
- package/lib/SharedBridge/need-storage-access-api-dialog.d.ts +0 -6
- package/lib/SharedBridge/need-storage-access-api-dialog.js +0 -191
- package/src/LoginButton/index.tsx +0 -73
- package/src/SharedBridge/need-storage-access-api-dialog.tsx +0 -149
@@ -1,5 +1,5 @@
|
|
1
1
|
import { SxProps } from '@mui/material';
|
2
|
-
export default function DIDConnectContainer({ open, popup, hideCloseButton, children, appPid, slotProps, onClose, }: {
|
2
|
+
export default function DIDConnectContainer({ open, popup, hideCloseButton, children, appPid, slotProps, onClose, keepMounted, }: {
|
3
3
|
popup?: boolean;
|
4
4
|
open?: boolean;
|
5
5
|
hideCloseButton?: boolean;
|
@@ -20,4 +20,5 @@ export default function DIDConnectContainer({ open, popup, hideCloseButton, chil
|
|
20
20
|
sx?: SxProps;
|
21
21
|
};
|
22
22
|
};
|
23
|
+
keepMounted?: boolean;
|
23
24
|
}): import("react/jsx-runtime").JSX.Element;
|
@@ -30,7 +30,8 @@ export default function DIDConnectContainer({
|
|
30
30
|
children,
|
31
31
|
appPid,
|
32
32
|
slotProps,
|
33
|
-
onClose = noop
|
33
|
+
onClose = noop,
|
34
|
+
keepMounted = false
|
34
35
|
}) {
|
35
36
|
const color = useCreation(() => {
|
36
37
|
const did = appPid || window.blocklet.appPid;
|
@@ -63,7 +64,7 @@ export default function DIDConnectContainer({
|
|
63
64
|
if (['backdropClick', 'escapeKeyDown'].includes(reason)) return;
|
64
65
|
onClose();
|
65
66
|
};
|
66
|
-
const showModal = debouncedOpen || open;
|
67
|
+
const showModal = debouncedOpen || open || keepMounted;
|
67
68
|
const DrawerComponent = hideCloseButton ? Drawer : SwipeableDrawer;
|
68
69
|
const hslColor = colorConvert.hex.hsl(color);
|
69
70
|
const [h, s, l] = hslColor;
|
@@ -237,6 +238,7 @@ export default function DIDConnectContainer({
|
|
237
238
|
slots: {
|
238
239
|
backdrop: BackdropWrap
|
239
240
|
},
|
241
|
+
keepMounted: keepMounted,
|
240
242
|
className: "did-connect__container-dialog",
|
241
243
|
onClose: handleOnClose,
|
242
244
|
PaperProps: {
|
@@ -6,3 +6,4 @@ export { default as withContainer } from './with-container';
|
|
6
6
|
export { default as withUxTheme } from './with-ux-theme';
|
7
7
|
export { default as DIDConnectLogo } from './did-connect-logo';
|
8
8
|
export { default as DIDConnectContainer } from './did-connect-container';
|
9
|
+
export { default as RequestStorageAccessApiDialog } from './request-storage-access-api-dialog';
|
package/lib/DIDConnect/index.js
CHANGED
@@ -5,4 +5,5 @@ export { default as PoweredBy } from './powered-by';
|
|
5
5
|
export { default as withContainer } from './with-container';
|
6
6
|
export { default as withUxTheme } from './with-ux-theme';
|
7
7
|
export { default as DIDConnectLogo } from './did-connect-logo';
|
8
|
-
export { default as DIDConnectContainer } from './did-connect-container';
|
8
|
+
export { default as DIDConnectContainer } from './did-connect-container';
|
9
|
+
export { default as RequestStorageAccessApiDialog } from './request-storage-access-api-dialog';
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { Locale } from '../type';
|
2
|
+
type StorageAccessState = 'prompt' | 'granted' | 'denied';
|
3
|
+
declare const _default: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<{
|
4
|
+
locale?: Locale;
|
5
|
+
src: string;
|
6
|
+
storageAccessState: StorageAccessState;
|
7
|
+
onHandle: (data: {
|
8
|
+
value: boolean;
|
9
|
+
error?: Error;
|
10
|
+
}) => void;
|
11
|
+
} & import("react").RefAttributes<unknown>>>;
|
12
|
+
export default _default;
|
@@ -0,0 +1,325 @@
|
|
1
|
+
import { Fragment as _Fragment, jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
2
|
+
import { Box, Button, Typography, Chip, List, ListItem } from '@mui/material';
|
3
|
+
import { Icon } from '@iconify/react';
|
4
|
+
import externalLinkIcon from '@iconify-icons/tabler/external-link';
|
5
|
+
import lockOutlineIcon from '@iconify-icons/material-symbols/lock-outline';
|
6
|
+
import checkCircleIcon from '@iconify-icons/material-symbols/check-circle';
|
7
|
+
import rocketLaunchRoundedIcon from '@iconify-icons/material-symbols/rocket-launch-rounded';
|
8
|
+
import { useMemoizedFn, useReactive } from 'ahooks';
|
9
|
+
import { forwardRef, memo, useImperativeHandle, useRef } from 'react';
|
10
|
+
import noop from 'lodash/noop';
|
11
|
+
import { translate } from '../Locale/util';
|
12
|
+
import DIDConnectContainer from './did-connect-container';
|
13
|
+
import CloseButton from '../CloseButton';
|
14
|
+
import SharedBridge from '../SharedBridge';
|
15
|
+
import { setVisitorId } from '../Util';
|
16
|
+
const translations = {
|
17
|
+
en: {
|
18
|
+
allow: 'Allow',
|
19
|
+
dataUsage: 'Your data is only used for identity authentication, and will not be collected or used for any other purpose.',
|
20
|
+
title: 'Authorization Request',
|
21
|
+
clickAllow: ({
|
22
|
+
allowButton
|
23
|
+
}) => {
|
24
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
25
|
+
children: ["You only need to click the ", allowButton, " button below, and you will not see this request again."]
|
26
|
+
});
|
27
|
+
},
|
28
|
+
reason: ({
|
29
|
+
site
|
30
|
+
}) => {
|
31
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
32
|
+
children: ["For a better login experience, we need to apply for the storage permission of the ", site, " site."]
|
33
|
+
});
|
34
|
+
},
|
35
|
+
afterAllow: {
|
36
|
+
title: 'After authorization, you will enjoy:',
|
37
|
+
list1: 'More convenient login experience',
|
38
|
+
list2: 'Faster access speed'
|
39
|
+
}
|
40
|
+
},
|
41
|
+
zh: {
|
42
|
+
allow: '允许',
|
43
|
+
dataUsage: '您的数据仅用于身份认证,不会被收集或用于其他用途。',
|
44
|
+
title: '授权请求',
|
45
|
+
clickAllow: ({
|
46
|
+
allowButton
|
47
|
+
}) => {
|
48
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
49
|
+
children: ["\u60A8\u53EA\u9700\u8981\u70B9\u51FB\u4E0B\u65B9\u7684 ", allowButton, " \u6309\u94AE\uFF0C\u540E\u7EED\u5C06\u4E0D\u4F1A\u518D\u770B\u5230\u8FD9\u4E2A\u8BF7\u6C42\u3002"]
|
50
|
+
});
|
51
|
+
},
|
52
|
+
reason: ({
|
53
|
+
site
|
54
|
+
}) => {
|
55
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
56
|
+
children: ["\u4E3A\u4E86\u8BA9\u60A8\u83B7\u5F97\u66F4\u597D\u7684\u767B\u5F55\u4F53\u9A8C\uFF0C\u6211\u4EEC\u9700\u8981\u7533\u8BF7 ", site, " \u7AD9\u70B9\u5B58\u50A8\u6743\u9650\u3002"]
|
57
|
+
});
|
58
|
+
},
|
59
|
+
afterAllow: {
|
60
|
+
title: '授权后,您将享受:',
|
61
|
+
list1: '更便捷的登录体验',
|
62
|
+
list2: '更快的访问速度'
|
63
|
+
}
|
64
|
+
}
|
65
|
+
};
|
66
|
+
const RequestStorageAccessApiDialog = /*#__PURE__*/forwardRef(({
|
67
|
+
locale = 'en',
|
68
|
+
src,
|
69
|
+
storageAccessState,
|
70
|
+
onHandle = noop
|
71
|
+
}, ref) => {
|
72
|
+
const sharedBridgeRef = useRef(null);
|
73
|
+
const currentState = useReactive({
|
74
|
+
callback: noop,
|
75
|
+
open: false,
|
76
|
+
get origin() {
|
77
|
+
try {
|
78
|
+
return new URL(src).origin;
|
79
|
+
} catch (error) {
|
80
|
+
return src;
|
81
|
+
}
|
82
|
+
},
|
83
|
+
get host() {
|
84
|
+
try {
|
85
|
+
return new URL(src).host;
|
86
|
+
} catch (error) {
|
87
|
+
return src;
|
88
|
+
}
|
89
|
+
}
|
90
|
+
});
|
91
|
+
const t = useMemoizedFn((key, data = {}) => {
|
92
|
+
return translate(translations, key, locale, 'en', data);
|
93
|
+
});
|
94
|
+
const reset = useMemoizedFn(() => {
|
95
|
+
currentState.open = false;
|
96
|
+
currentState.callback = noop;
|
97
|
+
});
|
98
|
+
const open = useMemoizedFn(() => {
|
99
|
+
currentState.open = true;
|
100
|
+
});
|
101
|
+
const close = useMemoizedFn(() => {
|
102
|
+
currentState.open = false;
|
103
|
+
});
|
104
|
+
const _requestStorageAccess = useMemoizedFn(async callback => {
|
105
|
+
const result = await sharedBridgeRef.current?.callIframe('requestStorageAccess');
|
106
|
+
if (result.value) {
|
107
|
+
callback(true, 'broswer');
|
108
|
+
} else if (storageAccessState === undefined) {
|
109
|
+
// 用户未在当前网页交互过,此时必然需要进行一次弹窗
|
110
|
+
callback(false, 'system');
|
111
|
+
} else if (storageAccessState === 'denied') {
|
112
|
+
// 用户已经明确拒绝过跨站授权,直接弹窗
|
113
|
+
callback(false);
|
114
|
+
} else {
|
115
|
+
// NOTICE: 暂时保留这部分逻辑,后续可能会用上
|
116
|
+
// else if (
|
117
|
+
// result.error?.name === 'NotAllowedError' &&
|
118
|
+
// result.error?.message === 'requestStorageAccess not allowed'
|
119
|
+
// ) {
|
120
|
+
// // 操作被浏览器禁止,需要用户手动与 iframe 交互一次才可以
|
121
|
+
// currentState.open = true;
|
122
|
+
// currentState.callback = callback;
|
123
|
+
// }
|
124
|
+
currentState.open = true;
|
125
|
+
currentState.callback = callback;
|
126
|
+
}
|
127
|
+
});
|
128
|
+
const requestStorageAccess = useMemoizedFn(() => {
|
129
|
+
return new Promise(resolve => {
|
130
|
+
_requestStorageAccess((result, origin) => {
|
131
|
+
reset();
|
132
|
+
resolve({
|
133
|
+
value: result,
|
134
|
+
origin
|
135
|
+
});
|
136
|
+
});
|
137
|
+
});
|
138
|
+
});
|
139
|
+
const handleAllow = useMemoizedFn(() => {
|
140
|
+
currentState.open = false;
|
141
|
+
});
|
142
|
+
const handleClose = useMemoizedFn(() => {
|
143
|
+
currentState.open = false;
|
144
|
+
currentState.callback(false, 'system');
|
145
|
+
});
|
146
|
+
useImperativeHandle(ref, () => ({
|
147
|
+
open,
|
148
|
+
close,
|
149
|
+
requestStorageAccess
|
150
|
+
}));
|
151
|
+
return /*#__PURE__*/_jsx(DIDConnectContainer, {
|
152
|
+
popup: true,
|
153
|
+
open: currentState.open,
|
154
|
+
onClose: handleClose,
|
155
|
+
keepMounted: true,
|
156
|
+
children: /*#__PURE__*/_jsxs(Box, {
|
157
|
+
sx: {
|
158
|
+
backgroundColor: 'background.default',
|
159
|
+
display: 'flex',
|
160
|
+
flexDirection: 'column',
|
161
|
+
height: '100%',
|
162
|
+
position: 'relative',
|
163
|
+
maxWidth: '100%',
|
164
|
+
transition: 'width 0.2s ease-in-out',
|
165
|
+
margin: 'auto',
|
166
|
+
p: 3,
|
167
|
+
gap: 2
|
168
|
+
},
|
169
|
+
children: [/*#__PURE__*/_jsx(CloseButton, {
|
170
|
+
onClose: handleClose,
|
171
|
+
sx: {
|
172
|
+
position: 'absolute',
|
173
|
+
right: 14,
|
174
|
+
top: 14
|
175
|
+
}
|
176
|
+
}), /*#__PURE__*/_jsxs(Typography, {
|
177
|
+
component: "div",
|
178
|
+
variant: "h4",
|
179
|
+
sx: {
|
180
|
+
fontWeight: 700,
|
181
|
+
fontFamily: 'Lexend',
|
182
|
+
display: 'flex',
|
183
|
+
alignItems: 'center',
|
184
|
+
gap: 1
|
185
|
+
},
|
186
|
+
children: [/*#__PURE__*/_jsx(Box, {
|
187
|
+
component: Icon,
|
188
|
+
icon: lockOutlineIcon,
|
189
|
+
fontSize: 28,
|
190
|
+
sx: {
|
191
|
+
color: 'warning.main'
|
192
|
+
}
|
193
|
+
}), t('title')]
|
194
|
+
}), /*#__PURE__*/_jsxs(Box, {
|
195
|
+
sx: {
|
196
|
+
display: 'flex',
|
197
|
+
flexDirection: 'column',
|
198
|
+
gap: 1
|
199
|
+
},
|
200
|
+
children: [/*#__PURE__*/_jsx(Typography, {
|
201
|
+
children: t('reason', {
|
202
|
+
site: /*#__PURE__*/_jsx(Chip, {
|
203
|
+
clickable: true,
|
204
|
+
component: "a",
|
205
|
+
href: currentState.origin,
|
206
|
+
label: currentState.host,
|
207
|
+
size: "small",
|
208
|
+
deleteIcon: /*#__PURE__*/_jsx(Icon, {
|
209
|
+
icon: externalLinkIcon
|
210
|
+
}),
|
211
|
+
onDelete: () => {},
|
212
|
+
target: "_blank"
|
213
|
+
})
|
214
|
+
})
|
215
|
+
}), /*#__PURE__*/_jsx(Typography, {
|
216
|
+
component: "div",
|
217
|
+
children: t('clickAllow', {
|
218
|
+
allowButton: /*#__PURE__*/_jsx(Chip, {
|
219
|
+
label: t('allow'),
|
220
|
+
size: "small",
|
221
|
+
color: "success"
|
222
|
+
})
|
223
|
+
})
|
224
|
+
}), /*#__PURE__*/_jsxs(Box, {
|
225
|
+
sx: {
|
226
|
+
mt: 2
|
227
|
+
},
|
228
|
+
children: [/*#__PURE__*/_jsxs(Typography, {
|
229
|
+
sx: {
|
230
|
+
display: 'flex',
|
231
|
+
alignItems: 'center',
|
232
|
+
gap: 1,
|
233
|
+
mb: 0.5
|
234
|
+
},
|
235
|
+
children: [/*#__PURE__*/_jsx(Box, {
|
236
|
+
component: Icon,
|
237
|
+
icon: checkCircleIcon,
|
238
|
+
fontSize: 24,
|
239
|
+
sx: {
|
240
|
+
color: 'success.main'
|
241
|
+
}
|
242
|
+
}), t('afterAllow.title')]
|
243
|
+
}), /*#__PURE__*/_jsxs(List, {
|
244
|
+
dense: true,
|
245
|
+
sx: {
|
246
|
+
py: 0,
|
247
|
+
pl: 2
|
248
|
+
},
|
249
|
+
children: [/*#__PURE__*/_jsxs(ListItem, {
|
250
|
+
sx: {
|
251
|
+
display: 'flex',
|
252
|
+
alignItems: 'center',
|
253
|
+
gap: 0.8
|
254
|
+
},
|
255
|
+
children: [/*#__PURE__*/_jsx(Box, {
|
256
|
+
component: Icon,
|
257
|
+
icon: rocketLaunchRoundedIcon,
|
258
|
+
fontSize: 20,
|
259
|
+
sx: {
|
260
|
+
color: 'success.main'
|
261
|
+
}
|
262
|
+
}), t('afterAllow.list1')]
|
263
|
+
}), /*#__PURE__*/_jsxs(ListItem, {
|
264
|
+
sx: {
|
265
|
+
display: 'flex',
|
266
|
+
alignItems: 'center',
|
267
|
+
gap: 0.8
|
268
|
+
},
|
269
|
+
children: [/*#__PURE__*/_jsx(Box, {
|
270
|
+
component: Icon,
|
271
|
+
icon: rocketLaunchRoundedIcon,
|
272
|
+
fontSize: 20,
|
273
|
+
sx: {
|
274
|
+
color: 'success.main'
|
275
|
+
}
|
276
|
+
}), t('afterAllow.list2')]
|
277
|
+
})]
|
278
|
+
})]
|
279
|
+
}), /*#__PURE__*/_jsx(Typography, {
|
280
|
+
component: "div",
|
281
|
+
variant: "body2",
|
282
|
+
color: "grey.700",
|
283
|
+
children: t('dataUsage')
|
284
|
+
})]
|
285
|
+
}), /*#__PURE__*/_jsx(Box, {
|
286
|
+
sx: {
|
287
|
+
display: 'flex',
|
288
|
+
justifyContent: 'center'
|
289
|
+
},
|
290
|
+
children: /*#__PURE__*/_jsxs(Box, {
|
291
|
+
sx: {
|
292
|
+
position: 'relative',
|
293
|
+
display: 'inline-block',
|
294
|
+
cursor: 'pointer'
|
295
|
+
},
|
296
|
+
children: [/*#__PURE__*/_jsx(Button, {
|
297
|
+
variant: "contained",
|
298
|
+
color: "success",
|
299
|
+
onClick: handleAllow,
|
300
|
+
sx: {
|
301
|
+
minWidth: 100,
|
302
|
+
letterSpacing: 1
|
303
|
+
},
|
304
|
+
children: t('allow')
|
305
|
+
}), /*#__PURE__*/_jsx(SharedBridge, {
|
306
|
+
ref: sharedBridgeRef,
|
307
|
+
onClick: ({
|
308
|
+
value,
|
309
|
+
visitorId
|
310
|
+
}) => {
|
311
|
+
if (visitorId) setVisitorId(visitorId);
|
312
|
+
currentState.callback(value, 'broswer');
|
313
|
+
},
|
314
|
+
locale: locale,
|
315
|
+
src: src,
|
316
|
+
sx: {
|
317
|
+
zIndex: 1
|
318
|
+
}
|
319
|
+
})]
|
320
|
+
})
|
321
|
+
})]
|
322
|
+
})
|
323
|
+
});
|
324
|
+
});
|
325
|
+
export default /*#__PURE__*/memo(RequestStorageAccessApiDialog);
|
@@ -14,7 +14,7 @@ import { translations } from '../libs/translation';
|
|
14
14
|
import Typography from '../../Typography';
|
15
15
|
import QuickLoginItem from './quick-login-item';
|
16
16
|
import { getFederatedEnabled, getMaster } from '../../Util/federated';
|
17
|
-
import
|
17
|
+
import { BLOCKLET_SERVICE_PATH_PREFIX } from '../../Util/constant';
|
18
18
|
export default function UnLogin({
|
19
19
|
session,
|
20
20
|
onLogin = noop,
|
@@ -56,7 +56,7 @@ export default function UnLogin({
|
|
56
56
|
const masterSite = getMaster(blocklet);
|
57
57
|
const loginApp = federatedEnabled && masterSite ? masterSite : blocklet;
|
58
58
|
const loginAppName = loginApp?.appName || 'DID Connect';
|
59
|
-
const loginAppLogo = joinURL(loginApp?.appUrl || '/', loginApp?.appLogo ||
|
59
|
+
const loginAppLogo = joinURL(loginApp?.appUrl || '/', loginApp?.appLogo || `${BLOCKLET_SERVICE_PATH_PREFIX}/blocklet/logo?imageFilter=convert&f=png&h=80`);
|
60
60
|
useEffect(() => {
|
61
61
|
let timer;
|
62
62
|
|
@@ -88,42 +88,34 @@ export default function UnLogin({
|
|
88
88
|
}
|
89
89
|
});
|
90
90
|
return /*#__PURE__*/_jsxs(_Fragment, {
|
91
|
-
children: [/*#__PURE__*/_jsx(
|
92
|
-
|
91
|
+
children: [/*#__PURE__*/_jsx(IconButton, {
|
92
|
+
ref: userAnchorRef,
|
93
|
+
"data-cy": "sessionManager-login",
|
94
|
+
className: "arc-session-user-unlogin",
|
95
|
+
size: "medium",
|
93
96
|
onClick: _onLogin,
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
})
|
117
|
-
}) : /*#__PURE__*/_jsx(Icon, {
|
118
|
-
icon: UserIcon,
|
119
|
-
fontSize: size,
|
120
|
-
color: dark ? '#fff' : 'inherit',
|
121
|
-
style: {
|
122
|
-
transform: 'scale(1.25)'
|
123
|
-
}
|
124
|
-
})
|
125
|
-
});
|
126
|
-
}
|
97
|
+
"aria-label": "Login button",
|
98
|
+
children: isFirstLoading ? /*#__PURE__*/_jsx(Box, {
|
99
|
+
width: size,
|
100
|
+
height: size,
|
101
|
+
display: "flex",
|
102
|
+
justifyContent: "center",
|
103
|
+
alignItems: "center",
|
104
|
+
children: /*#__PURE__*/_jsx(CircularProgress, {
|
105
|
+
style: {
|
106
|
+
width: size - 4,
|
107
|
+
height: size - 4,
|
108
|
+
color: dark ? '#fff' : ''
|
109
|
+
}
|
110
|
+
})
|
111
|
+
}) : /*#__PURE__*/_jsx(Icon, {
|
112
|
+
icon: UserIcon,
|
113
|
+
fontSize: size,
|
114
|
+
color: dark ? '#fff' : 'inherit',
|
115
|
+
style: {
|
116
|
+
transform: 'scale(1.25)'
|
117
|
+
}
|
118
|
+
})
|
127
119
|
}), /*#__PURE__*/_jsx(Popper, {
|
128
120
|
open: currentState.open,
|
129
121
|
anchorEl: userAnchorRef.current,
|
@@ -1,16 +1,15 @@
|
|
1
1
|
import type { SxProps } from '@mui/material';
|
2
|
-
import React from 'react';
|
3
2
|
import { Locale } from '../type';
|
4
|
-
declare const
|
3
|
+
declare const _default: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<{
|
5
4
|
src: string;
|
6
5
|
onClick: (data: {
|
7
6
|
action: string;
|
8
7
|
value: boolean;
|
9
8
|
visitorId?: string;
|
9
|
+
error?: Error;
|
10
10
|
}) => void;
|
11
|
-
onLoad
|
11
|
+
onLoad?: () => void;
|
12
12
|
sx?: SxProps;
|
13
|
-
iframeRef?: React.RefObject<HTMLIFrameElement>;
|
14
13
|
locale?: Locale;
|
15
|
-
}
|
16
|
-
export default
|
14
|
+
} & import("react").RefAttributes<unknown>>>;
|
15
|
+
export default _default;
|
@@ -1,28 +1,27 @@
|
|
1
|
-
import { jsx as _jsx
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
2
2
|
import { Box } from '@mui/material';
|
3
|
-
import
|
3
|
+
import { forwardRef, memo, useEffect, useId, useImperativeHandle, useRef } from 'react';
|
4
4
|
import { withQuery } from 'ufo';
|
5
5
|
import { useMemoizedFn, useReactive } from 'ahooks';
|
6
|
+
import noop from 'lodash/noop';
|
6
7
|
import { mergeSx } from '../Util/style';
|
7
8
|
import { callIframe, getCallbackAction } from '../Util/iframe';
|
8
|
-
|
9
|
-
import { DIDConnectContainer } from '../DIDConnect';
|
10
|
-
const SharedBridge = /*#__PURE__*/memo(function SharedBridge({
|
9
|
+
const SharedBridge = /*#__PURE__*/forwardRef(({
|
11
10
|
src,
|
12
11
|
onClick,
|
13
|
-
onLoad,
|
12
|
+
onLoad = noop,
|
14
13
|
sx,
|
15
|
-
iframeRef,
|
16
14
|
locale = 'en',
|
17
15
|
...rest
|
18
|
-
}) {
|
19
|
-
const
|
16
|
+
}, ref) => {
|
17
|
+
const targetIframeRef = useRef(null);
|
20
18
|
const refId = useId();
|
21
19
|
const dataId = `shared-bridge_${refId}`;
|
22
20
|
const currentState = useReactive({
|
23
21
|
hasInited: undefined,
|
24
22
|
open: false,
|
25
23
|
hasStorageAccess: false,
|
24
|
+
containerEl: null,
|
26
25
|
get origin() {
|
27
26
|
try {
|
28
27
|
return new URL(src).origin;
|
@@ -38,7 +37,6 @@ const SharedBridge = /*#__PURE__*/memo(function SharedBridge({
|
|
38
37
|
}
|
39
38
|
}
|
40
39
|
});
|
41
|
-
const targetIframeRef = iframeRef ?? _iframeRef;
|
42
40
|
useEffect(() => {
|
43
41
|
async function handleMessage(event) {
|
44
42
|
const {
|
@@ -74,6 +72,7 @@ const SharedBridge = /*#__PURE__*/memo(function SharedBridge({
|
|
74
72
|
currentState.hasStorageAccess = value;
|
75
73
|
currentState.hasInited = true;
|
76
74
|
});
|
75
|
+
// HACK: 如果目标 bridge 1s 内没有初始化,则认为目标 bridge 不兼容,不进行后续内容的加载
|
77
76
|
setTimeout(() => {
|
78
77
|
if (currentState.hasInited === undefined) {
|
79
78
|
currentState.hasInited = false;
|
@@ -81,43 +80,30 @@ const SharedBridge = /*#__PURE__*/memo(function SharedBridge({
|
|
81
80
|
}, 1000);
|
82
81
|
onLoad();
|
83
82
|
});
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
id: dataId
|
109
|
-
}),
|
110
|
-
sx: mergeSx({
|
111
|
-
border: 0,
|
112
|
-
position: 'absolute',
|
113
|
-
top: 0,
|
114
|
-
left: 0,
|
115
|
-
width: '100%',
|
116
|
-
height: '100%',
|
117
|
-
cursor: 'pointer',
|
118
|
-
opacity: 0
|
119
|
-
}, sx)
|
120
|
-
})]
|
83
|
+
useImperativeHandle(ref, () => ({
|
84
|
+
callIframe(action) {
|
85
|
+
return callIframe(targetIframeRef.current, action);
|
86
|
+
}
|
87
|
+
}));
|
88
|
+
return /*#__PURE__*/_jsx(Box, {
|
89
|
+
...rest,
|
90
|
+
component: "iframe",
|
91
|
+
ref: targetIframeRef,
|
92
|
+
onLoad: handleLoad,
|
93
|
+
"data-id": dataId,
|
94
|
+
src: withQuery(src, {
|
95
|
+
id: dataId
|
96
|
+
}),
|
97
|
+
sx: mergeSx({
|
98
|
+
border: 0,
|
99
|
+
position: 'absolute',
|
100
|
+
top: 0,
|
101
|
+
left: 0,
|
102
|
+
width: '100%',
|
103
|
+
height: '100%',
|
104
|
+
cursor: 'pointer',
|
105
|
+
backgroundColor: 'transparent'
|
106
|
+
}, sx)
|
121
107
|
});
|
122
108
|
});
|
123
|
-
export default SharedBridge;
|
109
|
+
export default /*#__PURE__*/memo(SharedBridge);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arcblock/ux",
|
3
|
-
"version": "2.13.
|
3
|
+
"version": "2.13.29",
|
4
4
|
"description": "Common used react components for arcblock products",
|
5
5
|
"keywords": [
|
6
6
|
"react",
|
@@ -71,14 +71,14 @@
|
|
71
71
|
"react": ">=18.2.0",
|
72
72
|
"react-router-dom": ">=6.22.3"
|
73
73
|
},
|
74
|
-
"gitHead": "
|
74
|
+
"gitHead": "98e08de2a4ec51ae6181b57e2c6cf175eabd92ff",
|
75
75
|
"dependencies": {
|
76
76
|
"@arcblock/did-motif": "^1.1.13",
|
77
|
-
"@arcblock/icons": "^2.13.
|
78
|
-
"@arcblock/nft-display": "^2.13.
|
79
|
-
"@arcblock/react-hooks": "^2.13.
|
77
|
+
"@arcblock/icons": "^2.13.29",
|
78
|
+
"@arcblock/nft-display": "^2.13.29",
|
79
|
+
"@arcblock/react-hooks": "^2.13.29",
|
80
80
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
81
|
-
"@blocklet/theme": "^2.13.
|
81
|
+
"@blocklet/theme": "^2.13.29",
|
82
82
|
"@fontsource/roboto": "~5.1.1",
|
83
83
|
"@fontsource/ubuntu-mono": "^5.0.18",
|
84
84
|
"@iconify-icons/logos": "^1.2.36",
|