@tanstack/table-core 8.0.0-alpha.80 → 8.0.0-alpha.84

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 (110) hide show
  1. package/build/cjs/core/cell.js +38 -0
  2. package/build/cjs/core/cell.js.map +1 -0
  3. package/build/cjs/core/column.js +88 -0
  4. package/build/cjs/core/column.js.map +1 -0
  5. package/build/cjs/{features/Headers.js → core/headers.js} +54 -66
  6. package/build/cjs/core/headers.js.map +1 -0
  7. package/build/cjs/core/instance.js +255 -0
  8. package/build/cjs/core/instance.js.map +1 -0
  9. package/build/cjs/core/row.js +77 -0
  10. package/build/cjs/core/row.js.map +1 -0
  11. package/build/cjs/createTable.js +4 -2
  12. package/build/cjs/createTable.js.map +1 -1
  13. package/build/cjs/features/ColumnSizing.js +5 -5
  14. package/build/cjs/features/ColumnSizing.js.map +1 -1
  15. package/build/cjs/features/Expanding.js.map +1 -1
  16. package/build/cjs/features/Filters.js +12 -7
  17. package/build/cjs/features/Filters.js.map +1 -1
  18. package/build/cjs/features/Grouping.js +5 -5
  19. package/build/cjs/features/Grouping.js.map +1 -1
  20. package/build/cjs/features/Ordering.js.map +1 -1
  21. package/build/cjs/features/Pagination.js.map +1 -1
  22. package/build/cjs/features/Pinning.js +17 -11
  23. package/build/cjs/features/Pinning.js.map +1 -1
  24. package/build/cjs/features/RowSelection.js.map +1 -1
  25. package/build/cjs/features/Sorting.js +9 -9
  26. package/build/cjs/features/Sorting.js.map +1 -1
  27. package/build/cjs/features/Visibility.js +3 -3
  28. package/build/cjs/features/Visibility.js.map +1 -1
  29. package/build/cjs/index.js +17 -5
  30. package/build/cjs/index.js.map +1 -1
  31. package/build/cjs/utils/filterRowsUtils.js +23 -21
  32. package/build/cjs/utils/filterRowsUtils.js.map +1 -1
  33. package/build/cjs/utils/getCoreRowModel.js +9 -8
  34. package/build/cjs/utils/getCoreRowModel.js.map +1 -1
  35. package/build/cjs/utils/getFacetedRowModel.js +1 -1
  36. package/build/cjs/utils/getFacetedRowModel.js.map +1 -1
  37. package/build/cjs/utils/getFilteredRowModel.js +20 -9
  38. package/build/cjs/utils/getFilteredRowModel.js.map +1 -1
  39. package/build/cjs/utils/getGroupedRowModel.js +14 -13
  40. package/build/cjs/utils/getGroupedRowModel.js.map +1 -1
  41. package/build/cjs/utils/getSortedRowModel.js +2 -2
  42. package/build/cjs/utils/getSortedRowModel.js.map +1 -1
  43. package/build/esm/index.js +731 -810
  44. package/build/esm/index.js.map +1 -1
  45. package/build/stats-html.html +1 -1
  46. package/build/stats-react.json +418 -377
  47. package/build/types/core/cell.d.ts +9 -0
  48. package/build/types/{features/Columns.d.ts → core/column.d.ts} +3 -17
  49. package/build/types/{features/Headers.d.ts → core/headers.d.ts} +26 -11
  50. package/build/types/core/instance.d.ts +57 -0
  51. package/build/types/core/row.d.ts +15 -0
  52. package/build/types/createTable.d.ts +8 -5
  53. package/build/types/features/ColumnSizing.d.ts +2 -1
  54. package/build/types/features/Expanding.d.ts +2 -1
  55. package/build/types/features/Filters.d.ts +5 -3
  56. package/build/types/features/Grouping.d.ts +3 -2
  57. package/build/types/features/Ordering.d.ts +2 -1
  58. package/build/types/features/Pagination.d.ts +2 -1
  59. package/build/types/features/Pinning.d.ts +3 -2
  60. package/build/types/features/RowSelection.d.ts +2 -1
  61. package/build/types/features/Sorting.d.ts +2 -1
  62. package/build/types/features/Visibility.d.ts +2 -1
  63. package/build/types/index.d.ts +7 -2
  64. package/build/types/sortingFns.d.ts +4 -4
  65. package/build/types/types.d.ts +13 -53
  66. package/build/umd/index.development.js +738 -806
  67. package/build/umd/index.development.js.map +1 -1
  68. package/build/umd/index.production.js +1 -1
  69. package/build/umd/index.production.js.map +1 -1
  70. package/package.json +1 -1
  71. package/src/core/cell.ts +47 -0
  72. package/src/core/column.ts +148 -0
  73. package/src/{features/Headers.ts → core/headers.ts} +98 -99
  74. package/src/core/instance.ts +361 -0
  75. package/src/core/row.ts +85 -0
  76. package/src/createTable.ts +14 -7
  77. package/src/features/ColumnSizing.ts +6 -6
  78. package/src/features/Expanding.ts +1 -2
  79. package/src/features/Filters.ts +20 -8
  80. package/src/features/Grouping.ts +7 -6
  81. package/src/features/Ordering.ts +1 -1
  82. package/src/features/Pagination.ts +1 -1
  83. package/src/features/Pinning.ts +18 -9
  84. package/src/features/RowSelection.ts +1 -1
  85. package/src/features/Sorting.ts +11 -11
  86. package/src/features/Visibility.ts +3 -3
  87. package/src/index.ts +7 -8
  88. package/src/types.ts +17 -64
  89. package/src/utils/filterRowsUtils.ts +5 -3
  90. package/src/utils/getCoreRowModel.ts +4 -2
  91. package/src/utils/getFacetedRowModel.ts +1 -1
  92. package/src/utils/getFilteredRowModel.ts +24 -13
  93. package/src/utils/getGroupedRowModel.ts +9 -8
  94. package/src/utils/getSortedRowModel.ts +2 -2
  95. package/build/cjs/core.js +0 -168
  96. package/build/cjs/core.js.map +0 -1
  97. package/build/cjs/features/Cells.js +0 -101
  98. package/build/cjs/features/Cells.js.map +0 -1
  99. package/build/cjs/features/Columns.js +0 -189
  100. package/build/cjs/features/Columns.js.map +0 -1
  101. package/build/cjs/features/Headers.js.map +0 -1
  102. package/build/cjs/features/Rows.js +0 -94
  103. package/build/cjs/features/Rows.js.map +0 -1
  104. package/build/types/core.d.ts +0 -30
  105. package/build/types/features/Cells.d.ts +0 -13
  106. package/build/types/features/Rows.d.ts +0 -28
  107. package/src/core.ts +0 -246
  108. package/src/features/Cells.ts +0 -128
  109. package/src/features/Columns.ts +0 -289
  110. package/src/features/Rows.ts +0 -142
