es-grid-template 1.4.3 → 1.4.5

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.
@@ -14,12 +14,17 @@ import dayjs from "dayjs";
14
14
  import 'dayjs/locale/es';
15
15
  import 'dayjs/locale/vi';
16
16
  import TableGrid from "../TableGrid";
17
- 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, getFormat } from "../hooks";
17
+ import { addClassBorderPasteCell, addClassCellIndexSelected, addRows8, addRowsUp, checkChild, editAbleColumns, findAllChildrenKeys, findItemByKey, findItemPath, flattenArray, flattenData, getDefaultValue, getEditType, getFirstSelectCell, getLastSelectCell, getRowNumber, getRowsPasteIndex, hideDraggingPoint, isEditable, isEqualSet, isObjEmpty, newGuid, onAddBgSelectedCell,
18
+ // onRemoveBorderSelectedCell,
19
+ onRemoveBgSelectedCell, removeClassBorderPasteCell, removeClassCellIndexSelected, showDraggingPoint, sortedSetASC, totalFixedWidth, updateArrayByKey, getFormat,
20
+ // isRangeCell,
21
+ // isSelectedCell,
22
+ onRemoveBgCellIndex, onAddBgCellIndex, onAddBorderSelectedCell, onRemoveBorderSelectedCell } from "../hooks";
18
23
  import Message from "../../Message/Message";
19
24
  import { Toolbar, ConfigProvider, InputNumber } from "rc-master-ui";
20
25
  import classnames from "classnames";
21
26
  import { Plus, Trash2 } from "becoxy-icons";
22
- import { faker } from "@faker-js/faker";
27
+ // import {faker} from "@faker-js/faker";
23
28
  import { SELECTION_COLUMN } from "../InternalTable";
