@tanstack/table-core 8.0.0-alpha.55 → 8.0.0-alpha.59

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 (88) hide show
  1. package/build/cjs/core.js +18 -404
  2. package/build/cjs/core.js.map +1 -1
  3. package/build/cjs/createTable.js +3 -3
  4. package/build/cjs/createTable.js.map +1 -1
  5. package/build/cjs/features/Cells.js +107 -0
  6. package/build/cjs/features/Cells.js.map +1 -0
  7. package/build/cjs/features/ColumnSizing.js +96 -54
  8. package/build/cjs/features/ColumnSizing.js.map +1 -1
  9. package/build/cjs/features/Columns.js +216 -0
  10. package/build/cjs/features/Columns.js.map +1 -0
  11. package/build/cjs/features/Expanding.js +13 -21
  12. package/build/cjs/features/Expanding.js.map +1 -1
  13. package/build/cjs/features/Filters.js +3 -3
  14. package/build/cjs/features/Filters.js.map +1 -1
  15. package/build/cjs/features/Grouping.js +8 -11
  16. package/build/cjs/features/Grouping.js.map +1 -1
  17. package/build/cjs/features/Headers.js +79 -220
  18. package/build/cjs/features/Headers.js.map +1 -1
  19. package/build/cjs/features/Ordering.js +1 -1
  20. package/build/cjs/features/Ordering.js.map +1 -1
  21. package/build/cjs/features/Pagination.js +5 -5
  22. package/build/cjs/features/Pagination.js.map +1 -1
  23. package/build/cjs/features/Pinning.js +172 -2
  24. package/build/cjs/features/Pinning.js.map +1 -1
  25. package/build/cjs/features/RowSelection.js +16 -48
  26. package/build/cjs/features/RowSelection.js.map +1 -1
  27. package/build/cjs/features/Rows.js +84 -0
  28. package/build/cjs/features/Rows.js.map +1 -0
  29. package/build/cjs/features/Sorting.js +9 -12
  30. package/build/cjs/features/Sorting.js.map +1 -1
  31. package/build/cjs/features/Visibility.js +59 -38
  32. package/build/cjs/features/Visibility.js.map +1 -1
  33. package/build/cjs/filterFns.js +16 -0
  34. package/build/cjs/filterFns.js.map +1 -1
  35. package/build/cjs/index.js +0 -1
  36. package/build/cjs/index.js.map +1 -1
  37. package/build/cjs/utils.js +0 -16
  38. package/build/cjs/utils.js.map +1 -1
  39. package/build/esm/index.js +866 -856
  40. package/build/esm/index.js.map +1 -1
  41. package/build/stats-html.html +1 -1
  42. package/build/stats-react.json +424 -322
  43. package/build/types/core.d.ts +9 -88
  44. package/build/types/createTable.d.ts +10 -11
  45. package/build/types/features/Cells.d.ts +13 -0
  46. package/build/types/features/ColumnSizing.d.ts +24 -30
  47. package/build/types/features/Columns.d.ts +54 -0
  48. package/build/types/features/Expanding.d.ts +6 -9
  49. package/build/types/features/Filters.d.ts +3 -1
  50. package/build/types/features/Grouping.d.ts +6 -9
  51. package/build/types/features/Headers.d.ts +3 -15
  52. package/build/types/features/Ordering.d.ts +1 -1
  53. package/build/types/features/Pagination.d.ts +6 -6
  54. package/build/types/features/Pinning.d.ts +18 -4
  55. package/build/types/features/RowSelection.d.ts +6 -13
  56. package/build/types/features/Rows.d.ts +27 -0
  57. package/build/types/features/Sorting.d.ts +5 -8
  58. package/build/types/features/Visibility.d.ts +9 -7
  59. package/build/types/filterFns.d.ts +5 -0
  60. package/build/types/types.d.ts +27 -69
  61. package/build/types/utils.d.ts +1 -5
  62. package/build/umd/index.development.js +844 -835
  63. package/build/umd/index.development.js.map +1 -1
  64. package/build/umd/index.production.js +1 -1
  65. package/build/umd/index.production.js.map +1 -1
  66. package/package.json +1 -1
  67. package/src/core.ts +55 -601
  68. package/src/createTable.ts +13 -17
  69. package/src/features/Cells.ts +130 -0
  70. package/src/features/ColumnSizing.ts +111 -89
  71. package/src/features/Columns.ts +288 -0
  72. package/src/features/Expanding.ts +20 -42
  73. package/src/features/Filters.ts +11 -3
  74. package/src/features/Grouping.ts +13 -39
  75. package/src/features/Headers.ts +49 -233
  76. package/src/features/Ordering.ts +1 -1
  77. package/src/features/Pagination.ts +14 -4
  78. package/src/features/Pinning.ts +194 -3
  79. package/src/features/RowSelection.ts +26 -88
  80. package/src/features/Rows.ts +123 -0
  81. package/src/features/Sorting.ts +20 -43
  82. package/src/features/Visibility.ts +82 -63
  83. package/src/filterFns.ts +20 -0
  84. package/src/types.ts +59 -133
  85. package/src/utils/getColumnFilteredRowModelAsync.ts +1 -5
  86. package/src/utils/getGlobalFilteredRowModelAsync.ts +2 -6
  87. package/src/utils/getSortedRowModelAsync.ts +0 -1
  88. package/src/utils.ts +2 -31
