@tanstack/table-core 8.11.8 → 8.12.0

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 (81) hide show
  1. package/build/lib/core/cell.js +1 -4
  2. package/build/lib/core/cell.js.map +1 -1
  3. package/build/lib/core/column.js +2 -14
  4. package/build/lib/core/column.js.map +1 -1
  5. package/build/lib/core/headers.js +17 -112
  6. package/build/lib/core/headers.js.map +1 -1
  7. package/build/lib/core/row.js +2 -14
  8. package/build/lib/core/row.js.map +1 -1
  9. package/build/lib/core/table.d.ts +6 -0
  10. package/build/lib/core/table.js +5 -35
  11. package/build/lib/core/table.js.map +1 -1
  12. package/build/lib/features/ColumnSizing.d.ts +6 -2
  13. package/build/lib/features/ColumnSizing.js +3 -9
  14. package/build/lib/features/ColumnSizing.js.map +1 -1
  15. package/build/lib/features/Ordering.d.ts +21 -0
  16. package/build/lib/features/Ordering.js +15 -4
  17. package/build/lib/features/Ordering.js.map +1 -1
  18. package/build/lib/features/Pagination.js +1 -7
  19. package/build/lib/features/Pagination.js.map +1 -1
  20. package/build/lib/features/Pinning.js +9 -57
  21. package/build/lib/features/Pinning.js.map +1 -1
  22. package/build/lib/features/RowSelection.js +3 -21
  23. package/build/lib/features/RowSelection.js.map +1 -1
  24. package/build/lib/features/Visibility.d.ts +3 -1
  25. package/build/lib/features/Visibility.js +7 -21
  26. package/build/lib/features/Visibility.js.map +1 -1
  27. package/build/lib/index.esm.js +89 -382
  28. package/build/lib/index.esm.js.map +1 -1
  29. package/build/lib/index.js +2 -0
  30. package/build/lib/index.js.map +1 -1
  31. package/build/lib/index.mjs +89 -382
  32. package/build/lib/index.mjs.map +1 -1
  33. package/build/lib/types.d.ts +2 -2
  34. package/build/lib/utils/getCoreRowModel.js +1 -10
  35. package/build/lib/utils/getCoreRowModel.js.map +1 -1
  36. package/build/lib/utils/getExpandedRowModel.js +1 -7
  37. package/build/lib/utils/getExpandedRowModel.js.map +1 -1
  38. package/build/lib/utils/getFacetedMinMaxValues.js +1 -8
  39. package/build/lib/utils/getFacetedMinMaxValues.js.map +1 -1
  40. package/build/lib/utils/getFacetedRowModel.js +1 -8
  41. package/build/lib/utils/getFacetedRowModel.js.map +1 -1
  42. package/build/lib/utils/getFacetedUniqueValues.js +1 -8
  43. package/build/lib/utils/getFacetedUniqueValues.js.map +1 -1
  44. package/build/lib/utils/getFilteredRowModel.js +1 -10
  45. package/build/lib/utils/getFilteredRowModel.js.map +1 -1
  46. package/build/lib/utils/getGroupedRowModel.js +6 -13
  47. package/build/lib/utils/getGroupedRowModel.js.map +1 -1
  48. package/build/lib/utils/getPaginationRowModel.js +1 -7
  49. package/build/lib/utils/getPaginationRowModel.js.map +1 -1
  50. package/build/lib/utils/getSortedRowModel.js +1 -10
  51. package/build/lib/utils/getSortedRowModel.js.map +1 -1
  52. package/build/lib/utils.d.ts +8 -3
  53. package/build/lib/utils.js +13 -2
  54. package/build/lib/utils.js.map +1 -1
  55. package/build/umd/index.development.js +90 -381
  56. package/build/umd/index.development.js.map +1 -1
  57. package/build/umd/index.production.js +1 -1
  58. package/build/umd/index.production.js.map +1 -1
  59. package/package.json +1 -1
  60. package/src/core/cell.ts +2 -5
  61. package/src/core/column.ts +3 -9
  62. package/src/core/headers.ts +19 -65
  63. package/src/core/row.ts +3 -10
  64. package/src/core/table.ts +12 -21
  65. package/src/features/ColumnSizing.ts +33 -20
  66. package/src/features/Ordering.ts +74 -35
  67. package/src/features/Pagination.ts +7 -5
  68. package/src/features/Pinning.ts +34 -60
  69. package/src/features/RowSelection.ts +4 -16
  70. package/src/features/Visibility.ts +18 -13
  71. package/src/types.ts +3 -1
  72. package/src/utils/getCoreRowModel.ts +4 -8
  73. package/src/utils/getExpandedRowModel.ts +2 -5
  74. package/src/utils/getFacetedMinMaxValues.ts +2 -8
  75. package/src/utils/getFacetedRowModel.ts +2 -8
  76. package/src/utils/getFacetedUniqueValues.ts +6 -8
  77. package/src/utils/getFilteredRowModel.ts +4 -8
  78. package/src/utils/getGroupedRowModel.ts +7 -11
  79. package/src/utils/getPaginationRowModel.ts +2 -5
  80. package/src/utils/getSortedRowModel.ts +4 -8
  81. package/src/utils.ts +25 -6
