@cngx/common 0.1.0-rc.6 → 0.1.0-rc.7

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 (62) hide show
  1. package/chart/README.md +85 -0
  2. package/command/README.md +157 -0
  3. package/data/README.md +23 -0
  4. package/fesm2022/cngx-common-a11y.mjs +247 -85
  5. package/fesm2022/cngx-common-a11y.mjs.map +1 -1
  6. package/fesm2022/cngx-common-audio.mjs +37 -37
  7. package/fesm2022/cngx-common-audio.mjs.map +1 -1
  8. package/fesm2022/cngx-common-card.mjs +13 -9
  9. package/fesm2022/cngx-common-card.mjs.map +1 -1
  10. package/fesm2022/cngx-common-chart.mjs +3404 -1392
  11. package/fesm2022/cngx-common-chart.mjs.map +1 -1
  12. package/fesm2022/cngx-common-command.mjs +144 -0
  13. package/fesm2022/cngx-common-command.mjs.map +1 -0
  14. package/fesm2022/cngx-common-data.mjs +304 -213
  15. package/fesm2022/cngx-common-data.mjs.map +1 -1
  16. package/fesm2022/cngx-common-dialog.mjs +369 -100
  17. package/fesm2022/cngx-common-dialog.mjs.map +1 -1
  18. package/fesm2022/cngx-common-display.mjs +138 -24
  19. package/fesm2022/cngx-common-display.mjs.map +1 -1
  20. package/fesm2022/cngx-common-interactive.mjs +1089 -459
  21. package/fesm2022/cngx-common-interactive.mjs.map +1 -1
  22. package/fesm2022/cngx-common-layout.mjs +113 -61
  23. package/fesm2022/cngx-common-layout.mjs.map +1 -1
  24. package/fesm2022/cngx-common-popover.mjs +430 -54
  25. package/fesm2022/cngx-common-popover.mjs.map +1 -1
  26. package/fesm2022/cngx-common-stepper.mjs +107 -49
  27. package/fesm2022/cngx-common-stepper.mjs.map +1 -1
  28. package/fesm2022/cngx-common-tabs.mjs +1170 -752
  29. package/fesm2022/cngx-common-tabs.mjs.map +1 -1
  30. package/fesm2022/cngx-common-timeline.mjs +1086 -0
  31. package/fesm2022/cngx-common-timeline.mjs.map +1 -0
  32. package/fesm2022/cngx-common.mjs +2 -2
  33. package/fesm2022/cngx-common.mjs.map +1 -1
  34. package/package.json +11 -1
  35. package/stepper/README.md +1 -1
  36. package/theming/components/cngx-accordion.css +3 -0
  37. package/theming/components/cngx-badge.css +22 -0
  38. package/theming/components/cngx-bottom-sheet.css +14 -2
  39. package/theming/components/cngx-breadcrumb.css +8 -0
  40. package/theming/components/cngx-button-toggle.css +44 -2
  41. package/theming/components/cngx-data-grid.css +66 -0
  42. package/theming/components/cngx-dialog.css +12 -0
  43. package/theming/components/cngx-divider.css +12 -0
  44. package/theming/components/cngx-listbox.css +27 -0
  45. package/theming/components/cngx-menu.css +36 -0
  46. package/theming/components/cngx-ripple.css +1 -1
  47. package/theming/components/cngx-tooltip.css +11 -0
  48. package/types/cngx-common-a11y.d.ts +63 -17
  49. package/types/cngx-common-audio.d.ts +32 -32
  50. package/types/cngx-common-card.d.ts +10 -3
  51. package/types/cngx-common-chart.d.ts +1281 -141
  52. package/types/cngx-common-command.d.ts +167 -0
  53. package/types/cngx-common-data.d.ts +264 -98
  54. package/types/cngx-common-dialog.d.ts +214 -25
  55. package/types/cngx-common-display.d.ts +83 -13
  56. package/types/cngx-common-interactive.d.ts +708 -174
  57. package/types/cngx-common-layout.d.ts +48 -1
  58. package/types/cngx-common-popover.d.ts +120 -3
  59. package/types/cngx-common-stepper.d.ts +55 -5
  60. package/types/cngx-common-tabs.d.ts +386 -25
  61. package/types/cngx-common-timeline.d.ts +1059 -0
  62. package/types/cngx-common.d.ts +1 -1
@@ -1,7 +1,8 @@
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, signal, computed, Injectable, inject, 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
4
  import { nextUid, buildAsyncStateView, hasTransition, onTransitionDone } from '@cngx/core/utils';
5
+ import { createScrollLock } from '@cngx/common/layout';
5
6
  import { isObservable, firstValueFrom, filter, take, map } from 'rxjs';
6
7
  import { toObservable } from '@angular/core/rxjs-interop';
7
8
  import { CngxSwipeDismiss } from '@cngx/common/interactive';
@@ -15,6 +16,14 @@ import { CngxSwipeDismiss } from '@cngx/common/interactive';
15
16
  */
16
17
  const DIALOG_REF = new InjectionToken('CngxDialogRef');
17
18
 
19
+ /**
20
+ * Injection token for the dialog ARIA registry.
21
+ *
22
+ * Provided by `CngxDialog` (`useExisting`) on the dialog element and by
23
+ * `CngxDialogOpener` on the programmatic content's child injector.
24
+ */
25
+ const CNGX_DIALOG_ARIA_REGISTRY = new InjectionToken('CngxDialogAriaRegistry');
26
+
18
27
  /**
19
28
  * Tracks open dialog instances as a stack for backdrop management.
20
29
  *
@@ -111,25 +120,36 @@ function provideDialogStack() {
111
120
  * <example-url>http://localhost:4200/#/common/dialog/template-directives</example-url>
112
121
  */
