@tanstack/table-core 8.0.0-alpha.30 → 8.0.0-alpha.36

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 (122) hide show
  1. package/build/cjs/aggregationTypes.js +1 -0
  2. package/build/cjs/aggregationTypes.js.map +1 -1
  3. package/build/cjs/core.js +43 -78
  4. package/build/cjs/core.js.map +1 -1
  5. package/build/cjs/createTable.js.map +1 -1
  6. package/build/cjs/features/ColumnSizing.js.map +1 -1
  7. package/build/cjs/features/Expanding.js +12 -16
  8. package/build/cjs/features/Expanding.js.map +1 -1
  9. package/build/cjs/features/Filters.js +28 -81
  10. package/build/cjs/features/Filters.js.map +1 -1
  11. package/build/cjs/features/Grouping.js +10 -16
  12. package/build/cjs/features/Grouping.js.map +1 -1
  13. package/build/cjs/features/Headers.js.map +1 -1
  14. package/build/cjs/features/Ordering.js.map +1 -1
  15. package/build/cjs/features/Pagination.js +8 -13
  16. package/build/cjs/features/Pagination.js.map +1 -1
  17. package/build/cjs/features/Pinning.js.map +1 -1
  18. package/build/cjs/features/RowSelection.js +9 -3
  19. package/build/cjs/features/RowSelection.js.map +1 -1
  20. package/build/cjs/features/Sorting.js +10 -16
  21. package/build/cjs/features/Sorting.js.map +1 -1
  22. package/build/cjs/features/Visibility.js.map +1 -1
  23. package/build/cjs/filterTypes.js.map +1 -1
  24. package/build/cjs/index.js +19 -12
  25. package/build/cjs/index.js.map +1 -1
  26. package/build/cjs/sortTypes.js.map +1 -1
  27. package/build/cjs/utils/filterRowsUtils.js.map +1 -1
  28. package/build/cjs/utils/getColumnFilteredRowModelSync.js +115 -0
  29. package/build/cjs/utils/getColumnFilteredRowModelSync.js.map +1 -0
  30. package/build/cjs/utils/getCoreRowModelAsync.js +127 -0
  31. package/build/cjs/utils/getCoreRowModelAsync.js.map +1 -0
  32. package/build/cjs/utils/getCoreRowModelSync.js +104 -0
  33. package/build/cjs/utils/getCoreRowModelSync.js.map +1 -0
  34. package/build/cjs/utils/getExpandedRowModel.js +61 -0
  35. package/build/cjs/utils/getExpandedRowModel.js.map +1 -0
  36. package/build/cjs/utils/getGlobalFilteredRowModelSync.js +91 -0
  37. package/build/cjs/utils/getGlobalFilteredRowModelSync.js.map +1 -0
  38. package/build/cjs/utils/getGroupedRowModel.js +176 -0
  39. package/build/cjs/utils/getGroupedRowModel.js.map +1 -0
  40. package/build/cjs/utils/getPaginationRowModel.js +61 -0
  41. package/build/cjs/utils/getPaginationRowModel.js.map +1 -0
  42. package/build/cjs/utils/getSortedRowModelSync.js +118 -0
  43. package/build/cjs/utils/getSortedRowModelSync.js.map +1 -0
  44. package/build/cjs/utils.js +155 -16
  45. package/build/cjs/utils.js.map +1 -1
  46. package/build/esm/index.js +877 -488
  47. package/build/esm/index.js.map +1 -1
  48. package/build/stats-html.html +1 -1
  49. package/build/stats-react.json +408 -300
  50. package/build/types/aggregationTypes.d.ts +1 -1
  51. package/build/types/core.d.ts +9 -1
  52. package/build/types/features/Expanding.d.ts +2 -1
  53. package/build/types/features/Filters.d.ts +6 -2
  54. package/build/types/features/Grouping.d.ts +3 -2
  55. package/build/types/features/Pagination.d.ts +2 -1
  56. package/build/types/features/Sorting.d.ts +2 -1
  57. package/build/types/index.d.ts +8 -6
  58. package/build/types/types.d.ts +2 -2
  59. package/build/types/utils/getColumnFilteredRowModelAsync.d.ts +4 -0
  60. package/build/types/utils/getColumnFilteredRowModelSync.d.ts +2 -0
  61. package/build/types/utils/getCoreRowModelAsync.d.ts +4 -0
  62. package/build/types/utils/getCoreRowModelSync.d.ts +2 -0
  63. package/build/types/utils/getExpandedRowModel.d.ts +7 -0
  64. package/build/types/utils/getGlobalFilteredRowModelAsync.d.ts +4 -0
  65. package/build/types/utils/getGlobalFilteredRowModelSync.d.ts +2 -0
  66. package/build/types/utils/getGroupedRowModel.d.ts +2 -0
  67. package/build/types/utils/getPaginationRowModel.d.ts +4 -0
  68. package/build/types/utils/{sortRowsQuicksortFn.d.ts → getSortedRowModelAsync.d.ts} +3 -1
  69. package/build/types/utils/getSortedRowModelSync.d.ts +2 -0
  70. package/build/types/utils.d.ts +16 -0
  71. package/build/umd/index.development.js +887 -493
  72. package/build/umd/index.development.js.map +1 -1
  73. package/build/umd/index.production.js +1 -1
  74. package/build/umd/index.production.js.map +1 -1
  75. package/package.json +3 -1
  76. package/src/aggregationTypes.ts +1 -1
  77. package/src/core.tsx +53 -97
  78. package/src/features/Expanding.ts +19 -27
  79. package/src/features/Filters.ts +52 -99
  80. package/src/features/Grouping.ts +19 -21
  81. package/src/features/Pagination.ts +17 -20
  82. package/src/features/RowSelection.ts +5 -3
  83. package/src/features/Sorting.ts +19 -23
  84. package/src/index.tsx +8 -6
  85. package/src/types.ts +3 -1
  86. package/src/utils/getColumnFilteredRowModelAsync.ts +119 -0
  87. package/src/utils/getColumnFilteredRowModelSync.ts +99 -0
  88. package/src/utils/getCoreRowModelAsync.ts +105 -0
  89. package/src/utils/getCoreRowModelSync.ts +107 -0
  90. package/src/utils/getExpandedRowModel.ts +58 -0
  91. package/src/utils/getGlobalFilteredRowModelAsync.ts +97 -0
  92. package/src/utils/getGlobalFilteredRowModelSync.ts +76 -0
  93. package/src/utils/getGroupedRowModel.ts +191 -0
  94. package/src/utils/getPaginationRowModel.ts +45 -0
  95. package/src/utils/getSortedRowModelAsync.ts +201 -0
  96. package/src/utils/getSortedRowModelSync.ts +118 -0
  97. package/src/utils.tsx +189 -16
  98. package/build/cjs/utils/columnFilterRowsFn.js +0 -73
  99. package/build/cjs/utils/columnFilterRowsFn.js.map +0 -1
  100. package/build/cjs/utils/expandRowsFn.js +0 -37
  101. package/build/cjs/utils/expandRowsFn.js.map +0 -1
  102. package/build/cjs/utils/globalFilterRowsFn.js +0 -49
  103. package/build/cjs/utils/globalFilterRowsFn.js.map +0 -1
  104. package/build/cjs/utils/groupRowsFn.js +0 -155
  105. package/build/cjs/utils/groupRowsFn.js.map +0 -1
  106. package/build/cjs/utils/paginateRowsFn.js +0 -44
  107. package/build/cjs/utils/paginateRowsFn.js.map +0 -1
  108. package/build/cjs/utils/sortRowsFn.js +0 -94
  109. package/build/cjs/utils/sortRowsFn.js.map +0 -1
  110. package/build/types/utils/columnFilterRowsFn.d.ts +0 -2
  111. package/build/types/utils/expandRowsFn.d.ts +0 -2
  112. package/build/types/utils/globalFilterRowsFn.d.ts +0 -2
  113. package/build/types/utils/groupRowsFn.d.ts +0 -2
  114. package/build/types/utils/paginateRowsFn.d.ts +0 -2
  115. package/build/types/utils/sortRowsFn.d.ts +0 -2
  116. package/src/utils/columnFilterRowsFn.ts +0 -56
  117. package/src/utils/expandRowsFn.ts +0 -34
  118. package/src/utils/globalFilterRowsFn.ts +0 -39
  119. package/src/utils/groupRowsFn.ts +0 -174
  120. package/src/utils/paginateRowsFn.ts +0 -28
  121. package/src/utils/sortRowsFn.ts +0 -99
  122. package/src/utils/sortRowsQuicksortFn.ts +0 -174
