@cngx/common 0.0.1-rc.0 → 0.1.0-rc.1

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 (61) hide show
  1. package/a11y/README.md +13 -16
  2. package/card/README.md +2 -21
  3. package/chart/README.md +5 -8
  4. package/data/README.md +45 -47
  5. package/dialog/README.md +12 -15
  6. package/display/README.md +5 -9
  7. package/fesm2022/cngx-common-a11y.mjs +164 -51
  8. package/fesm2022/cngx-common-a11y.mjs.map +1 -1
  9. package/fesm2022/cngx-common-card.mjs +157 -69
  10. package/fesm2022/cngx-common-card.mjs.map +1 -1
  11. package/fesm2022/cngx-common-chart.mjs +389 -92
  12. package/fesm2022/cngx-common-chart.mjs.map +1 -1
  13. package/fesm2022/cngx-common-data.mjs +311 -151
  14. package/fesm2022/cngx-common-data.mjs.map +1 -1
  15. package/fesm2022/cngx-common-dialog.mjs +167 -29
  16. package/fesm2022/cngx-common-dialog.mjs.map +1 -1
  17. package/fesm2022/cngx-common-display.mjs +445 -110
  18. package/fesm2022/cngx-common-display.mjs.map +1 -1
  19. package/fesm2022/cngx-common-interactive.mjs +2059 -435
  20. package/fesm2022/cngx-common-interactive.mjs.map +1 -1
  21. package/fesm2022/cngx-common-layout.mjs +188 -31
  22. package/fesm2022/cngx-common-layout.mjs.map +1 -1
  23. package/fesm2022/cngx-common-popover.mjs +711 -90
  24. package/fesm2022/cngx-common-popover.mjs.map +1 -1
  25. package/fesm2022/cngx-common-stepper.mjs +1479 -73
  26. package/fesm2022/cngx-common-stepper.mjs.map +1 -1
  27. package/fesm2022/cngx-common-tabs.mjs +1144 -85
  28. package/fesm2022/cngx-common-tabs.mjs.map +1 -1
  29. package/fesm2022/cngx-common.mjs +2 -2
  30. package/fesm2022/cngx-common.mjs.map +1 -1
  31. package/interactive/README.md +5 -5
  32. package/layout/README.md +2 -2
  33. package/package.json +7 -6
  34. package/popover/README.md +8 -34
  35. package/stepper/README.md +69 -8
  36. package/tabs/README.md +6 -6
  37. package/theming/components/cngx-async.css +74 -0
  38. package/theming/components/cngx-backdrop.css +73 -0
  39. package/theming/components/cngx-badge.css +340 -0
  40. package/theming/components/cngx-bottom-sheet.css +201 -0
  41. package/theming/components/cngx-button-toggle.css +99 -0
  42. package/theming/components/cngx-dialog.css +358 -0
  43. package/theming/components/cngx-divider.css +145 -0
  44. package/theming/components/cngx-listbox.css +220 -0
  45. package/theming/components/cngx-menu.css +371 -0
  46. package/theming/components/cngx-ripple.css +116 -0
  47. package/theming/components/cngx-tooltip.css +265 -0
  48. package/theming/system-tokens.css +24 -0
  49. package/types/cngx-common-a11y.d.ts +159 -38
  50. package/types/cngx-common-card.d.ts +137 -22
  51. package/types/cngx-common-chart.d.ts +337 -40
  52. package/types/cngx-common-data.d.ts +277 -45
  53. package/types/cngx-common-dialog.d.ts +162 -22
  54. package/types/cngx-common-display.d.ts +422 -78
  55. package/types/cngx-common-interactive.d.ts +1880 -305
  56. package/types/cngx-common-layout.d.ts +191 -28
  57. package/types/cngx-common-popover.d.ts +632 -87
  58. package/types/cngx-common-stepper.d.ts +1360 -45
  59. package/types/cngx-common-tabs.d.ts +1139 -56
  60. package/types/cngx-common.d.ts +1 -1
  61. package/README.md +0 -18
@@ -1,16 +1,31 @@
1
1
  import * as i0 from '@angular/core';
2
- import { InjectionToken, model, input, inject, signal, computed, Directive, TemplateRef, contentChild, DestroyRef, afterNextRender, untracked, effect, makeEnvironmentProviders, isDevMode, linkedSignal, runInInjectionContext } from '@angular/core';
2
+ import { InjectionToken, model, input, inject, Injector, computed, output, signal, Directive, TemplateRef, contentChild, DestroyRef, afterNextRender, untracked, effect, makeEnvironmentProviders, isDevMode, linkedSignal, runInInjectionContext } from '@angular/core';
3
3
  import { CNGX_COMMIT_CONTROLLER_FACTORY } from '@cngx/common/data';
4
4
  import { createTransitionTracker, CNGX_STATEFUL, nextUid } from '@cngx/core/utils';
5
- import { isObservable } from 'rxjs';
5
+ import { isObservable, Observable } from 'rxjs';
6
6
  import { toSignal, takeUntilDestroyed } from '@angular/core/rxjs-interop';
7
- import { Router, NavigationEnd } from '@angular/router';
8
- import { filter } from 'rxjs/operators';
7
+ import { Router, NavigationEnd, NavigationCancel, NavigationError } from '@angular/router';
8
+ import { filter, take } from 'rxjs/operators';
9
+
10
+ /**
11
+ * DI fallback the presenter reads when its `[commitAction]` input is
12
+ * unbound. Directives compose via DI tokens, not by hand-binding
13
+ * another directive's input (Pillar 3). When a source is present and
14
+ * exposes a non-null `action()`, its `mode()` wins over the
15
+ * `[commitMode]` input.
16
+ *
17
+ * @category common/tabs
18
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/commit-action.token.ts
19
+ * @since 0.1.0
20
+ */
21
+ const CNGX_TABS_COMMIT_ACTION = new InjectionToken('CngxTabsCommitAction');
9
22
 
10
23
  /**
11
24
  * Wraps a {@link CngxCommitController} with the action-shape adapter
12
25
  * that collapses `Observable<boolean>` / `Promise<boolean>` /
13
26
  * `boolean` returns into a single `accept: boolean` outcome.
27
+ *
28
+ * @category common/tabs
14
29
  */
