@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.
Files changed (212) hide show
  1. package/dist/core/row-models/coreRowModelsFeature.types.d.cts +1 -1
  2. package/dist/core/row-models/coreRowModelsFeature.types.d.ts +1 -1
  3. package/dist/core/row-models/coreRowModelsFeature.utils.cjs +1 -1
  4. package/dist/core/row-models/coreRowModelsFeature.utils.cjs.map +1 -1
  5. package/dist/core/row-models/coreRowModelsFeature.utils.d.cts +1 -1
  6. package/dist/core/row-models/coreRowModelsFeature.utils.d.ts +1 -1
  7. package/dist/core/row-models/coreRowModelsFeature.utils.js +1 -1
  8. package/dist/core/row-models/coreRowModelsFeature.utils.js.map +1 -1
  9. package/dist/features/aggregation/aggregationFeature.cjs +38 -0
  10. package/dist/features/aggregation/aggregationFeature.cjs.map +1 -0
  11. package/dist/features/aggregation/aggregationFeature.d.cts +10 -0
  12. package/dist/features/aggregation/aggregationFeature.d.ts +10 -0
  13. package/dist/features/aggregation/aggregationFeature.js +38 -0
  14. package/dist/features/aggregation/aggregationFeature.js.map +1 -0
  15. package/dist/features/aggregation/aggregationFeature.types.cjs +13 -0
  16. package/dist/features/aggregation/aggregationFeature.types.cjs.map +1 -0
  17. package/dist/features/aggregation/aggregationFeature.types.d.cts +172 -0
  18. package/dist/features/aggregation/aggregationFeature.types.d.ts +172 -0
  19. package/dist/features/aggregation/aggregationFeature.types.js +12 -0
  20. package/dist/features/aggregation/aggregationFeature.types.js.map +1 -0
  21. package/dist/features/aggregation/aggregationFeature.utils.cjs +198 -0
  22. package/dist/features/aggregation/aggregationFeature.utils.cjs.map +1 -0
  23. package/dist/features/aggregation/aggregationFeature.utils.d.cts +33 -0
  24. package/dist/features/aggregation/aggregationFeature.utils.d.ts +33 -0
  25. package/dist/features/aggregation/aggregationFeature.utils.js +192 -0
  26. package/dist/features/aggregation/aggregationFeature.utils.js.map +1 -0
  27. package/dist/features/aggregation/aggregationFns.cjs +240 -0
  28. package/dist/features/aggregation/aggregationFns.cjs.map +1 -0
  29. package/dist/features/aggregation/aggregationFns.d.cts +67 -0
  30. package/dist/features/aggregation/aggregationFns.d.ts +67 -0
  31. package/dist/features/aggregation/aggregationFns.js +229 -0
  32. package/dist/features/aggregation/aggregationFns.js.map +1 -0
  33. package/dist/features/column-filtering/columnFilteringFeature.types.d.cts +43 -3
  34. package/dist/features/column-filtering/columnFilteringFeature.types.d.ts +43 -3
  35. package/dist/features/column-filtering/columnFilteringFeature.utils.cjs +18 -9
  36. package/dist/features/column-filtering/columnFilteringFeature.utils.cjs.map +1 -1
  37. package/dist/features/column-filtering/columnFilteringFeature.utils.d.cts +6 -2
  38. package/dist/features/column-filtering/columnFilteringFeature.utils.d.ts +6 -2
  39. package/dist/features/column-filtering/columnFilteringFeature.utils.js +18 -9
  40. package/dist/features/column-filtering/columnFilteringFeature.utils.js.map +1 -1
  41. package/dist/features/column-filtering/createFilteredRowModel.cjs +7 -2
  42. package/dist/features/column-filtering/createFilteredRowModel.cjs.map +1 -1
  43. package/dist/features/column-filtering/createFilteredRowModel.d.cts +6 -2
  44. package/dist/features/column-filtering/createFilteredRowModel.d.ts +6 -2
  45. package/dist/features/column-filtering/createFilteredRowModel.js +7 -2
  46. package/dist/features/column-filtering/createFilteredRowModel.js.map +1 -1
  47. package/dist/features/column-filtering/filterFns.cjs +399 -0
  48. package/dist/features/column-filtering/filterFns.cjs.map +1 -0
  49. package/dist/features/column-filtering/filterFns.d.cts +210 -0
  50. package/dist/features/column-filtering/filterFns.d.ts +210 -0
  51. package/dist/features/column-filtering/filterFns.js +375 -0
  52. package/dist/features/column-filtering/filterFns.js.map +1 -0
  53. package/dist/features/column-grouping/columnGroupingFeature.cjs +3 -12
  54. package/dist/features/column-grouping/columnGroupingFeature.cjs.map +1 -1
  55. package/dist/features/column-grouping/columnGroupingFeature.d.cts +1 -1
  56. package/dist/features/column-grouping/columnGroupingFeature.d.ts +1 -1
  57. package/dist/features/column-grouping/columnGroupingFeature.js +4 -13
  58. package/dist/features/column-grouping/columnGroupingFeature.js.map +1 -1
  59. package/dist/features/column-grouping/columnGroupingFeature.types.d.cts +6 -49
  60. package/dist/features/column-grouping/columnGroupingFeature.types.d.ts +6 -49
  61. package/dist/features/column-grouping/columnGroupingFeature.utils.cjs +0 -50
  62. package/dist/features/column-grouping/columnGroupingFeature.utils.cjs.map +1 -1
  63. package/dist/features/column-grouping/columnGroupingFeature.utils.d.cts +2 -39
  64. package/dist/features/column-grouping/columnGroupingFeature.utils.d.ts +2 -39
  65. package/dist/features/column-grouping/columnGroupingFeature.utils.js +2 -49
  66. package/dist/features/column-grouping/columnGroupingFeature.utils.js.map +1 -1
  67. package/dist/features/column-grouping/createGroupedRowModel.cjs +23 -13
  68. package/dist/features/column-grouping/createGroupedRowModel.cjs.map +1 -1
  69. package/dist/features/column-grouping/createGroupedRowModel.d.cts +2 -3
  70. package/dist/features/column-grouping/createGroupedRowModel.d.ts +2 -3
  71. package/dist/features/column-grouping/createGroupedRowModel.js +25 -15
  72. package/dist/features/column-grouping/createGroupedRowModel.js.map +1 -1
  73. package/dist/features/global-filtering/globalFilteringFeature.utils.cjs +4 -2
  74. package/dist/features/global-filtering/globalFilteringFeature.utils.cjs.map +1 -1
  75. package/dist/features/global-filtering/globalFilteringFeature.utils.d.cts +2 -6
  76. package/dist/features/global-filtering/globalFilteringFeature.utils.d.ts +2 -6
  77. package/dist/features/global-filtering/globalFilteringFeature.utils.js +4 -2
  78. package/dist/features/global-filtering/globalFilteringFeature.utils.js.map +1 -1
  79. package/dist/features/row-sorting/createSortedRowModel.cjs +6 -2
  80. package/dist/features/row-sorting/createSortedRowModel.cjs.map +1 -1
  81. package/dist/features/row-sorting/createSortedRowModel.d.cts +6 -2
  82. package/dist/features/row-sorting/createSortedRowModel.d.ts +6 -2
  83. package/dist/features/row-sorting/createSortedRowModel.js +6 -2
  84. package/dist/features/row-sorting/createSortedRowModel.js.map +1 -1
  85. package/dist/features/row-sorting/rowSortingFeature.types.d.cts +32 -3
  86. package/dist/features/row-sorting/rowSortingFeature.types.d.ts +32 -3
  87. package/dist/features/row-sorting/rowSortingFeature.utils.cjs +20 -5
  88. package/dist/features/row-sorting/rowSortingFeature.utils.cjs.map +1 -1
  89. package/dist/features/row-sorting/rowSortingFeature.utils.js +20 -5
  90. package/dist/features/row-sorting/rowSortingFeature.utils.js.map +1 -1
  91. package/dist/{fns → features/row-sorting}/sortFns.cjs +69 -22
  92. package/dist/features/row-sorting/sortFns.cjs.map +1 -0
  93. package/dist/features/row-sorting/sortFns.d.cts +98 -0
  94. package/dist/features/row-sorting/sortFns.d.ts +98 -0
  95. package/dist/{fns → features/row-sorting}/sortFns.js +69 -23
  96. package/dist/features/row-sorting/sortFns.js.map +1 -0
  97. package/dist/features/stockFeatures.cjs +2 -0
  98. package/dist/features/stockFeatures.cjs.map +1 -1
  99. package/dist/features/stockFeatures.d.cts +2 -0
  100. package/dist/features/stockFeatures.d.ts +2 -0
  101. package/dist/features/stockFeatures.js +2 -0
  102. package/dist/features/stockFeatures.js.map +1 -1
  103. package/dist/helpers/tableFeatures.cjs +5 -4
  104. package/dist/helpers/tableFeatures.cjs.map +1 -1
  105. package/dist/helpers/tableFeatures.d.cts +5 -4
  106. package/dist/helpers/tableFeatures.d.ts +5 -4
  107. package/dist/helpers/tableFeatures.js +5 -4
  108. package/dist/helpers/tableFeatures.js.map +1 -1
  109. package/dist/index.cjs +18 -3
  110. package/dist/index.d.cts +10 -8
  111. package/dist/index.d.ts +10 -8
  112. package/dist/index.js +6 -4
  113. package/dist/static-functions.cjs +8 -3
  114. package/dist/static-functions.d.cts +3 -2
  115. package/dist/static-functions.d.ts +3 -2
  116. package/dist/static-functions.js +3 -2
  117. package/dist/types/Cell.d.cts +3 -1
  118. package/dist/types/Cell.d.ts +3 -1
  119. package/dist/types/Column.d.cts +4 -2
  120. package/dist/types/Column.d.ts +4 -2
  121. package/dist/types/ColumnDef.d.cts +5 -3
  122. package/dist/types/ColumnDef.d.ts +5 -3
  123. package/dist/types/Row.d.cts +3 -1
  124. package/dist/types/Row.d.ts +3 -1
  125. package/dist/types/RowModel.d.cts +1 -1
  126. package/dist/types/RowModel.d.ts +1 -1
  127. package/dist/types/RowModelFns.d.cts +3 -3
  128. package/dist/types/RowModelFns.d.ts +3 -3
  129. package/dist/types/Table.d.cts +1 -1
  130. package/dist/types/Table.d.ts +1 -1
  131. package/dist/types/TableFeatures.d.cts +19 -11
  132. package/dist/types/TableFeatures.d.ts +19 -11
  133. package/dist/types/TableOptions.d.cts +5 -3
  134. package/dist/types/TableOptions.d.ts +5 -3
  135. package/dist/types/TableState.d.cts +1 -1
  136. package/dist/types/TableState.d.ts +1 -1
  137. package/dist/types/type-utils.d.cts +8 -1
  138. package/dist/types/type-utils.d.ts +8 -1
  139. package/dist/worker/initTableWorker.cjs.map +1 -1
  140. package/dist/worker/initTableWorker.js.map +1 -1
  141. package/package.json +1 -1
  142. package/skills/aggregation/SKILL.md +131 -0
  143. package/skills/api-not-found/SKILL.md +1 -1
  144. package/skills/client-vs-server/SKILL.md +1 -1
  145. package/skills/column-faceting/SKILL.md +11 -5
  146. package/skills/column-filtering/SKILL.md +8 -3
  147. package/skills/column-ordering/SKILL.md +1 -1
  148. package/skills/column-pinning/SKILL.md +1 -1
  149. package/skills/column-resizing/SKILL.md +1 -1
  150. package/skills/column-sizing/SKILL.md +1 -1
  151. package/skills/column-visibility/SKILL.md +1 -1
  152. package/skills/core/SKILL.md +1 -1
  153. package/skills/custom-features/SKILL.md +1 -1
  154. package/skills/expanding/SKILL.md +1 -1
  155. package/skills/global-filtering/SKILL.md +3 -3
  156. package/skills/grouping/SKILL.md +12 -13
  157. package/skills/migrate-v8-to-v9/SKILL.md +21 -8
  158. package/skills/pagination/SKILL.md +1 -1
  159. package/skills/row-pinning/SKILL.md +1 -1
  160. package/skills/row-selection/SKILL.md +1 -1
  161. package/skills/sorting/SKILL.md +9 -3
  162. package/skills/table-features/SKILL.md +19 -13
  163. package/skills/typescript/SKILL.md +1 -1
  164. package/src/core/row-models/coreRowModelsFeature.utils.ts +1 -1
  165. package/src/features/aggregation/aggregationFeature.ts +59 -0
  166. package/src/features/aggregation/aggregationFeature.types.ts +312 -0
  167. package/src/features/aggregation/aggregationFeature.utils.ts +401 -0
  168. package/src/features/aggregation/aggregationFns.ts +336 -0
  169. package/src/features/column-filtering/columnFilteringFeature.types.ts +61 -1
  170. package/src/features/column-filtering/columnFilteringFeature.utils.ts +33 -19
  171. package/src/features/column-filtering/createFilteredRowModel.ts +13 -3
  172. package/src/features/column-filtering/filterFns.ts +533 -0
  173. package/src/features/column-grouping/columnGroupingFeature.ts +1 -20
  174. package/src/features/column-grouping/columnGroupingFeature.types.ts +4 -86
  175. package/src/features/column-grouping/columnGroupingFeature.utils.ts +1 -88
  176. package/src/features/column-grouping/createGroupedRowModel.ts +32 -38
  177. package/src/features/global-filtering/globalFilteringFeature.utils.ts +9 -1
  178. package/src/features/row-sorting/createSortedRowModel.ts +6 -2
  179. package/src/features/row-sorting/rowSortingFeature.types.ts +54 -2
  180. package/src/features/row-sorting/rowSortingFeature.utils.ts +46 -14
  181. package/src/{fns → features/row-sorting}/sortFns.ts +95 -81
  182. package/src/features/stockFeatures.ts +3 -0
  183. package/src/helpers/tableFeatures.ts +5 -4
  184. package/src/index.ts +7 -8
  185. package/src/static-functions.ts +1 -0
  186. package/src/types/Cell.ts +2 -0
  187. package/src/types/Column.ts +3 -1
  188. package/src/types/ColumnDef.ts +6 -3
  189. package/src/types/Row.ts +2 -0
  190. package/src/types/RowModelFns.ts +3 -3
  191. package/src/types/TableFeatures.ts +19 -11
  192. package/src/types/TableOptions.ts +5 -1
  193. package/src/types/type-utils.ts +8 -0
  194. package/src/worker/initTableWorker.ts +1 -1
  195. package/dist/fns/aggregationFns.cjs +0 -163
  196. package/dist/fns/aggregationFns.cjs.map +0 -1
  197. package/dist/fns/aggregationFns.d.cts +0 -85
  198. package/dist/fns/aggregationFns.d.ts +0 -85
  199. package/dist/fns/aggregationFns.js +0 -153
  200. package/dist/fns/aggregationFns.js.map +0 -1
  201. package/dist/fns/filterFns.cjs +0 -242
  202. package/dist/fns/filterFns.cjs.map +0 -1
  203. package/dist/fns/filterFns.d.cts +0 -178
  204. package/dist/fns/filterFns.d.ts +0 -178
  205. package/dist/fns/filterFns.js +0 -226
  206. package/dist/fns/filterFns.js.map +0 -1
  207. package/dist/fns/sortFns.cjs.map +0 -1
  208. package/dist/fns/sortFns.d.cts +0 -65
  209. package/dist/fns/sortFns.d.ts +0 -65
  210. package/dist/fns/sortFns.js.map +0 -1
  211. package/src/fns/aggregationFns.ts +0 -245
  212. package/src/fns/filterFns.ts +0 -455
