ngx-vector-components 3.4.0 → 3.4.1

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.
@@ -26,7 +26,7 @@ import { FileUploadModule } from 'primeng/fileupload';
26
26
  import * as i2$5 from 'primeng/inputmask';
27
27
  import { InputMaskModule } from 'primeng/inputmask';
28
28
  import * as i1$5 from 'primeng/inputnumber';
29
- import { InputNumberModule } from 'primeng/inputnumber';
29
+ import { InputNumber, InputNumberModule } from 'primeng/inputnumber';
30
30
  import * as i6 from 'primeng/inputtext';
31
31
  import { InputTextModule } from 'primeng/inputtext';
32
32
  import * as i2$7 from 'primeng/inputtextarea';
@@ -1562,25 +1562,12 @@ class CurrencyFieldComponent {
1562
1562
  this.rounded = false;
1563
1563
  this.isBankingField = false;
1564
1564
  this.inputClassName = '';
1565
- this.lastInvertedIndexTyped = 0;
1566
- this.subscription = new Subscription();
1567
1565
  }
1568
- set control(_control) {
1569
- this._control = _control;
1570
- if (this.control.value) {
1571
- this.lastInvertedIndexTyped = `${this.control.value}`.length;
1572
- }
1573
- this.subscription.add(this.control.valueChanges.subscribe((value) => {
1574
- if (value) {
1575
- this.lastInvertedIndexTyped = `${value}`.length;
1576
- }
1577
- }));
1578
- }
1579
- get control() {
1580
- return this._control;
1581
- }
1582
- ngOnDestroy() {
1583
- this.subscription.unsubscribe();
1566
+ ngAfterViewInit() {
1567
+ const inputElement = this.inputElement?.el.nativeElement.querySelector('input');
1568
+ inputElement.addEventListener('select', () => {
1569
+ inputElement.selectionStart = inputElement.selectionEnd;
1570
+ }, false);
1584
1571
  }
1585
1572
  getInputNgClass() {
1586
1573
  return { outlined: this.outlined, rounded: this.rounded, [this.inputClassName]: !!this.inputClassName };
@@ -1591,61 +1578,30 @@ class CurrencyFieldComponent {
1591
1578
  target?.setSelectionRange(selectionIndex, selectionIndex);
1592
1579
  }
1593
1580
  inputNextChar($event) {
1594
- this.focusLastIndex($event);
1595
1581
  const target = $event.target;
1582
+ const valueTyped = $event.key;
1583
+ let newValue = target.value.replace('R$ ', '').replace(/[\.,]/g, '');
1596
1584
  const isDeleteOrBackspace = ['Delete', 'Backspace'].includes($event.key);
1597
1585
  if (isDeleteOrBackspace) {
1598
- this.lastInvertedIndexTyped--;
1599
- target.value = target.value.substr(0, target.value.length - 1);
1600
- if (target.value === '') {
1601
- this.lastInvertedIndexTyped = 0;
1602
- target.value = '0,00';
1603
- return;
1604
- }
1605
- }
1606
- let valueTyped = $event.key;
1607
- if (!isNaN(+valueTyped) || isDeleteOrBackspace) {
1608
- if (target.value === '0,00' && +valueTyped === 0) {
1609
- return;
1610
- }
1611
- if (isDeleteOrBackspace) {
1612
- valueTyped = '';
1613
- }
1614
- let i = 0;
1615
- const reversedPreviousValue = StringUtil.revertString(target.value.replace(/[^0-9]/g, ''));
1616
- const newValue = StringUtil.revertString(StringUtil.revertString(this.lastInvertedIndexTyped >= 3 ? `${target.value}${valueTyped}`.replace(/[0-9]/g, '#') : '#,##').replace(/#/g, () => {
1617
- let returnValue = '0';
1618
- if (isDeleteOrBackspace) {
1619
- returnValue = reversedPreviousValue[i];
1620
- }
1621
- else {
1622
- if (i === 0) {
1623
- returnValue = `${valueTyped}`;
1624
- }
1625
- else {
1626
- returnValue = reversedPreviousValue[i - 1] || '0';
1627
- }
1628
- }
1629
- i++;
1630
- return returnValue;
1631
- }));
1632
- const newValueOnlyNumbers = newValue.replace(/[^0-9]/g, '');
1633
- target.value = Number(`${newValueOnlyNumbers.substring(0, newValueOnlyNumbers.length - 2)}.${newValueOnlyNumbers.substr(newValueOnlyNumbers.length - 2)}`).toLocaleString('pt-BR', {
1634
- currency: 'BRL',
1635
- minimumFractionDigits: 2,
1636
- maximumFractionDigits: 2,
1637
- });
1638
- if (!isNaN(+valueTyped)) {
1639
- this.lastInvertedIndexTyped++;
1640
- }
1586
+ newValue = newValue.substring(0, newValue.length - 1).padStart(3, '0');
1641
1587
  }
1588
+ else if (!isNaN(+valueTyped)) {
1589
+ newValue += valueTyped;
1590
+ newValue = `${+newValue}`.padStart(3, '0');
1591
+ }
1592
+ target.value = `R$ ${Number(`${newValue.substring(0, newValue.length - 2)}.${newValue.substring(newValue.length - 2, newValue.length)}`).toLocaleString('pt-BR', {
1593
+ currency: 'BRL',
1594
+ minimumFractionDigits: 2,
1595
+ maximumFractionDigits: 2,
1596
+ })}`;
1597
+ this.focusLastIndex($event);
1642
1598
  }
1643
1599
  clearValue() {
1644
1600
  this.control.setValue(0);
1645
1601
  }
1646
1602
  }
