@tanstack/table-core 8.13.2 → 8.14.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 (101) 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.js.map +1 -1
  8. package/build/lib/core/table.d.ts +7 -11
  9. package/build/lib/core/table.js +21 -13
  10. package/build/lib/core/table.js.map +1 -1
  11. package/build/lib/features/ColumnFaceting.d.ts +34 -0
  12. package/build/lib/features/ColumnFaceting.js +42 -0
  13. package/build/lib/features/ColumnFaceting.js.map +1 -0
  14. package/build/lib/features/{Filters.d.ts → ColumnFiltering.d.ts} +29 -132
  15. package/build/lib/features/{Filters.js → ColumnFiltering.js} +8 -83
  16. package/build/lib/features/ColumnFiltering.js.map +1 -0
  17. package/build/lib/features/{Grouping.d.ts → ColumnGrouping.d.ts} +2 -3
  18. package/build/lib/features/{Grouping.js → ColumnGrouping.js} +3 -3
  19. package/build/lib/features/ColumnGrouping.js.map +1 -0
  20. package/build/lib/features/{Ordering.d.ts → ColumnOrdering.d.ts} +2 -3
  21. package/build/lib/features/{Ordering.js → ColumnOrdering.js} +9 -9
  22. package/build/lib/features/ColumnOrdering.js.map +1 -0
  23. package/build/lib/features/ColumnPinning.d.ts +126 -0
  24. package/build/lib/features/{Pinning.js → ColumnPinning.js} +4 -115
  25. package/build/lib/features/ColumnPinning.js.map +1 -0
  26. package/build/lib/features/ColumnSizing.d.ts +2 -3
  27. package/build/lib/features/ColumnSizing.js +3 -3
  28. package/build/lib/features/ColumnSizing.js.map +1 -1
  29. package/build/lib/features/{Visibility.d.ts → ColumnVisibility.d.ts} +2 -3
  30. package/build/lib/features/{Visibility.js → ColumnVisibility.js} +3 -3
  31. package/build/lib/features/ColumnVisibility.js.map +1 -0
  32. package/build/lib/features/GlobalFiltering.d.ts +100 -0
  33. package/build/lib/features/GlobalFiltering.js +85 -0
  34. package/build/lib/features/GlobalFiltering.js.map +1 -0
  35. package/build/lib/features/{Expanding.d.ts → RowExpanding.d.ts} +2 -3
  36. package/build/lib/features/{Expanding.js → RowExpanding.js} +3 -3
  37. package/build/lib/features/RowExpanding.js.map +1 -0
  38. package/build/lib/features/{Pagination.d.ts → RowPagination.d.ts} +2 -3
  39. package/build/lib/features/{Pagination.js → RowPagination.js} +3 -3
  40. package/build/lib/features/RowPagination.js.map +1 -0
  41. package/build/lib/features/RowPinning.d.ts +98 -0
  42. package/build/lib/features/RowPinning.js +145 -0
  43. package/build/lib/features/RowPinning.js.map +1 -0
  44. package/build/lib/features/RowSelection.d.ts +1 -2
  45. package/build/lib/features/RowSelection.js.map +1 -1
  46. package/build/lib/features/{Sorting.d.ts → RowSorting.d.ts} +5 -3
  47. package/build/lib/features/{Sorting.js → RowSorting.js} +3 -3
  48. package/build/lib/features/RowSorting.js.map +1 -0
  49. package/build/lib/filterFns.d.ts +1 -1
  50. package/build/lib/filterFns.js.map +1 -1
  51. package/build/lib/index.d.ts +21 -18
  52. package/build/lib/index.esm.js +1490 -1446
  53. package/build/lib/index.esm.js.map +1 -1
  54. package/build/lib/index.js +47 -41
  55. package/build/lib/index.js.map +1 -1
  56. package/build/lib/index.mjs +1490 -1446
  57. package/build/lib/index.mjs.map +1 -1
  58. package/build/lib/sortingFns.d.ts +1 -1
  59. package/build/lib/sortingFns.js.map +1 -1
  60. package/build/lib/types.d.ts +30 -16
  61. package/build/lib/utils/getFilteredRowModel.js.map +1 -1
  62. package/build/lib/utils/getSortedRowModel.js.map +1 -1
  63. package/build/umd/index.development.js +1500 -1453
  64. package/build/umd/index.development.js.map +1 -1
  65. package/build/umd/index.production.js +1 -1
  66. package/build/umd/index.production.js.map +1 -1
  67. package/package.json +1 -1
  68. package/src/aggregationFns.ts +1 -1
  69. package/src/core/column.ts +2 -2
  70. package/src/core/headers.ts +9 -3
  71. package/src/core/row.ts +1 -1
  72. package/src/core/table.ts +40 -32
  73. package/src/features/ColumnFaceting.ts +84 -0
  74. package/src/features/{Filters.ts → ColumnFiltering.ts} +44 -279
  75. package/src/features/{Grouping.ts → ColumnGrouping.ts} +6 -6
  76. package/src/features/{Ordering.ts → ColumnOrdering.ts} +11 -5
  77. package/src/features/ColumnPinning.ts +336 -0
  78. package/src/features/ColumnSizing.ts +10 -3
  79. package/src/features/{Visibility.ts → ColumnVisibility.ts} +2 -2
  80. package/src/features/GlobalFiltering.ts +218 -0
  81. package/src/features/{Expanding.ts → RowExpanding.ts} +9 -3
  82. package/src/features/{Pagination.ts → RowPagination.ts} +9 -3
  83. package/src/features/RowPinning.ts +273 -0
  84. package/src/features/RowSelection.ts +9 -2
  85. package/src/features/{Sorting.ts → RowSorting.ts} +5 -2
  86. package/src/filterFns.ts +1 -1
  87. package/src/index.ts +30 -18
  88. package/src/sortingFns.ts +1 -1
  89. package/src/types.ts +60 -23
  90. package/src/utils/getFilteredRowModel.ts +1 -1
  91. package/src/utils/getSortedRowModel.ts +1 -1
  92. package/build/lib/features/Expanding.js.map +0 -1
  93. package/build/lib/features/Filters.js.map +0 -1
  94. package/build/lib/features/Grouping.js.map +0 -1
  95. package/build/lib/features/Ordering.js.map +0 -1
  96. package/build/lib/features/Pagination.js.map +0 -1
  97. package/build/lib/features/Pinning.d.ts +0 -222
  98. package/build/lib/features/Pinning.js.map +0 -1
  99. package/build/lib/features/Sorting.js.map +0 -1
  100. package/build/lib/features/Visibility.js.map +0 -1
  101. 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.14.0",
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,33 @@ 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 { GlobalFiltering } from '../features/GlobalFiltering'
34
+ import { RowExpanding } from '../features/RowExpanding'
35
+ import { RowPagination } from '../features/RowPagination'
36
+ import { RowPinning } from '../features/RowPinning'
32
37
  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
