@blocklet/pages-kit 0.4.99 → 0.4.100
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/cjs/components/CustomComponentRenderer/state.js +5 -2
- package/lib/cjs/contexts/color.js +153 -0
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/types/index.js +1 -0
- package/lib/cjs/types/style.js +2 -0
- package/lib/cjs/utils/property.js +43 -2
- package/lib/cjs/utils/style.js +167 -0
- package/lib/esm/components/CustomComponentRenderer/state.js +5 -2
- package/lib/esm/contexts/color.js +149 -0
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/types/index.js +1 -0
- package/lib/esm/types/style.js +1 -0
- package/lib/esm/utils/property.js +37 -1
- package/lib/esm/utils/style.js +155 -0
- package/lib/types/contexts/color.d.ts +25 -0
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/lib/types/types/index.d.ts +1 -0
- package/lib/types/types/state.d.ts +20 -6
- package/lib/types/types/style.d.ts +31 -0
- package/lib/types/utils/property.d.ts +4 -1
- package/lib/types/utils/style.d.ts +23 -0
- package/package.json +16 -4
|
@@ -108,7 +108,7 @@ function importCustomComponent(m, { componentId }) {
|
|
|
108
108
|
}
|
|
109
109
|
return null;
|
|
110
110
|
}, [loading, error, ResolvedComponent, props]);
|
|
111
|
-
return ((0, jsx_runtime_1.jsx)(material_1.Fade, { in: !loading, timeout: 500, children: (0, jsx_runtime_1.jsx)(material_1.Box, { children: content }) }));
|
|
111
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Fade, { in: !loading, timeout: 500, children: (0, jsx_runtime_1.jsx)(material_1.Box, { className: "CustomComponent-root", children: content }) }));
|
|
112
112
|
};
|
|
113
113
|
}
|
|
114
114
|
// non-Promise case
|
|
@@ -282,7 +282,10 @@ function useComponent({ instanceId, componentId, properties, locale, dev }) {
|
|
|
282
282
|
if (!property)
|
|
283
283
|
return undefined;
|
|
284
284
|
// keep preload props
|
|
285
|
-
let v = (0, property_1.parsePropertyValue)(property, value, {
|
|
285
|
+
let v = (0, property_1.parsePropertyValue)(property, value, {
|
|
286
|
+
locale,
|
|
287
|
+
defaultLocale: dev?.defaultLocale,
|
|
288
|
+
});
|
|
286
289
|
if (dev?.mode === 'production' &&
|
|
287
290
|
property.type === 'component' &&
|
|
288
291
|
property.key &&
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useMuiColorPalette = useMuiColorPalette;
|
|
4
|
+
exports.useColorConvert = useColorConvert;
|
|
5
|
+
const styles_1 = require("@mui/material/styles");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const style_1 = require("../utils/style");
|
|
8
|
+
/**
|
|
9
|
+
* Hook 用于获取和操作 MUI 主题色
|
|
10
|
+
*/
|
|
11
|
+
function useMuiColorPalette() {
|
|
12
|
+
const theme = (0, styles_1.useTheme)();
|
|
13
|
+
// 创建 MUI 色板预设及映射关系
|
|
14
|
+
const muiPaletteColors = (0, react_1.useMemo)(() => {
|
|
15
|
+
const colors = [];
|
|
16
|
+
// 定义调色板配置
|
|
17
|
+
const paletteConfig = [
|
|
18
|
+
// 特殊颜色组
|
|
19
|
+
{
|
|
20
|
+
type: 'special',
|
|
21
|
+
keys: ['transparent'],
|
|
22
|
+
variants: null,
|
|
23
|
+
format: () => 'transparent',
|
|
24
|
+
accessor: () => ({ transparent: 'transparent' }),
|
|
25
|
+
},
|
|
26
|
+
// mapper all colors
|
|
27
|
+
...['primary', 'secondary', 'error', 'warning', 'info', 'success'].map((key) => ({
|
|
28
|
+
type: key,
|
|
29
|
+
keys: [key],
|
|
30
|
+
variants: ['main', 'light', 'dark'],
|
|
31
|
+
format: (key, variant) => `${key}.${variant}`,
|
|
32
|
+
accessor: (key) => theme.palette[key],
|
|
33
|
+
})),
|
|
34
|
+
{
|
|
35
|
+
type: 'background',
|
|
36
|
+
keys: ['default', 'paper'],
|
|
37
|
+
variants: null,
|
|
38
|
+
format: (key) => `background.${key}`,
|
|
39
|
+
accessor: () => theme.palette.background,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
type: 'text',
|
|
43
|
+
keys: ['primary', 'secondary', 'disabled'],
|
|
44
|
+
variants: null,
|
|
45
|
+
format: (key) => `text.${key}`,
|
|
46
|
+
accessor: () => theme.palette.text,
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
type: 'action',
|
|
50
|
+
keys: ['active', 'hover', 'selected', 'disabled', 'disabledBackground', 'focus'],
|
|
51
|
+
variants: null,
|
|
52
|
+
format: (key) => `action.${key}`,
|
|
53
|
+
accessor: () => theme.palette.action,
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
type: 'grey',
|
|
57
|
+
keys: ['50', '100', '200', '300', '400', '500', '600', '700', '800', '900'],
|
|
58
|
+
variants: null,
|
|
59
|
+
format: (key) => `grey.${key}`,
|
|
60
|
+
accessor: () => theme.palette.grey,
|
|
61
|
+
},
|
|
62
|
+
];
|
|
63
|
+
// 统一处理各种调色板颜色
|
|
64
|
+
paletteConfig.forEach((config) => {
|
|
65
|
+
const { keys, variants, format, accessor } = config;
|
|
66
|
+
if (variants) {
|
|
67
|
+
// 处理带变体的调色板(如primary.main)
|
|
68
|
+
keys.forEach((key) => {
|
|
69
|
+
variants.forEach((variant) => {
|
|
70
|
+
try {
|
|
71
|
+
const paletteObj = accessor(key);
|
|
72
|
+
if (paletteObj && typeof paletteObj === 'object') {
|
|
73
|
+
const colorValue = String(paletteObj[variant] || '');
|
|
74
|
+
if (colorValue) {
|
|
75
|
+
colors.push({ colorKey: format(key, variant), colorValue, group: config.type });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch (e) {
|
|
80
|
+
// 忽略错误
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
// 处理不带变体的调色板(如grey.500)
|
|
87
|
+
keys.forEach((key) => {
|
|
88
|
+
try {
|
|
89
|
+
const paletteObj = accessor();
|
|
90
|
+
if (paletteObj && typeof paletteObj === 'object') {
|
|
91
|
+
const colorValue = String(paletteObj[key] || '');
|
|
92
|
+
if (colorValue) {
|
|
93
|
+
colors.push({ colorKey: format(key), colorValue, group: config.type });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
catch (e) {
|
|
98
|
+
// 忽略错误
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
return colors;
|
|
104
|
+
}, [theme]);
|
|
105
|
+
// 提取预设颜色数组 (仅颜色值)
|
|
106
|
+
const presetColors = (0, react_1.useMemo)(() => muiPaletteColors.map((color) => color.colorValue), [muiPaletteColors]);
|
|
107
|
+
// 根据颜色值获取 MUI 键名
|
|
108
|
+
const getMuiKeyByColor = (0, react_1.useCallback)((colorValue) => {
|
|
109
|
+
const found = muiPaletteColors.find((item) => item.colorValue === colorValue);
|
|
110
|
+
return found ? found.colorKey : null;
|
|
111
|
+
}, [muiPaletteColors]);
|
|
112
|
+
// 根据 MUI 键名获取颜色值
|
|
113
|
+
const getColorByMuiKey = (0, react_1.useCallback)((muiKey) => {
|
|
114
|
+
const found = muiPaletteColors.find((item) => item.colorKey === muiKey);
|
|
115
|
+
return found ? found.colorValue : null;
|
|
116
|
+
}, [muiPaletteColors]);
|
|
117
|
+
// 检查是否为有效的 MUI 颜色键
|
|
118
|
+
const isMuiColorKeyHook = (0, react_1.useCallback)((value) => {
|
|
119
|
+
return (0, style_1.isMuiColorKey)(value);
|
|
120
|
+
}, [style_1.isMuiColorKey]);
|
|
121
|
+
// 颜色分组逻辑
|
|
122
|
+
const groupedMuiColors = (0, react_1.useMemo)(() => {
|
|
123
|
+
const groups = {};
|
|
124
|
+
muiPaletteColors.forEach(({ colorKey, colorValue, group }) => {
|
|
125
|
+
if (group) {
|
|
126
|
+
if (!groups[group]) {
|
|
127
|
+
groups[group] = [];
|
|
128
|
+
}
|
|
129
|
+
groups[group].push({ colorKey, colorValue });
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
return groups;
|
|
133
|
+
}, [muiPaletteColors]);
|
|
134
|
+
return {
|
|
135
|
+
muiPaletteColors,
|
|
136
|
+
groupedMuiColors,
|
|
137
|
+
presetColors,
|
|
138
|
+
getMuiKeyByColor,
|
|
139
|
+
getColorByMuiKey,
|
|
140
|
+
isMuiColorKey: isMuiColorKeyHook,
|
|
141
|
+
theme,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* React Hook,用于实时转换颜色值(包括MUI主题色键)
|
|
146
|
+
*/
|
|
147
|
+
function useColorConvert() {
|
|
148
|
+
const muiPalette = useMuiColorPalette();
|
|
149
|
+
const { theme } = muiPalette;
|
|
150
|
+
return (0, react_1.useCallback)((color = '') => {
|
|
151
|
+
return (0, style_1.colorConvert)(color, theme);
|
|
152
|
+
}, [theme, style_1.colorConvert]);
|
|
153
|
+
}
|