@tanstack/table-core 8.9.11 → 8.10.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.
@@ -905,6 +905,15 @@ const Expanding = {
905
905
  var _table$options$getRow, _table$options$enable, _row$subRows;
906
906
  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);
907
907
  };
908
+ row.getIsAllParentsExpanded = () => {
909
+ let isFullyExpanded = true;
910
+ let currentRow = row;
911
+ while (isFullyExpanded && currentRow.parentId) {
912
+ currentRow = table.getRow(currentRow.parentId, true);
913
+ isFullyExpanded = currentRow.getIsExpanded();
914
+ }
915
+ return isFullyExpanded;
916
+ };
908
917
  row.getToggleExpandedHandler = () => {
909
918
  const canExpand = row.getCanExpand();
910
919
  return () => {
@@ -1628,20 +1637,26 @@ const Pagination = {
1628
1637
 
1629
1638
  //
1630
1639
 
1631
- const getDefaultPinningState = () => ({
1640
+ const getDefaultColumnPinningState = () => ({
1632
1641
  left: [],
1633
1642
  right: []
1634
1643
  });
1644
+ const getDefaultRowPinningState = () => ({
1645
+ top: [],
1646
+ bottom: []
1647
+ });
1635
1648
  const Pinning = {
1636
1649
  getInitialState: state => {
1637
1650
  return {
1638
- columnPinning: getDefaultPinningState(),
1651
+ columnPinning: getDefaultColumnPinningState(),
1652
+ rowPinning: getDefaultRowPinningState(),
1639
1653
  ...state
1640
1654
  };
1641
1655
  },
1642
1656
  getDefaultOptions: table => {
1643
1657
  return {
1644
- onColumnPinningChange: makeStateUpdater('columnPinning', table)
1658
+ onColumnPinningChange: makeStateUpdater('columnPinning', table),
1659
+ onRowPinningChange: makeStateUpdater('rowPinning', table)
1645
1660
  };
1646
1661
  },
1647
1662
  createColumn: (column, table) => {
@@ -1672,8 +1687,8 @@ const Pinning = {
1672
1687
  column.getCanPin = () => {
1673
1688
  const leafColumns = column.getLeafColumns();
1674
1689
  return leafColumns.some(d => {
1675
- var _d$columnDef$enablePi, _table$options$enable;
1676
- return ((_d$columnDef$enablePi = d.columnDef.enablePinning) != null ? _d$columnDef$enablePi : true) && ((_table$options$enable = table.options.enablePinning) != null ? _table$options$enable : true);
1690
+ var _d$columnDef$enablePi, _ref, _table$options$enable;
1691
+ 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);
1677
1692
  });
1678
1693
  };
1679
1694
  column.getIsPinned = () => {
@@ -1693,11 +1708,80 @@ const Pinning = {
1693
1708
  };
1694
1709
  },
1695
1710
  createRow: (row, table) => {
1711
+ row.pin = (position, includeLeafRows, includeParentRows) => {
1712
+ const leafRowIds = includeLeafRows ? row.getLeafRows().map(_ref2 => {
1713
+ let {
1714
+ id
1715
+ } = _ref2;
1716
+ return id;
1717
+ }) : [];
1718
+ const parentRowIds = includeParentRows ? row.getParentRows().map(_ref3 => {
1719
+ let {
1720
+ id
1721
+ } = _ref3;
1722
+ return id;
1723
+ }) : [];
1724
+ const rowIds = new Set([...parentRowIds, row.id, ...leafRowIds]);
1725
+ table.setRowPinning(old => {
1726
+ var _old$top3, _old$bottom3;
1727
+ if (position === 'bottom') {
1728
+ var _old$top, _old$bottom;
1729
+ return {
1730
+ top: ((_old$top = old == null ? void 0 : old.top) != null ? _old$top : []).filter(d => !(rowIds != null && rowIds.has(d))),
1731
+ bottom: [...((_old$bottom = old == null ? void 0 : old.bottom) != null ? _old$bottom : []).filter(d => !(rowIds != null && rowIds.has(d))), ...Array.from(rowIds)]
1732
+ };
1733
+ }
1734
+ if (position === 'top') {
1735
+ var _old$top2, _old$bottom2;
1736
+ return {
1737
+ top: [...((_old$top2 = old == null ? void 0 : old.top) != null ? _old$top2 : []).filter(d => !(rowIds != null && rowIds.has(d))), ...Array.from(rowIds)],
1738
+ bottom: ((_old$bottom2 = old == null ? void 0 : old.bottom) != null ? _old$bottom2 : []).filter(d => !(rowIds != null && rowIds.has(d)))
1739
+ };
1740
+ }
1741
+ return {
1742
+ top: ((_old$top3 = old == null ? void 0 : old.top) != null ? _old$top3 : []).filter(d => !(rowIds != null && rowIds.has(d))),
1743
+ bottom: ((_old$bottom3 = old == null ? void 0 : old.bottom) != null ? _old$bottom3 : []).filter(d => !(rowIds != null && rowIds.has(d)))
1744
+ };
1745
+ });
1746
+ };
1747
+ row.getCanPin = () => {
1748
+ var _ref4;
1749
+ const {
1750
+ enableRowPinning,
1751
+ enablePinning
1752
+ } = table.options;
1753
+ if (typeof enableRowPinning === 'function') {
1754
+ return enableRowPinning(row);
1755
+ }
1756
+ return (_ref4 = enableRowPinning != null ? enableRowPinning : enablePinning) != null ? _ref4 : true;
1757
+ };
1758
+ row.getIsPinned = () => {
1759
+ const rowIds = [row.id];
1760
+ const {
1761
+ top,
1762
+ bottom
1763
+ } = table.getState().rowPinning;
1764
+ const isTop = rowIds.some(d => top == null ? void 0 : top.includes(d));
1765
+ const isBottom = rowIds.some(d => bottom == null ? void 0 : bottom.includes(d));
1766
+ return isTop ? 'top' : isBottom ? 'bottom' : false;
1767
+ };
1768
+ row.getPinnedIndex = () => {
1769
+ var _table$_getPinnedRows, _visiblePinnedRowIds$;
1770
+ const position = row.getIsPinned();
1771
+ if (!position) return -1;
1772
+ const visiblePinnedRowIds = (_table$_getPinnedRows = table._getPinnedRows(position)) == null ? void 0 : _table$_getPinnedRows.map(_ref5 => {
1773
+ let {
1774
+ id
1775
+ } = _ref5;
1776
+ return id;
1777
+ });
1778
+ return (_visiblePinnedRowIds$ = visiblePinnedRowIds == null ? void 0 : visiblePinnedRowIds.indexOf(row.id)) != null ? _visiblePinnedRowIds$ : -1;
1779
+ };
1696
1780
  row.getCenterVisibleCells = memo(() => [row._getAllVisibleCells(), table.getState().columnPinning.left, table.getState().columnPinning.right], (allCells, left, right) => {
1697
1781
  const leftAndRight = [...(left != null ? left : []), ...(right != null ? right : [])];
1698
1782
  return allCells.filter(d => !leftAndRight.includes(d.column.id));
1699
1783
  }, {
1700
- key: process.env.NODE_ENV === 'production' && 'row.getCenterVisibleCells',
1784
+ key: process.env.NODE_ENV === 'development' && 'row.getCenterVisibleCells',
1701
1785
  debug: () => {
1702
1786
  var _table$options$debugA;
1703
1787
  return (_table$options$debugA = table.options.debugAll) != null ? _table$options$debugA : table.options.debugRows;
@@ -1710,7 +1794,7 @@ const Pinning = {
1710
1794
  }));
1711
1795
  return cells;
1712
1796
  }, {
1713
- key: process.env.NODE_ENV === 'production' && 'row.getLeftVisibleCells',
1797
+ key: process.env.NODE_ENV === 'development' && 'row.getLeftVisibleCells',
1714
1798
  debug: () => {
1715
1799
  var _table$options$debugA2;
1716
1800
  return (_table$options$debugA2 = table.options.debugAll) != null ? _table$options$debugA2 : table.options.debugRows;
@@ -1723,7 +1807,7 @@ const Pinning = {
1723
1807
  }));
1724
1808
  return cells;
1725
1809
  }, {
1726
- key: process.env.NODE_ENV === 'production' && 'row.getRightVisibleCells',
1810
+ key: process.env.NODE_ENV === 'development' && 'row.getRightVisibleCells',
1727
1811
  debug: () => {
1728
1812
  var _table$options$debugA3;
1729
1813
  return (_table$options$debugA3 = table.options.debugAll) != null ? _table$options$debugA3 : table.options.debugRows;
@@ -1734,7 +1818,7 @@ const Pinning = {
1734
1818
  table.setColumnPinning = updater => table.options.onColumnPinningChange == null ? void 0 : table.options.onColumnPinningChange(updater);
1735
1819
  table.resetColumnPinning = defaultState => {
1736
1820
  var _table$initialState$c, _table$initialState;
1737
- return table.setColumnPinning(defaultState ? getDefaultPinningState() : (_table$initialState$c = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.columnPinning) != null ? _table$initialState$c : getDefaultPinningState());
1821
+ return table.setColumnPinning(defaultState ? getDefaultColumnPinningState() : (_table$initialState$c = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.columnPinning) != null ? _table$initialState$c : getDefaultColumnPinningState());
1738
1822
  };
1739
1823
  table.getIsSomeColumnsPinned = position => {
1740
1824
  var _pinningState$positio;
@@ -1773,6 +1857,54 @@ const Pinning = {
1773
1857
  return (_table$options$debugA6 = table.options.debugAll) != null ? _table$options$debugA6 : table.options.debugColumns;
1774
1858
  }
1775
1859
  });
1860
+ table.setRowPinning = updater => table.options.onRowPinningChange == null ? void 0 : table.options.onRowPinningChange(updater);
1861
+ table.resetRowPinning = defaultState => {
1862
+ var _table$initialState$r, _table$initialState2;
1863
+ return table.setRowPinning(defaultState ? getDefaultRowPinningState() : (_table$initialState$r = (_table$initialState2 = table.initialState) == null ? void 0 : _table$initialState2.rowPinning) != null ? _table$initialState$r : getDefaultRowPinningState());
1864
+ };
1865
+ table.getIsSomeRowsPinned = position => {
1866
+ var _pinningState$positio2;
1867
+ const pinningState = table.getState().rowPinning;
1868
+ if (!position) {
1869
+ var _pinningState$top, _pinningState$bottom;
1870
+ return Boolean(((_pinningState$top = pinningState.top) == null ? void 0 : _pinningState$top.length) || ((_pinningState$bottom = pinningState.bottom) == null ? void 0 : _pinningState$bottom.length));
1871
+ }
1872
+ return Boolean((_pinningState$positio2 = pinningState[position]) == null ? void 0 : _pinningState$positio2.length);
1873
+ };
1874
+ table._getPinnedRows = position => memo(() => [table.getRowModel().rows, table.getState().rowPinning[position]], (visibleRows, pinnedRowIds) => {
1875
+ var _table$options$keepPi;
1876
+ const rows = ((_table$options$keepPi = table.options.keepPinnedRows) != null ? _table$options$keepPi : true) ?
1877
+ //get all rows that are pinned even if they would not be otherwise visible
1878
+ //account for expanded parent rows, but not pagination or filtering
1879
+ (pinnedRowIds != null ? pinnedRowIds : []).map(rowId => {
1880
+ const row = table.getRow(rowId, true);
1881
+ return row.getIsAllParentsExpanded() ? row : null;
1882
+ }) :
1883
+ //else get only visible rows that are pinned
1884
+ (pinnedRowIds != null ? pinnedRowIds : []).map(rowId => visibleRows.find(row => row.id === rowId));
1885
+ return rows.filter(Boolean).map(d => ({
1886
+ ...d,
1887
+ position
1888
+ }));
1889
+ }, {
1890
+ key: process.env.NODE_ENV === 'development' && `row.get${position === 'top' ? 'Top' : 'Bottom'}Rows`,
1891
+ debug: () => {
1892
+ var _table$options$debugA7;
1893
+ return (_table$options$debugA7 = table.options.debugAll) != null ? _table$options$debugA7 : table.options.debugRows;
1894
+ }
1895
+ })();
1896
+ table.getTopRows = () => table._getPinnedRows('top');
1897
+ table.getBottomRows = () => table._getPinnedRows('bottom');
1898
+ table.getCenterRows = memo(() => [table.getRowModel().rows, table.getState().rowPinning.top, table.getState().rowPinning.bottom], (allRows, top, bottom) => {
1899
+ const topAndBottom = new Set([...(top != null ? top : []), ...(bottom != null ? bottom : [])]);
1900
+ return allRows.filter(d => !topAndBottom.has(d.id));
1901
+ }, {
1902
+ key: process.env.NODE_ENV === 'development' && 'row.getCenterRows',
1903
+ debug: () => {
1904
+ var _table$options$debugA8;
1905
+ return (_table$options$debugA8 = table.options.debugAll) != null ? _table$options$debugA8 : table.options.debugRows;
1906
+ }
1907
+ });
1776
1908
  }
1777
1909
  };
1778
1910
 
@@ -2664,8 +2796,8 @@ function createTable(options) {
2664
2796
  getRowModel: () => {
2665
2797
  return table.getPaginationRowModel();
2666
2798
  },
2667
- getRow: id => {
2668
- const row = table.getRowModel().rowsById[id];
2799
+ getRow: (id, searchAll) => {
2800
+ const row = (searchAll ? table.getCoreRowModel() : table.getRowModel()).rowsById[id];
2669
2801
  if (!row) {
2670
2802
  if (process.env.NODE_ENV !== 'production') {
2671
2803
  throw new Error(`getRow expected an ID, but got ${id}`);