@tanstack/table-core 8.0.0-alpha.53 → 8.0.0-alpha.57
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.js +9 -384
- package/build/cjs/core.js.map +1 -1
- package/build/cjs/createTable.js.map +1 -1
- package/build/cjs/features/Cells.js +122 -0
- package/build/cjs/features/Cells.js.map +1 -0
- package/build/cjs/features/ColumnSizing.js +90 -37
- package/build/cjs/features/ColumnSizing.js.map +1 -1
- package/build/cjs/features/Columns.js +216 -0
- package/build/cjs/features/Columns.js.map +1 -0
- package/build/cjs/features/Expanding.js +1 -1
- package/build/cjs/features/Expanding.js.map +1 -1
- package/build/cjs/features/Filters.js +1 -1
- package/build/cjs/features/Filters.js.map +1 -1
- package/build/cjs/features/Grouping.js +1 -1
- package/build/cjs/features/Grouping.js.map +1 -1
- package/build/cjs/features/Headers.js +78 -153
- package/build/cjs/features/Headers.js.map +1 -1
- package/build/cjs/features/Ordering.js +2 -2
- package/build/cjs/features/Ordering.js.map +1 -1
- package/build/cjs/features/Pagination.js +1 -1
- package/build/cjs/features/Pagination.js.map +1 -1
- package/build/cjs/features/Pinning.js +172 -2
- package/build/cjs/features/Pinning.js.map +1 -1
- package/build/cjs/features/RowSelection.js +1 -1
- package/build/cjs/features/RowSelection.js.map +1 -1
- package/build/cjs/features/Rows.js +99 -0
- package/build/cjs/features/Rows.js.map +1 -0
- package/build/cjs/features/Sorting.js +1 -1
- package/build/cjs/features/Sorting.js.map +1 -1
- package/build/cjs/features/Visibility.js +51 -17
- package/build/cjs/features/Visibility.js.map +1 -1
- package/build/cjs/filterFns.js.map +1 -1
- package/build/cjs/sortingFns.js.map +1 -1
- package/build/cjs/utils/filterRowsUtils.js.map +1 -1
- package/build/cjs/utils/getColumnFilteredRowModelSync.js.map +1 -1
- package/build/cjs/utils/getCoreRowModelAsync.js.map +1 -1
- package/build/cjs/utils/getCoreRowModelSync.js.map +1 -1
- package/build/cjs/utils/getExpandedRowModel.js.map +1 -1
- package/build/cjs/utils/getGlobalFilteredRowModelSync.js.map +1 -1
- package/build/cjs/utils/getGroupedRowModel.js.map +1 -1
- package/build/cjs/utils/getPaginationRowModel.js.map +1 -1
- package/build/cjs/utils/getSortedRowModelSync.js.map +1 -1
- package/build/cjs/utils.js +2 -2
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +879 -693
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +420 -318
- package/build/types/core.d.ts +5 -82
- package/build/types/createTable.d.ts +4 -4
- package/build/types/features/Cells.d.ts +14 -0
- package/build/types/features/ColumnSizing.d.ts +31 -23
- package/build/types/features/Columns.d.ts +54 -0
- package/build/types/features/Expanding.d.ts +6 -6
- package/build/types/features/Filters.d.ts +14 -14
- package/build/types/features/Grouping.d.ts +16 -16
- package/build/types/features/Headers.d.ts +5 -13
- package/build/types/features/Ordering.d.ts +5 -5
- package/build/types/features/Pagination.d.ts +5 -5
- package/build/types/features/Pinning.d.ts +21 -7
- package/build/types/features/RowSelection.d.ts +8 -8
- package/build/types/features/Rows.d.ts +29 -0
- package/build/types/features/Sorting.d.ts +12 -12
- package/build/types/features/Visibility.d.ts +11 -6
- package/build/types/filterFns.d.ts +10 -10
- package/build/types/sortingFns.d.ts +7 -7
- package/build/types/types.d.ts +37 -33
- package/build/types/utils/filterRowsUtils.d.ts +3 -3
- package/build/types/utils/getColumnFilteredRowModelAsync.d.ts +2 -2
- package/build/types/utils/getColumnFilteredRowModelSync.d.ts +2 -2
- package/build/types/utils/getCoreRowModelAsync.d.ts +2 -2
- package/build/types/utils/getCoreRowModelSync.d.ts +2 -2
- package/build/types/utils/getExpandedRowModel.d.ts +3 -3
- package/build/types/utils/getGlobalFilteredRowModelAsync.d.ts +2 -2
- package/build/types/utils/getGlobalFilteredRowModelSync.d.ts +2 -2
- package/build/types/utils/getGroupedRowModel.d.ts +2 -2
- package/build/types/utils/getPaginationRowModel.d.ts +2 -2
- package/build/types/utils/getSortedRowModelAsync.d.ts +4 -4
- package/build/types/utils/getSortedRowModelSync.d.ts +2 -2
- package/build/types/utils.d.ts +0 -1
- package/build/umd/index.development.js +857 -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 +1 -1
- package/src/core.ts +32 -554
- package/src/createTable.ts +12 -5
- package/src/features/Cells.ts +156 -0
- package/src/features/ColumnSizing.ts +109 -58
- package/src/features/Columns.ts +290 -0
- package/src/features/Expanding.ts +6 -7
- package/src/features/Filters.ts +14 -15
- package/src/features/Grouping.ts +16 -17
- package/src/features/Headers.ts +51 -142
- package/src/features/Ordering.ts +8 -7
- package/src/features/Pagination.ts +5 -6
- package/src/features/Pinning.ts +198 -8
- package/src/features/RowSelection.ts +9 -10
- package/src/features/Rows.ts +151 -0
- package/src/features/Sorting.ts +12 -13
- package/src/features/Visibility.ts +73 -27
- package/src/filterFns.ts +10 -10
- package/src/sortingFns.ts +7 -7
- package/src/types.ts +47 -65
- package/src/utils/filterRowsUtils.ts +3 -3
- package/src/utils/getColumnFilteredRowModelAsync.ts +2 -2
- package/src/utils/getColumnFilteredRowModelSync.ts +2 -2
- package/src/utils/getCoreRowModelAsync.ts +2 -2
- package/src/utils/getCoreRowModelSync.ts +2 -2
- package/src/utils/getExpandedRowModel.ts +3 -3
- package/src/utils/getGlobalFilteredRowModelAsync.ts +2 -2
- package/src/utils/getGlobalFilteredRowModelSync.ts +2 -2
- package/src/utils/getGroupedRowModel.ts +3 -3
- package/src/utils/getPaginationRowModel.ts +2 -2
- package/src/utils/getSortedRowModelAsync.ts +4 -4
- package/src/utils/getSortedRowModelSync.ts +2 -2
- package/src/utils.ts +3 -5
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Getter,
|
|
3
3
|
OnChangeFn,
|
|
4
|
-
|
|
5
|
-
PartialGenerics,
|
|
4
|
+
TableGenerics,
|
|
6
5
|
PropGetterValue,
|
|
7
6
|
TableInstance,
|
|
8
7
|
Row,
|
|
@@ -17,7 +16,7 @@ export type RowSelectionTableState = {
|
|
|
17
16
|
rowSelection: RowSelectionState
|
|
18
17
|
}
|
|
19
18
|
|
|
20
|
-
export type RowSelectionOptions<TGenerics extends
|
|
19
|
+
export type RowSelectionOptions<TGenerics extends TableGenerics> = {
|
|
21
20
|
onRowSelectionChange?: OnChangeFn<RowSelectionState>
|
|
22
21
|
autoResetRowSelection?: boolean
|
|
23
22
|
enableRowSelection?: boolean | ((row: Row<TGenerics>) => boolean)
|
|
@@ -60,7 +59,7 @@ export type RowSelectionRow = {
|
|
|
60
59
|
) => undefined | PropGetterValue<ToggleRowSelectedProps, TGetter>
|
|
61
60
|
}
|
|
62
61
|
|
|
63
|
-
export type RowSelectionInstance<TGenerics extends
|
|
62
|
+
export type RowSelectionInstance<TGenerics extends TableGenerics> = {
|
|
64
63
|
queueResetRowSelection: () => void
|
|
65
64
|
getToggleRowSelectedProps: <TGetter extends Getter<ToggleRowSelectedProps>>(
|
|
66
65
|
rowId: string,
|
|
@@ -106,7 +105,7 @@ export const RowSelection = {
|
|
|
106
105
|
}
|
|
107
106
|
},
|
|
108
107
|
|
|
109
|
-
getDefaultOptions: <TGenerics extends
|
|
108
|
+
getDefaultOptions: <TGenerics extends TableGenerics>(
|
|
110
109
|
instance: TableInstance<TGenerics>
|
|
111
110
|
): RowSelectionOptions<TGenerics> => {
|
|
112
111
|
return {
|
|
@@ -121,7 +120,7 @@ export const RowSelection = {
|
|
|
121
120
|
}
|
|
122
121
|
},
|
|
123
122
|
|
|
124
|
-
|
|
123
|
+
createInstance: <TGenerics extends TableGenerics>(
|
|
125
124
|
instance: TableInstance<TGenerics>
|
|
126
125
|
): RowSelectionInstance<TGenerics> => {
|
|
127
126
|
let registered = false
|
|
@@ -536,7 +535,7 @@ export const RowSelection = {
|
|
|
536
535
|
}
|
|
537
536
|
},
|
|
538
537
|
|
|
539
|
-
createRow: <TGenerics extends
|
|
538
|
+
createRow: <TGenerics extends TableGenerics>(
|
|
540
539
|
row: Row<TGenerics>,
|
|
541
540
|
instance: TableInstance<TGenerics>
|
|
542
541
|
): RowSelectionRow => {
|
|
@@ -552,7 +551,7 @@ export const RowSelection = {
|
|
|
552
551
|
},
|
|
553
552
|
}
|
|
554
553
|
|
|
555
|
-
const mutateRowIsSelected = <TGenerics extends
|
|
554
|
+
const mutateRowIsSelected = <TGenerics extends TableGenerics>(
|
|
556
555
|
selectedRowIds: Record<string, boolean>,
|
|
557
556
|
id: string,
|
|
558
557
|
value: boolean,
|
|
@@ -580,7 +579,7 @@ const mutateRowIsSelected = <TGenerics extends AnyGenerics>(
|
|
|
580
579
|
}
|
|
581
580
|
}
|
|
582
581
|
|
|
583
|
-
export function selectRowsFn<TGenerics extends
|
|
582
|
+
export function selectRowsFn<TGenerics extends TableGenerics>(
|
|
584
583
|
instance: TableInstance<TGenerics>,
|
|
585
584
|
rowModel: RowModel<TGenerics>
|
|
586
585
|
): RowModel<TGenerics> {
|
|
@@ -621,7 +620,7 @@ export function selectRowsFn<TGenerics extends AnyGenerics>(
|
|
|
621
620
|
}
|
|
622
621
|
}
|
|
623
622
|
|
|
624
|
-
export function isRowSelected<TGenerics extends
|
|
623
|
+
export function isRowSelected<TGenerics extends TableGenerics>(
|
|
625
624
|
row: Row<TGenerics>,
|
|
626
625
|
selection: Record<string, boolean>,
|
|
627
626
|
instance: TableInstance<TGenerics>
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Cell,
|
|
3
|
+
TableGenerics,
|
|
4
|
+
TableInstance,
|
|
5
|
+
Row,
|
|
6
|
+
Column,
|
|
7
|
+
CoreCell,
|
|
8
|
+
Getter,
|
|
9
|
+
CellProps,
|
|
10
|
+
PropGetterValue,
|
|
11
|
+
RowProps,
|
|
12
|
+
RowModel,
|
|
13
|
+
RowValues,
|
|
14
|
+
PropGetter,
|
|
15
|
+
} from '../types'
|
|
16
|
+
import { flattenBy, memo, propGetter } from '../utils'
|
|
17
|
+
|
|
18
|
+
export type CoreRow<TGenerics extends TableGenerics> = {
|
|
19
|
+
id: string
|
|
20
|
+
index: number
|
|
21
|
+
original?: TGenerics['Row']
|
|
22
|
+
depth: number
|
|
23
|
+
values: RowValues
|
|
24
|
+
subRows: Row<TGenerics>[]
|
|
25
|
+
getLeafRows: () => Row<TGenerics>[]
|
|
26
|
+
getRowProps: PropGetter<RowProps>
|
|
27
|
+
originalSubRows?: TGenerics['Row'][]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type RowsOptions<TGenerics extends TableGenerics> = {
|
|
31
|
+
getCoreRowModel: (
|
|
32
|
+
instance: TableInstance<TGenerics>
|
|
33
|
+
) => () => RowModel<TGenerics>
|
|
34
|
+
getSubRows?: (
|
|
35
|
+
originalRow: TGenerics['Row'],
|
|
36
|
+
index: number
|
|
37
|
+
) => TGenerics['Row'][]
|
|
38
|
+
getRowId?: (
|
|
39
|
+
originalRow: TGenerics['Row'],
|
|
40
|
+
index: number,
|
|
41
|
+
parent?: Row<TGenerics>
|
|
42
|
+
) => string
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type RowsInstance<TGenerics extends TableGenerics> = {
|
|
46
|
+
getRowId: (
|
|
47
|
+
_: TGenerics['Row'],
|
|
48
|
+
index: number,
|
|
49
|
+
parent?: Row<TGenerics>
|
|
50
|
+
) => string
|
|
51
|
+
createRow: (
|
|
52
|
+
id: string,
|
|
53
|
+
original: TGenerics['Row'] | undefined,
|
|
54
|
+
rowIndex: number,
|
|
55
|
+
depth: number,
|
|
56
|
+
values: Record<string, any>
|
|
57
|
+
) => Row<TGenerics>
|
|
58
|
+
getCoreRowModel: () => RowModel<TGenerics>
|
|
59
|
+
_getCoreRowModel?: () => RowModel<TGenerics>
|
|
60
|
+
getRowModel: () => RowModel<TGenerics>
|
|
61
|
+
getRow: (id: string) => Row<TGenerics>
|
|
62
|
+
getRowProps: <TGetter extends Getter<RowProps>>(
|
|
63
|
+
rowId: string,
|
|
64
|
+
userProps?: TGetter
|
|
65
|
+
) => undefined | PropGetterValue<RowProps, TGetter>
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
//
|
|
69
|
+
|
|
70
|
+
export const Rows = {
|
|
71
|
+
// createRow: <TGenerics extends TableGenerics>(
|
|
72
|
+
// row: Row<TGenerics>,
|
|
73
|
+
// instance: TableInstance<TGenerics>
|
|
74
|
+
// ): CellsRow<TGenerics> => {
|
|
75
|
+
// return {}
|
|
76
|
+
// },
|
|
77
|
+
|
|
78
|
+
createInstance: <TGenerics extends TableGenerics>(
|
|
79
|
+
instance: TableInstance<TGenerics>
|
|
80
|
+
): RowsInstance<TGenerics> => {
|
|
81
|
+
return {
|
|
82
|
+
getRowId: (
|
|
83
|
+
row: TGenerics['Row'],
|
|
84
|
+
index: number,
|
|
85
|
+
parent?: Row<TGenerics>
|
|
86
|
+
) =>
|
|
87
|
+
instance.options.getRowId?.(row, index, parent) ??
|
|
88
|
+
`${parent ? [parent.id, index].join('.') : index}`,
|
|
89
|
+
createRow: (id, original, rowIndex, depth, values) => {
|
|
90
|
+
let row: CoreRow<TGenerics> = {
|
|
91
|
+
id,
|
|
92
|
+
index: rowIndex,
|
|
93
|
+
original,
|
|
94
|
+
depth,
|
|
95
|
+
values,
|
|
96
|
+
subRows: [],
|
|
97
|
+
getLeafRows: () => flattenBy(row.subRows, d => d.subRows),
|
|
98
|
+
getRowProps: userProps => instance.getRowProps(row.id, userProps)!,
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
for (let i = 0; i < instance._features.length; i++) {
|
|
102
|
+
const feature = instance._features[i]
|
|
103
|
+
Object.assign(row, feature.createRow?.(row, instance))
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return row as Row<TGenerics>
|
|
107
|
+
},
|
|
108
|
+
|
|
109
|
+
getCoreRowModel: () => {
|
|
110
|
+
if (!instance._getCoreRowModel) {
|
|
111
|
+
instance._getCoreRowModel = instance.options.getCoreRowModel(instance)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return instance._getCoreRowModel()
|
|
115
|
+
},
|
|
116
|
+
|
|
117
|
+
// The final calls start at the bottom of the model,
|
|
118
|
+
// expanded rows, which then work their way up
|
|
119
|
+
|
|
120
|
+
getRowModel: () => {
|
|
121
|
+
return instance.getPaginationRowModel()
|
|
122
|
+
},
|
|
123
|
+
getRow: (id: string) => {
|
|
124
|
+
const row = instance.getRowModel().rowsById[id]
|
|
125
|
+
|
|
126
|
+
if (!row) {
|
|
127
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
128
|
+
throw new Error(`getRow expected an ID, but got ${id}`)
|
|
129
|
+
}
|
|
130
|
+
throw new Error()
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return row
|
|
134
|
+
},
|
|
135
|
+
getRowProps: (rowId, userProps) => {
|
|
136
|
+
const row = instance.getRow(rowId)
|
|
137
|
+
if (!row) {
|
|
138
|
+
return
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return propGetter(
|
|
142
|
+
{
|
|
143
|
+
key: row.id,
|
|
144
|
+
role: 'row',
|
|
145
|
+
},
|
|
146
|
+
userProps
|
|
147
|
+
)
|
|
148
|
+
},
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
}
|
package/src/features/Sorting.ts
CHANGED
|
@@ -10,8 +10,7 @@ import {
|
|
|
10
10
|
Getter,
|
|
11
11
|
Header,
|
|
12
12
|
OnChangeFn,
|
|
13
|
-
|
|
14
|
-
PartialGenerics,
|
|
13
|
+
TableGenerics,
|
|
15
14
|
PropGetterValue,
|
|
16
15
|
TableInstance,
|
|
17
16
|
Row,
|
|
@@ -36,11 +35,11 @@ export type ColumnSort = {
|
|
|
36
35
|
|
|
37
36
|
export type SortingState = ColumnSort[]
|
|
38
37
|
|
|
39
|
-
export type SortingFn<TGenerics extends
|
|
38
|
+
export type SortingFn<TGenerics extends TableGenerics> = {
|
|
40
39
|
(rowA: Row<TGenerics>, rowB: Row<TGenerics>, columnId: string): number
|
|
41
40
|
}
|
|
42
41
|
|
|
43
|
-
export type CustomSortingFns<TGenerics extends
|
|
42
|
+
export type CustomSortingFns<TGenerics extends TableGenerics> = Record<
|
|
44
43
|
string,
|
|
45
44
|
SortingFn<TGenerics>
|
|
46
45
|
>
|
|
@@ -49,13 +48,13 @@ export type SortingTableState = {
|
|
|
49
48
|
sorting: SortingState
|
|
50
49
|
}
|
|
51
50
|
|
|
52
|
-
export type SortingFnOption<TGenerics extends
|
|
51
|
+
export type SortingFnOption<TGenerics extends TableGenerics> =
|
|
53
52
|
| 'auto'
|
|
54
53
|
| BuiltInSortingFn
|
|
55
54
|
| keyof TGenerics['SortingFns']
|
|
56
55
|
| SortingFn<TGenerics>
|
|
57
56
|
|
|
58
|
-
export type SortingColumnDef<TGenerics extends
|
|
57
|
+
export type SortingColumnDef<TGenerics extends TableGenerics> = {
|
|
59
58
|
sortingFn?: SortingFnOption<Overwrite<TGenerics, { Value: any }>>
|
|
60
59
|
sortDescFirst?: boolean
|
|
61
60
|
enableSorting?: boolean
|
|
@@ -65,7 +64,7 @@ export type SortingColumnDef<TGenerics extends AnyGenerics> = {
|
|
|
65
64
|
sortUndefined?: false | -1 | 1
|
|
66
65
|
}
|
|
67
66
|
|
|
68
|
-
export type SortingColumn<TGenerics extends
|
|
67
|
+
export type SortingColumn<TGenerics extends TableGenerics> = {
|
|
69
68
|
sortingFn: SortingFnOption<Overwrite<TGenerics, { Value: any }>>
|
|
70
69
|
getCanSort: () => boolean
|
|
71
70
|
getCanMultiSort: () => boolean
|
|
@@ -78,7 +77,7 @@ export type SortingColumn<TGenerics extends AnyGenerics> = {
|
|
|
78
77
|
) => undefined | PropGetterValue<ToggleSortingProps, TGetter>
|
|
79
78
|
}
|
|
80
79
|
|
|
81
|
-
export type SortingOptions<TGenerics extends
|
|
80
|
+
export type SortingOptions<TGenerics extends TableGenerics> = {
|
|
82
81
|
sortingFns?: TGenerics['SortingFns']
|
|
83
82
|
onSortingChange?: OnChangeFn<SortingState>
|
|
84
83
|
autoResetSorting?: boolean
|
|
@@ -99,7 +98,7 @@ export type ToggleSortingProps = {
|
|
|
99
98
|
onClick?: (event: unknown) => void
|
|
100
99
|
}
|
|
101
100
|
|
|
102
|
-
export type SortingInstance<TGenerics extends
|
|
101
|
+
export type SortingInstance<TGenerics extends TableGenerics> = {
|
|
103
102
|
queueResetSorting: () => void
|
|
104
103
|
getColumnAutoSortingFn: (columnId: string) => SortingFn<TGenerics> | undefined
|
|
105
104
|
getColumnAutoSortDir: (columnId: string) => SortDirection
|
|
@@ -130,7 +129,7 @@ export type SortingInstance<TGenerics extends AnyGenerics> = {
|
|
|
130
129
|
|
|
131
130
|
export const Sorting = {
|
|
132
131
|
getDefaultColumn: <
|
|
133
|
-
TGenerics extends
|
|
132
|
+
TGenerics extends TableGenerics
|
|
134
133
|
>(): SortingColumnDef<TGenerics> => {
|
|
135
134
|
return {
|
|
136
135
|
sortingFn: 'auto',
|
|
@@ -143,7 +142,7 @@ export const Sorting = {
|
|
|
143
142
|
}
|
|
144
143
|
},
|
|
145
144
|
|
|
146
|
-
getDefaultOptions: <TGenerics extends
|
|
145
|
+
getDefaultOptions: <TGenerics extends TableGenerics>(
|
|
147
146
|
instance: TableInstance<TGenerics>
|
|
148
147
|
): SortingOptions<TGenerics> => {
|
|
149
148
|
return {
|
|
@@ -155,7 +154,7 @@ export const Sorting = {
|
|
|
155
154
|
}
|
|
156
155
|
},
|
|
157
156
|
|
|
158
|
-
createColumn: <TGenerics extends
|
|
157
|
+
createColumn: <TGenerics extends TableGenerics>(
|
|
159
158
|
column: Column<TGenerics>,
|
|
160
159
|
instance: TableInstance<TGenerics>
|
|
161
160
|
): SortingColumn<TGenerics> => {
|
|
@@ -173,7 +172,7 @@ export const Sorting = {
|
|
|
173
172
|
}
|
|
174
173
|
},
|
|
175
174
|
|
|
176
|
-
|
|
175
|
+
createInstance: <TGenerics extends TableGenerics>(
|
|
177
176
|
instance: TableInstance<TGenerics>
|
|
178
177
|
): SortingInstance<TGenerics> => {
|
|
179
178
|
let registered = false
|
|
@@ -3,13 +3,13 @@ import {
|
|
|
3
3
|
Column,
|
|
4
4
|
Getter,
|
|
5
5
|
OnChangeFn,
|
|
6
|
-
|
|
7
|
-
PartialGenerics,
|
|
6
|
+
TableGenerics,
|
|
8
7
|
PropGetterValue,
|
|
9
8
|
TableInstance,
|
|
10
9
|
Updater,
|
|
10
|
+
Row,
|
|
11
11
|
} from '../types'
|
|
12
|
-
import {
|
|
12
|
+
import { makeStateUpdater, memo, propGetter } from '../utils'
|
|
13
13
|
|
|
14
14
|
export type VisibilityOptions = {
|
|
15
15
|
onColumnVisibilityChange?: OnChangeFn<VisibilityState>
|
|
@@ -26,9 +26,12 @@ export type VisibilityTableState = {
|
|
|
26
26
|
columnVisibility: VisibilityState
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
export type VisibilityInstance<TGenerics extends
|
|
29
|
+
export type VisibilityInstance<TGenerics extends TableGenerics> = {
|
|
30
30
|
getVisibleFlatColumns: () => Column<TGenerics>[]
|
|
31
31
|
getVisibleLeafColumns: () => Column<TGenerics>[]
|
|
32
|
+
getLeftVisibleLeafColumns: () => Column<TGenerics>[]
|
|
33
|
+
getRightVisibleLeafColumns: () => Column<TGenerics>[]
|
|
34
|
+
getCenterVisibleLeafColumns: () => Column<TGenerics>[]
|
|
32
35
|
setColumnVisibility: (updater: Updater<VisibilityState>) => void
|
|
33
36
|
toggleColumnVisibility: (columnId: string, value?: boolean) => void
|
|
34
37
|
toggleAllColumnsVisible: (value?: boolean) => void
|
|
@@ -52,7 +55,8 @@ export type VisibilityColumnDef = {
|
|
|
52
55
|
defaultIsVisible?: boolean
|
|
53
56
|
}
|
|
54
57
|
|
|
55
|
-
export type VisibilityRow<TGenerics extends
|
|
58
|
+
export type VisibilityRow<TGenerics extends TableGenerics> = {
|
|
59
|
+
_getAllVisibleCells: () => Cell<TGenerics>[]
|
|
56
60
|
getVisibleCells: () => Cell<TGenerics>[]
|
|
57
61
|
}
|
|
58
62
|
|
|
@@ -74,7 +78,7 @@ export const Visibility = {
|
|
|
74
78
|
}
|
|
75
79
|
},
|
|
76
80
|
|
|
77
|
-
getDefaultOptions: <TGenerics extends
|
|
81
|
+
getDefaultOptions: <TGenerics extends TableGenerics>(
|
|
78
82
|
instance: TableInstance<TGenerics>
|
|
79
83
|
): VisibilityDefaultOptions => {
|
|
80
84
|
return {
|
|
@@ -88,7 +92,7 @@ export const Visibility = {
|
|
|
88
92
|
}
|
|
89
93
|
},
|
|
90
94
|
|
|
91
|
-
createColumn: <TGenerics extends
|
|
95
|
+
createColumn: <TGenerics extends TableGenerics>(
|
|
92
96
|
column: Column<TGenerics>,
|
|
93
97
|
instance: TableInstance<TGenerics>
|
|
94
98
|
): VisibilityColumn => {
|
|
@@ -114,46 +118,88 @@ export const Visibility = {
|
|
|
114
118
|
}
|
|
115
119
|
},
|
|
116
120
|
|
|
117
|
-
|
|
121
|
+
createRow: <TGenerics extends TableGenerics>(
|
|
122
|
+
row: Row<TGenerics>,
|
|
118
123
|
instance: TableInstance<TGenerics>
|
|
119
|
-
):
|
|
124
|
+
): VisibilityRow<TGenerics> => {
|
|
120
125
|
return {
|
|
121
|
-
|
|
126
|
+
_getAllVisibleCells: memo(
|
|
122
127
|
() => [
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
.
|
|
126
|
-
.filter(d => d.getIsVisible?.())
|
|
128
|
+
row
|
|
129
|
+
.getAllCells()
|
|
130
|
+
.filter(cell => cell.column.getIsVisible())
|
|
127
131
|
.map(d => d.id)
|
|
128
132
|
.join('_'),
|
|
129
133
|
],
|
|
130
|
-
|
|
131
|
-
return
|
|
134
|
+
_ => {
|
|
135
|
+
return row.getAllCells().filter(cell => cell.column.getIsVisible())
|
|
132
136
|
},
|
|
133
137
|
{
|
|
134
|
-
key: '
|
|
135
|
-
debug: () =>
|
|
136
|
-
|
|
138
|
+
key: 'row._getAllVisibleCells',
|
|
139
|
+
debug: () => instance.options.debugAll ?? instance.options.debugRows,
|
|
140
|
+
}
|
|
141
|
+
),
|
|
142
|
+
getVisibleCells: memo(
|
|
143
|
+
() => [
|
|
144
|
+
row.getLeftVisibleCells(),
|
|
145
|
+
row.getCenterVisibleCells(),
|
|
146
|
+
row.getRightVisibleCells(),
|
|
147
|
+
],
|
|
148
|
+
(left, center, right) => [...left, ...center, ...right],
|
|
149
|
+
{
|
|
150
|
+
key: 'row.getVisibleCells',
|
|
151
|
+
debug: () => instance.options.debugAll ?? instance.options.debugRows,
|
|
137
152
|
}
|
|
138
153
|
),
|
|
154
|
+
}
|
|
155
|
+
},
|
|
139
156
|
|
|
140
|
-
|
|
157
|
+
createInstance: <TGenerics extends TableGenerics>(
|
|
158
|
+
instance: TableInstance<TGenerics>
|
|
159
|
+
): VisibilityInstance<TGenerics> => {
|
|
160
|
+
const makeVisibleColumnsMethod = (
|
|
161
|
+
key: string,
|
|
162
|
+
getColumns: () => Column<TGenerics>[]
|
|
163
|
+
): (() => Column<TGenerics>[]) => {
|
|
164
|
+
return memo(
|
|
141
165
|
() => [
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
.
|
|
145
|
-
.filter(d => d.getIsVisible?.())
|
|
166
|
+
getColumns(),
|
|
167
|
+
getColumns()
|
|
168
|
+
.filter(d => d.getIsVisible())
|
|
146
169
|
.map(d => d.id)
|
|
147
170
|
.join('_'),
|
|
148
171
|
],
|
|
149
|
-
|
|
150
|
-
return
|
|
172
|
+
columns => {
|
|
173
|
+
return columns.filter(d => d.getIsVisible?.())
|
|
151
174
|
},
|
|
152
175
|
{
|
|
153
|
-
key
|
|
176
|
+
key,
|
|
154
177
|
debug: () =>
|
|
155
178
|
instance.options.debugAll ?? instance.options.debugColumns,
|
|
156
179
|
}
|
|
180
|
+
)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return {
|
|
184
|
+
getVisibleFlatColumns: makeVisibleColumnsMethod(
|
|
185
|
+
'getVisibleFlatColumns',
|
|
186
|
+
() => instance.getAllFlatColumns()
|
|
187
|
+
),
|
|
188
|
+
getVisibleLeafColumns: makeVisibleColumnsMethod(
|
|
189
|
+
'getVisibleLeafColumns',
|
|
190
|
+
() => instance.getAllLeafColumns()
|
|
191
|
+
),
|
|
192
|
+
getLeftVisibleLeafColumns: makeVisibleColumnsMethod(
|
|
193
|
+
'getLeftVisibleLeafColumns',
|
|
194
|
+
() => instance.getLeftLeafColumns()
|
|
195
|
+
),
|
|
196
|
+
getRightVisibleLeafColumns: makeVisibleColumnsMethod(
|
|
197
|
+
'getRightVisibleLeafColumns',
|
|
198
|
+
() => instance.getRightLeafColumns()
|
|
199
|
+
),
|
|
200
|
+
getCenterVisibleLeafColumns: makeVisibleColumnsMethod(
|
|
201
|
+
'getCenterVisibleLeafColumns',
|
|
202
|
+
() => instance.getCenterLeafColumns()
|
|
157
203
|
),
|
|
158
204
|
|
|
159
205
|
setColumnVisibility: updater =>
|
package/src/filterFns.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TableGenerics, Row } from './types'
|
|
2
2
|
|
|
3
3
|
export const filterFns = {
|
|
4
4
|
includesString,
|
|
@@ -14,7 +14,7 @@ export const filterFns = {
|
|
|
14
14
|
|
|
15
15
|
export type BuiltInFilterFn = keyof typeof filterFns
|
|
16
16
|
|
|
17
|
-
function includesString<TGenerics extends
|
|
17
|
+
function includesString<TGenerics extends TableGenerics>(
|
|
18
18
|
rows: Row<TGenerics>[],
|
|
19
19
|
columnIds: string[],
|
|
20
20
|
filterValue: unknown
|
|
@@ -31,7 +31,7 @@ function includesString<TGenerics extends AnyGenerics>(
|
|
|
31
31
|
|
|
32
32
|
includesString.autoRemove = (val: any) => testFalsey(val)
|
|
33
33
|
|
|
34
|
-
function includesStringSensitive<TGenerics extends
|
|
34
|
+
function includesStringSensitive<TGenerics extends TableGenerics>(
|
|
35
35
|
rows: Row<TGenerics>[],
|
|
36
36
|
columnIds: string[],
|
|
37
37
|
filterValue: unknown
|
|
@@ -48,7 +48,7 @@ function includesStringSensitive<TGenerics extends AnyGenerics>(
|
|
|
48
48
|
|
|
49
49
|
includesStringSensitive.autoRemove = (val: any) => testFalsey(val)
|
|
50
50
|
|
|
51
|
-
function equalsString<TGenerics extends
|
|
51
|
+
function equalsString<TGenerics extends TableGenerics>(
|
|
52
52
|
rows: Row<TGenerics>[],
|
|
53
53
|
columnIds: string[],
|
|
54
54
|
filterValue: unknown
|
|
@@ -67,7 +67,7 @@ function equalsString<TGenerics extends AnyGenerics>(
|
|
|
67
67
|
|
|
68
68
|
equalsString.autoRemove = (val: any) => testFalsey(val)
|
|
69
69
|
|
|
70
|
-
function equalsStringSensitive<TGenerics extends
|
|
70
|
+
function equalsStringSensitive<TGenerics extends TableGenerics>(
|
|
71
71
|
rows: Row<TGenerics>[],
|
|
72
72
|
columnIds: string[],
|
|
73
73
|
filterValue: unknown
|
|
@@ -83,7 +83,7 @@ function equalsStringSensitive<TGenerics extends AnyGenerics>(
|
|
|
83
83
|
|
|
84
84
|
equalsStringSensitive.autoRemove = (val: any) => testFalsey(val)
|
|
85
85
|
|
|
86
|
-
function arrIncludes<TGenerics extends
|
|
86
|
+
function arrIncludes<TGenerics extends TableGenerics>(
|
|
87
87
|
rows: Row<TGenerics>[],
|
|
88
88
|
columnIds: string[],
|
|
89
89
|
filterValue: unknown
|
|
@@ -98,7 +98,7 @@ function arrIncludes<TGenerics extends AnyGenerics>(
|
|
|
98
98
|
|
|
99
99
|
arrIncludes.autoRemove = (val: any) => testFalsey(val) || !val?.length
|
|
100
100
|
|
|
101
|
-
function arrIncludesAll<TGenerics extends
|
|
101
|
+
function arrIncludesAll<TGenerics extends TableGenerics>(
|
|
102
102
|
rows: Row<TGenerics>[],
|
|
103
103
|
columnIds: string[],
|
|
104
104
|
filterValue: unknown[]
|
|
@@ -117,7 +117,7 @@ function arrIncludesAll<TGenerics extends AnyGenerics>(
|
|
|
117
117
|
|
|
118
118
|
arrIncludesAll.autoRemove = (val: any) => testFalsey(val) || !val?.length
|
|
119
119
|
|
|
120
|
-
function equals<TGenerics extends
|
|
120
|
+
function equals<TGenerics extends TableGenerics>(
|
|
121
121
|
rows: Row<TGenerics>[],
|
|
122
122
|
columnIds: string[],
|
|
123
123
|
filterValue: unknown
|
|
@@ -132,7 +132,7 @@ function equals<TGenerics extends AnyGenerics>(
|
|
|
132
132
|
|
|
133
133
|
equals.autoRemove = (val: any) => testFalsey(val)
|
|
134
134
|
|
|
135
|
-
function weakEquals<TGenerics extends
|
|
135
|
+
function weakEquals<TGenerics extends TableGenerics>(
|
|
136
136
|
rows: Row<TGenerics>[],
|
|
137
137
|
columnIds: string[],
|
|
138
138
|
filterValue: unknown
|
|
@@ -148,7 +148,7 @@ function weakEquals<TGenerics extends AnyGenerics>(
|
|
|
148
148
|
|
|
149
149
|
weakEquals.autoRemove = (val: any) => testFalsey(val)
|
|
150
150
|
|
|
151
|
-
function betweenNumberRange<TGenerics extends
|
|
151
|
+
function betweenNumberRange<TGenerics extends TableGenerics>(
|
|
152
152
|
rows: Row<TGenerics>[],
|
|
153
153
|
columnIds: string[],
|
|
154
154
|
filterValue: [unknown, unknown]
|
package/src/sortingFns.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TableGenerics, Row } from './types'
|
|
2
2
|
|
|
3
3
|
export const reSplitAlphaNumeric = /([0-9]+)/gm
|
|
4
4
|
|
|
@@ -13,7 +13,7 @@ export const sortingFns = {
|
|
|
13
13
|
|
|
14
14
|
export type BuiltInSortingFn = keyof typeof sortingFns
|
|
15
15
|
|
|
16
|
-
function alphanumeric<TGenerics extends
|
|
16
|
+
function alphanumeric<TGenerics extends TableGenerics>(
|
|
17
17
|
rowA: Row<TGenerics>,
|
|
18
18
|
rowB: Row<TGenerics>,
|
|
19
19
|
columnId: string
|
|
@@ -24,7 +24,7 @@ function alphanumeric<TGenerics extends AnyGenerics>(
|
|
|
24
24
|
)
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
function alphanumericCaseSensitive<TGenerics extends
|
|
27
|
+
function alphanumericCaseSensitive<TGenerics extends TableGenerics>(
|
|
28
28
|
rowA: Row<TGenerics>,
|
|
29
29
|
rowB: Row<TGenerics>,
|
|
30
30
|
columnId: string
|
|
@@ -84,7 +84,7 @@ function compareAlphanumeric(aStr: string, bStr: string) {
|
|
|
84
84
|
|
|
85
85
|
// The text filter is more basic (less numeric support)
|
|
86
86
|
// but is much faster
|
|
87
|
-
function text<TGenerics extends
|
|
87
|
+
function text<TGenerics extends TableGenerics>(
|
|
88
88
|
rowA: Row<TGenerics>,
|
|
89
89
|
rowB: Row<TGenerics>,
|
|
90
90
|
columnId: string
|
|
@@ -97,7 +97,7 @@ function text<TGenerics extends AnyGenerics>(
|
|
|
97
97
|
|
|
98
98
|
// The text filter is more basic (less numeric support)
|
|
99
99
|
// but is much faster
|
|
100
|
-
function textCaseSensitive<TGenerics extends
|
|
100
|
+
function textCaseSensitive<TGenerics extends TableGenerics>(
|
|
101
101
|
rowA: Row<TGenerics>,
|
|
102
102
|
rowB: Row<TGenerics>,
|
|
103
103
|
columnId: string
|
|
@@ -108,7 +108,7 @@ function textCaseSensitive<TGenerics extends AnyGenerics>(
|
|
|
108
108
|
)
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
function datetime<TGenerics extends
|
|
111
|
+
function datetime<TGenerics extends TableGenerics>(
|
|
112
112
|
rowA: Row<TGenerics>,
|
|
113
113
|
rowB: Row<TGenerics>,
|
|
114
114
|
columnId: string
|
|
@@ -119,7 +119,7 @@ function datetime<TGenerics extends AnyGenerics>(
|
|
|
119
119
|
)
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
function basic<TGenerics extends
|
|
122
|
+
function basic<TGenerics extends TableGenerics>(
|
|
123
123
|
rowA: Row<TGenerics>,
|
|
124
124
|
rowB: Row<TGenerics>,
|
|
125
125
|
columnId: string
|