@tanstack/table-core 8.0.11 → 8.0.14
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.
- package/build/cjs/core/cell.js +13 -13
- package/build/cjs/core/cell.js.map +1 -1
- package/build/cjs/core/column.js +20 -21
- package/build/cjs/core/column.js.map +1 -1
- package/build/cjs/core/headers.js +63 -68
- package/build/cjs/core/headers.js.map +1 -1
- package/build/cjs/core/row.js +16 -11
- package/build/cjs/core/row.js.map +1 -1
- package/build/cjs/core/{instance.js → table.js} +46 -57
- package/build/cjs/core/table.js.map +1 -0
- package/build/cjs/features/ColumnSizing.js +36 -36
- package/build/cjs/features/ColumnSizing.js.map +1 -1
- package/build/cjs/features/Expanding.js +34 -34
- package/build/cjs/features/Expanding.js.map +1 -1
- package/build/cjs/features/Filters.js +46 -52
- package/build/cjs/features/Filters.js.map +1 -1
- package/build/cjs/features/Grouping.js +24 -49
- package/build/cjs/features/Grouping.js.map +1 -1
- package/build/cjs/features/Ordering.js +8 -8
- package/build/cjs/features/Ordering.js.map +1 -1
- package/build/cjs/features/Pagination.js +37 -37
- package/build/cjs/features/Pagination.js.map +1 -1
- package/build/cjs/features/Pinning.js +33 -33
- package/build/cjs/features/Pinning.js.map +1 -1
- package/build/cjs/features/RowSelection.js +67 -67
- package/build/cjs/features/RowSelection.js.map +1 -1
- package/build/cjs/features/Sorting.js +36 -40
- package/build/cjs/features/Sorting.js.map +1 -1
- package/build/cjs/features/Visibility.js +30 -30
- package/build/cjs/features/Visibility.js.map +1 -1
- package/build/cjs/index.js +2 -4
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/utils/filterRowsUtils.js +8 -8
- package/build/cjs/utils/filterRowsUtils.js.map +1 -1
- package/build/cjs/utils/getCoreRowModel.js +8 -8
- package/build/cjs/utils/getCoreRowModel.js.map +1 -1
- package/build/cjs/utils/getExpandedRowModel.js +4 -4
- package/build/cjs/utils/getExpandedRowModel.js.map +1 -1
- package/build/cjs/utils/getFacetedMinMaxValues.js +3 -3
- package/build/cjs/utils/getFacetedMinMaxValues.js.map +1 -1
- package/build/cjs/utils/getFacetedRowModel.js +4 -4
- package/build/cjs/utils/getFacetedRowModel.js.map +1 -1
- package/build/cjs/utils/getFacetedUniqueValues.js +3 -3
- package/build/cjs/utils/getFacetedUniqueValues.js.map +1 -1
- package/build/cjs/utils/getFilteredRowModel.js +8 -8
- package/build/cjs/utils/getFilteredRowModel.js.map +1 -1
- package/build/cjs/utils/getGroupedRowModel.js +9 -9
- package/build/cjs/utils/getGroupedRowModel.js.map +1 -1
- package/build/cjs/utils/getPaginationRowModel.js +4 -4
- package/build/cjs/utils/getPaginationRowModel.js.map +1 -1
- package/build/cjs/utils/getSortedRowModel.js +7 -7
- package/build/cjs/utils/getSortedRowModel.js.map +1 -1
- package/build/cjs/utils.js +2 -2
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +567 -670
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +1092 -0
- package/build/types/index.d.ts +759 -0
- package/build/umd/index.development.js +567 -671
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/core/cell.ts +34 -28
- package/src/core/column.ts +83 -72
- package/src/core/headers.ts +118 -149
- package/src/core/row.ts +31 -25
- package/src/core/{instance.ts → table.ts} +85 -116
- package/src/features/ColumnSizing.ts +45 -47
- package/src/features/Expanding.ts +53 -59
- package/src/features/Filters.ts +112 -132
- package/src/features/Grouping.ts +63 -112
- package/src/features/Ordering.ts +19 -21
- package/src/features/Pagination.ts +54 -55
- package/src/features/Pinning.ts +49 -61
- package/src/features/RowSelection.ts +97 -108
- package/src/features/Sorting.ts +57 -72
- package/src/features/Visibility.ts +48 -48
- package/src/index.ts +1 -2
- package/src/types.ts +64 -69
- package/src/utils/filterRowsUtils.ts +33 -28
- package/src/utils/getCoreRowModel.ts +22 -22
- package/src/utils/getExpandedRowModel.ts +15 -15
- package/src/utils/getFacetedMinMaxValues.ts +6 -6
- package/src/utils/getFacetedRowModel.ts +12 -12
- package/src/utils/getFacetedUniqueValues.ts +6 -6
- package/src/utils/getFilteredRowModel.ts +17 -17
- package/src/utils/getGroupedRowModel.ts +18 -21
- package/src/utils/getPaginationRowModel.ts +10 -13
- package/src/utils/getSortedRowModel.ts +14 -14
- package/src/utils.ts +8 -2
- package/build/cjs/core/instance.js.map +0 -1
- package/build/cjs/createTable.js +0 -72
- package/build/cjs/createTable.js.map +0 -1
- package/src/createTable.ts +0 -188
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/table-core",
|
|
3
3
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "8.0.
|
|
4
|
+
"version": "8.0.14",
|
|
5
5
|
"description": "Headless UI for building powerful tables & datagrids for TS/JS.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/tanstack/table#readme",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"node": ">=12"
|
|
34
34
|
},
|
|
35
35
|
"files": [
|
|
36
|
-
"build",
|
|
36
|
+
"build/**",
|
|
37
37
|
"src"
|
|
38
38
|
]
|
|
39
39
|
}
|
package/src/core/cell.ts
CHANGED
|
@@ -1,51 +1,57 @@
|
|
|
1
|
-
import { Cell, Column, Row,
|
|
1
|
+
import { RowData, Cell, Column, Row, Table } from '../types'
|
|
2
2
|
|
|
3
|
-
export type CoreCell<
|
|
3
|
+
export type CoreCell<TData extends RowData> = {
|
|
4
4
|
id: string
|
|
5
|
-
getValue: () =>
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
getValue: () => any
|
|
6
|
+
renderValue: () => unknown
|
|
7
|
+
row: Row<TData>
|
|
8
|
+
column: Column<TData>
|
|
9
|
+
getContext: () => {
|
|
10
|
+
table: Table<TData>
|
|
11
|
+
column: Column<TData>
|
|
12
|
+
row: Row<TData>
|
|
13
|
+
cell: Cell<TData>
|
|
14
|
+
getValue: () => any
|
|
15
|
+
renderValue: () => any
|
|
16
|
+
}
|
|
9
17
|
}
|
|
10
18
|
|
|
11
|
-
export function createCell<
|
|
12
|
-
|
|
13
|
-
row: Row<
|
|
14
|
-
column: Column<
|
|
19
|
+
export function createCell<TData extends RowData>(
|
|
20
|
+
table: Table<TData>,
|
|
21
|
+
row: Row<TData>,
|
|
22
|
+
column: Column<TData>,
|
|
15
23
|
columnId: string
|
|
16
24
|
) {
|
|
17
25
|
const getRenderValue = () =>
|
|
18
|
-
cell.getValue() ??
|
|
26
|
+
cell.getValue() ?? table.options.renderFallbackValue
|
|
19
27
|
|
|
20
|
-
const cell: CoreCell<
|
|
28
|
+
const cell: CoreCell<TData> = {
|
|
21
29
|
id: `${row.id}_${column.id}`,
|
|
22
30
|
row,
|
|
23
31
|
column,
|
|
24
32
|
getValue: () => row.getValue(columnId),
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
: null
|
|
35
|
-
},
|
|
33
|
+
renderValue: getRenderValue,
|
|
34
|
+
getContext: () => ({
|
|
35
|
+
table,
|
|
36
|
+
column,
|
|
37
|
+
row,
|
|
38
|
+
cell: cell as Cell<TData>,
|
|
39
|
+
getValue: cell.getValue,
|
|
40
|
+
renderValue: cell.renderValue,
|
|
41
|
+
}),
|
|
36
42
|
}
|
|
37
43
|
|
|
38
|
-
|
|
44
|
+
table._features.forEach(feature => {
|
|
39
45
|
Object.assign(
|
|
40
46
|
cell,
|
|
41
47
|
feature.createCell?.(
|
|
42
|
-
cell as Cell<
|
|
48
|
+
cell as Cell<TData>,
|
|
43
49
|
column,
|
|
44
|
-
row as Row<
|
|
45
|
-
|
|
50
|
+
row as Row<TData>,
|
|
51
|
+
table
|
|
46
52
|
)
|
|
47
53
|
)
|
|
48
54
|
}, {})
|
|
49
55
|
|
|
50
|
-
return cell as Cell<
|
|
56
|
+
return cell as Cell<TData>
|
|
51
57
|
}
|
package/src/core/column.ts
CHANGED
|
@@ -3,93 +3,105 @@ import {
|
|
|
3
3
|
Column,
|
|
4
4
|
Header,
|
|
5
5
|
TableGenerics,
|
|
6
|
-
|
|
6
|
+
Table,
|
|
7
7
|
Row,
|
|
8
8
|
AccessorFn,
|
|
9
9
|
ColumnDef,
|
|
10
|
-
|
|
10
|
+
ColumnDefTemplate,
|
|
11
|
+
RowData,
|
|
11
12
|
} from '../types'
|
|
12
|
-
import { memo } from '../utils'
|
|
13
|
+
import { memo, UnionToIntersection } from '../utils'
|
|
14
|
+
import { CoreCell } from './cell'
|
|
15
|
+
import { CoreHeader } from './headers'
|
|
13
16
|
|
|
14
17
|
export type CoreColumnDefType = 'data' | 'display' | 'group'
|
|
15
18
|
|
|
16
|
-
|
|
19
|
+
type CoreColumnDefBase<TData extends RowData> = {
|
|
20
|
+
columns?: ColumnDef<TData>[]
|
|
21
|
+
header?: ColumnDefTemplate<ReturnType<CoreHeader<TData>['getContext']>>
|
|
22
|
+
footer?: ColumnDefTemplate<ReturnType<CoreHeader<TData>['getContext']>>
|
|
23
|
+
cell?: ColumnDefTemplate<ReturnType<CoreCell<TData>['getContext']>>
|
|
24
|
+
meta?: unknown
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type CoreColumnDefDisplay<TData extends RowData> = CoreColumnDefBase<TData> & {
|
|
17
28
|
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
29
|
}
|
|
49
30
|
|
|
50
|
-
|
|
31
|
+
type CoreColumnDefDisplayWithStringHeader<TData extends RowData> =
|
|
32
|
+
CoreColumnDefBase<TData> & {
|
|
33
|
+
header: string
|
|
34
|
+
id?: string
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
type CoreColumnDefAccessorFn<TData extends RowData> =
|
|
38
|
+
CoreColumnDefBase<TData> & {
|
|
39
|
+
accessorFn: AccessorFn<TData>
|
|
40
|
+
id: string
|
|
41
|
+
// accessorKey?: never
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
type CoreColumnDefAccessorKey<TData extends RowData> =
|
|
45
|
+
CoreColumnDefBase<TData> & {
|
|
46
|
+
accessorKey: keyof TData
|
|
47
|
+
id?: string
|
|
48
|
+
// accessorFn?: never
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type CoreColumnDef<TData extends RowData> =
|
|
52
|
+
| CoreColumnDefDisplay<TData>
|
|
53
|
+
| CoreColumnDefDisplayWithStringHeader<TData>
|
|
54
|
+
| CoreColumnDefAccessorFn<TData>
|
|
55
|
+
| CoreColumnDefAccessorKey<TData>
|
|
56
|
+
|
|
57
|
+
export type CoreColumnDefResolved<TData extends RowData> = Partial<
|
|
58
|
+
UnionToIntersection<CoreColumnDef<TData>>
|
|
59
|
+
>
|
|
60
|
+
|
|
61
|
+
export type CoreColumn<TData extends RowData> = {
|
|
51
62
|
id: string
|
|
52
63
|
depth: number
|
|
53
|
-
accessorFn?: AccessorFn<
|
|
54
|
-
columnDef: ColumnDef<
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
getLeafColumns: () => Column<TGenerics>[]
|
|
64
|
+
accessorFn?: AccessorFn<TData>
|
|
65
|
+
columnDef: ColumnDef<TData>
|
|
66
|
+
columns: Column<TData>[]
|
|
67
|
+
parent?: Column<TData>
|
|
68
|
+
getFlatColumns: () => Column<TData>[]
|
|
69
|
+
getLeafColumns: () => Column<TData>[]
|
|
60
70
|
}
|
|
61
71
|
|
|
62
|
-
export function createColumn<
|
|
63
|
-
|
|
64
|
-
columnDef: ColumnDef<
|
|
72
|
+
export function createColumn<TData extends RowData>(
|
|
73
|
+
table: Table<TData>,
|
|
74
|
+
columnDef: ColumnDef<TData>,
|
|
65
75
|
depth: number,
|
|
66
|
-
parent?: Column<
|
|
76
|
+
parent?: Column<TData>
|
|
67
77
|
) {
|
|
68
|
-
const defaultColumn =
|
|
78
|
+
const defaultColumn = table._getDefaultColumnDef()
|
|
69
79
|
|
|
70
|
-
|
|
80
|
+
const resolvedColumnDef = {
|
|
71
81
|
...defaultColumn,
|
|
72
82
|
...columnDef,
|
|
73
|
-
}
|
|
83
|
+
} as CoreColumnDefResolved<TData>
|
|
74
84
|
|
|
75
85
|
let id =
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
(typeof
|
|
86
|
+
resolvedColumnDef.id ??
|
|
87
|
+
resolvedColumnDef.accessorKey ??
|
|
88
|
+
(typeof resolvedColumnDef.header === 'string'
|
|
89
|
+
? resolvedColumnDef.header
|
|
90
|
+
: undefined)
|
|
79
91
|
|
|
80
|
-
let accessorFn: AccessorFn<
|
|
92
|
+
let accessorFn: AccessorFn<TData> | undefined
|
|
81
93
|
|
|
82
|
-
if (
|
|
83
|
-
accessorFn =
|
|
84
|
-
} else if (
|
|
85
|
-
accessorFn = (originalRow?:
|
|
86
|
-
(originalRow as any)[
|
|
94
|
+
if (resolvedColumnDef.accessorFn) {
|
|
95
|
+
accessorFn = resolvedColumnDef.accessorFn
|
|
96
|
+
} else if (resolvedColumnDef.accessorKey) {
|
|
97
|
+
accessorFn = (originalRow?: TData) =>
|
|
98
|
+
(originalRow as any)[resolvedColumnDef.accessorKey]
|
|
87
99
|
}
|
|
88
100
|
|
|
89
101
|
if (!id) {
|
|
90
102
|
if (process.env.NODE_ENV !== 'production') {
|
|
91
103
|
throw new Error(
|
|
92
|
-
|
|
104
|
+
resolvedColumnDef.accessorFn
|
|
93
105
|
? `Columns require an id when using an accessorFn`
|
|
94
106
|
: `Columns require an id when using a non-string header`
|
|
95
107
|
)
|
|
@@ -97,29 +109,28 @@ export function createColumn<TGenerics extends TableGenerics>(
|
|
|
97
109
|
throw new Error()
|
|
98
110
|
}
|
|
99
111
|
|
|
100
|
-
let column: CoreColumn<
|
|
101
|
-
id: `${id}`,
|
|
112
|
+
let column: CoreColumn<TData> = {
|
|
113
|
+
id: `${String(id)}`,
|
|
102
114
|
accessorFn,
|
|
103
115
|
parent: parent as any,
|
|
104
116
|
depth,
|
|
105
|
-
columnDef
|
|
106
|
-
columnDefType: columnDef.columnDefType as CoreColumnDefType,
|
|
117
|
+
columnDef: resolvedColumnDef as ColumnDef<TData>,
|
|
107
118
|
columns: [],
|
|
108
119
|
getFlatColumns: memo(
|
|
109
120
|
() => [true],
|
|
110
121
|
() => {
|
|
111
122
|
return [
|
|
112
|
-
column as Column<
|
|
123
|
+
column as Column<TData>,
|
|
113
124
|
...column.columns?.flatMap(d => d.getFlatColumns()),
|
|
114
125
|
]
|
|
115
126
|
},
|
|
116
127
|
{
|
|
117
128
|
key: process.env.NODE_ENV === 'production' && 'column.getFlatColumns',
|
|
118
|
-
debug: () =>
|
|
129
|
+
debug: () => table.options.debugAll ?? table.options.debugColumns,
|
|
119
130
|
}
|
|
120
131
|
),
|
|
121
132
|
getLeafColumns: memo(
|
|
122
|
-
() => [
|
|
133
|
+
() => [table._getOrderColumnsFn()],
|
|
123
134
|
orderColumns => {
|
|
124
135
|
if (column.columns?.length) {
|
|
125
136
|
let leafColumns = column.columns.flatMap(column =>
|
|
@@ -129,19 +140,19 @@ export function createColumn<TGenerics extends TableGenerics>(
|
|
|
129
140
|
return orderColumns(leafColumns)
|
|
130
141
|
}
|
|
131
142
|
|
|
132
|
-
return [column as Column<
|
|
143
|
+
return [column as Column<TData>]
|
|
133
144
|
},
|
|
134
145
|
{
|
|
135
146
|
key: process.env.NODE_ENV === 'production' && 'column.getLeafColumns',
|
|
136
|
-
debug: () =>
|
|
147
|
+
debug: () => table.options.debugAll ?? table.options.debugColumns,
|
|
137
148
|
}
|
|
138
149
|
),
|
|
139
150
|
}
|
|
140
151
|
|
|
141
|
-
column =
|
|
142
|
-
return Object.assign(obj, feature.createColumn?.(column,
|
|
152
|
+
column = table._features.reduce((obj, feature) => {
|
|
153
|
+
return Object.assign(obj, feature.createColumn?.(column, table))
|
|
143
154
|
}, column)
|
|
144
155
|
|
|
145
|
-
// Yes, we have to convert
|
|
146
|
-
return column as Column<
|
|
156
|
+
// Yes, we have to convert table to uknown, because we know more than the compiler here.
|
|
157
|
+
return column as Column<TData>
|
|
147
158
|
}
|