@mobx-ecosystem/mobx-form 2.0.4 → 2.0.5
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.
- package/dist/field-service.d.ts +1 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/field-service.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isEqual as e}from"lodash";import{
|
|
1
|
+
import{isEqual as e}from"lodash";import{makeAutoObservable as t}from"mobx";var n=function(){return n=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},n.apply(this,arguments)};function r(e,t,n,r){return new(n||(n=Promise))((function(i,o){function u(e){try{s(r.next(e))}catch(e){o(e)}}function a(e){try{s(r.throw(e))}catch(e){o(e)}}function s(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(u,a)}s((r=r.apply(e,t||[])).next())}))}function i(e,t){var n,r,i,o,u={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(s){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(u=0)),u;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!(i=u.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){u.label=a[1];break}if(6===a[0]&&u.label<i[1]){u.label=i[1],i=a;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(a);break}i[2]&&u.ops.pop(),u.trys.pop();continue}a=t.call(e,u)}catch(e){a=[6,e],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}}var o,u=function(){function r(e,n){var r=this;this._serviceType="field-service",this._disabled=!1,this.onChange=function(e,t){r.value=t,r.validate&&r.validate()},t(this),this.initValue=e,this.options=n}return Object.defineProperty(r.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(r.prototype,"value",{get:function(){return this._value},set:function(e){this._value=e},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"error",{get:function(){return this._error},set:function(e){this._error=e},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"disabled",{get:function(){return this._disabled},set:function(e){this._disabled=e},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"isValid",{get:function(){return!this._error},enumerable:!1,configurable:!0}),Object.defineProperty(r.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(r.prototype,"props",{get:function(){var e,t=this,r={value:this.value,error:this.error,disabled:this.disabled};return(null===(e=this.options)||void 0===e?void 0:e.onError)&&(r=n(n({},r),{onError:function(e){t.error=t.error||(null==e?void 0:e.toString())}})),n(n({},r),{onChange:this.onChange})},enumerable:!1,configurable:!0}),r}(),a=function(e){o=e.validation.validate},s=function(){if(!o)throw new Error("You must define configureForm to configure mobx-form")},l=function(){function e(e,n){var u=this;this.validate=function(){return r(u,void 0,void 0,(function(){var e,t;return i(this,(function(n){switch(n.label){case 0:return e=this.getValues(),[4,null==o?void 0:o(e,this.validationSchema)];case 1:return(t=n.sent())&&0!=Object.keys(t||[]).length?this.setErrors(t):this.resetErrors(),[2]}}))}))},this.getValues=function(){var e={};return u.keys.forEach((function(t){e[t]=u.fields[t].value})),e},this.setValuesAsInit=function(){u.keys.forEach((function(e){u.fields[e].initValue=u.fields[e].value}))},this.resetErrors=function(){u.keys.forEach((function(e){return u.fields[e].error=void 0}))},this.reset=function(){u.keys.forEach((function(e){return u.fields[e].value=u.fields[e].initValue})),u.validate()},this.disable=function(){u.keys.forEach((function(e){return u.fields[e].disabled=!0}))},this.enable=function(){u.keys.forEach((function(e){return u.fields[e].disabled=!1}))},s(),t(this),this.fields=e,this.validationSchema=n,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}),e.prototype.setErrors=function(e){var t=this;this.keys.forEach((function(n){t.fields[n].error=null==e?void 0:e[n]}))},e}();export{u as FieldService,l as FormService,s as _checkConfiguration,a as configureForm,o as validate};
|
package/package.json
CHANGED