24
29
  const {
25
30
  Paragraph,
@@ -173,7 +178,7 @@ const validateData = async (data, formSchema) => {
173
178
  };
174
179
  const GridEdit = props => {
175
180
  const {
176
- id: tableId,
181
+ id,
177
182
  tableRef,
178
183
  t,
179
184
  columns,
@@ -183,6 +188,7 @@ const GridEdit = props => {
183
188
  rowKey = 'id',
184
189
  selectionSettings,
185
190
  height,
191
+ scrollHeight,
186
192
  format,
187
193
  triggerChangeData,
188
194
  triggerChangeColumns,
@@ -224,20 +230,143 @@ const GridEdit = props => {
224
230
  const visibleCols = React.useMemo(() => {
225
231
  return flatColumns2(columns.filter(it => it.visible !== false));
226
232
  }, [columns]);
227
- const id = React.useMemo(() => {
228
- return tableId ?? faker.string.alpha(20);
229
- // return tableId ?? newGuid()
230
- }, [tableId]);
231
- const itemsAdd = [{
232
- key: '10',
233
- label: '10 rows'
234
- }, {
235
- key: '50',
236
- label: '50 rows'
237
- }, {
238
- key: '100',
239
- label: '100 rows'
240
- }];
233
+
234
+ // const id = React.useMemo(() => {
235
+ //
236
+ // return tableId ?? faker.string.alpha(20)
237
+ // // return tableId ?? newGuid()
238
+ //
239
+ // }, [tableId])
240
+
241
+ const itemsAdd = React.useMemo(() => {
242
+ return [{
243
+ key: '10',
244
+ label: `10 ${t ? t('rows') : 'rows'}`
245
+ }, {
246
+ key: '50',
247
+ label: `50 ${t ? t('rows') : 'rows'}`
248
+ }, {
249
+ key: '100',
250
+ label: `100 ${t ? t('rows') : 'rows'}`
251
+ }];
252
+ }, [t]);
253
+
254
+ // const defaultContext = React.useMemo(() => {
255
+ // return [
256
+ // {
257
+ // key: 'INSERT_BEFORE',
258
+ // label: 'Thêm dòng bên trên',
259
+ // icon: <Plus fontSize={14} />,
260
+ // children: [
261
+ // {
262
+ // parentKey: 'INSERT_BEFORE',
263
+ // key: 'INSERT_BEFORE_1',
264
+ // label: 'Thêm 1 dòng',
265
+ // row: 1
266
+ // },
267
+ // {
268
+ // parentKey: 'INSERT_BEFORE',
269
+ // key: 'INSERT_BEFORE_10',
270
+ // label: 'Thêm 10 dòng',
271
+ // row: 10
272
+ // },
273
+ // {
274
+ // parentKey: 'INSERT_BEFORE',
275
+ // key: 'INSERT_BEFORE_50',
276
+ // label: 'Thêm 50 dòng',
277
+ // row: 50
278
+ // },
279
+ // {
280
+ // parentKey: 'INSERT_BEFORE',
281
+ // key: 'INSERT_BEFORE_100',
282
+ // label: 'Thêm 100 dòng',
283
+ // row: 100
284
+ // },
285
+ // {
286
+ // parentKey: 'INSERT_BEFORE',
287
+ // key: 'INSERT_BEFORE_ADV',
288
+ // label: 'Tùy chỉnh'
289
+ // }
290
+ // ]
291
+ // },
292
+ // {
293
+ // key: 'INSERT_AFTER',
294
+ // label: 'Thêm dòng bên dưới',
295
+ // icon: <Plus fontSize={14} />,
296
+ // children: [
297
+ // {
298
+ // parentKey: 'INSERT_AFTER',
299
+ // key: 'INSERT_AFTER_1',
300
+ // label: 'Thêm 1 dòng',
301
+ // row: 1
302
+ // },
303
+ // {
304
+ // parentKey: 'INSERT_AFTER',
305
+ // key: 'INSERT_AFTER_10',
306
+ // label: 'Thêm 10 dòng',
307
+ // row: 10
308
+ // },
309
+ // {
310
+ // parentKey: 'INSERT_AFTER',
311
+ // key: 'INSERT_AFTER_50',
312
+ // label: 'Thêm 50 dòng',
313
+ // row: 50
314
+ // },
315
+ // {
316
+ // parentKey: 'INSERT_AFTER',
317
+ // key: 'INSERT_AFTER_100',
318
+ // label: 'Thêm 100 dòng',
319
+ // row: 100
320
+ // },
321
+ // {
322
+ // parentKey: 'INSERT_AFTER',
323
+ // key: 'INSERT_AFTER_ADV',
324
+ // label: 'Tùy chỉnh'
325
+ // }
326
+ // ]
327
+ // },
328
+ // {
329
+ // key: 'INSERT_CHILDREN',
330
+ // // label: 'Insert item children',
331
+ // label: 'Thêm cấp con',
332
+ // icon: <Plus fontSize={14} />
333
+ // // children: [
334
+ // // {
335
+ // // parentKey: 'INSERT_AFTER',
336
+ // // key: 'INSERT_AFTER_1',
337
+ // // label: 'Thêm 1 dòng',
338
+ // // row: 1
339
+ // // },
340
+ // // {
341
+ // // parentKey: 'INSERT_AFTER',
342
+ // // key: 'INSERT_AFTER_10',
343
+ // // label: 'Thêm 10 dòng',
344
+ // // row: 10
345
+ // // },
346
+ // // {
347
+ // // parentKey: 'INSERT_AFTER',
348
+ // // key: 'INSERT_AFTER_50',
349
+ // // label: 'Thêm 50 dòng',
350
+ // // row: 50
351
+ // // },
352
+ // // {
353
+ // // parentKey: 'INSERT_AFTER',
354
+ // // key: 'INSERT_AFTER_100',
355
+ // // label: 'Thêm 100 dòng',
356
+ // // row: 100
357
+ // // },
358
+ // // {
359
+ // // parentKey: 'INSERT_AFTER',
360
+ // // key: 'INSERT_AFTER_ADV',
361
+ // // label: 'Tùy chỉnh'
362
+ // // }
363
+ // // ]
364
+ // },
365
+ // { key: 'DELETE_CONTENT', label: 'Xóa nội dung', icon: <Trash2 fontSize={14} /> },
366
+ // { key: 'DELETE_ROWS', label: 'Xóa dòng', icon: <Trash2 fontSize={14} /> }
367
+ // ]
368
+ // }, [])
369
+
241
370
  const [form] = Form.useForm();
242
371
  const [editingKey, setEditingKey] = useState('');
243
372
  const [dataErrors, setDataErrors] = useState([]);
@@ -357,13 +486,13 @@ const GridEdit = props => {
357
486
  // thêm n dòng bên trên
358
487
  const handleInsertBefore = React.useCallback((item, n) => {
359
488
  //
360
- onRemoveBgSelectedCell(selectedCells.current, id);
361
- onRemoveBorderSelectedCell(selectedCells.current, id);
489
+ // onRemoveBgSelectedCell(selectedCells.current, id)
490
+ // onRemoveBorderSelectedCell(selectedCells.current, id)
362
491
  //
363
492
 
364
493
  setTimeout(() => {
365
- onAddBgSelectedCell(selectedCells.current, id);
366
- onAddBorderSelectedCell(selectedCells.current, id);
494
+ // onAddBgSelectedCell(selectedCells.current, id)
495
+ // onAddBorderSelectedCell(selectedCells.current, id)
367
496
  }, 10);
368
497
  const defaultRowValue = getDefaultValue(defaultValue);
369
498
  // const rowId = defaultRowValue && defaultRowValue.id ? defaultRowValue.id : newGuid()
@@ -434,7 +563,7 @@ const GridEdit = props => {
434
563
  triggerChangeData?.(newDataSource, 'INSERT_BEFORE');
435
564
  }
436
565
  }
437
- }, [dataSource, defaultValue, id, isFilter, rowKey, rowsFocus, triggerChangeData]);
566
+ }, [dataSource, defaultValue, isFilter, rowKey, rowsFocus, triggerChangeData]);
438
567
 
439
568
  //thêm 1 dòng bên dưới
440
569
  const handleInsertAfter = React.useCallback((item, n) => {
@@ -519,7 +648,7 @@ const GridEdit = props => {
519
648
  });
520
649
  } else {
521
650
  const newData = [...dataSource];
522
- let newElement = {};
651
+ let newElement;
523
652
  if (!record.children || record.children.length === 0) {
524
653
  newElement = {
525
654
  ...record,
@@ -553,8 +682,8 @@ const GridEdit = props => {
553
682
  }, [dataSource, defaultValue, getRowKey, mergedExpandedKeys, rowKey, rowsFocus, triggerChangeData]);
554
683
  const handleDeleteRows = React.useCallback(item => {
555
684
  setTimeout(() => {
556
- onAddBgSelectedCell(selectedCells.current, id);
557
- onAddBorderSelectedCell(selectedCells.current, id);
685
+ // onAddBgSelectedCell(selectedCells.current, id)
686
+ // onAddBorderSelectedCell(selectedCells.current, id)
558
687
  });
559
688
  if (item.onClick) {
560
689
  item.onClick({
@@ -570,7 +699,7 @@ const GridEdit = props => {
570
699
  });
571
700
  triggerChangeData?.([...newData], 'DELETE_ROWS');
572
701
  }
573
- }, [dataSource, id, rowsFocus, triggerChangeData]);
702
+ }, [dataSource, rowsFocus, triggerChangeData]);
574
703
  const handleDeleteAll = React.useCallback(() => {
575
704
  triggerChangeData?.([], 'INSERT_BEFORE');
576
705
  }, [triggerChangeData]);
@@ -816,7 +945,7 @@ const GridEdit = props => {
816
945
  }
817
946
  } = useForm({
818
947
  mode: 'onChange',
819
- resolver: yupResolver(validate)
948
+ resolver: validate ? yupResolver(validate) : undefined
820
949
  });
821
950
  const isEditing = React.useCallback(record => {
822
951
  return record[rowKey] === editingKey;
@@ -866,77 +995,6 @@ const GridEdit = props => {
866
995
  document.removeEventListener("click", handleClickOutside);
867
996
  };
868
997
  }, [id]);
869
- const handleMouseDown = (record, row, col, e) => {
870
- if (editingKey && editingKey === record[rowKey]) {
871
- return;
872
- }
873
- if (e.button === 2) {
874
- e.stopPropagation();
875
- return;
876
- }
877
-
878
- // isDragMouse.current = true
879
- isMouseDown.current = true;
880
- if (e.ctrlKey) {
881
- isSelecting.current = true;
882
- startCell.current = {
883
- row,
884
- col
885
- };
886
-
887
- // const cell: any = new Set([`${row}-${col}`])
888
-
889
- // setCurrentCtrlCells(cell)
890
- } else {
891
- isSelecting.current = true;
892
- startCell.current = {
893
- row,
894
- col
895
- };
896
- const target = e.target;
897
- if (target.closest('.dragging-point')) {
898
- e.stopPropagation();
899
- e.preventDefault();
900
- return; // Không xử lý gì cả
901
- } else {
902
- // setStartSelectedCell({row, col})
903
-
904
- startSelectedCells.current = {
905
- row,
906
- col
907
- };
908
-
909
- // setSelectedCells(new Set([`${row}-${col}`]));
910
-
911
- const cells = new Set([`${row}-${col}`]);
912
- if (selectedCells.current && selectedCells.current.size > 0) {
913
- if (!isEqualSet(cells, rangeCells)) {
914
- onRemoveBgSelectedCell(rangeCells, id);
915
- onRemoveBorderSelectedCell(rangeCells, id);
916
- hideDraggingPoint(rangeCells, id);
917
- }
918
- }
919
- if (rowsSelected.current && rowsSelected.current.size > 0) {
920
- removeClassCellIndexSelected(rowsSelected.current, id);
921
- }
922
- if (!isEqualSet(cells, selectedCells.current)) {
923
- selectedCells.current = cells;
924
- if (editingKey) {
925
- setTimeout(() => {
926
- onAddBgSelectedCell(cells, id);
927
- onAddBorderSelectedCell(cells, id);
928
- }, 200);
929
- } else {
930
- onAddBgSelectedCell(cells, id);
931
- onAddBorderSelectedCell(cells, id);
932
- }
933
- }
934
-
935
- // setRowsSelected(new Set())
936
- rowsSelected.current = new Set();
937
- }
938
- }
939
- };
940
998
  const triggerDragPaste = pastesArray => {
941
999
  const mergedSet = new Set([...selectedCells.current, ...pastesArray]);
942
1000
  const tmpCols = {
@@ -957,35 +1015,6 @@ const GridEdit = props => {
957
1015
  // return { row, col, value: '' };
958
1016
  });
959
1017
 
960
- // let selectedArray = []
961
- //
962
- // if (rowPasteLast > rowSelectedFirst) {
963
- // // kéo xuóng
964
- // selectedArray = Array.from(selectedCells).map((key: any) => {
965
- //
966
- // const [row, col] = key.split("-").map(Number);
967
- // // @ts-ignore
968
- // const columnKey = columns[col].field;
969
- //
970
- // // @ts-ignore
971
- // return { row, col, value: flattenData(childrenColumnName as any,dataSource)[row][columnKey] };
972
- // // return { row, col, value: '' };
973
- // });
974
- // } else {
975
- // // kéo lên
976
- //
977
- // selectedArray = Array.from(sortedSetDSC(selectedCells)).map((key: any) => {
978
- //
979
- // const [row, col] = key.split("-").map(Number);
980
- // // @ts-ignore
981
- // const columnKey = columns[col].field;
982
- //
983
- // // @ts-ignore
984
- // return { row, col, value: flattenData(childrenColumnName as any,dataSource)[row][columnKey] };
985
- // // return { row, col, value: '' };
986
- // });
987
- // }
988
-
989
1018
  // Xác định min/max row và col để sắp xếp dữ liệu
990
1019
  const minRow = Math.min(...selectedArray.map(cell => cell.row));
991
1020
  const maxRow = Math.max(...selectedArray.map(cell => cell.row));
@@ -1005,10 +1034,7 @@ const GridEdit = props => {
1005
1034
  }) => {
1006
1035
  table[row - minRow][col - minCol] = value;
1007
1036
  });
1008
- let newRange = {
1009
- combined: [],
1010
- addedRows: []
1011
- };
1037
+ let newRange;
1012
1038
  if (rowPasteLast > rowSelectedFirst) {
1013
1039
  // kéo xuóng
1014
1040
  newRange = addRows8(table, getRowsPasteIndex(pastesArray).length);
@@ -1065,18 +1091,20 @@ const GridEdit = props => {
1065
1091
 
1066
1092
  /// cập nhật cell class
1067
1093
  if (selectedCells.current && selectedCells.current.size > 0) {
1068
- onRemoveBgSelectedCell(rangeCells, id);
1069
- onRemoveBorderSelectedCell(rangeCells, id);
1094
+ // onRemoveBgSelectedCell(rangeCells, id)
1095
+ // onRemoveBorderSelectedCell(rangeCells, id)
1070
1096
  }
1071
1097
 
1072
1098
  // selectedCells.current = sortedSetASC(mergedSet)
1073
1099
  hideDraggingPoint(selectedCells.current, id);
1074
- selectedCells.current = sortedSetASC(mergedSet);
1075
- setRangeCells(sortedSetASC(mergedSet));
1100
+ const newCells = sortedSetASC(mergedSet);
1101
+ selectedCells.current = newCells;
1102
+ onAddBgCellIndex(newCells, id);
1103
+ setRangeCells(newCells);
1104
+ onAddBgSelectedCell(newCells, id);
1105
+ onAddBorderSelectedCell(newCells, id);
1076
1106
  setTimeout(() => {
1077
- onAddBgSelectedCell(sortedSetASC(mergedSet), id);
1078
- onAddBorderSelectedCell(sortedSetASC(mergedSet), id);
1079
- showDraggingPoint(sortedSetASC(mergedSet), id);
1107
+ showDraggingPoint(newCells, id);
1080
1108
  }, 50);
1081
1109
 
1082
1110
  // setPasteCells(new Set())
@@ -1101,6 +1129,80 @@ const GridEdit = props => {
1101
1129
  hideDraggingPoint(selectedCells.current, id);
1102
1130
  triggerDragPaste(newPasteCells);
1103
1131
  };
1132
+ const handleMouseDown = (record, row, col, e) => {
1133
+ if (e.button === 2) {
1134
+ e.stopPropagation();
1135
+ return;
1136
+ }
1137
+ if (editingKey && editingKey === record[rowKey]) {
1138
+ return;
1139
+ }
1140
+ if (record[rowKey] !== editingKey && editingKey !== '') {
1141
+ setEditingKey('');
1142
+ }
1143
+
1144
+ // isDragMouse.current = true
1145
+ isMouseDown.current = true;
1146
+ if (e.ctrlKey) {
1147
+ isSelecting.current = true;
1148
+ startCell.current = {
1149
+ row,
1150
+ col
1151
+ };
1152
+
1153
+ // const cell: any = new Set([`${row}-${col}`])
1154
+
1155
+ // setCurrentCtrlCells(cell)
1156
+ } else {
1157
+ isSelecting.current = true;
1158
+ startCell.current = {
1159
+ row,
1160
+ col
1161
+ };
1162
+ const target = e.target;
1163
+ if (target.closest('.dragging-point')) {
1164
+ e.stopPropagation();
1165
+ e.preventDefault();
1166
+ return; // Không xử lý gì cả
1167
+ } else {
1168
+ // setStartSelectedCell({row, col})
1169
+
1170
+ startSelectedCells.current = {
1171
+ row,
1172
+ col
1173
+ };
1174
+
1175
+ // setSelectedCells(new Set([`${row}-${col}`]));
1176
+
1177
+ const cells = new Set([`${row}-${col}`]);
1178
+ if (selectedCells.current && selectedCells.current.size > 0) {
1179
+ if (!isEqualSet(cells, rangeCells)) {
1180
+ // onRemoveBgSelectedCell(rangeCells, id)
1181
+ // onRemoveBorderSelectedCell(rangeCells, id)
1182
+ hideDraggingPoint(rangeCells, id);
1183
+ onRemoveBgCellIndex(selectedCells.current, id);
1184
+ }
1185
+ }
1186
+ if (rowsSelected.current && rowsSelected.current.size > 0) {
1187
+ removeClassCellIndexSelected(rowsSelected.current, id);
1188
+ }
1189
+ if (!isEqualSet(cells, selectedCells.current)) {
1190
+ onRemoveBgSelectedCell(selectedCells.current, id);
1191
+ hideDraggingPoint(selectedCells.current, id);
1192
+ selectedCells.current = cells;
1193
+ // setRangeCells(cells)
1194
+
1195
+ onAddBgCellIndex(cells, id);
1196
+ onAddBorderSelectedCell(cells, id);
1197
+ onAddBgSelectedCell(selectedCells.current, id, false);
1198
+ showDraggingPoint(selectedCells.current, id);
1199
+ }
1200
+
1201
+ // setRowsSelected(new Set())
1202
+ rowsSelected.current = new Set();
1203
+ }
1204
+ }
1205
+ };
1104
1206
  const handleMouseUp = e => {
1105
1207
  isSelecting.current = false;
1106
1208
  startCell.current = null;
@@ -1109,12 +1211,6 @@ const GridEdit = props => {
1109
1211
  isDragMouse.current = false;
1110
1212
  isMouseDown.current = false;
1111
1213
  setIsPasteDragging(false);
1112
-
1113
- // isPasteDragging.current = false
1114
- // setSelectIsDragging(false);
1115
-
1116
- // setCurrentCtrlCells(new Set())
1117
-
1118
1214
  if (e.ctrlKey) {
1119
1215
 
1120
1216
  // setCtrlCells([...ctrlCells, currentCtrlCells])
@@ -1126,18 +1222,20 @@ const GridEdit = props => {
1126
1222
  triggerDragPaste(pasteCells.current);
1127
1223
  } else {
1128
1224
  setRangeCells(selectedCells.current);
1129
- onRemoveBorderSelectedCell(rangeCells, id);
1130
- onAddBorderSelectedCell(selectedCells.current, id);
1131
1225
  const target = e.target;
1132
1226
  if (target.closest('.dragging-point')) {
1133
1227
  e.stopPropagation();
1134
1228
  e.preventDefault();
1135
1229
  return; // Không xử lý gì cả
1136
1230
  }
1137
- if (selectedCells.current && selectedCells.current.size > 0) {
1231
+ if (selectedCells.current && selectedCells.current.size > 1) {
1138
1232
  hideDraggingPoint(selectedCells.current, id);
1233
+ onAddBorderSelectedCell(selectedCells.current, id);
1234
+
1235
+ // showDraggingPoint(selectedCells.current, id)
1139
1236
  }
1140
1237
  showDraggingPoint(selectedCells.current, id);
1238
+ // onAddBorderSelectedCell(selectedCells.current, id)
1141
1239
  }
1142
1240
  };
1143
1241
  const handleMouseEnter = (row, col, e) => {
@@ -1256,15 +1354,17 @@ const GridEdit = props => {
1256
1354
  // setSelectedCells(new Set(newSelectedCells));
1257
1355
 
1258
1356
  if (selectedCells.current && selectedCells.current.size > 0) {
1259
- onRemoveBgSelectedCell(selectedCells.current, id);
1260
- onRemoveBorderSelectedCell(selectedCells.current, id);
1357
+ // onRemoveBgSelectedCell(selectedCells.current, id)
1358
+ // onRemoveBorderSelectedCell(selectedCells.current, id)
1261
1359
  }
1262
1360
  if (rowsSelected.current && rowsSelected.current.size > 0) {
1263
1361
  removeClassCellIndexSelected(rowsSelected.current, id);
1264
1362
  }
1265
1363
  selectedCells.current = newSelectedCells;
1266
- onAddBgSelectedCell(newSelectedCells, id);
1267
- onAddBorderSelectedCell(newSelectedCells, id);
1364
+
1365
+ // onAddBgSelectedCell(newSelectedCells, id)
1366
+ // onAddBorderSelectedCell(newSelectedCells, id)
1367
+
1268
1368
  hideDraggingPoint(selectedCells.current, id);
1269
1369
  showDraggingPoint(newSelectedCells, id);
1270
1370
  };
@@ -1273,6 +1373,9 @@ const GridEdit = props => {
1273
1373
  e.stopPropagation();
1274
1374
  return;
1275
1375
  }
1376
+ if (editingKey) {
1377
+ setEditingKey('');
1378
+ }
1276
1379
  isSelectingRow.current = true;
1277
1380
  rowStart.current = {
1278
1381
  row,
@@ -1285,13 +1388,11 @@ const GridEdit = props => {
1285
1388
  newSelectedCells.add(`${r}-${c}`);
1286
1389
  }
1287
1390
  }
1288
-
1289
- // setSelectedCells(newSelectedCells)
1290
- // setRowsSelected(new Set([`${row}-${col}`]));
1291
-
1292
1391
  if (selectedCells.current && selectedCells.current.size > 0) {
1392
+ onRemoveBgCellIndex(selectedCells.current, id);
1293
1393
  onRemoveBgSelectedCell(selectedCells.current, id);
1294
1394
  onRemoveBorderSelectedCell(selectedCells.current, id);
1395
+ // onRemoveBorderSelectedCell(selectedCells.current, id)
1295
1396
  }
1296
1397
  if (rowsSelected.current && rowsSelected.current.size > 0) {
1297
1398
  removeClassCellIndexSelected(rowsSelected.current, id);
@@ -1300,7 +1401,9 @@ const GridEdit = props => {
1300
1401
  selectedCells.current = newSelectedCells;
1301
1402
  rowsSelected.current = new Set([`${row}-${col}`]);
1302
1403
  onAddBgSelectedCell(newSelectedCells, id, false);
1303
- onAddBorderSelectedCell(newSelectedCells, id);
1404
+ setTimeout(() => {
1405
+ onAddBgSelectedCell(newSelectedCells, id, false);
1406
+ }, 10);
1304
1407
  addClassCellIndexSelected(new Set([`${row}-${col}`]), id);
1305
1408
  };
1306
1409
  const handleMouseEnterRowHeader = (row, col, e) => {
@@ -1330,13 +1433,11 @@ const GridEdit = props => {
1330
1433
  if (selectedCells.current && selectedCells.current.size > 0) {
1331
1434
  onRemoveBgSelectedCell(selectedCells.current, id);
1332
1435
  }
1333
- // setSelectedCells(newSelectedCells)
1334
1436
  selectedCells.current = newSelectedCells;
1335
1437
  onAddBgSelectedCell(newSelectedCells, id);
1336
1438
  if (rowsSelected.current && rowsSelected.current.size > 0) {
1337
1439
  removeClassCellIndexSelected(rowsSelected.current, id);
1338
1440
  }
1339
- // setRowsSelected(newSelectedRows)
1340
1441
  rowsSelected.current = newSelectedRows;
1341
1442
  addClassCellIndexSelected(newSelectedRows, id);
1342
1443
  };
@@ -1755,6 +1856,7 @@ const GridEdit = props => {
1755
1856
  }
1756
1857
  };
1757
1858
  const handleEdit = (record, col, editType, e) => {
1859
+ onRemoveBorderSelectedCell(selectedCells.current, id);
1758
1860
  setTooltipContent('');
1759
1861
  // @ts-ignore
1760
1862
  setEditingKey(record[rowKey]);
@@ -1854,10 +1956,16 @@ const GridEdit = props => {
1854
1956
  hideDraggingPoint(selectedCells.current, id);
1855
1957
  selectedCells.current = cells;
1856
1958
  setRangeCells(cells);
1857
- setTimeout(() => {
1858
- onAddBgSelectedCell(selectedCells.current, id);
1859
- onAddBorderSelectedCell(selectedCells.current, id);
1860
- }, 50);
1959
+
1960
+ // setTimeout(() => {
1961
+ //
1962
+ // // onAddBgSelectedCell(selectedCells.current, id)
1963
+ // // onAddBorderSelectedCell(selectedCells.current, id)
1964
+ //
1965
+ // }, 50)
1966
+
1967
+ onAddBgSelectedCell(selectedCells.current, id);
1968
+ onAddBorderSelectedCell(selectedCells.current, id);
1861
1969
  showDraggingPoint(cells, id);
1862
1970
  };
1863
1971
  const focusNextCell = (editingCell, cellEditable) => {
@@ -1866,6 +1974,7 @@ const GridEdit = props => {
1866
1974
  updateSelection();
1867
1975
  if (e?.key !== 'Tab') {
1868
1976
  editingCell.focus();
1977
+ // editingCell.click()
1869
1978
  }
1870
1979
  }
1871
1980
  if (scrollType === 'horizontal' && editingCell) {
@@ -1877,6 +1986,8 @@ const GridEdit = props => {
1877
1986
  scrollToCell(rowIndex, colIndex, cellEdit, 'vertical');
1878
1987
  if (e?.key !== 'Tab') {
1879
1988
  cellEditable.focus();
1989
+ onAddBorderSelectedCell(selectedCells.current, id);
1990
+ // editingCell.click()
1880
1991
  }
1881
1992
  }
1882
1993
  } else {
@@ -1884,6 +1995,7 @@ const GridEdit = props => {
1884
1995
  updateSelection();
1885
1996
  if (e?.key !== 'Tab') {
1886
1997
  cellEditable.focus();
1998
+ onAddBorderSelectedCell(selectedCells.current, id);
1887
1999
  }
1888
2000
  }
1889
2001
  if (cellEditable) {
@@ -1929,11 +2041,11 @@ const GridEdit = props => {
1929
2041
  e.preventDefault();
1930
2042
  }
1931
2043
  },
1932
- onClick: () => {
1933
- if (record[rowKey] !== editingKey && editingKey !== '') {
1934
- setEditingKey('');
1935
- }
1936
- },
2044
+ // onClick: () => {
2045
+ // if (record[rowKey] !== editingKey && (editingKey !== '')) {
2046
+ // setEditingKey('')
2047
+ // }
2048
+ // },
1937
2049
  tabIndex: (rowIndex ?? 0) * visibleCols.length + colIndex
1938
2050
  };
1939
2051
  },
@@ -1943,7 +2055,7 @@ const GridEdit = props => {
1943
2055
  className: classNames('ui-rc_cell-content ui-rc_cell-content--index', {}),
1944
2056
  onMouseDown: event => handleMouseDownRowHeader(rowNumber, colIndex, column, event),
1945
2057
  onMouseEnter: event => handleMouseEnterRowHeader(rowNumber, colIndex, event),
1946
- onMouseUp: handleMouseUp
2058
+ onMouseUp: event => handleMouseUp(event)
1947
2059
  }, /*#__PURE__*/React.createElement("div", {
1948
2060
  className: 'ui-rc_content'
1949
2061
  }, findItemPath(dataSource, record, rowKey)));
@@ -1970,9 +2082,12 @@ const GridEdit = props => {
1970
2082
  event.preventDefault();
1971
2083
  event.stopPropagation();
1972
2084
  handleEdit(record, column, column.editType, event);
1973
- onRemoveBgSelectedCell(selectedCells.current, id);
1974
- onRemoveBorderSelectedCell(selectedCells.current, id);
1975
- selectedCells.current = new Set();
2085
+
2086
+ // onRemoveBgSelectedCell(selectedCells.current, id)
2087
+ // onRemoveBorderSelectedCell(selectedCells.current, id)
2088
+
2089
+ // selectedCells.current = new Set()
2090
+
1976
2091
  handleCellClick(rowNumber, record, column);
1977
2092
  const hasKey = mergedExpandedKeys.has(key);
1978
2093
  if (hasKey) {
@@ -2062,8 +2177,9 @@ const GridEdit = props => {
2062
2177
  onDoubleClick: event => {
2063
2178
  if (!isEditing(record) && record[rowKey] !== editingKey && isEditable(column, record)) {
2064
2179
  handleEdit(record, column, getEditType(column, record), event);
2065
- onRemoveBgSelectedCell(selectedCells.current, id);
2066
- onRemoveBorderSelectedCell(selectedCells.current, id);
2180
+
2181
+ // onRemoveBgSelectedCell(selectedCells.current, id)
2182
+ // onRemoveBorderSelectedCell(selectedCells.current, id)
2067
2183
  handleCellClick(rowNumber, record, column);
2068
2184
  }
2069
2185
  },
@@ -2085,14 +2201,27 @@ const GridEdit = props => {
2085
2201
  },
2086
2202
  onClick: () => {
2087
2203
  if (record[rowKey] !== editingKey && editingKey !== '') {
2088
- setEditingKey('');
2204
+ // setEditingKey('')
2089
2205
  } else {
2206
+ if (record[rowKey] !== editingKey) {
2207
+ onAddBorderSelectedCell(selectedCells.current, id);
2208
+ }
2090
2209
  if (editingKey) {
2091
2210
  handleCellClick(rowNumber, record, column);
2092
2211
  }
2093
2212
  }
2094
2213
  },
2095
- className: isEditing(record) ? `rc-ui-cell-editable cell-editing ${!isEditable(column, record) ? 'disable' : ''}` : `rc-ui-cell-editable cell-editable ${!isEditable(column, record) ? 'disable' : ''}`,
2214
+ // className: isEditing(record) ? `rc-ui-cell-editable cell-editing ${!isEditable(column as any, record) ? 'disable' : ''}` : `rc-ui-cell-editable cell-editable ${!isEditable(column as any, record) ? 'disable' : ''}`,
2215
+ className: classNames('rc-ui-cell-editable', {
2216
+ 'cell-editing': isEditing(record),
2217
+ 'cell-editable': !isEditing(record),
2218
+ // selected: isSelectedCell(rangeCells,rowIndex, colIndex),
2219
+ // 'cell-border-bottom': isRangeCell(rangeCells, 'bottom',rowIndex, colIndex),
2220
+ // 'cell-border-right': isRangeCell(rangeCells, 'right',rowIndex, colIndex),
2221
+ // 'cell-border-top': isRangeCell(rangeCells, 'top',rowIndex, colIndex),
2222
+ // 'cell-border-left': isRangeCell(rangeCells, 'left',rowIndex, colIndex),
2223
+ disable: !isEditable(column, record)
2224
+ }),
2096
2225
  record,
2097
2226
  column: column,
2098
2227
  editType: getEditType(column, record),
@@ -2103,9 +2232,6 @@ const GridEdit = props => {
2103
2232
  'data-col-index': colIndex,
2104
2233
  'data-row-index': rowNumber,
2105
2234
  'data-tooltip-id': "tooltip-cell-content",
2106
- // 'data-tooltip-content': 'tooltip-cell-content',
2107
- // 'data-tooltip-delay-show': 1000,
2108
- // 'data-tooltip-content': getValueCell(column, record[column.field as any], format),
2109
2235
  editing: isEditing(record) && rowEditable?.(record) !== false && isEditable(column, record),
2110
2236
  cellEditing,
2111
2237
  t,
@@ -2195,6 +2321,40 @@ const GridEdit = props => {
2195
2321
  }
2196
2322
  };
2197
2323
  });
2324
+ // [
2325
+ // cellEditing,
2326
+ // columns,
2327
+ // dataErrors,
2328
+ // dataSource,
2329
+ // editingKey,
2330
+ // format,
2331
+ // getRowKey,
2332
+ // handleAddSingle,
2333
+ // handleCellClick,
2334
+ // handleClickColHeader,
2335
+ // handleCopy,
2336
+ // handleDeleteContent,
2337
+ // handleEdit,
2338
+ // handleFocusCell,
2339
+ // handleMouseDown,
2340
+ // handleMouseDownRowHeader,
2341
+ // handleMouseEnter,
2342
+ // handleMouseEnterRowHeader,
2343
+ // handleMouseUp,
2344
+ // handlePaste,
2345
+ // handlePointDoubleClick,
2346
+ // id,
2347
+ // isEditing,
2348
+ // isPasteDragging,
2349
+ // mergedExpandedKeys,
2350
+ // onTriggerExpand,
2351
+ // rowEditable,
2352
+ // rowKey,
2353
+ // setTooltipContent,
2354
+ // t,
2355
+ // visibleCols.length
2356
+ // ])
2357
+
2198
2358
  const transformColumns = React.useCallback(cols => {
2199
2359
  // @ts-ignore
2200
2360
  return cols.map(column => {
@@ -2202,6 +2362,14 @@ const GridEdit = props => {
2202
2362
  if (column === SELECTION_COLUMN) {
2203
2363
  return SELECTION_COLUMN;
2204
2364
  }
2365
+
2366
+ // Xử lý đệ quy cho children
2367
+ if (column.children?.length) {
2368
+ return {
2369
+ ...column,
2370
+ children: transformColumns(column.children)
2371
+ };
2372
+ }
2205
2373
  if (find) {
2206
2374
  return {
2207
2375
  ...find
@@ -2212,14 +2380,6 @@ const GridEdit = props => {
2212
2380
  ...column
2213
2381
  };
2214
2382
  }
2215
-
2216
- // Xử lý đệ quy cho children
2217
- if (column.children?.length) {
2218
- return {
2219
- ...column,
2220
- children: transformColumns(column.children)
2221
- };
2222
- }
2223
2383
  });
2224
2384
  }, [convertColumns]);
2225
2385
  const mergedColumns = React.useMemo(() => transformColumns(columns ?? []), [transformColumns, columns]);
@@ -2302,10 +2462,12 @@ const GridEdit = props => {
2302
2462
  };
2303
2463
  return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(GridStyle, {
2304
2464
  $heightTable: height,
2465
+ $heightScroll: scrollHeight,
2305
2466
  style: {
2306
2467
  position: 'relative'
2307
2468
  },
2308
- ref: ref
2469
+ ref: ref,
2470
+ id: id
2309
2471
  }, /*#__PURE__*/React.createElement(TableContext.Provider, {
2310
2472
  value: {
2311
2473
  rowKey,