@tanstack/table-core 8.9.7 → 8.9.8

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 (54) hide show
  1. package/build/lib/core/cell.js +1 -1
  2. package/build/lib/core/cell.js.map +1 -1
  3. package/build/lib/core/column.js +3 -3
  4. package/build/lib/core/column.js.map +1 -1
  5. package/build/lib/core/headers.js +182 -181
  6. package/build/lib/core/headers.js.map +1 -1
  7. package/build/lib/core/row.js +1 -1
  8. package/build/lib/core/row.js.map +1 -1
  9. package/build/lib/core/table.js +4 -3
  10. package/build/lib/core/table.js.map +1 -1
  11. package/build/lib/features/ColumnSizing.js +173 -179
  12. package/build/lib/features/ColumnSizing.js.map +1 -1
  13. package/build/lib/features/Expanding.js +119 -123
  14. package/build/lib/features/Expanding.js.map +1 -1
  15. package/build/lib/features/Filters.js +157 -165
  16. package/build/lib/features/Filters.js.map +1 -1
  17. package/build/lib/features/Grouping.js +71 -79
  18. package/build/lib/features/Grouping.js.map +1 -1
  19. package/build/lib/features/Ordering.js +32 -34
  20. package/build/lib/features/Ordering.js.map +1 -1
  21. package/build/lib/features/Pagination.js +112 -114
  22. package/build/lib/features/Pagination.js.map +1 -1
  23. package/build/lib/features/Pinning.js +120 -126
  24. package/build/lib/features/Pinning.js.map +1 -1
  25. package/build/lib/features/RowSelection.js +245 -247
  26. package/build/lib/features/RowSelection.js.map +1 -1
  27. package/build/lib/features/Sorting.js +163 -167
  28. package/build/lib/features/Sorting.js.map +1 -1
  29. package/build/lib/features/Visibility.js +60 -66
  30. package/build/lib/features/Visibility.js.map +1 -1
  31. package/build/lib/index.esm.js +1469 -1515
  32. package/build/lib/index.esm.js.map +1 -1
  33. package/build/lib/index.mjs +1469 -1515
  34. package/build/lib/index.mjs.map +1 -1
  35. package/build/umd/index.development.js +1469 -1515
  36. package/build/umd/index.development.js.map +1 -1
  37. package/build/umd/index.production.js +1 -1
  38. package/build/umd/index.production.js.map +1 -1
  39. package/package.json +1 -1
  40. package/src/core/cell.ts +5 -8
  41. package/src/core/column.ts +3 -3
  42. package/src/core/headers.ts +264 -280
  43. package/src/core/row.ts +1 -1
  44. package/src/core/table.ts +4 -3
  45. package/src/features/ColumnSizing.ts +220 -231
  46. package/src/features/Expanding.ts +132 -140
  47. package/src/features/Filters.ts +193 -206
  48. package/src/features/Grouping.ts +94 -110
  49. package/src/features/Ordering.ts +48 -51
  50. package/src/features/Pagination.ts +150 -154
  51. package/src/features/Pinning.ts +158 -178
  52. package/src/features/RowSelection.ts +280 -286
  53. package/src/features/Sorting.ts +196 -206
  54. package/src/features/Visibility.ts +98 -107
