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.
@@ -24,16 +24,9 @@ var _hooks = require("../hooks");
24
24
  var _Message = _interopRequireDefault(require("../../Message/Message"));
25
25
  var _rcMasterUi = require("rc-master-ui");
26
26
  var _becoxyIcons = require("becoxy-icons");
27
+ var _faker = require("@faker-js/faker");
27
28
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
28
29
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
29
- // import Command from "../Command";
30
-
31
- // import useMergedState from "rc-util/lib/hooks/useMergedState";
32
-
33
- // import type {ContextMenuItem} from "../type";
34
- // import {ContextInfo, ContextMenuItem} from "../type";
35
- // import useLazyKVMap from "rc-master-ui/es/table/hooks/useLazyKVMap";
36
-
37
30
  const {
38
31
  Paragraph,
39
32
  Title
@@ -118,8 +111,7 @@ const defaultContext = [{
118
111
  }];
119
112
  const GridEdit = props => {
120
113
  const {
121
- // id = newGuid(),
122
- id,
114
+ id: tableId,
123
115
  tableRef,
124
116
  t,
125
117
  columns,
@@ -147,17 +139,6 @@ const GridEdit = props => {
147
139
  showDefaultContext,
148
140
  ...rest
149
141
  } = props;
150
-
151
- // const {
152
- // mode,
153
- // type,
154
- // checkboxOnly,
155
- // hideSelectAll,
156
- // columnWidth,
157
- // selectedRowKeys,
158
- // defaultSelectedRowKeys
159
- // } = selectionSettings || {}
160
-
161
142
  const ref = (0, _react.useRef)(null);
162
143
  const isSelecting = (0, _react.useRef)(false);
163
144
  const startCell = (0, _react.useRef)(null);
@@ -176,10 +157,10 @@ const GridEdit = props => {
176
157
  // quét vùng được paste - tiếp tục hiển thị con trỏ crosshair
177
158
  // const isPasteDragging = useRef(false);
178
159
 
179
- // const isPointEnter = useRef(false);
180
-
181
- // const [getRecordByKey] = useLazyKVMap(dataSource, childrenColumnName, getRowKey);
182
-
160
+ const id = _react.default.useMemo(() => {
161
+ return tableId ?? _faker.faker.string.alpha(20);
162
+ // return tableId ?? newGuid()
163
+ }, [tableId]);
183
164
  const itemsAdd = [{
184
165
  key: '10',
185
166
  label: '10 rows'
@@ -193,8 +174,8 @@ const GridEdit = props => {
193
174
  const [form] = _antd.Form.useForm();
194
175
  const [editingKey, setEditingKey] = (0, _react.useState)('');
195
176
  const [isFilter, setIsFilter] = _react.default.useState(false);
177
+ const [rangeCells, setRangeCells] = (0, _react.useState)(new Set());
196
178
 
197
- // const [selectedCells, setSelectedCells] = useState(new Set())
198
179
  // const [pasteCells, setPasteCells] = useState(new Set())
199
180
 
200
181
  // const defaultModalPaste = {open: false, rowIndex: -1, colIndex: -1, record: {}, rowsPasted: []}
@@ -229,17 +210,9 @@ const GridEdit = props => {
229
210
  // return [];
230
211
  });
231
212
  const mergedExpandedKeys = _react.default.useMemo(() => new Set(innerExpandedKeys || []), [innerExpandedKeys]);
232
-
233
- // const [mergedSelectedKeys, setMergedSelectedKeys] = useMergedState<any[]>(
234
- // [],
235
- // {
236
- // value: [],
237
- // },
238
- // );
239
-
240
213
  const rowsFocus = _react.default.useMemo(() => {
241
- return [...new Set(Array.from(selectedCells.current).map(item => parseInt(item.split('-')[0])))] ?? [];
242
- }, [selectedCells]);
214
+ return [...new Set(Array.from(rangeCells).map(item => parseInt(item.split('-')[0])))] ?? [];
215
+ }, [rangeCells]);
243
216
  const contextMenuItems = _react.default.useMemo(() => {
244
217
  const a = showDefaultContext !== false ? [...defaultContext] : [];
245
218
  const b = propsContext ? [...propsContext, {
@@ -319,6 +292,15 @@ const GridEdit = props => {
319
292
 
320
293
  // thêm n dòng bên trên
321
294
  const handleInsertBefore = (item, n) => {
295
+ //
296
+ (0, _hooks.onRemoveBgSelectedCell)(selectedCells.current, id);
297
+ (0, _hooks.onRemoveBorderSelectedCell)(selectedCells.current, id);
298
+ //
299
+
300
+ setTimeout(() => {
301
+ (0, _hooks.onAddBgSelectedCell)(selectedCells.current, id);
302
+ (0, _hooks.onAddBorderSelectedCell)(selectedCells.current, id);
303
+ }, 10);
322
304
  const defaultRowValue = (0, _hooks.getDefaultValue)(defaultValue);
323
305
  // const rowId = defaultRowValue && defaultRowValue.id ? defaultRowValue.id : newGuid()
324
306
 
@@ -393,9 +375,6 @@ const GridEdit = props => {
393
375
  //thêm 1 dòng bên dưới
394
376
  const handleInsertAfter = (item, n) => {
395
377
  const defaultRowValue = (0, _hooks.getDefaultValue)(defaultValue);
396
-
397
- // const rowId = defaultRowValue && defaultRowValue.id ? defaultRowValue.id : newGuid()
398
-
399
378
  const record = (0, _hooks.flattenData)(childrenColumnName, dataSource)[rowsFocus[rowsFocus.length - 1]];
400
379
 
401
380
  // const record = getRecordByKey()
@@ -428,8 +407,6 @@ const GridEdit = props => {
428
407
  rowId: (0, _hooks.newGuid)()
429
408
  });
430
409
  const index = newData.findIndex(obj => obj[rowKey] === record[rowKey]);
431
-
432
- // newData.splice(index + 1, 0, { ...defaultRowValue, rowId, parentId: null })
433
410
  newData.splice(index + 1, 0, ...newRows);
434
411
  triggerChangeData?.(newData, 'INSERT_AFTER');
435
412
  } else {
@@ -511,6 +488,10 @@ const GridEdit = props => {
511
488
  }
512
489
  };
513
490
  const handleDeleteRows = item => {
491
+ setTimeout(() => {
492
+ (0, _hooks.onAddBgSelectedCell)(selectedCells.current, id);
493
+ (0, _hooks.onAddBorderSelectedCell)(selectedCells.current, id);
494
+ });
514
495
  if (item.onClick) {
515
496
  item.onClick({
516
497
  toolbar: item
@@ -766,10 +747,8 @@ const GridEdit = props => {
766
747
  trigger,
767
748
  getValues,
768
749
  reset
769
- // formState: { errors }
770
750
  } = (0, _reactHookForm.useForm)({
771
751
  mode: 'onChange'
772
- // defaultValues,
773
752
  // resolver: yupResolver(formSchema)
774
753
  });
775
754
  const isEditing = record => record[rowKey] === editingKey;
@@ -805,25 +784,13 @@ const GridEdit = props => {
805
784
  // setSelectedCells(new Set())
806
785
  // setRowsSelected(new Set())
807
786
 
808
- (0, _hooks.onRemoveClassSelectedCell)(selectedCells.current, id);
787
+ (0, _hooks.onRemoveBgSelectedCell)(selectedCells.current, id);
788
+ (0, _hooks.onRemoveBorderSelectedCell)(selectedCells.current, id);
809
789
  (0, _hooks.hideDraggingPoint)(selectedCells.current, id);
810
790
  rowsSelected.current = new Set();
811
791
  selectedCells.current = new Set();
792
+ setRangeCells(new Set());
812
793
  }
813
-
814
- // if (tableBodies.length > 0) {
815
- // const tableBody = tableBodies[0]; // Chọn tbody đầu tiên (nếu có nhiều)
816
- //
817
- // if (!tableBody.contains(event.target as Node)) {
818
- // setEditingKey('')
819
- // isSelecting.current = false;
820
- // startCell.current = null;
821
- // setSelectedCells(new Set())
822
- // setRowsSelected(new Set())
823
- // } else {
824
- //
825
- // }
826
- // }
827
794
  };
828
795
  document.addEventListener("click", handleClickOutside);
829
796
  return () => {
@@ -871,16 +838,28 @@ const GridEdit = props => {
871
838
 
872
839
  const cells = new Set([`${row}-${col}`]);
873
840
  if (selectedCells.current && selectedCells.current.size > 0) {
874
- (0, _hooks.onRemoveClassSelectedCell)(selectedCells.current, id);
875
- if (!(0, _hooks.isEqualSet)(cells, selectedCells.current)) {
876
- (0, _hooks.hideDraggingPoint)(selectedCells.current, id);
841
+ if (!(0, _hooks.isEqualSet)(cells, rangeCells)) {
842
+ (0, _hooks.onRemoveBgSelectedCell)(rangeCells, id);
843
+ (0, _hooks.onRemoveBorderSelectedCell)(rangeCells, id);
844
+ (0, _hooks.hideDraggingPoint)(rangeCells, id);
877
845
  }
878
846
  }
879
- selectedCells.current = cells;
880
- (0, _hooks.onAddClassBgSelectedCell)(cells, id);
881
847
  if (rowsSelected.current && rowsSelected.current.size > 0) {
882
848
  (0, _hooks.removeClassCellIndexSelected)(rowsSelected.current, id);
883
849
  }
850
+ if (!(0, _hooks.isEqualSet)(cells, selectedCells.current)) {
851
+ selectedCells.current = cells;
852
+ if (editingKey) {
853
+ setTimeout(() => {
854
+ (0, _hooks.onAddBgSelectedCell)(cells, id);
855
+ (0, _hooks.onAddBorderSelectedCell)(cells, id);
856
+ }, 100);
857
+ } else {
858
+ (0, _hooks.onAddBgSelectedCell)(cells, id);
859
+ (0, _hooks.onAddBorderSelectedCell)(cells, id);
860
+ }
861
+ }
862
+
884
863
  // setRowsSelected(new Set())
885
864
  rowsSelected.current = new Set();
886
865
  }
@@ -888,12 +867,12 @@ const GridEdit = props => {
888
867
  };
889
868
  const triggerDragPaste = pastesArray => {
890
869
  const mergedSet = new Set([...selectedCells.current, ...pastesArray]);
870
+ const tmpCols = (0, _columns.flatColumns2)(columns.filter(it => it.visible !== false));
891
871
  const rowSelectedFirst = (0, _hooks.getFirstSelectCell)(selectedCells.current).row;
892
872
  const rowPasteLast = (0, _hooks.getLastSelectCell)(pasteCells.current).row;
893
873
  const selectedArray = Array.from(selectedCells.current).map(key => {
894
874
  const [row, col] = key.split("-").map(Number);
895
- // @ts-ignore
896
- const columnKey = columns[col].field;
875
+ const columnKey = tmpCols[col].field;
897
876
 
898
877
  // @ts-ignore
899
878
  return {
@@ -987,13 +966,13 @@ const GridEdit = props => {
987
966
  }
988
967
  rowValues.forEach((cellValue, colIndex) => {
989
968
  const targetCol = startCol + colIndex;
990
- if (targetCol >= columns.length) {
969
+ if (targetCol >= tmpCols.length) {
991
970
  // Không vượt quá số cột
992
971
  return;
993
972
  }
994
973
 
995
974
  // @ts-ignore
996
- const columnKey = columns[targetCol].field;
975
+ const columnKey = tmpCols[targetCol].field;
997
976
 
998
977
  // @ts-ignore
999
978
  newData[targetRow] = {
@@ -1012,13 +991,15 @@ const GridEdit = props => {
1012
991
 
1013
992
  /// cập nhật cell class
1014
993
  if (selectedCells.current && selectedCells.current.size > 0) {
1015
- (0, _hooks.onRemoveClassSelectedCell)(selectedCells.current, id);
994
+ (0, _hooks.onRemoveBgSelectedCell)(rangeCells, id);
995
+ (0, _hooks.onRemoveBorderSelectedCell)(rangeCells, id);
1016
996
  }
1017
997
 
1018
998
  // selectedCells.current = sortedSetASC(mergedSet)
1019
999
  (0, _hooks.hideDraggingPoint)(selectedCells.current, id);
1020
1000
  selectedCells.current = (0, _hooks.sortedSetASC)(mergedSet);
1021
- (0, _hooks.onAddClassBgSelectedCell)((0, _hooks.sortedSetASC)(mergedSet), id);
1001
+ (0, _hooks.onAddBgSelectedCell)((0, _hooks.sortedSetASC)(mergedSet), id);
1002
+ (0, _hooks.onAddBorderSelectedCell)((0, _hooks.sortedSetASC)(mergedSet), id);
1022
1003
  (0, _hooks.showDraggingPoint)((0, _hooks.sortedSetASC)(mergedSet), id);
1023
1004
 
1024
1005
  // setPasteCells(new Set())
@@ -1088,6 +1069,9 @@ const GridEdit = props => {
1088
1069
  if (pasteCells && pasteCells.current.size > 0) {
1089
1070
  triggerDragPaste(pasteCells.current);
1090
1071
  } else {
1072
+ setRangeCells(selectedCells.current);
1073
+ (0, _hooks.onRemoveBorderSelectedCell)(rangeCells, id);
1074
+ (0, _hooks.onAddBorderSelectedCell)(selectedCells.current, id);
1091
1075
  const target = e.target;
1092
1076
  if (target.closest('.dragging-point')) {
1093
1077
  e.stopPropagation();
@@ -1147,10 +1131,10 @@ const GridEdit = props => {
1147
1131
  // setSelectedCells(newSelectedCells)
1148
1132
 
1149
1133
  if (selectedCells.current && selectedCells.current.size > 0) {
1150
- (0, _hooks.onRemoveClassSelectedCell)(selectedCells.current, id);
1134
+ (0, _hooks.onRemoveBgSelectedCell)(selectedCells.current, id);
1151
1135
  }
1152
1136
  selectedCells.current = newSelectedCells;
1153
- (0, _hooks.onAddClassBgSelectedCell)(newSelectedCells, id);
1137
+ (0, _hooks.onAddBgSelectedCell)(newSelectedCells, id);
1154
1138
  } else {
1155
1139
  // chọn vùng paste
1156
1140
 
@@ -1230,12 +1214,12 @@ const GridEdit = props => {
1230
1214
  // // setSelectedCells(newSelectedCells)
1231
1215
  //
1232
1216
  // if (selectedCells.current && selectedCells.current.size > 0) {
1233
- // onRemoveClassSelectedCell(selectedCells.current, id)
1217
+ // onRemoveBgSelectedCell(selectedCells.current, id)
1234
1218
  // }
1235
1219
  //
1236
1220
  // selectedCells.current = newSelectedCells
1237
1221
  //
1238
- // onAddClassBgSelectedCell(newSelectedCells, id)
1222
+ // onAddBgSelectedCell(newSelectedCells, id)
1239
1223
  //
1240
1224
  //
1241
1225
  // };
@@ -1251,13 +1235,15 @@ const GridEdit = props => {
1251
1235
  // setSelectedCells(new Set(newSelectedCells));
1252
1236
 
1253
1237
  if (selectedCells.current && selectedCells.current.size > 0) {
1254
- (0, _hooks.onRemoveClassSelectedCell)(selectedCells.current, id);
1238
+ (0, _hooks.onRemoveBgSelectedCell)(selectedCells.current, id);
1239
+ (0, _hooks.onRemoveBorderSelectedCell)(selectedCells.current, id);
1255
1240
  }
1256
1241
  if (rowsSelected.current && rowsSelected.current.size > 0) {
1257
1242
  (0, _hooks.removeClassCellIndexSelected)(rowsSelected.current, id);
1258
1243
  }
1259
1244
  selectedCells.current = newSelectedCells;
1260
- (0, _hooks.onAddClassBgSelectedCell)(newSelectedCells, id);
1245
+ (0, _hooks.onAddBgSelectedCell)(newSelectedCells, id);
1246
+ (0, _hooks.onAddBorderSelectedCell)(newSelectedCells, id);
1261
1247
  (0, _hooks.hideDraggingPoint)(selectedCells.current, id);
1262
1248
  (0, _hooks.showDraggingPoint)(newSelectedCells, id);
1263
1249
  };
@@ -1283,7 +1269,8 @@ const GridEdit = props => {
1283
1269
  // setRowsSelected(new Set([`${row}-${col}`]));
1284
1270
 
1285
1271
  if (selectedCells.current && selectedCells.current.size > 0) {
1286
- (0, _hooks.onRemoveClassSelectedCell)(selectedCells.current, id);
1272
+ (0, _hooks.onRemoveBgSelectedCell)(selectedCells.current, id);
1273
+ (0, _hooks.onRemoveBorderSelectedCell)(selectedCells.current, id);
1287
1274
  }
1288
1275
  if (rowsSelected.current && rowsSelected.current.size > 0) {
1289
1276
  (0, _hooks.removeClassCellIndexSelected)(rowsSelected.current, id);
@@ -1291,7 +1278,8 @@ const GridEdit = props => {
1291
1278
  (0, _hooks.hideDraggingPoint)(selectedCells.current, id);
1292
1279
  selectedCells.current = newSelectedCells;
1293
1280
  rowsSelected.current = new Set([`${row}-${col}`]);
1294
- (0, _hooks.onAddClassBgSelectedCell)(newSelectedCells, id);
1281
+ (0, _hooks.onAddBgSelectedCell)(newSelectedCells, id);
1282
+ (0, _hooks.onAddBorderSelectedCell)(newSelectedCells, id);
1295
1283
  (0, _hooks.addClassCellIndexSelected)(new Set([`${row}-${col}`]), id);
1296
1284
  };
1297
1285
  const handleMouseEnterRowHeader = (row, col, e) => {
@@ -1319,11 +1307,11 @@ const GridEdit = props => {
1319
1307
  }
1320
1308
  }
1321
1309
  if (selectedCells.current && selectedCells.current.size > 0) {
1322
- (0, _hooks.onRemoveClassSelectedCell)(selectedCells.current, id);
1310
+ (0, _hooks.onRemoveBgSelectedCell)(selectedCells.current, id);
1323
1311
  }
1324
1312
  // setSelectedCells(newSelectedCells)
1325
1313
  selectedCells.current = newSelectedCells;
1326
- (0, _hooks.onAddClassBgSelectedCell)(newSelectedCells, id);
1314
+ (0, _hooks.onAddBgSelectedCell)(newSelectedCells, id);
1327
1315
  if (rowsSelected.current && rowsSelected.current.size > 0) {
1328
1316
  (0, _hooks.removeClassCellIndexSelected)(rowsSelected.current, id);
1329
1317
  }
@@ -1701,9 +1689,6 @@ const GridEdit = props => {
1701
1689
  indexRow,
1702
1690
  key
1703
1691
  } = args;
1704
-
1705
- // const newRecord = getValues()
1706
-
1707
1692
  if (changeType === 'enter') {}
1708
1693
  if (changeType === 'blur') {
1709
1694
  const handleChangeCallback = callbackData => {
@@ -1772,7 +1757,6 @@ const GridEdit = props => {
1772
1757
  }
1773
1758
  if (e.key === 'Enter' || editType === 'date' || e.type === 'dblclick') {} else {
1774
1759
  setValue(col.dataIndex, editType === 'numeric' ? !isNaN(Number(e.key)) ? Number(e.key) : '' : e.key);
1775
- // setValue(col.dataIndex, e.key)
1776
1760
  }
1777
1761
  if (editType === 'select') {
1778
1762
  // setSearchValue(e.key)
@@ -1780,10 +1764,7 @@ const GridEdit = props => {
1780
1764
  }
1781
1765
  if (startSelectedCells.current && startSelectedCells.current.row !== undefined && startSelectedCells.current.col !== undefined) {
1782
1766
  setTimeout(() => {
1783
- // const input = document.querySelector(`.ui-rc-table-row[data-row-key="${selectedCell.row}"] .cell-editing[data-col-index="${selectedCell.col}"] input`) as HTMLInputElement;
1784
1767
  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`);
1785
- // const input = document.getElementById(`col${selectedCell.col}-record${selectedCell.row}`) as HTMLInputElement;
1786
-
1787
1768
  const select = document.querySelector(`div.cell-editing[tabindex="${startSelectedCells.current.col}"] .ant-select-selection-search input`);
1788
1769
  if (input) {
1789
1770
  input.focus();
@@ -1844,15 +1825,17 @@ const GridEdit = props => {
1844
1825
  // setSelectedCells(new Set([`${rowIndex}-${colIndex}`]));
1845
1826
 
1846
1827
  const cells = new Set([`${rowIndex}-${colIndex}`]);
1847
- console.log('cells', cells);
1848
1828
  if (selectedCells.current && selectedCells.current.size > 0) {
1849
- (0, _hooks.onRemoveClassSelectedCell)(selectedCells.current, id);
1829
+ (0, _hooks.onRemoveBgSelectedCell)(selectedCells.current, id);
1830
+ (0, _hooks.onRemoveBorderSelectedCell)(selectedCells.current, id);
1850
1831
  }
1851
1832
  (0, _hooks.hideDraggingPoint)(selectedCells.current, id);
1852
1833
  selectedCells.current = cells;
1834
+ setRangeCells(cells);
1853
1835
  setTimeout(() => {
1854
- (0, _hooks.onAddClassBgSelectedCell)(selectedCells.current, id);
1855
- }, 10);
1836
+ (0, _hooks.onAddBgSelectedCell)(selectedCells.current, id);
1837
+ (0, _hooks.onAddBorderSelectedCell)(selectedCells.current, id);
1838
+ }, 50);
1856
1839
  (0, _hooks.showDraggingPoint)(cells, id);
1857
1840
  };
1858
1841
  const focusNextCell = (editingCell, cellEditable) => {
@@ -1900,76 +1883,6 @@ const GridEdit = props => {
1900
1883
  focusNextCell(cellEdit, cell);
1901
1884
  }
1902
1885
  };
1903
-
1904
- // const getCellClass = (record: RecordType, rowIndex: number, colIndex: number) => {
1905
- //
1906
- //
1907
- // const cellKey = `${rowIndex}-${colIndex}`;
1908
- // const topCellKey = `${rowIndex + 1}-${colIndex}`;
1909
- // const leftCellKey = `${rowIndex}-${colIndex + 1}`;
1910
- // const rightCellKey = `${rowIndex}-${colIndex - 1}`;
1911
- //
1912
- // const isSelected = selectedCells.has(cellKey);
1913
- // const isTopSelected = selectedCells.has(topCellKey);
1914
- // const isLeftSelected = selectedCells.has(leftCellKey);
1915
- // const isRightSelected = selectedCells.has(rightCellKey);
1916
- //
1917
- //
1918
- // const isPasteSelected = pasteCells.has(cellKey);
1919
- // const isPasteLeftSelected = pasteCells.has(leftCellKey);
1920
- // const isPasteRightSelected = pasteCells.has(rightCellKey);
1921
- //
1922
- // const cellClass = isEditing(record) ? 'rc-ui-cell-editable cell-editing' : 'rc-ui-cell-editable cell-editable'
1923
- //
1924
- // const prevRecordEditing = flattenData(childrenColumnName, dataSource)[rowIndex + 1]
1925
- //
1926
- // const cellStart = getFirstSelectCell(selectedCells)
1927
- // const cellEnd = getLastSelectCell(selectedCells)
1928
- //
1929
- // const cellPasteStart = getFirstSelectCell(pasteCells)
1930
- // const cellPasteSEnd = getLastSelectCell(pasteCells)
1931
- //
1932
- //
1933
- // const isPasteBottom = pasteCells.size && cellPasteSEnd && rowIndex === Math.max(cellPasteStart.row, cellPasteSEnd.row)
1934
- //
1935
- //
1936
- // if (!isSelected && !isPasteSelected){
1937
- //
1938
- // // const isTop = prevRecordEditing && !isEditing(prevRecordEditing) && rowIndex === Math.min(cellStart.row - 1, cellEnd?.row);
1939
- // const isTop = prevRecordEditing && !isEditing(prevRecordEditing) && isTopMostInRegion(rowIndex + 1, colIndex, selectedCells)
1940
- //
1941
- // const isLeft = colIndex + 1 === Math.min(cellStart.col, cellEnd?.col);
1942
- // const isRight = colIndex - 1 === Math.max(cellStart.col, cellEnd?.col);
1943
- //
1944
- // const isPasteLeft = colIndex + 1 === Math.min(cellPasteStart.col, cellPasteSEnd?.col);
1945
- // const isPasteRight = colIndex - 1 === Math.max(cellPasteStart.col, cellPasteSEnd?.col);
1946
- //
1947
- //
1948
- // return (isTopSelected || isLeftSelected || isRightSelected ) ?
1949
- // `${cellClass} ${isTop ? `cell-border-top` : ''} ${isLeft ? `cell-border-left` : ''} ${isPasteBottom ? `cell-paste-border-bottom` : ''} ${isRight ? `next-cell-border-left` : ''}` :
1950
- //
1951
- // (isPasteLeftSelected || isPasteRightSelected) ? `${cellClass} ${isPasteLeft ? `cell-paste-border-left` : ''} ${isPasteRight ? `next-cell-paste-border-left` : ''}` :
1952
- //
1953
- // cellClass
1954
- //
1955
- // }
1956
- //
1957
- // const isBottom = isBottomMostInRegion(rowIndex, colIndex, selectedCells)
1958
- // // const isBottom = isBottomMostInRanges(rowIndex, colIndex, [selectedCells, ...ctrlCells])
1959
- //
1960
- // // const isRight = cellEnd && colIndex === Math.max(cellStart.col, cellEnd.col)
1961
- // const isRight = isRightMostInRegion(rowIndex, colIndex, selectedCells)
1962
- //
1963
- // const isLeft = colIndex === Math.min(cellStart.col, cellEnd?.col)
1964
- //
1965
- // const isPasteRight = cellPasteSEnd && colIndex === Math.max(cellPasteStart.col, cellPasteSEnd.col)
1966
- // const isPasteLeft = colIndex === Math.min(cellPasteStart.col, cellPasteSEnd?.col)
1967
- //
1968
- //
1969
- // 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` : '' }`
1970
- //
1971
- // };
1972
-
1973
1886
  const convertColumns = (0, _columns.flatColumns2)(columns.filter(it => it.visible !== false)).map((column, colIndex) => {
1974
1887
  if (!column?.field && !column?.key) {
1975
1888
  return column;
@@ -2005,17 +1918,9 @@ const GridEdit = props => {
2005
1918
  render: (value, record) => {
2006
1919
  const rowNumber = (0, _hooks.getRowNumber)(dataSource, record[rowKey], rowKey);
2007
1920
  return /*#__PURE__*/_react.default.createElement("div", {
2008
- className: (0, _classnames.default)('ui-rc_cell-content ui-rc_cell-content--index', {
2009
-
2010
- // selected: rowsSelected.has(`${rowNumber}-${colIndex}`) ,
2011
-
2012
- // focus: selectedCells && Array.from(selectedCells).some((item: any) => item.startsWith(`${rowNumber}-`))
2013
- }),
1921
+ className: (0, _classnames.default)('ui-rc_cell-content ui-rc_cell-content--index', {}),
2014
1922
  onMouseDown: event => handleMouseDownRowHeader(rowNumber, colIndex, column, event),
2015
- onMouseEnter: event => handleMouseEnterRowHeader(rowNumber, colIndex, event)
2016
-
2017
- // onClick={() => handleClickRowHeader(rowNumber, colIndex)}
2018
- ,
1923
+ onMouseEnter: event => handleMouseEnterRowHeader(rowNumber, colIndex, event),
2019
1924
  onMouseUp: handleMouseUp
2020
1925
  }, /*#__PURE__*/_react.default.createElement("div", {
2021
1926
  className: 'ui-rc_content'
@@ -2035,17 +1940,16 @@ const GridEdit = props => {
2035
1940
  return {
2036
1941
  onKeyDown: event => {
2037
1942
  const key = getRowKey(record, dataSource.indexOf(record));
2038
- if (event.key === 'Control' && event.ctrlKey) {
2039
-
2040
- // setIsCtrlDown(true)
2041
- } else {
1943
+ if (event.key === 'Control' && event.ctrlKey) {} else {
2042
1944
  if (event.key.length === 1 && !event.ctrlKey && !event.metaKey || event.key === 'Enter') {
2043
1945
  if (record[rowKey] !== editingKey && (0, _hooks.isEditable)(column, record)) {
2044
1946
  // ~~ khi editingKey = ''
2045
1947
  event.preventDefault();
2046
1948
  event.stopPropagation();
2047
1949
  handleEdit(record, column, column.editType, event);
2048
- (0, _hooks.onRemoveClassSelectedCell)(selectedCells.current, id);
1950
+ (0, _hooks.onRemoveBgSelectedCell)(selectedCells.current, id);
1951
+ (0, _hooks.onRemoveBorderSelectedCell)(selectedCells.current, id);
1952
+ selectedCells.current = new Set();
2049
1953
  handleCellClick(rowNumber, record, column);
2050
1954
  const hasKey = mergedExpandedKeys.has(key);
2051
1955
  if (hasKey) {
@@ -2133,6 +2037,8 @@ const GridEdit = props => {
2133
2037
  onDoubleClick: event => {
2134
2038
  if (!isEditing(record) && record[rowKey] !== editingKey && (0, _hooks.isEditable)(column, record)) {
2135
2039
  handleEdit(record, column, (0, _hooks.getEditType)(column, record), event);
2040
+ (0, _hooks.onRemoveBgSelectedCell)(selectedCells.current, id);
2041
+ (0, _hooks.onRemoveBorderSelectedCell)(selectedCells.current, id);
2136
2042
  handleCellClick(rowNumber, record, column);
2137
2043
  }
2138
2044
  },
@@ -2158,7 +2064,6 @@ const GridEdit = props => {
2158
2064
  }
2159
2065
  },
2160
2066
  className: isEditing(record) ? 'rc-ui-cell-editable cell-editing' : `rc-ui-cell-editable cell-editable ${!(0, _hooks.isEditable)(column, record) ? 'disable' : ''}`,
2161
- // className: getCellClass(record, rowNumber, colIndex),
2162
2067
  record,
2163
2068
  column: column,
2164
2069
  editType: (0, _hooks.getEditType)(column, record),
@@ -2175,13 +2080,10 @@ const GridEdit = props => {
2175
2080
  editing: isEditing(record) && rowEditable?.(record) !== false && (0, _hooks.isEditable)(column, record),
2176
2081
  cellEditing,
2177
2082
  t,
2178
- // editing: isEditing(record) && rowEditable?.(record) !== false,
2179
2083
  tabIndex: (rowIndex ?? 0) * columns.length + colIndex,
2180
2084
  style: isPasteDragging ? {
2181
2085
  cursor: "crosshair"
2182
2086
  } : {}
2183
-
2184
- // style: getStyle()
2185
2087
  };
2186
2088
  },
2187
2089
  onHeaderCell: (data, index) => {
@@ -2211,9 +2113,6 @@ const GridEdit = props => {
2211
2113
  const rowNumber = (0, _hooks.getRowNumber)(dataSource, record[rowKey], rowKey);
2212
2114
  return /*#__PURE__*/_react.default.createElement("div", {
2213
2115
  className: (0, _classnames.default)('ui-rc_cell-content', {
2214
- // selected: selectedCells.has(`${record[rowKey]}-${colIndex}`)
2215
- // selected: selectedCells.has(`${rowNumber}-${colIndex}`) || currentCtrlCells.has(`${rowNumber}-${colIndex}`) || mergedSets([selectedCells, ...ctrlCells]).has(`${rowNumber}-${colIndex}`),
2216
- // selected: selectedCells.has(`${rowNumber}-${colIndex}`),
2217
2116
  // disable: !isEditable(column as any, record)
2218
2117
  }),
2219
2118
  onMouseDown: event => handleMouseDown(record, rowNumber, colIndex, event),
@@ -2233,7 +2132,7 @@ const GridEdit = props => {
2233
2132
  // }}
2234
2133
  }, /*#__PURE__*/_react.default.createElement("div", {
2235
2134
  className: 'ui-rc_content'
2236
- }, (0, _columns.renderContent)(column, value, record, rowIndex, format)),
2135
+ }, (0, _columns.renderContent)(column, value, record, rowIndex, column.format ? typeof column.format === 'function' ? column.format(record) : column.format : format)),
2237
2136
  // selectedCells.current && selectedCells.current.size > 0 && getLastSelectCell(selectedCells.current).row === rowNumber &&
2238
2137
  // getLastSelectCell(selectedCells.current).col === colIndex &&
2239
2138
  // isEditable(column as any, record) &&
@@ -2245,8 +2144,6 @@ const GridEdit = props => {
2245
2144
  e.preventDefault();
2246
2145
  if (e.button === 0) {
2247
2146
  setIsPasteDragging(true);
2248
-
2249
- // isPasteDragging.current = true
2250
2147
  }
2251
2148
  },
2252
2149
  onDoubleClick: handlePointDoubleClick
@@ -2301,13 +2198,6 @@ const GridEdit = props => {
2301
2198
  }
2302
2199
  }));
2303
2200
  };
2304
- //
2305
- // const onSelectChange = (keys: any[]) => {
2306
- //
2307
- // console.log(keys)
2308
- // setMergedSelectedKeys(keys)
2309
- // }
2310
-
2311
2201
  const contextMenuClick = args => {
2312
2202
  if (args.item?.parentKey && args.item.parentKey === 'INSERT_BEFORE') {
2313
2203
  if (args.item.key === 'INSERT_BEFORE_ADV') {
@@ -2370,7 +2260,6 @@ const GridEdit = props => {
2370
2260
  position: 'relative'
2371
2261
  },
2372
2262
  ref: ref
2373
- // onMouseUp={handleMouseUp}
2374
2263
  }, /*#__PURE__*/_react.default.createElement(_useContext.TableContext.Provider, {
2375
2264
  value: {
2376
2265
  rowKey,
@@ -2410,9 +2299,7 @@ const GridEdit = props => {
2410
2299
  components: {
2411
2300
  ...components,
2412
2301
  body: {
2413
- // wrapper: () => <div></div>,
2414
2302
  cell: _EditableCell.default
2415
- // cell: () => <EditableCell />,
2416
2303
  }
2417
2304
  },
2418
2305
  className: (0, _classnames.default)(className, 'grid-editable'),
@@ -2473,27 +2360,15 @@ const GridEdit = props => {
2473
2360
  }
2474
2361
  },
2475
2362
  triggerChangeColumns: triggerChangeColumns,
2476
- clickHeaderToSort: false
2477
-
2478
- // rowSelection={ columns && columns.length === 0 ? undefined : {
2479
- // type: mode,
2480
- // columnWidth: columnWidth ?? 50 ,
2481
- // onChange: onSelectChange,
2482
- //
2483
- // selectedRowKeys: mergedSelectedKeys,
2484
- // preserveSelectedRowKeys: true,
2485
- // arrowKey: false
2486
- //
2487
- // }}
2488
- ,
2489
-
2363
+ clickHeaderToSort: false,
2490
2364
  isFilter: isFilter,
2491
2365
  setIsFilter: setIsFilter,
2492
2366
  contextMenuItems: contextMenuItems,
2493
2367
  contextMenuClick: contextMenuClick,
2494
2368
  onScroll: () => {
2495
2369
  if (selectedCells.current && selectedCells.current.size > 0) {
2496
- (0, _hooks.onAddClassBgSelectedCell)(selectedCells.current, id);
2370
+ (0, _hooks.onAddBgSelectedCell)(selectedCells.current, id);
2371
+ (0, _hooks.onAddBorderSelectedCell)(selectedCells.current, id);
2497
2372
  (0, _hooks.showDraggingPoint)(selectedCells.current, id);
2498
2373
  }
2499
2374
  if (rowsSelected && rowsSelected.current.size > 0) {
@@ -2505,9 +2380,8 @@ const GridEdit = props => {
2505
2380
  toastOptions: {
2506
2381
  className: 'react-hot-toast'
2507
2382
  }
2508
- }), /*#__PURE__*/_react.default.createElement(_antd.Modal
2509
- // title="Thêm dòng"
2510
- , {
2383
+ }), /*#__PURE__*/_react.default.createElement(_antd.Modal, {
2384
+ title: "Th\xEAm d\xF2ng",
2511
2385
  open: openModalAddRow.open,
2512
2386
  onOk: onOkAddRow,
2513
2387
  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
  }