@corp-products/ui-components 4.1.4 → 4.1.6

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.
@@ -45,7 +45,7 @@ import * as i1$5 from 'primeng/toggleswitch';
45
45
  import { ToggleSwitchModule } from 'primeng/toggleswitch';
46
46
  import * as i1$6 from '@ng-bootstrap/ng-bootstrap';
47
47
  import { NgbDatepickerI18n, NgbCalendarIslamicUmalqura, NgbDatepickerModule, NgbCalendar, NgbCalendarGregorian, NgbDate } from '@ng-bootstrap/ng-bootstrap';
48
- import { trigger, state, style, transition, animate } from '@angular/animations';
48
+ import { trigger, state, transition, style, animate } from '@angular/animations';
49
49
  import '@angular/localize/init';
50
50
  import * as i2$4 from 'primeng/accordion';
51
51
  import { AccordionModule } from 'primeng/accordion';
@@ -703,6 +703,42 @@ class FormUtils {
703
703
  }
704
704
  }
705
705
 
706
+ /**
707
+ * Validator function to check if the control value is a valid email address.
708
+ * @returns A validator function that checks if the value is a valid email address.
709
+ */
710
+ function emailStcValidator(allowedDomains) {
711
+ return (control) => {
712
+ const value = control.value;
713
+ if (!value)
714
+ return null;
715
+ const emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
716
+ // Helper function to check if email is from allowed domain
717
+ const isFromAllowedDomain = (email) => {
718
+ const domain = email.split('@')[1]?.toLowerCase();
719
+ return allowedDomains.some((allowedDomain) => domain === allowedDomain.toLowerCase());
720
+ };
721
+ // Helper function to validate a single email
722
+ const validateEmail = (email) => {
723
+ return emailPattern.test(email);
724
+ };
725
+ if (Array.isArray(value)) {
726
+ // Check if all emails are from allowed domains
727
+ const allFromAllowedDomains = value.every((email) => typeof email === 'string' && isFromAllowedDomain(email));
728
+ if (!allFromAllowedDomains) {
729
+ return { emailDomain: true };
730
+ }
731
+ // Validate each email
732
+ const allValid = value.every((email) => typeof email === 'string' && validateEmail(email));
733
+ return allValid ? null : { emailDomain: true };
734
+ }
735
+ // Single email validation (must match pattern AND be from allowed domain)
736
+ const isValid = typeof value === 'string' && validateEmail(value);
737
+ const allowed = typeof value === 'string' && isFromAllowedDomain(value);
738
+ return isValid && allowed ? null : { emailDomain: true };
739
+ };
740
+ }
741
+
706
742
  var BasicErrorKeysEnum;
707
743
  (function (BasicErrorKeysEnum) {
708
744
  BasicErrorKeysEnum["required"] = "REQUIRED";
@@ -719,6 +755,7 @@ var BasicErrorKeysEnum;
719
755
  BasicErrorKeysEnum["fileSelected"] = "FILE_SELECTED";
720
756
  BasicErrorKeysEnum["default"] = "DEFAULT";
721
757
  BasicErrorKeysEnum["numbersOnly"] = "NUMBERS_ONLY";
758
+ BasicErrorKeysEnum["invalidSaudiPhoneNumber"] = "INVALID_SAUDI_PHONE_NUMBER";
722
759
  })(BasicErrorKeysEnum || (BasicErrorKeysEnum = {}));
723
760
  var ErrorsWithValuesKeysEnum;
724
761
  (function (ErrorsWithValuesKeysEnum) {
@@ -729,6 +766,7 @@ var ErrorsWithValuesKeysEnum;
729
766
  ErrorsWithValuesKeysEnum["maxSize"] = "MAX_SIZE";
730
767
  ErrorsWithValuesKeysEnum["maxFiles"] = "MAX_FILES";
731
768
  ErrorsWithValuesKeysEnum["allowedTypes"] = "ALLOWED_TYPES";
769
+ ErrorsWithValuesKeysEnum["maxRepeatedChars"] = "MAX_REPEATED_CHARS";
732
770
  })(ErrorsWithValuesKeysEnum || (ErrorsWithValuesKeysEnum = {}));
