@blocklet/pages-kit 0.4.125 → 0.4.127
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 +2 -14
- package/lib/cjs/contexts/color.js +14 -7
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/common.js +11 -0
- package/lib/cjs/utils/preload.js +1 -0
- package/lib/cjs/utils/property.js +1 -1
- package/lib/cjs/utils/style.js +3 -12
- package/lib/esm/components/CustomComponentRenderer/state.js +2 -14
- package/lib/esm/contexts/color.js +14 -7
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/common.js +10 -0
- package/lib/esm/utils/preload.js +1 -0
- package/lib/esm/utils/property.js +1 -1
- package/lib/esm/utils/style.js +2 -11
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/lib/types/types/state.d.ts +1 -0
- package/lib/types/utils/common.d.ts +4 -0
- package/lib/types/utils/style.d.ts +2 -4
- package/package.json +1 -1
package/lib/cjs/utils/common.js
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isBrowserEnv = exports.COLOR_CONVERT_FUNCTION_NAME = void 0;
|
|
4
|
+
exports.isMuiColorKey = isMuiColorKey;
|
|
4
5
|
exports.COLOR_CONVERT_FUNCTION_NAME = 'colorConvert';
|
|
5
6
|
const isBrowserEnv = () => {
|
|
6
7
|
return typeof globalThis.window !== 'undefined' && typeof globalThis.document !== 'undefined';
|
|
7
8
|
};
|
|
8
9
|
exports.isBrowserEnv = isBrowserEnv;
|
|
10
|
+
/**
|
|
11
|
+
* 检查字符串是否为有效的MUI颜色键
|
|
12
|
+
*/
|
|
13
|
+
function isMuiColorKey(value) {
|
|
14
|
+
// special case
|
|
15
|
+
if (value === 'transparent') {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
return /^(primary|secondary|error|warning|info|success|grey|background|text|action)\.[a-z0-9]+$/.test(value);
|
|
19
|
+
}
|
package/lib/cjs/utils/preload.js
CHANGED
|
@@ -111,7 +111,7 @@ const initDynamicParsePropertyValueHandlers = () => {
|
|
|
111
111
|
initDynamicPropertyHandlersPromise = (async () => {
|
|
112
112
|
dynamicPropertyHandlers = {};
|
|
113
113
|
if ((0, common_1.isBrowserEnv)()) {
|
|
114
|
-
// colorConvert
|
|
114
|
+
// colorConvert 目前需要前端环境才能处理,依赖 mui theme
|
|
115
115
|
// @ts-ignore
|
|
116
116
|
const colorConvertFn = globalThis[common_1.COLOR_CONVERT_FUNCTION_NAME];
|
|
117
117
|
if (typeof colorConvertFn === 'function') {
|
package/lib/cjs/utils/style.js
CHANGED
|
@@ -3,10 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isMuiColorKey = void 0;
|
|
6
7
|
exports.getBlockletTheme = getBlockletTheme;
|
|
7
8
|
exports.isGradient = isGradient;
|
|
8
9
|
exports.isColorString = isColorString;
|
|
9
|
-
exports.isMuiColorKey = isMuiColorKey;
|
|
10
10
|
exports.getSafeGradient = getSafeGradient;
|
|
11
11
|
exports.parseColor = parseColor;
|
|
12
12
|
exports.colorConvert = colorConvert;
|
|
@@ -16,6 +16,7 @@ const gradient_parser_1 = __importDefault(require("gradient-parser"));
|
|
|
16
16
|
const get_1 = __importDefault(require("lodash/get"));
|
|
17
17
|
const tinycolor2_1 = __importDefault(require("tinycolor2"));
|
|
18
18
|
const common_1 = require("./common");
|
|
19
|
+
Object.defineProperty(exports, "isMuiColorKey", { enumerable: true, get: function () { return common_1.isMuiColorKey; } });
|
|
19
20
|
const GRADIENT_START = 0;
|
|
20
21
|
const GRADIENT_END = 100;
|
|
21
22
|
const baseTheme = (0, Theme_1.createTheme)({});
|
|
@@ -60,16 +61,6 @@ function isColorString(color) {
|
|
|
60
61
|
}
|
|
61
62
|
return false;
|
|
62
63
|
}
|
|
63
|
-
/**
|
|
64
|
-
* 检查字符串是否为有效的MUI颜色键
|
|
65
|
-
*/
|
|
66
|
-
function isMuiColorKey(value) {
|
|
67
|
-
// special case
|
|
68
|
-
if (value === 'transparent') {
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
return /^(primary|secondary|error|warning|info|success|grey|background|text|action)\.[a-z0-9]+$/.test(value);
|
|
72
|
-
}
|
|
73
64
|
/**
|
|
74
65
|
* 处理渐变的解析,并转换为rgba格式
|
|
75
66
|
*/
|
|
@@ -155,7 +146,7 @@ function parseColor(color = '') {
|
|
|
155
146
|
* @returns 转换后的颜色字符串
|
|
156
147
|
*/
|
|
157
148
|
function colorConvert(color, _theme = blockletTheme) {
|
|
158
|
-
if (isMuiColorKey(color)) {
|
|
149
|
+
if ((0, common_1.isMuiColorKey)(color)) {
|
|
159
150
|
if (color === 'transparent') {
|
|
160
151
|
return 'transparent';
|
|
161
152
|
}
|
|
@@ -17,7 +17,7 @@ const PRELOAD_COMPONENTS_STATE = window[PreloadComponentsStateGlobalVariableName
|
|
|
17
17
|
let states;
|
|
18
18
|
function importCustomComponent(m, { componentId }) {
|
|
19
19
|
// check if m is a Promise
|
|
20
|
-
if (m &&
|
|
20
|
+
if (m && m instanceof Promise) {
|
|
21
21
|
// handle Promise case
|
|
22
22
|
return (props) => {
|
|
23
23
|
const [loading, setLoading] = useState(true);
|
|
@@ -156,19 +156,7 @@ export const customComponentStates = () => {
|
|
|
156
156
|
if (typeof m === 'function') {
|
|
157
157
|
try {
|
|
158
158
|
const modulePromiseOrObject = m();
|
|
159
|
-
|
|
160
|
-
if (modulePromiseOrObject instanceof Promise) {
|
|
161
|
-
modulePromiseOrObject
|
|
162
|
-
.then((m) => {
|
|
163
|
-
Component = importCustomComponent(m, { componentId });
|
|
164
|
-
})
|
|
165
|
-
.catch((err) => {
|
|
166
|
-
console.error(`Failed to initialize component ${componentId}:`, err);
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
Component = importCustomComponent(modulePromiseOrObject, { componentId });
|
|
171
|
-
}
|
|
159
|
+
Component = importCustomComponent(modulePromiseOrObject, { componentId });
|
|
172
160
|
}
|
|
173
161
|
catch (err) {
|
|
174
162
|
console.error(`Failed to initialize component ${componentId}:`, err);
|
|
@@ -29,6 +29,13 @@ export function useMuiColorPalette() {
|
|
|
29
29
|
format: (key, variant) => `${key}.${variant}`,
|
|
30
30
|
accessor: (key) => theme.palette[key],
|
|
31
31
|
})),
|
|
32
|
+
// {
|
|
33
|
+
// type: 'did',
|
|
34
|
+
// keys: ['primary', 'secondary'],
|
|
35
|
+
// variants: null,
|
|
36
|
+
// format: (key: string) => `did.${key}`,
|
|
37
|
+
// accessor: () => theme.palette.did,
|
|
38
|
+
// },
|
|
32
39
|
{
|
|
33
40
|
type: 'background',
|
|
34
41
|
keys: ['default', 'paper'],
|
|
@@ -43,13 +50,13 @@ export function useMuiColorPalette() {
|
|
|
43
50
|
format: (key) => `text.${key}`,
|
|
44
51
|
accessor: () => theme.palette.text,
|
|
45
52
|
},
|
|
46
|
-
{
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
},
|
|
53
|
+
// {
|
|
54
|
+
// type: 'action',
|
|
55
|
+
// keys: ['active', 'hover', 'selected', 'disabled', 'disabledBackground', 'focus'],
|
|
56
|
+
// variants: null,
|
|
57
|
+
// format: (key: string) => `action.${key}`,
|
|
58
|
+
// accessor: () => theme.palette.action,
|
|
59
|
+
// },
|
|
53
60
|
{
|
|
54
61
|
type: 'grey',
|
|
55
62
|
keys: ['50', '100', '200', '300', '400', '500', '600', '700', '800', '900'],
|