@tanstack/table-core 8.0.0-alpha.9 → 8.0.0-beta.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 (186) hide show
  1. package/build/cjs/aggregationFns.js +120 -0
  2. package/build/cjs/aggregationFns.js.map +1 -0
  3. package/build/cjs/core/cell.js +40 -0
  4. package/build/cjs/core/cell.js.map +1 -0
  5. package/build/cjs/core/column.js +88 -0
  6. package/build/cjs/core/column.js.map +1 -0
  7. package/build/cjs/core/headers.js +403 -0
  8. package/build/cjs/core/headers.js.map +1 -0
  9. package/build/cjs/core/instance.js +255 -0
  10. package/build/cjs/core/instance.js.map +1 -0
  11. package/build/cjs/core/row.js +77 -0
  12. package/build/cjs/core/row.js.map +1 -0
  13. package/build/cjs/createTable.js +36 -29
  14. package/build/cjs/createTable.js.map +1 -1
  15. package/build/cjs/features/ColumnSizing.js +157 -189
  16. package/build/cjs/features/ColumnSizing.js.map +1 -1
  17. package/build/cjs/features/Expanding.js +103 -155
  18. package/build/cjs/features/Expanding.js.map +1 -1
  19. package/build/cjs/features/Filters.js +155 -304
  20. package/build/cjs/features/Filters.js.map +1 -1
  21. package/build/cjs/features/Grouping.js +97 -157
  22. package/build/cjs/features/Grouping.js.map +1 -1
  23. package/build/cjs/features/Ordering.js +30 -41
  24. package/build/cjs/features/Ordering.js.map +1 -1
  25. package/build/cjs/features/Pagination.js +102 -105
  26. package/build/cjs/features/Pagination.js.map +1 -1
  27. package/build/cjs/features/Pinning.js +131 -89
  28. package/build/cjs/features/Pinning.js.map +1 -1
  29. package/build/cjs/features/RowSelection.js +138 -267
  30. package/build/cjs/features/RowSelection.js.map +1 -1
  31. package/build/cjs/features/Sorting.js +82 -167
  32. package/build/cjs/features/Sorting.js.map +1 -1
  33. package/build/cjs/features/Visibility.js +69 -115
  34. package/build/cjs/features/Visibility.js.map +1 -1
  35. package/build/cjs/filterFns.js +107 -0
  36. package/build/cjs/filterFns.js.map +1 -0
  37. package/build/cjs/index.js +36 -23
  38. package/build/cjs/index.js.map +1 -1
  39. package/build/cjs/sortingFns.js +124 -0
  40. package/build/cjs/sortingFns.js.map +1 -0
  41. package/build/cjs/utils/filterRowsUtils.js +117 -0
  42. package/build/cjs/utils/filterRowsUtils.js.map +1 -0
  43. package/build/cjs/utils/getCoreRowModel.js +79 -0
  44. package/build/cjs/utils/getCoreRowModel.js.map +1 -0
  45. package/build/cjs/utils/getExpandedRowModel.js +57 -0
  46. package/build/cjs/utils/getExpandedRowModel.js.map +1 -0
  47. package/build/cjs/utils/getFacetedMinMaxValues.js +54 -0
  48. package/build/cjs/utils/getFacetedMinMaxValues.js.map +1 -0
  49. package/build/cjs/utils/getFacetedRowModel.js +50 -0
  50. package/build/cjs/utils/getFacetedRowModel.js.map +1 -0
  51. package/build/cjs/utils/getFacetedUniqueValues.js +48 -0
  52. package/build/cjs/utils/getFacetedUniqueValues.js.map +1 -0
  53. package/build/cjs/utils/getFilteredRowModel.js +139 -0
  54. package/build/cjs/utils/getFilteredRowModel.js.map +1 -0
  55. package/build/cjs/utils/getGroupedRowModel.js +161 -0
  56. package/build/cjs/utils/getGroupedRowModel.js.map +1 -0
  57. package/build/cjs/utils/getPaginationRowModel.js +61 -0
  58. package/build/cjs/utils/getPaginationRowModel.js.map +1 -0
  59. package/build/cjs/utils/getSortedRowModel.js +110 -0
  60. package/build/cjs/utils/getSortedRowModel.js.map +1 -0
  61. package/build/cjs/utils.js +38 -107
  62. package/build/cjs/utils.js.map +1 -1
  63. package/build/esm/index.js +2976 -3853
  64. package/build/esm/index.js.map +1 -1
  65. package/build/stats-html.html +1 -1
  66. package/build/stats-react.json +586 -408
  67. package/build/types/aggregationFns.d.ts +13 -0
  68. package/build/types/core/cell.d.ts +9 -0
  69. package/build/types/core/column.d.ts +40 -0
  70. package/build/types/core/headers.d.ts +46 -0
  71. package/build/types/core/instance.d.ts +57 -0
  72. package/build/types/core/row.d.ts +15 -0
  73. package/build/types/createTable.d.ts +47 -26
  74. package/build/types/features/ColumnSizing.d.ts +32 -44
  75. package/build/types/features/Expanding.d.ts +15 -26
  76. package/build/types/features/Filters.d.ts +64 -63
  77. package/build/types/features/Grouping.d.ts +32 -46
  78. package/build/types/features/Ordering.d.ts +7 -10
  79. package/build/types/features/Pagination.d.ts +16 -15
  80. package/build/types/features/Pinning.d.ts +16 -17
  81. package/build/types/features/RowSelection.d.ts +13 -33
  82. package/build/types/features/Sorting.d.ts +25 -44
  83. package/build/types/features/Visibility.d.ts +16 -25
  84. package/build/types/filterFns.d.ts +13 -0
  85. package/build/types/index.d.ts +16 -10
  86. package/build/types/sortingFns.d.ts +11 -0
  87. package/build/types/types.d.ts +37 -122
  88. package/build/types/utils/filterRowsUtils.d.ts +4 -0
  89. package/build/types/utils/getCoreRowModel.d.ts +2 -0
  90. package/build/types/utils/getExpandedRowModel.d.ts +7 -0
  91. package/build/types/utils/getFacetedMinMaxValues.d.ts +2 -0
  92. package/build/types/utils/getFacetedRowModel.d.ts +2 -0
  93. package/build/types/utils/getFacetedUniqueValues.d.ts +2 -0
  94. package/build/types/utils/getFilteredRowModel.d.ts +2 -0
  95. package/build/types/utils/getGroupedRowModel.d.ts +2 -0
  96. package/build/types/utils/getPaginationRowModel.d.ts +4 -0
  97. package/build/types/utils/getSortedRowModel.d.ts +2 -0
  98. package/build/types/utils.d.ts +7 -11
  99. package/build/umd/index.development.js +3024 -3893
  100. package/build/umd/index.development.js.map +1 -1
  101. package/build/umd/index.production.js +1 -1
  102. package/build/umd/index.production.js.map +1 -1
  103. package/package.json +9 -10
  104. package/src/.DS_Store +0 -0
  105. package/src/aggregationFns.ts +123 -0
  106. package/src/core/cell.ts +48 -0
  107. package/src/core/column.ts +147 -0
  108. package/src/core/headers.ts +575 -0
  109. package/src/core/instance.ts +361 -0
  110. package/src/core/row.ts +85 -0
  111. package/src/createTable.ts +188 -0
  112. package/src/features/ColumnSizing.ts +170 -185
  113. package/src/features/Expanding.ts +122 -194
  114. package/src/features/Filters.ts +301 -381
  115. package/src/features/Grouping.ts +160 -220
  116. package/src/features/Ordering.ts +24 -25
  117. package/src/features/Pagination.ts +90 -73
  118. package/src/features/Pinning.ts +186 -63
  119. package/src/features/RowSelection.ts +107 -245
  120. package/src/features/Sorting.ts +127 -225
  121. package/src/features/Visibility.ts +116 -132
  122. package/src/filterFns.ts +135 -0
  123. package/src/index.ts +29 -0
  124. package/src/{sortTypes.ts → sortingFns.ts} +63 -85
  125. package/src/types.ts +62 -168
  126. package/src/utils/filterRowsUtils.ts +112 -0
  127. package/src/utils/getCoreRowModel.ts +84 -0
  128. package/src/utils/getExpandedRowModel.ts +54 -0
  129. package/src/utils/getFacetedMinMaxValues.ts +40 -0
  130. package/src/utils/getFacetedRowModel.ts +50 -0
  131. package/src/utils/getFacetedUniqueValues.ts +37 -0
  132. package/src/utils/getFilteredRowModel.ts +159 -0
  133. package/src/utils/getGroupedRowModel.ts +175 -0
  134. package/src/utils/getPaginationRowModel.ts +48 -0
  135. package/src/utils/getSortedRowModel.ts +116 -0
  136. package/src/utils.ts +126 -0
  137. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -112
  138. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
  139. package/build/cjs/aggregationTypes.js +0 -130
  140. package/build/cjs/aggregationTypes.js.map +0 -1
  141. package/build/cjs/core.js +0 -545
  142. package/build/cjs/core.js.map +0 -1
  143. package/build/cjs/features/Headers.js +0 -630
  144. package/build/cjs/features/Headers.js.map +0 -1
  145. package/build/cjs/filterTypes.js +0 -172
  146. package/build/cjs/filterTypes.js.map +0 -1
  147. package/build/cjs/sortTypes.js +0 -122
  148. package/build/cjs/sortTypes.js.map +0 -1
  149. package/build/cjs/types.js +0 -22
  150. package/build/cjs/types.js.map +0 -1
  151. package/build/cjs/utils/columnFilterRowsFn.js +0 -131
  152. package/build/cjs/utils/columnFilterRowsFn.js.map +0 -1
  153. package/build/cjs/utils/expandRowsFn.js +0 -38
  154. package/build/cjs/utils/expandRowsFn.js.map +0 -1
  155. package/build/cjs/utils/globalFilterRowsFn.js +0 -101
  156. package/build/cjs/utils/globalFilterRowsFn.js.map +0 -1
  157. package/build/cjs/utils/groupRowsFn.js +0 -155
  158. package/build/cjs/utils/groupRowsFn.js.map +0 -1
  159. package/build/cjs/utils/paginateRowsFn.js +0 -44
  160. package/build/cjs/utils/paginateRowsFn.js.map +0 -1
  161. package/build/cjs/utils/sortRowsFn.js +0 -94
  162. package/build/cjs/utils/sortRowsFn.js.map +0 -1
  163. package/build/types/aggregationTypes.d.ts +0 -22
  164. package/build/types/core.d.ts +0 -105
  165. package/build/types/features/Headers.d.ts +0 -43
  166. package/build/types/filterTypes.d.ts +0 -50
  167. package/build/types/sortTypes.d.ts +0 -18
  168. package/build/types/utils/columnFilterRowsFn.d.ts +0 -2
  169. package/build/types/utils/expandRowsFn.d.ts +0 -2
  170. package/build/types/utils/globalFilterRowsFn.d.ts +0 -2
  171. package/build/types/utils/groupRowsFn.d.ts +0 -2
  172. package/build/types/utils/paginateRowsFn.d.ts +0 -2
  173. package/build/types/utils/sortRowsFn.d.ts +0 -2
  174. package/src/aggregationTypes.ts +0 -115
  175. package/src/core.tsx +0 -763
  176. package/src/createTable.tsx +0 -137
  177. package/src/features/Headers.ts +0 -747
  178. package/src/filterTypes.ts +0 -188
  179. package/src/index.tsx +0 -23
  180. package/src/utils/columnFilterRowsFn.ts +0 -113
  181. package/src/utils/expandRowsFn.ts +0 -30
  182. package/src/utils/globalFilterRowsFn.ts +0 -89
  183. package/src/utils/groupRowsFn.ts +0 -170
  184. package/src/utils/paginateRowsFn.ts +0 -28
  185. package/src/utils/sortRowsFn.ts +0 -95
  186. package/src/utils.tsx +0 -221
