@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.
- package/lib/Theme/theme-provider.js +76 -73
- package/package.json +7 -7
- package/src/ContactForm/index.tsx +0 -2
- package/src/Footer/index.tsx +0 -1
- package/src/Header/header.tsx +0 -1
- package/src/Layout/dashboard/sidebar.tsx +0 -1
- package/src/Layout/dashboard-legacy/header.tsx +0 -2
- package/src/Layout/dashboard-legacy/sidebar.tsx +0 -1
- package/src/SessionUser/components/session-user-switch.tsx +0 -1
- package/src/Theme/theme-provider.tsx +14 -0
- package/src/withTheme/index.tsx +0 -1
@@ -1,39 +1,40 @@
|
|
1
|
-
import { jsx as m, jsxs as
|
2
|
-
import { createContext as
|
3
|
-
import { useTheme as
|
4
|
-
import { deepmerge as
|
5
|
-
import
|
6
|
-
import
|
7
|
-
import {
|
8
|
-
import {
|
9
|
-
import {
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
15
|
-
function
|
16
|
-
const t =
|
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
|
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
|
-
|
21
|
+
V,
|
21
22
|
{
|
22
23
|
styles: {
|
23
24
|
// Chrome, Safari, Edge
|
24
25
|
"@supports selector(::-webkit-scrollbar)": {
|
25
|
-
[
|
26
|
+
[g]: {
|
26
27
|
width: "12px",
|
27
28
|
height: "12px"
|
28
29
|
},
|
29
|
-
[
|
30
|
-
background:
|
30
|
+
[r]: {
|
31
|
+
background: n
|
31
32
|
},
|
32
|
-
[
|
33
|
+
[i]: {
|
33
34
|
background: a,
|
34
35
|
borderRadius: "6px",
|
35
36
|
border: "2px solid",
|
36
|
-
borderColor:
|
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
|
-
[
|
47
|
+
[c]: {
|
47
48
|
scrollbarWidth: "auto",
|
48
|
-
scrollbarColor: `${a} ${
|
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 =
|
60
|
-
injectFirst:
|
60
|
+
theme: t = te,
|
61
|
+
injectFirst: n = !0,
|
61
62
|
darkSchemeClass: a = ""
|
62
63
|
}) {
|
63
|
-
const o = f(() => typeof t == "function" ||
|
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(
|
67
|
-
/* @__PURE__ */ m(
|
68
|
-
/* @__PURE__ */ m(
|
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
|
74
|
+
function re({
|
74
75
|
children: l = null,
|
75
76
|
theme: t = void 0,
|
76
|
-
prefer:
|
77
|
+
prefer: n = void 0,
|
77
78
|
disableBlockletTheme: a = !1,
|
78
79
|
...o
|
79
80
|
}) {
|
80
|
-
const [
|
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
|
-
|
83
|
+
u(e);
|
83
84
|
},
|
84
85
|
{
|
85
86
|
wait: 200
|
86
87
|
}
|
87
|
-
),
|
88
|
+
), v = f(() => {
|
88
89
|
let e = {};
|
89
90
|
if (t) {
|
90
|
-
const
|
91
|
+
const U = X(r);
|
91
92
|
if (typeof t == "function") {
|
92
|
-
const
|
93
|
-
|
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
|
98
|
-
return c && (
|
99
|
-
}, [
|
100
|
-
const e =
|
101
|
-
i(e), sessionStorage.removeItem(
|
102
|
-
}, [
|
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
|
-
|
105
|
+
r !== e && (i(e), sessionStorage.removeItem(h), localStorage.setItem(h, e));
|
105
106
|
},
|
106
|
-
[
|
107
|
-
),
|
107
|
+
[r, i]
|
108
|
+
), A = f(
|
108
109
|
() => ({
|
109
|
-
mode:
|
110
|
-
toggleMode:
|
111
|
-
changeMode:
|
112
|
-
prefer:
|
110
|
+
mode: r,
|
111
|
+
toggleMode: E,
|
112
|
+
changeMode: x,
|
113
|
+
prefer: n
|
113
114
|
}),
|
114
|
-
[
|
115
|
+
[r, n, E, x]
|
115
116
|
);
|
116
|
-
return
|
117
|
-
i(
|
118
|
-
}, [
|
119
|
-
const e = new URLSearchParams(
|
120
|
-
|
121
|
-
}, [
|
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 =
|
124
|
+
const e = T.palette.background.default;
|
124
125
|
if (d.current)
|
125
126
|
d.current.setAttribute("content", e);
|
126
127
|
else {
|
127
|
-
const
|
128
|
-
|
128
|
+
const s = document.createElement("meta");
|
129
|
+
s.name = "theme-color", s.content = e, document.head.appendChild(s), d.current = s;
|
129
130
|
}
|
130
|
-
}, [
|
131
|
-
const e = (
|
132
|
-
|
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
|
-
}, [
|
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
|
140
|
+
function he({
|
138
141
|
children: l = null,
|
139
142
|
prefer: t = void 0,
|
140
|
-
enableColorScheme:
|
143
|
+
enableColorScheme: n = !1,
|
141
144
|
...a
|
142
145
|
}) {
|
143
|
-
const { toggleMode: o } =
|
144
|
-
return
|
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
|
-
|
148
|
-
|
149
|
-
|
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.
|
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": "
|
63
|
+
"gitHead": "21018768a5b825c02861281925afb54efdf0aa4c",
|
64
64
|
"dependencies": {
|
65
|
-
"@arcblock/bridge": "3.0.
|
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.
|
69
|
-
"@arcblock/nft-display": "3.0.
|
70
|
-
"@arcblock/react-hooks": "3.0.
|
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.
|
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;
|
package/src/Footer/index.tsx
CHANGED
package/src/Header/header.tsx
CHANGED
@@ -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
|
}
|
@@ -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}>
|
package/src/withTheme/index.tsx
CHANGED
@@ -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};
|