113
122
  class CngxDialogTitle {
114
- elRef = inject((ElementRef));
123
+ elRef = inject(ElementRef);
115
124
  dialogRef = inject(DIALOG_REF, { optional: true });
125
+ ariaRegistry = inject(CNGX_DIALOG_ARIA_REGISTRY, { optional: true });
126
+ destroyRef = inject(DestroyRef);
127
+ idState = signal(nextUid('cngx-dialog-title'), ...(ngDevMode ? [{ debugName: "idState" }] : /* istanbul ignore next */ []));
116
128
  /**
117
129
  * Auto-generated unique ID bound to the host `[id]` attribute.
118
130
  *
119
131
  * Used by `CngxDialog` for `aria-labelledby`. When a parent `CngxDialog`
120
132
  * is present, the ID is derived from the dialog's ID (e.g. `cngx-dialog-0-title`).
133
+ * Read-only: an externally mutated id would silently break the ARIA wiring.
121
134
  */
122
- id = signal(nextUid('cngx-dialog-title'), ...(ngDevMode ? [{ debugName: "id" }] : /* istanbul ignore next */ []));
135
+ id = this.idState.asReadonly();
123
136
  /**
124
- * Text content of the title element.
137
+ * Text content of the title element, read fresh on every call.
125
138
  *
126
- * Read by `CngxDialog` on open to announce the dialog title via
127
- * an `aria-live` region for screen readers.
139
+ * Read by `CngxDialog` at announce time (each `'open'` transition) so a
140
+ * changed title - translation swap, interpolated data - is what screen
141
+ * readers hear. A `computed` would cache the first non-reactive DOM read
142
+ * forever.
128
143
  */
129
- textContent = computed(() => this.elRef.nativeElement.textContent?.trim() ?? '', ...(ngDevMode ? [{ debugName: "textContent" }] : /* istanbul ignore next */ []));
144
+ textContent = () => this.elRef.nativeElement.textContent?.trim() ?? '';
130
145
  constructor() {
131
146
  if (this.dialogRef) {
132
- this.id.set(`${this.dialogRef.id()}-title`);
147
+ this.idState.set(`${this.dialogRef.id()}-title`);
148
+ }
149
+ // Push registration: content queries cannot see dynamically created
150
+ // views, so programmatic dialogs rely on this channel exclusively.
151
+ if (this.ariaRegistry) {
152
+ this.destroyRef.onDestroy(this.ariaRegistry.registerTitle(this));
133
153
  }
134
154
  }
135
155
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDialogTitle, deps: [], target: i0.ɵɵFactoryTarget.Directive });
@@ -180,16 +200,25 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
180
200
  */
181
201
  class CngxDialogDescription {
182
202
  dialogRef = inject(DIALOG_REF, { optional: true });
203
+ ariaRegistry = inject(CNGX_DIALOG_ARIA_REGISTRY, { optional: true });
204
+ destroyRef = inject(DestroyRef);
205
+ idState = signal(nextUid('cngx-dialog-desc'), ...(ngDevMode ? [{ debugName: "idState" }] : /* istanbul ignore next */ []));
183
206
  /**
184
207
  * Auto-generated unique ID bound to the host `[id]` attribute.
185
208
  *
186
209
  * Used by `CngxDialog` for `aria-describedby`. When a parent `CngxDialog`
187
210
  * is present, the ID is derived from the dialog's ID (e.g. `cngx-dialog-0-desc`).
211
+ * Read-only: an externally mutated id would silently break the ARIA wiring.
188
212
  */
189
- id = signal(nextUid('cngx-dialog-desc'), ...(ngDevMode ? [{ debugName: "id" }] : /* istanbul ignore next */ []));
213
+ id = this.idState.asReadonly();
190
214
  constructor() {
191
215
  if (this.dialogRef) {
192
- this.id.set(`${this.dialogRef.id()}-desc`);
216
+ this.idState.set(`${this.dialogRef.id()}-desc`);
217
+ }
218
+ // Push registration: content queries cannot see dynamically created
219
+ // views, so programmatic dialogs rely on this channel exclusively.
220
+ if (this.ariaRegistry) {
221
+ this.destroyRef.onDestroy(this.ariaRegistry.registerDescription(this));
193
222
  }
194
223
  }
195
224
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDialogDescription, deps: [], target: i0.ɵɵFactoryTarget.Directive });
@@ -208,44 +237,29 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
208
237
  }], ctorParameters: () => [] });
209
238
 
210
239
  /**
211
- * Ref-count map for scroll lock - one lock per document root, shared across stacked modals.
240
+ * Apply the visually-hidden (screen-reader-only) recipe to a dynamically
241
+ * created dialog node.
212
242
  *
213
- * @internal
214
- */
215
- const lockCounts = new WeakMap();
216
- /**
217
- * Acquire a scroll lock on the document root, preserving prior overflow styles.
243
+ * Inline styles instead of relying on the `cngx-sr-only` class alone so the
244
+ * live region and the drag instruction stay hidden even when no cngx
245
+ * stylesheet is loaded. The node remains perceivable to AT - describedby
246
+ * targets and live regions must never be `display: none`.
218
247
  *
219
- * @internal
220
- */
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
248
+ * Internal helper - intentionally not exported from `public-api.ts`.
235
249
  */
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
- }
250
+ function applySrOnly(el) {
251
+ el.className = 'cngx-sr-only';
252
+ el.style.position = 'absolute';
253
+ el.style.width = '1px';
254
+ el.style.height = '1px';
255
+ el.style.padding = '0';
256
+ el.style.margin = '-1px';
257
+ el.style.overflow = 'hidden';
258
+ el.style.clip = 'rect(0, 0, 0, 0)';
259
+ el.style.whiteSpace = 'nowrap';
260
+ el.style.border = '0';
248
261
  }
