@blocklet/ui-react 3.1.6 → 3.1.8
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.
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
declare function WizardModal({ onFinished, show, onChangeVisible, loadingText, defaultPath, ...props }: {
|
|
2
|
+
[x: string]: any;
|
|
3
3
|
onFinished?: (() => void) | undefined;
|
|
4
4
|
show?: boolean | undefined;
|
|
5
5
|
onChangeVisible?: (() => void) | undefined;
|
|
6
6
|
loadingText?: string | undefined;
|
|
7
|
+
defaultPath?: string | undefined;
|
|
7
8
|
}): import("react/jsx-runtime").JSX.Element | null;
|
|
8
9
|
declare namespace WizardModal {
|
|
9
|
-
|
|
10
|
-
let onFinished: PropTypes.Requireable<(...args: any[]) => any>;
|
|
11
|
-
let show: PropTypes.Requireable<boolean>;
|
|
12
|
-
let onChangeVisible: PropTypes.Requireable<(...args: any[]) => any>;
|
|
13
|
-
let loadingText: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
14
|
-
}
|
|
10
|
+
let propTypes: any;
|
|
15
11
|
}
|
|
16
12
|
export default WizardModal;
|
|
@@ -1,51 +1,53 @@
|
|
|
1
|
-
import { jsxs as x, jsx as
|
|
2
|
-
import { useLocaleContext as
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
1
|
+
import { jsxs as x, jsx as a } from "react/jsx-runtime";
|
|
2
|
+
import { useLocaleContext as T } from "@arcblock/ux/lib/Locale/context";
|
|
3
|
+
import { Dialog as R, useTheme as j, useMediaQuery as D, Box as v, CircularProgress as E, Typography as M } from "@mui/material";
|
|
4
|
+
import P from "lodash/merge";
|
|
5
|
+
import t from "prop-types";
|
|
6
|
+
import { useState as h, useRef as b, useEffect as s } from "react";
|
|
6
7
|
import { withQuery as A, joinURL as F } from "ufo";
|
|
7
|
-
const
|
|
8
|
-
function
|
|
8
|
+
const B = "/.well-known/service/onboard/bind-account";
|
|
9
|
+
function Q({
|
|
9
10
|
onFinished: y = () => {
|
|
10
11
|
},
|
|
11
|
-
show:
|
|
12
|
-
onChangeVisible:
|
|
12
|
+
show: n = !1,
|
|
13
|
+
onChangeVisible: C = () => {
|
|
13
14
|
},
|
|
14
|
-
loadingText: l = ""
|
|
15
|
+
loadingText: l = "",
|
|
16
|
+
defaultPath: c = B,
|
|
17
|
+
...d
|
|
15
18
|
}) {
|
|
16
|
-
const [r,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
const [r, i] = h(n), [u, f] = h(!1), [k, m] = h(() => {
|
|
20
|
+
const e = localStorage.getItem("wizard-current-url");
|
|
21
|
+
return e?.includes("/.well-known/service/onboard") ? e : c;
|
|
22
|
+
}), z = b(y), p = b(), g = b(null), { locale: I } = T(), L = j(), w = D(L.breakpoints.down("sm"));
|
|
23
|
+
if (z.current = y, p.current = () => {
|
|
24
|
+
if (g.current?.contentWindow)
|
|
19
25
|
try {
|
|
20
|
-
const
|
|
21
|
-
localStorage.setItem("wizard-current-url",
|
|
26
|
+
const o = new URL(g.current.contentWindow.location.href).pathname;
|
|
27
|
+
localStorage.setItem("wizard-current-url", o), m(o);
|
|
22
28
|
} catch (e) {
|
|
23
|
-
|
|
29
|
+
m(c), console.warn("Failed to save wizard URL:", e);
|
|
24
30
|
}
|
|
25
|
-
localStorage.setItem("wizard-completed", "true"),
|
|
31
|
+
localStorage.setItem("wizard-completed", "true"), i(!1), C(!1);
|
|
26
32
|
}, s(() => {
|
|
27
|
-
|
|
28
|
-
}, [
|
|
29
|
-
!r &&
|
|
33
|
+
n !== r && i(n);
|
|
34
|
+
}, [n]), s(() => {
|
|
35
|
+
!r && u && f(!1);
|
|
30
36
|
}, [r]), s(() => {
|
|
31
|
-
const e = (
|
|
32
|
-
if (
|
|
37
|
+
const e = (o) => {
|
|
38
|
+
if (o.origin !== window.location.origin)
|
|
33
39
|
return;
|
|
34
|
-
const { type:
|
|
35
|
-
switch (
|
|
40
|
+
const { type: U, data: W } = o.data || {};
|
|
41
|
+
switch (U) {
|
|
36
42
|
case "wizard.loaded":
|
|
37
|
-
|
|
43
|
+
f(!0);
|
|
38
44
|
break;
|
|
39
45
|
case "wizard.finished": {
|
|
40
|
-
|
|
41
|
-
const w = z.current?.(U);
|
|
42
|
-
w instanceof Promise ? w.then((W) => {
|
|
43
|
-
W !== !1 && window.location.reload();
|
|
44
|
-
}) : w !== !1 && window.location.reload();
|
|
46
|
+
i(!1), m(c), localStorage.removeItem("wizard-current-url"), localStorage.setItem("wizard-completed", "true"), z.current?.(W);
|
|
45
47
|
break;
|
|
46
48
|
}
|
|
47
49
|
case "wizard.close": {
|
|
48
|
-
|
|
50
|
+
p.current();
|
|
49
51
|
break;
|
|
50
52
|
}
|
|
51
53
|
}
|
|
@@ -54,44 +56,52 @@ function B({
|
|
|
54
56
|
window.removeEventListener("message", e);
|
|
55
57
|
};
|
|
56
58
|
}, []), s(() => {
|
|
57
|
-
localStorage.getItem("wizard-completed") ||
|
|
59
|
+
localStorage.getItem("wizard-completed") || i(!0);
|
|
58
60
|
}, []), !r)
|
|
59
61
|
return null;
|
|
60
|
-
const S = A(F(window.location.origin,
|
|
62
|
+
const S = A(F(window.location.origin, k), {
|
|
61
63
|
locale: I
|
|
62
64
|
});
|
|
63
65
|
return /* @__PURE__ */ x(
|
|
64
|
-
|
|
66
|
+
R,
|
|
65
67
|
{
|
|
68
|
+
id: "wizard-dialog",
|
|
66
69
|
open: r,
|
|
67
|
-
onClose: () =>
|
|
70
|
+
onClose: () => p.current(),
|
|
68
71
|
fullWidth: !0,
|
|
69
|
-
maxWidth:
|
|
70
|
-
fullScreen:
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
72
|
+
maxWidth: w ? !1 : "md",
|
|
73
|
+
fullScreen: w,
|
|
74
|
+
...d,
|
|
75
|
+
slotProps: P(
|
|
76
|
+
{},
|
|
77
|
+
{
|
|
78
|
+
paper: {
|
|
79
|
+
sx: {
|
|
80
|
+
margin: 0,
|
|
81
|
+
borderRadius: 0,
|
|
82
|
+
position: "relative",
|
|
83
|
+
overflow: "hidden",
|
|
84
|
+
...w ? { borderRadius: 0 } : {
|
|
85
|
+
borderRadius: 1,
|
|
86
|
+
height: "720px"
|
|
87
|
+
}
|
|
81
88
|
}
|
|
82
89
|
}
|
|
83
|
-
}
|
|
84
|
-
|
|
90
|
+
},
|
|
91
|
+
d.slotProps
|
|
92
|
+
),
|
|
85
93
|
sx: {
|
|
86
94
|
"& .MuiBackdrop-root": {
|
|
87
95
|
backgroundColor: "rgba(0, 0, 0, 0.5)"
|
|
88
|
-
}
|
|
96
|
+
},
|
|
97
|
+
...d.sx
|
|
89
98
|
},
|
|
90
99
|
children: [
|
|
91
|
-
/* @__PURE__ */
|
|
100
|
+
/* @__PURE__ */ a(
|
|
92
101
|
"iframe",
|
|
93
102
|
{
|
|
94
|
-
ref:
|
|
103
|
+
ref: g,
|
|
104
|
+
id: "wizard-iframe",
|
|
95
105
|
src: S,
|
|
96
106
|
title: "Setup Wizard",
|
|
97
107
|
style: {
|
|
@@ -100,14 +110,14 @@ function B({
|
|
|
100
110
|
border: 0,
|
|
101
111
|
padding: 0,
|
|
102
112
|
margin: 0,
|
|
103
|
-
opacity:
|
|
113
|
+
opacity: u ? 1 : 0,
|
|
104
114
|
transition: "opacity 0.3s ease-in-out"
|
|
105
115
|
},
|
|
106
|
-
onLoad: () =>
|
|
116
|
+
onLoad: () => f(!0)
|
|
107
117
|
}
|
|
108
118
|
),
|
|
109
|
-
|
|
110
|
-
|
|
119
|
+
u ? null : /* @__PURE__ */ a(
|
|
120
|
+
v,
|
|
111
121
|
{
|
|
112
122
|
sx: {
|
|
113
123
|
position: "absolute",
|
|
@@ -120,9 +130,9 @@ function B({
|
|
|
120
130
|
alignItems: "center",
|
|
121
131
|
bgcolor: "background.paper"
|
|
122
132
|
},
|
|
123
|
-
children: /* @__PURE__ */ x(
|
|
124
|
-
/* @__PURE__ */
|
|
125
|
-
typeof l == "string" ? /* @__PURE__ */
|
|
133
|
+
children: /* @__PURE__ */ x(v, { sx: { display: "flex", alignItems: "center", flexDirection: "column", gap: 1 }, children: [
|
|
134
|
+
/* @__PURE__ */ a(E, {}),
|
|
135
|
+
typeof l == "string" ? /* @__PURE__ */ a(M, { variant: "body1", children: l }) : l
|
|
126
136
|
] })
|
|
127
137
|
}
|
|
128
138
|
)
|
|
@@ -130,12 +140,14 @@ function B({
|
|
|
130
140
|
}
|
|
131
141
|
);
|
|
132
142
|
}
|
|
133
|
-
|
|
134
|
-
onFinished:
|
|
135
|
-
show:
|
|
136
|
-
onChangeVisible:
|
|
137
|
-
loadingText:
|
|
143
|
+
Q.propTypes = {
|
|
144
|
+
onFinished: t.func,
|
|
145
|
+
show: t.bool,
|
|
146
|
+
onChangeVisible: t.func,
|
|
147
|
+
loadingText: t.node,
|
|
148
|
+
defaultPath: t.string,
|
|
149
|
+
...R.propTypes
|
|
138
150
|
};
|
|
139
151
|
export {
|
|
140
|
-
|
|
152
|
+
Q as default
|
|
141
153
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/ui-react",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.8",
|
|
4
4
|
"description": "Some useful front-end web components that can be used in Blocklets.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@abtnode/constant": "^1.16.47",
|
|
37
37
|
"@abtnode/util": "^1.16.47",
|
|
38
|
-
"@arcblock/bridge": "3.1.
|
|
39
|
-
"@arcblock/icons": "3.1.
|
|
40
|
-
"@arcblock/react-hooks": "3.1.
|
|
38
|
+
"@arcblock/bridge": "3.1.8",
|
|
39
|
+
"@arcblock/icons": "3.1.8",
|
|
40
|
+
"@arcblock/react-hooks": "3.1.8",
|
|
41
41
|
"@arcblock/ws": "^1.21.2",
|
|
42
42
|
"@blocklet/constant": "^1.16.47",
|
|
43
43
|
"@blocklet/did-space-react": "^1.1.14",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"access": "public"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
|
-
"@arcblock/did-connect-react": "3.1.
|
|
87
|
+
"@arcblock/did-connect-react": "3.1.8",
|
|
88
88
|
"@types/dompurify": "^3.2.0",
|
|
89
89
|
"@types/ua-parser-js": "^0.7.39",
|
|
90
90
|
"@types/validator": "^13.15.2",
|
|
@@ -92,5 +92,5 @@
|
|
|
92
92
|
"jest": "^29.7.0",
|
|
93
93
|
"unbuild": "^2.0.0"
|
|
94
94
|
},
|
|
95
|
-
"gitHead": "
|
|
95
|
+
"gitHead": "bb291c7f0f1afa39ca3dc07471c63b118a377cbe"
|
|
96
96
|
}
|
|
@@ -1,22 +1,29 @@
|
|
|
1
1
|
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
2
2
|
import { Box, CircularProgress, Dialog, Typography, useMediaQuery, useTheme } from '@mui/material';
|
|
3
|
+
import merge from 'lodash/merge';
|
|
3
4
|
import PropTypes from 'prop-types';
|
|
4
5
|
import { useEffect, useRef, useState } from 'react';
|
|
5
6
|
import { joinURL, withQuery } from 'ufo';
|
|
6
7
|
|
|
7
|
-
const DEFAULT_WIZARD_PATH = '/.well-known/service/
|
|
8
|
+
const DEFAULT_WIZARD_PATH = '/.well-known/service/onboard/bind-account';
|
|
8
9
|
|
|
9
10
|
export default function WizardModal({
|
|
10
11
|
onFinished = () => {},
|
|
11
12
|
show = false,
|
|
12
13
|
onChangeVisible = () => {},
|
|
13
14
|
loadingText = '',
|
|
15
|
+
defaultPath = DEFAULT_WIZARD_PATH,
|
|
16
|
+
...props
|
|
14
17
|
}) {
|
|
15
18
|
const [open, setOpen] = useState(show);
|
|
16
19
|
const [loaded, setLoaded] = useState(false);
|
|
17
20
|
const [currentUrl, setCurrentUrl] = useState(() => {
|
|
18
21
|
// 从 localStorage 恢复上次的 URL
|
|
19
|
-
|
|
22
|
+
const savedUrl = localStorage.getItem('wizard-current-url');
|
|
23
|
+
if (savedUrl?.includes('/.well-known/service/onboard')) {
|
|
24
|
+
return savedUrl;
|
|
25
|
+
}
|
|
26
|
+
return defaultPath;
|
|
20
27
|
});
|
|
21
28
|
const onFinishedRef = useRef(onFinished);
|
|
22
29
|
const handleCloseRef = useRef();
|
|
@@ -34,7 +41,7 @@ export default function WizardModal({
|
|
|
34
41
|
localStorage.setItem('wizard-current-url', savedUrl);
|
|
35
42
|
setCurrentUrl(savedUrl);
|
|
36
43
|
} catch (e) {
|
|
37
|
-
setCurrentUrl(
|
|
44
|
+
setCurrentUrl(defaultPath);
|
|
38
45
|
console.warn('Failed to save wizard URL:', e);
|
|
39
46
|
}
|
|
40
47
|
}
|
|
@@ -72,19 +79,10 @@ export default function WizardModal({
|
|
|
72
79
|
case 'wizard.finished': {
|
|
73
80
|
setOpen(false);
|
|
74
81
|
// 完成后重置为默认 URL
|
|
75
|
-
setCurrentUrl(
|
|
82
|
+
setCurrentUrl(defaultPath);
|
|
76
83
|
localStorage.removeItem('wizard-current-url');
|
|
77
84
|
localStorage.setItem('wizard-completed', 'true');
|
|
78
|
-
|
|
79
|
-
if (result instanceof Promise) {
|
|
80
|
-
result.then((reload) => {
|
|
81
|
-
if (reload !== false) {
|
|
82
|
-
window.location.reload();
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
} else if (result !== false) {
|
|
86
|
-
window.location.reload();
|
|
87
|
-
}
|
|
85
|
+
onFinishedRef.current?.(data);
|
|
88
86
|
break;
|
|
89
87
|
}
|
|
90
88
|
case 'wizard.close': {
|
|
@@ -100,7 +98,7 @@ export default function WizardModal({
|
|
|
100
98
|
return () => {
|
|
101
99
|
window.removeEventListener('message', listener);
|
|
102
100
|
};
|
|
103
|
-
}, []);
|
|
101
|
+
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
104
102
|
|
|
105
103
|
// 控制弹窗显示
|
|
106
104
|
useEffect(() => {
|
|
@@ -120,34 +118,42 @@ export default function WizardModal({
|
|
|
120
118
|
|
|
121
119
|
return (
|
|
122
120
|
<Dialog
|
|
121
|
+
id="wizard-dialog"
|
|
123
122
|
open={open}
|
|
124
123
|
onClose={() => handleCloseRef.current()}
|
|
125
124
|
fullWidth
|
|
126
125
|
maxWidth={isMobile ? false : 'md'}
|
|
127
126
|
fullScreen={isMobile}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
:
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
127
|
+
{...props}
|
|
128
|
+
slotProps={merge(
|
|
129
|
+
{},
|
|
130
|
+
{
|
|
131
|
+
paper: {
|
|
132
|
+
sx: {
|
|
133
|
+
margin: 0,
|
|
134
|
+
borderRadius: 0,
|
|
135
|
+
position: 'relative',
|
|
136
|
+
overflow: 'hidden',
|
|
137
|
+
...(isMobile
|
|
138
|
+
? { borderRadius: 0 }
|
|
139
|
+
: {
|
|
140
|
+
borderRadius: 1,
|
|
141
|
+
height: '720px',
|
|
142
|
+
}),
|
|
143
|
+
},
|
|
141
144
|
},
|
|
142
145
|
},
|
|
143
|
-
|
|
146
|
+
props.slotProps
|
|
147
|
+
)}
|
|
144
148
|
sx={{
|
|
145
149
|
'& .MuiBackdrop-root': {
|
|
146
150
|
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
|
147
151
|
},
|
|
152
|
+
...props.sx,
|
|
148
153
|
}}>
|
|
149
154
|
<iframe
|
|
150
155
|
ref={iframeRef}
|
|
156
|
+
id="wizard-iframe"
|
|
151
157
|
src={src}
|
|
152
158
|
title="Setup Wizard"
|
|
153
159
|
style={{
|
|
@@ -189,4 +195,6 @@ WizardModal.propTypes = {
|
|
|
189
195
|
show: PropTypes.bool,
|
|
190
196
|
onChangeVisible: PropTypes.func,
|
|
191
197
|
loadingText: PropTypes.node,
|
|
198
|
+
defaultPath: PropTypes.string,
|
|
199
|
+
...Dialog.propTypes,
|
|
192
200
|
};
|