@@ -8,7 +8,7 @@ import {
8
8
  Cell,
9
9
  RowData,
10
10
  } from '../types'
11
- import { makeStateUpdater, memo } from '../utils'
11
+ import { getMemoOptions, makeStateUpdater, memo } from '../utils'
12
12
 
13
13
  export type ColumnPinningPosition = false | 'left' | 'right'
14
14
  export type RowPinningPosition = false | 'top' | 'bottom'
@@ -426,11 +426,7 @@ export const Pinning: TableFeature = {
426
426
 
427
427
  return allCells.filter(d => !leftAndRight.includes(d.column.id))
428
428
  },
429
- {
430
- key:
431
- process.env.NODE_ENV === 'development' && 'row.getCenterVisibleCells',
432
- debug: () => table.options.debugAll ?? table.options.debugRows,
433
- }
429
+ getMemoOptions(table.options, 'debugRows', 'getCenterVisibleCells')
434
430
  )
435
431
  row.getLeftVisibleCells = memo(
436
432
  () => [row._getAllVisibleCells(), table.getState().columnPinning.left, ,],
@@ -442,11 +438,7 @@ export const Pinning: TableFeature = {
442
438
 
443
439
  return cells
444
440
  },
445
- {
446
- key:
447
- process.env.NODE_ENV === 'development' && 'row.getLeftVisibleCells',
448
- debug: () => table.options.debugAll ?? table.options.debugRows,
449
- }
441
+ getMemoOptions(table.options, 'debugRows', 'getLeftVisibleCells')
450
442
  )
451
443
  row.getRightVisibleCells = memo(
452
444
  () => [row._getAllVisibleCells(), table.getState().columnPinning.right],
@@ -458,11 +450,7 @@ export const Pinning: TableFeature = {
458
450
 
459
451
  return cells
460
452
  },
461
- {
462
- key:
463
- process.env.NODE_ENV === 'development' && 'row.getRightVisibleCells',
464
- debug: () => table.options.debugAll ?? table.options.debugRows,
465
- }
453
+ getMemoOptions(table.options, 'debugRows', 'getRightVisibleCells')
466
454
  )
467
455
  },
468
456
 
@@ -493,10 +481,7 @@ export const Pinning: TableFeature = {
493
481
  .map(columnId => allColumns.find(column => column.id === columnId)!)
494
482
  .filter(Boolean)
495
483
  },
496
- {
497
- key: process.env.NODE_ENV === 'development' && 'getLeftLeafColumns',
498
- debug: () => table.options.debugAll ?? table.options.debugColumns,
499
- }
484
+ getMemoOptions(table.options, 'debugColumns', 'getLeftLeafColumns')
500
485
  )
501
486
 
502
487
  table.getRightLeafColumns = memo(
@@ -506,10 +491,7 @@ export const Pinning: TableFeature = {
506
491
  .map(columnId => allColumns.find(column => column.id === columnId)!)
507
492
  .filter(Boolean)
508
493
  },
509
- {
510
- key: process.env.NODE_ENV === 'development' && 'getRightLeafColumns',
511
- debug: () => table.options.debugAll ?? table.options.debugColumns,
512
- }
494
+ getMemoOptions(table.options, 'debugColumns', 'getRightLeafColumns')
513
495
  )
