@tanstack/table-core 8.0.0-alpha.58 → 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 (76) hide show
  1. package/build/cjs/core.js +10 -21
  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 +0 -15
  6. package/build/cjs/features/Cells.js.map +1 -1
  7. package/build/cjs/features/ColumnSizing.js +8 -19
  8. package/build/cjs/features/ColumnSizing.js.map +1 -1
  9. package/build/cjs/features/Columns.js.map +1 -1
  10. package/build/cjs/features/Expanding.js +11 -19
  11. package/build/cjs/features/Expanding.js.map +1 -1
  12. package/build/cjs/features/Grouping.js +6 -9
  13. package/build/cjs/features/Grouping.js.map +1 -1
  14. package/build/cjs/features/Headers.js +1 -67
  15. package/build/cjs/features/Headers.js.map +1 -1
  16. package/build/cjs/features/Pagination.js +3 -3
  17. package/build/cjs/features/Pagination.js.map +1 -1
  18. package/build/cjs/features/Pinning.js.map +1 -1
  19. package/build/cjs/features/RowSelection.js +15 -47
  20. package/build/cjs/features/RowSelection.js.map +1 -1
  21. package/build/cjs/features/Rows.js +0 -15
  22. package/build/cjs/features/Rows.js.map +1 -1
  23. package/build/cjs/features/Sorting.js +7 -10
  24. package/build/cjs/features/Sorting.js.map +1 -1
  25. package/build/cjs/features/Visibility.js +8 -21
  26. package/build/cjs/features/Visibility.js.map +1 -1
  27. package/build/cjs/filterFns.js +16 -0
  28. package/build/cjs/filterFns.js.map +1 -1
  29. package/build/cjs/index.js +0 -1
  30. package/build/cjs/index.js.map +1 -1
  31. package/build/cjs/utils.js +0 -16
  32. package/build/cjs/utils.js.map +1 -1
  33. package/build/esm/index.js +90 -266
  34. package/build/esm/index.js.map +1 -1
  35. package/build/stats-html.html +1 -1
  36. package/build/stats-react.json +346 -346
  37. package/build/types/core.d.ts +8 -10
  38. package/build/types/createTable.d.ts +10 -11
  39. package/build/types/features/Cells.d.ts +1 -2
  40. package/build/types/features/ColumnSizing.d.ts +4 -18
  41. package/build/types/features/Expanding.d.ts +4 -8
  42. package/build/types/features/Grouping.d.ts +4 -8
  43. package/build/types/features/Headers.d.ts +1 -5
  44. package/build/types/features/Pagination.d.ts +5 -6
  45. package/build/types/features/RowSelection.d.ts +5 -12
  46. package/build/types/features/Rows.d.ts +2 -4
  47. package/build/types/features/Sorting.d.ts +3 -7
  48. package/build/types/features/Visibility.d.ts +3 -6
  49. package/build/types/filterFns.d.ts +5 -0
  50. package/build/types/types.d.ts +10 -60
  51. package/build/types/utils.d.ts +1 -4
  52. package/build/umd/index.development.js +89 -266
  53. package/build/umd/index.development.js.map +1 -1
  54. package/build/umd/index.production.js +1 -1
  55. package/build/umd/index.production.js.map +1 -1
  56. package/package.json +1 -1
  57. package/src/core.ts +28 -52
  58. package/src/createTable.ts +13 -17
  59. package/src/features/Cells.ts +1 -27
  60. package/src/features/ColumnSizing.ts +14 -44
  61. package/src/features/Columns.ts +0 -2
  62. package/src/features/Expanding.ts +14 -40
  63. package/src/features/Grouping.ts +10 -37
  64. package/src/features/Headers.ts +1 -95
  65. package/src/features/Pagination.ts +8 -2
  66. package/src/features/Pinning.ts +1 -1
  67. package/src/features/RowSelection.ts +25 -87
  68. package/src/features/Rows.ts +2 -30
  69. package/src/features/Sorting.ts +17 -41
  70. package/src/features/Visibility.ts +15 -43
  71. package/src/filterFns.ts +20 -0
  72. package/src/types.ts +36 -98
  73. package/src/utils/getColumnFilteredRowModelAsync.ts +1 -5
  74. package/src/utils/getGlobalFilteredRowModelAsync.ts +2 -6
  75. package/src/utils/getSortedRowModelAsync.ts +0 -1
  76. package/src/utils.ts +1 -28
