@arcblock/ux 2.13.48 → 2.13.49
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/NavMenu/products.js +5 -5
- package/lib/Theme/theme-provider.js +10 -2
- package/lib/Theme/theme.d.ts +1 -0
- package/lib/Theme/theme.js +16 -6
- package/package.json +6 -6
- package/src/NavMenu/products.tsx +5 -8
- package/src/Theme/theme-provider.tsx +11 -1
- package/src/Theme/theme.ts +18 -7
package/lib/NavMenu/products.js
CHANGED
@@ -1374,7 +1374,7 @@ const translations = {
|
|
1374
1374
|
blockletLauncher: {
|
1375
1375
|
description: 'One-click app launcher'
|
1376
1376
|
},
|
1377
|
-
|
1377
|
+
aiKit: {
|
1378
1378
|
description: 'Boost apps with AI'
|
1379
1379
|
},
|
1380
1380
|
paymentKit: {
|
@@ -1444,7 +1444,7 @@ const translations = {
|
|
1444
1444
|
blockletLauncher: {
|
1445
1445
|
description: '一键启动应用程序'
|
1446
1446
|
},
|
1447
|
-
|
1447
|
+
aiKit: {
|
1448
1448
|
description: 'AI 赋能应用'
|
1449
1449
|
},
|
1450
1450
|
paymentKit: {
|
@@ -1599,12 +1599,12 @@ export default function Products({
|
|
1599
1599
|
icon: /*#__PURE__*/_jsx(BlockletLauncherSvg, {})
|
1600
1600
|
}, {
|
1601
1601
|
label: /*#__PURE__*/_jsx(Link, {
|
1602
|
-
to: `https://www.
|
1602
|
+
to: `https://www.aikit.rocks/${locale}`,
|
1603
1603
|
target: "_blank",
|
1604
1604
|
rel: "noreferrer noopener",
|
1605
|
-
children: "
|
1605
|
+
children: "AI Kit"
|
1606
1606
|
}),
|
1607
|
-
description: t('products.
|
1607
|
+
description: t('products.aiKit.description'),
|
1608
1608
|
icon: /*#__PURE__*/_jsx(AIKitSvg, {})
|
1609
1609
|
}, {
|
1610
1610
|
label: /*#__PURE__*/_jsx(Link, {
|
@@ -8,7 +8,7 @@ import CssBaseline from '@mui/material/CssBaseline';
|
|
8
8
|
import set from 'lodash/set';
|
9
9
|
import { BLOCKLET_THEME_PREFER_KEY } from '@blocklet/theme';
|
10
10
|
import useLocationState from '../hooks/use-location-state';
|
11
|
-
import { createTheme, getDefaultThemePrefer, isTheme, isUxTheme, lazyCreateDefaultTheme } from './theme';
|
11
|
+
import { createTheme, getDefaultThemePrefer, isTheme, isUxTheme, isValidThemeMode, lazyCreateDefaultTheme } from './theme';
|
12
12
|
const defaultTheme = createTheme();
|
13
13
|
|
14
14
|
/** 颜色模式上下文类型 */
|
@@ -180,10 +180,18 @@ function ColorSchemeProvider({
|
|
180
180
|
prefer
|
181
181
|
}), [mode, prefer, toggleMode, changeMode]);
|
182
182
|
|
183
|
-
//
|
183
|
+
// 相应 prefer 或 urlTheme 的改变
|
184
184
|
useEffect(() => {
|
185
185
|
setMode(resolveMode(prefer));
|
186
186
|
}, [prefer, setMode, location.search]);
|
187
|
+
|
188
|
+
// 会话缓存 urlTheme 便于 App Launching 阶段临时统一 theme mode
|
189
|
+
useEffect(() => {
|
190
|
+
const urlTheme = new URLSearchParams(location.search).get('theme');
|
191
|
+
if (isValidThemeMode(urlTheme)) {
|
192
|
+
sessionStorage.setItem(BLOCKLET_THEME_PREFER_KEY, urlTheme);
|
193
|
+
}
|
194
|
+
}, [location.search]);
|
187
195
|
return /*#__PURE__*/_jsx(ColorSchemeContext.Provider, {
|
188
196
|
value: colorSchemeValue,
|
189
197
|
children: /*#__PURE__*/_jsx(BaseThemeProvider, {
|
package/lib/Theme/theme.d.ts
CHANGED
@@ -15,6 +15,7 @@ export declare function collectFontFamilies(obj?: {
|
|
15
15
|
fontFamily?: string;
|
16
16
|
}, fontSet?: Set<string>): Set<string>;
|
17
17
|
export declare function loadFonts(fonts: string[]): Promise<boolean>;
|
18
|
+
export declare function isValidThemeMode(mode: any): mode is PaletteMode;
|
18
19
|
export declare function getDefaultThemePrefer(meta?: {
|
19
20
|
theme: {
|
20
21
|
prefer: 'light' | 'dark' | 'system';
|
package/lib/Theme/theme.js
CHANGED
@@ -72,28 +72,38 @@ export function loadFonts(fonts) {
|
|
72
72
|
}
|
73
73
|
|
74
74
|
// 获取默认主题偏好
|
75
|
+
export function isValidThemeMode(mode) {
|
76
|
+
return mode === 'light' || mode === 'dark';
|
77
|
+
}
|
75
78
|
export function getDefaultThemePrefer(meta) {
|
76
79
|
// 跟随 url theme 参数
|
77
80
|
const urlParams = new URLSearchParams(window.location.search);
|
78
81
|
const urlPrefer = urlParams.get('theme');
|
79
|
-
if (urlPrefer
|
82
|
+
if (isValidThemeMode(urlPrefer)) {
|
80
83
|
return urlPrefer;
|
81
84
|
}
|
85
|
+
|
86
|
+
// 跟随 session theme
|
87
|
+
const sessionPrefer = sessionStorage.getItem(BLOCKLET_THEME_PREFER_KEY);
|
88
|
+
if (isValidThemeMode(sessionPrefer)) {
|
89
|
+
return sessionPrefer;
|
90
|
+
}
|
91
|
+
|
92
|
+
// 跟随 blocklet theme mode
|
82
93
|
const prefer = Object.assign({}, window.blocklet, meta).theme?.prefer;
|
94
|
+
if (prefer === 'light' || prefer === 'dark') {
|
95
|
+
return prefer;
|
96
|
+
}
|
83
97
|
if (prefer === 'system') {
|
84
98
|
// 跟随本地缓存
|
85
99
|
const localPrefer = localStorage.getItem(BLOCKLET_THEME_PREFER_KEY);
|
86
|
-
if (
|
100
|
+
if (isValidThemeMode(localPrefer)) {
|
87
101
|
return localPrefer;
|
88
102
|
}
|
89
103
|
|
90
104
|
// 跟随系统
|
91
105
|
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
92
106
|
}
|
93
|
-
// 跟随 blocklet theme mode
|
94
|
-
if (prefer === 'light' || prefer === 'dark') {
|
95
|
-
return prefer;
|
96
|
-
}
|
97
107
|
|
98
108
|
// fallback
|
99
109
|
return 'light';
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arcblock/ux",
|
3
|
-
"version": "2.13.
|
3
|
+
"version": "2.13.49",
|
4
4
|
"description": "Common used react components for arcblock products",
|
5
5
|
"keywords": [
|
6
6
|
"react",
|
@@ -71,14 +71,14 @@
|
|
71
71
|
"react": ">=18.2.0",
|
72
72
|
"react-router-dom": ">=6.22.3"
|
73
73
|
},
|
74
|
-
"gitHead": "
|
74
|
+
"gitHead": "a924ed1c40a2ca8fea2f50bea4de423d04aadd88",
|
75
75
|
"dependencies": {
|
76
76
|
"@arcblock/did-motif": "^1.1.13",
|
77
|
-
"@arcblock/icons": "^2.13.
|
78
|
-
"@arcblock/nft-display": "^2.13.
|
79
|
-
"@arcblock/react-hooks": "^2.13.
|
77
|
+
"@arcblock/icons": "^2.13.49",
|
78
|
+
"@arcblock/nft-display": "^2.13.49",
|
79
|
+
"@arcblock/react-hooks": "^2.13.49",
|
80
80
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
81
|
-
"@blocklet/theme": "^2.13.
|
81
|
+
"@blocklet/theme": "^2.13.49",
|
82
82
|
"@fontsource/roboto": "~5.1.1",
|
83
83
|
"@fontsource/ubuntu-mono": "^5.0.18",
|
84
84
|
"@iconify-icons/logos": "^1.2.36",
|
package/src/NavMenu/products.tsx
CHANGED
@@ -56,7 +56,7 @@ const translations = {
|
|
56
56
|
blockletLauncher: {
|
57
57
|
description: 'One-click app launcher',
|
58
58
|
},
|
59
|
-
|
59
|
+
aiKit: {
|
60
60
|
description: 'Boost apps with AI',
|
61
61
|
},
|
62
62
|
paymentKit: {
|
@@ -126,7 +126,7 @@ const translations = {
|
|
126
126
|
blockletLauncher: {
|
127
127
|
description: '一键启动应用程序',
|
128
128
|
},
|
129
|
-
|
129
|
+
aiKit: {
|
130
130
|
description: 'AI 赋能应用',
|
131
131
|
},
|
132
132
|
paymentKit: {
|
@@ -283,14 +283,11 @@ export default function Products({ className, isOpen, ...rest }: ProductsProps)
|
|
283
283
|
},
|
284
284
|
{
|
285
285
|
label: (
|
286
|
-
<Link
|
287
|
-
|
288
|
-
target="_blank"
|
289
|
-
rel="noreferrer noopener">
|
290
|
-
Al Kit
|
286
|
+
<Link to={`https://www.aikit.rocks/${locale}`} target="_blank" rel="noreferrer noopener">
|
287
|
+
AI Kit
|
291
288
|
</Link>
|
292
289
|
),
|
293
|
-
description: t('products.
|
290
|
+
description: t('products.aiKit.description'),
|
294
291
|
icon: <AIKitSvg />,
|
295
292
|
},
|
296
293
|
{
|
@@ -14,6 +14,7 @@ import {
|
|
14
14
|
getDefaultThemePrefer,
|
15
15
|
isTheme,
|
16
16
|
isUxTheme,
|
17
|
+
isValidThemeMode,
|
17
18
|
lazyCreateDefaultTheme,
|
18
19
|
type UxThemeOptions,
|
19
20
|
} from './theme';
|
@@ -225,11 +226,20 @@ function ColorSchemeProvider({
|
|
225
226
|
[mode, prefer, toggleMode, changeMode]
|
226
227
|
);
|
227
228
|
|
228
|
-
//
|
229
|
+
// 相应 prefer 或 urlTheme 的改变
|
229
230
|
useEffect(() => {
|
230
231
|
setMode(resolveMode(prefer));
|
231
232
|
}, [prefer, setMode, location.search]);
|
232
233
|
|
234
|
+
// 会话缓存 urlTheme 便于 App Launching 阶段临时统一 theme mode
|
235
|
+
useEffect(() => {
|
236
|
+
const urlTheme = new URLSearchParams(location.search).get('theme');
|
237
|
+
|
238
|
+
if (isValidThemeMode(urlTheme)) {
|
239
|
+
sessionStorage.setItem(BLOCKLET_THEME_PREFER_KEY, urlTheme);
|
240
|
+
}
|
241
|
+
}, [location.search]);
|
242
|
+
|
233
243
|
return (
|
234
244
|
<ColorSchemeContext.Provider value={colorSchemeValue}>
|
235
245
|
<BaseThemeProvider theme={theme} {...rest}>
|
package/src/Theme/theme.ts
CHANGED
@@ -81,29 +81,40 @@ export function loadFonts(fonts: string[]) {
|
|
81
81
|
}
|
82
82
|
|
83
83
|
// 获取默认主题偏好
|
84
|
+
export function isValidThemeMode(mode: any): mode is PaletteMode {
|
85
|
+
return mode === 'light' || mode === 'dark';
|
86
|
+
}
|
87
|
+
|
84
88
|
export function getDefaultThemePrefer(meta?: { theme: { prefer: 'light' | 'dark' | 'system' } }): PaletteMode {
|
85
89
|
// 跟随 url theme 参数
|
86
90
|
const urlParams = new URLSearchParams(window.location.search);
|
87
91
|
const urlPrefer = urlParams.get('theme');
|
88
|
-
if (urlPrefer
|
92
|
+
if (isValidThemeMode(urlPrefer)) {
|
89
93
|
return urlPrefer;
|
90
94
|
}
|
91
95
|
|
96
|
+
// 跟随 session theme
|
97
|
+
const sessionPrefer = sessionStorage.getItem(BLOCKLET_THEME_PREFER_KEY);
|
98
|
+
if (isValidThemeMode(sessionPrefer)) {
|
99
|
+
return sessionPrefer;
|
100
|
+
}
|
101
|
+
|
102
|
+
// 跟随 blocklet theme mode
|
92
103
|
const prefer = Object.assign({}, window.blocklet, meta).theme?.prefer;
|
104
|
+
if (prefer === 'light' || prefer === 'dark') {
|
105
|
+
return prefer;
|
106
|
+
}
|
107
|
+
|
93
108
|
if (prefer === 'system') {
|
94
109
|
// 跟随本地缓存
|
95
|
-
const localPrefer = localStorage.getItem(BLOCKLET_THEME_PREFER_KEY)
|
96
|
-
if (
|
110
|
+
const localPrefer = localStorage.getItem(BLOCKLET_THEME_PREFER_KEY);
|
111
|
+
if (isValidThemeMode(localPrefer)) {
|
97
112
|
return localPrefer;
|
98
113
|
}
|
99
114
|
|
100
115
|
// 跟随系统
|
101
116
|
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
102
117
|
}
|
103
|
-
// 跟随 blocklet theme mode
|
104
|
-
if (prefer === 'light' || prefer === 'dark') {
|
105
|
-
return prefer;
|
106
|
-
}
|
107
118
|
|
108
119
|
// fallback
|
109
120
|
return 'light';
|