@ibragim-dev-org/ui-forge-library 1.4.54 → 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.
@@ -2298,6 +2298,7 @@ class UiModal {
2298
2298
  backdropPortalRef;
2299
2299
  destroyDownloading$ = new Subject();
2300
2300
  destroyOutsideClickSubscription$ = new Subject();
2301
+ $isOpen = signal(false, ...(ngDevMode ? [{ debugName: "$isOpen" }] : []));
2301
2302
  constructor(overlay, injector, destroyRef, router, backdropService) {
2302
2303
  this.overlay = overlay;
2303
2304
  this.injector = injector;
@@ -2305,99 +2306,61 @@ class UiModal {
2305
2306
  this.router = router;
2306
2307
  this.backdropService = backdropService;
2307
2308
  }
2308
- /**
2309
- * Closes the last opened popup.
2310
- */
2311
2309
  close() {
2312
2310
  if (this.instances.length >= 1) {
2313
2311
  this.instances[this.instances.length - 1].close();
2314
2312
  this.instances.pop();
2315
- if (!this.instances.length) {
2313
+ this.$isOpen.set(this.instances.length > 0);
2314
+ if (!this.instances.length)
2316
2315
  this.destroy();
2317
- }
2318
2316
  }
2319
2317
  }
2320
- /**
2321
- * Closes a popup by its index in the instances array.
2322
- *
2323
- * @param index - The index of the popup to close.
2324
- */
2325
2318
  closeByIndex(index) {
2326
2319
  this.instances[index].close();
2327
2320
  this.instances.splice(index, 1);
2328
- if (!this.instances.length) {
2321
+ this.$isOpen.set(this.instances.length > 0);
2322
+ if (!this.instances.length)
2329
2323
  this.destroy();
2330
- }
2331
2324
  }
2332
- /**
2333
- * Closes a popup by its unique identifier.
2334
- *
2335
- * @param id - The unique identifier of the popup to close.
2336
- */
2337
2325
  closeById(id) {
2338
- const dropDownIndex = this.instances.findIndex((v) => v.id === id);
2339
- if (dropDownIndex >= 0) {
2340
- this.closeByIndex(dropDownIndex);
2341
- }
2326
+ const index = this.instances.findIndex((v) => v.id === id);
2327
+ if (index >= 0)
2328
+ this.closeByIndex(index);
2342
2329
  }
2343
- /**
2344
- * Closes all currently opened popups.
2345
- */
2346
2330
  closeAll() {
2347
- this.instances.forEach((element) => {
2348
- element.close();
2349
- });
2331
+ this.instances.forEach((i) => i.close());
2350
2332
  this.instances = [];
2333
+ this.$isOpen.set(false);
2351
2334
  this.destroy();
2352
2335
  }
2353
- /**
2354
- * Creates a popup instance with the specified component and options.
2355
- *
2356
- * @param overlayRef - The overlay reference for the popup.
2357
- * @param component - The component to be displayed in the popup.
2358
- * @param options - Configuration options for the popup, including inputs.
2359
- * @param id - A unique identifier for the popup instance.
2360
- * @param parameters - (Optional) Configuration options for the popup.
2361
- */
2362
2336
  createPopup(overlayRef, component, options, id, parameters) {
2363
2337
  const newParameters = this.fetchParameters(parameters);
2364
2338
  const uiPopupInstance = new UiPopupInstance(overlayRef, this.destroyRef, options.onClose, newParameters.animationOptions);
2365
- if (newParameters.width > 0) {
2339
+ if (newParameters.width > 0)
2366
2340
  uiPopupInstance.width = newParameters.width;
2367
- }
2368
2341
  const injector = Injector.create({
2369
2342
  parent: this.injector,
2370
2343
  providers: [{ provide: UiPopupInstance, useValue: uiPopupInstance }],
2371
2344
  });
2372
2345
  const componentRef = overlayRef.attach(new ComponentPortal(component, undefined, injector));
2373
- if (options) {
2374
- if (options.inputs) {
2375
- Object.keys(options.inputs).forEach((key) => {
2376
- if (options.inputs) {
2377
- componentRef.setInput(key, options.inputs[key]);
2378
- }
2379
- });
2380
- }
2346
+ if (options?.inputs) {
2347
+ Object.keys(options.inputs).forEach((key) => {
2348
+ componentRef.setInput(key, options.inputs[key]);
2349
+ });
2381
2350
  }
2382
2351
  uiPopupInstance.id = id;
2383
2352
  this.instances.push(uiPopupInstance);
2353
+ this.$isOpen.set(true);
2384
2354
  }
2385
- /**
2386
- * Subscribes to outside events (e.g., scroll, router events) to close popups.
2387
- */
2388
2355
  subscribeToOutsideEvents() {
2389
2356
  this.destroyOutsideClickSubscription$.next();
2390
2357
  if (isBrowser()) {
2391
2358
  fromEvent(window, 'scroll')
2392
- .pipe(tap(() => {
2393
- this.closeAll();
2394
- }), takeUntil$1(this.destroyOutsideClickSubscription$))
2359
+ .pipe(tap(() => this.closeAll()), takeUntil$1(this.destroyOutsideClickSubscription$))
2395
2360
  .subscribe();
2396
2361
  }
2397
2362
  this.router.events
2398
- .pipe(debounceTime(100), tap(() => {
2399
- this.closeAll();
2400
- }), takeUntil$1(this.destroyOutsideClickSubscription$))
2363
+ .pipe(debounceTime(100), tap(() => this.closeAll()), takeUntil$1(this.destroyOutsideClickSubscription$))
2401
2364
  .subscribe();
2402
2365
  }
2403
2366
  destroy() {
@@ -2405,12 +2368,10 @@ class UiModal {
2405
2368
  this.destroyOutsideClickSubscription$.next();
2406
2369
  }
2407
2370
  showBackdrop(isStaticBackdrop = false) {
2408
- if (isBrowser()) {
2371
+ if (isBrowser())
2409
2372
  document.body.style.setProperty('overflow-y', 'hidden');
2410
- }
2411
- if (this.backdropRef) {
2373
+ if (this.backdropRef)
2412
2374
  return;
2413
- }
2414
2375
  this.backdropRef = this.overlay.create({
2415
2376
  hasBackdrop: false,
2416
2377
  positionStrategy: this.overlay.position().global().centerHorizontally().centerVertically(),
@@ -2428,9 +2389,8 @@ class UiModal {
2428
2389
  }
2429
2390
  }
2430
2391
  hideBackdrop() {
2431
- if (!this.backdropRef) {
2392
+ if (!this.backdropRef)
2432
2393
  return;
2433
- }
2434
2394
  if (this.backdropPortalRef) {
2435
2395
  this.backdropPortalRef.location.nativeElement.classList.remove('animate-in');
2436
2396
  this.backdropPortalRef.location.nativeElement.classList.add('animate-out');
@@ -2440,35 +2400,26 @@ class UiModal {
2440
2400
  this.backdropRef?.detach();
2441
2401
  this.backdropRef?.dispose();
2442
2402
  this.backdropRef = undefined;
2443
- if (isBrowser()) {
2403
+ if (isBrowser())
2444
2404
  document.body.style.setProperty('overflow-y', 'auto');
2445
- }
2446
2405
  }))
2447
2406
  .subscribe();
2448
2407
  }
2449
- /**
2450
- * Fetches and normalizes popup parameters.
2451
- *
2452
- * @param parameters - Partial configuration options for the popup.
2453
- * @returns A complete set of popup parameters with default values applied.
2454
- */
2455
2408
  fetchParameters(parameters) {
2456
2409
  return {
2457
- animationOptions: parameters.animationOptions === undefined
2458
- ? {
2459
- startOrigin: 'center center',
2460
- endOrigin: 'center center',
2461
- start: 'scale(0.8)',
2462
- end: 'scale(1)',
2463
- leftStart: '0px',
2464
- leftEnd: '0',
2465
- topStart: '0px',
2466
- topEnd: '0',
2467
- }
2468
- : parameters.animationOptions,
2469
- isClosePrevious: parameters.isClosePrevious === undefined ? false : parameters.isClosePrevious,
2470
- isStaticBackdrop: parameters.isStaticBackdrop === undefined ? false : parameters.isStaticBackdrop,
2471
- 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,
2472
2423
  };
2473
2424
  }
2474
2425
  }