package/src/types.ts CHANGED
@@ -62,6 +62,7 @@ import {
62
62
  ColumnSizingTableState,
63
63
  } from './features/ColumnSizing'
64
64
  import {
65
+ PaginationInitialTableState,
65
66
  PaginationInstance,
66
67
  PaginationOptions,
67
68
  PaginationTableState,
@@ -85,19 +86,17 @@ export type TableGenerics = {
85
86
  FilterFns?: any
86
87
  SortingFns?: any
87
88
  AggregationFns?: any
88
- Render?: any
89
+ Renderer?: any
90
+ Rendered?: any
89
91
  ColumnMeta?: any
90
92
  TableMeta?: any
91
93
  }
92
94
 
93
95
  export type AnyRender = (Comp: any, props: any) => any
94
96
 
95
- export type UseRenderer<TGenerics extends TableGenerics> =
96
- TGenerics['Render'] extends (...args: any) => any ? TGenerics['Render'] : any
97
-
98
97
  export type TableFeature = {
99
98
  getDefaultOptions?: (instance: any) => any
100
- getInitialState?: () => any
99
+ getInitialState?: (initialState?: InitialTableState) => any
101
100
  createInstance?: (instance: any) => any
102
101
  getDefaultColumn?: () => any
103
102
  createColumn?: (column: any, instance: any) => any
@@ -123,19 +122,20 @@ export type TableInstance<TGenerics extends TableGenerics> =
123
122
  PaginationInstance<TGenerics> &
124
123
  RowSelectionInstance<TGenerics>
125
124
 
126
- export type Options<TGenerics extends TableGenerics> = CoreOptions<TGenerics> &
127
- ColumnsOptions<TGenerics> &
128
- RowsOptions<TGenerics> &
129
- VisibilityOptions &
130
- ColumnOrderOptions &
131
- ColumnPinningOptions &
132
- FiltersOptions<TGenerics> &
133
- SortingOptions<TGenerics> &
134
- GroupingOptions<TGenerics> &
135
- ExpandedOptions<TGenerics> &
136
- ColumnSizingOptions &
137
- PaginationOptions<TGenerics> &
138
- RowSelectionOptions<TGenerics>
125
+ export type TableOptions<TGenerics extends TableGenerics> =
126
+ CoreOptions<TGenerics> &
127
+ ColumnsOptions<TGenerics> &
128
+ RowsOptions<TGenerics> &
129
+ VisibilityOptions &
130
+ ColumnOrderOptions &
131
+ ColumnPinningOptions &
132
+ FiltersOptions<TGenerics> &
133
+ SortingOptions<TGenerics> &
134
+ GroupingOptions<TGenerics> &
135
+ ExpandedOptions<TGenerics> &
136
+ ColumnSizingOptions &
137
+ PaginationOptions<TGenerics> &
138
+ RowSelectionOptions<TGenerics>
139
139
 
140
140
  export type TableState = CoreTableState &
141
141
  VisibilityTableState &
@@ -149,6 +149,20 @@ export type TableState = CoreTableState &
149
149
  PaginationTableState &
150
150
  RowSelectionTableState
151
151
 
152
+ export type InitialTableState = Partial<
153
+ CoreTableState &
154
+ VisibilityTableState &
155
+ ColumnOrderTableState &
156
+ ColumnPinningTableState &
157
+ FiltersTableState &
158
+ SortingTableState &
159
+ ExpandedTableState &
160
+ GroupingTableState &
161
+ ColumnSizingTableState &
162
+ PaginationInitialTableState &
163
+ RowSelectionTableState
164
+ >
165
+
152
166
  export type Row<TGenerics extends TableGenerics> = CoreRow<TGenerics> &
153
167
  CellsRow<TGenerics> &
154
168
  VisibilityRow<TGenerics> &
@@ -171,7 +185,7 @@ export type AccessorFn<TData> = (originalRow: TData, index: number) => any
171
185
 
172
186
  export type Renderable<TGenerics extends TableGenerics, TProps> =
173
187
  | string
174
- | ((props: TProps) => ReturnType<UseRenderer<TGenerics>>)
188
+ | ((props: TProps) => TGenerics['Rendered'])
175
189
 
176
190
  export type ColumnDef<TGenerics extends TableGenerics> =
177
191
  CoreColumnDef<TGenerics> &
@@ -201,8 +215,7 @@ export type CoreCell<TGenerics extends TableGenerics> = {
201
215
  value: TGenerics['Value']
202
216
  row: Row<TGenerics>
203
217
  column: Column<TGenerics>
204
- getCellProps: PropGetter<CellProps>
205
- renderCell: () => string | null | ReturnType<UseRenderer<TGenerics>>
218
+ renderCell: () => string | null | TGenerics['Rendered']
206
219
  }
207
220
 
208
221
  export type Header<TGenerics extends TableGenerics> = CoreHeader<TGenerics> &
@@ -219,25 +232,21 @@ export type CoreHeader<TGenerics extends TableGenerics> = {
219
232
  subHeaders: Header<TGenerics>[]
220
233
  colSpan?: number
221
234
  rowSpan?: number
222
- getHeaderProps: PropGetter<HeaderProps>
223
- getFooterProps: PropGetter<HeaderProps>
224
235
  getLeafHeaders: () => Header<TGenerics>[]
225
236
  isPlaceholder?: boolean
226
237
  placeholderId?: string
227
238
  renderHeader: (options?: {
228
239
  renderPlaceholder?: boolean
229
- }) => string | null | ReturnType<UseRenderer<TGenerics>>
240
+ }) => string | null | TGenerics['Rendered']
230
241
  renderFooter: (options?: {
231
242
  renderPlaceholder?: boolean
232
- }) => string | null | ReturnType<UseRenderer<TGenerics>>
243
+ }) => string | null | TGenerics['Rendered']
233
244
  }
