@cngx/common 0.1.0-rc.6 → 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 (72) hide show
  1. package/card/README.md +2 -1
  2. package/chart/README.md +85 -0
  3. package/command/README.md +157 -0
  4. package/data/README.md +33 -1
  5. package/dialog/README.md +23 -1
  6. package/fesm2022/cngx-common-a11y.mjs +356 -180
  7. package/fesm2022/cngx-common-a11y.mjs.map +1 -1
  8. package/fesm2022/cngx-common-audio.mjs +84 -42
  9. package/fesm2022/cngx-common-audio.mjs.map +1 -1
  10. package/fesm2022/cngx-common-card.mjs +311 -53
  11. package/fesm2022/cngx-common-card.mjs.map +1 -1
  12. package/fesm2022/cngx-common-chart.mjs +4360 -1625
  13. package/fesm2022/cngx-common-chart.mjs.map +1 -1
  14. package/fesm2022/cngx-common-command.mjs +171 -0
  15. package/fesm2022/cngx-common-command.mjs.map +1 -0
  16. package/fesm2022/cngx-common-data.mjs +1556 -616
  17. package/fesm2022/cngx-common-data.mjs.map +1 -1
  18. package/fesm2022/cngx-common-dialog.mjs +518 -112
  19. package/fesm2022/cngx-common-dialog.mjs.map +1 -1
  20. package/fesm2022/cngx-common-display.mjs +468 -87
  21. package/fesm2022/cngx-common-display.mjs.map +1 -1
  22. package/fesm2022/cngx-common-interactive.mjs +2725 -1303
  23. package/fesm2022/cngx-common-interactive.mjs.map +1 -1
  24. package/fesm2022/cngx-common-layout.mjs +943 -164
  25. package/fesm2022/cngx-common-layout.mjs.map +1 -1
  26. package/fesm2022/cngx-common-popover.mjs +769 -103
  27. package/fesm2022/cngx-common-popover.mjs.map +1 -1
  28. package/fesm2022/cngx-common-stepper.mjs +816 -348
  29. package/fesm2022/cngx-common-stepper.mjs.map +1 -1
  30. package/fesm2022/cngx-common-tabs.mjs +2330 -1554
  31. package/fesm2022/cngx-common-tabs.mjs.map +1 -1
  32. package/fesm2022/cngx-common-timeline.mjs +1170 -0
  33. package/fesm2022/cngx-common-timeline.mjs.map +1 -0
  34. package/fesm2022/cngx-common.mjs +2 -2
  35. package/fesm2022/cngx-common.mjs.map +1 -1
  36. package/interactive/README.md +15 -4
  37. package/layout/README.md +21 -1
  38. package/package.json +11 -1
  39. package/popover/README.md +18 -2
  40. package/stepper/README.md +7 -5
  41. package/theming/components/cngx-accordion.css +4 -1
  42. package/theming/components/cngx-backdrop.css +12 -0
  43. package/theming/components/cngx-badge.css +22 -0
  44. package/theming/components/cngx-bottom-sheet.css +14 -2
  45. package/theming/components/cngx-breadcrumb.css +8 -0
  46. package/theming/components/cngx-button-toggle.css +73 -5
  47. package/theming/components/cngx-data-grid.css +234 -1
  48. package/theming/components/cngx-dialog.css +25 -0
  49. package/theming/components/cngx-divider.css +12 -0
  50. package/theming/components/cngx-listbox.css +48 -12
  51. package/theming/components/cngx-menu.css +91 -15
  52. package/theming/components/cngx-popover.css +24 -0
  53. package/theming/components/cngx-recycler-placeholder.css +196 -0
  54. package/theming/components/cngx-ripple.css +2 -2
  55. package/theming/components/cngx-slider.css +32 -1
  56. package/theming/components/cngx-tooltip.css +23 -0
  57. package/timeline/README.md +155 -0
  58. package/types/cngx-common-a11y.d.ts +101 -31
  59. package/types/cngx-common-audio.d.ts +32 -32
  60. package/types/cngx-common-card.d.ts +211 -20
  61. package/types/cngx-common-chart.d.ts +1605 -169
  62. package/types/cngx-common-command.d.ts +190 -0
  63. package/types/cngx-common-data.d.ts +842 -163
  64. package/types/cngx-common-dialog.d.ts +372 -28
  65. package/types/cngx-common-display.d.ts +432 -148
  66. package/types/cngx-common-interactive.d.ts +1553 -370
  67. package/types/cngx-common-layout.d.ts +613 -27
  68. package/types/cngx-common-popover.d.ts +376 -36
  69. package/types/cngx-common-stepper.d.ts +414 -114
  70. package/types/cngx-common-tabs.d.ts +597 -72
  71. package/types/cngx-common-timeline.d.ts +1125 -0
  72. package/types/cngx-common.d.ts +1 -1
@@ -1,8 +1,10 @@
1
1
  import * as i0 from '@angular/core';
2
- import { InjectionToken, signal, computed, Injectable, inject, ElementRef, Directive, Renderer2, DestroyRef, contentChild, input, effect, isDevMode, viewChild, ViewContainerRef, ChangeDetectionStrategy, Component, ApplicationRef, EnvironmentInjector, Injector, createComponent } from '@angular/core';
2
+ import { InjectionToken, inject, signal, computed, Injectable, ElementRef, DestroyRef, Directive, Renderer2, contentChild, input, effect, untracked, isDevMode, viewChild, ViewContainerRef, ChangeDetectionStrategy, Component, ApplicationRef, EnvironmentInjector, Injector, createComponent } from '@angular/core';
3
3
  import { DOCUMENT } from '@angular/common';
4
- import { nextUid, buildAsyncStateView, hasTransition, onTransitionDone } from '@cngx/core/utils';
4
+ import { createOverrideMerge, nextUid, coerceSignal, buildAsyncStateView, hasTransition, onTransitionDone } from '@cngx/core/utils';
5
+ import { createScrollLock } from '@cngx/common/layout';
5
6
  import { isObservable, firstValueFrom, filter, take, map } from 'rxjs';
7
+ import { createLanguageSection } from '@cngx/core/i18n';
6
8
  import { toObservable } from '@angular/core/rxjs-interop';
7
9
  import { CngxSwipeDismiss } from '@cngx/common/interactive';
8
10
 
@@ -15,6 +17,111 @@ import { CngxSwipeDismiss } from '@cngx/common/interactive';
15
17
  */
16
18
  const DIALOG_REF = new InjectionToken('CngxDialogRef');
17
19
 
20
+ /**
21
+ * The English dialog section: the single source of the dialog family's
22
+ * English copy. The `CNGX_DIALOG_DEFAULTS` labels default to it.
23
+ *
24
+ * @category common/dialog/i18n
25
+ * @since 0.1.0
26
+ * @relatedTo CNGX_DIALOG_DEFAULTS
27
+ */
28
+ const CNGX_DIALOG_LANGUAGE_EN = {
29
+ close: 'Close dialog',
30
+ errorFallback: 'An error occurred',
31
+ dragHandle: 'Move dialog',
32
+ dragHandleRoleDescription: 'draggable',
33
+ dragInstructions: 'Use arrow keys to move the dialog; Shift for larger steps',
34
+ };
35
+
36
+ /** @internal The dialog section of the active pack over the English labels. */
37
+ const dialogLabelsFromPack = createLanguageSection('dialog', CNGX_DIALOG_LANGUAGE_EN);
38
+ /**
39
+ * DI token carrying the merged {@link CngxDialogDefaults}. `providedIn: 'root'`:
40
+ * `labels` is the dialog section of the active language pack over the English
41
+ * defaults, so a consumer who provides nothing keeps today's behaviour
42
+ * exactly.
43
+ *
44
+ * @category common/dialog/config
45
+ * @wcag AA
46
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/dialog/config/dialog-config.ts
47
+ * @since 0.1.0
48
+ * @relatedTo CngxDialog, CngxDialogClose, CngxDialogDraggable
49
+ */
50
+ const CNGX_DIALOG_DEFAULTS = new InjectionToken('CngxDialogDefaults', {
51
+ providedIn: 'root',
52
+ factory: () => ({ labels: dialogLabelsFromPack() }),
53
+ });
54
+ /**
55
+ * Override dialog interaction strings. Unset keys keep the language pack's
56
+ * text, or the English default, and two calls merge rather than replace.
57
+ * Pass a `Signal` to switch the language at runtime.
58
+ *
59
+ * ```ts
60
+ * bootstrapApplication(AppComponent, {
61
+ * providers: [
62
+ * provideDialogConfig(
63
+ * withDialogLabels({ close: 'Dialog schließen', dragHandle: 'Dialog verschieben' }),
64
+ * ),
65
+ * ],
66
+ * });
67
+ * ```
68
+ *
69
+ * @category common/dialog/config
70
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/dialog/config/dialog-config.ts
71
+ * @since 0.1.0
72
+ */
73
+ function withDialogLabels(overrides) {
74
+ return { labels: overrides };
75
+ }
76
+ /**
77
+ * Register app-wide dialog defaults composed from `with*` features, applied
78
+ * on top of the active language pack.
79
+ *
80
+ * @category common/dialog/config
81
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/dialog/config/dialog-config.ts
82
+ * @since 0.1.0
83
+ */
84
+ function provideDialogConfig(...features) {
85
+ return [
86
+ {
87
+ provide: CNGX_DIALOG_DEFAULTS,
88
+ useFactory: () => ({
89
+ labels: features.reduce((acc, feature) => createOverrideMerge(acc, feature.labels), dialogLabelsFromPack()),
90
+ }),
91
+ },
92
+ ];
93
+ }
94
+ /**
95
+ * Sub-tree variant - use in `viewProviders` so the defaults only apply to
96
+ * dialogs opened from descendants of this component.
97
+ *
98
+ * @category common/dialog/config
99
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/dialog/config/dialog-config.ts
100
+ * @since 0.1.0
101
+ */
102
+ function provideDialogConfigAt(...features) {
103
+ return provideDialogConfig(...features);
104
+ }
105
+ /**
106
+ * Inject the currently-resolved dialog defaults. Safe in any injection
107
+ * context; falls back to the English bundle when nothing is provided.
108
+ *
109
+ * @category common/dialog/config
110
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/dialog/config/dialog-config.ts
111
+ * @since 0.1.0
112
+ */
113
+ function injectDialogConfig() {
114
+ return inject(CNGX_DIALOG_DEFAULTS);
115
+ }
116
+
117
+ /**
118
+ * Injection token for the dialog ARIA registry.
119
+ *
120
+ * Provided by `CngxDialog` (`useExisting`) on the dialog element and by
121
+ * `CngxDialogOpener` on the programmatic content's child injector.
122
+ */
123
+ const CNGX_DIALOG_ARIA_REGISTRY = new InjectionToken('CngxDialogAriaRegistry');
124
+
18
125
  /**
19
126
  * Tracks open dialog instances as a stack for backdrop management.
20
127
  *
@@ -111,25 +218,36 @@ function provideDialogStack() {
111
218
  * <example-url>http://localhost:4200/#/common/dialog/template-directives</example-url>
112
219
  */
