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