15
30
  function createTabsCommitHandler(opts) {
16
31
  const { controller } = opts;
@@ -61,7 +76,7 @@ function runTabsAction(action, fromIndex, toIndex, handlers) {
61
76
  }
62
77
  if (isObservable(result)) {
63
78
  // Synchronous Observables (`of(true)`) emit inside `.subscribe` before
64
- // the assignment binds — close over a pre-declared `let` to avoid TDZ.
79
+ // the assignment binds - close over a pre-declared `let` to avoid TDZ.
65
80
  let sub = null;
66
81
  sub = result.subscribe({
67
82
  next: (accept) => {
@@ -72,8 +87,7 @@ function runTabsAction(action, fromIndex, toIndex, handlers) {
72
87
  });
73
88
  unsubscribe = () => sub?.unsubscribe();
74
89
  }
75
- else if (result != null &&
76
- typeof result.then === 'function') {
90
+ else if (result != null && typeof result.then === 'function') {
77
91
  result.then(safeSuccess, safeError);
78
92
  }
79
93
  else {
@@ -91,6 +105,10 @@ function runTabsAction(action, fromIndex, toIndex, handlers) {
91
105
  * {@link createTabsCommitHandler}. Sibling to
92
106
  * `CNGX_ARRAY_COMMIT_HANDLER_FACTORY` (select) and
93
107
  * `CNGX_STEPPER_COMMIT_HANDLER_FACTORY`.
108
+ *
109
+ * @category common/tabs
110
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/commit-handler.ts
111
+ * @since 0.1.0
94
112
  */
95
113
  const CNGX_TABS_COMMIT_HANDLER_FACTORY = new InjectionToken('CngxTabsCommitHandlerFactory', {
96
114
  providedIn: 'root',
@@ -100,21 +118,36 @@ const CNGX_TABS_COMMIT_HANDLER_FACTORY = new InjectionToken('CngxTabsCommitHandl
100
118
  /**
101
119
  * DI token for the tab presenter's contract. Presenter provides via
102
120
  * `useExisting`; `CngxTab` injects to register; the organism injects
103
- * to forward keyboard nav from `CngxRovingTabindex`.
121
+ * to drive the APG tablist keyboard model (automatic activation via
122
+ * `select()`, roving stop derived from `activeId`) through
123
+ * `createTabKeyboardNav`.
124
+ *
125
+ * @category common/tabs
126
+ * @wcag AA
127
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/tab-group-host.token.ts
128
+ * @since 0.1.0
104
129
  */
105
130
  const CNGX_TAB_GROUP_HOST = new InjectionToken('CngxTabGroupHost');
106
131
 
107
132
  /**
108
- * Tab-group presenter — brain of every cngx tab flow. Owns the
133
+ * Tab-group presenter - brain of every cngx tab flow. Owns the
109
134
  * active-index model, the tab registry, orientation, loop policy,
110
135
  * and the commit-controller lifecycle. Provides
111
136
  * {@link CNGX_TAB_GROUP_HOST} for atoms and {@link CNGX_STATEFUL}
112
137
  * so `<cngx-toast-on />` / `<cngx-banner-on />` compose without
113
138
  * `[state]` wiring.
114
139
  *
115
- * **Layer:** `@cngx/common/tabs` (Level 2). Directive-only —
140
+ * **Layer:** `@cngx/common/tabs` (Level 2). Directive-only -
116
141
  * organisms compose via `hostDirectives`, consumers attach
117
142
  * `[cngxTabGroup]` directly.
143
+ *
144
+ * @category common/tabs
145
+ * @docsKind primary
146
+ * @wcag AA
147
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/presenter.directive.ts
148
+ * @since 0.1.0
149
+ * @relatedTo CngxTab, CngxTabContent, CngxTabLabel, CngxTabsFragmentSync
150
+ * <example-url>http://localhost:4200/#/ui/tabs/tab-commit-action/optimistic-pessimistic-commits-with-bridge-directives</example-url>
118
151
  */
119
152
  class CngxTabGroupPresenter {
120
153
  activeIndex = model(0, ...(ngDevMode ? [{ debugName: "activeIndex" }] : /* istanbul ignore next */ []));
@@ -124,20 +157,73 @@ class CngxTabGroupPresenter {
124
157
  * Async-commit action gating the transition. When non-null,
125
158
  * `select(...)` routes through {@link CngxTabsCommitHandler}; the
126
159
  * action's resolution decides whether the change lands. Supersede
127
- * semantics come from the commit-controller — a rapid second
160
+ * semantics come from the commit-controller - a rapid second
128
161
  * `select(...)` cancels the in-flight runner.
162
+ *
163
+ * @internal Two-field alias - bind the public `[commitAction]`; read
164
+ * the resolved {@link commitAction} computed (input ?? DI fallback).
129
165
  */
130
- commitAction = input(null, ...(ngDevMode ? [{ debugName: "commitAction" }] : /* istanbul ignore next */ []));
166
+ commitActionInput = input(null, { ...(ngDevMode ? { debugName: "commitActionInput" } : /* istanbul ignore next */ {}), alias: 'commitAction' });
131
167
  /**
132
- * Default `'optimistic'` — tab change is navigation, not a save,
168
+ * Default `'optimistic'` - tab change is navigation, not a save,
133
169
  * so eager visual feedback matches the user's mental model.
134
170
  * Switch to `'pessimistic'` when the new tab must wait for the
135
171
  * action to confirm.
172
+ *
173
+ * @internal Two-field alias - bind the public `[commitMode]`; read
174
+ * the resolved {@link commitMode} computed (DI fallback mode wins
175
+ * when a routed action is active).
176
+ */
177
+ commitModeInput = input('optimistic', { ...(ngDevMode ? { debugName: "commitModeInput" } : /* istanbul ignore next */ {}), alias: 'commitMode' });
178
+ injector = inject(Injector);
179
+ // Resolved lazily, never in a field initialiser: a sync directive
180
+ // (e.g. [cngxTabsRouteSync]) provides CNGX_TABS_COMMIT_ACTION via
181
+ // useExisting and itself injects this presenter as its host, so
182
+ // eager injection here would close a construction cycle (NG0200).
183
+ // First read happens at select()/template time - after both
184
+ // directives exist. The source is static per element, so memoising
185
+ // the resolution is safe.
186
+ injectedActionSource;
187
+ resolveInjectedAction() {
188
+ if (this.injectedActionSource === undefined) {
189
+ this.injectedActionSource = this.injector.get(CNGX_TABS_COMMIT_ACTION, null);
190
+ }
191
+ return this.injectedActionSource;
192
+ }
193
+ /**
194
+ * Resolved commit-action: the `[commitAction]` input when bound, else
195
+ * the {@link CNGX_TABS_COMMIT_ACTION} DI fallback (routed path), else
196
+ * `null`. `select()` reads this.
136
197
  */
137
- commitMode = input('optimistic', ...(ngDevMode ? [{ debugName: "commitMode" }] : /* istanbul ignore next */ []));
198
+ commitAction = computed(() => this.commitActionInput() ?? this.resolveInjectedAction()?.action() ?? null, ...(ngDevMode ? [{ debugName: "commitAction" }] : /* istanbul ignore next */ []));
199
+ /**
200
+ * Resolved commit mode. When the DI fallback supplies an active
201
+ * action its `mode` wins - the routed path pins `'pessimistic'` so a
202
+ * stray `[commitMode]="'optimistic'"` cannot break the
203
+ * route-follows-resolution invariant. Otherwise the `[commitMode]`
204
+ * input drives.
205
+ */
206
+ commitMode = computed(() => {
207
+ const source = this.resolveInjectedAction();
208
+ return source?.action() ? source.mode() : this.commitModeInput();
209
+ }, ...(ngDevMode ? [{ debugName: "commitMode" }] : /* istanbul ignore next */ []));
210
+ /**
211
+ * Emitted when a tab's close affordance is activated (the close
212
+ * button or Delete/Backspace on the focused tab). The presenter has
213
+ * already moved the active index onto the surviving neighbour; the
214
+ * consumer removes the tab from its own data in the handler.
215
+ */
216
+ tabClose = output();
217
+ /**
218
+ * Emitted when the add-tab affordance is activated. The consumer
219
+ * appends a tab to its own data; the presenter owns no creation logic.
220
+ */
221
+ tabAdd = output();
138
222
  genericFactory = inject(CNGX_COMMIT_CONTROLLER_FACTORY);
139
223
  commitController = this.genericFactory();
140
- commitHandler = inject(CNGX_TABS_COMMIT_HANDLER_FACTORY)({ controller: this.commitController });
224
+ commitHandler = inject(CNGX_TABS_COMMIT_HANDLER_FACTORY)({
225
+ controller: this.commitController,
226
+ });
141
227
  /** Producer surface for the `CNGX_STATEFUL` bridge contract. */
142
228
  state = this.commitController.state;
143
229
  commitState = this.commitController.state;
@@ -154,7 +240,7 @@ class CngxTabGroupPresenter {
154
240
  * the tracker's `linkedSignal` is allocated once per presenter.
155
241
  */
156
242
  commitTransition = createTransitionTracker(() => this.commitController.state.status());
157
- // Persistence-of-error surface — see `CngxTabGroupHost.lastFailedIndex`
243
+ // Persistence-of-error surface - see `CngxTabGroupHost.lastFailedIndex`
158
244
  // and `originIndexDuringCommit` for the contract.
159
245
  lastFailedIndexState = signal(undefined, ...(ngDevMode ? [{ debugName: "lastFailedIndexState" }] : /* istanbul ignore next */ []));
160
246
  originIndexDuringCommitState = signal(undefined, ...(ngDevMode ? [{ debugName: "originIndexDuringCommitState" }] : /* istanbul ignore next */ []));
@@ -209,7 +295,7 @@ class CngxTabGroupPresenter {
209
295
  }
210
296
  const action = this.commitAction();
211
297
  if (!action) {
212
- // No-action fast path — `originIndexDuringCommit` stays
298
+ // No-action fast path - `originIndexDuringCommit` stays
213
299
  // untouched, so a stale origin can never leak into the
214
300
  // live-region announcement.
215
301
  this.activeIndex.set(target);
@@ -218,7 +304,7 @@ class CngxTabGroupPresenter {
218
304
  }
219
305
  return;
220
306
  }
221
- // Open the commit window — origin is captured ONLY here so a
307
+ // Open the commit window - origin is captured ONLY here so a
222
308
  // stale value never lingers into a non-commit navigation.
223
309
  this.originIndexDuringCommitState.set(previous);
224
310
  const mode = this.commitMode();
@@ -227,7 +313,7 @@ class CngxTabGroupPresenter {
227
313
  }
228
314
  this.commitHandler.beginTransition(previous, target, action, (accept) => {
229
315
  if (accept) {
230
- // Window closes on success — origin label no longer needed;
316
+ // Window closes on success - origin label no longer needed;
231
317
  // clear the rejection flag if the user re-picked the failed
232
318
  // target successfully.
233
319
  this.originIndexDuringCommitState.set(undefined);
@@ -239,7 +325,7 @@ class CngxTabGroupPresenter {
239
325
  }
240
326
  }
241
327
  else {
242
- // Reject — flag the refused target; RETAIN the origin so
328
+ // Reject - flag the refused target; RETAIN the origin so
243
329
  // the organism's `liveAnnouncement` computed can resolve
244
330
  // the origin label for the rich rollback phrase. Optimistic
245
331
  // rolls back; pessimistic never moved.
@@ -303,8 +389,29 @@ class CngxTabGroupPresenter {
303
389
  this.select(idx);
304
390
  }
305
391
  }
392
+ requestClose(id) {
393
+ const tabs = this.tabs();
394
+ const index = tabs.findIndex((h) => h.id === id);
395
+ if (index < 0) {
396
+ return;
397
+ }
398
+ const active = this.clampedIndex();
399
+ // Only closing a tab BEFORE the active one needs a pre-emptive
400
+ // index shift: the active tab moves down one slot once the consumer
401
+ // removes the closed tab, so decrement to keep the same tab active.
402
+ // Closing the active tab (or one after it) needs no write -
403
+ // `clampedIndex` re-derives against the shorter array and lands on
404
+ // the next tab (or the new last when the closed tab was last).
405
+ if (index < active) {
406
+ this.activeIndex.set(active - 1);
407
+ }
408
+ this.tabClose.emit({ id, index });
409
+ }
410
+ requestAdd() {
411
+ this.tabAdd.emit();
412
+ }
306
413
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabGroupPresenter, deps: [], target: i0.ɵɵFactoryTarget.Directive });
307
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxTabGroupPresenter, isStandalone: true, selector: "[cngxTabGroup]", inputs: { activeIndex: { classPropertyName: "activeIndex", publicName: "activeIndex", isSignal: true, isRequired: false, transformFunction: null }, orientation: { classPropertyName: "orientation", publicName: "orientation", isSignal: true, isRequired: false, transformFunction: null }, loop: { classPropertyName: "loop", publicName: "loop", isSignal: true, isRequired: false, transformFunction: null }, commitAction: { classPropertyName: "commitAction", publicName: "commitAction", isSignal: true, isRequired: false, transformFunction: null }, commitMode: { classPropertyName: "commitMode", publicName: "commitMode", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { activeIndex: "activeIndexChange" }, providers: [
414
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxTabGroupPresenter, isStandalone: true, selector: "[cngxTabGroup]", inputs: { activeIndex: { classPropertyName: "activeIndex", publicName: "activeIndex", isSignal: true, isRequired: false, transformFunction: null }, orientation: { classPropertyName: "orientation", publicName: "orientation", isSignal: true, isRequired: false, transformFunction: null }, loop: { classPropertyName: "loop", publicName: "loop", isSignal: true, isRequired: false, transformFunction: null }, commitActionInput: { classPropertyName: "commitActionInput", publicName: "commitAction", isSignal: true, isRequired: false, transformFunction: null }, commitModeInput: { classPropertyName: "commitModeInput", publicName: "commitMode", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { activeIndex: "activeIndexChange", tabClose: "tabClose", tabAdd: "tabAdd" }, providers: [
308
415
  { provide: CNGX_TAB_GROUP_HOST, useExisting: CngxTabGroupPresenter },
309
416
  { provide: CNGX_STATEFUL, useExisting: CngxTabGroupPresenter },
310
417
  ], exportAs: ["cngxTabGroup"], ngImport: i0 });
@@ -320,19 +427,22 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
320
427
  { provide: CNGX_STATEFUL, useExisting: CngxTabGroupPresenter },
321
428
  ],
322
429
  }]
323
- }], propDecorators: { activeIndex: [{ type: i0.Input, args: [{ isSignal: true, alias: "activeIndex", required: false }] }, { type: i0.Output, args: ["activeIndexChange"] }], orientation: [{ type: i0.Input, args: [{ isSignal: true, alias: "orientation", required: false }] }], loop: [{ type: i0.Input, args: [{ isSignal: true, alias: "loop", required: false }] }], commitAction: [{ type: i0.Input, args: [{ isSignal: true, alias: "commitAction", required: false }] }], commitMode: [{ type: i0.Input, args: [{ isSignal: true, alias: "commitMode", required: false }] }] } });
430
+ }], propDecorators: { activeIndex: [{ type: i0.Input, args: [{ isSignal: true, alias: "activeIndex", required: false }] }, { type: i0.Output, args: ["activeIndexChange"] }], orientation: [{ type: i0.Input, args: [{ isSignal: true, alias: "orientation", required: false }] }], loop: [{ type: i0.Input, args: [{ isSignal: true, alias: "loop", required: false }] }], commitActionInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "commitAction", required: false }] }], commitModeInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "commitMode", required: false }] }], tabClose: [{ type: i0.Output, args: ["tabClose"] }], tabAdd: [{ type: i0.Output, args: ["tabAdd"] }] } });
324
431
  /**
325
432
  * Structural equality for the tab registry. Compares length and
326
- * per-entry `id`, `disabled()`, and `label()`.
433
+ * per-entry `id`, `disabled()`, `label()`, `subLabel()`, and
434
+ * `closable()`.
327
435
  *
328
- * `errorAggregator` is left out on purpose. The handle is a stable
329
- * per-tab reference injected once, so comparing it would push the
330
- * memoisation burden onto consumers and break the structural-equal
331
- * contract.
436
+ * `errorAggregator`, `hasError`, and `errorMessage` are left out on
437
+ * purpose. The handle is a stable per-tab reference injected once, and
438
+ * the organism reads `tab.hasError()` / `tab.errorMessage()` reactively
439
+ * off that handle (not off array identity), so the badge + descriptor
440
+ * update on error-state changes without the registry array re-emitting.
441
+ * Comparing them here would push the memoisation burden onto consumers
442
+ * and break the structural-equal contract.
332
443
  *
333
- * Reading `disabled()` and `label()` here doesn't subscribe — the
334
- * comparator runs synchronously inside `signal.set()`, outside any
335
- * tracking context.
444
+ * Reading the signals here doesn't subscribe - the comparator runs
445
+ * synchronously inside `signal.set()`, outside any tracking context.
336
446
  *
337
447
  * @internal
338
448
  */
@@ -346,7 +456,9 @@ function tabsEqual(a, b) {
346
456
  for (let i = 0; i < a.length; i++) {
347
457
  if (a[i].id !== b[i].id ||
348
458
  a[i].disabled() !== b[i].disabled() ||
349
- a[i].label() !== b[i].label()) {
459
+ a[i].label() !== b[i].label() ||
460
+ a[i].subLabel() !== b[i].subLabel() ||
461
+ a[i].closable() !== b[i].closable()) {
350
462
  return false;
351
463
  }
352
464
  }
@@ -357,6 +469,11 @@ function tabsEqual(a, b) {
357
469
  * DI token the organism provides via `useExisting`. The overflow
358
470
  * molecule and consumer-authored skin sub-components inject this
359
471
  * instead of the concrete component class.
472
+ *
473
+ * @category common/tabs
474
+ * @wcag AA
475
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/tab-panel-host.token.ts
476
+ * @since 0.1.0
360
477
  */
361
478
  const CNGX_TAB_PANEL_HOST = new InjectionToken('CngxTabPanelHost');
362
479
 
@@ -373,6 +490,20 @@ const CNGX_TAB_PANEL_HOST = new InjectionToken('CngxTabPanelHost');
373
490
  * </ng-template>
374
491
  * </div>
375
492
  * ```
493
+ *
494
+ * @category common/tabs
495
+ * @wcag AA
496
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/tab-content.directive.ts
497
+ * @since 0.1.0
498
+ * @relatedTo CngxTab, CngxTabLabel
499
+ * <example-url>http://localhost:4200/#/ui/tabs/tab-commit-action/optimistic-pessimistic-commits-with-bridge-directives</example-url>
500
+ * <example-url>http://localhost:4200/#/ui/tabs/tab-error-aggregation/per-tab-error-badges</example-url>
501
+ * <example-url>http://localhost:4200/#/ui/tabs/tab-group-vertical/vertical-sidebar-tabs</example-url>
502
+ * <example-url>http://localhost:4200/#/ui/tabs/tab-group/three-tab-navigation</example-url>
503
+ * <example-url>http://localhost:4200/#/ui/tabs/tab-overflow/8-tabs-in-a-narrow-container</example-url>
504
+ * <example-url>http://localhost:4200/#/ui/tabs/tab-slot-overrides/custom-busy-spinner-via-code-cngxtabbusyspinner-code</example-url>
505
+ * <example-url>http://localhost:4200/#/ui/tabs/tab-slot-overrides/custom-error-badge-via-code-cngxtaberrorbadge-code</example-url>
506
+ * <example-url>http://localhost:4200/#/ui/tabs/tab-slot-overrides/rejection-decoration-via-code-cngxtabrejectionicon-code</example-url>
376
507
  */
377
508
  class CngxTabContent {
378
509
  templateRef = inject((TemplateRef));
@@ -399,6 +530,14 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
399
530
  * <ng-template cngxTabContent>...</ng-template>
400
531
  * </div>
401
532
  * ```
533
+ *
534
+ * @category common/tabs
535
+ * @wcag AA
536
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/tab-label.directive.ts
537
+ * @since 0.1.0
538
+ * @relatedTo CngxTab, CngxTabContent
539
+ * <example-url>http://localhost:4200/#/ui/tabs/tab-group-vertical/vertical-sidebar-tabs</example-url>
540
+ * <example-url>http://localhost:4200/#/ui/tabs/tab-group/three-tab-navigation</example-url>
402
541
  */
403
542
  class CngxTabLabel {
404
543
  templateRef = inject((TemplateRef));
@@ -414,40 +553,151 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
414
553
  }]
415
554
  }] });
416
555
 
556
+ /**
557
+ * Structural slot directive marking a tab's secondary label template.
558
+ * Discovered by `<cngx-tab-group>` via `contentChild` on each
559
+ * `CngxTab` and rendered as a stacked second line under the primary
560
+ * label. Per-tab content, mirroring `CngxTabLabel` - the convenience
561
+ * `[subLabel]` string input on `CngxTab` covers the plain-text case.
562
+ *
563
+ * ```html
564
+ * <div cngxTab id="bookmarks">
565
+ * <ng-template cngxTabLabel>Bookmarks</ng-template>
566
+ * <ng-template cngxTabSubLabel>45 saved</ng-template>
567
+ * <ng-template cngxTabContent>...</ng-template>
568
+ * </div>
569
+ * ```
570
+ *
571
+ * @category common/tabs
572
+ * @wcag AA
573
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/slots/tab-sub-label.directive.ts
574
+ * @since 0.1.0
575
+ * @relatedTo CngxTab, CngxTabLabel, CngxTabContent
576
+ * <example-url>http://localhost:4200/#/ui/tabs/tab-sub-label/label-with-count</example-url>
577
+ */
578
+ class CngxTabSubLabel {
579
+ templateRef = inject((TemplateRef));
580
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabSubLabel, deps: [], target: i0.ɵɵFactoryTarget.Directive });
581
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxTabSubLabel, isStandalone: true, selector: "ng-template[cngxTabSubLabel]", exportAs: ["cngxTabSubLabel"], ngImport: i0 });
582
+ }
583
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabSubLabel, decorators: [{
584
+ type: Directive,
585
+ args: [{
586
+ selector: 'ng-template[cngxTabSubLabel]',
587
+ exportAs: 'cngxTabSubLabel',
588
+ standalone: true,
589
+ }]
590
+ }] });
591
+
417
592
  /**
418
593
  * Single-tab atom. Registers with the enclosing presenter via
419
594
  * {@link CNGX_TAB_GROUP_HOST} on construction; deregisters via
420
595
  * {@link DestroyRef} on teardown. The presenter holds the atom's
421
596
  * input signals by reference, so input changes propagate without
422
597
  * re-registration. `labelTemplate` / `contentTemplate` are projected
423
- * by the organism — the atom carries no rendering logic.
598
+ * by the organism - the atom carries no rendering logic.
599
+ *
600
+ * @category common/tabs
601
+ * @docsKind primary
602
+ * @wcag AA
603
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/tab.directive.ts
604
+ * @since 0.1.0
605
+ * @relatedTo CngxTabGroupPresenter, CngxTabLabel, CngxTabContent, CngxTabErrorBadge
606
+ * <example-url>http://localhost:4200/#/ui/tabs/tab-commit-action/optimistic-pessimistic-commits-with-bridge-directives</example-url>
607
+ * <example-url>http://localhost:4200/#/ui/tabs/tab-error-aggregation/per-tab-error-badges</example-url>
608
+ * <example-url>http://localhost:4200/#/ui/tabs/tab-group-vertical/vertical-sidebar-tabs</example-url>
609
+ * <example-url>http://localhost:4200/#/ui/tabs/tab-group/three-tab-navigation</example-url>
610
+ * <example-url>http://localhost:4200/#/ui/tabs/tab-overflow/8-tabs-in-a-narrow-container</example-url>
611
+ * <example-url>http://localhost:4200/#/ui/tabs/tab-slot-overrides/custom-busy-spinner-via-code-cngxtabbusyspinner-code</example-url>
612
+ * <example-url>http://localhost:4200/#/ui/tabs/tab-slot-overrides/custom-error-badge-via-code-cngxtaberrorbadge-code</example-url>
613
+ * <example-url>http://localhost:4200/#/ui/tabs/tab-slot-overrides/rejection-decoration-via-code-cngxtabrejectionicon-code</example-url>
424
614
  */