262
+
249
263
  /**
250
264
  * Signal-driven state machine for native `<dialog>`.
251
265
  *
@@ -327,6 +341,12 @@ class CngxDialog {
327
341
  dialogStack = inject(CngxDialogStack);
328
342
  titleDirective = contentChild(CngxDialogTitle, ...(ngDevMode ? [{ debugName: "titleDirective" }] : /* istanbul ignore next */ []));
329
343
  descriptionDirective = contentChild(CngxDialogDescription, ...(ngDevMode ? [{ debugName: "descriptionDirective" }] : /* istanbul ignore next */ []));
344
+ // Push-registered counterparts of the content queries above. Programmatic
345
+ // content lives in a dynamically created view the queries cannot see, so
346
+ // sources register through CNGX_DIALOG_ARIA_REGISTRY instead.
347
+ registeredTitle = signal(null, ...(ngDevMode ? [{ debugName: "registeredTitle" }] : /* istanbul ignore next */ []));
348
+ registeredDescription = signal(null, ...(ngDevMode ? [{ debugName: "registeredDescription" }] : /* istanbul ignore next */ []));
349
+ supplementalDescribedByIds = signal([], ...(ngDevMode ? [{ debugName: "supplementalDescribedByIds" }] : /* istanbul ignore next */ []));
330
350
  /**
331
351
  * Whether the dialog opens as modal (`showModal()`) or non-modal (`show()`).
332
352
  *
@@ -479,16 +499,34 @@ class CngxDialog {
479
499
  isOpening = computed(() => this.lifecycleSignal() === 'opening', ...(ngDevMode ? [{ debugName: "isOpening" }] : /* istanbul ignore next */ []));
480
500
  isOpen = computed(() => this.lifecycleSignal() === 'open', ...(ngDevMode ? [{ debugName: "isOpen" }] : /* istanbul ignore next */ []));
481
501
  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 */ []));
502
+ ariaModal = computed(() => this.openedAsModal() && this.lifecycleSignal() !== 'closed' ? 'true' : null, ...(ngDevMode ? [{ debugName: "ariaModal" }] : /* istanbul ignore next */ []));
503
+ ariaLabelledBy = computed(() => (this.titleDirective() ?? this.registeredTitle())?.id() ?? null, ...(ngDevMode ? [{ debugName: "ariaLabelledBy" }] : /* istanbul ignore next */ []));
504
+ ariaDescribedBy = computed(() => {
505
+ const ids = [];
506
+ const descriptionId = (this.descriptionDirective() ?? this.registeredDescription())?.id();
507
+ if (descriptionId) {
508
+ ids.push(descriptionId);
509
+ }
510
+ for (const id of this.supplementalDescribedByIds()) {
511
+ ids.push(typeof id === 'string' ? id : id());
512
+ }
513
+ return ids.length > 0 ? ids.join(' ') : null;
514
+ }, ...(ngDevMode ? [{ debugName: "ariaDescribedBy" }] : /* istanbul ignore next */ []));
485
515
  backdropOpacity = computed(() => this.dialogStack.topmost() === this.idSignal() ? '1' : '0', ...(ngDevMode ? [{ debugName: "backdropOpacity" }] : /* istanbul ignore next */ []));
486
516
  liveRegion = null;
