@tanstack/table-core 8.0.12 → 8.1.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.
- package/build/cjs/core/cell.js +13 -13
- package/build/cjs/core/cell.js.map +1 -1
- package/build/cjs/core/column.js +20 -21
- package/build/cjs/core/column.js.map +1 -1
- package/build/cjs/core/headers.js +63 -68
- package/build/cjs/core/headers.js.map +1 -1
- package/build/cjs/core/row.js +16 -11
- package/build/cjs/core/row.js.map +1 -1
- package/build/cjs/core/{instance.js → table.js} +46 -57
- package/build/cjs/core/table.js.map +1 -0
- package/build/cjs/features/ColumnSizing.js +36 -36
- package/build/cjs/features/ColumnSizing.js.map +1 -1
- package/build/cjs/features/Expanding.js +34 -34
- package/build/cjs/features/Expanding.js.map +1 -1
- package/build/cjs/features/Filters.js +46 -52
- package/build/cjs/features/Filters.js.map +1 -1
- package/build/cjs/features/Grouping.js +24 -49
- package/build/cjs/features/Grouping.js.map +1 -1
- package/build/cjs/features/Ordering.js +8 -8
- package/build/cjs/features/Ordering.js.map +1 -1
- package/build/cjs/features/Pagination.js +37 -37
- package/build/cjs/features/Pagination.js.map +1 -1
- package/build/cjs/features/Pinning.js +33 -33
- package/build/cjs/features/Pinning.js.map +1 -1
- package/build/cjs/features/RowSelection.js +86 -74
- package/build/cjs/features/RowSelection.js.map +1 -1
- package/build/cjs/features/Sorting.js +36 -40
- package/build/cjs/features/Sorting.js.map +1 -1
- package/build/cjs/features/Visibility.js +30 -30
- package/build/cjs/features/Visibility.js.map +1 -1
- package/build/cjs/index.js +3 -4
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/utils/filterRowsUtils.js +8 -8
- package/build/cjs/utils/filterRowsUtils.js.map +1 -1
- package/build/cjs/utils/getCoreRowModel.js +8 -8
- package/build/cjs/utils/getCoreRowModel.js.map +1 -1
- package/build/cjs/utils/getExpandedRowModel.js +4 -4
- package/build/cjs/utils/getExpandedRowModel.js.map +1 -1
- package/build/cjs/utils/getFacetedMinMaxValues.js +3 -3
- package/build/cjs/utils/getFacetedMinMaxValues.js.map +1 -1
- package/build/cjs/utils/getFacetedRowModel.js +4 -4
- package/build/cjs/utils/getFacetedRowModel.js.map +1 -1
- package/build/cjs/utils/getFacetedUniqueValues.js +3 -3
- package/build/cjs/utils/getFacetedUniqueValues.js.map +1 -1
- package/build/cjs/utils/getFilteredRowModel.js +8 -8
- package/build/cjs/utils/getFilteredRowModel.js.map +1 -1
- package/build/cjs/utils/getGroupedRowModel.js +9 -9
- package/build/cjs/utils/getGroupedRowModel.js.map +1 -1
- package/build/cjs/utils/getPaginationRowModel.js +4 -4
- package/build/cjs/utils/getPaginationRowModel.js.map +1 -1
- package/build/cjs/utils/getSortedRowModel.js +7 -7
- package/build/cjs/utils/getSortedRowModel.js.map +1 -1
- package/build/cjs/utils.js +2 -2
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +585 -677
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +352 -377
- package/build/types/index.d.ts +761 -29
- package/build/umd/index.development.js +586 -678
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/core/cell.ts +34 -28
- package/src/core/column.ts +83 -72
- package/src/core/headers.ts +118 -149
- package/src/core/row.ts +31 -25
- package/src/core/{instance.ts → table.ts} +85 -116
- package/src/features/ColumnSizing.ts +45 -47
- package/src/features/Expanding.ts +53 -59
- package/src/features/Filters.ts +112 -132
- package/src/features/Grouping.ts +63 -112
- package/src/features/Ordering.ts +19 -21
- package/src/features/Pagination.ts +54 -55
- package/src/features/Pinning.ts +49 -61
- package/src/features/RowSelection.ts +115 -114
- package/src/features/Sorting.ts +57 -72
- package/src/features/Visibility.ts +48 -48
- package/src/index.ts +1 -2
- package/src/types.ts +64 -69
- package/src/utils/filterRowsUtils.ts +33 -28
- package/src/utils/getCoreRowModel.ts +22 -22
- package/src/utils/getExpandedRowModel.ts +15 -15
- package/src/utils/getFacetedMinMaxValues.ts +6 -6
- package/src/utils/getFacetedRowModel.ts +12 -12
- package/src/utils/getFacetedUniqueValues.ts +6 -6
- package/src/utils/getFilteredRowModel.ts +17 -17
- package/src/utils/getGroupedRowModel.ts +18 -21
- package/src/utils/getPaginationRowModel.ts +10 -13
- package/src/utils/getSortedRowModel.ts +14 -14
- package/src/utils.ts +8 -2
- package/build/cjs/core/instance.js.map +0 -1
- package/build/cjs/createTable.js +0 -72
- package/build/cjs/createTable.js.map +0 -1
- package/build/types/aggregationFns.d.ts +0 -13
- package/build/types/core/cell.d.ts +0 -9
- package/build/types/core/column.d.ts +0 -40
- package/build/types/core/headers.d.ts +0 -46
- package/build/types/core/instance.d.ts +0 -58
- package/build/types/core/row.d.ts +0 -15
- package/build/types/createTable.d.ts +0 -63
- package/build/types/features/ColumnSizing.d.ts +0 -63
- package/build/types/features/Expanding.d.ts +0 -39
- package/build/types/features/Filters.d.ts +0 -90
- package/build/types/features/Grouping.d.ts +0 -68
- package/build/types/features/Ordering.d.ts +0 -18
- package/build/types/features/Pagination.d.ts +0 -42
- package/build/types/features/Pinning.d.ts +0 -40
- package/build/types/features/RowSelection.d.ts +0 -40
- package/build/types/features/Sorting.d.ts +0 -63
- package/build/types/features/Visibility.d.ts +0 -40
- package/build/types/filterFns.d.ts +0 -13
- package/build/types/sortingFns.d.ts +0 -11
- package/build/types/types.d.ts +0 -53
- package/build/types/utils/filterRowsUtils.d.ts +0 -4
- package/build/types/utils/getCoreRowModel.d.ts +0 -2
- package/build/types/utils/getExpandedRowModel.d.ts +0 -7
- package/build/types/utils/getFacetedMinMaxValues.d.ts +0 -2
- package/build/types/utils/getFacetedRowModel.d.ts +0 -2
- package/build/types/utils/getFacetedUniqueValues.d.ts +0 -2
- package/build/types/utils/getFilteredRowModel.d.ts +0 -2
- package/build/types/utils/getGroupedRowModel.d.ts +0 -2
- package/build/types/utils/getPaginationRowModel.d.ts +0 -4
- package/build/types/utils/getSortedRowModel.d.ts +0 -2
- package/build/types/utils.d.ts +0 -19
- package/src/createTable.ts +0 -188
package/src/features/Pinning.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { TableFeature } from '../core/
|
|
1
|
+
import { TableFeature } from '../core/table'
|
|
2
2
|
import {
|
|
3
3
|
OnChangeFn,
|
|
4
4
|
Updater,
|
|
5
|
-
|
|
5
|
+
Table,
|
|
6
6
|
Column,
|
|
7
7
|
TableGenerics,
|
|
8
8
|
Row,
|
|
9
9
|
Cell,
|
|
10
|
+
RowData,
|
|
10
11
|
} from '../types'
|
|
11
12
|
import { makeStateUpdater, memo } from '../utils'
|
|
12
13
|
|
|
@@ -41,19 +42,19 @@ export type ColumnPinningColumn = {
|
|
|
41
42
|
pin: (position: ColumnPinningPosition) => void
|
|
42
43
|
}
|
|
43
44
|
|
|
44
|
-
export type ColumnPinningRow<
|
|
45
|
-
getLeftVisibleCells: () => Cell<
|
|
46
|
-
getCenterVisibleCells: () => Cell<
|
|
47
|
-
getRightVisibleCells: () => Cell<
|
|
45
|
+
export type ColumnPinningRow<TData extends RowData> = {
|
|
46
|
+
getLeftVisibleCells: () => Cell<TData>[]
|
|
47
|
+
getCenterVisibleCells: () => Cell<TData>[]
|
|
48
|
+
getRightVisibleCells: () => Cell<TData>[]
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
export type ColumnPinningInstance<
|
|
51
|
+
export type ColumnPinningInstance<TData extends RowData> = {
|
|
51
52
|
setColumnPinning: (updater: Updater<ColumnPinningState>) => void
|
|
52
53
|
resetColumnPinning: (defaultState?: boolean) => void
|
|
53
54
|
getIsSomeColumnsPinned: (position?: ColumnPinningPosition) => boolean
|
|
54
|
-
getLeftLeafColumns: () => Column<
|
|
55
|
-
getRightLeafColumns: () => Column<
|
|
56
|
-
getCenterLeafColumns: () => Column<
|
|
55
|
+
getLeftLeafColumns: () => Column<TData>[]
|
|
56
|
+
getRightLeafColumns: () => Column<TData>[]
|
|
57
|
+
getCenterLeafColumns: () => Column<TData>[]
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
//
|
|
@@ -71,17 +72,17 @@ export const Pinning: TableFeature = {
|
|
|
71
72
|
}
|
|
72
73
|
},
|
|
73
74
|
|
|
74
|
-
getDefaultOptions: <
|
|
75
|
-
|
|
75
|
+
getDefaultOptions: <TData extends RowData>(
|
|
76
|
+
table: Table<TData>
|
|
76
77
|
): ColumnPinningDefaultOptions => {
|
|
77
78
|
return {
|
|
78
|
-
onColumnPinningChange: makeStateUpdater('columnPinning',
|
|
79
|
+
onColumnPinningChange: makeStateUpdater('columnPinning', table),
|
|
79
80
|
}
|
|
80
81
|
},
|
|
81
82
|
|
|
82
|
-
createColumn: <
|
|
83
|
-
column: Column<
|
|
84
|
-
|
|
83
|
+
createColumn: <TData extends RowData>(
|
|
84
|
+
column: Column<TData>,
|
|
85
|
+
table: Table<TData>
|
|
85
86
|
): ColumnPinningColumn => {
|
|
86
87
|
return {
|
|
87
88
|
pin: position => {
|
|
@@ -90,7 +91,7 @@ export const Pinning: TableFeature = {
|
|
|
90
91
|
.map(d => d.id)
|
|
91
92
|
.filter(Boolean) as string[]
|
|
92
93
|
|
|
93
|
-
|
|
94
|
+
table.setColumnPinning(old => {
|
|
94
95
|
if (position === 'right') {
|
|
95
96
|
return {
|
|
96
97
|
left: (old?.left ?? []).filter(d => !columnIds?.includes(d)),
|
|
@@ -124,14 +125,14 @@ export const Pinning: TableFeature = {
|
|
|
124
125
|
return leafColumns.some(
|
|
125
126
|
d =>
|
|
126
127
|
(d.columnDef.enablePinning ?? true) &&
|
|
127
|
-
(
|
|
128
|
+
(table.options.enablePinning ?? true)
|
|
128
129
|
)
|
|
129
130
|
},
|
|
130
131
|
|
|
131
132
|
getIsPinned: () => {
|
|
132
133
|
const leafColumnIds = column.getLeafColumns().map(d => d.id)
|
|
133
134
|
|
|
134
|
-
const { left, right } =
|
|
135
|
+
const { left, right } = table.getState().columnPinning
|
|
135
136
|
|
|
136
137
|
const isLeft = leafColumnIds.some(d => left?.includes(d))
|
|
137
138
|
const isRight = leafColumnIds.some(d => right?.includes(d))
|
|
@@ -143,23 +144,22 @@ export const Pinning: TableFeature = {
|
|
|
143
144
|
const position = column.getIsPinned()
|
|
144
145
|
|
|
145
146
|
return position
|
|
146
|
-
?
|
|
147
|
-
-1
|
|
147
|
+
? table.getState().columnPinning?.[position]?.indexOf(column.id) ?? -1
|
|
148
148
|
: 0
|
|
149
149
|
},
|
|
150
150
|
}
|
|
151
151
|
},
|
|
152
152
|
|
|
153
|
-
createRow: <
|
|
154
|
-
row: Row<
|
|
155
|
-
|
|
156
|
-
): ColumnPinningRow<
|
|
153
|
+
createRow: <TData extends RowData>(
|
|
154
|
+
row: Row<TData>,
|
|
155
|
+
table: Table<TData>
|
|
156
|
+
): ColumnPinningRow<TData> => {
|
|
157
157
|
return {
|
|
158
158
|
getCenterVisibleCells: memo(
|
|
159
159
|
() => [
|
|
160
160
|
row._getAllVisibleCells(),
|
|
161
|
-
|
|
162
|
-
|
|
161
|
+
table.getState().columnPinning.left,
|
|
162
|
+
table.getState().columnPinning.right,
|
|
163
163
|
],
|
|
164
164
|
(allCells, left, right) => {
|
|
165
165
|
const leftAndRight: string[] = [...(left ?? []), ...(right ?? [])]
|
|
@@ -170,13 +170,13 @@ export const Pinning: TableFeature = {
|
|
|
170
170
|
key:
|
|
171
171
|
process.env.NODE_ENV === 'production' &&
|
|
172
172
|
'row.getCenterVisibleCells',
|
|
173
|
-
debug: () =>
|
|
173
|
+
debug: () => table.options.debugAll ?? table.options.debugRows,
|
|
174
174
|
}
|
|
175
175
|
),
|
|
176
176
|
getLeftVisibleCells: memo(
|
|
177
177
|
() => [
|
|
178
178
|
row._getAllVisibleCells(),
|
|
179
|
-
|
|
179
|
+
table.getState().columnPinning.left,
|
|
180
180
|
,
|
|
181
181
|
],
|
|
182
182
|
(allCells, left) => {
|
|
@@ -185,56 +185,53 @@ export const Pinning: TableFeature = {
|
|
|
185
185
|
columnId => allCells.find(cell => cell.column.id === columnId)!
|
|
186
186
|
)
|
|
187
187
|
.filter(Boolean)
|
|
188
|
-
.map(d => ({ ...d, position: 'left' } as Cell<
|
|
188
|
+
.map(d => ({ ...d, position: 'left' } as Cell<TData>))
|
|
189
189
|
|
|
190
190
|
return cells
|
|
191
191
|
},
|
|
192
192
|
{
|
|
193
193
|
key:
|
|
194
194
|
process.env.NODE_ENV === 'production' && 'row.getLeftVisibleCells',
|
|
195
|
-
debug: () =>
|
|
195
|
+
debug: () => table.options.debugAll ?? table.options.debugRows,
|
|
196
196
|
}
|
|
197
197
|
),
|
|
198
198
|
getRightVisibleCells: memo(
|
|
199
|
-
() => [
|
|
200
|
-
row._getAllVisibleCells(),
|
|
201
|
-
instance.getState().columnPinning.right,
|
|
202
|
-
],
|
|
199
|
+
() => [row._getAllVisibleCells(), table.getState().columnPinning.right],
|
|
203
200
|
(allCells, right) => {
|
|
204
201
|
const cells = (right ?? [])
|
|
205
202
|
.map(
|
|
206
203
|
columnId => allCells.find(cell => cell.column.id === columnId)!
|
|
207
204
|
)
|
|
208
205
|
.filter(Boolean)
|
|
209
|
-
.map(d => ({ ...d, position: 'left' } as Cell<
|
|
206
|
+
.map(d => ({ ...d, position: 'left' } as Cell<TData>))
|
|
210
207
|
|
|
211
208
|
return cells
|
|
212
209
|
},
|
|
213
210
|
{
|
|
214
211
|
key:
|
|
215
212
|
process.env.NODE_ENV === 'production' && 'row.getRightVisibleCells',
|
|
216
|
-
debug: () =>
|
|
213
|
+
debug: () => table.options.debugAll ?? table.options.debugRows,
|
|
217
214
|
}
|
|
218
215
|
),
|
|
219
216
|
}
|
|
220
217
|
},
|
|
221
218
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
): ColumnPinningInstance<
|
|
219
|
+
createTable: <TData extends RowData>(
|
|
220
|
+
table: Table<TData>
|
|
221
|
+
): ColumnPinningInstance<TData> => {
|
|
225
222
|
return {
|
|
226
223
|
setColumnPinning: updater =>
|
|
227
|
-
|
|
224
|
+
table.options.onColumnPinningChange?.(updater),
|
|
228
225
|
|
|
229
226
|
resetColumnPinning: defaultState =>
|
|
230
|
-
|
|
227
|
+
table.setColumnPinning(
|
|
231
228
|
defaultState
|
|
232
229
|
? getDefaultPinningState()
|
|
233
|
-
:
|
|
230
|
+
: table.initialState?.columnPinning ?? getDefaultPinningState()
|
|
234
231
|
),
|
|
235
232
|
|
|
236
233
|
getIsSomeColumnsPinned: position => {
|
|
237
|
-
const pinningState =
|
|
234
|
+
const pinningState = table.getState().columnPinning
|
|
238
235
|
|
|
239
236
|
if (!position) {
|
|
240
237
|
return Boolean(
|
|
@@ -245,10 +242,7 @@ export const Pinning: TableFeature = {
|
|
|
245
242
|
},
|
|
246
243
|
|
|
247
244
|
getLeftLeafColumns: memo(
|
|
248
|
-
() => [
|
|
249
|
-
instance.getAllLeafColumns(),
|
|
250
|
-
instance.getState().columnPinning.left,
|
|
251
|
-
],
|
|
245
|
+
() => [table.getAllLeafColumns(), table.getState().columnPinning.left],
|
|
252
246
|
(allColumns, left) => {
|
|
253
247
|
return (left ?? [])
|
|
254
248
|
.map(columnId => allColumns.find(column => column.id === columnId)!)
|
|
@@ -256,16 +250,12 @@ export const Pinning: TableFeature = {
|
|
|
256
250
|
},
|
|
257
251
|
{
|
|
258
252
|
key: process.env.NODE_ENV === 'development' && 'getLeftLeafColumns',
|
|
259
|
-
debug: () =>
|
|
260
|
-
instance.options.debugAll ?? instance.options.debugColumns,
|
|
253
|
+
debug: () => table.options.debugAll ?? table.options.debugColumns,
|
|
261
254
|
}
|
|
262
255
|
),
|
|
263
256
|
|
|
264
257
|
getRightLeafColumns: memo(
|
|
265
|
-
() => [
|
|
266
|
-
instance.getAllLeafColumns(),
|
|
267
|
-
instance.getState().columnPinning.right,
|
|
268
|
-
],
|
|
258
|
+
() => [table.getAllLeafColumns(), table.getState().columnPinning.right],
|
|
269
259
|
(allColumns, right) => {
|
|
270
260
|
return (right ?? [])
|
|
271
261
|
.map(columnId => allColumns.find(column => column.id === columnId)!)
|
|
@@ -273,16 +263,15 @@ export const Pinning: TableFeature = {
|
|
|
273
263
|
},
|
|
274
264
|
{
|
|
275
265
|
key: process.env.NODE_ENV === 'development' && 'getRightLeafColumns',
|
|
276
|
-
debug: () =>
|
|
277
|
-
instance.options.debugAll ?? instance.options.debugColumns,
|
|
266
|
+
debug: () => table.options.debugAll ?? table.options.debugColumns,
|
|
278
267
|
}
|
|
279
268
|
),
|
|
280
269
|
|
|
281
270
|
getCenterLeafColumns: memo(
|
|
282
271
|
() => [
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
272
|
+
table.getAllLeafColumns(),
|
|
273
|
+
table.getState().columnPinning.left,
|
|
274
|
+
table.getState().columnPinning.right,
|
|
286
275
|
],
|
|
287
276
|
(allColumns, left, right) => {
|
|
288
277
|
const leftAndRight: string[] = [...(left ?? []), ...(right ?? [])]
|
|
@@ -291,8 +280,7 @@ export const Pinning: TableFeature = {
|
|
|
291
280
|
},
|
|
292
281
|
{
|
|
293
282
|
key: process.env.NODE_ENV === 'development' && 'getCenterLeafColumns',
|
|
294
|
-
debug: () =>
|
|
295
|
-
instance.options.debugAll ?? instance.options.debugColumns,
|
|
283
|
+
debug: () => table.options.debugAll ?? table.options.debugColumns,
|
|
296
284
|
}
|
|
297
285
|
),
|
|
298
286
|
}
|