425
615
  class CngxTab {
426
616
  id = input(nextUid('cngx-tab-'), ...(ngDevMode ? [{ debugName: "id" }] : /* istanbul ignore next */ []));
427
617
  disabled = input(false, ...(ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []));
428
618
  label = input(undefined, ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
619
+ /**
620
+ * Optional secondary text line under the primary label (a count, a
621
+ * status word, a short detail). Convenience for the common text
622
+ * case, parallel to `[label]`; the `*cngxTabSubLabel` slot covers
623
+ * richer content. Folds into the tab's accessible name.
624
+ */
625
+ subLabel = input(undefined, ...(ngDevMode ? [{ debugName: "subLabel" }] : /* istanbul ignore next */ []));
429
626
  errorAggregator = input(undefined, ...(ngDevMode ? [{ debugName: "errorAggregator" }] : /* istanbul ignore next */ []));
627
+ /**
628
+ * Direct error flag for the common "this tab is invalid" case - no
629
+ * `errorAggregator` boilerplate required. `true` or a non-empty string
630
+ * drives the error state; a string doubles as the inline message
631
+ * (surfaced via the `*cngxTabErrorBadge` slot context). `false` / `''`
632
+ * clear it. The aggregator stays the rich multi-source forms path; the
633
+ * two channels compose (either errors). Mirrors `CngxStep.error`.
634
+ */
635
+ error = input(false, ...(ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []));
636
+ /**
637
+ * Resolved direct-error message: the `[error]` string when non-empty,
638
+ * else `undefined`. Carried onto the registration handle so the error
639
+ * badge slot can render it. `computed` over the input - never written.
640
+ */
641
+ errorMessage = computed(() => {
642
+ const value = this.error();
643
+ return typeof value === 'string' && value !== '' ? value : undefined;
644
+ }, ...(ngDevMode ? [{ debugName: "errorMessage" }] : /* istanbul ignore next */ []));
645
+ /**
646
+ * Per-tab error fold driving the badge + SR descriptor. `true` when
647
+ * the direct `[error]` flag is set OR the optional aggregator wants to
648
+ * reveal (`shouldShow()` = `hasError` AND scope reveal-state). The
649
+ * aggregator arm reads `shouldShow`, not `hasError`, so deferred-reveal
650
+ * validation stays silent until revealed - the direct flag has no
651
+ * reveal concept (the consumer sets it when it wants it shown). A
652
+ * boolean, not a status enum: tabs carry no success/completed/disabled
653
+ * model (Pillar 3).
654
+ */
655
+ hasError = computed(() => {
656
+ const directError = this.error();
657
+ return ((directError !== false && directError !== '') ||
658
+ (this.errorAggregator()?.shouldShow?.() ?? false));
659
+ }, { ...(ngDevMode ? { debugName: "hasError" } : /* istanbul ignore next */ {}), equal: Object.is });
660
+ /**
661
+ * Per-tab close-affordance override. `undefined` (default) inherits
662
+ * the group-level `[closable]` resolution; set `false` to pin this
663
+ * tab open inside a dismissable group, or `true` to make a single tab
664
+ * closable while the group default is off.
665
+ */
666
+ closable = input(undefined, ...(ngDevMode ? [{ debugName: "closable" }] : /* istanbul ignore next */ []));
430
667
  labelTemplate = contentChild(CngxTabLabel, ...(ngDevMode ? [{ debugName: "labelTemplate" }] : /* istanbul ignore next */ []));
668
+ subLabelTemplate = contentChild(CngxTabSubLabel, ...(ngDevMode ? [{ debugName: "subLabelTemplate" }] : /* istanbul ignore next */ []));
431
669
  contentTemplate = contentChild(CngxTabContent, ...(ngDevMode ? [{ debugName: "contentTemplate" }] : /* istanbul ignore next */ []));
432
670
  host = inject(CNGX_TAB_GROUP_HOST, { optional: true });
671
+ destroyRef = inject(DestroyRef);
433
672
  /** `true` when the presenter's `activeId` equals this tab's id. */
434
673
  selected = computed(() => this.host?.activeId() === this.id(), { ...(ngDevMode ? { debugName: "selected" } : /* istanbul ignore next */ {}), equal: Object.is });
435
674
  constructor() {
436
675
  if (!this.host) {
437
676
  throw new Error('CngxTab: no enclosing CngxTabGroupPresenter found. Wrap the tab inside an element carrying [cngxTabGroup] (or place it inside <cngx-tab-group>).');
438
677
  }
678
+ }
679
+ ngOnInit() {
680
+ // Register in ngOnInit, NOT the constructor: a dynamically-bound
681
+ // `[id]` (or `[label]`) signal input is not applied until the first
682
+ // change detection, so a constructor read would capture the default
683
+ // auto-id. The handle id is the stable key consumers map `(tabClose)`
684
+ // back to their data with, so it must reflect the bound `[id]`.
685
+ const host = this.host;
439
686
  const tabId = this.id();
440
- this.host.register({
687
+ host.register({
441
688
  id: tabId,
442
689
  label: this.label,
690
+ subLabel: this.subLabel,
443
691
  disabled: this.disabled,
444
692
  errorAggregator: this.errorAggregator,
693
+ hasError: this.hasError,
694
+ errorMessage: this.errorMessage,
695
+ closable: this.closable,
445
696
  });
446
- const host = this.host;
447
- inject(DestroyRef).onDestroy(() => host.unregister(tabId));
697
+ this.destroyRef.onDestroy(() => host.unregister(tabId));
448
698
  }
449
699
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTab, deps: [], target: i0.ɵɵFactoryTarget.Directive });
450
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.2.0", version: "21.2.4", type: CngxTab, isStandalone: true, selector: "[cngxTab]", inputs: { id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, errorAggregator: { classPropertyName: "errorAggregator", publicName: "errorAggregator", isSignal: true, isRequired: false, transformFunction: null } }, queries: [{ propertyName: "labelTemplate", first: true, predicate: CngxTabLabel, descendants: true, isSignal: true }, { propertyName: "contentTemplate", first: true, predicate: CngxTabContent, descendants: true, isSignal: true }], exportAs: ["cngxTab"], ngImport: i0 });
700
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.2.0", version: "21.2.4", type: CngxTab, isStandalone: true, selector: "[cngxTab]", inputs: { id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, subLabel: { classPropertyName: "subLabel", publicName: "subLabel", isSignal: true, isRequired: false, transformFunction: null }, errorAggregator: { classPropertyName: "errorAggregator", publicName: "errorAggregator", isSignal: true, isRequired: false, transformFunction: null }, error: { classPropertyName: "error", publicName: "error", isSignal: true, isRequired: false, transformFunction: null }, closable: { classPropertyName: "closable", publicName: "closable", isSignal: true, isRequired: false, transformFunction: null } }, queries: [{ propertyName: "labelTemplate", first: true, predicate: CngxTabLabel, descendants: true, isSignal: true }, { propertyName: "subLabelTemplate", first: true, predicate: CngxTabSubLabel, descendants: true, isSignal: true }, { propertyName: "contentTemplate", first: true, predicate: CngxTabContent, descendants: true, isSignal: true }], exportAs: ["cngxTab"], ngImport: i0 });
451
701
  }
452
702
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTab, decorators: [{
453
703
  type: Directive,
@@ -456,7 +706,22 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
456
706
  exportAs: 'cngxTab',
457
707
  standalone: true,
458
708
  }]
459
- }], ctorParameters: () => [], propDecorators: { id: [{ type: i0.Input, args: [{ isSignal: true, alias: "id", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], errorAggregator: [{ type: i0.Input, args: [{ isSignal: true, alias: "errorAggregator", required: false }] }], labelTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => CngxTabLabel), { isSignal: true }] }], contentTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => CngxTabContent), { isSignal: true }] }] } });
709
+ }], ctorParameters: () => [], propDecorators: { id: [{ type: i0.Input, args: [{ isSignal: true, alias: "id", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], subLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "subLabel", required: false }] }], errorAggregator: [{ type: i0.Input, args: [{ isSignal: true, alias: "errorAggregator", required: false }] }], error: [{ type: i0.Input, args: [{ isSignal: true, alias: "error", required: false }] }], closable: [{ type: i0.Input, args: [{ isSignal: true, alias: "closable", required: false }] }], labelTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => CngxTabLabel), { isSignal: true }] }], subLabelTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => CngxTabSubLabel), { isSignal: true }] }], contentTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => CngxTabContent), { isSignal: true }] }] } });
710
+
711
+ /**
712
+ * Single dev-warning both tab sync directives emit when `@angular/router`
713
+ * is not provided. Shared so the message stays identical across
714
+ * {@link CngxTabsFragmentSync} (deep-linking) and {@link CngxTabsRouteSync}
715
+ * (router-outlet); only the `enables` clause differs. The URL readers
716
+ * themselves stay separate - they target different surfaces (fragment /
717
+ * query-param vs route path) and must not converge.
718
+ *
719
+ * @internal
720
+ */
721
+ function warnTabsRouterAbsent(directive, enables) {
722
+ console.warn(`${directive}: no Router available - directive is a no-op. ` +
723
+ `Provide @angular/router via provideRouter(...) to enable ${enables}.`);
724
+ }
460
725
 
461
726
  /**
462
727
  * URL deep-linking for tab groups. Bidirectional sync between
@@ -466,9 +731,16 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
466
731
  * - `mode = 'fragment'` (default) → `#tab=settings`
467
732
  * - `mode = 'queryParam'` with `paramName = 'tab'` → `?tab=settings`
468
733
  *
469
- * `Router` is optional — without it the directive logs a dev warning
734
+ * `Router` is optional - without it the directive logs a dev warning
470
735
  * via `afterNextRender` and becomes a no-op. Every `router.navigate`
471
736
  * and `host.selectById` inside the effects sits in `untracked()`.
737
+ *
738
+ * @category common/tabs
739
+ * @docsKind primary
740
+ * @wcag AA
741
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/router-sync.directive.ts
742
+ * @since 0.1.0
743
+ * @relatedTo CngxTabGroupPresenter, CngxTab
472
744
  */
473
745
  class CngxTabsFragmentSync {
474
746
  mode = input('fragment', ...(ngDevMode ? [{ debugName: "mode" }] : /* istanbul ignore next */ []));
@@ -477,10 +749,7 @@ class CngxTabsFragmentSync {
477
749
  router = inject(Router, { optional: true });
478
750
  constructor() {
479
751
  if (!this.router) {
480
- afterNextRender(() => {
481
- console.warn('CngxTabsFragmentSync: no Router available — directive is a no-op. ' +
482
- 'Provide @angular/router via provideRouter(...) to enable deep-linking.');
483
- });
752
+ afterNextRender(() => warnTabsRouterAbsent('CngxTabsFragmentSync', 'deep-linking'));
484
753
  return;
485
754
  }
486
755
  const router = this.router;
@@ -531,8 +800,7 @@ class CngxTabsFragmentSync {
531
800
  const fragment = router.routerState.snapshot.root.fragment ?? '';
532
801
  return this.parseFragment(fragment);
533
802
  }
534
- return (router.routerState.snapshot.root.queryParamMap.get(this.paramName()) ??
535
- null);
803
+ return router.routerState.snapshot.root.queryParamMap.get(this.paramName()) ?? null;
536
804
  }
537
805
  parseFragment(fragment) {
538
806
  const param = this.paramName();
@@ -557,17 +825,210 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
557
825
  }]
558
826
  }], ctorParameters: () => [], propDecorators: { mode: [{ type: i0.Input, args: [{ isSignal: true, alias: "mode", required: false }] }], paramName: [{ type: i0.Input, args: [{ isSignal: true, alias: "paramName", required: false }] }] } });
559
827
 
