@tanstack/table-core 8.0.0-alpha.63 → 8.0.0-alpha.67

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 (114) hide show
  1. package/build/cjs/core.js +7 -4
  2. package/build/cjs/core.js.map +1 -1
  3. package/build/cjs/features/Cells.js +2 -2
  4. package/build/cjs/features/Cells.js.map +1 -1
  5. package/build/cjs/features/ColumnSizing.js +68 -143
  6. package/build/cjs/features/ColumnSizing.js.map +1 -1
  7. package/build/cjs/features/Columns.js +7 -7
  8. package/build/cjs/features/Columns.js.map +1 -1
  9. package/build/cjs/features/Expanding.js +52 -90
  10. package/build/cjs/features/Expanding.js.map +1 -1
  11. package/build/cjs/features/Filters.js +213 -191
  12. package/build/cjs/features/Filters.js.map +1 -1
  13. package/build/cjs/features/Grouping.js +54 -80
  14. package/build/cjs/features/Grouping.js.map +1 -1
  15. package/build/cjs/features/Headers.js +16 -40
  16. package/build/cjs/features/Headers.js.map +1 -1
  17. package/build/cjs/features/Ordering.js +6 -5
  18. package/build/cjs/features/Ordering.js.map +1 -1
  19. package/build/cjs/features/Pagination.js +5 -5
  20. package/build/cjs/features/Pagination.js.map +1 -1
  21. package/build/cjs/features/Pinning.js +82 -168
  22. package/build/cjs/features/Pinning.js.map +1 -1
  23. package/build/cjs/features/RowSelection.js +67 -119
  24. package/build/cjs/features/RowSelection.js.map +1 -1
  25. package/build/cjs/features/Sorting.js +41 -91
  26. package/build/cjs/features/Sorting.js.map +1 -1
  27. package/build/cjs/features/Visibility.js +20 -43
  28. package/build/cjs/features/Visibility.js.map +1 -1
  29. package/build/cjs/filterFns.js +51 -108
  30. package/build/cjs/filterFns.js.map +1 -1
  31. package/build/cjs/index.js +5 -4
  32. package/build/cjs/index.js.map +1 -1
  33. package/build/cjs/utils/filterRowsUtils.js +21 -0
  34. package/build/cjs/utils/filterRowsUtils.js.map +1 -1
  35. package/build/cjs/utils/getCoreRowModelAsync.js +1 -1
  36. package/build/cjs/utils/getCoreRowModelAsync.js.map +1 -1
  37. package/build/cjs/utils/getCoreRowModelSync.js +1 -1
  38. package/build/cjs/utils/getCoreRowModelSync.js.map +1 -1
  39. package/build/cjs/utils/getExpandedRowModel.js +2 -2
  40. package/build/cjs/utils/getExpandedRowModel.js.map +1 -1
  41. package/build/cjs/utils/getFilteredRowModelSync.js +125 -0
  42. package/build/cjs/utils/getFilteredRowModelSync.js.map +1 -0
  43. package/build/cjs/utils/getGroupedRowModel.js +1 -1
  44. package/build/cjs/utils/getGroupedRowModel.js.map +1 -1
  45. package/build/cjs/utils/getPaginationRowModel.js +1 -1
  46. package/build/cjs/utils/getPaginationRowModel.js.map +1 -1
  47. package/build/cjs/utils/getSortedRowModelSync.js +3 -3
  48. package/build/cjs/utils/getSortedRowModelSync.js.map +1 -1
  49. package/build/cjs/utils.js +2 -6
  50. package/build/cjs/utils.js.map +1 -1
  51. package/build/esm/index.js +899 -1357
  52. package/build/esm/index.js.map +1 -1
  53. package/build/stats-html.html +1 -1
  54. package/build/stats-react.json +404 -418
  55. package/build/types/features/ColumnSizing.d.ts +2 -13
  56. package/build/types/features/Expanding.d.ts +3 -13
  57. package/build/types/features/Filters.d.ts +38 -42
  58. package/build/types/features/Grouping.d.ts +3 -18
  59. package/build/types/features/Ordering.d.ts +2 -6
  60. package/build/types/features/Pinning.d.ts +2 -19
  61. package/build/types/features/RowSelection.d.ts +4 -15
  62. package/build/types/features/Sorting.d.ts +5 -22
  63. package/build/types/features/Visibility.d.ts +2 -15
  64. package/build/types/filterFns.d.ts +10 -52
  65. package/build/types/index.d.ts +1 -2
  66. package/build/types/types.d.ts +2 -4
  67. package/build/types/utils/filterRowsUtils.d.ts +1 -0
  68. package/build/types/utils/{getColumnFilteredRowModelAsync.d.ts → getFilteredRowModelAsync.d.ts} +1 -1
  69. package/build/types/utils/getFilteredRowModelSync.d.ts +2 -0
  70. package/build/types/utils.d.ts +2 -2
  71. package/build/umd/index.development.js +867 -1323
  72. package/build/umd/index.development.js.map +1 -1
  73. package/build/umd/index.production.js +1 -1
  74. package/build/umd/index.production.js.map +1 -1
  75. package/package.json +2 -1
  76. package/src/core.ts +5 -5
  77. package/src/features/Cells.ts +4 -2
  78. package/src/features/ColumnSizing.ts +69 -126
  79. package/src/features/Columns.ts +12 -7
  80. package/src/features/Expanding.ts +62 -107
  81. package/src/features/Filters.ts +293 -243
  82. package/src/features/Grouping.ts +59 -81
  83. package/src/features/Headers.ts +18 -40
  84. package/src/features/Ordering.ts +7 -9
  85. package/src/features/Pagination.ts +4 -3
  86. package/src/features/Pinning.ts +77 -164
  87. package/src/features/RowSelection.ts +76 -123
  88. package/src/features/Sorting.ts +48 -106
  89. package/src/features/Visibility.ts +25 -52
  90. package/src/filterFns.ts +74 -147
  91. package/src/index.ts +1 -2
  92. package/src/types.ts +2 -2
  93. package/src/utils/filterRowsUtils.ts +24 -0
  94. package/src/utils/getCoreRowModelAsync.ts +1 -1
  95. package/src/utils/getCoreRowModelSync.ts +1 -1
  96. package/src/utils/getExpandedRowModel.ts +2 -2
  97. package/src/utils/getFilteredRowModelAsync.ts +157 -0
  98. package/src/utils/getFilteredRowModelSync.ts +141 -0
  99. package/src/utils/getGroupedRowModel.ts +1 -1
  100. package/src/utils/getPaginationRowModel.ts +1 -1
  101. package/src/utils/getSortedRowModelAsync.ts +1 -1
  102. package/src/utils/getSortedRowModelSync.ts +4 -4
  103. package/src/utils.ts +2 -4
  104. package/build/cjs/utils/getColumnFilteredRowModelSync.js +0 -115
  105. package/build/cjs/utils/getColumnFilteredRowModelSync.js.map +0 -1
  106. package/build/cjs/utils/getGlobalFilteredRowModelSync.js +0 -91
  107. package/build/cjs/utils/getGlobalFilteredRowModelSync.js.map +0 -1
  108. package/build/types/utils/getColumnFilteredRowModelSync.d.ts +0 -2
  109. package/build/types/utils/getGlobalFilteredRowModelAsync.d.ts +0 -4
  110. package/build/types/utils/getGlobalFilteredRowModelSync.d.ts +0 -2
  111. package/src/utils/getColumnFilteredRowModelAsync.ts +0 -118
  112. package/src/utils/getColumnFilteredRowModelSync.ts +0 -102
  113. package/src/utils/getGlobalFilteredRowModelAsync.ts +0 -96
  114. package/src/utils/getGlobalFilteredRowModelSync.ts +0 -79
