@tanstack/table-core 9.0.0-beta.77 → 9.0.0-beta.78
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/features/column-faceting/columnFacetingFeature.d.ts +6 -0
- package/dist/features/column-faceting/columnFacetingFeature.js +13 -35
- package/dist/features/column-faceting/columnFacetingFeature.utils.js +6 -2
- package/dist/features/column-filtering/columnFilteringFeature.types.d.ts +5 -0
- package/dist/features/column-filtering/columnFilteringFeature.utils.d.ts +6 -1
- package/dist/features/column-filtering/columnFilteringFeature.utils.js +9 -2
- package/dist/features/column-filtering/filterFns.d.ts +3 -1
- package/dist/features/column-filtering/filterFns.js +4 -1
- package/dist/features/column-filtering/filterRowsUtils.js +8 -0
- package/dist/features/column-visibility/columnVisibilityFeature.utils.d.ts +3 -1
- package/dist/features/column-visibility/columnVisibilityFeature.utils.js +9 -2
- package/package.json +1 -1
- package/skills/aggregation/SKILL.md +1 -1
- package/skills/api-not-found/SKILL.md +1 -1
- package/skills/cell-selection/SKILL.md +1 -1
- package/skills/cell-spanning/SKILL.md +1 -1
- package/skills/client-vs-server/SKILL.md +1 -1
- package/skills/column-faceting/SKILL.md +1 -1
- package/skills/column-filtering/SKILL.md +1 -1
- package/skills/column-ordering/SKILL.md +1 -1
- package/skills/column-pinning/SKILL.md +1 -1
- package/skills/column-resizing/SKILL.md +1 -1
- package/skills/column-sizing/SKILL.md +1 -1
- package/skills/column-visibility/SKILL.md +1 -1
- package/skills/core/SKILL.md +1 -1
- package/skills/custom-features/SKILL.md +1 -1
- package/skills/expanding/SKILL.md +1 -1
- package/skills/global-filtering/SKILL.md +1 -1
- package/skills/grouping/SKILL.md +1 -1
- package/skills/migrate-v8-to-v9/SKILL.md +1 -1
- package/skills/pagination/SKILL.md +1 -1
- package/skills/row-pinning/SKILL.md +1 -1
- package/skills/row-selection/SKILL.md +1 -1
- package/skills/sorting/SKILL.md +1 -1
- package/skills/table-features/SKILL.md +1 -1
- package/skills/typescript/SKILL.md +1 -1
|
@@ -2,6 +2,12 @@ import { TableFeature } from "../../types/TableFeatures.js";
|
|
|
2
2
|
//#region src/features/column-faceting/columnFacetingFeature.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* Feature that derives faceted row models, unique values, and min/max values for filters.
|
|
5
|
+
*
|
|
6
|
+
* These APIs are deliberately not memoized at this layer: the stock
|
|
7
|
+
* `createFaceted*` factories memoize internally (like every other stock row
|
|
8
|
+
* model), and an extra memo layer here would freeze custom factories whose
|
|
9
|
+
* data changes independently of the faceted row model. Custom factories own
|
|
10
|
+
* their memoization.
|
|
5
11
|
*/
|
|
6
12
|
declare const columnFacetingFeature: TableFeature;
|
|
7
13
|
//#endregion
|
|
@@ -1,51 +1,29 @@
|
|
|
1
|
-
import { assignPrototypeAPIs, assignTableAPIs
|
|
1
|
+
import { assignPrototypeAPIs, assignTableAPIs } from "../../utils.js";
|
|
2
2
|
import { column_getFacetedMinMaxValues, column_getFacetedRowModel, column_getFacetedUniqueValues, table_getGlobalFacetedMinMaxValues, table_getGlobalFacetedRowModel, table_getGlobalFacetedUniqueValues } from "./columnFacetingFeature.utils.js";
|
|
3
3
|
|
|
4
4
|
//#region src/features/column-faceting/columnFacetingFeature.ts
|
|
5
5
|
/**
|
|
6
6
|
* Feature that derives faceted row models, unique values, and min/max values for filters.
|
|
7
|
+
*
|
|
8
|
+
* These APIs are deliberately not memoized at this layer: the stock
|
|
9
|
+
* `createFaceted*` factories memoize internally (like every other stock row
|
|
10
|
+
* model), and an extra memo layer here would freeze custom factories whose
|
|
11
|
+
* data changes independently of the faceted row model. Custom factories own
|
|
12
|
+
* their memoization.
|
|
7
13
|
*/
|
|
8
14
|
const columnFacetingFeature = {
|
|
9
15
|
assignColumnPrototype: (prototype, table) => {
|
|
10
16
|
assignPrototypeAPIs("columnFacetingFeature", prototype, table, {
|
|
11
|
-
column_getFacetedRowModel: {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
table.atoms.columnFilters?.get(),
|
|
15
|
-
table.atoms.globalFilter?.get(),
|
|
16
|
-
table.getFilteredRowModel().rows
|
|
17
|
-
],
|
|
18
|
-
fn: (column) => column_getFacetedRowModel(column, column.table)
|
|
19
|
-
},
|
|
20
|
-
column_getFacetedMinMaxValues: {
|
|
21
|
-
memoDeps: (column) => [callMemoOrStaticFn(column, "getFacetedRowModel", column_getFacetedRowModel, column.table).flatRows],
|
|
22
|
-
fn: (column) => column_getFacetedMinMaxValues(column, column.table)
|
|
23
|
-
},
|
|
24
|
-
column_getFacetedUniqueValues: {
|
|
25
|
-
memoDeps: (column) => [callMemoOrStaticFn(column, "getFacetedRowModel", column_getFacetedRowModel, column.table).flatRows],
|
|
26
|
-
fn: (column) => column_getFacetedUniqueValues(column, column.table)
|
|
27
|
-
}
|
|
17
|
+
column_getFacetedRowModel: { fn: (column) => column_getFacetedRowModel(column, column.table) },
|
|
18
|
+
column_getFacetedMinMaxValues: { fn: (column) => column_getFacetedMinMaxValues(column, column.table) },
|
|
19
|
+
column_getFacetedUniqueValues: { fn: (column) => column_getFacetedUniqueValues(column, column.table) }
|
|
28
20
|
});
|
|
29
21
|
},
|
|
30
22
|
constructTableAPIs: (table) => {
|
|
31
23
|
assignTableAPIs("columnFacetingFeature", table, {
|
|
32
|
-
table_getGlobalFacetedRowModel: {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
table.atoms.columnFilters?.get(),
|
|
36
|
-
table.atoms.globalFilter?.get(),
|
|
37
|
-
table.getFilteredRowModel().rows
|
|
38
|
-
],
|
|
39
|
-
fn: () => table_getGlobalFacetedRowModel(table)
|
|
40
|
-
},
|
|
41
|
-
table_getGlobalFacetedMinMaxValues: {
|
|
42
|
-
memoDeps: () => [callMemoOrStaticFn(table, "getGlobalFacetedRowModel", table_getGlobalFacetedRowModel).flatRows],
|
|
43
|
-
fn: () => table_getGlobalFacetedMinMaxValues(table)
|
|
44
|
-
},
|
|
45
|
-
table_getGlobalFacetedUniqueValues: {
|
|
46
|
-
memoDeps: () => [callMemoOrStaticFn(table, "getGlobalFacetedRowModel", table_getGlobalFacetedRowModel).flatRows],
|
|
47
|
-
fn: () => table_getGlobalFacetedUniqueValues(table)
|
|
48
|
-
}
|
|
24
|
+
table_getGlobalFacetedRowModel: { fn: () => table_getGlobalFacetedRowModel(table) },
|
|
25
|
+
table_getGlobalFacetedMinMaxValues: { fn: () => table_getGlobalFacetedMinMaxValues(table) },
|
|
26
|
+
table_getGlobalFacetedUniqueValues: { fn: () => table_getGlobalFacetedUniqueValues(table) }
|
|
49
27
|
});
|
|
50
28
|
}
|
|
51
29
|
};
|
|
@@ -51,9 +51,13 @@ function column_getFacetedRowModel(column, table) {
|
|
|
51
51
|
function column_getFacetedUniqueValues(column, table) {
|
|
52
52
|
const facetedUniqueValues = table._rowModels.facetedUniqueValues ??= makeObjectMap();
|
|
53
53
|
let facetedUniqueValuesFn = facetedUniqueValues[column.id];
|
|
54
|
-
if (!facetedUniqueValuesFn) facetedUniqueValuesFn = facetedUniqueValues[column.id] = table.options.features.facetedUniqueValues?.(table, column.id) ?? (
|
|
54
|
+
if (!facetedUniqueValuesFn) facetedUniqueValuesFn = facetedUniqueValues[column.id] = table.options.features.facetedUniqueValues?.(table, column.id) ?? createStableEmptyMapFn();
|
|
55
55
|
return facetedUniqueValuesFn();
|
|
56
56
|
}
|
|
57
|
+
function createStableEmptyMapFn() {
|
|
58
|
+
const emptyMap = /* @__PURE__ */ new Map();
|
|
59
|
+
return () => emptyMap;
|
|
60
|
+
}
|
|
57
61
|
/**
|
|
58
62
|
* Computes min and max numeric facet values for the global filter context.
|
|
59
63
|
*
|
|
@@ -99,7 +103,7 @@ function table_getGlobalFacetedRowModel(table) {
|
|
|
99
103
|
* ```
|
|
100
104
|
*/
|
|
101
105
|
function table_getGlobalFacetedUniqueValues(table) {
|
|
102
|
-
if (!table._rowModels.globalFacetedUniqueValues) table._rowModels.globalFacetedUniqueValues = table.options.features.facetedUniqueValues?.(table, "__global__") ?? (
|
|
106
|
+
if (!table._rowModels.globalFacetedUniqueValues) table._rowModels.globalFacetedUniqueValues = table.options.features.facetedUniqueValues?.(table, "__global__") ?? createStableEmptyMapFn();
|
|
103
107
|
const facetedUniqueValuesFn = table._rowModels.globalFacetedUniqueValues;
|
|
104
108
|
return facetedUniqueValuesFn();
|
|
105
109
|
}
|
|
@@ -39,6 +39,11 @@ interface FilterFn<in out TFeatures extends TableFeatures, in out TData extends
|
|
|
39
39
|
/**
|
|
40
40
|
* Removes the filter from `state.columnFilters` when the filter value fails
|
|
41
41
|
* this test (e.g. empty strings for text filters).
|
|
42
|
+
*
|
|
43
|
+
* When provided, this test is authoritative: values it keeps stay in filter
|
|
44
|
+
* state even when they are empty strings, which the default heuristic would
|
|
45
|
+
* otherwise remove. An `undefined` filter value always clears the filter
|
|
46
|
+
* regardless.
|
|
42
47
|
*/
|
|
43
48
|
autoRemove?: ColumnFilterAutoRemoveTestFn<TFeatures, TData>;
|
|
44
49
|
/**
|
|
@@ -133,7 +133,12 @@ declare function table_resetColumnFilters<TFeatures extends TableFeatures, TData
|
|
|
133
133
|
/**
|
|
134
134
|
* Returns whether a filter value should be removed from filter state.
|
|
135
135
|
*
|
|
136
|
-
*
|
|
136
|
+
* `undefined` always removes: it is the universal "clear this filter"
|
|
137
|
+
* sentinel used by `setFilterValue(undefined)` and functional updaters. For
|
|
138
|
+
* any other value, a filter function's `autoRemove` hook is authoritative
|
|
139
|
+
* when provided, so custom filter functions can keep values (such as empty
|
|
140
|
+
* strings) that the default heuristic would drop. Without an `autoRemove`
|
|
141
|
+
* hook, empty strings are removed.
|
|
137
142
|
*
|
|
138
143
|
* @example
|
|
139
144
|
* ```ts
|
|
@@ -199,7 +199,12 @@ function table_resetColumnFilters(table, defaultState) {
|
|
|
199
199
|
/**
|
|
200
200
|
* Returns whether a filter value should be removed from filter state.
|
|
201
201
|
*
|
|
202
|
-
*
|
|
202
|
+
* `undefined` always removes: it is the universal "clear this filter"
|
|
203
|
+
* sentinel used by `setFilterValue(undefined)` and functional updaters. For
|
|
204
|
+
* any other value, a filter function's `autoRemove` hook is authoritative
|
|
205
|
+
* when provided, so custom filter functions can keep values (such as empty
|
|
206
|
+
* strings) that the default heuristic would drop. Without an `autoRemove`
|
|
207
|
+
* hook, empty strings are removed.
|
|
203
208
|
*
|
|
204
209
|
* @example
|
|
205
210
|
* ```ts
|
|
@@ -207,7 +212,9 @@ function table_resetColumnFilters(table, defaultState) {
|
|
|
207
212
|
* ```
|
|
208
213
|
*/
|
|
209
214
|
function shouldAutoRemoveFilter(filterFn, value, column) {
|
|
210
|
-
|
|
215
|
+
if (typeof value === "undefined") return true;
|
|
216
|
+
if (filterFn?.autoRemove) return !!filterFn.autoRemove(value, column);
|
|
217
|
+
return typeof value === "string" && !value;
|
|
211
218
|
}
|
|
212
219
|
|
|
213
220
|
//#endregion
|
|
@@ -143,7 +143,9 @@ declare const filterFn_betweenInclusive: CreatedFilterFn<any, any>;
|
|
|
143
143
|
* Keeps rows whose numeric value is inside an inclusive `[min, max]` range.
|
|
144
144
|
*
|
|
145
145
|
* Filter values are normalized so blank endpoints become open-ended and
|
|
146
|
-
* reversed endpoints are swapped.
|
|
146
|
+
* reversed endpoints are swapped. Only real numbers can fall inside the
|
|
147
|
+
* range: non-numeric row values (`null`, `undefined`, strings, booleans)
|
|
148
|
+
* never match.
|
|
147
149
|
*/
|
|
148
150
|
declare const filterFn_inNumberRange: CreatedFilterFn<any, any>;
|
|
149
151
|
/**
|
|
@@ -207,10 +207,13 @@ const filterFn_betweenInclusive = constructFilterFn({
|
|
|
207
207
|
* Keeps rows whose numeric value is inside an inclusive `[min, max]` range.
|
|
208
208
|
*
|
|
209
209
|
* Filter values are normalized so blank endpoints become open-ended and
|
|
210
|
-
* reversed endpoints are swapped.
|
|
210
|
+
* reversed endpoints are swapped. Only real numbers can fall inside the
|
|
211
|
+
* range: non-numeric row values (`null`, `undefined`, strings, booleans)
|
|
212
|
+
* never match.
|
|
211
213
|
*/
|
|
212
214
|
const filterFn_inNumberRange = constructFilterFn({
|
|
213
215
|
filter: (dataValue, filterValue) => {
|
|
216
|
+
if (typeof dataValue !== "number" || Number.isNaN(dataValue)) return false;
|
|
214
217
|
const [min, max] = filterValue;
|
|
215
218
|
return dataValue >= min && dataValue <= max;
|
|
216
219
|
},
|
|
@@ -67,6 +67,7 @@ function filterRowModelFromRoot(rowsToFilter, filterRow, table) {
|
|
|
67
67
|
filteredRows.push(row);
|
|
68
68
|
newFilteredFlatRows.push(row);
|
|
69
69
|
newFilteredRowsById[row.id] = row;
|
|
70
|
+
if (row.subRows.length && depth >= maxDepth) addSubRowsToFlatArrays(row.subRows, newFilteredFlatRows, newFilteredRowsById);
|
|
70
71
|
}
|
|
71
72
|
return filteredRows;
|
|
72
73
|
};
|
|
@@ -76,6 +77,13 @@ function filterRowModelFromRoot(rowsToFilter, filterRow, table) {
|
|
|
76
77
|
rowsById: newFilteredRowsById
|
|
77
78
|
};
|
|
78
79
|
}
|
|
80
|
+
function addSubRowsToFlatArrays(subRows, flatRows, rowsById) {
|
|
81
|
+
for (const subRow of subRows) {
|
|
82
|
+
flatRows.push(subRow);
|
|
83
|
+
rowsById[subRow.id] = subRow;
|
|
84
|
+
if (subRow.subRows.length) addSubRowsToFlatArrays(subRow.subRows, flatRows, rowsById);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
79
87
|
|
|
80
88
|
//#endregion
|
|
81
89
|
export { filterRows };
|
|
@@ -23,7 +23,9 @@ declare function getDefaultColumnVisibilityState(): ColumnVisibilityState;
|
|
|
23
23
|
* Updates this column's visibility when hiding is allowed.
|
|
24
24
|
*
|
|
25
25
|
* Passing `visible` stores that value. Omitting it flips the column's current
|
|
26
|
-
* visibility state.
|
|
26
|
+
* visibility state. Group columns update their hideable leaf columns because
|
|
27
|
+
* visibility state is keyed by leaf column ids. Columns that cannot hide stay
|
|
28
|
+
* unchanged.
|
|
27
29
|
*
|
|
28
30
|
* @example
|
|
29
31
|
* ```ts
|
|
@@ -20,7 +20,9 @@ function getDefaultColumnVisibilityState() {
|
|
|
20
20
|
* Updates this column's visibility when hiding is allowed.
|
|
21
21
|
*
|
|
22
22
|
* Passing `visible` stores that value. Omitting it flips the column's current
|
|
23
|
-
* visibility state.
|
|
23
|
+
* visibility state. Group columns update their hideable leaf columns because
|
|
24
|
+
* visibility state is keyed by leaf column ids. Columns that cannot hide stay
|
|
25
|
+
* unchanged.
|
|
24
26
|
*
|
|
25
27
|
* @example
|
|
26
28
|
* ```ts
|
|
@@ -30,7 +32,12 @@ function getDefaultColumnVisibilityState() {
|
|
|
30
32
|
function column_toggleVisibility(column, visible) {
|
|
31
33
|
if (column_getCanHide(column)) table_setColumnVisibility(column.table, (old) => {
|
|
32
34
|
const next = Object.assign(makeObjectMap(), old);
|
|
33
|
-
|
|
35
|
+
const nextVisible = visible ?? !callMemoOrStaticFn(column, "getIsVisible", column_getIsVisible);
|
|
36
|
+
const leafColumns = column.getLeafColumns();
|
|
37
|
+
for (let i = 0; i < leafColumns.length; i++) {
|
|
38
|
+
const leafColumn = leafColumns[i];
|
|
39
|
+
if (column_getCanHide(leafColumn)) next[leafColumn.id] = nextVisible;
|
|
40
|
+
}
|
|
34
41
|
return next;
|
|
35
42
|
});
|
|
36
43
|
}
|
package/package.json
CHANGED
package/skills/core/SKILL.md
CHANGED
|
@@ -5,7 +5,7 @@ description: >
|
|
|
5
5
|
metadata:
|
|
6
6
|
type: sub-skill
|
|
7
7
|
library: '@tanstack/table-core'
|
|
8
|
-
library_version: '9.0.0-beta.
|
|
8
|
+
library_version: '9.0.0-beta.78'
|
|
9
9
|
requires: ['core', 'table-features', 'typescript']
|
|
10
10
|
sources:
|
|
11
11
|
- 'TanStack/table:docs/framework/react/guide/custom-features.md'
|
package/skills/grouping/SKILL.md
CHANGED
|
@@ -5,7 +5,7 @@ description: >
|
|
|
5
5
|
metadata:
|
|
6
6
|
type: lifecycle
|
|
7
7
|
library: '@tanstack/table-core'
|
|
8
|
-
library_version: '9.0.0-beta.
|
|
8
|
+
library_version: '9.0.0-beta.78'
|
|
9
9
|
requires: ['core', 'table-features', 'typescript']
|
|
10
10
|
sources:
|
|
11
11
|
- 'TanStack/table:docs/framework/react/guide/migrating.md'
|
package/skills/sorting/SKILL.md
CHANGED