1647
1603
  CurrencyFieldComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.3", ngImport: i0, type: CurrencyFieldComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
1648
- CurrencyFieldComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.1.3", type: CurrencyFieldComponent, selector: "vector-currency-field", inputs: { minValue: "minValue", maxValue: "maxValue", placeholder: "placeholder", control: "control", outlined: "outlined", rounded: "rounded", label: "label", isBankingField: "isBankingField", inputClassName: "inputClassName" }, ngImport: i0, template: "<div [ngClass]=\"{ 'input-container': outlined, 'value-input-container': !outlined, rounded: rounded }\">\r\n <div class=\"inner-container\">\r\n <label *ngIf=\"label\">{{ label }}</label>\r\n <div class=\"input\">\r\n <span *ngIf=\"!outlined\">R$ </span>\r\n <div class=\"value-input\">\r\n <p-inputNumber\r\n class=\"currency-input\"\r\n [ngClass]=\"getInputNgClass()\"\r\n [formControl]=\"control\"\r\n mode=\"decimal\"\r\n [minFractionDigits]=\"2\"\r\n [maxFractionDigits]=\"2\"\r\n [min]=\"minValue\"\r\n [max]=\"maxValue\"\r\n [prefix]=\"outlined ? 'R$ ' : ''\"\r\n (click)=\"isBankingField ? focusLastIndex($event) : null\"\r\n (onKeyDown)=\"isBankingField ? inputNextChar($event) : null\"\r\n ></p-inputNumber>\r\n </div>\r\n </div>\r\n </div>\r\n <span *ngIf=\"rounded\" class=\"clear-value\" (click)=\"clearValue()\"><i class=\"pi pi-times\"></i></span>\r\n</div>\r\n", styles: [".value-input-container{padding:5px 20px;display:flex;align-items:center;justify-content:space-between}.value-input-container:focus-within{border:2px solid var(--theme-dark)}.value-input-container:not(.rounded) span{font-size:2em}.value-input-container label{color:var(--gray-dark);font-size:13px}.value-input-container span{font-weight:700;color:var(--theme-dark)}.value-input-container .input{display:flex;align-items:center}.value-input-container .input .value-input{margin:0 4px;flex:1}.rounded:not(.currency-input){padding:0 25px;background-color:#fff;border-radius:16px}.rounded span{font-size:1em}.rounded input{font-size:1rem}.rounded .clear-value{padding:5px 5px 0;border-radius:20px}.rounded .clear-value:hover{background-color:var(--gray-medium)}\n"], components: [{ type: i1$5.InputNumber, selector: "p-inputNumber", inputs: ["showButtons", "format", "buttonLayout", "inputId", "styleClass", "style", "placeholder", "size", "maxlength", "tabindex", "title", "ariaLabel", "ariaRequired", "name", "required", "autocomplete", "min", "max", "incrementButtonClass", "decrementButtonClass", "incrementButtonIcon", "decrementButtonIcon", "readonly", "step", "allowEmpty", "locale", "localeMatcher", "mode", "currency", "currencyDisplay", "useGrouping", "minFractionDigits", "maxFractionDigits", "prefix", "suffix", "inputStyle", "inputStyleClass", "disabled"], outputs: ["onInput", "onFocus", "onBlur", "onKeyDown"] }], directives: [{ type: i2.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i2$4.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { type: i2$4.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }] });
1604
+ CurrencyFieldComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.1.3", type: CurrencyFieldComponent, selector: "vector-currency-field", inputs: { minValue: "minValue", maxValue: "maxValue", placeholder: "placeholder", control: "control", outlined: "outlined", rounded: "rounded", label: "label", isBankingField: "isBankingField", inputClassName: "inputClassName" }, viewQueries: [{ propertyName: "inputElement", first: true, predicate: InputNumber, descendants: true }], ngImport: i0, template: "<div [ngClass]=\"{ 'input-container': outlined, 'value-input-container': !outlined, rounded: rounded }\">\r\n <div class=\"inner-container\">\r\n <label *ngIf=\"label\">{{ label }}</label>\r\n <div class=\"input\">\r\n <span *ngIf=\"!outlined\">R$ </span>\r\n <div class=\"value-input\">\r\n <p-inputNumber\r\n class=\"currency-input\"\r\n [ngClass]=\"getInputNgClass()\"\r\n [formControl]=\"control\"\r\n mode=\"decimal\"\r\n [minFractionDigits]=\"2\"\r\n [maxFractionDigits]=\"2\"\r\n [min]=\"minValue\"\r\n [max]=\"maxValue\"\r\n [prefix]=\"outlined ? 'R$ ' : ''\"\r\n (click)=\"isBankingField ? focusLastIndex($event) : null\"\r\n (onKeyDown)=\"isBankingField ? inputNextChar($event) : null\"\r\n ></p-inputNumber>\r\n </div>\r\n </div>\r\n </div>\r\n <span *ngIf=\"rounded\" class=\"clear-value\" (click)=\"clearValue()\"><i class=\"pi pi-times\"></i></span>\r\n</div>\r\n", styles: [".value-input-container{padding:5px 20px;display:flex;align-items:center;justify-content:space-between}.value-input-container:focus-within{border:2px solid var(--theme-dark)}.value-input-container:not(.rounded) span{font-size:2em}.value-input-container label{color:var(--gray-dark);font-size:13px}.value-input-container span{font-weight:700;color:var(--theme-dark)}.value-input-container .input{display:flex;align-items:center}.value-input-container .input .value-input{margin:0 4px;flex:1}.rounded:not(.currency-input){padding:0 25px;background-color:#fff;border-radius:16px}.rounded span{font-size:1em}.rounded input{font-size:1rem}.rounded .clear-value{padding:5px 5px 0;border-radius:20px}.rounded .clear-value:hover{background-color:var(--gray-medium)}\n"], components: [{ type: i1$5.InputNumber, selector: "p-inputNumber", inputs: ["showButtons", "format", "buttonLayout", "inputId", "styleClass", "style", "placeholder", "size", "maxlength", "tabindex", "title", "ariaLabel", "ariaRequired", "name", "required", "autocomplete", "min", "max", "incrementButtonClass", "decrementButtonClass", "incrementButtonIcon", "decrementButtonIcon", "readonly", "step", "allowEmpty", "locale", "localeMatcher", "mode", "currency", "currencyDisplay", "useGrouping", "minFractionDigits", "maxFractionDigits", "prefix", "suffix", "inputStyle", "inputStyleClass", "disabled"], outputs: ["onInput", "onFocus", "onBlur", "onKeyDown"] }], directives: [{ type: i2.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i2$4.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { type: i2$4.FormControlDirective, selector: "[formControl]", inputs: ["formControl", "disabled", "ngModel"], outputs: ["ngModelChange"], exportAs: ["ngForm"] }] });
1649
1605
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.3", ngImport: i0, type: CurrencyFieldComponent, decorators: [{
1650
1606
  type: Component,
