@tanstack/table-core 8.0.0-alpha.12 → 8.0.0-alpha.16

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 (70) hide show
  1. package/build/cjs/core.js +17 -6
  2. package/build/cjs/core.js.map +1 -1
  3. package/build/cjs/createTable.js +17 -9
  4. package/build/cjs/createTable.js.map +1 -1
  5. package/build/cjs/features/ColumnSizing.js +2 -2
  6. package/build/cjs/features/ColumnSizing.js.map +1 -1
  7. package/build/cjs/features/Expanding.js +2 -2
  8. package/build/cjs/features/Expanding.js.map +1 -1
  9. package/build/cjs/features/Filters.js +1 -1
  10. package/build/cjs/features/Filters.js.map +1 -1
  11. package/build/cjs/features/Grouping.js +13 -2
  12. package/build/cjs/features/Grouping.js.map +1 -1
  13. package/build/cjs/features/Headers.js +4 -4
  14. package/build/cjs/features/Headers.js.map +1 -1
  15. package/build/cjs/features/RowSelection.js.map +1 -1
  16. package/build/cjs/features/Visibility.js.map +1 -1
  17. package/build/cjs/index.js +1 -3
  18. package/build/cjs/index.js.map +1 -1
  19. package/build/cjs/types.js +0 -3
  20. package/build/cjs/types.js.map +1 -1
  21. package/build/cjs/utils/columnFilterRowsFn.js +1 -1
  22. package/build/cjs/utils/columnFilterRowsFn.js.map +1 -1
  23. package/build/cjs/utils/expandRowsFn.js.map +1 -1
  24. package/build/cjs/utils/globalFilterRowsFn.js.map +1 -1
  25. package/build/cjs/utils/groupRowsFn.js +1 -1
  26. package/build/cjs/utils/groupRowsFn.js.map +1 -1
  27. package/build/cjs/utils/paginateRowsFn.js.map +1 -1
  28. package/build/cjs/utils/sortRowsFn.js.map +1 -1
  29. package/build/cjs/utils.js +0 -24
  30. package/build/cjs/utils.js.map +1 -1
  31. package/build/esm/index.js +58 -50
  32. package/build/esm/index.js.map +1 -1
  33. package/build/stats-html.html +1 -1
  34. package/build/stats-react.json +268 -282
  35. package/build/types/core.d.ts +11 -9
  36. package/build/types/createTable.d.ts +32 -16
  37. package/build/types/features/ColumnSizing.d.ts +2 -3
  38. package/build/types/features/Grouping.d.ts +11 -5
  39. package/build/types/features/RowSelection.d.ts +2 -3
  40. package/build/types/features/Visibility.d.ts +1 -0
  41. package/build/types/types.d.ts +14 -7
  42. package/build/types/utils/columnFilterRowsFn.d.ts +2 -2
  43. package/build/types/utils/expandRowsFn.d.ts +2 -2
  44. package/build/types/utils/globalFilterRowsFn.d.ts +2 -2
  45. package/build/types/utils/groupRowsFn.d.ts +2 -2
  46. package/build/types/utils/paginateRowsFn.d.ts +2 -2
  47. package/build/types/utils/sortRowsFn.d.ts +2 -2
  48. package/build/types/utils.d.ts +4 -5
  49. package/build/umd/index.development.js +62 -58
  50. package/build/umd/index.development.js.map +1 -1
  51. package/build/umd/index.production.js +1 -1
  52. package/build/umd/index.production.js.map +1 -1
  53. package/package.json +1 -1
  54. package/src/core.tsx +63 -35
  55. package/src/createTable.tsx +69 -34
  56. package/src/features/ColumnSizing.ts +8 -14
  57. package/src/features/Expanding.ts +2 -2
  58. package/src/features/Filters.ts +1 -1
  59. package/src/features/Grouping.ts +30 -7
  60. package/src/features/Headers.ts +15 -3
  61. package/src/features/RowSelection.ts +2 -2
  62. package/src/features/Visibility.ts +1 -0
  63. package/src/types.ts +28 -15
  64. package/src/utils/columnFilterRowsFn.ts +3 -5
  65. package/src/utils/expandRowsFn.ts +2 -2
  66. package/src/utils/globalFilterRowsFn.ts +2 -2
  67. package/src/utils/groupRowsFn.ts +4 -4
  68. package/src/utils/paginateRowsFn.ts +2 -2
  69. package/src/utils/sortRowsFn.ts +2 -2
  70. package/src/utils.tsx +6 -45
