@cngx/common 0.1.0-rc.7 → 0.1.0-rc.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/card/README.md +2 -1
- package/data/README.md +10 -1
- package/dialog/README.md +23 -1
- package/fesm2022/cngx-common-a11y.mjs +125 -111
- package/fesm2022/cngx-common-a11y.mjs.map +1 -1
- package/fesm2022/cngx-common-audio.mjs +47 -5
- package/fesm2022/cngx-common-audio.mjs.map +1 -1
- package/fesm2022/cngx-common-card.mjs +300 -46
- package/fesm2022/cngx-common-card.mjs.map +1 -1
- package/fesm2022/cngx-common-chart.mjs +1176 -453
- package/fesm2022/cngx-common-chart.mjs.map +1 -1
- package/fesm2022/cngx-common-command.mjs +37 -10
- package/fesm2022/cngx-common-command.mjs.map +1 -1
- package/fesm2022/cngx-common-data.mjs +1318 -469
- package/fesm2022/cngx-common-data.mjs.map +1 -1
- package/fesm2022/cngx-common-dialog.mjs +151 -14
- package/fesm2022/cngx-common-dialog.mjs.map +1 -1
- package/fesm2022/cngx-common-display.mjs +340 -73
- package/fesm2022/cngx-common-display.mjs.map +1 -1
- package/fesm2022/cngx-common-interactive.mjs +1744 -952
- package/fesm2022/cngx-common-interactive.mjs.map +1 -1
- package/fesm2022/cngx-common-layout.mjs +841 -114
- package/fesm2022/cngx-common-layout.mjs.map +1 -1
- package/fesm2022/cngx-common-popover.mjs +350 -60
- package/fesm2022/cngx-common-popover.mjs.map +1 -1
- package/fesm2022/cngx-common-stepper.mjs +727 -317
- package/fesm2022/cngx-common-stepper.mjs.map +1 -1
- package/fesm2022/cngx-common-tabs.mjs +1601 -1243
- package/fesm2022/cngx-common-tabs.mjs.map +1 -1
- package/fesm2022/cngx-common-timeline.mjs +137 -53
- package/fesm2022/cngx-common-timeline.mjs.map +1 -1
- package/fesm2022/cngx-common.mjs +1 -1
- package/interactive/README.md +15 -4
- package/layout/README.md +21 -1
- package/package.json +3 -3
- package/popover/README.md +18 -2
- package/stepper/README.md +6 -4
- package/theming/components/cngx-accordion.css +1 -1
- package/theming/components/cngx-backdrop.css +12 -0
- package/theming/components/cngx-button-toggle.css +29 -3
- package/theming/components/cngx-data-grid.css +168 -1
- package/theming/components/cngx-dialog.css +13 -0
- package/theming/components/cngx-listbox.css +21 -12
- package/theming/components/cngx-menu.css +56 -16
- package/theming/components/cngx-popover.css +24 -0
- package/theming/components/cngx-recycler-placeholder.css +196 -0
- package/theming/components/cngx-ripple.css +1 -1
- package/theming/components/cngx-slider.css +32 -1
- package/theming/components/cngx-tooltip.css +12 -0
- package/timeline/README.md +155 -0
- package/types/cngx-common-a11y.d.ts +42 -18
- package/types/cngx-common-card.d.ts +201 -17
- package/types/cngx-common-chart.d.ts +343 -47
- package/types/cngx-common-command.d.ts +31 -8
- package/types/cngx-common-data.d.ts +581 -68
- package/types/cngx-common-dialog.d.ts +158 -3
- package/types/cngx-common-display.d.ts +356 -142
- package/types/cngx-common-interactive.d.ts +859 -210
- package/types/cngx-common-layout.d.ts +567 -28
- package/types/cngx-common-popover.d.ts +262 -39
- package/types/cngx-common-stepper.d.ts +366 -116
- package/types/cngx-common-tabs.d.ts +214 -50
- package/types/cngx-common-timeline.d.ts +82 -16
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { InjectionToken,
|
|
2
|
+
import { InjectionToken, inject, computed, makeEnvironmentProviders, model, input, Injector, output, signal, Directive, TemplateRef, contentChild, DestroyRef, Renderer2, ElementRef, effect, afterNextRender, untracked, isDevMode, linkedSignal, runInInjectionContext } from '@angular/core';
|
|
3
3
|
import { CNGX_COMMIT_CONTROLLER_FACTORY } from '@cngx/common/data';
|
|
4
|
-
import { createTransitionTracker, CNGX_STATEFUL, nextUid } from '@cngx/core/utils';
|
|
4
|
+
import { createOverrideMerge, createTransitionTracker, CNGX_STATEFUL, nextUid, coerceSignal, createAnnouncementPhrase } from '@cngx/core/utils';
|
|
5
|
+
import { recordEqual, arrayEqual } from '@cngx/utils';
|
|
6
|
+
import { createLanguageSection, formatMessage, createSectionBundle } from '@cngx/core/i18n';
|
|
5
7
|
import { isObservable, Observable } from 'rxjs';
|
|
8
|
+
import { PRIMARY_OUTLET, Router, NavigationEnd, ActivatedRoute } from '@angular/router';
|
|
6
9
|
import { toSignal, takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
7
|
-
import {
|
|
8
|
-
import { filter, take } from 'rxjs/operators';
|
|
10
|
+
import { filter } from 'rxjs/operators';
|
|
9
11
|
import { resolveInlineStep } from '@cngx/core';
|
|
10
12
|
|
|
11
13
|
/**
|
|
@@ -22,1291 +24,1536 @@ import { resolveInlineStep } from '@cngx/core';
|
|
|
22
24
|
const CNGX_TABS_COMMIT_ACTION = new InjectionToken('CngxTabsCommitAction');
|
|
23
25
|
|
|
24
26
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* `boolean` returns into a single `accept: boolean` outcome.
|
|
27
|
+
* The English tabs section: the single source of the tabs' English copy.
|
|
28
|
+
* `CNGX_TABS_I18N` and the `CNGX_TABS_CONFIG` labels default to it.
|
|
28
29
|
*
|
|
29
|
-
* @category common/tabs
|
|
30
|
+
* @category common/tabs/i18n
|
|
31
|
+
* @since 0.1.0
|
|
32
|
+
* @relatedTo CNGX_TABS_I18N, CNGX_TABS_CONFIG
|
|
30
33
|
*/
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
const CNGX_TABS_LANGUAGE_EN = {
|
|
35
|
+
tabsRegion: 'Tabs',
|
|
36
|
+
tabsLabel: 'Tabs',
|
|
37
|
+
tabRoleDescription: 'tab list',
|
|
38
|
+
tabPanelRoleDescription: 'tab panel',
|
|
39
|
+
selectedTab: 'Tab {position} of {count}: {label}',
|
|
40
|
+
tabLabelWithDetail: '{label}, {detail}',
|
|
41
|
+
tabHasErrors: { one: '{count} error', other: '{count} errors' },
|
|
42
|
+
moreTabsLabel: '{count} more',
|
|
43
|
+
unlabeledTab: 'Tab {position}',
|
|
44
|
+
previousTab: 'Previous tab: {tab}',
|
|
45
|
+
nextTab: 'Next tab: {tab}',
|
|
46
|
+
closeTab: 'Close "{label}"',
|
|
47
|
+
addTab: 'Add tab',
|
|
48
|
+
closedTab: 'Closed "{label}"',
|
|
49
|
+
closedUnlabeledTab: 'Tab closed',
|
|
50
|
+
commitFailedRetry: 'Could not switch tab - retry?',
|
|
51
|
+
commitInFlight: 'Switching tab…',
|
|
52
|
+
commitRolledBackTo: 'Could not save changes - reverted to "{origin}".',
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @internal The English tabs section with the active pack's tabs section on
|
|
57
|
+
* top. Feeds both `CNGX_TABS_I18N` and the `CNGX_TABS_CONFIG` labels.
|
|
58
|
+
*/
|
|
59
|
+
const injectTabsLanguage = createLanguageSection('tabs', CNGX_TABS_LANGUAGE_EN);
|
|
60
|
+
/** @internal Turns a tabs section into the token's keys for a locale. */
|
|
61
|
+
function tabsBundleFrom(section, locale) {
|
|
33
62
|
return {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
63
|
+
tabsLabel: section.tabsLabel,
|
|
64
|
+
selectedTab: (label, position, count) => formatMessage(section.selectedTab, { label, position, count }, locale),
|
|
65
|
+
tabLabelWithDetail: (label, detail) => formatMessage(section.tabLabelWithDetail, { label, detail }, locale),
|
|
66
|
+
tabHasErrors: (count) => formatMessage(section.tabHasErrors, { count }, locale),
|
|
67
|
+
moreTabsLabel: (count) => formatMessage(section.moreTabsLabel, { count }, locale),
|
|
68
|
+
unlabeledTab: (position) => formatMessage(section.unlabeledTab, { position }, locale),
|
|
69
|
+
previousTab: (tab) => formatMessage(section.previousTab, { tab }, locale),
|
|
70
|
+
nextTab: (tab) => formatMessage(section.nextTab, { tab }, locale),
|
|
71
|
+
closeTab: (label) => formatMessage(section.closeTab, { label }, locale),
|
|
72
|
+
addTab: section.addTab,
|
|
73
|
+
closedTab: (label) => label ? formatMessage(section.closedTab, { label }, locale) : section.closedUnlabeledTab,
|
|
74
|
+
commitFailedRetry: section.commitFailedRetry,
|
|
75
|
+
commitInFlight: section.commitInFlight,
|
|
76
|
+
commitRolledBackTo: (origin) => formatMessage(section.commitRolledBackTo, { origin }, locale),
|
|
44
77
|
};
|
|
45
78
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const safeSuccess = (accept) => {
|
|
50
|
-
if (cancelled) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
if (accept) {
|
|
54
|
-
handlers.onSuccess(toIndex);
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
handlers.onError(new Error('Tab transition refused by commitAction'));
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
const safeError = (err) => {
|
|
61
|
-
if (cancelled) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
handlers.onError(err);
|
|
65
|
-
};
|
|
66
|
-
let result;
|
|
67
|
-
try {
|
|
68
|
-
result = action(fromIndex, toIndex);
|
|
69
|
-
}
|
|
70
|
-
catch (err) {
|
|
71
|
-
safeError(err);
|
|
72
|
-
return {
|
|
73
|
-
cancel: () => {
|
|
74
|
-
cancelled = true;
|
|
75
|
-
},
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
if (isObservable(result)) {
|
|
79
|
-
// Synchronous Observables (`of(true)`) emit inside `.subscribe` before
|
|
80
|
-
// the assignment binds - close over a pre-declared `let` to avoid TDZ.
|
|
81
|
-
let sub = null;
|
|
82
|
-
sub = result.subscribe({
|
|
83
|
-
next: (accept) => {
|
|
84
|
-
safeSuccess(accept);
|
|
85
|
-
sub?.unsubscribe();
|
|
86
|
-
},
|
|
87
|
-
error: (err) => safeError(err),
|
|
88
|
-
});
|
|
89
|
-
unsubscribe = () => sub?.unsubscribe();
|
|
90
|
-
}
|
|
91
|
-
else if (result != null && typeof result.then === 'function') {
|
|
92
|
-
result.then(safeSuccess, safeError);
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
safeSuccess(result);
|
|
96
|
-
}
|
|
97
|
-
return {
|
|
98
|
-
cancel: () => {
|
|
99
|
-
cancelled = true;
|
|
100
|
-
unsubscribe?.();
|
|
101
|
-
},
|
|
102
|
-
};
|
|
79
|
+
/** @internal The tabs section of the active pack over English. */
|
|
80
|
+
function injectTabsSection() {
|
|
81
|
+
return injectTabsLanguage();
|
|
103
82
|
}
|
|
83
|
+
/** @internal Builds and reads the token, formatted for the reading locale. */
|
|
84
|
+
const tabsBundle = createSectionBundle({
|
|
85
|
+
section: injectTabsSection,
|
|
86
|
+
toBundle: tabsBundleFrom,
|
|
87
|
+
});
|
|
104
88
|
/**
|
|
105
|
-
* DI token for the
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
89
|
+
* DI token for the tabs i18n bundle, as a `Signal` so a runtime language
|
|
90
|
+
* switch re-renders every label it feeds. `providedIn: 'root'`: the tabs
|
|
91
|
+
* section of the active language pack over the English defaults, formatted
|
|
92
|
+
* for the app locale. Provide it through {@link provideTabsI18n}; a
|
|
93
|
+
* `{ provide, useValue }` entry must supply a `Signal<CngxTabsI18n>`.
|
|
110
94
|
*
|
|
111
|
-
* @category common/tabs
|
|
112
|
-
* @
|
|
95
|
+
* @category common/tabs/i18n
|
|
96
|
+
* @wcag AA
|
|
97
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/i18n/tabs-i18n.ts
|
|
113
98
|
* @since 0.1.0
|
|
114
99
|
*/
|
|
115
|
-
const
|
|
100
|
+
const CNGX_TABS_I18N = new InjectionToken('CngxTabsI18n', {
|
|
116
101
|
providedIn: 'root',
|
|
117
|
-
factory: () =>
|
|
102
|
+
factory: () => tabsBundle.build(),
|
|
118
103
|
});
|
|
104
|
+
/**
|
|
105
|
+
* Brands an i18n-mutator with the `_target` discriminator.
|
|
106
|
+
*
|
|
107
|
+
* @internal
|
|
108
|
+
*/
|
|
109
|
+
function defineTabsI18nFeature(fn) {
|
|
110
|
+
return Object.assign(fn, { _target: 'i18n' });
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Override i18n labels via a partial bundle - unset keys keep the
|
|
114
|
+
* language pack's copy, or the English default. Same shape as `withTabsAriaLabels` /
|
|
115
|
+
* `withTabsFallbackLabels` so `provideCngxTabs` composes both
|
|
116
|
+
* surfaces uniformly. Pass a `Signal` to switch the language at runtime.
|
|
117
|
+
*
|
|
118
|
+
* @category common/tabs/i18n
|
|
119
|
+
*/
|
|
120
|
+
function withTabsI18nLabels(overrides) {
|
|
121
|
+
return defineTabsI18nFeature((bundle) => createOverrideMerge(bundle, overrides));
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Provider for the tabs i18n bundle. Compose `withTabsI18nLabels(...)`
|
|
125
|
+
* (and future i18n `with*` features); unset keys fall back to the
|
|
126
|
+
* language pack, then English. The features apply on top of the active pack.
|
|
127
|
+
*
|
|
128
|
+
* ```ts
|
|
129
|
+
* bootstrapApplication(AppComponent, {
|
|
130
|
+
* providers: [
|
|
131
|
+
* provideTabsI18n(
|
|
132
|
+
* withTabsI18nLabels({ tabsLabel: 'Reiter', addTab: 'Neuer Reiter' }),
|
|
133
|
+
* ),
|
|
134
|
+
* ],
|
|
135
|
+
* });
|
|
136
|
+
* ```
|
|
137
|
+
*
|
|
138
|
+
* @category common/tabs/i18n
|
|
139
|
+
*/
|
|
140
|
+
function provideTabsI18n(...features) {
|
|
141
|
+
return {
|
|
142
|
+
provide: CNGX_TABS_I18N,
|
|
143
|
+
useFactory: () => tabsBundle.build(features),
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Inject the resolved tabs i18n bundle. Read it inside a `computed()`,
|
|
148
|
+
* template or handler so a language switch reaches the label.
|
|
149
|
+
*
|
|
150
|
+
* @category common/tabs/i18n
|
|
151
|
+
*/
|
|
152
|
+
function injectTabsI18n() {
|
|
153
|
+
return tabsBundle.resolve(inject(CNGX_TABS_I18N));
|
|
154
|
+
}
|
|
119
155
|
|
|
120
156
|
/**
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
* to
|
|
124
|
-
|
|
125
|
-
|
|
157
|
+
* @internal - library defaults of {@link CNGX_TABS_CONFIG}. Exported from
|
|
158
|
+
* this file (not from `public-api.ts`) so the announcement factory falls
|
|
159
|
+
* back to the same `fallbackLabels` strings instead of repeating them.
|
|
160
|
+
*/
|
|
161
|
+
const TABS_CONFIG_DEFAULTS = {
|
|
162
|
+
defaultOrientation: 'horizontal',
|
|
163
|
+
defaultLoop: true,
|
|
164
|
+
defaultCommitMode: 'optimistic',
|
|
165
|
+
fragmentSyncMode: 'fragment',
|
|
166
|
+
fragmentSyncParam: 'tab',
|
|
167
|
+
// routeMatch stays unset: the host-flavour default is the right answer
|
|
168
|
+
// for both organisms, and pinning one here would silently flip the
|
|
169
|
+
// other. linkAriaCurrent defaults at the link, not here.
|
|
170
|
+
linkAriaCurrent: 'page',
|
|
171
|
+
ariaLabels: {
|
|
172
|
+
tabsRegion: CNGX_TABS_LANGUAGE_EN.tabsRegion,
|
|
173
|
+
},
|
|
174
|
+
fallbackLabels: {
|
|
175
|
+
// W3C ARIA tablist convention - kept distinct from
|
|
176
|
+
// `i18n.tabsLabel` so AT doesn't read the same string twice
|
|
177
|
+
// back-to-back across `aria-roledescription` and `aria-label`.
|
|
178
|
+
tabRoleDescription: CNGX_TABS_LANGUAGE_EN.tabRoleDescription,
|
|
179
|
+
tabPanelRoleDescription: CNGX_TABS_LANGUAGE_EN.tabPanelRoleDescription,
|
|
180
|
+
},
|
|
181
|
+
overflowStabilizeMs: 100,
|
|
182
|
+
overflowMaxDeferMs: 250,
|
|
183
|
+
templates: {},
|
|
184
|
+
};
|
|
185
|
+
/**
|
|
186
|
+
* DI token for the resolved tabs config. \
|
|
187
|
+
* `providedIn: 'root'` with the library defaults; override via {@link provideTabsConfig}
|
|
188
|
+
* (root) or {@link provideTabsConfigAt} (component scope).
|
|
126
189
|
*
|
|
127
190
|
* @category common/tabs
|
|
128
191
|
* @wcag AA
|
|
129
|
-
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/
|
|
192
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/tabs-config.ts
|
|
130
193
|
* @since 0.1.0
|
|
131
194
|
*/
|
|
132
|
-
const
|
|
133
|
-
|
|
195
|
+
const CNGX_TABS_CONFIG = new InjectionToken('CngxTabsConfig', {
|
|
196
|
+
providedIn: 'root',
|
|
197
|
+
factory: () => resolveFeatures([]),
|
|
198
|
+
});
|
|
134
199
|
/**
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
* so `<cngx-toast-on />` / `<cngx-banner-on />` compose without
|
|
140
|
-
* `[state]` wiring.
|
|
200
|
+
* Internal helper that brands a config-mutator function with the
|
|
201
|
+
* `_target` discriminator. \
|
|
202
|
+
* Every `with*` config feature returns one
|
|
203
|
+
* of these.
|
|
141
204
|
*
|
|
142
|
-
*
|
|
143
|
-
|
|
144
|
-
|
|
205
|
+
* @internal
|
|
206
|
+
*/
|
|
207
|
+
function defineTabsConfigFeature(fn) {
|
|
208
|
+
return Object.assign(fn, { _target: 'config' });
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Override the default orientation. Per-instance `[orientation]`
|
|
212
|
+
* still wins; this changes the cascade default only.
|
|
145
213
|
*
|
|
146
214
|
* @category common/tabs
|
|
147
|
-
* @docsKind primary
|
|
148
|
-
* @wcag AA
|
|
149
|
-
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/presenter.directive.ts
|
|
150
|
-
* @since 0.1.0
|
|
151
|
-
* @relatedTo CngxTab, CngxTabContent, CngxTabLabel, CngxTabsFragmentSync
|
|
152
|
-
* <example-url>http://localhost:4200/#/ui/tabs/tab-commit-action/optimistic-pessimistic-commits-with-bridge-directives</example-url>
|
|
153
215
|
*/
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
* Async-commit action gating the transition.
|
|
160
|
-
* When non-null, `select(...)` routes through {@link CngxTabsCommitHandler}; the
|
|
161
|
-
* action's resolution decides whether the change lands. Supersede
|
|
162
|
-
* semantics come from the commit-controller - a rapid second
|
|
163
|
-
* `select(...)` cancels the in-flight runner.
|
|
164
|
-
*
|
|
165
|
-
* @internal Two-field alias - bind the public `[commitAction]`; read
|
|
166
|
-
* the resolved {@link commitAction} computed (input ?? DI fallback).
|
|
167
|
-
*/
|
|
168
|
-
commitActionInput = input(null, { ...(ngDevMode ? { debugName: "commitActionInput" } : /* istanbul ignore next */ {}), alias: 'commitAction' });
|
|
169
|
-
/**
|
|
170
|
-
* Default `'optimistic'` - tab change is navigation, not a save,
|
|
171
|
-
* so eager visual feedback matches the user's mental model.
|
|
172
|
-
* Switch to `'pessimistic'` when the new tab must wait for the
|
|
173
|
-
* action to confirm.
|
|
174
|
-
*
|
|
175
|
-
* @internal Two-field alias - bind the public `[commitMode]`; read
|
|
176
|
-
* the resolved {@link commitMode} computed (DI fallback mode wins
|
|
177
|
-
* when a routed action is active).
|
|
178
|
-
*/
|
|
179
|
-
commitModeInput = input('optimistic', { ...(ngDevMode ? { debugName: "commitModeInput" } : /* istanbul ignore next */ {}), alias: 'commitMode' });
|
|
180
|
-
injector = inject(Injector);
|
|
181
|
-
// Resolved lazily, never in a field initialiser: a sync directive
|
|
182
|
-
// (e.g. [cngxTabsRouteSync]) provides CNGX_TABS_COMMIT_ACTION via
|
|
183
|
-
// useExisting and itself injects this presenter as its host, so
|
|
184
|
-
// eager injection here would close a construction cycle (NG0200).
|
|
185
|
-
// First read happens at select()/template time - after both
|
|
186
|
-
// directives exist. The source is static per element, so memoising
|
|
187
|
-
// the resolution is safe.
|
|
188
|
-
injectedActionSource;
|
|
189
|
-
resolveInjectedAction() {
|
|
190
|
-
if (this.injectedActionSource === undefined) {
|
|
191
|
-
this.injectedActionSource = this.injector.get(CNGX_TABS_COMMIT_ACTION, null);
|
|
192
|
-
}
|
|
193
|
-
return this.injectedActionSource;
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Resolved commit-action: the `[commitAction]` input when bound, else
|
|
197
|
-
* the {@link CNGX_TABS_COMMIT_ACTION} DI fallback (routed path), else
|
|
198
|
-
* `null`. `select()` reads this.
|
|
199
|
-
*/
|
|
200
|
-
commitAction = computed(() => this.commitActionInput() ?? this.resolveInjectedAction()?.action() ?? null, ...(ngDevMode ? [{ debugName: "commitAction" }] : /* istanbul ignore next */ []));
|
|
201
|
-
/**
|
|
202
|
-
* Resolved commit mode. When the DI fallback supplies an active
|
|
203
|
-
* action its `mode` wins - the routed path pins `'pessimistic'` so a
|
|
204
|
-
* stray `[commitMode]="'optimistic'"` cannot break the
|
|
205
|
-
* route-follows-resolution invariant. Otherwise the `[commitMode]`
|
|
206
|
-
* input drives.
|
|
207
|
-
*/
|
|
208
|
-
commitMode = computed(() => {
|
|
209
|
-
const source = this.resolveInjectedAction();
|
|
210
|
-
return source?.action() ? source.mode() : this.commitModeInput();
|
|
211
|
-
}, ...(ngDevMode ? [{ debugName: "commitMode" }] : /* istanbul ignore next */ []));
|
|
212
|
-
/**
|
|
213
|
-
* Emitted when a tab's close affordance is activated (the close
|
|
214
|
-
* button or Delete/Backspace on the focused tab). The presenter has
|
|
215
|
-
* already moved the active index onto the surviving neighbour; the
|
|
216
|
-
* consumer removes the tab from its own data in the handler.
|
|
217
|
-
*/
|
|
218
|
-
tabClose = output();
|
|
219
|
-
/**
|
|
220
|
-
* Emitted when the add-tab affordance is activated. The consumer
|
|
221
|
-
* appends a tab to its own data; the presenter owns no creation logic.
|
|
222
|
-
*/
|
|
223
|
-
tabAdd = output();
|
|
224
|
-
genericFactory = inject(CNGX_COMMIT_CONTROLLER_FACTORY);
|
|
225
|
-
commitController = this.genericFactory();
|
|
226
|
-
commitHandler = inject(CNGX_TABS_COMMIT_HANDLER_FACTORY)({
|
|
227
|
-
controller: this.commitController,
|
|
228
|
-
});
|
|
229
|
-
/** Producer surface for the `CNGX_STATEFUL` bridge contract. */
|
|
230
|
-
state = this.commitController.state;
|
|
231
|
-
commitState = this.commitController.state;
|
|
232
|
-
/**
|
|
233
|
-
* Index the user is currently trying to commit to. Tracked
|
|
234
|
-
* separately from `state.data()` (which only updates on success)
|
|
235
|
-
* to drive per-tab `aria-busy`.
|
|
236
|
-
*/
|
|
237
|
-
intendedIndex = this.commitController.intendedValue;
|
|
238
|
-
/**
|
|
239
|
-
* Current/previous pair for `commitState.status()`. Skin
|
|
240
|
-
* sub-components feed `<span cngxLiveRegion>` from this tracker
|
|
241
|
-
* for declarative SR announcements. Shared across consumers so
|
|
242
|
-
* the tracker's `linkedSignal` is allocated once per presenter.
|
|
243
|
-
*/
|
|
244
|
-
commitTransition = createTransitionTracker(() => this.commitController.state.status());
|
|
245
|
-
// Persistence-of-error surface - see `CngxTabGroupHost.lastFailedIndex`
|
|
246
|
-
// and `originIndexDuringCommit` for the contract.
|
|
247
|
-
lastFailedIndexState = signal(undefined, ...(ngDevMode ? [{ debugName: "lastFailedIndexState" }] : /* istanbul ignore next */ []));
|
|
248
|
-
originIndexDuringCommitState = signal(undefined, ...(ngDevMode ? [{ debugName: "originIndexDuringCommitState" }] : /* istanbul ignore next */ []));
|
|
249
|
-
/** {@inheritDoc CngxTabGroupHost.lastFailedIndex} */
|
|
250
|
-
lastFailedIndex = this.lastFailedIndexState.asReadonly();
|
|
251
|
-
/** {@inheritDoc CngxTabGroupHost.originIndexDuringCommit} */
|
|
252
|
-
originIndexDuringCommit = this.originIndexDuringCommitState.asReadonly();
|
|
253
|
-
tabsState = signal([], { ...(ngDevMode ? { debugName: "tabsState" } : /* istanbul ignore next */ {}), equal: tabsEqual });
|
|
254
|
-
tabs = this.tabsState.asReadonly();
|
|
255
|
-
clampedIndex = computed(() => {
|
|
256
|
-
const count = this.tabs().length;
|
|
257
|
-
if (count === 0) {
|
|
258
|
-
return 0;
|
|
259
|
-
}
|
|
260
|
-
return Math.max(0, Math.min(this.activeIndex(), count - 1));
|
|
261
|
-
}, ...(ngDevMode ? [{ debugName: "clampedIndex" }] : /* istanbul ignore next */ []));
|
|
262
|
-
activeId = computed(() => this.tabs()[this.clampedIndex()]?.id ?? null, { ...(ngDevMode ? { debugName: "activeId" } : /* istanbul ignore next */ {}), equal: Object.is });
|
|
263
|
-
register(handle) {
|
|
264
|
-
const current = this.tabsState();
|
|
265
|
-
const idx = current.findIndex((h) => h.id === handle.id);
|
|
266
|
-
if (idx >= 0) {
|
|
267
|
-
const next = current.slice();
|
|
268
|
-
next[idx] = handle;
|
|
269
|
-
this.tabsState.set(next);
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
this.tabsState.set([...current, handle]);
|
|
273
|
-
}
|
|
274
|
-
unregister(id) {
|
|
275
|
-
const current = this.tabsState();
|
|
276
|
-
const next = current.filter((h) => h.id !== id);
|
|
277
|
-
if (next.length !== current.length) {
|
|
278
|
-
this.tabsState.set(next);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
/** {@inheritDoc CngxTabGroupHost.clearLastFailed} */
|
|
282
|
-
clearLastFailed() {
|
|
283
|
-
this.lastFailedIndexState.set(undefined);
|
|
284
|
-
}
|
|
285
|
-
select(index) {
|
|
286
|
-
const tabs = this.tabs();
|
|
287
|
-
if (tabs.length === 0) {
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
const target = Math.max(0, Math.min(index, tabs.length - 1));
|
|
291
|
-
if (tabs[target].disabled()) {
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
const previous = this.activeIndex();
|
|
295
|
-
if (target === previous) {
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
const action = this.commitAction();
|
|
299
|
-
if (!action) {
|
|
300
|
-
// No-action fast path - `originIndexDuringCommit` stays
|
|
301
|
-
// untouched, so a stale origin can never leak into the
|
|
302
|
-
// live-region announcement.
|
|
303
|
-
this.activeIndex.set(target);
|
|
304
|
-
if (this.lastFailedIndexState() === target) {
|
|
305
|
-
this.lastFailedIndexState.set(undefined);
|
|
306
|
-
}
|
|
307
|
-
return;
|
|
308
|
-
}
|
|
309
|
-
// Open the commit window - origin is captured ONLY here so a
|
|
310
|
-
// stale value never lingers into a non-commit navigation.
|
|
311
|
-
this.originIndexDuringCommitState.set(previous);
|
|
312
|
-
const mode = this.commitMode();
|
|
313
|
-
if (mode === 'optimistic') {
|
|
314
|
-
this.activeIndex.set(target);
|
|
315
|
-
}
|
|
316
|
-
this.commitHandler.beginTransition(previous, target, action, (accept) => {
|
|
317
|
-
if (accept) {
|
|
318
|
-
// Window closes on success - origin label no longer needed;
|
|
319
|
-
// clear the rejection flag if the user re-picked the failed
|
|
320
|
-
// target successfully.
|
|
321
|
-
this.originIndexDuringCommitState.set(undefined);
|
|
322
|
-
if (this.lastFailedIndexState() === target) {
|
|
323
|
-
this.lastFailedIndexState.set(undefined);
|
|
324
|
-
}
|
|
325
|
-
if (mode === 'pessimistic') {
|
|
326
|
-
this.activeIndex.set(target);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
else {
|
|
330
|
-
// Reject - flag the refused target; RETAIN the origin so
|
|
331
|
-
// the organism's `liveAnnouncement` computed can resolve
|
|
332
|
-
// the origin label for the rich rollback phrase. Optimistic
|
|
333
|
-
// rolls back; pessimistic never moved.
|
|
334
|
-
this.lastFailedIndexState.set(target);
|
|
335
|
-
if (mode === 'optimistic') {
|
|
336
|
-
this.activeIndex.set(previous);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
selectNext() {
|
|
342
|
-
const tabs = this.tabs();
|
|
343
|
-
if (tabs.length === 0) {
|
|
344
|
-
return;
|
|
345
|
-
}
|
|
346
|
-
let next = this.activeIndex() + 1;
|
|
347
|
-
while (next < tabs.length && tabs[next].disabled()) {
|
|
348
|
-
next++;
|
|
349
|
-
}
|
|
350
|
-
if (next < tabs.length) {
|
|
351
|
-
this.select(next);
|
|
352
|
-
return;
|
|
353
|
-
}
|
|
354
|
-
if (this.loop()) {
|
|
355
|
-
let i = 0;
|
|
356
|
-
while (i < tabs.length && tabs[i].disabled()) {
|
|
357
|
-
i++;
|
|
358
|
-
}
|
|
359
|
-
if (i < tabs.length && i !== this.activeIndex()) {
|
|
360
|
-
this.select(i);
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
selectPrevious() {
|
|
365
|
-
const tabs = this.tabs();
|
|
366
|
-
if (tabs.length === 0) {
|
|
367
|
-
return;
|
|
368
|
-
}
|
|
369
|
-
let prev = this.activeIndex() - 1;
|
|
370
|
-
while (prev >= 0 && tabs[prev].disabled()) {
|
|
371
|
-
prev--;
|
|
372
|
-
}
|
|
373
|
-
if (prev >= 0) {
|
|
374
|
-
this.select(prev);
|
|
375
|
-
return;
|
|
376
|
-
}
|
|
377
|
-
if (this.loop()) {
|
|
378
|
-
let i = tabs.length - 1;
|
|
379
|
-
while (i >= 0 && tabs[i].disabled()) {
|
|
380
|
-
i--;
|
|
381
|
-
}
|
|
382
|
-
if (i >= 0 && i !== this.activeIndex()) {
|
|
383
|
-
this.select(i);
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
selectById(id) {
|
|
388
|
-
const tabs = this.tabs();
|
|
389
|
-
const idx = tabs.findIndex((h) => h.id === id);
|
|
390
|
-
if (idx >= 0) {
|
|
391
|
-
this.select(idx);
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
requestClose(id) {
|
|
395
|
-
const tabs = this.tabs();
|
|
396
|
-
const index = tabs.findIndex((h) => h.id === id);
|
|
397
|
-
if (index < 0) {
|
|
398
|
-
return;
|
|
399
|
-
}
|
|
400
|
-
const active = this.clampedIndex();
|
|
401
|
-
// Only closing a tab BEFORE the active one needs a pre-emptive
|
|
402
|
-
// index shift: the active tab moves down one slot once the consumer
|
|
403
|
-
// removes the closed tab, so decrement to keep the same tab active.
|
|
404
|
-
// Closing the active tab (or one after it) needs no write -
|
|
405
|
-
// `clampedIndex` re-derives against the shorter array and lands on
|
|
406
|
-
// the next tab (or the new last when the closed tab was last).
|
|
407
|
-
if (index < active) {
|
|
408
|
-
this.activeIndex.set(active - 1);
|
|
409
|
-
}
|
|
410
|
-
this.tabClose.emit({ id, index });
|
|
411
|
-
}
|
|
412
|
-
requestAdd() {
|
|
413
|
-
this.tabAdd.emit();
|
|
414
|
-
}
|
|
415
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabGroupPresenter, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
416
|
-
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: [
|
|
417
|
-
{ provide: CNGX_TAB_GROUP_HOST, useExisting: CngxTabGroupPresenter },
|
|
418
|
-
{ provide: CNGX_STATEFUL, useExisting: CngxTabGroupPresenter },
|
|
419
|
-
], exportAs: ["cngxTabGroup"], ngImport: i0 });
|
|
216
|
+
function withTabsDefaultOrientation(orientation) {
|
|
217
|
+
return defineTabsConfigFeature((cfg) => ({
|
|
218
|
+
...cfg,
|
|
219
|
+
defaultOrientation: orientation,
|
|
220
|
+
}));
|
|
420
221
|
}
|
|
421
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabGroupPresenter, decorators: [{
|
|
422
|
-
type: Directive,
|
|
423
|
-
args: [{
|
|
424
|
-
selector: '[cngxTabGroup]',
|
|
425
|
-
exportAs: 'cngxTabGroup',
|
|
426
|
-
standalone: true,
|
|
427
|
-
providers: [
|
|
428
|
-
{ provide: CNGX_TAB_GROUP_HOST, useExisting: CngxTabGroupPresenter },
|
|
429
|
-
{ provide: CNGX_STATEFUL, useExisting: CngxTabGroupPresenter },
|
|
430
|
-
],
|
|
431
|
-
}]
|
|
432
|
-
}], 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"] }] } });
|
|
433
222
|
/**
|
|
434
|
-
*
|
|
435
|
-
*
|
|
436
|
-
*
|
|
437
|
-
*
|
|
438
|
-
* `errorAggregator`, `hasError`, and `errorMessage` are left out on
|
|
439
|
-
* purpose. The handle is a stable per-tab reference injected once, and
|
|
440
|
-
* the organism reads `tab.hasError()` / `tab.errorMessage()` reactively
|
|
441
|
-
* off that handle (not off array identity), so the badge + descriptor
|
|
442
|
-
* update on error-state changes without the registry array re-emitting.
|
|
443
|
-
* Comparing them here would push the memoisation burden onto consumers
|
|
444
|
-
* and break the structural-equal contract.
|
|
223
|
+
* @deprecated Use {@link withTabsDefaultOrientation}. The unprefixed name
|
|
224
|
+
* collides with the stepper family's identical symbol when both libs
|
|
225
|
+
* are auto-imported. The alias stays for one minor release before
|
|
226
|
+
* removal.
|
|
445
227
|
*
|
|
446
|
-
*
|
|
447
|
-
|
|
228
|
+
* @category common/tabs
|
|
229
|
+
*/
|
|
230
|
+
const withDefaultOrientation = withTabsDefaultOrientation;
|
|
231
|
+
/**
|
|
232
|
+
* Override whether roving-tabindex navigation loops from last back to
|
|
233
|
+
* first (and vice versa). Per-instance `[loop]` Input still wins.
|
|
448
234
|
*
|
|
449
|
-
* @
|
|
235
|
+
* @category common/tabs
|
|
450
236
|
*/
|
|
451
|
-
function
|
|
452
|
-
|
|
453
|
-
return true;
|
|
454
|
-
}
|
|
455
|
-
if (a.length !== b.length) {
|
|
456
|
-
return false;
|
|
457
|
-
}
|
|
458
|
-
for (let i = 0; i < a.length; i++) {
|
|
459
|
-
if (a[i].id !== b[i].id ||
|
|
460
|
-
a[i].disabled() !== b[i].disabled() ||
|
|
461
|
-
a[i].label() !== b[i].label() ||
|
|
462
|
-
a[i].subLabel() !== b[i].subLabel() ||
|
|
463
|
-
a[i].closable() !== b[i].closable()) {
|
|
464
|
-
return false;
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
return true;
|
|
237
|
+
function withTabsRovingLoop(loop) {
|
|
238
|
+
return defineTabsConfigFeature((cfg) => ({ ...cfg, defaultLoop: loop }));
|
|
468
239
|
}
|
|
469
|
-
|
|
470
240
|
/**
|
|
471
|
-
*
|
|
472
|
-
*
|
|
473
|
-
*
|
|
241
|
+
* Override the default commit mode for async tab transitions.
|
|
242
|
+
* `'optimistic'` activates the tab on action dispatch and rolls back
|
|
243
|
+
* on error; `'pessimistic'` waits for success. Per-instance
|
|
244
|
+
* `[commitMode]` Input still wins.
|
|
474
245
|
*
|
|
475
246
|
* @category common/tabs
|
|
476
|
-
* @wcag AA
|
|
477
|
-
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/tab-panel-host.token.ts
|
|
478
|
-
* @since 0.1.0
|
|
479
247
|
*/
|
|
480
|
-
|
|
481
|
-
|
|
248
|
+
function withTabsCommitMode(mode) {
|
|
249
|
+
return defineTabsConfigFeature((cfg) => ({
|
|
250
|
+
...cfg,
|
|
251
|
+
defaultCommitMode: mode,
|
|
252
|
+
}));
|
|
253
|
+
}
|
|
482
254
|
/**
|
|
483
|
-
*
|
|
484
|
-
*
|
|
485
|
-
*
|
|
486
|
-
* (
|
|
255
|
+
* Configure URL fragment / query-param deep-linking for the active tab
|
|
256
|
+
* (the {@link CngxTabsFragmentSync} directive). \
|
|
257
|
+
* `mode` chooses the URL surface (URL fragment or query parameter); `param` names the key
|
|
258
|
+
* (default `'tab'`).
|
|
487
259
|
*
|
|
488
|
-
*
|
|
489
|
-
*
|
|
490
|
-
* only ever test `navHost != null`. Nothing here can be widened into a
|
|
491
|
-
* second host contract - {@link CNGX_TAB_GROUP_HOST} already owns the
|
|
492
|
-
* presenter surface, and this token sits beside it so the tablist path
|
|
493
|
-
* gains no dead field.
|
|
260
|
+
* Not to be confused with `[cngxTabsRouteSync]`, the router-outlet
|
|
261
|
+
* integration - this feature configures fragment deep-linking only.
|
|
494
262
|
*
|
|
495
|
-
*
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
263
|
+
* @category common/tabs
|
|
264
|
+
*/
|
|
265
|
+
function withTabsFragmentSync(mode, param = 'tab') {
|
|
266
|
+
return defineTabsConfigFeature((cfg) => ({
|
|
267
|
+
...cfg,
|
|
268
|
+
fragmentSyncMode: mode,
|
|
269
|
+
fragmentSyncParam: param,
|
|
270
|
+
}));
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Force one URL-matching mode app-wide for `[cngxTabsRouteSync]`. \
|
|
274
|
+
* `'suffix'` treats every tab as a leaf route, `'prefix'` as a section
|
|
275
|
+
* that stays active for URLs beneath it.
|
|
500
276
|
*
|
|
501
|
-
*
|
|
502
|
-
*
|
|
503
|
-
*
|
|
504
|
-
*
|
|
505
|
-
* (suffix). The `[match]` input overrides the token-derived default when a
|
|
506
|
-
* consumer needs the other mode.
|
|
277
|
+
* Reach for this only when the host-flavour default is wrong for your
|
|
278
|
+
* app. Unset, a `<cngx-tab-nav>` matches by prefix and a
|
|
279
|
+
* `<cngx-tab-group>` by suffix, which is what each markup implies; this
|
|
280
|
+
* feature overrides *both*. Per-instance `[match]` still wins.
|
|
507
281
|
*
|
|
508
|
-
*
|
|
509
|
-
* @
|
|
510
|
-
* selector: 'my-section-nav',
|
|
511
|
-
* providers: [{ provide: CNGX_TAB_NAV_HOST, useValue: true }],
|
|
512
|
-
* hostDirectives: [CngxTabGroupPresenter],
|
|
513
|
-
* })
|
|
514
|
-
* export class MySectionNav {}
|
|
515
|
-
* ```
|
|
282
|
+
* Changes which policy runs, not the policies themselves - swap those via
|
|
283
|
+
* {@link CNGX_TAB_URL_MATCH_STRATEGY}.
|
|
516
284
|
*
|
|
517
285
|
* @category common/tabs
|
|
518
|
-
* @wcag AA
|
|
519
|
-
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/tab-nav-host.token.ts
|
|
520
|
-
* @since 0.1.0
|
|
521
|
-
* @relatedTo CngxTabsRouteSync, CNGX_TAB_GROUP_HOST, CngxTabNav, CngxMatTabNav
|
|
522
|
-
*/
|
|
523
|
-
const CNGX_TAB_NAV_HOST = new InjectionToken('CngxTabNavHost');
|
|
524
|
-
|
|
525
|
-
/**
|
|
526
|
-
* Path-segment count of a resolved `UrlTree`, used to rank prefix
|
|
527
|
-
* matches: `/rounds/explorer` outranks `/rounds` on a URL both match.
|
|
528
286
|
*/
|
|
529
|
-
function
|
|
530
|
-
|
|
531
|
-
const walk = (group) => {
|
|
532
|
-
count += group.segments.length;
|
|
533
|
-
for (const key of Object.keys(group.children)) {
|
|
534
|
-
walk(group.children[key]);
|
|
535
|
-
}
|
|
536
|
-
};
|
|
537
|
-
walk(tree.root);
|
|
538
|
-
return count;
|
|
287
|
+
function withTabsRouteMatch(mode) {
|
|
288
|
+
return defineTabsConfigFeature((cfg) => ({ ...cfg, routeMatch: mode }));
|
|
539
289
|
}
|
|
540
290
|
/**
|
|
541
|
-
*
|
|
542
|
-
*
|
|
543
|
-
*
|
|
544
|
-
*
|
|
545
|
-
*
|
|
546
|
-
*
|
|
547
|
-
*
|
|
291
|
+
* Set the `aria-current` token `[cngxTabLink]` publishes while active. \
|
|
292
|
+
* Default `'page'`.
|
|
293
|
+
*
|
|
294
|
+
* Use `'true'` for a section nav whose links stay active across a whole
|
|
295
|
+
* subtree: the active link is then the current *section*, and `page`
|
|
296
|
+
* would tell AT it is the page being viewed. Scope it to one nav with
|
|
297
|
+
* `provideTabsConfigAt` in that component's `viewProviders` rather than
|
|
298
|
+
* setting it app-wide, unless every nav in the app is section-shaped.
|
|
299
|
+
* Per-link `[ariaCurrent]` still wins.
|
|
300
|
+
*
|
|
301
|
+
* @category common/tabs
|
|
548
302
|
*/
|
|
549
|
-
function
|
|
550
|
-
|
|
551
|
-
const segments = path.split('/').filter(Boolean);
|
|
552
|
-
for (const tab of ctx.tabs) {
|
|
553
|
-
const route = ctx.routeFor(tab).map((command) => String(command));
|
|
554
|
-
if (route.length === 0 || route.length > segments.length) {
|
|
555
|
-
continue;
|
|
556
|
-
}
|
|
557
|
-
const tail = segments.slice(-route.length);
|
|
558
|
-
if (tail.every((segment, i) => segment === route[i])) {
|
|
559
|
-
return tab.id;
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
return null;
|
|
303
|
+
function withTabsLinkAriaCurrent(token) {
|
|
304
|
+
return defineTabsConfigFeature((cfg) => ({ ...cfg, linkAriaCurrent: token }));
|
|
563
305
|
}
|
|
564
306
|
/**
|
|
565
|
-
*
|
|
566
|
-
*
|
|
567
|
-
*
|
|
307
|
+
* @deprecated Use {@link withTabsFragmentSync}. "Router sync" collided
|
|
308
|
+
* with the new `[cngxTabsRouteSync]` router-outlet directive; this
|
|
309
|
+
* feature only ever configured fragment / query-param deep-linking. The
|
|
310
|
+
* alias stays for one minor release before removal.
|
|
568
311
|
*
|
|
569
|
-
*
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
*
|
|
574
|
-
*
|
|
575
|
-
*
|
|
576
|
-
*
|
|
312
|
+
* @category common/tabs
|
|
313
|
+
*/
|
|
314
|
+
const withTabsRouterSync = withTabsFragmentSync;
|
|
315
|
+
/**
|
|
316
|
+
* Select the app-wide default visual skin for `<cngx-tab-group>`. \
|
|
317
|
+
* Default `'line'`. Per-instance `[skin]` Input still wins; this moves
|
|
318
|
+
* the cascade default. Structure, slots, ARIA, and keyboard behaviour
|
|
319
|
+
* are identical across skins - only the `[data-skin]` host attribute
|
|
320
|
+
* changes the CSS layer. The Material twin (`[cngxMatTabs]`) ignores it.
|
|
577
321
|
*
|
|
578
|
-
*
|
|
579
|
-
* in the same set.
|
|
322
|
+
* @category common/tabs
|
|
580
323
|
*/
|
|
581
|
-
function
|
|
582
|
-
|
|
583
|
-
let winnerDepth = -1;
|
|
584
|
-
for (const tab of ctx.tabs) {
|
|
585
|
-
const route = ctx.routeFor(tab);
|
|
586
|
-
if (route.length === 0) {
|
|
587
|
-
continue;
|
|
588
|
-
}
|
|
589
|
-
const tree = ctx.router.createUrlTree(route, { relativeTo: ctx.activatedRoute });
|
|
590
|
-
const active = ctx.router.isActive(tree, {
|
|
591
|
-
paths: 'subset',
|
|
592
|
-
queryParams: 'ignored',
|
|
593
|
-
fragment: 'ignored',
|
|
594
|
-
matrixParams: 'ignored',
|
|
595
|
-
});
|
|
596
|
-
if (!active) {
|
|
597
|
-
continue;
|
|
598
|
-
}
|
|
599
|
-
const depth = urlTreeSegmentCount(tree);
|
|
600
|
-
if (depth > winnerDepth) {
|
|
601
|
-
winner = tab.id;
|
|
602
|
-
winnerDepth = depth;
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
return winner;
|
|
324
|
+
function withTabsSkin(skin) {
|
|
325
|
+
return defineTabsConfigFeature((cfg) => ({ ...cfg, skin }));
|
|
606
326
|
}
|
|
607
327
|
/**
|
|
608
|
-
*
|
|
609
|
-
*
|
|
610
|
-
*
|
|
611
|
-
*
|
|
612
|
-
* Pure: no injection context, no signal reads. The directive resolves the
|
|
613
|
-
* mode cascade and the tab registry, then hands both in.
|
|
328
|
+
* Set the app-wide default icon layout for `<cngx-tab-group>`. \
|
|
329
|
+
* Default`'start'`. Per-instance `[iconLayout]` Input still wins. Orthogonal to
|
|
330
|
+
* skin and orientation - only the `[data-icon-layout]` host attribute
|
|
331
|
+
* changes.
|
|
614
332
|
*
|
|
615
333
|
* @category common/tabs
|
|
616
334
|
*/
|
|
617
|
-
function
|
|
618
|
-
return {
|
|
619
|
-
resolve(ctx) {
|
|
620
|
-
return ctx.mode === 'prefix' ? resolveByPrefix(ctx) : resolveBySuffix(ctx);
|
|
621
|
-
},
|
|
622
|
-
};
|
|
335
|
+
function withTabsIconLayout(layout) {
|
|
336
|
+
return defineTabsConfigFeature((cfg) => ({ ...cfg, iconLayout: layout }));
|
|
623
337
|
}
|
|
624
338
|
/**
|
|
625
|
-
*
|
|
626
|
-
*
|
|
339
|
+
* Set the app-wide default panel render strategy for `<cngx-tab-group>`. \
|
|
340
|
+
* Default `'eager'` (every panel's content rendered up front, toggled
|
|
341
|
+
* via `[hidden]`). `'lazy'` keep-alives content after first activation;
|
|
342
|
+
* `'lazy-destroy'` renders only the active panel's content. Per-instance
|
|
343
|
+
* `[panelMode]` Input still wins. The panel `<div>` always stays in the
|
|
344
|
+
* DOM regardless of mode (the `aria-controls` target).
|
|
627
345
|
*
|
|
628
|
-
*
|
|
629
|
-
*
|
|
630
|
-
* on a route `data` key instead of the path, or a permission-aware read
|
|
631
|
-
* that skips tabs the user cannot open. `routeFor` only changes what a
|
|
632
|
-
* tab's route *is*; this changes how it is *compared*.
|
|
346
|
+
* Under `'lazy'`, a deep link mounts only the panel it names: both sync
|
|
347
|
+
* directives seed the active tab before the first panel render.
|
|
633
348
|
*
|
|
634
|
-
*
|
|
635
|
-
|
|
636
|
-
|
|
349
|
+
* @category common/tabs
|
|
350
|
+
*/
|
|
351
|
+
function withTabsPanelMode(mode) {
|
|
352
|
+
return defineTabsConfigFeature((cfg) => ({ ...cfg, panelMode: mode }));
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Set the app-wide default for stretching tabs to the full strip width
|
|
356
|
+
* (horizontal only). \
|
|
357
|
+
* Default `false`. Per-instance `[fitted]` Input still
|
|
358
|
+
* wins. No effect under `orientation="vertical"`.
|
|
637
359
|
*
|
|
638
360
|
* @category common/tabs
|
|
639
|
-
* @wcag AA
|
|
640
|
-
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/url-match.ts
|
|
641
|
-
* @since 0.1.0
|
|
642
|
-
* @relatedTo CngxTabsRouteSync, createTabUrlMatch, createTabRouterCommit
|
|
643
361
|
*/
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
});
|
|
648
|
-
|
|
362
|
+
function withTabsFitted(fitted) {
|
|
363
|
+
return defineTabsConfigFeature((cfg) => ({ ...cfg, fitted }));
|
|
364
|
+
}
|
|
649
365
|
/**
|
|
650
|
-
*
|
|
651
|
-
*
|
|
652
|
-
* `
|
|
653
|
-
*
|
|
654
|
-
* ```html
|
|
655
|
-
* <div cngxTab [label]="'Settings'">
|
|
656
|
-
* <ng-template cngxTabContent>
|
|
657
|
-
* <p>Settings panel body…</p>
|
|
658
|
-
* </ng-template>
|
|
659
|
-
* </div>
|
|
660
|
-
* ```
|
|
366
|
+
* Set the app-wide default tab-cluster alignment (horizontal only). \
|
|
367
|
+
* Default `'start'`. Per-instance `[tabAlign]` Input still wins. Ignored
|
|
368
|
+
* under `orientation="vertical"` and when the group is `fitted`.
|
|
661
369
|
*
|
|
662
370
|
* @category common/tabs
|
|
663
|
-
* @wcag AA
|
|
664
|
-
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/tab-content.directive.ts
|
|
665
|
-
* @since 0.1.0
|
|
666
|
-
* @relatedTo CngxTab, CngxTabLabel
|
|
667
371
|
*/
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabContent, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
671
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxTabContent, isStandalone: true, selector: "ng-template[cngxTabContent]", exportAs: ["cngxTabContent"], ngImport: i0 });
|
|
372
|
+
function withTabsAlign(align) {
|
|
373
|
+
return defineTabsConfigFeature((cfg) => ({ ...cfg, tabAlign: align }));
|
|
672
374
|
}
|
|
673
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabContent, decorators: [{
|
|
674
|
-
type: Directive,
|
|
675
|
-
args: [{
|
|
676
|
-
selector: 'ng-template[cngxTabContent]',
|
|
677
|
-
exportAs: 'cngxTabContent',
|
|
678
|
-
standalone: true,
|
|
679
|
-
}]
|
|
680
|
-
}] });
|
|
681
|
-
|
|
682
375
|
/**
|
|
683
|
-
*
|
|
684
|
-
*
|
|
685
|
-
* `
|
|
686
|
-
*
|
|
687
|
-
* ```html
|
|
688
|
-
* <div cngxTab id="settings">
|
|
689
|
-
* <ng-template cngxTabLabel>Settings</ng-template>
|
|
690
|
-
* ... tab content ...
|
|
691
|
-
* </div>
|
|
692
|
-
* ```
|
|
376
|
+
* Set the app-wide default for whether tabs render a close affordance. \
|
|
377
|
+
* Default `false`. Per-instance `[closable]` Input wins; a per-`CngxTab`
|
|
378
|
+
* `[closable]` override wins over both.
|
|
693
379
|
*
|
|
694
380
|
* @category common/tabs
|
|
695
|
-
* @wcag AA
|
|
696
|
-
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/tab-label.directive.ts
|
|
697
|
-
* @since 0.1.0
|
|
698
|
-
* @relatedTo CngxTab, CngxTabContent
|
|
699
381
|
*/
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabLabel, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
703
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxTabLabel, isStandalone: true, selector: "ng-template[cngxTabLabel]", exportAs: ["cngxTabLabel"], ngImport: i0 });
|
|
382
|
+
function withTabsClosable(closable) {
|
|
383
|
+
return defineTabsConfigFeature((cfg) => ({ ...cfg, closable }));
|
|
704
384
|
}
|
|
705
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabLabel, decorators: [{
|
|
706
|
-
type: Directive,
|
|
707
|
-
args: [{
|
|
708
|
-
selector: 'ng-template[cngxTabLabel]',
|
|
709
|
-
exportAs: 'cngxTabLabel',
|
|
710
|
-
standalone: true,
|
|
711
|
-
}]
|
|
712
|
-
}] });
|
|
713
|
-
|
|
714
385
|
/**
|
|
715
|
-
*
|
|
716
|
-
*
|
|
717
|
-
* `
|
|
718
|
-
* label. \
|
|
386
|
+
* Set the app-wide default for whether the group renders an add-tab
|
|
387
|
+
* button. \
|
|
388
|
+
* Default `false`. Per-instance `[addable]` Input wins.
|
|
719
389
|
*
|
|
720
|
-
*
|
|
721
|
-
|
|
390
|
+
* @category common/tabs
|
|
391
|
+
*/
|
|
392
|
+
function withTabsAddable(addable) {
|
|
393
|
+
return defineTabsConfigFeature((cfg) => ({ ...cfg, addable }));
|
|
394
|
+
}
|
|
395
|
+
/** @internal - shared empty base, so label merges over an unset key memoize. */
|
|
396
|
+
const NO_LABELS = {};
|
|
397
|
+
/**
|
|
398
|
+
* Merge ARIA labels into the cascade. Keys not provided keep their
|
|
399
|
+
* library defaults; per-instance overrides on the tab group still win.
|
|
400
|
+
* Pass a `Signal` to switch the language at runtime.
|
|
722
401
|
*
|
|
723
|
-
*
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
402
|
+
* @category common/tabs
|
|
403
|
+
*/
|
|
404
|
+
function withTabsAriaLabels(labels) {
|
|
405
|
+
return defineTabsConfigFeature((cfg) => ({
|
|
406
|
+
...cfg,
|
|
407
|
+
ariaLabels: createOverrideMerge(cfg.ariaLabels ?? NO_LABELS, labels),
|
|
408
|
+
}));
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Merge the tablist / tab-panel `aria-roledescription` fallbacks into the
|
|
412
|
+
* cascade. Keys not provided keep their library defaults. Pass a `Signal`
|
|
413
|
+
* to switch the language at runtime.
|
|
730
414
|
*
|
|
731
|
-
* @category common/tabs
|
|
732
|
-
* @wcag AA
|
|
733
|
-
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/slots/tab-sub-label.directive.ts
|
|
734
|
-
* @since 0.1.0
|
|
735
|
-
* @relatedTo CngxTab, CngxTabLabel, CngxTabContent
|
|
736
|
-
* <example-url>http://localhost:4200/#/ui/tabs/tab-sub-label/label-with-count</example-url>
|
|
415
|
+
* @category common/tabs
|
|
737
416
|
*/
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
templateRef = inject((TemplateRef));
|
|
744
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabSubLabel, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
745
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxTabSubLabel, isStandalone: true, selector: "ng-template[cngxTabSubLabel]", exportAs: ["cngxTabSubLabel"], ngImport: i0 });
|
|
417
|
+
function withTabsFallbackLabels(labels) {
|
|
418
|
+
return defineTabsConfigFeature((cfg) => ({
|
|
419
|
+
...cfg,
|
|
420
|
+
fallbackLabels: createOverrideMerge(cfg.fallbackLabels ?? NO_LABELS, labels),
|
|
421
|
+
}));
|
|
746
422
|
}
|
|
747
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabSubLabel, decorators: [{
|
|
748
|
-
type: Directive,
|
|
749
|
-
args: [{
|
|
750
|
-
selector: 'ng-template[cngxTabSubLabel]',
|
|
751
|
-
exportAs: 'cngxTabSubLabel',
|
|
752
|
-
standalone: true,
|
|
753
|
-
}]
|
|
754
|
-
}] });
|
|
755
|
-
|
|
756
423
|
/**
|
|
757
|
-
*
|
|
758
|
-
*
|
|
759
|
-
* {@link CNGX_TAB_GROUP_HOST} on construction; deregisters via
|
|
760
|
-
* {@link DestroyRef} on teardown. \
|
|
761
|
-
* The presenter holds the atom's
|
|
762
|
-
* input signals by reference, so input changes propagate without
|
|
763
|
-
* re-registration. \
|
|
764
|
-
* `labelTemplate` / `contentTemplate` are projected
|
|
765
|
-
* by the organism - the atom carries no rendering logic.
|
|
424
|
+
* Override the IO-debounce window (ms). See
|
|
425
|
+
* {@link CngxTabsConfig.overflowStabilizeMs}.
|
|
766
426
|
*
|
|
767
|
-
* ```html
|
|
768
|
-
* <div cngxTab [label]="'Settings'">
|
|
769
|
-
* ... content templates here ...
|
|
770
|
-
* </div>
|
|
771
|
-
* ```
|
|
772
427
|
* @category common/tabs
|
|
773
|
-
* @docsKind primary
|
|
774
|
-
* @wcag AA
|
|
775
|
-
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/tab.directive.ts
|
|
776
|
-
* @since 0.1.0
|
|
777
|
-
* @relatedTo CngxTabGroupPresenter, CngxTabLabel, CngxTabContent, CngxTabErrorBadge
|
|
778
|
-
* @slot cngxTabLabel The tab's own header label.
|
|
779
|
-
* @slot cngxTabSubLabel Secondary line under the label, e.g. a count or status.
|
|
780
|
-
* @slot cngxTabContent The panel body, rendered lazily when the tab activates.
|
|
781
428
|
*/
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
* clear it. The aggregator stays the rich multi-source forms path; the
|
|
800
|
-
* two channels compose (either errors). Mirrors `CngxStep.error`.
|
|
801
|
-
*/
|
|
802
|
-
error = input(false, ...(ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []));
|
|
803
|
-
/**
|
|
804
|
-
* Resolved direct-error message: the `[error]` string when non-empty,
|
|
805
|
-
* else `undefined`. Carried onto the registration handle so the error
|
|
806
|
-
* badge slot can render it. `computed` over the input - never written.
|
|
807
|
-
*/
|
|
808
|
-
errorMessage = computed(() => {
|
|
809
|
-
const value = this.error();
|
|
810
|
-
return typeof value === 'string' && value !== '' ? value : undefined;
|
|
811
|
-
}, ...(ngDevMode ? [{ debugName: "errorMessage" }] : /* istanbul ignore next */ []));
|
|
812
|
-
/**
|
|
813
|
-
* Per-tab error fold driving the badge + SR descriptor. `true` when
|
|
814
|
-
* the direct `[error]` flag is set OR the optional aggregator wants to
|
|
815
|
-
* reveal (`shouldShow()` = `hasError` AND scope reveal-state). The
|
|
816
|
-
* aggregator arm reads `shouldShow`, not `hasError`, so deferred-reveal
|
|
817
|
-
* validation stays silent until revealed - the direct flag has no
|
|
818
|
-
* reveal concept (the consumer sets it when it wants it shown). A
|
|
819
|
-
* boolean, not a status enum: tabs carry no success/completed/disabled
|
|
820
|
-
* model (Pillar 3).
|
|
821
|
-
*/
|
|
822
|
-
hasError = computed(() => {
|
|
823
|
-
const directError = this.error();
|
|
824
|
-
return ((directError !== false && directError !== '') ||
|
|
825
|
-
(this.errorAggregator()?.shouldShow?.() ?? false));
|
|
826
|
-
}, { ...(ngDevMode ? { debugName: "hasError" } : /* istanbul ignore next */ {}), equal: Object.is });
|
|
827
|
-
/**
|
|
828
|
-
* Per-tab close-affordance override. `undefined` (default) inherits
|
|
829
|
-
* the group-level `[closable]` resolution; set `false` to pin this
|
|
830
|
-
* tab open inside a dismissable group, or `true` to make a single tab
|
|
831
|
-
* closable while the group default is off.
|
|
832
|
-
*/
|
|
833
|
-
closable = input(undefined, ...(ngDevMode ? [{ debugName: "closable" }] : /* istanbul ignore next */ []));
|
|
834
|
-
labelTemplate = contentChild(CngxTabLabel, ...(ngDevMode ? [{ debugName: "labelTemplate" }] : /* istanbul ignore next */ []));
|
|
835
|
-
subLabelTemplate = contentChild(CngxTabSubLabel, ...(ngDevMode ? [{ debugName: "subLabelTemplate" }] : /* istanbul ignore next */ []));
|
|
836
|
-
contentTemplate = contentChild(CngxTabContent, ...(ngDevMode ? [{ debugName: "contentTemplate" }] : /* istanbul ignore next */ []));
|
|
837
|
-
host = inject(CNGX_TAB_GROUP_HOST, { optional: true });
|
|
838
|
-
destroyRef = inject(DestroyRef);
|
|
839
|
-
/** `true` when the presenter's `activeId` equals this tab's id. */
|
|
840
|
-
selected = computed(() => this.host?.activeId() === this.id(), { ...(ngDevMode ? { debugName: "selected" } : /* istanbul ignore next */ {}), equal: Object.is });
|
|
841
|
-
constructor() {
|
|
842
|
-
if (!this.host) {
|
|
843
|
-
throw new Error('CngxTab: no enclosing CngxTabGroupPresenter found. Wrap the tab inside an element carrying [cngxTabGroup] (or place it inside <cngx-tab-group>).');
|
|
844
|
-
}
|
|
845
|
-
}
|
|
846
|
-
ngOnInit() {
|
|
847
|
-
// Register in ngOnInit, NOT the constructor: a dynamically-bound
|
|
848
|
-
// `[id]` (or `[label]`) signal input is not applied until the first
|
|
849
|
-
// change detection, so a constructor read would capture the default
|
|
850
|
-
// auto-id. The handle id is the stable key consumers map `(tabClose)`
|
|
851
|
-
// back to their data with, so it must reflect the bound `[id]`.
|
|
852
|
-
const host = this.host;
|
|
853
|
-
const tabId = this.id();
|
|
854
|
-
host.register({
|
|
855
|
-
id: tabId,
|
|
856
|
-
label: this.label,
|
|
857
|
-
subLabel: this.subLabel,
|
|
858
|
-
disabled: this.disabled,
|
|
859
|
-
errorAggregator: this.errorAggregator,
|
|
860
|
-
hasError: this.hasError,
|
|
861
|
-
errorMessage: this.errorMessage,
|
|
862
|
-
closable: this.closable,
|
|
863
|
-
});
|
|
864
|
-
this.destroyRef.onDestroy(() => host.unregister(tabId));
|
|
865
|
-
}
|
|
866
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTab, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
867
|
-
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 });
|
|
429
|
+
function withTabOverflowStabilizeMs(ms) {
|
|
430
|
+
return defineTabsConfigFeature((cfg) => ({
|
|
431
|
+
...cfg,
|
|
432
|
+
overflowStabilizeMs: ms,
|
|
433
|
+
}));
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Override the worst-case staleness ceiling on the visibility-map
|
|
437
|
+
* commit. See {@link CngxTabsConfig.overflowMaxDeferMs}.
|
|
438
|
+
*
|
|
439
|
+
* @category common/tabs
|
|
440
|
+
*/
|
|
441
|
+
function withTabOverflowMaxDeferMs(ms) {
|
|
442
|
+
return defineTabsConfigFeature((cfg) => ({
|
|
443
|
+
...cfg,
|
|
444
|
+
overflowMaxDeferMs: ms,
|
|
445
|
+
}));
|
|
868
446
|
}
|
|
869
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTab, decorators: [{
|
|
870
|
-
type: Directive,
|
|
871
|
-
args: [{
|
|
872
|
-
selector: '[cngxTab]',
|
|
873
|
-
exportAs: 'cngxTab',
|
|
874
|
-
standalone: true,
|
|
875
|
-
}]
|
|
876
|
-
}], 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 }] }] } });
|
|
877
|
-
|
|
878
|
-
const TABS_CONFIG_DEFAULTS = {
|
|
879
|
-
defaultOrientation: 'horizontal',
|
|
880
|
-
defaultLoop: true,
|
|
881
|
-
defaultCommitMode: 'optimistic',
|
|
882
|
-
fragmentSyncMode: 'fragment',
|
|
883
|
-
fragmentSyncParam: 'tab',
|
|
884
|
-
// routeMatch stays unset: the host-flavour default is the right answer
|
|
885
|
-
// for both organisms, and pinning one here would silently flip the
|
|
886
|
-
// other. linkAriaCurrent defaults at the link, not here.
|
|
887
|
-
linkAriaCurrent: 'page',
|
|
888
|
-
ariaLabels: {
|
|
889
|
-
tabsRegion: 'Tabs',
|
|
890
|
-
},
|
|
891
|
-
fallbackLabels: {
|
|
892
|
-
// W3C ARIA tablist convention - kept distinct from
|
|
893
|
-
// `i18n.tabsLabel` so AT doesn't read the same string twice
|
|
894
|
-
// back-to-back across `aria-roledescription` and `aria-label`.
|
|
895
|
-
tabRoleDescription: 'tab list',
|
|
896
|
-
tabPanelRoleDescription: 'tab panel',
|
|
897
|
-
},
|
|
898
|
-
overflowStabilizeMs: 100,
|
|
899
|
-
overflowMaxDeferMs: 250,
|
|
900
|
-
templates: {},
|
|
901
|
-
};
|
|
902
447
|
/**
|
|
903
|
-
*
|
|
904
|
-
*
|
|
905
|
-
*
|
|
448
|
+
* App-wide override for the More-button label. Middle tier; \
|
|
449
|
+
* per-instance `*cngxTabOverflowTrigger` still wins.
|
|
450
|
+
*
|
|
451
|
+
* ```ts
|
|
452
|
+
* readonly moreTrigger = viewChild.required<TemplateRef<CngxTabOverflowTriggerContext>>(
|
|
453
|
+
* 'moreTrigger',
|
|
454
|
+
* { read: TemplateRef },
|
|
455
|
+
* );
|
|
456
|
+
*
|
|
457
|
+
* providers: [provideTabsConfig(withTabOverflowTriggerTemplate(this.moreTrigger()))]
|
|
458
|
+
* ```
|
|
906
459
|
*
|
|
907
460
|
* @category common/tabs
|
|
908
|
-
* @wcag AA
|
|
909
|
-
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/tabs-config.ts
|
|
910
|
-
* @since 0.1.0
|
|
911
461
|
*/
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
}
|
|
462
|
+
function withTabOverflowTriggerTemplate(template) {
|
|
463
|
+
return defineTabsConfigFeature((cfg) => ({
|
|
464
|
+
...cfg,
|
|
465
|
+
templates: { ...cfg.templates, overflowTrigger: template },
|
|
466
|
+
}));
|
|
467
|
+
}
|
|
916
468
|
/**
|
|
917
|
-
*
|
|
918
|
-
* `
|
|
919
|
-
* Every `with*` config feature returns one
|
|
920
|
-
* of these.
|
|
469
|
+
* App-wide override for each row inside the overflow popover. \
|
|
470
|
+
* Middle tier; per-instance `*cngxTabOverflowItem` still wins.
|
|
921
471
|
*
|
|
922
|
-
* @
|
|
472
|
+
* @category common/tabs
|
|
923
473
|
*/
|
|
924
|
-
function
|
|
925
|
-
return
|
|
474
|
+
function withTabOverflowItemTemplate(template) {
|
|
475
|
+
return defineTabsConfigFeature((cfg) => ({
|
|
476
|
+
...cfg,
|
|
477
|
+
templates: { ...cfg.templates, overflowItem: template },
|
|
478
|
+
}));
|
|
926
479
|
}
|
|
927
480
|
/**
|
|
928
|
-
*
|
|
929
|
-
* still wins
|
|
481
|
+
* App-wide override for the error-badge decoration. Middle tier;
|
|
482
|
+
* per-instance `*cngxTabErrorBadge` still wins. Sibling of the
|
|
483
|
+
* stepper family's `withStepBadgeTemplate`.
|
|
930
484
|
*
|
|
931
485
|
* @category common/tabs
|
|
932
486
|
*/
|
|
933
|
-
function
|
|
487
|
+
function withTabErrorBadgeTemplate(template) {
|
|
934
488
|
return defineTabsConfigFeature((cfg) => ({
|
|
935
489
|
...cfg,
|
|
936
|
-
|
|
490
|
+
templates: { ...cfg.templates, errorBadge: template },
|
|
937
491
|
}));
|
|
938
492
|
}
|
|
939
493
|
/**
|
|
940
|
-
*
|
|
941
|
-
*
|
|
942
|
-
*
|
|
943
|
-
*
|
|
494
|
+
* App-wide override for the rejection-icon decoration. Middle
|
|
495
|
+
* tier; \
|
|
496
|
+
* per-instance `*cngxTabRejectionIcon` still wins. Sibling
|
|
497
|
+
* of {@link withStepRejectionTemplate}.
|
|
944
498
|
*
|
|
945
499
|
* @category common/tabs
|
|
946
500
|
*/
|
|
947
|
-
|
|
501
|
+
function withTabRejectionIconTemplate(template) {
|
|
502
|
+
return defineTabsConfigFeature((cfg) => ({
|
|
503
|
+
...cfg,
|
|
504
|
+
templates: { ...cfg.templates, rejectionIcon: template },
|
|
505
|
+
}));
|
|
506
|
+
}
|
|
948
507
|
/**
|
|
949
|
-
*
|
|
950
|
-
*
|
|
508
|
+
* App-wide override for the commit-pending busy-spinner overlay.
|
|
509
|
+
* Middle tier; per-instance `*cngxTabBusySpinner` still wins.
|
|
510
|
+
* Sibling of {@link withStepBusySpinnerTemplate}.
|
|
951
511
|
*
|
|
952
512
|
* @category common/tabs
|
|
953
513
|
*/
|
|
954
|
-
function
|
|
955
|
-
return defineTabsConfigFeature((cfg) => ({
|
|
514
|
+
function withTabBusySpinnerTemplate(template) {
|
|
515
|
+
return defineTabsConfigFeature((cfg) => ({
|
|
516
|
+
...cfg,
|
|
517
|
+
templates: { ...cfg.templates, busySpinner: template },
|
|
518
|
+
}));
|
|
956
519
|
}
|
|
957
520
|
/**
|
|
958
|
-
*
|
|
959
|
-
*
|
|
960
|
-
*
|
|
961
|
-
* `[commitMode]` Input still wins.
|
|
521
|
+
* App-wide override for the tab-icon slot. Middle tier of the 3-stage
|
|
522
|
+
* cascade; per-instance `*cngxTabIcon` still wins. Sibling of
|
|
523
|
+
* {@link withStepIndicatorTemplate}.
|
|
962
524
|
*
|
|
963
525
|
* @category common/tabs
|
|
964
526
|
*/
|
|
965
|
-
function
|
|
527
|
+
function withTabIconTemplate(template) {
|
|
966
528
|
return defineTabsConfigFeature((cfg) => ({
|
|
967
529
|
...cfg,
|
|
968
|
-
|
|
530
|
+
templates: { ...cfg.templates, icon: template },
|
|
969
531
|
}));
|
|
970
532
|
}
|
|
971
533
|
/**
|
|
972
|
-
*
|
|
973
|
-
*
|
|
974
|
-
* `mode` chooses the URL surface (URL fragment or query parameter); `param` names the key
|
|
975
|
-
* (default `'tab'`).
|
|
534
|
+
* App-wide override for a tab's close-button glyph. Middle tier;
|
|
535
|
+
* per-instance `*cngxTabCloseIcon` still wins.
|
|
976
536
|
*
|
|
977
|
-
*
|
|
978
|
-
|
|
537
|
+
* @category common/tabs
|
|
538
|
+
*/
|
|
539
|
+
function withTabCloseIconTemplate(template) {
|
|
540
|
+
return defineTabsConfigFeature((cfg) => ({
|
|
541
|
+
...cfg,
|
|
542
|
+
templates: { ...cfg.templates, closeIcon: template },
|
|
543
|
+
}));
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* App-wide override for the add-tab button glyph. Middle tier;
|
|
547
|
+
* per-instance `*cngxTabAddIcon` still wins.
|
|
979
548
|
*
|
|
980
549
|
* @category common/tabs
|
|
981
550
|
*/
|
|
982
|
-
function
|
|
551
|
+
function withTabAddIconTemplate(template) {
|
|
983
552
|
return defineTabsConfigFeature((cfg) => ({
|
|
984
553
|
...cfg,
|
|
985
|
-
|
|
986
|
-
fragmentSyncParam: param,
|
|
554
|
+
templates: { ...cfg.templates, addIcon: template },
|
|
987
555
|
}));
|
|
988
556
|
}
|
|
989
557
|
/**
|
|
990
|
-
*
|
|
991
|
-
*
|
|
992
|
-
|
|
558
|
+
* @internal The defaults with the copy keys read from the tabs section of
|
|
559
|
+
* the active language pack. Runs in an injection context.
|
|
560
|
+
*/
|
|
561
|
+
function tabsConfigDefaultsFromPack() {
|
|
562
|
+
const language = injectTabsLanguage();
|
|
563
|
+
return {
|
|
564
|
+
...TABS_CONFIG_DEFAULTS,
|
|
565
|
+
ariaLabels: computed(() => ({ tabsRegion: language().tabsRegion }), { equal: recordEqual }),
|
|
566
|
+
fallbackLabels: computed(() => ({
|
|
567
|
+
tabRoleDescription: language().tabRoleDescription,
|
|
568
|
+
tabPanelRoleDescription: language().tabPanelRoleDescription,
|
|
569
|
+
}), { equal: recordEqual }),
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
/** @internal Runs in an injection context; features apply on top of the pack. */
|
|
573
|
+
function resolveFeatures(features) {
|
|
574
|
+
return features.reduce((cfg, feat) => feat(cfg), tabsConfigDefaultsFromPack());
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* Root-level provider. Apply once in `bootstrapApplication` /
|
|
578
|
+
* `appConfig.providers`. Returns {@link EnvironmentProviders} per
|
|
579
|
+
* the canonical cngx config-cascade signature.
|
|
993
580
|
*
|
|
994
|
-
*
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
581
|
+
* @category common/tabs
|
|
582
|
+
*/
|
|
583
|
+
function provideTabsConfig(...features) {
|
|
584
|
+
return makeEnvironmentProviders([
|
|
585
|
+
{ provide: CNGX_TABS_CONFIG, useFactory: () => resolveFeatures(features) },
|
|
586
|
+
]);
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* Component-scoped override. Returns `Provider[]` (not
|
|
590
|
+
* {@link EnvironmentProviders}) because `viewProviders` rejects
|
|
591
|
+
* opaque environment providers. Resolution priority: per-instance
|
|
592
|
+
* Input > viewProviders (`At`) > root > default.
|
|
998
593
|
*
|
|
999
|
-
*
|
|
1000
|
-
* {
|
|
594
|
+
* ```ts
|
|
595
|
+
* @Component({
|
|
596
|
+
* viewProviders: [...provideTabsConfigAt(withTabsDefaultOrientation('vertical'))],
|
|
597
|
+
* })
|
|
598
|
+
* ```
|
|
1001
599
|
*
|
|
1002
600
|
* @category common/tabs
|
|
1003
601
|
*/
|
|
1004
|
-
function
|
|
1005
|
-
return
|
|
602
|
+
function provideTabsConfigAt(...features) {
|
|
603
|
+
return [{ provide: CNGX_TABS_CONFIG, useFactory: () => resolveFeatures(features) }];
|
|
1006
604
|
}
|
|
1007
605
|
/**
|
|
1008
|
-
*
|
|
1009
|
-
* Default `'page'`.
|
|
606
|
+
* Inject the resolved tabs config in an injection context.
|
|
1010
607
|
*
|
|
1011
|
-
*
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
608
|
+
* @category common/tabs
|
|
609
|
+
*/
|
|
610
|
+
function injectTabsConfig() {
|
|
611
|
+
return inject(CNGX_TABS_CONFIG);
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* Wraps a {@link CngxCommitController} with the action-shape adapter
|
|
616
|
+
* that collapses `Observable<boolean>` / `Promise<boolean>` /
|
|
617
|
+
* `boolean` returns into a single `accept: boolean` outcome.
|
|
1017
618
|
*
|
|
1018
619
|
* @category common/tabs
|
|
1019
620
|
*/
|
|
1020
|
-
function
|
|
1021
|
-
|
|
621
|
+
function createTabsCommitHandler(opts) {
|
|
622
|
+
const { controller } = opts;
|
|
623
|
+
return {
|
|
624
|
+
isCommitting: controller.isCommitting,
|
|
625
|
+
beginTransition(fromIndex, toIndex, action, onResolve) {
|
|
626
|
+
controller.begin((handlers) => runTabsAction(action, fromIndex, toIndex, handlers), toIndex, fromIndex, {
|
|
627
|
+
onSuccess: () => onResolve(true),
|
|
628
|
+
onError: () => onResolve(false),
|
|
629
|
+
});
|
|
630
|
+
},
|
|
631
|
+
cancel() {
|
|
632
|
+
controller.cancel();
|
|
633
|
+
},
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
function runTabsAction(action, fromIndex, toIndex, handlers) {
|
|
637
|
+
let cancelled = false;
|
|
638
|
+
let unsubscribe = null;
|
|
639
|
+
const safeSuccess = (accept) => {
|
|
640
|
+
if (cancelled) {
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
643
|
+
if (accept) {
|
|
644
|
+
handlers.onSuccess(toIndex);
|
|
645
|
+
}
|
|
646
|
+
else {
|
|
647
|
+
handlers.onError(new Error('Tab transition refused by commitAction'));
|
|
648
|
+
}
|
|
649
|
+
};
|
|
650
|
+
const safeError = (err) => {
|
|
651
|
+
if (cancelled) {
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
handlers.onError(err);
|
|
655
|
+
};
|
|
656
|
+
let result;
|
|
657
|
+
try {
|
|
658
|
+
result = action(fromIndex, toIndex);
|
|
659
|
+
}
|
|
660
|
+
catch (err) {
|
|
661
|
+
safeError(err);
|
|
662
|
+
return {
|
|
663
|
+
cancel: () => {
|
|
664
|
+
cancelled = true;
|
|
665
|
+
},
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
if (isObservable(result)) {
|
|
669
|
+
// Synchronous Observables (`of(true)`) emit inside `.subscribe` before
|
|
670
|
+
// the assignment binds - close over a pre-declared `let` to avoid TDZ.
|
|
671
|
+
let sub = null;
|
|
672
|
+
let done = false;
|
|
673
|
+
sub = result.subscribe({
|
|
674
|
+
next: (accept) => {
|
|
675
|
+
if (done) {
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
678
|
+
// Done-latch, not just unsubscribe: a synchronous emission fires
|
|
679
|
+
// while `sub` is still null, so a non-completing source would
|
|
680
|
+
// otherwise stay live and re-resolve on its next emission.
|
|
681
|
+
done = true;
|
|
682
|
+
safeSuccess(accept);
|
|
683
|
+
sub?.unsubscribe();
|
|
684
|
+
},
|
|
685
|
+
error: (err) => {
|
|
686
|
+
if (done) {
|
|
687
|
+
return;
|
|
688
|
+
}
|
|
689
|
+
safeError(err);
|
|
690
|
+
},
|
|
691
|
+
complete: () => {
|
|
692
|
+
// EMPTY-style sources complete without emitting; without this arm
|
|
693
|
+
// the commit stays 'pending' forever and busy() latches true.
|
|
694
|
+
if (!done) {
|
|
695
|
+
safeError(new Error('Tabs commitAction completed without emitting'));
|
|
696
|
+
}
|
|
697
|
+
},
|
|
698
|
+
});
|
|
699
|
+
if (done) {
|
|
700
|
+
// The in-next unsubscribe was a no-op for a sync emission; close
|
|
701
|
+
// the still-live subscription now that `sub` is bound.
|
|
702
|
+
sub.unsubscribe();
|
|
703
|
+
}
|
|
704
|
+
unsubscribe = () => sub?.unsubscribe();
|
|
705
|
+
}
|
|
706
|
+
else if (result != null && typeof result.then === 'function') {
|
|
707
|
+
result.then(safeSuccess, safeError);
|
|
708
|
+
}
|
|
709
|
+
else {
|
|
710
|
+
safeSuccess(result);
|
|
711
|
+
}
|
|
712
|
+
return {
|
|
713
|
+
cancel: () => {
|
|
714
|
+
cancelled = true;
|
|
715
|
+
unsubscribe?.();
|
|
716
|
+
},
|
|
717
|
+
};
|
|
1022
718
|
}
|
|
1023
719
|
/**
|
|
1024
|
-
*
|
|
1025
|
-
*
|
|
1026
|
-
*
|
|
1027
|
-
*
|
|
1028
|
-
*
|
|
1029
|
-
* @category common/tabs
|
|
1030
|
-
*/
|
|
1031
|
-
const withTabsRouterSync = withTabsFragmentSync;
|
|
1032
|
-
/**
|
|
1033
|
-
* Select the app-wide default visual skin for `<cngx-tab-group>`. \
|
|
1034
|
-
* Default `'line'`. Per-instance `[skin]` Input still wins; this moves
|
|
1035
|
-
* the cascade default. Structure, slots, ARIA, and keyboard behaviour
|
|
1036
|
-
* are identical across skins - only the `[data-skin]` host attribute
|
|
1037
|
-
* changes the CSS layer. The Material twin (`[cngxMatTabs]`) ignores it.
|
|
720
|
+
* DI token for the commit-handler factory. \
|
|
721
|
+
* Defaults to {@link createTabsCommitHandler}. \
|
|
722
|
+
* Sibling to
|
|
723
|
+
* - `CNGX_ARRAY_COMMIT_HANDLER_FACTORY` (select) and
|
|
724
|
+
* - `CNGX_STEPPER_COMMIT_HANDLER_FACTORY`.
|
|
1038
725
|
*
|
|
1039
726
|
* @category common/tabs
|
|
727
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/commit-handler.ts
|
|
728
|
+
* @since 0.1.0
|
|
1040
729
|
*/
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
730
|
+
const CNGX_TABS_COMMIT_HANDLER_FACTORY = new InjectionToken('CngxTabsCommitHandlerFactory', {
|
|
731
|
+
providedIn: 'root',
|
|
732
|
+
factory: () => createTabsCommitHandler,
|
|
733
|
+
});
|
|
734
|
+
|
|
1044
735
|
/**
|
|
1045
|
-
*
|
|
1046
|
-
*
|
|
1047
|
-
*
|
|
1048
|
-
*
|
|
736
|
+
* DI token for the tab presenter's contract. \
|
|
737
|
+
* Presenter provides via `useExisting`; `CngxTab` injects to register; the organism injects
|
|
738
|
+
* to drive the APG tablist keyboard model (automatic activation via
|
|
739
|
+
* `select()`, roving stop derived from `activeId`) through
|
|
740
|
+
* `createTabKeyboardNav`.
|
|
1049
741
|
*
|
|
1050
742
|
* @category common/tabs
|
|
743
|
+
* @wcag AA
|
|
744
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/tab-group-host.token.ts
|
|
745
|
+
* @since 0.1.0
|
|
1051
746
|
*/
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
}
|
|
747
|
+
const CNGX_TAB_GROUP_HOST = new InjectionToken('CngxTabGroupHost');
|
|
748
|
+
|
|
1055
749
|
/**
|
|
1056
|
-
*
|
|
1057
|
-
*
|
|
1058
|
-
*
|
|
1059
|
-
*
|
|
1060
|
-
*
|
|
1061
|
-
*
|
|
1062
|
-
*
|
|
1063
|
-
* Under `'lazy'`, a deep link mounts only the panel it names: both sync
|
|
1064
|
-
* directives seed the active tab before the first panel render.
|
|
750
|
+
* Tab-group presenter - brain of every CNGX tab flow. \
|
|
751
|
+
* Owns the active-index model, the tab registry, orientation, loop policy,
|
|
752
|
+
* and the commit-controller lifecycle. \
|
|
753
|
+
* Provides {@link CNGX_TAB_GROUP_HOST} for atoms and {@link CNGX_STATEFUL}
|
|
754
|
+
* so `<cngx-toast-on />` / `<cngx-banner-on />` compose without
|
|
755
|
+
* `[state]` wiring.
|
|
1065
756
|
*
|
|
1066
|
-
*
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
return defineTabsConfigFeature((cfg) => ({ ...cfg, panelMode: mode }));
|
|
1070
|
-
}
|
|
1071
|
-
/**
|
|
1072
|
-
* Set the app-wide default for stretching tabs to the full strip width
|
|
1073
|
-
* (horizontal only). \
|
|
1074
|
-
* Default `false`. Per-instance `[fitted]` Input still
|
|
1075
|
-
* wins. No effect under `orientation="vertical"`.
|
|
757
|
+
* **Layer:** `@cngx/common/tabs`. \
|
|
758
|
+
* Directive-only - organisms compose via `hostDirectives`, consumers attach
|
|
759
|
+
* `[cngxTabGroup]` directly.
|
|
1076
760
|
*
|
|
1077
761
|
* @category common/tabs
|
|
762
|
+
* @docsKind primary
|
|
763
|
+
* @wcag AA
|
|
764
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/presenter.directive.ts
|
|
765
|
+
* @since 0.1.0
|
|
766
|
+
* @relatedTo CngxTab, CngxTabContent, CngxTabLabel, CngxTabsFragmentSync
|
|
767
|
+
* <example-url>http://localhost:4200/#/ui/tabs/tab-commit-action/optimistic-pessimistic-commits-with-bridge-directives</example-url>
|
|
1078
768
|
*/
|
|
1079
|
-
|
|
1080
|
-
|
|
769
|
+
class CngxTabGroupPresenter {
|
|
770
|
+
config = injectTabsConfig();
|
|
771
|
+
activeIndex = model(0, ...(ngDevMode ? [{ debugName: "activeIndex" }] : /* istanbul ignore next */ []));
|
|
772
|
+
/**
|
|
773
|
+
* @internal Two-field alias - bind the public `[orientation]`; read
|
|
774
|
+
* the resolved {@link orientation} computed (input ?? config ?? default).
|
|
775
|
+
*/
|
|
776
|
+
orientationInput = input(undefined, { ...(ngDevMode ? { debugName: "orientationInput" } : /* istanbul ignore next */ {}), alias: 'orientation' });
|
|
777
|
+
orientation = computed(() => this.orientationInput() ?? this.config.defaultOrientation ?? 'horizontal', ...(ngDevMode ? [{ debugName: "orientation" }] : /* istanbul ignore next */ []));
|
|
778
|
+
/**
|
|
779
|
+
* @internal Two-field alias - bind the public `[loop]`; read the
|
|
780
|
+
* resolved {@link loop} computed (input ?? config ?? default).
|
|
781
|
+
*/
|
|
782
|
+
loopInput = input(undefined, { ...(ngDevMode ? { debugName: "loopInput" } : /* istanbul ignore next */ {}), alias: 'loop' });
|
|
783
|
+
loop = computed(() => this.loopInput() ?? this.config.defaultLoop ?? true, ...(ngDevMode ? [{ debugName: "loop" }] : /* istanbul ignore next */ []));
|
|
784
|
+
/**
|
|
785
|
+
* Async-commit action gating the transition.
|
|
786
|
+
* When non-null, `select(...)` routes through {@link CngxTabsCommitHandler}; the
|
|
787
|
+
* action's resolution decides whether the change lands. Supersede
|
|
788
|
+
* semantics come from the commit-controller - a rapid second
|
|
789
|
+
* `select(...)` cancels the in-flight runner.
|
|
790
|
+
*
|
|
791
|
+
* @internal Two-field alias - bind the public `[commitAction]`; read
|
|
792
|
+
* the resolved {@link commitAction} computed (input ?? DI fallback).
|
|
793
|
+
*/
|
|
794
|
+
commitActionInput = input(null, { ...(ngDevMode ? { debugName: "commitActionInput" } : /* istanbul ignore next */ {}), alias: 'commitAction' });
|
|
795
|
+
/**
|
|
796
|
+
* Default `'optimistic'` - tab change is navigation, not a save,
|
|
797
|
+
* so eager visual feedback matches the user's mental model.
|
|
798
|
+
* Switch to `'pessimistic'` when the new tab must wait for the
|
|
799
|
+
* action to confirm.
|
|
800
|
+
*
|
|
801
|
+
* @internal Two-field alias - bind the public `[commitMode]`; read
|
|
802
|
+
* the resolved {@link commitMode} computed (DI fallback mode wins
|
|
803
|
+
* when a routed action is active, else input ?? config ?? default).
|
|
804
|
+
*/
|
|
805
|
+
commitModeInput = input(undefined, { ...(ngDevMode ? { debugName: "commitModeInput" } : /* istanbul ignore next */ {}), alias: 'commitMode' });
|
|
806
|
+
injector = inject(Injector);
|
|
807
|
+
// Resolved lazily, never in a field initialiser: a sync directive
|
|
808
|
+
// (e.g. [cngxTabsRouteSync]) provides CNGX_TABS_COMMIT_ACTION via
|
|
809
|
+
// useExisting and itself injects this presenter as its host, so
|
|
810
|
+
// eager injection here would close a construction cycle (NG0200).
|
|
811
|
+
// First read happens at select()/template time - after both
|
|
812
|
+
// directives exist. The source is static per element, so memoising
|
|
813
|
+
// the resolution is safe.
|
|
814
|
+
injectedActionSource;
|
|
815
|
+
resolveInjectedAction() {
|
|
816
|
+
if (this.injectedActionSource === undefined) {
|
|
817
|
+
this.injectedActionSource = this.injector.get(CNGX_TABS_COMMIT_ACTION, null);
|
|
818
|
+
}
|
|
819
|
+
return this.injectedActionSource;
|
|
820
|
+
}
|
|
821
|
+
/**
|
|
822
|
+
* Resolved commit-action: the `[commitAction]` input when bound, else
|
|
823
|
+
* the {@link CNGX_TABS_COMMIT_ACTION} DI fallback (routed path), else
|
|
824
|
+
* `null`. `select()` reads this.
|
|
825
|
+
*/
|
|
826
|
+
commitAction = computed(() => this.commitActionInput() ?? this.resolveInjectedAction()?.action() ?? null, ...(ngDevMode ? [{ debugName: "commitAction" }] : /* istanbul ignore next */ []));
|
|
827
|
+
/**
|
|
828
|
+
* Resolved commit mode. When the DI fallback supplies an active
|
|
829
|
+
* action its `mode` wins - the routed path pins `'pessimistic'` so a
|
|
830
|
+
* stray `[commitMode]="'optimistic'"` cannot break the
|
|
831
|
+
* route-follows-resolution invariant. Otherwise the `[commitMode]`
|
|
832
|
+
* input drives.
|
|
833
|
+
*/
|
|
834
|
+
commitMode = computed(() => {
|
|
835
|
+
const source = this.resolveInjectedAction();
|
|
836
|
+
if (source?.action()) {
|
|
837
|
+
return source.mode();
|
|
838
|
+
}
|
|
839
|
+
return this.commitModeInput() ?? this.config.defaultCommitMode ?? 'optimistic';
|
|
840
|
+
}, ...(ngDevMode ? [{ debugName: "commitMode" }] : /* istanbul ignore next */ []));
|
|
841
|
+
/**
|
|
842
|
+
* Emitted when a tab's close affordance is activated (the close
|
|
843
|
+
* button or Delete on the focused tab). The presenter has
|
|
844
|
+
* already moved the active index onto the surviving neighbour; the
|
|
845
|
+
* consumer removes the tab from its own data in the handler.
|
|
846
|
+
*/
|
|
847
|
+
tabClose = output();
|
|
848
|
+
/**
|
|
849
|
+
* Emitted when the add-tab affordance is activated. The consumer
|
|
850
|
+
* appends a tab to its own data; the presenter owns no creation logic.
|
|
851
|
+
*/
|
|
852
|
+
tabAdd = output();
|
|
853
|
+
genericFactory = inject(CNGX_COMMIT_CONTROLLER_FACTORY);
|
|
854
|
+
commitController = this.genericFactory();
|
|
855
|
+
commitHandler = inject(CNGX_TABS_COMMIT_HANDLER_FACTORY)({
|
|
856
|
+
controller: this.commitController,
|
|
857
|
+
});
|
|
858
|
+
/** Producer surface for the `CNGX_STATEFUL` bridge contract. */
|
|
859
|
+
state = this.commitController.state;
|
|
860
|
+
commitState = this.commitController.state;
|
|
861
|
+
/**
|
|
862
|
+
* Index the user is currently trying to commit to. Tracked
|
|
863
|
+
* separately from `state.data()` (which only updates on success)
|
|
864
|
+
* to drive per-tab `aria-busy`.
|
|
865
|
+
*/
|
|
866
|
+
intendedIndex = this.commitController.intendedValue;
|
|
867
|
+
/**
|
|
868
|
+
* Current/previous pair for `commitState.status()`. Skin
|
|
869
|
+
* sub-components feed `<span cngxLiveRegion>` from this tracker
|
|
870
|
+
* for declarative SR announcements. Shared across consumers so
|
|
871
|
+
* the tracker's `linkedSignal` is allocated once per presenter.
|
|
872
|
+
*/
|
|
873
|
+
commitTransition = createTransitionTracker(() => this.commitController.state.status());
|
|
874
|
+
// Persistence-of-error surface - see `CngxTabGroupHost.lastFailedIndex`
|
|
875
|
+
// and `originIndexDuringCommit` for the contract.
|
|
876
|
+
lastFailedIndexState = signal(undefined, ...(ngDevMode ? [{ debugName: "lastFailedIndexState" }] : /* istanbul ignore next */ []));
|
|
877
|
+
originIndexDuringCommitState = signal(undefined, ...(ngDevMode ? [{ debugName: "originIndexDuringCommitState" }] : /* istanbul ignore next */ []));
|
|
878
|
+
/** {@inheritDoc CngxTabGroupHost.lastFailedIndex} */
|
|
879
|
+
lastFailedIndex = this.lastFailedIndexState.asReadonly();
|
|
880
|
+
/** {@inheritDoc CngxTabGroupHost.originIndexDuringCommit} */
|
|
881
|
+
originIndexDuringCommit = this.originIndexDuringCommitState.asReadonly();
|
|
882
|
+
tabsState = signal([], { ...(ngDevMode ? { debugName: "tabsState" } : /* istanbul ignore next */ {}), equal: tabsEqual });
|
|
883
|
+
tabs = this.tabsState.asReadonly();
|
|
884
|
+
clampedIndex = computed(() => {
|
|
885
|
+
const count = this.tabs().length;
|
|
886
|
+
if (count === 0) {
|
|
887
|
+
return 0;
|
|
888
|
+
}
|
|
889
|
+
return Math.max(0, Math.min(this.activeIndex(), count - 1));
|
|
890
|
+
}, ...(ngDevMode ? [{ debugName: "clampedIndex" }] : /* istanbul ignore next */ []));
|
|
891
|
+
activeId = computed(() => this.tabs()[this.clampedIndex()]?.id ?? null, { ...(ngDevMode ? { debugName: "activeId" } : /* istanbul ignore next */ {}), equal: Object.is });
|
|
892
|
+
register(handle) {
|
|
893
|
+
const current = this.tabsState();
|
|
894
|
+
const idx = current.findIndex((h) => h.id === handle.id);
|
|
895
|
+
if (idx >= 0) {
|
|
896
|
+
const next = current.slice();
|
|
897
|
+
next[idx] = handle;
|
|
898
|
+
this.tabsState.set(next);
|
|
899
|
+
return;
|
|
900
|
+
}
|
|
901
|
+
this.tabsState.set([...current, handle]);
|
|
902
|
+
}
|
|
903
|
+
unregister(id, handle) {
|
|
904
|
+
const current = this.tabsState();
|
|
905
|
+
const entry = current.find((h) => h.id === id);
|
|
906
|
+
if (entry === undefined) {
|
|
907
|
+
return;
|
|
908
|
+
}
|
|
909
|
+
// Instance guard: after an idempotent re-register replaced the stored
|
|
910
|
+
// handle, the superseded instance's destroy is a no-op.
|
|
911
|
+
if (handle !== undefined && entry !== handle) {
|
|
912
|
+
return;
|
|
913
|
+
}
|
|
914
|
+
this.tabsState.set(current.filter((h) => h !== entry));
|
|
915
|
+
}
|
|
916
|
+
/** {@inheritDoc CngxTabGroupHost.clearLastFailed} */
|
|
917
|
+
clearLastFailed() {
|
|
918
|
+
this.lastFailedIndexState.set(undefined);
|
|
919
|
+
}
|
|
920
|
+
select(index) {
|
|
921
|
+
const tabs = this.tabs();
|
|
922
|
+
if (tabs.length === 0) {
|
|
923
|
+
return;
|
|
924
|
+
}
|
|
925
|
+
const target = Math.max(0, Math.min(index, tabs.length - 1));
|
|
926
|
+
if (tabs[target].disabled()) {
|
|
927
|
+
return;
|
|
928
|
+
}
|
|
929
|
+
const previous = this.activeIndex();
|
|
930
|
+
if (target === previous) {
|
|
931
|
+
return;
|
|
932
|
+
}
|
|
933
|
+
const action = this.commitAction();
|
|
934
|
+
if (!action) {
|
|
935
|
+
// No-action fast path - `originIndexDuringCommit` stays
|
|
936
|
+
// untouched, so a stale origin can never leak into the
|
|
937
|
+
// live-region announcement.
|
|
938
|
+
this.activeIndex.set(target);
|
|
939
|
+
if (this.lastFailedIndexState() === target) {
|
|
940
|
+
this.lastFailedIndexState.set(undefined);
|
|
941
|
+
}
|
|
942
|
+
return;
|
|
943
|
+
}
|
|
944
|
+
// Open the commit window - origin is captured ONLY here so a
|
|
945
|
+
// stale value never lingers into a non-commit navigation.
|
|
946
|
+
this.originIndexDuringCommitState.set(previous);
|
|
947
|
+
const mode = this.commitMode();
|
|
948
|
+
if (mode === 'optimistic') {
|
|
949
|
+
this.activeIndex.set(target);
|
|
950
|
+
}
|
|
951
|
+
this.commitHandler.beginTransition(previous, target, action, (accept) => {
|
|
952
|
+
if (accept) {
|
|
953
|
+
// Window closes on success - origin label no longer needed;
|
|
954
|
+
// clear the rejection flag if the user re-picked the failed
|
|
955
|
+
// target successfully.
|
|
956
|
+
this.originIndexDuringCommitState.set(undefined);
|
|
957
|
+
if (this.lastFailedIndexState() === target) {
|
|
958
|
+
this.lastFailedIndexState.set(undefined);
|
|
959
|
+
}
|
|
960
|
+
if (mode === 'pessimistic') {
|
|
961
|
+
this.activeIndex.set(target);
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
else {
|
|
965
|
+
// Reject - flag the refused target; RETAIN the origin so
|
|
966
|
+
// the organism's `liveAnnouncement` computed can resolve
|
|
967
|
+
// the origin label for the rich rollback phrase. Optimistic
|
|
968
|
+
// rolls back; pessimistic never moved.
|
|
969
|
+
this.lastFailedIndexState.set(target);
|
|
970
|
+
if (mode === 'optimistic') {
|
|
971
|
+
this.activeIndex.set(previous);
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
});
|
|
975
|
+
}
|
|
976
|
+
selectNext() {
|
|
977
|
+
const tabs = this.tabs();
|
|
978
|
+
if (tabs.length === 0) {
|
|
979
|
+
return;
|
|
980
|
+
}
|
|
981
|
+
let next = this.activeIndex() + 1;
|
|
982
|
+
while (next < tabs.length && tabs[next].disabled()) {
|
|
983
|
+
next++;
|
|
984
|
+
}
|
|
985
|
+
if (next < tabs.length) {
|
|
986
|
+
this.select(next);
|
|
987
|
+
return;
|
|
988
|
+
}
|
|
989
|
+
if (this.loop()) {
|
|
990
|
+
let i = 0;
|
|
991
|
+
while (i < tabs.length && tabs[i].disabled()) {
|
|
992
|
+
i++;
|
|
993
|
+
}
|
|
994
|
+
if (i < tabs.length && i !== this.activeIndex()) {
|
|
995
|
+
this.select(i);
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
selectPrevious() {
|
|
1000
|
+
const tabs = this.tabs();
|
|
1001
|
+
if (tabs.length === 0) {
|
|
1002
|
+
return;
|
|
1003
|
+
}
|
|
1004
|
+
let prev = this.activeIndex() - 1;
|
|
1005
|
+
while (prev >= 0 && tabs[prev].disabled()) {
|
|
1006
|
+
prev--;
|
|
1007
|
+
}
|
|
1008
|
+
if (prev >= 0) {
|
|
1009
|
+
this.select(prev);
|
|
1010
|
+
return;
|
|
1011
|
+
}
|
|
1012
|
+
if (this.loop()) {
|
|
1013
|
+
let i = tabs.length - 1;
|
|
1014
|
+
while (i >= 0 && tabs[i].disabled()) {
|
|
1015
|
+
i--;
|
|
1016
|
+
}
|
|
1017
|
+
if (i >= 0 && i !== this.activeIndex()) {
|
|
1018
|
+
this.select(i);
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
selectById(id) {
|
|
1023
|
+
const tabs = this.tabs();
|
|
1024
|
+
const idx = tabs.findIndex((h) => h.id === id);
|
|
1025
|
+
if (idx >= 0) {
|
|
1026
|
+
this.select(idx);
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
requestClose(id) {
|
|
1030
|
+
const tabs = this.tabs();
|
|
1031
|
+
const index = tabs.findIndex((h) => h.id === id);
|
|
1032
|
+
if (index < 0) {
|
|
1033
|
+
return;
|
|
1034
|
+
}
|
|
1035
|
+
const active = this.clampedIndex();
|
|
1036
|
+
// Closing a tab BEFORE the active one needs a pre-emptive index
|
|
1037
|
+
// shift: the active tab moves down one slot once the consumer
|
|
1038
|
+
// removes the closed tab, so decrement to keep the same tab active.
|
|
1039
|
+
// Closing the active tab mid-strip (or one after the active) needs
|
|
1040
|
+
// no write - `clampedIndex` re-derives against the shorter array
|
|
1041
|
+
// and lands on the next tab.
|
|
1042
|
+
if (index < active) {
|
|
1043
|
+
this.activeIndex.set(active - 1);
|
|
1044
|
+
}
|
|
1045
|
+
else if (index === active && index === tabs.length - 1 && index > 0) {
|
|
1046
|
+
// Closing the ACTIVE LAST tab: the derived clamp would land on the
|
|
1047
|
+
// new last, but the [(activeIndex)] model itself would keep the
|
|
1048
|
+
// now out-of-range value - clamp-write so two-way consumers see
|
|
1049
|
+
// the real position.
|
|
1050
|
+
this.activeIndex.set(index - 1);
|
|
1051
|
+
}
|
|
1052
|
+
// The rejection markers are flat indices into the same registry, so a
|
|
1053
|
+
// close before them drifts the decoration onto the wrong tab (reachable
|
|
1054
|
+
// only via the dismissable affordance the organism layers on top). Shift
|
|
1055
|
+
// them the same way `activeIndex` shifts, and drop the marker outright
|
|
1056
|
+
// when its own tab is the one closed.
|
|
1057
|
+
this.lastFailedIndexState.update((failed) => shiftIndexOnClose(failed, index));
|
|
1058
|
+
this.originIndexDuringCommitState.update((origin) => shiftIndexOnClose(origin, index));
|
|
1059
|
+
this.tabClose.emit({ id, index });
|
|
1060
|
+
}
|
|
1061
|
+
requestAdd() {
|
|
1062
|
+
this.tabAdd.emit();
|
|
1063
|
+
}
|
|
1064
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabGroupPresenter, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1065
|
+
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 }, orientationInput: { classPropertyName: "orientationInput", publicName: "orientation", isSignal: true, isRequired: false, transformFunction: null }, loopInput: { classPropertyName: "loopInput", 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: [
|
|
1066
|
+
{ provide: CNGX_TAB_GROUP_HOST, useExisting: CngxTabGroupPresenter },
|
|
1067
|
+
{ provide: CNGX_STATEFUL, useExisting: CngxTabGroupPresenter },
|
|
1068
|
+
], exportAs: ["cngxTabGroup"], ngImport: i0 });
|
|
1081
1069
|
}
|
|
1070
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabGroupPresenter, decorators: [{
|
|
1071
|
+
type: Directive,
|
|
1072
|
+
args: [{
|
|
1073
|
+
selector: '[cngxTabGroup]',
|
|
1074
|
+
exportAs: 'cngxTabGroup',
|
|
1075
|
+
standalone: true,
|
|
1076
|
+
providers: [
|
|
1077
|
+
{ provide: CNGX_TAB_GROUP_HOST, useExisting: CngxTabGroupPresenter },
|
|
1078
|
+
{ provide: CNGX_STATEFUL, useExisting: CngxTabGroupPresenter },
|
|
1079
|
+
],
|
|
1080
|
+
}]
|
|
1081
|
+
}], propDecorators: { activeIndex: [{ type: i0.Input, args: [{ isSignal: true, alias: "activeIndex", required: false }] }, { type: i0.Output, args: ["activeIndexChange"] }], orientationInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "orientation", required: false }] }], loopInput: [{ 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"] }] } });
|
|
1082
1082
|
/**
|
|
1083
|
-
*
|
|
1084
|
-
*
|
|
1085
|
-
*
|
|
1083
|
+
* Follow a stored flat rejection index across the removal of the tab at
|
|
1084
|
+
* `removed`. The referenced tab going away drops the marker (`undefined`);
|
|
1085
|
+
* a removal ahead of it shifts it down one slot; a removal after it leaves
|
|
1086
|
+
* it put. Keeps `lastFailedIndex` / `originIndexDuringCommit` pointing at the
|
|
1087
|
+
* same handle once the consumer removes a dismissed tab from its data.
|
|
1086
1088
|
*
|
|
1087
|
-
* @
|
|
1089
|
+
* @internal
|
|
1088
1090
|
*/
|
|
1089
|
-
function
|
|
1090
|
-
|
|
1091
|
+
function shiftIndexOnClose(stored, removed) {
|
|
1092
|
+
if (stored === undefined || removed === stored) {
|
|
1093
|
+
return undefined;
|
|
1094
|
+
}
|
|
1095
|
+
return removed < stored ? stored - 1 : stored;
|
|
1091
1096
|
}
|
|
1092
1097
|
/**
|
|
1093
|
-
*
|
|
1094
|
-
*
|
|
1095
|
-
*
|
|
1098
|
+
* Registry equality for the tab registry signal: element-wise reference
|
|
1099
|
+
* identity, not structural comparison. Two arrays are equal only when
|
|
1100
|
+
* they carry the exact same handle instances in the same order.
|
|
1096
1101
|
*
|
|
1097
|
-
*
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
*
|
|
1104
|
-
*
|
|
1105
|
-
*
|
|
1102
|
+
* Handles are stable per-tab references - `label`, `disabled`,
|
|
1103
|
+
* `hasError` and friends propagate through the handle's signals, so
|
|
1104
|
+
* consumers update off the handle without the registry array
|
|
1105
|
+
* re-emitting, and value comparison here would be redundant for an
|
|
1106
|
+
* unchanged handle. For a REPLACED handle (idempotent re-register
|
|
1107
|
+
* under an id collision) a value compare is actively wrong: it reports
|
|
1108
|
+
* the value-identical new instance as equal, discards the write, and
|
|
1109
|
+
* leaves the registry serving the destroyed instance's signals.
|
|
1110
|
+
* Reference inequality is the change signal.
|
|
1106
1111
|
*
|
|
1107
|
-
* @
|
|
1112
|
+
* @internal
|
|
1108
1113
|
*/
|
|
1109
|
-
function
|
|
1110
|
-
|
|
1114
|
+
function tabsEqual(a, b) {
|
|
1115
|
+
if (a === b) {
|
|
1116
|
+
return true;
|
|
1117
|
+
}
|
|
1118
|
+
if (a.length !== b.length) {
|
|
1119
|
+
return false;
|
|
1120
|
+
}
|
|
1121
|
+
for (let i = 0; i < a.length; i++) {
|
|
1122
|
+
if (a[i] !== b[i]) {
|
|
1123
|
+
return false;
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
return true;
|
|
1111
1127
|
}
|
|
1128
|
+
|
|
1112
1129
|
/**
|
|
1113
|
-
*
|
|
1114
|
-
*
|
|
1130
|
+
* DI token the organism provides via `useExisting`.\
|
|
1131
|
+
* The overflow molecule and consumer-authored skin sub-components inject this
|
|
1132
|
+
* instead of the concrete component class.
|
|
1115
1133
|
*
|
|
1116
1134
|
* @category common/tabs
|
|
1135
|
+
* @wcag AA
|
|
1136
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/tab-panel-host.token.ts
|
|
1137
|
+
* @since 0.1.0
|
|
1117
1138
|
*/
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
...cfg,
|
|
1121
|
-
ariaLabels: { ...cfg.ariaLabels, ...labels },
|
|
1122
|
-
}));
|
|
1123
|
-
}
|
|
1139
|
+
const CNGX_TAB_PANEL_HOST = new InjectionToken('CngxTabPanelHost');
|
|
1140
|
+
|
|
1124
1141
|
/**
|
|
1125
|
-
*
|
|
1126
|
-
*
|
|
1142
|
+
* Marks a tab presenter as the **navigation** flavour rather than the
|
|
1143
|
+
* tablist flavour. \
|
|
1144
|
+
* Provided by `<cngx-tab-nav>` (`@cngx/ui/tabs`) and `[cngxMatTabNav]`
|
|
1145
|
+
* (`@cngx/ui/mat-tabs`); deliberately not provided by `<cngx-tab-group>`.
|
|
1127
1146
|
*
|
|
1128
|
-
*
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
}));
|
|
1135
|
-
}
|
|
1136
|
-
/**
|
|
1137
|
-
* Override the IO-debounce window (ms). See
|
|
1138
|
-
* {@link CngxTabsConfig.overflowStabilizeMs}.
|
|
1147
|
+
* Presence-only by design. There is no contract interface: providers
|
|
1148
|
+
* register `{ provide: CNGX_TAB_NAV_HOST, useValue: true }` and readers
|
|
1149
|
+
* only ever test `navHost != null`. Nothing here can be widened into a
|
|
1150
|
+
* second host contract - {@link CNGX_TAB_GROUP_HOST} already owns the
|
|
1151
|
+
* presenter surface, and this token sits beside it so the tablist path
|
|
1152
|
+
* gains no dead field.
|
|
1139
1153
|
*
|
|
1140
|
-
*
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
overflowStabilizeMs: ms,
|
|
1146
|
-
}));
|
|
1147
|
-
}
|
|
1148
|
-
/**
|
|
1149
|
-
* Override the worst-case staleness ceiling on the visibility-map
|
|
1150
|
-
* commit. See {@link CngxTabsConfig.overflowMaxDeferMs}.
|
|
1154
|
+
* **Why a token and not the host class.** A sub-directive talks to its
|
|
1155
|
+
* host through DI, never through a concrete class: importing `CngxTabNav`
|
|
1156
|
+
* from `@cngx/common` would be a `common -> ui` edge that Sheriff rejects,
|
|
1157
|
+
* and element-tag sniffing breaks the moment a decomposed skin renames the
|
|
1158
|
+
* element.
|
|
1151
1159
|
*
|
|
1152
|
-
* @
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
}));
|
|
1159
|
-
}
|
|
1160
|
-
/**
|
|
1161
|
-
* App-wide override for the More-button label. Middle tier; \
|
|
1162
|
-
* per-instance `*cngxTabOverflowTrigger` still wins.
|
|
1160
|
+
* **What reads it.** {@link CngxTabsRouteSync} injects it
|
|
1161
|
+
* `{ optional: true, host: true }` to pick its URL-matching semantics: a
|
|
1162
|
+
* nav link owns a whole subtree and stays current for every URL beneath it
|
|
1163
|
+
* (prefix), while a tablist tab is a leaf and matches only its own route
|
|
1164
|
+
* (suffix). The `[match]` input overrides the token-derived default when a
|
|
1165
|
+
* consumer needs the other mode.
|
|
1163
1166
|
*
|
|
1164
1167
|
* ```ts
|
|
1165
|
-
*
|
|
1166
|
-
* '
|
|
1167
|
-
* {
|
|
1168
|
-
*
|
|
1169
|
-
*
|
|
1170
|
-
*
|
|
1168
|
+
* @Component({
|
|
1169
|
+
* selector: 'my-section-nav',
|
|
1170
|
+
* providers: [{ provide: CNGX_TAB_NAV_HOST, useValue: true }],
|
|
1171
|
+
* hostDirectives: [CngxTabGroupPresenter],
|
|
1172
|
+
* })
|
|
1173
|
+
* export class MySectionNav {}
|
|
1171
1174
|
* ```
|
|
1172
1175
|
*
|
|
1173
1176
|
* @category common/tabs
|
|
1177
|
+
* @wcag AA
|
|
1178
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/tab-nav-host.token.ts
|
|
1179
|
+
* @since 0.1.0
|
|
1180
|
+
* @relatedTo CngxTabsRouteSync, CNGX_TAB_GROUP_HOST, CngxTabNav, CngxMatTabNav
|
|
1174
1181
|
*/
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
...cfg,
|
|
1178
|
-
templates: { ...cfg.templates, overflowTrigger: template },
|
|
1179
|
-
}));
|
|
1180
|
-
}
|
|
1182
|
+
const CNGX_TAB_NAV_HOST = new InjectionToken('CngxTabNavHost');
|
|
1183
|
+
|
|
1181
1184
|
/**
|
|
1182
|
-
*
|
|
1183
|
-
*
|
|
1184
|
-
*
|
|
1185
|
-
* @category common/tabs
|
|
1185
|
+
* Path-segment count of a resolved `UrlTree`, used to rank prefix
|
|
1186
|
+
* matches: `/rounds/explorer` outranks `/rounds` on a URL both match.
|
|
1186
1187
|
*/
|
|
1187
|
-
function
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1188
|
+
function urlTreeSegmentCount(tree) {
|
|
1189
|
+
let count = 0;
|
|
1190
|
+
const walk = (group) => {
|
|
1191
|
+
count += group.segments.length;
|
|
1192
|
+
for (const key of Object.keys(group.children)) {
|
|
1193
|
+
walk(group.children[key]);
|
|
1194
|
+
}
|
|
1195
|
+
};
|
|
1196
|
+
walk(tree.root);
|
|
1197
|
+
return count;
|
|
1192
1198
|
}
|
|
1193
1199
|
/**
|
|
1194
|
-
*
|
|
1195
|
-
*
|
|
1196
|
-
*
|
|
1197
|
-
*
|
|
1198
|
-
*
|
|
1200
|
+
* Primary-outlet path segments of the current URL, decoded. Going
|
|
1201
|
+
* through `router.parseUrl` (not a hand-rolled split) keeps matrix
|
|
1202
|
+
* params (`;theme=dark`) out of the compared paths, decodes
|
|
1203
|
+
* percent-encoded segments so they compare against raw `routeFor`
|
|
1204
|
+
* commands, and confines the walk to the primary outlet so an aux
|
|
1205
|
+
* outlet (`(aside:x)`) can neither pollute the tail nor match.
|
|
1199
1206
|
*/
|
|
1200
|
-
function
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1207
|
+
function primaryPathSegments(router) {
|
|
1208
|
+
const segments = [];
|
|
1209
|
+
let group = router.parseUrl(router.url).root;
|
|
1210
|
+
while (group !== undefined) {
|
|
1211
|
+
segments.push(...group.segments.map((segment) => segment.path));
|
|
1212
|
+
group = group.children[PRIMARY_OUTLET];
|
|
1213
|
+
}
|
|
1214
|
+
return segments;
|
|
1205
1215
|
}
|
|
1206
1216
|
/**
|
|
1207
|
-
*
|
|
1208
|
-
*
|
|
1209
|
-
*
|
|
1210
|
-
*
|
|
1211
|
-
*
|
|
1212
|
-
*
|
|
1217
|
+
* Find the tab whose route is the trailing segment(s) of the current URL
|
|
1218
|
+
* path. Anchors on position, not a loose "appears anywhere" scan - a tab
|
|
1219
|
+
* id that happens to equal an unrelated parent segment cannot win. The
|
|
1220
|
+
* path is the decoded primary-outlet segment list (query, fragment,
|
|
1221
|
+
* matrix params, and aux outlets excluded). If two tabs produce the same
|
|
1222
|
+
* trailing segment(s) (only possible with a colliding custom `routeFor`),
|
|
1223
|
+
* the first registered tab wins; the default id-based mapping never
|
|
1224
|
+
* collides.
|
|
1213
1225
|
*/
|
|
1214
|
-
function
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1226
|
+
function resolveBySuffix(ctx) {
|
|
1227
|
+
const segments = primaryPathSegments(ctx.router);
|
|
1228
|
+
for (const tab of ctx.tabs) {
|
|
1229
|
+
const route = ctx.routeFor(tab).map((command) => String(command));
|
|
1230
|
+
if (route.length === 0 || route.length > segments.length) {
|
|
1231
|
+
continue;
|
|
1232
|
+
}
|
|
1233
|
+
const tail = segments.slice(-route.length);
|
|
1234
|
+
if (tail.every((segment, i) => segment === route[i])) {
|
|
1235
|
+
return tab.id;
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
return null;
|
|
1219
1239
|
}
|
|
1220
1240
|
/**
|
|
1221
|
-
*
|
|
1222
|
-
*
|
|
1223
|
-
*
|
|
1241
|
+
* Find the tab that owns the current URL's subtree: the one whose
|
|
1242
|
+
* resolved `UrlTree` is a subset of the active tree, ignoring query
|
|
1243
|
+
* params, fragment, and matrix params.
|
|
1224
1244
|
*
|
|
1225
|
-
*
|
|
1245
|
+
* Routes resolve `{ relativeTo: ActivatedRoute }` rather than against the
|
|
1246
|
+
* URL root. A root-anchored segment compare breaks a nav mounted under a
|
|
1247
|
+
* base path - at `/app/rounds` a `['rounds']` route would compare
|
|
1248
|
+
* `'app' === 'rounds'`, resolve `null`, and hand the first link a wrong
|
|
1249
|
+
* `aria-current`, which is the exact defect prefix mode exists to fix.
|
|
1250
|
+
* Relative resolution is safe on the read side because the nav path is
|
|
1251
|
+
* commit-free: links navigate through their own `routerLink`, so nothing
|
|
1252
|
+
* here can diverge from a commit navigation.
|
|
1253
|
+
*
|
|
1254
|
+
* Longest route wins, so a `/rounds` tab cannot shadow `/rounds/explorer`
|
|
1255
|
+
* in the same set.
|
|
1226
1256
|
*/
|
|
1227
|
-
function
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1257
|
+
function resolveByPrefix(ctx) {
|
|
1258
|
+
let winner = null;
|
|
1259
|
+
let winnerDepth = -1;
|
|
1260
|
+
for (const tab of ctx.tabs) {
|
|
1261
|
+
const route = ctx.routeFor(tab);
|
|
1262
|
+
if (route.length === 0) {
|
|
1263
|
+
continue;
|
|
1264
|
+
}
|
|
1265
|
+
const tree = ctx.router.createUrlTree(route, { relativeTo: ctx.activatedRoute });
|
|
1266
|
+
const active = ctx.router.isActive(tree, {
|
|
1267
|
+
paths: 'subset',
|
|
1268
|
+
queryParams: 'ignored',
|
|
1269
|
+
fragment: 'ignored',
|
|
1270
|
+
matrixParams: 'ignored',
|
|
1271
|
+
});
|
|
1272
|
+
if (!active) {
|
|
1273
|
+
continue;
|
|
1274
|
+
}
|
|
1275
|
+
const depth = urlTreeSegmentCount(tree);
|
|
1276
|
+
if (depth > winnerDepth) {
|
|
1277
|
+
winner = tab.id;
|
|
1278
|
+
winnerDepth = depth;
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
return winner;
|
|
1232
1282
|
}
|
|
1233
1283
|
/**
|
|
1234
|
-
*
|
|
1235
|
-
*
|
|
1236
|
-
*
|
|
1284
|
+
* The two URL-matching policies `[cngxTabsRouteSync]` ships, dispatched
|
|
1285
|
+
* on {@link CngxTabUrlMatchContext.mode}. Same exact-versus-prefix
|
|
1286
|
+
* distinction `routerLinkActive` draws.
|
|
1287
|
+
*
|
|
1288
|
+
* Pure: no injection context, no signal reads. The directive resolves the
|
|
1289
|
+
* mode cascade and the tab registry, then hands both in.
|
|
1237
1290
|
*
|
|
1238
1291
|
* @category common/tabs
|
|
1239
1292
|
*/
|
|
1240
|
-
function
|
|
1241
|
-
return
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1293
|
+
function createTabUrlMatch() {
|
|
1294
|
+
return {
|
|
1295
|
+
resolve(ctx) {
|
|
1296
|
+
return ctx.mode === 'prefix' ? resolveByPrefix(ctx) : resolveBySuffix(ctx);
|
|
1297
|
+
},
|
|
1298
|
+
};
|
|
1245
1299
|
}
|
|
1246
1300
|
/**
|
|
1247
|
-
*
|
|
1248
|
-
*
|
|
1301
|
+
* Swap point for how a routed tab set decides which tab the URL belongs
|
|
1302
|
+
* to. Default {@link createTabUrlMatch}.
|
|
1303
|
+
*
|
|
1304
|
+
* Override when neither shipped policy fits: locale-segment-insensitive
|
|
1305
|
+
* comparison (`/de/rounds` and `/en/rounds` are the same tab), matching
|
|
1306
|
+
* on a route `data` key instead of the path, or a permission-aware read
|
|
1307
|
+
* that skips tabs the user cannot open. `routeFor` only changes what a
|
|
1308
|
+
* tab's route *is*; this changes how it is *compared*.
|
|
1309
|
+
*
|
|
1310
|
+
* Mirrors {@link CNGX_TABS_COMMIT_ACTION} on the write side: the
|
|
1311
|
+
* navigation a tab switch performs is already swappable, so the read that
|
|
1312
|
+
* mirrors navigation back onto `activeIndex` should be too.
|
|
1249
1313
|
*
|
|
1250
1314
|
* @category common/tabs
|
|
1315
|
+
* @wcag AA
|
|
1316
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/url-match.ts
|
|
1317
|
+
* @since 0.1.0
|
|
1318
|
+
* @relatedTo CngxTabsRouteSync, createTabUrlMatch, createTabRouterCommit
|
|
1251
1319
|
*/
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
}
|
|
1320
|
+
const CNGX_TAB_URL_MATCH_STRATEGY = new InjectionToken('CngxTabUrlMatchStrategy', {
|
|
1321
|
+
providedIn: 'root',
|
|
1322
|
+
factory: () => createTabUrlMatch(),
|
|
1323
|
+
});
|
|
1324
|
+
|
|
1258
1325
|
/**
|
|
1259
|
-
*
|
|
1260
|
-
*
|
|
1326
|
+
* Structural slot directive marking the per-tab panel-body template. \
|
|
1327
|
+
* Discovered by `<cngx-tab-group>` via `contentChild` on each
|
|
1328
|
+
* `CngxTab` and projected into the matching `role="tabpanel"`.
|
|
1329
|
+
*
|
|
1330
|
+
* ```html
|
|
1331
|
+
* <div cngxTab [label]="'Settings'">
|
|
1332
|
+
* <ng-template cngxTabContent>
|
|
1333
|
+
* <p>Settings panel body…</p>
|
|
1334
|
+
* </ng-template>
|
|
1335
|
+
* </div>
|
|
1336
|
+
* ```
|
|
1261
1337
|
*
|
|
1262
1338
|
* @category common/tabs
|
|
1339
|
+
* @wcag AA
|
|
1340
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/tab-content.directive.ts
|
|
1341
|
+
* @since 0.1.0
|
|
1342
|
+
* @relatedTo CngxTab, CngxTabLabel
|
|
1263
1343
|
*/
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
}));
|
|
1269
|
-
}
|
|
1270
|
-
function resolveFeatures(features) {
|
|
1271
|
-
return features.reduce((cfg, feat) => feat(cfg), TABS_CONFIG_DEFAULTS);
|
|
1344
|
+
class CngxTabContent {
|
|
1345
|
+
templateRef = inject((TemplateRef));
|
|
1346
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabContent, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1347
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxTabContent, isStandalone: true, selector: "ng-template[cngxTabContent]", exportAs: ["cngxTabContent"], ngImport: i0 });
|
|
1272
1348
|
}
|
|
1349
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabContent, decorators: [{
|
|
1350
|
+
type: Directive,
|
|
1351
|
+
args: [{
|
|
1352
|
+
selector: 'ng-template[cngxTabContent]',
|
|
1353
|
+
exportAs: 'cngxTabContent',
|
|
1354
|
+
standalone: true,
|
|
1355
|
+
}]
|
|
1356
|
+
}] });
|
|
1357
|
+
|
|
1273
1358
|
/**
|
|
1274
|
-
*
|
|
1275
|
-
*
|
|
1276
|
-
*
|
|
1359
|
+
* Structural slot directive marking the per-tab label template. \
|
|
1360
|
+
* Discovered by `<cngx-tab-group>` via `contentChild` on each
|
|
1361
|
+
* `CngxTab` and projected into the tab strip.
|
|
1362
|
+
*
|
|
1363
|
+
* ```html
|
|
1364
|
+
* <div cngxTab id="settings">
|
|
1365
|
+
* <ng-template cngxTabLabel>Settings</ng-template>
|
|
1366
|
+
* ... tab content ...
|
|
1367
|
+
* </div>
|
|
1368
|
+
* ```
|
|
1277
1369
|
*
|
|
1278
1370
|
* @category common/tabs
|
|
1371
|
+
* @wcag AA
|
|
1372
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/tab-label.directive.ts
|
|
1373
|
+
* @since 0.1.0
|
|
1374
|
+
* @relatedTo CngxTab, CngxTabContent
|
|
1279
1375
|
*/
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
]);
|
|
1376
|
+
class CngxTabLabel {
|
|
1377
|
+
templateRef = inject((TemplateRef));
|
|
1378
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabLabel, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1379
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxTabLabel, isStandalone: true, selector: "ng-template[cngxTabLabel]", exportAs: ["cngxTabLabel"], ngImport: i0 });
|
|
1284
1380
|
}
|
|
1381
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabLabel, decorators: [{
|
|
1382
|
+
type: Directive,
|
|
1383
|
+
args: [{
|
|
1384
|
+
selector: 'ng-template[cngxTabLabel]',
|
|
1385
|
+
exportAs: 'cngxTabLabel',
|
|
1386
|
+
standalone: true,
|
|
1387
|
+
}]
|
|
1388
|
+
}] });
|
|
1389
|
+
|
|
1285
1390
|
/**
|
|
1286
|
-
*
|
|
1287
|
-
*
|
|
1288
|
-
*
|
|
1289
|
-
*
|
|
1391
|
+
* Structural slot directive marking a tab's secondary label template. \
|
|
1392
|
+
* Discovered by `<cngx-tab-group>` via `contentChild` on each
|
|
1393
|
+
* `CngxTab` and rendered as a stacked second line under the primary
|
|
1394
|
+
* label. \
|
|
1290
1395
|
*
|
|
1291
|
-
*
|
|
1292
|
-
*
|
|
1293
|
-
*
|
|
1294
|
-
*
|
|
1396
|
+
* Per-tab content, mirroring `CngxTabLabel` - the convenience
|
|
1397
|
+
* `[subLabel]` string input on `CngxTab` covers the plain-text case.
|
|
1398
|
+
*
|
|
1399
|
+
* ```html
|
|
1400
|
+
* <div cngxTab id="bookmarks">
|
|
1401
|
+
* <ng-template cngxTabLabel>Bookmarks</ng-template>
|
|
1402
|
+
* <ng-template cngxTabSubLabel>45 saved</ng-template>
|
|
1403
|
+
* <ng-template cngxTabContent>...</ng-template>
|
|
1404
|
+
* </div>
|
|
1295
1405
|
* ```
|
|
1296
1406
|
*
|
|
1297
|
-
* @category common/tabs
|
|
1407
|
+
* @category common/tabs/slots
|
|
1408
|
+
* @wcag AA
|
|
1409
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/slots/tab-sub-label.directive.ts
|
|
1410
|
+
* @since 0.1.0
|
|
1411
|
+
* @relatedTo CngxTab, CngxTabLabel, CngxTabContent
|
|
1412
|
+
* <example-url>http://localhost:4200/#/ui/tabs/tab-sub-label/label-with-count</example-url>
|
|
1298
1413
|
*/
|
|
1299
|
-
|
|
1300
|
-
|
|
1414
|
+
class CngxTabSubLabel {
|
|
1415
|
+
/**
|
|
1416
|
+
* The captured `<ng-template>`, projected by `<cngx-tab-group>` as the
|
|
1417
|
+
* tab's secondary label line under the primary label.
|
|
1418
|
+
*/
|
|
1419
|
+
templateRef = inject((TemplateRef));
|
|
1420
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabSubLabel, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1421
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxTabSubLabel, isStandalone: true, selector: "ng-template[cngxTabSubLabel]", exportAs: ["cngxTabSubLabel"], ngImport: i0 });
|
|
1301
1422
|
}
|
|
1423
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabSubLabel, decorators: [{
|
|
1424
|
+
type: Directive,
|
|
1425
|
+
args: [{
|
|
1426
|
+
selector: 'ng-template[cngxTabSubLabel]',
|
|
1427
|
+
exportAs: 'cngxTabSubLabel',
|
|
1428
|
+
standalone: true,
|
|
1429
|
+
}]
|
|
1430
|
+
}] });
|
|
1431
|
+
|
|
1302
1432
|
/**
|
|
1303
|
-
*
|
|
1433
|
+
* Single-tab atom. \
|
|
1434
|
+
* Registers with the enclosing presenter via
|
|
1435
|
+
* {@link CNGX_TAB_GROUP_HOST} on construction; deregisters via
|
|
1436
|
+
* {@link DestroyRef} on teardown. \
|
|
1437
|
+
* The presenter holds the atom's
|
|
1438
|
+
* input signals by reference, so input changes propagate without
|
|
1439
|
+
* re-registration. \
|
|
1440
|
+
* `labelTemplate` / `contentTemplate` are projected
|
|
1441
|
+
* by the organism - the atom carries no rendering logic.
|
|
1304
1442
|
*
|
|
1443
|
+
* ```html
|
|
1444
|
+
* <div cngxTab [label]="'Settings'">
|
|
1445
|
+
* ... content templates here ...
|
|
1446
|
+
* </div>
|
|
1447
|
+
* ```
|
|
1305
1448
|
* @category common/tabs
|
|
1449
|
+
* @docsKind primary
|
|
1450
|
+
* @wcag AA
|
|
1451
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/tab.directive.ts
|
|
1452
|
+
* @since 0.1.0
|
|
1453
|
+
* @relatedTo CngxTabGroupPresenter, CngxTabLabel, CngxTabContent, CngxTabErrorBadge
|
|
1454
|
+
* @slot cngxTabLabel The tab's own header label.
|
|
1455
|
+
* @slot cngxTabSubLabel Secondary line under the label, e.g. a count or status.
|
|
1456
|
+
* @slot cngxTabContent The panel body, rendered lazily when the tab activates.
|
|
1306
1457
|
*/
|
|
1307
|
-
|
|
1308
|
-
|
|
1458
|
+
class CngxTab {
|
|
1459
|
+
id = input(nextUid('cngx-tab-'), ...(ngDevMode ? [{ debugName: "id" }] : /* istanbul ignore next */ []));
|
|
1460
|
+
disabled = input(false, ...(ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []));
|
|
1461
|
+
label = input(undefined, ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
|
|
1462
|
+
/**
|
|
1463
|
+
* Optional secondary text line under the primary label (a count, a
|
|
1464
|
+
* status word, a short detail). Convenience for the common text
|
|
1465
|
+
* case, parallel to `[label]`; the `*cngxTabSubLabel` slot covers
|
|
1466
|
+
* richer content. Folds into the tab's accessible name.
|
|
1467
|
+
*/
|
|
1468
|
+
subLabel = input(undefined, ...(ngDevMode ? [{ debugName: "subLabel" }] : /* istanbul ignore next */ []));
|
|
1469
|
+
errorAggregator = input(undefined, ...(ngDevMode ? [{ debugName: "errorAggregator" }] : /* istanbul ignore next */ []));
|
|
1470
|
+
/**
|
|
1471
|
+
* Direct error flag for the common "this tab is invalid" case - no
|
|
1472
|
+
* `errorAggregator` boilerplate required. `true` or a non-empty string
|
|
1473
|
+
* drives the error state; a string doubles as the inline message
|
|
1474
|
+
* (surfaced via the `*cngxTabErrorBadge` slot context). `false` / `''`
|
|
1475
|
+
* clear it. The aggregator stays the rich multi-source forms path; the
|
|
1476
|
+
* two channels compose (either errors). Mirrors `CngxStep.error`.
|
|
1477
|
+
*/
|
|
1478
|
+
error = input(false, ...(ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []));
|
|
1479
|
+
/**
|
|
1480
|
+
* Resolved direct-error message: the `[error]` string when non-empty,
|
|
1481
|
+
* else `undefined`. Carried onto the registration handle so the error
|
|
1482
|
+
* badge slot can render it. `computed` over the input - never written.
|
|
1483
|
+
*/
|
|
1484
|
+
errorMessage = computed(() => {
|
|
1485
|
+
const value = this.error();
|
|
1486
|
+
return typeof value === 'string' && value !== '' ? value : undefined;
|
|
1487
|
+
}, ...(ngDevMode ? [{ debugName: "errorMessage" }] : /* istanbul ignore next */ []));
|
|
1488
|
+
/**
|
|
1489
|
+
* Per-tab error fold driving the badge + SR descriptor. `true` when
|
|
1490
|
+
* the direct `[error]` flag is set OR the optional aggregator wants to
|
|
1491
|
+
* reveal (`shouldShow()` = `hasError` AND scope reveal-state). The
|
|
1492
|
+
* aggregator arm reads `shouldShow`, not `hasError`, so deferred-reveal
|
|
1493
|
+
* validation stays silent until revealed - the direct flag has no
|
|
1494
|
+
* reveal concept (the consumer sets it when it wants it shown). A
|
|
1495
|
+
* boolean, not a status enum: tabs carry no success/completed/disabled
|
|
1496
|
+
* model (Pillar 3).
|
|
1497
|
+
*/
|
|
1498
|
+
hasError = computed(() => {
|
|
1499
|
+
const directError = this.error();
|
|
1500
|
+
return ((directError !== false && directError !== '') ||
|
|
1501
|
+
(this.errorAggregator()?.shouldShow?.() ?? false));
|
|
1502
|
+
}, { ...(ngDevMode ? { debugName: "hasError" } : /* istanbul ignore next */ {}), equal: Object.is });
|
|
1503
|
+
/**
|
|
1504
|
+
* Per-tab close-affordance override. `undefined` (default) inherits
|
|
1505
|
+
* the group-level `[closable]` resolution; set `false` to pin this
|
|
1506
|
+
* tab open inside a dismissable group, or `true` to make a single tab
|
|
1507
|
+
* closable while the group default is off.
|
|
1508
|
+
*/
|
|
1509
|
+
closable = input(undefined, ...(ngDevMode ? [{ debugName: "closable" }] : /* istanbul ignore next */ []));
|
|
1510
|
+
labelTemplate = contentChild(CngxTabLabel, ...(ngDevMode ? [{ debugName: "labelTemplate" }] : /* istanbul ignore next */ []));
|
|
1511
|
+
subLabelTemplate = contentChild(CngxTabSubLabel, ...(ngDevMode ? [{ debugName: "subLabelTemplate" }] : /* istanbul ignore next */ []));
|
|
1512
|
+
contentTemplate = contentChild(CngxTabContent, ...(ngDevMode ? [{ debugName: "contentTemplate" }] : /* istanbul ignore next */ []));
|
|
1513
|
+
host = inject(CNGX_TAB_GROUP_HOST, { optional: true });
|
|
1514
|
+
destroyRef = inject(DestroyRef);
|
|
1515
|
+
/** `true` when the presenter's `activeId` equals this tab's id. */
|
|
1516
|
+
selected = computed(() => this.host?.activeId() === this.id(), { ...(ngDevMode ? { debugName: "selected" } : /* istanbul ignore next */ {}), equal: Object.is });
|
|
1517
|
+
constructor() {
|
|
1518
|
+
if (!this.host) {
|
|
1519
|
+
throw new Error('CngxTab: no enclosing CngxTabGroupPresenter found. Wrap the tab inside an element carrying [cngxTabGroup] (or place it inside <cngx-tab-group>).');
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
ngOnInit() {
|
|
1523
|
+
// Register in ngOnInit, NOT the constructor: a dynamically-bound
|
|
1524
|
+
// `[id]` (or `[label]`) signal input is not applied until the first
|
|
1525
|
+
// change detection, so a constructor read would capture the default
|
|
1526
|
+
// auto-id. The handle id is the stable key consumers map `(tabClose)`
|
|
1527
|
+
// back to their data with, so it must reflect the bound `[id]`.
|
|
1528
|
+
// The id is captured once here - init-stable by contract. A later
|
|
1529
|
+
// `[id]` rebind does not re-register; the auto-uid default makes a
|
|
1530
|
+
// stable consumer-supplied id the normal case. Mirrors CngxStep.
|
|
1531
|
+
const host = this.host;
|
|
1532
|
+
const tabId = this.id();
|
|
1533
|
+
const handle = {
|
|
1534
|
+
id: tabId,
|
|
1535
|
+
label: this.label,
|
|
1536
|
+
subLabel: this.subLabel,
|
|
1537
|
+
disabled: this.disabled,
|
|
1538
|
+
errorAggregator: this.errorAggregator,
|
|
1539
|
+
hasError: this.hasError,
|
|
1540
|
+
errorMessage: this.errorMessage,
|
|
1541
|
+
closable: this.closable,
|
|
1542
|
+
};
|
|
1543
|
+
host.register(handle);
|
|
1544
|
+
this.destroyRef.onDestroy(() => host.unregister(tabId, handle));
|
|
1545
|
+
}
|
|
1546
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTab, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1547
|
+
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 });
|
|
1309
1548
|
}
|
|
1549
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTab, decorators: [{
|
|
1550
|
+
type: Directive,
|
|
1551
|
+
args: [{
|
|
1552
|
+
selector: '[cngxTab]',
|
|
1553
|
+
exportAs: 'cngxTab',
|
|
1554
|
+
standalone: true,
|
|
1555
|
+
}]
|
|
1556
|
+
}], 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 }] }] } });
|
|
1310
1557
|
|
|
1311
1558
|
/**
|
|
1312
1559
|
* Turns a consumer `<a routerLink>` into a registered {@link CngxTabHandle}
|
|
@@ -1408,9 +1655,11 @@ class CngxTabLink {
|
|
|
1408
1655
|
/** `true` when the presenter's `activeId` equals this link's id. */
|
|
1409
1656
|
selected = computed(() => this.host?.activeId() === this.id(), { ...(ngDevMode ? { debugName: "selected" } : /* istanbul ignore next */ {}), equal: Object.is });
|
|
1410
1657
|
/**
|
|
1411
|
-
* Id of the injected SR error-message descriptor.
|
|
1412
|
-
*
|
|
1413
|
-
*
|
|
1658
|
+
* Id of the injected SR error-message descriptor. The `aria-describedby`
|
|
1659
|
+
* host binding emits it only while `hasError()` - `aria-hidden` on a
|
|
1660
|
+
* directly-referenced node does not suppress it (accname 1.2 traverses
|
|
1661
|
+
* the reference), so the id reference itself is gated, not just the
|
|
1662
|
+
* span's visibility.
|
|
1414
1663
|
*/
|
|
1415
1664
|
descriptorId = computed(() => `${this.id()}-desc`, ...(ngDevMode ? [{ debugName: "descriptorId" }] : /* istanbul ignore next */ []));
|
|
1416
1665
|
/** The injected descriptor `<span>`, created in {@link ngOnInit}. */
|
|
@@ -1458,7 +1707,7 @@ class CngxTabLink {
|
|
|
1458
1707
|
this.descriptorEl = descriptor;
|
|
1459
1708
|
this.syncDescriptor(descriptor);
|
|
1460
1709
|
this.destroyRef.onDestroy(() => {
|
|
1461
|
-
host.unregister(handle.id);
|
|
1710
|
+
host.unregister(handle.id, handle);
|
|
1462
1711
|
if (parent) {
|
|
1463
1712
|
this.renderer.removeChild(parent, descriptor);
|
|
1464
1713
|
}
|
|
@@ -1482,7 +1731,7 @@ class CngxTabLink {
|
|
|
1482
1731
|
}
|
|
1483
1732
|
}
|
|
1484
1733
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabLink, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1485
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxTabLink, isStandalone: true, selector: "[cngxTabLink]", inputs: { id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, error: { classPropertyName: "error", publicName: "error", isSignal: true, isRequired: false, transformFunction: null }, errorAggregator: { classPropertyName: "errorAggregator", publicName: "errorAggregator", isSignal: true, isRequired: false, transformFunction: null }, ariaCurrent: { classPropertyName: "ariaCurrent", publicName: "ariaCurrent", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "attr.aria-current": "selected() ? resolvedAriaCurrent() : null", "attr.aria-invalid": "hasError() ? 'true' : null", "attr.aria-describedby": "descriptorId()", "class.cngx-tab-nav__link--active": "selected()", "class.cngx-tab-nav__link--error": "hasError()" }, classAttribute: "cngx-tab-nav__link" }, exportAs: ["cngxTabLink"], ngImport: i0 });
|
|
1734
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxTabLink, isStandalone: true, selector: "[cngxTabLink]", inputs: { id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, error: { classPropertyName: "error", publicName: "error", isSignal: true, isRequired: false, transformFunction: null }, errorAggregator: { classPropertyName: "errorAggregator", publicName: "errorAggregator", isSignal: true, isRequired: false, transformFunction: null }, ariaCurrent: { classPropertyName: "ariaCurrent", publicName: "ariaCurrent", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "attr.aria-current": "selected() ? resolvedAriaCurrent() : null", "attr.aria-invalid": "hasError() ? 'true' : null", "attr.aria-describedby": "hasError() ? descriptorId() : null", "class.cngx-tab-nav__link--active": "selected()", "class.cngx-tab-nav__link--error": "hasError()" }, classAttribute: "cngx-tab-nav__link" }, exportAs: ["cngxTabLink"], ngImport: i0 });
|
|
1486
1735
|
}
|
|
1487
1736
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabLink, decorators: [{
|
|
1488
1737
|
type: Directive,
|
|
@@ -1494,7 +1743,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1494
1743
|
class: 'cngx-tab-nav__link',
|
|
1495
1744
|
'[attr.aria-current]': 'selected() ? resolvedAriaCurrent() : null',
|
|
1496
1745
|
'[attr.aria-invalid]': "hasError() ? 'true' : null",
|
|
1497
|
-
'[attr.aria-describedby]': 'descriptorId()',
|
|
1746
|
+
'[attr.aria-describedby]': 'hasError() ? descriptorId() : null',
|
|
1498
1747
|
'[class.cngx-tab-nav__link--active]': 'selected()',
|
|
1499
1748
|
'[class.cngx-tab-nav__link--error]': 'hasError()',
|
|
1500
1749
|
},
|
|
@@ -1555,8 +1804,15 @@ function warnTabsRouterAbsent(directive, enables) {
|
|
|
1555
1804
|
* @relatedTo CngxTabGroupPresenter, CngxTab
|
|
1556
1805
|
*/
|
|
1557
1806
|
class CngxTabsFragmentSync {
|
|
1558
|
-
|
|
1559
|
-
|
|
1807
|
+
// Default undefined so the cascade resolves through CNGX_TABS_CONFIG.
|
|
1808
|
+
// Init-only: the seed and the write effect capture the resolved mode /
|
|
1809
|
+
// param on their first run; changing either after init leaves the old
|
|
1810
|
+
// URL key behind. Rebuild the directive to change them.
|
|
1811
|
+
modeInput = input(undefined, { ...(ngDevMode ? { debugName: "modeInput" } : /* istanbul ignore next */ {}), alias: 'mode' });
|
|
1812
|
+
paramNameInput = input(undefined, { ...(ngDevMode ? { debugName: "paramNameInput" } : /* istanbul ignore next */ {}), alias: 'paramName' });
|
|
1813
|
+
config = injectTabsConfig();
|
|
1814
|
+
mode = computed(() => this.modeInput() ?? this.config.fragmentSyncMode ?? 'fragment', ...(ngDevMode ? [{ debugName: "mode" }] : /* istanbul ignore next */ []));
|
|
1815
|
+
paramName = computed(() => this.paramNameInput() ?? this.config.fragmentSyncParam ?? 'tab', ...(ngDevMode ? [{ debugName: "paramName" }] : /* istanbul ignore next */ []));
|
|
1560
1816
|
/**
|
|
1561
1817
|
* Whether reflecting the active tab into the URL replaces the current
|
|
1562
1818
|
* history entry instead of pushing a new one. Default `true`, which is
|
|
@@ -1597,27 +1853,21 @@ class CngxTabsFragmentSync {
|
|
|
1597
1853
|
afterNextRender(() => {
|
|
1598
1854
|
this.seedFromUrl(router);
|
|
1599
1855
|
});
|
|
1856
|
+
let initialReflect = true;
|
|
1600
1857
|
effect(() => {
|
|
1601
1858
|
const id = this.host.activeId();
|
|
1602
1859
|
if (!id) {
|
|
1603
1860
|
return;
|
|
1604
1861
|
}
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
queryParams: { [this.paramName()]: id },
|
|
1615
|
-
queryParamsHandling: 'merge',
|
|
1616
|
-
replaceUrl,
|
|
1617
|
-
});
|
|
1618
|
-
// Router rejection (e.g. cancelled navigation) has no recovery path.
|
|
1619
|
-
navigation.catch?.(() => undefined);
|
|
1620
|
-
});
|
|
1862
|
+
if (initialReflect) {
|
|
1863
|
+
// Bare mount is not an interaction: the first resolved active id
|
|
1864
|
+
// (default tab or URL seed) must not stamp the URL - a page that
|
|
1865
|
+
// merely renders tabs would otherwise rewrite its own history
|
|
1866
|
+
// entry. The URL starts changing when the active tab does.
|
|
1867
|
+
initialReflect = false;
|
|
1868
|
+
return;
|
|
1869
|
+
}
|
|
1870
|
+
untracked(() => this.writeUrl(router, id));
|
|
1621
1871
|
});
|
|
1622
1872
|
const navEnd = toSignal(router.events.pipe(filter((e) => e instanceof NavigationEnd), takeUntilDestroyed(destroyRef)), { initialValue: null });
|
|
1623
1873
|
effect(() => {
|
|
@@ -1671,6 +1921,36 @@ class CngxTabsFragmentSync {
|
|
|
1671
1921
|
this.seeded = true;
|
|
1672
1922
|
untracked(() => this.host.selectById(initial));
|
|
1673
1923
|
}
|
|
1924
|
+
/**
|
|
1925
|
+
* Reflect `id` into the URL. Fragment mode re-serializes the existing
|
|
1926
|
+
* fragment params so foreign state (`#foo=1&tab=x`) survives the
|
|
1927
|
+
* write; values are URI-encoded symmetric to {@link parseFragment}.
|
|
1928
|
+
*/
|
|
1929
|
+
writeUrl(router, id) {
|
|
1930
|
+
const replaceUrl = this.replaceUrl();
|
|
1931
|
+
const navigation = this.mode() === 'fragment'
|
|
1932
|
+
? router.navigate([], {
|
|
1933
|
+
fragment: this.serializeFragment(router, id),
|
|
1934
|
+
queryParamsHandling: 'merge',
|
|
1935
|
+
replaceUrl,
|
|
1936
|
+
})
|
|
1937
|
+
: router.navigate([], {
|
|
1938
|
+
queryParams: { [this.paramName()]: id },
|
|
1939
|
+
queryParamsHandling: 'merge',
|
|
1940
|
+
replaceUrl,
|
|
1941
|
+
});
|
|
1942
|
+
// Router rejection (e.g. cancelled navigation) has no recovery path.
|
|
1943
|
+
navigation.catch?.(() => undefined);
|
|
1944
|
+
}
|
|
1945
|
+
serializeFragment(router, id) {
|
|
1946
|
+
const param = this.paramName();
|
|
1947
|
+
const current = router.routerState.snapshot.root.fragment ?? '';
|
|
1948
|
+
const segments = current
|
|
1949
|
+
.split('&')
|
|
1950
|
+
.filter((seg) => seg !== '' && seg.split('=')[0] !== param);
|
|
1951
|
+
segments.push(`${param}=${encodeURIComponent(id)}`);
|
|
1952
|
+
return segments.join('&');
|
|
1953
|
+
}
|
|
1674
1954
|
readUrlValue(router) {
|
|
1675
1955
|
if (this.mode() === 'fragment') {
|
|
1676
1956
|
const fragment = router.routerState.snapshot.root.fragment ?? '';
|
|
@@ -1684,13 +1964,13 @@ class CngxTabsFragmentSync {
|
|
|
1684
1964
|
for (const seg of segments) {
|
|
1685
1965
|
const [key, val] = seg.split('=');
|
|
1686
1966
|
if (key === param && val) {
|
|
1687
|
-
return val;
|
|
1967
|
+
return decodeURIComponent(val);
|
|
1688
1968
|
}
|
|
1689
1969
|
}
|
|
1690
1970
|
return null;
|
|
1691
1971
|
}
|
|
1692
1972
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabsFragmentSync, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1693
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxTabsFragmentSync, isStandalone: true, selector: "[cngxTabsFragmentSync]", inputs: {
|
|
1973
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxTabsFragmentSync, isStandalone: true, selector: "[cngxTabsFragmentSync]", inputs: { modeInput: { classPropertyName: "modeInput", publicName: "mode", isSignal: true, isRequired: false, transformFunction: null }, paramNameInput: { classPropertyName: "paramNameInput", publicName: "paramName", isSignal: true, isRequired: false, transformFunction: null }, replaceUrl: { classPropertyName: "replaceUrl", publicName: "replaceUrl", isSignal: true, isRequired: false, transformFunction: null } }, exportAs: ["cngxTabsFragmentSync"], ngImport: i0 });
|
|
1694
1974
|
}
|
|
1695
1975
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabsFragmentSync, decorators: [{
|
|
1696
1976
|
type: Directive,
|
|
@@ -1699,7 +1979,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1699
1979
|
exportAs: 'cngxTabsFragmentSync',
|
|
1700
1980
|
standalone: true,
|
|
1701
1981
|
}]
|
|
1702
|
-
}], ctorParameters: () => [], propDecorators: {
|
|
1982
|
+
}], ctorParameters: () => [], propDecorators: { modeInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "mode", required: false }] }], paramNameInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "paramName", required: false }] }], replaceUrl: [{ type: i0.Input, args: [{ isSignal: true, alias: "replaceUrl", required: false }] }] } });
|
|
1703
1983
|
|
|
1704
1984
|
/**
|
|
1705
1985
|
* Default tab-to-route mapping: the tab id is the child segment.
|
|
@@ -1712,19 +1992,22 @@ const cngxDefaultTabRoute = (handle) => [handle.id];
|
|
|
1712
1992
|
/**
|
|
1713
1993
|
* Builds a {@link CngxTabsCommitAction} that gates a tab switch through
|
|
1714
1994
|
* `@angular/router`. The action navigates to the target tab's route and
|
|
1715
|
-
* resolves on
|
|
1995
|
+
* resolves on this navigation's own `navigate()` promise:
|
|
1716
1996
|
*
|
|
1717
|
-
* - `NavigationEnd` → `true` (commit the switch)
|
|
1718
|
-
* - `NavigationCancel`
|
|
1719
|
-
*
|
|
1997
|
+
* - resolved `true` (`NavigationEnd`) → `true` (commit the switch)
|
|
1998
|
+
* - resolved `false` (`NavigationCancel` - a `CanDeactivate` guard
|
|
1999
|
+
* blocked, or a newer navigation superseded this one) → `false`
|
|
2000
|
+
* - rejected (`NavigationError` - guard/resolver threw) → `false`
|
|
1720
2001
|
*
|
|
1721
2002
|
* Routed tabs reuse the presenter's commit lifecycle verbatim - the
|
|
1722
2003
|
* router navigation is simply the async op. \
|
|
1723
2004
|
* In pessimistic mode the active tab follows the *resolved* route, so a cancelled guard keeps
|
|
1724
|
-
* the old tab with zero extra gate machinery.
|
|
1725
|
-
*
|
|
1726
|
-
* navigation
|
|
1727
|
-
* controller's `cancel()`
|
|
2005
|
+
* the old tab with zero extra gate machinery. Correlating on the
|
|
2006
|
+
* promise (not `router.events`) means a concurrent unrelated
|
|
2007
|
+
* navigation's outcome can never resolve this commit; the commit
|
|
2008
|
+
* controller's `cancel()` closes the subscriber on supersede, and a
|
|
2009
|
+
* late promise resolution lands on the closed subscriber and is
|
|
2010
|
+
* dropped by RxJS itself.
|
|
1728
2011
|
*
|
|
1729
2012
|
* @category common/tabs
|
|
1730
2013
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/router-commit.ts
|
|
@@ -1739,20 +2022,20 @@ function createTabRouterCommit(opts) {
|
|
|
1739
2022
|
subscriber.complete();
|
|
1740
2023
|
return;
|
|
1741
2024
|
}
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
2025
|
+
// Resolve from THIS call's promise - correlated by construction.
|
|
2026
|
+
// A take(1) on router.events would grab the first terminal event
|
|
2027
|
+
// of ANY navigation, so a concurrent unrelated navigation could
|
|
2028
|
+
// resolve this commit with a foreign outcome.
|
|
2029
|
+
opts.router.navigate(routeFor(target)).then((result) => {
|
|
2030
|
+
// `false` is a cancelled or superseded navigation. A skipped
|
|
2031
|
+
// same-URL navigation resolves `null` - the tab's route is
|
|
2032
|
+
// already active, which commits.
|
|
2033
|
+
subscriber.next(result !== false);
|
|
2034
|
+
subscriber.complete();
|
|
2035
|
+
}, () => {
|
|
2036
|
+
subscriber.next(false);
|
|
1748
2037
|
subscriber.complete();
|
|
1749
2038
|
});
|
|
1750
|
-
// A rejected promise surfaces on the events stream as
|
|
1751
|
-
// NavigationError, so the subscription above is the single
|
|
1752
|
-
// resolution path; swallow the promise rejection to avoid an
|
|
1753
|
-
// unhandled-rejection warning.
|
|
1754
|
-
opts.router.navigate(routeFor(target)).catch(() => undefined);
|
|
1755
|
-
return () => sub.unsubscribe();
|
|
1756
2039
|
});
|
|
1757
2040
|
}
|
|
1758
2041
|
|
|
@@ -2023,87 +2306,6 @@ function createTabsHostAttrs(inputs) {
|
|
|
2023
2306
|
};
|
|
2024
2307
|
}
|
|
2025
2308
|
|
|
2026
|
-
const TABS_I18N_DEFAULTS = {
|
|
2027
|
-
tabsLabel: 'Tabs',
|
|
2028
|
-
selectedTab: (label, position, count) => `Tab ${position} of ${count}: ${label}`,
|
|
2029
|
-
tabLabelWithDetail: (label, detail) => `${label}, ${detail}`,
|
|
2030
|
-
tabHasErrors: (count) => `${count} error${count === 1 ? '' : 's'}`,
|
|
2031
|
-
moreTabsLabel: (count) => `${count} more`,
|
|
2032
|
-
previousTab: 'Previous tab',
|
|
2033
|
-
nextTab: 'Next tab',
|
|
2034
|
-
closeTab: (label) => `Close "${label}"`,
|
|
2035
|
-
addTab: 'Add tab',
|
|
2036
|
-
commitFailedRetry: 'Tab change refused - retry?',
|
|
2037
|
-
commitInFlight: 'Switching tab…',
|
|
2038
|
-
commitRolledBackTo: (originLabel) => `Could not save changes - reverted to "${originLabel}".`,
|
|
2039
|
-
};
|
|
2040
|
-
/**
|
|
2041
|
-
* DI token for the tabs i18n bundle. `providedIn: 'root'` with
|
|
2042
|
-
* English defaults.
|
|
2043
|
-
*
|
|
2044
|
-
* @category common/tabs/i18n
|
|
2045
|
-
* @wcag AA
|
|
2046
|
-
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/i18n/tabs-i18n.ts
|
|
2047
|
-
* @since 0.1.0
|
|
2048
|
-
*/
|
|
2049
|
-
const CNGX_TABS_I18N = new InjectionToken('CngxTabsI18n', {
|
|
2050
|
-
providedIn: 'root',
|
|
2051
|
-
factory: () => TABS_I18N_DEFAULTS,
|
|
2052
|
-
});
|
|
2053
|
-
/**
|
|
2054
|
-
* Brands an i18n-mutator with the `_target` discriminator.
|
|
2055
|
-
*
|
|
2056
|
-
* @internal
|
|
2057
|
-
*/
|
|
2058
|
-
function defineTabsI18nFeature(fn) {
|
|
2059
|
-
return Object.assign(fn, { _target: 'i18n' });
|
|
2060
|
-
}
|
|
2061
|
-
/**
|
|
2062
|
-
* Override i18n labels via a partial bundle - unset keys keep the
|
|
2063
|
-
* English default. Same shape as `withTabsAriaLabels` /
|
|
2064
|
-
* `withTabsFallbackLabels` so `provideCngxTabs` composes both
|
|
2065
|
-
* surfaces uniformly.
|
|
2066
|
-
*
|
|
2067
|
-
* @category common/tabs/i18n
|
|
2068
|
-
*/
|
|
2069
|
-
function withTabsI18nLabels(overrides) {
|
|
2070
|
-
return defineTabsI18nFeature((bundle) => ({ ...bundle, ...overrides }));
|
|
2071
|
-
}
|
|
2072
|
-
function resolveI18nFeatures(features) {
|
|
2073
|
-
return features.reduce((bundle, feat) => feat(bundle), TABS_I18N_DEFAULTS);
|
|
2074
|
-
}
|
|
2075
|
-
/**
|
|
2076
|
-
* Provider for the tabs i18n bundle. Compose `withTabsI18nLabels(...)`
|
|
2077
|
-
* (and future i18n `with*` features); unset keys fall back to the
|
|
2078
|
-
* English default.
|
|
2079
|
-
*
|
|
2080
|
-
* ```ts
|
|
2081
|
-
* bootstrapApplication(AppComponent, {
|
|
2082
|
-
* providers: [
|
|
2083
|
-
* provideTabsI18n(
|
|
2084
|
-
* withTabsI18nLabels({ tabsLabel: 'Reiter', previousTab: 'Vorheriger' }),
|
|
2085
|
-
* ),
|
|
2086
|
-
* ],
|
|
2087
|
-
* });
|
|
2088
|
-
* ```
|
|
2089
|
-
*
|
|
2090
|
-
* @category common/tabs/i18n
|
|
2091
|
-
*/
|
|
2092
|
-
function provideTabsI18n(...features) {
|
|
2093
|
-
return {
|
|
2094
|
-
provide: CNGX_TABS_I18N,
|
|
2095
|
-
useValue: resolveI18nFeatures(features),
|
|
2096
|
-
};
|
|
2097
|
-
}
|
|
2098
|
-
/**
|
|
2099
|
-
* Inject the resolved tabs i18n bundle.
|
|
2100
|
-
*
|
|
2101
|
-
* @category common/tabs/i18n
|
|
2102
|
-
*/
|
|
2103
|
-
function injectTabsI18n() {
|
|
2104
|
-
return inject(CNGX_TABS_I18N);
|
|
2105
|
-
}
|
|
2106
|
-
|
|
2107
2309
|
function partitionFeatures(features) {
|
|
2108
2310
|
const config = [];
|
|
2109
2311
|
const i18n = [];
|
|
@@ -2188,7 +2390,9 @@ function provideCngxTabs(...features) {
|
|
|
2188
2390
|
function provideCngxTabsAt(...features) {
|
|
2189
2391
|
const { config, i18n } = partitionFeatures(features);
|
|
2190
2392
|
return [
|
|
2191
|
-
|
|
2393
|
+
// Gate like i18n: an i18n-only call must not plant an empty config
|
|
2394
|
+
// at this injector level and shadow an app-wide provideTabsConfig.
|
|
2395
|
+
...(config.length > 0 ? provideTabsConfigAt(...config) : []),
|
|
2192
2396
|
...(i18n.length > 0 ? [provideTabsI18n(...i18n)] : []),
|
|
2193
2397
|
];
|
|
2194
2398
|
}
|
|
@@ -2660,33 +2864,107 @@ function createTabDismissals(opts) {
|
|
|
2660
2864
|
const resolvedAddable = computed(() => opts.addable() ?? opts.config.addable ?? false, ...(ngDevMode ? [{ debugName: "resolvedAddable" }] : /* istanbul ignore next */ []));
|
|
2661
2865
|
const closeIconContextCache = new WeakMap();
|
|
2662
2866
|
const isTabClosable = (tab) => tab.closable() ?? resolvedClosable();
|
|
2867
|
+
// 1-based position per tab id, derived once per tab list, so a close-button
|
|
2868
|
+
// label never scans the strip.
|
|
2869
|
+
const tabIds = computed(() => opts.host.tabs().map((tab) => tab.id), { ...(ngDevMode ? { debugName: "tabIds" } : /* istanbul ignore next */ {}), equal: arrayEqual });
|
|
2870
|
+
const positionById = computed(() => new Map(tabIds().map((id, index) => [id, index + 1])), ...(ngDevMode ? [{ debugName: "positionById" }] : /* istanbul ignore next */ []));
|
|
2871
|
+
// The close request only ASKS the consumer to remove the tab - the
|
|
2872
|
+
// removal may land asynchronously (or never). Focus restore and the
|
|
2873
|
+
// closed announcement key on a requested id actually leaving the
|
|
2874
|
+
// registry, not on the next render after the request. Requests enter
|
|
2875
|
+
// via handleClose (the only writer); landed ids are pruned on the
|
|
2876
|
+
// next request, so the map stays interaction-bounded.
|
|
2877
|
+
const pendingCloseLabels = signal(new Map(), ...(ngDevMode ? [{ debugName: "pendingCloseLabels" }] : /* istanbul ignore next */ []));
|
|
2878
|
+
// Landed-close phrase, purely derived from the registry transition:
|
|
2879
|
+
// an id that was present in the previous registry emission, carries a
|
|
2880
|
+
// pending close request, and is gone from the current one has landed.
|
|
2881
|
+
// `prev.source` supplies the departed handle (and its label) without
|
|
2882
|
+
// a managed side-slot.
|
|
2883
|
+
const closedAnnouncement = linkedSignal({ ...(ngDevMode ? { debugName: "closedAnnouncement" } : /* istanbul ignore next */ {}), source: () => opts.host.tabs(),
|
|
2884
|
+
computation: (tabs, prev) => {
|
|
2885
|
+
if (prev === undefined) {
|
|
2886
|
+
return '';
|
|
2887
|
+
}
|
|
2888
|
+
const pending = pendingCloseLabels();
|
|
2889
|
+
const currentIds = new Set(tabs.map((tab) => tab.id));
|
|
2890
|
+
const landed = prev.source.find((tab) => !currentIds.has(tab.id) && pending.has(tab.id));
|
|
2891
|
+
if (landed === undefined) {
|
|
2892
|
+
return prev.value;
|
|
2893
|
+
}
|
|
2894
|
+
// Feeds the live region: copy is read untracked so a language
|
|
2895
|
+
// switch does not re-announce the last close.
|
|
2896
|
+
const label = pending.get(landed.id) ?? '';
|
|
2897
|
+
return untracked(() => opts.i18n().closedTab(label));
|
|
2898
|
+
} });
|
|
2899
|
+
const restoreFocus = () => {
|
|
2900
|
+
// Skin-agnostic lookup: `[role="tab"]` + `data-tab-id` are the
|
|
2901
|
+
// ARIA/data contract every skin must honour (mirrors the keyboard
|
|
2902
|
+
// nav's focus targeting); class names are skin-owned and a rename
|
|
2903
|
+
// must not silently break focus restoration.
|
|
2904
|
+
const activeId = opts.host.activeId();
|
|
2905
|
+
const active = activeId === null
|
|
2906
|
+
? null
|
|
2907
|
+
: (Array.from(opts.hostElement.querySelectorAll('[role="tab"]')).find((button) => button.getAttribute('data-tab-id') === activeId) ?? null);
|
|
2908
|
+
const add = opts.hostElement.querySelector('[data-tab-add]');
|
|
2909
|
+
const target = active ?? add;
|
|
2910
|
+
if (target) {
|
|
2911
|
+
target.focus();
|
|
2912
|
+
return;
|
|
2913
|
+
}
|
|
2914
|
+
opts.hostElement.tabIndex = -1;
|
|
2915
|
+
opts.hostElement.focus();
|
|
2916
|
+
};
|
|
2917
|
+
// Pure side effect - no signal writes. The once-per-landing guard is
|
|
2918
|
+
// plain imperative bookkeeping, not reactive state.
|
|
2919
|
+
const focusRestoredIds = new Set();
|
|
2920
|
+
effect(() => {
|
|
2921
|
+
const tabs = opts.host.tabs();
|
|
2922
|
+
const pending = pendingCloseLabels();
|
|
2923
|
+
untracked(() => {
|
|
2924
|
+
const landed = [...pending.keys()].filter((id) => !tabs.some((tab) => tab.id === id) && !focusRestoredIds.has(id));
|
|
2925
|
+
if (landed.length === 0) {
|
|
2926
|
+
return;
|
|
2927
|
+
}
|
|
2928
|
+
for (const id of landed) {
|
|
2929
|
+
focusRestoredIds.add(id);
|
|
2930
|
+
}
|
|
2931
|
+
// Restore focus once the removal has rendered: the new active
|
|
2932
|
+
// tab, then the add button, and finally the group element itself
|
|
2933
|
+
// (made programmatically focusable) so focus never falls to
|
|
2934
|
+
// `<body>` when the strip empties with no add button (APG).
|
|
2935
|
+
afterNextRender(restoreFocus, { injector: opts.injector });
|
|
2936
|
+
});
|
|
2937
|
+
}, { injector: opts.injector });
|
|
2663
2938
|
const handleClose = (tab, event) => {
|
|
2664
2939
|
event?.stopPropagation();
|
|
2665
2940
|
if (!isTabClosable(tab)) {
|
|
2666
2941
|
return;
|
|
2667
2942
|
}
|
|
2943
|
+
pendingCloseLabels.update((current) => {
|
|
2944
|
+
const next = new Map(
|
|
2945
|
+
// Prune requests that already landed - keeps the map bounded and
|
|
2946
|
+
// stops a later consumer-driven removal of a RE-ADDED same id
|
|
2947
|
+
// from reading as a close.
|
|
2948
|
+
[...current].filter(([id]) => opts.host.tabs().some((tab2) => tab2.id === id)));
|
|
2949
|
+
next.set(tab.id, tab.label() ?? '');
|
|
2950
|
+
focusRestoredIds.delete(tab.id);
|
|
2951
|
+
return next;
|
|
2952
|
+
});
|
|
2668
2953
|
opts.host.requestClose(tab.id);
|
|
2669
|
-
// Restore focus once the consumer's removal has rendered: the new
|
|
2670
|
-
// active tab, then the add button, and finally the group element
|
|
2671
|
-
// itself (made programmatically focusable) so focus never falls to
|
|
2672
|
-
// `<body>` when the strip empties with no add button (APG).
|
|
2673
|
-
afterNextRender(() => {
|
|
2674
|
-
const active = opts.hostElement.querySelector('.cngx-tabs__tab[aria-selected="true"]');
|
|
2675
|
-
const add = opts.hostElement.querySelector('.cngx-tabs__add');
|
|
2676
|
-
const target = active ?? add;
|
|
2677
|
-
if (target) {
|
|
2678
|
-
target.focus();
|
|
2679
|
-
return;
|
|
2680
|
-
}
|
|
2681
|
-
opts.hostElement.tabIndex = -1;
|
|
2682
|
-
opts.hostElement.focus();
|
|
2683
|
-
}, { injector: opts.injector });
|
|
2684
2954
|
};
|
|
2685
2955
|
return {
|
|
2686
2956
|
resolvedClosable,
|
|
2687
2957
|
resolvedAddable,
|
|
2688
2958
|
isTabClosable,
|
|
2689
|
-
|
|
2959
|
+
// An unlabelled tab is named by position, never as `Close ""`.
|
|
2960
|
+
closeButtonLabel: (tab) => {
|
|
2961
|
+
const i18n = opts.i18n();
|
|
2962
|
+
const label = tab.label() ?? '';
|
|
2963
|
+
if (label !== '') {
|
|
2964
|
+
return i18n.closeTab(label);
|
|
2965
|
+
}
|
|
2966
|
+
return i18n.closeTab(i18n.unlabeledTab(positionById().get(tab.id) ?? 0));
|
|
2967
|
+
},
|
|
2690
2968
|
closeIconContextFor: (tab) => {
|
|
2691
2969
|
let ctx = closeIconContextCache.get(tab);
|
|
2692
2970
|
if (!ctx) {
|
|
@@ -2695,6 +2973,7 @@ function createTabDismissals(opts) {
|
|
|
2695
2973
|
}
|
|
2696
2974
|
return ctx;
|
|
2697
2975
|
},
|
|
2976
|
+
closedAnnouncement: closedAnnouncement.asReadonly(),
|
|
2698
2977
|
handleClose,
|
|
2699
2978
|
handleTabKeydown: (tab, event) => {
|
|
2700
2979
|
if (event.key === 'Delete' && isTabClosable(tab)) {
|
|
@@ -2797,6 +3076,32 @@ function createTabKeyboardNav(opts) {
|
|
|
2797
3076
|
const buttons = Array.from(opts.hostElement.querySelectorAll('[role="tab"]'));
|
|
2798
3077
|
buttons.find((button) => button.getAttribute('data-tab-id') === id)?.focus();
|
|
2799
3078
|
};
|
|
3079
|
+
if (opts.injector) {
|
|
3080
|
+
effect(() => {
|
|
3081
|
+
if (opts.host.commitTransition.current() !== 'error') {
|
|
3082
|
+
return;
|
|
3083
|
+
}
|
|
3084
|
+
untracked(() => {
|
|
3085
|
+
// Only release focus that this tablist is actually holding on a
|
|
3086
|
+
// non-active tab button - never steal focus from elsewhere.
|
|
3087
|
+
const focused = document.activeElement;
|
|
3088
|
+
if (!(focused instanceof HTMLElement) || !opts.hostElement.contains(focused)) {
|
|
3089
|
+
return;
|
|
3090
|
+
}
|
|
3091
|
+
if (focused.getAttribute('role') !== 'tab') {
|
|
3092
|
+
return;
|
|
3093
|
+
}
|
|
3094
|
+
const activeId = opts.host.activeId();
|
|
3095
|
+
if (activeId === null || focused.getAttribute('data-tab-id') === activeId) {
|
|
3096
|
+
return;
|
|
3097
|
+
}
|
|
3098
|
+
const idx = opts.host.tabs().findIndex((tab) => tab.id === activeId);
|
|
3099
|
+
if (idx >= 0) {
|
|
3100
|
+
focusTabAt(idx);
|
|
3101
|
+
}
|
|
3102
|
+
});
|
|
3103
|
+
}, { injector: opts.injector });
|
|
3104
|
+
}
|
|
2800
3105
|
return {
|
|
2801
3106
|
tabTabindex: (tab) => (tab.id === opts.host.activeId() ? 0 : -1),
|
|
2802
3107
|
handleKeydown: (event) => {
|
|
@@ -2925,13 +3230,18 @@ function createTabGroupTemplateBindings(opts) {
|
|
|
2925
3230
|
*/
|
|
2926
3231
|
function createTabGroupAnnouncements(options) {
|
|
2927
3232
|
const { presenter, i18n, config, ariaLabel, ariaLabelledBy } = options;
|
|
2928
|
-
const
|
|
2929
|
-
const
|
|
3233
|
+
const closedAnnouncement = options.closedAnnouncement ?? (() => '');
|
|
3234
|
+
const fallbackLabels = coerceSignal(config.fallbackLabels);
|
|
3235
|
+
const defaultFallbackLabels = coerceSignal(TABS_CONFIG_DEFAULTS.fallbackLabels);
|
|
3236
|
+
const ariaLabels = coerceSignal(config.ariaLabels);
|
|
3237
|
+
const tabsRoleDescription = computed(() => fallbackLabels()?.tabRoleDescription ?? defaultFallbackLabels().tabRoleDescription, ...(ngDevMode ? [{ debugName: "tabsRoleDescription" }] : /* istanbul ignore next */ []));
|
|
3238
|
+
const tabPanelRoleDescription = computed(() => fallbackLabels()?.tabPanelRoleDescription ??
|
|
3239
|
+
defaultFallbackLabels().tabPanelRoleDescription, ...(ngDevMode ? [{ debugName: "tabPanelRoleDescription" }] : /* istanbul ignore next */ []));
|
|
2930
3240
|
const resolvedAriaLabel = computed(() => {
|
|
2931
3241
|
if (ariaLabelledBy()) {
|
|
2932
3242
|
return null;
|
|
2933
3243
|
}
|
|
2934
|
-
return ariaLabel() ??
|
|
3244
|
+
return ariaLabel() ?? ariaLabels()?.tabsRegion ?? i18n().tabsLabel;
|
|
2935
3245
|
}, ...(ngDevMode ? [{ debugName: "resolvedAriaLabel" }] : /* istanbul ignore next */ []));
|
|
2936
3246
|
// `prev?.source` = source value before the most recent change -
|
|
2937
3247
|
// prior activeIndex without an `effect`-driven slot (Pillar 1).
|
|
@@ -2939,10 +3249,31 @@ function createTabGroupAnnouncements(options) {
|
|
|
2939
3249
|
const priorActiveIndex = linkedSignal({ ...(ngDevMode ? { debugName: "priorActiveIndex" } : /* istanbul ignore next */ {}), source: () => presenter.activeIndex(),
|
|
2940
3250
|
computation: (curr, prev) => prev?.source ?? curr,
|
|
2941
3251
|
equal: Object.is });
|
|
3252
|
+
// Close phrase with commit-activity expiry: a NEW phrase (re)arms; a
|
|
3253
|
+
// commit status change while armed spends the phrase, so a later
|
|
3254
|
+
// return to idle re-renders '' instead of re-announcing the stale
|
|
3255
|
+
// close. Mount seeds with the current phrase (never empty-coerced).
|
|
3256
|
+
const closedPhrase = createAnnouncementPhrase({
|
|
3257
|
+
source: () => ({
|
|
3258
|
+
phrase: closedAnnouncement(),
|
|
3259
|
+
status: presenter.commitTransition.current(),
|
|
3260
|
+
}),
|
|
3261
|
+
arm: (curr, prev) => (curr.phrase !== prev.phrase ? curr.phrase : null),
|
|
3262
|
+
spend: (curr, prev) => curr.status !== prev.status,
|
|
3263
|
+
seed: (src) => src.phrase,
|
|
3264
|
+
});
|
|
3265
|
+
// Copy and tab labels (which a consumer may translate) are read untracked
|
|
3266
|
+
// in the live region: a language switch must not re-speak the last phrase;
|
|
3267
|
+
// the next transition speaks the new language.
|
|
2942
3268
|
const liveAnnouncement = computed(() => {
|
|
3269
|
+
// Read the close phrase EAGERLY: linkedSignal only observes status
|
|
3270
|
+
// snapshots it is actually read under, so a lazy read at the idle
|
|
3271
|
+
// arm would skip the intermediate 'pending' and never spend the
|
|
3272
|
+
// phrase.
|
|
3273
|
+
const closeConfirmation = closedPhrase();
|
|
2943
3274
|
const current = presenter.commitTransition.current();
|
|
2944
3275
|
if (current === 'pending') {
|
|
2945
|
-
return i18n.commitInFlight;
|
|
3276
|
+
return untracked(() => i18n().commitInFlight);
|
|
2946
3277
|
}
|
|
2947
3278
|
if (current === 'error') {
|
|
2948
3279
|
// No `previous === 'pending'` guard - sync rejections collapse
|
|
@@ -2952,12 +3283,13 @@ function createTabGroupAnnouncements(options) {
|
|
|
2952
3283
|
const failedIdx = presenter.lastFailedIndex();
|
|
2953
3284
|
const originIdx = presenter.originIndexDuringCommit();
|
|
2954
3285
|
if (failedIdx !== undefined && originIdx !== undefined) {
|
|
2955
|
-
const
|
|
3286
|
+
const origin = presenter.tabs()[originIdx];
|
|
3287
|
+
const originLabel = origin ? untracked(origin.label) : undefined;
|
|
2956
3288
|
if (originLabel) {
|
|
2957
|
-
return i18n.commitRolledBackTo(originLabel);
|
|
3289
|
+
return untracked(() => i18n().commitRolledBackTo(originLabel));
|
|
2958
3290
|
}
|
|
2959
3291
|
}
|
|
2960
|
-
return i18n.commitFailedRetry;
|
|
3292
|
+
return untracked(() => i18n().commitFailedRetry);
|
|
2961
3293
|
}
|
|
2962
3294
|
if (current === 'success') {
|
|
2963
3295
|
const tabs = presenter.tabs();
|
|
@@ -2966,18 +3298,24 @@ function createTabGroupAnnouncements(options) {
|
|
|
2966
3298
|
if (!tab) {
|
|
2967
3299
|
return '';
|
|
2968
3300
|
}
|
|
2969
|
-
const label = tab.label
|
|
2970
|
-
const
|
|
3301
|
+
const label = untracked(tab.label) ?? '';
|
|
3302
|
+
const count = tabs.length;
|
|
2971
3303
|
const prevIdx = priorActiveIndex();
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
3304
|
+
return untracked(() => {
|
|
3305
|
+
const copy = i18n();
|
|
3306
|
+
const positionPhrase = copy.selectedTab(label, idx + 1, count);
|
|
3307
|
+
if (idx > prevIdx) {
|
|
3308
|
+
return copy.nextTab(positionPhrase);
|
|
3309
|
+
}
|
|
3310
|
+
if (idx < prevIdx) {
|
|
3311
|
+
return copy.previousTab(positionPhrase);
|
|
3312
|
+
}
|
|
3313
|
+
return positionPhrase;
|
|
3314
|
+
});
|
|
2979
3315
|
}
|
|
2980
|
-
|
|
3316
|
+
// Idle: the landed-close confirmation is the only phrase that may
|
|
3317
|
+
// hold the region, and only until the next commit activity.
|
|
3318
|
+
return closeConfirmation;
|
|
2981
3319
|
}, ...(ngDevMode ? [{ debugName: "liveAnnouncement" }] : /* istanbul ignore next */ []));
|
|
2982
3320
|
function statusPhrase(tab) {
|
|
2983
3321
|
if (!tab.hasError()) {
|
|
@@ -2992,14 +3330,15 @@ function createTabGroupAnnouncements(options) {
|
|
|
2992
3330
|
if (directMessage) {
|
|
2993
3331
|
return directMessage;
|
|
2994
3332
|
}
|
|
2995
|
-
return i18n.tabHasErrors(aggregator?.errorCount() ?? 1);
|
|
3333
|
+
return i18n().tabHasErrors(aggregator?.errorCount() ?? 1);
|
|
2996
3334
|
}
|
|
2997
3335
|
function tabAriaLabel(tab, position) {
|
|
2998
3336
|
const tabs = presenter.tabs();
|
|
2999
3337
|
const label = tab.label() ?? '';
|
|
3000
3338
|
const detail = tab.subLabel();
|
|
3001
|
-
const
|
|
3002
|
-
|
|
3339
|
+
const copy = i18n();
|
|
3340
|
+
const labelPart = detail ? copy.tabLabelWithDetail(label, detail) : label;
|
|
3341
|
+
return copy.selectedTab(labelPart, position, tabs.length);
|
|
3003
3342
|
}
|
|
3004
3343
|
// Eager seed - `linkedSignal` is lazy and the success arm doesn't
|
|
3005
3344
|
// touch the tracker at construction (commitTransition is `idle`),
|
|
@@ -3065,7 +3404,13 @@ function createTabNavAnnouncement(options) {
|
|
|
3065
3404
|
if (id === null || id === priorActiveId()) {
|
|
3066
3405
|
return '';
|
|
3067
3406
|
}
|
|
3068
|
-
|
|
3407
|
+
// The label may be translated by the consumer; read untracked so a
|
|
3408
|
+
// language switch does not re-announce the landing section.
|
|
3409
|
+
const landed = presenter.tabs().find((tab) => tab.id === id);
|
|
3410
|
+
if (!landed) {
|
|
3411
|
+
return '';
|
|
3412
|
+
}
|
|
3413
|
+
return untracked(landed.label) ?? '';
|
|
3069
3414
|
}, ...(ngDevMode ? [{ debugName: "liveAnnouncement" }] : /* istanbul ignore next */ []));
|
|
3070
3415
|
afterNextRender(() => {
|
|
3071
3416
|
queueMicrotask(() => {
|
|
@@ -3122,10 +3467,12 @@ function triggerContextEqual(a, b) {
|
|
|
3122
3467
|
return a.count === b.count && a.hiddenTabs === b.hiddenTabs;
|
|
3123
3468
|
}
|
|
3124
3469
|
/**
|
|
3125
|
-
* Structural equal - same length + per-index `id` and
|
|
3126
|
-
* Without this, every IO emission yields fresh
|
|
3470
|
+
* Structural equal - same length + per-index `id`, `label`, and
|
|
3471
|
+
* `disabled`. Without this, every IO emission yields fresh
|
|
3127
3472
|
* `ActiveDescendantItem[]` references and AD's `resolvedItems`
|
|
3128
|
-
* cascade fires for an unchanged visible-tab set.
|
|
3473
|
+
* cascade fires for an unchanged visible-tab set. `label` is compared
|
|
3474
|
+
* because typeahead matches on it - omitting it would leave the
|
|
3475
|
+
* overflow list matching against stale labels after a rename.
|
|
3129
3476
|
*
|
|
3130
3477
|
* @internal
|
|
3131
3478
|
*/
|
|
@@ -3137,7 +3484,7 @@ function adItemsEqual(a, b) {
|
|
|
3137
3484
|
return false;
|
|
3138
3485
|
}
|
|
3139
3486
|
for (let i = 0; i < a.length; i++) {
|
|
3140
|
-
if (a[i].id !== b[i].id || a[i].disabled !== b[i].disabled) {
|
|
3487
|
+
if (a[i].id !== b[i].id || a[i].label !== b[i].label || a[i].disabled !== b[i].disabled) {
|
|
3141
3488
|
return false;
|
|
3142
3489
|
}
|
|
3143
3490
|
}
|
|
@@ -3180,10 +3527,20 @@ function createTabOverflowTemplateBindings(opts) {
|
|
|
3180
3527
|
itemContextCache.set(tab, { context, disabled, index });
|
|
3181
3528
|
return context;
|
|
3182
3529
|
};
|
|
3530
|
+
// 1-based strip position per tab id, derived once per tab list.
|
|
3531
|
+
const tabIds = computed(() => opts.tabs().map((tab) => tab.id), { ...(ngDevMode ? { debugName: "tabIds" } : /* istanbul ignore next */ {}), equal: arrayEqual });
|
|
3532
|
+
const positionById = computed(() => new Map(tabIds().map((id, index) => [id, index + 1])), ...(ngDevMode ? [{ debugName: "positionById" }] : /* istanbul ignore next */ []));
|
|
3533
|
+
const itemLabel = (tab) => {
|
|
3534
|
+
const label = tab.label() ?? '';
|
|
3535
|
+
if (label !== '') {
|
|
3536
|
+
return label;
|
|
3537
|
+
}
|
|
3538
|
+
return opts.i18n().unlabeledTab(positionById().get(tab.id) ?? 0);
|
|
3539
|
+
};
|
|
3183
3540
|
const adItems = computed(() => opts.hiddenTabs().map((tab) => ({
|
|
3184
3541
|
id: tabOverflowOptionId(tab),
|
|
3185
3542
|
value: tab,
|
|
3186
|
-
label: tab
|
|
3543
|
+
label: itemLabel(tab),
|
|
3187
3544
|
disabled: tab.disabled(),
|
|
3188
3545
|
})), { ...(ngDevMode ? { debugName: "adItems" } : /* istanbul ignore next */ {}), equal: adItemsEqual });
|
|
3189
3546
|
return {
|
|
@@ -3191,6 +3548,7 @@ function createTabOverflowTemplateBindings(opts) {
|
|
|
3191
3548
|
itemTemplate,
|
|
3192
3549
|
triggerContext,
|
|
3193
3550
|
buildItemContext,
|
|
3551
|
+
itemLabel,
|
|
3194
3552
|
adItems,
|
|
3195
3553
|
};
|
|
3196
3554
|
}
|
|
@@ -3405,5 +3763,5 @@ const CNGX_DIRECTIVE_BY_ID_MAP_FACTORY = new InjectionToken('CngxDirectiveByIdMa
|
|
|
3405
3763
|
* Generated bundle index. Do not edit.
|
|
3406
3764
|
*/
|
|
3407
3765
|
|
|
3408
|
-
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_NAV_HOST, CNGX_TAB_OVERFLOW_DOM_ADAPTER_FACTORY, CNGX_TAB_PANEL_HOST, CNGX_TAB_URL_MATCH_STRATEGY, CngxTab, CngxTabAddIcon, CngxTabBusySpinner, CngxTabCloseIcon, CngxTabContent, CngxTabErrorBadge, CngxTabGroupPresenter, CngxTabIcon, CngxTabLabel, CngxTabLink, CngxTabOverflowItem, CngxTabOverflowTrigger, CngxTabRejectionIcon, CngxTabSubLabel, CngxTabsFragmentSync, CngxTabsRouteSync, createCngxTabOverflowDefaultDomAdapter, createDirectiveByIdMap, createDomAnchorRetry, createOrganismScrollSync, createOverflowPopoverHighlightSync, createTabDismissals, createTabGroupAnnouncements, createTabGroupTemplateBindings, createTabKeyboardNav, createTabNavAnnouncement, createTabOverflowTemplateBindings, createTabRouterCommit, createTabUrlMatch, 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, withTabsLinkAriaCurrent, withTabsPanelMode, withTabsRouteMatch, withTabsRouterSync, withTabsRovingLoop, withTabsSkin };
|
|
3766
|
+
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_TABS_LANGUAGE_EN, CNGX_TAB_GROUP_HOST, CNGX_TAB_NAV_HOST, CNGX_TAB_OVERFLOW_DOM_ADAPTER_FACTORY, CNGX_TAB_PANEL_HOST, CNGX_TAB_URL_MATCH_STRATEGY, CngxTab, CngxTabAddIcon, CngxTabBusySpinner, CngxTabCloseIcon, CngxTabContent, CngxTabErrorBadge, CngxTabGroupPresenter, CngxTabIcon, CngxTabLabel, CngxTabLink, CngxTabOverflowItem, CngxTabOverflowTrigger, CngxTabRejectionIcon, CngxTabSubLabel, CngxTabsFragmentSync, CngxTabsRouteSync, createCngxTabOverflowDefaultDomAdapter, createDirectiveByIdMap, createDomAnchorRetry, createOrganismScrollSync, createOverflowPopoverHighlightSync, createTabDismissals, createTabGroupAnnouncements, createTabGroupTemplateBindings, createTabKeyboardNav, createTabNavAnnouncement, createTabOverflowTemplateBindings, createTabRouterCommit, createTabUrlMatch, 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, withTabsLinkAriaCurrent, withTabsPanelMode, withTabsRouteMatch, withTabsRouterSync, withTabsRovingLoop, withTabsSkin };
|
|
3409
3767
|
//# sourceMappingURL=cngx-common-tabs.mjs.map
|