material-react-table 0.34.1 → 0.35.2

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.
package/dist/cjs/index.js CHANGED
@@ -7,6 +7,7 @@ var reactTable = require('@tanstack/react-table');
7
7
  var iconsMaterial = require('@mui/icons-material');
8
8
  var matchSorterUtils = require('@tanstack/match-sorter-utils');
9
9
  var material = require('@mui/material');
10
+ var reactVirtual = require('react-virtual');
10
11
 
11
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
12
13
 
@@ -567,7 +568,7 @@ const getDefaultColumnFilterFn = (columnDef) => {
567
568
  return 'fuzzy';
568
569
  };
569
570
 
570
- const MRT_ShowHideColumnsMenuItems = ({ allColumns, currentHoveredColumn, setCurrentHoveredColumn, column, isSubMenu, table, }) => {
571
+ const MRT_ShowHideColumnsMenuItems = ({ allColumns, hoveredColumn, setHoveredColumn, column, isSubMenu, table, }) => {
571
572
  var _a;
572
573
  const { getState, options: { enableColumnOrdering, enableHiding, enablePinning, localization, }, setColumnOrder, } = table;
573
574
  const { columnOrder } = getState();
@@ -595,14 +596,14 @@ const MRT_ShowHideColumnsMenuItems = ({ allColumns, currentHoveredColumn, setCur
595
596
  };
596
597
  const handleDragEnd = (_e) => {
597
598
  setIsDragging(false);
598
- setCurrentHoveredColumn(null);
599
- if (currentHoveredColumn) {
600
- setColumnOrder(reorderColumn(column, currentHoveredColumn, columnOrder));
599
+ setHoveredColumn(null);
600
+ if (hoveredColumn) {
601
+ setColumnOrder(reorderColumn(column, hoveredColumn, columnOrder));
601
602
  }
602
603
  };
603
604
  const handleDragEnter = (_e) => {
604
605
  if (!isDragging) {
605
- setCurrentHoveredColumn(column);
606
+ setHoveredColumn(column);
606
607
  }
607
608
  };
608
609
  return (React__default["default"].createElement(React__default["default"].Fragment, null,
@@ -613,7 +614,7 @@ const MRT_ShowHideColumnsMenuItems = ({ allColumns, currentHoveredColumn, setCur
613
614
  opacity: isDragging ? 0.5 : 1,
614
615
  outline: isDragging
615
616
  ? `1px dashed ${theme.palette.divider}`
616
- : (currentHoveredColumn === null || currentHoveredColumn === void 0 ? void 0 : currentHoveredColumn.id) === column.id
617
+ : (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === column.id
617
618
  ? `2px dashed ${theme.palette.primary.main}`
618
619
  : 'none',
619
620
  pl: `${(column.depth + 0.5) * 2}rem`,
@@ -643,7 +644,7 @@ const MRT_ShowHideColumnsMenuItems = ({ allColumns, currentHoveredColumn, setCur
643
644
  React__default["default"].createElement(material.Switch, null)), disabled: (isSubMenu && switchChecked) ||
644
645
  !column.getCanHide() ||
645
646
  column.getIsGrouped(), label: columnDef.header, onChange: () => handleToggleColumnHidden(column) })) : (React__default["default"].createElement(material.Typography, { sx: { alignSelf: 'center' } }, columnDef.header)))), (_a = column.columns) === null || _a === void 0 ? void 0 :
646
- _a.map((c, i) => (React__default["default"].createElement(MRT_ShowHideColumnsMenuItems, { allColumns: allColumns, column: c, currentHoveredColumn: currentHoveredColumn, isSubMenu: isSubMenu, key: `${i}-${c.id}`, setCurrentHoveredColumn: setCurrentHoveredColumn, table: table })))));
647
+ _a.map((c, i) => (React__default["default"].createElement(MRT_ShowHideColumnsMenuItems, { allColumns: allColumns, column: c, hoveredColumn: hoveredColumn, isSubMenu: isSubMenu, key: `${i}-${c.id}`, setHoveredColumn: setHoveredColumn, table: table })))));
647
648
  };
648
649
 
649
650
  const MRT_ShowHideColumnsMenu = ({ anchorEl, isSubMenu, setAnchorEl, table, }) => {
@@ -673,7 +674,7 @@ const MRT_ShowHideColumnsMenu = ({ anchorEl, isSubMenu, setAnchorEl, table, }) =
673
674
  getLeftLeafColumns(),
674
675
  getRightLeafColumns(),
675
676
  ]);
676
- const [currentHoveredColumn, setCurrentHoveredColumn] = React.useState(null);
677
+ const [hoveredColumn, setHoveredColumn] = React.useState(null);
677
678
  return (React__default["default"].createElement(material.Menu, { anchorEl: anchorEl, open: !!anchorEl, onClose: () => setAnchorEl(null), MenuListProps: {
678
679
  dense: density === 'compact',
679
680
  } },
@@ -688,7 +689,7 @@ const MRT_ShowHideColumnsMenu = ({ anchorEl, isSubMenu, setAnchorEl, table, }) =
688
689
  !isSubMenu && enablePinning && (React__default["default"].createElement(material.Button, { disabled: !getIsSomeColumnsPinned(), onClick: () => table.resetColumnPinning(true) }, localization.unpinAll)),
689
690
  React__default["default"].createElement(material.Button, { disabled: getIsAllColumnsVisible(), onClick: () => toggleAllColumnsVisible(true) }, localization.showAll)),
690
691
  React__default["default"].createElement(material.Divider, null),
691
- allColumns.map((column, index) => (React__default["default"].createElement(MRT_ShowHideColumnsMenuItems, { allColumns: allColumns, column: column, currentHoveredColumn: currentHoveredColumn, isSubMenu: isSubMenu, key: `${index}-${column.id}`, setCurrentHoveredColumn: setCurrentHoveredColumn, table: table })))));
692
+ allColumns.map((column, index) => (React__default["default"].createElement(MRT_ShowHideColumnsMenuItems, { allColumns: allColumns, column: column, hoveredColumn: hoveredColumn, isSubMenu: isSubMenu, key: `${index}-${column.id}`, setHoveredColumn: setHoveredColumn, table: table })))));
692
693
  };
693
694
 
694
695
  const commonMenuItemStyles = {
@@ -881,16 +882,20 @@ const MRT_RowActionMenu = ({ anchorEl, handleEdit, row, setAnchorEl, table, }) =
881
882
  };
882
883
 