517
+ /**
518
+ * The modal mode latched at `open()`. Everything that depends on how the
519
+ * dialog actually opened derives from this - scroll-lock release, stack
520
+ * pop, Escape/backdrop dismissal, focus strategy, and `aria-modal` -
521
+ * so toggling `[modal]` while open can neither unbalance the ref count
522
+ * nor strand a rendered backdrop without its dismissal surface.
523
+ */
524
+ openedAsModal = signal(false, ...(ngDevMode ? [{ debugName: "openedAsModal" }] : /* istanbul ignore next */ []));
487
525
  constructor() {
488
526
  this.createLiveRegion();
489
527
  effect(() => {
490
528
  if (this.lifecycleSignal() === 'open') {
491
- const titleText = this.titleDirective()?.textContent() ?? '';
529
+ const titleText = untracked(() => (this.titleDirective() ?? this.registeredTitle())?.textContent?.() ?? '');
492
530
  if (titleText && this.liveRegion) {
493
531
  this.liveRegion.textContent = titleText;
494
532
  // Clear after one frame so subsequent opens re-announce
@@ -501,9 +539,19 @@ class CngxDialog {
501
539
  }
502
540
  });
503
541
  effect(() => {
542
+ // The error VALUE is the announce trigger and stays tracked: the
543
+ // boolean effectiveError() alone is equal-cut on true -> false -> true,
544
+ // so a retried identical failure would never re-fire this effect.
504
545
  if (this.effectiveError() && this.liveRegion) {
505
546
  const errMsg = this.state()?.error() ?? this.submitErrorState();
506
547
  this.liveRegion.textContent = typeof errMsg === 'string' ? errMsg : 'An error occurred';
548
+ // Clear after one frame (same pattern as the title announce) so a
549
+ // repeated identical error is a fresh mutation the SR re-announces.
550
+ requestAnimationFrame(() => {
551
+ if (this.liveRegion) {
552
+ this.liveRegion.textContent = '';
553
+ }
554
+ });
507
555
  }
508
556
  });
509
557
  this.destroyRef.onDestroy(() => {
@@ -512,6 +560,39 @@ class CngxDialog {
512
560
  }
513
561
  });
514
562
  }
563
+ /**
564
+ * Register the labelling source for `aria-labelledby` and the open announce.
565
+ *
566
+ * A present content-queried title wins over the registered handle (same
567
+ * directive in the declarative case - identical id either way).
568
+ *
569
+ * @internal CNGX_DIALOG_ARIA_REGISTRY implementation - not public API.
570
+ */
571
+ registerTitle(handle) {
572
+ this.warnDoubleRegistration('title', untracked(this.registeredTitle), handle);
573
+ this.registeredTitle.set(handle);
574
+ return () => this.registeredTitle.update((current) => (current === handle ? null : current));
575
+ }
576
+ /**
577
+ * Register the primary description source for `aria-describedby`.
578
+ *
579
+ * @internal CNGX_DIALOG_ARIA_REGISTRY implementation - not public API.
580
+ */
581
+ registerDescription(handle) {
582
+ this.warnDoubleRegistration('description', untracked(this.registeredDescription), handle);
583
+ this.registeredDescription.set(handle);
584
+ return () => this.registeredDescription.update((current) => (current === handle ? null : current));
585
+ }
586
+ /**
587
+ * Register a supplemental `aria-describedby` id, merged after the
588
+ * description id in registration order.
589
+ *
590
+ * @internal CNGX_DIALOG_ARIA_REGISTRY implementation - not public API.
591
+ */
592
+ registerDescribedBy(id) {
593
+ this.supplementalDescribedByIds.update((ids) => [...ids, id]);
594
+ return () => this.supplementalDescribedByIds.update((ids) => ids.filter((x) => x !== id));
595
+ }
515
596
  /**
516
597
  * Open the dialog.
517
598
  *
@@ -531,7 +612,8 @@ class CngxDialog {
531
612
  this.submitErrorState.set(undefined);
532
613
  this.triggerElement.set(this.doc.activeElement);
533
614
  this.lifecycleSignal.set('opening');
534
- if (this.modal()) {
615
+ this.openedAsModal.set(this.modal());
616
+ if (this.openedAsModal()) {
535
617
  dialog.showModal();
536
618
  this.acquireScrollLock();
537
619
  this.dialogStack.push(this.idSignal());
@@ -624,26 +706,46 @@ class CngxDialog {
624
706
  }
625
707
  handleCancel(event) {
626
708
  event.preventDefault();
627
- if (this.closeOnEscape() && this.modal()) {
709
+ if (this.closeOnEscape() && this.openedAsModal()) {
628
710
  this.dismiss();
629
711
  }
630
712
  }
713
+ /**
714
+ * `true` when the last pointerdown landed on the backdrop (the dialog
715
+ * element itself, outside the content rect). Backdrop dismissal requires
716
+ * the interaction to START there: a text-selection drag that begins inside
717
+ * the content and releases over the backdrop synthesises a click with
718
+ * outside coordinates and must not dismiss.
719
+ */
720
+ pointerDownOnBackdrop = false;
721
+ handlePointerDown(event) {
722
+ this.pointerDownOnBackdrop =
723
+ event.target === this.dialogElement && this.isOutsideContentRect(event.clientX, event.clientY);
724
+ }
631
725
  handleClick(event) {
632
- if (!this.modal() || !this.closeOnBackdropClick()) {
726
+ const startedOnBackdrop = this.pointerDownOnBackdrop;
727
+ this.pointerDownOnBackdrop = false;
728
+ if (!this.openedAsModal() || !this.closeOnBackdropClick()) {
633
729
  return;
634
730
  }
635
731
  if (this.lifecycleSignal() !== 'open') {
636
732
  return;
637
733
  }
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) {
734
+ // Keyboard "clicks" (Enter/Space on a child control) report (0, 0)
735
+ // coordinates - the target guard rejects them because they target the
736
+ // control, never the dialog element itself.
737
+ if (event.target !== this.dialogElement || !startedOnBackdrop) {
738
+ return;
739
+ }
740
+ if (this.isOutsideContentRect(event.clientX, event.clientY)) {
644
741
  this.dismiss();
645
742
  }
646
743
  }
744
+ /** Backdrop test: coordinates outside the dialog's content rect. */
745
+ isOutsideContentRect(x, y) {
746
+ const rect = this.dialogElement.getBoundingClientRect();
747
+ return x < rect.left || x > rect.right || y < rect.top || y > rect.bottom;
748
+ }
647
749
  get dialogElement() {
648
750
  return this.elRef.nativeElement;
649
751
  }
@@ -661,15 +763,16 @@ class CngxDialog {
661
763
  if (dialog.open) {
662
764
  dialog.close();
663
765
  }
664
- if (this.modal()) {
766
+ if (this.openedAsModal()) {
665
767
  this.releaseScrollLock();
666
768
  this.dialogStack.pop(this.idSignal());
769
+ this.openedAsModal.set(false);
667
770
  }
668
771
  this.lifecycleSignal.set('closed');
669
772
  this.returnFocus();
670
773
  }
671
774
  moveFocus() {
672
- if (!this.modal()) {
775
+ if (!this.openedAsModal()) {
673
776
  return;
674
777
  }
675
778
  const strategy = this.autoFocus();
@@ -707,24 +810,37 @@ class CngxDialog {
707
810
  const span = this.renderer.createElement('span');
708
811
  span.setAttribute('aria-live', 'polite');
709
812
  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';
813
+ applySrOnly(span);
720
814
  this.renderer.appendChild(this.dialogElement, span);
721
815
  this.liveRegion = span;
722
816
  }
817
+ /**
818
+ * Release function of the currently held scroll lock, `null` while not
819
+ * locked. The shared `createScrollLock` core (single WeakMap owner in
820
+ * `@cngx/common/layout`) keeps this instance's count in the same registry
821
+ * as `CngxScrollLock`, so interleaved dialog + directive locks restore the
822
+ * saved overflow values correctly.
823
+ */
824
+ scrollLockRelease = null;
723
825
  acquireScrollLock() {
724
- acquireScrollLock(this.doc.documentElement);
826
+ this.scrollLockRelease ??= createScrollLock(this.doc.documentElement);
725
827
  }
726
828
  releaseScrollLock() {
727
- releaseScrollLock(this.doc.documentElement);
829
+ this.scrollLockRelease?.();
830
+ this.scrollLockRelease = null;
831
+ }
832
+ /**
833
+ * The registry is single-slot per kind, so a second live registration
834
+ * silently wins - surface the authoring error instead of letting the
835
+ * two open paths resolve different labelling.
836
+ */
837
+ warnDoubleRegistration(kind, current, next) {
838
+ if (!isDevMode() || current === null || current === next) {
839
+ return;
840
+ }
841
+ console.warn(`CngxDialog [${this.idSignal()}]: a second ${kind} registered while another ` +
842
+ `is live. The dialog references one ${kind} id - the newest registration ` +
843
+ `wins. Remove the extra cngxDialog${kind === 'title' ? 'Title' : 'Description'} element.`);
728
844
  }
729
845
  warnNonModalA11y() {
730
846
  if (!isDevMode()) {
@@ -743,7 +859,10 @@ class CngxDialog {
743
859
  }
744
860
  }
745
861
  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 });
862
+ 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: [
863
+ { provide: DIALOG_REF, useExisting: CngxDialog },
864
+ { provide: CNGX_DIALOG_ARIA_REGISTRY, useExisting: CngxDialog },
865
+ ], 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
866
  }
748
867
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDialog, decorators: [{
749
868
  type: Directive,
@@ -751,7 +870,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
751
870
  selector: 'dialog[cngxDialog]',
752
871
  exportAs: 'cngxDialog',
753
872
  standalone: true,
754
- providers: [{ provide: DIALOG_REF, useExisting: CngxDialog }],
873
+ providers: [
874
+ { provide: DIALOG_REF, useExisting: CngxDialog },
875
+ { provide: CNGX_DIALOG_ARIA_REGISTRY, useExisting: CngxDialog },
876
+ ],
755
877
  host: {
756
878
  '[class.cngx-dialog--opening]': 'isOpening()',
757
879
  '[class.cngx-dialog--open]': 'isOpen()',
@@ -765,6 +887,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
765
887
  '[class.cngx-dialog--error]': 'effectiveError()',
766
888
  '[style.--cngx-dialog-backdrop-opacity]': 'backdropOpacity()',
767
889
  '(cancel)': 'handleCancel($event)',
890
+ '(pointerdown)': 'handlePointerDown($event)',
768
891
  '(click)': 'handleClick($event)',
769
892
  },
770
893
  }]
@@ -882,7 +1005,7 @@ const CNGX_DIALOG_DATA = new InjectionToken('CngxDialogData');
882
1005
  /**
883
1006
  * Internal container component for programmatically opened dialogs.
884
1007
  *
885
- * Not part of the public API — instantiated exclusively by `CngxDialogOpener`.
1008
+ * Not part of the public API - instantiated exclusively by `CngxDialogOpener`.
886
1009
  * Renders the native `<dialog>` shell and exposes a `<ng-container>` outlet
887
1010
  * where the content component or template is inserted.
888
1011
  *
@@ -893,16 +1016,24 @@ class CngxDialogOutlet {
893
1016
  closeOnBackdropClick = input(true, ...(ngDevMode ? [{ debugName: "closeOnBackdropClick" }] : /* istanbul ignore next */ []));
894
1017
  closeOnEscape = input(true, ...(ngDevMode ? [{ debugName: "closeOnEscape" }] : /* istanbul ignore next */ []));
895
1018
  autoFocus = input('first-focusable', ...(ngDevMode ? [{ debugName: "autoFocus" }] : /* istanbul ignore next */ []));
1019
+ submitAction = input(undefined, ...(ngDevMode ? [{ debugName: "submitAction" }] : /* istanbul ignore next */ []));
1020
+ state = input(undefined, ...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
1021
+ error = input(false, ...(ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []));
1022
+ focusFallback = input(undefined, ...(ngDevMode ? [{ debugName: "focusFallback" }] : /* istanbul ignore next */ []));
896
1023
  dialog = viewChild.required(CngxDialog);
897
1024
  contentOutlet = viewChild('contentOutlet', { ...(ngDevMode ? { debugName: "contentOutlet" } : /* istanbul ignore next */ {}), read: ViewContainerRef });
898
1025
  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: `
1026
+ 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
1027
  <dialog
901
1028
  cngxDialog
902
1029
  [modal]="modal()"
903
1030
  [closeOnBackdropClick]="closeOnBackdropClick()"
904
1031
  [closeOnEscape]="closeOnEscape()"
905
1032
  [autoFocus]="autoFocus()"
1033
+ [submitAction]="submitAction()"
1034
+ [state]="state()"
1035
+ [error]="error()"
1036
+ [focusFallback]="focusFallback()"
906
1037
  #dialog="cngxDialog"
907
1038
  >
908
1039
  <ng-container #contentOutlet />
@@ -918,12 +1049,16 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
918
1049
  [closeOnBackdropClick]="closeOnBackdropClick()"
919
1050
  [closeOnEscape]="closeOnEscape()"
920
1051
  [autoFocus]="autoFocus()"
1052
+ [submitAction]="submitAction()"
1053
+ [state]="state()"
1054
+ [error]="error()"
1055
+ [focusFallback]="focusFallback()"
921
1056
  #dialog="cngxDialog"
922
1057
  >
923
1058
  <ng-container #contentOutlet />
924
1059
  </dialog>
925
1060
  `, 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 }] }] } });
