@tanstack/table-core 8.11.1 → 8.11.3

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 (86) hide show
  1. package/LICENSE +21 -0
  2. package/build/lib/aggregationFns.js +9 -11
  3. package/build/lib/aggregationFns.js.map +1 -1
  4. package/build/lib/columnHelper.js +9 -11
  5. package/build/lib/columnHelper.js.map +1 -1
  6. package/build/lib/core/cell.js +9 -11
  7. package/build/lib/core/cell.js.map +1 -1
  8. package/build/lib/core/column.js +9 -11
  9. package/build/lib/core/column.js.map +1 -1
  10. package/build/lib/core/headers.js +9 -11
  11. package/build/lib/core/headers.js.map +1 -1
  12. package/build/lib/core/row.js +9 -11
  13. package/build/lib/core/row.js.map +1 -1
  14. package/build/lib/core/table.js +17 -15
  15. package/build/lib/core/table.js.map +1 -1
  16. package/build/lib/features/ColumnSizing.d.ts +1 -1
  17. package/build/lib/features/ColumnSizing.js +9 -11
  18. package/build/lib/features/ColumnSizing.js.map +1 -1
  19. package/build/lib/features/Expanding.js +9 -11
  20. package/build/lib/features/Expanding.js.map +1 -1
  21. package/build/lib/features/Filters.js +9 -11
  22. package/build/lib/features/Filters.js.map +1 -1
  23. package/build/lib/features/Grouping.js +9 -11
  24. package/build/lib/features/Grouping.js.map +1 -1
  25. package/build/lib/features/Ordering.js +9 -11
  26. package/build/lib/features/Ordering.js.map +1 -1
  27. package/build/lib/features/Pagination.js +9 -11
  28. package/build/lib/features/Pagination.js.map +1 -1
  29. package/build/lib/features/Pinning.js +9 -11
  30. package/build/lib/features/Pinning.js.map +1 -1
  31. package/build/lib/features/RowSelection.js +10 -12
  32. package/build/lib/features/RowSelection.js.map +1 -1
  33. package/build/lib/features/Sorting.js +9 -11
  34. package/build/lib/features/Sorting.js.map +1 -1
  35. package/build/lib/features/Visibility.js +9 -11
  36. package/build/lib/features/Visibility.js.map +1 -1
  37. package/build/lib/filterFns.js +9 -11
  38. package/build/lib/filterFns.js.map +1 -1
  39. package/build/lib/index.esm.js +18 -14
  40. package/build/lib/index.esm.js.map +1 -1
  41. package/build/lib/index.js +9 -11
  42. package/build/lib/index.js.map +1 -1
  43. package/build/lib/index.mjs +18 -14
  44. package/build/lib/index.mjs.map +1 -1
  45. package/build/lib/sortingFns.js +9 -11
  46. package/build/lib/sortingFns.js.map +1 -1
  47. package/build/lib/utils/filterRowsUtils.js +9 -11
  48. package/build/lib/utils/filterRowsUtils.js.map +1 -1
  49. package/build/lib/utils/getCoreRowModel.js +9 -11
  50. package/build/lib/utils/getCoreRowModel.js.map +1 -1
  51. package/build/lib/utils/getExpandedRowModel.js +9 -11
  52. package/build/lib/utils/getExpandedRowModel.js.map +1 -1
  53. package/build/lib/utils/getFacetedMinMaxValues.js +9 -11
  54. package/build/lib/utils/getFacetedMinMaxValues.js.map +1 -1
  55. package/build/lib/utils/getFacetedRowModel.js +9 -11
  56. package/build/lib/utils/getFacetedRowModel.js.map +1 -1
  57. package/build/lib/utils/getFacetedUniqueValues.js +9 -11
  58. package/build/lib/utils/getFacetedUniqueValues.js.map +1 -1
  59. package/build/lib/utils/getFilteredRowModel.js +9 -11
  60. package/build/lib/utils/getFilteredRowModel.js.map +1 -1
  61. package/build/lib/utils/getGroupedRowModel.js +9 -11
  62. package/build/lib/utils/getGroupedRowModel.js.map +1 -1
  63. package/build/lib/utils/getPaginationRowModel.js +9 -11
  64. package/build/lib/utils/getPaginationRowModel.js.map +1 -1
  65. package/build/lib/utils/getSortedRowModel.js +9 -11
  66. package/build/lib/utils/getSortedRowModel.js.map +1 -1
  67. package/build/lib/utils.js +9 -11
  68. package/build/lib/utils.js.map +1 -1
  69. package/build/umd/index.development.js +17 -15
  70. package/build/umd/index.development.js.map +1 -1
  71. package/build/umd/index.production.js +10 -10
  72. package/build/umd/index.production.js.map +1 -1
  73. package/package.json +13 -3
  74. package/src/aggregationFns.ts +0 -0
  75. package/src/columnHelper.ts +3 -3
  76. package/src/core/row.ts +2 -1
  77. package/src/core/table.ts +10 -5
  78. package/src/features/ColumnSizing.ts +11 -6
  79. package/src/features/Filters.ts +9 -9
  80. package/src/features/Grouping.ts +7 -5
  81. package/src/features/RowSelection.ts +1 -1
  82. package/src/features/Sorting.ts +3 -3
  83. package/src/index.ts +0 -0
  84. package/src/types.ts +4 -2
  85. package/src/utils/getSortedRowModel.ts +5 -5
  86. package/src/utils.ts +14 -14
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tanstack/table-core",
3
3
  "author": "Tanner Linsley",
