es-grid-template 1.4.4 → 1.4.6

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.
@@ -25,10 +25,11 @@ var _hooks = require("../hooks");
25
25
  var _Message = _interopRequireDefault(require("../../Message/Message"));
26
26
  var _rcMasterUi = require("rc-master-ui");
27
27
  var _becoxyIcons = require("becoxy-icons");
28
- var _faker = require("@faker-js/faker");
29
28
  var _InternalTable = require("../InternalTable");
30
29
  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); }
31
30
  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; }
31
+ // import {faker} from "@faker-js/faker";
32
+
32
33
  const {
33
34
  Paragraph,
34
35
  Title
@@ -181,16 +182,17 @@ const validateData = async (data, formSchema) => {
181
182
  };
182
183
  const GridEdit = props => {
183
184
  const {
184
- id: tableId,
185
+ id,
185
186
  tableRef,
186
187
  t,
187
188
  columns,
188
189
  dataSource,
189
190
  components,
190
191
  allowResizing,
191
- rowKey = 'rowId',
192
+ rowKey = 'id',
192
193
  selectionSettings,
193
194
  height,
195
+ scrollHeight,
194
196
  format,
195
197
  triggerChangeData,
196
198
  triggerChangeColumns,
@@ -232,20 +234,143 @@ const GridEdit = props => {
232
234
  const visibleCols = _react.default.useMemo(() => {
233
235
  return (0, _columns.flatColumns2)(columns.filter(it => it.visible !== false));
234
236
  }, [columns]);
235
- const id = _react.default.useMemo(() => {
236
- return tableId ?? _faker.faker.string.alpha(20);
237
- // return tableId ?? newGuid()
238
- }, [tableId]);
239
- const itemsAdd = [{
240
- key: '10',
241
- label: '10 rows'
242
- }, {
243
- key: '50',
244
- label: '50 rows'
245
- }, {
246
- key: '100',
247
- label: '100 rows'
248
- }];
237
+
238
+ // const id = React.useMemo(() => {
239
+ //
240
+ // return tableId ?? faker.string.alpha(20)
241
+ // // return tableId ?? newGuid()
242
+ //
243
+ // }, [tableId])
244
+
245
+ const itemsAdd = _react.default.useMemo(() => {
246
+ return [{
247
+ key: '10',
248
+ label: `10 ${t ? t('rows') : 'rows'}`
249
+ }, {
250
+ key: '50',
251
+ label: `50 ${t ? t('rows') : 'rows'}`
252
+ }, {
253
+ key: '100',
254
+ label: `100 ${t ? t('rows') : 'rows'}`
255
+ }];
256
+ }, [t]);
257
+
258
+ // const defaultContext = React.useMemo(() => {
259
+ // return [
260
+ // {
261
+ // key: 'INSERT_BEFORE',
262
+ // label: 'Thêm dòng bên trên',
263
+ // icon: <Plus fontSize={14} />,
264
+ // children: [
265
+ // {
266
+ // parentKey: 'INSERT_BEFORE',
267
+ // key: 'INSERT_BEFORE_1',
268
+ // label: 'Thêm 1 dòng',
269
+ // row: 1
270
+ // },
271
+ // {
272
+ // parentKey: 'INSERT_BEFORE',
273
+ // key: 'INSERT_BEFORE_10',
274
+ // label: 'Thêm 10 dòng',
275
+ // row: 10
276
+ // },
277
+ // {
278
+ // parentKey: 'INSERT_BEFORE',
279
+ // key: 'INSERT_BEFORE_50',
280
+ // label: 'Thêm 50 dòng',
281
+ // row: 50
282
+ // },
283
+ // {
284
+ // parentKey: 'INSERT_BEFORE',
285
+ // key: 'INSERT_BEFORE_100',
286
+ // label: 'Thêm 100 dòng',
287
+ // row: 100
288
+ // },
289
+ // {
290
+ // parentKey: 'INSERT_BEFORE',
291
+ // key: 'INSERT_BEFORE_ADV',
292
+ // label: 'Tùy chỉnh'
293
+ // }
294
+ // ]
295
+ // },
296
+ // {
297
+ // key: 'INSERT_AFTER',
298
+ // label: 'Thêm dòng bên dưới',
299
+ // icon: <Plus fontSize={14} />,
300
+ // children: [
301
+ // {
302
+ // parentKey: 'INSERT_AFTER',
303
+ // key: 'INSERT_AFTER_1',
304
+ // label: 'Thêm 1 dòng',
305
+ // row: 1
306
+ // },
307
+ // {
308
+ // parentKey: 'INSERT_AFTER',
309
+ // key: 'INSERT_AFTER_10',
310
+ // label: 'Thêm 10 dòng',
311
+ // row: 10
312
+ // },
313
+ // {
314
+ // parentKey: 'INSERT_AFTER',
315
+ // key: 'INSERT_AFTER_50',
316
+ // label: 'Thêm 50 dòng',
317
+ // row: 50
318
+ // },
319
+ // {
320
+ // parentKey: 'INSERT_AFTER',
321
+ // key: 'INSERT_AFTER_100',
322
+ // label: 'Thêm 100 dòng',
323
+ // row: 100
324
+ // },
325
+ // {
326
+ // parentKey: 'INSERT_AFTER',
327
+ // key: 'INSERT_AFTER_ADV',
328
+ // label: 'Tùy chỉnh'
329
+ // }
330
+ // ]
331
+ // },
332
+ // {
333
+ // key: 'INSERT_CHILDREN',
334
+ // // label: 'Insert item children',
335
+ // label: 'Thêm cấp con',
336
+ // icon: <Plus fontSize={14} />
337
+ // // children: [
338
+ // // {
339
+ // // parentKey: 'INSERT_AFTER',
340
+ // // key: 'INSERT_AFTER_1',
341
+ // // label: 'Thêm 1 dòng',
342
+ // // row: 1
343
+ // // },
344
+ // // {
345
+ // // parentKey: 'INSERT_AFTER',
346
+ // // key: 'INSERT_AFTER_10',
347
+ // // label: 'Thêm 10 dòng',
348
+ // // row: 10
349
+ // // },
350
+ // // {
351
+ // // parentKey: 'INSERT_AFTER',
352
+ // // key: 'INSERT_AFTER_50',
353
+ // // label: 'Thêm 50 dòng',
354
+ // // row: 50
355
+ // // },
356
+ // // {
357
+ // // parentKey: 'INSERT_AFTER',
358
+ // // key: 'INSERT_AFTER_100',
359
+ // // label: 'Thêm 100 dòng',
360
+ // // row: 100
361
+ // // },
362
+ // // {
363
+ // // parentKey: 'INSERT_AFTER',
364
+ // // key: 'INSERT_AFTER_ADV',
365
+ // // label: 'Tùy chỉnh'
366
+ // // }
367
+ // // ]
368
+ // },
369
+ // { key: 'DELETE_CONTENT', label: 'Xóa nội dung', icon: <Trash2 fontSize={14} /> },
370
+ // { key: 'DELETE_ROWS', label: 'Xóa dòng', icon: <Trash2 fontSize={14} /> }
371
+ // ]
372
+ // }, [])
373
+
249
374
  const [form] = _antd.Form.useForm();
250
375
  const [editingKey, setEditingKey] = (0, _react.useState)('');
251
376
  const [dataErrors, setDataErrors] = (0, _react.useState)([]);
@@ -442,7 +567,7 @@ const GridEdit = props => {
442
567
  triggerChangeData?.(newDataSource, 'INSERT_BEFORE');
443
568
  }
444
569
  }
445
- }, [dataSource, defaultValue, id, isFilter, rowKey, rowsFocus, triggerChangeData]);
570
+ }, [dataSource, defaultValue, isFilter, rowKey, rowsFocus, triggerChangeData]);
446
571
 
447
572
  //thêm 1 dòng bên dưới
448
573
  const handleInsertAfter = _react.default.useCallback((item, n) => {
@@ -527,7 +652,7 @@ const GridEdit = props => {
527
652
  });
528
653
  } else {
529
654
  const newData = [...dataSource];
530
- let newElement = {};
655
+ let newElement;
531
656
  if (!record.children || record.children.length === 0) {
532
657
  newElement = {
533
658
  ...record,
@@ -578,7 +703,7 @@ const GridEdit = props => {
578
703
  });
579
704
  triggerChangeData?.([...newData], 'DELETE_ROWS');
580
705
  }
581
- }, [dataSource, id, rowsFocus, triggerChangeData]);
706
+ }, [dataSource, rowsFocus, triggerChangeData]);
582
707
  const handleDeleteAll = _react.default.useCallback(() => {
583
708
  triggerChangeData?.([], 'INSERT_BEFORE');
584
709
  }, [triggerChangeData]);
@@ -913,10 +1038,7 @@ const GridEdit = props => {
913
1038
  }) => {
914
1039
  table[row - minRow][col - minCol] = value;
915
1040
  });
916
- let newRange = {
917
- combined: [],
918
- addedRows: []
919
- };
1041
+ let newRange;
920
1042
  if (rowPasteLast > rowSelectedFirst) {
921
1043
  // kéo xuóng
922
1044
  newRange = (0, _hooks.addRows8)(table, (0, _hooks.getRowsPasteIndex)(pastesArray).length);
@@ -996,277 +1118,549 @@ const GridEdit = props => {
996
1118
  }
997
1119
  pasteCells.current = new Set();
998
1120
  };
