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

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
 
@@ -2287,6 +2298,7 @@ class UiModal {
2287
2298
  backdropPortalRef;
2288
2299
  destroyDownloading$ = new Subject();
2289
2300
  destroyOutsideClickSubscription$ = new Subject();
2301
+ $isOpen = signal(false, ...(ngDevMode ? [{ debugName: "$isOpen" }] : []));
2290
2302
  constructor(overlay, injector, destroyRef, router, backdropService) {
2291
2303
  this.overlay = overlay;
2292
2304
  this.injector = injector;
@@ -2294,99 +2306,61 @@ class UiModal {
2294
2306
  this.router = router;
2295
2307
  this.backdropService = backdropService;
2296
2308
  }
2297
- /**
2298
- * Closes the last opened popup.
2299
- */
2300
2309
  close() {
2301
2310
  if (this.instances.length >= 1) {
2302
2311
  this.instances[this.instances.length - 1].close();
2303
2312
  this.instances.pop();
2304
- if (!this.instances.length) {
2313
+ this.$isOpen.set(this.instances.length > 0);
2314
+ if (!this.instances.length)
2305
2315
  this.destroy();
2306
- }
2307
2316
  }
2308
2317
  }
2309
- /**
2310
- * Closes a popup by its index in the instances array.
2311
- *
2312
- * @param index - The index of the popup to close.
2313
- */
2314
2318
  closeByIndex(index) {
2315
2319
  this.instances[index].close();
2316
2320
  this.instances.splice(index, 1);
2317
- if (!this.instances.length) {
2321
+ this.$isOpen.set(this.instances.length > 0);
2322
+ if (!this.instances.length)
2318
2323
  this.destroy();
2319
- }
2320
2324
  }
2321
- /**
2322
- * Closes a popup by its unique identifier.
2323
- *
2324
- * @param id - The unique identifier of the popup to close.
2325
- */
2326
2325
  closeById(id) {
2327
- const dropDownIndex = this.instances.findIndex((v) => v.id === id);
2328
- if (dropDownIndex >= 0) {
2329
- this.closeByIndex(dropDownIndex);
2330
- }
2326
+ const index = this.instances.findIndex((v) => v.id === id);
2327
+ if (index >= 0)
2328
+ this.closeByIndex(index);
2331
2329
  }
2332
- /**
2333
- * Closes all currently opened popups.
2334
- */
2335
2330
  closeAll() {
2336
- this.instances.forEach((element) => {
2337
- element.close();
2338
- });
2331
+ this.instances.forEach((i) => i.close());
2339
2332
  this.instances = [];
2333
+ this.$isOpen.set(false);
2340
2334
  this.destroy();
2341
2335
  }
2342
- /**
2343
- * Creates a popup instance with the specified component and options.
2344
- *
2345
- * @param overlayRef - The overlay reference for the popup.
2346
- * @param component - The component to be displayed in the popup.
2347
- * @param options - Configuration options for the popup, including inputs.
2348
- * @param id - A unique identifier for the popup instance.
2349
- * @param parameters - (Optional) Configuration options for the popup.
2350
- */
2351
2336
  createPopup(overlayRef, component, options, id, parameters) {
2352
2337
  const newParameters = this.fetchParameters(parameters);
2353
2338
  const uiPopupInstance = new UiPopupInstance(overlayRef, this.destroyRef, options.onClose, newParameters.animationOptions);
2354
- if (newParameters.width > 0) {
2339
+ if (newParameters.width > 0)
2355
2340
  uiPopupInstance.width = newParameters.width;
2356
- }
2357
2341
  const injector = Injector.create({
2358
2342
  parent: this.injector,
2359
2343
  providers: [{ provide: UiPopupInstance, useValue: uiPopupInstance }],
2360
2344
  });
2361
2345
  const componentRef = overlayRef.attach(new ComponentPortal(component, undefined, injector));
2362
- if (options) {
2363
- if (options.inputs) {
2364
- Object.keys(options.inputs).forEach((key) => {
2365
- if (options.inputs) {
2366
- componentRef.setInput(key, options.inputs[key]);
2367
- }
2368
- });
2369
- }
2346
+ if (options?.inputs) {
2347
+ Object.keys(options.inputs).forEach((key) => {
2348
+ componentRef.setInput(key, options.inputs[key]);
2349
+ });
2370
2350
  }
2371
2351
  uiPopupInstance.id = id;
2372
2352
  this.instances.push(uiPopupInstance);
2353
+ this.$isOpen.set(true);
2373
2354
  }
2374
- /**
2375
- * Subscribes to outside events (e.g., scroll, router events) to close popups.
2376
- */
2377
2355
  subscribeToOutsideEvents() {
2378
2356
  this.destroyOutsideClickSubscription$.next();
2379
2357
  if (isBrowser()) {
2380
2358
  fromEvent(window, 'scroll')
2381
- .pipe(tap(() => {
2382
- this.closeAll();
2383
- }), takeUntil$1(this.destroyOutsideClickSubscription$))
2359
+ .pipe(tap(() => this.closeAll()), takeUntil$1(this.destroyOutsideClickSubscription$))
2384
2360
  .subscribe();
2385
2361
  }
2386
2362
  this.router.events
2387
- .pipe(debounceTime(100), tap(() => {
2388
- this.closeAll();
2389
- }), takeUntil$1(this.destroyOutsideClickSubscription$))
2363
+ .pipe(debounceTime(100), tap(() => this.closeAll()), takeUntil$1(this.destroyOutsideClickSubscription$))
2390
2364
  .subscribe();
2391
2365
  }
2392
2366
  destroy() {
@@ -2394,12 +2368,10 @@ class UiModal {
2394
2368
  this.destroyOutsideClickSubscription$.next();
2395
2369
  }
2396
2370
  showBackdrop(isStaticBackdrop = false) {
2397
- if (isBrowser()) {
2371
+ if (isBrowser())
2398
2372
  document.body.style.setProperty('overflow-y', 'hidden');
2399
- }
2400
- if (this.backdropRef) {
2373
+ if (this.backdropRef)
2401
2374
  return;
2402
- }
2403
2375
  this.backdropRef = this.overlay.create({
2404
2376
  hasBackdrop: false,
2405
2377
  positionStrategy: this.overlay.position().global().centerHorizontally().centerVertically(),
@@ -2417,9 +2389,8 @@ class UiModal {
2417
2389
  }
2418
2390
  }
2419
2391
  hideBackdrop() {
2420
- if (!this.backdropRef) {
2392
+ if (!this.backdropRef)
2421
2393
  return;
2422
- }
2423
2394
  if (this.backdropPortalRef) {
2424
2395
  this.backdropPortalRef.location.nativeElement.classList.remove('animate-in');
2425
2396
  this.backdropPortalRef.location.nativeElement.classList.add('animate-out');
@@ -2429,35 +2400,26 @@ class UiModal {
2429
2400
  this.backdropRef?.detach();
2430
2401
  this.backdropRef?.dispose();
2431
2402
  this.backdropRef = undefined;
2432
- if (isBrowser()) {
2403
+ if (isBrowser())
2433
2404
  document.body.style.setProperty('overflow-y', 'auto');
2434
- }
2435
2405
  }))
2436
2406
  .subscribe();
2437
2407
  }
2438
- /**
2439
- * Fetches and normalizes popup parameters.
2440
- *
2441
- * @param parameters - Partial configuration options for the popup.
2442
- * @returns A complete set of popup parameters with default values applied.
2443
- */
2444
2408
  fetchParameters(parameters) {
2445
2409
  return {
2446
- animationOptions: parameters.animationOptions === undefined
2447
- ? {
2448
- startOrigin: 'center center',
2449
- endOrigin: 'center center',
2450
- start: 'scale(0.8)',
2451
- end: 'scale(1)',
2452
- leftStart: '0px',
2453
- leftEnd: '0',
2454
- topStart: '0px',
2455
- topEnd: '0',
2456
- }
2457
- : parameters.animationOptions,
2458
- isClosePrevious: parameters.isClosePrevious === undefined ? false : parameters.isClosePrevious,
2459
- isStaticBackdrop: parameters.isStaticBackdrop === undefined ? false : parameters.isStaticBackdrop,
2460
- width: parameters.width === undefined ? 0 : parameters.width,
2410
+ animationOptions: parameters.animationOptions ?? {
2411
+ startOrigin: 'center center',
2412
+ endOrigin: 'center center',
2413
+ start: 'scale(0.8)',
2414
+ end: 'scale(1)',
2415
+ leftStart: '0px',
2416
+ leftEnd: '0',
2417
+ topStart: '0px',
2418
+ topEnd: '0',
2419
+ },
2420
+ isClosePrevious: parameters.isClosePrevious ?? false,
2421
+ isStaticBackdrop: parameters.isStaticBackdrop ?? false,
2422
+ width: parameters.width ?? 0,
2461
2423
  };
2462
2424
  }
2463
2425
  }
@@ -3926,21 +3888,23 @@ class UiInputCountryDirective extends UiInputDirective {
3926
3888
  super(elementRef, renderer);
3927
3889
  }
3928
3890
  ngAfterViewInit() {
3929
- this.autoSetCountry();
3891
+ void this.autoSetCountry();
3930
3892
  }
3931
3893
  onPaste(event) {
3932
3894
  event.preventDefault();
3933
- const pastedText = event.clipboardData?.getData('text') || '';
3934
- const country = this.searchCountry(pastedText);
3895
+ void this.handlePaste(event.clipboardData?.getData('text') || '');
3896
+ }
3897
+ async handlePaste(pastedText) {
3898
+ const country = await this.searchCountry(pastedText);
3935
3899
  if (country) {
3936
3900
  this.setCountry(country);
3937
3901
  return;
3938
3902
  }
3939
3903
  this.onInput(this.value() + pastedText);
3940
3904
  }
3941
- searchCountry(temp) {
3942
- const country = CountryService.getCountries().find((c) => c.name.toLowerCase().includes(temp.toLowerCase()));
3943
- return country;
3905
+ async searchCountry(temp) {
3906
+ const countries = await CountryService.getCountries();
3907
+ return countries.find((c) => c.name.toLowerCase().includes(temp.toLowerCase()));
3944
3908
  }
3945
3909
  setCountry(country) {
3946
3910
  this.$selectedCountry.set(country);
@@ -3950,7 +3914,7 @@ class UiInputCountryDirective extends UiInputDirective {
3950
3914
  inputElement.focus();
3951
3915
  }
3952
3916
  }
3953
- autoSetCountry() {
3917
+ async autoSetCountry() {
3954
3918
  const value = this.value();
3955
3919
  if (!value?.length) {
3956
3920
  this.$selectedCountry.set({
@@ -3961,7 +3925,7 @@ class UiInputCountryDirective extends UiInputDirective {
3961
3925
  });
3962
3926
  return;
3963
3927
  }
3964
- const country = this.searchCountry(value);
3928
+ const country = await this.searchCountry(value);
3965
3929
  if (country) {
3966
3930
  this.$selectedCountry.set(country);
3967
3931
  }
@@ -4133,13 +4097,19 @@ class UIPhoneNumberDirective extends UiInputDirective {
4133
4097
  super(elementRef, renderer);
4134
4098
  }
4135
4099
  ngAfterViewInit() {
4136
- const selectedCountry = CountryService.getCountryByCode('US') ?? emptyCountry;
4100
+ void this.initSelectedCountry();
4101
+ }
4102
+ async initSelectedCountry() {
4103
+ const selectedCountry = (await CountryService.getCountryByCode('US')) ?? emptyCountry;
4137
4104
  this.$selectedCountry.set(selectedCountry);
4138
4105
  this.$countryCode.set(selectedCountry.phonePrefix + ' ');
4139
4106
  }
4140
4107
  onInput(value) {
4108
+ void this.formatInput(value);
4109
+ }
4110
+ async formatInput(value) {
4141
4111
  const digitsOnly = value.replace(/\D/g, '');
4142
- const formattedValue = CountryService.formatPhoneNumber(digitsOnly, this.$selectedCountry().code);
4112
+ const formattedValue = await CountryService.formatPhoneNumber(digitsOnly, this.$selectedCountry().code);
4143
4113
  super.onInput(formattedValue);
4144
4114
  const inputElement = this.$inputElement()?.nativeElement;
4145
4115
  if (inputElement) {
@@ -4148,8 +4118,11 @@ class UIPhoneNumberDirective extends UiInputDirective {
4148
4118
  }
4149
4119
  onPaste(event) {
4150
4120
  event.preventDefault();
4151
- const pastedText = event.clipboardData?.getData('text') || '';
4152
- const country = CountryService.getCountries().find((c) => pastedText.startsWith(c.phonePrefix));
4121
+ void this.handlePaste(event.clipboardData?.getData('text') || '');
4122
+ }
4123
+ async handlePaste(pastedText) {
4124
+ const countries = await CountryService.getCountries();
4125
+ const country = countries.find((c) => pastedText.startsWith(c.phonePrefix));
4153
4126
  if (country) {
4154
4127
  const localNumber = pastedText.slice(country.phonePrefix.length);
4155
4128
  this.setCountry(country);