113
220
  class CngxDialogTitle {
114
- elRef = inject((ElementRef));
221
+ elRef = inject(ElementRef);
115
222
  dialogRef = inject(DIALOG_REF, { optional: true });
223
+ ariaRegistry = inject(CNGX_DIALOG_ARIA_REGISTRY, { optional: true });
224
+ destroyRef = inject(DestroyRef);
225
+ idState = signal(nextUid('cngx-dialog-title'), ...(ngDevMode ? [{ debugName: "idState" }] : /* istanbul ignore next */ []));
116
226
  /**
117
227
  * Auto-generated unique ID bound to the host `[id]` attribute.
118
228
  *
119
229
  * Used by `CngxDialog` for `aria-labelledby`. When a parent `CngxDialog`
120
230
  * is present, the ID is derived from the dialog's ID (e.g. `cngx-dialog-0-title`).
231
+ * Read-only: an externally mutated id would silently break the ARIA wiring.
121
232
  */
122
- id = signal(nextUid('cngx-dialog-title'), ...(ngDevMode ? [{ debugName: "id" }] : /* istanbul ignore next */ []));
233
+ id = this.idState.asReadonly();
123
234
  /**
124
- * Text content of the title element.
235
+ * Text content of the title element, read fresh on every call.
125
236
  *
126
- * Read by `CngxDialog` on open to announce the dialog title via
127
- * an `aria-live` region for screen readers.
237
+ * Read by `CngxDialog` at announce time (each `'open'` transition) so a
238
+ * changed title - translation swap, interpolated data - is what screen
239
+ * readers hear. A `computed` would cache the first non-reactive DOM read
240
+ * forever.
128
241
  */
129
- textContent = computed(() => this.elRef.nativeElement.textContent?.trim() ?? '', ...(ngDevMode ? [{ debugName: "textContent" }] : /* istanbul ignore next */ []));
242
+ textContent = () => this.elRef.nativeElement.textContent?.trim() ?? '';
130
243
  constructor() {
131
244
  if (this.dialogRef) {
132
- this.id.set(`${this.dialogRef.id()}-title`);
245
+ this.idState.set(`${this.dialogRef.id()}-title`);
246
+ }
247
+ // Push registration: content queries cannot see dynamically created
248
+ // views, so programmatic dialogs rely on this channel exclusively.
249
+ if (this.ariaRegistry) {
250
+ this.destroyRef.onDestroy(this.ariaRegistry.registerTitle(this));
133
251
  }
134
252
  }
135
253
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDialogTitle, deps: [], target: i0.ɵɵFactoryTarget.Directive });
@@ -180,16 +298,25 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
180
298
  */
181
299
  class CngxDialogDescription {
182
300
  dialogRef = inject(DIALOG_REF, { optional: true });
301
+ ariaRegistry = inject(CNGX_DIALOG_ARIA_REGISTRY, { optional: true });
302
+ destroyRef = inject(DestroyRef);
303
+ idState = signal(nextUid('cngx-dialog-desc'), ...(ngDevMode ? [{ debugName: "idState" }] : /* istanbul ignore next */ []));
183
304
  /**
184
305
  * Auto-generated unique ID bound to the host `[id]` attribute.
185
306
  *
186
307
  * Used by `CngxDialog` for `aria-describedby`. When a parent `CngxDialog`
187
308
  * is present, the ID is derived from the dialog's ID (e.g. `cngx-dialog-0-desc`).
309
+ * Read-only: an externally mutated id would silently break the ARIA wiring.
188
310
  */
189
- id = signal(nextUid('cngx-dialog-desc'), ...(ngDevMode ? [{ debugName: "id" }] : /* istanbul ignore next */ []));
311
+ id = this.idState.asReadonly();
190
312
  constructor() {
191
313
  if (this.dialogRef) {
192
- this.id.set(`${this.dialogRef.id()}-desc`);
314
+ this.idState.set(`${this.dialogRef.id()}-desc`);
315
+ }
316
+ // Push registration: content queries cannot see dynamically created
317
+ // views, so programmatic dialogs rely on this channel exclusively.
318
+ if (this.ariaRegistry) {
319
+ this.destroyRef.onDestroy(this.ariaRegistry.registerDescription(this));
193
320
  }
194
321
  }
195
322
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDialogDescription, deps: [], target: i0.ɵɵFactoryTarget.Directive });
@@ -208,44 +335,29 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
208
335
  }], ctorParameters: () => [] });
209
336
 
210
337
  /**
211
- * Ref-count map for scroll lock - one lock per document root, shared across stacked modals.
338
+ * Apply the visually-hidden (screen-reader-only) recipe to a dynamically
339
+ * created dialog node.
212
340
  *
213
- * @internal
214
- */
215
- const lockCounts = new WeakMap();
216
- /**
217
- * Acquire a scroll lock on the document root, preserving prior overflow styles.
341
+ * Inline styles instead of relying on the `cngx-sr-only` class alone so the
342
+ * live region and the drag instruction stay hidden even when no cngx
343
+ * stylesheet is loaded. The node remains perceivable to AT - describedby
344
+ * targets and live regions must never be `display: none`.
218
345
  *
219
- * @internal
346
+ * Internal helper - intentionally not exported from `public-api.ts`.
220
347
  */
221
- function acquireScrollLock(html) {
222
- const count = lockCounts.get(html) ?? 0;
223
- if (count === 0) {
224
- html.dataset['cngxPrevOverflow'] = html.style.overflow;
225
- html.dataset['cngxPrevScrollbarGutter'] = html.style.scrollbarGutter;
226
- html.style.overflow = 'hidden';
227
- html.style.scrollbarGutter = 'stable';
228
- }
229
- lockCounts.set(html, count + 1);
230
- }
231
- /**
232
- * Release a scroll lock. Restores prior overflow styles when the count reaches zero.
233
- *
234
- * @internal
235
- */
236
- function releaseScrollLock(html) {
237
- const count = lockCounts.get(html) ?? 0;
238
- if (count <= 1) {
239
- html.style.overflow = html.dataset['cngxPrevOverflow'] ?? '';
240
- html.style.scrollbarGutter = html.dataset['cngxPrevScrollbarGutter'] ?? '';
241
- delete html.dataset['cngxPrevOverflow'];
242
- delete html.dataset['cngxPrevScrollbarGutter'];
243
- lockCounts.set(html, 0);
244
- }
245
- else {
246
- lockCounts.set(html, count - 1);
247
- }
348
+ function applySrOnly(el) {
349
+ el.className = 'cngx-sr-only';
350
+ el.style.position = 'absolute';
351
+ el.style.width = '1px';
352
+ el.style.height = '1px';
353
+ el.style.padding = '0';
354
+ el.style.margin = '-1px';
355
+ el.style.overflow = 'hidden';
356
+ el.style.clip = 'rect(0, 0, 0, 0)';
357
+ el.style.whiteSpace = 'nowrap';
358
+ el.style.border = '0';
248
359
  }
360
+
249
361
  /**
250
362
  * Signal-driven state machine for native `<dialog>`.
251
363
  *
@@ -325,8 +437,18 @@ class CngxDialog {
325
437
  renderer = inject(Renderer2);
326
438
  destroyRef = inject(DestroyRef);
327
439
  dialogStack = inject(CngxDialogStack);
440
+ labels = coerceSignal(injectDialogConfig().labels);
441
+ // Armed while a close transition runs; cancelled on destroy so the
442
+ // transitionend listener and fallback timer never outlive the directive.
443
+ pendingClose = null;
328
444
  titleDirective = contentChild(CngxDialogTitle, ...(ngDevMode ? [{ debugName: "titleDirective" }] : /* istanbul ignore next */ []));
