@arcblock/ux 2.12.72 → 2.12.73
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.
@@ -13,12 +13,13 @@ export interface ConfigProviderProps extends Omit<LocaleProviderProps, 'translat
|
|
13
13
|
children: ReactNode;
|
14
14
|
prefer?: ThemeMode;
|
15
15
|
theme?: ThemeOptions | Record<ThemeMode, ThemeOptions>;
|
16
|
+
disableBlockletTheme?: boolean;
|
16
17
|
translations?: Record<string, any>;
|
17
18
|
}
|
18
19
|
/**
|
19
20
|
* 集中化配置
|
20
21
|
*/
|
21
|
-
export declare function ConfigProvider({ children, prefer, theme: themeOptions, injectFirst, locale, fallbackLocale, translations, languages, onLoadingTranslation, }: ConfigProviderProps): import("react/jsx-runtime").JSX.Element;
|
22
|
+
export declare function ConfigProvider({ children, prefer, theme: themeOptions, disableBlockletTheme, injectFirst, locale, fallbackLocale, translations, languages, onLoadingTranslation, }: ConfigProviderProps): import("react/jsx-runtime").JSX.Element;
|
22
23
|
export declare namespace ConfigProvider {
|
23
24
|
var useConfig: typeof import("./config-provider").useConfig;
|
24
25
|
}
|
@@ -19,6 +19,7 @@ export function ConfigProvider({
|
|
19
19
|
// theme config
|
20
20
|
prefer,
|
21
21
|
theme: themeOptions,
|
22
|
+
disableBlockletTheme = false,
|
22
23
|
injectFirst,
|
23
24
|
// locale config
|
24
25
|
locale,
|
@@ -65,8 +66,11 @@ export function ConfigProvider({
|
|
65
66
|
return result;
|
66
67
|
}, [mode, themeOptions]);
|
67
68
|
const theme = useMemo(() => {
|
68
|
-
return createTheme(
|
69
|
-
|
69
|
+
return createTheme({
|
70
|
+
..._themeOptions,
|
71
|
+
disableBlockletTheme
|
72
|
+
});
|
73
|
+
}, [_themeOptions, disableBlockletTheme]);
|
70
74
|
const toggleMode = useCallback(() => {
|
71
75
|
const newMode = mode === 'light' ? 'dark' : 'light';
|
72
76
|
setMode(newMode);
|
package/lib/Theme/theme.d.ts
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
import { Components, type ThemeOptions } from '@mui/material/styles';
|
2
2
|
import { deepmerge } from '@mui/utils';
|
3
3
|
import type { Typography } from '@mui/material/styles/createTypography';
|
4
|
-
import '@fontsource/roboto/400';
|
5
|
-
import '@fontsource/roboto/500';
|
6
|
-
import '@fontsource/roboto/700';
|
7
4
|
import { ThemeMode } from '../type';
|
5
|
+
import '@fontsource/roboto/latin-400.css';
|
6
|
+
import '@fontsource/roboto/latin-500.css';
|
7
|
+
import '@fontsource/roboto/latin-700.css';
|
8
|
+
import '@fontsource/roboto/latin-ext-400.css';
|
9
|
+
import '@fontsource/roboto/latin-ext-500.css';
|
10
|
+
import '@fontsource/roboto/latin-ext-700.css';
|
8
11
|
declare module '@mui/material/styles' {
|
9
12
|
interface Theme {
|
10
13
|
mode?: ThemeMode;
|
@@ -42,6 +45,10 @@ export declare function collectFontFamilies(obj?: {
|
|
42
45
|
}, fontSet?: Set<string>): Set<string>;
|
43
46
|
export declare function loadFonts(fonts: string[]): Promise<boolean>;
|
44
47
|
export declare function createDefaultThemeOptions(mode?: ThemeMode): ThemeOptions;
|
45
|
-
export declare const create: ({ mode, pageWidth, overrides, palette, components, ...rest }?: ThemeOptions
|
46
|
-
|
48
|
+
export declare const create: ({ disableBlockletTheme, mode, pageWidth, overrides, palette, components, ...rest }?: ThemeOptions & {
|
49
|
+
disableBlockletTheme?: boolean;
|
50
|
+
}) => import("@mui/material/styles").Theme;
|
51
|
+
export declare const createTheme: ({ disableBlockletTheme, mode, pageWidth, overrides, palette, components, ...rest }?: ThemeOptions & {
|
52
|
+
disableBlockletTheme?: boolean;
|
53
|
+
}) => import("@mui/material/styles").Theme;
|
47
54
|
export { deepmerge };
|
package/lib/Theme/theme.js
CHANGED
@@ -3,16 +3,17 @@
|
|
3
3
|
import { createTheme as _createTheme, responsiveFontSizes } from '@mui/material/styles';
|
4
4
|
import { deepmerge } from '@mui/utils';
|
5
5
|
import webfontloader from 'webfontloader';
|
6
|
-
// 为了避免加载全量的字体导致打包后体积太大,目前只选择了 MUI 默认的 Roboto 字体
|
7
|
-
// eslint-disable-next-line import/no-unresolved
|
8
|
-
import '@fontsource/roboto/400';
|
9
|
-
// eslint-disable-next-line import/no-unresolved
|
10
|
-
import '@fontsource/roboto/500';
|
11
|
-
// eslint-disable-next-line import/no-unresolved
|
12
|
-
import '@fontsource/roboto/700';
|
13
6
|
import colors from '../Colors';
|
14
7
|
import { cleanedObj } from '../Util';
|
15
8
|
|
9
|
+
// 默认只加载最基本的 roboto latin 字体
|
10
|
+
import '@fontsource/roboto/latin-400.css';
|
11
|
+
import '@fontsource/roboto/latin-500.css';
|
12
|
+
import '@fontsource/roboto/latin-700.css';
|
13
|
+
import '@fontsource/roboto/latin-ext-400.css';
|
14
|
+
import '@fontsource/roboto/latin-ext-500.css';
|
15
|
+
import '@fontsource/roboto/latin-ext-700.css';
|
16
|
+
|
16
17
|
// 扩展 Theme
|
17
18
|
|
18
19
|
// 扩展 TypographyOptions
|
@@ -39,7 +40,8 @@ export function collectFontFamilies(obj, fontSet = new Set()) {
|
|
39
40
|
}
|
40
41
|
|
41
42
|
// 动态加载字体
|
42
|
-
const
|
43
|
+
const defaultFonts = ['Roboto', 'Helvetica', 'Arial', 'sans-serif']; // 后三者是系统字体,无需动态加载
|
44
|
+
const prevFonts = new Set(defaultFonts.concat('inherit')); // inherit 属于 MUI 特殊值,无需动态加载
|
43
45
|
export function loadFonts(fonts) {
|
44
46
|
// 过滤出未加载的字体
|
45
47
|
const unloadedFonts = fonts.filter(font => !prevFonts.has(font));
|
@@ -51,6 +53,10 @@ export function loadFonts(fonts) {
|
|
51
53
|
|
52
54
|
// record
|
53
55
|
unloadedFonts.forEach(font => prevFonts.add(font));
|
56
|
+
|
57
|
+
// support font-display: swap
|
58
|
+
const lastFontIndex = unloadedFonts.length - 1;
|
59
|
+
unloadedFonts[lastFontIndex] = `${unloadedFonts[lastFontIndex]}&display=swap`;
|
54
60
|
return new Promise(resolve => {
|
55
61
|
webfontloader.load({
|
56
62
|
google: {
|
@@ -78,6 +84,7 @@ export function createDefaultThemeOptions(mode = 'light') {
|
|
78
84
|
}
|
79
85
|
},
|
80
86
|
typography: {
|
87
|
+
fontFamily: defaultFonts.join(','),
|
81
88
|
useNextVariants: true,
|
82
89
|
color: {
|
83
90
|
// 此处 #222222 必须硬编码, layout/sidebar.js -> Icon/image 加载图片时 color 会影响加载路径
|
@@ -153,6 +160,7 @@ export function createDefaultThemeOptions(mode = 'light') {
|
|
153
160
|
|
154
161
|
// https://material-ui.com/customization/default-theme/
|
155
162
|
export const create = ({
|
163
|
+
disableBlockletTheme = false,
|
156
164
|
mode = 'light',
|
157
165
|
pageWidth = 'md',
|
158
166
|
overrides,
|
@@ -200,10 +208,14 @@ export const create = ({
|
|
200
208
|
};
|
201
209
|
// Blocklet Server 后台配置的全局主题
|
202
210
|
const blockletThemeOptions = window.blocklet?.theme?.[mode] ?? {};
|
203
|
-
//
|
211
|
+
// UX Theme 默认配置
|
204
212
|
const defaultThemeOptions = createDefaultThemeOptions(mode);
|
205
|
-
//
|
206
|
-
|
213
|
+
// 合并配置
|
214
|
+
let mergedThemeOptions = defaultThemeOptions;
|
215
|
+
if (!disableBlockletTheme) {
|
216
|
+
mergedThemeOptions = deepmerge(defaultThemeOptions, cleanedObj(blockletThemeOptions));
|
217
|
+
}
|
218
|
+
mergedThemeOptions = deepmerge(mergedThemeOptions, cleanedObj(userThemeOptions));
|
207
219
|
const theme = _createTheme(mergedThemeOptions);
|
208
220
|
|
209
221
|
// 异步加载字体
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arcblock/ux",
|
3
|
-
"version": "2.12.
|
3
|
+
"version": "2.12.73",
|
4
4
|
"description": "Common used react components for arcblock products",
|
5
5
|
"keywords": [
|
6
6
|
"react",
|
@@ -70,14 +70,14 @@
|
|
70
70
|
"react": ">=18.2.0",
|
71
71
|
"react-router-dom": ">=6.22.3"
|
72
72
|
},
|
73
|
-
"gitHead": "
|
73
|
+
"gitHead": "74e3edd3e04e1c18ac20951cfad0fa06e0743531",
|
74
74
|
"dependencies": {
|
75
75
|
"@arcblock/did-motif": "^1.1.13",
|
76
|
-
"@arcblock/icons": "^2.12.
|
77
|
-
"@arcblock/nft-display": "^2.12.
|
78
|
-
"@arcblock/react-hooks": "^2.12.
|
76
|
+
"@arcblock/icons": "^2.12.73",
|
77
|
+
"@arcblock/nft-display": "^2.12.73",
|
78
|
+
"@arcblock/react-hooks": "^2.12.73",
|
79
79
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
80
|
-
"@fontsource/roboto": "
|
80
|
+
"@fontsource/roboto": "~5.1.1",
|
81
81
|
"@fontsource/ubuntu-mono": "^5.0.18",
|
82
82
|
"@iconify-icons/logos": "^1.2.36",
|
83
83
|
"@iconify-icons/material-symbols": "^1.2.58",
|
@@ -29,6 +29,7 @@ export interface ConfigProviderProps
|
|
29
29
|
children: ReactNode;
|
30
30
|
prefer?: ThemeMode;
|
31
31
|
theme?: ThemeOptions | Record<ThemeMode, ThemeOptions>;
|
32
|
+
disableBlockletTheme?: boolean;
|
32
33
|
translations?: Record<string, any>;
|
33
34
|
}
|
34
35
|
|
@@ -40,6 +41,7 @@ export function ConfigProvider({
|
|
40
41
|
// theme config
|
41
42
|
prefer,
|
42
43
|
theme: themeOptions,
|
44
|
+
disableBlockletTheme = false,
|
43
45
|
injectFirst,
|
44
46
|
// locale config
|
45
47
|
locale,
|
@@ -87,8 +89,8 @@ export function ConfigProvider({
|
|
87
89
|
}, [mode, themeOptions]);
|
88
90
|
|
89
91
|
const theme = useMemo(() => {
|
90
|
-
return createTheme(_themeOptions);
|
91
|
-
}, [_themeOptions]);
|
92
|
+
return createTheme({ ..._themeOptions, disableBlockletTheme });
|
93
|
+
}, [_themeOptions, disableBlockletTheme]);
|
92
94
|
|
93
95
|
const toggleMode = useCallback(() => {
|
94
96
|
const newMode = mode === 'light' ? 'dark' : 'light';
|
package/src/Theme/theme.ts
CHANGED
@@ -4,18 +4,19 @@ import { createTheme as _createTheme, Components, responsiveFontSizes, type Them
|
|
4
4
|
import { deepmerge } from '@mui/utils';
|
5
5
|
import type { Typography } from '@mui/material/styles/createTypography';
|
6
6
|
import webfontloader from 'webfontloader';
|
7
|
-
// 为了避免加载全量的字体导致打包后体积太大,目前只选择了 MUI 默认的 Roboto 字体
|
8
|
-
// eslint-disable-next-line import/no-unresolved
|
9
|
-
import '@fontsource/roboto/400';
|
10
|
-
// eslint-disable-next-line import/no-unresolved
|
11
|
-
import '@fontsource/roboto/500';
|
12
|
-
// eslint-disable-next-line import/no-unresolved
|
13
|
-
import '@fontsource/roboto/700';
|
14
7
|
|
15
8
|
import colors from '../Colors';
|
16
9
|
import { ThemeMode } from '../type';
|
17
10
|
import { cleanedObj } from '../Util';
|
18
11
|
|
12
|
+
// 默认只加载最基本的 roboto latin 字体
|
13
|
+
import '@fontsource/roboto/latin-400.css';
|
14
|
+
import '@fontsource/roboto/latin-500.css';
|
15
|
+
import '@fontsource/roboto/latin-700.css';
|
16
|
+
import '@fontsource/roboto/latin-ext-400.css';
|
17
|
+
import '@fontsource/roboto/latin-ext-500.css';
|
18
|
+
import '@fontsource/roboto/latin-ext-700.css';
|
19
|
+
|
19
20
|
// 扩展 Theme
|
20
21
|
declare module '@mui/material/styles' {
|
21
22
|
interface Theme {
|
@@ -77,7 +78,8 @@ export function collectFontFamilies(obj?: { fontFamily?: string }, fontSet: Set<
|
|
77
78
|
}
|
78
79
|
|
79
80
|
// 动态加载字体
|
80
|
-
const
|
81
|
+
const defaultFonts = ['Roboto', 'Helvetica', 'Arial', 'sans-serif']; // 后三者是系统字体,无需动态加载
|
82
|
+
const prevFonts = new Set<string>(defaultFonts.concat('inherit')); // inherit 属于 MUI 特殊值,无需动态加载
|
81
83
|
export function loadFonts(fonts: string[]) {
|
82
84
|
// 过滤出未加载的字体
|
83
85
|
const unloadedFonts = fonts.filter((font) => !prevFonts.has(font));
|
@@ -90,6 +92,10 @@ export function loadFonts(fonts: string[]) {
|
|
90
92
|
// record
|
91
93
|
unloadedFonts.forEach((font) => prevFonts.add(font));
|
92
94
|
|
95
|
+
// support font-display: swap
|
96
|
+
const lastFontIndex = unloadedFonts.length - 1;
|
97
|
+
unloadedFonts[lastFontIndex] = `${unloadedFonts[lastFontIndex]}&display=swap`;
|
98
|
+
|
93
99
|
return new Promise<boolean>((resolve) => {
|
94
100
|
webfontloader.load({
|
95
101
|
google: {
|
@@ -117,6 +123,7 @@ export function createDefaultThemeOptions(mode: ThemeMode = 'light'): ThemeOptio
|
|
117
123
|
},
|
118
124
|
},
|
119
125
|
typography: {
|
126
|
+
fontFamily: defaultFonts.join(','),
|
120
127
|
useNextVariants: true,
|
121
128
|
color: {
|
122
129
|
// 此处 #222222 必须硬编码, layout/sidebar.js -> Icon/image 加载图片时 color 会影响加载路径
|
@@ -193,6 +200,7 @@ export function createDefaultThemeOptions(mode: ThemeMode = 'light'): ThemeOptio
|
|
193
200
|
|
194
201
|
// https://material-ui.com/customization/default-theme/
|
195
202
|
export const create = ({
|
203
|
+
disableBlockletTheme = false,
|
196
204
|
mode = 'light',
|
197
205
|
pageWidth = 'md',
|
198
206
|
overrides,
|
@@ -200,7 +208,7 @@ export const create = ({
|
|
200
208
|
palette,
|
201
209
|
components,
|
202
210
|
...rest
|
203
|
-
}: ThemeOptions = {}) => {
|
211
|
+
}: ThemeOptions & { disableBlockletTheme?: boolean } = {}) => {
|
204
212
|
const userThemeOptions: ThemeOptions = {
|
205
213
|
themeName: 'ArcBlock',
|
206
214
|
palette: {
|
@@ -240,14 +248,14 @@ export const create = ({
|
|
240
248
|
};
|
241
249
|
// Blocklet Server 后台配置的全局主题
|
242
250
|
const blockletThemeOptions = window.blocklet?.theme?.[mode] ?? {};
|
243
|
-
//
|
251
|
+
// UX Theme 默认配置
|
244
252
|
const defaultThemeOptions = createDefaultThemeOptions(mode);
|
245
|
-
//
|
246
|
-
|
247
|
-
|
248
|
-
cleanedObj(
|
249
|
-
|
250
|
-
|
253
|
+
// 合并配置
|
254
|
+
let mergedThemeOptions = defaultThemeOptions;
|
255
|
+
if (!disableBlockletTheme) {
|
256
|
+
mergedThemeOptions = deepmerge(defaultThemeOptions, cleanedObj(blockletThemeOptions));
|
257
|
+
}
|
258
|
+
mergedThemeOptions = deepmerge(mergedThemeOptions, cleanedObj(userThemeOptions));
|
251
259
|
const theme = _createTheme(mergedThemeOptions);
|
252
260
|
|
253
261
|
// 异步加载字体
|