Skip to content

Commit 9330b1d

Browse files
committed
re-arrange where plugins are added
1 parent 5d0987d commit 9330b1d

File tree

16 files changed

+177
-429
lines changed

16 files changed

+177
-429
lines changed

packages/angular-table/src/constructTableHelper.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import type {
88
} from '@tanstack/table-core'
99
import type { Signal } from '@angular/core'
1010

11+
// NOTE: This is a custom fork of the constructTableHelper function from the core package
12+
// It is used to create a table helper that can be used to create tables in Angular
13+
// It is a fork because the core package does not support Angular's reactive system
14+
// So we need to create a custom function to create a table helper that can be used in Angular
15+
1116
/**
1217
* Options for creating a table helper to share common options across multiple tables
1318
* coreColumnsFeature, data, and state are excluded from this type and reserved for only the `useTable`/`createTable` functions

packages/angular-table/src/reactivity.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
import { computed, signal } from '@angular/core'
22
import { toComputed } from './proxy'
33
import type { Signal } from '@angular/core'
4-
import type { Table, TableFeature } from '@tanstack/table-core'
4+
import type {
5+
RowData,
6+
Table,
7+
TableFeature,
8+
TableFeatures,
9+
} from '@tanstack/table-core'
510

6-
// TODO: remove this once we have a better way to define plugins
711
declare module '@tanstack/table-core' {
8-
interface TableOptions_Plugins {
12+
interface TableOptions_Plugins<
13+
TFeatures extends TableFeatures,
14+
TData extends RowData,
15+
> {
916
enableExperimentalReactivity?: boolean
1017
}
1118

12-
interface Table_Plugins {
13-
_rootNotifier?: Signal<Table<any, any>>
14-
_setRootNotifier?: (signal: Signal<Table<any, any>>) => void
19+
interface Table_Plugins<
20+
TFeatures extends TableFeatures,
21+
TData extends RowData,
22+
> {
23+
_rootNotifier?: Signal<Table<TFeatures, TData>>
24+
_setRootNotifier?: (signal: Signal<Table<TFeatures, TData>>) => void
1525
}
1626
}
1727

packages/react-table/src/useTable.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import type {
99
Table,
1010
TableFeatures,
1111
TableOptions,
12-
TableOptions_Internal,
1312
TableState,
1413
} from '@tanstack/table-core'
1514

@@ -35,9 +34,7 @@ function useTableRef<TFeatures extends TableFeatures, TData extends RowData>(
3534
export function useTable<
3635
TFeatures extends TableFeatures,
3736
TData extends RowData,
38-
>(
39-
tableOptions: TableOptions_Internal<TFeatures, Array<TData>>,
40-
): Table<TFeatures, TData> {
37+
>(tableOptions: TableOptions<TFeatures, TData>): Table<TFeatures, TData> {
4138
const _features = { ...coreFeatures, ...tableOptions._features }
4239

4340
const [state, setState] = useState<TableState<TFeatures>>(() =>

packages/table-core/src/features/column-filtering/columnFilteringFeature.utils.ts

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import { functionalUpdate, isDev, isFunction } from '../../utils'
22
import type { CellData, RowData, Updater } from '../../types/type-utils'
33
import type { TableFeatures } from '../../types/TableFeatures'
44
import type { Table_Internal } from '../../types/Table'
5-
import type { Column } from '../../types/Column'
5+
import type { Column_Internal } from '../../types/Column'
66
import type {
7-
ColumnDef_ColumnFiltering,
87
ColumnFiltersState,
98
FilterFn,
109
} from './columnFilteringFeature.types'
@@ -17,7 +16,7 @@ export function column_getAutoFilterFn<
1716
TFeatures extends TableFeatures,
1817
TData extends RowData,
1918
TValue extends CellData = CellData,
20-
>(column: Column<TFeatures, TData, TValue>) {
19+
>(column: Column_Internal<TFeatures, TData, TValue>) {
2120
const filterFns = column._table._rowModelFns.filterFns as
2221
| Record<string, FilterFn<TFeatures, TData>>
2322
| undefined
@@ -54,9 +53,7 @@ export function column_getFilterFn<
5453
TData extends RowData,
5554
TValue extends CellData = CellData,
5655
>(
57-
column: Column<TFeatures, TData, TValue> & {
58-
columnDef: ColumnDef_ColumnFiltering<TFeatures, TData>
59-
},
56+
column: Column_Internal<TFeatures, TData, TValue>,
6057
): FilterFn<TFeatures, TData> | undefined {
6158
let filterFn = null
6259
const filterFns = column._table._rowModelFns.filterFns as
@@ -81,11 +78,7 @@ export function column_getCanFilter<
8178
TFeatures extends TableFeatures,
8279
TData extends RowData,
8380
TValue extends CellData = CellData,
84-
>(
85-
column: Column<TFeatures, TData, TValue> & {
86-
columnDef: ColumnDef_ColumnFiltering<TFeatures, TData>
87-
},
88-
) {
81+
>(column: Column_Internal<TFeatures, TData, TValue>) {
8982
return (
9083
(column.columnDef.enableColumnFilter ?? true) &&
9184
(column._table.options.enableColumnFilters ?? true) &&
@@ -98,23 +91,15 @@ export function column_getIsFiltered<
9891
TFeatures extends TableFeatures,
9992
TData extends RowData,
10093
TValue extends CellData = CellData,
101-
>(
102-
column: Column<TFeatures, TData, TValue> & {
103-
columnDef: ColumnDef_ColumnFiltering<TFeatures, TData>
104-
},
105-
) {
94+
>(column: Column_Internal<TFeatures, TData, TValue>) {
10695
return column_getFilterIndex(column) > -1
10796
}
10897

10998
export function column_getFilterValue<
11099
TFeatures extends TableFeatures,
111100
TData extends RowData,
112101
TValue extends CellData = CellData,
113-
>(
114-
column: Column<TFeatures, TData, TValue> & {
115-
columnDef: ColumnDef_ColumnFiltering<TFeatures, TData>
116-
},
117-
) {
102+
>(column: Column_Internal<TFeatures, TData, TValue>) {
118103
return column._table.options.state?.columnFilters?.find(
119104
(d) => d.id === column.id,
120105
)?.value
@@ -124,11 +109,7 @@ export function column_getFilterIndex<
124109
TFeatures extends TableFeatures,
125110
TData extends RowData,
126111
TValue extends CellData = CellData,
127-
>(
128-
column: Column<TFeatures, TData, TValue> & {
129-
columnDef: ColumnDef_ColumnFiltering<TFeatures, TData>
130-
},
131-
): number {
112+
>(column: Column_Internal<TFeatures, TData, TValue>): number {
132113
return (
133114
column._table.options.state?.columnFilters?.findIndex(
134115
(d) => d.id === column.id,
@@ -140,12 +121,7 @@ export function column_setFilterValue<
140121
TFeatures extends TableFeatures,
141122
TData extends RowData,
142123
TValue extends CellData = CellData,
143-
>(
144-
column: Column<TFeatures, TData, TValue> & {
145-
columnDef: ColumnDef_ColumnFiltering<TFeatures, TData>
146-
},
147-
value: any,
148-
) {
124+
>(column: Column_Internal<TFeatures, TData, TValue>, value: any) {
149125
table_setColumnFilters(column._table, (old) => {
150126
const filterFn = column_getFilterFn(column)
151127
const previousFilter = old.find((d) => d.id === column.id)
@@ -223,11 +199,14 @@ export function shouldAutoRemoveFilter<
223199
>(
224200
filterFn?: FilterFn<TFeatures, TData>,
225201
value?: any,
226-
column?: Column<TFeatures, TData, TValue>,
202+
column?: Column_Internal<TFeatures, TData, TValue>,
227203
) {
228204
return (
229205
(filterFn && filterFn.autoRemove
230-
? filterFn.autoRemove(value, column as Column<TFeatures, TData, unknown>)
206+
? filterFn.autoRemove(
207+
value,
208+
column as Column_Internal<TFeatures, TData, unknown>,
209+
)
231210
: false) ||
232211
typeof value === 'undefined' ||
233212
(typeof value === 'string' && !value)

packages/table-core/src/types/Cell.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,26 @@ import type { CellData, RowData } from './type-utils'
22
import type { ExtractFeatureTypes, TableFeatures } from './TableFeatures'
33
import type { Cell_Cell } from '../core/cells/coreCellsFeature.types'
44

5-
export interface Cell_Plugins {}
5+
/**
6+
* Use this interface as a target for declaration merging to add your own plugin properties.
7+
* Note: This will affect the types of all tables in your project.
8+
*/
9+
export interface Cell_Plugins<
10+
TFeatures extends TableFeatures,
11+
TData extends RowData,
12+
TValue extends CellData = CellData,
13+
> {}
614