329
445
  descriptionDirective = contentChild(CngxDialogDescription, ...(ngDevMode ? [{ debugName: "descriptionDirective" }] : /* istanbul ignore next */ []));
446
+ // Push-registered counterparts of the content queries above. Programmatic
447
+ // content lives in a dynamically created view the queries cannot see, so
448
+ // sources register through CNGX_DIALOG_ARIA_REGISTRY instead.
449
+ registeredTitle = signal(null, ...(ngDevMode ? [{ debugName: "registeredTitle" }] : /* istanbul ignore next */ []));
450
+ registeredDescription = signal(null, ...(ngDevMode ? [{ debugName: "registeredDescription" }] : /* istanbul ignore next */ []));
451
+ supplementalDescribedByIds = signal([], ...(ngDevMode ? [{ debugName: "supplementalDescribedByIds" }] : /* istanbul ignore next */ []));
330
452
  /**
331
453
  * Whether the dialog opens as modal (`showModal()`) or non-modal (`show()`).
332
454
  *
@@ -479,16 +601,34 @@ class CngxDialog {
479
601
  isOpening = computed(() => this.lifecycleSignal() === 'opening', ...(ngDevMode ? [{ debugName: "isOpening" }] : /* istanbul ignore next */ []));
480
602
  isOpen = computed(() => this.lifecycleSignal() === 'open', ...(ngDevMode ? [{ debugName: "isOpen" }] : /* istanbul ignore next */ []));
481
603
  isClosing = computed(() => this.lifecycleSignal() === 'closing', ...(ngDevMode ? [{ debugName: "isClosing" }] : /* istanbul ignore next */ []));
482
- ariaModal = computed(() => this.modal() && this.lifecycleSignal() !== 'closed' ? 'true' : null, ...(ngDevMode ? [{ debugName: "ariaModal" }] : /* istanbul ignore next */ []));
483
- ariaLabelledBy = computed(() => this.titleDirective()?.id() ?? null, ...(ngDevMode ? [{ debugName: "ariaLabelledBy" }] : /* istanbul ignore next */ []));
484
- ariaDescribedBy = computed(() => this.descriptionDirective()?.id() ?? null, ...(ngDevMode ? [{ debugName: "ariaDescribedBy" }] : /* istanbul ignore next */ []));
604
+ ariaModal = computed(() => this.openedAsModal() && this.lifecycleSignal() !== 'closed' ? 'true' : null, ...(ngDevMode ? [{ debugName: "ariaModal" }] : /* istanbul ignore next */ []));
605
+ ariaLabelledBy = computed(() => (this.titleDirective() ?? this.registeredTitle())?.id() ?? null, ...(ngDevMode ? [{ debugName: "ariaLabelledBy" }] : /* istanbul ignore next */ []));
606
+ ariaDescribedBy = computed(() => {
607
+ const ids = [];
608
+ const descriptionId = (this.descriptionDirective() ?? this.registeredDescription())?.id();
609
+ if (descriptionId) {
610
+ ids.push(descriptionId);
611
+ }
612
+ for (const id of this.supplementalDescribedByIds()) {
613
+ ids.push(typeof id === 'string' ? id : id());
614
+ }
615
+ return ids.length > 0 ? ids.join(' ') : null;
616
+ }, ...(ngDevMode ? [{ debugName: "ariaDescribedBy" }] : /* istanbul ignore next */ []));
485
617
  backdropOpacity = computed(() => this.dialogStack.topmost() === this.idSignal() ? '1' : '0', ...(ngDevMode ? [{ debugName: "backdropOpacity" }] : /* istanbul ignore next */ []));
486
618
  liveRegion = null;
