@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
- 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,53 @@
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";
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 b = "/.well-known/service/wizard/bind-account";
8
- function B({
8
+ const B = "/.well-known/service/onboard/bind-account";
9
+ function Q({
9
10
  onFinished: y = () => {
10
11
  },
11
- show: o = !1,
12
- onChangeVisible: v = () => {
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, 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] = 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 t = new URL(m.current.contentWindow.location.href).pathname;
21
- localStorage.setItem("wizard-current-url", t), u(t);
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
- 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), C(!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: U, data: W } = o.data || {};
41
+ switch (U) {
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"), z.current?.(W);
45
47
  break;
46
48
  }
47
49
  case "wizard.close": {
48
- f.current();
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") || n(!0);
59
+ localStorage.getItem("wizard-completed") || i(!0);
58
60
  }, []), !r)
59
61
  return null;
60
- const S = A(F(window.location.origin, C), {
62
+ const S = A(F(window.location.origin, k), {
61
63
  locale: I
62
64
  });
63
65
  return /* @__PURE__ */ x(
64
- D,
66
+ R,
65
67
  {
68
+ id: "wizard-dialog",
66
69
  open: r,
67
- onClose: () => f.current(),
70
+ onClose: () => p.current(),
68
71
  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)"
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__ */ i(
100
+ /* @__PURE__ */ a(
92
101
  "iframe",
93
102
  {
94
- ref: m,
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: c ? 1 : 0,
113
+ opacity: u ? 1 : 0,
104
114
  transition: "opacity 0.3s ease-in-out"
105
115
  },
106
- onLoad: () => d(!0)
116
+ onLoad: () => f(!0)
107
117
  }
108
118
  ),
109
- c ? null : /* @__PURE__ */ i(
110
- R,
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(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
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
- B.propTypes = {
134
- onFinished: a.func,
135
- show: a.bool,
136
- onChangeVisible: a.func,
137
- loadingText: a.node
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
- B as default
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.6",
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.6",
39
- "@arcblock/icons": "3.1.6",
40
- "@arcblock/react-hooks": "3.1.6",
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.6",
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": "d3267421c4d35038b226d34edc0e7bc943c5c926"
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/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,19 +79,10 @@ 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
- const result = onFinishedRef.current?.(data);
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
- 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
- }),
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
  };