UNPKG

@agile-ts/multieditor

Version:

Simple Form Manager for UI-Frameworks

200 lines (199 loc) 7.29 kB
import { Agile, Observer, StateIngestConfigInterface } from '@agile-ts/core'; import { Item, ItemKey } from '../item'; import { StatusInterface, StatusType } from '../status'; import { DeepFieldPaths, DeepFieldPathValues, CreateEditorConfig, EditorConfigInterface, EditorKey, FieldData, FieldPaths, RecomputeValidatedStateMethodConfigInterface, SubmitConfigInterface, UpdateInitialValueConfigInterface } from './types'; export declare class Multieditor<TFieldData extends FieldData = FieldData> { agileInstance: () => Agile; config: EditorConfigInterface; _key?: EditorKey; isModified: boolean; isValid: boolean; submitted: boolean; fixedProperties: ItemKey[]; editableProperties: ItemKey[]; onSubmit: (preparedData: { [key: string]: any; }, config?: Object) => Promise<any>; data: { [key: string]: Item; }; /** * Simple Form Handler. * * @public * @param agileInstance - Instance of Agile the Multieditor belongs to. * @param config - Configuration object */ constructor(config: CreateEditorConfig<TFieldData>, agileInstance: Agile); /** * Updates the key/name identifier of the Multieditor. * * @public * @param value - New key/name identifier. */ set key(value: EditorKey | undefined); /** * Returns the key/name identifier of the Multieditor. * * @public */ get key(): EditorKey | undefined; /** * Returns an array of dependencies the Multieditor depends on. * * These returned dependencies can be bound to a UI-Component * the Mutlieditor is used in, to make the Form reactive. * * @public */ get deps(): Array<Observer>; /** * Returns an array of dependencies the Item * with the specified key/name identifier depends on. * * @public * @param itemKey - Key/Name identifier of the Item. */ itemDeps(itemKey: FieldPaths<TFieldData>): Array<Observer>; /** * Assigns a new value to the Item with the specified key/name identifier. * * @public * @param itemKey - Key/Name identifier of the Item. * @param value - New Item value * @param config - Configuration object */ setValue<TItemName extends DeepFieldPaths<TFieldData> = DeepFieldPaths<TFieldData>>(itemKey: TItemName, value: DeepFieldPathValues<TFieldData, TItemName>, config?: StateIngestConfigInterface): this; /** * Assigns a new initial value to the Item with the specified key/name identifier. * * @public * @param itemKey - Key/Name identifier of the Item. * @param value - New Item initial value * @param config - Configuration object */ setInitialValue<TItemName extends DeepFieldPaths<TFieldData> = DeepFieldPaths<TFieldData>>(itemKey: TItemName, value: DeepFieldPathValues<TFieldData, TItemName>, config?: UpdateInitialValueConfigInterface): this; /** * Submits the Multieditor. * * @public * @param config - Configuration object */ submit(config?: SubmitConfigInterface): Promise<any | false>; /** * Resets the Multieditor and all its Items. * * @public */ reset(): this; /** * Assigns the specified new Status to the Item with the specified key/name identifier. * * However, if tracking of the particular Status is active, * the value is only tracked (not applied). * If the tracking has been finished the last tracked Status value should be applied to the Status. * * @public * @param itemKey - Key/Name identifier of the Item. * @param type - Status type * @param message - Status message */ setStatus(itemKey: FieldPaths<TFieldData>, type: StatusType, message: string): this; /** * Resets the Status of the Item with the specified key/name identifier. * * @public * @param itemKey - Key/Name identifier of the Item. */ resetStatus(itemKey: FieldPaths<TFieldData>): this; /** * Retrieves the Status of the Item with the specified key/name identifier. * * If the to retrieve Status doesn't exist, `null` is returned. * * @public * @param itemKey - Key/Name identifier of the Item. */ getStatus(itemKey: FieldPaths<TFieldData>): StatusInterface | null; /** * Retrieves a single Item with the specified key/name identifier from the Multieditor. * * If the to retrieve Item doesn't exist, `null` is returned. * * @public * @param itemKey - Key/Name identifier of the Item. */ getItem<TItemName extends FieldPaths<TFieldData> = FieldPaths<TFieldData>>(itemKey: TItemName): Item<DeepFieldPathValues<TFieldData, TItemName>> | null; /** * Retrieves the initial value of a single Item * with the specified key/name identifier from the Multieditor. * * If the to retrieve Item containing the initial value doesn't exist, `undefined` is returned. * * @public * @param itemKey - Key/Name identifier of the Item. */ getItemValue<TItemName extends FieldPaths<TFieldData> = FieldPaths<TFieldData>>(itemKey: TItemName): DeepFieldPathValues<TFieldData, TItemName> | undefined; /** * Retrieves the value of a single Item * with the specified key/name identifier from the Multieditor. * * If the to retrieve Item containing the initial value doesn't exist, `undefined` is returned. * * @public * @param itemKey - Key/Name identifier of the Item. */ getItemInitialValue<TItemName extends FieldPaths<TFieldData> = FieldPaths<TFieldData>>(itemKey: TItemName): DeepFieldPathValues<TFieldData, TItemName> | undefined; /** * Returns a boolean indicating whether at least one Item * of the Items with the specified key/name identifiers is modified. * * @public * @param itemKeys - Key/Name identifiers of the Items. */ areModified(itemKeys: ItemKey[]): boolean; /** * Recomputes the modified state of the Multieditor * based on its Items modified status. * * @public */ recomputeModifiedState(): this; /** * Recomputes the validated state of the Multieditor * based on its Items validation status. * * @public */ recomputeValidatedState(config?: RecomputeValidatedStateMethodConfigInterface): boolean; /** * Revalidates the Multieditor. * * @public */ validate(): boolean; /** * Returns a boolean indication whether the Status of the specified Item * can be updated during a value change of the Item. * * @internal * @param item - Item */ canAssignStatusToItemOnChange(item: Item): boolean; /** * Returns a boolean indication whether the Status of the specified Item * can be updated during the submission of the Multieditor. * * @internal * @param item - Item */ canAssignStatusToItemOnSubmit(item: Item): boolean; /** * Returns a boolean indication whether the Status of the specified Item * can be updated during the blur of the Item. * * @internal * @param item - Item */ canAssignStatusToItemOnBlur(item: Item): boolean; }