@@ -0,0 +1,533 @@
1
+ import type {
2
+ CreatedFilterFn,
3
+ ExtractFilterMeta,
4
+ FilterFnDef,
5
+ } from './columnFilteringFeature.types'
6
+ import type { RowData } from '../../types/type-utils'
7
+ import type { TableFeatures } from '../../types/TableFeatures'
8
+ import type { Row } from '../../types/Row'
9
+
10
+ /**
11
+ * Builds a `FilterFn` from a value-level comparator plus optional resolvers.
12
+ *
13
+ * The `filter` comparator receives the row's data value (already passed
14
+ * through `resolveDataValue` when one is defined) and the filter value
15
+ * (already passed through `resolveFilterValue` by the table). Keeping
16
+ * normalization in the resolvers means a variant of an existing filter
17
+ * function only has to swap the resolvers, not re-implement the comparison.
18
+ *
19
+ * The definition is attached to the returned function, so a variant can be
20
+ * created by spreading a built-in filter function and overriding what differs:
21
+ *
22
+ * ```ts
23
+ * const normalize = (value: unknown) =>
24
+ * String(value ?? '')
25
+ * .toLowerCase()
26
+ * .normalize('NFD')
27
+ * .replace(/\p{Diacritic}/gu, '')
28
+ *
29
+ * const includesStringIgnoreDiacritics = constructFilterFn({
30
+ * ...filterFn_includesString,
31
+ * resolveFilterValue: normalize,
32
+ * resolveDataValue: normalize,
33
+ * })
34
+ * ```
35
+ *
36
+ * Note: the table applies `resolveFilterValue` once per filter before any rows
37
+ * are tested. When calling a filter function directly (outside of a table),
38
+ * apply it yourself: `fn(row, columnId, fn.resolveFilterValue?.(value) ?? value)`.
39
+ */
40
+ export function constructFilterFn<
41
+ TFeatures extends TableFeatures = any,
42
+ TData extends RowData = any,
43
+ >(def: FilterFnDef<TFeatures, TData>): CreatedFilterFn<TFeatures, TData> {
44
+ const filterFn: CreatedFilterFn<TFeatures, TData> = Object.assign(
45
+ <TRowFeatures extends TableFeatures, TRowData extends RowData>(
46
+ row: Row<TRowFeatures, TRowData>,
47
+ columnId: string,
48
+ filterValue: any,
49
+ addMeta?: (meta: ExtractFilterMeta<TRowFeatures>) => void,
50
+ ): boolean => {
51
+ const rawValue = row.getValue(columnId)
52
+ const dataValue = filterFn.resolveDataValue
53
+ ? filterFn.resolveDataValue(rawValue)
54
+ : rawValue
55
+ // The def's comparator is typed against the factory's TFeatures/TData;
56
+ // the caller's row generics are erased at this boundary.
57
+ return filterFn.filter(
58
+ dataValue,
59
+ filterValue,
60
+ row as any,
61
+ columnId,
62
+ addMeta as any,
63
+ )
64
+ },
65
+ def,
66
+ )
67
+ return filterFn
68
+ }
69
+
70
+ // Basic filters
71
+
72
+ /**
73
+ * Keeps rows whose column value is strictly equal to the filter value.
74
+ *
75
+ * Uses JavaScript `===` comparison and auto-removes empty filter values.
76
+ */
77
+ export const filterFn_equals = constructFilterFn({
78
+ filter: (dataValue, filterValue) => dataValue === filterValue,
79
+ autoRemove: (val: any) => testFalsy(val),
80
+ })
81
+
82
+ /**
83
+ * Keeps rows whose column value is loosely equal to the filter value.
84
+ *
85
+ * Uses JavaScript `==` comparison and auto-removes empty filter values. This is
86
+ * useful for matching string input against numeric row values.
87
+ */
88
+ export const filterFn_weakEquals = constructFilterFn({
89
+ filter: (dataValue, filterValue) => dataValue == filterValue,
90
+ autoRemove: (val: any) => testFalsy(val),
91
+ })
92
+
93
+ // String filters
94
+
95
+ /**
96
+ * Keeps rows whose stringified column value includes the filter text.
97
+ *
98
+ * Matching is case-sensitive and empty filter values are auto-removed.
99
+ */
100
+ export const filterFn_includesStringSensitive = constructFilterFn({
101
+ filter: (dataValue, filterValue) => Boolean(dataValue?.includes(filterValue)),
102
+ autoRemove: (val: any) => testFalsy(val),
103
+ resolveFilterValue: (val: any) => String(val),
104
+ resolveDataValue: (val: any) => (val == null ? undefined : String(val)),
105
+ })
106
+
107
+ /**
108
+ * Keeps rows whose stringified column value includes the filter text.
109
+ *
110
+ * Both values are lowercased before comparison, and empty filter values are
111
+ * auto-removed.
112
+ */
113
+ export const filterFn_includesString = constructFilterFn({
114
+ filter: (dataValue, filterValue) => Boolean(dataValue?.includes(filterValue)),
115
+ autoRemove: (val: any) => testFalsy(val),
116
+ resolveFilterValue: (val: any) => String(val).toLowerCase(),
117
+ resolveDataValue: (val: any) =>
118
+ val == null ? undefined : String(val).toLowerCase(),
119
+ })
120
+
121
+ /**
122
+ * Keeps rows whose stringified column value equals the filter text.
123
+ *
124
+ * Both values are lowercased before comparison, and empty filter values are
125
+ * auto-removed.
126
+ */
127
+ export const filterFn_equalsString = constructFilterFn({
128
+ filter: (dataValue, filterValue) => dataValue === filterValue,
129
+ autoRemove: (val: any) => testFalsy(val),
130
+ resolveFilterValue: (val: any) => String(val).toLowerCase(),
131
+ resolveDataValue: (val: any) =>
132
+ val == null ? undefined : String(val).toLowerCase(),
133
+ })
134
+
135
+ /**
136
+ * Keeps rows whose stringified column value exactly equals the filter text.
137
+ *
138
+ * Matching is case-sensitive and empty filter values are auto-removed.
139
+ */
140
+ export const filterFn_equalsStringSensitive = constructFilterFn({
141
+ filter: (dataValue, filterValue) => dataValue === filterValue,
142
+ autoRemove: (val: any) => testFalsy(val),
143
+ resolveFilterValue: (val: any) => String(val),
144
+ resolveDataValue: (val: any) => (val == null ? undefined : String(val)),
145
+ })
146
+
147
+ /**
148
+ * Keeps rows whose stringified column value starts with the filter text.
149
+ *
150
+ * Both values are lowercased before comparison, and empty filter values are
151
+ * auto-removed.
152
+ */
153
+ export const filterFn_startsWith = constructFilterFn({
154
+ filter: (dataValue, filterValue) =>
155
+ Boolean(dataValue?.startsWith(filterValue)),
156
+ autoRemove: (val: any) => testFalsy(val),
157
+ resolveFilterValue: (val: any) => String(val).toLowerCase(),
158
+ resolveDataValue: (val: any) =>
159
+ val == null ? undefined : String(val).toLowerCase(),
160
+ })
161
+
162
+ /**
163
+ * Keeps rows whose stringified column value ends with the filter text.
164
+ *
165
+ * Both values are lowercased before comparison, and empty filter values are
166
+ * auto-removed.
167
+ */
168
+ export const filterFn_endsWith = constructFilterFn({
169
+ filter: (dataValue, filterValue) => Boolean(dataValue?.endsWith(filterValue)),
170
+ autoRemove: (val: any) => testFalsy(val),
171
+ resolveFilterValue: (val: any) => String(val).toLowerCase(),
172
+ resolveDataValue: (val: any) =>
173
+ val == null ? undefined : String(val).toLowerCase(),
174
+ })
175
+
176
+ // Blank filters
177
+
178
+ /**
179
+ * Keeps rows whose column value is empty.
180
+ *
181
+ * A value is empty when it is nullish or stringifies to whitespace only. The
182
+ * filter value acts as an on/off flag: `false` and blank values are
183
+ * auto-removed.
184
+ */
185
+ export const filterFn_empty = constructFilterFn({
186
+ filter: (dataValue) => testValueEmpty(dataValue),
187
+ autoRemove: (val: any) => testFalsy(val) || val === false,
188
+ })
189
+
190
+ /**
191
+ * Keeps rows whose column value is not empty.
192
+ *
193
+ * A value is empty when it is nullish or stringifies to whitespace only. The
194
+ * filter value acts as an on/off flag: `false` and blank values are
195
+ * auto-removed.
196
+ */
197
+ export const filterFn_notEmpty = constructFilterFn({
198
+ filter: (dataValue) => !testValueEmpty(dataValue),
199
+ autoRemove: (val: any) => testFalsy(val) || val === false,
200
+ })
201
+
202
+ // Number filters
203
+
204
+ /**
205
+ * Keeps rows whose value is greater than the filter value.
206
+ *
207
+ * Numeric values are compared numerically when both sides can be coerced to
208
+ * numbers; otherwise normalized strings are compared.
209
+ */
210
+ export const filterFn_greaterThan = constructFilterFn({
211
+ filter: (dataValue, filterValue) =>
212
+ compareGreaterThan(dataValue, filterValue),
213
+ autoRemove: (val: any) => testFalsy(val),
214
+ })
215
+
216
+ /**
217
+ * Keeps rows whose value is greater than or equal to the filter value.
218
+ *
219
+ * Delegates to the built-in greater-than and strict-equality comparisons.
220
+ */
221
+ export const filterFn_greaterThanOrEqualTo = constructFilterFn({
222
+ filter: (dataValue, filterValue) =>
223
+ compareGreaterThanOrEqualTo(dataValue, filterValue),
224
+ autoRemove: (val: any) => testFalsy(val),
225
+ })
226
+
227
+ /**
228
+ * Keeps rows whose value is less than the filter value.
229
+ *
230
+ * This is implemented as the inverse of greater-than-or-equal comparison.
231
+ */
232
+ export const filterFn_lessThan = constructFilterFn({
233
+ filter: (dataValue, filterValue) =>
234
+ !compareGreaterThanOrEqualTo(dataValue, filterValue),
235
+ autoRemove: (val: any) => testFalsy(val),
236
+ })
237
+
238
+ /**
239
+ * Keeps rows whose value is less than or equal to the filter value.
240
+ *
241
+ * This is implemented as the inverse of greater-than comparison.
242
+ */
243
+ export const filterFn_lessThanOrEqualTo = constructFilterFn({
244
+ filter: (dataValue, filterValue) =>
245
+ !compareGreaterThan(dataValue, filterValue),
246
+ autoRemove: (val: any) => testFalsy(val),
247
+ })
248
+
249
+ // Range filters
250
+
251
+ /**
252
+ * Keeps rows whose value falls between an exclusive min/max pair.
253
+ *
254
+ * Blank range endpoints are treated as open-ended.
255
+ */
256
+ export const filterFn_between = constructFilterFn({
257
+ filter: (dataValue, filterValues: [unknown, unknown]) =>
258
+ compareBetween(dataValue, filterValues, false),
259
+ autoRemove: (val: any) =>
260
+ testFalsy(val) ||
261
+ (Array.isArray(val) && testFalsy(val[0]) && testFalsy(val[1])),
262
+ })
263
+
264
+ /**
265
+ * Keeps rows whose value falls between an inclusive min/max pair.
266
+ *
267
+ * Blank range endpoints are treated as open-ended.
268
+ */
269
+ export const filterFn_betweenInclusive = constructFilterFn({
270
+ filter: (dataValue, filterValues: [unknown, unknown]) =>
271
+ compareBetween(dataValue, filterValues, true),
272
+ autoRemove: (val: any) =>
273
+ testFalsy(val) ||
274
+ (Array.isArray(val) && testFalsy(val[0]) && testFalsy(val[1])),
275
+ })
276
+
277
+ /**
278
+ * Keeps rows whose numeric value is inside an inclusive `[min, max]` range.
279
+ *
280
+ * Filter values are normalized so blank endpoints become open-ended and
281
+ * reversed endpoints are swapped.
282
+ */
283
+ export const filterFn_inNumberRange = constructFilterFn({
284
+ filter: (dataValue: number, filterValue: [number, number]) => {
285
+ const [min, max] = filterValue
286
+ return dataValue >= min && dataValue <= max
287
+ },
288
+ resolveFilterValue: (val: [any, any]) => {
289
+ const [unsafeMin, unsafeMax] = val
290
+
291
+ const parsedMin =
292
+ typeof unsafeMin !== 'number' ? parseFloat(unsafeMin) : unsafeMin
293
+ const parsedMax =
294
+ typeof unsafeMax !== 'number' ? parseFloat(unsafeMax) : unsafeMax
295
+
296
+ let min =
297
+ unsafeMin === null || Number.isNaN(parsedMin) ? -Infinity : parsedMin
298
+ let max =
299
+ unsafeMax === null || Number.isNaN(parsedMax) ? Infinity : parsedMax
300
+
301
+ if (min > max) {
302
+ const temp = min
303
+ min = max
304
+ max = temp
305
+ }
306
+
307
+ return [min, max] as const
308
+ },
309
+ autoRemove: (val: any) =>
310
+ testFalsy(val) ||
311
+ (Array.isArray(val) && testFalsy(val[0]) && testFalsy(val[1])),
312
+ })
313
+
314
+ // Date filters
315
+
316
+ /**
317
+ * Keeps rows whose date value is inside an inclusive `[min, max]` date range.
318
+ *
319
+ * Row values and range endpoints may be `Date` objects, timestamps, or
320
+ * parseable date strings. Blank or invalid endpoints become open-ended and
321
+ * reversed endpoints are swapped. Rows without a valid date never match.
322
+ */
323
+ export const filterFn_inDateRange = constructFilterFn({
324
+ filter: (dataValue: number, filterValue: [number, number]) => {
325
+ const [min, max] = filterValue
326
+ return dataValue >= min && dataValue <= max
327
+ },
328
+ resolveFilterValue: (val: [any, any]) => {
329
+ const [unsafeMin, unsafeMax] = val
330
+
331
+ const parsedMin = toDateTimestamp(unsafeMin)
332
+ const parsedMax = toDateTimestamp(unsafeMax)
333
+
334
+ let min = Number.isNaN(parsedMin) ? -Infinity : parsedMin
335
+ let max = Number.isNaN(parsedMax) ? Infinity : parsedMax
336
+
337
+ if (min > max) {
338
+ const temp = min
339
+ min = max
340
+ max = temp
341
+ }
342
+
343
+ return [min, max] as const
344
+ },
345
+ resolveDataValue: (val: any) => toDateTimestamp(val),
346
+ autoRemove: (val: any) =>
347
+ testFalsy(val) ||
348
+ (Array.isArray(val) && testFalsy(val[0]) && testFalsy(val[1])),
349
+ })
350
+
351
+ // Array filters
352
+
353
+ /**
354
+ * Keeps rows whose scalar column value equals at least one filter value.
355
+ */
356
+ export const filterFn_arrHas = constructFilterFn({
357
+ filter: (dataValue, filterValue: Array<unknown>) => {
358
+ for (let i = 0; i < filterValue.length; i++) {
359
+ if (dataValue === filterValue[i]) {
360
+ return true
361
+ }
362
+ }
363
+ return false
364
+ },
365
+ autoRemove: (val: any) => testFalsy(val) || !val?.length,
366
+ })
367
+
368
+ /**
369
+ * Keeps rows whose array or string column value includes at least one filter value.
370
+ */
371
+ export const filterFn_arrIncludes = constructFilterFn({
372
+ filter: (dataValue, filterValue: Array<unknown>) => {
373
+ if (typeof dataValue !== 'string' && !Array.isArray(dataValue)) {
374
+ return false
375
+ }
376
+
377
+ for (let i = 0; i < filterValue.length; i++) {
378
+ if (dataValue.includes(filterValue[i] as any)) {
379
+ return true
380
+ }
381
+ }
382
+ return false
383
+ },
384
+ autoRemove: (val: any) => testFalsy(val) || !val?.length,
385
+ })
386
+
387
+ /**
388
+ * Keeps rows whose array column value includes every filter value.
389
+ */
390
+ export const filterFn_arrIncludesAll = constructFilterFn({
391
+ filter: (dataValue, filterValue: Array<unknown>) => {
392
+ if (!Array.isArray(dataValue)) return false
393
+ for (let i = 0; i < filterValue.length; i++) {
394
+ if (!dataValue.includes(filterValue[i])) {
395
+ return false
396
+ }
397
+ }
398
+ return true
399
+ },
400
+ autoRemove: (val: any) => testFalsy(val) || !val?.length,
401
+ })
402
+
403
+ /**
404
+ * Keeps rows whose array column value includes at least one filter value.
405
+ */
406
+ export const filterFn_arrIncludesSome = constructFilterFn({
407
+ filter: (dataValue, filterValue: Array<unknown>) => {
408
+ if (!Array.isArray(dataValue)) return false
409
+ for (let i = 0; i < filterValue.length; i++) {
410
+ if (dataValue.includes(filterValue[i])) {
411
+ return true
412
+ }
413
+ }
414
+ return false
415
+ },
416
+ autoRemove: (val: any) => testFalsy(val) || !val?.length,
417
+ })
418
+
419
+ // Export
420
+
421
+ /**
422
+ * The built-in filter function registry.
423
+ *
424
+ * Registering this full object opts out of tree-shaking: every built-in
425
+ * filter function ends up in your bundle. Prefer importing the `filterFn_*`
426
+ * functions you actually use and registering just those in the `filterFns`
427
+ * slot, or passing them directly to the `filterFn` column option.
428
+ *
429
+ * @deprecated Import individual `filterFn_*` functions instead for a smaller
430
+ * bundle. This export still works and is not going away in v9, but built-in
431
+ * name resolution (including `filterFn: 'auto'`) only finds functions you
432
+ * register yourself.
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
+ empty: filterFn_empty,
442
+ endsWith: filterFn_endsWith,
443
+ equals: filterFn_equals,
444
+ equalsString: filterFn_equalsString,
445
+ equalsStringSensitive: filterFn_equalsStringSensitive,
446
+ inDateRange: filterFn_inDateRange,
447
+ inNumberRange: filterFn_inNumberRange,
448
+ includesString: filterFn_includesString,
449
+ includesStringSensitive: filterFn_includesStringSensitive,
450
+ notEmpty: filterFn_notEmpty,
451
+ startsWith: filterFn_startsWith,
452
+ weakEquals: filterFn_weakEquals,
453
+ }
454
+
455
+ export type BuiltInFilterFn = keyof typeof filterFns
456
+
457
+ // Utils
458
+
459
+ function testFalsy(val: any) {
460
+ return val === undefined || val === null || val === ''
461
+ }
462
+
463
+ function testValueEmpty(dataValue: any) {
464
+ return dataValue == null || String(dataValue).trim() === ''
465
+ }
466
+
467
+ function toDateTimestamp(value: any): number {
468
+ if (value instanceof Date) {
469
+ return value.getTime()
470
+ }
471
+ if (typeof value === 'number') {
472
+ return value
473
+ }
474
+ // Guard nullish and blank values explicitly: `new Date(null)` is the epoch,
475
+ // not an invalid date.
476
+ if (value == null || value === '') {
477
+ return NaN
478
+ }
479
+ return new Date(value).getTime()
480
+ }
481
+
482
+ function compareGreaterThan(dataValue: any, filterValue: any): boolean {
483
+ const numericDataValue = dataValue == null ? 0 : +dataValue
484
+ const numericFilterValue = Number(filterValue)
485
+
486
+ if (!isNaN(numericFilterValue) && !isNaN(numericDataValue)) {
487
+ return numericDataValue > numericFilterValue
488
+ }
489
+
490
+ const stringDataValue = String(dataValue ?? '')
491
+ .toLowerCase()
492
+ .trim()
493
+ const stringFilterValue = String(filterValue).toLowerCase().trim()
494
+ return stringDataValue > stringFilterValue
495
+ }
496
+
497
+ function compareGreaterThanOrEqualTo(dataValue: any, filterValue: any) {
498
+ return dataValue === filterValue || compareGreaterThan(dataValue, filterValue)
499
+ }
500
+
501
+ function compareBetween(
502
+ dataValue: any,
503
+ filterValues: [unknown, unknown],
504
+ inclusive: boolean,
505
+ ): boolean {
506
+ const min = filterValues[0]
507
+ const hasMin = min !== '' && min !== undefined
508
+ if (hasMin) {
509
+ const passesMin = inclusive
510
+ ? compareGreaterThanOrEqualTo(dataValue, min)
511
+ : compareGreaterThan(dataValue, min)
512
+ if (!passesMin) {
513
+ return false
514
+ }
515
+ }
516
+
517
+ const max = filterValues[1]
518
+ if (max === '' || max === undefined) {
519
+ return true
520
+ }
521
+
522
+ if (hasMin) {
523
+ const numericMin = Number(min)
524
+ const numericMax = Number(max)
525
+ if (!isNaN(numericMin) && !isNaN(numericMax) && numericMin > numericMax) {
526
+ return true
527
+ }
528
+ }
529
+
530
+ return inclusive
531
+ ? !compareGreaterThan(dataValue, max)
532
+ : !compareGreaterThanOrEqualTo(dataValue, max)
533
+ }
@@ -5,11 +5,8 @@ import {
5
5
  makeStateUpdater,
6
6
  } from '../../utils'
7
7
  import {
8
- cell_getIsAggregated,
9
8
  cell_getIsGrouped,
10
9
  cell_getIsPlaceholder,
11
- column_getAggregationFn,
12
- column_getAutoAggregationFn,
13
10
  column_getCanGroup,
14
11
  column_getGroupedIndex,
15
12
  column_getIsGrouped,
@@ -24,7 +21,7 @@ import {
24
21
  import type { TableFeature } from '../../types/TableFeatures'
25
22
 
26
23
  /**
27
- * Feature that adds column grouping state, aggregation defaults, and grouped row APIs.
24
+ * Feature that adds column grouping state and grouped row APIs.
28
25
  */
