UNPKG

@tapsellorg/angular-material-library

Version:

Angular library for Tapsell

823 lines (803 loc) 34.9 kB
import * as i0 from '@angular/core'; import { input, Directive, InjectionToken, Inject, Optional, Self, HostListener, LOCALE_ID, forwardRef, Injectable, Pipe, NgModule } from '@angular/core'; import { formatNumber, CommonModule } from '@angular/common'; import * as i2 from '@angular/material/form-field'; import { MAT_FORM_FIELD } from '@angular/material/form-field'; import { Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; import * as i1 from '@angular/forms'; import { NG_VALUE_ACCESSOR } from '@angular/forms'; import { StringUtils } from '@tapsellorg/angular-material-library/src/lib/common'; import { MAT_INPUT_VALUE_ACCESSOR } from '@angular/material/input'; class PghInputTypeDirective { constructor(elemRef) { this.elemRef = elemRef; this.type = input(''); this.showPassword = input(false, { alias: 'pghShowPassword', }); } ngOnChanges(changes) { if (changes.type) { this.handleTypeChange(); } if (changes.showPassword) { this.handleShowPasswordChange(); } } handleTypeChange() { if (!this.type()) return; switch (this.type()) { case 'email': this.setInputMode('email'); break; case 'tel': this.setInputMode('tel'); break; case 'url': this.setInputMode('url'); break; case 'number': this.setInputMode('numeric'); // this.setType('text'); break; case 'password': this.handleShowPasswordChange(); break; default: this.setInputMode('text'); } } setInputMode(inputMode) { this.elemRef.nativeElement.inputMode = inputMode; } handleShowPasswordChange() { if (this.type() !== 'password') return; this.setType(this.showPassword() ? 'text' : 'password'); } setType(type) { this.elemRef.nativeElement.type = type; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: PghInputTypeDirective, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive }); } static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "19.2.13", type: PghInputTypeDirective, isStandalone: false, selector: "input[type]", inputs: { type: { classPropertyName: "type", publicName: "type", isSignal: true, isRequired: false, transformFunction: null }, showPassword: { classPropertyName: "showPassword", publicName: "pghShowPassword", isSignal: true, isRequired: false, transformFunction: null } }, usesOnChanges: true, ngImport: i0 }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: PghInputTypeDirective, decorators: [{ type: Directive, args: [{ selector: 'input[type]', standalone: false, }] }], ctorParameters: () => [{ type: i0.ElementRef }] }); const PGH_DEFAULT_ERROR_MESSAGES = { required: 'این قسمت را خالی نگذارید', pattern: 'فرمت ورودی اشتباه است', email: 'ایمیل اشتباه است', password: 'پسورد اشتباه است', url: 'یک URL مثل http://example.com وارد کنید', entity: 'یک Entity مثل market://example', phoneNumber: 'یک شماره تلفن مثل 09009990099 وارد کنید', uppercase: 'کارکترهای Capital قابل قبول نیست', postalCode: 'کد پستی وارد شده معتبر نیست.', sheba: 'شماره‌ی شبای ۲۴ رقمی بدون IR وارد کنید', shebaIr: 'شماره‌ی شبای ۲۴ رقمی با IR وارد کنید', debitCard: 'یک شماره کارت مثلا 2222333344445555 وارد کنید', nationalCode: 'کدملی وارد شده معتبر نیست', unknownOption: 'مقدار وارد شده معتبر نیست', forbiddenOption: 'این ورودی قابل قبول نیست', forbiddenFileName: 'لطفا نامی کوتاه، انگلیسی و بدون فاصله برای فایل خود انتخاب کنید', forbiddenFileType: 'فایل با این پسوند قابل انتخاب نیست', illegalSize: 'حجم فایل انتخاب شده بیشتر از حد مجاز است', }; const PGH_FIELD_ERROR_MESSAGES = new InjectionToken('errorMessages', { providedIn: 'root', factory: () => PGH_DEFAULT_ERROR_MESSAGES, }); class PghFieldErrorDirective { get ngControl() { return this._formField?._control?.ngControl ?? this._ngControl; } constructor(template, containerRef, DEFAULT_ERROR_MESSAGES, _formField, _ngControl) { this.template = template; this.containerRef = containerRef; this.DEFAULT_ERROR_MESSAGES = DEFAULT_ERROR_MESSAGES; this._formField = _formField; this._ngControl = _ngControl; this._destroyed = new Subject(); this._errorMessages = input('', { alias: 'pghFieldError', }); this.errorMessages = {}; } ngAfterViewInit() { // this.ngControl?.valueChanges?.pipe() this.setErrorMessages(); this.handleErrors(); this.ngControl?.statusChanges?.pipe(takeUntil(this._destroyed))?.subscribe?.({ next: value => { if (this.ngControl?.valid) return; this.handleErrors(); }, }); } ngOnChanges(changes) { if (changes._errorMessages) { this.setErrorMessages(); this.handleErrors(); } } setErrorMessages() { const errorMessagesObject = this._errorMessages(); this.errorMessages = { ...PGH_DEFAULT_ERROR_MESSAGES, ...this.DEFAULT_ERROR_MESSAGES, ...(typeof errorMessagesObject === 'object' ? errorMessagesObject : {}), }; } handleErrors() { this.containerRef.clear(); if (!this.errorMessages || !this.ngControl) return; Object.keys(this.ngControl.errors ?? {}).some(key => { const message = this.errorMessages[key]; if (message) { this.createErrorView(key); return true; } return false; }); } createErrorView(key) { const message = this.errorMessages[key]; this.containerRef.createEmbeddedView(this.template, { $implicit: message, key: key, }); } ngOnDestroy() { this._destroyed.next(); this._destroyed.complete(); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: PghFieldErrorDirective, deps: [{ token: i0.TemplateRef }, { token: i0.ViewContainerRef }, { token: PGH_FIELD_ERROR_MESSAGES }, { token: MAT_FORM_FIELD, optional: true }, { token: i1.NgControl, optional: true, self: true }], target: i0.ɵɵFactoryTarget.Directive }); } static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "19.2.13", type: PghFieldErrorDirective, isStandalone: false, selector: "[pghFieldError]", inputs: { _errorMessages: { classPropertyName: "_errorMessages", publicName: "pghFieldError", isSignal: true, isRequired: false, transformFunction: null } }, usesOnChanges: true, ngImport: i0 }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: PghFieldErrorDirective, decorators: [{ type: Directive, args: [{ selector: '[pghFieldError]', standalone: false, }] }], ctorParameters: () => [{ type: i0.TemplateRef }, { type: i0.ViewContainerRef }, { type: undefined, decorators: [{ type: Inject, args: [PGH_FIELD_ERROR_MESSAGES] }] }, { type: i2.MatFormField, decorators: [{ type: Optional }, { type: Inject, args: [MAT_FORM_FIELD] }] }, { type: i1.NgControl, decorators: [{ type: Optional }, { type: Self }] }] }); class PghMarkAllAsTouchedDirective { onSubmit() { this.container.control?.markAllAsTouched(); } constructor(container) { this.container = container; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: PghMarkAllAsTouchedDirective, deps: [{ token: i1.ControlContainer, self: true }], target: i0.ɵɵFactoryTarget.Directive }); } static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.13", type: PghMarkAllAsTouchedDirective, isStandalone: false, selector: "form[formGroup]", host: { listeners: { "submit": "onSubmit()" } }, ngImport: i0 }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: PghMarkAllAsTouchedDirective, decorators: [{ type: Directive, args: [{ selector: 'form[formGroup]', standalone: false, }] }], ctorParameters: () => [{ type: i1.ControlContainer, decorators: [{ type: Self }] }], propDecorators: { onSubmit: [{ type: HostListener, args: ['submit'] }] } }); class PghPersianNumbersToEnglishDirective { constructor(el, control) { this.el = el; this.control = control; } onInput() { if (!this.control.control) return; const convertedNumbers = StringUtils.convertPersianNumbersToEnglish(this.el.nativeElement.value); this.control.control.setValue(convertedNumbers); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: PghPersianNumbersToEnglishDirective, deps: [{ token: i0.ElementRef }, { token: i1.NgControl }], target: i0.ɵɵFactoryTarget.Directive }); } static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.13", type: PghPersianNumbersToEnglishDirective, isStandalone: false, selector: "input[pghPersianNumbersToEnglish]", host: { listeners: { "input": "onInput()" } }, ngImport: i0 }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: PghPersianNumbersToEnglishDirective, decorators: [{ type: Directive, args: [{ selector: 'input[pghPersianNumbersToEnglish]', standalone: false, }] }], ctorParameters: () => [{ type: i0.ElementRef }, { type: i1.NgControl }], propDecorators: { onInput: [{ type: HostListener, args: ['input'] }] } }); class PghFinancialInputDirective { constructor(elementRef, localeId) { this.elementRef = elementRef; this.localeId = localeId; this._value = null; this.value = input('', { transform: (value) => { this._value = value; this.formatValue(value); return this._value; }, }); } formatValue(value, bypassValueCheck = false) { if (value !== null) { if (bypassValueCheck || Number(value) < 1000) { this.elementRef.nativeElement.value = formatNumber(Number(value), this.localeId); } else { this.elementRef.nativeElement.value = String(value); } } else { this.elementRef.nativeElement.value = ''; } } onInput(value) { value = StringUtils.convertPersianNumbersToEnglish(value); const parsedValue = parseFloat(value.replace(/[^\d]/g, '')); this._value = !isNaN(parsedValue) ? parsedValue : null; this.formatValue(this._value, true); this._onChange(this._value); } _onBlur() { this.formatValue(this._value, true); this._onTouched(this._value); } // eslint-disable-next-line @typescript-eslint/no-empty-function _onChange(_) { } // eslint-disable-next-line @typescript-eslint/no-empty-function _onTouched(_) { } writeValue(value) { this._value = value; this.formatValue(this._value); } registerOnChange(fn) { this._onChange = fn; } registerOnTouched(fn) { this._onTouched = fn; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: PghFinancialInputDirective, deps: [{ token: i0.ElementRef }, { token: LOCALE_ID }], target: i0.ɵɵFactoryTarget.Directive }); } static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "19.2.13", type: PghFinancialInputDirective, isStandalone: false, selector: "input[pghFinancialInput]", inputs: { value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: false, transformFunction: null } }, host: { listeners: { "input": "onInput($event.target.value)", "blur": "_onBlur()" } }, providers: [ { provide: MAT_INPUT_VALUE_ACCESSOR, useExisting: PghFinancialInputDirective }, { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => PghFinancialInputDirective), multi: true, }, ], ngImport: i0 }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: PghFinancialInputDirective, decorators: [{ type: Directive, args: [{ selector: 'input[pghFinancialInput]', providers: [ { provide: MAT_INPUT_VALUE_ACCESSOR, useExisting: PghFinancialInputDirective }, { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => PghFinancialInputDirective), multi: true, }, ], standalone: false, }] }], ctorParameters: () => [{ type: i0.ElementRef }, { type: undefined, decorators: [{ type: Inject, args: [LOCALE_ID] }] }], propDecorators: { onInput: [{ type: HostListener, args: ['input', ['$event.target.value']] }], _onBlur: [{ type: HostListener, args: ['blur'] }] } }); const ZERO = ''; const DELIMITER = ' و '; const NEGATIVE = 'منفی '; const UNITS = [ '', 'یک', 'دو', 'سه', 'چهار', 'پنج', 'شش', 'هفت', 'هشت', 'نه', 'ده', 'یازده', 'دوازده', 'سیزده', 'چهارده', 'پانزده', 'شانزده', 'هفده', 'هجده', 'نوزده', 'بیست', ]; const TENS = ['', '', 'بیست', 'سی', 'چهل', 'پنجاه', 'شصت', 'هفتاد', 'هشتاد', 'نود']; const HUNDREDS = [ '', 'یکصد', 'دویست', 'سیصد', 'چهارصد', 'پانصد', 'ششصد', 'هفتصد', 'هشتصد', 'نهصد', ]; const SCALES = [ '', ' هزار', ' میلیون', ' میلیارد', ' بیلیون', ' بیلیارد', ' تریلیون', ' تریلیارد', ' کوآدریلیون', ' کادریلیارد', ' کوینتیلیون', ' کوانتینیارد', ' سکستیلیون', ' سکستیلیارد', ' سپتیلیون', ' سپتیلیارد', ' اکتیلیون', ' اکتیلیارد', ' نانیلیون', ' نانیلیارد', ' دسیلیون', ' دسیلیارد', ]; const DECIMAL_SUFFIXES = [ '', 'دهم', 'صدم', 'هزارم', 'ده‌هزارم', 'صد‌هزارم', 'میلیونوم', 'ده‌میلیونوم', 'صدمیلیونوم', 'میلیاردم', 'ده‌میلیاردم', 'صد‌‌میلیاردم', ]; class PghNumberToWordsService { constructor() { this.convertNumberToWords = (value) => { let input = value.toString().replace(/[^0-9.-]/g, ''); let isNegative = false; const floatParse = parseFloat(input); if (isNaN(floatParse)) { return ZERO; } if (floatParse < 0) { isNegative = true; input = input.replace(/-/g, ''); } let decimalPart = ''; let integerPart = input; const pointIndex = input.indexOf('.'); if (pointIndex > -1) { integerPart = input.substring(0, pointIndex); decimalPart = input.substring(pointIndex + 1, input.length); } if (integerPart.length > 66) { return 'خارج از محدوده'; } const slicedNumber = this.prepareNumber(integerPart); const output = []; for (let i = 0; i < slicedNumber.length; i += 1) { const converted = this.integerToWords(slicedNumber[i]); if (converted !== '') { output.push(converted + SCALES[slicedNumber.length - (i + 1)]); } } if (decimalPart.length > 0) { decimalPart = this.convertDecimalPart(decimalPart); } return (isNegative ? NEGATIVE : '') + output.join(DELIMITER) + decimalPart; }; this.prepareNumber = (num) => { let output = num; if (typeof output === 'number') { output = output.toString(); } if (output.length % 3 === 1) { output = `00${output}`; } else if (output.length % 3 === 2) { output = `0${output}`; } return output.replace(/\d{3}(?=\d)/g, '$&*').split('*'); }; this.integerToWords = (num) => { if (parseInt(num, 0) === 0) { return ''; } const parsedInt = parseInt(num, 0); if (parsedInt <= 20) { return UNITS[parsedInt]; } if (parsedInt < 100) { const ones = parsedInt % 10; const tens = (parsedInt - ones) / 10; if (ones > 0) { return TENS[tens] + DELIMITER + UNITS[ones]; } return TENS[tens]; } const ones = parsedInt % 10; const hundreds = (parsedInt - (parsedInt % 100)) / 100; const tens = (parsedInt - (hundreds * 100 + ones)) / 10; const output = [HUNDREDS[hundreds]]; const secondPart = tens * 10 + ones; if (secondPart === 0) { return output.join(DELIMITER); } if (secondPart <= 20) { output.push(UNITS[secondPart]); } else { output.push(TENS[tens]); if (ones > 0) { output.push(UNITS[ones]); } } return output.join(DELIMITER); }; this.convertDecimalPart = (decimalPart) => { decimalPart = decimalPart.replace(/0*$/, ''); if (decimalPart === '') { return ''; } const maxDecimalLength = DECIMAL_SUFFIXES.length - 1; if (decimalPart.length > maxDecimalLength) { decimalPart = decimalPart.substring(0, maxDecimalLength); } return (' ممیز ' + this.convertNumberToWords(decimalPart) + ' ' + DECIMAL_SUFFIXES[decimalPart.length]); }; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: PghNumberToWordsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: PghNumberToWordsService, providedIn: 'root' }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: PghNumberToWordsService, decorators: [{ type: Injectable, args: [{ providedIn: 'root', }] }], ctorParameters: () => [] }); class PghNumberToWordsPipe { constructor(pghNumberToWordsService) { this.pghNumberToWordsService = pghNumberToWordsService; } transform(number) { return this.pghNumberToWordsService.convertNumberToWords(number); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: PghNumberToWordsPipe, deps: [{ token: PghNumberToWordsService }], target: i0.ɵɵFactoryTarget.Pipe }); } static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.13", ngImport: i0, type: PghNumberToWordsPipe, isStandalone: false, name: "pghNumberToWords" }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: PghNumberToWordsPipe, decorators: [{ type: Pipe, args: [{ name: 'pghNumberToWords', standalone: false, }] }], ctorParameters: () => [{ type: PghNumberToWordsService }] }); class PghMoneyToWordsPipe { constructor(pghNumberToWordsService) { this.pghNumberToWordsService = pghNumberToWordsService; } transform(number) { if (Number(number) === 0) return ''; const value = isNaN(number) ? Number(number) : number; const tomanPart = value > 9 ? `${this.pghNumberToWordsService.convertNumberToWords(Math.floor(value / 10))} تومان` : ''; const rialPart = value % 10 > 0 ? `${this.pghNumberToWordsService.convertNumberToWords(value % 10)} ریال` : ''; return tomanPart && rialPart ? tomanPart + ' و ' + rialPart : tomanPart ? tomanPart : rialPart; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: PghMoneyToWordsPipe, deps: [{ token: PghNumberToWordsService }], target: i0.ɵɵFactoryTarget.Pipe }); } static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.13", ngImport: i0, type: PghMoneyToWordsPipe, isStandalone: false, name: "pghMoneyToWords" }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: PghMoneyToWordsPipe, decorators: [{ type: Pipe, args: [{ name: 'pghMoneyToWords', standalone: false, }] }], ctorParameters: () => [{ type: PghNumberToWordsService }] }); class PghRialToTomanPipe { transform(number) { if (!number) return 0; const value = isNaN(number) ? Number(number) : number; return Math.floor(value / 10); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: PghRialToTomanPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); } static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.13", ngImport: i0, type: PghRialToTomanPipe, isStandalone: false, name: "pghRialToToman" }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: PghRialToTomanPipe, decorators: [{ type: Pipe, args: [{ name: 'pghRialToToman', standalone: false, }] }] }); class PghInputModule { static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: PghInputModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); } static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.13", ngImport: i0, type: PghInputModule, declarations: [PghInputTypeDirective, PghFieldErrorDirective, PghMarkAllAsTouchedDirective, PghPersianNumbersToEnglishDirective, PghFinancialInputDirective, PghNumberToWordsPipe, PghMoneyToWordsPipe, PghRialToTomanPipe], imports: [CommonModule], exports: [PghInputTypeDirective, PghFieldErrorDirective, PghMarkAllAsTouchedDirective, PghPersianNumbersToEnglishDirective, PghFinancialInputDirective, PghNumberToWordsPipe, PghMoneyToWordsPipe, PghRialToTomanPipe] }); } static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: PghInputModule, imports: [CommonModule] }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: PghInputModule, decorators: [{ type: NgModule, args: [{ declarations: [ PghInputTypeDirective, PghFieldErrorDirective, PghMarkAllAsTouchedDirective, PghPersianNumbersToEnglishDirective, PghFinancialInputDirective, PghNumberToWordsPipe, PghMoneyToWordsPipe, PghRialToTomanPipe, ], imports: [CommonModule], exports: [ PghInputTypeDirective, PghFieldErrorDirective, PghMarkAllAsTouchedDirective, PghPersianNumbersToEnglishDirective, PghFinancialInputDirective, PghNumberToWordsPipe, PghMoneyToWordsPipe, PghRialToTomanPipe, ], }] }] }); // @dynamic class PghFormValidators { static { this.URL_REGEX = /^https?:\/\/.*\..*$/i; } static { this.ENTITY_REGEX = /^(.*)(:\/\/)(.*)$/i; } static { this.PHONE_NUMBER_REGEX = /^\+*\(?\d{1,4}\)?[\d ./-]*$/i; } /** * FormGroup Validator * * ```typescript * this.formBuilder.group({ * password: [], * confirmPassword: [], * }, { * validators: [PghFormValidators.matchPassword] * }) * ``` * * @param passwordField * @param confirmField */ static matchPassword(passwordField, confirmField) { return (formGroup) => { const field1 = formGroup.get(passwordField); const field2 = formGroup.get(confirmField); const password = field1?.value; const confirmPassword = field2?.value; return password !== confirmPassword ? { mismatchPassword: true } : undefined; }; } static urlValidator() { return PghFormValidators.pattern(PghFormValidators.URL_REGEX, 'url'); } /** * Validates an android entity. Example: any://any */ static entityValidator() { return PghFormValidators.pattern(PghFormValidators.ENTITY_REGEX, 'entity'); } static phoneNumberValidator() { return PghFormValidators.pattern(PghFormValidators.PHONE_NUMBER_REGEX, 'phoneNumber'); } /** * Uppercase letters aren't allowed */ static noUppercase() { return PghFormValidators.pattern(/^[^A-Z]*$/, 'uppercase'); } static postalCode() { return PghFormValidators.pattern(/^[0-9]{10}/, 'postalCode'); } static shaba(includeIR = true) { return PghFormValidators.pattern(includeIR ? /^IR\d{24}$/ : /^\d{24}$/, includeIR ? 'shebaIr' : 'sheba'); } static debitCard() { return PghFormValidators.pattern(/^\d{16}$/, 'debitCard'); } /** * Runs the validator only if the condition function returns true * you can optionally include an elseValidator * @param condition * @param validator * @param elseValidator */ static conditionalValidator(condition, validator, elseValidator) { return (control) => { if (condition()) { return validator(control); } return elseValidator ? elseValidator(control) : null; }; } /** * Validates a given condition function is true. If it's not, It'll be invalid with the errorName provided * @param condition * @param errorName */ static validateCondition(condition, errorName) { return (control) => condition(control) ? null : { [errorName]: { value: control.value } }; } /** * Validates the value is not any of the given options * @param forbiddenValues */ static forbiddenValues(forbiddenValues) { return (control) => forbiddenValues.includes(control.value) ? { forbiddenOption: { value: control.value } } : null; } /** * Validates the value is one of the given options * @param allowedValues */ static allowedValues(allowedValues) { return (control) => { if (!control.value) return null; return allowedValues.includes(control.value) ? null : { unknownOption: { value: control.value } }; }; } /** * Same as the angular pattern validator but with a custom errorName. * This is useful when you want to check multiple patterns against a control and * display different error messages for each pattern * @param regex Regex to check * @param errorName a custom error name */ static pattern(regex, errorName) { return (control) => { if (!control.value || typeof control.value !== 'string') return null; return regex.exec(control.value) ? null : { [errorName]: { value: control.value } }; }; } /** * Opposite of the pattern validator * @param regex Regex to check * @param errorName a custom error name */ static forbiddenPattern(regex, errorName) { return (control) => { if (!control.value || typeof control.value !== 'string') return null; return regex.exec(control.value) ? { [errorName]: { value: control.value } } : null; }; } static iranianNationalCode() { return PghFormValidators.pattern(/^(\d{10}|\d{12})$/, 'nationalCode'); } static hasNumber() { return PghFormValidators.pattern(/\d/, 'hasNumber'); } static hasCapitalCase() { return PghFormValidators.pattern(/[A-Z]/, 'hasCapitalCase'); } static hasSmallCase() { return PghFormValidators.pattern(/[a-z]/, 'hasSmallCase'); } } class PghAutofocusDirective { constructor(el) { this.el = el; } ngAfterViewInit() { setTimeout(() => { this.el.nativeElement?.focus?.(); }); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: PghAutofocusDirective, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive }); } static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.13", type: PghAutofocusDirective, isStandalone: false, selector: "[pghAutofocus]", ngImport: i0 }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: PghAutofocusDirective, decorators: [{ type: Directive, args: [{ selector: '[pghAutofocus]', standalone: false, }] }], ctorParameters: () => [{ type: i0.ElementRef }] }); class PghAutofocusModule { static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: PghAutofocusModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); } static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.13", ngImport: i0, type: PghAutofocusModule, declarations: [PghAutofocusDirective], imports: [CommonModule], exports: [PghAutofocusDirective] }); } static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: PghAutofocusModule, imports: [CommonModule] }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.13", ngImport: i0, type: PghAutofocusModule, decorators: [{ type: NgModule, args: [{ declarations: [PghAutofocusDirective], imports: [CommonModule], exports: [PghAutofocusDirective], }] }] }); class PghFileValidators { static { this.NAME_VALIDATOR_PATTERN = /^[~`!@#$%^&*()_+=[\]\\{}|;':",.\/<>?a-zA-Z0-9-]{1,60}$/i; } static { this.messages = PGH_DEFAULT_ERROR_MESSAGES; } static checkAllowedTypes(acceptableTypes, fileType) { const acceptedTypesWithStar = acceptableTypes .filter(t => t.includes('*')) .map(type => type.split('/')[0]); const acceptedTypesWithoutStar = acceptableTypes.filter(t => !t.includes('*')); const splitFileType = fileType.split('/')[0]; if (!acceptedTypesWithoutStar.includes(fileType) && !acceptedTypesWithStar.includes(splitFileType)) { return this.messages.forbiddenFileType; } return null; } static checkNameValidator(fileName) { if (!PghFileValidators.NAME_VALIDATOR_PATTERN.test(fileName)) return this.messages.forbiddenFileName; return null; } static checkSizeValidation(maxSize, fileSize) { if (maxSize * 1024 < fileSize / 1024) return this.messages.illegalSize; return null; } } /** * Generated bundle index. Do not edit. */ export { PGH_DEFAULT_ERROR_MESSAGES, PGH_FIELD_ERROR_MESSAGES, PghAutofocusDirective, PghAutofocusModule, PghFieldErrorDirective, PghFileValidators, PghFinancialInputDirective, PghFormValidators, PghInputModule, PghInputTypeDirective, PghMarkAllAsTouchedDirective, PghMoneyToWordsPipe, PghNumberToWordsPipe, PghNumberToWordsService, PghPersianNumbersToEnglishDirective, PghRialToTomanPipe }; //# sourceMappingURL=tapsellorg-angular-material-library-src-lib-input.mjs.map