514
496
 
515
497
  table.getCenterLeafColumns = memo(
@@ -523,10 +505,7 @@ export const Pinning: TableFeature = {
523
505
 
524
506
  return allColumns.filter(d => !leftAndRight.includes(d.id))
525
507
  },
526
- {
527
- key: process.env.NODE_ENV === 'development' && 'getCenterLeafColumns',
528
- debug: () => table.options.debugAll ?? table.options.debugColumns,
529
- }
508
+ getMemoOptions(table.options, 'debugColumns', 'getCenterLeafColumns')
530
509
  )
531
510
 
532
511
  table.setRowPinning = updater => table.options.onRowPinningChange?.(updater)
@@ -547,34 +526,32 @@ export const Pinning: TableFeature = {
547
526
  return Boolean(pinningState[position]?.length)
548
527
  }
549
528
 
550
- table._getPinnedRows = (position: 'top' | 'bottom') =>
551
- memo(
552
- () => [table.getRowModel().rows, table.getState().rowPinning[position]],
553
- (visibleRows, pinnedRowIds) => {
554
- const rows =
555
- table.options.keepPinnedRows ?? true
556
- ? //get all rows that are pinned even if they would not be otherwise visible
557
- //account for expanded parent rows, but not pagination or filtering
558
- (pinnedRowIds ?? []).map(rowId => {
559
- const row = table.getRow(rowId, true)
560
- return row.getIsAllParentsExpanded() ? row : null
561
- })
562
- : //else get only visible rows that are pinned
563
- (pinnedRowIds ?? []).map(
564
- rowId => visibleRows.find(row => row.id === rowId)!
565
- )
566
-
567
- return rows
568
- .filter(Boolean)
569
- .map(d => ({ ...d, position })) as Row<TData>[]
570
- },
571
- {
572
- key:
573
- process.env.NODE_ENV === 'development' &&
574
- `row.get${position === 'top' ? 'Top' : 'Bottom'}Rows`,
575
- debug: () => table.options.debugAll ?? table.options.debugRows,
576
- }
577
- )()
529
+ table._getPinnedRows = memo(
530
+ position => [
531
+ table.getRowModel().rows,
532
+ table.getState().rowPinning[position!],
533
+ position,
534
+ ],
535
+ (visibleRows, pinnedRowIds, position) => {
536
+ const rows =
537
+ table.options.keepPinnedRows ?? true
538
+ ? //get all rows that are pinned even if they would not be otherwise visible
539
+ //account for expanded parent rows, but not pagination or filtering
540
+ (pinnedRowIds ?? []).map(rowId => {
541
+ const row = table.getRow(rowId, true)
542
+ return row.getIsAllParentsExpanded() ? row : null
543
+ })
544
+ : //else get only visible rows that are pinned
545
+ (pinnedRowIds ?? []).map(
546
+ rowId => visibleRows.find(row => row.id === rowId)!
547
+ )
548
+
549
+ return rows
550
+ .filter(Boolean)
551
+ .map(d => ({ ...d, position })) as Row<TData>[]
552
+ },
553
+ getMemoOptions(table.options, 'debugRows', '_getPinnedRows')
554
+ )
578
555
 
579
556
  table.getTopRows = () => table._getPinnedRows('top')
580
557
 
@@ -590,10 +567,7 @@ export const Pinning: TableFeature = {
590
567
  const topAndBottom = new Set([...(top ?? []), ...(bottom ?? [])])
591
568
  return allRows.filter(d => !topAndBottom.has(d.id))
592
569
  },
593
- {
594
- key: process.env.NODE_ENV === 'development' && 'row.getCenterRows',
595
- debug: () => table.options.debugAll ?? table.options.debugRows,
596
- }
570
+ getMemoOptions(table.options, 'debugRows', 'getCenterRows')
597
571
  )
598
572
  },
599
573
  }
@@ -1,6 +1,6 @@
1
1
  import { TableFeature } from '../core/table'
2
2
  import { OnChangeFn, Table, Row, RowModel, Updater, RowData } from '../types'
