@tanstack/table-core 8.13.2 → 8.15.1

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 (108) hide show
  1. package/build/lib/aggregationFns.d.ts +1 -1
  2. package/build/lib/aggregationFns.js.map +1 -1
  3. package/build/lib/core/column.js +1 -1
  4. package/build/lib/core/column.js.map +1 -1
  5. package/build/lib/core/headers.d.ts +1 -2
  6. package/build/lib/core/headers.js.map +1 -1
  7. package/build/lib/core/row.d.ts +1 -1
  8. package/build/lib/core/row.js.map +1 -1
  9. package/build/lib/core/table.d.ts +7 -11
  10. package/build/lib/core/table.js +24 -13
  11. package/build/lib/core/table.js.map +1 -1
  12. package/build/lib/features/ColumnFaceting.d.ts +34 -0
  13. package/build/lib/features/ColumnFaceting.js +42 -0
  14. package/build/lib/features/ColumnFaceting.js.map +1 -0
  15. package/build/lib/features/ColumnFiltering.d.ts +194 -0
  16. package/build/lib/features/{Filters.js → ColumnFiltering.js} +8 -83
  17. package/build/lib/features/ColumnFiltering.js.map +1 -0
  18. package/build/lib/features/{Grouping.d.ts → ColumnGrouping.d.ts} +2 -3
  19. package/build/lib/features/{Grouping.js → ColumnGrouping.js} +3 -3
  20. package/build/lib/features/ColumnGrouping.js.map +1 -0
  21. package/build/lib/features/{Ordering.d.ts → ColumnOrdering.d.ts} +2 -3
  22. package/build/lib/features/{Ordering.js → ColumnOrdering.js} +9 -9
  23. package/build/lib/features/ColumnOrdering.js.map +1 -0
  24. package/build/lib/features/ColumnPinning.d.ts +126 -0
  25. package/build/lib/features/{Pinning.js → ColumnPinning.js} +4 -115
  26. package/build/lib/features/ColumnPinning.js.map +1 -0
  27. package/build/lib/features/ColumnSizing.d.ts +2 -3
  28. package/build/lib/features/ColumnSizing.js +3 -3
  29. package/build/lib/features/ColumnSizing.js.map +1 -1
  30. package/build/lib/features/{Visibility.d.ts → ColumnVisibility.d.ts} +2 -3
  31. package/build/lib/features/{Visibility.js → ColumnVisibility.js} +3 -3
  32. package/build/lib/features/ColumnVisibility.js.map +1 -0
  33. package/build/lib/features/GlobalFaceting.d.ts +26 -0
  34. package/build/lib/features/GlobalFaceting.js +42 -0
  35. package/build/lib/features/GlobalFaceting.js.map +1 -0
  36. package/build/lib/features/GlobalFiltering.d.ts +79 -0
  37. package/build/lib/features/GlobalFiltering.js +63 -0
  38. package/build/lib/features/GlobalFiltering.js.map +1 -0
  39. package/build/lib/features/{Expanding.d.ts → RowExpanding.d.ts} +2 -3
  40. package/build/lib/features/{Expanding.js → RowExpanding.js} +3 -3
  41. package/build/lib/features/RowExpanding.js.map +1 -0
  42. package/build/lib/features/{Pagination.d.ts → RowPagination.d.ts} +2 -3
  43. package/build/lib/features/{Pagination.js → RowPagination.js} +3 -3
  44. package/build/lib/features/RowPagination.js.map +1 -0
  45. package/build/lib/features/RowPinning.d.ts +98 -0
  46. package/build/lib/features/RowPinning.js +145 -0
  47. package/build/lib/features/RowPinning.js.map +1 -0
  48. package/build/lib/features/RowSelection.d.ts +1 -2
  49. package/build/lib/features/RowSelection.js.map +1 -1
  50. package/build/lib/features/{Sorting.d.ts → RowSorting.d.ts} +5 -3
  51. package/build/lib/features/{Sorting.js → RowSorting.js} +3 -3
  52. package/build/lib/features/RowSorting.js.map +1 -0
  53. package/build/lib/filterFns.d.ts +1 -1
  54. package/build/lib/filterFns.js.map +1 -1
  55. package/build/lib/index.d.ts +22 -18
  56. package/build/lib/index.esm.js +1509 -1457
  57. package/build/lib/index.esm.js.map +1 -1
  58. package/build/lib/index.js +49 -41
  59. package/build/lib/index.js.map +1 -1
  60. package/build/lib/index.mjs +1509 -1457
  61. package/build/lib/index.mjs.map +1 -1
  62. package/build/lib/sortingFns.d.ts +1 -1
  63. package/build/lib/sortingFns.js.map +1 -1
  64. package/build/lib/types.d.ts +32 -17
  65. package/build/lib/utils/getFilteredRowModel.js.map +1 -1
  66. package/build/lib/utils/getSortedRowModel.js.map +1 -1
  67. package/build/umd/index.development.js +1520 -1464
  68. package/build/umd/index.development.js.map +1 -1
  69. package/build/umd/index.production.js +1 -1
  70. package/build/umd/index.production.js.map +1 -1
  71. package/package.json +1 -1
  72. package/src/aggregationFns.ts +1 -1
  73. package/src/core/column.ts +2 -2
  74. package/src/core/headers.ts +9 -3
  75. package/src/core/row.ts +1 -1
  76. package/src/core/table.ts +42 -32
  77. package/src/features/ColumnFaceting.ts +84 -0
  78. package/src/features/ColumnFiltering.ts +429 -0
  79. package/src/features/{Grouping.ts → ColumnGrouping.ts} +6 -6
  80. package/src/features/{Ordering.ts → ColumnOrdering.ts} +11 -5
  81. package/src/features/ColumnPinning.ts +336 -0
  82. package/src/features/ColumnSizing.ts +10 -3
  83. package/src/features/{Visibility.ts → ColumnVisibility.ts} +2 -2
  84. package/src/features/GlobalFaceting.ts +66 -0
  85. package/src/features/GlobalFiltering.ts +162 -0
  86. package/src/features/{Expanding.ts → RowExpanding.ts} +9 -3
  87. package/src/features/{Pagination.ts → RowPagination.ts} +9 -3
  88. package/src/features/RowPinning.ts +273 -0
  89. package/src/features/RowSelection.ts +9 -2
  90. package/src/features/{Sorting.ts → RowSorting.ts} +5 -2
  91. package/src/filterFns.ts +1 -1
  92. package/src/index.ts +31 -18
  93. package/src/sortingFns.ts +1 -1
  94. package/src/types.ts +66 -25
  95. package/src/utils/getFilteredRowModel.ts +1 -1
  96. package/src/utils/getSortedRowModel.ts +1 -1
  97. package/build/lib/features/Expanding.js.map +0 -1
  98. package/build/lib/features/Filters.d.ts +0 -297
  99. package/build/lib/features/Filters.js.map +0 -1
  100. package/build/lib/features/Grouping.js.map +0 -1
  101. package/build/lib/features/Ordering.js.map +0 -1
  102. package/build/lib/features/Pagination.js.map +0 -1
  103. package/build/lib/features/Pinning.d.ts +0 -222
  104. package/build/lib/features/Pinning.js.map +0 -1
  105. package/build/lib/features/Sorting.js.map +0 -1
  106. package/build/lib/features/Visibility.js.map +0 -1
  107. package/src/features/Filters.ts +0 -664
  108. package/src/features/Pinning.ts +0 -573
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/table-core",
3
- "version": "8.13.2",
3
+ "version": "8.15.1",
4
4
  "description": "Headless UI for building powerful tables & datagrids for TS/JS.",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -1,4 +1,4 @@