package/src/types.ts CHANGED
@@ -1,4 +1,3 @@
1
- import React from 'react'
2
1
  import {
3
2
  CoreColumn,
4
3
  CoreColumnDef,
@@ -42,6 +41,7 @@ import {
42
41
  SortingTableState,
43
42
  } from './features/Sorting'
44
43
  import {
44
+ GroupingCell,
45
45
  GroupingColumn,
46
46
  GroupingColumnDef,
47
47
  GroupingInstance,
@@ -55,7 +55,7 @@ import {
55
55
  ExpandedTableState,
56
56
  ExpandedRow,
57
57
  } from './features/Expanding'
58
- import { Overwrite } from './utils'
58
+ import { Overwrite, PartialKeys } from './utils'
59
59
  import {
60
60
  ColumnSizingColumn,
61
61
  ColumnSizingColumnDef,
@@ -76,20 +76,27 @@ import {
76
76
  RowSelectionTableState,
77
77
  } from './features/RowSelection'
78
78
 
79
- // declare global {
80
- // const process.env.NODE_ENV !== 'production': boolean
81
- // }
82
-
83
79
  export type DefaultGenerics = {
84
80
  Row: unknown
85
81
  Value: unknown
86
82
  FilterFns: object
87
83
  SortingFns: object
88
84
  AggregationFns: object
85
+ Render: unknown
86
+ ColumnMeta: object
89
87
  }
90
88
 
89
+ export type AnyRender = (Comp: any, props: any) => any
90
+
91
+ export type UseRenderer<TGenerics extends PartialGenerics> =
92
+ TGenerics['Render'] extends (...args: any) => any ? TGenerics['Render'] : any
93
+
91
94
  export type PartialGenerics = Partial<DefaultGenerics>
92
95
 
96
+ export type AnyGenerics = {
97
+ [TKey in keyof PartialGenerics]: any
98
+ }
99
+
93
100
  export type TableInstance<TGenerics extends PartialGenerics> =
94
101
  TableCore<TGenerics> &
95
102
  VisibilityInstance<TGenerics> &
@@ -104,11 +111,6 @@ export type TableInstance<TGenerics extends PartialGenerics> =
104
111
  PaginationInstance<TGenerics> &
105
112
  RowSelectionInstance<TGenerics>
106
113
 
107
- export type Renderable<TProps> =
108
- | React.ReactNode
109
- | React.FunctionComponent<TProps>
110
- | React.Component<TProps>
111
-
112
114
  //
113
115
 
114
116
  export type Options<TGenerics extends PartialGenerics> =
@@ -167,6 +169,10 @@ export type _NonGenerated<T> = Overwrite<
167
169
  }
168
170
  >
169
171
 
172
+ export type Renderable<TGenerics extends PartialGenerics, TProps> =
173
+ | string
174
+ | ((props: TProps) => ReturnType<UseRenderer<TGenerics>>)
175
+
170
176
  export type ColumnDef<TGenerics extends PartialGenerics> =
171
177
  CoreColumnDef<TGenerics> &
172
178
  VisibilityColumnDef &
@@ -185,7 +191,10 @@ export type Column<TGenerics extends PartialGenerics> = ColumnDef<TGenerics> &
185
191
  GroupingColumn<TGenerics> &
186
192
  ColumnSizingColumn<TGenerics>
187
193
 
188
- export type Cell<TGenerics extends PartialGenerics> = {
194
+ export type Cell<TGenerics extends PartialGenerics> = CoreCell<TGenerics> &
195
+ GroupingCell<TGenerics>
196
+
197
+ export type CoreCell<TGenerics extends PartialGenerics> = {
189
198
  id: string
190
199
  rowId: string
191
200
  columnId: string
@@ -193,7 +202,7 @@ export type Cell<TGenerics extends PartialGenerics> = {
193
202
  row: Row<TGenerics>
194
203
  column: Column<TGenerics>
195
204
  getCellProps: PropGetter<CellProps>
196
- renderCell: () => React.ReactNode
205
+ renderCell: () => string | null | ReturnType<UseRenderer<TGenerics>>
197
206
  }
198
207
 
199
208
  export type Header<TGenerics extends PartialGenerics> = CoreHeader<TGenerics> &
@@ -212,8 +221,12 @@ export type CoreHeader<TGenerics extends PartialGenerics> = {
212
221
  getLeafHeaders: () => Header<TGenerics>[]
213
222
  isPlaceholder?: boolean
214
223
  placeholderId?: string
215
- renderHeader: (options?: { renderPlaceholder?: boolean }) => React.ReactNode
216
- renderFooter: (options?: { renderPlaceholder?: boolean }) => React.ReactNode
224
+ renderHeader: (options?: {
225
+ renderPlaceholder?: boolean
226
+ }) => string | null | ReturnType<UseRenderer<TGenerics>>
227
+ renderFooter: (options?: {
228
+ renderPlaceholder?: boolean
229
+ }) => string | null | ReturnType<UseRenderer<TGenerics>>
217
230
  }
218
231
 
219
232
  export type HeaderGroup<TGenerics extends PartialGenerics> = {
@@ -1,6 +1,6 @@
1
- import { PartialGenerics, TableInstance, Row, RowModel } from '../types'
1
+ import { AnyGenerics, TableInstance, Row, RowModel } from '../types'
2
2
 
3
- export function columnFilterRowsFn<TGenerics extends PartialGenerics>(
3
+ export function columnFilterRowsFn<TGenerics extends AnyGenerics>(
4
4
  instance: TableInstance<TGenerics>,
5
5
  rowModel: RowModel<TGenerics>
6
6
  ): RowModel<TGenerics> {
@@ -18,9 +18,7 @@ export function columnFilterRowsFn<TGenerics extends PartialGenerics>(
18
18
 
19
19
  if (!column) {
20
20
  if (process.env.NODE_ENV !== 'production') {
21
- console.warn(
22
- `React-Table: Could not find a column with id: ${columnId}`
23
- )
21
+ console.warn(`Table: Could not find a column with id: ${columnId}`)
24
22
  }
25
23
  throw new Error()
26
24
  }
@@ -1,6 +1,6 @@
1
- import { PartialGenerics, TableInstance, Row, RowModel } from '../types'
1
+ import { TableInstance, Row, RowModel, AnyGenerics } from '../types'
2
2
 
3
- export function expandRowsFn<TGenerics extends PartialGenerics>(
3
+ export function expandRowsFn<TGenerics extends AnyGenerics>(
4
4
  instance: TableInstance<TGenerics>,
5
5
  sortedRowModel: RowModel<TGenerics>
6
6
  ): RowModel<TGenerics> {
@@ -1,6 +1,6 @@
1
- import { PartialGenerics, TableInstance, Row, RowModel } from '../types'
1
+ import { TableInstance, Row, RowModel, AnyGenerics } from '../types'
2
2
 
3
- export function globalFilterRowsFn<TGenerics extends PartialGenerics>(
3
+ export function globalFilterRowsFn<TGenerics extends AnyGenerics>(
4
4
  instance: TableInstance<TGenerics>,
5
5
  rowModel: RowModel<TGenerics>
6
6
  ): RowModel<TGenerics> {
@@ -1,7 +1,7 @@
1
- import { PartialGenerics, TableInstance, Row, RowModel } from '../types'
1
+ import { TableInstance, Row, RowModel, AnyGenerics } from '../types'
2
2
  import { flattenBy } from '../utils'
3
3
 
4
- export function groupRowsFn<TGenerics extends PartialGenerics>(
4
+ export function groupRowsFn<TGenerics extends AnyGenerics>(
5
5
  instance: TableInstance<TGenerics>,
6
6
  sortedRowModel: RowModel<TGenerics>
7
7
  ): RowModel<TGenerics> {
@@ -52,7 +52,7 @@ export function groupRowsFn<TGenerics extends PartialGenerics>(
52
52
  console.info({ column })
53
53
  throw new Error(
54
54
  process.env.NODE_ENV !== 'production'
55
- ? `React Table: Invalid column.aggregateType option for column listed above`
55
+ ? `Table: Invalid column.aggregateType option for column listed above`
56
56
  : ''
57
57
  )
58
58
  } else {
@@ -151,7 +151,7 @@ export function groupRowsFn<TGenerics extends PartialGenerics>(
151
151
  }
152
152
  }
153
153
 
154
- function groupBy<TGenerics extends PartialGenerics>(
154
+ function groupBy<TGenerics extends AnyGenerics>(
155
155
  rows: Row<TGenerics>[],
156
156
  columnId: string
157
157
  ) {
@@ -1,7 +1,7 @@
1
- import { PartialGenerics, TableInstance, RowModel } from '../types'
1
+ import { TableInstance, RowModel, AnyGenerics } from '../types'
2
2
  import { expandRowsFn } from './expandRowsFn'
3
3
 
4
- export function paginateRowsFn<TGenerics extends PartialGenerics>(
4
+ export function paginateRowsFn<TGenerics extends AnyGenerics>(
5
5
  instance: TableInstance<TGenerics>,
6
6
  rowModel: RowModel<TGenerics>
7
7
  ): RowModel<TGenerics> {
@@ -1,7 +1,7 @@
1
- import { PartialGenerics, TableInstance, Row, RowModel } from '../types'
1
+ import { TableInstance, Row, RowModel, AnyGenerics } from '../types'
2
2
  import { SortingFn } from '../features/Sorting'
3
3
 
4
- export function sortRowsFn<TGenerics extends PartialGenerics>(
4
+ export function sortRowsFn<TGenerics extends AnyGenerics>(
5
5
  instance: TableInstance<TGenerics>,
6
6
  rowModel: RowModel<TGenerics>
7
7
  ): RowModel<TGenerics> {
package/src/utils.tsx CHANGED
@@ -1,18 +1,14 @@
1
- import React from 'react'
2
- import {
3
- Getter,
4
- NoInfer,
5
- PropGetterValue,
6
- Renderable,
7
- TableState,
8
- Updater,
9
- } from './types'
1
+ import { Getter, NoInfer, PropGetterValue, TableState, Updater } from './types'
10
2
 
11
3
  export type IsAny<T> = 0 extends 1 & T ? true : false
12
4
  export type PartialKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
13
5
  export type RequiredKeys<T, K extends keyof T> = Omit<T, K> &
14
6
  Required<Pick<T, K>>
15
- export type Overwrite<T, U> = Omit<T, keyof U> & U
7
+ export type Overwrite<T, U extends { [TKey in keyof T]?: any }> = Omit<
8
+ T,
9
+ keyof U
10
+ > &
11
+ U
16
12
 
17
13
  export type DataUpdateFunction<T> = (input: T) => T
18
14
 
@@ -168,41 +164,6 @@ export function memo<TDeps extends readonly any[], TResult>(
168
164
  }
169
165
  }
170
166
 
171
- export type Render = typeof flexRender
172
-
173
- export function flexRender<TProps extends {}>(
174
- Comp: Renderable<TProps>,
175
- props: TProps
176
- ): React.ReactNode {
177
- return !Comp ? null : isReactComponent(Comp) ? <Comp {...props} /> : Comp
178
- }
179
-
180
- function isReactComponent(component: unknown): component is React.FC {
181
- return (
182
- isClassComponent(component) ||
183
- typeof component === 'function' ||
184
- isExoticComponent(component)
185
- )
186
- }
187
-
188
- function isClassComponent(component: any) {
189
- return (
190
- typeof component === 'function' &&
191
- (() => {
192
- const proto = Object.getPrototypeOf(component)
193
- return proto.prototype && proto.prototype.isReactComponent
194
- })()
195
- )
196
- }
197
-
198
- function isExoticComponent(component: any) {
199
- return (
200
- typeof component === 'object' &&
201
- typeof component.$$typeof === 'symbol' &&
202
- ['react.memo', 'react.forward_ref'].includes(component.$$typeof.description)
203
- )
204
- }
205
-
206
167
  // export function hashString(str: string, seed = 0): string {
207
168
  // let h1 = 0xdeadbeef ^ seed,
208
169
  // h2 = 0x41c6ce57 ^ seed