234
245
 
235
246
  export type HeaderGroup<TGenerics extends TableGenerics> = {
236
247
  id: string
237
248
  depth: number
238
249
  headers: Header<TGenerics>[]
239
- getHeaderGroupProps: PropGetter<HeaderGroupProps>
240
- getFooterGroupProps: PropGetter<FooterGroupProps>
241
250
  }
242
251
 
243
252
  export type HeaderRenderProps<THeader> = {
@@ -253,75 +262,4 @@ export type CellRenderProps<TCell, TRow> = {
253
262
  row: TRow
254
263
  }
255
264
 
256
- export type TableProps = {
257
- role: string
258
- }
259
-
260
- export type TableBodyProps = {
261
- role: string
262
- }
263
-
264
- export type TableHeadProps = {
265
- key: string
266
- role: string
267
- }
268
-
269
- export type TableFooterProps = {
270
- key: string
271
- role: string
272
- }
273
-
274
- export type HeaderGroupProps = {
275
- key: string
276
- role: string
277
- }
278
-
279
- export type FooterGroupProps = {
280
- key: string
281
- role: string
282
- }
283
-
284
- export type HeaderProps = {
285
- key: string
286
- role: string
287
- colSpan?: number
288
- rowSpan?: number
289
- }
290
-
291
- export type FooterProps = {
292
- key: string
293
- role: string
294
- colSpan?: number
295
- rowSpan?: number
296
- }
297
-
298
- export type RowProps = {
299
- key: string
300
- role: string
301
- }
302
-
303
- export type CellProps = {
304
- key: string
305
- role: string
306
- }
307
-
308
- //
309
-
310
- export type PropGetter<TBase> = <TGetter extends Getter<TBase>>(
311
- userProps?: TGetter
312
- ) => PropGetterValue<TBase, TGetter>
313
-
314
- export type Getter<TInitial> =
315
- | ((initial: TInitial) => object)
316
- | object
317
- | undefined
318
-
319
- export type PropGetterValue<TBase, TGetter> = TGetter extends undefined
320
- ? TBase
321
- : TGetter extends (...args: any[]) => infer TReturn
322
- ? Overwrite<TBase, TReturn>
323
- : TGetter extends object
324
- ? Overwrite<TBase, TGetter>
325
- : never
326
-
327
265
  export type NoInfer<A extends any> = [A][A extends any ? 0 : never]
@@ -1,9 +1,5 @@
1
1
  import { TableInstance, RowModel, TableGenerics, Row } from '../types'
2
- import { incrementalMemo, memo } from '../utils'
3
- import {
4
- filterRowModelFromLeafs,
5
- filterRowModelFromRoot,
6
- } from './filterRowsUtils'
2
+ import { incrementalMemo } from '../utils'
7
3
 
8
4
  export function getColumnFilteredRowModelAsync<
9
5
  TGenerics extends TableGenerics
@@ -1,9 +1,5 @@
1
- import { TableInstance, RowModel, TableGenerics, Row } from '../types'
2
- import { incrementalMemo, memo } from '../utils'
3
- import {
4
- filterRowModelFromLeafs,
5
- filterRowModelFromRoot,
6
- } from './filterRowsUtils'
1
+ import { TableInstance, RowModel, TableGenerics } from '../types'
2
+ import { incrementalMemo } from '../utils'
7
3
 
8
4
  export function getGlobalFilteredRowModelAsync<
9
5
  TGenerics extends TableGenerics
@@ -1,5 +1,4 @@
1
1
  import { TableInstance, Row, RowModel, TableGenerics } from '../types'
2
- import { SortingFn } from '../features/Sorting'
3
2
  import { incrementalMemo, memo } from '../utils'
4
3
 
5
4
  export function getSortedRowModelSync<TGenerics extends TableGenerics>(opts?: {
package/src/utils.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { Getter, NoInfer, PropGetterValue, TableState, Updater } from './types'
1
+ import { NoInfer, TableState, Updater } from './types'
2
2
 
3
- export type IsAny<T> = 0 extends 1 & T ? true : false
4
3
  export type PartialKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
5
4
  export type RequiredKeys<T, K extends keyof T> = Omit<T, K> &
6
5
  Required<Pick<T, K>>
@@ -12,15 +11,6 @@ export type Overwrite<T, U extends { [TKey in keyof T]?: any }> = Omit<
12
11
 
13
12
  export type IfDefined<T, N> = 0 extends 1 & T ? N : T extends {} ? T : N
14
13
 
15
- // export type DefinedGenericKeys<T extends TableGenerics> = {
16
- // [K in keyof T]: 0 extends 1 & T[K] ? never : T[K] extends {} ? K : never
17
- // }[keyof T]
18
-
19
- // export type DefinedGenerics<T extends TableGenerics> = Pick<
20
- // T,
21
- // DefinedGenericKeys<T>
22
- // >
23
-
24
14
  export function functionalUpdate<T>(updater: Updater<T>, input: T): T {
25
15
  return typeof updater === 'function'
26
16
  ? (updater as (input: T) => T)(input)
@@ -98,23 +88,6 @@ export function flattenBy<TNode>(
98
88
  return flat
99
89
  }
100
90
 
101
- type PropGetterImpl = <TBaseProps, TGetter extends Getter<TBaseProps>>(
102
- initial: TBaseProps,
103
- userProps?: TGetter
104
- ) => PropGetterValue<TBaseProps, TGetter>
105
-
106
- // @ts-ignore // Just rely on the type, not the implementation
107
- export const propGetter: PropGetterImpl = (initial, getter) => {
108
- if (isFunction(getter)) {
109
- return getter(initial)
110
- }
111
-
112
- return {
113
- ...initial,
114
- ...(getter ?? {}),
115
- }
116
- }
117
-
118
91
  export function memo<TDeps extends readonly any[], TResult>(
119
92
  getDeps: () => [...TDeps],
120
93
  fn: (...args: NoInfer<[...TDeps]>) => TResult,