import { AbstractControl as NgAbstractControl, AbstractControlOptions as NgAbstractControlOptions, ValidationErrors as NgValidationErrors } from '@angular/forms'; import { Observable, Subject } from 'rxjs'; import { RxapFormArray } from './form-array'; import { RxapFormControl } from './form-control'; import { RxapFormGroup } from './form-group'; import { FormDefinition } from './model'; export type ValidationErrors = T; export type ValidatorFn = (control: AbstractControl) => ValidationErrors | null; export type AsyncValidatorFn = (control: AbstractControl) => Promise | null> | Observable | null>; export interface AbstractControlOptions extends NgAbstractControlOptions { validators?: ValidatorFn | ValidatorFn[] | null; asyncValidators?: AsyncValidatorFn | AsyncValidatorFn[] | null; } export type ValidatorOrOpts = ValidatorFn | ValidatorFn[] | AbstractControlOptions | null; export type AsyncValidator = AsyncValidatorFn | AsyncValidatorFn[] | null; export type Validator = ValidatorFn | ValidatorFn[]; export interface ControlOptions { onlySelf?: boolean; emitEvent?: boolean; emitModelToViewChange?: boolean; emitViewToModelChange?: boolean; initial?: boolean; /** * used in the RxapFormArray patchValue method. * * true - if the value has not a control with any index. The control is created * false - default behavior */ coerce?: boolean; /** * used in the RxapFormArray patchValue method. * * true - the length of the control array is limited by the length of the value. * false - default behavior * * example with strict = true * * current from array controls: [ 0: {}, 1: {}, 2: {} ] * * patch value A: [ 0: {}, 1: {}, 2: {} ] * result: [ 0: {}, 1: {}, 2: {} ] * * path value B: [ 0: {}, 1: {} ] * result: [ 0: {}, 1: {} ] * */ strict?: boolean; } export type ControlEventOptions = Pick; export type OnlySelf = Pick; export type EmitEvent = Pick; export type ControlPath = Array | string; export type ControlState = 'VALID' | 'INVALID' | 'PENDING' | 'DISABLED'; export interface AbstractControl extends NgAbstractControl { value: T; controlId?: string; fullControlPath?: string; rxapFormDefinition?: FormDefinition; readonly?: boolean; stateChanges?: Subject; } export type ExtractStrings = Extract; export interface NgValidatorsErrors { required: true; email: true; pattern: { requiredPattern: string; actualValue: string; }; minlength: { requiredLength: number; actualLength: number; }; maxlength: { requiredLength: number; actualLength: number; }; min: { min: number; actual: number; }; max: { max: number; actual: number; }; } export interface BoxedValue { value: T; disabled?: boolean; } export type OrBoxedValue = T | BoxedValue | (() => T); type ArrayType = T extends Array ? R : any; export type KeyValueControls = { [K in keyof T]: T[K] extends RxapFormControl ? RxapFormControl : T[K] extends RxapFormGroup ? RxapFormGroup : T[K] extends RxapFormArray> ? RxapFormArray> : AbstractControl; }; export type ExtractAbstractControl = T extends KeyValueControls ? { [K in keyof U]: AbstractControl; } : T; export {};