es-grid-template 1.4.5 → 1.4.7

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.
@@ -954,7 +954,7 @@ const GridEdit = props => {
954
954
  const isEditing = _react.default.useCallback(record => {
955
955
  return record[rowKey] === editingKey;
956
956
  }, [editingKey, rowKey]);
957
- (0, _react.useEffect)(() => {
957
+ _react.default.useEffect(() => {
958
958
  const handleClickOutside = event => {
959
959
  const element = event.target;
960
960
 
@@ -994,9 +994,11 @@ const GridEdit = props => {
994
994
  setRangeCells(new Set());
995
995
  }
996
996
  };
997
- document.addEventListener("click", handleClickOutside);
997
+ document.addEventListener('mousedown', handleClickOutside);
998
+ document.addEventListener('touchstart', handleClickOutside);
998
999
  return () => {
999
- document.removeEventListener("click", handleClickOutside);
1000
+ document.removeEventListener('mousedown', handleClickOutside);
1001
+ document.removeEventListener('touchstart', handleClickOutside);
1000
1002
  };
1001
1003
  }, [id]);
1002
1004
  const triggerDragPaste = pastesArray => {
@@ -1118,210 +1120,482 @@ const GridEdit = props => {
1118
1120
  }
1119
1121
  pasteCells.current = new Set();
1120
1122
  };
1121
- const handlePointDoubleClick = e => {
1122
- // e.preventDefault()
1123
- e.stopPropagation();
1124
- const colStart = (0, _hooks.getFirstSelectCell)(selectedCells.current).col;
1125
- const colEnd = (0, _hooks.getLastSelectCell)(selectedCells.current).col;
1126
- const startPasteRow = (0, _hooks.getLastSelectCell)(selectedCells.current).row;
1127
- const newPasteCells = new Set();
1128
- for (let r = Math.min(startPasteRow, dataSource.length - 1) + 1; r <= Math.max(startPasteRow, dataSource.length - 1); r++) {
1129
- for (let c = Math.min(colStart, colStart); c <= Math.max(colStart, colEnd); c++) {
1130
- newPasteCells.add(`${r}-${c}`);
1131
- }
1132
- }
1133
- (0, _hooks.hideDraggingPoint)(selectedCells.current, id);
1134
- triggerDragPaste(newPasteCells);
1135
- };
1136
- const handleMouseDown = (record, row, col, e) => {
1137
- if (e.button === 2) {
1138
- e.stopPropagation();
1139
- return;
1140
- }
1141
- if (editingKey && editingKey === record[rowKey]) {
1142
- return;
1143
- }
1144
- if (record[rowKey] !== editingKey && editingKey !== '') {
1145
- setEditingKey('');
1146
- }
1123
+ const handlePasted = (record, indexCol, rowNumber, pasteData) => {
1124
+ const rows = pasteData.slice(0, onCellPaste?.maxRowsPaste ?? 200);
1125
+ if (!record?.parentId) {
1126
+ // Cập nhật data mới
1127
+ const newData = [...dataSource];
1147
1128
 
1148
- // isDragMouse.current = true
1149
- isMouseDown.current = true;
1150
- if (e.ctrlKey) {
1151
- isSelecting.current = true;
1152
- startCell.current = {
1153
- row,
1154
- col
1155
- };
1129
+ // const indexRows = newData.findIndex((it) => it[rowKey as any] === record[rowKey])
1156
1130
 
1157
- // const cell: any = new Set([`${row}-${col}`])
1131
+ // Lấy vị trí bắt đầu
1132
+ // const { row: startRow, col: startCol } = selectedCell;
1133
+ const startRow = newData.findIndex(it => it[rowKey] === record[rowKey]);
1134
+ const startCol = indexCol;
1158
1135
 
1159
- // setCurrentCtrlCells(cell)
1160
- } else {
1161
- isSelecting.current = true;
1162
- startCell.current = {
1163
- row,
1164
- col
1165
- };
1166
- const target = e.target;
1167
- if (target.closest('.dragging-point')) {
1168
- e.stopPropagation();
1169
- e.preventDefault();
1170
- return; // Không xử lý gì cả
1171
- } else {
1172
- // setStartSelectedCell({row, col})
1136
+ // const flattData = flattenArray(newData);
1173
1137
 
1174
- startSelectedCells.current = {
1175
- row,
1176
- col
1177
- };
1138
+ const pastedRows = [];
1139
+ const pastedColumns = new Set();
1140
+ rows.forEach((rowValues, rowIndex) => {
1141
+ const targetRow = startRow + rowIndex;
1178
1142
 
1179
- // setSelectedCells(new Set([`${row}-${col}`]));
1143
+ // Nếu vượt quá số dòng hiện có, thêm dòng mới
1144
+ if (targetRow >= newData.length) {
1145
+ // @ts-ignore
1146
+ // newData.push({ id: newGuid()});
1147
+ newData.push({
1148
+ id: undefined,
1149
+ rowId: (0, _hooks.newGuid)()
1150
+ });
1151
+ }
1152
+ rowValues.forEach((cellValue, colIndex) => {
1153
+ const targetCol = startCol + colIndex;
1154
+ if (targetCol >= visibleCols.length) {
1155
+ // Không vượt quá số cột
1156
+ return;
1157
+ }
1158
+ if (visibleCols[targetCol].editEnable) {
1159
+ // @ts-ignore
1160
+ const columnKey = visibleCols[targetCol].field;
1180
1161
 
1181
- const cells = new Set([`${row}-${col}`]);
1182
- if (selectedCells.current && selectedCells.current.size > 0) {
1183
- if (!(0, _hooks.isEqualSet)(cells, rangeCells)) {
1184
- // onRemoveBgSelectedCell(rangeCells, id)
1185
- // onRemoveBorderSelectedCell(rangeCells, id)
1186
- (0, _hooks.hideDraggingPoint)(rangeCells, id);
1187
- (0, _hooks.onRemoveBgCellIndex)(selectedCells.current, id);
1162
+ // @ts-ignore
1163
+ newData[targetRow] = {
1164
+ ...newData[targetRow],
1165
+ [columnKey]: cellValue.trim()
1166
+ };
1167
+ pastedColumns.add(columnKey);
1188
1168
  }
1189
- }
1190
- if (rowsSelected.current && rowsSelected.current.size > 0) {
1191
- (0, _hooks.removeClassCellIndexSelected)(rowsSelected.current, id);
1192
- }
1193
- if (!(0, _hooks.isEqualSet)(cells, selectedCells.current)) {
1194
- (0, _hooks.onRemoveBgSelectedCell)(selectedCells.current, id);
1195
- (0, _hooks.hideDraggingPoint)(selectedCells.current, id);
1196
- selectedCells.current = cells;
1197
- // setRangeCells(cells)
1169
+ });
1198
1170
 
1199
- (0, _hooks.onAddBgCellIndex)(cells, id);
1200
- (0, _hooks.onAddBorderSelectedCell)(cells, id);
1201
- (0, _hooks.onAddBgSelectedCell)(selectedCells.current, id, false);
1202
- (0, _hooks.showDraggingPoint)(selectedCells.current, id);
1203
- }
1171
+ // Lưu dòng được paste
1172
+ pastedRows.push(newData[targetRow]);
1173
+ });
1174
+ const pastedColumnsArray = Array.from(pastedColumns) ?? [];
1175
+ triggerPaste?.(pastedRows, pastedColumnsArray, newData);
1176
+ } else {
1177
+ // Cập nhật data mới
1178
+ const newData = [...dataSource];
1179
+ const parent = (0, _hooks.findItemByKey)(newData, rowKey, record.parentId);
1204
1180
 
1205
- // setRowsSelected(new Set())
1206
- rowsSelected.current = new Set();
1207
- }
1208
- }
1209
- };
1210
- const handleMouseUp = e => {
1211
- isSelecting.current = false;
1212
- startCell.current = null;
1213
- isSelectingRow.current = false;
1214
- rowStart.current = null;
1215
- isDragMouse.current = false;
1216
- isMouseDown.current = false;
1217
- setIsPasteDragging(false);
1218
- if (e.ctrlKey) {
1181
+ // Cập nhật childData mới
1182
+ const childData = parent?.children ? [...parent.children] : [];
1219
1183
 
1220
- // setCtrlCells([...ctrlCells, currentCtrlCells])
1221
- }
1184
+ // Lấy vị trí bắt đầu
1185
+ // const { row: startRow, col: startCol } = selectedCell;
1186
+ const startRow = childData.findIndex(it => it[rowKey] === record[rowKey]);
1187
+ const startCol = indexCol;
1188
+ const pastedRows = [];
1189
+ const pastedColumns = new Set();
1190
+ rows.forEach((rowValues, rowIndex) => {
1191
+ const targetRow = startRow + rowIndex;
1222
1192
 
1223
- // nếu ctrlCell length > 0 thì set selectCells
1193
+ // Nếu vượt quá số dòng hiện có, thêm dòng mới
1194
+ if (targetRow >= childData.length) {
1195
+ childData.push({
1196
+ id: undefined,
1197
+ rowId: (0, _hooks.newGuid)(),
1198
+ parentId: parent[rowKey ?? 'id']
1199
+ });
1200
+ }
1201
+ rowValues.forEach((cellValue, colIndex) => {
1202
+ const targetCol = startCol + colIndex;
1203
+ if (targetCol >= visibleCols.length) {
1204
+ // Không vượt quá số cột
1205
+ return;
1206
+ }
1207
+ if (visibleCols[targetCol].editEnable) {
1208
+ // @ts-ignore
1209
+ const columnKey = visibleCols[targetCol].field;
1224
1210
 
1225
- if (pasteCells && pasteCells.current.size > 0) {
1226
- triggerDragPaste(pasteCells.current);
1227
- } else {
1228
- setRangeCells(selectedCells.current);
1229
- const target = e.target;
1230
- if (target.closest('.dragging-point')) {
1231
- e.stopPropagation();
1232
- e.preventDefault();
1233
- return; // Không xử lý gì cả
1234
- }
1235
- if (selectedCells.current && selectedCells.current.size > 1) {
1236
- (0, _hooks.hideDraggingPoint)(selectedCells.current, id);
1237
- (0, _hooks.onAddBorderSelectedCell)(selectedCells.current, id);
1211
+ // @ts-ignore
1212
+ childData[targetRow] = {
1213
+ ...childData[targetRow],
1214
+ [columnKey]: cellValue.trim()
1215
+ };
1216
+ pastedColumns.add(columnKey);
1217
+ }
1218
+ });
1238
1219
 
1239
- // showDraggingPoint(selectedCells.current, id)
1240
- }
1241
- (0, _hooks.showDraggingPoint)(selectedCells.current, id);
1242
- // onAddBorderSelectedCell(selectedCells.current, id)
1220
+ // Lưu dòng được paste
1221
+ pastedRows.push(childData[targetRow]);
1222
+ });
1223
+ const pastedColumnsArray = Array.from(pastedColumns) ?? [];
1224
+ const newRowData = {
1225
+ ...parent,
1226
+ children: childData
1227
+ };
1228
+ const newDataSource = (0, _hooks.updateArrayByKey)(newData, newRowData, rowKey);
1229
+ triggerPaste?.(pastedRows, pastedColumnsArray, newDataSource);
1243
1230
  }
1244
1231
  };
1245
- const handleMouseEnter = (row, col, e) => {
1246
- if (!isSelecting.current || !startCell.current) {
1247
- return;
1248
- }
1249
- const {
1250
- row: startRow,
1251
- col: startCol
1252
- } = startCell.current;
1253
- if (e.ctrlKey) {
1254
- // const newCtrlCells = new Set();
1255
- // for (let r = Math.min(startRow, row); r <= Math.max(startRow, row); r++) {
1256
- // for (let c = Math.min(startCol, col); c <= Math.max(startCol, col); c++) {
1257
- // newCtrlCells.add(`${r}-${c}`)
1258
- // }
1259
- // }
1232
+ const handlePaste = (record, indexCol, rowNumber, e) => {
1233
+ // const clipboard: any = (e.clipboardData || (window && window?.Clipboard)).getData("text")
1234
+ const pasteData = e.clipboardData.getData("text/plain");
1260
1235
 
1261
- // setCurrentCtrlCells(newCtrlCells)
1236
+ // Chuyển đổi dữ liệu từ clipboard thành mảng
1237
+ const rowsPasted = pasteData.split("\n").map(row =>
1238
+ // const rows = pasteData.split("\n").map((row: any) =>
1239
+ row.replace(/\r/g, "").split("\t"));
1240
+ if (rowsPasted.length > (onCellPaste?.maxRowsPaste ?? 200)) {
1241
+ // bật popup thông báo
1262
1242
 
1263
- return;
1243
+ _antd.Modal.confirm({
1244
+ content: /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(Paragraph, {
1245
+ style: {
1246
+ marginBottom: '.25rem',
1247
+ fontSize: 14
1248
+ }
1249
+ }, "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, {
1250
+ level: 5,
1251
+ style: {
1252
+ marginTop: '.75rem'
1253
+ }
1254
+ }, "B\u1EA1n c\xF3 mu\u1ED1n ti\u1EBFp t\u1EE5c sao ch\xE9p kh\xF4ng?")),
1255
+ centered: true,
1256
+ className: 'be-popup-container',
1257
+ onOk: () => {
1258
+ handlePasted(record, indexCol, rowNumber, rowsPasted);
1259
+ }
1260
+ // footer: (_, { OkBtn, CancelBtn }) => (
1261
+ // <>
1262
+ // <OkBtn />
1263
+ // <CancelBtn />
1264
+ // </>
1265
+ // ),
1266
+ });
1267
+ } else {
1268
+ handlePasted(record, indexCol, rowNumber, rowsPasted);
1264
1269
  }
1265
- if (!isPasteDragging) {
1266
- // chọn vùng copy
1267
-
1268
- // setSelectIsDragging(true)
1269
1270
 
1270
- setIsPasteDragging(false);
1271
- // isPasteDragging.current = false
1272
-
1273
- const newSelectedCells = new Set();
1274
- for (let r = Math.min(startRow, row); r <= Math.max(startRow, row); r++) {
1275
- for (let c = Math.min(startCol, col); c <= Math.max(startCol, col); c++) {
1276
- newSelectedCells.add(`${r}-${c}`);
1277
- }
1271
+ // const rows = rowsPasted.slice(0, (onCellPaste?.maxRowsPaste ?? 200));
1272
+ //
1273
+ //
1274
+ // if (!record?.parentId ) {
1275
+ //
1276
+ // // Cập nhật data mới
1277
+ // const newData = [...dataSource];
1278
+ //
1279
+ // // @ts-ignore
1280
+ // const indexRows = newData.findIndex((it) => it[rowKey] === record[rowKey])
1281
+ //
1282
+ // // Lấy vị trí bắt đầu
1283
+ // // const { row: startRow, col: startCol } = selectedCell;
1284
+ // const startRow = indexRows
1285
+ // const startCol = indexCol
1286
+ //
1287
+ //
1288
+ //
1289
+ // // const flattData = flattenArray(newData);
1290
+ //
1291
+ // const pastedRows: RecordType[] = [];
1292
+ // const pastedColumns = new Set()
1293
+ //
1294
+ //
1295
+ // rows.forEach((rowValues: any, rowIndex: any) => {
1296
+ // const targetRow = startRow + rowIndex;
1297
+ //
1298
+ // // Nếu vượt quá số dòng hiện có, thêm dòng mới
1299
+ // if (targetRow >= newData.length) {
1300
+ // // @ts-ignore
1301
+ // // newData.push({ id: newGuid()});
1302
+ // newData.push({ id: undefined, rowId: newGuid()});
1303
+ // }
1304
+ //
1305
+ // rowValues.forEach((cellValue: any, colIndex: any) => {
1306
+ // const targetCol = startCol + colIndex;
1307
+ // if (targetCol >= columns.length) { // Không vượt quá số cột
1308
+ // return
1309
+ // }
1310
+ //
1311
+ // if (columns[targetCol].editEnable) {
1312
+ // // @ts-ignore
1313
+ // const columnKey = columns[targetCol].field;
1314
+ //
1315
+ // // @ts-ignore
1316
+ // newData[targetRow] = { ...newData[targetRow], [columnKey]: cellValue.trim() };
1317
+ // pastedColumns.add(columnKey);
1318
+ // }
1319
+ //
1320
+ // });
1321
+ //
1322
+ // // Lưu dòng được paste
1323
+ // pastedRows.push(newData[targetRow]);
1324
+ //
1325
+ // });
1326
+ //
1327
+ // const pastedColumnsArray = Array.from(pastedColumns) ?? [];
1328
+ //
1329
+ // triggerPaste?.(pastedRows, pastedColumnsArray as string[], newData)
1330
+ //
1331
+ //
1332
+ // } else {
1333
+ //
1334
+ // // Cập nhật data mới
1335
+ // const newData = [...dataSource];
1336
+ //
1337
+ // const parent = findItemByKey(newData, rowKey as any, record.parentId)
1338
+ //
1339
+ // // Cập nhật childData mới
1340
+ // const childData: any[] = parent?.children ? [...parent.children] : []
1341
+ //
1342
+ //
1343
+ // // Lấy vị trí bắt đầu
1344
+ // // const { row: startRow, col: startCol } = selectedCell;
1345
+ // const startRow = childData.findIndex((it) => it[rowKey] === record[rowKey])
1346
+ // const startCol = indexCol
1347
+ //
1348
+ // const pastedRows: RecordType[] = []
1349
+ // const pastedColumns = new Set()
1350
+ //
1351
+ //
1352
+ // rows.forEach((rowValues: any, rowIndex: any) => {
1353
+ // const targetRow = startRow + rowIndex
1354
+ //
1355
+ // // Nếu vượt quá số dòng hiện có, thêm dòng mới
1356
+ // if (targetRow >= childData.length) {
1357
+ //
1358
+ // childData.push({ id: undefined, rowId: newGuid(), parentId: parent[rowKey ?? 'id']})
1359
+ // }
1360
+ //
1361
+ // rowValues.forEach((cellValue: any, colIndex: any) => {
1362
+ // const targetCol = startCol + colIndex
1363
+ // if (targetCol >= columns.length) { // Không vượt quá số cột
1364
+ // return
1365
+ // }
1366
+ //
1367
+ // if (columns[targetCol].editEnable) {
1368
+ //
1369
+ // // @ts-ignore
1370
+ // const columnKey = columns[targetCol].field
1371
+ //
1372
+ // // @ts-ignore
1373
+ // childData[targetRow] = { ...childData[targetRow], [columnKey]: cellValue.trim() }
1374
+ // pastedColumns.add(columnKey)
1375
+ // }
1376
+ //
1377
+ // })
1378
+ //
1379
+ // // Lưu dòng được paste
1380
+ // pastedRows.push(childData[targetRow])
1381
+ //
1382
+ // })
1383
+ //
1384
+ // const pastedColumnsArray = Array.from(pastedColumns) ?? []
1385
+ //
1386
+ // const newRowData = {...parent, children: childData}
1387
+ //
1388
+ // const newDataSource = updateArrayByKey(newData, newRowData, rowKey as string)
1389
+ //
1390
+ // triggerPaste?.(pastedRows, pastedColumnsArray as string[], newDataSource )
1391
+ // }
1392
+ };
1393
+ const handlePointDoubleClick = e => {
1394
+ // e.preventDefault()
1395
+ e.stopPropagation();
1396
+ const colStart = (0, _hooks.getFirstSelectCell)(selectedCells.current).col;
1397
+ const colEnd = (0, _hooks.getLastSelectCell)(selectedCells.current).col;
1398
+ const startPasteRow = (0, _hooks.getLastSelectCell)(selectedCells.current).row;
1399
+ const newPasteCells = new Set();
1400
+ for (let r = Math.min(startPasteRow, dataSource.length - 1) + 1; r <= Math.max(startPasteRow, dataSource.length - 1); r++) {
1401
+ for (let c = Math.min(colStart, colStart); c <= Math.max(colStart, colEnd); c++) {
1402
+ newPasteCells.add(`${r}-${c}`);
1278
1403
  }
1404
+ }
1405
+ (0, _hooks.hideDraggingPoint)(selectedCells.current, id);
1406
+ triggerDragPaste(newPasteCells);
1407
+ };
1408
+ const handleMouseDown = (record, row, col, e) => {
1409
+ if (e.button === 2) {
1410
+ e.stopPropagation();
1411
+ return;
1412
+ }
1413
+ if (editingKey && editingKey === record[rowKey]) {
1414
+ return;
1415
+ }
1416
+ if (record[rowKey] !== editingKey && editingKey !== '') {
1417
+ setTimeout(() => {
1418
+ setEditingKey('');
1419
+ });
1420
+ }
1279
1421
 
1280
- // setSelectedCells(newSelectedCells)
1422
+ // isDragMouse.current = true
1423
+ isMouseDown.current = true;
1424
+ if (e.ctrlKey) {
1425
+ isSelecting.current = true;
1426
+ startCell.current = {
1427
+ row,
1428
+ col
1429
+ };
1281
1430
 
1282
- if (selectedCells.current && selectedCells.current.size > 0) {
1283
- (0, _hooks.onRemoveBgSelectedCell)(selectedCells.current, id);
1284
- }
1285
- selectedCells.current = newSelectedCells;
1286
- (0, _hooks.onAddBgSelectedCell)(newSelectedCells, id);
1287
- } else {
1288
- // chọn vùng paste
1431
+ // const cell: any = new Set([`${row}-${col}`])
1289
1432
 
1290
- // setSelectIsDragging(false)
1433
+ // setCurrentCtrlCells(cell)
1434
+ } else {
1435
+ isSelecting.current = true;
1436
+ startCell.current = {
1437
+ row,
1438
+ col
1439
+ };
1440
+ const target = e.target;
1441
+ if (target.closest('.dragging-point')) {
1442
+ e.stopPropagation();
1443
+ e.preventDefault();
1444
+ return; // Không xử lý gì cả
1445
+ } else {
1446
+ // setStartSelectedCell({row, col})
1291
1447
 
1292
- // setIsPasteDragging(true) ////////
1448
+ startSelectedCells.current = {
1449
+ row,
1450
+ col
1451
+ };
1293
1452
 
1294
- const newSelectedCells = new Set();
1295
- for (let r = Math.min(startRow, row); r <= Math.max(startRow, row); r++) {
1296
- for (let c = Math.min(startCol, col); c <= Math.max(startCol, col); c++) {
1297
- newSelectedCells.add(`${r}-${c}`);
1298
- }
1299
- }
1300
- const colStart = (0, _hooks.getFirstSelectCell)(selectedCells.current).col;
1301
- const colEnd = (0, _hooks.getLastSelectCell)(selectedCells.current).col;
1302
- const rowSelectedEnd = (0, _hooks.getLastSelectCell)(selectedCells.current).row;
1303
- if (row >= rowSelectedEnd) {
1304
- // kéo xuống dưới
1453
+ // setSelectedCells(new Set([`${row}-${col}`]));
1305
1454
 
1306
- const newPasteCells = new Set();
1307
- for (let r = Math.min(startRow, row) + 1; r <= Math.max(startRow, row); r++) {
1308
- for (let c = Math.min(colStart, col); c <= Math.max(colStart, colEnd); c++) {
1309
- newPasteCells.add(`${r}-${c}`);
1455
+ const cells = new Set([`${row}-${col}`]);
1456
+ if (selectedCells.current && selectedCells.current.size > 0) {
1457
+ if (!(0, _hooks.isEqualSet)(cells, rangeCells)) {
1458
+ // onRemoveBgSelectedCell(rangeCells, id)
1459
+ // onRemoveBorderSelectedCell(rangeCells, id)
1460
+ (0, _hooks.hideDraggingPoint)(rangeCells, id);
1461
+ (0, _hooks.onRemoveBgCellIndex)(selectedCells.current, id);
1310
1462
  }
1311
1463
  }
1464
+ if (rowsSelected.current && rowsSelected.current.size > 0) {
1465
+ (0, _hooks.removeClassCellIndexSelected)(rowsSelected.current, id);
1466
+ }
1467
+ if (!(0, _hooks.isEqualSet)(cells, selectedCells.current)) {
1468
+ (0, _hooks.onRemoveBgSelectedCell)(selectedCells.current, id);
1469
+ (0, _hooks.hideDraggingPoint)(selectedCells.current, id);
1470
+ selectedCells.current = cells;
1471
+ // setRangeCells(cells)
1312
1472
 
1313
- // setPasteCells(newPasteCells)
1314
-
1315
- if (pasteCells.current && pasteCells.current.size > 0) {
1316
- (0, _hooks.removeClassBorderPasteCell)(pasteCells.current, 'down', id);
1473
+ (0, _hooks.onAddBgCellIndex)(cells, id);
1474
+ (0, _hooks.onAddBorderSelectedCell)(cells, id);
1475
+ (0, _hooks.onAddBgSelectedCell)(selectedCells.current, id, false);
1476
+ (0, _hooks.showDraggingPoint)(selectedCells.current, id);
1317
1477
  }
1318
- pasteCells.current = newPasteCells;
1319
- (0, _hooks.addClassBorderPasteCell)(newPasteCells, 'down', id);
1478
+
1479
+ // setRowsSelected(new Set())
1480
+ rowsSelected.current = new Set();
1320
1481
  }
1321
- if (row < rowSelectedEnd) {
1322
- // kéo lên trên
1482
+ }
1483
+ };
1484
+ const handleMouseUp = e => {
1485
+ isSelecting.current = false;
1486
+ startCell.current = null;
1487
+ isSelectingRow.current = false;
1488
+ rowStart.current = null;
1489
+ isDragMouse.current = false;
1490
+ isMouseDown.current = false;
1491
+ setIsPasteDragging(false);
1492
+ if (e.ctrlKey) {
1323
1493
 
1324
- const rowSelectedStart = (0, _hooks.getFirstSelectCell)(selectedCells.current).row;
1494
+ // setCtrlCells([...ctrlCells, currentCtrlCells])
1495
+ }
1496
+
1497
+ // nếu ctrlCell length > 0 thì set selectCells
1498
+
1499
+ if (pasteCells && pasteCells.current.size > 0) {
1500
+ triggerDragPaste(pasteCells.current);
1501
+ } else {
1502
+ setRangeCells(selectedCells.current);
1503
+ const target = e.target;
1504
+ if (target.closest('.dragging-point')) {
1505
+ e.stopPropagation();
1506
+ e.preventDefault();
1507
+ return; // Không xử lý gì cả
1508
+ }
1509
+ if (selectedCells.current && selectedCells.current.size > 1) {
1510
+ (0, _hooks.hideDraggingPoint)(selectedCells.current, id);
1511
+ (0, _hooks.onAddBorderSelectedCell)(selectedCells.current, id);
1512
+
1513
+ // showDraggingPoint(selectedCells.current, id)
1514
+ }
1515
+ (0, _hooks.showDraggingPoint)(selectedCells.current, id);
1516
+ // onAddBorderSelectedCell(selectedCells.current, id)
1517
+ }
1518
+ };
1519
+ const handleMouseEnter = (row, col, e) => {
1520
+ if (!isSelecting.current || !startCell.current) {
1521
+ return;
1522
+ }
1523
+ const {
1524
+ row: startRow,
1525
+ col: startCol
1526
+ } = startCell.current;
1527
+ if (e.ctrlKey) {
1528
+ // const newCtrlCells = new Set();
1529
+ // for (let r = Math.min(startRow, row); r <= Math.max(startRow, row); r++) {
1530
+ // for (let c = Math.min(startCol, col); c <= Math.max(startCol, col); c++) {
1531
+ // newCtrlCells.add(`${r}-${c}`)
1532
+ // }
1533
+ // }
1534
+
1535
+ // setCurrentCtrlCells(newCtrlCells)
1536
+
1537
+ return;
1538
+ }
1539
+ if (!isPasteDragging) {
1540
+ // chọn vùng copy
1541
+
1542
+ // setSelectIsDragging(true)
1543
+
1544
+ setIsPasteDragging(false);
1545
+ // isPasteDragging.current = false
1546
+
1547
+ const newSelectedCells = new Set();
1548
+ for (let r = Math.min(startRow, row); r <= Math.max(startRow, row); r++) {
1549
+ for (let c = Math.min(startCol, col); c <= Math.max(startCol, col); c++) {
1550
+ newSelectedCells.add(`${r}-${c}`);
1551
+ }
1552
+ }
1553
+
1554
+ // setSelectedCells(newSelectedCells)
1555
+
1556
+ if (selectedCells.current && selectedCells.current.size > 0) {
1557
+ (0, _hooks.onRemoveBgSelectedCell)(selectedCells.current, id);
1558
+ }
1559
+ selectedCells.current = newSelectedCells;
1560
+ (0, _hooks.onAddBgSelectedCell)(newSelectedCells, id);
1561
+ } else {
1562
+ // chọn vùng paste
1563
+
1564
+ // setSelectIsDragging(false)
1565
+
1566
+ // setIsPasteDragging(true) ////////
1567
+
1568
+ const newSelectedCells = new Set();
1569
+ for (let r = Math.min(startRow, row); r <= Math.max(startRow, row); r++) {
1570
+ for (let c = Math.min(startCol, col); c <= Math.max(startCol, col); c++) {
1571
+ newSelectedCells.add(`${r}-${c}`);
1572
+ }
1573
+ }
1574
+ const colStart = (0, _hooks.getFirstSelectCell)(selectedCells.current).col;
1575
+ const colEnd = (0, _hooks.getLastSelectCell)(selectedCells.current).col;
1576
+ const rowSelectedEnd = (0, _hooks.getLastSelectCell)(selectedCells.current).row;
1577
+ if (row >= rowSelectedEnd) {
1578
+ // kéo xuống dưới
1579
+
1580
+ const newPasteCells = new Set();
1581
+ for (let r = Math.min(startRow, row) + 1; r <= Math.max(startRow, row); r++) {
1582
+ for (let c = Math.min(colStart, col); c <= Math.max(colStart, colEnd); c++) {
1583
+ newPasteCells.add(`${r}-${c}`);
1584
+ }
1585
+ }
1586
+
1587
+ // setPasteCells(newPasteCells)
1588
+
1589
+ if (pasteCells.current && pasteCells.current.size > 0) {
1590
+ (0, _hooks.removeClassBorderPasteCell)(pasteCells.current, 'down', id);
1591
+ }
1592
+ pasteCells.current = newPasteCells;
1593
+ (0, _hooks.addClassBorderPasteCell)(newPasteCells, 'down', id);
1594
+ }
1595
+ if (row < rowSelectedEnd) {
1596
+ // kéo lên trên
1597
+
1598
+ const rowSelectedStart = (0, _hooks.getFirstSelectCell)(selectedCells.current).row;
1325
1599
  if (row < rowSelectedStart) {
1326
1600
  const newPasteCells = new Set();
1327
1601
  for (let r = Math.min(rowSelectedStart, row); r <= Math.max(rowSelectedStart, row) - 1; r++) {
@@ -1515,276 +1789,6 @@ const GridEdit = props => {
1515
1789
  e.clipboardData.setData("text/plain", copyText);
1516
1790
  (0, _Message.default)(t ? t('CopySuccessful') : 'Copy Successful');
1517
1791
  };
1518
- const handlePasted = (record, indexCol, rowNumber, pasteData) => {
1519
- const rows = pasteData.slice(0, onCellPaste?.maxRowsPaste ?? 200);
1520
- if (!record?.parentId) {
1521
- // Cập nhật data mới
1522
- const newData = [...dataSource];
1523
-
1524
- // const indexRows = newData.findIndex((it) => it[rowKey as any] === record[rowKey])
1525
-
1526
- // Lấy vị trí bắt đầu
1527
- // const { row: startRow, col: startCol } = selectedCell;
1528
- const startRow = newData.findIndex(it => it[rowKey] === record[rowKey]);
1529
- const startCol = indexCol;
1530
-
1531
- // const flattData = flattenArray(newData);
1532
-
1533
- const pastedRows = [];
1534
- const pastedColumns = new Set();
1535
- rows.forEach((rowValues, rowIndex) => {
1536
- const targetRow = startRow + rowIndex;
1537
-
1538
- // Nếu vượt quá số dòng hiện có, thêm dòng mới
1539
- if (targetRow >= newData.length) {
1540
- // @ts-ignore
1541
- // newData.push({ id: newGuid()});
1542
- newData.push({
1543
- id: undefined,
1544
- rowId: (0, _hooks.newGuid)()
1545
- });
1546
- }
1547
- rowValues.forEach((cellValue, colIndex) => {
1548
- const targetCol = startCol + colIndex;
1549
- if (targetCol >= visibleCols.length) {
1550
- // Không vượt quá số cột
1551
- return;
1552
- }
1553
- if (visibleCols[targetCol].editEnable) {
1554
- // @ts-ignore
1555
- const columnKey = visibleCols[targetCol].field;
1556
-
1557
- // @ts-ignore
1558
- newData[targetRow] = {
1559
- ...newData[targetRow],
1560
- [columnKey]: cellValue.trim()
1561
- };
1562
- pastedColumns.add(columnKey);
1563
- }
1564
- });
1565
-
1566
- // Lưu dòng được paste
1567
- pastedRows.push(newData[targetRow]);
1568
- });
1569
- const pastedColumnsArray = Array.from(pastedColumns) ?? [];
1570
- triggerPaste?.(pastedRows, pastedColumnsArray, newData);
1571
- } else {
1572
- // Cập nhật data mới
1573
- const newData = [...dataSource];
1574
- const parent = (0, _hooks.findItemByKey)(newData, rowKey, record.parentId);
1575
-
1576
- // Cập nhật childData mới
1577
- const childData = parent?.children ? [...parent.children] : [];
1578
-
1579
- // Lấy vị trí bắt đầu
1580
- // const { row: startRow, col: startCol } = selectedCell;
1581
- const startRow = childData.findIndex(it => it[rowKey] === record[rowKey]);
1582
- const startCol = indexCol;
1583
- const pastedRows = [];
1584
- const pastedColumns = new Set();
1585
- rows.forEach((rowValues, rowIndex) => {
1586
- const targetRow = startRow + rowIndex;
1587
-
1588
- // Nếu vượt quá số dòng hiện có, thêm dòng mới
1589
- if (targetRow >= childData.length) {
1590
- childData.push({
1591
- id: undefined,
1592
- rowId: (0, _hooks.newGuid)(),
1593
- parentId: parent[rowKey ?? 'id']
1594
- });
1595
- }
1596
- rowValues.forEach((cellValue, colIndex) => {
1597
- const targetCol = startCol + colIndex;
1598
- if (targetCol >= visibleCols.length) {
1599
- // Không vượt quá số cột
1600
- return;
1601
- }
1602
- if (visibleCols[targetCol].editEnable) {
1603
- // @ts-ignore
1604
- const columnKey = visibleCols[targetCol].field;
1605
-
1606
- // @ts-ignore
1607
- childData[targetRow] = {
1608
- ...childData[targetRow],
1609
- [columnKey]: cellValue.trim()
1610
- };
1611
- pastedColumns.add(columnKey);
1612
- }
1613
- });
1614
-
1615
- // Lưu dòng được paste
1616
- pastedRows.push(childData[targetRow]);
1617
- });
1618
- const pastedColumnsArray = Array.from(pastedColumns) ?? [];
1619
- const newRowData = {
1620
- ...parent,
1621
- children: childData
1622
- };
1623
- const newDataSource = (0, _hooks.updateArrayByKey)(newData, newRowData, rowKey);
1624
- triggerPaste?.(pastedRows, pastedColumnsArray, newDataSource);
1625
- }
1626
- };
1627
- const handlePaste = (record, indexCol, rowNumber, e) => {
1628
- // const clipboard: any = (e.clipboardData || (window && window?.Clipboard)).getData("text")
1629
- const pasteData = e.clipboardData.getData("text/plain");
1630
-
1631
- // Chuyển đổi dữ liệu từ clipboard thành mảng
1632
- const rowsPasted = pasteData.split("\n").map(row =>
1633
- // const rows = pasteData.split("\n").map((row: any) =>
1634
- row.replace(/\r/g, "").split("\t"));
1635
- if (rowsPasted.length > (onCellPaste?.maxRowsPaste ?? 200)) {
1636
- // bật popup thông báo
1637
-
1638
- _antd.Modal.confirm({
1639
- content: /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(Paragraph, {
1640
- style: {
1641
- marginBottom: '.25rem',
1642
- fontSize: 14
1643
- }
1644
- }, "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, {
1645
- level: 5,
1646
- style: {
1647
- marginTop: '.75rem'
1648
- }
1649
- }, "B\u1EA1n c\xF3 mu\u1ED1n ti\u1EBFp t\u1EE5c sao ch\xE9p kh\xF4ng?")),
1650
- centered: true,
1651
- className: 'be-popup-container',
1652
- onOk: () => {
1653
- handlePasted(record, indexCol, rowNumber, rowsPasted);
1654
- }
1655
- // footer: (_, { OkBtn, CancelBtn }) => (
1656
- // <>
1657
- // <OkBtn />
1658
- // <CancelBtn />
1659
- // </>
1660
- // ),
1661
- });
1662
- } else {
1663
- handlePasted(record, indexCol, rowNumber, rowsPasted);
1664
- }
1665
-
1666
- // const rows = rowsPasted.slice(0, (onCellPaste?.maxRowsPaste ?? 200));
1667
- //
1668
- //
1669
- // if (!record?.parentId ) {
1670
- //
1671
- // // Cập nhật data mới
1672
- // const newData = [...dataSource];
1673
- //
1674
- // // @ts-ignore
1675
- // const indexRows = newData.findIndex((it) => it[rowKey] === record[rowKey])
1676
- //
1677
- // // Lấy vị trí bắt đầu
1678
- // // const { row: startRow, col: startCol } = selectedCell;
1679
- // const startRow = indexRows
1680
- // const startCol = indexCol
1681
- //
1682
- //
1683
- //
1684
- // // const flattData = flattenArray(newData);
1685
- //
1686
- // const pastedRows: RecordType[] = [];
1687
- // const pastedColumns = new Set()
1688
- //
1689
- //
1690
- // rows.forEach((rowValues: any, rowIndex: any) => {
1691
- // const targetRow = startRow + rowIndex;
1692
- //
1693
- // // Nếu vượt quá số dòng hiện có, thêm dòng mới
1694
- // if (targetRow >= newData.length) {
1695
- // // @ts-ignore
1696
- // // newData.push({ id: newGuid()});
1697
- // newData.push({ id: undefined, rowId: newGuid()});
1698
- // }
1699
- //
1700
- // rowValues.forEach((cellValue: any, colIndex: any) => {
1701
- // const targetCol = startCol + colIndex;
1702
- // if (targetCol >= columns.length) { // Không vượt quá số cột
1703
- // return
1704
- // }
1705
- //
1706
- // if (columns[targetCol].editEnable) {
1707
- // // @ts-ignore
1708
- // const columnKey = columns[targetCol].field;
1709
- //
1710
- // // @ts-ignore
1711
- // newData[targetRow] = { ...newData[targetRow], [columnKey]: cellValue.trim() };
1712
- // pastedColumns.add(columnKey);
1713
- // }
1714
- //
1715
- // });
1716
- //
1717
- // // Lưu dòng được paste
1718
- // pastedRows.push(newData[targetRow]);
1719
- //
1720
- // });
1721
- //
1722
- // const pastedColumnsArray = Array.from(pastedColumns) ?? [];
1723
- //
1724
- // triggerPaste?.(pastedRows, pastedColumnsArray as string[], newData)
1725
- //
1726
- //
1727
- // } else {
1728
- //
1729
- // // Cập nhật data mới
1730
- // const newData = [...dataSource];
1731
- //
1732
- // const parent = findItemByKey(newData, rowKey as any, record.parentId)
1733
- //
1734
- // // Cập nhật childData mới
1735
- // const childData: any[] = parent?.children ? [...parent.children] : []
1736
- //
1737
- //
1738
- // // Lấy vị trí bắt đầu
1739
- // // const { row: startRow, col: startCol } = selectedCell;
1740
- // const startRow = childData.findIndex((it) => it[rowKey] === record[rowKey])
1741
- // const startCol = indexCol
1742
- //
1743
- // const pastedRows: RecordType[] = []
1744
- // const pastedColumns = new Set()
1745
- //
1746
- //
1747
- // rows.forEach((rowValues: any, rowIndex: any) => {
1748
- // const targetRow = startRow + rowIndex
1749
- //
1750
- // // Nếu vượt quá số dòng hiện có, thêm dòng mới
1751
- // if (targetRow >= childData.length) {
1752
- //
1753
- // childData.push({ id: undefined, rowId: newGuid(), parentId: parent[rowKey ?? 'id']})
1754
- // }
1755
- //
1756
- // rowValues.forEach((cellValue: any, colIndex: any) => {
1757
- // const targetCol = startCol + colIndex
1758
- // if (targetCol >= columns.length) { // Không vượt quá số cột
1759
- // return
1760
- // }
1761
- //
1762
- // if (columns[targetCol].editEnable) {
1763
- //
1764
- // // @ts-ignore
1765
- // const columnKey = columns[targetCol].field
1766
- //
1767
- // // @ts-ignore
1768
- // childData[targetRow] = { ...childData[targetRow], [columnKey]: cellValue.trim() }
1769
- // pastedColumns.add(columnKey)
1770
- // }
1771
- //
1772
- // })
1773
- //
1774
- // // Lưu dòng được paste
1775
- // pastedRows.push(childData[targetRow])
1776
- //
1777
- // })
1778
- //
1779
- // const pastedColumnsArray = Array.from(pastedColumns) ?? []
1780
- //
1781
- // const newRowData = {...parent, children: childData}
1782
- //
1783
- // const newDataSource = updateArrayByKey(newData, newRowData, rowKey as string)
1784
- //
1785
- // triggerPaste?.(pastedRows, pastedColumnsArray as string[], newDataSource )
1786
- // }
1787
- };
1788
1792
  const onSubmit = formData => {
1789
1793
  try {
1790
1794
  // const record = (await form.validateFields()) as RecordType;