@telcomdev/ui 0.1.19 → 0.1.21
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.
|
@@ -3562,6 +3562,7 @@ class TdInput {
|
|
|
3562
3562
|
legacyMaxLength = signal(null, /* @ts-ignore */
|
|
3563
3563
|
...(ngDevMode ? [{ debugName: "legacyMaxLength" }] : /* istanbul ignore next */ []));
|
|
3564
3564
|
receivedNullValue = false;
|
|
3565
|
+
decimalMaskDigits = '';
|
|
3565
3566
|
nativeInput;
|
|
3566
3567
|
id = '';
|
|
3567
3568
|
label = 'Campo';
|
|
@@ -3692,21 +3693,31 @@ class TdInput {
|
|
|
3692
3693
|
return this.hasSupportingContent() ? `${this.inputId}-description` : null;
|
|
3693
3694
|
}
|
|
3694
3695
|
get resolvedType() {
|
|
3696
|
+
if (this.isDecimalMask())
|
|
3697
|
+
return 'text';
|
|
3695
3698
|
return this.type === 'password' && this.passwordVisible ? 'text' : this.type;
|
|
3696
3699
|
}
|
|
3697
3700
|
onChange = () => undefined;
|
|
3698
3701
|
writeValue(value) {
|
|
3699
3702
|
if (value === null || value === undefined) {
|
|
3700
3703
|
this.receivedNullValue = true;
|
|
3704
|
+
this.decimalMaskDigits = '';
|
|
3701
3705
|
this.value.set(null);
|
|
3702
3706
|
}
|
|
3703
3707
|
else if (this.type === 'number' &&
|
|
3704
3708
|
this.formBridge.usesSignalForms &&
|
|
3705
3709
|
typeof value === 'number') {
|
|
3710
|
+
this.decimalMaskDigits = this.isDecimalMask()
|
|
3711
|
+
? this.decimalDigitsFromProgrammaticValue(String(value))
|
|
3712
|
+
: '';
|
|
3706
3713
|
this.value.set(value);
|
|
3707
3714
|
}
|
|
3708
3715
|
else {
|
|
3709
|
-
|
|
3716
|
+
const textValue = String(value);
|
|
3717
|
+
if (this.isDecimalMask()) {
|
|
3718
|
+
this.decimalMaskDigits = this.decimalDigitsFromProgrammaticValue(textValue);
|
|
3719
|
+
}
|
|
3720
|
+
this.value.set(this.transformTextValue(textValue));
|
|
3710
3721
|
}
|
|
3711
3722
|
this.cdr.markForCheck();
|
|
3712
3723
|
}
|
|
@@ -3724,6 +3735,10 @@ class TdInput {
|
|
|
3724
3735
|
}
|
|
3725
3736
|
handleInput(event) {
|
|
3726
3737
|
const inputElement = event.target;
|
|
3738
|
+
if (this.isDecimalMask()) {
|
|
3739
|
+
this.handleDecimalMaskInput(inputElement, event);
|
|
3740
|
+
return;
|
|
3741
|
+
}
|
|
3727
3742
|
const transformedValue = this.transformTextValue(inputElement.value);
|
|
3728
3743
|
if (inputElement.value !== transformedValue) {
|
|
3729
3744
|
inputElement.value = transformedValue;
|
|
@@ -3739,13 +3754,14 @@ class TdInput {
|
|
|
3739
3754
|
this.formBridge.markTouched(this.touched, this.touch);
|
|
3740
3755
|
}
|
|
3741
3756
|
clear() {
|
|
3757
|
+
this.decimalMaskDigits = '';
|
|
3742
3758
|
this.setValue(this.resolveEmptyValue());
|
|
3743
3759
|
}
|
|
3744
3760
|
parseInputValue(value, inputElement) {
|
|
3745
3761
|
if (!value) {
|
|
3746
3762
|
return this.resolveEmptyValue();
|
|
3747
3763
|
}
|
|
3748
|
-
if (this.type !== 'number' || !this.formBridge.usesSignalForms) {
|
|
3764
|
+
if (this.isDecimalMask() || this.type !== 'number' || !this.formBridge.usesSignalForms) {
|
|
3749
3765
|
return value;
|
|
3750
3766
|
}
|
|
3751
3767
|
const numericValue = inputElement.valueAsNumber;
|
|
@@ -3820,13 +3836,32 @@ class TdInput {
|
|
|
3820
3836
|
return value;
|
|
3821
3837
|
}
|
|
3822
3838
|
maskDecimal(value) {
|
|
3839
|
+
return this.formatDecimalMaskDigits(value.replace(/\D/g, ''));
|
|
3840
|
+
}
|
|
3841
|
+
handleDecimalMaskInput(inputElement, event) {
|
|
3842
|
+
const inputEvent = event;
|
|
3843
|
+
const inputType = inputEvent.inputType || '';
|
|
3844
|
+
const dataDigits = (inputEvent.data ?? '').replace(/\D/g, '');
|
|
3845
|
+
const maxDigits = this.maxDecimalMaskDigits();
|
|
3846
|
+
if (inputType.startsWith('delete')) {
|
|
3847
|
+
this.decimalMaskDigits = this.decimalMaskDigits.slice(0, -1);
|
|
3848
|
+
}
|
|
3849
|
+
else if (dataDigits) {
|
|
3850
|
+
this.decimalMaskDigits = this.limitDigits(this.decimalMaskDigits + dataDigits, maxDigits);
|
|
3851
|
+
}
|
|
3852
|
+
else {
|
|
3853
|
+
this.decimalMaskDigits = this.limitDigits(this.decimalDigitsFromEditedValue(inputElement.value), maxDigits);
|
|
3854
|
+
}
|
|
3855
|
+
const transformedValue = this.formatDecimalMaskDigits(this.decimalMaskDigits);
|
|
3856
|
+
inputElement.value = transformedValue;
|
|
3857
|
+
this.moveCaretToEnd(inputElement);
|
|
3858
|
+
this.setValue(this.parseInputValue(transformedValue, inputElement));
|
|
3859
|
+
}
|
|
3860
|
+
formatDecimalMaskDigits(digitsValue) {
|
|
3823
3861
|
const config = this.resolveDecimalMaskConfig();
|
|
3824
3862
|
const scale = config.decimalDigits;
|
|
3825
3863
|
const integerLimit = config.integerDigits;
|
|
3826
|
-
const
|
|
3827
|
-
? integerLimit + scale
|
|
3828
|
-
: null;
|
|
3829
|
-
const digits = this.limitDigits(value.replace(/\D/g, ''), maxDigits);
|
|
3864
|
+
const digits = this.limitDigits(digitsValue.replace(/\D/g, ''), this.maxDecimalMaskDigits());
|
|
3830
3865
|
if (!digits)
|
|
3831
3866
|
return '';
|
|
3832
3867
|
if (scale === 0)
|
|
@@ -3837,6 +3872,29 @@ class TdInput {
|
|
|
3837
3872
|
const decimalPart = padded.slice(splitIndex);
|
|
3838
3873
|
return `${integerPart || '0'}.${decimalPart}`;
|
|
3839
3874
|
}
|
|
3875
|
+
maxDecimalMaskDigits() {
|
|
3876
|
+
const config = this.resolveDecimalMaskConfig();
|
|
3877
|
+
const scale = config.decimalDigits;
|
|
3878
|
+
const integerLimit = config.integerDigits;
|
|
3879
|
+
return integerLimit && integerLimit > 0 ? integerLimit + scale : null;
|
|
3880
|
+
}
|
|
3881
|
+
decimalDigitsFromEditedValue(value) {
|
|
3882
|
+
return value.replace(/\D/g, '').replace(/^0+(?=\d)/, '');
|
|
3883
|
+
}
|
|
3884
|
+
decimalDigitsFromProgrammaticValue(value) {
|
|
3885
|
+
return this.decimalDigitsFromEditedValue(value);
|
|
3886
|
+
}
|
|
3887
|
+
moveCaretToEnd(inputElement) {
|
|
3888
|
+
queueMicrotask(() => {
|
|
3889
|
+
const end = inputElement.value.length;
|
|
3890
|
+
try {
|
|
3891
|
+
inputElement.setSelectionRange(end, end);
|
|
3892
|
+
}
|
|
3893
|
+
catch {
|
|
3894
|
+
// type="number" no soporta setSelectionRange en algunos navegadores.
|
|
3895
|
+
}
|
|
3896
|
+
});
|
|
3897
|
+
}
|
|
3840
3898
|
isDecimalMask() {
|
|
3841
3899
|
return this.mask === 'decimal' || this.mask.startsWith('decimal(');
|
|
3842
3900
|
}
|