29
26
  export const columnGroupingFeature: TableFeature = {
30
27
  getInitialState: (initialState) => {
@@ -34,13 +31,6 @@ export const columnGroupingFeature: TableFeature = {
34
31
  }
35
32
  },
36
33
 
37
- getDefaultColumnDef: () => {
38
- return {
39
- aggregatedCell: ({ getValue }: any) => getValue()?.toString?.() ?? null,
40
- aggregationFn: 'auto',
41
- }
42
- },
43
-
44
34
  getDefaultTableOptions: (table) => {
45
35
  return {
46
36
  onGroupingChange: makeStateUpdater('grouping', table),
@@ -56,9 +46,6 @@ export const columnGroupingFeature: TableFeature = {
56
46
  cell_getIsPlaceholder: {
57
47
  fn: (cell) => cell_getIsPlaceholder(cell),
58
48
  },
59
- cell_getIsAggregated: {
60
- fn: (cell) => cell_getIsAggregated(cell),
61
- },
62
49
  })
63
50
  },
64
51
 
@@ -79,12 +66,6 @@ export const columnGroupingFeature: TableFeature = {
79
66
  column_getToggleGroupingHandler: {
80
67
  fn: (column) => column_getToggleGroupingHandler(column),
81
68
  },
82
- column_getAutoAggregationFn: {
83
- fn: (column) => column_getAutoAggregationFn(column),
84
- },
85
- column_getAggregationFn: {
86
- fn: (column) => column_getAggregationFn(column),
87
- },
88
69
  })