828
+ /**
829
+ * Default tab-to-route mapping: the tab id is the child segment.
830
+ * Shared so the factory and `[cngxTabsRouteSync]` reference one
831
+ * definition instead of inlining the closure twice.
832
+ *
833
+ * @internal
834
+ */
835
+ const cngxDefaultTabRoute = (handle) => [handle.id];
836
+ /**
837
+ * Builds a {@link CngxTabsCommitAction} that gates a tab switch through
838
+ * `@angular/router`. The action navigates to the target tab's route and
839
+ * resolves on the router's own outcome:
840
+ *
841
+ * - `NavigationEnd` → `true` (commit the switch)
842
+ * - `NavigationCancel` (a `CanDeactivate` guard blocked) → `false`
843
+ * - `NavigationError` (guard/resolver threw) → `false`
844
+ *
845
+ * Routed tabs reuse the presenter's commit lifecycle verbatim - the
846
+ * router navigation is simply the async op. In pessimistic mode the
847
+ * active tab follows the *resolved* route, so a cancelled guard keeps
848
+ * the old tab with zero extra gate machinery. The events subscription
849
+ * is opened *before* `navigate(...)` so a synchronously-resolving
850
+ * navigation cannot emit before the action is listening; the commit
851
+ * controller's `cancel()` unsubscribes on supersede.
852
+ *
853
+ * @category common/tabs
854
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/router-commit.ts
855
+ * @since 0.1.0
856
+ */
857
+ function createTabRouterCommit(opts) {
858
+ const routeFor = opts.routeFor ?? cngxDefaultTabRoute;
859
+ return (_fromIndex, toIndex) => new Observable((subscriber) => {
860
+ const target = opts.tabs()[toIndex];
861
+ if (!target) {
862
+ subscriber.next(false);
863
+ subscriber.complete();
864
+ return;
865
+ }
866
+ const sub = opts.router.events
867
+ .pipe(filter((e) => e instanceof NavigationEnd ||
868
+ e instanceof NavigationCancel ||
869
+ e instanceof NavigationError), take(1))
870
+ .subscribe((event) => {
871
+ subscriber.next(event instanceof NavigationEnd);
872
+ subscriber.complete();
873
+ });
874
+ // A rejected promise surfaces on the events stream as
875
+ // NavigationError, so the subscription above is the single
876
+ // resolution path; swallow the promise rejection to avoid an
877
+ // unhandled-rejection warning.
878
+ opts.router.navigate(routeFor(target)).catch(() => undefined);
879
+ return () => sub.unsubscribe();
880
+ });
881
+ }
882
+
883
+ /**
884
+ * Router-outlet integration for tab groups. Opt-in via
885
+ * `[cngxTabsRouteSync]` on the presenter element. Each tab is an
886
+ * Angular child route whose component renders into a `<router-outlet>`;
887
+ * switching tabs navigates, and a `CanDeactivate` guard can gate the
888
+ * leave.
889
+ *
890
+ * Supplies the presenter's commit-action through the
891
+ * {@link CNGX_TABS_COMMIT_ACTION} DI fallback (no consumer
892
+ * `[commitAction]` hand-binding) and pins **pessimistic** mode so the
893
+ * active tab follows the *resolved* route - a guard-cancelled switch
894
+ * keeps the old tab. The routing gate reuses the presenter's commit
895
+ * lifecycle verbatim; the router navigation is the async op.
896
+ *
897
+ * Seeds the active tab from the current URL on mount and reflects
898
+ * external navigations (back/forward, direct URL) into `activeIndex`
899
+ * *without* re-navigating - those writes bypass the commit-action,
900
+ * since the router is already at the resolved route.
901
+ *
902
+ * `Router` is optional - without it the directive logs a single dev
903
+ * warning via `afterNextRender`, exposes a null action, and becomes a
904
+ * no-op. Mirrors {@link CngxTabsFragmentSync}; every `activeIndex`
905
+ * write inside an effect sits in `untracked()`.
906
+ *
907
+ * @category common/tabs
908
+ * @docsKind primary
909
+ * @wcag AA
910
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/route-sync.directive.ts
911
+ * @since 0.1.0
912
+ * @relatedTo CngxTabGroupPresenter, CngxTabsFragmentSync, createTabRouterCommit
913
+ */
914
+ class CngxTabsRouteSync {
915
+ /**
916
+ * Maps a tab handle to its router command array. Default
917
+ * `(handle) => [handle.id]` - the tab id is the child segment.
918
+ * Override for real route paths.
919
+ */
920
+ routeFor = input(cngxDefaultTabRoute, ...(ngDevMode ? [{ debugName: "routeFor" }] : /* istanbul ignore next */ []));
921
+ host = inject(CNGX_TAB_GROUP_HOST, { host: true });
922
+ router = inject(Router, { optional: true });
923
+ /**
924
+ * Pessimistic-only - not exposed as an input. The route-sync owns the
925
+ * mode so optimistic (show-then-revert) can never flash the target
926
+ * tab before a `CanDeactivate` guard decides.
927
+ */
928
+ mode = signal('pessimistic', ...(ngDevMode ? [{ debugName: "mode" }] : /* istanbul ignore next */ []));
929
+ /**
930
+ * Router commit-action read by the presenter via the DI fallback.
931
+ * `null` when no `Router` is available (graceful no-op). Rebuilt only
932
+ * when `routeFor` changes; the navigation gate itself is the async
933
+ * op inside the action.
934
+ */
935
+ action = computed(() => {
936
+ const router = this.router;
937
+ if (!router) {
938
+ return null;
939
+ }
940
+ return createTabRouterCommit({
941
+ router,
942
+ tabs: this.host.tabs,
943
+ routeFor: this.routeFor(),
944
+ });
945
+ }, ...(ngDevMode ? [{ debugName: "action" }] : /* istanbul ignore next */ []));
946
+ constructor() {
947
+ if (!this.router) {
948
+ afterNextRender(() => warnTabsRouterAbsent('CngxTabsRouteSync', 'routed tabs'));
949
+ return;
950
+ }
951
+ const router = this.router;
952
+ const destroyRef = inject(DestroyRef);
953
+ // Seed from the current URL once the registry has populated.
954
+ afterNextRender(() => {
955
+ untracked(() => this.reflectFromUrl(router));
956
+ });
957
+ const navEnd = toSignal(router.events.pipe(filter((e) => e instanceof NavigationEnd), takeUntilDestroyed(destroyRef)), { initialValue: null });
958
+ effect(() => {
959
+ const e = navEnd();
960
+ if (!e) {
961
+ return;
962
+ }
963
+ untracked(() => this.reflectFromUrl(router));
964
+ });
965
+ }
966
+ /**
967
+ * Mirror the URL's active tab onto `activeIndex` without navigating.
968
+ * Writing the index directly (not via `select()`) is the re-entry
969
+ * guard: `select()` would re-run the commit-action and navigate to
970
+ * the route the router is already on, leaving the commit pending
971
+ * forever.
972
+ */
973
+ reflectFromUrl(router) {
974
+ const next = this.readActiveId(router);
975
+ if (!next || next === this.host.activeId()) {
976
+ return;
977
+ }
978
+ const index = this.host.tabs().findIndex((t) => t.id === next);
979
+ if (index >= 0) {
980
+ this.host.activeIndex.set(index);
981
+ }
982
+ }
983
+ /**
984
+ * Find the tab whose route is the trailing segment(s) of the current
985
+ * URL path. Anchors on position (a suffix match), not a loose
986
+ * "appears anywhere" scan - a tab id that happens to equal an
987
+ * unrelated parent segment cannot win. The path is taken before any
988
+ * query/fragment. If two tabs produce the same trailing segment(s)
989
+ * (only possible with a custom `routeFor` that collides), the first
990
+ * registered tab wins - the default id-based mapping never collides.
991
+ */
992
+ readActiveId(router) {
993
+ const path = router.url.split(/[?#]/)[0];
994
+ const segments = path.split('/').filter(Boolean);
995
+ const routeFor = this.routeFor();
996
+ for (const tab of this.host.tabs()) {
997
+ const route = routeFor(tab).map((command) => String(command));
998
+ if (route.length === 0 || route.length > segments.length) {
999
+ continue;
1000
+ }
1001
+ const tail = segments.slice(-route.length);
1002
+ if (tail.every((segment, i) => segment === route[i])) {
1003
+ return tab.id;
1004
+ }
1005
+ }
1006
+ return null;
1007
+ }
1008
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabsRouteSync, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1009
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxTabsRouteSync, isStandalone: true, selector: "[cngxTabsRouteSync]", inputs: { routeFor: { classPropertyName: "routeFor", publicName: "routeFor", isSignal: true, isRequired: false, transformFunction: null } }, providers: [{ provide: CNGX_TABS_COMMIT_ACTION, useExisting: CngxTabsRouteSync }], exportAs: ["cngxTabsRouteSync"], ngImport: i0 });
1010
+ }
1011
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabsRouteSync, decorators: [{
1012
+ type: Directive,
1013
+ args: [{
1014
+ selector: '[cngxTabsRouteSync]',
1015
+ exportAs: 'cngxTabsRouteSync',
1016
+ standalone: true,
1017
+ providers: [{ provide: CNGX_TABS_COMMIT_ACTION, useExisting: CngxTabsRouteSync }],
1018
+ }]
1019
+ }], ctorParameters: () => [], propDecorators: { routeFor: [{ type: i0.Input, args: [{ isSignal: true, alias: "routeFor", required: false }] }] } });
1020
+
560
1021
  const TABS_CONFIG_DEFAULTS = {
561
1022
  defaultOrientation: 'horizontal',
562
1023
  defaultLoop: true,
563
1024
  defaultCommitMode: 'optimistic',
564
- routerSyncMode: 'fragment',
565
- routerSyncParam: 'tab',
1025
+ fragmentSyncMode: 'fragment',
1026
+ fragmentSyncParam: 'tab',
566
1027
  ariaLabels: {
567
1028
  tabsRegion: 'Tabs',
568
1029
  },
569
1030
  fallbackLabels: {
570
- // W3C ARIA tablist convention — kept distinct from
1031
+ // W3C ARIA tablist convention - kept distinct from
571
1032
  // `i18n.tabsLabel` so AT doesn't read the same string twice
572
1033
  // back-to-back across `aria-roledescription` and `aria-label`.
573
1034
  tabRoleDescription: 'tab list',
@@ -581,8 +1042,16 @@ const TABS_CONFIG_DEFAULTS = {
581
1042
  * DI token for the resolved tabs config. `providedIn: 'root'` with
582
1043
  * the library defaults; override via {@link provideTabsConfig}
583
1044
  * (root) or {@link provideTabsConfigAt} (component scope).
1045
+ *
1046
+ * @category common/tabs
1047
+ * @wcag AA
1048
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/tabs-config.ts
1049
+ * @since 0.1.0
584
1050
  */
585
- const CNGX_TABS_CONFIG = new InjectionToken('CngxTabsConfig', { providedIn: 'root', factory: () => TABS_CONFIG_DEFAULTS });
1051
+ const CNGX_TABS_CONFIG = new InjectionToken('CngxTabsConfig', {
1052
+ providedIn: 'root',
1053
+ factory: () => TABS_CONFIG_DEFAULTS,
1054
+ });
586
1055
  /**
587
1056
  * Internal helper that brands a config-mutator function with the
588
1057
  * `_target` discriminator. Every `with*` config feature returns one
@@ -596,6 +1065,8 @@ function defineTabsConfigFeature(fn) {
596
1065
  /**
597
1066
  * Override the default orientation. Per-instance `[orientation]`
598
1067
  * still wins; this changes the cascade default only.
1068
+ *
1069
+ * @category common/tabs
599
1070
  */
600
1071
  function withTabsDefaultOrientation(orientation) {
601
1072
  return defineTabsConfigFeature((cfg) => ({
@@ -608,11 +1079,15 @@ function withTabsDefaultOrientation(orientation) {
608
1079
  * collides with the stepper family's identical symbol when both libs
609
1080
  * are auto-imported. The alias stays for one minor release before
610
1081
  * removal.
1082
+ *
1083
+ * @category common/tabs
611
1084
  */
612
1085
  const withDefaultOrientation = withTabsDefaultOrientation;
613
1086
  /**
614
1087
  * Override whether roving-tabindex navigation loops from last back to
615
1088
  * first (and vice versa). Per-instance `[loop]` Input still wins.
1089
+ *
1090
+ * @category common/tabs
616
1091
  */
617
1092
  function withTabsRovingLoop(loop) {
618
1093
  return defineTabsConfigFeature((cfg) => ({ ...cfg, defaultLoop: loop }));
@@ -622,6 +1097,8 @@ function withTabsRovingLoop(loop) {
622
1097
  * `'optimistic'` activates the tab on action dispatch and rolls back
623
1098
  * on error; `'pessimistic'` waits for success. Per-instance
624
1099
  * `[commitMode]` Input still wins.
1100
+ *
1101
+ * @category common/tabs
625
1102
  */
626
1103
  function withTabsCommitMode(mode) {
627
1104
  return defineTabsConfigFeature((cfg) => ({
@@ -630,20 +1107,112 @@ function withTabsCommitMode(mode) {
630
1107
  }));
631
1108
  }
632
1109
  /**
633
- * Configure router synchronisation for the active tab. `mode` chooses
634
- * the URL surface (URL fragment or query parameter); `param` names
635
- * the key (default `'tab'`).
1110
+ * Configure URL fragment / query-param deep-linking for the active tab
1111
+ * (the {@link CngxTabsFragmentSync} directive). `mode` chooses the URL
1112
+ * surface (URL fragment or query parameter); `param` names the key
1113
+ * (default `'tab'`).
1114
+ *
1115
+ * Not to be confused with `[cngxTabsRouteSync]`, the router-outlet
1116
+ * integration - this feature configures fragment deep-linking only.
1117
+ *
1118
+ * @category common/tabs
636
1119
  */
637
- function withTabsRouterSync(mode, param = 'tab') {
1120
+ function withTabsFragmentSync(mode, param = 'tab') {
638
1121
  return defineTabsConfigFeature((cfg) => ({
639
1122
  ...cfg,
640
- routerSyncMode: mode,
641
- routerSyncParam: param,
1123
+ fragmentSyncMode: mode,
1124
+ fragmentSyncParam: param,
642
1125
  }));
643
1126
  }
1127
+ /**
1128
+ * @deprecated Use {@link withTabsFragmentSync}. "Router sync" collided
1129
+ * with the new `[cngxTabsRouteSync]` router-outlet directive; this
1130
+ * feature only ever configured fragment / query-param deep-linking. The
1131
+ * alias stays for one minor release before removal.
1132
+ *
1133
+ * @category common/tabs
1134
+ */
1135
+ const withTabsRouterSync = withTabsFragmentSync;
1136
+ /**
1137
+ * Select the app-wide default visual skin for `<cngx-tab-group>`.
1138
+ * Default `'line'`. Per-instance `[skin]` Input still wins; this moves
1139
+ * the cascade default. Structure, slots, ARIA, and keyboard behaviour
1140
+ * are identical across skins - only the `[data-skin]` host attribute
1141
+ * changes the CSS layer. The Material twin (`[cngxMatTabs]`) ignores it.
1142
+ *
1143
+ * @category common/tabs
1144
+ */
1145
+ function withTabsSkin(skin) {
1146
+ return defineTabsConfigFeature((cfg) => ({ ...cfg, skin }));
1147
+ }
1148
+ /**
1149
+ * Set the app-wide default icon layout for `<cngx-tab-group>`. Default
1150
+ * `'start'`. Per-instance `[iconLayout]` Input still wins. Orthogonal to
1151
+ * skin and orientation - only the `[data-icon-layout]` host attribute
1152
+ * changes.
1153
+ *
1154
+ * @category common/tabs
1155
+ */
1156
+ function withTabsIconLayout(layout) {
1157
+ return defineTabsConfigFeature((cfg) => ({ ...cfg, iconLayout: layout }));
1158
+ }
1159
+ /**
1160
+ * Set the app-wide default panel render strategy for `<cngx-tab-group>`.
1161
+ * Default `'eager'` (every panel's content rendered up front, toggled
1162
+ * via `[hidden]`). `'lazy'` keep-alives content after first activation;
1163
+ * `'lazy-destroy'` renders only the active panel's content. Per-instance
1164
+ * `[panelMode]` Input still wins. The panel `<div>` always stays in the
1165
+ * DOM regardless of mode (the `aria-controls` target).
1166
+ *
1167
+ * @category common/tabs
1168
+ */
1169
+ function withTabsPanelMode(mode) {
1170
+ return defineTabsConfigFeature((cfg) => ({ ...cfg, panelMode: mode }));
1171
+ }
1172
+ /**
1173
+ * Set the app-wide default for stretching tabs to the full strip width
1174
+ * (horizontal only). Default `false`. Per-instance `[fitted]` Input still
1175
+ * wins. No effect under `orientation="vertical"`.
1176
+ *
1177
+ * @category common/tabs
1178
+ */
1179
+ function withTabsFitted(fitted) {
1180
+ return defineTabsConfigFeature((cfg) => ({ ...cfg, fitted }));
1181
+ }
1182
+ /**
1183
+ * Set the app-wide default tab-cluster alignment (horizontal only).
1184
+ * Default `'start'`. Per-instance `[tabAlign]` Input still wins. Ignored
1185
+ * under `orientation="vertical"` and when the group is `fitted`.
1186
+ *
1187
+ * @category common/tabs
1188
+ */
1189
+ function withTabsAlign(align) {
1190
+ return defineTabsConfigFeature((cfg) => ({ ...cfg, tabAlign: align }));
1191
+ }
1192
+ /**
1193
+ * Set the app-wide default for whether tabs render a close affordance.
1194
+ * Default `false`. Per-instance `[closable]` Input wins; a per-`CngxTab`
1195
+ * `[closable]` override wins over both.
1196
+ *
1197
+ * @category common/tabs
1198
+ */
1199
+ function withTabsClosable(closable) {
1200
+ return defineTabsConfigFeature((cfg) => ({ ...cfg, closable }));
1201
+ }
1202
+ /**
1203
+ * Set the app-wide default for whether the group renders an add-tab
1204
+ * button. Default `false`. Per-instance `[addable]` Input wins.
1205
+ *
1206
+ * @category common/tabs
1207
+ */
1208
+ function withTabsAddable(addable) {
1209
+ return defineTabsConfigFeature((cfg) => ({ ...cfg, addable }));
1210
+ }
644
1211
  /**
645
1212
  * Merge ARIA labels into the cascade. Keys not provided keep their
646
1213
  * library defaults; per-instance overrides on the tab group still win.
1214
+ *
1215
+ * @category common/tabs
647
1216
  */
648
1217
  function withTabsAriaLabels(labels) {
649
1218
  return defineTabsConfigFeature((cfg) => ({
@@ -654,6 +1223,8 @@ function withTabsAriaLabels(labels) {
654
1223
  /**
655
1224
  * Merge text fallback labels (overflow trigger, busy / rejection text)
656
1225
  * into the cascade. Used when a slot directive is not present.
1226
+ *
1227
+ * @category common/tabs
657
1228
  */
658
1229
  function withTabsFallbackLabels(labels) {
659
1230
  return defineTabsConfigFeature((cfg) => ({
@@ -664,6 +1235,8 @@ function withTabsFallbackLabels(labels) {
664
1235
  /**
665
1236
  * Override the IO-debounce window (ms). See
666
1237
  * {@link CngxTabsConfig.overflowStabilizeMs}.
1238
+ *
1239
+ * @category common/tabs
667
1240
  */
668
1241
  function withTabOverflowStabilizeMs(ms) {
669
1242
  return defineTabsConfigFeature((cfg) => ({
@@ -674,6 +1247,8 @@ function withTabOverflowStabilizeMs(ms) {
674
1247
  /**
675
1248
  * Override the worst-case staleness ceiling on the visibility-map
676
1249
  * commit. See {@link CngxTabsConfig.overflowMaxDeferMs}.
1250
+ *
1251
+ * @category common/tabs
677
1252
  */
678
1253
  function withTabOverflowMaxDeferMs(ms) {
679
1254
  return defineTabsConfigFeature((cfg) => ({
@@ -691,6 +1266,8 @@ function withTabOverflowMaxDeferMs(ms) {
691
1266
  *
692
1267
  * providers: [provideTabsConfig(withTabOverflowTriggerTemplate(this.moreTrigger))]
693
1268
  * ```
1269
+ *
1270
+ * @category common/tabs
694
1271
  */
695
1272
  function withTabOverflowTriggerTemplate(template) {
696
1273
  return defineTabsConfigFeature((cfg) => ({
@@ -701,6 +1278,8 @@ function withTabOverflowTriggerTemplate(template) {
701
1278
  /**
702
1279
  * App-wide override for each row inside the overflow popover.
703
1280
  * Middle tier; per-instance `*cngxTabOverflowItem` still wins.
1281
+ *
1282
+ * @category common/tabs
704
1283
  */
705
1284
  function withTabOverflowItemTemplate(template) {
706
1285
  return defineTabsConfigFeature((cfg) => ({
@@ -712,6 +1291,8 @@ function withTabOverflowItemTemplate(template) {
712
1291
  * App-wide override for the error-badge decoration. Middle tier;
713
1292
  * per-instance `*cngxTabErrorBadge` still wins. Sibling of the
714
1293
  * stepper family's `withStepBadgeTemplate`.
1294
+ *
1295
+ * @category common/tabs
715
1296
  */
716
1297
  function withTabErrorBadgeTemplate(template) {
717
1298
  return defineTabsConfigFeature((cfg) => ({
@@ -723,6 +1304,8 @@ function withTabErrorBadgeTemplate(template) {
723
1304
  * App-wide override for the rejection-icon decoration. Middle
724
1305
  * tier; per-instance `*cngxTabRejectionIcon` still wins. Sibling
725
1306
  * of {@link withStepRejectionTemplate}.
1307
+ *
1308
+ * @category common/tabs
726
1309
  */
727
1310
  function withTabRejectionIconTemplate(template) {
728
1311
  return defineTabsConfigFeature((cfg) => ({
@@ -734,6 +1317,8 @@ function withTabRejectionIconTemplate(template) {
734
1317
  * App-wide override for the commit-pending busy-spinner overlay.
735
1318
  * Middle tier; per-instance `*cngxTabBusySpinner` still wins.
736
1319
  * Sibling of {@link withStepBusySpinnerTemplate}.
1320
+ *
1321
+ * @category common/tabs
737
1322
  */
738
1323
  function withTabBusySpinnerTemplate(template) {
739
1324
  return defineTabsConfigFeature((cfg) => ({
@@ -741,6 +1326,43 @@ function withTabBusySpinnerTemplate(template) {
741
1326
  templates: { ...cfg.templates, busySpinner: template },
742
1327
  }));
743
1328
  }
1329
+ /**
1330
+ * App-wide override for the tab-icon slot. Middle tier of the 3-stage
1331
+ * cascade; per-instance `*cngxTabIcon` still wins. Sibling of
1332
+ * {@link withStepIndicatorTemplate}.
1333
+ *
1334
+ * @category common/tabs
1335
+ */
1336
+ function withTabIconTemplate(template) {
1337
+ return defineTabsConfigFeature((cfg) => ({
1338
+ ...cfg,
1339
+ templates: { ...cfg.templates, icon: template },
1340
+ }));
1341
+ }
1342
+ /**
1343
+ * App-wide override for a tab's close-button glyph. Middle tier;
1344
+ * per-instance `*cngxTabCloseIcon` still wins.
1345
+ *
1346
+ * @category common/tabs
1347
+ */
1348
+ function withTabCloseIconTemplate(template) {
1349
+ return defineTabsConfigFeature((cfg) => ({
1350
+ ...cfg,
1351
+ templates: { ...cfg.templates, closeIcon: template },
1352
+ }));
1353
+ }
1354
+ /**
1355
+ * App-wide override for the add-tab button glyph. Middle tier;
1356
+ * per-instance `*cngxTabAddIcon` still wins.
1357
+ *
1358
+ * @category common/tabs
1359
+ */
1360
+ function withTabAddIconTemplate(template) {
1361
+ return defineTabsConfigFeature((cfg) => ({
1362
+ ...cfg,
1363
+ templates: { ...cfg.templates, addIcon: template },
1364
+ }));
1365
+ }
744
1366
  function resolveFeatures(features) {
745
1367
  return features.reduce((cfg, feat) => feat(cfg), TABS_CONFIG_DEFAULTS);
746
1368
  }
@@ -748,6 +1370,8 @@ function resolveFeatures(features) {
748
1370
  * Root-level provider. Apply once in `bootstrapApplication` /
749
1371
  * `appConfig.providers`. Returns {@link EnvironmentProviders} per
750
1372
  * the canonical cngx config-cascade signature.
1373
+ *
1374
+ * @category common/tabs
751
1375
  */
752
1376
  function provideTabsConfig(...features) {
753
1377
  return makeEnvironmentProviders([
@@ -765,24 +1389,55 @@ function provideTabsConfig(...features) {
765
1389
  * viewProviders: [...provideTabsConfigAt(withTabsDefaultOrientation('vertical'))],
766
1390
  * })
767
1391
  * ```
1392
+ *
1393
+ * @category common/tabs
768
1394
  */
769
1395
  function provideTabsConfigAt(...features) {
770
1396
  return [{ provide: CNGX_TABS_CONFIG, useValue: resolveFeatures(features) }];
771
1397
  }
772
1398
  /**
773
1399
  * Inject the resolved tabs config in an injection context.
1400
+ *
1401
+ * @category common/tabs
774
1402
  */
775
1403
  function injectTabsConfig() {
776
1404
  return inject(CNGX_TABS_CONFIG);
777
1405
  }
778
1406
 
1407
+ /**
1408
+ * Level-2 helper resolving the host-attribute cascades for
1409
+ * `<cngx-tab-group>` (skin / iconLayout). Keeps the organism class
1410
+ * under the LOC guard while making the cascade pattern reusable. Sibling
1411
+ * shape to `createStepperHostAttrs`; the resolved-type unions differ per
1412
+ * family, so the helpers are siblings, not shared code.
1413
+ *
1414
+ * Each computed honors Pillar 1 (Ableitung statt Verwaltung):
1415
+ * per-instance input wins over root config wins over library default. No
1416
+ * manual sync. The library defaults (`'line'` / `'start'`) live here,
1417
+ * not in `TABS_CONFIG_DEFAULTS` - mirroring the stepper.
1418
+ *
1419
+ * @internal
1420
+ */
1421
+ function createTabsHostAttrs(inputs) {
1422
+ return {
1423
+ resolvedSkin: computed(() => inputs.skin() ?? inputs.config.skin ?? 'line'),
1424
+ resolvedIconLayout: computed(() => inputs.iconLayout() ?? inputs.config.iconLayout ?? 'start'),
1425
+ resolvedPanelMode: computed(() => inputs.panelMode() ?? inputs.config.panelMode ?? 'eager'),
1426
+ resolvedFitted: computed(() => inputs.fitted() ?? inputs.config.fitted ?? false),
1427
+ resolvedTabAlign: computed(() => inputs.tabAlign() ?? inputs.config.tabAlign ?? 'start'),
1428
+ };
1429
+ }
1430
+
779
1431
  const TABS_I18N_DEFAULTS = {
780
1432
  tabsLabel: 'Tabs',
781
1433
  selectedTab: (label, position, count) => `Tab ${position} of ${count}: ${label}`,
1434
+ tabLabelWithDetail: (label, detail) => `${label}, ${detail}`,
782
1435
  tabHasErrors: (count) => `${count} error${count === 1 ? '' : 's'}`,
783
1436
  moreTabsLabel: (count) => `${count} more`,
784
1437
  previousTab: 'Previous tab',
785
1438
  nextTab: 'Next tab',
1439
+ closeTab: (label) => `Close "${label}"`,
1440
+ addTab: 'Add tab',
786
1441
  commitFailedRetry: 'Tab change refused — retry?',
787
1442
  commitInFlight: 'Switching tab…',
788
1443
  commitRolledBackTo: (originLabel) => `Could not save changes — reverted to "${originLabel}".`,
@@ -790,8 +1445,16 @@ const TABS_I18N_DEFAULTS = {
790
1445
  /**
791
1446
  * DI token for the tabs i18n bundle. `providedIn: 'root'` with
792
1447
  * English defaults.
1448
+ *
1449
+ * @category common/tabs/i18n
1450
+ * @wcag AA
1451
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/i18n/tabs-i18n.ts
1452
+ * @since 0.1.0
793
1453
  */
794
- const CNGX_TABS_I18N = new InjectionToken('CngxTabsI18n', { providedIn: 'root', factory: () => TABS_I18N_DEFAULTS });
1454
+ const CNGX_TABS_I18N = new InjectionToken('CngxTabsI18n', {
1455
+ providedIn: 'root',
1456
+ factory: () => TABS_I18N_DEFAULTS,
1457
+ });
795
1458
  /**
796
1459
  * Brands an i18n-mutator with the `_target` discriminator.
797
1460
  *
@@ -801,10 +1464,12 @@ function defineTabsI18nFeature(fn) {
801
1464
  return Object.assign(fn, { _target: 'i18n' });
802
1465
  }
803
1466
  /**
804
- * Override i18n labels via a partial bundle — unset keys keep the
1467
+ * Override i18n labels via a partial bundle - unset keys keep the
805
1468
  * English default. Same shape as `withTabsAriaLabels` /
806
1469
  * `withTabsFallbackLabels` so `provideCngxTabs` composes both
807
1470
  * surfaces uniformly.
1471
+ *
1472
+ * @category common/tabs/i18n
808
1473
  */
809
1474
  function withTabsI18nLabels(overrides) {
810
1475
  return defineTabsI18nFeature((bundle) => ({ ...bundle, ...overrides }));
@@ -826,6 +1491,8 @@ function resolveI18nFeatures(features) {
826
1491
  * ],
827
1492
  * });
828
1493
  * ```
1494
+ *
1495
+ * @category common/tabs/i18n
829
1496
  */
830
1497
  function provideTabsI18n(...features) {
831
1498
  return {
@@ -835,6 +1502,8 @@ function provideTabsI18n(...features) {
835
1502
  }
836
1503
  /**
837
1504
  * Inject the resolved tabs i18n bundle.
1505
+ *
1506
+ * @category common/tabs/i18n
838
1507
  */
839
1508
  function injectTabsI18n() {
840
1509
  return inject(CNGX_TABS_I18N);
@@ -884,6 +1553,8 @@ function partitionFeatures(features) {
884
1553
  * ],
885
1554
  * });
886
1555
  * ```
1556
+ *
1557
+ * @category common/tabs
887
1558
  */
888
1559
  function provideCngxTabs(...features) {
889
1560
  const { config, i18n } = partitionFeatures(features);
@@ -907,6 +1578,8 @@ function provideCngxTabs(...features) {
907
1578
  * ],
908
1579
  * })
909
1580
  * ```
1581
+ *
1582
+ * @category common/tabs
910
1583
  */
911
1584
  function provideCngxTabsAt(...features) {
912
1585
  const { config, i18n } = partitionFeatures(features);
@@ -920,6 +1593,8 @@ function provideCngxTabsAt(...features) {
920
1593
  * Default adapter for the cngx-native `<cngx-tab-group>` strip:
921
1594
  * walks `host.closest('.cngx-tabs__strip-wrapper')` for the IO root,
922
1595
  * then `[id="${handle.id}-header"]` for each button.
1596
+ *
1597
+ * @category common/tabs/overflow
923
1598
  */
924
1599
  function createCngxTabOverflowDefaultDomAdapter() {
925
1600
  return {
@@ -938,6 +1613,10 @@ function createCngxTabOverflowDefaultDomAdapter() {
938
1613
  * swap in a Material, custom-skin, or test-double adapter without
939
1614
  * forking the molecule. Defaults to
940
1615
  * {@link createCngxTabOverflowDefaultDomAdapter}.
1616
+ *
1617
+ * @category common/tabs/overflow
1618
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/overflow/dom-adapter.ts
1619
+ * @since 0.1.0
941
1620
  */
942
1621
  const CNGX_TAB_OVERFLOW_DOM_ADAPTER_FACTORY = new InjectionToken('CngxTabOverflowDomAdapterFactory', {
943
1622
  providedIn: 'root',
@@ -945,7 +1624,7 @@ const CNGX_TAB_OVERFLOW_DOM_ADAPTER_FACTORY = new InjectionToken('CngxTabOverflo
945
1624
  });
946
1625
 
947
1626
  /**
948
- * Bounded retry loop for DOM-anchoring patterns — shared
1627
+ * Bounded retry loop for DOM-anchoring patterns - shared
949
1628
  * attempt-counter + give-up + cancellation contract. Used by
950
1629
  * `<cngx-tab-overflow>`'s rAF strip-attach loop and `[cngxMatTabs]`'s
951
1630
  * `afterNextRender` header-anchor loop. Consumer-supplied scheduler
@@ -969,6 +1648,8 @@ const CNGX_TAB_OVERFLOW_DOM_ADAPTER_FACTORY = new InjectionToken('CngxTabOverflo
969
1648
  * afterNextRender(() => retry.start());
970
1649
  * destroyRef.onDestroy(() => retry.cancel());
971
1650
  * ```
1651
+ *
1652
+ * @category common/tabs/overflow
972
1653
  */
973
1654
  function createDomAnchorRetry(options) {
974
1655
  let attempts = 0;
@@ -985,7 +1666,7 @@ function createDomAnchorRetry(options) {
985
1666
  result = options.attempt();
986
1667
  }
987
1668
  catch {
988
- // Swallow + terminal stop — covers the test-runner teardown
1669
+ // Swallow + terminal stop - covers the test-runner teardown
989
1670
  // race where a global (e.g. IntersectionObserver) is reset
990
1671
  // between schedule and fire, before consumer DestroyRef can
991
1672
  // call cancel(). Production callback bugs still surface via
@@ -1020,7 +1701,7 @@ function createDomAnchorRetry(options) {
1020
1701
  }
1021
1702
  /**
1022
1703
  * DI token for the DOM-anchor retry policy. Default
1023
- * {@link createDomAnchorRetry}. Two real consumers today —
1704
+ * {@link createDomAnchorRetry}. Two real consumers today -
1024
1705
  * `<cngx-tab-overflow>`'s rAF strip-attach loop and
1025
1706
  * `[cngxMatTabs]`'s `afterNextRender` header-anchor loop. Override
1026
1707
  * via `providers` / `viewProviders` for retry-with-backoff,
@@ -1028,6 +1709,10 @@ function createDomAnchorRetry(options) {
1028
1709
  * `CNGX_OVERFLOW_POPOVER_HIGHLIGHT_FACTORY`,
1029
1710
  * `CNGX_TAB_OVERFLOW_DOM_ADAPTER_FACTORY`, and
1030
1711
  * `CNGX_TABS_COMMIT_HANDLER_FACTORY`.
1712
+ *
1713
+ * @category common/tabs/overflow
1714
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/overflow/dom-anchor-retry.ts
1715
+ * @since 0.1.0
1031
1716
  */
1032
1717
  const CNGX_DOM_ANCHOR_RETRY_FACTORY = new InjectionToken('CngxDomAnchorRetryFactory', {
1033
1718
  providedIn: 'root',
@@ -1047,6 +1732,12 @@ const CNGX_DOM_ANCHOR_RETRY_FACTORY = new InjectionToken('CngxDomAnchorRetryFact
1047
1732
  * </ng-template>
1048
1733
  * </cngx-tab-overflow>
1049
1734
  * ```
1735
+ *
1736
+ * @category common/tabs/overflow
1737
+ * @wcag AA
1738
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/overflow/tab-overflow-trigger.directive.ts
1739
+ * @since 0.1.0
1740
+ * @relatedTo CngxTabOverflowItem, CngxTab
1050
1741
  */
1051
1742
  class CngxTabOverflowTrigger {
1052
1743
  templateRef = inject(TemplateRef);
@@ -1077,6 +1768,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
1077
1768
  * </ng-template>
1078
1769
  * </cngx-tab-overflow>
1079
1770
  * ```
1771
+ *
1772
+ * @category common/tabs/overflow
1773
+ * @wcag AA
1774
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/overflow/tab-overflow-item.directive.ts
1775
+ * @since 0.1.0
1776
+ * @relatedTo CngxTabOverflowTrigger, CngxTab
1080
1777
  */
1081
1778
  class CngxTabOverflowItem {
1082
1779
  templateRef = inject(TemplateRef);
@@ -1107,6 +1804,15 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
1107
1804
  * </ng-template>
1108
1805
  * </cngx-tab-group>
1109
1806
  * ```
1807
+ *
1808
+ * @category common/tabs/slots
1809
+ * @wcag AA
1810
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/slots/tab-error-badge.directive.ts
1811
+ * @since 0.1.0
1812
+ * @relatedTo CngxTabRejectionIcon, CngxTabBusySpinner, CngxTab
1813
+ * <example-url>http://localhost:4200/#/ui/tabs/tab-slot-overrides/custom-busy-spinner-via-code-cngxtabbusyspinner-code</example-url>
1814
+ * <example-url>http://localhost:4200/#/ui/tabs/tab-slot-overrides/custom-error-badge-via-code-cngxtaberrorbadge-code</example-url>
1815
+ * <example-url>http://localhost:4200/#/ui/tabs/tab-slot-overrides/rejection-decoration-via-code-cngxtabrejectionicon-code</example-url>
1110
1816
  */
1111
1817
  class CngxTabErrorBadge {
1112
1818
  templateRef = inject(TemplateRef);
@@ -1142,6 +1848,15 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
1142
1848
  * </ng-template>
1143
1849
  * </cngx-tab-group>
1144
1850
  * ```
1851
+ *
1852
+ * @category common/tabs/slots
1853
+ * @wcag AA
1854
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/slots/tab-rejection-icon.directive.ts
1855
+ * @since 0.1.0
1856
+ * @relatedTo CngxTabErrorBadge, CngxTabBusySpinner, CngxTab
1857
+ * <example-url>http://localhost:4200/#/ui/tabs/tab-slot-overrides/custom-busy-spinner-via-code-cngxtabbusyspinner-code</example-url>
1858
+ * <example-url>http://localhost:4200/#/ui/tabs/tab-slot-overrides/custom-error-badge-via-code-cngxtaberrorbadge-code</example-url>
1859
+ * <example-url>http://localhost:4200/#/ui/tabs/tab-slot-overrides/rejection-decoration-via-code-cngxtabrejectionicon-code</example-url>
1145
1860
  */
1146
1861
  class CngxTabRejectionIcon {
1147
1862
  templateRef = inject(TemplateRef);
@@ -1169,6 +1884,15 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
1169
1884
  * </ng-template>
1170
1885
  * </cngx-tab-group>
1171
1886
  * ```
1887
+ *
1888
+ * @category common/tabs/slots
1889
+ * @wcag AA
1890
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/slots/tab-busy-spinner.directive.ts
1891
+ * @since 0.1.0
1892
+ * @relatedTo CngxTabErrorBadge, CngxTabRejectionIcon, CngxTab
1893
+ * <example-url>http://localhost:4200/#/ui/tabs/tab-slot-overrides/custom-busy-spinner-via-code-cngxtabbusyspinner-code</example-url>
1894
+ * <example-url>http://localhost:4200/#/ui/tabs/tab-slot-overrides/custom-error-badge-via-code-cngxtaberrorbadge-code</example-url>
1895
+ * <example-url>http://localhost:4200/#/ui/tabs/tab-slot-overrides/rejection-decoration-via-code-cngxtabrejectionicon-code</example-url>
1172
1896
  */
1173
1897
  class CngxTabBusySpinner {
1174
1898
  templateRef = inject(TemplateRef);
@@ -1185,11 +1909,304 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
1185
1909
  }] });
1186
1910
 
1187
1911
  /**
1188
- * Wires the 3-stage template cascade for the three `<cngx-tab-group>`
1189
- * skin slots:
1912
+ * Structural slot for the tab-icon template. One group-level slot with
1913
+ * per-tab context (stepper-slot parity), not a per-`CngxTab` input.
1914
+ * 3-stage cascade: per-instance directive >
1915
+ * `CNGX_TABS_CONFIG.templates.icon` > none (no icon rendered).
1916
+ *
1917
+ * ```html
1918
+ * <cngx-tab-group iconLayout="start">
1919
+ * <ng-template cngxTabIcon let-tab="tab" let-active="active">
1920
+ * <cngx-icon [name]="active ? 'folder-open' : 'folder'" />
1921
+ * </ng-template>
1922
+ * </cngx-tab-group>
1923
+ * ```
1924
+ *
1925
+ * @category common/tabs/slots
1926
+ * @wcag AA
1927
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/slots/tab-icon.directive.ts
1928
+ * @since 0.1.0
1929
+ * @relatedTo CngxTabErrorBadge, CngxTab, CngxTabGroup
1930
+ */
1931
+ class CngxTabIcon {
1932
+ templateRef = inject(TemplateRef);
1933
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabIcon, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1934
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxTabIcon, isStandalone: true, selector: "ng-template[cngxTabIcon]", exportAs: ["cngxTabIcon"], ngImport: i0 });
1935
+ }
1936
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabIcon, decorators: [{
1937
+ type: Directive,
1938
+ args: [{
1939
+ selector: 'ng-template[cngxTabIcon]',
1940
+ exportAs: 'cngxTabIcon',
1941
+ standalone: true,
1942
+ }]
1943
+ }] });
1944
+
1945
+ /**
1946
+ * Structural slot for a tab's close-button glyph. 3-stage cascade:
1947
+ * per-instance directive > `CNGX_TABS_CONFIG.templates.closeIcon` >
1948
+ * `CNGX_TABS_GLYPHS.closeIcon`.
1949
+ *
1950
+ * ```html
1951
+ * <cngx-tab-group closable (tabClose)="remove($event.id)">
1952
+ * <ng-template cngxTabCloseIcon><cngx-icon name="close" /></ng-template>
1953
+ * ...
1954
+ * </cngx-tab-group>
1955
+ * ```
1956
+ *
1957
+ * @category common/tabs/slots
1958
+ * @wcag AA
1959
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/slots/tab-close-icon.directive.ts
1960
+ * @since 0.1.0
1961
+ * @relatedTo CngxTabAddIcon, CngxTabGroup
1962
+ */
1963
+ class CngxTabCloseIcon {
1964
+ templateRef = inject(TemplateRef);
1965
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabCloseIcon, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1966
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxTabCloseIcon, isStandalone: true, selector: "ng-template[cngxTabCloseIcon]", exportAs: ["cngxTabCloseIcon"], ngImport: i0 });
1967
+ }
1968
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabCloseIcon, decorators: [{
1969
+ type: Directive,
1970
+ args: [{
1971
+ selector: 'ng-template[cngxTabCloseIcon]',
1972
+ exportAs: 'cngxTabCloseIcon',
1973
+ standalone: true,
1974
+ }]
1975
+ }] });
1976
+
1977
+ /**
1978
+ * Structural slot for the add-tab button glyph. 3-stage cascade:
1979
+ * per-instance directive > `CNGX_TABS_CONFIG.templates.addIcon` >
1980
+ * `CNGX_TABS_GLYPHS.addIcon`. The button owns its `aria-label`; the
1981
+ * template paints only the glyph, so its context is `void`.
1982
+ *
1983
+ * ```html
1984
+ * <cngx-tab-group addable (tabAdd)="add()">
1985
+ * <ng-template cngxTabAddIcon><cngx-icon name="plus" /></ng-template>
1986
+ * ...
1987
+ * </cngx-tab-group>
1988
+ * ```
1989
+ *
1990
+ * @category common/tabs/slots
1991
+ * @wcag AA
1992
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/slots/tab-add-icon.directive.ts
1993
+ * @since 0.1.0
1994
+ * @relatedTo CngxTabCloseIcon, CngxTabGroup
1995
+ */
1996
+ class CngxTabAddIcon {
1997
+ templateRef = inject(TemplateRef);
1998
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabAddIcon, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1999
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxTabAddIcon, isStandalone: true, selector: "ng-template[cngxTabAddIcon]", exportAs: ["cngxTabAddIcon"], ngImport: i0 });
2000
+ }
2001
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabAddIcon, decorators: [{
2002
+ type: Directive,
2003
+ args: [{
2004
+ selector: 'ng-template[cngxTabAddIcon]',
2005
+ exportAs: 'cngxTabAddIcon',
2006
+ standalone: true,
2007
+ }]
2008
+ }] });
2009
+
2010
+ /**
2011
+ * Level-2 helper resolving the dismissable/addable affordances for
2012
+ * `<cngx-tab-group>`. Keeps the close/add cascade + interaction off the
2013
+ * organism class (LOC guard). Pillar 1: each cascade is one `computed()`.
2014
+ * The actual tab removal is the consumer's (Ableitung statt Verwaltung) -
2015
+ * `handleClose` only routes through the presenter's `requestClose`, which
2016
+ * moves the active index, and restores focus once the consumer's removal
2017
+ * has rendered.
2018
+ *
2019
+ * @category common/tabs
2020
+ */
2021
+ function createTabDismissals(opts) {
2022
+ const resolvedClosable = computed(() => opts.closable() ?? opts.config.closable ?? false, ...(ngDevMode ? [{ debugName: "resolvedClosable" }] : /* istanbul ignore next */ []));
2023
+ const resolvedAddable = computed(() => opts.addable() ?? opts.config.addable ?? false, ...(ngDevMode ? [{ debugName: "resolvedAddable" }] : /* istanbul ignore next */ []));
2024
+ const closeIconContextCache = new WeakMap();
2025
+ const isTabClosable = (tab) => tab.closable() ?? resolvedClosable();
2026
+ const handleClose = (tab, event) => {
2027
+ event?.stopPropagation();
2028
+ if (!isTabClosable(tab)) {
2029
+ return;
2030
+ }
2031
+ opts.host.requestClose(tab.id);
2032
+ // Restore focus once the consumer's removal has rendered: the new
2033
+ // active tab, then the add button, and finally the group element
2034
+ // itself (made programmatically focusable) so focus never falls to
2035
+ // `<body>` when the strip empties with no add button (APG).
2036
+ afterNextRender(() => {
2037
+ const active = opts.hostElement.querySelector('.cngx-tabs__tab[aria-selected="true"]');
2038
+ const add = opts.hostElement.querySelector('.cngx-tabs__add');
2039
+ const target = active ?? add;
2040
+ if (target) {
2041
+ target.focus();
2042
+ return;
2043
+ }
2044
+ opts.hostElement.tabIndex = -1;
2045
+ opts.hostElement.focus();
2046
+ }, { injector: opts.injector });
2047
+ };
2048
+ return {
2049
+ resolvedClosable,
2050
+ resolvedAddable,
2051
+ isTabClosable,
2052
+ closeButtonLabel: (tab) => opts.i18n.closeTab(tab.label() ?? ''),
2053
+ closeIconContextFor: (tab) => {
2054
+ let ctx = closeIconContextCache.get(tab);
2055
+ if (!ctx) {
2056
+ ctx = { tab };
2057
+ closeIconContextCache.set(tab, ctx);
2058
+ }
2059
+ return ctx;
2060
+ },
2061
+ handleClose,
2062
+ handleTabKeydown: (tab, event) => {
2063
+ if (event.key === 'Delete' && isTabClosable(tab)) {
2064
+ event.preventDefault();
2065
+ handleClose(tab);
2066
+ }
2067
+ },
2068
+ handleAdd: () => opts.host.requestAdd(),
2069
+ };
2070
+ }
2071
+
2072
+ /**
2073
+ * Level-2 helper implementing the WAI-ARIA APG tabs keyboard model for
2074
+ * `<cngx-tab-group>` with **automatic activation**: an arrow press moves
2075
+ * focus AND activates the target tab in one step, so focus and selection
2076
+ * never diverge. Keeps the keyboard logic off the organism class (LOC
2077
+ * guard) and out of a competing roving-tabindex state machine.
2078
+ *
2079
+ * Pillar 1 (Ableitung statt Verwaltung): the tab stop is derived from the
2080
+ * presenter's `activeId`, not managed as a second index. Pillar 2
2081
+ * (Kommunikation): activation routes through `host.select()`, which owns
2082
+ * disabled-skip, loop, commit gating, and the live-region announcement -
2083
+ * the keyboard layer adds only focus movement (a DOM concern the
2084
+ * presenter, living in `@cngx/common`, must not own).
2085
+ *
2086
+ * Navigation always originates from the active tab: under automatic
2087
+ * activation the focused tab is always the active one, so the clamped
2088
+ * active index is the correct origin.
2089
+ *
2090
+ * @category common/tabs
2091
+ */
2092
+ function createTabKeyboardNav(opts) {
2093
+ const clampedActive = () => {
2094
+ const len = opts.host.tabs().length;
2095
+ if (len === 0) {
2096
+ return 0;
2097
+ }
2098
+ return Math.max(0, Math.min(opts.host.activeIndex(), len - 1));
2099
+ };
2100
+ // Next enabled index in `direction`, honouring `loop`. Mirrors the
2101
+ // presenter's `selectNext`/`selectPrevious` geometry but returns the
2102
+ // resolved index so the caller can both activate and focus it.
2103
+ const step = (direction) => {
2104
+ const tabs = opts.host.tabs();
2105
+ const len = tabs.length;
2106
+ if (len === 0) {
2107
+ return null;
2108
+ }
2109
+ const loop = opts.host.loop();
2110
+ let idx = clampedActive() + direction;
2111
+ for (let i = 0; i < len; i++) {
2112
+ if (loop) {
2113
+ idx = ((idx % len) + len) % len;
2114
+ }
2115
+ else if (idx < 0 || idx >= len) {
2116
+ return null;
2117
+ }
2118
+ if (!tabs[idx].disabled()) {
2119
+ return idx;
2120
+ }
2121
+ idx += direction;
2122
+ }
2123
+ return null;
2124
+ };
2125
+ // First (direction 1) or last (direction -1) enabled tab, for Home/End.
2126
+ const edge = (direction) => {
2127
+ const tabs = opts.host.tabs();
2128
+ const len = tabs.length;
2129
+ if (direction === 1) {
2130
+ for (let i = 0; i < len; i++) {
2131
+ if (!tabs[i].disabled()) {
2132
+ return i;
2133
+ }
2134
+ }
2135
+ }
2136
+ else {
2137
+ for (let i = len - 1; i >= 0; i--) {
2138
+ if (!tabs[i].disabled()) {
2139
+ return i;
2140
+ }
2141
+ }
2142
+ }
2143
+ return null;
2144
+ };
2145
+ // Focus the tab button for the tab at `index`, keyed off the stable
2146
+ // tab id (the rendered `data-tab-id`) rather than a positional
2147
+ // `.cngx-tabs__tab[index]` lookup - so a skin that reorders or wraps
2148
+ // the tab buttons can't misdirect keyboard focus. `[role="tab"]` is
2149
+ // the APG contract every skin must honour, so it survives a class
2150
+ // rename too. The button already exists regardless of pending CD, so
2151
+ // focus is immediate and never waits on the activation's render.
2152
+ const focusTabAt = (index) => {
2153
+ const id = opts.host.tabs()[index]?.id;
2154
+ if (id == null) {
2155
+ return;
2156
+ }
2157
+ const buttons = Array.from(opts.hostElement.querySelectorAll('[role="tab"]'));
2158
+ buttons.find((button) => button.getAttribute('data-tab-id') === id)?.focus();
2159
+ };
2160
+ return {
2161
+ tabTabindex: (tab) => (tab.id === opts.host.activeId() ? 0 : -1),
2162
+ handleKeydown: (event) => {
2163
+ const horizontal = opts.host.orientation() === 'horizontal';
2164
+ let target;
2165
+ switch (event.key) {
2166
+ case 'ArrowRight':
2167
+ target = horizontal ? step(1) : null;
2168
+ break;
2169
+ case 'ArrowLeft':
2170
+ target = horizontal ? step(-1) : null;
2171
+ break;
2172
+ case 'ArrowDown':
2173
+ target = horizontal ? null : step(1);
2174
+ break;
2175
+ case 'ArrowUp':
2176
+ target = horizontal ? null : step(-1);
2177
+ break;
2178
+ case 'Home':
2179
+ target = edge(1);
2180
+ break;
2181
+ case 'End':
2182
+ target = edge(-1);
2183
+ break;
2184
+ default:
2185
+ return;
2186
+ }
2187
+ if (target === null) {
2188
+ return;
2189
+ }
2190
+ event.preventDefault();
2191
+ // Automatic activation: select first (content + aria-selected +
2192
+ // announcement follow), then move focus to the same tab button.
2193
+ opts.host.select(target);
2194
+ focusTabAt(target);
2195
+ },
2196
+ };
2197
+ }
2198
+
2199
+ /**
2200
+ * Wires the 3-stage template cascade for the `<cngx-tab-group>` skin
2201
+ * slots (errorBadge / rejectionIcon / busySpinner / icon / closeIcon /
2202
+ * addIcon):
1190
2203
  * per-instance directive >
1191
2204
  * `CNGX_TABS_CONFIG.templates.<key>` >
1192
- * `null` (built-in default).
2205
+ * `null`.
2206
+ *
2207
+ * `null` means the organism renders its built-in default - a default
2208
+ * span for the state decorations, the `CNGX_TABS_GLYPHS` glyph for
2209
+ * `closeIcon` / `addIcon`, and nothing for `icon`.
1193
2210
  *
1194
2211
  * Pure — no DI, no side effects. Safe in field-init. Sibling to
1195
2212
  * `createStepperTemplateBindings` and `createTabOverflowTemplateBindings`.
@@ -1197,6 +2214,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
1197
2214
  * Single-consumer today: `[cngxMatTabs]` does not consume this —
1198
2215
  * Material owns the rendered tab-button chrome via its own MDC
1199
2216
  * template, leaving no DOM seam. See `tabs-accepted-debt §9`.
2217
+ *
2218
+ * @category common/tabs/slots
1200
2219
  */
1201
2220
  function createTabGroupTemplateBindings(opts) {
1202
2221
  return {
@@ -1209,19 +2228,25 @@ function createTabGroupTemplateBindings(opts) {
1209
2228
  busySpinner: computed(() => opts.busySpinnerSlot()?.templateRef ??
1210
2229
  opts.config.templates?.busySpinner ??
1211
2230
  null),
2231
+ icon: computed(() => opts.iconSlot()?.templateRef ?? opts.config.templates?.icon ?? null),
2232
+ closeIcon: computed(() => opts.closeIconSlot?.()?.templateRef ??
2233
+ opts.config.templates?.closeIcon ??
2234
+ null),
2235
+ addIcon: computed(() => opts.addIconSlot?.()?.templateRef ?? opts.config.templates?.addIcon ?? null),
1212
2236
  };
1213
2237
  }
1214
2238
 
1215
2239
  // Single-consumer factory — staged under family-uniformity
1216
- // (tabs-accepted-debt §9, alongside `createTabGroupTemplateBindings`
1217
- // and `CngxMatTabAggregatorContent`). Re-Eval: second consumer OR
1218
- // sibling debt closure.
2240
+ // (`createTabGroupTemplateBindings` and `CngxMatTabAggregatorContent`).
2241
+ // Re-eval on second consumer or sibling debt closure.
1219
2242
  /**
1220
2243
  * Pure factory bundling the `<cngx-tab-group>` AT-announcement +
1221
2244
  * descriptor surfaces. Owns one internal `linkedSignal`
1222
2245
  * (prior-active-index, drives the success-arm direction prefix) —
1223
2246
  * lazy by `linkedSignal` semantics, so the organism reads
1224
2247
  * `liveAnnouncement` once at construction to seed it.
2248
+ *
2249
+ * @category common/tabs/announcements
1225
2250
  */
1226
2251
  function createTabGroupAnnouncements(options) {
1227
2252
  const { presenter, i18n, config, ariaLabel, ariaLabelledBy } = options;
@@ -1233,9 +2258,9 @@ function createTabGroupAnnouncements(options) {
1233
2258
  }
1234
2259
  return ariaLabel() ?? config.ariaLabels?.tabsRegion ?? i18n.tabsLabel;
1235
2260
  }, ...(ngDevMode ? [{ debugName: "resolvedAriaLabel" }] : /* istanbul ignore next */ []));
1236
- // `prev?.source` gives the source value before the most recent
1237
- // change — prior activeIndex without an `effect`-driven slot
1238
- // (Pillar 1). Coalesce to current on first emission.
2261
+ // `prev?.source` = source value before the most recent change —
2262
+ // prior activeIndex without an `effect`-driven slot (Pillar 1).
2263
+ // Coalesce to current on first emission.
1239
2264
  const priorActiveIndex = linkedSignal({ ...(ngDevMode ? { debugName: "priorActiveIndex" } : /* istanbul ignore next */ {}), source: () => presenter.activeIndex(),
1240
2265
  computation: (curr, prev) => prev?.source ?? curr,
1241
2266
  equal: Object.is });
@@ -1280,19 +2305,26 @@ function createTabGroupAnnouncements(options) {
1280
2305
  return '';
1281
2306
  }, ...(ngDevMode ? [{ debugName: "liveAnnouncement" }] : /* istanbul ignore next */ []));
1282
2307
  function statusPhrase(tab) {
1283
- const aggregator = tab.errorAggregator();
1284
- if (!aggregator?.shouldShow()) {
2308
+ if (!tab.hasError()) {
1285
2309
  return '';
1286
2310
  }
1287
- const announcement = aggregator.announcement();
2311
+ const aggregator = tab.errorAggregator();
2312
+ const announcement = aggregator?.announcement();
1288
2313
  if (announcement) {
1289
2314
  return announcement;
1290
2315
  }
1291
- return i18n.tabHasErrors(aggregator.errorCount());
2316
+ const directMessage = tab.errorMessage();
2317
+ if (directMessage) {
2318
+ return directMessage;
2319
+ }
2320
+ return i18n.tabHasErrors(aggregator?.errorCount() ?? 1);
1292
2321
  }
1293
2322
  function tabAriaLabel(tab, position) {
1294
2323
  const tabs = presenter.tabs();
1295
- return i18n.selectedTab(tab.label() ?? '', position, tabs.length);
2324
+ const label = tab.label() ?? '';
2325
+ const detail = tab.subLabel();
2326
+ const labelPart = detail ? i18n.tabLabelWithDetail(label, detail) : label;
2327
+ return i18n.selectedTab(labelPart, position, tabs.length);
1296
2328
  }
1297
2329
  // Eager seed — `linkedSignal` is lazy and the success arm doesn't
1298
2330
  // touch the tracker at construction (commitTransition is `idle`),
@@ -1319,12 +2351,17 @@ function createTabGroupAnnouncements(options) {
1319
2351
  * directives or `withTab*Template` config features.
1320
2352
  *
1321
2353
  * @internal
2354
+ * @category common/tabs
1322
2355
  */
1323
2356
  const CNGX_TABS_GLYPHS = {
1324
2357
  /** Default visual for `*cngxTabErrorBadge` when no override is bound. */
1325
2358
  errorBadge: '!',
1326
2359
  /** Default visual for `*cngxTabRejectionIcon` when no override is bound. */
1327
2360
  rejectionIcon: '!',
2361
+ /** Default visual for a tab's close button when no override is bound. */
2362
+ closeIcon: '×',
2363
+ /** Default visual for the add-tab button when no override is bound. */
2364
+ addIcon: '+',
1328
2365
  };
1329
2366
 
1330
2367
  /**
@@ -1332,24 +2369,30 @@ const CNGX_TABS_GLYPHS = {
1332
2369
  * Stable across CD passes so `aria-activedescendant` resolves to
1333
2370
  * the same `<li>`. `-overflow-option` suffix avoids collision with
1334
2371
  * the strip-button (`-header`) and per-tab descriptor (`-desc`).
2372
+ *
2373
+ * @category common/tabs/overflow
1335
2374
  */
1336
2375
  function tabOverflowOptionId(tab) {
1337
2376
  return `${tab.id}-overflow-option`;
1338
2377
  }
1339
2378
  /**
1340
- * Structural equal — same `count` + same `hiddenTabs` reference.
2379
+ * Structural equal - same `count` + same `hiddenTabs` reference.
1341
2380
  * The upstream `hiddenTabs` signal already uses `tabIdListEqual`,
1342
2381
  * so this guard stops `ngTemplateOutlet` rebinding on shape-stable
1343
2382
  * IO emissions.
2383
+ *
2384
+ * @internal
1344
2385
  */
1345
2386
  function triggerContextEqual(a, b) {
1346
2387
  return a.count === b.count && a.hiddenTabs === b.hiddenTabs;
1347
2388
  }
1348
2389
  /**
1349
- * Structural equal — same length + per-index `id` and `disabled`.
2390
+ * Structural equal - same length + per-index `id` and `disabled`.
1350
2391
  * Without this, every IO emission yields fresh
1351
2392
  * `ActiveDescendantItem[]` references and AD's `resolvedItems`
1352
2393
  * cascade fires for an unchanged visible-tab set.
2394
+ *
2395
+ * @internal
1353
2396
  */
1354
2397
  function adItemsEqual(a, b) {
1355
2398
  if (a === b) {
@@ -1371,17 +2414,15 @@ function adItemsEqual(a, b) {
1371
2414
  * `CNGX_TABS_CONFIG.templates.overflow*` > built-in markup
1372
2415
  * (template-outlet returns `null`).
1373
2416
  *
1374
- * Pure — no DI, no side effects, no destroy hooks. Safe to call
2417
+ * Pure - no DI, no side effects, no destroy hooks. Safe to call
1375
2418
  * from a component's field-init block. Mirrors the select-family
1376
2419
  * `createTemplateRegistry` pattern.
2420
+ *
2421
+ * @category common/tabs/overflow
1377
2422
  */
1378
2423
  function createTabOverflowTemplateBindings(opts) {
1379
- const triggerTemplate = computed(() => opts.triggerSlot()?.templateRef ??
1380
- opts.config.templates?.overflowTrigger ??
1381
- null, ...(ngDevMode ? [{ debugName: "triggerTemplate" }] : /* istanbul ignore next */ []));
1382
- const itemTemplate = computed(() => opts.itemSlot()?.templateRef ??
1383
- opts.config.templates?.overflowItem ??
1384
- null, ...(ngDevMode ? [{ debugName: "itemTemplate" }] : /* istanbul ignore next */ []));
2424
+ const triggerTemplate = computed(() => opts.triggerSlot()?.templateRef ?? opts.config.templates?.overflowTrigger ?? null, ...(ngDevMode ? [{ debugName: "triggerTemplate" }] : /* istanbul ignore next */ []));
2425
+ const itemTemplate = computed(() => opts.itemSlot()?.templateRef ?? opts.config.templates?.overflowItem ?? null, ...(ngDevMode ? [{ debugName: "itemTemplate" }] : /* istanbul ignore next */ []));
1385
2426
  const triggerContext = computed(() => {
1386
2427
  const count = opts.hiddenCount();
1387
2428
  const hiddenTabs = opts.hiddenTabs();
@@ -1421,12 +2462,14 @@ function createTabOverflowTemplateBindings(opts) {
1421
2462
  /**
1422
2463
  * Resets the AD highlight on popover close. Keyboard-open paths
1423
2464
  * (ArrowDown / End / typeahead on the closed trigger) set
1424
- * `activeIndex` via AD's own keydown listener before opening —
2465
+ * `activeIndex` via AD's own keydown listener before opening -
1425
2466
  * unaffected. Mouse-open leaves `activeIndex === -1` so the popover
1426
2467
  * renders unhighlighted. Without this reset, the next open would
1427
2468
  * inherit a stale index from the prior keyboard session.
1428
2469
  *
1429
2470
  * Must run in injection context.
2471
+ *
2472
+ * @category common/tabs/overflow
1430
2473
  */
1431
2474
  function createOverflowPopoverHighlightSync(popover, ad) {
1432
2475
  effect(() => {
@@ -1445,6 +2488,10 @@ function createOverflowPopoverHighlightSync(popover, ad) {
1445
2488
  * telemetry on close, custom highlight rules. Symmetric to
1446
2489
  * `CNGX_TAB_OVERFLOW_DOM_ADAPTER_FACTORY` and
1447
2490
  * `CNGX_TABS_COMMIT_HANDLER_FACTORY`.
2491
+ *
2492
+ * @category common/tabs/overflow
2493
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/overflow/overflow-template-cascade.ts
2494
+ * @since 0.1.0
1448
2495
  */
1449
2496
  const CNGX_OVERFLOW_POPOVER_HIGHLIGHT_FACTORY = new InjectionToken('CngxOverflowPopoverHighlightSyncFactory', {
1450
2497
  providedIn: 'root',
@@ -1462,7 +2509,9 @@ const DEFAULT_SCROLL_OPTIONS = {
1462
2509
  * scrolls the matching `[id="<itemId>-header"]` into view.
1463
2510
  *
1464
2511
  * The DOM call sits in `untracked()` (only `activeId` is tracked).
1465
- * `scrollIntoView` is missing in jsdom — guarded with optional chain.
2512
+ * `scrollIntoView` is missing in jsdom - guarded with optional chain.
2513
+ *
2514
+ * @category common/tabs/scroll-sync
1466
2515
  */
1467
2516
  function createOrganismScrollSync(opts) {
1468
2517
  const { activeId, hostElement, scrollOptions, injector } = opts;
@@ -1486,6 +2535,10 @@ function createOrganismScrollSync(opts) {
1486
2535
  * custom selector, telemetry, or `prefers-reduced-motion` opt-out.
1487
2536
  * Sibling to `CNGX_DOM_ANCHOR_RETRY_FACTORY` and
1488
2537
  * `CNGX_OVERFLOW_POPOVER_HIGHLIGHT_FACTORY`.
2538
+ *
2539
+ * @category common/tabs/scroll-sync
2540
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/scroll-sync/organism-scroll-sync.ts
2541
+ * @since 0.1.0
1489
2542
  */
1490
2543
  const CNGX_ORGANISM_SCROLL_SYNC_FACTORY = new InjectionToken('CngxOrganismScrollSyncFactory', {
1491
2544
  providedIn: 'root',
@@ -1517,6 +2570,8 @@ function directiveMapEqual(a, b) {
1517
2570
  * directives keyed by `id()`. Structural equal prevents cascade when
1518
2571
  * `contentChildren` re-emits an unchanged child set. Shared by
1519
2572
  * `<cngx-tab-group>`, `<cngx-stepper>`, and `<cngx-mat-stepper>`.
2573
+ *
2574
+ * @category common/tabs/registry
1520
2575
  */
1521
2576
  function createDirectiveByIdMap(opts) {
1522
2577
  return computed(() => {
@@ -1533,6 +2588,10 @@ function createDirectiveByIdMap(opts) {
1533
2588
  * telemetry, or custom equality. Sibling to
1534
2589
  * `CNGX_DOM_ANCHOR_RETRY_FACTORY` and
1535
2590
  * `CNGX_ORGANISM_SCROLL_SYNC_FACTORY`.
2591
+ *
2592
+ * @category common/tabs/registry
2593
+ * @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/registry/directive-by-id-map.ts
2594
+ * @since 0.1.0
1536
2595
  */
1537
2596
  const CNGX_DIRECTIVE_BY_ID_MAP_FACTORY = new InjectionToken('CngxDirectiveByIdMapFactory', {
1538
2597
  providedIn: 'root',
@@ -1547,5 +2606,5 @@ const CNGX_DIRECTIVE_BY_ID_MAP_FACTORY = new InjectionToken('CngxDirectiveByIdMa
1547
2606
  * Generated bundle index. Do not edit.
1548
2607
  */
1549
2608
 
1550
- export { CNGX_DIRECTIVE_BY_ID_MAP_FACTORY, CNGX_DOM_ANCHOR_RETRY_FACTORY, CNGX_ORGANISM_SCROLL_SYNC_FACTORY, CNGX_OVERFLOW_POPOVER_HIGHLIGHT_FACTORY, CNGX_TABS_COMMIT_HANDLER_FACTORY, CNGX_TABS_CONFIG, CNGX_TABS_GLYPHS, CNGX_TABS_I18N, CNGX_TAB_GROUP_HOST, CNGX_TAB_OVERFLOW_DOM_ADAPTER_FACTORY, CNGX_TAB_PANEL_HOST, CngxTab, CngxTabBusySpinner, CngxTabContent, CngxTabErrorBadge, CngxTabGroupPresenter, CngxTabLabel, CngxTabOverflowItem, CngxTabOverflowTrigger, CngxTabRejectionIcon, CngxTabsFragmentSync, createCngxTabOverflowDefaultDomAdapter, createDirectiveByIdMap, createDomAnchorRetry, createOrganismScrollSync, createOverflowPopoverHighlightSync, createTabGroupAnnouncements, createTabGroupTemplateBindings, createTabOverflowTemplateBindings, createTabsCommitHandler, injectTabsConfig, injectTabsI18n, provideCngxTabs, provideCngxTabsAt, provideTabsConfig, provideTabsConfigAt, provideTabsI18n, tabOverflowOptionId, withDefaultOrientation, withTabBusySpinnerTemplate, withTabErrorBadgeTemplate, withTabOverflowItemTemplate, withTabOverflowMaxDeferMs, withTabOverflowStabilizeMs, withTabOverflowTriggerTemplate, withTabRejectionIconTemplate, withTabsAriaLabels, withTabsCommitMode, withTabsDefaultOrientation, withTabsFallbackLabels, withTabsI18nLabels, withTabsRouterSync, withTabsRovingLoop };
2609
+ export { CNGX_DIRECTIVE_BY_ID_MAP_FACTORY, CNGX_DOM_ANCHOR_RETRY_FACTORY, CNGX_ORGANISM_SCROLL_SYNC_FACTORY, CNGX_OVERFLOW_POPOVER_HIGHLIGHT_FACTORY, CNGX_TABS_COMMIT_ACTION, CNGX_TABS_COMMIT_HANDLER_FACTORY, CNGX_TABS_CONFIG, CNGX_TABS_GLYPHS, CNGX_TABS_I18N, CNGX_TAB_GROUP_HOST, CNGX_TAB_OVERFLOW_DOM_ADAPTER_FACTORY, CNGX_TAB_PANEL_HOST, CngxTab, CngxTabAddIcon, CngxTabBusySpinner, CngxTabCloseIcon, CngxTabContent, CngxTabErrorBadge, CngxTabGroupPresenter, CngxTabIcon, CngxTabLabel, CngxTabOverflowItem, CngxTabOverflowTrigger, CngxTabRejectionIcon, CngxTabSubLabel, CngxTabsFragmentSync, CngxTabsRouteSync, createCngxTabOverflowDefaultDomAdapter, createDirectiveByIdMap, createDomAnchorRetry, createOrganismScrollSync, createOverflowPopoverHighlightSync, createTabDismissals, createTabGroupAnnouncements, createTabGroupTemplateBindings, createTabKeyboardNav, createTabOverflowTemplateBindings, createTabRouterCommit, createTabsCommitHandler, createTabsHostAttrs, injectTabsConfig, injectTabsI18n, provideCngxTabs, provideCngxTabsAt, provideTabsConfig, provideTabsConfigAt, provideTabsI18n, tabOverflowOptionId, withDefaultOrientation, withTabAddIconTemplate, withTabBusySpinnerTemplate, withTabCloseIconTemplate, withTabErrorBadgeTemplate, withTabIconTemplate, withTabOverflowItemTemplate, withTabOverflowMaxDeferMs, withTabOverflowStabilizeMs, withTabOverflowTriggerTemplate, withTabRejectionIconTemplate, withTabsAddable, withTabsAlign, withTabsAriaLabels, withTabsClosable, withTabsCommitMode, withTabsDefaultOrientation, withTabsFallbackLabels, withTabsFitted, withTabsFragmentSync, withTabsI18nLabels, withTabsIconLayout, withTabsPanelMode, withTabsRouterSync, withTabsRovingLoop, withTabsSkin };
1551
2610
  //# sourceMappingURL=cngx-common-tabs.mjs.map