pjc-fields 0.0.53 → 0.0.55

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.
@@ -1582,7 +1582,9 @@ class PjcEnumFieldComponent {
1582
1582
  readonly = input(false, ...(ngDevMode ? [{ debugName: "readonly" }] : /* istanbul ignore next */ []));
1583
1583
  erros = input({}, ...(ngDevMode ? [{ debugName: "erros" }] : /* istanbul ignore next */ []));
1584
1584
  /** URL of the endpoint that returns the list of items. */
1585
- url = input.required(...(ngDevMode ? [{ debugName: "url" }] : /* istanbul ignore next */ []));
1585
+ url = input('', ...(ngDevMode ? [{ debugName: "url" }] : /* istanbul ignore next */ []));
1586
+ /** Static list of items to display. When provided, takes precedence over `url`. */
1587
+ options = input([], ...(ngDevMode ? [{ debugName: "options" }] : /* istanbul ignore next */ []));
1586
1588
  /**
1587
1589
  * Key of the object property displayed as the option label in the select.
1588
1590
  * Defaults to 'descricao'.
@@ -1628,8 +1630,12 @@ class PjcEnumFieldComponent {
1628
1630
  }
1629
1631
  constructor() {
1630
1632
  effect(() => {
1633
+ const staticOptions = this.options();
1631
1634
  const url = this.url();
1632
- if (url) {
1635
+ if (staticOptions.length > 0) {
1636
+ this.items.set(staticOptions);
1637
+ }
1638
+ else if (url) {
1633
1639
  this.fetchItems(url);
1634
1640
  }
1635
1641
  else {
@@ -1675,7 +1681,7 @@ class PjcEnumFieldComponent {
1675
1681
  });
1676
1682
  }
1677
1683
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: PjcEnumFieldComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
1678
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.4", type: PjcEnumFieldComponent, isStandalone: true, selector: "pjc-enum-field", inputs: { label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, hint: { classPropertyName: "hint", publicName: "hint", isSignal: true, isRequired: false, transformFunction: null }, placeholder: { classPropertyName: "placeholder", publicName: "placeholder", isSignal: true, isRequired: false, transformFunction: null }, id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null }, labelVariant: { classPropertyName: "labelVariant", publicName: "labelVariant", isSignal: true, isRequired: false, transformFunction: null }, readonly: { classPropertyName: "readonly", publicName: "readonly", isSignal: true, isRequired: false, transformFunction: null }, erros: { classPropertyName: "erros", publicName: "erros", isSignal: true, isRequired: false, transformFunction: null }, url: { classPropertyName: "url", publicName: "url", isSignal: true, isRequired: true, transformFunction: null }, optionLabel: { classPropertyName: "optionLabel", publicName: "optionLabel", isSignal: true, isRequired: false, transformFunction: null }, optionValue: { classPropertyName: "optionValue", publicName: "optionValue", isSignal: true, isRequired: false, transformFunction: null }, filter: { classPropertyName: "filter", publicName: "filter", isSignal: true, isRequired: false, transformFunction: null }, showClear: { classPropertyName: "showClear", publicName: "showClear", isSignal: true, isRequired: false, transformFunction: null } }, providers: [
1684
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.4", type: PjcEnumFieldComponent, isStandalone: true, selector: "pjc-enum-field", inputs: { label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, hint: { classPropertyName: "hint", publicName: "hint", isSignal: true, isRequired: false, transformFunction: null }, placeholder: { classPropertyName: "placeholder", publicName: "placeholder", isSignal: true, isRequired: false, transformFunction: null }, id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null }, labelVariant: { classPropertyName: "labelVariant", publicName: "labelVariant", isSignal: true, isRequired: false, transformFunction: null }, readonly: { classPropertyName: "readonly", publicName: "readonly", isSignal: true, isRequired: false, transformFunction: null }, erros: { classPropertyName: "erros", publicName: "erros", isSignal: true, isRequired: false, transformFunction: null }, url: { classPropertyName: "url", publicName: "url", isSignal: true, isRequired: false, transformFunction: null }, options: { classPropertyName: "options", publicName: "options", isSignal: true, isRequired: false, transformFunction: null }, optionLabel: { classPropertyName: "optionLabel", publicName: "optionLabel", isSignal: true, isRequired: false, transformFunction: null }, optionValue: { classPropertyName: "optionValue", publicName: "optionValue", isSignal: true, isRequired: false, transformFunction: null }, filter: { classPropertyName: "filter", publicName: "filter", isSignal: true, isRequired: false, transformFunction: null }, showClear: { classPropertyName: "showClear", publicName: "showClear", isSignal: true, isRequired: false, transformFunction: null } }, providers: [
1679
1685
  {
1680
1686
  provide: NG_VALUE_ACCESSOR,
1681
1687
  useExisting: forwardRef(() => PjcEnumFieldComponent),
@@ -1692,7 +1698,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
1692
1698
  multi: true,
1693
1699
  },
1694
1700
  ], template: "<div class=\"flex flex-col gap-1 w-full\">\n @if (label()) {\n <p-floatlabel [variant]=\"labelVariant()\" class=\"w-full\">\n <p-select\n [inputId]=\"id()\"\n [options]=\"items()\"\n [ngModel]=\"value\"\n (ngModelChange)=\"onModelChange($event)\"\n (onBlur)=\"onModelTouched()\"\n [optionLabel]=\"optionLabel()\"\n [optionValue]=\"optionValue()\"\n appendTo=\"body\"\n [filter]=\"filter()\"\n [filterMatchMode]=\"$any(accentContainsFilter)\"\n [showClear]=\"showClear()\"\n [disabled]=\"disabled || readonly() || loading()\"\n [loading]=\"loading()\"\n styleClass=\"w-full\"\n class=\"w-full\"\n [class.ng-invalid]=\"invalid\"\n [class.ng-dirty]=\"invalid\"\n />\n <label [for]=\"id()\">{{ label() }}</label>\n </p-floatlabel>\n } @else {\n <p-select\n [inputId]=\"id()\"\n [options]=\"items()\"\n [ngModel]=\"value\"\n (ngModelChange)=\"onModelChange($event)\"\n (onBlur)=\"onModelTouched()\"\n [optionLabel]=\"optionLabel()\"\n [optionValue]=\"optionValue()\"\n appendTo=\"body\"\n [filter]=\"filter()\"\n [showClear]=\"showClear()\"\n [placeholder]=\"placeholder()\"\n [disabled]=\"disabled || readonly() || loading()\"\n [loading]=\"loading()\"\n styleClass=\"w-full\"\n class=\"w-full\"\n [class.ng-invalid]=\"invalid\"\n [class.ng-dirty]=\"invalid\"\n />\n }\n\n @if (hint()) {\n <small class=\"text-xs text-surface-500\">{{ hint() }}</small>\n }\n\n @if (errorMessage) {\n <p-message severity=\"error\" variant=\"simple\" size=\"small\">{{ errorMessage }}</p-message>\n }\n\n <ng-content></ng-content>\n</div>\n" }]
1695
- }], ctorParameters: () => [], propDecorators: { label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], hint: [{ type: i0.Input, args: [{ isSignal: true, alias: "hint", required: false }] }], placeholder: [{ type: i0.Input, args: [{ isSignal: true, alias: "placeholder", required: false }] }], id: [{ type: i0.Input, args: [{ isSignal: true, alias: "id", required: false }] }], labelVariant: [{ type: i0.Input, args: [{ isSignal: true, alias: "labelVariant", required: false }] }], readonly: [{ type: i0.Input, args: [{ isSignal: true, alias: "readonly", required: false }] }], erros: [{ type: i0.Input, args: [{ isSignal: true, alias: "erros", required: false }] }], url: [{ type: i0.Input, args: [{ isSignal: true, alias: "url", required: true }] }], optionLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "optionLabel", required: false }] }], optionValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "optionValue", required: false }] }], filter: [{ type: i0.Input, args: [{ isSignal: true, alias: "filter", required: false }] }], showClear: [{ type: i0.Input, args: [{ isSignal: true, alias: "showClear", required: false }] }] } });
1701
+ }], ctorParameters: () => [], propDecorators: { label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], hint: [{ type: i0.Input, args: [{ isSignal: true, alias: "hint", required: false }] }], placeholder: [{ type: i0.Input, args: [{ isSignal: true, alias: "placeholder", required: false }] }], id: [{ type: i0.Input, args: [{ isSignal: true, alias: "id", required: false }] }], labelVariant: [{ type: i0.Input, args: [{ isSignal: true, alias: "labelVariant", required: false }] }], readonly: [{ type: i0.Input, args: [{ isSignal: true, alias: "readonly", required: false }] }], erros: [{ type: i0.Input, args: [{ isSignal: true, alias: "erros", required: false }] }], url: [{ type: i0.Input, args: [{ isSignal: true, alias: "url", required: false }] }], options: [{ type: i0.Input, args: [{ isSignal: true, alias: "options", required: false }] }], optionLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "optionLabel", required: false }] }], optionValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "optionValue", required: false }] }], filter: [{ type: i0.Input, args: [{ isSignal: true, alias: "filter", required: false }] }], showClear: [{ type: i0.Input, args: [{ isSignal: true, alias: "showClear", required: false }] }] } });
1696
1702
 
1697
1703
  class PjcErroValidacaoComponent {
1698
1704
  container = inject(ControlContainer);
@@ -1980,28 +1986,64 @@ class PjcMoedaFieldComponent {
1980
1986
  onKeyDown(event) {
1981
1987
  if (this.disabled || this.readonly())
1982
1988
  return;
1989
+ const input = event.target;
1990
+ const cursorPos = input.selectionStart ?? 0;
1991
+ const displayText = input.value;
1992
+ const digitsBeforeCursor = (displayText.substring(0, cursorPos).match(/\d/g) || []).length;
1993
+ const displayDigits = (displayText.match(/\d/g) || []).join('');
1983
1994
  if (/^\d$/.test(event.key)) {
1984
1995
  event.preventDefault();
1985
- if (this.cents() < 9_999_999_999) {
1986
- this.cents.update(c => c * 10 + Number.parseInt(event.key, 10));
1996
+ const digits = displayDigits.split('');
1997
+ digits.splice(digitsBeforeCursor, 0, event.key);
1998
+ const newCents = Number.parseInt(digits.join(''), 10) || 0;
1999
+ if (newCents <= 9_999_999_999) {
2000
+ this.cents.set(newCents);
1987
2001
  this.emitValue();
2002
+ this.restoreCursor(input, digitsBeforeCursor + 1);
1988
2003
  }
1989
2004
  }
1990
2005
  else if (event.key === 'Backspace') {
1991
2006
  event.preventDefault();
1992
- this.cents.update(c => Math.floor(c / 10));
1993
- this.emitValue();
2007
+ if (digitsBeforeCursor > 0) {
2008
+ const digits = displayDigits.split('');
2009
+ digits.splice(digitsBeforeCursor - 1, 1);
2010
+ this.cents.set(Number.parseInt(digits.join(''), 10) || 0);
2011
+ this.emitValue();
2012
+ this.restoreCursor(input, digitsBeforeCursor - 1);
2013
+ }
1994
2014
  }
1995
2015
  else if (event.key === 'Delete') {
1996
2016
  event.preventDefault();
1997
- this.cents.set(0);
1998
- this.emitValue();
2017
+ if (digitsBeforeCursor < displayDigits.length) {
2018
+ const digits = displayDigits.split('');
2019
+ digits.splice(digitsBeforeCursor, 1);
2020
+ this.cents.set(Number.parseInt(digits.join(''), 10) || 0);
2021
+ this.emitValue();
2022
+ this.restoreCursor(input, digitsBeforeCursor);
2023
+ }
1999
2024
  }
2000
2025
  else if (event.key.length === 1) {
2001
2026
  // Block all other printable characters (letters, symbols, etc.)
2002
2027
  event.preventDefault();
2003
2028
  }
2004
2029
  }
2030
+ restoreCursor(input, targetDigitPos) {
2031
+ requestAnimationFrame(() => {
2032
+ const newValue = input.value;
2033
+ let digitCount = 0;
2034
+ let newPos = newValue.length;
2035
+ for (let i = 0; i < newValue.length; i++) {
2036
+ if (/\d/.test(newValue[i])) {
2037
+ digitCount++;
2038
+ if (digitCount === targetDigitPos) {
2039
+ newPos = i + 1;
2040
+ break;
2041
+ }
2042
+ }
2043
+ }
2044
+ input.setSelectionRange(newPos, newPos);
2045
+ });
2046
+ }
2005
2047
  onPaste(event) {
2006
2048
  event.preventDefault();
2007
2049
  }