@cngx/ui 0.1.0-rc.7 → 0.1.0-rc.8

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.
Files changed (96) hide show
  1. package/README.md +0 -1
  2. package/a11y/README.md +11 -5
  3. package/accordion/README.md +4 -2
  4. package/breadcrumb/README.md +262 -0
  5. package/collection/README.md +6 -0
  6. package/command-palette/README.md +224 -0
  7. package/data-grid-accordion/README.md +76 -2
  8. package/feedback/README.md +40 -0
  9. package/fesm2022/cngx-ui-a11y.mjs +189 -57
  10. package/fesm2022/cngx-ui-a11y.mjs.map +1 -1
  11. package/fesm2022/cngx-ui-accordion.mjs +102 -35
  12. package/fesm2022/cngx-ui-accordion.mjs.map +1 -1
  13. package/fesm2022/cngx-ui-action-button.mjs +112 -50
  14. package/fesm2022/cngx-ui-action-button.mjs.map +1 -1
  15. package/fesm2022/cngx-ui-breadcrumb.mjs +176 -96
  16. package/fesm2022/cngx-ui-breadcrumb.mjs.map +1 -1
  17. package/fesm2022/cngx-ui-chart-panel.mjs +180 -23
  18. package/fesm2022/cngx-ui-chart-panel.mjs.map +1 -1
  19. package/fesm2022/cngx-ui-collection.mjs +194 -62
  20. package/fesm2022/cngx-ui-collection.mjs.map +1 -1
  21. package/fesm2022/cngx-ui-command-palette.mjs +395 -119
  22. package/fesm2022/cngx-ui-command-palette.mjs.map +1 -1
  23. package/fesm2022/cngx-ui-context-menu.mjs +149 -34
  24. package/fesm2022/cngx-ui-context-menu.mjs.map +1 -1
  25. package/fesm2022/cngx-ui-data-grid-accordion.mjs +415 -98
  26. package/fesm2022/cngx-ui-data-grid-accordion.mjs.map +1 -1
  27. package/fesm2022/cngx-ui-empty-state.mjs +16 -6
  28. package/fesm2022/cngx-ui-empty-state.mjs.map +1 -1
  29. package/fesm2022/cngx-ui-feedback.mjs +1022 -439
  30. package/fesm2022/cngx-ui-feedback.mjs.map +1 -1
  31. package/fesm2022/cngx-ui-mat-accordion.mjs +75 -7
  32. package/fesm2022/cngx-ui-mat-accordion.mjs.map +1 -1
  33. package/fesm2022/cngx-ui-mat-paginator.mjs +67 -24
  34. package/fesm2022/cngx-ui-mat-paginator.mjs.map +1 -1
  35. package/fesm2022/cngx-ui-mat-stepper.mjs +72 -47
  36. package/fesm2022/cngx-ui-mat-stepper.mjs.map +1 -1
  37. package/fesm2022/cngx-ui-mat-tabs.mjs +314 -141
  38. package/fesm2022/cngx-ui-mat-tabs.mjs.map +1 -1
  39. package/fesm2022/cngx-ui-overlay.mjs +69 -13
  40. package/fesm2022/cngx-ui-overlay.mjs.map +1 -1
  41. package/fesm2022/cngx-ui-paginator.mjs +487 -178
  42. package/fesm2022/cngx-ui-paginator.mjs.map +1 -1
  43. package/fesm2022/cngx-ui-sidenav.mjs +327 -106
  44. package/fesm2022/cngx-ui-sidenav.mjs.map +1 -1
  45. package/fesm2022/cngx-ui-skeleton.mjs +4 -16
  46. package/fesm2022/cngx-ui-skeleton.mjs.map +1 -1
  47. package/fesm2022/cngx-ui-speak.mjs +107 -8
  48. package/fesm2022/cngx-ui-speak.mjs.map +1 -1
  49. package/fesm2022/cngx-ui-stat-card.mjs +146 -46
  50. package/fesm2022/cngx-ui-stat-card.mjs.map +1 -1
  51. package/fesm2022/cngx-ui-stepper.mjs +191 -68
  52. package/fesm2022/cngx-ui-stepper.mjs.map +1 -1
  53. package/fesm2022/cngx-ui-tabs.mjs +10 -6
  54. package/fesm2022/cngx-ui-tabs.mjs.map +1 -1
  55. package/fesm2022/cngx-ui-timeline.mjs +74 -21
  56. package/fesm2022/cngx-ui-timeline.mjs.map +1 -1
  57. package/fesm2022/cngx-ui-toc.mjs +70 -26
  58. package/fesm2022/cngx-ui-toc.mjs.map +1 -1
  59. package/fesm2022/cngx-ui.mjs +15 -20
  60. package/fesm2022/cngx-ui.mjs.map +1 -1
  61. package/mat-paginator/README.md +9 -2
  62. package/mat-tabs/styles/mat-tabs.css +9 -10
  63. package/overlay/README.md +9 -4
  64. package/package.json +4 -4
  65. package/paginator/README.md +8 -4
  66. package/sidenav/README.md +33 -11
  67. package/speak/README.md +3 -2
  68. package/stepper/README.md +13 -1
  69. package/timeline/README.md +1 -1
  70. package/toc/README.md +4 -1
  71. package/types/cngx-ui-a11y.d.ts +121 -30
  72. package/types/cngx-ui-accordion.d.ts +91 -26
  73. package/types/cngx-ui-action-button.d.ts +44 -3
  74. package/types/cngx-ui-breadcrumb.d.ts +154 -58
  75. package/types/cngx-ui-chart-panel.d.ts +122 -18
  76. package/types/cngx-ui-collection.d.ts +147 -55
  77. package/types/cngx-ui-command-palette.d.ts +297 -183
  78. package/types/cngx-ui-context-menu.d.ts +98 -6
  79. package/types/cngx-ui-data-grid-accordion.d.ts +274 -38
  80. package/types/cngx-ui-empty-state.d.ts +9 -2
  81. package/types/cngx-ui-feedback.d.ts +594 -56
  82. package/types/cngx-ui-mat-accordion.d.ts +29 -1
  83. package/types/cngx-ui-mat-paginator.d.ts +37 -8
  84. package/types/cngx-ui-mat-stepper.d.ts +23 -11
  85. package/types/cngx-ui-mat-tabs.d.ts +207 -14
  86. package/types/cngx-ui-overlay.d.ts +56 -10
  87. package/types/cngx-ui-paginator.d.ts +403 -129
  88. package/types/cngx-ui-sidenav.d.ts +248 -74
  89. package/types/cngx-ui-skeleton.d.ts +6 -7
  90. package/types/cngx-ui-speak.d.ts +118 -5
  91. package/types/cngx-ui-stat-card.d.ts +117 -33
  92. package/types/cngx-ui-stepper.d.ts +66 -27
  93. package/types/cngx-ui-tabs.d.ts +2 -2
  94. package/types/cngx-ui-timeline.d.ts +23 -7
  95. package/types/cngx-ui-toc.d.ts +80 -13
  96. package/types/cngx-ui.d.ts +7 -4
