final-form
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -446,15 +446,3 @@ 'use strict'; | ||
} | ||
var formState = { | ||
dirty: false, | ||
errors: {}, | ||
initialValues: initialValues && _extends({}, initialValues), | ||
invalid: false, | ||
pristine: true, | ||
submitting: false, | ||
submitFailed: false, | ||
submitSucceeded: false, | ||
valid: true, | ||
validating: 0, | ||
values: initialValues ? _extends({}, initialValues) : {} | ||
}; | ||
var state = { | ||
@@ -464,3 +452,15 @@ subscribers: { index: 0, entries: {} }, | ||
fields: {}, | ||
formState: formState, | ||
formState: { | ||
dirty: false, | ||
errors: {}, | ||
initialValues: initialValues && _extends({}, initialValues), | ||
invalid: false, | ||
pristine: true, | ||
submitting: false, | ||
submitFailed: false, | ||
submitSucceeded: false, | ||
valid: true, | ||
validating: 0, | ||
values: initialValues ? _extends({}, initialValues) : {} | ||
}, | ||
lastFormState: undefined | ||
@@ -621,5 +621,3 @@ }; | ||
var hasSyncErrors = function hasSyncErrors() { | ||
return formState.error || Object.keys(state.fields).some(function (key) { | ||
return state.fields[key].error; | ||
}); | ||
return !!(state.formState.error || Object.keys(state.formState.errors).length); | ||
}; | ||
@@ -681,4 +679,4 @@ | ||
var previous = fields[name]; | ||
if (previous && previous.active) { | ||
// can only blur registered active fields | ||
if (previous) { | ||
// can only blur registered fields | ||
delete formState.active; | ||
@@ -685,0 +683,0 @@ fields[name] = _extends({}, previous, { |
@@ -442,15 +442,3 @@ // | ||
} | ||
var formState = { | ||
dirty: false, | ||
errors: {}, | ||
initialValues: initialValues && _extends({}, initialValues), | ||
invalid: false, | ||
pristine: true, | ||
submitting: false, | ||
submitFailed: false, | ||
submitSucceeded: false, | ||
valid: true, | ||
validating: 0, | ||
values: initialValues ? _extends({}, initialValues) : {} | ||
}; | ||
var state = { | ||
@@ -460,3 +448,15 @@ subscribers: { index: 0, entries: {} }, | ||
fields: {}, | ||
formState: formState, | ||
formState: { | ||
dirty: false, | ||
errors: {}, | ||
initialValues: initialValues && _extends({}, initialValues), | ||
invalid: false, | ||
pristine: true, | ||
submitting: false, | ||
submitFailed: false, | ||
submitSucceeded: false, | ||
valid: true, | ||
validating: 0, | ||
values: initialValues ? _extends({}, initialValues) : {} | ||
}, | ||
lastFormState: undefined | ||
@@ -617,5 +617,3 @@ }; | ||
var hasSyncErrors = function hasSyncErrors() { | ||
return formState.error || Object.keys(state.fields).some(function (key) { | ||
return state.fields[key].error; | ||
}); | ||
return !!(state.formState.error || Object.keys(state.formState.errors).length); | ||
}; | ||
@@ -677,4 +675,4 @@ | ||
var previous = fields[name]; | ||
if (previous && previous.active) { | ||
// can only blur registered active fields | ||
if (previous) { | ||
// can only blur registered fields | ||
delete formState.active; | ||
@@ -681,0 +679,0 @@ fields[name] = _extends({}, previous, { |
@@ -448,15 +448,3 @@ (function (global, factory) { | ||
} | ||
var formState = { | ||
dirty: false, | ||
errors: {}, | ||
initialValues: initialValues && _extends({}, initialValues), | ||
invalid: false, | ||
pristine: true, | ||
submitting: false, | ||
submitFailed: false, | ||
submitSucceeded: false, | ||
valid: true, | ||
validating: 0, | ||
values: initialValues ? _extends({}, initialValues) : {} | ||
}; | ||
var state = { | ||
@@ -466,3 +454,15 @@ subscribers: { index: 0, entries: {} }, | ||
fields: {}, | ||
formState: formState, | ||
formState: { | ||
dirty: false, | ||
errors: {}, | ||
initialValues: initialValues && _extends({}, initialValues), | ||
invalid: false, | ||
pristine: true, | ||
submitting: false, | ||
submitFailed: false, | ||
submitSucceeded: false, | ||
valid: true, | ||
validating: 0, | ||
values: initialValues ? _extends({}, initialValues) : {} | ||
}, | ||
lastFormState: undefined | ||
@@ -623,5 +623,3 @@ }; | ||
var hasSyncErrors = function hasSyncErrors() { | ||
return formState.error || Object.keys(state.fields).some(function (key) { | ||
return state.fields[key].error; | ||
}); | ||
return !!(state.formState.error || Object.keys(state.formState.errors).length); | ||
}; | ||
@@ -683,4 +681,4 @@ | ||
var previous = fields[name]; | ||
if (previous && previous.active) { | ||
// can only blur registered active fields | ||
if (previous) { | ||
// can only blur registered fields | ||
delete formState.active; | ||
@@ -687,0 +685,0 @@ fields[name] = _extends({}, previous, { |
@@ -1,2 +0,2 @@ | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(e["final-form"]={})}(this,function(e){"use strict";function r(e,r,t,i,n){var o=n(t,i,r,arguments.length>5&&void 0!==arguments[5]&&arguments[5]);o&&e(o)}function t(e,t,i,n){var o=e.entries;Object.keys(o).forEach(function(e){var a=o[Number(e)],u=a.subscription;r(a.subscriber,u,t,i,n)})}var i=function(e){if(null===e||void 0===e)return[];if("string"!=typeof e)throw new Error("toPath() expects a string");return e.length?e.split(/[.[\]]+/).filter(Boolean):[]},n=function(e,r){var t=i(r),n=e,o=!0,a=!1,u=void 0;try{for(var s,f=t[Symbol.iterator]();!(o=(s=f.next()).done);o=!0){var l=s.value;if(void 0===n||null===n||!isNaN(n))return;if(Array.isArray(n)&&isNaN(l))return;n=n[l]}}catch(e){a=!0,u=e}finally{try{!o&&f.return&&f.return()}finally{if(a)throw u}}return n},o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a=function(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e},u=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e},s=function(e){if(Array.isArray(e)){for(var r=0,t=Array(e.length);r<e.length;r++)t[r]=e[r];return t}return Array.from(e)},f=function e(r,t,i,n){if(t>=i.length)return n;var o=i[t];if(isNaN(o)){if(void 0===r||null===r){var f=e(void 0,t+1,i,n);return void 0===f?void 0:a({},o,f)}if(Array.isArray(r))throw new Error("Cannot set a non-numeric property on an array");var l=e(r[o],t+1,i,n),c=Object.keys(r).length;return void 0===l&&(void 0===r[o]&&0===c||void 0!==r[o]&&c<=1)?void 0:u({},r,a({},o,l))}var d=Number(o);if(void 0===r||null===r){var v=e(void 0,t+1,i,n);if(void 0===v)return;var b=[];return b[d]=v,b}if(!Array.isArray(r))throw new Error("Cannot set a numeric property on an object");var m=r[d],h=e(m,t+1,i,n);if(void 0!==h||!(void 0===m&&0===r.length||void 0!==m&&1===r.length)){var y=[].concat(s(r));return void 0===h?y.splice(d,1):y[d]=h,y}},l=function(e,r,t){if(void 0===e||null===e)throw new Error("Cannot call setIn() with "+String(e)+" state");if(void 0===r||null===r)throw new Error("Cannot call setIn() with "+String(r)+" key");return f(e,0,i(r),t)},c=function(e,r){var t=e.initialValues,i=e.submitFailed,o=e.submitSucceeded,a=e.values,u=r.active,s=r.blur,f=r.change,l=r.error,c=r.focus,d=r.name,v=r.submitError,b=r.touched,m=r.visited,h=n(a,d),y=t&&n(t,d),S=y===h,g=!l&&!v;return{active:u,blur:s,change:f,dirty:!S,error:l,focus:c,initial:y,invalid:!g,length:Array.isArray(h)?h.length:void 0,name:d,pristine:S,submitError:v,submitFailed:i,submitSucceeded:o,touched:b,valid:g,value:h,visited:m}},d=["active","data","dirty","error","initial","invalid","length","pristine","submitError","submitFailed","submitSucceeded","touched","valid","value","visited"],v=function(e,r){if(e===r)return!0;if("object"!==(void 0===e?"undefined":o(e))||!e||"object"!==(void 0===r?"undefined":o(r))||!r)return!1;var t=Object.keys(e),i=Object.keys(r);if(t.length!==i.length)return!1;for(var n=Object.prototype.hasOwnProperty.bind(r),a=0;a<t.length;a++){var u=t[a];if(!n(u)||e[u]!==r[u])return!1}return!0},b=function(e,r,t,i,n,o){var a=!1;return n.forEach(function(n){i[n]&&(e[n]=r[n],t&&(~o.indexOf(n)?v(r[n],t[n]):r[n]===t[n])||(a=!0))}),a},m=["data"],h=function(e,r,t,i){var n={blur:e.blur,change:e.change,focus:e.focus,name:e.name};return b(n,e,r,t,d,m)||!r||i?n:void 0},y=["active","dirty","error","errors","initialValues","invalid","pristine","submitting","submitError","submitErrors","submitFailed","submitSucceeded","valid","validating","values"],S=[],g=function(e,r,t,i){var n={};return b(n,e,r,t,y,S)||!r||i?n:void 0},p=function(e){var r=void 0,t=void 0;return function(){for(var i=arguments.length,n=Array(i),o=0;o<i;o++)n[o]=arguments[o];return r&&n.length===r.length&&!n.some(function(e,t){return!v(r[t],e)})||(r=n,t=e.apply(void 0,n)),t}},E=function(e){return!!e&&("object"===(void 0===e?"undefined":o(e))||"function"==typeof e)&&"function"==typeof e.then},O=Symbol("form-error"),j=function(e){var r=e.active,t=e.error,i=e.errors,n=e.initialValues,o=e.pristine,a=e.submitting,u=e.submitFailed,s=e.submitSucceeded,f=e.submitError,l=e.submitErrors,c=e.valid;return{active:r,dirty:!o,error:t,errors:i,invalid:!c,initialValues:n,pristine:o,submitting:a,submitFailed:u,submitSucceeded:s,submitError:f,submitErrors:l,valid:c,validating:e.validating>0,values:e.values}};e.createForm=function(e){if(!e)throw new Error("No config specified");var i=e.debug,o=e.initialValues,a=e.mutators,f=e.onSubmit,d=e.validate,b=e.validateOnBlur;if(!f)throw new Error("No onSubmit function specified");var m={dirty:!1,errors:{},initialValues:o&&u({},o),invalid:!1,pristine:!0,submitting:!1,submitFailed:!1,submitSucceeded:!1,valid:!0,validating:0,values:o?u({},o):{}},y={subscribers:{index:0,entries:{}},fieldSubscribers:{},fields:{},formState:m,lastFormState:void 0},S=!1,w=function(e,r,t){if(e.fields[r]){var i=t(n(e.formState.values,r));e.formState.values=l(e.formState.values,r,i)||{}}},k=a&&Object.keys(a).reduce(function(e,r){return e[r]=function(){for(var e=arguments.length,t=Array(e),i=0;i<e;i++)t[i]=arguments[i];var o={formState:y.formState,fields:y.fields},u=a[r](t,o,{changeValue:w,getIn:n,setIn:l,shallowEqual:v});return y.formState=o.formState,y.fields=o.fields,N(function(){V(),C()}),u},e},{}),F=function(e){var r=[];if(d){var t=d(u({},y.formState.values));E(t)?r.push(t.then(e)):e(t)}return r},A=function(e,r){var t=e.validators,i=[];if(Object.keys(t).length){var o=void 0;Object.keys(t).forEach(function(a){var u=(0,t[Number(a)])(n(y.formState.values,e.name),y.formState.values);u&&E(u)?i.push(u.then(r)):o||(o=u)}),r(o)}return i},N=function(e){var r=y.fields,t=y.formState,i=Object.keys(r);if(d||i.some(function(e){return r[e].validators&&Object.keys(r[e].validators).length})){var o={},a={},f=[].concat(s(F(function(e){o=e||{}})),s(i.reduce(function(e,t){return e.concat(A(r[t],function(e){a[t]=e}))},[]))),c=function(){var e=u({},o);i.forEach(function(t){var i=a[t]||n(o,t);e=l(e,t,i)||{},r[t].error=i}),v(t.errors,e)||(t.errors=e),t.error=o[O]};c(),f.length?(y.formState.validating++,e&&e(),Promise.all(f).then(function(){y.formState.validating--,c(),e&&e()})):e&&e()}else e&&e()},V=function(e){if(!S){var r=y.fields,i=y.fieldSubscribers,n=y.formState;Object.keys(r).forEach(function(e){var o=r[e],a=c(n,o),u=o.lastFieldState;v(a,u)||(o.lastFieldState=a,t(i[e],a,u,h))})}},x=function(){return m.error||Object.keys(y.fields).some(function(e){return y.fields[e].error})},P=function(){var e=y.fields,r=y.formState,t=y.lastFormState,i=Object.keys(e);r.pristine=i.every(function(e){return n(r.values,e)===n(r.initialValues,e)}),r.valid=!(r.error||r.submitError||Object.keys(r.errors).length||r.submitErrors&&Object.keys(r.submitErrors).length);var o=j(r);return t&&v(t,o)?t:o},I=function(){return i&&!1&&i(j(y.formState),Object.keys(y.fields).reduce(function(e,r){return e[r]=y.fields[r],e},{}))},C=function(){if(I(),!S){var e=y.lastFormState,r=P();r!==e&&(y.lastFormState=r,t(y.subscribers,r,e,g))}};N();var R={batch:function(e){S=!0,e(),S=!1,V(),C()},blur:function(e){var r=y.fields,t=y.formState,i=r[e];i&&i.active&&(delete t.active,r[e]=u({},i,{active:!1,touched:!0}),b?N(function(){V(),C()}):(V(),C()))},change:function(e,r){var t=y.fields,i=y.formState;t[e]&&n(i.values,e)!==r&&(w(y,e,function(){return r}),b?(V(),C()):N(function(){V(),C()}))},focus:function(e){var r=y.fields[e];r&&!r.active&&(y.formState.active=e,r.active=!0,r.visited=!0,V(),C())},mutators:k,getState:function(){return j(y.formState)},initialize:function(e){var r=y.fields,t=y.formState;t.initialValues=e,t.values=e,Object.keys(r).forEach(function(e){var t=r[e];t.touched=!1,t.visited=!1}),N(function(){V(),C()})},registerField:function(e,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=arguments[3];y.fieldSubscribers[e]||(y.fieldSubscribers[e]={index:0,entries:{}});var a=y.fieldSubscribers[e].index++;if(y.fieldSubscribers[e].entries[a]={subscriber:p(t),subscription:i},!y.fields[e]){var u=y.formState.initialValues?n(y.formState.initialValues,e):void 0;y.fields[e]={active:!1,blur:function(){return R.blur(e)},change:function(r){return R.change(e,r)},data:{},focus:function(){return R.focus(e)},initial:u,lastFieldState:void 0,name:e,pristine:!0,touched:!1,valid:!0,value:u,validators:{},visited:!1}}o&&(y.fields[e].validators[a]=o);var s=!1,f=function(){var n=c(y.formState,y.fields[e]);r(t,i,n,void 0,h,!0),y.fields[e].lastFieldState=n,s=!0};return N(function(){C(),s||f(),V()}),function(){delete y.fields[e].validators[a],delete y.fieldSubscribers[e].entries[a],Object.keys(y.fieldSubscribers[e].entries).length||(delete y.fieldSubscribers[e],delete y.fields[e]),N(function(){V(),C()})}},reset:function(){R.initialize(y.formState.initialValues||{})},submit:function(){var e=y.formState,r=y.fields;if(x())return Object.keys(r).forEach(function(e){r[e].touched=!0}),void V();var t=void 0,i=!1,o=function(o){e.submitting=!1,o&&(Object.keys(o).length||Object.getOwnPropertySymbols(o).length)?(e.submitFailed=!0,e.submitSucceeded=!1,e.submitErrors=o,Object.keys(r).forEach(function(e){r[e].submitError=o&&n(o,e)}),e.submitError=o[O]):(Object.keys(r).forEach(function(e){delete r[e].submitError}),delete e.submitErrors,delete e.submitError,e.submitFailed=!1,e.submitSucceeded=!0),C(),V(),i=!0,t&&t()};if(e.submitting=!0,e.submitFailed=!1,e.submitSucceeded=!1,2===f.length){if(f(e.values,o),!i)return C(),new Promise(function(e){t=e})}else{var a=f(e.values);if(a&&E(a))return C(),a.then(o);o(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=p(e),n=y.subscribers,o=y.lastFormState,a=n.index++;n.entries[a]={subscriber:i,subscription:t};var u=P();return u!==o&&(y.lastFormState=u),r(i,t,u,u,g,!0),function(){delete n.entries[a]}}};return R},e.FORM_ERROR=O,e.version="1.1.0",e.formSubscriptionItems=y,e.fieldSubscriptionItems=d,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r(e["final-form"]={})}(this,function(e){"use strict";function r(e,r,t,i,n){var o=n(t,i,r,arguments.length>5&&void 0!==arguments[5]&&arguments[5]);o&&e(o)}function t(e,t,i,n){var o=e.entries;Object.keys(o).forEach(function(e){var a=o[Number(e)],u=a.subscription;r(a.subscriber,u,t,i,n)})}var i=function(e){if(null===e||void 0===e)return[];if("string"!=typeof e)throw new Error("toPath() expects a string");return e.length?e.split(/[.[\]]+/).filter(Boolean):[]},n=function(e,r){var t=i(r),n=e,o=!0,a=!1,u=void 0;try{for(var s,l=t[Symbol.iterator]();!(o=(s=l.next()).done);o=!0){var f=s.value;if(void 0===n||null===n||!isNaN(n))return;if(Array.isArray(n)&&isNaN(f))return;n=n[f]}}catch(e){a=!0,u=e}finally{try{!o&&l.return&&l.return()}finally{if(a)throw u}}return n},o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a=function(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e},u=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e},s=function(e){if(Array.isArray(e)){for(var r=0,t=Array(e.length);r<e.length;r++)t[r]=e[r];return t}return Array.from(e)},l=function(e,r,t){if(void 0===e||null===e)throw new Error("Cannot call setIn() with "+String(e)+" state");if(void 0===r||null===r)throw new Error("Cannot call setIn() with "+String(r)+" key");return function e(r,t,i,n){if(t>=i.length)return n;var o=i[t];if(isNaN(o)){if(void 0===r||null===r){var l=e(void 0,t+1,i,n);return void 0===l?void 0:a({},o,l)}if(Array.isArray(r))throw new Error("Cannot set a non-numeric property on an array");var f=e(r[o],t+1,i,n),c=Object.keys(r).length;return void 0===f&&(void 0===r[o]&&0===c||void 0!==r[o]&&c<=1)?void 0:u({},r,a({},o,f))}var d=Number(o);if(void 0===r||null===r){var v=e(void 0,t+1,i,n);if(void 0===v)return;var b=[];return b[d]=v,b}if(!Array.isArray(r))throw new Error("Cannot set a numeric property on an object");var m=r[d],h=e(m,t+1,i,n);if(void 0!==h||!(void 0===m&&0===r.length||void 0!==m&&1===r.length)){var y=[].concat(s(r));return void 0===h?y.splice(d,1):y[d]=h,y}}(e,0,i(r),t)},f=function(e,r){var t=e.initialValues,i=e.submitFailed,o=e.submitSucceeded,a=e.values,u=r.active,s=r.blur,l=r.change,f=r.error,c=r.focus,d=r.name,v=r.submitError,b=r.touched,m=r.visited,h=n(a,d),y=t&&n(t,d),S=y===h,g=!f&&!v;return{active:u,blur:s,change:l,dirty:!S,error:f,focus:c,initial:y,invalid:!g,length:Array.isArray(h)?h.length:void 0,name:d,pristine:S,submitError:v,submitFailed:i,submitSucceeded:o,touched:b,valid:g,value:h,visited:m}},c=["active","data","dirty","error","initial","invalid","length","pristine","submitError","submitFailed","submitSucceeded","touched","valid","value","visited"],d=function(e,r){if(e===r)return!0;if("object"!==(void 0===e?"undefined":o(e))||!e||"object"!==(void 0===r?"undefined":o(r))||!r)return!1;var t=Object.keys(e),i=Object.keys(r);if(t.length!==i.length)return!1;for(var n=Object.prototype.hasOwnProperty.bind(r),a=0;a<t.length;a++){var u=t[a];if(!n(u)||e[u]!==r[u])return!1}return!0},v=function(e,r,t,i,n,o){var a=!1;return n.forEach(function(n){i[n]&&(e[n]=r[n],t&&(~o.indexOf(n)?d(r[n],t[n]):r[n]===t[n])||(a=!0))}),a},b=["data"],m=function(e,r,t,i){var n={blur:e.blur,change:e.change,focus:e.focus,name:e.name};return v(n,e,r,t,c,b)||!r||i?n:void 0},h=["active","dirty","error","errors","initialValues","invalid","pristine","submitting","submitError","submitErrors","submitFailed","submitSucceeded","valid","validating","values"],y=[],S=function(e,r,t,i){var n={};return v(n,e,r,t,h,y)||!r||i?n:void 0},g=function(e){var r=void 0,t=void 0;return function(){for(var i=arguments.length,n=Array(i),o=0;o<i;o++)n[o]=arguments[o];return r&&n.length===r.length&&!n.some(function(e,t){return!d(r[t],e)})||(r=n,t=e.apply(void 0,n)),t}},p=function(e){return!!e&&("object"===(void 0===e?"undefined":o(e))||"function"==typeof e)&&"function"==typeof e.then},E=Symbol("form-error"),O=function(e){var r=e.active,t=e.error,i=e.errors,n=e.initialValues,o=e.pristine,a=e.submitting,u=e.submitFailed,s=e.submitSucceeded,l=e.submitError,f=e.submitErrors,c=e.valid;return{active:r,dirty:!o,error:t,errors:i,invalid:!c,initialValues:n,pristine:o,submitting:a,submitFailed:u,submitSucceeded:s,submitError:l,submitErrors:f,valid:c,validating:e.validating>0,values:e.values}};e.createForm=function(e){if(!e)throw new Error("No config specified");e.debug;var i=e.initialValues,o=e.mutators,a=e.onSubmit,c=e.validate,v=e.validateOnBlur;if(!a)throw new Error("No onSubmit function specified");var b={subscribers:{index:0,entries:{}},fieldSubscribers:{},fields:{},formState:{dirty:!1,errors:{},initialValues:i&&u({},i),invalid:!1,pristine:!0,submitting:!1,submitFailed:!1,submitSucceeded:!1,valid:!0,validating:0,values:i?u({},i):{}},lastFormState:void 0},h=!1,y=function(e,r,t){if(e.fields[r]){var i=t(n(e.formState.values,r));e.formState.values=l(e.formState.values,r,i)||{}}},j=o&&Object.keys(o).reduce(function(e,r){return e[r]=function(){for(var e=arguments.length,t=Array(e),i=0;i<e;i++)t[i]=arguments[i];var a={formState:b.formState,fields:b.fields},u=o[r](t,a,{changeValue:y,getIn:n,setIn:l,shallowEqual:d});return b.formState=a.formState,b.fields=a.fields,w(function(){F(),A()}),u},e},{}),w=function(e){var r=b.fields,t=b.formState,i=Object.keys(r);if(c||i.some(function(e){return r[e].validators&&Object.keys(r[e].validators).length})){var o={},a={},f=[].concat(s(function(e){var r=[];if(c){var t=c(u({},b.formState.values));p(t)?r.push(t.then(e)):e(t)}return r}(function(e){o=e||{}})),s(i.reduce(function(e,t){return e.concat(function(e,r){var t=e.validators,i=[];if(Object.keys(t).length){var o=void 0;Object.keys(t).forEach(function(a){var u=(0,t[Number(a)])(n(b.formState.values,e.name),b.formState.values);u&&p(u)?i.push(u.then(r)):o||(o=u)}),r(o)}return i}(r[t],function(e){a[t]=e}))},[]))),v=function(){var e=u({},o);i.forEach(function(t){var i=a[t]||n(o,t);e=l(e,t,i)||{},r[t].error=i}),d(t.errors,e)||(t.errors=e),t.error=o[E]};v(),f.length?(b.formState.validating++,e&&e(),Promise.all(f).then(function(){b.formState.validating--,v(),e&&e()})):e&&e()}else e&&e()},F=function(e){if(!h){var r=b.fields,i=b.fieldSubscribers,n=b.formState;Object.keys(r).forEach(function(e){var o=r[e],a=f(n,o),u=o.lastFieldState;d(a,u)||(o.lastFieldState=a,t(i[e],a,u,m))})}},k=function(){var e=b.fields,r=b.formState,t=b.lastFormState,i=Object.keys(e);r.pristine=i.every(function(e){return n(r.values,e)===n(r.initialValues,e)}),r.valid=!(r.error||r.submitError||Object.keys(r.errors).length||r.submitErrors&&Object.keys(r.submitErrors).length);var o=O(r);return t&&d(t,o)?t:o},A=function(){if(!h){var e=b.lastFormState,r=k();r!==e&&(b.lastFormState=r,t(b.subscribers,r,e,S))}};w();var N={batch:function(e){h=!0,e(),h=!1,F(),A()},blur:function(e){var r=b.fields,t=b.formState,i=r[e];i&&(delete t.active,r[e]=u({},i,{active:!1,touched:!0}),v?w(function(){F(),A()}):(F(),A()))},change:function(e,r){var t=b.fields,i=b.formState;t[e]&&n(i.values,e)!==r&&(y(b,e,function(){return r}),v?(F(),A()):w(function(){F(),A()}))},focus:function(e){var r=b.fields[e];r&&!r.active&&(b.formState.active=e,r.active=!0,r.visited=!0,F(),A())},mutators:j,getState:function(){return O(b.formState)},initialize:function(e){var r=b.fields,t=b.formState;t.initialValues=e,t.values=e,Object.keys(r).forEach(function(e){var t=r[e];t.touched=!1,t.visited=!1}),w(function(){F(),A()})},registerField:function(e,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=arguments[3];b.fieldSubscribers[e]||(b.fieldSubscribers[e]={index:0,entries:{}});var a=b.fieldSubscribers[e].index++;if(b.fieldSubscribers[e].entries[a]={subscriber:g(t),subscription:i},!b.fields[e]){var u=b.formState.initialValues?n(b.formState.initialValues,e):void 0;b.fields[e]={active:!1,blur:function(){return N.blur(e)},change:function(r){return N.change(e,r)},data:{},focus:function(){return N.focus(e)},initial:u,lastFieldState:void 0,name:e,pristine:!0,touched:!1,valid:!0,value:u,validators:{},visited:!1}}o&&(b.fields[e].validators[a]=o);var s=!1;return w(function(){A(),s||function(){var n=f(b.formState,b.fields[e]);r(t,i,n,void 0,m,!0),b.fields[e].lastFieldState=n,s=!0}(),F()}),function(){delete b.fields[e].validators[a],delete b.fieldSubscribers[e].entries[a],Object.keys(b.fieldSubscribers[e].entries).length||(delete b.fieldSubscribers[e],delete b.fields[e]),w(function(){F(),A()})}},reset:function(){N.initialize(b.formState.initialValues||{})},submit:function(){var e=b.formState,r=b.fields;if(b.formState.error||Object.keys(b.formState.errors).length)return Object.keys(r).forEach(function(e){r[e].touched=!0}),void F();var t=void 0,i=!1,o=function(o){e.submitting=!1,o&&(Object.keys(o).length||Object.getOwnPropertySymbols(o).length)?(e.submitFailed=!0,e.submitSucceeded=!1,e.submitErrors=o,Object.keys(r).forEach(function(e){r[e].submitError=o&&n(o,e)}),e.submitError=o[E]):(Object.keys(r).forEach(function(e){delete r[e].submitError}),delete e.submitErrors,delete e.submitError,e.submitFailed=!1,e.submitSucceeded=!0),A(),F(),i=!0,t&&t()};if(e.submitting=!0,e.submitFailed=!1,e.submitSucceeded=!1,2===a.length){if(a(e.values,o),!i)return A(),new Promise(function(e){t=e})}else{var u=a(e.values);if(u&&p(u))return A(),u.then(o);o(u)}},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=g(e),n=b.subscribers,o=b.lastFormState,a=n.index++;n.entries[a]={subscriber:i,subscription:t};var u=k();return u!==o&&(b.lastFormState=u),r(i,t,u,u,S,!0),function(){delete n.entries[a]}}};return N},e.FORM_ERROR=E,e.version="1.1.0",e.formSubscriptionItems=h,e.fieldSubscriptionItems=c,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=final-form.umd.min.js.map |
{ | ||
"name": "final-form", | ||
"version": "1.2.0", | ||
"description": "🏁 Framework agnostic, high performance, subscription-based form state management", | ||
"version": "1.2.1", | ||
"description": | ||
"🏁 Framework agnostic, high performance, subscription-based form state management", | ||
"main": "dist/final-form.cjs.js", | ||
"jsnext:main": "dist/final-form.es.js", | ||
"module": "dist/final-form.es.js", | ||
"files": [ | ||
"dist" | ||
], | ||
"files": ["dist"], | ||
"scripts": { | ||
@@ -16,3 +15,4 @@ "start": "nps", | ||
}, | ||
"author": "Erik Rasmussen <rasmussenerik@gmail.com> (http://github.com/erikras)", | ||
"author": | ||
"Erik Rasmussen <rasmussenerik@gmail.com> (http://github.com/erikras)", | ||
"license": "MIT", | ||
@@ -61,6 +61,3 @@ "repository": { | ||
"lint-staged": { | ||
"*.{js,json,md,css}": [ | ||
"prettier --write", | ||
"git add" | ||
] | ||
"*.{js,json,md,css}": ["prettier --write", "git add"] | ||
}, | ||
@@ -67,0 +64,0 @@ "bundlesize": [ |
@@ -154,3 +154,3 @@ # 🏁 Final Form | ||
* [`initialize: (values: Object) => void`](#initialize-values-object--void) | ||
* [`mutators: ?{ [string]: Function }](#mutators--string-function-) | ||
* [`mutators: ?{ [string]: Function }`](#mutators--string-function-) | ||
* [`submit: () => ?Promise<?Object>`](#submit---promiseobject) | ||
@@ -223,3 +223,3 @@ * [`subscribe: (subscriber: FormSubscriber, subscription: FormSubscription) => Unsubscribe`](#subscribe-subscriber-formsubscriber-subscription-formsubscription--unsubscribe) | ||
* [`MutableState: { formState: InternalFormState, fields: { [string]: InternalFieldState } }`](#mutablestate--formstate-internalformstate-fields--string-internalfieldstate--) | ||
* [`Mutator: (args: any[], state: MutableState, tools: Tools) => any](#mutator-args-any-state-mutablestate-tools-tools--any) | ||
* [`Mutator: (args: any[], state: MutableState, tools: Tools) => any`](#mutator-args-any-state-mutablestate-tools-tools--any) | ||
* [`RegisterField: (name: string, subscriber: FieldSubscriber, subscription: FieldSubscription, validate?: (value: ?any, allValues: Object) => ?any) => Unsubscribe`](#registerfield-name-string-subscriber-fieldsubscriber-subscription-fieldsubscription-validate-value-any-allvalues-object--any--unsubscribe) | ||
@@ -541,3 +541,3 @@ * [`Tools`](#tools) | ||
#### `mutators: ?{ [string]: Function } | ||
#### `mutators: ?{ [string]: Function }` | ||
@@ -864,3 +864,3 @@ The state-bound versions of the mutators provided to [`Config`](#config). | ||
### `Mutator: (args: any[], state: MutableState, tools: Tools) => any | ||
### `Mutator: (args: any[], state: MutableState, tools: Tools) => any` | ||
@@ -867,0 +867,0 @@ A mutator function that takes some arguments, the internal form |
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
128825
2386