final-form
Advanced tools
Comparing version 4.16.1 to 4.16.2
@@ -334,3 +334,3 @@ 'use strict'; | ||
var version = "4.16.1"; | ||
var version = "4.16.2"; | ||
@@ -347,3 +347,3 @@ var configOptions = ['debug', 'initialValues', 'keepDirtyOnReinitialize', 'mutators', 'onSubmit', 'validate', 'validateOnBlur']; | ||
if (value && typeof value === 'object') { | ||
if (value && typeof value === 'object' && !(value instanceof Error)) { | ||
return hasAnyError(value); | ||
@@ -1023,3 +1023,3 @@ } | ||
}, | ||
data: {}, | ||
data: fieldConfig && fieldConfig.data || {}, | ||
focus: function focus() { | ||
@@ -1226,4 +1226,2 @@ return api.focus(name); | ||
} else { | ||
delete formState.submitErrors; | ||
delete formState.submitError; | ||
formState.submitFailed = false; | ||
@@ -1245,2 +1243,4 @@ formState.submitSucceeded = true; | ||
delete formState.submitErrors; | ||
delete formState.submitError; | ||
formState.submitting = true; | ||
@@ -1247,0 +1247,0 @@ formState.submitFailed = false; |
@@ -328,3 +328,3 @@ import _extends from '@babel/runtime/helpers/esm/extends'; | ||
var version = "4.16.1"; | ||
var version = "4.16.2"; | ||
@@ -341,3 +341,3 @@ var configOptions = ['debug', 'initialValues', 'keepDirtyOnReinitialize', 'mutators', 'onSubmit', 'validate', 'validateOnBlur']; | ||
if (value && typeof value === 'object') { | ||
if (value && typeof value === 'object' && !(value instanceof Error)) { | ||
return hasAnyError(value); | ||
@@ -1017,3 +1017,3 @@ } | ||
}, | ||
data: {}, | ||
data: fieldConfig && fieldConfig.data || {}, | ||
focus: function focus() { | ||
@@ -1220,4 +1220,2 @@ return api.focus(name); | ||
} else { | ||
delete formState.submitErrors; | ||
delete formState.submitError; | ||
formState.submitFailed = false; | ||
@@ -1239,2 +1237,4 @@ formState.submitSucceeded = true; | ||
delete formState.submitErrors; | ||
delete formState.submitError; | ||
formState.submitting = true; | ||
@@ -1241,0 +1241,0 @@ formState.submitFailed = false; |
@@ -364,3 +364,3 @@ (function (global, factory) { | ||
var version = "4.16.1"; | ||
var version = "4.16.2"; | ||
@@ -377,3 +377,3 @@ var configOptions = ['debug', 'initialValues', 'keepDirtyOnReinitialize', 'mutators', 'onSubmit', 'validate', 'validateOnBlur']; | ||
if (value && typeof value === 'object') { | ||
if (value && typeof value === 'object' && !(value instanceof Error)) { | ||
return hasAnyError(value); | ||
@@ -1053,3 +1053,3 @@ } | ||
}, | ||
data: {}, | ||
data: fieldConfig && fieldConfig.data || {}, | ||
focus: function focus() { | ||
@@ -1256,4 +1256,2 @@ return api.focus(name); | ||
} else { | ||
delete formState.submitErrors; | ||
delete formState.submitError; | ||
formState.submitFailed = false; | ||
@@ -1275,2 +1273,4 @@ formState.submitSucceeded = true; | ||
delete formState.submitErrors; | ||
delete formState.submitError; | ||
formState.submitting = true; | ||
@@ -1277,0 +1277,0 @@ formState.submitFailed = false; |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self)["final-form"]={})}(this,function(e){"use strict";function N(){return(N=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var i=arguments[t];for(var r in i)Object.prototype.hasOwnProperty.call(i,r)&&(e[r]=i[r])}return e}).apply(this,arguments)}function u(e){if(null==e||!e.length)return[];if("string"!=typeof e)throw new Error("toPath() expects a string");return e.split(/[.[\]]+/).filter(Boolean)}var R=function(e,t){for(var i=u(t),r=e,n=0;n<i.length;n++){var a=i[n];if(null==r||"object"!=typeof r||Array.isArray(r)&&isNaN(a))return;r=r[a]}return r};function S(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var i=e[Symbol.toPrimitive];if(void 0===i)return("string"===t?String:Number)(e);var r=i.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}(e,"string");return"symbol"==typeof t?t:String(t)}function h(e,t,i,r,n){if(t>=i.length)return r;var a=i[t];if(isNaN(a)){var u;if(null==e){var o,s=h(void 0,t+1,i,r,n);return void 0===s?void 0:((o={})[a]=s,o)}if(Array.isArray(e))throw new Error("Cannot set a non-numeric property on an array");var l=h(e[a],t+1,i,r,n);if(void 0!==l)return N({},e,((u={})[a]=l,u));var f=Object.keys(e).length;if(void 0===e[a]&&0===f)return;if(void 0!==e[a]&&f<=1)return isNaN(i[t-1])||n?void 0:{};e[a];return function(e,t){if(null==e)return{};var i,r,n={},a=Object.keys(e);for(r=0;r<a.length;r++)i=a[r],0<=t.indexOf(i)||(n[i]=e[i]);return n}(e,[a].map(S))}var d=Number(a);if(null==e){var c=h(void 0,t+1,i,r,n);if(void 0===c)return;var v=[];return v[d]=c,v}if(!Array.isArray(e))throw new Error("Cannot set a numeric property on an object");var b=h(e[d],t+1,i,r,n),m=[].concat(e);if(n&&void 0===b){if(m.splice(d,1),0===m.length)return}else m[d]=b;return m}function A(e,t,i,r){if(void 0===r&&(r=!1),null==e)throw new Error("Cannot call setIn() with "+String(e)+" state");if(null==t)throw new Error("Cannot call setIn() with "+String(t)+" key");return h(e,0,u(t),i,r)}var x="FINAL_FORM/form-error",I="FINAL_FORM/array-error";function P(e,t){var i=e.errors,r=e.initialValues,n=e.lastSubmittedValues,a=e.submitErrors,u=e.submitFailed,o=e.submitSucceeded,s=e.submitting,l=e.values,f=t.active,d=t.blur,c=t.change,v=t.data,b=t.focus,m=t.modified,S=t.name,h=t.touched,g=t.validating,y=t.visited,p=R(l,S),E=R(i,S);E&&E[I]&&(E=E[I]);var F=a&&R(a,S),O=r&&R(r,S),j=t.isEqual(O,p),k=!E&&!F;return{active:f,blur:d,change:c,data:v,dirty:!j,dirtySinceLastSubmit:!(!n||t.isEqual(R(n,S),p)),error:E,focus:b,initial:O,invalid:!k,length:Array.isArray(p)?p.length:void 0,modified:m,name:S,pristine:j,submitError:F,submitFailed:u,submitSucceeded:o,submitting:s,touched:h,valid:k,value:p,visited:y,validating:g}}var a=["active","data","dirty","dirtySinceLastSubmit","error","initial","invalid","length","modified","pristine","submitError","submitFailed","submitSucceeded","submitting","touched","valid","value","visited","validating"],L=function(e,t){if(e===t)return!0;if("object"!=typeof e||!e||"object"!=typeof t||!t)return!1;var i=Object.keys(e),r=Object.keys(t);if(i.length!==r.length)return!1;for(var n=Object.prototype.hasOwnProperty.bind(t),a=0;a<i.length;a++){var u=i[a];if(!n(u)||e[u]!==t[u])return!1}return!0};function o(t,i,r,n,e,a){var u=!1;return e.forEach(function(e){n[e]&&(t[e]=i[e],r&&(~a.indexOf(e)?L(i[e],r[e]):i[e]===r[e])||(u=!0))}),u}function q(e,t,i,r){var n={blur:e.blur,change:e.change,focus:e.focus,name:e.name};return o(n,e,t,i,a,s)||!t||r?n:void 0}var s=["data"],l=["active","dirty","dirtyFields","dirtySinceLastSubmit","error","errors","hasSubmitErrors","hasValidationErrors","initialValues","invalid","modified","pristine","submitting","submitError","submitErrors","submitFailed","submitSucceeded","touched","valid","validating","values","visited"],f=["touched","visited"];function z(e,t,i,r){var n={};return o(n,e,t,i,l,f)||!t||r?n:void 0}function C(r){var n,a;return function(){for(var e=arguments.length,t=new Array(e),i=0;i<e;i++)t[i]=arguments[i];return n&&t.length===n.length&&!t.some(function(e,t){return!L(n[t],e)})||(n=t,a=r.apply(void 0,t)),a}}function _(e){return!!e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof e.then}function U(e,t){return e===t}var B=function i(r){return Object.keys(r).some(function(e){var t=r[e];return t&&"object"==typeof t?i(t):void 0!==t})};function M(e,t,i,r,n,a){void 0===a&&(a=!1);var u=n(i,r,t,a);u&&e(u)}function D(e,r,n,a){var u=e.entries;Object.keys(u).forEach(function(e){var t=u[Number(e)];if(t){var i=t.subscription;M(t.subscriber,i,r,n,a)}})}e.ARRAY_ERROR=I,e.FORM_ERROR=x,e.configOptions=["debug","initialValues","keepDirtyOnReinitialize","mutators","onSubmit","validate","validateOnBlur"],e.createForm=function(e){if(!e)throw new Error("No config specified");e.debug;var u=e.destroyOnUnregister,a=e.keepDirtyOnReinitialize,t=e.initialValues,o=e.mutators,s=e.onSubmit,b=e.validate,l=e.validateOnBlur;if(!s)throw new Error("No onSubmit function specified");function m(t){return function(e){return delete E[t],e}}function f(e,t,i){var r=i(R(e.formState.values,t));e.formState.values=A(e.formState.values,t,r)||{}}function d(e,t,i){if(e.fields[t]){var r,n;e.fields=N({},e.fields,((r={})[i]=N({},e.fields[t],{name:i,lastFieldState:void 0}),r)),delete e.fields[t],e.fieldSubscribers=N({},e.fieldSubscribers,((n={})[i]=e.fieldSubscribers[t],n)),delete e.fieldSubscribers[t];var a=R(e.formState.values,t);e.formState.values=A(e.formState.values,t,void 0)||{},e.formState.values=A(e.formState.values,i,a),delete e.lastFormState}}function i(a){return function(){if(o){for(var e={formState:h.formState,fields:h.fields,fieldSubscribers:h.fieldSubscribers,lastFormState:h.lastFormState},t=arguments.length,i=new Array(t),r=0;r<t;r++)i[r]=arguments[r];var n=o[a](i,e,{changeValue:f,getIn:R,renameField:d,setIn:A,shallowEqual:L});return h.formState=e.formState,h.fields=e.fields,h.fieldSubscribers=e.fieldSubscribers,h.lastFormState=e.lastFormState,F(void 0,function(){O(),w()}),n}}}function S(r){return Object.keys(r.validators).reduce(function(e,t){var i=r.validators[Number(t)]();return i&&e.push(i),e},[])}function c(){Object.keys(h.fields).forEach(function(e){h.fields[e].touched=!0})}function v(){var e=h.fields,i=h.formState,t=h.lastFormState,r=N({},e),n=Object.keys(r),a=!1,u=n.reduce(function(e,t){return!r[t].isEqual(R(i.values,t),R(i.initialValues||{},t))&&(a=!0,e[t]=!0),e},{});i.pristine=!a,i.dirtySinceLastSubmit=!(!i.lastSubmittedValues||n.every(function(e){var t=i.lastSubmittedValues||{};return r[e].isEqual(R(i.values,e),R(t,e))})),i.valid=!(i.error||i.submitError||B(i.errors)||i.submitErrors&&B(i.submitErrors));var o=function(e){var t=e.active,i=e.dirtySinceLastSubmit,r=e.error,n=e.errors,a=e.initialValues,u=e.pristine,o=e.submitting,s=e.submitFailed,l=e.submitSucceeded,f=e.submitError,d=e.submitErrors,c=e.valid,v=e.validating,b=e.values;return{active:t,dirty:!u,dirtySinceLastSubmit:i,error:r,errors:n,hasSubmitErrors:!!(f||d&&B(d)),hasValidationErrors:!(!r&&!B(n)),invalid:!c,initialValues:a,pristine:u,submitting:o,submitFailed:s,submitSucceeded:l,submitError:f,submitErrors:d,valid:c,validating:0<v,values:b}}(i),s=n.reduce(function(e,t){return e.modified[t]=r[t].modified,e.touched[t]=r[t].touched,e.visited[t]=r[t].visited,e},{modified:{},touched:{},visited:{}}),l=s.modified,f=s.touched,d=s.visited;return o.dirtyFields=t&&L(t.dirtyFields,u)?t.dirtyFields:u,o.modified=t&&L(t.modified,l)?t.modified:l,o.touched=t&&L(t.touched,f)?t.touched:f,o.visited=t&&L(t.visited,d)?t.visited:d,t&&L(t,o)?t:o}var h={subscribers:{index:0,entries:{}},fieldSubscribers:{},fields:{},formState:{dirtySinceLastSubmit:!1,errors:{},initialValues:t&&N({},t),invalid:!1,pristine:!0,submitting:!1,submitFailed:!1,submitSucceeded:!1,valid:!0,validating:0,values:t?N({},t):{}},lastFormState:void 0},r=!1,g=!1,y=!1,p=0,E={},n=o?Object.keys(o).reduce(function(e,t){return e[t]=i(t),e},{}):{},F=function(e,t){if(g)return y=!0,void t();var o=h.fields,i=h.formState,s=N({},o),r=Object.keys(s);if(b||r.some(function(e){return S(s[e]).length})){var l=!1;if(e){var n=s[e];if(n){var a=n.validateFields;a&&(l=!0,r=a.length?a.concat(e):[e])}}var f={},d={},u=[].concat(function(e){var t=[];if(b){var i=b(N({},h.formState.values));if(_(i)){var r=p++,n=i.then(e).then(m(r));t.push(n),E[r]=n}else e(i)}return t}(function(e){f=e||{}}),r.reduce(function(e,t){return e.concat(function(n,a){var u,o=[],e=S(n);e.length&&(e.forEach(function(e){var t=e(R(h.formState.values,n.name),h.formState.values,3===e.length?P(h.formState,h.fields[n.name]):void 0);if(t&&_(t)){var i=p++;n.validating=!0;var r=t.then(function(e){n.validating=!1,a(e)}).then(m(i));o.push(r),E[i]=r}else u||(u=t)}),a(u));return o}(o[t],function(e){d[t]=e}))},[])),c=function(){function e(a){r.forEach(function(e){if(o[e]){var t=R(f,e),i=R(u,e),r=S(s[e]).length,n=d[e];a(e,r&&n||b&&t||(t||l?void 0:i))}})}var u=N({},l?i.errors:{},f);e(function(e,t){u=A(u,e,t)||{}}),e(function(e,t){if(t&&t[I]){var i=R(u,e),r=[].concat(i);r[I]=t[I],u=A(u,e,r)}}),L(i.errors,u)||(i.errors=u),i.error=f[x]};if(c(),u.length){h.formState.validating++,t();var v=function(){h.formState.validating--,c(),t()};Promise.all(u).then(v,v)}else t()}else t()},O=function(e){if(!r&&!g){var t=h.fields,a=h.fieldSubscribers,u=h.formState,o=N({},t);Object.keys(o).forEach(function(e){var t=o[e],i=P(u,t),r=t.lastFieldState;if(!L(i,r)){t.lastFieldState=i;var n=a[e];n&&D(n,i,r,q)}})}},j=!1,k=!1,w=function e(){if(j)k=!0;else{if(j=!0,!r&&!g){var t=h.lastFormState,i=v();i!==t&&(h.lastFormState=i,D(h.subscribers,i,t,z))}j=!1,k&&(k=!1,e())}};F(void 0,function(){});var V={batch:function(e){r=!0,e(),r=!1,O(),w()},blur:function(e){var t=h.fields,i=h.formState,r=t[e];r&&(delete i.active,t[e]=N({},r,{active:!1,touched:!0}),l?F(e,function(){O(),w()}):(O(),w()))},change:function(e,t){var i=h.fields,r=h.formState;if(R(r.values,e)!==t){f(h,e,function(){return t});var n=i[e];n&&(i[e]=N({},n,{modified:!0})),l?(O(),w()):F(e,function(){O(),w()})}},get destroyOnUnregister(){return!!u},set destroyOnUnregister(e){u=e},focus:function(e){var t=h.fields[e];t&&!t.active&&(h.formState.active=e,t.active=!0,t.visited=!0,O(),w())},mutators:n,getFieldState:function(e){var t=h.fields[e];return t&&t.lastFieldState},getRegisteredFields:function(){return Object.keys(h.fields)},getState:function(){return v()},initialize:function(e){var t=h.fields,i=h.formState,r=N({},t),n="function"==typeof e?e(i.values):e;a||(i.values=n),Object.keys(r).forEach(function(e){var t=r[e];t.modified=!1,t.touched=!1,t.visited=!1,!a||t.isEqual(R(i.values,e),R(i.initialValues||{},e))&&(i.values=A(i.values,e,R(n,e)))}),i.initialValues=n,F(void 0,function(){O(),w()})},isValidationPaused:function(){return g},pauseValidation:function(){g=!0},registerField:function(t,i,r,e){void 0===r&&(r={}),h.fieldSubscribers[t]||(h.fieldSubscribers[t]={index:0,entries:{}});var n=h.fieldSubscribers[t].index++;h.fieldSubscribers[t].entries[n]={subscriber:C(i),subscription:r},h.fields[t]||(h.fields[t]={active:!1,afterSubmit:e&&e.afterSubmit,beforeSubmit:e&&e.beforeSubmit,blur:function(){return V.blur(t)},change:function(e){return V.change(t,e)},data:{},focus:function(){return V.focus(t)},isEqual:e&&e.isEqual||U,lastFieldState:void 0,modified:!1,name:t,touched:!1,valid:!0,validateFields:e&&e.validateFields,validators:{},validating:!1,visited:!1}),e&&(e.getValidator&&(h.fields[t].validators[n]=e.getValidator),void 0!==e.initialValue&&(h.formState.initialValues=A(h.formState.initialValues||{},t,e.initialValue),h.formState.values=A(h.formState.values,t,e.initialValue)),void 0!==e.defaultValue&&(h.formState.values=A(h.formState.values,t,e.defaultValue)));var a=!1;return F(void 0,function(){w(),a||function(){var e=P(h.formState,h.fields[t]);M(i,r,e,void 0,q,!0),h.fields[t].lastFieldState=e,a=!0}(),O()}),function(){delete h.fields[t].validators[n],delete h.fieldSubscribers[t].entries[n],Object.keys(h.fieldSubscribers[t].entries).length||(delete h.fieldSubscribers[t],delete h.fields[t],h.formState.errors=A(h.formState.errors,t,void 0)||{},u&&(h.formState.values=A(h.formState.values,t,void 0,!0)||{})),F(void 0,function(){O(),w()})}},reset:function(e){if(void 0===e&&(e=h.formState.initialValues),h.formState.submitting)throw Error("Cannot reset() in onSubmit(), use setTimeout(form.reset)");h.formState.submitFailed=!1,h.formState.submitSucceeded=!1,delete h.formState.submitError,delete h.formState.submitErrors,delete h.formState.lastSubmittedValues,V.initialize(e||{})},resumeValidation:function(){g=!1,y&&F(void 0,function(){O(),w()}),y=!1},setConfig:function(e,t){switch(e){case"debug":t;break;case"destroyOnUnregister":u=t;break;case"initialValues":V.initialize(t);break;case"keepDirtyOnReinitialize":a=t;break;case"mutators":(o=t)?(Object.keys(n).forEach(function(e){e in t||delete n[e]}),Object.keys(t).forEach(function(e){n[e]=i(e)})):Object.keys(n).forEach(function(e){delete n[e]});break;case"onSubmit":s=t;break;case"validate":b=t,F(void 0,function(){O(),w()});break;case"validateOnBlur":l=t;break;default:throw new Error("Unrecognised option "+e)}},submit:function(){var t=h.formState;if(!t.submitting){if(h.formState.error||B(h.formState.errors))return c(),h.formState.submitFailed=!0,w(),void O();var e=Object.keys(E);if(e.length)Promise.all(e.reduce(function(e,t){return e.push(E[Number(t)]),e},[])).then(V.submit,V.submit);else if(!Object.keys(h.fields).find(function(e){return h.fields[e].beforeSubmit&&!1===h.fields[e].beforeSubmit()})){var i,r=!1,n=function(e){return t.submitting=!1,e&&B(e)?(t.submitFailed=!0,t.submitSucceeded=!1,t.submitErrors=e,t.submitError=e[x],c()):(delete t.submitErrors,delete t.submitError,t.submitFailed=!1,t.submitSucceeded=!0,Object.keys(h.fields).forEach(function(e){return h.fields[e].afterSubmit&&h.fields[e].afterSubmit()})),w(),O(),r=!0,i&&i(e),e};t.submitting=!0,t.submitFailed=!1,t.submitSucceeded=!1,t.lastSubmittedValues=N({},t.values);var a=s(t.values,V,n);if(!r){if(a&&_(a))return w(),O(),a.then(n,function(e){throw n(),e});if(3<=s.length)return w(),O(),new Promise(function(e){i=e});n(a)}}}},subscribe:function(e,t){if(!e)throw new Error("No callback given.");if(!t)throw new Error("No subscription provided. What values do you want to listen to?");var i=C(e),r=h.subscribers,n=h.lastFormState,a=r.index++;r.entries[a]={subscriber:i,subscription:t};var u=v();return u!==n&&(h.lastFormState=u),M(i,t,u,u,z,!0),function(){delete r.entries[a]}}};return V},e.fieldSubscriptionItems=a,e.formSubscriptionItems=l,e.getIn=R,e.setIn=A,e.version="4.16.1",Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self)["final-form"]={})}(this,function(e){"use strict";function N(){return(N=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var i=arguments[t];for(var r in i)Object.prototype.hasOwnProperty.call(i,r)&&(e[r]=i[r])}return e}).apply(this,arguments)}function u(e){if(null==e||!e.length)return[];if("string"!=typeof e)throw new Error("toPath() expects a string");return e.split(/[.[\]]+/).filter(Boolean)}var R=function(e,t){for(var i=u(t),r=e,n=0;n<i.length;n++){var a=i[n];if(null==r||"object"!=typeof r||Array.isArray(r)&&isNaN(a))return;r=r[a]}return r};function S(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var i=e[Symbol.toPrimitive];if(void 0===i)return("string"===t?String:Number)(e);var r=i.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}(e,"string");return"symbol"==typeof t?t:String(t)}function h(e,t,i,r,n){if(t>=i.length)return r;var a=i[t];if(isNaN(a)){var u;if(null==e){var o,s=h(void 0,t+1,i,r,n);return void 0===s?void 0:((o={})[a]=s,o)}if(Array.isArray(e))throw new Error("Cannot set a non-numeric property on an array");var l=h(e[a],t+1,i,r,n);if(void 0!==l)return N({},e,((u={})[a]=l,u));var f=Object.keys(e).length;if(void 0===e[a]&&0===f)return;if(void 0!==e[a]&&f<=1)return isNaN(i[t-1])||n?void 0:{};e[a];return function(e,t){if(null==e)return{};var i,r,n={},a=Object.keys(e);for(r=0;r<a.length;r++)i=a[r],0<=t.indexOf(i)||(n[i]=e[i]);return n}(e,[a].map(S))}var d=Number(a);if(null==e){var c=h(void 0,t+1,i,r,n);if(void 0===c)return;var v=[];return v[d]=c,v}if(!Array.isArray(e))throw new Error("Cannot set a numeric property on an object");var b=h(e[d],t+1,i,r,n),m=[].concat(e);if(n&&void 0===b){if(m.splice(d,1),0===m.length)return}else m[d]=b;return m}function A(e,t,i,r){if(void 0===r&&(r=!1),null==e)throw new Error("Cannot call setIn() with "+String(e)+" state");if(null==t)throw new Error("Cannot call setIn() with "+String(t)+" key");return h(e,0,u(t),i,r)}var x="FINAL_FORM/form-error",I="FINAL_FORM/array-error";function P(e,t){var i=e.errors,r=e.initialValues,n=e.lastSubmittedValues,a=e.submitErrors,u=e.submitFailed,o=e.submitSucceeded,s=e.submitting,l=e.values,f=t.active,d=t.blur,c=t.change,v=t.data,b=t.focus,m=t.modified,S=t.name,h=t.touched,g=t.validating,y=t.visited,p=R(l,S),E=R(i,S);E&&E[I]&&(E=E[I]);var F=a&&R(a,S),O=r&&R(r,S),j=t.isEqual(O,p),k=!E&&!F;return{active:f,blur:d,change:c,data:v,dirty:!j,dirtySinceLastSubmit:!(!n||t.isEqual(R(n,S),p)),error:E,focus:b,initial:O,invalid:!k,length:Array.isArray(p)?p.length:void 0,modified:m,name:S,pristine:j,submitError:F,submitFailed:u,submitSucceeded:o,submitting:s,touched:h,valid:k,value:p,visited:y,validating:g}}var a=["active","data","dirty","dirtySinceLastSubmit","error","initial","invalid","length","modified","pristine","submitError","submitFailed","submitSucceeded","submitting","touched","valid","value","visited","validating"],L=function(e,t){if(e===t)return!0;if("object"!=typeof e||!e||"object"!=typeof t||!t)return!1;var i=Object.keys(e),r=Object.keys(t);if(i.length!==r.length)return!1;for(var n=Object.prototype.hasOwnProperty.bind(t),a=0;a<i.length;a++){var u=i[a];if(!n(u)||e[u]!==t[u])return!1}return!0};function o(t,i,r,n,e,a){var u=!1;return e.forEach(function(e){n[e]&&(t[e]=i[e],r&&(~a.indexOf(e)?L(i[e],r[e]):i[e]===r[e])||(u=!0))}),u}function q(e,t,i,r){var n={blur:e.blur,change:e.change,focus:e.focus,name:e.name};return o(n,e,t,i,a,s)||!t||r?n:void 0}var s=["data"],l=["active","dirty","dirtyFields","dirtySinceLastSubmit","error","errors","hasSubmitErrors","hasValidationErrors","initialValues","invalid","modified","pristine","submitting","submitError","submitErrors","submitFailed","submitSucceeded","touched","valid","validating","values","visited"],f=["touched","visited"];function z(e,t,i,r){var n={};return o(n,e,t,i,l,f)||!t||r?n:void 0}function C(r){var n,a;return function(){for(var e=arguments.length,t=new Array(e),i=0;i<e;i++)t[i]=arguments[i];return n&&t.length===n.length&&!t.some(function(e,t){return!L(n[t],e)})||(n=t,a=r.apply(void 0,t)),a}}function _(e){return!!e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof e.then}function U(e,t){return e===t}var B=function i(r){return Object.keys(r).some(function(e){var t=r[e];return!t||"object"!=typeof t||t instanceof Error?void 0!==t:i(t)})};function M(e,t,i,r,n,a){void 0===a&&(a=!1);var u=n(i,r,t,a);u&&e(u)}function D(e,r,n,a){var u=e.entries;Object.keys(u).forEach(function(e){var t=u[Number(e)];if(t){var i=t.subscription;M(t.subscriber,i,r,n,a)}})}e.ARRAY_ERROR=I,e.FORM_ERROR=x,e.configOptions=["debug","initialValues","keepDirtyOnReinitialize","mutators","onSubmit","validate","validateOnBlur"],e.createForm=function(e){if(!e)throw new Error("No config specified");e.debug;var u=e.destroyOnUnregister,a=e.keepDirtyOnReinitialize,t=e.initialValues,o=e.mutators,s=e.onSubmit,b=e.validate,l=e.validateOnBlur;if(!s)throw new Error("No onSubmit function specified");function m(t){return function(e){return delete E[t],e}}function f(e,t,i){var r=i(R(e.formState.values,t));e.formState.values=A(e.formState.values,t,r)||{}}function d(e,t,i){if(e.fields[t]){var r,n;e.fields=N({},e.fields,((r={})[i]=N({},e.fields[t],{name:i,lastFieldState:void 0}),r)),delete e.fields[t],e.fieldSubscribers=N({},e.fieldSubscribers,((n={})[i]=e.fieldSubscribers[t],n)),delete e.fieldSubscribers[t];var a=R(e.formState.values,t);e.formState.values=A(e.formState.values,t,void 0)||{},e.formState.values=A(e.formState.values,i,a),delete e.lastFormState}}function i(a){return function(){if(o){for(var e={formState:h.formState,fields:h.fields,fieldSubscribers:h.fieldSubscribers,lastFormState:h.lastFormState},t=arguments.length,i=new Array(t),r=0;r<t;r++)i[r]=arguments[r];var n=o[a](i,e,{changeValue:f,getIn:R,renameField:d,setIn:A,shallowEqual:L});return h.formState=e.formState,h.fields=e.fields,h.fieldSubscribers=e.fieldSubscribers,h.lastFormState=e.lastFormState,F(void 0,function(){O(),w()}),n}}}function S(r){return Object.keys(r.validators).reduce(function(e,t){var i=r.validators[Number(t)]();return i&&e.push(i),e},[])}function c(){Object.keys(h.fields).forEach(function(e){h.fields[e].touched=!0})}function v(){var e=h.fields,i=h.formState,t=h.lastFormState,r=N({},e),n=Object.keys(r),a=!1,u=n.reduce(function(e,t){return!r[t].isEqual(R(i.values,t),R(i.initialValues||{},t))&&(a=!0,e[t]=!0),e},{});i.pristine=!a,i.dirtySinceLastSubmit=!(!i.lastSubmittedValues||n.every(function(e){var t=i.lastSubmittedValues||{};return r[e].isEqual(R(i.values,e),R(t,e))})),i.valid=!(i.error||i.submitError||B(i.errors)||i.submitErrors&&B(i.submitErrors));var o=function(e){var t=e.active,i=e.dirtySinceLastSubmit,r=e.error,n=e.errors,a=e.initialValues,u=e.pristine,o=e.submitting,s=e.submitFailed,l=e.submitSucceeded,f=e.submitError,d=e.submitErrors,c=e.valid,v=e.validating,b=e.values;return{active:t,dirty:!u,dirtySinceLastSubmit:i,error:r,errors:n,hasSubmitErrors:!!(f||d&&B(d)),hasValidationErrors:!(!r&&!B(n)),invalid:!c,initialValues:a,pristine:u,submitting:o,submitFailed:s,submitSucceeded:l,submitError:f,submitErrors:d,valid:c,validating:0<v,values:b}}(i),s=n.reduce(function(e,t){return e.modified[t]=r[t].modified,e.touched[t]=r[t].touched,e.visited[t]=r[t].visited,e},{modified:{},touched:{},visited:{}}),l=s.modified,f=s.touched,d=s.visited;return o.dirtyFields=t&&L(t.dirtyFields,u)?t.dirtyFields:u,o.modified=t&&L(t.modified,l)?t.modified:l,o.touched=t&&L(t.touched,f)?t.touched:f,o.visited=t&&L(t.visited,d)?t.visited:d,t&&L(t,o)?t:o}var h={subscribers:{index:0,entries:{}},fieldSubscribers:{},fields:{},formState:{dirtySinceLastSubmit:!1,errors:{},initialValues:t&&N({},t),invalid:!1,pristine:!0,submitting:!1,submitFailed:!1,submitSucceeded:!1,valid:!0,validating:0,values:t?N({},t):{}},lastFormState:void 0},r=!1,g=!1,y=!1,p=0,E={},n=o?Object.keys(o).reduce(function(e,t){return e[t]=i(t),e},{}):{},F=function(e,t){if(g)return y=!0,void t();var o=h.fields,i=h.formState,s=N({},o),r=Object.keys(s);if(b||r.some(function(e){return S(s[e]).length})){var l=!1;if(e){var n=s[e];if(n){var a=n.validateFields;a&&(l=!0,r=a.length?a.concat(e):[e])}}var f={},d={},u=[].concat(function(e){var t=[];if(b){var i=b(N({},h.formState.values));if(_(i)){var r=p++,n=i.then(e).then(m(r));t.push(n),E[r]=n}else e(i)}return t}(function(e){f=e||{}}),r.reduce(function(e,t){return e.concat(function(n,a){var u,o=[],e=S(n);e.length&&(e.forEach(function(e){var t=e(R(h.formState.values,n.name),h.formState.values,3===e.length?P(h.formState,h.fields[n.name]):void 0);if(t&&_(t)){var i=p++;n.validating=!0;var r=t.then(function(e){n.validating=!1,a(e)}).then(m(i));o.push(r),E[i]=r}else u||(u=t)}),a(u));return o}(o[t],function(e){d[t]=e}))},[])),c=function(){function e(a){r.forEach(function(e){if(o[e]){var t=R(f,e),i=R(u,e),r=S(s[e]).length,n=d[e];a(e,r&&n||b&&t||(t||l?void 0:i))}})}var u=N({},l?i.errors:{},f);e(function(e,t){u=A(u,e,t)||{}}),e(function(e,t){if(t&&t[I]){var i=R(u,e),r=[].concat(i);r[I]=t[I],u=A(u,e,r)}}),L(i.errors,u)||(i.errors=u),i.error=f[x]};if(c(),u.length){h.formState.validating++,t();var v=function(){h.formState.validating--,c(),t()};Promise.all(u).then(v,v)}else t()}else t()},O=function(e){if(!r&&!g){var t=h.fields,a=h.fieldSubscribers,u=h.formState,o=N({},t);Object.keys(o).forEach(function(e){var t=o[e],i=P(u,t),r=t.lastFieldState;if(!L(i,r)){t.lastFieldState=i;var n=a[e];n&&D(n,i,r,q)}})}},j=!1,k=!1,w=function e(){if(j)k=!0;else{if(j=!0,!r&&!g){var t=h.lastFormState,i=v();i!==t&&(h.lastFormState=i,D(h.subscribers,i,t,z))}j=!1,k&&(k=!1,e())}};F(void 0,function(){});var V={batch:function(e){r=!0,e(),r=!1,O(),w()},blur:function(e){var t=h.fields,i=h.formState,r=t[e];r&&(delete i.active,t[e]=N({},r,{active:!1,touched:!0}),l?F(e,function(){O(),w()}):(O(),w()))},change:function(e,t){var i=h.fields,r=h.formState;if(R(r.values,e)!==t){f(h,e,function(){return t});var n=i[e];n&&(i[e]=N({},n,{modified:!0})),l?(O(),w()):F(e,function(){O(),w()})}},get destroyOnUnregister(){return!!u},set destroyOnUnregister(e){u=e},focus:function(e){var t=h.fields[e];t&&!t.active&&(h.formState.active=e,t.active=!0,t.visited=!0,O(),w())},mutators:n,getFieldState:function(e){var t=h.fields[e];return t&&t.lastFieldState},getRegisteredFields:function(){return Object.keys(h.fields)},getState:function(){return v()},initialize:function(e){var t=h.fields,i=h.formState,r=N({},t),n="function"==typeof e?e(i.values):e;a||(i.values=n),Object.keys(r).forEach(function(e){var t=r[e];t.modified=!1,t.touched=!1,t.visited=!1,!a||t.isEqual(R(i.values,e),R(i.initialValues||{},e))&&(i.values=A(i.values,e,R(n,e)))}),i.initialValues=n,F(void 0,function(){O(),w()})},isValidationPaused:function(){return g},pauseValidation:function(){g=!0},registerField:function(t,i,r,e){void 0===r&&(r={}),h.fieldSubscribers[t]||(h.fieldSubscribers[t]={index:0,entries:{}});var n=h.fieldSubscribers[t].index++;h.fieldSubscribers[t].entries[n]={subscriber:C(i),subscription:r},h.fields[t]||(h.fields[t]={active:!1,afterSubmit:e&&e.afterSubmit,beforeSubmit:e&&e.beforeSubmit,blur:function(){return V.blur(t)},change:function(e){return V.change(t,e)},data:e&&e.data||{},focus:function(){return V.focus(t)},isEqual:e&&e.isEqual||U,lastFieldState:void 0,modified:!1,name:t,touched:!1,valid:!0,validateFields:e&&e.validateFields,validators:{},validating:!1,visited:!1}),e&&(e.getValidator&&(h.fields[t].validators[n]=e.getValidator),void 0!==e.initialValue&&(h.formState.initialValues=A(h.formState.initialValues||{},t,e.initialValue),h.formState.values=A(h.formState.values,t,e.initialValue)),void 0!==e.defaultValue&&(h.formState.values=A(h.formState.values,t,e.defaultValue)));var a=!1;return F(void 0,function(){w(),a||function(){var e=P(h.formState,h.fields[t]);M(i,r,e,void 0,q,!0),h.fields[t].lastFieldState=e,a=!0}(),O()}),function(){delete h.fields[t].validators[n],delete h.fieldSubscribers[t].entries[n],Object.keys(h.fieldSubscribers[t].entries).length||(delete h.fieldSubscribers[t],delete h.fields[t],h.formState.errors=A(h.formState.errors,t,void 0)||{},u&&(h.formState.values=A(h.formState.values,t,void 0,!0)||{})),F(void 0,function(){O(),w()})}},reset:function(e){if(void 0===e&&(e=h.formState.initialValues),h.formState.submitting)throw Error("Cannot reset() in onSubmit(), use setTimeout(form.reset)");h.formState.submitFailed=!1,h.formState.submitSucceeded=!1,delete h.formState.submitError,delete h.formState.submitErrors,delete h.formState.lastSubmittedValues,V.initialize(e||{})},resumeValidation:function(){g=!1,y&&F(void 0,function(){O(),w()}),y=!1},setConfig:function(e,t){switch(e){case"debug":t;break;case"destroyOnUnregister":u=t;break;case"initialValues":V.initialize(t);break;case"keepDirtyOnReinitialize":a=t;break;case"mutators":(o=t)?(Object.keys(n).forEach(function(e){e in t||delete n[e]}),Object.keys(t).forEach(function(e){n[e]=i(e)})):Object.keys(n).forEach(function(e){delete n[e]});break;case"onSubmit":s=t;break;case"validate":b=t,F(void 0,function(){O(),w()});break;case"validateOnBlur":l=t;break;default:throw new Error("Unrecognised option "+e)}},submit:function(){var t=h.formState;if(!t.submitting){if(h.formState.error||B(h.formState.errors))return c(),h.formState.submitFailed=!0,w(),void O();var e=Object.keys(E);if(e.length)Promise.all(e.reduce(function(e,t){return e.push(E[Number(t)]),e},[])).then(V.submit,V.submit);else if(!Object.keys(h.fields).find(function(e){return h.fields[e].beforeSubmit&&!1===h.fields[e].beforeSubmit()})){var i,r=!1,n=function(e){return t.submitting=!1,e&&B(e)?(t.submitFailed=!0,t.submitSucceeded=!1,t.submitErrors=e,t.submitError=e[x],c()):(t.submitFailed=!1,t.submitSucceeded=!0,Object.keys(h.fields).forEach(function(e){return h.fields[e].afterSubmit&&h.fields[e].afterSubmit()})),w(),O(),r=!0,i&&i(e),e};delete t.submitErrors,delete t.submitError,t.submitting=!0,t.submitFailed=!1,t.submitSucceeded=!1,t.lastSubmittedValues=N({},t.values);var a=s(t.values,V,n);if(!r){if(a&&_(a))return w(),O(),a.then(n,function(e){throw n(),e});if(3<=s.length)return w(),O(),new Promise(function(e){i=e});n(a)}}}},subscribe:function(e,t){if(!e)throw new Error("No callback given.");if(!t)throw new Error("No subscription provided. What values do you want to listen to?");var i=C(e),r=h.subscribers,n=h.lastFormState,a=r.index++;r.entries[a]={subscriber:i,subscription:t};var u=v();return u!==n&&(h.lastFormState=u),M(i,t,u,u,z,!0),function(){delete r.entries[a]}}};return V},e.fieldSubscriptionItems=a,e.formSubscriptionItems=l,e.getIn=R,e.setIn=A,e.version="4.16.2",Object.defineProperty(e,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=final-form.umd.min.js.map |
@@ -126,3 +126,3 @@ export type Subscription = { [key: string]: boolean } | ||
) => any | Promise<any> | ||
type GetFieldValidator<FieldValue> = () => FieldValidator<FieldValue> | ||
type GetFieldValidator<FieldValue> = () => FieldValidator<FieldValue> | undefined | ||
@@ -132,2 +132,3 @@ export interface FieldConfig<FieldValue> { | ||
beforeSubmit?: () => void | false | ||
data?: any | ||
defaultValue?: any | ||
@@ -134,0 +135,0 @@ getValidator?: GetFieldValidator<FieldValue> |
{ | ||
"name": "final-form", | ||
"version": "4.16.1", | ||
"version": "4.16.2", | ||
"description": "🏁 Framework agnostic, high performance, subscription-based form state management", | ||
@@ -47,3 +47,3 @@ "main": "dist/final-form.cjs.js", | ||
"babel-jest": "^24.1.0", | ||
"bundlesize": "^0.17.1", | ||
"bundlesize": "^0.18.0", | ||
"doctoc": "^1.4.0", | ||
@@ -92,3 +92,3 @@ "eslint": "^5.13.0", | ||
"path": "dist/final-form.umd.min.js", | ||
"maxSize": "4.90kB" | ||
"maxSize": "5.0kB" | ||
}, | ||
@@ -95,0 +95,0 @@ { |
@@ -172,2 +172,3 @@ # 🏁 Final Form | ||
- [`valid?: boolean`](#valid-boolean) | ||
- [`validating: boolean`](#validating-boolean) | ||
- [`value?: any`](#value-any) | ||
@@ -275,3 +276,3 @@ - [`visited?: boolean`](#visited-boolean) | ||
- [`valid: boolean`](#valid-boolean) | ||
- [`validating: boolean`](#validating-boolean) | ||
- [`validating: boolean`](#validating-boolean-1) | ||
- [`visited: boolean`](#visited-boolean) | ||
@@ -534,2 +535,6 @@ - [`InternalFormState`](#internalformstate) | ||
#### `data?: any` | ||
Initial state for arbitrary values to be placed by mutators. | ||
#### `defaultValue?: any` | ||
@@ -652,2 +657,6 @@ | ||
#### `validating: boolean` | ||
`true` if this field is currently waiting on its asynchronous field-level validation function to resolve. `false` otherwise. | ||
#### `value?: any` | ||
@@ -654,0 +663,0 @@ |
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
214444
3605
1311