619
+ /**
620
+ * The modal mode latched at `open()`. Everything that depends on how the
621
+ * dialog actually opened derives from this - scroll-lock release, stack
622
+ * pop, Escape/backdrop dismissal, focus strategy, and `aria-modal` -
623
+ * so toggling `[modal]` while open can neither unbalance the ref count
624
+ * nor strand a rendered backdrop without its dismissal surface.
625
+ */
626
+ openedAsModal = signal(false, ...(ngDevMode ? [{ debugName: "openedAsModal" }] : /* istanbul ignore next */ []));
487
627
  constructor() {
488
628
  this.createLiveRegion();
489
629
  effect(() => {
490
630
  if (this.lifecycleSignal() === 'open') {
491
- const titleText = this.titleDirective()?.textContent() ?? '';
631
+ const titleText = untracked(() => (this.titleDirective() ?? this.registeredTitle())?.textContent?.() ?? '');
492
632
  if (titleText && this.liveRegion) {
493
633
  this.liveRegion.textContent = titleText;
494
634
  // Clear after one frame so subsequent opens re-announce
@@ -501,17 +641,65 @@ class CngxDialog {
501
641
  }
502
642
  });
503
643
  effect(() => {
644
+ // The error VALUE is the announce trigger and stays tracked: the
645
+ // boolean effectiveError() alone is equal-cut on true -> false -> true,
646
+ // so a retried identical failure would never re-fire this effect.
504
647
  if (this.effectiveError() && this.liveRegion) {
505
648
  const errMsg = this.state()?.error() ?? this.submitErrorState();
506
- this.liveRegion.textContent = typeof errMsg === 'string' ? errMsg : 'An error occurred';
649
+ // The fallback copy is read untracked: a language switch must not
650
+ // re-fire the announcement; the next error speaks the new language.
651
+ this.liveRegion.textContent =
652
+ typeof errMsg === 'string' ? errMsg : untracked(() => this.labels().errorFallback);
653
+ // Clear after one frame (same pattern as the title announce) so a
654
+ // repeated identical error is a fresh mutation the SR re-announces.
655
+ requestAnimationFrame(() => {
656
+ if (this.liveRegion) {
657
+ this.liveRegion.textContent = '';
658
+ }
659
+ });
507
660
  }
508
661
  });
509
662
  this.destroyRef.onDestroy(() => {
663
+ // finalize() disarms pendingClose; a 'closed' lifecycle means it
664
+ // already ran and the handle is gone.
510
665
  if (this.lifecycleSignal() !== 'closed') {
511
666
  this.finalize();
512
667
  }
513
668
  });
514
669
  }
670
+ /**
671
+ * Register the labelling source for `aria-labelledby` and the open announce.
672
+ *
673
+ * A present content-queried title wins over the registered handle (same
674
+ * directive in the declarative case - identical id either way).
675
+ *
676
+ * @internal CNGX_DIALOG_ARIA_REGISTRY implementation - not public API.
677
+ */
678
+ registerTitle(handle) {
679
+ this.warnDoubleRegistration('title', untracked(this.registeredTitle), handle);
680
+ this.registeredTitle.set(handle);
681
+ return () => this.registeredTitle.update((current) => (current === handle ? null : current));
682
+ }
683
+ /**
684
+ * Register the primary description source for `aria-describedby`.
685
+ *
686
+ * @internal CNGX_DIALOG_ARIA_REGISTRY implementation - not public API.
687
+ */
688
+ registerDescription(handle) {
689
+ this.warnDoubleRegistration('description', untracked(this.registeredDescription), handle);
690
+ this.registeredDescription.set(handle);
691
+ return () => this.registeredDescription.update((current) => (current === handle ? null : current));
692
+ }
693
+ /**
694
+ * Register a supplemental `aria-describedby` id, merged after the
695
+ * description id in registration order.
696
+ *
697
+ * @internal CNGX_DIALOG_ARIA_REGISTRY implementation - not public API.
698
+ */
699
+ registerDescribedBy(id) {
700
+ this.supplementalDescribedByIds.update((ids) => [...ids, id]);
701
+ return () => this.supplementalDescribedByIds.update((ids) => ids.filter((x) => x !== id));
702
+ }
515
703
  /**
516
704
  * Open the dialog.
517
705
  *
@@ -531,7 +719,8 @@ class CngxDialog {
531
719
  this.submitErrorState.set(undefined);
532
720
  this.triggerElement.set(this.doc.activeElement);
533
721
  this.lifecycleSignal.set('opening');
534
- if (this.modal()) {
722
+ this.openedAsModal.set(this.modal());
723
+ if (this.openedAsModal()) {
535
724
  dialog.showModal();
536
725
  this.acquireScrollLock();
537
726
  this.dialogStack.push(this.idSignal());
@@ -624,52 +813,77 @@ class CngxDialog {
624
813
  }
625
814
  handleCancel(event) {
626
815
  event.preventDefault();
627
- if (this.closeOnEscape() && this.modal()) {
816
+ if (this.closeOnEscape() && this.openedAsModal()) {
628
817
  this.dismiss();
629
818
  }
630
819
  }
820
+ /**
821
+ * `true` when the last pointerdown landed on the backdrop (the dialog
822
+ * element itself, outside the content rect). Backdrop dismissal requires
823
+ * the interaction to START there: a text-selection drag that begins inside
824
+ * the content and releases over the backdrop synthesises a click with
825
+ * outside coordinates and must not dismiss.
826
+ */
827
+ pointerDownOnBackdrop = false;
828
+ handlePointerDown(event) {
829
+ this.pointerDownOnBackdrop =
830
+ event.target === this.dialogElement && this.isOutsideContentRect(event.clientX, event.clientY);
831
+ }
631
832
  handleClick(event) {
632
- if (!this.modal() || !this.closeOnBackdropClick()) {
833
+ const startedOnBackdrop = this.pointerDownOnBackdrop;
834
+ this.pointerDownOnBackdrop = false;
835
+ if (!this.openedAsModal() || !this.closeOnBackdropClick()) {
633
836
  return;
634
837
  }
635
838
  if (this.lifecycleSignal() !== 'open') {
636
839
  return;
637
840
  }
638
- // Detect backdrop click: click coordinates outside dialog content rect
639
- const rect = this.dialogElement.getBoundingClientRect();
640
- if (event.clientX < rect.left ||
641
- event.clientX > rect.right ||
642
- event.clientY < rect.top ||
643
- event.clientY > rect.bottom) {
841
+ // Keyboard "clicks" (Enter/Space on a child control) report (0, 0)
842
+ // coordinates - the target guard rejects them because they target the
843
+ // control, never the dialog element itself.
844
+ if (event.target !== this.dialogElement || !startedOnBackdrop) {
845
+ return;
846
+ }
847
+ if (this.isOutsideContentRect(event.clientX, event.clientY)) {
644
848
  this.dismiss();
645
849
  }
646
850
  }
851
+ /** Backdrop test: coordinates outside the dialog's content rect. */
852
+ isOutsideContentRect(x, y) {
853
+ const rect = this.dialogElement.getBoundingClientRect();
854
+ return x < rect.left || x > rect.right || y < rect.top || y > rect.bottom;
855
+ }
647
856
  get dialogElement() {
648
857
  return this.elRef.nativeElement;
649
858
  }
650
859
  startClosing() {
651
860
  if (hasTransition(this.dialogElement)) {
652
861
  this.lifecycleSignal.set('closing');
653
- onTransitionDone(this.dialogElement, () => this.finalize());
862
+ this.pendingClose = onTransitionDone(this.dialogElement, () => this.finalize());
654
863
  }
655
864
  else {
656
865
  this.finalize();
657
866
  }
658
867
  }
659
868
  finalize() {
869
+ // Disarm any pending close wait no matter which path got here, so the
870
+ // settled handle never lingers as a stale armed field.
871
+ this.pendingClose?.cancel();
872
+ this.pendingClose = null;
660
873
  const dialog = this.dialogElement;
661
874
  if (dialog.open) {
662
875
  dialog.close();
663
876
  }
664
- if (this.modal()) {
877
+ if (this.openedAsModal()) {
665
878
  this.releaseScrollLock();
666
879
  this.dialogStack.pop(this.idSignal());
880
+ this.openedAsModal.set(false);
667
881
  }
668
882
  this.lifecycleSignal.set('closed');
669
883
  this.returnFocus();
670
884
  }
671
885
  moveFocus() {
672
- if (!this.modal()) {
886
+ if (!this.openedAsModal()) {
673
887
  return;
674
888
  }
675
889
  const strategy = this.autoFocus();
@@ -707,24 +921,37 @@ class CngxDialog {
707
921
  const span = this.renderer.createElement('span');
708
922
  span.setAttribute('aria-live', 'polite');
709
923
  span.setAttribute('aria-atomic', 'true');
710
- span.className = 'cngx-sr-only';
711
- span.style.position = 'absolute';
712
- span.style.width = '1px';
713
- span.style.height = '1px';
714
- span.style.padding = '0';
715
- span.style.margin = '-1px';
716
- span.style.overflow = 'hidden';
717
- span.style.clip = 'rect(0, 0, 0, 0)';
718
- span.style.whiteSpace = 'nowrap';
719
- span.style.border = '0';
924
+ applySrOnly(span);
720
925
  this.renderer.appendChild(this.dialogElement, span);
721
926
  this.liveRegion = span;
722
927
  }
928
+ /**
929
+ * Release function of the currently held scroll lock, `null` while not
930
+ * locked. The shared `createScrollLock` core (single WeakMap owner in
931
+ * `@cngx/common/layout`) keeps this instance's count in the same registry
932
+ * as `CngxScrollLock`, so interleaved dialog + directive locks restore the
933
+ * saved overflow values correctly.
934
+ */
935
+ scrollLockRelease = null;
723
936
  acquireScrollLock() {
724
- acquireScrollLock(this.doc.documentElement);
937
+ this.scrollLockRelease ??= createScrollLock(this.doc.documentElement);
725
938
  }
726
939
  releaseScrollLock() {
727
- releaseScrollLock(this.doc.documentElement);
940
+ this.scrollLockRelease?.();
941
+ this.scrollLockRelease = null;
942
+ }
943
+ /**
944
+ * The registry is single-slot per kind, so a second live registration
945
+ * silently wins - surface the authoring error instead of letting the
946
+ * two open paths resolve different labelling.
947
+ */
948
+ warnDoubleRegistration(kind, current, next) {
949
+ if (!isDevMode() || current === null || current === next) {
950
+ return;
951
+ }
952
+ console.warn(`CngxDialog [${this.idSignal()}]: a second ${kind} registered while another ` +
953
+ `is live. The dialog references one ${kind} id - the newest registration ` +
954
+ `wins. Remove the extra cngxDialog${kind === 'title' ? 'Title' : 'Description'} element.`);
728
955
  }
729
956
  warnNonModalA11y() {
730
957
  if (!isDevMode()) {
@@ -743,7 +970,10 @@ class CngxDialog {
743
970
  }
744
971
  }
745
972
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDialog, deps: [], target: i0.ɵɵFactoryTarget.Directive });
746
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.2.0", version: "21.2.4", type: CngxDialog, isStandalone: true, selector: "dialog[cngxDialog]", inputs: { modal: { classPropertyName: "modal", publicName: "modal", isSignal: true, isRequired: false, transformFunction: null }, closeOnBackdropClick: { classPropertyName: "closeOnBackdropClick", publicName: "closeOnBackdropClick", isSignal: true, isRequired: false, transformFunction: null }, closeOnEscape: { classPropertyName: "closeOnEscape", publicName: "closeOnEscape", isSignal: true, isRequired: false, transformFunction: null }, autoFocus: { classPropertyName: "autoFocus", publicName: "autoFocus", isSignal: true, isRequired: false, transformFunction: null }, focusFallback: { classPropertyName: "focusFallback", publicName: "focusFallback", isSignal: true, isRequired: false, transformFunction: null }, state: { classPropertyName: "state", publicName: "state", isSignal: true, isRequired: false, transformFunction: null }, submitAction: { classPropertyName: "submitAction", publicName: "submitAction", isSignal: true, isRequired: false, transformFunction: null }, error: { classPropertyName: "error", publicName: "error", isSignal: true, isRequired: false, transformFunction: null } }, host: { listeners: { "cancel": "handleCancel($event)", "click": "handleClick($event)" }, properties: { "class.cngx-dialog--opening": "isOpening()", "class.cngx-dialog--open": "isOpen()", "class.cngx-dialog--closing": "isClosing()", "class.cngx-dialog--modal": "modal()", "attr.aria-modal": "ariaModal()", "attr.aria-labelledby": "ariaLabelledBy()", "attr.aria-describedby": "ariaDescribedBy()", "class.cngx-dialog--pending": "isPending()", "attr.aria-busy": "isPending() || null", "class.cngx-dialog--error": "effectiveError()", "style.--cngx-dialog-backdrop-opacity": "backdropOpacity()" } }, providers: [{ provide: DIALOG_REF, useExisting: CngxDialog }], queries: [{ propertyName: "titleDirective", first: true, predicate: CngxDialogTitle, descendants: true, isSignal: true }, { propertyName: "descriptionDirective", first: true, predicate: CngxDialogDescription, descendants: true, isSignal: true }], exportAs: ["cngxDialog"], ngImport: i0 });
973
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.2.0", version: "21.2.4", type: CngxDialog, isStandalone: true, selector: "dialog[cngxDialog]", inputs: { modal: { classPropertyName: "modal", publicName: "modal", isSignal: true, isRequired: false, transformFunction: null }, closeOnBackdropClick: { classPropertyName: "closeOnBackdropClick", publicName: "closeOnBackdropClick", isSignal: true, isRequired: false, transformFunction: null }, closeOnEscape: { classPropertyName: "closeOnEscape", publicName: "closeOnEscape", isSignal: true, isRequired: false, transformFunction: null }, autoFocus: { classPropertyName: "autoFocus", publicName: "autoFocus", isSignal: true, isRequired: false, transformFunction: null }, focusFallback: { classPropertyName: "focusFallback", publicName: "focusFallback", isSignal: true, isRequired: false, transformFunction: null }, state: { classPropertyName: "state", publicName: "state", isSignal: true, isRequired: false, transformFunction: null }, submitAction: { classPropertyName: "submitAction", publicName: "submitAction", isSignal: true, isRequired: false, transformFunction: null }, error: { classPropertyName: "error", publicName: "error", isSignal: true, isRequired: false, transformFunction: null } }, host: { listeners: { "cancel": "handleCancel($event)", "pointerdown": "handlePointerDown($event)", "click": "handleClick($event)" }, properties: { "class.cngx-dialog--opening": "isOpening()", "class.cngx-dialog--open": "isOpen()", "class.cngx-dialog--closing": "isClosing()", "class.cngx-dialog--modal": "modal()", "attr.aria-modal": "ariaModal()", "attr.aria-labelledby": "ariaLabelledBy()", "attr.aria-describedby": "ariaDescribedBy()", "class.cngx-dialog--pending": "isPending()", "attr.aria-busy": "isPending() || null", "class.cngx-dialog--error": "effectiveError()", "style.--cngx-dialog-backdrop-opacity": "backdropOpacity()" } }, providers: [
974
+ { provide: DIALOG_REF, useExisting: CngxDialog },
975
+ { provide: CNGX_DIALOG_ARIA_REGISTRY, useExisting: CngxDialog },
976
+ ], queries: [{ propertyName: "titleDirective", first: true, predicate: CngxDialogTitle, descendants: true, isSignal: true }, { propertyName: "descriptionDirective", first: true, predicate: CngxDialogDescription, descendants: true, isSignal: true }], exportAs: ["cngxDialog"], ngImport: i0 });
747
977
  }
748
978
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDialog, decorators: [{
749
979
  type: Directive,
@@ -751,7 +981,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
751
981
  selector: 'dialog[cngxDialog]',
752
982
  exportAs: 'cngxDialog',
753
983
  standalone: true,
754
- providers: [{ provide: DIALOG_REF, useExisting: CngxDialog }],
984
+ providers: [
985
+ { provide: DIALOG_REF, useExisting: CngxDialog },
986
+ { provide: CNGX_DIALOG_ARIA_REGISTRY, useExisting: CngxDialog },
987
+ ],
755
988
  host: {
756
989
  '[class.cngx-dialog--opening]': 'isOpening()',
757
990
  '[class.cngx-dialog--open]': 'isOpen()',
@@ -765,6 +998,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
765
998
  '[class.cngx-dialog--error]': 'effectiveError()',
766
999
  '[style.--cngx-dialog-backdrop-opacity]': 'backdropOpacity()',
767
1000
  '(cancel)': 'handleCancel($event)',
1001
+ '(pointerdown)': 'handlePointerDown($event)',
768
1002
  '(click)': 'handleClick($event)',
769
1003
  },
770
1004
  }]
@@ -807,10 +1041,14 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
807
1041
  class CngxDialogClose {
808
1042
  dialogRef = inject(DIALOG_REF);
809
1043
  elRef = inject((ElementRef));
1044
+ labels = coerceSignal(injectDialogConfig().labels);
810
1045
  /** Value to pass to `close()`. When `undefined`, calls `dismiss()` instead. */
811
1046
  value = input(undefined, { ...(ngDevMode ? { debugName: "value" } : /* istanbul ignore next */ {}), alias: 'cngxDialogClose' });
812
1047
  /**
813
- * Explicit `aria-label` override.
1048
+ * Explicit `aria-label` override. Bind a dynamic accessible name here,
1049
+ * not through `[attr.aria-label]`: the directive owns the host's
1050
+ * `aria-label` binding, so a second binding on the same attribute races it.
1051
+ * A static `aria-label="..."` attribute on the host is kept as is.
814
1052
  *
815
1053
  * When not set, the directive auto-detects whether the host element
816
1054
  * has descriptive text content. If it does (e.g. "Cancel", "Confirm"),
@@ -818,11 +1056,17 @@ class CngxDialogClose {
818
1056
  * empty, or visually an icon, `aria-label` defaults to `"Close dialog"`.
819
1057
  */
820
1058
  label = input(undefined, { ...(ngDevMode ? { debugName: "label" } : /* istanbul ignore next */ {}), alias: 'cngxDialogCloseLabel' });
1059
+ // The value is read once at construction and written back through the host
1060
+ // binding: returning null would remove the consumer's attribute, and after
1061
+ // the first render the binding owns aria-label, so a recompute must not
1062
+ // mistake the directive's own value for a consumer-authored one.
1063
+ consumerAriaLabel = this.elRef.nativeElement.getAttribute('aria-label');
821
1064
  /** Set type="button" on <button> hosts to prevent form submit. */
822
1065
  hostType = this.elRef.nativeElement.tagName === 'BUTTON' ? 'button' : null;
823
1066
  /**
824
1067
  * Computed `aria-label`. Returns:
825
1068
  * - explicit `label()` input if set
1069
+ * - the consumer's static `aria-label` attribute, kept as is
826
1070
  * - `null` if host text is descriptive (> 1 char, not whitespace-only)
827
1071
  * - `'Close dialog'` for icon-only / single-char content
828
1072
  */
@@ -831,16 +1075,15 @@ class CngxDialogClose {
831
1075
  if (explicit !== undefined) {
832
1076
  return explicit || null;
833
1077
  }
834
- // If host already has aria-label attribute set by the consumer, don't override
835
- const el = this.elRef.nativeElement;
836
- if (el.hasAttribute('aria-label')) {
837
- return null;
1078
+ if (this.consumerAriaLabel !== null) {
1079
+ return this.consumerAriaLabel;
838
1080
  }
1081
+ const el = this.elRef.nativeElement;
839
1082
  const text = el.textContent?.trim() ?? '';
840
1083
  if (text.length > 1) {
841
1084
  return null;
842
1085
  }
843
- return 'Close dialog';
1086
+ return this.labels().close;
844
1087
  }, ...(ngDevMode ? [{ debugName: "ariaLabel" }] : /* istanbul ignore next */ []));
845
1088
  handleClick() {
846
1089
  const v = this.value();
@@ -882,7 +1125,7 @@ const CNGX_DIALOG_DATA = new InjectionToken('CngxDialogData');
882
1125
  /**
883
1126
  * Internal container component for programmatically opened dialogs.
884
1127
  *
885
- * Not part of the public API — instantiated exclusively by `CngxDialogOpener`.
1128
+ * Not part of the public API - instantiated exclusively by `CngxDialogOpener`.
886
1129
  * Renders the native `<dialog>` shell and exposes a `<ng-container>` outlet
887
1130
  * where the content component or template is inserted.
888
1131
  *
@@ -893,16 +1136,24 @@ class CngxDialogOutlet {
893
1136
  closeOnBackdropClick = input(true, ...(ngDevMode ? [{ debugName: "closeOnBackdropClick" }] : /* istanbul ignore next */ []));
894
1137
  closeOnEscape = input(true, ...(ngDevMode ? [{ debugName: "closeOnEscape" }] : /* istanbul ignore next */ []));
895
1138
  autoFocus = input('first-focusable', ...(ngDevMode ? [{ debugName: "autoFocus" }] : /* istanbul ignore next */ []));
1139
+ submitAction = input(undefined, ...(ngDevMode ? [{ debugName: "submitAction" }] : /* istanbul ignore next */ []));
1140
+ state = input(undefined, ...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
1141
+ error = input(false, ...(ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []));
1142
+ focusFallback = input(undefined, ...(ngDevMode ? [{ debugName: "focusFallback" }] : /* istanbul ignore next */ []));
896
1143
  dialog = viewChild.required(CngxDialog);
897
1144
  contentOutlet = viewChild('contentOutlet', { ...(ngDevMode ? { debugName: "contentOutlet" } : /* istanbul ignore next */ {}), read: ViewContainerRef });
898
1145
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDialogOutlet, deps: [], target: i0.ɵɵFactoryTarget.Component });
899
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "21.2.4", type: CngxDialogOutlet, isStandalone: true, selector: "cngx-dialog-outlet", inputs: { modal: { classPropertyName: "modal", publicName: "modal", isSignal: true, isRequired: false, transformFunction: null }, closeOnBackdropClick: { classPropertyName: "closeOnBackdropClick", publicName: "closeOnBackdropClick", isSignal: true, isRequired: false, transformFunction: null }, closeOnEscape: { classPropertyName: "closeOnEscape", publicName: "closeOnEscape", isSignal: true, isRequired: false, transformFunction: null }, autoFocus: { classPropertyName: "autoFocus", publicName: "autoFocus", isSignal: true, isRequired: false, transformFunction: null } }, viewQueries: [{ propertyName: "dialog", first: true, predicate: CngxDialog, descendants: true, isSignal: true }, { propertyName: "contentOutlet", first: true, predicate: ["contentOutlet"], descendants: true, read: ViewContainerRef, isSignal: true }], ngImport: i0, template: `
1146
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "21.2.4", type: CngxDialogOutlet, isStandalone: true, selector: "cngx-dialog-outlet", inputs: { modal: { classPropertyName: "modal", publicName: "modal", isSignal: true, isRequired: false, transformFunction: null }, closeOnBackdropClick: { classPropertyName: "closeOnBackdropClick", publicName: "closeOnBackdropClick", isSignal: true, isRequired: false, transformFunction: null }, closeOnEscape: { classPropertyName: "closeOnEscape", publicName: "closeOnEscape", isSignal: true, isRequired: false, transformFunction: null }, autoFocus: { classPropertyName: "autoFocus", publicName: "autoFocus", isSignal: true, isRequired: false, transformFunction: null }, submitAction: { classPropertyName: "submitAction", publicName: "submitAction", isSignal: true, isRequired: false, transformFunction: null }, state: { classPropertyName: "state", publicName: "state", isSignal: true, isRequired: false, transformFunction: null }, error: { classPropertyName: "error", publicName: "error", isSignal: true, isRequired: false, transformFunction: null }, focusFallback: { classPropertyName: "focusFallback", publicName: "focusFallback", isSignal: true, isRequired: false, transformFunction: null } }, viewQueries: [{ propertyName: "dialog", first: true, predicate: CngxDialog, descendants: true, isSignal: true }, { propertyName: "contentOutlet", first: true, predicate: ["contentOutlet"], descendants: true, read: ViewContainerRef, isSignal: true }], ngImport: i0, template: `
900
1147
  <dialog
901
1148
  cngxDialog
902
1149
  [modal]="modal()"
903
1150
  [closeOnBackdropClick]="closeOnBackdropClick()"
904
1151
  [closeOnEscape]="closeOnEscape()"
905
1152
  [autoFocus]="autoFocus()"
1153
+ [submitAction]="submitAction()"
1154
+ [state]="state()"
1155
+ [error]="error()"
1156
+ [focusFallback]="focusFallback()"
906
1157
  #dialog="cngxDialog"
907
1158
  >
908
1159
  <ng-container #contentOutlet />
@@ -918,12 +1169,16 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
918
1169
  [closeOnBackdropClick]="closeOnBackdropClick()"
919
1170
  [closeOnEscape]="closeOnEscape()"
920
1171
  [autoFocus]="autoFocus()"
1172
+ [submitAction]="submitAction()"
1173
+ [state]="state()"
1174
+ [error]="error()"
1175
+ [focusFallback]="focusFallback()"
921
1176
  #dialog="cngxDialog"
922
1177
  >
923
1178
  <ng-container #contentOutlet />
924
1179
  </dialog>
925
1180
  `, changeDetection: ChangeDetectionStrategy.OnPush, styles: [":host{display:contents}\n"] }]
926
- }], propDecorators: { modal: [{ type: i0.Input, args: [{ isSignal: true, alias: "modal", required: false }] }], closeOnBackdropClick: [{ type: i0.Input, args: [{ isSignal: true, alias: "closeOnBackdropClick", required: false }] }], closeOnEscape: [{ type: i0.Input, args: [{ isSignal: true, alias: "closeOnEscape", required: false }] }], autoFocus: [{ type: i0.Input, args: [{ isSignal: true, alias: "autoFocus", required: false }] }], dialog: [{ type: i0.ViewChild, args: [i0.forwardRef(() => CngxDialog), { isSignal: true }] }], contentOutlet: [{ type: i0.ViewChild, args: ['contentOutlet', { ...{ read: ViewContainerRef }, isSignal: true }] }] } });
1181
+ }], propDecorators: { modal: [{ type: i0.Input, args: [{ isSignal: true, alias: "modal", required: false }] }], closeOnBackdropClick: [{ type: i0.Input, args: [{ isSignal: true, alias: "closeOnBackdropClick", required: false }] }], closeOnEscape: [{ type: i0.Input, args: [{ isSignal: true, alias: "closeOnEscape", required: false }] }], autoFocus: [{ type: i0.Input, args: [{ isSignal: true, alias: "autoFocus", required: false }] }], submitAction: [{ type: i0.Input, args: [{ isSignal: true, alias: "submitAction", required: false }] }], state: [{ type: i0.Input, args: [{ isSignal: true, alias: "state", required: false }] }], error: [{ type: i0.Input, args: [{ isSignal: true, alias: "error", required: false }] }], focusFallback: [{ type: i0.Input, args: [{ isSignal: true, alias: "focusFallback", required: false }] }], dialog: [{ type: i0.ViewChild, args: [i0.forwardRef(() => CngxDialog), { isSignal: true }] }], contentOutlet: [{ type: i0.ViewChild, args: ['contentOutlet', { ...{ read: ViewContainerRef }, isSignal: true }] }] } });
927
1182
 
928
1183
  /**
929
1184
  * Reference to a programmatically opened dialog.
@@ -987,6 +1242,16 @@ class CngxDialogRef {
987
1242
  get id() {
988
1243
  return this.inner.id;
989
1244
  }
1245
+ /**
1246
+ * Async state of the submit channel - same surface a declarative dialog
1247
+ * exposes. Populated when the open config carries a `submitAction`;
1248
+ * remains at `'idle'` otherwise.
1249
+ *
1250
+ * Bind to any state consumer: `<cngx-alert [state]="ref.submitState" />`.
1251
+ */
1252
+ get submitState() {
1253
+ return this.inner.submitState;
1254
+ }
990
1255
  /**
991
1256
  * Close the dialog with a typed result value.
992
1257
  *
@@ -1073,6 +1338,13 @@ class CngxDialogOpener {
1073
1338
  injector = inject(Injector);
1074
1339
  doc = inject(DOCUMENT);
1075
1340
  openDialogs = [];
1341
+ /**
1342
+ * Per-open close-watcher effects, keyed by ref. Owned here (not on the
1343
+ * public `CngxDialogRef`) - the effect's injector outlives the dialog, so
1344
+ * without the explicit destroy in `cleanup()` every `open()` would leak
1345
+ * one live effect.
1346
+ */
1347
+ cleanupEffects = new WeakMap();
1076
1348
  open(content, config = {}) {
1077
1349
  const outletRef = createComponent(CngxDialogOutlet, {
1078
1350
  environmentInjector: this.envInjector,
@@ -1083,17 +1355,35 @@ class CngxDialogOpener {
1083
1355
  if (config.autoFocus) {
1084
1356
  outletRef.setInput('autoFocus', config.autoFocus);
1085
1357
  }
1358
+ if (config.submitAction) {
1359
+ outletRef.setInput('submitAction', config.submitAction);
1360
+ }
1361
+ if (config.state) {
1362
+ outletRef.setInput('state', config.state);
1363
+ }
1364
+ if (config.error !== undefined) {
1365
+ outletRef.setInput('error', config.error);
1366
+ }
1367
+ if (config.focusFallback) {
1368
+ outletRef.setInput('focusFallback', config.focusFallback);
1369
+ }
1086
1370
  // Attach to ApplicationRef so change detection runs
1087
1371
  this.appRef.attachView(outletRef.hostView);
1088
1372
  const hostEl = outletRef.location.nativeElement;
1089
1373
  this.doc.body.appendChild(hostEl);
1090
- const innerDialog = outletRef.instance.dialog();
1374
+ // CngxDialog has open() but the DialogRef<T> interface does not - keep
1375
+ // the concrete instance for the open() call below.
1376
+ const dialogInstance = outletRef.instance.dialog();
1377
+ const innerDialog = dialogInstance;
1091
1378
  const outletVcr = outletRef.instance.contentOutlet();
1092
1379
  let contentRef = null;
1093
1380
  const childInjector = Injector.create({
1094
1381
  parent: this.injector,
1095
1382
  providers: [
1096
1383
  { provide: DIALOG_REF, useValue: innerDialog },
1384
+ // Content lives in a dynamically created view the dialog's content
1385
+ // queries cannot see - labelling flows through the registry instead.
1386
+ { provide: CNGX_DIALOG_ARIA_REGISTRY, useValue: dialogInstance },
1097
1387
  { provide: CNGX_DIALOG_DATA, useValue: config.data ?? null },
1098
1388
  ],
1099
1389
  });
@@ -1109,16 +1399,14 @@ class CngxDialogOpener {
1109
1399
  }
1110
1400
  const dialogRef = new CngxDialogRef(innerDialog, outletRef, contentRef, this.injector);
1111
1401
  this.openDialogs.push(dialogRef);
1112
- // CngxDialog has open() but the DialogRef<T> interface does not - call the concrete instance.
1113
- const dialogInstance = outletRef.instance.dialog();
1114
1402
  dialogInstance.open();
1115
- effect(() => {
1403
+ this.cleanupEffects.set(dialogRef, effect(() => {
1116
1404
  if (innerDialog.lifecycle() === 'closed' &&
1117
1405
  outletRef.hostView &&
1118
1406
  !outletRef.hostView.destroyed) {
1119
- this.cleanup(dialogRef);
1407
+ untracked(() => this.cleanup(dialogRef));
1120
1408
  }
1121
- }, { injector: childInjector });
1409
+ }, { injector: childInjector }));
1122
1410
  return dialogRef;
1123
1411
  }
1124
1412
  /**
@@ -1133,6 +1421,8 @@ class CngxDialogOpener {
1133
1421
  }
1134
1422
  }
1135
1423
  cleanup(ref) {
1424
+ this.cleanupEffects.get(ref)?.destroy();
1425
+ this.cleanupEffects.delete(ref);
1136
1426
  const idx = this.openDialogs.indexOf(ref);
1137
1427
  if (idx >= 0) {
1138
1428
  this.openDialogs.splice(idx, 1);
@@ -1212,7 +1502,8 @@ class CngxBottomSheet {
1212
1502
  /**
1213
1503
  * Whether the drag handle bar is visible.
1214
1504
  *
1215
- * The handle itself is rendered via CSS (`::before` pseudo-element on the host).
1505
+ * The handle itself is rendered via CSS (`::before` pseudo-element, gated
1506
+ * on the `cngx-bottom-sheet--handle` modifier class this input binds).
1216
1507
  * Set to `false` to hide it.
1217
1508
  *
1218
1509
  * @defaultValue `true`
@@ -1225,7 +1516,7 @@ class CngxBottomSheet {
1225
1516
  }
1226
1517
  }
1227
1518
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxBottomSheet, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1228
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxBottomSheet, isStandalone: true, selector: "dialog[cngxBottomSheet]", inputs: { showHandle: { classPropertyName: "showHandle", publicName: "showHandle", isSignal: true, isRequired: false, transformFunction: null } }, host: { classAttribute: "cngx-bottom-sheet" }, exportAs: ["cngxBottomSheet"], ngImport: i0 });
1519
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxBottomSheet, isStandalone: true, selector: "dialog[cngxBottomSheet]", inputs: { showHandle: { classPropertyName: "showHandle", publicName: "showHandle", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "class.cngx-bottom-sheet--handle": "showHandle()" }, classAttribute: "cngx-bottom-sheet" }, exportAs: ["cngxBottomSheet"], ngImport: i0 });
1229
1520
  }
1230
1521
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxBottomSheet, decorators: [{
1231
1522
  type: Directive,
@@ -1235,6 +1526,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
1235
1526
  standalone: true,
1236
1527
  host: {
1237
1528
  class: 'cngx-bottom-sheet',
1529
+ '[class.cngx-bottom-sheet--handle]': 'showHandle()',
1238
1530
  },
1239
1531
  }]
1240
1532
  }], ctorParameters: () => [], propDecorators: { showHandle: [{ type: i0.Input, args: [{ isSignal: true, alias: "showHandle", required: false }] }] } });
@@ -1251,6 +1543,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
1251
1543
  * - Shift + Arrow moves 50px
1252
1544
  * - Home resets to origin
1253
1545
  *
1546
+ * Keys move the dialog only while the handle element itself has focus -
1547
+ * arrows inside form fields keep moving the caret. Without an explicit
1548
+ * `[handle]` the dialog element becomes focusable (`tabindex="0"`) and is
1549
+ * the keyboard drag surface.
1550
+ *
1254
1551
  * ```html
1255
1552
  * <dialog cngxDialog cngxDialogDraggable>
1256
1553
  * <div class="dialog-header" #handle>Title</div>
@@ -1284,7 +1581,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
1284
1581
  class CngxDialogDraggable {
1285
1582
  elRef = inject(ElementRef);
1286
1583
  doc = inject(DOCUMENT);
1584
+ labels = coerceSignal(injectDialogConfig().labels);
1287
1585
  destroyRef = inject(DestroyRef);
1586
+ ariaRegistry = inject(CNGX_DIALOG_ARIA_REGISTRY, { optional: true });
1288
1587
  /** Handle element for initiating drag. If not set, entire dialog is the handle. */
1289
1588
  handle = input(undefined, ...(ngDevMode ? [{ debugName: "handle" }] : /* istanbul ignore next */ []));
1290
1589
  /** Clamp position to viewport bounds. */
@@ -1308,7 +1607,9 @@ class CngxDialogDraggable {
1308
1607
  * @defaultValue `'live'`
1309
1608
  */
1310
1609
  snapMode = input('live', ...(ngDevMode ? [{ debugName: "snapMode" }] : /* istanbul ignore next */ []));
1311
- positionState = signal({ x: 0, y: 0 }, ...(ngDevMode ? [{ debugName: "positionState" }] : /* istanbul ignore next */ []));
1610
+ // equal keeps live grid-snap quiet: every pointermove produces a fresh
1611
+ // {x, y} literal, and under snapping most of them carry identical values.
1612
+ positionState = signal({ x: 0, y: 0 }, { ...(ngDevMode ? { debugName: "positionState" } : /* istanbul ignore next */ {}), equal: (a, b) => a.x === b.x && a.y === b.y });
1312
1613
  draggingState = signal(false, ...(ngDevMode ? [{ debugName: "draggingState" }] : /* istanbul ignore next */ []));
1313
1614
  /** Current offset position. */
1314
1615
  position = this.positionState.asReadonly();
@@ -1326,29 +1627,55 @@ class CngxDialogDraggable {
1326
1627
  constructor() {
1327
1628
  effect(() => {
1328
1629
  const handleEl = this.handle() ?? this.elRef.nativeElement;
1329
- this.setupHandle(handleEl);
1630
+ // untracked: setupHandle registers with the dialog's aria registry -
1631
+ // a signal write that must not become a tracked dependency.
1632
+ untracked(() => this.setupHandle(handleEl));
1633
+ });
1634
+ // A language switch relabels the promoted handle and the instruction in
1635
+ // place, without re-running the handle setup.
1636
+ effect(() => {
1637
+ const labels = this.labels();
1638
+ untracked(() => this.applyLabels(labels));
1330
1639
  });
1331
1640
  this.destroyRef.onDestroy(() => this.cleanup());
1332
1641
  }
1333
1642
  currentHandle = null;
1334
1643
  boundPointerDown = null;
1335
1644
  boundKeyDown = null;
1645
+ handleAddedTabindex = false;
1646
+ handleAddedAria = false;
1336
1647
  /** Attach pointer and keyboard listeners to `el`, cleaning up the previous handle first. */
1337
1648
  setupHandle(el) {
1338
- if (this.currentHandle && this.boundPointerDown) {
1339
- this.currentHandle.removeEventListener('pointerdown', this.boundPointerDown);
1340
- }
1341
- if (this.currentHandle && this.boundKeyDown) {
1342
- this.currentHandle.removeEventListener('keydown', this.boundKeyDown);
1343
- }
1649
+ this.teardownHandle();
1344
1650
  this.currentHandle = el;
1345
- // A11y: make handle focusable and describe as draggable
1346
- if (!el.hasAttribute('tabindex') && el !== this.elRef.nativeElement) {
1651
+ // A11y: the handle must be keyboard-reachable - the target-scoped keydown
1652
+ // guard makes it the only element arrow keys can move the dialog from,
1653
+ // so an unfocusable handle would strip the keyboard path entirely.
1654
+ if (!el.hasAttribute('tabindex')) {
1347
1655
  el.setAttribute('tabindex', '0');
1656
+ this.handleAddedTabindex = true;
1348
1657
  }
1658
+ // Labelling stays off the host-as-handle: aria-label/aria-roledescription
1659
+ // on the dialog element itself would clobber its accessible name (the
1660
+ // title) and its role text.
1349
1661
  if (!el.hasAttribute('aria-roledescription') && el !== this.elRef.nativeElement) {
1350
- el.setAttribute('aria-roledescription', 'draggable');
1351
- el.setAttribute('aria-label', 'Move dialog');
1662
+ el.setAttribute('aria-roledescription', this.labels().dragHandleRoleDescription);
1663
+ el.setAttribute('aria-label', this.labels().dragHandle);
1664
+ this.handleAddedAria = true;
1665
+ }
1666
+ // The keyboard path is live on every handle, so the instruction is too.
1667
+ // The registry channel exists only because CngxDialog owns
1668
+ // aria-describedby on its host; everywhere else (explicit handle,
1669
+ // draggable on a non-dialog element) nothing owns the attribute and it
1670
+ // is set directly - guarded like tabindex, a consumer-authored
1671
+ // describedby wins.
1672
+ const instruction = this.createInstructionNode();
1673
+ if (el === this.elRef.nativeElement && this.ariaRegistry) {
1674
+ this.releaseInstruction = this.ariaRegistry.registerDescribedBy(instruction.id);
1675
+ }
1676
+ else if (!el.hasAttribute('aria-describedby')) {
1677
+ el.setAttribute('aria-describedby', instruction.id);
1678
+ this.handleAddedDescribedBy = true;
1352
1679
  }
1353
1680
  el.style.cursor = 'var(--cngx-dialog-drag-cursor, grab)';
1354
1681
  el.style.touchAction = 'none';
@@ -1383,6 +1710,9 @@ class CngxDialogDraggable {
1383
1710
  this.boundUp = (e) => this.handlePointerUp(e);
1384
1711
  this.doc.addEventListener('pointermove', this.boundMove);
1385
1712
  this.doc.addEventListener('pointerup', this.boundUp);
1713
+ // A cancelled pointer (touch interrupted, capture stolen) never fires
1714
+ // pointerup - without this the drag state sticks and userSelect stays off.
1715
+ this.doc.addEventListener('pointercancel', this.boundUp);
1386
1716
  }
1387
1717
  handlePointerMove(event) {
1388
1718
  let x = this.posStartX + (event.clientX - this.dragStartX);
@@ -1418,11 +1748,18 @@ class CngxDialogDraggable {
1418
1748
  }
1419
1749
  if (this.boundUp) {
1420
1750
  this.doc.removeEventListener('pointerup', this.boundUp);
1751
+ this.doc.removeEventListener('pointercancel', this.boundUp);
1421
1752
  }
1422
1753
  this.boundMove = null;
1423
1754
  this.boundUp = null;
1424
1755
  }
1425
1756
  handleKeyDown(event) {
1757
+ // When the whole dialog is the handle, every keydown inside it bubbles
1758
+ // here - arrows typed into form fields must move the caret, not the
1759
+ // dialog. Only keys originating on the handle element itself may drag.
1760
+ if (event.target !== this.currentHandle) {
1761
+ return;
1762
+ }
1426
1763
  const grid = this.gridSize();
1427
1764
  // When grid is active, Arrow keys step by grid size (Shift = 5x grid)
1428
1765
  const step = grid > 0 ? (event.shiftKey ? grid * 5 : grid) : event.shiftKey ? 50 : 10;
@@ -1461,19 +1798,88 @@ class CngxDialogDraggable {
1461
1798
  y: Math.round(y / grid) * grid,
1462
1799
  };
1463
1800
  }
1801
+ /** Re-apply the handle labels and the instruction text this directive owns. */
1802
+ applyLabels(labels) {
1803
+ if (this.currentHandle && this.handleAddedAria) {
1804
+ this.currentHandle.setAttribute('aria-roledescription', labels.dragHandleRoleDescription);
1805
+ this.currentHandle.setAttribute('aria-label', labels.dragHandle);
1806
+ }
1807
+ if (this.instructionNode) {
1808
+ this.instructionNode.textContent = labels.dragInstructions;
1809
+ }
1810
+ }
1811
+ instructionNode = null;
1812
+ releaseInstruction = null;
1813
+ handleAddedDescribedBy = false;
1814
+ /**
1815
+ * Visually hidden keyboard-drag instruction, appended to the host so it
1816
+ * lives inside the dialog for both handle modes. Same hidden technique as
1817
+ * the dialog's live region - a referenced node must stay perceivable to
1818
+ * AT, not `display: none`.
1819
+ */
1820
+ createInstructionNode() {
1821
+ const node = this.doc.createElement('span');
1822
+ node.id = nextUid('cngx-dialog-drag-hint');
1823
+ node.textContent = this.labels().dragInstructions;
1824
+ applySrOnly(node);
1825
+ this.elRef.nativeElement.appendChild(node);
1826
+ this.instructionNode = node;
1827
+ return node;
1828
+ }
1829
+ /**
1830
+ * Detach listeners from the current handle and restore every attribute and
1831
+ * style this directive added. A demoted handle must not stay focusable or
1832
+ * keep announcing "Move dialog" with a dead keyboard path behind it.
1833
+ *
1834
+ * The instruction node and its describedby registration leave atomically
1835
+ * with the capability they describe: a handle swap away from host-as-handle
1836
+ * removes the arrow-keys-on-the-dialog path itself, so keeping an orphan
1837
+ * description would misinform AT, not inform it.
1838
+ */
1839
+ teardownHandle() {
1840
+ this.releaseInstruction?.();
1841
+ this.releaseInstruction = null;
1842
+ this.instructionNode?.remove();
1843
+ this.instructionNode = null;
1844
+ const handle = this.currentHandle;
1845
+ if (!handle) {
1846
+ return;
1847
+ }
1848
+ if (this.handleAddedDescribedBy) {
1849
+ handle.removeAttribute('aria-describedby');
1850
+ this.handleAddedDescribedBy = false;
1851
+ }
1852
+ if (this.boundPointerDown) {
1853
+ handle.removeEventListener('pointerdown', this.boundPointerDown);
1854
+ }
1855
+ if (this.boundKeyDown) {
1856
+ handle.removeEventListener('keydown', this.boundKeyDown);
1857
+ }
1858
+ if (this.handleAddedTabindex) {
1859
+ handle.removeAttribute('tabindex');
1860
+ this.handleAddedTabindex = false;
1861
+ }
1862
+ if (this.handleAddedAria) {
1863
+ handle.removeAttribute('aria-roledescription');
1864
+ handle.removeAttribute('aria-label');
1865
+ this.handleAddedAria = false;
1866
+ }
1867
+ handle.style.cursor = '';
1868
+ handle.style.touchAction = '';
1869
+ this.currentHandle = null;
1870
+ }
1464
1871
  cleanup() {
1465
1872
  if (this.boundMove) {
1466
1873
  this.doc.removeEventListener('pointermove', this.boundMove);
1467
1874
  }
1468
1875
  if (this.boundUp) {
1469
1876
  this.doc.removeEventListener('pointerup', this.boundUp);
1877
+ this.doc.removeEventListener('pointercancel', this.boundUp);
1470
1878
  }
1471
- if (this.currentHandle && this.boundPointerDown) {
1472
- this.currentHandle.removeEventListener('pointerdown', this.boundPointerDown);
1473
- }
1474
- if (this.currentHandle && this.boundKeyDown) {
1475
- this.currentHandle.removeEventListener('keydown', this.boundKeyDown);
1476
- }
1879
+ // A destroy mid-drag skips handlePointerUp - the global style must not
1880
+ // outlive the directive.
1881
+ this.doc.documentElement.style.userSelect = '';
1882
+ this.teardownHandle();
1477
1883
  }
1478
1884
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDialogDraggable, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1479
1885
  static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxDialogDraggable, isStandalone: true, selector: "[cngxDialogDraggable]", inputs: { handle: { classPropertyName: "handle", publicName: "handle", isSignal: true, isRequired: false, transformFunction: null }, constrainToViewport: { classPropertyName: "constrainToViewport", publicName: "constrainToViewport", isSignal: true, isRequired: false, transformFunction: null }, gridSize: { classPropertyName: "gridSize", publicName: "gridSize", isSignal: true, isRequired: false, transformFunction: null }, snapMode: { classPropertyName: "snapMode", publicName: "snapMode", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "style.--cngx-dialog-x": "cssX()", "style.--cngx-dialog-y": "cssY()", "class.cngx-dialog--dragging": "isDragging()" } }, exportAs: ["cngxDialogDraggable"], ngImport: i0 });
@@ -1500,5 +1906,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
1500
1906
  * Generated bundle index. Do not edit.
1501
1907
  */
1502
1908
 
1503
- export { CNGX_DIALOG_DATA, CngxBottomSheet, CngxDialog, CngxDialogClose, CngxDialogDescription, CngxDialogDraggable, CngxDialogOpener, CngxDialogRef, CngxDialogStack, CngxDialogTitle, DIALOG_REF, provideDialog, provideDialogStack };
1909
+ export { CNGX_DIALOG_DATA, CNGX_DIALOG_DEFAULTS, CNGX_DIALOG_LANGUAGE_EN, CngxBottomSheet, CngxDialog, CngxDialogClose, CngxDialogDescription, CngxDialogDraggable, CngxDialogOpener, CngxDialogRef, CngxDialogStack, CngxDialogTitle, DIALOG_REF, injectDialogConfig, provideDialog, provideDialogConfig, provideDialogConfigAt, provideDialogStack, withDialogLabels };
1504
1910
  //# sourceMappingURL=cngx-common-dialog.mjs.map