733
771
 
734
772
  class FormValidationService {
@@ -763,6 +801,9 @@ class FormValidationService {
763
801
  requiredLength: val?.requiredLength,
764
802
  actualLength: val?.actualLength,
765
803
  }),
804
+ maxRepeatedChars: (val) => this.getTranslation(ErrorsWithValuesKeysEnum.maxRepeatedChars, {
805
+ maxRepeats: val?.maxRepeats,
806
+ }),
766
807
  min: (val) => this.getTranslation(ErrorsWithValuesKeysEnum.min, { min: val?.min }),
767
808
  max: (val) => this.getTranslation(ErrorsWithValuesKeysEnum.max, { max: val?.max }),
768
809
  maxSize: (val) => this.getTranslation(ErrorsWithValuesKeysEnum.maxSize, { size: val?.requiredLength }),
@@ -781,6 +822,57 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImpo
781
822
  }]
782
823
  }] });
783
824
 
825
+ function numbersOnlyValidator(control) {
826
+ const value = control.value;
827
+ if (value === null || value === undefined || value === '') {
828
+ return null;
829
+ }
830
+ const isNumbersOnly = /^[0-9]+$/.test(value);
831
+ return isNumbersOnly ? null : { numbersOnly: true };
832
+ }
833
+
834
+ function maxRepeatedCharsValidator(maxRepeats = 3) {
835
+ return (control) => {
836
+ const value = control.value;
837
+ if (!value)
838
+ return null;
839
+ const str = value.toString();
840
+ let count = 1;
841
+ for (let i = 1; i < str.length; i++) {
842
+ if (str[i] === str[i - 1]) {
843
+ count++;
844
+ if (count > maxRepeats) {
845
+ return { maxRepeatedChars: { maxRepeats } };
846
+ }
847
+ }
848
+ else {
849
+ count = 1;
850
+ }
851
+ }
852
+ return null;
853
+ };
854
+ }
855
+
856
+ /**
857
+ * Validator to check if the control value is a valid Saudi phone number.
858
+ * Valid formats: 05XXXXXXXX (10 digits) or 009665XXXXXXXX (14 digits)
859
+ */
860
+ function saudiPhoneValidator() {
861
+ return (control) => {
862
+ let value = control.value;
863
+ if (!value)
864
+ return null;
865
+ // Convert to string and trim spaces
866
+ value = value.toString().trim();
867
+ // Regex: accepts 05XXXXXXXX or 009665XXXXXXXX
868
+ const saudiPhoneRegex = /^(?:05\d{8}|009665\d{8})$/;
869
+ if (!saudiPhoneRegex.test(value)) {
870
+ return { invalidSaudiPhoneNumber: true };
871
+ }
872
+ return null;
873
+ };
874
+ }
875
+
784
876
  class ValidationErrorsPipe {
785
877
  formValidationService = inject(FormValidationService);
786
878
  // allowed keys here to handle errors in case of cross-validators like startDate and endDate validators,
@@ -806,51 +898,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.15", ngImpo
806
898
  }]
807
899
  }] });
808
900
 
