@zajno/common 1.3.15 → 1.4.2
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/coverage/clover.xml +105 -91
- package/coverage/coverage-final.json +6 -6
- package/coverage/lcov-report/index.html +19 -19
- package/coverage/lcov-report/src/__tests__/helpers/index.html +1 -1
- package/coverage/lcov-report/src/__tests__/helpers/main.ts.html +1 -1
- package/coverage/lcov-report/src/async/arrays.ts.html +1 -1
- package/coverage/lcov-report/src/async/index.html +1 -1
- package/coverage/lcov-report/src/dates/calc.ts.html +1 -1
- package/coverage/lcov-report/src/dates/convert.ts.html +1 -1
- package/coverage/lcov-report/src/dates/datex.ts.html +1 -1
- package/coverage/lcov-report/src/dates/format.ts.html +1 -1
- package/coverage/lcov-report/src/dates/index.html +1 -1
- package/coverage/lcov-report/src/dates/index.ts.html +1 -1
- package/coverage/lcov-report/src/dates/parse.ts.html +1 -1
- package/coverage/lcov-report/src/dates/period.ts.html +1 -1
- package/coverage/lcov-report/src/dates/shift.ts.html +1 -1
- package/coverage/lcov-report/src/dates/types.ts.html +1 -1
- package/coverage/lcov-report/src/dates/yearDate.ts.html +1 -1
- package/coverage/lcov-report/src/enumHelper.ts.html +1 -1
- package/coverage/lcov-report/src/event.ts.html +1 -1
- package/coverage/lcov-report/src/fields/index.html +1 -1
- package/coverage/lcov-report/src/fields/update.ts.html +1 -1
- package/coverage/lcov-report/src/functions.ts.html +1 -1
- package/coverage/lcov-report/src/index.html +1 -1
- package/coverage/lcov-report/src/lazy.light.ts.html +4 -4
- package/coverage/lcov-report/src/logger/batch.ts.html +1 -1
- package/coverage/lcov-report/src/logger/console.ts.html +1 -1
- package/coverage/lcov-report/src/logger/index.html +1 -1
- package/coverage/lcov-report/src/logger/index.ts.html +1 -1
- package/coverage/lcov-report/src/logger/named.ts.html +1 -1
- package/coverage/lcov-report/src/logger/proxy.ts.html +1 -1
- package/coverage/lcov-report/src/math/arrays.ts.html +1 -1
- package/coverage/lcov-report/src/math/calc.ts.html +1 -1
- package/coverage/lcov-report/src/math/distribution.ts.html +1 -1
- package/coverage/lcov-report/src/math/index.html +1 -1
- package/coverage/lcov-report/src/math/index.ts.html +1 -1
- package/coverage/lcov-report/src/transitionObserver.ts.html +1 -1
- package/coverage/lcov-report/src/types.ts.html +1 -1
- package/coverage/lcov-report/src/validation/ValidationErrors.ts.html +1 -1
- package/coverage/lcov-report/src/validation/creditCard.ts.html +1 -1
- package/coverage/lcov-report/src/validation/helpers.ts.html +1 -1
- package/coverage/lcov-report/src/validation/index.html +1 -1
- package/coverage/lcov-report/src/validation/index.ts.html +1 -1
- package/coverage/lcov-report/src/validation/types.ts.html +1 -1
- package/coverage/lcov-report/src/validation/validators.ts.html +1 -1
- package/coverage/lcov-report/src/validation/wrappers.ts.html +1 -1
- package/coverage/lcov-report/src/viewModels/FlagModel.ts.html +25 -10
- package/coverage/lcov-report/src/viewModels/MultiSelectModel.ts.html +20 -8
- package/coverage/lcov-report/src/viewModels/NumberModel.ts.html +24 -9
- package/coverage/lcov-report/src/viewModels/SelectModel.ts.html +48 -21
- package/coverage/lcov-report/src/viewModels/Validatable.ts.html +42 -18
- package/coverage/lcov-report/src/viewModels/index.html +52 -52
- package/coverage/lcov-report/src/viewModels/wrappers.ts.html +1 -1
- package/coverage/lcov.info +266 -237
- package/lib/viewModels/CommonModel.d.ts +13 -0
- package/lib/viewModels/CommonModel.d.ts.map +1 -0
- package/lib/viewModels/CommonModel.js +37 -0
- package/lib/viewModels/CommonModel.js.map +1 -0
- package/lib/viewModels/FlagModel.d.ts +1 -0
- package/lib/viewModels/FlagModel.d.ts.map +1 -1
- package/lib/viewModels/FlagModel.js +8 -1
- package/lib/viewModels/FlagModel.js.map +1 -1
- package/lib/viewModels/MultiSelectModel.d.ts.map +1 -1
- package/lib/viewModels/MultiSelectModel.js +3 -0
- package/lib/viewModels/MultiSelectModel.js.map +1 -1
- package/lib/viewModels/NumberModel.d.ts +1 -0
- package/lib/viewModels/NumberModel.d.ts.map +1 -1
- package/lib/viewModels/NumberModel.js +8 -1
- package/lib/viewModels/NumberModel.js.map +1 -1
- package/lib/viewModels/SelectModel.d.ts +1 -0
- package/lib/viewModels/SelectModel.d.ts.map +1 -1
- package/lib/viewModels/SelectModel.js +24 -14
- package/lib/viewModels/SelectModel.js.map +1 -1
- package/lib/viewModels/TextModel.d.ts +2 -0
- package/lib/viewModels/TextModel.d.ts.map +1 -1
- package/lib/viewModels/TextModel.js +27 -23
- package/lib/viewModels/TextModel.js.map +1 -1
- package/lib/viewModels/Validatable.d.ts +3 -1
- package/lib/viewModels/Validatable.d.ts.map +1 -1
- package/lib/viewModels/Validatable.js +14 -7
- package/lib/viewModels/Validatable.js.map +1 -1
- package/lib/viewModels/index.d.ts +1 -0
- package/lib/viewModels/index.d.ts.map +1 -1
- package/lib/viewModels/index.js +1 -0
- package/lib/viewModels/index.js.map +1 -1
- package/package.json +1 -1
- package/src/viewModels/CommonModel.ts +43 -0
- package/src/viewModels/FlagModel.ts +6 -1
- package/src/viewModels/MultiSelectModel.ts +4 -0
- package/src/viewModels/NumberModel.ts +6 -1
- package/src/viewModels/SelectModel.ts +11 -2
- package/src/viewModels/TextModel.ts +21 -11
- package/src/viewModels/Validatable.ts +16 -8
- package/src/viewModels/index.ts +1 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createLazy } from '../lazy.light';
|
|
2
|
-
import { observable, computed, makeObservable, reaction } from 'mobx';
|
|
2
|
+
import { observable, computed, makeObservable, reaction, action } from 'mobx';
|
|
3
3
|
import { FlagModel, ILabeledFlagModel } from './FlagModel';
|
|
4
4
|
import { ValidatableModel } from './Validatable';
|
|
5
5
|
import { IValueModel } from './types';
|
|
@@ -75,12 +75,21 @@ export class Select<T = any> extends ValidatableModel<T> implements IValueModel<
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
set index(val: number) {
|
|
78
|
+
this.setIndex(val);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@action
|
|
82
|
+
public setIndex = (val: number) => {
|
|
78
83
|
if (this._indexLocked) {
|
|
79
84
|
return;
|
|
80
85
|
}
|
|
81
86
|
|
|
82
87
|
this._index = val;
|
|
83
88
|
|
|
89
|
+
if (this._validateOnChange) {
|
|
90
|
+
this.validate();
|
|
91
|
+
}
|
|
92
|
+
|
|
84
93
|
// update all flags to be properly selected
|
|
85
94
|
try {
|
|
86
95
|
this._indexLocked = true;
|
|
@@ -91,7 +100,7 @@ export class Select<T = any> extends ValidatableModel<T> implements IValueModel<
|
|
|
91
100
|
} finally {
|
|
92
101
|
this._indexLocked = false;
|
|
93
102
|
}
|
|
94
|
-
}
|
|
103
|
+
};
|
|
95
104
|
|
|
96
105
|
reset = () => {
|
|
97
106
|
super.reset();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { observable,
|
|
1
|
+
import { observable, makeObservable, reaction, action } from 'mobx';
|
|
2
2
|
import { Getter } from '../types';
|
|
3
3
|
import { IValueModel } from './types';
|
|
4
4
|
import logger from '../logger';
|
|
@@ -46,10 +46,7 @@ export class TextInputVM extends ValidatableModel<string> implements IValueModel
|
|
|
46
46
|
@observable
|
|
47
47
|
private _focused = false;
|
|
48
48
|
|
|
49
|
-
@observable
|
|
50
49
|
private _name: string = null;
|
|
51
|
-
|
|
52
|
-
@observable
|
|
53
50
|
private _title: string = null;
|
|
54
51
|
|
|
55
52
|
private readonly _valueObserving: () => void = null;
|
|
@@ -71,14 +68,22 @@ export class TextInputVM extends ValidatableModel<string> implements IValueModel
|
|
|
71
68
|
get title() { return this._title; }
|
|
72
69
|
|
|
73
70
|
set value(val) {
|
|
71
|
+
this.setValue(val);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@action
|
|
75
|
+
public readonly setValue = (value: string) => {
|
|
74
76
|
if (!this._valueObserving) {
|
|
75
|
-
this._value =
|
|
77
|
+
this._value = value;
|
|
78
|
+
|
|
79
|
+
if (this._validateOnChange) {
|
|
80
|
+
this.validate();
|
|
81
|
+
}
|
|
76
82
|
} else {
|
|
77
83
|
logger.warn('[TextInputViewModel] Setting value is not allowed when value is observing');
|
|
78
84
|
}
|
|
79
|
-
}
|
|
85
|
+
};
|
|
80
86
|
|
|
81
|
-
@computed
|
|
82
87
|
get isEmpty() {
|
|
83
88
|
return !this._value;
|
|
84
89
|
}
|
|
@@ -87,15 +92,20 @@ export class TextInputVM extends ValidatableModel<string> implements IValueModel
|
|
|
87
92
|
return this._focused;
|
|
88
93
|
}
|
|
89
94
|
|
|
90
|
-
set focused(val) {
|
|
91
|
-
this.
|
|
92
|
-
|
|
95
|
+
set focused(val: boolean) {
|
|
96
|
+
this.setFocused(val);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@action
|
|
100
|
+
public readonly setFocused = (value = true) => {
|
|
101
|
+
this._focused = value;
|
|
102
|
+
if (!value) {
|
|
93
103
|
this.onBlur();
|
|
94
104
|
return;
|
|
95
105
|
}
|
|
96
106
|
|
|
97
107
|
super.reset();
|
|
98
|
-
}
|
|
108
|
+
};
|
|
99
109
|
|
|
100
110
|
protected get valueToValidate() { return (this.value ?? '').trim(); }
|
|
101
111
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { observable, makeObservable, action } from 'mobx';
|
|
1
|
+
import { observable, makeObservable, action, runInAction } from 'mobx';
|
|
2
2
|
import { ValidatorFunction, ValidatorFunctionAsync, ValidationErrors, ValidationError } from '../validation';
|
|
3
3
|
import { someAsync } from '../async/arrays';
|
|
4
4
|
|
|
5
5
|
export type ValueValidator<T, TErrors = ValidationErrors> = ValidatorFunction<T, TErrors> | ValidatorFunctionAsync<T, TErrors>;
|
|
6
|
-
export type ValidationErrorsStrings<TErrors extends string | number = number> = Record<TErrors, string
|
|
6
|
+
export type ValidationErrorsStrings<TErrors extends string | number = number> = Partial<Omit<Record<TErrors, string>, 0 | null>>;
|
|
7
7
|
|
|
8
8
|
export type ValidationConfig<T, TErrors extends string | number = ValidationErrors> = {
|
|
9
9
|
validator: ValueValidator<Readonly<T>, TErrors>,
|
|
@@ -21,6 +21,7 @@ export abstract class ValidatableModel<T = string> {
|
|
|
21
21
|
private _error: string = null;
|
|
22
22
|
|
|
23
23
|
private _validationError: ValidationError = null;
|
|
24
|
+
protected _validateOnChange = false;
|
|
24
25
|
|
|
25
26
|
constructor() {
|
|
26
27
|
makeObservable(this);
|
|
@@ -38,6 +39,11 @@ export abstract class ValidatableModel<T = string> {
|
|
|
38
39
|
return this;
|
|
39
40
|
}
|
|
40
41
|
|
|
42
|
+
public validateOnChange(enable = true) {
|
|
43
|
+
this._validateOnChange = enable;
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
|
|
41
47
|
public async testValidate(value: T) {
|
|
42
48
|
if (this._validator) {
|
|
43
49
|
const res = await this._validator(value);
|
|
@@ -60,12 +66,14 @@ export abstract class ValidatableModel<T = string> {
|
|
|
60
66
|
this._validationError = err as ValidationError;
|
|
61
67
|
}
|
|
62
68
|
|
|
63
|
-
|
|
64
|
-
this.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
+
runInAction(() => {
|
|
70
|
+
if (!this._validationError) {
|
|
71
|
+
this._error = null;
|
|
72
|
+
} else {
|
|
73
|
+
const code = this._validationError.code;
|
|
74
|
+
this._error = this._strings && this._strings[code];
|
|
75
|
+
}
|
|
76
|
+
});
|
|
69
77
|
return this._validationError == null;
|
|
70
78
|
}
|
|
71
79
|
|