@tanstack/table-core 8.0.0-alpha.32 → 8.0.0-alpha.37

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 (37) hide show
  1. package/build/cjs/core.js +21 -0
  2. package/build/cjs/core.js.map +1 -1
  3. package/build/cjs/features/RowSelection.js +9 -3
  4. package/build/cjs/features/RowSelection.js.map +1 -1
  5. package/build/cjs/utils/getColumnFilteredRowModelSync.js +3 -1
  6. package/build/cjs/utils/getColumnFilteredRowModelSync.js.map +1 -1
  7. package/build/cjs/utils/getCoreRowModelAsync.js +4 -2
  8. package/build/cjs/utils/getCoreRowModelAsync.js.map +1 -1
  9. package/build/cjs/utils/getCoreRowModelSync.js +4 -2
  10. package/build/cjs/utils/getCoreRowModelSync.js.map +1 -1
  11. package/build/cjs/utils/getGlobalFilteredRowModelSync.js +4 -2
  12. package/build/cjs/utils/getGlobalFilteredRowModelSync.js.map +1 -1
  13. package/build/cjs/utils/getGroupedRowModel.js +3 -1
  14. package/build/cjs/utils/getGroupedRowModel.js.map +1 -1
  15. package/build/cjs/utils/getSortedRowModelSync.js +3 -1
  16. package/build/cjs/utils/getSortedRowModelSync.js.map +1 -1
  17. package/build/esm/index.js +51 -12
  18. package/build/esm/index.js.map +1 -1
  19. package/build/stats-html.html +1 -1
  20. package/build/stats-react.json +305 -305
  21. package/build/types/core.d.ts +2 -0
  22. package/build/umd/index.development.js +51 -12
  23. package/build/umd/index.development.js.map +1 -1
  24. package/build/umd/index.production.js +1 -1
  25. package/build/umd/index.production.js.map +1 -1
  26. package/package.json +3 -1
  27. package/src/core.tsx +20 -0
  28. package/src/features/RowSelection.ts +5 -3
  29. package/src/utils/getColumnFilteredRowModelAsync.ts +3 -1
  30. package/src/utils/getColumnFilteredRowModelSync.ts +3 -1
  31. package/src/utils/getCoreRowModelAsync.ts +4 -2
  32. package/src/utils/getCoreRowModelSync.ts +4 -2
  33. package/src/utils/getGlobalFilteredRowModelAsync.ts +4 -2
  34. package/src/utils/getGlobalFilteredRowModelSync.ts +4 -2
  35. package/src/utils/getGroupedRowModel.ts +5 -1
  36. package/src/utils/getSortedRowModelAsync.ts +3 -1
  37. package/src/utils/getSortedRowModelSync.ts +3 -1
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tanstack/table-core",
3
3
  "author": "Tanner Linsley",
4
- "version": "8.0.0-alpha.32",
4
+ "version": "8.0.0-alpha.37",
5
5
  "description": "Hooks for building lightweight, fast and extendable datagrids for React",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/tanstack/react-table#readme",
@@ -14,6 +14,8 @@
14
14
  },