@@ -6,9 +6,9 @@ import {
6
6
  AccessorFn,
7
7
  AnyRender,
8
8
  TableGenerics,
9
- Options,
9
+ TableOptions,
10
10
  } from './types'
11
- import { IfDefined, Overwrite, PartialKeys } from './utils'
11
+ import { IfDefined, Overwrite } from './utils'
12
12
 
13
13
  export type TableFactory<TGenerics extends TableGenerics> =
14
14
  () => Table<TGenerics>
@@ -25,12 +25,16 @@ export type CreateTableOptions<
25
25
  filterFns?: TFilterFns
26
26
  sortingFns?: TSortingFns
27
27
  aggregationFns?: TAggregationFns
28
- } & Omit<Options<TGenerics>, 'filterFns' | 'sortingFns' | 'aggregationFns'>
28
+ } & Omit<
29
+ TableOptions<TGenerics>,
30
+ 'filterFns' | 'sortingFns' | 'aggregationFns'
31
+ >
29
32
  >
30
33
 
31
34
  export type Table<TGenerics extends TableGenerics> = {
32
35
  generics: TGenerics
33
- options: Partial<Options<TGenerics>>
36
+ options: Partial<TableOptions<TGenerics>>
37
+ setGenerics: <T extends TableGenerics>() => Table<T>
34
38
  setRowType: <TRow>() => Table<Overwrite<TGenerics, { Row: TRow }>>
35
39
  setTableMetaType: <TTableMeta>() => Table<
36
40
  Overwrite<TGenerics, { TableMeta: TTableMeta }>
@@ -60,9 +64,6 @@ export type Table<TGenerics extends TableGenerics> = {
60
64
  }
61
65
  >
62
66
  >
63
- createColumns: <TColumnDef extends ColumnDef<any>>(
64
- columns: TColumnDef[]
65
- ) => TColumnDef[]
66
67
  createGroup: (
67
68
  column: Overwrite<
68
69
  | Overwrite<
@@ -87,12 +88,7 @@ export type Table<TGenerics extends TableGenerics> = {
87
88
  >
88
89
  ) => ColumnDef<TGenerics>
89
90
  createDisplayColumn: (
90
- column: Overwrite<
91
- PartialKeys<ColumnDef<TGenerics>, 'accessorFn' | 'accessorKey'>,
92
- {
93
- columns?: ColumnDef<any>[]
94
- }
95
- >
91
+ column: Omit<ColumnDef<TGenerics>, 'columns'>
96
92
  ) => ColumnDef<TGenerics>
97
93
  createDataColumn: <
98
94
  TAccessor extends AccessorFn<TGenerics['Row']> | keyof TGenerics['Row']
@@ -124,9 +120,9 @@ export type Table<TGenerics extends TableGenerics> = {
124
120
 
125
121
  //
126
122
 
127
- export function createTableFactory<TRender extends AnyRender>(opts: {
128
- render: TRender
129
- }): () => Table<{ Render: TRender }> {
123
+ export function createTableFactory<TRenderer extends AnyRender>(opts: {
124
+ render: TRenderer
125
+ }): () => Table<{ Renderer: TRenderer; Rendered: ReturnType<TRenderer> }> {
130
126
  return () => createTable(undefined, undefined, opts)
131
127
  }
132
128
 
@@ -144,6 +140,7 @@ function createTable<TGenerics extends TableGenerics>(
144
140
  throw new Error('')
145
141
  })(),
146
142
  },
143
+ setGenerics: () => table as any,
147
144
  setRowType: () => table as any,
148
145
  setTableMetaType: () => table as any,
149
146
  setColumnMetaType: () => table as any,
@@ -152,7 +149,6 @@ function createTable<TGenerics extends TableGenerics>(
152
149
  ...options,
153
150
  ...newOptions,
154
151
  } as any),
155
- createColumns: columns => columns,
156
152
  createDisplayColumn: column => ({ ...column, columnDefType: 'display' }),
157
153
  createGroup: column => ({ ...column, columnDefType: 'group' } as any),
158
154
  createDataColumn: (accessor, column): any => {
@@ -0,0 +1,130 @@
1
+ import {
2
+ Cell,
3
+ TableGenerics,
4
+ TableInstance,
5
+ Row,
6
+ Column,
7
+ CoreCell,
8
+ } from '../types'
9
+ import { memo } from '../utils'
10
+
11
+ export type CellsRow<TGenerics extends TableGenerics> = {
12
+ getAllCells: () => Cell<TGenerics>[]
13
+ getAllCellsByColumnId: () => Record<string, Cell<TGenerics>>
14
+ }
15
+
16
+ export type CellsInstance<TGenerics extends TableGenerics> = {
17
+ createCell: (
18
+ row: Row<TGenerics>,
19
+ column: Column<TGenerics>,
20
+ value: any
21
+ ) => Cell<TGenerics>
22
+ getCell: (rowId: string, columnId: string) => Cell<TGenerics>
23
+ }
24
+
25
+ //
26
+
27
+ export const Cells = {
28
+ createRow: <TGenerics extends TableGenerics>(
29
+ row: Row<TGenerics>,
30
+ instance: TableInstance<TGenerics>
31
+ ): CellsRow<TGenerics> => {
32
+ return {
33
+ getAllCells: memo(
34
+ () => [instance.getAllLeafColumns()],
35
+ leafColumns => {
36
+ return leafColumns.map(column => {
37
+ return instance.createCell(
38
+ row as Row<TGenerics>,
39
+ column,
40
+ row.values[column.id]
41
+ )
42
+ })
43
+ },
44
+ {
45
+ key: process.env.NODE_ENV !== 'production' ? 'row.getAllCells' : '',
46
+ debug: () => instance.options.debugAll ?? instance.options.debugRows,
47
+ }
48
+ ),
49
+
50
+ getAllCellsByColumnId: memo(
51
+ () => [row.getAllCells()],
52
+ allCells => {
53
+ return allCells.reduce((acc, cell) => {
54
+ acc[cell.columnId] = cell
55
+ return acc
56
+ }, {} as Record<string, Cell<TGenerics>>)
57
+ },
58
+ {
59
+ key: 'row.getAllCellsByColumnId',
60
+ debug: () => instance.options.debugAll ?? instance.options.debugRows,
61
+ }
62
+ ),
63
+ }
64
+ },
65
+
66
+ createInstance: <TGenerics extends TableGenerics>(
67
+ instance: TableInstance<TGenerics>
68
+ ): CellsInstance<TGenerics> => {
69
+ return {
70
+ createCell: (row, column, value) => {
71
+ const cell: CoreCell<TGenerics> = {
72
+ id: `${row.id}_${column.id}`,
73
+ rowId: row.id,
74
+ columnId: column.id,
75
+ row,
76
+ column,
77
+ value,
78
+ renderCell: () =>
79
+ column.cell
80
+ ? instance.render(column.cell, {
81
+ instance,
82
+ column,
83
+ row,
84
+ cell: cell as Cell<TGenerics>,
85
+ value,
86
+ })
87
+ : null,
88
+ }
89
+
90
+ instance._features.forEach(feature => {
91
+ Object.assign(
92
+ cell,
93
+ feature.createCell?.(
94
+ cell as Cell<TGenerics>,
95
+ column,
96
+ row as Row<TGenerics>,
97
+ instance
98
+ )
99
+ )
100
+ }, {})
101
+
102
+ return cell as Cell<TGenerics>
103
+ },
104
+
105
+ getCell: (rowId: string, columnId: string) => {
106
+ const row = instance.getRow(rowId)
107
+
108
+ if (!row) {
109
+ if (process.env.NODE_ENV !== 'production') {
110
+ throw new Error(`[Table] could not find row with id ${rowId}`)
111
+ }
112
+ throw new Error()
113
+ }
114
+
115
+ const cell = row.getAllCellsByColumnId()[columnId]
116
+
117
+ if (!cell) {
118
+ if (process.env.NODE_ENV !== 'production') {
119
+ throw new Error(
120
+ `[Table] could not find cell ${columnId} in row ${rowId}`
121
+ )
122
+ }
123
+ throw new Error()
124
+ }
125
+
126
+ return cell
127
+ },
128
+ }
129
+ },
130
+ }
@@ -1,23 +1,23 @@
1
1
  import {
2
2
  Column,
3
- Getter,
4
3
  Header,
5
4
  OnChangeFn,
6
5
  TableGenerics,
7
- PropGetterValue,
8
6
  TableInstance,
9
7
  Updater,
8
+ TableFeature,
10
9
  } from '../types'
11
- import { makeStateUpdater, propGetter } from '../utils'
10
+ import { makeStateUpdater } from '../utils'
11
+ import { ColumnPinningPosition } from './Pinning'
12
12
 
13
13
  //
14
14
 
15
15
  export type ColumnSizingTableState = {
16
- columnSizing: ColumnSizing
16
+ columnSizing: ColumnSizingState
17
17
  columnSizingInfo: ColumnSizingInfoState
18
18
  }
19
19
 
20
- export type ColumnSizing = Record<string, number>
20
+ export type ColumnSizingState = Record<string, number>
21
21
 
22
22
  export type ColumnSizingInfoState = {
23
23
  startOffset: null | number
@@ -33,27 +33,20 @@ export type ColumnResizeMode = 'onChange' | 'onEnd'
33
33
  export type ColumnSizingOptions = {
34
34
  enableColumnResizing?: boolean
35
35
  columnResizeMode?: ColumnResizeMode
36
- onColumnSizingChange?: OnChangeFn<ColumnSizing>
36
+ onColumnSizingChange?: OnChangeFn<ColumnSizingState>
37
37
  onColumnSizingInfoChange?: OnChangeFn<ColumnSizingInfoState>
38
38
  }
39
39
 
40
40
  export type ColumnSizingDefaultOptions = {
41
41
  columnResizeMode: ColumnResizeMode
42
- onColumnSizingChange: OnChangeFn<ColumnSizing>
42
+ onColumnSizingChange: OnChangeFn<ColumnSizingState>
43
43
  onColumnSizingInfoChange: OnChangeFn<ColumnSizingInfoState>
44
44
  }
45
45
 
46
- export type ColumnResizerProps = {
47
- title?: string
48
- onMouseDown?: (e: MouseEvent) => void
49
- onTouchStart?: (e: TouchEvent) => void
50
- draggable?: boolean
51
- role?: string
52
- }
53
-
54
46
  export type ColumnSizingInstance<TGenerics extends TableGenerics> = {
55
- getColumnWidth: (columnId: string) => number
56
- setColumnSizing: (updater: Updater<ColumnSizing>) => void
47
+ getColumnSize: (columnId: string) => number
48
+ getColumnStart: (columnId: string, position?: ColumnPinningPosition) => number
49
+ setColumnSizing: (updater: Updater<ColumnSizingState>) => void
57
50
  setColumnSizingInfo: (updater: Updater<ColumnSizingInfoState>) => void
58
51
  resetColumnSizing: () => void
59
52
  resetColumnSize: (columnId: string) => void
@@ -61,23 +54,26 @@ export type ColumnSizingInstance<TGenerics extends TableGenerics> = {
61
54
  resetHeaderSizeInfo: () => void
62
55
  getColumnCanResize: (columnId: string) => boolean
63
56
  getHeaderCanResize: (headerId: string) => boolean
64
- getHeaderResizerProps: <TGetter extends Getter<ColumnResizerProps>>(
65
- headerId: string,
66
- userProps?: TGetter
67
- ) => undefined | PropGetterValue<ColumnResizerProps, TGetter>
57
+ getResizeHandler: (headerId: string) => (event: unknown) => void
68
58
  getColumnIsResizing: (columnId: string) => boolean
69
59
  getHeaderIsResizing: (headerId: string) => boolean
60
+ getTotalSize: () => number
61
+ getLeftTotalSize: () => number
62
+ getCenterTotalSize: () => number
63
+ getRightTotalSize: () => number
70
64
  }
71
65
 
72
66
  export type ColumnSizingColumnDef = {
73
67
  enableResizing?: boolean
74
68
  defaultCanResize?: boolean
75
- width?: number
76
- minWidth?: number
77
- maxWidth?: number
69
+ size?: number
70
+ minSize?: number
71
+ maxSize?: number
78
72
  }
79
73
 
80
74
  export type ColumnSizingColumn<TGenerics extends TableGenerics> = {
75
+ getSize: () => number
76
+ getStart: (position?: ColumnPinningPosition) => number
81
77
  getCanResize: () => boolean
82
78
  getIsResizing: () => boolean
83
79
  resetSize: () => void
@@ -86,21 +82,19 @@ export type ColumnSizingColumn<TGenerics extends TableGenerics> = {
86
82
  export type ColumnSizingHeader<TGenerics extends TableGenerics> = {
87
83
  getCanResize: () => boolean
88
84
  getIsResizing: () => boolean
89
- getResizerProps: <TGetter extends Getter<ColumnResizerProps>>(
90
- userProps?: TGetter
91
- ) => undefined | PropGetterValue<ColumnResizerProps, TGetter>
85
+ getResizeHandler: () => (event: unknown) => void
92
86
  resetSize: () => void
93
87
  }
94
88
 
95
89
  //
96
90
 
97
91
  export const defaultColumnSizing = {
98
- width: 150,
99
- minWidth: 20,
100
- maxWidth: Number.MAX_SAFE_INTEGER,
92
+ size: 150,
93
+ minSize: 20,
94
+ maxSize: Number.MAX_SAFE_INTEGER,
101
95
  }
102
96
 
103
- export const ColumnSizing = {
97
+ export const ColumnSizing: TableFeature = {
104
98
  getDefaultColumn: (): ColumnSizingColumnDef => {
105
99
  return defaultColumnSizing
106
100
  },
@@ -128,11 +122,36 @@ export const ColumnSizing = {
128
122
  }
129
123
  },
130
124
 
131
- getInstance: <TGenerics extends TableGenerics>(
125
+ createColumn: <TGenerics extends TableGenerics>(
126
+ column: Column<TGenerics>,
127
+ instance: TableInstance<TGenerics>
128
+ ): ColumnSizingColumn<TGenerics> => {
129
+ return {
130
+ getSize: () => instance.getColumnSize(column.id),
131
+ getStart: position => instance.getColumnStart(column.id, position),
132
+ getIsResizing: () => instance.getColumnIsResizing(column.id),
133
+ getCanResize: () => instance.getColumnCanResize(column.id),
134
+ resetSize: () => instance.resetColumnSize(column.id),
135
+ }
136
+ },
137
+
138
+ createHeader: <TGenerics extends TableGenerics>(
139
+ header: Header<TGenerics>,
140
+ instance: TableInstance<TGenerics>
141
+ ): ColumnSizingHeader<TGenerics> => {
142
+ return {
143
+ getIsResizing: () => instance.getColumnIsResizing(header.column.id),
144
+ getCanResize: () => instance.getColumnCanResize(header.column.id),
145
+ resetSize: () => instance.resetColumnSize(header.column.id),
146
+ getResizeHandler: () => instance.getResizeHandler(header.id),
147
+ }
148
+ },
149
+
150
+ createInstance: <TGenerics extends TableGenerics>(
132
151
  instance: TableInstance<TGenerics>
133
152
  ): ColumnSizingInstance<TGenerics> => {
134
153
  return {
135
- getColumnWidth: (columnId: string) => {
154
+ getColumnSize: (columnId: string) => {
136
155
  const column = instance.getColumn(columnId)
137
156
 
138
157
  if (!column) {
@@ -143,12 +162,38 @@ export const ColumnSizing = {
143
162
 
144
163
  return Math.min(
145
164
  Math.max(
146
- column.minWidth ?? defaultColumnSizing.minWidth,
147
- columnSize ?? column.width ?? defaultColumnSizing.width
165
+ column.minSize ?? defaultColumnSizing.minSize,
166
+ columnSize ?? column.size ?? defaultColumnSizing.size
148
167
  ),
149
- column.maxWidth ?? defaultColumnSizing.maxWidth
168
+ column.maxSize ?? defaultColumnSizing.maxSize
150
169
  )
151
170
  },
171
+ getColumnStart: (columnId, position) => {
172
+ const column = instance.getColumn(columnId)
173
+
174
+ if (!column) {
175
+ throw new Error()
176
+ }
177
+
178
+ const columns = !position
179
+ ? instance.getVisibleLeafColumns()
180
+ : position === 'left'
181
+ ? instance.getLeftVisibleLeafColumns()
182
+ : instance.getRightVisibleLeafColumns()
183
+
184
+ const index = columns.findIndex(d => d.id === columnId)
185
+
186
+ if (index > 0) {
187
+ const prevSiblingColumn = columns[index - 1]
188
+
189
+ return (
190
+ instance.getColumnStart(prevSiblingColumn.id, position) +
191
+ prevSiblingColumn.getSize()
192
+ )
193
+ }
194
+
195
+ return 0
196
+ },
152
197
  setColumnSizing: updater =>
153
198
  instance.options.onColumnSizingChange?.(updater),
154
199
  setColumnSizingInfo: updater =>
@@ -214,14 +259,18 @@ export const ColumnSizing = {
214
259
 
215
260
  return instance.getColumnIsResizing(header.column.id)
216
261
  },
217
-
218
- getHeaderResizerProps: (headerId, userProps) => {
262
+ getResizeHandler: (headerId: string) => {
219
263
  const header = instance.getHeader(headerId)
220
264
  const column = instance.getColumn(header.column.id)
221
-
222
265
  const canResize = column.getCanResize()
223
266
 
224
- const onResizeStart = (e: unknown) => {
267
+ return (e: unknown) => {
268
+ if (!canResize) {
269
+ return
270
+ }
271
+
272
+ ;(e as any).persist?.()
273
+
225
274
  if (isTouchStartEvent(e)) {
226
275
  // lets not respond to multiple touches (e.g. 2 or 3 fingers)
227
276
  if (e.touches && e.touches.length > 1) {
@@ -231,11 +280,11 @@ export const ColumnSizing = {
231
280
 
232
281
  const header = headerId ? instance.getHeader(headerId) : undefined
233
282
 
234
- const startSize = header ? header.getWidth() : column.getWidth()
283
+ const startSize = header ? header.getSize() : column.getSize()
235
284
 
236
285
  const columnSizingStart: [string, number][] = header
237
- ? header.getLeafHeaders().map(d => [d.column.id, d.getWidth()])
238
- : [[column.id, column.getWidth()]]
286
+ ? header.getLeafHeaders().map(d => [d.column.id, d.getSize()])
287
+ : [[column.id, column.getSize()]]
239
288
 
240
289
  const clientX = isTouchStartEvent(e)
241
290
  ? Math.round(e.touches[0].clientX)
@@ -249,7 +298,7 @@ export const ColumnSizing = {
249
298
  return
250
299
  }
251
300
 
252
- let newColumnSizing: ColumnSizing = {}
301
+ let newColumnSizing: ColumnSizingState = {}
253
302
 
254
303
  instance.setColumnSizingInfo(old => {
255
304
  const deltaOffset = clientXPos - (old?.startOffset ?? 0)
@@ -258,11 +307,10 @@ export const ColumnSizing = {
258
307
  -0.999999
259
308
  )
260
309
 
261
- old.columnSizingStart.forEach(([columnId, headerWidth]) => {
310
+ old.columnSizingStart.forEach(([columnId, headerSize]) => {
262
311
  newColumnSizing[columnId] =
263
312
  Math.round(
264
- Math.max(headerWidth + headerWidth * deltaPercentage, 0) *
265
- 100
313
+ Math.max(headerSize + headerSize * deltaPercentage, 0) * 100
266
314
  ) / 100
267
315
  })
268
316
 
@@ -368,49 +416,23 @@ export const ColumnSizing = {
368
416
  isResizingColumn: column.id,
369
417
  }))
370
418
  }
371
-
372
- const initialProps: ColumnResizerProps = canResize
373
- ? {
374
- title: 'Toggle Grouping',
375
- draggable: false,
376
- role: 'separator',
377
- onMouseDown: (e: MouseEvent) => {
378
- ;(e as any).persist?.()
379
- onResizeStart(e)
380
- },
381
- onTouchStart: (e: TouchEvent) => {
382
- ;(e as any).persist?.()
383
- onResizeStart(e)
384
- },
385
- }
386
- : {}
387
-
388
- return propGetter(initialProps, userProps)
389
419
  },
390
- }
391
- },
392
-
393
- createColumn: <TGenerics extends TableGenerics>(
394
- column: Column<TGenerics>,
395
- instance: TableInstance<TGenerics>
396
- ): ColumnSizingColumn<TGenerics> => {
397
- return {
398
- getIsResizing: () => instance.getColumnIsResizing(column.id),
399
- getCanResize: () => instance.getColumnCanResize(column.id),
400
- resetSize: () => instance.resetColumnSize(column.id),
401
- }
402
- },
403
-
404
- createHeader: <TGenerics extends TableGenerics>(
405
- header: Header<TGenerics>,
406
- instance: TableInstance<TGenerics>
407
- ): ColumnSizingHeader<TGenerics> => {
408
- return {
409
- getIsResizing: () => instance.getColumnIsResizing(header.column.id),
410
- getCanResize: () => instance.getColumnCanResize(header.column.id),
411
- resetSize: () => instance.resetColumnSize(header.column.id),
412
- getResizerProps: userProps =>
413
- instance.getHeaderResizerProps(header.id, userProps),
420
+ getTotalSize: () =>
421
+ instance.getHeaderGroups()[0]?.headers.reduce((sum, header) => {
422
+ return sum + header.getSize()
423
+ }, 0) ?? 0,
424
+ getLeftTotalSize: () =>
425
+ instance.getLeftHeaderGroups()[0]?.headers.reduce((sum, header) => {
426
+ return sum + header.getSize()
427
+ }, 0) ?? 0,
428
+ getCenterTotalSize: () =>
429
+ instance.getCenterHeaderGroups()[0]?.headers.reduce((sum, header) => {
430
+ return sum + header.getSize()
431
+ }, 0) ?? 0,
432
+ getRightTotalSize: () =>
433
+ instance.getRightHeaderGroups()[0]?.headers.reduce((sum, header) => {
434
+ return sum + header.getSize()
435
+ }, 0) ?? 0,
414
436
  }
415
437
  },
416
438
  }