import { Directive, effect, inject, input } from '@angular/core' import { FormApi } from '@tanstack/form-core' import { TanStackWithFormInjectable } from './with-form-injectable' import type { FormAsyncValidateOrFn, FormValidateOrFn, } from '@tanstack/form-core' @Directive({ selector: '[tanstack-with-form]', standalone: true, providers: [TanStackWithFormInjectable], }) export class TanStackWithForm< TFormData, TOnMount extends undefined | FormValidateOrFn, TOnChange extends undefined | FormValidateOrFn, TOnChangeAsync extends undefined | FormAsyncValidateOrFn, TOnBlur extends undefined | FormValidateOrFn, TOnBlurAsync extends undefined | FormAsyncValidateOrFn, TOnSubmit extends undefined | FormValidateOrFn, TOnSubmitAsync extends undefined | FormAsyncValidateOrFn, TOnDynamic extends undefined | FormValidateOrFn, TOnDynamicAsync extends undefined | FormAsyncValidateOrFn, TOnServer extends undefined | FormAsyncValidateOrFn, TSubmitMeta, > { form = input.required< FormApi< TFormData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TOnDynamic, TOnDynamicAsync, TOnServer, TSubmitMeta > >() base = inject(TanStackWithFormInjectable) constructor() { effect(() => { this.base._form.set(this.form()) }) } }