@@ -1,5 +1,6 @@
1
+ import { DOCUMENT } from '@angular/common';
1
2
  import * as i0 from '@angular/core';
2
- import { inject, Injector, Injectable, makeEnvironmentProviders } from '@angular/core';
3
+ import { signal, inject, Injector, DestroyRef, Injectable, makeEnvironmentProviders } from '@angular/core';
3
4
  import { Overlay, OverlayConfig } from '@angular/cdk/overlay';
4
5
  import { ComponentPortal } from '@angular/cdk/portal';
5
6
  import { Subject, takeUntil } from 'rxjs';
@@ -7,6 +8,10 @@ import { Subject, takeUntil } from 'rxjs';
7
8
  /**
8
9
  * Typed wrapper around a CDK OverlayRef that exposes a close result stream.
9
10
  *
11
+ * Closes on Escape and on a backdrop click (unless `disableClose`), restores
12
+ * focus to the element that opened it, and surfaces its open state as a signal
13
+ * beside the RxJS `afterClosed$`.
14
+ *
10
15
  * @category ui/overlay
11
16
  * @docsKind primary
12
17
  * @wcag AA
@@ -19,18 +24,47 @@ class CngxOverlayRef {
19
24
  _afterClosed = new Subject();
20
25
  /** Emits once with the close result when the overlay is dismissed, then completes. */
21
26
  afterClosed$ = this._afterClosed.asObservable();
