es-grid-template 1.3.6 → 1.3.8
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/assets/index.css +35 -24
- package/assets/index.scss +57 -21
- package/es/grid-component/EditableCell.js +12 -11
- package/es/grid-component/GridStyle.d.ts +5 -3
- package/es/grid-component/GridStyle.js +1 -1
- package/es/grid-component/TableGrid.js +28 -21
- package/es/grid-component/hooks/columns/index.d.ts +1 -1
- package/es/grid-component/hooks/columns/index.js +15 -14
- package/es/grid-component/hooks/useColumns.js +12 -9
- package/es/grid-component/hooks/utils.d.ts +19 -4
- package/es/grid-component/hooks/utils.js +377 -26
- package/es/grid-component/styles.scss +57 -21
- package/es/grid-component/table/Grid.js +1 -1
- package/es/grid-component/table/GridEdit.js +383 -268
- package/es/grid-component/table/Group.js +1 -1
- package/es/grid-component/type.d.ts +4 -4
- package/lib/grid-component/EditableCell.js +12 -11
- package/lib/grid-component/GridStyle.d.ts +5 -3
- package/lib/grid-component/GridStyle.js +1 -1
- package/lib/grid-component/TableGrid.js +26 -20
- package/lib/grid-component/hooks/columns/index.d.ts +1 -1
- package/lib/grid-component/hooks/columns/index.js +15 -14
- package/lib/grid-component/hooks/useColumns.js +12 -9
- package/lib/grid-component/hooks/utils.d.ts +19 -4
- package/lib/grid-component/hooks/utils.js +401 -33
- package/lib/grid-component/styles.scss +57 -21
- package/lib/grid-component/table/Grid.js +1 -1
- package/lib/grid-component/table/GridEdit.js +382 -259
- package/lib/grid-component/table/Group.js +1 -1
- package/lib/grid-component/type.d.ts +4 -4
- package/package.json +2 -2
|
@@ -13,26 +13,12 @@ import dayjs from "dayjs";
|
|
|
13
13
|
import 'dayjs/locale/es';
|
|
14
14
|
import 'dayjs/locale/vi';
|
|
15
15
|
import TableGrid from "../TableGrid";
|
|
16
|
-
import { addRows8, addRowsUp, checkChild, editAbleColumns, findAllChildrenKeys, findItemByKey, findItemPath, flattenArray, flattenData, getDefaultValue, getEditType, getFirstSelectCell, getLastSelectCell, getRowNumber, getRowsPasteIndex,
|
|
17
|
-
// isBottomMostInRanges,
|
|
18
|
-
isBottomMostInRegion,
|
|
19
|
-
// isContinuous,
|
|
20
|
-
isEditable,
|
|
21
|
-
// isEqualSet,
|
|
22
|
-
isObjEmpty, isRightMostInRegion, isTopMostInRegion,
|
|
23
|
-
// mergedSets,
|
|
24
|
-
newGuid, sortedSetASC, totalFixedWidth, updateArrayByKey } from "../hooks";
|
|
16
|
+
import { addClassBorderPasteCell, addClassCellIndexSelected, addRows8, addRowsUp, checkChild, editAbleColumns, findAllChildrenKeys, findItemByKey, findItemPath, flattenArray, flattenData, getDefaultValue, getEditType, getFirstSelectCell, getLastSelectCell, getRowNumber, getRowsPasteIndex, hideDraggingPoint, isEditable, isEqualSet, isObjEmpty, newGuid, onAddBorderSelectedCell, onAddBgSelectedCell, onRemoveBorderSelectedCell, onRemoveBgSelectedCell, removeClassBorderPasteCell, removeClassCellIndexSelected, showDraggingPoint, sortedSetASC, totalFixedWidth, updateArrayByKey } from "../hooks";
|
|
25
17
|
import Message from "../../Message/Message";
|
|
26
|
-
// import Command from "../Command";
|
|
27
|
-
|
|
28
18
|
import { Toolbar, ConfigProvider, InputNumber } from "rc-master-ui";
|
|
29
19
|
import classnames from "classnames";
|
|
30
|
-
import useMergedState from "rc-util/es/hooks/useMergedState";
|
|
31
20
|
import { Plus, Trash2 } from "becoxy-icons";
|
|
32
|
-
|
|
33
|
-
// import {ContextInfo, ContextMenuItem} from "../type";
|
|
34
|
-
// import useLazyKVMap from "rc-master-ui/es/table/hooks/useLazyKVMap";
|
|
35
|
-
|
|
21
|
+
import { faker } from "@faker-js/faker";
|
|
36
22
|
const {
|
|
37
23
|
Paragraph,
|
|
38
24
|
Title
|
|
@@ -117,7 +103,7 @@ const defaultContext = [{
|
|
|
117
103
|
}];
|
|
118
104
|
const GridEdit = props => {
|
|
119
105
|
const {
|
|
120
|
-
id,
|
|
106
|
+
id: tableId,
|
|
121
107
|
tableRef,
|
|
122
108
|
t,
|
|
123
109
|
columns,
|
|
@@ -145,24 +131,28 @@ const GridEdit = props => {
|
|
|
145
131
|
showDefaultContext,
|
|
146
132
|
...rest
|
|
147
133
|
} = props;
|
|
148
|
-
const {
|
|
149
|
-
mode,
|
|
150
|
-
type,
|
|
151
|
-
// checkboxOnly,
|
|
152
|
-
// hideSelectAll,
|
|
153
|
-
columnWidth
|
|
154
|
-
// selectedRowKeys,
|
|
155
|
-
// defaultSelectedRowKeys
|
|
156
|
-
} = selectionSettings || {};
|
|
157
134
|
const ref = useRef(null);
|
|
158
135
|
const isSelecting = useRef(false);
|
|
159
136
|
const startCell = useRef(null);
|
|
160
137
|
const childrenColumnName = 'children';
|
|
161
138
|
const isSelectingRow = useRef(false);
|
|
162
139
|
const rowStart = useRef(null);
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
140
|
+
const rowsSelected = useRef(new Set());
|
|
141
|
+
const selectedCells = useRef(new Set());
|
|
142
|
+
const pasteCells = useRef(new Set());
|
|
143
|
+
const startSelectedCells = useRef(null);
|
|
144
|
+
|
|
145
|
+
// quét vùng chọn
|
|
146
|
+
const isDragMouse = useRef(false);
|
|
147
|
+
const isMouseDown = useRef(false);
|
|
148
|
+
|
|
149
|
+
// quét vùng được paste - tiếp tục hiển thị con trỏ crosshair
|
|
150
|
+
// const isPasteDragging = useRef(false);
|
|
151
|
+
|
|
152
|
+
const id = React.useMemo(() => {
|
|
153
|
+
return tableId ?? faker.string.alpha(20);
|
|
154
|
+
// return tableId ?? newGuid()
|
|
155
|
+
}, [tableId]);
|
|
166
156
|
const itemsAdd = [{
|
|
167
157
|
key: '10',
|
|
168
158
|
label: '10 rows'
|
|
@@ -176,7 +166,9 @@ const GridEdit = props => {
|
|
|
176
166
|
const [form] = Form.useForm();
|
|
177
167
|
const [editingKey, setEditingKey] = useState('');
|
|
178
168
|
const [isFilter, setIsFilter] = React.useState(false);
|
|
179
|
-
const [
|
|
169
|
+
const [rangeCells, setRangeCells] = useState(new Set());
|
|
170
|
+
|
|
171
|
+
// const [pasteCells, setPasteCells] = useState(new Set())
|
|
180
172
|
|
|
181
173
|
// const defaultModalPaste = {open: false, rowIndex: -1, colIndex: -1, record: {}, rowsPasted: []}
|
|
182
174
|
|
|
@@ -189,16 +181,17 @@ const GridEdit = props => {
|
|
|
189
181
|
open: false,
|
|
190
182
|
type: ''
|
|
191
183
|
});
|
|
192
|
-
// const [openModalPaste, setOpenModalPaste] = useState(defaultModalPaste)
|
|
193
|
-
|
|
194
184
|
const [rowsAdd, setRowsAdd] = useState(1);
|
|
195
|
-
const [pasteCells, setPasteCells] = useState(new Set());
|
|
196
185
|
const [cellEditing, setCellEditing] = useState(null);
|
|
197
|
-
|
|
186
|
+
|
|
187
|
+
// const [isSelectDragging, setSelectIsDragging] = useState(false)
|
|
188
|
+
|
|
198
189
|
const [isPasteDragging, setIsPasteDragging] = useState(false); // isPasteDragging == tiếp tục hiển thị con trỏ crosshair
|
|
199
190
|
|
|
200
|
-
const [rowsSelected, setRowsSelected] = useState(new Set())
|
|
201
|
-
|
|
191
|
+
// const [rowsSelected, setRowsSelected] = useState(new Set())
|
|
192
|
+
|
|
193
|
+
// const [startSelectedCells, setStartSelectedCell] = useState<{ row: number; col: number } | null>(null)
|
|
194
|
+
|
|
202
195
|
const [innerExpandedKeys, setInnerExpandedKeys] = React.useState(() => {
|
|
203
196
|
// if (defaultExpandedRowKeys) {
|
|
204
197
|
// return defaultExpandedRowKeys;
|
|
@@ -209,12 +202,9 @@ const GridEdit = props => {
|
|
|
209
202
|
// return [];
|
|
210
203
|
});
|
|
211
204
|
const mergedExpandedKeys = React.useMemo(() => new Set(innerExpandedKeys || []), [innerExpandedKeys]);
|
|
212
|
-
const [mergedSelectedKeys, setMergedSelectedKeys] = useMergedState([], {
|
|
213
|
-
value: []
|
|
214
|
-
});
|
|
215
205
|
const rowsFocus = React.useMemo(() => {
|
|
216
|
-
return [...new Set(Array.from(
|
|
217
|
-
}, [
|
|
206
|
+
return [...new Set(Array.from(rangeCells).map(item => parseInt(item.split('-')[0])))] ?? [];
|
|
207
|
+
}, [rangeCells]);
|
|
218
208
|
const contextMenuItems = React.useMemo(() => {
|
|
219
209
|
const a = showDefaultContext !== false ? [...defaultContext] : [];
|
|
220
210
|
const b = propsContext ? [...propsContext, {
|
|
@@ -294,6 +284,15 @@ const GridEdit = props => {
|
|
|
294
284
|
|
|
295
285
|
// thêm n dòng bên trên
|
|
296
286
|
const handleInsertBefore = (item, n) => {
|
|
287
|
+
//
|
|
288
|
+
onRemoveBgSelectedCell(selectedCells.current, id);
|
|
289
|
+
onRemoveBorderSelectedCell(selectedCells.current, id);
|
|
290
|
+
//
|
|
291
|
+
|
|
292
|
+
setTimeout(() => {
|
|
293
|
+
onAddBgSelectedCell(selectedCells.current, id);
|
|
294
|
+
onAddBorderSelectedCell(selectedCells.current, id);
|
|
295
|
+
}, 10);
|
|
297
296
|
const defaultRowValue = getDefaultValue(defaultValue);
|
|
298
297
|
// const rowId = defaultRowValue && defaultRowValue.id ? defaultRowValue.id : newGuid()
|
|
299
298
|
|
|
@@ -368,9 +367,6 @@ const GridEdit = props => {
|
|
|
368
367
|
//thêm 1 dòng bên dưới
|
|
369
368
|
const handleInsertAfter = (item, n) => {
|
|
370
369
|
const defaultRowValue = getDefaultValue(defaultValue);
|
|
371
|
-
|
|
372
|
-
// const rowId = defaultRowValue && defaultRowValue.id ? defaultRowValue.id : newGuid()
|
|
373
|
-
|
|
374
370
|
const record = flattenData(childrenColumnName, dataSource)[rowsFocus[rowsFocus.length - 1]];
|
|
375
371
|
|
|
376
372
|
// const record = getRecordByKey()
|
|
@@ -403,8 +399,6 @@ const GridEdit = props => {
|
|
|
403
399
|
rowId: newGuid()
|
|
404
400
|
});
|
|
405
401
|
const index = newData.findIndex(obj => obj[rowKey] === record[rowKey]);
|
|
406
|
-
|
|
407
|
-
// newData.splice(index + 1, 0, { ...defaultRowValue, rowId, parentId: null })
|
|
408
402
|
newData.splice(index + 1, 0, ...newRows);
|
|
409
403
|
triggerChangeData?.(newData, 'INSERT_AFTER');
|
|
410
404
|
} else {
|
|
@@ -486,6 +480,10 @@ const GridEdit = props => {
|
|
|
486
480
|
}
|
|
487
481
|
};
|
|
488
482
|
const handleDeleteRows = item => {
|
|
483
|
+
setTimeout(() => {
|
|
484
|
+
onAddBgSelectedCell(selectedCells.current, id);
|
|
485
|
+
onAddBorderSelectedCell(selectedCells.current, id);
|
|
486
|
+
});
|
|
489
487
|
if (item.onClick) {
|
|
490
488
|
item.onClick({
|
|
491
489
|
toolbar: item
|
|
@@ -505,14 +503,14 @@ const GridEdit = props => {
|
|
|
505
503
|
triggerChangeData?.([], 'INSERT_BEFORE');
|
|
506
504
|
};
|
|
507
505
|
const handleDeleteContent = () => {
|
|
508
|
-
if (selectedCells.size > 0) {
|
|
506
|
+
if (selectedCells.current.size > 0) {
|
|
509
507
|
const newData = [...dataSource];
|
|
510
508
|
|
|
511
509
|
// colIndex => field
|
|
512
510
|
const colIndexToField = flatColumns2(columns).map(col => col.field);
|
|
513
511
|
|
|
514
512
|
// Duyệt qua mỗi ô cần xóa
|
|
515
|
-
for (const cell of selectedCells) {
|
|
513
|
+
for (const cell of selectedCells.current) {
|
|
516
514
|
const [rowIndexStr, colIndexStr] = cell.split("-");
|
|
517
515
|
const rowIndex = Number(rowIndexStr);
|
|
518
516
|
const colIndex = Number(colIndexStr);
|
|
@@ -741,10 +739,8 @@ const GridEdit = props => {
|
|
|
741
739
|
trigger,
|
|
742
740
|
getValues,
|
|
743
741
|
reset
|
|
744
|
-
// formState: { errors }
|
|
745
742
|
} = useForm({
|
|
746
743
|
mode: 'onChange'
|
|
747
|
-
// defaultValues,
|
|
748
744
|
// resolver: yupResolver(formSchema)
|
|
749
745
|
});
|
|
750
746
|
const isEditing = record => record[rowKey] === editingKey;
|
|
@@ -777,23 +773,16 @@ const GridEdit = props => {
|
|
|
777
773
|
setEditingKey('');
|
|
778
774
|
isSelecting.current = false;
|
|
779
775
|
startCell.current = null;
|
|
780
|
-
setSelectedCells(new Set())
|
|
781
|
-
setRowsSelected(new Set())
|
|
776
|
+
// setSelectedCells(new Set())
|
|
777
|
+
// setRowsSelected(new Set())
|
|
778
|
+
|
|
779
|
+
onRemoveBgSelectedCell(selectedCells.current, id);
|
|
780
|
+
onRemoveBorderSelectedCell(selectedCells.current, id);
|
|
781
|
+
hideDraggingPoint(selectedCells.current, id);
|
|
782
|
+
rowsSelected.current = new Set();
|
|
783
|
+
selectedCells.current = new Set();
|
|
784
|
+
setRangeCells(new Set());
|
|
782
785
|
}
|
|
783
|
-
|
|
784
|
-
// if (tableBodies.length > 0) {
|
|
785
|
-
// const tableBody = tableBodies[0]; // Chọn tbody đầu tiên (nếu có nhiều)
|
|
786
|
-
//
|
|
787
|
-
// if (!tableBody.contains(event.target as Node)) {
|
|
788
|
-
// setEditingKey('')
|
|
789
|
-
// isSelecting.current = false;
|
|
790
|
-
// startCell.current = null;
|
|
791
|
-
// setSelectedCells(new Set())
|
|
792
|
-
// setRowsSelected(new Set())
|
|
793
|
-
// } else {
|
|
794
|
-
//
|
|
795
|
-
// }
|
|
796
|
-
// }
|
|
797
786
|
};
|
|
798
787
|
document.addEventListener("click", handleClickOutside);
|
|
799
788
|
return () => {
|
|
@@ -805,6 +794,9 @@ const GridEdit = props => {
|
|
|
805
794
|
e.stopPropagation();
|
|
806
795
|
return;
|
|
807
796
|
}
|
|
797
|
+
|
|
798
|
+
// isDragMouse.current = true
|
|
799
|
+
isMouseDown.current = true;
|
|
808
800
|
if (e.ctrlKey) {
|
|
809
801
|
isSelecting.current = true;
|
|
810
802
|
startCell.current = {
|
|
@@ -821,45 +813,56 @@ const GridEdit = props => {
|
|
|
821
813
|
row,
|
|
822
814
|
col
|
|
823
815
|
};
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
816
|
+
const target = e.target;
|
|
817
|
+
if (target.closest('.dragging-point')) {
|
|
818
|
+
e.stopPropagation();
|
|
819
|
+
e.preventDefault();
|
|
820
|
+
return; // Không xử lý gì cả
|
|
827
821
|
} else {
|
|
828
|
-
setStartSelectedCell({
|
|
822
|
+
// setStartSelectedCell({row, col})
|
|
823
|
+
|
|
824
|
+
startSelectedCells.current = {
|
|
829
825
|
row,
|
|
830
826
|
col
|
|
831
|
-
}
|
|
832
|
-
|
|
833
|
-
|
|
827
|
+
};
|
|
828
|
+
|
|
829
|
+
// setSelectedCells(new Set([`${row}-${col}`]));
|
|
830
|
+
|
|
831
|
+
const cells = new Set([`${row}-${col}`]);
|
|
832
|
+
if (selectedCells.current && selectedCells.current.size > 0) {
|
|
833
|
+
if (!isEqualSet(cells, rangeCells)) {
|
|
834
|
+
onRemoveBgSelectedCell(rangeCells, id);
|
|
835
|
+
onRemoveBorderSelectedCell(rangeCells, id);
|
|
836
|
+
hideDraggingPoint(selectedCells.current, id);
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
if (rowsSelected.current && rowsSelected.current.size > 0) {
|
|
840
|
+
removeClassCellIndexSelected(rowsSelected.current, id);
|
|
841
|
+
}
|
|
842
|
+
if (!isEqualSet(cells, selectedCells.current)) {
|
|
843
|
+
selectedCells.current = cells;
|
|
844
|
+
if (editingKey) {
|
|
845
|
+
setTimeout(() => {
|
|
846
|
+
onAddBgSelectedCell(cells, id);
|
|
847
|
+
onAddBorderSelectedCell(cells, id);
|
|
848
|
+
}, 100);
|
|
849
|
+
} else {
|
|
850
|
+
onAddBgSelectedCell(cells, id);
|
|
851
|
+
onAddBorderSelectedCell(cells, id);
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
// setRowsSelected(new Set())
|
|
856
|
+
rowsSelected.current = new Set();
|
|
834
857
|
}
|
|
835
858
|
}
|
|
836
|
-
|
|
837
|
-
// isSelecting.current = true;
|
|
838
|
-
// startCell.current = { row, col };
|
|
839
|
-
//
|
|
840
|
-
// if (e.target.className === 'dragging-point') {
|
|
841
|
-
// // e.stopPropagation()
|
|
842
|
-
// // e.preventDefault()
|
|
843
|
-
// } else {
|
|
844
|
-
//
|
|
845
|
-
// setStartSelectedCell({row, col})
|
|
846
|
-
// setSelectedCells(new Set([`${row}-${col}`]));
|
|
847
|
-
// setRowsSelected(new Set())
|
|
848
|
-
// }
|
|
849
859
|
};
|
|
850
860
|
const triggerDragPaste = pastesArray => {
|
|
851
|
-
const mergedSet = new Set([...selectedCells, ...pastesArray]);
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
setSelectedCells(sortedSetASC(mergedSet));
|
|
857
|
-
setPasteCells(new Set());
|
|
858
|
-
const rowSelectedFirst = getFirstSelectCell(selectedCells).row;
|
|
859
|
-
const rowPasteLast = getLastSelectCell(pasteCells).row;
|
|
860
|
-
const selectedArray = Array.from(selectedCells).map(key => {
|
|
861
|
+
const mergedSet = new Set([...selectedCells.current, ...pastesArray]);
|
|
862
|
+
const rowSelectedFirst = getFirstSelectCell(selectedCells.current).row;
|
|
863
|
+
const rowPasteLast = getLastSelectCell(pasteCells.current).row;
|
|
864
|
+
const selectedArray = Array.from(selectedCells.current).map(key => {
|
|
861
865
|
const [row, col] = key.split("-").map(Number);
|
|
862
|
-
// @ts-ignore
|
|
863
866
|
const columnKey = columns[col].field;
|
|
864
867
|
|
|
865
868
|
// @ts-ignore
|
|
@@ -871,6 +874,35 @@ const GridEdit = props => {
|
|
|
871
874
|
// return { row, col, value: '' };
|
|
872
875
|
});
|
|
873
876
|
|
|
877
|
+
// let selectedArray = []
|
|
878
|
+
//
|
|
879
|
+
// if (rowPasteLast > rowSelectedFirst) {
|
|
880
|
+
// // kéo xuóng
|
|
881
|
+
// selectedArray = Array.from(selectedCells).map((key: any) => {
|
|
882
|
+
//
|
|
883
|
+
// const [row, col] = key.split("-").map(Number);
|
|
884
|
+
// // @ts-ignore
|
|
885
|
+
// const columnKey = columns[col].field;
|
|
886
|
+
//
|
|
887
|
+
// // @ts-ignore
|
|
888
|
+
// return { row, col, value: flattenData(childrenColumnName as any,dataSource)[row][columnKey] };
|
|
889
|
+
// // return { row, col, value: '' };
|
|
890
|
+
// });
|
|
891
|
+
// } else {
|
|
892
|
+
// // kéo lên
|
|
893
|
+
//
|
|
894
|
+
// selectedArray = Array.from(sortedSetDSC(selectedCells)).map((key: any) => {
|
|
895
|
+
//
|
|
896
|
+
// const [row, col] = key.split("-").map(Number);
|
|
897
|
+
// // @ts-ignore
|
|
898
|
+
// const columnKey = columns[col].field;
|
|
899
|
+
//
|
|
900
|
+
// // @ts-ignore
|
|
901
|
+
// return { row, col, value: flattenData(childrenColumnName as any,dataSource)[row][columnKey] };
|
|
902
|
+
// // return { row, col, value: '' };
|
|
903
|
+
// });
|
|
904
|
+
// }
|
|
905
|
+
|
|
874
906
|
// Xác định min/max row và col để sắp xếp dữ liệu
|
|
875
907
|
const minRow = Math.min(...selectedArray.map(cell => cell.row));
|
|
876
908
|
const maxRow = Math.max(...selectedArray.map(cell => cell.row));
|
|
@@ -909,7 +941,7 @@ const GridEdit = props => {
|
|
|
909
941
|
// Lấy vị trí bắt đầu
|
|
910
942
|
// const { row: startRow, col: startCol } = selectedCell;
|
|
911
943
|
const startRow = getFirstSelectCell(pastesArray).row;
|
|
912
|
-
const startCol = getFirstSelectCell(selectedCells).col;
|
|
944
|
+
const startCol = getFirstSelectCell(selectedCells.current).col;
|
|
913
945
|
const pastedRows = [];
|
|
914
946
|
const pastedColumns = new Set();
|
|
915
947
|
newRange.addedRows.forEach((rowValues, rowIndex) => {
|
|
@@ -947,19 +979,40 @@ const GridEdit = props => {
|
|
|
947
979
|
const pastedColumnsArray = Array.from(pastedColumns) ?? [];
|
|
948
980
|
triggerPaste?.(pastedRows, pastedColumnsArray, newData);
|
|
949
981
|
}
|
|
982
|
+
|
|
983
|
+
/// cập nhật cell class
|
|
984
|
+
if (selectedCells.current && selectedCells.current.size > 0) {
|
|
985
|
+
onRemoveBgSelectedCell(rangeCells, id);
|
|
986
|
+
onRemoveBorderSelectedCell(rangeCells, id);
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
// selectedCells.current = sortedSetASC(mergedSet)
|
|
990
|
+
hideDraggingPoint(selectedCells.current, id);
|
|
991
|
+
selectedCells.current = sortedSetASC(mergedSet);
|
|
992
|
+
onAddBgSelectedCell(sortedSetASC(mergedSet), id);
|
|
993
|
+
onAddBorderSelectedCell(sortedSetASC(mergedSet), id);
|
|
994
|
+
showDraggingPoint(sortedSetASC(mergedSet), id);
|
|
995
|
+
|
|
996
|
+
// setPasteCells(new Set())
|
|
997
|
+
|
|
998
|
+
if (pasteCells.current && pasteCells.current.size > 0) {
|
|
999
|
+
removeClassBorderPasteCell(pasteCells.current, 'up', id);
|
|
1000
|
+
}
|
|
1001
|
+
pasteCells.current = new Set();
|
|
950
1002
|
};
|
|
951
1003
|
const handlePointDoubleClick = e => {
|
|
952
|
-
e.preventDefault()
|
|
1004
|
+
// e.preventDefault()
|
|
953
1005
|
e.stopPropagation();
|
|
954
|
-
const colStart = getFirstSelectCell(selectedCells).col;
|
|
955
|
-
const colEnd = getLastSelectCell(selectedCells).col;
|
|
956
|
-
const startPasteRow = getLastSelectCell(selectedCells).row;
|
|
1006
|
+
const colStart = getFirstSelectCell(selectedCells.current).col;
|
|
1007
|
+
const colEnd = getLastSelectCell(selectedCells.current).col;
|
|
1008
|
+
const startPasteRow = getLastSelectCell(selectedCells.current).row;
|
|
957
1009
|
const newPasteCells = new Set();
|
|
958
1010
|
for (let r = Math.min(startPasteRow, dataSource.length - 1) + 1; r <= Math.max(startPasteRow, dataSource.length - 1); r++) {
|
|
959
1011
|
for (let c = Math.min(colStart, colStart); c <= Math.max(colStart, colEnd); c++) {
|
|
960
1012
|
newPasteCells.add(`${r}-${c}`);
|
|
961
1013
|
}
|
|
962
1014
|
}
|
|
1015
|
+
hideDraggingPoint(selectedCells.current, id);
|
|
963
1016
|
triggerDragPaste(newPasteCells);
|
|
964
1017
|
};
|
|
965
1018
|
|
|
@@ -988,8 +1041,12 @@ const GridEdit = props => {
|
|
|
988
1041
|
startCell.current = null;
|
|
989
1042
|
isSelectingRow.current = false;
|
|
990
1043
|
rowStart.current = null;
|
|
1044
|
+
isDragMouse.current = false;
|
|
1045
|
+
isMouseDown.current = false;
|
|
991
1046
|
setIsPasteDragging(false);
|
|
992
|
-
|
|
1047
|
+
|
|
1048
|
+
// isPasteDragging.current = false
|
|
1049
|
+
// setSelectIsDragging(false);
|
|
993
1050
|
|
|
994
1051
|
// setCurrentCtrlCells(new Set())
|
|
995
1052
|
|
|
@@ -1000,10 +1057,33 @@ const GridEdit = props => {
|
|
|
1000
1057
|
|
|
1001
1058
|
// nếu ctrlCell length > 0 thì set selectCells
|
|
1002
1059
|
|
|
1003
|
-
if (pasteCells.size > 0) {
|
|
1004
|
-
triggerDragPaste(pasteCells);
|
|
1060
|
+
if (pasteCells && pasteCells.current.size > 0) {
|
|
1061
|
+
triggerDragPaste(pasteCells.current);
|
|
1062
|
+
} else {
|
|
1063
|
+
setRangeCells(selectedCells.current);
|
|
1064
|
+
onRemoveBorderSelectedCell(rangeCells, id);
|
|
1065
|
+
onAddBorderSelectedCell(selectedCells.current, id);
|
|
1066
|
+
const target = e.target;
|
|
1067
|
+
if (target.closest('.dragging-point')) {
|
|
1068
|
+
e.stopPropagation();
|
|
1069
|
+
e.preventDefault();
|
|
1070
|
+
return; // Không xử lý gì cả
|
|
1071
|
+
}
|
|
1072
|
+
if (selectedCells.current && selectedCells.current.size > 0) {
|
|
1073
|
+
hideDraggingPoint(selectedCells.current, id);
|
|
1074
|
+
}
|
|
1075
|
+
showDraggingPoint(selectedCells.current, id);
|
|
1005
1076
|
}
|
|
1006
1077
|
};
|
|
1078
|
+
|
|
1079
|
+
// const handlePointEnter = () => {
|
|
1080
|
+
// isPointEnter.current = true;
|
|
1081
|
+
// }
|
|
1082
|
+
//
|
|
1083
|
+
// const handlePointLeave = () => {
|
|
1084
|
+
// isPointEnter.current = false;
|
|
1085
|
+
// }
|
|
1086
|
+
|
|
1007
1087
|
const handleMouseEnter = (row, col, e) => {
|
|
1008
1088
|
if (!isSelecting.current || !startCell.current) {
|
|
1009
1089
|
return;
|
|
@@ -1027,29 +1107,41 @@ const GridEdit = props => {
|
|
|
1027
1107
|
if (!isPasteDragging) {
|
|
1028
1108
|
// chọn vùng copy
|
|
1029
1109
|
|
|
1030
|
-
setSelectIsDragging(true)
|
|
1110
|
+
// setSelectIsDragging(true)
|
|
1111
|
+
|
|
1031
1112
|
setIsPasteDragging(false);
|
|
1113
|
+
// isPasteDragging.current = false
|
|
1114
|
+
|
|
1032
1115
|
const newSelectedCells = new Set();
|
|
1033
1116
|
for (let r = Math.min(startRow, row); r <= Math.max(startRow, row); r++) {
|
|
1034
1117
|
for (let c = Math.min(startCol, col); c <= Math.max(startCol, col); c++) {
|
|
1035
1118
|
newSelectedCells.add(`${r}-${c}`);
|
|
1036
1119
|
}
|
|
1037
1120
|
}
|
|
1038
|
-
|
|
1121
|
+
|
|
1122
|
+
// setSelectedCells(newSelectedCells)
|
|
1123
|
+
|
|
1124
|
+
if (selectedCells.current && selectedCells.current.size > 0) {
|
|
1125
|
+
onRemoveBgSelectedCell(selectedCells.current, id);
|
|
1126
|
+
}
|
|
1127
|
+
selectedCells.current = newSelectedCells;
|
|
1128
|
+
onAddBgSelectedCell(newSelectedCells, id);
|
|
1039
1129
|
} else {
|
|
1040
1130
|
// chọn vùng paste
|
|
1041
1131
|
|
|
1042
|
-
setSelectIsDragging(false)
|
|
1043
|
-
|
|
1132
|
+
// setSelectIsDragging(false)
|
|
1133
|
+
|
|
1134
|
+
// setIsPasteDragging(true) ////////
|
|
1135
|
+
|
|
1044
1136
|
const newSelectedCells = new Set();
|
|
1045
1137
|
for (let r = Math.min(startRow, row); r <= Math.max(startRow, row); r++) {
|
|
1046
1138
|
for (let c = Math.min(startCol, col); c <= Math.max(startCol, col); c++) {
|
|
1047
1139
|
newSelectedCells.add(`${r}-${c}`);
|
|
1048
1140
|
}
|
|
1049
1141
|
}
|
|
1050
|
-
const colStart = getFirstSelectCell(selectedCells).col;
|
|
1051
|
-
const colEnd = getLastSelectCell(selectedCells).col;
|
|
1052
|
-
const rowSelectedEnd = getLastSelectCell(selectedCells).row;
|
|
1142
|
+
const colStart = getFirstSelectCell(selectedCells.current).col;
|
|
1143
|
+
const colEnd = getLastSelectCell(selectedCells.current).col;
|
|
1144
|
+
const rowSelectedEnd = getLastSelectCell(selectedCells.current).row;
|
|
1053
1145
|
if (row >= rowSelectedEnd) {
|
|
1054
1146
|
// kéo xuống dưới
|
|
1055
1147
|
|
|
@@ -1059,12 +1151,19 @@ const GridEdit = props => {
|
|
|
1059
1151
|
newPasteCells.add(`${r}-${c}`);
|
|
1060
1152
|
}
|
|
1061
1153
|
}
|
|
1062
|
-
|
|
1154
|
+
|
|
1155
|
+
// setPasteCells(newPasteCells)
|
|
1156
|
+
|
|
1157
|
+
if (pasteCells.current && pasteCells.current.size > 0) {
|
|
1158
|
+
removeClassBorderPasteCell(pasteCells.current, 'down', id);
|
|
1159
|
+
}
|
|
1160
|
+
pasteCells.current = newPasteCells;
|
|
1161
|
+
addClassBorderPasteCell(newPasteCells, 'down', id);
|
|
1063
1162
|
}
|
|
1064
1163
|
if (row < rowSelectedEnd) {
|
|
1065
1164
|
// kéo lên trên
|
|
1066
1165
|
|
|
1067
|
-
const rowSelectedStart = getFirstSelectCell(selectedCells).row;
|
|
1166
|
+
const rowSelectedStart = getFirstSelectCell(selectedCells.current).row;
|
|
1068
1167
|
if (row < rowSelectedStart) {
|
|
1069
1168
|
const newPasteCells = new Set();
|
|
1070
1169
|
for (let r = Math.min(rowSelectedStart, row); r <= Math.max(rowSelectedStart, row) - 1; r++) {
|
|
@@ -1072,7 +1171,14 @@ const GridEdit = props => {
|
|
|
1072
1171
|
newPasteCells.add(`${r}-${c}`);
|
|
1073
1172
|
}
|
|
1074
1173
|
}
|
|
1075
|
-
|
|
1174
|
+
|
|
1175
|
+
// setPasteCells(newPasteCells)
|
|
1176
|
+
|
|
1177
|
+
if (pasteCells.current && pasteCells.current.size > 0) {
|
|
1178
|
+
removeClassBorderPasteCell(pasteCells.current, 'up', id);
|
|
1179
|
+
}
|
|
1180
|
+
pasteCells.current = newPasteCells;
|
|
1181
|
+
addClassBorderPasteCell(newPasteCells, 'up', id);
|
|
1076
1182
|
}
|
|
1077
1183
|
}
|
|
1078
1184
|
if (col > colEnd) {
|
|
@@ -1083,16 +1189,32 @@ const GridEdit = props => {
|
|
|
1083
1189
|
}
|
|
1084
1190
|
}
|
|
1085
1191
|
};
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
}
|
|
1192
|
+
|
|
1193
|
+
// const handleClickRowHeader = (row: any, col: any) => {
|
|
1194
|
+
//
|
|
1195
|
+
// const newSelectedCells = new Set()
|
|
1196
|
+
//
|
|
1197
|
+
// const tCols = editAbleColumns(columns)
|
|
1198
|
+
//
|
|
1199
|
+
// for (let r = Math.min(row, row); r <= Math.max(row, row); r++) {
|
|
1200
|
+
// for (let c = Math.min(tCols.length, col) + 1; c <= Math.max(tCols.length, col); c++) {
|
|
1201
|
+
// newSelectedCells.add(`${r}-${c}`)
|
|
1202
|
+
// }
|
|
1203
|
+
// }
|
|
1204
|
+
//
|
|
1205
|
+
// // setSelectedCells(newSelectedCells)
|
|
1206
|
+
//
|
|
1207
|
+
// if (selectedCells.current && selectedCells.current.size > 0) {
|
|
1208
|
+
// onRemoveBgSelectedCell(selectedCells.current, id)
|
|
1209
|
+
// }
|
|
1210
|
+
//
|
|
1211
|
+
// selectedCells.current = newSelectedCells
|
|
1212
|
+
//
|
|
1213
|
+
// onAddBgSelectedCell(newSelectedCells, id)
|
|
1214
|
+
//
|
|
1215
|
+
//
|
|
1216
|
+
// };
|
|
1217
|
+
|
|
1096
1218
|
const handleClickColHeader = (column, indexColumn) => {
|
|
1097
1219
|
const newSelectedCells = new Set();
|
|
1098
1220
|
for (let r = Math.min(dataSource.length, 0); r <= Math.max(dataSource.length - 1, 0); r++) {
|
|
@@ -1100,9 +1222,23 @@ const GridEdit = props => {
|
|
|
1100
1222
|
newSelectedCells.add(`${r}-${c}`);
|
|
1101
1223
|
}
|
|
1102
1224
|
}
|
|
1103
|
-
|
|
1225
|
+
|
|
1226
|
+
// setSelectedCells(new Set(newSelectedCells));
|
|
1227
|
+
|
|
1228
|
+
if (selectedCells.current && selectedCells.current.size > 0) {
|
|
1229
|
+
onRemoveBgSelectedCell(selectedCells.current, id);
|
|
1230
|
+
onRemoveBorderSelectedCell(selectedCells.current, id);
|
|
1231
|
+
}
|
|
1232
|
+
if (rowsSelected.current && rowsSelected.current.size > 0) {
|
|
1233
|
+
removeClassCellIndexSelected(rowsSelected.current, id);
|
|
1234
|
+
}
|
|
1235
|
+
selectedCells.current = newSelectedCells;
|
|
1236
|
+
onAddBgSelectedCell(newSelectedCells, id);
|
|
1237
|
+
onAddBorderSelectedCell(newSelectedCells, id);
|
|
1238
|
+
hideDraggingPoint(selectedCells.current, id);
|
|
1239
|
+
showDraggingPoint(newSelectedCells, id);
|
|
1104
1240
|
};
|
|
1105
|
-
const
|
|
1241
|
+
const handleMouseDownRowHeader = (row, col, column, e) => {
|
|
1106
1242
|
if (e.button === 2) {
|
|
1107
1243
|
e.stopPropagation();
|
|
1108
1244
|
return;
|
|
@@ -1112,9 +1248,32 @@ const GridEdit = props => {
|
|
|
1112
1248
|
row,
|
|
1113
1249
|
col
|
|
1114
1250
|
};
|
|
1115
|
-
|
|
1251
|
+
const newSelectedCells = new Set();
|
|
1252
|
+
const tCols = editAbleColumns(columns);
|
|
1253
|
+
for (let r = Math.min(row, row); r <= Math.max(row, row); r++) {
|
|
1254
|
+
for (let c = Math.min(tCols.length, col) + 1; c <= Math.max(tCols.length, col); c++) {
|
|
1255
|
+
newSelectedCells.add(`${r}-${c}`);
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
// setSelectedCells(newSelectedCells)
|
|
1260
|
+
// setRowsSelected(new Set([`${row}-${col}`]));
|
|
1261
|
+
|
|
1262
|
+
if (selectedCells.current && selectedCells.current.size > 0) {
|
|
1263
|
+
onRemoveBgSelectedCell(selectedCells.current, id);
|
|
1264
|
+
onRemoveBorderSelectedCell(selectedCells.current, id);
|
|
1265
|
+
}
|
|
1266
|
+
if (rowsSelected.current && rowsSelected.current.size > 0) {
|
|
1267
|
+
removeClassCellIndexSelected(rowsSelected.current, id);
|
|
1268
|
+
}
|
|
1269
|
+
hideDraggingPoint(selectedCells.current, id);
|
|
1270
|
+
selectedCells.current = newSelectedCells;
|
|
1271
|
+
rowsSelected.current = new Set([`${row}-${col}`]);
|
|
1272
|
+
onAddBgSelectedCell(newSelectedCells, id);
|
|
1273
|
+
onAddBorderSelectedCell(newSelectedCells, id);
|
|
1274
|
+
addClassCellIndexSelected(new Set([`${row}-${col}`]), id);
|
|
1116
1275
|
};
|
|
1117
|
-
const
|
|
1276
|
+
const handleMouseEnterRowHeader = (row, col, e) => {
|
|
1118
1277
|
// dừng sự kiện kéo để chọn từ các column khác khi vừa gặp column index
|
|
1119
1278
|
if (isSelecting) {
|
|
1120
1279
|
startCell.current = null;
|
|
@@ -1138,8 +1297,18 @@ const GridEdit = props => {
|
|
|
1138
1297
|
newSelectedCells.add(`${r}-${c}`);
|
|
1139
1298
|
}
|
|
1140
1299
|
}
|
|
1141
|
-
|
|
1142
|
-
|
|
1300
|
+
if (selectedCells.current && selectedCells.current.size > 0) {
|
|
1301
|
+
onRemoveBgSelectedCell(selectedCells.current, id);
|
|
1302
|
+
}
|
|
1303
|
+
// setSelectedCells(newSelectedCells)
|
|
1304
|
+
selectedCells.current = newSelectedCells;
|
|
1305
|
+
onAddBgSelectedCell(newSelectedCells, id);
|
|
1306
|
+
if (rowsSelected.current && rowsSelected.current.size > 0) {
|
|
1307
|
+
removeClassCellIndexSelected(rowsSelected.current, id);
|
|
1308
|
+
}
|
|
1309
|
+
// setRowsSelected(newSelectedRows)
|
|
1310
|
+
rowsSelected.current = newSelectedRows;
|
|
1311
|
+
addClassCellIndexSelected(newSelectedRows, id);
|
|
1143
1312
|
};
|
|
1144
1313
|
const handleCellClick = (indexRow, record, column) => {
|
|
1145
1314
|
const cellClickCallback = newOptions => {
|
|
@@ -1169,7 +1338,7 @@ const GridEdit = props => {
|
|
|
1169
1338
|
}
|
|
1170
1339
|
};
|
|
1171
1340
|
const handleCopy = e => {
|
|
1172
|
-
const selectedArray = Array.from(selectedCells).map(key => {
|
|
1341
|
+
const selectedArray = Array.from(selectedCells.current).map(key => {
|
|
1173
1342
|
const [row, col] = key.split("-").map(Number);
|
|
1174
1343
|
// @ts-ignore
|
|
1175
1344
|
const columnKey = editAbleColumns(columns)[col - 1].field;
|
|
@@ -1511,9 +1680,6 @@ const GridEdit = props => {
|
|
|
1511
1680
|
indexRow,
|
|
1512
1681
|
key
|
|
1513
1682
|
} = args;
|
|
1514
|
-
|
|
1515
|
-
// const newRecord = getValues()
|
|
1516
|
-
|
|
1517
1683
|
if (changeType === 'enter') {}
|
|
1518
1684
|
if (changeType === 'blur') {
|
|
1519
1685
|
const handleChangeCallback = callbackData => {
|
|
@@ -1534,7 +1700,7 @@ const GridEdit = props => {
|
|
|
1534
1700
|
indexRow,
|
|
1535
1701
|
rowData: record,
|
|
1536
1702
|
rowId: key,
|
|
1537
|
-
rowsData: [],
|
|
1703
|
+
rowsData: [...dataSource],
|
|
1538
1704
|
sumValue: []
|
|
1539
1705
|
}, handleChangeCallback);
|
|
1540
1706
|
} else {
|
|
@@ -1547,7 +1713,7 @@ const GridEdit = props => {
|
|
|
1547
1713
|
indexRow,
|
|
1548
1714
|
rowData: record,
|
|
1549
1715
|
rowId: key,
|
|
1550
|
-
rowsData: [],
|
|
1716
|
+
rowsData: [...dataSource],
|
|
1551
1717
|
sumValue: []
|
|
1552
1718
|
}, handleChangeCallback);
|
|
1553
1719
|
onSubmit(record);
|
|
@@ -1580,35 +1746,17 @@ const GridEdit = props => {
|
|
|
1580
1746
|
// }
|
|
1581
1747
|
});
|
|
1582
1748
|
}
|
|
1583
|
-
|
|
1584
|
-
// columns.forEach(column => {
|
|
1585
|
-
//
|
|
1586
|
-
// const dateFormat = getDatepickerFormat(editType, column)
|
|
1587
|
-
//
|
|
1588
|
-
// // @ts-ignore
|
|
1589
|
-
// if ((column.editType === 'date' || column.editType === 'datetime') && record[column.dataIndex]) {
|
|
1590
|
-
//
|
|
1591
|
-
// // @ts-ignore
|
|
1592
|
-
// formattedRecord[column.dataIndex] = !isEmpty(record[column.dataIndex]) ? convertDateToDayjs(new Date(record[column.dataIndex]), dateFormat) : null
|
|
1593
|
-
// }
|
|
1594
|
-
//
|
|
1595
|
-
// });
|
|
1596
|
-
|
|
1597
1749
|
if (e.key === 'Enter' || editType === 'date' || e.type === 'dblclick') {} else {
|
|
1598
1750
|
setValue(col.dataIndex, editType === 'numeric' ? !isNaN(Number(e.key)) ? Number(e.key) : '' : e.key);
|
|
1599
|
-
// setValue(col.dataIndex, e.key)
|
|
1600
1751
|
}
|
|
1601
1752
|
if (editType === 'select') {
|
|
1602
1753
|
// setSearchValue(e.key)
|
|
1603
1754
|
// setOpen(true)
|
|
1604
1755
|
}
|
|
1605
|
-
if (startSelectedCells
|
|
1756
|
+
if (startSelectedCells.current && startSelectedCells.current.row !== undefined && startSelectedCells.current.col !== undefined) {
|
|
1606
1757
|
setTimeout(() => {
|
|
1607
|
-
|
|
1608
|
-
const
|
|
1609
|
-
// const input = document.getElementById(`col${selectedCell.col}-record${selectedCell.row}`) as HTMLInputElement;
|
|
1610
|
-
|
|
1611
|
-
const select = document.querySelector(`div.cell-editing[tabindex="${startSelectedCells?.col}"] .ant-select-selection-search input`);
|
|
1758
|
+
const input = document.querySelector(`.ui-rc-table-row .cell-editing[data-row-index="${startSelectedCells.current.row}"].cell-editing[data-col-index="${startSelectedCells.current.col}"] input`);
|
|
1759
|
+
const select = document.querySelector(`div.cell-editing[tabindex="${startSelectedCells.current.col}"] .ant-select-selection-search input`);
|
|
1612
1760
|
if (input) {
|
|
1613
1761
|
input.focus();
|
|
1614
1762
|
}
|
|
@@ -1660,11 +1808,25 @@ const GridEdit = props => {
|
|
|
1660
1808
|
const cellEdit = document.querySelector(`.ui-rc-table-row .cell-editing[data-row-index="${rowIndex}"].cell-editing[data-col-index="${colIndex}"]`);
|
|
1661
1809
|
const cell = document.querySelector(`.ui-rc-table-row .cell-editable[data-row-index="${rowIndex}"].cell-editable[data-col-index="${colIndex}"]`);
|
|
1662
1810
|
const updateSelection = () => {
|
|
1663
|
-
setStartSelectedCell({
|
|
1811
|
+
// setStartSelectedCell({ row: rowIndex, col: colIndex });
|
|
1812
|
+
startSelectedCells.current = {
|
|
1664
1813
|
row: rowIndex,
|
|
1665
1814
|
col: colIndex
|
|
1666
|
-
}
|
|
1667
|
-
setSelectedCells(new Set([`${rowIndex}-${colIndex}`]));
|
|
1815
|
+
};
|
|
1816
|
+
// setSelectedCells(new Set([`${rowIndex}-${colIndex}`]));
|
|
1817
|
+
|
|
1818
|
+
const cells = new Set([`${rowIndex}-${colIndex}`]);
|
|
1819
|
+
if (selectedCells.current && selectedCells.current.size > 0) {
|
|
1820
|
+
onRemoveBgSelectedCell(selectedCells.current, id);
|
|
1821
|
+
onRemoveBorderSelectedCell(selectedCells.current, id);
|
|
1822
|
+
}
|
|
1823
|
+
hideDraggingPoint(selectedCells.current, id);
|
|
1824
|
+
selectedCells.current = cells;
|
|
1825
|
+
setTimeout(() => {
|
|
1826
|
+
onAddBgSelectedCell(selectedCells.current, id);
|
|
1827
|
+
onAddBorderSelectedCell(selectedCells.current, id);
|
|
1828
|
+
}, 50);
|
|
1829
|
+
showDraggingPoint(cells, id);
|
|
1668
1830
|
};
|
|
1669
1831
|
const focusNextCell = (editingCell, cellEditable) => {
|
|
1670
1832
|
if (isEdit) {
|
|
@@ -1711,62 +1873,18 @@ const GridEdit = props => {
|
|
|
1711
1873
|
focusNextCell(cellEdit, cell);
|
|
1712
1874
|
}
|
|
1713
1875
|
};
|
|
1714
|
-
const getCellClass = (record, rowIndex, colIndex) => {
|
|
1715
|
-
const cellKey = `${rowIndex}-${colIndex}`;
|
|
1716
|
-
const topCellKey = `${rowIndex + 1}-${colIndex}`;
|
|
1717
|
-
const leftCellKey = `${rowIndex}-${colIndex + 1}`;
|
|
1718
|
-
const rightCellKey = `${rowIndex}-${colIndex - 1}`;
|
|
1719
|
-
const isSelected = selectedCells.has(cellKey);
|
|
1720
|
-
const isTopSelected = selectedCells.has(topCellKey);
|
|
1721
|
-
const isLeftSelected = selectedCells.has(leftCellKey);
|
|
1722
|
-
const isRightSelected = selectedCells.has(rightCellKey);
|
|
1723
|
-
const topPasteCellKey = `${rowIndex + 1}-${colIndex}`;
|
|
1724
|
-
const isPasteSelected = pasteCells.has(cellKey);
|
|
1725
|
-
const isPasteTopSelected = pasteCells.has(topPasteCellKey);
|
|
1726
|
-
const isPasteLeftSelected = pasteCells.has(leftCellKey);
|
|
1727
|
-
const isPasteRightSelected = pasteCells.has(rightCellKey);
|
|
1728
|
-
const cellClass = isEditing(record) ? 'rc-ui-cell-editable cell-editing' : 'rc-ui-cell-editable cell-editable';
|
|
1729
|
-
const prevRecordEditing = flattenData(childrenColumnName, dataSource)[rowIndex + 1];
|
|
1730
|
-
const cellStart = getFirstSelectCell(selectedCells);
|
|
1731
|
-
const cellEnd = getLastSelectCell(selectedCells);
|
|
1732
|
-
const cellPasteStart = getFirstSelectCell(pasteCells);
|
|
1733
|
-
const cellPasteSEnd = getLastSelectCell(pasteCells);
|
|
1734
|
-
const isPasteBottom = cellPasteSEnd.row > cellStart.row && pasteCells.size && cellPasteSEnd && rowIndex === Math.max(cellPasteStart.row, cellPasteSEnd.row);
|
|
1735
|
-
|
|
1736
|
-
// const rowSelectedFirst = getFirstSelectCell(selectedCells).row
|
|
1737
|
-
// const rowPasteLast = getLastSelectCell(pasteCells).row
|
|
1738
|
-
|
|
1739
|
-
if (!isSelected && !isPasteSelected) {
|
|
1740
|
-
// const isTop = prevRecordEditing && !isEditing(prevRecordEditing) && rowIndex === Math.min(cellStart.row - 1, cellEnd?.row);
|
|
1741
|
-
const isTop = prevRecordEditing && !isEditing(prevRecordEditing) && isTopMostInRegion(rowIndex + 1, colIndex, selectedCells);
|
|
1742
|
-
const isLeft = colIndex + 1 === Math.min(cellStart.col, cellEnd?.col);
|
|
1743
|
-
const isRight = colIndex - 1 === Math.max(cellStart.col, cellEnd?.col);
|
|
1744
|
-
const isPasteTop = cellPasteSEnd.row < cellStart.row && isTopMostInRegion(rowIndex + 1, colIndex, pasteCells);
|
|
1745
|
-
const isPasteLeft = colIndex + 1 === Math.min(cellPasteStart.col, cellPasteSEnd?.col);
|
|
1746
|
-
const isPasteRight = colIndex - 1 === Math.max(cellPasteStart.col, cellPasteSEnd?.col);
|
|
1747
|
-
return isTopSelected || isLeftSelected || isRightSelected ? `${cellClass} ${isTop ? `cell-border-top` : ''} ${isLeft ? `cell-border-left` : ''} ${isPasteBottom ? `cell-paste-border-bottom` : ''} ${isRight ? `next-cell-border-left` : ''}` : isPasteLeftSelected || isPasteRightSelected || isPasteTopSelected ? `${cellClass} ${isPasteLeft ? `cell-paste-border-left` : ''} ${isPasteRight ? `next-cell-paste-border-left` : ''} ${isPasteTop ? `cell-paste-border-top` : ''}` : cellClass;
|
|
1748
|
-
}
|
|
1749
|
-
const isBottom = isBottomMostInRegion(rowIndex, colIndex, selectedCells);
|
|
1750
|
-
// const isBottom = isBottomMostInRanges(rowIndex, colIndex, [selectedCells, ...ctrlCells])
|
|
1751
|
-
|
|
1752
|
-
// const isRight = cellEnd && colIndex === Math.max(cellStart.col, cellEnd.col)
|
|
1753
|
-
const isRight = isRightMostInRegion(rowIndex, colIndex, selectedCells);
|
|
1754
|
-
const isLeft = colIndex === Math.min(cellStart.col, cellEnd?.col);
|
|
1755
|
-
const isPasteRight = cellPasteSEnd && colIndex === Math.max(cellPasteStart.col, cellPasteSEnd.col);
|
|
1756
|
-
const isPasteLeft = colIndex === Math.min(cellPasteStart.col, cellPasteSEnd?.col);
|
|
1757
|
-
return `${cellClass} ${isPasteBottom ? `cell-paste-border-bottom` : ''} ${isPasteSelected && isPasteRight ? `cell-paste-border-right` : ''} ${isPasteSelected && isPasteLeft ? `fixed-cell-paste-border-left` : ''} ${isBottom ? `cell-border-bottom` : ''} ${isRight ? `cell-border-right` : ''} ${isLeft ? `fixed-cell-border-left` : ''} ${isBottom && isRight ? `cell-border-end` : ''}`;
|
|
1758
|
-
};
|
|
1759
1876
|
const convertColumns = flatColumns2(columns.filter(it => it.visible !== false)).map((column, colIndex) => {
|
|
1760
1877
|
if (!column?.field && !column?.key) {
|
|
1761
1878
|
return column;
|
|
1762
1879
|
}
|
|
1763
|
-
if (column.dataIndex === '
|
|
1880
|
+
if (column.dataIndex === '#' || column.dataIndex === '#') {
|
|
1764
1881
|
return {
|
|
1765
1882
|
...column,
|
|
1766
|
-
className: 'rc-ui-cell-editable',
|
|
1883
|
+
className: 'rc-ui-cell-editable rc-ui-cell-index',
|
|
1767
1884
|
onCell: (record, rowIndex) => {
|
|
1768
1885
|
const rowNumber = getRowNumber(dataSource, record[rowKey], rowKey);
|
|
1769
1886
|
return {
|
|
1887
|
+
'data-row-index': rowNumber,
|
|
1770
1888
|
onPaste: event => {
|
|
1771
1889
|
if (editingKey === '') {
|
|
1772
1890
|
handlePaste(record, colIndex + 1, rowNumber, event);
|
|
@@ -1790,13 +1908,9 @@ const GridEdit = props => {
|
|
|
1790
1908
|
render: (value, record) => {
|
|
1791
1909
|
const rowNumber = getRowNumber(dataSource, record[rowKey], rowKey);
|
|
1792
1910
|
return /*#__PURE__*/React.createElement("div", {
|
|
1793
|
-
className: classNames('ui-rc_cell-content ui-rc_cell-content--index', {
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
}),
|
|
1797
|
-
onMouseDown: event => handleMouseDownColIndex(rowNumber, colIndex, event),
|
|
1798
|
-
onMouseEnter: event => handleMouseEnterColIndex(rowNumber, colIndex, event),
|
|
1799
|
-
onClick: () => handleClickRowHeader(rowNumber, colIndex),
|
|
1911
|
+
className: classNames('ui-rc_cell-content ui-rc_cell-content--index', {}),
|
|
1912
|
+
onMouseDown: event => handleMouseDownRowHeader(rowNumber, colIndex, column, event),
|
|
1913
|
+
onMouseEnter: event => handleMouseEnterRowHeader(rowNumber, colIndex, event),
|
|
1800
1914
|
onMouseUp: handleMouseUp
|
|
1801
1915
|
}, /*#__PURE__*/React.createElement("div", {
|
|
1802
1916
|
className: 'ui-rc_content'
|
|
@@ -1816,16 +1930,16 @@ const GridEdit = props => {
|
|
|
1816
1930
|
return {
|
|
1817
1931
|
onKeyDown: event => {
|
|
1818
1932
|
const key = getRowKey(record, dataSource.indexOf(record));
|
|
1819
|
-
if (event.key === 'Control' && event.ctrlKey) {
|
|
1820
|
-
|
|
1821
|
-
// setIsCtrlDown(true)
|
|
1822
|
-
} else {
|
|
1933
|
+
if (event.key === 'Control' && event.ctrlKey) {} else {
|
|
1823
1934
|
if (event.key.length === 1 && !event.ctrlKey && !event.metaKey || event.key === 'Enter') {
|
|
1824
1935
|
if (record[rowKey] !== editingKey && isEditable(column, record)) {
|
|
1825
1936
|
// ~~ khi editingKey = ''
|
|
1826
1937
|
event.preventDefault();
|
|
1827
1938
|
event.stopPropagation();
|
|
1828
1939
|
handleEdit(record, column, column.editType, event);
|
|
1940
|
+
onRemoveBgSelectedCell(selectedCells.current, id);
|
|
1941
|
+
onRemoveBorderSelectedCell(selectedCells.current, id);
|
|
1942
|
+
selectedCells.current = new Set();
|
|
1829
1943
|
handleCellClick(rowNumber, record, column);
|
|
1830
1944
|
const hasKey = mergedExpandedKeys.has(key);
|
|
1831
1945
|
if (hasKey) {
|
|
@@ -1867,7 +1981,7 @@ const GridEdit = props => {
|
|
|
1867
1981
|
}
|
|
1868
1982
|
}
|
|
1869
1983
|
if (event.key === 'ArrowLeft' && colIndex > 0) {
|
|
1870
|
-
if (!column.dataIndex && !column.key || column.field === '
|
|
1984
|
+
if (!column.dataIndex && !column.key || column.field === '#' || column.dataIndex === '#') {
|
|
1871
1985
|
event.stopPropagation();
|
|
1872
1986
|
event.preventDefault();
|
|
1873
1987
|
} else {
|
|
@@ -1898,13 +2012,6 @@ const GridEdit = props => {
|
|
|
1898
2012
|
}
|
|
1899
2013
|
}
|
|
1900
2014
|
},
|
|
1901
|
-
// onKeyUp: (event: any) => {
|
|
1902
|
-
// if (event.key === 'Control' && event.ctrlKey) {
|
|
1903
|
-
//
|
|
1904
|
-
// console.log('onKeyUp')
|
|
1905
|
-
// }
|
|
1906
|
-
// },
|
|
1907
|
-
|
|
1908
2015
|
onPaste: event => {
|
|
1909
2016
|
if (editingKey === '') {
|
|
1910
2017
|
handlePaste(record, colIndex, rowNumber, event);
|
|
@@ -1920,6 +2027,8 @@ const GridEdit = props => {
|
|
|
1920
2027
|
onDoubleClick: event => {
|
|
1921
2028
|
if (!isEditing(record) && record[rowKey] !== editingKey && isEditable(column, record)) {
|
|
1922
2029
|
handleEdit(record, column, getEditType(column, record), event);
|
|
2030
|
+
onRemoveBgSelectedCell(selectedCells.current, id);
|
|
2031
|
+
onRemoveBorderSelectedCell(selectedCells.current, id);
|
|
1923
2032
|
handleCellClick(rowNumber, record, column);
|
|
1924
2033
|
}
|
|
1925
2034
|
},
|
|
@@ -1928,12 +2037,15 @@ const GridEdit = props => {
|
|
|
1928
2037
|
// startCell.current = { row: rowNumber, col: colIndex };
|
|
1929
2038
|
|
|
1930
2039
|
if (selectedCells.size === 0) {
|
|
1931
|
-
setStartSelectedCell({
|
|
2040
|
+
// setStartSelectedCell({ row: rowNumber, col: colIndex })
|
|
2041
|
+
// setSelectedCells(new Set([`${rowNumber}-${colIndex}`]));
|
|
2042
|
+
|
|
2043
|
+
startSelectedCells.current = {
|
|
1932
2044
|
row: rowNumber,
|
|
1933
2045
|
col: colIndex
|
|
1934
|
-
}
|
|
1935
|
-
|
|
1936
|
-
|
|
2046
|
+
};
|
|
2047
|
+
selectedCells.current = new Set([`${rowNumber}-${colIndex}`]);
|
|
2048
|
+
rowsSelected.current = new Set();
|
|
1937
2049
|
}
|
|
1938
2050
|
},
|
|
1939
2051
|
onClick: () => {
|
|
@@ -1941,12 +2053,13 @@ const GridEdit = props => {
|
|
|
1941
2053
|
setEditingKey('');
|
|
1942
2054
|
}
|
|
1943
2055
|
},
|
|
1944
|
-
|
|
1945
|
-
className: getCellClass(record, rowNumber, colIndex),
|
|
2056
|
+
className: isEditing(record) ? 'rc-ui-cell-editable cell-editing' : `rc-ui-cell-editable cell-editable ${!isEditable(column, record) ? 'disable' : ''}`,
|
|
1946
2057
|
record,
|
|
1947
2058
|
column: column,
|
|
1948
2059
|
editType: getEditType(column, record),
|
|
1949
2060
|
dataIndex: column.dataIndex,
|
|
2061
|
+
indexRow: rowNumber,
|
|
2062
|
+
indexCol: colIndex,
|
|
1950
2063
|
title: getValueCell(column, record[column.field], format),
|
|
1951
2064
|
'data-col-index': colIndex,
|
|
1952
2065
|
'data-row-index': rowNumber,
|
|
@@ -1957,7 +2070,6 @@ const GridEdit = props => {
|
|
|
1957
2070
|
editing: isEditing(record) && rowEditable?.(record) !== false && isEditable(column, record),
|
|
1958
2071
|
cellEditing,
|
|
1959
2072
|
t,
|
|
1960
|
-
// editing: isEditing(record) && rowEditable?.(record) !== false,
|
|
1961
2073
|
tabIndex: (rowIndex ?? 0) * columns.length + colIndex,
|
|
1962
2074
|
style: isPasteDragging ? {
|
|
1963
2075
|
cursor: "crosshair"
|
|
@@ -1991,14 +2103,18 @@ const GridEdit = props => {
|
|
|
1991
2103
|
const rowNumber = getRowNumber(dataSource, record[rowKey], rowKey);
|
|
1992
2104
|
return /*#__PURE__*/React.createElement("div", {
|
|
1993
2105
|
className: classNames('ui-rc_cell-content', {
|
|
1994
|
-
//
|
|
1995
|
-
// selected: selectedCells.has(`${rowNumber}-${colIndex}`) || currentCtrlCells.has(`${rowNumber}-${colIndex}`) || mergedSets([selectedCells, ...ctrlCells]).has(`${rowNumber}-${colIndex}`),
|
|
1996
|
-
selected: selectedCells.has(`${rowNumber}-${colIndex}`),
|
|
1997
|
-
disable: !isEditable(column, record)
|
|
2106
|
+
// disable: !isEditable(column as any, record)
|
|
1998
2107
|
}),
|
|
1999
2108
|
onMouseDown: event => handleMouseDown(record, rowNumber, colIndex, event),
|
|
2000
2109
|
onMouseEnter: event => handleMouseEnter(rowNumber, colIndex, event),
|
|
2001
|
-
onMouseUp: handleMouseUp
|
|
2110
|
+
onMouseUp: handleMouseUp,
|
|
2111
|
+
onMouseMove: () => {
|
|
2112
|
+
if (selectedCells && selectedCells.current.size > 0 && isMouseDown.current) {
|
|
2113
|
+
hideDraggingPoint(selectedCells.current, id);
|
|
2114
|
+
isDragMouse.current = true;
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2117
|
+
|
|
2002
2118
|
// onClick={(event) => {
|
|
2003
2119
|
//
|
|
2004
2120
|
// handleClickCell(event)
|
|
@@ -2006,18 +2122,19 @@ const GridEdit = props => {
|
|
|
2006
2122
|
// }}
|
|
2007
2123
|
}, /*#__PURE__*/React.createElement("div", {
|
|
2008
2124
|
className: 'ui-rc_content'
|
|
2009
|
-
}, renderContent(column, value, record, rowIndex, format
|
|
2010
|
-
|
|
2011
|
-
//
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
,
|
|
2125
|
+
}, renderContent(column, value, record, rowIndex, column.format ? typeof column.format === 'function' ? column.format(record) : column.format : format)),
|
|
2126
|
+
// selectedCells.current && selectedCells.current.size > 0 && getLastSelectCell(selectedCells.current).row === rowNumber &&
|
|
2127
|
+
// getLastSelectCell(selectedCells.current).col === colIndex &&
|
|
2128
|
+
// isEditable(column as any, record) &&
|
|
2129
|
+
|
|
2130
|
+
!isDragMouse.current && /*#__PURE__*/React.createElement("div", {
|
|
2131
|
+
className: 'dragging-point hidden',
|
|
2017
2132
|
onMouseDown: e => {
|
|
2018
2133
|
// e.stopPropagation()
|
|
2019
2134
|
e.preventDefault();
|
|
2020
|
-
|
|
2135
|
+
if (e.button === 0) {
|
|
2136
|
+
setIsPasteDragging(true);
|
|
2137
|
+
}
|
|
2021
2138
|
},
|
|
2022
2139
|
onDoubleClick: handlePointDoubleClick
|
|
2023
2140
|
}, /*#__PURE__*/React.createElement("span", {
|
|
@@ -2071,9 +2188,6 @@ const GridEdit = props => {
|
|
|
2071
2188
|
}
|
|
2072
2189
|
}));
|
|
2073
2190
|
};
|
|
2074
|
-
const onSelectChange = keys => {
|
|
2075
|
-
setMergedSelectedKeys(keys);
|
|
2076
|
-
};
|
|
2077
2191
|
const contextMenuClick = args => {
|
|
2078
2192
|
if (args.item?.parentKey && args.item.parentKey === 'INSERT_BEFORE') {
|
|
2079
2193
|
if (args.item.key === 'INSERT_BEFORE_ADV') {
|
|
@@ -2131,12 +2245,11 @@ const GridEdit = props => {
|
|
|
2131
2245
|
setRowsAdd(val);
|
|
2132
2246
|
};
|
|
2133
2247
|
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(GridStyle, {
|
|
2134
|
-
heightTable: height,
|
|
2248
|
+
$heightTable: height,
|
|
2135
2249
|
style: {
|
|
2136
2250
|
position: 'relative'
|
|
2137
2251
|
},
|
|
2138
2252
|
ref: ref
|
|
2139
|
-
// onMouseUp={handleMouseUp}
|
|
2140
2253
|
}, /*#__PURE__*/React.createElement(TableContext.Provider, {
|
|
2141
2254
|
value: {
|
|
2142
2255
|
rowKey,
|
|
@@ -2176,9 +2289,7 @@ const GridEdit = props => {
|
|
|
2176
2289
|
components: {
|
|
2177
2290
|
...components,
|
|
2178
2291
|
body: {
|
|
2179
|
-
// wrapper: () => <div></div>,
|
|
2180
2292
|
cell: EditableCell
|
|
2181
|
-
// cell: () => <EditableCell />,
|
|
2182
2293
|
}
|
|
2183
2294
|
},
|
|
2184
2295
|
className: classNames(className, 'grid-editable'),
|
|
@@ -2194,9 +2305,11 @@ const GridEdit = props => {
|
|
|
2194
2305
|
,
|
|
2195
2306
|
selectionSettings: selectionSettings ? {
|
|
2196
2307
|
...selectionSettings,
|
|
2197
|
-
checkboxOnly: true
|
|
2308
|
+
checkboxOnly: true,
|
|
2309
|
+
arrowKey: false
|
|
2198
2310
|
} : {
|
|
2199
|
-
checkboxOnly: true
|
|
2311
|
+
checkboxOnly: true,
|
|
2312
|
+
arrowKey: false
|
|
2200
2313
|
},
|
|
2201
2314
|
rowHoverable: false,
|
|
2202
2315
|
bottomToolbar: bottomToolbar,
|
|
@@ -2238,25 +2351,27 @@ const GridEdit = props => {
|
|
|
2238
2351
|
},
|
|
2239
2352
|
triggerChangeColumns: triggerChangeColumns,
|
|
2240
2353
|
clickHeaderToSort: false,
|
|
2241
|
-
rowSelection: columns && columns.length === 0 ? undefined : {
|
|
2242
|
-
type: mode === 'checkbox' || type === 'multiple' ? 'checkbox' : "radio",
|
|
2243
|
-
columnWidth: !mode ? 0.0000001 : columnWidth ?? 50,
|
|
2244
|
-
onChange: onSelectChange,
|
|
2245
|
-
selectedRowKeys: mergedSelectedKeys,
|
|
2246
|
-
preserveSelectedRowKeys: true
|
|
2247
|
-
},
|
|
2248
2354
|
isFilter: isFilter,
|
|
2249
2355
|
setIsFilter: setIsFilter,
|
|
2250
2356
|
contextMenuItems: contextMenuItems,
|
|
2251
|
-
contextMenuClick: contextMenuClick
|
|
2357
|
+
contextMenuClick: contextMenuClick,
|
|
2358
|
+
onScroll: () => {
|
|
2359
|
+
if (selectedCells.current && selectedCells.current.size > 0) {
|
|
2360
|
+
onAddBgSelectedCell(selectedCells.current, id);
|
|
2361
|
+
onAddBorderSelectedCell(selectedCells.current, id);
|
|
2362
|
+
showDraggingPoint(selectedCells.current, id);
|
|
2363
|
+
}
|
|
2364
|
+
if (rowsSelected && rowsSelected.current.size > 0) {
|
|
2365
|
+
addClassCellIndexSelected(rowsSelected.current, id);
|
|
2366
|
+
}
|
|
2367
|
+
}
|
|
2252
2368
|
})))))), /*#__PURE__*/React.createElement(Toaster, {
|
|
2253
2369
|
position: toast,
|
|
2254
2370
|
toastOptions: {
|
|
2255
2371
|
className: 'react-hot-toast'
|
|
2256
2372
|
}
|
|
2257
|
-
}), /*#__PURE__*/React.createElement(Modal
|
|
2258
|
-
|
|
2259
|
-
, {
|
|
2373
|
+
}), /*#__PURE__*/React.createElement(Modal, {
|
|
2374
|
+
title: "Th\xEAm d\xF2ng",
|
|
2260
2375
|
open: openModalAddRow.open,
|
|
2261
2376
|
onOk: onOkAddRow,
|
|
2262
2377
|
onCancel: hideModalAddRow,
|