ng-tailwind 6.4.8 → 6.4.9

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.
@@ -102,6 +102,7 @@ export declare class NgtInputComponent extends NgtBaseNgModel implements OnInit,
102
102
  private initComponent;
103
103
  private updateValidations;
104
104
  private setupMasks;
105
+ private setupAlphanumericPasteHandler;
105
106
  private setupProperties;
106
107
  private minValueValidator;
107
108
  private multipleOfValidator;
@@ -2451,6 +2451,7 @@ class NgtInputComponent extends NgtBaseNgModel {
2451
2451
  return this.clearInput();
2452
2452
  }
2453
2453
  const cnpjMaskPattern = 'XX.XXX.XXX/XXXX-99';
2454
+ const onBeforeCnpjPaste = (pastedValue) => pastedValue.toUpperCase().replace(/[^A-Z0-9]/g, '');
2454
2455
  const cnpjMaskParameters = {
2455
2456
  mask: [cnpjMaskPattern],
2456
2457
  definitions: {
@@ -2459,7 +2460,8 @@ class NgtInputComponent extends NgtBaseNgModel {
2459
2460
  casing: 'upper'
2460
2461
  }
2461
2462
  },
2462
- showMaskOnHover: false
2463
+ showMaskOnHover: false,
2464
+ onBeforePaste: onBeforeCnpjPaste
2463
2465
  };
2464
2466
  let masks = {
2465
2467
  [InputMaskEnum.CPF]: {
@@ -2477,15 +2479,15 @@ class NgtInputComponent extends NgtBaseNgModel {
2477
2479
  },
2478
2480
  [InputMaskEnum.CPF_CNPJ_RUT]: {
2479
2481
  mask: ['999.999.999-99', '999999999999', cnpjMaskPattern],
2480
- keepStatic: true,
2481
2482
  definitions: cnpjMaskParameters.definitions,
2482
- showMaskOnHover: false
2483
+ showMaskOnHover: false,
2484
+ onBeforePaste: onBeforeCnpjPaste
2483
2485
  },
2484
2486
  [InputMaskEnum.CPF_CNPJ]: {
2485
2487
  mask: ['999.999.999-99', cnpjMaskPattern],
2486
- keepStatic: true,
2487
2488
  definitions: cnpjMaskParameters.definitions,
2488
- showMaskOnHover: false
2489
+ showMaskOnHover: false,
2490
+ onBeforePaste: onBeforeCnpjPaste
2489
2491
  },
2490
2492
  [InputMaskEnum.DECIMAL]: {
2491
2493
  digits: this.decimalMaskPrecision,
@@ -2537,6 +2539,39 @@ class NgtInputComponent extends NgtBaseNgModel {
2537
2539
  else {
2538
2540
  applyInputMask(this.element.nativeElement, masks[this.mask]);
2539
2541
  }
2542
+ if (this.mask == InputMaskEnum.CPF_CNPJ || this.mask == InputMaskEnum.CPF_CNPJ_RUT) {
2543
+ this.setupAlphanumericPasteHandler();
2544
+ }
2545
+ }
2546
+ setupAlphanumericPasteHandler() {
2547
+ const handler = (event) => {
2548
+ const pastedText = event.clipboardData?.getData('text/plain') ?? '';
2549
+ const normalized = pastedText.toUpperCase().replace(/[^A-Z0-9]/g, '');
2550
+ if (normalized.length !== 14 || !/[A-Z]/.test(normalized)) {
2551
+ return;
2552
+ }
2553
+ event.preventDefault();
2554
+ event.stopImmediatePropagation();
2555
+ const formatted = `${normalized.substring(0, 2)}.${normalized.substring(2, 5)}.${normalized.substring(5, 8)}/${normalized.substring(8, 12)}-${normalized.substring(12, 14)}`;
2556
+ const input = this.element.nativeElement;
2557
+ const inputmaskInstance = input.inputmask;
2558
+ const alphaMaskOptions = {
2559
+ mask: ['XX.XXX.XXX/XXXX-99'],
2560
+ definitions: { X: { validator: '[0-9A-Za-z]', casing: 'upper' } },
2561
+ showMaskOnHover: false
2562
+ };
2563
+ if (inputmaskInstance && typeof inputmaskInstance.option === 'function') {
2564
+ inputmaskInstance.option(alphaMaskOptions);
2565
+ }
2566
+ else {
2567
+ removeInputMask(input);
2568
+ Inputmask(alphaMaskOptions).mask(input);
2569
+ }
2570
+ input.value = formatted;
2571
+ input.dispatchEvent(new Event('input', { bubbles: true }));
2572
+ input.dispatchEvent(new Event('change', { bubbles: true }));
2573
+ };
2574
+ this.element.nativeElement.addEventListener('paste', handler, true);
2540
2575
  }
2541
2576
  setupProperties() {
2542
2577
  let props = {