Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-form-with-constraints

Package Overview
Dependencies
Maintainers
1
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-form-with-constraints - npm Package Compare versions

Comparing version 0.14.1-beta.1 to 0.14.1

6

CHANGELOG.md

@@ -0,1 +1,7 @@

## v0.14.1 (2020/02/28)
### Features
- Update npm packages
## v0.14.0 (2019/09/25)

@@ -2,0 +8,0 @@

4

dist/react-form-with-constraints.development.js

@@ -5,3 +5,3 @@ (function (global, factory) {

(global = global || self, factory(global.ReactFormWithConstraints = {}, global.React, global.PropTypes));
}(this, function (exports, React, PropTypes) { 'use strict';
}(this, (function (exports, React, PropTypes) { 'use strict';

@@ -1190,3 +1190,3 @@ /*! *****************************************************************************

}));
})));
//# sourceMappingURL=react-form-with-constraints.development.js.map

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("prop-types")):"function"==typeof define&&define.amd?define(["exports","react","prop-types"],t):t((e=e||self).ReactFormWithConstraints={},e.React,e.PropTypes)}(this,function(o,f,e){"use strict";var n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i])})(e,t)};function r(e,t){function i(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(i.prototype=t.prototype,new i)}var p=function(){return(p=Object.assign||function(e){for(var t,i=1,n=arguments.length;i<n;i++)for(var r in t=arguments[i])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)};function h(e,t){var i={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(n=Object.getOwnPropertySymbols(e);r<n.length;r++)t.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(e,n[r])&&(i[n[r]]=e[n[r]])}return i}function l(a,s,o,l){return new(o=o||Promise)(function(e,t){function i(e){try{r(l.next(e))}catch(e){t(e)}}function n(e){try{r(l.throw(e))}catch(e){t(e)}}function r(t){t.done?e(t.value):new o(function(e){e(t.value)}).then(i,n)}r((l=l.apply(a,s||[])).next())})}function v(i,n){var r,a,s,e,o={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return e={next:t(0),throw:t(1),return:t(2)},"function"==typeof Symbol&&(e[Symbol.iterator]=function(){return this}),e;function t(t){return function(e){return function(t){if(r)throw new TypeError("Generator is already executing.");for(;o;)try{if(r=1,a&&(s=2&t[0]?a.return:t[0]?a.throw||((s=a.return)&&s.call(a),0):a.next)&&!(s=s.call(a,t[1])).done)return s;switch(a=0,s&&(t=[2&t[0],s.value]),t[0]){case 0:case 1:s=t;break;case 4:return o.label++,{value:t[1],done:!1};case 5:o.label++,a=t[1],t=[0];continue;case 7:t=o.ops.pop(),o.trys.pop();continue;default:if(!(s=0<(s=o.trys).length&&s[s.length-1])&&(6===t[0]||2===t[0])){o=0;continue}if(3===t[0]&&(!s||t[1]>s[0]&&t[1]<s[3])){o.label=t[1];break}if(6===t[0]&&o.label<s[1]){o.label=s[1],s=t;break}if(s&&o.label<s[2]){o.label=s[2],o.ops.push(t);break}s[2]&&o.ops.pop(),o.trys.pop();continue}t=n.call(i,o)}catch(e){t=[6,e],a=0}finally{r=s=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([t,e])}}}function y(e){var t="function"==typeof Symbol&&e[Symbol.iterator],i=0;return t?t.call(e):{next:function(){return e&&i>=e.length&&(e=void 0),{value:e&&e[i++],done:!e}}}}function i(e,t){var i="function"==typeof Symbol&&e[Symbol.iterator];if(!i)return e;var n,r,a=i.call(e),s=[];try{for(;(void 0===t||0<t--)&&!(n=a.next()).done;)s.push(n.value)}catch(e){r={error:e}}finally{try{n&&!n.done&&(i=a.return)&&i.call(a)}finally{if(r)throw r.error}}return s}function m(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(i(arguments[t]));return e}var a=(t.prototype.emit=function(u){for(var f=[],e=1;e<arguments.length;e++)f[e-1]=arguments[e];return l(this,void 0,void 0,function(){var t,i,n,r,a,s,o,l,d,c;return v(this,function(e){switch(e.label){case 0:if(t=this.listeners.get(u),i=new Array,void 0===t)return[3,8];console.assert(0<t.length,"No listener for event '"+u+"'"),e.label=1;case 1:e.trys.push([1,6,7,8]),n=y(t),r=n.next(),e.label=2;case 2:return r.done?[3,5]:(a=r.value,o=(s=i).push,[4,a.apply(void 0,m(f))]);case 3:o.apply(s,[e.sent()]),e.label=4;case 4:return r=n.next(),[3,2];case 5:return[3,8];case 6:return l=e.sent(),d={error:l},[3,8];case 7:try{r&&!r.done&&(c=n.return)&&c.call(n)}finally{if(d)throw d.error}return[7];case 8:return[2,i]}})})},t.prototype.addListener=function(e,t){this.listeners.has(e)||this.listeners.set(e,[]);var i=this.listeners.get(e);console.assert(-1===i.indexOf(t),"Listener already added for event '"+e+"'"),i.push(t)},t.prototype.removeListener=function(e,t){var i=this.listeners.get(e);console.assert(void 0!==i,"Unknown event '"+e+"'");var n=i.lastIndexOf(t);console.assert(-1<n,"Listener not found for event '"+e+"'"),i.splice(n,1),0===i.length&&this.listeners.delete(e)},t);function t(){this.listeners=new Map}var s="VALIDATE_FIELD_EVENT";function d(e){return r(t,i=e),t.prototype.emitValidateFieldEvent=function(e){return this.validateFieldEventEmitter.emit(s,e)},t.prototype.addValidateFieldEventListener=function(e){this.validateFieldEventEmitter.addListener(s,e)},t.prototype.removeValidateFieldEventListener=function(e){this.validateFieldEventEmitter.removeListener(s,e)},t;function t(){var e=null!==i&&i.apply(this,arguments)||this;return e.validateFieldEventEmitter=new a,e}var i}var c="FIELD_WILL_VALIDATE_EVENT";function u(e){return r(t,i=e),t.prototype.emitFieldWillValidateEvent=function(e){return this.fieldWillValidateEventEmitter.emit(c,e)},t.prototype.addFieldWillValidateEventListener=function(e){this.fieldWillValidateEventEmitter.addListener(c,e)},t.prototype.removeFieldWillValidateEventListener=function(e){this.fieldWillValidateEventEmitter.removeListener(c,e)},t;function t(){var e=null!==i&&i.apply(this,arguments)||this;return e.fieldWillValidateEventEmitter=new a,e}var i}var F="FIELD_DID_VALIDATE_EVENT";function E(e){return r(t,i=e),t.prototype.emitFieldDidValidateEvent=function(e){return this.fieldDidValidateEventEmitter.emit(F,e)},t.prototype.addFieldDidValidateEventListener=function(e){this.fieldDidValidateEventEmitter.addListener(F,e)},t.prototype.removeFieldDidValidateEventListener=function(e){this.fieldDidValidateEventEmitter.removeListener(F,e)},t;function t(){var e=null!==i&&i.apply(this,arguments)||this;return e.fieldDidValidateEventEmitter=new a,e}var i}var b="FIELD_DID_RESET_EVENT";function w(e){return r(t,i=e),t.prototype.emitFieldDidResetEvent=function(e){return this.fieldDidResetEventEmitter.emit(b,e)},t.prototype.addFieldDidResetEventListener=function(e){this.fieldDidResetEventEmitter.addListener(b,e)},t.prototype.removeFieldDidResetEventListener=function(e){this.fieldDidResetEventEmitter.removeListener(b,e)},t;function t(){var e=null!==i&&i.apply(this,arguments)||this;return e.fieldDidResetEventEmitter=new a,e}var i}var g=function(e){this.badInput=e.badInput,this.customError=e.customError,this.patternMismatch=e.patternMismatch,this.rangeOverflow=e.rangeOverflow,this.rangeUnderflow=e.rangeUnderflow,this.stepMismatch=e.stepMismatch,this.tooLong=e.tooLong,this.tooShort=e.tooShort,this.typeMismatch=e.typeMismatch,this.valid=e.valid,this.valueMissing=e.valueMissing};function V(e){return void 0===e.props}var k,D,x=function(e){V(e)?(e=e,this.name=e.name,this.type=e.type,this.value=e.value,this.validity=new g(e.validity),this.validationMessage=e.validationMessage):(e=e,this.name=e.props.name,this.type=void 0,this.value=e.props.value,this.validity=void 0,this.validationMessage=void 0)};(D=k=k||{}).Error="error",D.Warning="warning",D.Info="info",D.WhenValid="whenValid";var L=k;var S,R=(O.prototype.addOrReplaceValidation=function(t){var e=this.validations.findIndex(function(e){return e.key===t.key});-1<e?this.validations[e]=t:this.validations.push(t)},O.prototype.clearValidations=function(){!function(e){for(;e.length;)e.pop()}(this.validations)},O.prototype.hasFeedbacksOfType=function(t,i){return this.validations.some(function(e){return(void 0===i||e.key.startsWith(i+"."))&&e.type===t&&!0===e.show})},O.prototype.hasErrors=function(e){return this.hasFeedbacksOfType(L.Error,e)},O.prototype.hasWarnings=function(e){return this.hasFeedbacksOfType(L.Warning,e)},O.prototype.hasInfos=function(e){return this.hasFeedbacksOfType(L.Info,e)},O.prototype.hasFeedbacks=function(e){return this.hasErrors(e)||this.hasWarnings(e)||this.hasInfos(e)},O.prototype.isValid=function(){return!this.hasErrors()},O);function O(e){this.name=e,this.validations=[]}(S=o.FieldEvent||(o.FieldEvent={})).Added="FIELD_ADDED",S.Removed="FIELD_REMOVED";var W,I=(r(M,W=a),M.prototype.getField=function(t){var e=this.fields.filter(function(e){return e.name===t});return 1===e.length?e[0]:void 0},M.prototype.addField=function(t){var e=this.fields.filter(function(e){return e.name===t});if(console.assert(0===e.length||1===e.length,"Cannot have more than 1 field matching '"+t+"'"),0===e.length){var i=new R(t);this.fields.push(i),this.emit(o.FieldEvent.Added,i)}},M.prototype.removeField=function(t){var e=this.fields.filter(function(e){return e.name===t}),i=this.fields.indexOf(e[0]);-1<i&&(this.fields.splice(i,1),this.emit(o.FieldEvent.Removed,t))},M.prototype.isValid=function(){return this.fields.every(function(e){return e.isValid()})},M.prototype.hasFeedbacks=function(){return this.fields.some(function(e){return e.hasFeedbacks()})},M);function M(){var e=null!==W&&W.apply(this,arguments)||this;return e.fields=new Array,e}function N(e){return e.reduce(function(e,t){return e.concat(Array.isArray(t)?N(t):t)},[])}function _(e){return void 0!==e}var C,T=(r(P,C=f.PureComponent),P);function P(){return null!==C&&C.apply(this,arguments)||this}var A,j=(r(q,A=w(u(E(d(T))))),q.prototype.getChildContext=function(){return{form:this}},q.prototype.computeFieldFeedbacksKey=function(){return""+this.fieldFeedbacksKeyCounter++},q.prototype.validateFields=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return this._validateFields.apply(this,m([!0],e))},q.prototype.validateForm=function(){return this.validateFieldsWithoutFeedback()},q.prototype.validateFieldsWithoutFeedback=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return this._validateFields.apply(this,m([!1],e))},q.prototype._validateFields=function(c){for(var u=[],e=1;e<arguments.length;e++)u[e-1]=arguments[e];return l(this,void 0,void 0,function(){var t,i,n,r,a,s,o,l,d;return v(this,function(e){switch(e.label){case 0:t=new Array,i=this.normalizeInputs.apply(this,m(u)),e.label=1;case 1:e.trys.push([1,6,7,8]),n=y(i),r=n.next(),e.label=2;case 2:return r.done?[3,5]:(a=r.value,[4,this.validateField(c,new x(a))]);case 3:void 0!==(s=e.sent())&&(s.element=a,t.push(s)),e.label=4;case 4:return r=n.next(),[3,2];case 5:return[3,8];case 6:return o=e.sent(),l={error:o},[3,8];case 7:try{r&&!r.done&&(d=n.return)&&d.call(n)}finally{if(l)throw l.error}return[7];case 8:return[2,t]}})})},q.prototype.validateField=function(r,a){return l(this,void 0,void 0,function(){var t,i,n;return v(this,function(e){switch(e.label){case 0:return t=a.name,void 0!==(i=this.fieldsStore.getField(t))?[3,1]:[3,3];case 1:return!r&&i.hasFeedbacks()?[3,3]:(i.clearValidations(),this.emitFieldWillValidateEvent(t),[4,this.emitValidateFieldEvent(a)]);case 2:n=e.sent(),console.assert(JSON.stringify(N(n).filter(_))===JSON.stringify(i.validations),"FieldsStore does not match emitValidateFieldEvent() result, did the user changed the input rapidly?"),this.emitFieldDidValidateEvent(i),e.label=3;case 3:return[2,i]}})})},q.prototype.normalizeInputs=function(){for(var e,r=this,t=[],i=0;i<arguments.length;i++)t[i]=arguments[i];return 0===t.length?(e=(e=m(this.form.querySelectorAll("[name]"))).filter(function(e){return void 0!==e.validity})).filter(function(e){return"checkbox"!==e.type&&"radio"!==e.type}).map(function(e){return e.name}).forEach(function(e,t,i){if(i.indexOf(e)!==t)throw new Error("Multiple elements matching '[name=\""+e+"\"]' inside the form")}):e=t.map(function(e){if("string"!=typeof e)return e;var t='[name="'+e+'"]',i=m(r.form.querySelectorAll(t));if(0<i.filter(function(e){return void 0===e.validity}).length)throw new Error("'"+t+"' should match an <input>, <select> or <textarea>");if(1<i.filter(function(e){return"checkbox"!==e.type&&"radio"!==e.type}).length)throw new Error("Multiple elements matching '"+t+"' inside the form");var n=i[0];if(void 0===n)throw new Error("Could not find field '"+t+"' inside the form");return n}),e},q.prototype.isValid=function(){return this.fieldsStore.isValid()},q.prototype.hasFeedbacks=function(){return this.fieldsStore.hasFeedbacks()},q.prototype.reset=function(){return this.resetFields()},q.prototype.resetFields=function(){for(var c=[],e=0;e<arguments.length;e++)c[e]=arguments[e];return l(this,void 0,void 0,function(){var t,i,n,r,a,s,o,l,d;return v(this,function(e){switch(e.label){case 0:t=new Array,i=this.normalizeInputs.apply(this,m(c)),e.label=1;case 1:e.trys.push([1,6,7,8]),n=y(i),r=n.next(),e.label=2;case 2:return r.done?[3,5]:(a=r.value,[4,this.resetField(new x(a))]);case 3:void 0!==(s=e.sent())&&t.push(s),e.label=4;case 4:return r=n.next(),[3,2];case 5:return[3,8];case 6:return o=e.sent(),l={error:o},[3,8];case 7:try{r&&!r.done&&(d=n.return)&&d.call(n)}finally{if(l)throw l.error}return[7];case 8:return[2,t]}})})},q.prototype.resetField=function(n){return l(this,void 0,void 0,function(){var t,i;return v(this,function(e){switch(e.label){case 0:return t=n.name,void 0!==(i=this.fieldsStore.getField(t))?[3,1]:[3,3];case 1:return i.clearValidations(),[4,this.emitFieldDidResetEvent(i)];case 2:e.sent(),e.label=3;case 3:return[2,i]}})})},q.prototype.render=function(){var t=this;return f.createElement("form",p({ref:function(e){return t.form=e}},this.props))},q.childContextTypes={form:e.instanceOf(q).isRequired},q);function q(){var e=null!==A&&A.apply(this,arguments)||this;return e.form=null,e.fieldsStore=new I,e.fieldFeedbacksKeyCounter=0,e}var U,K=(r(z,U=f.PureComponent),z);function z(){return null!==U&&U.apply(this,arguments)||this}var J,G,H=(r(B,J=d(K)),B.prototype.getChildContext=function(){return{fieldFeedbacks:this}},B.prototype.computeFieldFeedbackKey=function(){return this.key+"."+this.fieldFeedbackKeyCounter++},B.prototype.addFieldFeedback=function(){return this.computeFieldFeedbackKey()},B.prototype.componentDidMount=function(){var e=this.context,t=e.form,i=e.fieldFeedbacks;t.fieldsStore.addField(this.fieldName),(i||t).addValidateFieldEventListener(this.validate)},B.prototype.componentWillUnmount=function(){var e=this.context,t=e.form,i=e.fieldFeedbacks;t.fieldsStore.removeField(this.fieldName),(i||t).removeValidateFieldEventListener(this.validate)},B.prototype._validate=function(t){return l(this,void 0,void 0,function(){return v(this,function(e){switch(e.label){case 0:return[4,this.emitValidateFieldEvent(t)];case 1:return[2,N(e.sent())]}})})},B.prototype.render=function(){var e=this.props.children;return void 0!==e?e:null},B.defaultProps={stop:"first-error"},B.contextTypes={form:e.instanceOf(j).isRequired,fieldFeedbacks:e.instanceOf(B)},B.childContextTypes={fieldFeedbacks:e.instanceOf(B).isRequired},B);function B(e,t){var i=J.call(this,e,t)||this;i.fieldFeedbackKeyCounter=0,i.validate=function(s){return l(i,void 0,void 0,function(){var t,i,n,r,a;return v(this,function(e){switch(e.label){case 0:return t=this.context,i=t.form,n=t.fieldFeedbacks,s.name!==this.fieldName?[3,3]:(a=i.fieldsStore.getField(this.fieldName),n&&("first"===n.props.stop&&a.hasFeedbacks(n.key)||"first-error"===n.props.stop&&a.hasErrors(n.key)||"first-warning"===n.props.stop&&a.hasWarnings(n.key)||"first-info"===n.props.stop&&a.hasInfos(n.key))?[3,3]:[3,1]);case 1:return[4,this._validate(s)];case 2:r=e.sent(),e.label=3;case 3:return[2,r]}})})};var n=t.form,r=t.fieldFeedbacks;if(i.key=r?r.computeFieldFeedbackKey():n.computeFieldFeedbacksKey(),r){if(i.fieldName=r.fieldName,void 0!==e.for)throw new Error("FieldFeedbacks cannot have a parent and a 'for' prop")}else{if(void 0===e.for)throw new Error("FieldFeedbacks cannot be without parent and without 'for' prop");i.fieldName=e.for}return i}(G=o.Status||(o.Status={}))[G.None=0]="None",G[G.Pending=1]="Pending",G[G.Rejected=2]="Rejected",G[G.Resolved=3]="Resolved";var Q,X=(r(Y,Q=f.PureComponent),Y);function Y(){return null!==Q&&Q.apply(this,arguments)||this}var Z,$=(r(ee,Z=d(X)),ee.prototype.getChildContext=function(){return{async:this}},ee.prototype.componentDidMount=function(){this.context.fieldFeedbacks.addValidateFieldEventListener(this.validate)},ee.prototype.componentWillUnmount=function(){this.context.fieldFeedbacks.removeValidateFieldEventListener(this.validate)},ee.prototype._validate=function(n){return l(this,void 0,void 0,function(){var t,i;return v(this,function(e){switch(e.label){case 0:this.setState({status:o.Status.Pending}),e.label=1;case 1:return e.trys.push([1,3,,4]),[4,this.props.promise(n.value)];case 2:return t=e.sent(),this.setState({status:o.Status.Resolved,value:t}),[3,4];case 3:return i=e.sent(),this.setState({status:o.Status.Rejected,value:i}),[3,4];case 4:return[2,this.emitValidateFieldEvent(n)]}})})},ee.prototype.render=function(){var e=this.props,t=this.state,i=null;switch(t.status){case o.Status.None:break;case o.Status.Pending:e.pending&&(i=e.pending);break;case o.Status.Resolved:e.then&&(i=e.then(t.value));break;case o.Status.Rejected:e.catch&&(i=e.catch(t.value));break;default:console.assert(!1,"Unknown status: '"+t.status+"'")}return i},ee.contextTypes={form:e.instanceOf(j).isRequired,fieldFeedbacks:e.instanceOf(H).isRequired},ee.childContextTypes={async:e.instanceOf(ee).isRequired},ee);function ee(){var s=null!==Z&&Z.apply(this,arguments)||this;return s.state={status:o.Status.None},s.validate=function(e){var t,i=s.context,n=i.form,r=i.fieldFeedbacks,a=n.fieldsStore.getField(e.name);return"first"===r.props.stop&&a.hasFeedbacks(r.key)||"first-error"===r.props.stop&&a.hasErrors(r.key)||"first-warning"===r.props.stop&&a.hasWarnings(r.key)||"first-info"===r.props.stop&&a.hasInfos(r.key)?s.setState({status:o.Status.None}):t=s._validate(e),t},s}var te,ie=(r(ne,te=f.Component),ne.prototype.componentDidMount=function(){this.context.form.addFieldWillValidateEventListener(this.fieldWillValidate),this.context.form.addFieldDidValidateEventListener(this.fieldDidValidate),this.context.form.addFieldDidResetEventListener(this.fieldDidReset)},ne.prototype.componentWillUnmount=function(){this.context.form.removeFieldWillValidateEventListener(this.fieldWillValidate),this.context.form.removeFieldDidValidateEventListener(this.fieldDidValidate),this.context.form.removeFieldDidResetEventListener(this.fieldDidReset)},ne.prototype.render=function(){var e=this.props,t=e.style,i=h(e,["style"]);return this.state.fieldIsValid?f.createElement("span",p({},i,{style:p({display:"block"},t)})):null},ne.contextTypes={form:e.instanceOf(j).isRequired,fieldFeedbacks:e.instanceOf(H).isRequired},ne);function ne(){var t=null!==te&&te.apply(this,arguments)||this;return t.state={fieldIsValid:void 0},t.fieldWillValidate=function(e){e===t.context.fieldFeedbacks.fieldName&&t.setState({fieldIsValid:void 0})},t.fieldDidValidate=function(e){e.name===t.context.fieldFeedbacks.fieldName&&t.setState({fieldIsValid:e.isValid()})},t.fieldDidReset=function(e){e.name===t.context.fieldFeedbacks.fieldName&&t.setState({fieldIsValid:void 0})},t}var re,ae=(r(se,re=f.Component),se.prototype.componentDidMount=function(){var e=this.context,t=e.form,i=e.fieldFeedbacks,n=e.async;n?n.addValidateFieldEventListener(this.validate):i.addValidateFieldEventListener(this.validate),t.addFieldDidResetEventListener(this.fieldDidReset)},se.prototype.componentWillUnmount=function(){var e=this.context,t=e.form,i=e.fieldFeedbacks,n=e.async;n?n.removeValidateFieldEventListener(this.validate):i.removeValidateFieldEventListener(this.validate),t.removeFieldDidResetEventListener(this.fieldDidReset)},se.prototype.render=function(){var e=this.props,t=(e.when,e.error,e.warning,e.info,e.className),i=e.classes,n=e.style,r=e.children,a=h(e,["when","error","warning","info","className","classes","style","children"]),s=this.state,o=s.validation,l=s.validationMessage,d=i[o.type],c=void 0!==t?t+" "+d:d;if(o.type===L.WhenValid)return f.createElement(ie,p({"data-feedback":this.key,style:n,className:c},a),r);if(o.show){var u=void 0!==r?r:l;return f.createElement("span",p({"data-feedback":this.key,className:c,style:p({display:"block"},n)},a),u)}return null},se.defaultProps={when:function(){return!0},classes:{error:"error",warning:"warning",info:"info",whenValid:"when-valid"}},se.contextTypes={form:e.instanceOf(j).isRequired,fieldFeedbacks:e.instanceOf(H).isRequired,async:e.instanceOf($)},se);function se(e,t){var l=re.call(this,e,t)||this;l.validate=function(e){var t=l.props.when,i=l.context,n=i.form,r=i.fieldFeedbacks,a=n.fieldsStore.getField(e.name),s=p({},l.state.validation);if("first"===r.props.stop&&a.hasFeedbacks(r.key)||"first-error"===r.props.stop&&a.hasErrors(r.key)||"first-warning"===r.props.stop&&a.hasWarnings(r.key)||"first-info"===r.props.stop&&a.hasInfos(r.key))s.show=void 0;else if(s.show=!1,"function"==typeof t)s.show=t(e.value);else{if("string"!=typeof t)throw new TypeError("Invalid FieldFeedback 'when' type: "+typeof t);if("valid"===t)s.show=void 0;else{var o=e.validity;o.valid||("*"===t?s.show=!0:(o.badInput&&"badInput"===t||o.patternMismatch&&"patternMismatch"===t||o.rangeOverflow&&"rangeOverflow"===t||o.rangeUnderflow&&"rangeUnderflow"===t||o.stepMismatch&&"stepMismatch"===t||o.tooLong&&"tooLong"===t||o.tooShort&&"tooShort"===t||o.typeMismatch&&"typeMismatch"===t||o.valueMissing&&"valueMissing"===t)&&(s.show=!0))}}return a.addOrReplaceValidation(s),l.setState({validation:s,validationMessage:e.validationMessage}),s},l.fieldDidReset=function(e){e.name===l.context.fieldFeedbacks.fieldName&&l.setState(function(e){return{validation:p(p({},e.validation),{show:void 0}),validationMessage:""}})},l.key=t.fieldFeedbacks.addFieldFeedback();var i=e.error,n=e.warning,r=e.info,a=e.when,s=L.Error;if("valid"===a?s=L.WhenValid:n?s=L.Warning:r&&(s=L.Info),s===L.WhenValid&&(i||n||r))throw new Error('Cannot have an attribute (error, warning...) with FieldFeedback when="valid"');return l.state={validation:{key:l.key,type:s,show:void 0},validationMessage:""},l}var oe,le=(r(de,oe=f.Component),de.prototype.componentDidMount=function(){this.context.form.addFieldWillValidateEventListener(this.fieldWillValidate),this.context.form.addFieldDidValidateEventListener(this.fieldDidValidate),this.context.form.addFieldDidResetEventListener(this.fieldDidReset)},de.prototype.componentWillUnmount=function(){this.context.form.removeFieldWillValidateEventListener(this.fieldWillValidate),this.context.form.removeFieldDidValidateEventListener(this.fieldDidValidate),this.context.form.removeFieldDidResetEventListener(this.fieldDidReset)},de.prototype.fieldValidationStates=function(){var e=this.state.field,t=[];return void 0!==e&&("pending"===e?t.push("isPending"):(e.hasErrors()&&t.push("hasErrors"),e.hasWarnings()&&t.push("hasWarnings"),e.hasInfos()&&t.push("hasInfos"),e.isValid()&&t.push("isValid"))),t},de.prototype.render=function(){var e=this.props,t=e.innerRef,i=e.className,n=e.classes,r=h(e,["innerRef","className","classes"]),a=this.fieldValidationStates(),s=i;return a.forEach(function(e){var t=n[e];void 0!==t&&(void 0!==s?s+=" "+t:s=t)}),f.createElement("input",p({ref:t},r,{className:s}))},de.contextTypes={form:e.instanceOf(j).isRequired},de.defaultProps={classes:{isPending:"is-pending",hasErrors:"has-errors",hasWarnings:"has-warnings",hasInfos:"has-infos",isValid:"is-valid"}},de);function de(){var t=null!==oe&&oe.apply(this,arguments)||this;return t.state={field:void 0},t.fieldWillValidate=function(e){e===t.props.name&&t.setState({field:"pending"})},t.fieldDidValidate=function(e){e.name===t.props.name&&t.setState({field:e})},t.fieldDidReset=function(e){e.name===t.props.name&&t.setState({field:void 0})},t}o.Async=$,o.EventEmitter=a,o.Field=R,o.FieldDidResetEvent=b,o.FieldDidValidateEvent=F,o.FieldFeedback=ae,o.FieldFeedbackType=L,o.FieldFeedbackWhenValid=ie,o.FieldFeedbacks=H,o.FieldWillValidateEvent=c,o.FieldsStore=I,o.FormWithConstraints=j,o.IValidityState=g,o.Input=le,o.InputElement=x,o.ValidateFieldEvent=s,o.deepForEach=function i(e,n){f.Children.forEach(e,function(e){var t=e;t.props&&t.props.children&&"object"==typeof t.props.children&&i(t.props.children,n),n(t)})},o.isHTMLInput=V,o.withFieldDidResetEventEmitter=w,o.withFieldDidValidateEventEmitter=E,o.withFieldWillValidateEventEmitter=u,o.withValidateFieldEventEmitter=d,Object.defineProperty(o,"__esModule",{value:!0})});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("prop-types")):"function"==typeof define&&define.amd?define(["exports","react","prop-types"],t):t((e=e||self).ReactFormWithConstraints={},e.React,e.PropTypes)}(this,function(o,f,e){"use strict";var n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i])})(e,t)};function r(e,t){function i(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(i.prototype=t.prototype,new i)}var p=function(){return(p=Object.assign||function(e){for(var t,i=1,n=arguments.length;i<n;i++)for(var r in t=arguments[i])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)};function h(e,t){var i={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(i[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(n=Object.getOwnPropertySymbols(e);r<n.length;r++)t.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(e,n[r])&&(i[n[r]]=e[n[r]])}return i}function l(a,s,o,l){return new(o=o||Promise)(function(e,t){function i(e){try{r(l.next(e))}catch(e){t(e)}}function n(e){try{r(l.throw(e))}catch(e){t(e)}}function r(t){t.done?e(t.value):new o(function(e){e(t.value)}).then(i,n)}r((l=l.apply(a,s||[])).next())})}function v(i,n){var r,a,s,e,o={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return e={next:t(0),throw:t(1),return:t(2)},"function"==typeof Symbol&&(e[Symbol.iterator]=function(){return this}),e;function t(t){return function(e){return function(t){if(r)throw new TypeError("Generator is already executing.");for(;o;)try{if(r=1,a&&(s=2&t[0]?a.return:t[0]?a.throw||((s=a.return)&&s.call(a),0):a.next)&&!(s=s.call(a,t[1])).done)return s;switch(a=0,s&&(t=[2&t[0],s.value]),t[0]){case 0:case 1:s=t;break;case 4:return o.label++,{value:t[1],done:!1};case 5:o.label++,a=t[1],t=[0];continue;case 7:t=o.ops.pop(),o.trys.pop();continue;default:if(!(s=0<(s=o.trys).length&&s[s.length-1])&&(6===t[0]||2===t[0])){o=0;continue}if(3===t[0]&&(!s||t[1]>s[0]&&t[1]<s[3])){o.label=t[1];break}if(6===t[0]&&o.label<s[1]){o.label=s[1],s=t;break}if(s&&o.label<s[2]){o.label=s[2],o.ops.push(t);break}s[2]&&o.ops.pop(),o.trys.pop();continue}t=n.call(i,o)}catch(e){t=[6,e],a=0}finally{r=s=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}([t,e])}}}function y(e){var t="function"==typeof Symbol&&e[Symbol.iterator],i=0;return t?t.call(e):{next:function(){return e&&i>=e.length&&(e=void 0),{value:e&&e[i++],done:!e}}}}function i(e,t){var i="function"==typeof Symbol&&e[Symbol.iterator];if(!i)return e;var n,r,a=i.call(e),s=[];try{for(;(void 0===t||0<t--)&&!(n=a.next()).done;)s.push(n.value)}catch(e){r={error:e}}finally{try{n&&!n.done&&(i=a.return)&&i.call(a)}finally{if(r)throw r.error}}return s}function m(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(i(arguments[t]));return e}var a=(t.prototype.emit=function(u){for(var f=[],e=1;e<arguments.length;e++)f[e-1]=arguments[e];return l(this,void 0,void 0,function(){var t,i,n,r,a,s,o,l,d,c;return v(this,function(e){switch(e.label){case 0:if(t=this.listeners.get(u),i=new Array,void 0===t)return[3,8];console.assert(0<t.length,"No listener for event '"+u+"'"),e.label=1;case 1:e.trys.push([1,6,7,8]),n=y(t),r=n.next(),e.label=2;case 2:return r.done?[3,5]:(a=r.value,o=(s=i).push,[4,a.apply(void 0,m(f))]);case 3:o.apply(s,[e.sent()]),e.label=4;case 4:return r=n.next(),[3,2];case 5:return[3,8];case 6:return l=e.sent(),d={error:l},[3,8];case 7:try{r&&!r.done&&(c=n.return)&&c.call(n)}finally{if(d)throw d.error}return[7];case 8:return[2,i]}})})},t.prototype.addListener=function(e,t){this.listeners.has(e)||this.listeners.set(e,[]);var i=this.listeners.get(e);console.assert(-1===i.indexOf(t),"Listener already added for event '"+e+"'"),i.push(t)},t.prototype.removeListener=function(e,t){var i=this.listeners.get(e);console.assert(void 0!==i,"Unknown event '"+e+"'");var n=i.lastIndexOf(t);console.assert(-1<n,"Listener not found for event '"+e+"'"),i.splice(n,1),0===i.length&&this.listeners.delete(e)},t);function t(){this.listeners=new Map}var s="VALIDATE_FIELD_EVENT";function d(e){return r(t,i=e),t.prototype.emitValidateFieldEvent=function(e){return this.validateFieldEventEmitter.emit(s,e)},t.prototype.addValidateFieldEventListener=function(e){this.validateFieldEventEmitter.addListener(s,e)},t.prototype.removeValidateFieldEventListener=function(e){this.validateFieldEventEmitter.removeListener(s,e)},t;function t(){var e=null!==i&&i.apply(this,arguments)||this;return e.validateFieldEventEmitter=new a,e}var i}var c="FIELD_WILL_VALIDATE_EVENT";function u(e){return r(t,i=e),t.prototype.emitFieldWillValidateEvent=function(e){return this.fieldWillValidateEventEmitter.emit(c,e)},t.prototype.addFieldWillValidateEventListener=function(e){this.fieldWillValidateEventEmitter.addListener(c,e)},t.prototype.removeFieldWillValidateEventListener=function(e){this.fieldWillValidateEventEmitter.removeListener(c,e)},t;function t(){var e=null!==i&&i.apply(this,arguments)||this;return e.fieldWillValidateEventEmitter=new a,e}var i}var F="FIELD_DID_VALIDATE_EVENT";function E(e){return r(t,i=e),t.prototype.emitFieldDidValidateEvent=function(e){return this.fieldDidValidateEventEmitter.emit(F,e)},t.prototype.addFieldDidValidateEventListener=function(e){this.fieldDidValidateEventEmitter.addListener(F,e)},t.prototype.removeFieldDidValidateEventListener=function(e){this.fieldDidValidateEventEmitter.removeListener(F,e)},t;function t(){var e=null!==i&&i.apply(this,arguments)||this;return e.fieldDidValidateEventEmitter=new a,e}var i}var b="FIELD_DID_RESET_EVENT";function w(e){return r(t,i=e),t.prototype.emitFieldDidResetEvent=function(e){return this.fieldDidResetEventEmitter.emit(b,e)},t.prototype.addFieldDidResetEventListener=function(e){this.fieldDidResetEventEmitter.addListener(b,e)},t.prototype.removeFieldDidResetEventListener=function(e){this.fieldDidResetEventEmitter.removeListener(b,e)},t;function t(){var e=null!==i&&i.apply(this,arguments)||this;return e.fieldDidResetEventEmitter=new a,e}var i}var g=function(e){this.badInput=e.badInput,this.customError=e.customError,this.patternMismatch=e.patternMismatch,this.rangeOverflow=e.rangeOverflow,this.rangeUnderflow=e.rangeUnderflow,this.stepMismatch=e.stepMismatch,this.tooLong=e.tooLong,this.tooShort=e.tooShort,this.typeMismatch=e.typeMismatch,this.valid=e.valid,this.valueMissing=e.valueMissing};function V(e){return void 0===e.props}var k,D,x=function(e){V(e)?(e=e,this.name=e.name,this.type=e.type,this.value=e.value,this.validity=new g(e.validity),this.validationMessage=e.validationMessage):(e=e,this.name=e.props.name,this.type=void 0,this.value=e.props.value,this.validity=void 0,this.validationMessage=void 0)};(D=k=k||{}).Error="error",D.Warning="warning",D.Info="info",D.WhenValid="whenValid";var L=k;var S,R=(O.prototype.addOrReplaceValidation=function(t){var e=this.validations.findIndex(function(e){return e.key===t.key});-1<e?this.validations[e]=t:this.validations.push(t)},O.prototype.clearValidations=function(){!function(e){for(;e.length;)e.pop()}(this.validations)},O.prototype.hasFeedbacksOfType=function(t,i){return this.validations.some(function(e){return(void 0===i||e.key.startsWith(i+"."))&&e.type===t&&!0===e.show})},O.prototype.hasErrors=function(e){return this.hasFeedbacksOfType(L.Error,e)},O.prototype.hasWarnings=function(e){return this.hasFeedbacksOfType(L.Warning,e)},O.prototype.hasInfos=function(e){return this.hasFeedbacksOfType(L.Info,e)},O.prototype.hasFeedbacks=function(e){return this.hasErrors(e)||this.hasWarnings(e)||this.hasInfos(e)},O.prototype.isValid=function(){return!this.hasErrors()},O);function O(e){this.name=e,this.validations=[]}(S=o.FieldEvent||(o.FieldEvent={})).Added="FIELD_ADDED",S.Removed="FIELD_REMOVED";var W,I=(r(M,W=a),M.prototype.getField=function(t){var e=this.fields.filter(function(e){return e.name===t});return 1===e.length?e[0]:void 0},M.prototype.addField=function(t){var e=this.fields.filter(function(e){return e.name===t});if(console.assert(0===e.length||1===e.length,"Cannot have more than 1 field matching '"+t+"'"),0===e.length){var i=new R(t);this.fields.push(i),this.emit(o.FieldEvent.Added,i)}},M.prototype.removeField=function(t){var e=this.fields.filter(function(e){return e.name===t}),i=this.fields.indexOf(e[0]);-1<i&&(this.fields.splice(i,1),this.emit(o.FieldEvent.Removed,t))},M.prototype.isValid=function(){return this.fields.every(function(e){return e.isValid()})},M.prototype.hasFeedbacks=function(){return this.fields.some(function(e){return e.hasFeedbacks()})},M);function M(){var e=null!==W&&W.apply(this,arguments)||this;return e.fields=new Array,e}function N(e){return e.reduce(function(e,t){return e.concat(Array.isArray(t)?N(t):t)},[])}function _(e){return void 0!==e}var C,T=(r(P,C=f.PureComponent),P);function P(){return null!==C&&C.apply(this,arguments)||this}var A,j=(r(q,A=w(u(E(d(T))))),q.prototype.getChildContext=function(){return{form:this}},q.prototype.computeFieldFeedbacksKey=function(){return""+this.fieldFeedbacksKeyCounter++},q.prototype.validateFields=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return this._validateFields.apply(this,m([!0],e))},q.prototype.validateForm=function(){return this.validateFieldsWithoutFeedback()},q.prototype.validateFieldsWithoutFeedback=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return this._validateFields.apply(this,m([!1],e))},q.prototype._validateFields=function(c){for(var u=[],e=1;e<arguments.length;e++)u[e-1]=arguments[e];return l(this,void 0,void 0,function(){var t,i,n,r,a,s,o,l,d;return v(this,function(e){switch(e.label){case 0:t=new Array,i=this.normalizeInputs.apply(this,m(u)),e.label=1;case 1:e.trys.push([1,6,7,8]),n=y(i),r=n.next(),e.label=2;case 2:return r.done?[3,5]:(a=r.value,[4,this.validateField(c,new x(a))]);case 3:void 0!==(s=e.sent())&&(s.element=a,t.push(s)),e.label=4;case 4:return r=n.next(),[3,2];case 5:return[3,8];case 6:return o=e.sent(),l={error:o},[3,8];case 7:try{r&&!r.done&&(d=n.return)&&d.call(n)}finally{if(l)throw l.error}return[7];case 8:return[2,t]}})})},q.prototype.validateField=function(r,a){return l(this,void 0,void 0,function(){var t,i,n;return v(this,function(e){switch(e.label){case 0:return t=a.name,void 0!==(i=this.fieldsStore.getField(t))?[3,1]:[3,3];case 1:return!r&&i.hasFeedbacks()?[3,3]:(i.clearValidations(),this.emitFieldWillValidateEvent(t),[4,this.emitValidateFieldEvent(a)]);case 2:n=e.sent(),console.assert(JSON.stringify(N(n).filter(_))===JSON.stringify(i.validations),"FieldsStore does not match emitValidateFieldEvent() result, did the user changed the input rapidly?"),this.emitFieldDidValidateEvent(i),e.label=3;case 3:return[2,i]}})})},q.prototype.normalizeInputs=function(){for(var e,r=this,t=[],i=0;i<arguments.length;i++)t[i]=arguments[i];return 0===t.length?(e=(e=m(this.form.querySelectorAll("[name]"))).filter(function(e){return void 0!==e.validity})).filter(function(e){return"checkbox"!==e.type&&"radio"!==e.type}).map(function(e){return e.name}).forEach(function(e,t,i){if(i.indexOf(e)!==t)throw new Error("Multiple elements matching '[name=\""+e+"\"]' inside the form")}):e=t.map(function(e){if("string"!=typeof e)return e;var t='[name="'+e+'"]',i=m(r.form.querySelectorAll(t));if(0<i.filter(function(e){return void 0===e.validity}).length)throw new Error("'"+t+"' should match an <input>, <select> or <textarea>");if(1<i.filter(function(e){return"checkbox"!==e.type&&"radio"!==e.type}).length)throw new Error("Multiple elements matching '"+t+"' inside the form");var n=i[0];if(void 0===n)throw new Error("Could not find field '"+t+"' inside the form");return n}),e},q.prototype.isValid=function(){return this.fieldsStore.isValid()},q.prototype.hasFeedbacks=function(){return this.fieldsStore.hasFeedbacks()},q.prototype.reset=function(){return this.resetFields()},q.prototype.resetFields=function(){for(var c=[],e=0;e<arguments.length;e++)c[e]=arguments[e];return l(this,void 0,void 0,function(){var t,i,n,r,a,s,o,l,d;return v(this,function(e){switch(e.label){case 0:t=new Array,i=this.normalizeInputs.apply(this,m(c)),e.label=1;case 1:e.trys.push([1,6,7,8]),n=y(i),r=n.next(),e.label=2;case 2:return r.done?[3,5]:(a=r.value,[4,this.resetField(new x(a))]);case 3:void 0!==(s=e.sent())&&t.push(s),e.label=4;case 4:return r=n.next(),[3,2];case 5:return[3,8];case 6:return o=e.sent(),l={error:o},[3,8];case 7:try{r&&!r.done&&(d=n.return)&&d.call(n)}finally{if(l)throw l.error}return[7];case 8:return[2,t]}})})},q.prototype.resetField=function(n){return l(this,void 0,void 0,function(){var t,i;return v(this,function(e){switch(e.label){case 0:return t=n.name,void 0!==(i=this.fieldsStore.getField(t))?[3,1]:[3,3];case 1:return i.clearValidations(),[4,this.emitFieldDidResetEvent(i)];case 2:e.sent(),e.label=3;case 3:return[2,i]}})})},q.prototype.render=function(){var t=this;return f.createElement("form",p({ref:function(e){return t.form=e}},this.props))},q.childContextTypes={form:e.instanceOf(q).isRequired},q);function q(){var e=null!==A&&A.apply(this,arguments)||this;return e.form=null,e.fieldsStore=new I,e.fieldFeedbacksKeyCounter=0,e}var U,K=(r(z,U=f.PureComponent),z);function z(){return null!==U&&U.apply(this,arguments)||this}var J,G,H=(r(B,J=d(K)),B.prototype.getChildContext=function(){return{fieldFeedbacks:this}},B.prototype.computeFieldFeedbackKey=function(){return this.key+"."+this.fieldFeedbackKeyCounter++},B.prototype.addFieldFeedback=function(){return this.computeFieldFeedbackKey()},B.prototype.componentDidMount=function(){var e=this.context,t=e.form,i=e.fieldFeedbacks;t.fieldsStore.addField(this.fieldName),(i||t).addValidateFieldEventListener(this.validate)},B.prototype.componentWillUnmount=function(){var e=this.context,t=e.form,i=e.fieldFeedbacks;t.fieldsStore.removeField(this.fieldName),(i||t).removeValidateFieldEventListener(this.validate)},B.prototype._validate=function(t){return l(this,void 0,void 0,function(){return v(this,function(e){switch(e.label){case 0:return[4,this.emitValidateFieldEvent(t)];case 1:return[2,N(e.sent())]}})})},B.prototype.render=function(){var e=this.props.children;return void 0!==e?e:null},B.defaultProps={stop:"first-error"},B.contextTypes={form:e.instanceOf(j).isRequired,fieldFeedbacks:e.instanceOf(B)},B.childContextTypes={fieldFeedbacks:e.instanceOf(B).isRequired},B);function B(e,t){var i=J.call(this,e,t)||this;i.fieldFeedbackKeyCounter=0,i.validate=function(s){return l(i,void 0,void 0,function(){var t,i,n,r,a;return v(this,function(e){switch(e.label){case 0:return(t=this.context,i=t.form,n=t.fieldFeedbacks,s.name!==this.fieldName)?[3,3]:(a=i.fieldsStore.getField(this.fieldName),n&&("first"===n.props.stop&&a.hasFeedbacks(n.key)||"first-error"===n.props.stop&&a.hasErrors(n.key)||"first-warning"===n.props.stop&&a.hasWarnings(n.key)||"first-info"===n.props.stop&&a.hasInfos(n.key))?[3,3]:[3,1]);case 1:return[4,this._validate(s)];case 2:r=e.sent(),e.label=3;case 3:return[2,r]}})})};var n=t.form,r=t.fieldFeedbacks;if(i.key=r?r.computeFieldFeedbackKey():n.computeFieldFeedbacksKey(),r){if(i.fieldName=r.fieldName,void 0!==e.for)throw new Error("FieldFeedbacks cannot have a parent and a 'for' prop")}else{if(void 0===e.for)throw new Error("FieldFeedbacks cannot be without parent and without 'for' prop");i.fieldName=e.for}return i}(G=o.Status||(o.Status={}))[G.None=0]="None",G[G.Pending=1]="Pending",G[G.Rejected=2]="Rejected",G[G.Resolved=3]="Resolved";var Q,X=(r(Y,Q=f.PureComponent),Y);function Y(){return null!==Q&&Q.apply(this,arguments)||this}var Z,$=(r(ee,Z=d(X)),ee.prototype.getChildContext=function(){return{async:this}},ee.prototype.componentDidMount=function(){this.context.fieldFeedbacks.addValidateFieldEventListener(this.validate)},ee.prototype.componentWillUnmount=function(){this.context.fieldFeedbacks.removeValidateFieldEventListener(this.validate)},ee.prototype._validate=function(n){return l(this,void 0,void 0,function(){var t,i;return v(this,function(e){switch(e.label){case 0:this.setState({status:o.Status.Pending}),e.label=1;case 1:return e.trys.push([1,3,,4]),[4,this.props.promise(n.value)];case 2:return t=e.sent(),this.setState({status:o.Status.Resolved,value:t}),[3,4];case 3:return i=e.sent(),this.setState({status:o.Status.Rejected,value:i}),[3,4];case 4:return[2,this.emitValidateFieldEvent(n)]}})})},ee.prototype.render=function(){var e=this.props,t=this.state,i=null;switch(t.status){case o.Status.None:break;case o.Status.Pending:e.pending&&(i=e.pending);break;case o.Status.Resolved:e.then&&(i=e.then(t.value));break;case o.Status.Rejected:e.catch&&(i=e.catch(t.value));break;default:console.assert(!1,"Unknown status: '"+t.status+"'")}return i},ee.contextTypes={form:e.instanceOf(j).isRequired,fieldFeedbacks:e.instanceOf(H).isRequired},ee.childContextTypes={async:e.instanceOf(ee).isRequired},ee);function ee(){var s=null!==Z&&Z.apply(this,arguments)||this;return s.state={status:o.Status.None},s.validate=function(e){var t,i=s.context,n=i.form,r=i.fieldFeedbacks,a=n.fieldsStore.getField(e.name);return"first"===r.props.stop&&a.hasFeedbacks(r.key)||"first-error"===r.props.stop&&a.hasErrors(r.key)||"first-warning"===r.props.stop&&a.hasWarnings(r.key)||"first-info"===r.props.stop&&a.hasInfos(r.key)?s.setState({status:o.Status.None}):t=s._validate(e),t},s}var te,ie=(r(ne,te=f.Component),ne.prototype.componentDidMount=function(){this.context.form.addFieldWillValidateEventListener(this.fieldWillValidate),this.context.form.addFieldDidValidateEventListener(this.fieldDidValidate),this.context.form.addFieldDidResetEventListener(this.fieldDidReset)},ne.prototype.componentWillUnmount=function(){this.context.form.removeFieldWillValidateEventListener(this.fieldWillValidate),this.context.form.removeFieldDidValidateEventListener(this.fieldDidValidate),this.context.form.removeFieldDidResetEventListener(this.fieldDidReset)},ne.prototype.render=function(){var e=this.props,t=e.style,i=h(e,["style"]);return this.state.fieldIsValid?f.createElement("span",p({},i,{style:p({display:"block"},t)})):null},ne.contextTypes={form:e.instanceOf(j).isRequired,fieldFeedbacks:e.instanceOf(H).isRequired},ne);function ne(){var t=null!==te&&te.apply(this,arguments)||this;return t.state={fieldIsValid:void 0},t.fieldWillValidate=function(e){e===t.context.fieldFeedbacks.fieldName&&t.setState({fieldIsValid:void 0})},t.fieldDidValidate=function(e){e.name===t.context.fieldFeedbacks.fieldName&&t.setState({fieldIsValid:e.isValid()})},t.fieldDidReset=function(e){e.name===t.context.fieldFeedbacks.fieldName&&t.setState({fieldIsValid:void 0})},t}var re,ae=(r(se,re=f.Component),se.prototype.componentDidMount=function(){var e=this.context,t=e.form,i=e.fieldFeedbacks,n=e.async;n?n.addValidateFieldEventListener(this.validate):i.addValidateFieldEventListener(this.validate),t.addFieldDidResetEventListener(this.fieldDidReset)},se.prototype.componentWillUnmount=function(){var e=this.context,t=e.form,i=e.fieldFeedbacks,n=e.async;n?n.removeValidateFieldEventListener(this.validate):i.removeValidateFieldEventListener(this.validate),t.removeFieldDidResetEventListener(this.fieldDidReset)},se.prototype.render=function(){var e=this.props,t=(e.when,e.error,e.warning,e.info,e.className),i=e.classes,n=e.style,r=e.children,a=h(e,["when","error","warning","info","className","classes","style","children"]),s=this.state,o=s.validation,l=s.validationMessage,d=i[o.type],c=void 0!==t?t+" "+d:d;if(o.type===L.WhenValid)return f.createElement(ie,p({"data-feedback":this.key,style:n,className:c},a),r);if(o.show){var u=void 0!==r?r:l;return f.createElement("span",p({"data-feedback":this.key,className:c,style:p({display:"block"},n)},a),u)}return null},se.defaultProps={when:function(){return!0},classes:{error:"error",warning:"warning",info:"info",whenValid:"when-valid"}},se.contextTypes={form:e.instanceOf(j).isRequired,fieldFeedbacks:e.instanceOf(H).isRequired,async:e.instanceOf($)},se);function se(e,t){var l=re.call(this,e,t)||this;l.validate=function(e){var t=l.props.when,i=l.context,n=i.form,r=i.fieldFeedbacks,a=n.fieldsStore.getField(e.name),s=p({},l.state.validation);if("first"===r.props.stop&&a.hasFeedbacks(r.key)||"first-error"===r.props.stop&&a.hasErrors(r.key)||"first-warning"===r.props.stop&&a.hasWarnings(r.key)||"first-info"===r.props.stop&&a.hasInfos(r.key))s.show=void 0;else if(s.show=!1,"function"==typeof t)s.show=t(e.value);else{if("string"!=typeof t)throw new TypeError("Invalid FieldFeedback 'when' type: "+typeof t);if("valid"===t)s.show=void 0;else{var o=e.validity;o.valid||("*"===t||o.badInput&&"badInput"===t||o.patternMismatch&&"patternMismatch"===t||o.rangeOverflow&&"rangeOverflow"===t||o.rangeUnderflow&&"rangeUnderflow"===t||o.stepMismatch&&"stepMismatch"===t||o.tooLong&&"tooLong"===t||o.tooShort&&"tooShort"===t||o.typeMismatch&&"typeMismatch"===t||o.valueMissing&&"valueMissing"===t)&&(s.show=!0)}}return a.addOrReplaceValidation(s),l.setState({validation:s,validationMessage:e.validationMessage}),s},l.fieldDidReset=function(e){e.name===l.context.fieldFeedbacks.fieldName&&l.setState(function(e){return{validation:p(p({},e.validation),{show:void 0}),validationMessage:""}})},l.key=t.fieldFeedbacks.addFieldFeedback();var i=e.error,n=e.warning,r=e.info,a=e.when,s=L.Error;if("valid"===a?s=L.WhenValid:n?s=L.Warning:r&&(s=L.Info),s===L.WhenValid&&(i||n||r))throw new Error('Cannot have an attribute (error, warning...) with FieldFeedback when="valid"');return l.state={validation:{key:l.key,type:s,show:void 0},validationMessage:""},l}var oe,le=(r(de,oe=f.Component),de.prototype.componentDidMount=function(){this.context.form.addFieldWillValidateEventListener(this.fieldWillValidate),this.context.form.addFieldDidValidateEventListener(this.fieldDidValidate),this.context.form.addFieldDidResetEventListener(this.fieldDidReset)},de.prototype.componentWillUnmount=function(){this.context.form.removeFieldWillValidateEventListener(this.fieldWillValidate),this.context.form.removeFieldDidValidateEventListener(this.fieldDidValidate),this.context.form.removeFieldDidResetEventListener(this.fieldDidReset)},de.prototype.fieldValidationStates=function(){var e=this.state.field,t=[];return void 0!==e&&("pending"===e?t.push("isPending"):(e.hasErrors()&&t.push("hasErrors"),e.hasWarnings()&&t.push("hasWarnings"),e.hasInfos()&&t.push("hasInfos"),e.isValid()&&t.push("isValid"))),t},de.prototype.render=function(){var e=this.props,t=e.innerRef,i=e.className,n=e.classes,r=h(e,["innerRef","className","classes"]),a=this.fieldValidationStates(),s=i;return a.forEach(function(e){var t=n[e];void 0!==t&&(void 0!==s?s+=" "+t:s=t)}),f.createElement("input",p({ref:t},r,{className:s}))},de.contextTypes={form:e.instanceOf(j).isRequired},de.defaultProps={classes:{isPending:"is-pending",hasErrors:"has-errors",hasWarnings:"has-warnings",hasInfos:"has-infos",isValid:"is-valid"}},de);function de(){var t=null!==oe&&oe.apply(this,arguments)||this;return t.state={field:void 0},t.fieldWillValidate=function(e){e===t.props.name&&t.setState({field:"pending"})},t.fieldDidValidate=function(e){e.name===t.props.name&&t.setState({field:e})},t.fieldDidReset=function(e){e.name===t.props.name&&t.setState({field:void 0})},t}o.Async=$,o.EventEmitter=a,o.Field=R,o.FieldDidResetEvent=b,o.FieldDidValidateEvent=F,o.FieldFeedback=ae,o.FieldFeedbackType=L,o.FieldFeedbackWhenValid=ie,o.FieldFeedbacks=H,o.FieldWillValidateEvent=c,o.FieldsStore=I,o.FormWithConstraints=j,o.IValidityState=g,o.Input=le,o.InputElement=x,o.ValidateFieldEvent=s,o.deepForEach=function i(e,n){f.Children.forEach(e,function(e){var t=e;t.props&&t.props.children&&"object"==typeof t.props.children&&i(t.props.children,n),n(t)})},o.isHTMLInput=V,o.withFieldDidResetEventEmitter=w,o.withFieldDidValidateEventEmitter=E,o.withFieldWillValidateEventEmitter=u,o.withValidateFieldEventEmitter=d,Object.defineProperty(o,"__esModule",{value:!0})});
//# sourceMappingURL=react-form-with-constraints.production.min.js.map
{
"name": "react-form-with-constraints",
"version": "0.14.1-beta.1",
"version": "0.14.1",
"repository": {

@@ -50,24 +50,24 @@ "type": "git",

"devDependencies": {
"@types/enzyme": "^3.10.3",
"@types/enzyme-adapter-react-16": "^1.0.5",
"@types/jest": "^24.0.18",
"@types/enzyme": "^3.10.5",
"@types/enzyme-adapter-react-16": "^1.0.6",
"@types/jest": "^25.1.3",
"@types/js-beautify": "^1.8.1",
"@types/jscodeshift": "^0.6.3",
"@types/prop-types": "^15.7.3",
"@types/react": "^16.9.2",
"enzyme": "^3.10.0",
"enzyme-adapter-react-16": "^1.14.0",
"jest": "^24.9.0",
"js-beautify": "^1.10.2",
"jscodeshift": "^0.6.4",
"react": "^16.9.0",
"react-dom": "^16.9.0",
"rollup": "^1.21.4",
"rollup-plugin-filesize": "^6.2.0",
"rollup-plugin-typescript2": "^0.24.2",
"rollup-plugin-uglify": "^6.0.3",
"ts-jest": "^24.1.0",
"typescript": "^3.6.3"
"@types/react": "^16.9.23",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.2",
"jest": "^25.1.0",
"js-beautify": "^1.10.3",
"jscodeshift": "^0.7.0",
"react": "^16.13.0",
"react-dom": "^16.13.0",
"rollup": "^1.31.1",
"rollup-plugin-filesize": "^6.2.1",
"rollup-plugin-typescript2": "^0.26.0",
"rollup-plugin-uglify": "^6.0.4",
"ts-jest": "^25.2.1",
"typescript": "^3.8.2"
},
"gitHead": "6cc2d55ced0b63e3ad7e5a8693415685bdebd272"
"gitHead": "0019a2aa13d803a9edb9dae87bd6422dc62e879b"
}

Sorry, the diff of this file is not supported yet

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