@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.
Files changed (127) hide show
  1. package/build/cjs/core/cell.js +13 -13
  2. package/build/cjs/core/cell.js.map +1 -1
  3. package/build/cjs/core/column.js +20 -21
  4. package/build/cjs/core/column.js.map +1 -1
  5. package/build/cjs/core/headers.js +63 -68
  6. package/build/cjs/core/headers.js.map +1 -1
  7. package/build/cjs/core/row.js +16 -11
  8. package/build/cjs/core/row.js.map +1 -1
  9. package/build/cjs/core/{instance.js → table.js} +46 -57
  10. package/build/cjs/core/table.js.map +1 -0
  11. package/build/cjs/features/ColumnSizing.js +36 -36
  12. package/build/cjs/features/ColumnSizing.js.map +1 -1
  13. package/build/cjs/features/Expanding.js +34 -34
  14. package/build/cjs/features/Expanding.js.map +1 -1
  15. package/build/cjs/features/Filters.js +46 -52
  16. package/build/cjs/features/Filters.js.map +1 -1
  17. package/build/cjs/features/Grouping.js +24 -49
  18. package/build/cjs/features/Grouping.js.map +1 -1
  19. package/build/cjs/features/Ordering.js +8 -8
  20. package/build/cjs/features/Ordering.js.map +1 -1
  21. package/build/cjs/features/Pagination.js +37 -37
  22. package/build/cjs/features/Pagination.js.map +1 -1
  23. package/build/cjs/features/Pinning.js +33 -33
  24. package/build/cjs/features/Pinning.js.map +1 -1
  25. package/build/cjs/features/RowSelection.js +86 -74
  26. package/build/cjs/features/RowSelection.js.map +1 -1
  27. package/build/cjs/features/Sorting.js +36 -40
  28. package/build/cjs/features/Sorting.js.map +1 -1
  29. package/build/cjs/features/Visibility.js +30 -30
  30. package/build/cjs/features/Visibility.js.map +1 -1
  31. package/build/cjs/index.js +3 -4
  32. package/build/cjs/index.js.map +1 -1
  33. package/build/cjs/utils/filterRowsUtils.js +8 -8
  34. package/build/cjs/utils/filterRowsUtils.js.map +1 -1
  35. package/build/cjs/utils/getCoreRowModel.js +8 -8
  36. package/build/cjs/utils/getCoreRowModel.js.map +1 -1
  37. package/build/cjs/utils/getExpandedRowModel.js +4 -4
  38. package/build/cjs/utils/getExpandedRowModel.js.map +1 -1
  39. package/build/cjs/utils/getFacetedMinMaxValues.js +3 -3
  40. package/build/cjs/utils/getFacetedMinMaxValues.js.map +1 -1
  41. package/build/cjs/utils/getFacetedRowModel.js +4 -4
  42. package/build/cjs/utils/getFacetedRowModel.js.map +1 -1
  43. package/build/cjs/utils/getFacetedUniqueValues.js +3 -3
  44. package/build/cjs/utils/getFacetedUniqueValues.js.map +1 -1
  45. package/build/cjs/utils/getFilteredRowModel.js +8 -8
  46. package/build/cjs/utils/getFilteredRowModel.js.map +1 -1
  47. package/build/cjs/utils/getGroupedRowModel.js +9 -9
  48. package/build/cjs/utils/getGroupedRowModel.js.map +1 -1
  49. package/build/cjs/utils/getPaginationRowModel.js +4 -4
  50. package/build/cjs/utils/getPaginationRowModel.js.map +1 -1
  51. package/build/cjs/utils/getSortedRowModel.js +7 -7
  52. package/build/cjs/utils/getSortedRowModel.js.map +1 -1
  53. package/build/cjs/utils.js +2 -2
  54. package/build/cjs/utils.js.map +1 -1
  55. package/build/esm/index.js +585 -677
  56. package/build/esm/index.js.map +1 -1
  57. package/build/stats-html.html +1 -1
  58. package/build/stats-react.json +352 -377
  59. package/build/types/index.d.ts +761 -29
  60. package/build/umd/index.development.js +586 -678
  61. package/build/umd/index.development.js.map +1 -1
  62. package/build/umd/index.production.js +1 -1
  63. package/build/umd/index.production.js.map +1 -1
  64. package/package.json +1 -1
  65. package/src/core/cell.ts +34 -28
  66. package/src/core/column.ts +83 -72
  67. package/src/core/headers.ts +118 -149
  68. package/src/core/row.ts +31 -25
  69. package/src/core/{instance.ts → table.ts} +85 -116
  70. package/src/features/ColumnSizing.ts +45 -47
  71. package/src/features/Expanding.ts +53 -59
  72. package/src/features/Filters.ts +112 -132
  73. package/src/features/Grouping.ts +63 -112
  74. package/src/features/Ordering.ts +19 -21
  75. package/src/features/Pagination.ts +54 -55
  76. package/src/features/Pinning.ts +49 -61
  77. package/src/features/RowSelection.ts +115 -114
  78. package/src/features/Sorting.ts +57 -72
  79. package/src/features/Visibility.ts +48 -48
  80. package/src/index.ts +1 -2
  81. package/src/types.ts +64 -69
  82. package/src/utils/filterRowsUtils.ts +33 -28
  83. package/src/utils/getCoreRowModel.ts +22 -22
  84. package/src/utils/getExpandedRowModel.ts +15 -15
  85. package/src/utils/getFacetedMinMaxValues.ts +6 -6
  86. package/src/utils/getFacetedRowModel.ts +12 -12
  87. package/src/utils/getFacetedUniqueValues.ts +6 -6
  88. package/src/utils/getFilteredRowModel.ts +17 -17
  89. package/src/utils/getGroupedRowModel.ts +18 -21
  90. package/src/utils/getPaginationRowModel.ts +10 -13
  91. package/src/utils/getSortedRowModel.ts +14 -14
  92. package/src/utils.ts +8 -2
  93. package/build/cjs/core/instance.js.map +0 -1
  94. package/build/cjs/createTable.js +0 -72
  95. package/build/cjs/createTable.js.map +0 -1
  96. package/build/types/aggregationFns.d.ts +0 -13
  97. package/build/types/core/cell.d.ts +0 -9
  98. package/build/types/core/column.d.ts +0 -40
  99. package/build/types/core/headers.d.ts +0 -46
  100. package/build/types/core/instance.d.ts +0 -58
  101. package/build/types/core/row.d.ts +0 -15
  102. package/build/types/createTable.d.ts +0 -63
  103. package/build/types/features/ColumnSizing.d.ts +0 -63
  104. package/build/types/features/Expanding.d.ts +0 -39
  105. package/build/types/features/Filters.d.ts +0 -90
  106. package/build/types/features/Grouping.d.ts +0 -68
  107. package/build/types/features/Ordering.d.ts +0 -18
  108. package/build/types/features/Pagination.d.ts +0 -42
  109. package/build/types/features/Pinning.d.ts +0 -40
  110. package/build/types/features/RowSelection.d.ts +0 -40
  111. package/build/types/features/Sorting.d.ts +0 -63
  112. package/build/types/features/Visibility.d.ts +0 -40
  113. package/build/types/filterFns.d.ts +0 -13
  114. package/build/types/sortingFns.d.ts +0 -11
  115. package/build/types/types.d.ts +0 -53
  116. package/build/types/utils/filterRowsUtils.d.ts +0 -4
  117. package/build/types/utils/getCoreRowModel.d.ts +0 -2
  118. package/build/types/utils/getExpandedRowModel.d.ts +0 -7
  119. package/build/types/utils/getFacetedMinMaxValues.d.ts +0 -2
  120. package/build/types/utils/getFacetedRowModel.d.ts +0 -2
  121. package/build/types/utils/getFacetedUniqueValues.d.ts +0 -2
  122. package/build/types/utils/getFilteredRowModel.d.ts +0 -2
  123. package/build/types/utils/getGroupedRowModel.d.ts +0 -2
  124. package/build/types/utils/getPaginationRowModel.d.ts +0 -4
  125. package/build/types/utils/getSortedRowModel.d.ts +0 -2
  126. package/build/types/utils.d.ts +0 -19
  127. package/src/createTable.ts +0 -188
