pjc-fields 0.0.29 → 0.0.32

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.
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Component, input, forwardRef, ChangeDetectionStrategy, signal, computed, inject, ElementRef, output, Directive, ChangeDetectorRef, DestroyRef } from '@angular/core';
2
+ import { Component, input, forwardRef, ChangeDetectionStrategy, signal, computed, inject, ElementRef, output, Directive, ChangeDetectorRef, DestroyRef, Injectable, InjectionToken, effect } from '@angular/core';
3
3
  import * as i1 from '@angular/forms';
4
4
  import { FormsModule, NG_VALUE_ACCESSOR, NG_VALIDATORS, ControlContainer } from '@angular/forms';
5
5
  import * as i2 from 'primeng/inputmask';
@@ -22,6 +22,11 @@ import { InputNumberModule } from 'primeng/inputnumber';
22
22
  import { KeyValuePipe } from '@angular/common';
23
23
  import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
24
24
  import { merge } from 'rxjs';
25
+ import * as i2$4 from 'primeng/autocomplete';
26
+ import { AutoCompleteModule } from 'primeng/autocomplete';
27
+ import { HttpClient } from '@angular/common/http';
28
+ import { map } from 'rxjs/operators';
29
+ import * as i3$2 from 'primeng/api';
25
30
 
26
31
  class PjcFields {
27
32
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: PjcFields, deps: [], target: i0.ɵɵFactoryTarget.Component });
@@ -1224,6 +1229,7 @@ const ESTADOS = [
1224
1229
  { uf: 'SE', descricao: 'Sergipe' },
1225
1230
  { uf: 'TO', descricao: 'Tocantins' },
1226
1231
  ];
1232
+
1227
1233
  class PjcUfFieldComponent {
1228
1234
  label = input('UF', ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
1229
1235
  hint = input('', ...(ngDevMode ? [{ debugName: "hint" }] : /* istanbul ignore next */ []));
@@ -1833,6 +1839,139 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
1833
1839
  args: [{ selector: 'pjc-erro-validacao', changeDetection: ChangeDetectionStrategy.OnPush, imports: [KeyValuePipe], template: "@if (control; as ctrl) {\n @if (ctrl.touched && ctrl.errors) {\n @for (entry of erros() | keyvalue; track entry.key) {\n @if (ctrl.errors[entry.key]) {\n <small class=\"text-red-500 text-xs\">{{ entry.value }}</small>\n }\n }\n }\n}\n" }]
1834
1840
  }], propDecorators: { controlName: [{ type: i0.Input, args: [{ isSignal: true, alias: "controlName", required: true }] }], erros: [{ type: i0.Input, args: [{ isSignal: true, alias: "erros", required: true }] }] } });
1835
1841
 
