@blocklet/ui-react 3.1.6 → 3.1.7

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