4
- "version": "8.11.1",
4
+ "version": "8.11.3",
5
5
  "description": "Headless UI for building powerful tables & datagrids for TS/JS.",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/tanstack/table#readme",
@@ -24,6 +24,7 @@
24
24
  "type": "github",
25
25
  "url": "https://github.com/sponsors/tannerlinsley"
26
26
  },
27
+ "type": "commonjs",
27
28
  "module": "build/lib/index.esm.js",
28
29
  "main": "build/lib/index.js",
29
30
  "types": "build/lib/index.d.ts",
@@ -43,5 +44,14 @@
43
44
  "build/lib/*",
44
45
  "build/umd/*",
45
46
  "src"
46
- ]
47
- }
47
+ ],
48
+ "scripts": {
49
+ "clean": "rimraf ./build",
50
+ "test:lib": "vitest",
51
+ "test:lib:dev": "pnpm test:lib --watch",
52
+ "test:types": "tsc --noEmit",
53
+ "build": "pnpm build:rollup && pnpm build:types",
54
+ "build:rollup": "rollup --config rollup.config.mjs",
55
+ "build:types": "tsc --emitDeclarationOnly"
56
+ }
57
+ }
File without changes
@@ -6,7 +6,7 @@ import {
6
6
  IdentifiedColumnDef,
7
7
  RowData,
8
8
  } from './types'
9
- import { DeepKeys, DeepValue, RequiredKeys } from './utils'
9
+ import { DeepKeys, DeepValue } from './utils'
10
10
 
11
11
  // type Person = {
12
12
  // firstName: string
