es-grid-template 1.3.7 → 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.
@@ -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)) {
833
+ if (!isEqualSet(cells, rangeCells)) {
834
+ onRemoveBgSelectedCell(rangeCells, id);
835
+ onRemoveBorderSelectedCell(rangeCells, id);
867
836
  hideDraggingPoint(selectedCells.current, 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
  }
@@ -883,7 +863,6 @@ const GridEdit = props => {
883
863
  const rowPasteLast = getLastSelectCell(pasteCells.current).row;
884
864
  const selectedArray = Array.from(selectedCells.current).map(key => {
885
865
  const [row, col] = key.split("-").map(Number);
886
- // @ts-ignore
887
866
  const columnKey = columns[col].field;
888
867
 
889
868
  // @ts-ignore
@@ -1003,13 +982,15 @@ const GridEdit = props => {
1003
982
 
1004
983
  /// cập nhật cell class
1005
984
  if (selectedCells.current && selectedCells.current.size > 0) {
1006
- onRemoveClassSelectedCell(selectedCells.current, id);
985
+ onRemoveBgSelectedCell(rangeCells, id);
986
+ onRemoveBorderSelectedCell(rangeCells, id);
1007
987
  }
1008
988
 
1009
989
  // selectedCells.current = sortedSetASC(mergedSet)
1010
990
  hideDraggingPoint(selectedCells.current, id);
1011
991
  selectedCells.current = sortedSetASC(mergedSet);
1012
- onAddClassBgSelectedCell(sortedSetASC(mergedSet), id);
992
+ onAddBgSelectedCell(sortedSetASC(mergedSet), id);
993
+ onAddBorderSelectedCell(sortedSetASC(mergedSet), id);
1013
994
  showDraggingPoint(sortedSetASC(mergedSet), id);
1014
995
 
1015
996
  // setPasteCells(new Set())
@@ -1079,6 +1060,9 @@ const GridEdit = props => {
1079
1060
  if (pasteCells && pasteCells.current.size > 0) {
1080
1061
  triggerDragPaste(pasteCells.current);
1081
1062
  } else {
1063
+ setRangeCells(selectedCells.current);
1064
+ onRemoveBorderSelectedCell(rangeCells, id);
1065
+ onAddBorderSelectedCell(selectedCells.current, id);
1082
1066
  const target = e.target;
1083
1067
  if (target.closest('.dragging-point')) {
1084
1068
  e.stopPropagation();
@@ -1138,10 +1122,10 @@ const GridEdit = props => {
1138
1122
  // setSelectedCells(newSelectedCells)
1139
1123
 
1140
1124
  if (selectedCells.current && selectedCells.current.size > 0) {
1141
- onRemoveClassSelectedCell(selectedCells.current, id);
1125
+ onRemoveBgSelectedCell(selectedCells.current, id);
1142
1126
  }
1143
1127
  selectedCells.current = newSelectedCells;
1144
- onAddClassBgSelectedCell(newSelectedCells, id);
1128
+ onAddBgSelectedCell(newSelectedCells, id);
1145
1129
  } else {
1146
1130
  // chọn vùng paste
1147
1131
 
@@ -1221,12 +1205,12 @@ const GridEdit = props => {
1221
1205
  // // setSelectedCells(newSelectedCells)
1222
1206
  //
1223
1207
  // if (selectedCells.current && selectedCells.current.size > 0) {
1224
- // onRemoveClassSelectedCell(selectedCells.current, id)
1208
+ // onRemoveBgSelectedCell(selectedCells.current, id)
1225
1209
  // }
1226
1210
  //
1227
1211
  // selectedCells.current = newSelectedCells
1228
1212
  //
1229
- // onAddClassBgSelectedCell(newSelectedCells, id)
1213
+ // onAddBgSelectedCell(newSelectedCells, id)
1230
1214
  //
1231
1215
  //
1232
1216
  // };
@@ -1242,13 +1226,15 @@ const GridEdit = props => {
1242
1226
  // setSelectedCells(new Set(newSelectedCells));
1243
1227
 
1244
1228
  if (selectedCells.current && selectedCells.current.size > 0) {
1245
- onRemoveClassSelectedCell(selectedCells.current, id);
1229
+ onRemoveBgSelectedCell(selectedCells.current, id);
1230
+ onRemoveBorderSelectedCell(selectedCells.current, id);
1246
1231
  }
1247
1232
  if (rowsSelected.current && rowsSelected.current.size > 0) {
1248
1233
  removeClassCellIndexSelected(rowsSelected.current, id);
1249
1234
  }
1250
1235
  selectedCells.current = newSelectedCells;
1251
- onAddClassBgSelectedCell(newSelectedCells, id);
1236
+ onAddBgSelectedCell(newSelectedCells, id);
1237
+ onAddBorderSelectedCell(newSelectedCells, id);
1252
1238
  hideDraggingPoint(selectedCells.current, id);
1253
1239
  showDraggingPoint(newSelectedCells, id);
1254
1240
  };
@@ -1274,7 +1260,8 @@ const GridEdit = props => {
1274
1260
  // setRowsSelected(new Set([`${row}-${col}`]));
1275
1261
 
1276
1262
  if (selectedCells.current && selectedCells.current.size > 0) {
1277
- onRemoveClassSelectedCell(selectedCells.current, id);
1263
+ onRemoveBgSelectedCell(selectedCells.current, id);
1264
+ onRemoveBorderSelectedCell(selectedCells.current, id);
1278
1265
  }
1279
1266
  if (rowsSelected.current && rowsSelected.current.size > 0) {
1280
1267
  removeClassCellIndexSelected(rowsSelected.current, id);
@@ -1282,7 +1269,8 @@ const GridEdit = props => {
1282
1269
  hideDraggingPoint(selectedCells.current, id);
1283
1270
  selectedCells.current = newSelectedCells;
1284
1271
  rowsSelected.current = new Set([`${row}-${col}`]);
1285
- onAddClassBgSelectedCell(newSelectedCells, id);
1272
+ onAddBgSelectedCell(newSelectedCells, id);
1273
+ onAddBorderSelectedCell(newSelectedCells, id);
1286
1274
  addClassCellIndexSelected(new Set([`${row}-${col}`]), id);
1287
1275
  };
1288
1276
  const handleMouseEnterRowHeader = (row, col, e) => {
@@ -1310,11 +1298,11 @@ const GridEdit = props => {
1310
1298
  }
1311
1299
  }
1312
1300
  if (selectedCells.current && selectedCells.current.size > 0) {
1313
- onRemoveClassSelectedCell(selectedCells.current, id);
1301
+ onRemoveBgSelectedCell(selectedCells.current, id);
1314
1302
  }
1315
1303
  // setSelectedCells(newSelectedCells)
1316
1304
  selectedCells.current = newSelectedCells;
1317
- onAddClassBgSelectedCell(newSelectedCells, id);
1305
+ onAddBgSelectedCell(newSelectedCells, id);
1318
1306
  if (rowsSelected.current && rowsSelected.current.size > 0) {
1319
1307
  removeClassCellIndexSelected(rowsSelected.current, id);
1320
1308
  }
@@ -1692,9 +1680,6 @@ const GridEdit = props => {
1692
1680
  indexRow,
1693
1681
  key
1694
1682
  } = args;
1695
-
1696
- // const newRecord = getValues()
1697
-
1698
1683
  if (changeType === 'enter') {}
1699
1684
  if (changeType === 'blur') {
1700
1685
  const handleChangeCallback = callbackData => {
@@ -1763,7 +1748,6 @@ const GridEdit = props => {
1763
1748
  }
1764
1749
  if (e.key === 'Enter' || editType === 'date' || e.type === 'dblclick') {} else {
1765
1750
  setValue(col.dataIndex, editType === 'numeric' ? !isNaN(Number(e.key)) ? Number(e.key) : '' : e.key);
1766
- // setValue(col.dataIndex, e.key)
1767
1751
  }
1768
1752
  if (editType === 'select') {
1769
1753
  // setSearchValue(e.key)
@@ -1771,10 +1755,7 @@ const GridEdit = props => {
1771
1755
  }
1772
1756
  if (startSelectedCells.current && startSelectedCells.current.row !== undefined && startSelectedCells.current.col !== undefined) {
1773
1757
  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
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`);
1776
- // const input = document.getElementById(`col${selectedCell.col}-record${selectedCell.row}`) as HTMLInputElement;
1777
-
1778
1759
  const select = document.querySelector(`div.cell-editing[tabindex="${startSelectedCells.current.col}"] .ant-select-selection-search input`);
1779
1760
  if (input) {
1780
1761
  input.focus();
@@ -1835,15 +1816,16 @@ const GridEdit = props => {
1835
1816
  // setSelectedCells(new Set([`${rowIndex}-${colIndex}`]));
1836
1817
 
1837
1818
  const cells = new Set([`${rowIndex}-${colIndex}`]);
1838
- console.log('cells', cells);
1839
1819
  if (selectedCells.current && selectedCells.current.size > 0) {
1840
- onRemoveClassSelectedCell(selectedCells.current, id);
1820
+ onRemoveBgSelectedCell(selectedCells.current, id);
1821
+ onRemoveBorderSelectedCell(selectedCells.current, id);
1841
1822
  }
1842
1823
  hideDraggingPoint(selectedCells.current, id);
1843
1824
  selectedCells.current = cells;
1844
1825
  setTimeout(() => {
1845
- onAddClassBgSelectedCell(selectedCells.current, id);
1846
- }, 10);
1826
+ onAddBgSelectedCell(selectedCells.current, id);
1827
+ onAddBorderSelectedCell(selectedCells.current, id);
1828
+ }, 50);
1847
1829
  showDraggingPoint(cells, id);
1848
1830
  };
1849
1831
  const focusNextCell = (editingCell, cellEditable) => {
@@ -1891,76 +1873,6 @@ const GridEdit = props => {
1891
1873
  focusNextCell(cellEdit, cell);
1892
1874
  }
1893
1875
  };
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
1876
  const convertColumns = flatColumns2(columns.filter(it => it.visible !== false)).map((column, colIndex) => {
1965
1877
  if (!column?.field && !column?.key) {
1966
1878
  return column;
@@ -1996,17 +1908,9 @@ const GridEdit = props => {
1996
1908
  render: (value, record) => {
1997
1909
  const rowNumber = getRowNumber(dataSource, record[rowKey], rowKey);
1998
1910
  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
- }),
1911
+ className: classNames('ui-rc_cell-content ui-rc_cell-content--index', {}),
2005
1912
  onMouseDown: event => handleMouseDownRowHeader(rowNumber, colIndex, column, event),
2006
- onMouseEnter: event => handleMouseEnterRowHeader(rowNumber, colIndex, event)
2007
-
2008
- // onClick={() => handleClickRowHeader(rowNumber, colIndex)}
2009
- ,
1913
+ onMouseEnter: event => handleMouseEnterRowHeader(rowNumber, colIndex, event),
2010
1914
  onMouseUp: handleMouseUp
2011
1915
  }, /*#__PURE__*/React.createElement("div", {
2012
1916
  className: 'ui-rc_content'
@@ -2026,17 +1930,16 @@ const GridEdit = props => {
2026
1930
  return {
2027
1931
  onKeyDown: event => {
2028
1932
  const key = getRowKey(record, dataSource.indexOf(record));
2029
- if (event.key === 'Control' && event.ctrlKey) {
2030
-
2031
- // setIsCtrlDown(true)
2032
- } else {
1933
+ if (event.key === 'Control' && event.ctrlKey) {} else {
2033
1934
  if (event.key.length === 1 && !event.ctrlKey && !event.metaKey || event.key === 'Enter') {
2034
1935
  if (record[rowKey] !== editingKey && isEditable(column, record)) {
2035
1936
  // ~~ khi editingKey = ''
2036
1937
  event.preventDefault();
2037
1938
  event.stopPropagation();
2038
1939
  handleEdit(record, column, column.editType, event);
2039
- onRemoveClassSelectedCell(selectedCells.current, id);
1940
+ onRemoveBgSelectedCell(selectedCells.current, id);
1941
+ onRemoveBorderSelectedCell(selectedCells.current, id);
1942
+ selectedCells.current = new Set();
2040
1943
  handleCellClick(rowNumber, record, column);
2041
1944
  const hasKey = mergedExpandedKeys.has(key);
2042
1945
  if (hasKey) {
@@ -2124,6 +2027,8 @@ const GridEdit = props => {
2124
2027
  onDoubleClick: event => {
2125
2028
  if (!isEditing(record) && record[rowKey] !== editingKey && isEditable(column, record)) {
2126
2029
  handleEdit(record, column, getEditType(column, record), event);
2030
+ onRemoveBgSelectedCell(selectedCells.current, id);
2031
+ onRemoveBorderSelectedCell(selectedCells.current, id);
2127
2032
  handleCellClick(rowNumber, record, column);
2128
2033
  }
2129
2034
  },
@@ -2149,7 +2054,6 @@ const GridEdit = props => {
2149
2054
  }
2150
2055
  },
2151
2056
  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
2057
  record,
2154
2058
  column: column,
2155
2059
  editType: getEditType(column, record),
@@ -2166,13 +2070,10 @@ const GridEdit = props => {
2166
2070
  editing: isEditing(record) && rowEditable?.(record) !== false && isEditable(column, record),
2167
2071
  cellEditing,
2168
2072
  t,
2169
- // editing: isEditing(record) && rowEditable?.(record) !== false,
2170
2073
  tabIndex: (rowIndex ?? 0) * columns.length + colIndex,
2171
2074
  style: isPasteDragging ? {
2172
2075
  cursor: "crosshair"
2173
2076
  } : {}
2174
-
2175
- // style: getStyle()
2176
2077
  };
2177
2078
  },
2178
2079
  onHeaderCell: (data, index) => {
@@ -2202,9 +2103,6 @@ const GridEdit = props => {
2202
2103
  const rowNumber = getRowNumber(dataSource, record[rowKey], rowKey);
2203
2104
  return /*#__PURE__*/React.createElement("div", {
2204
2105
  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
2106
  // disable: !isEditable(column as any, record)
2209
2107
  }),
2210
2108
  onMouseDown: event => handleMouseDown(record, rowNumber, colIndex, event),
@@ -2224,7 +2122,7 @@ const GridEdit = props => {
2224
2122
  // }}
2225
2123
  }, /*#__PURE__*/React.createElement("div", {
2226
2124
  className: 'ui-rc_content'
2227
- }, renderContent(column, value, record, rowIndex, format)),
2125
+ }, renderContent(column, value, record, rowIndex, column.format ? typeof column.format === 'function' ? column.format(record) : column.format : format)),
2228
2126
  // selectedCells.current && selectedCells.current.size > 0 && getLastSelectCell(selectedCells.current).row === rowNumber &&
2229
2127
  // getLastSelectCell(selectedCells.current).col === colIndex &&
2230
2128
  // isEditable(column as any, record) &&
@@ -2236,8 +2134,6 @@ const GridEdit = props => {
2236
2134
  e.preventDefault();
2237
2135
  if (e.button === 0) {
2238
2136
  setIsPasteDragging(true);
2239
-
2240
- // isPasteDragging.current = true
2241
2137
  }
2242
2138
  },
2243
2139
  onDoubleClick: handlePointDoubleClick
@@ -2292,13 +2188,6 @@ const GridEdit = props => {
2292
2188
  }
2293
2189
  }));
2294
2190
  };
2295
- //
2296
- // const onSelectChange = (keys: any[]) => {
2297
- //
2298
- // console.log(keys)
2299
- // setMergedSelectedKeys(keys)
2300
- // }
2301
-
2302
2191
  const contextMenuClick = args => {
2303
2192
  if (args.item?.parentKey && args.item.parentKey === 'INSERT_BEFORE') {
2304
2193
  if (args.item.key === 'INSERT_BEFORE_ADV') {
@@ -2361,7 +2250,6 @@ const GridEdit = props => {
2361
2250
  position: 'relative'
2362
2251
  },
2363
2252
  ref: ref
2364
- // onMouseUp={handleMouseUp}
2365
2253
  }, /*#__PURE__*/React.createElement(TableContext.Provider, {
2366
2254
  value: {
2367
2255
  rowKey,
@@ -2401,9 +2289,7 @@ const GridEdit = props => {
2401
2289
  components: {
2402
2290
  ...components,
2403
2291
  body: {
2404
- // wrapper: () => <div></div>,
2405
2292
  cell: EditableCell
2406
- // cell: () => <EditableCell />,
2407
2293
  }
2408
2294
  },
2409
2295
  className: classNames(className, 'grid-editable'),
@@ -2464,27 +2350,15 @@ const GridEdit = props => {
2464
2350
  }
2465
2351
  },
2466
2352
  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
-
2353
+ clickHeaderToSort: false,
2481
2354
  isFilter: isFilter,
2482
2355
  setIsFilter: setIsFilter,
2483
2356
  contextMenuItems: contextMenuItems,
2484
2357
  contextMenuClick: contextMenuClick,
2485
2358
  onScroll: () => {
2486
2359
  if (selectedCells.current && selectedCells.current.size > 0) {
2487
- onAddClassBgSelectedCell(selectedCells.current, id);
2360
+ onAddBgSelectedCell(selectedCells.current, id);
2361
+ onAddBorderSelectedCell(selectedCells.current, id);
2488
2362
  showDraggingPoint(selectedCells.current, id);
2489
2363
  }
2490
2364
  if (rowsSelected && rowsSelected.current.size > 0) {
@@ -2496,9 +2370,8 @@ const GridEdit = props => {
2496
2370
  toastOptions: {
2497
2371
  className: 'react-hot-toast'
2498
2372
  }
2499
- }), /*#__PURE__*/React.createElement(Modal
2500
- // title="Thêm dòng"
2501
- , {
2373
+ }), /*#__PURE__*/React.createElement(Modal, {
2374
+ title: "Th\xEAm d\xF2ng",
2502
2375
  open: openModalAddRow.open,
2503
2376
  onOk: onOkAddRow,
2504
2377
  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
  }