@@ -0,0 +1,118 @@
1
+ import { TableInstance, Row, RowModel, AnyGenerics } from '../types'
2
+ import { SortingFn } from '../features/Sorting'
3
+ import { memo } from '../utils'
4
+
5
+ export function getSortedRowModelSync<TGenerics extends AnyGenerics>(): (
6
+ instance: TableInstance<TGenerics>
7
+ ) => () => RowModel<TGenerics> {
8
+ return instance =>
9
+ memo(
10
+ () => [instance.getState().sorting, instance.getGlobalFilteredRowModel()],
11
+ (sorting, rowModel) => {
12
+ if (!rowModel.rows.length || !sorting?.length) {
13
+ return rowModel
14
+ }
15
+
16
+ const sortingState = instance.getState().sorting
17
+
18
+ const sortedFlatRows: Row<TGenerics>[] = []
19
+
20
+ // Filter out sortings that correspond to non existing columns
21
+ const availableSorting = sortingState.filter(sort =>
22
+ instance.getColumnCanSort(sort.id)
23
+ )
24
+
25
+ const columnInfoById: Record<
26
+ string,
27
+ {
28
+ sortUndefined?: false | -1 | 1
29
+ invertSorting?: boolean
30
+ sortingFn: SortingFn<TGenerics>
31
+ }
32
+ > = {}
33
+
34
+ availableSorting.forEach(sortEntry => {
35
+ const column = instance.getColumn(sortEntry.id)!
36
+
37
+ columnInfoById[sortEntry.id] = {
38
+ sortUndefined: column.sortUndefined,
39
+ invertSorting: column.invertSorting,
40
+ sortingFn: instance.getColumnSortingFn(sortEntry.id)!,
41
+ }
42
+ })
43
+
44
+ const sortData = (rows: Row<TGenerics>[]) => {
45
+ // This will also perform a stable sorting using the row index
46
+ // if needed.
47
+ const sortedData = rows.slice()
48
+
49
+ sortedData.sort((rowA, rowB) => {
50
+ for (let i = 0; i < availableSorting.length; i += 1) {
51
+ const sortEntry = availableSorting[i]!
52
+ const columnInfo = columnInfoById[sortEntry.id]!
53
+ const isDesc = sortEntry?.desc ?? false
54
+
55
+ if (columnInfo.sortUndefined) {
56
+ const aValue = rowA.values[sortEntry.id]
57
+ const bValue = rowB.values[sortEntry.id]
58
+
59
+ const aUndefined = typeof aValue === 'undefined'
60
+ const bUndefined = typeof bValue === 'undefined'
61
+
62
+ if (aUndefined || bUndefined) {
63
+ return aUndefined && bUndefined
64
+ ? 0
65
+ : aUndefined
66
+ ? columnInfo.sortUndefined
67
+ : -columnInfo.sortUndefined
68
+ }
69
+ }
70
+
71
+ // This function should always return in ascending order
72
+ let sortInt = columnInfo.sortingFn(rowA, rowB, sortEntry.id)
73
+
74
+ if (sortInt !== 0) {
75
+ if (isDesc) {
76
+ sortInt *= -1
77
+ }
78
+
79
+ if (columnInfo.invertSorting) {
80
+ sortInt *= -1
81
+ }
82
+
83
+ return sortInt
84
+ }
85
+ }
86
+
87
+ return rowA.index - rowB.index
88
+ })
89
+
90
+ // If there are sub-rows, sort them
91
+ sortedData.forEach(row => {
92
+ sortedFlatRows.push(row)
93
+ if (!row.subRows || row.subRows.length <= 1) {
94
+ return
95
+ }
96
+ row.subRows = sortData(row.subRows)
97
+ })
98
+
99
+ return sortedData
100
+ }
101
+
102
+ return {
103
+ rows: sortData(rowModel.rows),
104
+ flatRows: sortedFlatRows,
105
+ rowsById: rowModel.rowsById,
106
+ }
107
+ },
108
+ {
109
+ key: 'getSortedRowModel',
110
+ debug: () => instance.options.debugAll ?? instance.options.debugTable,
111
+ onChange: () => {
112
+ instance.queue(() => {
113
+ instance._notifyGroupingReset()
114
+ })
115
+ },
116
+ }
117
+ )
118
+ }
package/src/utils.tsx CHANGED
@@ -22,6 +22,35 @@ export function noop() {
22
22
  //
23
23
  }
