@shival99/z-ui 2.1.31 → 2.1.32

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.
@@ -1,15 +1,18 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Injectable, InjectionToken, inject, DestroyRef, signal, computed, PLATFORM_ID, effect } from '@angular/core';
2
+ import { InjectionToken, EventEmitter, Inject, PLATFORM_ID, Injectable, inject, Injector, TemplateRef, DestroyRef, signal, computed, effect } from '@angular/core';
3
3
  import { zNormalize, zFormatNumExcel, zConvertColorToArgb } from '@shival99/z-ui/utils';
4
+ import { __decorate, __param, __metadata } from 'tslib';
5
+ import { isPlatformBrowser, DOCUMENT } from '@angular/common';
6
+ import { Subject, takeUntil, fromEvent, filter, firstValueFrom, from, switchMap, of, catchError, throwError, tap, map, defer, BehaviorSubject } from 'rxjs';
7
+ import { Overlay, OverlayRef, OverlayConfig } from '@angular/cdk/overlay';
8
+ import { TemplatePortal, ComponentPortal } from '@angular/cdk/portal';
4
9
  import * as ExcelJS from 'exceljs';
5
10
  import { saveAs } from 'file-saver';
6
11
  import * as XLSX from 'xlsx';
7
12
  import { HttpClient, HttpHeaders, HttpErrorResponse } from '@angular/common/http';
8
13
  import { Router } from '@angular/router';
9
- import { firstValueFrom, from, switchMap, of, catchError, throwError, tap, map, defer, Subject, BehaviorSubject } from 'rxjs';
10
14
  import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
11
15
  import { TranslateService } from '@ngx-translate/core';
12
- import { isPlatformBrowser, DOCUMENT } from '@angular/common';
13
16
 
14
17
  const Z_CACHE_SCOPE_SEPARATOR = '::';
15
18
  const Z_DB_SCOPE_SEPARATOR = '__';
@@ -57,6 +60,92 @@ function zStripScopedCacheKey(key) {
57
60
  return normalizedKey.slice(0, normalizedKey.length - Z_CACHE_SCOPE_SUFFIX.length);
58
61
  }
59
62
 
63
+ /** Injection token for data passed to a dynamic component or template. */
64
+ const Z_DYNAMIC_DATA = new InjectionToken('Z_DYNAMIC_DATA');
65
+
66
+ /**
67
+ * Controls one free-form dynamic overlay instance.
68
+ *
69
+ * @template T Component instance type, when the overlay contains a component.
70
+ * @template TResult Value emitted after the overlay closes.
71
+ */
72
+ let ZDynamicRef = class ZDynamicRef {
73
+ _overlayRef;
74
+ _platformId;
75
+ _destroy$ = new Subject();
76
+ _isClosing = false;
77
+ _componentRef = null;
78
+ /** Component instance attached to the overlay, or `null` for template content. */
79
+ componentInstance = null;
80
+ /** Emits the close result once, then completes. */
81
+ afterClose = new EventEmitter();
82
+ constructor(_overlayRef, _platformId) {
83
+ this._overlayRef = _overlayRef;
84
+ this._platformId = _platformId;
85
+ if (!this._overlayRef || !isPlatformBrowser(this._platformId)) {
86
+ return;
87
+ }
88
+ this._overlayRef
89
+ .backdropClick()
90
+ .pipe(takeUntil(this._destroy$))
91
+ .subscribe(() => {
92
+ if (this._closeOnBackdropClick) {
93
+ this.close();
94
+ }
95
+ });
96
+ fromEvent(document, 'keydown')
97
+ .pipe(filter(event => event.key === 'Escape'), takeUntil(this._destroy$))
98
+ .subscribe(() => {
99
+ if (this._closeOnEscape) {
100
+ this.close();
101
+ }
102
+ });
103
+ }
104
+ _closeOnBackdropClick = true;
105
+ _closeOnEscape = true;
106
+ /** Configures close triggers for the instance. */
107
+ setCloseBehavior(closeOnBackdropClick, closeOnEscape) {
108
+ this._closeOnBackdropClick = closeOnBackdropClick;
109
+ this._closeOnEscape = closeOnEscape;
110
+ }
111
+ /** Returns whether this ref has already been closed. */
112
+ isClosed() {
113
+ return this._isClosing;
114
+ }
115
+ /** Closes the overlay and emits the optional result exactly once. */
116
+ close(result) {
117
+ if (this._isClosing) {
118
+ return;
119
+ }
120
+ this._isClosing = true;
121
+ this._overlayRef?.dispose();
122
+ this._componentRef = null;
123
+ this.componentInstance = null;
124
+ this.afterClose.emit(result);
125
+ this.afterClose.complete();
126
+ this._destroy$.next();
127
+ this._destroy$.complete();
128
+ }
129
+ /** Updates the overlay position using its configured strategy. */
130
+ updatePosition() {
131
+ this._overlayRef?.updatePosition();
132
+ }
133
+ /** Updates the overlay pane dimensions. */
134
+ updateSize(width, height) {
135
+ const sizeConfig = { width, height };
136
+ this._overlayRef?.updateSize(sizeConfig);
137
+ }
138
+ /** @internal Used by the service after attaching a component portal. */
139
+ attachComponentRef(componentRef) {
140
+ this._componentRef = componentRef;
141
+ this.componentInstance = componentRef.instance;
142
+ }
143
+ };
144
+ ZDynamicRef = __decorate([
145
+ __param(1, Inject(PLATFORM_ID)),
146
+ __metadata("design:paramtypes", [Object, Object])
147
+ ], ZDynamicRef);
148
+
60
149
  const Z_EXCEL_COLORS = {
61
150
  'green-50': 'FFF0FDF4',
62
151
  'green-100': 'FFDCFCE7',
@@ -349,6 +438,157 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.9", ngImpor
349
438
  }]
