@blocklet/pages-kit 0.4.121 → 0.4.123
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/builtin/color-picker.js +35 -25
- package/lib/cjs/contexts/color.js +4 -2
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/style.js +4 -0
- package/lib/esm/builtin/color-picker.js +37 -28
- package/lib/esm/contexts/color.js +5 -3
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/style.js +3 -0
- package/lib/types/builtin/color-picker.d.ts +9 -5
- package/lib/types/contexts/color.d.ts +1 -1
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/lib/types/utils/style.d.ts +1 -0
- package/package.json +1 -1
package/lib/cjs/utils/style.js
CHANGED
|
@@ -10,6 +10,7 @@ exports.isMuiColorKey = isMuiColorKey;
|
|
|
10
10
|
exports.getSafeGradient = getSafeGradient;
|
|
11
11
|
exports.parseColor = parseColor;
|
|
12
12
|
exports.colorConvert = colorConvert;
|
|
13
|
+
exports.getTransparentBackground = getTransparentBackground;
|
|
13
14
|
const Theme_1 = require("@arcblock/ux/lib/Theme");
|
|
14
15
|
const gradient_parser_1 = __importDefault(require("gradient-parser"));
|
|
15
16
|
const get_1 = __importDefault(require("lodash/get"));
|
|
@@ -173,3 +174,6 @@ if ((0, common_1.isBrowserEnv)()) {
|
|
|
173
174
|
// @ts-ignore inject colorConvert to globalThis
|
|
174
175
|
globalThis[common_1.COLOR_CONVERT_FUNCTION_NAME] = colorConvert;
|
|
175
176
|
}
|
|
177
|
+
function getTransparentBackground() {
|
|
178
|
+
return 'repeating-conic-gradient(#CCCCCC 0% 25%, #FFFFFF 0% 50%) 50% / 10px 10px';
|
|
179
|
+
}
|
|
@@ -1,48 +1,47 @@
|
|
|
1
|
-
import { jsx as _jsx,
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import Empty from '@arcblock/ux/lib/Empty';
|
|
3
3
|
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
4
|
-
import { Box, Button, Dialog, DialogActions, DialogContent, DialogTitle, ButtonGroup, Typography, Tooltip, Skeleton, } from '@mui/material';
|
|
4
|
+
import { Box, Button, Dialog, DialogActions, DialogContent, DialogTitle, ButtonGroup, Typography, Tooltip, Skeleton, ThemeProvider, } from '@mui/material';
|
|
5
5
|
import { useBoolean, useLocalStorageState, useReactive } from 'ahooks';
|
|
6
6
|
import { Suspense, forwardRef, lazy, useCallback, useImperativeHandle, useRef } from 'react';
|
|
7
7
|
import tinycolor from 'tinycolor2';
|
|
8
8
|
import { useMuiColorPalette } from '../contexts/color';
|
|
9
|
-
import { isColorString, isGradient, getSafeGradient } from '../utils/style';
|
|
9
|
+
import { getBlockletTheme, isColorString, isGradient, getSafeGradient, getTransparentBackground } from '../utils/style';
|
|
10
10
|
const ColorPickerLib = lazy(() => import('react-best-gradient-color-picker'));
|
|
11
11
|
const HEIGHT = 400;
|
|
12
12
|
const WIDTH = 270;
|
|
13
|
+
const blockletTheme = getBlockletTheme();
|
|
14
|
+
export function BlockletThemeProvider({ children }) {
|
|
15
|
+
return _jsx(ThemeProvider, { theme: blockletTheme, children: children });
|
|
16
|
+
}
|
|
13
17
|
export function ColorItem({ color, sx = {}, ...props }) {
|
|
14
18
|
isColorString(color);
|
|
15
19
|
const styleMap = {};
|
|
16
20
|
if (isGradient(color)) {
|
|
17
21
|
styleMap.backgroundImage = color;
|
|
18
22
|
}
|
|
23
|
+
else if (color === 'transparent') {
|
|
24
|
+
styleMap.background = getTransparentBackground();
|
|
25
|
+
}
|
|
19
26
|
else {
|
|
20
27
|
styleMap.backgroundColor = color;
|
|
21
28
|
}
|
|
22
|
-
return (
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const refDialog = useRef(null);
|
|
38
|
-
return (_jsxs(_Fragment, { children: [_jsx(ColorItem, { color: value, style: { width: '1rem', height: '1rem', padding: 0, marginRight: '0.25rem', ...style }, sx: { ...sx }, onClick: () => {
|
|
39
|
-
refDialog.current?.open({ value });
|
|
40
|
-
} }), _jsx(ConfigColorDialog, { ref: refDialog, onSave: ({ value }, close) => {
|
|
41
|
-
onChange(value);
|
|
42
|
-
close();
|
|
43
|
-
} })] }));
|
|
29
|
+
return (
|
|
30
|
+
// @FIXME:临时方案,等 theme 功能定下来之后去掉
|
|
31
|
+
_jsx(BlockletThemeProvider, { children: _jsx(Box, { sx: {
|
|
32
|
+
width: '100%',
|
|
33
|
+
height: '100%',
|
|
34
|
+
cursor: 'pointer',
|
|
35
|
+
transition: 'opacity 0.2s',
|
|
36
|
+
border: '1px solid #ccc',
|
|
37
|
+
borderRadius: 0.5,
|
|
38
|
+
'&:hover': {
|
|
39
|
+
opacity: 0.75,
|
|
40
|
+
},
|
|
41
|
+
...sx,
|
|
42
|
+
...styleMap,
|
|
43
|
+
}, ...props }) }));
|
|
44
44
|
}
|
|
45
|
-
export default ColorPicker;
|
|
46
45
|
export const ConfigColorDialog = forwardRef(function ConfigColorDialog({ onSave, enableMuiPalette = true }, ref) {
|
|
47
46
|
const state = useReactive({
|
|
48
47
|
value: '',
|
|
@@ -156,7 +155,7 @@ export const ConfigColorDialog = forwardRef(function ConfigColorDialog({ onSave,
|
|
|
156
155
|
selectedColor = 'rgba(0,0,0,0.7)';
|
|
157
156
|
}
|
|
158
157
|
}
|
|
159
|
-
return (_jsx(Tooltip, { title: item.colorKey, children: _jsx(
|
|
158
|
+
return (_jsx(Tooltip, { title: item.colorKey, children: _jsx(ColorItem, { color: item.colorValue, onClick: () => {
|
|
160
159
|
state.value = item.colorValue;
|
|
161
160
|
state.originalMuiKey = item.colorKey;
|
|
162
161
|
}, sx: {
|
|
@@ -175,7 +174,7 @@ export const ConfigColorDialog = forwardRef(function ConfigColorDialog({ onSave,
|
|
|
175
174
|
// 透明色时显示棋盘背景
|
|
176
175
|
...(item.colorValue === 'transparent'
|
|
177
176
|
? {
|
|
178
|
-
background:
|
|
177
|
+
background: getTransparentBackground(),
|
|
179
178
|
}
|
|
180
179
|
: {}),
|
|
181
180
|
}, children: state.originalMuiKey === item.colorKey && (_jsx("i", { className: "i-mdi:check", style: {
|
|
@@ -191,3 +190,13 @@ export const ConfigColorDialog = forwardRef(function ConfigColorDialog({ onSave,
|
|
|
191
190
|
state.originalMuiKey = null;
|
|
192
191
|
}, hidePresets: true, hideAdvancedSliders: true, hideColorGuide: true, hideInputType: true }) }) })) })] }), _jsxs(DialogActions, { children: [_jsx(Button, { variant: "outlined", size: "small", onClick: handleClose, children: t('common.cancel') }), _jsx(Button, { variant: "contained", size: "small", onClick: handleSave, children: t('maker.save') })] })] }));
|
|
193
192
|
});
|
|
193
|
+
export function ColorPicker({ value, onChange, style = {}, sx = {} }) {
|
|
194
|
+
const refDialog = useRef(null);
|
|
195
|
+
return (_jsxs(_Fragment, { children: [_jsx(ColorItem, { color: value || '', style: { width: '1rem', height: '1rem', padding: 0, marginRight: '0.25rem', ...style }, sx: { ...sx }, onClick: () => {
|
|
196
|
+
refDialog.current?.open({ value });
|
|
197
|
+
} }), _jsx(ConfigColorDialog, { ref: refDialog, onSave: ({ value }, close) => {
|
|
198
|
+
onChange(value);
|
|
199
|
+
close();
|
|
200
|
+
} })] }));
|
|
201
|
+
}
|
|
202
|
+
export default ColorPicker;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { useTheme } from '@mui/material/styles';
|
|
1
|
+
// import { useTheme } from '@mui/material/styles';
|
|
2
2
|
import { useCallback, useMemo } from 'react';
|
|
3
|
-
import { isMuiColorKey, colorConvert } from '../utils/style';
|
|
3
|
+
import { isMuiColorKey, colorConvert, getBlockletTheme } from '../utils/style';
|
|
4
4
|
/**
|
|
5
5
|
* Hook 用于获取和操作 MUI 主题色
|
|
6
6
|
*/
|
|
7
7
|
export function useMuiColorPalette() {
|
|
8
|
-
|
|
8
|
+
// @FIXME:临时方案,等 theme 功能定下来之后去掉
|
|
9
|
+
const theme = getBlockletTheme();
|
|
10
|
+
// const theme = useTheme();
|
|
9
11
|
// 创建 MUI 色板预设及映射关系
|
|
10
12
|
const muiPaletteColors = useMemo(() => {
|
|
11
13
|
const colors = [];
|