715
export interface Cell_Core<
816
TFeatures extends TableFeatures,
917
TData extends RowData,
1018
TValue extends CellData = CellData,
11-
> extends Cell_Cell<TFeatures, TData, TValue>,
12-
Cell_Plugins {}
13-
14-
// export type Cell<
15-
// TFeatures extends TableFeatures,
16-
// TData extends RowData,
17-
// TValue extends CellData = CellData,
18-
// > = Cell_Cell<TFeatures, TData, TValue> &
19-
// UnionToIntersection<
20-
// 'columnGroupingFeature' extends keyof TFeatures
21-
// ? Cell_ColumnGrouping
22-
// : never
23-
// >
19+
> extends Cell_Cell<TFeatures, TData, TValue> {}
2420

2521
export type Cell<
2622
TFeatures extends TableFeatures,
2723
TData extends RowData,
2824
TValue extends CellData = CellData,
29-
> = Cell_Core<TFeatures, TData, TValue> & ExtractFeatureTypes<TFeatures, 'Cell'>
25+
> = Cell_Core<TFeatures, TData, TValue> &
26+
ExtractFeatureTypes<TFeatures, 'Cell'> &
27+
Cell_Plugins<TFeatures, TData, TValue>

packages/table-core/src/types/Column.ts

Lines changed: 12 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,29 @@ import type { ExtractFeatureTypes, TableFeatures } from './TableFeatures'
33
import type { RowData } from './type-utils'
44
import type { ColumnDefBase_All } from './ColumnDef'
55