350
439
  }] });
351
440
 
441
+ /**
442
+ * Global z-index counter for overlay components (z-modal, z-drawer, etc.).
443
+ *
444
+ * Each time an overlay opens, it calls `next()` to get a unique, incrementing
445
+ * z-index value. This guarantees that overlays opened later always stack on top
446
+ * of earlier ones — regardless of DOM order or HMR re-creation.
447
+ */
448
+ class ZOverlayZIndexService {
449
+ _currentZIndex = 1000;
450
+ _platformId = inject(PLATFORM_ID);
451
+ /**
452
+ * Returns the next z-index value and increments the counter.
453
+ * Kept for backward compatibility with existing overlay flow.
454
+ */
455
+ next() {
456
+ const zIndex = this._currentZIndex;
457
+ this._currentZIndex += 2; // +2 to leave room for backdrop (zIndex - 1)
458
+ return zIndex;
459
+ }
460
+ applyToOverlay(overlayRef) {
461
+ const zIndex = this.next();
462
+ overlayRef.hostElement.style.zIndex = `${zIndex}`;
463
+ if (overlayRef.backdropElement) {
464
+ overlayRef.backdropElement.style.zIndex = `${zIndex - 1}`;
465
+ }
466
+ return zIndex;
467
+ }
468
+ deferMoveToTop(overlayRef) {
469
+ if (!isPlatformBrowser(this._platformId)) {
470
+ return;
471
+ }
472
+ queueMicrotask(() => {
473
+ this.moveToTop(overlayRef);
474
+ });
475
+ }
476
+ moveToTop(overlayRef) {
477
+ if (!isPlatformBrowser(this._platformId)) {
478
+ return;
479
+ }
480
+ const wrapperElement = overlayRef.hostElement;
481
+ if (!wrapperElement) {
482
+ return;
483
+ }
484
+ if (wrapperElement.hasAttribute('popover')) {
485
+ const popoverWrapper = wrapperElement;
486
+ if (popoverWrapper.hidePopover && popoverWrapper.showPopover) {
487
+ try {
488
+ popoverWrapper.hidePopover();
489
+ popoverWrapper.showPopover();
490
+ return;
491
+ }
492
+ catch {
493
+ // fall through to non-popover fallback
494
+ }
495
+ }
496
+ }
497
+ const parent = wrapperElement.parentElement;
498
+ if (parent) {
499
+ parent.appendChild(wrapperElement);
500
+ }
501
+ }
502
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.9", ngImport: i0, type: ZOverlayZIndexService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
503
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.9", ngImport: i0, type: ZOverlayZIndexService, providedIn: 'root' });
504
+ }
505
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.9", ngImport: i0, type: ZOverlayZIndexService, decorators: [{
506
+ type: Injectable,
507
+ args: [{
508
+ providedIn: 'root',
509
+ }]
510
+ }] });
511
+
512
+ /**
513
+ * Opens components and templates in a bare CDK overlay.
514
+ *
515
+ * @description The service supplies overlay lifecycle and positioning only. The
516
+ * mounted content owns its complete layout, including close controls and styling.
517
+ */
518
+ class ZDynamicService {
519
+ _overlay = inject(Overlay);
520
+ _injector = inject(Injector);
521
+ _platformId = inject(PLATFORM_ID);
522
+ _zIndexService = inject(ZOverlayZIndexService);
523
+ /** Alias for `open`, matching the create-style API used by modal and drawer services. */
524
+ create(content, options = {}) {
525
+ return this.open(content, options);
526
+ }
527
+ /** Opens a component or template in a free-form CDK overlay. */
528
+ open(content, options = {}) {
529
+ const overlayRef = this._createOverlay(options);
530
+ const dynamicRef = new ZDynamicRef(overlayRef, this._platformId);
531
+ dynamicRef.setCloseBehavior(options.closeOnBackdropClick ?? true, options.closeOnEscape ?? true);
532
+ if (!overlayRef) {
533
+ return dynamicRef;
534
+ }
535
+ this._zIndexService.applyToOverlay(overlayRef);
536
+ if (this._isTemplate(content)) {
537
+ if (!options.viewContainerRef) {
538
+ dynamicRef.close();
539
+ throw new Error('ZDynamicService requires viewContainerRef when opening a TemplateRef');
540
+ }
541
+ const context = {
542
+ $implicit: dynamicRef,
543
+ dynamicRef,
544
+ data: options.data,
545
+ };
546
+ overlayRef.attach(new TemplatePortal(content, options.viewContainerRef, context));
547
+ return dynamicRef;
548
+ }
549
+ const injector = Injector.create({
550
+ parent: this._injector,
551
+ providers: [
552
+ { provide: OverlayRef, useValue: overlayRef },
553
+ { provide: ZDynamicRef, useValue: dynamicRef },
554
+ { provide: Z_DYNAMIC_DATA, useValue: options.data },
555
+ ],
556
+ });
557
+ const componentRef = overlayRef.attach(new ComponentPortal(content, options.viewContainerRef, injector));
558
+ componentRef.changeDetectorRef.detectChanges();
559
+ dynamicRef.attachComponentRef(componentRef);
560
+ return dynamicRef;
561
+ }
562
+ _createOverlay(options) {
563
+ if (!isPlatformBrowser(this._platformId)) {
564
+ return undefined;
565
+ }
566
+ const config = new OverlayConfig({
567
+ hasBackdrop: options.hasBackdrop ?? true,
568
+ backdropClass: options.backdropClass ?? 'cdk-overlay-dark-backdrop',
569
+ panelClass: options.panelClass,
570
+ positionStrategy: options.positionStrategy ?? this._overlay.position().global(),
571
+ scrollStrategy: options.scrollStrategy ?? this._overlay.scrollStrategies.block(),
572
+ width: options.width,
573
+ height: options.height,
574
+ minWidth: options.minWidth,
575
+ maxWidth: options.maxWidth,
576
+ minHeight: options.minHeight,
577
+ maxHeight: options.maxHeight,
578
+ });
579
+ return this._overlay.create(config);
580
+ }
581
+ _isTemplate(content) {
582
+ return content instanceof TemplateRef;
583
+ }
584
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.9", ngImport: i0, type: ZDynamicService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
585
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.9", ngImport: i0, type: ZDynamicService, providedIn: 'root' });
586
+ }
587
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.9", ngImport: i0, type: ZDynamicService, decorators: [{
588
+ type: Injectable,
589
+ args: [{ providedIn: 'root' }]
590
+ }] });
591
+
352
592
  class ZExcelService {
353
593
  static _isHeaderConfig(config) {
354
594
  if (!config || typeof config !== 'object') {
@@ -2131,77 +2371,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.9", ngImpor
2131
2371
  }]
2132
2372
  }] });
