@tanstack/table-core 8.19.2 → 9.0.0-alpha.10
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/aggregationFns.cjs +94 -0
- package/dist/cjs/aggregationFns.cjs.map +1 -0
- package/dist/cjs/aggregationFns.d.cts +14 -0
- package/dist/cjs/columnHelper.cjs +19 -0
- package/dist/cjs/columnHelper.cjs.map +1 -0
- package/dist/cjs/columnHelper.d.cts +9 -0
- package/dist/cjs/core/cell.cjs +38 -0
- package/dist/cjs/core/cell.cjs.map +1 -0
- package/dist/cjs/core/cell.d.cts +50 -0
- package/dist/cjs/core/column.cjs +81 -0
- package/dist/cjs/core/column.cjs.map +1 -0
- package/dist/cjs/core/column.d.cts +56 -0
- package/dist/cjs/core/headers.cjs +310 -0
- package/dist/cjs/core/headers.cjs.map +1 -0
- package/dist/cjs/core/headers.d.cts +195 -0
- package/dist/cjs/core/row.cjs +92 -0
- package/dist/cjs/core/row.cjs.map +1 -0
- package/dist/cjs/core/row.d.cts +92 -0
- package/dist/cjs/core/table.cjs +232 -0
- package/dist/cjs/core/table.cjs.map +1 -0
- package/dist/cjs/core/table.d.cts +229 -0
- package/dist/cjs/features/ColumnFaceting.cjs +29 -0
- package/dist/cjs/features/ColumnFaceting.cjs.map +1 -0
- package/dist/cjs/features/ColumnFaceting.d.cts +35 -0
- package/dist/cjs/features/ColumnFiltering.cjs +137 -0
- package/dist/cjs/features/ColumnFiltering.cjs.map +1 -0
- package/dist/cjs/features/ColumnFiltering.d.cts +195 -0
- package/dist/cjs/features/ColumnGrouping.cjs +133 -0
- package/dist/cjs/features/ColumnGrouping.cjs.map +1 -0
- package/dist/cjs/features/ColumnGrouping.d.cts +202 -0
- package/dist/cjs/features/ColumnOrdering.cjs +76 -0
- package/dist/cjs/features/ColumnOrdering.cjs.map +1 -0
- package/dist/cjs/features/ColumnOrdering.d.cts +54 -0
- package/dist/cjs/features/ColumnPinning.cjs +145 -0
- package/dist/cjs/features/ColumnPinning.cjs.map +1 -0
- package/dist/cjs/features/ColumnPinning.d.cts +127 -0
- package/dist/cjs/features/ColumnSizing.cjs +307 -0
- package/dist/cjs/features/ColumnSizing.cjs.map +1 -0
- package/dist/cjs/features/ColumnSizing.d.cts +194 -0
- package/dist/cjs/features/ColumnVisibility.cjs +144 -0
- package/dist/cjs/features/ColumnVisibility.cjs.map +1 -0
- package/dist/cjs/features/ColumnVisibility.d.cts +130 -0
- package/dist/cjs/features/GlobalFaceting.cjs +29 -0
- package/dist/cjs/features/GlobalFaceting.cjs.map +1 -0
- package/dist/cjs/features/GlobalFaceting.d.cts +27 -0
- package/dist/cjs/features/GlobalFiltering.cjs +50 -0
- package/dist/cjs/features/GlobalFiltering.cjs.map +1 -0
- package/dist/cjs/features/GlobalFiltering.d.cts +80 -0
- package/dist/cjs/features/RowExpanding.cjs +152 -0
- package/dist/cjs/features/RowExpanding.cjs.map +1 -0
- package/dist/cjs/features/RowExpanding.d.cts +155 -0
- package/dist/cjs/features/RowPagination.cjs +161 -0
- package/dist/cjs/features/RowPagination.cjs.map +1 -0
- package/dist/cjs/features/RowPagination.d.cts +166 -0
- package/dist/cjs/features/RowPinning.cjs +132 -0
- package/dist/cjs/features/RowPinning.cjs.map +1 -0
- package/dist/cjs/features/RowPinning.d.cts +99 -0
- package/dist/cjs/features/RowSelection.cjs +296 -0
- package/dist/cjs/features/RowSelection.cjs.map +1 -0
- package/dist/cjs/features/RowSelection.d.cts +177 -0
- package/dist/cjs/features/RowSorting.cjs +200 -0
- package/dist/cjs/features/RowSorting.cjs.map +1 -0
- package/dist/cjs/features/RowSorting.d.cts +238 -0
- package/dist/cjs/filterFns.cjs +88 -0
- package/dist/cjs/filterFns.cjs.map +1 -0
- package/dist/cjs/filterFns.d.cts +14 -0
- package/{build/lib/index.js → dist/cjs/index.cjs} +41 -53
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +34 -0
- package/{build/lib/sortingFns.js → dist/cjs/sortingFns.cjs} +23 -52
- package/dist/cjs/sortingFns.cjs.map +1 -0
- package/dist/cjs/sortingFns.d.cts +12 -0
- package/dist/cjs/types.d.cts +120 -0
- package/{build/lib/utils/filterRowsUtils.js → dist/cjs/utils/filterRowsUtils.cjs} +34 -46
- package/dist/cjs/utils/filterRowsUtils.cjs.map +1 -0
- package/dist/cjs/utils/filterRowsUtils.d.cts +3 -0
- package/dist/cjs/utils/getCoreRowModel.cjs +54 -0
- package/dist/cjs/utils/getCoreRowModel.cjs.map +1 -0
- package/dist/cjs/utils/getCoreRowModel.d.cts +3 -0
- package/dist/cjs/utils/getExpandedRowModel.cjs +41 -0
- package/dist/cjs/utils/getExpandedRowModel.cjs.map +1 -0
- package/dist/cjs/utils/getExpandedRowModel.d.cts +8 -0
- package/dist/cjs/utils/getFacetedMinMaxValues.cjs +35 -0
- package/dist/cjs/utils/getFacetedMinMaxValues.cjs.map +1 -0
- package/dist/cjs/utils/getFacetedMinMaxValues.d.cts +3 -0
- package/dist/cjs/utils/getFacetedRowModel.cjs +35 -0
- package/dist/cjs/utils/getFacetedRowModel.cjs.map +1 -0
- package/dist/cjs/utils/getFacetedRowModel.d.cts +3 -0
- package/dist/cjs/utils/getFacetedUniqueValues.cjs +37 -0
- package/dist/cjs/utils/getFacetedUniqueValues.cjs.map +1 -0
- package/dist/cjs/utils/getFacetedUniqueValues.d.cts +3 -0
- package/dist/cjs/utils/getFilteredRowModel.cjs +116 -0
- package/dist/cjs/utils/getFilteredRowModel.cjs.map +1 -0
- package/dist/cjs/utils/getFilteredRowModel.d.cts +3 -0
- package/dist/cjs/utils/getGroupedRowModel.cjs +118 -0
- package/dist/cjs/utils/getGroupedRowModel.cjs.map +1 -0
- package/dist/cjs/utils/getGroupedRowModel.d.cts +3 -0
- package/dist/cjs/utils/getPaginationRowModel.cjs +49 -0
- package/dist/cjs/utils/getPaginationRowModel.cjs.map +1 -0
- package/dist/cjs/utils/getPaginationRowModel.d.cts +5 -0
- package/dist/cjs/utils/getSortedRowModel.cjs +88 -0
- package/dist/cjs/utils/getSortedRowModel.cjs.map +1 -0
- package/dist/cjs/utils/getSortedRowModel.d.cts +3 -0
- package/{build/lib/utils.js → dist/cjs/utils.cjs} +26 -39
- package/dist/cjs/utils.cjs.map +1 -0
- package/dist/cjs/utils.d.cts +39 -0
- package/{build/lib → dist/esm}/aggregationFns.d.ts +2 -1
- package/dist/esm/aggregationFns.js +94 -0
- package/dist/esm/aggregationFns.js.map +1 -0
- package/{build/lib → dist/esm}/columnHelper.d.ts +3 -2
- package/dist/esm/columnHelper.js +19 -0
- package/{build/lib → dist/esm}/columnHelper.js.map +1 -1
- package/{build/lib → dist/esm}/core/cell.d.ts +2 -1
- package/dist/esm/core/cell.js +38 -0
- package/dist/esm/core/cell.js.map +1 -0
- package/{build/lib → dist/esm}/core/column.d.ts +2 -1
- package/dist/esm/core/column.js +81 -0
- package/dist/esm/core/column.js.map +1 -0
- package/{build/lib → dist/esm}/core/headers.d.ts +1 -0
- package/dist/esm/core/headers.js +310 -0
- package/dist/esm/core/headers.js.map +1 -0
- package/{build/lib → dist/esm}/core/row.d.ts +2 -1
- package/dist/esm/core/row.js +92 -0
- package/dist/esm/core/row.js.map +1 -0
- package/{build/lib → dist/esm}/core/table.d.ts +10 -1
- package/dist/esm/core/table.js +232 -0
- package/dist/esm/core/table.js.map +1 -0
- package/{build/lib → dist/esm}/features/ColumnFaceting.d.ts +1 -0
- package/{build/lib → dist/esm}/features/ColumnFaceting.js +6 -19
- package/{build/lib → dist/esm}/features/ColumnFaceting.js.map +1 -1
- package/{build/lib → dist/esm}/features/ColumnFiltering.d.ts +1 -0
- package/dist/esm/features/ColumnFiltering.js +137 -0
- package/dist/esm/features/ColumnFiltering.js.map +1 -0
- package/{build/lib → dist/esm}/features/ColumnGrouping.d.ts +1 -0
- package/dist/esm/features/ColumnGrouping.js +133 -0
- package/dist/esm/features/ColumnGrouping.js.map +1 -0
- package/{build/lib → dist/esm}/features/ColumnOrdering.d.ts +1 -0
- package/dist/esm/features/ColumnOrdering.js +76 -0
- package/dist/esm/features/ColumnOrdering.js.map +1 -0
- package/{build/lib → dist/esm}/features/ColumnPinning.d.ts +1 -0
- package/dist/esm/features/ColumnPinning.js +145 -0
- package/dist/esm/features/ColumnPinning.js.map +1 -0
- package/{build/lib → dist/esm}/features/ColumnSizing.d.ts +2 -1
- package/dist/esm/features/ColumnSizing.js +307 -0
- package/dist/esm/features/ColumnSizing.js.map +1 -0
- package/{build/lib → dist/esm}/features/ColumnVisibility.d.ts +1 -0
- package/dist/esm/features/ColumnVisibility.js +144 -0
- package/dist/esm/features/ColumnVisibility.js.map +1 -0
- package/{build/lib → dist/esm}/features/GlobalFaceting.d.ts +1 -0
- package/{build/lib → dist/esm}/features/GlobalFaceting.js +8 -21
- package/dist/esm/features/GlobalFaceting.js.map +1 -0
- package/{build/lib → dist/esm}/features/GlobalFiltering.d.ts +1 -0
- package/dist/esm/features/GlobalFiltering.js +50 -0
- package/dist/esm/features/GlobalFiltering.js.map +1 -0
- package/{build/lib → dist/esm}/features/RowExpanding.d.ts +1 -0
- package/{build/lib → dist/esm}/features/RowExpanding.js +37 -58
- package/dist/esm/features/RowExpanding.js.map +1 -0
- package/{build/lib → dist/esm}/features/RowPagination.d.ts +1 -0
- package/dist/esm/features/RowPagination.js +161 -0
- package/dist/esm/features/RowPagination.js.map +1 -0
- package/{build/lib → dist/esm}/features/RowPinning.d.ts +1 -0
- package/dist/esm/features/RowPinning.js +132 -0
- package/dist/esm/features/RowPinning.js.map +1 -0
- package/{build/lib → dist/esm}/features/RowSelection.d.ts +1 -0
- package/dist/esm/features/RowSelection.js +296 -0
- package/dist/esm/features/RowSelection.js.map +1 -0
- package/{build/lib → dist/esm}/features/RowSorting.d.ts +1 -0
- package/dist/esm/features/RowSorting.js +200 -0
- package/dist/esm/features/RowSorting.js.map +1 -0
- package/{build/lib → dist/esm}/filterFns.d.ts +2 -1
- package/dist/esm/filterFns.js +88 -0
- package/dist/esm/filterFns.js.map +1 -0
- package/dist/esm/index.d.ts +34 -0
- package/dist/esm/index.js +88 -0
- package/dist/esm/index.js.map +1 -0
- package/{build/lib → dist/esm}/sortingFns.d.ts +2 -1
- package/dist/esm/sortingFns.js +91 -0
- package/dist/esm/sortingFns.js.map +1 -0
- package/{build/lib → dist/esm}/types.d.ts +29 -28
- package/{build/lib → dist/esm}/utils/filterRowsUtils.d.ts +1 -0
- package/dist/esm/utils/filterRowsUtils.js +99 -0
- package/dist/esm/utils/filterRowsUtils.js.map +1 -0
- package/{build/lib → dist/esm}/utils/getCoreRowModel.d.ts +1 -0
- package/dist/esm/utils/getCoreRowModel.js +54 -0
- package/dist/esm/utils/getCoreRowModel.js.map +1 -0
- package/{build/lib → dist/esm}/utils/getExpandedRowModel.d.ts +1 -0
- package/dist/esm/utils/getExpandedRowModel.js +41 -0
- package/dist/esm/utils/getExpandedRowModel.js.map +1 -0
- package/{build/lib → dist/esm}/utils/getFacetedMinMaxValues.d.ts +1 -0
- package/dist/esm/utils/getFacetedMinMaxValues.js +35 -0
- package/dist/esm/utils/getFacetedMinMaxValues.js.map +1 -0
- package/{build/lib → dist/esm}/utils/getFacetedRowModel.d.ts +1 -0
- package/dist/esm/utils/getFacetedRowModel.js +35 -0
- package/{build/lib → dist/esm}/utils/getFacetedRowModel.js.map +1 -1
- package/{build/lib → dist/esm}/utils/getFacetedUniqueValues.d.ts +1 -0
- package/dist/esm/utils/getFacetedUniqueValues.js +37 -0
- package/dist/esm/utils/getFacetedUniqueValues.js.map +1 -0
- package/{build/lib → dist/esm}/utils/getFilteredRowModel.d.ts +1 -0
- package/dist/esm/utils/getFilteredRowModel.js +116 -0
- package/{build/lib → dist/esm}/utils/getFilteredRowModel.js.map +1 -1
- package/{build/lib → dist/esm}/utils/getGroupedRowModel.d.ts +1 -0
- package/dist/esm/utils/getGroupedRowModel.js +118 -0
- package/dist/esm/utils/getGroupedRowModel.js.map +1 -0
- package/{build/lib → dist/esm}/utils/getPaginationRowModel.d.ts +1 -0
- package/dist/esm/utils/getPaginationRowModel.js +49 -0
- package/dist/esm/utils/getPaginationRowModel.js.map +1 -0
- package/{build/lib → dist/esm}/utils/getSortedRowModel.d.ts +1 -0
- package/dist/esm/utils/getSortedRowModel.js +88 -0
- package/{build/lib → dist/esm}/utils/getSortedRowModel.js.map +1 -1
- package/{build/lib → dist/esm}/utils.d.ts +2 -1
- package/dist/esm/utils.js +98 -0
- package/{build/lib → dist/esm}/utils.js.map +1 -1
- package/package.json +14 -10
- package/src/core/cell.ts +2 -2
- package/src/core/column.ts +2 -2
- package/src/core/headers.ts +5 -5
- package/src/core/row.ts +4 -4
- package/src/core/table.ts +43 -7
- package/src/features/ColumnFaceting.ts +1 -1
- package/src/features/ColumnFiltering.ts +6 -6
- package/src/features/ColumnGrouping.ts +7 -7
- package/src/features/ColumnOrdering.ts +4 -4
- package/src/features/ColumnPinning.ts +5 -5
- package/src/features/ColumnSizing.ts +6 -6
- package/src/features/ColumnVisibility.ts +5 -5
- package/src/features/GlobalFaceting.ts +1 -1
- package/src/features/GlobalFiltering.ts +4 -4
- package/src/features/RowExpanding.ts +4 -4
- package/src/features/RowPagination.ts +3 -3
- package/src/features/RowPinning.ts +4 -4
- package/src/features/RowSelection.ts +4 -4
- package/src/features/RowSorting.ts +5 -5
- package/src/types.ts +8 -8
- package/src/utils/filterRowsUtils.ts +3 -3
- package/src/utils/getCoreRowModel.ts +2 -2
- package/src/utils/getGroupedRowModel.ts +2 -2
- package/build/lib/aggregationFns.js +0 -108
- package/build/lib/aggregationFns.js.map +0 -1
- package/build/lib/columnHelper.js +0 -71
- package/build/lib/core/cell.js +0 -42
- package/build/lib/core/cell.js.map +0 -1
- package/build/lib/core/column.js +0 -80
- package/build/lib/core/column.js.map +0 -1
- package/build/lib/core/headers.js +0 -270
- package/build/lib/core/headers.js.map +0 -1
- package/build/lib/core/row.js +0 -89
- package/build/lib/core/row.js.map +0 -1
- package/build/lib/core/table.js +0 -212
- package/build/lib/core/table.js.map +0 -1
- package/build/lib/features/ColumnFiltering.js +0 -151
- package/build/lib/features/ColumnFiltering.js.map +0 -1
- package/build/lib/features/ColumnGrouping.js +0 -142
- package/build/lib/features/ColumnGrouping.js.map +0 -1
- package/build/lib/features/ColumnOrdering.js +0 -84
- package/build/lib/features/ColumnOrdering.js.map +0 -1
- package/build/lib/features/ColumnPinning.js +0 -130
- package/build/lib/features/ColumnPinning.js.map +0 -1
- package/build/lib/features/ColumnSizing.js +0 -270
- package/build/lib/features/ColumnSizing.js.map +0 -1
- package/build/lib/features/ColumnVisibility.js +0 -99
- package/build/lib/features/ColumnVisibility.js.map +0 -1
- package/build/lib/features/GlobalFaceting.js.map +0 -1
- package/build/lib/features/GlobalFiltering.js +0 -63
- package/build/lib/features/GlobalFiltering.js.map +0 -1
- package/build/lib/features/RowExpanding.js.map +0 -1
- package/build/lib/features/RowPagination.js +0 -169
- package/build/lib/features/RowPagination.js.map +0 -1
- package/build/lib/features/RowPinning.js +0 -145
- package/build/lib/features/RowPinning.js.map +0 -1
- package/build/lib/features/RowSelection.js +0 -391
- package/build/lib/features/RowSelection.js.map +0 -1
- package/build/lib/features/RowSorting.js +0 -226
- package/build/lib/features/RowSorting.js.map +0 -1
- package/build/lib/filterFns.js +0 -96
- package/build/lib/filterFns.js.map +0 -1
- package/build/lib/index.d.ts +0 -34
- package/build/lib/index.esm.js +0 -3522
- package/build/lib/index.esm.js.map +0 -1
- package/build/lib/index.js.map +0 -1
- package/build/lib/index.mjs +0 -3522
- package/build/lib/index.mjs.map +0 -1
- package/build/lib/sortingFns.js.map +0 -1
- package/build/lib/utils/filterRowsUtils.js.map +0 -1
- package/build/lib/utils/getCoreRowModel.js +0 -65
- package/build/lib/utils/getCoreRowModel.js.map +0 -1
- package/build/lib/utils/getExpandedRowModel.js +0 -46
- package/build/lib/utils/getExpandedRowModel.js.map +0 -1
- package/build/lib/utils/getFacetedMinMaxValues.js +0 -43
- package/build/lib/utils/getFacetedMinMaxValues.js.map +0 -1
- package/build/lib/utils/getFacetedRowModel.js +0 -36
- package/build/lib/utils/getFacetedUniqueValues.js +0 -39
- package/build/lib/utils/getFacetedUniqueValues.js.map +0 -1
- package/build/lib/utils/getFilteredRowModel.js +0 -111
- package/build/lib/utils/getGroupedRowModel.js +0 -150
- package/build/lib/utils/getGroupedRowModel.js.map +0 -1
- package/build/lib/utils/getPaginationRowModel.js +0 -60
- package/build/lib/utils/getPaginationRowModel.js.map +0 -1
- package/build/lib/utils/getSortedRowModel.js +0 -102
- package/build/umd/index.development.js +0 -3578
- package/build/umd/index.development.js.map +0 -1
- package/build/umd/index.production.js +0 -12
- package/build/umd/index.production.js.map +0 -1
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { filterFns } from "../filterFns.js";
|
|
2
|
+
import { makeStateUpdater, isFunction } from "../utils.js";
|
|
3
|
+
const GlobalFiltering = {
|
|
4
|
+
_getInitialState: (state) => {
|
|
5
|
+
return {
|
|
6
|
+
globalFilter: void 0,
|
|
7
|
+
...state
|
|
8
|
+
};
|
|
9
|
+
},
|
|
10
|
+
_getDefaultOptions: (table) => {
|
|
11
|
+
return {
|
|
12
|
+
onGlobalFilterChange: makeStateUpdater("globalFilter", table),
|
|
13
|
+
globalFilterFn: "auto",
|
|
14
|
+
getColumnCanGlobalFilter: (column) => {
|
|
15
|
+
var _a, _b;
|
|
16
|
+
const value = (_b = (_a = table.getCoreRowModel().flatRows[0]) == null ? void 0 : _a._getAllCellsByColumnId()[column.id]) == null ? void 0 : _b.getValue();
|
|
17
|
+
return typeof value === "string" || typeof value === "number";
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
_createColumn: (column, table) => {
|
|
22
|
+
column.getCanGlobalFilter = () => {
|
|
23
|
+
var _a, _b;
|
|
24
|
+
return (column.columnDef.enableGlobalFilter ?? true) && (table.options.enableGlobalFilter ?? true) && (table.options.enableFilters ?? true) && (((_b = (_a = table.options).getColumnCanGlobalFilter) == null ? void 0 : _b.call(_a, column)) ?? true) && !!column.accessorFn;
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
_createTable: (table) => {
|
|
28
|
+
table.getGlobalAutoFilterFn = () => {
|
|
29
|
+
return filterFns.includesString;
|
|
30
|
+
};
|
|
31
|
+
table.getGlobalFilterFn = () => {
|
|
32
|
+
var _a;
|
|
33
|
+
const { globalFilterFn } = table.options;
|
|
34
|
+
return isFunction(globalFilterFn) ? globalFilterFn : globalFilterFn === "auto" ? table.getGlobalAutoFilterFn() : ((_a = table.options.filterFns) == null ? void 0 : _a[globalFilterFn]) ?? filterFns[globalFilterFn];
|
|
35
|
+
};
|
|
36
|
+
table.setGlobalFilter = (updater) => {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
(_b = (_a = table.options).onGlobalFilterChange) == null ? void 0 : _b.call(_a, updater);
|
|
39
|
+
};
|
|
40
|
+
table.resetGlobalFilter = (defaultState) => {
|
|
41
|
+
table.setGlobalFilter(
|
|
42
|
+
defaultState ? void 0 : table.initialState.globalFilter
|
|
43
|
+
);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
export {
|
|
48
|
+
GlobalFiltering
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=GlobalFiltering.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GlobalFiltering.js","sources":["../../../src/features/GlobalFiltering.ts"],"sourcesContent":["import { FilterFn, FilterFnOption } from '..'\nimport { BuiltInFilterFn, filterFns } from '../filterFns'\nimport {\n Column,\n OnChangeFn,\n Table,\n Updater,\n RowData,\n TableFeature,\n} from '../types'\nimport { isFunction, makeStateUpdater } from '../utils'\n\nexport interface GlobalFilterTableState {\n globalFilter: any\n}\n\nexport interface GlobalFilterColumnDef {\n /**\n * Enables/disables the **global** filter for this column.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/global-filtering#enableglobalfilter)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/global-filtering)\n */\n enableGlobalFilter?: boolean\n}\n\nexport interface GlobalFilterColumn {\n /**\n * Returns whether or not the column can be **globally** filtered. Set to `false` to disable a column from being scanned during global filtering.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/global-filtering#getcanglobalfilter)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/global-filtering)\n */\n getCanGlobalFilter: () => boolean\n}\n\nexport interface GlobalFilterOptions<TData extends RowData> {\n /**\n * Enables/disables **global** filtering for all columns.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/global-filtering#enableglobalfilter)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/global-filtering)\n */\n enableGlobalFilter?: boolean\n /**\n * If provided, this function will be called with the column and should return `true` or `false` to indicate whether this column should be used for global filtering.\n *\n * This is useful if the column can contain data that is not `string` or `number` (i.e. `undefined`).\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/global-filtering#getcolumncanglobalfilter)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/global-filtering)\n */\n getColumnCanGlobalFilter?: (column: Column<TData, unknown>) => boolean\n /**\n * The filter function to use for global filtering.\n * - A `string` referencing a built-in filter function\n * - A `string` that references a custom filter functions provided via the `tableOptions.filterFns` option\n * - A custom filter function\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/global-filtering#globalfilterfn)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/global-filtering)\n */\n globalFilterFn?: FilterFnOption<TData>\n /**\n * If provided, this function will be called with an `updaterFn` when `state.globalFilter` changes. This overrides the default internal state management, so you will need to persist the state change either fully or partially outside of the table.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/global-filtering#onglobalfilterchange)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/global-filtering)\n */\n onGlobalFilterChange?: OnChangeFn<any>\n}\n\nexport interface GlobalFilterInstance<TData extends RowData> {\n /**\n * Currently, this function returns the built-in `includesString` filter function. In future releases, it may return more dynamic filter functions based on the nature of the data provided.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/global-filtering#getglobalautofilterfn)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/global-filtering)\n */\n getGlobalAutoFilterFn: () => FilterFn<TData> | undefined\n /**\n * Returns the filter function (either user-defined or automatic, depending on configuration) for the global filter.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/global-filtering#getglobalfilterfn)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/global-filtering)\n */\n getGlobalFilterFn: () => FilterFn<TData> | undefined\n /**\n * Resets the **globalFilter** state to `initialState.globalFilter`, or `true` can be passed to force a default blank state reset to `undefined`.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/global-filtering#resetglobalfilter)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/global-filtering)\n */\n resetGlobalFilter: (defaultState?: boolean) => void\n /**\n * Sets or updates the `state.globalFilter` state.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/global-filtering#setglobalfilter)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/global-filtering)\n */\n setGlobalFilter: (updater: Updater<any>) => void\n}\n\n//\n\nexport const GlobalFiltering: TableFeature = {\n _getInitialState: (state): GlobalFilterTableState => {\n return {\n globalFilter: undefined,\n ...state,\n }\n },\n\n _getDefaultOptions: <TData extends RowData>(\n table: Table<TData>\n ): GlobalFilterOptions<TData> => {\n return {\n onGlobalFilterChange: makeStateUpdater('globalFilter', table),\n globalFilterFn: 'auto',\n getColumnCanGlobalFilter: column => {\n const value = table\n .getCoreRowModel()\n .flatRows[0]?._getAllCellsByColumnId()\n [column.id]?.getValue()\n\n return typeof value === 'string' || typeof value === 'number'\n },\n } as GlobalFilterOptions<TData>\n },\n\n _createColumn: <TData extends RowData>(\n column: Column<TData, unknown>,\n table: Table<TData>\n ): void => {\n column.getCanGlobalFilter = () => {\n return (\n (column.columnDef.enableGlobalFilter ?? true) &&\n (table.options.enableGlobalFilter ?? true) &&\n (table.options.enableFilters ?? true) &&\n (table.options.getColumnCanGlobalFilter?.(column) ?? true) &&\n !!column.accessorFn\n )\n }\n },\n\n _createTable: <TData extends RowData>(table: Table<TData>): void => {\n table.getGlobalAutoFilterFn = () => {\n return filterFns.includesString\n }\n\n table.getGlobalFilterFn = () => {\n const { globalFilterFn: globalFilterFn } = table.options\n\n return isFunction(globalFilterFn)\n ? globalFilterFn\n : globalFilterFn === 'auto'\n ? table.getGlobalAutoFilterFn()\n : table.options.filterFns?.[globalFilterFn as string] ??\n filterFns[globalFilterFn as BuiltInFilterFn]\n }\n\n table.setGlobalFilter = updater => {\n table.options.onGlobalFilterChange?.(updater)\n }\n\n table.resetGlobalFilter = defaultState => {\n table.setGlobalFilter(\n defaultState ? undefined : table.initialState.globalFilter\n )\n }\n },\n}\n"],"names":[],"mappings":";;AA+FO,MAAM,kBAAgC;AAAA,EAC3C,kBAAkB,CAAC,UAAkC;AAC5C,WAAA;AAAA,MACL,cAAc;AAAA,MACd,GAAG;AAAA,IAAA;AAAA,EAEP;AAAA,EAEA,oBAAoB,CAClB,UAC+B;AACxB,WAAA;AAAA,MACL,sBAAsB,iBAAiB,gBAAgB,KAAK;AAAA,MAC5D,gBAAgB;AAAA,MAChB,0BAA0B,CAAU,WAAA;;AAClC,cAAM,SAAQ,iBACX,gBAAgB,EAChB,SAAS,CAAC,MAFC,mBAEE,yBACb,OAAO,QAHI,mBAGC;AAEf,eAAO,OAAO,UAAU,YAAY,OAAO,UAAU;AAAA,MACvD;AAAA,IAAA;AAAA,EAEJ;AAAA,EAEA,eAAe,CACb,QACA,UACS;AACT,WAAO,qBAAqB,MAAM;;AAE7B,cAAA,OAAO,UAAU,sBAAsB,UACvC,MAAM,QAAQ,sBAAsB,UACpC,MAAM,QAAQ,iBAAiB,YAC/B,iBAAM,SAAQ,6BAAd,4BAAyC,YAAW,SACrD,CAAC,CAAC,OAAO;AAAA,IAAA;AAAA,EAGf;AAAA,EAEA,cAAc,CAAwB,UAA8B;AAClE,UAAM,wBAAwB,MAAM;AAClC,aAAO,UAAU;AAAA,IAAA;AAGnB,UAAM,oBAAoB,MAAM;;AACxB,YAAA,EAAE,eAA+B,IAAI,MAAM;AAEjD,aAAO,WAAW,cAAc,IAC5B,iBACA,mBAAmB,SACjB,MAAM,sBAAsB,MAC5B,WAAM,QAAQ,cAAd,mBAA0B,oBAC1B,UAAU,cAAiC;AAAA,IAAA;AAGnD,UAAM,kBAAkB,CAAW,YAAA;;AAC3B,wBAAA,SAAQ,yBAAR,4BAA+B;AAAA,IAAO;AAG9C,UAAM,oBAAoB,CAAgB,iBAAA;AAClC,YAAA;AAAA,QACJ,eAAe,SAAY,MAAM,aAAa;AAAA,MAAA;AAAA,IAChD;AAAA,EAEJ;AACF;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { RowModel } from '..';
|
|
2
2
|
import { OnChangeFn, Table, Row, Updater, RowData, TableFeature } from '../types';
|
|
3
|
+
|
|
3
4
|
export type ExpandedStateList = Record<string, boolean>;
|
|
4
5
|
export type ExpandedState = true | Record<string, boolean>;
|
|
5
6
|
export interface ExpandedTableState {
|
|
@@ -1,44 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
* table-core
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) TanStack
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
-
*
|
|
9
|
-
* @license MIT
|
|
10
|
-
*/
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
var utils = require('../utils.js');
|
|
14
|
-
|
|
15
|
-
//
|
|
16
|
-
|
|
1
|
+
import { makeStateUpdater } from "../utils.js";
|
|
17
2
|
const RowExpanding = {
|
|
18
|
-
|
|
3
|
+
_getInitialState: (state) => {
|
|
19
4
|
return {
|
|
20
5
|
expanded: {},
|
|
21
6
|
...state
|
|
22
7
|
};
|
|
23
8
|
},
|
|
24
|
-
|
|
9
|
+
_getDefaultOptions: (table) => {
|
|
25
10
|
return {
|
|
26
|
-
onExpandedChange:
|
|
11
|
+
onExpandedChange: makeStateUpdater("expanded", table),
|
|
27
12
|
paginateExpandedRows: true
|
|
28
13
|
};
|
|
29
14
|
},
|
|
30
|
-
|
|
15
|
+
_createTable: (table) => {
|
|
31
16
|
let registered = false;
|
|
32
17
|
let queued = false;
|
|
33
18
|
table._autoResetExpanded = () => {
|
|
34
|
-
var _ref, _table$options$autoRe;
|
|
35
19
|
if (!registered) {
|
|
36
20
|
table._queue(() => {
|
|
37
21
|
registered = true;
|
|
38
22
|
});
|
|
39
23
|
return;
|
|
40
24
|
}
|
|
41
|
-
if (
|
|
25
|
+
if (table.options.autoResetAll ?? table.options.autoResetExpanded ?? !table.options.manualExpanding) {
|
|
42
26
|
if (queued) return;
|
|
43
27
|
queued = true;
|
|
44
28
|
table._queue(() => {
|
|
@@ -47,24 +31,28 @@ const RowExpanding = {
|
|
|
47
31
|
});
|
|
48
32
|
}
|
|
49
33
|
};
|
|
50
|
-
table.setExpanded = updater =>
|
|
51
|
-
|
|
52
|
-
|
|
34
|
+
table.setExpanded = (updater) => {
|
|
35
|
+
var _a, _b;
|
|
36
|
+
return (_b = (_a = table.options).onExpandedChange) == null ? void 0 : _b.call(_a, updater);
|
|
37
|
+
};
|
|
38
|
+
table.toggleAllRowsExpanded = (expanded) => {
|
|
39
|
+
if (expanded ?? !table.getIsAllRowsExpanded()) {
|
|
53
40
|
table.setExpanded(true);
|
|
54
41
|
} else {
|
|
55
42
|
table.setExpanded({});
|
|
56
43
|
}
|
|
57
44
|
};
|
|
58
|
-
table.resetExpanded = defaultState => {
|
|
59
|
-
var
|
|
60
|
-
table.setExpanded(defaultState ? {} : (
|
|
45
|
+
table.resetExpanded = (defaultState) => {
|
|
46
|
+
var _a;
|
|
47
|
+
table.setExpanded(defaultState ? {} : ((_a = table.initialState) == null ? void 0 : _a.expanded) ?? {});
|
|
61
48
|
};
|
|
62
49
|
table.getCanSomeRowsExpand = () => {
|
|
63
|
-
return table.getPrePaginationRowModel().flatRows.some(row => row.getCanExpand());
|
|
50
|
+
return table.getPrePaginationRowModel().flatRows.some((row) => row.getCanExpand());
|
|
64
51
|
};
|
|
65
52
|
table.getToggleAllRowsExpandedHandler = () => {
|
|
66
|
-
return e => {
|
|
67
|
-
|
|
53
|
+
return (e) => {
|
|
54
|
+
var _a;
|
|
55
|
+
(_a = e.persist) == null ? void 0 : _a.call(e);
|
|
68
56
|
table.toggleAllRowsExpanded();
|
|
69
57
|
};
|
|
70
58
|
};
|
|
@@ -74,28 +62,22 @@ const RowExpanding = {
|
|
|
74
62
|
};
|
|
75
63
|
table.getIsAllRowsExpanded = () => {
|
|
76
64
|
const expanded = table.getState().expanded;
|
|
77
|
-
|
|
78
|
-
// If expanded is true, save some cycles and return true
|
|
79
|
-
if (typeof expanded === 'boolean') {
|
|
65
|
+
if (typeof expanded === "boolean") {
|
|
80
66
|
return expanded === true;
|
|
81
67
|
}
|
|
82
68
|
if (!Object.keys(expanded).length) {
|
|
83
69
|
return false;
|
|
84
70
|
}
|
|
85
|
-
|
|
86
|
-
// If any row is not expanded, return false
|
|
87
|
-
if (table.getRowModel().flatRows.some(row => !row.getIsExpanded())) {
|
|
71
|
+
if (table.getRowModel().flatRows.some((row) => !row.getIsExpanded())) {
|
|
88
72
|
return false;
|
|
89
73
|
}
|
|
90
|
-
|
|
91
|
-
// They must all be expanded :shrug:
|
|
92
74
|
return true;
|
|
93
75
|
};
|
|
94
76
|
table.getExpandedDepth = () => {
|
|
95
77
|
let maxDepth = 0;
|
|
96
78
|
const rowIds = table.getState().expanded === true ? Object.keys(table.getRowModel().rowsById) : Object.keys(table.getState().expanded);
|
|
97
|
-
rowIds.forEach(id => {
|
|
98
|
-
const splitId = id.split(
|
|
79
|
+
rowIds.forEach((id) => {
|
|
80
|
+
const splitId = id.split(".");
|
|
99
81
|
maxDepth = Math.max(maxDepth, splitId.length);
|
|
100
82
|
});
|
|
101
83
|
return maxDepth;
|
|
@@ -111,20 +93,19 @@ const RowExpanding = {
|
|
|
111
93
|
return table._getExpandedRowModel();
|
|
112
94
|
};
|
|
113
95
|
},
|
|
114
|
-
|
|
115
|
-
row.toggleExpanded = expanded => {
|
|
116
|
-
table.setExpanded(old => {
|
|
117
|
-
|
|
118
|
-
const exists = old === true ? true : !!(old != null && old[row.id]);
|
|
96
|
+
_createRow: (row, table) => {
|
|
97
|
+
row.toggleExpanded = (expanded) => {
|
|
98
|
+
table.setExpanded((old) => {
|
|
99
|
+
const exists = old === true ? true : !!(old == null ? void 0 : old[row.id]);
|
|
119
100
|
let oldExpanded = {};
|
|
120
101
|
if (old === true) {
|
|
121
|
-
Object.keys(table.getRowModel().rowsById).forEach(rowId => {
|
|
102
|
+
Object.keys(table.getRowModel().rowsById).forEach((rowId) => {
|
|
122
103
|
oldExpanded[rowId] = true;
|
|
123
104
|
});
|
|
124
105
|
} else {
|
|
125
106
|
oldExpanded = old;
|
|
126
107
|
}
|
|
127
|
-
expanded =
|
|
108
|
+
expanded = expanded ?? !exists;
|
|
128
109
|
if (!exists && expanded) {
|
|
129
110
|
return {
|
|
130
111
|
...oldExpanded,
|
|
@@ -132,23 +113,20 @@ const RowExpanding = {
|
|
|
132
113
|
};
|
|
133
114
|
}
|
|
134
115
|
if (exists && !expanded) {
|
|
135
|
-
const {
|
|
136
|
-
[row.id]: _,
|
|
137
|
-
...rest
|
|
138
|
-
} = oldExpanded;
|
|
116
|
+
const { [row.id]: _, ...rest } = oldExpanded;
|
|
139
117
|
return rest;
|
|
140
118
|
}
|
|
141
119
|
return old;
|
|
142
120
|
});
|
|
143
121
|
};
|
|
144
122
|
row.getIsExpanded = () => {
|
|
145
|
-
var
|
|
123
|
+
var _a, _b;
|
|
146
124
|
const expanded = table.getState().expanded;
|
|
147
|
-
return !!((
|
|
125
|
+
return !!(((_b = (_a = table.options).getIsRowExpanded) == null ? void 0 : _b.call(_a, row)) ?? (expanded === true || (expanded == null ? void 0 : expanded[row.id])));
|
|
148
126
|
};
|
|
149
127
|
row.getCanExpand = () => {
|
|
150
|
-
var
|
|
151
|
-
return (
|
|
128
|
+
var _a, _b, _c;
|
|
129
|
+
return ((_b = (_a = table.options).getRowCanExpand) == null ? void 0 : _b.call(_a, row)) ?? ((table.options.enableExpanding ?? true) && !!((_c = row.subRows) == null ? void 0 : _c.length));
|
|
152
130
|
};
|
|
153
131
|
row.getIsAllParentsExpanded = () => {
|
|
154
132
|
let isFullyExpanded = true;
|
|
@@ -168,6 +146,7 @@ const RowExpanding = {
|
|
|
168
146
|
};
|
|
169
147
|
}
|
|
170
148
|
};
|
|
171
|
-
|
|
172
|
-
|
|
149
|
+
export {
|
|
150
|
+
RowExpanding
|
|
151
|
+
};
|
|
173
152
|
//# sourceMappingURL=RowExpanding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RowExpanding.js","sources":["../../../src/features/RowExpanding.ts"],"sourcesContent":["import { RowModel } from '..'\nimport {\n OnChangeFn,\n Table,\n Row,\n Updater,\n RowData,\n TableFeature,\n} from '../types'\nimport { makeStateUpdater } from '../utils'\n\nexport type ExpandedStateList = Record<string, boolean>\nexport type ExpandedState = true | Record<string, boolean>\nexport interface ExpandedTableState {\n expanded: ExpandedState\n}\n\nexport interface ExpandedRow {\n /**\n * Returns whether the row can be expanded.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/expanding#getcanexpand)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/expanding)\n */\n getCanExpand: () => boolean\n /**\n * Returns whether all parent rows of the row are expanded.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/expanding#getisallparentsexpanded)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/expanding)\n */\n getIsAllParentsExpanded: () => boolean\n /**\n * Returns whether the row is expanded.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/expanding#getisexpanded)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/expanding)\n */\n getIsExpanded: () => boolean\n /**\n * Returns a function that can be used to toggle the expanded state of the row. This function can be used to bind to an event handler to a button.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/expanding#gettoggleexpandedhandler)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/expanding)\n */\n getToggleExpandedHandler: () => () => void\n /**\n * Toggles the expanded state (or sets it if `expanded` is provided) for the row.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/expanding#toggleexpanded)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/expanding)\n */\n toggleExpanded: (expanded?: boolean) => void\n}\n\nexport interface ExpandedOptions<TData extends RowData> {\n /**\n * Enable this setting to automatically reset the expanded state of the table when expanding state changes.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/expanding#autoresetexpanded)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/expanding)\n */\n autoResetExpanded?: boolean\n /**\n * Enable/disable expanding for all rows.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/expanding#enableexpanding)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/expanding)\n */\n enableExpanding?: boolean\n /**\n * This function is responsible for returning the expanded row model. If this function is not provided, the table will not expand rows. You can use the default exported `getExpandedRowModel` function to get the expanded row model or implement your own.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/expanding#getexpandedrowmodel)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/expanding)\n */\n getExpandedRowModel?: (table: Table<any>) => () => RowModel<any>\n /**\n * If provided, allows you to override the default behavior of determining whether a row is currently expanded.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/expanding#getisrowexpanded)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/expanding)\n */\n getIsRowExpanded?: (row: Row<TData>) => boolean\n /**\n * If provided, allows you to override the default behavior of determining whether a row can be expanded.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/expanding#getrowcanexpand)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/expanding)\n */\n getRowCanExpand?: (row: Row<TData>) => boolean\n /**\n * Enables manual row expansion. If this is set to `true`, `getExpandedRowModel` will not be used to expand rows and you would be expected to perform the expansion in your own data model. This is useful if you are doing server-side expansion.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/expanding#manualexpanding)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/expanding)\n */\n manualExpanding?: boolean\n /**\n * This function is called when the `expanded` table state changes. If a function is provided, you will be responsible for managing this state on your own. To pass the managed state back to the table, use the `tableOptions.state.expanded` option.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/expanding#onexpandedchange)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/expanding)\n */\n onExpandedChange?: OnChangeFn<ExpandedState>\n /**\n * If `true` expanded rows will be paginated along with the rest of the table (which means expanded rows may span multiple pages). If `false` expanded rows will not be considered for pagination (which means expanded rows will always render on their parents page. This also means more rows will be rendered than the set page size)\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/expanding#paginateexpandedrows)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/expanding)\n */\n paginateExpandedRows?: boolean\n}\n\nexport interface ExpandedInstance<TData extends RowData> {\n _autoResetExpanded: () => void\n _getExpandedRowModel?: () => RowModel<TData>\n /**\n * Returns whether there are any rows that can be expanded.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/expanding#getcansomerowsexpand)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/expanding)\n */\n getCanSomeRowsExpand: () => boolean\n /**\n * Returns the maximum depth of the expanded rows.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/expanding#getexpandeddepth)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/expanding)\n */\n getExpandedDepth: () => number\n /**\n * Returns the row model after expansion has been applied.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/expanding#getexpandedrowmodel)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/expanding)\n */\n getExpandedRowModel: () => RowModel<TData>\n /**\n * Returns whether all rows are currently expanded.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/expanding#getisallrowsexpanded)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/expanding)\n */\n getIsAllRowsExpanded: () => boolean\n /**\n * Returns whether there are any rows that are currently expanded.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/expanding#getissomerowsexpanded)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/expanding)\n */\n getIsSomeRowsExpanded: () => boolean\n /**\n * Returns the row model before expansion has been applied.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/expanding#getpreexpandedrowmodel)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/expanding)\n */\n getPreExpandedRowModel: () => RowModel<TData>\n /**\n * Returns a handler that can be used to toggle the expanded state of all rows. This handler is meant to be used with an `input[type=checkbox]` element.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/expanding#gettoggleallrowsexpandedhandler)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/expanding)\n */\n getToggleAllRowsExpandedHandler: () => (event: unknown) => void\n /**\n * Resets the expanded state of the table to the initial state.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/expanding#resetexpanded)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/expanding)\n */\n resetExpanded: (defaultState?: boolean) => void\n /**\n * Updates the expanded state of the table via an update function or value.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/expanding#setexpanded)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/expanding)\n */\n setExpanded: (updater: Updater<ExpandedState>) => void\n /**\n * Toggles the expanded state for all rows.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/expanding#toggleallrowsexpanded)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/expanding)\n */\n toggleAllRowsExpanded: (expanded?: boolean) => void\n}\n\n//\n\nexport const RowExpanding: TableFeature = {\n _getInitialState: (state): ExpandedTableState => {\n return {\n expanded: {},\n ...state,\n }\n },\n\n _getDefaultOptions: <TData extends RowData>(\n table: Table<TData>\n ): ExpandedOptions<TData> => {\n return {\n onExpandedChange: makeStateUpdater('expanded', table),\n paginateExpandedRows: true,\n }\n },\n\n _createTable: <TData extends RowData>(table: Table<TData>): void => {\n let registered = false\n let queued = false\n\n table._autoResetExpanded = () => {\n if (!registered) {\n table._queue(() => {\n registered = true\n })\n return\n }\n\n if (\n table.options.autoResetAll ??\n table.options.autoResetExpanded ??\n !table.options.manualExpanding\n ) {\n if (queued) return\n queued = true\n table._queue(() => {\n table.resetExpanded()\n queued = false\n })\n }\n }\n table.setExpanded = updater => table.options.onExpandedChange?.(updater)\n table.toggleAllRowsExpanded = expanded => {\n if (expanded ?? !table.getIsAllRowsExpanded()) {\n table.setExpanded(true)\n } else {\n table.setExpanded({})\n }\n }\n table.resetExpanded = defaultState => {\n table.setExpanded(defaultState ? {} : table.initialState?.expanded ?? {})\n }\n table.getCanSomeRowsExpand = () => {\n return table\n .getPrePaginationRowModel()\n .flatRows.some(row => row.getCanExpand())\n }\n table.getToggleAllRowsExpandedHandler = () => {\n return (e: unknown) => {\n ;(e as any).persist?.()\n table.toggleAllRowsExpanded()\n }\n }\n table.getIsSomeRowsExpanded = () => {\n const expanded = table.getState().expanded\n return expanded === true || Object.values(expanded).some(Boolean)\n }\n table.getIsAllRowsExpanded = () => {\n const expanded = table.getState().expanded\n\n // If expanded is true, save some cycles and return true\n if (typeof expanded === 'boolean') {\n return expanded === true\n }\n\n if (!Object.keys(expanded).length) {\n return false\n }\n\n // If any row is not expanded, return false\n if (table.getRowModel().flatRows.some(row => !row.getIsExpanded())) {\n return false\n }\n\n // They must all be expanded :shrug:\n return true\n }\n table.getExpandedDepth = () => {\n let maxDepth = 0\n\n const rowIds =\n table.getState().expanded === true\n ? Object.keys(table.getRowModel().rowsById)\n : Object.keys(table.getState().expanded)\n\n rowIds.forEach(id => {\n const splitId = id.split('.')\n maxDepth = Math.max(maxDepth, splitId.length)\n })\n\n return maxDepth\n }\n table.getPreExpandedRowModel = () => table.getSortedRowModel()\n table.getExpandedRowModel = () => {\n if (!table._getExpandedRowModel && table.options.getExpandedRowModel) {\n table._getExpandedRowModel = table.options.getExpandedRowModel(table)\n }\n\n if (table.options.manualExpanding || !table._getExpandedRowModel) {\n return table.getPreExpandedRowModel()\n }\n\n return table._getExpandedRowModel()\n }\n },\n\n _createRow: <TData extends RowData>(\n row: Row<TData>,\n table: Table<TData>\n ): void => {\n row.toggleExpanded = expanded => {\n table.setExpanded(old => {\n const exists = old === true ? true : !!old?.[row.id]\n\n let oldExpanded: ExpandedStateList = {}\n\n if (old === true) {\n Object.keys(table.getRowModel().rowsById).forEach(rowId => {\n oldExpanded[rowId] = true\n })\n } else {\n oldExpanded = old\n }\n\n expanded = expanded ?? !exists\n\n if (!exists && expanded) {\n return {\n ...oldExpanded,\n [row.id]: true,\n }\n }\n\n if (exists && !expanded) {\n const { [row.id]: _, ...rest } = oldExpanded\n return rest\n }\n\n return old\n })\n }\n row.getIsExpanded = () => {\n const expanded = table.getState().expanded\n\n return !!(\n table.options.getIsRowExpanded?.(row) ??\n (expanded === true || expanded?.[row.id])\n )\n }\n row.getCanExpand = () => {\n return (\n table.options.getRowCanExpand?.(row) ??\n ((table.options.enableExpanding ?? true) && !!row.subRows?.length)\n )\n }\n row.getIsAllParentsExpanded = () => {\n let isFullyExpanded = true\n let currentRow = row\n\n while (isFullyExpanded && currentRow.parentId) {\n currentRow = table.getRow(currentRow.parentId, true)\n isFullyExpanded = currentRow.getIsExpanded()\n }\n\n return isFullyExpanded\n }\n row.getToggleExpandedHandler = () => {\n const canExpand = row.getCanExpand()\n\n return () => {\n if (!canExpand) return\n row.toggleExpanded()\n }\n }\n },\n}\n"],"names":[],"mappings":";AAwKO,MAAM,eAA6B;AAAA,EACxC,kBAAkB,CAAC,UAA8B;AACxC,WAAA;AAAA,MACL,UAAU,CAAC;AAAA,MACX,GAAG;AAAA,IAAA;AAAA,EAEP;AAAA,EAEA,oBAAoB,CAClB,UAC2B;AACpB,WAAA;AAAA,MACL,kBAAkB,iBAAiB,YAAY,KAAK;AA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AA,QAChB;AAEA,mBAAW,YAAY,CAAC;AAEpB,YAAA,CAAC,UAAU,UAAU;AAChB,iBAAA;AAAA,YACL,GAAG;AAAA,YACH,CAAC,IAAI,EAAE,GAAG;AAAA,UAAA;AAAA,QAEd;AAEI,YAAA,UAAU,CAAC,UAAU;AACjB,gBAAA,EAAE,CAAC,IAAI,EAAE,GAAG,GAAG,GAAG,KAAS,IAAA;AAC1B,iBAAA;AAAA,QACT;AAEO,eAAA;AAAA,MAAA,CACR;AAAA,IAAA;AAEH,QAAI,gBAAgB,MAAM;;AAClB,YAAA,WAAW,MAAM,SAAA,EAAW;AAE3B,aAAA,CAAC,IACN,iBAAM,SAAQ,qBAAd,4BAAiC,UAChC,aAAa,SAAQ,qCAAW,IAAI;AAAA,IAAE;AAG3C,QAAI,eAAe,MAAM;;AACvB,eACE,iBAAM,SAAQ,oBAAd,4BAAgC,WAC9B,MAAM,QAAQ,mBAAmB,SAAS,CAAC,GAAC,SAAI,YAAJ,mBAAa;AAAA,IAAA;AAG/D,QAAI,0BAA0B,MAAM;AAClC,UAAI,kBAAkB;AACtB,UAAI,aAAa;AAEV,aAAA,mBAAmB,WAAW,UAAU;AAC7C,qBAAa,MAAM,OAAO,WAAW,UAAU,IAAI;AACnD,0BAAkB,WAAW;MAC/B;AAEO,aAAA;AAAA,IAAA;AAET,QAAI,2BAA2B,MAAM;AAC7B,YAAA,YAAY,IAAI;AAEtB,aAAO,MAAM;AACX,YAAI,CAAC,UAAW;AAChB,YAAI,eAAe;AAAA,MAAA;AAAA,IACrB;AAAA,EAEJ;AACF;"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { makeStateUpdater, functionalUpdate, memo, getMemoOptions } from "../utils.js";
|
|
2
|
+
const defaultPageIndex = 0;
|
|
3
|
+
const defaultPageSize = 10;
|
|
4
|
+
const getDefaultPaginationState = () => ({
|
|
5
|
+
pageIndex: defaultPageIndex,
|
|
6
|
+
pageSize: defaultPageSize
|
|
7
|
+
});
|
|
8
|
+
const RowPagination = {
|
|
9
|
+
_getInitialState: (state) => {
|
|
10
|
+
return {
|
|
11
|
+
...state,
|
|
12
|
+
pagination: {
|
|
13
|
+
...getDefaultPaginationState(),
|
|
14
|
+
...state == null ? void 0 : state.pagination
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
_getDefaultOptions: (table) => {
|
|
19
|
+
return {
|
|
20
|
+
onPaginationChange: makeStateUpdater("pagination", table)
|
|
21
|
+
};
|
|
22
|
+
},
|
|
23
|
+
_createTable: (table) => {
|
|
24
|
+
let registered = false;
|
|
25
|
+
let queued = false;
|
|
26
|
+
table._autoResetPageIndex = () => {
|
|
27
|
+
if (!registered) {
|
|
28
|
+
table._queue(() => {
|
|
29
|
+
registered = true;
|
|
30
|
+
});
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (table.options.autoResetAll ?? table.options.autoResetPageIndex ?? !table.options.manualPagination) {
|
|
34
|
+
if (queued) return;
|
|
35
|
+
queued = true;
|
|
36
|
+
table._queue(() => {
|
|
37
|
+
table.resetPageIndex();
|
|
38
|
+
queued = false;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
table.setPagination = (updater) => {
|
|
43
|
+
var _a, _b;
|
|
44
|
+
const safeUpdater = (old) => {
|
|
45
|
+
let newState = functionalUpdate(updater, old);
|
|
46
|
+
return newState;
|
|
47
|
+
};
|
|
48
|
+
return (_b = (_a = table.options).onPaginationChange) == null ? void 0 : _b.call(_a, safeUpdater);
|
|
49
|
+
};
|
|
50
|
+
table.resetPagination = (defaultState) => {
|
|
51
|
+
table.setPagination(
|
|
52
|
+
defaultState ? getDefaultPaginationState() : table.initialState.pagination ?? getDefaultPaginationState()
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
table.setPageIndex = (updater) => {
|
|
56
|
+
table.setPagination((old) => {
|
|
57
|
+
let pageIndex = functionalUpdate(updater, old.pageIndex);
|
|
58
|
+
const maxPageIndex = typeof table.options.pageCount === "undefined" || table.options.pageCount === -1 ? Number.MAX_SAFE_INTEGER : table.options.pageCount - 1;
|
|
59
|
+
pageIndex = Math.max(0, Math.min(pageIndex, maxPageIndex));
|
|
60
|
+
return {
|
|
61
|
+
...old,
|
|
62
|
+
pageIndex
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
table.resetPageIndex = (defaultState) => {
|
|
67
|
+
var _a, _b;
|
|
68
|
+
table.setPageIndex(
|
|
69
|
+
defaultState ? defaultPageIndex : ((_b = (_a = table.initialState) == null ? void 0 : _a.pagination) == null ? void 0 : _b.pageIndex) ?? defaultPageIndex
|
|
70
|
+
);
|
|
71
|
+
};
|
|
72
|
+
table.resetPageSize = (defaultState) => {
|
|
73
|
+
var _a, _b;
|
|
74
|
+
table.setPageSize(
|
|
75
|
+
defaultState ? defaultPageSize : ((_b = (_a = table.initialState) == null ? void 0 : _a.pagination) == null ? void 0 : _b.pageSize) ?? defaultPageSize
|
|
76
|
+
);
|
|
77
|
+
};
|
|
78
|
+
table.setPageSize = (updater) => {
|
|
79
|
+
table.setPagination((old) => {
|
|
80
|
+
const pageSize = Math.max(1, functionalUpdate(updater, old.pageSize));
|
|
81
|
+
const topRowIndex = old.pageSize * old.pageIndex;
|
|
82
|
+
const pageIndex = Math.floor(topRowIndex / pageSize);
|
|
83
|
+
return {
|
|
84
|
+
...old,
|
|
85
|
+
pageIndex,
|
|
86
|
+
pageSize
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
table.setPageCount = (updater) => table.setPagination((old) => {
|
|
91
|
+
let newPageCount = functionalUpdate(
|
|
92
|
+
updater,
|
|
93
|
+
table.options.pageCount ?? -1
|
|
94
|
+
);
|
|
95
|
+
if (typeof newPageCount === "number") {
|
|
96
|
+
newPageCount = Math.max(-1, newPageCount);
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
...old,
|
|
100
|
+
pageCount: newPageCount
|
|
101
|
+
};
|
|
102
|
+
});
|
|
103
|
+
table.getPageOptions = memo(
|
|
104
|
+
() => [table.getPageCount()],
|
|
105
|
+
(pageCount) => {
|
|
106
|
+
let pageOptions = [];
|
|
107
|
+
if (pageCount && pageCount > 0) {
|
|
108
|
+
pageOptions = [...new Array(pageCount)].fill(null).map((_, i) => i);
|
|
109
|
+
}
|
|
110
|
+
return pageOptions;
|
|
111
|
+
},
|
|
112
|
+
getMemoOptions(table.options, "debugTable", "getPageOptions")
|
|
113
|
+
);
|
|
114
|
+
table.getCanPreviousPage = () => table.getState().pagination.pageIndex > 0;
|
|
115
|
+
table.getCanNextPage = () => {
|
|
116
|
+
const { pageIndex } = table.getState().pagination;
|
|
117
|
+
const pageCount = table.getPageCount();
|
|
118
|
+
if (pageCount === -1) {
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
if (pageCount === 0) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
return pageIndex < pageCount - 1;
|
|
125
|
+
};
|
|
126
|
+
table.previousPage = () => {
|
|
127
|
+
return table.setPageIndex((old) => old - 1);
|
|
128
|
+
};
|
|
129
|
+
table.nextPage = () => {
|
|
130
|
+
return table.setPageIndex((old) => {
|
|
131
|
+
return old + 1;
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
table.firstPage = () => {
|
|
135
|
+
return table.setPageIndex(0);
|
|
136
|
+
};
|
|
137
|
+
table.lastPage = () => {
|
|
138
|
+
return table.setPageIndex(table.getPageCount() - 1);
|
|
139
|
+
};
|
|
140
|
+
table.getPrePaginationRowModel = () => table.getExpandedRowModel();
|
|
141
|
+
table.getPaginationRowModel = () => {
|
|
142
|
+
if (!table._getPaginationRowModel && table.options.getPaginationRowModel) {
|
|
143
|
+
table._getPaginationRowModel = table.options.getPaginationRowModel(table);
|
|
144
|
+
}
|
|
145
|
+
if (table.options.manualPagination || !table._getPaginationRowModel) {
|
|
146
|
+
return table.getPrePaginationRowModel();
|
|
147
|
+
}
|
|
148
|
+
return table._getPaginationRowModel();
|
|
149
|
+
};
|
|
150
|
+
table.getPageCount = () => {
|
|
151
|
+
return table.options.pageCount ?? Math.ceil(table.getRowCount() / table.getState().pagination.pageSize);
|
|
152
|
+
};
|
|
153
|
+
table.getRowCount = () => {
|
|
154
|
+
return table.options.rowCount ?? table.getPrePaginationRowModel().rows.length;
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
export {
|
|
159
|
+
RowPagination
|
|
160
|
+
};
|
|
161
|
+
//# sourceMappingURL=RowPagination.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RowPagination.js","sources":["../../../src/features/RowPagination.ts"],"sourcesContent":["import {\n OnChangeFn,\n Table,\n RowModel,\n Updater,\n RowData,\n TableFeature,\n} from '../types'\nimport {\n functionalUpdate,\n getMemoOptions,\n makeStateUpdater,\n memo,\n} from '../utils'\n\nexport interface PaginationState {\n pageIndex: number\n pageSize: number\n}\n\nexport interface PaginationTableState {\n pagination: PaginationState\n}\n\nexport interface PaginationInitialTableState {\n pagination?: Partial<PaginationState>\n}\n\nexport interface PaginationOptions {\n /**\n * If set to `true`, pagination will be reset to the first page when page-altering state changes eg. `data` is updated, filters change, grouping changes, etc.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#autoresetpageindex)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination)\n */\n autoResetPageIndex?: boolean\n /**\n * Returns the row model after pagination has taken place, but no further.\n *\n * Pagination columns are automatically reordered by default to the start of the columns list. If you would rather remove them or leave them as-is, set the appropriate mode here.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#getpaginationrowmodel)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination)\n */\n getPaginationRowModel?: (table: Table<any>) => () => RowModel<any>\n /**\n * Enables manual pagination. If this option is set to `true`, the table will not automatically paginate rows using `getPaginationRowModel()` and instead will expect you to manually paginate the rows before passing them to the table. This is useful if you are doing server-side pagination and aggregation.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#manualpagination)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination)\n */\n manualPagination?: boolean\n /**\n * If this function is provided, it will be called when the pagination state changes and you will be expected to manage the state yourself. You can pass the managed state back to the table via the `tableOptions.state.pagination` option.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#onpaginationchange)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination)\n */\n onPaginationChange?: OnChangeFn<PaginationState>\n /**\n * When manually controlling pagination, you can supply a total `pageCount` value to the table if you know it (Or supply a `rowCount` and `pageCount` will be calculated). If you do not know how many pages there are, you can set this to `-1`.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#pagecount)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination)\n */\n pageCount?: number\n /**\n * When manually controlling pagination, you can supply a total `rowCount` value to the table if you know it. The `pageCount` can be calculated from this value and the `pageSize`.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#rowcount)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination)\n */\n rowCount?: number\n}\n\nexport interface PaginationDefaultOptions {\n onPaginationChange: OnChangeFn<PaginationState>\n}\n\nexport interface PaginationInstance<TData extends RowData> {\n _autoResetPageIndex: () => void\n _getPaginationRowModel?: () => RowModel<TData>\n /**\n * Returns whether the table can go to the next page.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#getcannextpage)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination)\n */\n getCanNextPage: () => boolean\n /**\n * Returns whether the table can go to the previous page.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#getcanpreviouspage)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination)\n */\n getCanPreviousPage: () => boolean\n /**\n * Returns the page count. If manually paginating or controlling the pagination state, this will come directly from the `options.pageCount` table option, otherwise it will be calculated from the table data using the total row count and current page size.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#getpagecount)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination)\n */\n getPageCount: () => number\n /**\n * Returns the row count. If manually paginating or controlling the pagination state, this will come directly from the `options.rowCount` table option, otherwise it will be calculated from the table data.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#getrowcount)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination)\n */\n getRowCount: () => number\n /**\n * Returns an array of page options (zero-index-based) for the current page size.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#getpageoptions)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination)\n */\n getPageOptions: () => number[]\n /**\n * Returns the row model for the table after pagination has been applied.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#getpaginationrowmodel)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination)\n */\n getPaginationRowModel: () => RowModel<TData>\n /**\n * Returns the row model for the table before any pagination has been applied.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#getprepaginationrowmodel)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination)\n */\n getPrePaginationRowModel: () => RowModel<TData>\n /**\n * Increments the page index by one, if possible.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#nextpage)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination)\n */\n nextPage: () => void\n /**\n * Decrements the page index by one, if possible.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#previouspage)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination)\n */\n previousPage: () => void\n /**\n * Sets the page index to `0`.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#firstpage)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination)\n */\n firstPage: () => void\n /**\n * Sets the page index to the last page.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#lastpage)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination)\n */\n lastPage: () => void\n /**\n * Resets the page index to its initial state. If `defaultState` is `true`, the page index will be reset to `0` regardless of initial state.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#resetpageindex)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination)\n */\n resetPageIndex: (defaultState?: boolean) => void\n /**\n * Resets the page size to its initial state. If `defaultState` is `true`, the page size will be reset to `10` regardless of initial state.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#resetpagesize)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination)\n */\n resetPageSize: (defaultState?: boolean) => void\n /**\n * Resets the **pagination** state to `initialState.pagination`, or `true` can be passed to force a default blank state reset to `[]`.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#resetpagination)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination)\n */\n resetPagination: (defaultState?: boolean) => void\n /**\n * @deprecated The page count no longer exists in the pagination state. Just pass as a table option instead.\n */\n setPageCount: (updater: Updater<number>) => void\n /**\n * Updates the page index using the provided function or value in the `state.pagination.pageIndex` state.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#setpageindex)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination)\n */\n setPageIndex: (updater: Updater<number>) => void\n /**\n * Updates the page size using the provided function or value in the `state.pagination.pageSize` state.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#setpagesize)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination)\n */\n setPageSize: (updater: Updater<number>) => void\n /**\n * Sets or updates the `state.pagination` state.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/pagination#setpagination)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/pagination)\n */\n setPagination: (updater: Updater<PaginationState>) => void\n}\n\n//\n\nconst defaultPageIndex = 0\nconst defaultPageSize = 10\n\nconst getDefaultPaginationState = (): PaginationState => ({\n pageIndex: defaultPageIndex,\n pageSize: defaultPageSize,\n})\n\nexport const RowPagination: TableFeature = {\n _getInitialState: (state): PaginationTableState => {\n return {\n ...state,\n pagination: {\n ...getDefaultPaginationState(),\n ...state?.pagination,\n },\n }\n },\n\n _getDefaultOptions: <TData extends RowData>(\n table: Table<TData>\n ): PaginationDefaultOptions => {\n return {\n onPaginationChange: makeStateUpdater('pagination', table),\n }\n },\n\n _createTable: <TData extends RowData>(table: Table<TData>): void => {\n let registered = false\n let queued = false\n\n table._autoResetPageIndex = () => {\n if (!registered) {\n table._queue(() => {\n registered = true\n })\n return\n }\n\n if (\n table.options.autoResetAll ??\n table.options.autoResetPageIndex ??\n !table.options.manualPagination\n ) {\n if (queued) return\n queued = true\n table._queue(() => {\n table.resetPageIndex()\n queued = false\n })\n }\n }\n table.setPagination = updater => {\n const safeUpdater: Updater<PaginationState> = old => {\n let newState = functionalUpdate(updater, old)\n\n return newState\n }\n\n return table.options.onPaginationChange?.(safeUpdater)\n }\n table.resetPagination = defaultState => {\n table.setPagination(\n defaultState\n ? getDefaultPaginationState()\n : table.initialState.pagination ?? getDefaultPaginationState()\n )\n }\n table.setPageIndex = updater => {\n table.setPagination(old => {\n let pageIndex = functionalUpdate(updater, old.pageIndex)\n\n const maxPageIndex =\n typeof table.options.pageCount === 'undefined' ||\n table.options.pageCount === -1\n ? Number.MAX_SAFE_INTEGER\n : table.options.pageCount - 1\n\n pageIndex = Math.max(0, Math.min(pageIndex, maxPageIndex))\n\n return {\n ...old,\n pageIndex,\n }\n })\n }\n table.resetPageIndex = defaultState => {\n table.setPageIndex(\n defaultState\n ? defaultPageIndex\n : table.initialState?.pagination?.pageIndex ?? defaultPageIndex\n )\n }\n table.resetPageSize = defaultState => {\n table.setPageSize(\n defaultState\n ? defaultPageSize\n : table.initialState?.pagination?.pageSize ?? defaultPageSize\n )\n }\n table.setPageSize = updater => {\n table.setPagination(old => {\n const pageSize = Math.max(1, functionalUpdate(updater, old.pageSize))\n const topRowIndex = old.pageSize * old.pageIndex!\n const pageIndex = Math.floor(topRowIndex / pageSize)\n\n return {\n ...old,\n pageIndex,\n pageSize,\n }\n })\n }\n //deprecated\n table.setPageCount = updater =>\n table.setPagination(old => {\n let newPageCount = functionalUpdate(\n updater,\n table.options.pageCount ?? -1\n )\n\n if (typeof newPageCount === 'number') {\n newPageCount = Math.max(-1, newPageCount)\n }\n\n return {\n ...old,\n pageCount: newPageCount,\n }\n })\n\n table.getPageOptions = memo(\n () => [table.getPageCount()],\n pageCount => {\n let pageOptions: number[] = []\n if (pageCount && pageCount > 0) {\n pageOptions = [...new Array(pageCount)].fill(null).map((_, i) => i)\n }\n return pageOptions\n },\n getMemoOptions(table.options, 'debugTable', 'getPageOptions')\n )\n\n table.getCanPreviousPage = () => table.getState().pagination.pageIndex > 0\n\n table.getCanNextPage = () => {\n const { pageIndex } = table.getState().pagination\n\n const pageCount = table.getPageCount()\n\n if (pageCount === -1) {\n return true\n }\n\n if (pageCount === 0) {\n return false\n }\n\n return pageIndex < pageCount - 1\n }\n\n table.previousPage = () => {\n return table.setPageIndex(old => old - 1)\n }\n\n table.nextPage = () => {\n return table.setPageIndex(old => {\n return old + 1\n })\n }\n\n table.firstPage = () => {\n return table.setPageIndex(0)\n }\n\n table.lastPage = () => {\n return table.setPageIndex(table.getPageCount() - 1)\n }\n\n table.getPrePaginationRowModel = () => table.getExpandedRowModel()\n table.getPaginationRowModel = () => {\n if (\n !table._getPaginationRowModel &&\n table.options.getPaginationRowModel\n ) {\n table._getPaginationRowModel =\n table.options.getPaginationRowModel(table)\n }\n\n if (table.options.manualPagination || !table._getPaginationRowModel) {\n return table.getPrePaginationRowModel()\n }\n\n return table._getPaginationRowModel()\n }\n\n table.getPageCount = () => {\n return (\n table.options.pageCount ??\n Math.ceil(table.getRowCount() / table.getState().pagination.pageSize)\n )\n }\n\n table.getRowCount = () => {\n return (\n table.options.rowCount ?? table.getPrePaginationRowModel().rows.length\n )\n }\n },\n}\n"],"names":[],"m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