@tanstack/angular-table 9.0.0-alpha.10 → 9.0.0-alpha.12

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/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@tanstack/angular-table",
3
- "version": "9.0.0-alpha.10",
3
+ "version": "9.0.0-alpha.12",
4
4
  "description": "Headless UI for building powerful tables & datagrids for Angular.",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "https://github.com/TanStack/table.git",
9
+ "url": "git+https://github.com/TanStack/table.git",
10
10
  "directory": "packages/angular-table"
11
11
  },
12
12
  "homepage": "https://tanstack.com/table",
@@ -21,13 +21,11 @@
21
21
  "datagrid"
22
22
  ],
23
23
  "type": "module",
24
- "module": "dist/esm2022/index.mjs",
25
- "types": "dist/index.d.ts",
24
+ "module": "dist/fesm2022/tanstack-angular-table.mjs",
25
+ "types": "dist/types/tanstack-angular-table.d.ts",
26
26
  "exports": {
27
27
  ".": {
28
- "types": "./dist/index.d.ts",
29
- "esm": "./dist/esm2022/index.mjs",
30
- "esm2022": "./dist/esm2022/index.mjs",
28
+ "types": "./dist/types/tanstack-angular-table.d.ts",
31
29
  "default": "./dist/fesm2022/tanstack-angular-table.mjs"
32
30
  },
33
31
  "./package.json": {
@@ -35,26 +33,38 @@
35
33
  }
36
34
  },
37
35
  "engines": {
38
- "node": ">=12"
36
+ "node": ">=18"
39
37
  },
40
38
  "files": [
41
39
  "dist",
42
40
  "src"
43
41
  ],
44
42
  "dependencies": {
45
- "tslib": "^2.6.3",
46
- "@tanstack/table-core": "9.0.0-alpha.10"
43
+ "@tanstack/angular-store": "^0.9.1",
44
+ "tslib": "^2.8.1",
45
+ "@tanstack/table-core": "9.0.0-alpha.12"
47
46
  },
48
47
  "devDependencies": {
49
- "@analogjs/vite-plugin-angular": "^1.5.0",
50
- "@angular/core": "^18.0.3",
51
- "@angular/platform-browser": "^18.0.3",
52
- "@angular/platform-browser-dynamic": "^18.0.3",
53
- "ng-packagr": "^18.0.0"
48
+ "@analogjs/vite-plugin-angular": "^2.2.2",
49
+ "@analogjs/vitest-angular": "^2.2.2",
50
+ "@angular/core": "^21.1.1",
51
+ "@angular/platform-browser": "^21.1.1",
52
+ "ng-packagr": "^21.1.0",
53
+ "typescript": "5.9.3"
54
54
  },
55
55
  "peerDependencies": {
56
- "@angular/core": ">=17"
56
+ "@angular/core": ">=19"
57
57
  },
58
58
  "sideEffects": false,
59
- "scripts": {}
59
+ "scripts": {
60
+ "build": "ng-packagr -p ng-package.json -c tsconfig.build.json && rimraf ./dist/package.json",
61
+ "build:types": "tsc --emitDeclarationOnly",
62
+ "clean": "rimraf ./build && rimraf ./dist",
63
+ "test:build": "publint --strict",
64
+ "test:eslint": "eslint ./src",
65
+ "test:lib": "vitest",
66
+ "test:benchmark": "vitest bench",
67
+ "test:lib:dev": "vitest --watch",
68
+ "test:types": "tsc && vitest --typecheck"
69
+ }
60
70
  }
