@tanstack/table-core 9.0.0-beta.49 → 9.0.0-beta.50

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 (73) hide show
  1. package/dist/core/rows/coreRowsFeature.cjs +5 -1
  2. package/dist/core/rows/coreRowsFeature.cjs.map +1 -1
  3. package/dist/core/rows/coreRowsFeature.js +6 -2
  4. package/dist/core/rows/coreRowsFeature.js.map +1 -1
  5. package/dist/core/rows/coreRowsFeature.types.d.cts +8 -0
  6. package/dist/core/rows/coreRowsFeature.types.d.ts +8 -0
  7. package/dist/core/rows/coreRowsFeature.utils.cjs +11 -0
  8. package/dist/core/rows/coreRowsFeature.utils.cjs.map +1 -1
  9. package/dist/core/rows/coreRowsFeature.utils.d.cts +6 -1
  10. package/dist/core/rows/coreRowsFeature.utils.d.ts +6 -1
  11. package/dist/core/rows/coreRowsFeature.utils.js +11 -1
  12. package/dist/core/rows/coreRowsFeature.utils.js.map +1 -1
  13. package/dist/features/aggregation/aggregationFeature.cjs +3 -2
  14. package/dist/features/aggregation/aggregationFeature.cjs.map +1 -1
  15. package/dist/features/aggregation/aggregationFeature.js +3 -2
  16. package/dist/features/aggregation/aggregationFeature.js.map +1 -1
  17. package/dist/features/aggregation/aggregationFeature.types.cjs.map +1 -1
  18. package/dist/features/aggregation/aggregationFeature.types.d.cts +36 -13
  19. package/dist/features/aggregation/aggregationFeature.types.d.ts +36 -13
  20. package/dist/features/aggregation/aggregationFeature.types.js.map +1 -1
  21. package/dist/features/aggregation/aggregationFeature.utils.cjs +36 -22
  22. package/dist/features/aggregation/aggregationFeature.utils.cjs.map +1 -1
  23. package/dist/features/aggregation/aggregationFeature.utils.d.cts +9 -8
  24. package/dist/features/aggregation/aggregationFeature.utils.d.ts +9 -8
  25. package/dist/features/aggregation/aggregationFeature.utils.js +36 -22
  26. package/dist/features/aggregation/aggregationFeature.utils.js.map +1 -1
  27. package/dist/features/aggregation/aggregationFns.cjs +35 -29
  28. package/dist/features/aggregation/aggregationFns.cjs.map +1 -1
  29. package/dist/features/aggregation/aggregationFns.d.cts +8 -7
  30. package/dist/features/aggregation/aggregationFns.d.ts +8 -7
  31. package/dist/features/aggregation/aggregationFns.js +35 -29
  32. package/dist/features/aggregation/aggregationFns.js.map +1 -1
  33. package/dist/features/column-grouping/createGroupedRowModel.cjs +3 -3
  34. package/dist/features/column-grouping/createGroupedRowModel.cjs.map +1 -1
  35. package/dist/features/column-grouping/createGroupedRowModel.js +3 -3
  36. package/dist/features/column-grouping/createGroupedRowModel.js.map +1 -1
  37. package/dist/index.d.cts +2 -2
  38. package/dist/index.d.ts +2 -2
  39. package/dist/static-functions.cjs +1 -0
  40. package/dist/static-functions.d.cts +2 -2
  41. package/dist/static-functions.d.ts +2 -2
  42. package/dist/static-functions.js +2 -2
  43. package/package.json +1 -1
  44. package/skills/aggregation/SKILL.md +25 -15
  45. package/skills/api-not-found/SKILL.md +1 -1
  46. package/skills/client-vs-server/SKILL.md +1 -1
  47. package/skills/column-faceting/SKILL.md +1 -1
  48. package/skills/column-filtering/SKILL.md +1 -1
  49. package/skills/column-ordering/SKILL.md +1 -1
  50. package/skills/column-pinning/SKILL.md +1 -1
  51. package/skills/column-resizing/SKILL.md +1 -1
  52. package/skills/column-sizing/SKILL.md +1 -1
  53. package/skills/column-visibility/SKILL.md +1 -1
  54. package/skills/core/SKILL.md +1 -1
  55. package/skills/custom-features/SKILL.md +1 -1
  56. package/skills/expanding/SKILL.md +1 -1
  57. package/skills/global-filtering/SKILL.md +1 -1
  58. package/skills/grouping/SKILL.md +1 -1
  59. package/skills/migrate-v8-to-v9/SKILL.md +11 -3
  60. package/skills/pagination/SKILL.md +1 -1
  61. package/skills/row-pinning/SKILL.md +1 -1
  62. package/skills/row-selection/SKILL.md +1 -1
  63. package/skills/sorting/SKILL.md +1 -1
  64. package/skills/table-features/SKILL.md +1 -1
  65. package/skills/typescript/SKILL.md +1 -1
  66. package/src/core/rows/coreRowsFeature.ts +5 -0
  67. package/src/core/rows/coreRowsFeature.types.ts +8 -0
  68. package/src/core/rows/coreRowsFeature.utils.ts +18 -0
  69. package/src/features/aggregation/aggregationFeature.ts +2 -1
  70. package/src/features/aggregation/aggregationFeature.types.ts +39 -12
  71. package/src/features/aggregation/aggregationFeature.utils.ts +56 -27
  72. package/src/features/aggregation/aggregationFns.ts +42 -33
  73. package/src/features/column-grouping/createGroupedRowModel.ts +3 -3