3
- import { makeStateUpdater, memo } from '../utils'
3
+ import { getMemoOptions, makeStateUpdater, memo } from '../utils'
4
4
 
5
5
  export type RowSelectionState = Record<string, boolean>
6
6
 
@@ -333,10 +333,7 @@ export const RowSelection: TableFeature = {
333
333
 
334
334
  return selectRowsFn(table, rowModel)
335
335
  },
336
- {
337
- key: process.env.NODE_ENV === 'development' && 'getSelectedRowModel',
338
- debug: () => table.options.debugAll ?? table.options.debugTable,
339
- }
336
+ getMemoOptions(table.options, 'debugTable', 'getSelectedRowModel')
340
337
  )
341
338
 
342
339
  table.getFilteredSelectedRowModel = memo(
@@ -352,12 +349,7 @@ export const RowSelection: TableFeature = {
352
349
 
353
350
  return selectRowsFn(table, rowModel)
354
351
  },
355
- {
356
- key:
357
- process.env.NODE_ENV === 'production' &&
358
- 'getFilteredSelectedRowModel',
359
- debug: () => table.options.debugAll ?? table.options.debugTable,
360
- }
352
+ getMemoOptions(table.options, 'debugTable', 'getFilteredSelectedRowModel')
361
353
  )
362
354
 
363
355
  table.getGroupedSelectedRowModel = memo(
@@ -373,11 +365,7 @@ export const RowSelection: TableFeature = {
373
365
 
374
366
  return selectRowsFn(table, rowModel)
375
367
  },
376
- {
377
- key:
378
- process.env.NODE_ENV === 'production' && 'getGroupedSelectedRowModel',
379
- debug: () => table.options.debugAll ?? table.options.debugTable,
380
- }
368
+ getMemoOptions(table.options, 'debugTable', 'getGroupedSelectedRowModel')
381
369
  )
382
370
 
383
371
  ///
@@ -1,3 +1,4 @@
1
+ import { ColumnPinningPosition } from '..'
1
2
  import { TableFeature } from '../core/table'
2
3
  import {
3
4
  Cell,
@@ -8,7 +9,7 @@ import {
8
9
  Row,
9
10
  RowData,
10
11
  } from '../types'
11
- import { makeStateUpdater, memo } from '../utils'
12
+ import { getMemoOptions, makeStateUpdater, memo } from '../utils'
12
13
 
13
14
  export type VisibilityState = Record<string, boolean>
14
15
 
@@ -199,10 +200,7 @@ export const Visibility: TableFeature = {
199
200
  cells => {
200
201
  return cells.filter(cell => cell.column.getIsVisible())
201
202
  },
202
- {
203
- key: process.env.NODE_ENV === 'production' && 'row._getAllVisibleCells',
204
- debug: () => table.options.debugAll ?? table.options.debugRows,
205
- }
203
+ getMemoOptions(table.options, 'debugRows', '_getAllVisibleCells')
206
204
  )
207
205
  row.getVisibleCells = memo(
208
206
  () => [
@@ -211,10 +209,7 @@ export const Visibility: TableFeature = {
211
209
  row.getRightVisibleCells(),
212
210
  ],
213
211
  (left, center, right) => [...left, ...center, ...right],
214
- {
215
- key: process.env.NODE_ENV === 'development' && 'row.getVisibleCells',
216
- debug: () => table.options.debugAll ?? table.options.debugRows,
217
- }
212
+ getMemoOptions(table.options, 'debugRows', 'getVisibleCells')
218
213
  )
219
214
  },
220
215
 
@@ -234,10 +229,7 @@ export const Visibility: TableFeature = {
234
229
  columns => {
235
230
  return columns.filter(d => d.getIsVisible?.())
236
231
  },
237
- {
238
- key,
239
- debug: () => table.options.debugAll ?? table.options.debugColumns,
240
- }
232
+ getMemoOptions(table.options, 'debugColumns', key)
241
233
  )
242
234
  }
243
235
 
@@ -300,3 +292,16 @@ export const Visibility: TableFeature = {
300
292
  }
301
293
  },
302
294
  }