22
- constructor(cdkRef) {
27
+ openState = signal(true, ...(ngDevMode ? [{ debugName: "openState" }] : /* istanbul ignore next */ []));
28
+ /**
29
+ * `true` while the overlay is open, `false` once closed. The signal view of
30
+ * the lifecycle beside {@link afterClosed$} - bind it in a template without
31
+ * an `async` pipe.
32
+ */
33
+ isOpen = this.openState.asReadonly();
34
+ restoreFocusTo;
35
+ constructor(cdkRef, config = {}) {
23
36
  this.cdkRef = cdkRef;
24
- cdkRef
25
- .backdropClick()
26
- .pipe(takeUntil(this._afterClosed))
27
- .subscribe(() => this.close());
37
+ this.restoreFocusTo = config.restoreFocusTo ?? null;
38
+ if (!config.disableClose) {
39
+ cdkRef
40
+ .backdropClick()
41
+ .pipe(takeUntil(this._afterClosed))
42
+ .subscribe(() => this.close());
43
+ cdkRef
44
+ .keydownEvents()
45
+ .pipe(takeUntil(this._afterClosed))
46
+ .subscribe((event) => {
47
+ if (event.key === 'Escape') {
48
+ event.preventDefault();
49
+ this.close();
50
+ }
51
+ });
52
+ }
28
53
  }
29
- /** Closes the overlay, emitting `result` on `afterClosed$`, then disposes the CDK ref. */
54
+ /**
55
+ * Closes the overlay, emitting `result` on `afterClosed$`, disposing the CDK
56
+ * ref, and restoring focus. Idempotent - a second call (e.g. Escape after a
57
+ * scope teardown already closed it) is a no-op.
58
+ */
30
59
  close(result) {
60
+ if (!this.openState()) {
61
+ return;
62
+ }
63
+ this.openState.set(false);
31
64
  this._afterClosed.next(result);
32
65
  this._afterClosed.complete();
33
66
  this.cdkRef.dispose();
67
+ this.restoreFocusTo?.focus();
34
68
  }
35
69
  }
36
70
 
