@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
@@ -76,70 +76,63 @@ export const Visibility: TableFeature = {
76
76
  createColumn: <TData extends RowData, TValue>(
77
77
  column: Column<TData, TValue>,
78
78
  table: Table<TData>
79
- ): VisibilityColumn => {
80
- return {
81
- toggleVisibility: value => {
82
- if (column.getCanHide()) {
83
- table.setColumnVisibility(old => ({
84
- ...old,
85
- [column.id]: value ?? !column.getIsVisible(),
86
- }))
87
- }
88
- },
89
- getIsVisible: () => {
90
- return table.getState().columnVisibility?.[column.id] ?? true
91
- },
79
+ ): void => {
80
+ column.toggleVisibility = value => {
81
+ if (column.getCanHide()) {
82
+ table.setColumnVisibility(old => ({
83
+ ...old,
84
+ [column.id]: value ?? !column.getIsVisible(),
85
+ }))
86
+ }
87
+ }
88
+ column.getIsVisible = () => {
89
+ return table.getState().columnVisibility?.[column.id] ?? true
90
+ }
92
91
 
93
- getCanHide: () => {
94
- return (
95
- (column.columnDef.enableHiding ?? true) &&
96
- (table.options.enableHiding ?? true)
92
+ column.getCanHide = () => {
93
+ return (
94
+ (column.columnDef.enableHiding ?? true) &&
95
+ (table.options.enableHiding ?? true)
96
+ )
97
+ }
98
+ column.getToggleVisibilityHandler = () => {
99
+ return (e: unknown) => {
100
+ column.toggleVisibility?.(
101
+ ((e as MouseEvent).target as HTMLInputElement).checked
97
102
  )
98
- },
99
- getToggleVisibilityHandler: () => {
100
- return (e: unknown) => {
101
- column.toggleVisibility?.(
102
- ((e as MouseEvent).target as HTMLInputElement).checked
103
- )
104
- }
105
- },
103
+ }
106
104
  }
107
105
  },
108
106
 
109
107
  createRow: <TData extends RowData>(
110
108
  row: Row<TData>,
111
109
  table: Table<TData>
112
- ): VisibilityRow<TData> => {
113
- return {
114
- _getAllVisibleCells: memo(
115
- () => [row.getAllCells(), table.getState().columnVisibility],
116
- cells => {
117
- return cells.filter(cell => cell.column.getIsVisible())
118
- },
119
- {
120
- key:
121
- process.env.NODE_ENV === 'production' && 'row._getAllVisibleCells',
122
- debug: () => table.options.debugAll ?? table.options.debugRows,
123
- }
124
- ),
125
- getVisibleCells: memo(
126
- () => [
127
- row.getLeftVisibleCells(),
128
- row.getCenterVisibleCells(),
129
- row.getRightVisibleCells(),
130
- ],
131
- (left, center, right) => [...left, ...center, ...right],
132
- {
133
- key: process.env.NODE_ENV === 'development' && 'row.getVisibleCells',
134
- debug: () => table.options.debugAll ?? table.options.debugRows,
135
- }
136
- ),
137
- }
110
+ ): void => {
111
+ row._getAllVisibleCells = memo(
112
+ () => [row.getAllCells(), table.getState().columnVisibility],
113
+ cells => {
114
+ return cells.filter(cell => cell.column.getIsVisible())
115
+ },
116
+ {
117
+ key: process.env.NODE_ENV === 'production' && 'row._getAllVisibleCells',
118
+ debug: () => table.options.debugAll ?? table.options.debugRows,
119
+ }
120
+ )
121
+ row.getVisibleCells = memo(
122
+ () => [
123
+ row.getLeftVisibleCells(),
124
+ row.getCenterVisibleCells(),
125
+ row.getRightVisibleCells(),
126
+ ],
127
+ (left, center, right) => [...left, ...center, ...right],
128
+ {
129
+ key: process.env.NODE_ENV === 'development' && 'row.getVisibleCells',
130
+ debug: () => table.options.debugAll ?? table.options.debugRows,
131
+ }
132
+ )
138
133
  },
139
134
 
140
- createTable: <TData extends RowData>(
141
- table: Table<TData>
142
- ): VisibilityInstance<TData> => {
135
+ createTable: <TData extends RowData>(table: Table<TData>): void => {
143
136
  const makeVisibleColumnsMethod = (
144
137
  key: string,
145
138
  getColumns: () => Column<TData, unknown>[]
@@ -162,64 +155,62 @@ export const Visibility: TableFeature = {
162
155
  )
163
156
  }
164
157
 
165
- return {
166
- getVisibleFlatColumns: makeVisibleColumnsMethod(
167
- 'getVisibleFlatColumns',
168
- () => table.getAllFlatColumns()
169
- ),
170
- getVisibleLeafColumns: makeVisibleColumnsMethod(
171
- 'getVisibleLeafColumns',
172
- () => table.getAllLeafColumns()
173
- ),
174
- getLeftVisibleLeafColumns: makeVisibleColumnsMethod(
175
- 'getLeftVisibleLeafColumns',
176
- () => table.getLeftLeafColumns()
177
- ),
178
- getRightVisibleLeafColumns: makeVisibleColumnsMethod(
179
- 'getRightVisibleLeafColumns',
180
- () => table.getRightLeafColumns()
181
- ),
182
- getCenterVisibleLeafColumns: makeVisibleColumnsMethod(
183
- 'getCenterVisibleLeafColumns',
184
- () => table.getCenterLeafColumns()
185
- ),
186
-
187
- setColumnVisibility: updater =>
188
- table.options.onColumnVisibilityChange?.(updater),
189
-
190
- resetColumnVisibility: defaultState => {
191
- table.setColumnVisibility(
192
- defaultState ? {} : table.initialState.columnVisibility ?? {}
193
- )
194
- },
158
+ table.getVisibleFlatColumns = makeVisibleColumnsMethod(
159
+ 'getVisibleFlatColumns',
160
+ () => table.getAllFlatColumns()
161
+ )
162
+ table.getVisibleLeafColumns = makeVisibleColumnsMethod(
163
+ 'getVisibleLeafColumns',
164
+ () => table.getAllLeafColumns()
165
+ )
166
+ table.getLeftVisibleLeafColumns = makeVisibleColumnsMethod(
167
+ 'getLeftVisibleLeafColumns',
168
+ () => table.getLeftLeafColumns()
169
+ )
170
+ table.getRightVisibleLeafColumns = makeVisibleColumnsMethod(
171
+ 'getRightVisibleLeafColumns',
172
+ () => table.getRightLeafColumns()
173
+ )
174
+ table.getCenterVisibleLeafColumns = makeVisibleColumnsMethod(
175
+ 'getCenterVisibleLeafColumns',
176
+ () => table.getCenterLeafColumns()
177
+ )
178
+
179
+ table.setColumnVisibility = updater =>
180
+ table.options.onColumnVisibilityChange?.(updater)
181
+
182
+ table.resetColumnVisibility = defaultState => {
183
+ table.setColumnVisibility(
184
+ defaultState ? {} : table.initialState.columnVisibility ?? {}
185
+ )
186
+ }
187
+
188
+ table.toggleAllColumnsVisible = value => {
189
+ value = value ?? !table.getIsAllColumnsVisible()
195
190
 
196
- toggleAllColumnsVisible: value => {
197
- value = value ?? !table.getIsAllColumnsVisible()
198
-
199
- table.setColumnVisibility(
200
- table.getAllLeafColumns().reduce(
201
- (obj, column) => ({
202
- ...obj,
203
- [column.id]: !value ? !column.getCanHide?.() : value,
204
- }),
205
- {}
206
- )
191
+ table.setColumnVisibility(
192
+ table.getAllLeafColumns().reduce(
193
+ (obj, column) => ({
194
+ ...obj,
195
+ [column.id]: !value ? !column.getCanHide?.() : value,
196
+ }),
197
+ {}
207
198
  )
208
- },
199
+ )
200
+ }
209
201
 
210
- getIsAllColumnsVisible: () =>
211
- !table.getAllLeafColumns().some(column => !column.getIsVisible?.()),
202
+ table.getIsAllColumnsVisible = () =>
203
+ !table.getAllLeafColumns().some(column => !column.getIsVisible?.())
212
204
 
213
- getIsSomeColumnsVisible: () =>
214
- table.getAllLeafColumns().some(column => column.getIsVisible?.()),
205
+ table.getIsSomeColumnsVisible = () =>
206
+ table.getAllLeafColumns().some(column => column.getIsVisible?.())
215
207
 
216
- getToggleAllColumnsVisibilityHandler: () => {
217
- return (e: unknown) => {
218
- table.toggleAllColumnsVisible(
219
- ((e as MouseEvent).target as HTMLInputElement)?.checked
220
- )
221
- }
222
- },
208
+ table.getToggleAllColumnsVisibilityHandler = () => {
209
+ return (e: unknown) => {
210
+ table.toggleAllColumnsVisible(
211
+ ((e as MouseEvent).target as HTMLInputElement)?.checked
212
+ )
213
+ }
223
214
  }
224
215
  },
225
216
  }