295
+
296
+ export function _getVisibleLeafColumns<TData extends RowData>(
297
+ table: Table<TData>,
298
+ position?: ColumnPinningPosition | 'center'
299
+ ) {
300
+ return !position
301
+ ? table.getVisibleLeafColumns()
302
+ : position === 'center'
303
+ ? table.getCenterVisibleLeafColumns()
304
+ : position === 'left'
305
+ ? table.getLeftVisibleLeafColumns()
306
+ : table.getRightVisibleLeafColumns()
307
+ }
package/src/types.ts CHANGED
@@ -8,6 +8,7 @@ import {
8
8
  VisibilityRow,
9
9
  } from './features/Visibility'
10
10
  import {
11
+ ColumnOrderColumn,
11
12
  ColumnOrderInstance,
12
13
  ColumnOrderOptions,
13
14
  ColumnOrderTableState,
@@ -304,7 +305,8 @@ export interface Column<TData extends RowData, TValue = unknown>
304
305
  FiltersColumn<TData>,
305
306
  SortingColumn<TData>,
306
307
  GroupingColumn<TData>,
307
- ColumnSizingColumn {}
308
+ ColumnSizingColumn,
309
+ ColumnOrderColumn {}
308
310
 
309
311
  export interface Cell<TData extends RowData, TValue>
310
312
  extends CoreCell<TData, TValue>,
@@ -1,6 +1,6 @@
1
1
  import { createRow } from '../core/row'
2
2
  import { Table, Row, RowModel, RowData } from '../types'
3
- import { memo } from '../utils'
3
+ import { getMemoOptions, memo } from '../utils'
4
4
 
5
5
  export function getCoreRowModel<TData extends RowData>(): (
6
6
  table: Table<TData>
@@ -75,12 +75,8 @@ export function getCoreRowModel<TData extends RowData>(): (
75
75
 
76
76
  return rowModel
77
77
  },
78
- {
79
- key: process.env.NODE_ENV === 'development' && 'getRowModel',
80
- debug: () => table.options.debugAll ?? table.options.debugTable,
81
- onChange: () => {
82
- table._autoResetPageIndex()
83
- },
84
- }
78
+ getMemoOptions(table.options, 'debugTable', 'getRowModel', () =>
79
+ table._autoResetPageIndex()
80
+ )
85
81
  )
86
82
  }
@@ -1,5 +1,5 @@
1
1
  import { Table, Row, RowModel, RowData } from '../types'
2
- import { memo } from '../utils'
2
+ import { getMemoOptions, memo } from '../utils'
3
3
 
4
4
  export function getExpandedRowModel<TData extends RowData>(): (
5
5
  table: Table<TData>
@@ -26,10 +26,7 @@ export function getExpandedRowModel<TData extends RowData>(): (
26
26
 
27
27
  return expandRows(rowModel)
28
28
  },
29
- {
30
- key: process.env.NODE_ENV === 'development' && 'getExpandedRowModel',
31
- debug: () => table.options.debugAll ?? table.options.debugTable,
32
- }
29
+ getMemoOptions(table.options, 'debugTable', 'getExpandedRowModel')
33
30
  )
34
31
  }
35
32
 
@@ -1,5 +1,5 @@
1
1
  import { Table, RowData } from '../types'
2
- import { memo } from '../utils'
2
+ import { getMemoOptions, memo } from '../utils'
3
3
 
4
4
  export function getFacetedMinMaxValues<TData extends RowData>(): (
5
5
  table: Table<TData>,
@@ -37,12 +37,6 @@ export function getFacetedMinMaxValues<TData extends RowData>(): (
37
37
 
38
38
  return facetedMinMaxValues
39
39
  },
40
- {
41
- key:
42
- process.env.NODE_ENV === 'development' &&
43
- 'getFacetedMinMaxValues_' + columnId,
44
- debug: () => table.options.debugAll ?? table.options.debugTable,
45
- onChange: () => {},
46
- }
40
+ getMemoOptions(table.options, 'debugTable', 'getFacetedMinMaxValues')
47
41
  )
48
42
  }
@@ -1,5 +1,5 @@
1
1
  import { Table, RowModel, Row, RowData } from '../types'
