@mobx-ecosystem/mobx-form 2.0.5 → 2.1.0
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 -1
- package/dist/form-service.d.ts +12 -0
- 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);
|
package/dist/form-service.d.ts
CHANGED
|
@@ -30,6 +30,18 @@ export declare class FormService<T extends Record<string, FieldService<unknown>>
|
|
|
30
30
|
* @returns Object of field values
|
|
31
31
|
*/
|
|
32
32
|
getValues: () => Record<string, unknown>;
|
|
33
|
+
/**
|
|
34
|
+
* Set fields by this
|
|
35
|
+
*/
|
|
36
|
+
setFieldsByThis: (obj: any) => void;
|
|
37
|
+
/**
|
|
38
|
+
* Set object to values by form service keys
|
|
39
|
+
*/
|
|
40
|
+
setValues: (obj: Record<string, unknown>) => void;
|
|
41
|
+
/**
|
|
42
|
+
* Set object to init values by form service keys
|
|
43
|
+
*/
|
|
44
|
+
setInitValues: (obj: Record<string, unknown>) => void;
|
|
33
45
|
/**
|
|
34
46
|
* Set field values to init values
|
|
35
47
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isEqual as e}from"lodash";import{makeAutoObservable as t}from"mobx";var
|
|
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};
|
package/package.json
CHANGED