1
- import { AggregationFn } from './features/Grouping'
1
+ import { AggregationFn } from './features/ColumnGrouping'
2
2
  import { isNumberArray } from './utils'
3
3
 
4
4
  const sum: AggregationFn<any> = (columnId, _leafRows, childRows) => {
@@ -157,9 +157,9 @@ export function createColumn<TData extends RowData, TValue>(
157
157
  }
158
158
 
159
159
  for (const feature of table._features) {
160
- feature.createColumn?.(column, table)
160
+ feature.createColumn?.(column as Column<TData, TValue>, table)
161
161
  }
162
162
 
163
- // Yes, we have to convert table to uknown, because we know more than the compiler here.
163
+ // Yes, we have to convert table to unknown, because we know more than the compiler here.
164
164
  return column as Column<TData, TValue>
165
165
  }
@@ -1,6 +1,12 @@
1
- import { RowData, Column, Header, HeaderGroup, Table } from '../types'
1
+ import {
2
+ RowData,
3
+ Column,
4
+ Header,
5
+ HeaderGroup,
6
+ Table,
7
+ TableFeature,
8
+ } from '../types'
2
9
  import { getMemoOptions, memo } from '../utils'
3
- import { TableFeature } from './table'
4
10
 
5
11
  const debug = 'debugHeaders'
6
12
 
@@ -250,7 +256,7 @@ function createHeader<TData extends RowData, TValue>(
250
256
  }
251
257
 
252
258
  table._features.forEach(feature => {
253
- feature.createHeader?.(header, table)
259
+ feature.createHeader?.(header as Header<TData, TValue>, table)
254
260
  })
255
261
 
256
262
  return header as Header<TData, TValue>