89
70
  },
90
71
 
@@ -1,15 +1,7 @@
1
1
  import type { RowModel } from '../../core/row-models/coreRowModelsFeature.types'
2
- import type { BuiltInAggregationFn } from '../../fns/aggregationFns'
3
- import type {
4
- CellData,
5
- OnChangeFn,
6
- RowData,
7
- Updater,
8
- } from '../../types/type-utils'
9
- import type { IsAny, TableFeatures } from '../../types/TableFeatures'
2
+ import type { OnChangeFn, RowData, Updater } from '../../types/type-utils'
3
+ import type { TableFeatures } from '../../types/TableFeatures'
10
4
  import type { Row } from '../../types/Row'
11
- import type { Cell } from '../../types/Cell'
12
- import type { ColumnDefTemplate } from '../../types/ColumnDef'
13
5
 
14
6
  export type GroupingState = Array<string>
15
7
 
@@ -17,69 +9,10 @@ export interface TableState_ColumnGrouping {
17
9
  grouping: GroupingState
18
10
  }
19
11
 
20
- export interface RowModelFns_ColumnGrouping<
21
- in out TFeatures extends TableFeatures,
22
- in out TData extends RowData,
23
- > {
24
- aggregationFns: Record<string, AggregationFn<TFeatures, TData>>
25
- }
26
-
27
- export interface AggregationFns {}
28
-
29
- export type AggregationFn<
30
- TFeatures extends TableFeatures,
31
- TData extends RowData,
32
- > = (
33
- columnId: string,
34
- leafRows: Array<Row<TFeatures, TData>>,
35
- childRows: Array<Row<TFeatures, TData>>,
36
- ) => any
37
-
38
- export type CustomAggregationFns<
39
- TFeatures extends TableFeatures,
40
- TData extends RowData,
41
- > = Record<string, AggregationFn<TFeatures, TData>>
42
-
43
- /**
44
- * Resolves the valid string names for `columnDef.aggregationFn` for a feature
45
- * set.
46
- *
47
- * When the features object declares an `aggregationFns` registry
48
- * (`tableFeatures({ ..., aggregationFns })`), its keys are the only valid
49
- * names; a name is only assignable if an aggregation function is actually
50
- * registered for it. Otherwise this falls back to the global
51
- * declaration-merged `AggregationFns` interface.
52
- */
53
- export type ExtractAggregationFnKeys<TFeatures extends TableFeatures> =
54
- IsAny<TFeatures> extends true
55
- ? keyof AggregationFns | BuiltInAggregationFn
56
- : TFeatures extends { aggregationFns: infer TAggregationFns extends object }
57
- ? Extract<keyof TAggregationFns, string>
58
- : keyof AggregationFns
59
-
60
- export type AggregationFnOption<
61
- TFeatures extends TableFeatures,
62
- TData extends RowData,
63
- > =
64
- | 'auto'
65
- | ExtractAggregationFnKeys<TFeatures>
66
- | AggregationFn<TFeatures, TData>
67
-
68
12
  export interface ColumnDef_ColumnGrouping<
