///
export declare type NamePath = string | number;
export declare type FormLayout = 'horizontal' | 'vertical' | 'inline';
export declare type LabelAlign = 'left' | 'right';
export declare type StoreValue = any;
export interface Store {
[name: string]: StoreValue;
}
export interface FieldError {
[name: string]: string;
}
export interface Fields {
[name: string]: {
current: FieldInstance;
};
}
export interface FormInstance {
getFieldError: (name: NamePath) => string | undefined;
getFieldsError: (namePathList?: NamePath[]) => FieldError;
getFieldValue: (name: NamePath) => any;
getDefaultValue: (name: NamePath) => any;
getFieldsValue: (namePathList?: NamePath[]) => any;
resetFields: (fields?: NamePath[]) => void;
setFieldsValue: (value: Values) => void;
setFieldValue: (name: NamePath, value: Values) => void;
validateFields: (namePathList?: NamePath[]) => Promise;
submit: () => void;
getInternalHooks: (secret: string) => InternalHooks | null;
}
export interface InnerLocale {
locale: string;
requiredMessage: string;
}
export interface InternalFormInstance extends FormInstance {
labelWidth?: string | number;
labelAlign?: LabelAlign;
wrapperWidth?: string | number;
vertical?: boolean;
disabled?: boolean;
local?: InnerLocale;
getInternalHooks: (key: string) => InternalHooks | null;
}
export declare type Stores = {
prev: Store;
curr: Store;
};
export interface FieldInstance {
onStoreChange: (stores: Stores, namePathList: NamePath[] | null, source: NotifySource) => void;
meta: {
name?: NamePath;
rules?: Rule[];
defaultValue?: any;
trigger?: string | string[];
};
}
export interface Callbacks {
onValuesChange?: (changedValues: any, values: Values) => void;
onFinish?: (value: Values) => void;
onFinishFailed?: (errorInfo: ValidateErrorEntity) => void;
}
export interface UpdateAction {
type: 'updateValue';
namePath: NamePath;
value: StoreValue;
}
export interface ValidateAction {
type: 'validateField';
namePath: NamePath;
}
export declare type ReducerAction = UpdateAction | ValidateAction;
export interface InternalHooks {
dispatch: (action: ReducerAction) => void;
setDefaultValues: (values: Store) => void;
setCallbacks: (callbacks: Callbacks) => void;
registerField: (name: NamePath, field: {
current: FieldInstance;
}) => void;
deleteField: (name: NamePath) => void;
}
export declare type NotifySource = 'externalUpdateValue' | 'updateValue' | 'reset' | 'validateField' | 'validateFinish';
export interface ValidateErrorEntity {
values: Values;
errorFields: {
name: NamePath;
errors: string[];
}[];
}
declare type Validator = (rule: RuleObject, value: StoreValue, callback: (error?: string) => void) => Promise | void;
export declare type RuleType = 'string' | 'number' | 'boolean' | 'method' | 'regexp' | 'integer' | 'float' | 'object' | 'enum' | 'date' | 'url' | 'hex' | 'email';
export interface ValidatorRule {
message?: string | React.ReactElement;
validator: Validator;
}
interface BaseRule {
enum?: StoreValue[];
len?: number;
max?: number;
message?: string | React.ReactElement;
min?: number;
pattern?: RegExp;
required?: boolean;
transform?: (value: StoreValue) => StoreValue;
type?: RuleType;
whitespace?: boolean;
/** Customize rule level `validateTrigger`. Must be subset of Field `validateTrigger` */
validateTrigger?: string | string[];
}
declare type AggregationRule = BaseRule & Partial;
interface ArrayRule extends Omit {
type: 'array';
defaultField?: RuleObject;
}
export declare type RuleRender = (form: FormInstance) => RuleObject;
export declare type RuleObject = AggregationRule | ArrayRule;
export declare type Rule = RuleObject | RuleRender;
export {};