import * as i0 from '@angular/core'; import { OnDestroy, ElementRef, TemplateRef, AfterContentInit, QueryList, OnInit, AfterViewInit } from '@angular/core'; import { AbstractControl, ValidationErrors } from '@angular/forms'; import * as i9 from '@odx/angular'; import { Controller } from '@odx/angular'; import * as rxjs from 'rxjs'; import { Observable, BehaviorSubject } from 'rxjs'; import { DynamicContent, DynamicTextContent } from '@odx/angular/cdk/dynamic-view'; import * as _odx_angular_utils from '@odx/angular/utils'; type CompatibleControl = Partial; interface FieldControl { control: CompatibleControl; nativeElement: HTMLElement; } /** * Provides centralized form field management for Angular applications. * This service handles the registration and management of form controls, including their disabled and read-only states, * and integrates seamlessly with Angular's forms module. It manages the state of individual form fields across the application, * ensuring that changes to the state (such as disabled or read-only) are consistently reflected in the UI. * * Extends the `Controller` class, which provides basic functionality for managing state and interactions. * The service utilizes Angular's dependency injection to access and manipulate form controls and their properties, * making it easier to maintain and update form state across complex forms. * * @extends {Controller} */ declare class FormFieldService extends Controller implements OnDestroy { private readonly disabledController; private readonly readonlyController; private readonly control$$; /** * Observable that emits the currently registered control object, which includes * both the control instance and the associated native HTML element. * * @emits {FieldControl | null} */ readonly control$: Observable; /** * Observable that emits the ID of the current control's HTML element. Generates a unique ID * if not already assigned. * * @emits {string | null} */ readonly controlId$: Observable; /** * Observable that emits the hint ID associated with the control, which is typically used for accessibility * purposes. * * @emits {string | null} */ readonly controlHintId$: Observable; /** * Observable that emits the error message ID associated with the control, * used for linking form errors for accessibility. * * @emits {string | null} */ readonly controlErrorId$: Observable; /** * Observable that emits a boolean indicating whether the control is disabled, * combining both internal state and controller state. * * @emits {boolean} */ readonly isDisabled$: Observable; /** * Observable that emits a boolean indicating whether the control is required, * based on the presence of the required attribute or validator. * * @emits {boolean} */ readonly isRequired$: Observable; /** * Observable that emits a boolean indicating whether the control is readonly, * based on the presence of the readonly attribute. * * @emits {boolean} */ readonly isReadonly$: Observable; ngOnDestroy(): void; /** * Registers a control along with its native element to the service. * * @param {AbstractControl} control - The Angular form control. * @param {ElementRef} nativeElement - The native element associated with the form control. */ registerControl(control: CompatibleControl, { nativeElement }: ElementRef): void; /** * Removes the currently registered control from the service. */ removeControl(): void; private updateControlDisabledState; private getControlDisabledState; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵprov: i0.ɵɵInjectableDeclaration; } interface FormFieldError { key: string; message: DynamicContent; context?: { $implicit: unknown; }; } type FormFieldErrorResolver = (context: C) => DynamicTextContent; interface FormFieldErrorResolvers { min?: FormFieldErrorResolver<{ min: number; actual: number; }>; max?: FormFieldErrorResolver<{ max: number; actual: number; }>; required?: FormFieldErrorResolver; requiredTrue?: FormFieldErrorResolver; email?: FormFieldErrorResolver; minlength?: FormFieldErrorResolver<{ requiredLength: number; actualLength: number; }>; maxlength?: FormFieldErrorResolver<{ requiredLength: number; actualLength: number; }>; pattern?: FormFieldErrorResolver<{ requiredPattern: string; }>; [key: string]: FormFieldErrorResolver | undefined; } type FormFieldVariant = (typeof FormFieldVariant)[keyof typeof FormFieldVariant]; declare const FormFieldVariant: { readonly FULL: "full"; readonly SIMPLE: "simple"; readonly HORIZONTAL: "horizontal"; }; /** * A component that displays form field information such as hints or error messages, providing feedback to the user. * It integrates with the `FormFieldService` to reactively update and display this information based on the state of a * form field. The component uses dynamic content loading to facilitate the rendering of custom template-driven or * reactive hints and error messages, enhancing the flexibility and reusability of form validations and user prompts. */ declare class FormFieldInfoComponent { protected readonly formFieldService: FormFieldService; /** * Input property that takes a `FormFieldError` object. This object contains detailed information about * the form field error state including the message to be displayed, the key identifier of the error, and * any contextual data that might be necessary for error resolution. * * @type {FormFieldError} * @default null */ error: FormFieldError | null; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵcmp: i0.ɵɵComponentDeclaration; } /** * Manages and resolves form field errors by integrating custom error messages and templates. * This service provides reactive observables for error states that can be used to display custom error messages in templates. * It supports both string-based error messages and Angular templates for richer error displays. */ declare class FormFieldErrorService implements OnDestroy { private readonly config; private readonly fieldError$$; private readonly customErrors$$; /** * An Observable that emits the resolved form field error based on current validations and custom errors. * It outputs either a `FormFieldError` object with a message and context or `null` if no errors are found. * * @emits {FormFieldError | null} */ readonly error$: rxjs.Observable; /** * An Observable that emits a boolean indicating whether there are any active errors. * * @emits {boolean} */ readonly hasError$: rxjs.Observable; /** * Gets a boolean indicating whether the current field has any errors. * * @returns {boolean} */ get hasError(): boolean; ngOnDestroy(): void; /** * Sets the first relevant error from the ValidationErrors object if any error matches the non-ignored error list. * * @param {ValidationErrors | null} errors ValidationErrors object containing potential errors from a form control. */ setError(errors?: ValidationErrors | null): void; /** * Registers a custom error template for a specific error key. * * @param {string | undefined} key The error key to register the custom template under. If omitted, a default key is used. * @param {TemplateRef} template A TemplateRef instance containing the Angular template to display for this error. */ registerCustomError(key: string | undefined, template: TemplateRef): void; private getFirstError; private resolveError; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵprov: i0.ɵɵInjectableDeclaration; } /** * A component that aggregates multiple form field error services to manage and display error states across * a group of form fields. It facilitates centralized error handling and dynamic updates to error messages, * making it ideal for forms with complex validation rules or multiple data entry points. * * This component dynamically listens to changes in error states from its child components and updates the * error information displayed to the user based on the most relevant error. */ declare class FormGroupComponent implements AfterContentInit { readonly element: i0.ElementRef; /** * An observable that emits the current error state of the form group. It is calculated by combining * the error states of all child form fields and selecting the most relevant error to display. * * @type {Observable | null} * @default null */ error$: Observable | null; /** * A QueryList containing all instances of FormFieldErrorService used by child components of this form group. This list * is used to subscribe to error changes in all child components and dynamically update the group's error state. * * @type {QueryList} */ formFieldErrorServices: QueryList; ngAfterContentInit(): void; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵcmp: i0.ɵɵComponentDeclaration; } /** * Represents a directive that provides control functionality for a form field. * This directive is responsible for registering the control with the form field service, * handling control changes, and managing form field attributes and error states. */ declare class FormFieldControlDirective implements OnInit, AfterViewInit, OnDestroy { private readonly ngControl; private readonly form; private readonly forceValidation$$; private readonly onFormSubmit$; private readonly formFieldService; private readonly formFieldErrorService; private readonly takeUntilDestroyed; private readonly autoSize$; readonly element: i0.ElementRef; /** * Makes a `textarea` control grow to fit content * * @type {boolean} * @default false */ readonly autoSize: i0.InputSignalWithTransform; constructor(); ngOnInit(): void; ngAfterViewInit(): void; ngOnDestroy(): void; isAutoSizeTextarea(): boolean; private resizeToContent; private resetHeight; private registerOnBlur; private registerOnStatusChange; private patchControl; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵdir: i0.ɵɵDirectiveDeclaration; } /** * Directive for displaying custom error messages in a form field. */ declare class FormFieldErrorDirective implements OnInit { private readonly formFieldErrorService; private readonly template; /** * The key used to identify the custom error message. * * @type {string | undefined} */ key?: string; ngOnInit(): void; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵdir: i0.ɵɵDirectiveDeclaration; } /** * Directive for displaying a hint within a form field. */ declare class FormFieldHintDirective { protected readonly formFieldService: FormFieldService; constructor(); static ɵfac: i0.ɵɵFactoryDeclaration; static ɵdir: i0.ɵɵDirectiveDeclaration; } /** * Directive for the label element within a form field. */ declare class FormFieldLabelDirective { readonly element: i0.ElementRef; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵdir: i0.ɵɵDirectiveDeclaration; } /** * Represents a directive for handling form-related functionality. * This directive listens for form submit and reset events, making them observable, which can be used to handle * form interactions more reactively within Angular applications. */ declare class FormDirective { readonly element: i0.ElementRef; /** * An Observable that emits events every time the form is submitted. This stream is shared among multiple subscribers, * which means the form's submit event is processed as it occurs and is multicasted to all subscribers. * * @emits {Event} The submit event emitted by the form element. */ readonly submit$: rxjs.Observable; /** * An Observable that emits events every time the form is reset. Similar to `submit$`, this stream is also shared * among multiple subscribers, allowing components to react to form resets reactively and concurrently. * * @emits {Event} The reset event emitted by the form element. */ readonly reset$: rxjs.Observable; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵdir: i0.ɵɵDirectiveDeclaration; } declare class SignalFormFieldStateSyncDirective { private readonly signalFormField; private readonly formFieldErrorService; private readonly form; constructor(); static ɵfac: i0.ɵɵFactoryDeclaration; static ɵdir: i0.ɵɵDirectiveDeclaration; } /** * Represents a form field component. */ declare class FormFieldComponent { protected readonly hasWarning$$: BehaviorSubject; protected readonly formGroup: FormGroupComponent | null; protected readonly formFieldService: FormFieldService; protected readonly formFieldErrorService: FormFieldErrorService; readonly element: ElementRef; /** * The label directive associated with the form field component. * * @type {FormFieldLabelDirective | undefined} */ labelDirective?: FormFieldLabelDirective; /** * The control element of the form field component. * * @type {ElementRef} */ controlElement: ElementRef; /** * The label of the form field component. * * @type {string | null} * @default null */ label?: string | null; /** * Indicates whether the form field should have a warning. * * @type {boolean} */ set hasWarning(value: boolean); get hasWarning(): boolean; /** * The variant of the form field. * * @type {FormFieldVariant} * @default FormFieldVariant.FULL */ variant: FormFieldVariant | null; /** * Indicates whether the form field has a label. * * @type {boolean} */ get hasLabel(): boolean; constructor(); static ɵfac: i0.ɵɵFactoryDeclaration; static ɵcmp: i0.ɵɵComponentDeclaration; static ngAcceptInputType_hasWarning: unknown; } declare class FormFieldModule { static ɵfac: i0.ɵɵFactoryDeclaration; static ɵmod: i0.ɵɵNgModuleDeclaration; static ɵinj: i0.ɵɵInjectorDeclaration; } declare const FormFieldDefaultConfig: FormFieldConfig; interface FormFieldConfig { /** * Object of error resolvers used to resolve error messages globally * @default {} */ errors: FormFieldErrorResolvers; ignoreErrors: string[]; } declare const FormFieldConfig: i0.InjectionToken>; declare const injectFormFieldConfig: () => FormFieldConfig; declare const provideFormFieldConfig: >>(config: _odx_angular_utils.ConfigProvider, D>) => i0.FactoryProvider | i0.ValueProvider; export { FormDirective, FormFieldComponent, FormFieldConfig, FormFieldControlDirective, FormFieldDefaultConfig, FormFieldErrorDirective, FormFieldErrorService, FormFieldHintDirective, FormFieldInfoComponent, FormFieldLabelDirective, FormFieldModule, FormFieldVariant, FormGroupComponent, SignalFormFieldStateSyncDirective, injectFormFieldConfig, provideFormFieldConfig }; export type { FormFieldError, FormFieldErrorResolver, FormFieldErrorResolvers };