@@ -6,6 +6,7 @@ import {
6
6
  TableGenerics,
7
7
  Row,
8
8
  Cell,
9
+ TableFeature,
9
10
  } from '../types'
10
11
  import { makeStateUpdater, memo } from '../utils'
11
12
 
@@ -31,7 +32,6 @@ export type ColumnPinningDefaultOptions = {
31
32
 
32
33
  export type ColumnPinningColumnDef = {
33
34
  enablePinning?: boolean
34
- defaultCanPin?: boolean
35
35
  }
36
36
 
37
37
  export type ColumnPinningColumn = {
@@ -47,19 +47,9 @@ export type ColumnPinningRow<TGenerics extends TableGenerics> = {
47
47
  getRightVisibleCells: () => Cell<TGenerics>[]
48
48
  }
49
49
 
50
- export type ColumnPinningCell<TGenerics extends TableGenerics> = {
51
- getLeftVisibleCells: () => Cell<TGenerics>[]
52
- getCenterVisibleCells: () => Cell<TGenerics>[]
53
- getRightVisibleCells: () => Cell<TGenerics>[]
54
- }
55
-
56
50
  export type ColumnPinningInstance<TGenerics extends TableGenerics> = {
57
51
  setColumnPinning: (updater: Updater<ColumnPinningState>) => void
58
52
  resetColumnPinning: () => void
59
- pinColumn: (columnId: string, position: ColumnPinningPosition) => void
60
- getColumnCanPin: (columnId: string) => boolean
61
- getColumnIsPinned: (columnId: string) => ColumnPinningPosition
62
- getColumnPinnedIndex: (columnId: string) => number
63
53
  getIsSomeColumnsPinned: () => boolean
64
54
  getLeftLeafColumns: () => Column<TGenerics>[]
65
55
  getRightLeafColumns: () => Column<TGenerics>[]
@@ -68,13 +58,14 @@ export type ColumnPinningInstance<TGenerics extends TableGenerics> = {
68
58
 
69
59
  //
70
60
 
71
- export const Pinning = {
72
- getInitialState: (): ColumnPinningTableState => {
61
+ export const Pinning: TableFeature = {
62
+ getInitialState: (state): ColumnPinningTableState => {
73
63
  return {
74
64
  columnPinning: {
75
65
  left: [],
76
66
  right: [],
77
67
  },
68
+ ...state,
78
69
  }
79
70
  },
80
71
 
@@ -91,10 +82,69 @@ export const Pinning = {
91
82
  instance: TableInstance<TGenerics>
92
83
  ): ColumnPinningColumn => {
93
84
  return {
94
- getCanPin: () => instance.getColumnCanPin(column.id),
95
- getPinnedIndex: () => instance.getColumnPinnedIndex(column.id),
96
- getIsPinned: () => instance.getColumnIsPinned(column.id),
97
- pin: position => instance.pinColumn(column.id, position),
85
+ pin: position => {
86
+ const columnIds = column
87
+ .getLeafColumns()
88
+ .map(d => d.id)
89
+ .filter(Boolean) as string[]
90
+
91
+ instance.setColumnPinning(old => {
92
+ if (position === 'right') {
93
+ return {
94
+ left: (old?.left ?? []).filter(d => !columnIds?.includes(d)),
95
+ right: [
96
+ ...(old?.right ?? []).filter(d => !columnIds?.includes(d)),
97
+ ...columnIds,
98
+ ],
99
+ }
100
+ }
101
+
102
+ if (position === 'left') {
103
+ return {
104
+ left: [
105
+ ...(old?.left ?? []).filter(d => !columnIds?.includes(d)),
106
+ ...columnIds,
107
+ ],
108
+ right: (old?.right ?? []).filter(d => !columnIds?.includes(d)),
109
+ }
110
+ }
111
+
112
+ return {
113
+ left: (old?.left ?? []).filter(d => !columnIds?.includes(d)),
114
+ right: (old?.right ?? []).filter(d => !columnIds?.includes(d)),
115
+ }
116
+ })
117
+ },
118
+
119
+ getCanPin: () => {
120
+ const leafColumns = column.getLeafColumns()
121
+
122
+ return leafColumns.some(
123
+ d =>
124
+ (d.enablePinning ?? true) &&
125
+ (instance.options.enablePinning ?? true)
126
+ )
127
+ },
128
+
129
+ getIsPinned: () => {
130
+ const leafColumnIds = column.getLeafColumns().map(d => d.id)
131
+
132
+ const { left, right } = instance.getState().columnPinning
133
+
134
+ const isLeft = leafColumnIds.some(d => left?.includes(d))
135
+ const isRight = leafColumnIds.some(d => right?.includes(d))
136
+
137
+ return isLeft ? 'left' : isRight ? 'right' : false
138
+ },
139
+
140
+ getPinnedIndex: () => {
141
+ const position = column.getIsPinned()
142
+
143
+ return position
144
+ ? instance.getState().columnPinning?.[position]?.indexOf(column.id) ??
145
+ -1
146
+ : 0
147
+ },
98
148
  }
99
149
  },
100
150
 
@@ -115,7 +165,9 @@ export const Pinning = {
115
165
  return allCells.filter(d => !leftAndRight.includes(d.columnId))
116
166
  },
117
167
  {
118
- key: 'row.getCenterVisibleCells',
168
+ key:
169
+ process.env.NODE_ENV === 'production' &&
170
+ 'row.getCenterVisibleCells',
119
171
  debug: () => instance.options.debugAll ?? instance.options.debugRows,
120
172
  }
121
173
  ),
@@ -134,7 +186,8 @@ export const Pinning = {
134
186
  return cells
135
187
  },
136
188
  {
137
- key: 'row.getLeftVisibleCells',
189
+ key:
190
+ process.env.NODE_ENV === 'production' && 'row.getLeftVisibleCells',
138
191
  debug: () => instance.options.debugAll ?? instance.options.debugRows,
139
192
  }
140
193
  ),
@@ -152,68 +205,8 @@ export const Pinning = {
152
205
  return cells
153
206
  },
154
207
  {
155
- key: 'row.getRightVisibleCells',
156
- debug: () => instance.options.debugAll ?? instance.options.debugRows,
157
- }
158
- ),
159
- }
160
- },
161
-
162
- createCell: <TGenerics extends TableGenerics>(
163
- cell: Cell<TGenerics>,
164
- instance: TableInstance<TGenerics>
165
- ): ColumnPinningCell<TGenerics> => {
166
- return {
167
- getCenterVisibleCells: memo(
168
- () => [
169
- cell.row._getAllVisibleCells(),
170
- instance.getState().columnPinning.left,
171
- instance.getState().columnPinning.right,
172
- ],
173
- (allCells, left, right) => {
174
- const leftAndRight: string[] = [...(left ?? []), ...(right ?? [])]
175
-
176
- return allCells.filter(d => !leftAndRight.includes(d.columnId))
177
- },
178
- {
179
- key: 'row.getCenterVisibleCells',
180
- debug: () => instance.options.debugAll ?? instance.options.debugRows,
181
- }
182
- ),
183
- getLeftVisibleCells: memo(
184
- () => [
185
- cell.row._getAllVisibleCells(),
186
- instance.getState().columnPinning.left,
187
- ,
188
- ],
189
- (allCells, left) => {
190
- const cells = (left ?? [])
191
- .map(columnId => allCells.find(cell => cell.columnId === columnId)!)
192
- .filter(Boolean)
193
- .map(d => ({ ...d, position: 'left' } as Cell<TGenerics>))
194
-
195
- return cells
196
- },
197
- {
198
- key: 'row.getLeftVisibleCells',
199
- debug: () => instance.options.debugAll ?? instance.options.debugRows,
200
- }
201
- ),
202
- getRightVisibleCells: memo(
203
- () => [
204
- cell.row._getAllVisibleCells(),
205
- instance.getState().columnPinning.right,
206
- ],
207
- (allCells, right) => {
208
- const cells = (right ?? [])
209
- .map(columnId => allCells.find(cell => cell.columnId === columnId)!)
210
- .filter(Boolean)
211
- .map(d => ({ ...d, position: 'left' } as Cell<TGenerics>))
212
-
213
- return cells
214
- },
215
- {
216
- key: 'row.getRightVisibleCells',
208
+ key:
209
+ process.env.NODE_ENV === 'production' && 'row.getRightVisibleCells',
217
210
  debug: () => instance.options.debugAll ?? instance.options.debugRows,
218
211
  }
219
212
  ),
@@ -230,86 +223,6 @@ export const Pinning = {
230
223
  resetColumnPinning: () =>
231
224
  instance.setColumnPinning(instance.initialState?.columnPinning ?? {}),
232
225
 
233
- pinColumn: (columnId, position) => {
234
- const column = instance.getColumn(columnId)
235
-
236
- const columnIds = column
237
- ?.getLeafColumns()
238
- .map(d => d.id)
239
- .filter(Boolean) as string[]
240
-
241
- instance.setColumnPinning(old => {
242
- if (position === 'right') {
243
- return {
244
- left: (old?.left ?? []).filter(d => !columnIds?.includes(d)),
245
- right: [
246
- ...(old?.right ?? []).filter(d => !columnIds?.includes(d)),
247
- ...columnIds,
248
- ],
249
- }
250
- }
251
-
252
- if (position === 'left') {
253
- return {
254
- left: [
255
- ...(old?.left ?? []).filter(d => !columnIds?.includes(d)),
256
- ...columnIds,
257
- ],
258
- right: (old?.right ?? []).filter(d => !columnIds?.includes(d)),
259
- }
260
- }
261
-
262
- return {
263
- left: (old?.left ?? []).filter(d => !columnIds?.includes(d)),
264
- right: (old?.right ?? []).filter(d => !columnIds?.includes(d)),
265
- }
266
- })
267
- },
268
-
269
- getColumnCanPin: columnId => {
270
- const column = instance.getColumn(columnId)
271
-
272
- if (!column) {
273
- throw new Error()
274
- }
275
-
276
- const leafColumns = column.getLeafColumns()
277
-
278
- return leafColumns.some(
279
- d =>
280
- d.enablePinning ??
281
- instance.options.enablePinning ??
282
- d.defaultCanPin ??
283
- !!d.accessorFn
284
- )
285
- },
286
-
287
- getColumnIsPinned: columnId => {
288
- const column = instance.getColumn(columnId)
289
-
290
- if (!column) {
291
- throw new Error()
292
- }
293
-
294
- const leafColumnIds = column.getLeafColumns().map(d => d.id)
295
-
296
- const { left, right } = instance.getState().columnPinning
297
-
298
- const isLeft = leafColumnIds.some(d => left?.includes(d))
299
- const isRight = leafColumnIds.some(d => right?.includes(d))
300
-
301
- return isLeft ? 'left' : isRight ? 'right' : false
302
- },
303
-
304
- getColumnPinnedIndex: columnId => {
305
- const position = instance.getColumnIsPinned(columnId)
306
-
307
- return position
308
- ? instance.getState().columnPinning?.[position]?.indexOf(columnId) ??
309
- -1
310
- : 0
311
- },
312
-
313
226
  getIsSomeColumnsPinned: () => {
314
227
  const { left, right } = instance.getState().columnPinning
315
228
 
@@ -327,7 +240,7 @@ export const Pinning = {
327
240
  .filter(Boolean)
328
241
  },
329
242
  {
330
- key: 'getLeftLeafColumns',
243
+ key: process.env.NODE_ENV === 'development' && 'getLeftLeafColumns',
331
244
  debug: () =>
332
245
  instance.options.debugAll ?? instance.options.debugColumns,
333
246
  }
@@ -344,7 +257,7 @@ export const Pinning = {
344
257
  .filter(Boolean)
345
258
  },
346
259
  {
347
- key: 'getRightLeafColumns',
260
+ key: process.env.NODE_ENV === 'development' && 'getRightLeafColumns',
348
261
  debug: () =>
349
262
  instance.options.debugAll ?? instance.options.debugColumns,
350
263
  }
@@ -362,7 +275,7 @@ export const Pinning = {
362
275
  return allColumns.filter(d => !leftAndRight.includes(d.id))
363
276
  },
364
277
  {
365
- key: 'getCenterLeafColumns',
278
+ key: process.env.NODE_ENV === 'development' && 'getCenterLeafColumns',
366
279
  debug: () =>
367
280
  instance.options.debugAll ?? instance.options.debugColumns,
368
281
  }
@@ -5,6 +5,7 @@ import {
5
5
  Row,
6
6
  RowModel,
7
7
  Updater,
8
+ TableFeature,
8
9
  } from '../types'
9
10
  import { makeStateUpdater, memo } from '../utils'
10
11
 
@@ -15,10 +16,10 @@ export type RowSelectionTableState = {
15
16
  }
16
17
 
17
18
  export type RowSelectionOptions<TGenerics extends TableGenerics> = {
18
- onRowSelectionChange?: OnChangeFn<RowSelectionState>
19
19
  enableRowSelection?: boolean | ((row: Row<TGenerics>) => boolean)
20
20
  enableMultiRowSelection?: boolean | ((row: Row<TGenerics>) => boolean)
21
21
  enableSubRowSelection?: boolean | ((row: Row<TGenerics>) => boolean)
22
+ onRowSelectionChange?: OnChangeFn<RowSelectionState>
22
23
  // enableGroupingRowSelection?:
23
24
  // | boolean
24
25
  // | ((
@@ -43,25 +44,16 @@ export type RowSelectionRow = {
43
44
  getIsSomeSelected: () => boolean
44
45
  getCanSelect: () => boolean
45
46
  getCanMultiSelect: () => boolean
47
+ getCanSelectSubRows: () => boolean
46
48
  toggleSelected: (value?: boolean) => void
47
49
  getToggleSelectedHandler: () => (event: unknown) => void
48
50
  }
49
51
 
50
52
  export type RowSelectionInstance<TGenerics extends TableGenerics> = {
51
- getToggleRowSelectedHandler: (
52
- rowId: string
53
- ) => undefined | ((e: unknown) => void)
54
53
  getToggleAllRowsSelectedHandler: () => (event: unknown) => void
55
54
  getToggleAllPageRowsSelectedHandler: () => (event: unknown) => void
56
55
  setRowSelection: (updater: Updater<RowSelectionState>) => void
57
56
  resetRowSelection: () => void
58
- toggleRowSelected: (rowId: string, value?: boolean) => void
59
- getRowCanSelect: (rowId: string) => boolean
60
- getRowCanSelectSubRows: (rowId: string) => boolean
61
- getRowCanMultiSelect: (rowId: string) => boolean
62
- // getGroupingRowCanSelect: (rowId: string) => boolean
63
- getRowIsSelected: (rowId: string) => boolean
64
- getRowIsSomeSelected: (rowId: string) => boolean
65
57
  getIsAllRowsSelected: () => boolean
66
58
  getIsAllPageRowsSelected: () => boolean
67
59
  getIsSomeRowsSelected: () => boolean
@@ -76,10 +68,11 @@ export type RowSelectionInstance<TGenerics extends TableGenerics> = {
76
68
 
77
69
  //
78
70
 
79
- export const RowSelection = {
80
- getInitialState: (): RowSelectionTableState => {
71
+ export const RowSelection: TableFeature = {
72
+ getInitialState: (state): RowSelectionTableState => {
81
73
  return {
82
74
  rowSelection: {},
75
+ ...state,
83
76
  }
84
77
  },
85
78
 
@@ -146,24 +139,7 @@ export const RowSelection = {
146
139
 
147
140
  return rowSelection
148
141
  }),
149
- toggleRowSelected: (rowId, value) => {
150
- const row = instance.getRow(rowId)
151
- const isSelected = row.getIsSelected()
152
-
153
- instance.setRowSelection(old => {
154
- value = typeof value !== 'undefined' ? value : !isSelected
155
-
156
- if (isSelected === value) {
157
- return old
158
- }
159
-
160
- const selectedRowIds = { ...old }
161
142
 
162
- mutateRowIsSelected(selectedRowIds, rowId, value, instance)
163
-
164
- return selectedRowIds
165
- })
166
- },
167
143
  // addRowSelectionRange: rowId => {
168
144
  // const {
169
145
  // rows,
@@ -237,7 +213,7 @@ export const RowSelection = {
237
213
  return selectRowsFn(instance, rowModel)
238
214
  },
239
215
  {
240
- key: 'getSelectedRowModel',
216
+ key: process.env.NODE_ENV === 'development' && 'getSelectedRowModel',
241
217
  debug: () => instance.options.debugAll ?? instance.options.debugTable,
242
218
  }
243
219
  ),
@@ -245,7 +221,7 @@ export const RowSelection = {
245
221
  getFilteredSelectedRowModel: memo(
246
222
  () => [
247
223
  instance.getState().rowSelection,
248
- instance.getGlobalFilteredRowModel(),
224
+ instance.getFilteredRowModel(),
249
225
  ],
250
226
  (rowSelection, rowModel) => {
251
227
  if (!Object.keys(rowSelection).length) {
@@ -259,7 +235,9 @@ export const RowSelection = {
259
235
  return selectRowsFn(instance, rowModel)
260
236
  },
261
237
  {
262
- key: 'getFilteredSelectedRowModel',
238
+ key:
239
+ process.env.NODE_ENV === 'production' &&
240
+ 'getFilteredSelectedRowModel',
263
241
  debug: () => instance.options.debugAll ?? instance.options.debugTable,
264
242
  }
265
243
  ),
@@ -278,77 +256,15 @@ export const RowSelection = {
278
256
  return selectRowsFn(instance, rowModel)
279
257
  },
280
258
  {
281
- key: 'getGroupedSelectedRowModel',
259
+ key:
260
+ process.env.NODE_ENV === 'production' &&
261
+ 'getGroupedSelectedRowModel',
282
262
  debug: () => instance.options.debugAll ?? instance.options.debugTable,
283
263
  }
284
264
  ),
285
265
 
286
266
  ///
287
267
 
288
- getRowIsSelected: rowId => {
289
- const { rowSelection } = instance.getState()
290
- const row = instance.getRow(rowId)
291
-
292
- if (!row) {
293
- throw new Error()
294
- }
295
-
296
- return isRowSelected(row, rowSelection, instance) === true
297
- },
298
-
299
- getRowIsSomeSelected: rowId => {
300
- const { rowSelection } = instance.getState()
301
- const row = instance.getRow(rowId)
302
-
303
- if (!row) {
304
- throw new Error()
305
- }
306
-
307
- return isRowSelected(row, rowSelection, instance) === 'some'
308
- },
309
-
310
- getRowCanSelect: rowId => {
311
- const row = instance.getRow(rowId)
312
-
313
- if (!row) {
314
- throw new Error()
315
- }
316
-
317
- if (typeof instance.options.enableRowSelection === 'function') {
318
- return instance.options.enableRowSelection(row)
319
- }
320
-
321
- return instance.options.enableRowSelection ?? true
322
- },
323
-
324
- getRowCanSelectSubRows: rowId => {
325
- const row = instance.getRow(rowId)
326
-
327
- if (!row) {
328
- throw new Error()
329
- }
330
-
331
- if (typeof instance.options.enableSubRowSelection === 'function') {
332
- return instance.options.enableSubRowSelection(row)
333
- }
334
-
335
- return instance.options.enableSubRowSelection ?? true
336
- },
337
-
338
- getRowCanMultiSelect: rowId => {
339
- const row = instance.getRow(rowId)
340
-
341
- if (!row) {
342
- throw new Error()
343
- }
344
-
345
- if (typeof instance.options.enableMultiRowSelection === 'function') {
346
- return instance.options.enableMultiRowSelection(row)
347
- }
348
-
349
- return instance.options.enableMultiRowSelection ?? true
350
- },
351
-
352
268
  // getGroupingRowCanSelect: rowId => {
353
269
  // const row = instance.getRow(rowId)
354
270
 
@@ -364,8 +280,7 @@ export const RowSelection = {
364
280
  // },
365
281
 
366
282
  getIsAllRowsSelected: () => {
367
- const preFilteredFlatRows =
368
- instance.getPreGlobalFilteredRowModel().flatRows
283
+ const preFilteredFlatRows = instance.getPreFilteredRowModel().flatRows
369
284
  const { rowSelection } = instance.getState()
370
285
 
371
286
  let isAllRowsSelected = Boolean(
@@ -411,21 +326,6 @@ export const RowSelection = {
411
326
  : !!paginationFlatRows?.length
412
327
  },
413
328
 
414
- getToggleRowSelectedHandler: rowId => {
415
- const row = instance.getRow(rowId)
416
-
417
- const isSelected = row.getIsSelected()
418
- const isSomeSelected = row.getIsSomeSelected()
419
- const canSelect = row.getCanSelect()
420
-
421
- return (e: unknown) => {
422
- if (!canSelect) return
423
- row.toggleSelected(
424
- ((e as MouseEvent).target as HTMLInputElement)?.checked
425
- )
426
- }
427
- },
428
-
429
329
  getToggleAllRowsSelectedHandler: () => {
430
330
  return (e: unknown) => {
431
331
  instance.toggleAllRowsSelected(
@@ -449,13 +349,66 @@ export const RowSelection = {
449
349
  instance: TableInstance<TGenerics>
450
350
  ): RowSelectionRow => {
451
351
  return {
452
- getIsSelected: () => instance.getRowIsSelected(row.id),
453
- getIsSomeSelected: () => instance.getRowIsSomeSelected(row.id),
454
- toggleSelected: value => instance.toggleRowSelected(row.id, value),
455
- getToggleSelectedHandler: () =>
456
- instance.getToggleRowSelectedHandler(row.id)!,
457
- getCanMultiSelect: () => instance.getRowCanMultiSelect(row.id),
458
- getCanSelect: () => instance.getRowCanSelect(row.id),
352
+ toggleSelected: value => {
353
+ const isSelected = row.getIsSelected()
354
+
355
+ instance.setRowSelection(old => {
356
+ value = typeof value !== 'undefined' ? value : !isSelected
357
+
358
+ if (isSelected === value) {
359
+ return old
360
+ }
361
+
362
+ const selectedRowIds = { ...old }
363
+
364
+ mutateRowIsSelected(selectedRowIds, row.id, value, instance)
365
+
366
+ return selectedRowIds
367
+ })
368
+ },
369
+ getIsSelected: () => {
370
+ const { rowSelection } = instance.getState()
371
+ return isRowSelected(row, rowSelection, instance) === true
372
+ },
373
+
374
+ getIsSomeSelected: () => {
375
+ const { rowSelection } = instance.getState()
376
+ return isRowSelected(row, rowSelection, instance) === 'some'
377
+ },
378
+
379
+ getCanSelect: () => {
380
+ if (typeof instance.options.enableRowSelection === 'function') {
381
+ return instance.options.enableRowSelection(row)
382
+ }
383
+
384
+ return instance.options.enableRowSelection ?? true
385
+ },
386
+
387
+ getCanSelectSubRows: () => {
388
+ if (typeof instance.options.enableSubRowSelection === 'function') {
389
+ return instance.options.enableSubRowSelection(row)
390
+ }
391
+
392
+ return instance.options.enableSubRowSelection ?? true
393
+ },
394
+
395
+ getCanMultiSelect: () => {
396
+ if (typeof instance.options.enableMultiRowSelection === 'function') {
397
+ return instance.options.enableMultiRowSelection(row)
398
+ }
399
+
400
+ return instance.options.enableMultiRowSelection ?? true
401
+ },
402
+ getToggleSelectedHandler: () => {
403
+ const canSelect = row.getCanSelect()
404
+
405
+ return (e: unknown) => {
406
+ if (!canSelect) return
407
+ row.toggleSelected(
408
+ ((e as MouseEvent).target as HTMLInputElement)?.checked
409
+ )
410
+ }
411
+ },
459
412
  }
460
413
  },
461
414
  }
@@ -481,7 +434,7 @@ const mutateRowIsSelected = <TGenerics extends TableGenerics>(
481
434
  }
482
435
  // }
483
436
 
484
- if (row.subRows?.length && instance.getRowCanSelectSubRows(row.id)) {
437
+ if (row.subRows?.length && row.getCanSelectSubRows()) {
485
438
  row.subRows.forEach(row =>
486
439
  mutateRowIsSelected(selectedRowIds, row.id, value, instance)
487
440
  )