Comparing version 3.0.0-alpha.2 to 3.0.0-alpha.3
/// <reference types="react" /> | ||
import BaseForm from './BaseForm'; | ||
import ValidatedQuickForm, { ValidatedQuickFormProps, ValidatedQuickFormState } from './ValidatedQuickForm'; | ||
import { BaseForm } from './BaseForm'; | ||
import { DeepPartial } from './types'; | ||
export declare type AutoFormProps<Model extends {}> = ValidatedQuickFormProps<Model> & { | ||
import { ValidatedQuickForm, ValidatedQuickFormProps, ValidatedQuickFormState } from './ValidatedQuickForm'; | ||
export declare type AutoFormProps<Model> = ValidatedQuickFormProps<Model> & { | ||
onChangeModel?(model: DeepPartial<Model>): void; | ||
}; | ||
export declare type AutoFormState<Model extends {}> = ValidatedQuickFormState<Model> & { | ||
export declare type AutoFormState<Model> = ValidatedQuickFormState<Model> & { | ||
model: DeepPartial<Model>; | ||
modelSync: DeepPartial<Model>; | ||
}; | ||
declare function Auto<Base extends typeof ValidatedQuickForm>(base: Base): { | ||
new <Model extends {} = Record<string, any>, Props extends AutoFormProps<Model> = AutoFormProps<Model>, State extends AutoFormState<Model> = AutoFormState<Model>>(props: Props): { | ||
componentDidUpdate(prevProps: Props): void; | ||
export declare function Auto<Base extends typeof ValidatedQuickForm>(Base: Base): { | ||
new <Model, Props extends AutoFormProps<Model> = AutoFormProps<Model>, State extends AutoFormState<Model> = AutoFormState<Model>>(props: Props): { | ||
componentDidUpdate(prevProps: Props, prevState: State, snapshot: never): void; | ||
getNativeFormProps(): Record<string, any>; | ||
getModel(mode: any): State["model"]; | ||
onChange(key: any, value: any): void; | ||
__reset(state: State): { | ||
model: Props["model"]; | ||
modelSync: Props["model"]; | ||
error: null; | ||
validate: boolean; | ||
validating: boolean; | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
onValidate(): Promise<unknown>; | ||
validate: (key?: string | undefined, value?: any) => Promise<unknown>; | ||
validateModel: (model: any) => Promise<unknown>; | ||
getContextError(): State["error"]; | ||
getContext(): { | ||
validating: State["validating"]; | ||
changed: boolean; | ||
changedMap: { | ||
[x: string]: Record<string, void> | { | ||
[x: string]: Record<string, void> | any | undefined; | ||
} | undefined; | ||
}; | ||
error: any; | ||
model: DeepPartial<Record<string, any>>; | ||
name: string[]; | ||
onChange(key: string, value?: any): void; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): any; | ||
randomId(): string; | ||
schema: import("./Bridge").default; | ||
state: { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
submitting: boolean; | ||
}; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
onValidateModel(model: Props["model"]): Promise<unknown>; | ||
__reset(state: State): Partial<State>; | ||
onValidate(): Promise<any>; | ||
validate: (key?: string | undefined, value?: any) => Promise<any>; | ||
validateModel: (originalModel: any) => Promise<any>; | ||
getContextError(): any; | ||
getContext(): import("./types").Context<Model>; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<any>; | ||
onValidateModel(originalModel: Props["model"]): Promise<any>; | ||
componentDidMount(): void; | ||
@@ -66,3 +34,3 @@ componentWillUnmount(): void; | ||
randomId: () => string; | ||
getContextName(): never[]; | ||
getContextName(): string[]; | ||
getContextModel(): DeepPartial<Model>; | ||
@@ -75,6 +43,5 @@ getContextState(): { | ||
}; | ||
getContextSchema(): State["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getChangedKeys<T>(root: string, valueA?: T | undefined, valueB?: T | undefined): string[]; | ||
getContextSchema(): import("./Bridge").Bridge; | ||
getContextOnChange(): (key: string, value?: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => any; | ||
onReset(): void; | ||
@@ -104,244 +71,39 @@ render(): JSX.Element; | ||
displayName: string; | ||
Validated: <Base_1 extends typeof BaseForm>(base: Base_1) => { | ||
new <Model_1 extends {} = Record<string, any>, Props_1 extends import("./ValidatedForm").ValidatedFormProps<Model_1> = import("./ValidatedForm").ValidatedFormProps<Model_1>, State_1 extends import("./ValidatedForm").ValidatedFormState<Model_1> = import("./ValidatedForm").ValidatedFormState<Model_1>>(props: Props_1): { | ||
validate: (key?: string | undefined, value?: any) => Promise<unknown>; | ||
validateModel: (model: any) => Promise<unknown>; | ||
getContextError(): State_1["error"]; | ||
getContext(): { | ||
validating: State_1["validating"]; | ||
changed: boolean; | ||
changedMap: { | ||
[x: string]: Record<string, void> | { | ||
[x: string]: Record<string, void> | any | undefined; | ||
} | undefined; | ||
}; | ||
error: any; | ||
model: DeepPartial<Record<string, any>>; | ||
name: string[]; | ||
onChange(key: string, value?: any): void; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): any; | ||
randomId(): string; | ||
schema: import("./Bridge").default; | ||
state: { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
submitting: boolean; | ||
}; | ||
getNativeFormProps(): Record<string, any>; | ||
componentDidUpdate(prevProps: Props_1, prevState: State_1, snapshot: never): void; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State_1): { | ||
error: null; | ||
validate: boolean; | ||
validating: boolean; | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
onValidate(key?: string | undefined, value?: any): Promise<unknown>; | ||
onValidateModel(model: Props_1["model"]): Promise<unknown>; | ||
componentDidMount(): void; | ||
componentWillUnmount(): void; | ||
delayId?: any; | ||
mounted: boolean; | ||
reset: () => void; | ||
change: (key: string, value: any) => void; | ||
submit: (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<any>; | ||
randomId: () => string; | ||
getContextName(): never[]; | ||
getContextModel(): DeepPartial<Model_1>; | ||
getContextState(): { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
getContextSchema(): State_1["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: DeepPartial<Model_1>): DeepPartial<Model_1>; | ||
getChangedKeys<T_1>(root: string, valueA?: T_1 | undefined, valueB?: T_1 | undefined): string[]; | ||
onReset(): void; | ||
render(): JSX.Element; | ||
context: any; | ||
setState<K_1 extends keyof State_1>(state: State_1 | ((prevState: Readonly<State_1>, props: Readonly<Props_1>) => State_1 | Pick<State_1, K_1> | null) | Pick<State_1, K_1> | null, callback?: (() => void) | undefined): void; | ||
forceUpdate(callback?: (() => void) | undefined): void; | ||
readonly props: Readonly<Props_1> & Readonly<{ | ||
children?: import("react").ReactNode; | ||
}>; | ||
state: Readonly<State_1>; | ||
refs: { | ||
[key: string]: import("react").ReactInstance; | ||
}; | ||
shouldComponentUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): boolean; | ||
componentDidCatch?(error: Error, errorInfo: import("react").ErrorInfo): void; | ||
getSnapshotBeforeUpdate?(prevProps: Readonly<Props_1>, prevState: Readonly<State_1>): any; | ||
componentWillMount?(): void; | ||
UNSAFE_componentWillMount?(): void; | ||
componentWillReceiveProps?(nextProps: Readonly<Props_1>, nextContext: any): void; | ||
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<Props_1>, nextContext: any): void; | ||
componentWillUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): void; | ||
UNSAFE_componentWillUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): void; | ||
}; | ||
Validated: any; | ||
displayName: string; | ||
defaultProps: { | ||
onValidate(model: any, error: any, callback: any): void; | ||
validate: string; | ||
autosave: boolean; | ||
autosaveDelay: number; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
}; | ||
getDerivedStateFromProps({ schema }: import("./BaseForm").BaseFormProps<any>, { bridge }: import("./BaseForm").BaseFormState<any>): { | ||
bridge: import("./Bridge").default; | ||
}; | ||
contextType?: import("react").Context<any> | undefined; | ||
} & Base_1; | ||
Validated: typeof import("./ValidatedForm").Validated; | ||
defaultProps: { | ||
onValidate(model: any, error: any, callback: any): void; | ||
onValidate(model: any, error: any): any; | ||
validate: string; | ||
autosave: boolean; | ||
autosaveDelay: number; | ||
error: null; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
onSubmit(): void; | ||
} & { | ||
autosave: boolean; | ||
autosaveDelay: number; | ||
error: null; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
onSubmit(): void; | ||
}; | ||
getDerivedStateFromProps: typeof BaseForm.getDerivedStateFromProps; | ||
contextType?: import("react").Context<any> | undefined; | ||
Quick: <Base_2 extends typeof BaseForm>(base: Base_2) => { | ||
new <Model_2 extends {} = Record<string, any>, Props_2 extends import("./QuickForm").QuickFormProps<Model_2> = import("./QuickForm").QuickFormProps<Model_2>, State_2 extends import("./BaseForm").BaseFormState<Model_2> = import("./BaseForm").BaseFormState<Model_2>>(props: Props_2): { | ||
getNativeFormProps(): Record<string, any>; | ||
getAutoField(): import("react").ComponentType<{ | ||
name?: string | undefined; | ||
}>; | ||
getErrorsField(): import("react").ComponentType<{}>; | ||
getSubmitField(): import("react").ComponentType<{}>; | ||
componentDidMount(): void; | ||
componentDidUpdate(prevProps: any, prevState: any, snapshot: any): void; | ||
componentWillUnmount(): void; | ||
delayId?: any; | ||
mounted: boolean; | ||
reset: () => void; | ||
change: (key: string, value: any) => void; | ||
submit: (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<any>; | ||
randomId: () => string; | ||
getContext(): import("./types").Context<Record<string, any>>; | ||
getContextName(): never[]; | ||
getContextError(): Props_2["error"]; | ||
getContextModel(): DeepPartial<Model_2>; | ||
getContextState(): { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
getContextSchema(): State_2["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: DeepPartial<Model_2>): DeepPartial<Model_2>; | ||
getChangedKeys<T_2>(root: string, valueA?: T_2 | undefined, valueB?: T_2 | undefined): string[]; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State_2): { | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
onReset(): void; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
render(): JSX.Element; | ||
context: any; | ||
setState<K_2 extends keyof State_2>(state: State_2 | ((prevState: Readonly<State_2>, props: Readonly<Props_2>) => State_2 | Pick<State_2, K_2> | null) | Pick<State_2, K_2> | null, callback?: (() => void) | undefined): void; | ||
forceUpdate(callback?: (() => void) | undefined): void; | ||
readonly props: Readonly<Props_2> & Readonly<{ | ||
children?: import("react").ReactNode; | ||
}>; | ||
state: Readonly<State_2>; | ||
refs: { | ||
[key: string]: import("react").ReactInstance; | ||
}; | ||
shouldComponentUpdate?(nextProps: Readonly<Props_2>, nextState: Readonly<State_2>, nextContext: any): boolean; | ||
componentDidCatch?(error: Error, errorInfo: import("react").ErrorInfo): void; | ||
getSnapshotBeforeUpdate?(prevProps: Readonly<Props_2>, prevState: Readonly<State_2>): any; | ||
componentWillMount?(): void; | ||
UNSAFE_componentWillMount?(): void; | ||
componentWillReceiveProps?(nextProps: Readonly<Props_2>, nextContext: any): void; | ||
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<Props_2>, nextContext: any): void; | ||
componentWillUpdate?(nextProps: Readonly<Props_2>, nextState: Readonly<State_2>, nextContext: any): void; | ||
UNSAFE_componentWillUpdate?(nextProps: Readonly<Props_2>, nextState: Readonly<State_2>, nextContext: any): void; | ||
}; | ||
Quick: any; | ||
displayName: string; | ||
defaultProps: { | ||
autosave: boolean; | ||
autosaveDelay: number; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
}; | ||
getDerivedStateFromProps({ schema }: import("./BaseForm").BaseFormProps<any>, { bridge }: import("./BaseForm").BaseFormState<any>): { | ||
bridge: import("./Bridge").default; | ||
}; | ||
contextType?: import("react").Context<any> | undefined; | ||
} & Base_2; | ||
Quick: typeof import("./QuickForm").Quick; | ||
} & Base; | ||
declare const _default: { | ||
new <Model extends {} = Record<string, any>, Props extends AutoFormProps<Model> = AutoFormProps<Model>, State extends AutoFormState<Model> = AutoFormState<Model>>(props: Props): { | ||
componentDidUpdate(prevProps: Props): void; | ||
export declare const AutoForm: { | ||
new <Model, Props extends AutoFormProps<Model> = AutoFormProps<Model>, State extends AutoFormState<Model> = AutoFormState<Model>>(props: Props): { | ||
componentDidUpdate(prevProps: Props, prevState: State, snapshot: never): void; | ||
getNativeFormProps(): Record<string, any>; | ||
getModel(mode: any): State["model"]; | ||
onChange(key: any, value: any): void; | ||
__reset(state: State): { | ||
model: Props["model"]; | ||
modelSync: Props["model"]; | ||
error: null; | ||
validate: boolean; | ||
validating: boolean; | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
onValidate(): Promise<unknown>; | ||
validate: (key?: string | undefined, value?: any) => Promise<unknown>; | ||
validateModel: (model: any) => Promise<unknown>; | ||
getContextError(): State["error"]; | ||
getContext(): { | ||
validating: State["validating"]; | ||
changed: boolean; | ||
changedMap: { | ||
[x: string]: Record<string, void> | { | ||
[x: string]: Record<string, void> | any | undefined; | ||
} | undefined; | ||
}; | ||
error: any; | ||
model: DeepPartial<Record<string, any>>; | ||
name: string[]; | ||
onChange(key: string, value?: any): void; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): any; | ||
randomId(): string; | ||
schema: import("./Bridge").default; | ||
state: { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
submitting: boolean; | ||
}; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
onValidateModel(model: Props["model"]): Promise<unknown>; | ||
__reset(state: State): Partial<State>; | ||
onValidate(): Promise<any>; | ||
validate: (key?: string | undefined, value?: any) => Promise<any>; | ||
validateModel: (originalModel: any) => Promise<any>; | ||
getContextError(): any; | ||
getContext(): import("./types").Context<Model>; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<any>; | ||
onValidateModel(originalModel: Props["model"]): Promise<any>; | ||
componentDidMount(): void; | ||
@@ -355,3 +117,3 @@ componentWillUnmount(): void; | ||
randomId: () => string; | ||
getContextName(): never[]; | ||
getContextName(): string[]; | ||
getContextModel(): DeepPartial<Model>; | ||
@@ -364,6 +126,5 @@ getContextState(): { | ||
}; | ||
getContextSchema(): State["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getChangedKeys<T>(root: string, valueA?: T | undefined, valueB?: T | undefined): string[]; | ||
getContextSchema(): import("./Bridge").Bridge; | ||
getContextOnChange(): (key: string, value?: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => any; | ||
onReset(): void; | ||
@@ -393,240 +154,37 @@ render(): JSX.Element; | ||
displayName: string; | ||
Validated: <Base extends typeof BaseForm>(base: Base) => { | ||
new <Model_1 extends {} = Record<string, any>, Props_1 extends import("./ValidatedForm").ValidatedFormProps<Model_1> = import("./ValidatedForm").ValidatedFormProps<Model_1>, State_1 extends import("./ValidatedForm").ValidatedFormState<Model_1> = import("./ValidatedForm").ValidatedFormState<Model_1>>(props: Props_1): { | ||
validate: (key?: string | undefined, value?: any) => Promise<unknown>; | ||
validateModel: (model: any) => Promise<unknown>; | ||
getContextError(): State_1["error"]; | ||
getContext(): { | ||
validating: State_1["validating"]; | ||
changed: boolean; | ||
changedMap: { | ||
[x: string]: Record<string, void> | { | ||
[x: string]: Record<string, void> | any | undefined; | ||
} | undefined; | ||
}; | ||
error: any; | ||
model: DeepPartial<Record<string, any>>; | ||
name: string[]; | ||
onChange(key: string, value?: any): void; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): any; | ||
randomId(): string; | ||
schema: import("./Bridge").default; | ||
state: { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
submitting: boolean; | ||
}; | ||
getNativeFormProps(): Record<string, any>; | ||
componentDidUpdate(prevProps: Props_1, prevState: State_1, snapshot: never): void; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State_1): { | ||
error: null; | ||
validate: boolean; | ||
validating: boolean; | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
onValidate(key?: string | undefined, value?: any): Promise<unknown>; | ||
onValidateModel(model: Props_1["model"]): Promise<unknown>; | ||
componentDidMount(): void; | ||
componentWillUnmount(): void; | ||
delayId?: any; | ||
mounted: boolean; | ||
reset: () => void; | ||
change: (key: string, value: any) => void; | ||
submit: (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<any>; | ||
randomId: () => string; | ||
getContextName(): never[]; | ||
getContextModel(): DeepPartial<Model_1>; | ||
getContextState(): { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
getContextSchema(): State_1["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: DeepPartial<Model_1>): DeepPartial<Model_1>; | ||
getChangedKeys<T_1>(root: string, valueA?: T_1 | undefined, valueB?: T_1 | undefined): string[]; | ||
onReset(): void; | ||
render(): JSX.Element; | ||
context: any; | ||
setState<K_1 extends keyof State_1>(state: State_1 | ((prevState: Readonly<State_1>, props: Readonly<Props_1>) => State_1 | Pick<State_1, K_1> | null) | Pick<State_1, K_1> | null, callback?: (() => void) | undefined): void; | ||
forceUpdate(callback?: (() => void) | undefined): void; | ||
readonly props: Readonly<Props_1> & Readonly<{ | ||
children?: import("react").ReactNode; | ||
}>; | ||
state: Readonly<State_1>; | ||
refs: { | ||
[key: string]: import("react").ReactInstance; | ||
}; | ||
shouldComponentUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): boolean; | ||
componentDidCatch?(error: Error, errorInfo: import("react").ErrorInfo): void; | ||
getSnapshotBeforeUpdate?(prevProps: Readonly<Props_1>, prevState: Readonly<State_1>): any; | ||
componentWillMount?(): void; | ||
UNSAFE_componentWillMount?(): void; | ||
componentWillReceiveProps?(nextProps: Readonly<Props_1>, nextContext: any): void; | ||
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<Props_1>, nextContext: any): void; | ||
componentWillUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): void; | ||
UNSAFE_componentWillUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): void; | ||
}; | ||
Validated: any; | ||
displayName: string; | ||
defaultProps: { | ||
onValidate(model: any, error: any, callback: any): void; | ||
validate: string; | ||
autosave: boolean; | ||
autosaveDelay: number; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
}; | ||
getDerivedStateFromProps({ schema }: import("./BaseForm").BaseFormProps<any>, { bridge }: import("./BaseForm").BaseFormState<any>): { | ||
bridge: import("./Bridge").default; | ||
}; | ||
contextType?: import("react").Context<any> | undefined; | ||
} & Base; | ||
Validated: typeof import("./ValidatedForm").Validated; | ||
defaultProps: { | ||
onValidate(model: any, error: any, callback: any): void; | ||
onValidate(model: any, error: any): any; | ||
validate: string; | ||
autosave: boolean; | ||
autosaveDelay: number; | ||
error: null; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
onSubmit(): void; | ||
} & { | ||
autosave: boolean; | ||
autosaveDelay: number; | ||
error: null; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
onSubmit(): void; | ||
}; | ||
getDerivedStateFromProps: typeof BaseForm.getDerivedStateFromProps; | ||
contextType?: import("react").Context<any> | undefined; | ||
Quick: <Base_1 extends typeof BaseForm>(base: Base_1) => { | ||
new <Model_2 extends {} = Record<string, any>, Props_2 extends import("./QuickForm").QuickFormProps<Model_2> = import("./QuickForm").QuickFormProps<Model_2>, State_2 extends import("./BaseForm").BaseFormState<Model_2> = import("./BaseForm").BaseFormState<Model_2>>(props: Props_2): { | ||
getNativeFormProps(): Record<string, any>; | ||
getAutoField(): import("react").ComponentType<{ | ||
name?: string | undefined; | ||
}>; | ||
getErrorsField(): import("react").ComponentType<{}>; | ||
getSubmitField(): import("react").ComponentType<{}>; | ||
componentDidMount(): void; | ||
componentDidUpdate(prevProps: any, prevState: any, snapshot: any): void; | ||
componentWillUnmount(): void; | ||
delayId?: any; | ||
mounted: boolean; | ||
reset: () => void; | ||
change: (key: string, value: any) => void; | ||
submit: (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<any>; | ||
randomId: () => string; | ||
getContext(): import("./types").Context<Record<string, any>>; | ||
getContextName(): never[]; | ||
getContextError(): Props_2["error"]; | ||
getContextModel(): DeepPartial<Model_2>; | ||
getContextState(): { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
getContextSchema(): State_2["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: DeepPartial<Model_2>): DeepPartial<Model_2>; | ||
getChangedKeys<T_2>(root: string, valueA?: T_2 | undefined, valueB?: T_2 | undefined): string[]; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State_2): { | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
onReset(): void; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
render(): JSX.Element; | ||
context: any; | ||
setState<K_2 extends keyof State_2>(state: State_2 | ((prevState: Readonly<State_2>, props: Readonly<Props_2>) => State_2 | Pick<State_2, K_2> | null) | Pick<State_2, K_2> | null, callback?: (() => void) | undefined): void; | ||
forceUpdate(callback?: (() => void) | undefined): void; | ||
readonly props: Readonly<Props_2> & Readonly<{ | ||
children?: import("react").ReactNode; | ||
}>; | ||
state: Readonly<State_2>; | ||
refs: { | ||
[key: string]: import("react").ReactInstance; | ||
}; | ||
shouldComponentUpdate?(nextProps: Readonly<Props_2>, nextState: Readonly<State_2>, nextContext: any): boolean; | ||
componentDidCatch?(error: Error, errorInfo: import("react").ErrorInfo): void; | ||
getSnapshotBeforeUpdate?(prevProps: Readonly<Props_2>, prevState: Readonly<State_2>): any; | ||
componentWillMount?(): void; | ||
UNSAFE_componentWillMount?(): void; | ||
componentWillReceiveProps?(nextProps: Readonly<Props_2>, nextContext: any): void; | ||
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<Props_2>, nextContext: any): void; | ||
componentWillUpdate?(nextProps: Readonly<Props_2>, nextState: Readonly<State_2>, nextContext: any): void; | ||
UNSAFE_componentWillUpdate?(nextProps: Readonly<Props_2>, nextState: Readonly<State_2>, nextContext: any): void; | ||
}; | ||
Quick: any; | ||
displayName: string; | ||
defaultProps: { | ||
autosave: boolean; | ||
autosaveDelay: number; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
}; | ||
getDerivedStateFromProps({ schema }: import("./BaseForm").BaseFormProps<any>, { bridge }: import("./BaseForm").BaseFormState<any>): { | ||
bridge: import("./Bridge").default; | ||
}; | ||
contextType?: import("react").Context<any> | undefined; | ||
} & Base_1; | ||
Quick: typeof import("./QuickForm").Quick; | ||
} & { | ||
new <Model_3 extends {} = Record<string, any>, Props_3 extends import("./ValidatedForm").ValidatedFormProps<Model_3> = import("./ValidatedForm").ValidatedFormProps<Model_3>, State_3 extends import("./ValidatedForm").ValidatedFormState<Model_3> = import("./ValidatedForm").ValidatedFormState<Model_3>>(props: Props_3): { | ||
validate: (key?: string | undefined, value?: any) => Promise<unknown>; | ||
validateModel: (model: any) => Promise<unknown>; | ||
getContextError(): State_3["error"]; | ||
getContext(): { | ||
validating: State_3["validating"]; | ||
changed: boolean; | ||
changedMap: { | ||
[x: string]: Record<string, void> | { | ||
[x: string]: Record<string, void> | any | undefined; | ||
} | undefined; | ||
}; | ||
error: any; | ||
model: DeepPartial<Record<string, any>>; | ||
name: string[]; | ||
onChange(key: string, value?: any): void; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): any; | ||
randomId(): string; | ||
schema: import("./Bridge").default; | ||
state: { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
submitting: boolean; | ||
}; | ||
new <Model_1, Props_1 extends import("./ValidatedForm").ValidatedFormProps<Model_1> = import("./ValidatedForm").ValidatedFormProps<Model_1>, State_1 extends import("./ValidatedForm").ValidatedFormState<Model_1> = import("./ValidatedForm").ValidatedFormState<Model_1>>(props: Props_1): { | ||
validate: (key?: string | undefined, value?: any) => Promise<any>; | ||
validateModel: (originalModel: any) => Promise<any>; | ||
getContextError(): any; | ||
getContext(): import("./types").Context<Model_1>; | ||
getNativeFormProps(): Record<string, any>; | ||
componentDidUpdate(prevProps: Props_3, prevState: State_3, snapshot: never): void; | ||
componentDidUpdate(prevProps: Props_1, prevState: State_1, snapshot: never): void; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State_3): { | ||
error: null; | ||
validate: boolean; | ||
validating: boolean; | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
onValidate(key?: string | undefined, value?: any): Promise<unknown>; | ||
onValidateModel(model: Props_3["model"]): Promise<unknown>; | ||
__reset(state: State_1): Partial<State_1>; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<any>; | ||
onValidate(key?: string | undefined, value?: any): Promise<any>; | ||
onValidateModel(originalModel: Props_1["model"]): Promise<any>; | ||
componentDidMount(): void; | ||
@@ -640,4 +198,4 @@ componentWillUnmount(): void; | ||
randomId: () => string; | ||
getContextName(): never[]; | ||
getContextModel(): DeepPartial<Model_3>; | ||
getContextName(): string[]; | ||
getContextModel(): DeepPartial<Model_1>; | ||
getContextState(): { | ||
@@ -649,150 +207,47 @@ disabled: boolean; | ||
}; | ||
getContextSchema(): State_3["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: DeepPartial<Model_3>): DeepPartial<Model_3>; | ||
getChangedKeys<T_3>(root: string, valueA?: T_3 | undefined, valueB?: T_3 | undefined): string[]; | ||
getContextSchema(): import("./Bridge").Bridge; | ||
getContextOnChange(): (key: string, value?: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => any; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: DeepPartial<Model_1>): DeepPartial<Model_1>; | ||
onReset(): void; | ||
render(): JSX.Element; | ||
context: any; | ||
setState<K_3 extends keyof State_3>(state: State_3 | ((prevState: Readonly<State_3>, props: Readonly<Props_3>) => State_3 | Pick<State_3, K_3> | null) | Pick<State_3, K_3> | null, callback?: (() => void) | undefined): void; | ||
setState<K_1 extends keyof State_1>(state: State_1 | ((prevState: Readonly<State_1>, props: Readonly<Props_1>) => State_1 | Pick<State_1, K_1> | null) | Pick<State_1, K_1> | null, callback?: (() => void) | undefined): void; | ||
forceUpdate(callback?: (() => void) | undefined): void; | ||
readonly props: Readonly<Props_3> & Readonly<{ | ||
readonly props: Readonly<Props_1> & Readonly<{ | ||
children?: import("react").ReactNode; | ||
}>; | ||
state: Readonly<State_3>; | ||
state: Readonly<State_1>; | ||
refs: { | ||
[key: string]: import("react").ReactInstance; | ||
}; | ||
shouldComponentUpdate?(nextProps: Readonly<Props_3>, nextState: Readonly<State_3>, nextContext: any): boolean; | ||
shouldComponentUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): boolean; | ||
componentDidCatch?(error: Error, errorInfo: import("react").ErrorInfo): void; | ||
getSnapshotBeforeUpdate?(prevProps: Readonly<Props_3>, prevState: Readonly<State_3>): any; | ||
getSnapshotBeforeUpdate?(prevProps: Readonly<Props_1>, prevState: Readonly<State_1>): any; | ||
componentWillMount?(): void; | ||
UNSAFE_componentWillMount?(): void; | ||
componentWillReceiveProps?(nextProps: Readonly<Props_3>, nextContext: any): void; | ||
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<Props_3>, nextContext: any): void; | ||
componentWillUpdate?(nextProps: Readonly<Props_3>, nextState: Readonly<State_3>, nextContext: any): void; | ||
UNSAFE_componentWillUpdate?(nextProps: Readonly<Props_3>, nextState: Readonly<State_3>, nextContext: any): void; | ||
componentWillReceiveProps?(nextProps: Readonly<Props_1>, nextContext: any): void; | ||
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<Props_1>, nextContext: any): void; | ||
componentWillUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): void; | ||
UNSAFE_componentWillUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): void; | ||
}; | ||
Validated: <Base extends typeof BaseForm>(base: Base) => { | ||
new <Model_1 extends {} = Record<string, any>, Props_1 extends import("./ValidatedForm").ValidatedFormProps<Model_1> = import("./ValidatedForm").ValidatedFormProps<Model_1>, State_1 extends import("./ValidatedForm").ValidatedFormState<Model_1> = import("./ValidatedForm").ValidatedFormState<Model_1>>(props: Props_1): { | ||
validate: (key?: string | undefined, value?: any) => Promise<unknown>; | ||
validateModel: (model: any) => Promise<unknown>; | ||
getContextError(): State_1["error"]; | ||
getContext(): { | ||
validating: State_1["validating"]; | ||
changed: boolean; | ||
changedMap: { | ||
[x: string]: Record<string, void> | { | ||
[x: string]: Record<string, void> | any | undefined; | ||
} | undefined; | ||
}; | ||
error: any; | ||
model: DeepPartial<Record<string, any>>; | ||
name: string[]; | ||
onChange(key: string, value?: any): void; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): any; | ||
randomId(): string; | ||
schema: import("./Bridge").default; | ||
state: { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
submitting: boolean; | ||
}; | ||
getNativeFormProps(): Record<string, any>; | ||
componentDidUpdate(prevProps: Props_1, prevState: State_1, snapshot: never): void; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State_1): { | ||
error: null; | ||
validate: boolean; | ||
validating: boolean; | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
onValidate(key?: string | undefined, value?: any): Promise<unknown>; | ||
onValidateModel(model: Props_1["model"]): Promise<unknown>; | ||
componentDidMount(): void; | ||
componentWillUnmount(): void; | ||
delayId?: any; | ||
mounted: boolean; | ||
reset: () => void; | ||
change: (key: string, value: any) => void; | ||
submit: (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<any>; | ||
randomId: () => string; | ||
getContextName(): never[]; | ||
getContextModel(): DeepPartial<Model_1>; | ||
getContextState(): { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
getContextSchema(): State_1["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: DeepPartial<Model_1>): DeepPartial<Model_1>; | ||
getChangedKeys<T_1>(root: string, valueA?: T_1 | undefined, valueB?: T_1 | undefined): string[]; | ||
onReset(): void; | ||
render(): JSX.Element; | ||
context: any; | ||
setState<K_1 extends keyof State_1>(state: State_1 | ((prevState: Readonly<State_1>, props: Readonly<Props_1>) => State_1 | Pick<State_1, K_1> | null) | Pick<State_1, K_1> | null, callback?: (() => void) | undefined): void; | ||
forceUpdate(callback?: (() => void) | undefined): void; | ||
readonly props: Readonly<Props_1> & Readonly<{ | ||
children?: import("react").ReactNode; | ||
}>; | ||
state: Readonly<State_1>; | ||
refs: { | ||
[key: string]: import("react").ReactInstance; | ||
}; | ||
shouldComponentUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): boolean; | ||
componentDidCatch?(error: Error, errorInfo: import("react").ErrorInfo): void; | ||
getSnapshotBeforeUpdate?(prevProps: Readonly<Props_1>, prevState: Readonly<State_1>): any; | ||
componentWillMount?(): void; | ||
UNSAFE_componentWillMount?(): void; | ||
componentWillReceiveProps?(nextProps: Readonly<Props_1>, nextContext: any): void; | ||
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<Props_1>, nextContext: any): void; | ||
componentWillUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): void; | ||
UNSAFE_componentWillUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): void; | ||
}; | ||
Validated: any; | ||
displayName: string; | ||
defaultProps: { | ||
onValidate(model: any, error: any, callback: any): void; | ||
validate: string; | ||
autosave: boolean; | ||
autosaveDelay: number; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
}; | ||
getDerivedStateFromProps({ schema }: import("./BaseForm").BaseFormProps<any>, { bridge }: import("./BaseForm").BaseFormState<any>): { | ||
bridge: import("./Bridge").default; | ||
}; | ||
contextType?: import("react").Context<any> | undefined; | ||
} & Base; | ||
Validated: typeof import("./ValidatedForm").Validated; | ||
displayName: string; | ||
defaultProps: { | ||
onValidate(model: any, error: any, callback: any): void; | ||
onValidate(model: any, error: any): any; | ||
validate: string; | ||
autosave: boolean; | ||
autosaveDelay: number; | ||
error: null; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
onSubmit(): void; | ||
}; | ||
getDerivedStateFromProps({ schema }: import("./BaseForm").BaseFormProps<any>, { bridge }: import("./BaseForm").BaseFormState<any>): { | ||
bridge: import("./Bridge").default; | ||
}; | ||
contextType?: import("react").Context<any> | undefined; | ||
} & { | ||
new <Model_4 extends {} = Record<string, any>, Props_4 extends import("./QuickForm").QuickFormProps<Model_4> = import("./QuickForm").QuickFormProps<Model_4>, State_4 extends import("./BaseForm").BaseFormState<Model_4> = import("./BaseForm").BaseFormState<Model_4>>(props: Props_4): { | ||
new <Model_2, Props_2 extends import("./QuickForm").QuickFormProps<Model_2> = import("./QuickForm").QuickFormProps<Model_2>, State_2 extends import("./BaseForm").BaseFormState<Model_2> = import("./BaseForm").BaseFormState<Model_2>>(props: Props_2): { | ||
getNativeFormProps(): Record<string, any>; | ||
getAutoField(): import("react").ComponentType<{ | ||
name?: string | undefined; | ||
name: string; | ||
}>; | ||
@@ -802,3 +257,3 @@ getErrorsField(): import("react").ComponentType<{}>; | ||
componentDidMount(): void; | ||
componentDidUpdate(prevProps: any, prevState: any, snapshot: any): void; | ||
componentDidUpdate(prevProps: Props_2, prevState: State_2, snapshot: never): void; | ||
componentWillUnmount(): void; | ||
@@ -811,6 +266,6 @@ delayId?: any; | ||
randomId: () => string; | ||
getContext(): import("./types").Context<Record<string, any>>; | ||
getContextName(): never[]; | ||
getContextError(): Props_4["error"]; | ||
getContextModel(): DeepPartial<Model_4>; | ||
getContext(): import("./types").Context<Model_2>; | ||
getContextName(): string[]; | ||
getContextError(): any; | ||
getContextModel(): DeepPartial<Model_2>; | ||
getContextState(): { | ||
@@ -822,113 +277,32 @@ disabled: boolean; | ||
}; | ||
getContextSchema(): State_4["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: DeepPartial<Model_4>): DeepPartial<Model_4>; | ||
getChangedKeys<T_4>(root: string, valueA?: T_4 | undefined, valueB?: T_4 | undefined): string[]; | ||
getContextSchema(): import("./Bridge").Bridge; | ||
getContextOnChange(): (key: string, value?: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => any; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: DeepPartial<Model_2>): DeepPartial<Model_2>; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State_4): { | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
__reset(state: State_2): Partial<State_2>; | ||
onReset(): void; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<any>; | ||
render(): JSX.Element; | ||
context: any; | ||
setState<K_4 extends keyof State_4>(state: State_4 | ((prevState: Readonly<State_4>, props: Readonly<Props_4>) => State_4 | Pick<State_4, K_4> | null) | Pick<State_4, K_4> | null, callback?: (() => void) | undefined): void; | ||
setState<K_2 extends keyof State_2>(state: State_2 | ((prevState: Readonly<State_2>, props: Readonly<Props_2>) => State_2 | Pick<State_2, K_2> | null) | Pick<State_2, K_2> | null, callback?: (() => void) | undefined): void; | ||
forceUpdate(callback?: (() => void) | undefined): void; | ||
readonly props: Readonly<Props_4> & Readonly<{ | ||
readonly props: Readonly<Props_2> & Readonly<{ | ||
children?: import("react").ReactNode; | ||
}>; | ||
state: Readonly<State_4>; | ||
state: Readonly<State_2>; | ||
refs: { | ||
[key: string]: import("react").ReactInstance; | ||
}; | ||
shouldComponentUpdate?(nextProps: Readonly<Props_4>, nextState: Readonly<State_4>, nextContext: any): boolean; | ||
shouldComponentUpdate?(nextProps: Readonly<Props_2>, nextState: Readonly<State_2>, nextContext: any): boolean; | ||
componentDidCatch?(error: Error, errorInfo: import("react").ErrorInfo): void; | ||
getSnapshotBeforeUpdate?(prevProps: Readonly<Props_4>, prevState: Readonly<State_4>): any; | ||
getSnapshotBeforeUpdate?(prevProps: Readonly<Props_2>, prevState: Readonly<State_2>): any; | ||
componentWillMount?(): void; | ||
UNSAFE_componentWillMount?(): void; | ||
componentWillReceiveProps?(nextProps: Readonly<Props_4>, nextContext: any): void; | ||
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<Props_4>, nextContext: any): void; | ||
componentWillUpdate?(nextProps: Readonly<Props_4>, nextState: Readonly<State_4>, nextContext: any): void; | ||
UNSAFE_componentWillUpdate?(nextProps: Readonly<Props_4>, nextState: Readonly<State_4>, nextContext: any): void; | ||
componentWillReceiveProps?(nextProps: Readonly<Props_2>, nextContext: any): void; | ||
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<Props_2>, nextContext: any): void; | ||
componentWillUpdate?(nextProps: Readonly<Props_2>, nextState: Readonly<State_2>, nextContext: any): void; | ||
UNSAFE_componentWillUpdate?(nextProps: Readonly<Props_2>, nextState: Readonly<State_2>, nextContext: any): void; | ||
}; | ||
Quick: <Base_1 extends typeof BaseForm>(base: Base_1) => { | ||
new <Model_2 extends {} = Record<string, any>, Props_2 extends import("./QuickForm").QuickFormProps<Model_2> = import("./QuickForm").QuickFormProps<Model_2>, State_2 extends import("./BaseForm").BaseFormState<Model_2> = import("./BaseForm").BaseFormState<Model_2>>(props: Props_2): { | ||
getNativeFormProps(): Record<string, any>; | ||
getAutoField(): import("react").ComponentType<{ | ||
name?: string | undefined; | ||
}>; | ||
getErrorsField(): import("react").ComponentType<{}>; | ||
getSubmitField(): import("react").ComponentType<{}>; | ||
componentDidMount(): void; | ||
componentDidUpdate(prevProps: any, prevState: any, snapshot: any): void; | ||
componentWillUnmount(): void; | ||
delayId?: any; | ||
mounted: boolean; | ||
reset: () => void; | ||
change: (key: string, value: any) => void; | ||
submit: (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<any>; | ||
randomId: () => string; | ||
getContext(): import("./types").Context<Record<string, any>>; | ||
getContextName(): never[]; | ||
getContextError(): Props_2["error"]; | ||
getContextModel(): DeepPartial<Model_2>; | ||
getContextState(): { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
getContextSchema(): State_2["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: DeepPartial<Model_2>): DeepPartial<Model_2>; | ||
getChangedKeys<T_2>(root: string, valueA?: T_2 | undefined, valueB?: T_2 | undefined): string[]; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State_2): { | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
onReset(): void; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
render(): JSX.Element; | ||
context: any; | ||
setState<K_2 extends keyof State_2>(state: State_2 | ((prevState: Readonly<State_2>, props: Readonly<Props_2>) => State_2 | Pick<State_2, K_2> | null) | Pick<State_2, K_2> | null, callback?: (() => void) | undefined): void; | ||
forceUpdate(callback?: (() => void) | undefined): void; | ||
readonly props: Readonly<Props_2> & Readonly<{ | ||
children?: import("react").ReactNode; | ||
}>; | ||
state: Readonly<State_2>; | ||
refs: { | ||
[key: string]: import("react").ReactInstance; | ||
}; | ||
shouldComponentUpdate?(nextProps: Readonly<Props_2>, nextState: Readonly<State_2>, nextContext: any): boolean; | ||
componentDidCatch?(error: Error, errorInfo: import("react").ErrorInfo): void; | ||
getSnapshotBeforeUpdate?(prevProps: Readonly<Props_2>, prevState: Readonly<State_2>): any; | ||
componentWillMount?(): void; | ||
UNSAFE_componentWillMount?(): void; | ||
componentWillReceiveProps?(nextProps: Readonly<Props_2>, nextContext: any): void; | ||
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<Props_2>, nextContext: any): void; | ||
componentWillUpdate?(nextProps: Readonly<Props_2>, nextState: Readonly<State_2>, nextContext: any): void; | ||
UNSAFE_componentWillUpdate?(nextProps: Readonly<Props_2>, nextState: Readonly<State_2>, nextContext: any): void; | ||
}; | ||
Quick: any; | ||
displayName: string; | ||
defaultProps: { | ||
autosave: boolean; | ||
autosaveDelay: number; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
}; | ||
getDerivedStateFromProps({ schema }: import("./BaseForm").BaseFormProps<any>, { bridge }: import("./BaseForm").BaseFormState<any>): { | ||
bridge: import("./Bridge").default; | ||
}; | ||
contextType?: import("react").Context<any> | undefined; | ||
} & Base_1; | ||
Quick: typeof import("./QuickForm").Quick; | ||
displayName: string; | ||
@@ -938,11 +312,10 @@ defaultProps: { | ||
autosaveDelay: number; | ||
error: null; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
onSubmit(): void; | ||
}; | ||
getDerivedStateFromProps({ schema }: import("./BaseForm").BaseFormProps<any>, { bridge }: import("./BaseForm").BaseFormState<any>): { | ||
bridge: import("./Bridge").default; | ||
}; | ||
contextType?: import("react").Context<any> | undefined; | ||
} & typeof BaseForm; | ||
export default _default; | ||
export declare type AutoForm = typeof AutoForm; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var cloneDeep_1 = tslib_1.__importDefault(require("lodash/cloneDeep")); | ||
var clone_1 = tslib_1.__importDefault(require("lodash/clone")); | ||
var isEqual_1 = tslib_1.__importDefault(require("lodash/isEqual")); | ||
var omit_1 = tslib_1.__importDefault(require("lodash/omit")); | ||
var set_1 = tslib_1.__importDefault(require("lodash/set")); | ||
var ValidatedQuickForm_1 = tslib_1.__importDefault(require("./ValidatedQuickForm")); | ||
function Auto(base) { | ||
var setWith_1 = tslib_1.__importDefault(require("lodash/setWith")); | ||
var ValidatedQuickForm_1 = require("./ValidatedQuickForm"); | ||
function Auto(Base) { | ||
// @ts-ignore: Mixin class problem. | ||
@@ -18,3 +18,3 @@ var AutoForm = /** @class */ (function (_super) { | ||
} | ||
AutoForm.prototype.componentDidUpdate = function (prevProps) { | ||
AutoForm.prototype.componentDidUpdate = function (prevProps, prevState, snapshot) { | ||
var model = this.props.model; | ||
@@ -24,4 +24,3 @@ if (!isEqual_1.default(model, prevProps.model)) { | ||
} | ||
// @ts-ignore | ||
_super.prototype.componentDidUpdate.apply(this, arguments); | ||
_super.prototype.componentDidUpdate.call(this, prevProps, prevState, snapshot); | ||
}; | ||
@@ -36,3 +35,5 @@ AutoForm.prototype.getNativeFormProps = function () { | ||
var _this = this; | ||
this.setState(function (state) { return ({ modelSync: set_1.default(cloneDeep_1.default(state.modelSync), key, value) }); }, function () { | ||
this.setState(function (state) { return ({ | ||
modelSync: setWith_1.default(clone_1.default(state.modelSync), key, value, clone_1.default), | ||
}); }, function () { | ||
_super.prototype.onChange.call(_this, key, value); | ||
@@ -53,7 +54,8 @@ _this.setState(function (state) { | ||
AutoForm.Auto = Auto; | ||
AutoForm.displayName = "Auto" + base.displayName; | ||
AutoForm.displayName = "Auto" + Base.displayName; | ||
return AutoForm; | ||
}(base)); | ||
}(Base)); | ||
return AutoForm; | ||
} | ||
exports.default = Auto(ValidatedQuickForm_1.default); | ||
exports.Auto = Auto; | ||
exports.AutoForm = Auto(ValidatedQuickForm_1.ValidatedQuickForm); |
@@ -1,9 +0,9 @@ | ||
import React, { Component, SyntheticEvent } from 'react'; | ||
import Bridge from './Bridge'; | ||
import { Component, SyntheticEvent } from 'react'; | ||
import { Bridge } from './Bridge'; | ||
import { ChangedMap, Context, DeepPartial, ModelTransformMode } from './types'; | ||
export declare type BaseFormProps<Model extends {}> = { | ||
export declare type BaseFormProps<Model> = { | ||
autosave: boolean; | ||
autosaveDelay: number; | ||
disabled?: boolean; | ||
error?: any; | ||
error: any; | ||
id?: string; | ||
@@ -15,11 +15,8 @@ label: boolean; | ||
onChange?(key: string, value: any): void; | ||
onSubmit?(model: DeepPartial<Model>): any; | ||
onSubmitSuccess?(result: any): void; | ||
onSubmitFailure?(result: any): void; | ||
onSubmit(model: DeepPartial<Model>): any; | ||
placeholder?: boolean; | ||
schema: any; | ||
schema: Bridge; | ||
showInlineError?: boolean; | ||
}; | ||
export declare type BaseFormState<Model extends {}> = { | ||
bridge: Bridge; | ||
export declare type BaseFormState<Model> = { | ||
changed: boolean; | ||
@@ -30,3 +27,3 @@ changedMap: ChangedMap<Model>; | ||
}; | ||
export default class BaseForm<Model extends {} = Record<string, any>, Props extends BaseFormProps<Model> = BaseFormProps<Model>, State extends BaseFormState<Model> = BaseFormState<Model>> extends Component<Props, State> { | ||
export declare class BaseForm<Model, Props extends BaseFormProps<Model> = BaseFormProps<Model>, State extends BaseFormState<Model> = BaseFormState<Model>> extends Component<Props, State> { | ||
static displayName: string; | ||
@@ -36,12 +33,11 @@ static defaultProps: { | ||
autosaveDelay: number; | ||
error: null; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
onSubmit(): void; | ||
}; | ||
constructor(props: Props); | ||
static getDerivedStateFromProps({ schema }: BaseFormProps<any>, { bridge }: BaseFormState<any>): { | ||
bridge: Bridge; | ||
}; | ||
componentDidMount(): void; | ||
componentDidUpdate(prevProps: any, prevState: any, snapshot: any): void; | ||
componentDidUpdate(prevProps: Props, prevState: State, snapshot: never): void; | ||
componentWillUnmount(): void; | ||
@@ -54,23 +50,17 @@ delayId?: any; | ||
randomId: () => string; | ||
getContext(): Context; | ||
getContextName(): never[]; | ||
getContextError(): Props["error"]; | ||
getContextModel(): DeepPartial<Model>; | ||
getContextState(): Context['state']; | ||
getContextSchema(): State["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: React.SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getModel(mode?: ModelTransformMode, model?: DeepPartial<Model>): DeepPartial<Model>; | ||
getChangedKeys<T>(root: string, valueA?: T, valueB?: T): string[]; | ||
getContext(): Context<Model>; | ||
getContextName(): Context<Model>['name']; | ||
getContextError(): Context<Model>['error']; | ||
getContextModel(): Context<Model>['model']; | ||
getContextState(): Context<Model>['state']; | ||
getContextSchema(): Context<Model>['schema']; | ||
getContextOnChange(): Context<Model>['onChange']; | ||
getContextOnSubmit(): Context<Model>['onSubmit']; | ||
getModel(mode?: ModelTransformMode, model?: DeepPartial<Model>): Context<Model>['model']; | ||
getNativeFormProps(): Record<string, any>; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State): { | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
__reset(state: State): Partial<State>; | ||
onReset(): void; | ||
onSubmit(event?: SyntheticEvent): Promise<void>; | ||
onSubmit(event?: SyntheticEvent): Promise<any>; | ||
render(): JSX.Element; | ||
} |
@@ -5,11 +5,9 @@ "use strict"; | ||
var react_1 = tslib_1.__importStar(require("react")); | ||
var cloneDeep_1 = tslib_1.__importDefault(require("lodash/cloneDeep")); | ||
var clone_1 = tslib_1.__importDefault(require("lodash/clone")); | ||
var get_1 = tslib_1.__importDefault(require("lodash/get")); | ||
var isFunction_1 = tslib_1.__importDefault(require("lodash/isFunction")); | ||
var omit_1 = tslib_1.__importDefault(require("lodash/omit")); | ||
var set_1 = tslib_1.__importDefault(require("lodash/set")); | ||
var changedKeys_1 = tslib_1.__importDefault(require("./changedKeys")); | ||
var context_1 = tslib_1.__importDefault(require("./context")); | ||
var createSchemaBridge_1 = tslib_1.__importDefault(require("./createSchemaBridge")); | ||
var randomIds_1 = tslib_1.__importDefault(require("./randomIds")); | ||
var setWith_1 = tslib_1.__importDefault(require("lodash/setWith")); | ||
var changedKeys_1 = require("./changedKeys"); | ||
var context_1 = require("./context"); | ||
var randomIds_1 = require("./randomIds"); | ||
var BaseForm = /** @class */ (function (_super) { | ||
@@ -21,3 +19,2 @@ tslib_1.__extends(BaseForm, _super); | ||
_this.state = { | ||
bridge: createSchemaBridge_1.default(_this.props.schema), | ||
changed: false, | ||
@@ -29,3 +26,3 @@ changedMap: Object.create(null), | ||
_this.mounted = false; | ||
_this.randomId = randomIds_1.default(_this.props.id); | ||
_this.randomId = randomIds_1.randomIds(_this.props.id); | ||
_this.onReset = _this.reset = _this.onReset.bind(_this); | ||
@@ -44,8 +41,2 @@ _this.onChange = _this.change = _this.onChange.bind(_this); | ||
} | ||
BaseForm.getDerivedStateFromProps = function (_a, _b) { | ||
var schema = _a.schema; | ||
var bridge = _b.bridge; | ||
// TODO: It updates the state each time. Add bridge.isSame(schema)? | ||
return { bridge: createSchemaBridge_1.default(schema) }; | ||
}; | ||
BaseForm.prototype.componentDidMount = function () { | ||
@@ -92,3 +83,3 @@ this.mounted = true; | ||
BaseForm.prototype.getContextSchema = function () { | ||
return this.state.bridge; | ||
return this.props.schema; | ||
}; | ||
@@ -105,5 +96,2 @@ BaseForm.prototype.getContextOnChange = function () { | ||
}; | ||
BaseForm.prototype.getChangedKeys = function (root, valueA, valueB) { | ||
return changedKeys_1.default(root, valueA, valueB); | ||
}; | ||
BaseForm.prototype.getNativeFormProps = function () { | ||
@@ -132,8 +120,13 @@ var props = omit_1.default(this.props, [ | ||
if (this.mounted) { | ||
var keys_1 = this.getChangedKeys(key, value, get_1.default(this.getModel(), key)); | ||
var keys_1 = changedKeys_1.changedKeys(key, value, get_1.default(this.getModel(), key)); | ||
if (keys_1.length !== 0) { | ||
this.setState(function (state) { return ({ | ||
changed: true, | ||
changedMap: keys_1.reduce(function (changedMap, key) { return set_1.default(changedMap, key, {}); }, cloneDeep_1.default(state.changedMap)), | ||
}); }); | ||
this.setState(function (state) { | ||
// If all are already marked, we can skip the update completely. | ||
return state.changed && keys_1.every(function (key) { return !!get_1.default(state.changedMap, key); }) | ||
? null | ||
: { | ||
changed: true, | ||
changedMap: keys_1.reduce(function (changedMap, key) { return setWith_1.default(changedMap, key, {}, clone_1.default); }, clone_1.default(state.changedMap)), | ||
}; | ||
}); | ||
} | ||
@@ -163,7 +156,8 @@ } | ||
changedMap: Object.create(null), | ||
resetCount: state.resetCount + 1, | ||
submitting: false, | ||
resetCount: state.resetCount + 1, | ||
}; | ||
}; | ||
BaseForm.prototype.onReset = function () { | ||
// @ts-ignore | ||
this.setState(this.__reset); | ||
@@ -177,18 +171,13 @@ }; | ||
} | ||
var result = this.props.onSubmit && this.props.onSubmit(this.getModel('submit')); | ||
// Set the `submitting` state only if onSubmit is async so we don't cause an unnecessary re-render | ||
var submitting; | ||
if (isPromiseLike(result)) { | ||
this.setState({ submitting: true }); | ||
submitting = result.finally(function () { | ||
_this.setState({ submitting: false }); | ||
}); | ||
var result = this.props.onSubmit(this.getModel('submit')); | ||
if (!(result instanceof Promise)) { | ||
return Promise.resolve(result); | ||
} | ||
else { | ||
submitting = Promise.resolve(result); | ||
} | ||
return submitting.then(this.props.onSubmitSuccess, this.props.onSubmitFailure); | ||
this.setState({ submitting: true }); | ||
return result.finally(function () { | ||
_this.setState({ submitting: false }); | ||
}); | ||
}; | ||
BaseForm.prototype.render = function () { | ||
return (react_1.default.createElement(context_1.default.Provider, { value: this.getContext() }, | ||
return (react_1.default.createElement(context_1.context.Provider, { value: this.getContext() }, | ||
react_1.default.createElement("form", tslib_1.__assign({}, this.getNativeFormProps())))); | ||
@@ -200,11 +189,10 @@ }; | ||
autosaveDelay: 0, | ||
error: null, | ||
label: true, | ||
model: Object.create(null), | ||
noValidate: true, | ||
onSubmit: function () { }, | ||
}; | ||
return BaseForm; | ||
}(react_1.Component)); | ||
exports.default = BaseForm; | ||
function isPromiseLike(value) { | ||
return !!value && isFunction_1.default(value.then); | ||
} | ||
exports.BaseForm = BaseForm; |
@@ -1,4 +0,3 @@ | ||
export default abstract class Bridge { | ||
export declare abstract class Bridge { | ||
constructor(...args: any[]); | ||
static check(schema: any): boolean; | ||
getError(name: string, error: any): any; | ||
@@ -12,3 +11,3 @@ getErrorMessage(name: string, error: any): string | undefined; | ||
getType(name: string): any; | ||
getValidator(options?: any): (model: Record<string, any>) => void; | ||
getValidator(options?: any): (model: Record<string, any>) => any; | ||
} |
@@ -13,5 +13,2 @@ "use strict"; | ||
} | ||
Bridge.check = function (schema) { | ||
return invariant_1.default(false, '%s have not implemented `check` method (args=%o).', this.name, { schema: schema }); | ||
}; | ||
Bridge.prototype.getError = function (name, error) { | ||
@@ -46,2 +43,2 @@ return invariant_1.default(false, '%s have not implemented `getError` method (args=%o).', this.constructor.name, { name: name, error: error }); | ||
}()); | ||
exports.default = Bridge; | ||
exports.Bridge = Bridge; |
@@ -1,1 +0,1 @@ | ||
export default function changedKeys<T>(root: string, valueA?: T, valueB?: T): string[]; | ||
export declare function changedKeys<T>(root: string, valueA?: T, valueB?: T): string[]; |
@@ -6,3 +6,3 @@ "use strict"; | ||
var xorWith_1 = tslib_1.__importDefault(require("lodash/xorWith")); | ||
var joinName_1 = tslib_1.__importDefault(require("./joinName")); | ||
var joinName_1 = require("./joinName"); | ||
function changedKeys(root, valueA, valueB) { | ||
@@ -12,4 +12,4 @@ if (!valueA || valueA !== Object(valueA) || valueA instanceof Date) | ||
if (!valueB) | ||
return tslib_1.__spreadArrays([root], Object.keys(valueA).map(function (key) { return joinName_1.default(root, key); })); | ||
var changed = xorWith_1.default(Object.entries(valueA), Object.entries(valueB), isEqual_1.default).map(function (pair) { return joinName_1.default(root, pair[0]); }); | ||
return tslib_1.__spreadArrays([root], Object.keys(valueA).map(function (key) { return joinName_1.joinName(root, key); })); | ||
var changed = xorWith_1.default(Object.entries(valueA), Object.entries(valueB), isEqual_1.default).map(function (pair) { return joinName_1.joinName(root, pair[0]); }); | ||
if (changed.length) | ||
@@ -19,2 +19,2 @@ changed.unshift(root); | ||
} | ||
exports.default = changedKeys; | ||
exports.changedKeys = changedKeys; |
import React, { ComponentType } from 'react'; | ||
import { GuaranteedProps } from './types'; | ||
export default function connectField<Props extends Partial<GuaranteedProps<Value>>, Value = Props['value']>(Component: ComponentType<Props>, options?: { | ||
export declare function connectField<Props extends Partial<GuaranteedProps<Value>>, Value = Props['value']>(Component: ComponentType<Props>, options?: { | ||
includeInChain?: boolean; | ||
@@ -8,2 +8,2 @@ initialValue?: boolean; | ||
name: string; | ||
} & Partial<GuaranteedProps<Value>> & Pick<Props, Exclude<keyof Props, "disabled" | "label" | "error" | "id" | "onChange" | "placeholder" | "showInlineError" | "changed" | "value" | "errorMessage" | "field" | "fieldType" | "fields" | "name">>>; | ||
} & Partial<GuaranteedProps<Value>> & Pick<Props, Exclude<keyof Props, "disabled" | "label" | "changed" | "error" | "id" | "onChange" | "placeholder" | "showInlineError" | "name" | "value" | "errorMessage" | "field" | "fieldType" | "fields">>>; |
@@ -7,7 +7,7 @@ "use strict"; | ||
var some_1 = tslib_1.__importDefault(require("lodash/some")); | ||
var context_1 = tslib_1.__importDefault(require("./context")); | ||
var useField_1 = tslib_1.__importDefault(require("./useField")); | ||
var context_1 = require("./context"); | ||
var useField_1 = require("./useField"); | ||
function connectField(Component, options) { | ||
function Field(props) { | ||
var _a = useField_1.default(props.name, props, options), fieldProps = _a[0], context = _a[1]; | ||
var _a = useField_1.useField(props.name, props, options), fieldProps = _a[0], context = _a[1]; | ||
var anyFlowingPropertySet = some_1.default(context.state, function (_, key) { return props[key] !== null && props[key] !== undefined; }); | ||
@@ -25,3 +25,3 @@ if (!anyFlowingPropertySet && (options === null || options === void 0 ? void 0 : options.includeInChain) === false) { | ||
nextContext.name = nextContext.name.concat(props.name); | ||
return (react_1.default.createElement(context_1.default.Provider, { value: nextContext }, | ||
return (react_1.default.createElement(context_1.context.Provider, { value: nextContext }, | ||
react_1.default.createElement(Component, tslib_1.__assign({}, props, fieldProps)))); | ||
@@ -32,2 +32,2 @@ } | ||
} | ||
exports.default = connectField; | ||
exports.connectField = connectField; |
/// <reference types="react" /> | ||
import { Context } from './types'; | ||
declare const _default: import("react").Context<Context<Record<string, any>> | null>; | ||
export default _default; | ||
export declare const context: import("react").Context<Context<any> | null>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var react_1 = require("react"); | ||
exports.default = react_1.createContext(null); | ||
exports.context = react_1.createContext(null); |
@@ -1,8 +0,8 @@ | ||
import Bridge from './Bridge'; | ||
import { Bridge } from './Bridge'; | ||
declare function create(schema: any): Bridge; | ||
declare function register(bridge: typeof Bridge): void; | ||
declare const _default: typeof create & { | ||
export declare const createSchemaBridge: typeof create & { | ||
register: typeof register; | ||
registered: (typeof Bridge)[]; | ||
}; | ||
export default _default; | ||
export {}; |
@@ -30,2 +30,5 @@ "use strict"; | ||
} | ||
exports.default = Object.assign(create, { register: register, registered: registered }); | ||
exports.createSchemaBridge = Object.assign(create, { | ||
register: register, | ||
registered: registered, | ||
}); |
@@ -1,7 +0,7 @@ | ||
declare function filter<T extends {}>(props: T): Partial<T>; | ||
declare function filter<T extends object>(props: T): Partial<T>; | ||
declare function register(...props: string[]): void; | ||
declare const _default: typeof filter & { | ||
export declare const filterDOMProps: typeof filter & { | ||
register: typeof register; | ||
registered: string[]; | ||
registered: readonly string[]; | ||
}; | ||
export default _default; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var omit_1 = tslib_1.__importDefault(require("lodash/omit")); | ||
var pickBy_1 = tslib_1.__importDefault(require("lodash/pickBy")); | ||
var sortedIndex_1 = tslib_1.__importDefault(require("lodash/sortedIndex")); | ||
var sortedIndexOf_1 = tslib_1.__importDefault(require("lodash/sortedIndexOf")); | ||
var registered = [ | ||
// These props are provided by BaseField | ||
// These props are provided by useField directly. | ||
'changed', | ||
'changedMap', | ||
'disabled', | ||
'error', | ||
@@ -15,23 +15,23 @@ 'errorMessage', | ||
'fields', | ||
'findError', | ||
'findField', | ||
'findValue', | ||
'initialCount', | ||
'label', | ||
'name', | ||
'onChange', | ||
'parent', | ||
'transform', | ||
'value', | ||
// These props are provided by useField through context.state. | ||
'disabled', | ||
'label', | ||
'placeholder', | ||
'showInlineError', | ||
'submitting', | ||
'transform', | ||
'validating', | ||
'value', | ||
// These are used by AutoField | ||
// This is used by AutoField. | ||
'component', | ||
// These is used by AutoField and bridges. | ||
'allowedValues', | ||
'component', | ||
]; | ||
].sort(); | ||
function filter(props) { | ||
return omit_1.default(props, registered); | ||
return pickBy_1.default(props, filterOne); | ||
} | ||
function filterOne(value, prop) { | ||
return sortedIndexOf_1.default(registered, prop) === -1; | ||
} | ||
function register() { | ||
@@ -43,7 +43,10 @@ var props = []; | ||
props.forEach(function (prop) { | ||
if (!registered.includes(prop)) { | ||
registered.push(prop); | ||
if (sortedIndexOf_1.default(registered, prop) === -1) { | ||
registered.splice(sortedIndex_1.default(registered, prop), 0, prop); | ||
} | ||
}); | ||
} | ||
exports.default = Object.assign(filter, { register: register, registered: registered }); | ||
exports.filterDOMProps = Object.assign(filter, { | ||
register: register, | ||
registered: registered, | ||
}); |
@@ -0,17 +1,16 @@ | ||
export * from './AutoForm'; | ||
export * from './BaseForm'; | ||
export * from './Bridge'; | ||
export * from './QuickForm'; | ||
export * from './ValidatedForm'; | ||
export * from './ValidatedQuickForm'; | ||
export * from './changedKeys'; | ||
export * from './connectField'; | ||
export * from './context'; | ||
export * from './filterDOMProps'; | ||
export * from './injectName'; | ||
export * from './joinName'; | ||
export * from './randomIds'; | ||
export * from './types'; | ||
export { default as AutoForm } from './AutoForm'; | ||
export { default as BaseForm } from './BaseForm'; | ||
export { default as Bridge } from './Bridge'; | ||
export { default as QuickForm } from './QuickForm'; | ||
export { default as ValidatedForm } from './ValidatedForm'; | ||
export { default as ValidatedQuickForm } from './ValidatedQuickForm'; | ||
export { default as changedKeys } from './changedKeys'; | ||
export { default as connectField } from './connectField'; | ||
export { default as context } from './context'; | ||
export { default as createSchemaBridge } from './createSchemaBridge'; | ||
export { default as filterDOMProps } from './filterDOMProps'; | ||
export { default as injectName } from './injectName'; | ||
export { default as joinName } from './joinName'; | ||
export { default as randomIds } from './randomIds'; | ||
export { default as useField } from './useField'; | ||
export { default as useForm } from './useForm'; | ||
export * from './useField'; | ||
export * from './useForm'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var AutoForm_1 = require("./AutoForm"); | ||
exports.AutoForm = AutoForm_1.default; | ||
var BaseForm_1 = require("./BaseForm"); | ||
exports.BaseForm = BaseForm_1.default; | ||
var Bridge_1 = require("./Bridge"); | ||
exports.Bridge = Bridge_1.default; | ||
var QuickForm_1 = require("./QuickForm"); | ||
exports.QuickForm = QuickForm_1.default; | ||
var ValidatedForm_1 = require("./ValidatedForm"); | ||
exports.ValidatedForm = ValidatedForm_1.default; | ||
var ValidatedQuickForm_1 = require("./ValidatedQuickForm"); | ||
exports.ValidatedQuickForm = ValidatedQuickForm_1.default; | ||
var changedKeys_1 = require("./changedKeys"); | ||
exports.changedKeys = changedKeys_1.default; | ||
var connectField_1 = require("./connectField"); | ||
exports.connectField = connectField_1.default; | ||
var context_1 = require("./context"); | ||
exports.context = context_1.default; | ||
var createSchemaBridge_1 = require("./createSchemaBridge"); | ||
exports.createSchemaBridge = createSchemaBridge_1.default; | ||
var filterDOMProps_1 = require("./filterDOMProps"); | ||
exports.filterDOMProps = filterDOMProps_1.default; | ||
var injectName_1 = require("./injectName"); | ||
exports.injectName = injectName_1.default; | ||
var joinName_1 = require("./joinName"); | ||
exports.joinName = joinName_1.default; | ||
var randomIds_1 = require("./randomIds"); | ||
exports.randomIds = randomIds_1.default; | ||
var useField_1 = require("./useField"); | ||
exports.useField = useField_1.default; | ||
var useForm_1 = require("./useForm"); | ||
exports.useForm = useForm_1.default; | ||
var tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./AutoForm"), exports); | ||
tslib_1.__exportStar(require("./BaseForm"), exports); | ||
tslib_1.__exportStar(require("./Bridge"), exports); | ||
tslib_1.__exportStar(require("./QuickForm"), exports); | ||
tslib_1.__exportStar(require("./ValidatedForm"), exports); | ||
tslib_1.__exportStar(require("./ValidatedQuickForm"), exports); | ||
tslib_1.__exportStar(require("./changedKeys"), exports); | ||
tslib_1.__exportStar(require("./connectField"), exports); | ||
tslib_1.__exportStar(require("./context"), exports); | ||
tslib_1.__exportStar(require("./filterDOMProps"), exports); | ||
tslib_1.__exportStar(require("./injectName"), exports); | ||
tslib_1.__exportStar(require("./joinName"), exports); | ||
tslib_1.__exportStar(require("./randomIds"), exports); | ||
tslib_1.__exportStar(require("./useField"), exports); | ||
tslib_1.__exportStar(require("./useForm"), exports); |
import { ReactNode } from 'react'; | ||
export default function injectName(name: string, children: ReactNode, parent?: ReactNode): ReactNode[]; | ||
export declare function injectName(name: string, children: ReactNode, parent?: ReactNode): ReactNode[]; |
@@ -6,3 +6,3 @@ "use strict"; | ||
var react_1 = require("react"); | ||
var joinName_1 = tslib_1.__importDefault(require("./joinName")); | ||
var joinName_1 = require("./joinName"); | ||
function injectName(name, children, parent) { | ||
@@ -16,6 +16,6 @@ return react_1.Children.map(react_1.Children.toArray(children), function (child) { | ||
children: injectName(name, element.props.children, child), | ||
name: joinName_1.default(name, element.props.name), | ||
name: joinName_1.joinName(name, element.props.name), | ||
}); | ||
}); | ||
} | ||
exports.default = injectName; | ||
exports.injectName = injectName; |
@@ -1,3 +0,2 @@ | ||
declare function joinName(flag: null, ...parts: unknown[]): string[]; | ||
declare function joinName(...parts: unknown[]): string; | ||
export default joinName; | ||
export declare function joinName(flag: null, ...parts: unknown[]): string[]; | ||
export declare function joinName(...parts: unknown[]): string; |
@@ -15,2 +15,2 @@ "use strict"; | ||
} | ||
exports.default = joinName; | ||
exports.joinName = joinName; |
import React, { ComponentType } from 'react'; | ||
import BaseForm, { BaseFormProps, BaseFormState } from './BaseForm'; | ||
export declare type QuickFormProps<Model extends {}> = BaseFormProps<Model> & { | ||
import { BaseForm, BaseFormProps, BaseFormState } from './BaseForm'; | ||
export declare type QuickFormProps<Model> = BaseFormProps<Model> & { | ||
autoField?: ComponentType<{ | ||
name?: string; | ||
name: string; | ||
}>; | ||
@@ -10,8 +10,8 @@ errorsField?: ComponentType; | ||
}; | ||
export declare type QuickFormState<Model extends {}> = BaseFormState<Model>; | ||
declare function Quick<Base extends typeof BaseForm>(base: Base): { | ||
new <Model extends {} = Record<string, any>, Props extends QuickFormProps<Model> = QuickFormProps<Model>, State extends BaseFormState<Model> = BaseFormState<Model>>(props: Props): { | ||
export declare type QuickFormState<Model> = BaseFormState<Model>; | ||
export declare function Quick<Base extends typeof BaseForm>(Base: Base): { | ||
new <Model, Props extends QuickFormProps<Model> = QuickFormProps<Model>, State extends BaseFormState<Model> = BaseFormState<Model>>(props: Props): { | ||
getNativeFormProps(): Record<string, any>; | ||
getAutoField(): React.ComponentType<{ | ||
name?: string | undefined; | ||
name: string; | ||
}>; | ||
@@ -21,3 +21,3 @@ getErrorsField(): React.ComponentType<{}>; | ||
componentDidMount(): void; | ||
componentDidUpdate(prevProps: any, prevState: any, snapshot: any): void; | ||
componentDidUpdate(prevProps: Props, prevState: State, snapshot: never): void; | ||
componentWillUnmount(): void; | ||
@@ -30,5 +30,5 @@ delayId?: any; | ||
randomId: () => string; | ||
getContext(): import("./types").Context<Record<string, any>>; | ||
getContextName(): never[]; | ||
getContextError(): Props["error"]; | ||
getContext(): import("./types").Context<Model>; | ||
getContextName(): string[]; | ||
getContextError(): any; | ||
getContextModel(): import("./types").DeepPartial<Model>; | ||
@@ -41,16 +41,10 @@ getContextState(): { | ||
}; | ||
getContextSchema(): State["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: React.SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getContextSchema(): import("./Bridge").Bridge; | ||
getContextOnChange(): (key: string, value?: any) => void; | ||
getContextOnSubmit(): (event?: React.SyntheticEvent<Element, Event> | undefined) => any; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: import("./types").DeepPartial<Model>): import("./types").DeepPartial<Model>; | ||
getChangedKeys<T>(root: string, valueA?: T | undefined, valueB?: T | undefined): string[]; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State): { | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
__reset(state: State): Partial<State>; | ||
onReset(): void; | ||
onSubmit(event?: React.SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
onSubmit(event?: React.SyntheticEvent<Element, Event> | undefined): Promise<any>; | ||
render(): JSX.Element; | ||
@@ -82,16 +76,15 @@ context: any; | ||
autosaveDelay: number; | ||
error: null; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
onSubmit(): void; | ||
}; | ||
getDerivedStateFromProps({ schema }: BaseFormProps<any>, { bridge }: BaseFormState<any>): { | ||
bridge: import("./Bridge").default; | ||
}; | ||
contextType?: React.Context<any> | undefined; | ||
} & Base; | ||
declare const _default: { | ||
new <Model extends {} = Record<string, any>, Props extends QuickFormProps<Model> = QuickFormProps<Model>, State extends BaseFormState<Model> = BaseFormState<Model>>(props: Props): { | ||
export declare const QuickForm: { | ||
new <Model, Props extends QuickFormProps<Model> = QuickFormProps<Model>, State extends BaseFormState<Model> = BaseFormState<Model>>(props: Props): { | ||
getNativeFormProps(): Record<string, any>; | ||
getAutoField(): React.ComponentType<{ | ||
name?: string | undefined; | ||
name: string; | ||
}>; | ||
@@ -101,3 +94,3 @@ getErrorsField(): React.ComponentType<{}>; | ||
componentDidMount(): void; | ||
componentDidUpdate(prevProps: any, prevState: any, snapshot: any): void; | ||
componentDidUpdate(prevProps: Props, prevState: State, snapshot: never): void; | ||
componentWillUnmount(): void; | ||
@@ -110,5 +103,5 @@ delayId?: any; | ||
randomId: () => string; | ||
getContext(): import("./types").Context<Record<string, any>>; | ||
getContextName(): never[]; | ||
getContextError(): Props["error"]; | ||
getContext(): import("./types").Context<Model>; | ||
getContextName(): string[]; | ||
getContextError(): any; | ||
getContextModel(): import("./types").DeepPartial<Model>; | ||
@@ -121,16 +114,10 @@ getContextState(): { | ||
}; | ||
getContextSchema(): State["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: React.SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getContextSchema(): import("./Bridge").Bridge; | ||
getContextOnChange(): (key: string, value?: any) => void; | ||
getContextOnSubmit(): (event?: React.SyntheticEvent<Element, Event> | undefined) => any; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: import("./types").DeepPartial<Model>): import("./types").DeepPartial<Model>; | ||
getChangedKeys<T>(root: string, valueA?: T | undefined, valueB?: T | undefined): string[]; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State): { | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
__reset(state: State): Partial<State>; | ||
onReset(): void; | ||
onSubmit(event?: React.SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
onSubmit(event?: React.SyntheticEvent<Element, Event> | undefined): Promise<any>; | ||
render(): JSX.Element; | ||
@@ -162,11 +149,10 @@ context: any; | ||
autosaveDelay: number; | ||
error: null; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
onSubmit(): void; | ||
}; | ||
getDerivedStateFromProps({ schema }: BaseFormProps<any>, { bridge }: BaseFormState<any>): { | ||
bridge: import("./Bridge").default; | ||
}; | ||
contextType?: React.Context<any> | undefined; | ||
} & typeof BaseForm; | ||
export default _default; | ||
export declare type QuickForm = typeof QuickForm; |
@@ -5,4 +5,4 @@ "use strict"; | ||
var react_1 = tslib_1.__importDefault(require("react")); | ||
var BaseForm_1 = tslib_1.__importDefault(require("./BaseForm")); | ||
function Quick(base) { | ||
var BaseForm_1 = require("./BaseForm"); | ||
function Quick(Base) { | ||
// @ts-ignore: Mixin class problem. | ||
@@ -37,7 +37,8 @@ var QuickForm = /** @class */ (function (_super) { | ||
QuickForm.Quick = Quick; | ||
QuickForm.displayName = "Quick" + base.displayName; | ||
QuickForm.displayName = "Quick" + Base.displayName; | ||
return QuickForm; | ||
}(base)); | ||
}(Base)); | ||
return QuickForm; | ||
} | ||
exports.default = Quick(BaseForm_1.default); | ||
exports.Quick = Quick; | ||
exports.QuickForm = Quick(BaseForm_1.BaseForm); |
@@ -1,1 +0,1 @@ | ||
export default function randomIds(prefix?: string): () => string; | ||
export declare function randomIds(prefix?: string): () => string; |
@@ -15,2 +15,2 @@ "use strict"; | ||
} | ||
exports.default = randomIds; | ||
exports.randomIds = randomIds; |
import { SyntheticEvent } from 'react'; | ||
import Bridge from './Bridge'; | ||
import { Bridge } from './Bridge'; | ||
export declare type ChangedMap<T> = T extends {} ? { | ||
[P in keyof T]?: ChangedMap<T[P]>; | ||
} : Record<string, void>; | ||
export declare type Context<Model extends {} = Record<string, any>> = { | ||
export declare type Context<Model> = { | ||
changed: boolean; | ||
@@ -45,4 +45,4 @@ changedMap: ChangedMap<Model>; | ||
export declare type ModelTransformMode = 'form' | 'submit' | 'validate'; | ||
export declare type Override<T, U> = U & Omit<T, keyof U>; | ||
export declare type Partialize<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>; | ||
export declare type ValidateMode = 'onChange' | 'onChangeAfterSubmit' | 'onSubmit'; | ||
export declare type Override<T, U> = U & Omit<T, keyof U>; |
import { GuaranteedProps } from './types'; | ||
export default function useField<Props extends Record<string, any>, Value = Props['value'], Model = Record<string, any>>(fieldName: string, props: Props, options?: { | ||
export declare function useField<Props extends Record<string, any>, Value = Props['value'], Model = Record<string, any>>(fieldName: string, props: Props, options?: { | ||
initialValue?: boolean; | ||
}): [GuaranteedProps<Value> & Props, import("./types").Context<Model>]; |
@@ -7,4 +7,4 @@ "use strict"; | ||
var react_1 = require("react"); | ||
var joinName_1 = tslib_1.__importDefault(require("./joinName")); | ||
var useForm_1 = tslib_1.__importDefault(require("./useForm")); | ||
var joinName_1 = require("./joinName"); | ||
var useForm_1 = require("./useForm"); | ||
function propagate(prop, schema, state, fallback) { | ||
@@ -22,4 +22,4 @@ var schemaDisabled = schema === false || schema === ''; | ||
var _a, _b; | ||
var context = useForm_1.default(); | ||
var name = joinName_1.default(context.name, fieldName); | ||
var context = useForm_1.useForm(); | ||
var name = joinName_1.joinName(context.name, fieldName); | ||
var state = mapValues_1.default(context.state, function (prev, key) { | ||
@@ -71,2 +71,2 @@ var next = props[key]; | ||
} | ||
exports.default = useField; | ||
exports.useField = useField; |
import { Context } from './types'; | ||
export default function useForm<Model extends {}>(): Context<Model>; | ||
export declare function useForm<Model>(): Context<Model>; |
@@ -6,8 +6,8 @@ "use strict"; | ||
var react_1 = require("react"); | ||
var context_1 = tslib_1.__importDefault(require("./context")); | ||
var context_1 = require("./context"); | ||
function useForm() { | ||
var context = react_1.useContext(context_1.default); | ||
var context = react_1.useContext(context_1.context); | ||
invariant_1.default(context !== null, 'useForm must be used within a form.'); | ||
return context; | ||
} | ||
exports.default = useForm; | ||
exports.useForm = useForm; |
import { SyntheticEvent } from 'react'; | ||
import BaseForm, { BaseFormProps, BaseFormState } from './BaseForm'; | ||
import { DeepPartial, ValidateMode } from './types'; | ||
export declare type ValidatedFormProps<Model extends {}> = BaseFormProps<Model> & { | ||
onValidate: (model: DeepPartial<Model>, error: any, callback: (error?: any) => void) => void; | ||
import { BaseForm, BaseFormProps, BaseFormState } from './BaseForm'; | ||
import { Context, DeepPartial, ValidateMode } from './types'; | ||
export declare type ValidatedFormProps<Model> = BaseFormProps<Model> & { | ||
onValidate(model: DeepPartial<Model>, error: any): any; | ||
validate: ValidateMode; | ||
validator?: any; | ||
}; | ||
export declare type ValidatedFormState<Model extends {}> = BaseFormState<Model> & { | ||
export declare type ValidatedFormState<Model> = BaseFormState<Model> & { | ||
error: any; | ||
validate: boolean; | ||
validating: boolean; | ||
validator: (model: DeepPartial<Model>) => void | never; | ||
validator(model: DeepPartial<Model>): any; | ||
}; | ||
declare function Validated<Base extends typeof BaseForm>(base: Base): { | ||
new <Model extends {} = Record<string, any>, Props extends ValidatedFormProps<Model> = ValidatedFormProps<Model>, State extends ValidatedFormState<Model> = ValidatedFormState<Model>>(props: Props): { | ||
validate: (key?: string | undefined, value?: any) => Promise<unknown>; | ||
validateModel: (model: any) => Promise<unknown>; | ||
getContextError(): State["error"]; | ||
getContext(): { | ||
validating: State["validating"]; | ||
changed: boolean; | ||
changedMap: { | ||
[x: string]: Record<string, void> | { | ||
[x: string]: Record<string, void> | any | undefined; | ||
} | undefined; | ||
}; | ||
error: any; | ||
model: DeepPartial<Record<string, any>>; | ||
name: string[]; | ||
onChange(key: string, value?: any): void; | ||
onSubmit(event?: SyntheticEvent<Element, Event> | undefined): any; | ||
randomId(): string; | ||
schema: import("./Bridge").default; | ||
state: { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
submitting: boolean; | ||
}; | ||
export declare function Validated<Base extends typeof BaseForm>(Base: Base): { | ||
new <Model, Props extends ValidatedFormProps<Model> = ValidatedFormProps<Model>, State extends ValidatedFormState<Model> = ValidatedFormState<Model>>(props: Props): { | ||
validate: (key?: string | undefined, value?: any) => Promise<any>; | ||
validateModel: (originalModel: any) => Promise<any>; | ||
getContextError(): any; | ||
getContext(): Context<Model>; | ||
getNativeFormProps(): Record<string, any>; | ||
componentDidUpdate(prevProps: Props, prevState: State, snapshot: never): void; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State): { | ||
error: null; | ||
validate: boolean; | ||
validating: boolean; | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
onSubmit(event?: SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
onValidate(key?: string | undefined, value?: any): Promise<unknown>; | ||
onValidateModel(model: Props["model"]): Promise<unknown>; | ||
__reset(state: State): Partial<State>; | ||
onSubmit(event?: SyntheticEvent<Element, Event> | undefined): Promise<any>; | ||
onValidate(key?: string | undefined, value?: any): Promise<any>; | ||
onValidateModel(originalModel: Props["model"]): Promise<any>; | ||
componentDidMount(): void; | ||
@@ -66,3 +36,3 @@ componentWillUnmount(): void; | ||
randomId: () => string; | ||
getContextName(): never[]; | ||
getContextName(): string[]; | ||
getContextModel(): DeepPartial<Model>; | ||
@@ -75,7 +45,6 @@ getContextState(): { | ||
}; | ||
getContextSchema(): State["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getContextSchema(): import("./Bridge").Bridge; | ||
getContextOnChange(): (key: string, value?: any) => void; | ||
getContextOnSubmit(): (event?: SyntheticEvent<Element, Event> | undefined) => any; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: DeepPartial<Model>): DeepPartial<Model>; | ||
getChangedKeys<T>(root: string, valueA?: T | undefined, valueB?: T | undefined): string[]; | ||
onReset(): void; | ||
@@ -106,58 +75,27 @@ render(): JSX.Element; | ||
defaultProps: { | ||
onValidate(model: any, error: any, callback: any): void; | ||
onValidate(model: any, error: any): any; | ||
validate: string; | ||
autosave: boolean; | ||
autosaveDelay: number; | ||
error: null; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
onSubmit(): void; | ||
}; | ||
getDerivedStateFromProps({ schema }: BaseFormProps<any>, { bridge }: BaseFormState<any>): { | ||
bridge: import("./Bridge").default; | ||
}; | ||
contextType?: import("react").Context<any> | undefined; | ||
} & Base; | ||
declare const _default: { | ||
new <Model extends {} = Record<string, any>, Props extends ValidatedFormProps<Model> = ValidatedFormProps<Model>, State extends ValidatedFormState<Model> = ValidatedFormState<Model>>(props: Props): { | ||
validate: (key?: string | undefined, value?: any) => Promise<unknown>; | ||
validateModel: (model: any) => Promise<unknown>; | ||
getContextError(): State["error"]; | ||
getContext(): { | ||
validating: State["validating"]; | ||
changed: boolean; | ||
changedMap: { | ||
[x: string]: Record<string, void> | { | ||
[x: string]: Record<string, void> | any | undefined; | ||
} | undefined; | ||
}; | ||
error: any; | ||
model: DeepPartial<Record<string, any>>; | ||
name: string[]; | ||
onChange(key: string, value?: any): void; | ||
onSubmit(event?: SyntheticEvent<Element, Event> | undefined): any; | ||
randomId(): string; | ||
schema: import("./Bridge").default; | ||
state: { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
submitting: boolean; | ||
}; | ||
export declare const ValidatedForm: { | ||
new <Model, Props extends ValidatedFormProps<Model> = ValidatedFormProps<Model>, State extends ValidatedFormState<Model> = ValidatedFormState<Model>>(props: Props): { | ||
validate: (key?: string | undefined, value?: any) => Promise<any>; | ||
validateModel: (originalModel: any) => Promise<any>; | ||
getContextError(): any; | ||
getContext(): Context<Model>; | ||
getNativeFormProps(): Record<string, any>; | ||
componentDidUpdate(prevProps: Props, prevState: State, snapshot: never): void; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State): { | ||
error: null; | ||
validate: boolean; | ||
validating: boolean; | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
onSubmit(event?: SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
onValidate(key?: string | undefined, value?: any): Promise<unknown>; | ||
onValidateModel(model: Props["model"]): Promise<unknown>; | ||
__reset(state: State): Partial<State>; | ||
onSubmit(event?: SyntheticEvent<Element, Event> | undefined): Promise<any>; | ||
onValidate(key?: string | undefined, value?: any): Promise<any>; | ||
onValidateModel(originalModel: Props["model"]): Promise<any>; | ||
componentDidMount(): void; | ||
@@ -171,3 +109,3 @@ componentWillUnmount(): void; | ||
randomId: () => string; | ||
getContextName(): never[]; | ||
getContextName(): string[]; | ||
getContextModel(): DeepPartial<Model>; | ||
@@ -180,7 +118,6 @@ getContextState(): { | ||
}; | ||
getContextSchema(): State["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getContextSchema(): import("./Bridge").Bridge; | ||
getContextOnChange(): (key: string, value?: any) => void; | ||
getContextOnSubmit(): (event?: SyntheticEvent<Element, Event> | undefined) => any; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: DeepPartial<Model>): DeepPartial<Model>; | ||
getChangedKeys<T>(root: string, valueA?: T | undefined, valueB?: T | undefined): string[]; | ||
onReset(): void; | ||
@@ -211,15 +148,14 @@ render(): JSX.Element; | ||
defaultProps: { | ||
onValidate(model: any, error: any, callback: any): void; | ||
onValidate(model: any, error: any): any; | ||
validate: string; | ||
autosave: boolean; | ||
autosaveDelay: number; | ||
error: null; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
onSubmit(): void; | ||
}; | ||
getDerivedStateFromProps({ schema }: BaseFormProps<any>, { bridge }: BaseFormState<any>): { | ||
bridge: import("./Bridge").default; | ||
}; | ||
contextType?: import("react").Context<any> | undefined; | ||
} & typeof BaseForm; | ||
export default _default; | ||
export declare type ValidatedForm = typeof ValidatedForm; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var clone_1 = tslib_1.__importDefault(require("lodash/clone")); | ||
var cloneDeep_1 = tslib_1.__importDefault(require("lodash/cloneDeep")); | ||
@@ -8,5 +9,5 @@ var isEqual_1 = tslib_1.__importDefault(require("lodash/isEqual")); | ||
var omit_1 = tslib_1.__importDefault(require("lodash/omit")); | ||
var set_1 = tslib_1.__importDefault(require("lodash/set")); | ||
var BaseForm_1 = tslib_1.__importDefault(require("./BaseForm")); | ||
function Validated(base) { | ||
var setWith_1 = tslib_1.__importDefault(require("lodash/setWith")); | ||
var BaseForm_1 = require("./BaseForm"); | ||
function Validated(Base) { | ||
// @ts-ignore: Mixin class problem. | ||
@@ -17,3 +18,3 @@ var ValidatedForm = /** @class */ (function (_super) { | ||
var _this = _super.call(this, props) || this; | ||
_this.state = tslib_1.__assign(tslib_1.__assign({}, _this.state), { error: null, validate: false, validating: false, validator: _this.getContextSchema().getValidator(_this.props.validator) }); | ||
_this.state = tslib_1.__assign(tslib_1.__assign({}, _this.state), { error: null, validate: false, validating: false, validator: _this.getContextSchema().getValidator(props.validator) }); | ||
_this.onValidate = _this.validate = _this.onValidate.bind(_this); | ||
@@ -24,3 +25,4 @@ _this.onValidateModel = _this.validateModel = _this.onValidateModel.bind(_this); | ||
ValidatedForm.prototype.getContextError = function () { | ||
return _super.prototype.getContextError.call(this) || this.state.error; | ||
var _a; | ||
return (_a = _super.prototype.getContextError.call(this)) !== null && _a !== void 0 ? _a : this.state.error; | ||
}; | ||
@@ -42,5 +44,5 @@ ValidatedForm.prototype.getContext = function () { | ||
if (schema !== prevProps.schema || validator !== prevProps.validator) { | ||
this.setState(function (state) { return ({ validator: state.bridge.getValidator(validator) }); }, function () { | ||
this.setState({ validator: schema.getValidator(validator) }, function () { | ||
if (shouldRevalidate(validate, _this.state.validate)) { | ||
_this.onValidate().catch(noop_1.default); | ||
_this.onValidate(); | ||
} | ||
@@ -51,3 +53,3 @@ }); | ||
shouldRevalidate(validate, this.state.validate)) { | ||
this.onValidateModel(model).catch(noop_1.default); | ||
this.onValidateModel(model); | ||
} | ||
@@ -57,8 +59,4 @@ }; | ||
if (shouldRevalidate(this.props.validate, this.state.validate)) { | ||
this.onValidate(key, value).catch(noop_1.default); | ||
this.onValidate(key, value); | ||
} | ||
// FIXME: https://github.com/vazco/uniforms/issues/293 | ||
// if (this.props.validate === 'onSubmit' && this.state.validate) { | ||
// this.setState(() => ({error: null})); | ||
// } | ||
_super.prototype.onChange.call(this, key, value); | ||
@@ -75,25 +73,16 @@ }; | ||
} | ||
var promise = new Promise(function (resolve, reject) { | ||
_this.setState(function () { return ({ submitting: true, validate: true }); }, function () { | ||
_this.onValidate().then(function () { | ||
_super.prototype.onSubmit.call(_this).then(resolve, function (error) { | ||
_this.setState({ error: error }); | ||
reject(error); | ||
}); | ||
}, reject); | ||
this.setState({ validate: true }); | ||
var result = this.onValidate().then(function (error) { | ||
if (error !== null) { | ||
return Promise.reject(error); | ||
} | ||
// Validation failed (i.e. returned an error), so no error is present | ||
// both in the props nor the state. | ||
return _super.prototype.onSubmit.call(_this).catch(function (error) { | ||
_this.setState({ error: error }); | ||
throw error; | ||
}); | ||
}); | ||
promise | ||
// `onSubmit` should never reject, so we ignore this rejection. | ||
.catch(noop_1.default) | ||
.then(function () { | ||
// It can be already unmounted. | ||
if (_this.mounted) { | ||
// If validation fails, or `super.onSubmit` doesn't touch `submitting`, we need to reset it. | ||
_this.setState(function (state) { | ||
return state.submitting ? { submitting: false } : null; | ||
}); | ||
} | ||
}); | ||
return promise; | ||
result.catch(noop_1.default); | ||
return result; | ||
}; | ||
@@ -103,32 +92,31 @@ ValidatedForm.prototype.onValidate = function (key, value) { | ||
if (model && key) { | ||
model = set_1.default(cloneDeep_1.default(model), key, cloneDeep_1.default(value)); | ||
model = setWith_1.default(clone_1.default(model), key, cloneDeep_1.default(value), clone_1.default); | ||
} | ||
return this.onValidateModel(model); | ||
}; | ||
ValidatedForm.prototype.onValidateModel = function (model) { | ||
ValidatedForm.prototype.onValidateModel = function (originalModel) { | ||
var _this = this; | ||
model = this.getModel('validate', model); | ||
var catched = this.props.error || null; | ||
try { | ||
this.state.validator(model); | ||
} | ||
catch (error) { | ||
catched = error; | ||
} | ||
this.setState({ validating: true }); | ||
return new Promise(function (resolve, reject) { | ||
_this.props.onValidate(model, catched, function (error) { | ||
if (error === void 0) { error = catched; } | ||
// Do not copy error from props to state. | ||
_this.setState(function () { return ({ | ||
error: error === _this.props.error ? null : error, | ||
validating: false, | ||
}); }, function () { | ||
if (error) { | ||
reject(error); | ||
} | ||
else { | ||
resolve(); | ||
} | ||
var model = this.getModel('validate', originalModel); | ||
// Using `then` allows using the same code for both synchronous and | ||
// asynchronous cases. We could use `await` here, but it would make all | ||
// calls asynchronous, unnecessary delaying synchronous validation. | ||
var then = makeThen(function () { | ||
_this.setState({ validating: true }); | ||
}); | ||
return then(this.state.validator(model), function (error) { | ||
if (error === void 0) { error = null; } | ||
return then(_this.props.onValidate(model, error), function (error) { | ||
if (error === void 0) { error = null; } | ||
var _a; | ||
// Do not copy the error from props to the state. | ||
error = _this.props.error === error ? null : error; | ||
// If the whole operation was synchronous and resulted in the same | ||
// error, we can skip the re-render. | ||
_this.setState(function (state) { | ||
return state.error === error && !state.validating | ||
? null | ||
: { error: error, validating: false }; | ||
}); | ||
// A predefined error takes precedence over the validation one. | ||
return Promise.resolve((_a = _this.props.error) !== null && _a !== void 0 ? _a : error); | ||
}); | ||
@@ -138,13 +126,24 @@ }); | ||
ValidatedForm.Validated = Validated; | ||
ValidatedForm.displayName = "Validated" + base.displayName; | ||
ValidatedForm.defaultProps = tslib_1.__assign(tslib_1.__assign({}, base.defaultProps), { onValidate: function (model, error, callback) { | ||
callback(); | ||
ValidatedForm.displayName = "Validated" + Base.displayName; | ||
ValidatedForm.defaultProps = tslib_1.__assign(tslib_1.__assign({}, Base.defaultProps), { onValidate: function (model, error) { | ||
return error; | ||
}, validate: 'onChangeAfterSubmit' }); | ||
return ValidatedForm; | ||
}(base)); | ||
}(Base)); | ||
return ValidatedForm; | ||
} | ||
exports.Validated = Validated; | ||
function makeThen(callIfAsync) { | ||
function then(value, fn) { | ||
if (value instanceof Promise) { | ||
callIfAsync(); | ||
return value.then(fn); | ||
} | ||
return fn(value); | ||
} | ||
return then; | ||
} | ||
function shouldRevalidate(inProps, inState) { | ||
return (inProps === 'onChange' || (inProps === 'onChangeAfterSubmit' && inState)); | ||
} | ||
exports.default = Validated(BaseForm_1.default); | ||
exports.ValidatedForm = Validated(BaseForm_1.BaseForm); |
/// <reference types="react" /> | ||
import BaseForm from './BaseForm'; | ||
import { QuickFormProps, QuickFormState } from './QuickForm'; | ||
import { ValidatedFormProps, ValidatedFormState } from './ValidatedForm'; | ||
import { BaseForm } from './BaseForm'; | ||
import { Quick, QuickFormProps, QuickFormState } from './QuickForm'; | ||
import { Validated, ValidatedFormProps, ValidatedFormState } from './ValidatedForm'; | ||
export declare type ValidatedQuickFormProps<Model> = QuickFormProps<Model> & ValidatedFormProps<Model>; | ||
export declare type ValidatedQuickFormState<Model> = QuickFormState<Model> & ValidatedFormState<Model>; | ||
declare const _default: { | ||
new <Model extends {} = Record<string, any>, Props extends ValidatedFormProps<Model> = ValidatedFormProps<Model>, State extends ValidatedFormState<Model> = ValidatedFormState<Model>>(props: Props): { | ||
validate: (key?: string | undefined, value?: any) => Promise<unknown>; | ||
validateModel: (model: any) => Promise<unknown>; | ||
getContextError(): State["error"]; | ||
getContext(): { | ||
validating: State["validating"]; | ||
changed: boolean; | ||
changedMap: { | ||
[x: string]: Record<string, void> | { | ||
[x: string]: Record<string, void> | any | undefined; | ||
} | undefined; | ||
}; | ||
error: any; | ||
model: import("./types").DeepPartial<Record<string, any>>; | ||
name: string[]; | ||
onChange(key: string, value?: any): void; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): any; | ||
randomId(): string; | ||
schema: import("./Bridge").default; | ||
state: { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
submitting: boolean; | ||
}; | ||
export declare const ValidatedQuickForm: { | ||
new <Model, Props extends ValidatedFormProps<Model> = ValidatedFormProps<Model>, State extends ValidatedFormState<Model> = ValidatedFormState<Model>>(props: Props): { | ||
validate: (key?: string | undefined, value?: any) => Promise<any>; | ||
validateModel: (originalModel: any) => Promise<any>; | ||
getContextError(): any; | ||
getContext(): import("./types").Context<Model>; | ||
getNativeFormProps(): Record<string, any>; | ||
componentDidUpdate(prevProps: Props, prevState: State, snapshot: never): void; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State): { | ||
error: null; | ||
validate: boolean; | ||
validating: boolean; | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
onValidate(key?: string | undefined, value?: any): Promise<unknown>; | ||
onValidateModel(model: Props["model"]): Promise<unknown>; | ||
__reset(state: State): Partial<State>; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<any>; | ||
onValidate(key?: string | undefined, value?: any): Promise<any>; | ||
onValidateModel(originalModel: Props["model"]): Promise<any>; | ||
componentDidMount(): void; | ||
@@ -58,3 +28,3 @@ componentWillUnmount(): void; | ||
randomId: () => string; | ||
getContextName(): never[]; | ||
getContextName(): string[]; | ||
getContextModel(): import("./types").DeepPartial<Model>; | ||
@@ -67,7 +37,6 @@ getContextState(): { | ||
}; | ||
getContextSchema(): State["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getContextSchema(): import("./Bridge").Bridge; | ||
getContextOnChange(): (key: string, value?: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => any; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: import("./types").DeepPartial<Model>): import("./types").DeepPartial<Model>; | ||
getChangedKeys<T>(root: string, valueA?: T | undefined, valueB?: T | undefined): string[]; | ||
onReset(): void; | ||
@@ -95,123 +64,21 @@ render(): JSX.Element; | ||
}; | ||
Validated: <Base extends typeof BaseForm>(base: Base) => { | ||
new <Model_1 extends {} = Record<string, any>, Props_1 extends ValidatedFormProps<Model_1> = ValidatedFormProps<Model_1>, State_1 extends ValidatedFormState<Model_1> = ValidatedFormState<Model_1>>(props: Props_1): { | ||
validate: (key?: string | undefined, value?: any) => Promise<unknown>; | ||
validateModel: (model: any) => Promise<unknown>; | ||
getContextError(): State_1["error"]; | ||
getContext(): { | ||
validating: State_1["validating"]; | ||
changed: boolean; | ||
changedMap: { | ||
[x: string]: Record<string, void> | { | ||
[x: string]: Record<string, void> | any | undefined; | ||
} | undefined; | ||
}; | ||
error: any; | ||
model: import("./types").DeepPartial<Record<string, any>>; | ||
name: string[]; | ||
onChange(key: string, value?: any): void; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): any; | ||
randomId(): string; | ||
schema: import("./Bridge").default; | ||
state: { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
submitting: boolean; | ||
}; | ||
getNativeFormProps(): Record<string, any>; | ||
componentDidUpdate(prevProps: Props_1, prevState: State_1, snapshot: never): void; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State_1): { | ||
error: null; | ||
validate: boolean; | ||
validating: boolean; | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
onValidate(key?: string | undefined, value?: any): Promise<unknown>; | ||
onValidateModel(model: Props_1["model"]): Promise<unknown>; | ||
componentDidMount(): void; | ||
componentWillUnmount(): void; | ||
delayId?: any; | ||
mounted: boolean; | ||
reset: () => void; | ||
change: (key: string, value: any) => void; | ||
submit: (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<any>; | ||
randomId: () => string; | ||
getContextName(): never[]; | ||
getContextModel(): import("./types").DeepPartial<Model_1>; | ||
getContextState(): { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
getContextSchema(): State_1["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: import("./types").DeepPartial<Model_1>): import("./types").DeepPartial<Model_1>; | ||
getChangedKeys<T_1>(root: string, valueA?: T_1 | undefined, valueB?: T_1 | undefined): string[]; | ||
onReset(): void; | ||
render(): JSX.Element; | ||
context: any; | ||
setState<K_1 extends keyof State_1>(state: State_1 | ((prevState: Readonly<State_1>, props: Readonly<Props_1>) => State_1 | Pick<State_1, K_1> | null) | Pick<State_1, K_1> | null, callback?: (() => void) | undefined): void; | ||
forceUpdate(callback?: (() => void) | undefined): void; | ||
readonly props: Readonly<Props_1> & Readonly<{ | ||
children?: import("react").ReactNode; | ||
}>; | ||
state: Readonly<State_1>; | ||
refs: { | ||
[key: string]: import("react").ReactInstance; | ||
}; | ||
shouldComponentUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): boolean; | ||
componentDidCatch?(error: Error, errorInfo: import("react").ErrorInfo): void; | ||
getSnapshotBeforeUpdate?(prevProps: Readonly<Props_1>, prevState: Readonly<State_1>): any; | ||
componentWillMount?(): void; | ||
UNSAFE_componentWillMount?(): void; | ||
componentWillReceiveProps?(nextProps: Readonly<Props_1>, nextContext: any): void; | ||
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<Props_1>, nextContext: any): void; | ||
componentWillUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): void; | ||
UNSAFE_componentWillUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): void; | ||
}; | ||
Validated: any; | ||
displayName: string; | ||
defaultProps: { | ||
onValidate(model: any, error: any, callback: any): void; | ||
validate: string; | ||
autosave: boolean; | ||
autosaveDelay: number; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
}; | ||
getDerivedStateFromProps({ schema }: import("./BaseForm").BaseFormProps<any>, { bridge }: import("./BaseForm").BaseFormState<any>): { | ||
bridge: import("./Bridge").default; | ||
}; | ||
contextType?: import("react").Context<any> | undefined; | ||
} & Base; | ||
Validated: typeof Validated; | ||
displayName: string; | ||
defaultProps: { | ||
onValidate(model: any, error: any, callback: any): void; | ||
onValidate(model: any, error: any): any; | ||
validate: string; | ||
autosave: boolean; | ||
autosaveDelay: number; | ||
error: null; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
onSubmit(): void; | ||
}; | ||
getDerivedStateFromProps({ schema }: import("./BaseForm").BaseFormProps<any>, { bridge }: import("./BaseForm").BaseFormState<any>): { | ||
bridge: import("./Bridge").default; | ||
}; | ||
contextType?: import("react").Context<any> | undefined; | ||
} & { | ||
new <Model_2 extends {} = Record<string, any>, Props_2 extends QuickFormProps<Model_2> = QuickFormProps<Model_2>, State_2 extends import("./BaseForm").BaseFormState<Model_2> = import("./BaseForm").BaseFormState<Model_2>>(props: Props_2): { | ||
new <Model_1, Props_1 extends QuickFormProps<Model_1> = QuickFormProps<Model_1>, State_1 extends import("./BaseForm").BaseFormState<Model_1> = import("./BaseForm").BaseFormState<Model_1>>(props: Props_1): { | ||
getNativeFormProps(): Record<string, any>; | ||
getAutoField(): import("react").ComponentType<{ | ||
name?: string | undefined; | ||
name: string; | ||
}>; | ||
@@ -221,3 +88,3 @@ getErrorsField(): import("react").ComponentType<{}>; | ||
componentDidMount(): void; | ||
componentDidUpdate(prevProps: any, prevState: any, snapshot: any): void; | ||
componentDidUpdate(prevProps: Props_1, prevState: State_1, snapshot: never): void; | ||
componentWillUnmount(): void; | ||
@@ -230,6 +97,6 @@ delayId?: any; | ||
randomId: () => string; | ||
getContext(): import("./types").Context<Record<string, any>>; | ||
getContextName(): never[]; | ||
getContextError(): Props_2["error"]; | ||
getContextModel(): import("./types").DeepPartial<Model_2>; | ||
getContext(): import("./types").Context<Model_1>; | ||
getContextName(): string[]; | ||
getContextError(): any; | ||
getContextModel(): import("./types").DeepPartial<Model_1>; | ||
getContextState(): { | ||
@@ -241,113 +108,32 @@ disabled: boolean; | ||
}; | ||
getContextSchema(): State_2["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: import("./types").DeepPartial<Model_2>): import("./types").DeepPartial<Model_2>; | ||
getChangedKeys<T_2>(root: string, valueA?: T_2 | undefined, valueB?: T_2 | undefined): string[]; | ||
getContextSchema(): import("./Bridge").Bridge; | ||
getContextOnChange(): (key: string, value?: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => any; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: import("./types").DeepPartial<Model_1>): import("./types").DeepPartial<Model_1>; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State_2): { | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
__reset(state: State_1): Partial<State_1>; | ||
onReset(): void; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<any>; | ||
render(): JSX.Element; | ||
context: any; | ||
setState<K_2 extends keyof State_2>(state: State_2 | ((prevState: Readonly<State_2>, props: Readonly<Props_2>) => State_2 | Pick<State_2, K_2> | null) | Pick<State_2, K_2> | null, callback?: (() => void) | undefined): void; | ||
setState<K_1 extends keyof State_1>(state: State_1 | ((prevState: Readonly<State_1>, props: Readonly<Props_1>) => State_1 | Pick<State_1, K_1> | null) | Pick<State_1, K_1> | null, callback?: (() => void) | undefined): void; | ||
forceUpdate(callback?: (() => void) | undefined): void; | ||
readonly props: Readonly<Props_2> & Readonly<{ | ||
readonly props: Readonly<Props_1> & Readonly<{ | ||
children?: import("react").ReactNode; | ||
}>; | ||
state: Readonly<State_2>; | ||
state: Readonly<State_1>; | ||
refs: { | ||
[key: string]: import("react").ReactInstance; | ||
}; | ||
shouldComponentUpdate?(nextProps: Readonly<Props_2>, nextState: Readonly<State_2>, nextContext: any): boolean; | ||
shouldComponentUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): boolean; | ||
componentDidCatch?(error: Error, errorInfo: import("react").ErrorInfo): void; | ||
getSnapshotBeforeUpdate?(prevProps: Readonly<Props_2>, prevState: Readonly<State_2>): any; | ||
getSnapshotBeforeUpdate?(prevProps: Readonly<Props_1>, prevState: Readonly<State_1>): any; | ||
componentWillMount?(): void; | ||
UNSAFE_componentWillMount?(): void; | ||
componentWillReceiveProps?(nextProps: Readonly<Props_2>, nextContext: any): void; | ||
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<Props_2>, nextContext: any): void; | ||
componentWillUpdate?(nextProps: Readonly<Props_2>, nextState: Readonly<State_2>, nextContext: any): void; | ||
UNSAFE_componentWillUpdate?(nextProps: Readonly<Props_2>, nextState: Readonly<State_2>, nextContext: any): void; | ||
componentWillReceiveProps?(nextProps: Readonly<Props_1>, nextContext: any): void; | ||
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<Props_1>, nextContext: any): void; | ||
componentWillUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): void; | ||
UNSAFE_componentWillUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): void; | ||
}; | ||
Quick: <Base_1 extends typeof BaseForm>(base: Base_1) => { | ||
new <Model_3 extends {} = Record<string, any>, Props_3 extends QuickFormProps<Model_3> = QuickFormProps<Model_3>, State_3 extends import("./BaseForm").BaseFormState<Model_3> = import("./BaseForm").BaseFormState<Model_3>>(props: Props_3): { | ||
getNativeFormProps(): Record<string, any>; | ||
getAutoField(): import("react").ComponentType<{ | ||
name?: string | undefined; | ||
}>; | ||
getErrorsField(): import("react").ComponentType<{}>; | ||
getSubmitField(): import("react").ComponentType<{}>; | ||
componentDidMount(): void; | ||
componentDidUpdate(prevProps: any, prevState: any, snapshot: any): void; | ||
componentWillUnmount(): void; | ||
delayId?: any; | ||
mounted: boolean; | ||
reset: () => void; | ||
change: (key: string, value: any) => void; | ||
submit: (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<any>; | ||
randomId: () => string; | ||
getContext(): import("./types").Context<Record<string, any>>; | ||
getContextName(): never[]; | ||
getContextError(): Props_3["error"]; | ||
getContextModel(): import("./types").DeepPartial<Model_3>; | ||
getContextState(): { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
getContextSchema(): State_3["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: import("./types").DeepPartial<Model_3>): import("./types").DeepPartial<Model_3>; | ||
getChangedKeys<T_3>(root: string, valueA?: T_3 | undefined, valueB?: T_3 | undefined): string[]; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State_3): { | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
onReset(): void; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
render(): JSX.Element; | ||
context: any; | ||
setState<K_3 extends keyof State_3>(state: State_3 | ((prevState: Readonly<State_3>, props: Readonly<Props_3>) => State_3 | Pick<State_3, K_3> | null) | Pick<State_3, K_3> | null, callback?: (() => void) | undefined): void; | ||
forceUpdate(callback?: (() => void) | undefined): void; | ||
readonly props: Readonly<Props_3> & Readonly<{ | ||
children?: import("react").ReactNode; | ||
}>; | ||
state: Readonly<State_3>; | ||
refs: { | ||
[key: string]: import("react").ReactInstance; | ||
}; | ||
shouldComponentUpdate?(nextProps: Readonly<Props_3>, nextState: Readonly<State_3>, nextContext: any): boolean; | ||
componentDidCatch?(error: Error, errorInfo: import("react").ErrorInfo): void; | ||
getSnapshotBeforeUpdate?(prevProps: Readonly<Props_3>, prevState: Readonly<State_3>): any; | ||
componentWillMount?(): void; | ||
UNSAFE_componentWillMount?(): void; | ||
componentWillReceiveProps?(nextProps: Readonly<Props_3>, nextContext: any): void; | ||
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<Props_3>, nextContext: any): void; | ||
componentWillUpdate?(nextProps: Readonly<Props_3>, nextState: Readonly<State_3>, nextContext: any): void; | ||
UNSAFE_componentWillUpdate?(nextProps: Readonly<Props_3>, nextState: Readonly<State_3>, nextContext: any): void; | ||
}; | ||
Quick: any; | ||
displayName: string; | ||
defaultProps: { | ||
autosave: boolean; | ||
autosaveDelay: number; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
}; | ||
getDerivedStateFromProps({ schema }: import("./BaseForm").BaseFormProps<any>, { bridge }: import("./BaseForm").BaseFormState<any>): { | ||
bridge: import("./Bridge").default; | ||
}; | ||
contextType?: import("react").Context<any> | undefined; | ||
} & Base_1; | ||
Quick: typeof Quick; | ||
displayName: string; | ||
@@ -357,11 +143,10 @@ defaultProps: { | ||
autosaveDelay: number; | ||
error: null; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
onSubmit(): void; | ||
}; | ||
getDerivedStateFromProps({ schema }: import("./BaseForm").BaseFormProps<any>, { bridge }: import("./BaseForm").BaseFormState<any>): { | ||
bridge: import("./Bridge").default; | ||
}; | ||
contextType?: import("react").Context<any> | undefined; | ||
} & typeof BaseForm; | ||
export default _default; | ||
export declare type ValidatedQuickForm = typeof ValidatedQuickForm; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var BaseForm_1 = tslib_1.__importDefault(require("./BaseForm")); | ||
var QuickForm_1 = tslib_1.__importDefault(require("./QuickForm")); | ||
var ValidatedForm_1 = tslib_1.__importDefault(require("./ValidatedForm")); | ||
exports.default = ValidatedForm_1.default.Validated(QuickForm_1.default.Quick(BaseForm_1.default)); | ||
var BaseForm_1 = require("./BaseForm"); | ||
var QuickForm_1 = require("./QuickForm"); | ||
var ValidatedForm_1 = require("./ValidatedForm"); | ||
exports.ValidatedQuickForm = ValidatedForm_1.Validated(QuickForm_1.Quick(BaseForm_1.BaseForm)); |
/// <reference types="react" /> | ||
import BaseForm from './BaseForm'; | ||
import ValidatedQuickForm, { ValidatedQuickFormProps, ValidatedQuickFormState } from './ValidatedQuickForm'; | ||
import { BaseForm } from './BaseForm'; | ||
import { DeepPartial } from './types'; | ||
export declare type AutoFormProps<Model extends {}> = ValidatedQuickFormProps<Model> & { | ||
import { ValidatedQuickForm, ValidatedQuickFormProps, ValidatedQuickFormState } from './ValidatedQuickForm'; | ||
export declare type AutoFormProps<Model> = ValidatedQuickFormProps<Model> & { | ||
onChangeModel?(model: DeepPartial<Model>): void; | ||
}; | ||
export declare type AutoFormState<Model extends {}> = ValidatedQuickFormState<Model> & { | ||
export declare type AutoFormState<Model> = ValidatedQuickFormState<Model> & { | ||
model: DeepPartial<Model>; | ||
modelSync: DeepPartial<Model>; | ||
}; | ||
declare function Auto<Base extends typeof ValidatedQuickForm>(base: Base): { | ||
new <Model extends {} = Record<string, any>, Props extends AutoFormProps<Model> = AutoFormProps<Model>, State extends AutoFormState<Model> = AutoFormState<Model>>(props: Props): { | ||
componentDidUpdate(prevProps: Props): void; | ||
export declare function Auto<Base extends typeof ValidatedQuickForm>(Base: Base): { | ||
new <Model, Props extends AutoFormProps<Model> = AutoFormProps<Model>, State extends AutoFormState<Model> = AutoFormState<Model>>(props: Props): { | ||
componentDidUpdate(prevProps: Props, prevState: State, snapshot: never): void; | ||
getNativeFormProps(): Record<string, any>; | ||
getModel(mode: any): State["model"]; | ||
onChange(key: any, value: any): void; | ||
__reset(state: State): { | ||
model: Props["model"]; | ||
modelSync: Props["model"]; | ||
error: null; | ||
validate: boolean; | ||
validating: boolean; | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
onValidate(): Promise<unknown>; | ||
validate: (key?: string | undefined, value?: any) => Promise<unknown>; | ||
validateModel: (model: any) => Promise<unknown>; | ||
getContextError(): State["error"]; | ||
getContext(): { | ||
validating: State["validating"]; | ||
changed: boolean; | ||
changedMap: { | ||
[x: string]: Record<string, void> | { | ||
[x: string]: Record<string, void> | any | undefined; | ||
} | undefined; | ||
}; | ||
error: any; | ||
model: DeepPartial<Record<string, any>>; | ||
name: string[]; | ||
onChange(key: string, value?: any): void; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): any; | ||
randomId(): string; | ||
schema: import("./Bridge").default; | ||
state: { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
submitting: boolean; | ||
}; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
onValidateModel(model: Props["model"]): Promise<unknown>; | ||
__reset(state: State): Partial<State>; | ||
onValidate(): Promise<any>; | ||
validate: (key?: string | undefined, value?: any) => Promise<any>; | ||
validateModel: (originalModel: any) => Promise<any>; | ||
getContextError(): any; | ||
getContext(): import("./types").Context<Model>; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<any>; | ||
onValidateModel(originalModel: Props["model"]): Promise<any>; | ||
componentDidMount(): void; | ||
@@ -66,3 +34,3 @@ componentWillUnmount(): void; | ||
randomId: () => string; | ||
getContextName(): never[]; | ||
getContextName(): string[]; | ||
getContextModel(): DeepPartial<Model>; | ||
@@ -75,6 +43,5 @@ getContextState(): { | ||
}; | ||
getContextSchema(): State["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getChangedKeys<T>(root: string, valueA?: T | undefined, valueB?: T | undefined): string[]; | ||
getContextSchema(): import("./Bridge").Bridge; | ||
getContextOnChange(): (key: string, value?: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => any; | ||
onReset(): void; | ||
@@ -104,244 +71,39 @@ render(): JSX.Element; | ||
displayName: string; | ||
Validated: <Base_1 extends typeof BaseForm>(base: Base_1) => { | ||
new <Model_1 extends {} = Record<string, any>, Props_1 extends import("./ValidatedForm").ValidatedFormProps<Model_1> = import("./ValidatedForm").ValidatedFormProps<Model_1>, State_1 extends import("./ValidatedForm").ValidatedFormState<Model_1> = import("./ValidatedForm").ValidatedFormState<Model_1>>(props: Props_1): { | ||
validate: (key?: string | undefined, value?: any) => Promise<unknown>; | ||
validateModel: (model: any) => Promise<unknown>; | ||
getContextError(): State_1["error"]; | ||
getContext(): { | ||
validating: State_1["validating"]; | ||
changed: boolean; | ||
changedMap: { | ||
[x: string]: Record<string, void> | { | ||
[x: string]: Record<string, void> | any | undefined; | ||
} | undefined; | ||
}; | ||
error: any; | ||
model: DeepPartial<Record<string, any>>; | ||
name: string[]; | ||
onChange(key: string, value?: any): void; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): any; | ||
randomId(): string; | ||
schema: import("./Bridge").default; | ||
state: { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
submitting: boolean; | ||
}; | ||
getNativeFormProps(): Record<string, any>; | ||
componentDidUpdate(prevProps: Props_1, prevState: State_1, snapshot: never): void; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State_1): { | ||
error: null; | ||
validate: boolean; | ||
validating: boolean; | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
onValidate(key?: string | undefined, value?: any): Promise<unknown>; | ||
onValidateModel(model: Props_1["model"]): Promise<unknown>; | ||
componentDidMount(): void; | ||
componentWillUnmount(): void; | ||
delayId?: any; | ||
mounted: boolean; | ||
reset: () => void; | ||
change: (key: string, value: any) => void; | ||
submit: (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<any>; | ||
randomId: () => string; | ||
getContextName(): never[]; | ||
getContextModel(): DeepPartial<Model_1>; | ||
getContextState(): { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
getContextSchema(): State_1["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: DeepPartial<Model_1>): DeepPartial<Model_1>; | ||
getChangedKeys<T_1>(root: string, valueA?: T_1 | undefined, valueB?: T_1 | undefined): string[]; | ||
onReset(): void; | ||
render(): JSX.Element; | ||
context: any; | ||
setState<K_1 extends keyof State_1>(state: State_1 | ((prevState: Readonly<State_1>, props: Readonly<Props_1>) => State_1 | Pick<State_1, K_1> | null) | Pick<State_1, K_1> | null, callback?: (() => void) | undefined): void; | ||
forceUpdate(callback?: (() => void) | undefined): void; | ||
readonly props: Readonly<Props_1> & Readonly<{ | ||
children?: import("react").ReactNode; | ||
}>; | ||
state: Readonly<State_1>; | ||
refs: { | ||
[key: string]: import("react").ReactInstance; | ||
}; | ||
shouldComponentUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): boolean; | ||
componentDidCatch?(error: Error, errorInfo: import("react").ErrorInfo): void; | ||
getSnapshotBeforeUpdate?(prevProps: Readonly<Props_1>, prevState: Readonly<State_1>): any; | ||
componentWillMount?(): void; | ||
UNSAFE_componentWillMount?(): void; | ||
componentWillReceiveProps?(nextProps: Readonly<Props_1>, nextContext: any): void; | ||
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<Props_1>, nextContext: any): void; | ||
componentWillUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): void; | ||
UNSAFE_componentWillUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): void; | ||
}; | ||
Validated: any; | ||
displayName: string; | ||
defaultProps: { | ||
onValidate(model: any, error: any, callback: any): void; | ||
validate: string; | ||
autosave: boolean; | ||
autosaveDelay: number; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
}; | ||
getDerivedStateFromProps({ schema }: import("./BaseForm").BaseFormProps<any>, { bridge }: import("./BaseForm").BaseFormState<any>): { | ||
bridge: import("./Bridge").default; | ||
}; | ||
contextType?: import("react").Context<any> | undefined; | ||
} & Base_1; | ||
Validated: typeof import("./ValidatedForm").Validated; | ||
defaultProps: { | ||
onValidate(model: any, error: any, callback: any): void; | ||
onValidate(model: any, error: any): any; | ||
validate: string; | ||
autosave: boolean; | ||
autosaveDelay: number; | ||
error: null; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
onSubmit(): void; | ||
} & { | ||
autosave: boolean; | ||
autosaveDelay: number; | ||
error: null; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
onSubmit(): void; | ||
}; | ||
getDerivedStateFromProps: typeof BaseForm.getDerivedStateFromProps; | ||
contextType?: import("react").Context<any> | undefined; | ||
Quick: <Base_2 extends typeof BaseForm>(base: Base_2) => { | ||
new <Model_2 extends {} = Record<string, any>, Props_2 extends import("./QuickForm").QuickFormProps<Model_2> = import("./QuickForm").QuickFormProps<Model_2>, State_2 extends import("./BaseForm").BaseFormState<Model_2> = import("./BaseForm").BaseFormState<Model_2>>(props: Props_2): { | ||
getNativeFormProps(): Record<string, any>; | ||
getAutoField(): import("react").ComponentType<{ | ||
name?: string | undefined; | ||
}>; | ||
getErrorsField(): import("react").ComponentType<{}>; | ||
getSubmitField(): import("react").ComponentType<{}>; | ||
componentDidMount(): void; | ||
componentDidUpdate(prevProps: any, prevState: any, snapshot: any): void; | ||
componentWillUnmount(): void; | ||
delayId?: any; | ||
mounted: boolean; | ||
reset: () => void; | ||
change: (key: string, value: any) => void; | ||
submit: (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<any>; | ||
randomId: () => string; | ||
getContext(): import("./types").Context<Record<string, any>>; | ||
getContextName(): never[]; | ||
getContextError(): Props_2["error"]; | ||
getContextModel(): DeepPartial<Model_2>; | ||
getContextState(): { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
getContextSchema(): State_2["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: DeepPartial<Model_2>): DeepPartial<Model_2>; | ||
getChangedKeys<T_2>(root: string, valueA?: T_2 | undefined, valueB?: T_2 | undefined): string[]; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State_2): { | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
onReset(): void; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
render(): JSX.Element; | ||
context: any; | ||
setState<K_2 extends keyof State_2>(state: State_2 | ((prevState: Readonly<State_2>, props: Readonly<Props_2>) => State_2 | Pick<State_2, K_2> | null) | Pick<State_2, K_2> | null, callback?: (() => void) | undefined): void; | ||
forceUpdate(callback?: (() => void) | undefined): void; | ||
readonly props: Readonly<Props_2> & Readonly<{ | ||
children?: import("react").ReactNode; | ||
}>; | ||
state: Readonly<State_2>; | ||
refs: { | ||
[key: string]: import("react").ReactInstance; | ||
}; | ||
shouldComponentUpdate?(nextProps: Readonly<Props_2>, nextState: Readonly<State_2>, nextContext: any): boolean; | ||
componentDidCatch?(error: Error, errorInfo: import("react").ErrorInfo): void; | ||
getSnapshotBeforeUpdate?(prevProps: Readonly<Props_2>, prevState: Readonly<State_2>): any; | ||
componentWillMount?(): void; | ||
UNSAFE_componentWillMount?(): void; | ||
componentWillReceiveProps?(nextProps: Readonly<Props_2>, nextContext: any): void; | ||
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<Props_2>, nextContext: any): void; | ||
componentWillUpdate?(nextProps: Readonly<Props_2>, nextState: Readonly<State_2>, nextContext: any): void; | ||
UNSAFE_componentWillUpdate?(nextProps: Readonly<Props_2>, nextState: Readonly<State_2>, nextContext: any): void; | ||
}; | ||
Quick: any; | ||
displayName: string; | ||
defaultProps: { | ||
autosave: boolean; | ||
autosaveDelay: number; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
}; | ||
getDerivedStateFromProps({ schema }: import("./BaseForm").BaseFormProps<any>, { bridge }: import("./BaseForm").BaseFormState<any>): { | ||
bridge: import("./Bridge").default; | ||
}; | ||
contextType?: import("react").Context<any> | undefined; | ||
} & Base_2; | ||
Quick: typeof import("./QuickForm").Quick; | ||
} & Base; | ||
declare const _default: { | ||
new <Model extends {} = Record<string, any>, Props extends AutoFormProps<Model> = AutoFormProps<Model>, State extends AutoFormState<Model> = AutoFormState<Model>>(props: Props): { | ||
componentDidUpdate(prevProps: Props): void; | ||
export declare const AutoForm: { | ||
new <Model, Props extends AutoFormProps<Model> = AutoFormProps<Model>, State extends AutoFormState<Model> = AutoFormState<Model>>(props: Props): { | ||
componentDidUpdate(prevProps: Props, prevState: State, snapshot: never): void; | ||
getNativeFormProps(): Record<string, any>; | ||
getModel(mode: any): State["model"]; | ||
onChange(key: any, value: any): void; | ||
__reset(state: State): { | ||
model: Props["model"]; | ||
modelSync: Props["model"]; | ||
error: null; | ||
validate: boolean; | ||
validating: boolean; | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
onValidate(): Promise<unknown>; | ||
validate: (key?: string | undefined, value?: any) => Promise<unknown>; | ||
validateModel: (model: any) => Promise<unknown>; | ||
getContextError(): State["error"]; | ||
getContext(): { | ||
validating: State["validating"]; | ||
changed: boolean; | ||
changedMap: { | ||
[x: string]: Record<string, void> | { | ||
[x: string]: Record<string, void> | any | undefined; | ||
} | undefined; | ||
}; | ||
error: any; | ||
model: DeepPartial<Record<string, any>>; | ||
name: string[]; | ||
onChange(key: string, value?: any): void; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): any; | ||
randomId(): string; | ||
schema: import("./Bridge").default; | ||
state: { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
submitting: boolean; | ||
}; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
onValidateModel(model: Props["model"]): Promise<unknown>; | ||
__reset(state: State): Partial<State>; | ||
onValidate(): Promise<any>; | ||
validate: (key?: string | undefined, value?: any) => Promise<any>; | ||
validateModel: (originalModel: any) => Promise<any>; | ||
getContextError(): any; | ||
getContext(): import("./types").Context<Model>; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<any>; | ||
onValidateModel(originalModel: Props["model"]): Promise<any>; | ||
componentDidMount(): void; | ||
@@ -355,3 +117,3 @@ componentWillUnmount(): void; | ||
randomId: () => string; | ||
getContextName(): never[]; | ||
getContextName(): string[]; | ||
getContextModel(): DeepPartial<Model>; | ||
@@ -364,6 +126,5 @@ getContextState(): { | ||
}; | ||
getContextSchema(): State["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getChangedKeys<T>(root: string, valueA?: T | undefined, valueB?: T | undefined): string[]; | ||
getContextSchema(): import("./Bridge").Bridge; | ||
getContextOnChange(): (key: string, value?: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => any; | ||
onReset(): void; | ||
@@ -393,240 +154,37 @@ render(): JSX.Element; | ||
displayName: string; | ||
Validated: <Base extends typeof BaseForm>(base: Base) => { | ||
new <Model_1 extends {} = Record<string, any>, Props_1 extends import("./ValidatedForm").ValidatedFormProps<Model_1> = import("./ValidatedForm").ValidatedFormProps<Model_1>, State_1 extends import("./ValidatedForm").ValidatedFormState<Model_1> = import("./ValidatedForm").ValidatedFormState<Model_1>>(props: Props_1): { | ||
validate: (key?: string | undefined, value?: any) => Promise<unknown>; | ||
validateModel: (model: any) => Promise<unknown>; | ||
getContextError(): State_1["error"]; | ||
getContext(): { | ||
validating: State_1["validating"]; | ||
changed: boolean; | ||
changedMap: { | ||
[x: string]: Record<string, void> | { | ||
[x: string]: Record<string, void> | any | undefined; | ||
} | undefined; | ||
}; | ||
error: any; | ||
model: DeepPartial<Record<string, any>>; | ||
name: string[]; | ||
onChange(key: string, value?: any): void; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): any; | ||
randomId(): string; | ||
schema: import("./Bridge").default; | ||
state: { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
submitting: boolean; | ||
}; | ||
getNativeFormProps(): Record<string, any>; | ||
componentDidUpdate(prevProps: Props_1, prevState: State_1, snapshot: never): void; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State_1): { | ||
error: null; | ||
validate: boolean; | ||
validating: boolean; | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
onValidate(key?: string | undefined, value?: any): Promise<unknown>; | ||
onValidateModel(model: Props_1["model"]): Promise<unknown>; | ||
componentDidMount(): void; | ||
componentWillUnmount(): void; | ||
delayId?: any; | ||
mounted: boolean; | ||
reset: () => void; | ||
change: (key: string, value: any) => void; | ||
submit: (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<any>; | ||
randomId: () => string; | ||
getContextName(): never[]; | ||
getContextModel(): DeepPartial<Model_1>; | ||
getContextState(): { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
getContextSchema(): State_1["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: DeepPartial<Model_1>): DeepPartial<Model_1>; | ||
getChangedKeys<T_1>(root: string, valueA?: T_1 | undefined, valueB?: T_1 | undefined): string[]; | ||
onReset(): void; | ||
render(): JSX.Element; | ||
context: any; | ||
setState<K_1 extends keyof State_1>(state: State_1 | ((prevState: Readonly<State_1>, props: Readonly<Props_1>) => State_1 | Pick<State_1, K_1> | null) | Pick<State_1, K_1> | null, callback?: (() => void) | undefined): void; | ||
forceUpdate(callback?: (() => void) | undefined): void; | ||
readonly props: Readonly<Props_1> & Readonly<{ | ||
children?: import("react").ReactNode; | ||
}>; | ||
state: Readonly<State_1>; | ||
refs: { | ||
[key: string]: import("react").ReactInstance; | ||
}; | ||
shouldComponentUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): boolean; | ||
componentDidCatch?(error: Error, errorInfo: import("react").ErrorInfo): void; | ||
getSnapshotBeforeUpdate?(prevProps: Readonly<Props_1>, prevState: Readonly<State_1>): any; | ||
componentWillMount?(): void; | ||
UNSAFE_componentWillMount?(): void; | ||
componentWillReceiveProps?(nextProps: Readonly<Props_1>, nextContext: any): void; | ||
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<Props_1>, nextContext: any): void; | ||
componentWillUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): void; | ||
UNSAFE_componentWillUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): void; | ||
}; | ||
Validated: any; | ||
displayName: string; | ||
defaultProps: { | ||
onValidate(model: any, error: any, callback: any): void; | ||
validate: string; | ||
autosave: boolean; | ||
autosaveDelay: number; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
}; | ||
getDerivedStateFromProps({ schema }: import("./BaseForm").BaseFormProps<any>, { bridge }: import("./BaseForm").BaseFormState<any>): { | ||
bridge: import("./Bridge").default; | ||
}; | ||
contextType?: import("react").Context<any> | undefined; | ||
} & Base; | ||
Validated: typeof import("./ValidatedForm").Validated; | ||
defaultProps: { | ||
onValidate(model: any, error: any, callback: any): void; | ||
onValidate(model: any, error: any): any; | ||
validate: string; | ||
autosave: boolean; | ||
autosaveDelay: number; | ||
error: null; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
onSubmit(): void; | ||
} & { | ||
autosave: boolean; | ||
autosaveDelay: number; | ||
error: null; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
onSubmit(): void; | ||
}; | ||
getDerivedStateFromProps: typeof BaseForm.getDerivedStateFromProps; | ||
contextType?: import("react").Context<any> | undefined; | ||
Quick: <Base_1 extends typeof BaseForm>(base: Base_1) => { | ||
new <Model_2 extends {} = Record<string, any>, Props_2 extends import("./QuickForm").QuickFormProps<Model_2> = import("./QuickForm").QuickFormProps<Model_2>, State_2 extends import("./BaseForm").BaseFormState<Model_2> = import("./BaseForm").BaseFormState<Model_2>>(props: Props_2): { | ||
getNativeFormProps(): Record<string, any>; | ||
getAutoField(): import("react").ComponentType<{ | ||
name?: string | undefined; | ||
}>; | ||
getErrorsField(): import("react").ComponentType<{}>; | ||
getSubmitField(): import("react").ComponentType<{}>; | ||
componentDidMount(): void; | ||
componentDidUpdate(prevProps: any, prevState: any, snapshot: any): void; | ||
componentWillUnmount(): void; | ||
delayId?: any; | ||
mounted: boolean; | ||
reset: () => void; | ||
change: (key: string, value: any) => void; | ||
submit: (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<any>; | ||
randomId: () => string; | ||
getContext(): import("./types").Context<Record<string, any>>; | ||
getContextName(): never[]; | ||
getContextError(): Props_2["error"]; | ||
getContextModel(): DeepPartial<Model_2>; | ||
getContextState(): { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
getContextSchema(): State_2["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: DeepPartial<Model_2>): DeepPartial<Model_2>; | ||
getChangedKeys<T_2>(root: string, valueA?: T_2 | undefined, valueB?: T_2 | undefined): string[]; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State_2): { | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
onReset(): void; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
render(): JSX.Element; | ||
context: any; | ||
setState<K_2 extends keyof State_2>(state: State_2 | ((prevState: Readonly<State_2>, props: Readonly<Props_2>) => State_2 | Pick<State_2, K_2> | null) | Pick<State_2, K_2> | null, callback?: (() => void) | undefined): void; | ||
forceUpdate(callback?: (() => void) | undefined): void; | ||
readonly props: Readonly<Props_2> & Readonly<{ | ||
children?: import("react").ReactNode; | ||
}>; | ||
state: Readonly<State_2>; | ||
refs: { | ||
[key: string]: import("react").ReactInstance; | ||
}; | ||
shouldComponentUpdate?(nextProps: Readonly<Props_2>, nextState: Readonly<State_2>, nextContext: any): boolean; | ||
componentDidCatch?(error: Error, errorInfo: import("react").ErrorInfo): void; | ||
getSnapshotBeforeUpdate?(prevProps: Readonly<Props_2>, prevState: Readonly<State_2>): any; | ||
componentWillMount?(): void; | ||
UNSAFE_componentWillMount?(): void; | ||
componentWillReceiveProps?(nextProps: Readonly<Props_2>, nextContext: any): void; | ||
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<Props_2>, nextContext: any): void; | ||
componentWillUpdate?(nextProps: Readonly<Props_2>, nextState: Readonly<State_2>, nextContext: any): void; | ||
UNSAFE_componentWillUpdate?(nextProps: Readonly<Props_2>, nextState: Readonly<State_2>, nextContext: any): void; | ||
}; | ||
Quick: any; | ||
displayName: string; | ||
defaultProps: { | ||
autosave: boolean; | ||
autosaveDelay: number; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
}; | ||
getDerivedStateFromProps({ schema }: import("./BaseForm").BaseFormProps<any>, { bridge }: import("./BaseForm").BaseFormState<any>): { | ||
bridge: import("./Bridge").default; | ||
}; | ||
contextType?: import("react").Context<any> | undefined; | ||
} & Base_1; | ||
Quick: typeof import("./QuickForm").Quick; | ||
} & { | ||
new <Model_3 extends {} = Record<string, any>, Props_3 extends import("./ValidatedForm").ValidatedFormProps<Model_3> = import("./ValidatedForm").ValidatedFormProps<Model_3>, State_3 extends import("./ValidatedForm").ValidatedFormState<Model_3> = import("./ValidatedForm").ValidatedFormState<Model_3>>(props: Props_3): { | ||
validate: (key?: string | undefined, value?: any) => Promise<unknown>; | ||
validateModel: (model: any) => Promise<unknown>; | ||
getContextError(): State_3["error"]; | ||
getContext(): { | ||
validating: State_3["validating"]; | ||
changed: boolean; | ||
changedMap: { | ||
[x: string]: Record<string, void> | { | ||
[x: string]: Record<string, void> | any | undefined; | ||
} | undefined; | ||
}; | ||
error: any; | ||
model: DeepPartial<Record<string, any>>; | ||
name: string[]; | ||
onChange(key: string, value?: any): void; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): any; | ||
randomId(): string; | ||
schema: import("./Bridge").default; | ||
state: { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
submitting: boolean; | ||
}; | ||
new <Model_1, Props_1 extends import("./ValidatedForm").ValidatedFormProps<Model_1> = import("./ValidatedForm").ValidatedFormProps<Model_1>, State_1 extends import("./ValidatedForm").ValidatedFormState<Model_1> = import("./ValidatedForm").ValidatedFormState<Model_1>>(props: Props_1): { | ||
validate: (key?: string | undefined, value?: any) => Promise<any>; | ||
validateModel: (originalModel: any) => Promise<any>; | ||
getContextError(): any; | ||
getContext(): import("./types").Context<Model_1>; | ||
getNativeFormProps(): Record<string, any>; | ||
componentDidUpdate(prevProps: Props_3, prevState: State_3, snapshot: never): void; | ||
componentDidUpdate(prevProps: Props_1, prevState: State_1, snapshot: never): void; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State_3): { | ||
error: null; | ||
validate: boolean; | ||
validating: boolean; | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
onValidate(key?: string | undefined, value?: any): Promise<unknown>; | ||
onValidateModel(model: Props_3["model"]): Promise<unknown>; | ||
__reset(state: State_1): Partial<State_1>; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<any>; | ||
onValidate(key?: string | undefined, value?: any): Promise<any>; | ||
onValidateModel(originalModel: Props_1["model"]): Promise<any>; | ||
componentDidMount(): void; | ||
@@ -640,4 +198,4 @@ componentWillUnmount(): void; | ||
randomId: () => string; | ||
getContextName(): never[]; | ||
getContextModel(): DeepPartial<Model_3>; | ||
getContextName(): string[]; | ||
getContextModel(): DeepPartial<Model_1>; | ||
getContextState(): { | ||
@@ -649,150 +207,47 @@ disabled: boolean; | ||
}; | ||
getContextSchema(): State_3["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: DeepPartial<Model_3>): DeepPartial<Model_3>; | ||
getChangedKeys<T_3>(root: string, valueA?: T_3 | undefined, valueB?: T_3 | undefined): string[]; | ||
getContextSchema(): import("./Bridge").Bridge; | ||
getContextOnChange(): (key: string, value?: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => any; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: DeepPartial<Model_1>): DeepPartial<Model_1>; | ||
onReset(): void; | ||
render(): JSX.Element; | ||
context: any; | ||
setState<K_3 extends keyof State_3>(state: State_3 | ((prevState: Readonly<State_3>, props: Readonly<Props_3>) => State_3 | Pick<State_3, K_3> | null) | Pick<State_3, K_3> | null, callback?: (() => void) | undefined): void; | ||
setState<K_1 extends keyof State_1>(state: State_1 | ((prevState: Readonly<State_1>, props: Readonly<Props_1>) => State_1 | Pick<State_1, K_1> | null) | Pick<State_1, K_1> | null, callback?: (() => void) | undefined): void; | ||
forceUpdate(callback?: (() => void) | undefined): void; | ||
readonly props: Readonly<Props_3> & Readonly<{ | ||
readonly props: Readonly<Props_1> & Readonly<{ | ||
children?: import("react").ReactNode; | ||
}>; | ||
state: Readonly<State_3>; | ||
state: Readonly<State_1>; | ||
refs: { | ||
[key: string]: import("react").ReactInstance; | ||
}; | ||
shouldComponentUpdate?(nextProps: Readonly<Props_3>, nextState: Readonly<State_3>, nextContext: any): boolean; | ||
shouldComponentUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): boolean; | ||
componentDidCatch?(error: Error, errorInfo: import("react").ErrorInfo): void; | ||
getSnapshotBeforeUpdate?(prevProps: Readonly<Props_3>, prevState: Readonly<State_3>): any; | ||
getSnapshotBeforeUpdate?(prevProps: Readonly<Props_1>, prevState: Readonly<State_1>): any; | ||
componentWillMount?(): void; | ||
UNSAFE_componentWillMount?(): void; | ||
componentWillReceiveProps?(nextProps: Readonly<Props_3>, nextContext: any): void; | ||
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<Props_3>, nextContext: any): void; | ||
componentWillUpdate?(nextProps: Readonly<Props_3>, nextState: Readonly<State_3>, nextContext: any): void; | ||
UNSAFE_componentWillUpdate?(nextProps: Readonly<Props_3>, nextState: Readonly<State_3>, nextContext: any): void; | ||
componentWillReceiveProps?(nextProps: Readonly<Props_1>, nextContext: any): void; | ||
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<Props_1>, nextContext: any): void; | ||
componentWillUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): void; | ||
UNSAFE_componentWillUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): void; | ||
}; | ||
Validated: <Base extends typeof BaseForm>(base: Base) => { | ||
new <Model_1 extends {} = Record<string, any>, Props_1 extends import("./ValidatedForm").ValidatedFormProps<Model_1> = import("./ValidatedForm").ValidatedFormProps<Model_1>, State_1 extends import("./ValidatedForm").ValidatedFormState<Model_1> = import("./ValidatedForm").ValidatedFormState<Model_1>>(props: Props_1): { | ||
validate: (key?: string | undefined, value?: any) => Promise<unknown>; | ||
validateModel: (model: any) => Promise<unknown>; | ||
getContextError(): State_1["error"]; | ||
getContext(): { | ||
validating: State_1["validating"]; | ||
changed: boolean; | ||
changedMap: { | ||
[x: string]: Record<string, void> | { | ||
[x: string]: Record<string, void> | any | undefined; | ||
} | undefined; | ||
}; | ||
error: any; | ||
model: DeepPartial<Record<string, any>>; | ||
name: string[]; | ||
onChange(key: string, value?: any): void; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): any; | ||
randomId(): string; | ||
schema: import("./Bridge").default; | ||
state: { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
submitting: boolean; | ||
}; | ||
getNativeFormProps(): Record<string, any>; | ||
componentDidUpdate(prevProps: Props_1, prevState: State_1, snapshot: never): void; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State_1): { | ||
error: null; | ||
validate: boolean; | ||
validating: boolean; | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
onValidate(key?: string | undefined, value?: any): Promise<unknown>; | ||
onValidateModel(model: Props_1["model"]): Promise<unknown>; | ||
componentDidMount(): void; | ||
componentWillUnmount(): void; | ||
delayId?: any; | ||
mounted: boolean; | ||
reset: () => void; | ||
change: (key: string, value: any) => void; | ||
submit: (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<any>; | ||
randomId: () => string; | ||
getContextName(): never[]; | ||
getContextModel(): DeepPartial<Model_1>; | ||
getContextState(): { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
getContextSchema(): State_1["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: DeepPartial<Model_1>): DeepPartial<Model_1>; | ||
getChangedKeys<T_1>(root: string, valueA?: T_1 | undefined, valueB?: T_1 | undefined): string[]; | ||
onReset(): void; | ||
render(): JSX.Element; | ||
context: any; | ||
setState<K_1 extends keyof State_1>(state: State_1 | ((prevState: Readonly<State_1>, props: Readonly<Props_1>) => State_1 | Pick<State_1, K_1> | null) | Pick<State_1, K_1> | null, callback?: (() => void) | undefined): void; | ||
forceUpdate(callback?: (() => void) | undefined): void; | ||
readonly props: Readonly<Props_1> & Readonly<{ | ||
children?: import("react").ReactNode; | ||
}>; | ||
state: Readonly<State_1>; | ||
refs: { | ||
[key: string]: import("react").ReactInstance; | ||
}; | ||
shouldComponentUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): boolean; | ||
componentDidCatch?(error: Error, errorInfo: import("react").ErrorInfo): void; | ||
getSnapshotBeforeUpdate?(prevProps: Readonly<Props_1>, prevState: Readonly<State_1>): any; | ||
componentWillMount?(): void; | ||
UNSAFE_componentWillMount?(): void; | ||
componentWillReceiveProps?(nextProps: Readonly<Props_1>, nextContext: any): void; | ||
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<Props_1>, nextContext: any): void; | ||
componentWillUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): void; | ||
UNSAFE_componentWillUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): void; | ||
}; | ||
Validated: any; | ||
displayName: string; | ||
defaultProps: { | ||
onValidate(model: any, error: any, callback: any): void; | ||
validate: string; | ||
autosave: boolean; | ||
autosaveDelay: number; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
}; | ||
getDerivedStateFromProps({ schema }: import("./BaseForm").BaseFormProps<any>, { bridge }: import("./BaseForm").BaseFormState<any>): { | ||
bridge: import("./Bridge").default; | ||
}; | ||
contextType?: import("react").Context<any> | undefined; | ||
} & Base; | ||
Validated: typeof import("./ValidatedForm").Validated; | ||
displayName: string; | ||
defaultProps: { | ||
onValidate(model: any, error: any, callback: any): void; | ||
onValidate(model: any, error: any): any; | ||
validate: string; | ||
autosave: boolean; | ||
autosaveDelay: number; | ||
error: null; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
onSubmit(): void; | ||
}; | ||
getDerivedStateFromProps({ schema }: import("./BaseForm").BaseFormProps<any>, { bridge }: import("./BaseForm").BaseFormState<any>): { | ||
bridge: import("./Bridge").default; | ||
}; | ||
contextType?: import("react").Context<any> | undefined; | ||
} & { | ||
new <Model_4 extends {} = Record<string, any>, Props_4 extends import("./QuickForm").QuickFormProps<Model_4> = import("./QuickForm").QuickFormProps<Model_4>, State_4 extends import("./BaseForm").BaseFormState<Model_4> = import("./BaseForm").BaseFormState<Model_4>>(props: Props_4): { | ||
new <Model_2, Props_2 extends import("./QuickForm").QuickFormProps<Model_2> = import("./QuickForm").QuickFormProps<Model_2>, State_2 extends import("./BaseForm").BaseFormState<Model_2> = import("./BaseForm").BaseFormState<Model_2>>(props: Props_2): { | ||
getNativeFormProps(): Record<string, any>; | ||
getAutoField(): import("react").ComponentType<{ | ||
name?: string | undefined; | ||
name: string; | ||
}>; | ||
@@ -802,3 +257,3 @@ getErrorsField(): import("react").ComponentType<{}>; | ||
componentDidMount(): void; | ||
componentDidUpdate(prevProps: any, prevState: any, snapshot: any): void; | ||
componentDidUpdate(prevProps: Props_2, prevState: State_2, snapshot: never): void; | ||
componentWillUnmount(): void; | ||
@@ -811,6 +266,6 @@ delayId?: any; | ||
randomId: () => string; | ||
getContext(): import("./types").Context<Record<string, any>>; | ||
getContextName(): never[]; | ||
getContextError(): Props_4["error"]; | ||
getContextModel(): DeepPartial<Model_4>; | ||
getContext(): import("./types").Context<Model_2>; | ||
getContextName(): string[]; | ||
getContextError(): any; | ||
getContextModel(): DeepPartial<Model_2>; | ||
getContextState(): { | ||
@@ -822,113 +277,32 @@ disabled: boolean; | ||
}; | ||
getContextSchema(): State_4["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: DeepPartial<Model_4>): DeepPartial<Model_4>; | ||
getChangedKeys<T_4>(root: string, valueA?: T_4 | undefined, valueB?: T_4 | undefined): string[]; | ||
getContextSchema(): import("./Bridge").Bridge; | ||
getContextOnChange(): (key: string, value?: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => any; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: DeepPartial<Model_2>): DeepPartial<Model_2>; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State_4): { | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
__reset(state: State_2): Partial<State_2>; | ||
onReset(): void; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<any>; | ||
render(): JSX.Element; | ||
context: any; | ||
setState<K_4 extends keyof State_4>(state: State_4 | ((prevState: Readonly<State_4>, props: Readonly<Props_4>) => State_4 | Pick<State_4, K_4> | null) | Pick<State_4, K_4> | null, callback?: (() => void) | undefined): void; | ||
setState<K_2 extends keyof State_2>(state: State_2 | ((prevState: Readonly<State_2>, props: Readonly<Props_2>) => State_2 | Pick<State_2, K_2> | null) | Pick<State_2, K_2> | null, callback?: (() => void) | undefined): void; | ||
forceUpdate(callback?: (() => void) | undefined): void; | ||
readonly props: Readonly<Props_4> & Readonly<{ | ||
readonly props: Readonly<Props_2> & Readonly<{ | ||
children?: import("react").ReactNode; | ||
}>; | ||
state: Readonly<State_4>; | ||
state: Readonly<State_2>; | ||
refs: { | ||
[key: string]: import("react").ReactInstance; | ||
}; | ||
shouldComponentUpdate?(nextProps: Readonly<Props_4>, nextState: Readonly<State_4>, nextContext: any): boolean; | ||
shouldComponentUpdate?(nextProps: Readonly<Props_2>, nextState: Readonly<State_2>, nextContext: any): boolean; | ||
componentDidCatch?(error: Error, errorInfo: import("react").ErrorInfo): void; | ||
getSnapshotBeforeUpdate?(prevProps: Readonly<Props_4>, prevState: Readonly<State_4>): any; | ||
getSnapshotBeforeUpdate?(prevProps: Readonly<Props_2>, prevState: Readonly<State_2>): any; | ||
componentWillMount?(): void; | ||
UNSAFE_componentWillMount?(): void; | ||
componentWillReceiveProps?(nextProps: Readonly<Props_4>, nextContext: any): void; | ||
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<Props_4>, nextContext: any): void; | ||
componentWillUpdate?(nextProps: Readonly<Props_4>, nextState: Readonly<State_4>, nextContext: any): void; | ||
UNSAFE_componentWillUpdate?(nextProps: Readonly<Props_4>, nextState: Readonly<State_4>, nextContext: any): void; | ||
componentWillReceiveProps?(nextProps: Readonly<Props_2>, nextContext: any): void; | ||
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<Props_2>, nextContext: any): void; | ||
componentWillUpdate?(nextProps: Readonly<Props_2>, nextState: Readonly<State_2>, nextContext: any): void; | ||
UNSAFE_componentWillUpdate?(nextProps: Readonly<Props_2>, nextState: Readonly<State_2>, nextContext: any): void; | ||
}; | ||
Quick: <Base_1 extends typeof BaseForm>(base: Base_1) => { | ||
new <Model_2 extends {} = Record<string, any>, Props_2 extends import("./QuickForm").QuickFormProps<Model_2> = import("./QuickForm").QuickFormProps<Model_2>, State_2 extends import("./BaseForm").BaseFormState<Model_2> = import("./BaseForm").BaseFormState<Model_2>>(props: Props_2): { | ||
getNativeFormProps(): Record<string, any>; | ||
getAutoField(): import("react").ComponentType<{ | ||
name?: string | undefined; | ||
}>; | ||
getErrorsField(): import("react").ComponentType<{}>; | ||
getSubmitField(): import("react").ComponentType<{}>; | ||
componentDidMount(): void; | ||
componentDidUpdate(prevProps: any, prevState: any, snapshot: any): void; | ||
componentWillUnmount(): void; | ||
delayId?: any; | ||
mounted: boolean; | ||
reset: () => void; | ||
change: (key: string, value: any) => void; | ||
submit: (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<any>; | ||
randomId: () => string; | ||
getContext(): import("./types").Context<Record<string, any>>; | ||
getContextName(): never[]; | ||
getContextError(): Props_2["error"]; | ||
getContextModel(): DeepPartial<Model_2>; | ||
getContextState(): { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
getContextSchema(): State_2["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: DeepPartial<Model_2>): DeepPartial<Model_2>; | ||
getChangedKeys<T_2>(root: string, valueA?: T_2 | undefined, valueB?: T_2 | undefined): string[]; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State_2): { | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
onReset(): void; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
render(): JSX.Element; | ||
context: any; | ||
setState<K_2 extends keyof State_2>(state: State_2 | ((prevState: Readonly<State_2>, props: Readonly<Props_2>) => State_2 | Pick<State_2, K_2> | null) | Pick<State_2, K_2> | null, callback?: (() => void) | undefined): void; | ||
forceUpdate(callback?: (() => void) | undefined): void; | ||
readonly props: Readonly<Props_2> & Readonly<{ | ||
children?: import("react").ReactNode; | ||
}>; | ||
state: Readonly<State_2>; | ||
refs: { | ||
[key: string]: import("react").ReactInstance; | ||
}; | ||
shouldComponentUpdate?(nextProps: Readonly<Props_2>, nextState: Readonly<State_2>, nextContext: any): boolean; | ||
componentDidCatch?(error: Error, errorInfo: import("react").ErrorInfo): void; | ||
getSnapshotBeforeUpdate?(prevProps: Readonly<Props_2>, prevState: Readonly<State_2>): any; | ||
componentWillMount?(): void; | ||
UNSAFE_componentWillMount?(): void; | ||
componentWillReceiveProps?(nextProps: Readonly<Props_2>, nextContext: any): void; | ||
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<Props_2>, nextContext: any): void; | ||
componentWillUpdate?(nextProps: Readonly<Props_2>, nextState: Readonly<State_2>, nextContext: any): void; | ||
UNSAFE_componentWillUpdate?(nextProps: Readonly<Props_2>, nextState: Readonly<State_2>, nextContext: any): void; | ||
}; | ||
Quick: any; | ||
displayName: string; | ||
defaultProps: { | ||
autosave: boolean; | ||
autosaveDelay: number; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
}; | ||
getDerivedStateFromProps({ schema }: import("./BaseForm").BaseFormProps<any>, { bridge }: import("./BaseForm").BaseFormState<any>): { | ||
bridge: import("./Bridge").default; | ||
}; | ||
contextType?: import("react").Context<any> | undefined; | ||
} & Base_1; | ||
Quick: typeof import("./QuickForm").Quick; | ||
displayName: string; | ||
@@ -938,11 +312,10 @@ defaultProps: { | ||
autosaveDelay: number; | ||
error: null; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
onSubmit(): void; | ||
}; | ||
getDerivedStateFromProps({ schema }: import("./BaseForm").BaseFormProps<any>, { bridge }: import("./BaseForm").BaseFormState<any>): { | ||
bridge: import("./Bridge").default; | ||
}; | ||
contextType?: import("react").Context<any> | undefined; | ||
} & typeof BaseForm; | ||
export default _default; | ||
export declare type AutoForm = typeof AutoForm; |
@@ -1,9 +0,9 @@ | ||
import cloneDeep from 'lodash/cloneDeep'; | ||
import clone from 'lodash/clone'; | ||
import isEqual from 'lodash/isEqual'; | ||
import omit from 'lodash/omit'; | ||
import set from 'lodash/set'; | ||
import ValidatedQuickForm from './ValidatedQuickForm'; | ||
function Auto(base) { | ||
import setWith from 'lodash/setWith'; | ||
import { ValidatedQuickForm, } from './ValidatedQuickForm'; | ||
export function Auto(Base) { | ||
// @ts-ignore: Mixin class problem. | ||
class AutoForm extends base { | ||
class AutoForm extends Base { | ||
constructor(props) { | ||
@@ -13,3 +13,3 @@ super(props); | ||
} | ||
componentDidUpdate(prevProps) { | ||
componentDidUpdate(prevProps, prevState, snapshot) { | ||
const { model } = this.props; | ||
@@ -19,4 +19,3 @@ if (!isEqual(model, prevProps.model)) { | ||
} | ||
// @ts-ignore | ||
super.componentDidUpdate(...arguments); | ||
super.componentDidUpdate(prevProps, prevState, snapshot); | ||
} | ||
@@ -30,3 +29,5 @@ getNativeFormProps() { | ||
onChange(key, value) { | ||
this.setState(state => ({ modelSync: set(cloneDeep(state.modelSync), key, value) }), () => { | ||
this.setState(state => ({ | ||
modelSync: setWith(clone(state.modelSync), key, value, clone), | ||
}), () => { | ||
super.onChange(key, value); | ||
@@ -48,5 +49,5 @@ this.setState(state => { | ||
AutoForm.Auto = Auto; | ||
AutoForm.displayName = `Auto${base.displayName}`; | ||
AutoForm.displayName = `Auto${Base.displayName}`; | ||
return AutoForm; | ||
} | ||
export default Auto(ValidatedQuickForm); | ||
export const AutoForm = Auto(ValidatedQuickForm); |
@@ -1,9 +0,9 @@ | ||
import React, { Component, SyntheticEvent } from 'react'; | ||
import Bridge from './Bridge'; | ||
import { Component, SyntheticEvent } from 'react'; | ||
import { Bridge } from './Bridge'; | ||
import { ChangedMap, Context, DeepPartial, ModelTransformMode } from './types'; | ||
export declare type BaseFormProps<Model extends {}> = { | ||
export declare type BaseFormProps<Model> = { | ||
autosave: boolean; | ||
autosaveDelay: number; | ||
disabled?: boolean; | ||
error?: any; | ||
error: any; | ||
id?: string; | ||
@@ -15,11 +15,8 @@ label: boolean; | ||
onChange?(key: string, value: any): void; | ||
onSubmit?(model: DeepPartial<Model>): any; | ||
onSubmitSuccess?(result: any): void; | ||
onSubmitFailure?(result: any): void; | ||
onSubmit(model: DeepPartial<Model>): any; | ||
placeholder?: boolean; | ||
schema: any; | ||
schema: Bridge; | ||
showInlineError?: boolean; | ||
}; | ||
export declare type BaseFormState<Model extends {}> = { | ||
bridge: Bridge; | ||
export declare type BaseFormState<Model> = { | ||
changed: boolean; | ||
@@ -30,3 +27,3 @@ changedMap: ChangedMap<Model>; | ||
}; | ||
export default class BaseForm<Model extends {} = Record<string, any>, Props extends BaseFormProps<Model> = BaseFormProps<Model>, State extends BaseFormState<Model> = BaseFormState<Model>> extends Component<Props, State> { | ||
export declare class BaseForm<Model, Props extends BaseFormProps<Model> = BaseFormProps<Model>, State extends BaseFormState<Model> = BaseFormState<Model>> extends Component<Props, State> { | ||
static displayName: string; | ||
@@ -36,12 +33,11 @@ static defaultProps: { | ||
autosaveDelay: number; | ||
error: null; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
onSubmit(): void; | ||
}; | ||
constructor(props: Props); | ||
static getDerivedStateFromProps({ schema }: BaseFormProps<any>, { bridge }: BaseFormState<any>): { | ||
bridge: Bridge; | ||
}; | ||
componentDidMount(): void; | ||
componentDidUpdate(prevProps: any, prevState: any, snapshot: any): void; | ||
componentDidUpdate(prevProps: Props, prevState: State, snapshot: never): void; | ||
componentWillUnmount(): void; | ||
@@ -54,23 +50,17 @@ delayId?: any; | ||
randomId: () => string; | ||
getContext(): Context; | ||
getContextName(): never[]; | ||
getContextError(): Props["error"]; | ||
getContextModel(): DeepPartial<Model>; | ||
getContextState(): Context['state']; | ||
getContextSchema(): State["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: React.SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getModel(mode?: ModelTransformMode, model?: DeepPartial<Model>): DeepPartial<Model>; | ||
getChangedKeys<T>(root: string, valueA?: T, valueB?: T): string[]; | ||
getContext(): Context<Model>; | ||
getContextName(): Context<Model>['name']; | ||
getContextError(): Context<Model>['error']; | ||
getContextModel(): Context<Model>['model']; | ||
getContextState(): Context<Model>['state']; | ||
getContextSchema(): Context<Model>['schema']; | ||
getContextOnChange(): Context<Model>['onChange']; | ||
getContextOnSubmit(): Context<Model>['onSubmit']; | ||
getModel(mode?: ModelTransformMode, model?: DeepPartial<Model>): Context<Model>['model']; | ||
getNativeFormProps(): Record<string, any>; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State): { | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
__reset(state: State): Partial<State>; | ||
onReset(): void; | ||
onSubmit(event?: SyntheticEvent): Promise<void>; | ||
onSubmit(event?: SyntheticEvent): Promise<any>; | ||
render(): JSX.Element; | ||
} |
import React, { Component } from 'react'; | ||
import cloneDeep from 'lodash/cloneDeep'; | ||
import clone from 'lodash/clone'; | ||
import get from 'lodash/get'; | ||
import isFunction from 'lodash/isFunction'; | ||
import omit from 'lodash/omit'; | ||
import set from 'lodash/set'; | ||
import changedKeys from './changedKeys'; | ||
import context from './context'; | ||
import createSchemaBridge from './createSchemaBridge'; | ||
import randomIds from './randomIds'; | ||
export default class BaseForm extends Component { | ||
import setWith from 'lodash/setWith'; | ||
import { changedKeys } from './changedKeys'; | ||
import { context } from './context'; | ||
import { randomIds } from './randomIds'; | ||
export class BaseForm extends Component { | ||
constructor(props) { | ||
@@ -16,3 +14,2 @@ super(props); | ||
this.state = { | ||
bridge: createSchemaBridge(this.props.schema), | ||
changed: false, | ||
@@ -34,6 +31,2 @@ changedMap: Object.create(null), | ||
} | ||
static getDerivedStateFromProps({ schema }, { bridge }) { | ||
// TODO: It updates the state each time. Add bridge.isSame(schema)? | ||
return { bridge: createSchemaBridge(schema) }; | ||
} | ||
componentDidMount() { | ||
@@ -80,3 +73,3 @@ this.mounted = true; | ||
getContextSchema() { | ||
return this.state.bridge; | ||
return this.props.schema; | ||
} | ||
@@ -92,5 +85,2 @@ getContextOnChange() { | ||
} | ||
getChangedKeys(root, valueA, valueB) { | ||
return changedKeys(root, valueA, valueB); | ||
} | ||
getNativeFormProps() { | ||
@@ -118,8 +108,12 @@ const props = omit(this.props, [ | ||
if (this.mounted) { | ||
const keys = this.getChangedKeys(key, value, get(this.getModel(), key)); | ||
const keys = changedKeys(key, value, get(this.getModel(), key)); | ||
if (keys.length !== 0) { | ||
this.setState(state => ({ | ||
changed: true, | ||
changedMap: keys.reduce((changedMap, key) => set(changedMap, key, {}), cloneDeep(state.changedMap)), | ||
})); | ||
this.setState(state => | ||
// If all are already marked, we can skip the update completely. | ||
state.changed && keys.every(key => !!get(state.changedMap, key)) | ||
? null | ||
: { | ||
changed: true, | ||
changedMap: keys.reduce((changedMap, key) => setWith(changedMap, key, {}, clone), clone(state.changedMap)), | ||
}); | ||
} | ||
@@ -149,7 +143,8 @@ } | ||
changedMap: Object.create(null), | ||
resetCount: state.resetCount + 1, | ||
submitting: false, | ||
resetCount: state.resetCount + 1, | ||
}; | ||
} | ||
onReset() { | ||
// @ts-ignore | ||
this.setState(this.__reset); | ||
@@ -162,15 +157,10 @@ } | ||
} | ||
const result = this.props.onSubmit && this.props.onSubmit(this.getModel('submit')); | ||
// Set the `submitting` state only if onSubmit is async so we don't cause an unnecessary re-render | ||
let submitting; | ||
if (isPromiseLike(result)) { | ||
this.setState({ submitting: true }); | ||
submitting = result.finally(() => { | ||
this.setState({ submitting: false }); | ||
}); | ||
const result = this.props.onSubmit(this.getModel('submit')); | ||
if (!(result instanceof Promise)) { | ||
return Promise.resolve(result); | ||
} | ||
else { | ||
submitting = Promise.resolve(result); | ||
} | ||
return submitting.then(this.props.onSubmitSuccess, this.props.onSubmitFailure); | ||
this.setState({ submitting: true }); | ||
return result.finally(() => { | ||
this.setState({ submitting: false }); | ||
}); | ||
} | ||
@@ -186,8 +176,7 @@ render() { | ||
autosaveDelay: 0, | ||
error: null, | ||
label: true, | ||
model: Object.create(null), | ||
noValidate: true, | ||
onSubmit() { }, | ||
}; | ||
function isPromiseLike(value) { | ||
return !!value && isFunction(value.then); | ||
} |
@@ -1,4 +0,3 @@ | ||
export default abstract class Bridge { | ||
export declare abstract class Bridge { | ||
constructor(...args: any[]); | ||
static check(schema: any): boolean; | ||
getError(name: string, error: any): any; | ||
@@ -12,3 +11,3 @@ getErrorMessage(name: string, error: any): string | undefined; | ||
getType(name: string): any; | ||
getValidator(options?: any): (model: Record<string, any>) => void; | ||
getValidator(options?: any): (model: Record<string, any>) => any; | ||
} |
import invariant from 'invariant'; | ||
export default class Bridge { | ||
export class Bridge { | ||
constructor(...args) { | ||
invariant(this.constructor !== Bridge, 'Bridge cannot be instantiated (args=%o).', { args }); | ||
} | ||
static check(schema) { | ||
return invariant(false, '%s have not implemented `check` method (args=%o).', this.name, { schema }); | ||
} | ||
getError(name, error) { | ||
@@ -10,0 +7,0 @@ return invariant(false, '%s have not implemented `getError` method (args=%o).', this.constructor.name, { name, error }); |
@@ -1,1 +0,1 @@ | ||
export default function changedKeys<T>(root: string, valueA?: T, valueB?: T): string[]; | ||
export declare function changedKeys<T>(root: string, valueA?: T, valueB?: T): string[]; |
import isEqual from 'lodash/isEqual'; | ||
import xorWith from 'lodash/xorWith'; | ||
import joinName from './joinName'; | ||
export default function changedKeys(root, valueA, valueB) { | ||
import { joinName } from './joinName'; | ||
export function changedKeys(root, valueA, valueB) { | ||
if (!valueA || valueA !== Object(valueA) || valueA instanceof Date) | ||
@@ -6,0 +6,0 @@ return isEqual(valueA, valueB) ? [] : [root]; |
import React, { ComponentType } from 'react'; | ||
import { GuaranteedProps } from './types'; | ||
export default function connectField<Props extends Partial<GuaranteedProps<Value>>, Value = Props['value']>(Component: ComponentType<Props>, options?: { | ||
export declare function connectField<Props extends Partial<GuaranteedProps<Value>>, Value = Props['value']>(Component: ComponentType<Props>, options?: { | ||
includeInChain?: boolean; | ||
@@ -8,2 +8,2 @@ initialValue?: boolean; | ||
name: string; | ||
} & Partial<GuaranteedProps<Value>> & Pick<Props, Exclude<keyof Props, "disabled" | "label" | "error" | "id" | "onChange" | "placeholder" | "showInlineError" | "changed" | "value" | "errorMessage" | "field" | "fieldType" | "fields" | "name">>>; | ||
} & Partial<GuaranteedProps<Value>> & Pick<Props, Exclude<keyof Props, "disabled" | "label" | "changed" | "error" | "id" | "onChange" | "placeholder" | "showInlineError" | "name" | "value" | "errorMessage" | "field" | "fieldType" | "fields">>>; |
import React from 'react'; | ||
import mapValues from 'lodash/mapValues'; | ||
import some from 'lodash/some'; | ||
import contextReference from './context'; | ||
import useField from './useField'; | ||
export default function connectField(Component, options) { | ||
import { context as contextReference } from './context'; | ||
import { useField } from './useField'; | ||
export function connectField(Component, options) { | ||
function Field(props) { | ||
@@ -8,0 +8,0 @@ const [fieldProps, context] = useField(props.name, props, options); |
/// <reference types="react" /> | ||
import { Context } from './types'; | ||
declare const _default: import("react").Context<Context<Record<string, any>> | null>; | ||
export default _default; | ||
export declare const context: import("react").Context<Context<any> | null>; |
import { createContext } from 'react'; | ||
export default createContext(null); | ||
export const context = createContext(null); |
@@ -1,8 +0,8 @@ | ||
import Bridge from './Bridge'; | ||
import { Bridge } from './Bridge'; | ||
declare function create(schema: any): Bridge; | ||
declare function register(bridge: typeof Bridge): void; | ||
declare const _default: typeof create & { | ||
export declare const createSchemaBridge: typeof create & { | ||
register: typeof register; | ||
registered: (typeof Bridge)[]; | ||
}; | ||
export default _default; | ||
export {}; |
@@ -27,2 +27,5 @@ import invariant from 'invariant'; | ||
} | ||
export default Object.assign(create, { register, registered }); | ||
export const createSchemaBridge = Object.assign(create, { | ||
register, | ||
registered, | ||
}); |
@@ -1,7 +0,7 @@ | ||
declare function filter<T extends {}>(props: T): Partial<T>; | ||
declare function filter<T extends object>(props: T): Partial<T>; | ||
declare function register(...props: string[]): void; | ||
declare const _default: typeof filter & { | ||
export declare const filterDOMProps: typeof filter & { | ||
register: typeof register; | ||
registered: string[]; | ||
registered: readonly string[]; | ||
}; | ||
export default _default; | ||
export {}; |
@@ -1,7 +0,7 @@ | ||
import omit from 'lodash/omit'; | ||
import pickBy from 'lodash/pickBy'; | ||
import sortedIndex from 'lodash/sortedIndex'; | ||
import sortedIndexOf from 'lodash/sortedIndexOf'; | ||
const registered = [ | ||
// These props are provided by BaseField | ||
// These props are provided by useField directly. | ||
'changed', | ||
'changedMap', | ||
'disabled', | ||
'error', | ||
@@ -12,30 +12,33 @@ 'errorMessage', | ||
'fields', | ||
'findError', | ||
'findField', | ||
'findValue', | ||
'initialCount', | ||
'label', | ||
'name', | ||
'onChange', | ||
'parent', | ||
'transform', | ||
'value', | ||
// These props are provided by useField through context.state. | ||
'disabled', | ||
'label', | ||
'placeholder', | ||
'showInlineError', | ||
'submitting', | ||
'transform', | ||
'validating', | ||
'value', | ||
// These are used by AutoField | ||
// This is used by AutoField. | ||
'component', | ||
// These is used by AutoField and bridges. | ||
'allowedValues', | ||
'component', | ||
]; | ||
].sort(); | ||
function filter(props) { | ||
return omit(props, registered); | ||
return pickBy(props, filterOne); | ||
} | ||
function filterOne(value, prop) { | ||
return sortedIndexOf(registered, prop) === -1; | ||
} | ||
function register(...props) { | ||
props.forEach(prop => { | ||
if (!registered.includes(prop)) { | ||
registered.push(prop); | ||
if (sortedIndexOf(registered, prop) === -1) { | ||
registered.splice(sortedIndex(registered, prop), 0, prop); | ||
} | ||
}); | ||
} | ||
export default Object.assign(filter, { register, registered }); | ||
export const filterDOMProps = Object.assign(filter, { | ||
register, | ||
registered: registered, | ||
}); |
@@ -0,17 +1,16 @@ | ||
export * from './AutoForm'; | ||
export * from './BaseForm'; | ||
export * from './Bridge'; | ||
export * from './QuickForm'; | ||
export * from './ValidatedForm'; | ||
export * from './ValidatedQuickForm'; | ||
export * from './changedKeys'; | ||
export * from './connectField'; | ||
export * from './context'; | ||
export * from './filterDOMProps'; | ||
export * from './injectName'; | ||
export * from './joinName'; | ||
export * from './randomIds'; | ||
export * from './types'; | ||
export { default as AutoForm } from './AutoForm'; | ||
export { default as BaseForm } from './BaseForm'; | ||
export { default as Bridge } from './Bridge'; | ||
export { default as QuickForm } from './QuickForm'; | ||
export { default as ValidatedForm } from './ValidatedForm'; | ||
export { default as ValidatedQuickForm } from './ValidatedQuickForm'; | ||
export { default as changedKeys } from './changedKeys'; | ||
export { default as connectField } from './connectField'; | ||
export { default as context } from './context'; | ||
export { default as createSchemaBridge } from './createSchemaBridge'; | ||
export { default as filterDOMProps } from './filterDOMProps'; | ||
export { default as injectName } from './injectName'; | ||
export { default as joinName } from './joinName'; | ||
export { default as randomIds } from './randomIds'; | ||
export { default as useField } from './useField'; | ||
export { default as useForm } from './useForm'; | ||
export * from './useField'; | ||
export * from './useForm'; |
@@ -1,16 +0,15 @@ | ||
export { default as AutoForm } from './AutoForm'; | ||
export { default as BaseForm } from './BaseForm'; | ||
export { default as Bridge } from './Bridge'; | ||
export { default as QuickForm } from './QuickForm'; | ||
export { default as ValidatedForm } from './ValidatedForm'; | ||
export { default as ValidatedQuickForm } from './ValidatedQuickForm'; | ||
export { default as changedKeys } from './changedKeys'; | ||
export { default as connectField } from './connectField'; | ||
export { default as context } from './context'; | ||
export { default as createSchemaBridge } from './createSchemaBridge'; | ||
export { default as filterDOMProps } from './filterDOMProps'; | ||
export { default as injectName } from './injectName'; | ||
export { default as joinName } from './joinName'; | ||
export { default as randomIds } from './randomIds'; | ||
export { default as useField } from './useField'; | ||
export { default as useForm } from './useForm'; | ||
export * from './AutoForm'; | ||
export * from './BaseForm'; | ||
export * from './Bridge'; | ||
export * from './QuickForm'; | ||
export * from './ValidatedForm'; | ||
export * from './ValidatedQuickForm'; | ||
export * from './changedKeys'; | ||
export * from './connectField'; | ||
export * from './context'; | ||
export * from './filterDOMProps'; | ||
export * from './injectName'; | ||
export * from './joinName'; | ||
export * from './randomIds'; | ||
export * from './useField'; | ||
export * from './useForm'; |
import { ReactNode } from 'react'; | ||
export default function injectName(name: string, children: ReactNode, parent?: ReactNode): ReactNode[]; | ||
export declare function injectName(name: string, children: ReactNode, parent?: ReactNode): ReactNode[]; |
import get from 'lodash/get'; | ||
import { Children, cloneElement } from 'react'; | ||
import joinName from './joinName'; | ||
export default function injectName(name, children, parent) { | ||
import { joinName } from './joinName'; | ||
export function injectName(name, children, parent) { | ||
return Children.map(Children.toArray(children), child => { | ||
@@ -6,0 +6,0 @@ if (!child || typeof child !== 'object' || get(parent, 'props.name')) |
@@ -1,3 +0,2 @@ | ||
declare function joinName(flag: null, ...parts: unknown[]): string[]; | ||
declare function joinName(...parts: unknown[]): string; | ||
export default joinName; | ||
export declare function joinName(flag: null, ...parts: unknown[]): string[]; | ||
export declare function joinName(...parts: unknown[]): string; |
@@ -1,2 +0,2 @@ | ||
function joinName(...parts) { | ||
export function joinName(...parts) { | ||
const name = parts.reduce((parts, part) => part || part === 0 | ||
@@ -7,2 +7,1 @@ ? parts.concat(typeof part === 'string' ? part.split('.') : part) | ||
} | ||
export default joinName; |
import React, { ComponentType } from 'react'; | ||
import BaseForm, { BaseFormProps, BaseFormState } from './BaseForm'; | ||
export declare type QuickFormProps<Model extends {}> = BaseFormProps<Model> & { | ||
import { BaseForm, BaseFormProps, BaseFormState } from './BaseForm'; | ||
export declare type QuickFormProps<Model> = BaseFormProps<Model> & { | ||
autoField?: ComponentType<{ | ||
name?: string; | ||
name: string; | ||
}>; | ||
@@ -10,8 +10,8 @@ errorsField?: ComponentType; | ||
}; | ||
export declare type QuickFormState<Model extends {}> = BaseFormState<Model>; | ||
declare function Quick<Base extends typeof BaseForm>(base: Base): { | ||
new <Model extends {} = Record<string, any>, Props extends QuickFormProps<Model> = QuickFormProps<Model>, State extends BaseFormState<Model> = BaseFormState<Model>>(props: Props): { | ||
export declare type QuickFormState<Model> = BaseFormState<Model>; | ||
export declare function Quick<Base extends typeof BaseForm>(Base: Base): { | ||
new <Model, Props extends QuickFormProps<Model> = QuickFormProps<Model>, State extends BaseFormState<Model> = BaseFormState<Model>>(props: Props): { | ||
getNativeFormProps(): Record<string, any>; | ||
getAutoField(): React.ComponentType<{ | ||
name?: string | undefined; | ||
name: string; | ||
}>; | ||
@@ -21,3 +21,3 @@ getErrorsField(): React.ComponentType<{}>; | ||
componentDidMount(): void; | ||
componentDidUpdate(prevProps: any, prevState: any, snapshot: any): void; | ||
componentDidUpdate(prevProps: Props, prevState: State, snapshot: never): void; | ||
componentWillUnmount(): void; | ||
@@ -30,5 +30,5 @@ delayId?: any; | ||
randomId: () => string; | ||
getContext(): import("./types").Context<Record<string, any>>; | ||
getContextName(): never[]; | ||
getContextError(): Props["error"]; | ||
getContext(): import("./types").Context<Model>; | ||
getContextName(): string[]; | ||
getContextError(): any; | ||
getContextModel(): import("./types").DeepPartial<Model>; | ||
@@ -41,16 +41,10 @@ getContextState(): { | ||
}; | ||
getContextSchema(): State["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: React.SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getContextSchema(): import("./Bridge").Bridge; | ||
getContextOnChange(): (key: string, value?: any) => void; | ||
getContextOnSubmit(): (event?: React.SyntheticEvent<Element, Event> | undefined) => any; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: import("./types").DeepPartial<Model>): import("./types").DeepPartial<Model>; | ||
getChangedKeys<T>(root: string, valueA?: T | undefined, valueB?: T | undefined): string[]; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State): { | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
__reset(state: State): Partial<State>; | ||
onReset(): void; | ||
onSubmit(event?: React.SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
onSubmit(event?: React.SyntheticEvent<Element, Event> | undefined): Promise<any>; | ||
render(): JSX.Element; | ||
@@ -82,16 +76,15 @@ context: any; | ||
autosaveDelay: number; | ||
error: null; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
onSubmit(): void; | ||
}; | ||
getDerivedStateFromProps({ schema }: BaseFormProps<any>, { bridge }: BaseFormState<any>): { | ||
bridge: import("./Bridge").default; | ||
}; | ||
contextType?: React.Context<any> | undefined; | ||
} & Base; | ||
declare const _default: { | ||
new <Model extends {} = Record<string, any>, Props extends QuickFormProps<Model> = QuickFormProps<Model>, State extends BaseFormState<Model> = BaseFormState<Model>>(props: Props): { | ||
export declare const QuickForm: { | ||
new <Model, Props extends QuickFormProps<Model> = QuickFormProps<Model>, State extends BaseFormState<Model> = BaseFormState<Model>>(props: Props): { | ||
getNativeFormProps(): Record<string, any>; | ||
getAutoField(): React.ComponentType<{ | ||
name?: string | undefined; | ||
name: string; | ||
}>; | ||
@@ -101,3 +94,3 @@ getErrorsField(): React.ComponentType<{}>; | ||
componentDidMount(): void; | ||
componentDidUpdate(prevProps: any, prevState: any, snapshot: any): void; | ||
componentDidUpdate(prevProps: Props, prevState: State, snapshot: never): void; | ||
componentWillUnmount(): void; | ||
@@ -110,5 +103,5 @@ delayId?: any; | ||
randomId: () => string; | ||
getContext(): import("./types").Context<Record<string, any>>; | ||
getContextName(): never[]; | ||
getContextError(): Props["error"]; | ||
getContext(): import("./types").Context<Model>; | ||
getContextName(): string[]; | ||
getContextError(): any; | ||
getContextModel(): import("./types").DeepPartial<Model>; | ||
@@ -121,16 +114,10 @@ getContextState(): { | ||
}; | ||
getContextSchema(): State["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: React.SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getContextSchema(): import("./Bridge").Bridge; | ||
getContextOnChange(): (key: string, value?: any) => void; | ||
getContextOnSubmit(): (event?: React.SyntheticEvent<Element, Event> | undefined) => any; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: import("./types").DeepPartial<Model>): import("./types").DeepPartial<Model>; | ||
getChangedKeys<T>(root: string, valueA?: T | undefined, valueB?: T | undefined): string[]; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State): { | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
__reset(state: State): Partial<State>; | ||
onReset(): void; | ||
onSubmit(event?: React.SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
onSubmit(event?: React.SyntheticEvent<Element, Event> | undefined): Promise<any>; | ||
render(): JSX.Element; | ||
@@ -162,11 +149,10 @@ context: any; | ||
autosaveDelay: number; | ||
error: null; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
onSubmit(): void; | ||
}; | ||
getDerivedStateFromProps({ schema }: BaseFormProps<any>, { bridge }: BaseFormState<any>): { | ||
bridge: import("./Bridge").default; | ||
}; | ||
contextType?: React.Context<any> | undefined; | ||
} & typeof BaseForm; | ||
export default _default; | ||
export declare type QuickForm = typeof QuickForm; |
import { __rest } from "tslib"; | ||
import React from 'react'; | ||
import BaseForm from './BaseForm'; | ||
function Quick(base) { | ||
import { BaseForm } from './BaseForm'; | ||
export function Quick(Base) { | ||
// @ts-ignore: Mixin class problem. | ||
class QuickForm extends base { | ||
class QuickForm extends Base { | ||
getNativeFormProps() { | ||
@@ -12,3 +12,3 @@ const _a = super.getNativeFormProps(), { autoField: AutoField = this.getAutoField(), errorsField: ErrorsField = this.getErrorsField(), submitField: SubmitField = this.getSubmitField() } = _a, props = __rest(_a, ["autoField", "errorsField", "submitField"]); | ||
.getSubfields() | ||
.map((key) => React.createElement(AutoField, { key: key, name: key })) | ||
.map(key => React.createElement(AutoField, { key: key, name: key })) | ||
.concat([ | ||
@@ -32,5 +32,5 @@ React.createElement(ErrorsField, { key: "$ErrorsField" }), | ||
QuickForm.Quick = Quick; | ||
QuickForm.displayName = `Quick${base.displayName}`; | ||
QuickForm.displayName = `Quick${Base.displayName}`; | ||
return QuickForm; | ||
} | ||
export default Quick(BaseForm); | ||
export const QuickForm = Quick(BaseForm); |
@@ -1,1 +0,1 @@ | ||
export default function randomIds(prefix?: string): () => string; | ||
export declare function randomIds(prefix?: string): () => string; |
@@ -9,4 +9,4 @@ // Workaround for SSR | ||
const randomIdPrefix = randomIdsGenerator('uniforms'); | ||
export default function randomIds(prefix = randomIdPrefix()) { | ||
export function randomIds(prefix = randomIdPrefix()) { | ||
return randomIdsGenerator(prefix); | ||
} |
import { SyntheticEvent } from 'react'; | ||
import Bridge from './Bridge'; | ||
import { Bridge } from './Bridge'; | ||
export declare type ChangedMap<T> = T extends {} ? { | ||
[P in keyof T]?: ChangedMap<T[P]>; | ||
} : Record<string, void>; | ||
export declare type Context<Model extends {} = Record<string, any>> = { | ||
export declare type Context<Model> = { | ||
changed: boolean; | ||
@@ -45,4 +45,4 @@ changedMap: ChangedMap<Model>; | ||
export declare type ModelTransformMode = 'form' | 'submit' | 'validate'; | ||
export declare type Override<T, U> = U & Omit<T, keyof U>; | ||
export declare type Partialize<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>; | ||
export declare type ValidateMode = 'onChange' | 'onChangeAfterSubmit' | 'onSubmit'; | ||
export declare type Override<T, U> = U & Omit<T, keyof U>; |
import { GuaranteedProps } from './types'; | ||
export default function useField<Props extends Record<string, any>, Value = Props['value'], Model = Record<string, any>>(fieldName: string, props: Props, options?: { | ||
export declare function useField<Props extends Record<string, any>, Value = Props['value'], Model = Record<string, any>>(fieldName: string, props: Props, options?: { | ||
initialValue?: boolean; | ||
}): [GuaranteedProps<Value> & Props, import("./types").Context<Model>]; |
import get from 'lodash/get'; | ||
import mapValues from 'lodash/mapValues'; | ||
import { useCallback, useEffect, useMemo } from 'react'; | ||
import joinName from './joinName'; | ||
import useForm from './useForm'; | ||
import { joinName } from './joinName'; | ||
import { useForm } from './useForm'; | ||
function propagate(prop, schema, state, fallback) { | ||
@@ -16,3 +16,3 @@ const schemaDisabled = schema === false || schema === ''; | ||
} | ||
export default function useField(fieldName, props, options) { | ||
export function useField(fieldName, props, options) { | ||
var _a, _b; | ||
@@ -19,0 +19,0 @@ const context = useForm(); |
import { Context } from './types'; | ||
export default function useForm<Model extends {}>(): Context<Model>; | ||
export declare function useForm<Model>(): Context<Model>; |
import invariant from 'invariant'; | ||
import { useContext } from 'react'; | ||
import contextReference from './context'; | ||
export default function useForm() { | ||
import { context as contextReference } from './context'; | ||
export function useForm() { | ||
const context = useContext(contextReference); | ||
@@ -6,0 +6,0 @@ invariant(context !== null, 'useForm must be used within a form.'); |
import { SyntheticEvent } from 'react'; | ||
import BaseForm, { BaseFormProps, BaseFormState } from './BaseForm'; | ||
import { DeepPartial, ValidateMode } from './types'; | ||
export declare type ValidatedFormProps<Model extends {}> = BaseFormProps<Model> & { | ||
onValidate: (model: DeepPartial<Model>, error: any, callback: (error?: any) => void) => void; | ||
import { BaseForm, BaseFormProps, BaseFormState } from './BaseForm'; | ||
import { Context, DeepPartial, ValidateMode } from './types'; | ||
export declare type ValidatedFormProps<Model> = BaseFormProps<Model> & { | ||
onValidate(model: DeepPartial<Model>, error: any): any; | ||
validate: ValidateMode; | ||
validator?: any; | ||
}; | ||
export declare type ValidatedFormState<Model extends {}> = BaseFormState<Model> & { | ||
export declare type ValidatedFormState<Model> = BaseFormState<Model> & { | ||
error: any; | ||
validate: boolean; | ||
validating: boolean; | ||
validator: (model: DeepPartial<Model>) => void | never; | ||
validator(model: DeepPartial<Model>): any; | ||
}; | ||
declare function Validated<Base extends typeof BaseForm>(base: Base): { | ||
new <Model extends {} = Record<string, any>, Props extends ValidatedFormProps<Model> = ValidatedFormProps<Model>, State extends ValidatedFormState<Model> = ValidatedFormState<Model>>(props: Props): { | ||
validate: (key?: string | undefined, value?: any) => Promise<unknown>; | ||
validateModel: (model: any) => Promise<unknown>; | ||
getContextError(): State["error"]; | ||
getContext(): { | ||
validating: State["validating"]; | ||
changed: boolean; | ||
changedMap: { | ||
[x: string]: Record<string, void> | { | ||
[x: string]: Record<string, void> | any | undefined; | ||
} | undefined; | ||
}; | ||
error: any; | ||
model: DeepPartial<Record<string, any>>; | ||
name: string[]; | ||
onChange(key: string, value?: any): void; | ||
onSubmit(event?: SyntheticEvent<Element, Event> | undefined): any; | ||
randomId(): string; | ||
schema: import("./Bridge").default; | ||
state: { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
submitting: boolean; | ||
}; | ||
export declare function Validated<Base extends typeof BaseForm>(Base: Base): { | ||
new <Model, Props extends ValidatedFormProps<Model> = ValidatedFormProps<Model>, State extends ValidatedFormState<Model> = ValidatedFormState<Model>>(props: Props): { | ||
validate: (key?: string | undefined, value?: any) => Promise<any>; | ||
validateModel: (originalModel: any) => Promise<any>; | ||
getContextError(): any; | ||
getContext(): Context<Model>; | ||
getNativeFormProps(): Record<string, any>; | ||
componentDidUpdate(prevProps: Props, prevState: State, snapshot: never): void; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State): { | ||
error: null; | ||
validate: boolean; | ||
validating: boolean; | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
onSubmit(event?: SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
onValidate(key?: string | undefined, value?: any): Promise<unknown>; | ||
onValidateModel(model: Props["model"]): Promise<unknown>; | ||
__reset(state: State): Partial<State>; | ||
onSubmit(event?: SyntheticEvent<Element, Event> | undefined): Promise<any>; | ||
onValidate(key?: string | undefined, value?: any): Promise<any>; | ||
onValidateModel(originalModel: Props["model"]): Promise<any>; | ||
componentDidMount(): void; | ||
@@ -66,3 +36,3 @@ componentWillUnmount(): void; | ||
randomId: () => string; | ||
getContextName(): never[]; | ||
getContextName(): string[]; | ||
getContextModel(): DeepPartial<Model>; | ||
@@ -75,7 +45,6 @@ getContextState(): { | ||
}; | ||
getContextSchema(): State["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getContextSchema(): import("./Bridge").Bridge; | ||
getContextOnChange(): (key: string, value?: any) => void; | ||
getContextOnSubmit(): (event?: SyntheticEvent<Element, Event> | undefined) => any; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: DeepPartial<Model>): DeepPartial<Model>; | ||
getChangedKeys<T>(root: string, valueA?: T | undefined, valueB?: T | undefined): string[]; | ||
onReset(): void; | ||
@@ -106,58 +75,27 @@ render(): JSX.Element; | ||
defaultProps: { | ||
onValidate(model: any, error: any, callback: any): void; | ||
onValidate(model: any, error: any): any; | ||
validate: string; | ||
autosave: boolean; | ||
autosaveDelay: number; | ||
error: null; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
onSubmit(): void; | ||
}; | ||
getDerivedStateFromProps({ schema }: BaseFormProps<any>, { bridge }: BaseFormState<any>): { | ||
bridge: import("./Bridge").default; | ||
}; | ||
contextType?: import("react").Context<any> | undefined; | ||
} & Base; | ||
declare const _default: { | ||
new <Model extends {} = Record<string, any>, Props extends ValidatedFormProps<Model> = ValidatedFormProps<Model>, State extends ValidatedFormState<Model> = ValidatedFormState<Model>>(props: Props): { | ||
validate: (key?: string | undefined, value?: any) => Promise<unknown>; | ||
validateModel: (model: any) => Promise<unknown>; | ||
getContextError(): State["error"]; | ||
getContext(): { | ||
validating: State["validating"]; | ||
changed: boolean; | ||
changedMap: { | ||
[x: string]: Record<string, void> | { | ||
[x: string]: Record<string, void> | any | undefined; | ||
} | undefined; | ||
}; | ||
error: any; | ||
model: DeepPartial<Record<string, any>>; | ||
name: string[]; | ||
onChange(key: string, value?: any): void; | ||
onSubmit(event?: SyntheticEvent<Element, Event> | undefined): any; | ||
randomId(): string; | ||
schema: import("./Bridge").default; | ||
state: { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
submitting: boolean; | ||
}; | ||
export declare const ValidatedForm: { | ||
new <Model, Props extends ValidatedFormProps<Model> = ValidatedFormProps<Model>, State extends ValidatedFormState<Model> = ValidatedFormState<Model>>(props: Props): { | ||
validate: (key?: string | undefined, value?: any) => Promise<any>; | ||
validateModel: (originalModel: any) => Promise<any>; | ||
getContextError(): any; | ||
getContext(): Context<Model>; | ||
getNativeFormProps(): Record<string, any>; | ||
componentDidUpdate(prevProps: Props, prevState: State, snapshot: never): void; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State): { | ||
error: null; | ||
validate: boolean; | ||
validating: boolean; | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
onSubmit(event?: SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
onValidate(key?: string | undefined, value?: any): Promise<unknown>; | ||
onValidateModel(model: Props["model"]): Promise<unknown>; | ||
__reset(state: State): Partial<State>; | ||
onSubmit(event?: SyntheticEvent<Element, Event> | undefined): Promise<any>; | ||
onValidate(key?: string | undefined, value?: any): Promise<any>; | ||
onValidateModel(originalModel: Props["model"]): Promise<any>; | ||
componentDidMount(): void; | ||
@@ -171,3 +109,3 @@ componentWillUnmount(): void; | ||
randomId: () => string; | ||
getContextName(): never[]; | ||
getContextName(): string[]; | ||
getContextModel(): DeepPartial<Model>; | ||
@@ -180,7 +118,6 @@ getContextState(): { | ||
}; | ||
getContextSchema(): State["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getContextSchema(): import("./Bridge").Bridge; | ||
getContextOnChange(): (key: string, value?: any) => void; | ||
getContextOnSubmit(): (event?: SyntheticEvent<Element, Event> | undefined) => any; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: DeepPartial<Model>): DeepPartial<Model>; | ||
getChangedKeys<T>(root: string, valueA?: T | undefined, valueB?: T | undefined): string[]; | ||
onReset(): void; | ||
@@ -211,15 +148,14 @@ render(): JSX.Element; | ||
defaultProps: { | ||
onValidate(model: any, error: any, callback: any): void; | ||
onValidate(model: any, error: any): any; | ||
validate: string; | ||
autosave: boolean; | ||
autosaveDelay: number; | ||
error: null; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
onSubmit(): void; | ||
}; | ||
getDerivedStateFromProps({ schema }: BaseFormProps<any>, { bridge }: BaseFormState<any>): { | ||
bridge: import("./Bridge").default; | ||
}; | ||
contextType?: import("react").Context<any> | undefined; | ||
} & typeof BaseForm; | ||
export default _default; | ||
export declare type ValidatedForm = typeof ValidatedForm; |
@@ -0,1 +1,2 @@ | ||
import clone from 'lodash/clone'; | ||
import cloneDeep from 'lodash/cloneDeep'; | ||
@@ -5,10 +6,10 @@ import isEqual from 'lodash/isEqual'; | ||
import omit from 'lodash/omit'; | ||
import set from 'lodash/set'; | ||
import BaseForm from './BaseForm'; | ||
function Validated(base) { | ||
import setWith from 'lodash/setWith'; | ||
import { BaseForm } from './BaseForm'; | ||
export function Validated(Base) { | ||
// @ts-ignore: Mixin class problem. | ||
class ValidatedForm extends base { | ||
class ValidatedForm extends Base { | ||
constructor(props) { | ||
super(props); | ||
this.state = Object.assign(Object.assign({}, this.state), { error: null, validate: false, validating: false, validator: this.getContextSchema().getValidator(this.props.validator) }); | ||
this.state = Object.assign(Object.assign({}, this.state), { error: null, validate: false, validating: false, validator: this.getContextSchema().getValidator(props.validator) }); | ||
this.onValidate = this.validate = this.onValidate.bind(this); | ||
@@ -18,3 +19,4 @@ this.onValidateModel = this.validateModel = this.onValidateModel.bind(this); | ||
getContextError() { | ||
return super.getContextError() || this.state.error; | ||
var _a; | ||
return (_a = super.getContextError()) !== null && _a !== void 0 ? _a : this.state.error; | ||
} | ||
@@ -35,5 +37,5 @@ getContext() { | ||
if (schema !== prevProps.schema || validator !== prevProps.validator) { | ||
this.setState(state => ({ validator: state.bridge.getValidator(validator) }), () => { | ||
this.setState({ validator: schema.getValidator(validator) }, () => { | ||
if (shouldRevalidate(validate, this.state.validate)) { | ||
this.onValidate().catch(noop); | ||
this.onValidate(); | ||
} | ||
@@ -44,3 +46,3 @@ }); | ||
shouldRevalidate(validate, this.state.validate)) { | ||
this.onValidateModel(model).catch(noop); | ||
this.onValidateModel(model); | ||
} | ||
@@ -50,8 +52,4 @@ } | ||
if (shouldRevalidate(this.props.validate, this.state.validate)) { | ||
this.onValidate(key, value).catch(noop); | ||
this.onValidate(key, value); | ||
} | ||
// FIXME: https://github.com/vazco/uniforms/issues/293 | ||
// if (this.props.validate === 'onSubmit' && this.state.validate) { | ||
// this.setState(() => ({error: null})); | ||
// } | ||
super.onChange(key, value); | ||
@@ -67,23 +65,16 @@ } | ||
} | ||
const promise = new Promise((resolve, reject) => { | ||
this.setState(() => ({ submitting: true, validate: true }), () => { | ||
this.onValidate().then(() => { | ||
super.onSubmit().then(resolve, error => { | ||
this.setState({ error }); | ||
reject(error); | ||
}); | ||
}, reject); | ||
this.setState({ validate: true }); | ||
const result = this.onValidate().then(error => { | ||
if (error !== null) { | ||
return Promise.reject(error); | ||
} | ||
// Validation failed (i.e. returned an error), so no error is present | ||
// both in the props nor the state. | ||
return super.onSubmit().catch(error => { | ||
this.setState({ error }); | ||
throw error; | ||
}); | ||
}); | ||
promise | ||
// `onSubmit` should never reject, so we ignore this rejection. | ||
.catch(noop) | ||
.then(() => { | ||
// It can be already unmounted. | ||
if (this.mounted) { | ||
// If validation fails, or `super.onSubmit` doesn't touch `submitting`, we need to reset it. | ||
this.setState(state => state.submitting ? { submitting: false } : null); | ||
} | ||
}); | ||
return promise; | ||
result.catch(noop); | ||
return result; | ||
} | ||
@@ -93,44 +84,48 @@ onValidate(key, value) { | ||
if (model && key) { | ||
model = set(cloneDeep(model), key, cloneDeep(value)); | ||
model = setWith(clone(model), key, cloneDeep(value), clone); | ||
} | ||
return this.onValidateModel(model); | ||
} | ||
onValidateModel(model) { | ||
model = this.getModel('validate', model); | ||
let catched = this.props.error || null; | ||
try { | ||
this.state.validator(model); | ||
} | ||
catch (error) { | ||
catched = error; | ||
} | ||
this.setState({ validating: true }); | ||
return new Promise((resolve, reject) => { | ||
this.props.onValidate(model, catched, (error = catched) => { | ||
// Do not copy error from props to state. | ||
this.setState(() => ({ | ||
error: error === this.props.error ? null : error, | ||
validating: false, | ||
}), () => { | ||
if (error) { | ||
reject(error); | ||
} | ||
else { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
onValidateModel(originalModel) { | ||
const model = this.getModel('validate', originalModel); | ||
// Using `then` allows using the same code for both synchronous and | ||
// asynchronous cases. We could use `await` here, but it would make all | ||
// calls asynchronous, unnecessary delaying synchronous validation. | ||
const then = makeThen(() => { | ||
this.setState({ validating: true }); | ||
}); | ||
return then(this.state.validator(model), (error = null) => then(this.props.onValidate(model, error), (error = null) => { | ||
var _a; | ||
// Do not copy the error from props to the state. | ||
error = this.props.error === error ? null : error; | ||
// If the whole operation was synchronous and resulted in the same | ||
// error, we can skip the re-render. | ||
this.setState(state => state.error === error && !state.validating | ||
? null | ||
: { error, validating: false }); | ||
// A predefined error takes precedence over the validation one. | ||
return Promise.resolve((_a = this.props.error) !== null && _a !== void 0 ? _a : error); | ||
})); | ||
} | ||
} | ||
ValidatedForm.Validated = Validated; | ||
ValidatedForm.displayName = `Validated${base.displayName}`; | ||
ValidatedForm.defaultProps = Object.assign(Object.assign({}, base.defaultProps), { onValidate(model, error, callback) { | ||
callback(); | ||
ValidatedForm.displayName = `Validated${Base.displayName}`; | ||
ValidatedForm.defaultProps = Object.assign(Object.assign({}, Base.defaultProps), { onValidate(model, error) { | ||
return error; | ||
}, validate: 'onChangeAfterSubmit' }); | ||
return ValidatedForm; | ||
} | ||
function makeThen(callIfAsync) { | ||
function then(value, fn) { | ||
if (value instanceof Promise) { | ||
callIfAsync(); | ||
return value.then(fn); | ||
} | ||
return fn(value); | ||
} | ||
return then; | ||
} | ||
function shouldRevalidate(inProps, inState) { | ||
return (inProps === 'onChange' || (inProps === 'onChangeAfterSubmit' && inState)); | ||
} | ||
export default Validated(BaseForm); | ||
export const ValidatedForm = Validated(BaseForm); |
/// <reference types="react" /> | ||
import BaseForm from './BaseForm'; | ||
import { QuickFormProps, QuickFormState } from './QuickForm'; | ||
import { ValidatedFormProps, ValidatedFormState } from './ValidatedForm'; | ||
import { BaseForm } from './BaseForm'; | ||
import { Quick, QuickFormProps, QuickFormState } from './QuickForm'; | ||
import { Validated, ValidatedFormProps, ValidatedFormState } from './ValidatedForm'; | ||
export declare type ValidatedQuickFormProps<Model> = QuickFormProps<Model> & ValidatedFormProps<Model>; | ||
export declare type ValidatedQuickFormState<Model> = QuickFormState<Model> & ValidatedFormState<Model>; | ||
declare const _default: { | ||
new <Model extends {} = Record<string, any>, Props extends ValidatedFormProps<Model> = ValidatedFormProps<Model>, State extends ValidatedFormState<Model> = ValidatedFormState<Model>>(props: Props): { | ||
validate: (key?: string | undefined, value?: any) => Promise<unknown>; | ||
validateModel: (model: any) => Promise<unknown>; | ||
getContextError(): State["error"]; | ||
getContext(): { | ||
validating: State["validating"]; | ||
changed: boolean; | ||
changedMap: { | ||
[x: string]: Record<string, void> | { | ||
[x: string]: Record<string, void> | any | undefined; | ||
} | undefined; | ||
}; | ||
error: any; | ||
model: import("./types").DeepPartial<Record<string, any>>; | ||
name: string[]; | ||
onChange(key: string, value?: any): void; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): any; | ||
randomId(): string; | ||
schema: import("./Bridge").default; | ||
state: { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
submitting: boolean; | ||
}; | ||
export declare const ValidatedQuickForm: { | ||
new <Model, Props extends ValidatedFormProps<Model> = ValidatedFormProps<Model>, State extends ValidatedFormState<Model> = ValidatedFormState<Model>>(props: Props): { | ||
validate: (key?: string | undefined, value?: any) => Promise<any>; | ||
validateModel: (originalModel: any) => Promise<any>; | ||
getContextError(): any; | ||
getContext(): import("./types").Context<Model>; | ||
getNativeFormProps(): Record<string, any>; | ||
componentDidUpdate(prevProps: Props, prevState: State, snapshot: never): void; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State): { | ||
error: null; | ||
validate: boolean; | ||
validating: boolean; | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
onValidate(key?: string | undefined, value?: any): Promise<unknown>; | ||
onValidateModel(model: Props["model"]): Promise<unknown>; | ||
__reset(state: State): Partial<State>; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<any>; | ||
onValidate(key?: string | undefined, value?: any): Promise<any>; | ||
onValidateModel(originalModel: Props["model"]): Promise<any>; | ||
componentDidMount(): void; | ||
@@ -58,3 +28,3 @@ componentWillUnmount(): void; | ||
randomId: () => string; | ||
getContextName(): never[]; | ||
getContextName(): string[]; | ||
getContextModel(): import("./types").DeepPartial<Model>; | ||
@@ -67,7 +37,6 @@ getContextState(): { | ||
}; | ||
getContextSchema(): State["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getContextSchema(): import("./Bridge").Bridge; | ||
getContextOnChange(): (key: string, value?: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => any; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: import("./types").DeepPartial<Model>): import("./types").DeepPartial<Model>; | ||
getChangedKeys<T>(root: string, valueA?: T | undefined, valueB?: T | undefined): string[]; | ||
onReset(): void; | ||
@@ -95,123 +64,21 @@ render(): JSX.Element; | ||
}; | ||
Validated: <Base extends typeof BaseForm>(base: Base) => { | ||
new <Model_1 extends {} = Record<string, any>, Props_1 extends ValidatedFormProps<Model_1> = ValidatedFormProps<Model_1>, State_1 extends ValidatedFormState<Model_1> = ValidatedFormState<Model_1>>(props: Props_1): { | ||
validate: (key?: string | undefined, value?: any) => Promise<unknown>; | ||
validateModel: (model: any) => Promise<unknown>; | ||
getContextError(): State_1["error"]; | ||
getContext(): { | ||
validating: State_1["validating"]; | ||
changed: boolean; | ||
changedMap: { | ||
[x: string]: Record<string, void> | { | ||
[x: string]: Record<string, void> | any | undefined; | ||
} | undefined; | ||
}; | ||
error: any; | ||
model: import("./types").DeepPartial<Record<string, any>>; | ||
name: string[]; | ||
onChange(key: string, value?: any): void; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): any; | ||
randomId(): string; | ||
schema: import("./Bridge").default; | ||
state: { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
submitting: boolean; | ||
}; | ||
getNativeFormProps(): Record<string, any>; | ||
componentDidUpdate(prevProps: Props_1, prevState: State_1, snapshot: never): void; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State_1): { | ||
error: null; | ||
validate: boolean; | ||
validating: boolean; | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
onValidate(key?: string | undefined, value?: any): Promise<unknown>; | ||
onValidateModel(model: Props_1["model"]): Promise<unknown>; | ||
componentDidMount(): void; | ||
componentWillUnmount(): void; | ||
delayId?: any; | ||
mounted: boolean; | ||
reset: () => void; | ||
change: (key: string, value: any) => void; | ||
submit: (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<any>; | ||
randomId: () => string; | ||
getContextName(): never[]; | ||
getContextModel(): import("./types").DeepPartial<Model_1>; | ||
getContextState(): { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
getContextSchema(): State_1["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: import("./types").DeepPartial<Model_1>): import("./types").DeepPartial<Model_1>; | ||
getChangedKeys<T_1>(root: string, valueA?: T_1 | undefined, valueB?: T_1 | undefined): string[]; | ||
onReset(): void; | ||
render(): JSX.Element; | ||
context: any; | ||
setState<K_1 extends keyof State_1>(state: State_1 | ((prevState: Readonly<State_1>, props: Readonly<Props_1>) => State_1 | Pick<State_1, K_1> | null) | Pick<State_1, K_1> | null, callback?: (() => void) | undefined): void; | ||
forceUpdate(callback?: (() => void) | undefined): void; | ||
readonly props: Readonly<Props_1> & Readonly<{ | ||
children?: import("react").ReactNode; | ||
}>; | ||
state: Readonly<State_1>; | ||
refs: { | ||
[key: string]: import("react").ReactInstance; | ||
}; | ||
shouldComponentUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): boolean; | ||
componentDidCatch?(error: Error, errorInfo: import("react").ErrorInfo): void; | ||
getSnapshotBeforeUpdate?(prevProps: Readonly<Props_1>, prevState: Readonly<State_1>): any; | ||
componentWillMount?(): void; | ||
UNSAFE_componentWillMount?(): void; | ||
componentWillReceiveProps?(nextProps: Readonly<Props_1>, nextContext: any): void; | ||
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<Props_1>, nextContext: any): void; | ||
componentWillUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): void; | ||
UNSAFE_componentWillUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): void; | ||
}; | ||
Validated: any; | ||
displayName: string; | ||
defaultProps: { | ||
onValidate(model: any, error: any, callback: any): void; | ||
validate: string; | ||
autosave: boolean; | ||
autosaveDelay: number; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
}; | ||
getDerivedStateFromProps({ schema }: import("./BaseForm").BaseFormProps<any>, { bridge }: import("./BaseForm").BaseFormState<any>): { | ||
bridge: import("./Bridge").default; | ||
}; | ||
contextType?: import("react").Context<any> | undefined; | ||
} & Base; | ||
Validated: typeof Validated; | ||
displayName: string; | ||
defaultProps: { | ||
onValidate(model: any, error: any, callback: any): void; | ||
onValidate(model: any, error: any): any; | ||
validate: string; | ||
autosave: boolean; | ||
autosaveDelay: number; | ||
error: null; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
onSubmit(): void; | ||
}; | ||
getDerivedStateFromProps({ schema }: import("./BaseForm").BaseFormProps<any>, { bridge }: import("./BaseForm").BaseFormState<any>): { | ||
bridge: import("./Bridge").default; | ||
}; | ||
contextType?: import("react").Context<any> | undefined; | ||
} & { | ||
new <Model_2 extends {} = Record<string, any>, Props_2 extends QuickFormProps<Model_2> = QuickFormProps<Model_2>, State_2 extends import("./BaseForm").BaseFormState<Model_2> = import("./BaseForm").BaseFormState<Model_2>>(props: Props_2): { | ||
new <Model_1, Props_1 extends QuickFormProps<Model_1> = QuickFormProps<Model_1>, State_1 extends import("./BaseForm").BaseFormState<Model_1> = import("./BaseForm").BaseFormState<Model_1>>(props: Props_1): { | ||
getNativeFormProps(): Record<string, any>; | ||
getAutoField(): import("react").ComponentType<{ | ||
name?: string | undefined; | ||
name: string; | ||
}>; | ||
@@ -221,3 +88,3 @@ getErrorsField(): import("react").ComponentType<{}>; | ||
componentDidMount(): void; | ||
componentDidUpdate(prevProps: any, prevState: any, snapshot: any): void; | ||
componentDidUpdate(prevProps: Props_1, prevState: State_1, snapshot: never): void; | ||
componentWillUnmount(): void; | ||
@@ -230,6 +97,6 @@ delayId?: any; | ||
randomId: () => string; | ||
getContext(): import("./types").Context<Record<string, any>>; | ||
getContextName(): never[]; | ||
getContextError(): Props_2["error"]; | ||
getContextModel(): import("./types").DeepPartial<Model_2>; | ||
getContext(): import("./types").Context<Model_1>; | ||
getContextName(): string[]; | ||
getContextError(): any; | ||
getContextModel(): import("./types").DeepPartial<Model_1>; | ||
getContextState(): { | ||
@@ -241,113 +108,32 @@ disabled: boolean; | ||
}; | ||
getContextSchema(): State_2["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: import("./types").DeepPartial<Model_2>): import("./types").DeepPartial<Model_2>; | ||
getChangedKeys<T_2>(root: string, valueA?: T_2 | undefined, valueB?: T_2 | undefined): string[]; | ||
getContextSchema(): import("./Bridge").Bridge; | ||
getContextOnChange(): (key: string, value?: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => any; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: import("./types").DeepPartial<Model_1>): import("./types").DeepPartial<Model_1>; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State_2): { | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
__reset(state: State_1): Partial<State_1>; | ||
onReset(): void; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<any>; | ||
render(): JSX.Element; | ||
context: any; | ||
setState<K_2 extends keyof State_2>(state: State_2 | ((prevState: Readonly<State_2>, props: Readonly<Props_2>) => State_2 | Pick<State_2, K_2> | null) | Pick<State_2, K_2> | null, callback?: (() => void) | undefined): void; | ||
setState<K_1 extends keyof State_1>(state: State_1 | ((prevState: Readonly<State_1>, props: Readonly<Props_1>) => State_1 | Pick<State_1, K_1> | null) | Pick<State_1, K_1> | null, callback?: (() => void) | undefined): void; | ||
forceUpdate(callback?: (() => void) | undefined): void; | ||
readonly props: Readonly<Props_2> & Readonly<{ | ||
readonly props: Readonly<Props_1> & Readonly<{ | ||
children?: import("react").ReactNode; | ||
}>; | ||
state: Readonly<State_2>; | ||
state: Readonly<State_1>; | ||
refs: { | ||
[key: string]: import("react").ReactInstance; | ||
}; | ||
shouldComponentUpdate?(nextProps: Readonly<Props_2>, nextState: Readonly<State_2>, nextContext: any): boolean; | ||
shouldComponentUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): boolean; | ||
componentDidCatch?(error: Error, errorInfo: import("react").ErrorInfo): void; | ||
getSnapshotBeforeUpdate?(prevProps: Readonly<Props_2>, prevState: Readonly<State_2>): any; | ||
getSnapshotBeforeUpdate?(prevProps: Readonly<Props_1>, prevState: Readonly<State_1>): any; | ||
componentWillMount?(): void; | ||
UNSAFE_componentWillMount?(): void; | ||
componentWillReceiveProps?(nextProps: Readonly<Props_2>, nextContext: any): void; | ||
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<Props_2>, nextContext: any): void; | ||
componentWillUpdate?(nextProps: Readonly<Props_2>, nextState: Readonly<State_2>, nextContext: any): void; | ||
UNSAFE_componentWillUpdate?(nextProps: Readonly<Props_2>, nextState: Readonly<State_2>, nextContext: any): void; | ||
componentWillReceiveProps?(nextProps: Readonly<Props_1>, nextContext: any): void; | ||
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<Props_1>, nextContext: any): void; | ||
componentWillUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): void; | ||
UNSAFE_componentWillUpdate?(nextProps: Readonly<Props_1>, nextState: Readonly<State_1>, nextContext: any): void; | ||
}; | ||
Quick: <Base_1 extends typeof BaseForm>(base: Base_1) => { | ||
new <Model_3 extends {} = Record<string, any>, Props_3 extends QuickFormProps<Model_3> = QuickFormProps<Model_3>, State_3 extends import("./BaseForm").BaseFormState<Model_3> = import("./BaseForm").BaseFormState<Model_3>>(props: Props_3): { | ||
getNativeFormProps(): Record<string, any>; | ||
getAutoField(): import("react").ComponentType<{ | ||
name?: string | undefined; | ||
}>; | ||
getErrorsField(): import("react").ComponentType<{}>; | ||
getSubmitField(): import("react").ComponentType<{}>; | ||
componentDidMount(): void; | ||
componentDidUpdate(prevProps: any, prevState: any, snapshot: any): void; | ||
componentWillUnmount(): void; | ||
delayId?: any; | ||
mounted: boolean; | ||
reset: () => void; | ||
change: (key: string, value: any) => void; | ||
submit: (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<any>; | ||
randomId: () => string; | ||
getContext(): import("./types").Context<Record<string, any>>; | ||
getContextName(): never[]; | ||
getContextError(): Props_3["error"]; | ||
getContextModel(): import("./types").DeepPartial<Model_3>; | ||
getContextState(): { | ||
disabled: boolean; | ||
label: boolean; | ||
placeholder: boolean; | ||
showInlineError: boolean; | ||
}; | ||
getContextSchema(): State_3["bridge"]; | ||
getContextOnChange(): (key: string, value: any) => void; | ||
getContextOnSubmit(): (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<void>; | ||
getModel(mode?: "form" | "submit" | "validate" | undefined, model?: import("./types").DeepPartial<Model_3>): import("./types").DeepPartial<Model_3>; | ||
getChangedKeys<T_3>(root: string, valueA?: T_3 | undefined, valueB?: T_3 | undefined): string[]; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State_3): { | ||
changed: boolean; | ||
changedMap: any; | ||
submitting: boolean; | ||
resetCount: number; | ||
}; | ||
onReset(): void; | ||
onSubmit(event?: import("react").SyntheticEvent<Element, Event> | undefined): Promise<void>; | ||
render(): JSX.Element; | ||
context: any; | ||
setState<K_3 extends keyof State_3>(state: State_3 | ((prevState: Readonly<State_3>, props: Readonly<Props_3>) => State_3 | Pick<State_3, K_3> | null) | Pick<State_3, K_3> | null, callback?: (() => void) | undefined): void; | ||
forceUpdate(callback?: (() => void) | undefined): void; | ||
readonly props: Readonly<Props_3> & Readonly<{ | ||
children?: import("react").ReactNode; | ||
}>; | ||
state: Readonly<State_3>; | ||
refs: { | ||
[key: string]: import("react").ReactInstance; | ||
}; | ||
shouldComponentUpdate?(nextProps: Readonly<Props_3>, nextState: Readonly<State_3>, nextContext: any): boolean; | ||
componentDidCatch?(error: Error, errorInfo: import("react").ErrorInfo): void; | ||
getSnapshotBeforeUpdate?(prevProps: Readonly<Props_3>, prevState: Readonly<State_3>): any; | ||
componentWillMount?(): void; | ||
UNSAFE_componentWillMount?(): void; | ||
componentWillReceiveProps?(nextProps: Readonly<Props_3>, nextContext: any): void; | ||
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<Props_3>, nextContext: any): void; | ||
componentWillUpdate?(nextProps: Readonly<Props_3>, nextState: Readonly<State_3>, nextContext: any): void; | ||
UNSAFE_componentWillUpdate?(nextProps: Readonly<Props_3>, nextState: Readonly<State_3>, nextContext: any): void; | ||
}; | ||
Quick: any; | ||
displayName: string; | ||
defaultProps: { | ||
autosave: boolean; | ||
autosaveDelay: number; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
}; | ||
getDerivedStateFromProps({ schema }: import("./BaseForm").BaseFormProps<any>, { bridge }: import("./BaseForm").BaseFormState<any>): { | ||
bridge: import("./Bridge").default; | ||
}; | ||
contextType?: import("react").Context<any> | undefined; | ||
} & Base_1; | ||
Quick: typeof Quick; | ||
displayName: string; | ||
@@ -357,11 +143,10 @@ defaultProps: { | ||
autosaveDelay: number; | ||
error: null; | ||
label: boolean; | ||
model: any; | ||
noValidate: boolean; | ||
onSubmit(): void; | ||
}; | ||
getDerivedStateFromProps({ schema }: import("./BaseForm").BaseFormProps<any>, { bridge }: import("./BaseForm").BaseFormState<any>): { | ||
bridge: import("./Bridge").default; | ||
}; | ||
contextType?: import("react").Context<any> | undefined; | ||
} & typeof BaseForm; | ||
export default _default; | ||
export declare type ValidatedQuickForm = typeof ValidatedQuickForm; |
@@ -1,4 +0,4 @@ | ||
import BaseForm from './BaseForm'; | ||
import QuickForm from './QuickForm'; | ||
import ValidatedForm from './ValidatedForm'; | ||
export default ValidatedForm.Validated(QuickForm.Quick(BaseForm)); | ||
import { BaseForm } from './BaseForm'; | ||
import { Quick } from './QuickForm'; | ||
import { Validated, } from './ValidatedForm'; | ||
export const ValidatedQuickForm = Validated(Quick(BaseForm)); |
{ | ||
"name": "uniforms", | ||
"version": "3.0.0-alpha.2", | ||
"version": "3.0.0-alpha.3", | ||
"license": "MIT", | ||
@@ -35,3 +35,3 @@ "main": "es5/index.js", | ||
}, | ||
"gitHead": "a828a69acbfb54f1676e2340c4cea08aa0c41d19" | ||
"gitHead": "032f300a30be7dbf54d8e53231fd85db03dd0cf8" | ||
} |
import invariant from 'invariant'; | ||
export default abstract class Bridge { | ||
export abstract class Bridge { | ||
constructor(...args: any[]) { | ||
@@ -12,11 +12,2 @@ invariant( | ||
static check(schema: any): boolean { | ||
return invariant( | ||
false, | ||
'%s have not implemented `check` method (args=%o).', | ||
this.name, | ||
{ schema }, | ||
); | ||
} | ||
getError(name: string, error: any): any { | ||
@@ -94,3 +85,3 @@ return invariant( | ||
getValidator(options?: any): (model: Record<string, any>) => void { | ||
getValidator(options?: any): (model: Record<string, any>) => any { | ||
return invariant( | ||
@@ -97,0 +88,0 @@ false, |
import isEqual from 'lodash/isEqual'; | ||
import xorWith from 'lodash/xorWith'; | ||
import joinName from './joinName'; | ||
import { joinName } from './joinName'; | ||
export default function changedKeys<T>(root: string, valueA?: T, valueB?: T) { | ||
export function changedKeys<T>(root: string, valueA?: T, valueB?: T) { | ||
if (!valueA || valueA !== Object(valueA) || valueA instanceof Date) | ||
@@ -8,0 +8,0 @@ return isEqual(valueA, valueB) ? [] : [root]; |
@@ -5,2 +5,2 @@ import { createContext } from 'react'; | ||
export default createContext<Context | null>(null); | ||
export const context = createContext<Context<any> | null>(null); |
@@ -1,8 +0,8 @@ | ||
import omit from 'lodash/omit'; | ||
import pickBy from 'lodash/pickBy'; | ||
import sortedIndex from 'lodash/sortedIndex'; | ||
import sortedIndexOf from 'lodash/sortedIndexOf'; | ||
const registered = [ | ||
// These props are provided by BaseField | ||
// These props are provided by useField directly. | ||
'changed', | ||
'changedMap', | ||
'disabled', | ||
'error', | ||
@@ -13,30 +13,33 @@ 'errorMessage', | ||
'fields', | ||
'findError', | ||
'findField', | ||
'findValue', | ||
'initialCount', | ||
'label', | ||
'name', | ||
'onChange', | ||
'parent', | ||
'placeholder', | ||
'showInlineError', | ||
'submitting', | ||
'transform', | ||
'validating', | ||
'value', | ||
// These are used by AutoField | ||
'allowedValues', | ||
// These props are provided by useField through context.state. | ||
'disabled', | ||
'label', | ||
'placeholder', | ||
'showInlineError', | ||
// This is used by AutoField. | ||
'component', | ||
]; | ||
function filter<T extends {}>(props: T) { | ||
return omit(props, registered); | ||
// These is used by AutoField and bridges. | ||
'allowedValues', | ||
].sort(); | ||
function filter<T extends object>(props: T) { | ||
return pickBy(props, filterOne); | ||
} | ||
function filterOne(value: unknown, prop: string) { | ||
return sortedIndexOf(registered, prop) === -1; | ||
} | ||
function register(...props: string[]) { | ||
props.forEach(prop => { | ||
if (!registered.includes(prop)) { | ||
registered.push(prop); | ||
if (sortedIndexOf(registered, prop) === -1) { | ||
registered.splice(sortedIndex(registered, prop), 0, prop); | ||
} | ||
@@ -46,2 +49,5 @@ }); | ||
export default Object.assign(filter, { register, registered }); | ||
export const filterDOMProps = Object.assign(filter, { | ||
register, | ||
registered: registered as readonly string[], | ||
}); |
@@ -0,17 +1,16 @@ | ||
export * from './AutoForm'; | ||
export * from './BaseForm'; | ||
export * from './Bridge'; | ||
export * from './QuickForm'; | ||
export * from './ValidatedForm'; | ||
export * from './ValidatedQuickForm'; | ||
export * from './changedKeys'; | ||
export * from './connectField'; | ||
export * from './context'; | ||
export * from './filterDOMProps'; | ||
export * from './injectName'; | ||
export * from './joinName'; | ||
export * from './randomIds'; | ||
export * from './types'; | ||
export { default as AutoForm } from './AutoForm'; | ||
export { default as BaseForm } from './BaseForm'; | ||
export { default as Bridge } from './Bridge'; | ||
export { default as QuickForm } from './QuickForm'; | ||
export { default as ValidatedForm } from './ValidatedForm'; | ||
export { default as ValidatedQuickForm } from './ValidatedQuickForm'; | ||
export { default as changedKeys } from './changedKeys'; | ||
export { default as connectField } from './connectField'; | ||
export { default as context } from './context'; | ||
export { default as createSchemaBridge } from './createSchemaBridge'; | ||
export { default as filterDOMProps } from './filterDOMProps'; | ||
export { default as injectName } from './injectName'; | ||
export { default as joinName } from './joinName'; | ||
export { default as randomIds } from './randomIds'; | ||
export { default as useField } from './useField'; | ||
export { default as useForm } from './useForm'; | ||
export * from './useField'; | ||
export * from './useForm'; |
import get from 'lodash/get'; | ||
import { Children, ReactElement, ReactNode, cloneElement } from 'react'; | ||
import joinName from './joinName'; | ||
import { joinName } from './joinName'; | ||
export default function injectName( | ||
export function injectName( | ||
name: string, | ||
@@ -8,0 +8,0 @@ children: ReactNode, |
@@ -1,4 +0,4 @@ | ||
function joinName(flag: null, ...parts: unknown[]): string[]; | ||
function joinName(...parts: unknown[]): string; | ||
function joinName(...parts: unknown[]) { | ||
export function joinName(flag: null, ...parts: unknown[]): string[]; | ||
export function joinName(...parts: unknown[]): string; | ||
export function joinName(...parts: unknown[]) { | ||
const name = parts.reduce( | ||
@@ -14,3 +14,1 @@ (parts: unknown[], part: unknown) => | ||
} | ||
export default joinName; |
@@ -12,4 +12,4 @@ // Workaround for SSR | ||
export default function randomIds(prefix = randomIdPrefix()) { | ||
export function randomIds(prefix = randomIdPrefix()) { | ||
return randomIdsGenerator(prefix); | ||
} |
import { SyntheticEvent } from 'react'; | ||
import Bridge from './Bridge'; | ||
import { Bridge } from './Bridge'; | ||
@@ -9,3 +9,3 @@ export type ChangedMap<T> = T extends {} | ||
export type Context<Model extends {} = Record<string, any>> = { | ||
export type Context<Model> = { | ||
changed: boolean; | ||
@@ -53,6 +53,6 @@ changedMap: ChangedMap<Model>; | ||
export type Override<T, U> = U & Omit<T, keyof U>; | ||
export type Partialize<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>; | ||
export type ValidateMode = 'onChange' | 'onChangeAfterSubmit' | 'onSubmit'; | ||
export type Override<T, U> = U & Omit<T, keyof U>; |
import invariant from 'invariant'; | ||
import { useContext } from 'react'; | ||
import contextReference from './context'; | ||
import { Context } from './types'; | ||
import { context as contextReference } from './context'; | ||
export default function useForm<Model extends {}>() { | ||
const context = useContext(contextReference) as Context<Model>; | ||
export function useForm<Model>(): Context<Model> { | ||
const context = useContext(contextReference); | ||
invariant(context !== null, 'useForm must be used within a form.'); | ||
return context; | ||
} |
@@ -1,4 +0,5 @@ | ||
import BaseForm from './BaseForm'; | ||
import QuickForm, { QuickFormProps, QuickFormState } from './QuickForm'; | ||
import ValidatedForm, { | ||
import { BaseForm } from './BaseForm'; | ||
import { Quick, QuickFormProps, QuickFormState } from './QuickForm'; | ||
import { | ||
Validated, | ||
ValidatedFormProps, | ||
@@ -14,2 +15,3 @@ ValidatedFormState, | ||
export default ValidatedForm.Validated(QuickForm.Quick(BaseForm)); | ||
export const ValidatedQuickForm = Validated(Quick(BaseForm)); | ||
export type ValidatedQuickForm = typeof ValidatedQuickForm; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
181186
92
4210