es-grid-template 1.3.7 → 1.3.9

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.
@@ -13,18 +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 { addClassBorderPasteCell, addClassCellIndexSelected, addRows8, addRowsUp, checkChild, editAbleColumns, findAllChildrenKeys, findItemByKey, findItemPath, flattenArray, flattenData, getDefaultValue, getEditType, getFirstSelectCell, getLastSelectCell, getRowNumber, getRowsPasteIndex, hideDraggingPoint, isEditable, isEqualSet, isObjEmpty, newGuid, onAddClassBgSelectedCell, onRemoveClassSelectedCell, removeClassBorderPasteCell, removeClassCellIndexSelected, showDraggingPoint, 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";
17
17
  import Message from "../../Message/Message";
18
- // import Command from "../Command";
19
-
20
18
  import { Toolbar, ConfigProvider, InputNumber } from "rc-master-ui";
21
19
  import classnames from "classnames";
22
- // import useMergedState from "rc-util/lib/hooks/useMergedState";
23
20
  import { Plus, Trash2 } from "becoxy-icons";
24
- // import type {ContextMenuItem} from "../type";
25
- // import {ContextInfo, ContextMenuItem} from "../type";
26
- // import useLazyKVMap from "rc-master-ui/es/table/hooks/useLazyKVMap";
27
-
21
+ import { faker } from "@faker-js/faker";
28
22
  const {
29
23
  Paragraph,
30
24
  Title
@@ -109,8 +103,7 @@ const defaultContext = [{
109
103
  }];
110
104
  const GridEdit = props => {
111
105
  const {
112
- // id = newGuid(),
113
- id,
106
+ id: tableId,
114
107
  tableRef,
115
108
  t,
116
109
  columns,
@@ -138,17 +131,6 @@ const GridEdit = props => {
138
131
  showDefaultContext,
139
132
  ...rest
140
133
  } = props;
141
-
142
- // const {
143
- // mode,
144
- // type,
145
- // checkboxOnly,
146
- // hideSelectAll,
147
- // columnWidth,
148
- // selectedRowKeys,
149
- // defaultSelectedRowKeys
150
- // } = selectionSettings || {}
151
-
152
134
  const ref = useRef(null);
153
135
  const isSelecting = useRef(false);
154
136
  const startCell = useRef(null);
@@ -167,10 +149,10 @@ const GridEdit = props => {
167
149
  // quét vùng được paste - tiếp tục hiển thị con trỏ crosshair
168
150
  // const isPasteDragging = useRef(false);
169
151
 
170
- // const isPointEnter = useRef(false);
171
-
172
- // const [getRecordByKey] = useLazyKVMap(dataSource, childrenColumnName, getRowKey);
173
-
152
+ const id = React.useMemo(() => {
153
+ return tableId ?? faker.string.alpha(20);
154
+ // return tableId ?? newGuid()
155
+ }, [tableId]);
174
156
  const itemsAdd = [{
175
157
  key: '10',
176
158
  label: '10 rows'
@@ -184,8 +166,8 @@ const GridEdit = props => {
184
166
  const [form] = Form.useForm();
185
167
  const [editingKey, setEditingKey] = useState('');
186
168
  const [isFilter, setIsFilter] = React.useState(false);
169
+ const [rangeCells, setRangeCells] = useState(new Set());
187
170
 
188
- // const [selectedCells, setSelectedCells] = useState(new Set())
189
171
  // const [pasteCells, setPasteCells] = useState(new Set())
190
172
 
191
173
  // const defaultModalPaste = {open: false, rowIndex: -1, colIndex: -1, record: {}, rowsPasted: []}
@@ -220,17 +202,9 @@ const GridEdit = props => {
220
202
  // return [];
221
203
  });
222
204
  const mergedExpandedKeys = React.useMemo(() => new Set(innerExpandedKeys || []), [innerExpandedKeys]);
223
-
224
- // const [mergedSelectedKeys, setMergedSelectedKeys] = useMergedState<any[]>(
225
- // [],
226
- // {
227
- // value: [],
228
- // },
229
- // );
230
-
231
205
  const rowsFocus = React.useMemo(() => {
232
- return [...new Set(Array.from(selectedCells.current).map(item => parseInt(item.split('-')[0])))] ?? [];
233
- }, [selectedCells]);
206
+ return [...new Set(Array.from(rangeCells).map(item => parseInt(item.split('-')[0])))] ?? [];
207
+ }, [rangeCells]);
234
208
  const contextMenuItems = React.useMemo(() => {
235
209
  const a = showDefaultContext !== false ? [...defaultContext] : [];
236
210
  const b = propsContext ? [...propsContext, {
@@ -310,6 +284,15 @@ const GridEdit = props => {
310
284
 
311
285
  // thêm n dòng bên trên
312
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);
313
296
  const defaultRowValue = getDefaultValue(defaultValue);
314
297
  // const rowId = defaultRowValue && defaultRowValue.id ? defaultRowValue.id : newGuid()
315
298
 
@@ -384,9 +367,6 @@ const GridEdit = props => {
384
367
  //thêm 1 dòng bên dưới
385
368
  const handleInsertAfter = (item, n) => {
386
369
  const defaultRowValue = getDefaultValue(defaultValue);
387
-
388
- // const rowId = defaultRowValue && defaultRowValue.id ? defaultRowValue.id : newGuid()
389
-
390
370
  const record = flattenData(childrenColumnName, dataSource)[rowsFocus[rowsFocus.length - 1]];
391
371
 
392
372
  // const record = getRecordByKey()
@@ -419,8 +399,6 @@ const GridEdit = props => {
419
399
  rowId: newGuid()
420
400
  });
421
401
  const index = newData.findIndex(obj => obj[rowKey] === record[rowKey]);
422
-
423
- // newData.splice(index + 1, 0, { ...defaultRowValue, rowId, parentId: null })
424
402
  newData.splice(index + 1, 0, ...newRows);
425
403
  triggerChangeData?.(newData, 'INSERT_AFTER');
426
404
  } else {
@@ -502,6 +480,10 @@ const GridEdit = props => {
502
480
  }
503
481
  };
504
482
  const handleDeleteRows = item => {
483
+ setTimeout(() => {
484
+ onAddBgSelectedCell(selectedCells.current, id);
485
+ onAddBorderSelectedCell(selectedCells.current, id);
486
+ });
505
487
  if (item.onClick) {
506
488
  item.onClick({
507
489
  toolbar: item
@@ -757,10 +739,8 @@ const GridEdit = props => {
757
739
  trigger,
758
740
  getValues,
759
741
  reset
760
- // formState: { errors }
761
742
  } = useForm({
762
743
  mode: 'onChange'
763
- // defaultValues,
764
744
  // resolver: yupResolver(formSchema)
765
745
  });
766
746
  const isEditing = record => record[rowKey] === editingKey;
@@ -796,25 +776,13 @@ const GridEdit = props => {
796
776
  // setSelectedCells(new Set())
797
777
  // setRowsSelected(new Set())
798
778
 
799
- onRemoveClassSelectedCell(selectedCells.current, id);
779
+ onRemoveBgSelectedCell(selectedCells.current, id);
780
+ onRemoveBorderSelectedCell(selectedCells.current, id);
800
781
  hideDraggingPoint(selectedCells.current, id);
801
782
  rowsSelected.current = new Set();
802
783
  selectedCells.current = new Set();
784
+ setRangeCells(new Set());
803
785
  }
804
-
805
- // if (tableBodies.length > 0) {
806
- // const tableBody = tableBodies[0]; // Chọn tbody đầu tiên (nếu có nhiều)
807
- //
808
- // if (!tableBody.contains(event.target as Node)) {
809
- // setEditingKey('')
810
- // isSelecting.current = false;
811
- // startCell.current = null;
812
- // setSelectedCells(new Set())
813
- // setRowsSelected(new Set())
814
- // } else {
815
- //
816
- // }
817
- // }
818
786
  };
819
787
  document.addEventListener("click", handleClickOutside);
820
788
  return () => {
@@ -862,16 +830,28 @@ const GridEdit = props => {
862
830
 
863
831
  const cells = new Set([`${row}-${col}`]);
864
832
  if (selectedCells.current && selectedCells.current.size > 0) {
865
- onRemoveClassSelectedCell(selectedCells.current, id);
866
- if (!isEqualSet(cells, selectedCells.current)) {
867
- hideDraggingPoint(selectedCells.current, id);
833
+ if (!isEqualSet(cells, rangeCells)) {
834
+ onRemoveBgSelectedCell(rangeCells, id);
835
+ onRemoveBorderSelectedCell(rangeCells, id);
836
+ hideDraggingPoint(rangeCells, id);
868
837
  }
869
838
  }
870
- selectedCells.current = cells;
871
- onAddClassBgSelectedCell(cells, id);
872
839
  if (rowsSelected.current && rowsSelected.current.size > 0) {
873
840
  removeClassCellIndexSelected(rowsSelected.current, id);
874
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
+
875
855
  // setRowsSelected(new Set())
876
856
  rowsSelected.current = new Set();
877
857
  }
@@ -879,12 +859,12 @@ const GridEdit = props => {
879
859
  };
880
860
  const triggerDragPaste = pastesArray => {
881
861
  const mergedSet = new Set([...selectedCells.current, ...pastesArray]);
862
+ const tmpCols = flatColumns2(columns.filter(it => it.visible !== false));
882
863
  const rowSelectedFirst = getFirstSelectCell(selectedCells.current).row;
883
864
  const rowPasteLast = getLastSelectCell(pasteCells.current).row;
884
865
  const selectedArray = Array.from(selectedCells.current).map(key => {
885
866
  const [row, col] = key.split("-").map(Number);
886
- // @ts-ignore
887
- const columnKey = columns[col].field;
867
+ const columnKey = tmpCols[col].field;
888
868
 
889
869
  // @ts-ignore
890
870
  return {
@@ -978,13 +958,13 @@ const GridEdit = props => {
978
958
  }
979
959
  rowValues.forEach((cellValue, colIndex) => {
980
960
  const targetCol = startCol + colIndex;
981
- if (targetCol >= columns.length) {
961
+ if (targetCol >= tmpCols.length) {
982
962
  // Không vượt quá số cột
983
963
  return;
984
964
  }
985
965
 
986
966
  // @ts-ignore
987
- const columnKey = columns[targetCol].field;
967
+ const columnKey = tmpCols[targetCol].field;
988
968
 
989
969
  // @ts-ignore
990
970
  newData[targetRow] = {
@@ -1003,13 +983,15 @@ const GridEdit = props => {
1003
983
 
1004
984
  /// cập nhật cell class
1005
985
  if (selectedCells.current && selectedCells.current.size > 0) {
1006
- onRemoveClassSelectedCell(selectedCells.current, id);
986
+ onRemoveBgSelectedCell(rangeCells, id);
987
+ onRemoveBorderSelectedCell(rangeCells, id);
1007
988
  }
1008
989
 
1009
990
  // selectedCells.current = sortedSetASC(mergedSet)
1010
991
  hideDraggingPoint(selectedCells.current, id);
1011
992
  selectedCells.current = sortedSetASC(mergedSet);
1012
- onAddClassBgSelectedCell(sortedSetASC(mergedSet), id);
993
+ onAddBgSelectedCell(sortedSetASC(mergedSet), id);
994
+ onAddBorderSelectedCell(sortedSetASC(mergedSet), id);
1013
995
  showDraggingPoint(sortedSetASC(mergedSet), id);
1014
996
 
1015
997
  // setPasteCells(new Set())
@@ -1079,6 +1061,9 @@ const GridEdit = props => {
1079
1061
  if (pasteCells && pasteCells.current.size > 0) {
1080
1062
  triggerDragPaste(pasteCells.current);
1081
1063
  } else {
1064
+ setRangeCells(selectedCells.current);
1065
+ onRemoveBorderSelectedCell(rangeCells, id);
1066
+ onAddBorderSelectedCell(selectedCells.current, id);
1082
1067
  const target = e.target;
1083
1068
  if (target.closest('.dragging-point')) {
1084
1069
  e.stopPropagation();
@@ -1138,10 +1123,10 @@ const GridEdit = props => {
1138
1123
  // setSelectedCells(newSelectedCells)
1139
1124
 
1140
1125
  if (selectedCells.current && selectedCells.current.size > 0) {
1141
- onRemoveClassSelectedCell(selectedCells.current, id);
1126
+ onRemoveBgSelectedCell(selectedCells.current, id);
1142
1127
  }
1143
1128
  selectedCells.current = newSelectedCells;
1144
- onAddClassBgSelectedCell(newSelectedCells, id);
1129
+ onAddBgSelectedCell(newSelectedCells, id);
1145
1130
  } else {
1146
1131
  // chọn vùng paste
1147
1132
 
@@ -1221,12 +1206,12 @@ const GridEdit = props => {
1221
1206
  // // setSelectedCells(newSelectedCells)
1222
1207
  //
1223
1208
  // if (selectedCells.current && selectedCells.current.size > 0) {
1224
- // onRemoveClassSelectedCell(selectedCells.current, id)
1209
+ // onRemoveBgSelectedCell(selectedCells.current, id)
1225
1210
  // }
1226
1211
  //
1227
1212
  // selectedCells.current = newSelectedCells
1228
1213
  //
1229
- // onAddClassBgSelectedCell(newSelectedCells, id)
1214
+ // onAddBgSelectedCell(newSelectedCells, id)
1230
1215
  //
1231
1216
  //
1232
1217
  // };
@@ -1242,13 +1227,15 @@ const GridEdit = props => {
1242
1227
  // setSelectedCells(new Set(newSelectedCells));
1243
1228
 
1244
1229
  if (selectedCells.current && selectedCells.current.size > 0) {
1245
- onRemoveClassSelectedCell(selectedCells.current, id);
1230
+ onRemoveBgSelectedCell(selectedCells.current, id);
1231
+ onRemoveBorderSelectedCell(selectedCells.current, id);
1246
1232
  }
1247
1233
  if (rowsSelected.current && rowsSelected.current.size > 0) {
1248
1234
  removeClassCellIndexSelected(rowsSelected.current, id);
1249
1235
  }
1250
1236
  selectedCells.current = newSelectedCells;
1251
- onAddClassBgSelectedCell(newSelectedCells, id);
1237
+ onAddBgSelectedCell(newSelectedCells, id);
1238
+ onAddBorderSelectedCell(newSelectedCells, id);
1252
1239
  hideDraggingPoint(selectedCells.current, id);
1253
1240
  showDraggingPoint(newSelectedCells, id);
1254
1241
  };
@@ -1274,7 +1261,8 @@ const GridEdit = props => {
1274
1261
  // setRowsSelected(new Set([`${row}-${col}`]));
1275
1262
 
1276
1263
  if (selectedCells.current && selectedCells.current.size > 0) {
1277
- onRemoveClassSelectedCell(selectedCells.current, id);
1264
+ onRemoveBgSelectedCell(selectedCells.current, id);
1265
+ onRemoveBorderSelectedCell(selectedCells.current, id);
1278
1266
  }
1279
1267
  if (rowsSelected.current && rowsSelected.current.size > 0) {
1280
1268
  removeClassCellIndexSelected(rowsSelected.current, id);
@@ -1282,7 +1270,8 @@ const GridEdit = props => {
1282
1270
  hideDraggingPoint(selectedCells.current, id);
1283
1271
  selectedCells.current = newSelectedCells;
1284
1272
  rowsSelected.current = new Set([`${row}-${col}`]);
1285
- onAddClassBgSelectedCell(newSelectedCells, id);
1273
+ onAddBgSelectedCell(newSelectedCells, id);
1274
+ onAddBorderSelectedCell(newSelectedCells, id);
1286
1275
  addClassCellIndexSelected(new Set([`${row}-${col}`]), id);
1287
1276
  };
1288
1277
  const handleMouseEnterRowHeader = (row, col, e) => {
@@ -1310,11 +1299,11 @@ const GridEdit = props => {
1310
1299
  }
1311
1300
  }
1312
1301
  if (selectedCells.current && selectedCells.current.size > 0) {
1313
- onRemoveClassSelectedCell(selectedCells.current, id);
1302
+ onRemoveBgSelectedCell(selectedCells.current, id);
1314
1303
  }
1315
1304
  // setSelectedCells(newSelectedCells)
1316
1305
  selectedCells.current = newSelectedCells;
1317
- onAddClassBgSelectedCell(newSelectedCells, id);
1306
+ onAddBgSelectedCell(newSelectedCells, id);
1318
1307
  if (rowsSelected.current && rowsSelected.current.size > 0) {
1319
1308
  removeClassCellIndexSelected(rowsSelected.current, id);
1320
1309
  }
@@ -1692,9 +1681,6 @@ const GridEdit = props => {
1692
1681
  indexRow,
1693
1682
  key
1694
1683
  } = args;
1695
-
1696
- // const newRecord = getValues()
1697
-
1698
1684
  if (changeType === 'enter') {}
1699
1685
  if (changeType === 'blur') {
1700
1686
  const handleChangeCallback = callbackData => {
@@ -1763,7 +1749,6 @@ const GridEdit = props => {
1763
1749
  }
1764
1750
  if (e.key === 'Enter' || editType === 'date' || e.type === 'dblclick') {} else {
1765
1751
  setValue(col.dataIndex, editType === 'numeric' ? !isNaN(Number(e.key)) ? Number(e.key) : '' : e.key);
1766
- // setValue(col.dataIndex, e.key)
1767
1752
  }
1768
1753
  if (editType === 'select') {
1769
1754
  // setSearchValue(e.key)
@@ -1771,10 +1756,7 @@ const GridEdit = props => {
1771
1756
  }
1772
1757
  if (startSelectedCells.current && startSelectedCells.current.row !== undefined && startSelectedCells.current.col !== undefined) {
1773
1758
  setTimeout(() => {
1774
- // const input = document.querySelector(`.ui-rc-table-row[data-row-key="${selectedCell.row}"] .cell-editing[data-col-index="${selectedCell.col}"] input`) as HTMLInputElement;
1775
1759
  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`);
1776
- // const input = document.getElementById(`col${selectedCell.col}-record${selectedCell.row}`) as HTMLInputElement;
1777
-
1778
1760
  const select = document.querySelector(`div.cell-editing[tabindex="${startSelectedCells.current.col}"] .ant-select-selection-search input`);
1779
1761
  if (input) {
1780
1762
  input.focus();
@@ -1835,15 +1817,17 @@ const GridEdit = props => {
1835
1817
  // setSelectedCells(new Set([`${rowIndex}-${colIndex}`]));
1836
1818
 
1837
1819
  const cells = new Set([`${rowIndex}-${colIndex}`]);
1838
- console.log('cells', cells);
1839
1820
  if (selectedCells.current && selectedCells.current.size > 0) {
1840
- onRemoveClassSelectedCell(selectedCells.current, id);
1821
+ onRemoveBgSelectedCell(selectedCells.current, id);
1822
+ onRemoveBorderSelectedCell(selectedCells.current, id);
1841
1823
  }
1842
1824
  hideDraggingPoint(selectedCells.current, id);
1843
1825
  selectedCells.current = cells;
1826
+ setRangeCells(cells);
1844
1827
  setTimeout(() => {
1845
- onAddClassBgSelectedCell(selectedCells.current, id);
1846
- }, 10);
1828
+ onAddBgSelectedCell(selectedCells.current, id);
1829
+ onAddBorderSelectedCell(selectedCells.current, id);
1830
+ }, 50);
1847
1831
  showDraggingPoint(cells, id);
1848
1832
  };
1849
1833
  const focusNextCell = (editingCell, cellEditable) => {
@@ -1891,76 +1875,6 @@ const GridEdit = props => {
1891
1875
  focusNextCell(cellEdit, cell);
1892
1876
  }
1893
1877
  };
1894
-
1895
- // const getCellClass = (record: RecordType, rowIndex: number, colIndex: number) => {
1896
- //
1897
- //
1898
- // const cellKey = `${rowIndex}-${colIndex}`;
1899
- // const topCellKey = `${rowIndex + 1}-${colIndex}`;
1900
- // const leftCellKey = `${rowIndex}-${colIndex + 1}`;
1901
- // const rightCellKey = `${rowIndex}-${colIndex - 1}`;
1902
- //
1903
- // const isSelected = selectedCells.has(cellKey);
1904
- // const isTopSelected = selectedCells.has(topCellKey);
1905
- // const isLeftSelected = selectedCells.has(leftCellKey);
1906
- // const isRightSelected = selectedCells.has(rightCellKey);
1907
- //
1908
- //
1909
- // const isPasteSelected = pasteCells.has(cellKey);
1910
- // const isPasteLeftSelected = pasteCells.has(leftCellKey);
1911
- // const isPasteRightSelected = pasteCells.has(rightCellKey);
1912
- //
1913
- // const cellClass = isEditing(record) ? 'rc-ui-cell-editable cell-editing' : 'rc-ui-cell-editable cell-editable'
1914
- //
1915
- // const prevRecordEditing = flattenData(childrenColumnName, dataSource)[rowIndex + 1]
1916
- //
1917
- // const cellStart = getFirstSelectCell(selectedCells)
1918
- // const cellEnd = getLastSelectCell(selectedCells)
1919
- //
1920
- // const cellPasteStart = getFirstSelectCell(pasteCells)
1921
- // const cellPasteSEnd = getLastSelectCell(pasteCells)
1922
- //
1923
- //
1924
- // const isPasteBottom = pasteCells.size && cellPasteSEnd && rowIndex === Math.max(cellPasteStart.row, cellPasteSEnd.row)
1925
- //
1926
- //
1927
- // if (!isSelected && !isPasteSelected){
1928
- //
1929
- // // const isTop = prevRecordEditing && !isEditing(prevRecordEditing) && rowIndex === Math.min(cellStart.row - 1, cellEnd?.row);
1930
- // const isTop = prevRecordEditing && !isEditing(prevRecordEditing) && isTopMostInRegion(rowIndex + 1, colIndex, selectedCells)
1931
- //
1932
- // const isLeft = colIndex + 1 === Math.min(cellStart.col, cellEnd?.col);
1933
- // const isRight = colIndex - 1 === Math.max(cellStart.col, cellEnd?.col);
1934
- //
1935
- // const isPasteLeft = colIndex + 1 === Math.min(cellPasteStart.col, cellPasteSEnd?.col);
1936
- // const isPasteRight = colIndex - 1 === Math.max(cellPasteStart.col, cellPasteSEnd?.col);
1937
- //
1938
- //
1939
- // return (isTopSelected || isLeftSelected || isRightSelected ) ?
1940
- // `${cellClass} ${isTop ? `cell-border-top` : ''} ${isLeft ? `cell-border-left` : ''} ${isPasteBottom ? `cell-paste-border-bottom` : ''} ${isRight ? `next-cell-border-left` : ''}` :
1941
- //
1942
- // (isPasteLeftSelected || isPasteRightSelected) ? `${cellClass} ${isPasteLeft ? `cell-paste-border-left` : ''} ${isPasteRight ? `next-cell-paste-border-left` : ''}` :
1943
- //
1944
- // cellClass
1945
- //
1946
- // }
1947
- //
1948
- // const isBottom = isBottomMostInRegion(rowIndex, colIndex, selectedCells)
1949
- // // const isBottom = isBottomMostInRanges(rowIndex, colIndex, [selectedCells, ...ctrlCells])
1950
- //
1951
- // // const isRight = cellEnd && colIndex === Math.max(cellStart.col, cellEnd.col)
1952
- // const isRight = isRightMostInRegion(rowIndex, colIndex, selectedCells)
1953
- //
1954
- // const isLeft = colIndex === Math.min(cellStart.col, cellEnd?.col)
1955
- //
1956
- // const isPasteRight = cellPasteSEnd && colIndex === Math.max(cellPasteStart.col, cellPasteSEnd.col)
1957
- // const isPasteLeft = colIndex === Math.min(cellPasteStart.col, cellPasteSEnd?.col)
1958
- //
1959
- //
1960
- // 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` : '' }`
1961
- //
1962
- // };
1963
-
1964
1878
  const convertColumns = flatColumns2(columns.filter(it => it.visible !== false)).map((column, colIndex) => {
1965
1879
  if (!column?.field && !column?.key) {
1966
1880
  return column;
@@ -1996,17 +1910,9 @@ const GridEdit = props => {
1996
1910
  render: (value, record) => {
1997
1911
  const rowNumber = getRowNumber(dataSource, record[rowKey], rowKey);
1998
1912
  return /*#__PURE__*/React.createElement("div", {
1999
- className: classNames('ui-rc_cell-content ui-rc_cell-content--index', {
2000
-
2001
- // selected: rowsSelected.has(`${rowNumber}-${colIndex}`) ,
2002
-
2003
- // focus: selectedCells && Array.from(selectedCells).some((item: any) => item.startsWith(`${rowNumber}-`))
2004
- }),
1913
+ className: classNames('ui-rc_cell-content ui-rc_cell-content--index', {}),
2005
1914
  onMouseDown: event => handleMouseDownRowHeader(rowNumber, colIndex, column, event),
2006
- onMouseEnter: event => handleMouseEnterRowHeader(rowNumber, colIndex, event)
2007
-
2008
- // onClick={() => handleClickRowHeader(rowNumber, colIndex)}
2009
- ,
1915
+ onMouseEnter: event => handleMouseEnterRowHeader(rowNumber, colIndex, event),
2010
1916
  onMouseUp: handleMouseUp
2011
1917
  }, /*#__PURE__*/React.createElement("div", {
2012
1918
  className: 'ui-rc_content'
@@ -2026,17 +1932,16 @@ const GridEdit = props => {
2026
1932
  return {
2027
1933
  onKeyDown: event => {
2028
1934
  const key = getRowKey(record, dataSource.indexOf(record));
2029
- if (event.key === 'Control' && event.ctrlKey) {
2030
-
2031
- // setIsCtrlDown(true)
2032
- } else {
1935
+ if (event.key === 'Control' && event.ctrlKey) {} else {
2033
1936
  if (event.key.length === 1 && !event.ctrlKey && !event.metaKey || event.key === 'Enter') {
2034
1937
  if (record[rowKey] !== editingKey && isEditable(column, record)) {
2035
1938
  // ~~ khi editingKey = ''
2036
1939
  event.preventDefault();
2037
1940
  event.stopPropagation();
2038
1941
  handleEdit(record, column, column.editType, event);
2039
- onRemoveClassSelectedCell(selectedCells.current, id);
1942
+ onRemoveBgSelectedCell(selectedCells.current, id);
1943
+ onRemoveBorderSelectedCell(selectedCells.current, id);
1944
+ selectedCells.current = new Set();
2040
1945
  handleCellClick(rowNumber, record, column);
2041
1946
  const hasKey = mergedExpandedKeys.has(key);
2042
1947
  if (hasKey) {
@@ -2124,6 +2029,8 @@ const GridEdit = props => {
2124
2029
  onDoubleClick: event => {
2125
2030
  if (!isEditing(record) && record[rowKey] !== editingKey && isEditable(column, record)) {
2126
2031
  handleEdit(record, column, getEditType(column, record), event);
2032
+ onRemoveBgSelectedCell(selectedCells.current, id);
2033
+ onRemoveBorderSelectedCell(selectedCells.current, id);
2127
2034
  handleCellClick(rowNumber, record, column);
2128
2035
  }
2129
2036
  },
@@ -2149,7 +2056,6 @@ const GridEdit = props => {
2149
2056
  }
2150
2057
  },
2151
2058
  className: isEditing(record) ? 'rc-ui-cell-editable cell-editing' : `rc-ui-cell-editable cell-editable ${!isEditable(column, record) ? 'disable' : ''}`,
2152
- // className: getCellClass(record, rowNumber, colIndex),
2153
2059
  record,
2154
2060
  column: column,
2155
2061
  editType: getEditType(column, record),
@@ -2166,13 +2072,10 @@ const GridEdit = props => {
2166
2072
  editing: isEditing(record) && rowEditable?.(record) !== false && isEditable(column, record),
2167
2073
  cellEditing,
2168
2074
  t,
2169
- // editing: isEditing(record) && rowEditable?.(record) !== false,
2170
2075
  tabIndex: (rowIndex ?? 0) * columns.length + colIndex,
2171
2076
  style: isPasteDragging ? {
2172
2077
  cursor: "crosshair"
2173
2078
  } : {}
2174
-
2175
- // style: getStyle()
2176
2079
  };
2177
2080
  },
2178
2081
  onHeaderCell: (data, index) => {
@@ -2202,9 +2105,6 @@ const GridEdit = props => {
2202
2105
  const rowNumber = getRowNumber(dataSource, record[rowKey], rowKey);
2203
2106
  return /*#__PURE__*/React.createElement("div", {
2204
2107
  className: classNames('ui-rc_cell-content', {
2205
- // selected: selectedCells.has(`${record[rowKey]}-${colIndex}`)
2206
- // selected: selectedCells.has(`${rowNumber}-${colIndex}`) || currentCtrlCells.has(`${rowNumber}-${colIndex}`) || mergedSets([selectedCells, ...ctrlCells]).has(`${rowNumber}-${colIndex}`),
2207
- // selected: selectedCells.has(`${rowNumber}-${colIndex}`),
2208
2108
  // disable: !isEditable(column as any, record)
2209
2109
  }),
2210
2110
  onMouseDown: event => handleMouseDown(record, rowNumber, colIndex, event),
@@ -2224,7 +2124,7 @@ const GridEdit = props => {
2224
2124
  // }}
2225
2125
  }, /*#__PURE__*/React.createElement("div", {
2226
2126
  className: 'ui-rc_content'
2227
- }, renderContent(column, value, record, rowIndex, format)),
2127
+ }, renderContent(column, value, record, rowIndex, column.format ? typeof column.format === 'function' ? column.format(record) : column.format : format)),
2228
2128
  // selectedCells.current && selectedCells.current.size > 0 && getLastSelectCell(selectedCells.current).row === rowNumber &&
2229
2129
  // getLastSelectCell(selectedCells.current).col === colIndex &&
2230
2130
  // isEditable(column as any, record) &&
@@ -2236,8 +2136,6 @@ const GridEdit = props => {
2236
2136
  e.preventDefault();
2237
2137
  if (e.button === 0) {
2238
2138
  setIsPasteDragging(true);
2239
-
2240
- // isPasteDragging.current = true
2241
2139
  }
2242
2140
  },
2243
2141
  onDoubleClick: handlePointDoubleClick
@@ -2292,13 +2190,6 @@ const GridEdit = props => {
2292
2190
  }
2293
2191
  }));
2294
2192
  };
2295
- //
2296
- // const onSelectChange = (keys: any[]) => {
2297
- //
2298
- // console.log(keys)
2299
- // setMergedSelectedKeys(keys)
2300
- // }
2301
-
2302
2193
  const contextMenuClick = args => {
2303
2194
  if (args.item?.parentKey && args.item.parentKey === 'INSERT_BEFORE') {
2304
2195
  if (args.item.key === 'INSERT_BEFORE_ADV') {
@@ -2361,7 +2252,6 @@ const GridEdit = props => {
2361
2252
  position: 'relative'
2362
2253
  },
2363
2254
  ref: ref
2364
- // onMouseUp={handleMouseUp}
2365
2255
  }, /*#__PURE__*/React.createElement(TableContext.Provider, {
2366
2256
  value: {
2367
2257
  rowKey,
@@ -2401,9 +2291,7 @@ const GridEdit = props => {
2401
2291
  components: {
2402
2292
  ...components,
2403
2293
  body: {
2404
- // wrapper: () => <div></div>,
2405
2294
  cell: EditableCell
2406
- // cell: () => <EditableCell />,
2407
2295
  }
2408
2296
  },
2409
2297
  className: classNames(className, 'grid-editable'),
@@ -2464,27 +2352,15 @@ const GridEdit = props => {
2464
2352
  }
2465
2353
  },
2466
2354
  triggerChangeColumns: triggerChangeColumns,
2467
- clickHeaderToSort: false
2468
-
2469
- // rowSelection={ columns && columns.length === 0 ? undefined : {
2470
- // type: mode,
2471
- // columnWidth: columnWidth ?? 50 ,
2472
- // onChange: onSelectChange,
2473
- //
2474
- // selectedRowKeys: mergedSelectedKeys,
2475
- // preserveSelectedRowKeys: true,
2476
- // arrowKey: false
2477
- //
2478
- // }}
2479
- ,
2480
-
2355
+ clickHeaderToSort: false,
2481
2356
  isFilter: isFilter,
2482
2357
  setIsFilter: setIsFilter,
2483
2358
  contextMenuItems: contextMenuItems,
2484
2359
  contextMenuClick: contextMenuClick,
2485
2360
  onScroll: () => {
2486
2361
  if (selectedCells.current && selectedCells.current.size > 0) {
2487
- onAddClassBgSelectedCell(selectedCells.current, id);
2362
+ onAddBgSelectedCell(selectedCells.current, id);
2363
+ onAddBorderSelectedCell(selectedCells.current, id);
2488
2364
  showDraggingPoint(selectedCells.current, id);
2489
2365
  }
2490
2366
  if (rowsSelected && rowsSelected.current.size > 0) {
@@ -2496,9 +2372,8 @@ const GridEdit = props => {
2496
2372
  toastOptions: {
2497
2373
  className: 'react-hot-toast'
2498
2374
  }
2499
- }), /*#__PURE__*/React.createElement(Modal
2500
- // title="Thêm dòng"
2501
- , {
2375
+ }), /*#__PURE__*/React.createElement(Modal, {
2376
+ title: "Th\xEAm d\xF2ng",
2502
2377
  open: openModalAddRow.open,
2503
2378
  onOk: onOkAddRow,
2504
2379
  onCancel: hideModalAddRow,
@@ -84,7 +84,7 @@ export type ToolbarClick = {
84
84
  item: any;
85
85
  column: any;
86
86
  };
87
- export type ColumnTable<RecordType = AnyObject> = Omit<RcColumnType<RecordType>, 'headerTemplate' | 'title'> & {
87
+ export type ColumnTable<RecordType = AnyObject> = Omit<RcColumnType<RecordType>, 'headerTemplate' | 'title' | 'format' | 'commandItems'> & {
88
88
  field?: string;
89
89
  key?: any;
90
90
  type?: IColumnType;
@@ -93,7 +93,7 @@ export type ColumnTable<RecordType = AnyObject> = Omit<RcColumnType<RecordType>,
93
93
  isSummary?: boolean;
94
94
  summaryTemplate?: (data: number, key: string) => ReactElement | ReactNode;
95
95
  maxWidth?: string | number;
96
- format?: IFormat;
96
+ format?: IFormat | ((rowData: any) => IFormat);
97
97
  allowFiltering?: boolean;
98
98
  allowSorter?: boolean;
99
99
  operator?: FilterOperator;
@@ -207,12 +207,12 @@ export type GridTableProps<RecordType = AnyObject> = TableProps<RecordType>;
207
207
  export interface CommandItem {
208
208
  id: string;
209
209
  type?: string;
210
- visible?: boolean;
210
+ visible?: boolean | ((record: any) => boolean);
211
211
  title: string;
212
212
  color?: 'blue' | 'purple' | 'cyan' | 'green' | 'magenta' | 'pink' | 'red' | 'orange' | 'yellow' | 'volcano' | 'geekblue' | 'lime' | 'gold';
213
213
  tooltip?: string;
214
214
  icon?: ReactNode | ReactElement | (() => ReactNode | ReactElement);
215
- template?: ReactNode | ReactElement | (() => ReactNode | ReactElement);
215
+ template?: ReactNode | ReactElement | ((record: any) => ReactNode | ReactElement);
216
216
  client?: boolean;
217
217
  confirmDialog?: boolean;
218
218
  }