@tanstack/react-table 8.0.0-alpha.5 → 8.0.0-alpha.6

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tanstack/react-table",
3
3
  "author": "Tanner Linsley",
4
- "version": "8.0.0-alpha.5",
4
+ "version": "8.0.0-alpha.6",
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",
package/src/core.tsx CHANGED
@@ -291,96 +291,6 @@ export type CoreColumnDef<
291
291
  header: Header<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
292
292
  column: Column<TData, TValue, TFilterFns, TSortingFns, TAggregationFns>
293
293
  }>
294
- } & // instance: ReactTable< // | Renderable<{ // | string // header?: // accessorKey?: never // id: string // accessorFn: AccessorFn<TData> // | {
295
- // TData,
296
- // TValue,
297
- // TFilterFns,
298
- // TSortingFns,
299
- // TAggregationFns
300
- // >
301
- // header: Header<
302
- // TData,
303
- // TValue,
304
- // TFilterFns,
305
- // TSortingFns,
306
- // TAggregationFns
307
- // >
308
- // column: Column<
309
- // TData,
310
- // TValue,
311
- // TFilterFns,
312
- // TSortingFns,
313
- // TAggregationFns
314
- // >
315
- // }>
316
- // }
317
- // | {
318
- // accessorKey: string & keyof TData
319
- // id?: string
320
- // accessorFn?: never
321
- // header?:
322
- // | string
323
- // | Renderable<{
324
- // instance: ReactTable<
325
- // TData,
326
- // TValue,
327
- // TFilterFns,
328
- // TSortingFns,
329
- // TAggregationFns
330
- // >
331
- // header: Header<
332
- // TData,
333
- // TValue,
334
- // TFilterFns,
335
- // TSortingFns,
336
- // TAggregationFns
337
- // >
338
- // column: Column<
339
- // TData,
340
- // TValue,
341
- // TFilterFns,
342
- // TSortingFns,
343
- // TAggregationFns
344
- // >
345
- // }>
346
- // }
347
- // | {
348
- // id: string
349
- // accessorKey?: never
350
- // accessorFn?: never
351
- // header?:
352
- // | string
353
- // | Renderable<{
354
- // instance: ReactTable<
355
- // TData,
356
- // TValue,
357
- // TFilterFns,
358
- // TSortingFns,
359
- // TAggregationFns
360
- // >
361
- // header: Header<
362
- // TData,
363
- // TValue,
364
- // TFilterFns,
365
- // TSortingFns,
366
- // TAggregationFns
367
- // >
368
- // column: Column<
369
- // TData,
370
- // TValue,
371
- // TFilterFns,
372
- // TSortingFns,
373
- // TAggregationFns
374
- // >
375
- // }>
376
- // }
377
- // | {
378
- // header: string
379
- // id?: string
380
- // accessorKey?: never
381
- // accessorFn?: never
382
- // }
383
- {
384
294
  __generated: true
385
295
  width?: number
386
296
  minWidth?: number
@@ -192,7 +192,7 @@ export function getInstance<
192
192
  toggleRowExpanded: (rowId, expanded) => {
193
193
  if (!rowId) return
194
194
 
195
- instance.setExpanded((old = {}) => {
195
+ instance.setExpanded(old => {
196
196
  const exists = old === true ? true : !!old?.[rowId]
197
197
 
198
198
  let oldExpanded: ExpandedStateList = {}
@@ -230,7 +230,7 @@ export function getInstance<
230
230
  }
231
231
  },
232
232
  resetExpanded: () => {
233
- instance.setExpanded(instance.options?.initialState?.expanded ?? {})
233
+ instance.setExpanded(instance.initialState?.expanded ?? {})
234
234
  },
235
235
  getIsRowExpanded: rowId => {
236
236
  const row = instance.getRow(rowId)
@@ -362,7 +362,9 @@ export function getInstance<
362
362
  {
363
363
  key: 'getExpandedRowModel',
364
364
  debug: instance.options.debug,
365
- onChange: () => instance._notifyPageIndexReset(),
365
+ onChange: () => {
366
+ instance._notifyPageIndexReset()
367
+ },
366
368
  }
367
369
  ),
368
370
 
@@ -628,9 +628,7 @@ export function getInstance<
628
628
  },
629
629
 
630
630
  resetColumnFilters: () => {
631
- instance.setColumnFilters(
632
- instance.options?.initialState?.columnFilters ?? []
633
- )
631
+ instance.setColumnFilters(instance.initialState?.columnFilters ?? [])
634
632
  },
635
633
 
636
634
  getColumnFilteredRowModel: memo(
@@ -730,7 +728,9 @@ export function getInstance<
730
728
  {
731
729
  key: 'getGlobalFilteredRowModel',
732
730
  debug: instance.options.debug,
733
- onChange: () => instance._notifySortingReset(),
731
+ onChange: () => {
732
+ instance._notifySortingReset()
733
+ },
734
734
  }
735
735
  ),
736
736
 
@@ -331,7 +331,7 @@ export function getInstance<
331
331
  instance.getState().grouping?.indexOf(columnId),
332
332
 
333
333
  resetGrouping: () => {
334
- instance.setGrouping(instance.options?.initialState?.grouping ?? [])
334
+ instance.setGrouping(instance.initialState?.grouping ?? [])
335
335
  },
336
336
 
337
337
  getToggleGroupingProps: (columnId, userProps) => {
@@ -217,9 +217,7 @@ export function getInstance<
217
217
  instance.setPageIndex(0)
218
218
  },
219
219
  resetPageSize: () => {
220
- instance.setPageSize(
221
- instance.options.initialState?.pagination?.pageSize ?? 10
222
- )
220
+ instance.setPageSize(instance.initialState?.pagination?.pageSize ?? 10)
223
221
  },
224
222
  setPageSize: updater => {
225
223
  instance.setPagination(old => {
@@ -114,9 +114,7 @@ export function getInstance<
114
114
  ),
115
115
 
116
116
  resetColumnPinning: () =>
117
- instance.setColumnPinning(
118
- instance.options.initialState?.columnPinning ?? {}
119
- ),
117
+ instance.setColumnPinning(instance.initialState?.columnPinning ?? {}),
120
118
 
121
119
  pinColumn: (columnId, position) => {
122
120
  const column = instance.getColumn(columnId)
@@ -484,7 +484,7 @@ export function getInstance<
484
484
  instance.getState().sorting?.findIndex(d => d.id === columnId) ?? -1,
485
485
 
486
486
  resetSorting: () => {
487
- instance.setSorting(instance.options?.initialState?.sorting ?? [])
487
+ instance.setSorting(instance.initialState?.sorting ?? [])
488
488
  },
489
489
 
490
490
  getToggleSortingProps: (columnId, userProps) => {
package/src/utils.tsx CHANGED
@@ -43,29 +43,6 @@ export function makeStateUpdater(key: keyof TableState, instance: unknown) {
43
43
  }
44
44
  }
45
45
 
46
- // SSR has issues with useLayoutEffect still, so use useEffect during SSR
47
- export const safeUseLayoutEffect =
48
- typeof document !== 'undefined' ? React.useLayoutEffect : React.useEffect
49
-
50
- export function useMountedLayoutEffect(fn: any, deps: any[]) {
51
- const mountedRef = React.useRef(false)
52
-
53
- safeUseLayoutEffect(() => {
54
- if (mountedRef.current) {
55
- fn()
56
- }
57
- mountedRef.current = true
58
- // eslint-disable-next-line
59
- }, deps)
60
- }
61
-
62
- export function useGetLatest<T>(obj: T): () => T {
63
- const ref = React.useRef<T>()
64
- ref.current = obj
65
-
66
- return React.useCallback(() => ref.current!, [])
67
- }
68
-
69
46
  type AnyFunction = (...args: any) => any
70
47
 
71
48
  export function isFunction<T extends AnyFunction>(d: any): d is T {
@@ -124,27 +101,19 @@ export function memo<TDeps extends readonly any[], TResult>(
124
101
 
125
102
  return () => {
126
103
  const newDeps = getDeps()
127
- const newSerializedDeps = newDeps
128
- const oldSerializedDeps = deps
129
104
 
130
105
  const depsChanged =
131
- newSerializedDeps.length !== oldSerializedDeps.length ||
132
- newSerializedDeps.some(
133
- (dep: any, index: number) => oldSerializedDeps[index] !== dep
134
- )
106
+ newDeps.length !== deps.length ||
107
+ newDeps.some((dep: any, index: number) => deps[index] !== dep)
135
108
 
136
109
  if (depsChanged) {
137
110
  if (opts?.debug) {
138
111
  console.info(opts?.key, {
139
- length: `${oldSerializedDeps.length} -> ${newSerializedDeps.length}`,
140
- ...newSerializedDeps
112
+ length: `${deps.length} -> ${newDeps.length}`,
113
+ ...newDeps
141
114
  .map((_, index) => {
142
- if (oldSerializedDeps[index] !== newSerializedDeps[index]) {
143
- return [
144
- index,
145
- oldSerializedDeps[index],
146
- newSerializedDeps[index],
147
- ]
115
+ if (deps[index] !== newDeps[index]) {
116
+ return [index, deps[index], newDeps[index]]
148
117
  }
149
118
 
150
119
  return false
@@ -163,7 +132,7 @@ export function memo<TDeps extends readonly any[], TResult>(
163
132
 
164
133
  let oldResult = result
165
134
  result = fn(...newDeps)
166
- deps = newSerializedDeps
135
+ deps = newDeps
167
136
  opts?.onChange?.(result, oldResult)
168
137
 
169
138
  oldResult = undefined
@@ -173,37 +142,6 @@ export function memo<TDeps extends readonly any[], TResult>(
173
142
  }
174
143
  }
175
144
 
176
- // Copied from: https://github.com/jonschlinkert/is-plain-object
177
- export function isPlainObject(o: any): o is Object {
178
- if (!hasObjectPrototype(o)) {
179
- return false
180
- }
181
-
182
- // If has modified constructor
183
- const ctor = o.constructor
184
- if (typeof ctor === 'undefined') {
185
- return true
186
- }
187
-
188
- // If has modified prototype
189
- const prot = ctor.prototype
190
- if (!hasObjectPrototype(prot)) {
191
- return false
192
- }
193
-
194
- // If constructor does not have an Object-specific method
195
- if (!prot.hasOwnProperty('isPrototypeOf')) {
196
- return false
197
- }
198
-
199
- // Most likely a plain Object
200
- return true
201
- }
202
-
203
- function hasObjectPrototype(o: any): boolean {
204
- return Object.prototype.toString.call(o) === '[object Object]'
205
- }
206
-
207
145
  export type Render = typeof flexRender
208
146
 
209
147
  export function flexRender<TProps extends {}>(