@tanstack/angular-table 9.0.0-alpha.4 → 9.0.0-alpha.41
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 +117 -0
- package/dist/README.md +117 -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 +1225 -258
- 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 +795 -0
- package/package.json +37 -18
- 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 +241 -0
- package/src/flex-render/renderer.ts +393 -0
- package/src/flex-render/view.ts +207 -0
- package/src/flexRender.ts +124 -0
- package/src/helpers/cell.ts +104 -0
- package/src/helpers/createTableHook.ts +480 -0
- package/src/helpers/flexRenderCell.ts +136 -0
- package/src/helpers/header.ts +99 -0
- package/src/helpers/table.ts +87 -0
- package/src/index.ts +21 -70
- package/src/injectTable.ts +238 -0
- package/src/{lazy-signal-initializer.ts → lazySignalInitializer.ts} +2 -2
- 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
|
@@ -1,11 +1,1049 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { InjectionToken, input, inject, Directive, reflectComponentType, Injectable, KeyValueDiffers, ChangeDetectorRef, OutputEmitterRef, TemplateRef, Type, runInInjectionContext, computed, effect, untracked, Injector, ViewContainerRef, DestroyRef, assertInInjectionContext, signal } from '@angular/core';
|
|
3
|
+
import { constructReactivityFeature, constructTable, createColumnHelper } from '@tanstack/table-core';
|
|
4
4
|
export * from '@tanstack/table-core';
|
|
5
|
+
import { injectSelector } from '@tanstack/angular-store';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Injection token that provides access to the current cell.
|
|
9
|
+
*
|
|
10
|
+
* This token is provided by the {@link TanStackTableCell} directive.
|
|
11
|
+
*/
|
|
12
|
+
const TanStackTableCellToken = new InjectionToken('[TanStack Table] CellContext');
|
|
13
|
+
/**
|
|
14
|
+
* Provides a TanStack Table `Cell` instance in Angular DI.
|
|
15
|
+
*
|
|
16
|
+
* The cell can be injected by:
|
|
17
|
+
* - any descendant of an element using `[tanStackTableCell]="..."`
|
|
18
|
+
* - any component instantiated by `*flexRender` when the render props contains `cell`
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* Inject from the nearest `[tanStackTableCell]`:
|
|
22
|
+
* ```html
|
|
23
|
+
* <td [tanStackTableCell]="cell">
|
|
24
|
+
* <app-cell-actions />
|
|
25
|
+
* </td>
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* ```ts
|
|
29
|
+
* @Component({
|
|
30
|
+
* selector: 'app-cell-actions',
|
|
31
|
+
* template: `{{ cell().id }}`,
|
|
32
|
+
* })
|
|
33
|
+
* export class CellActionsComponent {
|
|
34
|
+
* readonly cell = injectTableCellContext()
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* Inject inside a component rendered via `flexRender`:
|
|
40
|
+
* ```ts
|
|
41
|
+
* @Component({
|
|
42
|
+
* selector: 'app-price-cell',
|
|
43
|
+
* template: `{{ cell().getValue() }}`,
|
|
44
|
+
* })
|
|
45
|
+
* export class PriceCellComponent {
|
|
46
|
+
* readonly cell = injectTableCellContext()
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
class TanStackTableCell {
|
|
51
|
+
/**
|
|
52
|
+
* The current TanStack Table cell.
|
|
53
|
+
*
|
|
54
|
+
* Provided as a required signal input so DI consumers always read the latest value.
|
|
55
|
+
*/
|
|
56
|
+
cell = input.required({ ...(ngDevMode ? { debugName: "cell" } : /* istanbul ignore next */ {}), alias: 'tanStackTableCell' });
|
|
57
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.11", ngImport: i0, type: TanStackTableCell, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
58
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.11", type: TanStackTableCell, isStandalone: true, selector: "[tanStackTableCell]", inputs: { cell: { classPropertyName: "cell", publicName: "tanStackTableCell", isSignal: true, isRequired: true, transformFunction: null } }, providers: [
|
|
59
|
+
{
|
|
60
|
+
provide: TanStackTableCellToken,
|
|
61
|
+
useFactory: () => inject(TanStackTableCell).cell,
|
|
62
|
+
},
|
|
63
|
+
], exportAs: ["cell"], ngImport: i0 });
|
|
64
|
+
}
|
|
65
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.11", ngImport: i0, type: TanStackTableCell, decorators: [{
|
|
66
|
+
type: Directive,
|
|
67
|
+
args: [{
|
|
68
|
+
selector: '[tanStackTableCell]',
|
|
69
|
+
exportAs: 'cell',
|
|
70
|
+
providers: [
|
|
71
|
+
{
|
|
72
|
+
provide: TanStackTableCellToken,
|
|
73
|
+
useFactory: () => inject(TanStackTableCell).cell,
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
}]
|
|
77
|
+
}], propDecorators: { cell: [{ type: i0.Input, args: [{ isSignal: true, alias: "tanStackTableCell", required: true }] }] } });
|
|
78
|
+
/**
|
|
79
|
+
* Injects the current TanStack Table cell signal.
|
|
80
|
+
*
|
|
81
|
+
* Available when:
|
|
82
|
+
* - there is a nearest `[tanStackTableCell]` directive in the DI tree, or
|
|
83
|
+
* - the caller is rendered via `*flexRender` with render props containing `cell`
|
|
84
|
+
*/
|
|
85
|
+
function injectTableCellContext() {
|
|
86
|
+
return inject(TanStackTableCellToken);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Injection token that provides access to the current header.
|
|
91
|
+
*
|
|
92
|
+
* This token is provided by the {@link TanStackTableHeader} directive.
|
|
93
|
+
*/
|
|
94
|
+
const TanStackTableHeaderToken = new InjectionToken('[TanStack Table] HeaderContext');
|
|
95
|
+
/**
|
|
96
|
+
* Provides a TanStack Table `Header` instance in Angular DI.
|
|
97
|
+
*
|
|
98
|
+
* The header can be injected by:
|
|
99
|
+
* - any descendant of an element using `[tanStackTableHeader]="..."`
|
|
100
|
+
* - any component instantiated by `*flexRender` when the render props contains `header`
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```html
|
|
104
|
+
* <th [tanStackTableHeader]="header">
|
|
105
|
+
* <app-sort-indicator />
|
|
106
|
+
* </th>
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* ```ts
|
|
110
|
+
* @Component({
|
|
111
|
+
* selector: 'app-sort-indicator',
|
|
112
|
+
* template: `
|
|
113
|
+
* <button (click)="toggle()">
|
|
114
|
+
* {{ header().column.id }}
|
|
115
|
+
* </button>
|
|
116
|
+
* `,
|
|
117
|
+
* })
|
|
118
|
+
* export class SortIndicatorComponent {
|
|
119
|
+
* readonly header = injectTableHeaderContext()
|
|
120
|
+
*
|
|
121
|
+
* toggle() {
|
|
122
|
+
* this.header().column.toggleSorting()
|
|
123
|
+
* }
|
|
124
|
+
* }
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
class TanStackTableHeader {
|
|
128
|
+
/**
|
|
129
|
+
* The current TanStack Table header.
|
|
130
|
+
*
|
|
131
|
+
* Provided as a required signal input so DI consumers always read the latest value.
|
|
132
|
+
*/
|
|
133
|
+
header = input.required({ ...(ngDevMode ? { debugName: "header" } : /* istanbul ignore next */ {}), alias: 'tanStackTableHeader' });
|
|
134
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.11", ngImport: i0, type: TanStackTableHeader, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
135
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.11", type: TanStackTableHeader, isStandalone: true, selector: "[tanStackTableHeader]", inputs: { header: { classPropertyName: "header", publicName: "tanStackTableHeader", isSignal: true, isRequired: true, transformFunction: null } }, providers: [
|
|
136
|
+
{
|
|
137
|
+
provide: TanStackTableHeaderToken,
|
|
138
|
+
useFactory: () => inject(TanStackTableHeader).header,
|
|
139
|
+
},
|
|
140
|
+
], exportAs: ["header"], ngImport: i0 });
|
|
141
|
+
}
|
|
142
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.11", ngImport: i0, type: TanStackTableHeader, decorators: [{
|
|
143
|
+
type: Directive,
|
|
144
|
+
args: [{
|
|
145
|
+
selector: '[tanStackTableHeader]',
|
|
146
|
+
exportAs: 'header',
|
|
147
|
+
providers: [
|
|
148
|
+
{
|
|
149
|
+
provide: TanStackTableHeaderToken,
|
|
150
|
+
useFactory: () => inject(TanStackTableHeader).header,
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
}]
|
|
154
|
+
}], propDecorators: { header: [{ type: i0.Input, args: [{ isSignal: true, alias: "tanStackTableHeader", required: true }] }] } });
|
|
155
|
+
/**
|
|
156
|
+
* Injects the current TanStack Table header signal.
|
|
157
|
+
*
|
|
158
|
+
* Available when:
|
|
159
|
+
* - there is a nearest `[tanStackTableHeader]` directive in the DI tree, or
|
|
160
|
+
* - the caller is rendered via `*flexRender` with render props containing `header`
|
|
161
|
+
*/
|
|
162
|
+
function injectTableHeaderContext() {
|
|
163
|
+
return inject(TanStackTableHeaderToken);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Injection token that provides access to the current {@link AngularTable} instance.
|
|
168
|
+
*
|
|
169
|
+
* This token is provided by the {@link TanStackTable} directive.
|
|
170
|
+
*/
|
|
171
|
+
const TanStackTableToken = new InjectionToken('[TanStack Table] Table Context');
|
|
172
|
+
/**
|
|
173
|
+
* Provides a TanStack Table instance (`AngularTable`) in Angular DI.
|
|
174
|
+
*
|
|
175
|
+
* The table can be injected by:
|
|
176
|
+
* - any descendant of an element using `[tanStackTable]="..."`
|
|
177
|
+
* - any component instantiated by `*flexRender` when the render props contains `table`
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```html
|
|
181
|
+
* <div [tanStackTable]="table">
|
|
182
|
+
* <app-pagination />
|
|
183
|
+
* </div>
|
|
184
|
+
* ```
|
|
185
|
+
*
|
|
186
|
+
* ```ts
|
|
187
|
+
* @Component({
|
|
188
|
+
* selector: 'app-pagination',
|
|
189
|
+
* template: `
|
|
190
|
+
* <button (click)="prev()" [disabled]="!table().getCanPreviousPage()">Prev</button>
|
|
191
|
+
* <button (click)="next()" [disabled]="!table().getCanNextPage()">Next</button>
|
|
192
|
+
* `,
|
|
193
|
+
* })
|
|
194
|
+
* export class PaginationComponent {
|
|
195
|
+
* readonly table = injectTableContext()
|
|
196
|
+
*
|
|
197
|
+
* prev() {
|
|
198
|
+
* this.table().previousPage()
|
|
199
|
+
* }
|
|
200
|
+
* next() {
|
|
201
|
+
* this.table().nextPage()
|
|
202
|
+
* }
|
|
203
|
+
* }
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
class TanStackTable {
|
|
207
|
+
/**
|
|
208
|
+
* The current TanStack Table instance.
|
|
209
|
+
*
|
|
210
|
+
* Provided as a required signal input so DI consumers always read the latest value.
|
|
211
|
+
*/
|
|
212
|
+
table = input.required({ ...(ngDevMode ? { debugName: "table" } : /* istanbul ignore next */ {}), alias: 'tanStackTable' });
|
|
213
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.11", ngImport: i0, type: TanStackTable, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
214
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.11", type: TanStackTable, isStandalone: true, selector: "[tanStackTable]", inputs: { table: { classPropertyName: "table", publicName: "tanStackTable", isSignal: true, isRequired: true, transformFunction: null } }, providers: [
|
|
215
|
+
{
|
|
216
|
+
provide: TanStackTableToken,
|
|
217
|
+
useFactory: () => inject(TanStackTable).table,
|
|
218
|
+
},
|
|
219
|
+
], exportAs: ["table"], ngImport: i0 });
|
|
220
|
+
}
|
|
221
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.11", ngImport: i0, type: TanStackTable, decorators: [{
|
|
222
|
+
type: Directive,
|
|
223
|
+
args: [{
|
|
224
|
+
selector: '[tanStackTable]',
|
|
225
|
+
exportAs: 'table',
|
|
226
|
+
providers: [
|
|
227
|
+
{
|
|
228
|
+
provide: TanStackTableToken,
|
|
229
|
+
useFactory: () => inject(TanStackTable).table,
|
|
230
|
+
},
|
|
231
|
+
],
|
|
232
|
+
}]
|
|
233
|
+
}], propDecorators: { table: [{ type: i0.Input, args: [{ isSignal: true, alias: "tanStackTable", required: true }] }] } });
|
|
234
|
+
/**
|
|
235
|
+
* Injects the current TanStack Table instance signal.
|
|
236
|
+
*
|
|
237
|
+
* Available when:
|
|
238
|
+
* - there is a nearest `[tanStackTable]` directive in the DI tree, or
|
|
239
|
+
* - the caller is rendered via `*flexRender` with render props containing `table`
|
|
240
|
+
*/
|
|
241
|
+
function injectTableContext() {
|
|
242
|
+
return inject(TanStackTableToken);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const FlexRenderComponentProps = new InjectionToken('[@tanstack/angular-table] Flex render component context props');
|
|
246
|
+
/**
|
|
247
|
+
* Inject the flex render context props.
|
|
248
|
+
*
|
|
249
|
+
* Can be used in components rendered via FlexRender directives.
|
|
250
|
+
*/
|
|
251
|
+
function injectFlexRenderContext() {
|
|
252
|
+
return inject(FlexRenderComponentProps);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Flags used to manage and optimize the rendering lifecycle of the content of the cell
|
|
257
|
+
* while using {@link FlexViewRenderer}.
|
|
258
|
+
*/
|
|
259
|
+
const FlexRenderFlags = {
|
|
260
|
+
/**
|
|
261
|
+
* Indicates that the view is being created for the first time or will be cleared during the next update phase.
|
|
262
|
+
* This is the initial state and will transition after the first ngDoCheck.
|
|
263
|
+
*/
|
|
264
|
+
ViewFirstRender: 1 << 0,
|
|
265
|
+
/**
|
|
266
|
+
* Indicates the `content` property has been modified or the view requires a complete re-render.
|
|
267
|
+
* When this flag is enabled, the view will be cleared and recreated from scratch.
|
|
268
|
+
*/
|
|
269
|
+
ContentChanged: 1 << 1,
|
|
270
|
+
/**
|
|
271
|
+
* Indicates that the `props` property reference has changed.
|
|
272
|
+
* When this flag is enabled, the view context is updated based on the type of the content.
|
|
273
|
+
*
|
|
274
|
+
* For Component view, inputs will be updated and view will be marked as dirty.
|
|
275
|
+
* For TemplateRef and primitive values, view will be marked as dirty
|
|
276
|
+
*/
|
|
277
|
+
PropsReferenceChanged: 1 << 2,
|
|
278
|
+
/**
|
|
279
|
+
* Indicates that the current rendered view needs to be checked for changes.
|
|
280
|
+
* This will be set to true when `content(props)` result has changed or during
|
|
281
|
+
* forced update
|
|
282
|
+
*/
|
|
283
|
+
Dirty: 1 << 3,
|
|
284
|
+
/**
|
|
285
|
+
* Indicates that the first render effect has been checked at least one time.
|
|
286
|
+
*/
|
|
287
|
+
RenderEffectChecked: 1 << 4,
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Helper function to create a {@link FlexRenderComponent} instance, with better type-safety.
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* ```ts
|
|
295
|
+
* import {flexRenderComponent} from '@tanstack/angular-table'
|
|
296
|
+
* import {inputBinding, outputBinding} from '@angular/core';
|
|
297
|
+
*
|
|
298
|
+
* const columns = [
|
|
299
|
+
* {
|
|
300
|
+
* cell: ({ row }) => {
|
|
301
|
+
* return flexRenderComponent(MyComponent, {
|
|
302
|
+
* inputs: { value: mySignalValue() },
|
|
303
|
+
* outputs: { valueChange: (val) => {} }
|
|
304
|
+
* // or using angular native createComponent#binding api
|
|
305
|
+
* bindings: [
|
|
306
|
+
* inputBinding('value', mySignalValue),
|
|
307
|
+
* outputBinding('valueChange', value => {
|
|
308
|
+
* console.log("my value changed to", value)
|
|
309
|
+
* })
|
|
310
|
+
* ]
|
|
311
|
+
* })
|
|
312
|
+
* },
|
|
313
|
+
* },
|
|
314
|
+
* ]
|
|
315
|
+
* ```
|
|
316
|
+
*/
|
|
317
|
+
function flexRenderComponent(component, options) {
|
|
318
|
+
const { inputs, injector, outputs, directives, bindings } = options ?? {};
|
|
319
|
+
return new FlexRenderComponentInstance(component, inputs, injector, outputs, directives, bindings);
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Wrapper class for a component that will be used as content for {@link FlexRenderDirective}
|
|
323
|
+
*
|
|
324
|
+
* Prefer {@link flexRenderComponent} helper for better type-safety
|
|
325
|
+
*/
|
|
326
|
+
class FlexRenderComponentInstance {
|
|
327
|
+
component;
|
|
328
|
+
inputs;
|
|
329
|
+
injector;
|
|
330
|
+
outputs;
|
|
331
|
+
directives;
|
|
332
|
+
bindings;
|
|
333
|
+
mirror;
|
|
334
|
+
allowedInputNames = [];
|
|
335
|
+
allowedOutputNames = [];
|
|
336
|
+
constructor(component, inputs, injector, outputs, directives, bindings) {
|
|
337
|
+
this.component = component;
|
|
338
|
+
this.inputs = inputs;
|
|
339
|
+
this.injector = injector;
|
|
340
|
+
this.outputs = outputs;
|
|
341
|
+
this.directives = directives;
|
|
342
|
+
this.bindings = bindings;
|
|
343
|
+
const mirror = reflectComponentType(component);
|
|
344
|
+
if (!mirror) {
|
|
345
|
+
throw new Error(`[@tanstack-table/angular] The provided symbol is not a component`);
|
|
346
|
+
}
|
|
347
|
+
this.mirror = mirror;
|
|
348
|
+
for (const input of this.mirror.inputs) {
|
|
349
|
+
this.allowedInputNames.push(input.propName);
|
|
350
|
+
}
|
|
351
|
+
for (const output of this.mirror.outputs) {
|
|
352
|
+
this.allowedOutputNames.push(output.propName);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
class FlexRenderComponentFactory {
|
|
358
|
+
#viewContainerRef;
|
|
359
|
+
constructor(viewContainerRef) {
|
|
360
|
+
this.#viewContainerRef = viewContainerRef;
|
|
361
|
+
}
|
|
362
|
+
createComponent(flexRenderComponent, componentInjector) {
|
|
363
|
+
const componentRef = this.#viewContainerRef.createComponent(flexRenderComponent.component, {
|
|
364
|
+
injector: componentInjector,
|
|
365
|
+
directives: flexRenderComponent.directives,
|
|
366
|
+
bindings: flexRenderComponent.bindings ?? [],
|
|
367
|
+
});
|
|
368
|
+
const view = new FlexRenderComponentRef(componentRef, flexRenderComponent, componentInjector);
|
|
369
|
+
const { inputs, outputs } = flexRenderComponent;
|
|
370
|
+
if (inputs)
|
|
371
|
+
view.setInputs(inputs);
|
|
372
|
+
if (outputs)
|
|
373
|
+
view.setOutputs(outputs);
|
|
374
|
+
return view;
|
|
375
|
+
}
|
|
376
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.11", ngImport: i0, type: FlexRenderComponentFactory, deps: [{ token: i0.ViewContainerRef }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
377
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.11", ngImport: i0, type: FlexRenderComponentFactory });
|
|
378
|
+
}
|
|
379
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.11", ngImport: i0, type: FlexRenderComponentFactory, decorators: [{
|
|
380
|
+
type: Injectable
|
|
381
|
+
}], ctorParameters: () => [{ type: i0.ViewContainerRef }] });
|
|
382
|
+
class FlexRenderComponentRef {
|
|
383
|
+
componentRef;
|
|
384
|
+
componentInjector;
|
|
385
|
+
#keyValueDiffersFactory;
|
|
386
|
+
#componentData;
|
|
387
|
+
#inputValueDiffer;
|
|
388
|
+
#outputRegistry;
|
|
389
|
+
constructor(componentRef, componentData, componentInjector) {
|
|
390
|
+
this.componentRef = componentRef;
|
|
391
|
+
this.componentInjector = componentInjector;
|
|
392
|
+
this.#componentData = componentData;
|
|
393
|
+
this.#keyValueDiffersFactory = componentInjector.get(KeyValueDiffers);
|
|
394
|
+
this.#outputRegistry = new FlexRenderComponentOutputManager(this.#keyValueDiffersFactory, this.outputs);
|
|
395
|
+
this.#inputValueDiffer = this.#keyValueDiffersFactory
|
|
396
|
+
.find(this.inputs)
|
|
397
|
+
.create();
|
|
398
|
+
this.#inputValueDiffer.diff(this.inputs);
|
|
399
|
+
this.componentRef.onDestroy(() => this.#outputRegistry.unsubscribeAll());
|
|
400
|
+
}
|
|
401
|
+
get component() {
|
|
402
|
+
return this.#componentData.component;
|
|
403
|
+
}
|
|
404
|
+
get inputs() {
|
|
405
|
+
return this.#componentData.inputs ?? {};
|
|
406
|
+
}
|
|
407
|
+
get outputs() {
|
|
408
|
+
return this.#componentData.outputs ?? {};
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Get component input and output diff by the given item
|
|
412
|
+
*/
|
|
413
|
+
diff(item) {
|
|
414
|
+
return {
|
|
415
|
+
inputDiff: this.#inputValueDiffer.diff(item.inputs ?? {}),
|
|
416
|
+
outputDiff: this.#outputRegistry.diff(item.outputs ?? {}),
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
*
|
|
421
|
+
* @param compare Whether the current ref component instance is the same as the given one
|
|
422
|
+
*/
|
|
423
|
+
eqType(compare) {
|
|
424
|
+
return compare.component === this.component;
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Tries to update current component refs input by the new given content component.
|
|
428
|
+
*/
|
|
429
|
+
update(content) {
|
|
430
|
+
const eq = this.eqType(content);
|
|
431
|
+
if (!eq)
|
|
432
|
+
return;
|
|
433
|
+
const { inputDiff, outputDiff } = this.diff(content);
|
|
434
|
+
if (inputDiff) {
|
|
435
|
+
inputDiff.forEachAddedItem((item) => this.setInput(item.key, item.currentValue));
|
|
436
|
+
inputDiff.forEachChangedItem((item) => this.setInput(item.key, item.currentValue));
|
|
437
|
+
inputDiff.forEachRemovedItem((item) => this.setInput(item.key, undefined));
|
|
438
|
+
}
|
|
439
|
+
if (outputDiff) {
|
|
440
|
+
outputDiff.forEachAddedItem((item) => {
|
|
441
|
+
this.setOutput(item.key, item.currentValue);
|
|
442
|
+
});
|
|
443
|
+
outputDiff.forEachChangedItem((item) => {
|
|
444
|
+
if (item.currentValue) {
|
|
445
|
+
this.#outputRegistry.setListener(item.key, item.currentValue);
|
|
446
|
+
}
|
|
447
|
+
else {
|
|
448
|
+
this.#outputRegistry.unsubscribe(item.key);
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
outputDiff.forEachRemovedItem((item) => {
|
|
452
|
+
this.#outputRegistry.unsubscribe(item.key);
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
this.#componentData = content;
|
|
456
|
+
}
|
|
457
|
+
markAsDirty() {
|
|
458
|
+
this.componentRef.injector.get(ChangeDetectorRef).markForCheck();
|
|
459
|
+
}
|
|
460
|
+
setInputs(inputs) {
|
|
461
|
+
for (const prop in inputs) {
|
|
462
|
+
this.setInput(prop, inputs[prop]);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
setInput(key, value) {
|
|
466
|
+
if (this.#componentData.allowedInputNames.includes(key)) {
|
|
467
|
+
this.componentRef.setInput(key, value);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
setOutputs(outputs) {
|
|
471
|
+
this.#outputRegistry.unsubscribeAll();
|
|
472
|
+
for (const prop in outputs) {
|
|
473
|
+
this.setOutput(prop, outputs[prop]);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
setOutput(outputName, emit) {
|
|
477
|
+
if (!this.#componentData.allowedOutputNames.includes(outputName))
|
|
478
|
+
return;
|
|
479
|
+
if (!emit) {
|
|
480
|
+
this.#outputRegistry.unsubscribe(outputName);
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
const hasListener = this.#outputRegistry.hasListener(outputName);
|
|
484
|
+
this.#outputRegistry.setListener(outputName, emit);
|
|
485
|
+
if (hasListener) {
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
const instance = this.componentRef.instance;
|
|
489
|
+
const output = instance[outputName];
|
|
490
|
+
if (output && output instanceof OutputEmitterRef) {
|
|
491
|
+
output.subscribe((value) => {
|
|
492
|
+
this.#outputRegistry.getListener(outputName)?.(value);
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
class FlexRenderComponentOutputManager {
|
|
498
|
+
#outputSubscribers = {};
|
|
499
|
+
#outputListeners = {};
|
|
500
|
+
#valueDiffer;
|
|
501
|
+
constructor(keyValueDiffers, initialOutputs) {
|
|
502
|
+
this.#valueDiffer = keyValueDiffers.find(initialOutputs).create();
|
|
503
|
+
if (initialOutputs) {
|
|
504
|
+
this.#valueDiffer.diff(initialOutputs);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
hasListener(outputName) {
|
|
508
|
+
return outputName in this.#outputListeners;
|
|
509
|
+
}
|
|
510
|
+
setListener(outputName, callback) {
|
|
511
|
+
this.#outputListeners[outputName] = callback;
|
|
512
|
+
}
|
|
513
|
+
getListener(outputName) {
|
|
514
|
+
return this.#outputListeners[outputName];
|
|
515
|
+
}
|
|
516
|
+
unsubscribeAll() {
|
|
517
|
+
for (const prop in this.#outputSubscribers) {
|
|
518
|
+
this.unsubscribe(prop);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
unsubscribe(outputName) {
|
|
522
|
+
if (outputName in this.#outputSubscribers) {
|
|
523
|
+
this.#outputSubscribers[outputName]?.unsubscribe();
|
|
524
|
+
delete this.#outputSubscribers[outputName];
|
|
525
|
+
delete this.#outputListeners[outputName];
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
diff(outputs) {
|
|
529
|
+
return this.#valueDiffer.diff(outputs);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
function mapToFlexRenderTypedContent(content) {
|
|
534
|
+
if (content === null || content === undefined) {
|
|
535
|
+
return { kind: 'null' };
|
|
536
|
+
}
|
|
537
|
+
if (typeof content === 'string' || typeof content === 'number') {
|
|
538
|
+
return { kind: 'primitive', content };
|
|
539
|
+
}
|
|
540
|
+
if (content instanceof FlexRenderComponentInstance) {
|
|
541
|
+
return { kind: 'flexRenderComponent', content };
|
|
542
|
+
}
|
|
543
|
+
else if (content instanceof TemplateRef) {
|
|
544
|
+
return { kind: 'templateRef', content };
|
|
545
|
+
}
|
|
546
|
+
else if (content instanceof Type) {
|
|
547
|
+
return { kind: 'component', content };
|
|
548
|
+
}
|
|
549
|
+
else {
|
|
550
|
+
return { kind: 'primitive', content };
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
class FlexRenderView {
|
|
554
|
+
view;
|
|
555
|
+
#previousContent;
|
|
556
|
+
#content;
|
|
557
|
+
constructor(initialContent, view) {
|
|
558
|
+
this.#content = initialContent;
|
|
559
|
+
this.view = view;
|
|
560
|
+
}
|
|
561
|
+
get previousContent() {
|
|
562
|
+
return this.#previousContent ?? { kind: 'null' };
|
|
563
|
+
}
|
|
564
|
+
get content() {
|
|
565
|
+
return this.#content;
|
|
566
|
+
}
|
|
567
|
+
set content(content) {
|
|
568
|
+
this.#previousContent = this.#content;
|
|
569
|
+
this.#content = content;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
class FlexRenderTemplateView extends FlexRenderView {
|
|
573
|
+
constructor(initialContent, view) {
|
|
574
|
+
super(initialContent, view);
|
|
575
|
+
}
|
|
576
|
+
updateProps(props) {
|
|
577
|
+
this.view.markForCheck();
|
|
578
|
+
}
|
|
579
|
+
dirtyCheck() {
|
|
580
|
+
// Basically a no-op. When the view is created via EmbeddedViewRef, we don't need to do any manual update
|
|
581
|
+
// since this type of content has a proxy as a context, then every time the root component is checked for changes,
|
|
582
|
+
// the property getter will be re-evaluated.
|
|
583
|
+
//
|
|
584
|
+
// If in a future we need to manually mark the view as dirty, just uncomment next line
|
|
585
|
+
// this.view.markForCheck()
|
|
586
|
+
}
|
|
587
|
+
unmount() {
|
|
588
|
+
this.view.destroy();
|
|
589
|
+
}
|
|
590
|
+
onDestroy(callback) {
|
|
591
|
+
this.view.onDestroy(callback);
|
|
592
|
+
}
|
|
593
|
+
eq(compare) {
|
|
594
|
+
return ((this.content.kind === 'primitive' &&
|
|
595
|
+
compare.kind === 'primitive' &&
|
|
596
|
+
this.content.content === compare.content) ||
|
|
597
|
+
(this.content.kind === 'templateRef' &&
|
|
598
|
+
compare.kind === 'templateRef' &&
|
|
599
|
+
this.content.content === compare.content));
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
class FlexRenderComponentView extends FlexRenderView {
|
|
603
|
+
constructor(initialContent, view) {
|
|
604
|
+
super(initialContent, view);
|
|
605
|
+
}
|
|
606
|
+
updateProps(props) {
|
|
607
|
+
switch (this.content.kind) {
|
|
608
|
+
case 'component': {
|
|
609
|
+
this.view.setInputs(props);
|
|
610
|
+
break;
|
|
611
|
+
}
|
|
612
|
+
case 'flexRenderComponent': {
|
|
613
|
+
// No-op. When FlexRenderFlags.PropsReferenceChanged is set,
|
|
614
|
+
// FlexRenderComponent will be updated into `dirtyCheck`.
|
|
615
|
+
break;
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
dirtyCheck() {
|
|
620
|
+
switch (this.content.kind) {
|
|
621
|
+
case 'component': {
|
|
622
|
+
// Component context is currently valuated with the cell context. Since it's reference
|
|
623
|
+
// shouldn't change, we force mark the component as dirty in order to re-evaluate function invocation in view.
|
|
624
|
+
// NOTE: this should behave like having a component with ChangeDetectionStrategy.Default
|
|
625
|
+
this.view.markAsDirty();
|
|
626
|
+
break;
|
|
627
|
+
}
|
|
628
|
+
case 'flexRenderComponent': {
|
|
629
|
+
// Given context instance will always have a different reference than the previous one,
|
|
630
|
+
// so instead of recreating the entire view, we will only update the current view
|
|
631
|
+
if (this.view.eqType(this.content.content)) {
|
|
632
|
+
this.view.update(this.content.content);
|
|
633
|
+
}
|
|
634
|
+
this.view.markAsDirty();
|
|
635
|
+
break;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
unmount() {
|
|
640
|
+
this.view.componentRef.destroy();
|
|
641
|
+
}
|
|
642
|
+
onDestroy(callback) {
|
|
643
|
+
this.view.componentRef.onDestroy(callback);
|
|
644
|
+
}
|
|
645
|
+
eq(compare) {
|
|
646
|
+
return ((this.content.kind === 'component' &&
|
|
647
|
+
compare.kind === 'component' &&
|
|
648
|
+
this.content.content === compare.content) ||
|
|
649
|
+
(this.content.kind === 'flexRenderComponent' &&
|
|
650
|
+
compare.kind === 'flexRenderComponent' &&
|
|
651
|
+
this.content.content.component === compare.content.component));
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
/**
|
|
656
|
+
* Internal view renderer used by Angular TanStack Table to implement `flexRender` directives.
|
|
657
|
+
*
|
|
658
|
+
* @internal Use FlexRender directives instead.
|
|
659
|
+
*/
|
|
660
|
+
class FlexViewRenderer {
|
|
661
|
+
#renderFlags = FlexRenderFlags.ViewFirstRender;
|
|
662
|
+
#renderView = null;
|
|
663
|
+
#currentRenderEffectRef = null;
|
|
664
|
+
#content;
|
|
665
|
+
#props;
|
|
666
|
+
#injector;
|
|
667
|
+
#viewContainerRef;
|
|
668
|
+
#templateRef;
|
|
669
|
+
#flexRenderComponentFactory;
|
|
670
|
+
#getLatestContentValue = () => {
|
|
671
|
+
const content = this.#content();
|
|
672
|
+
const props = this.#props();
|
|
673
|
+
return typeof content !== 'function'
|
|
674
|
+
? content
|
|
675
|
+
: runInInjectionContext(this.#injector(), () => content(props));
|
|
676
|
+
};
|
|
677
|
+
#latestContent = computed(() => this.#getLatestContentValue(), ...(ngDevMode ? [{ debugName: "#latestContent" }] : /* istanbul ignore next */ []));
|
|
678
|
+
#getContentValue = computed(() => {
|
|
679
|
+
const latestContent = this.#latestContent();
|
|
680
|
+
return mapToFlexRenderTypedContent(latestContent);
|
|
681
|
+
}, ...(ngDevMode ? [{ debugName: "#getContentValue" }] : /* istanbul ignore next */ []));
|
|
682
|
+
constructor(options) {
|
|
683
|
+
this.#content = options.content;
|
|
684
|
+
this.#props = options.props;
|
|
685
|
+
this.#injector = options.injector;
|
|
686
|
+
this.#templateRef = options.templateRef;
|
|
687
|
+
this.#viewContainerRef = options.viewContainerRef;
|
|
688
|
+
this.#flexRenderComponentFactory = new FlexRenderComponentFactory(this.#viewContainerRef);
|
|
689
|
+
}
|
|
690
|
+
mount() {
|
|
691
|
+
let previousContent;
|
|
692
|
+
let previousProps;
|
|
693
|
+
return effect(() => {
|
|
694
|
+
const props = this.#props();
|
|
695
|
+
const content = this.#content();
|
|
696
|
+
if (!(this.#renderFlags & FlexRenderFlags.ViewFirstRender)) {
|
|
697
|
+
if (previousContent !== content) {
|
|
698
|
+
this.#renderFlags |= FlexRenderFlags.ContentChanged;
|
|
699
|
+
}
|
|
700
|
+
if (previousProps !== props) {
|
|
701
|
+
this.#renderFlags |= FlexRenderFlags.PropsReferenceChanged;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
untracked(() => this.#update());
|
|
705
|
+
if (FlexRenderFlags.ViewFirstRender & this.#renderFlags) {
|
|
706
|
+
this.#renderFlags &= ~FlexRenderFlags.ViewFirstRender;
|
|
707
|
+
}
|
|
708
|
+
previousContent = content;
|
|
709
|
+
previousProps = props;
|
|
710
|
+
});
|
|
711
|
+
}
|
|
712
|
+
destroy() {
|
|
713
|
+
if (this.#currentRenderEffectRef) {
|
|
714
|
+
this.#currentRenderEffectRef.destroy();
|
|
715
|
+
this.#currentRenderEffectRef = null;
|
|
716
|
+
}
|
|
717
|
+
if (this.#renderView) {
|
|
718
|
+
this.#renderView.unmount();
|
|
719
|
+
this.#renderView = null;
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
#update() {
|
|
723
|
+
if (this.#renderFlags &
|
|
724
|
+
(FlexRenderFlags.ContentChanged | FlexRenderFlags.ViewFirstRender)) {
|
|
725
|
+
this.#render();
|
|
726
|
+
return;
|
|
727
|
+
}
|
|
728
|
+
if (this.#renderFlags & FlexRenderFlags.PropsReferenceChanged) {
|
|
729
|
+
if (this.#renderView)
|
|
730
|
+
this.#renderView.updateProps(this.#props());
|
|
731
|
+
this.#renderFlags &= ~FlexRenderFlags.PropsReferenceChanged;
|
|
732
|
+
}
|
|
733
|
+
if (this.#renderFlags & FlexRenderFlags.Dirty) {
|
|
734
|
+
if (this.#renderView)
|
|
735
|
+
this.#renderView.dirtyCheck();
|
|
736
|
+
this.#renderFlags &= ~FlexRenderFlags.Dirty;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
#render() {
|
|
740
|
+
// When the view is recreated from scratch (content change or first render),
|
|
741
|
+
// we have to destroy the current effect listener since it will be recreated
|
|
742
|
+
// skipping the first call (FlexRenderFlags.RenderEffectChecked)
|
|
743
|
+
if (this.#shouldRecreateEntireView() && this.#currentRenderEffectRef) {
|
|
744
|
+
this.#currentRenderEffectRef.destroy();
|
|
745
|
+
this.#currentRenderEffectRef = null;
|
|
746
|
+
this.#renderFlags &= ~FlexRenderFlags.RenderEffectChecked;
|
|
747
|
+
}
|
|
748
|
+
this.#viewContainerRef.clear();
|
|
749
|
+
if (this.#renderView) {
|
|
750
|
+
this.#renderView.unmount();
|
|
751
|
+
this.#renderView = null;
|
|
752
|
+
}
|
|
753
|
+
this.#renderFlags =
|
|
754
|
+
(this.#renderFlags & FlexRenderFlags.ViewFirstRender) |
|
|
755
|
+
(this.#renderFlags & FlexRenderFlags.RenderEffectChecked);
|
|
756
|
+
const resolvedContent = this.#getContentValue();
|
|
757
|
+
this.#renderView = this.#renderViewByContent(resolvedContent);
|
|
758
|
+
// If the content is a function `content(props)`, we initialize an effect
|
|
759
|
+
// to react to changes. If the current fn uses signals, we will set the DirtySignal flag
|
|
760
|
+
// to re-schedule the component updates
|
|
761
|
+
if (!this.#currentRenderEffectRef &&
|
|
762
|
+
typeof untracked(this.#content) === 'function') {
|
|
763
|
+
this.#currentRenderEffectRef = effect(() => {
|
|
764
|
+
this.#latestContent();
|
|
765
|
+
if (!(this.#renderFlags & FlexRenderFlags.RenderEffectChecked)) {
|
|
766
|
+
this.#renderFlags |= FlexRenderFlags.RenderEffectChecked;
|
|
767
|
+
return;
|
|
768
|
+
}
|
|
769
|
+
this.#renderFlags |= FlexRenderFlags.Dirty;
|
|
770
|
+
this.#doCheck();
|
|
771
|
+
}, { ...(ngDevMode ? { debugName: "#currentRenderEffectRef" } : /* istanbul ignore next */ {}), injector: this.#viewContainerRef.injector });
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
#shouldRecreateEntireView() {
|
|
775
|
+
return (this.#renderFlags &
|
|
776
|
+
FlexRenderFlags.ContentChanged &
|
|
777
|
+
FlexRenderFlags.ViewFirstRender);
|
|
778
|
+
}
|
|
779
|
+
#doCheck() {
|
|
780
|
+
const latestContent = this.#getContentValue();
|
|
781
|
+
if (latestContent.kind === 'null' || !this.#renderView) {
|
|
782
|
+
this.#renderFlags |= FlexRenderFlags.ContentChanged;
|
|
783
|
+
}
|
|
784
|
+
else {
|
|
785
|
+
const { kind: currentKind } = this.#renderView.content;
|
|
786
|
+
if (latestContent.kind !== currentKind ||
|
|
787
|
+
!this.#renderView.eq(latestContent)) {
|
|
788
|
+
this.#renderFlags |= FlexRenderFlags.ContentChanged;
|
|
789
|
+
}
|
|
790
|
+
this.#renderView.content = latestContent;
|
|
791
|
+
}
|
|
792
|
+
this.#update();
|
|
793
|
+
}
|
|
794
|
+
#renderViewByContent(content) {
|
|
795
|
+
if (content.kind === 'primitive') {
|
|
796
|
+
return this.#renderStringContent(content);
|
|
797
|
+
}
|
|
798
|
+
else if (content.kind === 'templateRef') {
|
|
799
|
+
return this.#renderTemplateRefContent(content);
|
|
800
|
+
}
|
|
801
|
+
else if (content.kind === 'flexRenderComponent') {
|
|
802
|
+
return this.#renderComponent(content);
|
|
803
|
+
}
|
|
804
|
+
else if (content.kind === 'component') {
|
|
805
|
+
return this.#renderCustomComponent(content);
|
|
806
|
+
}
|
|
807
|
+
else {
|
|
808
|
+
return null;
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
#renderStringContent(template) {
|
|
812
|
+
const context = () => {
|
|
813
|
+
const content = this.#content();
|
|
814
|
+
return typeof content === 'string' || typeof content === 'number'
|
|
815
|
+
? content
|
|
816
|
+
: runInInjectionContext(this.#injector(), () => content?.(this.#props()));
|
|
817
|
+
};
|
|
818
|
+
const ref = this.#viewContainerRef.createEmbeddedView(this.#templateRef, {
|
|
819
|
+
get $implicit() {
|
|
820
|
+
return context();
|
|
821
|
+
},
|
|
822
|
+
});
|
|
823
|
+
return new FlexRenderTemplateView(template, ref);
|
|
824
|
+
}
|
|
825
|
+
#renderTemplateRefContent(template) {
|
|
826
|
+
const latestContext = () => this.#props();
|
|
827
|
+
const view = this.#viewContainerRef.createEmbeddedView(template.content, {
|
|
828
|
+
get $implicit() {
|
|
829
|
+
return latestContext();
|
|
830
|
+
},
|
|
831
|
+
}, { injector: this.#getInjector() });
|
|
832
|
+
return new FlexRenderTemplateView(template, view);
|
|
833
|
+
}
|
|
834
|
+
#renderComponent(flexRenderComponent) {
|
|
835
|
+
const { injector } = flexRenderComponent.content;
|
|
836
|
+
const componentInjector = this.#getInjector(injector);
|
|
837
|
+
const view = this.#flexRenderComponentFactory.createComponent(flexRenderComponent.content, componentInjector);
|
|
838
|
+
return new FlexRenderComponentView(flexRenderComponent, view);
|
|
839
|
+
}
|
|
840
|
+
#renderCustomComponent(component) {
|
|
841
|
+
const instance = flexRenderComponent(component.content, {
|
|
842
|
+
inputs: this.#props(),
|
|
843
|
+
});
|
|
844
|
+
const injector = this.#getInjector(instance.injector);
|
|
845
|
+
const view = this.#flexRenderComponentFactory.createComponent(instance, injector);
|
|
846
|
+
return new FlexRenderComponentView(component, view);
|
|
847
|
+
}
|
|
848
|
+
#getInjector(parentInjector) {
|
|
849
|
+
const getContext = () => this.#props();
|
|
850
|
+
const proxy = new Proxy(this.#props(), {
|
|
851
|
+
get: (_, key) => getContext()[key],
|
|
852
|
+
});
|
|
853
|
+
const staticProviders = [];
|
|
854
|
+
if ('table' in proxy) {
|
|
855
|
+
staticProviders.push({
|
|
856
|
+
provide: TanStackTableToken,
|
|
857
|
+
useValue: () => proxy.table,
|
|
858
|
+
});
|
|
859
|
+
}
|
|
860
|
+
if ('cell' in proxy) {
|
|
861
|
+
staticProviders.push({
|
|
862
|
+
provide: TanStackTableCellToken,
|
|
863
|
+
useValue: () => proxy.cell,
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
if ('header' in proxy) {
|
|
867
|
+
staticProviders.push({
|
|
868
|
+
provide: TanStackTableHeaderToken,
|
|
869
|
+
useValue: () => proxy.header,
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
return Injector.create({
|
|
873
|
+
parent: parentInjector ?? this.#injector(),
|
|
874
|
+
providers: [
|
|
875
|
+
...staticProviders,
|
|
876
|
+
{ provide: FlexRenderComponentProps, useValue: proxy },
|
|
877
|
+
],
|
|
878
|
+
});
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
/**
|
|
883
|
+
* Simplified directive wrapper of `*flexRender`.
|
|
884
|
+
*
|
|
885
|
+
* Use this utility component to render headers, cells, or footers with custom markup.
|
|
886
|
+
*
|
|
887
|
+
* Only one prop (`cell`, `header`, or `footer`) may be passed based on the used selector.
|
|
888
|
+
*
|
|
889
|
+
* @example
|
|
890
|
+
* ```html
|
|
891
|
+
* <td *flexRenderCell="cell; let cell">{{cell}}</td>
|
|
892
|
+
* <th *flexRenderHeader="header; let header">{{header}}</th>
|
|
893
|
+
* <th *flexRenderFooter="footer; let footer">{{footer}}</th>
|
|
894
|
+
* ```
|
|
895
|
+
*
|
|
896
|
+
* This replaces calling `*flexRender` directly like this:
|
|
897
|
+
* ```html
|
|
898
|
+
* <td *flexRender="cell.column.columnDef.cell; props: cell.getContext(); let cell">{{cell}}</td>
|
|
899
|
+
* <td *flexRender="header.column.columnDef.header; props: header.getContext(); let header">{{header}}</td>
|
|
900
|
+
* <td *flexRender="footer.column.columnDef.footer; props: footer.getContext(); let footer">{{footer}}</td>
|
|
901
|
+
* ```
|
|
902
|
+
*
|
|
903
|
+
* Can be imported through {@link FlexRenderCell} or {@link FlexRender} import,
|
|
904
|
+
* which the latter is preferred.
|
|
905
|
+
*
|
|
906
|
+
* @example
|
|
907
|
+
* ```ts
|
|
908
|
+
* import {FlexRender} from '@tanstack/angular-table
|
|
909
|
+
*
|
|
910
|
+
* @Component({
|
|
911
|
+
* // ...
|
|
912
|
+
* imports: [
|
|
913
|
+
* FlexRender
|
|
914
|
+
* ]
|
|
915
|
+
* })
|
|
916
|
+
* ```
|
|
917
|
+
*/
|
|
918
|
+
class FlexRenderCell {
|
|
919
|
+
cell = input(undefined, { ...(ngDevMode ? { debugName: "cell" } : /* istanbul ignore next */ {}), alias: 'flexRenderCell' });
|
|
920
|
+
header = input(undefined, { ...(ngDevMode ? { debugName: "header" } : /* istanbul ignore next */ {}), alias: 'flexRenderHeader' });
|
|
921
|
+
footer = input(undefined, { ...(ngDevMode ? { debugName: "footer" } : /* istanbul ignore next */ {}), alias: 'flexRenderFooter' });
|
|
922
|
+
#renderData = computed(() => {
|
|
923
|
+
const cell = this.cell();
|
|
924
|
+
const header = this.header();
|
|
925
|
+
const footer = this.footer();
|
|
926
|
+
if (cell) {
|
|
927
|
+
return [cell.column.columnDef.cell, cell.getContext()];
|
|
928
|
+
}
|
|
929
|
+
if (header) {
|
|
930
|
+
return [header.column.columnDef.header, header.getContext()];
|
|
931
|
+
}
|
|
932
|
+
if (footer) {
|
|
933
|
+
return [footer.column.columnDef.footer, footer.getContext()];
|
|
934
|
+
}
|
|
935
|
+
return [null, null];
|
|
936
|
+
}, { ...(ngDevMode ? { debugName: "#renderData" } : /* istanbul ignore next */ {}), equal: (a, b) => {
|
|
937
|
+
return a[0] === b[0] && a[1] === b[1];
|
|
938
|
+
} });
|
|
939
|
+
#injector = inject(Injector);
|
|
940
|
+
#templateRef = inject(TemplateRef);
|
|
941
|
+
#viewContainerRef = inject(ViewContainerRef);
|
|
942
|
+
constructor() {
|
|
943
|
+
const content = computed(() => this.#renderData()[0], ...(ngDevMode ? [{ debugName: "content" }] : /* istanbul ignore next */ []));
|
|
944
|
+
const props = computed(() => this.#renderData()[1], ...(ngDevMode ? [{ debugName: "props" }] : /* istanbul ignore next */ []));
|
|
945
|
+
const renderer = new FlexViewRenderer({
|
|
946
|
+
content: content,
|
|
947
|
+
props: props,
|
|
948
|
+
injector: () => this.#injector,
|
|
949
|
+
templateRef: this.#templateRef,
|
|
950
|
+
viewContainerRef: this.#viewContainerRef,
|
|
951
|
+
});
|
|
952
|
+
renderer.mount();
|
|
953
|
+
inject(DestroyRef).onDestroy(() => {
|
|
954
|
+
renderer.destroy();
|
|
955
|
+
});
|
|
956
|
+
}
|
|
957
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.11", ngImport: i0, type: FlexRenderCell, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
958
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.11", type: FlexRenderCell, isStandalone: true, selector: "ng-template[flexRenderCell], ng-template[flexRenderFooter], ng-template[flexRenderHeader]", inputs: { cell: { classPropertyName: "cell", publicName: "flexRenderCell", isSignal: true, isRequired: false, transformFunction: null }, header: { classPropertyName: "header", publicName: "flexRenderHeader", isSignal: true, isRequired: false, transformFunction: null }, footer: { classPropertyName: "footer", publicName: "flexRenderFooter", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0 });
|
|
959
|
+
}
|
|
960
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.11", ngImport: i0, type: FlexRenderCell, decorators: [{
|
|
961
|
+
type: Directive,
|
|
962
|
+
args: [{
|
|
963
|
+
selector: 'ng-template[flexRenderCell], ng-template[flexRenderFooter], ng-template[flexRenderHeader]',
|
|
964
|
+
}]
|
|
965
|
+
}], ctorParameters: () => [], propDecorators: { cell: [{ type: i0.Input, args: [{ isSignal: true, alias: "flexRenderCell", required: false }] }], header: [{ type: i0.Input, args: [{ isSignal: true, alias: "flexRenderHeader", required: false }] }], footer: [{ type: i0.Input, args: [{ isSignal: true, alias: "flexRenderFooter", required: false }] }] } });
|
|
966
|
+
|
|
967
|
+
/**
|
|
968
|
+
* Use this utility directive to render headers, cells, or footers with custom markup.
|
|
969
|
+
*
|
|
970
|
+
* Note: If you are rendering cell, header, or footer without custom context or other props,
|
|
971
|
+
* you can use the {@link FlexRenderCell} directive as shorthand instead .
|
|
972
|
+
*
|
|
973
|
+
* @example
|
|
974
|
+
* ```ts
|
|
975
|
+
* import {FlexRender} from '@tanstack/angular-table';
|
|
976
|
+
*
|
|
977
|
+
* @Component({
|
|
978
|
+
* imports: [FlexRender],
|
|
979
|
+
* template: `
|
|
980
|
+
* <td
|
|
981
|
+
* *flexRender="
|
|
982
|
+
* cell.column.columnDef.cell;
|
|
983
|
+
* props: cell.getContext();
|
|
984
|
+
* let cell"
|
|
985
|
+
* >
|
|
986
|
+
* {{cell}}
|
|
987
|
+
* </td>
|
|
988
|
+
*
|
|
989
|
+
* <th
|
|
990
|
+
* *flexRender="
|
|
991
|
+
* header.column.columnDef.header;
|
|
992
|
+
* props: header.getContext();
|
|
993
|
+
* let header"
|
|
994
|
+
* >
|
|
995
|
+
* {{header}}
|
|
996
|
+
* </td>
|
|
997
|
+
*
|
|
998
|
+
* <td
|
|
999
|
+
* *flexRender="
|
|
1000
|
+
* footer.column.columnDef.footer;
|
|
1001
|
+
* props: footer.getContext();
|
|
1002
|
+
* let footer"
|
|
1003
|
+
* >
|
|
1004
|
+
* {{footer}}
|
|
1005
|
+
* </td>
|
|
1006
|
+
* `,
|
|
1007
|
+
* })
|
|
1008
|
+
* class App {
|
|
1009
|
+
* }
|
|
1010
|
+
* ```
|
|
1011
|
+
*
|
|
1012
|
+
* Can be imported through {@link FlexRenderDirective} or {@link FlexRender} import,
|
|
1013
|
+
* which the latter is preferred.
|
|
1014
|
+
*/
|
|
1015
|
+
class FlexRenderDirective {
|
|
1016
|
+
content = input(undefined, { ...(ngDevMode ? { debugName: "content" } : /* istanbul ignore next */ {}), alias: 'flexRender' });
|
|
1017
|
+
props = input({}, { ...(ngDevMode ? { debugName: "props" } : /* istanbul ignore next */ {}), alias: 'flexRenderProps' });
|
|
1018
|
+
injector = input(inject(Injector), { ...(ngDevMode ? { debugName: "injector" } : /* istanbul ignore next */ {}), alias: 'flexRenderInjector' });
|
|
1019
|
+
#viewContainerRef = inject(ViewContainerRef);
|
|
1020
|
+
#templateRef = inject(TemplateRef);
|
|
1021
|
+
constructor() {
|
|
1022
|
+
const renderer = new FlexViewRenderer({
|
|
1023
|
+
content: this.content,
|
|
1024
|
+
props: this.props,
|
|
1025
|
+
injector: this.injector,
|
|
1026
|
+
templateRef: this.#templateRef,
|
|
1027
|
+
viewContainerRef: this.#viewContainerRef,
|
|
1028
|
+
});
|
|
1029
|
+
renderer.mount();
|
|
1030
|
+
inject(DestroyRef).onDestroy(() => {
|
|
1031
|
+
renderer.destroy();
|
|
1032
|
+
});
|
|
1033
|
+
}
|
|
1034
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.11", ngImport: i0, type: FlexRenderDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1035
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.11", type: FlexRenderDirective, isStandalone: true, selector: "ng-template[flexRender]", inputs: { content: { classPropertyName: "content", publicName: "flexRender", isSignal: true, isRequired: false, transformFunction: null }, props: { classPropertyName: "props", publicName: "flexRenderProps", isSignal: true, isRequired: false, transformFunction: null }, injector: { classPropertyName: "injector", publicName: "flexRenderInjector", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0 });
|
|
1036
|
+
}
|
|
1037
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.11", ngImport: i0, type: FlexRenderDirective, decorators: [{
|
|
1038
|
+
type: Directive,
|
|
1039
|
+
args: [{
|
|
1040
|
+
selector: 'ng-template[flexRender]',
|
|
1041
|
+
}]
|
|
1042
|
+
}], ctorParameters: () => [], propDecorators: { content: [{ type: i0.Input, args: [{ isSignal: true, alias: "flexRender", required: false }] }], props: [{ type: i0.Input, args: [{ isSignal: true, alias: "flexRenderProps", required: false }] }], injector: [{ type: i0.Input, args: [{ isSignal: true, alias: "flexRenderInjector", required: false }] }] } });
|
|
5
1043
|
|
|
6
1044
|
/**
|
|
7
1045
|
* Implementation from @tanstack/angular-query
|
|
8
|
-
* {
|
|
1046
|
+
* {https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/util/lazy-init/lazy-init.ts}
|
|
9
1047
|
*/
|
|
10
1048
|
function lazyInit(initializer) {
|
|
11
1049
|
let object = null;
|
|
@@ -45,281 +1083,210 @@ function lazyInit(initializer) {
|
|
|
45
1083
|
});
|
|
46
1084
|
}
|
|
47
1085
|
|
|
48
|
-
function proxifyTable(tableSignal) {
|
|
49
|
-
const internalState = tableSignal;
|
|
50
|
-
return new Proxy(internalState, {
|
|
51
|
-
apply() {
|
|
52
|
-
return tableSignal();
|
|
53
|
-
},
|
|
54
|
-
get(target, property) {
|
|
55
|
-
if (target[property]) {
|
|
56
|
-
return target[property];
|
|
57
|
-
}
|
|
58
|
-
const table = untracked(tableSignal);
|
|
59
|
-
/**
|
|
60
|
-
* Attempt to convert all accessors into computed ones,
|
|
61
|
-
* excluding handlers as they do not retain any reactive value
|
|
62
|
-
*/
|
|
63
|
-
if (property.startsWith('get') &&
|
|
64
|
-
!property.endsWith('Handler') &&
|
|
65
|
-
!property.endsWith('Model')) {
|
|
66
|
-
const maybeFn = table[property];
|
|
67
|
-
if (typeof maybeFn === 'function') {
|
|
68
|
-
Object.defineProperty(target, property, {
|
|
69
|
-
value: toComputed(tableSignal, maybeFn),
|
|
70
|
-
configurable: true,
|
|
71
|
-
enumerable: true,
|
|
72
|
-
});
|
|
73
|
-
return target[property];
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
// @ts-expect-error
|
|
77
|
-
return (target[property] = table[property]);
|
|
78
|
-
},
|
|
79
|
-
has(_, prop) {
|
|
80
|
-
return !!untracked(tableSignal)[prop];
|
|
81
|
-
},
|
|
82
|
-
ownKeys() {
|
|
83
|
-
return Reflect.ownKeys(untracked(tableSignal));
|
|
84
|
-
},
|
|
85
|
-
getOwnPropertyDescriptor() {
|
|
86
|
-
return {
|
|
87
|
-
enumerable: true,
|
|
88
|
-
configurable: true,
|
|
89
|
-
};
|
|
90
|
-
},
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
1086
|
/**
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
* -
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
1087
|
+
* Creates and returns an Angular-reactive table instance.
|
|
1088
|
+
*
|
|
1089
|
+
* The initializer is intentionally re-evaluated whenever any signal read inside it changes.
|
|
1090
|
+
* This is how the adapter keeps the table in sync with Angular's reactivity model.
|
|
1091
|
+
*
|
|
1092
|
+
* Because of that behavior, keep expensive/static values (for example `columns`, feature setup, row models)
|
|
1093
|
+
* as stable references outside the initializer, and only read reactive state (`data()`, pagination/filter/sorting signals, etc.)
|
|
1094
|
+
* inside it.
|
|
1095
|
+
*
|
|
1096
|
+
* The returned table is also signal-reactive: table state and table APIs are wired for Angular signals, so you can safely consume table methods inside `computed(...)` and `effect(...)`.
|
|
1097
|
+
*
|
|
1098
|
+
* @example
|
|
1099
|
+
* 1. Register the table features you need
|
|
1100
|
+
* ```ts
|
|
1101
|
+
* // Register only the features you need
|
|
1102
|
+
* import {tableFeatures, rowPaginationFeature} from '@tanstack/angular-table';
|
|
1103
|
+
* const _features = tableFeatures({
|
|
1104
|
+
* rowPaginationFeature,
|
|
1105
|
+
* // ...all other features you need
|
|
1106
|
+
* })
|
|
1107
|
+
*
|
|
1108
|
+
* // Use all table core features
|
|
1109
|
+
* import {stockFeatures} from '@tanstack/angular-table';
|
|
1110
|
+
* const _features = tableFeatures(stockFeatures);
|
|
1111
|
+
* ```
|
|
1112
|
+
* 2. Prepare the table columns
|
|
1113
|
+
* ```ts
|
|
1114
|
+
* import {ColumnDef} from '@tanstack/angular-table';
|
|
1115
|
+
*
|
|
1116
|
+
* type MyData = {}
|
|
1117
|
+
*
|
|
1118
|
+
* const columns: ColumnDef<typeof _features, MyData>[] = [
|
|
1119
|
+
* // ...column definitions
|
|
1120
|
+
* ]
|
|
1121
|
+
*
|
|
1122
|
+
* // or using createColumnHelper
|
|
1123
|
+
* import {createColumnHelper} from '@tanstack/angular-table';
|
|
1124
|
+
* const columnHelper = createColumnHelper<typeof _features, MyData>();
|
|
1125
|
+
* const columns = columnHelper.columns([
|
|
1126
|
+
* columnHelper.accessor(...),
|
|
1127
|
+
* // ...other columns
|
|
1128
|
+
* ])
|
|
1129
|
+
* ```
|
|
1130
|
+
* 3. Create the table instance with `injectTable`
|
|
1131
|
+
* ```ts
|
|
1132
|
+
* const table = injectTable(() => {
|
|
1133
|
+
* // ...table options,
|
|
1134
|
+
* _features,
|
|
1135
|
+
* columns: columns,
|
|
1136
|
+
* data: myDataSignal(),
|
|
1137
|
+
* })
|
|
1138
|
+
* ```
|
|
1139
|
+
*
|
|
1140
|
+
* @returns An Angular-reactive TanStack Table instance.
|
|
103
1141
|
*/
|
|
104
|
-
function
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
1142
|
+
function injectTable(options, selector = (state) => state) {
|
|
1143
|
+
assertInInjectionContext(injectTable);
|
|
1144
|
+
const injector = inject(Injector);
|
|
1145
|
+
const stateNotifier = signal(0, ...(ngDevMode ? [{ debugName: "stateNotifier" }] : /* istanbul ignore next */ []));
|
|
1146
|
+
const angularReactivityFeature = constructReactivityFeature({
|
|
1147
|
+
stateNotifier: () => stateNotifier(),
|
|
1148
|
+
});
|
|
1149
|
+
return lazyInit(() => {
|
|
1150
|
+
const resolvedOptions = {
|
|
1151
|
+
...options(),
|
|
1152
|
+
_features: {
|
|
1153
|
+
...options()._features,
|
|
1154
|
+
angularReactivityFeature,
|
|
1155
|
+
},
|
|
1156
|
+
};
|
|
1157
|
+
const table = constructTable(resolvedOptions);
|
|
1158
|
+
const tableState = injectSelector(table.store, (state) => state, {
|
|
1159
|
+
injector,
|
|
110
1160
|
});
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return (...argsArray) => {
|
|
114
|
-
const serializedArgs = serializeArgs(...argsArray);
|
|
115
|
-
if (computedCache.hasOwnProperty(serializedArgs)) {
|
|
116
|
-
return computedCache[serializedArgs]?.();
|
|
117
|
-
}
|
|
118
|
-
const computedSignal = computed(() => {
|
|
119
|
-
void signal();
|
|
120
|
-
return fn(...argsArray);
|
|
1161
|
+
const tableOptions = injectSelector(table.optionsStore, (state) => state, {
|
|
1162
|
+
injector,
|
|
121
1163
|
});
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
1164
|
+
const updatedOptions = computed(() => {
|
|
1165
|
+
const tableOptionsValue = options();
|
|
1166
|
+
const result = {
|
|
1167
|
+
...untracked(() => table.options),
|
|
1168
|
+
...tableOptionsValue,
|
|
1169
|
+
_features: { ...tableOptionsValue._features, angularReactivityFeature },
|
|
1170
|
+
};
|
|
1171
|
+
if (tableOptionsValue.state) {
|
|
1172
|
+
result.state = tableOptionsValue.state;
|
|
1173
|
+
}
|
|
1174
|
+
return result;
|
|
1175
|
+
}, ...(ngDevMode ? [{ debugName: "updatedOptions" }] : /* istanbul ignore next */ []));
|
|
1176
|
+
effect(() => {
|
|
1177
|
+
const newOptions = updatedOptions();
|
|
1178
|
+
untracked(() => table.setOptions(newOptions));
|
|
1179
|
+
}, { injector, debugName: 'tableOptionsUpdate' });
|
|
1180
|
+
let isMount = true;
|
|
1181
|
+
effect(() => {
|
|
1182
|
+
void [tableOptions(), tableState()];
|
|
1183
|
+
if (!isMount)
|
|
1184
|
+
untracked(() => stateNotifier.update((n) => n + 1));
|
|
1185
|
+
isMount && (isMount = false);
|
|
1186
|
+
}, { injector, debugName: 'tableStateNotifier' });
|
|
1187
|
+
const computedFn = function computedSubscribe(props) {
|
|
1188
|
+
if (props.source !== undefined) {
|
|
1189
|
+
return injectSelector(props.source, props.selector ?? ((value) => value), {
|
|
1190
|
+
injector,
|
|
1191
|
+
...(props.equal && { compare: props.equal }),
|
|
1192
|
+
});
|
|
1193
|
+
}
|
|
1194
|
+
return injectSelector(table.store, props.selector, {
|
|
1195
|
+
injector,
|
|
1196
|
+
...(props.equal && { compare: props.equal }),
|
|
1197
|
+
});
|
|
1198
|
+
};
|
|
1199
|
+
table.computed = computedFn;
|
|
1200
|
+
table.Subscribe = computedFn;
|
|
1201
|
+
Object.defineProperty(table, 'state', {
|
|
1202
|
+
value: injectSelector(table.store, selector, { injector }),
|
|
1203
|
+
});
|
|
1204
|
+
Object.defineProperty(table, 'value', {
|
|
1205
|
+
value: computed(() => {
|
|
1206
|
+
tableOptions();
|
|
1207
|
+
tableState();
|
|
1208
|
+
return table;
|
|
1209
|
+
}),
|
|
1210
|
+
});
|
|
1211
|
+
return table;
|
|
1212
|
+
});
|
|
128
1213
|
}
|
|
129
1214
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
content = undefined;
|
|
134
|
-
props = {};
|
|
135
|
-
injector = inject(Injector);
|
|
136
|
-
constructor(viewContainerRef, templateRef) {
|
|
137
|
-
this.viewContainerRef = viewContainerRef;
|
|
138
|
-
this.templateRef = templateRef;
|
|
139
|
-
}
|
|
140
|
-
ref = null;
|
|
141
|
-
ngOnInit() {
|
|
142
|
-
this.ref = this.render();
|
|
143
|
-
}
|
|
144
|
-
ngDoCheck() {
|
|
145
|
-
if (this.ref instanceof ComponentRef) {
|
|
146
|
-
this.ref.injector.get(ChangeDetectorRef).markForCheck();
|
|
147
|
-
}
|
|
148
|
-
else if (this.ref instanceof EmbeddedViewRef) {
|
|
149
|
-
this.ref.markForCheck();
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
render() {
|
|
153
|
-
this.viewContainerRef.clear();
|
|
154
|
-
const { content, props } = this;
|
|
155
|
-
if (!this.content) {
|
|
156
|
-
return null;
|
|
157
|
-
}
|
|
158
|
-
if (typeof content === 'string' || typeof content === 'number') {
|
|
159
|
-
return this.renderStringContent();
|
|
160
|
-
}
|
|
161
|
-
if (typeof content === 'function') {
|
|
162
|
-
return this.renderContent(content(props));
|
|
163
|
-
}
|
|
164
|
-
return null;
|
|
1215
|
+
function createTableHook({ tableComponents, cellComponents, headerComponents, ...defaultTableOptions }) {
|
|
1216
|
+
function injectTableContext$1() {
|
|
1217
|
+
return injectTableContext();
|
|
165
1218
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
return this.renderStringContent();
|
|
169
|
-
}
|
|
170
|
-
if (content instanceof TemplateRef) {
|
|
171
|
-
return this.viewContainerRef.createEmbeddedView(content, this.getTemplateRefContext());
|
|
172
|
-
}
|
|
173
|
-
else if (content instanceof FlexRenderComponent) {
|
|
174
|
-
return this.renderComponent(content);
|
|
175
|
-
}
|
|
176
|
-
else if (content instanceof Type) {
|
|
177
|
-
return this.renderCustomComponent(content);
|
|
178
|
-
}
|
|
179
|
-
else {
|
|
180
|
-
return null;
|
|
181
|
-
}
|
|
1219
|
+
function injectTableHeaderContext$1() {
|
|
1220
|
+
return injectTableHeaderContext();
|
|
182
1221
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
return typeof this.content === 'string' ||
|
|
186
|
-
typeof this.content === 'number'
|
|
187
|
-
? this.content
|
|
188
|
-
: this.content?.(this.props);
|
|
189
|
-
};
|
|
190
|
-
return this.viewContainerRef.createEmbeddedView(this.templateRef, {
|
|
191
|
-
get $implicit() {
|
|
192
|
-
return context();
|
|
193
|
-
},
|
|
194
|
-
});
|
|
1222
|
+
function injectTableCellContext$1() {
|
|
1223
|
+
return injectTableCellContext();
|
|
195
1224
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
const getContext = () => this.props;
|
|
199
|
-
const proxy = new Proxy(this.props, {
|
|
200
|
-
get: (_, key) => getContext()?.[key],
|
|
201
|
-
});
|
|
202
|
-
const componentInjector = Injector.create({
|
|
203
|
-
parent: injector ?? this.injector,
|
|
204
|
-
providers: [{ provide: FlexRenderComponentProps, useValue: proxy }],
|
|
205
|
-
});
|
|
206
|
-
const componentRef = this.viewContainerRef.createComponent(component, {
|
|
207
|
-
injector: componentInjector,
|
|
208
|
-
});
|
|
209
|
-
for (const prop in inputs) {
|
|
210
|
-
if (componentRef.instance?.hasOwnProperty(prop)) {
|
|
211
|
-
componentRef.setInput(prop, inputs[prop]);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
return componentRef;
|
|
1225
|
+
function injectFlexRenderHeaderContext() {
|
|
1226
|
+
return injectFlexRenderContext();
|
|
215
1227
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
injector: this.injector,
|
|
219
|
-
});
|
|
220
|
-
for (const prop in this.props) {
|
|
221
|
-
// Only signal based input can be added here
|
|
222
|
-
if (componentRef.instance?.hasOwnProperty(prop) &&
|
|
223
|
-
// @ts-ignore
|
|
224
|
-
isSignal(componentRef.instance[prop])) {
|
|
225
|
-
componentRef.setInput(prop, this.props[prop]);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
return componentRef;
|
|
1228
|
+
function injectFlexRenderCellContext() {
|
|
1229
|
+
return injectFlexRenderContext();
|
|
229
1230
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
1231
|
+
function injectAppTable(tableOptions, selector) {
|
|
1232
|
+
function appCell(cell) {
|
|
1233
|
+
return cell;
|
|
1234
|
+
}
|
|
1235
|
+
function appHeader(header) {
|
|
1236
|
+
return header;
|
|
1237
|
+
}
|
|
1238
|
+
function appFooter(footer) {
|
|
1239
|
+
return footer;
|
|
1240
|
+
}
|
|
1241
|
+
const appTableFeatures = {
|
|
1242
|
+
constructTableAPIs: (table) => {
|
|
1243
|
+
Object.assign(table, tableComponents, { appCell, appHeader, appFooter });
|
|
1244
|
+
},
|
|
1245
|
+
assignCellPrototype(prototype) {
|
|
1246
|
+
Object.assign(prototype, cellComponents);
|
|
1247
|
+
},
|
|
1248
|
+
assignHeaderPrototype(prototype) {
|
|
1249
|
+
Object.assign(prototype, headerComponents);
|
|
235
1250
|
},
|
|
236
1251
|
};
|
|
1252
|
+
return injectTable(() => {
|
|
1253
|
+
const options = {
|
|
1254
|
+
...defaultTableOptions,
|
|
1255
|
+
...tableOptions(),
|
|
1256
|
+
};
|
|
1257
|
+
options._features = { ...options._features, appTableFeatures };
|
|
1258
|
+
return options;
|
|
1259
|
+
}, selector);
|
|
237
1260
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
type: Directive,
|
|
243
|
-
args: [{
|
|
244
|
-
selector: '[flexRender]',
|
|
245
|
-
standalone: true,
|
|
246
|
-
}]
|
|
247
|
-
}], ctorParameters: () => [{ type: i0.ViewContainerRef, decorators: [{
|
|
248
|
-
type: Inject,
|
|
249
|
-
args: [ViewContainerRef]
|
|
250
|
-
}] }, { type: i0.TemplateRef, decorators: [{
|
|
251
|
-
type: Inject,
|
|
252
|
-
args: [TemplateRef]
|
|
253
|
-
}] }], propDecorators: { content: [{
|
|
254
|
-
type: Input,
|
|
255
|
-
args: [{ required: true, alias: 'flexRender' }]
|
|
256
|
-
}], props: [{
|
|
257
|
-
type: Input,
|
|
258
|
-
args: [{ required: true, alias: 'flexRenderProps' }]
|
|
259
|
-
}], injector: [{
|
|
260
|
-
type: Input,
|
|
261
|
-
args: [{ required: false, alias: 'flexRenderInjector' }]
|
|
262
|
-
}] } });
|
|
263
|
-
class FlexRenderComponent {
|
|
264
|
-
component;
|
|
265
|
-
inputs;
|
|
266
|
-
injector;
|
|
267
|
-
constructor(component, inputs = {}, injector) {
|
|
268
|
-
this.component = component;
|
|
269
|
-
this.inputs = inputs;
|
|
270
|
-
this.injector = injector;
|
|
1261
|
+
function createAppColumnHelper() {
|
|
1262
|
+
// The runtime implementation is the same - components are attached at render time
|
|
1263
|
+
// This cast provides the enhanced types for column definitions
|
|
1264
|
+
return createColumnHelper();
|
|
271
1265
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
1266
|
+
return {
|
|
1267
|
+
createAppColumnHelper,
|
|
1268
|
+
injectTableContext: injectTableContext$1,
|
|
1269
|
+
injectTableHeaderContext: injectTableHeaderContext$1,
|
|
1270
|
+
injectTableCellContext: injectTableCellContext$1,
|
|
1271
|
+
injectFlexRenderHeaderContext,
|
|
1272
|
+
injectFlexRenderCellContext,
|
|
1273
|
+
injectAppTable,
|
|
1274
|
+
};
|
|
276
1275
|
}
|
|
277
1276
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
// By default, manage table state here using the table's initial state
|
|
288
|
-
const state = signal(table.initialState);
|
|
289
|
-
// Compose table options using computed.
|
|
290
|
-
// This is to allow `tableSignal` to listen and set table option
|
|
291
|
-
const updatedOptions = computed(() => {
|
|
292
|
-
// listen to table state changed
|
|
293
|
-
const tableState = state();
|
|
294
|
-
// listen to input options changed
|
|
295
|
-
const tableOptions = options();
|
|
296
|
-
return {
|
|
297
|
-
...table.options,
|
|
298
|
-
...resolvedOptions,
|
|
299
|
-
...tableOptions,
|
|
300
|
-
state: { ...tableState, ...tableOptions.state },
|
|
301
|
-
onStateChange: updater => {
|
|
302
|
-
const value = updater instanceof Function ? updater(tableState) : updater;
|
|
303
|
-
state.set(value);
|
|
304
|
-
resolvedOptions.onStateChange?.(updater);
|
|
305
|
-
},
|
|
306
|
-
};
|
|
307
|
-
});
|
|
308
|
-
// convert table instance to signal for proxify to listen to any table state and options changes
|
|
309
|
-
const tableSignal = computed(() => {
|
|
310
|
-
table.setOptions(updatedOptions());
|
|
311
|
-
return table;
|
|
312
|
-
}, {
|
|
313
|
-
equal: () => false,
|
|
314
|
-
});
|
|
315
|
-
// proxify Table instance to provide ability for consumer to listen to any table state changes
|
|
316
|
-
return proxifyTable(tableSignal);
|
|
317
|
-
});
|
|
318
|
-
}
|
|
1277
|
+
/**
|
|
1278
|
+
* Constant helper to import FlexRender directives.
|
|
1279
|
+
*
|
|
1280
|
+
* You should prefer to use this constant over importing the directives separately,
|
|
1281
|
+
* as it ensures you always have the correct set of directives over library updates.
|
|
1282
|
+
*
|
|
1283
|
+
* @see {@link FlexRenderDirective} and {@link FlexRenderCell} for more details on the directives included in this export.
|
|
1284
|
+
*/
|
|
1285
|
+
const FlexRender = [FlexRenderDirective, FlexRenderCell];
|
|
319
1286
|
|
|
320
1287
|
/**
|
|
321
1288
|
* Generated bundle index. Do not edit.
|
|
322
1289
|
*/
|
|
323
1290
|
|
|
324
|
-
export {
|
|
1291
|
+
export { FlexRender, FlexRenderCell, FlexRenderComponentInstance, FlexRenderDirective, TanStackTable, TanStackTableCell, TanStackTableCellToken, TanStackTableHeader, TanStackTableHeaderToken, TanStackTableToken, createTableHook, flexRenderComponent, injectFlexRenderContext, injectTable, injectTableCellContext, injectTableContext, injectTableHeaderContext };
|
|
325
1292
|
//# sourceMappingURL=tanstack-angular-table.mjs.map
|