matcha-components 20.105.0 → 20.108.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.
@@ -5707,8 +5707,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.0", ngImpor
5707
5707
  type: Injectable
5708
5708
  }] });
5709
5709
 
5710
- // DEBUG: Versão da biblioteca - remover após debug
5711
- console.log('🎯 MATCHA-MASK VERSION: v101 - MASKEXPRESSION FIX - ' + new Date().toISOString());
5710
+ console.log('🎯 MATCHA-MASK VERSION: v102 - ELEMENTREF FIX - ' + new Date().toISOString());
5712
5711
  class MatchaMaskService extends MatchaMaskApplierService {
5713
5712
  constructor() {
5714
5713
  super(...arguments);
@@ -5944,16 +5943,9 @@ class MatchaMaskService extends MatchaMaskApplierService {
5944
5943
  (newInputValue !== this.currentValue && this.writingValue) ||
5945
5944
  (this.previousValue === this.currentValue && justPasted);
5946
5945
  }
5947
- console.log('=== applyMask EMIT CHECK ===');
5948
- console.log('result:', result);
5949
- console.log('previousValue:', this.previousValue);
5950
- console.log('currentValue:', this.currentValue);
5951
- console.log('_emitValue:', this._emitValue);
5952
- console.log('maskExpression:', this.maskExpression);
5953
- console.log('dropSpecialCharacters:', this.dropSpecialCharacters);
5954
5946
  // Propagate the input value back to the Angular model
5955
5947
  // eslint-disable-next-line no-unused-expressions,@typescript-eslint/no-unused-expressions
5956
- this._emitValue ? this.formControlResult(result) : console.log('formControlResult NOT called because _emitValue is false');
5948
+ this._emitValue ? this.formControlResult(result) : '';
5957
5949
  // Handle hidden input and showMaskTyped
5958
5950
  if (!this.showMaskTyped || (this.showMaskTyped && this.hiddenInput)) {
5959
5951
  if (this.hiddenInput) {
@@ -6228,47 +6220,31 @@ class MatchaMaskService extends MatchaMaskApplierService {
6228
6220
  this.maskChanged = false;
6229
6221
  // Para máscaras de separador (currency), fazer conversão direta para número
6230
6222
  if (this.maskExpression.startsWith("separator" /* MaskExpression.SEPARATOR */) && this.dropSpecialCharacters) {
6231
- console.log('=== formControlResult CURRENCY DEBUG ===');
6232
- console.log('maskExpression:', this.maskExpression);
6233
- console.log('dropSpecialCharacters:', this.dropSpecialCharacters);
6234
- console.log('inputValue:', inputValue);
6235
- console.log('prefix:', this.prefix);
6236
- console.log('thousandSeparator:', this.thousandSeparator);
6237
- console.log('decimalMarker:', this.decimalMarker);
6238
6223
  // Remover prefixo e sufixo
6239
6224
  let cleanValue = inputValue;
6240
6225
  if (this.prefix) {
6241
6226
  cleanValue = cleanValue.replace(this.prefix, '');
6242
- console.log('after removePrefix:', cleanValue);
6243
6227
  }
6244
6228
  if (this.suffix) {
6245
6229
  cleanValue = cleanValue.replace(this.suffix, '');
6246
- console.log('after removeSuffix:', cleanValue);
6247
6230
  }
6248
6231
  // Remover separador de milhares
6249
6232
  if (this.thousandSeparator) {
6250
6233
  cleanValue = cleanValue.split(this.thousandSeparator).join('');
6251
- console.log('after removeThousand:', cleanValue);
6252
6234
  }
6253
6235
  // Converter decimal marker para ponto
6254
6236
  const markers = Array.isArray(this.decimalMarker)
6255
6237
  ? this.decimalMarker
6256
6238
  : [this.decimalMarker];
6257
- console.log('markers to replace:', markers);
6258
6239
  for (const marker of markers) {
6259
6240
  if (marker && marker !== '.') {
6260
6241
  cleanValue = cleanValue.replace(marker, '.');
6261
- console.log('after replaceMarker ' + marker + ':', cleanValue);
6262
6242
  }
6263
6243
  }
6264
6244
  // Converter para número
6265
6245
  const numValue = parseFloat(cleanValue);
6266
6246
  const finalValue = isNaN(numValue) ? 0 : numValue;
6267
- console.log('numValue:', numValue, 'type:', typeof numValue);
6268
- console.log('finalValue:', finalValue, 'type:', typeof finalValue);
6269
- console.log('onChange exists:', typeof this.onChange);
6270
6247
  this.onChange(outputTransformFn(finalValue));
6271
- console.log('onChange called with:', finalValue);
6272
6248
  return;
6273
6249
  }
6274
6250
  // Para máscaras de separador, garantir que isNumberValue é true
@@ -6509,6 +6485,7 @@ class MatchaMaskCompatibleDirective {
6509
6485
  this._isComposing = false;
6510
6486
  this._maskService = inject(MatchaMaskService, { self: true });
6511
6487
  this.document = inject(DOCUMENT);
6488
+ this.elementRef = inject(ElementRef);
6512
6489
  this._config = inject(MATCHA_MASK_CONFIG);
6513
6490
  // eslint-disable-next-line @typescript-eslint/no-empty-function
6514
6491
  this.onChange = (_) => { };
@@ -6834,8 +6811,10 @@ class MatchaMaskCompatibleDirective {
6834
6811
  // Implementar lógica de teclado se necessário
6835
6812
  }
6836
6813
  writeValue(value) {
6814
+ console.log('🔵 writeValue chamado - valor:', value, 'tipo:', typeof value);
6837
6815
  // Se já estamos escrevendo, não processar novamente (prevenir loop infinito)
6838
6816
  if (this._maskService.writingValue) {
6817
+ console.log('⚠️ writeValue ABORTADO - writingValue já é true');
6839
6818
  return;
6840
6819
  }
6841
6820
  this._maskService.writingValue = true;
@@ -6847,71 +6826,40 @@ class MatchaMaskCompatibleDirective {
6847
6826
  }
6848
6827
  else if (typeof value === 'number') {
6849
6828
  inputValue = value.toString();
6829
+ console.log('🔢 Número convertido para string:', inputValue);
6850
6830
  }
6851
6831
  else {
6852
6832
  inputValue = String(value);
6853
6833
  }
6854
- // Para máscaras de separador (currency), formatar o valor do backend corretamente
6855
- // Exemplo: backend envia 10.5, devemos exibir "R$ 10,50"
6856
- if (this._mask && this._mask.trim().startsWith('separator.')) {
6857
- const precision = this._maskService.getPrecision(this._mask);
6834
+ // Para máscaras de separador, converter ponto para vírgula antes de processar
6835
+ // Isso permite que valores do backend (ex: 10.5) sejam formatados corretamente
6836
+ if (this._mask && this._mask.trim().startsWith('separator.') && inputValue.includes('.')) {
6858
6837
  const decimalMarker = this._maskService.decimalMarker;
6859
6838
  const actualDecimalMarker = decimalMarker === ',' ||
6860
6839
  (Array.isArray(decimalMarker) && decimalMarker.includes(',')) ? ',' : '.';
6861
- // Se o valor tem ponto decimal (formato backend), converter para formato de exibição
6862
- if (inputValue.includes('.')) {
6863
- // Separar parte inteira e decimal
6864
- const parts = inputValue.split('.');
6865
- const integerPart = parts[0] || '0';
6866
- let decimalPart = parts[1] || '';
6867
- // Ajustar casas decimais conforme precisão
6868
- if (precision > 0) {
6869
- decimalPart = decimalPart.padEnd(precision, '0').substring(0, precision);
6870
- }
6871
- // Aplicar separador de milhares na parte inteira
6872
- let formattedInteger = integerPart;
6873
- const rgx = /(\d+)(\d{3})/;
6874
- while (this._maskService.thousandSeparator && rgx.test(formattedInteger)) {
6875
- formattedInteger = formattedInteger.replace(rgx, '$1' + this._maskService.thousandSeparator + '$2');
6876
- }
6877
- // Montar valor formatado
6878
- inputValue = precision > 0
6879
- ? formattedInteger + actualDecimalMarker + decimalPart
6880
- : formattedInteger;
6881
- }
6882
- else if (!inputValue.includes(actualDecimalMarker) && precision > 0) {
6883
- // Valor sem casas decimais (ex: "10"), adicionar zeros
6884
- let formattedInteger = inputValue;
6885
- const rgx = /(\d+)(\d{3})/;
6886
- while (this._maskService.thousandSeparator && rgx.test(formattedInteger)) {
6887
- formattedInteger = formattedInteger.replace(rgx, '$1' + this._maskService.thousandSeparator + '$2');
6888
- }
6889
- inputValue = formattedInteger + actualDecimalMarker + '0'.repeat(precision);
6890
- }
6891
- // Adicionar prefixo se configurado
6892
- if (this._maskService.prefix && !inputValue.startsWith(this._maskService.prefix)) {
6893
- inputValue = this._maskService.prefix + inputValue;
6894
- }
6895
- // Adicionar sufixo se configurado
6896
- if (this._maskService.suffix && !inputValue.endsWith(this._maskService.suffix)) {
6897
- inputValue = inputValue + this._maskService.suffix;
6840
+ if (actualDecimalMarker === ',') {
6841
+ // Converter ponto para vírgula para que applyMask processe corretamente
6842
+ inputValue = inputValue.replace('.', ',');
6843
+ console.log('🔄 Converteu ponto para vírgula:', inputValue);
6898
6844
  }
6899
- this._inputValue = inputValue;
6900
- this._maskService.currentValue = inputValue;
6901
- this._maskService.previousValue = inputValue;
6902
- this._maskService.writingValue = false;
6903
- return;
6904
6845
  }
6905
6846
  this._inputValue = inputValue;
6906
6847
  // Aplicar máscara se definida
6907
- // O applyMask formata o valor para exibição E chama formControlResult
6908
- // que envia o valor limpo (número) para o FormControl via onChange
6909
6848
  if (this._mask && this._mask.trim() !== '') {
6910
- this._maskService.applyMask(inputValue, this._mask);
6911
- // NÃO chamar onChange aqui - formControlResult já fez isso com o valor limpo
6849
+ console.log('📝 Chamando applyMask com:', inputValue);
6850
+ const maskedValue = this._maskService.applyMask(inputValue, this._mask);
6851
+ console.log('📝 applyMask retornou:', maskedValue);
6852
+ // Atualizar o valor do elemento HTML diretamente usando ElementRef
6853
+ if (this.elementRef && this.elementRef.nativeElement) {
6854
+ this.elementRef.nativeElement.value = maskedValue;
6855
+ console.log('✅ Elemento HTML atualizado com:', maskedValue);
6856
+ }
6857
+ else {
6858
+ console.log('⚠️ ElementRef não disponível');
6859
+ }
6912
6860
  }
6913
- // Sem máscara, não precisa fazer nada - o valor já está no FormControl
6914
6861
  this._maskService.writingValue = false;
6862
+ console.log('✅ writeValue CONCLUÍDO');
6915
6863
  }
6916
6864
  registerOnChange(fn) {
6917
6865
  this.onChange = fn;