1651
1607
  args: [{ selector: 'vector-currency-field', template: "<div [ngClass]=\"{ 'input-container': outlined, 'value-input-container': !outlined, rounded: rounded }\">\r\n <div class=\"inner-container\">\r\n <label *ngIf=\"label\">{{ label }}</label>\r\n <div class=\"input\">\r\n <span *ngIf=\"!outlined\">R$ </span>\r\n <div class=\"value-input\">\r\n <p-inputNumber\r\n class=\"currency-input\"\r\n [ngClass]=\"getInputNgClass()\"\r\n [formControl]=\"control\"\r\n mode=\"decimal\"\r\n [minFractionDigits]=\"2\"\r\n [maxFractionDigits]=\"2\"\r\n [min]=\"minValue\"\r\n [max]=\"maxValue\"\r\n [prefix]=\"outlined ? 'R$ ' : ''\"\r\n (click)=\"isBankingField ? focusLastIndex($event) : null\"\r\n (onKeyDown)=\"isBankingField ? inputNextChar($event) : null\"\r\n ></p-inputNumber>\r\n </div>\r\n </div>\r\n </div>\r\n <span *ngIf=\"rounded\" class=\"clear-value\" (click)=\"clearValue()\"><i class=\"pi pi-times\"></i></span>\r\n</div>\r\n", styles: [".value-input-container{padding:5px 20px;display:flex;align-items:center;justify-content:space-between}.value-input-container:focus-within{border:2px solid var(--theme-dark)}.value-input-container:not(.rounded) span{font-size:2em}.value-input-container label{color:var(--gray-dark);font-size:13px}.value-input-container span{font-weight:700;color:var(--theme-dark)}.value-input-container .input{display:flex;align-items:center}.value-input-container .input .value-input{margin:0 4px;flex:1}.rounded:not(.currency-input){padding:0 25px;background-color:#fff;border-radius:16px}.rounded span{font-size:1em}.rounded input{font-size:1rem}.rounded .clear-value{padding:5px 5px 0;border-radius:20px}.rounded .clear-value:hover{background-color:var(--gray-medium)}\n"] }]
@@ -1667,6 +1623,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.3", ngImpor
1667
1623
  type: Input
1668
1624
  }], inputClassName: [{
1669
1625
  type: Input
1626
+ }], inputElement: [{
1627
+ type: ViewChild,
1628
+ args: [InputNumber]
1670
1629
  }] } });
1671
1630
 
1672
1631
  class TextFieldComponent {