@antscorp/antsomi-ui 1.3.3-beta.21 → 1.3.3-beta.22
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/dist/index.js +1 -1
- package/es/components/molecules/ResizeGrid/ResizeGrid.js +13 -5
- package/es/components/molecules/ResizeGrid/components/Cell/Cell.js +24 -5
- package/es/components/molecules/ResizeGrid/constant.d.ts +1 -1
- package/es/components/molecules/ResizeGrid/constant.js +2 -1
- package/es/components/molecules/ResizeGrid/types.d.ts +1 -0
- package/es/test.js +11 -1
- package/package.json +1 -1
|
@@ -10,9 +10,10 @@ const defaultProps = {
|
|
|
10
10
|
cellActiveStyle: {},
|
|
11
11
|
isPreviewMode: false,
|
|
12
12
|
isCompact: false,
|
|
13
|
+
delayUpdate: 100,
|
|
13
14
|
};
|
|
14
15
|
export const ResizeGrid = props => {
|
|
15
|
-
const { containerStyle, cellBorderStyle, cellStyle, cellActiveStyle, isPreviewMode, renderCell, grid: initGrid, image, imageSize, imagePosition, isCompact, onChange, } = props;
|
|
16
|
+
const { containerStyle, cellBorderStyle, cellStyle, cellActiveStyle, isPreviewMode, renderCell, grid: initGrid, image, imageSize, imagePosition, isCompact, onChange, delayUpdate, } = props;
|
|
16
17
|
const [grid, setGrid] = useState(buildGrid(initGrid || GRID_TEMPLATE.GRID_2_3));
|
|
17
18
|
const startRef = useRef(null);
|
|
18
19
|
const startCellRef = useRef(null);
|
|
@@ -21,11 +22,13 @@ export const ResizeGrid = props => {
|
|
|
21
22
|
const gridRef = useRef();
|
|
22
23
|
const containerRef = useRef(null);
|
|
23
24
|
const cellsRef = useRef({});
|
|
24
|
-
const
|
|
25
|
+
const onChangeTimoutRef = useRef();
|
|
26
|
+
const onChangeDelayRef = useRef();
|
|
27
|
+
const acceptUpdateRef = useRef(false);
|
|
25
28
|
// console.log('grid', grid)
|
|
26
29
|
const handleChangeGrid = () => {
|
|
27
|
-
clearTimeout(
|
|
28
|
-
|
|
30
|
+
clearTimeout(onChangeTimoutRef.current);
|
|
31
|
+
onChangeTimoutRef.current = setTimeout(() => {
|
|
29
32
|
if (containerRef.current && cellsRef.current && cellsRef.current[0]) {
|
|
30
33
|
const container = containerRef.current.getBoundingClientRect();
|
|
31
34
|
const childs = Object.values(cellsRef.current).map(cell => {
|
|
@@ -41,6 +44,11 @@ export const ResizeGrid = props => {
|
|
|
41
44
|
});
|
|
42
45
|
if (typeof onChange === 'function') {
|
|
43
46
|
onChange(grid, childs);
|
|
47
|
+
acceptUpdateRef.current = false;
|
|
48
|
+
clearTimeout(onChangeDelayRef.current);
|
|
49
|
+
onChangeDelayRef.current = setTimeout(() => {
|
|
50
|
+
acceptUpdateRef.current = true;
|
|
51
|
+
}, delayUpdate);
|
|
44
52
|
}
|
|
45
53
|
}
|
|
46
54
|
}, 300);
|
|
@@ -54,7 +62,7 @@ export const ResizeGrid = props => {
|
|
|
54
62
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
55
63
|
}, [grid]);
|
|
56
64
|
useDeepCompareEffect(() => {
|
|
57
|
-
if ((initGrid === null || initGrid === void 0 ? void 0 : initGrid.rows) && (initGrid === null || initGrid === void 0 ? void 0 : initGrid.cols)) {
|
|
65
|
+
if (acceptUpdateRef.current && (initGrid === null || initGrid === void 0 ? void 0 : initGrid.rows) && (initGrid === null || initGrid === void 0 ? void 0 : initGrid.cols)) {
|
|
58
66
|
setGrid(buildGrid(initGrid));
|
|
59
67
|
}
|
|
60
68
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -4,7 +4,25 @@ import { StyledCell } from './styled';
|
|
|
4
4
|
export const Cell = ({ cell, idx, down, downCell, up, setRef, downSelect, upSelect, hoverSelect, unMerge, renderCell, style, isPreviewMode, borderStyle = '1px dashed', activeStyle, }) => {
|
|
5
5
|
const { objectFit, image } = cell;
|
|
6
6
|
const downRef = useRef(false);
|
|
7
|
+
const ctrlKeyRef = useRef(false);
|
|
7
8
|
const cellRef = useRef(null);
|
|
9
|
+
const isMac = () => navigator.platform.indexOf('Mac') >= 0;
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
const handleKeyDown = e => {
|
|
12
|
+
if ((isMac() && e.metaKey) || (!isMac() && e.key === 'Control')) {
|
|
13
|
+
ctrlKeyRef.current = true;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const handleKeyUp = () => {
|
|
17
|
+
ctrlKeyRef.current = false;
|
|
18
|
+
};
|
|
19
|
+
document.addEventListener('keydown', handleKeyDown);
|
|
20
|
+
document.addEventListener('keyup', handleKeyUp);
|
|
21
|
+
return () => {
|
|
22
|
+
document.removeEventListener('keydown', handleKeyDown);
|
|
23
|
+
document.removeEventListener('keyup', handleKeyUp);
|
|
24
|
+
};
|
|
25
|
+
}, [idx, cell]);
|
|
8
26
|
useEffect(() => {
|
|
9
27
|
setRef(idx, cellRef);
|
|
10
28
|
}, [idx, cell]);
|
|
@@ -17,7 +35,7 @@ export const Cell = ({ cell, idx, down, downCell, up, setRef, downSelect, upSele
|
|
|
17
35
|
const handleUpCell = e => {
|
|
18
36
|
upSelect(idx, cell);
|
|
19
37
|
};
|
|
20
|
-
const handleDown = (direction, idx
|
|
38
|
+
const handleDown = (e, direction, idx) => {
|
|
21
39
|
e.stopPropagation();
|
|
22
40
|
downRef.current = true;
|
|
23
41
|
// console.log('down', direction, idx, e)
|
|
@@ -28,7 +46,7 @@ export const Cell = ({ cell, idx, down, downCell, up, setRef, downSelect, upSele
|
|
|
28
46
|
bottom: cell.rowEnd,
|
|
29
47
|
left: cell.colStart,
|
|
30
48
|
}[direction];
|
|
31
|
-
if (
|
|
49
|
+
if (ctrlKeyRef.current ||
|
|
32
50
|
(direction === 'top' && cell.movedTop) ||
|
|
33
51
|
(direction === 'right' && cell.movedRight) ||
|
|
34
52
|
(direction === 'bottom' && cell.movedBottom) ||
|
|
@@ -39,7 +57,7 @@ export const Cell = ({ cell, idx, down, downCell, up, setRef, downSelect, upSele
|
|
|
39
57
|
down(e, type, line);
|
|
40
58
|
}
|
|
41
59
|
};
|
|
42
|
-
const handleUp = (direction, idx
|
|
60
|
+
const handleUp = (e, direction, idx) => {
|
|
43
61
|
e.stopPropagation();
|
|
44
62
|
// console.log('up', direction, idx, e)
|
|
45
63
|
downRef.current = false;
|
|
@@ -50,7 +68,8 @@ export const Cell = ({ cell, idx, down, downCell, up, setRef, downSelect, upSele
|
|
|
50
68
|
};
|
|
51
69
|
const renderCellContent = (cell, idx) => renderCell
|
|
52
70
|
? renderCell(cell, idx)
|
|
53
|
-
: !!image &&
|
|
71
|
+
: !!image &&
|
|
72
|
+
image.imageUrl && (React.createElement("div", { className: "imageWrapper" },
|
|
54
73
|
React.createElement("img", { src: image.imageUrl, alt: "menu", style: image.imageStyles })));
|
|
55
74
|
// const handleDrag = (direction, idx, e) => {
|
|
56
75
|
// if (!downRef.current) return;
|
|
@@ -63,5 +82,5 @@ export const Cell = ({ cell, idx, down, downCell, up, setRef, downSelect, upSele
|
|
|
63
82
|
outline: '1px solid #005eb8',
|
|
64
83
|
}))), style) },
|
|
65
84
|
renderCellContent(cell, idx),
|
|
66
|
-
['top', 'right', 'bottom', 'left'].map(direction => (React.createElement("div", { key: direction, className: `resize-${direction}`, onMouseDown: e => handleDown(direction, idx
|
|
85
|
+
['top', 'right', 'bottom', 'left'].map(direction => (React.createElement("div", { key: direction, className: `resize-${direction}`, onMouseDown: e => handleDown(e, direction, idx), onMouseUp: e => handleUp(e, direction, idx) })))));
|
|
67
86
|
};
|
|
@@ -27,7 +27,7 @@ export declare const GRID_TEMPLATE: {
|
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
29
|
export declare const buildCell: (cell: any) => any;
|
|
30
|
-
export declare const buildGrid: (
|
|
30
|
+
export declare const buildGrid: (inputGrid: Partial<TGrid>) => TGrid;
|
|
31
31
|
export declare const buildGridArea: (box: any) => string;
|
|
32
32
|
export declare const buildTranform: (box: any) => string;
|
|
33
33
|
export declare const MIN_SIZE = 32;
|
|
@@ -36,8 +36,9 @@ export const GRID_TEMPLATE = {
|
|
|
36
36
|
},
|
|
37
37
|
};
|
|
38
38
|
export const buildCell = cell => (Object.assign({ rowEnd: cell.rowEnd || cell.rowStart + 1, colEnd: cell.colEnd || cell.colStart + 1 }, cell));
|
|
39
|
-
export const buildGrid = (
|
|
39
|
+
export const buildGrid = (inputGrid) => {
|
|
40
40
|
let childs = [];
|
|
41
|
+
const grid = JSON.parse(JSON.stringify(inputGrid));
|
|
41
42
|
let buildCol = !grid.gridTemplateColumns || !grid.gridTemplateColumns.length;
|
|
42
43
|
const buildRow = !grid.gridTemplateRows || !grid.gridTemplateRows.length;
|
|
43
44
|
const buildChild = !grid.childs || !grid.childs.length;
|
package/es/test.js
CHANGED
|
@@ -4,7 +4,7 @@ import { createRoot } from 'react-dom/client';
|
|
|
4
4
|
import '@antscorp/icons/main.css';
|
|
5
5
|
import { ConfigProvider, EdgeSetting, GradientSetting, IconSelection, PositionSetting, SettingWrapper,
|
|
6
6
|
// Slider,
|
|
7
|
-
SliderWithInputNumber, Space, UploadImage, RateV2, } from './components';
|
|
7
|
+
SliderWithInputNumber, Space, UploadImage, RateV2, ResizeGrid, } from './components';
|
|
8
8
|
// import { Slider } from 'antd';
|
|
9
9
|
import { Slider } from '@antscorp/antsomi-ui/es/components/atoms/Slider';
|
|
10
10
|
import { Rate } from './components/atoms/Rate';
|
|
@@ -87,6 +87,7 @@ export const App = () => {
|
|
|
87
87
|
// ---------------------------- Test Helps End ------------------------------
|
|
88
88
|
// ------------------------ Media template components test start -------------------------
|
|
89
89
|
const [starValue, setStarValue] = useState(1.3);
|
|
90
|
+
const [grid, setGrid] = useState({ rows: 3, cols: 3 });
|
|
90
91
|
return (React.createElement(ConfigProvider, null,
|
|
91
92
|
React.createElement("div", { style: {
|
|
92
93
|
width: 500,
|
|
@@ -105,6 +106,15 @@ export const App = () => {
|
|
|
105
106
|
React.createElement("br", null),
|
|
106
107
|
React.createElement("h2", { style: { textAlign: 'center' } }, "Test component of media template"),
|
|
107
108
|
React.createElement(Space, { size: 20, direction: "vertical" },
|
|
109
|
+
React.createElement(ResizeGrid, { grid: grid, renderCell: (cell, idx) => (React.createElement("div", { style: { height: '100%' } })),
|
|
110
|
+
// image="https://source.unsplash.com/random/300×300"
|
|
111
|
+
// imagePosition="center"
|
|
112
|
+
// imageSize="contain"
|
|
113
|
+
onChange: (grid, childs) => {
|
|
114
|
+
console.log('chnaged', grid, childs);
|
|
115
|
+
setGrid(grid);
|
|
116
|
+
} }),
|
|
117
|
+
React.createElement("button", { onClick: () => setGrid({ cols: 4, rows: 3 }) }, "change"),
|
|
108
118
|
React.createElement(SettingWrapper, { vertical: true, label: "Color Setting" },
|
|
109
119
|
React.createElement(GradientSetting, null)),
|
|
110
120
|
React.createElement(SliderWithInputNumber, { label: "Size (px)", labelStyling: { marginTop: 10 }, min: 0, max: 100, value: sliderValue, onAfterChange: handleChangeSlider }),
|