@ibragim-dev-org/ui-forge-library 1.4.53 → 1.4.54

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.
@@ -7,7 +7,6 @@ import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
7
7
  import { isPlatformBrowser, DOCUMENT, NgStyle } from '@angular/common';
8
8
  import { throttleTime, tap as tap$1, takeUntil, debounceTime as debounceTime$1 } from 'rxjs/operators';
9
9
  import * as i2 from '@angular/platform-browser';
10
- import { PhoneNumberUtil, AsYouTypeFormatter } from 'google-libphonenumber';
11
10
  import { ulid } from 'ulid';
12
11
  import * as i1 from '@angular/cdk/overlay';
13
12
  import { OverlayConfig, FlexibleConnectedPositionStrategy } from '@angular/cdk/overlay';
@@ -1250,6 +1249,7 @@ class CountryService {
1250
1249
  static regionNames = null;
1251
1250
  static _supportedRegions = null;
1252
1251
  static _countries = null;
1252
+ static modulePromise = null;
1253
1253
  static flagOverrides = {
1254
1254
  AC: 'sh-ac',
1255
1255
  TA: 'sh-ta',
@@ -1265,33 +1265,42 @@ class CountryService {
1265
1265
  SX: 'sx',
1266
1266
  MF: 'mf',
1267
1267
  };
1268
+ static async loadLibphonenumber() {
1269
+ if (!this.modulePromise) {
1270
+ this.modulePromise = import('google-libphonenumber');
1271
+ }
1272
+ return this.modulePromise;
1273
+ }
1268
1274
  // Lazy initializer for phoneUtil
1269
- static getPhoneUtil() {
1275
+ static async getPhoneUtil() {
1270
1276
  if (!this.phoneUtil) {
1277
+ const { PhoneNumberUtil } = await this.loadLibphonenumber();
1271
1278
  this.phoneUtil = PhoneNumberUtil.getInstance();
1272
1279
  }
1273
1280
  return this.phoneUtil;
1274
1281
  }
1275
1282
  // Lazy initializer for regionNames
1276
- static getRegionNames() {
1283
+ static async getRegionNames() {
1277
1284
  if (!this.regionNames) {
1278
1285
  this.regionNames = new Intl.DisplayNames(['en'], { type: 'region' });
1279
1286
  }
1280
1287
  return this.regionNames;
1281
1288
  }
1282
1289
  // Lazy initializer for supported regions
1283
- static getSupportedRegions() {
1290
+ static async getSupportedRegions() {
1284
1291
  if (!this._supportedRegions) {
1285
- this._supportedRegions = this.getPhoneUtil().getSupportedRegions();
1292
+ const phoneUtil = await this.getPhoneUtil();
1293
+ this._supportedRegions = phoneUtil.getSupportedRegions();
1286
1294
  }
1287
1295
  return this._supportedRegions;
1288
1296
  }
1289
1297
  // Lazy initializer for countries
1290
- static getCountries() {
1298
+ static async getCountries() {
1291
1299
  if (!this._countries) {
1292
- const phoneUtil = this.getPhoneUtil();
1293
- const regionNames = this.getRegionNames();
1294
- this._countries = this.getSupportedRegions().map((code) => {
1300
+ const phoneUtil = await this.getPhoneUtil();
1301
+ const regionNames = await this.getRegionNames();
1302
+ const supportedRegions = await this.getSupportedRegions();
1303
+ this._countries = supportedRegions.map((code) => {
1295
1304
  const name = regionNames.of(code) ?? '';
1296
1305
  const isoCode = (this.flagOverrides[code] ?? code).toLowerCase();
1297
1306
  const phonePrefix = '+' + phoneUtil.getCountryCodeForRegion(code);
@@ -1306,7 +1315,8 @@ class CountryService {
1306
1315
  return this._countries;
1307
1316
  }
1308
1317
  // Format phone number lazily
1309
- static formatPhoneNumber(raw, countryCode) {
1318
+ static async formatPhoneNumber(raw, countryCode) {
1319
+ const { AsYouTypeFormatter } = await this.loadLibphonenumber();
1310
1320
  const formatter = new AsYouTypeFormatter(countryCode);
1311
1321
  let formatted = '';
1312
1322
  for (const digit of raw) {
@@ -1315,8 +1325,9 @@ class CountryService {
1315
1325
  return formatted;
1316
1326
  }
1317
1327
  // Lookup country lazily
1318
- static getCountryByCode(code) {
1319
- return this.getCountries().find((v) => v.code === code.toUpperCase());
1328
+ static async getCountryByCode(code) {
1329
+ const countries = await this.getCountries();
1330
+ return countries.find((v) => v.code === code.toUpperCase());
1320
1331
  }
1321
1332
  }
1322
1333
 
@@ -3926,21 +3937,23 @@ class UiInputCountryDirective extends UiInputDirective {
3926
3937
  super(elementRef, renderer);
3927
3938
  }
3928
3939
  ngAfterViewInit() {
3929
- this.autoSetCountry();
3940
+ void this.autoSetCountry();
3930
3941
  }
3931
3942
  onPaste(event) {
3932
3943
  event.preventDefault();
3933
- const pastedText = event.clipboardData?.getData('text') || '';
3934
- const country = this.searchCountry(pastedText);
3944
+ void this.handlePaste(event.clipboardData?.getData('text') || '');
3945
+ }
3946
+ async handlePaste(pastedText) {
3947
+ const country = await this.searchCountry(pastedText);
3935
3948
  if (country) {
3936
3949
  this.setCountry(country);
3937
3950
  return;
3938
3951
  }
3939
3952
  this.onInput(this.value() + pastedText);
3940
3953
  }
3941
- searchCountry(temp) {
3942
- const country = CountryService.getCountries().find((c) => c.name.toLowerCase().includes(temp.toLowerCase()));
3943
- return country;
3954
+ async searchCountry(temp) {
3955
+ const countries = await CountryService.getCountries();
3956
+ return countries.find((c) => c.name.toLowerCase().includes(temp.toLowerCase()));
3944
3957
  }
3945
3958
  setCountry(country) {
3946
3959
  this.$selectedCountry.set(country);
@@ -3950,7 +3963,7 @@ class UiInputCountryDirective extends UiInputDirective {
3950
3963
  inputElement.focus();
3951
3964
  }
3952
3965
  }
3953
- autoSetCountry() {
3966
+ async autoSetCountry() {
3954
3967
  const value = this.value();
3955
3968
  if (!value?.length) {
3956
3969
  this.$selectedCountry.set({
@@ -3961,7 +3974,7 @@ class UiInputCountryDirective extends UiInputDirective {
3961
3974
  });
3962
3975
  return;
3963
3976
  }
3964
- const country = this.searchCountry(value);
3977
+ const country = await this.searchCountry(value);
3965
3978
  if (country) {
3966
3979
  this.$selectedCountry.set(country);
3967
3980
  }
@@ -4133,13 +4146,19 @@ class UIPhoneNumberDirective extends UiInputDirective {
4133
4146
  super(elementRef, renderer);
4134
4147
  }
4135
4148
  ngAfterViewInit() {
4136
- const selectedCountry = CountryService.getCountryByCode('US') ?? emptyCountry;
4149
+ void this.initSelectedCountry();
4150
+ }
4151
+ async initSelectedCountry() {
4152
+ const selectedCountry = (await CountryService.getCountryByCode('US')) ?? emptyCountry;
4137
4153
  this.$selectedCountry.set(selectedCountry);
4138
4154
  this.$countryCode.set(selectedCountry.phonePrefix + ' ');
4139
4155
  }
4140
4156
  onInput(value) {
4157
+ void this.formatInput(value);
4158
+ }
4159
+ async formatInput(value) {
4141
4160
  const digitsOnly = value.replace(/\D/g, '');
4142
- const formattedValue = CountryService.formatPhoneNumber(digitsOnly, this.$selectedCountry().code);
4161
+ const formattedValue = await CountryService.formatPhoneNumber(digitsOnly, this.$selectedCountry().code);
4143
4162
  super.onInput(formattedValue);
4144
4163
  const inputElement = this.$inputElement()?.nativeElement;
4145
4164
  if (inputElement) {
@@ -4148,8 +4167,11 @@ class UIPhoneNumberDirective extends UiInputDirective {
4148
4167
  }
4149
4168
  onPaste(event) {
4150
4169
  event.preventDefault();
4151
- const pastedText = event.clipboardData?.getData('text') || '';
4152
- const country = CountryService.getCountries().find((c) => pastedText.startsWith(c.phonePrefix));
4170
+ void this.handlePaste(event.clipboardData?.getData('text') || '');
4171
+ }
4172
+ async handlePaste(pastedText) {
4173
+ const countries = await CountryService.getCountries();
4174
+ const country = countries.find((c) => pastedText.startsWith(c.phonePrefix));
4153
4175
  if (country) {
4154
4176
  const localNumber = pastedText.slice(country.phonePrefix.length);
4155
4177
  this.setCountry(country);