@arcblock/ux 3.0.21 → 3.0.23

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,39 +1,40 @@
1
- import { jsx as m, jsxs as j } from "react/jsx-runtime";
2
- import { createContext as F, use as G, useState as E, useRef as H, useMemo as f, useCallback as x, useEffect as h } from "react";
3
- import { useTheme as M, StyledEngineProvider as I, ThemeProvider as N, CssBaseline as O, GlobalStyles as U } from "@mui/material";
4
- import { deepmerge as A } from "@mui/utils";
5
- import y from "lodash/set";
6
- import { useDebounceFn as K } from "ahooks";
7
- import { getBlockletThemeOptions as V, BLOCKLET_THEME_PREFER_KEY as b, isValidThemeMode as W, getDefaultThemePrefer as $ } from "@blocklet/theme";
8
- import { useLocationState as q } from "../hooks/use-location-state.js";
9
- import { createTheme as T, lazyCreateDefaultTheme as z, isUxTheme as Y, isTheme as J } from "./theme.js";
10
- const Q = T(), P = F({});
11
- function X() {
12
- return G(P);
1
+ import { jsx as m, jsxs as I } from "react/jsx-runtime";
2
+ import { createContext as N, use as O, useState as x, useRef as K, useMemo as g, useCallback as B, useEffect as b } from "react";
3
+ import { useTheme as R, CssBaseline as V, StyledEngineProvider as W, ThemeProvider as q, GlobalStyles as z } from "@mui/material";
4
+ import { deepmerge as Y } from "@mui/utils";
5
+ import $ from "lodash/set";
6
+ import J from "lodash/isUndefined";
7
+ import { useDebounceFn as Q, useCreation as M } from "ahooks";
8
+ import { getBlockletThemeOptions as X, BLOCKLET_THEME_PREFER_KEY as h, isValidThemeMode as Z, getDefaultThemePrefer as P } from "@blocklet/theme";
9
+ import { useLocationState as ee } from "../hooks/use-location-state.js";
10
+ import { createTheme as C, lazyCreateDefaultTheme as te, isUxTheme as oe, isTheme as re } from "./theme.js";
11
+ const ne = C(), j = N({});
12
+ function A() {
13
+ return O(j);
13
14
  }
14
- const B = (l) => l ? l === "system" ? $({ theme: { prefer: "system" } }) : l : $();
15
- function Z({ className: l = void 0 }) {
16
- const t = M();
15
+ const _ = (i) => i ? i === "system" ? P({ theme: { prefer: "system" } }) : i : P();
16
+ function se({ className: i = void 0 }) {
17
+ const t = R();
17
18
  if (t.palette.mode === "dark") {
18
- const r = "transparent", a = t.palette.grey[300], o = (l || "").trim().split(/\s+/).filter(Boolean).map((u) => u.startsWith(".") ? u : `.${u}`).join(" "), s = o ? `${o}::-webkit-scrollbar, ${o} *::-webkit-scrollbar` : "*::-webkit-scrollbar", i = o ? `${o}::-webkit-scrollbar-track, ${o} *::-webkit-scrollbar-track` : "*::-webkit-scrollbar-track", c = o ? `${o}::-webkit-scrollbar-thumb, ${o} *::-webkit-scrollbar-thumb` : "*::-webkit-scrollbar-thumb", g = o ? `${o}, ${o} *` : "*";
19
+ const n = "transparent", s = t.palette.grey[300], o = (i || "").trim().split(/\s+/).filter(Boolean).map((d) => d.startsWith(".") ? d : `.${d}`).join(" "), u = o ? `${o}::-webkit-scrollbar, ${o} *::-webkit-scrollbar` : "*::-webkit-scrollbar", r = o ? `${o}::-webkit-scrollbar-track, ${o} *::-webkit-scrollbar-track` : "*::-webkit-scrollbar-track", a = o ? `${o}::-webkit-scrollbar-thumb, ${o} *::-webkit-scrollbar-thumb` : "*::-webkit-scrollbar-thumb", c = o ? `${o}, ${o} *` : "*";
19
20
  return /* @__PURE__ */ m(
20
- U,
21
+ z,
21
22
  {
22
23
  styles: {
23
24
  // Chrome, Safari, Edge
24
25
  "@supports selector(::-webkit-scrollbar)": {
25
- [s]: {
26
+ [u]: {
26
27
  width: "12px",
27
28
  height: "12px"
28
29
  },
29
- [i]: {
30
- background: r
30
+ [r]: {
31
+ background: n
31
32
  },
32
- [c]: {
33
- background: a,
33
+ [a]: {
34
+ background: s,
34
35
  borderRadius: "6px",
35
36
  border: "2px solid",
36
- borderColor: r,
37
+ borderColor: n,
37
38
  backgroundClip: "padding-box",
38
39
  "&:hover": {
39
40
  background: t.palette.grey[400],
@@ -43,9 +44,9 @@ function Z({ className: l = void 0 }) {
43
44
  },
44
45
  // Firefox
45
46
  "@supports not selector(::-webkit-scrollbar)": {
46
- [g]: {
47
+ [c]: {
47
48
  scrollbarWidth: "auto",
48
- scrollbarColor: `${a} ${r}`
49
+ scrollbarColor: `${s} ${n}`
49
50
  }
50
51
  }
51
52
  }
@@ -54,97 +55,101 @@ function Z({ className: l = void 0 }) {
54
55
  }
55
56
  return null;
56
57
  }
57
- function _({
58
- children: l = null,
59
- theme: t = Q,
60
- injectFirst: r = !0,
61
- darkSchemeClass: a = ""
58
+ let D = !1;
59
+ const L = {};
60
+ function U({
61
+ children: i = null,
62
+ theme: t = ne,
63
+ injectFirst: n = !0,
64
+ darkSchemeClass: s = ""
62
65
  }) {
63
- const o = f(() => typeof t == "function" || J(t) ? t : T(t), [t]);
66
+ const o = g(() => typeof t == "function" || re(t) ? t : C(t), [t]), u = M(() => D ? null : (D = !0, /* @__PURE__ */ m(V, {})), []), r = M(() => L[s] ? null : (L[s] = !0, /* @__PURE__ */ m(se, { className: s })), [s]);
64
67
  return (
65
68
  // injectFirst 会影响 makeStyles 自定义样式和 mui styles 覆盖问题
66
- /* @__PURE__ */ m(I, { injectFirst: r, children: /* @__PURE__ */ j(N, { theme: o, children: [
67
- /* @__PURE__ */ m(O, {}),
68
- /* @__PURE__ */ m(Z, { className: a }),
69
- l
69
+ /* @__PURE__ */ m(W, { injectFirst: n, children: /* @__PURE__ */ I(q, { theme: o, children: [
70
+ u,
71
+ r,
72
+ i
70
73
  ] }) })
71
74
  );
72
75
  }
73
- function ee({
74
- children: l = null,
76
+ function le({
77
+ children: i = null,
75
78
  theme: t = void 0,
76
- prefer: r = void 0,
77
- disableBlockletTheme: a = !1,
79
+ prefer: n = void 0,
80
+ disableBlockletTheme: s = !1,
78
81
  ...o
79
82
  }) {
80
- const [s, i] = E(() => B(r)), [c, g] = E(null), u = M(), k = q(), d = H(null), { run: w } = K(
83
+ const u = A(), [r, a] = x(() => _(n)), [c, d] = x(null), p = R(), k = ee(), f = K(null), S = J(u.toggleMode), { run: w } = Q(
81
84
  (e) => {
82
- g(e);
85
+ d(e);
83
86
  },
84
87
  {
85
88
  wait: 200
86
89
  }
87
- ), C = f(() => {
90
+ ), v = g(() => {
88
91
  let e = {};
89
92
  if (t) {
90
- const R = z(s);
93
+ const G = te(r);
91
94
  if (typeof t == "function") {
92
- const D = R();
93
- Y(u) ? e = { ...t(u, { mode: s }) } : e = { ...t(D, { mode: s }) };
95
+ const H = G();
96
+ oe(p) ? e = { ...t(p, { mode: r }) } : e = { ...t(H, { mode: r }) };
94
97
  } else
95
98
  e = { ...t };
96
99
  }
97
- let n = s;
98
- return c && (n = c.mode || "light", e = A(e, V(n, c))), y(e, "palette.mode", n), y(e, "mode", n), e;
99
- }, [s, t, u, c]), p = f(() => T({ ...C, disableBlockletTheme: !!c || a }), [C, a, c]), S = x(() => {
100
- const e = s === "light" ? "dark" : "light";
101
- i(e), sessionStorage.removeItem(b), localStorage.setItem(b, e);
102
- }, [s, i]), v = x(
100
+ let l = r;
101
+ return c && (l = c.mode || "light", e = Y(e, X(l, c))), $(e, "palette.mode", l), $(e, "mode", l), e;
102
+ }, [r, t, p, c]), T = g(() => C({ ...v, disableBlockletTheme: !!c || s }), [v, s, c]), E = B(() => {
103
+ const e = r === "light" ? "dark" : "light";
104
+ a(e), sessionStorage.removeItem(h), localStorage.setItem(h, e);
105
+ }, [r, a]), y = B(
103
106
  (e) => {
104
- s !== e && (i(e), sessionStorage.removeItem(b), localStorage.setItem(b, e));
107
+ r !== e && (a(e), sessionStorage.removeItem(h), localStorage.setItem(h, e));
105
108
  },
106
- [s, i]
107
- ), L = f(
109
+ [r, a]
110
+ ), F = g(
108
111
  () => ({
109
- mode: s,
110
- toggleMode: S,
111
- changeMode: v,
112
- prefer: r
112
+ mode: r,
113
+ toggleMode: E,
114
+ changeMode: y,
115
+ prefer: n
113
116
  }),
114
- [s, r, S, v]
117
+ [r, n, E, y]
115
118
  );
116
- return h(() => {
117
- i(B(r));
118
- }, [r, i, k.search]), h(() => {
119
+ return b(() => {
120
+ a(_(n));
121
+ }, [n, a, k.search]), b(() => {
119
122
  const e = new URLSearchParams(k.search).get("theme");
120
- W(e) && sessionStorage.setItem(b, e);
121
- }, [k.search]), h(() => {
122
- d.current || (d.current = document.querySelector('meta[name="theme-color"]'));
123
- const e = p.palette.background.default;
124
- if (d.current)
125
- d.current.setAttribute("content", e);
123
+ Z(e) && sessionStorage.setItem(h, e);
124
+ }, [k.search]), b(() => {
125
+ f.current || (f.current = document.querySelector('meta[name="theme-color"]'));
126
+ const e = T.palette.background.default;
127
+ if (f.current)
128
+ f.current.setAttribute("content", e);
126
129
  else {
127
- const n = document.createElement("meta");
128
- n.name = "theme-color", n.content = e, document.head.appendChild(n), d.current = n;
130
+ const l = document.createElement("meta");
131
+ l.name = "theme-color", l.content = e, document.head.appendChild(l), f.current = l;
129
132
  }
130
- }, [p.palette.background.default]), h(() => {
131
- const e = (n) => {
132
- n.origin === window.origin && n.data.type === "THEME_BUILDER_CONFIG_CHANGED" && w(n.data.payload);
133
+ }, [T.palette.background.default]), b(() => {
134
+ const e = (l) => {
135
+ l.origin === window.origin && l.data.type === "THEME_BUILDER_CONFIG_CHANGED" && w(l.data.payload);
133
136
  };
134
137
  return window.addEventListener("message", e), () => window.removeEventListener("message", e);
135
- }, [w]), /* @__PURE__ */ m(P, { value: L, children: /* @__PURE__ */ m(_, { theme: p, ...o, children: l }) });
138
+ }, [w]), b(() => {
139
+ S && (r === "dark" ? document.documentElement.setAttribute("data-theme", "dark") : document.documentElement.removeAttribute("data-theme"));
140
+ }, [S, r]), /* @__PURE__ */ m(j, { value: F, children: /* @__PURE__ */ m(U, { theme: T, ...o, children: i }) });
136
141
  }
137
- function me({
138
- children: l = null,
142
+ function pe({
143
+ children: i = null,
139
144
  prefer: t = void 0,
140
- enableColorScheme: r = !1,
141
- ...a
145
+ enableColorScheme: n = !1,
146
+ ...s
142
147
  }) {
143
- const { toggleMode: o } = X();
144
- return r || t || !o ? /* @__PURE__ */ m(ee, { prefer: t, ...a, children: l }) : /* @__PURE__ */ m(_, { ...a, children: l });
148
+ const { toggleMode: o } = A();
149
+ return n || t || !o ? /* @__PURE__ */ m(le, { prefer: t, ...s, children: i }) : /* @__PURE__ */ m(U, { ...s, children: i });
145
150
  }
146
151
  export {
147
- P as ColorSchemeContext,
148
- me as default,
149
- X as useColorScheme
152
+ j as ColorSchemeContext,
153
+ pe as default,
154
+ A as useColorScheme
150
155
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/ux",
3
- "version": "3.0.21",
3
+ "version": "3.0.23",
4
4
  "description": "Common used react components for arcblock products",
5
5
  "keywords": [
6
6
  "react",
@@ -60,16 +60,16 @@
60
60
  "react": "^19.0.0",
61
61
  "react-router-dom": "^6.22.3"
62
62
  },
63
- "gitHead": "c14ba0a6dd6fef59a623fd3b0e07855b9dc55076",
63
+ "gitHead": "360a929c8fe8cd2a63b04eda4c5315b096d39473",
64
64
  "dependencies": {
65
- "@arcblock/bridge": "3.0.21",
65
+ "@arcblock/bridge": "3.0.23",
66
66
  "@arcblock/did": "^1.20.15",
67
67
  "@arcblock/did-motif": "^1.1.14",
68
- "@arcblock/icons": "3.0.21",
69
- "@arcblock/nft-display": "3.0.21",
70
- "@arcblock/react-hooks": "3.0.21",
68
+ "@arcblock/icons": "3.0.23",
69
+ "@arcblock/nft-display": "3.0.23",
70
+ "@arcblock/react-hooks": "3.0.23",
71
71
  "@blocklet/js-sdk": "^1.16.45",
72
- "@blocklet/theme": "3.0.21",
72
+ "@blocklet/theme": "3.0.23",
73
73
  "@fontsource/roboto": "~5.1.1",
74
74
  "@fontsource/ubuntu-mono": "^5.2.6",
75
75
  "@iconify-icons/logos": "^1.2.36",
@@ -222,7 +222,6 @@ const Form = styled('form', {
222
222
  font-size: 30px;
223
223
  text-align: center;
224
224
  color: ${(props) => {
225
- // @ts-expect-error
226
225
  return props.theme.typography.color.main;
227
226
  }};
228
227
  }
@@ -239,7 +238,6 @@ const Form = styled('form', {
239
238
  border: none;
240
239
  border-bottom: 1px solid
241
240
  ${(props) => {
242
- // @ts-expect-error
243
241
  return props.theme.typography.color.main;
244
242
  }};
245
243
  font-size: 16px;
@@ -85,7 +85,6 @@ const Container = styled('div', {
85
85
 
86
86
  .footer-item {
87
87
  color: ${(props) => {
88
- // @ts-expect-error
89
88
  return props.theme.palette.text.hint;
90
89
  }};
91
90
  display: flex;
@@ -167,7 +167,6 @@ const Root = styled(Box)`
167
167
  .header-brand-desc {
168
168
  margin-top: 4px;
169
169
  color: ${({ theme }) => {
170
- // @ts-expect-error
171
170
  return theme.palette.text.hint;
172
171
  }};
173
172
  }
@@ -178,7 +178,6 @@ const Root = styled('div')`
178
178
  }
179
179
  .layout-sidebar-group {
180
180
  color: ${(props) => {
181
- // @ts-expect-error
182
181
  return props.theme.palette.text.hint;
183
182
  }};
184
183
  .layout-sidebar-group-title {
@@ -37,7 +37,6 @@ const StyledAppBar = styled(AppBar)`
37
37
  font-size: 24px;
38
38
  font-weight: 800;
39
39
  color: ${(props) => {
40
- // @ts-expect-error
41
40
  return props.theme.typography.color.main;
42
41
  }};
43
42
  text-transform: uppercase;
@@ -48,7 +47,6 @@ const StyledAppBar = styled(AppBar)`
48
47
  font-size: 14px;
49
48
  line-height: 1.71;
50
49
  color: ${(props) => {
51
- // @ts-expect-error
52
50
  return props.theme.typography.color.gray;
53
51
  }};
54
52
  }
@@ -52,7 +52,6 @@ export default function Sidebar({
52
52
  <ImageIcon
53
53
  name={images[name]}
54
54
  size={36}
55
- // @ts-expect-error
56
55
  color={selected ? '#00c2c4' : theme.typography.color.main}
57
56
  prefix={prefix}
58
57
  showBadge={showBadge}
@@ -106,7 +106,6 @@ export default function SessionUserSwitch({
106
106
  return (
107
107
  <SessionUserItem
108
108
  sessionItem={currentSession}
109
- // @ts-expect-error
110
109
  statusContent={<Icon icon={SwapHorizRoundedIcon} color={palette.text.hint} />}
111
110
  sx={{
112
111
  borderRadius: 1,
@@ -11,7 +11,8 @@ import {
11
11
  } from '@mui/material';
12
12
  import { deepmerge } from '@mui/utils';
13
13
  import set from 'lodash/set';
14
- import { useDebounceFn } from 'ahooks';
14
+ import isUndefined from 'lodash/isUndefined';
15
+ import { useCreation, useDebounceFn } from 'ahooks';
15
16
  import {
16
17
  BLOCKLET_THEME_PREFER_KEY,
17
18
  getDefaultThemePrefer,
@@ -128,6 +129,9 @@ interface BaseThemeProviderProps {
128
129
  darkSchemeClass?: string;
129
130
  }
130
131
 
132
+ let injectedCssBaseline = false;
133
+ const injectedDarkSchemeStylesMap: Record<string, boolean> = {};
134
+
131
135
  /** 快速配置 MUI 主题 */
132
136
  function BaseThemeProvider({
133
137
  children = null,
@@ -146,12 +150,26 @@ function BaseThemeProvider({
146
150
  return createTheme(theme);
147
151
  }, [theme]);
148
152
 
153
+ const cssBaseline = useCreation(() => {
154
+ if (injectedCssBaseline) return null;
155
+
156
+ injectedCssBaseline = true;
157
+ return <CssBaseline />;
158
+ }, []);
159
+
160
+ const darkSchemeStyles = useCreation(() => {
161
+ if (injectedDarkSchemeStylesMap[darkSchemeClass]) return null;
162
+
163
+ injectedDarkSchemeStylesMap[darkSchemeClass] = true;
164
+ return <DarkSchemeStyles className={darkSchemeClass} />;
165
+ }, [darkSchemeClass]);
166
+
149
167
  return (
150
168
  // injectFirst 会影响 makeStyles 自定义样式和 mui styles 覆盖问题
151
169
  <StyledEngineProvider injectFirst={injectFirst}>
152
170
  <MuiThemeProvider theme={_theme}>
153
- <CssBaseline />
154
- <DarkSchemeStyles className={darkSchemeClass} />
171
+ {cssBaseline}
172
+ {darkSchemeStyles}
155
173
  {children}
156
174
  </MuiThemeProvider>
157
175
  </StyledEngineProvider>
@@ -171,11 +189,13 @@ function ColorSchemeProvider({
171
189
  disableBlockletTheme = false,
172
190
  ...rest
173
191
  }: ThemeProviderProps) {
192
+ const parentColorScheme = useColorScheme();
174
193
  const [mode, setMode] = useState<PaletteMode>(() => resolveMode(prefer));
175
194
  const [themeBuilderConfig, setThemeBuilderConfig] = useState<BlockletThemeMeta | null>(null);
176
195
  const parentTheme = useTheme();
177
196
  const location = useLocationState();
178
197
  const metaThemeColorRef = useRef<HTMLMetaElement | null>(null);
198
+ const isTopColorScheme = isUndefined(parentColorScheme.toggleMode);
179
199
 
180
200
  // 使用防抖函数包装 setThemeBuilderConfig,避免过于频繁的主题修改
181
201
  const { run: debouncedSetThemeBuilderConfig } = useDebounceFn(
@@ -301,6 +321,17 @@ function ColorSchemeProvider({
301
321
  return () => window.removeEventListener('message', handleMessage);
302
322
  }, [debouncedSetThemeBuilderConfig]);
303
323
 
324
+ // 修改 document[data-theme] 属性
325
+ useEffect(() => {
326
+ if (isTopColorScheme) {
327
+ if (mode === 'dark') {
328
+ document.documentElement.setAttribute('data-theme', 'dark');
329
+ } else {
330
+ document.documentElement.removeAttribute('data-theme');
331
+ }
332
+ }
333
+ }, [isTopColorScheme, mode]);
334
+
304
335
  return (
305
336
  <ColorSchemeContext value={colorSchemeValue}>
306
337
  <BaseThemeProvider theme={theme} {...rest}>
@@ -17,7 +17,6 @@ function withTheme<P extends object>(
17
17
  // @ts-expect-error
18
18
  const theme = createTheme({ mode, pageWidth, palette, typography });
19
19
 
20
- // @ts-expect-error
21
20
  const color = theme.typography.color.main;
22
21
  const globalStyles = css`
23
22
  font-family: ${theme.typography.fontFamily};