@tanstack/table-core 9.0.0-beta.46 → 9.0.0-beta.48
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/core/row-models/coreRowModelsFeature.types.d.cts +1 -1
- package/dist/core/row-models/coreRowModelsFeature.types.d.ts +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.cjs +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.cjs.map +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.d.cts +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.d.ts +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.js +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.js.map +1 -1
- package/dist/features/aggregation/aggregationFeature.cjs +38 -0
- package/dist/features/aggregation/aggregationFeature.cjs.map +1 -0
- package/dist/features/aggregation/aggregationFeature.d.cts +10 -0
- package/dist/features/aggregation/aggregationFeature.d.ts +10 -0
- package/dist/features/aggregation/aggregationFeature.js +38 -0
- package/dist/features/aggregation/aggregationFeature.js.map +1 -0
- package/dist/features/aggregation/aggregationFeature.types.cjs +13 -0
- package/dist/features/aggregation/aggregationFeature.types.cjs.map +1 -0
- package/dist/features/aggregation/aggregationFeature.types.d.cts +172 -0
- package/dist/features/aggregation/aggregationFeature.types.d.ts +172 -0
- package/dist/features/aggregation/aggregationFeature.types.js +12 -0
- package/dist/features/aggregation/aggregationFeature.types.js.map +1 -0
- package/dist/features/aggregation/aggregationFeature.utils.cjs +198 -0
- package/dist/features/aggregation/aggregationFeature.utils.cjs.map +1 -0
- package/dist/features/aggregation/aggregationFeature.utils.d.cts +33 -0
- package/dist/features/aggregation/aggregationFeature.utils.d.ts +33 -0
- package/dist/features/aggregation/aggregationFeature.utils.js +192 -0
- package/dist/features/aggregation/aggregationFeature.utils.js.map +1 -0
- package/dist/features/aggregation/aggregationFns.cjs +240 -0
- package/dist/features/aggregation/aggregationFns.cjs.map +1 -0
- package/dist/features/aggregation/aggregationFns.d.cts +67 -0
- package/dist/features/aggregation/aggregationFns.d.ts +67 -0
- package/dist/features/aggregation/aggregationFns.js +229 -0
- package/dist/features/aggregation/aggregationFns.js.map +1 -0
- package/dist/features/column-filtering/columnFilteringFeature.types.d.cts +43 -3
- package/dist/features/column-filtering/columnFilteringFeature.types.d.ts +43 -3
- package/dist/features/column-filtering/columnFilteringFeature.utils.cjs +18 -9
- package/dist/features/column-filtering/columnFilteringFeature.utils.cjs.map +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.utils.d.cts +6 -2
- package/dist/features/column-filtering/columnFilteringFeature.utils.d.ts +6 -2
- package/dist/features/column-filtering/columnFilteringFeature.utils.js +18 -9
- package/dist/features/column-filtering/columnFilteringFeature.utils.js.map +1 -1
- package/dist/features/column-filtering/createFilteredRowModel.cjs +7 -2
- package/dist/features/column-filtering/createFilteredRowModel.cjs.map +1 -1
- package/dist/features/column-filtering/createFilteredRowModel.d.cts +6 -2
- package/dist/features/column-filtering/createFilteredRowModel.d.ts +6 -2
- package/dist/features/column-filtering/createFilteredRowModel.js +7 -2
- package/dist/features/column-filtering/createFilteredRowModel.js.map +1 -1
- package/dist/features/column-filtering/filterFns.cjs +399 -0
- package/dist/features/column-filtering/filterFns.cjs.map +1 -0
- package/dist/features/column-filtering/filterFns.d.cts +210 -0
- package/dist/features/column-filtering/filterFns.d.ts +210 -0
- package/dist/features/column-filtering/filterFns.js +375 -0
- package/dist/features/column-filtering/filterFns.js.map +1 -0
- package/dist/features/column-grouping/columnGroupingFeature.cjs +3 -12
- package/dist/features/column-grouping/columnGroupingFeature.cjs.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.d.cts +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.d.ts +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.js +4 -13
- package/dist/features/column-grouping/columnGroupingFeature.js.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.types.d.cts +6 -49
- package/dist/features/column-grouping/columnGroupingFeature.types.d.ts +6 -49
- package/dist/features/column-grouping/columnGroupingFeature.utils.cjs +0 -50
- package/dist/features/column-grouping/columnGroupingFeature.utils.cjs.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.utils.d.cts +2 -39
- package/dist/features/column-grouping/columnGroupingFeature.utils.d.ts +2 -39
- package/dist/features/column-grouping/columnGroupingFeature.utils.js +2 -49
- package/dist/features/column-grouping/columnGroupingFeature.utils.js.map +1 -1
- package/dist/features/column-grouping/createGroupedRowModel.cjs +23 -13
- package/dist/features/column-grouping/createGroupedRowModel.cjs.map +1 -1
- package/dist/features/column-grouping/createGroupedRowModel.d.cts +2 -3
- package/dist/features/column-grouping/createGroupedRowModel.d.ts +2 -3
- package/dist/features/column-grouping/createGroupedRowModel.js +25 -15
- package/dist/features/column-grouping/createGroupedRowModel.js.map +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.utils.cjs +4 -2
- package/dist/features/global-filtering/globalFilteringFeature.utils.cjs.map +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.utils.d.cts +2 -6
- package/dist/features/global-filtering/globalFilteringFeature.utils.d.ts +2 -6
- package/dist/features/global-filtering/globalFilteringFeature.utils.js +4 -2
- package/dist/features/global-filtering/globalFilteringFeature.utils.js.map +1 -1
- package/dist/features/row-sorting/createSortedRowModel.cjs +6 -2
- package/dist/features/row-sorting/createSortedRowModel.cjs.map +1 -1
- package/dist/features/row-sorting/createSortedRowModel.d.cts +6 -2
- package/dist/features/row-sorting/createSortedRowModel.d.ts +6 -2
- package/dist/features/row-sorting/createSortedRowModel.js +6 -2
- package/dist/features/row-sorting/createSortedRowModel.js.map +1 -1
- package/dist/features/row-sorting/rowSortingFeature.types.d.cts +32 -3
- package/dist/features/row-sorting/rowSortingFeature.types.d.ts +32 -3
- package/dist/features/row-sorting/rowSortingFeature.utils.cjs +20 -5
- package/dist/features/row-sorting/rowSortingFeature.utils.cjs.map +1 -1
- package/dist/features/row-sorting/rowSortingFeature.utils.js +20 -5
- package/dist/features/row-sorting/rowSortingFeature.utils.js.map +1 -1
- package/dist/{fns → features/row-sorting}/sortFns.cjs +69 -22
- package/dist/features/row-sorting/sortFns.cjs.map +1 -0
- package/dist/features/row-sorting/sortFns.d.cts +98 -0
- package/dist/features/row-sorting/sortFns.d.ts +98 -0
- package/dist/{fns → features/row-sorting}/sortFns.js +69 -23
- package/dist/features/row-sorting/sortFns.js.map +1 -0
- package/dist/features/stockFeatures.cjs +2 -0
- package/dist/features/stockFeatures.cjs.map +1 -1
- package/dist/features/stockFeatures.d.cts +2 -0
- package/dist/features/stockFeatures.d.ts +2 -0
- package/dist/features/stockFeatures.js +2 -0
- package/dist/features/stockFeatures.js.map +1 -1
- package/dist/helpers/tableFeatures.cjs +5 -4
- package/dist/helpers/tableFeatures.cjs.map +1 -1
- package/dist/helpers/tableFeatures.d.cts +5 -4
- package/dist/helpers/tableFeatures.d.ts +5 -4
- package/dist/helpers/tableFeatures.js +5 -4
- package/dist/helpers/tableFeatures.js.map +1 -1
- package/dist/index.cjs +18 -3
- package/dist/index.d.cts +10 -8
- package/dist/index.d.ts +10 -8
- package/dist/index.js +6 -4
- package/dist/static-functions.cjs +8 -3
- package/dist/static-functions.d.cts +3 -2
- package/dist/static-functions.d.ts +3 -2
- package/dist/static-functions.js +3 -2
- package/dist/types/Cell.d.cts +3 -1
- package/dist/types/Cell.d.ts +3 -1
- package/dist/types/Column.d.cts +4 -2
- package/dist/types/Column.d.ts +4 -2
- package/dist/types/ColumnDef.d.cts +5 -3
- package/dist/types/ColumnDef.d.ts +5 -3
- package/dist/types/Row.d.cts +3 -1
- package/dist/types/Row.d.ts +3 -1
- package/dist/types/RowModel.d.cts +1 -1
- package/dist/types/RowModel.d.ts +1 -1
- package/dist/types/RowModelFns.d.cts +3 -3
- package/dist/types/RowModelFns.d.ts +3 -3
- package/dist/types/Table.d.cts +1 -1
- package/dist/types/Table.d.ts +1 -1
- package/dist/types/TableFeatures.d.cts +19 -11
- package/dist/types/TableFeatures.d.ts +19 -11
- package/dist/types/TableOptions.d.cts +5 -3
- package/dist/types/TableOptions.d.ts +5 -3
- package/dist/types/TableState.d.cts +1 -1
- package/dist/types/TableState.d.ts +1 -1
- package/dist/types/type-utils.d.cts +8 -1
- package/dist/types/type-utils.d.ts +8 -1
- package/dist/worker/initTableWorker.cjs.map +1 -1
- package/dist/worker/initTableWorker.js.map +1 -1
- package/package.json +1 -1
- package/skills/aggregation/SKILL.md +131 -0
- package/skills/api-not-found/SKILL.md +1 -1
- package/skills/client-vs-server/SKILL.md +1 -1
- package/skills/column-faceting/SKILL.md +11 -5
- package/skills/column-filtering/SKILL.md +8 -3
- 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 +3 -3
- package/skills/grouping/SKILL.md +12 -13
- package/skills/migrate-v8-to-v9/SKILL.md +21 -8
- 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 +9 -3
- package/skills/table-features/SKILL.md +19 -13
- package/skills/typescript/SKILL.md +1 -1
- package/src/core/row-models/coreRowModelsFeature.utils.ts +1 -1
- package/src/features/aggregation/aggregationFeature.ts +59 -0
- package/src/features/aggregation/aggregationFeature.types.ts +312 -0
- package/src/features/aggregation/aggregationFeature.utils.ts +401 -0
- package/src/features/aggregation/aggregationFns.ts +336 -0
- package/src/features/column-filtering/columnFilteringFeature.types.ts +61 -1
- package/src/features/column-filtering/columnFilteringFeature.utils.ts +33 -19
- package/src/features/column-filtering/createFilteredRowModel.ts +13 -3
- package/src/features/column-filtering/filterFns.ts +533 -0
- package/src/features/column-grouping/columnGroupingFeature.ts +1 -20
- package/src/features/column-grouping/columnGroupingFeature.types.ts +4 -86
- package/src/features/column-grouping/columnGroupingFeature.utils.ts +1 -88
- package/src/features/column-grouping/createGroupedRowModel.ts +32 -38
- package/src/features/global-filtering/globalFilteringFeature.utils.ts +9 -1
- package/src/features/row-sorting/createSortedRowModel.ts +6 -2
- package/src/features/row-sorting/rowSortingFeature.types.ts +54 -2
- package/src/features/row-sorting/rowSortingFeature.utils.ts +46 -14
- package/src/{fns → features/row-sorting}/sortFns.ts +95 -81
- package/src/features/stockFeatures.ts +3 -0
- package/src/helpers/tableFeatures.ts +5 -4
- package/src/index.ts +7 -8
- package/src/static-functions.ts +1 -0
- package/src/types/Cell.ts +2 -0
- package/src/types/Column.ts +3 -1
- package/src/types/ColumnDef.ts +6 -3
- package/src/types/Row.ts +2 -0
- package/src/types/RowModelFns.ts +3 -3
- package/src/types/TableFeatures.ts +19 -11
- package/src/types/TableOptions.ts +5 -1
- package/src/types/type-utils.ts +8 -0
- package/src/worker/initTableWorker.ts +1 -1
- package/dist/fns/aggregationFns.cjs +0 -163
- package/dist/fns/aggregationFns.cjs.map +0 -1
- package/dist/fns/aggregationFns.d.cts +0 -85
- package/dist/fns/aggregationFns.d.ts +0 -85
- package/dist/fns/aggregationFns.js +0 -153
- package/dist/fns/aggregationFns.js.map +0 -1
- package/dist/fns/filterFns.cjs +0 -242
- package/dist/fns/filterFns.cjs.map +0 -1
- package/dist/fns/filterFns.d.cts +0 -178
- package/dist/fns/filterFns.d.ts +0 -178
- package/dist/fns/filterFns.js +0 -226
- package/dist/fns/filterFns.js.map +0 -1
- package/dist/fns/sortFns.cjs.map +0 -1
- package/dist/fns/sortFns.d.cts +0 -65
- package/dist/fns/sortFns.d.ts +0 -65
- package/dist/fns/sortFns.js.map +0 -1
- package/src/fns/aggregationFns.ts +0 -245
- package/src/fns/filterFns.ts +0 -455
package/src/fns/filterFns.ts
DELETED
|
@@ -1,455 +0,0 @@
|
|
|
1
|
-
import type { RowData } from '../types/type-utils'
|
|
2
|
-
import type { TableFeatures } from '../types/TableFeatures'
|
|
3
|
-
import type { Row } from '../types/Row'
|
|
4
|
-
|
|
5
|
-
// Basic filters
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Keeps rows whose column value is strictly equal to the filter value.
|
|
9
|
-
*
|
|
10
|
-
* Uses JavaScript `===` comparison and auto-removes empty filter values.
|
|
11
|
-
*/
|
|
12
|
-
export const filterFn_equals = Object.assign(
|
|
13
|
-
<TFeatures extends TableFeatures, TData extends RowData>(
|
|
14
|
-
row: Row<TFeatures, TData>,
|
|
15
|
-
columnId: string,
|
|
16
|
-
filterValue: unknown,
|
|
17
|
-
) => {
|
|
18
|
-
return row.getValue(columnId) === filterValue
|
|
19
|
-
},
|
|
20
|
-
{ autoRemove: (val: any) => testFalsy(val) },
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Keeps rows whose column value is loosely equal to the filter value.
|
|
25
|
-
*
|
|
26
|
-
* Uses JavaScript `==` comparison and auto-removes empty filter values. This is
|
|
27
|
-
* useful for matching string input against numeric row values.
|
|
28
|
-
*/
|
|
29
|
-
export const filterFn_weakEquals = Object.assign(
|
|
30
|
-
<TFeatures extends TableFeatures, TData extends RowData>(
|
|
31
|
-
row: Row<TFeatures, TData>,
|
|
32
|
-
columnId: string,
|
|
33
|
-
filterValue: unknown,
|
|
34
|
-
) => {
|
|
35
|
-
return row.getValue(columnId) == filterValue
|
|
36
|
-
},
|
|
37
|
-
{ autoRemove: (val: any) => testFalsy(val) },
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
// String filters
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Keeps rows whose stringified column value includes the filter text.
|
|
44
|
-
*
|
|
45
|
-
* Matching is case-sensitive and empty filter values are auto-removed.
|
|
46
|
-
*/
|
|
47
|
-
export const filterFn_includesStringSensitive = Object.assign(
|
|
48
|
-
<TFeatures extends TableFeatures, TData extends RowData>(
|
|
49
|
-
row: Row<TFeatures, TData>,
|
|
50
|
-
columnId: string,
|
|
51
|
-
filterValue: unknown,
|
|
52
|
-
) => {
|
|
53
|
-
return Boolean(
|
|
54
|
-
row.getValue(columnId)?.toString().includes(String(filterValue)),
|
|
55
|
-
)
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
autoRemove: (val: any) => testFalsy(val),
|
|
59
|
-
resolveFilterValue: (val: any) => String(val),
|
|
60
|
-
},
|
|
61
|
-
)
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Keeps rows whose stringified column value includes the filter text.
|
|
65
|
-
*
|
|
66
|
-
* Both values are lowercased before comparison, and empty filter values are
|
|
67
|
-
* auto-removed.
|
|
68
|
-
*/
|
|
69
|
-
export const filterFn_includesString = Object.assign(
|
|
70
|
-
<TFeatures extends TableFeatures, TData extends RowData>(
|
|
71
|
-
row: Row<TFeatures, TData>,
|
|
72
|
-
columnId: string,
|
|
73
|
-
filterValue: unknown,
|
|
74
|
-
) => {
|
|
75
|
-
return Boolean(
|
|
76
|
-
row
|
|
77
|
-
.getValue(columnId)
|
|
78
|
-
?.toString()
|
|
79
|
-
.toLowerCase()
|
|
80
|
-
.includes(String(filterValue).toLowerCase()),
|
|
81
|
-
)
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
autoRemove: (val: any) => testFalsy(val),
|
|
85
|
-
resolveFilterValue: (val: any) => String(val).toLowerCase(),
|
|
86
|
-
},
|
|
87
|
-
)
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Keeps rows whose stringified column value equals the filter text.
|
|
91
|
-
*
|
|
92
|
-
* Both values are lowercased before comparison, and empty filter values are
|
|
93
|
-
* auto-removed.
|
|
94
|
-
*/
|
|
95
|
-
export const filterFn_equalsString = Object.assign(
|
|
96
|
-
<TFeatures extends TableFeatures, TData extends RowData>(
|
|
97
|
-
row: Row<TFeatures, TData>,
|
|
98
|
-
columnId: string,
|
|
99
|
-
filterValue: unknown,
|
|
100
|
-
) => {
|
|
101
|
-
return (
|
|
102
|
-
row.getValue(columnId)?.toString().toLowerCase() ===
|
|
103
|
-
String(filterValue).toLowerCase()
|
|
104
|
-
)
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
autoRemove: (val: any) => testFalsy(val),
|
|
108
|
-
resolveFilterValue: (val: any) => String(val).toLowerCase(),
|
|
109
|
-
},
|
|
110
|
-
)
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Keeps rows whose stringified column value exactly equals the filter text.
|
|
114
|
-
*
|
|
115
|
-
* Matching is case-sensitive and empty filter values are auto-removed.
|
|
116
|
-
*/
|
|
117
|
-
export const filterFn_equalsStringSensitive = Object.assign(
|
|
118
|
-
<TFeatures extends TableFeatures, TData extends RowData>(
|
|
119
|
-
row: Row<TFeatures, TData>,
|
|
120
|
-
columnId: string,
|
|
121
|
-
filterValue: unknown,
|
|
122
|
-
) => {
|
|
123
|
-
return row.getValue(columnId)?.toString() === String(filterValue)
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
autoRemove: (val: any) => testFalsy(val),
|
|
127
|
-
resolveFilterValue: (val: any) => String(val),
|
|
128
|
-
},
|
|
129
|
-
)
|
|
130
|
-
|
|
131
|
-
// Number filters
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Keeps rows whose value is greater than the filter value.
|
|
135
|
-
*
|
|
136
|
-
* Numeric values are compared numerically when both sides can be coerced to
|
|
137
|
-
* numbers; otherwise normalized strings are compared.
|
|
138
|
-
*/
|
|
139
|
-
export const filterFn_greaterThan = Object.assign(
|
|
140
|
-
<TFeatures extends TableFeatures, TData extends RowData>(
|
|
141
|
-
row: Row<TFeatures, TData>,
|
|
142
|
-
columnId: string,
|
|
143
|
-
filterValue: unknown,
|
|
144
|
-
) => {
|
|
145
|
-
const rowValue = row.getValue(columnId)
|
|
146
|
-
const numericRowValue =
|
|
147
|
-
rowValue === null || rowValue === undefined ? 0 : +rowValue
|
|
148
|
-
const numericFilterValue = Number(filterValue)
|
|
149
|
-
|
|
150
|
-
if (!isNaN(numericFilterValue) && !isNaN(numericRowValue)) {
|
|
151
|
-
return numericRowValue > numericFilterValue
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const stringValue = (rowValue ?? '').toString().toLowerCase().trim()
|
|
155
|
-
const stringFilterValue = String(filterValue).toLowerCase().trim()
|
|
156
|
-
return stringValue > stringFilterValue
|
|
157
|
-
},
|
|
158
|
-
{ autoRemove: (val: any) => testFalsy(val) },
|
|
159
|
-
)
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Keeps rows whose value is greater than or equal to the filter value.
|
|
163
|
-
*
|
|
164
|
-
* Delegates to the built-in greater-than and equality comparisons.
|
|
165
|
-
*/
|
|
166
|
-
export const filterFn_greaterThanOrEqualTo = Object.assign(
|
|
167
|
-
<TFeatures extends TableFeatures, TData extends RowData>(
|
|
168
|
-
row: Row<TFeatures, TData>,
|
|
169
|
-
columnId: string,
|
|
170
|
-
filterValue: unknown,
|
|
171
|
-
) => {
|
|
172
|
-
return (
|
|
173
|
-
filterFn_greaterThan(row, columnId, filterValue) ||
|
|
174
|
-
filterFn_equals(row, columnId, filterValue)
|
|
175
|
-
)
|
|
176
|
-
},
|
|
177
|
-
{ autoRemove: (val: any) => testFalsy(val) },
|
|
178
|
-
)
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Keeps rows whose value is less than the filter value.
|
|
182
|
-
*
|
|
183
|
-
* This is implemented as the inverse of greater-than-or-equal comparison.
|
|
184
|
-
*/
|
|
185
|
-
export const filterFn_lessThan = Object.assign(
|
|
186
|
-
<TFeatures extends TableFeatures, TData extends RowData>(
|
|
187
|
-
row: Row<TFeatures, TData>,
|
|
188
|
-
columnId: string,
|
|
189
|
-
filterValue: unknown,
|
|
190
|
-
) => {
|
|
191
|
-
return !filterFn_greaterThanOrEqualTo(row, columnId, filterValue)
|
|
192
|
-
},
|
|
193
|
-
{ autoRemove: (val: any) => testFalsy(val) },
|
|
194
|
-
)
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Keeps rows whose value is less than or equal to the filter value.
|
|
198
|
-
*
|
|
199
|
-
* This is implemented as the inverse of greater-than comparison.
|
|
200
|
-
*/
|
|
201
|
-
export const filterFn_lessThanOrEqualTo = Object.assign(
|
|
202
|
-
<TFeatures extends TableFeatures, TData extends RowData>(
|
|
203
|
-
row: Row<TFeatures, TData>,
|
|
204
|
-
columnId: string,
|
|
205
|
-
filterValue: unknown,
|
|
206
|
-
) => {
|
|
207
|
-
return !filterFn_greaterThan(row, columnId, filterValue)
|
|
208
|
-
},
|
|
209
|
-
{ autoRemove: (val: any) => testFalsy(val) },
|
|
210
|
-
)
|
|
211
|
-
|
|
212
|
-
// Range filters
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Keeps rows whose value falls between an exclusive min/max pair.
|
|
216
|
-
*
|
|
217
|
-
* Blank range endpoints are treated as open-ended.
|
|
218
|
-
*/
|
|
219
|
-
const filterFn_between = Object.assign(
|
|
220
|
-
<TFeatures extends TableFeatures, TData extends RowData>(
|
|
221
|
-
row: Row<TFeatures, TData>,
|
|
222
|
-
columnId: string,
|
|
223
|
-
filterValues: [unknown, unknown],
|
|
224
|
-
): boolean => {
|
|
225
|
-
const min = filterValues[0]
|
|
226
|
-
if (min !== '' && min !== undefined) {
|
|
227
|
-
if (!filterFn_greaterThan(row, columnId, min)) {
|
|
228
|
-
return false
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
const max = filterValues[1]
|
|
233
|
-
if (max === '' || max === undefined) {
|
|
234
|
-
return true
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
if (min !== '' && min !== undefined) {
|
|
238
|
-
const numericMin = Number(min)
|
|
239
|
-
const numericMax = Number(max)
|
|
240
|
-
if (!isNaN(numericMin) && !isNaN(numericMax) && numericMin > numericMax) {
|
|
241
|
-
return true
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
return filterFn_lessThan(row, columnId, max)
|
|
246
|
-
},
|
|
247
|
-
{
|
|
248
|
-
autoRemove: (val: any) =>
|
|
249
|
-
testFalsy(val) ||
|
|
250
|
-
(Array.isArray(val) && testFalsy(val[0]) && testFalsy(val[1])),
|
|
251
|
-
},
|
|
252
|
-
)
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Keeps rows whose value falls between an inclusive min/max pair.
|
|
256
|
-
*
|
|
257
|
-
* Blank range endpoints are treated as open-ended.
|
|
258
|
-
*/
|
|
259
|
-
const filterFn_betweenInclusive = Object.assign(
|
|
260
|
-
<TFeatures extends TableFeatures, TData extends RowData>(
|
|
261
|
-
row: Row<TFeatures, TData>,
|
|
262
|
-
columnId: string,
|
|
263
|
-
filterValues: [unknown, unknown],
|
|
264
|
-
): boolean => {
|
|
265
|
-
const min = filterValues[0]
|
|
266
|
-
if (min !== '' && min !== undefined) {
|
|
267
|
-
if (!filterFn_greaterThanOrEqualTo(row, columnId, min)) {
|
|
268
|
-
return false
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
const max = filterValues[1]
|
|
273
|
-
if (max === '' || max === undefined) {
|
|
274
|
-
return true
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
if (min !== '' && min !== undefined) {
|
|
278
|
-
const numericMin = Number(min)
|
|
279
|
-
const numericMax = Number(max)
|
|
280
|
-
if (!isNaN(numericMin) && !isNaN(numericMax) && numericMin > numericMax) {
|
|
281
|
-
return true
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
return filterFn_lessThanOrEqualTo(row, columnId, max)
|
|
286
|
-
},
|
|
287
|
-
{
|
|
288
|
-
autoRemove: (val: any) =>
|
|
289
|
-
testFalsy(val) ||
|
|
290
|
-
(Array.isArray(val) && testFalsy(val[0]) && testFalsy(val[1])),
|
|
291
|
-
},
|
|
292
|
-
)
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
* Keeps rows whose numeric value is inside an inclusive `[min, max]` range.
|
|
296
|
-
*
|
|
297
|
-
* Filter values are normalized so blank endpoints become open-ended and
|
|
298
|
-
* reversed endpoints are swapped.
|
|
299
|
-
*/
|
|
300
|
-
export const filterFn_inNumberRange = Object.assign(
|
|
301
|
-
<TFeatures extends TableFeatures, TData extends RowData>(
|
|
302
|
-
row: Row<TFeatures, TData>,
|
|
303
|
-
columnId: string,
|
|
304
|
-
filterValue: [number, number],
|
|
305
|
-
) => {
|
|
306
|
-
const [min, max] = filterValue
|
|
307
|
-
|
|
308
|
-
const rowValue: number = row.getValue(columnId)
|
|
309
|
-
return rowValue >= min && rowValue <= max
|
|
310
|
-
},
|
|
311
|
-
{
|
|
312
|
-
resolveFilterValue: (val: [any, any]) => {
|
|
313
|
-
const [unsafeMin, unsafeMax] = val
|
|
314
|
-
|
|
315
|
-
const parsedMin =
|
|
316
|
-
typeof unsafeMin !== 'number' ? parseFloat(unsafeMin) : unsafeMin
|
|
317
|
-
const parsedMax =
|
|
318
|
-
typeof unsafeMax !== 'number' ? parseFloat(unsafeMax) : unsafeMax
|
|
319
|
-
|
|
320
|
-
let min =
|
|
321
|
-
unsafeMin === null || Number.isNaN(parsedMin) ? -Infinity : parsedMin
|
|
322
|
-
let max =
|
|
323
|
-
unsafeMax === null || Number.isNaN(parsedMax) ? Infinity : parsedMax
|
|
324
|
-
|
|
325
|
-
if (min > max) {
|
|
326
|
-
const temp = min
|
|
327
|
-
min = max
|
|
328
|
-
max = temp
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
return [min, max] as const
|
|
332
|
-
},
|
|
333
|
-
autoRemove: (val: any) =>
|
|
334
|
-
testFalsy(val) ||
|
|
335
|
-
(Array.isArray(val) && testFalsy(val[0]) && testFalsy(val[1])),
|
|
336
|
-
},
|
|
337
|
-
)
|
|
338
|
-
|
|
339
|
-
// Array filters
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* Keeps rows whose scalar column value equals at least one filter value.
|
|
343
|
-
*/
|
|
344
|
-
export const filterFn_arrHas = Object.assign(
|
|
345
|
-
<TFeatures extends TableFeatures, TData extends RowData>(
|
|
346
|
-
row: Row<TFeatures, TData>,
|
|
347
|
-
columnId: string,
|
|
348
|
-
filterValue: Array<unknown>,
|
|
349
|
-
) => {
|
|
350
|
-
const value = row.getValue<unknown>(columnId)
|
|
351
|
-
for (let i = 0; i < filterValue.length; i++) {
|
|
352
|
-
if (value === filterValue[i]) {
|
|
353
|
-
return true
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
return false
|
|
357
|
-
},
|
|
358
|
-
{ autoRemove: (val: any) => testFalsy(val) || !val?.length },
|
|
359
|
-
)
|
|
360
|
-
|
|
361
|
-
/**
|
|
362
|
-
* Keeps rows whose array or string column value includes at least one filter value.
|
|
363
|
-
*/
|
|
364
|
-
export const filterFn_arrIncludes = Object.assign(
|
|
365
|
-
<TFeatures extends TableFeatures, TData extends RowData>(
|
|
366
|
-
row: Row<TFeatures, TData>,
|
|
367
|
-
columnId: string,
|
|
368
|
-
filterValue: Array<unknown>,
|
|
369
|
-
) => {
|
|
370
|
-
const value = row.getValue<unknown>(columnId)
|
|
371
|
-
if (typeof value !== 'string' && !Array.isArray(value)) {
|
|
372
|
-
return false
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
for (let i = 0; i < filterValue.length; i++) {
|
|
376
|
-
if (value.includes(filterValue[i] as any)) {
|
|
377
|
-
return true
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
return false
|
|
381
|
-
},
|
|
382
|
-
{ autoRemove: (val: any) => testFalsy(val) || !val?.length },
|
|
383
|
-
)
|
|
384
|
-
|
|
385
|
-
/**
|
|
386
|
-
* Keeps rows whose array column value includes every filter value.
|
|
387
|
-
*/
|
|
388
|
-
export const filterFn_arrIncludesAll = Object.assign(
|
|
389
|
-
<TFeatures extends TableFeatures, TData extends RowData>(
|
|
390
|
-
row: Row<TFeatures, TData>,
|
|
391
|
-
columnId: string,
|
|
392
|
-
filterValue: Array<unknown>,
|
|
393
|
-
) => {
|
|
394
|
-
const value = row.getValue<Array<unknown>>(columnId)
|
|
395
|
-
if (!Array.isArray(value)) return false
|
|
396
|
-
for (let i = 0; i < filterValue.length; i++) {
|
|
397
|
-
if (!value.includes(filterValue[i])) {
|
|
398
|
-
return false
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
return true
|
|
402
|
-
},
|
|
403
|
-
{ autoRemove: (val: any) => testFalsy(val) || !val?.length },
|
|
404
|
-
)
|
|
405
|
-
|
|
406
|
-
/**
|
|
407
|
-
* Keeps rows whose array column value includes at least one filter value.
|
|
408
|
-
*/
|
|
409
|
-
export const filterFn_arrIncludesSome = Object.assign(
|
|
410
|
-
<TFeatures extends TableFeatures, TData extends RowData>(
|
|
411
|
-
row: Row<TFeatures, TData>,
|
|
412
|
-
columnId: string,
|
|
413
|
-
filterValue: Array<unknown>,
|
|
414
|
-
) => {
|
|
415
|
-
const value = row.getValue<Array<unknown>>(columnId)
|
|
416
|
-
if (!Array.isArray(value)) return false
|
|
417
|
-
for (let i = 0; i < filterValue.length; i++) {
|
|
418
|
-
if (value.includes(filterValue[i])) {
|
|
419
|
-
return true
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
return false
|
|
423
|
-
},
|
|
424
|
-
{ autoRemove: (val: any) => testFalsy(val) || !val?.length },
|
|
425
|
-
)
|
|
426
|
-
|
|
427
|
-
// Export
|
|
428
|
-
|
|
429
|
-
/**
|
|
430
|
-
* The built-in filter function registry.
|
|
431
|
-
*
|
|
432
|
-
* Pass this object to filtered row model creation or extend it with custom filter functions.
|
|
433
|
-
*/
|
|
434
|
-
export const filterFns = {
|
|
435
|
-
arrIncludes: filterFn_arrIncludes,
|
|
436
|
-
arrIncludesAll: filterFn_arrIncludesAll,
|
|
437
|
-
arrHas: filterFn_arrHas,
|
|
438
|
-
arrIncludesSome: filterFn_arrIncludesSome,
|
|
439
|
-
between: filterFn_between,
|
|
440
|
-
betweenInclusive: filterFn_betweenInclusive,
|
|
441
|
-
equals: filterFn_equals,
|
|
442
|
-
equalsString: filterFn_equalsString,
|
|
443
|
-
inNumberRange: filterFn_inNumberRange,
|
|
444
|
-
includesString: filterFn_includesString,
|
|
445
|
-
includesStringSensitive: filterFn_includesStringSensitive,
|
|
446
|
-
weakEquals: filterFn_weakEquals,
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
export type BuiltInFilterFn = keyof typeof filterFns
|
|
450
|
-
|
|
451
|
-
// Utils
|
|
452
|
-
|
|
453
|
-
function testFalsy(val: any) {
|
|
454
|
-
return val === undefined || val === null || val === ''
|
|
455
|
-
}
|