Comparing version 0.2.0-alpha.0 to 0.2.0-alpha.1
@@ -827,3 +827,3 @@ 'use strict'; | ||
}); | ||
var values = new Map([].concat(initialValues).map(function (_ref2) { | ||
var values = new Map([].concat(initialValues.entries()).map(function (_ref2) { | ||
var key = _ref2[0], | ||
@@ -830,0 +830,0 @@ subject = _ref2[1]; |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),e=Symbol("path"),r=function(t){if("string"==typeof t)return t;var r=new Proxy({path:""},a(!1)),n=t(r);if(n!==r)throw new Error("You must return a value from the argument in the selector function");return n[e]},n=function(t,e,n){var o=r(t);return e.has(o)||e.set(o,n()),e.get(o)},o=function(t){return"object"==typeof t?t:t(new Proxy({path:""},a(!0))).map((function(t){return t[e]}))},u=function t(e,r,n){if(r.startsWith("[")){var o=r.indexOf("]"),u=Number(r.substring(1,o)),a=r.substring(o+1);return a.length?a.startsWith(".")?(e[u]=e[u]||{},t(e[u],a.slice(1),n)):(e[u]=e[u]||[],t(e[u],a,n)):void(e[u]=n)}switch(i(r)){case"array":var c=r.indexOf("["),s=r.substring(0,c),f=r.substring(c);return e[s]=e[s]||[],t(e[s],f,n);case"object":var l=r.indexOf("."),h=r.substring(0,l),v=r.substring(l+1);return e[h]=e[h]||{},t(e[h],v,n);case"terminal":return void(e[r]=n)}},i=function(t){var e=t.indexOf("."),r=t.indexOf("[");return e<0&&r<0?"terminal":e<0?"array":r<0||e<r?"object":"array"},a=function(t){var r={get:function(n,o,u){if(o===e)return n.path;if("symbol"==typeof o)throw new Error("Can't serialize symbols to keys");var i="number"!=typeof o&&isNaN(o)?n.path.length?n.path+"."+o:o:n.path+"["+o+"]";return t&&0===n.path.length?new Proxy({path:i},r):(n.path=i,u)}};return r},c=function(){function t(t){var e=this;this.observers=new Set,this.state=s,t((function(t){e.state=t,e.observers.forEach((function(e){return e(t)}))}))}var e=t.prototype;return e.subscribe=function(t){var e=this;return this.observers.add(t),this.state!==s&&t(this.state),function(){e.observers.delete(t)}},e.hasValue=function(){return this.state!==s},e.getState=function(){if(this.state===s)throw new Error("Empty value");return this.state},t}(),s=Symbol("empty"),f=function(){function t(t){void 0===t&&(t=l),this.observers=new Set,this.state=t}var e=t.prototype;return e.subscribe=function(t){var e=this;return this.observers.add(t),this.state!==l&&t(this.state),function(){e.observers.delete(t)}},e.setState=function(t){this.state=t,this.observers.forEach((function(e){return e(t)}))},e.hasValue=function(){return this.state!==l},e.getState=function(){if(this.state===l)throw new Error("Empty value");return this.state},t}(),l=Symbol("empty"),h=function(t){return new Promise((function(e){if(t.hasValue())return e(t.getState());var r=t.subscribe((function(t){r(),e(t)}))}))},v=function(t){return new c((function(e){var r=!1,n=Array.isArray(t)?[]:{},o=Object.entries(t);o.forEach((function(t){var u=t[0];return t[1].subscribe((function(t){n[u]=t,(r||Object.keys(n).length===o.length)&&(r=!0,e(n))}))}))}))},p=function(){return function(t){return new c((function(e){var r=d;t.subscribe((function(t){t!==r&&e(t),r=t}))}))}},d=Symbol("empty"),y=function(t){return function(e){return new c((function(r){return e.subscribe((function(e){return r(t(e))}))}))}};function b(t){for(var e=t,r=arguments.length,n=new Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];return n.forEach((function(t){e=t(e)})),e}var g=function(){return function(t){return new c((function(e){var r={skip:!0},n=t.subscribe((function(t){return r.skip?void 0:e(t)}));return r.skip=!1,n}))}},m=function(t){return function(e){return new c((function(r){var n=function(){},o=e.subscribe((function(e){n(),n=t(e).subscribe((function(t){return r(t)}))}));return function(){n(),o()}}))}},w=function(t){return function(e){return new c((function(r){var n=0,o=e.subscribe((function(e){n<t&&r(e),++n>=t&&o&&o()}));n>=t&&o()}))}},x=function(){function t(t){var e=this;this.observers=new Set,t((function(t){e.observers.forEach((function(e){return e(t)}))}))}return t.prototype.subscribe=function(t){var e=this;return this.observers.add(t),function(){return e.observers.delete(t)}},t}(),E=function(){function t(){this.observers=new Set}var e=t.prototype;return e.emit=function(t){this.observers.forEach((function(e){return e(t)}))},e.subscribe=function(t){var e=this;return this.observers.add(t),function(){return e.observers.delete(t)}},t}();function S(t,e,r,n,o,u,i){try{var a=t[u](i),c=a.value}catch(t){return void r(t)}a.done?e(c):Promise.resolve(c).then(n,o)}function O(){return(O=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function j(t){return(j=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function L(t,e){return(L=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function _(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function V(t,e,r){return(V=_()?Reflect.construct:function(t,e,r){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(t,n));return r&&L(o,r.prototype),o}).apply(null,arguments)}function k(t){var e="function"==typeof Map?new Map:void 0;return(k=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return V(t,arguments,j(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),L(r,t)})(t)}var A,P=function(t,e){return"function"==typeof t?t(e):"string"==typeof t?Number(e(t)):t},N=function t(e,r){return function(){for(var n=arguments.length,o=new Array(n),u=0;u<n;u++)o[u]=arguments[u];if(r>=e.length)return!0;var i=e[r].apply(e,o),a=function(n){return!0!==n?n:t(e,r+1).apply(void 0,o)};return R(i)?i.then(a):a(i)}},F=function(){return!0},R=function(t){return"object"==typeof t&&!Array.isArray(t)},M=function(t,e){return n(e,t.controlStates,(function(){return new f}))},I=function(t){var e=t.key,n=t.validator$,o=t.value$,u=t.getControlValue$,i=new c((function(t){var i=new Set,a=C;n.subscribe((function(t){return a=t}));var c=C;function s(){if(a===C)throw new Error("No validator defined");if(c===C)throw new Error("No validator defined");try{var n=a(c,(function(t){var e,n=r(t),o=u(n);if(i.has(o)||(i.add(o),(e=o,new x((function(t){return g()(e).subscribe(t)}))).subscribe(s)),!o.hasValue())throw new $(n);return o.getState()}));if("boolean"==typeof n)return t(!0!==n&&[]);if(Array.isArray(n))return t(n);t("pending"),n.then((function(e){return t(!0!==e&&(!1===e?[]:e))}))}catch(r){return r instanceof $?console.warn("Setting control "+e+" error to pending, as the validation depends on a field that hasn't been registered yet",r):console.error(r),t("pending")}}o.subscribe((function(t){c=t,s()}))})),a=new c((function(e){e(!1);var r=function(){};return t.manualError$.subscribe((function(t){e(t),r(),r=b(o,g(),w(1),y((function(){return!1}))).subscribe(e)}))}));return b(v({validatorResult:i,manualResult:a}),y((function(t){var e=t.validatorResult,r=t.manualResult;return!1===r||"pending"===r?e:!1===e||"pending"===e?r:[].concat(r,e)})))},$=function(t){var e,r;function n(e){var r;return(r=t.call(this,"Control "+e+" doesn't have any value yet")||this).name="ValueNotThereYetError",Object.setPrototypeOf(function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(r),n.prototype),r}return r=t,(e=n).prototype=Object.create(r.prototype),e.prototype.constructor=e,e.__proto__=r,n}(k(Error)),C=Symbol("empty"),T=(function(t){var e=function(t){var e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",u=n.asyncIterator||"@@asyncIterator",i=n.toStringTag||"@@toStringTag";function a(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{a({},"")}catch(t){a=function(t,e,r){return t[e]=r}}function c(t,e,r,n){var o=Object.create((e&&e.prototype instanceof l?e:l).prototype),u=new S(n||[]);return o._invoke=function(t,e,r){var n="suspendedStart";return function(o,u){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw u;return{value:void 0,done:!0}}for(r.method=o,r.arg=u;;){var i=r.delegate;if(i){var a=w(i,r);if(a){if(a===f)continue;return a}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=s(t,e,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===f)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}(t,r,u),o}function s(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=c;var f={};function l(){}function h(){}function v(){}var p={};p[o]=function(){return this};var d=Object.getPrototypeOf,y=d&&d(d(O([])));y&&y!==e&&r.call(y,o)&&(p=y);var b=v.prototype=l.prototype=Object.create(p);function g(t){["next","throw","return"].forEach((function(e){a(t,e,(function(t){return this._invoke(e,t)}))}))}function m(t,e){var n;this._invoke=function(o,u){function i(){return new e((function(n,i){!function n(o,u,i,a){var c=s(t[o],t,u);if("throw"!==c.type){var f=c.arg,l=f.value;return l&&"object"==typeof l&&r.call(l,"__await")?e.resolve(l.__await).then((function(t){n("next",t,i,a)}),(function(t){n("throw",t,i,a)})):e.resolve(l).then((function(t){f.value=t,i(f)}),(function(t){return n("throw",t,i,a)}))}a(c.arg)}(o,u,n,i)}))}return n=n?n.then(i,i):i()}}function w(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,w(t,e),"throw"===e.method))return f;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return f}var n=s(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,f;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,f):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,f)}function x(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function E(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function S(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(x,this),this.reset(!0)}function O(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,u=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return u.next=u}}return{next:j}}function j(){return{value:void 0,done:!0}}return h.prototype=b.constructor=v,v.constructor=h,h.displayName=a(v,i,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===h||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,v):(t.__proto__=v,a(t,i,"GeneratorFunction")),t.prototype=Object.create(b),t},t.awrap=function(t){return{__await:t}},g(m.prototype),m.prototype[u]=function(){return this},t.AsyncIterator=m,t.async=function(e,r,n,o,u){void 0===u&&(u=Promise);var i=new m(c(e,r,n,o),u);return t.isGeneratorFunction(r)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},g(b),a(b,i,"Generator"),b[o]=function(){return this},b.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=O,S.prototype={constructor:S,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(E),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return i.type="throw",i.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var u=this.tryEntries[o],i=u.completion;if("root"===u.tryLoc)return n("end");if(u.tryLoc<=this.prev){var a=r.call(u,"catchLoc"),c=r.call(u,"finallyLoc");if(a&&c){if(this.prev<u.catchLoc)return n(u.catchLoc,!0);if(this.prev<u.finallyLoc)return n(u.finallyLoc)}else if(a){if(this.prev<u.catchLoc)return n(u.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<u.finallyLoc)return n(u.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var u=o;break}}u&&("break"===t||"continue"===t)&&u.tryLoc<=e&&e<=u.finallyLoc&&(u=null);var i=u?u.completion:{};return i.type=t,i.arg=e,u?(this.method="next",this.next=u.finallyLoc,f):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),f},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),E(r),f}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;E(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:O(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},t}(t.exports);try{regeneratorRuntime=e}catch(t){Function("r","regeneratorRuntime = r")(e)}}(A={exports:{}}),A.exports),G=function(t,e){var o,u,i=r(e.key);return t.registerControl(e),{getValue:function(){return n(i,t.values,(function(){return new f})).getState()},setValue:function(e){return n(i,t.values,(function(){return new f})).setState(e)},subscribe:function(e){return n(i,t.values,(function(){return new f})).subscribe(e)},touch:(o=T.mark((function e(){var r;return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=M(t,i),e.next=3,h(r);case 3:if(!r.getState().touched){e.next=5;break}return e.abrupt("return");case 5:r.setState(O({},r.getState(),{touched:!0}));case 6:case"end":return e.stop()}}),e)})),u=function(){var t=this,e=arguments;return new Promise((function(r,n){var u=o.apply(t,e);function i(t){S(u,r,n,i,a,"next",t)}function a(t){S(u,r,n,i,a,"throw",t)}i(void 0)}))},function(){return u.apply(this,arguments)})}},K={},W=new f(!1),Y={};exports.isAtLeast=function(t){return function(e,r){var n=P(t,r);return!(Number(e)<n)||["Expected a value of at least "+n]}},exports.isAtMost=function(t){return function(e,r){var n=P(t,r);return!(Number(e)>n)||["Expected a value of at most "+n]}},exports.isGreaterThan=function(t){return function(e,r){var n=P(t,r);return!(Number(e)<=n)||["Expected a value greater than "+n]}},exports.isInteger=function(t){return parseInt(t)===parseFloat(t)||["Expected an integer"]},exports.isLessThan=function(t){return function(e,r){var n=P(t,r);return!(Number(e)>=n)||["Expected a value less than "+n]}},exports.isNumber=function(t){return!isNaN(t)||["Expected a number"]},exports.isRequired=function(t){return null!=t&&""!==t||["required"]},exports.matches=function(t,e){return function(r){return!!t.test(r)||[null!=e?e:"Invalid value"]}},exports.mergeValidators=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return function(){for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];var o=e.map((function(t){return t.apply(void 0,r)})),u=function(t){var e=t.flatMap((function(t){return"boolean"==typeof t?[]:t}));return 0===e.length?!t.some((function(t){return!1===t})):e};return o.some(R)?Promise.all(o).then(u):u(o)}},exports.pipeValidators=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return N(e,0)},exports.readField=function(t,e){try{return n(e,t.values,(function(){return new f})).getState()}catch(t){return}},exports.readForm=function(t){try{return function(t){var e={};for(var r in t)u(e,r,t[r]);return e}(Object.fromEntries([].concat(t.values.entries()).map((function(t){return[t[0],t[1].getState()]}))))}catch(t){return{}}},exports.resetForm=function(t,e){var r=t.values,n=t.initialValues;(e?o(e):[].concat(r.keys())).forEach((function(e){if(r.has(e)&&n.has(e)){r.get(e).setState(n.get(e).getState());var o=M(t,e);o.getState().touched&&o.setState(O({},o.getState(),{touched:!1}))}}))},exports.setFieldError=function(t,e,r){try{M(t,e).getState().manualError.emit(r)}catch(t){console.warn("Can't set error: Field not registered",t)}},exports.setFieldValue=function(t,e,r){n(e,t.values,(function(){return new f})).setState(r)},exports.setInitialValue=function(t,e,r){return n(e,t.initialValues,(function(){return new f})).setState(r)},exports.touchFields=function(t,e,r){void 0===r&&(r=!0),(e?o(e):t.registeredKeys.getState()).forEach((function(e){var n=M(t,e);n.getState().touched!==r&&n.setState(O({},n.getState(),{touched:r}))}))},exports.useControl=function(e,r){var n=G(e,r),o=n.subscribe,u=function(t,e){if(null==t)return{};var r,n,o={},u=Object.keys(t);for(n=0;n<u.length;n++)e.indexOf(r=u[n])>=0||(o[r]=t[r]);return o}(n,["subscribe"]),i=t.useState(u.getValue),a=i[0],c=i[1];return t.useEffect((function(){return o(c)}),[]),O({},u,{value:a})},exports.useControlSubscription=G,exports.useErrors=function(e,r){var n=r?o(r):[K],u=t.useState({}),i=u[0],a=u[1],c=t.useMemo((function(){var t=n[0]===K?b(e.registeredKeys,y((function(t){return Array.from(t)}))):new f(n);return b(t,m((function(t){return v(Object.fromEntries(t.map((function(t){return[t,b(M(e,t),y((function(t){return t.touched?t.error$:W})),p(),m((function(t){return t})))]}))))})),y((function(t){return Object.fromEntries(Object.entries(t).filter((function(t){return!1!==t[1]})))})))}),[e].concat(n));return t.useEffect((function(){return c.subscribe((function(t){return a((function(){return t}))}))}),[c]),i},exports.useForm=function(e){var o=t.useRef(null);return o.current||(o.current=function(t){void 0===t&&(t={});var e=new f(new Set),o=new Map;Object.entries(function t(e){var r={};if(!e)return r;if("object"!=typeof e)throw new Error("Model must be an object");var n=Array.isArray(e)?function(t){return"["+t+"]"}:function(t){return t};return Object.entries(e).forEach((function(e){var o=e[0],u=e[1];if(function(t){return null!==t&&"object"==typeof t&&t.__proto__===Object.prototype}(u)||Array.isArray(u)){var i=t(u);Object.entries(i).forEach((function(t){var e=t[0],u=t[1],i=e.startsWith("[")?"":".";r[n(o)+i+e]=u}))}else r[n(o)]=u})),r}(t.initialValue||{})).forEach((function(t){o.set(t[0],new f(t[1]))}));var u=new Map([].concat(o).map((function(t){return[t[0],new f(t[1].getState())]}))),i=new Map,a=function(t){return n(t,u,(function(){return new f}))};return{registeredKeys:e,registerControl:function(t){var s,l=t.initialValue,h=t.validator,v=void 0===h?F:h,d=r(t.key),g=a(d),m=n(d,i,(function(){return new f}));if(!m.hasValue()){var w=e.getState();w.add(d),e.setState(w);var x=new E;m.setState({touched:!1,validator:v,manualError:x,error$:I({key:d,validator$:b(m,y((function(t){return t.validator})),(s=v,function(t){return new c((function(e){return e(s),t.subscribe(e)}))}),p()),value$:g,manualError$:x,getControlValue$:a})})}v!==m.getState().validator&&m.setState(O({},m.getState(),{validator:v}));var S=n(d,o,(function(){return new f(l)}));S.hasValue()&&S.getState()===l||S.setState(l);var j=n(d,u,(function(){return new f}));j.hasValue()||j.setState(l)},initialValues:o,controlStates:i,values:u,dispose:function(){o.clear(),u.clear(),i.clear()}}}(e)),t.useEffect((function(){return function(){return o.current.dispose()}}),[]),o.current},exports.useInput=function(e,o){void 0===o&&(o={});var u=o.eventType,i=void 0===u?"input":u,a=o.elementProp,c=void 0===a?"value":a,s=t.useRef(null);return t.useEffect((function(){var t=s.current;if(t){var u=o.initialValue,a=void 0===u?"":u,l=o.validator,h=o.key?r(o.key):t.name;if(h){e.registerControl({initialValue:a,key:h,validator:l});var v=n(h,e.values,(function(){return new f})),p=v.subscribe((function(e){t[c]!==e&&(t[c]=e)})),d=function(){var t=M(e,h);t.getState().touched||t.setState(O({},t.getState(),{touched:!0}))};t.addEventListener("blur",d);var y=function(t){return v.setState(t.target[c])};return t.addEventListener(i,y),function(){p(),t.removeEventListener("blur",d),t.removeEventListener(i,y)}}console.error("An input is missing its key. Either supply it through useInput `key` option or through the input's name",t,{options:o})}})),s},exports.useIsPristine=function(e){var r=t.useMemo((function(){return b(e.registeredKeys,m((function(t){return b(v(Array.from(t).map((function(t){var r=n(t,e.initialValues,(function(){return new f})),o=n(t,e.values,(function(){return new f}));return b(v({initialValue:r,value:o}),y((function(t){return t.initialValue===t.value})))}))),y((function(t){return t.every((function(t){return t}))})))})),p())}),[e]),o=t.useState((function(){return!r.hasValue()||r.getState()})),u=o[0],i=o[1];return t.useEffect((function(){return r.subscribe(i)}),[r]),u},exports.useIsValid=function(e,r,n){void 0===r&&(r=!1);var u=n?o(n):[Y],i=t.useMemo((function(){var t=u[0]===Y?b(e.registeredKeys,y((function(t){return Array.from(t)}))):new f(u);return b(t,m((function(t){return v(Object.fromEntries(t.map((function(t){return[t,b(M(e,t),w(1),m((function(t){return t.error$})))]}))))})),y((function(t){return Object.fromEntries(Object.entries(t).filter((function(t){return!1!==t[1]})))})))}),[e].concat(u)),a=t.useMemo((function(){return b(i,y((function(t){var e=Object.values(t),r=!1;return!e.some((function(t){return"pending"!==t||(r=!0,!1)}))&&(!r||"pending")})))}),[i]),c=t.useState((function(){return a.hasValue()?a.getState():r})),s=c[0],l=c[1];return t.useEffect((function(){return a.subscribe(l)}),[a]),s},exports.useWatch=function(e,r){var o=n(r,e.values,(function(){return new f})),u=t.useState((function(){if(o.hasValue())return o.getState()})),i=u[0],a=u[1];return t.useEffect((function(){return o.subscribe(a)}),[o]),i}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),e=Symbol("path"),r=function(t){if("string"==typeof t)return t;var r=new Proxy({path:""},a(!1)),n=t(r);if(n!==r)throw new Error("You must return a value from the argument in the selector function");return n[e]},n=function(t,e,n){var o=r(t);return e.has(o)||e.set(o,n()),e.get(o)},o=function(t){return"object"==typeof t?t:t(new Proxy({path:""},a(!0))).map((function(t){return t[e]}))},u=function t(e,r,n){if(r.startsWith("[")){var o=r.indexOf("]"),u=Number(r.substring(1,o)),a=r.substring(o+1);return a.length?a.startsWith(".")?(e[u]=e[u]||{},t(e[u],a.slice(1),n)):(e[u]=e[u]||[],t(e[u],a,n)):void(e[u]=n)}switch(i(r)){case"array":var c=r.indexOf("["),s=r.substring(0,c),f=r.substring(c);return e[s]=e[s]||[],t(e[s],f,n);case"object":var l=r.indexOf("."),h=r.substring(0,l),v=r.substring(l+1);return e[h]=e[h]||{},t(e[h],v,n);case"terminal":return void(e[r]=n)}},i=function(t){var e=t.indexOf("."),r=t.indexOf("[");return e<0&&r<0?"terminal":e<0?"array":r<0||e<r?"object":"array"},a=function(t){var r={get:function(n,o,u){if(o===e)return n.path;if("symbol"==typeof o)throw new Error("Can't serialize symbols to keys");var i="number"!=typeof o&&isNaN(o)?n.path.length?n.path+"."+o:o:n.path+"["+o+"]";return t&&0===n.path.length?new Proxy({path:i},r):(n.path=i,u)}};return r},c=function(){function t(t){var e=this;this.observers=new Set,this.state=s,t((function(t){e.state=t,e.observers.forEach((function(e){return e(t)}))}))}var e=t.prototype;return e.subscribe=function(t){var e=this;return this.observers.add(t),this.state!==s&&t(this.state),function(){e.observers.delete(t)}},e.hasValue=function(){return this.state!==s},e.getState=function(){if(this.state===s)throw new Error("Empty value");return this.state},t}(),s=Symbol("empty"),f=function(){function t(t){void 0===t&&(t=l),this.observers=new Set,this.state=t}var e=t.prototype;return e.subscribe=function(t){var e=this;return this.observers.add(t),this.state!==l&&t(this.state),function(){e.observers.delete(t)}},e.setState=function(t){this.state=t,this.observers.forEach((function(e){return e(t)}))},e.hasValue=function(){return this.state!==l},e.getState=function(){if(this.state===l)throw new Error("Empty value");return this.state},t}(),l=Symbol("empty"),h=function(t){return new Promise((function(e){if(t.hasValue())return e(t.getState());var r=t.subscribe((function(t){r(),e(t)}))}))},v=function(t){return new c((function(e){var r=!1,n=Array.isArray(t)?[]:{},o=Object.entries(t);o.forEach((function(t){var u=t[0];return t[1].subscribe((function(t){n[u]=t,(r||Object.keys(n).length===o.length)&&(r=!0,e(n))}))}))}))},p=function(){return function(t){return new c((function(e){var r=d;t.subscribe((function(t){t!==r&&e(t),r=t}))}))}},d=Symbol("empty"),y=function(t){return function(e){return new c((function(r){return e.subscribe((function(e){return r(t(e))}))}))}};function b(t){for(var e=t,r=arguments.length,n=new Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];return n.forEach((function(t){e=t(e)})),e}var g=function(){return function(t){return new c((function(e){var r={skip:!0},n=t.subscribe((function(t){return r.skip?void 0:e(t)}));return r.skip=!1,n}))}},m=function(t){return function(e){return new c((function(r){var n=function(){},o=e.subscribe((function(e){n(),n=t(e).subscribe((function(t){return r(t)}))}));return function(){n(),o()}}))}},w=function(t){return function(e){return new c((function(r){var n=0,o=e.subscribe((function(e){n<t&&r(e),++n>=t&&o&&o()}));n>=t&&o()}))}},x=function(){function t(t){var e=this;this.observers=new Set,t((function(t){e.observers.forEach((function(e){return e(t)}))}))}return t.prototype.subscribe=function(t){var e=this;return this.observers.add(t),function(){return e.observers.delete(t)}},t}(),E=function(){function t(){this.observers=new Set}var e=t.prototype;return e.emit=function(t){this.observers.forEach((function(e){return e(t)}))},e.subscribe=function(t){var e=this;return this.observers.add(t),function(){return e.observers.delete(t)}},t}();function S(t,e,r,n,o,u,i){try{var a=t[u](i),c=a.value}catch(t){return void r(t)}a.done?e(c):Promise.resolve(c).then(n,o)}function O(){return(O=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function j(t){return(j=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function L(t,e){return(L=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function _(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function V(t,e,r){return(V=_()?Reflect.construct:function(t,e,r){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(t,n));return r&&L(o,r.prototype),o}).apply(null,arguments)}function k(t){var e="function"==typeof Map?new Map:void 0;return(k=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return V(t,arguments,j(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),L(r,t)})(t)}var A,P=function(t,e){return"function"==typeof t?t(e):"string"==typeof t?Number(e(t)):t},N=function t(e,r){return function(){for(var n=arguments.length,o=new Array(n),u=0;u<n;u++)o[u]=arguments[u];if(r>=e.length)return!0;var i=e[r].apply(e,o),a=function(n){return!0!==n?n:t(e,r+1).apply(void 0,o)};return R(i)?i.then(a):a(i)}},F=function(){return!0},R=function(t){return"object"==typeof t&&!Array.isArray(t)},M=function(t,e){return n(e,t.controlStates,(function(){return new f}))},I=function(t){var e=t.key,n=t.validator$,o=t.value$,u=t.getControlValue$,i=new c((function(t){var i=new Set,a=C;n.subscribe((function(t){return a=t}));var c=C;function s(){if(a===C)throw new Error("No validator defined");if(c===C)throw new Error("No validator defined");try{var n=a(c,(function(t){var e,n=r(t),o=u(n);if(i.has(o)||(i.add(o),(e=o,new x((function(t){return g()(e).subscribe(t)}))).subscribe(s)),!o.hasValue())throw new $(n);return o.getState()}));if("boolean"==typeof n)return t(!0!==n&&[]);if(Array.isArray(n))return t(n);t("pending"),n.then((function(e){return t(!0!==e&&(!1===e?[]:e))}))}catch(r){return r instanceof $?console.warn("Setting control "+e+" error to pending, as the validation depends on a field that hasn't been registered yet",r):console.error(r),t("pending")}}o.subscribe((function(t){c=t,s()}))})),a=new c((function(e){e(!1);var r=function(){};return t.manualError$.subscribe((function(t){e(t),r(),r=b(o,g(),w(1),y((function(){return!1}))).subscribe(e)}))}));return b(v({validatorResult:i,manualResult:a}),y((function(t){var e=t.validatorResult,r=t.manualResult;return!1===r||"pending"===r?e:!1===e||"pending"===e?r:[].concat(r,e)})))},$=function(t){var e,r;function n(e){var r;return(r=t.call(this,"Control "+e+" doesn't have any value yet")||this).name="ValueNotThereYetError",Object.setPrototypeOf(function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(r),n.prototype),r}return r=t,(e=n).prototype=Object.create(r.prototype),e.prototype.constructor=e,e.__proto__=r,n}(k(Error)),C=Symbol("empty"),T=(function(t){var e=function(t){var e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",u=n.asyncIterator||"@@asyncIterator",i=n.toStringTag||"@@toStringTag";function a(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{a({},"")}catch(t){a=function(t,e,r){return t[e]=r}}function c(t,e,r,n){var o=Object.create((e&&e.prototype instanceof l?e:l).prototype),u=new S(n||[]);return o._invoke=function(t,e,r){var n="suspendedStart";return function(o,u){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw u;return{value:void 0,done:!0}}for(r.method=o,r.arg=u;;){var i=r.delegate;if(i){var a=w(i,r);if(a){if(a===f)continue;return a}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=s(t,e,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===f)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}(t,r,u),o}function s(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=c;var f={};function l(){}function h(){}function v(){}var p={};p[o]=function(){return this};var d=Object.getPrototypeOf,y=d&&d(d(O([])));y&&y!==e&&r.call(y,o)&&(p=y);var b=v.prototype=l.prototype=Object.create(p);function g(t){["next","throw","return"].forEach((function(e){a(t,e,(function(t){return this._invoke(e,t)}))}))}function m(t,e){var n;this._invoke=function(o,u){function i(){return new e((function(n,i){!function n(o,u,i,a){var c=s(t[o],t,u);if("throw"!==c.type){var f=c.arg,l=f.value;return l&&"object"==typeof l&&r.call(l,"__await")?e.resolve(l.__await).then((function(t){n("next",t,i,a)}),(function(t){n("throw",t,i,a)})):e.resolve(l).then((function(t){f.value=t,i(f)}),(function(t){return n("throw",t,i,a)}))}a(c.arg)}(o,u,n,i)}))}return n=n?n.then(i,i):i()}}function w(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,w(t,e),"throw"===e.method))return f;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return f}var n=s(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,f;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,f):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,f)}function x(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function E(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function S(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(x,this),this.reset(!0)}function O(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,u=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return u.next=u}}return{next:j}}function j(){return{value:void 0,done:!0}}return h.prototype=b.constructor=v,v.constructor=h,h.displayName=a(v,i,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===h||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,v):(t.__proto__=v,a(t,i,"GeneratorFunction")),t.prototype=Object.create(b),t},t.awrap=function(t){return{__await:t}},g(m.prototype),m.prototype[u]=function(){return this},t.AsyncIterator=m,t.async=function(e,r,n,o,u){void 0===u&&(u=Promise);var i=new m(c(e,r,n,o),u);return t.isGeneratorFunction(r)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},g(b),a(b,i,"Generator"),b[o]=function(){return this},b.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=O,S.prototype={constructor:S,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(E),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return i.type="throw",i.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var u=this.tryEntries[o],i=u.completion;if("root"===u.tryLoc)return n("end");if(u.tryLoc<=this.prev){var a=r.call(u,"catchLoc"),c=r.call(u,"finallyLoc");if(a&&c){if(this.prev<u.catchLoc)return n(u.catchLoc,!0);if(this.prev<u.finallyLoc)return n(u.finallyLoc)}else if(a){if(this.prev<u.catchLoc)return n(u.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<u.finallyLoc)return n(u.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var u=o;break}}u&&("break"===t||"continue"===t)&&u.tryLoc<=e&&e<=u.finallyLoc&&(u=null);var i=u?u.completion:{};return i.type=t,i.arg=e,u?(this.method="next",this.next=u.finallyLoc,f):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),f},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),E(r),f}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;E(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:O(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},t}(t.exports);try{regeneratorRuntime=e}catch(t){Function("r","regeneratorRuntime = r")(e)}}(A={exports:{}}),A.exports),G=function(t,e){var o,u,i=r(e.key);return t.registerControl(e),{getValue:function(){return n(i,t.values,(function(){return new f})).getState()},setValue:function(e){return n(i,t.values,(function(){return new f})).setState(e)},subscribe:function(e){return n(i,t.values,(function(){return new f})).subscribe(e)},touch:(o=T.mark((function e(){var r;return T.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=M(t,i),e.next=3,h(r);case 3:if(!r.getState().touched){e.next=5;break}return e.abrupt("return");case 5:r.setState(O({},r.getState(),{touched:!0}));case 6:case"end":return e.stop()}}),e)})),u=function(){var t=this,e=arguments;return new Promise((function(r,n){var u=o.apply(t,e);function i(t){S(u,r,n,i,a,"next",t)}function a(t){S(u,r,n,i,a,"throw",t)}i(void 0)}))},function(){return u.apply(this,arguments)})}},K={},W=new f(!1),Y={};exports.isAtLeast=function(t){return function(e,r){var n=P(t,r);return!(Number(e)<n)||["Expected a value of at least "+n]}},exports.isAtMost=function(t){return function(e,r){var n=P(t,r);return!(Number(e)>n)||["Expected a value of at most "+n]}},exports.isGreaterThan=function(t){return function(e,r){var n=P(t,r);return!(Number(e)<=n)||["Expected a value greater than "+n]}},exports.isInteger=function(t){return parseInt(t)===parseFloat(t)||["Expected an integer"]},exports.isLessThan=function(t){return function(e,r){var n=P(t,r);return!(Number(e)>=n)||["Expected a value less than "+n]}},exports.isNumber=function(t){return!isNaN(t)||["Expected a number"]},exports.isRequired=function(t){return null!=t&&""!==t||["required"]},exports.matches=function(t,e){return function(r){return!!t.test(r)||[null!=e?e:"Invalid value"]}},exports.mergeValidators=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return function(){for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];var o=e.map((function(t){return t.apply(void 0,r)})),u=function(t){var e=t.flatMap((function(t){return"boolean"==typeof t?[]:t}));return 0===e.length?!t.some((function(t){return!1===t})):e};return o.some(R)?Promise.all(o).then(u):u(o)}},exports.pipeValidators=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return N(e,0)},exports.readField=function(t,e){try{return n(e,t.values,(function(){return new f})).getState()}catch(t){return}},exports.readForm=function(t){try{return function(t){var e={};for(var r in t)u(e,r,t[r]);return e}(Object.fromEntries([].concat(t.values.entries()).map((function(t){return[t[0],t[1].getState()]}))))}catch(t){return{}}},exports.resetForm=function(t,e){var r=t.values,n=t.initialValues;(e?o(e):[].concat(r.keys())).forEach((function(e){if(r.has(e)&&n.has(e)){r.get(e).setState(n.get(e).getState());var o=M(t,e);o.getState().touched&&o.setState(O({},o.getState(),{touched:!1}))}}))},exports.setFieldError=function(t,e,r){try{M(t,e).getState().manualError.emit(r)}catch(t){console.warn("Can't set error: Field not registered",t)}},exports.setFieldValue=function(t,e,r){n(e,t.values,(function(){return new f})).setState(r)},exports.setInitialValue=function(t,e,r){return n(e,t.initialValues,(function(){return new f})).setState(r)},exports.touchFields=function(t,e,r){void 0===r&&(r=!0),(e?o(e):t.registeredKeys.getState()).forEach((function(e){var n=M(t,e);n.getState().touched!==r&&n.setState(O({},n.getState(),{touched:r}))}))},exports.useControl=function(e,r){var n=G(e,r),o=n.subscribe,u=function(t,e){if(null==t)return{};var r,n,o={},u=Object.keys(t);for(n=0;n<u.length;n++)e.indexOf(r=u[n])>=0||(o[r]=t[r]);return o}(n,["subscribe"]),i=t.useState(u.getValue),a=i[0],c=i[1];return t.useEffect((function(){return o(c)}),[]),O({},u,{value:a})},exports.useControlSubscription=G,exports.useErrors=function(e,r){var n=r?o(r):[K],u=t.useState({}),i=u[0],a=u[1],c=t.useMemo((function(){var t=n[0]===K?b(e.registeredKeys,y((function(t){return Array.from(t)}))):new f(n);return b(t,m((function(t){return v(Object.fromEntries(t.map((function(t){return[t,b(M(e,t),y((function(t){return t.touched?t.error$:W})),p(),m((function(t){return t})))]}))))})),y((function(t){return Object.fromEntries(Object.entries(t).filter((function(t){return!1!==t[1]})))})))}),[e].concat(n));return t.useEffect((function(){return c.subscribe((function(t){return a((function(){return t}))}))}),[c]),i},exports.useForm=function(e){var o=t.useRef(null);return o.current||(o.current=function(t){void 0===t&&(t={});var e=new f(new Set),o=new Map;Object.entries(function t(e){var r={};if(!e)return r;if("object"!=typeof e)throw new Error("Model must be an object");var n=Array.isArray(e)?function(t){return"["+t+"]"}:function(t){return t};return Object.entries(e).forEach((function(e){var o=e[0],u=e[1];if(function(t){return null!==t&&"object"==typeof t&&t.__proto__===Object.prototype}(u)||Array.isArray(u)){var i=t(u);Object.entries(i).forEach((function(t){var e=t[0],u=t[1],i=e.startsWith("[")?"":".";r[n(o)+i+e]=u}))}else r[n(o)]=u})),r}(t.initialValue||{})).forEach((function(t){o.set(t[0],new f(t[1]))}));var u=new Map([].concat(o.entries()).map((function(t){return[t[0],new f(t[1].getState())]}))),i=new Map,a=function(t){return n(t,u,(function(){return new f}))};return{registeredKeys:e,registerControl:function(t){var s,l=t.initialValue,h=t.validator,v=void 0===h?F:h,d=r(t.key),g=a(d),m=n(d,i,(function(){return new f}));if(!m.hasValue()){var w=e.getState();w.add(d),e.setState(w);var x=new E;m.setState({touched:!1,validator:v,manualError:x,error$:I({key:d,validator$:b(m,y((function(t){return t.validator})),(s=v,function(t){return new c((function(e){return e(s),t.subscribe(e)}))}),p()),value$:g,manualError$:x,getControlValue$:a})})}v!==m.getState().validator&&m.setState(O({},m.getState(),{validator:v}));var S=n(d,o,(function(){return new f(l)}));S.hasValue()&&S.getState()===l||S.setState(l);var j=n(d,u,(function(){return new f}));j.hasValue()||j.setState(l)},initialValues:o,controlStates:i,values:u,dispose:function(){o.clear(),u.clear(),i.clear()}}}(e)),t.useEffect((function(){return function(){return o.current.dispose()}}),[]),o.current},exports.useInput=function(e,o){void 0===o&&(o={});var u=o.eventType,i=void 0===u?"input":u,a=o.elementProp,c=void 0===a?"value":a,s=t.useRef(null);return t.useEffect((function(){var t=s.current;if(t){var u=o.initialValue,a=void 0===u?"":u,l=o.validator,h=o.key?r(o.key):t.name;if(h){e.registerControl({initialValue:a,key:h,validator:l});var v=n(h,e.values,(function(){return new f})),p=v.subscribe((function(e){t[c]!==e&&(t[c]=e)})),d=function(){var t=M(e,h);t.getState().touched||t.setState(O({},t.getState(),{touched:!0}))};t.addEventListener("blur",d);var y=function(t){return v.setState(t.target[c])};return t.addEventListener(i,y),function(){p(),t.removeEventListener("blur",d),t.removeEventListener(i,y)}}console.error("An input is missing its key. Either supply it through useInput `key` option or through the input's name",t,{options:o})}})),s},exports.useIsPristine=function(e){var r=t.useMemo((function(){return b(e.registeredKeys,m((function(t){return b(v(Array.from(t).map((function(t){var r=n(t,e.initialValues,(function(){return new f})),o=n(t,e.values,(function(){return new f}));return b(v({initialValue:r,value:o}),y((function(t){return t.initialValue===t.value})))}))),y((function(t){return t.every((function(t){return t}))})))})),p())}),[e]),o=t.useState((function(){return!r.hasValue()||r.getState()})),u=o[0],i=o[1];return t.useEffect((function(){return r.subscribe(i)}),[r]),u},exports.useIsValid=function(e,r,n){void 0===r&&(r=!1);var u=n?o(n):[Y],i=t.useMemo((function(){var t=u[0]===Y?b(e.registeredKeys,y((function(t){return Array.from(t)}))):new f(u);return b(t,m((function(t){return v(Object.fromEntries(t.map((function(t){return[t,b(M(e,t),w(1),m((function(t){return t.error$})))]}))))})),y((function(t){return Object.fromEntries(Object.entries(t).filter((function(t){return!1!==t[1]})))})))}),[e].concat(u)),a=t.useMemo((function(){return b(i,y((function(t){var e=Object.values(t),r=!1;return!e.some((function(t){return"pending"!==t||(r=!0,!1)}))&&(!r||"pending")})))}),[i]),c=t.useState((function(){return a.hasValue()?a.getState():r})),s=c[0],l=c[1];return t.useEffect((function(){return a.subscribe(l)}),[a]),s},exports.useWatch=function(e,r){var o=n(r,e.values,(function(){return new f})),u=t.useState((function(){if(o.hasValue())return o.getState()})),i=u[0],a=u[1];return t.useEffect((function(){return o.subscribe(a)}),[o]),i}; | ||
//# sourceMappingURL=formicary.cjs.production.min.js.map |
@@ -823,3 +823,3 @@ import { useState, useEffect, useMemo, useRef } from 'react'; | ||
}); | ||
var values = new Map([].concat(initialValues).map(function (_ref2) { | ||
var values = new Map([].concat(initialValues.entries()).map(function (_ref2) { | ||
var key = _ref2[0], | ||
@@ -826,0 +826,0 @@ subject = _ref2[1]; |
{ | ||
"version": "0.2.0-alpha.0", | ||
"version": "0.2.0-alpha.1", | ||
"license": "MIT", | ||
@@ -4,0 +4,0 @@ "main": "dist/index.js", |
@@ -62,3 +62,3 @@ import { | ||
const values = new Map( | ||
[...initialValues].map( | ||
[...initialValues.entries()].map( | ||
([key, subject]) => | ||
@@ -65,0 +65,0 @@ [key, new ObservableState(subject.getState())] as const |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
552352
3