@tanstack/table-core 8.0.0-alpha.67 → 8.0.0-alpha.68

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 (126) hide show
  1. package/build/cjs/aggregationFns.js +25 -37
  2. package/build/cjs/aggregationFns.js.map +1 -1
  3. package/build/cjs/core.js +167 -46
  4. package/build/cjs/core.js.map +1 -1
  5. package/build/cjs/createTable.js +24 -40
  6. package/build/cjs/createTable.js.map +1 -1
  7. package/build/cjs/features/Cells.js +28 -34
  8. package/build/cjs/features/Cells.js.map +1 -1
  9. package/build/cjs/features/ColumnSizing.js +90 -107
  10. package/build/cjs/features/ColumnSizing.js.map +1 -1
  11. package/build/cjs/features/Columns.js +52 -79
  12. package/build/cjs/features/Columns.js.map +1 -1
  13. package/build/cjs/features/Expanding.js +48 -57
  14. package/build/cjs/features/Expanding.js.map +1 -1
  15. package/build/cjs/features/Filters.js +96 -191
  16. package/build/cjs/features/Filters.js.map +1 -1
  17. package/build/cjs/features/Grouping.js +52 -70
  18. package/build/cjs/features/Grouping.js.map +1 -1
  19. package/build/cjs/features/Headers.js +109 -165
  20. package/build/cjs/features/Headers.js.map +1 -1
  21. package/build/cjs/features/Ordering.js +30 -42
  22. package/build/cjs/features/Ordering.js.map +1 -1
  23. package/build/cjs/features/Pagination.js +63 -71
  24. package/build/cjs/features/Pagination.js.map +1 -1
  25. package/build/cjs/features/Pinning.js +65 -121
  26. package/build/cjs/features/Pinning.js.map +1 -1
  27. package/build/cjs/features/RowSelection.js +92 -111
  28. package/build/cjs/features/RowSelection.js.map +1 -1
  29. package/build/cjs/features/Rows.js +32 -22
  30. package/build/cjs/features/Rows.js.map +1 -1
  31. package/build/cjs/features/Sorting.js +49 -68
  32. package/build/cjs/features/Sorting.js.map +1 -1
  33. package/build/cjs/features/Visibility.js +43 -87
  34. package/build/cjs/features/Visibility.js.map +1 -1
  35. package/build/cjs/filterFns.js +48 -72
  36. package/build/cjs/filterFns.js.map +1 -1
  37. package/build/cjs/index.js +13 -13
  38. package/build/cjs/sortingFns.js +21 -21
  39. package/build/cjs/sortingFns.js.map +1 -1
  40. package/build/cjs/utils/filterRowsUtils.js +49 -55
  41. package/build/cjs/utils/filterRowsUtils.js.map +1 -1
  42. package/build/cjs/utils/getCoreRowModel.js +98 -0
  43. package/build/cjs/utils/getCoreRowModel.js.map +1 -0
  44. package/build/cjs/utils/getExpandedRowModel.js +17 -21
  45. package/build/cjs/utils/getExpandedRowModel.js.map +1 -1
  46. package/build/cjs/utils/getFacetedMinMaxValues.js +48 -0
  47. package/build/cjs/utils/getFacetedMinMaxValues.js.map +1 -0
  48. package/build/cjs/utils/getFacetedRowModel.js +50 -0
  49. package/build/cjs/utils/getFacetedRowModel.js.map +1 -0
  50. package/build/cjs/utils/getFacetedUniqueValues.js +48 -0
  51. package/build/cjs/utils/getFacetedUniqueValues.js.map +1 -0
  52. package/build/cjs/utils/getFilteredRowModel.js +130 -0
  53. package/build/cjs/utils/getFilteredRowModel.js.map +1 -0
  54. package/build/cjs/utils/getGroupedRowModel.js +126 -136
  55. package/build/cjs/utils/getGroupedRowModel.js.map +1 -1
  56. package/build/cjs/utils/getPaginationRowModel.js +39 -39
  57. package/build/cjs/utils/getPaginationRowModel.js.map +1 -1
  58. package/build/cjs/utils/getSortedRowModel.js +112 -0
  59. package/build/cjs/utils/getSortedRowModel.js.map +1 -0
  60. package/build/cjs/utils.js +36 -207
  61. package/build/cjs/utils.js.map +1 -1
  62. package/build/esm/index.js +1729 -2313
  63. package/build/esm/index.js.map +1 -1
  64. package/build/stats-html.html +1 -1
  65. package/build/stats-react.json +421 -481
  66. package/build/types/core.d.ts +3 -5
  67. package/build/types/features/Cells.d.ts +1 -1
  68. package/build/types/features/Columns.d.ts +1 -1
  69. package/build/types/features/Filters.d.ts +10 -5
  70. package/build/types/features/Grouping.d.ts +4 -3
  71. package/build/types/features/Rows.d.ts +4 -3
  72. package/build/types/index.d.ts +6 -4
  73. package/build/types/types.d.ts +3 -13
  74. package/build/types/utils/filterRowsUtils.d.ts +3 -3
  75. package/build/types/utils/getCoreRowModel.d.ts +2 -0
  76. package/build/types/utils/getFacetedMinMaxValues.d.ts +2 -0
  77. package/build/types/utils/getFacetedRowModel.d.ts +2 -0
  78. package/build/types/utils/getFacetedUniqueValues.d.ts +2 -0
  79. package/build/types/utils/{getCoreRowModelSync.d.ts → getFilteredRowModel.d.ts} +1 -1
  80. package/build/types/utils/getGroupedRowModel.d.ts +1 -1
  81. package/build/types/utils/getSortedRowModel.d.ts +2 -0
  82. package/build/types/utils.d.ts +1 -17
  83. package/build/umd/index.development.js +1730 -2316
  84. package/build/umd/index.development.js.map +1 -1
  85. package/build/umd/index.production.js +1 -1
  86. package/build/umd/index.production.js.map +1 -1
  87. package/package.json +1 -1
  88. package/src/core.ts +197 -45
  89. package/src/features/Cells.ts +7 -11
  90. package/src/features/ColumnSizing.ts +6 -5
  91. package/src/features/Columns.ts +4 -8
  92. package/src/features/Filters.ts +95 -156
  93. package/src/features/Grouping.ts +16 -20
  94. package/src/features/Rows.ts +21 -6
  95. package/src/features/Sorting.ts +2 -2
  96. package/src/filterFns.ts +9 -9
  97. package/src/index.ts +12 -4
  98. package/src/sortingFns.ts +11 -11
  99. package/src/types.ts +3 -16
  100. package/src/utils/filterRowsUtils.ts +47 -68
  101. package/src/utils/{getCoreRowModelSync.ts → getCoreRowModel.ts} +2 -8
  102. package/src/utils/getFacetedMinMaxValues.ts +37 -0
  103. package/src/utils/getFacetedRowModel.ts +50 -0
  104. package/src/utils/getFacetedUniqueValues.ts +37 -0
  105. package/src/utils/{getFilteredRowModelSync.ts → getFilteredRowModel.ts} +29 -20
  106. package/src/utils/getGroupedRowModel.ts +52 -61
  107. package/src/utils/{getSortedRowModelSync.ts → getSortedRowModel.ts} +3 -3
  108. package/src/utils.ts +28 -236
  109. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -112
  110. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
  111. package/build/cjs/utils/getCoreRowModelAsync.js +0 -125
  112. package/build/cjs/utils/getCoreRowModelAsync.js.map +0 -1
  113. package/build/cjs/utils/getCoreRowModelSync.js +0 -102
  114. package/build/cjs/utils/getCoreRowModelSync.js.map +0 -1
  115. package/build/cjs/utils/getFilteredRowModelSync.js +0 -125
  116. package/build/cjs/utils/getFilteredRowModelSync.js.map +0 -1
  117. package/build/cjs/utils/getSortedRowModelSync.js +0 -118
  118. package/build/cjs/utils/getSortedRowModelSync.js.map +0 -1
  119. package/build/types/utils/getCoreRowModelAsync.d.ts +0 -4
  120. package/build/types/utils/getFilteredRowModelAsync.d.ts +0 -4
  121. package/build/types/utils/getFilteredRowModelSync.d.ts +0 -2
  122. package/build/types/utils/getSortedRowModelAsync.d.ts +0 -13
  123. package/build/types/utils/getSortedRowModelSync.d.ts +0 -2
  124. package/src/utils/getCoreRowModelAsync.ts +0 -104
  125. package/src/utils/getFilteredRowModelAsync.ts +0 -157
  126. package/src/utils/getSortedRowModelAsync.ts +0 -200
