@zeedhi/common 1.108.1 → 1.109.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.
@@ -2876,11 +2876,20 @@ class Number$1 extends TextInput {
2876
2876
  this.formatterFn = FormatterParserProvider.getFormatter('ZdNumber');
2877
2877
  this.parserFn = FormatterParserProvider.getParser('ZdNumber');
2878
2878
  this.maskValid = false;
2879
- const newMask = Object.assign(Object.assign({}, this.defaultMask), props.mask);
2879
+ const newMask = this.mergeMasks(this.defaultMask, props.mask);
2880
2880
  this.align = this.getInitValue('align', props.align, this.align);
2881
2881
  this.mask = this.getInitValue('mask', newMask, this.defaultMask);
2882
2882
  this.createAccessors();
2883
2883
  this.validateMask();
2884
+ this.initializeMaskProxy();
2885
+ }
2886
+ /**
2887
+ * Merges two masks
2888
+ */
2889
+ mergeMasks(maskA, maskB) {
2890
+ if (typeof maskB !== 'object')
2891
+ return Object.assign({}, maskA);
2892
+ return Object.assign(Object.assign({}, maskA), maskB);
2884
2893
  }
2885
2894
  validateMask() {
2886
2895
  AutoNumeric.validate(this.mask, true);
@@ -2934,6 +2943,35 @@ class Number$1 extends TextInput {
2934
2943
  this.localValue = parsed;
2935
2944
  }
2936
2945
  }
2946
+ /**
2947
+ * initializes a mask proxy to call update when the mask is changed
2948
+ */
2949
+ initializeMaskProxy() {
2950
+ this.internalMask = new Proxy(Object.assign({}, this.mask), {
2951
+ set: (target, prop, newValue) => {
2952
+ target[prop] = newValue;
2953
+ setTimeout(() => {
2954
+ var _a;
2955
+ (_a = this.autoNumericObj) === null || _a === void 0 ? void 0 : _a.update(this.mask);
2956
+ });
2957
+ return true;
2958
+ },
2959
+ });
2960
+ }
2961
+ get mask() {
2962
+ return this.internalMask;
2963
+ }
2964
+ set mask(value) {
2965
+ this.internalMask = value;
2966
+ if (typeof value !== 'object')
2967
+ return;
2968
+ // when the mask is replaced, should reinitialize the mask Proxy
2969
+ setTimeout(() => {
2970
+ var _a;
2971
+ this.initializeMaskProxy();
2972
+ (_a = this.autoNumericObj) === null || _a === void 0 ? void 0 : _a.update(this.mask);
2973
+ });
2974
+ }
2937
2975
  /**
2938
2976
  * Retrieves a formatted value with mask
2939
2977
  * @param value Any value
@@ -2883,11 +2883,20 @@
2883
2883
  this.formatterFn = core.FormatterParserProvider.getFormatter('ZdNumber');
2884
2884
  this.parserFn = core.FormatterParserProvider.getParser('ZdNumber');
2885
2885
  this.maskValid = false;
2886
- const newMask = Object.assign(Object.assign({}, this.defaultMask), props.mask);
2886
+ const newMask = this.mergeMasks(this.defaultMask, props.mask);
2887
2887
  this.align = this.getInitValue('align', props.align, this.align);
2888
2888
  this.mask = this.getInitValue('mask', newMask, this.defaultMask);
2889
2889
  this.createAccessors();
2890
2890
  this.validateMask();
2891
+ this.initializeMaskProxy();
2892
+ }
2893
+ /**
2894
+ * Merges two masks
2895
+ */
2896
+ mergeMasks(maskA, maskB) {
2897
+ if (typeof maskB !== 'object')
2898
+ return Object.assign({}, maskA);
2899
+ return Object.assign(Object.assign({}, maskA), maskB);
2891
2900
  }
2892
2901
  validateMask() {
2893
2902
  AutoNumeric.validate(this.mask, true);
@@ -2941,6 +2950,35 @@
2941
2950
  this.localValue = parsed;
2942
2951
  }
2943
2952
  }
