@tanstack/angular-table 9.0.0-alpha.5 → 9.0.0-alpha.52
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 +127 -0
- package/dist/README.md +127 -0
- package/dist/fesm2022/tanstack-angular-table-static-functions.mjs +6 -0
- package/dist/fesm2022/tanstack-angular-table-static-functions.mjs.map +1 -0
- package/dist/fesm2022/tanstack-angular-table.mjs +1357 -242
- package/dist/fesm2022/tanstack-angular-table.mjs.map +1 -1
- package/dist/types/tanstack-angular-table-static-functions.d.ts +1 -0
- package/dist/types/tanstack-angular-table.d.ts +793 -0
- package/package.json +39 -19
- package/skills/angular/angular-rendering-directives/SKILL.md +415 -0
- package/skills/angular/angular-rendering-directives/references/content-shapes.md +142 -0
- package/skills/angular/angular-rendering-directives/references/create-table-hook-registries.md +89 -0
- package/skills/angular/angular-rendering-directives/references/di-tokens.md +171 -0
- package/skills/angular/angular-rendering-directives/references/flex-render-component-options.md +64 -0
- package/skills/angular/client-to-server/SKILL.md +467 -0
- package/skills/angular/compose-with-tanstack-query/SKILL.md +482 -0
- package/skills/angular/compose-with-tanstack-store/SKILL.md +397 -0
- package/skills/angular/compose-with-tanstack-virtual/SKILL.md +400 -0
- package/skills/angular/getting-started/SKILL.md +496 -0
- package/skills/angular/getting-started/references/feature-row-model-mapping.md +48 -0
- package/skills/angular/migrate-v8-to-v9/SKILL.md +419 -0
- package/skills/angular/migrate-v8-to-v9/references/v8-to-v9-mapping.md +261 -0
- package/skills/angular/production-readiness/SKILL.md +469 -0
- package/skills/angular/table-state/SKILL.md +429 -0
- package/skills/angular/table-state/references/external-atoms-and-app-hook.md +152 -0
- package/src/flex-render/context.ts +14 -0
- package/src/flex-render/flags.ts +34 -0
- package/src/flex-render/flexRenderComponent.ts +288 -0
- package/src/flex-render/flexRenderComponentFactory.ts +251 -0
- package/src/flex-render/renderer.ts +393 -0
- package/src/flex-render/view.ts +226 -0
- package/src/flexRender.ts +124 -0
- package/src/helpers/cell.ts +104 -0
- package/src/helpers/createTableHook.ts +499 -0
- package/src/helpers/flexRenderCell.ts +136 -0
- package/src/helpers/header.ts +99 -0
- package/src/helpers/table.ts +85 -0
- package/src/index.ts +23 -70
- package/src/injectTable.ts +206 -0
- package/src/{lazy-signal-initializer.ts → lazySignalInitializer.ts} +2 -2
- package/src/reactivity.ts +147 -0
- package/static-functions/index.ts +1 -0
- package/static-functions/ng-package.json +6 -0
- package/dist/esm2022/flex-render.mjs +0 -150
- package/dist/esm2022/index.mjs +0 -48
- package/dist/esm2022/lazy-signal-initializer.mjs +0 -43
- package/dist/esm2022/proxy.mjs +0 -83
- package/dist/esm2022/tanstack-angular-table.mjs +0 -5
- package/dist/flex-render.d.ts +0 -31
- package/dist/index.d.ts +0 -5
- package/dist/lazy-signal-initializer.d.ts +0 -5
- package/dist/proxy.d.ts +0 -3
- package/src/__tests__/createAngularTable.test.ts +0 -95
- package/src/__tests__/flex-render.test.ts +0 -178
- package/src/__tests__/lazy-init.test.ts +0 -124
- package/src/__tests__/test-setup.ts +0 -12
- package/src/__tests__/test-utils.ts +0 -62
- package/src/flex-render.ts +0 -187
- package/src/proxy.ts +0 -97
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DestroyRef,
|
|
3
|
+
Directive,
|
|
4
|
+
Injector,
|
|
5
|
+
InputSignal,
|
|
6
|
+
TemplateRef,
|
|
7
|
+
ViewContainerRef,
|
|
8
|
+
inject,
|
|
9
|
+
input,
|
|
10
|
+
} from '@angular/core'
|
|
11
|
+
import {
|
|
12
|
+
FlexRenderInputContent,
|
|
13
|
+
FlexViewRenderer,
|
|
14
|
+
} from './flex-render/renderer'
|
|
15
|
+
import type {
|
|
16
|
+
CellContext,
|
|
17
|
+
CellData,
|
|
18
|
+
HeaderContext,
|
|
19
|
+
RowData,
|
|
20
|
+
TableFeatures,
|
|
21
|
+
} from '@tanstack/table-core'
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
injectFlexRenderContext,
|
|
25
|
+
type FlexRenderComponentProps,
|
|
26
|
+
} from './flex-render/context'
|
|
27
|
+
|
|
28
|
+
export type {
|
|
29
|
+
FlexRenderInputContent,
|
|
30
|
+
FlexRenderContent,
|
|
31
|
+
} from './flex-render/renderer'
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Use this utility directive to render headers, cells, or footers with custom markup.
|
|
35
|
+
*
|
|
36
|
+
* Note: If you are rendering cell, header, or footer without custom context or other props,
|
|
37
|
+
* you can use the {@link FlexRenderCell} directive as shorthand instead .
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* import {FlexRender} from '@tanstack/angular-table';
|
|
42
|
+
*
|
|
43
|
+
* @Component({
|
|
44
|
+
* imports: [FlexRender],
|
|
45
|
+
* template: `
|
|
46
|
+
* <td
|
|
47
|
+
* *flexRender="
|
|
48
|
+
* cell.column.columnDef.cell;
|
|
49
|
+
* props: cell.getContext();
|
|
50
|
+
* let cell"
|
|
51
|
+
* >
|
|
52
|
+
* {{cell}}
|
|
53
|
+
* </td>
|
|
54
|
+
*
|
|
55
|
+
* <th
|
|
56
|
+
* *flexRender="
|
|
57
|
+
* header.column.columnDef.header;
|
|
58
|
+
* props: header.getContext();
|
|
59
|
+
* let header"
|
|
60
|
+
* >
|
|
61
|
+
* {{header}}
|
|
62
|
+
* </td>
|
|
63
|
+
*
|
|
64
|
+
* <td
|
|
65
|
+
* *flexRender="
|
|
66
|
+
* footer.column.columnDef.footer;
|
|
67
|
+
* props: footer.getContext();
|
|
68
|
+
* let footer"
|
|
69
|
+
* >
|
|
70
|
+
* {{footer}}
|
|
71
|
+
* </td>
|
|
72
|
+
* `,
|
|
73
|
+
* })
|
|
74
|
+
* class App {
|
|
75
|
+
* }
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* Can be imported through {@link FlexRenderDirective} or {@link FlexRender} import,
|
|
79
|
+
* which the latter is preferred.
|
|
80
|
+
*/
|
|
81
|
+
@Directive({
|
|
82
|
+
selector: 'ng-template[flexRender]',
|
|
83
|
+
})
|
|
84
|
+
export class FlexRenderDirective<
|
|
85
|
+
TFeatures extends TableFeatures,
|
|
86
|
+
TRowData extends RowData,
|
|
87
|
+
TValue extends CellData,
|
|
88
|
+
TProps extends
|
|
89
|
+
| NonNullable<unknown>
|
|
90
|
+
| CellContext<TFeatures, TRowData, TValue>
|
|
91
|
+
| HeaderContext<TFeatures, TRowData, TValue>,
|
|
92
|
+
> {
|
|
93
|
+
readonly content: InputSignal<FlexRenderInputContent<TProps>> = input(
|
|
94
|
+
undefined as FlexRenderInputContent<TProps>,
|
|
95
|
+
{ alias: 'flexRender' },
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
readonly props = input<TProps>({} as TProps, {
|
|
99
|
+
alias: 'flexRenderProps',
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
readonly injector = input(inject(Injector), {
|
|
103
|
+
alias: 'flexRenderInjector',
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
readonly #viewContainerRef = inject(ViewContainerRef)
|
|
107
|
+
readonly #templateRef = inject(TemplateRef)
|
|
108
|
+
|
|
109
|
+
constructor() {
|
|
110
|
+
const renderer = new FlexViewRenderer({
|
|
111
|
+
content: this.content,
|
|
112
|
+
props: this.props,
|
|
113
|
+
injector: this.injector,
|
|
114
|
+
templateRef: this.#templateRef,
|
|
115
|
+
viewContainerRef: this.#viewContainerRef,
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
renderer.mount()
|
|
119
|
+
|
|
120
|
+
inject(DestroyRef).onDestroy(() => {
|
|
121
|
+
renderer.destroy()
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Directive, InjectionToken, inject, input } from '@angular/core'
|
|
2
|
+
import { Cell, CellData, RowData, TableFeatures } from '@tanstack/table-core'
|
|
3
|
+
import type { Signal } from '@angular/core'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* DI context shape for a TanStack Table cell.
|
|
7
|
+
*
|
|
8
|
+
* This exists to make the current `Cell` injectable by any nested component/directive
|
|
9
|
+
* without having to pass it through inputs/props manually.
|
|
10
|
+
*/
|
|
11
|
+
export interface TanStackTableCellContext<
|
|
12
|
+
TFeatures extends TableFeatures,
|
|
13
|
+
TData extends RowData,
|
|
14
|
+
TValue extends CellData,
|
|
15
|
+
> {
|
|
16
|
+
/** Signal that returns the current cell instance. */
|
|
17
|
+
cell: Signal<Cell<TFeatures, TData, TValue>>
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Injection token that provides access to the current cell.
|
|
22
|
+
*
|
|
23
|
+
* This token is provided by the {@link TanStackTableCell} directive.
|
|
24
|
+
*/
|
|
25
|
+
export const TanStackTableCellToken = new InjectionToken<
|
|
26
|
+
TanStackTableCellContext<any, any, any>['cell']
|
|
27
|
+
>('[TanStack Table] CellContext')
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Provides a TanStack Table `Cell` instance in Angular DI.
|
|
31
|
+
*
|
|
32
|
+
* The cell can be injected by:
|
|
33
|
+
* - any descendant of an element using `[tanStackTableCell]="..."`
|
|
34
|
+
* - any component instantiated by `*flexRender` when the render props contains `cell`
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* Inject from the nearest `[tanStackTableCell]`:
|
|
38
|
+
* ```html
|
|
39
|
+
* <td [tanStackTableCell]="cell">
|
|
40
|
+
* <app-cell-actions />
|
|
41
|
+
* </td>
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* ```ts
|
|
45
|
+
* @Component({
|
|
46
|
+
* selector: 'app-cell-actions',
|
|
47
|
+
* template: `{{ cell().id }}`,
|
|
48
|
+
* })
|
|
49
|
+
* export class CellActionsComponent {
|
|
50
|
+
* readonly cell = injectTableCellContext()
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* Inject inside a component rendered via `flexRender`:
|
|
56
|
+
* ```ts
|
|
57
|
+
* @Component({
|
|
58
|
+
* selector: 'app-price-cell',
|
|
59
|
+
* template: `{{ cell().getValue() }}`,
|
|
60
|
+
* })
|
|
61
|
+
* export class PriceCellComponent {
|
|
62
|
+
* readonly cell = injectTableCellContext()
|
|
63
|
+
* }
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
@Directive({
|
|
67
|
+
selector: '[tanStackTableCell]',
|
|
68
|
+
exportAs: 'cell',
|
|
69
|
+
providers: [
|
|
70
|
+
{
|
|
71
|
+
provide: TanStackTableCellToken,
|
|
72
|
+
useFactory: () => inject(TanStackTableCell).cell,
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
})
|
|
76
|
+
export class TanStackTableCell<
|
|
77
|
+
TFeatures extends TableFeatures,
|
|
78
|
+
TData extends RowData,
|
|
79
|
+
TValue extends CellData,
|
|
80
|
+
> implements TanStackTableCellContext<TFeatures, TData, TValue> {
|
|
81
|
+
/**
|
|
82
|
+
* The current TanStack Table cell.
|
|
83
|
+
*
|
|
84
|
+
* Provided as a required signal input so DI consumers always read the latest value.
|
|
85
|
+
*/
|
|
86
|
+
readonly cell = input.required<Cell<TFeatures, TData, TValue>>({
|
|
87
|
+
alias: 'tanStackTableCell',
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Injects the current TanStack Table cell signal.
|
|
93
|
+
*
|
|
94
|
+
* Available when:
|
|
95
|
+
* - there is a nearest `[tanStackTableCell]` directive in the DI tree, or
|
|
96
|
+
* - the caller is rendered via `*flexRender` with render props containing `cell`
|
|
97
|
+
*/
|
|
98
|
+
export function injectTableCellContext<
|
|
99
|
+
TFeatures extends TableFeatures,
|
|
100
|
+
TData extends RowData,
|
|
101
|
+
TValue extends CellData,
|
|
102
|
+
>(): TanStackTableCellContext<TFeatures, TData, TValue>['cell'] {
|
|
103
|
+
return inject(TanStackTableCellToken)
|
|
104
|
+
}
|