883
884
  const MRT_EditActionButtons = ({ row, table }) => {
884
- const { getState, options: { icons: { CancelIcon, SaveIcon }, localization, onEditRowSubmit, }, setCurrentEditingRow, } = table;
885
- const { currentEditingRow } = getState();
885
+ const { getState, options: { icons: { CancelIcon, SaveIcon }, localization, onEditingRowSave, }, setEditingRow, } = table;
886
+ const { editingRow } = getState();
886
887
  const handleCancel = () => {
887
- var _a;
888
- row._valuesCache = (_a = row.original) !== null && _a !== void 0 ? _a : {};
889
- setCurrentEditingRow(null);
888
+ row._valuesCache = Object.assign({}, row.original);
889
+ setEditingRow(null);
890
890
  };
891
891
  const handleSave = () => {
892
- onEditRowSubmit === null || onEditRowSubmit === void 0 ? void 0 : onEditRowSubmit({ row: currentEditingRow !== null && currentEditingRow !== void 0 ? currentEditingRow : row, table });
893
- setCurrentEditingRow(null);
892
+ var _a;
893
+ onEditingRowSave === null || onEditingRowSave === void 0 ? void 0 : onEditingRowSave({
894
+ row: editingRow !== null && editingRow !== void 0 ? editingRow : row,
895
+ table,
896
+ values: (_a = editingRow === null || editingRow === void 0 ? void 0 : editingRow._valuesCache) !== null && _a !== void 0 ? _a : Object.assign({}, row.original),
897
+ });
898
+ setEditingRow(null);
894
899
  };
895
900
  return (React__default["default"].createElement(material.Box, { sx: { display: 'flex', gap: '0.75rem' } },
896
901
  React__default["default"].createElement(material.Tooltip, { arrow: true, title: localization.cancel },
@@ -912,8 +917,8 @@ const commonIconButtonStyles = {
912
917
  },
913
918
  };
914
919
  const MRT_ToggleRowActionMenuButton = ({ row, table }) => {
915
- const { getState, options: { enableEditing, icons: { EditIcon, MoreHorizIcon }, localization, renderRowActionMenuItems, renderRowActions, }, setCurrentEditingRow, } = table;
916
- const { currentEditingRow } = getState();
920
+ const { getState, options: { enableEditing, icons: { EditIcon, MoreHorizIcon }, localization, renderRowActionMenuItems, renderRowActions, }, setEditingRow, } = table;
921
+ const { editingRow } = getState();
917
922
  const [anchorEl, setAnchorEl] = React.useState(null);
918
923
  const handleOpenRowActionMenu = (event) => {
919
924
  event.stopPropagation();
@@ -921,10 +926,10 @@ const MRT_ToggleRowActionMenuButton = ({ row, table }) => {
921
926
  setAnchorEl(event.currentTarget);
922
927
  };
923
928
  const handleStartEditMode = () => {
924
- setCurrentEditingRow(Object.assign({}, row));
929
+ setEditingRow(Object.assign({}, row));
925
930
  setAnchorEl(null);
926
931
  };
927
- return (React__default["default"].createElement(React__default["default"].Fragment, null, renderRowActions ? (React__default["default"].createElement(React__default["default"].Fragment, null, renderRowActions({ row, table }))) : row.id === (currentEditingRow === null || currentEditingRow === void 0 ? void 0 : currentEditingRow.id) ? (React__default["default"].createElement(MRT_EditActionButtons, { row: row, table: table })) : !renderRowActionMenuItems && enableEditing ? (React__default["default"].createElement(material.Tooltip, { placement: "right", arrow: true, title: localization.edit },
932
+ return (React__default["default"].createElement(React__default["default"].Fragment, null, renderRowActions ? (React__default["default"].createElement(React__default["default"].Fragment, null, renderRowActions({ row, table }))) : row.id === (editingRow === null || editingRow === void 0 ? void 0 : editingRow.id) ? (React__default["default"].createElement(MRT_EditActionButtons, { row: row, table: table })) : !renderRowActionMenuItems && enableEditing ? (React__default["default"].createElement(material.Tooltip, { placement: "right", arrow: true, title: localization.edit },
928
933
  React__default["default"].createElement(material.IconButton, { sx: commonIconButtonStyles, onClick: handleStartEditMode },
929
934
  React__default["default"].createElement(EditIcon, null)))) : renderRowActionMenuItems ? (React__default["default"].createElement(React__default["default"].Fragment, null,
930
935
  React__default["default"].createElement(material.Tooltip, { arrow: true, enterDelay: 1000, enterNextDelay: 1000, title: localization.rowActions },
@@ -1154,15 +1159,15 @@ const MRT_ToolbarInternalButtons = ({ table }) => {
1154
1159
 
1155
1160
  const MRT_ToolbarDropZone = ({ table }) => {
1156
1161
  var _a, _b;
1157
- const { getState, options: { enableGrouping, localization }, setCurrentHoveredColumn, } = table;
1158
- const { currentDraggingColumn, currentHoveredColumn } = getState();
1162
+ const { getState, options: { enableGrouping, localization }, setHoveredColumn, } = table;
1163
+ const { draggingColumn, hoveredColumn } = getState();
1159
1164
  const handleDragEnter = (_event) => {
1160
- setCurrentHoveredColumn({ id: 'drop-zone' });
1165
+ setHoveredColumn({ id: 'drop-zone' });
1161
1166
  };
1162
- return (React__default["default"].createElement(material.Fade, { unmountOnExit: true, mountOnEnter: true, in: !!enableGrouping && !!currentDraggingColumn },
1167
+ return (React__default["default"].createElement(material.Fade, { unmountOnExit: true, mountOnEnter: true, in: !!enableGrouping && !!draggingColumn },
1163
1168
  React__default["default"].createElement(material.Box, { sx: (theme) => ({
1164
1169
  alignItems: 'center',
1165
- backgroundColor: material.alpha(theme.palette.info.main, (currentHoveredColumn === null || currentHoveredColumn === void 0 ? void 0 : currentHoveredColumn.id) === 'drop-zone' ? 0.2 : 0.1),
1170
+ backgroundColor: material.alpha(theme.palette.info.main, (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === 'drop-zone' ? 0.2 : 0.1),
1166
1171
  border: `dashed ${theme.palette.info.main} 2px`,
1167
1172
  display: 'flex',
1168
1173
  justifyContent: 'center',
@@ -1171,7 +1176,7 @@ const MRT_ToolbarDropZone = ({ table }) => {
1171
1176
  width: 'calc(100% - 4px)',
1172
1177
  zIndex: 2,
1173
1178
  }), onDragEnter: handleDragEnter },
1174
- React__default["default"].createElement(material.Typography, null, localization.dropToGroupBy.replace('{column}', (_b = (_a = currentDraggingColumn === null || currentDraggingColumn === void 0 ? void 0 : currentDraggingColumn.columnDef) === null || _a === void 0 ? void 0 : _a.header) !== null && _b !== void 0 ? _b : '')))));
1179
+ React__default["default"].createElement(material.Typography, null, localization.dropToGroupBy.replace('{column}', (_b = (_a = draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.columnDef) === null || _a === void 0 ? void 0 : _a.header) !== null && _b !== void 0 ? _b : '')))));
1175
1180
  };
1176
1181
 
1177
1182
  const commonToolbarStyles = ({ theme }) => ({
@@ -1501,9 +1506,9 @@ const MRT_TableHeadCellFilterLabel = ({ header, table }) => {
1501
1506
  };
1502
1507
 
1503
1508
  const MRT_TableHeadCellGrabHandle = ({ column, table, tableHeadCellRef, }) => {
1504
- const { getState, options: { enableColumnOrdering, muiTableHeadCellDragHandleProps, onColumnDrop, }, setColumnOrder, setCurrentDraggingColumn, setCurrentHoveredColumn, } = table;
1509
+ const { getState, options: { enableColumnOrdering, muiTableHeadCellDragHandleProps, onColumnDrop, }, setColumnOrder, setDraggingColumn, setHoveredColumn, } = table;
1505
1510
  const { columnDef } = column;
1506
- const { currentHoveredColumn, currentDraggingColumn, columnOrder } = getState();
1511
+ const { hoveredColumn, draggingColumn, columnOrder } = getState();
1507
1512
  const mIconButtonProps = muiTableHeadCellDragHandleProps instanceof Function
1508
1513
  ? muiTableHeadCellDragHandleProps({ column, table })
1509
1514
  : muiTableHeadCellDragHandleProps;
@@ -1512,25 +1517,25 @@ const MRT_TableHeadCellGrabHandle = ({ column, table, tableHeadCellRef, }) => {
1512
1517
  : columnDef.muiTableHeadCellDragHandleProps;
1513
1518
  const iconButtonProps = Object.assign(Object.assign({}, mIconButtonProps), mcIconButtonProps);
1514
1519
  const handleDragStart = (e) => {
1515
- setCurrentDraggingColumn(column);
1520
+ setDraggingColumn(column);
1516
1521
  e.dataTransfer.setDragImage(tableHeadCellRef.current, 0, 0);
1517
1522
  };
1518
1523
  const handleDragEnd = (event) => {
1519
1524
  onColumnDrop === null || onColumnDrop === void 0 ? void 0 : onColumnDrop({
1520
1525
  event,
1521
1526
  draggedColumn: column,
1522
- targetColumn: currentHoveredColumn,
1527
+ targetColumn: hoveredColumn,
1523
1528
  });
1524
- if ((currentHoveredColumn === null || currentHoveredColumn === void 0 ? void 0 : currentHoveredColumn.id) === 'drop-zone') {
1529
+ if ((hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === 'drop-zone') {
1525
1530
  column.toggleGrouping();
1526
1531
  }
1527
1532
  else if (enableColumnOrdering &&
1528
- currentHoveredColumn &&
1529
- (currentHoveredColumn === null || currentHoveredColumn === void 0 ? void 0 : currentHoveredColumn.id) !== (currentDraggingColumn === null || currentDraggingColumn === void 0 ? void 0 : currentDraggingColumn.id)) {
1530
- setColumnOrder(reorderColumn(column, currentHoveredColumn, columnOrder));
1533
+ hoveredColumn &&
1534
+ (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) !== (draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id)) {
1535
+ setColumnOrder(reorderColumn(column, hoveredColumn, columnOrder));
1531
1536
  }
1532
- setCurrentDraggingColumn(null);
1533
- setCurrentHoveredColumn(null);
1537
+ setDraggingColumn(null);
1538
+ setHoveredColumn(null);
1534
1539
  };
1535
1540
  return (React__default["default"].createElement(MRT_GrabHandleButton, { iconButtonProps: iconButtonProps, onDragStart: handleDragStart, onDragEnd: handleDragEnd, table: table }));
1536
1541
  };
@@ -1588,8 +1593,8 @@ const MRT_TableHeadCellSortLabel = ({ header, table }) => {
1588
1593
  const MRT_TableHeadCell = ({ header, table }) => {
1589
1594
  var _a, _b, _c, _d;
1590
1595
  const theme = material.useTheme();
1591
- const { getState, options: { enableColumnActions, enableColumnDragging, enableColumnOrdering, enableColumnResizing, enableGrouping, enableMultiSort, muiTableHeadCellProps, }, setCurrentHoveredColumn, } = table;
1592
- const { density, currentDraggingColumn, currentHoveredColumn, showColumnFilters, } = getState();
1596
+ const { getState, options: { enableColumnActions, enableColumnDragging, enableColumnOrdering, enableColumnResizing, enableGrouping, enableMultiSort, muiTableHeadCellProps, }, setHoveredColumn, } = table;
1597
+ const { density, draggingColumn, hoveredColumn, showColumnFilters } = getState();
1593
1598
  const { column } = header;
1594
1599
  const { columnDef } = column;
1595
1600
  const { columnDefType } = columnDef;
@@ -1611,16 +1616,16 @@ const MRT_TableHeadCell = ({ header, table }) => {
1611
1616
  return ((table.getRightLeafHeaders().length - 1 - column.getPinnedIndex()) * 150);
1612
1617
  };
1613
1618
  const handleDragEnter = (_e) => {
1614
- if (enableGrouping && (currentHoveredColumn === null || currentHoveredColumn === void 0 ? void 0 : currentHoveredColumn.id) === 'drop-zone') {
1615
- setCurrentHoveredColumn(null);
1619
+ if (enableGrouping && (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === 'drop-zone') {
1620
+ setHoveredColumn(null);
1616
1621
  }
1617
- if (enableColumnOrdering && currentDraggingColumn) {
1618
- setCurrentHoveredColumn(columnDef.enableColumnOrdering !== false ? column : null);
1622
+ if (enableColumnOrdering && draggingColumn) {
1623
+ setHoveredColumn(columnDef.enableColumnOrdering !== false ? column : null);
1619
1624
  }
1620
1625
  };
1621
- const draggingBorder = (currentDraggingColumn === null || currentDraggingColumn === void 0 ? void 0 : currentDraggingColumn.id) === column.id
1626
+ const draggingBorder = (draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id) === column.id
1622
1627
  ? `1px dashed ${theme.palette.text.secondary}`
1623
- : (currentHoveredColumn === null || currentHoveredColumn === void 0 ? void 0 : currentHoveredColumn.id) === column.id
1628
+ : (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === column.id
1624
1629
  ? `2px dashed ${theme.palette.primary.main}`
1625
1630
  : undefined;
1626
1631
  const draggingBorders = draggingBorder
@@ -1648,8 +1653,7 @@ const MRT_TableHeadCell = ({ header, table }) => {
1648
1653
  ? `-4px 0 4px -2px ${material.alpha(theme.palette.common.black, 0.1)}`
1649
1654
  : undefined, fontWeight: 'bold', left: column.getIsPinned() === 'left'
1650
1655
  ? `${column.getStart('left')}px`
1651
- : undefined, overflow: 'visible', opacity: (currentDraggingColumn === null || currentDraggingColumn === void 0 ? void 0 : currentDraggingColumn.id) === column.id ||
1652
- (currentHoveredColumn === null || currentHoveredColumn === void 0 ? void 0 : currentHoveredColumn.id) === column.id
1656
+ : undefined, overflow: 'visible', opacity: (draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id) === column.id || (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === column.id
1653
1657
  ? 0.5
1654
1658
  : 1, p: density === 'compact'
1655
1659
  ? '0.5rem'
@@ -1671,7 +1675,7 @@ const MRT_TableHeadCell = ({ header, table }) => {
1671
1675
  ? '0.25'
1672
1676
  : density === 'comfortable'
1673
1677
  ? '.75rem'
1674
- : '1.25rem', right: column.getIsPinned() === 'right' ? `${getTotalRight()}px` : undefined, transition: `all ${enableColumnResizing ? 0 : '0.2s'} ease-in-out`, userSelect: enableMultiSort && column.getCanSort() ? 'none' : undefined, verticalAlign: 'top', zIndex: column.getIsResizing() || (currentDraggingColumn === null || currentDraggingColumn === void 0 ? void 0 : currentDraggingColumn.id) === column.id
1678
+ : '1.25rem', right: column.getIsPinned() === 'right' ? `${getTotalRight()}px` : undefined, transition: `all ${enableColumnResizing ? 0 : '0.2s'} ease-in-out`, userSelect: enableMultiSort && column.getCanSort() ? 'none' : undefined, verticalAlign: 'top', zIndex: column.getIsResizing() || (draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id) === column.id
1675
1679
  ? 3
1676
1680
  : column.getIsPinned() && columnDefType !== 'group'
1677
1681
  ? 2
@@ -1735,521 +1739,30 @@ const MRT_TableHead = ({ table }) => {
1735
1739
  return (React__default["default"].createElement(material.TableHead, Object.assign({}, tableHeadProps), getHeaderGroups().map((headerGroup) => (React__default["default"].createElement(MRT_TableHeadRow, { headerGroup: headerGroup, key: headerGroup.id, table: table })))));
1736
1740
  };
1737
1741
 
1738
- function _extends() {
1739
- _extends = Object.assign || function (target) {
1740
- for (var i = 1; i < arguments.length; i++) {
1741
- var source = arguments[i];
1742
-
1743
- for (var key in source) {
1744
- if (Object.prototype.hasOwnProperty.call(source, key)) {
1745
- target[key] = source[key];
1746
- }
1747
- }
1748
- }
1749
-
1750
- return target;
1751
- };
1752
-
1753
- return _extends.apply(this, arguments);
1754
- }
1755
-
1756
- function _objectWithoutPropertiesLoose(source, excluded) {
1757
- if (source == null) return {};
1758
- var target = {};
1759
- var sourceKeys = Object.keys(source);
1760
- var key, i;
1761
-
1762
- for (i = 0; i < sourceKeys.length; i++) {
1763
- key = sourceKeys[i];
1764
- if (excluded.indexOf(key) >= 0) continue;
1765
- target[key] = source[key];
1766
- }
1767
-
1768
- return target;
1769
- }
1770
-
1771
- var props = ['bottom', 'height', 'left', 'right', 'top', 'width'];
1772
-
1773
- var rectChanged = function rectChanged(a, b) {
1774
- if (a === void 0) {
1775
- a = {};
1776
- }
1777
-
1778
- if (b === void 0) {
1779
- b = {};
1780
- }
1781
-
1782
- return props.some(function (prop) {
1783
- return a[prop] !== b[prop];
1784
- });
1785
- };
1786
-
1787
- var observedNodes = /*#__PURE__*/new Map();
1788
- var rafId;
1789
-
1790
- var run = function run() {
1791
- var changedStates = [];
1792
- observedNodes.forEach(function (state, node) {
1793
- var newRect = node.getBoundingClientRect();
1794
-
1795
- if (rectChanged(newRect, state.rect)) {
1796
- state.rect = newRect;
1797
- changedStates.push(state);
1798
- }
1799
- });
1800
- changedStates.forEach(function (state) {
1801
- state.callbacks.forEach(function (cb) {
1802
- return cb(state.rect);
1803
- });
1804
- });
1805
- rafId = window.requestAnimationFrame(run);
1806
- };
1807
-
1808
- function observeRect(node, cb) {
1809
- return {
1810
- observe: function observe() {
1811
- var wasEmpty = observedNodes.size === 0;
1812
-
1813
- if (observedNodes.has(node)) {
1814
- observedNodes.get(node).callbacks.push(cb);
1815
- } else {
1816
- observedNodes.set(node, {
1817
- rect: undefined,
1818
- hasRectChanged: false,
1819
- callbacks: [cb]
1820
- });
1821
- }
1822
-
1823
- if (wasEmpty) run();
1824
- },
1825
- unobserve: function unobserve() {
1826
- var state = observedNodes.get(node);
1827
-
1828
- if (state) {
1829
- // Remove the callback
1830
- var index = state.callbacks.indexOf(cb);
1831
- if (index >= 0) state.callbacks.splice(index, 1); // Remove the node reference
1832
-
1833
- if (!state.callbacks.length) observedNodes["delete"](node); // Stop the loop
1834
-
1835
- if (!observedNodes.size) cancelAnimationFrame(rafId);
1836
- }
1837
- }
1838
- };
1839
- }
1840
-
1841
- var useIsomorphicLayoutEffect$1 = typeof window !== 'undefined' ? React__default["default"].useLayoutEffect : React__default["default"].useEffect;
1842
-
1843
- function useRect(nodeRef, initialRect) {
1844
- if (initialRect === void 0) {
1845
- initialRect = {
1846
- width: 0,
1847
- height: 0
1848
- };
1849
- }
1850
-
1851
- var _React$useState = React__default["default"].useState(nodeRef.current),
1852
- element = _React$useState[0],
1853
- setElement = _React$useState[1];
1854
-
1855
- var _React$useReducer = React__default["default"].useReducer(rectReducer, initialRect),
1856
- rect = _React$useReducer[0],
1857
- dispatch = _React$useReducer[1];
1858
-
1859
- var initialRectSet = React__default["default"].useRef(false);
1860
- useIsomorphicLayoutEffect$1(function () {
1861
- if (nodeRef.current !== element) {
1862
- setElement(nodeRef.current);
1863
- }
1864
- });
1865
- useIsomorphicLayoutEffect$1(function () {
1866
- if (element && !initialRectSet.current) {
1867
- initialRectSet.current = true;
1868
-
1869
- var _rect = element.getBoundingClientRect();
1870
-
1871
- dispatch({
1872
- rect: _rect
1873
- });
1874
- }
1875
- }, [element]);
1876
- React__default["default"].useEffect(function () {
1877
- if (!element) {
1878
- return;
1879
- }
1880
-
1881
- var observer = observeRect(element, function (rect) {
1882
- dispatch({
1883
- rect: rect
1884
- });
1885
- });
1886
- observer.observe();
1887
- return function () {
1888
- observer.unobserve();
1889
- };
1890
- }, [element]);
1891
- return rect;
1892
- }
1893
-
1894
- function rectReducer(state, action) {
1895
- var rect = action.rect;
1896
-
1897
- if (state.height !== rect.height || state.width !== rect.width) {
1898
- return rect;
1899
- }
1900
-
1901
- return state;
1902
- }
1903
-
1904
- var defaultEstimateSize = function defaultEstimateSize() {
1905
- return 50;
1906
- };
1907
-
1908
- var defaultKeyExtractor = function defaultKeyExtractor(index) {
1909
- return index;
1910
- };
1911
-
1912
- var defaultMeasureSize = function defaultMeasureSize(el, horizontal) {
1913
- var key = horizontal ? 'offsetWidth' : 'offsetHeight';
1914
- return el[key];
1915
- };
1916
-
1917
- var defaultRangeExtractor = function defaultRangeExtractor(range) {
1918
- var start = Math.max(range.start - range.overscan, 0);
1919
- var end = Math.min(range.end + range.overscan, range.size - 1);
1920
- var arr = [];
1921
-
1922
- for (var i = start; i <= end; i++) {
1923
- arr.push(i);
1924
- }
1925
-
1926
- return arr;
1927
- };
1928
- function useVirtual(_ref) {
1929
- var _measurements;
1930
-
1931
- var _ref$size = _ref.size,
1932
- size = _ref$size === void 0 ? 0 : _ref$size,
1933
- _ref$estimateSize = _ref.estimateSize,
1934
- estimateSize = _ref$estimateSize === void 0 ? defaultEstimateSize : _ref$estimateSize,
1935
- _ref$overscan = _ref.overscan,
1936
- overscan = _ref$overscan === void 0 ? 1 : _ref$overscan,
1937
- _ref$paddingStart = _ref.paddingStart,
1938
- paddingStart = _ref$paddingStart === void 0 ? 0 : _ref$paddingStart,
1939
- _ref$paddingEnd = _ref.paddingEnd,
1940
- paddingEnd = _ref$paddingEnd === void 0 ? 0 : _ref$paddingEnd,
1941
- parentRef = _ref.parentRef,
1942
- horizontal = _ref.horizontal,
1943
- scrollToFn = _ref.scrollToFn,
1944
- useObserver = _ref.useObserver,
1945
- initialRect = _ref.initialRect,
1946
- onScrollElement = _ref.onScrollElement,
1947
- scrollOffsetFn = _ref.scrollOffsetFn,
1948
- _ref$keyExtractor = _ref.keyExtractor,
1949
- keyExtractor = _ref$keyExtractor === void 0 ? defaultKeyExtractor : _ref$keyExtractor,
1950
- _ref$measureSize = _ref.measureSize,
1951
- measureSize = _ref$measureSize === void 0 ? defaultMeasureSize : _ref$measureSize,
1952
- _ref$rangeExtractor = _ref.rangeExtractor,
1953
- rangeExtractor = _ref$rangeExtractor === void 0 ? defaultRangeExtractor : _ref$rangeExtractor;
1954
- var sizeKey = horizontal ? 'width' : 'height';
1955
- var scrollKey = horizontal ? 'scrollLeft' : 'scrollTop';
1956
- var latestRef = React__default["default"].useRef({
1957
- scrollOffset: 0,
1958
- measurements: []
1959
- });
1960
-
1961
- var _React$useState = React__default["default"].useState(0),
1962
- scrollOffset = _React$useState[0],
1963
- setScrollOffset = _React$useState[1];
1964
-
1965
- latestRef.current.scrollOffset = scrollOffset;
1966
- var useMeasureParent = useObserver || useRect;
1967
-
1968
- var _useMeasureParent = useMeasureParent(parentRef, initialRect),
1969
- outerSize = _useMeasureParent[sizeKey];
1970
-
1971
- latestRef.current.outerSize = outerSize;
1972
- var defaultScrollToFn = React__default["default"].useCallback(function (offset) {
1973
- if (parentRef.current) {
1974
- parentRef.current[scrollKey] = offset;
1975
- }
1976
- }, [parentRef, scrollKey]);
1977
- var resolvedScrollToFn = scrollToFn || defaultScrollToFn;
1978
- scrollToFn = React__default["default"].useCallback(function (offset) {
1979
- resolvedScrollToFn(offset, defaultScrollToFn);
1980
- }, [defaultScrollToFn, resolvedScrollToFn]);
1981
-
1982
- var _React$useState2 = React__default["default"].useState({}),
1983
- measuredCache = _React$useState2[0],
1984
- setMeasuredCache = _React$useState2[1];
1985
-
1986
- var measure = React__default["default"].useCallback(function () {
1987
- return setMeasuredCache({});
1988
- }, []);
1989
- var pendingMeasuredCacheIndexesRef = React__default["default"].useRef([]);
1990
- var measurements = React__default["default"].useMemo(function () {
1991
- var min = pendingMeasuredCacheIndexesRef.current.length > 0 ? Math.min.apply(Math, pendingMeasuredCacheIndexesRef.current) : 0;
1992
- pendingMeasuredCacheIndexesRef.current = [];
1993
- var measurements = latestRef.current.measurements.slice(0, min);
1994
-
1995
- for (var i = min; i < size; i++) {
1996
- var key = keyExtractor(i);
1997
- var measuredSize = measuredCache[key];
1998
-
1999
- var _start = measurements[i - 1] ? measurements[i - 1].end : paddingStart;
2000
-
2001
- var _size = typeof measuredSize === 'number' ? measuredSize : estimateSize(i);
2002
-
2003
- var _end = _start + _size;
2004
-
2005
- measurements[i] = {
2006
- index: i,
2007
- start: _start,
2008
- size: _size,
2009
- end: _end,
2010
- key: key
2011
- };
2012
- }
2013
-
2014
- return measurements;
2015
- }, [estimateSize, measuredCache, paddingStart, size, keyExtractor]);
2016
- var totalSize = (((_measurements = measurements[size - 1]) == null ? void 0 : _measurements.end) || paddingStart) + paddingEnd;
2017
- latestRef.current.measurements = measurements;
2018
- latestRef.current.totalSize = totalSize;
2019
- var element = onScrollElement ? onScrollElement.current : parentRef.current;
2020
- var scrollOffsetFnRef = React__default["default"].useRef(scrollOffsetFn);
2021
- scrollOffsetFnRef.current = scrollOffsetFn;
2022
- useIsomorphicLayoutEffect$1(function () {
2023
- if (!element) {
2024
- setScrollOffset(0);
2025
- return;
2026
- }
2027
-
2028
- var onScroll = function onScroll(event) {
2029
- var offset = scrollOffsetFnRef.current ? scrollOffsetFnRef.current(event) : element[scrollKey];
2030
- setScrollOffset(offset);
2031
- };
2032
-
2033
- onScroll();
2034
- element.addEventListener('scroll', onScroll, {
2035
- capture: false,
2036
- passive: true
2037
- });
2038
- return function () {
2039
- element.removeEventListener('scroll', onScroll);
2040
- };
2041
- }, [element, scrollKey]);
2042
-
2043
- var _calculateRange = calculateRange(latestRef.current),
2044
- start = _calculateRange.start,
2045
- end = _calculateRange.end;
2046
-
2047
- var indexes = React__default["default"].useMemo(function () {
2048
- return rangeExtractor({
2049
- start: start,
2050
- end: end,
2051
- overscan: overscan,
2052
- size: measurements.length
2053
- });
2054
- }, [start, end, overscan, measurements.length, rangeExtractor]);
2055
- var measureSizeRef = React__default["default"].useRef(measureSize);
2056
- measureSizeRef.current = measureSize;
2057
- var virtualItems = React__default["default"].useMemo(function () {
2058
- var virtualItems = [];
2059
-
2060
- var _loop = function _loop(k, len) {
2061
- var i = indexes[k];
2062
- var measurement = measurements[i];
2063
-
2064
- var item = _extends(_extends({}, measurement), {}, {
2065
- measureRef: function measureRef(el) {
2066
- if (el) {
2067
- var measuredSize = measureSizeRef.current(el, horizontal);
2068
-
2069
- if (measuredSize !== item.size) {
2070
- var _scrollOffset = latestRef.current.scrollOffset;
2071
-
2072
- if (item.start < _scrollOffset) {
2073
- defaultScrollToFn(_scrollOffset + (measuredSize - item.size));
2074
- }
2075
-
2076
- pendingMeasuredCacheIndexesRef.current.push(i);
2077
- setMeasuredCache(function (old) {
2078
- var _extends2;
2079
-
2080
- return _extends(_extends({}, old), {}, (_extends2 = {}, _extends2[item.key] = measuredSize, _extends2));
2081
- });
2082
- }
2083
- }
2084
- }
2085
- });
2086
-
2087
- virtualItems.push(item);
2088
- };
2089
-
2090
- for (var k = 0, len = indexes.length; k < len; k++) {
2091
- _loop(k);
2092
- }
2093
-
2094
- return virtualItems;
2095
- }, [indexes, defaultScrollToFn, horizontal, measurements]);
2096
- var mountedRef = React__default["default"].useRef(false);
2097
- useIsomorphicLayoutEffect$1(function () {
2098
- if (mountedRef.current) {
2099
- setMeasuredCache({});
2100
- }
2101
-
2102
- mountedRef.current = true;
2103
- }, [estimateSize]);
2104
- var scrollToOffset = React__default["default"].useCallback(function (toOffset, _temp) {
2105
- var _ref2 = _temp === void 0 ? {} : _temp,
2106
- _ref2$align = _ref2.align,
2107
- align = _ref2$align === void 0 ? 'start' : _ref2$align;
2108
-
2109
- var _latestRef$current = latestRef.current,
2110
- scrollOffset = _latestRef$current.scrollOffset,
2111
- outerSize = _latestRef$current.outerSize;
2112
-
2113
- if (align === 'auto') {
2114
- if (toOffset <= scrollOffset) {
2115
- align = 'start';
2116
- } else if (toOffset >= scrollOffset + outerSize) {
2117
- align = 'end';
2118
- } else {
2119
- align = 'start';
2120
- }
2121
- }
2122
-
2123
- if (align === 'start') {
2124
- scrollToFn(toOffset);
2125
- } else if (align === 'end') {
2126
- scrollToFn(toOffset - outerSize);
2127
- } else if (align === 'center') {
2128
- scrollToFn(toOffset - outerSize / 2);
2129
- }
2130
- }, [scrollToFn]);
2131
- var tryScrollToIndex = React__default["default"].useCallback(function (index, _temp2) {
2132
- var _ref3 = _temp2 === void 0 ? {} : _temp2,
2133
- _ref3$align = _ref3.align,
2134
- align = _ref3$align === void 0 ? 'auto' : _ref3$align,
2135
- rest = _objectWithoutPropertiesLoose(_ref3, ["align"]);
2136
-
2137
- var _latestRef$current2 = latestRef.current,
2138
- measurements = _latestRef$current2.measurements,
2139
- scrollOffset = _latestRef$current2.scrollOffset,
2140
- outerSize = _latestRef$current2.outerSize;
2141
- var measurement = measurements[Math.max(0, Math.min(index, size - 1))];
2142
-
2143
- if (!measurement) {
2144
- return;
2145
- }
2146
-
2147
- if (align === 'auto') {
2148
- if (measurement.end >= scrollOffset + outerSize) {
2149
- align = 'end';
2150
- } else if (measurement.start <= scrollOffset) {
2151
- align = 'start';
2152
- } else {
2153
- return;
2154
- }
2155
- }
2156
-
2157
- var toOffset = align === 'center' ? measurement.start + measurement.size / 2 : align === 'end' ? measurement.end : measurement.start;
2158
- scrollToOffset(toOffset, _extends({
2159
- align: align
2160
- }, rest));
2161
- }, [scrollToOffset, size]);
2162
- var scrollToIndex = React__default["default"].useCallback(function () {
2163
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2164
- args[_key] = arguments[_key];
2165
- }
2166
-
2167
- // We do a double request here because of
2168
- // dynamic sizes which can cause offset shift
2169
- // and end up in the wrong spot. Unfortunately,
2170
- // we can't know about those dynamic sizes until
2171
- // we try and render them. So double down!
2172
- tryScrollToIndex.apply(void 0, args);
2173
- requestAnimationFrame(function () {
2174
- tryScrollToIndex.apply(void 0, args);
2175
- });
2176
- }, [tryScrollToIndex]);
2177
- return {
2178
- virtualItems: virtualItems,
2179
- totalSize: totalSize,
2180
- scrollToOffset: scrollToOffset,
2181
- scrollToIndex: scrollToIndex,
2182
- measure: measure
2183
- };
2184
- }
2185
-
2186
- var findNearestBinarySearch = function findNearestBinarySearch(low, high, getCurrentValue, value) {
2187
- while (low <= high) {
2188
- var middle = (low + high) / 2 | 0;
2189
- var currentValue = getCurrentValue(middle);
2190
-
2191
- if (currentValue < value) {
2192
- low = middle + 1;
2193
- } else if (currentValue > value) {
2194
- high = middle - 1;
2195
- } else {
2196
- return middle;
2197
- }
2198
- }
2199
-
2200
- if (low > 0) {
2201
- return low - 1;
2202
- } else {
2203
- return 0;
2204
- }
2205
- };
2206
-
2207
- function calculateRange(_ref4) {
2208
- var measurements = _ref4.measurements,
2209
- outerSize = _ref4.outerSize,
2210
- scrollOffset = _ref4.scrollOffset;
2211
- var size = measurements.length - 1;
2212
-
2213
- var getOffset = function getOffset(index) {
2214
- return measurements[index].start;
2215
- };
2216
-
2217
- var start = findNearestBinarySearch(0, size, getOffset, scrollOffset);
2218
- var end = start;
2219
-
2220
- while (end < size && measurements[end].end < scrollOffset + outerSize) {
2221
- end++;
2222
- }
2223
-
2224
- return {
2225
- start: start,
2226
- end: end
2227
- };
2228
- }
2229
-
2230
1742
  const MRT_EditCellTextField = ({ cell, table }) => {
2231
1743
  var _a;
2232
- const { getState, options: { tableId, enableEditing, muiTableBodyCellEditTextFieldProps, onCellEditBlur, onCellEditChange, }, setCurrentEditingCell, setCurrentEditingRow, } = table;
1744
+ const { getState, options: { tableId, muiTableBodyCellEditTextFieldProps, onCellEditBlur, onCellEditChange, }, setEditingCell, setEditingRow, } = table;
2233
1745
  const { column, row } = cell;
2234
1746
  const { columnDef } = column;
2235
- const [value, setValue] = React.useState(cell.getValue());
1747
+ const { editingRow } = getState();
1748
+ const [value, setValue] = React.useState(() => cell.getValue());
2236
1749
  const handleChange = (event) => {
2237
1750
  var _a;
2238
1751
  setValue(event.target.value);
2239
- (_a = columnDef.onCellEditChange) === null || _a === void 0 ? void 0 : _a.call(columnDef, { event, cell, table });
2240
- onCellEditChange === null || onCellEditChange === void 0 ? void 0 : onCellEditChange({ event, cell, table });
1752
+ (_a = columnDef.onCellEditChange) === null || _a === void 0 ? void 0 : _a.call(columnDef, { event, cell, table, value });
1753
+ onCellEditChange === null || onCellEditChange === void 0 ? void 0 : onCellEditChange({ event, cell, table, value });
2241
1754
  };
2242
1755
  const handleBlur = (event) => {
2243
1756
  var _a;
2244
- if (getState().currentEditingRow) {
1757
+ if (editingRow) {
2245
1758
  if (!row._valuesCache)
2246
1759
  row._valuesCache = {};
2247
1760
  row._valuesCache[column.id] = value;
2248
- setCurrentEditingRow(Object.assign({}, getState().currentEditingRow));
1761
+ setEditingRow(Object.assign({}, editingRow));
2249
1762
  }
2250
- setCurrentEditingCell(null);
2251
- (_a = columnDef.onCellEditBlur) === null || _a === void 0 ? void 0 : _a.call(columnDef, { event, cell, table });
2252
- onCellEditBlur === null || onCellEditBlur === void 0 ? void 0 : onCellEditBlur({ event, cell, table });
1763
+ setEditingCell(null);
1764
+ (_a = columnDef.onCellEditBlur) === null || _a === void 0 ? void 0 : _a.call(columnDef, { event, cell, table, value });
1765
+ onCellEditBlur === null || onCellEditBlur === void 0 ? void 0 : onCellEditBlur({ event, cell, table, value });
2253
1766
  };
2254
1767
  const mTableBodyCellEditTextFieldProps = muiTableBodyCellEditTextFieldProps instanceof Function
2255
1768
  ? muiTableBodyCellEditTextFieldProps({ cell, table })
@@ -2261,10 +1774,10 @@ const MRT_EditCellTextField = ({ cell, table }) => {
2261
1774
  })
2262
1775
  : columnDef.muiTableBodyCellEditTextFieldProps;
2263
1776
  const textFieldProps = Object.assign(Object.assign({}, mTableBodyCellEditTextFieldProps), mcTableBodyCellEditTextFieldProps);
2264
- if (enableEditing && columnDef.enableEditing !== false && columnDef.Edit) {
1777
+ if (columnDef.Edit) {
2265
1778
  return React__default["default"].createElement(React__default["default"].Fragment, null, (_a = columnDef.Edit) === null || _a === void 0 ? void 0 : _a.call(columnDef, { cell, column, table }));
2266
1779
  }
2267
- return (React__default["default"].createElement(material.TextField, Object.assign({ id: `mrt-${tableId}-edit-cell-text-field-${cell.id}`, margin: "dense", onBlur: handleBlur, onChange: handleChange, onClick: (e) => e.stopPropagation(), placeholder: columnDef.header, value: value, variant: "standard" }, textFieldProps)));
1780
+ return (React__default["default"].createElement(material.TextField, Object.assign({ id: `mrt-${tableId}-edit-cell-text-field-${cell.id}`, margin: "none", onBlur: handleBlur, onChange: handleChange, onClick: (e) => e.stopPropagation(), placeholder: columnDef.header, value: value, variant: "standard" }, textFieldProps)));
2268
1781
  };
2269
1782
 
2270
1783
  const MRT_CopyButton = ({ cell, children, table }) => {
@@ -2300,16 +1813,16 @@ const MRT_TableBodyRowGrabHandle = ({ cell, rowRef, table, }) => {
2300
1813
  : muiTableBodyRowDragHandleProps;
2301
1814
  const handleDragStart = (e) => {
2302
1815
  e.dataTransfer.setDragImage(rowRef.current, 0, 0);
2303
- table.setCurrentDraggingRow(cell.row);
1816
+ table.setDraggingRow(cell.row);
2304
1817
  };
2305
1818
  const handleDragEnd = (event) => {
2306
1819
  onRowDrop === null || onRowDrop === void 0 ? void 0 : onRowDrop({
2307
1820
  event,
2308
- draggedRow: table.getState().currentDraggingRow,
2309
- targetRow: table.getState().currentHoveredRow,
1821
+ draggedRow: table.getState().draggingRow,
1822
+ targetRow: table.getState().hoveredRow,
2310
1823
  });
2311
- table.setCurrentDraggingRow(null);
2312
- table.setCurrentHoveredRow(null);
1824
+ table.setDraggingRow(null);
1825
+ table.setHoveredRow(null);
2313
1826
  };
2314
1827
  return (React__default["default"].createElement(MRT_GrabHandleButton, { iconButtonProps: iconButtonProps, onDragStart: handleDragStart, onDragEnd: handleDragEnd, table: table }));
2315
1828
  };
@@ -2317,8 +1830,8 @@ const MRT_TableBodyRowGrabHandle = ({ cell, rowRef, table, }) => {
2317
1830
  const MRT_TableBodyCell = ({ cell, enableHover, rowIndex, rowRef, table, }) => {
2318
1831
  var _a, _b, _c, _d, _f, _g, _h, _j;
2319
1832
  const theme = material.useTheme();
2320
- const { getState, options: { editingMode, enableClickToCopy, enableColumnOrdering, enableEditing, enableGrouping, enablePagination, enableRowNumbers, muiTableBodyCellProps, muiTableBodyCellSkeletonProps, rowNumberMode, tableId, }, setCurrentEditingCell, setCurrentHoveredColumn, } = table;
2321
- const { currentDraggingColumn, currentEditingCell, currentEditingRow, currentHoveredColumn, density, isLoading, showSkeletons, } = getState();
1833
+ const { getState, options: { editingMode, enableClickToCopy, enableColumnOrdering, enableEditing, enableGrouping, enablePagination, enableRowNumbers, muiTableBodyCellProps, muiTableBodyCellSkeletonProps, rowNumberMode, tableId, }, setEditingCell, setHoveredColumn, } = table;
1834
+ const { draggingColumn, editingCell, editingRow, hoveredColumn, density, isLoading, showSkeletons, } = getState();
2322
1835
  const { column, row } = cell;
2323
1836
  const { columnDef } = column;
2324
1837
  const { columnDefType } = columnDef;
@@ -2333,8 +1846,8 @@ const MRT_TableBodyCell = ({ cell, enableHover, rowIndex, rowRef, table, }) => {
2333
1846
  columnDef.enableEditing !== false;
2334
1847
  const isEditing = isEditable &&
2335
1848
  (editingMode === 'table' ||
2336
- (currentEditingRow === null || currentEditingRow === void 0 ? void 0 : currentEditingRow.id) === row.id ||
2337
- (currentEditingCell === null || currentEditingCell === void 0 ? void 0 : currentEditingCell.id) === cell.id);
1849
+ (editingRow === null || editingRow === void 0 ? void 0 : editingRow.id) === row.id ||
1850
+ (editingCell === null || editingCell === void 0 ? void 0 : editingCell.id) === cell.id);
2338
1851
  const [skeletonWidth, setSkeletonWidth] = React.useState(0);
2339
1852
  React.useEffect(() => setSkeletonWidth(isLoading || showSkeletons
2340
1853
  ? columnDefType === 'display'
@@ -2346,7 +1859,7 @@ const MRT_TableBodyCell = ({ cell, enableHover, rowIndex, rowRef, table, }) => {
2346
1859
  if ((enableEditing || columnDef.enableEditing) &&
2347
1860
  columnDef.enableEditing !== false &&
2348
1861
  editingMode === 'cell') {
2349
- setCurrentEditingCell(cell);
1862
+ setEditingCell(cell);
2350
1863
  setTimeout(() => {
2351
1864
  const textField = document.getElementById(`mrt-${tableId}-edit-cell-text-field-${cell.id}`);
2352
1865
  if (textField) {
@@ -2367,16 +1880,16 @@ const MRT_TableBodyCell = ({ cell, enableHover, rowIndex, rowRef, table, }) => {
2367
1880
  return ((table.getRightLeafHeaders().length - 1 - column.getPinnedIndex()) * 150);
2368
1881
  };
2369
1882
  const handleDragEnter = (_e) => {
2370
- if (enableGrouping && (currentHoveredColumn === null || currentHoveredColumn === void 0 ? void 0 : currentHoveredColumn.id) === 'drop-zone') {
2371
- setCurrentHoveredColumn(null);
1883
+ if (enableGrouping && (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === 'drop-zone') {
1884
+ setHoveredColumn(null);
2372
1885
  }
2373
- if (enableColumnOrdering && currentDraggingColumn) {
2374
- setCurrentHoveredColumn(columnDef.enableColumnOrdering !== false ? column : null);
1886
+ if (enableColumnOrdering && draggingColumn) {
1887
+ setHoveredColumn(columnDef.enableColumnOrdering !== false ? column : null);
2375
1888
  }
2376
1889
  };
2377
- const draggingBorder = (currentDraggingColumn === null || currentDraggingColumn === void 0 ? void 0 : currentDraggingColumn.id) === column.id
1890
+ const draggingBorder = (draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id) === column.id
2378
1891
  ? `1px dashed ${theme.palette.text.secondary}`
2379
- : (currentHoveredColumn === null || currentHoveredColumn === void 0 ? void 0 : currentHoveredColumn.id) === column.id
1892
+ : (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === column.id
2380
1893
  ? `2px dashed ${theme.palette.primary.main}`
2381
1894
  : undefined;
2382
1895
  const draggingBorders = draggingBorder
@@ -2402,8 +1915,7 @@ const MRT_TableBodyCell = ({ cell, enableHover, rowIndex, rowRef, table, }) => {
2402
1915
  ? `-4px 0 4px -2px ${material.alpha(theme.palette.common.black, 0.1)}`
2403
1916
  : undefined, cursor: isEditable && editingMode === 'cell' ? 'pointer' : 'text', left: column.getIsPinned() === 'left'
2404
1917
  ? `${column.getStart('left')}px`
2405
- : undefined, opacity: (currentDraggingColumn === null || currentDraggingColumn === void 0 ? void 0 : currentDraggingColumn.id) === column.id ||
2406
- (currentHoveredColumn === null || currentHoveredColumn === void 0 ? void 0 : currentHoveredColumn.id) === column.id
1918
+ : undefined, opacity: (draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id) === column.id || (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === column.id
2407
1919
  ? 0.5
2408
1920
  : 1, overflow: 'hidden', p: density === 'compact'
2409
1921
  ? columnDefType === 'display'
@@ -2422,7 +1934,7 @@ const MRT_TableBodyCell = ({ cell, enableHover, rowIndex, rowRef, table, }) => {
2422
1934
  : density === 'comfortable'
2423
1935
  ? 0.75
2424
1936
  : 1.25)}rem`
2425
- : undefined, position: column.getIsPinned() ? 'sticky' : 'relative', right: column.getIsPinned() === 'right' ? `${getTotalRight()}px` : undefined, textOverflow: columnDefType !== 'display' ? 'ellipsis' : undefined, transition: 'all 0.2s ease-in-out', whiteSpace: density === 'compact' ? 'nowrap' : 'normal', zIndex: (currentDraggingColumn === null || currentDraggingColumn === void 0 ? void 0 : currentDraggingColumn.id) === column.id
1937
+ : undefined, position: column.getIsPinned() ? 'sticky' : 'relative', right: column.getIsPinned() === 'right' ? `${getTotalRight()}px` : undefined, textOverflow: columnDefType !== 'display' ? 'ellipsis' : undefined, transition: 'all 0.2s ease-in-out', whiteSpace: density === 'compact' ? 'nowrap' : 'normal', zIndex: (draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id) === column.id
2426
1938
  ? 2
2427
1939
  : column.getIsPinned()
2428
1940
  ? 1
@@ -2468,20 +1980,20 @@ const MRT_TableDetailPanel = ({ row, table }) => {
2468
1980
  const MRT_TableBodyRow = ({ row, rowIndex, table }) => {
2469
1981
  var _a, _b;
2470
1982
  const theme = material.useTheme();
2471
- const { getIsSomeColumnsPinned, getState, options: { enableRowOrdering, muiTableBodyRowProps, renderDetailPanel }, setCurrentHoveredRow, } = table;
2472
- const { currentDraggingRow, currentHoveredRow } = getState();
1983
+ const { getIsSomeColumnsPinned, getState, options: { enableRowOrdering, muiTableBodyRowProps, renderDetailPanel }, setHoveredRow, } = table;
1984
+ const { draggingRow, hoveredRow } = getState();
2473
1985
  const tableRowProps = muiTableBodyRowProps instanceof Function
2474
1986
  ? muiTableBodyRowProps({ row, table })
2475
1987
  : muiTableBodyRowProps;
2476
1988
  const handleDragEnter = (_e) => {
2477
- if (enableRowOrdering && currentDraggingRow) {
2478
- setCurrentHoveredRow(row);
1989
+ if (enableRowOrdering && draggingRow) {
1990
+ setHoveredRow(row);
2479
1991
  }
2480
1992
  };
2481
1993
  const rowRef = React.useRef(null);
2482
- const draggingBorder = (currentDraggingRow === null || currentDraggingRow === void 0 ? void 0 : currentDraggingRow.id) === row.id
1994
+ const draggingBorder = (draggingRow === null || draggingRow === void 0 ? void 0 : draggingRow.id) === row.id
2483
1995
  ? `1px dashed ${theme.palette.text.secondary}`
2484
- : (currentHoveredRow === null || currentHoveredRow === void 0 ? void 0 : currentHoveredRow.id) === row.id
1996
+ : (hoveredRow === null || hoveredRow === void 0 ? void 0 : hoveredRow.id) === row.id
2485
1997
  ? `2px dashed ${theme.palette.primary.main}`
2486
1998
  : undefined;
2487
1999
  const draggingBorders = draggingBorder
@@ -2490,10 +2002,7 @@ const MRT_TableBodyRow = ({ row, rowIndex, table }) => {
2490
2002
  }
2491
2003
  : undefined;
2492
2004
  return (React__default["default"].createElement(React__default["default"].Fragment, null,
2493
- React__default["default"].createElement(material.TableRow, Object.assign({ onDragEnter: handleDragEnter, hover: true, selected: row.getIsSelected(), ref: rowRef }, tableRowProps, { sx: (theme) => (Object.assign(Object.assign({ backgroundColor: material.lighten(theme.palette.background.default, 0.06), opacity: (currentDraggingRow === null || currentDraggingRow === void 0 ? void 0 : currentDraggingRow.id) === row.id ||
2494
- (currentHoveredRow === null || currentHoveredRow === void 0 ? void 0 : currentHoveredRow.id) === row.id
2495
- ? 0.5
2496
- : 1, transition: 'all 0.2s ease-in-out', '&:hover td': {
2005
+ React__default["default"].createElement(material.TableRow, Object.assign({ onDragEnter: handleDragEnter, hover: true, selected: row.getIsSelected(), ref: rowRef }, tableRowProps, { sx: (theme) => (Object.assign(Object.assign({ backgroundColor: material.lighten(theme.palette.background.default, 0.06), opacity: (draggingRow === null || draggingRow === void 0 ? void 0 : draggingRow.id) === row.id || (hoveredRow === null || hoveredRow === void 0 ? void 0 : hoveredRow.id) === row.id ? 0.5 : 1, transition: 'all 0.2s ease-in-out', '&:hover td': {
2497
2006
  backgroundColor: (tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.hover) !== false && getIsSomeColumnsPinned()
2498
2007
  ? theme.palette.mode === 'dark'
2499
2008
  ? `${material.lighten(theme.palette.background.default, 0.12)}`
@@ -2535,7 +2044,7 @@ const MRT_TableBody = ({ table, tableContainerRef }) => {
2535
2044
  globalFilter,
2536
2045
  ]);
2537
2046
  const rowVirtualizer = enableRowVirtualization
2538
- ? useVirtual(Object.assign({ size: rows.length, parentRef: tableContainerRef, overscan: 15 }, vProps))
2047
+ ? reactVirtual.useVirtual(Object.assign({ size: rows.length, parentRef: tableContainerRef, overscan: 15 }, vProps))
2539
2048
  : {};
2540
2049
  // const rowVirtualizer: Virtualizer = enableRowVirtualization
2541
2050
  // ? useVirtualizer({
@@ -2700,7 +2209,7 @@ const MRT_TablePaper = ({ table }) => {
2700
2209
  };
2701
2210
 
2702
2211
  const MRT_TableRoot = (props) => {
2703
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4;
2212
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7;
2704
2213
  const [tableId, setIdPrefix] = React.useState(props.tableId);
2705
2214
  React.useEffect(() => { var _a; return setIdPrefix((_a = props.tableId) !== null && _a !== void 0 ? _a : Math.random().toString(36).substring(2, 9)); }, [props.tableId]);
2706
2215
  const initialState = React.useMemo(() => {
@@ -2708,20 +2217,12 @@ const MRT_TableRoot = (props) => {
2708
2217
  const initState = (_a = props.initialState) !== null && _a !== void 0 ? _a : {};
2709
2218
  initState.columnOrder =
2710
2219
  (_b = initState.columnOrder) !== null && _b !== void 0 ? _b : getDefaultColumnOrderIds(props);
2220
+ initState.globalFilterFn =
2221
+ props.globalFilterFn instanceof String
2222
+ ? props.globalFilterFn
2223
+ : 'fuzzy';
2711
2224
  return initState;
2712
2225
  }, []);
2713
- const [columnOrder, setColumnOrder] = React.useState((_a = initialState.columnOrder) !== null && _a !== void 0 ? _a : []);
2714
- const [currentDraggingColumn, setCurrentDraggingColumn] = React.useState((_b = initialState.currentDraggingColumn) !== null && _b !== void 0 ? _b : null);
2715
- const [currentDraggingRow, setCurrentDraggingRow] = React.useState((_c = initialState.currentDraggingRow) !== null && _c !== void 0 ? _c : null);
2716
- const [currentEditingCell, setCurrentEditingCell] = React.useState((_d = initialState.currentEditingCell) !== null && _d !== void 0 ? _d : null);
2717
- const [currentEditingRow, setCurrentEditingRow] = React.useState((_e = initialState.currentEditingRow) !== null && _e !== void 0 ? _e : null);
2718
- const [currentHoveredColumn, setCurrentHoveredColumn] = React.useState((_f = initialState.currentHoveredColumn) !== null && _f !== void 0 ? _f : null);
2719
- const [currentHoveredRow, setCurrentHoveredRow] = React.useState((_g = initialState.currentHoveredRow) !== null && _g !== void 0 ? _g : null);
2720
- const [density, setDensity] = React.useState((_h = initialState === null || initialState === void 0 ? void 0 : initialState.density) !== null && _h !== void 0 ? _h : 'comfortable');
2721
- const [isFullScreen, setIsFullScreen] = React.useState((_j = initialState === null || initialState === void 0 ? void 0 : initialState.isFullScreen) !== null && _j !== void 0 ? _j : false);
2722
- const [showAlertBanner, setShowAlertBanner] = React.useState((_l = (_k = props.initialState) === null || _k === void 0 ? void 0 : _k.showAlertBanner) !== null && _l !== void 0 ? _l : false);
2723
- const [showColumnFilters, setShowFilters] = React.useState((_m = initialState === null || initialState === void 0 ? void 0 : initialState.showColumnFilters) !== null && _m !== void 0 ? _m : false);
2724
- const [showGlobalFilter, setShowGlobalFilter] = React.useState((_o = initialState === null || initialState === void 0 ? void 0 : initialState.showGlobalFilter) !== null && _o !== void 0 ? _o : false);
2725
2226
  const [columnFilterFns, setColumnFilterFns] = React.useState(() => Object.assign({}, ...getAllLeafColumnDefs(props.columns).map((col) => {
2726
2227
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
2727
2228
  return ({
@@ -2730,9 +2231,19 @@ const MRT_TableRoot = (props) => {
2730
2231
  : (_m = (_f = col.filterFn) !== null && _f !== void 0 ? _f : (_g = initialState === null || initialState === void 0 ? void 0 : initialState.columnFilterFns) === null || _g === void 0 ? void 0 : _g[(_l = (_j = (_h = col.id) === null || _h === void 0 ? void 0 : _h.toString()) !== null && _j !== void 0 ? _j : (_k = col.accessorKey) === null || _k === void 0 ? void 0 : _k.toString()) !== null && _l !== void 0 ? _l : '']) !== null && _m !== void 0 ? _m : getDefaultColumnFilterFn(col),
2731
2232
  });
2732
2233
  })));
2733
- const [globalFilterFn, setGlobalFilterFn] = React.useState(props.globalFilterFn instanceof String
2734
- ? props.globalFilterFn
2735
- : 'fuzzy');
2234
+ const [columnOrder, setColumnOrder] = React.useState((_a = initialState.columnOrder) !== null && _a !== void 0 ? _a : []);
2235
+ const [density, setDensity] = React.useState((_b = initialState === null || initialState === void 0 ? void 0 : initialState.density) !== null && _b !== void 0 ? _b : 'comfortable');
2236
+ const [draggingColumn, setDraggingColumn] = React.useState((_c = initialState.draggingColumn) !== null && _c !== void 0 ? _c : null);
2237
+ const [draggingRow, setDraggingRow] = React.useState((_d = initialState.draggingRow) !== null && _d !== void 0 ? _d : null);
2238
+ const [editingCell, setEditingCell] = React.useState((_e = initialState.editingCell) !== null && _e !== void 0 ? _e : null);
2239
+ const [editingRow, setEditingRow] = React.useState((_f = initialState.editingRow) !== null && _f !== void 0 ? _f : null);
2240
+ const [globalFilterFn, setGlobalFilterFn] = React.useState((_g = initialState.globalFilterFn) !== null && _g !== void 0 ? _g : 'fuzzy');
2241
+ const [hoveredColumn, setHoveredColumn] = React.useState((_h = initialState.hoveredColumn) !== null && _h !== void 0 ? _h : null);
2242
+ const [hoveredRow, setHoveredRow] = React.useState((_j = initialState.hoveredRow) !== null && _j !== void 0 ? _j : null);
2243
+ const [isFullScreen, setIsFullScreen] = React.useState((_k = initialState === null || initialState === void 0 ? void 0 : initialState.isFullScreen) !== null && _k !== void 0 ? _k : false);
2244
+ const [showAlertBanner, setShowAlertBanner] = React.useState((_m = (_l = props.initialState) === null || _l === void 0 ? void 0 : _l.showAlertBanner) !== null && _m !== void 0 ? _m : false);
2245
+ const [showColumnFilters, setShowFilters] = React.useState((_o = initialState === null || initialState === void 0 ? void 0 : initialState.showColumnFilters) !== null && _o !== void 0 ? _o : false);
2246
+ const [showGlobalFilter, setShowGlobalFilter] = React.useState((_p = initialState === null || initialState === void 0 ? void 0 : initialState.showGlobalFilter) !== null && _p !== void 0 ? _p : false);
2736
2247
  const displayColumns = React.useMemo(() => {
2737
2248
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
2738
2249
  return [
@@ -2759,8 +2270,6 @@ const MRT_TableRoot = (props) => {
2759
2270
  props.enableRowSelection,
2760
2271
  props.enableSelectAll,
2761
2272
  props.localization,
2762
- props.muiTableBodyCellProps,
2763
- props.muiTableHeadCellProps,
2764
2273
  props.positionActionsColumn,
2765
2274
  ]);
2766
2275
  const columnDefs = React.useMemo(() => prepareColumns([...displayColumns, ...props.columns], columnFilterFns, props.filterFns, props.sortingFns), [columnFilterFns, displayColumns, props.columns]);
@@ -2779,26 +2288,24 @@ const MRT_TableRoot = (props) => {
2779
2288
  });
2780
2289
  })))
2781
2290
  : props.data;
2782
- }, [props.data, (_p = props.state) === null || _p === void 0 ? void 0 : _p.isLoading, (_q = props.state) === null || _q === void 0 ? void 0 : _q.showSkeletons]);
2291
+ }, [props.data, (_q = props.state) === null || _q === void 0 ? void 0 : _q.isLoading, (_r = props.state) === null || _r === void 0 ? void 0 : _r.showSkeletons]);
2783
2292
  //@ts-ignore
2784
2293
  const table = Object.assign(Object.assign({}, reactTable.useReactTable(Object.assign(Object.assign({ getCoreRowModel: reactTable.getCoreRowModel(), getExpandedRowModel: reactTable.getExpandedRowModel(), getFacetedRowModel: reactTable.getFacetedRowModel(), getFilteredRowModel: reactTable.getFilteredRowModel(), getGroupedRowModel: reactTable.getGroupedRowModel(), getPaginationRowModel: reactTable.getPaginationRowModel(), getSortedRowModel: reactTable.getSortedRowModel(), onColumnOrderChange: setColumnOrder, getSubRows: (row) => row === null || row === void 0 ? void 0 : row.subRows }, props), {
2785
2294
  //@ts-ignore
2786
- columns: columnDefs, data, globalFilterFn:
2787
- //@ts-ignore
2788
- (_r = props.filterFns[globalFilterFn]) !== null && _r !== void 0 ? _r : props.filterFns.fuzzy, initialState, state: Object.assign({ columnOrder,
2789
- currentDraggingColumn,
2790
- currentDraggingRow,
2791
- currentEditingCell,
2792
- currentEditingRow,
2793
- columnFilterFns,
2794
- globalFilterFn,
2795
- currentHoveredColumn,
2796
- currentHoveredRow,
2295
+ columns: columnDefs, data, globalFilterFn: (_t = (_s = props.filterFns) === null || _s === void 0 ? void 0 : _s[globalFilterFn]) !== null && _t !== void 0 ? _t : (_u = props.filterFns) === null || _u === void 0 ? void 0 : _u.fuzzy, initialState, state: Object.assign({ columnFilterFns,
2296
+ columnOrder,
2797
2297
  density,
2298
+ draggingColumn,
2299
+ draggingRow,
2300
+ editingCell,
2301
+ editingRow,
2302
+ globalFilterFn,
2303
+ hoveredColumn,
2304
+ hoveredRow,
2798
2305
  isFullScreen,
2799
2306
  showAlertBanner,
2800
2307
  showColumnFilters,
2801
- showGlobalFilter }, props.state), tableId }))), { setCurrentDraggingColumn: (_s = props.onCurrentDraggingColumnChange) !== null && _s !== void 0 ? _s : setCurrentDraggingColumn, setCurrentDraggingRow: (_t = props.onCurrentDraggingRowChange) !== null && _t !== void 0 ? _t : setCurrentDraggingRow, setCurrentEditingCell: (_u = props.onCurrentEditingCellChange) !== null && _u !== void 0 ? _u : setCurrentEditingCell, setCurrentEditingRow: (_v = props.onCurrentEditingRowChange) !== null && _v !== void 0 ? _v : setCurrentEditingRow, setColumnFilterFns: (_w = props.onCurrentFilterFnsChange) !== null && _w !== void 0 ? _w : setColumnFilterFns, setGlobalFilterFn: (_x = props.onCurrentGlobalFilterFnChange) !== null && _x !== void 0 ? _x : setGlobalFilterFn, setCurrentHoveredColumn: (_y = props.onCurrentHoveredColumnChange) !== null && _y !== void 0 ? _y : setCurrentHoveredColumn, setCurrentHoveredRow: (_z = props.onCurrentHoveredRowChange) !== null && _z !== void 0 ? _z : setCurrentHoveredRow, setDensity: (_0 = props.onDensityChange) !== null && _0 !== void 0 ? _0 : setDensity, setIsFullScreen: (_1 = props.onIsFullScreenChange) !== null && _1 !== void 0 ? _1 : setIsFullScreen, setShowAlertBanner: (_2 = props.onShowAlertBannerChange) !== null && _2 !== void 0 ? _2 : setShowAlertBanner, setShowFilters: (_3 = props.onShowFiltersChange) !== null && _3 !== void 0 ? _3 : setShowFilters, setShowGlobalFilter: (_4 = props.onShowGlobalFilterChange) !== null && _4 !== void 0 ? _4 : setShowGlobalFilter });
2308
+ showGlobalFilter }, props.state), tableId }))), { setColumnFilterFns: (_v = props.onFilterFnsChange) !== null && _v !== void 0 ? _v : setColumnFilterFns, setDensity: (_w = props.onDensityChange) !== null && _w !== void 0 ? _w : setDensity, setDraggingColumn: (_x = props.onDraggingColumnChange) !== null && _x !== void 0 ? _x : setDraggingColumn, setDraggingRow: (_y = props.onDraggingRowChange) !== null && _y !== void 0 ? _y : setDraggingRow, setEditingCell: (_z = props.onEditingCellChange) !== null && _z !== void 0 ? _z : setEditingCell, setEditingRow: (_0 = props.onEditingRowChange) !== null && _0 !== void 0 ? _0 : setEditingRow, setGlobalFilterFn: (_1 = props.onGlobalFilterFnChange) !== null && _1 !== void 0 ? _1 : setGlobalFilterFn, setHoveredColumn: (_2 = props.onHoveredColumnChange) !== null && _2 !== void 0 ? _2 : setHoveredColumn, setHoveredRow: (_3 = props.onHoveredRowChange) !== null && _3 !== void 0 ? _3 : setHoveredRow, setIsFullScreen: (_4 = props.onIsFullScreenChange) !== null && _4 !== void 0 ? _4 : setIsFullScreen, setShowAlertBanner: (_5 = props.onShowAlertBannerChange) !== null && _5 !== void 0 ? _5 : setShowAlertBanner, setShowFilters: (_6 = props.onShowFiltersChange) !== null && _6 !== void 0 ? _6 : setShowFilters, setShowGlobalFilter: (_7 = props.onShowGlobalFilterChange) !== null && _7 !== void 0 ? _7 : setShowGlobalFilter });
2802
2309
  return (React__default["default"].createElement(React__default["default"].Fragment, null,
2803
2310
  React__default["default"].createElement(material.Dialog, { PaperComponent: material.Box, TransitionComponent: material.Grow, disablePortal: true, fullScreen: true, keepMounted: false, onClose: () => setIsFullScreen(false), open: isFullScreen, transitionDuration: 400 },
2804
2311
  React__default["default"].createElement(MRT_TablePaper, { table: table })),