Comparing version 4.0.0-alpha.5 to 4.0.0-alpha.6
@@ -14,7 +14,15 @@ /// <reference types="react" /> | ||
new <Model extends UnknownObject, Props extends AutoFormProps<Model> = AutoFormProps<Model>, State extends AutoFormState<Model> = AutoFormState<Model>>(props: Props): { | ||
/** | ||
* Returns model value based on the `schema` model and `props.model`. | ||
* Latter one takes precedence. Does shallow copy. | ||
*/ | ||
mergeSchemaAndPropsModel(schema: Props["schema"], model: Props["model"]): Props["model"]; | ||
componentDidUpdate(prevProps: Props, prevState: State, snapshot: never): void; | ||
getNativeFormProps(): { | ||
[key: string]: unknown; | ||
children?: import("react").ReactNode; | ||
id?: string | undefined; | ||
key: string; | ||
noValidate: boolean; | ||
onSubmit: (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<unknown>; | ||
key: string; | ||
}; | ||
@@ -96,7 +104,15 @@ getModel(mode: ModelTransformMode): State["model"]; | ||
new <Model extends UnknownObject, Props extends AutoFormProps<Model> = AutoFormProps<Model>, State extends AutoFormState<Model> = AutoFormState<Model>>(props: Props): { | ||
/** | ||
* Returns model value based on the `schema` model and `props.model`. | ||
* Latter one takes precedence. Does shallow copy. | ||
*/ | ||
mergeSchemaAndPropsModel(schema: Props["schema"], model: Props["model"]): Props["model"]; | ||
componentDidUpdate(prevProps: Props, prevState: State, snapshot: never): void; | ||
getNativeFormProps(): { | ||
[key: string]: unknown; | ||
children?: import("react").ReactNode; | ||
id?: string | undefined; | ||
key: string; | ||
noValidate: boolean; | ||
onSubmit: (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<unknown>; | ||
key: string; | ||
}; | ||
@@ -183,4 +199,7 @@ getModel(mode: ModelTransformMode): State["model"]; | ||
[key: string]: unknown; | ||
children?: import("react").ReactNode; | ||
id?: string | undefined; | ||
key: string; | ||
noValidate: boolean; | ||
onSubmit: (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<unknown>; | ||
key: string; | ||
}; | ||
@@ -251,4 +270,7 @@ componentDidUpdate(prevProps: Props_1, prevState: State_1, snapshot: never): void; | ||
[key: string]: unknown; | ||
children?: import("react").ReactNode; | ||
id?: string | undefined; | ||
key: string; | ||
noValidate: boolean; | ||
onSubmit: (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<unknown>; | ||
key: string; | ||
}; | ||
@@ -255,0 +277,0 @@ getAutoField(): import("react").ComponentType<{ |
@@ -15,8 +15,16 @@ "use strict"; | ||
super(props); | ||
this.state = Object.assign(Object.assign({}, this.state), { model: props.model }); | ||
this.state = Object.assign(Object.assign({}, this.state), { model: this.mergeSchemaAndPropsModel(this.props.schema, this.props.model) }); | ||
} | ||
/** | ||
* Returns model value based on the `schema` model and `props.model`. | ||
* Latter one takes precedence. Does shallow copy. | ||
*/ | ||
mergeSchemaAndPropsModel(schema, model) { | ||
const initialModel = schema.getInitialModel(); | ||
return Object.assign(initialModel, model); | ||
} | ||
componentDidUpdate(prevProps, prevState, snapshot) { | ||
const { model } = this.props; | ||
const { model, schema } = this.props; | ||
if (!(0, isEqual_1.default)(model, prevProps.model)) { | ||
this.setState({ model }); | ||
this.setState({ model: this.mergeSchemaAndPropsModel(schema, model) }); | ||
} | ||
@@ -23,0 +31,0 @@ super.componentDidUpdate(prevProps, prevState, snapshot); |
@@ -1,2 +0,2 @@ | ||
import { Component, SyntheticEvent } from 'react'; | ||
import React, { Component, SyntheticEvent } from 'react'; | ||
import { Bridge } from './Bridge'; | ||
@@ -15,3 +15,2 @@ import { ChangedMap, Context, ModelTransformMode, UnknownObject } from './types'; | ||
onSubmit: (model: Model) => void | Promise<unknown>; | ||
placeholder?: boolean; | ||
readOnly?: boolean; | ||
@@ -59,4 +58,7 @@ schema: Bridge; | ||
[key: string]: unknown; | ||
children?: React.ReactNode; | ||
id?: BaseFormProps<Model>['id']; | ||
key: string; | ||
noValidate: BaseFormProps<Model>['noValidate']; | ||
onSubmit: BaseForm<Model, Props, State>['onSubmit']; | ||
key: string; | ||
}; | ||
@@ -63,0 +65,0 @@ onChange(key: string, value: unknown): void; |
@@ -45,9 +45,2 @@ "use strict"; | ||
} | ||
// There are at least 4 places where we'd need to check, whether or not we | ||
// actually perform `setState` after the component gets unmounted. Instead, | ||
// we override it to hide the React warning. Also because React no longer | ||
// will raise it in the newer versions. | ||
// https://github.com/facebook/react/pull/22114 | ||
// https://github.com/vazco/uniforms/issues/1152 | ||
this.setState = () => { }; | ||
} | ||
@@ -150,5 +143,7 @@ getContext() { | ||
// for AutoForm to validate correct model, waiting in `onChange`. | ||
this.setState(() => null, () => { | ||
this.onSubmit(); | ||
}); | ||
if (this.mounted) { | ||
this.setState(() => null, () => { | ||
this.onSubmit(); | ||
}); | ||
} | ||
}, this.props.autosaveDelay); | ||
@@ -167,6 +162,8 @@ } | ||
onReset() { | ||
// @ts-expect-error | ||
// It's bound in constructor. | ||
// eslint-disable-next-line @typescript-eslint/unbound-method | ||
this.setState(this.__reset); | ||
if (this.mounted) { | ||
// @ts-expect-error | ||
// It's bound in constructor. | ||
// eslint-disable-next-line @typescript-eslint/unbound-method | ||
this.setState(this.__reset); | ||
} | ||
} | ||
@@ -178,3 +175,5 @@ onSubmit(event) { | ||
} | ||
this.setState(state => (state.submitted ? null : { submitted: true })); | ||
if (this.mounted) { | ||
this.setState(state => (state.submitted ? null : { submitted: true })); | ||
} | ||
const result = this.props.onSubmit(this.getModel('submit')); | ||
@@ -184,5 +183,9 @@ if (!(result instanceof Promise)) { | ||
} | ||
this.setState({ submitting: true }); | ||
if (this.mounted) { | ||
this.setState({ submitting: true }); | ||
} | ||
return result.finally(() => { | ||
this.setState({ submitting: false }); | ||
if (this.mounted) { | ||
this.setState({ submitting: false }); | ||
} | ||
}); | ||
@@ -189,0 +192,0 @@ } |
@@ -37,2 +37,6 @@ import { UnknownObject } from './types'; | ||
/** | ||
* Get initial model value recursively. | ||
*/ | ||
getInitialModel(): UnknownObject; | ||
/** | ||
* Get props defined in schema for a field `name`. There are no required nor | ||
@@ -39,0 +43,0 @@ * banned fields, however properties like `required` are often available. |
@@ -6,2 +6,3 @@ "use strict"; | ||
const invariant_1 = (0, tslib_1.__importDefault)(require("invariant")); | ||
const set_1 = (0, tslib_1.__importDefault)(require("lodash/set")); | ||
class Bridge { | ||
@@ -55,2 +56,14 @@ // Each bridge can have a different set of parameters. | ||
/** | ||
* Get initial model value recursively. | ||
*/ | ||
getInitialModel() { | ||
const initialModel = {}; | ||
const subFields = this.getSubfields(); | ||
for (const fieldName of subFields) { | ||
const initialValue = this.getInitialValue(fieldName); | ||
(0, set_1.default)(initialModel, fieldName, initialValue); | ||
} | ||
return initialModel; | ||
} | ||
/** | ||
* Get props defined in schema for a field `name`. There are no required nor | ||
@@ -57,0 +70,0 @@ * banned fields, however properties like `required` are often available. |
@@ -14,4 +14,7 @@ /// <reference types="node" /> | ||
[key: string]: unknown; | ||
children?: React.ReactNode; | ||
id?: string | undefined; | ||
key: string; | ||
noValidate: boolean; | ||
onSubmit: (event?: React.SyntheticEvent<Element, Event> | undefined) => Promise<unknown>; | ||
key: string; | ||
}; | ||
@@ -86,4 +89,7 @@ getAutoField(): ComponentType<{ | ||
[key: string]: unknown; | ||
children?: React.ReactNode; | ||
id?: string | undefined; | ||
key: string; | ||
noValidate: boolean; | ||
onSubmit: (event?: React.SyntheticEvent<Element, Event> | undefined) => Promise<unknown>; | ||
key: string; | ||
}; | ||
@@ -90,0 +96,0 @@ getAutoField(): React.ComponentType<{ |
@@ -53,5 +53,3 @@ "use strict"; | ||
(0, react_1.useEffect)(() => { | ||
var _a; | ||
const required = (_a = props.required) !== null && _a !== void 0 ? _a : schemaProps.required; | ||
if (required && initialValue !== undefined) { | ||
if (initialValue !== undefined) { | ||
onChange(initialValue); | ||
@@ -58,0 +56,0 @@ } |
@@ -24,4 +24,7 @@ /// <reference types="node" /> | ||
[key: string]: unknown; | ||
children?: import("react").ReactNode; | ||
id?: string | undefined; | ||
key: string; | ||
noValidate: boolean; | ||
onSubmit: (event?: SyntheticEvent<Element, Event> | undefined) => Promise<unknown>; | ||
key: string; | ||
}; | ||
@@ -97,4 +100,7 @@ componentDidUpdate(prevProps: Props, prevState: State, snapshot: never): void; | ||
[key: string]: unknown; | ||
children?: import("react").ReactNode; | ||
id?: string | undefined; | ||
key: string; | ||
noValidate: boolean; | ||
onSubmit: (event?: SyntheticEvent<Element, Event> | undefined) => Promise<unknown>; | ||
key: string; | ||
}; | ||
@@ -101,0 +107,0 @@ componentDidUpdate(prevProps: Props, prevState: State, snapshot: never): void; |
@@ -17,4 +17,7 @@ /// <reference types="react" /> | ||
[key: string]: unknown; | ||
children?: import("react").ReactNode; | ||
id?: string | undefined; | ||
key: string; | ||
noValidate: boolean; | ||
onSubmit: (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<unknown>; | ||
key: string; | ||
}; | ||
@@ -85,4 +88,7 @@ componentDidUpdate(prevProps: Props, prevState: State, snapshot: never): void; | ||
[key: string]: unknown; | ||
children?: import("react").ReactNode; | ||
id?: string | undefined; | ||
key: string; | ||
noValidate: boolean; | ||
onSubmit: (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<unknown>; | ||
key: string; | ||
}; | ||
@@ -89,0 +95,0 @@ getAutoField(): import("react").ComponentType<{ |
@@ -14,7 +14,15 @@ /// <reference types="react" /> | ||
new <Model extends UnknownObject, Props extends AutoFormProps<Model> = AutoFormProps<Model>, State extends AutoFormState<Model> = AutoFormState<Model>>(props: Props): { | ||
/** | ||
* Returns model value based on the `schema` model and `props.model`. | ||
* Latter one takes precedence. Does shallow copy. | ||
*/ | ||
mergeSchemaAndPropsModel(schema: Props["schema"], model: Props["model"]): Props["model"]; | ||
componentDidUpdate(prevProps: Props, prevState: State, snapshot: never): void; | ||
getNativeFormProps(): { | ||
[key: string]: unknown; | ||
children?: import("react").ReactNode; | ||
id?: string | undefined; | ||
key: string; | ||
noValidate: boolean; | ||
onSubmit: (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<unknown>; | ||
key: string; | ||
}; | ||
@@ -96,7 +104,15 @@ getModel(mode: ModelTransformMode): State["model"]; | ||
new <Model extends UnknownObject, Props extends AutoFormProps<Model> = AutoFormProps<Model>, State extends AutoFormState<Model> = AutoFormState<Model>>(props: Props): { | ||
/** | ||
* Returns model value based on the `schema` model and `props.model`. | ||
* Latter one takes precedence. Does shallow copy. | ||
*/ | ||
mergeSchemaAndPropsModel(schema: Props["schema"], model: Props["model"]): Props["model"]; | ||
componentDidUpdate(prevProps: Props, prevState: State, snapshot: never): void; | ||
getNativeFormProps(): { | ||
[key: string]: unknown; | ||
children?: import("react").ReactNode; | ||
id?: string | undefined; | ||
key: string; | ||
noValidate: boolean; | ||
onSubmit: (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<unknown>; | ||
key: string; | ||
}; | ||
@@ -183,4 +199,7 @@ getModel(mode: ModelTransformMode): State["model"]; | ||
[key: string]: unknown; | ||
children?: import("react").ReactNode; | ||
id?: string | undefined; | ||
key: string; | ||
noValidate: boolean; | ||
onSubmit: (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<unknown>; | ||
key: string; | ||
}; | ||
@@ -251,4 +270,7 @@ componentDidUpdate(prevProps: Props_1, prevState: State_1, snapshot: never): void; | ||
[key: string]: unknown; | ||
children?: import("react").ReactNode; | ||
id?: string | undefined; | ||
key: string; | ||
noValidate: boolean; | ||
onSubmit: (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<unknown>; | ||
key: string; | ||
}; | ||
@@ -255,0 +277,0 @@ getAutoField(): import("react").ComponentType<{ |
@@ -11,8 +11,16 @@ import clone from 'lodash/clone'; | ||
super(props); | ||
this.state = Object.assign(Object.assign({}, this.state), { model: props.model }); | ||
this.state = Object.assign(Object.assign({}, this.state), { model: this.mergeSchemaAndPropsModel(this.props.schema, this.props.model) }); | ||
} | ||
/** | ||
* Returns model value based on the `schema` model and `props.model`. | ||
* Latter one takes precedence. Does shallow copy. | ||
*/ | ||
mergeSchemaAndPropsModel(schema, model) { | ||
const initialModel = schema.getInitialModel(); | ||
return Object.assign(initialModel, model); | ||
} | ||
componentDidUpdate(prevProps, prevState, snapshot) { | ||
const { model } = this.props; | ||
const { model, schema } = this.props; | ||
if (!isEqual(model, prevProps.model)) { | ||
this.setState({ model }); | ||
this.setState({ model: this.mergeSchemaAndPropsModel(schema, model) }); | ||
} | ||
@@ -19,0 +27,0 @@ super.componentDidUpdate(prevProps, prevState, snapshot); |
@@ -1,2 +0,2 @@ | ||
import { Component, SyntheticEvent } from 'react'; | ||
import React, { Component, SyntheticEvent } from 'react'; | ||
import { Bridge } from './Bridge'; | ||
@@ -15,3 +15,2 @@ import { ChangedMap, Context, ModelTransformMode, UnknownObject } from './types'; | ||
onSubmit: (model: Model) => void | Promise<unknown>; | ||
placeholder?: boolean; | ||
readOnly?: boolean; | ||
@@ -59,4 +58,7 @@ schema: Bridge; | ||
[key: string]: unknown; | ||
children?: React.ReactNode; | ||
id?: BaseFormProps<Model>['id']; | ||
key: string; | ||
noValidate: BaseFormProps<Model>['noValidate']; | ||
onSubmit: BaseForm<Model, Props, State>['onSubmit']; | ||
key: string; | ||
}; | ||
@@ -63,0 +65,0 @@ onChange(key: string, value: unknown): void; |
@@ -41,9 +41,2 @@ import clone from 'lodash/clone'; | ||
} | ||
// There are at least 4 places where we'd need to check, whether or not we | ||
// actually perform `setState` after the component gets unmounted. Instead, | ||
// we override it to hide the React warning. Also because React no longer | ||
// will raise it in the newer versions. | ||
// https://github.com/facebook/react/pull/22114 | ||
// https://github.com/vazco/uniforms/issues/1152 | ||
this.setState = () => { }; | ||
} | ||
@@ -146,5 +139,7 @@ getContext() { | ||
// for AutoForm to validate correct model, waiting in `onChange`. | ||
this.setState(() => null, () => { | ||
this.onSubmit(); | ||
}); | ||
if (this.mounted) { | ||
this.setState(() => null, () => { | ||
this.onSubmit(); | ||
}); | ||
} | ||
}, this.props.autosaveDelay); | ||
@@ -163,6 +158,8 @@ } | ||
onReset() { | ||
// @ts-expect-error | ||
// It's bound in constructor. | ||
// eslint-disable-next-line @typescript-eslint/unbound-method | ||
this.setState(this.__reset); | ||
if (this.mounted) { | ||
// @ts-expect-error | ||
// It's bound in constructor. | ||
// eslint-disable-next-line @typescript-eslint/unbound-method | ||
this.setState(this.__reset); | ||
} | ||
} | ||
@@ -174,3 +171,5 @@ onSubmit(event) { | ||
} | ||
this.setState(state => (state.submitted ? null : { submitted: true })); | ||
if (this.mounted) { | ||
this.setState(state => (state.submitted ? null : { submitted: true })); | ||
} | ||
const result = this.props.onSubmit(this.getModel('submit')); | ||
@@ -180,5 +179,9 @@ if (!(result instanceof Promise)) { | ||
} | ||
this.setState({ submitting: true }); | ||
if (this.mounted) { | ||
this.setState({ submitting: true }); | ||
} | ||
return result.finally(() => { | ||
this.setState({ submitting: false }); | ||
if (this.mounted) { | ||
this.setState({ submitting: false }); | ||
} | ||
}); | ||
@@ -185,0 +188,0 @@ } |
@@ -37,2 +37,6 @@ import { UnknownObject } from './types'; | ||
/** | ||
* Get initial model value recursively. | ||
*/ | ||
getInitialModel(): UnknownObject; | ||
/** | ||
* Get props defined in schema for a field `name`. There are no required nor | ||
@@ -39,0 +43,0 @@ * banned fields, however properties like `required` are often available. |
import invariant from 'invariant'; | ||
import set from 'lodash/set'; | ||
export class Bridge { | ||
@@ -50,2 +51,14 @@ // Each bridge can have a different set of parameters. | ||
/** | ||
* Get initial model value recursively. | ||
*/ | ||
getInitialModel() { | ||
const initialModel = {}; | ||
const subFields = this.getSubfields(); | ||
for (const fieldName of subFields) { | ||
const initialValue = this.getInitialValue(fieldName); | ||
set(initialModel, fieldName, initialValue); | ||
} | ||
return initialModel; | ||
} | ||
/** | ||
* Get props defined in schema for a field `name`. There are no required nor | ||
@@ -52,0 +65,0 @@ * banned fields, however properties like `required` are often available. |
@@ -14,4 +14,7 @@ /// <reference types="node" /> | ||
[key: string]: unknown; | ||
children?: React.ReactNode; | ||
id?: string | undefined; | ||
key: string; | ||
noValidate: boolean; | ||
onSubmit: (event?: React.SyntheticEvent<Element, Event> | undefined) => Promise<unknown>; | ||
key: string; | ||
}; | ||
@@ -86,4 +89,7 @@ getAutoField(): ComponentType<{ | ||
[key: string]: unknown; | ||
children?: React.ReactNode; | ||
id?: string | undefined; | ||
key: string; | ||
noValidate: boolean; | ||
onSubmit: (event?: React.SyntheticEvent<Element, Event> | undefined) => Promise<unknown>; | ||
key: string; | ||
}; | ||
@@ -90,0 +96,0 @@ getAutoField(): React.ComponentType<{ |
@@ -49,5 +49,3 @@ import get from 'lodash/get'; | ||
useEffect(() => { | ||
var _a; | ||
const required = (_a = props.required) !== null && _a !== void 0 ? _a : schemaProps.required; | ||
if (required && initialValue !== undefined) { | ||
if (initialValue !== undefined) { | ||
onChange(initialValue); | ||
@@ -54,0 +52,0 @@ } |
@@ -24,4 +24,7 @@ /// <reference types="node" /> | ||
[key: string]: unknown; | ||
children?: import("react").ReactNode; | ||
id?: string | undefined; | ||
key: string; | ||
noValidate: boolean; | ||
onSubmit: (event?: SyntheticEvent<Element, Event> | undefined) => Promise<unknown>; | ||
key: string; | ||
}; | ||
@@ -97,4 +100,7 @@ componentDidUpdate(prevProps: Props, prevState: State, snapshot: never): void; | ||
[key: string]: unknown; | ||
children?: import("react").ReactNode; | ||
id?: string | undefined; | ||
key: string; | ||
noValidate: boolean; | ||
onSubmit: (event?: SyntheticEvent<Element, Event> | undefined) => Promise<unknown>; | ||
key: string; | ||
}; | ||
@@ -101,0 +107,0 @@ componentDidUpdate(prevProps: Props, prevState: State, snapshot: never): void; |
@@ -17,4 +17,7 @@ /// <reference types="react" /> | ||
[key: string]: unknown; | ||
children?: import("react").ReactNode; | ||
id?: string | undefined; | ||
key: string; | ||
noValidate: boolean; | ||
onSubmit: (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<unknown>; | ||
key: string; | ||
}; | ||
@@ -85,4 +88,7 @@ componentDidUpdate(prevProps: Props, prevState: State, snapshot: never): void; | ||
[key: string]: unknown; | ||
children?: import("react").ReactNode; | ||
id?: string | undefined; | ||
key: string; | ||
noValidate: boolean; | ||
onSubmit: (event?: import("react").SyntheticEvent<Element, Event> | undefined) => Promise<unknown>; | ||
key: string; | ||
}; | ||
@@ -89,0 +95,0 @@ getAutoField(): import("react").ComponentType<{ |
{ | ||
"name": "uniforms", | ||
"version": "4.0.0-alpha.5", | ||
"version": "4.0.0-alpha.6", | ||
"license": "MIT", | ||
@@ -44,3 +44,3 @@ "main": "./cjs/index.js", | ||
}, | ||
"gitHead": "f878689ee4892ba486a0986a02db78f69b9c8a6d" | ||
"gitHead": "884581ac1dc9191159459d1d5ad2c7169f8769f3" | ||
} |
import invariant from 'invariant'; | ||
import set from 'lodash/set'; | ||
@@ -88,2 +89,15 @@ import { UnknownObject } from './types'; | ||
/** | ||
* Get initial model value recursively. | ||
*/ | ||
getInitialModel(): UnknownObject { | ||
const initialModel: UnknownObject = {}; | ||
const subFields = this.getSubfields(); | ||
for (const fieldName of subFields) { | ||
const initialValue = this.getInitialValue(fieldName); | ||
set(initialModel, fieldName, initialValue); | ||
} | ||
return initialModel; | ||
} | ||
/** | ||
* Get props defined in schema for a field `name`. There are no required nor | ||
@@ -90,0 +104,0 @@ * banned fields, however properties like `required` are often available. |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
228723
5270
1