@mobx-ecosystem/mobx-form 2.0.4 → 2.0.6
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 +2 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/field-service.d.ts
CHANGED
|
@@ -3,11 +3,11 @@ type FieldOptionsType = {
|
|
|
3
3
|
};
|
|
4
4
|
type Nullable<T> = T | null;
|
|
5
5
|
export declare class FieldService<T> {
|
|
6
|
+
validate?(): Promise<void>;
|
|
6
7
|
_serviceType: string;
|
|
7
8
|
_initValue?: Nullable<T>;
|
|
8
9
|
_value?: Nullable<T>;
|
|
9
10
|
_error?: string;
|
|
10
|
-
validate?(): Promise<void>;
|
|
11
11
|
_disabled: boolean;
|
|
12
12
|
options?: FieldOptionsType;
|
|
13
13
|
constructor(initValue?: T, options?: FieldOptionsType);
|
|
@@ -21,6 +21,7 @@ export declare class FieldService<T> {
|
|
|
21
21
|
set disabled(disabled: boolean);
|
|
22
22
|
get isValid(): boolean;
|
|
23
23
|
get isInit(): boolean;
|
|
24
|
+
onChange: (_: any, value: T) => void;
|
|
24
25
|
get props(): any;
|
|
25
26
|
}
|
|
26
27
|
export {};
|
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 i=function(){return i=Object.assign||function(e){for(var t,i=1,r=arguments.length;i<r;i++)for(var n in t=arguments[i])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e},i.apply(this,arguments)};function r(e,t,i,r){return new(i||(i=Promise))((function(n,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?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(u,a)}s((r=r.apply(e,t||[])).next())}))}function n(e,t){var i,r,n,o,u={label:0,sent:function(){if(1&n[0])throw n[1];return n[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(i)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(u=0)),u;)try{if(i=1,r&&(n=2&a[0]?r.return:a[0]?r.throw||((n=r.return)&&n.call(r),0):r.next)&&!(n=n.call(r,a[1])).done)return n;switch(r=0,n&&(a=[2&a[0],n.value]),a[0]){case 0:case 1:n=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(!(n=u.trys,(n=n.length>0&&n[n.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!n||a[1]>n[0]&&a[1]<n[3])){u.label=a[1];break}if(6===a[0]&&u.label<n[1]){u.label=n[1],n=a;break}if(n&&u.label<n[2]){u.label=n[2],u.ops.push(a);break}n[2]&&u.ops.pop(),u.trys.pop();continue}a=t.call(e,u)}catch(e){a=[6,e],r=0}finally{i=n=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,i){var r=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){r.value=t,r.validate&&r.validate()},t(this),this.initValue=e,this.options=i}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}(),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,i){var u=this;this.validate=function(){return r(u,void 0,void 0,(function(){var e,t;return n(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 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=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}),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,s as _checkConfiguration,a as configureForm,o as validate};
|
package/package.json
CHANGED