@tanstack/svelte-table 8.9.11 → 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.
@@ -920,6 +920,15 @@
920
920
  var _table$options$getRow, _table$options$enable, _row$subRows;
921
921
  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);
922
922
  };
923
+ row.getIsAllParentsExpanded = () => {
924
+ let isFullyExpanded = true;
925
+ let currentRow = row;
926
+ while (isFullyExpanded && currentRow.parentId) {
927
+ currentRow = table.getRow(currentRow.parentId, true);
928
+ isFullyExpanded = currentRow.getIsExpanded();
929
+ }
930
+ return isFullyExpanded;
931
+ };
923
932
  row.getToggleExpandedHandler = () => {
924
933
  const canExpand = row.getCanExpand();
925
934
  return () => {
@@ -1643,20 +1652,26 @@
1643
1652
 
1644
1653
  //
1645
1654
 
1646
- const getDefaultPinningState = () => ({
1655
+ const getDefaultColumnPinningState = () => ({
1647
1656
  left: [],
1648
1657
  right: []
1649
1658
  });
1659
+ const getDefaultRowPinningState = () => ({
1660
+ top: [],
1661
+ bottom: []
1662
+ });
1650
1663
  const Pinning = {
1651
1664
  getInitialState: state => {
1652
1665
  return {
1653
- columnPinning: getDefaultPinningState(),
1666
+ columnPinning: getDefaultColumnPinningState(),
1667
+ rowPinning: getDefaultRowPinningState(),
1654
1668
  ...state
1655
1669
  };
1656
1670
  },
1657
1671
  getDefaultOptions: table => {
1658
1672
  return {
1659
- onColumnPinningChange: makeStateUpdater('columnPinning', table)
1673
+ onColumnPinningChange: makeStateUpdater('columnPinning', table),
1674
+ onRowPinningChange: makeStateUpdater('rowPinning', table)
1660
1675
  };
1661
1676
  },
1662
1677
  createColumn: (column, table) => {
@@ -1687,8 +1702,8 @@
1687
1702
  column.getCanPin = () => {
1688
1703
  const leafColumns = column.getLeafColumns();
1689
1704
  return leafColumns.some(d => {
1690
- var _d$columnDef$enablePi, _table$options$enable;
1691
- return ((_d$columnDef$enablePi = d.columnDef.enablePinning) != null ? _d$columnDef$enablePi : true) && ((_table$options$enable = table.options.enablePinning) != null ? _table$options$enable : true);
1705
+ var _d$columnDef$enablePi, _ref, _table$options$enable;
1706
+ 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);
1692
1707
  });
1693
1708
  };
1694
1709
  column.getIsPinned = () => {
@@ -1708,11 +1723,80 @@
1708
1723
  };
1709
1724
  },
1710
1725
  createRow: (row, table) => {
1726
+ row.pin = (position, includeLeafRows, includeParentRows) => {
1727
+ const leafRowIds = includeLeafRows ? row.getLeafRows().map(_ref2 => {
1728
+ let {
1729
+ id
1730
+ } = _ref2;
1731
+ return id;
1732
+ }) : [];
1733
+ const parentRowIds = includeParentRows ? row.getParentRows().map(_ref3 => {
1734
+ let {
1735
+ id
1736
+ } = _ref3;
1737
+ return id;
1738
+ }) : [];
1739
+ const rowIds = new Set([...parentRowIds, row.id, ...leafRowIds]);
1740
+ table.setRowPinning(old => {
1741
+ var _old$top3, _old$bottom3;
1742
+ if (position === 'bottom') {
1743
+ var _old$top, _old$bottom;
1744
+ return {
1745
+ top: ((_old$top = old == null ? void 0 : old.top) != null ? _old$top : []).filter(d => !(rowIds != null && rowIds.has(d))),
1746
+ bottom: [...((_old$bottom = old == null ? void 0 : old.bottom) != null ? _old$bottom : []).filter(d => !(rowIds != null && rowIds.has(d))), ...rowIds]
1747
+ };
1748
+ }
1749
+ if (position === 'top') {
1750
+ var _old$top2, _old$bottom2;
1751
+ return {
1752
+ top: [...((_old$top2 = old == null ? void 0 : old.top) != null ? _old$top2 : []).filter(d => !(rowIds != null && rowIds.has(d))), ...rowIds],
1753
+ bottom: ((_old$bottom2 = old == null ? void 0 : old.bottom) != null ? _old$bottom2 : []).filter(d => !(rowIds != null && rowIds.has(d)))
1754
+ };
1755
+ }
1756
+ return {
1757
+ top: ((_old$top3 = old == null ? void 0 : old.top) != null ? _old$top3 : []).filter(d => !(rowIds != null && rowIds.has(d))),
1758
+ bottom: ((_old$bottom3 = old == null ? void 0 : old.bottom) != null ? _old$bottom3 : []).filter(d => !(rowIds != null && rowIds.has(d)))
1759
+ };
1760
+ });
1761
+ };
1762
+ row.getCanPin = () => {
1763
+ var _ref4;
1764
+ const {
1765
+ enableRowPinning,
1766
+ enablePinning
1767
+ } = table.options;
1768
+ if (typeof enableRowPinning === 'function') {
1769
+ return enableRowPinning(row);
1770
+ }
1771
+ return (_ref4 = enableRowPinning != null ? enableRowPinning : enablePinning) != null ? _ref4 : true;
1772
+ };
1773
+ row.getIsPinned = () => {
1774
+ const rowIds = [row.id];
1775
+ const {
1776
+ top,
1777
+ bottom
1778
+ } = table.getState().rowPinning;
1779
+ const isTop = rowIds.some(d => top == null ? void 0 : top.includes(d));
1780
+ const isBottom = rowIds.some(d => bottom == null ? void 0 : bottom.includes(d));
1781
+ return isTop ? 'top' : isBottom ? 'bottom' : false;
1782
+ };
1783
+ row.getPinnedIndex = () => {
1784
+ var _table$_getPinnedRows, _visiblePinnedRowIds$;
1785
+ const position = row.getIsPinned();
1786
+ if (!position) return -1;
1787
+ const visiblePinnedRowIds = (_table$_getPinnedRows = table._getPinnedRows(position)) == null ? void 0 : _table$_getPinnedRows.map(_ref5 => {
1788
+ let {
1789
+ id
1790
+ } = _ref5;
1791
+ return id;
1792
+ });
1793
+ return (_visiblePinnedRowIds$ = visiblePinnedRowIds == null ? void 0 : visiblePinnedRowIds.indexOf(row.id)) != null ? _visiblePinnedRowIds$ : -1;
1794
+ };
1711
1795
  row.getCenterVisibleCells = memo(() => [row._getAllVisibleCells(), table.getState().columnPinning.left, table.getState().columnPinning.right], (allCells, left, right) => {
1712
1796
  const leftAndRight = [...(left != null ? left : []), ...(right != null ? right : [])];
1713
1797
  return allCells.filter(d => !leftAndRight.includes(d.column.id));
1714
1798
  }, {
1715
- key: "development" === 'production' ,
1799
+ key: 'row.getCenterVisibleCells',
1716
1800
  debug: () => {
1717
1801
  var _table$options$debugA;
1718
1802
  return (_table$options$debugA = table.options.debugAll) != null ? _table$options$debugA : table.options.debugRows;
@@ -1725,7 +1809,7 @@
1725
1809
  }));
1726
1810
  return cells;
1727
1811
  }, {
1728
- key: "development" === 'production' ,
1812
+ key: 'row.getLeftVisibleCells',
1729
1813
  debug: () => {
1730
1814
  var _table$options$debugA2;
1731
1815
  return (_table$options$debugA2 = table.options.debugAll) != null ? _table$options$debugA2 : table.options.debugRows;
@@ -1738,7 +1822,7 @@
1738
1822
  }));
1739
1823
  return cells;
1740
1824
  }, {
1741
- key: "development" === 'production' ,
1825
+ key: 'row.getRightVisibleCells',
1742
1826
  debug: () => {
1743
1827
  var _table$options$debugA3;
1744
1828
  return (_table$options$debugA3 = table.options.debugAll) != null ? _table$options$debugA3 : table.options.debugRows;
@@ -1749,7 +1833,7 @@
1749
1833
  table.setColumnPinning = updater => table.options.onColumnPinningChange == null ? void 0 : table.options.onColumnPinningChange(updater);
1750
1834
  table.resetColumnPinning = defaultState => {
1751
1835
  var _table$initialState$c, _table$initialState;
1752
- return table.setColumnPinning(defaultState ? getDefaultPinningState() : (_table$initialState$c = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.columnPinning) != null ? _table$initialState$c : getDefaultPinningState());
1836
+ return table.setColumnPinning(defaultState ? getDefaultColumnPinningState() : (_table$initialState$c = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.columnPinning) != null ? _table$initialState$c : getDefaultColumnPinningState());
1753
1837
  };
1754
1838
  table.getIsSomeColumnsPinned = position => {
1755
1839
  var _pinningState$positio;
@@ -1788,6 +1872,54 @@
1788
1872
  return (_table$options$debugA6 = table.options.debugAll) != null ? _table$options$debugA6 : table.options.debugColumns;
1789
1873
  }
1790
1874
  });
1875
+ table.setRowPinning = updater => table.options.onRowPinningChange == null ? void 0 : table.options.onRowPinningChange(updater);
1876
+ table.resetRowPinning = defaultState => {
1877
+ var _table$initialState$r, _table$initialState2;
1878
+ return table.setRowPinning(defaultState ? getDefaultRowPinningState() : (_table$initialState$r = (_table$initialState2 = table.initialState) == null ? void 0 : _table$initialState2.rowPinning) != null ? _table$initialState$r : getDefaultRowPinningState());
1879
+ };
1880
+ table.getIsSomeRowsPinned = position => {
1881
+ var _pinningState$positio2;
1882
+ const pinningState = table.getState().rowPinning;
1883
+ if (!position) {
1884
+ var _pinningState$top, _pinningState$bottom;
1885
+ return Boolean(((_pinningState$top = pinningState.top) == null ? void 0 : _pinningState$top.length) || ((_pinningState$bottom = pinningState.bottom) == null ? void 0 : _pinningState$bottom.length));
1886
+ }
1887
+ return Boolean((_pinningState$positio2 = pinningState[position]) == null ? void 0 : _pinningState$positio2.length);
1888
+ };
1889
+ table._getPinnedRows = position => memo(() => [table.getRowModel().rows, table.getState().rowPinning[position]], (visibleRows, pinnedRowIds) => {
1890
+ var _table$options$keepPi;
1891
+ const rows = ((_table$options$keepPi = table.options.keepPinnedRows) != null ? _table$options$keepPi : true) ?
1892
+ //get all rows that are pinned even if they would not be otherwise visible
1893
+ //account for expanded parent rows, but not pagination or filtering
1894
+ (pinnedRowIds != null ? pinnedRowIds : []).map(rowId => {
1895
+ const row = table.getRow(rowId, true);
1896
+ return row.getIsAllParentsExpanded() ? row : null;
1897
+ }) :
1898
+ //else get only visible rows that are pinned
1899
+ (pinnedRowIds != null ? pinnedRowIds : []).map(rowId => visibleRows.find(row => row.id === rowId));
1900
+ return rows.filter(Boolean).map(d => ({
1901
+ ...d,
1902
+ position
1903
+ }));
1904
+ }, {
1905
+ key: `row.get${position === 'top' ? 'Top' : 'Bottom'}Rows`,
1906
+ debug: () => {
1907
+ var _table$options$debugA7;
1908
+ return (_table$options$debugA7 = table.options.debugAll) != null ? _table$options$debugA7 : table.options.debugRows;
1909
+ }
1910
+ })();
1911
+ table.getTopRows = () => table._getPinnedRows('top');
1912
+ table.getBottomRows = () => table._getPinnedRows('bottom');
1913
+ table.getCenterRows = memo(() => [table.getRowModel().rows, table.getState().rowPinning.top, table.getState().rowPinning.bottom], (allRows, top, bottom) => {
1914
+ const topAndBottom = new Set([...(top != null ? top : []), ...(bottom != null ? bottom : [])]);
1915
+ return allRows.filter(d => !topAndBottom.has(d.id));
1916
+ }, {
1917
+ key: 'row.getCenterRows',
1918
+ debug: () => {
1919
+ var _table$options$debugA8;
1920
+ return (_table$options$debugA8 = table.options.debugAll) != null ? _table$options$debugA8 : table.options.debugRows;
1921
+ }
1922
+ });
1791
1923
  }
1792
1924
  };
1793
1925
 
@@ -2679,8 +2811,8 @@
2679
2811
  getRowModel: () => {
2680
2812
  return table.getPaginationRowModel();
2681
2813
  },
2682
- getRow: id => {
2683
- const row = table.getRowModel().rowsById[id];
2814
+ getRow: (id, searchAll) => {
2815
+ const row = (searchAll ? table.getCoreRowModel() : table.getRowModel()).rowsById[id];
2684
2816
  if (!row) {
2685
2817
  {
2686
2818
  throw new Error(`getRow expected an ID, but got ${id}`);