@@ -1,11 +1,12 @@
1
- import { TableFeature } from '../core/instance'
1
+ import { TableFeature } from '../core/table'
2
2
  import {
3
3
  OnChangeFn,
4
4
  TableGenerics,
5
- TableInstance,
5
+ Table,
6
6
  Row,
7
7
  RowModel,
8
8
  Updater,
9
+ RowData,
9
10
  } from '../types'
10
11
  import { makeStateUpdater, memo } from '../utils'
11
12
 
@@ -15,33 +16,28 @@ export type RowSelectionTableState = {
15
16
  rowSelection: RowSelectionState
16
17
  }
17
18
 
18
- export type RowSelectionOptions<TGenerics extends TableGenerics> = {
19
- enableRowSelection?: boolean | ((row: Row<TGenerics>) => boolean)
20
- enableMultiRowSelection?: boolean | ((row: Row<TGenerics>) => boolean)
21
- enableSubRowSelection?: boolean | ((row: Row<TGenerics>) => boolean)
19
+ export type RowSelectionOptions<TData extends RowData> = {
20
+ enableRowSelection?: boolean | ((row: Row<TData>) => boolean)
21
+ enableMultiRowSelection?: boolean | ((row: Row<TData>) => boolean)
22
+ enableSubRowSelection?: boolean | ((row: Row<TData>) => boolean)
22
23
  onRowSelectionChange?: OnChangeFn<RowSelectionState>
23
24
  // enableGroupingRowSelection?:
24
25
  // | boolean
25
26
  // | ((
26
- // row: Row<TGenerics>
27
+ // row: Row<TData>
27
28
  // ) => boolean)
28
29
  // isAdditiveSelectEvent?: (e: unknown) => boolean
29
30
  // isInclusiveSelectEvent?: (e: unknown) => boolean
30
31
  // selectRowsFn?: (
31
- // instance: TableInstance<
32
- // TData,
33
- // TValue,
34
- // TFilterFns,
35
- // TSortingFns,
36
- // TAggregationFns
37
- // >,
38
- // rowModel: RowModel<TGenerics>
39
- // ) => RowModel<TGenerics>
32
+ // table: Table<TData>,
33
+ // rowModel: RowModel<TData>
34
+ // ) => RowModel<TData>
40
35
  }
41
36
 
42
37
  export type RowSelectionRow = {
43
38
  getIsSelected: () => boolean
44
39
  getIsSomeSelected: () => boolean
40
+ getIsAllSubRowsSelected: () => boolean
45
41
  getCanSelect: () => boolean
46
42
  getCanMultiSelect: () => boolean
47
43
  getCanSelectSubRows: () => boolean
@@ -49,7 +45,7 @@ export type RowSelectionRow = {
49
45
  getToggleSelectedHandler: () => (event: unknown) => void
50
46
  }
51
47
 
52
- export type RowSelectionInstance<TGenerics extends TableGenerics> = {
48
+ export type RowSelectionInstance<TData extends RowData> = {
53
49
  getToggleAllRowsSelectedHandler: () => (event: unknown) => void
54
50
  getToggleAllPageRowsSelectedHandler: () => (event: unknown) => void
55
51
  setRowSelection: (updater: Updater<RowSelectionState>) => void
@@ -60,10 +56,10 @@ export type RowSelectionInstance<TGenerics extends TableGenerics> = {
60
56
  getIsSomePageRowsSelected: () => boolean
61
57
  toggleAllRowsSelected: (value?: boolean) => void
62
58
  toggleAllPageRowsSelected: (value?: boolean) => void
63
- getPreSelectedRowModel: () => RowModel<TGenerics>
64
- getSelectedRowModel: () => RowModel<TGenerics>
65
- getFilteredSelectedRowModel: () => RowModel<TGenerics>
66
- getGroupedSelectedRowModel: () => RowModel<TGenerics>
59
+ getPreSelectedRowModel: () => RowModel<TData>
60
+ getSelectedRowModel: () => RowModel<TData>
61
+ getFilteredSelectedRowModel: () => RowModel<TData>
62
+ getGroupedSelectedRowModel: () => RowModel<TData>
67
63
  }
68
64
 
69
65
  //
@@ -76,11 +72,11 @@ export const RowSelection: TableFeature = {
76
72
  }
77
73
  },
78
74
 
79
- getDefaultOptions: <TGenerics extends TableGenerics>(
80
- instance: TableInstance<TGenerics>
81
- ): RowSelectionOptions<TGenerics> => {
75
+ getDefaultOptions: <TData extends RowData>(
76
+ table: Table<TData>
77
+ ): RowSelectionOptions<TData> => {
82
78
  return {
83
- onRowSelectionChange: makeStateUpdater('rowSelection', instance),
79
+ onRowSelectionChange: makeStateUpdater('rowSelection', table),
84
80
  enableRowSelection: true,
85
81
  enableMultiRowSelection: true,
86
82
  enableSubRowSelection: true,
@@ -90,26 +86,23 @@ export const RowSelection: TableFeature = {
90
86
  }
91
87
  },
92
88
 
93
- createInstance: <TGenerics extends TableGenerics>(
94
- instance: TableInstance<TGenerics>
95
- ): RowSelectionInstance<TGenerics> => {
89
+ createTable: <TData extends RowData>(
90
+ table: Table<TData>
91
+ ): RowSelectionInstance<TData> => {
96
92
  return {
97
- setRowSelection: updater =>
98
- instance.options.onRowSelectionChange?.(updater),
93
+ setRowSelection: updater => table.options.onRowSelectionChange?.(updater),
99
94
  resetRowSelection: defaultState =>
100
- instance.setRowSelection(
101
- defaultState ? {} : instance.initialState.rowSelection ?? {}
95
+ table.setRowSelection(
96
+ defaultState ? {} : table.initialState.rowSelection ?? {}
102
97
  ),
103
98
  toggleAllRowsSelected: value => {
104
- instance.setRowSelection(old => {
99
+ table.setRowSelection(old => {
105
100
  value =
106
- typeof value !== 'undefined'
107
- ? value
108
- : !instance.getIsAllRowsSelected()
101
+ typeof value !== 'undefined' ? value : !table.getIsAllRowsSelected()
109
102
 
110
103
  const rowSelection = { ...old }
111
104
 
112
- const preGroupedFlatRows = instance.getPreGroupedRowModel().flatRows
105
+ const preGroupedFlatRows = table.getPreGroupedRowModel().flatRows
113
106
 
114
107
  // We don't use `mutateRowIsSelected` here for performance reasons.
115
108
  // All of the rows are flat already, so it wouldn't be worth it
@@ -127,16 +120,16 @@ export const RowSelection: TableFeature = {
127
120
  })
128
121
  },
129
122
  toggleAllPageRowsSelected: value =>
130
- instance.setRowSelection(old => {
123
+ table.setRowSelection(old => {
131
124
  const resolvedValue =
132
125
  typeof value !== 'undefined'
133
126
  ? value
134
- : !instance.getIsAllPageRowsSelected()
127
+ : !table.getIsAllPageRowsSelected()
135
128
 
136
129
  const rowSelection: RowSelectionState = { ...old }
137
130
 
138
- instance.getRowModel().rows.forEach(row => {
139
- mutateRowIsSelected(rowSelection, row.id, resolvedValue, instance)
131
+ table.getRowModel().rows.forEach(row => {
132
+ mutateRowIsSelected(rowSelection, row.id, resolvedValue, table)
140
133
  })
141
134
 
142
135
  return rowSelection
@@ -147,7 +140,7 @@ export const RowSelection: TableFeature = {
147
140
  // rows,
148
141
  // rowsById,
149
142
  // options: { selectGroupingRows, selectSubRows },
150
- // } = instance
143
+ // } = table
151
144
 
152
145
  // const findSelectedRow = (rows: Row[]) => {
153
146
  // let found
@@ -180,7 +173,7 @@ export const RowSelection: TableFeature = {
180
173
  // })
181
174
  // }
182
175
 
183
- // instance.rows.forEach(row => {
176
+ // table.rows.forEach(row => {
184
177
  // const isFirstRow = row.id === firstRow.id
185
178
  // const isLastRow = row.id === lastRow.id
186
179
 
@@ -198,11 +191,11 @@ export const RowSelection: TableFeature = {
198
191
  // }
199
192
  // })
200
193
 
201
- // instance.setRowSelection(selectedRowIds)
194
+ // table.setRowSelection(selectedRowIds)
202
195
  // },
203
- getPreSelectedRowModel: () => instance.getCoreRowModel(),
196
+ getPreSelectedRowModel: () => table.getCoreRowModel(),
204
197
  getSelectedRowModel: memo(
205
- () => [instance.getState().rowSelection, instance.getCoreRowModel()],
198
+ () => [table.getState().rowSelection, table.getCoreRowModel()],
206
199
  (rowSelection, rowModel) => {
207
200
  if (!Object.keys(rowSelection).length) {
208
201
  return {
@@ -212,19 +205,16 @@ export const RowSelection: TableFeature = {
212
205
  }
213
206
  }
214
207
 
215
- return selectRowsFn(instance, rowModel)
208
+ return selectRowsFn(table, rowModel)
216
209
  },
217
210
  {
218
211
  key: process.env.NODE_ENV === 'development' && 'getSelectedRowModel',
219
- debug: () => instance.options.debugAll ?? instance.options.debugTable,
212
+ debug: () => table.options.debugAll ?? table.options.debugTable,
220
213
  }
221
214
  ),
222
215
 
223
216
  getFilteredSelectedRowModel: memo(
224
- () => [
225
- instance.getState().rowSelection,
226
- instance.getFilteredRowModel(),
227
- ],
217
+ () => [table.getState().rowSelection, table.getFilteredRowModel()],
228
218
  (rowSelection, rowModel) => {
229
219
  if (!Object.keys(rowSelection).length) {
230
220
  return {
@@ -234,18 +224,18 @@ export const RowSelection: TableFeature = {
234
224
  }
235
225
  }
236
226
 
237
- return selectRowsFn(instance, rowModel)
227
+ return selectRowsFn(table, rowModel)
238
228
  },
239
229
  {
240
230
  key:
241
231
  process.env.NODE_ENV === 'production' &&
242
232
  'getFilteredSelectedRowModel',
243
- debug: () => instance.options.debugAll ?? instance.options.debugTable,
233
+ debug: () => table.options.debugAll ?? table.options.debugTable,
244
234
  }
245
235
  ),
246
236
 
247
237
  getGroupedSelectedRowModel: memo(
248
- () => [instance.getState().rowSelection, instance.getSortedRowModel()],
238
+ () => [table.getState().rowSelection, table.getSortedRowModel()],
249
239
  (rowSelection, rowModel) => {
250
240
  if (!Object.keys(rowSelection).length) {
251
241
  return {
@@ -255,35 +245,35 @@ export const RowSelection: TableFeature = {
255
245
  }
256
246
  }
257
247
 
258
- return selectRowsFn(instance, rowModel)
248
+ return selectRowsFn(table, rowModel)
259
249
  },
260
250
  {
261
251
  key:
262
252
  process.env.NODE_ENV === 'production' &&
263
253
  'getGroupedSelectedRowModel',
264
- debug: () => instance.options.debugAll ?? instance.options.debugTable,
254
+ debug: () => table.options.debugAll ?? table.options.debugTable,
265
255
  }
266
256
  ),
267
257
 
268
258
  ///
269
259
 
270
260
  // getGroupingRowCanSelect: rowId => {
271
- // const row = instance.getRow(rowId)
261
+ // const row = table.getRow(rowId)
272
262
 
273
263
  // if (!row) {
274
264
  // throw new Error()
275
265
  // }
276
266
 
277
- // if (typeof instance.options.enableGroupingRowSelection === 'function') {
278
- // return instance.options.enableGroupingRowSelection(row)
267
+ // if (typeof table.options.enableGroupingRowSelection === 'function') {
268
+ // return table.options.enableGroupingRowSelection(row)
279
269
  // }
280
270
 
281
- // return instance.options.enableGroupingRowSelection ?? false
271
+ // return table.options.enableGroupingRowSelection ?? false
282
272
  // },
283
273
 
284
274
  getIsAllRowsSelected: () => {
285
- const preFilteredFlatRows = instance.getPreFilteredRowModel().flatRows
286
- const { rowSelection } = instance.getState()
275
+ const preFilteredFlatRows = table.getPreFilteredRowModel().flatRows
276
+ const { rowSelection } = table.getState()
287
277
 
288
278
  let isAllRowsSelected = Boolean(
289
279
  preFilteredFlatRows.length && Object.keys(rowSelection).length
@@ -299,8 +289,8 @@ export const RowSelection: TableFeature = {
299
289
  },
300
290
 
301
291
  getIsAllPageRowsSelected: () => {
302
- const paginationFlatRows = instance.getPaginationRowModel().flatRows
303
- const { rowSelection } = instance.getState()
292
+ const paginationFlatRows = table.getPaginationRowModel().flatRows
293
+ const { rowSelection } = table.getState()
304
294
 
305
295
  let isAllPageRowsSelected = !!paginationFlatRows.length
306
296
 
@@ -316,14 +306,14 @@ export const RowSelection: TableFeature = {
316
306
 
317
307
  getIsSomeRowsSelected: () => {
318
308
  return (
319
- !instance.getIsAllRowsSelected() &&
320
- !!Object.keys(instance.getState().rowSelection ?? {}).length
309
+ !table.getIsAllRowsSelected() &&
310
+ !!Object.keys(table.getState().rowSelection ?? {}).length
321
311
  )
322
312
  },
323
313
 
324
314
  getIsSomePageRowsSelected: () => {
325
- const paginationFlatRows = instance.getPaginationRowModel().flatRows
326
- return instance.getIsAllPageRowsSelected()
315
+ const paginationFlatRows = table.getPaginationRowModel().flatRows
316
+ return table.getIsAllPageRowsSelected()
327
317
  ? false
328
318
  : paginationFlatRows.some(
329
319
  d => d.getIsSelected() || d.getIsSomeSelected()
@@ -332,7 +322,7 @@ export const RowSelection: TableFeature = {
332
322
 
333
323
  getToggleAllRowsSelectedHandler: () => {
334
324
  return (e: unknown) => {
335
- instance.toggleAllRowsSelected(
325
+ table.toggleAllRowsSelected(
336
326
  ((e as MouseEvent).target as HTMLInputElement).checked
337
327
  )
338
328
  }
@@ -340,7 +330,7 @@ export const RowSelection: TableFeature = {
340
330
 
341
331
  getToggleAllPageRowsSelectedHandler: () => {
342
332
  return (e: unknown) => {
343
- instance.toggleAllPageRowsSelected(
333
+ table.toggleAllPageRowsSelected(
344
334
  ((e as MouseEvent).target as HTMLInputElement).checked
345
335
  )
346
336
  }
@@ -348,15 +338,15 @@ export const RowSelection: TableFeature = {
348
338
  }
349
339
  },
350
340
 
351
- createRow: <TGenerics extends TableGenerics>(
352
- row: Row<TGenerics>,
353
- instance: TableInstance<TGenerics>
341
+ createRow: <TData extends RowData>(
342
+ row: Row<TData>,
343
+ table: Table<TData>
354
344
  ): RowSelectionRow => {
355
345
  return {
356
346
  toggleSelected: value => {
357
347
  const isSelected = row.getIsSelected()
358
348
 
359
- instance.setRowSelection(old => {
349
+ table.setRowSelection(old => {
360
350
  value = typeof value !== 'undefined' ? value : !isSelected
361
351
 
362
352
  if (isSelected === value) {
@@ -365,43 +355,48 @@ export const RowSelection: TableFeature = {
365
355
 
366
356
  const selectedRowIds = { ...old }
367
357
 
368
- mutateRowIsSelected(selectedRowIds, row.id, value, instance)
358
+ mutateRowIsSelected(selectedRowIds, row.id, value, table)
369
359
 
370
360
  return selectedRowIds
371
361
  })
372
362
  },
373
363
  getIsSelected: () => {
374
- const { rowSelection } = instance.getState()
375
- return isRowSelected(row, rowSelection, instance) === true
364
+ const { rowSelection } = table.getState()
365
+ return isRowSelected(row, rowSelection)
376
366
  },
377
367
 
378
368
  getIsSomeSelected: () => {
379
- const { rowSelection } = instance.getState()
380
- return isRowSelected(row, rowSelection, instance) === 'some'
369
+ const { rowSelection } = table.getState()
370
+ return isSubRowSelected(row, rowSelection, table) === 'some'
371
+ },
372
+
373
+ getIsAllSubRowsSelected: () => {
374
+ const { rowSelection } = table.getState()
375
+ return isSubRowSelected(row, rowSelection, table) === 'all'
381
376
  },
382
377
 
383
378
  getCanSelect: () => {
384
- if (typeof instance.options.enableRowSelection === 'function') {
385
- return instance.options.enableRowSelection(row)
379
+ if (typeof table.options.enableRowSelection === 'function') {
380
+ return table.options.enableRowSelection(row)
386
381
  }
387
382
 
388
- return instance.options.enableRowSelection ?? true
383
+ return table.options.enableRowSelection ?? true
389
384
  },
390
385
 
391
386
  getCanSelectSubRows: () => {
392
- if (typeof instance.options.enableSubRowSelection === 'function') {
393
- return instance.options.enableSubRowSelection(row)
387
+ if (typeof table.options.enableSubRowSelection === 'function') {
388
+ return table.options.enableSubRowSelection(row)
394
389
  }
395
390
 
396
- return instance.options.enableSubRowSelection ?? true
391
+ return table.options.enableSubRowSelection ?? true
397
392
  },
398
393
 
399
394
  getCanMultiSelect: () => {
400
- if (typeof instance.options.enableMultiRowSelection === 'function') {
401
- return instance.options.enableMultiRowSelection(row)
395
+ if (typeof table.options.enableMultiRowSelection === 'function') {
396
+ return table.options.enableMultiRowSelection(row)
402
397
  }
403
398
 
404
- return instance.options.enableMultiRowSelection ?? true
399
+ return table.options.enableMultiRowSelection ?? true
405
400
  },
406
401
  getToggleSelectedHandler: () => {
407
402
  const canSelect = row.getCanSelect()
@@ -417,21 +412,24 @@ export const RowSelection: TableFeature = {
417
412
  },
418
413
  }
419
414
 
420
- const mutateRowIsSelected = <TGenerics extends TableGenerics>(
415
+ const mutateRowIsSelected = <TData extends RowData>(
421
416
  selectedRowIds: Record<string, boolean>,
422
417
  id: string,
423
418
  value: boolean,
424
- instance: TableInstance<TGenerics>
419
+ table: Table<TData>
425
420
  ) => {
426
- const row = instance.getRow(id)
421
+ const row = table.getRow(id)
427
422
 
428
423
  const isGrouped = row.getIsGrouped()
429
424
 
430
425
  // if ( // TODO: enforce grouping row selection rules
431
426
  // !isGrouped ||
432
- // (isGrouped && instance.options.enableGroupingRowSelection)
427
+ // (isGrouped && table.options.enableGroupingRowSelection)
433
428
  // ) {
434
429
  if (value) {
430
+ if (!row.getCanMultiSelect()) {
431
+ Object.keys(selectedRowIds).forEach(key => delete selectedRowIds[key])
432
+ }
435
433
  selectedRowIds[id] = true
436
434
  } else {
437
435
  delete selectedRowIds[id]
@@ -440,25 +438,25 @@ const mutateRowIsSelected = <TGenerics extends TableGenerics>(
440
438
 
441
439
  if (row.subRows?.length && row.getCanSelectSubRows()) {
442
440
  row.subRows.forEach(row =>
443
- mutateRowIsSelected(selectedRowIds, row.id, value, instance)
441
+ mutateRowIsSelected(selectedRowIds, row.id, value, table)
444
442
  )
445
443
  }
446
444
  }
447
445
 
448
- export function selectRowsFn<TGenerics extends TableGenerics>(
449
- instance: TableInstance<TGenerics>,
450
- rowModel: RowModel<TGenerics>
451
- ): RowModel<TGenerics> {
452
- const rowSelection = instance.getState().rowSelection
446
+ export function selectRowsFn<TData extends RowData>(
447
+ table: Table<TData>,
448
+ rowModel: RowModel<TData>
449
+ ): RowModel<TData> {
450
+ const rowSelection = table.getState().rowSelection
453
451
 
454
- const newSelectedFlatRows: Row<TGenerics>[] = []
455
- const newSelectedRowsById: Record<string, Row<TGenerics>> = {}
452
+ const newSelectedFlatRows: Row<TData>[] = []
453
+ const newSelectedRowsById: Record<string, Row<TData>> = {}
456
454
 
457
455
  // Filters top level and nested rows
458
- const recurseRows = (rows: Row<TGenerics>[], depth = 0): Row<TGenerics>[] => {
456
+ const recurseRows = (rows: Row<TData>[], depth = 0): Row<TData>[] => {
459
457
  return rows
460
458
  .map(row => {
461
- const isSelected = isRowSelected(row, rowSelection, instance) === true
459
+ const isSelected = isRowSelected(row, rowSelection)
462
460
 
463
461
  if (isSelected) {
464
462
  newSelectedFlatRows.push(row)
@@ -476,7 +474,7 @@ export function selectRowsFn<TGenerics extends TableGenerics>(
476
474
  return row
477
475
  }
478
476
  })
479
- .filter(Boolean) as Row<TGenerics>[]
477
+ .filter(Boolean) as Row<TData>[]
480
478
  }
481
479
 
482
480
  return {
@@ -486,15 +484,18 @@ export function selectRowsFn<TGenerics extends TableGenerics>(
486
484
  }
487
485
  }
488
486
 
489
- export function isRowSelected<TGenerics extends TableGenerics>(
490
- row: Row<TGenerics>,
491
- selection: Record<string, boolean>,
492
- instance: TableInstance<TGenerics>
493
- ): boolean | 'some' {
494
- if (selection[row.id]) {
495
- return true
496
- }
487
+ export function isRowSelected<TData extends RowData>(
488
+ row: Row<TData>,
489
+ selection: Record<string, boolean>
490
+ ): boolean {
491
+ return selection[row.id] ?? false
492
+ }
497
493
 
494
+ export function isSubRowSelected<TData extends RowData>(
495
+ row: Row<TData>,
496
+ selection: Record<string, boolean>,
497
+ table: Table<TData>
498
+ ): boolean | 'some' | 'all' {
498
499
  if (row.subRows && row.subRows.length) {
499
500
  let allChildrenSelected = true
500
501
  let someSelected = false
@@ -505,14 +506,14 @@ export function isRowSelected<TGenerics extends TableGenerics>(
505
506
  return
506
507
  }
507
508
 
508
- if (isRowSelected(subRow, selection, instance)) {
509
+ if (isRowSelected(subRow, selection)) {
509
510
  someSelected = true
510
511
  } else {
511
512
  allChildrenSelected = false
512
513
  }
513
514
  })
514
515
 
515
- return allChildrenSelected ? true : someSelected ? 'some' : false
516
+ return allChildrenSelected ? 'all' : someSelected ? 'some' : false
516
517
  }
517
518
 
518
519
  return false