matcha-components 20.97.0 → 20.99.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.
@@ -5940,12 +5940,6 @@ class MatchaMaskService extends MatchaMaskApplierService {
5940
5940
  (newInputValue !== this.currentValue && this.writingValue) ||
5941
5941
  (this.previousValue === this.currentValue && justPasted);
5942
5942
  }
5943
- // DEBUG: Verificar se formControlResult está sendo chamado
5944
- console.log('=== applyMask DEBUG ===');
5945
- console.log('result:', result);
5946
- console.log('_emitValue:', this._emitValue);
5947
- console.log('previousValue:', this.previousValue);
5948
- console.log('currentValue:', this.currentValue);
5949
5943
  // Propagate the input value back to the Angular model
5950
5944
  // eslint-disable-next-line no-unused-expressions,@typescript-eslint/no-unused-expressions
5951
5945
  this._emitValue ? this.formControlResult(result) : '';
@@ -6226,35 +6220,15 @@ class MatchaMaskService extends MatchaMaskApplierService {
6226
6220
  if (this.maskExpression.startsWith("separator" /* MaskExpression.SEPARATOR */)) {
6227
6221
  this.isNumberValue = true;
6228
6222
  }
6229
- console.log('=== formControlResult DEBUG ===');
6230
- console.log('inputValue:', inputValue);
6231
- console.log('isNumberValue:', this.isNumberValue);
6232
- console.log('dropSpecialCharacters:', this.dropSpecialCharacters);
6233
6223
  if (Array.isArray(this.dropSpecialCharacters)) {
6234
- const afterPrefix = this._removePrefix(inputValue);
6235
- const afterSuffix = this._removeSuffix(afterPrefix);
6236
- const afterMask = this._removeMask(afterSuffix, this.dropSpecialCharacters);
6237
- const afterSymbols = this._checkSymbols(afterMask);
6238
- const afterNumber = this._toNumber(afterSymbols);
6239
- const finalValue = outputTransformFn(afterNumber);
6240
- console.log('Array: afterPrefix:', afterPrefix, 'afterSuffix:', afterSuffix, 'afterMask:', afterMask, 'afterSymbols:', afterSymbols, 'afterNumber:', afterNumber, 'final:', finalValue, 'type:', typeof finalValue);
6241
- this.onChange(finalValue);
6224
+ this.onChange(outputTransformFn(this._toNumber(this._checkSymbols(this._removeMask(this._removeSuffix(this._removePrefix(inputValue)), this.dropSpecialCharacters)))));
6242
6225
  }
6243
6226
  else if (this.dropSpecialCharacters ||
6244
6227
  (!this.dropSpecialCharacters && this.prefix === inputValue)) {
6245
- const afterPrefix = this._removePrefix(inputValue);
6246
- const afterSuffix = this._removeSuffix(afterPrefix);
6247
- const afterSymbols = this._checkSymbols(afterSuffix);
6248
- const afterNumber = this._toNumber(afterSymbols);
6249
- const finalValue = outputTransformFn(afterNumber);
6250
- console.log('Boolean: afterPrefix:', afterPrefix, 'afterSuffix:', afterSuffix, 'afterSymbols:', afterSymbols, 'afterNumber:', afterNumber, 'final:', finalValue, 'type:', typeof finalValue);
6251
- this.onChange(finalValue);
6228
+ this.onChange(outputTransformFn(this._toNumber(this._checkSymbols(this._removeSuffix(this._removePrefix(inputValue))))));
6252
6229
  }
6253
6230
  else {
6254
- const afterNumber = this._toNumber(inputValue);
6255
- const finalValue = outputTransformFn(afterNumber);
6256
- console.log('Else: afterNumber:', afterNumber, 'final:', finalValue);
6257
- this.onChange(finalValue);
6231
+ this.onChange(outputTransformFn(this._toNumber(inputValue)));
6258
6232
  }
6259
6233
  }
