import { IBlockContext, INavigate } from "@leight-core/leight"; import { FormInstance } from "antd"; import CancelablePromise from "cancelable-promise"; import { NamePath } from "rc-field-form/lib/interface"; export interface IFormItemContext { readonly field: NamePath; readonly label: string; setValue(value: any): void; getValue(): any; setErrors(errors: string[]): void; } export declare type IFormFields = [NamePath, any]; export interface IFormError { readonly id: NamePath; readonly error: string; } export interface IErrorHandler { readonly error: TError; readonly formContext: IFormContext; } export interface IFormErrorHandler { (error: IErrorHandler): void; } export interface IFormErrorMap { readonly [index: string]: IFormError | IFormErrorHandler; } export interface IFormErrors { readonly message?: string; readonly errors: IFormError[]; } export interface IFormContext { readonly translation?: string; /** * Antd form instance. */ readonly form: FormInstance; /** * Current form errors. */ readonly errors: IFormErrors; /** * Set field errors. * * @param errors */ setErrors(errors: IFormErrors): void; /** * Set form values * * @param values values being set */ setValues(values: TValues): void; /** * Reset form to the initial state. */ reset(): void; /** * Return current form values. */ values(): any; /** * Throw away all error messages of all fields. */ resetErrors(): void; /** * Force form refresh (just revalidate and reset fields to get current sync with visible fields). */ refresh(): void; /** * Quick access to form's blocking context. */ readonly blockContext: IBlockContext; /** * Resolve with true or false. */ canSubmit(then?: (canSubmit: boolean) => void): CancelablePromise; } export interface IToOptionMapper { (item: TItem): IBaseSelectOption; } export interface IFormMutationMapper { (values: TFormValues): TRequest; } export interface IFormInitialMapper { (): TFormValues; } export interface IFormOnValuesChanged { (success: IFormValuesChanged): void; } export interface IFormValuesChanged { readonly values: TFormValues; readonly formContext: IFormContext; readonly changed: Partial; } export interface IFormSuccess { readonly navigate: INavigate; readonly values: TFormValues; readonly response: TResponse; readonly formContext: IFormContext; } export interface IFormOnSuccess { (success: IFormSuccess): void; } export interface IFormFailure { readonly error: string; readonly formContext: IFormContext; } export interface IFormOnFailure { (failure: IFormFailure): void; } export interface IToError { readonly error: TError; readonly formContext: IFormContext; } export declare type IBaseSelectItem = any; export interface IBaseSelectOption { value: IBaseSelectItem; label: IBaseSelectItem; } export interface IFilterContext { readonly filter: TFilter; setFilter(filter?: TFilter): void; }