@genesislcap/foundation-ui 14.304.3-alpha-efb2fd0.0 → 14.305.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/custom-elements.json +1214 -1385
- package/dist/dts/number-field/number-field.d.ts +0 -2
- package/dist/dts/number-field/number-field.d.ts.map +1 -1
- package/dist/dts/number-field/number-field.template.d.ts.map +1 -1
- package/dist/dts/number-field/utils.d.ts +3 -39
- package/dist/dts/number-field/utils.d.ts.map +1 -1
- package/dist/dts/stepper/stepper.d.ts +3 -0
- package/dist/dts/stepper/stepper.d.ts.map +1 -1
- package/dist/esm/number-field/number-field.js +43 -90
- package/dist/esm/number-field/utils.js +9 -260
- package/dist/esm/stepper/stepper.js +55 -10
- package/package.json +18 -18
|
@@ -10,8 +10,6 @@ export declare class NumberField extends FASTNumberField {
|
|
|
10
10
|
value: string;
|
|
11
11
|
withFormatting: boolean;
|
|
12
12
|
locale: string;
|
|
13
|
-
autoStepPrecision: boolean;
|
|
14
|
-
maximumInputPrecision: number;
|
|
15
13
|
options: Intl.NumberFormatOptions;
|
|
16
14
|
stepUp(): void;
|
|
17
15
|
stepDown(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number-field.d.ts","sourceRoot":"","sources":["../../../src/number-field/number-field.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,IAAI,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE5E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"number-field.d.ts","sourceRoot":"","sources":["../../../src/number-field/number-field.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,IAAI,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE5E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAOrE;;GAEG;AACH,qBAAa,WAAY,SAAQ,eAAe;IACxC,YAAY,EAAE,MAAM,CAAC;IAC3B,OAAO,CAAC,mBAAmB;IAKA,QAAQ,EAAE,OAAO,CAAS;IAC/C,KAAK,EAAE,MAAM,CAAM;IACE,cAAc,EAAE,OAAO,CAAS;IACrD,MAAM,EAAE,MAAM,CAAW;IAE/B,OAAO,EAAE,IAAI,CAAC,mBAAmB,CAG/B;IAEF,MAAM,IAAI,IAAI;IAuBd,QAAQ,IAAI,IAAI;IAuBhB,2BAA2B;IAK3B,eAAe,IAAI,IAAI;IAuBvB,YAAY,CAAC,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,GAAG,IAAI;IAoC5C,UAAU,IAAI,IAAI;CAsBnB;AAED,eAAO,MAAM,kCAAkC,EAAE,cAGhD,CAAC;AAEF,eAAO,MAAM,wBAAwB;;;CAWpC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,oTAMhC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number-field.template.d.ts","sourceRoot":"","sources":["../../../src/number-field/number-field.template.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"number-field.template.d.ts","sourceRoot":"","sources":["../../../src/number-field/number-field.template.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAGL,yBAAyB,EACzB,kBAAkB,EAEnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD;;;;;GAKG;AACH,eAAO,MAAM,6BAA6B,EAAE,yBAAyB,CACnE,YAAY,CAAC,WAAW,CAAC,EACzB,kBAAkB,CA0EnB,CAAC"}
|
|
@@ -5,43 +5,7 @@ export declare const formatControlValue: (value: string, locale: string) => stri
|
|
|
5
5
|
export declare const sanitiseInputVal: (inputVal: string, locale: string) => string;
|
|
6
6
|
export declare const toIntlNumberFormat: (value: string, locale: string, options: Intl.NumberFormatOptions) => string;
|
|
7
7
|
export declare const preserveTrailingZerosAfterParse: (value: string, parsedValue: string, locale: string) => string;
|
|
8
|
-
export declare const validateValue: (value: string, locale: string, withFormatting?: boolean
|
|
9
|
-
export declare const validateInput: (value: string, locale: string
|
|
10
|
-
export declare const validateMinMax: (value: string, locale: string, withFormatting: boolean, min: number, max: number
|
|
11
|
-
/**
|
|
12
|
-
* Performs high precision addition using Pure JavaScript (NO BigInt needed!)
|
|
13
|
-
* This is the BEST solution for precision arithmetic
|
|
14
|
-
* @param a - First number
|
|
15
|
-
* @param b - Second number
|
|
16
|
-
* @returns Sum with maintained precision
|
|
17
|
-
*/
|
|
18
|
-
export declare const addWithPrecision: (a: number, b: number) => number;
|
|
19
|
-
/**
|
|
20
|
-
* Performs high precision subtraction using Pure JavaScript
|
|
21
|
-
* @param a - First number
|
|
22
|
-
* @param b - Second number
|
|
23
|
-
* @returns Difference with maintained precision
|
|
24
|
-
*/
|
|
25
|
-
export declare const subtractWithPrecision: (a: number, b: number) => number;
|
|
26
|
-
/**
|
|
27
|
-
* Increment a value with precision using direct string manipulation
|
|
28
|
-
* @param valueString - The value as a string to maintain precision
|
|
29
|
-
* @param step - The step value to add
|
|
30
|
-
* @returns The incremented value as a string with preserved precision
|
|
31
|
-
*/
|
|
32
|
-
export declare const incrementWithPrecision: (valueString: string | number, step: number) => string;
|
|
33
|
-
/**
|
|
34
|
-
* Decrement a value with precision using direct string manipulation
|
|
35
|
-
* @param valueString - The value as a string to maintain precision
|
|
36
|
-
* @param step - The step value to subtract
|
|
37
|
-
* @returns The decremented value as a string with preserved precision
|
|
38
|
-
*/
|
|
39
|
-
export declare const decrementWithPrecision: (valueString: string | number, step: number) => string;
|
|
40
|
-
/**
|
|
41
|
-
* Calculate auto step precision based on decimal places
|
|
42
|
-
* Maintains original step calculation for compatibility
|
|
43
|
-
* @param value - The value to calculate step precision for
|
|
44
|
-
* @returns The calculated step value
|
|
45
|
-
*/
|
|
46
|
-
export declare const calculateAutoStepPrecision: (value: string | number) => number;
|
|
8
|
+
export declare const validateValue: (value: string, locale: string, withFormatting?: boolean) => string;
|
|
9
|
+
export declare const validateInput: (value: string, locale: string) => string;
|
|
10
|
+
export declare const validateMinMax: (value: string, locale: string, withFormatting: boolean, min: number, max: number) => string;
|
|
47
11
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/number-field/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/number-field/utils.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,uBAAuB,GAClC,OAAO,MAAM,EACb,QAAQ,MAAM,KACb;IAAE,gBAAgB,EAAE,MAAM,CAAA;CAI5B,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,OAAO,MAAM,EAAE,QAAQ,MAAM,KAAG,MAWlE,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,UAAU,MAAM,EAAE,QAAQ,MAAM,KAAG,MAEnE,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAC7B,OAAO,MAAM,EACb,QAAQ,MAAM,EACd,SAAS,IAAI,CAAC,mBAAmB,KAChC,MAEF,CAAC;AAEF,eAAO,MAAM,+BAA+B,GAC1C,OAAO,MAAM,EACb,aAAa,MAAM,EACnB,QAAQ,MAAM,KACb,MA+BF,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,EAAE,QAAQ,MAAM,EAAE,wBAAqB,KAAG,MAYpF,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,EAAE,QAAQ,MAAM,KAAG,MAG7D,CAAC;AAEF,eAAO,MAAM,cAAc,GACzB,OAAO,MAAM,EACb,QAAQ,MAAM,EACd,uBAAqB,EACrB,KAAK,MAAM,EACX,KAAK,MAAM,KACV,MAWF,CAAC"}
|
|
@@ -10,6 +10,7 @@ export declare class Stepper extends FoundationElement {
|
|
|
10
10
|
hideSubmitButton: boolean;
|
|
11
11
|
hideStepNumber: boolean;
|
|
12
12
|
allowBackwardJumps: boolean;
|
|
13
|
+
allowForwardJumps: boolean;
|
|
13
14
|
orientation: TabsOrientation;
|
|
14
15
|
orientationChanged(): void;
|
|
15
16
|
activeid: string;
|
|
@@ -27,6 +28,8 @@ export declare class Stepper extends FoundationElement {
|
|
|
27
28
|
connectedCallback(): void;
|
|
28
29
|
private getActiveIndex;
|
|
29
30
|
handleStepClick(stepIndex: any): void;
|
|
31
|
+
private handleBackwardJump;
|
|
32
|
+
private handleForwardJump;
|
|
30
33
|
get disabledPreviousStep(): boolean;
|
|
31
34
|
get isLastStep(): boolean;
|
|
32
35
|
get islastStepValid(): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stepper.d.ts","sourceRoot":"","sources":["../../../src/stepper/stepper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAEhF,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAI5C,MAAM,MAAM,UAAU,GAAG;IAAE,OAAO,EAAE,MAAM,GAAG,CAAA;CAAE,CAAC;AAEhD;;GAEG;AACH,qBAAa,OAAQ,SAAQ,iBAAiB;IACgB,gBAAgB,EAAE,OAAO,CAAC;IAC5B,cAAc,EAAE,OAAO,CAAC;IACpB,kBAAkB,EAAE,OAAO,CAAS;
|
|
1
|
+
{"version":3,"file":"stepper.d.ts","sourceRoot":"","sources":["../../../src/stepper/stepper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAEhF,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAI5C,MAAM,MAAM,UAAU,GAAG;IAAE,OAAO,EAAE,MAAM,GAAG,CAAA;CAAE,CAAC;AAEhD;;GAEG;AACH,qBAAa,OAAQ,SAAQ,iBAAiB;IACgB,gBAAgB,EAAE,OAAO,CAAC;IAC5B,cAAc,EAAE,OAAO,CAAC;IACpB,kBAAkB,EAAE,OAAO,CAAS;IACrC,iBAAiB,EAAE,OAAO,CAAS;IAC1F,WAAW,EAAE,eAAe,CAA4B;IAC9D,kBAAkB,IAAI,IAAI;IAOpB,QAAQ,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IAQ7C,IAAI,EAAE,UAAU,EAAE,GAAG,WAAW,EAAE,CAAC;IAC/C,WAAW,IAAI,IAAI;IAWP,SAAS,EAAE,WAAW,EAAE,CAAC;IACrC,gBAAgB,IAAI,IAAI;IAUZ,UAAU,EAAE,UAAU,EAAE,CAAC;IACzB,aAAa,SAAK;IAClB,cAAc,EAAE,MAAM,CAAK;IAEvC,SAAS,EAAE,WAAW,CAAC;IACvB,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,WAAW,CAAgB;IAEnC,iBAAiB,IAAI,IAAI;IAQzB,OAAO,CAAC,cAAc;IAStB,eAAe,CAAC,SAAS,KAAA;IAQzB,OAAO,CAAC,kBAAkB;IAe1B,OAAO,CAAC,iBAAiB;IAwCzB,IAAc,oBAAoB,YAEjC;IAED,IAAc,UAAU,YAEvB;IAED,IAAc,eAAe,YAkB5B;IAED,OAAO,IAAI,IAAI;IAIf,QAAQ,IAAI,IAAI;IAqChB,YAAY,IAAI,IAAI;IAQpB,SAAS,CAAC,OAAO,QAAO,IAAI,CAqC1B;IAEF,gBAAgB,aAWd;IAEF,OAAO,CAAC,YAAY,CAUlB;IAEF,OAAO,CAAC,SAAS;IAMjB,OAAO,CAAC,cAAc;IAMtB,OAAO,CAAC,mBAAmB;CAG5B;AAGD,eAAO,MAAM,8BAA8B,EAAE,cAA0B,CAAC;AAExE,eAAO,MAAM,oBAAoB,IAAK,CAAC;AAEvC;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;kBAM5B,CAAC"}
|
|
@@ -4,9 +4,8 @@ import { NumberField as FASTNumberField } from '@microsoft/fast-components';
|
|
|
4
4
|
import { DOM, attr } from '@microsoft/fast-element';
|
|
5
5
|
import { foundationNumberFieldStyles as styles } from './number-field.styles';
|
|
6
6
|
import { foundationNumberFieldTemplate as template } from './number-field.template';
|
|
7
|
-
import {
|
|
7
|
+
import { formatControlValue, toIntlNumberFormat, validateInput, validateMinMax } from './utils';
|
|
8
8
|
const MAX_DECIMAL_PLACES = 3;
|
|
9
|
-
const MAX_INPUT_PRECISION = 12;
|
|
10
9
|
/**
|
|
11
10
|
* @tagname %%prefix%%-number-field
|
|
12
11
|
*/
|
|
@@ -17,8 +16,6 @@ export class NumberField extends FASTNumberField {
|
|
|
17
16
|
this.value = '';
|
|
18
17
|
this.withFormatting = false;
|
|
19
18
|
this.locale = 'en-US';
|
|
20
|
-
this.autoStepPrecision = false;
|
|
21
|
-
this.maximumInputPrecision = MAX_INPUT_PRECISION;
|
|
22
19
|
this.options = {
|
|
23
20
|
maximumFractionDigits: MAX_DECIMAL_PLACES,
|
|
24
21
|
minimumFractionDigits: 0,
|
|
@@ -30,60 +27,33 @@ export class NumberField extends FASTNumberField {
|
|
|
30
27
|
}
|
|
31
28
|
}
|
|
32
29
|
stepUp() {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
this.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
const stepUpValue = incrementWithPrecision(this.value, stepValue);
|
|
47
|
-
this.value = stepUpValue.toString();
|
|
48
|
-
}
|
|
49
|
-
if (this.control) {
|
|
50
|
-
if (this.min !== undefined || this.max !== undefined) {
|
|
51
|
-
this.control.value = validateMinMax(this.value, this.locale, this.withFormatting, this.min, this.max, this.maximumInputPrecision);
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
this.control.value = this.value;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
30
|
+
const value = parseFloat(this.value);
|
|
31
|
+
const stepUpValue = !isNaN(value)
|
|
32
|
+
? value + this.step
|
|
33
|
+
: this.min > 0
|
|
34
|
+
? this.min
|
|
35
|
+
: this.max < 0
|
|
36
|
+
? this.max
|
|
37
|
+
: !this.min
|
|
38
|
+
? this.step
|
|
39
|
+
: 0;
|
|
40
|
+
this.value = stepUpValue.toString();
|
|
41
|
+
this.control.value = validateMinMax(stepUpValue.toString(), this.locale, this.withFormatting, this.min, this.max);
|
|
57
42
|
this.handleTextInput();
|
|
58
43
|
}
|
|
59
44
|
stepDown() {
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
stepValue = this.step;
|
|
75
|
-
}
|
|
76
|
-
const stepDownValue = decrementWithPrecision(this.value, stepValue);
|
|
77
|
-
this.value = stepDownValue.toString();
|
|
78
|
-
}
|
|
79
|
-
if (this.control) {
|
|
80
|
-
if (this.min !== undefined || this.max !== undefined) {
|
|
81
|
-
this.control.value = validateMinMax(this.value, this.locale, this.withFormatting, this.min, this.max, this.maximumInputPrecision);
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
this.control.value = this.value;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
45
|
+
const value = parseFloat(this.value);
|
|
46
|
+
const stepDownValue = !isNaN(value)
|
|
47
|
+
? value - this.step
|
|
48
|
+
: this.min > 0
|
|
49
|
+
? this.min
|
|
50
|
+
: this.max < 0
|
|
51
|
+
? this.max
|
|
52
|
+
: !this.min
|
|
53
|
+
? 0 - this.step
|
|
54
|
+
: 0;
|
|
55
|
+
this.value = stepDownValue.toString();
|
|
56
|
+
this.control.value = validateMinMax(stepDownValue.toString(), this.locale, this.withFormatting, this.min, this.max);
|
|
87
57
|
this.handleTextInput();
|
|
88
58
|
}
|
|
89
59
|
hasSeparatorWithoutDecimals() {
|
|
@@ -91,29 +61,22 @@ export class NumberField extends FASTNumberField {
|
|
|
91
61
|
return new RegExp(regexString);
|
|
92
62
|
}
|
|
93
63
|
handleTextInput() {
|
|
94
|
-
if (!this.control)
|
|
95
|
-
return;
|
|
96
64
|
if (this.control.value === '-' || this.control.value === '-0')
|
|
97
65
|
return;
|
|
98
66
|
this['isUserInput'] = true;
|
|
99
67
|
if (this.withFormatting && !new NumberParser(this.locale).hasSeparator(this.control.value)) {
|
|
100
68
|
DOM.queueUpdate(() => {
|
|
101
|
-
const validValue = validateInput(this.control.value, this.locale
|
|
69
|
+
const validValue = validateInput(this.control.value, this.locale);
|
|
102
70
|
this.value = validValue;
|
|
103
|
-
|
|
104
|
-
this.control.value = formatControlValue(validValue, this.locale);
|
|
105
|
-
}
|
|
71
|
+
this.control.value = formatControlValue(validValue, this.locale);
|
|
106
72
|
this.$emit('input');
|
|
107
73
|
});
|
|
108
74
|
}
|
|
109
75
|
else if (!this.withFormatting &&
|
|
110
76
|
!this.hasSeparatorWithoutDecimals().test(this.control.value)) {
|
|
111
77
|
DOM.queueUpdate(() => {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
this.control.value = this.control.value.replace(/[^0-9\-+e.]/g, '');
|
|
115
|
-
}
|
|
116
|
-
this.value = ((_a = this.control) === null || _a === void 0 ? void 0 : _a.value) || '';
|
|
78
|
+
this.control.value = this.control.value.replace(/[^0-9\-+e.]/g, '');
|
|
79
|
+
this.value = this.control.value;
|
|
117
80
|
this.$emit('input');
|
|
118
81
|
});
|
|
119
82
|
}
|
|
@@ -125,41 +88,37 @@ export class NumberField extends FASTNumberField {
|
|
|
125
88
|
}
|
|
126
89
|
if (next !== undefined && next !== null && next !== previous) {
|
|
127
90
|
if (!this['isUserInput']) {
|
|
128
|
-
this.value = validateMinMax(this.value, this.locale, false, this.min, this.max
|
|
91
|
+
this.value = validateMinMax(this.value, this.locale, false, this.min, this.max);
|
|
129
92
|
DOM.queueUpdate(() => {
|
|
130
|
-
|
|
131
|
-
this.
|
|
132
|
-
this.
|
|
133
|
-
|
|
134
|
-
: this.value;
|
|
135
|
-
}
|
|
93
|
+
this.control.value =
|
|
94
|
+
this.withFormatting && this.value
|
|
95
|
+
? toIntlNumberFormat(this.value, this.locale, this.options)
|
|
96
|
+
: this.value;
|
|
136
97
|
});
|
|
137
98
|
return;
|
|
138
99
|
}
|
|
139
100
|
const value = next;
|
|
140
101
|
DOM.queueUpdate(() => {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
if (this.control.value === '' || this.value === '') {
|
|
102
|
+
var _a;
|
|
103
|
+
if (((_a = this.control) === null || _a === void 0 ? void 0 : _a.value) === '' || this.value === '') {
|
|
144
104
|
this.control.value = value;
|
|
145
105
|
return;
|
|
146
106
|
}
|
|
147
107
|
this.control.value = formatControlValue(String(value), this.locale);
|
|
148
108
|
this.value = this.withFormatting
|
|
149
|
-
? validateInput(this.control.value, this.locale
|
|
109
|
+
? validateInput(this.control.value, this.locale)
|
|
150
110
|
: this.control.value;
|
|
151
111
|
});
|
|
152
112
|
}
|
|
153
113
|
}
|
|
154
114
|
handleBlur() {
|
|
155
|
-
if (!this.control)
|
|
156
|
-
return;
|
|
157
115
|
this['isUserInput'] = false;
|
|
158
|
-
const validatedValue = validateMinMax(this.control.value, this.locale, this.withFormatting, this.min, this.max
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
116
|
+
const validatedValue = validateMinMax(this.control.value, this.locale, this.withFormatting, this.min, this.max);
|
|
117
|
+
if (validatedValue && !isNaN(parseFloat(validatedValue))) {
|
|
118
|
+
this.value = Intl.NumberFormat('en-US', {
|
|
119
|
+
maximumFractionDigits: this.options.maximumFractionDigits,
|
|
120
|
+
useGrouping: false,
|
|
121
|
+
}).format(parseFloat(validatedValue));
|
|
163
122
|
}
|
|
164
123
|
this.control.value =
|
|
165
124
|
this.withFormatting && this.value
|
|
@@ -183,12 +142,6 @@ __decorate([
|
|
|
183
142
|
__decorate([
|
|
184
143
|
attr
|
|
185
144
|
], NumberField.prototype, "locale", void 0);
|
|
186
|
-
__decorate([
|
|
187
|
-
attr({ mode: 'boolean' })
|
|
188
|
-
], NumberField.prototype, "autoStepPrecision", void 0);
|
|
189
|
-
__decorate([
|
|
190
|
-
attr
|
|
191
|
-
], NumberField.prototype, "maximumInputPrecision", void 0);
|
|
192
145
|
export const foundationNumberFieldShadowOptions = {
|
|
193
146
|
delegatesFocus: true,
|
|
194
147
|
mode: 'open',
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { NumberParser } from '@genesislcap/foundation-utils';
|
|
2
2
|
const formattedInputPrecision = 12;
|
|
3
3
|
const FORMAT_TEST_NUMBER = 12345.6;
|
|
4
|
-
const DECIMAL_BASE = 10;
|
|
5
4
|
export const getSeparatorsFromParser = (value, locale) => {
|
|
6
5
|
var _a;
|
|
7
6
|
const parts = new Intl.NumberFormat(locale).formatToParts(FORMAT_TEST_NUMBER);
|
|
@@ -50,78 +49,19 @@ export const preserveTrailingZerosAfterParse = (value, parsedValue, locale) => {
|
|
|
50
49
|
}
|
|
51
50
|
return String(parsedValue);
|
|
52
51
|
};
|
|
53
|
-
export const validateValue = (value, locale, withFormatting = true
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const inputPrecision = precision !== null && precision !== void 0 ? precision : formattedInputPrecision;
|
|
58
|
-
let cleanValue;
|
|
59
|
-
if (withFormatting) {
|
|
60
|
-
// Use locale-specific parsing when formatting is enabled
|
|
61
|
-
cleanValue = sanitiseInputVal(value, locale);
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
// When formatting is disabled, we need to handle locale-specific separators
|
|
65
|
-
// but still validate the number format
|
|
66
|
-
const { decimalSeparator } = getSeparatorsFromParser(value, locale);
|
|
67
|
-
if (decimalSeparator !== '.') {
|
|
68
|
-
// Convert locale separator to standard decimal point for validation
|
|
69
|
-
const normalizedValue = value.replace(new RegExp(`\\${decimalSeparator}`, 'g'), '.');
|
|
70
|
-
cleanValue = normalizedValue;
|
|
71
|
-
// For withFormatting = false, strip decimal part when using non-standard separator
|
|
72
|
-
const decimalIndex = cleanValue.indexOf('.');
|
|
73
|
-
if (decimalIndex !== -1) {
|
|
74
|
-
cleanValue = cleanValue.substring(0, decimalIndex);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
cleanValue = value;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
// Use regex to validate number format without losing precision
|
|
82
|
-
const numberRegex = /^-?\d*\.?\d+$/;
|
|
83
|
-
if (!numberRegex.test(cleanValue)) {
|
|
84
|
-
return '';
|
|
85
|
-
}
|
|
86
|
-
// Use custom toPrecision implementation to preserve precision without parseFloat
|
|
87
|
-
if (inputPrecision !== undefined) {
|
|
88
|
-
// Count significant digits (both before and after decimal point) like toPrecision() does
|
|
89
|
-
// Convert to string to avoid type issues
|
|
90
|
-
const cleanValueStr = `${cleanValue}`.replace('.', ''); // Remove decimal point to count all digits
|
|
91
|
-
const significantDigits = cleanValueStr.replace(/^0+/, '').length; // Remove leading zeros and count
|
|
92
|
-
if (significantDigits > inputPrecision) {
|
|
93
|
-
// Need to truncate to inputPrecision significant digits
|
|
94
|
-
const decimalIndex = cleanValue.indexOf('.');
|
|
95
|
-
if (decimalIndex !== -1) {
|
|
96
|
-
// Has decimal point
|
|
97
|
-
const integerPart = cleanValue.substring(0, decimalIndex);
|
|
98
|
-
const integerDigits = integerPart.length;
|
|
99
|
-
if (integerDigits >= inputPrecision) {
|
|
100
|
-
// Integer part has enough digits, truncate it
|
|
101
|
-
return cleanValue.substring(0, inputPrecision);
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
// Need some decimal places
|
|
105
|
-
const decimalDigitsNeeded = inputPrecision - integerDigits;
|
|
106
|
-
const decimalPart = cleanValue.substring(decimalIndex + 1);
|
|
107
|
-
const truncatedDecimalPart = decimalPart.substring(0, decimalDigitsNeeded);
|
|
108
|
-
return `${integerPart}.${truncatedDecimalPart}`;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
// No decimal point, just truncate integer part
|
|
113
|
-
return cleanValue.substring(0, inputPrecision);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
52
|
+
export const validateValue = (value, locale, withFormatting = true) => {
|
|
53
|
+
let validValue = parseFloat(parseFloat(withFormatting ? sanitiseInputVal(value, locale) : value).toPrecision(formattedInputPrecision));
|
|
54
|
+
if (isNaN(validValue)) {
|
|
55
|
+
validValue = '';
|
|
116
56
|
}
|
|
117
|
-
return
|
|
57
|
+
return String(validValue);
|
|
118
58
|
};
|
|
119
|
-
export const validateInput = (value, locale
|
|
120
|
-
const parsedValue = validateValue(value, locale
|
|
59
|
+
export const validateInput = (value, locale) => {
|
|
60
|
+
const parsedValue = validateValue(value, locale);
|
|
121
61
|
return preserveTrailingZerosAfterParse(value, parsedValue, locale);
|
|
122
62
|
};
|
|
123
|
-
export const validateMinMax = (value, locale, withFormatting = true, min, max
|
|
124
|
-
let validValue = parseFloat(validateValue(value, locale, withFormatting
|
|
63
|
+
export const validateMinMax = (value, locale, withFormatting = true, min, max) => {
|
|
64
|
+
let validValue = parseFloat(validateValue(value, locale, withFormatting));
|
|
125
65
|
if (isNaN(validValue)) {
|
|
126
66
|
validValue = '';
|
|
127
67
|
}
|
|
@@ -131,194 +71,3 @@ export const validateMinMax = (value, locale, withFormatting = true, min, max, p
|
|
|
131
71
|
}
|
|
132
72
|
return String(validValue);
|
|
133
73
|
};
|
|
134
|
-
/**
|
|
135
|
-
* Performs high precision addition using Pure JavaScript (NO BigInt needed!)
|
|
136
|
-
* This is the BEST solution for precision arithmetic
|
|
137
|
-
* @param a - First number
|
|
138
|
-
* @param b - Second number
|
|
139
|
-
* @returns Sum with maintained precision
|
|
140
|
-
*/
|
|
141
|
-
export const addWithPrecision = (a, b) => {
|
|
142
|
-
try {
|
|
143
|
-
const aStr = a.toString();
|
|
144
|
-
const bStr = b.toString();
|
|
145
|
-
const aDecimalIndex = aStr.indexOf('.');
|
|
146
|
-
const bDecimalIndex = bStr.indexOf('.');
|
|
147
|
-
const aPrecision = aDecimalIndex === -1 ? 0 : aStr.length - aDecimalIndex - 1;
|
|
148
|
-
const bPrecision = bDecimalIndex === -1 ? 0 : bStr.length - bDecimalIndex - 1;
|
|
149
|
-
const maxPrecision = Math.max(aPrecision, bPrecision);
|
|
150
|
-
const multiplier = Math.pow(DECIMAL_BASE, maxPrecision);
|
|
151
|
-
const aInt = Math.round(a * multiplier);
|
|
152
|
-
const bInt = Math.round(b * multiplier);
|
|
153
|
-
const resultInt = aInt + bInt;
|
|
154
|
-
return resultInt / multiplier;
|
|
155
|
-
}
|
|
156
|
-
catch (error) {
|
|
157
|
-
// fallback
|
|
158
|
-
return a + b;
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
/**
|
|
162
|
-
* Performs high precision subtraction using Pure JavaScript
|
|
163
|
-
* @param a - First number
|
|
164
|
-
* @param b - Second number
|
|
165
|
-
* @returns Difference with maintained precision
|
|
166
|
-
*/
|
|
167
|
-
export const subtractWithPrecision = (a, b) => {
|
|
168
|
-
try {
|
|
169
|
-
const aStr = a.toString();
|
|
170
|
-
const bStr = b.toString();
|
|
171
|
-
const aDecimalIndex = aStr.indexOf('.');
|
|
172
|
-
const bDecimalIndex = bStr.indexOf('.');
|
|
173
|
-
const aPrecision = aDecimalIndex === -1 ? 0 : aStr.length - aDecimalIndex - 1;
|
|
174
|
-
const bPrecision = bDecimalIndex === -1 ? 0 : bStr.length - bDecimalIndex - 1;
|
|
175
|
-
const maxPrecision = Math.max(aPrecision, bPrecision);
|
|
176
|
-
const multiplier = Math.pow(DECIMAL_BASE, maxPrecision);
|
|
177
|
-
const aInt = Math.round(a * multiplier);
|
|
178
|
-
const bInt = Math.round(b * multiplier);
|
|
179
|
-
const resultInt = aInt - bInt;
|
|
180
|
-
return resultInt / multiplier;
|
|
181
|
-
}
|
|
182
|
-
catch (error) {
|
|
183
|
-
// fallback
|
|
184
|
-
return a - b;
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
/**
|
|
188
|
-
* Increment a value with precision using direct string manipulation
|
|
189
|
-
* @param valueString - The value as a string to maintain precision
|
|
190
|
-
* @param step - The step value to add
|
|
191
|
-
* @returns The incremented value as a string with preserved precision
|
|
192
|
-
*/
|
|
193
|
-
export const incrementWithPrecision = (valueString, step) => {
|
|
194
|
-
try {
|
|
195
|
-
const valueStr = typeof valueString === 'string' ? valueString : valueString.toString();
|
|
196
|
-
const decimalIndex = valueStr.indexOf('.');
|
|
197
|
-
if (decimalIndex === -1) {
|
|
198
|
-
const value = parseInt(valueStr);
|
|
199
|
-
return (value + step).toString();
|
|
200
|
-
}
|
|
201
|
-
const decimalPart = valueStr.substring(decimalIndex + 1);
|
|
202
|
-
const decimalPlaces = decimalPart.length;
|
|
203
|
-
const lastDigitIndex = decimalPart.length - 1;
|
|
204
|
-
const lastDigit = parseInt(decimalPart.charAt(lastDigitIndex));
|
|
205
|
-
const newLastDigit = lastDigit + 1;
|
|
206
|
-
if (newLastDigit <= 9) {
|
|
207
|
-
const newDecimalPart = decimalPart.substring(0, lastDigitIndex) + newLastDigit;
|
|
208
|
-
return valueStr.substring(0, decimalIndex + 1) + newDecimalPart;
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
let newDecimalPart = '';
|
|
212
|
-
let carry = 1;
|
|
213
|
-
for (let i = lastDigitIndex; i >= 0; i -= 1) {
|
|
214
|
-
const digit = parseInt(decimalPart.charAt(i));
|
|
215
|
-
const newDigit = digit + carry;
|
|
216
|
-
if (newDigit <= 9) {
|
|
217
|
-
newDecimalPart = newDigit + newDecimalPart;
|
|
218
|
-
carry = 0;
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
221
|
-
newDecimalPart = '0' + newDecimalPart;
|
|
222
|
-
carry = 1;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
if (carry === 1) {
|
|
226
|
-
const integerPart = parseInt(valueStr.substring(0, decimalIndex));
|
|
227
|
-
return integerPart + 1 + '.' + newDecimalPart;
|
|
228
|
-
}
|
|
229
|
-
else {
|
|
230
|
-
return valueStr.substring(0, decimalIndex + 1) + newDecimalPart;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
catch (error) {
|
|
235
|
-
const value = typeof valueString === 'string' ? parseFloat(valueString) : valueString;
|
|
236
|
-
return (value + step).toString();
|
|
237
|
-
}
|
|
238
|
-
};
|
|
239
|
-
/**
|
|
240
|
-
* Decrement a value with precision using direct string manipulation
|
|
241
|
-
* @param valueString - The value as a string to maintain precision
|
|
242
|
-
* @param step - The step value to subtract
|
|
243
|
-
* @returns The decremented value as a string with preserved precision
|
|
244
|
-
*/
|
|
245
|
-
export const decrementWithPrecision = (valueString, step) => {
|
|
246
|
-
try {
|
|
247
|
-
const valueStr = typeof valueString === 'string' ? valueString : valueString.toString();
|
|
248
|
-
const decimalIndex = valueStr.indexOf('.');
|
|
249
|
-
if (decimalIndex === -1) {
|
|
250
|
-
const value = parseInt(valueStr);
|
|
251
|
-
return (value - step).toString();
|
|
252
|
-
}
|
|
253
|
-
const decimalPart = valueStr.substring(decimalIndex + 1);
|
|
254
|
-
const decimalPlaces = decimalPart.length;
|
|
255
|
-
const lastDigitIndex = decimalPart.length - 1;
|
|
256
|
-
const lastDigit = parseInt(decimalPart.charAt(lastDigitIndex));
|
|
257
|
-
const newLastDigit = lastDigit - 1;
|
|
258
|
-
if (newLastDigit >= 0) {
|
|
259
|
-
const newDecimalPart = decimalPart.substring(0, lastDigitIndex) + newLastDigit;
|
|
260
|
-
return valueStr.substring(0, decimalIndex + 1) + newDecimalPart;
|
|
261
|
-
}
|
|
262
|
-
else {
|
|
263
|
-
let newDecimalPart = '';
|
|
264
|
-
let borrow = 1;
|
|
265
|
-
for (let i = lastDigitIndex; i >= 0; i -= 1) {
|
|
266
|
-
const digit = parseInt(decimalPart.charAt(i));
|
|
267
|
-
const newDigit = digit - borrow;
|
|
268
|
-
if (newDigit >= 0) {
|
|
269
|
-
newDecimalPart = newDigit + newDecimalPart;
|
|
270
|
-
borrow = 0;
|
|
271
|
-
}
|
|
272
|
-
else {
|
|
273
|
-
newDecimalPart = '9' + newDecimalPart;
|
|
274
|
-
borrow = 1;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
if (borrow === 1) {
|
|
278
|
-
const integerPart = parseInt(valueStr.substring(0, decimalIndex));
|
|
279
|
-
return integerPart - 1 + '.' + newDecimalPart;
|
|
280
|
-
}
|
|
281
|
-
else {
|
|
282
|
-
return valueStr.substring(0, decimalIndex + 1) + newDecimalPart;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
catch (error) {
|
|
287
|
-
const value = typeof valueString === 'string' ? parseFloat(valueString) : valueString;
|
|
288
|
-
return (value - step).toString();
|
|
289
|
-
}
|
|
290
|
-
};
|
|
291
|
-
/**
|
|
292
|
-
* Calculate auto step precision based on decimal places
|
|
293
|
-
* Maintains original step calculation for compatibility
|
|
294
|
-
* @param value - The value to calculate step precision for
|
|
295
|
-
* @returns The calculated step value
|
|
296
|
-
*/
|
|
297
|
-
export const calculateAutoStepPrecision = (value) => {
|
|
298
|
-
try {
|
|
299
|
-
const valueStr = typeof value === 'string' ? value : value.toString();
|
|
300
|
-
const decimalIndex = valueStr.indexOf('.');
|
|
301
|
-
if (decimalIndex === -1) {
|
|
302
|
-
return 1;
|
|
303
|
-
}
|
|
304
|
-
const decimalPart = valueStr.substring(decimalIndex + 1);
|
|
305
|
-
const decimalPlaces = decimalPart.length;
|
|
306
|
-
if (decimalPlaces === 0) {
|
|
307
|
-
return 1;
|
|
308
|
-
}
|
|
309
|
-
const step = Math.pow(DECIMAL_BASE, -decimalPlaces);
|
|
310
|
-
return parseFloat(step.toFixed(decimalPlaces));
|
|
311
|
-
}
|
|
312
|
-
catch (error) {
|
|
313
|
-
const valueStr = typeof value === 'string' ? value : value.toString();
|
|
314
|
-
const decimalIndex = valueStr.indexOf('.');
|
|
315
|
-
if (decimalIndex === -1)
|
|
316
|
-
return 1;
|
|
317
|
-
const decimalPart = valueStr.substring(decimalIndex + 1);
|
|
318
|
-
const decimalPlaces = decimalPart.length;
|
|
319
|
-
if (decimalPlaces === 0)
|
|
320
|
-
return 1;
|
|
321
|
-
const step = Math.pow(DECIMAL_BASE, -decimalPlaces);
|
|
322
|
-
return parseFloat(step.toFixed(decimalPlaces));
|
|
323
|
-
}
|
|
324
|
-
};
|