Comparing version 3.0.0-alpha.4 to 3.0.0-alpha.5
/// <reference types="react" /> | ||
import { BaseForm } from './BaseForm'; | ||
import { DeepPartial } from './types'; | ||
import { DeepPartial, ModelTransformMode } from './types'; | ||
import { ValidatedQuickForm, ValidatedQuickFormProps, ValidatedQuickFormState } from './ValidatedQuickForm'; | ||
@@ -16,4 +16,4 @@ export declare type AutoFormProps<Model> = ValidatedQuickFormProps<Model> & { | ||
getNativeFormProps(): Record<string, any>; | ||
getModel(mode: any): State["model"]; | ||
onChange(key: any, value: any): void; | ||
getModel(mode: ModelTransformMode): State["model"]; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State): Partial<State>; | ||
@@ -97,4 +97,4 @@ onValidate(): Promise<any>; | ||
getNativeFormProps(): Record<string, any>; | ||
getModel(mode: any): State["model"]; | ||
onChange(key: any, value: any): void; | ||
getModel(mode: ModelTransformMode): State["model"]; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State): Partial<State>; | ||
@@ -101,0 +101,0 @@ onValidate(): Promise<any>; |
@@ -15,3 +15,3 @@ "use strict"; | ||
var _this = _super.call(this, props) || this; | ||
_this.state = tslib_1.__assign(tslib_1.__assign({}, _this.state), { model: props.model, modelSync: props.model }); | ||
_this.state = tslib_1.__assign(tslib_1.__assign({}, _this.state), { model: props.model }); | ||
return _this; | ||
@@ -22,3 +22,3 @@ } | ||
if (!isEqual_1.default(model, prevProps.model)) { | ||
this.setState({ model: model, modelSync: model }); | ||
this.setState({ model: model }); | ||
} | ||
@@ -31,19 +31,14 @@ _super.prototype.componentDidUpdate.call(this, prevProps, prevState, snapshot); | ||
AutoForm.prototype.getModel = function (mode) { | ||
return mode === 'form' ? this.state.modelSync : this.state.model; | ||
return this.state.model; | ||
}; | ||
AutoForm.prototype.onChange = function (key, value) { | ||
var _this = this; | ||
this.setState(function (state) { return ({ | ||
modelSync: setWith_1.default(clone_1.default(state.modelSync), key, value, clone_1.default), | ||
}); }, function () { | ||
this.setState(function (state) { return ({ model: setWith_1.default(clone_1.default(state.model), key, value, clone_1.default) }); }, function () { | ||
_super.prototype.onChange.call(_this, key, value); | ||
_this.setState(function (state) { | ||
if (_this.props.onChangeModel) | ||
_this.props.onChangeModel(state.modelSync); | ||
return { model: state.modelSync }; | ||
}); | ||
if (_this.props.onChangeModel) | ||
_this.props.onChangeModel(_this.state.model); | ||
}); | ||
}; | ||
AutoForm.prototype.__reset = function (state) { | ||
return tslib_1.__assign(tslib_1.__assign({}, _super.prototype.__reset.call(this, state)), { model: this.props.model, modelSync: this.props.model }); | ||
return tslib_1.__assign(tslib_1.__assign({}, _super.prototype.__reset.call(this, state)), { model: this.props.model }); | ||
}; | ||
@@ -50,0 +45,0 @@ AutoForm.prototype.onValidate = function () { |
import React, { ComponentType } from 'react'; | ||
import { GuaranteedProps, Override } from './types'; | ||
export declare function connectField<Props extends Partial<GuaranteedProps<Value>>, Value = Props['value']>(Component: ComponentType<Props>, options?: { | ||
includeInChain?: boolean; | ||
initialValue?: boolean; | ||
}): React.FunctionComponent<Override<Props, Override<Partial<GuaranteedProps<Value> & Partial<Props>>, { | ||
kind?: 'leaf' | 'node'; | ||
}): React.FunctionComponent<Override<Props, Override<Partial<GuaranteedProps<Value>>, { | ||
label?: string | boolean | Props["label"] | null | undefined; | ||
name: string; | ||
placeholder?: string | boolean | Props["placeholder"] | null | undefined; | ||
}>>>; | ||
}>>> & { | ||
Component: React.ComponentType<Props>; | ||
options: { | ||
initialValue?: boolean | undefined; | ||
kind?: "leaf" | "node" | undefined; | ||
} | undefined; | ||
}; |
@@ -12,3 +12,3 @@ "use strict"; | ||
var _a = useField_1.useField(props.name, props, options), fieldProps = _a[0], context = _a[1]; | ||
var hasChainName = (options === null || options === void 0 ? void 0 : options.includeInChain) !== false && props.name !== ''; | ||
var hasChainName = props.name !== ''; | ||
var anyFlowingPropertySet = some_1.default(context.state, function (_, key) { return props[key] !== null && props[key] !== undefined; }); | ||
@@ -31,4 +31,7 @@ if (!anyFlowingPropertySet && !hasChainName) { | ||
Field.displayName = (Component.displayName || Component.name) + "Field"; | ||
return Field; | ||
return Object.assign(Field, { | ||
Component: Component, | ||
options: options, | ||
}); | ||
} | ||
exports.connectField = connectField; |
/// <reference types="react" /> | ||
import { BaseForm } from './BaseForm'; | ||
import { DeepPartial } from './types'; | ||
import { DeepPartial, ModelTransformMode } from './types'; | ||
import { ValidatedQuickForm, ValidatedQuickFormProps, ValidatedQuickFormState } from './ValidatedQuickForm'; | ||
@@ -16,4 +16,4 @@ export declare type AutoFormProps<Model> = ValidatedQuickFormProps<Model> & { | ||
getNativeFormProps(): Record<string, any>; | ||
getModel(mode: any): State["model"]; | ||
onChange(key: any, value: any): void; | ||
getModel(mode: ModelTransformMode): State["model"]; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State): Partial<State>; | ||
@@ -97,4 +97,4 @@ onValidate(): Promise<any>; | ||
getNativeFormProps(): Record<string, any>; | ||
getModel(mode: any): State["model"]; | ||
onChange(key: any, value: any): void; | ||
getModel(mode: ModelTransformMode): State["model"]; | ||
onChange(key: string, value: any): void; | ||
__reset(state: State): Partial<State>; | ||
@@ -101,0 +101,0 @@ onValidate(): Promise<any>; |
@@ -11,3 +11,3 @@ import clone from 'lodash/clone'; | ||
super(props); | ||
this.state = Object.assign(Object.assign({}, this.state), { model: props.model, modelSync: props.model }); | ||
this.state = Object.assign(Object.assign({}, this.state), { model: props.model }); | ||
} | ||
@@ -17,3 +17,3 @@ componentDidUpdate(prevProps, prevState, snapshot) { | ||
if (!isEqual(model, prevProps.model)) { | ||
this.setState({ model, modelSync: model }); | ||
this.setState({ model }); | ||
} | ||
@@ -26,18 +26,13 @@ super.componentDidUpdate(prevProps, prevState, snapshot); | ||
getModel(mode) { | ||
return mode === 'form' ? this.state.modelSync : this.state.model; | ||
return this.state.model; | ||
} | ||
onChange(key, value) { | ||
this.setState(state => ({ | ||
modelSync: setWith(clone(state.modelSync), key, value, clone), | ||
}), () => { | ||
this.setState(state => ({ model: setWith(clone(state.model), key, value, clone) }), () => { | ||
super.onChange(key, value); | ||
this.setState(state => { | ||
if (this.props.onChangeModel) | ||
this.props.onChangeModel(state.modelSync); | ||
return { model: state.modelSync }; | ||
}); | ||
if (this.props.onChangeModel) | ||
this.props.onChangeModel(this.state.model); | ||
}); | ||
} | ||
__reset(state) { | ||
return Object.assign(Object.assign({}, super.__reset(state)), { model: this.props.model, modelSync: this.props.model }); | ||
return Object.assign(Object.assign({}, super.__reset(state)), { model: this.props.model }); | ||
} | ||
@@ -44,0 +39,0 @@ onValidate() { |
import React, { ComponentType } from 'react'; | ||
import { GuaranteedProps, Override } from './types'; | ||
export declare function connectField<Props extends Partial<GuaranteedProps<Value>>, Value = Props['value']>(Component: ComponentType<Props>, options?: { | ||
includeInChain?: boolean; | ||
initialValue?: boolean; | ||
}): React.FunctionComponent<Override<Props, Override<Partial<GuaranteedProps<Value> & Partial<Props>>, { | ||
kind?: 'leaf' | 'node'; | ||
}): React.FunctionComponent<Override<Props, Override<Partial<GuaranteedProps<Value>>, { | ||
label?: string | boolean | Props["label"] | null | undefined; | ||
name: string; | ||
placeholder?: string | boolean | Props["placeholder"] | null | undefined; | ||
}>>>; | ||
}>>> & { | ||
Component: React.ComponentType<Props>; | ||
options: { | ||
initialValue?: boolean | undefined; | ||
kind?: "leaf" | "node" | undefined; | ||
} | undefined; | ||
}; |
@@ -9,3 +9,3 @@ import React from 'react'; | ||
const [fieldProps, context] = useField(props.name, props, options); | ||
const hasChainName = (options === null || options === void 0 ? void 0 : options.includeInChain) !== false && props.name !== ''; | ||
const hasChainName = props.name !== ''; | ||
const anyFlowingPropertySet = some(context.state, (_, key) => props[key] !== null && props[key] !== undefined); | ||
@@ -26,3 +26,6 @@ if (!anyFlowingPropertySet && !hasChainName) { | ||
Field.displayName = `${Component.displayName || Component.name}Field`; | ||
return Field; | ||
return Object.assign(Field, { | ||
Component, | ||
options, | ||
}); | ||
} |
{ | ||
"name": "uniforms", | ||
"version": "3.0.0-alpha.4", | ||
"version": "3.0.0-alpha.5", | ||
"license": "MIT", | ||
@@ -35,3 +35,3 @@ "main": "es5/index.js", | ||
}, | ||
"gitHead": "1f70af5f56235d4875611ee813c61aeaa2b0ae46" | ||
"gitHead": "dc48cb023e00503430cc3879c9bf28fac2e1257c" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
4430
188917