6260
6234
  _toNumber(value) {
@@ -6332,6 +6306,25 @@ class MatchaMaskService extends MatchaMaskApplierService {
6332
6306
  this.decimalMarker === "," /* MaskExpression.COMMA */) {
6333
6307
  processedResult = processedResult.replace("," /* MaskExpression.COMMA */, "." /* MaskExpression.DOT */);
6334
6308
  }
6309
+ // Para máscaras de separador (currency), processar de forma especial
6310
+ // Remover separador de milhares e converter decimal marker para ponto
6311
+ if (this.maskExpression.startsWith("separator" /* MaskExpression.SEPARATOR */)) {
6312
+ let cleanValue = processedResult;
6313
+ // Remover separador de milhares
6314
+ if (this.thousandSeparator) {
6315
+ cleanValue = cleanValue.split(this.thousandSeparator).join('');
6316
+ }
6317
+ // Converter decimal marker para ponto
6318
+ const markers = Array.isArray(this.decimalMarker)
6319
+ ? this.decimalMarker
6320
+ : [this.decimalMarker];
6321
+ for (const marker of markers) {
6322
+ if (marker && marker !== '.') {
6323
+ cleanValue = cleanValue.replace(marker, '.');
6324
+ }
6325
+ }
6326
+ return cleanValue;
6327
+ }
6335
6328
  const separatorPrecision = this._retrieveSeparatorPrecision(this.maskExpression);
6336
6329
  const separatorValue = this.specialCharacters.length === 0
6337
6330
  ? this._retrieveSeparatorValue(processedResult)
@@ -6802,14 +6795,56 @@ class MatchaMaskCompatibleDirective {
6802
6795
  else {
6803
6796
  inputValue = String(value);
6804
6797
  }
6805
- // Se a máscara usa separator e o valor tem ponto decimal, converter para vírgula
6806
- // Isso é útil quando valores numéricos vêm do backend (ex: 10.5 -> 10,50)
6807
- if (this._mask && this._mask.trim().startsWith('separator.') && inputValue.includes('.')) {
6808
- // Converter ponto para vírgula se o decimalMarker é vírgula
6798
+ // Para máscaras de separador (currency), formatar o valor do backend corretamente
6799
+ // Exemplo: backend envia 10.5, devemos exibir "R$ 10,50"
6800
+ if (this._mask && this._mask.trim().startsWith('separator.')) {
6801
+ const precision = this._maskService.getPrecision(this._mask);
6809
6802
  const decimalMarker = this._maskService.decimalMarker;
6810
- if (decimalMarker === ',' || (Array.isArray(decimalMarker) && decimalMarker.includes(','))) {
6811
- inputValue = inputValue.replace('.', ',');
6803
+ const actualDecimalMarker = decimalMarker === ',' ||
6804
+ (Array.isArray(decimalMarker) && decimalMarker.includes(',')) ? ',' : '.';
6805
+ // Se o valor tem ponto decimal (formato backend), converter para formato de exibição
6806
+ if (inputValue.includes('.')) {
6807
+ // Separar parte inteira e decimal
6808
+ const parts = inputValue.split('.');
6809
+ const integerPart = parts[0] || '0';
6810
+ let decimalPart = parts[1] || '';
6811
+ // Ajustar casas decimais conforme precisão
6812
+ if (precision > 0) {
6813
+ decimalPart = decimalPart.padEnd(precision, '0').substring(0, precision);
6814
+ }
6815
+ // Aplicar separador de milhares na parte inteira
6816
+ let formattedInteger = integerPart;
6817
+ const rgx = /(\d+)(\d{3})/;
6818
+ while (this._maskService.thousandSeparator && rgx.test(formattedInteger)) {
6819
+ formattedInteger = formattedInteger.replace(rgx, '$1' + this._maskService.thousandSeparator + '$2');
6820
+ }
6821
+ // Montar valor formatado
6822
+ inputValue = precision > 0
6823
+ ? formattedInteger + actualDecimalMarker + decimalPart
6824
+ : formattedInteger;
6825
+ }
6826
+ else if (!inputValue.includes(actualDecimalMarker) && precision > 0) {
6827
+ // Valor sem casas decimais (ex: "10"), adicionar zeros
6828
+ let formattedInteger = inputValue;
6829
+ const rgx = /(\d+)(\d{3})/;
6830
+ while (this._maskService.thousandSeparator && rgx.test(formattedInteger)) {
6831
+ formattedInteger = formattedInteger.replace(rgx, '$1' + this._maskService.thousandSeparator + '$2');
6832
+ }
6833
+ inputValue = formattedInteger + actualDecimalMarker + '0'.repeat(precision);
6834
+ }
6835
+ // Adicionar prefixo se configurado
6836
+ if (this._maskService.prefix && !inputValue.startsWith(this._maskService.prefix)) {
6837
+ inputValue = this._maskService.prefix + inputValue;
6812
6838
  }
6839
+ // Adicionar sufixo se configurado
6840
+ if (this._maskService.suffix && !inputValue.endsWith(this._maskService.suffix)) {
6841
+ inputValue = inputValue + this._maskService.suffix;
6842
+ }
6843
+ this._inputValue = inputValue;
6844
+ this._maskService.currentValue = inputValue;
6845
+ this._maskService.previousValue = inputValue;
6846
+ this._maskService.writingValue = false;
6847
+ return;
6813
6848
  }
6814
6849
  this._inputValue = inputValue;
6815
6850
  // Aplicar máscara se definida