UNPKG

signal-template-forms

Version:

A powerful, type-safe Angular forms library built with signals, providing reactive form management with excellent developer experience and performance.

90 lines (89 loc) 3.46 kB
import { Injector } from '@angular/core'; import { type RuntimeFields } from '../../../models/signal-field-types.model'; import { type SignalFormContainer } from '../../../models/signal-form.model'; import * as i0 from "@angular/core"; /** * Base directive for form input components that provides common functionality * such as validation, computed values, and options filtering. * * This directive should be extended by all form field components to provide * consistent behavior across the form system. * * @template TField - The specific field type extending RuntimeFields * @template TModel - The form model type * @template K - The field key type * * @example * ```typescript * export class FormTextFieldComponent extends BaseInputDirective< * RuntimeTextSignalField<TModel, K>, * TModel, * K * > { * // Component implementation * } * ``` */ export declare abstract class BaseInputDirective<TField extends RuntimeFields<TModel, K>, TModel extends object, K extends keyof TModel = keyof TModel> { /** * The field configuration and state */ field: import("@angular/core").InputSignal<TField>; /** * Computed form reference obtained from the field */ protected readonly form: import("@angular/core").Signal<SignalFormContainer<TModel, unknown>>; /** * Angular injector for effect management */ protected readonly injector: Injector; /** * Computed property indicating if the field is required based on validators */ protected readonly isRequired: import("@angular/core").Signal<boolean>; /** * Computed property indicating if the field should be hidden */ protected readonly isHidden: import("@angular/core").Signal<boolean>; /** * Computed property indicating if the field should be disabled */ protected readonly isDisabled: import("@angular/core").Signal<boolean>; /** * Computed property that returns filtered options for fields that support options. * For fields without options, returns an empty array. * * Applies dynamic options filtering if a dynamicOptions function is provided. */ protected readonly filteredOptions: import("@angular/core").Signal<any>; /** * Initializes the directive by setting up reactive effects for * computed values and value watching */ constructor(); /** * Sets up an effect to initialize computed values when the field is first loaded. * This only runs once to set the initial computed value. * * @private */ private initializeComputedValueEffect; /** * Sets up an effect to watch for changes in computed values and update * the field value accordingly. This runs whenever dependencies change. * * @private */ private watchComputedValueEffect; /** * Updates the field value and optionally marks it as touched and dirty. * * @param value - The new value to set * @param markTouched - Whether to mark the field as touched and dirty (default: true) * * @protected */ protected setValue<T>(value: T, markTouched?: boolean): void; static ɵfac: i0.ɵɵFactoryDeclaration<BaseInputDirective<any, any, any>, never>; static ɵdir: i0.ɵɵDirectiveDeclaration<BaseInputDirective<any, any, any>, never, never, { "field": { "alias": "field"; "required": true; "isSignal": true; }; }, {}, never, never, true, never>; }