Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mobx-ecosystem/mobx-form

Package Overview
Dependencies
Maintainers
1
Versions
92
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mobx-ecosystem/mobx-form - npm Package Compare versions

Comparing version 2.3.2 to 2.3.3

2

dist/index.js

@@ -1,1 +0,1 @@

import{isEqual as e}from"lodash";import{makeAutoObservable as t,runInAction as r}from"mobx";var i=function(){return i=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},i.apply(this,arguments)};function n(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 o(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 a,u=function(){function r(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(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=i(i({},r),{onError:function(e){t.error=t.error||(null==e?void 0:e.toString())}})),i(i({},r),{onChange:this.onChange})},enumerable:!1,configurable:!0}),r}(),l=function(e){a=e.validation.validate},c=function(){if(!a)throw new Error("You must define configureForm to configure mobx-form")},f=function(){function e(e,i){var l=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 n(l,void 0,void 0,(function(){var e,t;return o(this,(function(r){switch(r.label){case 0:return e=this.getValues(),[4,null==a?void 0:a(e,this.validationSchema)];case 1:return(t=r.sent())&&0!=Object.keys(t||[]).length?this.setErrors(t):this.resetErrors(),[2]}}))}))}}),Object.defineProperty(this,"setValidationSchema",{enumerable:!0,configurable:!0,writable:!0,value:function(e){l.validationSchema=e}}),Object.defineProperty(this,"getValues",{enumerable:!0,configurable:!0,writable:!0,value:function(){var e={};return l.keys.forEach((function(t){e[t]=l.getValue(l.fields[t].value)})),e}}),Object.defineProperty(this,"getValue",{enumerable:!0,configurable:!0,writable:!0,value:function(e){return e instanceof u?l.getValue(e.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 u&&(t[r]=e[r])})),l.fields=t,l.keys.forEach((function(e){r((function(){l.fields[e].validate=l.validate}))}))}}),Object.defineProperty(this,"setValues",{enumerable:!0,configurable:!0,writable:!0,value:function(e){l.keys.forEach((function(t){return l.fields[t].value=e[t]}))}}),Object.defineProperty(this,"setInitValues",{enumerable:!0,configurable:!0,writable:!0,value:function(e){l.keys.forEach((function(t){return l.fields[t].initValue=e[t]}))}}),Object.defineProperty(this,"setValuesAsInit",{enumerable:!0,configurable:!0,writable:!0,value:function(){l.keys.forEach((function(e){l.fields[e].initValue=l.fields[e].value}))}}),Object.defineProperty(this,"resetErrors",{enumerable:!0,configurable:!0,writable:!0,value:function(){l.keys.forEach((function(e){return l.fields[e].error=void 0}))}}),Object.defineProperty(this,"setError",{enumerable:!0,configurable:!0,writable:!0,value:function(e,t){console.log({debug:{error:e,field:t}}),"string"!=typeof e&&t&&t instanceof u?Object.keys(e||{}).forEach((function(r){var i;r in t.value&&l.setError(null==e?void 0:e[r],null===(i=t.value)||void 0===i?void 0:i[r])})):t.error=e}}),Object.defineProperty(this,"reset",{enumerable:!0,configurable:!0,writable:!0,value:function(){l.keys.forEach((function(e){return l.fields[e].value=l.fields[e].initValue})),l.validate()}}),Object.defineProperty(this,"disable",{enumerable:!0,configurable:!0,writable:!0,value:function(){l.keys.forEach((function(e){return l.fields[e].disabled=!0}))}}),Object.defineProperty(this,"enable",{enumerable:!0,configurable:!0,writable:!0,value:function(){l.keys.forEach((function(e){return l.fields[e].disabled=!1}))}}),c(),t(this),this.fields=e,this.validationSchema=i,this.keys.forEach((function(e){l.fields[e].validate=l.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.setError(null==e?void 0:e[r],t.fields[r])}))}}),e}();export{u as FieldService,f as FormService,c as _checkConfiguration,l as configureForm,a as validate};
import{isEqual as e}from"lodash";import{makeAutoObservable as t,runInAction as r}from"mobx";var i=function(){return i=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},i.apply(this,arguments)};function n(e,t,r,i){return new(r||(r=Promise))((function(n,o){function a(e){try{u(i.next(e))}catch(e){o(e)}}function l(e){try{u(i.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,l)}u((i=i.apply(e,t||[])).next())}))}function o(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:l(0),throw:l(1),return:l(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function l(l){return function(u){return function(l){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,l[0]&&(a=0)),a;)try{if(r=1,i&&(n=2&l[0]?i.return:l[0]?i.throw||((n=i.return)&&n.call(i),0):i.next)&&!(n=n.call(i,l[1])).done)return n;switch(i=0,n&&(l=[2&l[0],n.value]),l[0]){case 0:case 1:n=l;break;case 4:return a.label++,{value:l[1],done:!1};case 5:a.label++,i=l[1],l=[0];continue;case 7:l=a.ops.pop(),a.trys.pop();continue;default:if(!(n=a.trys,(n=n.length>0&&n[n.length-1])||6!==l[0]&&2!==l[0])){a=0;continue}if(3===l[0]&&(!n||l[1]>n[0]&&l[1]<n[3])){a.label=l[1];break}if(6===l[0]&&a.label<n[1]){a.label=n[1],n=l;break}if(n&&a.label<n[2]){a.label=n[2],a.ops.push(l);break}n[2]&&a.ops.pop(),a.trys.pop();continue}l=t.call(e,a)}catch(e){l=[6,e],i=0}finally{r=n=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}([l,u])}}}var a,l=function(){function r(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(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=i(i({},r),{onError:function(e){t.error=t.error||(null==e?void 0:e.toString())}})),i(i({},r),{onChange:this.onChange})},enumerable:!1,configurable:!0}),r}(),u=function(e){a=e.validation.validate},c=function(){if(!a)throw new Error("You must define configureForm to configure mobx-form")},f=function(){function e(e,i){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 n(u,void 0,void 0,(function(){var e,t;return o(this,(function(r){switch(r.label){case 0:return e=this.getValues(),[4,null==a?void 0:a(e,this.validationSchema)];case 1:return t=r.sent(),console.log({validateDebug:{fieldValues:e,errors:t}}),t&&0!=Object.keys(t||[]).length?this.setErrors(t):this.resetErrors(),[2]}}))}))}}),Object.defineProperty(this,"setValidationSchema",{enumerable:!0,configurable:!0,writable:!0,value:function(e){u.validationSchema=e}}),Object.defineProperty(this,"getValues",{enumerable:!0,configurable:!0,writable:!0,value:function(){var e={};return u.keys.forEach((function(t){e[t]=u.getValue(u.fields[t].value)})),e}}),Object.defineProperty(this,"getValue",{enumerable:!0,configurable:!0,writable:!0,value:function(e){return e instanceof l?u.getValue(e.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 l&&(t[r]=e[r])})),u.fields=t,u.keys.forEach((function(e){r((function(){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,"setError",{enumerable:!0,configurable:!0,writable:!0,value:function(e,t){console.log({debug:{error:e,field:t}}),"string"!=typeof e&&t&&t instanceof l?Object.keys(e||{}).forEach((function(r){var i;r in t.value&&u.setError(null==e?void 0:e[r],null===(i=t.value)||void 0===i?void 0:i[r])})):t.error=e}}),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}))}}),c(),t(this),this.fields=e,this.validationSchema=i,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.setError(null==e?void 0:e[r],t.fields[r])}))}}),e}();export{l as FieldService,f as FormService,c as _checkConfiguration,u as configureForm,a as validate};

@@ -5,3 +5,3 @@ {

"private": false,
"version": "2.3.2",
"version": "2.3.3",
"description": "provides the ability to use forms with validation in MobX stores",

@@ -8,0 +8,0 @@ "main": "dist/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc