final-form-calculate
Version:
Decorator for calculating field values based on other field values in 🏁 Final Form
3 lines (2 loc) • 2.02 kB
JavaScript
((n,e)=>{"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((n="undefined"!=typeof globalThis?globalThis:n||self)["final-form-calculate"]={})})(this,function(n){function s(n,e){for(var t=u(e),r=n,o=0;o<t.length;o++){var f=t[o];if(null==r||"object"!=typeof r||Array.isArray(r)&&isNaN(Number(f)))return;r=r[f]}return r}var e=".".charCodeAt(0),f=/\\(\\)?/g,t=RegExp("[^.[\\]]+|\\[(?:([^\"'][^[]*)|([\"'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2)\\]|(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|$))","g"),r=function(n){var o=[];return n.charCodeAt(0)===e&&o.push(""),n.replace(t,function(n,e,t,r){return t?n=r.replace(f,"$1"):e&&(n=e.trim()),o.push(n),""}),o},o={},i=/[.[\]]+/,u=function(n){if(null==n||!n.length)return[];if("string"!=typeof n)throw new Error("toPath() expects a string");return null==o[n]&&(n.endsWith("[]")?o[n]=n.split(i).filter(Boolean):o[n]=r(n)),o[n]};function l(n){return n&&("object"==typeof n||"function"==typeof n)&&"function"==typeof n.then}function h(n,e){return n===e}n.default=function(){for(var n=arguments.length,e=new Array(n),t=0;t<n;t++)e[t]=arguments[t];return function(c){var a;return c.subscribe(function(n){var u=n.values;c.batch(function(){function f(n,e,t){var r,o=u&&s(u,n),f=a&&s(a,n);e(o,f)||("function"==typeof t?l(r=t(o,n,u,a))?r.then(function(e){Object.keys(e).forEach(function(n){c.change(n,e[n])})}):Object.keys(r).forEach(function(n){c.change(n,r[n])}):Object.keys(t).forEach(function(e){var n=(0,t[e])(o,u,a);l(n)?n.then(function(n){c.change(e,n)}):c.change(e,n)}))}var i=c.getRegisteredFields();e.forEach(function(n){var e,t=n.field,r=n.isEqual,o=n.updates;"string"==typeof t?f(t,r||h,o):(e=Array.isArray(t)?function(e){return~t.indexOf(e)||-1!==t.findIndex(function(n){return n instanceof RegExp&&n.test(e)})}:function(n){return t.test(n)},i.forEach(function(n){e(n)&&f(n,r||h,o)}))}),a=u})},{values:!0})}},Object.defineProperty(n,"__esModule",{value:!0})});
//# sourceMappingURL=final-form-calculate.umd.min.js.map