pjc-fields 0.0.40 → 0.0.41

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.
@@ -163,6 +163,34 @@ class PjcValidators {
163
163
  return emailRegex.test(value) ? null : { emailInvalido: true };
164
164
  };
165
165
  }
166
+ static imei() {
167
+ return (control) => {
168
+ const digits = control.value?.replace(/\D/g, '');
169
+ if (!digits)
170
+ return null;
171
+ if (digits.length !== 15) {
172
+ return { imeiInvalido: true };
173
+ }
174
+ if (!PjcValidators.validateImei(digits)) {
175
+ return { imeiInvalido: true };
176
+ }
177
+ return null;
178
+ };
179
+ }
180
+ static validateImei(digits) {
181
+ let sum = 0;
182
+ for (let i = 0; i < digits.length; i++) {
183
+ let n = Number.parseInt(digits[i], 10);
184
+ if (i % 2 === 1) {
185
+ n *= 2;
186
+ if (n > 9) {
187
+ n -= 9;
188
+ }
189
+ }
190
+ sum += n;
191
+ }
192
+ return sum % 10 === 0;
193
+ }
166
194
  static numeroCartao() {
167
195
  return (control) => {
168
196
  const digits = control.value?.replace(/\D/g, '');
@@ -1622,6 +1650,83 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
1622
1650
  ], template: "<div class=\"flex flex-col gap-1 w-full\">\n @if (label()) {\n <p-floatlabel [variant]=\"labelVariant()\" class=\"w-full\">\n <p-inputnumber\n [inputId]=\"id()\"\n [ngModel]=\"value\"\n (ngModelChange)=\"onValueChange($event)\"\n (onBlur)=\"onTouched()\"\n [placeholder]=\"placeholder()\"\n [useGrouping]=\"useGrouping()\"\n [prefix]=\"prefix()\"\n [suffix]=\"suffix()\"\n [min]=\"min()\"\n [max]=\"max()\"\n [disabled]=\"disabled\"\n [readonly]=\"readonly()\"\n [maxFractionDigits]=\"0\"\n inputStyleClass=\"w-full p-2 outline-none bg-transparent\"\n styleClass=\"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-inputnumber\n [inputId]=\"id()\"\n [ngModel]=\"value\"\n (ngModelChange)=\"onValueChange($event)\"\n (onBlur)=\"onTouched()\"\n [placeholder]=\"placeholder()\"\n [useGrouping]=\"useGrouping()\"\n [prefix]=\"prefix()\"\n [suffix]=\"suffix()\"\n [min]=\"min()\"\n [max]=\"max()\"\n [disabled]=\"disabled\"\n [maxFractionDigits]=\"0\"\n inputStyleClass=\"w-full p-2 border border-surface-300 rounded-md outline-none bg-transparent focus:border-primary-500\"\n styleClass=\"w-full\"\n [class.ng-invalid]=\"invalid\"\n [class.ng-dirty]=\"invalid\"\n />\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" }]