@@ -57,23 +91,45 @@ class CngxOverlayRef {
57
91
  class CngxOverlay {
58
92
  overlay = inject(Overlay);
59
93
  injector = inject(Injector);
94
+ document = inject(DOCUMENT);
95
+ // Held by the only capability the registry needs; the generic CngxOverlayRef
96
+ // is invariant in R (its Subject leaks into the type), so a structural close
97
+ // handle sidesteps that without an unknown-cast.
98
+ openRefs = new Set();
99
+ constructor() {
100
+ // The service is destroyed with its providing scope (component or
101
+ // environment injector). Anything still open would otherwise leak a
102
+ // detached overlay panel and its subscriptions - close them.
103
+ inject(DestroyRef).onDestroy(() => {
104
+ for (const ref of [...this.openRefs]) {
105
+ ref.close();
106
+ }
107
+ });
108
+ }
60
109
  /**
61
110
  * Opens `component` in a CDK overlay panel and returns a typed ref.
62
111
  *
63
- * Defaults to a centered, backdropped panel. Merge `config` to override
64
- * position strategy, scroll strategy, or any other CDK `OverlayConfig` option.
112
+ * Defaults to a centered, backdropped panel that closes on Escape or a
113
+ * backdrop click; pass `disableClose` to opt out. Focus returns to the
114
+ * element that was focused at open time. Merge `config` to override position
115
+ * strategy, scroll strategy, or any other CDK `OverlayConfig` option.
65
116
  *
66
117
  * @param component Component class to attach as a portal.
67
- * @param config CDK overlay configuration overrides.
118
+ * @param config Overlay configuration overrides (CDK options + `disableClose`).
68
119
  */
69
120
  open(component, config = {}) {
121
+ const { disableClose, ...cdkConfig } = config;
70
122
  const overlayConfig = new OverlayConfig({
71
123
  hasBackdrop: true,
72
124
  positionStrategy: this.overlay.position().global().centerHorizontally().centerVertically(),
73
- ...config,
125
+ ...cdkConfig,
74
126
  });
75
127
  const cdkRef = this.overlay.create(overlayConfig);
76
- const ngxRef = new CngxOverlayRef(cdkRef);
128
+ // Capture the opener BEFORE attaching, so focus can return to it on close.
129
+ const restoreFocusTo = this.document.activeElement;
130
+ const ngxRef = new CngxOverlayRef(cdkRef, { disableClose, restoreFocusTo });
131
+ this.openRefs.add(ngxRef);
132
+ ngxRef.afterClosed$.subscribe({ complete: () => this.openRefs.delete(ngxRef) });
77
133
  const injector = Injector.create({
78
134
  parent: this.injector,
79
135
  providers: [{ provide: CngxOverlayRef, useValue: ngxRef }],
@@ -87,7 +143,7 @@ class CngxOverlay {
87
143
  }
88
144
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxOverlay, decorators: [{
89
145
  type: Injectable
90
- }] });
146
+ }], ctorParameters: () => [] });
91
147
  /**
92
148
  * Provides `CngxOverlay` as an environment-scoped service.
93
149
  *
@@ -1 +1 @@
1
- {"version":3,"file":"cngx-ui-overlay.mjs","sources":["../../../projects/ui/overlay/overlay-ref.ts","../../../projects/ui/overlay/overlay.service.ts","../../../projects/ui/overlay/public-api.ts","../../../projects/ui/overlay/cngx-ui-overlay.ts"],"sourcesContent":["import { type OverlayRef as CdkOverlayRef } from '@angular/cdk/overlay';\nimport { Subject, takeUntil } from 'rxjs';\n\n/**\n * Typed wrapper around a CDK OverlayRef that exposes a close result stream.\n *\n * @category ui/overlay\n * @docsKind primary\n * @wcag AA\n * @github https://github.com/cngxjs/cngx/blob/main/projects/ui/overlay/overlay-ref.ts\n * @since 0.1.0\n * @relatedTo CngxOverlay, provideOverlay\n */\nexport class CngxOverlayRef<R = unknown> {\n private readonly _afterClosed = new Subject<R | undefined>();\n\n /** Emits once with the close result when the overlay is dismissed, then completes. */\n readonly afterClosed$ = this._afterClosed.asObservable();\n\n constructor(private readonly cdkRef: CdkOverlayRef) {\n cdkRef\n .backdropClick()\n .pipe(takeUntil(this._afterClosed))\n .subscribe(() => this.close());\n }\n\n /** Closes the overlay, emitting `result` on `afterClosed$`, then disposes the CDK ref. */\n close(result?: R): void {\n this._afterClosed.next(result);\n this._afterClosed.complete();\n this.cdkRef.dispose();\n }\n}\n","import {\n Injectable,\n Injector,\n inject,\n makeEnvironmentProviders,\n type EnvironmentProviders,\n type Type,\n} from '@angular/core';\nimport { Overlay, OverlayConfig, type OverlayRef as CdkOverlayRef } from '@angular/cdk/overlay';\nimport { ComponentPortal } from '@angular/cdk/portal';\nimport { CngxOverlayRef } from './overlay-ref';\n\n/**\n * Config accepted by {@link CngxOverlay.open}. Partial alias of CDK's\n * {@link OverlayConfig} - every field is optional and falls back to\n * the CDK overlay default.\n *\n * @category ui/overlay\n */\nexport type CngxOverlayConfig = Partial<OverlayConfig>;\n\n/**\n * Thin service over CDK Overlay that returns a typed CngxOverlayRef.\n *\n * Must be provided via `provideOverlay()` in application or component providers.\n * ```ts\n * // app.config.ts\n * provideOverlay()\n\n * // usage\n * const ref = overlayService.open(MyComponent, { hasBackdrop: true });\n * ref.afterClosed$.subscribe(result => console.log(result));\n* ```\n *\n * @category ui/overlay\n * @docsKind primary\n * @wcag AA\n * @github https://github.com/cngxjs/cngx/blob/main/projects/ui/overlay/overlay.service.ts\n * @since 0.1.0\n * @relatedTo CngxOverlayRef, provideOverlay\n */\n@Injectable()\nexport class CngxOverlay {\n private readonly overlay = inject(Overlay);\n private readonly injector = inject(Injector);\n\n /**\n * Opens `component` in a CDK overlay panel and returns a typed ref.\n *\n * Defaults to a centered, backdropped panel. Merge `config` to override\n * position strategy, scroll strategy, or any other CDK `OverlayConfig` option.\n *\n * @param component Component class to attach as a portal.\n * @param config CDK overlay configuration overrides.\n */\n open<C, R = unknown>(component: Type<C>, config: CngxOverlayConfig = {}): CngxOverlayRef<R> {\n const overlayConfig = new OverlayConfig({\n hasBackdrop: true,\n positionStrategy: this.overlay.position().global().centerHorizontally().centerVertically(),\n ...config,\n });\n\n const cdkRef: CdkOverlayRef = this.overlay.create(overlayConfig);\n const ngxRef = new CngxOverlayRef<R>(cdkRef);\n\n const injector = Injector.create({\n parent: this.injector,\n providers: [{ provide: CngxOverlayRef, useValue: ngxRef }],\n });\n\n const portal = new ComponentPortal(component, null, injector);\n cdkRef.attach(portal);\n return ngxRef;\n }\n}\n\n/**\n * Provides `CngxOverlay` as an environment-scoped service.\n *\n * @category ui/overlay\n */\nexport function provideOverlay(): EnvironmentProviders {\n return makeEnvironmentProviders([CngxOverlay]);\n}\n","/**\n * Public API Surface of @cngx/ui/overlay\n * @module @cngx/ui/overlay\n */\n\nexport { CngxOverlay, provideOverlay, type CngxOverlayConfig } from './overlay.service';\nexport { CngxOverlayRef } from './overlay-ref';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;AAGA;;;;;;;;;AASG;MACU,cAAc,CAAA;AAMI,IAAA,MAAA;AALZ,IAAA,YAAY,GAAG,IAAI,OAAO,EAAiB;;AAGnD,IAAA,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE;AAExD,IAAA,WAAA,CAA6B,MAAqB,EAAA;QAArB,IAAA,CAAA,MAAM,GAAN,MAAM;QACjC;AACG,aAAA,aAAa;AACb,aAAA,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC;aACjC,SAAS,CAAC,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;IAClC;;AAGA,IAAA,KAAK,CAAC,MAAU,EAAA;AACd,QAAA,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC;AAC9B,QAAA,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE;AAC5B,QAAA,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE;IACvB;AACD;;ACXD;;;;;;;;;;;;;;;;;;;AAmBG;MAEU,WAAW,CAAA;AACL,IAAA,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;AACzB,IAAA,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;AAE5C;;;;;;;;AAQG;AACH,IAAA,IAAI,CAAiB,SAAkB,EAAE,MAAA,GAA4B,EAAE,EAAA;AACrE,QAAA,MAAM,aAAa,GAAG,IAAI,aAAa,CAAC;AACtC,YAAA,WAAW,EAAE,IAAI;AACjB,YAAA,gBAAgB,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,CAAC,kBAAkB,EAAE,CAAC,gBAAgB,EAAE;AAC1F,YAAA,GAAG,MAAM;AACV,SAAA,CAAC;QAEF,MAAM,MAAM,GAAkB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC;AAChE,QAAA,MAAM,MAAM,GAAG,IAAI,cAAc,CAAI,MAAM,CAAC;AAE5C,QAAA,MAAM,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC;YAC/B,MAAM,EAAE,IAAI,CAAC,QAAQ;YACrB,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AAC3D,SAAA,CAAC;QAEF,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC,SAAS,EAAE,IAAI,EAAE,QAAQ,CAAC;AAC7D,QAAA,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;AACrB,QAAA,OAAO,MAAM;IACf;uGA/BW,WAAW,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;2GAAX,WAAW,EAAA,CAAA;;2FAAX,WAAW,EAAA,UAAA,EAAA,CAAA;kBADvB;;AAmCD;;;;AAIG;SACa,cAAc,GAAA;AAC5B,IAAA,OAAO,wBAAwB,CAAC,CAAC,WAAW,CAAC,CAAC;AAChD;;ACnFA;;;AAGG;;ACHH;;AAEG;;;;"}
1
+ {"version":3,"file":"cngx-ui-overlay.mjs","sources":["../../../projects/ui/overlay/overlay-ref.ts","../../../projects/ui/overlay/overlay.service.ts","../../../projects/ui/overlay/public-api.ts","../../../projects/ui/overlay/cngx-ui-overlay.ts"],"sourcesContent":["import { type OverlayRef as CdkOverlayRef } from '@angular/cdk/overlay';\nimport { signal, type Signal } from '@angular/core';\nimport { Subject, takeUntil } from 'rxjs';\n\n/**\n * Construction-time options for a {@link CngxOverlayRef}. Set by\n * {@link CngxOverlay.open}, not by consumers.\n *\n * @category ui/overlay\n */\nexport interface CngxOverlayRefConfig {\n /**\n * When `true`, neither Escape nor a backdrop click closes the overlay - the\n * only way out is a programmatic `close()`. Default `false`.\n */\n readonly disableClose?: boolean;\n /**\n * Element focus returns to when the overlay closes - captured at open time,\n * before the overlay steals focus. `null` skips restoration.\n */\n readonly restoreFocusTo?: HTMLElement | null;\n}\n\n/**\n * Typed wrapper around a CDK OverlayRef that exposes a close result stream.\n *\n * Closes on Escape and on a backdrop click (unless `disableClose`), restores\n * focus to the element that opened it, and surfaces its open state as a signal\n * beside the RxJS `afterClosed$`.\n *\n * @category ui/overlay\n * @docsKind primary\n * @wcag AA\n * @github https://github.com/cngxjs/cngx/blob/main/projects/ui/overlay/overlay-ref.ts\n * @since 0.1.0\n * @relatedTo CngxOverlay, provideOverlay\n */\nexport class CngxOverlayRef<R = unknown> {\n private readonly _afterClosed = new Subject<R | undefined>();\n\n /** Emits once with the close result when the overlay is dismissed, then completes. */\n readonly afterClosed$ = this._afterClosed.asObservable();\n\n private readonly openState = signal(true);\n /**\n * `true` while the overlay is open, `false` once closed. The signal view of\n * the lifecycle beside {@link afterClosed$} - bind it in a template without\n * an `async` pipe.\n */\n readonly isOpen: Signal<boolean> = this.openState.asReadonly();\n\n private readonly restoreFocusTo: HTMLElement | null;\n\n constructor(\n private readonly cdkRef: CdkOverlayRef,\n config: CngxOverlayRefConfig = {},\n ) {\n this.restoreFocusTo = config.restoreFocusTo ?? null;\n\n if (!config.disableClose) {\n cdkRef\n .backdropClick()\n .pipe(takeUntil(this._afterClosed))\n .subscribe(() => this.close());\n cdkRef\n .keydownEvents()\n .pipe(takeUntil(this._afterClosed))\n .subscribe((event) => {\n if (event.key === 'Escape') {\n event.preventDefault();\n this.close();\n }\n });\n }\n }\n\n /**\n * Closes the overlay, emitting `result` on `afterClosed$`, disposing the CDK\n * ref, and restoring focus. Idempotent - a second call (e.g. Escape after a\n * scope teardown already closed it) is a no-op.\n */\n close(result?: R): void {\n if (!this.openState()) {\n return;\n }\n this.openState.set(false);\n this._afterClosed.next(result);\n this._afterClosed.complete();\n this.cdkRef.dispose();\n this.restoreFocusTo?.focus();\n }\n}\n","import { DOCUMENT } from '@angular/common';\nimport {\n DestroyRef,\n Injectable,\n Injector,\n inject,\n makeEnvironmentProviders,\n type EnvironmentProviders,\n type Type,\n} from '@angular/core';\nimport { Overlay, OverlayConfig, type OverlayRef as CdkOverlayRef } from '@angular/cdk/overlay';\nimport { ComponentPortal } from '@angular/cdk/portal';\nimport { CngxOverlayRef } from './overlay-ref';\n\n/**\n * Config accepted by {@link CngxOverlay.open}. A partial of CDK's\n * {@link OverlayConfig} - every field is optional and falls back to the CDK\n * overlay default - plus `disableClose`, a cngx addition that turns off the\n * Escape / backdrop dismiss affordances.\n *\n * @category ui/overlay\n */\nexport type CngxOverlayConfig = Partial<OverlayConfig> & {\n /**\n * When `true`, Escape and backdrop clicks do not close the overlay; only a\n * programmatic `close()` does. Default `false`.\n */\n readonly disableClose?: boolean;\n};\n\n/**\n * Thin service over CDK Overlay that returns a typed CngxOverlayRef.\n *\n * Must be provided via `provideOverlay()` in application or component providers.\n * ```ts\n * // app.config.ts\n * provideOverlay()\n\n * // usage\n * const ref = overlayService.open(MyComponent, { hasBackdrop: true });\n * ref.afterClosed$.subscribe(result => console.log(result));\n* ```\n *\n * @category ui/overlay\n * @docsKind primary\n * @wcag AA\n * @github https://github.com/cngxjs/cngx/blob/main/projects/ui/overlay/overlay.service.ts\n * @since 0.1.0\n * @relatedTo CngxOverlayRef, provideOverlay\n */\n@Injectable()\nexport class CngxOverlay {\n private readonly overlay = inject(Overlay);\n private readonly injector = inject(Injector);\n private readonly document = inject(DOCUMENT);\n // Held by the only capability the registry needs; the generic CngxOverlayRef\n // is invariant in R (its Subject leaks into the type), so a structural close\n // handle sidesteps that without an unknown-cast.\n private readonly openRefs = new Set<{ close(): void }>();\n\n constructor() {\n // The service is destroyed with its providing scope (component or\n // environment injector). Anything still open would otherwise leak a\n // detached overlay panel and its subscriptions - close them.\n inject(DestroyRef).onDestroy(() => {\n for (const ref of [...this.openRefs]) {\n ref.close();\n }\n });\n }\n\n /**\n * Opens `component` in a CDK overlay panel and returns a typed ref.\n *\n * Defaults to a centered, backdropped panel that closes on Escape or a\n * backdrop click; pass `disableClose` to opt out. Focus returns to the\n * element that was focused at open time. Merge `config` to override position\n * strategy, scroll strategy, or any other CDK `OverlayConfig` option.\n *\n * @param component Component class to attach as a portal.\n * @param config Overlay configuration overrides (CDK options + `disableClose`).\n */\n open<C, R = unknown>(component: Type<C>, config: CngxOverlayConfig = {}): CngxOverlayRef<R> {\n const { disableClose, ...cdkConfig } = config;\n const overlayConfig = new OverlayConfig({\n hasBackdrop: true,\n positionStrategy: this.overlay.position().global().centerHorizontally().centerVertically(),\n ...cdkConfig,\n });\n\n const cdkRef: CdkOverlayRef = this.overlay.create(overlayConfig);\n // Capture the opener BEFORE attaching, so focus can return to it on close.\n const restoreFocusTo = this.document.activeElement as HTMLElement | null;\n const ngxRef = new CngxOverlayRef<R>(cdkRef, { disableClose, restoreFocusTo });\n\n this.openRefs.add(ngxRef);\n ngxRef.afterClosed$.subscribe({ complete: () => this.openRefs.delete(ngxRef) });\n\n const injector = Injector.create({\n parent: this.injector,\n providers: [{ provide: CngxOverlayRef, useValue: ngxRef }],\n });\n\n const portal = new ComponentPortal(component, null, injector);\n cdkRef.attach(portal);\n return ngxRef;\n }\n}\n\n/**\n * Provides `CngxOverlay` as an environment-scoped service.\n *\n * @category ui/overlay\n */\nexport function provideOverlay(): EnvironmentProviders {\n return makeEnvironmentProviders([CngxOverlay]);\n}\n","/**\n * Public API Surface of @cngx/ui/overlay\n * @module @cngx/ui/overlay\n */\n\nexport { CngxOverlay, provideOverlay, type CngxOverlayConfig } from './overlay.service';\nexport { CngxOverlayRef } from './overlay-ref';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;AAuBA;;;;;;;;;;;;;AAaG;MACU,cAAc,CAAA;AAiBN,IAAA,MAAA;AAhBF,IAAA,YAAY,GAAG,IAAI,OAAO,EAAiB;;AAGnD,IAAA,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE;AAEvC,IAAA,SAAS,GAAG,MAAM,CAAC,IAAI,gFAAC;AACzC;;;;AAIG;AACM,IAAA,MAAM,GAAoB,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE;AAE7C,IAAA,cAAc;IAE/B,WAAA,CACmB,MAAqB,EACtC,MAAA,GAA+B,EAAE,EAAA;QADhB,IAAA,CAAA,MAAM,GAAN,MAAM;QAGvB,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,cAAc,IAAI,IAAI;AAEnD,QAAA,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE;YACxB;AACG,iBAAA,aAAa;AACb,iBAAA,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC;iBACjC,SAAS,CAAC,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;YAChC;AACG,iBAAA,aAAa;AACb,iBAAA,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC;AACjC,iBAAA,SAAS,CAAC,CAAC,KAAK,KAAI;AACnB,gBAAA,IAAI,KAAK,CAAC,GAAG,KAAK,QAAQ,EAAE;oBAC1B,KAAK,CAAC,cAAc,EAAE;oBACtB,IAAI,CAAC,KAAK,EAAE;gBACd;AACF,YAAA,CAAC,CAAC;QACN;IACF;AAEA;;;;AAIG;AACH,IAAA,KAAK,CAAC,MAAU,EAAA;AACd,QAAA,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE;YACrB;QACF;AACA,QAAA,IAAI,CAAC,SAAS,CAAC,GAAG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