@@ -39,8 +39,8 @@ function collectRangeValues(context: AggregationContext<any, any, unknown>) {
39
39
  }
40
40
 
41
41
  /**
42
- * Sums numeric row values. Non-number values contribute zero. As in the
43
- * previous API, `NaN` is a number and therefore propagates through the sum.
42
+ * Sums numeric selected-row values. Non-number values contribute zero. As in
43
+ * the previous API, `NaN` is a number and therefore propagates through the sum.
44
44
  */
45
45
  export const aggregationFn_sum = constructAggregationFn<
46
46
  any,
@@ -56,10 +56,10 @@ export const aggregationFn_sum = constructAggregationFn<
56
56
  }
57
57
  return sum
58
58
  },
59
- merge: ({ childResults }) => {
59
+ merge: ({ subRowResults }) => {
60
60
  let sum = 0
61
- for (let i = 0; i < childResults.length; i++) {
62
- const value = childResults[i]
61
+ for (let i = 0; i < subRowResults.length; i++) {
62
+ const value = subRowResults[i]
63
63
  if (isNumber(value)) sum += value
64
64
  }
65
65
  return sum
@@ -67,8 +67,8 @@ export const aggregationFn_sum = constructAggregationFn<
67
67
  })
68
68
 
69
69
  /**
70
- * Finds the minimum numeric or Date value. Invalid value types are ignored;
71
- * `NaN` preserves the legacy numeric seeding behavior.
70
+ * Finds the minimum numeric or Date value from the selected rows. Invalid value
71
+ * types are ignored; `NaN` preserves the legacy numeric seeding behavior.
72
72
  */
73
73
  export const aggregationFn_min = constructAggregationFn<
74
74
  any,
@@ -84,16 +84,17 @@ export const aggregationFn_min = constructAggregationFn<
84
84
  }
85
85
  return result
86
86
  },
87
- merge: ({ childResults }) => {
87
+ merge: ({ subRowResults }) => {
88
88
  let result: RangeValue | undefined
89
89
  let kind: 'date' | 'number' | undefined
90
- for (let i = 0; i < childResults.length; i++) {
91
- const value = childResults[i]
90
+ for (let i = 0; i < subRowResults.length; i++) {
91
+ const value = subRowResults[i]
92
92
  const valueKind = getRangeKind(value)
93
93
  if (!valueKind) continue
94
+ if (value === undefined) continue
94
95
  kind ??= valueKind
95
96
  if (kind !== valueKind) continue
96
- if (result === undefined || compareRangeValues(value!, result) < 0) {
97
+ if (result === undefined || compareRangeValues(value, result) < 0) {
97
98
  result = value
98
99
  }
99
100
  }
@@ -102,8 +103,8 @@ export const aggregationFn_min = constructAggregationFn<
102
103
  })
103
104
 
104
105
  /**
105
- * Finds the maximum numeric or Date value. Invalid value types are ignored;
106
- * `NaN` preserves the legacy numeric seeding behavior.
106
+ * Finds the maximum numeric or Date value from the selected rows. Invalid value
107
+ * types are ignored; `NaN` preserves the legacy numeric seeding behavior.
107
108
  */
108
109
  export const aggregationFn_max = constructAggregationFn<
109
110
  any,
@@ -119,16 +120,17 @@ export const aggregationFn_max = constructAggregationFn<
119
120
  }
120
121
  return result
121
122
  },