6-
export interface Column_Plugins {}
6+
/**
7+
* Use this interface as a target for declaration merging to add your own plugin properties.
8+
* Note: This will affect the types of all tables in your project.
9+
*/
10+
export interface Column_Plugins<
11+
TFeatures extends TableFeatures,
12+
TData extends RowData,
13+
TValue = unknown,
14+
> {}
715

816
export interface Column_Core<
917
TFeatures extends TableFeatures,
1018
TData extends RowData,
1119
TValue = unknown,
12-
> extends Column_Column<TFeatures, TData, TValue>,
13-
Column_Plugins {}
14-
15-
// export type Column<
16-
// TFeatures extends TableFeatures,
17-
// TData extends RowData,
18-
// TValue = unknown,
19-
// > = Column_Core<TFeatures, TData, TValue> &
20-
// UnionToIntersection<
21-
// | ('columnFacetingFeature' extends keyof TFeatures
22-
// ? Column_ColumnFaceting<TFeatures, TData>
23-
// : never)
24-
// | ('columnFilteringFeature' extends keyof TFeatures
25-
// ? Column_ColumnFiltering<TFeatures, TData>
26-
// : never)
27-
// | ('columnGroupingFeature' extends keyof TFeatures
28-
// ? Column_ColumnGrouping<TFeatures, TData>
29-
// : never)
30-
// | ('columnOrderingFeature' extends keyof TFeatures
31-
// ? Column_ColumnOrdering
32-
// : never)
33-
// | ('columnPinningFeature' extends keyof TFeatures
34-
// ? Column_ColumnPinning
35-
// : never)
36-
// | ('columnResizingFeature' extends keyof TFeatures
37-
// ? Column_ColumnResizing
38-
// : never)
39-
// | ('columnSizingFeature' extends keyof TFeatures
40-
// ? Column_ColumnSizing
41-
// : never)
42-
// | ('columnVisibilityFeature' extends keyof TFeatures
43-
// ? Column_ColumnVisibility
44-
// : never)
45-
// | ('globalFilteringFeature' extends keyof TFeatures
46-
// ? Column_GlobalFiltering
47-
// : never)
48-
// | ('rowSortingFeature' extends keyof TFeatures
49-
// ? Column_RowSorting<TFeatures, TData>
50-
// : never)
51-
// >
20+
> extends Column_Column<TFeatures, TData, TValue> {}
5221