package/package.json CHANGED
@@ -1,19 +1,21 @@
1
1
  {
2
2
  "name": "@tanstack/table-core",
3
3
  "author": "Tanner Linsley",
4
- "version": "8.0.0-alpha.9",
5
- "description": "Hooks for building lightweight, fast and extendable datagrids for React",
4
+ "version": "8.0.0-beta.0",
5
+ "description": "Headless UI for building powerful tables & datagrids for TS/JS.",
6
6
  "license": "MIT",
7
- "homepage": "https://github.com/tanstack/react-table#readme",
7
+ "homepage": "https://github.com/tanstack/table#readme",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "git+https://github.com/tanstack/react-table.git"
10
+ "url": "git+https://github.com/tanstack/table.git"
11
11
  },
12
12
  "publishConfig": {
13
13
  "registry": "https://registry.npmjs.org/"
14
14
  },
15
15
  "keywords": [
16
16
  "react",
17
+ "vue",
18
+ "solid",
17
19
  "table",
18
20
  "table-core",
19
21
  "datagrid"
@@ -24,17 +26,14 @@
24
26
  },
25
27
  "module": "build/esm/index.js",
26
28
  "main": "build/cjs/index.js",
27
- "browser": "build/umd/index.production.min.js",
29
+ "browser": "build/umd/index.production.js",
28
30
  "types": "build/types/index.d.ts",