24
24
 
25
+ export function getBatchGroups<T>(arr: T[], count: number) {
26
+ const groups: { start: number; end: number; items: T[] }[] = [
27
+ {
28
+ start: 0,
29
+ end: count - 1,
30
+ items: [],
31
+ },
32
+ ]
33
+
34
+ let groupIndex = 0
35
+ let group = groups[groupIndex]
36
+
37
+ for (let i = 0; i < arr.length; i++) {
38
+ if (i > group.end) {
39
+ groupIndex++
40
+ groups[groupIndex] = {
41
+ start: i,
42
+ end: i + count - 1,
43
+ items: [],
44
+ }
45
+ }
46
+ group = groups[groupIndex]
47
+ const item = arr[i]
48
+ group.items.push(item)
49
+ }
50
+
51
+ return groups
52
+ }
53
+
25
54
  export function makeStateUpdater(key: keyof TableState, instance: unknown) {
26
55
  return (updater: Updater<any>) => {
27
56
  ;(instance as any).setState(<TTableState,>(old: TTableState) => {
@@ -163,19 +192,163 @@ export function memo<TDeps extends readonly any[], TResult>(
163
192
  }
164
193
  }
165
194
 
166
- // export function hashString(str: string, seed = 0): string {
167
- // let h1 = 0xdeadbeef ^ seed,
168
- // h2 = 0x41c6ce57 ^ seed
169
- // for (let i = 0, ch; i < str.length; i++) {
170
- // ch = str.charCodeAt(i)
171
- // h1 = Math.imul(h1 ^ ch, 2654435761)
172
- // h2 = Math.imul(h2 ^ ch, 1597334677)
173
- // }
174
- // h1 =
175
- // Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^
176
- // Math.imul(h2 ^ (h2 >>> 13), 3266489909)
177
- // h2 =
178
- // Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^
179
- // Math.imul(h1 ^ (h1 >>> 13), 3266489909)
180
- // return (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString()
181
- // }
195
+ type WorkFn = () => void
196
+
197
+ export function incrementalMemo<TDeps extends readonly any[], TResult>(
198
+ getDeps: () => [...TDeps],
199
+ getInitialValue: (...args: NoInfer<[...TDeps]>) => TResult,
200
+ schedule: (
201
+ ...args: NoInfer<[...TDeps]>
202
+ ) => (resultRef: {
203
+ current: TResult
204
+ }) => (scheduler: (workFn: WorkFn) => void) => void,
205
+ opts: {
206
+ key: string
207
+ onProgress: (
208
+ progress: number,
209
+ nextResult: TResult,
210
+ result?: TResult
211
+ ) => void
212
+ onChange: (result: TResult, previousResult?: TResult) => void
213
+ initialSync?: boolean
214
+ timeout?: number
215
+ debug?: () => any
216
+ }
217
+ ): () => TResult {
218
+ let oldDeps: any[]
219
+ let deps: any[]
220
+ let result: TResult | undefined
221
+ let nextResultRef: { current: TResult }
222
+ let tasks: WorkFn[] = []
223
+ let totalTaskCount = 0
224
+ let resultStartTime: number
225
+ let batchIndex = 0
226
+ let progress = 0
227
+ let working = false
228
+ let callback: ReturnType<typeof requestIdleCallback>
229
+
230
+ const timeout = opts.timeout ?? 100
231
+
232
+ const onProgress = (latestResult: TResult, previousResult?: TResult) => {
233
+ progress = 1 - tasks.length / totalTaskCount
234
+ opts.onProgress(progress, latestResult, previousResult)
235
+ }
236
+
237
+ return () => {
238
+ const scheduleFn = (workFn: WorkFn) => {
239
+ totalTaskCount++
240
+ tasks.push(workFn)
241
+ }
242
+
243
+ const newDeps = getDeps()
244
+
245
+ let first = false
246
+
247
+ if (!deps) {
248
+ first = true
249
+ deps = []
250
+ result = getInitialValue(...newDeps)
251
+ }
252
+
253
+ const depsChanged =
254
+ newDeps.length !== deps.length ||
255
+ newDeps.some((dep: any, index: number) => deps[index] !== dep)
256
+
257
+ if (depsChanged) {
258
+ cancelIdleCallback(callback)
259
+ oldDeps = deps
260
+ deps = newDeps
261
+ totalTaskCount = 0
262
+ tasks = []
263
+ nextResultRef = { current: getInitialValue(...newDeps) }
264
+ resultStartTime = Date.now()
265
+ schedule(...newDeps)(nextResultRef)(scheduleFn)
266
+ }
267
+
268
+ const commitResult = () => {
269
+ cancelIdleCallback(callback)
270
+
271
+ if (opts.key && opts.debug) {
272
+ if (opts?.debug()) {
273
+ const resultEndTime =
274
+ Math.round((Date.now() - resultStartTime!) * 100) / 100
275
+ const resultFpsPercentage = resultEndTime / batchIndex / 16
276
+
277
+ console.info(
278
+ `%c⏱ ${resultEndTime} ms / ${batchIndex} tasks = ${Math.round(
279
+ resultEndTime / batchIndex
280
+ )} ms/task`,
281
+ `
282
+ font-size: .6rem;
283
+ font-weight: bold;
284
+ color: hsl(${Math.max(
285
+ 0,
286
+ Math.min(120 - 120 * resultFpsPercentage, 120)
287
+ )}deg 100% 31%);`,
288
+ opts?.key,
289
+ {
290
+ length: `${oldDeps.length} -> ${deps.length}`,
291
+ ...deps
292
+ .map((_, index) => {
293
+ if (oldDeps[index] !== deps[index]) {
294
+ return [index, oldDeps[index], deps[index]]
295
+ }
296
+
297
+ return false
298
+ })
299
+ .filter(Boolean)
300
+ .reduce(
301
+ (accu, [a, b]: any) => ({
302
+ ...accu,
303
+ [a]: b,
304
+ }),
305
+ {}
306
+ ),
307
+ parent,
308
+ }
309
+ )
310
+ }
311
+ }
312
+
313
+ working = false
314
+ let previousResult = result
315
+ result = nextResultRef.current
316
+ onProgress(result, previousResult)
317
+ opts.onChange(result, previousResult)
318
+ }
319
+
320
+ if (opts.initialSync && first) {
321
+ batchIndex = 1
322
+ first = false
323
+ for (let i = 0; i < tasks.length; i++) {
324
+ tasks[i]()
325
+ }
326
+ tasks = []
327
+ commitResult()
328
+ } else if (!working && tasks.length) {
329
+ cancelIdleCallback(callback)
330
+ working = true
331
+ batchIndex = 0
332
+
333
+ const workLoop = (deadline: any) => {
334
+ while (tasks.length && deadline.timeRemaining() > 0) {
335
+ tasks.shift()!()
336
+ }
337
+
338
+ if (!tasks.length) {
339
+ commitResult()
340
+ } else {
341
+ ++batchIndex
342
+ onProgress(nextResultRef.current, result)
343
+ callback = requestIdleCallback(workLoop, { timeout })
344
+ }
345
+ }
346
+
347
+ callback = requestIdleCallback(workLoop, { timeout })
348
+ }
349
+
350
+ return result!
351
+ }
352
+ }
353
+
354
+ // opts?.onChange?.(result, oldResult)
@@ -1,73 +0,0 @@
1
- /**
2
- * table-core
3
- *
4
- * Copyright (c) TanStack
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE.md file in the root directory of this source tree.
8
- *
9
- * @license MIT
10
- */
11
- 'use strict';
12
-
13
- Object.defineProperty(exports, '__esModule', { value: true });
14
-
15
- var filterRowsUtils = require('./filterRowsUtils.js');
16
-
17
- function columnFilterRowsFn(instance, rowModel) {
18
- var columnFilters = instance.getState().columnFilters;
19
- var filterFromLeafRows = instance.options.filterFromLeafRows;
20
-
21
- var filterRows = function filterRows(rowsToFilter, depth) {
22
- for (var i = 0; i < columnFilters.length; i++) {
23
- var _columnFilters$i = columnFilters[i],
24
- columnId = _columnFilters$i.id,
25
- filterValue = _columnFilters$i.value; // Find the columnFilters column
26
-
27
- var column = instance.getColumn(columnId);
28
-
29
- if (!column) {
30
- if (process.env.NODE_ENV !== 'production') {
31
- console.warn("Table: Could not find a column with id: " + columnId);
32
- }
33
-
34
- throw new Error();
35
- }
36
-
37
- if (depth === 0) {
38
- (function () {
39
- var preFilteredRows = [].concat(rowsToFilter);
40
-
41
- column.getPreFilteredRows = function () {
42
- return preFilteredRows;
43
- };
44
- })();
45
- }
46
-
47
- var filterFn = instance.getColumnFilterFn(column.id);
48
-
49
- if (!filterFn) {
50
- if (process.env.NODE_ENV !== 'production') {
51
- console.warn("Could not find a valid 'column.filterType' for column with the ID: " + column.id + ".");
52
- }
53
-
54
- continue;
55
- } // Pass the rows, id, filterValue and column to the filterFn
56
- // to get the filtered rows back
57
-
58
-
59
- rowsToFilter = filterFn(rowsToFilter, [columnId], filterValue);
60
- }
61
-
62
- return rowsToFilter;
63
- };
64
-
65
- if (filterFromLeafRows) {
66
- return filterRowsUtils.filterRowModelFromLeafs(rowModel.rows, filterRows, instance);
67
- }
68
-
69
- return filterRowsUtils.filterRowModelFromRoot(rowModel.rows, filterRows, instance);
70
- }
71
-
72
- exports.columnFilterRowsFn = columnFilterRowsFn;
73
- //# sourceMappingURL=columnFilterRowsFn.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"columnFilterRowsFn.js","sources":["../../../src/utils/columnFilterRowsFn.ts"],"sourcesContent":["import { AnyGenerics, TableInstance, Row, RowModel } from '../types'\nimport {\n filterRowModelFromLeafs,\n filterRowModelFromRoot,\n} from './filterRowsUtils'\n\nexport function columnFilterRowsFn<TGenerics extends AnyGenerics>(\n instance: TableInstance<TGenerics>,\n rowModel: RowModel<TGenerics>\n): RowModel<TGenerics> {\n const columnFilters = instance.getState().columnFilters\n const filterFromLeafRows = instance.options.filterFromLeafRows\n\n const filterRows = (rowsToFilter: Row<TGenerics>[], depth: number) => {\n for (let i = 0; i < columnFilters.length; i++) {\n const { id: columnId, value: filterValue } = columnFilters[i]\n // Find the columnFilters column\n const column = instance.getColumn(columnId)\n\n if (!column) {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(`Table: Could not find a column with id: ${columnId}`)\n }\n throw new Error()\n }\n\n if (depth === 0) {\n const preFilteredRows = [...rowsToFilter]\n column.getPreFilteredRows = () => preFilteredRows\n }\n\n const filterFn = instance.getColumnFilterFn(column.id)\n\n if (!filterFn) {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(\n `Could not find a valid 'column.filterType' for column with the ID: ${column.id}.`\n )\n }\n continue\n }\n\n // Pass the rows, id, filterValue and column to the filterFn\n // to get the filtered rows back\n rowsToFilter = filterFn(rowsToFilter, [columnId], filterValue)\n }\n\n return rowsToFilter\n }\n\n if (filterFromLeafRows) {\n return filterRowModelFromLeafs(rowModel.rows, filterRows, instance)\n }\n\n return filterRowModelFromRoot(rowModel.rows, filterRows, instance)\n}\n"],"names":["columnFilterRowsFn","instance","rowModel","columnFilters","getState","filterFromLeafRows","options","filterRows","rowsToFilter","depth","i","length","columnId","id","filterValue","value","column","getColumn","process","env","NODE_ENV","console","warn","Error","preFilteredRows","getPreFilteredRows","filterFn","getColumnFilterFn","filterRowModelFromLeafs","rows","filterRowModelFromRoot"],"mappings":";;;;;;;;;;;;;;;;AAMO,SAASA,kBAAT,CACLC,QADK,EAELC,QAFK,EAGgB;AACrB,MAAMC,aAAa,GAAGF,QAAQ,CAACG,QAAT,GAAoBD,aAA1C;AACA,MAAME,kBAAkB,GAAGJ,QAAQ,CAACK,OAAT,CAAiBD,kBAA5C;;AAEA,MAAME,UAAU,GAAG,SAAbA,UAAa,CAACC,YAAD,EAAiCC,KAAjC,EAAmD;AACpE,SAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGP,aAAa,CAACQ,MAAlC,EAA0CD,CAAC,EAA3C,EAA+C;AAC7C,6BAA6CP,aAAa,CAACO,CAAD,CAA1D;AAAA,UAAYE,QAAZ,oBAAQC,EAAR;AAAA,UAA6BC,WAA7B,oBAAsBC,KAAtB,CAD6C;;AAG7C,UAAMC,MAAM,GAAGf,QAAQ,CAACgB,SAAT,CAAmBL,QAAnB,CAAf;;AAEA,UAAI,CAACI,MAAL,EAAa;AACX,YAAIE,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzCC,UAAAA,OAAO,CAACC,IAAR,8CAAwDV,QAAxD;AACD;;AACD,cAAM,IAAIW,KAAJ,EAAN;AACD;;AAED,UAAId,KAAK,KAAK,CAAd,EAAiB;AAAA;AACf,cAAMe,eAAe,aAAOhB,YAAP,CAArB;;AACAQ,UAAAA,MAAM,CAACS,kBAAP,GAA4B;AAAA,mBAAMD,eAAN;AAAA,WAA5B;AAFe;AAGhB;;AAED,UAAME,QAAQ,GAAGzB,QAAQ,CAAC0B,iBAAT,CAA2BX,MAAM,CAACH,EAAlC,CAAjB;;AAEA,UAAI,CAACa,QAAL,EAAe;AACb,YAAIR,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzCC,UAAAA,OAAO,CAACC,IAAR,yEACwEN,MAAM,CAACH,EAD/E;AAGD;;AACD;AACD,OA1B4C;AA6B7C;;;AACAL,MAAAA,YAAY,GAAGkB,QAAQ,CAAClB,YAAD,EAAe,CAACI,QAAD,CAAf,EAA2BE,WAA3B,CAAvB;AACD;;AAED,WAAON,YAAP;AACD,GAnCD;;AAqCA,MAAIH,kBAAJ,EAAwB;AACtB,WAAOuB,uCAAuB,CAAC1B,QAAQ,CAAC2B,IAAV,EAAgBtB,UAAhB,EAA4BN,QAA5B,CAA9B;AACD;;AAED,SAAO6B,sCAAsB,CAAC5B,QAAQ,CAAC2B,IAAV,EAAgBtB,UAAhB,EAA4BN,QAA5B,CAA7B;AACD;;;;"}
@@ -1,37 +0,0 @@
1
- /**
2
- * table-core
3
- *
4
- * Copyright (c) TanStack
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE.md file in the root directory of this source tree.
8
- *
9
- * @license MIT
10
- */
11
- 'use strict';
12
-
13
- Object.defineProperty(exports, '__esModule', { value: true });
14
-
15
- function expandRowsFn(instance, sortedRowModel) {
16
- var expandedRows = [];
17
-
18
- var handleRow = function handleRow(row) {
19
- var _row$subRows;
20
-
21
- expandedRows.push(row);
22
-
23
- if (instance.options.expandSubRows && (_row$subRows = row.subRows) != null && _row$subRows.length && instance.getIsRowExpanded(row.id)) {
24
- row.subRows.forEach(handleRow);
25
- }
26
- };
27
-
28
- sortedRowModel.rows.forEach(handleRow);
29
- return {
30
- rows: expandedRows,
31
- flatRows: sortedRowModel.flatRows,
32
- rowsById: sortedRowModel.rowsById
33
- };
34
- }
35
-
36
- exports.expandRowsFn = expandRowsFn;
37
- //# sourceMappingURL=expandRowsFn.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"expandRowsFn.js","sources":["../../../src/utils/expandRowsFn.ts"],"sourcesContent":["import {\n TableInstance,\n Row,\n RowModel,\n AnyGenerics,\n PartialGenerics,\n} from '../types'\n\nexport function expandRowsFn<TGenerics extends AnyGenerics>(\n instance: TableInstance<TGenerics>,\n sortedRowModel: RowModel<TGenerics>\n): RowModel<TGenerics> {\n const expandedRows: Row<TGenerics>[] = []\n\n const handleRow = (row: Row<TGenerics>) => {\n expandedRows.push(row)\n\n if (\n instance.options.expandSubRows &&\n row.subRows?.length &&\n instance.getIsRowExpanded(row.id)\n ) {\n row.subRows.forEach(handleRow)\n }\n }\n\n sortedRowModel.rows.forEach(handleRow)\n\n return {\n rows: expandedRows,\n flatRows: sortedRowModel.flatRows,\n rowsById: sortedRowModel.rowsById,\n }\n}\n"],"names":["expandRowsFn","instance","sortedRowModel","expandedRows","handleRow","row","push","options","expandSubRows","subRows","length","getIsRowExpanded","id","forEach","rows","flatRows","rowsById"],"mappings":";;;;;;;;;;;;;;AAQO,SAASA,YAAT,CACLC,QADK,EAELC,cAFK,EAGgB;AACrB,MAAMC,YAA8B,GAAG,EAAvC;;AAEA,MAAMC,SAAS,GAAG,SAAZA,SAAY,CAACC,GAAD,EAAyB;AAAA;;AACzCF,IAAAA,YAAY,CAACG,IAAb,CAAkBD,GAAlB;;AAEA,QACEJ,QAAQ,CAACM,OAAT,CAAiBC,aAAjB,oBACAH,GAAG,CAACI,OADJ,aACA,aAAaC,MADb,IAEAT,QAAQ,CAACU,gBAAT,CAA0BN,GAAG,CAACO,EAA9B,CAHF,EAIE;AACAP,MAAAA,GAAG,CAACI,OAAJ,CAAYI,OAAZ,CAAoBT,SAApB;AACD;AACF,GAVD;;AAYAF,EAAAA,cAAc,CAACY,IAAf,CAAoBD,OAApB,CAA4BT,SAA5B;AAEA,SAAO;AACLU,IAAAA,IAAI,EAAEX,YADD;AAELY,IAAAA,QAAQ,EAAEb,cAAc,CAACa,QAFpB;AAGLC,IAAAA,QAAQ,EAAEd,cAAc,CAACc;AAHpB,GAAP;AAKD;;;;"}
@@ -1,49 +0,0 @@
1
- /**
2
- * table-core
3
- *
4
- * Copyright (c) TanStack
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE.md file in the root directory of this source tree.
8
- *
9
- * @license MIT
10
- */
11
- 'use strict';
12
-
13
- Object.defineProperty(exports, '__esModule', { value: true });
14
-
15
- var filterRowsUtils = require('./filterRowsUtils.js');
16
-
17
- function globalFilterRowsFn(instance, rowModel) {
18
- var globalFilter = instance.getState().globalFilter;
19
- var filterFromLeafRows = instance.options.filterFromLeafRows;
20
- var filterFn = instance.getGlobalFilterFn();
21
-
22
- if (!filterFn) {
23
- if (process.env.NODE_ENV !== 'production') {
24
- console.warn("Could not find a valid 'globalFilterType'");
25
- }
26
-
27
- return rowModel;
28
- }
29
-
30
- var filterableColumns = instance.getAllLeafColumns().filter(function (column) {
31
- return column.getCanGlobalFilter();
32
- });
33
- var filterableColumnIds = filterableColumns.map(function (d) {
34
- return d.id;
35
- });
36
-
37
- var filterRows = function filterRows(rows) {
38
- return filterFn(rows, filterableColumnIds, globalFilter);
39
- };
40
-
41
- if (filterFromLeafRows) {
42
- filterRowsUtils.filterRowModelFromLeafs(rowModel.rows, filterRows, instance);
43
- }
44
-
45
- return filterRowsUtils.filterRowModelFromRoot(rowModel.rows, filterRows, instance);
46
- }
47
-
48
- exports.globalFilterRowsFn = globalFilterRowsFn;
49
- //# sourceMappingURL=globalFilterRowsFn.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"globalFilterRowsFn.js","sources":["../../../src/utils/globalFilterRowsFn.ts"],"sourcesContent":["import { TableInstance, Row, RowModel, AnyGenerics } from '../types'\nimport {\n filterRowModelFromLeafs,\n filterRowModelFromRoot,\n} from './filterRowsUtils'\n\nexport function globalFilterRowsFn<TGenerics extends AnyGenerics>(\n instance: TableInstance<TGenerics>,\n rowModel: RowModel<TGenerics>\n): RowModel<TGenerics> {\n const globalFilter = instance.getState().globalFilter\n\n const filterFromLeafRows = instance.options.filterFromLeafRows\n\n const filterFn = instance.getGlobalFilterFn()\n\n if (!filterFn) {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(`Could not find a valid 'globalFilterType'`)\n }\n return rowModel\n }\n\n const filterableColumns = instance\n .getAllLeafColumns()\n .filter(column => column.getCanGlobalFilter())\n\n const filterableColumnIds = filterableColumns.map(d => d.id)\n\n const filterRows = (rows: Row<TGenerics>[]) => {\n return filterFn(rows, filterableColumnIds, globalFilter)\n }\n\n if (filterFromLeafRows) {\n filterRowModelFromLeafs(rowModel.rows, filterRows, instance)\n }\n\n return filterRowModelFromRoot(rowModel.rows, filterRows, instance)\n}\n"],"names":["globalFilterRowsFn","instance","rowModel","globalFilter","getState","filterFromLeafRows","options","filterFn","getGlobalFilterFn","process","env","NODE_ENV","console","warn","filterableColumns","getAllLeafColumns","filter","column","getCanGlobalFilter","filterableColumnIds","map","d","id","filterRows","rows","filterRowModelFromLeafs","filterRowModelFromRoot"],"mappings":";;;;;;;;;;;;;;;;AAMO,SAASA,kBAAT,CACLC,QADK,EAELC,QAFK,EAGgB;AACrB,MAAMC,YAAY,GAAGF,QAAQ,CAACG,QAAT,GAAoBD,YAAzC;AAEA,MAAME,kBAAkB,GAAGJ,QAAQ,CAACK,OAAT,CAAiBD,kBAA5C;AAEA,MAAME,QAAQ,GAAGN,QAAQ,CAACO,iBAAT,EAAjB;;AAEA,MAAI,CAACD,QAAL,EAAe;AACb,QAAIE,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzCC,MAAAA,OAAO,CAACC,IAAR;AACD;;AACD,WAAOX,QAAP;AACD;;AAED,MAAMY,iBAAiB,GAAGb,QAAQ,CAC/Bc,iBADuB,GAEvBC,MAFuB,CAEhB,UAAAC,MAAM;AAAA,WAAIA,MAAM,CAACC,kBAAP,EAAJ;AAAA,GAFU,CAA1B;AAIA,MAAMC,mBAAmB,GAAGL,iBAAiB,CAACM,GAAlB,CAAsB,UAAAC,CAAC;AAAA,WAAIA,CAAC,CAACC,EAAN;AAAA,GAAvB,CAA5B;;AAEA,MAAMC,UAAU,GAAG,SAAbA,UAAa,CAACC,IAAD,EAA4B;AAC7C,WAAOjB,QAAQ,CAACiB,IAAD,EAAOL,mBAAP,EAA4BhB,YAA5B,CAAf;AACD,GAFD;;AAIA,MAAIE,kBAAJ,EAAwB;AACtBoB,IAAAA,uCAAuB,CAACvB,QAAQ,CAACsB,IAAV,EAAgBD,UAAhB,EAA4BtB,QAA5B,CAAvB;AACD;;AAED,SAAOyB,sCAAsB,CAACxB,QAAQ,CAACsB,IAAV,EAAgBD,UAAhB,EAA4BtB,QAA5B,CAA7B;AACD;;;;"}
@@ -1,155 +0,0 @@
1
- /**
2
- * table-core
3
- *
4
- * Copyright (c) TanStack
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE.md file in the root directory of this source tree.
8
- *
9
- * @license MIT
10
- */
11
- 'use strict';
12
-
13
- Object.defineProperty(exports, '__esModule', { value: true });
14
-
15
- var utils = require('../utils.js');
16
-
17
- function groupRowsFn(instance, sortedRowModel) {
18
- var groupingState = instance.getState().grouping; // Filter the grouping list down to columns that exist
19
-
20
- var existingGrouping = groupingState.filter(function (columnId) {
21
- return instance.getColumn(columnId);
22
- }); // Find the columns that can or are aggregating
23
- // Uses each column to aggregate rows into a single value
24
-
25
- var aggregateRowsToValues = function aggregateRowsToValues(leafRows, groupedRows, depth) {
26
- var values = {};
27
- instance.getAllLeafColumns().forEach(function (column) {
28
- // Don't aggregate columns that are in the grouping
29
- if (existingGrouping.includes(column.id)) {
30
- values[column.id] = groupedRows[0] ? groupedRows[0].values[column.id] : null;
31
- return;
32
- } // Aggregate the values
33
-
34
-
35
- var aggregateFn = instance.getColumnAggregationFn(column.id);
36
-
37
- if (aggregateFn) {
38
- values[column.id] = aggregateFn(function () {
39
- return leafRows.map(function (row) {
40
- var columnValue = row.values[column.id];
41
-
42
- if (!depth && column.aggregateValue) {
43
- columnValue = column.aggregateValue(columnValue);
44
- }
45
-
46
- return columnValue;
47
- });
48
- }, function () {
49
- return groupedRows.map(function (row) {
50
- return row.values[column.id];
51
- });
52
- });
53
- } else if (column.aggregationType) {
54
- console.info({
55
- column: column
56
- });
57
- throw new Error(process.env.NODE_ENV !== 'production' ? "Table: Invalid column.aggregateType option for column listed above" : '');
58
- } else {
59
- values[column.id] = null;
60
- }
61
- });
62
- return values;
63
- };
64
-
65
- var groupedFlatRows = [];
66
- var groupedRowsById = {}; // const onlyGroupedFlatRows: Row[] = [];
67
- // const onlyGroupedRowsById: Record<RowId, Row> = {};
68
- // const nonGroupedFlatRows: Row[] = [];
69
- // const nonGroupedRowsById: Record<RowId, Row> = {};
70
- // Recursively group the data
71
-
72
- var groupUpRecursively = function groupUpRecursively(rows, depth, parentId) {
73
- if (depth === void 0) {
74
- depth = 0;
75
- }
76
-
77
- // This is the last level, just return the rows
78
- if (depth === existingGrouping.length) {
79
- return rows;
80
- }
81
-
82
- var columnId = existingGrouping[depth]; // Group the rows together for this level
83
-
84
- var rowGroupsMap = groupBy(rows, columnId); // Peform aggregations for each group
85
-
86
- var aggregatedGroupedRows = Array.from(rowGroupsMap.entries()).map(function (_ref, index) {
87
- var groupingValue = _ref[0],
88
- groupedRows = _ref[1];
89
- var id = columnId + ":" + groupingValue;
90
- id = parentId ? parentId + ">" + id : id; // First, Recurse to group sub rows before aggregation
91
-
92
- var subRows = groupUpRecursively(groupedRows, depth + 1, id); // Flatten the leaf rows of the rows in this group
93
-
94
- var leafRows = depth ? utils.flattenBy(groupedRows, function (row) {
95
- return row.subRows;
96
- }) : groupedRows;
97
- var values = aggregateRowsToValues(leafRows, groupedRows, depth);
98
- var row = instance.createRow(id, undefined, index, depth, values);
99
- Object.assign(row, {
100
- groupingColumnId: columnId,
101
- groupingValue: groupingValue,
102
- subRows: subRows,
103
- leafRows: leafRows
104
- });
105
- subRows.forEach(function (subRow) {
106
- groupedFlatRows.push(subRow);
107
- groupedRowsById[subRow.id] = subRow; // if (subRow.getIsGrouped?.()) {
108
- // onlyGroupedFlatRows.push(subRow);
109
- // onlyGroupedRowsById[subRow.id] = subRow;
110
- // } else {
111
- // nonGroupedFlatRows.push(subRow);
112
- // nonGroupedRowsById[subRow.id] = subRow;
113
- // }
114
- });
115
- return row;
116
- });
117
- return aggregatedGroupedRows;
118
- };
119
-
120
- var groupedRows = groupUpRecursively(sortedRowModel.rows, 0, '');
121
- groupedRows.forEach(function (subRow) {
122
- groupedFlatRows.push(subRow);
123
- groupedRowsById[subRow.id] = subRow; // if (subRow.getIsGrouped?.()) {
124
- // onlyGroupedFlatRows.push(subRow);
125
- // onlyGroupedRowsById[subRow.id] = subRow;
126
- // } else {
127
- // nonGroupedFlatRows.push(subRow);
128
- // nonGroupedRowsById[subRow.id] = subRow;
129
- // }
130
- });
131
- return {
132
- rows: groupedRows,
133
- flatRows: groupedFlatRows,
134
- rowsById: groupedRowsById
135
- };
136
- }
137
-
138
- function groupBy(rows, columnId) {
139
- var groupMap = new Map();
140
- return rows.reduce(function (map, row) {
141
- var resKey = "" + row.values[columnId];
142
- var previous = map.get(resKey);
143
-
144
- if (!previous) {
145
- map.set(resKey, [row]);
146
- } else {
147
- map.set(resKey, [].concat(previous, [row]));
148
- }
149
-
150
- return map;
151
- }, groupMap);
152
- }
153
-
154
- exports.groupRowsFn = groupRowsFn;
155
- //# sourceMappingURL=groupRowsFn.js.map