@@ -82,206 +82,186 @@ export const Pinning: TableFeature = {
82
82
  createColumn: <TData extends RowData, TValue>(
83
83
  column: Column<TData, TValue>,
84
84
  table: Table<TData>
85
- ): ColumnPinningColumn => {
86
- return {
87
- pin: position => {
88
- const columnIds = column
89
- .getLeafColumns()
90
- .map(d => d.id)
91
- .filter(Boolean) as string[]
92
-
93
- table.setColumnPinning(old => {
94
- if (position === 'right') {
95
- return {
96
- left: (old?.left ?? []).filter(d => !columnIds?.includes(d)),
97
- right: [
98
- ...(old?.right ?? []).filter(d => !columnIds?.includes(d)),
99
- ...columnIds,
100
- ],
101
- }
102
- }
103
-
104
- if (position === 'left') {
105
- return {
106
- left: [
107
- ...(old?.left ?? []).filter(d => !columnIds?.includes(d)),
108
- ...columnIds,
109
- ],
110
- right: (old?.right ?? []).filter(d => !columnIds?.includes(d)),
111
- }
85
+ ): void => {
86
+ column.pin = position => {
87
+ const columnIds = column
88
+ .getLeafColumns()
89
+ .map(d => d.id)
90
+ .filter(Boolean) as string[]
91
+
92
+ table.setColumnPinning(old => {
93
+ if (position === 'right') {
94
+ return {
95
+ left: (old?.left ?? []).filter(d => !columnIds?.includes(d)),
96
+ right: [
97
+ ...(old?.right ?? []).filter(d => !columnIds?.includes(d)),
98
+ ...columnIds,
99
+ ],
112
100
  }
101
+ }
113
102
 
103
+ if (position === 'left') {
114
104
  return {
115
- left: (old?.left ?? []).filter(d => !columnIds?.includes(d)),
105
+ left: [
106
+ ...(old?.left ?? []).filter(d => !columnIds?.includes(d)),
107
+ ...columnIds,
108
+ ],
116
109
  right: (old?.right ?? []).filter(d => !columnIds?.includes(d)),
117
110
  }
118
- })
119
- },
111
+ }
120
112
 
121
- getCanPin: () => {
122
- const leafColumns = column.getLeafColumns()
113
+ return {
114
+ left: (old?.left ?? []).filter(d => !columnIds?.includes(d)),
115
+ right: (old?.right ?? []).filter(d => !columnIds?.includes(d)),
116
+ }
117
+ })
118
+ }
123
119
 
124
- return leafColumns.some(
125
- d =>
126
- (d.columnDef.enablePinning ?? true) &&
127
- (table.options.enablePinning ?? true)
128
- )
129
- },
120
+ column.getCanPin = () => {
121
+ const leafColumns = column.getLeafColumns()
130
122
 
131
- getIsPinned: () => {
132
- const leafColumnIds = column.getLeafColumns().map(d => d.id)
123
+ return leafColumns.some(
124
+ d =>
125
+ (d.columnDef.enablePinning ?? true) &&
126
+ (table.options.enablePinning ?? true)
127
+ )
128
+ }
133
129
 
134
- const { left, right } = table.getState().columnPinning
130
+ column.getIsPinned = () => {
131
+ const leafColumnIds = column.getLeafColumns().map(d => d.id)
135
132
 
136
- const isLeft = leafColumnIds.some(d => left?.includes(d))
137
- const isRight = leafColumnIds.some(d => right?.includes(d))
133
+ const { left, right } = table.getState().columnPinning
138
134
 
139
- return isLeft ? 'left' : isRight ? 'right' : false
140
- },
135
+ const isLeft = leafColumnIds.some(d => left?.includes(d))
136
+ const isRight = leafColumnIds.some(d => right?.includes(d))
141
137
 
142
- getPinnedIndex: () => {
143
- const position = column.getIsPinned()
138
+ return isLeft ? 'left' : isRight ? 'right' : false
139
+ }
144
140
 
145
- return position
146
- ? table.getState().columnPinning?.[position]?.indexOf(column.id) ?? -1
147
- : 0
148
- },
141
+ column.getPinnedIndex = () => {
142
+ const position = column.getIsPinned()
143
+
144
+ return position
145
+ ? table.getState().columnPinning?.[position]?.indexOf(column.id) ?? -1
146
+ : 0
149
147
  }
150
148
  },
151
149
 
152
150
  createRow: <TData extends RowData>(
153
151
  row: Row<TData>,
154
152
  table: Table<TData>
155
- ): ColumnPinningRow<TData> => {
156
- return {
157
- getCenterVisibleCells: memo(
158
- () => [
159
- row._getAllVisibleCells(),
160
- table.getState().columnPinning.left,
161
- table.getState().columnPinning.right,
162
- ],
163
- (allCells, left, right) => {
164
- const leftAndRight: string[] = [...(left ?? []), ...(right ?? [])]
165
-
166
- return allCells.filter(d => !leftAndRight.includes(d.column.id))
167
- },
168
- {
169
- key:
170
- process.env.NODE_ENV === 'production' &&
171
- 'row.getCenterVisibleCells',
172
- debug: () => table.options.debugAll ?? table.options.debugRows,
173
- }
174
- ),
175
- getLeftVisibleCells: memo(
176
- () => [
177
- row._getAllVisibleCells(),
178
- table.getState().columnPinning.left,
179
- ,
180
- ],
181
- (allCells, left) => {
182
- const cells = (left ?? [])
183
- .map(
184
- columnId => allCells.find(cell => cell.column.id === columnId)!
185
- )
186
- .filter(Boolean)
187
- .map(d => ({ ...d, position: 'left' } as Cell<TData, unknown>))
188
-
189
- return cells
190
- },
191
- {
192
- key:
193
- process.env.NODE_ENV === 'production' && 'row.getLeftVisibleCells',
194
- debug: () => table.options.debugAll ?? table.options.debugRows,
195
- }
196
- ),
197
- getRightVisibleCells: memo(
198
- () => [row._getAllVisibleCells(), table.getState().columnPinning.right],
199
- (allCells, right) => {
200
- const cells = (right ?? [])
201
- .map(
202
- columnId => allCells.find(cell => cell.column.id === columnId)!
203
- )
204
- .filter(Boolean)
205
- .map(d => ({ ...d, position: 'right' } as Cell<TData, unknown>))
206
-
207
- return cells
208
- },
209
- {
210
- key:
211
- process.env.NODE_ENV === 'production' && 'row.getRightVisibleCells',
212
- debug: () => table.options.debugAll ?? table.options.debugRows,
213
- }
214
- ),
215
- }
153
+ ): void => {
154
+ row.getCenterVisibleCells = memo(
155
+ () => [
156
+ row._getAllVisibleCells(),
157
+ table.getState().columnPinning.left,
158
+ table.getState().columnPinning.right,
159
+ ],
160
+ (allCells, left, right) => {
161
+ const leftAndRight: string[] = [...(left ?? []), ...(right ?? [])]
162
+
163
+ return allCells.filter(d => !leftAndRight.includes(d.column.id))
164
+ },
165
+ {
166
+ key:
167
+ process.env.NODE_ENV === 'production' && 'row.getCenterVisibleCells',
168
+ debug: () => table.options.debugAll ?? table.options.debugRows,
169
+ }
170
+ )
171
+ row.getLeftVisibleCells = memo(
172
+ () => [row._getAllVisibleCells(), table.getState().columnPinning.left, ,],
173
+ (allCells, left) => {
174
+ const cells = (left ?? [])
175
+ .map(columnId => allCells.find(cell => cell.column.id === columnId)!)
176
+ .filter(Boolean)
177
+ .map(d => ({ ...d, position: 'left' } as Cell<TData, unknown>))
178
+
179
+ return cells
180
+ },
181
+ {
182
+ key: process.env.NODE_ENV === 'production' && 'row.getLeftVisibleCells',
183
+ debug: () => table.options.debugAll ?? table.options.debugRows,
184
+ }
185
+ )
186
+ row.getRightVisibleCells = memo(
187
+ () => [row._getAllVisibleCells(), table.getState().columnPinning.right],
188
+ (allCells, right) => {
189
+ const cells = (right ?? [])
190
+ .map(columnId => allCells.find(cell => cell.column.id === columnId)!)
191
+ .filter(Boolean)
192
+ .map(d => ({ ...d, position: 'right' } as Cell<TData, unknown>))
193
+
194
+ return cells
195
+ },
196
+ {
197
+ key:
198
+ process.env.NODE_ENV === 'production' && 'row.getRightVisibleCells',
199
+ debug: () => table.options.debugAll ?? table.options.debugRows,
200
+ }
201
+ )
216
202
  },
217
203
 
218
- createTable: <TData extends RowData>(
219
- table: Table<TData>
220
- ): ColumnPinningInstance<TData> => {
221
- return {
222
- setColumnPinning: updater =>
223
- table.options.onColumnPinningChange?.(updater),
224
-
225
- resetColumnPinning: defaultState =>
226
- table.setColumnPinning(
227
- defaultState
228
- ? getDefaultPinningState()
229
- : table.initialState?.columnPinning ?? getDefaultPinningState()
230
- ),
231
-
232
- getIsSomeColumnsPinned: position => {
233
- const pinningState = table.getState().columnPinning
234
-
235
- if (!position) {
236
- return Boolean(
237
- pinningState.left?.length || pinningState.right?.length
238
- )
239
- }
240
- return Boolean(pinningState[position]?.length)
241
- },
204
+ createTable: <TData extends RowData>(table: Table<TData>): void => {
205
+ table.setColumnPinning = updater =>
206
+ table.options.onColumnPinningChange?.(updater)
242
207
 
243
- getLeftLeafColumns: memo(
244
- () => [table.getAllLeafColumns(), table.getState().columnPinning.left],
245
- (allColumns, left) => {
246
- return (left ?? [])
247
- .map(columnId => allColumns.find(column => column.id === columnId)!)
248
- .filter(Boolean)
249
- },
250
- {
251
- key: process.env.NODE_ENV === 'development' && 'getLeftLeafColumns',
252
- debug: () => table.options.debugAll ?? table.options.debugColumns,
253
- }
254
- ),
255
-
256
- getRightLeafColumns: memo(
257
- () => [table.getAllLeafColumns(), table.getState().columnPinning.right],
258
- (allColumns, right) => {
259
- return (right ?? [])
260
- .map(columnId => allColumns.find(column => column.id === columnId)!)
261
- .filter(Boolean)
262
- },
263
- {
264
- key: process.env.NODE_ENV === 'development' && 'getRightLeafColumns',
265
- debug: () => table.options.debugAll ?? table.options.debugColumns,
266
- }
267
- ),
268
-
269
- getCenterLeafColumns: memo(
270
- () => [
271
- table.getAllLeafColumns(),
272
- table.getState().columnPinning.left,
273
- table.getState().columnPinning.right,
274
- ],
275
- (allColumns, left, right) => {
276
- const leftAndRight: string[] = [...(left ?? []), ...(right ?? [])]
277
-
278
- return allColumns.filter(d => !leftAndRight.includes(d.id))
279
- },
280
- {
281
- key: process.env.NODE_ENV === 'development' && 'getCenterLeafColumns',
282
- debug: () => table.options.debugAll ?? table.options.debugColumns,
283
- }
284
- ),
208
+ table.resetColumnPinning = defaultState =>
209
+ table.setColumnPinning(
210
+ defaultState
211
+ ? getDefaultPinningState()
212
+ : table.initialState?.columnPinning ?? getDefaultPinningState()
213
+ )
214
+
215
+ table.getIsSomeColumnsPinned = position => {
216
+ const pinningState = table.getState().columnPinning
217
+
218
+ if (!position) {
219
+ return Boolean(pinningState.left?.length || pinningState.right?.length)
220
+ }
221
+ return Boolean(pinningState[position]?.length)
285
222
  }
223
+
224
+ table.getLeftLeafColumns = memo(
225
+ () => [table.getAllLeafColumns(), table.getState().columnPinning.left],
226
+ (allColumns, left) => {
227
+ return (left ?? [])
228
+ .map(columnId => allColumns.find(column => column.id === columnId)!)
229
+ .filter(Boolean)
230
+ },
231
+ {
232
+ key: process.env.NODE_ENV === 'development' && 'getLeftLeafColumns',
233
+ debug: () => table.options.debugAll ?? table.options.debugColumns,
234
+ }
235
+ )
236
+
237
+ table.getRightLeafColumns = memo(
238
+ () => [table.getAllLeafColumns(), table.getState().columnPinning.right],
239
+ (allColumns, right) => {
240
+ return (right ?? [])
241
+ .map(columnId => allColumns.find(column => column.id === columnId)!)
242
+ .filter(Boolean)
243
+ },
244
+ {
245
+ key: process.env.NODE_ENV === 'development' && 'getRightLeafColumns',
246
+ debug: () => table.options.debugAll ?? table.options.debugColumns,
247
+ }
248
+ )
249
+
250
+ table.getCenterLeafColumns = memo(
251
+ () => [
252
+ table.getAllLeafColumns(),
253
+ table.getState().columnPinning.left,
254
+ table.getState().columnPinning.right,
255
+ ],
256
+ (allColumns, left, right) => {
257
+ const leftAndRight: string[] = [...(left ?? []), ...(right ?? [])]
258
+
259
+ return allColumns.filter(d => !leftAndRight.includes(d.id))
260
+ },
261
+ {
262
+ key: process.env.NODE_ENV === 'development' && 'getCenterLeafColumns',
263
+ debug: () => table.options.debugAll ?? table.options.debugColumns,
264
+ }
265
+ )
286
266
  },
287
267
  }