122
- merge: ({ childResults }) => {
123
+ merge: ({ subRowResults }) => {
123
124
  let result: RangeValue | undefined
124
125
  let kind: 'date' | 'number' | undefined
125
- for (let i = 0; i < childResults.length; i++) {
126
- const value = childResults[i]
126
+ for (let i = 0; i < subRowResults.length; i++) {
127
+ const value = subRowResults[i]
127
128
  const valueKind = getRangeKind(value)
128
129
  if (!valueKind) continue
130
+ if (value === undefined) continue
129
131
  kind ??= valueKind
130
132
  if (kind !== valueKind) continue
131
- if (result === undefined || compareRangeValues(value!, result) > 0) {
133
+ if (result === undefined || compareRangeValues(value, result) > 0) {
132
134
  result = value
133
135
  }
134
136
  }
@@ -137,7 +139,8 @@ export const aggregationFn_max = constructAggregationFn<
137
139
  })
138
140
 
139
141
  /**
140
- * Finds the minimum and maximum numeric or Date values. Empty inputs return
142
+ * Finds the minimum and maximum numeric or Date values from the selected rows.
143
+ * Empty inputs return
141
144
  * `[undefined, undefined]`, preserving the previous built-in result shape.
142
145
  */
143
146
  export const aggregationFn_extent = constructAggregationFn<
@@ -158,26 +161,32 @@ export const aggregationFn_extent = constructAggregationFn<
158
161
  }
159
162
  return [min, max]
160
163
  },
161
- merge: ({ childResults }) => {
164
+ merge: ({ subRowResults }) => {
162
165
  let result: [RangeValue | undefined, RangeValue | undefined] = [
163
166
  undefined,
164
167
  undefined,
165
168
  ]
166
169
  let kind: 'date' | 'number' | undefined
167
- for (let i = 0; i < childResults.length; i++) {
168
- const extent = childResults[i]!
169
- const valueKind = getRangeKind(extent[0])
170
- if (!valueKind) continue
170
+ for (let i = 0; i < subRowResults.length; i++) {
171
+ const extent = subRowResults[i]!
172
+ const min = extent[0]
173
+ const max = extent[1]
174
+ const valueKind = getRangeKind(min)
175
+ if (!valueKind || min === undefined || max === undefined) continue
171
176
  kind ??= valueKind
172
177
  if (kind !== valueKind) continue
173
178
  if (result[0] === undefined) {
174
- result = [extent[0], extent[1]]
179
+ result = [min, max]
175
180
  } else {
176
- if (compareRangeValues(extent[0]!, result[0]) < 0) {
177
- result[0] = extent[0]
181
+ if (compareRangeValues(min, result[0]) < 0) {
182
+ result[0] = min
178
183
  }
179
- if (compareRangeValues(extent[1]!, result[1]!) > 0) {
180
- result[1] = extent[1]
184
+ const currentMax = result[1]
185
+ if (
186
+ currentMax === undefined ||
187
+ compareRangeValues(max, currentMax) > 0
188
+ ) {
189
+ result[1] = max
181
190
  }
182
191
  }
183
192
  }
@@ -277,10 +286,10 @@ export const aggregationFn_count = constructAggregationFn<
277
286
  number
278
287
  >({
279
288
  aggregate: ({ rows }) => rows.length,
280
- merge: ({ childResults }) => {
289
+ merge: ({ subRowResults }) => {
281
290
  let count = 0
282
- for (let i = 0; i < childResults.length; i++) {
283
- const value = childResults[i]
291
+ for (let i = 0; i < subRowResults.length; i++) {
292
+ const value = subRowResults[i]
284
293
  if (isNumber(value)) count += value
285
294
  }
286
295
  return count
@@ -296,7 +305,7 @@ export const aggregationFn_first = constructAggregationFn<
296
305
  >({
297
306
  aggregate: (context) =>
298
307
  context.rows[0] ? context.getValue(context.rows[0]) : undefined,
299
- merge: ({ childResults }) => childResults[0],
308
+ merge: ({ subRowResults }) => subRowResults[0],
300
309
  })
301
310
 
302
311
  /** Returns the last row's value, including a nullish value. */
@@ -310,7 +319,7 @@ export const aggregationFn_last = constructAggregationFn<
310
319
  const row = context.rows[context.rows.length - 1]
311
320
  return row ? context.getValue(row) : undefined
312
321
  },
313
- merge: ({ childResults }) => childResults[childResults.length - 1],
322
+ merge: ({ subRowResults }) => subRowResults[subRowResults.length - 1],
314
323
  })
315
324
 
316
325
  /**
@@ -118,7 +118,7 @@ function _createGroupedRowModel<
118
118
  subRow.parentId = id
119
119
  })
120
120
 
121
- const leafRows = normalizeAggregationRows(groupedRows)
121
+ const leafRows = normalizeAggregationRows(groupedRows, Infinity)
122
122
 
123
123
  const row = constructRow(
124
124
  table,
@@ -167,10 +167,10 @@ function _createGroupedRowModel<
167
167
  const cache = ((row as any)._aggregationValuesCache ??=
168
168
  makeObjectMap())
169
169
  cache[colId] = aggregateColumnValue({
170
- childRows: subRows,
170
+ subRows,
171
171
  column,
172
172
  groupingRow: row,
173
- rows: leafRows,
173
+ rows: groupedRows,
174
174
  })
175
175
  return cache[colId]
176
176
  },