31
+ "sideEffects": false,
29
32
  "engines": {
30
33
  "node": ">=12"
31
34
  },
32
35
  "files": [
33
36
  "build",
34
37
  "src"
35
- ],
36
- "peerDependencies": {
37
- "react": ">=16",
38
- "react-dom": ">=16"
39
- }
38
+ ]
40
39
  }
package/src/.DS_Store CHANGED
Binary file
@@ -0,0 +1,123 @@
1
+ import { AggregationFn } from './features/Grouping'
2
+
3
+ const sum: AggregationFn<any> = (columnId, _leafRows, childRows) => {
4
+ // It's faster to just add the aggregations together instead of
5
+ // process leaf nodes individually
6
+ return childRows.reduce(
7
+ (sum: number, next: unknown) => sum + (typeof next === 'number' ? next : 0),
8
+ 0
9
+ )
10
+ }
11
+
12
+ const min: AggregationFn<any> = (columnId, _leafRows, childRows) => {
13
+ let min: number | undefined
14
+
15
+ childRows.forEach(row => {
16
+ const value = row.getValue(columnId)
17
+
18
+ if (
19
+ value != null &&
20
+ (min! > value || (min === undefined && value >= value))
21
+ ) {
22
+ min = value
23
+ }
24
+ })
25
+
26
+ return min
27
+ }
28
+
29
+ const max: AggregationFn<any> = (columnId, _leafRows, childRows) => {
30
+ let max: number | undefined
31
+
32
+ childRows.forEach(row => {
33
+ const value = row.getValue(columnId)
34
+ if (
35
+ value != null &&
36
+ (max! < value || (max === undefined && value >= value))
37
+ ) {
38
+ max = value
39
+ }
40
+ })
41
+
42
+ return max
43
+ }
44
+
45
+ const extent: AggregationFn<any> = (columnId, _leafRows, childRows) => {
46
+ let min: number | undefined
47
+ let max: number | undefined
48
+
49
+ childRows.forEach(row => {
50
+ const value = row.getValue(columnId)
51
+ if (value != null) {
52
+ if (min === undefined) {
53
+ if (value >= value) min = max = value
54
+ } else {
55
+ if (min > value) min = value
56
+ if (max! < value) max = value
57
+ }
58
+ }
59
+ })
60
+
61
+ return [min, max]
62
+ }
63
+
64
+ const mean: AggregationFn<any> = (columnId, leafRows) => {
65
+ let count = 0
66
+ let sum = 0
67
+
68
+ leafRows.forEach(row => {
69
+ let value = row.getValue(columnId)
70
+ if (value != null && (value = +value) >= value) {
71
+ ++count, (sum += value)
72
+ }
73
+ })
74
+
75
+ if (count) return sum / count
76
+
77
+ return
78
+ }
79
+
80
+ const median: AggregationFn<any> = (columnId, leafRows) => {
81
+ if (!leafRows.length) {
82
+ return
83
+ }
84
+
85
+ let min = 0
86
+ let max = 0
87
+
88
+ leafRows.forEach(row => {
89
+ let value = row.getValue(columnId)
90
+ if (typeof value === 'number') {
91
+ min = Math.min(min, value)
92
+ max = Math.max(max, value)
93
+ }
94
+ })
95
+
96
+ return (min + max) / 2
97
+ }
98
+
99
+ const unique: AggregationFn<any> = (columnId, leafRows) => {
100
+ return Array.from(new Set(leafRows.map(d => d.getValue(columnId))).values())
101
+ }
102
+
103
+ const uniqueCount: AggregationFn<any> = (columnId, leafRows) => {
104
+ return new Set(leafRows.map(d => d.getValue(columnId))).size
105
+ }
106
+
107
+ const count: AggregationFn<any> = (_columnId, leafRows) => {
108
+ return leafRows.length
109
+ }
110
+
111
+ export const aggregationFns = {
112
+ sum,
113
+ min,
114
+ max,
115
+ extent,
116
+ mean,
117
+ median,
118
+ unique,
119
+ uniqueCount,
120
+ count,
121
+ }
122
+
123
+ export type BuiltInAggregationFn = keyof typeof aggregationFns
@@ -0,0 +1,48 @@
1
+ import { Cell, Column, Row, TableGenerics, TableInstance } from '../types'
2
+
3
+ export type CoreCell<TGenerics extends TableGenerics> = {
4
+ id: string
5
+ getValue: () => TGenerics['Value']
6
+ row: Row<TGenerics>
7
+ column: Column<TGenerics>
8
+ renderCell: () => string | null | TGenerics['Rendered']
9
+ }
10
+
11
+ export function createCell<TGenerics extends TableGenerics>(
12
+ instance: TableInstance<TGenerics>,
13
+ row: Row<TGenerics>,
14
+ column: Column<TGenerics>,
15
+ columnId: string
16
+ ) {
17
+ const cell: CoreCell<TGenerics> = {
18
+ id: `${row.id}_${column.id}`,
19
+ row,
20
+ column,
21
+ getValue: () => row.getValue(columnId),
22
+ renderCell: () => {
23
+ return column.columnDef.cell
24
+ ? instance._render(column.columnDef.cell, {
25
+ instance,
26
+ column,
27
+ row,
28
+ cell: cell as Cell<TGenerics>,
29
+ getValue: cell.getValue,
30
+ })
31
+ : null
32
+ },
33
+ }
34
+
35
+ instance._features.forEach(feature => {
36
+ Object.assign(
37
+ cell,
38
+ feature.createCell?.(
39
+ cell as Cell<TGenerics>,
40
+ column,
41
+ row as Row<TGenerics>,
42
+ instance
43
+ )
44
+ )
45
+ }, {})
46
+
47
+ return cell as Cell<TGenerics>
48
+ }
@@ -0,0 +1,147 @@
1
+ import {
2
+ Cell,
3
+ Column,
4
+ Header,
5
+ TableGenerics,
6
+ TableInstance,
7
+ Row,
8
+ AccessorFn,
9
+ ColumnDef,
10
+ Renderable,
11
+ } from '../types'
12
+ import { memo } from '../utils'
13
+
14
+ export type CoreColumnDefType = 'data' | 'display' | 'group'
15
+
16
+ export type CoreColumnDef<TGenerics extends TableGenerics> = {
17
+ id: string
18
+ accessorKey?: string & keyof TGenerics['Row']
19
+ accessorFn?: AccessorFn<TGenerics['Row']>
20
+ columns?: ColumnDef<TGenerics>[]
21
+ header?: Renderable<
22
+ TGenerics,
23
+ {
24
+ instance: TableInstance<TGenerics>
25
+ header: Header<TGenerics>
26
+ column: Column<TGenerics>
27
+ }
28
+ >
29
+ footer?: Renderable<
30
+ TGenerics,
31
+ {
32
+ instance: TableInstance<TGenerics>
33
+ header: Header<TGenerics>
34
+ column: Column<TGenerics>
35
+ }
36
+ >
37
+ cell?: Renderable<
38
+ TGenerics,
39
+ {
40
+ instance: TableInstance<TGenerics>
41
+ row: Row<TGenerics>
42
+ column: Column<TGenerics>
43
+ cell: Cell<TGenerics>
44
+ getValue: () => TGenerics['Value']
45
+ }
46
+ >
47
+ meta?: TGenerics['ColumnMeta']
48
+ }
49
+
50
+ export type CoreColumn<TGenerics extends TableGenerics> = {
51
+ id: string
52
+ depth: number
53
+ accessorFn?: AccessorFn<TGenerics['Row']>
54
+ columnDef: ColumnDef<TGenerics>
55
+ columnDefType: CoreColumnDefType
56
+ columns: Column<TGenerics>[]
57
+ parent?: Column<TGenerics>
58
+ getFlatColumns: () => Column<TGenerics>[]
59
+ getLeafColumns: () => Column<TGenerics>[]
60
+ }
61
+
62
+ export function createColumn<TGenerics extends TableGenerics>(
63
+ instance: TableInstance<TGenerics>,
64
+ columnDef: ColumnDef<TGenerics> & { columnDefType?: CoreColumnDefType },
65
+ depth: number,
66
+ parent?: Column<TGenerics>
67
+ ) {
68
+ const defaultColumn = instance._getDefaultColumnDef()
69
+
70
+ columnDef = {
71
+ ...defaultColumn,
72
+ ...columnDef,
73
+ }
74
+
75
+ let id =
76
+ columnDef.id ??
77
+ columnDef.accessorKey ??
78
+ (typeof columnDef.header === 'string' ? columnDef.header : undefined)
79
+
80
+ let accessorFn: AccessorFn<TGenerics['Row']> | undefined
81
+
82
+ if (columnDef.accessorFn) {
83
+ accessorFn = columnDef.accessorFn
84
+ } else if (columnDef.accessorKey) {
85
+ accessorFn = (originalRow?: TGenerics['Row']) =>
86
+ (originalRow as any)[columnDef.accessorKey]
87
+ }
88
+
89
+ if (!id) {
90
+ if (process.env.NODE_ENV !== 'production') {
91
+ throw new Error(
92
+ columnDef.accessorFn
93
+ ? `Columns require an id when using an accessorFn`
94
+ : `Columns require an id when using a non-string header`
95
+ )
96
+ }
97
+ throw new Error()
98
+ }
99
+
100
+ let column: CoreColumn<TGenerics> = {
101
+ id: `${id}`,
102
+ accessorFn,
103
+ parent: parent as any,
104
+ depth,
105
+ columnDef,
106
+ columnDefType: columnDef.columnDefType as CoreColumnDefType,
107
+ columns: [],
108
+ getFlatColumns: memo(
109
+ () => [true],
110
+ () => {
111
+ return [
112
+ column as Column<TGenerics>,
113
+ ...column.columns?.flatMap(d => d.getFlatColumns()),
114
+ ]
115
+ },
116
+ {
117
+ key: process.env.NODE_ENV === 'production' && 'column.getFlatColumns',
118
+ debug: () => instance.options.debugAll ?? instance.options.debugColumns,
119
+ }
120
+ ),
121
+ getLeafColumns: memo(
122
+ () => [instance._getOrderColumnsFn()],
123
+ orderColumns => {
124
+ if (column.columns?.length) {
125
+ let leafColumns = column.columns.flatMap(column =>
126
+ column.getLeafColumns()
127
+ )
128
+
129
+ return orderColumns(leafColumns)
130
+ }
131
+
132
+ return [column as Column<TGenerics>]
133
+ },
134
+ {
135
+ key: process.env.NODE_ENV === 'production' && 'column.getLeafColumns',
136
+ debug: () => instance.options.debugAll ?? instance.options.debugColumns,
137
+ }
138
+ ),
139
+ }
140
+
141
+ column = instance._features.reduce((obj, feature) => {
142
+ return Object.assign(obj, feature.createColumn?.(column, instance))
143
+ }, column)
144
+
145
+ // Yes, we have to convert instance to uknown, because we know more than the compiler here.
146
+ return column as Column<TGenerics>
147
+ }