2953
+ /**
2954
+ * initializes a mask proxy to call update when the mask is changed
2955
+ */
2956
+ initializeMaskProxy() {
2957
+ this.internalMask = new Proxy(Object.assign({}, this.mask), {
2958
+ set: (target, prop, newValue) => {
2959
+ target[prop] = newValue;
2960
+ setTimeout(() => {
2961
+ var _a;
2962
+ (_a = this.autoNumericObj) === null || _a === void 0 ? void 0 : _a.update(this.mask);
2963
+ });
2964
+ return true;
2965
+ },
2966
+ });
2967
+ }
2968
+ get mask() {
2969
+ return this.internalMask;
2970
+ }
2971
+ set mask(value) {
2972
+ this.internalMask = value;
2973
+ if (typeof value !== 'object')
2974
+ return;
2975
+ // when the mask is replaced, should reinitialize the mask Proxy
2976
+ setTimeout(() => {
2977
+ var _a;
2978
+ this.initializeMaskProxy();
2979
+ (_a = this.autoNumericObj) === null || _a === void 0 ? void 0 : _a.update(this.mask);
2980
+ });
2981
+ }
2944
2982
  /**
2945
2983
  * Retrieves a formatted value with mask
2946
2984
  * @param value Any value
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeedhi/common",
3
- "version": "1.108.1",
3
+ "version": "1.109.0",
4
4
  "description": "Zeedhi Common",
5
5
  "author": "Zeedhi <zeedhi@teknisa.com>",
6
6
  "license": "ISC",
@@ -43,5 +43,5 @@
43
43
  "lodash.times": "4.3.*",
44
44
  "mockdate": "3.0.*"
45
45
  },
46
- "gitHead": "9cd96dd092145062a963f12aaba1bb3e0d872cc8"
46
+ "gitHead": "1f4ffbc7dac5b71cff4065c5956921405a362085"
47
47
  }
@@ -1,25 +1,36 @@
1
1
  import { INumber } from './interfaces';
2
2
  import { TextInput } from '../zd-text-input/text-input';
3
+ export declare type AutoNumericObj = {
4
+ rawValue: string;
5
+ update(mask: any): any;
6
+ clear(): any;
7
+ setValue(value: number): any;
8
+ remove(): any;
9
+ };
3
10
  /**
4
11
  * Base class for Number component
5
12
  */
6
13
  export declare class Number extends TextInput implements INumber {
7
- mask: any;
8
14
  protected defaultMask: any;
9
15
  align: string;
10
16
  /**
11
17
  * AutoNumeric object
12
18
  */
13
- autoNumericObj: any;
19
+ autoNumericObj: AutoNumericObj;
14
20
  private formattedValue?;
15
21
  private localValue?;
16
22
  protected formatterFn: Function;
17
23
  protected parserFn: Function;
18
24
  private maskValid;
25
+ private internalMask;
19
26
  /**
20
27
  * Creates a new number input
21
28
  */
22
29
  constructor(props: INumber);
30
+ /**
31
+ * Merges two masks
32
+ */
33
+ private mergeMasks;
23
34
  validateMask(): void;
24
35
  get value(): any;
25
36
  set value(value: any);
@@ -28,6 +39,12 @@ export declare class Number extends TextInput implements INumber {
28
39
  */
29
40
  get displayValue(): any;
30
41
  set displayValue(value: any);
42
+ /**
43
+ * initializes a mask proxy to call update when the mask is changed
44
+ */
45
+ private initializeMaskProxy;
46
+ get mask(): any;
47
+ set mask(value: any);
31
48
  /**
32
49
  * Retrieves a formatted value with mask
33
50
  * @param value Any value
@@ -0,0 +1,12 @@
1
+ export interface IJSONObject {
2
+ path: string;
3
+ }
4
+ export declare class JsonCacheService {
5
+ /**
6
+ * jsons collection
7
+ */
8
+ static jsonCollection: IJSONObject[];
9
+ static saveJSONCache(jsonCollection: IJSONObject[]): Promise<void>;
10
+ static getJSONCache(path: string): any;
11
+ static clearJSONCache(jsonCollection: IJSONObject[]): void;
12
+ }