1623
1651
  }], propDecorators: { label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", 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 }] }], prefix: [{ type: i0.Input, args: [{ isSignal: true, alias: "prefix", required: false }] }], suffix: [{ type: i0.Input, args: [{ isSignal: true, alias: "suffix", required: false }] }], useGrouping: [{ type: i0.Input, args: [{ isSignal: true, alias: "useGrouping", required: false }] }], min: [{ type: i0.Input, args: [{ isSignal: true, alias: "min", required: false }] }], max: [{ type: i0.Input, args: [{ isSignal: true, alias: "max", required: false }] }], readonly: [{ type: i0.Input, args: [{ isSignal: true, alias: "readonly", required: false }] }], erros: [{ type: i0.Input, args: [{ isSignal: true, alias: "erros", required: false }] }] } });
1624
1652
 
1653
+ class PjcImeiFieldComponent {
1654
+ label = input('', ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
1655
+ hint = input('', ...(ngDevMode ? [{ debugName: "hint" }] : /* istanbul ignore next */ []));
1656
+ placeholder = input('000000000000000', ...(ngDevMode ? [{ debugName: "placeholder" }] : /* istanbul ignore next */ []));
1657
+ id = input(`pjc-imei-${Math.random().toString(36).substring(2, 9)}`, ...(ngDevMode ? [{ debugName: "id" }] : /* istanbul ignore next */ []));
1658
+ labelVariant = input('on', ...(ngDevMode ? [{ debugName: "labelVariant" }] : /* istanbul ignore next */ []));
1659
+ readonly = input(false, ...(ngDevMode ? [{ debugName: "readonly" }] : /* istanbul ignore next */ []));
1660
+ erros = input({}, ...(ngDevMode ? [{ debugName: "erros" }] : /* istanbul ignore next */ []));
1661
+ injector = inject(Injector);
1662
+ cdr = inject(ChangeDetectorRef);
1663
+ destroyRef = inject(DestroyRef);
1664
+ ngControl = null;
1665
+ value = '';
1666
+ disabled = false;
1667
+ onChange = () => { };
1668
+ onTouched = () => { };
1669
+ ngOnInit() {
1670
+ this.ngControl = initFormValidation(this.injector, this.cdr, this.destroyRef);
1671
+ }
1672
+ get invalid() {
1673
+ return isFormControlInvalid(this.ngControl);
1674
+ }
1675
+ get errorMessage() {
1676
+ return getErrorMessage(this.ngControl, this.erros());
1677
+ }
1678
+ writeValue(val) {
1679
+ this.value = val ?? '';
1680
+ }
1681
+ registerOnChange(fn) {
1682
+ this.onChange = fn;
1683
+ }
1684
+ registerOnTouched(fn) {
1685
+ this.onTouched = fn;
1686
+ }
1687
+ setDisabledState(isDisabled) {
1688
+ this.disabled = isDisabled;
1689
+ }
1690
+ onModelChange(value) {
1691
+ this.value = value ?? '';
1692
+ this.onChange(this.value);
1693
+ }
1694
+ onModelTouched() {
1695
+ this.onTouched();
1696
+ }
1697
+ validate(control) {
1698
+ return PjcValidators.imei()(control);
1699
+ }
1700
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: PjcImeiFieldComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
1701
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.4", type: PjcImeiFieldComponent, isStandalone: true, selector: "pjc-imei-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 } }, providers: [
1702
+ {
1703
+ provide: NG_VALUE_ACCESSOR,
1704
+ useExisting: forwardRef(() => PjcImeiFieldComponent),
1705
+ multi: true,
1706
+ },
1707
+ {
1708
+ provide: NG_VALIDATORS,
1709
+ useExisting: forwardRef(() => PjcImeiFieldComponent),
1710
+ multi: true,
1711
+ },
1712
+ ], 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-inputMask\n [id]=\"id()\"\n mask=\"999999999999999\"\n [ngModel]=\"value\"\n (ngModelChange)=\"onModelChange($event)\"\n (onBlur)=\"onModelTouched()\"\n [unmask]=\"true\"\n [autoClear]=\"false\"\n [placeholder]=\"placeholder()\"\n [disabled]=\"disabled\"\n [readonly]=\"readonly()\"\n [class.ng-invalid]=\"invalid\"\n [class.ng-dirty]=\"invalid\"\n styleClass=\"w-full\"\n inputStyleClass=\"w-full p-2 outline-none bg-transparent\"\n ></p-inputMask>\n <label [for]=\"id()\">{{ label() }}</label>\n </p-floatlabel>\n } @else {\n <p-inputMask\n [id]=\"id()\"\n mask=\"999999999999999\"\n [ngModel]=\"value\"\n (ngModelChange)=\"onModelChange($event)\"\n (onBlur)=\"onModelTouched()\"\n [unmask]=\"true\"\n [autoClear]=\"false\"\n [placeholder]=\"placeholder()\"\n [disabled]=\"disabled\"\n [class.ng-invalid]=\"invalid\"\n [class.ng-dirty]=\"invalid\"\n styleClass=\"w-full border border-surface-300 rounded-md focus:border-primary-500 transition-colors\"\n inputStyleClass=\"w-full p-2 outline-none bg-transparent\"\n ></p-inputMask>\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", 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: InputMaskModule }, { kind: "component", type: i2.InputMask, selector: "p-inputmask, p-inputMask, p-input-mask", inputs: ["type", "slotChar", "autoClear", "showClear", "style", "inputId", "styleClass", "placeholder", "tabindex", "title", "ariaLabel", "ariaLabelledBy", "ariaRequired", "readonly", "unmask", "characterPattern", "autofocus", "autocomplete", "keepBuffer", "mask"], outputs: ["onComplete", "onFocus", "onBlur", "onInput", "onKeydown", "onClear"] }, { kind: "ngmodule", type: FloatLabelModule }, { kind: "component", type: i3.FloatLabel, selector: "p-floatlabel, p-floatLabel, p-float-label", inputs: ["variant"] }, { kind: "ngmodule", type: MessageModule }, { kind: "component", type: i4.Message, selector: "p-message", inputs: ["severity", "text", "escape", "style", "styleClass", "closable", "icon", "closeIcon", "life", "showTransitionOptions", "hideTransitionOptions", "size", "variant", "motionOptions"], outputs: ["onClose"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
1713
+ }
1714
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: PjcImeiFieldComponent, decorators: [{
1715
+ type: Component,
1716
+ args: [{ selector: 'pjc-imei-field', changeDetection: ChangeDetectionStrategy.OnPush, imports: [FormsModule, InputMaskModule, FloatLabelModule, MessageModule], providers: [
1717
+ {
1718
+ provide: NG_VALUE_ACCESSOR,
1719
+ useExisting: forwardRef(() => PjcImeiFieldComponent),
1720
+ multi: true,
1721
+ },
1722
+ {
1723
+ provide: NG_VALIDATORS,
1724
+ useExisting: forwardRef(() => PjcImeiFieldComponent),
1725
+ multi: true,
1726
+ },
1727
+ ], template: "<div class=\"flex flex-col gap-1 w-full\">\n @if (label()) {\n <p-floatlabel [variant]=\"labelVariant()\" class=\"w-full\">\n <p-inputMask\n [id]=\"id()\"\n mask=\"999999999999999\"\n [ngModel]=\"value\"\n (ngModelChange)=\"onModelChange($event)\"\n (onBlur)=\"onModelTouched()\"\n [unmask]=\"true\"\n [autoClear]=\"false\"\n [placeholder]=\"placeholder()\"\n [disabled]=\"disabled\"\n [readonly]=\"readonly()\"\n [class.ng-invalid]=\"invalid\"\n [class.ng-dirty]=\"invalid\"\n styleClass=\"w-full\"\n inputStyleClass=\"w-full p-2 outline-none bg-transparent\"\n ></p-inputMask>\n <label [for]=\"id()\">{{ label() }}</label>\n </p-floatlabel>\n } @else {\n <p-inputMask\n [id]=\"id()\"\n mask=\"999999999999999\"\n [ngModel]=\"value\"\n (ngModelChange)=\"onModelChange($event)\"\n (onBlur)=\"onModelTouched()\"\n [unmask]=\"true\"\n [autoClear]=\"false\"\n [placeholder]=\"placeholder()\"\n [disabled]=\"disabled\"\n [class.ng-invalid]=\"invalid\"\n [class.ng-dirty]=\"invalid\"\n styleClass=\"w-full border border-surface-300 rounded-md focus:border-primary-500 transition-colors\"\n inputStyleClass=\"w-full p-2 outline-none bg-transparent\"\n ></p-inputMask>\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" }]
1728
+ }], 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 }] }] } });
1729
+
1625
1730
  class PjcNumeroCartaoFieldComponent {
1626
1731
  label = input('', ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
1627
1732
  hint = input('', ...(ngDevMode ? [{ debugName: "hint" }] : /* istanbul ignore next */ []));
@@ -2320,5 +2425,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
2320
2425
  * Generated bundle index. Do not edit.
2321
2426
  */
2322
2427
 
2323
- 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 };
2428
+ export { ESTADOS, PJC_CIDADE_SERVICE, PjcCepFieldComponent, PjcChassiFieldComponent, PjcChassiInputDirective, PjcCidadeFieldComponent, PjcCidadeService, PjcCnhFieldComponent, PjcCnpjFieldComponent, PjcCpfCnpjFieldComponent, PjcCpfFieldComponent, PjcDataFieldComponent, PjcDataHoraFieldComponent, PjcEmailFieldComponent, PjcErroValidacaoComponent, PjcFields, PjcHoraFieldComponent, PjcImeiFieldComponent, PjcIntegerFieldComponent, PjcMoedaFieldComponent, PjcNumeroCartaoFieldComponent, PjcPasswordFieldComponent, PjcPlacaFieldComponent, PjcRenavamFieldComponent, PjcTelefoneFieldComponent, PjcUfFieldComponent, PjcUppercaseFieldComponent, PjcValidators };
2324
2429
  //# sourceMappingURL=pjc-fields.mjs.map