2
- import { memo } from '../utils'
2
+ import { getMemoOptions, memo } from '../utils'
3
3
  import { filterRows } from './filterRowsUtils'
4
4
 
5
5
  export function getFacetedRowModel<TData extends RowData>(): (
@@ -39,12 +39,6 @@ export function getFacetedRowModel<TData extends RowData>(): (
39
39
 
40
40
  return filterRows(preRowModel.rows, filterRowsImpl, table)
41
41
  },
42
- {
43
- key:
44
- process.env.NODE_ENV === 'development' &&
45
- 'getFacetedRowModel_' + columnId,
46
- debug: () => table.options.debugAll ?? table.options.debugTable,
47
- onChange: () => {},
48
- }
42
+ getMemoOptions(table.options, 'debugTable', 'getFacetedRowModel')
49
43
  )
50
44
  }
@@ -1,5 +1,5 @@
1
1
  import { Table, RowData } from '../types'
2
- import { memo } from '../utils'
2
+ import { getMemoOptions, memo } from '../utils'
3
3
 
4
4
  export function getFacetedUniqueValues<TData extends RowData>(): (
5
5
  table: Table<TData>,
@@ -33,12 +33,10 @@ export function getFacetedUniqueValues<TData extends RowData>(): (
33
33
 
34
34
  return facetedUniqueValues
35
35
  },
36
- {
37
- key:
38
- process.env.NODE_ENV === 'development' &&
39
- 'getFacetedUniqueValues_' + columnId,
40
- debug: () => table.options.debugAll ?? table.options.debugTable,
41
- onChange: () => {},
42
- }
36
+ getMemoOptions(
37
+ table.options,
38
+ 'debugTable',
39
+ `getFacetedUniqueValues_${columnId}`
40
+ )
43
41
  )
44
42
  }
@@ -1,6 +1,6 @@
1
1
  import { ResolvedColumnFilter } from '../features/Filters'
2
2
  import { Table, RowModel, Row, RowData } from '../types'
3
- import { memo } from '../utils'
3
+ import { getMemoOptions, memo } from '../utils'
4
4
  import { filterRows } from './filterRowsUtils'
5
5
 
6
6
  export function getFilteredRowModel<TData extends RowData>(): (
@@ -144,12 +144,8 @@ export function getFilteredRowModel<TData extends RowData>(): (
144
144
  // Filter final rows using all of the active filters
145
145
  return filterRows(rowModel.rows, filterRowsImpl, table)
146
146
  },
147
- {
148
- key: process.env.NODE_ENV === 'development' && 'getFilteredRowModel',
149
- debug: () => table.options.debugAll ?? table.options.debugTable,
150
- onChange: () => {
151
- table._autoResetPageIndex()
152
- },
153
- }
147
+ getMemoOptions(table.options, 'debugTable', 'getFilteredRowModel', () =>
148
+ table._autoResetPageIndex()
149
+ )
154
150
  )
155
151
  }
@@ -1,6 +1,6 @@
1
1
  import { createRow } from '../core/row'
2
2
  import { Table, Row, RowModel, RowData } from '../types'
3
- import { flattenBy, memo } from '../utils'
3
+ import { flattenBy, getMemoOptions, memo } from '../utils'
4
4
 
5
5
  export function getGroupedRowModel<TData extends RowData>(): (
6
6
  table: Table<TData>
@@ -156,16 +156,12 @@ export function getGroupedRowModel<TData extends RowData>(): (
156
156
  rowsById: groupedRowsById,
157
157
  }
158
158
  },
159
- {
160
- key: process.env.NODE_ENV === 'development' && 'getGroupedRowModel',
161
- debug: () => table.options.debugAll ?? table.options.debugTable,
162
- onChange: () => {
163
- table._queue(() => {
164
- table._autoResetExpanded()
165
- table._autoResetPageIndex()
166
- })
167
- },
168
- }
159
+ getMemoOptions(table.options, 'debugTable', 'getGroupedRowModel', () => {
160
+ table._queue(() => {
161
+ table._autoResetExpanded()
162
+ table._autoResetPageIndex()
163
+ })
164
+ })
169
165
  )
170
166
  }
171
167
 