@@ -1,289 +0,0 @@
1
- import {
2
- Cell,
3
- Column,
4
- Header,
5
- TableGenerics,
6
- TableInstance,
7
- Row,
8
- AccessorFn,
9
- ColumnDef,
10
- Renderable,
11
- } from '../types'
12
- import { memo } from '../utils'
13
-
14
- export type CoreColumnDefType = 'data' | 'display' | 'group'
15
-
16
- export type CoreColumnDef<TGenerics extends TableGenerics> = {
17
- id: string
18
- accessorKey?: string & keyof TGenerics['Row']
19
- accessorFn?: AccessorFn<TGenerics['Row']>
20
- columns?: ColumnDef<TGenerics>[]
21
- header?: Renderable<
22
- TGenerics,
23
- {
24
- instance: TableInstance<TGenerics>
25
- header: Header<TGenerics>
26
- column: Column<TGenerics>
27
- }
28
- >
29
- footer?: Renderable<
30
- TGenerics,
31
- {
32
- instance: TableInstance<TGenerics>
33
- header: Header<TGenerics>
34
- column: Column<TGenerics>
35
- }
36
- >
37
- cell?: Renderable<
38
- TGenerics,
39
- {
40
- instance: TableInstance<TGenerics>
41
- row: Row<TGenerics>
42
- column: Column<TGenerics>
43
- cell: Cell<TGenerics>
44
- getValue: () => TGenerics['Value']
45
- }
46
- >
47
- meta?: TGenerics['ColumnMeta']
48
- }
49
-
50
- export type CoreColumn<TGenerics extends TableGenerics> = {
51
- id: string
52
- depth: number
53
- accessorFn?: AccessorFn<TGenerics['Row']>
54
- columnDef: ColumnDef<TGenerics>
55
- columnDefType: CoreColumnDefType
56
- columns: Column<TGenerics>[]
57
- parent?: Column<TGenerics>
58
- getFlatColumns: () => Column<TGenerics>[]
59
- getLeafColumns: () => Column<TGenerics>[]
60
- }
61
-
62
- export type ColumnsOptions<TGenerics extends TableGenerics> = {
63
- columns: ColumnDef<TGenerics>[]
64
- defaultColumn?: Partial<ColumnDef<TGenerics>>
65
- }
66
-
67
- export type ColumnsInstance<TGenerics extends TableGenerics> = {
68
- getDefaultColumn: () => Partial<ColumnDef<TGenerics>>
69
- getColumnDefs: () => ColumnDef<TGenerics>[]
70
- createColumn: (
71
- columnDef: ColumnDef<TGenerics>,
72
- depth: number,
73
- parent?: Column<TGenerics>
74
- ) => Column<TGenerics>
75
- getAllColumns: () => Column<TGenerics>[]
76
- getAllFlatColumns: () => Column<TGenerics>[]
77
- getAllFlatColumnsById: () => Record<string, Column<TGenerics>>
78
- getAllLeafColumns: () => Column<TGenerics>[]
79
- getColumn: (columnId: string) => Column<TGenerics>
80
- }
81
-
82
- //
83
-
84
- export const Columns = {
85
- createInstance: <TGenerics extends TableGenerics>(
86
- instance: TableInstance<TGenerics>
87
- ): ColumnsInstance<TGenerics> => {
88
- return {
89
- getDefaultColumn: memo(
90
- () => [instance.options.defaultColumn],
91
- defaultColumn => {
92
- defaultColumn = (defaultColumn ?? {}) as Partial<ColumnDef<TGenerics>>
93
-
94
- return {
95
- header: props => props.header.column.id,
96
- footer: props => props.header.column.id,
97
- cell: props => props.getValue().toString?.() ?? null,
98
- ...instance._features.reduce((obj, feature) => {
99
- return Object.assign(obj, feature.getDefaultColumn?.())
100
- }, {}),
101
- ...defaultColumn,
102
- } as Partial<ColumnDef<TGenerics>>
103
- },
104
- {
105
- debug: () =>
106
- instance.options.debugAll ?? instance.options.debugColumns,
107
- key: process.env.NODE_ENV === 'development' && 'getDefaultColumn',
108
- }
109
- ),
110
-
111
- getColumnDefs: () => instance.options.columns,
112
-
113
- createColumn: (
114
- columnDef: ColumnDef<TGenerics> & { columnDefType?: CoreColumnDefType },
115
- depth: number,
116
- parent
117
- ) => {
118
- const defaultColumn = instance.getDefaultColumn()
119
-
120
- let id =
121
- columnDef.id ??
122
- columnDef.accessorKey ??
123
- (typeof columnDef.header === 'string' ? columnDef.header : undefined)
124
-
125
- let accessorFn: AccessorFn<TGenerics['Row']> | undefined
126
-
127
- if (columnDef.accessorFn) {
128
- accessorFn = columnDef.accessorFn
129
- } else if (columnDef.accessorKey) {
130
- accessorFn = (originalRow?: TGenerics['Row']) =>
131
- (originalRow as any)[columnDef.accessorKey]
132
- }
133
-
134
- if (!id) {
135
- if (process.env.NODE_ENV !== 'production') {
136
- throw new Error(
137
- columnDef.accessorFn
138
- ? `Columns require an id when using an accessorFn`
139
- : `Columns require an id when using a non-string header`
140
- )
141
- }
142
- throw new Error()
143
- }
144
-
145
- let column: CoreColumn<TGenerics> = {
146
- ...defaultColumn,
147
- ...columnDef,
148
- id: `${id}`,
149
- accessorFn,
150
- parent: parent as any,
151
- depth,
152
- columnDef,
153
- columnDefType: columnDef.columnDefType as CoreColumnDefType,
154
- columns: [],
155
- getFlatColumns: memo(
156
- () => [true],
157
- () => {
158
- return [
159
- column as Column<TGenerics>,
160
- ...column.columns?.flatMap(d => d.getFlatColumns()),
161
- ]
162
- },
163
- {
164
- key:
165
- process.env.NODE_ENV === 'production' &&
166
- 'column.getFlatColumns',
167
- debug: () =>
168
- instance.options.debugAll ?? instance.options.debugColumns,
169
- }
170
- ),
171
- getLeafColumns: memo(
172
- () => [instance._getOrderColumnsFn()],
173
- orderColumns => {
174
- if (column.columns?.length) {
175
- let leafColumns = column.columns.flatMap(column =>
176
- column.getLeafColumns()
177
- )
178
-
179
- return orderColumns(leafColumns)
180
- }
181
-
182
- return [column as Column<TGenerics>]
183
- },
184
- {
185
- key:
186
- process.env.NODE_ENV === 'production' &&
187
- 'column.getLeafColumns',
188
- debug: () =>
189
- instance.options.debugAll ?? instance.options.debugColumns,
190
- }
191
- ),
192
- }
193
-
194
- column = instance._features.reduce((obj, feature) => {
195
- return Object.assign(obj, feature.createColumn?.(column, instance))
196
- }, column)
197
-
198
- // Yes, we have to convert instance to uknown, because we know more than the compiler here.
199
- return column as Column<TGenerics>
200
- },
201
-
202
- getAllColumns: memo(
203
- () => [instance.getColumnDefs()],
204
- columnDefs => {
205
- const recurseColumns = (
206
- columnDefs: ColumnDef<TGenerics>[],
207
- parent?: Column<TGenerics>,
208
- depth = 0
209
- ): Column<TGenerics>[] => {
210
- return columnDefs.map(columnDef => {
211
- const column = instance.createColumn(columnDef, depth, parent)
212
-
213
- column.columns = columnDef.columns
214
- ? recurseColumns(columnDef.columns, column, depth + 1)
215
- : []
216
-
217
- return column
218
- })
219
- }
220
-
221
- return recurseColumns(columnDefs)
222
- },
223
- {
224
- key: process.env.NODE_ENV === 'development' && 'getAllColumns',
225
- debug: () =>
226
- instance.options.debugAll ?? instance.options.debugColumns,
227
- }
228
- ),
229
-
230
- getAllFlatColumns: memo(
231
- () => [instance.getAllColumns()],
232
- allColumns => {
233
- return allColumns.flatMap(column => {
234
- return column.getFlatColumns()
235
- })
236
- },
237
- {
238
- key: process.env.NODE_ENV === 'development' && 'getAllFlatColumns',
239
- debug: () =>
240
- instance.options.debugAll ?? instance.options.debugColumns,
241
- }
242
- ),
243
-
244
- getAllFlatColumnsById: memo(
245
- () => [instance.getAllFlatColumns()],
246
- flatColumns => {
247
- return flatColumns.reduce((acc, column) => {
248
- acc[column.id] = column
249
- return acc
250
- }, {} as Record<string, Column<TGenerics>>)
251
- },
252
- {
253
- key:
254
- process.env.NODE_ENV === 'development' && 'getAllFlatColumnsById',
255
- debug: () =>
256
- instance.options.debugAll ?? instance.options.debugColumns,
257
- }
258
- ),
259
-
260
- getAllLeafColumns: memo(
261
- () => [instance.getAllColumns(), instance._getOrderColumnsFn()],
262
- (allColumns, orderColumns) => {
263
- let leafColumns = allColumns.flatMap(column =>
264
- column.getLeafColumns()
265
- )
266
- return orderColumns(leafColumns)
267
- },
268
- {
269
- key: process.env.NODE_ENV === 'development' && 'getAllLeafColumns',
270
- debug: () =>
271
- instance.options.debugAll ?? instance.options.debugColumns,
272
- }
273
- ),
274
-
275
- getColumn: columnId => {
276
- const column = instance.getAllFlatColumnsById()[columnId]
277
-
278
- if (!column) {
279
- if (process.env.NODE_ENV !== 'production') {
280
- console.warn(`[Table] Column with id ${columnId} does not exist.`)
281
- }
282
- throw new Error()
283
- }
284
-
285
- return column
286
- },
287
- }
288
- },
289
- }
@@ -1,142 +0,0 @@
1
- import {
2
- TableGenerics,
3
- TableInstance,
4
- Row,
5
- RowModel,
6
- RowValues,
7
- } from '../types'
8
- import { flattenBy } from '../utils'
9
-
10
- export type CoreRow<TGenerics extends TableGenerics> = {
11
- id: string
12
- index: number
13
- original?: TGenerics['Row']
14
- depth: number
15
- valuesCache: Record<string, any>
16
- getValue: (columnId: string) => any
17
- subRows: Row<TGenerics>[]
18
- getLeafRows: () => Row<TGenerics>[]
19
- originalSubRows?: TGenerics['Row'][]
20
- }
21
-
22
- export type RowsOptions<TGenerics extends TableGenerics> = {
23
- getCoreRowModel: (
24
- instance: TableInstance<TGenerics>
25
- ) => () => RowModel<TGenerics>
26
- getSubRows?: (
27
- originalRow: TGenerics['Row'],
28
- index: number
29
- ) => undefined | TGenerics['Row'][]
30
- getRowId?: (
31
- originalRow: TGenerics['Row'],
32
- index: number,
33
- parent?: Row<TGenerics>
34
- ) => string
35
- }
36
-
37
- export type RowsInstance<TGenerics extends TableGenerics> = {
38
- getRowId: (
39
- _: TGenerics['Row'],
40
- index: number,
41
- parent?: Row<TGenerics>
42
- ) => string
43
- createRow: (
44
- id: string,
45
- original: TGenerics['Row'] | undefined,
46
- rowIndex: number,
47
- depth: number,
48
- subRows?: Row<TGenerics>[]
49
- ) => Row<TGenerics>
50
- getCoreRowModel: () => RowModel<TGenerics>
51
- _getCoreRowModel?: () => RowModel<TGenerics>
52
- getRowModel: () => RowModel<TGenerics>
53
- getRow: (id: string) => Row<TGenerics>
54
- }
55
-
56
- //
57
-
58
- export const Rows = {
59
- // createRow: <TGenerics extends TableGenerics>(
60
- // row: Row<TGenerics>,
61
- // instance: TableInstance<TGenerics>
62
- // ): CellsRow<TGenerics> => {
63
- // return {}
64
- // },
65
-
66
- createInstance: <TGenerics extends TableGenerics>(
67
- instance: TableInstance<TGenerics>
68
- ): RowsInstance<TGenerics> => {
69
- return {
70
- getRowId: (
71
- row: TGenerics['Row'],
72
- index: number,
73
- parent?: Row<TGenerics>
74
- ) =>
75
- instance.options.getRowId?.(row, index, parent) ??
76
- `${parent ? [parent.id, index].join('.') : index}`,
77
- createRow: (id, original, rowIndex, depth, subRows) => {
78
- let row: CoreRow<TGenerics> = {
79
- id,
80
- index: rowIndex,
81
- original,
82
- depth,
83
- valuesCache: {},
84
- getValue: columnId => {
85
- if (row.valuesCache.hasOwnProperty(columnId)) {
86
- return row.valuesCache[columnId]
87
- }
88
-
89
- const column = instance.getColumn(columnId)
90
-
91
- if (!column.accessorFn) {
92
- return undefined
93
- }
94
-
95
- row.valuesCache[columnId] = column.accessorFn(
96
- row.original,
97
- rowIndex
98
- )
99
-
100
- return row.valuesCache[columnId]
101
- },
102
- subRows: subRows ?? [],
103
- getLeafRows: () => flattenBy(row.subRows, d => d.subRows),
104
- }
105
-
106
- for (let i = 0; i < instance._features.length; i++) {
107
- const feature = instance._features[i]
108
- Object.assign(row, feature?.createRow?.(row, instance))
109
- }
110
-
111
- return row as Row<TGenerics>
112
- },
113
-
114
- getCoreRowModel: () => {
115
- if (!instance._getCoreRowModel) {
116
- instance._getCoreRowModel = instance.options.getCoreRowModel(instance)
117
- }
118
-
119
- return instance._getCoreRowModel()
120
- },
121
-
122
- // The final calls start at the bottom of the model,
123
- // expanded rows, which then work their way up
124
-
125
- getRowModel: () => {
126
- return instance.getPaginationRowModel()
127
- },
128
- getRow: (id: string) => {
129
- const row = instance.getRowModel().rowsById[id]
130
-
131
- if (!row) {
132
- if (process.env.NODE_ENV !== 'production') {
133
- throw new Error(`getRow expected an ID, but got ${id}`)
134
- }
135
- throw new Error()
136
- }
137
-
138
- return row
139
- },
140
- }
141
- },
142
- }