matcha-components 20.106.0 → 20.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.
|
@@ -5116,7 +5116,12 @@ class MatchaMaskApplierService {
|
|
|
5116
5116
|
}
|
|
5117
5117
|
}
|
|
5118
5118
|
// Modo moeda: dígitos entram pela direita (ex: 1 → 0,01, 12 → 0,12, 123 → 1,23)
|
|
5119
|
-
|
|
5119
|
+
// IMPORTANTE: Só aplicar currencyMode se o valor NÃO tem o decimalMarker
|
|
5120
|
+
// Se já tem o decimalMarker, significa que veio formatado do backend (ex: 10,50)
|
|
5121
|
+
const hasDecimalMarker = typeof decimalMarker === 'string'
|
|
5122
|
+
? processedValue.includes(decimalMarker)
|
|
5123
|
+
: decimalMarker.some((marker) => processedValue.includes(marker));
|
|
5124
|
+
if (this.currencyMode && precision > 0 && !hasDecimalMarker) {
|
|
5120
5125
|
// Extrair apenas dígitos e sinal negativo
|
|
5121
5126
|
const hasMinus = processedValue.startsWith("-" /* MaskExpression.MINUS */) ||
|
|
5122
5127
|
(this.allowNegativeNumbers && processedValue.includes("-" /* MaskExpression.MINUS */));
|
|
@@ -5707,6 +5712,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.0", ngImpor
|
|
|
5707
5712
|
type: Injectable
|
|
5708
5713
|
}] });
|
|
5709
5714
|
|
|
5715
|
+
console.log('🎯 MATCHA-MASK VERSION: v103 - CURRENCYMODE DECIMAL FIX - ' + new Date().toISOString());
|
|
5710
5716
|
class MatchaMaskService extends MatchaMaskApplierService {
|
|
5711
5717
|
constructor() {
|
|
5712
5718
|
super(...arguments);
|
|
@@ -6484,6 +6490,7 @@ class MatchaMaskCompatibleDirective {
|
|
|
6484
6490
|
this._isComposing = false;
|
|
6485
6491
|
this._maskService = inject(MatchaMaskService, { self: true });
|
|
6486
6492
|
this.document = inject(DOCUMENT);
|
|
6493
|
+
this.elementRef = inject(ElementRef);
|
|
6487
6494
|
this._config = inject(MATCHA_MASK_CONFIG);
|
|
6488
6495
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
6489
6496
|
this.onChange = (_) => { };
|
|
@@ -6809,8 +6816,10 @@ class MatchaMaskCompatibleDirective {
|
|
|
6809
6816
|
// Implementar lógica de teclado se necessário
|
|
6810
6817
|
}
|
|
6811
6818
|
writeValue(value) {
|
|
6819
|
+
console.log('🔵 writeValue chamado - valor:', value, 'tipo:', typeof value);
|
|
6812
6820
|
// Se já estamos escrevendo, não processar novamente (prevenir loop infinito)
|
|
6813
6821
|
if (this._maskService.writingValue) {
|
|
6822
|
+
console.log('⚠️ writeValue ABORTADO - writingValue já é true');
|
|
6814
6823
|
return;
|
|
6815
6824
|
}
|
|
6816
6825
|
this._maskService.writingValue = true;
|
|
@@ -6822,71 +6831,40 @@ class MatchaMaskCompatibleDirective {
|
|
|
6822
6831
|
}
|
|
6823
6832
|
else if (typeof value === 'number') {
|
|
6824
6833
|
inputValue = value.toString();
|
|
6834
|
+
console.log('🔢 Número convertido para string:', inputValue);
|
|
6825
6835
|
}
|
|
6826
6836
|
else {
|
|
6827
6837
|
inputValue = String(value);
|
|
6828
6838
|
}
|
|
6829
|
-
// Para máscaras de separador
|
|
6830
|
-
//
|
|
6831
|
-
if (this._mask && this._mask.trim().startsWith('separator.')) {
|
|
6832
|
-
const precision = this._maskService.getPrecision(this._mask);
|
|
6839
|
+
// Para máscaras de separador, converter ponto para vírgula antes de processar
|
|
6840
|
+
// Isso permite que valores do backend (ex: 10.5) sejam formatados corretamente
|
|
6841
|
+
if (this._mask && this._mask.trim().startsWith('separator.') && inputValue.includes('.')) {
|
|
6833
6842
|
const decimalMarker = this._maskService.decimalMarker;
|
|
6834
6843
|
const actualDecimalMarker = decimalMarker === ',' ||
|
|
6835
6844
|
(Array.isArray(decimalMarker) && decimalMarker.includes(',')) ? ',' : '.';
|
|
6836
|
-
|
|
6837
|
-
|
|
6838
|
-
|
|
6839
|
-
|
|
6840
|
-
const integerPart = parts[0] || '0';
|
|
6841
|
-
let decimalPart = parts[1] || '';
|
|
6842
|
-
// Ajustar casas decimais conforme precisão
|
|
6843
|
-
if (precision > 0) {
|
|
6844
|
-
decimalPart = decimalPart.padEnd(precision, '0').substring(0, precision);
|
|
6845
|
-
}
|
|
6846
|
-
// Aplicar separador de milhares na parte inteira
|
|
6847
|
-
let formattedInteger = integerPart;
|
|
6848
|
-
const rgx = /(\d+)(\d{3})/;
|
|
6849
|
-
while (this._maskService.thousandSeparator && rgx.test(formattedInteger)) {
|
|
6850
|
-
formattedInteger = formattedInteger.replace(rgx, '$1' + this._maskService.thousandSeparator + '$2');
|
|
6851
|
-
}
|
|
6852
|
-
// Montar valor formatado
|
|
6853
|
-
inputValue = precision > 0
|
|
6854
|
-
? formattedInteger + actualDecimalMarker + decimalPart
|
|
6855
|
-
: formattedInteger;
|
|
6856
|
-
}
|
|
6857
|
-
else if (!inputValue.includes(actualDecimalMarker) && precision > 0) {
|
|
6858
|
-
// Valor sem casas decimais (ex: "10"), adicionar zeros
|
|
6859
|
-
let formattedInteger = inputValue;
|
|
6860
|
-
const rgx = /(\d+)(\d{3})/;
|
|
6861
|
-
while (this._maskService.thousandSeparator && rgx.test(formattedInteger)) {
|
|
6862
|
-
formattedInteger = formattedInteger.replace(rgx, '$1' + this._maskService.thousandSeparator + '$2');
|
|
6863
|
-
}
|
|
6864
|
-
inputValue = formattedInteger + actualDecimalMarker + '0'.repeat(precision);
|
|
6865
|
-
}
|
|
6866
|
-
// Adicionar prefixo se configurado
|
|
6867
|
-
if (this._maskService.prefix && !inputValue.startsWith(this._maskService.prefix)) {
|
|
6868
|
-
inputValue = this._maskService.prefix + inputValue;
|
|
6869
|
-
}
|
|
6870
|
-
// Adicionar sufixo se configurado
|
|
6871
|
-
if (this._maskService.suffix && !inputValue.endsWith(this._maskService.suffix)) {
|
|
6872
|
-
inputValue = inputValue + this._maskService.suffix;
|
|
6845
|
+
if (actualDecimalMarker === ',') {
|
|
6846
|
+
// Converter ponto para vírgula para que applyMask processe corretamente
|
|
6847
|
+
inputValue = inputValue.replace('.', ',');
|
|
6848
|
+
console.log('🔄 Converteu ponto para vírgula:', inputValue);
|
|
6873
6849
|
}
|
|
6874
|
-
this._inputValue = inputValue;
|
|
6875
|
-
this._maskService.currentValue = inputValue;
|
|
6876
|
-
this._maskService.previousValue = inputValue;
|
|
6877
|
-
this._maskService.writingValue = false;
|
|
6878
|
-
return;
|
|
6879
6850
|
}
|
|
6880
6851
|
this._inputValue = inputValue;
|
|
6881
6852
|
// Aplicar máscara se definida
|
|
6882
|
-
// O applyMask formata o valor para exibição E chama formControlResult
|
|
6883
|
-
// que envia o valor limpo (número) para o FormControl via onChange
|
|
6884
6853
|
if (this._mask && this._mask.trim() !== '') {
|
|
6885
|
-
|
|
6886
|
-
|
|
6854
|
+
console.log('📝 Chamando applyMask com:', inputValue);
|
|
6855
|
+
const maskedValue = this._maskService.applyMask(inputValue, this._mask);
|
|
6856
|
+
console.log('📝 applyMask retornou:', maskedValue);
|
|
6857
|
+
// Atualizar o valor do elemento HTML diretamente usando ElementRef
|
|
6858
|
+
if (this.elementRef && this.elementRef.nativeElement) {
|
|
6859
|
+
this.elementRef.nativeElement.value = maskedValue;
|
|
6860
|
+
console.log('✅ Elemento HTML atualizado com:', maskedValue);
|
|
6861
|
+
}
|
|
6862
|
+
else {
|
|
6863
|
+
console.log('⚠️ ElementRef não disponível');
|
|
6864
|
+
}
|
|
6887
6865
|
}
|
|
6888
|
-
// Sem máscara, não precisa fazer nada - o valor já está no FormControl
|
|
6889
6866
|
this._maskService.writingValue = false;
|
|
6867
|
+
console.log('✅ writeValue CONCLUÍDO');
|
|
6890
6868
|
}
|
|
6891
6869
|
registerOnChange(fn) {
|
|
6892
6870
|
this.onChange = fn;
|