1842
+ class PjcCidadeService {
1843
+ http = inject(HttpClient);
1844
+ API_URL = 'https://servicodados.ibge.gov.br/api/v1/localidades/estados';
1845
+ getMunicipiosByUf(uf) {
1846
+ return this.http
1847
+ .get(`${this.API_URL}/${uf}/municipios`)
1848
+ .pipe(map((data) => data
1849
+ .map((m) => ({ id: m.id, nome: m.nome, descricao: m.descricao }))
1850
+ .sort((a, b) => {
1851
+ const aDisplay = a.nome || a.descricao || '';
1852
+ const bDisplay = b.nome || b.descricao || '';
1853
+ return aDisplay.localeCompare(bDisplay);
1854
+ })));
1855
+ }
1856
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: PjcCidadeService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1857
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: PjcCidadeService, providedIn: 'root' });
1858
+ }
1859
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: PjcCidadeService, decorators: [{
1860
+ type: Injectable,
1861
+ args: [{
1862
+ providedIn: 'root',
1863
+ }]
1864
+ }] });
1865
+
1866
+ const PJC_CIDADE_SERVICE = new InjectionToken('PjcCidadeService');
1867
+
1868
+ class PjcCidadeFieldComponent {
1869
+ label = input('', ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
1870
+ hint = input('', ...(ngDevMode ? [{ debugName: "hint" }] : /* istanbul ignore next */ []));
1871
+ placeholder = input('Digite o nome da cidade', ...(ngDevMode ? [{ debugName: "placeholder" }] : /* istanbul ignore next */ []));
1872
+ id = input(`pjc-cidade-${Math.random().toString(36).substring(2, 9)}`, ...(ngDevMode ? [{ debugName: "id" }] : /* istanbul ignore next */ []));
1873
+ labelVariant = input('on', ...(ngDevMode ? [{ debugName: "labelVariant" }] : /* istanbul ignore next */ []));
1874
+ readonly = input(false, ...(ngDevMode ? [{ debugName: "readonly" }] : /* istanbul ignore next */ []));
1875
+ uf = input('', ...(ngDevMode ? [{ debugName: "uf" }] : /* istanbul ignore next */ []));
1876
+ service = inject(PJC_CIDADE_SERVICE, { optional: true }) ?? inject(PjcCidadeService);
1877
+ municipios = signal([], ...(ngDevMode ? [{ debugName: "municipios" }] : /* istanbul ignore next */ []));
1878
+ filteredMunicipios = signal([], ...(ngDevMode ? [{ debugName: "filteredMunicipios" }] : /* istanbul ignore next */ []));
1879
+ loading = signal(false, ...(ngDevMode ? [{ debugName: "loading" }] : /* istanbul ignore next */ []));
1880
+ value = null;
1881
+ disabled = false;
1882
+ onChange = () => { };
1883
+ onTouched = () => { };
1884
+ constructor() {
1885
+ effect(() => {
1886
+ const uf = this.uf();
1887
+ if (uf) {
1888
+ this.fetchMunicipios(uf);
1889
+ }
1890
+ else {
1891
+ this.municipios.set([]);
1892
+ this.filteredMunicipios.set([]);
1893
+ }
1894
+ });
1895
+ }
1896
+ writeValue(val) {
1897
+ if (val === null || val === undefined) {
1898
+ this.value = null;
1899
+ }
1900
+ else if (typeof val === 'string') {
1901
+ const found = this.municipios().find(m => m.nome === val || m.descricao === val);
1902
+ this.value = found ?? { id: 0, nome: val };
1903
+ }
1904
+ else {
1905
+ this.value = val;
1906
+ }
1907
+ }
1908
+ registerOnChange(fn) {
1909
+ this.onChange = fn;
1910
+ }
1911
+ registerOnTouched(fn) {
1912
+ this.onTouched = fn;
1913
+ }
1914
+ setDisabledState(isDisabled) {
1915
+ this.disabled = isDisabled;
1916
+ }
1917
+ onModelChange(value) {
1918
+ if (typeof value === 'string') {
1919
+ this.value = null;
1920
+ this.onChange(null);
1921
+ }
1922
+ else {
1923
+ this.value = value;
1924
+ this.onChange(value);
1925
+ }
1926
+ }
1927
+ onModelTouched() {
1928
+ this.onTouched();
1929
+ }
1930
+ getMunicipioDisplay(m) {
1931
+ return m.nome || m.descricao || '';
1932
+ }
1933
+ filterMunicipios(event) {
1934
+ const query = event.query.toLowerCase();
1935
+ this.filteredMunicipios.set(this.municipios().filter(m => this.getMunicipioDisplay(m).toLowerCase().includes(query)));
1936
+ }
1937
+ fetchMunicipios(uf) {
1938
+ this.loading.set(true);
1939
+ this.value = null;
1940
+ this.onChange(null);
1941
+ this.service.getMunicipiosByUf(uf).subscribe({
1942
+ next: (data) => {
1943
+ const normalized = data.map(m => ({ ...m, nome: m.nome || m.descricao || '' }));
1944
+ this.municipios.set(normalized);
1945
+ this.filteredMunicipios.set(normalized);
1946
+ this.loading.set(false);
1947
+ },
1948
+ error: () => {
1949
+ this.municipios.set([]);
1950
+ this.filteredMunicipios.set([]);
1951
+ this.loading.set(false);
1952
+ },
1953
+ });
1954
+ }
1955
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: PjcCidadeFieldComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
1956
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.4", type: PjcCidadeFieldComponent, isStandalone: true, selector: "pjc-cidade-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 }, uf: { classPropertyName: "uf", publicName: "uf", isSignal: true, isRequired: false, transformFunction: null } }, providers: [
1957
+ {
1958
+ provide: NG_VALUE_ACCESSOR,
1959
+ useExisting: forwardRef(() => PjcCidadeFieldComponent),
1960
+ multi: true,
1961
+ },
1962
+ ], ngImport: i0, template: "<div class=\"flex flex-col gap-1 w-full\">\n @if (label()) {\n <p-floatlabel [variant]=\"labelVariant()\" class=\"w-full\">\n <p-autocomplete\n [inputId]=\"id()\"\n [suggestions]=\"filteredMunicipios()\"\n [ngModel]=\"value\"\n (ngModelChange)=\"onModelChange($event)\"\n (onBlur)=\"onModelTouched()\"\n (completeMethod)=\"filterMunicipios($event)\"\n dataKey=\"id\"\n optionLabel=\"nome\"\n [forceSelection]=\"true\"\n [disabled]=\"disabled || readonly() || !uf() || loading()\"\n appendTo=\"body\"\n styleClass=\"w-full\"\n inputStyleClass=\"w-full\"\n >\n <ng-template pTemplate=\"item\" let-option>\n {{ getMunicipioDisplay(option) }}\n </ng-template>\n </p-autocomplete>\n <label [for]=\"id()\">{{ label() }}</label>\n </p-floatlabel>\n } @else {\n <p-autocomplete\n [inputId]=\"id()\"\n [suggestions]=\"filteredMunicipios()\"\n [ngModel]=\"value\"\n (ngModelChange)=\"onModelChange($event)\"\n (onBlur)=\"onModelTouched()\"\n (completeMethod)=\"filterMunicipios($event)\"\n dataKey=\"id\"\n optionLabel=\"nome\"\n [forceSelection]=\"true\"\n [placeholder]=\"placeholder()\"\n [disabled]=\"disabled || readonly() || !uf() || loading()\"\n appendTo=\"body\"\n styleClass=\"w-full\"\n inputStyleClass=\"w-full\"\n >\n <ng-template pTemplate=\"item\" let-option>\n {{ getMunicipioDisplay(option) }}\n </ng-template>\n </p-autocomplete>\n }\n\n @if (hint()) {\n <small class=\"text-xs text-surface-500\">{{ hint() }}</small>\n }\n\n <ng-content></ng-content>\n</div>\n", dependencies: [{ kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "ngmodule", type: AutoCompleteModule }, { kind: "component", type: i2$4.AutoComplete, selector: "p-autoComplete, p-autocomplete, p-auto-complete", inputs: ["minLength", "minQueryLength", "delay", "panelStyle", "styleClass", "panelStyleClass", "inputStyle", "inputId", "inputStyleClass", "placeholder", "readonly", "scrollHeight", "lazy", "virtualScroll", "virtualScrollItemSize", "virtualScrollOptions", "autoHighlight", "forceSelection", "type", "autoZIndex", "baseZIndex", "ariaLabel", "dropdownAriaLabel", "ariaLabelledBy", "dropdownIcon", "unique", "group", "completeOnFocus", "showClear", "dropdown", "showEmptyMessage", "dropdownMode", "multiple", "addOnTab", "tabindex", "dataKey", "emptyMessage", "showTransitionOptions", "hideTransitionOptions", "autofocus", "autocomplete", "optionGroupChildren", "optionGroupLabel", "overlayOptions", "suggestions", "optionLabel", "optionValue", "id", "searchMessage", "emptySelectionMessage", "selectionMessage", "autoOptionFocus", "selectOnFocus", "searchLocale", "optionDisabled", "focusOnHover", "typeahead", "addOnBlur", "separator", "appendTo", "motionOptions"], outputs: ["completeMethod", "onSelect", "onUnselect", "onAdd", "onFocus", "onBlur", "onDropdownClick", "onClear", "onInputKeydown", "onKeyUp", "onShow", "onHide", "onLazyLoad"] }, { kind: "directive", type: i3$2.PrimeTemplate, selector: "[pTemplate]", inputs: ["type", "pTemplate"] }, { kind: "ngmodule", type: FloatLabelModule }, { kind: "component", type: i3.FloatLabel, selector: "p-floatlabel, p-floatLabel, p-float-label", inputs: ["variant"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
1963
+ }
1964
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: PjcCidadeFieldComponent, decorators: [{
1965
+ type: Component,
1966
+ args: [{ selector: 'pjc-cidade-field', changeDetection: ChangeDetectionStrategy.OnPush, imports: [FormsModule, AutoCompleteModule, FloatLabelModule], providers: [
1967
+ {
1968
+ provide: NG_VALUE_ACCESSOR,
1969
+ useExisting: forwardRef(() => PjcCidadeFieldComponent),
1970
+ multi: true,
1971
+ },
1972
+ ], template: "<div class=\"flex flex-col gap-1 w-full\">\n @if (label()) {\n <p-floatlabel [variant]=\"labelVariant()\" class=\"w-full\">\n <p-autocomplete\n [inputId]=\"id()\"\n [suggestions]=\"filteredMunicipios()\"\n [ngModel]=\"value\"\n (ngModelChange)=\"onModelChange($event)\"\n (onBlur)=\"onModelTouched()\"\n (completeMethod)=\"filterMunicipios($event)\"\n dataKey=\"id\"\n optionLabel=\"nome\"\n [forceSelection]=\"true\"\n [disabled]=\"disabled || readonly() || !uf() || loading()\"\n appendTo=\"body\"\n styleClass=\"w-full\"\n inputStyleClass=\"w-full\"\n >\n <ng-template pTemplate=\"item\" let-option>\n {{ getMunicipioDisplay(option) }}\n </ng-template>\n </p-autocomplete>\n <label [for]=\"id()\">{{ label() }}</label>\n </p-floatlabel>\n } @else {\n <p-autocomplete\n [inputId]=\"id()\"\n [suggestions]=\"filteredMunicipios()\"\n [ngModel]=\"value\"\n (ngModelChange)=\"onModelChange($event)\"\n (onBlur)=\"onModelTouched()\"\n (completeMethod)=\"filterMunicipios($event)\"\n dataKey=\"id\"\n optionLabel=\"nome\"\n [forceSelection]=\"true\"\n [placeholder]=\"placeholder()\"\n [disabled]=\"disabled || readonly() || !uf() || loading()\"\n appendTo=\"body\"\n styleClass=\"w-full\"\n inputStyleClass=\"w-full\"\n >\n <ng-template pTemplate=\"item\" let-option>\n {{ getMunicipioDisplay(option) }}\n </ng-template>\n </p-autocomplete>\n }\n\n @if (hint()) {\n <small class=\"text-xs text-surface-500\">{{ hint() }}</small>\n }\n\n <ng-content></ng-content>\n</div>\n" }]
1973
+ }], 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 }] }], uf: [{ type: i0.Input, args: [{ isSignal: true, alias: "uf", required: false }] }] } });
1974
+
1836
1975
  /*
1837
1976
  * Public API Surface of pjc-fields
1838
1977
  */
