@arcblock/ux 3.0.21 → 3.0.22

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 F } from "react/jsx-runtime";
2
+ import { createContext as G, use as H, useState as y, useRef as I, useMemo as f, useCallback as $, useEffect as b } from "react";
3
+ import { useTheme as _, StyledEngineProvider as N, ThemeProvider as O, CssBaseline as K, GlobalStyles as V } from "@mui/material";
4
+ import { deepmerge as W } from "@mui/utils";
5
+ import B from "lodash/set";
6
+ import q from "lodash/isUndefined";
7
+ import { useDebounceFn as z } from "ahooks";
8
+ import { getBlockletThemeOptions as Y, BLOCKLET_THEME_PREFER_KEY as h, isValidThemeMode as J, getDefaultThemePrefer as M } from "@blocklet/theme";
9
+ import { useLocationState as Q } from "../hooks/use-location-state.js";
10
+ import { createTheme as C, lazyCreateDefaultTheme as X, isUxTheme as Z, isTheme as ee } from "./theme.js";
11
+ const te = C(), L = G({});
12
+ function R() {
13
+ return H(L);
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 P = (l) => l ? l === "system" ? M({ theme: { prefer: "system" } }) : l : M();
16
+ function oe({ className: l = void 0 }) {
17
+ const t = _();
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", a = t.palette.grey[300], o = (l || "").trim().split(/\s+/).filter(Boolean).map((u) => u.startsWith(".") ? u : `.${u}`).join(" "), g = o ? `${o}::-webkit-scrollbar, ${o} *::-webkit-scrollbar` : "*::-webkit-scrollbar", r = o ? `${o}::-webkit-scrollbar-track, ${o} *::-webkit-scrollbar-track` : "*::-webkit-scrollbar-track", i = o ? `${o}::-webkit-scrollbar-thumb, ${o} *::-webkit-scrollbar-thumb` : "*::-webkit-scrollbar-thumb", c = o ? `${o}, ${o} *` : "*";
19
20
  return /* @__PURE__ */ m(
20
- U,
21
+ V,
21
22
  {
22
23
  styles: {
23
24
  // Chrome, Safari, Edge
24
25
  "@supports selector(::-webkit-scrollbar)": {
25
- [s]: {
26
+ [g]: {
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
+ [i]: {
33
34
  background: a,
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: `${a} ${n}`
49
50
  }
50
51
  }
51
52
  }
@@ -54,97 +55,99 @@ function Z({ className: l = void 0 }) {
54
55
  }
55
56
  return null;
56
57
  }
57
- function _({
58
+ function D({
58
59
  children: l = null,
59
- theme: t = Q,
60
- injectFirst: r = !0,
60
+ theme: t = te,
61
+ injectFirst: n = !0,
61
62
  darkSchemeClass: a = ""
62
63
  }) {
63
- const o = f(() => typeof t == "function" || J(t) ? t : T(t), [t]);
64
+ const o = f(() => typeof t == "function" || ee(t) ? t : C(t), [t]);
64
65
  return (
65
66
  // 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 }),
67
+ /* @__PURE__ */ m(N, { injectFirst: n, children: /* @__PURE__ */ F(O, { theme: o, children: [
68
+ /* @__PURE__ */ m(K, {}),
69
+ /* @__PURE__ */ m(oe, { className: a }),
69
70
  l
70
71
  ] }) })
71
72
  );
72
73
  }
73
- function ee({
74
+ function re({
74
75
  children: l = null,
75
76
  theme: t = void 0,
76
- prefer: r = void 0,
77
+ prefer: n = void 0,
77
78
  disableBlockletTheme: a = !1,
78
79
  ...o
79
80
  }) {
80
- const [s, i] = E(() => B(r)), [c, g] = E(null), u = M(), k = q(), d = H(null), { run: w } = K(
81
+ const g = R(), [r, i] = y(() => P(n)), [c, u] = y(null), k = _(), p = Q(), d = I(null), w = q(g.toggleMode), { run: S } = z(
81
82
  (e) => {
82
- g(e);
83
+ u(e);
83
84
  },
84
85
  {
85
86
  wait: 200
86
87
  }
87
- ), C = f(() => {
88
+ ), v = f(() => {
88
89
  let e = {};
89
90
  if (t) {
90
- const R = z(s);
91
+ const U = X(r);
91
92
  if (typeof t == "function") {
92
- const D = R();
93
- Y(u) ? e = { ...t(u, { mode: s }) } : e = { ...t(D, { mode: s }) };
93
+ const j = U();
94
+ Z(k) ? e = { ...t(k, { mode: r }) } : e = { ...t(j, { mode: r }) };
94
95
  } else
95
96
  e = { ...t };
96
97
  }
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(
98
+ let s = r;
99
+ return c && (s = c.mode || "light", e = W(e, Y(s, c))), B(e, "palette.mode", s), B(e, "mode", s), e;
100
+ }, [r, t, k, c]), T = f(() => C({ ...v, disableBlockletTheme: !!c || a }), [v, a, c]), E = $(() => {
101
+ const e = r === "light" ? "dark" : "light";
102
+ i(e), sessionStorage.removeItem(h), localStorage.setItem(h, e);
103
+ }, [r, i]), x = $(
103
104
  (e) => {
104
- s !== e && (i(e), sessionStorage.removeItem(b), localStorage.setItem(b, e));
105
+ r !== e && (i(e), sessionStorage.removeItem(h), localStorage.setItem(h, e));
105
106
  },
106
- [s, i]
107
- ), L = f(
107
+ [r, i]
108
+ ), A = f(
108
109
  () => ({
109
- mode: s,
110
- toggleMode: S,
111
- changeMode: v,
112
- prefer: r
110
+ mode: r,
111
+ toggleMode: E,
112
+ changeMode: x,
113
+ prefer: n
113
114
  }),
114
- [s, r, S, v]
115
+ [r, n, E, x]
115
116
  );
116
- return h(() => {
117
- i(B(r));
118
- }, [r, i, k.search]), h(() => {
119
- const e = new URLSearchParams(k.search).get("theme");
120
- W(e) && sessionStorage.setItem(b, e);
121
- }, [k.search]), h(() => {
117
+ return b(() => {
118
+ i(P(n));
119
+ }, [n, i, p.search]), b(() => {
120
+ const e = new URLSearchParams(p.search).get("theme");
121
+ J(e) && sessionStorage.setItem(h, e);
122
+ }, [p.search]), b(() => {
122
123
  d.current || (d.current = document.querySelector('meta[name="theme-color"]'));
123
- const e = p.palette.background.default;
124
+ const e = T.palette.background.default;
124
125
  if (d.current)
125
126
  d.current.setAttribute("content", e);
126
127
  else {
127
- const n = document.createElement("meta");
128
- n.name = "theme-color", n.content = e, document.head.appendChild(n), d.current = n;
128
+ const s = document.createElement("meta");
129
+ s.name = "theme-color", s.content = e, document.head.appendChild(s), d.current = s;
129
130
  }
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);
131
+ }, [T.palette.background.default]), b(() => {
132
+ const e = (s) => {
133
+ s.origin === window.origin && s.data.type === "THEME_BUILDER_CONFIG_CHANGED" && S(s.data.payload);
133
134
  };
134
135
  return window.addEventListener("message", e), () => window.removeEventListener("message", e);
135
- }, [w]), /* @__PURE__ */ m(P, { value: L, children: /* @__PURE__ */ m(_, { theme: p, ...o, children: l }) });
136
+ }, [S]), b(() => {
137
+ w && (r === "dark" ? document.documentElement.setAttribute("data-theme", "dark") : document.documentElement.removeAttribute("data-theme"));
138
+ }, [w, r]), /* @__PURE__ */ m(L, { value: A, children: /* @__PURE__ */ m(D, { theme: T, ...o, children: l }) });
136
139
  }
137
- function me({
140
+ function he({
138
141
  children: l = null,
139
142
  prefer: t = void 0,
140
- enableColorScheme: r = !1,
143
+ enableColorScheme: n = !1,
141
144
  ...a
142
145
  }) {
143
- const { toggleMode: o } = X();
144
- return r || t || !o ? /* @__PURE__ */ m(ee, { prefer: t, ...a, children: l }) : /* @__PURE__ */ m(_, { ...a, children: l });
146
+ const { toggleMode: o } = R();
147
+ return n || t || !o ? /* @__PURE__ */ m(re, { prefer: t, ...a, children: l }) : /* @__PURE__ */ m(D, { ...a, children: l });
145
148
  }
146
149
  export {
147
- P as ColorSchemeContext,
148
- me as default,
149
- X as useColorScheme
150
+ L as ColorSchemeContext,
151
+ he as default,
152
+ R as useColorScheme
150
153
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/ux",
3
- "version": "3.0.21",
3
+ "version": "3.0.22",
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": "21018768a5b825c02861281925afb54efdf0aa4c",
64
64
  "dependencies": {
65
- "@arcblock/bridge": "3.0.21",
65
+ "@arcblock/bridge": "3.0.22",
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.22",
69
+ "@arcblock/nft-display": "3.0.22",
70
+ "@arcblock/react-hooks": "3.0.22",
71
71
  "@blocklet/js-sdk": "^1.16.45",
72
- "@blocklet/theme": "3.0.21",
72
+ "@blocklet/theme": "3.0.22",
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,6 +11,7 @@ import {
11
11
  } from '@mui/material';
12
12
  import { deepmerge } from '@mui/utils';
13
13
  import set from 'lodash/set';
14
+ import isUndefined from 'lodash/isUndefined';
14
15
  import { useDebounceFn } from 'ahooks';
15
16
  import {
16
17
  BLOCKLET_THEME_PREFER_KEY,
@@ -171,11 +172,13 @@ function ColorSchemeProvider({
171
172
  disableBlockletTheme = false,
172
173
  ...rest
173
174
  }: ThemeProviderProps) {
175
+ const parentColorScheme = useColorScheme();
174
176
  const [mode, setMode] = useState<PaletteMode>(() => resolveMode(prefer));
175
177
  const [themeBuilderConfig, setThemeBuilderConfig] = useState<BlockletThemeMeta | null>(null);
176
178
  const parentTheme = useTheme();
177
179
  const location = useLocationState();
178
180
  const metaThemeColorRef = useRef<HTMLMetaElement | null>(null);
181
+ const isTopColorScheme = isUndefined(parentColorScheme.toggleMode);
179
182
 
180
183
  // 使用防抖函数包装 setThemeBuilderConfig,避免过于频繁的主题修改
181
184
  const { run: debouncedSetThemeBuilderConfig } = useDebounceFn(
@@ -301,6 +304,17 @@ function ColorSchemeProvider({
301
304
  return () => window.removeEventListener('message', handleMessage);
302
305
  }, [debouncedSetThemeBuilderConfig]);
303
306
 
307
+ // 修改 document[data-theme] 属性
308
+ useEffect(() => {
309
+ if (isTopColorScheme) {
310
+ if (mode === 'dark') {
311
+ document.documentElement.setAttribute('data-theme', 'dark');
312
+ } else {
313
+ document.documentElement.removeAttribute('data-theme');
314
+ }
315
+ }
316
+ }, [isTopColorScheme, mode]);
317
+
304
318
  return (
305
319
  <ColorSchemeContext value={colorSchemeValue}>
306
320
  <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};