@tanstack/angular-table 9.0.0-alpha.21 → 9.0.0-alpha.24
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.
|
@@ -5,26 +5,24 @@ import {
|
|
|
5
5
|
runInInjectionContext,
|
|
6
6
|
untracked,
|
|
7
7
|
} from '@angular/core'
|
|
8
|
-
import { TanStackTableToken } from '../helpers/table'
|
|
9
8
|
import { TanStackTableCellToken } from '../helpers/cell'
|
|
10
9
|
import { TanStackTableHeaderToken } from '../helpers/header'
|
|
10
|
+
import { TanStackTableToken } from '../helpers/table'
|
|
11
11
|
import { FlexRenderComponentProps } from './context'
|
|
12
12
|
import { FlexRenderFlags } from './flags'
|
|
13
|
+
import { flexRenderComponent } from './flexRenderComponent'
|
|
14
|
+
import { FlexRenderComponentFactory } from './flexRenderComponentFactory'
|
|
13
15
|
import {
|
|
14
16
|
FlexRenderComponentView,
|
|
15
17
|
FlexRenderTemplateView,
|
|
16
18
|
mapToFlexRenderTypedContent,
|
|
17
19
|
} from './view'
|
|
18
|
-
import { flexRenderComponent } from './flexRenderComponent'
|
|
19
|
-
import { FlexRenderComponentFactory } from './flexRenderComponentFactory'
|
|
20
|
-
import type { FlexRenderComponent } from './flexRenderComponent'
|
|
21
20
|
import type {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
} from '
|
|
27
|
-
import type { FlexRenderTypedContent, FlexRenderView } from './view'
|
|
21
|
+
FlexRenderTypedContent,
|
|
22
|
+
FlexRenderView,
|
|
23
|
+
FlexRenderViewAllowedType,
|
|
24
|
+
} from './view'
|
|
25
|
+
import type { FlexRenderComponent } from './flexRenderComponent'
|
|
28
26
|
import type {
|
|
29
27
|
CellContext,
|
|
30
28
|
CellData,
|
|
@@ -32,6 +30,12 @@ import type {
|
|
|
32
30
|
RowData,
|
|
33
31
|
TableFeatures,
|
|
34
32
|
} from '@tanstack/table-core'
|
|
33
|
+
import type {
|
|
34
|
+
EffectRef,
|
|
35
|
+
TemplateRef,
|
|
36
|
+
Type,
|
|
37
|
+
ViewContainerRef,
|
|
38
|
+
} from '@angular/core'
|
|
35
39
|
|
|
36
40
|
/**
|
|
37
41
|
* Content supported by the `flexRender` directive when declaring
|
|
@@ -106,7 +110,10 @@ export class FlexViewRenderer<
|
|
|
106
110
|
| HeaderContext<TFeatures, TRowData, TValue>,
|
|
107
111
|
> {
|
|
108
112
|
#renderFlags = FlexRenderFlags.ViewFirstRender
|
|
109
|
-
#renderView: FlexRenderView<
|
|
113
|
+
#renderView: FlexRenderView<
|
|
114
|
+
FlexRenderViewAllowedType,
|
|
115
|
+
FlexRenderTypedContent
|
|
116
|
+
> | null = null
|
|
110
117
|
#currentRenderEffectRef: EffectRef | null = null
|
|
111
118
|
#content: () => FlexRenderInputContent<TProps>
|
|
112
119
|
#props: () => TProps
|
|
@@ -257,18 +264,21 @@ export class FlexViewRenderer<
|
|
|
257
264
|
if (latestContent.kind === 'null' || !this.#renderView) {
|
|
258
265
|
this.#renderFlags |= FlexRenderFlags.ContentChanged
|
|
259
266
|
} else {
|
|
260
|
-
this.#renderView.content
|
|
261
|
-
|
|
262
|
-
|
|
267
|
+
const { kind: currentKind } = this.#renderView.content
|
|
268
|
+
if (
|
|
269
|
+
latestContent.kind !== currentKind ||
|
|
270
|
+
!this.#renderView.eq(latestContent)
|
|
271
|
+
) {
|
|
263
272
|
this.#renderFlags |= FlexRenderFlags.ContentChanged
|
|
264
273
|
}
|
|
274
|
+
this.#renderView.content = latestContent
|
|
265
275
|
}
|
|
266
276
|
this.#update()
|
|
267
277
|
}
|
|
268
278
|
|
|
269
279
|
#renderViewByContent(
|
|
270
280
|
content: FlexRenderTypedContent,
|
|
271
|
-
): FlexRenderView<
|
|
281
|
+
): FlexRenderView<FlexRenderViewAllowedType, FlexRenderTypedContent> | null {
|
|
272
282
|
if (content.kind === 'primitive') {
|
|
273
283
|
return this.#renderStringContent(content)
|
|
274
284
|
} else if (content.kind === 'templateRef') {
|
package/src/flex-render/view.ts
CHANGED
|
@@ -35,8 +35,14 @@ export function mapToFlexRenderTypedContent(
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
export type FlexRenderViewAllowedType =
|
|
39
|
+
| FlexRenderComponentRef<any>
|
|
40
|
+
| EmbeddedViewRef<unknown>
|
|
41
|
+
| null
|
|
42
|
+
|
|
38
43
|
export abstract class FlexRenderView<
|
|
39
|
-
TView extends
|
|
44
|
+
TView extends FlexRenderViewAllowedType,
|
|
45
|
+
TContent extends FlexRenderTypedContent,
|
|
40
46
|
> {
|
|
41
47
|
readonly view: TView
|
|
42
48
|
#previousContent: FlexRenderTypedContent | undefined
|
|
@@ -69,11 +75,14 @@ export abstract class FlexRenderView<
|
|
|
69
75
|
|
|
70
76
|
abstract onDestroy(callback: Function): void
|
|
71
77
|
|
|
78
|
+
abstract eq(view: TContent): boolean
|
|
79
|
+
|
|
72
80
|
abstract unmount(): void
|
|
73
81
|
}
|
|
74
82
|
|
|
75
83
|
export class FlexRenderTemplateView extends FlexRenderView<
|
|
76
|
-
EmbeddedViewRef<unknown
|
|
84
|
+
EmbeddedViewRef<unknown>,
|
|
85
|
+
Extract<FlexRenderTypedContent, { kind: 'primitive' | 'templateRef' }>
|
|
77
86
|
> {
|
|
78
87
|
constructor(
|
|
79
88
|
initialContent: Extract<
|
|
@@ -105,10 +114,27 @@ export class FlexRenderTemplateView extends FlexRenderView<
|
|
|
105
114
|
override onDestroy(callback: Function) {
|
|
106
115
|
this.view.onDestroy(callback)
|
|
107
116
|
}
|
|
117
|
+
|
|
118
|
+
override eq(
|
|
119
|
+
compare: Extract<
|
|
120
|
+
FlexRenderTypedContent,
|
|
121
|
+
{ kind: 'primitive' | 'templateRef' }
|
|
122
|
+
>,
|
|
123
|
+
): boolean {
|
|
124
|
+
return (
|
|
125
|
+
(this.content.kind === 'primitive' &&
|
|
126
|
+
compare.kind === 'primitive' &&
|
|
127
|
+
this.content.content === compare.content) ||
|
|
128
|
+
(this.content.kind === 'templateRef' &&
|
|
129
|
+
compare.kind === 'templateRef' &&
|
|
130
|
+
this.content.content === compare.content)
|
|
131
|
+
)
|
|
132
|
+
}
|
|
108
133
|
}
|
|
109
134
|
|
|
110
135
|
export class FlexRenderComponentView extends FlexRenderView<
|
|
111
|
-
FlexRenderComponentRef<unknown
|
|
136
|
+
FlexRenderComponentRef<unknown>,
|
|
137
|
+
Extract<FlexRenderTypedContent, { kind: 'component' | 'flexRenderComponent' }>
|
|
112
138
|
> {
|
|
113
139
|
constructor(
|
|
114
140
|
initialContent: Extract<
|
|
@@ -162,4 +188,20 @@ export class FlexRenderComponentView extends FlexRenderView<
|
|
|
162
188
|
override onDestroy(callback: Function) {
|
|
163
189
|
this.view.componentRef.onDestroy(callback)
|
|
164
190
|
}
|
|
191
|
+
|
|
192
|
+
override eq(
|
|
193
|
+
compare: Extract<
|
|
194
|
+
FlexRenderTypedContent,
|
|
195
|
+
{ kind: 'component' | 'flexRenderComponent' }
|
|
196
|
+
>,
|
|
197
|
+
): boolean {
|
|
198
|
+
return (
|
|
199
|
+
(this.content.kind === 'component' &&
|
|
200
|
+
compare.kind === 'component' &&
|
|
201
|
+
this.content.content === compare.content) ||
|
|
202
|
+
(this.content.kind === 'flexRenderComponent' &&
|
|
203
|
+
compare.kind === 'flexRenderComponent' &&
|
|
204
|
+
this.content.content.component === compare.content.component)
|
|
205
|
+
)
|
|
206
|
+
}
|
|
165
207
|
}
|