@tanstack/angular-table 9.0.0-beta.3 → 9.0.0-beta.31
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/README.md +1 -0
- package/dist/README.md +1 -0
- package/dist/fesm2022/tanstack-angular-table.mjs +31 -66
- package/dist/fesm2022/tanstack-angular-table.mjs.map +1 -1
- package/dist/types/tanstack-angular-table.d.ts +9 -23
- package/package.json +8 -7
- package/skills/angular/angular-rendering-directives/SKILL.md +4 -4
- package/skills/angular/angular-rendering-directives/references/create-table-hook-registries.md +4 -4
- package/skills/angular/client-to-server/SKILL.md +22 -21
- package/skills/angular/compose-with-tanstack-query/SKILL.md +17 -13
- package/skills/angular/compose-with-tanstack-store/SKILL.md +16 -8
- package/skills/angular/compose-with-tanstack-virtual/SKILL.md +1 -2
- package/skills/angular/getting-started/SKILL.md +34 -43
- package/skills/angular/getting-started/references/feature-row-model-mapping.md +9 -6
- package/skills/angular/migrate-v8-to-v9/SKILL.md +43 -40
- package/skills/angular/migrate-v8-to-v9/references/v8-to-v9-mapping.md +21 -14
- package/skills/angular/production-readiness/SKILL.md +40 -37
- package/skills/angular/table-state/SKILL.md +19 -26
- package/skills/angular/table-state/references/external-atoms-and-app-hook.md +8 -7
- package/src/helpers/cell.ts +6 -2
- package/src/helpers/createTableHook.ts +43 -21
- package/src/helpers/header.ts +4 -2
- package/src/helpers/table.ts +4 -2
- package/src/injectTable.ts +7 -78
|
@@ -314,16 +314,16 @@ export type CreateTableHookResult<
|
|
|
314
314
|
THeaderComponents
|
|
315
315
|
>
|
|
316
316
|
injectTableContext: <TData extends RowData = RowData>() => Signal<
|
|
317
|
-
AngularTable<TFeatures, TData>
|
|
317
|
+
AngularTable<TFeatures, TData> & TTableComponents
|
|
318
318
|
>
|
|
319
319
|
injectTableHeaderContext: <
|
|
320
320
|
TValue extends CellData = CellData,
|
|
321
321
|
TRowData extends RowData = RowData,
|
|
322
|
-
>() => Signal<Header<TFeatures, TRowData, TValue
|
|
322
|
+
>() => Signal<Header<TFeatures, TRowData, TValue> & THeaderComponents>
|
|
323
323
|
injectTableCellContext: <
|
|
324
324
|
TValue extends CellData = CellData,
|
|
325
325
|
TRowData extends RowData = RowData,
|
|
326
|
-
>() => Signal<Cell<TFeatures, TRowData, TValue
|
|
326
|
+
>() => Signal<Cell<TFeatures, TRowData, TValue> & TCellComponents>
|
|
327
327
|
injectFlexRenderHeaderContext: <
|
|
328
328
|
TData extends RowData,
|
|
329
329
|
TValue extends CellData,
|
|
@@ -333,10 +333,7 @@ export type CreateTableHookResult<
|
|
|
333
333
|
TValue extends CellData,
|
|
334
334
|
>() => CellContext<TFeatures, TData, TValue>
|
|
335
335
|
injectAppTable: <TData extends RowData>(
|
|
336
|
-
tableOptions: () => Omit<
|
|
337
|
-
TableOptions<TFeatures, TData>,
|
|
338
|
-
'features' | 'rowModels'
|
|
339
|
-
>,
|
|
336
|
+
tableOptions: () => Omit<TableOptions<TFeatures, TData>, 'features'>,
|
|
340
337
|
) => AppAngularTable<
|
|
341
338
|
TFeatures,
|
|
342
339
|
TData,
|
|
@@ -358,7 +355,6 @@ export type CreateTableHookResult<
|
|
|
358
355
|
* ```ts
|
|
359
356
|
* const { injectAppTable, createAppColumnHelper } = createTableHook({
|
|
360
357
|
* features,
|
|
361
|
-
* rowModels: {},
|
|
362
358
|
* tableComponents: {},
|
|
363
359
|
* cellComponents: {},
|
|
364
360
|
* headerComponents: {},
|
|
@@ -387,23 +383,46 @@ export function createTableHook<
|
|
|
387
383
|
THeaderComponents
|
|
388
384
|
> {
|
|
389
385
|
function injectTableContext<TData extends RowData = RowData>(): Signal<
|
|
390
|
-
AngularTable<TFeatures, TData>
|
|
386
|
+
AngularTable<TFeatures, TData> & TTableComponents
|
|
391
387
|
> {
|
|
392
|
-
|
|
388
|
+
// `injectAppTable` Object.assign-es `tableComponents` onto the same table
|
|
389
|
+
// instance it returns (via `constructTableAPIs`), and that instance is what
|
|
390
|
+
// gets provided to DI, so this asserts the runtime shape.
|
|
391
|
+
return _injectTableContext<TFeatures, TData>() as unknown as Signal<
|
|
392
|
+
AngularTable<TFeatures, TData> & TTableComponents
|
|
393
|
+
>
|
|
393
394
|
}
|
|
394
395
|
|
|
395
396
|
function injectTableHeaderContext<
|
|
396
397
|
TValue extends CellData = CellData,
|
|
397
398
|
TRowData extends RowData = RowData,
|
|
398
|
-
>(): Signal<Header<TFeatures, TRowData, TValue
|
|
399
|
-
|
|
399
|
+
>(): Signal<Header<TFeatures, TRowData, TValue> & THeaderComponents> {
|
|
400
|
+
// `injectAppTable` Object.assign-es `headerComponents` onto the header
|
|
401
|
+
// prototype (via `assignHeaderPrototype`), so every header instance carries
|
|
402
|
+
// them. This asserts the runtime shape.
|
|
403
|
+
return _injectTableHeaderContext<
|
|
404
|
+
TFeatures,
|
|
405
|
+
TRowData,
|
|
406
|
+
TValue
|
|
407
|
+
>() as unknown as Signal<
|
|
408
|
+
Header<TFeatures, TRowData, TValue> & THeaderComponents
|
|
409
|
+
>
|
|
400
410
|
}
|
|
401
411
|
|
|
402
412
|
function injectTableCellContext<
|
|
403
413
|
TValue extends CellData = CellData,
|
|
404
414
|
TRowData extends RowData = RowData,
|
|
405
|
-
>(): Signal<Cell<TFeatures, TRowData, TValue
|
|
406
|
-
|
|
415
|
+
>(): Signal<Cell<TFeatures, TRowData, TValue> & TCellComponents> {
|
|
416
|
+
// `injectAppTable` Object.assign-es `cellComponents` onto the cell prototype
|
|
417
|
+
// (via `assignCellPrototype`), so every cell instance carries them. This
|
|
418
|
+
// asserts the runtime shape.
|
|
419
|
+
return _injectTableCellContext<
|
|
420
|
+
TFeatures,
|
|
421
|
+
TRowData,
|
|
422
|
+
TValue
|
|
423
|
+
>() as unknown as Signal<
|
|
424
|
+
Cell<TFeatures, TRowData, TValue> & TCellComponents
|
|
425
|
+
>
|
|
407
426
|
}
|
|
408
427
|
|
|
409
428
|
function injectFlexRenderHeaderContext<
|
|
@@ -424,10 +443,7 @@ export function createTableHook<
|
|
|
424
443
|
TData extends RowData,
|
|
425
444
|
TSelected = TableState<TFeatures>,
|
|
426
445
|
>(
|
|
427
|
-
tableOptions: () => Omit<
|
|
428
|
-
TableOptions<TFeatures, TData>,
|
|
429
|
-
'features' | 'rowModels'
|
|
430
|
-
>,
|
|
446
|
+
tableOptions: () => Omit<TableOptions<TFeatures, TData>, 'features'>,
|
|
431
447
|
): AppAngularTable<
|
|
432
448
|
TFeatures,
|
|
433
449
|
TData,
|
|
@@ -447,7 +463,7 @@ export function createTableHook<
|
|
|
447
463
|
return footer as Header<TFeatures, TData, any> & THeaderComponents
|
|
448
464
|
}
|
|
449
465
|
|
|
450
|
-
const appTableFeatures: TableFeature
|
|
466
|
+
const appTableFeatures: TableFeature = {
|
|
451
467
|
constructTableAPIs: (table) => {
|
|
452
468
|
Object.assign(table, tableComponents, { appCell, appHeader, appFooter })
|
|
453
469
|
},
|
|
@@ -467,8 +483,14 @@ export function createTableHook<
|
|
|
467
483
|
...defaultTableOptions.features,
|
|
468
484
|
appTableFeatures,
|
|
469
485
|
},
|
|
470
|
-
} as TableOptions<TFeatures, TData>
|
|
471
|
-
}) as
|
|
486
|
+
} as unknown as TableOptions<TFeatures, TData>
|
|
487
|
+
}) as unknown as AppAngularTable<
|
|
488
|
+
TFeatures,
|
|
489
|
+
TData,
|
|
490
|
+
TTableComponents,
|
|
491
|
+
TCellComponents,
|
|
492
|
+
THeaderComponents
|
|
493
|
+
>
|
|
472
494
|
}
|
|
473
495
|
|
|
474
496
|
function createAppColumnHelper<TData extends RowData>(): AppColumnHelper<
|
package/src/helpers/header.ts
CHANGED
|
@@ -23,7 +23,7 @@ export interface TanStackTableHeaderContext<
|
|
|
23
23
|
* This token is provided by the {@link TanStackTableHeader} directive.
|
|
24
24
|
*/
|
|
25
25
|
export const TanStackTableHeaderToken = new InjectionToken<
|
|
26
|
-
TanStackTableHeaderContext<
|
|
26
|
+
TanStackTableHeaderContext<TableFeatures, RowData, CellData>['header']
|
|
27
27
|
>('[TanStack Table] HeaderContext')
|
|
28
28
|
|
|
29
29
|
/**
|
|
@@ -95,5 +95,7 @@ export function injectTableHeaderContext<
|
|
|
95
95
|
TData extends RowData,
|
|
96
96
|
TValue extends CellData,
|
|
97
97
|
>(): TanStackTableHeaderContext<TFeatures, TData, TValue>['header'] {
|
|
98
|
-
return inject(
|
|
98
|
+
return inject(
|
|
99
|
+
TanStackTableHeaderToken,
|
|
100
|
+
) as unknown as TanStackTableHeaderContext<TFeatures, TData, TValue>['header']
|
|
99
101
|
}
|
package/src/helpers/table.ts
CHANGED
|
@@ -9,7 +9,7 @@ import type { Signal } from '@angular/core'
|
|
|
9
9
|
* This token is provided by the {@link TanStackTable} directive.
|
|
10
10
|
*/
|
|
11
11
|
export const TanStackTableToken = new InjectionToken<
|
|
12
|
-
Signal<AngularTable<
|
|
12
|
+
Signal<AngularTable<TableFeatures, RowData>>
|
|
13
13
|
>('[TanStack Table] Table Context')
|
|
14
14
|
|
|
15
15
|
/**
|
|
@@ -81,5 +81,7 @@ export function injectTableContext<
|
|
|
81
81
|
TFeatures extends TableFeatures,
|
|
82
82
|
TData extends RowData,
|
|
83
83
|
>(): Signal<AngularTable<TFeatures, TData>> {
|
|
84
|
-
return inject(TanStackTableToken)
|
|
84
|
+
return inject(TanStackTableToken) as unknown as Signal<
|
|
85
|
+
AngularTable<TFeatures, TData>
|
|
86
|
+
>
|
|
85
87
|
}
|
package/src/injectTable.ts
CHANGED
|
@@ -15,7 +15,6 @@ import type {
|
|
|
15
15
|
Table,
|
|
16
16
|
TableFeatures,
|
|
17
17
|
TableOptions,
|
|
18
|
-
TableState,
|
|
19
18
|
} from '@tanstack/table-core'
|
|
20
19
|
import type {
|
|
21
20
|
Atom,
|
|
@@ -33,70 +32,7 @@ export type SubscribeSource<TValue> =
|
|
|
33
32
|
export type AngularTable<
|
|
34
33
|
TFeatures extends TableFeatures,
|
|
35
34
|
TData extends RowData,
|
|
36
|
-
> = Table<TFeatures, TData>
|
|
37
|
-
/**
|
|
38
|
-
* @deprecated Prefer `table.atoms.<slice>.get()` for template/render reads
|
|
39
|
-
* of a specific state slice, `table.state` for full-state debug snapshots, or
|
|
40
|
-
* Angular computed values around explicit selectors. `table.store.state` is a
|
|
41
|
-
* current-value snapshot and is easy to misuse in render code.
|
|
42
|
-
*/
|
|
43
|
-
readonly store: Table<TFeatures, TData>['store']
|
|
44
|
-
/**
|
|
45
|
-
* The current table state exposed as a flat proxy. Prefer
|
|
46
|
-
* `table.atoms.<slice>.get()` when reading a specific slice.
|
|
47
|
-
*/
|
|
48
|
-
readonly state: Readonly<TableState<TFeatures>>
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function createStateProxy<
|
|
52
|
-
TFeatures extends TableFeatures,
|
|
53
|
-
TData extends RowData,
|
|
54
|
-
>(table: Table<TFeatures, TData>): Readonly<TableState<TFeatures>> {
|
|
55
|
-
const getSnapshot = () => {
|
|
56
|
-
const snapshot = {} as TableState<TFeatures>
|
|
57
|
-
const stateKeys = Object.keys(table.initialState) as Array<
|
|
58
|
-
string & keyof TableState<TFeatures>
|
|
59
|
-
>
|
|
60
|
-
|
|
61
|
-
for (const key of stateKeys) {
|
|
62
|
-
;(snapshot as Record<string, unknown>)[key] = table.atoms[key].get()
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return snapshot
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const target = {} as TableState<TFeatures>
|
|
69
|
-
|
|
70
|
-
return new Proxy(target, {
|
|
71
|
-
get(target, prop, receiver) {
|
|
72
|
-
if (prop === 'toJSON') {
|
|
73
|
-
return getSnapshot
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (typeof prop === 'string' && prop in table.initialState) {
|
|
77
|
-
return table.atoms[prop as keyof TableState<TFeatures>]?.get()
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return Reflect.get(target, prop, receiver)
|
|
81
|
-
},
|
|
82
|
-
has(_, prop) {
|
|
83
|
-
return typeof prop === 'string' && prop in table.initialState
|
|
84
|
-
},
|
|
85
|
-
ownKeys() {
|
|
86
|
-
return Reflect.ownKeys(table.initialState)
|
|
87
|
-
},
|
|
88
|
-
getOwnPropertyDescriptor(_, prop) {
|
|
89
|
-
if (typeof prop !== 'string' || !(prop in table.initialState)) {
|
|
90
|
-
return undefined
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return {
|
|
94
|
-
enumerable: true,
|
|
95
|
-
configurable: true,
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
})
|
|
99
|
-
}
|
|
35
|
+
> = Table<TFeatures, TData>
|
|
100
36
|
|
|
101
37
|
/**
|
|
102
38
|
* Creates and returns an Angular-reactive table instance.
|
|
@@ -166,28 +102,21 @@ export function injectTable<
|
|
|
166
102
|
|
|
167
103
|
return ngZone.runOutsideAngular(() =>
|
|
168
104
|
lazyInit(() => {
|
|
169
|
-
|
|
105
|
+
// Explicit type arguments skip generic inference from the spread object
|
|
106
|
+
// (a type-check hot spot); the spread only adds the angular reactivity
|
|
107
|
+
// binding to `features`.
|
|
108
|
+
const table = constructTable<TFeatures, TData>({
|
|
170
109
|
...options(),
|
|
171
110
|
features: {
|
|
172
|
-
|
|
111
|
+
coreReactivityFeature: angularReactivity(injector),
|
|
173
112
|
...options().features,
|
|
174
113
|
},
|
|
175
|
-
})
|
|
114
|
+
})
|
|
176
115
|
|
|
177
116
|
injector.get(DestroyRef).onDestroy(() => {
|
|
178
117
|
table._reactivity.unmount?.()
|
|
179
118
|
})
|
|
180
119
|
|
|
181
|
-
const stateProxy = createStateProxy(table)
|
|
182
|
-
|
|
183
|
-
Object.defineProperty(table, 'state', {
|
|
184
|
-
get() {
|
|
185
|
-
return stateProxy
|
|
186
|
-
},
|
|
187
|
-
configurable: true,
|
|
188
|
-
enumerable: true,
|
|
189
|
-
})
|
|
190
|
-
|
|
191
120
|
let isMount = true
|
|
192
121
|
effect(
|
|
193
122
|
() => {
|