import type { MsgSource } from "react-elmish"; import type { ValidationError, ValidationKey } from "../Validation"; type MessageSource = MsgSource<"Form">; type Message = ({ name: "ValueChanged"; value: Partial; } | { name: "AcceptRequest"; } | { name: "Accept"; } | { name: "CancelRequest"; } | { name: "Cancel"; } | { name: "Validate"; msg?: Message; } | { name: "Validated"; errors: ValidationError[]; msg?: Message; } | { name: "ReValidate"; }) & MessageSource; declare const Source: MessageSource; interface Model { values: TValues; errors: ValidationError[]; validated: boolean; } interface Options { /** * Is called to create the initial form values. * @returns The initial form values. */ initValues: (props: TProps) => TValues; /** * Is called to validate all inputs of the Form. * @returns An array of validation errors, or an empty array if all inputs are valid. */ validate?: (model: Model & TModel & { reValidating: boolean; }, props: TProps) => Promise[]>; /** * This callback is called when one ore more values were changed. * @remarks * In this function you can manipulate the values of the form. */ onValueChanged?: (values: Partial, model: Model & TModel, props: TProps) => Partial; /** * This callback is called after the validation. */ onValidated?: (errors: ValidationError[], model: Model & TModel & { reValidating: boolean; }, props: TProps) => void; /** * This callback is called when the form should be cancelled. * @param model The current model. * @param props The props. */ onCancel?: (model: Model & TModel, props: TProps) => void; /** * This callback is called when the form should be accepted. * @param model The current model. * @param props The props. */ onAccept?: (model: Model & TModel, props: TProps) => void; } interface Msg { /** * Updates the modified value. */ valueChanged: (value: Partial) => Message; /** * Requests to accept the Form. */ acceptRequest: () => Message; /** * Accepts the Form. */ accept: () => Message; /** * Requests to cancel the Form. */ cancelRequest: () => Message; /** * Cancels the Form. */ cancel: () => Message; /** * Validates all inputs. */ validate: (msg?: Message) => Message; /** * All inputs validated. */ validated: (errors: ValidationError[], msg?: Message) => Message; /** * Runs the validation again if it has already been performed. */ reValidate: () => Message; } /** * Creates the `Msg` object with the Form message creators. * @returns The `Msg` object. */ declare function createMsg(): Msg; /** * Creates the initial Form model. * @param options The Form options. * @returns The `init` function. */ declare function createInit(options: Options): (props: TProps) => Model; export type { Message, MessageSource, Model, Msg, Options }; export { createInit, createMsg, Source };