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

final-form

Package Overview
Dependencies
Maintainers
1
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

final-form - npm Package Compare versions

Comparing version 4.7.3 to 4.8.0

38

dist/final-form.cjs.js

@@ -335,3 +335,3 @@ 'use strict';

var configOptions = ['debug', 'initialValues', 'keepDirtyOnReinitialize', 'mutators', 'onSubmit', 'validate', 'validateOnBlur'];
var version = '4.7.3';
var version = '4.8.0';

@@ -420,2 +420,3 @@ var tripleEquals = function tripleEquals(a, b) {

var debug = config.debug,
destroyOnUnregister = config.destroyOnUnregister,
keepDirtyOnReinitialize = config.keepDirtyOnReinitialize,

@@ -478,2 +479,3 @@ initialValues = config.initialValues,

return function () {
// istanbul ignore next
if (mutators) {

@@ -690,2 +692,25 @@ // ^^ causes branch coverage warning, but needed to appease the Flow gods

if (!shallowEqual(fieldState, lastFieldState)) {
// **************************************************************
// Curious about why a field is getting notified? Uncomment this.
// **************************************************************
// const diffKeys = Object.keys(fieldState).filter(
// key => fieldState[key] !== (lastFieldState && lastFieldState[key])
// )
// console.debug(
// 'notifying',
// name,
// '\nField State\n',
// diffKeys.reduce(
// (result, key) => ({ ...result, [key]: fieldState[key] }),
// {}
// ),
// '\nLast Field State\n',
// diffKeys.reduce(
// (result, key) => ({
// ...result,
// [key]: lastFieldState && lastFieldState[key]
// }),
// {}
// )
// )
field.lastFieldState = fieldState;

@@ -717,3 +742,4 @@ notify(fieldSubscribers[name], fieldState, lastFieldState, filterFieldState);

formState.dirtySinceLastSubmit = !!(formState.lastSubmittedValues && !fieldKeys.every(function (key) {
return fields[key].isEqual(getIn(formState.values, key), getIn(formState.lastSubmittedValues || {}, key) // || {} is for flow, but causes branch coverage complaint
return fields[key].isEqual(getIn(formState.values, key), // istanbul ignore next
getIn(formState.lastSubmittedValues || {}, key) // || {} is for flow, but causes branch coverage complaint
);

@@ -962,2 +988,6 @@ }));

state.formState.errors = setIn(state.formState.errors, name, undefined) || {};
if (destroyOnUnregister) {
state.formState.values = setIn(state.formState.values, name, undefined) || {};
}
}

@@ -1001,2 +1031,6 @@

case 'destroyOnUnregister':
destroyOnUnregister = value;
break;
case 'initialValues':

@@ -1003,0 +1037,0 @@ api.initialize(value);

@@ -331,3 +331,3 @@ function _defineProperty(obj, key, value) {

var configOptions = ['debug', 'initialValues', 'keepDirtyOnReinitialize', 'mutators', 'onSubmit', 'validate', 'validateOnBlur'];
var version = '4.7.3';
var version = '4.8.0';

@@ -416,2 +416,3 @@ var tripleEquals = function tripleEquals(a, b) {

var debug = config.debug,
destroyOnUnregister = config.destroyOnUnregister,
keepDirtyOnReinitialize = config.keepDirtyOnReinitialize,

@@ -474,2 +475,3 @@ initialValues = config.initialValues,

return function () {
// istanbul ignore next
if (mutators) {

@@ -686,2 +688,25 @@ // ^^ causes branch coverage warning, but needed to appease the Flow gods

if (!shallowEqual(fieldState, lastFieldState)) {
// **************************************************************
// Curious about why a field is getting notified? Uncomment this.
// **************************************************************
// const diffKeys = Object.keys(fieldState).filter(
// key => fieldState[key] !== (lastFieldState && lastFieldState[key])
// )
// console.debug(
// 'notifying',
// name,
// '\nField State\n',
// diffKeys.reduce(
// (result, key) => ({ ...result, [key]: fieldState[key] }),
// {}
// ),
// '\nLast Field State\n',
// diffKeys.reduce(
// (result, key) => ({
// ...result,
// [key]: lastFieldState && lastFieldState[key]
// }),
// {}
// )
// )
field.lastFieldState = fieldState;

@@ -713,3 +738,4 @@ notify(fieldSubscribers[name], fieldState, lastFieldState, filterFieldState);

formState.dirtySinceLastSubmit = !!(formState.lastSubmittedValues && !fieldKeys.every(function (key) {
return fields[key].isEqual(getIn(formState.values, key), getIn(formState.lastSubmittedValues || {}, key) // || {} is for flow, but causes branch coverage complaint
return fields[key].isEqual(getIn(formState.values, key), // istanbul ignore next
getIn(formState.lastSubmittedValues || {}, key) // || {} is for flow, but causes branch coverage complaint
);

@@ -958,2 +984,6 @@ }));

state.formState.errors = setIn(state.formState.errors, name, undefined) || {};
if (destroyOnUnregister) {
state.formState.values = setIn(state.formState.values, name, undefined) || {};
}
}

@@ -997,2 +1027,6 @@

case 'destroyOnUnregister':
destroyOnUnregister = value;
break;
case 'initialValues':

@@ -999,0 +1033,0 @@ api.initialize(value);

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

var configOptions = ['debug', 'initialValues', 'keepDirtyOnReinitialize', 'mutators', 'onSubmit', 'validate', 'validateOnBlur'];
var version = '4.7.3';
var version = '4.8.0';

@@ -422,2 +422,3 @@ var tripleEquals = function tripleEquals(a, b) {

var debug = config.debug,
destroyOnUnregister = config.destroyOnUnregister,
keepDirtyOnReinitialize = config.keepDirtyOnReinitialize,

@@ -480,2 +481,3 @@ initialValues = config.initialValues,

return function () {
// istanbul ignore next
if (mutators) {

@@ -692,2 +694,25 @@ // ^^ causes branch coverage warning, but needed to appease the Flow gods

if (!shallowEqual(fieldState, lastFieldState)) {
// **************************************************************
// Curious about why a field is getting notified? Uncomment this.
// **************************************************************
// const diffKeys = Object.keys(fieldState).filter(
// key => fieldState[key] !== (lastFieldState && lastFieldState[key])
// )
// console.debug(
// 'notifying',
// name,
// '\nField State\n',
// diffKeys.reduce(
// (result, key) => ({ ...result, [key]: fieldState[key] }),
// {}
// ),
// '\nLast Field State\n',
// diffKeys.reduce(
// (result, key) => ({
// ...result,
// [key]: lastFieldState && lastFieldState[key]
// }),
// {}
// )
// )
field.lastFieldState = fieldState;

@@ -719,3 +744,4 @@ notify(fieldSubscribers[name], fieldState, lastFieldState, filterFieldState);

formState.dirtySinceLastSubmit = !!(formState.lastSubmittedValues && !fieldKeys.every(function (key) {
return fields[key].isEqual(getIn(formState.values, key), getIn(formState.lastSubmittedValues || {}, key) // || {} is for flow, but causes branch coverage complaint
return fields[key].isEqual(getIn(formState.values, key), // istanbul ignore next
getIn(formState.lastSubmittedValues || {}, key) // || {} is for flow, but causes branch coverage complaint
);

@@ -964,2 +990,6 @@ }));

state.formState.errors = setIn(state.formState.errors, name, undefined) || {};
if (destroyOnUnregister) {
state.formState.values = setIn(state.formState.values, name, undefined) || {};
}
}

@@ -1003,2 +1033,6 @@

case 'destroyOnUnregister':
destroyOnUnregister = value;
break;
case 'initialValues':

@@ -1005,0 +1039,0 @@ api.initialize(value);

2

dist/final-form.umd.min.js

@@ -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["final-form"]={})}(this,function(e){"use strict";function k(n){for(var e=1;e<arguments.length;e++){var a=null!=arguments[e]?arguments[e]:{},t=Object.keys(a);"function"==typeof Object.getOwnPropertySymbols&&(t=t.concat(Object.getOwnPropertySymbols(a).filter(function(e){return Object.getOwnPropertyDescriptor(a,e).enumerable}))),t.forEach(function(e){var t,i,r;t=n,r=a[i=e],i in t?Object.defineProperty(t,i,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[i]=r})}return n}var u=function(e){if(null==e||!e.length)return[];if("string"!=typeof e)throw new Error("toPath() expects a string");return e.split(/[.[\]]+/).filter(Boolean)},V=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},N=function(e,t,i){if(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 function e(t,i,r,n){if(i>=r.length)return n;var a=r[i];if(isNaN(a)){var u;if(null==t){var o,s=e(void 0,i+1,r,n);return void 0===s?void 0:((o={})[a]=s,o)}if(Array.isArray(t))throw new Error("Cannot set a non-numeric property on an array");var l=e(t[a],i+1,r,n),c=Object.keys(t).length;if(void 0===l){if(void 0===t[a]&&0===c)return;if(void 0!==t[a]&&c<=1)return isNaN(r[i-1])?void 0:{}}return k({},t,((u={})[a]=l,u))}var f=Number(a);if(null==t){var d=e(void 0,i+1,r,n);if(void 0===d)return;var v=[];return v[f]=d,v}if(!Array.isArray(t))throw new Error("Cannot set a numeric property on an object");var b=e(t[f],i+1,r,n),m=t.concat();return m[f]=b,m}(e,0,u(t),i)},R="FINAL_FORM/form-error",A="FINAL_FORM/array-error",P=function(e,t){var i=e.errors,r=e.initialValues,n=e.lastSubmittedValues,a=e.submitErrors,u=e.submitFailed,o=e.submitSucceeded,s=e.values,l=t.active,c=t.blur,f=t.change,d=t.data,v=t.focus,b=t.name,m=t.touched,S=t.visited,h=V(s,b),y=V(i,b);y&&y[A]&&(y=y[A]);var g=a&&V(a,b),p=r&&V(r,b),E=t.isEqual(p,h),O=!y&&!g;return{active:l,blur:c,change:f,data:d,dirty:!E,dirtySinceLastSubmit:!(!n||t.isEqual(V(n,b),h)),error:y,focus:v,initial:p,invalid:!O,length:Array.isArray(h)?h.length:void 0,name:b,pristine:E,submitError:g,submitFailed:u,submitSucceeded:o,touched:m,valid:O,value:h,visited:S}},a=["active","data","dirty","dirtySinceLastSubmit","error","initial","invalid","length","pristine","submitError","submitFailed","submitSucceeded","touched","valid","value","visited"],I=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)?I(i[e],r[e]):i[e]===r[e])||(u=!0))}),u}var s=["data"],x=function(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},l=["active","dirty","dirtySinceLastSubmit","error","errors","hasSubmitErrors","hasValidationErrors","initialValues","invalid","pristine","submitting","submitError","submitErrors","submitFailed","submitSucceeded","touched","valid","validating","values","visited"],c=["touched","visited"],L=function(e,t,i,r){var n={};return o(n,e,t,i,l,c)||!t||r?n:void 0},q=function(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!I(n[t],e)})||(n=t,a=r.apply(void 0,t)),a}},z=function(e){return!!e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof e.then},_=function(e,t){return e===t},C=function i(e){return Object.entries(e).some(function(e){e[0];var t=e[1];return t&&"object"==typeof t?i(t):void 0!==t})},B=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,c=e.submitError,f=e.submitErrors,d=e.valid,v=e.validating,b=e.values;return{active:t,dirty:!u,dirtySinceLastSubmit:i,error:r,errors:n,hasSubmitErrors:!!(c||f&&C(f)),hasValidationErrors:!(!r&&!C(n)),invalid:!d,initialValues:a,pristine:u,submitting:o,submitFailed:s,submitSucceeded:l,submitError:c,submitErrors:f,valid:d,validating:0<v,values:b}};function D(e,t,i,r,n,a){void 0===a&&(a=!1);var u=n(i,r,t,a);u&&e(u)}function M(e,r,n,a){var u=e.entries;Object.keys(u).forEach(function(e){var t=u[Number(e)],i=t.subscription;D(t.subscriber,i,r,n,a)})}e.createForm=function(e){if(!e)throw new Error("No config specified");e.debug;var a=e.keepDirtyOnReinitialize,t=e.initialValues,u=e.mutators,o=e.onSubmit,f=e.validate,n=e.validateOnBlur;if(!o)throw new Error("No onSubmit function specified");var d={subscribers:{index:0,entries:{}},fieldSubscribers:{},fields:{},formState:{dirtySinceLastSubmit:!1,errors:{},initialValues:t&&k({},t),invalid:!1,pristine:!0,submitting:!1,submitFailed:!1,submitSucceeded:!1,valid:!0,validating:0,values:t?k({},t):{}},lastFormState:void 0},r=!1,v=!1,b=!1,m=0,S={},h=function(t){return function(e){return delete S[t],e}},s=function(e,t,i){if(e.fields[t]){var r=i(V(e.formState.values,t));e.formState.values=N(e.formState.values,t,r)||{}}},i=function(a){return function(){if(u){for(var e={formState:d.formState,fields:d.fields},t=arguments.length,i=new Array(t),r=0;r<t;r++)i[r]=arguments[r];var n=u[a](i,e,{changeValue:s,getIn:V,setIn:N,shallowEqual:I});return d.formState=e.formState,d.fields=e.fields,c(void 0,function(){g(),w()}),n}}},l=u&&Object.keys(u).reduce(function(e,t){return e[t]=i(t),e},{})||{},y=function(r){return Object.keys(r.validators).reduce(function(e,t){var i=r.validators[Number(t)]();return i&&e.push(i),e},[])},c=function(e,t){if(v)return b=!0,void(t&&t());var s=d.fields,i=d.formState,r=Object.keys(s);if(f||r.some(function(e){return y(s[e]).length})){var o=!1;if(e){var n=s[e].validateFields;n&&(o=!0,r=n.length?n.concat(e):[e])}var l={},c={},a=function(e){var t=[];if(f){var i=f(k({},d.formState.values));if(z(i)){var r=m++,n=i.then(e).then(h(r));t.push(n),S[r]=n}else e(i)}return t}(function(e){l=e||{}}).concat(r.reduce(function(e,t){return e.concat((n=s[t],a=function(e){c[t]=e},o=[],(i=y(n)).length&&(i.forEach(function(e){var t=e(V(d.formState.values,n.name),d.formState.values);if(t&&z(t)){var i=m++,r=t.then(a).then(h(i));o.push(r),S[i]=r}else u||(u=t)}),a(u)),o));var n,a,u,o,i},[])),u=function(){var u=k({},o?i.errors:{},l),e=function(a){r.forEach(function(e){if(s[e]){var t=V(l,e),i=V(u,e),r=y(s[e]).length,n=c[e];a(e,r&&n||f&&t||(t||o?void 0:i))}})};e(function(e,t){u=N(u,e,t)||{}}),e(function(e,t){if(t&&t[A]){var i=V(u,e).concat();i[A]=t[A],u=N(u,e,i)}}),I(i.errors,u)||(i.errors=u),i.error=l[R]};u(),a.length?(d.formState.validating++,t&&t(),Promise.all(a).then(function(){d.formState.validating--,u(),t&&t()})):t&&t()}else t&&t()},g=function(e){if(!r&&!v){var n=d.fields,a=d.fieldSubscribers,u=d.formState;Object.keys(n).forEach(function(e){var t=n[e],i=P(u,t),r=t.lastFieldState;I(i,r)||(t.lastFieldState=i,M(a[e],i,r,x))})}},p=function(){Object.keys(d.fields).forEach(function(e){d.fields[e].touched=!0})},E=function(){var i=d.fields,t=d.formState,e=d.lastFormState,r=Object.keys(i);t.pristine=r.every(function(e){return i[e].isEqual(V(t.values,e),V(t.initialValues||{},e))}),t.dirtySinceLastSubmit=!(!t.lastSubmittedValues||r.every(function(e){return i[e].isEqual(V(t.values,e),V(t.lastSubmittedValues||{},e))})),t.valid=!(t.error||t.submitError||C(t.errors)||t.submitErrors&&C(t.submitErrors));var n=B(t),a=r.reduce(function(e,t){return e.touched[t]=i[t].touched,e.visited[t]=i[t].visited,e},{touched:{},visited:{}}),u=a.touched,o=a.visited;return n.touched=e&&I(e.touched,u)?e.touched:u,n.visited=e&&I(e.visited,o)?e.visited:o,e&&I(e,n)?e:n},O=!1,F=!1,w=function e(){if(O)F=!0;else{if(O=!0,!r&&!v){var t=d.lastFormState,i=E();i!==t&&(d.lastFormState=i,M(d.subscribers,i,t,L))}O=!1,F&&(F=!1,e())}};c();var j={batch:function(e){r=!0,e(),r=!1,g(),w()},blur:function(e){var t=d.fields,i=d.formState,r=t[e];r&&(delete i.active,t[e]=k({},r,{active:!1,touched:!0}),n?c(e,function(){g(),w()}):(g(),w()))},change:function(e,t){var i=d.fields,r=d.formState;i[e]&&V(r.values,e)!==t&&(s(d,e,function(){return t}),n?(g(),w()):c(e,function(){g(),w()}))},focus:function(e){var t=d.fields[e];t&&!t.active&&(d.formState.active=e,t.active=!0,t.visited=!0,g(),w())},mutators:l,getFieldState:function(e){var t=d.fields[e];return t&&t.lastFieldState},getRegisteredFields:function(){return Object.keys(d.fields)},getState:function(){return B(d.formState)},initialize:function(i){var r=d.fields,n=d.formState;a||(n.values=i),Object.keys(r).forEach(function(e){var t=r[e];t.touched=!1,t.visited=!1,a&&r[e].isEqual(V(n.values,e),V(n.initialValues||{},e))&&(n.values=N(n.values,e,V(i,e)))}),n.initialValues=i,c(void 0,function(){g(),w()})},isValidationPaused:function(){return v},pauseValidation:function(){v=!0},registerField:function(t,i,r,e){void 0===r&&(r={}),d.fieldSubscribers[t]||(d.fieldSubscribers[t]={index:0,entries:{}});var n=d.fieldSubscribers[t].index++;if(d.fieldSubscribers[t].entries[n]={subscriber:q(i),subscription:r},!d.fields[t]){var a=d.formState.initialValues?V(d.formState.initialValues,t):void 0;d.fields[t]={active:!1,blur:function(){return j.blur(t)},change:function(e){return j.change(t,e)},data:{},focus:function(){return j.focus(t)},initial:a,isEqual:e&&e.isEqual||_,lastFieldState:void 0,name:t,touched:!1,valid:!0,validateFields:e&&e.validateFields,validators:{},visited:!1}}e&&e.getValidator&&(d.fields[t].validators[n]=e.getValidator);var u=!1;return c(void 0,function(){var e;w(),u||(e=P(d.formState,d.fields[t]),D(i,r,e,void 0,x,!0),d.fields[t].lastFieldState=e,u=!0),g()}),function(){delete d.fields[t].validators[n],delete d.fieldSubscribers[t].entries[n],Object.keys(d.fieldSubscribers[t].entries).length||(delete d.fieldSubscribers[t],delete d.fields[t],d.formState.errors=N(d.formState.errors,t,void 0)||{}),c(void 0,function(){g(),w()})}},reset:function(e){void 0===e&&(e=d.formState.initialValues),d.formState.submitFailed=!1,d.formState.submitSucceeded=!1,delete d.formState.submitErrors,delete d.formState.lastSubmittedValues,j.initialize(e||{})},resumeValidation:function(){v=!1,b&&c(void 0,function(){g(),w()}),b=!1},setConfig:function(e,t){switch(e){case"debug":break;case"initialValues":j.initialize(t);break;case"keepDirtyOnReinitialize":a=t;break;case"mutators":(u=t)?(Object.keys(l).forEach(function(e){e in t||delete l[e]}),Object.keys(t).forEach(function(e){l[e]=i(e)})):Object.keys(l).forEach(function(e){delete l[e]});break;case"onSubmit":o=t;break;case"validate":f=t,c(void 0,function(){g(),w()});break;case"validateOnBlur":n=t;break;default:throw new Error("Unrecognised option "+e)}},submit:function(){var t=d.formState;if(d.formState.error||C(d.formState.errors))return p(),d.formState.submitFailed=!0,w(),void g();var e=Object.keys(S);if(e.length)Promise.all(e.reduce(function(e,t){return e.push(S[Number(t)]),e},[])).then(function(){return j.submit()});else{var i,r=!1,n=function(e){return t.submitting=!1,e&&C(e)?(t.submitFailed=!0,t.submitSucceeded=!1,t.submitErrors=e,t.submitError=e[R],p()):(delete t.submitErrors,delete t.submitError,t.submitFailed=!1,t.submitSucceeded=!0),w(),g(),r=!0,i&&i(e),e};if(t.submitting=!0,t.submitFailed=!1,t.submitSucceeded=!1,t.lastSubmittedValues=k({},t.values),3===o.length){if(o(t.values,j,n),!r)return w(),new Promise(function(e){i=e})}else{var a=o(t.values,j);if(a&&z(a))return w(),a.then(n);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=q(e),r=d.subscribers,n=d.lastFormState,a=r.index++;r.entries[a]={subscriber:i,subscription:t};var u=E();return u!==n&&(d.lastFormState=u),D(i,t,u,u,L,!0),function(){delete r.entries[a]}}};return j},e.configOptions=["debug","initialValues","keepDirtyOnReinitialize","mutators","onSubmit","validate","validateOnBlur"],e.version="4.7.3",e.ARRAY_ERROR=A,e.FORM_ERROR=R,e.formSubscriptionItems=l,e.fieldSubscriptionItems=a,e.getIn=V,e.setIn=N,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["final-form"]={})}(this,function(e){"use strict";function V(n){for(var e=1;e<arguments.length;e++){var a=null!=arguments[e]?arguments[e]:{},t=Object.keys(a);"function"==typeof Object.getOwnPropertySymbols&&(t=t.concat(Object.getOwnPropertySymbols(a).filter(function(e){return Object.getOwnPropertyDescriptor(a,e).enumerable}))),t.forEach(function(e){var t,i,r;t=n,r=a[i=e],i in t?Object.defineProperty(t,i,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[i]=r})}return n}var u=function(e){if(null==e||!e.length)return[];if("string"!=typeof e)throw new Error("toPath() expects a string");return e.split(/[.[\]]+/).filter(Boolean)},N=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},R=function(e,t,i){if(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 function e(t,i,r,n){if(i>=r.length)return n;var a=r[i];if(isNaN(a)){var u;if(null==t){var o,s=e(void 0,i+1,r,n);return void 0===s?void 0:((o={})[a]=s,o)}if(Array.isArray(t))throw new Error("Cannot set a non-numeric property on an array");var l=e(t[a],i+1,r,n),c=Object.keys(t).length;if(void 0===l){if(void 0===t[a]&&0===c)return;if(void 0!==t[a]&&c<=1)return isNaN(r[i-1])?void 0:{}}return V({},t,((u={})[a]=l,u))}var f=Number(a);if(null==t){var d=e(void 0,i+1,r,n);if(void 0===d)return;var v=[];return v[f]=d,v}if(!Array.isArray(t))throw new Error("Cannot set a numeric property on an object");var b=e(t[f],i+1,r,n),m=t.concat();return m[f]=b,m}(e,0,u(t),i)},A="FINAL_FORM/form-error",P="FINAL_FORM/array-error",I=function(e,t){var i=e.errors,r=e.initialValues,n=e.lastSubmittedValues,a=e.submitErrors,u=e.submitFailed,o=e.submitSucceeded,s=e.values,l=t.active,c=t.blur,f=t.change,d=t.data,v=t.focus,b=t.name,m=t.touched,S=t.visited,h=N(s,b),y=N(i,b);y&&y[P]&&(y=y[P]);var g=a&&N(a,b),p=r&&N(r,b),E=t.isEqual(p,h),O=!y&&!g;return{active:l,blur:c,change:f,data:d,dirty:!E,dirtySinceLastSubmit:!(!n||t.isEqual(N(n,b),h)),error:y,focus:v,initial:p,invalid:!O,length:Array.isArray(h)?h.length:void 0,name:b,pristine:E,submitError:g,submitFailed:u,submitSucceeded:o,touched:m,valid:O,value:h,visited:S}},a=["active","data","dirty","dirtySinceLastSubmit","error","initial","invalid","length","pristine","submitError","submitFailed","submitSucceeded","touched","valid","value","visited"],x=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)?x(i[e],r[e]):i[e]===r[e])||(u=!0))}),u}var s=["data"],L=function(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},l=["active","dirty","dirtySinceLastSubmit","error","errors","hasSubmitErrors","hasValidationErrors","initialValues","invalid","pristine","submitting","submitError","submitErrors","submitFailed","submitSucceeded","touched","valid","validating","values","visited"],c=["touched","visited"],q=function(e,t,i,r){var n={};return o(n,e,t,i,l,c)||!t||r?n:void 0},z=function(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!x(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},C=function(e,t){return e===t},B=function i(e){return Object.entries(e).some(function(e){e[0];var t=e[1];return t&&"object"==typeof t?i(t):void 0!==t})},D=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,c=e.submitError,f=e.submitErrors,d=e.valid,v=e.validating,b=e.values;return{active:t,dirty:!u,dirtySinceLastSubmit:i,error:r,errors:n,hasSubmitErrors:!!(c||f&&B(f)),hasValidationErrors:!(!r&&!B(n)),invalid:!d,initialValues:a,pristine:u,submitting:o,submitFailed:s,submitSucceeded:l,submitError:c,submitErrors:f,valid:d,validating:0<v,values:b}};function M(e,t,i,r,n,a){void 0===a&&(a=!1);var u=n(i,r,t,a);u&&e(u)}function U(e,r,n,a){var u=e.entries;Object.keys(u).forEach(function(e){var t=u[Number(e)],i=t.subscription;M(t.subscriber,i,r,n,a)})}e.createForm=function(e){if(!e)throw new Error("No config specified");e.debug;var o=e.destroyOnUnregister,a=e.keepDirtyOnReinitialize,t=e.initialValues,u=e.mutators,s=e.onSubmit,f=e.validate,n=e.validateOnBlur;if(!s)throw new Error("No onSubmit function specified");var d={subscribers:{index:0,entries:{}},fieldSubscribers:{},fields:{},formState:{dirtySinceLastSubmit:!1,errors:{},initialValues:t&&V({},t),invalid:!1,pristine:!0,submitting:!1,submitFailed:!1,submitSucceeded:!1,valid:!0,validating:0,values:t?V({},t):{}},lastFormState:void 0},r=!1,v=!1,b=!1,m=0,S={},h=function(t){return function(e){return delete S[t],e}},l=function(e,t,i){if(e.fields[t]){var r=i(N(e.formState.values,t));e.formState.values=R(e.formState.values,t,r)||{}}},i=function(a){return function(){if(u){for(var e={formState:d.formState,fields:d.fields},t=arguments.length,i=new Array(t),r=0;r<t;r++)i[r]=arguments[r];var n=u[a](i,e,{changeValue:l,getIn:N,setIn:R,shallowEqual:x});return d.formState=e.formState,d.fields=e.fields,g(void 0,function(){p(),j()}),n}}},c=u&&Object.keys(u).reduce(function(e,t){return e[t]=i(t),e},{})||{},y=function(r){return Object.keys(r.validators).reduce(function(e,t){var i=r.validators[Number(t)]();return i&&e.push(i),e},[])},g=function(e,t){if(v)return b=!0,void(t&&t());var s=d.fields,i=d.formState,r=Object.keys(s);if(f||r.some(function(e){return y(s[e]).length})){var o=!1;if(e){var n=s[e].validateFields;n&&(o=!0,r=n.length?n.concat(e):[e])}var l={},c={},a=function(e){var t=[];if(f){var i=f(V({},d.formState.values));if(_(i)){var r=m++,n=i.then(e).then(h(r));t.push(n),S[r]=n}else e(i)}return t}(function(e){l=e||{}}).concat(r.reduce(function(e,t){return e.concat((n=s[t],a=function(e){c[t]=e},o=[],(i=y(n)).length&&(i.forEach(function(e){var t=e(N(d.formState.values,n.name),d.formState.values);if(t&&_(t)){var i=m++,r=t.then(a).then(h(i));o.push(r),S[i]=r}else u||(u=t)}),a(u)),o));var n,a,u,o,i},[])),u=function(){var u=V({},o?i.errors:{},l),e=function(a){r.forEach(function(e){if(s[e]){var t=N(l,e),i=N(u,e),r=y(s[e]).length,n=c[e];a(e,r&&n||f&&t||(t||o?void 0:i))}})};e(function(e,t){u=R(u,e,t)||{}}),e(function(e,t){if(t&&t[P]){var i=N(u,e).concat();i[P]=t[P],u=R(u,e,i)}}),x(i.errors,u)||(i.errors=u),i.error=l[A]};u(),a.length?(d.formState.validating++,t&&t(),Promise.all(a).then(function(){d.formState.validating--,u(),t&&t()})):t&&t()}else t&&t()},p=function(e){if(!r&&!v){var n=d.fields,a=d.fieldSubscribers,u=d.formState;Object.keys(n).forEach(function(e){var t=n[e],i=I(u,t),r=t.lastFieldState;x(i,r)||(t.lastFieldState=i,U(a[e],i,r,L))})}},E=function(){Object.keys(d.fields).forEach(function(e){d.fields[e].touched=!0})},O=function(){var i=d.fields,t=d.formState,e=d.lastFormState,r=Object.keys(i);t.pristine=r.every(function(e){return i[e].isEqual(N(t.values,e),N(t.initialValues||{},e))}),t.dirtySinceLastSubmit=!(!t.lastSubmittedValues||r.every(function(e){return i[e].isEqual(N(t.values,e),N(t.lastSubmittedValues||{},e))})),t.valid=!(t.error||t.submitError||B(t.errors)||t.submitErrors&&B(t.submitErrors));var n=D(t),a=r.reduce(function(e,t){return e.touched[t]=i[t].touched,e.visited[t]=i[t].visited,e},{touched:{},visited:{}}),u=a.touched,o=a.visited;return n.touched=e&&x(e.touched,u)?e.touched:u,n.visited=e&&x(e.visited,o)?e.visited:o,e&&x(e,n)?e:n},F=!1,w=!1,j=function e(){if(F)w=!0;else{if(F=!0,!r&&!v){var t=d.lastFormState,i=O();i!==t&&(d.lastFormState=i,U(d.subscribers,i,t,q))}F=!1,w&&(w=!1,e())}};g();var k={batch:function(e){r=!0,e(),r=!1,p(),j()},blur:function(e){var t=d.fields,i=d.formState,r=t[e];r&&(delete i.active,t[e]=V({},r,{active:!1,touched:!0}),n?g(e,function(){p(),j()}):(p(),j()))},change:function(e,t){var i=d.fields,r=d.formState;i[e]&&N(r.values,e)!==t&&(l(d,e,function(){return t}),n?(p(),j()):g(e,function(){p(),j()}))},focus:function(e){var t=d.fields[e];t&&!t.active&&(d.formState.active=e,t.active=!0,t.visited=!0,p(),j())},mutators:c,getFieldState:function(e){var t=d.fields[e];return t&&t.lastFieldState},getRegisteredFields:function(){return Object.keys(d.fields)},getState:function(){return D(d.formState)},initialize:function(i){var r=d.fields,n=d.formState;a||(n.values=i),Object.keys(r).forEach(function(e){var t=r[e];t.touched=!1,t.visited=!1,a&&r[e].isEqual(N(n.values,e),N(n.initialValues||{},e))&&(n.values=R(n.values,e,N(i,e)))}),n.initialValues=i,g(void 0,function(){p(),j()})},isValidationPaused:function(){return v},pauseValidation:function(){v=!0},registerField:function(t,i,r,e){void 0===r&&(r={}),d.fieldSubscribers[t]||(d.fieldSubscribers[t]={index:0,entries:{}});var n=d.fieldSubscribers[t].index++;if(d.fieldSubscribers[t].entries[n]={subscriber:z(i),subscription:r},!d.fields[t]){var a=d.formState.initialValues?N(d.formState.initialValues,t):void 0;d.fields[t]={active:!1,blur:function(){return k.blur(t)},change:function(e){return k.change(t,e)},data:{},focus:function(){return k.focus(t)},initial:a,isEqual:e&&e.isEqual||C,lastFieldState:void 0,name:t,touched:!1,valid:!0,validateFields:e&&e.validateFields,validators:{},visited:!1}}e&&e.getValidator&&(d.fields[t].validators[n]=e.getValidator);var u=!1;return g(void 0,function(){var e;j(),u||(e=I(d.formState,d.fields[t]),M(i,r,e,void 0,L,!0),d.fields[t].lastFieldState=e,u=!0),p()}),function(){delete d.fields[t].validators[n],delete d.fieldSubscribers[t].entries[n],Object.keys(d.fieldSubscribers[t].entries).length||(delete d.fieldSubscribers[t],delete d.fields[t],d.formState.errors=R(d.formState.errors,t,void 0)||{},o&&(d.formState.values=R(d.formState.values,t,void 0)||{})),g(void 0,function(){p(),j()})}},reset:function(e){void 0===e&&(e=d.formState.initialValues),d.formState.submitFailed=!1,d.formState.submitSucceeded=!1,delete d.formState.submitErrors,delete d.formState.lastSubmittedValues,k.initialize(e||{})},resumeValidation:function(){v=!1,b&&g(void 0,function(){p(),j()}),b=!1},setConfig:function(e,t){switch(e){case"debug":break;case"destroyOnUnregister":o=t;break;case"initialValues":k.initialize(t);break;case"keepDirtyOnReinitialize":a=t;break;case"mutators":(u=t)?(Object.keys(c).forEach(function(e){e in t||delete c[e]}),Object.keys(t).forEach(function(e){c[e]=i(e)})):Object.keys(c).forEach(function(e){delete c[e]});break;case"onSubmit":s=t;break;case"validate":f=t,g(void 0,function(){p(),j()});break;case"validateOnBlur":n=t;break;default:throw new Error("Unrecognised option "+e)}},submit:function(){var t=d.formState;if(d.formState.error||B(d.formState.errors))return E(),d.formState.submitFailed=!0,j(),void p();var e=Object.keys(S);if(e.length)Promise.all(e.reduce(function(e,t){return e.push(S[Number(t)]),e},[])).then(function(){return k.submit()});else{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[A],E()):(delete t.submitErrors,delete t.submitError,t.submitFailed=!1,t.submitSucceeded=!0),j(),p(),r=!0,i&&i(e),e};if(t.submitting=!0,t.submitFailed=!1,t.submitSucceeded=!1,t.lastSubmittedValues=V({},t.values),3===s.length){if(s(t.values,k,n),!r)return j(),new Promise(function(e){i=e})}else{var a=s(t.values,k);if(a&&_(a))return j(),a.then(n);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=z(e),r=d.subscribers,n=d.lastFormState,a=r.index++;r.entries[a]={subscriber:i,subscription:t};var u=O();return u!==n&&(d.lastFormState=u),M(i,t,u,u,q,!0),function(){delete r.entries[a]}}};return k},e.configOptions=["debug","initialValues","keepDirtyOnReinitialize","mutators","onSubmit","validate","validateOnBlur"],e.version="4.8.0",e.ARRAY_ERROR=P,e.FORM_ERROR=A,e.formSubscriptionItems=l,e.fieldSubscriptionItems=a,e.getIn=N,e.setIn=R,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=final-form.umd.min.js.map

@@ -156,2 +156,3 @@ export type Subscriber<V> = (value: V) => void

| 'debug'
| 'destroyOnUnregister'
| 'initialValues'

@@ -215,2 +216,3 @@ | 'keepDirtyOnReinitialize'

debug?: DebugFunction
destroyOnUnregister?: boolean
initialValues?: object

@@ -217,0 +219,0 @@ keepDirtyOnReinitialize?: boolean

{
"name": "final-form",
"version": "4.7.3",
"version": "4.8.0",
"description": "🏁 Framework agnostic, high performance, subscription-based form state management",

@@ -5,0 +5,0 @@ "main": "dist/final-form.cjs.js",

@@ -126,2 +126,3 @@ # 🏁 Final Form

* [`debug?: DebugFunction`](#debug-debugfunction)
* [`destroyOnUnregister?: boolean`](#destroyonunregister-boolean)
* [`keepDirtyOnReinitialize?: boolean`](#keepdirtyonreinitialize-boolean)

@@ -407,2 +408,6 @@ * [`initialValues?: Object`](#initialvalues-object)

#### `destroyOnUnregister?: boolean`
If `true`, the value of a field will be destroyed when that field is unregistered. Defaults to `false`. Can be useful when creating dynamic forms where only form values displayed need be submitted.
#### `keepDirtyOnReinitialize?: boolean`

@@ -409,0 +414,0 @@

Sorry, the diff of this file is not supported yet

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