2133
2373
 
2134
- /**
2135
- * Global z-index counter for overlay components (z-modal, z-drawer, etc.).
2136
- *
2137
- * Each time an overlay opens, it calls `next()` to get a unique, incrementing
2138
- * z-index value. This guarantees that overlays opened later always stack on top
2139
- * of earlier ones — regardless of DOM order or HMR re-creation.
2140
- */
2141
- class ZOverlayZIndexService {
2142
- _currentZIndex = 1000;
2143
- _platformId = inject(PLATFORM_ID);
2144
- /**
2145
- * Returns the next z-index value and increments the counter.
2146
- * Kept for backward compatibility with existing overlay flow.
2147
- */
2148
- next() {
2149
- const zIndex = this._currentZIndex;
2150
- this._currentZIndex += 2; // +2 to leave room for backdrop (zIndex - 1)
2151
- return zIndex;
2152
- }
2153
- applyToOverlay(overlayRef) {
2154
- const zIndex = this.next();
2155
- overlayRef.hostElement.style.zIndex = `${zIndex}`;
2156
- if (overlayRef.backdropElement) {
2157
- overlayRef.backdropElement.style.zIndex = `${zIndex - 1}`;
2158
- }
2159
- return zIndex;
2160
- }
2161
- deferMoveToTop(overlayRef) {
2162
- if (!isPlatformBrowser(this._platformId)) {
2163
- return;
2164
- }
2165
- queueMicrotask(() => {
2166
- this.moveToTop(overlayRef);
2167
- });
2168
- }
2169
- moveToTop(overlayRef) {
2170
- if (!isPlatformBrowser(this._platformId)) {
2171
- return;
2172
- }
2173
- const wrapperElement = overlayRef.hostElement;
2174
- if (!wrapperElement) {
2175
- return;
2176
- }
2177
- if (wrapperElement.hasAttribute('popover')) {
2178
- const popoverWrapper = wrapperElement;
2179
- if (popoverWrapper.hidePopover && popoverWrapper.showPopover) {
2180
- try {
2181
- popoverWrapper.hidePopover();
2182
- popoverWrapper.showPopover();
2183
- return;
2184
- }
2185
- catch {
2186
- // fall through to non-popover fallback
2187
- }
2188
- }
2189
- }
2190
- const parent = wrapperElement.parentElement;
2191
- if (parent) {
2192
- parent.appendChild(wrapperElement);
2193
- }
2194
- }
2195
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.9", ngImport: i0, type: ZOverlayZIndexService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
2196
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.9", ngImport: i0, type: ZOverlayZIndexService, providedIn: 'root' });
2197
- }
2198
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.9", ngImport: i0, type: ZOverlayZIndexService, decorators: [{
2199
- type: Injectable,
2200
- args: [{
2201
- providedIn: 'root',
2202
- }]
2203
- }] });
2204
-
2205
2374
  class ZSubjectService {
2206
2375
  _subjects = new Map();
2207
2376
  _behaviorSubjects = new Map();
@@ -2411,5 +2580,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.9", ngImpor
2411
2580
  * Generated bundle index. Do not edit.
2412
2581
  */
2413
2582
 
2414
- export { ZCacheService, ZExcelService, ZHttpAbstractService, ZIndexDbService, ZOverlayContainerService, ZOverlayZIndexService, ZSubjectService, ZThemeService, ZTranslateService, Z_DEFAULT_THEME, Z_EXCEL_BORDER_THIN, Z_EXCEL_CHAR_WIDTH_MAP, Z_EXCEL_COLORS, Z_EXCEL_DEFAULT_CONFIG, Z_EXCEL_FONT_MULTIPLIERS, Z_EXCEL_WIDTH_LIMITS, Z_HTTP_DEFAULT_CONFIG, Z_INDEXDB_BATCH_SIZE, Z_INDEXDB_DEFAULT_CONFIG, Z_INDEXDB_MAX_VERSION, Z_LANG_CACHE_KEY, Z_LANG_TO_LOCALE, Z_THEME_CONFIG, Z_THEME_CSS_MAP, Z_THEME_PREFERENCES_CACHE_KEY, zBuildScopedCacheKey, zBuildScopedDbName, zStripScopedCacheKey };
2583
+ export { ZCacheService, ZDynamicRef, ZDynamicService, ZExcelService, ZHttpAbstractService, ZIndexDbService, ZOverlayContainerService, ZOverlayZIndexService, ZSubjectService, ZThemeService, ZTranslateService, Z_DEFAULT_THEME, Z_DYNAMIC_DATA, Z_EXCEL_BORDER_THIN, Z_EXCEL_CHAR_WIDTH_MAP, Z_EXCEL_COLORS, Z_EXCEL_DEFAULT_CONFIG, Z_EXCEL_FONT_MULTIPLIERS, Z_EXCEL_WIDTH_LIMITS, Z_HTTP_DEFAULT_CONFIG, Z_INDEXDB_BATCH_SIZE, Z_INDEXDB_DEFAULT_CONFIG, Z_INDEXDB_MAX_VERSION, Z_LANG_CACHE_KEY, Z_LANG_TO_LOCALE, Z_THEME_CONFIG, Z_THEME_CSS_MAP, Z_THEME_PREFERENCES_CACHE_KEY, zBuildScopedCacheKey, zBuildScopedDbName, zStripScopedCacheKey };
2415
2584
  //# sourceMappingURL=shival99-z-ui-services.mjs.map