@@ -55,8 +55,8 @@ export type ColumnHelper<TData extends RowData> = {
55
55
  TValue extends TAccessor extends AccessorFn<TData, infer TReturn>
56
56
  ? TReturn
57
57
  : TAccessor extends DeepKeys<TData>
58
- ? DeepValue<TData, TAccessor>
59
- : never,
58
+ ? DeepValue<TData, TAccessor>
59
+ : never,
60
60
  >(
61
61
  accessor: TAccessor,
62
62
  column: TAccessor extends AccessorFn<TData>
package/src/core/row.ts CHANGED
@@ -154,7 +154,8 @@ export const createRow = <TData extends RowData>(
154
154
  row.getValue(columnId) ?? table.options.renderFallbackValue,
155
155
  subRows: subRows ?? [],
156
156
  getLeafRows: () => flattenBy(row.subRows, d => d.subRows),
157
- getParentRow: () => (row.parentId ? table.getRow(row.parentId, true) : undefined),
157
+ getParentRow: () =>
158
+ row.parentId ? table.getRow(row.parentId, true) : undefined,
158
159
  getParentRows: () => {
159
160
  let parentRows: Row<TData>[] = []
160
161
  let currentRow = row
package/src/core/table.ts CHANGED
@@ -374,15 +374,20 @@ export function createTable<TData extends RowData>(
374
374
  getRowModel: () => {
375
375
  return table.getPaginationRowModel()
376
376
  },
377
+ //in next version, we should just pass in the row model as the optional 2nd arg
377
378
  getRow: (id: string, searchAll?: boolean) => {
378
- const row = (searchAll ? table.getCoreRowModel() : table.getRowModel())
379
- .rowsById[id]
379
+ let row = (
380
+ searchAll ? table.getPrePaginationRowModel() : table.getRowModel()
381
+ ).rowsById[id]
380
382
 
381
383
  if (!row) {
382
- if (process.env.NODE_ENV !== 'production') {
383
- throw new Error(`getRow expected an ID, but got ${id}`)
384
+ row = table.getCoreRowModel().rowsById[id]
385
+ if (!row) {
386
+ if (process.env.NODE_ENV !== 'production') {
387
+ throw new Error(`getRow could not find row with ID: ${id}`)
388
+ }
389
+ throw new Error()
384
390
  }
385
- throw new Error()
386
391
  }
387
392
 
388
393
  return row
@@ -40,7 +40,7 @@ export interface ColumnSizingOptions {
40
40
  enableColumnResizing?: boolean
41
41
  /**
42
42
  * Enables or disables right-to-left support for resizing the column. defaults to 'ltr'.
43
- * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-sizing#rtl)
43
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-sizing#columnResizeDirection)
44
44
  * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-sizing)
45
45
  */
46
46
  columnResizeDirection?: ColumnResizeDirection
@@ -60,7 +60,10 @@ export interface ColumnSizingOptions {
60
60
 
61
61
  export type ColumnSizingDefaultOptions = Pick<
62
62
  ColumnSizingOptions,
63
- 'columnResizeMode' | 'onColumnSizingChange' | 'onColumnSizingInfoChange' | 'columnResizeDirection'
63
+ | 'columnResizeMode'
64
+ | 'onColumnSizingChange'
65
+ | 'onColumnSizingInfoChange'
66
+ | 'columnResizeDirection'
64
67
  >
65
68
 
66
69
  export interface ColumnSizingInstance {
@@ -258,8 +261,8 @@ export const ColumnSizing: TableFeature = {
258
261
  const columns = !position
259
262
  ? table.getVisibleLeafColumns()
260
263
  : position === 'left'
261
- ? table.getLeftVisibleLeafColumns()
262
- : table.getRightVisibleLeafColumns()
264
+ ? table.getLeftVisibleLeafColumns()
265
+ : table.getRightVisibleLeafColumns()
263
266
 
264
267
  const index = columns.findIndex(d => d.id === column.id)
265
268
 
@@ -355,8 +358,10 @@ export const ColumnSizing: TableFeature = {
355
358
  }
356
359
 
357
360
  table.setColumnSizingInfo(old => {
358
- const deltaDirection = table.options.columnResizeDirection === 'rtl' ? -1 : 1
359
- const deltaOffset = (clientXPos - (old?.startOffset ?? 0)) * deltaDirection
361
+ const deltaDirection =
362
+ table.options.columnResizeDirection === 'rtl' ? -1 : 1
363
+ const deltaOffset =
364
+ (clientXPos - (old?.startOffset ?? 0)) * deltaDirection
360
365
  const deltaPercentage = Math.max(
361
366
  deltaOffset / (old?.startSize ?? 0),
362
367
  -0.999999
@@ -234,7 +234,7 @@ interface FiltersOptionsBase<TData extends RowData> {
234
234
  enableGlobalFilter?: boolean
235
235
  /**
236
236
  * If provided, this function will be called with the column and should return `true` or `false` to indicate whether this column should be used for global filtering.
237
- *
237
+ *
238
238
  * This is useful if the column can contain data that is not `string` or `number` (i.e. `undefined`).
239
239
  * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/filters#getcolumncanglobalfilter)
240
240
  * @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
@@ -434,10 +434,10 @@ export const Filters: TableFeature = {
434
434
  return isFunction(column.columnDef.filterFn)
435
435
  ? column.columnDef.filterFn
436
436
  : column.columnDef.filterFn === 'auto'
437
- ? column.getAutoFilterFn()
438
- : // @ts-ignore
439
- table.options.filterFns?.[column.columnDef.filterFn as string] ??
440
- filterFns[column.columnDef.filterFn as BuiltInFilterFn]
437
+ ? column.getAutoFilterFn()
438
+ : // @ts-ignore
439
+ table.options.filterFns?.[column.columnDef.filterFn as string] ??
440
+ filterFns[column.columnDef.filterFn as BuiltInFilterFn]
441
441
  }
442
442
  column.getCanFilter = () => {
443
443
  return (
@@ -556,10 +556,10 @@ export const Filters: TableFeature = {
556
556
  return isFunction(globalFilterFn)
557
557
  ? globalFilterFn
558
558
  : globalFilterFn === 'auto'
559
- ? table.getGlobalAutoFilterFn()
560
- : // @ts-ignore
561
- table.options.filterFns?.[globalFilterFn as string] ??
562
- filterFns[globalFilterFn as BuiltInFilterFn]
559
+ ? table.getGlobalAutoFilterFn()
560
+ : // @ts-ignore
561
+ table.options.filterFns?.[globalFilterFn as string] ??
562
+ filterFns[globalFilterFn as BuiltInFilterFn]
563
563
  }
564
564
 
565
565
  table.setColumnFilters = (updater: Updater<ColumnFiltersState>) => {
@@ -326,11 +326,13 @@ export const Grouping: TableFeature = {
326
326
  return isFunction(column.columnDef.aggregationFn)
327
327
  ? column.columnDef.aggregationFn
328
328
  : column.columnDef.aggregationFn === 'auto'
329
- ? column.getAutoAggregationFn()
330
- : table.options.aggregationFns?.[
331
- column.columnDef.aggregationFn as string
332
- ] ??
333
- aggregationFns[column.columnDef.aggregationFn as BuiltInAggregationFn]
329
+ ? column.getAutoAggregationFn()
330
+ : table.options.aggregationFns?.[
331
+ column.columnDef.aggregationFn as string
332
+ ] ??
333
+ aggregationFns[
334
+ column.columnDef.aggregationFn as BuiltInAggregationFn
335
+ ]
334
336
  }
335
337
  },
336
338
 
@@ -556,7 +556,7 @@ const mutateRowIsSelected = <TData extends RowData>(
556
556
  includeChildren: boolean,
557
557
  table: Table<TData>
558
558
  ) => {
559
- const row = table.getRow(id)
559
+ const row = table.getRow(id, true)
560
560
 
561
561
  // const isGrouped = row.getIsGrouped()
562
562
 
@@ -348,9 +348,9 @@ export const Sorting: TableFeature = {
348
348
  return isFunction(column.columnDef.sortingFn)
349
349
  ? column.columnDef.sortingFn
350
350
  : column.columnDef.sortingFn === 'auto'
351
- ? column.getAutoSortingFn()
352
- : table.options.sortingFns?.[column.columnDef.sortingFn as string] ??
353
- sortingFns[column.columnDef.sortingFn as BuiltInSortingFn]
351
+ ? column.getAutoSortingFn()
352
+ : table.options.sortingFns?.[column.columnDef.sortingFn as string] ??
353
+ sortingFns[column.columnDef.sortingFn as BuiltInSortingFn]
354
354
  }
355
355
  column.toggleSorting = (desc, multi) => {
356
356
  // if (column.columns.length) {
package/src/index.ts CHANGED
File without changes
package/src/types.ts CHANGED
@@ -265,8 +265,10 @@ export type AccessorFnColumnDef<
265
265
  TValue = unknown,
266
266
  > = AccessorFnColumnDefBase<TData, TValue> & ColumnIdentifiers<TData, TValue>
267
267
 
268
- export interface AccessorKeyColumnDefBase<TData extends RowData, TValue = unknown>
269
- extends ColumnDefBase<TData, TValue> {
268
+ export interface AccessorKeyColumnDefBase<
269
+ TData extends RowData,
270
+ TValue = unknown,
271
+ > extends ColumnDefBase<TData, TValue> {
270
272
  id?: string
271
273
  accessorKey: (string & {}) | keyof TData
272
274
  }
@@ -18,8 +18,8 @@ export function getSortedRowModel<TData extends RowData>(): (
18
18
  const sortedFlatRows: Row<TData>[] = []
19
19
 
20
20
  // Filter out sortings that correspond to non existing columns
21
- const availableSorting = sortingState.filter(sort =>
22
- table.getColumn(sort.id)?.getCanSort()
21
+ const availableSorting = sortingState.filter(
22
+ sort => table.getColumn(sort.id)?.getCanSort()
23
23
  )
24
24
 
25
25
  const columnInfoById: Record<
@@ -45,7 +45,7 @@ export function getSortedRowModel<TData extends RowData>(): (
45
45
  const sortData = (rows: Row<TData>[]) => {
46
46
  // This will also perform a stable sorting using the row index
47
47
  // if needed.
48
- const sortedData = rows.map(row => ({...row}))
48
+ const sortedData = rows.map(row => ({ ...row }))
49
49
 
50
50
  sortedData.sort((rowA, rowB) => {
51
51
  for (let i = 0; i < availableSorting.length; i += 1) {
@@ -68,8 +68,8 @@ export function getSortedRowModel<TData extends RowData>(): (
68
68
  aUndefined && bUndefined
69
69
  ? 0
70
70
  : aUndefined
71
- ? columnInfo.sortUndefined
72
- : -columnInfo.sortUndefined
71
+ ? columnInfo.sortUndefined
72
+ : -columnInfo.sortUndefined
73
73
  }
74
74
  }
75
75
 
package/src/utils.ts CHANGED
@@ -40,24 +40,24 @@ type AllowedIndexes<
40
40
  > = Tuple extends readonly []
41
41
  ? Keys
42
42
  : Tuple extends readonly [infer _, ...infer Tail]
43
- ? AllowedIndexes<Tail, Keys | Tail['length']>
44
- : Keys
43
+ ? AllowedIndexes<Tail, Keys | Tail['length']>
44
+ : Keys
45
45
 
46
46
  export type DeepKeys<T, TDepth extends any[] = []> = TDepth['length'] extends 5
47
47
  ? never
48
48
  : unknown extends T
49
- ? string
50
- : object extends T
51
- ? string
52
- : T extends readonly any[] & IsTuple<T>
53
- ? AllowedIndexes<T> | DeepKeysPrefix<T, AllowedIndexes<T>, TDepth>
54
- : T extends any[]
55
- ? DeepKeys<T[number], [...TDepth, any]>
56
- : T extends Date
57
- ? never
58
- : T extends object
59
- ? (keyof T & string) | DeepKeysPrefix<T, keyof T, TDepth>
60
- : never
49
+ ? string
50
+ : object extends T
51
+ ? string
52
+ : T extends readonly any[] & IsTuple<T>
53
+ ? AllowedIndexes<T> | DeepKeysPrefix<T, AllowedIndexes<T>, TDepth>
54
+ : T extends any[]
55
+ ? DeepKeys<T[number], [...TDepth, any]>
56
+ : T extends Date
57
+ ? never
58
+ : T extends object
59
+ ? (keyof T & string) | DeepKeysPrefix<T, keyof T, TDepth>
60
+ : never
61
61
 
62
62
  type DeepKeysPrefix<
63
63
  T,