15
15
  "keywords": [
16
16
  "react",
17
+ "vue",
18
+ "solid",
17
19
  "table",
18
20
  "table-core",
19
21
  "datagrid"
package/src/core.tsx CHANGED
@@ -47,6 +47,7 @@ import { Sorting } from './features/Sorting'
47
47
  import { Visibility } from './features/Visibility'
48
48
  import { Headers } from './features/Headers'
49
49
  import { mean } from './aggregationTypes'
50
+ import React from 'react'
50
51
 
51
52
  const features: TableFeature[] = [
52
53
  Headers,
@@ -104,6 +105,8 @@ export type TableCore<TGenerics extends AnyGenerics> = {
104
105
  reset: () => void
105
106
  options: RequiredKeys<Options<TGenerics>, 'state'>
106
107
  setOptions: (newOptions: Updater<Options<TGenerics>>) => void
108
+ queue: (cb: () => void) => void
109
+ willUpdate: () => void
107
110
  getRowId: (
108
111
  _: TGenerics['Row'],
109
112
  index: number,
@@ -259,11 +262,28 @@ export function createTableInstance<TGenerics extends AnyGenerics>(
259
262
  ...(options.initialState ?? {}),
260
263
  } as TableState
261
264
 
265
+ const queued: (() => void)[] = []
266
+ let queuedTimeout: NodeJS.Timeout
267
+
262
268
  const finalInstance: TableInstance<TGenerics> = {
263
269
  ...instance,
264
270
  ...features.reduce((obj, feature) => {
265
271
  return Object.assign(obj, feature.getInstance?.(instance))
266
272
  }, {}),
273
+ queue: cb => {
274
+ queued.push(cb)
275
+ if (!queuedTimeout) {
276
+ queuedTimeout = setTimeout(() => {
277
+ instance.setState(old => ({ ...old }))
278
+ })
279
+ }
280
+ },
281
+ willUpdate: () => {
282
+ clearTimeout(queuedTimeout)
283
+ while (queued.length) {
284
+ queued.shift()!()
285
+ }
286
+ },
267
287
  initialState,
268
288
  reset: () => {
269
289
  instance.setState(instance.initialState)
@@ -287,7 +287,9 @@ export const RowSelection = {
287
287
  {
288
288
  key: 'getSelectedRowModel',
289
289
  debug: () => instance.options.debugAll ?? instance.options.debugTable,
290
- onChange: () => instance._notifyExpandedReset(),
290
+ onChange: () => {
291
+ instance.queue(() => instance._notifyExpandedReset())
292
+ },
291
293
  }
292
294
  ),
293
295
 
@@ -310,7 +312,7 @@ export const RowSelection = {
310
312
  {
311
313
  key: 'getFilteredSelectedRowModel',
312
314
  debug: () => instance.options.debugAll ?? instance.options.debugTable,
313
- onChange: () => instance._notifyExpandedReset(),
315
+ onChange: () => instance.queue(() => instance._notifyExpandedReset()),
314
316
  }
315
317
  ),
316
318
 
@@ -330,7 +332,7 @@ export const RowSelection = {
330
332
  {
331
333
  key: 'getGroupedSelectedRowModel',
332
334
  debug: () => instance.options.debugAll ?? instance.options.debugTable,
333
- onChange: () => instance._notifyExpandedReset(),
335
+ onChange: () => instance.queue(() => instance._notifyExpandedReset()),
334
336
  }
335
337
  ),
336
338
 
@@ -110,7 +110,9 @@ export function getColumnFilteredRowModelAsync<
110
110
  },
111
111
  debug: () => instance.options.debugAll ?? instance.options.debugTable,
112
112
  onChange: () => {
113
- instance._notifySortingReset()
113
+ instance.queue(() => {
114
+ instance._notifySortingReset()
115
+ })
114
116
  },
115
117
  }
116
118
  )
@@ -90,7 +90,9 @@ export function getColumnFilteredRowModelSync<
90
90
  key: 'getColumnFilteredRowModelSync',
91
91
  debug: () => instance.options.debugAll ?? instance.options.debugTable,
92
92
  onChange: () => {
93
- instance._notifySortingReset()
93
+ instance.queue(() => {
94
+ instance._notifySortingReset()
95
+ })
94
96
  },
95
97
  }
96
98
  )
@@ -95,8 +95,10 @@ export function getCoreRowModelAsync<TGenerics extends AnyGenerics>(opts?: {
95
95
  },
96
96
  debug: () => instance.options.debugAll ?? instance.options.debugTable,
97
97
  onChange: () => {
98
- instance._notifyFiltersReset()
99
- instance._notifyRowSelectionReset()
98
+ instance.queue(() => {
99
+ instance._notifyFiltersReset()
100
+ instance._notifyRowSelectionReset()
101
+ })
100
102
  },
101
103
  }
102
104
  )