999
- const handlePointDoubleClick = e => {
1000
- // e.preventDefault()
1001
- e.stopPropagation();
1002
- const colStart = (0, _hooks.getFirstSelectCell)(selectedCells.current).col;
1003
- const colEnd = (0, _hooks.getLastSelectCell)(selectedCells.current).col;
1004
- const startPasteRow = (0, _hooks.getLastSelectCell)(selectedCells.current).row;
1005
- const newPasteCells = new Set();
1006
- for (let r = Math.min(startPasteRow, dataSource.length - 1) + 1; r <= Math.max(startPasteRow, dataSource.length - 1); r++) {
1007
- for (let c = Math.min(colStart, colStart); c <= Math.max(colStart, colEnd); c++) {
1008
- newPasteCells.add(`${r}-${c}`);
1009
- }
1010
- }
1011
- (0, _hooks.hideDraggingPoint)(selectedCells.current, id);
1012
- triggerDragPaste(newPasteCells);
1013
- };
1014
- const handleMouseDown = (record, row, col, e) => {
1015
- if (e.button === 2) {
1016
- e.stopPropagation();
1017
- return;
1018
- }
1019
- if (editingKey && editingKey === record[rowKey]) {
1020
- return;
1021
- }
1022
- if (record[rowKey] !== editingKey && editingKey !== '') {
1023
- setEditingKey('');
1024
- }
1121
+ const handlePasted = (record, indexCol, rowNumber, pasteData) => {
1122
+ const rows = pasteData.slice(0, onCellPaste?.maxRowsPaste ?? 200);
1123
+ if (!record?.parentId) {
1124
+ // Cập nhật data mới
1125
+ const newData = [...dataSource];
1025
1126
 
1026
- // isDragMouse.current = true
1027
- isMouseDown.current = true;
1028
- if (e.ctrlKey) {
1029
- isSelecting.current = true;
1030
- startCell.current = {
1031
- row,
1032
- col
1033
- };
1127
+ // const indexRows = newData.findIndex((it) => it[rowKey as any] === record[rowKey])
1034
1128
 
1035
- // const cell: any = new Set([`${row}-${col}`])
1129
+ // Lấy vị trí bắt đầu
1130
+ // const { row: startRow, col: startCol } = selectedCell;
1131
+ const startRow = newData.findIndex(it => it[rowKey] === record[rowKey]);
1132
+ const startCol = indexCol;
1036
1133
 
1037
- // setCurrentCtrlCells(cell)
1038
- } else {
1039
- isSelecting.current = true;
1040
- startCell.current = {
1041
- row,
1042
- col
1043
- };
1044
- const target = e.target;
1045
- if (target.closest('.dragging-point')) {
1046
- e.stopPropagation();
1047
- e.preventDefault();
1048
- return; // Không xử lý gì cả
1049
- } else {
1050
- // setStartSelectedCell({row, col})
1134
+ // const flattData = flattenArray(newData);
1051
1135
 
1052
- startSelectedCells.current = {
1053
- row,
1054
- col
1055
- };
1136
+ const pastedRows = [];
1137
+ const pastedColumns = new Set();
1138
+ rows.forEach((rowValues, rowIndex) => {
1139
+ const targetRow = startRow + rowIndex;
1056
1140
 
1057
- // setSelectedCells(new Set([`${row}-${col}`]));
1141
+ // Nếu vượt quá số dòng hiện có, thêm dòng mới
1142
+ if (targetRow >= newData.length) {
1143
+ // @ts-ignore
1144
+ // newData.push({ id: newGuid()});
1145
+ newData.push({
1146
+ id: undefined,
1147
+ rowId: (0, _hooks.newGuid)()
1148
+ });
1149
+ }
1150
+ rowValues.forEach((cellValue, colIndex) => {
1151
+ const targetCol = startCol + colIndex;
1152
+ if (targetCol >= visibleCols.length) {
1153
+ // Không vượt quá số cột
1154
+ return;
1155
+ }
1156
+ if (visibleCols[targetCol].editEnable) {
1157
+ // @ts-ignore
1158
+ const columnKey = visibleCols[targetCol].field;
1058
1159
 
1059
- const cells = new Set([`${row}-${col}`]);
1060
- if (selectedCells.current && selectedCells.current.size > 0) {
1061
- if (!(0, _hooks.isEqualSet)(cells, rangeCells)) {
1062
- // onRemoveBgSelectedCell(rangeCells, id)
1063
- // onRemoveBorderSelectedCell(rangeCells, id)
1064
- (0, _hooks.hideDraggingPoint)(rangeCells, id);
1065
- (0, _hooks.onRemoveBgCellIndex)(selectedCells.current, id);
1160
+ // @ts-ignore
1161
+ newData[targetRow] = {
1162
+ ...newData[targetRow],
1163
+ [columnKey]: cellValue.trim()
1164
+ };
1165
+ pastedColumns.add(columnKey);
1066
1166
  }
1067
- }
1068
- if (rowsSelected.current && rowsSelected.current.size > 0) {
1069
- (0, _hooks.removeClassCellIndexSelected)(rowsSelected.current, id);
1070
- }
1071
- if (!(0, _hooks.isEqualSet)(cells, selectedCells.current)) {
1072
- (0, _hooks.onRemoveBgSelectedCell)(selectedCells.current, id);
1073
- (0, _hooks.hideDraggingPoint)(selectedCells.current, id);
1074
- selectedCells.current = cells;
1075
- // setRangeCells(cells)
1167
+ });
1076
1168
 
1077
- (0, _hooks.onAddBgCellIndex)(cells, id);
1078
- (0, _hooks.onAddBorderSelectedCell)(cells, id);
1079
- (0, _hooks.onAddBgSelectedCell)(selectedCells.current, id, false);
1080
- (0, _hooks.showDraggingPoint)(selectedCells.current, id);
1081
- }
1169
+ // Lưu dòng được paste
1170
+ pastedRows.push(newData[targetRow]);
1171
+ });
1172
+ const pastedColumnsArray = Array.from(pastedColumns) ?? [];
1173
+ triggerPaste?.(pastedRows, pastedColumnsArray, newData);
1174
+ } else {
1175
+ // Cập nhật data mới
1176
+ const newData = [...dataSource];
1177
+ const parent = (0, _hooks.findItemByKey)(newData, rowKey, record.parentId);
1082
1178
 
1083
- // setRowsSelected(new Set())
1084
- rowsSelected.current = new Set();
1085
- }
1086
- }
1087
- };
1088
- const handleMouseUp = e => {
1089
- isSelecting.current = false;
1090
- startCell.current = null;
1091
- isSelectingRow.current = false;
1092
- rowStart.current = null;
1093
- isDragMouse.current = false;
1094
- isMouseDown.current = false;
1095
- setIsPasteDragging(false);
1096
- if (e.ctrlKey) {
1179
+ // Cập nhật childData mới
1180
+ const childData = parent?.children ? [...parent.children] : [];
1097
1181
 
1098
- // setCtrlCells([...ctrlCells, currentCtrlCells])
1099
- }
1182
+ // Lấy vị trí bắt đầu
1183
+ // const { row: startRow, col: startCol } = selectedCell;
1184
+ const startRow = childData.findIndex(it => it[rowKey] === record[rowKey]);
1185
+ const startCol = indexCol;
1186
+ const pastedRows = [];
1187
+ const pastedColumns = new Set();
1188
+ rows.forEach((rowValues, rowIndex) => {
1189
+ const targetRow = startRow + rowIndex;
1100
1190
 
1101
- // nếu ctrlCell length > 0 thì set selectCells
1191
+ // Nếu vượt quá số dòng hiện có, thêm dòng mới
1192
+ if (targetRow >= childData.length) {
1193
+ childData.push({
1194
+ id: undefined,
1195
+ rowId: (0, _hooks.newGuid)(),
1196
+ parentId: parent[rowKey ?? 'id']
1197
+ });
1198
+ }
1199
+ rowValues.forEach((cellValue, colIndex) => {
1200
+ const targetCol = startCol + colIndex;
1201
+ if (targetCol >= visibleCols.length) {
1202
+ // Không vượt quá số cột
1203
+ return;
1204
+ }
1205
+ if (visibleCols[targetCol].editEnable) {
1206
+ // @ts-ignore
1207
+ const columnKey = visibleCols[targetCol].field;
1102
1208
 
1103
- if (pasteCells && pasteCells.current.size > 0) {
1104
- triggerDragPaste(pasteCells.current);
1105
- } else {
1106
- setRangeCells(selectedCells.current);
1107
- const target = e.target;
1108
- if (target.closest('.dragging-point')) {
1109
- e.stopPropagation();
1110
- e.preventDefault();
1111
- return; // Không xử lý gì cả
1112
- }
1113
- if (selectedCells.current && selectedCells.current.size > 1) {
1114
- (0, _hooks.hideDraggingPoint)(selectedCells.current, id);
1115
- (0, _hooks.onAddBorderSelectedCell)(selectedCells.current, id);
1209
+ // @ts-ignore
1210
+ childData[targetRow] = {
1211
+ ...childData[targetRow],
1212
+ [columnKey]: cellValue.trim()
1213
+ };
1214
+ pastedColumns.add(columnKey);
1215
+ }
1216
+ });
1116
1217
 
1117
- // showDraggingPoint(selectedCells.current, id)
1118
- }
1119
- (0, _hooks.showDraggingPoint)(selectedCells.current, id);
1120
- // onAddBorderSelectedCell(selectedCells.current, id)
1218
+ // Lưu dòng được paste
1219
+ pastedRows.push(childData[targetRow]);
1220
+ });
1221
+ const pastedColumnsArray = Array.from(pastedColumns) ?? [];
1222
+ const newRowData = {
1223
+ ...parent,
1224
+ children: childData
1225
+ };
1226
+ const newDataSource = (0, _hooks.updateArrayByKey)(newData, newRowData, rowKey);
1227
+ triggerPaste?.(pastedRows, pastedColumnsArray, newDataSource);
1121
1228
  }
1122
1229
  };
1123
- const handleMouseEnter = (row, col, e) => {
1124
- if (!isSelecting.current || !startCell.current) {
1125
- return;
1126
- }
1127
- const {
1128
- row: startRow,
1129
- col: startCol
1130
- } = startCell.current;
1131
- if (e.ctrlKey) {
1132
- // const newCtrlCells = new Set();
1133
- // for (let r = Math.min(startRow, row); r <= Math.max(startRow, row); r++) {
1134
- // for (let c = Math.min(startCol, col); c <= Math.max(startCol, col); c++) {
1135
- // newCtrlCells.add(`${r}-${c}`)
1136
- // }
1137
- // }
1138
-
1139
- // setCurrentCtrlCells(newCtrlCells)
1140
-
1141
- return;
1142
- }
1143
- if (!isPasteDragging) {
1144
- // chọn vùng copy
1145
-
1146
- // setSelectIsDragging(true)
1147
-
1148
- setIsPasteDragging(false);
1149
- // isPasteDragging.current = false
1230
+ const handlePaste = (record, indexCol, rowNumber, e) => {
1231
+ // const clipboard: any = (e.clipboardData || (window && window?.Clipboard)).getData("text")
1232
+ const pasteData = e.clipboardData.getData("text/plain");
1150
1233
 
1151
- const newSelectedCells = new Set();
1152
- for (let r = Math.min(startRow, row); r <= Math.max(startRow, row); r++) {
1153
- for (let c = Math.min(startCol, col); c <= Math.max(startCol, col); c++) {
1154
- newSelectedCells.add(`${r}-${c}`);
1155
- }
1156
- }
1234
+ // Chuyển đổi dữ liệu từ clipboard thành mảng
1235
+ const rowsPasted = pasteData.split("\n").map(row =>
1236
+ // const rows = pasteData.split("\n").map((row: any) =>
1237
+ row.replace(/\r/g, "").split("\t"));
1238
+ if (rowsPasted.length > (onCellPaste?.maxRowsPaste ?? 200)) {
1239
+ // bật popup thông báo
1157
1240
 
1158
- // setSelectedCells(newSelectedCells)
1159
-
1160
- if (selectedCells.current && selectedCells.current.size > 0) {
1161
- (0, _hooks.onRemoveBgSelectedCell)(selectedCells.current, id);
1162
- }
1163
- selectedCells.current = newSelectedCells;
1164
- (0, _hooks.onAddBgSelectedCell)(newSelectedCells, id);
1165
- } else {
1166
- // chọn vùng paste
1167
-
1168
- // setSelectIsDragging(false)
1169
-
1170
- // setIsPasteDragging(true) ////////
1171
-
1172
- const newSelectedCells = new Set();
1173
- for (let r = Math.min(startRow, row); r <= Math.max(startRow, row); r++) {
1174
- for (let c = Math.min(startCol, col); c <= Math.max(startCol, col); c++) {
1175
- newSelectedCells.add(`${r}-${c}`);
1176
- }
1177
- }
1178
- const colStart = (0, _hooks.getFirstSelectCell)(selectedCells.current).col;
1179
- const colEnd = (0, _hooks.getLastSelectCell)(selectedCells.current).col;
1180
- const rowSelectedEnd = (0, _hooks.getLastSelectCell)(selectedCells.current).row;
1181
- if (row >= rowSelectedEnd) {
1182
- // kéo xuống dưới
1183
-
1184
- const newPasteCells = new Set();
1185
- for (let r = Math.min(startRow, row) + 1; r <= Math.max(startRow, row); r++) {
1186
- for (let c = Math.min(colStart, col); c <= Math.max(colStart, colEnd); c++) {
1187
- newPasteCells.add(`${r}-${c}`);
1188
- }
1189
- }
1190
-
1191
- // setPasteCells(newPasteCells)
1192
-
1193
- if (pasteCells.current && pasteCells.current.size > 0) {
1194
- (0, _hooks.removeClassBorderPasteCell)(pasteCells.current, 'down', id);
1195
- }
1196
- pasteCells.current = newPasteCells;
1197
- (0, _hooks.addClassBorderPasteCell)(newPasteCells, 'down', id);
1198
- }
1199
- if (row < rowSelectedEnd) {
1200
- // kéo lên trên
1201
-
1202
- const rowSelectedStart = (0, _hooks.getFirstSelectCell)(selectedCells.current).row;
1203
- if (row < rowSelectedStart) {
1204
- const newPasteCells = new Set();
1205
- for (let r = Math.min(rowSelectedStart, row); r <= Math.max(rowSelectedStart, row) - 1; r++) {
1206
- for (let c = Math.min(colStart, col); c <= Math.max(colStart, colEnd); c++) {
1207
- newPasteCells.add(`${r}-${c}`);
1208
- }
1241
+ _antd.Modal.confirm({
1242
+ content: /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(Paragraph, {
1243
+ style: {
1244
+ marginBottom: '.25rem',
1245
+ fontSize: 14
1209
1246
  }
1210
-
1211
- // setPasteCells(newPasteCells)
1212
-
1213
- if (pasteCells.current && pasteCells.current.size > 0) {
1214
- (0, _hooks.removeClassBorderPasteCell)(pasteCells.current, 'up', id);
1247
+ }, "D\u1EEF li\u1EC7u sao ch\xE9p v\u01B0\u1EE3t qu\xE1 s\u1ED1 d\xF2ng cho ph\xE9p (500 d\xF2ng).Ph\u1EA7n m\u1EC1n s\u1EBD ch\u1EC9 l\u1EA5y 500 d\xF2ng \u0111\u1EA7u ti\xEAn."), /*#__PURE__*/_react.default.createElement(Title, {
1248
+ level: 5,
1249
+ style: {
1250
+ marginTop: '.75rem'
1215
1251
  }
1216
- pasteCells.current = newPasteCells;
1217
- (0, _hooks.addClassBorderPasteCell)(newPasteCells, 'up', id);
1252
+ }, "B\u1EA1n c\xF3 mu\u1ED1n ti\u1EBFp t\u1EE5c sao ch\xE9p kh\xF4ng?")),
1253
+ centered: true,
1254
+ className: 'be-popup-container',
1255
+ onOk: () => {
1256
+ handlePasted(record, indexCol, rowNumber, rowsPasted);
1218
1257
  }
1219
- }
1220
- if (col > colEnd) {
1221
- // kéo sang phải
1222
- }
1223
- if (row < colStart) {
1224
- // kéo sang trái
1225
- }
1258
+ // footer: (_, { OkBtn, CancelBtn }) => (
1259
+ // <>
1260
+ // <OkBtn />
1261
+ // <CancelBtn />
1262
+ // </>
1263
+ // ),
1264
+ });
1265
+ } else {
1266
+ handlePasted(record, indexCol, rowNumber, rowsPasted);
1226
1267
  }
1268
+
1269
+ // const rows = rowsPasted.slice(0, (onCellPaste?.maxRowsPaste ?? 200));
1270
+ //
1271
+ //
1272
+ // if (!record?.parentId ) {
1273
+ //
1274
+ // // Cập nhật data mới
1275
+ // const newData = [...dataSource];
1276
+ //
1277
+ // // @ts-ignore
1278
+ // const indexRows = newData.findIndex((it) => it[rowKey] === record[rowKey])
1279
+ //
1280
+ // // Lấy vị trí bắt đầu
1281
+ // // const { row: startRow, col: startCol } = selectedCell;
1282
+ // const startRow = indexRows
1283
+ // const startCol = indexCol
1284
+ //
1285
+ //
1286
+ //
1287
+ // // const flattData = flattenArray(newData);
1288
+ //
1289
+ // const pastedRows: RecordType[] = [];
1290
+ // const pastedColumns = new Set()
1291
+ //
1292
+ //
1293
+ // rows.forEach((rowValues: any, rowIndex: any) => {
1294
+ // const targetRow = startRow + rowIndex;
1295
+ //
1296
+ // // Nếu vượt quá số dòng hiện có, thêm dòng mới
1297
+ // if (targetRow >= newData.length) {
1298
+ // // @ts-ignore
1299
+ // // newData.push({ id: newGuid()});
1300
+ // newData.push({ id: undefined, rowId: newGuid()});
1301
+ // }
1302
+ //
1303
+ // rowValues.forEach((cellValue: any, colIndex: any) => {
1304
+ // const targetCol = startCol + colIndex;
1305
+ // if (targetCol >= columns.length) { // Không vượt quá số cột
1306
+ // return
1307
+ // }
1308
+ //
1309
+ // if (columns[targetCol].editEnable) {
1310
+ // // @ts-ignore
1311
+ // const columnKey = columns[targetCol].field;
1312
+ //
1313
+ // // @ts-ignore
1314
+ // newData[targetRow] = { ...newData[targetRow], [columnKey]: cellValue.trim() };
1315
+ // pastedColumns.add(columnKey);
1316
+ // }
1317
+ //
1318
+ // });
1319
+ //
1320
+ // // Lưu dòng được paste
1321
+ // pastedRows.push(newData[targetRow]);
1322
+ //
1323
+ // });
1324
+ //
1325
+ // const pastedColumnsArray = Array.from(pastedColumns) ?? [];
1326
+ //
1327
+ // triggerPaste?.(pastedRows, pastedColumnsArray as string[], newData)
1328
+ //
1329
+ //
1330
+ // } else {
1331
+ //
1332
+ // // Cập nhật data mới
1333
+ // const newData = [...dataSource];
1334
+ //
1335
+ // const parent = findItemByKey(newData, rowKey as any, record.parentId)
1336
+ //
1337
+ // // Cập nhật childData mới
1338
+ // const childData: any[] = parent?.children ? [...parent.children] : []
1339
+ //
1340
+ //
1341
+ // // Lấy vị trí bắt đầu
1342
+ // // const { row: startRow, col: startCol } = selectedCell;
1343
+ // const startRow = childData.findIndex((it) => it[rowKey] === record[rowKey])
1344
+ // const startCol = indexCol
1345
+ //
1346
+ // const pastedRows: RecordType[] = []
1347
+ // const pastedColumns = new Set()
1348
+ //
1349
+ //
1350
+ // rows.forEach((rowValues: any, rowIndex: any) => {
1351
+ // const targetRow = startRow + rowIndex
1352
+ //
1353
+ // // Nếu vượt quá số dòng hiện có, thêm dòng mới
1354
+ // if (targetRow >= childData.length) {
1355
+ //
1356
+ // childData.push({ id: undefined, rowId: newGuid(), parentId: parent[rowKey ?? 'id']})
1357
+ // }
1358
+ //
1359
+ // rowValues.forEach((cellValue: any, colIndex: any) => {
1360
+ // const targetCol = startCol + colIndex
1361
+ // if (targetCol >= columns.length) { // Không vượt quá số cột
1362
+ // return
1363
+ // }
1364
+ //
1365
+ // if (columns[targetCol].editEnable) {
1366
+ //
1367
+ // // @ts-ignore
1368
+ // const columnKey = columns[targetCol].field
1369
+ //
1370
+ // // @ts-ignore
1371
+ // childData[targetRow] = { ...childData[targetRow], [columnKey]: cellValue.trim() }
1372
+ // pastedColumns.add(columnKey)
1373
+ // }
1374
+ //
1375
+ // })
1376
+ //
1377
+ // // Lưu dòng được paste
1378
+ // pastedRows.push(childData[targetRow])
1379
+ //
1380
+ // })
1381
+ //
1382
+ // const pastedColumnsArray = Array.from(pastedColumns) ?? []
1383
+ //
1384
+ // const newRowData = {...parent, children: childData}
1385
+ //
1386
+ // const newDataSource = updateArrayByKey(newData, newRowData, rowKey as string)
1387
+ //
1388
+ // triggerPaste?.(pastedRows, pastedColumnsArray as string[], newDataSource )
1389
+ // }
1227
1390
  };
1228
- const handleClickColHeader = (column, indexColumn) => {
1229
- const newSelectedCells = new Set();
1230
- for (let r = Math.min(dataSource.length, 0); r <= Math.max(dataSource.length - 1, 0); r++) {
1231
- for (let c = Math.min(indexColumn, indexColumn); c <= Math.max(indexColumn, indexColumn); c++) {
1232
- newSelectedCells.add(`${r}-${c}`);
1391
+ const handlePointDoubleClick = e => {
1392
+ // e.preventDefault()
1393
+ e.stopPropagation();
1394
+ const colStart = (0, _hooks.getFirstSelectCell)(selectedCells.current).col;
1395
+ const colEnd = (0, _hooks.getLastSelectCell)(selectedCells.current).col;
1396
+ const startPasteRow = (0, _hooks.getLastSelectCell)(selectedCells.current).row;
1397
+ const newPasteCells = new Set();
1398
+ for (let r = Math.min(startPasteRow, dataSource.length - 1) + 1; r <= Math.max(startPasteRow, dataSource.length - 1); r++) {
1399
+ for (let c = Math.min(colStart, colStart); c <= Math.max(colStart, colEnd); c++) {
1400
+ newPasteCells.add(`${r}-${c}`);
1233
1401
  }
1234
1402
  }
1235
-
1236
- // setSelectedCells(new Set(newSelectedCells));
1237
-
1238
- if (selectedCells.current && selectedCells.current.size > 0) {
1239
- // onRemoveBgSelectedCell(selectedCells.current, id)
1240
- // onRemoveBorderSelectedCell(selectedCells.current, id)
1241
- }
1242
- if (rowsSelected.current && rowsSelected.current.size > 0) {
1243
- (0, _hooks.removeClassCellIndexSelected)(rowsSelected.current, id);
1244
- }
1245
- selectedCells.current = newSelectedCells;
1246
-
1247
- // onAddBgSelectedCell(newSelectedCells, id)
1248
- // onAddBorderSelectedCell(newSelectedCells, id)
1249
-
1250
1403
  (0, _hooks.hideDraggingPoint)(selectedCells.current, id);
1251
- (0, _hooks.showDraggingPoint)(newSelectedCells, id);
1404
+ triggerDragPaste(newPasteCells);
1252
1405
  };
1253
- const handleMouseDownRowHeader = (row, col, column, e) => {
1406
+ const handleMouseDown = (record, row, col, e) => {
1254
1407
  if (e.button === 2) {
1255
1408
  e.stopPropagation();
1256
1409
  return;
1257
1410
  }
1258
- if (editingKey) {
1259
- setEditingKey('');
1411
+ if (editingKey && editingKey === record[rowKey]) {
1412
+ return;
1260
1413
  }
1261
- isSelectingRow.current = true;
1262
- rowStart.current = {
1263
- row,
1264
- col
1265
- };
1266
- const newSelectedCells = new Set();
1267
- const tCols = (0, _hooks.editAbleColumns)(visibleCols);
1268
- for (let r = Math.min(row, row); r <= Math.max(row, row); r++) {
1269
- for (let c = Math.min(tCols.length, col) + 1; c <= Math.max(tCols.length, col); c++) {
1414
+ if (record[rowKey] !== editingKey && editingKey !== '') {
1415
+ setTimeout(() => {
1416
+ setEditingKey('');
1417
+ });
1418
+ }
1419
+
1420
+ // isDragMouse.current = true
1421
+ isMouseDown.current = true;
1422
+ if (e.ctrlKey) {
1423
+ isSelecting.current = true;
1424
+ startCell.current = {
1425
+ row,
1426
+ col
1427
+ };
1428
+
1429
+ // const cell: any = new Set([`${row}-${col}`])
1430
+
1431
+ // setCurrentCtrlCells(cell)
1432
+ } else {
1433
+ isSelecting.current = true;
1434
+ startCell.current = {
1435
+ row,
1436
+ col
1437
+ };
1438
+ const target = e.target;
1439
+ if (target.closest('.dragging-point')) {
1440
+ e.stopPropagation();
1441
+ e.preventDefault();
1442
+ return; // Không xử lý gì cả
1443
+ } else {
1444
+ // setStartSelectedCell({row, col})
1445
+
1446
+ startSelectedCells.current = {
1447
+ row,
1448
+ col
1449
+ };
1450
+
1451
+ // setSelectedCells(new Set([`${row}-${col}`]));
1452
+
1453
+ const cells = new Set([`${row}-${col}`]);
1454
+ if (selectedCells.current && selectedCells.current.size > 0) {
1455
+ if (!(0, _hooks.isEqualSet)(cells, rangeCells)) {
1456
+ // onRemoveBgSelectedCell(rangeCells, id)
1457
+ // onRemoveBorderSelectedCell(rangeCells, id)
1458
+ (0, _hooks.hideDraggingPoint)(rangeCells, id);
1459
+ (0, _hooks.onRemoveBgCellIndex)(selectedCells.current, id);
1460
+ }
1461
+ }
1462
+ if (rowsSelected.current && rowsSelected.current.size > 0) {
1463
+ (0, _hooks.removeClassCellIndexSelected)(rowsSelected.current, id);
1464
+ }
1465
+ if (!(0, _hooks.isEqualSet)(cells, selectedCells.current)) {
1466
+ (0, _hooks.onRemoveBgSelectedCell)(selectedCells.current, id);
1467
+ (0, _hooks.hideDraggingPoint)(selectedCells.current, id);
1468
+ selectedCells.current = cells;
1469
+ // setRangeCells(cells)
1470
+
1471
+ (0, _hooks.onAddBgCellIndex)(cells, id);
1472
+ (0, _hooks.onAddBorderSelectedCell)(cells, id);
1473
+ (0, _hooks.onAddBgSelectedCell)(selectedCells.current, id, false);
1474
+ (0, _hooks.showDraggingPoint)(selectedCells.current, id);
1475
+ }
1476
+
1477
+ // setRowsSelected(new Set())
1478
+ rowsSelected.current = new Set();
1479
+ }
1480
+ }
1481
+ };
1482
+ const handleMouseUp = e => {
1483
+ isSelecting.current = false;
1484
+ startCell.current = null;
1485
+ isSelectingRow.current = false;
1486
+ rowStart.current = null;
1487
+ isDragMouse.current = false;
1488
+ isMouseDown.current = false;
1489
+ setIsPasteDragging(false);
1490
+ if (e.ctrlKey) {
1491
+
1492
+ // setCtrlCells([...ctrlCells, currentCtrlCells])
1493
+ }
1494
+
1495
+ // nếu ctrlCell length > 0 thì set selectCells
1496
+
1497
+ if (pasteCells && pasteCells.current.size > 0) {
1498
+ triggerDragPaste(pasteCells.current);
1499
+ } else {
1500
+ setRangeCells(selectedCells.current);
1501
+ const target = e.target;
1502
+ if (target.closest('.dragging-point')) {
1503
+ e.stopPropagation();
1504
+ e.preventDefault();
1505
+ return; // Không xử lý gì cả
1506
+ }
1507
+ if (selectedCells.current && selectedCells.current.size > 1) {
1508
+ (0, _hooks.hideDraggingPoint)(selectedCells.current, id);
1509
+ (0, _hooks.onAddBorderSelectedCell)(selectedCells.current, id);
1510
+
1511
+ // showDraggingPoint(selectedCells.current, id)
1512
+ }
1513
+ (0, _hooks.showDraggingPoint)(selectedCells.current, id);
1514
+ // onAddBorderSelectedCell(selectedCells.current, id)
1515
+ }
1516
+ };
1517
+ const handleMouseEnter = (row, col, e) => {
1518
+ if (!isSelecting.current || !startCell.current) {
1519
+ return;
1520
+ }
1521
+ const {
1522
+ row: startRow,
1523
+ col: startCol
1524
+ } = startCell.current;
1525
+ if (e.ctrlKey) {
1526
+ // const newCtrlCells = new Set();
1527
+ // for (let r = Math.min(startRow, row); r <= Math.max(startRow, row); r++) {
1528
+ // for (let c = Math.min(startCol, col); c <= Math.max(startCol, col); c++) {
1529
+ // newCtrlCells.add(`${r}-${c}`)
1530
+ // }
1531
+ // }
1532
+
1533
+ // setCurrentCtrlCells(newCtrlCells)
1534
+
1535
+ return;
1536
+ }
1537
+ if (!isPasteDragging) {
1538
+ // chọn vùng copy
1539
+
1540
+ // setSelectIsDragging(true)
1541
+
1542
+ setIsPasteDragging(false);
1543
+ // isPasteDragging.current = false
1544
+
1545
+ const newSelectedCells = new Set();
1546
+ for (let r = Math.min(startRow, row); r <= Math.max(startRow, row); r++) {
1547
+ for (let c = Math.min(startCol, col); c <= Math.max(startCol, col); c++) {
1548
+ newSelectedCells.add(`${r}-${c}`);
1549
+ }
1550
+ }
1551
+
1552
+ // setSelectedCells(newSelectedCells)
1553
+
1554
+ if (selectedCells.current && selectedCells.current.size > 0) {
1555
+ (0, _hooks.onRemoveBgSelectedCell)(selectedCells.current, id);
1556
+ }
1557
+ selectedCells.current = newSelectedCells;
1558
+ (0, _hooks.onAddBgSelectedCell)(newSelectedCells, id);
1559
+ } else {
1560
+ // chọn vùng paste
1561
+
1562
+ // setSelectIsDragging(false)
1563
+
1564
+ // setIsPasteDragging(true) ////////
1565
+
1566
+ const newSelectedCells = new Set();
1567
+ for (let r = Math.min(startRow, row); r <= Math.max(startRow, row); r++) {
1568
+ for (let c = Math.min(startCol, col); c <= Math.max(startCol, col); c++) {
1569
+ newSelectedCells.add(`${r}-${c}`);
1570
+ }
1571
+ }
1572
+ const colStart = (0, _hooks.getFirstSelectCell)(selectedCells.current).col;
1573
+ const colEnd = (0, _hooks.getLastSelectCell)(selectedCells.current).col;
1574
+ const rowSelectedEnd = (0, _hooks.getLastSelectCell)(selectedCells.current).row;
1575
+ if (row >= rowSelectedEnd) {
1576
+ // kéo xuống dưới
1577
+
1578
+ const newPasteCells = new Set();
1579
+ for (let r = Math.min(startRow, row) + 1; r <= Math.max(startRow, row); r++) {
1580
+ for (let c = Math.min(colStart, col); c <= Math.max(colStart, colEnd); c++) {
1581
+ newPasteCells.add(`${r}-${c}`);
1582
+ }
1583
+ }
1584
+
1585
+ // setPasteCells(newPasteCells)
1586
+
1587
+ if (pasteCells.current && pasteCells.current.size > 0) {
1588
+ (0, _hooks.removeClassBorderPasteCell)(pasteCells.current, 'down', id);
1589
+ }
1590
+ pasteCells.current = newPasteCells;
1591
+ (0, _hooks.addClassBorderPasteCell)(newPasteCells, 'down', id);
1592
+ }
1593
+ if (row < rowSelectedEnd) {
1594
+ // kéo lên trên
1595
+
1596
+ const rowSelectedStart = (0, _hooks.getFirstSelectCell)(selectedCells.current).row;
1597
+ if (row < rowSelectedStart) {
1598
+ const newPasteCells = new Set();
1599
+ for (let r = Math.min(rowSelectedStart, row); r <= Math.max(rowSelectedStart, row) - 1; r++) {
1600
+ for (let c = Math.min(colStart, col); c <= Math.max(colStart, colEnd); c++) {
1601
+ newPasteCells.add(`${r}-${c}`);
1602
+ }
1603
+ }
1604
+
1605
+ // setPasteCells(newPasteCells)
1606
+
1607
+ if (pasteCells.current && pasteCells.current.size > 0) {
1608
+ (0, _hooks.removeClassBorderPasteCell)(pasteCells.current, 'up', id);
1609
+ }
1610
+ pasteCells.current = newPasteCells;
1611
+ (0, _hooks.addClassBorderPasteCell)(newPasteCells, 'up', id);
1612
+ }
1613
+ }
1614
+ if (col > colEnd) {
1615
+ // kéo sang phải
1616
+ }
1617
+ if (row < colStart) {
1618
+ // kéo sang trái
1619
+ }
1620
+ }
1621
+ };
1622
+ const handleClickColHeader = (column, indexColumn) => {
1623
+ const newSelectedCells = new Set();
1624
+ for (let r = Math.min(dataSource.length, 0); r <= Math.max(dataSource.length - 1, 0); r++) {
1625
+ for (let c = Math.min(indexColumn, indexColumn); c <= Math.max(indexColumn, indexColumn); c++) {
1626
+ newSelectedCells.add(`${r}-${c}`);
1627
+ }
1628
+ }
1629
+
1630
+ // setSelectedCells(new Set(newSelectedCells));
1631
+
1632
+ if (selectedCells.current && selectedCells.current.size > 0) {
1633
+ // onRemoveBgSelectedCell(selectedCells.current, id)
1634
+ // onRemoveBorderSelectedCell(selectedCells.current, id)
1635
+ }
1636
+ if (rowsSelected.current && rowsSelected.current.size > 0) {
1637
+ (0, _hooks.removeClassCellIndexSelected)(rowsSelected.current, id);
1638
+ }
1639
+ selectedCells.current = newSelectedCells;
1640
+
1641
+ // onAddBgSelectedCell(newSelectedCells, id)
1642
+ // onAddBorderSelectedCell(newSelectedCells, id)
1643
+
1644
+ (0, _hooks.hideDraggingPoint)(selectedCells.current, id);
1645
+ (0, _hooks.showDraggingPoint)(newSelectedCells, id);
1646
+ };
1647
+ const handleMouseDownRowHeader = (row, col, column, e) => {
1648
+ if (e.button === 2) {
1649
+ e.stopPropagation();
1650
+ return;
1651
+ }
1652
+ if (editingKey) {
1653
+ setEditingKey('');
1654
+ }
1655
+ isSelectingRow.current = true;
1656
+ rowStart.current = {
1657
+ row,
1658
+ col
1659
+ };
1660
+ const newSelectedCells = new Set();
1661
+ const tCols = (0, _hooks.editAbleColumns)(visibleCols);
1662
+ for (let r = Math.min(row, row); r <= Math.max(row, row); r++) {
1663
+ for (let c = Math.min(tCols.length, col) + 1; c <= Math.max(tCols.length, col); c++) {
1270
1664
  newSelectedCells.add(`${r}-${c}`);
1271
1665
  }
1272
1666
  }
@@ -1311,357 +1705,87 @@ const GridEdit = props => {
1311
1705
  for (let c = Math.min((0, _hooks.editAbleColumns)(columns).length, col) + 1; c <= Math.max((0, _hooks.editAbleColumns)(columns).length, col); c++) {
1312
1706
  newSelectedCells.add(`${r}-${c}`);
1313
1707
  }
1314
- }
1315
- if (selectedCells.current && selectedCells.current.size > 0) {
1316
- (0, _hooks.onRemoveBgSelectedCell)(selectedCells.current, id);
1317
- }
1318
- selectedCells.current = newSelectedCells;
1319
- (0, _hooks.onAddBgSelectedCell)(newSelectedCells, id);
1320
- if (rowsSelected.current && rowsSelected.current.size > 0) {
1321
- (0, _hooks.removeClassCellIndexSelected)(rowsSelected.current, id);
1322
- }
1323
- rowsSelected.current = newSelectedRows;
1324
- (0, _hooks.addClassCellIndexSelected)(newSelectedRows, id);
1325
- };
1326
- const handleCellClick = (indexRow, record, column) => {
1327
- const cellClickCallback = newOptions => {
1328
- if (newOptions) {
1329
- const newElem = {
1330
- ...column,
1331
- editSelectSettings: {
1332
- ...(column?.editSelectSettings ? {
1333
- ...column?.editSelectSettings
1334
- } : {}),
1335
- options: newOptions
1336
- }
1337
- };
1338
- const rrr = (0, _hooks.updateArrayByKey)([...columns], newElem, 'field');
1339
- triggerChangeColumns?.(rrr, 'click');
1340
- }
1341
- };
1342
- if (onCellClick) {
1343
- onCellClick({
1344
- index: indexRow,
1345
- rowId: record.rowId,
1346
- cellValue: record[record.field],
1347
- type: "Editing",
1348
- field: column.field,
1349
- rowData: record
1350
- }, cellClickCallback);
1351
- }
1352
- };
1353
- const handleCopy = e => {
1354
- const selectedArray = Array.from(selectedCells.current).map(key => {
1355
- const [row, col] = key.split("-").map(Number);
1356
- // @ts-ignore
1357
- const columnKey = (0, _hooks.editAbleColumns)(columns)[col - 1].field;
1358
-
1359
- // @ts-ignore
1360
- return {
1361
- row,
1362
- col,
1363
- value: (0, _hooks.flattenData)(childrenColumnName, dataSource)[row][columnKey] ?? ''
1364
- };
1365
- // return { row, col, value: '' };
1366
- });
1367
-
1368
- // Xác định min/max row và col để sắp xếp dữ liệu
1369
- const minRow = Math.min(...selectedArray.map(cell => cell.row));
1370
- const maxRow = Math.max(...selectedArray.map(cell => cell.row));
1371
- const minCol = Math.min(...selectedArray.map(cell => cell.col));
1372
- const maxCol = Math.max(...selectedArray.map(cell => cell.col));
1373
-
1374
- // Tạo dữ liệu dạng bảng (mảng 2D)
1375
- const table = Array.from({
1376
- length: maxRow - minRow + 1
1377
- }, () => Array(maxCol - minCol + 1).fill(""));
1378
-
1379
- // Gán giá trị vào bảng
1380
- selectedArray.forEach(({
1381
- row,
1382
- col,
1383
- value
1384
- }) => {
1385
- table[row - minRow][col - minCol] = value;
1386
- });
1387
-
1388
- // Chuyển mảng 2D thành chuỗi định dạng Excel
1389
- const copyText = table.map(row => row.join("\t")).join("\n");
1390
-
1391
- // Copy vào clipboard
1392
- e.preventDefault();
1393
- e.clipboardData.setData("text/plain", copyText);
1394
- (0, _Message.default)(t ? t('CopySuccessful') : 'Copy Successful');
1395
- };
1396
- const handlePasted = (record, indexCol, rowNumber, pasteData) => {
1397
- const rows = pasteData.slice(0, onCellPaste?.maxRowsPaste ?? 200);
1398
- if (!record?.parentId) {
1399
- // Cập nhật data mới
1400
- const newData = [...dataSource];
1401
-
1402
- // const indexRows = newData.findIndex((it) => it[rowKey as any] === record[rowKey])
1403
-
1404
- // Lấy vị trí bắt đầu
1405
- // const { row: startRow, col: startCol } = selectedCell;
1406
- const startRow = newData.findIndex(it => it[rowKey] === record[rowKey]);
1407
- const startCol = indexCol;
1408
-
1409
- // const flattData = flattenArray(newData);
1410
-
1411
- const pastedRows = [];
1412
- const pastedColumns = new Set();
1413
- rows.forEach((rowValues, rowIndex) => {
1414
- const targetRow = startRow + rowIndex;
1415
-
1416
- // Nếu vượt quá số dòng hiện có, thêm dòng mới
1417
- if (targetRow >= newData.length) {
1418
- // @ts-ignore
1419
- // newData.push({ id: newGuid()});
1420
- newData.push({
1421
- id: undefined,
1422
- rowId: (0, _hooks.newGuid)()
1423
- });
1424
- }
1425
- rowValues.forEach((cellValue, colIndex) => {
1426
- const targetCol = startCol + colIndex;
1427
- if (targetCol >= visibleCols.length) {
1428
- // Không vượt quá số cột
1429
- return;
1430
- }
1431
- if (visibleCols[targetCol].editEnable) {
1432
- // @ts-ignore
1433
- const columnKey = visibleCols[targetCol].field;
1434
-
1435
- // @ts-ignore
1436
- newData[targetRow] = {
1437
- ...newData[targetRow],
1438
- [columnKey]: cellValue.trim()
1439
- };
1440
- pastedColumns.add(columnKey);
1441
- }
1442
- });
1443
-
1444
- // Lưu dòng được paste
1445
- pastedRows.push(newData[targetRow]);
1446
- });
1447
- const pastedColumnsArray = Array.from(pastedColumns) ?? [];
1448
- triggerPaste?.(pastedRows, pastedColumnsArray, newData);
1449
- } else {
1450
- // Cập nhật data mới
1451
- const newData = [...dataSource];
1452
- const parent = (0, _hooks.findItemByKey)(newData, rowKey, record.parentId);
1453
-
1454
- // Cập nhật childData mới
1455
- const childData = parent?.children ? [...parent.children] : [];
1456
-
1457
- // Lấy vị trí bắt đầu
1458
- // const { row: startRow, col: startCol } = selectedCell;
1459
- const startRow = childData.findIndex(it => it[rowKey] === record[rowKey]);
1460
- const startCol = indexCol;
1461
- const pastedRows = [];
1462
- const pastedColumns = new Set();
1463
- rows.forEach((rowValues, rowIndex) => {
1464
- const targetRow = startRow + rowIndex;
1465
-
1466
- // Nếu vượt quá số dòng hiện có, thêm dòng mới
1467
- if (targetRow >= childData.length) {
1468
- childData.push({
1469
- id: undefined,
1470
- rowId: (0, _hooks.newGuid)(),
1471
- parentId: parent[rowKey ?? 'id']
1472
- });
1473
- }
1474
- rowValues.forEach((cellValue, colIndex) => {
1475
- const targetCol = startCol + colIndex;
1476
- if (targetCol >= visibleCols.length) {
1477
- // Không vượt quá số cột
1478
- return;
1479
- }
1480
- if (visibleCols[targetCol].editEnable) {
1481
- // @ts-ignore
1482
- const columnKey = visibleCols[targetCol].field;
1483
-
1484
- // @ts-ignore
1485
- childData[targetRow] = {
1486
- ...childData[targetRow],
1487
- [columnKey]: cellValue.trim()
1488
- };
1489
- pastedColumns.add(columnKey);
1490
- }
1491
- });
1492
-
1493
- // Lưu dòng được paste
1494
- pastedRows.push(childData[targetRow]);
1495
- });
1496
- const pastedColumnsArray = Array.from(pastedColumns) ?? [];
1497
- const newRowData = {
1498
- ...parent,
1499
- children: childData
1500
- };
1501
- const newDataSource = (0, _hooks.updateArrayByKey)(newData, newRowData, rowKey);
1502
- triggerPaste?.(pastedRows, pastedColumnsArray, newDataSource);
1503
- }
1504
- };
1505
- const handlePaste = (record, indexCol, rowNumber, e) => {
1506
- // const clipboard: any = (e.clipboardData || (window && window?.Clipboard)).getData("text")
1507
- const pasteData = e.clipboardData.getData("text/plain");
1508
-
1509
- // Chuyển đổi dữ liệu từ clipboard thành mảng
1510
- const rowsPasted = pasteData.split("\n").map(row =>
1511
- // const rows = pasteData.split("\n").map((row: any) =>
1512
- row.replace(/\r/g, "").split("\t"));
1513
- if (rowsPasted.length > (onCellPaste?.maxRowsPaste ?? 200)) {
1514
- // bật popup thông báo
1515
-
1516
- _antd.Modal.confirm({
1517
- content: /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(Paragraph, {
1518
- style: {
1519
- marginBottom: '.25rem',
1520
- fontSize: 14
1521
- }
1522
- }, "D\u1EEF li\u1EC7u sao ch\xE9p v\u01B0\u1EE3t qu\xE1 s\u1ED1 d\xF2ng cho ph\xE9p (500 d\xF2ng).Ph\u1EA7n m\u1EC1n s\u1EBD ch\u1EC9 l\u1EA5y 500 d\xF2ng \u0111\u1EA7u ti\xEAn."), /*#__PURE__*/_react.default.createElement(Title, {
1523
- level: 5,
1524
- style: {
1525
- marginTop: '.75rem'
1526
- }
1527
- }, "B\u1EA1n c\xF3 mu\u1ED1n ti\u1EBFp t\u1EE5c sao ch\xE9p kh\xF4ng?")),
1528
- centered: true,
1529
- className: 'be-popup-container',
1530
- onOk: () => {
1531
- handlePasted(record, indexCol, rowNumber, rowsPasted);
1532
- }
1533
- // footer: (_, { OkBtn, CancelBtn }) => (
1534
- // <>
1535
- // <OkBtn />
1536
- // <CancelBtn />
1537
- // </>
1538
- // ),
1539
- });
1540
- } else {
1541
- handlePasted(record, indexCol, rowNumber, rowsPasted);
1542
- }
1543
-
1544
- // const rows = rowsPasted.slice(0, (onCellPaste?.maxRowsPaste ?? 200));
1545
- //
1546
- //
1547
- // if (!record?.parentId ) {
1548
- //
1549
- // // Cập nhật data mới
1550
- // const newData = [...dataSource];
1551
- //
1552
- // // @ts-ignore
1553
- // const indexRows = newData.findIndex((it) => it[rowKey] === record[rowKey])
1554
- //
1555
- // // Lấy vị trí bắt đầu
1556
- // // const { row: startRow, col: startCol } = selectedCell;
1557
- // const startRow = indexRows
1558
- // const startCol = indexCol
1559
- //
1560
- //
1561
- //
1562
- // // const flattData = flattenArray(newData);
1563
- //
1564
- // const pastedRows: RecordType[] = [];
1565
- // const pastedColumns = new Set()
1566
- //
1567
- //
1568
- // rows.forEach((rowValues: any, rowIndex: any) => {
1569
- // const targetRow = startRow + rowIndex;
1570
- //
1571
- // // Nếu vượt quá số dòng hiện có, thêm dòng mới
1572
- // if (targetRow >= newData.length) {
1573
- // // @ts-ignore
1574
- // // newData.push({ id: newGuid()});
1575
- // newData.push({ id: undefined, rowId: newGuid()});
1576
- // }
1577
- //
1578
- // rowValues.forEach((cellValue: any, colIndex: any) => {
1579
- // const targetCol = startCol + colIndex;
1580
- // if (targetCol >= columns.length) { // Không vượt quá số cột
1581
- // return
1582
- // }
1583
- //
1584
- // if (columns[targetCol].editEnable) {
1585
- // // @ts-ignore
1586
- // const columnKey = columns[targetCol].field;
1587
- //
1588
- // // @ts-ignore
1589
- // newData[targetRow] = { ...newData[targetRow], [columnKey]: cellValue.trim() };
1590
- // pastedColumns.add(columnKey);
1591
- // }
1592
- //
1593
- // });
1594
- //
1595
- // // Lưu dòng được paste
1596
- // pastedRows.push(newData[targetRow]);
1597
- //
1598
- // });
1599
- //
1600
- // const pastedColumnsArray = Array.from(pastedColumns) ?? [];
1601
- //
1602
- // triggerPaste?.(pastedRows, pastedColumnsArray as string[], newData)
1603
- //
1604
- //
1605
- // } else {
1606
- //
1607
- // // Cập nhật data mới
1608
- // const newData = [...dataSource];
1609
- //
1610
- // const parent = findItemByKey(newData, rowKey as any, record.parentId)
1611
- //
1612
- // // Cập nhật childData mới
1613
- // const childData: any[] = parent?.children ? [...parent.children] : []
1614
- //
1615
- //
1616
- // // Lấy vị trí bắt đầu
1617
- // // const { row: startRow, col: startCol } = selectedCell;
1618
- // const startRow = childData.findIndex((it) => it[rowKey] === record[rowKey])
1619
- // const startCol = indexCol
1620
- //
1621
- // const pastedRows: RecordType[] = []
1622
- // const pastedColumns = new Set()
1623
- //
1624
- //
1625
- // rows.forEach((rowValues: any, rowIndex: any) => {
1626
- // const targetRow = startRow + rowIndex
1627
- //
1628
- // // Nếu vượt quá số dòng hiện có, thêm dòng mới
1629
- // if (targetRow >= childData.length) {
1630
- //
1631
- // childData.push({ id: undefined, rowId: newGuid(), parentId: parent[rowKey ?? 'id']})
1632
- // }
1633
- //
1634
- // rowValues.forEach((cellValue: any, colIndex: any) => {
1635
- // const targetCol = startCol + colIndex
1636
- // if (targetCol >= columns.length) { // Không vượt quá số cột
1637
- // return
1638
- // }
1639
- //
1640
- // if (columns[targetCol].editEnable) {
1641
- //
1642
- // // @ts-ignore
1643
- // const columnKey = columns[targetCol].field
1644
- //
1645
- // // @ts-ignore
1646
- // childData[targetRow] = { ...childData[targetRow], [columnKey]: cellValue.trim() }
1647
- // pastedColumns.add(columnKey)
1648
- // }
1649
- //
1650
- // })
1651
- //
1652
- // // Lưu dòng được paste
1653
- // pastedRows.push(childData[targetRow])
1654
- //
1655
- // })
1656
- //
1657
- // const pastedColumnsArray = Array.from(pastedColumns) ?? []
1658
- //
1659
- // const newRowData = {...parent, children: childData}
1660
- //
1661
- // const newDataSource = updateArrayByKey(newData, newRowData, rowKey as string)
1662
- //
1663
- // triggerPaste?.(pastedRows, pastedColumnsArray as string[], newDataSource )
1664
- // }
1708
+ }
1709
+ if (selectedCells.current && selectedCells.current.size > 0) {
1710
+ (0, _hooks.onRemoveBgSelectedCell)(selectedCells.current, id);
1711
+ }
1712
+ selectedCells.current = newSelectedCells;
1713
+ (0, _hooks.onAddBgSelectedCell)(newSelectedCells, id);
1714
+ if (rowsSelected.current && rowsSelected.current.size > 0) {
1715
+ (0, _hooks.removeClassCellIndexSelected)(rowsSelected.current, id);
1716
+ }
1717
+ rowsSelected.current = newSelectedRows;
1718
+ (0, _hooks.addClassCellIndexSelected)(newSelectedRows, id);
1719
+ };
1720
+ const handleCellClick = (indexRow, record, column) => {
1721
+ const cellClickCallback = newOptions => {
1722
+ if (newOptions) {
1723
+ const newElem = {
1724
+ ...column,
1725
+ editSelectSettings: {
1726
+ ...(column?.editSelectSettings ? {
1727
+ ...column?.editSelectSettings
1728
+ } : {}),
1729
+ options: newOptions
1730
+ }
1731
+ };
1732
+ const rrr = (0, _hooks.updateArrayByKey)([...columns], newElem, 'field');
1733
+ triggerChangeColumns?.(rrr, 'click');
1734
+ }
1735
+ };
1736
+ if (onCellClick) {
1737
+ onCellClick({
1738
+ index: indexRow,
1739
+ rowId: record.rowId,
1740
+ cellValue: record[record.field],
1741
+ type: "Editing",
1742
+ field: column.field,
1743
+ rowData: record
1744
+ }, cellClickCallback);
1745
+ }
1746
+ };
1747
+ const handleCopy = e => {
1748
+ const selectedArray = Array.from(selectedCells.current).map(key => {
1749
+ const [row, col] = key.split("-").map(Number);
1750
+ // @ts-ignore
1751
+ const columnKey = (0, _hooks.editAbleColumns)(columns)[col - 1].field;
1752
+
1753
+ // @ts-ignore
1754
+ return {
1755
+ row,
1756
+ col,
1757
+ value: (0, _hooks.flattenData)(childrenColumnName, dataSource)[row][columnKey] ?? ''
1758
+ };
1759
+ // return { row, col, value: '' };
1760
+ });
1761
+
1762
+ // Xác định min/max row và col để sắp xếp dữ liệu
1763
+ const minRow = Math.min(...selectedArray.map(cell => cell.row));
1764
+ const maxRow = Math.max(...selectedArray.map(cell => cell.row));
1765
+ const minCol = Math.min(...selectedArray.map(cell => cell.col));
1766
+ const maxCol = Math.max(...selectedArray.map(cell => cell.col));
1767
+
1768
+ // Tạo dữ liệu dạng bảng (mảng 2D)
1769
+ const table = Array.from({
1770
+ length: maxRow - minRow + 1
1771
+ }, () => Array(maxCol - minCol + 1).fill(""));
1772
+
1773
+ // Gán giá trị vào bảng
1774
+ selectedArray.forEach(({
1775
+ row,
1776
+ col,
1777
+ value
1778
+ }) => {
1779
+ table[row - minRow][col - minCol] = value;
1780
+ });
1781
+
1782
+ // Chuyển mảng 2D thành chuỗi định dạng Excel
1783
+ const copyText = table.map(row => row.join("\t")).join("\n");
1784
+
1785
+ // Copy vào clipboard
1786
+ e.preventDefault();
1787
+ e.clipboardData.setData("text/plain", copyText);
1788
+ (0, _Message.default)(t ? t('CopySuccessful') : 'Copy Successful');
1665
1789
  };
1666
1790
  const onSubmit = formData => {
1667
1791
  try {
@@ -1899,312 +2023,344 @@ const GridEdit = props => {
1899
2023
  focusNextCell(cellEdit, cell);
1900
2024
  }
1901
2025
  };
1902
- const convertColumns = _react.default.useMemo(() => {
1903
- return (0, _columns.flatColumns2)(columns.filter(it => it.visible !== false)).map((column, colIndex) => {
1904
- if (column === _InternalTable.SELECTION_COLUMN) {
1905
- return _InternalTable.SELECTION_COLUMN;
1906
- }
1907
- if (column.field === '#') {
1908
- return {
1909
- ...column,
1910
- className: 'rc-ui-cell-editable rc-ui-cell-index',
1911
- onCell: (record, rowIndex) => {
1912
- const rowNumber = (0, _hooks.getRowNumber)(dataSource, record[rowKey], rowKey);
1913
- return {
1914
- 'data-row-index': rowNumber,
1915
- onPaste: event => {
1916
- if (editingKey === '') {
1917
- handlePaste(record, colIndex + 1, rowNumber, event);
1918
- event.preventDefault();
1919
- }
1920
- },
1921
- onCopy: e => {
1922
- if (editingKey === '') {
1923
- handleCopy(e);
1924
- e.preventDefault();
1925
- }
1926
- },
1927
- // onClick: () => {
1928
- // if (record[rowKey] !== editingKey && (editingKey !== '')) {
1929
- // setEditingKey('')
1930
- // }
1931
- // },
1932
- tabIndex: (rowIndex ?? 0) * visibleCols.length + colIndex
1933
- };
1934
- },
1935
- render: (value, record) => {
1936
- const rowNumber = (0, _hooks.getRowNumber)(dataSource, record[rowKey], rowKey);
1937
- return /*#__PURE__*/_react.default.createElement("div", {
1938
- className: (0, _classnames.default)('ui-rc_cell-content ui-rc_cell-content--index', {}),
1939
- onMouseDown: event => handleMouseDownRowHeader(rowNumber, colIndex, column, event),
1940
- onMouseEnter: event => handleMouseEnterRowHeader(rowNumber, colIndex, event),
1941
- onMouseUp: event => handleMouseUp(event)
1942
- }, /*#__PURE__*/_react.default.createElement("div", {
1943
- className: 'ui-rc_content'
1944
- }, (0, _hooks.findItemPath)(dataSource, record, rowKey)));
1945
- }
1946
- };
1947
- }
1948
- if (column.field === 'command') {
1949
- return {
1950
- ...column
1951
- };
1952
- }
2026
+ const convertColumns = (0, _columns.flatColumns2)(columns.filter(it => it.visible !== false)).map((column, colIndex) => {
2027
+ if (column === _InternalTable.SELECTION_COLUMN) {
2028
+ return _InternalTable.SELECTION_COLUMN;
2029
+ }
2030
+ if (column.field === '#') {
1953
2031
  return {
1954
2032
  ...column,
2033
+ className: 'rc-ui-cell-editable rc-ui-cell-index',
1955
2034
  onCell: (record, rowIndex) => {
1956
2035
  const rowNumber = (0, _hooks.getRowNumber)(dataSource, record[rowKey], rowKey);
1957
2036
  return {
1958
- ...column?.onCell?.(record, rowIndex),
1959
- onKeyDown: event => {
1960
- const key = getRowKey(record, dataSource.indexOf(record));
1961
- if (event.key === 'Control' && event.ctrlKey) {} else {
1962
- if (event.key.length === 1 && !event.ctrlKey && !event.metaKey || event.key === 'Enter') {
1963
- if (record[rowKey] !== editingKey && (0, _hooks.isEditable)(column, record)) {
1964
- // ~~ khi editingKey = ''
1965
- event.preventDefault();
1966
- event.stopPropagation();
1967
- handleEdit(record, column, column.editType, event);
2037
+ 'data-row-index': rowNumber,
2038
+ onPaste: event => {
2039
+ if (editingKey === '') {
2040
+ handlePaste(record, colIndex + 1, rowNumber, event);
2041
+ event.preventDefault();
2042
+ }
2043
+ },
2044
+ onCopy: e => {
2045
+ if (editingKey === '') {
2046
+ handleCopy(e);
2047
+ e.preventDefault();
2048
+ }
2049
+ },
2050
+ // onClick: () => {
2051
+ // if (record[rowKey] !== editingKey && (editingKey !== '')) {
2052
+ // setEditingKey('')
2053
+ // }
2054
+ // },
2055
+ tabIndex: (rowIndex ?? 0) * visibleCols.length + colIndex
2056
+ };
2057
+ },
2058
+ render: (value, record) => {
2059
+ const rowNumber = (0, _hooks.getRowNumber)(dataSource, record[rowKey], rowKey);
2060
+ return /*#__PURE__*/_react.default.createElement("div", {
2061
+ className: (0, _classnames.default)('ui-rc_cell-content ui-rc_cell-content--index', {}),
2062
+ onMouseDown: event => handleMouseDownRowHeader(rowNumber, colIndex, column, event),
2063
+ onMouseEnter: event => handleMouseEnterRowHeader(rowNumber, colIndex, event),
2064
+ onMouseUp: event => handleMouseUp(event)
2065
+ }, /*#__PURE__*/_react.default.createElement("div", {
2066
+ className: 'ui-rc_content'
2067
+ }, (0, _hooks.findItemPath)(dataSource, record, rowKey)));
2068
+ }
2069
+ };
2070
+ }
2071
+ if (column.field === 'command') {
2072
+ return {
2073
+ ...column
2074
+ };
2075
+ }
2076
+ return {
2077
+ ...column,
2078
+ onCell: (record, rowIndex) => {
2079
+ const rowNumber = (0, _hooks.getRowNumber)(dataSource, record[rowKey], rowKey);
2080
+ return {
2081
+ ...column?.onCell?.(record, rowIndex),
2082
+ onKeyDown: event => {
2083
+ const key = getRowKey(record, dataSource.indexOf(record));
2084
+ if (event.key === 'Control' && event.ctrlKey) {} else {
2085
+ if (event.key.length === 1 && !event.ctrlKey && !event.metaKey || event.key === 'Enter') {
2086
+ if (record[rowKey] !== editingKey && (0, _hooks.isEditable)(column, record)) {
2087
+ // ~~ khi editingKey = ''
2088
+ event.preventDefault();
2089
+ event.stopPropagation();
2090
+ handleEdit(record, column, column.editType, event);
1968
2091
 
1969
- // onRemoveBgSelectedCell(selectedCells.current, id)
1970
- // onRemoveBorderSelectedCell(selectedCells.current, id)
2092
+ // onRemoveBgSelectedCell(selectedCells.current, id)
2093
+ // onRemoveBorderSelectedCell(selectedCells.current, id)
1971
2094
 
1972
- // selectedCells.current = new Set()
2095
+ // selectedCells.current = new Set()
1973
2096
 
1974
- handleCellClick(rowNumber, record, column);
1975
- const hasKey = mergedExpandedKeys.has(key);
1976
- if (hasKey) {
1977
- // mergedExpandedKeys.delete(key);
1978
- // newExpandedKeys = [...mergedExpandedKeys];
1979
- } else {
1980
- onTriggerExpand(record);
1981
- }
2097
+ handleCellClick(rowNumber, record, column);
2098
+ const hasKey = mergedExpandedKeys.has(key);
2099
+ if (hasKey) {
2100
+ // mergedExpandedKeys.delete(key);
2101
+ // newExpandedKeys = [...mergedExpandedKeys];
1982
2102
  } else {
1983
- if (event.key === 'Enter') {
1984
- event.preventDefault();
1985
- event.stopPropagation();
1986
- if (editingKey && editingKey !== '' && (rowNumber ?? 0) + 1 < (0, _hooks.flattenArray)(dataSource).length && event.key === 'Enter') {
1987
- handleFocusCell((rowNumber ?? 0) + 1, colIndex, column, 'vertical', event);
1988
- } else {
1989
- // // focus cell hiện tại và tắt edit
1990
- // handleFocusCell((rowNumber ?? 0), colIndex, column, 'vertical', event)
1991
- // setEditingKey('')
1992
-
1993
- // thêm dòng mới
1994
-
1995
- handleAddSingle();
1996
- handleFocusCell((rowNumber ?? 0) + 1, colIndex, column, 'vertical', event, true);
1997
- }
1998
- }
2103
+ onTriggerExpand(record);
1999
2104
  }
2000
- }
2001
- if (event.key === 'Tab') {
2002
- if (editingKey) {} else {
2003
- if (colIndex + 1 !== visibleCols.length) {
2004
- handleFocusCell(rowNumber, colIndex + 1, column, 'horizontal', event);
2105
+ } else {
2106
+ if (event.key === 'Enter') {
2107
+ event.preventDefault();
2108
+ event.stopPropagation();
2109
+ if (editingKey && editingKey !== '' && (rowNumber ?? 0) + 1 < (0, _hooks.flattenArray)(dataSource).length && event.key === 'Enter') {
2110
+ handleFocusCell((rowNumber ?? 0) + 1, colIndex, column, 'vertical', event);
2005
2111
  } else {
2006
- event.stopPropagation();
2007
- event.preventDefault();
2112
+ // // focus cell hiện tại và tắt edit
2113
+ // handleFocusCell((rowNumber ?? 0), colIndex, column, 'vertical', event)
2114
+ // setEditingKey('')
2115
+
2116
+ // thêm dòng mới
2117
+
2118
+ handleAddSingle();
2119
+ handleFocusCell((rowNumber ?? 0) + 1, colIndex, column, 'vertical', event, true);
2008
2120
  }
2009
2121
  }
2010
2122
  }
2011
- if (event.key === 'ArrowRight' && colIndex + 1 !== visibleCols.length) {
2012
- if (editingKey !== '') {} else {
2123
+ }
2124
+ if (event.key === 'Tab') {
2125
+ if (editingKey) {} else {
2126
+ if (colIndex + 1 !== visibleCols.length) {
2013
2127
  handleFocusCell(rowNumber, colIndex + 1, column, 'horizontal', event);
2014
- }
2015
- }
2016
- if (event.key === 'ArrowLeft' && colIndex > 0) {
2017
- if (!column.dataIndex && !column.key || column.field === '#' || column.dataIndex === '#') {
2128
+ } else {
2018
2129
  event.stopPropagation();
2019
2130
  event.preventDefault();
2020
- } else {
2021
- if (editingKey !== '') {} else {
2022
- handleFocusCell(rowNumber, colIndex - 1, column, 'horizontal', event);
2023
- }
2024
2131
  }
2025
2132
  }
2026
- if (event.key === 'ArrowDown' && (rowNumber ?? 0) + 1 < (0, _hooks.flattenArray)(dataSource).length) {
2027
- if (isEditing(record) && ((0, _hooks.getEditType)(column, record) === 'treeSelect' || (0, _hooks.getEditType)(column, record) === 'select' || (0, _hooks.getEditType)(column, record) === 'selectTable' || (0, _hooks.getEditType)(column, record) === 'asyncSelect')) {
2028
- event.stopPropagation();
2029
- } else {
2030
- handleFocusCell((rowNumber ?? 0) + 1, colIndex, column, 'vertical', event);
2031
- }
2133
+ }
2134
+ if (event.key === 'ArrowRight' && colIndex + 1 !== visibleCols.length) {
2135
+ if (editingKey !== '') {} else {
2136
+ handleFocusCell(rowNumber, colIndex + 1, column, 'horizontal', event);
2032
2137
  }
2033
- if (event.key === 'ArrowUp' && (rowNumber ?? 0) > 0) {
2034
- if (isEditing(record) && ((0, _hooks.getEditType)(column, record) === 'asyncSelect' || (0, _hooks.getEditType)(column, record) === 'select' || (0, _hooks.getEditType)(column, record) === 'selectTable' || (0, _hooks.getEditType)(column, record) === 'treeSelect')) {
2035
- event.stopPropagation();
2036
- } else {
2037
- handleFocusCell((rowNumber ?? 0) - 1, colIndex, column, 'vertical', event);
2138
+ }
2139
+ if (event.key === 'ArrowLeft' && colIndex > 0) {
2140
+ if (!column.dataIndex && !column.key || column.field === '#' || column.dataIndex === '#') {
2141
+ event.stopPropagation();
2142
+ event.preventDefault();
2143
+ } else {
2144
+ if (editingKey !== '') {} else {
2145
+ handleFocusCell(rowNumber, colIndex - 1, column, 'horizontal', event);
2038
2146
  }
2039
2147
  }
2040
- if (event.key === 'Delete') {
2041
- handleDeleteContent();
2148
+ }
2149
+ if (event.key === 'ArrowDown' && (rowNumber ?? 0) + 1 < (0, _hooks.flattenArray)(dataSource).length) {
2150
+ if (isEditing(record) && ((0, _hooks.getEditType)(column, record) === 'treeSelect' || (0, _hooks.getEditType)(column, record) === 'select' || (0, _hooks.getEditType)(column, record) === 'selectTable' || (0, _hooks.getEditType)(column, record) === 'asyncSelect')) {
2151
+ event.stopPropagation();
2152
+ } else {
2153
+ handleFocusCell((rowNumber ?? 0) + 1, colIndex, column, 'vertical', event);
2042
2154
  }
2043
- if (event.key === 'Escape') {
2044
- setEditingKey('');
2155
+ }
2156
+ if (event.key === 'ArrowUp' && (rowNumber ?? 0) > 0) {
2157
+ if (isEditing(record) && ((0, _hooks.getEditType)(column, record) === 'asyncSelect' || (0, _hooks.getEditType)(column, record) === 'select' || (0, _hooks.getEditType)(column, record) === 'selectTable' || (0, _hooks.getEditType)(column, record) === 'treeSelect')) {
2158
+ event.stopPropagation();
2159
+ } else {
2160
+ handleFocusCell((rowNumber ?? 0) - 1, colIndex, column, 'vertical', event);
2045
2161
  }
2046
2162
  }
2047
- },
2048
- onPaste: event => {
2049
- if (editingKey === '') {
2050
- handlePaste(record, colIndex, rowNumber, event);
2051
- event.preventDefault();
2163
+ if (event.key === 'Delete') {
2164
+ handleDeleteContent();
2052
2165
  }
2053
- },
2054
- onCopy: e => {
2055
- if (editingKey === '') {
2056
- handleCopy(e);
2057
- e.preventDefault();
2166
+ if (event.key === 'Escape') {
2167
+ setEditingKey('');
2058
2168
  }
2059
- },
2060
- onDoubleClick: event => {
2061
- if (!isEditing(record) && record[rowKey] !== editingKey && (0, _hooks.isEditable)(column, record)) {
2062
- handleEdit(record, column, (0, _hooks.getEditType)(column, record), event);
2169
+ }
2170
+ },
2171
+ onPaste: event => {
2172
+ if (editingKey === '') {
2173
+ handlePaste(record, colIndex, rowNumber, event);
2174
+ event.preventDefault();
2175
+ }
2176
+ },
2177
+ onCopy: e => {
2178
+ if (editingKey === '') {
2179
+ handleCopy(e);
2180
+ e.preventDefault();
2181
+ }
2182
+ },
2183
+ onDoubleClick: event => {
2184
+ if (!isEditing(record) && record[rowKey] !== editingKey && (0, _hooks.isEditable)(column, record)) {
2185
+ handleEdit(record, column, (0, _hooks.getEditType)(column, record), event);
2063
2186
 
2064
- // onRemoveBgSelectedCell(selectedCells.current, id)
2065
- // onRemoveBorderSelectedCell(selectedCells.current, id)
2066
- handleCellClick(rowNumber, record, column);
2067
- }
2068
- },
2069
- onContextMenu: () => {
2070
- // isSelecting.current = true;
2071
- // startCell.current = { row: rowNumber, col: colIndex };
2072
-
2073
- if (selectedCells.size === 0) {
2074
- // setStartSelectedCell({ row: rowNumber, col: colIndex })
2075
- // setSelectedCells(new Set([`${rowNumber}-${colIndex}`]));
2076
-
2077
- startSelectedCells.current = {
2078
- row: rowNumber,
2079
- col: colIndex
2080
- };
2081
- selectedCells.current = new Set([`${rowNumber}-${colIndex}`]);
2082
- rowsSelected.current = new Set();
2083
- }
2084
- },
2085
- onClick: () => {
2086
- if (record[rowKey] !== editingKey && editingKey !== '') {
2087
- // setEditingKey('')
2088
- } else {
2089
- if (record[rowKey] !== editingKey) {
2090
- (0, _hooks.onAddBorderSelectedCell)(selectedCells.current, id);
2091
- }
2092
- if (editingKey) {
2093
- handleCellClick(rowNumber, record, column);
2094
- }
2095
- }
2096
- },
2097
- // className: isEditing(record) ? `rc-ui-cell-editable cell-editing ${!isEditable(column as any, record) ? 'disable' : ''}` : `rc-ui-cell-editable cell-editable ${!isEditable(column as any, record) ? 'disable' : ''}`,
2098
- className: (0, _classnames.default)('rc-ui-cell-editable', {
2099
- 'cell-editing': isEditing(record),
2100
- 'cell-editable': !isEditing(record)
2101
- // selected: isSelectedCell(rangeCells,rowIndex, colIndex),
2102
- // 'cell-border-bottom': isRangeCell(rangeCells, 'bottom',rowIndex, colIndex),
2103
- // 'cell-border-right': isRangeCell(rangeCells, 'right',rowIndex, colIndex),
2104
- // 'cell-border-top': isRangeCell(rangeCells, 'top',rowIndex, colIndex),
2105
- // 'cell-border-left': isRangeCell(rangeCells, 'left',rowIndex, colIndex),
2106
- // disable: !isEditable(column as any, record)
2107
- }),
2108
- record,
2109
- column: column,
2110
- editType: (0, _hooks.getEditType)(column, record),
2111
- dataIndex: column.dataIndex,
2112
- indexRow: rowNumber,
2113
- indexCol: colIndex,
2114
- title: (0, _columns.getValueCell)(column, record[column.field], format),
2115
- 'data-col-index': colIndex,
2116
- 'data-row-index': rowNumber,
2117
- 'data-tooltip-id': "tooltip-cell-content",
2118
- editing: isEditing(record) && rowEditable?.(record) !== false && (0, _hooks.isEditable)(column, record),
2119
- cellEditing,
2120
- t,
2121
- tabIndex: (rowIndex ?? 0) * visibleCols.length + colIndex,
2122
- style: isPasteDragging ? {
2123
- cursor: "crosshair"
2124
- } : {}
2125
- };
2126
- },
2127
- onHeaderCell: (data, index) => {
2128
- return {
2129
- ...(column.onHeaderCell ? column.onHeaderCell?.(data, index) : {}),
2130
- onClick: () => {
2131
- handleClickColHeader(column, colIndex);
2132
- },
2133
- onCopy: e => {
2134
- if (editingKey === '') {
2135
- handleCopy(e);
2136
- e.preventDefault();
2187
+ // onRemoveBgSelectedCell(selectedCells.current, id)
2188
+ // onRemoveBorderSelectedCell(selectedCells.current, id)
2189
+ handleCellClick(rowNumber, record, column);
2190
+ }
2191
+ },
2192
+ onContextMenu: () => {
2193
+ // isSelecting.current = true;
2194
+ // startCell.current = { row: rowNumber, col: colIndex };
2195
+
2196
+ if (selectedCells.size === 0) {
2197
+ // setStartSelectedCell({ row: rowNumber, col: colIndex })
2198
+ // setSelectedCells(new Set([`${rowNumber}-${colIndex}`]));
2199
+
2200
+ startSelectedCells.current = {
2201
+ row: rowNumber,
2202
+ col: colIndex
2203
+ };
2204
+ selectedCells.current = new Set([`${rowNumber}-${colIndex}`]);
2205
+ rowsSelected.current = new Set();
2206
+ }
2207
+ },
2208
+ onClick: () => {
2209
+ if (record[rowKey] !== editingKey && editingKey !== '') {
2210
+ // setEditingKey('')
2211
+ } else {
2212
+ if (record[rowKey] !== editingKey) {
2213
+ (0, _hooks.onAddBorderSelectedCell)(selectedCells.current, id);
2137
2214
  }
2138
- },
2139
- onPaste: event => {
2140
- if (editingKey === '') {
2141
- handlePaste(dataSource[0], colIndex, 0, event);
2142
- event.preventDefault();
2215
+ if (editingKey) {
2216
+ handleCellClick(rowNumber, record, column);
2143
2217
  }
2144
- },
2145
- style: {
2146
- userSelect: 'none'
2147
2218
  }
2148
- };
2149
- },
2150
- render: (value, record, rowIndex) => {
2151
- const rowNumber = (0, _hooks.getRowNumber)(dataSource, record[rowKey], rowKey);
2152
- const colFormat = typeof column.format === 'function' ? column.format(record) : column.format;
2153
- const cellFormat = (0, _hooks.getFormat)(colFormat, format);
2154
- const rowError = dataErrors.find(it => it.index === rowNumber);
2155
- const cellError = rowError && column.field && rowError[column.field]?.field === column.field ? rowError[column.field] : null;
2156
-
2157
- // const aaa = dataErrors.find((it) => column?.field && it[column.field].field === column.field && it.index === rowNumber)
2158
- // const aaa = column.field && rowError && rowError[column.field]?.field === column?.field
2219
+ },
2220
+ // className: isEditing(record) ? `rc-ui-cell-editable cell-editing ${!isEditable(column as any, record) ? 'disable' : ''}` : `rc-ui-cell-editable cell-editable ${!isEditable(column as any, record) ? 'disable' : ''}`,
2221
+ className: (0, _classnames.default)('rc-ui-cell-editable', {
2222
+ 'cell-editing': isEditing(record),
2223
+ 'cell-editable': !isEditing(record),
2224
+ // selected: isSelectedCell(rangeCells,rowIndex, colIndex),
2225
+ // 'cell-border-bottom': isRangeCell(rangeCells, 'bottom',rowIndex, colIndex),
2226
+ // 'cell-border-right': isRangeCell(rangeCells, 'right',rowIndex, colIndex),
2227
+ // 'cell-border-top': isRangeCell(rangeCells, 'top',rowIndex, colIndex),
2228
+ // 'cell-border-left': isRangeCell(rangeCells, 'left',rowIndex, colIndex),
2229
+ disable: !(0, _hooks.isEditable)(column, record)
2230
+ }),
2231
+ record,
2232
+ column: column,
2233
+ editType: (0, _hooks.getEditType)(column, record),
2234
+ dataIndex: column.dataIndex,
2235
+ indexRow: rowNumber,
2236
+ indexCol: colIndex,
2237
+ title: (0, _columns.getValueCell)(column, record[column.field], format),
2238
+ 'data-col-index': colIndex,
2239
+ 'data-row-index': rowNumber,
2240
+ 'data-tooltip-id': "tooltip-cell-content",
2241
+ editing: isEditing(record) && rowEditable?.(record) !== false && (0, _hooks.isEditable)(column, record),
2242
+ cellEditing,
2243
+ t,
2244
+ tabIndex: (rowIndex ?? 0) * visibleCols.length + colIndex,
2245
+ style: isPasteDragging ? {
2246
+ cursor: "crosshair"
2247
+ } : {}
2248
+ };
2249
+ },
2250
+ onHeaderCell: (data, index) => {
2251
+ return {
2252
+ ...(column.onHeaderCell ? column.onHeaderCell?.(data, index) : {}),
2253
+ onClick: () => {
2254
+ handleClickColHeader(column, colIndex);
2255
+ },
2256
+ onCopy: e => {
2257
+ if (editingKey === '') {
2258
+ handleCopy(e);
2259
+ e.preventDefault();
2260
+ }
2261
+ },
2262
+ onPaste: event => {
2263
+ if (editingKey === '') {
2264
+ handlePaste(dataSource[0], colIndex, 0, event);
2265
+ event.preventDefault();
2266
+ }
2267
+ },
2268
+ style: {
2269
+ userSelect: 'none'
2270
+ }
2271
+ };
2272
+ },
2273
+ render: (value, record, rowIndex) => {
2274
+ const rowNumber = (0, _hooks.getRowNumber)(dataSource, record[rowKey], rowKey);
2275
+ const colFormat = typeof column.format === 'function' ? column.format(record) : column.format;
2276
+ const cellFormat = (0, _hooks.getFormat)(colFormat, format);
2277
+ const rowError = dataErrors.find(it => it.index === rowNumber);
2278
+ const cellError = rowError && column.field && rowError[column.field]?.field === column.field ? rowError[column.field] : null;
2279
+
2280
+ // const aaa = dataErrors.find((it) => column?.field && it[column.field].field === column.field && it.index === rowNumber)
2281
+ // const aaa = column.field && rowError && rowError[column.field]?.field === column?.field
2282
+
2283
+ return /*#__PURE__*/_react.default.createElement("div", {
2284
+ className: (0, _classnames.default)('ui-rc_cell-content', {
2285
+ // disable: !isEditable(column as any, record)
2286
+ isValid: column.field && rowError && rowError[column.field]?.field === column?.field
2287
+ }),
2288
+ onMouseDown: event => handleMouseDown(record, rowNumber, colIndex, event),
2289
+ onMouseEnter: event => {
2290
+ // setTooltipContent(cellError ? cellError.message : renderContent(column as any, value, record, rowIndex, cellFormat))
2291
+ setTooltipContent(cellError ? cellError.message : '');
2292
+ handleMouseEnter(rowNumber, colIndex, event);
2293
+ },
2294
+ onMouseUp: handleMouseUp,
2295
+ onMouseMove: () => {
2296
+ if (selectedCells && selectedCells.current.size > 0 && isMouseDown.current) {
2297
+ (0, _hooks.hideDraggingPoint)(selectedCells.current, id);
2298
+ isDragMouse.current = true;
2299
+ }
2300
+ }
2159
2301
 
2160
- return /*#__PURE__*/_react.default.createElement("div", {
2161
- className: (0, _classnames.default)('ui-rc_cell-content', {
2162
- // disable: !isEditable(column as any, record)
2163
- isValid: column.field && rowError && rowError[column.field]?.field === column?.field
2164
- }),
2165
- onMouseDown: event => handleMouseDown(record, rowNumber, colIndex, event),
2166
- onMouseEnter: event => {
2167
- // setTooltipContent(cellError ? cellError.message : renderContent(column as any, value, record, rowIndex, cellFormat))
2168
- setTooltipContent(cellError ? cellError.message : '');
2169
- handleMouseEnter(rowNumber, colIndex, event);
2170
- },
2171
- onMouseUp: handleMouseUp,
2172
- onMouseMove: () => {
2173
- if (selectedCells && selectedCells.current.size > 0 && isMouseDown.current) {
2174
- (0, _hooks.hideDraggingPoint)(selectedCells.current, id);
2175
- isDragMouse.current = true;
2176
- }
2302
+ // onClick={(event) => {
2303
+ //
2304
+ // handleClickCell(event)
2305
+ //
2306
+ // }}
2307
+ }, /*#__PURE__*/_react.default.createElement("div", {
2308
+ className: 'ui-rc_content'
2309
+ }, (0, _columns.renderContent)(column, value, record, rowIndex, cellFormat)),
2310
+ // selectedCells.current && selectedCells.current.size > 0 && getLastSelectCell(selectedCells.current).row === rowNumber &&
2311
+ // getLastSelectCell(selectedCells.current).col === colIndex &&
2312
+ // isEditable(column as any, record) &&
2313
+
2314
+ !isDragMouse.current && /*#__PURE__*/_react.default.createElement("div", {
2315
+ className: 'dragging-point hidden',
2316
+ onMouseDown: e => {
2317
+ // e.stopPropagation()
2318
+ e.preventDefault();
2319
+ if (e.button === 0) {
2320
+ setIsPasteDragging(true);
2177
2321
  }
2322
+ },
2323
+ onDoubleClick: handlePointDoubleClick
2324
+ }, /*#__PURE__*/_react.default.createElement("span", {
2325
+ className: 'dot-point'
2326
+ })));
2327
+ }
2328
+ };
2329
+ });
2330
+ // [
2331
+ // cellEditing,
2332
+ // columns,
2333
+ // dataErrors,
2334
+ // dataSource,
2335
+ // editingKey,
2336
+ // format,
2337
+ // getRowKey,
2338
+ // handleAddSingle,
2339
+ // handleCellClick,
2340
+ // handleClickColHeader,
2341
+ // handleCopy,
2342
+ // handleDeleteContent,
2343
+ // handleEdit,
2344
+ // handleFocusCell,
2345
+ // handleMouseDown,
2346
+ // handleMouseDownRowHeader,
2347
+ // handleMouseEnter,
2348
+ // handleMouseEnterRowHeader,
2349
+ // handleMouseUp,
2350
+ // handlePaste,
2351
+ // handlePointDoubleClick,
2352
+ // id,
2353
+ // isEditing,
2354
+ // isPasteDragging,
2355
+ // mergedExpandedKeys,
2356
+ // onTriggerExpand,
2357
+ // rowEditable,
2358
+ // rowKey,
2359
+ // setTooltipContent,
2360
+ // t,
2361
+ // visibleCols.length
2362
+ // ])
2178
2363
 
2179
- // onClick={(event) => {
2180
- //
2181
- // handleClickCell(event)
2182
- //
2183
- // }}
2184
- }, /*#__PURE__*/_react.default.createElement("div", {
2185
- className: 'ui-rc_content'
2186
- }, (0, _columns.renderContent)(column, value, record, rowIndex, cellFormat)),
2187
- // selectedCells.current && selectedCells.current.size > 0 && getLastSelectCell(selectedCells.current).row === rowNumber &&
2188
- // getLastSelectCell(selectedCells.current).col === colIndex &&
2189
- // isEditable(column as any, record) &&
2190
-
2191
- !isDragMouse.current && /*#__PURE__*/_react.default.createElement("div", {
2192
- className: 'dragging-point hidden',
2193
- onMouseDown: e => {
2194
- // e.stopPropagation()
2195
- e.preventDefault();
2196
- if (e.button === 0) {
2197
- setIsPasteDragging(true);
2198
- }
2199
- },
2200
- onDoubleClick: handlePointDoubleClick
2201
- }, /*#__PURE__*/_react.default.createElement("span", {
2202
- className: 'dot-point'
2203
- })));
2204
- }
2205
- };
2206
- });
2207
- }, [cellEditing, columns, dataErrors, dataSource, editingKey, format, getRowKey, handleAddSingle, handleCellClick, handleClickColHeader, handleCopy, handleDeleteContent, handleEdit, handleFocusCell, handleMouseDown, handleMouseDownRowHeader, handleMouseEnter, handleMouseEnterRowHeader, handleMouseUp, handlePaste, handlePointDoubleClick, id, isEditing, isPasteDragging, mergedExpandedKeys, onTriggerExpand, rangeCells, rowEditable, rowKey, setTooltipContent, t, visibleCols.length]);
2208
2364
  const transformColumns = _react.default.useCallback(cols => {
2209
2365
  // @ts-ignore
2210
2366
  return cols.map(column => {
@@ -2212,6 +2368,14 @@ const GridEdit = props => {
2212
2368
  if (column === _InternalTable.SELECTION_COLUMN) {
2213
2369
  return _InternalTable.SELECTION_COLUMN;
2214
2370
  }
2371
+
2372
+ // Xử lý đệ quy cho children
2373
+ if (column.children?.length) {
2374
+ return {
2375
+ ...column,
2376
+ children: transformColumns(column.children)
2377
+ };
2378
+ }
2215
2379
  if (find) {
2216
2380
  return {
2217
2381
  ...find
@@ -2222,14 +2386,6 @@ const GridEdit = props => {
2222
2386
  ...column
2223
2387
  };
2224
2388
  }
2225
-
2226
- // Xử lý đệ quy cho children
2227
- if (column.children?.length) {
2228
- return {
2229
- ...column,
2230
- children: transformColumns(column.children)
2231
- };
2232
- }
2233
2389
  });
2234
2390
  }, [convertColumns]);
2235
2391
  const mergedColumns = _react.default.useMemo(() => transformColumns(columns ?? []), [transformColumns, columns]);
@@ -2312,10 +2468,12 @@ const GridEdit = props => {
2312
2468
  };
2313
2469
  return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement(_GridStyle.GridStyle, {
2314
2470
  $heightTable: height,
2471
+ $heightScroll: scrollHeight,
2315
2472
  style: {
2316
2473
  position: 'relative'
2317
2474
  },
2318
- ref: ref
2475
+ ref: ref,
2476
+ id: id
2319
2477
  }, /*#__PURE__*/_react.default.createElement(_useContext.TableContext.Provider, {
2320
2478
  value: {
2321
2479
  rowKey,