package/src/core/row.ts CHANGED
@@ -194,7 +194,7 @@ export const createRow = <TData extends RowData>(
194
194
 
195
195
  for (let i = 0; i < table._features.length; i++) {
196
196
  const feature = table._features[i]
197
- feature?.createRow?.(row, table)
197
+ feature?.createRow?.(row as Row<TData>, table)
198
198
  }
199
199
 
200
200
  return row as Row<TData>
package/src/core/table.ts CHANGED
@@ -15,6 +15,7 @@ import {
15
15
  TableMeta,
16
16
  ColumnDefResolved,
17
17
  GroupColumnDef,
18
+ TableFeature,
18
19
  } from '../types'
19
20
 
20
21
  //
@@ -22,38 +23,35 @@ import { createColumn } from './column'
22
23
  import { Headers } from './headers'
23
24
  //
24
25
 
26
+ import { ColumnFaceting } from '../features/ColumnFaceting'
27
+ import { ColumnFiltering } from '../features/ColumnFiltering'
28
+ import { ColumnGrouping } from '../features/ColumnGrouping'
29
+ import { ColumnOrdering } from '../features/ColumnOrdering'
30
+ import { ColumnPinning } from '../features/ColumnPinning'
25
31
  import { ColumnSizing } from '../features/ColumnSizing'
26
- import { Expanding } from '../features/Expanding'
27
- import { Filters } from '../features/Filters'
28
- import { Grouping } from '../features/Grouping'
29
- import { Ordering } from '../features/Ordering'
30
- import { Pagination } from '../features/Pagination'
31
- import { Pinning } from '../features/Pinning'
32
+ import { ColumnVisibility } from '../features/ColumnVisibility'
33
+ import { GlobalFaceting } from '../features/GlobalFaceting'
34
+ import { GlobalFiltering } from '../features/GlobalFiltering'
35
+ import { RowExpanding } from '../features/RowExpanding'
36
+ import { RowPagination } from '../features/RowPagination'
37
+ import { RowPinning } from '../features/RowPinning'
32
38
  import { RowSelection } from '../features/RowSelection'
33
- import { Sorting } from '../features/Sorting'
34
- import { Visibility } from '../features/Visibility'
35
-
36
- export interface TableFeature {
37
- createCell?: (cell: any, column: any, row: any, table: any) => any
38
- createColumn?: (column: any, table: any) => any
39
- createHeader?: (column: any, table: any) => any
40
- createRow?: (row: any, table: any) => any
41
- createTable?: (table: any) => any
42
- getDefaultColumnDef?: () => any
43
- getDefaultOptions?: (table: any) => any
44
- getInitialState?: (initialState?: InitialTableState) => any
45
- }
39
+ import { RowSorting } from '../features/RowSorting'
46
40
 
47
- const features = [
41
+ const builtInFeatures = [
48
42
  Headers,
49
- Visibility,
50
- Ordering,
51
- Pinning,
52
- Filters,
53
- Sorting,
54
- Grouping,
55
- Expanding,
56
- Pagination,
43
+ ColumnVisibility,
44
+ ColumnOrdering,
45
+ ColumnPinning,
46
+ ColumnFaceting,
47
+ ColumnFiltering,
48
+ GlobalFaceting, //depends on ColumnFaceting
49
+ GlobalFiltering, //depends on ColumnFiltering
50
+ RowSorting,
51
+ ColumnGrouping, //depends on RowSorting
52
+ RowExpanding,
53
+ RowPagination,
54
+ RowPinning,
57
55
  RowSelection,
58
56
  ColumnSizing,
59
57
  ] as const
@@ -63,6 +61,12 @@ const features = [
63
61
  export interface CoreTableState {}
64
62
 
65
63
  export interface CoreOptions<TData extends RowData> {
64
+ /**
65
+ * An array of extra features that you can add to the table instance.
66
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#_features)
67
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/tables)
68
+ */
69
+ _features?: TableFeature[]
66
70
  /**
67
71
  * Set this option to override any of the `autoReset...` feature options.
68
72
  * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#autoresetall)
@@ -279,11 +283,16 @@ export interface CoreInstance<TData extends RowData> {
279
283
  export function createTable<TData extends RowData>(
280
284
  options: TableOptionsResolved<TData>
281
285
  ): Table<TData> {
282
- if (options.debugAll || options.debugTable) {
286
+ if (
287
+ process.env.NODE_ENV !== 'production' &&
288
+ (options.debugAll || options.debugTable)
289
+ ) {
283
290
  console.info('Creating Table Instance...')
284
291
  }
285
292
 
286
- let table = { _features: features } as unknown as Table<TData>
293
+ const _features = [...builtInFeatures, ...(options._features ?? [])]
294
+
295
+ let table = { _features } as unknown as Table<TData>
287
296
 
288
297
  const defaultOptions = table._features.reduce((obj, feature) => {
289
298
  return Object.assign(obj, feature.getDefaultOptions?.(table))
@@ -308,14 +317,15 @@ export function createTable<TData extends RowData>(
308
317
  } as TableState
309
318
 
310
319
  table._features.forEach(feature => {
311
- initialState = feature.getInitialState?.(initialState) ?? initialState
320
+ initialState = (feature.getInitialState?.(initialState) ??
321
+ initialState) as TableState
312
322
  })
313
323
 
314
324
  const queued: (() => void)[] = []
315
325
  let queuedTimeout = false
316
326
 
317
327
  const coreInstance: CoreInstance<TData> = {
318
- _features: features,
328
+ _features,
319
329
  options: {
320
330
  ...defaultOptions,
321
331
  ...options,
@@ -0,0 +1,84 @@
1
+ import { RowModel } from '..'
2
+ import { Column, RowData, Table, TableFeature } from '../types'
3
+
4
+ export interface FacetedColumn<TData extends RowData> {
5
+ _getFacetedMinMaxValues?: () => undefined | [number, number]
6
+ _getFacetedRowModel?: () => RowModel<TData>
7
+ _getFacetedUniqueValues?: () => Map<any, number>
8
+ /**
9
+ * A function that **computes and returns** a min/max tuple derived from `column.getFacetedRowModel`. Useful for displaying faceted result values.
10
+ * > ⚠️ Requires that you pass a valid `getFacetedMinMaxValues` function to `options.getFacetedMinMaxValues`. A default implementation is provided via the exported `getFacetedMinMaxValues` function.
11
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-faceting#getfacetedminmaxvalues)
12
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-faceting)
13
+ */
14
+ getFacetedMinMaxValues: () => undefined | [number, number]
15
+ /**
16
+ * Returns the row model with all other column filters applied, excluding its own filter. Useful for displaying faceted result counts.
17
+ * > ⚠️ Requires that you pass a valid `getFacetedRowModel` function to `options.facetedRowModel`. A default implementation is provided via the exported `getFacetedRowModel` function.
18
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-faceting#getfacetedrowmodel)
19
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-faceting)
20
+ */
21
+ getFacetedRowModel: () => RowModel<TData>
22
+ /**
23
+ * A function that **computes and returns** a `Map` of unique values and their occurrences derived from `column.getFacetedRowModel`. Useful for displaying faceted result values.
24
+ * > ⚠️ Requires that you pass a valid `getFacetedUniqueValues` function to `options.getFacetedUniqueValues`. A default implementation is provided via the exported `getFacetedUniqueValues` function.
25
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-faceting#getfaceteduniquevalues)
26
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-faceting)
27
+ */
28
+ getFacetedUniqueValues: () => Map<any, number>
29
+ }
30
+
31
+ export interface FacetedOptions<TData extends RowData> {
32
+ getFacetedMinMaxValues?: (
33
+ table: Table<TData>,
34
+ columnId: string
35
+ ) => () => undefined | [number, number]
36
+ getFacetedRowModel?: (
37
+ table: Table<TData>,
38
+ columnId: string
39
+ ) => () => RowModel<TData>
40
+ getFacetedUniqueValues?: (
41
+ table: Table<TData>,
42
+ columnId: string
43
+ ) => () => Map<any, number>
44
+ }
45
+
46
+ //
47
+
48
+ export const ColumnFaceting: TableFeature = {
49
+ createColumn: <TData extends RowData>(
50
+ column: Column<TData, unknown>,
51
+ table: Table<TData>
52
+ ): void => {
53
+ column._getFacetedRowModel =
54
+ table.options.getFacetedRowModel &&
55
+ table.options.getFacetedRowModel(table, column.id)
56
+ column.getFacetedRowModel = () => {
57
+ if (!column._getFacetedRowModel) {
58
+ return table.getPreFilteredRowModel()
59
+ }
60
+
61
+ return column._getFacetedRowModel()
62
+ }
63
+ column._getFacetedUniqueValues =
64
+ table.options.getFacetedUniqueValues &&
65
+ table.options.getFacetedUniqueValues(table, column.id)
66
+ column.getFacetedUniqueValues = () => {
67
+ if (!column._getFacetedUniqueValues) {
68
+ return new Map()
69
+ }
70
+
71
+ return column._getFacetedUniqueValues()
72
+ }
73
+ column._getFacetedMinMaxValues =
74
+ table.options.getFacetedMinMaxValues &&
75
+ table.options.getFacetedMinMaxValues(table, column.id)
76
+ column.getFacetedMinMaxValues = () => {
77
+ if (!column._getFacetedMinMaxValues) {
78
+ return undefined
79
+ }
80
+
81
+ return column._getFacetedMinMaxValues()
82
+ }
83
+ },
84
+ }