1061
+ }], 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
1062
 
928
1063
  /**
929
1064
  * Reference to a programmatically opened dialog.
@@ -987,6 +1122,16 @@ class CngxDialogRef {
987
1122
  get id() {
988
1123
  return this.inner.id;
989
1124
  }
1125
+ /**
1126
+ * Async state of the submit channel - same surface a declarative dialog
1127
+ * exposes. Populated when the open config carries a `submitAction`;
1128
+ * remains at `'idle'` otherwise.
1129
+ *
1130
+ * Bind to any state consumer: `<cngx-alert [state]="ref.submitState" />`.
1131
+ */
1132
+ get submitState() {
1133
+ return this.inner.submitState;
1134
+ }
990
1135
  /**
991
1136
  * Close the dialog with a typed result value.
992
1137
  *
@@ -1073,6 +1218,13 @@ class CngxDialogOpener {
1073
1218
  injector = inject(Injector);
1074
1219
  doc = inject(DOCUMENT);
1075
1220
  openDialogs = [];
1221
+ /**
1222
+ * Per-open close-watcher effects, keyed by ref. Owned here (not on the
1223
+ * public `CngxDialogRef`) - the effect's injector outlives the dialog, so
1224
+ * without the explicit destroy in `cleanup()` every `open()` would leak
1225
+ * one live effect.
1226
+ */
1227
+ cleanupEffects = new WeakMap();
1076
1228
  open(content, config = {}) {
1077
1229
  const outletRef = createComponent(CngxDialogOutlet, {
1078
1230
  environmentInjector: this.envInjector,
@@ -1083,17 +1235,35 @@ class CngxDialogOpener {
1083
1235
  if (config.autoFocus) {
1084
1236
  outletRef.setInput('autoFocus', config.autoFocus);
1085
1237
  }
1238
+ if (config.submitAction) {
1239
+ outletRef.setInput('submitAction', config.submitAction);
1240
+ }
1241
+ if (config.state) {
1242
+ outletRef.setInput('state', config.state);
1243
+ }
1244
+ if (config.error !== undefined) {
1245
+ outletRef.setInput('error', config.error);
1246
+ }
1247
+ if (config.focusFallback) {
1248
+ outletRef.setInput('focusFallback', config.focusFallback);
1249
+ }
1086
1250
  // Attach to ApplicationRef so change detection runs
1087
1251
  this.appRef.attachView(outletRef.hostView);
1088
1252
  const hostEl = outletRef.location.nativeElement;
1089
1253
  this.doc.body.appendChild(hostEl);
1090
- const innerDialog = outletRef.instance.dialog();
1254
+ // CngxDialog has open() but the DialogRef<T> interface does not - keep
1255
+ // the concrete instance for the open() call below.
1256
+ const dialogInstance = outletRef.instance.dialog();
1257
+ const innerDialog = dialogInstance;
1091
1258
  const outletVcr = outletRef.instance.contentOutlet();
1092
1259
  let contentRef = null;
1093
1260
  const childInjector = Injector.create({
1094
1261
  parent: this.injector,
1095
1262
  providers: [
1096
1263
  { provide: DIALOG_REF, useValue: innerDialog },
1264
+ // Content lives in a dynamically created view the dialog's content
1265
+ // queries cannot see - labelling flows through the registry instead.
1266
+ { provide: CNGX_DIALOG_ARIA_REGISTRY, useValue: dialogInstance },
1097
1267
  { provide: CNGX_DIALOG_DATA, useValue: config.data ?? null },
1098
1268
  ],
1099
1269
  });
@@ -1109,16 +1279,14 @@ class CngxDialogOpener {
1109
1279
  }
1110
1280
  const dialogRef = new CngxDialogRef(innerDialog, outletRef, contentRef, this.injector);
1111
1281
  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
1282
  dialogInstance.open();
1115
- effect(() => {
1283
+ this.cleanupEffects.set(dialogRef, effect(() => {
1116
1284
  if (innerDialog.lifecycle() === 'closed' &&
1117
1285
  outletRef.hostView &&
1118
1286
  !outletRef.hostView.destroyed) {
1119
- this.cleanup(dialogRef);
1287
+ untracked(() => this.cleanup(dialogRef));
1120
1288
  }
1121
- }, { injector: childInjector });
1289
+ }, { injector: childInjector }));
1122
1290
  return dialogRef;
1123
1291
  }
1124
1292
  /**
@@ -1133,6 +1301,8 @@ class CngxDialogOpener {
1133
1301
  }
1134
1302
  }
1135
1303
  cleanup(ref) {
1304
+ this.cleanupEffects.get(ref)?.destroy();
1305
+ this.cleanupEffects.delete(ref);
1136
1306
  const idx = this.openDialogs.indexOf(ref);
1137
1307
  if (idx >= 0) {
1138
1308
  this.openDialogs.splice(idx, 1);
@@ -1212,7 +1382,8 @@ class CngxBottomSheet {
1212
1382
  /**
1213
1383
  * Whether the drag handle bar is visible.
1214
1384
  *
1215
- * The handle itself is rendered via CSS (`::before` pseudo-element on the host).
1385
+ * The handle itself is rendered via CSS (`::before` pseudo-element, gated
1386
+ * on the `cngx-bottom-sheet--handle` modifier class this input binds).
1216
1387
  * Set to `false` to hide it.
1217
1388
  *
1218
1389
  * @defaultValue `true`
@@ -1225,7 +1396,7 @@ class CngxBottomSheet {
1225
1396
  }
1226
1397
  }
1227
1398
  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 });
1399
+ 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
1400
  }
1230
1401
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxBottomSheet, decorators: [{
1231
1402
  type: Directive,
@@ -1235,6 +1406,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
1235
1406
  standalone: true,
1236
1407
  host: {
1237
1408
  class: 'cngx-bottom-sheet',
1409
+ '[class.cngx-bottom-sheet--handle]': 'showHandle()',
1238
1410
  },
1239
1411
  }]
1240
1412
  }], ctorParameters: () => [], propDecorators: { showHandle: [{ type: i0.Input, args: [{ isSignal: true, alias: "showHandle", required: false }] }] } });
@@ -1251,6 +1423,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
1251
1423
  * - Shift + Arrow moves 50px
1252
1424
  * - Home resets to origin
1253
1425
  *
1426
+ * Keys move the dialog only while the handle element itself has focus -
1427
+ * arrows inside form fields keep moving the caret. Without an explicit
1428
+ * `[handle]` the dialog element becomes focusable (`tabindex="0"`) and is
1429
+ * the keyboard drag surface.
1430
+ *
1254
1431
  * ```html
1255
1432
  * <dialog cngxDialog cngxDialogDraggable>
1256
1433
  * <div class="dialog-header" #handle>Title</div>
@@ -1285,6 +1462,7 @@ class CngxDialogDraggable {
1285
1462
  elRef = inject(ElementRef);
1286
1463
  doc = inject(DOCUMENT);
1287
1464
  destroyRef = inject(DestroyRef);
1465
+ ariaRegistry = inject(CNGX_DIALOG_ARIA_REGISTRY, { optional: true });
1288
1466
  /** Handle element for initiating drag. If not set, entire dialog is the handle. */
1289
1467
  handle = input(undefined, ...(ngDevMode ? [{ debugName: "handle" }] : /* istanbul ignore next */ []));
1290
1468
  /** Clamp position to viewport bounds. */
@@ -1308,7 +1486,9 @@ class CngxDialogDraggable {
1308
1486
  * @defaultValue `'live'`
1309
1487
  */
1310
1488
  snapMode = input('live', ...(ngDevMode ? [{ debugName: "snapMode" }] : /* istanbul ignore next */ []));
1311
- positionState = signal({ x: 0, y: 0 }, ...(ngDevMode ? [{ debugName: "positionState" }] : /* istanbul ignore next */ []));
1489
+ // equal keeps live grid-snap quiet: every pointermove produces a fresh
1490
+ // {x, y} literal, and under snapping most of them carry identical values.
1491
+ positionState = signal({ x: 0, y: 0 }, { ...(ngDevMode ? { debugName: "positionState" } : /* istanbul ignore next */ {}), equal: (a, b) => a.x === b.x && a.y === b.y });
1312
1492
  draggingState = signal(false, ...(ngDevMode ? [{ debugName: "draggingState" }] : /* istanbul ignore next */ []));
1313
1493
  /** Current offset position. */
1314
1494
  position = this.positionState.asReadonly();
@@ -1326,29 +1506,49 @@ class CngxDialogDraggable {
1326
1506
  constructor() {
1327
1507
  effect(() => {
1328
1508
  const handleEl = this.handle() ?? this.elRef.nativeElement;
1329
- this.setupHandle(handleEl);
1509
+ // untracked: setupHandle registers with the dialog's aria registry -
1510
+ // a signal write that must not become a tracked dependency.
1511
+ untracked(() => this.setupHandle(handleEl));
1330
1512
  });
1331
1513
  this.destroyRef.onDestroy(() => this.cleanup());
1332
1514
  }
1333
1515
  currentHandle = null;
1334
1516
  boundPointerDown = null;
1335
1517
  boundKeyDown = null;
1518
+ handleAddedTabindex = false;
1519
+ handleAddedAria = false;
1336
1520
  /** Attach pointer and keyboard listeners to `el`, cleaning up the previous handle first. */
1337
1521
  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
- }
1522
+ this.teardownHandle();
1344
1523
  this.currentHandle = el;
1345
- // A11y: make handle focusable and describe as draggable
1346
- if (!el.hasAttribute('tabindex') && el !== this.elRef.nativeElement) {
1524
+ // A11y: the handle must be keyboard-reachable - the target-scoped keydown
1525
+ // guard makes it the only element arrow keys can move the dialog from,
1526
+ // so an unfocusable handle would strip the keyboard path entirely.
1527
+ if (!el.hasAttribute('tabindex')) {
1347
1528
  el.setAttribute('tabindex', '0');
1529
+ this.handleAddedTabindex = true;
1348
1530
  }
1531
+ // Labelling stays off the host-as-handle: aria-label/aria-roledescription
1532
+ // on the dialog element itself would clobber its accessible name (the
1533
+ // title) and its role text.
1349
1534
  if (!el.hasAttribute('aria-roledescription') && el !== this.elRef.nativeElement) {
1350
1535
  el.setAttribute('aria-roledescription', 'draggable');
1351
1536
  el.setAttribute('aria-label', 'Move dialog');
1537
+ this.handleAddedAria = true;
1538
+ }
1539
+ // The keyboard path is live on every handle, so the instruction is too.
1540
+ // The registry channel exists only because CngxDialog owns
1541
+ // aria-describedby on its host; everywhere else (explicit handle,
1542
+ // draggable on a non-dialog element) nothing owns the attribute and it
1543
+ // is set directly - guarded like tabindex, a consumer-authored
1544
+ // describedby wins.
1545
+ const instruction = this.createInstructionNode();
1546
+ if (el === this.elRef.nativeElement && this.ariaRegistry) {
1547
+ this.releaseInstruction = this.ariaRegistry.registerDescribedBy(instruction.id);
1548
+ }
1549
+ else if (!el.hasAttribute('aria-describedby')) {
1550
+ el.setAttribute('aria-describedby', instruction.id);
1551
+ this.handleAddedDescribedBy = true;
1352
1552
  }
1353
1553
  el.style.cursor = 'var(--cngx-dialog-drag-cursor, grab)';
1354
1554
  el.style.touchAction = 'none';
@@ -1383,6 +1583,9 @@ class CngxDialogDraggable {
1383
1583
  this.boundUp = (e) => this.handlePointerUp(e);
1384
1584
  this.doc.addEventListener('pointermove', this.boundMove);
1385
1585
  this.doc.addEventListener('pointerup', this.boundUp);
1586
+ // A cancelled pointer (touch interrupted, capture stolen) never fires
1587
+ // pointerup - without this the drag state sticks and userSelect stays off.
1588
+ this.doc.addEventListener('pointercancel', this.boundUp);
1386
1589
  }
1387
1590
  handlePointerMove(event) {
1388
1591
  let x = this.posStartX + (event.clientX - this.dragStartX);
@@ -1418,11 +1621,18 @@ class CngxDialogDraggable {
1418
1621
  }
1419
1622
  if (this.boundUp) {
1420
1623
  this.doc.removeEventListener('pointerup', this.boundUp);
1624
+ this.doc.removeEventListener('pointercancel', this.boundUp);
1421
1625
  }
1422
1626
  this.boundMove = null;
1423
1627
  this.boundUp = null;
1424
1628
  }
1425
1629
  handleKeyDown(event) {
1630
+ // When the whole dialog is the handle, every keydown inside it bubbles
1631
+ // here - arrows typed into form fields must move the caret, not the
1632
+ // dialog. Only keys originating on the handle element itself may drag.
1633
+ if (event.target !== this.currentHandle) {
1634
+ return;
1635
+ }
1426
1636
  const grid = this.gridSize();
1427
1637
  // When grid is active, Arrow keys step by grid size (Shift = 5x grid)
1428
1638
  const step = grid > 0 ? (event.shiftKey ? grid * 5 : grid) : event.shiftKey ? 50 : 10;
@@ -1461,19 +1671,78 @@ class CngxDialogDraggable {
1461
1671
  y: Math.round(y / grid) * grid,
1462
1672
  };
1463
1673
  }
1674
+ instructionNode = null;
1675
+ releaseInstruction = null;
1676
+ handleAddedDescribedBy = false;
1677
+ /**
1678
+ * Visually hidden keyboard-drag instruction, appended to the host so it
1679
+ * lives inside the dialog for both handle modes. Same hidden technique as
1680
+ * the dialog's live region - a referenced node must stay perceivable to
1681
+ * AT, not `display: none`.
1682
+ */
1683
+ createInstructionNode() {
1684
+ const node = this.doc.createElement('span');
1685
+ node.id = nextUid('cngx-dialog-drag-hint');
1686
+ node.textContent = 'Use arrow keys to move the dialog; Shift for larger steps';
1687
+ applySrOnly(node);
1688
+ this.elRef.nativeElement.appendChild(node);
1689
+ this.instructionNode = node;
1690
+ return node;
1691
+ }
1692
+ /**
1693
+ * Detach listeners from the current handle and restore every attribute and
1694
+ * style this directive added. A demoted handle must not stay focusable or
1695
+ * keep announcing "Move dialog" with a dead keyboard path behind it.
1696
+ *
1697
+ * The instruction node and its describedby registration leave atomically
1698
+ * with the capability they describe: a handle swap away from host-as-handle
1699
+ * removes the arrow-keys-on-the-dialog path itself, so keeping an orphan
1700
+ * description would misinform AT, not inform it.
1701
+ */
1702
+ teardownHandle() {
1703
+ this.releaseInstruction?.();
1704
+ this.releaseInstruction = null;
1705
+ this.instructionNode?.remove();
1706
+ this.instructionNode = null;
1707
+ const handle = this.currentHandle;
1708
+ if (!handle) {
1709
+ return;
1710
+ }
1711
+ if (this.handleAddedDescribedBy) {
1712
+ handle.removeAttribute('aria-describedby');
1713
+ this.handleAddedDescribedBy = false;
1714
+ }
1715
+ if (this.boundPointerDown) {
1716
+ handle.removeEventListener('pointerdown', this.boundPointerDown);
1717
+ }
1718
+ if (this.boundKeyDown) {
1719
+ handle.removeEventListener('keydown', this.boundKeyDown);
1720
+ }
1721
+ if (this.handleAddedTabindex) {
1722
+ handle.removeAttribute('tabindex');
1723
+ this.handleAddedTabindex = false;
1724
+ }
1725
+ if (this.handleAddedAria) {
1726
+ handle.removeAttribute('aria-roledescription');
1727
+ handle.removeAttribute('aria-label');
1728
+ this.handleAddedAria = false;
1729
+ }
1730
+ handle.style.cursor = '';
1731
+ handle.style.touchAction = '';
1732
+ this.currentHandle = null;
1733
+ }
1464
1734
  cleanup() {
1465
1735
  if (this.boundMove) {
1466
1736
  this.doc.removeEventListener('pointermove', this.boundMove);
1467
1737
  }
1468
1738
  if (this.boundUp) {
1469
1739
  this.doc.removeEventListener('pointerup', this.boundUp);
1740
+ this.doc.removeEventListener('pointercancel', this.boundUp);
1470
1741
  }
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
- }
1742
+ // A destroy mid-drag skips handlePointerUp - the global style must not
1743
+ // outlive the directive.
1744
+ this.doc.documentElement.style.userSelect = '';
1745
+ this.teardownHandle();
1477
1746
  }
1478
1747
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDialogDraggable, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1479
1748
  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 });