809
- function numbersOnlyValidator(control) {
810
- const value = control.value;
811
- if (value === null || value === undefined || value === '') {
812
- return null;
813
- }
814
- const isNumbersOnly = /^[0-9]+$/.test(value);
815
- return isNumbersOnly ? null : { numbersOnly: true };
816
- }
817
-
818
- /**
819
- * Validator function to check if the control value is a valid email address.
820
- * @returns A validator function that checks if the value is a valid email address.
821
- */
822
- function emailStcValidator(allowedDomains) {
823
- return (control) => {
824
- const value = control.value;
825
- if (!value)
826
- return null;
827
- const emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
828
- // Helper function to check if email is from allowed domain
829
- const isFromAllowedDomain = (email) => {
830
- const domain = email.split('@')[1]?.toLowerCase();
831
- return allowedDomains.some((allowedDomain) => domain === allowedDomain.toLowerCase());
832
- };
833
- // Helper function to validate a single email
834
- const validateEmail = (email) => {
835
- return emailPattern.test(email);
836
- };
837
- if (Array.isArray(value)) {
838
- // Check if all emails are from allowed domains
839
- const allFromAllowedDomains = value.every((email) => typeof email === 'string' && isFromAllowedDomain(email));
840
- if (!allFromAllowedDomains) {
841
- return { emailDomain: true };
842
- }
843
- // Validate each email
844
- const allValid = value.every((email) => typeof email === 'string' && validateEmail(email));
845
- return allValid ? null : { emailDomain: true };
846
- }
847
- // Single email validation (must match pattern AND be from allowed domain)
848
- const isValid = typeof value === 'string' && validateEmail(value);
849
- const allowed = typeof value === 'string' && isFromAllowedDomain(value);
850
- return isValid && allowed ? null : { emailDomain: true };
851
- };
852
- }
853
-
854
901
  class AutoCompleteComponent extends BaseInputComponent {
855
902
  selectedItemTemplate = null;
856
903
  // eslint-disable-next-line @angular-eslint/no-output-on-prefix
@@ -2883,5 +2930,5 @@ const notFutureDateValidator = (dateKey) => (control) => {
2883
2930
  * Generated bundle index. Do not edit.
2884
2931
  */
2885
2932
 
2886
- export { AlertDialogComponent, AlertDialogService, AppAccordionComponent, AppBreadcrumbComponent, AppButtonComponent, AppDropdownMenuComponent, AppTabsComponent, AutoCompleteComponent, BasicErrorKeysEnum, BottomSheetComponent, ConfirmationDialogComponent, ConfirmationDialogService, DatePickerComponent, DualCalendarComponent, DynamicFormComponent, DynamicSidebarService, DynamicSidebarV2Service, ErrorsWithValuesKeysEnum, FormFieldTypeEnum, FormUtils, FormValidationService, IcoMoonIconComponent, InputComponent, MONTHS_GREGORIAN, MONTHS_HIJRI, ReadMoreComponent, SelectButtonComponent, SelectComponent, SideBarComponent, SidebarConfigDefaults, SwitchComponent, UploadStatus, UserAutocompleteCardComponent, UserInfoComponent, ValidationErrorsPipe, WEEKDAYS, dateRangeValidator, emailStcValidator, getGregorianMonthName, getHijriMonthName, getWeekdayName, notFutureDateValidator, numbersOnlyValidator };
2933
+ export { AlertDialogComponent, AlertDialogService, AppAccordionComponent, AppBreadcrumbComponent, AppButtonComponent, AppDropdownMenuComponent, AppTabsComponent, AutoCompleteComponent, BasicErrorKeysEnum, BottomSheetComponent, ConfirmationDialogComponent, ConfirmationDialogService, DatePickerComponent, DualCalendarComponent, DynamicFormComponent, DynamicSidebarService, DynamicSidebarV2Service, ErrorsWithValuesKeysEnum, FormFieldTypeEnum, FormUtils, FormValidationService, IcoMoonIconComponent, InputComponent, MONTHS_GREGORIAN, MONTHS_HIJRI, ReadMoreComponent, SelectButtonComponent, SelectComponent, SideBarComponent, SidebarConfigDefaults, SwitchComponent, UploadStatus, UserAutocompleteCardComponent, UserInfoComponent, ValidationErrorsPipe, WEEKDAYS, dateRangeValidator, emailStcValidator, getGregorianMonthName, getHijriMonthName, getWeekdayName, maxRepeatedCharsValidator, notFutureDateValidator, numbersOnlyValidator, saudiPhoneValidator };
2887
2934
  //# sourceMappingURL=corp-products-ui-components.mjs.map