@mobx-ecosystem/mobx-form 2.1.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{isEqual as e}from"lodash";import{makeAutoObservable as t}from"mobx";var i=function(){return i=Object.assign||function(e){for(var t,i=1,n=arguments.length;i<n;i++)for(var r in t=arguments[i])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},i.apply(this,arguments)};function n(e,t,i,n){return new(i||(i=Promise))((function(r,o){function u(e){try{a(n.next(e))}catch(e){o(e)}}function s(e){try{a(n.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(u,s)}a((n=n.apply(e,t||[])).next())}))}function r(e,t){var i,n,r,o,u={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(s){return function(a){return function(s){if(i)throw new TypeError("Generator is already executing.");for(;o&&(o=0,s[0]&&(u=0)),u;)try{if(i=1,n&&(r=2&s[0]?n.return:s[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,s[1])).done)return r;switch(n=0,r&&(s=[2&s[0],r.value]),s[0]){case 0:case 1:r=s;break;case 4:return u.label++,{value:s[1],done:!1};case 5:u.label++,n=s[1],s=[0];continue;case 7:s=u.ops.pop(),u.trys.pop();continue;default:if(!(r=u.trys,(r=r.length>0&&r[r.length-1])||6!==s[0]&&2!==s[0])){u=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]<r[3])){u.label=s[1];break}if(6===s[0]&&u.label<r[1]){u.label=r[1],r=s;break}if(r&&u.label<r[2]){u.label=r[2],u.ops.push(s);break}r[2]&&u.ops.pop(),u.trys.pop();continue}s=t.call(e,u)}catch(e){s=[6,e],n=0}finally{i=r=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}}var o,u=function(){function n(e,i){var n=this;this._serviceType="field-service",this._initValue=void 0,this._value=void 0,this._error=void 0,this._disabled=!1,this.onChange=function(e,t){n.value=t,n.validate&&n.validate()},t(this),this.initValue=e,this.options=i}return Object.defineProperty(n.prototype,"initValue",{get:function(){return this._initValue},set:function(e){this._initValue=e,this._value=e,this.validate&&this.validate()},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"value",{get:function(){return this._value},set:function(e){this._value=e},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"error",{get:function(){return this._error},set:function(e){this._error=e},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"disabled",{get:function(){return this._disabled},set:function(e){this._disabled=e},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"isValid",{get:function(){return!this._error},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"isInit",{get:function(){return null!==(t=this.value)&&"object"==typeof t?e(this.value,this._initValue):this._value===this._initValue;var t},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"props",{get:function(){var e,t=this,n={value:this.value,error:this.error,disabled:this.disabled};return(null===(e=this.options)||void 0===e?void 0:e.onError)&&(n=i(i({},n),{onError:function(e){t.error=t.error||(null==e?void 0:e.toString())}})),i(i({},n),{onChange:this.onChange})},enumerable:!1,configurable:!0}),n}(),s=function(e){o=e.validation.validate},a=function(){if(!o)throw new Error("You must define configureForm to configure mobx-form")},l=function(){function e(e,i){var s=this;this.validate=function(){return n(s,void 0,void 0,(function(){var e,t;return r(this,(function(i){switch(i.label){case 0:return e=this.getValues(),[4,null==o?void 0:o(e,this.validationSchema)];case 1:return(t=i.sent())&&0!=Object.keys(t||[]).length?this.setErrors(t):this.resetErrors(),[2]}}))}))},this.getValues=function(){var e={};return s.keys.forEach((function(t){e[t]=s.fields[t].value})),e},this.setFieldsByThis=function(e){var t={};Object.keys(e).forEach((function(i){e[i]&&e[i]instanceof u&&(t[i]=e[i])})),s.fields=t,s.keys.forEach((function(e){s.fields[e].validate=s.validate}))},this.setValues=function(e){s.keys.forEach((function(t){return s.fields[t].value=e[t]}))},this.setInitValues=function(e){s.keys.forEach((function(t){return s.fields[t].initValue=e[t]}))},this.setValuesAsInit=function(){s.keys.forEach((function(e){s.fields[e].initValue=s.fields[e].value}))},this.resetErrors=function(){s.keys.forEach((function(e){return s.fields[e].error=void 0}))},this.reset=function(){s.keys.forEach((function(e){return s.fields[e].value=s.fields[e].initValue})),s.validate()},this.disable=function(){s.keys.forEach((function(e){return s.fields[e].disabled=!0}))},this.enable=function(){s.keys.forEach((function(e){return s.fields[e].disabled=!1}))},a(),t(this),this.fields=e,this.validationSchema=i,this.keys.forEach((function(e){s.fields[e].validate=s.validate}))}return Object.defineProperty(e.prototype,"keys",{get:function(){return Object.keys(this.fields)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isValid",{get:function(){var e=this;return this.keys.every((function(t){return e.fields[t].isValid}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isTouched",{get:function(){var e=this;return this.keys.some((function(t){return!e.fields[t].isInit}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"canBeSubmitted",{get:function(){return this.isTouched&&this.isValid},enumerable:!1,configurable:!0}),e.prototype.setErrors=function(e){var t=this;this.keys.forEach((function(i){t.fields[i].error=null==e?void 0:e[i]}))},e}();export{u as FieldService,l as FormService,a as _checkConfiguration,s as configureForm,o as validate};
1
+ import{isEqual as e}from"lodash";import{makeAutoObservable as t}from"mobx";var r=function(){return r=Object.assign||function(e){for(var t,r=1,i=arguments.length;r<i;r++)for(var n in t=arguments[r])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e},r.apply(this,arguments)};function i(e,t,r,i){return new(r||(r=Promise))((function(n,o){function a(e){try{l(i.next(e))}catch(e){o(e)}}function u(e){try{l(i.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,u)}l((i=i.apply(e,t||[])).next())}))}function n(e,t){var r,i,n,o,a={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(u){return function(l){return function(u){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,u[0]&&(a=0)),a;)try{if(r=1,i&&(n=2&u[0]?i.return:u[0]?i.throw||((n=i.return)&&n.call(i),0):i.next)&&!(n=n.call(i,u[1])).done)return n;switch(i=0,n&&(u=[2&u[0],n.value]),u[0]){case 0:case 1:n=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,i=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!(n=a.trys,(n=n.length>0&&n[n.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!n||u[1]>n[0]&&u[1]<n[3])){a.label=u[1];break}if(6===u[0]&&a.label<n[1]){a.label=n[1],n=u;break}if(n&&a.label<n[2]){a.label=n[2],a.ops.push(u);break}n[2]&&a.ops.pop(),a.trys.pop();continue}u=t.call(e,a)}catch(e){u=[6,e],i=0}finally{r=n=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,l])}}}var o,a=function(){function i(e,r){var i=this;Object.defineProperty(this,"_serviceType",{enumerable:!0,configurable:!0,writable:!0,value:"field-service"}),Object.defineProperty(this,"_initValue",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_value",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_error",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_disabled",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"onChange",{enumerable:!0,configurable:!0,writable:!0,value:function(e,t){i.value=t,i.validate&&i.validate()}}),t(this),this.initValue=e,this.options=r}return Object.defineProperty(i.prototype,"initValue",{get:function(){return this._initValue},set:function(e){this._initValue=e,this._value=e,this.validate&&this.validate()},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"value",{get:function(){return this._value},set:function(e){this._value=e},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"error",{get:function(){return this._error},set:function(e){this._error=e},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"disabled",{get:function(){return this._disabled},set:function(e){this._disabled=e},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"isValid",{get:function(){return!this._error},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"isInit",{get:function(){return null!==(t=this.value)&&"object"==typeof t?e(this.value,this._initValue):this._value===this._initValue;var t},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"props",{get:function(){var e,t=this,i={value:this.value,error:this.error,disabled:this.disabled};return(null===(e=this.options)||void 0===e?void 0:e.onError)&&(i=r(r({},i),{onError:function(e){t.error=t.error||(null==e?void 0:e.toString())}})),r(r({},i),{onChange:this.onChange})},enumerable:!1,configurable:!0}),i}(),u=function(e){o=e.validation.validate},l=function(){if(!o)throw new Error("You must define configureForm to configure mobx-form")},f=function(){function e(e,r){var u=this;Object.defineProperty(this,"fields",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"validationSchema",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"validate",{enumerable:!0,configurable:!0,writable:!0,value:function(){return i(u,void 0,void 0,(function(){var e,t;return n(this,(function(r){switch(r.label){case 0:return e=this.getValues(),[4,null==o?void 0:o(e,this.validationSchema)];case 1:return(t=r.sent())&&0!=Object.keys(t||[]).length?this.setErrors(t):this.resetErrors(),[2]}}))}))}}),Object.defineProperty(this,"getValues",{enumerable:!0,configurable:!0,writable:!0,value:function(){var e={};return u.keys.forEach((function(t){e[t]=u.fields[t].value})),e}}),Object.defineProperty(this,"setFieldsByThis",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var t={};Object.keys(e).forEach((function(r){e[r]&&e[r]instanceof a&&(t[r]=e[r])})),u.fields=t,u.keys.forEach((function(e){u.fields[e].validate=u.validate}))}}),Object.defineProperty(this,"setValues",{enumerable:!0,configurable:!0,writable:!0,value:function(e){u.keys.forEach((function(t){return u.fields[t].value=e[t]}))}}),Object.defineProperty(this,"setInitValues",{enumerable:!0,configurable:!0,writable:!0,value:function(e){u.keys.forEach((function(t){return u.fields[t].initValue=e[t]}))}}),Object.defineProperty(this,"setValuesAsInit",{enumerable:!0,configurable:!0,writable:!0,value:function(){u.keys.forEach((function(e){u.fields[e].initValue=u.fields[e].value}))}}),Object.defineProperty(this,"resetErrors",{enumerable:!0,configurable:!0,writable:!0,value:function(){u.keys.forEach((function(e){return u.fields[e].error=void 0}))}}),Object.defineProperty(this,"reset",{enumerable:!0,configurable:!0,writable:!0,value:function(){u.keys.forEach((function(e){return u.fields[e].value=u.fields[e].initValue})),u.validate()}}),Object.defineProperty(this,"disable",{enumerable:!0,configurable:!0,writable:!0,value:function(){u.keys.forEach((function(e){return u.fields[e].disabled=!0}))}}),Object.defineProperty(this,"enable",{enumerable:!0,configurable:!0,writable:!0,value:function(){u.keys.forEach((function(e){return u.fields[e].disabled=!1}))}}),l(),t(this),this.fields=e,this.validationSchema=r,this.keys.forEach((function(e){u.fields[e].validate=u.validate}))}return Object.defineProperty(e.prototype,"keys",{get:function(){return Object.keys(this.fields)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isValid",{get:function(){var e=this;return this.keys.every((function(t){return e.fields[t].isValid}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isTouched",{get:function(){var e=this;return this.keys.some((function(t){return!e.fields[t].isInit}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"canBeSubmitted",{get:function(){return this.isTouched&&this.isValid},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"setErrors",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;this.keys.forEach((function(r){t.fields[r].error=null==e?void 0:e[r]}))}}),e}();export{a as FieldService,f as FormService,l as _checkConfiguration,u as configureForm,o as validate};
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "type": "module",
3
3
  "name": "@mobx-ecosystem/mobx-form",
4
4
  "private": false,
5
- "version": "2.1.0",
5
+ "version": "2.1.1",
6
6
  "description": "provides the ability to use forms with validation in MobX stores",
7
7
  "main": "dist/index.js",
8
8
  "module": "dist/index.js",