@tanstack/table-core 8.17.3 → 9.0.0-alpha.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.
- package/dist/cjs/aggregationFns.cjs +98 -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 +93 -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 +228 -0
- package/dist/cjs/core/table.cjs.map +1 -0
- package/dist/cjs/core/table.d.cts +221 -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 +134 -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 +308 -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 +154 -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 +162 -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 +133 -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 +298 -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 +201 -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} +36 -49
- 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 +36 -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 +38 -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 +91 -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} +30 -41
- 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 +98 -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 +1 -0
- package/dist/esm/core/cell.js +38 -0
- package/{build/lib → dist/esm}/core/cell.js.map +1 -1
- package/{build/lib → dist/esm}/core/column.d.ts +1 -0
- package/dist/esm/core/column.js +81 -0
- package/{build/lib → dist/esm}/core/column.js.map +1 -1
- package/{build/lib → dist/esm}/core/headers.d.ts +1 -0
- package/dist/esm/core/headers.js +310 -0
- package/{build/lib → dist/esm}/core/headers.js.map +1 -1
- package/{build/lib → dist/esm}/core/row.d.ts +1 -0
- package/dist/esm/core/row.js +93 -0
- package/{build/lib → dist/esm}/core/row.js.map +1 -1
- package/{build/lib → dist/esm}/core/table.d.ts +1 -0
- package/dist/esm/core/table.js +228 -0
- package/{build/lib → dist/esm}/core/table.js.map +1 -1
- package/{build/lib → dist/esm}/features/ColumnFaceting.d.ts +1 -0
- package/{build/lib → dist/esm}/features/ColumnFaceting.js +5 -18
- 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/{build/lib → dist/esm}/features/ColumnFiltering.js.map +1 -1
- package/{build/lib → dist/esm}/features/ColumnGrouping.d.ts +1 -0
- package/dist/esm/features/ColumnGrouping.js +134 -0
- package/{build/lib → dist/esm}/features/ColumnGrouping.js.map +1 -1
- package/{build/lib → dist/esm}/features/ColumnOrdering.d.ts +1 -0
- package/dist/esm/features/ColumnOrdering.js +76 -0
- package/{build/lib → dist/esm}/features/ColumnOrdering.js.map +1 -1
- package/{build/lib → dist/esm}/features/ColumnPinning.d.ts +1 -0
- package/dist/esm/features/ColumnPinning.js +145 -0
- package/{build/lib → dist/esm}/features/ColumnPinning.js.map +1 -1
- package/{build/lib → dist/esm}/features/ColumnSizing.d.ts +2 -1
- package/dist/esm/features/ColumnSizing.js +308 -0
- package/{build/lib → dist/esm}/features/ColumnSizing.js.map +1 -1
- package/{build/lib → dist/esm}/features/ColumnVisibility.d.ts +1 -0
- package/dist/esm/features/ColumnVisibility.js +144 -0
- package/{build/lib → dist/esm}/features/ColumnVisibility.js.map +1 -1
- package/{build/lib → dist/esm}/features/GlobalFaceting.d.ts +1 -0
- package/{build/lib → dist/esm}/features/GlobalFaceting.js +8 -21
- package/{build/lib → dist/esm}/features/GlobalFaceting.js.map +1 -1
- package/{build/lib → dist/esm}/features/GlobalFiltering.d.ts +1 -0
- package/dist/esm/features/GlobalFiltering.js +50 -0
- package/{build/lib → dist/esm}/features/GlobalFiltering.js.map +1 -1
- package/{build/lib → dist/esm}/features/RowExpanding.d.ts +1 -0
- package/{build/lib → dist/esm}/features/RowExpanding.js +40 -59
- package/{build/lib → dist/esm}/features/RowExpanding.js.map +1 -1
- package/{build/lib → dist/esm}/features/RowPagination.d.ts +1 -0
- package/dist/esm/features/RowPagination.js +162 -0
- package/{build/lib → dist/esm}/features/RowPagination.js.map +1 -1
- package/{build/lib → dist/esm}/features/RowPinning.d.ts +1 -0
- package/dist/esm/features/RowPinning.js +133 -0
- package/{build/lib → dist/esm}/features/RowPinning.js.map +1 -1
- package/{build/lib → dist/esm}/features/RowSelection.d.ts +1 -0
- package/dist/esm/features/RowSelection.js +298 -0
- package/{build/lib → dist/esm}/features/RowSelection.js.map +1 -1
- package/{build/lib → dist/esm}/features/RowSorting.d.ts +1 -0
- package/dist/esm/features/RowSorting.js +201 -0
- package/{build/lib → dist/esm}/features/RowSorting.js.map +1 -1
- 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 +87 -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 +21 -20
- 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/{build/lib → dist/esm}/utils/getCoreRowModel.js.map +1 -1
- 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 +36 -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 +38 -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/{build/lib → dist/esm}/utils/getGroupedRowModel.js.map +1 -1
- 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 +91 -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 +100 -0
- package/{build/lib → dist/esm}/utils.js.map +1 -1
- package/package.json +15 -19
- 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/column.js +0 -80
- package/build/lib/core/headers.js +0 -270
- package/build/lib/core/row.js +0 -89
- package/build/lib/core/table.js +0 -212
- package/build/lib/features/ColumnFiltering.js +0 -151
- package/build/lib/features/ColumnGrouping.js +0 -142
- package/build/lib/features/ColumnOrdering.js +0 -84
- package/build/lib/features/ColumnPinning.js +0 -130
- package/build/lib/features/ColumnSizing.js +0 -270
- package/build/lib/features/ColumnVisibility.js +0 -99
- package/build/lib/features/GlobalFiltering.js +0 -63
- package/build/lib/features/RowPagination.js +0 -169
- package/build/lib/features/RowPinning.js +0 -145
- package/build/lib/features/RowSelection.js +0 -391
- package/build/lib/features/RowSorting.js +0 -226
- 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/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/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,298 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const utils = require("../utils.cjs");
|
|
4
|
+
const RowSelection = {
|
|
5
|
+
getInitialState: (state) => {
|
|
6
|
+
return {
|
|
7
|
+
rowSelection: {},
|
|
8
|
+
...state
|
|
9
|
+
};
|
|
10
|
+
},
|
|
11
|
+
getDefaultOptions: (table) => {
|
|
12
|
+
return {
|
|
13
|
+
onRowSelectionChange: utils.makeStateUpdater("rowSelection", table),
|
|
14
|
+
enableRowSelection: true,
|
|
15
|
+
enableMultiRowSelection: true,
|
|
16
|
+
enableSubRowSelection: true
|
|
17
|
+
// enableGroupingRowSelection: false,
|
|
18
|
+
// isAdditiveSelectEvent: (e: unknown) => !!e.metaKey,
|
|
19
|
+
// isInclusiveSelectEvent: (e: unknown) => !!e.shiftKey,
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
createTable: (table) => {
|
|
23
|
+
table.setRowSelection = (updater) => {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
return (_b = (_a = table.options).onRowSelectionChange) == null ? void 0 : _b.call(_a, updater);
|
|
26
|
+
};
|
|
27
|
+
table.resetRowSelection = (defaultState) => table.setRowSelection(
|
|
28
|
+
defaultState ? {} : table.initialState.rowSelection ?? {}
|
|
29
|
+
);
|
|
30
|
+
table.toggleAllRowsSelected = (value) => {
|
|
31
|
+
table.setRowSelection((old) => {
|
|
32
|
+
value = typeof value !== "undefined" ? value : !table.getIsAllRowsSelected();
|
|
33
|
+
const rowSelection = { ...old };
|
|
34
|
+
const preGroupedFlatRows = table.getPreGroupedRowModel().flatRows;
|
|
35
|
+
if (value) {
|
|
36
|
+
preGroupedFlatRows.forEach((row) => {
|
|
37
|
+
if (!row.getCanSelect()) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
rowSelection[row.id] = true;
|
|
41
|
+
});
|
|
42
|
+
} else {
|
|
43
|
+
preGroupedFlatRows.forEach((row) => {
|
|
44
|
+
delete rowSelection[row.id];
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return rowSelection;
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
table.toggleAllPageRowsSelected = (value) => table.setRowSelection((old) => {
|
|
51
|
+
const resolvedValue = typeof value !== "undefined" ? value : !table.getIsAllPageRowsSelected();
|
|
52
|
+
const rowSelection = { ...old };
|
|
53
|
+
table.getRowModel().rows.forEach((row) => {
|
|
54
|
+
mutateRowIsSelected(rowSelection, row.id, resolvedValue, true, table);
|
|
55
|
+
});
|
|
56
|
+
return rowSelection;
|
|
57
|
+
});
|
|
58
|
+
table.getPreSelectedRowModel = () => table.getCoreRowModel();
|
|
59
|
+
table.getSelectedRowModel = utils.memo(
|
|
60
|
+
() => [table.getState().rowSelection, table.getCoreRowModel()],
|
|
61
|
+
(rowSelection, rowModel) => {
|
|
62
|
+
if (!Object.keys(rowSelection).length) {
|
|
63
|
+
return {
|
|
64
|
+
rows: [],
|
|
65
|
+
flatRows: [],
|
|
66
|
+
rowsById: {}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return selectRowsFn(table, rowModel);
|
|
70
|
+
},
|
|
71
|
+
utils.getMemoOptions(table.options, "debugTable", "getSelectedRowModel")
|
|
72
|
+
);
|
|
73
|
+
table.getFilteredSelectedRowModel = utils.memo(
|
|
74
|
+
() => [table.getState().rowSelection, table.getFilteredRowModel()],
|
|
75
|
+
(rowSelection, rowModel) => {
|
|
76
|
+
if (!Object.keys(rowSelection).length) {
|
|
77
|
+
return {
|
|
78
|
+
rows: [],
|
|
79
|
+
flatRows: [],
|
|
80
|
+
rowsById: {}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
return selectRowsFn(table, rowModel);
|
|
84
|
+
},
|
|
85
|
+
utils.getMemoOptions(table.options, "debugTable", "getFilteredSelectedRowModel")
|
|
86
|
+
);
|
|
87
|
+
table.getGroupedSelectedRowModel = utils.memo(
|
|
88
|
+
() => [table.getState().rowSelection, table.getSortedRowModel()],
|
|
89
|
+
(rowSelection, rowModel) => {
|
|
90
|
+
if (!Object.keys(rowSelection).length) {
|
|
91
|
+
return {
|
|
92
|
+
rows: [],
|
|
93
|
+
flatRows: [],
|
|
94
|
+
rowsById: {}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return selectRowsFn(table, rowModel);
|
|
98
|
+
},
|
|
99
|
+
utils.getMemoOptions(table.options, "debugTable", "getGroupedSelectedRowModel")
|
|
100
|
+
);
|
|
101
|
+
table.getIsAllRowsSelected = () => {
|
|
102
|
+
const preGroupedFlatRows = table.getFilteredRowModel().flatRows;
|
|
103
|
+
const { rowSelection } = table.getState();
|
|
104
|
+
let isAllRowsSelected = Boolean(
|
|
105
|
+
preGroupedFlatRows.length && Object.keys(rowSelection).length
|
|
106
|
+
);
|
|
107
|
+
if (isAllRowsSelected) {
|
|
108
|
+
if (preGroupedFlatRows.some(
|
|
109
|
+
(row) => row.getCanSelect() && !rowSelection[row.id]
|
|
110
|
+
)) {
|
|
111
|
+
isAllRowsSelected = false;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return isAllRowsSelected;
|
|
115
|
+
};
|
|
116
|
+
table.getIsAllPageRowsSelected = () => {
|
|
117
|
+
const paginationFlatRows = table.getPaginationRowModel().flatRows.filter((row) => row.getCanSelect());
|
|
118
|
+
const { rowSelection } = table.getState();
|
|
119
|
+
let isAllPageRowsSelected = !!paginationFlatRows.length;
|
|
120
|
+
if (isAllPageRowsSelected && paginationFlatRows.some((row) => !rowSelection[row.id])) {
|
|
121
|
+
isAllPageRowsSelected = false;
|
|
122
|
+
}
|
|
123
|
+
return isAllPageRowsSelected;
|
|
124
|
+
};
|
|
125
|
+
table.getIsSomeRowsSelected = () => {
|
|
126
|
+
const totalSelected = Object.keys(
|
|
127
|
+
table.getState().rowSelection ?? {}
|
|
128
|
+
).length;
|
|
129
|
+
return totalSelected > 0 && totalSelected < table.getFilteredRowModel().flatRows.length;
|
|
130
|
+
};
|
|
131
|
+
table.getIsSomePageRowsSelected = () => {
|
|
132
|
+
const paginationFlatRows = table.getPaginationRowModel().flatRows;
|
|
133
|
+
return table.getIsAllPageRowsSelected() ? false : paginationFlatRows.filter((row) => row.getCanSelect()).some((d) => d.getIsSelected() || d.getIsSomeSelected());
|
|
134
|
+
};
|
|
135
|
+
table.getToggleAllRowsSelectedHandler = () => {
|
|
136
|
+
return (e) => {
|
|
137
|
+
table.toggleAllRowsSelected(
|
|
138
|
+
e.target.checked
|
|
139
|
+
);
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
table.getToggleAllPageRowsSelectedHandler = () => {
|
|
143
|
+
return (e) => {
|
|
144
|
+
table.toggleAllPageRowsSelected(
|
|
145
|
+
e.target.checked
|
|
146
|
+
);
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
},
|
|
150
|
+
createRow: (row, table) => {
|
|
151
|
+
row.toggleSelected = (value, opts) => {
|
|
152
|
+
const isSelected = row.getIsSelected();
|
|
153
|
+
table.setRowSelection((old) => {
|
|
154
|
+
value = typeof value !== "undefined" ? value : !isSelected;
|
|
155
|
+
if (row.getCanSelect() && isSelected === value) {
|
|
156
|
+
return old;
|
|
157
|
+
}
|
|
158
|
+
const selectedRowIds = { ...old };
|
|
159
|
+
mutateRowIsSelected(
|
|
160
|
+
selectedRowIds,
|
|
161
|
+
row.id,
|
|
162
|
+
value,
|
|
163
|
+
(opts == null ? void 0 : opts.selectChildren) ?? true,
|
|
164
|
+
table
|
|
165
|
+
);
|
|
166
|
+
return selectedRowIds;
|
|
167
|
+
});
|
|
168
|
+
};
|
|
169
|
+
row.getIsSelected = () => {
|
|
170
|
+
const { rowSelection } = table.getState();
|
|
171
|
+
return isRowSelected(row, rowSelection);
|
|
172
|
+
};
|
|
173
|
+
row.getIsSomeSelected = () => {
|
|
174
|
+
const { rowSelection } = table.getState();
|
|
175
|
+
return isSubRowSelected(row, rowSelection) === "some";
|
|
176
|
+
};
|
|
177
|
+
row.getIsAllSubRowsSelected = () => {
|
|
178
|
+
const { rowSelection } = table.getState();
|
|
179
|
+
return isSubRowSelected(row, rowSelection) === "all";
|
|
180
|
+
};
|
|
181
|
+
row.getCanSelect = () => {
|
|
182
|
+
if (typeof table.options.enableRowSelection === "function") {
|
|
183
|
+
return table.options.enableRowSelection(row);
|
|
184
|
+
}
|
|
185
|
+
return table.options.enableRowSelection ?? true;
|
|
186
|
+
};
|
|
187
|
+
row.getCanSelectSubRows = () => {
|
|
188
|
+
if (typeof table.options.enableSubRowSelection === "function") {
|
|
189
|
+
return table.options.enableSubRowSelection(row);
|
|
190
|
+
}
|
|
191
|
+
return table.options.enableSubRowSelection ?? true;
|
|
192
|
+
};
|
|
193
|
+
row.getCanMultiSelect = () => {
|
|
194
|
+
if (typeof table.options.enableMultiRowSelection === "function") {
|
|
195
|
+
return table.options.enableMultiRowSelection(row);
|
|
196
|
+
}
|
|
197
|
+
return table.options.enableMultiRowSelection ?? true;
|
|
198
|
+
};
|
|
199
|
+
row.getToggleSelectedHandler = () => {
|
|
200
|
+
const canSelect = row.getCanSelect();
|
|
201
|
+
return (e) => {
|
|
202
|
+
var _a;
|
|
203
|
+
if (!canSelect)
|
|
204
|
+
return;
|
|
205
|
+
row.toggleSelected(
|
|
206
|
+
(_a = e.target) == null ? void 0 : _a.checked
|
|
207
|
+
);
|
|
208
|
+
};
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
const mutateRowIsSelected = (selectedRowIds, id, value, includeChildren, table) => {
|
|
213
|
+
var _a;
|
|
214
|
+
const row = table.getRow(id, true);
|
|
215
|
+
if (value) {
|
|
216
|
+
if (!row.getCanMultiSelect()) {
|
|
217
|
+
Object.keys(selectedRowIds).forEach((key) => delete selectedRowIds[key]);
|
|
218
|
+
}
|
|
219
|
+
if (row.getCanSelect()) {
|
|
220
|
+
selectedRowIds[id] = true;
|
|
221
|
+
}
|
|
222
|
+
} else {
|
|
223
|
+
delete selectedRowIds[id];
|
|
224
|
+
}
|
|
225
|
+
if (includeChildren && ((_a = row.subRows) == null ? void 0 : _a.length) && row.getCanSelectSubRows()) {
|
|
226
|
+
row.subRows.forEach(
|
|
227
|
+
(row2) => mutateRowIsSelected(selectedRowIds, row2.id, value, includeChildren, table)
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
function selectRowsFn(table, rowModel) {
|
|
232
|
+
const rowSelection = table.getState().rowSelection;
|
|
233
|
+
const newSelectedFlatRows = [];
|
|
234
|
+
const newSelectedRowsById = {};
|
|
235
|
+
const recurseRows = (rows, depth = 0) => {
|
|
236
|
+
return rows.map((row) => {
|
|
237
|
+
var _a;
|
|
238
|
+
const isSelected = isRowSelected(row, rowSelection);
|
|
239
|
+
if (isSelected) {
|
|
240
|
+
newSelectedFlatRows.push(row);
|
|
241
|
+
newSelectedRowsById[row.id] = row;
|
|
242
|
+
}
|
|
243
|
+
if ((_a = row.subRows) == null ? void 0 : _a.length) {
|
|
244
|
+
row = {
|
|
245
|
+
...row,
|
|
246
|
+
subRows: recurseRows(row.subRows, depth + 1)
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
if (isSelected) {
|
|
250
|
+
return row;
|
|
251
|
+
}
|
|
252
|
+
}).filter(Boolean);
|
|
253
|
+
};
|
|
254
|
+
return {
|
|
255
|
+
rows: recurseRows(rowModel.rows),
|
|
256
|
+
flatRows: newSelectedFlatRows,
|
|
257
|
+
rowsById: newSelectedRowsById
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
function isRowSelected(row, selection) {
|
|
261
|
+
return selection[row.id] ?? false;
|
|
262
|
+
}
|
|
263
|
+
function isSubRowSelected(row, selection, table) {
|
|
264
|
+
var _a;
|
|
265
|
+
if (!((_a = row.subRows) == null ? void 0 : _a.length))
|
|
266
|
+
return false;
|
|
267
|
+
let allChildrenSelected = true;
|
|
268
|
+
let someSelected = false;
|
|
269
|
+
row.subRows.forEach((subRow) => {
|
|
270
|
+
if (someSelected && !allChildrenSelected) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
if (subRow.getCanSelect()) {
|
|
274
|
+
if (isRowSelected(subRow, selection)) {
|
|
275
|
+
someSelected = true;
|
|
276
|
+
} else {
|
|
277
|
+
allChildrenSelected = false;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
if (subRow.subRows && subRow.subRows.length) {
|
|
281
|
+
const subRowChildrenSelected = isSubRowSelected(subRow, selection);
|
|
282
|
+
if (subRowChildrenSelected === "all") {
|
|
283
|
+
someSelected = true;
|
|
284
|
+
} else if (subRowChildrenSelected === "some") {
|
|
285
|
+
someSelected = true;
|
|
286
|
+
allChildrenSelected = false;
|
|
287
|
+
} else {
|
|
288
|
+
allChildrenSelected = false;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
return allChildrenSelected ? "all" : someSelected ? "some" : false;
|
|
293
|
+
}
|
|
294
|
+
exports.RowSelection = RowSelection;
|
|
295
|
+
exports.isRowSelected = isRowSelected;
|
|
296
|
+
exports.isSubRowSelected = isSubRowSelected;
|
|
297
|
+
exports.selectRowsFn = selectRowsFn;
|
|
298
|
+
//# sourceMappingURL=RowSelection.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RowSelection.cjs","sources":["../../../src/features/RowSelection.ts"],"sourcesContent":["import {\n OnChangeFn,\n Table,\n Row,\n RowModel,\n Updater,\n RowData,\n TableFeature,\n} from '../types'\nimport { getMemoOptions, makeStateUpdater, memo } from '../utils'\n\nexport type RowSelectionState = Record<string, boolean>\n\nexport interface RowSelectionTableState {\n rowSelection: RowSelectionState\n}\n\nexport interface RowSelectionOptions<TData extends RowData> {\n /**\n * - Enables/disables multiple row selection for all rows in the table OR\n * - A function that given a row, returns whether to enable/disable multiple row selection for that row's children/grandchildren\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#enablemultirowselection)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)\n */\n enableMultiRowSelection?: boolean | ((row: Row<TData>) => boolean)\n /**\n * - Enables/disables row selection for all rows in the table OR\n * - A function that given a row, returns whether to enable/disable row selection for that row\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#enablerowselection)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)\n */\n enableRowSelection?: boolean | ((row: Row<TData>) => boolean)\n /**\n * Enables/disables automatic sub-row selection when a parent row is selected, or a function that enables/disables automatic sub-row selection for each row.\n * (Use in combination with expanding or grouping features)\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#enablesubrowselection)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)\n */\n enableSubRowSelection?: boolean | ((row: Row<TData>) => boolean)\n /**\n * If provided, this function will be called with an `updaterFn` when `state.rowSelection` 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/row-selection#onrowselectionchange)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)\n */\n onRowSelectionChange?: OnChangeFn<RowSelectionState>\n // enableGroupingRowSelection?:\n // | boolean\n // | ((\n // row: Row<TData>\n // ) => boolean)\n // isAdditiveSelectEvent?: (e: unknown) => boolean\n // isInclusiveSelectEvent?: (e: unknown) => boolean\n // selectRowsFn?: (\n // table: Table<TData>,\n // rowModel: RowModel<TData>\n // ) => RowModel<TData>\n}\n\nexport interface RowSelectionRow {\n /**\n * Returns whether or not the row can multi-select.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#getcanmultiselect)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)\n */\n getCanMultiSelect: () => boolean\n /**\n * Returns whether or not the row can be selected.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#getcanselect)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)\n */\n getCanSelect: () => boolean\n /**\n * Returns whether or not the row can select sub rows automatically when the parent row is selected.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#getcanselectsubrows)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)\n */\n getCanSelectSubRows: () => boolean\n /**\n * Returns whether or not all of the row's sub rows are selected.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#getisallsubrowsselected)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)\n */\n getIsAllSubRowsSelected: () => boolean\n /**\n * Returns whether or not the row is selected.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#getisselected)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)\n */\n getIsSelected: () => boolean\n /**\n * Returns whether or not some of the row's sub rows are selected.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#getissomeselected)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)\n */\n getIsSomeSelected: () => boolean\n /**\n * Returns a handler that can be used to toggle the row.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#gettoggleselectedhandler)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)\n */\n getToggleSelectedHandler: () => (event: unknown) => void\n /**\n * Selects/deselects the row.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#toggleselected)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)\n */\n toggleSelected: (value?: boolean, opts?: { selectChildren?: boolean }) => void\n}\n\nexport interface RowSelectionInstance<TData extends RowData> {\n /**\n * Returns the row model of all rows that are selected after filtering has been applied.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#getfilteredselectedrowmodel)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)\n */\n getFilteredSelectedRowModel: () => RowModel<TData>\n /**\n * Returns the row model of all rows that are selected after grouping has been applied.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#getgroupedselectedrowmodel)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)\n */\n getGroupedSelectedRowModel: () => RowModel<TData>\n /**\n * Returns whether or not all rows on the current page are selected.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#getisallpagerowsselected)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)\n */\n getIsAllPageRowsSelected: () => boolean\n /**\n * Returns whether or not all rows in the table are selected.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#getisallrowsselected)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)\n */\n getIsAllRowsSelected: () => boolean\n /**\n * Returns whether or not any rows on the current page are selected.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#getissomepagerowsselected)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)\n */\n getIsSomePageRowsSelected: () => boolean\n /**\n * Returns whether or not any rows in the table are selected.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#getissomerowsselected)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)\n */\n getIsSomeRowsSelected: () => boolean\n /**\n * Returns the core row model of all rows before row selection has been applied.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#getpreselectedrowmodel)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)\n */\n getPreSelectedRowModel: () => RowModel<TData>\n /**\n * Returns the row model of all rows that are selected.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#getselectedrowmodel)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)\n */\n getSelectedRowModel: () => RowModel<TData>\n /**\n * Returns a handler that can be used to toggle all rows on the current page.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#gettoggleallpagerowsselectedhandler)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)\n */\n getToggleAllPageRowsSelectedHandler: () => (event: unknown) => void\n /**\n * Returns a handler that can be used to toggle all rows in the table.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#gettoggleallrowsselectedhandler)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)\n */\n getToggleAllRowsSelectedHandler: () => (event: unknown) => void\n /**\n * Resets the **rowSelection** state to the `initialState.rowSelection`, 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/row-selection#resetrowselection)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)\n */\n resetRowSelection: (defaultState?: boolean) => void\n /**\n * Sets or updates the `state.rowSelection` state.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#setrowselection)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)\n */\n setRowSelection: (updater: Updater<RowSelectionState>) => void\n /**\n * Selects/deselects all rows on the current page.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#toggleallpagerowsselected)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)\n */\n toggleAllPageRowsSelected: (value?: boolean) => void\n /**\n * Selects/deselects all rows in the table.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#toggleallrowsselected)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)\n */\n toggleAllRowsSelected: (value?: boolean) => void\n}\n\n//\n\nexport const RowSelection: TableFeature = {\n getInitialState: (state): RowSelectionTableState => {\n return {\n rowSelection: {},\n ...state,\n }\n },\n\n getDefaultOptions: <TData extends RowData>(\n table: Table<TData>\n ): RowSelectionOptions<TData> => {\n return {\n onRowSelectionChange: makeStateUpdater('rowSelection', table),\n enableRowSelection: true,\n enableMultiRowSelection: true,\n enableSubRowSelection: true,\n // enableGroupingRowSelection: false,\n // isAdditiveSelectEvent: (e: unknown) => !!e.metaKey,\n // isInclusiveSelectEvent: (e: unknown) => !!e.shiftKey,\n }\n },\n\n createTable: <TData extends RowData>(table: Table<TData>): void => {\n table.setRowSelection = updater =>\n table.options.onRowSelectionChange?.(updater)\n table.resetRowSelection = defaultState =>\n table.setRowSelection(\n defaultState ? {} : table.initialState.rowSelection ?? {}\n )\n table.toggleAllRowsSelected = value => {\n table.setRowSelection(old => {\n value =\n typeof value !== 'undefined' ? value : !table.getIsAllRowsSelected()\n\n const rowSelection = { ...old }\n\n const preGroupedFlatRows = table.getPreGroupedRowModel().flatRows\n\n // We don't use `mutateRowIsSelected` here for performance reasons.\n // All of the rows are flat already, so it wouldn't be worth it\n if (value) {\n preGroupedFlatRows.forEach(row => {\n if (!row.getCanSelect()) {\n return\n }\n rowSelection[row.id] = true\n })\n } else {\n preGroupedFlatRows.forEach(row => {\n delete rowSelection[row.id]\n })\n }\n\n return rowSelection\n })\n }\n table.toggleAllPageRowsSelected = value =>\n table.setRowSelection(old => {\n const resolvedValue =\n typeof value !== 'undefined'\n ? value\n : !table.getIsAllPageRowsSelected()\n\n const rowSelection: RowSelectionState = { ...old }\n\n table.getRowModel().rows.forEach(row => {\n mutateRowIsSelected(rowSelection, row.id, resolvedValue, true, table)\n })\n\n return rowSelection\n })\n\n // addRowSelectionRange: rowId => {\n // const {\n // rows,\n // rowsById,\n // options: { selectGroupingRows, selectSubRows },\n // } = table\n\n // const findSelectedRow = (rows: Row[]) => {\n // let found\n // rows.find(d => {\n // if (d.getIsSelected()) {\n // found = d\n // return true\n // }\n // const subFound = findSelectedRow(d.subRows || [])\n // if (subFound) {\n // found = subFound\n // return true\n // }\n // return false\n // })\n // return found\n // }\n\n // const firstRow = findSelectedRow(rows) || rows[0]\n // const lastRow = rowsById[rowId]\n\n // let include = false\n // const selectedRowIds = {}\n\n // const addRow = (row: Row) => {\n // mutateRowIsSelected(selectedRowIds, row.id, true, {\n // rowsById,\n // selectGroupingRows: selectGroupingRows!,\n // selectSubRows: selectSubRows!,\n // })\n // }\n\n // table.rows.forEach(row => {\n // const isFirstRow = row.id === firstRow.id\n // const isLastRow = row.id === lastRow.id\n\n // if (isFirstRow || isLastRow) {\n // if (!include) {\n // include = true\n // } else if (include) {\n // addRow(row)\n // include = false\n // }\n // }\n\n // if (include) {\n // addRow(row)\n // }\n // })\n\n // table.setRowSelection(selectedRowIds)\n // },\n table.getPreSelectedRowModel = () => table.getCoreRowModel()\n table.getSelectedRowModel = memo(\n () => [table.getState().rowSelection, table.getCoreRowModel()],\n (rowSelection, rowModel) => {\n if (!Object.keys(rowSelection).length) {\n return {\n rows: [],\n flatRows: [],\n rowsById: {},\n }\n }\n\n return selectRowsFn(table, rowModel)\n },\n getMemoOptions(table.options, 'debugTable', 'getSelectedRowModel')\n )\n\n table.getFilteredSelectedRowModel = memo(\n () => [table.getState().rowSelection, table.getFilteredRowModel()],\n (rowSelection, rowModel) => {\n if (!Object.keys(rowSelection).length) {\n return {\n rows: [],\n flatRows: [],\n rowsById: {},\n }\n }\n\n return selectRowsFn(table, rowModel)\n },\n getMemoOptions(table.options, 'debugTable', 'getFilteredSelectedRowModel')\n )\n\n table.getGroupedSelectedRowModel = memo(\n () => [table.getState().rowSelection, table.getSortedRowModel()],\n (rowSelection, rowModel) => {\n if (!Object.keys(rowSelection).length) {\n return {\n rows: [],\n flatRows: [],\n rowsById: {},\n }\n }\n\n return selectRowsFn(table, rowModel)\n },\n getMemoOptions(table.options, 'debugTable', 'getGroupedSelectedRowModel')\n )\n\n ///\n\n // getGroupingRowCanSelect: rowId => {\n // const row = table.getRow(rowId)\n\n // if (!row) {\n // throw new Error()\n // }\n\n // if (typeof table.options.enableGroupingRowSelection === 'function') {\n // return table.options.enableGroupingRowSelection(row)\n // }\n\n // return table.options.enableGroupingRowSelection ?? false\n // },\n\n table.getIsAllRowsSelected = () => {\n const preGroupedFlatRows = table.getFilteredRowModel().flatRows\n const { rowSelection } = table.getState()\n\n let isAllRowsSelected = Boolean(\n preGroupedFlatRows.length && Object.keys(rowSelection).length\n )\n\n if (isAllRowsSelected) {\n if (\n preGroupedFlatRows.some(\n row => row.getCanSelect() && !rowSelection[row.id]\n )\n ) {\n isAllRowsSelected = false\n }\n }\n\n return isAllRowsSelected\n }\n\n table.getIsAllPageRowsSelected = () => {\n const paginationFlatRows = table\n .getPaginationRowModel()\n .flatRows.filter(row => row.getCanSelect())\n const { rowSelection } = table.getState()\n\n let isAllPageRowsSelected = !!paginationFlatRows.length\n\n if (\n isAllPageRowsSelected &&\n paginationFlatRows.some(row => !rowSelection[row.id])\n ) {\n isAllPageRowsSelected = false\n }\n\n return isAllPageRowsSelected\n }\n\n table.getIsSomeRowsSelected = () => {\n const totalSelected = Object.keys(\n table.getState().rowSelection ?? {}\n ).length\n return (\n totalSelected > 0 &&\n totalSelected < table.getFilteredRowModel().flatRows.length\n )\n }\n\n table.getIsSomePageRowsSelected = () => {\n const paginationFlatRows = table.getPaginationRowModel().flatRows\n return table.getIsAllPageRowsSelected()\n ? false\n : paginationFlatRows\n .filter(row => row.getCanSelect())\n .some(d => d.getIsSelected() || d.getIsSomeSelected())\n }\n\n table.getToggleAllRowsSelectedHandler = () => {\n return (e: unknown) => {\n table.toggleAllRowsSelected(\n ((e as MouseEvent).target as HTMLInputElement).checked\n )\n }\n }\n\n table.getToggleAllPageRowsSelectedHandler = () => {\n return (e: unknown) => {\n table.toggleAllPageRowsSelected(\n ((e as MouseEvent).target as HTMLInputElement).checked\n )\n }\n }\n },\n\n createRow: <TData extends RowData>(\n row: Row<TData>,\n table: Table<TData>\n ): void => {\n row.toggleSelected = (value, opts) => {\n const isSelected = row.getIsSelected()\n\n table.setRowSelection(old => {\n value = typeof value !== 'undefined' ? value : !isSelected\n\n if (row.getCanSelect() && isSelected === value) {\n return old\n }\n\n const selectedRowIds = { ...old }\n\n mutateRowIsSelected(\n selectedRowIds,\n row.id,\n value,\n opts?.selectChildren ?? true,\n table\n )\n\n return selectedRowIds\n })\n }\n row.getIsSelected = () => {\n const { rowSelection } = table.getState()\n return isRowSelected(row, rowSelection)\n }\n\n row.getIsSomeSelected = () => {\n const { rowSelection } = table.getState()\n return isSubRowSelected(row, rowSelection, table) === 'some'\n }\n\n row.getIsAllSubRowsSelected = () => {\n const { rowSelection } = table.getState()\n return isSubRowSelected(row, rowSelection, table) === 'all'\n }\n\n row.getCanSelect = () => {\n if (typeof table.options.enableRowSelection === 'function') {\n return table.options.enableRowSelection(row)\n }\n\n return table.options.enableRowSelection ?? true\n }\n\n row.getCanSelectSubRows = () => {\n if (typeof table.options.enableSubRowSelection === 'function') {\n return table.options.enableSubRowSelection(row)\n }\n\n return table.options.enableSubRowSelection ?? true\n }\n\n row.getCanMultiSelect = () => {\n if (typeof table.options.enableMultiRowSelection === 'function') {\n return table.options.enableMultiRowSelection(row)\n }\n\n return table.options.enableMultiRowSelection ?? true\n }\n row.getToggleSelectedHandler = () => {\n const canSelect = row.getCanSelect()\n\n return (e: unknown) => {\n if (!canSelect) return\n row.toggleSelected(\n ((e as MouseEvent).target as HTMLInputElement)?.checked\n )\n }\n }\n },\n}\n\nconst mutateRowIsSelected = <TData extends RowData>(\n selectedRowIds: Record<string, boolean>,\n id: string,\n value: boolean,\n includeChildren: boolean,\n table: Table<TData>\n) => {\n const row = table.getRow(id, true)\n\n // const isGrouped = row.getIsGrouped()\n\n // if ( // TODO: enforce grouping row selection rules\n // !isGrouped ||\n // (isGrouped && table.options.enableGroupingRowSelection)\n // ) {\n if (value) {\n if (!row.getCanMultiSelect()) {\n Object.keys(selectedRowIds).forEach(key => delete selectedRowIds[key])\n }\n if (row.getCanSelect()) {\n selectedRowIds[id] = true\n }\n } else {\n delete selectedRowIds[id]\n }\n // }\n\n if (includeChildren && row.subRows?.length && row.getCanSelectSubRows()) {\n row.subRows.forEach(row =>\n mutateRowIsSelected(selectedRowIds, row.id, value, includeChildren, table)\n )\n }\n}\n\nexport function selectRowsFn<TData extends RowData>(\n table: Table<TData>,\n rowModel: RowModel<TData>\n): RowModel<TData> {\n const rowSelection = table.getState().rowSelection\n\n const newSelectedFlatRows: Row<TData>[] = []\n const newSelectedRowsById: Record<string, Row<TData>> = {}\n\n // Filters top level and nested rows\n const recurseRows = (rows: Row<TData>[], depth = 0): Row<TData>[] => {\n return rows\n .map(row => {\n const isSelected = isRowSelected(row, rowSelection)\n\n if (isSelected) {\n newSelectedFlatRows.push(row)\n newSelectedRowsById[row.id] = row\n }\n\n if (row.subRows?.length) {\n row = {\n ...row,\n subRows: recurseRows(row.subRows, depth + 1),\n }\n }\n\n if (isSelected) {\n return row\n }\n })\n .filter(Boolean) as Row<TData>[]\n }\n\n return {\n rows: recurseRows(rowModel.rows),\n flatRows: newSelectedFlatRows,\n rowsById: newSelectedRowsById,\n }\n}\n\nexport function isRowSelected<TData extends RowData>(\n row: Row<TData>,\n selection: Record<string, boolean>\n): boolean {\n return selection[row.id] ?? false\n}\n\nexport function isSubRowSelected<TData extends RowData>(\n row: Row<TData>,\n selection: Record<string, boolean>,\n table: Table<TData>\n): boolean | 'some' | 'all' {\n if (!row.subRows?.length) return false\n\n let allChildrenSelected = true\n let someSelected = false\n\n row.subRows.forEach(subRow => {\n // Bail out early if we know both of these\n if (someSelected && !allChildrenSelected) {\n return\n }\n\n if (subRow.getCanSelect()) {\n if (isRowSelected(subRow, selection)) {\n someSelected = true\n } else {\n allChildrenSelected = false\n }\n }\n\n // Check row selection of nested subrows\n if (subRow.subRows && subRow.subRows.length) {\n const subRowChildrenSelected = isSubRowSelected(subRow, selection, table)\n if (subRowChildrenSelected === 'all') {\n someSelected = true\n } else if (subRowChildrenSelected === 'some') {\n someSelected = true\n allChildrenSelected = false\n } else {\n allChildrenSelected = false\n }\n }\n })\n\n return allChildrenSelected ? 'all' : someSelected ? 'some' : false\n}\n"],"names":["makeStateUpdater","memo","getMemoOptions","row"],"mappings":";;;AAsMO,MAAM,eAA6B;AAAA,EACxC,iBAAiB,CAAC,UAAkC;AAC3C,WAAA;AAAA,MACL,cAAc,CAAC;AAAA,MACf,GAAG;AAAA,IAAA;AAAA,EAEP;AAAA,EAEA,mBAAmB,CACjB,UAC+B;AACxB,WAAA;AAAA,MACL,sBAAsBA,MAAAA,iBAAiB,gBAAgB,KAAK;AAAA,MAC5D,oBAAoB;AAAA,MACpB,yBAAyB;AAAA,MACzB,uBAAuB;AAAA;AAAA;AAAA;AAAA,IAAA;AAAA,EAK3B;AAAA,EAEA,aAAa,CAAwB,UAA8B;AACjE,UAAM,kBAAkB,CAAA,YAAA;;AACtB,+BAAM,SAAQ,yBAAd,4BAAqC;AAAA;AACjC,UAAA,oBAAoB,kBACxB,MAAM;AAAA,MACJ,eAAe,CAAA,IAAK,MAAM,aAAa,gBAAgB,CAAC;AAAA,IAAA;AAE5D,UAAM,wBAAwB,CAAS,UAAA;AACrC,YAAM,gBAAgB,CAAO,QAAA;AAC3B,gBACE,OAAO,UAAU,cAAc,QAAQ,CAAC,MAAM;AAE1C,cAAA,eAAe,EAAE,GAAG;AAEpB,cAAA,qBAAqB,MAAM,sBAAA,EAAwB;AAIzD,YAAI,OAAO;AACT,6BAAmB,QAAQ,CAAO,QAAA;AAC5B,gBAAA,CAAC,IAAI,gBAAgB;AACvB;AAAA,YACF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OAAO,QAAQ,QAAQ;AAC3C,YAAM,yBAAyB,iBAAiB,QAAQ,SAAgB;AACxE,UAAI,2BAA2B,OAAO;AACrB,uBAAA;AAAA,MAAA,WACN,2BAA2B,QAAQ;AAC7B,uBAAA;AACO,8BAAA;AAAA,MAAA,OACjB;AACiB,8BAAA;AAAA,MACxB;AAAA,IACF;AAAA,EAAA,CACD;AAEM,SAAA,sBAAsB,QAAQ,eAAe,SAAS;AAC/D;;;;;"}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { OnChangeFn, Table, Row, RowModel, Updater, RowData, TableFeature } from '../types';
|
|
2
|
+
|
|
3
|
+
export type RowSelectionState = Record<string, boolean>;
|
|
4
|
+
export interface RowSelectionTableState {
|
|
5
|
+
rowSelection: RowSelectionState;
|
|
6
|
+
}
|
|
7
|
+
export interface RowSelectionOptions<TData extends RowData> {
|
|
8
|
+
/**
|
|
9
|
+
* - Enables/disables multiple row selection for all rows in the table OR
|
|
10
|
+
* - A function that given a row, returns whether to enable/disable multiple row selection for that row's children/grandchildren
|
|
11
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#enablemultirowselection)
|
|
12
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)
|
|
13
|
+
*/
|
|
14
|
+
enableMultiRowSelection?: boolean | ((row: Row<TData>) => boolean);
|
|
15
|
+
/**
|
|
16
|
+
* - Enables/disables row selection for all rows in the table OR
|
|
17
|
+
* - A function that given a row, returns whether to enable/disable row selection for that row
|
|
18
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#enablerowselection)
|
|
19
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)
|
|
20
|
+
*/
|
|
21
|
+
enableRowSelection?: boolean | ((row: Row<TData>) => boolean);
|
|
22
|
+
/**
|
|
23
|
+
* Enables/disables automatic sub-row selection when a parent row is selected, or a function that enables/disables automatic sub-row selection for each row.
|
|
24
|
+
* (Use in combination with expanding or grouping features)
|
|
25
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#enablesubrowselection)
|
|
26
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)
|
|
27
|
+
*/
|
|
28
|
+
enableSubRowSelection?: boolean | ((row: Row<TData>) => boolean);
|
|
29
|
+
/**
|
|
30
|
+
* If provided, this function will be called with an `updaterFn` when `state.rowSelection` 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.
|
|
31
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#onrowselectionchange)
|
|
32
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)
|
|
33
|
+
*/
|
|
34
|
+
onRowSelectionChange?: OnChangeFn<RowSelectionState>;
|
|
35
|
+
}
|
|
36
|
+
export interface RowSelectionRow {
|
|
37
|
+
/**
|
|
38
|
+
* Returns whether or not the row can multi-select.
|
|
39
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#getcanmultiselect)
|
|
40
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)
|
|
41
|
+
*/
|
|
42
|
+
getCanMultiSelect: () => boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Returns whether or not the row can be selected.
|
|
45
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#getcanselect)
|
|
46
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)
|
|
47
|
+
*/
|
|
48
|
+
getCanSelect: () => boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Returns whether or not the row can select sub rows automatically when the parent row is selected.
|
|
51
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#getcanselectsubrows)
|
|
52
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)
|
|
53
|
+
*/
|
|
54
|
+
getCanSelectSubRows: () => boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Returns whether or not all of the row's sub rows are selected.
|
|
57
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#getisallsubrowsselected)
|
|
58
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)
|
|
59
|
+
*/
|
|
60
|
+
getIsAllSubRowsSelected: () => boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Returns whether or not the row is selected.
|
|
63
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#getisselected)
|
|
64
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)
|
|
65
|
+
*/
|
|
66
|
+
getIsSelected: () => boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Returns whether or not some of the row's sub rows are selected.
|
|
69
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#getissomeselected)
|
|
70
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)
|
|
71
|
+
*/
|
|
72
|
+
getIsSomeSelected: () => boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Returns a handler that can be used to toggle the row.
|
|
75
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#gettoggleselectedhandler)
|
|
76
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)
|
|
77
|
+
*/
|
|
78
|
+
getToggleSelectedHandler: () => (event: unknown) => void;
|
|
79
|
+
/**
|
|
80
|
+
* Selects/deselects the row.
|
|
81
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#toggleselected)
|
|
82
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)
|
|
83
|
+
*/
|
|
84
|
+
toggleSelected: (value?: boolean, opts?: {
|
|
85
|
+
selectChildren?: boolean;
|
|
86
|
+
}) => void;
|
|
87
|
+
}
|
|
88
|
+
export interface RowSelectionInstance<TData extends RowData> {
|
|
89
|
+
/**
|
|
90
|
+
* Returns the row model of all rows that are selected after filtering has been applied.
|
|
91
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#getfilteredselectedrowmodel)
|
|
92
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)
|
|
93
|
+
*/
|
|
94
|
+
getFilteredSelectedRowModel: () => RowModel<TData>;
|
|
95
|
+
/**
|
|
96
|
+
* Returns the row model of all rows that are selected after grouping has been applied.
|
|
97
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#getgroupedselectedrowmodel)
|
|
98
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)
|
|
99
|
+
*/
|
|
100
|
+
getGroupedSelectedRowModel: () => RowModel<TData>;
|
|
101
|
+
/**
|
|
102
|
+
* Returns whether or not all rows on the current page are selected.
|
|
103
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#getisallpagerowsselected)
|
|
104
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)
|
|
105
|
+
*/
|
|
106
|
+
getIsAllPageRowsSelected: () => boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Returns whether or not all rows in the table are selected.
|
|
109
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#getisallrowsselected)
|
|
110
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)
|
|
111
|
+
*/
|
|
112
|
+
getIsAllRowsSelected: () => boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Returns whether or not any rows on the current page are selected.
|
|
115
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#getissomepagerowsselected)
|
|
116
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)
|
|
117
|
+
*/
|
|
118
|
+
getIsSomePageRowsSelected: () => boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Returns whether or not any rows in the table are selected.
|
|
121
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#getissomerowsselected)
|
|
122
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)
|
|
123
|
+
*/
|
|
124
|
+
getIsSomeRowsSelected: () => boolean;
|
|
125
|
+
/**
|
|
126
|
+
* Returns the core row model of all rows before row selection has been applied.
|
|
127
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#getpreselectedrowmodel)
|
|
128
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)
|
|
129
|
+
*/
|
|
130
|
+
getPreSelectedRowModel: () => RowModel<TData>;
|
|
131
|
+
/**
|
|
132
|
+
* Returns the row model of all rows that are selected.
|
|
133
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#getselectedrowmodel)
|
|
134
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)
|
|
135
|
+
*/
|
|
136
|
+
getSelectedRowModel: () => RowModel<TData>;
|
|
137
|
+
/**
|
|
138
|
+
* Returns a handler that can be used to toggle all rows on the current page.
|
|
139
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#gettoggleallpagerowsselectedhandler)
|
|
140
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)
|
|
141
|
+
*/
|
|
142
|
+
getToggleAllPageRowsSelectedHandler: () => (event: unknown) => void;
|
|
143
|
+
/**
|
|
144
|
+
* Returns a handler that can be used to toggle all rows in the table.
|
|
145
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#gettoggleallrowsselectedhandler)
|
|
146
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)
|
|
147
|
+
*/
|
|
148
|
+
getToggleAllRowsSelectedHandler: () => (event: unknown) => void;
|
|
149
|
+
/**
|
|
150
|
+
* Resets the **rowSelection** state to the `initialState.rowSelection`, or `true` can be passed to force a default blank state reset to `{}`.
|
|
151
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#resetrowselection)
|
|
152
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)
|
|
153
|
+
*/
|
|
154
|
+
resetRowSelection: (defaultState?: boolean) => void;
|
|
155
|
+
/**
|
|
156
|
+
* Sets or updates the `state.rowSelection` state.
|
|
157
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#setrowselection)
|
|
158
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)
|
|
159
|
+
*/
|
|
160
|
+
setRowSelection: (updater: Updater<RowSelectionState>) => void;
|
|
161
|
+
/**
|
|
162
|
+
* Selects/deselects all rows on the current page.
|
|
163
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#toggleallpagerowsselected)
|
|
164
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)
|
|
165
|
+
*/
|
|
166
|
+
toggleAllPageRowsSelected: (value?: boolean) => void;
|
|
167
|
+
/**
|
|
168
|
+
* Selects/deselects all rows in the table.
|
|
169
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#toggleallrowsselected)
|
|
170
|
+
* @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)
|
|
171
|
+
*/
|
|
172
|
+
toggleAllRowsSelected: (value?: boolean) => void;
|
|
173
|
+
}
|
|
174
|
+
export declare const RowSelection: TableFeature;
|
|
175
|
+
export declare function selectRowsFn<TData extends RowData>(table: Table<TData>, rowModel: RowModel<TData>): RowModel<TData>;
|
|
176
|
+
export declare function isRowSelected<TData extends RowData>(row: Row<TData>, selection: Record<string, boolean>): boolean;
|
|
177
|
+
export declare function isSubRowSelected<TData extends RowData>(row: Row<TData>, selection: Record<string, boolean>, table: Table<TData>): boolean | 'some' | 'all';
|