5322
export type Column<
5423
TFeatures extends TableFeatures,
5524
TData extends RowData,
5625
TValue = unknown,
5726
> = Column_Core<TFeatures, TData, TValue> &
58-
ExtractFeatureTypes<TFeatures, 'Column'>
27+
ExtractFeatureTypes<TFeatures, 'Column'> &
28+
Column_Plugins<TFeatures, TData, TValue>
5929

6030
export type Column_Internal<
6131
TFeatures extends TableFeatures,

packages/table-core/src/types/ColumnDef.ts

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@ import type { ColumnDef_ColumnVisibility } from '../features/column-visibility/c
1111
import type { ColumnDef_GlobalFiltering } from '../features/global-filtering/globalFilteringFeature.types'
1212
import type { ColumnDef_RowSorting } from '../features/row-sorting/rowSortingFeature.types'
1313

14-
export interface ColumnDef_Plugins {}
14+
/**
15+
* Use this interface as a target for declaration merging to add your own plugin properties.
16+
* Note: This will affect the types of all tables in your project.
17+
*/
18+
export interface ColumnDef_Plugins<
19+
TFeatures extends TableFeatures,
20+
TData extends RowData,
21+
TValue extends CellData = CellData,
22+
> {}
1523

1624
export interface ColumnMeta<
1725
TFeatures extends TableFeatures,
@@ -57,51 +65,20 @@ interface ColumnDefBase_Core<
5765
TFeatures extends TableFeatures,
5866
TData extends RowData,
5967
TValue extends CellData = CellData,
60-
> extends ColumnDef_Plugins {
68+
> {
6169
getUniqueValues?: AccessorFn<TData, Array<unknown>>
6270
footer?: ColumnDefTemplate<HeaderContext<TFeatures, TData, TValue>>
6371
cell?: ColumnDefTemplate<CellContext<TFeatures, TData, TValue>>
6472
meta?: ColumnMeta<TFeatures, TData, TValue>
6573
}
6674

67-
// export type ColumnDefBase<
68-
// TFeatures extends TableFeatures,
69-
// TData extends RowData,
70-
// TValue extends CellData = CellData,
71-
// > = ColumnDefBase_Core<TFeatures, TData, TValue> &
72-
// UnionToIntersection<
73-
// | ('columnVisibilityFeature' extends keyof TFeatures
74-
// ? ColumnDef_ColumnVisibility
75-
// : never)
76-
// | ('columnPinningFeature' extends keyof TFeatures
77-
// ? ColumnDef_ColumnPinning
78-
// : never)
79-
// | ('columnFilteringFeature' extends keyof TFeatures
80-
// ? ColumnDef_ColumnFiltering<TFeatures, TData>
81-
// : never)
82-
// | ('globalFilteringFeature' extends keyof TFeatures
83-
// ? ColumnDef_GlobalFiltering
84-
// : never)
85-
// | ('rowSortingFeature' extends keyof TFeatures
86-
// ? ColumnDef_RowSorting<TFeatures, TData>
87-
// : never)
88-
// | ('columnGroupingFeature' extends keyof TFeatures
89-
// ? ColumnDef_ColumnGrouping<TFeatures, TData, TValue>
90-
// : never)
91-
// | ('columnSizingFeature' extends keyof TFeatures
92-
// ? ColumnDef_ColumnSizing
93-
// : never)
94-
// | ('columnResizingFeature' extends keyof TFeatures
95-
// ? ColumnDef_ColumnResizing
96-
// : never)
97-
// >
98-
9975
export type ColumnDefBase<
10076
TFeatures extends TableFeatures,
10177
TData extends RowData,
10278
TValue extends CellData = CellData,
10379
> = ColumnDefBase_Core<TFeatures, TData, TValue> &
104-
ExtractFeatureTypes<TFeatures, 'ColumnDef'>
80+
ExtractFeatureTypes<TFeatures, 'ColumnDef'> &
81+
ColumnDef_Plugins<TFeatures, TData, TValue>
10582

10683
export type ColumnDefBase_All<
10784
TFeatures extends TableFeatures,

0 commit comments

Comments
 (0)