@@ -1841,5 +1980,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
1841
1980
  * Generated bundle index. Do not edit.
1842
1981
  */
1843
1982
 
1844
- export { PjcCepFieldComponent, PjcChassiFieldComponent, PjcChassiInputDirective, PjcCnhFieldComponent, PjcCnpjFieldComponent, PjcCpfCnpjFieldComponent, PjcCpfFieldComponent, PjcDataFieldComponent, PjcDataHoraFieldComponent, PjcEmailFieldComponent, PjcErroValidacaoComponent, PjcFields, PjcHoraFieldComponent, PjcIntegerFieldComponent, PjcMoedaFieldComponent, PjcNumeroCartaoFieldComponent, PjcPasswordFieldComponent, PjcPlacaFieldComponent, PjcRenavamFieldComponent, PjcTelefoneFieldComponent, PjcUfFieldComponent, PjcUppercaseFieldComponent, PjcValidators };
1983
+ export { ESTADOS, PJC_CIDADE_SERVICE, PjcCepFieldComponent, PjcChassiFieldComponent, PjcChassiInputDirective, PjcCidadeFieldComponent, PjcCidadeService, PjcCnhFieldComponent, PjcCnpjFieldComponent, PjcCpfCnpjFieldComponent, PjcCpfFieldComponent, PjcDataFieldComponent, PjcDataHoraFieldComponent, PjcEmailFieldComponent, PjcErroValidacaoComponent, PjcFields, PjcHoraFieldComponent, PjcIntegerFieldComponent, PjcMoedaFieldComponent, PjcNumeroCartaoFieldComponent, PjcPasswordFieldComponent, PjcPlacaFieldComponent, PjcRenavamFieldComponent, PjcTelefoneFieldComponent, PjcUfFieldComponent, PjcUppercaseFieldComponent, PjcValidators };
1845
1984
  //# sourceMappingURL=pjc-fields.mjs.map