69
13
  in out TFeatures extends TableFeatures,
70
14
  in out TData extends RowData,
71
- TValue extends CellData = CellData,
72
15
  > {
73
- /**
74
- * The cell to display each row for the column if the cell is an aggregate. If a function is passed, it will be passed a props object with the context of the cell and should return the property type for your adapter (the exact type depends on the adapter being used).
75
- */
76
- aggregatedCell?: ColumnDefTemplate<
77
- ReturnType<Cell<TFeatures, TData, TValue>['getContext']>
78
- >
79
- /**
80
- * The resolved aggregation function for the column.
81
- */
82
- aggregationFn?: AggregationFnOption<TFeatures, TData>
83
16
  /**
84
17
  * Allows this column to be added to grouping state.
85
18
  *
@@ -99,18 +32,7 @@ export interface ColumnDef_ColumnGrouping<
99
32
  ) => any
100
33
  }
101
34
 
102
- export interface Column_ColumnGrouping<
103
- in out TFeatures extends TableFeatures,
104
- in out TData extends RowData,
105
- > {
106
- /**
107
- * Returns the aggregation function for the column.
108
- */
109
- getAggregationFn: () => AggregationFn<TFeatures, TData> | undefined
110
- /**
111
- * Returns the automatically inferred aggregation function for the column.
112
- */
113
- getAutoAggregationFn: () => AggregationFn<TFeatures, TData> | undefined
35
+ export interface Column_ColumnGrouping {
114
36
  /**
115
37
  * Checks whether this column can currently be grouped.
116
38
  */
@@ -154,10 +76,6 @@ export interface Row_ColumnGrouping {
154
76
  }
155
77
 
156
78
  export interface Cell_ColumnGrouping {
157
- /**
158
- * Checks whether this cell should render an aggregated value.
159
- */
160
- getIsAggregated: () => boolean
161
79
  /**
162
80
  * Checks whether this cell represents the active grouping column.
163
81
  */
@@ -217,7 +135,7 @@ export interface Table_RowModels_Grouped<
217
135
  in out TData extends RowData,
218
136
  > {
219
137
  /**
220
- * Resolves the row model after grouping and aggregation have been applied.
138
+ * Resolves the row model after grouping has been applied.
221
139
  */
222
140
  getGroupedRowModel: () => RowModel<TFeatures, TData>
223
141
  /**