@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.
- package/lib/Theme/theme-provider.js +88 -83
- 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 +34 -3
- 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 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
|
15
|
-
function
|
16
|
-
const t =
|
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
|
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
|
-
|
21
|
+
z,
|
21
22
|
{
|
22
23
|
styles: {
|
23
24
|
// Chrome, Safari, Edge
|
24
25
|
"@supports selector(::-webkit-scrollbar)": {
|
25
|
-
[
|
26
|
+
[u]: {
|
26
27
|
width: "12px",
|
27
28
|
height: "12px"
|
28
29
|
},
|
29
|
-
[
|
30
|
-
background:
|
30
|
+
[r]: {
|
31
|
+
background: n
|
31
32
|
},
|
32
|
-
[
|
33
|
-
background:
|
33
|
+
[a]: {
|
34
|
+
background: s,
|
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: `${
|
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
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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 =
|
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(
|
67
|
-
|
68
|
-
|
69
|
-
|
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
|
74
|
-
children:
|
76
|
+
function le({
|
77
|
+
children: i = null,
|
75
78
|
theme: t = void 0,
|
76
|
-
prefer:
|
77
|
-
disableBlockletTheme:
|
79
|
+
prefer: n = void 0,
|
80
|
+
disableBlockletTheme: s = !1,
|
78
81
|
...o
|
79
82
|
}) {
|
80
|
-
const [
|
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
|
-
|
85
|
+
d(e);
|
83
86
|
},
|
84
87
|
{
|
85
88
|
wait: 200
|
86
89
|
}
|
87
|
-
),
|
90
|
+
), v = g(() => {
|
88
91
|
let e = {};
|
89
92
|
if (t) {
|
90
|
-
const
|
93
|
+
const G = te(r);
|
91
94
|
if (typeof t == "function") {
|
92
|
-
const
|
93
|
-
|
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
|
98
|
-
return c && (
|
99
|
-
}, [
|
100
|
-
const e =
|
101
|
-
|
102
|
-
}, [
|
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
|
-
|
107
|
+
r !== e && (a(e), sessionStorage.removeItem(h), localStorage.setItem(h, e));
|
105
108
|
},
|
106
|
-
[
|
107
|
-
),
|
109
|
+
[r, a]
|
110
|
+
), F = g(
|
108
111
|
() => ({
|
109
|
-
mode:
|
110
|
-
toggleMode:
|
111
|
-
changeMode:
|
112
|
-
prefer:
|
112
|
+
mode: r,
|
113
|
+
toggleMode: E,
|
114
|
+
changeMode: y,
|
115
|
+
prefer: n
|
113
116
|
}),
|
114
|
-
[
|
117
|
+
[r, n, E, y]
|
115
118
|
);
|
116
|
-
return
|
117
|
-
|
118
|
-
}, [
|
119
|
+
return b(() => {
|
120
|
+
a(_(n));
|
121
|
+
}, [n, a, k.search]), b(() => {
|
119
122
|
const e = new URLSearchParams(k.search).get("theme");
|
120
|
-
|
121
|
-
}, [k.search]),
|
122
|
-
|
123
|
-
const e =
|
124
|
-
if (
|
125
|
-
|
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
|
128
|
-
|
130
|
+
const l = document.createElement("meta");
|
131
|
+
l.name = "theme-color", l.content = e, document.head.appendChild(l), f.current = l;
|
129
132
|
}
|
130
|
-
}, [
|
131
|
-
const e = (
|
132
|
-
|
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]),
|
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
|
138
|
-
children:
|
142
|
+
function pe({
|
143
|
+
children: i = null,
|
139
144
|
prefer: t = void 0,
|
140
|
-
enableColorScheme:
|
141
|
-
...
|
145
|
+
enableColorScheme: n = !1,
|
146
|
+
...s
|
142
147
|
}) {
|
143
|
-
const { toggleMode: o } =
|
144
|
-
return
|
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
|
-
|
148
|
-
|
149
|
-
|
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.
|
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": "
|
63
|
+
"gitHead": "360a929c8fe8cd2a63b04eda4c5315b096d39473",
|
64
64
|
"dependencies": {
|
65
|
-
"@arcblock/bridge": "3.0.
|
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.
|
69
|
-
"@arcblock/nft-display": "3.0.
|
70
|
-
"@arcblock/react-hooks": "3.0.
|
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.
|
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;
|
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,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
|
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
|
-
|
154
|
-
|
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}>
|
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};
|