es-grid-template 1.2.9 → 1.3.1

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.
@@ -34,6 +34,7 @@ _dayjs.default.extend(_customParseFormat.default);
34
34
  const toast = 'top-right';
35
35
  const GridEdit = props => {
36
36
  const {
37
+ id,
37
38
  tableRef,
38
39
  t,
39
40
  columns,
@@ -68,6 +69,7 @@ const GridEdit = props => {
68
69
  // selectedRowKeys,
69
70
  // defaultSelectedRowKeys
70
71
  } = selectionSettings || {};
72
+ const ref = (0, _react.useRef)(null);
71
73
  const isSelecting = (0, _react.useRef)(false);
72
74
  const startCell = (0, _react.useRef)(null);
73
75
  const childrenColumnName = 'children';
@@ -502,35 +504,53 @@ const GridEdit = props => {
502
504
  (0, _react.useEffect)(() => {
503
505
  const handleClickOutside = event => {
504
506
  const element = event.target;
505
- const tableBodies = document.getElementsByClassName("ui-rc-table-tbody");
507
+
508
+ // const tableId = id ? document.getElementById(id) : undefined
509
+ // const tableBodies = document.getElementsByClassName("ui-rc-table-tbody");
506
510
  const container = document.querySelector(".be-popup-container");
511
+ const tableBody = document.querySelector(`#${id} .ui-rc-table-tbody`);
507
512
  // const containerHidden = document.querySelector(".be-popup-container.ant-picker-dropdown-hidden")
508
513
 
509
514
  // const toolbarContainer = document.getElementsByClassName("ui-rc-toolbar");
510
- const itemContainer = document.querySelector(".ui-rc-toolbar-selection-overflow-item");
515
+ const itemContainer = document.querySelector(`#${id} .ui-rc-toolbar-selection-overflow-item`);
511
516
  const isInsideContainer = element.closest(".be-popup-container") && container;
512
- const isInsideToolbar = element.closest(".ui-rc-toolbar-selection-overflow-item") && itemContainer;
517
+ const isInsideToolbar = element.closest(`#${id} .ui-rc-toolbar-selection-overflow-item`) && itemContainer;
513
518
  if (isInsideContainer || isInsideToolbar) {
519
+ // console.log('ooooooooooooo')
514
520
  return;
515
521
  }
516
- if (tableBodies.length > 0) {
517
- const tableBody = tableBodies[0]; // Chọn tbody đầu tiên (nếu có nhiều)
518
-
519
- if (!tableBody.contains(event.target)) {
520
- setEditingKey('');
521
- isSelecting.current = false;
522
- startCell.current = null;
523
- setSelectedCells(new Set());
524
- setRowsSelected(new Set());
525
- } else {}
522
+
523
+ // if (ref.current && !ref.current.contains(event.target)) {
524
+ // if (ref.current && tableId && !tableId.contains(event.target as Node)) {
525
+ if (ref.current && tableBody && !tableBody.contains(event.target)) {
526
+ setEditingKey('');
527
+ isSelecting.current = false;
528
+ startCell.current = null;
529
+ setSelectedCells(new Set());
530
+ setRowsSelected(new Set());
526
531
  }
532
+
533
+ // if (tableBodies.length > 0) {
534
+ // const tableBody = tableBodies[0]; // Chọn tbody đầu tiên (nếu có nhiều)
535
+ //
536
+ // if (!tableBody.contains(event.target as Node)) {
537
+ // setEditingKey('')
538
+ // isSelecting.current = false;
539
+ // startCell.current = null;
540
+ // setSelectedCells(new Set())
541
+ // setRowsSelected(new Set())
542
+ // } else {
543
+ //
544
+ // }
545
+ // }
527
546
  };
528
547
  document.addEventListener("click", handleClickOutside);
529
548
  return () => {
530
549
  document.removeEventListener("click", handleClickOutside);
531
550
  };
532
551
  }, []);
533
- const handleMouseDown = (record, row, col, e) => {
552
+ const handleMouseDown = (0, _react.useCallback)((record, row, col, e) => {
553
+ setEditingKey('');
534
554
  if (e.button === 2) {
535
555
  e.stopPropagation();
536
556
  return;
@@ -567,7 +587,7 @@ const GridEdit = props => {
567
587
  // setSelectedCells(new Set([`${row}-${col}`]));
568
588
  // setRowsSelected(new Set())
569
589
  // }
570
- };
590
+ }, []);
571
591
 
572
592
  // const handlePointEnter = (e: any) => {
573
593
  //
@@ -861,7 +881,7 @@ const GridEdit = props => {
861
881
  const selectedArray = Array.from(selectedCells).map(key => {
862
882
  const [row, col] = key.split("-").map(Number);
863
883
  // @ts-ignore
864
- const columnKey = columns[col].field;
884
+ const columnKey = (0, _hooks.editAbleColumns)(columns)[col - 1].field;
865
885
 
866
886
  // @ts-ignore
867
887
  return {
@@ -940,16 +960,17 @@ const GridEdit = props => {
940
960
  // Không vượt quá số cột
941
961
  return;
942
962
  }
943
-
944
- // @ts-ignore
945
- const columnKey = columns[targetCol].field;
946
-
947
- // @ts-ignore
948
- newData[targetRow] = {
949
- ...newData[targetRow],
950
- [columnKey]: cellValue.trim()
951
- };
952
- pastedColumns.add(columnKey);
963
+ if (columns[targetCol].editEnable) {
964
+ // @ts-ignore
965
+ const columnKey = columns[targetCol].field;
966
+
967
+ // @ts-ignore
968
+ newData[targetRow] = {
969
+ ...newData[targetRow],
970
+ [columnKey]: cellValue.trim()
971
+ };
972
+ pastedColumns.add(columnKey);
973
+ }
953
974
  });
954
975
 
955
976
  // Lưu dòng được paste
@@ -988,16 +1009,17 @@ const GridEdit = props => {
988
1009
  // Không vượt quá số cột
989
1010
  return;
990
1011
  }
991
-
992
- // @ts-ignore
993
- const columnKey = columns[targetCol].field;
994
-
995
- // @ts-ignore
996
- childData[targetRow] = {
997
- ...childData[targetRow],
998
- [columnKey]: cellValue.trim()
999
- };
1000
- pastedColumns.add(columnKey);
1012
+ if (columns[targetCol].editEnable) {
1013
+ // @ts-ignore
1014
+ const columnKey = columns[targetCol].field;
1015
+
1016
+ // @ts-ignore
1017
+ childData[targetRow] = {
1018
+ ...childData[targetRow],
1019
+ [columnKey]: cellValue.trim()
1020
+ };
1021
+ pastedColumns.add(columnKey);
1022
+ }
1001
1023
  });
1002
1024
 
1003
1025
  // Lưu dòng được paste
@@ -1296,7 +1318,7 @@ const GridEdit = props => {
1296
1318
  tabIndex: (rowIndex ?? 0) * columns.length + colIndex
1297
1319
  };
1298
1320
  },
1299
- render: (value, record, rowIndex) => {
1321
+ render: (value, record) => {
1300
1322
  const rowNumber = (0, _hooks.getRowNumber)(dataSource, record[rowKey], rowKey);
1301
1323
  return /*#__PURE__*/_react.default.createElement("div", {
1302
1324
  className: (0, _classnames.default)('ui-rc_cell-content ui-rc_cell-content--index', {
@@ -1305,10 +1327,11 @@ const GridEdit = props => {
1305
1327
  }),
1306
1328
  onMouseDown: event => handleMouseDownColIndex(rowNumber, colIndex, event),
1307
1329
  onMouseEnter: event => handleMouseEnterColIndex(rowNumber, colIndex, event),
1308
- onClick: () => handleClickRowHeader(rowNumber, colIndex)
1330
+ onClick: () => handleClickRowHeader(rowNumber, colIndex),
1331
+ onMouseUp: handleMouseUp
1309
1332
  }, /*#__PURE__*/_react.default.createElement("div", {
1310
1333
  className: 'ui-rc_content'
1311
- }, rowIndex + 1));
1334
+ }, (0, _hooks.findItemPath)(dataSource, record, rowKey)));
1312
1335
  }
1313
1336
  };
1314
1337
  }
@@ -1322,6 +1345,10 @@ const GridEdit = props => {
1322
1345
  onCell: (record, rowIndex) => {
1323
1346
  const rowNumber = (0, _hooks.getRowNumber)(dataSource, record[rowKey], rowKey);
1324
1347
  return {
1348
+ // onKeyPress: () => {
1349
+ //
1350
+ // },
1351
+
1325
1352
  onKeyDown: event => {
1326
1353
  const key = getRowKey(record, dataSource.indexOf(record));
1327
1354
  if (event.key.length === 1 && !event.ctrlKey && !event.metaKey || event.key === 'Enter') {
@@ -1435,14 +1462,15 @@ const GridEdit = props => {
1435
1462
  return /*#__PURE__*/_react.default.createElement("div", {
1436
1463
  className: (0, _classnames.default)('ui-rc_cell-content', {
1437
1464
  // selected: selectedCells.has(`${record[rowKey]}-${colIndex}`)
1438
- selected: selectedCells.has(`${rowNumber}-${colIndex}`)
1465
+ selected: selectedCells.has(`${rowNumber}-${colIndex}`),
1466
+ disable: !(0, _hooks.isEditable)(column, record)
1439
1467
  }),
1440
1468
  onMouseDown: event => handleMouseDown(record, rowNumber, colIndex, event),
1441
1469
  onMouseEnter: () => handleMouseEnter(rowNumber, colIndex),
1442
1470
  onMouseUp: handleMouseUp
1443
1471
  }, /*#__PURE__*/_react.default.createElement("div", {
1444
1472
  className: 'ui-rc_content'
1445
- }, (0, _columns.renderContent)(column, value, record, rowIndex, format)), selectedCells && selectedCells.size > 0 && (0, _hooks.getLastSelectCell)(selectedCells).row === rowNumber && (0, _hooks.getLastSelectCell)(selectedCells).col === colIndex && (0, _hooks.isEditable)(column, record) !== false && !isSelectDragging &&
1473
+ }, (0, _columns.renderContent)(column, value, record, rowIndex, format)), selectedCells && selectedCells.size > 0 && (0, _hooks.getLastSelectCell)(selectedCells).row === rowNumber && (0, _hooks.getLastSelectCell)(selectedCells).col === colIndex && (0, _hooks.isEditable)(column, record) && !isSelectDragging &&
1446
1474
  /*#__PURE__*/
1447
1475
  // showDraggingPoint &&
1448
1476
  _react.default.createElement("div", {
@@ -1508,7 +1536,8 @@ const GridEdit = props => {
1508
1536
  style: {
1509
1537
  position: 'relative'
1510
1538
  },
1511
- onMouseUp: handleMouseUp
1539
+ ref: ref
1540
+ // onMouseUp={handleMouseUp}
1512
1541
  }, /*#__PURE__*/_react.default.createElement(_useContext.TableContext.Provider, {
1513
1542
  value: {
1514
1543
  rowKey,
@@ -1529,7 +1558,7 @@ const GridEdit = props => {
1529
1558
  rowHoverBg: '#eb461912',
1530
1559
  rowSelectedBg: '#eb4619',
1531
1560
  rowSelectedHoverBg: '#eb4619',
1532
- cellFontSize: 12,
1561
+ // cellFontSize: 12,
1533
1562
  cellFontSizeSM: 13,
1534
1563
  headerBg: '#ffffff',
1535
1564
  cellPaddingBlockSM: 7
@@ -1542,11 +1571,13 @@ const GridEdit = props => {
1542
1571
  }
1543
1572
  }, /*#__PURE__*/_react.default.createElement(_TableGrid.default, (0, _extends2.default)({}, rest, {
1544
1573
  t: t,
1574
+ id: id,
1545
1575
  tableRef: tableRef,
1546
1576
  dataSource: dataSource,
1547
1577
  components: {
1548
1578
  ...components,
1549
1579
  body: {
1580
+ // wrapper: () => <div></div>,
1550
1581
  cell: _EditableCell.default
1551
1582
  // cell: () => <EditableCell />,
1552
1583
  }
@@ -1559,11 +1590,15 @@ const GridEdit = props => {
1559
1590
  target: 'sorter-icon'
1560
1591
  },
1561
1592
  format: format,
1562
- toolbarItems: toolbarItems,
1593
+ toolbarItems: toolbarItems
1594
+ // selectionSettings={selectionSettings ? {...selectionSettings, checkboxOnly: true} : undefined}
1595
+ ,
1563
1596
  selectionSettings: selectionSettings ? {
1564
1597
  ...selectionSettings,
1565
1598
  checkboxOnly: true
1566
- } : undefined,
1599
+ } : {
1600
+ checkboxOnly: true
1601
+ },
1567
1602
  rowHoverable: false,
1568
1603
  bottomToolbar: bottomToolbar,
1569
1604
  expandable: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-grid-template",
3
- "version": "1.2.9",
3
+ "version": "1.3.1",
4
4
  "description": "es-grid-template",
5
5
  "keywords": [
6
6
  "react",