@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.
- package/build/lib/core/table.d.ts +1 -1
- package/build/lib/core/table.js +2 -2
- package/build/lib/core/table.js.map +1 -1
- package/build/lib/features/Expanding.d.ts +1 -0
- package/build/lib/features/Expanding.js +9 -0
- package/build/lib/features/Expanding.js.map +1 -1
- package/build/lib/features/Pinning.d.ts +33 -1
- package/build/lib/features/Pinning.js +132 -9
- package/build/lib/features/Pinning.js.map +1 -1
- package/build/lib/index.esm.js +143 -11
- package/build/lib/index.esm.js.map +1 -1
- package/build/lib/index.mjs +143 -11
- package/build/lib/index.mjs.map +1 -1
- package/build/lib/types.d.ts +6 -6
- package/build/umd/index.development.js +143 -11
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/core/table.ts +11 -7
- package/src/features/Expanding.ts +12 -0
- package/src/features/Pinning.ts +194 -12
- package/src/types.ts +9 -0
package/build/lib/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CoreOptions, CoreTableState, CoreInstance } from './core/table';
|
|
2
2
|
import { VisibilityInstance, VisibilityTableState, VisibilityColumn as ColumnVisibilityColumn, VisibilityOptions, VisibilityColumnDef, VisibilityRow } from './features/Visibility';
|
|
3
3
|
import { ColumnOrderInstance, ColumnOrderOptions, ColumnOrderTableState } from './features/Ordering';
|
|
4
|
-
import { ColumnPinningColumn, ColumnPinningColumnDef, ColumnPinningInstance, ColumnPinningOptions, ColumnPinningRow, ColumnPinningTableState } from './features/Pinning';
|
|
4
|
+
import { ColumnPinningColumn, ColumnPinningColumnDef, ColumnPinningInstance, ColumnPinningOptions, ColumnPinningRow, ColumnPinningTableState, RowPinningInstance, RowPinningOptions, RowPinningRow, RowPinningTableState } from './features/Pinning';
|
|
5
5
|
import { CoreHeader, CoreHeaderGroup, HeaderContext, HeadersInstance } from './core/headers';
|
|
6
6
|
import { FiltersColumn, FiltersColumnDef, FiltersInstance, FiltersOptions, FiltersRow, FiltersTableState } from './features/Filters';
|
|
7
7
|
import { SortingColumn, SortingColumnDef, SortingInstance, SortingOptions, SortingTableState } from './features/Sorting';
|
|
@@ -30,20 +30,20 @@ export type Updater<T> = T | ((old: T) => T);
|
|
|
30
30
|
export type OnChangeFn<T> = (updaterOrValue: Updater<T>) => void;
|
|
31
31
|
export type RowData = unknown | object | any[];
|
|
32
32
|
export type AnyRender = (Comp: any, props: any) => any;
|
|
33
|
-
export interface Table<TData extends RowData> extends CoreInstance<TData>, HeadersInstance<TData>, VisibilityInstance<TData>, ColumnOrderInstance<TData>, ColumnPinningInstance<TData>, FiltersInstance<TData>, SortingInstance<TData>, GroupingInstance<TData>, ColumnSizingInstance, ExpandedInstance<TData>, PaginationInstance<TData>, RowSelectionInstance<TData> {
|
|
33
|
+
export interface Table<TData extends RowData> extends CoreInstance<TData>, HeadersInstance<TData>, VisibilityInstance<TData>, ColumnOrderInstance<TData>, ColumnPinningInstance<TData>, RowPinningInstance<TData>, FiltersInstance<TData>, SortingInstance<TData>, GroupingInstance<TData>, ColumnSizingInstance, ExpandedInstance<TData>, PaginationInstance<TData>, RowSelectionInstance<TData> {
|
|
34
34
|
}
|
|
35
|
-
interface FeatureOptions<TData extends RowData> extends VisibilityOptions, ColumnOrderOptions, ColumnPinningOptions, FiltersOptions<TData>, SortingOptions<TData>, GroupingOptions, ExpandedOptions<TData>, ColumnSizingOptions, PaginationOptions, RowSelectionOptions<TData> {
|
|
35
|
+
interface FeatureOptions<TData extends RowData> extends VisibilityOptions, ColumnOrderOptions, ColumnPinningOptions, RowPinningOptions<TData>, FiltersOptions<TData>, SortingOptions<TData>, GroupingOptions, ExpandedOptions<TData>, ColumnSizingOptions, PaginationOptions, RowSelectionOptions<TData> {
|
|
36
36
|
}
|
|
37
37
|
export type TableOptionsResolved<TData extends RowData> = CoreOptions<TData> & FeatureOptions<TData>;
|
|
38
38
|
export interface TableOptions<TData extends RowData> extends PartialKeys<TableOptionsResolved<TData>, 'state' | 'onStateChange' | 'renderFallbackValue'> {
|
|
39
39
|
}
|
|
40
|
-
export interface TableState extends CoreTableState, VisibilityTableState, ColumnOrderTableState, ColumnPinningTableState, FiltersTableState, SortingTableState, ExpandedTableState, GroupingTableState, ColumnSizingTableState, PaginationTableState, RowSelectionTableState {
|
|
40
|
+
export interface TableState extends CoreTableState, VisibilityTableState, ColumnOrderTableState, ColumnPinningTableState, RowPinningTableState, FiltersTableState, SortingTableState, ExpandedTableState, GroupingTableState, ColumnSizingTableState, PaginationTableState, RowSelectionTableState {
|
|
41
41
|
}
|
|
42
|
-
interface CompleteInitialTableState extends CoreTableState, VisibilityTableState, ColumnOrderTableState, ColumnPinningTableState, FiltersTableState, SortingTableState, ExpandedTableState, GroupingTableState, ColumnSizingTableState, PaginationInitialTableState, RowSelectionTableState {
|
|
42
|
+
interface CompleteInitialTableState extends CoreTableState, VisibilityTableState, ColumnOrderTableState, ColumnPinningTableState, RowPinningTableState, FiltersTableState, SortingTableState, ExpandedTableState, GroupingTableState, ColumnSizingTableState, PaginationInitialTableState, RowSelectionTableState {
|
|
43
43
|
}
|
|
44
44
|
export interface InitialTableState extends Partial<CompleteInitialTableState> {
|
|
45
45
|
}
|
|
46
|
-
export interface Row<TData extends RowData> extends CoreRow<TData>, VisibilityRow<TData>, ColumnPinningRow<TData>, FiltersRow<TData>, GroupingRow, RowSelectionRow, ExpandedRow {
|
|
46
|
+
export interface Row<TData extends RowData> extends CoreRow<TData>, VisibilityRow<TData>, ColumnPinningRow<TData>, RowPinningRow, FiltersRow<TData>, GroupingRow, RowSelectionRow, ExpandedRow {
|
|
47
47
|
}
|
|
48
48
|
export interface RowModel<TData extends RowData> {
|
|
49
49
|
rows: Row<TData>[];
|
|
@@ -910,6 +910,15 @@
|
|
|
910
910
|
var _table$options$getRow, _table$options$enable, _row$subRows;
|
|
911
911
|
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);
|
|
912
912
|
};
|
|
913
|
+
row.getIsAllParentsExpanded = () => {
|
|
914
|
+
let isFullyExpanded = true;
|
|
915
|
+
let currentRow = row;
|
|
916
|
+
while (isFullyExpanded && currentRow.parentId) {
|
|
917
|
+
currentRow = table.getRow(currentRow.parentId, true);
|
|
918
|
+
isFullyExpanded = currentRow.getIsExpanded();
|
|
919
|
+
}
|
|
920
|
+
return isFullyExpanded;
|
|
921
|
+
};
|
|
913
922
|
row.getToggleExpandedHandler = () => {
|
|
914
923
|
const canExpand = row.getCanExpand();
|
|
915
924
|
return () => {
|
|
@@ -1633,20 +1642,26 @@
|
|
|
1633
1642
|
|
|
1634
1643
|
//
|
|
1635
1644
|
|
|
1636
|
-
const
|
|
1645
|
+
const getDefaultColumnPinningState = () => ({
|
|
1637
1646
|
left: [],
|
|
1638
1647
|
right: []
|
|
1639
1648
|
});
|
|
1649
|
+
const getDefaultRowPinningState = () => ({
|
|
1650
|
+
top: [],
|
|
1651
|
+
bottom: []
|
|
1652
|
+
});
|
|
1640
1653
|
const Pinning = {
|
|
1641
1654
|
getInitialState: state => {
|
|
1642
1655
|
return {
|
|
1643
|
-
columnPinning:
|
|
1656
|
+
columnPinning: getDefaultColumnPinningState(),
|
|
1657
|
+
rowPinning: getDefaultRowPinningState(),
|
|
1644
1658
|
...state
|
|
1645
1659
|
};
|
|
1646
1660
|
},
|
|
1647
1661
|
getDefaultOptions: table => {
|
|
1648
1662
|
return {
|
|
1649
|
-
onColumnPinningChange: makeStateUpdater('columnPinning', table)
|
|
1663
|
+
onColumnPinningChange: makeStateUpdater('columnPinning', table),
|
|
1664
|
+
onRowPinningChange: makeStateUpdater('rowPinning', table)
|
|
1650
1665
|
};
|
|
1651
1666
|
},
|
|
1652
1667
|
createColumn: (column, table) => {
|
|
@@ -1677,8 +1692,8 @@
|
|
|
1677
1692
|
column.getCanPin = () => {
|
|
1678
1693
|
const leafColumns = column.getLeafColumns();
|
|
1679
1694
|
return leafColumns.some(d => {
|
|
1680
|
-
var _d$columnDef$enablePi, _table$options$enable;
|
|
1681
|
-
return ((_d$columnDef$enablePi = d.columnDef.enablePinning) != null ? _d$columnDef$enablePi : true) && ((_table$options$enable = table.options.
|
|
1695
|
+
var _d$columnDef$enablePi, _ref, _table$options$enable;
|
|
1696
|
+
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);
|
|
1682
1697
|
});
|
|
1683
1698
|
};
|
|
1684
1699
|
column.getIsPinned = () => {
|
|
@@ -1698,11 +1713,80 @@
|
|
|
1698
1713
|
};
|
|
1699
1714
|
},
|
|
1700
1715
|
createRow: (row, table) => {
|
|
1716
|
+
row.pin = (position, includeLeafRows, includeParentRows) => {
|
|
1717
|
+
const leafRowIds = includeLeafRows ? row.getLeafRows().map(_ref2 => {
|
|
1718
|
+
let {
|
|
1719
|
+
id
|
|
1720
|
+
} = _ref2;
|
|
1721
|
+
return id;
|
|
1722
|
+
}) : [];
|
|
1723
|
+
const parentRowIds = includeParentRows ? row.getParentRows().map(_ref3 => {
|
|
1724
|
+
let {
|
|
1725
|
+
id
|
|
1726
|
+
} = _ref3;
|
|
1727
|
+
return id;
|
|
1728
|
+
}) : [];
|
|
1729
|
+
const rowIds = new Set([...parentRowIds, row.id, ...leafRowIds]);
|
|
1730
|
+
table.setRowPinning(old => {
|
|
1731
|
+
var _old$top3, _old$bottom3;
|
|
1732
|
+
if (position === 'bottom') {
|
|
1733
|
+
var _old$top, _old$bottom;
|
|
1734
|
+
return {
|
|
1735
|
+
top: ((_old$top = old == null ? void 0 : old.top) != null ? _old$top : []).filter(d => !(rowIds != null && rowIds.has(d))),
|
|
1736
|
+
bottom: [...((_old$bottom = old == null ? void 0 : old.bottom) != null ? _old$bottom : []).filter(d => !(rowIds != null && rowIds.has(d))), ...Array.from(rowIds)]
|
|
1737
|
+
};
|
|
1738
|
+
}
|
|
1739
|
+
if (position === 'top') {
|
|
1740
|
+
var _old$top2, _old$bottom2;
|
|
1741
|
+
return {
|
|
1742
|
+
top: [...((_old$top2 = old == null ? void 0 : old.top) != null ? _old$top2 : []).filter(d => !(rowIds != null && rowIds.has(d))), ...Array.from(rowIds)],
|
|
1743
|
+
bottom: ((_old$bottom2 = old == null ? void 0 : old.bottom) != null ? _old$bottom2 : []).filter(d => !(rowIds != null && rowIds.has(d)))
|
|
1744
|
+
};
|
|
1745
|
+
}
|
|
1746
|
+
return {
|
|
1747
|
+
top: ((_old$top3 = old == null ? void 0 : old.top) != null ? _old$top3 : []).filter(d => !(rowIds != null && rowIds.has(d))),
|
|
1748
|
+
bottom: ((_old$bottom3 = old == null ? void 0 : old.bottom) != null ? _old$bottom3 : []).filter(d => !(rowIds != null && rowIds.has(d)))
|
|
1749
|
+
};
|
|
1750
|
+
});
|
|
1751
|
+
};
|
|
1752
|
+
row.getCanPin = () => {
|
|
1753
|
+
var _ref4;
|
|
1754
|
+
const {
|
|
1755
|
+
enableRowPinning,
|
|
1756
|
+
enablePinning
|
|
1757
|
+
} = table.options;
|
|
1758
|
+
if (typeof enableRowPinning === 'function') {
|
|
1759
|
+
return enableRowPinning(row);
|
|
1760
|
+
}
|
|
1761
|
+
return (_ref4 = enableRowPinning != null ? enableRowPinning : enablePinning) != null ? _ref4 : true;
|
|
1762
|
+
};
|
|
1763
|
+
row.getIsPinned = () => {
|
|
1764
|
+
const rowIds = [row.id];
|
|
1765
|
+
const {
|
|
1766
|
+
top,
|
|
1767
|
+
bottom
|
|
1768
|
+
} = table.getState().rowPinning;
|
|
1769
|
+
const isTop = rowIds.some(d => top == null ? void 0 : top.includes(d));
|
|
1770
|
+
const isBottom = rowIds.some(d => bottom == null ? void 0 : bottom.includes(d));
|
|
1771
|
+
return isTop ? 'top' : isBottom ? 'bottom' : false;
|
|
1772
|
+
};
|
|
1773
|
+
row.getPinnedIndex = () => {
|
|
1774
|
+
var _table$_getPinnedRows, _visiblePinnedRowIds$;
|
|
1775
|
+
const position = row.getIsPinned();
|
|
1776
|
+
if (!position) return -1;
|
|
1777
|
+
const visiblePinnedRowIds = (_table$_getPinnedRows = table._getPinnedRows(position)) == null ? void 0 : _table$_getPinnedRows.map(_ref5 => {
|
|
1778
|
+
let {
|
|
1779
|
+
id
|
|
1780
|
+
} = _ref5;
|
|
1781
|
+
return id;
|
|
1782
|
+
});
|
|
1783
|
+
return (_visiblePinnedRowIds$ = visiblePinnedRowIds == null ? void 0 : visiblePinnedRowIds.indexOf(row.id)) != null ? _visiblePinnedRowIds$ : -1;
|
|
1784
|
+
};
|
|
1701
1785
|
row.getCenterVisibleCells = memo(() => [row._getAllVisibleCells(), table.getState().columnPinning.left, table.getState().columnPinning.right], (allCells, left, right) => {
|
|
1702
1786
|
const leftAndRight = [...(left != null ? left : []), ...(right != null ? right : [])];
|
|
1703
1787
|
return allCells.filter(d => !leftAndRight.includes(d.column.id));
|
|
1704
1788
|
}, {
|
|
1705
|
-
key:
|
|
1789
|
+
key: 'row.getCenterVisibleCells',
|
|
1706
1790
|
debug: () => {
|
|
1707
1791
|
var _table$options$debugA;
|
|
1708
1792
|
return (_table$options$debugA = table.options.debugAll) != null ? _table$options$debugA : table.options.debugRows;
|
|
@@ -1715,7 +1799,7 @@
|
|
|
1715
1799
|
}));
|
|
1716
1800
|
return cells;
|
|
1717
1801
|
}, {
|
|
1718
|
-
key:
|
|
1802
|
+
key: 'row.getLeftVisibleCells',
|
|
1719
1803
|
debug: () => {
|
|
1720
1804
|
var _table$options$debugA2;
|
|
1721
1805
|
return (_table$options$debugA2 = table.options.debugAll) != null ? _table$options$debugA2 : table.options.debugRows;
|
|
@@ -1728,7 +1812,7 @@
|
|
|
1728
1812
|
}));
|
|
1729
1813
|
return cells;
|
|
1730
1814
|
}, {
|
|
1731
|
-
key:
|
|
1815
|
+
key: 'row.getRightVisibleCells',
|
|
1732
1816
|
debug: () => {
|
|
1733
1817
|
var _table$options$debugA3;
|
|
1734
1818
|
return (_table$options$debugA3 = table.options.debugAll) != null ? _table$options$debugA3 : table.options.debugRows;
|
|
@@ -1739,7 +1823,7 @@
|
|
|
1739
1823
|
table.setColumnPinning = updater => table.options.onColumnPinningChange == null ? void 0 : table.options.onColumnPinningChange(updater);
|
|
1740
1824
|
table.resetColumnPinning = defaultState => {
|
|
1741
1825
|
var _table$initialState$c, _table$initialState;
|
|
1742
|
-
return table.setColumnPinning(defaultState ?
|
|
1826
|
+
return table.setColumnPinning(defaultState ? getDefaultColumnPinningState() : (_table$initialState$c = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.columnPinning) != null ? _table$initialState$c : getDefaultColumnPinningState());
|
|
1743
1827
|
};
|
|
1744
1828
|
table.getIsSomeColumnsPinned = position => {
|
|
1745
1829
|
var _pinningState$positio;
|
|
@@ -1778,6 +1862,54 @@
|
|
|
1778
1862
|
return (_table$options$debugA6 = table.options.debugAll) != null ? _table$options$debugA6 : table.options.debugColumns;
|
|
1779
1863
|
}
|
|
1780
1864
|
});
|
|
1865
|
+
table.setRowPinning = updater => table.options.onRowPinningChange == null ? void 0 : table.options.onRowPinningChange(updater);
|
|
1866
|
+
table.resetRowPinning = defaultState => {
|
|
1867
|
+
var _table$initialState$r, _table$initialState2;
|
|
1868
|
+
return table.setRowPinning(defaultState ? getDefaultRowPinningState() : (_table$initialState$r = (_table$initialState2 = table.initialState) == null ? void 0 : _table$initialState2.rowPinning) != null ? _table$initialState$r : getDefaultRowPinningState());
|
|
1869
|
+
};
|
|
1870
|
+
table.getIsSomeRowsPinned = position => {
|
|
1871
|
+
var _pinningState$positio2;
|
|
1872
|
+
const pinningState = table.getState().rowPinning;
|
|
1873
|
+
if (!position) {
|
|
1874
|
+
var _pinningState$top, _pinningState$bottom;
|
|
1875
|
+
return Boolean(((_pinningState$top = pinningState.top) == null ? void 0 : _pinningState$top.length) || ((_pinningState$bottom = pinningState.bottom) == null ? void 0 : _pinningState$bottom.length));
|
|
1876
|
+
}
|
|
1877
|
+
return Boolean((_pinningState$positio2 = pinningState[position]) == null ? void 0 : _pinningState$positio2.length);
|
|
1878
|
+
};
|
|
1879
|
+
table._getPinnedRows = position => memo(() => [table.getRowModel().rows, table.getState().rowPinning[position]], (visibleRows, pinnedRowIds) => {
|
|
1880
|
+
var _table$options$keepPi;
|
|
1881
|
+
const rows = ((_table$options$keepPi = table.options.keepPinnedRows) != null ? _table$options$keepPi : true) ?
|
|
1882
|
+
//get all rows that are pinned even if they would not be otherwise visible
|
|
1883
|
+
//account for expanded parent rows, but not pagination or filtering
|
|
1884
|
+
(pinnedRowIds != null ? pinnedRowIds : []).map(rowId => {
|
|
1885
|
+
const row = table.getRow(rowId, true);
|
|
1886
|
+
return row.getIsAllParentsExpanded() ? row : null;
|
|
1887
|
+
}) :
|
|
1888
|
+
//else get only visible rows that are pinned
|
|
1889
|
+
(pinnedRowIds != null ? pinnedRowIds : []).map(rowId => visibleRows.find(row => row.id === rowId));
|
|
1890
|
+
return rows.filter(Boolean).map(d => ({
|
|
1891
|
+
...d,
|
|
1892
|
+
position
|
|
1893
|
+
}));
|
|
1894
|
+
}, {
|
|
1895
|
+
key: `row.get${position === 'top' ? 'Top' : 'Bottom'}Rows`,
|
|
1896
|
+
debug: () => {
|
|
1897
|
+
var _table$options$debugA7;
|
|
1898
|
+
return (_table$options$debugA7 = table.options.debugAll) != null ? _table$options$debugA7 : table.options.debugRows;
|
|
1899
|
+
}
|
|
1900
|
+
})();
|
|
1901
|
+
table.getTopRows = () => table._getPinnedRows('top');
|
|
1902
|
+
table.getBottomRows = () => table._getPinnedRows('bottom');
|
|
1903
|
+
table.getCenterRows = memo(() => [table.getRowModel().rows, table.getState().rowPinning.top, table.getState().rowPinning.bottom], (allRows, top, bottom) => {
|
|
1904
|
+
const topAndBottom = new Set([...(top != null ? top : []), ...(bottom != null ? bottom : [])]);
|
|
1905
|
+
return allRows.filter(d => !topAndBottom.has(d.id));
|
|
1906
|
+
}, {
|
|
1907
|
+
key: 'row.getCenterRows',
|
|
1908
|
+
debug: () => {
|
|
1909
|
+
var _table$options$debugA8;
|
|
1910
|
+
return (_table$options$debugA8 = table.options.debugAll) != null ? _table$options$debugA8 : table.options.debugRows;
|
|
1911
|
+
}
|
|
1912
|
+
});
|
|
1781
1913
|
}
|
|
1782
1914
|
};
|
|
1783
1915
|
|
|
@@ -2669,8 +2801,8 @@
|
|
|
2669
2801
|
getRowModel: () => {
|
|
2670
2802
|
return table.getPaginationRowModel();
|
|
2671
2803
|
},
|
|
2672
|
-
getRow: id => {
|
|
2673
|
-
const row = table.getRowModel().rowsById[id];
|
|
2804
|
+
getRow: (id, searchAll) => {
|
|
2805
|
+
const row = (searchAll ? table.getCoreRowModel() : table.getRowModel()).rowsById[id];
|
|
2674
2806
|
if (!row) {
|
|
2675
2807
|
{
|
|
2676
2808
|
throw new Error(`getRow expected an ID, but got ${id}`);
|