@@ -0,0 +1,231 @@
1
+ import { computed, signal } from '@angular/core'
2
+ import { setReactivePropertiesOnObject } from './reactivityUtils'
3
+ import type { Signal } from '@angular/core'
4
+ import type {
5
+ RowData,
6
+ Table,
7
+ TableFeature,
8
+ TableFeatures,
9
+ } from '@tanstack/table-core'
10
+
11
+ declare module '@tanstack/table-core' {
12
+ interface TableOptions_Plugins<
13
+ TFeatures extends TableFeatures,
14
+ TData extends RowData,
15
+ > extends TableOptions_AngularReactivity {}
16
+
17
+ interface Table_Plugins<
18
+ TFeatures extends TableFeatures,
19
+ TData extends RowData,
20
+ > extends Table_AngularReactivity<TFeatures, TData> {}
21
+ }
22
+
23
+ /**
24
+ * Predicate used to skip/ignore a property name when applying Angular reactivity.
25
+ *
26
+ * Returning `true` means the property should NOT be wrapped/made reactive.
27
+ */
28
+ type SkipPropertyFn = (property: string) => boolean
29
+
30
+ /**
31
+ * Fine-grained configuration for Angular reactivity.
32
+ *
33
+ * Each key controls whether prototype methods/getters on the corresponding TanStack Table
34
+ * objects are wrapped with signal-aware access.
35
+ *
36
+ * - `true` enables wrapping using the default skip rules.
37
+ * - `false` disables wrapping entirely for that object type.
38
+ * - a function allows customizing the skip rules (see {@link SkipPropertyFn}).
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * const table = injectTable(() => {
43
+ * // ...table options,
44
+ * reactivity: {
45
+ * // fine-grained control over which table objects have reactive properties,
46
+ * // and which properties are wrapped
47
+ * header: true,
48
+ * column: true,
49
+ * row: true,
50
+ * cell: true,
51
+ * }
52
+ * })
53
+ * ```
54
+ */
55
+ export interface AngularReactivityFlags {
56
+ /** Controls reactive wrapping for `Header` instances. */
57
+ header: boolean | SkipPropertyFn
58
+ /** Controls reactive wrapping for `Column` instances. */
59
+ column: boolean | SkipPropertyFn
60
+ /** Controls reactive wrapping for `Row` instances. */
61
+ row: boolean | SkipPropertyFn
62
+ /** Controls reactive wrapping for `Cell` instances. */
63
+ cell: boolean | SkipPropertyFn
64
+ }
65
+
66
+ /**
67
+ * Table option extension for Angular reactivity.
68
+ *
69
+ * Available on `createTable` options via module augmentation in this file.
70
+ */
71
+ interface TableOptions_AngularReactivity {
72
+ /**
73
+ * Enables/disables and configures Angular reactivity on table-related prototypes.
74
+ *
75
+ * If omitted, defaults are provided by the feature.
76
+ */
77
+ reactivity?: Partial<AngularReactivityFlags>
78
+ }
79
+
80
+ /**
81
+ * Table API extension for Angular reactivity.
82
+ *
83
+ * Added to the table instance via module augmentation.
84
+ */
85
+ interface Table_AngularReactivity<
86
+ TFeatures extends TableFeatures,
87
+ TData extends RowData,
88
+ > {
89
+ /**
90
+ * Returns a table signal that updates whenever the table state or options changes.
91
+ */
92
+ get: Signal<Table<TFeatures, TData>>
93
+ /**
94
+ * Sets the reactive notifier that powers {@link get}.
95
+ *
96
+ * @internal Used by the Angular table adapter to connect its notifier to the core table.
97
+ */
98
+ setTableNotifier: (signal: Signal<Table<TFeatures, TData>>) => void
99
+ }
100
+
101
+ /**
102
+ * Type map describing what this feature adds to TanStack Table constructors.
103
+ */
104
+ interface AngularReactivityFeatureConstructors<
105
+ TFeatures extends TableFeatures,
106
+ TData extends RowData,
107
+ > {
108
+ TableOptions: TableOptions_AngularReactivity
109
+ Table: Table_AngularReactivity<TFeatures, TData>
110
+ }
111
+
112
+ /**
113
+ * Resolves the user-provided `reactivity.*` config to a skip predicate.
114
+ *
115
+ * - `false` is handled by callers (feature method returns early)
116
+ * - `true` selects the default predicate
117
+ * - a function overrides the default predicate
118
+ */
119
+ const getUserSkipPropertyFn = (
120
+ value: undefined | null | boolean | SkipPropertyFn,
121
+ defaultPropertyFn: SkipPropertyFn,
122
+ ) => {
123
+ if (typeof value === 'boolean') {
124
+ return defaultPropertyFn
125
+ }
126
+
127
+ return value ?? defaultPropertyFn
128
+ }
129
+
130
+ function constructAngularReactivityFeature<
131
+ TFeatures extends TableFeatures,
132
+ TData extends RowData,
133
+ >(): TableFeature<AngularReactivityFeatureConstructors<TFeatures, TData>> {
134
+ return {
135
+ getDefaultTableOptions(table) {
136
+ return {
137
+ reactivity: {
138
+ header: true,
139
+ column: true,
140
+ row: true,
141
+ cell: true,
142
+ },
143
+ }
144
+ },
145
+ constructTableAPIs: (table) => {
146
+ const rootNotifier = signal<Signal<any> | null>(null)
147
+ table.setTableNotifier = (notifier) => rootNotifier.set(notifier)
148
+ table.get = computed(() => rootNotifier()!(), { equal: () => false })
149
+ setReactivePropertiesOnObject(table.get, table, {
150
+ overridePrototype: false,
151
+ skipProperty: skipBaseProperties,
152
+ })
153
+ },
154
+
155
+ assignCellPrototype: (prototype, table) => {
156
+ if (table.options.reactivity?.cell === false) {
157
+ return
158
+ }
159
+ setReactivePropertiesOnObject(table.get, prototype, {
160
+ skipProperty: getUserSkipPropertyFn(
161
+ table.options.reactivity?.cell,
162
+ skipBaseProperties,
163
+ ),
164
+ overridePrototype: true,
165
+ })
166
+ },
167
+
168
+ assignColumnPrototype: (prototype, table) => {
169
+ if (table.options.reactivity?.column === false) {
170
+ return
171
+ }
172
+ setReactivePropertiesOnObject(table.get, prototype, {
173
+ skipProperty: getUserSkipPropertyFn(
174
+ table.options.reactivity?.cell,
175
+ skipBaseProperties,
176
+ ),
177
+ overridePrototype: true,
178
+ })
179
+ },
180
+
181
+ assignHeaderPrototype: (prototype, table) => {
182
+ if (table.options.reactivity?.header === false) {
183
+ return
184
+ }
185
+ setReactivePropertiesOnObject(table.get, prototype, {
186
+ skipProperty: getUserSkipPropertyFn(
187
+ table.options.reactivity?.cell,
188
+ skipBaseProperties,
189
+ ),
190
+ overridePrototype: true,
191
+ })
192
+ },
193
+
194
+ assignRowPrototype: (prototype, table) => {
195
+ if (table.options.reactivity?.row === false) {
196
+ return
197
+ }
198
+ setReactivePropertiesOnObject(table.get, prototype, {
199
+ skipProperty: getUserSkipPropertyFn(
200
+ table.options.reactivity?.cell,
201
+ skipBaseProperties,
202
+ ),
203
+ overridePrototype: true,
204
+ })
205
+ },
206
+ }
207
+ }
208
+
209
+ /**
210
+ * Angular reactivity feature that add reactive signal supports in table core instance.
211
+ * This is used internally by the Angular table adapter `injectTable`.
212
+ *
213
+ * @private
214
+ */
215
+ export const angularReactivityFeature = constructAngularReactivityFeature()
216
+
217
+ /**
218
+ * Default predicate used to skip base/non-reactive properties.
219
+ */
220
+ function skipBaseProperties(property: string): boolean {
221
+ return (
222
+ // equals `getContext`
223
+ property === 'getContext' ||
224
+ // start with `_`
225
+ property[0] === '_' ||
226
+ // doesn't start with `get`, but faster
227
+ !(property[0] === 'g' && property[1] === 'e' && property[2] === 't') ||
228
+ // ends with `Handler`
229
+ property.endsWith('Handler')
230
+ )
231
+ }
@@ -0,0 +1,14 @@
1
+ import { InjectionToken, inject } from '@angular/core'
2
+
3
+ export const FlexRenderComponentProps = new InjectionToken<
4
+ NonNullable<unknown>
5
+ >('[@tanstack/angular-table] Flex render component context props')
6
+
7
+ /**
8
+ * Inject the flex render context props.
9
+ *
10
+ * Can be used in components rendered via FlexRender directives.
11
+ */
12
+ export function injectFlexRenderContext<T extends NonNullable<unknown>>(): T {
13
+ return inject<T>(FlexRenderComponentProps)
14
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Flags used to manage and optimize the rendering lifecycle of the content of the cell
3
+ * while using {@link FlexViewRenderer}.
4
+ */
5
+ export const FlexRenderFlags = {
6
+ /**
7
+ * Indicates that the view is being created for the first time or will be cleared during the next update phase.
8
+ * This is the initial state and will transition after the first ngDoCheck.
9
+ */
10
+ ViewFirstRender: 1 << 0,
11
+ /**
12
+ * Indicates the `content` property has been modified or the view requires a complete re-render.
13
+ * When this flag is enabled, the view will be cleared and recreated from scratch.
14
+ */
15
+ ContentChanged: 1 << 1,
16
+ /**
17
+ * Indicates that the `props` property reference has changed.
18
+ * When this flag is enabled, the view context is updated based on the type of the content.
19
+ *
20
+ * For Component view, inputs will be updated and view will be marked as dirty.
21
+ * For TemplateRef and primitive values, view will be marked as dirty
22
+ */
23
+ PropsReferenceChanged: 1 << 2,
24
+ /**
25
+ * Indicates that the current rendered view needs to be checked for changes.
26
+ * This will be set to true when `content(props)` result has changed or during
27
+ * forced update
28
+ */
29
+ Dirty: 1 << 3,
30
+ /**
31
+ * Indicates that the first render effect has been checked at least one time.
32
+ */
33
+ RenderEffectChecked: 1 << 4,
34
+ } as const
@@ -0,0 +1,288 @@
1
+ import { reflectComponentType } from '@angular/core'
2
+ import type {
3
+ Binding,
4
+ ComponentMirror,
5
+ Injector,
6
+ InputSignal,
7
+ OutputEmitterRef,
8
+ Type,
9
+ createComponent,
10
+ } from '@angular/core'
11
+
12
+ type CreateComponentOptions = Parameters<typeof createComponent>[1]
13
+ type CreateComponentBindings = CreateComponentOptions['bindings']
14
+ type CreateComponentDirectives = CreateComponentOptions['directives']
15
+
16
+ interface FlexRenderOptions<
17
+ TInputs extends Record<string, any>,
18
+ TOutputs extends Record<string, any>,
19
+ > {
20
+ /**
21
+ * Native Angular bindings applied at component creation time via `createComponent`.
22
+ * Use this option to set inputs, outputs, or two-way bindings at creation time.
23
+ * Shouldn't be used together with {@link FlexRenderOptions#inputs} or {@link FlexRenderOptions#outputs} option.
24
+ *
25
+ * Binding input/outputs at creation time: {@link https://angular.dev/guide/components/programmatic-rendering#binding-inputs-outputs-and-setting-host-directives-at-creation}
26
+ *
27
+ * Two-way binding: {@link https://angular.dev/api/core/twoWayBinding}
28
+ *
29
+ * Output binding: {@link https://angular.dev/api/core/outputBinding}
30
+ *
31
+ * Input binding: {@link https://angular.dev/api/core/inputBinding}
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * import {flexRenderComponent} from '@tanstack/angular-table';
36
+ * flexRenderComponent(MyComponent, {
37
+ * bindings: [
38
+ * // Will update `value` input every time `mySignalValue` changes
39
+ * inputBinding('value', mySignalValue),
40
+ * // Set myProperty to 1 when the component is created
41
+ * inputBinding('myProperty', () => 1),
42
+ * // Callback called every time `valueChange` output emit
43
+ * outputBinding('valueChange', value => {
44
+ * console.log("my value changed to", value)
45
+ * }),
46
+ * // Two-way binding between `value` input and `valueChange` output
47
+ * // Useful while using `model` inputs.
48
+ * twoWayBinding('value', mySignal)
49
+ * ]
50
+ * })
51
+ * ```
52
+ */
53
+ readonly bindings?: Array<Binding>
54
+ /**
55
+ * Directives to apply to the component at creation time.
56
+ *
57
+ * Binding directives at creation time: {@link https://angular.dev/guide/components/programmatic-rendering#binding-inputs-outputs-and-setting-host-directives-at-creation}
58
+ *
59
+ * Two-way binding: {@link https://angular.dev/api/core/twoWayBinding}
60
+ *
61
+ * Output binding: {@link https://angular.dev/api/core/outputBinding}
62
+ *
63
+ * Input binding: {@link https://angular.dev/api/core/inputBinding}
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * import {flexRenderComponent} from '@tanstack/angular-table';
68
+ * flexRenderComponent(MyComponent, {
69
+ * bindings: [
70
+ * // ...
71
+ * ],
72
+ * directives: [
73
+ * DirectiveA,
74
+ * {
75
+ * type: DirectiveB,
76
+ * bindings: [
77
+ * inputBinding('value', mySignalValue),
78
+ * // ...
79
+ * ]
80
+ * }
81
+ * ]
82
+ * })
83
+ * ```
84
+ */
85
+ readonly directives?: CreateComponentDirectives
86
+ /**
87
+ * Component instance inputs.
88
+ *
89
+ * These values are assigned after the component has been created using
90
+ * [componentRef.setInput API](https://angular.dev/api/core/ComponentRef#setInput).
91
+ *
92
+ * Shouldn't be used together with {@link FlexRenderOptions#bindings} option
93
+ */
94
+ readonly inputs?: TInputs
95
+ /**
96
+ * Component instance outputs.
97
+ *
98
+ * Outputs are wired imperatively after component creation using {@link OutputEmitterRef#subscribe}.
99
+ *
100
+ * Shouldn't be used together with {@link FlexRenderOptions#bindings} option
101
+ */
102
+ readonly outputs?: TOutputs
103
+ /**
104
+ * Optional {@link Injector} that will be used when rendering the component
105
+ */
106
+ readonly injector?: Injector
107
+ }
108
+
109
+ type Inputs<T> = {
110
+ [K in keyof T as T[K] extends InputSignal<infer R>
111
+ ? K
112
+ : never]?: T[K] extends InputSignal<infer R> ? R : never
113
+ }
114
+
115
+ type Outputs<T> = {
116
+ [K in keyof T as T[K] extends OutputEmitterRef<infer R>
117
+ ? K
118
+ : never]?: T[K] extends OutputEmitterRef<infer R>
119
+ ? OutputEmitterRef<R>['emit']
120
+ : never
121
+ }
122
+
123
+ /**
124
+ * Helper function to create a {@link FlexRenderComponent} instance, with better type-safety.
125
+ *
126
+ * @example
127
+ * ```ts
128
+ * import {flexRenderComponent} from '@tanstack/angular-table'
129
+ * import {inputBinding, outputBinding} from '@angular/core';
130
+ *
131
+ * const columns = [
132
+ * {
133
+ * cell: ({ row }) => {
134
+ * return flexRenderComponent(MyComponent, {
135
+ * inputs: { value: mySignalValue() },
136
+ * outputs: { valueChange: (val) => {} }
137
+ * // or using angular native createComponent#binding api
138
+ * bindings: [
139
+ * inputBinding('value', mySignalValue),
140
+ * outputBinding('valueChange', value => {
141
+ * console.log("my value changed to", value)
142
+ * })
143
+ * ]
144
+ * })
145
+ * },
146
+ * },
147
+ * ]
148
+ * ```
149
+ */
150
+ export function flexRenderComponent<TComponent = any>(
151
+ component: Type<TComponent>,
152
+ options?: FlexRenderOptions<Inputs<TComponent>, Outputs<TComponent>>,
153
+ ): FlexRenderComponent<TComponent> {
154
+ const { inputs, injector, outputs, directives, bindings } = options ?? {}
155
+ return new FlexRenderComponentInstance(
156
+ component,
157
+ inputs,
158
+ injector,
159
+ outputs,
160
+ directives,
161
+ bindings,
162
+ )
163
+ }
164
+
165
+ /**
166
+ * Wrapper interface for a component that will be used as content for {@link FlexRenderDirective}.
167
+ * Can be created using {@link flexRenderComponent} helper.
168
+ *
169
+ * @example
170
+ *
171
+ * ```ts
172
+ * import {flexRenderComponent} from '@tanstack/angular-table'
173
+ *
174
+ * // Usage in cell/header/footer definition
175
+ * const columns = [
176
+ * {
177
+ * cell: ({ row }) => {
178
+ * return flexRenderComponent(MyComponent, {
179
+ * inputs: { value: mySignalValue() },
180
+ * outputs: { valueChange: (val) => {} }
181
+ * // or using angular createComponent#bindings api
182
+ * bindings: [
183
+ * inputBinding('value', mySignalValue),
184
+ * outputBinding('valueChange', value => {
185
+ * console.log("my value changed to", value)
186
+ * })
187
+ * ]
188
+ * })
189
+ * },
190
+ * },
191
+ * ]
192
+ *
193
+ * import {input, output} from '@angular/core';
194
+ *
195
+ * @Component({
196
+ * selector: 'my-component',
197
+ * })
198
+ * class MyComponent {
199
+ * readonly value = input(0);
200
+ * readonly valueChange = output<number>();
201
+ * }
202
+ *
203
+ * ```
204
+ */
205
+ export interface FlexRenderComponent<TComponent = any> {
206
+ /**
207
+ * The component type
208
+ */
209
+ readonly component: Type<TComponent>
210
+ /**
211
+ * Reflected metadata about the component.
212
+ */
213
+ readonly mirror: ComponentMirror<TComponent>
214
+ /**
215
+ * List of allowed input names.
216
+ */
217
+ readonly allowedInputNames: Array<string>
218
+ /**
219
+ * List of allowed output names.
220
+ */
221
+ readonly allowedOutputNames: Array<string>
222
+ /**
223
+ * Component instance outputs. Subscribed via {@link OutputEmitterRef#subscribe}
224
+ *
225
+ * @see {@link FlexRenderOptions#outputs}
226
+ */
227
+ readonly outputs?: Outputs<TComponent>
228
+ /**
229
+ * Component instance inputs. Set via [componentRef.setInput API](https://angular.dev/api/core/ComponentRef#setInput))
230
+ *
231
+ * @see {@link FlexRenderOptions#inputs}
232
+ */
233
+ readonly inputs?: Inputs<TComponent>
234
+ /**
235
+ * Optional {@link Injector} that will be used when rendering the component.
236
+ *
237
+ * @see {@link FlexRenderOptions#injector}
238
+ */
239
+ readonly injector?: Injector
240
+ /**
241
+ * Bindings to apply to the root component
242
+ *
243
+ * @see {@link FlexRenderOptions#bindings}
244
+ */
245
+ bindings?: CreateComponentBindings
246
+ /**
247
+ * Directives that should be applied to the component.
248
+ *
249
+ * @see {FlexRenderOptions#directives}
250
+ */
251
+ directives?: CreateComponentDirectives
252
+ }
253
+
254
+ /**
255
+ * Wrapper class for a component that will be used as content for {@link FlexRenderDirective}
256
+ *
257
+ * Prefer {@link flexRenderComponent} helper for better type-safety
258
+ */
259
+ export class FlexRenderComponentInstance<
260
+ TComponent = any,
261
+ > implements FlexRenderComponent<TComponent> {
262
+ readonly mirror: ComponentMirror<TComponent>
263
+ readonly allowedInputNames: Array<string> = []
264
+ readonly allowedOutputNames: Array<string> = []
265
+
266
+ constructor(
267
+ readonly component: Type<TComponent>,
268
+ readonly inputs?: Inputs<TComponent>,
269
+ readonly injector?: Injector,
270
+ readonly outputs?: Outputs<TComponent>,
271
+ readonly directives?: CreateComponentDirectives,
272
+ readonly bindings?: CreateComponentBindings,
273
+ ) {
274
+ const mirror = reflectComponentType(component)
275
+ if (!mirror) {
276
+ throw new Error(
277
+ `[@tanstack-table/angular] The provided symbol is not a component`,
278
+ )
279
+ }
280
+ this.mirror = mirror
281
+ for (const input of this.mirror.inputs) {
282
+ this.allowedInputNames.push(input.propName)
283
+ }
284
+ for (const output of this.mirror.outputs) {
285
+ this.allowedOutputNames.push(output.propName)
286
+ }
287
+ }
288
+ }