@tanstack/react-table 8.9.10 → 8.10.0

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.
@@ -940,6 +940,15 @@
940
940
  var _table$options$getRow, _table$options$enable, _row$subRows;
941
941
  return (_table$options$getRow = table.options.getRowCanExpand == null ? void 0 : table.options.getRowCanExpand(row)) != null ? _table$options$getRow : ((_table$options$enable = table.options.enableExpanding) != null ? _table$options$enable : true) && !!((_row$subRows = row.subRows) != null && _row$subRows.length);
942
942
  };
943
+ row.getIsAllParentsExpanded = () => {
944
+ let isFullyExpanded = true;
945
+ let currentRow = row;
946
+ while (isFullyExpanded && currentRow.parentId) {
947
+ currentRow = table.getRow(currentRow.parentId, true);
948
+ isFullyExpanded = currentRow.getIsExpanded();
949
+ }
950
+ return isFullyExpanded;
951
+ };
943
952
  row.getToggleExpandedHandler = () => {
944
953
  const canExpand = row.getCanExpand();
945
954
  return () => {
@@ -1663,20 +1672,26 @@
1663
1672
 
1664
1673
  //
1665
1674
 
1666
- const getDefaultPinningState = () => ({
1675
+ const getDefaultColumnPinningState = () => ({
1667
1676
  left: [],
1668
1677
  right: []
1669
1678
  });
1679
+ const getDefaultRowPinningState = () => ({
1680
+ top: [],
1681
+ bottom: []
1682
+ });
1670
1683
  const Pinning = {
1671
1684
  getInitialState: state => {
1672
1685
  return {
1673
- columnPinning: getDefaultPinningState(),
1686
+ columnPinning: getDefaultColumnPinningState(),
1687
+ rowPinning: getDefaultRowPinningState(),
1674
1688
  ...state
1675
1689
  };
1676
1690
  },
1677
1691
  getDefaultOptions: table => {
1678
1692
  return {
1679
- onColumnPinningChange: makeStateUpdater('columnPinning', table)
1693
+ onColumnPinningChange: makeStateUpdater('columnPinning', table),
1694
+ onRowPinningChange: makeStateUpdater('rowPinning', table)
1680
1695
  };
1681
1696
  },
1682
1697
  createColumn: (column, table) => {
@@ -1707,8 +1722,8 @@
1707
1722
  column.getCanPin = () => {
1708
1723
  const leafColumns = column.getLeafColumns();
1709
1724
  return leafColumns.some(d => {
1710
- var _d$columnDef$enablePi, _table$options$enable;
1711
- return ((_d$columnDef$enablePi = d.columnDef.enablePinning) != null ? _d$columnDef$enablePi : true) && ((_table$options$enable = table.options.enablePinning) != null ? _table$options$enable : true);
1725
+ var _d$columnDef$enablePi, _ref, _table$options$enable;
1726
+ return ((_d$columnDef$enablePi = d.columnDef.enablePinning) != null ? _d$columnDef$enablePi : true) && ((_ref = (_table$options$enable = table.options.enableColumnPinning) != null ? _table$options$enable : table.options.enablePinning) != null ? _ref : true);
1712
1727
  });
1713
1728
  };
1714
1729
  column.getIsPinned = () => {
@@ -1728,11 +1743,80 @@
1728
1743
  };
1729
1744
  },
1730
1745
  createRow: (row, table) => {
1746
+ row.pin = (position, includeLeafRows, includeParentRows) => {
1747
+ const leafRowIds = includeLeafRows ? row.getLeafRows().map(_ref2 => {
1748
+ let {
1749
+ id
1750
+ } = _ref2;
1751
+ return id;
1752
+ }) : [];
1753
+ const parentRowIds = includeParentRows ? row.getParentRows().map(_ref3 => {
1754
+ let {
1755
+ id
1756
+ } = _ref3;
1757
+ return id;
1758
+ }) : [];
1759
+ const rowIds = new Set([...parentRowIds, row.id, ...leafRowIds]);
1760
+ table.setRowPinning(old => {
1761
+ var _old$top3, _old$bottom3;
1762
+ if (position === 'bottom') {
1763
+ var _old$top, _old$bottom;
1764
+ return {
1765
+ top: ((_old$top = old == null ? void 0 : old.top) != null ? _old$top : []).filter(d => !(rowIds != null && rowIds.has(d))),
1766
+ bottom: [...((_old$bottom = old == null ? void 0 : old.bottom) != null ? _old$bottom : []).filter(d => !(rowIds != null && rowIds.has(d))), ...rowIds]
1767
+ };
1768
+ }
1769
+ if (position === 'top') {
1770
+ var _old$top2, _old$bottom2;
1771
+ return {
1772
+ top: [...((_old$top2 = old == null ? void 0 : old.top) != null ? _old$top2 : []).filter(d => !(rowIds != null && rowIds.has(d))), ...rowIds],
1773
+ bottom: ((_old$bottom2 = old == null ? void 0 : old.bottom) != null ? _old$bottom2 : []).filter(d => !(rowIds != null && rowIds.has(d)))
1774
+ };
1775
+ }
1776
+ return {
1777
+ top: ((_old$top3 = old == null ? void 0 : old.top) != null ? _old$top3 : []).filter(d => !(rowIds != null && rowIds.has(d))),
1778
+ bottom: ((_old$bottom3 = old == null ? void 0 : old.bottom) != null ? _old$bottom3 : []).filter(d => !(rowIds != null && rowIds.has(d)))
1779
+ };
1780
+ });
1781
+ };
1782
+ row.getCanPin = () => {
1783
+ var _ref4;
1784
+ const {
1785
+ enableRowPinning,
1786
+ enablePinning
1787
+ } = table.options;
1788
+ if (typeof enableRowPinning === 'function') {
1789
+ return enableRowPinning(row);
1790
+ }
1791
+ return (_ref4 = enableRowPinning != null ? enableRowPinning : enablePinning) != null ? _ref4 : true;
1792
+ };
1793
+ row.getIsPinned = () => {
1794
+ const rowIds = [row.id];
1795
+ const {
1796
+ top,
1797
+ bottom
1798
+ } = table.getState().rowPinning;
1799
+ const isTop = rowIds.some(d => top == null ? void 0 : top.includes(d));
1800
+ const isBottom = rowIds.some(d => bottom == null ? void 0 : bottom.includes(d));
1801
+ return isTop ? 'top' : isBottom ? 'bottom' : false;
1802
+ };
1803
+ row.getPinnedIndex = () => {
1804
+ var _table$_getPinnedRows, _visiblePinnedRowIds$;
1805
+ const position = row.getIsPinned();
1806
+ if (!position) return -1;
1807
+ const visiblePinnedRowIds = (_table$_getPinnedRows = table._getPinnedRows(position)) == null ? void 0 : _table$_getPinnedRows.map(_ref5 => {
1808
+ let {
1809
+ id
1810
+ } = _ref5;
1811
+ return id;
1812
+ });
1813
+ return (_visiblePinnedRowIds$ = visiblePinnedRowIds == null ? void 0 : visiblePinnedRowIds.indexOf(row.id)) != null ? _visiblePinnedRowIds$ : -1;
1814
+ };
1731
1815
  row.getCenterVisibleCells = memo(() => [row._getAllVisibleCells(), table.getState().columnPinning.left, table.getState().columnPinning.right], (allCells, left, right) => {
1732
1816
  const leftAndRight = [...(left != null ? left : []), ...(right != null ? right : [])];
1733
1817
  return allCells.filter(d => !leftAndRight.includes(d.column.id));
1734
1818
  }, {
1735
- key: "development" === 'production' ,
1819
+ key: 'row.getCenterVisibleCells',
1736
1820
  debug: () => {
1737
1821
  var _table$options$debugA;
1738
1822
  return (_table$options$debugA = table.options.debugAll) != null ? _table$options$debugA : table.options.debugRows;
@@ -1745,7 +1829,7 @@
1745
1829
  }));
1746
1830
  return cells;
1747
1831
  }, {
1748
- key: "development" === 'production' ,
1832
+ key: 'row.getLeftVisibleCells',
1749
1833
  debug: () => {
1750
1834
  var _table$options$debugA2;
1751
1835
  return (_table$options$debugA2 = table.options.debugAll) != null ? _table$options$debugA2 : table.options.debugRows;
@@ -1758,7 +1842,7 @@
1758
1842
  }));
1759
1843
  return cells;
1760
1844
  }, {
1761
- key: "development" === 'production' ,
1845
+ key: 'row.getRightVisibleCells',
1762
1846
  debug: () => {
1763
1847
  var _table$options$debugA3;
1764
1848
  return (_table$options$debugA3 = table.options.debugAll) != null ? _table$options$debugA3 : table.options.debugRows;
@@ -1769,7 +1853,7 @@
1769
1853
  table.setColumnPinning = updater => table.options.onColumnPinningChange == null ? void 0 : table.options.onColumnPinningChange(updater);
1770
1854
  table.resetColumnPinning = defaultState => {
1771
1855
  var _table$initialState$c, _table$initialState;
1772
- return table.setColumnPinning(defaultState ? getDefaultPinningState() : (_table$initialState$c = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.columnPinning) != null ? _table$initialState$c : getDefaultPinningState());
1856
+ return table.setColumnPinning(defaultState ? getDefaultColumnPinningState() : (_table$initialState$c = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.columnPinning) != null ? _table$initialState$c : getDefaultColumnPinningState());
1773
1857
  };
1774
1858
  table.getIsSomeColumnsPinned = position => {
1775
1859
  var _pinningState$positio;
@@ -1808,6 +1892,54 @@
1808
1892
  return (_table$options$debugA6 = table.options.debugAll) != null ? _table$options$debugA6 : table.options.debugColumns;
1809
1893
  }
1810
1894
  });
1895
+ table.setRowPinning = updater => table.options.onRowPinningChange == null ? void 0 : table.options.onRowPinningChange(updater);
1896
+ table.resetRowPinning = defaultState => {
1897
+ var _table$initialState$r, _table$initialState2;
1898
+ return table.setRowPinning(defaultState ? getDefaultRowPinningState() : (_table$initialState$r = (_table$initialState2 = table.initialState) == null ? void 0 : _table$initialState2.rowPinning) != null ? _table$initialState$r : getDefaultRowPinningState());
1899
+ };
1900
+ table.getIsSomeRowsPinned = position => {
1901
+ var _pinningState$positio2;
1902
+ const pinningState = table.getState().rowPinning;
1903
+ if (!position) {
1904
+ var _pinningState$top, _pinningState$bottom;
1905
+ return Boolean(((_pinningState$top = pinningState.top) == null ? void 0 : _pinningState$top.length) || ((_pinningState$bottom = pinningState.bottom) == null ? void 0 : _pinningState$bottom.length));
1906
+ }
1907
+ return Boolean((_pinningState$positio2 = pinningState[position]) == null ? void 0 : _pinningState$positio2.length);
1908
+ };
1909
+ table._getPinnedRows = position => memo(() => [table.getRowModel().rows, table.getState().rowPinning[position]], (visibleRows, pinnedRowIds) => {
1910
+ var _table$options$keepPi;
1911
+ const rows = ((_table$options$keepPi = table.options.keepPinnedRows) != null ? _table$options$keepPi : true) ?
1912
+ //get all rows that are pinned even if they would not be otherwise visible
1913
+ //account for expanded parent rows, but not pagination or filtering
1914
+ (pinnedRowIds != null ? pinnedRowIds : []).map(rowId => {
1915
+ const row = table.getRow(rowId, true);
1916
+ return row.getIsAllParentsExpanded() ? row : null;
1917
+ }) :
1918
+ //else get only visible rows that are pinned
1919
+ (pinnedRowIds != null ? pinnedRowIds : []).map(rowId => visibleRows.find(row => row.id === rowId));
1920
+ return rows.filter(Boolean).map(d => ({
1921
+ ...d,
1922
+ position
1923
+ }));
1924
+ }, {
1925
+ key: `row.get${position === 'top' ? 'Top' : 'Bottom'}Rows`,
1926
+ debug: () => {
1927
+ var _table$options$debugA7;
1928
+ return (_table$options$debugA7 = table.options.debugAll) != null ? _table$options$debugA7 : table.options.debugRows;
1929
+ }
1930
+ })();
1931
+ table.getTopRows = () => table._getPinnedRows('top');
1932
+ table.getBottomRows = () => table._getPinnedRows('bottom');
1933
+ table.getCenterRows = memo(() => [table.getRowModel().rows, table.getState().rowPinning.top, table.getState().rowPinning.bottom], (allRows, top, bottom) => {
1934
+ const topAndBottom = new Set([...(top != null ? top : []), ...(bottom != null ? bottom : [])]);
1935
+ return allRows.filter(d => !topAndBottom.has(d.id));
1936
+ }, {
1937
+ key: 'row.getCenterRows',
1938
+ debug: () => {
1939
+ var _table$options$debugA8;
1940
+ return (_table$options$debugA8 = table.options.debugAll) != null ? _table$options$debugA8 : table.options.debugRows;
1941
+ }
1942
+ });
1811
1943
  }
1812
1944
  };
1813
1945
 
@@ -2699,8 +2831,8 @@
2699
2831
  getRowModel: () => {
2700
2832
  return table.getPaginationRowModel();
2701
2833
  },
2702
- getRow: id => {
2703
- const row = table.getRowModel().rowsById[id];
2834
+ getRow: (id, searchAll) => {
2835
+ const row = (searchAll ? table.getCoreRowModel() : table.getRowModel()).rowsById[id];
2704
2836
  if (!row) {
2705
2837
  {
2706
2838
  throw new Error(`getRow expected an ID, but got ${id}`);