import { Observable, Subject } from "rxjs"; import { FormControl, FormGroup } from "@angular/forms"; import { type StartCaseOptions } from "angular-extensions/core"; import { Validation, ValidationConstructor } from "./validation.model"; /** * Constructor object for Field class */ declare type FieldConstructor = Partial, "control" | "element" | "options" | "onValueChange" | "onOptionsChange" | "validation" | "customOptionFilterPredicate" | "_initialStatus" | "destroy" | "setOptions" | "setFromOptions" | "updateValidation" | "visible" | "formattedValue" | "formGroup" | "optionChanges" | "destroy$"> & { options: TOption[] | Observable; onValueChange: (value: TValue, previous: TValue) => void; onOptionsChange: (value: TOption[]) => void; validation: ValidationConstructor; /** * Indicates field initial state */ disabled: boolean; /** * Configures when {@link valueChanges} should emit event. */ updateOn?: "change" | "blur" | "submit"; }>; /** * Commonly used Field value formatters */ export declare const Formatters: { /** * Formats Field value to UTC date ("yyyy-MM-dd") string. * * @param field Field * @returns String */ utcDateFormatter: (field: Field) => string; /** * Formats Field value to UTC date/time ("yyyy-MM-dd'T'HH:mm:ss'Z'") string. * * @param field Field * @returns String */ utcDateTimeFormatter: (field: Field) => string; /** * Formats Field value to date string with {@link DatePipe} and {@link NGX_DATE_FORMATS} * * @param field Field * @returns String */ dateFormatter: (field: Field) => string; /** * Formats Field value to date/time string with {@link DateTimePipe} and {@link NGX_DATE_FORMATS} * * @param field Field * @returns String */ dateTimeFormatter: (field: Field) => string; }; /** * Field <=> Control value converter. * Useful when HTML input has different model that actual Field. * * @template TFieldValue Field Value * @template TControlValue Field's Control Value */ interface FieldControlValueConverter { fromControlValue: (value: TControlValue) => TFieldValue; toControlValue: (value: TFieldValue) => TControlValue; } /** * Field option that can be used in select-control, etc. */ export declare class Option { id: TId; name: string; label: string; value: TValue; constructor(props?: Partial>); /** * Creates options from specified Enum * * @param enumType Enum type * @param options Label formatter options * @returns Collection of options */ static ForEnum(enumType: any, options?: StartCaseOptions): Option[]; } /** * Provides simplified api to work with Angular reactive forms and predefined control components. */ export declare class Field { private optionChanges$; private _options; _initialStatus: { disabled: boolean; }; readonly destroy$: Subject; /** * Angular FormControl of field. Control components communicates via this control between Field and UI */ control: FormControl; /** * Reference to control root HTML element */ element?: HTMLElement; /** * Name of a field inside parent's FormGroup, etc. */ name: string; /** * Placeholder of a field */ placeholder?: string; /** * Label of a field */ label?: string; /** * Info text of field showed in mat-hint */ info?: string; /** * Validations of a field */ validation: Validation; /** * Field value formatter which is used by {@link formattedValue}. See list of built-in {@link Formatters} */ formatter: (field: Field) => TFormattedValue; /** * Field's Control value converter, conversion is done whenever value is being read from/written to a {@link control}. */ controlConverter: FieldControlValueConverter; /** * Configures when field should be visible, by default is always visible. */ visibilityProvider?: () => boolean; /** * Highlights field */ highlight?: (value?: any) => void; /** * Determines whether field is querying data: options, etc. */ isQuerying: boolean; /** * Gets field's parent as form group */ get formGroup(): FormGroup; /** * Gets field's visibility status. Based on {@link visibilityProvider}. */ get visible(): boolean; /** * Sets field's visibility status. Based on {@link visibilityProvider}. */ set visible(isVisible: boolean); /** * Gets field's value. Applies conversion if specified at {@link controlConverter}. */ get value(): TValue; /** * Sets field's value. Applies conversion if specified at {@link controlConverter}. * If previous value is the same as current value, {@link onValueChange} wont emit changes */ set value(value: TValue); /** * Gets formatted value, applies {@link formatter} if exists */ get formattedValue(): TFormattedValue; /** * Gets Field's options */ get options(): TOption[]; /** * Sets Field's options and notifies subscribers. */ set options(value: TOption[]); /** * Gets option changes stream */ get optionChanges(): Observable; readonly customOptionFilterPredicate: boolean; /** * Indicates whether field values should be updated when options changed. */ updateValueWhenOptionsChanged: boolean; /** * Configures when Field should be destroyed. * If "control" - Field is destroyed when control ngOnDestroy method called. * If "editor" - Field is destroyed when editor destroy method called. * * @default Default value: "control" */ destoryWith: "control" | "editor"; /** * Options filter predicate that is used by select-control, by default filters by option label */ optionsFilterPredicate: (option: TOption, filter: string) => boolean; /** * Custom option identifier that is used by select-control to compare options */ optionId: (option: TOption, index?: number) => number | string; /** * Custom option label provider that is used by select-control */ optionLabel: (option: TOption) => string; /** * Custom option label provider that is used by select-control */ optionTooltip?: (option: TOption) => string; /** * Allows to specify option display label when selected */ optionDisplayLabel?: (option: TOption) => string; /** * Custom option value provider that is used by select-control */ optionValue: (option: TOption) => TControlValue; /** * Custom option availability provider that is used by select-control */ optionDisabled: (option: TOption) => boolean; /** * Options provider function accepting string query */ optionsProvider?: (query: string) => Observable; /** * Options group provider that is used by select-control. */ optionsGroupProvider?: (option: TOption) => TOptionGroup; /** * Custom option group label provider that is used by select-control */ optionGroupLabel: (optionGroup: TOptionGroup) => string; constructor(props: FieldConstructor); /** * Sets Field's options. Subscribes to Observable input and tracks status in {@link isQuerying} property */ setOptions(value: TOption[] | Observable): Promise; /** * Selects values from available options based on options predicate. Honors * * @param optionPredicate Options predicate that will select values from * @param config Configures default value if nothing selected or should it emit value change event. * @returns Promise */ setFromOptions(optionPredicate: (option: TOption) => boolean, config?: { defaultValue?: TValue; emitEvent?: boolean; }): Promise; /** * Updates field validation * * @param validation Validation constructor parameters */ updateValidation(validation: ValidationConstructor): void; /** * Destroys field and its subscriptions */ destroy(): void; } export {};