Comparing version 3.9.0 to 3.9.1
@@ -10,3 +10,2 @@ /// <reference types="react" /> | ||
model: DeepPartial<Model>; | ||
modelSync: DeepPartial<Model>; | ||
}; | ||
@@ -13,0 +12,0 @@ export declare function Auto<Base extends typeof ValidatedQuickForm>(Base: Base): { |
@@ -9,25 +9,42 @@ "use strict"; | ||
const useField_1 = require("./useField"); | ||
function getNextContext(context, props, options) { | ||
// Leaf components by definition do not affect the context. `AutoField` will | ||
// skip most of them anyway, but if rendered directly we have to do it here. | ||
// An example in the core theme are the `List*Field`s. | ||
if ((options === null || options === void 0 ? void 0 : options.kind) === 'leaf') { | ||
return context; | ||
} | ||
const changesName = props.name !== ''; | ||
const changesState = Object.keys(context.state).some(key => { | ||
const next = props[key]; | ||
return next !== null && next !== undefined; | ||
}); | ||
// There are no other ways of affecting the context. | ||
if (!changesName && !changesState) { | ||
return context; | ||
} | ||
const nextContext = Object.assign({}, context); | ||
if (changesName) { | ||
nextContext.name = nextContext.name.concat(props.name); | ||
} | ||
if (changesState) { | ||
nextContext.state = mapValues_1.default(nextContext.state, (prev, key) => { | ||
const next = props[key]; | ||
return next !== null && next !== undefined ? !!next : prev; | ||
}); | ||
} | ||
return nextContext; | ||
} | ||
function connectField(Component, options) { | ||
function Field(props) { | ||
const [fieldProps, context] = useField_1.useField(props.name, props, options); | ||
const hasChainName = props.name !== ''; | ||
const anyFlowingPropertySet = Object.keys(context.state).some(key => { | ||
const next = props[key]; | ||
return next !== null && next !== undefined; | ||
}); | ||
if (!anyFlowingPropertySet && !hasChainName) { | ||
return react_1.default.createElement(Component, Object.assign({}, props, fieldProps)); | ||
const nextContext = getNextContext(context, props, options); | ||
const body = react_1.default.createElement(Component, Object.assign({}, props, fieldProps)); | ||
// If the context has not changed, then don't render the `Provider`. It's | ||
// possible that it will change at some point, but it's extremely rare, as | ||
// either `name` or one of the "state props" has to change. | ||
if (context === nextContext) { | ||
return body; | ||
} | ||
const nextContext = Object.assign({}, context); | ||
if (anyFlowingPropertySet) { | ||
nextContext.state = mapValues_1.default(nextContext.state, (prev, key) => { | ||
const next = props[key]; | ||
return next !== null && next !== undefined ? !!next : prev; | ||
}); | ||
} | ||
if (hasChainName) { | ||
nextContext.name = nextContext.name.concat(props.name); | ||
} | ||
return (react_1.default.createElement(context_1.context.Provider, { value: nextContext }, | ||
react_1.default.createElement(Component, Object.assign({}, props, fieldProps)))); | ||
return react_1.default.createElement(context_1.context.Provider, { children: body, value: nextContext }); | ||
} | ||
@@ -34,0 +51,0 @@ Field.displayName = `${Component.displayName || Component.name}Field`; |
@@ -10,3 +10,2 @@ /// <reference types="react" /> | ||
model: DeepPartial<Model>; | ||
modelSync: DeepPartial<Model>; | ||
}; | ||
@@ -13,0 +12,0 @@ export declare function Auto<Base extends typeof ValidatedQuickForm>(Base: Base): { |
@@ -5,25 +5,42 @@ import mapValues from 'lodash/mapValues'; | ||
import { useField } from './useField'; | ||
function getNextContext(context, props, options) { | ||
// Leaf components by definition do not affect the context. `AutoField` will | ||
// skip most of them anyway, but if rendered directly we have to do it here. | ||
// An example in the core theme are the `List*Field`s. | ||
if ((options === null || options === void 0 ? void 0 : options.kind) === 'leaf') { | ||
return context; | ||
} | ||
const changesName = props.name !== ''; | ||
const changesState = Object.keys(context.state).some(key => { | ||
const next = props[key]; | ||
return next !== null && next !== undefined; | ||
}); | ||
// There are no other ways of affecting the context. | ||
if (!changesName && !changesState) { | ||
return context; | ||
} | ||
const nextContext = Object.assign({}, context); | ||
if (changesName) { | ||
nextContext.name = nextContext.name.concat(props.name); | ||
} | ||
if (changesState) { | ||
nextContext.state = mapValues(nextContext.state, (prev, key) => { | ||
const next = props[key]; | ||
return next !== null && next !== undefined ? !!next : prev; | ||
}); | ||
} | ||
return nextContext; | ||
} | ||
export function connectField(Component, options) { | ||
function Field(props) { | ||
const [fieldProps, context] = useField(props.name, props, options); | ||
const hasChainName = props.name !== ''; | ||
const anyFlowingPropertySet = Object.keys(context.state).some(key => { | ||
const next = props[key]; | ||
return next !== null && next !== undefined; | ||
}); | ||
if (!anyFlowingPropertySet && !hasChainName) { | ||
return React.createElement(Component, Object.assign({}, props, fieldProps)); | ||
const nextContext = getNextContext(context, props, options); | ||
const body = React.createElement(Component, Object.assign({}, props, fieldProps)); | ||
// If the context has not changed, then don't render the `Provider`. It's | ||
// possible that it will change at some point, but it's extremely rare, as | ||
// either `name` or one of the "state props" has to change. | ||
if (context === nextContext) { | ||
return body; | ||
} | ||
const nextContext = Object.assign({}, context); | ||
if (anyFlowingPropertySet) { | ||
nextContext.state = mapValues(nextContext.state, (prev, key) => { | ||
const next = props[key]; | ||
return next !== null && next !== undefined ? !!next : prev; | ||
}); | ||
} | ||
if (hasChainName) { | ||
nextContext.name = nextContext.name.concat(props.name); | ||
} | ||
return (React.createElement(contextReference.Provider, { value: nextContext }, | ||
React.createElement(Component, Object.assign({}, props, fieldProps)))); | ||
return React.createElement(contextReference.Provider, { children: body, value: nextContext }); | ||
} | ||
@@ -30,0 +47,0 @@ Field.displayName = `${Component.displayName || Component.name}Field`; |
{ | ||
"name": "uniforms", | ||
"version": "3.9.0", | ||
"version": "3.9.1", | ||
"license": "MIT", | ||
@@ -44,3 +44,3 @@ "main": "./cjs/index.js", | ||
}, | ||
"gitHead": "88112752bda44226fe116ccfdb317758408f2026" | ||
"gitHead": "5fb4efc108d309e2577ba03e8a1f048a4f13d581" | ||
} |
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
218833
5101