@@ -97,8 +97,10 @@ export function getCoreRowModelSync<TGenerics extends AnyGenerics>(): (
97
97
  key: 'getRowModel',
98
98
  debug: () => instance.options.debugAll ?? instance.options.debugTable,
99
99
  onChange: () => {
100
- instance._notifyFiltersReset()
101
- instance._notifyRowSelectionReset()
100
+ instance.queue(() => {
101
+ instance._notifyFiltersReset()
102
+ instance._notifyRowSelectionReset()
103
+ })
102
104
  },
103
105
  }
104
106
  )
@@ -56,7 +56,7 @@ export function getGlobalFilteredRowModelAsync<
56
56
  // }
57
57
 
58
58
  // if (filterFromLeafRows) {
59
- // filterRowModelFromLeafs(rowModel.rows, filterRows, instance)
59
+ // return filterRowModelFromLeafs(rowModel.rows, filterRows, instance)
60
60
  // }
61
61
 
62
62
  // return filterRowModelFromRoot(rowModel.rows, filterRows, instance)
@@ -88,7 +88,9 @@ export function getGlobalFilteredRowModelAsync<
88
88
  },
89
89
  debug: () => instance.options.debugAll ?? instance.options.debugTable,
90
90
  onChange: () => {
91
- instance._notifySortingReset()
91
+ instance.queue(() => {
92
+ instance._notifySortingReset()
93
+ })
92
94
  },
93
95
  }
94
96
  )
@@ -39,7 +39,7 @@ export function getGlobalFilteredRowModelSync<
39
39
  }
40
40
 
41
41
  if (filterFromLeafRows) {
42
- filterRowModelFromLeafs(rowModel.rows, filterRows, instance)
42
+ return filterRowModelFromLeafs(rowModel.rows, filterRows, instance)
43
43
  }
44
44
 
45
45
  return filterRowModelFromRoot(rowModel.rows, filterRows, instance)
@@ -67,7 +67,9 @@ export function getGlobalFilteredRowModelSync<
67
67
  key: 'getGlobalFilteredRowModelSync',
68
68
  debug: () => instance.options.debugAll ?? instance.options.debugTable,
69
69
  onChange: () => {
70
- instance._notifySortingReset()
70
+ instance.queue(() => {
71
+ instance._notifySortingReset()
72
+ })
71
73
  },
72
74
  }
73
75
  )
@@ -163,7 +163,11 @@ export function getGroupedRowModelSync<TGenerics extends AnyGenerics>(): (
163
163
  {
164
164
  key: 'getGroupedRowModel',
165
165
  debug: () => instance.options.debugAll ?? instance.options.debugTable,
166
- onChange: () => instance._notifyExpandedReset(),
166
+ onChange: () => {
167
+ instance.queue(() => {
168
+ instance._notifyExpandedReset()
169
+ })
170
+ },
167
171
  }
168
172
  )
169
173
  }
@@ -83,7 +83,9 @@ export function getSortedRowModelSync<TGenerics extends AnyGenerics>(opts?: {
83
83
  },
84
84
  debug: () => instance.options.debugAll ?? instance.options.debugTable,
85
85
  onChange: () => {
86
- instance._notifyGroupingReset()
86
+ instance.queue(() => {
87
+ instance._notifyGroupingReset()
88
+ })
87
89
  },
88
90
  }
89
91
  )
@@ -109,7 +109,9 @@ export function getSortedRowModelSync<TGenerics extends AnyGenerics>(): (
109
109
  key: 'getSortedRowModel',
110
110
  debug: () => instance.options.debugAll ?? instance.options.debugTable,
111
111
  onChange: () => {
112
- instance._notifyGroupingReset()
112
+ instance.queue(() => {
113
+ instance._notifyGroupingReset()
114
+ })
113
115
  },
114
116
  }
115
117
  )