@antscorp/antsomi-ui 1.3.5-beta.109 → 1.3.5-beta.110
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.
|
@@ -32,9 +32,10 @@ const defaultProps = {
|
|
|
32
32
|
isCompact: false,
|
|
33
33
|
delayUpdate: 200,
|
|
34
34
|
selectColor: '#2f79bf80',
|
|
35
|
+
allowActive: true,
|
|
35
36
|
};
|
|
36
37
|
export const ResizeGrid = props => {
|
|
37
|
-
const { containerStyle, cellBorder, cellStyle, cellActiveStyle, isPreview, renderCell, grid: initGrid, image, imageSize, imagePosition, isCompact, onChange, delayUpdate, selectColor, reCalculateFlag, } = props;
|
|
38
|
+
const { containerStyle, cellBorder, cellStyle, cellActiveStyle, isPreview, renderCell, grid: initGrid, image, imageSize, imagePosition, isCompact, onChange, delayUpdate, selectColor, reCalculateFlag, allowActive, } = props;
|
|
38
39
|
const [grid, setGrid] = useState(buildGrid(initGrid || GRID_TEMPLATE.GRID_2_3));
|
|
39
40
|
const startRef = useRef(null);
|
|
40
41
|
const startCellRef = useRef(null);
|
|
@@ -54,6 +55,7 @@ export const ResizeGrid = props => {
|
|
|
54
55
|
const ctrlKeyRef = useRef(false);
|
|
55
56
|
const initRef = useRef(0);
|
|
56
57
|
const initDoneRef = useRef(false);
|
|
58
|
+
const cachedMergeCellRef = useRef({});
|
|
57
59
|
// console.log('grid', grid)
|
|
58
60
|
function lineVertical(isShow = true, left = 0) {
|
|
59
61
|
if (verticalLineRef.current && layersRef.current) {
|
|
@@ -103,7 +105,7 @@ export const ResizeGrid = props => {
|
|
|
103
105
|
: (cell.rowEnd !== line || !cell.sizeY) && (cell.rowStart !== line || !cell.sizeY);
|
|
104
106
|
const notFollow = (cell, line, isCol = true) => !isFollow(cell, line, isCol);
|
|
105
107
|
const floorSize = size => Math.floor(size);
|
|
106
|
-
|
|
108
|
+
useDeepCompareEffect(() => {
|
|
107
109
|
handleChangeGrid();
|
|
108
110
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
109
111
|
}, [grid, reCalculateFlag]);
|
|
@@ -158,9 +160,7 @@ export const ResizeGrid = props => {
|
|
|
158
160
|
}
|
|
159
161
|
}
|
|
160
162
|
else {
|
|
161
|
-
child.transformY &&
|
|
162
|
-
!child.movedBottom &&
|
|
163
|
-
(child.sizeY = +child.sizeY + yDistant);
|
|
163
|
+
child.transformY && !child.movedBottom && (child.sizeY = +child.sizeY + yDistant);
|
|
164
164
|
}
|
|
165
165
|
// console.log('check...', startRef.current.line, child.transformY, yDistant, +child.transformY - yDistant)
|
|
166
166
|
if (child.sizeY < MIN_SIZE) {
|
|
@@ -560,9 +560,8 @@ export const ResizeGrid = props => {
|
|
|
560
560
|
};
|
|
561
561
|
const downSelect = (idx, cell) => {
|
|
562
562
|
// console.log('dow select', idx, cell);
|
|
563
|
-
if (isPreview)
|
|
564
|
-
|
|
565
|
-
!cell.active && activeCell({ idx });
|
|
563
|
+
// if (isPreview) return;
|
|
564
|
+
// !cell.active && activeCell({ idx });
|
|
566
565
|
selectRef.current = { idx, cell };
|
|
567
566
|
gridRef.current = grid;
|
|
568
567
|
};
|
|
@@ -574,12 +573,14 @@ export const ResizeGrid = props => {
|
|
|
574
573
|
return;
|
|
575
574
|
}
|
|
576
575
|
const newChilds = [...grid.childs];
|
|
576
|
+
const insertArr = [];
|
|
577
577
|
for (let i = rowStart; i < rowEnd; i++) {
|
|
578
578
|
for (let j = colStart; j < colEnd; j++) {
|
|
579
579
|
const rStart = i;
|
|
580
580
|
const cStart = j;
|
|
581
581
|
const rEnd = rStart + 1;
|
|
582
582
|
const cEnd = cStart + 1;
|
|
583
|
+
const insertIdx = cachedMergeCellRef.current[`${rStart}-${cStart}`] || idx;
|
|
583
584
|
// console.log('merge', i, j, rStart, cStart, rEnd, cEnd)
|
|
584
585
|
const newChild = {
|
|
585
586
|
colStart: cStart,
|
|
@@ -588,21 +589,25 @@ export const ResizeGrid = props => {
|
|
|
588
589
|
rowEnd: rEnd,
|
|
589
590
|
};
|
|
590
591
|
if (i === rowStart && j === colStart) {
|
|
591
|
-
newChilds[idx] = newChild;
|
|
592
|
+
newChilds[idx] = Object.assign(Object.assign({}, newChilds[idx]), newChild);
|
|
592
593
|
}
|
|
593
594
|
else if (rStart !== rowStart ||
|
|
594
595
|
rEnd !== rowEnd ||
|
|
595
596
|
cStart !== colStart ||
|
|
596
597
|
cEnd !== colEnd) {
|
|
597
|
-
|
|
598
|
+
insertArr.push({ idx: insertIdx, cell: newChild });
|
|
598
599
|
}
|
|
599
600
|
}
|
|
600
601
|
}
|
|
602
|
+
insertArr.sort((a, b) => a.idx - b.idx);
|
|
603
|
+
insertArr.forEach(({ idx, cell }) => {
|
|
604
|
+
newChilds.splice(idx, 0, cell);
|
|
605
|
+
});
|
|
601
606
|
setGrid(prev => (Object.assign(Object.assign({}, prev), { childs: newChilds })));
|
|
602
607
|
};
|
|
603
608
|
function resetBackgroundCellRef() {
|
|
604
|
-
Object.
|
|
605
|
-
if (r.current) {
|
|
609
|
+
Object.entries(cellsRef.current).forEach(([idx, r]) => {
|
|
610
|
+
if (r.current && grid.childs[idx] && !grid.childs[idx].active) {
|
|
606
611
|
r.current.style.background = 'unset';
|
|
607
612
|
}
|
|
608
613
|
});
|
|
@@ -628,6 +633,8 @@ export const ResizeGrid = props => {
|
|
|
628
633
|
delete newChilds[idxStart].sizeY;
|
|
629
634
|
hCells.reverse().forEach(i => {
|
|
630
635
|
if (i !== idxStart) {
|
|
636
|
+
const deleteChild = newChilds[i];
|
|
637
|
+
cachedMergeCellRef.current[`${deleteChild.rowStart}-${deleteChild.colStart}`] = i;
|
|
631
638
|
newChilds.splice(i, 1);
|
|
632
639
|
delete cellsRef.current[i];
|
|
633
640
|
delete cordinatesRef.current[i];
|
|
@@ -636,6 +643,12 @@ export const ResizeGrid = props => {
|
|
|
636
643
|
});
|
|
637
644
|
setGrid(Object.assign(Object.assign({}, gridRef.current), { childs: newChilds }));
|
|
638
645
|
}
|
|
646
|
+
else {
|
|
647
|
+
if (!isPreview) {
|
|
648
|
+
!cell.active && activeCell({ idx });
|
|
649
|
+
// cellsRef.current[idx]?.style.background = cellActiveStyle?.background;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
639
652
|
selectRef.current = null;
|
|
640
653
|
selectEndRef.current = null;
|
|
641
654
|
};
|
|
@@ -698,7 +711,7 @@ export const ResizeGrid = props => {
|
|
|
698
711
|
const renderGrid = (style) => {
|
|
699
712
|
const { gridTemplateColumns, gridTemplateRows, childs } = grid;
|
|
700
713
|
// console.log('grid', { gridTemplateColumns, gridTemplateRows, childs });
|
|
701
|
-
return (React.createElement("div", { className: "grid-container", ref: containerRef, style: Object.assign({ gridTemplateColumns: gridTemplateColumns.map(fr => `${fr}%`).join(' '), gridTemplateRows: gridTemplateRows.map(fr => `${fr}%`).join(' ') }, style) }, childs.map((cell, idx) => (React.createElement(Cell, { key: `${cell.rowStart}-${cell.colStart}-${cell.rowEnd}-${cell.colEnd}`, idx: idx, cell: cell, down: handleDown, downCell: handleDownCell, up: handleUp, setRef: setRef, setCordinate: setCordinate, downSelect: downSelect, upSelect: upSelect, hoverSelect: hoverSelect, unMerge: unMerge, renderCell: renderCell, borderStyle: cellBorder, style: cellStyle, activeStyle: cellActiveStyle, isPreview: isPreview, rowPercentage: grid.gridTemplateRows[cell.rowStart - 1], colPercentage: grid.gridTemplateColumns[cell.colStart - 1], ctrlKeyRef: ctrlKeyRef })))));
|
|
714
|
+
return (React.createElement("div", { className: "grid-container", ref: containerRef, style: Object.assign({ gridTemplateColumns: gridTemplateColumns.map(fr => `${fr}%`).join(' '), gridTemplateRows: gridTemplateRows.map(fr => `${fr}%`).join(' ') }, style) }, childs.map((cell, idx) => (React.createElement(Cell, { key: `${cell.rowStart}-${cell.colStart}-${cell.rowEnd}-${cell.colEnd}`, idx: idx, cell: cell, down: handleDown, downCell: handleDownCell, up: handleUp, setRef: setRef, setCordinate: setCordinate, downSelect: downSelect, upSelect: upSelect, hoverSelect: hoverSelect, unMerge: unMerge, renderCell: renderCell, borderStyle: cellBorder, style: cellStyle, activeStyle: cellActiveStyle, isPreview: isPreview, rowPercentage: grid.gridTemplateRows[cell.rowStart - 1], colPercentage: grid.gridTemplateColumns[cell.colStart - 1], ctrlKeyRef: ctrlKeyRef, allowActive: allowActive })))));
|
|
702
715
|
};
|
|
703
716
|
const handleUpLine = () => {
|
|
704
717
|
lineVertical(false);
|
|
@@ -2,7 +2,7 @@ import React, { useEffect, useRef } from 'react';
|
|
|
2
2
|
import { buildGridArea, buildTranform } from '../../constant';
|
|
3
3
|
import { StyledCell } from './styled';
|
|
4
4
|
import { useDeepCompareEffect } from '../../../../../hooks/useDeepCompareEffect';
|
|
5
|
-
export const Cell = ({ cell, idx, down, downCell, up, setRef, downSelect, upSelect, hoverSelect, unMerge, renderCell, style, isPreview, borderStyle, activeStyle,
|
|
5
|
+
export const Cell = ({ cell, idx, down, downCell, up, setRef, downSelect, upSelect, hoverSelect, unMerge, renderCell, style, isPreview, borderStyle, activeStyle, setCordinate, rowPercentage, colPercentage, ctrlKeyRef, allowActive, }) => {
|
|
6
6
|
const { objectFit, image } = cell;
|
|
7
7
|
const downRef = useRef(false);
|
|
8
8
|
const timeoutRef = useRef();
|
|
@@ -72,7 +72,7 @@ export const Cell = ({ cell, idx, down, downCell, up, setRef, downSelect, upSele
|
|
|
72
72
|
// console.log('TRANSFORM', idx, buildTranform(cell))
|
|
73
73
|
return (React.createElement(StyledCell, { ref: cellRef, className: "cell",
|
|
74
74
|
// onClick={handleActiveCell}
|
|
75
|
-
onMouseOver: handleHoverSelect, onFocus: e => e, onMouseDown: handleDownCell, onMouseUp: handleUpCell, onDoubleClick: handlUnMerge, borderStyle: borderStyle || 'unset', style: Object.assign(Object.assign({ gridArea: buildGridArea(cell), width: cell.sizeX ? `${cell.sizeX}px` : 'unset', height: cell.sizeY ? `${cell.sizeY}px` : 'unset', transform: buildTranform(cell) }, (cell.active &&
|
|
75
|
+
onMouseOver: handleHoverSelect, onFocus: e => e, onMouseDown: handleDownCell, onMouseUp: handleUpCell, onDoubleClick: handlUnMerge, borderStyle: borderStyle || 'unset', style: Object.assign(Object.assign({ gridArea: buildGridArea(cell), width: cell.sizeX ? `${cell.sizeX}px` : 'unset', height: cell.sizeY ? `${cell.sizeY}px` : 'unset', transform: buildTranform(cell) }, (allowActive && cell.active &&
|
|
76
76
|
!isPreview &&
|
|
77
77
|
(activeStyle || {
|
|
78
78
|
outline: '1px solid #005eb8',
|
|
@@ -84,6 +84,7 @@ export interface CellProps {
|
|
|
84
84
|
style?: React.CSSProperties;
|
|
85
85
|
activeStyle?: React.CSSProperties;
|
|
86
86
|
isPreview?: boolean;
|
|
87
|
+
allowActive?: boolean;
|
|
87
88
|
ctrlKeyRef?: React.RefObject<boolean>;
|
|
88
89
|
}
|
|
89
90
|
export type TGrid = {
|
|
@@ -135,6 +136,7 @@ export interface IResizeGridProps {
|
|
|
135
136
|
cellActiveStyle?: React.CSSProperties;
|
|
136
137
|
containerStyle?: React.CSSProperties;
|
|
137
138
|
isCompact?: boolean;
|
|
139
|
+
allowActive?: boolean;
|
|
138
140
|
delayUpdate?: number;
|
|
139
141
|
reCalculateFlag?: number | boolean;
|
|
140
142
|
}
|