@@ -1,5 +1,5 @@
1
1
  import { Table, RowModel, Row, RowData } from '../types'
2
- import { memo } from '../utils'
2
+ import { getMemoOptions, memo } from '../utils'
3
3
  import { expandRows } from './getExpandedRowModel'
4
4
 
5
5
  export function getPaginationRowModel<TData extends RowData>(opts?: {
@@ -55,9 +55,6 @@ export function getPaginationRowModel<TData extends RowData>(opts?: {
55
55
 
56
56
  return paginatedRowModel
57
57
  },
58
- {
59
- key: process.env.NODE_ENV === 'development' && 'getPaginationRowModel',
60
- debug: () => table.options.debugAll ?? table.options.debugTable,
61
- }
58
+ getMemoOptions(table.options, 'debugTable', 'getPaginationRowModel')
62
59
  )
63
60
  }
@@ -1,6 +1,6 @@
1
1
  import { Table, Row, RowModel, RowData } from '../types'
2
2
  import { SortingFn } from '../features/Sorting'
3
- import { memo } from '../utils'
3
+ import { getMemoOptions, memo } from '../utils'
4
4
 
5
5
  export function getSortedRowModel<TData extends RowData>(): (
6
6
  table: Table<TData>
@@ -111,12 +111,8 @@ export function getSortedRowModel<TData extends RowData>(): (
111
111
  rowsById: rowModel.rowsById,
112
112
  }
113
113
  },
114
- {
115
- key: process.env.NODE_ENV === 'development' && 'getSortedRowModel',
116
- debug: () => table.options.debugAll ?? table.options.debugTable,
117
- onChange: () => {
118
- table._autoResetPageIndex()
119
- },
120
- }
114
+ getMemoOptions(table.options, 'debugTable', 'getSortedRowModel', () =>
115
+ table._autoResetPageIndex()
116
+ )
121
117
  )
122
118
  }
package/src/utils.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { TableState, Updater } from './types'
1
+ import { TableOptionsResolved, TableState, Updater } from './types'
2
2
 
3
3
  export type PartialKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
4
4
  export type RequiredKeys<T, K extends keyof T> = Omit<T, K> &
@@ -134,23 +134,23 @@ export function flattenBy<TNode>(
134
134
  return flat
135
135
  }
136
136
 
137
- export function memo<TDeps extends readonly any[], TResult>(
138
- getDeps: () => [...TDeps],
137
+ export function memo<TDeps extends readonly any[], TDepArgs, TResult>(
138
+ getDeps: (depArgs?: TDepArgs) => [...TDeps],
139
139
  fn: (...args: NoInfer<[...TDeps]>) => TResult,
140
140
  opts: {
141
141
  key: any
142
142
  debug?: () => any
143
143
  onChange?: (result: TResult) => void
144
144
  }
145
- ): () => TResult {
145
+ ): (depArgs?: TDepArgs) => TResult {
146
146
  let deps: any[] = []
147
147
  let result: TResult | undefined
148
148
 
149
- return () => {
149
+ return depArgs => {
150
150
  let depTime: number
151
151
  if (opts.key && opts.debug) depTime = Date.now()
152
152
 
153
- const newDeps = getDeps()
153
+ const newDeps = getDeps(depArgs)
154
154
 
155
155
  const depsChanged =
156
156
  newDeps.length !== deps.length ||
@@ -199,3 +199,22 @@ export function memo<TDeps extends readonly any[], TResult>(
199
199
  return result!
200
200
  }
201
201
  }
202
+
203
+ export function getMemoOptions(
204
+ tableOptions: Partial<TableOptionsResolved<any>>,
205
+ debugLevel:
206
+ | 'debugAll'
207
+ | 'debugCells'
208
+ | 'debugTable'
209
+ | 'debugColumns'
210
+ | 'debugRows'
211
+ | 'debugHeaders',
212
+ key: string,
213
+ onChange?: (result: any) => void
214
+ ) {
215
+ return {
216
+ debug: () => tableOptions?.debugAll ?? tableOptions[debugLevel],
217
+ key: process.env.NODE_ENV === 'development' && key,
218
+ onChange,
219
+ }
220
+ }