@agile-ts/multieditor
Version:
Simple Form Manager for UI-Frameworks
68 lines (67 loc) • 2.2 kB
TypeScript
import { StateRuntimeJobConfigInterface, State } from '@agile-ts/core';
import { Multieditor } from './multieditor';
import { Status } from './status';
import { Validator } from './validator';
export declare class Item<ValueType = any> extends State<ValueType> {
editor: () => Multieditor;
config: ItemConfigInterface;
isValid: boolean;
validator: Validator<ValueType>;
status: Status<ValueType>;
touched: boolean;
computeValueMethod?: ComputeValueMethod<ValueType>;
/**
* An Item represents a piece of information from the Multieditor.
*
* @public
* @param editor - Multieditor to which the Item belongs.
* @param initialValue - Initial value of the Item.
* @param config - Configuration object
*/
constructor(editor: Multieditor, initialValue: ValueType, config: ItemConfigInterface<ValueType>);
/**
* Revalidates the Item via the Validator
* and updates the 'isValid' state.
*
* @public
*/
validate(): Promise<boolean>;
/**
* Resets the Item value to its initial value.
*
* @public
* @param config - Configuration object
*/
reset(config?: StateRuntimeJobConfigInterface): this;
/**
* Defines the method used to compute the value of the Item.
*
* It is retrieved on each Item value change,
* in order to compute the new Item value
* based on the specified compute method.
*
* @public
* @param method - Method to compute the value of the Item.
*/
computeValue(method: ComputeValueMethod<ValueType>): this;
blur(): this;
}
export interface ItemConfigInterface<ValueType = any> {
/**
* Key/Name identifier of the Item.
*/
key: ItemKey;
/**
* Whether the Item value can be edited
* and thus should be represented in the 'preparedData' object when submitting.
* @default true
*/
canBeEdited?: boolean;
/**
* Validator to handle validating the Item.
* @default newly create Validator
*/
validator?: Validator<ValueType>;
}
export declare type ComputeValueMethod<T = any> = (value: T) => T;
export declare type ItemKey = string | number;