- }
38
+ import { RowSorting } from '../features/RowSorting'
46
39
 
47
- const features = [
40
+ const builtInFeatures = [
48
41
  Headers,
49
- Visibility,
50
- Ordering,
51
- Pinning,
52
- Filters,
53
- Sorting,
54
- Grouping,
55
- Expanding,
56
- Pagination,
42
+ ColumnVisibility,
43
+ ColumnOrdering,
44
+ ColumnPinning,
45
+ ColumnFaceting,
46
+ ColumnFiltering,
47
+ GlobalFiltering, //depends on ColumnFiltering and ColumnFaceting
48
+ RowSorting,
49
+ ColumnGrouping, //depends on RowSorting
50
+ RowExpanding,
51
+ RowPagination,
52
+ RowPinning,
57
53
  RowSelection,
58
54
  ColumnSizing,
59
55
  ] as const
@@ -63,6 +59,12 @@ const features = [
63
59
  export interface CoreTableState {}
64
60
 
65
61
  export interface CoreOptions<TData extends RowData> {
62
+ /**
63
+ * An array of extra features that you can add to the table instance.
64
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#_features)
65
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/tables)
66
+ */
67
+ _features?: TableFeature[]
66
68
  /**
67
69
  * Set this option to override any of the `autoReset...` feature options.
68
70
  * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#autoresetall)
@@ -279,11 +281,16 @@ export interface CoreInstance<TData extends RowData> {
279
281
  export function createTable<TData extends RowData>(
280
282
  options: TableOptionsResolved<TData>
281
283
  ): Table<TData> {
282
- if (options.debugAll || options.debugTable) {
284
+ if (
285
+ process.env.NODE_ENV !== 'production' &&
286
+ (options.debugAll || options.debugTable)
287
+ ) {
283
288
  console.info('Creating Table Instance...')
284
289
  }
285
290
 
286
- let table = { _features: features } as unknown as Table<TData>
291
+ const _features = [...builtInFeatures, ...(options._features ?? [])]
292
+
293
+ let table = { _features } as unknown as Table<TData>
287
294
 
288
295
  const defaultOptions = table._features.reduce((obj, feature) => {
289
296
  return Object.assign(obj, feature.getDefaultOptions?.(table))
@@ -308,14 +315,15 @@ export function createTable<TData extends RowData>(
308
315
  } as TableState
309
316
 
310
317
  table._features.forEach(feature => {
311
- initialState = feature.getInitialState?.(initialState) ?? initialState
318
+ initialState = (feature.getInitialState?.(initialState) ??
319
+ initialState) as TableState
312
320
  })
313
321
 
314
322
  const queued: (() => void)[] = []
315
323
  let queuedTimeout = false
316
324
 
317
325
  const coreInstance: CoreInstance<TData> = {
318
- _features: features,
326
+ _features,
319
327
  options: {
320
328
  ...defaultOptions,
321
329
  ...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/filters#getfacetedminmaxvalues)
12
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
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/filters#getfacetedrowmodel)
19
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
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/filters#getfaceteduniquevalues)
26
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/filters)
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
+ }