@@ -1,200 +0,0 @@
1
- import { TableInstance, Row, RowModel, TableGenerics } from '../types'
2
- import { incrementalMemo, memo } from '../utils'
3
-
4
- export function getSortedRowModelSync<TGenerics extends TableGenerics>(opts?: {
5
- initialSync?: boolean
6
- }): (instance: TableInstance<TGenerics>) => () => RowModel<TGenerics> {
7
- return instance =>
8
- incrementalMemo(
9
- () => [instance.getState().sorting, instance.getPreSortedRowModel()],
10
- (_sorting, rowModel): RowModel<TGenerics> => {
11
- return {
12
- rows: rowModel.rows.slice(),
13
- flatRows: [],
14
- rowsById: rowModel.rowsById,
15
- }
16
- },
17
- (sorting, rowModel) => rowModelRef => scheduleTask => {
18
- // TODO: Figure out how to do async sorting
19
- // We probably need to use a sorting algo that is "divide and
20
- // conquer", since that will probably distribute the easiest into
21
- // separate tasks. The trick will be batching those tasks in a way
22
- // that makes them fast. JS work loops don't tend to do well with
23
- // a high number of tasks that do one thing. Instead, shoot for each
24
- // task to have a few thousand opts (or whatever amount is generally
25
- // fast for most devices).
26
-
27
- throw new Error()
28
-
29
- // if (!rowModel.rows.length || !sorting?.length) {
30
- // rowModelRef.current = rowModel
31
- // return
32
- // }
33
-
34
- // const sortingState = instance.getState().sorting
35
-
36
- // const sortedFlatRows: Row<TGenerics>[] = []
37
-
38
- // // Filter out sortings that correspond to non existing columns
39
- // const availableSorting = sortingState.filter(sort =>
40
- // instance.getColumnCanSort(sort.id)
41
- // )
42
-
43
- // const sorters = availableSorting.map(columnSorting => {
44
- // const column = instance.getColumn(columnSorting.id)!
45
- // const sortingFn = instance.getColumnSortingFn(columnSorting.id)!
46
-
47
- // return {
48
- // id: columnSorting.id,
49
- // compare: (rowA: Row<TGenerics>, rowB: Row<TGenerics>) =>
50
- // sortingFn(rowA, rowB, columnSorting.id),
51
- // desc: columnSorting.desc,
52
- // invertSorting: column.invertSorting,
53
- // sortUndefined: column.sortUndefined,
54
- // }
55
- // })
56
-
57
- // const sortData = (rows: Row<TGenerics>[]) => {
58
- // // This will also perform a stable sorting using the row index
59
- // // if needed.
60
-
61
- // const sortedData = quicksort(rows, sorters)
62
-
63
- // // If there are sub-rows, sort them
64
- // sortedData.forEach(row => {
65
- // rowModelRef.current.flatRows.push(row)
66
- // if (!row.subRows || row.subRows.length <= 1) {
67
- // return
68
- // }
69
- // row.subRows = sortData(row.subRows)
70
- // })
71
-
72
- // return sortedData
73
- // }
74
-
75
- // sortData(rowModelRef.current.rows)
76
- },
77
- {
78
- key: process.env.NODE_ENV === 'development' && 'getSortedRowModel',
79
- initialSync: opts?.initialSync,
80
- onProgress: progress => {
81
- instance.setState(old => ({ ...old, sortingProgress: progress }))
82
- },
83
- debug: () => instance.options.debugAll ?? instance.options.debugTable,
84
- onChange: () => {
85
- instance.queue(() => {
86
- instance._autoResetPageIndex()
87
- })
88
- },
89
- }
90
- )
91
- }
92
-
93
- type Sorter<TGenerics extends TableGenerics> = {
94
- id: string
95
- compare: (a: Row<TGenerics>, b: Row<TGenerics>) => number
96
- desc?: boolean
97
- sortUndefined?: false | -1 | 1
98
- invertSorting?: boolean
99
- }
100
-
101
- export function quicksort<TGenerics extends TableGenerics>(
102
- rows: Row<TGenerics>[],
103
- sorters: Sorter<TGenerics>[]
104
- ): Row<TGenerics>[] {
105
- if (!rows.length) {
106
- return rows
107
- }
108
-
109
- // Copy the rows so we can mutate the order
110
- rows = rows.slice()
111
-
112
- // Start the quicksort recursion
113
- recurse(0, rows.length - 1)
114
-
115
- // Return the rows
116
- return rows
117
-
118
- function recurse(start: number, end: number) {
119
- const pivotIndex = pivot(start, end)
120
-
121
- if (start < pivotIndex - 1) {
122
- recurse(start, pivotIndex - 1)
123
- }
124
-
125
- if (pivotIndex < end) {
126
- recurse(pivotIndex + 1, end)
127
- }
128
- }
129
-
130
- function pivot(start: number, end: number) {
131
- const pivotIndex = Math.floor((start + end) / 2)
132
- let i = start
133
- let j = end
134
-
135
- const compare = (a: number, b: number) => {
136
- const rowA = rows[a]
137
- const rowB = rows[b]
138
-
139
- for (let i = 0; i < sorters.length; i += 1) {
140
- const sorter = sorters[i]!
141
- const isDesc = sorter?.desc ?? false
142
-
143
- if (sorter.sortUndefined) {
144
- const aValue = rowA.values[sorter.id]
145
- const bValue = rowB.values[sorter.id]
146
-
147
- const aUndefined = typeof aValue === 'undefined'
148
- const bUndefined = typeof bValue === 'undefined'
149
-
150
- if (aUndefined || bUndefined) {
151
- if (aUndefined !== bUndefined) {
152
- return aUndefined ? sorter.sortUndefined : -sorter.sortUndefined
153
- }
154
- }
155
- }
156
-
157
- // This function should always return in ascending order
158
- let sortInt = sorter.compare(rowA, rowB)
159
-
160
- if (sortInt !== 0) {
161
- if (isDesc) {
162
- sortInt *= -1
163
- }
164
-
165
- if (sorter.invertSorting) {
166
- sortInt *= -1
167
- }
168
-
169
- return sortInt
170
- }
171
- }
172
-
173
- return rowA.index < rowB.index ? -1 : 1
174
- }
175
-
176
- while (i <= j) {
177
- while (compare(i, pivotIndex) < 0) {
178
- i++
179
- }
180
-
181
- while (compare(pivotIndex, j) < 0) {
182
- j--
183
- }
184
-
185
- if (i <= j) {
186
- swap(rows, i, j)
187
- i++
188
- j--
189
- }
190
- }
191
-
192
- return i
193
- }
194
-
195
- function swap<T>(arr: T[], a: number, b: number) {
196
- const t = arr[a]
197
- arr[a] = arr[b]
198
- arr[b] = t
199
- }
200
- }