@mobx-ecosystem/mobx-form
Advanced tools
Comparing version 2.10.10 to 2.10.11
import { FieldService } from "./field-service"; | ||
import { IField, ValueType } from "./types"; | ||
export declare class AutocompleteFieldService<T = ValueType<unknown>> implements IField { | ||
validate?(): Promise<void>; | ||
field: FieldService<T>; | ||
inputField: FieldService<string>; | ||
constructor(initValue?: ValueType<T>); | ||
get validate(): (() => Promise<void>) | undefined; | ||
set validate(validate: (() => Promise<void>) | undefined); | ||
setValue: (value: ValueType<T>, { inputValue, withNotification }: { | ||
@@ -9,0 +10,0 @@ inputValue?: string | undefined; |
@@ -11,3 +11,3 @@ import { IField, ValueType } from './types'; | ||
}>; | ||
validate?(): Promise<void>; | ||
validate?: () => Promise<void>; | ||
_serviceType: string; | ||
@@ -14,0 +14,0 @@ private _initValue?; |
@@ -1,1 +0,1 @@ | ||
import{isEqual as e}from"lodash";import{makeAutoObservable as t}from"mobx";import r from"mitt";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,u){function o(e){try{l(i.next(e))}catch(e){u(e)}}function a(e){try{l(i.throw(e))}catch(e){u(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(o,a)}l((i=i.apply(e,t||[])).next())}))}function u(e,t){var r,i,n,u,o={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return u={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function a(a){return function(l){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;u&&(u=0,a[0]&&(o=0)),o;)try{if(r=1,i&&(n=2&a[0]?i.return:a[0]?i.throw||((n=i.return)&&n.call(i),0):i.next)&&!(n=n.call(i,a[1])).done)return n;switch(i=0,n&&(a=[2&a[0],n.value]),a[0]){case 0:case 1:n=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,i=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(n=o.trys,(n=n.length>0&&n[n.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!n||a[1]>n[0]&&a[1]<n[3])){o.label=a[1];break}if(6===a[0]&&o.label<n[1]){o.label=n[1],n=a;break}if(n&&o.label<n[2]){o.label=n[2],o.ops.push(a);break}n[2]&&o.ops.pop(),o.trys.pop();continue}a=t.call(e,o)}catch(e){a=[6,e],i=0}finally{r=n=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,l])}}}var o,a,l=function(){function n(e,i){var n=this;Object.defineProperty(this,"_isListenerWorks",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"eventBus",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),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,"_isBlurred",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"createListener",{enumerable:!0,configurable:!0,writable:!0,value:function(){n._isListenerWorks=!0,n.eventBus=r()}}),Object.defineProperty(this,"pauseListener",{enumerable:!0,configurable:!0,writable:!0,value:function(){n._isListenerWorks=!1}}),Object.defineProperty(this,"resumeListener",{enumerable:!0,configurable:!0,writable:!0,value:function(){n._isListenerWorks=!0}}),Object.defineProperty(this,"destroyListener",{enumerable:!0,configurable:!0,writable:!0,value:function(){n.eventBus=void 0}}),Object.defineProperty(this,"onChange",{enumerable:!0,configurable:!0,writable:!0,value:function(e,t){var r;n.value=t,null===(r=n.validate)||void 0===r||r.call(n)}}),Object.defineProperty(this,"onBlur",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var t;n.isBlurred=!0,null===(t=n.validate)||void 0===t||t.call(n)}}),Object.defineProperty(this,"reset",{enumerable:!0,configurable:!0,writable:!0,value:function(){n.value=n.initValue,n.isBlurred=!1}}),Object.defineProperty(this,"setAsInit",{enumerable:!0,configurable:!0,writable:!0,value:function(){n.initValue=n.value,n.isBlurred=!1}}),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){var t,r=this._value;this._value=e,r!==e&&this._isListenerWorks&&(null===(t=this.eventBus)||void 0===t||t.emit("ON_CHANGE",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,"isBlurred",{get:function(){return this._isBlurred},set:function(e){this._isBlurred=e},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"isTouched",{get:function(){return!this.isInit||this.isBlurred},enumerable:!1,configurable:!0}),Object.defineProperty(n.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,onBlur:this.onBlur})},enumerable:!1,configurable:!0}),n}(),s=function(e){o=e.validation.validate,a=e.validation.preSubmitValidationError},c=function(){if(!o||!a)throw new Error("You must define configureForm to configure mobx-form")},f=function(){function e(e){var r=this;Object.defineProperty(this,"_touched",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_disabled",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_error",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_initValue",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_value",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"setTouched",{enumerable:!0,configurable:!0,writable:!0,value:function(e){r._touched=e}}),Object.defineProperty(this,"add",{enumerable:!0,configurable:!0,writable:!0,value:function(e){r.value.push(e),r.setTouched(!0),r._validate()}}),Object.defineProperty(this,"removeByIndex",{enumerable:!0,configurable:!0,writable:!0,value:function(e){r.value.splice(e,1),r.setTouched(!0),r._validate()}}),Object.defineProperty(this,"_validate",{enumerable:!0,configurable:!0,writable:!0,value:function(){var e;r.value.forEach((function(e){return e.formService.validate()})),null===(e=r.validate)||void 0===e||e.call(r)}}),Object.defineProperty(this,"reset",{enumerable:!0,configurable:!0,writable:!0,value:function(){r._value=r.initValue,r._value.forEach((function(e){return e.formService.reset()})),r.setTouched(!1)}}),Object.defineProperty(this,"setAsInit",{enumerable:!0,configurable:!0,writable:!0,value:function(){r._initValue=r.value,r._value.forEach((function(e){return e.formService.setValuesAsInit()})),r.setTouched(!1)}}),Object.defineProperty(this,"getValues",{enumerable:!0,configurable:!0,writable:!0,value:function(){return r.value.map((function(e){return e.formService.getValues()}))}}),t(this),this.initValue=e||[]}return Object.defineProperty(e.prototype,"initValue",{get:function(){return this._initValue},set:function(e){this._initValue=e,this._value=e.slice(0),this.setTouched(!1),this._validate()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"value",{get:function(){return this._value},set:function(e){this._value=e,this.setTouched(!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"disabled",{get:function(){return this._disabled},set:function(e){this._disabled=e,e?this.value.forEach((function(e){return e.formService.disable()})):this.value.forEach((function(e){return e.formService.enable()}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"error",{get:function(){return this._error},set:function(e){this._error=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isValid",{get:function(){return!this._error&&this.value.every((function(e){return e.formService.isValid}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isTouched",{get:function(){return this._touched||this.value.some((function(e){return e.formService.isTouched}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isInit",{get:function(){return!this.isTouched},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"hasItems",{get:function(){return Boolean(this.value.length)},enumerable:!1,configurable:!0}),e}(),b=function(){function e(e,r){var i=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,"onSubmit",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"setOnSubmit",{enumerable:!0,configurable:!0,writable:!0,value:function(e){i.onSubmit=e}}),Object.defineProperty(this,"submit",{enumerable:!0,configurable:!0,writable:!0,value:function(){return n(i,void 0,void 0,(function(){var e;return u(this,(function(t){switch(t.label){case 0:return[4,this.validate("everything")];case 1:return t.sent(),this.canBeSubmitted?[2,null===(e=this.onSubmit)||void 0===e?void 0:e.call(this)]:(null==a||a(),[2])}}))}))}}),Object.defineProperty(this,"validate",{enumerable:!0,configurable:!0,writable:!0,value:function(e){return void 0===e&&(e="only-touched"),n(i,void 0,void 0,(function(){var t,r;return u(this,(function(i){switch(i.label){case 0:return t=this.getValues(),[4,null==o?void 0:o(t,this.validationSchema)];case 1:return(r=i.sent())&&0!=Object.keys(r||[]).length?this.setErrors(r,e):this.resetErrors(),[2]}}))}))}}),Object.defineProperty(this,"setValidationSchema",{enumerable:!0,configurable:!0,writable:!0,value:function(e){i.validationSchema=e,i.setValidationToFields()}}),Object.defineProperty(this,"getValues",{enumerable:!0,configurable:!0,writable:!0,value:function(){for(var e={},t=0,r=i.keys;t<r.length;t++){var n=r[t];e[n]=i.getValue(i.fields[n])}return e}}),Object.defineProperty(this,"getValue",{enumerable:!0,configurable:!0,writable:!0,value:function(e){if(e instanceof l||e instanceof f)return null==e?void 0:e.value;if("object"==typeof e){for(var t={},r=0,n=Object.keys(e);r<n.length;r++){var u=n[r];t[u]=i.getValue(null==e?void 0:e[u])}return t}return 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||e[r]instanceof f)&&(t[r]=e[r])})),i.fields=t,i.setValidationToFields()}}),Object.defineProperty(this,"bypassFields",{enumerable:!0,configurable:!0,writable:!0,value:function(e,t,r){e instanceof l||e instanceof f?t(e,r):"object"==typeof e&&Object.keys(e||{}).forEach((function(n){i.bypassFields(null==e?void 0:e[n],t,null==r?void 0:r[n])}))}}),Object.defineProperty(this,"setValidationToFields",{enumerable:!0,configurable:!0,writable:!0,value:function(){i.bypassFields(i.fields,(function(e){return e.validate=i.validate}))}}),Object.defineProperty(this,"setInitValues",{enumerable:!0,configurable:!0,writable:!0,value:function(e){i.bypassFields(i.fields,(function(e,t){return e.initValue=t}),e)}}),Object.defineProperty(this,"setValues",{enumerable:!0,configurable:!0,writable:!0,value:function(e){i.bypassFields(i.fields,(function(e,t){return e.value=t}),e)}}),Object.defineProperty(this,"resetErrors",{enumerable:!0,configurable:!0,writable:!0,value:function(){i.bypassFields(i.fields,(function(e){return e.error=void 0}))}}),Object.defineProperty(this,"setValuesAsInit",{enumerable:!0,configurable:!0,writable:!0,value:function(){i.bypassFields(i.fields,(function(e){e.setAsInit()}))}}),Object.defineProperty(this,"reset",{enumerable:!0,configurable:!0,writable:!0,value:function(){i.bypassFields(i.fields,(function(e){return e.reset()})),i.validate()}}),Object.defineProperty(this,"disable",{enumerable:!0,configurable:!0,writable:!0,value:function(){i.bypassFields(i.fields,(function(e){return e.disabled=!0}))}}),Object.defineProperty(this,"enable",{enumerable:!0,configurable:!0,writable:!0,value:function(){i.bypassFields(i.fields,(function(e){return e.disabled=!1}))}}),c(),t(this),this.fields=e,this.validationSchema=r,this.setValidationToFields()}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=!0;return this.bypassFields(this.fields,(function(t){t.isValid||(e=!1)})),e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isTouched",{get:function(){var e=!1;return this.bypassFields(this.fields,(function(t){t.isTouched&&(e=!0)})),e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"canBeSubmitted",{get:function(){return this.isTouched&&this.isValid},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"disabled",{get:function(){var e=!0;return this.bypassFields(this.fields,(function(t){t.disabled||(e=!1)})),e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"setErrors",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){void 0===t&&(t="only-touched"),this.bypassFields(this.fields,(function(e,r){(e.isTouched||"everything"===t)&&(e.error=r)}),e)}}),e}(),d=function(){function e(){var e=this;Object.defineProperty(this,"formServices",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"setForms",{enumerable:!0,configurable:!0,writable:!0,value:function(t){e.formServices=t}}),Object.defineProperty(this,"validate",{enumerable:!0,configurable:!0,writable:!0,value:function(t){return n(e,void 0,void 0,(function(){var e,r;return u(this,(function(i){switch(i.label){case 0:e=0,r=this.formServices,i.label=1;case 1:return e<r.length?[4,r[e].validate(t)]:[3,4];case 2:i.sent(),i.label=3;case 3:return e++,[3,1];case 4:return[2]}}))}))}}),Object.defineProperty(this,"getValues",{enumerable:!0,configurable:!0,writable:!0,value:function(){return e.formServices.map((function(e){return e.getValues()}))}}),Object.defineProperty(this,"resetErrors",{enumerable:!0,configurable:!0,writable:!0,value:function(){return e.formServices.forEach((function(e){return e.resetErrors()}))}}),Object.defineProperty(this,"setValuesAsInit",{enumerable:!0,configurable:!0,writable:!0,value:function(){return e.formServices.forEach((function(e){return e.setValuesAsInit()}))}}),Object.defineProperty(this,"reset",{enumerable:!0,configurable:!0,writable:!0,value:function(){return e.formServices.forEach((function(e){return e.reset()}))}}),Object.defineProperty(this,"disable",{enumerable:!0,configurable:!0,writable:!0,value:function(){return e.formServices.forEach((function(e){return e.disable()}))}}),Object.defineProperty(this,"enable",{enumerable:!0,configurable:!0,writable:!0,value:function(){return e.formServices.forEach((function(e){return e.enable()}))}}),t(this)}return Object.defineProperty(e.prototype,"fields",{get:function(){return this.formServices.map((function(e){return e.fields})).flat()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"keys",{get:function(){return this.formServices.map((function(e){return e.keys})).flat()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isValid",{get:function(){return this.formServices.every((function(e){return e.isValid}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isTouched",{get:function(){return this.formServices.some((function(e){return e.isTouched}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"canBeSubmitted",{get:function(){return this.isTouched&&this.isValid},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"disabled",{get:function(){return this.formServices.every((function(e){return e.disabled}))},enumerable:!1,configurable:!0}),e}(),h=function(){function e(e){var r=this;Object.defineProperty(this,"field",{enumerable:!0,configurable:!0,writable:!0,value:new l(null)}),Object.defineProperty(this,"inputField",{enumerable:!0,configurable:!0,writable:!0,value:new l("")}),Object.defineProperty(this,"setValue",{enumerable:!0,configurable:!0,writable:!0,value:function(e,t){var i=t.inputValue,n=void 0===i?"":i,u=t.withNotification;void 0===u||u?(r.field.value=e,r.inputField.value=n):(r.field.pauseListener(),r.inputField.pauseListener(),r.field.value=e,r.inputField.value=n,r.field.resumeListener(),r.inputField.resumeListener())}}),Object.defineProperty(this,"reset",{enumerable:!0,configurable:!0,writable:!0,value:function(){r.field.reset()}}),Object.defineProperty(this,"setAsInit",{enumerable:!0,configurable:!0,writable:!0,value:function(){r.field.setAsInit()}}),Object.defineProperty(this,"onInputChange",{enumerable:!0,configurable:!0,writable:!0,value:function(e,t){r.inputField.value=t}}),t(this),this.field.initValue=e}return Object.defineProperty(e.prototype,"value",{get:function(){return this.field.value},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"error",{get:function(){return this.field.error},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"disabled",{get:function(){return this.field.disabled},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isValid",{get:function(){return this.field.isValid},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isInit",{get:function(){return this.field.isInit},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"props",{get:function(){return i(i({},this.field.props),{inputValue:this.inputField.value,onInputChange:this.onInputChange})},enumerable:!1,configurable:!0}),e}();export{h as AutocompleteFieldService,f as CombinedFormFieldService,d as CombinedFormService,l as FieldService,b as FormService,c as _checkConfiguration,s as configureForm,a as preSubmitValidationError,o as validate}; | ||
import{isEqual as e}from"lodash";import{makeAutoObservable as t}from"mobx";import r from"mitt";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,u){function o(e){try{l(i.next(e))}catch(e){u(e)}}function a(e){try{l(i.throw(e))}catch(e){u(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(o,a)}l((i=i.apply(e,t||[])).next())}))}function u(e,t){var r,i,n,u,o={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return u={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function a(a){return function(l){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;u&&(u=0,a[0]&&(o=0)),o;)try{if(r=1,i&&(n=2&a[0]?i.return:a[0]?i.throw||((n=i.return)&&n.call(i),0):i.next)&&!(n=n.call(i,a[1])).done)return n;switch(i=0,n&&(a=[2&a[0],n.value]),a[0]){case 0:case 1:n=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,i=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(n=o.trys,(n=n.length>0&&n[n.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!n||a[1]>n[0]&&a[1]<n[3])){o.label=a[1];break}if(6===a[0]&&o.label<n[1]){o.label=n[1],n=a;break}if(n&&o.label<n[2]){o.label=n[2],o.ops.push(a);break}n[2]&&o.ops.pop(),o.trys.pop();continue}a=t.call(e,o)}catch(e){a=[6,e],i=0}finally{r=n=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,l])}}}var o,a,l=function(){function n(e,i){var n=this;Object.defineProperty(this,"_isListenerWorks",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"eventBus",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"validate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),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,"_isBlurred",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"createListener",{enumerable:!0,configurable:!0,writable:!0,value:function(){n._isListenerWorks=!0,n.eventBus=r()}}),Object.defineProperty(this,"pauseListener",{enumerable:!0,configurable:!0,writable:!0,value:function(){n._isListenerWorks=!1}}),Object.defineProperty(this,"resumeListener",{enumerable:!0,configurable:!0,writable:!0,value:function(){n._isListenerWorks=!0}}),Object.defineProperty(this,"destroyListener",{enumerable:!0,configurable:!0,writable:!0,value:function(){n.eventBus=void 0}}),Object.defineProperty(this,"onChange",{enumerable:!0,configurable:!0,writable:!0,value:function(e,t){var r;n.value=t,null===(r=n.validate)||void 0===r||r.call(n)}}),Object.defineProperty(this,"onBlur",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var t;n.isBlurred=!0,null===(t=n.validate)||void 0===t||t.call(n)}}),Object.defineProperty(this,"reset",{enumerable:!0,configurable:!0,writable:!0,value:function(){n.value=n.initValue,n.isBlurred=!1}}),Object.defineProperty(this,"setAsInit",{enumerable:!0,configurable:!0,writable:!0,value:function(){n.initValue=n.value,n.isBlurred=!1}}),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){var t,r=this._value;this._value=e,r!==e&&this._isListenerWorks&&(null===(t=this.eventBus)||void 0===t||t.emit("ON_CHANGE",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,"isBlurred",{get:function(){return this._isBlurred},set:function(e){this._isBlurred=e},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"isTouched",{get:function(){return!this.isInit||this.isBlurred},enumerable:!1,configurable:!0}),Object.defineProperty(n.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,onBlur:this.onBlur})},enumerable:!1,configurable:!0}),n}(),s=function(e){o=e.validation.validate,a=e.validation.preSubmitValidationError},c=function(){if(!o||!a)throw new Error("You must define configureForm to configure mobx-form")},f=function(){function e(e){var r=this;Object.defineProperty(this,"_touched",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_disabled",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_error",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_initValue",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_value",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"setTouched",{enumerable:!0,configurable:!0,writable:!0,value:function(e){r._touched=e}}),Object.defineProperty(this,"add",{enumerable:!0,configurable:!0,writable:!0,value:function(e){r.value.push(e),r.setTouched(!0),r._validate()}}),Object.defineProperty(this,"removeByIndex",{enumerable:!0,configurable:!0,writable:!0,value:function(e){r.value.splice(e,1),r.setTouched(!0),r._validate()}}),Object.defineProperty(this,"_validate",{enumerable:!0,configurable:!0,writable:!0,value:function(){var e;r.value.forEach((function(e){return e.formService.validate()})),null===(e=r.validate)||void 0===e||e.call(r)}}),Object.defineProperty(this,"reset",{enumerable:!0,configurable:!0,writable:!0,value:function(){r._value=r.initValue,r._value.forEach((function(e){return e.formService.reset()})),r.setTouched(!1)}}),Object.defineProperty(this,"setAsInit",{enumerable:!0,configurable:!0,writable:!0,value:function(){r._initValue=r.value,r._value.forEach((function(e){return e.formService.setValuesAsInit()})),r.setTouched(!1)}}),Object.defineProperty(this,"getValues",{enumerable:!0,configurable:!0,writable:!0,value:function(){return r.value.map((function(e){return e.formService.getValues()}))}}),t(this),this.initValue=e||[]}return Object.defineProperty(e.prototype,"initValue",{get:function(){return this._initValue},set:function(e){this._initValue=e,this._value=e.slice(0),this.setTouched(!1),this._validate()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"value",{get:function(){return this._value},set:function(e){this._value=e,this.setTouched(!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"disabled",{get:function(){return this._disabled},set:function(e){this._disabled=e,e?this.value.forEach((function(e){return e.formService.disable()})):this.value.forEach((function(e){return e.formService.enable()}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"error",{get:function(){return this._error},set:function(e){this._error=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isValid",{get:function(){return!this._error&&this.value.every((function(e){return e.formService.isValid}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isTouched",{get:function(){return this._touched||this.value.some((function(e){return e.formService.isTouched}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isInit",{get:function(){return!this.isTouched},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"hasItems",{get:function(){return Boolean(this.value.length)},enumerable:!1,configurable:!0}),e}(),b=function(){function e(e,r){var i=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,"onSubmit",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"setOnSubmit",{enumerable:!0,configurable:!0,writable:!0,value:function(e){i.onSubmit=e}}),Object.defineProperty(this,"submit",{enumerable:!0,configurable:!0,writable:!0,value:function(){return n(i,void 0,void 0,(function(){var e;return u(this,(function(t){switch(t.label){case 0:return[4,this.validate("everything")];case 1:return t.sent(),this.canBeSubmitted?[2,null===(e=this.onSubmit)||void 0===e?void 0:e.call(this)]:(null==a||a(),[2])}}))}))}}),Object.defineProperty(this,"validate",{enumerable:!0,configurable:!0,writable:!0,value:function(e){return void 0===e&&(e="only-touched"),n(i,void 0,void 0,(function(){var t,r;return u(this,(function(i){switch(i.label){case 0:return t=this.getValues(),[4,null==o?void 0:o(t,this.validationSchema)];case 1:return(r=i.sent())&&0!=Object.keys(r||[]).length?this.setErrors(r,e):this.resetErrors(),[2]}}))}))}}),Object.defineProperty(this,"setValidationSchema",{enumerable:!0,configurable:!0,writable:!0,value:function(e){i.validationSchema=e,i.setValidationToFields()}}),Object.defineProperty(this,"getValues",{enumerable:!0,configurable:!0,writable:!0,value:function(){for(var e={},t=0,r=i.keys;t<r.length;t++){var n=r[t];e[n]=i.getValue(i.fields[n])}return e}}),Object.defineProperty(this,"getValue",{enumerable:!0,configurable:!0,writable:!0,value:function(e){if(e instanceof l||e instanceof f)return null==e?void 0:e.value;if("object"==typeof e){for(var t={},r=0,n=Object.keys(e);r<n.length;r++){var u=n[r];t[u]=i.getValue(null==e?void 0:e[u])}return t}return 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||e[r]instanceof f)&&(t[r]=e[r])})),i.fields=t,i.setValidationToFields()}}),Object.defineProperty(this,"bypassFields",{enumerable:!0,configurable:!0,writable:!0,value:function(e,t,r){e instanceof l||e instanceof f?t(e,r):"object"==typeof e&&Object.keys(e||{}).forEach((function(n){i.bypassFields(null==e?void 0:e[n],t,null==r?void 0:r[n])}))}}),Object.defineProperty(this,"setValidationToFields",{enumerable:!0,configurable:!0,writable:!0,value:function(){i.bypassFields(i.fields,(function(e){return e.validate=i.validate}))}}),Object.defineProperty(this,"setInitValues",{enumerable:!0,configurable:!0,writable:!0,value:function(e){i.bypassFields(i.fields,(function(e,t){return e.initValue=t}),e)}}),Object.defineProperty(this,"setValues",{enumerable:!0,configurable:!0,writable:!0,value:function(e){i.bypassFields(i.fields,(function(e,t){return e.value=t}),e)}}),Object.defineProperty(this,"resetErrors",{enumerable:!0,configurable:!0,writable:!0,value:function(){i.bypassFields(i.fields,(function(e){return e.error=void 0}))}}),Object.defineProperty(this,"setValuesAsInit",{enumerable:!0,configurable:!0,writable:!0,value:function(){i.bypassFields(i.fields,(function(e){e.setAsInit()}))}}),Object.defineProperty(this,"reset",{enumerable:!0,configurable:!0,writable:!0,value:function(){i.bypassFields(i.fields,(function(e){return e.reset()})),i.validate()}}),Object.defineProperty(this,"disable",{enumerable:!0,configurable:!0,writable:!0,value:function(){i.bypassFields(i.fields,(function(e){return e.disabled=!0}))}}),Object.defineProperty(this,"enable",{enumerable:!0,configurable:!0,writable:!0,value:function(){i.bypassFields(i.fields,(function(e){return e.disabled=!1}))}}),c(),t(this),this.fields=e,this.validationSchema=r,this.setValidationToFields()}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=!0;return this.bypassFields(this.fields,(function(t){t.isValid||(e=!1)})),e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isTouched",{get:function(){var e=!1;return this.bypassFields(this.fields,(function(t){t.isTouched&&(e=!0)})),e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"canBeSubmitted",{get:function(){return this.isTouched&&this.isValid},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"disabled",{get:function(){var e=!0;return this.bypassFields(this.fields,(function(t){t.disabled||(e=!1)})),e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"setErrors",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){void 0===t&&(t="only-touched"),this.bypassFields(this.fields,(function(e,r){(e.isTouched||"everything"===t)&&(e.error=r)}),e)}}),e}(),d=function(){function e(){var e=this;Object.defineProperty(this,"formServices",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"setForms",{enumerable:!0,configurable:!0,writable:!0,value:function(t){e.formServices=t}}),Object.defineProperty(this,"validate",{enumerable:!0,configurable:!0,writable:!0,value:function(t){return n(e,void 0,void 0,(function(){var e,r;return u(this,(function(i){switch(i.label){case 0:e=0,r=this.formServices,i.label=1;case 1:return e<r.length?[4,r[e].validate(t)]:[3,4];case 2:i.sent(),i.label=3;case 3:return e++,[3,1];case 4:return[2]}}))}))}}),Object.defineProperty(this,"getValues",{enumerable:!0,configurable:!0,writable:!0,value:function(){return e.formServices.map((function(e){return e.getValues()}))}}),Object.defineProperty(this,"resetErrors",{enumerable:!0,configurable:!0,writable:!0,value:function(){return e.formServices.forEach((function(e){return e.resetErrors()}))}}),Object.defineProperty(this,"setValuesAsInit",{enumerable:!0,configurable:!0,writable:!0,value:function(){return e.formServices.forEach((function(e){return e.setValuesAsInit()}))}}),Object.defineProperty(this,"reset",{enumerable:!0,configurable:!0,writable:!0,value:function(){return e.formServices.forEach((function(e){return e.reset()}))}}),Object.defineProperty(this,"disable",{enumerable:!0,configurable:!0,writable:!0,value:function(){return e.formServices.forEach((function(e){return e.disable()}))}}),Object.defineProperty(this,"enable",{enumerable:!0,configurable:!0,writable:!0,value:function(){return e.formServices.forEach((function(e){return e.enable()}))}}),t(this)}return Object.defineProperty(e.prototype,"fields",{get:function(){return this.formServices.map((function(e){return e.fields})).flat()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"keys",{get:function(){return this.formServices.map((function(e){return e.keys})).flat()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isValid",{get:function(){return this.formServices.every((function(e){return e.isValid}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isTouched",{get:function(){return this.formServices.some((function(e){return e.isTouched}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"canBeSubmitted",{get:function(){return this.isTouched&&this.isValid},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"disabled",{get:function(){return this.formServices.every((function(e){return e.disabled}))},enumerable:!1,configurable:!0}),e}(),h=function(){function e(e){var r=this;Object.defineProperty(this,"field",{enumerable:!0,configurable:!0,writable:!0,value:new l(null)}),Object.defineProperty(this,"inputField",{enumerable:!0,configurable:!0,writable:!0,value:new l("")}),Object.defineProperty(this,"setValue",{enumerable:!0,configurable:!0,writable:!0,value:function(e,t){var i=t.inputValue,n=void 0===i?"":i,u=t.withNotification;void 0===u||u?(r.field.value=e,r.inputField.value=n):(r.field.pauseListener(),r.inputField.pauseListener(),r.field.value=e,r.inputField.value=n,r.field.resumeListener(),r.inputField.resumeListener())}}),Object.defineProperty(this,"reset",{enumerable:!0,configurable:!0,writable:!0,value:function(){r.field.reset()}}),Object.defineProperty(this,"setAsInit",{enumerable:!0,configurable:!0,writable:!0,value:function(){r.field.setAsInit()}}),Object.defineProperty(this,"onInputChange",{enumerable:!0,configurable:!0,writable:!0,value:function(e,t){r.inputField.value=t}}),t(this),this.field.initValue=e}return Object.defineProperty(e.prototype,"validate",{get:function(){return this.field.validate},set:function(e){this.field.validate=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"value",{get:function(){return this.field.value},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"error",{get:function(){return this.field.error},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"disabled",{get:function(){return this.field.disabled},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isValid",{get:function(){return this.field.isValid},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isInit",{get:function(){return this.field.isInit},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"props",{get:function(){return i(i({},this.field.props),{inputValue:this.inputField.value,onInputChange:this.onInputChange})},enumerable:!1,configurable:!0}),e}();export{h as AutocompleteFieldService,f as CombinedFormFieldService,d as CombinedFormService,l as FieldService,b as FormService,c as _checkConfiguration,s as configureForm,a as preSubmitValidationError,o as validate}; |
@@ -16,3 +16,3 @@ import { FormService } from "./form-service"; | ||
isInit: boolean; | ||
validate?(): Promise<void>; | ||
validate?: () => Promise<void>; | ||
reset(): void; | ||
@@ -19,0 +19,0 @@ setAsInit(): void; |
@@ -5,3 +5,3 @@ { | ||
"private": false, | ||
"version": "2.10.10", | ||
"version": "2.10.11", | ||
"description": "provides the ability to use forms with validation in MobX stores", | ||
@@ -8,0 +8,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29174
338