New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

uniforms

Package Overview
Dependencies
Maintainers
1
Versions
192
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

uniforms - npm Package Compare versions

Comparing version 1.0.0-rc.28 to 1.0.0-rc.29

6

lib/components/fields/BaseField.js
'use strict';Object.defineProperty(exports,"__esModule",{value:true});var _extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};var _typeof=typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"?function(obj){return typeof obj;}:function(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol?"symbol":typeof obj;};var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();var _lodash=require('lodash.get');var _lodash2=_interopRequireDefault(_lodash);var _lodash3=require('lodash.isequal');var _lodash4=_interopRequireDefault(_lodash3);var _react=require('react');var _BaseForm=require('../forms/BaseForm');var _BaseForm2=_interopRequireDefault(_BaseForm);var _joinName=require('../../helpers/joinName');var _joinName2=_interopRequireDefault(_joinName);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _possibleConstructorReturn(self,call){if(!self){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return call&&(typeof call==="object"||typeof call==="function")?call:self;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof superClass);}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass;}var BaseField=function(_Component){_inherits(BaseField,_Component);function BaseField(){_classCallCheck(this,BaseField);var _this=_possibleConstructorReturn(this,Object.getPrototypeOf(BaseField).apply(this,arguments));_this.randomId=_this.context.uniforms.randomId();_this.findValue=_this.findValue.bind(_this);_this.findField=_this.findField.bind(_this);_this.findError=_this.findError.bind(_this);_this.getFieldProps=_this.getFieldProps.bind(_this);_this.getChildContextName=_this.getChildContextName.bind(_this);_this.getChildContextError=_this.getChildContextError.bind(_this);_this.getChildContextModel=_this.getChildContextModel.bind(_this);_this.getChildContextState=_this.getChildContextState.bind(_this);_this.getChildContextSchema=_this.getChildContextSchema.bind(_this);_this.getChildContextOnChange=_this.getChildContextOnChange.bind(_this);return _this;}_createClass(BaseField,[{key:'shouldComponentUpdate',value:function shouldComponentUpdate(nextProps,nextState,_ref){var nextContext=_ref.uniforms;var prevProps=this.props;var prevContext=this.context.uniforms;if(!(0,_lodash4.default)(prevProps,nextProps)){return true;}var prevName=(0,_joinName2.default)(prevContext.name,prevProps.name);var nextName=(0,_joinName2.default)(nextContext.name,nextProps.name);if(prevName!==nextName){return true;}if(nextName.indexOf('.')!==-1){var prevParentValue=(0,_lodash2.default)(prevContext.model,prevName.replace(/(.+)\..+$/,'$1'));var nextParentValue=(0,_lodash2.default)(nextContext.model,nextName.replace(/(.+)\..+$/,'$1'));if(Array.isArray(nextParentValue)&&!(0,_lodash4.default)(prevParentValue,nextParentValue)){return true;}}var prevValue=(0,_lodash2.default)(prevContext.model,prevName);var nextValue=(0,_lodash2.default)(nextContext.model,nextName);if(!(0,_lodash4.default)(prevValue,nextValue)){return true;}if(prevContext.error!==nextContext.error){var prevError=prevContext.error&&prevContext.schema.getError(prevName,prevContext.error);var nextError=nextContext.error&&nextContext.schema.getError(nextName,nextContext.error);if(!(0,_lodash4.default)(prevError,nextError)){return true;}// TODO: This is a workaround for List and Nest fields
// Those should update, if their child error has changed
// eslint-disable-next-line max-len
if(nextValue&&(typeof nextValue==='undefined'?'undefined':_typeof(nextValue))==='object'&&Object.prototype.toString.call(nextValue)!=='[object Date]'){return true;}}if(nextContext.schema!==prevContext.schema){return true;}return false;}},{key:'getChildContext',value:function getChildContext(){return{uniforms:{name:this.getChildContextName(),error:this.getChildContextError(),model:this.getChildContextModel(),state:this.getChildContextState(),schema:this.getChildContextSchema(),onChange:this.getChildContextOnChange(),randomId:this.context.uniforms.randomId}};}},{key:'getChildContextName',value:function getChildContextName(){return(0,_joinName2.default)(null,this.context.uniforms.name,this.props.name);}},{key:'getChildContextError',value:function getChildContextError(){return this.context.uniforms.error;}},{key:'getChildContextModel',value:function getChildContextModel(){return this.context.uniforms.model;}},{key:'getChildContextState',value:function getChildContextState(){var state=this.context.uniforms.state;var props=this.props;var propagate=function propagate(name){return props[name]===undefined||props[name]===null?state[name]:!!props[name];};return _extends({},state,{label:propagate('label'),disabled:propagate('disabled'),placeholder:propagate('placeholder')});}},{key:'getChildContextSchema',value:function getChildContextSchema(){return this.context.uniforms.schema;}},{key:'getChildContextOnChange',value:function getChildContextOnChange(){return this.context.uniforms.onChange;}// eslint-disable-next-line complexity
},{key:'getFieldProps',value:function getFieldProps(name){var _ref2=arguments.length<=1||arguments[1]===undefined?{}:arguments[1];var _ref2$explicitInitial=_ref2.explicitInitialValue;var explicitInitialValue=_ref2$explicitInitial===undefined?false:_ref2$explicitInitial;var _ref2$overrideValue=_ref2.overrideValue;var overrideValue=_ref2$overrideValue===undefined?false:_ref2$overrideValue;var _ref2$includeParent=_ref2.includeParent;var includeParent=_ref2$includeParent===undefined?false:_ref2$includeParent;var context=this.context.uniforms;var props=_extends({},this.getChildContextState(),this.props);if(name===undefined){name=(0,_joinName2.default)(context.name,props.name);}var field=context.schema.getField(name);var fieldType=context.schema.getType(name);var schemaProps=context.schema.getProps(name,props);var error=context.schema.getError(name,context.error);var fields=context.schema.getSubfields(name);var parent=includeParent&&name.indexOf('.')!==-1?this.getFieldProps(name.replace(/(.+)\..+$/,'$1'),{includeParent:false}):null;var id=props.id||this.randomId;var errorMessage=context.schema.getErrorMessage(name,context.error);var label=props.label?props.label===true?schemaProps.label:props.label:props.label===null?null:'';var placeholder=props.placeholder?props.placeholder===true?schemaProps.label:props.placeholder:'';var changed=!!(0,_lodash2.default)(context.state.changedMap,name);var value=(0,_lodash2.default)(context.model,name);if(value===undefined&&!explicitInitialValue){value=context.schema.getInitialValue(name,this.props);// This prevents (un)controlled input change warning.
if(nextValue&&(typeof nextValue==='undefined'?'undefined':_typeof(nextValue))==='object'&&Object.prototype.toString.call(nextValue)!=='[object Date]'){return true;}}if(nextContext.schema!==prevContext.schema){return true;}return false;}},{key:'getChildContext',value:function getChildContext(){return{uniforms:{name:this.getChildContextName(),error:this.getChildContextError(),model:this.getChildContextModel(),state:this.getChildContextState(),schema:this.getChildContextSchema(),onChange:this.getChildContextOnChange(),randomId:this.context.uniforms.randomId}};}},{key:'getChildContextName',value:function getChildContextName(){return(0,_joinName2.default)(null,this.context.uniforms.name,this.props.name);}},{key:'getChildContextError',value:function getChildContextError(){return this.context.uniforms.error;}},{key:'getChildContextModel',value:function getChildContextModel(){return this.context.uniforms.model;}},{key:'getChildContextState',value:function getChildContextState(){var state=this.context.uniforms.state;var props=this.props;var propagate=function propagate(name){return props[name]===undefined||props[name]===null?state[name]:!!props[name];};return _extends({},state,{label:propagate('label'),disabled:propagate('disabled'),placeholder:propagate('placeholder')});}},{key:'getChildContextSchema',value:function getChildContextSchema(){return this.context.uniforms.schema;}},{key:'getChildContextOnChange',value:function getChildContextOnChange(){return this.context.uniforms.onChange;}// eslint-disable-next-line complexity, max-len
},{key:'getFieldProps',value:function getFieldProps(name){var _ref2=arguments.length<=1||arguments[1]===undefined?{}:arguments[1];var _ref2$explicitInitial=_ref2.explicitInitialValue;var explicitInitialValue=_ref2$explicitInitial===undefined?false:_ref2$explicitInitial;var _ref2$overrideValue=_ref2.overrideValue;var overrideValue=_ref2$overrideValue===undefined?false:_ref2$overrideValue;var _ref2$includeParent=_ref2.includeParent;var includeParent=_ref2$includeParent===undefined?false:_ref2$includeParent;var _ref2$ensureValue=_ref2.ensureValue;var ensureValue=_ref2$ensureValue===undefined?true:_ref2$ensureValue;var context=this.context.uniforms;var props=_extends({},this.getChildContextState(),this.props);if(name===undefined){name=(0,_joinName2.default)(context.name,props.name);}var field=context.schema.getField(name);var fieldType=context.schema.getType(name);var schemaProps=context.schema.getProps(name,props);var error=context.schema.getError(name,context.error);var fields=context.schema.getSubfields(name);var parent=includeParent&&name.indexOf('.')!==-1?this.getFieldProps(name.replace(/(.+)\..+$/,'$1'),{includeParent:false}):null;var id=props.id||this.randomId;var errorMessage=context.schema.getErrorMessage(name,context.error);var label=props.label?props.label===true?schemaProps.label:props.label:props.label===null?null:'';var placeholder=props.placeholder?props.placeholder===true?schemaProps.label:props.placeholder:'';var changed=!!(0,_lodash2.default)(context.state.changedMap,name);var value=(0,_lodash2.default)(context.model,name);if(value===undefined&&!explicitInitialValue){value=context.schema.getInitialValue(name,this.props);// This prevents (un)controlled input change warning.
// More info: https://fb.me/react-controlled-components.
if(value===undefined){value='';}}else if(explicitInitialValue){props.initialValue=context.schema.getInitialValue(name,this.props);}var findValue=this.findValue;var findField=this.findField;var findError=this.findError;var onChange=function onChange(value){var key=arguments.length<=1||arguments[1]===undefined?name:arguments[1];return context.onChange(key,value);};return _extends({changed:changed,error:error,errorMessage:errorMessage,field:field,fieldType:fieldType,fields:fields,findError:findError,findField:findField,findValue:findValue,id:id,onChange:onChange,parent:parent,value:value},props,schemaProps,overrideValue&&{value:value},{label:label,name:name,placeholder:placeholder});}},{key:'findError',value:function findError(name){return this.context.uniforms.schema.getError(name,this.context.uniforms.error);}},{key:'findField',value:function findField(name){return this.context.uniforms.schema.getField(name);}},{key:'findValue',value:function findValue(name){return(0,_lodash2.default)(this.context.uniforms.model,name);}}]);return BaseField;}(_react.Component);BaseField.propTypes={id:_react.PropTypes.string,name:_react.PropTypes.string,disabled:_react.PropTypes.bool,label:_react.PropTypes.oneOfType([_react.PropTypes.bool,_react.PropTypes.string,_react.PropTypes.node]),placeholder:_react.PropTypes.oneOfType([_react.PropTypes.bool,_react.PropTypes.string])};BaseField.contextTypes=_BaseForm2.default.childContextTypes;BaseField.childContextTypes=_BaseForm2.default.childContextTypes;exports.default=BaseField;
if(value===undefined&&ensureValue){value='';}}else if(explicitInitialValue){props.initialValue=context.schema.getInitialValue(name,this.props);}var findValue=this.findValue;var findField=this.findField;var findError=this.findError;var onChange=function onChange(value){var key=arguments.length<=1||arguments[1]===undefined?name:arguments[1];return context.onChange(key,value);};return _extends({changed:changed,error:error,errorMessage:errorMessage,field:field,fieldType:fieldType,fields:fields,findError:findError,findField:findField,findValue:findValue,id:id,onChange:onChange,parent:parent,value:value},props,schemaProps,overrideValue&&{value:value},{label:label,name:name,placeholder:placeholder});}},{key:'findError',value:function findError(name){return this.context.uniforms.schema.getError(name,this.context.uniforms.error);}},{key:'findField',value:function findField(name){return this.context.uniforms.schema.getField(name);}},{key:'findValue',value:function findValue(name){return(0,_lodash2.default)(this.context.uniforms.model,name);}}]);return BaseField;}(_react.Component);BaseField.propTypes={id:_react.PropTypes.string,name:_react.PropTypes.string,disabled:_react.PropTypes.bool,label:_react.PropTypes.oneOfType([_react.PropTypes.bool,_react.PropTypes.string,_react.PropTypes.node]),placeholder:_react.PropTypes.oneOfType([_react.PropTypes.bool,_react.PropTypes.string])};BaseField.contextTypes=_BaseForm2.default.childContextTypes;BaseField.childContextTypes=_BaseForm2.default.childContextTypes;exports.default=BaseField;

@@ -1,3 +0,3 @@

'use strict';Object.defineProperty(exports,"__esModule",{value:true});var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();var _get=function get(object,property,receiver){if(object===null)object=Function.prototype;var desc=Object.getOwnPropertyDescriptor(object,property);if(desc===undefined){var parent=Object.getPrototypeOf(object);if(parent===null){return undefined;}else{return get(parent,property,receiver);}}else if("value"in desc){return desc.value;}else{var getter=desc.get;if(getter===undefined){return undefined;}return getter.call(receiver);}};exports.default=connectField;var _react=require('react');var _BaseField=require('../components/fields/BaseField');var _BaseField2=_interopRequireDefault(_BaseField);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _possibleConstructorReturn(self,call){if(!self){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return call&&(typeof call==="object"||typeof call==="function")?call:self;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof superClass);}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass;}function connectField(component){var _class,_temp;var _ref=arguments.length<=1||arguments[1]===undefined?{}:arguments[1];var _ref$mapProps=_ref.mapProps;var mapProps=_ref$mapProps===undefined?function(x){return x;}:_ref$mapProps;var _ref$baseField=_ref.baseField;var baseField=_ref$baseField===undefined?_BaseField2.default:_ref$baseField;var _ref$initialValue=_ref.initialValue;var initialValue=_ref$initialValue===undefined?true:_ref$initialValue;var _ref$includeParent=_ref.includeParent;var includeParent=_ref$includeParent===undefined?false:_ref$includeParent;var _ref$includeInChain=_ref.includeInChain;var includeInChain=_ref$includeInChain===undefined?true:_ref$includeInChain;return _temp=_class=function(_baseField){_inherits(_class,_baseField);function _class(){_classCallCheck(this,_class);return _possibleConstructorReturn(this,Object.getPrototypeOf(_class).apply(this,arguments));}_createClass(_class,[{key:'getChildContextName',value:function getChildContextName(){return includeInChain?_get(Object.getPrototypeOf(_class.prototype),'getChildContextName',this).call(this):this.context.uniforms.name;}},{key:'render',value:function render(){return(0,_react.createElement)(component,mapProps(this.getFieldProps(undefined,{includeParent:includeParent})));}},{key:'componentWillMount',value:function componentWillMount(){if(initialValue){var props=this.getFieldProps(undefined,{explicitInitialValue:true,includeParent:false});// https://github.com/vazco/uniforms/issues/52
'use strict';Object.defineProperty(exports,"__esModule",{value:true});var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();var _get=function get(object,property,receiver){if(object===null)object=Function.prototype;var desc=Object.getOwnPropertyDescriptor(object,property);if(desc===undefined){var parent=Object.getPrototypeOf(object);if(parent===null){return undefined;}else{return get(parent,property,receiver);}}else if("value"in desc){return desc.value;}else{var getter=desc.get;if(getter===undefined){return undefined;}return getter.call(receiver);}};exports.default=connectField;var _react=require('react');var _BaseField=require('../components/fields/BaseField');var _BaseField2=_interopRequireDefault(_BaseField);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _possibleConstructorReturn(self,call){if(!self){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return call&&(typeof call==="object"||typeof call==="function")?call:self;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof superClass);}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass;}function connectField(component){var _class,_temp;var _ref=arguments.length<=1||arguments[1]===undefined?{}:arguments[1];var _ref$mapProps=_ref.mapProps;var mapProps=_ref$mapProps===undefined?function(x){return x;}:_ref$mapProps;var _ref$baseField=_ref.baseField;var baseField=_ref$baseField===undefined?_BaseField2.default:_ref$baseField;var _ref$ensureValue=_ref.ensureValue;var ensureValue=_ref$ensureValue===undefined?true:_ref$ensureValue;var _ref$initialValue=_ref.initialValue;var initialValue=_ref$initialValue===undefined?true:_ref$initialValue;var _ref$includeParent=_ref.includeParent;var includeParent=_ref$includeParent===undefined?false:_ref$includeParent;var _ref$includeInChain=_ref.includeInChain;var includeInChain=_ref$includeInChain===undefined?true:_ref$includeInChain;return _temp=_class=function(_baseField){_inherits(_class,_baseField);function _class(){_classCallCheck(this,_class);return _possibleConstructorReturn(this,Object.getPrototypeOf(_class).apply(this,arguments));}_createClass(_class,[{key:'getChildContextName',value:function getChildContextName(){return includeInChain?_get(Object.getPrototypeOf(_class.prototype),'getChildContextName',this).call(this):this.context.uniforms.name;}},{key:'render',value:function render(){return(0,_react.createElement)(component,mapProps(this.getFieldProps(undefined,{ensureValue:ensureValue,includeParent:includeParent})));}},{key:'componentWillMount',value:function componentWillMount(){if(initialValue){var props=this.getFieldProps(undefined,{explicitInitialValue:true,includeParent:false});// https://github.com/vazco/uniforms/issues/52
// If field is initially rendered with value, we treat it as an initial value.
if(this.props.value!==undefined){props.onChange(this.props.value);return;}if(props.value===undefined&&props.required){props.onChange(props.initialValue);}}}}]);return _class;}(baseField),_class.displayName=(baseField.displayName||baseField.name)+'('+(component.displayName||component.name)+')',_temp;}
{
"name": "uniforms",
"version": "1.0.0-rc.28",
"version": "1.0.0-rc.29",
"main": "lib/index.js",

@@ -5,0 +5,0 @@ "jsnext:main": "src/index.js",

@@ -145,4 +145,4 @@ import get from 'lodash.get';

// eslint-disable-next-line complexity
getFieldProps (name, {explicitInitialValue = false, overrideValue = false, includeParent = false} = {}) {
// eslint-disable-next-line complexity, max-len
getFieldProps (name, {explicitInitialValue = false, overrideValue = false, includeParent = false, ensureValue = true} = {}) {
const context = this.context.uniforms;

@@ -194,3 +194,3 @@ const props = {

// More info: https://fb.me/react-controlled-components.
if (value === undefined) {
if (value === undefined && ensureValue) {
value = '';

@@ -197,0 +197,0 @@ }

@@ -9,2 +9,3 @@ import {createElement} from 'react';

ensureValue = true,
initialValue = true,

@@ -22,3 +23,3 @@ includeParent = false,

render () {
return createElement(component, mapProps(this.getFieldProps(undefined, {includeParent})));
return createElement(component, mapProps(this.getFieldProps(undefined, {ensureValue, includeParent})));
}

@@ -25,0 +26,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc