@cngx/common 0.1.0-rc.7 → 0.1.0-rc.9
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/command/README.md +29 -0
- package/data/README.md +15 -3
- package/dialog/README.md +23 -1
- package/fesm2022/cngx-common-a11y.mjs +517 -184
- package/fesm2022/cngx-common-a11y.mjs.map +1 -1
- package/fesm2022/cngx-common-audio.mjs +62 -17
- package/fesm2022/cngx-common-audio.mjs.map +1 -1
- package/fesm2022/cngx-common-card.mjs +301 -46
- package/fesm2022/cngx-common-card.mjs.map +1 -1
- package/fesm2022/cngx-common-chart.mjs +1221 -479
- package/fesm2022/cngx-common-chart.mjs.map +1 -1
- package/fesm2022/cngx-common-command.mjs +97 -16
- package/fesm2022/cngx-common-command.mjs.map +1 -1
- package/fesm2022/cngx-common-data.mjs +1496 -499
- package/fesm2022/cngx-common-data.mjs.map +1 -1
- package/fesm2022/cngx-common-dialog.mjs +236 -61
- package/fesm2022/cngx-common-dialog.mjs.map +1 -1
- package/fesm2022/cngx-common-display.mjs +364 -93
- package/fesm2022/cngx-common-display.mjs.map +1 -1
- package/fesm2022/cngx-common-interactive.mjs +2040 -1046
- package/fesm2022/cngx-common-interactive.mjs.map +1 -1
- package/fesm2022/cngx-common-layout.mjs +955 -125
- package/fesm2022/cngx-common-layout.mjs.map +1 -1
- package/fesm2022/cngx-common-popover.mjs +1293 -89
- package/fesm2022/cngx-common-popover.mjs.map +1 -1
- package/fesm2022/cngx-common-stepper.mjs +997 -453
- package/fesm2022/cngx-common-stepper.mjs.map +1 -1
- package/fesm2022/cngx-common-tabs.mjs +1794 -1265
- package/fesm2022/cngx-common-tabs.mjs.map +1 -1
- package/fesm2022/cngx-common-timeline.mjs +151 -61
- 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 +37 -1
- package/package.json +20 -7
- package/popover/README.md +58 -2
- package/schematics/collection.json +9 -0
- package/schematics/ng-add/index.js +9 -0
- package/schematics/ng-add/schema.json +91 -0
- package/schematics/package.json +3 -0
- package/stepper/README.md +11 -8
- 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-sheet.css +402 -0
- package/theming/components/cngx-popover.css +28 -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 +205 -28
- package/types/cngx-common-card.d.ts +201 -17
- package/types/cngx-common-chart.d.ts +345 -48
- package/types/cngx-common-command.d.ts +50 -10
- package/types/cngx-common-data.d.ts +743 -92
- package/types/cngx-common-dialog.d.ts +161 -10
- package/types/cngx-common-display.d.ts +356 -142
- package/types/cngx-common-interactive.d.ts +910 -226
- package/types/cngx-common-layout.d.ts +603 -32
- package/types/cngx-common-popover.d.ts +612 -49
- package/types/cngx-common-stepper.d.ts +526 -237
- package/types/cngx-common-tabs.d.ts +358 -75
- package/types/cngx-common-timeline.d.ts +108 -22
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { InjectionToken,
|
|
3
|
-
import { CNGX_COMMIT_CONTROLLER_FACTORY } from '@cngx/common/data';
|
|
4
|
-
import { createTransitionTracker, CNGX_STATEFUL, nextUid } from '@cngx/core/utils';
|
|
2
|
+
import { InjectionToken, inject, computed, makeEnvironmentProviders, model, input, Injector, output, signal, Directive, TemplateRef, contentChild, DestroyRef, Renderer2, ElementRef, effect, afterNextRender, untracked, linkedSignal, runInInjectionContext } from '@angular/core';
|
|
3
|
+
import { CNGX_COMMIT_CONTROLLER_FACTORY, createRefusedPhrase } from '@cngx/common/data';
|
|
4
|
+
import { createOverrideMerge, createTransitionTracker, CNGX_STATEFUL, nextUid, coerceSignal, createAnnouncementPhrase } from '@cngx/core/utils';
|
|
5
|
+
import { recordEqual, CngxRuntimeError, cngxDevWarn, 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, ActivatedRoute, NavigationEnd } 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,1600 @@ 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
|
+
unlabeledTabOfCount: 'Tab {position} of {count}',
|
|
45
|
+
previousTab: 'Previous tab: {tab}',
|
|
46
|
+
nextTab: 'Next tab: {tab}',
|
|
47
|
+
closeTab: 'Close "{label}"',
|
|
48
|
+
addTab: 'Add tab',
|
|
49
|
+
closedTab: 'Closed "{label}"',
|
|
50
|
+
closedUnlabeledTab: 'Tab closed',
|
|
51
|
+
commitFailedRetry: 'Could not switch tab - retry?',
|
|
52
|
+
commitInFlight: 'Switching tab…',
|
|
53
|
+
commitRolledBackTo: 'Could not save changes - reverted to "{origin}".',
|
|
54
|
+
commitRefused: 'Tab switch not allowed - stayed on "{origin}".',
|
|
55
|
+
commitRefusedGeneric: 'Tab switch not allowed.',
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @internal The English tabs section with the active pack's tabs section on
|
|
60
|
+
* top. Feeds both `CNGX_TABS_I18N` and the `CNGX_TABS_CONFIG` labels.
|
|
61
|
+
*/
|
|
62
|
+
const injectTabsLanguage = createLanguageSection('tabs', CNGX_TABS_LANGUAGE_EN);
|
|
63
|
+
/** @internal Turns a tabs section into the token's keys for a locale. */
|
|
64
|
+
function tabsBundleFrom(section, locale) {
|
|
33
65
|
return {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
},
|
|
66
|
+
tabsLabel: section.tabsLabel,
|
|
67
|
+
selectedTab: (label, position, count) => formatMessage(section.selectedTab, { label, position, count }, locale),
|
|
68
|
+
tabLabelWithDetail: (label, detail) => formatMessage(section.tabLabelWithDetail, { label, detail }, locale),
|
|
69
|
+
tabHasErrors: (count) => formatMessage(section.tabHasErrors, { count }, locale),
|
|
70
|
+
moreTabsLabel: (count) => formatMessage(section.moreTabsLabel, { count }, locale),
|
|
71
|
+
unlabeledTab: (position) => formatMessage(section.unlabeledTab, { position }, locale),
|
|
72
|
+
unlabeledTabOfCount: (position, count) => formatMessage(section.unlabeledTabOfCount, { position, count }, locale),
|
|
73
|
+
previousTab: (tab) => formatMessage(section.previousTab, { tab }, locale),
|
|
74
|
+
nextTab: (tab) => formatMessage(section.nextTab, { tab }, locale),
|
|
75
|
+
closeTab: (label) => formatMessage(section.closeTab, { label }, locale),
|
|
76
|
+
addTab: section.addTab,
|
|
77
|
+
closedTab: (label) => label ? formatMessage(section.closedTab, { label }, locale) : section.closedUnlabeledTab,
|
|
78
|
+
commitFailedRetry: section.commitFailedRetry,
|
|
79
|
+
commitInFlight: section.commitInFlight,
|
|
80
|
+
commitRolledBackTo: (origin) => formatMessage(section.commitRolledBackTo, { origin }, locale),
|
|
81
|
+
commitRefused: (origin) => formatMessage(section.commitRefused, { origin }, locale),
|
|
82
|
+
commitRefusedGeneric: section.commitRefusedGeneric,
|
|
44
83
|
};
|
|
45
84
|
}
|
|
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
|
-
};
|
|
85
|
+
/** @internal The tabs section of the active pack over English. */
|
|
86
|
+
function injectTabsSection() {
|
|
87
|
+
return injectTabsLanguage();
|
|
103
88
|
}
|
|
89
|
+
/** @internal Builds and reads the token, formatted for the reading locale. */
|
|
90
|
+
const tabsBundle = createSectionBundle({
|
|
91
|
+
section: injectTabsSection,
|
|
92
|
+
toBundle: tabsBundleFrom,
|
|
93
|
+
});
|
|
104
94
|
/**
|
|
105
|
-
* DI token for the
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
95
|
+
* DI token for the tabs i18n bundle, as a `Signal` so a runtime language
|
|
96
|
+
* switch re-renders every label it feeds. `providedIn: 'root'`: the tabs
|
|
97
|
+
* section of the active language pack over the English defaults, formatted
|
|
98
|
+
* for the app locale. Provide it through {@link provideTabsI18n}; a
|
|
99
|
+
* `{ provide, useValue }` entry must supply a `Signal<CngxTabsI18n>`.
|
|
110
100
|
*
|
|
111
|
-
* @category common/tabs
|
|
112
|
-
* @
|
|
101
|
+
* @category common/tabs/i18n
|
|
102
|
+
* @wcag AA
|
|
103
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/i18n/tabs-i18n.ts
|
|
113
104
|
* @since 0.1.0
|
|
114
105
|
*/
|
|
115
|
-
const
|
|
106
|
+
const CNGX_TABS_I18N = new InjectionToken('CngxTabsI18n', {
|
|
116
107
|
providedIn: 'root',
|
|
117
|
-
factory: () =>
|
|
108
|
+
factory: () => tabsBundle.build(),
|
|
118
109
|
});
|
|
110
|
+
/**
|
|
111
|
+
* Brands an i18n-mutator with the `_target` discriminator.
|
|
112
|
+
*
|
|
113
|
+
* @internal
|
|
114
|
+
*/
|
|
115
|
+
function defineTabsI18nFeature(fn) {
|
|
116
|
+
return Object.assign(fn, { _target: 'i18n' });
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Override i18n labels via a partial bundle - unset keys keep the
|
|
120
|
+
* language pack's copy, or the English default. Same shape as `withTabsAriaLabels` /
|
|
121
|
+
* `withTabsFallbackLabels` so `provideCngxTabs` composes both
|
|
122
|
+
* surfaces uniformly. Pass a `Signal` to switch the language at runtime.
|
|
123
|
+
*
|
|
124
|
+
* @category common/tabs/i18n
|
|
125
|
+
*/
|
|
126
|
+
function withTabsI18nLabels(overrides) {
|
|
127
|
+
return defineTabsI18nFeature((bundle) => createOverrideMerge(bundle, overrides));
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Provider for the tabs i18n bundle. Compose `withTabsI18nLabels(...)`
|
|
131
|
+
* (and future i18n `with*` features); unset keys fall back to the
|
|
132
|
+
* language pack, then English. The features apply on top of the active pack.
|
|
133
|
+
*
|
|
134
|
+
* ```ts
|
|
135
|
+
* bootstrapApplication(AppComponent, {
|
|
136
|
+
* providers: [
|
|
137
|
+
* provideTabsI18n(
|
|
138
|
+
* withTabsI18nLabels({ tabsLabel: 'Reiter', addTab: 'Neuer Reiter' }),
|
|
139
|
+
* ),
|
|
140
|
+
* ],
|
|
141
|
+
* });
|
|
142
|
+
* ```
|
|
143
|
+
*
|
|
144
|
+
* @category common/tabs/i18n
|
|
145
|
+
*/
|
|
146
|
+
function provideTabsI18n(...features) {
|
|
147
|
+
return {
|
|
148
|
+
provide: CNGX_TABS_I18N,
|
|
149
|
+
useFactory: () => tabsBundle.build(features),
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Inject the resolved tabs i18n bundle. Read it inside a `computed()`,
|
|
154
|
+
* template or handler so a language switch reaches the label.
|
|
155
|
+
*
|
|
156
|
+
* @category common/tabs/i18n
|
|
157
|
+
*/
|
|
158
|
+
function injectTabsI18n() {
|
|
159
|
+
return tabsBundle.resolve(inject(CNGX_TABS_I18N));
|
|
160
|
+
}
|
|
119
161
|
|
|
120
162
|
/**
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
* to
|
|
124
|
-
|
|
125
|
-
|
|
163
|
+
* @internal - library defaults of {@link CNGX_TABS_CONFIG}. Exported from
|
|
164
|
+
* this file (not from `public-api.ts`) so the announcement factory falls
|
|
165
|
+
* back to the same `fallbackLabels` strings instead of repeating them.
|
|
166
|
+
*/
|
|
167
|
+
const TABS_CONFIG_DEFAULTS = {
|
|
168
|
+
defaultOrientation: 'horizontal',
|
|
169
|
+
defaultLoop: true,
|
|
170
|
+
defaultCommitMode: 'optimistic',
|
|
171
|
+
fragmentSyncMode: 'fragment',
|
|
172
|
+
fragmentSyncParam: 'tab',
|
|
173
|
+
// routeMatch stays unset: the host-flavour default is the right answer
|
|
174
|
+
// for both organisms, and pinning one here would silently flip the
|
|
175
|
+
// other. linkAriaCurrent defaults at the link, not here.
|
|
176
|
+
linkAriaCurrent: 'page',
|
|
177
|
+
ariaLabels: {
|
|
178
|
+
tabsRegion: CNGX_TABS_LANGUAGE_EN.tabsRegion,
|
|
179
|
+
},
|
|
180
|
+
fallbackLabels: {
|
|
181
|
+
// W3C ARIA tablist convention - kept distinct from
|
|
182
|
+
// `i18n.tabsLabel` so AT doesn't read the same string twice
|
|
183
|
+
// back-to-back across `aria-roledescription` and `aria-label`.
|
|
184
|
+
tabRoleDescription: CNGX_TABS_LANGUAGE_EN.tabRoleDescription,
|
|
185
|
+
tabPanelRoleDescription: CNGX_TABS_LANGUAGE_EN.tabPanelRoleDescription,
|
|
186
|
+
},
|
|
187
|
+
overflowStabilizeMs: 100,
|
|
188
|
+
overflowMaxDeferMs: 250,
|
|
189
|
+
templates: {},
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* DI token for the resolved tabs config. \
|
|
193
|
+
* `providedIn: 'root'` with the library defaults; override via {@link provideTabsConfig}
|
|
194
|
+
* (root) or {@link provideTabsConfigAt} (component scope).
|
|
126
195
|
*
|
|
127
196
|
* @category common/tabs
|
|
128
197
|
* @wcag AA
|
|
129
|
-
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/
|
|
198
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/tabs-config.ts
|
|
130
199
|
* @since 0.1.0
|
|
131
200
|
*/
|
|
132
|
-
const
|
|
133
|
-
|
|
201
|
+
const CNGX_TABS_CONFIG = new InjectionToken('CngxTabsConfig', {
|
|
202
|
+
providedIn: 'root',
|
|
203
|
+
factory: () => resolveFeatures([]),
|
|
204
|
+
});
|
|
134
205
|
/**
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
* so `<cngx-toast-on />` / `<cngx-banner-on />` compose without
|
|
140
|
-
* `[state]` wiring.
|
|
206
|
+
* Internal helper that brands a config-mutator function with the
|
|
207
|
+
* `_target` discriminator. \
|
|
208
|
+
* Every `with*` config feature returns one
|
|
209
|
+
* of these.
|
|
141
210
|
*
|
|
142
|
-
*
|
|
143
|
-
|
|
144
|
-
|
|
211
|
+
* @internal
|
|
212
|
+
*/
|
|
213
|
+
function defineTabsConfigFeature(fn) {
|
|
214
|
+
return Object.assign(fn, { _target: 'config' });
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Override the default orientation. Per-instance `[orientation]`
|
|
218
|
+
* still wins; this changes the cascade default only.
|
|
145
219
|
*
|
|
146
220
|
* @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
221
|
*/
|
|
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 });
|
|
222
|
+
function withTabsDefaultOrientation(orientation) {
|
|
223
|
+
return defineTabsConfigFeature((cfg) => ({
|
|
224
|
+
...cfg,
|
|
225
|
+
defaultOrientation: orientation,
|
|
226
|
+
}));
|
|
420
227
|
}
|
|
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
228
|
/**
|
|
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.
|
|
229
|
+
* @deprecated Use {@link withTabsDefaultOrientation}. The unprefixed name
|
|
230
|
+
* collides with the stepper family's identical symbol when both libs
|
|
231
|
+
* are auto-imported. The alias stays for one minor release before
|
|
232
|
+
* removal.
|
|
445
233
|
*
|
|
446
|
-
*
|
|
447
|
-
|
|
234
|
+
* @category common/tabs
|
|
235
|
+
*/
|
|
236
|
+
const withDefaultOrientation = withTabsDefaultOrientation;
|
|
237
|
+
/**
|
|
238
|
+
* Override whether roving-tabindex navigation loops from last back to
|
|
239
|
+
* first (and vice versa). Per-instance `[loop]` Input still wins.
|
|
448
240
|
*
|
|
449
|
-
* @
|
|
241
|
+
* @category common/tabs
|
|
450
242
|
*/
|
|
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;
|
|
243
|
+
function withTabsRovingLoop(loop) {
|
|
244
|
+
return defineTabsConfigFeature((cfg) => ({ ...cfg, defaultLoop: loop }));
|
|
468
245
|
}
|
|
469
|
-
|
|
470
246
|
/**
|
|
471
|
-
*
|
|
472
|
-
*
|
|
473
|
-
*
|
|
247
|
+
* Override the default commit mode for async tab transitions.
|
|
248
|
+
* `'optimistic'` activates the tab on action dispatch and rolls back
|
|
249
|
+
* on error; `'pessimistic'` waits for success. Per-instance
|
|
250
|
+
* `[commitMode]` Input still wins.
|
|
474
251
|
*
|
|
475
252
|
* @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
253
|
*/
|
|
480
|
-
|
|
481
|
-
|
|
254
|
+
function withTabsCommitMode(mode) {
|
|
255
|
+
return defineTabsConfigFeature((cfg) => ({
|
|
256
|
+
...cfg,
|
|
257
|
+
defaultCommitMode: mode,
|
|
258
|
+
}));
|
|
259
|
+
}
|
|
482
260
|
/**
|
|
483
|
-
*
|
|
484
|
-
*
|
|
485
|
-
*
|
|
486
|
-
* (
|
|
261
|
+
* Configure URL fragment / query-param deep-linking for the active tab
|
|
262
|
+
* (the {@link CngxTabsFragmentSync} directive). \
|
|
263
|
+
* `mode` chooses the URL surface (URL fragment or query parameter); `param` names the key
|
|
264
|
+
* (default `'tab'`).
|
|
487
265
|
*
|
|
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.
|
|
266
|
+
* Not to be confused with `[cngxTabsRouteSync]`, the router-outlet
|
|
267
|
+
* integration - this feature configures fragment deep-linking only.
|
|
494
268
|
*
|
|
495
|
-
*
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
269
|
+
* @category common/tabs
|
|
270
|
+
*/
|
|
271
|
+
function withTabsFragmentSync(mode, param = 'tab') {
|
|
272
|
+
return defineTabsConfigFeature((cfg) => ({
|
|
273
|
+
...cfg,
|
|
274
|
+
fragmentSyncMode: mode,
|
|
275
|
+
fragmentSyncParam: param,
|
|
276
|
+
}));
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Force one URL-matching mode app-wide for `[cngxTabsRouteSync]`. \
|
|
280
|
+
* `'suffix'` treats every tab as a leaf route, `'prefix'` as a section
|
|
281
|
+
* that stays active for URLs beneath it.
|
|
500
282
|
*
|
|
501
|
-
*
|
|
502
|
-
*
|
|
503
|
-
*
|
|
504
|
-
*
|
|
505
|
-
* (suffix). The `[match]` input overrides the token-derived default when a
|
|
506
|
-
* consumer needs the other mode.
|
|
283
|
+
* Reach for this only when the host-flavour default is wrong for your
|
|
284
|
+
* app. Unset, a `<cngx-tab-nav>` matches by prefix and a
|
|
285
|
+
* `<cngx-tab-group>` by suffix, which is what each markup implies; this
|
|
286
|
+
* feature overrides *both*. Per-instance `[match]` still wins.
|
|
507
287
|
*
|
|
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
|
-
* ```
|
|
288
|
+
* Changes which policy runs, not the policies themselves - swap those via
|
|
289
|
+
* {@link CNGX_TAB_URL_MATCH_STRATEGY}.
|
|
516
290
|
*
|
|
517
291
|
* @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
292
|
*/
|
|
523
|
-
|
|
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
|
-
*/
|
|
529
|
-
function urlTreeSegmentCount(tree) {
|
|
530
|
-
let count = 0;
|
|
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;
|
|
293
|
+
function withTabsRouteMatch(mode) {
|
|
294
|
+
return defineTabsConfigFeature((cfg) => ({ ...cfg, routeMatch: mode }));
|
|
539
295
|
}
|
|
540
296
|
/**
|
|
541
|
-
*
|
|
542
|
-
*
|
|
543
|
-
*
|
|
544
|
-
*
|
|
545
|
-
*
|
|
546
|
-
*
|
|
547
|
-
*
|
|
297
|
+
* Set the `aria-current` token `[cngxTabLink]` publishes while active. \
|
|
298
|
+
* Default `'page'`.
|
|
299
|
+
*
|
|
300
|
+
* Use `'true'` for a section nav whose links stay active across a whole
|
|
301
|
+
* subtree: the active link is then the current *section*, and `page`
|
|
302
|
+
* would tell AT it is the page being viewed. Scope it to one nav with
|
|
303
|
+
* `provideTabsConfigAt` in that component's `viewProviders` rather than
|
|
304
|
+
* setting it app-wide, unless every nav in the app is section-shaped.
|
|
305
|
+
* Per-link `[ariaCurrent]` still wins.
|
|
306
|
+
*
|
|
307
|
+
* @category common/tabs
|
|
548
308
|
*/
|
|
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;
|
|
309
|
+
function withTabsLinkAriaCurrent(token) {
|
|
310
|
+
return defineTabsConfigFeature((cfg) => ({ ...cfg, linkAriaCurrent: token }));
|
|
563
311
|
}
|
|
564
312
|
/**
|
|
565
|
-
*
|
|
566
|
-
*
|
|
567
|
-
*
|
|
313
|
+
* @deprecated Use {@link withTabsFragmentSync}. "Router sync" collided
|
|
314
|
+
* with the new `[cngxTabsRouteSync]` router-outlet directive; this
|
|
315
|
+
* feature only ever configured fragment / query-param deep-linking. The
|
|
316
|
+
* alias stays for one minor release before removal.
|
|
568
317
|
*
|
|
569
|
-
*
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
*
|
|
574
|
-
*
|
|
575
|
-
*
|
|
576
|
-
*
|
|
318
|
+
* @category common/tabs
|
|
319
|
+
*/
|
|
320
|
+
const withTabsRouterSync = withTabsFragmentSync;
|
|
321
|
+
/**
|
|
322
|
+
* Select the app-wide default visual skin for `<cngx-tab-group>`. \
|
|
323
|
+
* Default `'line'`. Per-instance `[skin]` Input still wins; this moves
|
|
324
|
+
* the cascade default. Structure, slots, ARIA, and keyboard behaviour
|
|
325
|
+
* are identical across skins - only the `[data-skin]` host attribute
|
|
326
|
+
* changes the CSS layer. The Material twin (`[cngxMatTabs]`) ignores it.
|
|
577
327
|
*
|
|
578
|
-
*
|
|
579
|
-
* in the same set.
|
|
328
|
+
* @category common/tabs
|
|
580
329
|
*/
|
|
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;
|
|
330
|
+
function withTabsSkin(skin) {
|
|
331
|
+
return defineTabsConfigFeature((cfg) => ({ ...cfg, skin }));
|
|
606
332
|
}
|
|
607
333
|
/**
|
|
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.
|
|
334
|
+
* Set the app-wide default icon layout for `<cngx-tab-group>`. \
|
|
335
|
+
* Default`'start'`. Per-instance `[iconLayout]` Input still wins. Orthogonal to
|
|
336
|
+
* skin and orientation - only the `[data-icon-layout]` host attribute
|
|
337
|
+
* changes.
|
|
614
338
|
*
|
|
615
339
|
* @category common/tabs
|
|
616
340
|
*/
|
|
617
|
-
function
|
|
618
|
-
return {
|
|
619
|
-
resolve(ctx) {
|
|
620
|
-
return ctx.mode === 'prefix' ? resolveByPrefix(ctx) : resolveBySuffix(ctx);
|
|
621
|
-
},
|
|
622
|
-
};
|
|
341
|
+
function withTabsIconLayout(layout) {
|
|
342
|
+
return defineTabsConfigFeature((cfg) => ({ ...cfg, iconLayout: layout }));
|
|
623
343
|
}
|
|
624
344
|
/**
|
|
625
|
-
*
|
|
626
|
-
*
|
|
345
|
+
* Set the app-wide default panel render strategy for `<cngx-tab-group>`. \
|
|
346
|
+
* Default `'eager'` (every panel's content rendered up front, toggled
|
|
347
|
+
* via `[hidden]`). `'lazy'` keep-alives content after first activation;
|
|
348
|
+
* `'lazy-destroy'` renders only the active panel's content. Per-instance
|
|
349
|
+
* `[panelMode]` Input still wins. The panel `<div>` always stays in the
|
|
350
|
+
* DOM regardless of mode (the `aria-controls` target).
|
|
627
351
|
*
|
|
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*.
|
|
352
|
+
* Under `'lazy'`, a deep link mounts only the panel it names: both sync
|
|
353
|
+
* directives seed the active tab before the first panel render.
|
|
633
354
|
*
|
|
634
|
-
*
|
|
635
|
-
|
|
636
|
-
|
|
355
|
+
* @category common/tabs
|
|
356
|
+
*/
|
|
357
|
+
function withTabsPanelMode(mode) {
|
|
358
|
+
return defineTabsConfigFeature((cfg) => ({ ...cfg, panelMode: mode }));
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Set the app-wide default for stretching tabs to the full strip width
|
|
362
|
+
* (horizontal only). \
|
|
363
|
+
* Default `false`. Per-instance `[fitted]` Input still
|
|
364
|
+
* wins. No effect under `orientation="vertical"`.
|
|
637
365
|
*
|
|
638
366
|
* @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
367
|
*/
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
});
|
|
648
|
-
|
|
368
|
+
function withTabsFitted(fitted) {
|
|
369
|
+
return defineTabsConfigFeature((cfg) => ({ ...cfg, fitted }));
|
|
370
|
+
}
|
|
649
371
|
/**
|
|
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
|
-
* ```
|
|
372
|
+
* Set the app-wide default tab-cluster alignment (horizontal only). \
|
|
373
|
+
* Default `'start'`. Per-instance `[tabAlign]` Input still wins. Ignored
|
|
374
|
+
* under `orientation="vertical"` and when the group is `fitted`.
|
|
661
375
|
*
|
|
662
376
|
* @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
377
|
*/
|
|
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 });
|
|
378
|
+
function withTabsAlign(align) {
|
|
379
|
+
return defineTabsConfigFeature((cfg) => ({ ...cfg, tabAlign: align }));
|
|
672
380
|
}
|
|
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
381
|
/**
|
|
683
|
-
*
|
|
684
|
-
*
|
|
685
|
-
* `
|
|
686
|
-
*
|
|
687
|
-
* ```html
|
|
688
|
-
* <div cngxTab id="settings">
|
|
689
|
-
* <ng-template cngxTabLabel>Settings</ng-template>
|
|
690
|
-
* ... tab content ...
|
|
691
|
-
* </div>
|
|
692
|
-
* ```
|
|
382
|
+
* Set the app-wide default for whether tabs render a close affordance. \
|
|
383
|
+
* Default `false`. Per-instance `[closable]` Input wins; a per-`CngxTab`
|
|
384
|
+
* `[closable]` override wins over both.
|
|
693
385
|
*
|
|
694
386
|
* @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
387
|
*/
|
|
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 });
|
|
388
|
+
function withTabsClosable(closable) {
|
|
389
|
+
return defineTabsConfigFeature((cfg) => ({ ...cfg, closable }));
|
|
704
390
|
}
|
|
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
391
|
/**
|
|
715
|
-
*
|
|
716
|
-
*
|
|
717
|
-
* `
|
|
718
|
-
* label. \
|
|
392
|
+
* Set the app-wide default for whether the group renders an add-tab
|
|
393
|
+
* button. \
|
|
394
|
+
* Default `false`. Per-instance `[addable]` Input wins.
|
|
719
395
|
*
|
|
720
|
-
*
|
|
721
|
-
|
|
396
|
+
* @category common/tabs
|
|
397
|
+
*/
|
|
398
|
+
function withTabsAddable(addable) {
|
|
399
|
+
return defineTabsConfigFeature((cfg) => ({ ...cfg, addable }));
|
|
400
|
+
}
|
|
401
|
+
/** @internal - shared empty base, so label merges over an unset key memoize. */
|
|
402
|
+
const NO_LABELS = {};
|
|
403
|
+
/**
|
|
404
|
+
* Merge ARIA labels into the cascade. Keys not provided keep their
|
|
405
|
+
* library defaults; per-instance overrides on the tab group still win.
|
|
406
|
+
* Pass a `Signal` to switch the language at runtime.
|
|
722
407
|
*
|
|
723
|
-
*
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
408
|
+
* @category common/tabs
|
|
409
|
+
*/
|
|
410
|
+
function withTabsAriaLabels(labels) {
|
|
411
|
+
return defineTabsConfigFeature((cfg) => ({
|
|
412
|
+
...cfg,
|
|
413
|
+
ariaLabels: createOverrideMerge(cfg.ariaLabels ?? NO_LABELS, labels),
|
|
414
|
+
}));
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Merge the tablist / tab-panel `aria-roledescription` fallbacks into the
|
|
418
|
+
* cascade. Keys not provided keep their library defaults. Pass a `Signal`
|
|
419
|
+
* to switch the language at runtime.
|
|
730
420
|
*
|
|
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>
|
|
421
|
+
* @category common/tabs
|
|
737
422
|
*/
|
|
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 });
|
|
423
|
+
function withTabsFallbackLabels(labels) {
|
|
424
|
+
return defineTabsConfigFeature((cfg) => ({
|
|
425
|
+
...cfg,
|
|
426
|
+
fallbackLabels: createOverrideMerge(cfg.fallbackLabels ?? NO_LABELS, labels),
|
|
427
|
+
}));
|
|
746
428
|
}
|
|
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
429
|
/**
|
|
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.
|
|
430
|
+
* Override the IO-debounce window (ms). See
|
|
431
|
+
* {@link CngxTabsConfig.overflowStabilizeMs}.
|
|
766
432
|
*
|
|
767
|
-
* ```html
|
|
768
|
-
* <div cngxTab [label]="'Settings'">
|
|
769
|
-
* ... content templates here ...
|
|
770
|
-
* </div>
|
|
771
|
-
* ```
|
|
772
433
|
* @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
434
|
*/
|
|
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 });
|
|
435
|
+
function withTabOverflowStabilizeMs(ms) {
|
|
436
|
+
return defineTabsConfigFeature((cfg) => ({
|
|
437
|
+
...cfg,
|
|
438
|
+
overflowStabilizeMs: ms,
|
|
439
|
+
}));
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Override the worst-case staleness ceiling on the visibility-map
|
|
443
|
+
* commit. See {@link CngxTabsConfig.overflowMaxDeferMs}.
|
|
444
|
+
*
|
|
445
|
+
* @category common/tabs
|
|
446
|
+
*/
|
|
447
|
+
function withTabOverflowMaxDeferMs(ms) {
|
|
448
|
+
return defineTabsConfigFeature((cfg) => ({
|
|
449
|
+
...cfg,
|
|
450
|
+
overflowMaxDeferMs: ms,
|
|
451
|
+
}));
|
|
868
452
|
}
|
|
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
453
|
/**
|
|
903
|
-
*
|
|
904
|
-
*
|
|
905
|
-
*
|
|
454
|
+
* App-wide override for the More-button label. Middle tier; \
|
|
455
|
+
* per-instance `*cngxTabOverflowTrigger` still wins.
|
|
456
|
+
*
|
|
457
|
+
* ```ts
|
|
458
|
+
* readonly moreTrigger = viewChild.required<TemplateRef<CngxTabOverflowTriggerContext>>(
|
|
459
|
+
* 'moreTrigger',
|
|
460
|
+
* { read: TemplateRef },
|
|
461
|
+
* );
|
|
462
|
+
*
|
|
463
|
+
* providers: [provideTabsConfig(withTabOverflowTriggerTemplate(this.moreTrigger()))]
|
|
464
|
+
* ```
|
|
906
465
|
*
|
|
907
466
|
* @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
467
|
*/
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
}
|
|
468
|
+
function withTabOverflowTriggerTemplate(template) {
|
|
469
|
+
return defineTabsConfigFeature((cfg) => ({
|
|
470
|
+
...cfg,
|
|
471
|
+
templates: { ...cfg.templates, overflowTrigger: template },
|
|
472
|
+
}));
|
|
473
|
+
}
|
|
916
474
|
/**
|
|
917
|
-
*
|
|
918
|
-
* `
|
|
919
|
-
* Every `with*` config feature returns one
|
|
920
|
-
* of these.
|
|
475
|
+
* App-wide override for each row inside the overflow popover. \
|
|
476
|
+
* Middle tier; per-instance `*cngxTabOverflowItem` still wins.
|
|
921
477
|
*
|
|
922
|
-
* @
|
|
478
|
+
* @category common/tabs
|
|
923
479
|
*/
|
|
924
|
-
function
|
|
925
|
-
return
|
|
480
|
+
function withTabOverflowItemTemplate(template) {
|
|
481
|
+
return defineTabsConfigFeature((cfg) => ({
|
|
482
|
+
...cfg,
|
|
483
|
+
templates: { ...cfg.templates, overflowItem: template },
|
|
484
|
+
}));
|
|
926
485
|
}
|
|
927
486
|
/**
|
|
928
|
-
*
|
|
929
|
-
* still wins
|
|
487
|
+
* App-wide override for the error-badge decoration. Middle tier;
|
|
488
|
+
* per-instance `*cngxTabErrorBadge` still wins. Sibling of the
|
|
489
|
+
* stepper family's `withStepBadgeTemplate`.
|
|
930
490
|
*
|
|
931
491
|
* @category common/tabs
|
|
932
492
|
*/
|
|
933
|
-
function
|
|
493
|
+
function withTabErrorBadgeTemplate(template) {
|
|
934
494
|
return defineTabsConfigFeature((cfg) => ({
|
|
935
495
|
...cfg,
|
|
936
|
-
|
|
496
|
+
templates: { ...cfg.templates, errorBadge: template },
|
|
937
497
|
}));
|
|
938
498
|
}
|
|
939
499
|
/**
|
|
940
|
-
*
|
|
941
|
-
*
|
|
942
|
-
*
|
|
943
|
-
*
|
|
500
|
+
* App-wide override for the rejection-icon decoration. Middle
|
|
501
|
+
* tier; \
|
|
502
|
+
* per-instance `*cngxTabRejectionIcon` still wins. Sibling
|
|
503
|
+
* of {@link withStepRejectionTemplate}.
|
|
944
504
|
*
|
|
945
505
|
* @category common/tabs
|
|
946
506
|
*/
|
|
947
|
-
|
|
507
|
+
function withTabRejectionIconTemplate(template) {
|
|
508
|
+
return defineTabsConfigFeature((cfg) => ({
|
|
509
|
+
...cfg,
|
|
510
|
+
templates: { ...cfg.templates, rejectionIcon: template },
|
|
511
|
+
}));
|
|
512
|
+
}
|
|
948
513
|
/**
|
|
949
|
-
*
|
|
950
|
-
*
|
|
514
|
+
* App-wide override for the commit-pending busy-spinner overlay.
|
|
515
|
+
* Middle tier; per-instance `*cngxTabBusySpinner` still wins.
|
|
516
|
+
* Sibling of {@link withStepBusySpinnerTemplate}.
|
|
951
517
|
*
|
|
952
518
|
* @category common/tabs
|
|
953
519
|
*/
|
|
954
|
-
function
|
|
955
|
-
return defineTabsConfigFeature((cfg) => ({
|
|
520
|
+
function withTabBusySpinnerTemplate(template) {
|
|
521
|
+
return defineTabsConfigFeature((cfg) => ({
|
|
522
|
+
...cfg,
|
|
523
|
+
templates: { ...cfg.templates, busySpinner: template },
|
|
524
|
+
}));
|
|
956
525
|
}
|
|
957
526
|
/**
|
|
958
|
-
*
|
|
959
|
-
*
|
|
960
|
-
*
|
|
961
|
-
* `[commitMode]` Input still wins.
|
|
527
|
+
* App-wide override for the tab-icon slot. Middle tier of the 3-stage
|
|
528
|
+
* cascade; per-instance `*cngxTabIcon` still wins. Sibling of
|
|
529
|
+
* {@link withStepIndicatorTemplate}.
|
|
962
530
|
*
|
|
963
531
|
* @category common/tabs
|
|
964
532
|
*/
|
|
965
|
-
function
|
|
533
|
+
function withTabIconTemplate(template) {
|
|
966
534
|
return defineTabsConfigFeature((cfg) => ({
|
|
967
535
|
...cfg,
|
|
968
|
-
|
|
536
|
+
templates: { ...cfg.templates, icon: template },
|
|
969
537
|
}));
|
|
970
538
|
}
|
|
971
539
|
/**
|
|
972
|
-
*
|
|
973
|
-
*
|
|
974
|
-
* `mode` chooses the URL surface (URL fragment or query parameter); `param` names the key
|
|
975
|
-
* (default `'tab'`).
|
|
540
|
+
* App-wide override for a tab's close-button glyph. Middle tier;
|
|
541
|
+
* per-instance `*cngxTabCloseIcon` still wins.
|
|
976
542
|
*
|
|
977
|
-
*
|
|
978
|
-
|
|
543
|
+
* @category common/tabs
|
|
544
|
+
*/
|
|
545
|
+
function withTabCloseIconTemplate(template) {
|
|
546
|
+
return defineTabsConfigFeature((cfg) => ({
|
|
547
|
+
...cfg,
|
|
548
|
+
templates: { ...cfg.templates, closeIcon: template },
|
|
549
|
+
}));
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* App-wide override for the add-tab button glyph. Middle tier;
|
|
553
|
+
* per-instance `*cngxTabAddIcon` still wins.
|
|
979
554
|
*
|
|
980
555
|
* @category common/tabs
|
|
981
556
|
*/
|
|
982
|
-
function
|
|
557
|
+
function withTabAddIconTemplate(template) {
|
|
983
558
|
return defineTabsConfigFeature((cfg) => ({
|
|
984
559
|
...cfg,
|
|
985
|
-
|
|
986
|
-
fragmentSyncParam: param,
|
|
560
|
+
templates: { ...cfg.templates, addIcon: template },
|
|
987
561
|
}));
|
|
988
562
|
}
|
|
989
563
|
/**
|
|
990
|
-
*
|
|
991
|
-
*
|
|
992
|
-
|
|
564
|
+
* @internal The defaults with the copy keys read from the tabs section of
|
|
565
|
+
* the active language pack. Runs in an injection context.
|
|
566
|
+
*/
|
|
567
|
+
function tabsConfigDefaultsFromPack() {
|
|
568
|
+
const language = injectTabsLanguage();
|
|
569
|
+
return {
|
|
570
|
+
...TABS_CONFIG_DEFAULTS,
|
|
571
|
+
ariaLabels: computed(() => ({ tabsRegion: language().tabsRegion }), { equal: recordEqual }),
|
|
572
|
+
fallbackLabels: computed(() => ({
|
|
573
|
+
tabRoleDescription: language().tabRoleDescription,
|
|
574
|
+
tabPanelRoleDescription: language().tabPanelRoleDescription,
|
|
575
|
+
}), { equal: recordEqual }),
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
/** @internal Runs in an injection context; features apply on top of the pack. */
|
|
579
|
+
function resolveFeatures(features) {
|
|
580
|
+
return features.reduce((cfg, feat) => feat(cfg), tabsConfigDefaultsFromPack());
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Root-level provider. Apply once in `bootstrapApplication` /
|
|
584
|
+
* `appConfig.providers`. Returns {@link EnvironmentProviders} per
|
|
585
|
+
* the canonical cngx config-cascade signature.
|
|
993
586
|
*
|
|
994
|
-
*
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
587
|
+
* @category common/tabs
|
|
588
|
+
*/
|
|
589
|
+
function provideTabsConfig(...features) {
|
|
590
|
+
return makeEnvironmentProviders([
|
|
591
|
+
{ provide: CNGX_TABS_CONFIG, useFactory: () => resolveFeatures(features) },
|
|
592
|
+
]);
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* Component-scoped override. Returns `Provider[]` (not
|
|
596
|
+
* {@link EnvironmentProviders}) because `viewProviders` rejects
|
|
597
|
+
* opaque environment providers. Resolution priority: per-instance
|
|
598
|
+
* Input > viewProviders (`At`) > root > default.
|
|
998
599
|
*
|
|
999
|
-
*
|
|
1000
|
-
* {
|
|
600
|
+
* ```ts
|
|
601
|
+
* @Component({
|
|
602
|
+
* viewProviders: [...provideTabsConfigAt(withTabsDefaultOrientation('vertical'))],
|
|
603
|
+
* })
|
|
604
|
+
* ```
|
|
1001
605
|
*
|
|
1002
606
|
* @category common/tabs
|
|
1003
607
|
*/
|
|
1004
|
-
function
|
|
1005
|
-
return
|
|
608
|
+
function provideTabsConfigAt(...features) {
|
|
609
|
+
return [{ provide: CNGX_TABS_CONFIG, useFactory: () => resolveFeatures(features) }];
|
|
1006
610
|
}
|
|
1007
611
|
/**
|
|
1008
|
-
*
|
|
1009
|
-
* Default `'page'`.
|
|
612
|
+
* Inject the resolved tabs config in an injection context.
|
|
1010
613
|
*
|
|
1011
|
-
*
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
614
|
+
* @category common/tabs
|
|
615
|
+
*/
|
|
616
|
+
function injectTabsConfig() {
|
|
617
|
+
return inject(CNGX_TABS_CONFIG);
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* Wraps a {@link CngxCommitController} with the action-shape adapter
|
|
622
|
+
* that resolves `Observable<boolean>` / `Promise<boolean>` / `boolean`
|
|
623
|
+
* returns into one {@link CngxTabsCommitResolution}: `true` accepts,
|
|
624
|
+
* `false` refuses (the controller settles to `'idle'` and stores no
|
|
625
|
+
* error), a throw fails.
|
|
1017
626
|
*
|
|
1018
627
|
* @category common/tabs
|
|
1019
628
|
*/
|
|
1020
|
-
function
|
|
1021
|
-
|
|
629
|
+
function createTabsCommitHandler(opts) {
|
|
630
|
+
const { controller } = opts;
|
|
631
|
+
return {
|
|
632
|
+
isCommitting: controller.isCommitting,
|
|
633
|
+
beginTransition(fromIndex, toIndex, action, onResolve) {
|
|
634
|
+
controller.begin((handlers) => runTabsAction(action, fromIndex, toIndex, handlers), toIndex, fromIndex, {
|
|
635
|
+
onSuccess: () => onResolve('accepted'),
|
|
636
|
+
onError: () => onResolve('failed'),
|
|
637
|
+
onRefused: () => onResolve('refused'),
|
|
638
|
+
});
|
|
639
|
+
},
|
|
640
|
+
cancel() {
|
|
641
|
+
controller.cancel();
|
|
642
|
+
},
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
function runTabsAction(action, fromIndex, toIndex, handlers) {
|
|
646
|
+
let cancelled = false;
|
|
647
|
+
let unsubscribe = null;
|
|
648
|
+
const safeSuccess = (accept) => {
|
|
649
|
+
if (cancelled) {
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
652
|
+
if (accept) {
|
|
653
|
+
handlers.onSuccess(toIndex);
|
|
654
|
+
}
|
|
655
|
+
else {
|
|
656
|
+
handlers.onRefused();
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
const safeError = (err) => {
|
|
660
|
+
if (cancelled) {
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
handlers.onError(err);
|
|
664
|
+
};
|
|
665
|
+
let result;
|
|
666
|
+
try {
|
|
667
|
+
result = action(fromIndex, toIndex);
|
|
668
|
+
}
|
|
669
|
+
catch (err) {
|
|
670
|
+
safeError(err);
|
|
671
|
+
return {
|
|
672
|
+
cancel: () => {
|
|
673
|
+
cancelled = true;
|
|
674
|
+
},
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
if (isObservable(result)) {
|
|
678
|
+
// Synchronous Observables (`of(true)`) emit inside `.subscribe` before
|
|
679
|
+
// the assignment binds - close over a pre-declared `let` to avoid TDZ.
|
|
680
|
+
let sub = null;
|
|
681
|
+
let done = false;
|
|
682
|
+
sub = result.subscribe({
|
|
683
|
+
next: (accept) => {
|
|
684
|
+
if (done) {
|
|
685
|
+
return;
|
|
686
|
+
}
|
|
687
|
+
// Done-latch, not just unsubscribe: a synchronous emission fires
|
|
688
|
+
// while `sub` is still null, so a non-completing source would
|
|
689
|
+
// otherwise stay live and re-resolve on its next emission.
|
|
690
|
+
done = true;
|
|
691
|
+
safeSuccess(accept);
|
|
692
|
+
sub?.unsubscribe();
|
|
693
|
+
},
|
|
694
|
+
error: (err) => {
|
|
695
|
+
if (done) {
|
|
696
|
+
return;
|
|
697
|
+
}
|
|
698
|
+
safeError(err);
|
|
699
|
+
},
|
|
700
|
+
complete: () => {
|
|
701
|
+
// EMPTY-style sources complete without emitting; without this arm
|
|
702
|
+
// the commit stays 'pending' forever and busy() latches true.
|
|
703
|
+
if (!done) {
|
|
704
|
+
safeError(new CngxRuntimeError('CNGX1059', typeof ngDevMode !== 'undefined' &&
|
|
705
|
+
ngDevMode &&
|
|
706
|
+
'[cngxTabGroup] commitAction completed without emitting true or false.'));
|
|
707
|
+
}
|
|
708
|
+
},
|
|
709
|
+
});
|
|
710
|
+
if (done) {
|
|
711
|
+
// The in-next unsubscribe was a no-op for a sync emission; close
|
|
712
|
+
// the still-live subscription now that `sub` is bound.
|
|
713
|
+
sub.unsubscribe();
|
|
714
|
+
}
|
|
715
|
+
unsubscribe = () => sub?.unsubscribe();
|
|
716
|
+
}
|
|
717
|
+
else if (result != null && typeof result.then === 'function') {
|
|
718
|
+
result.then(safeSuccess, safeError);
|
|
719
|
+
}
|
|
720
|
+
else {
|
|
721
|
+
safeSuccess(result);
|
|
722
|
+
}
|
|
723
|
+
return {
|
|
724
|
+
cancel: () => {
|
|
725
|
+
cancelled = true;
|
|
726
|
+
unsubscribe?.();
|
|
727
|
+
},
|
|
728
|
+
};
|
|
1022
729
|
}
|
|
1023
730
|
/**
|
|
1024
|
-
*
|
|
1025
|
-
*
|
|
1026
|
-
*
|
|
1027
|
-
*
|
|
731
|
+
* DI token for the commit-handler factory. \
|
|
732
|
+
* Defaults to {@link createTabsCommitHandler}. \
|
|
733
|
+
* Sibling to
|
|
734
|
+
* - `CNGX_ARRAY_COMMIT_HANDLER_FACTORY` (select) and
|
|
735
|
+
* - `CNGX_STEPPER_COMMIT_HANDLER_FACTORY`.
|
|
1028
736
|
*
|
|
1029
737
|
* @category common/tabs
|
|
738
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/commit-handler.ts
|
|
739
|
+
* @since 0.1.0
|
|
1030
740
|
*/
|
|
1031
|
-
const
|
|
741
|
+
const CNGX_TABS_COMMIT_HANDLER_FACTORY = new InjectionToken('CngxTabsCommitHandlerFactory', {
|
|
742
|
+
providedIn: 'root',
|
|
743
|
+
factory: () => createTabsCommitHandler,
|
|
744
|
+
});
|
|
745
|
+
|
|
1032
746
|
/**
|
|
1033
|
-
*
|
|
1034
|
-
*
|
|
1035
|
-
* the
|
|
1036
|
-
*
|
|
1037
|
-
*
|
|
747
|
+
* DI token for the tab presenter's contract. \
|
|
748
|
+
* Presenter provides via `useExisting`; `CngxTab` injects to register; the organism injects
|
|
749
|
+
* to drive the APG tablist keyboard model (automatic activation via
|
|
750
|
+
* `select()`, roving stop derived from `activeId`) through
|
|
751
|
+
* `createTabKeyboardNav`.
|
|
1038
752
|
*
|
|
1039
753
|
* @category common/tabs
|
|
754
|
+
* @wcag AA
|
|
755
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/tab-group-host.token.ts
|
|
756
|
+
* @since 0.1.0
|
|
1040
757
|
*/
|
|
1041
|
-
|
|
1042
|
-
return defineTabsConfigFeature((cfg) => ({ ...cfg, skin }));
|
|
1043
|
-
}
|
|
758
|
+
const CNGX_TAB_GROUP_HOST = new InjectionToken('CngxTabGroupHost');
|
|
1044
759
|
/**
|
|
1045
|
-
*
|
|
1046
|
-
*
|
|
1047
|
-
*
|
|
1048
|
-
*
|
|
760
|
+
* Inject the {@link CNGX_TAB_GROUP_HOST} for a tab add-on directive, from
|
|
761
|
+
* its own element or an ancestor in the same template. Throws a
|
|
762
|
+
* `CngxRuntimeError` with code `CNGX1055` when there is none, in development
|
|
763
|
+
* and production alike. `selector` names the add-on in the development
|
|
764
|
+
* message.
|
|
1049
765
|
*
|
|
1050
|
-
* @
|
|
766
|
+
* @internal
|
|
1051
767
|
*/
|
|
1052
|
-
function
|
|
1053
|
-
|
|
768
|
+
function injectTabGroupHost(selector) {
|
|
769
|
+
const group = inject(CNGX_TAB_GROUP_HOST, { host: true, optional: true });
|
|
770
|
+
if (!group) {
|
|
771
|
+
throw new CngxRuntimeError('CNGX1055', typeof ngDevMode !== 'undefined' &&
|
|
772
|
+
ngDevMode &&
|
|
773
|
+
`[${selector}] must be placed on or inside an element with [cngxTabGroup], such as <cngx-tab-group> or <cngx-tab-nav>.`);
|
|
774
|
+
}
|
|
775
|
+
return group;
|
|
1054
776
|
}
|
|
777
|
+
|
|
1055
778
|
/**
|
|
1056
|
-
*
|
|
1057
|
-
*
|
|
1058
|
-
*
|
|
1059
|
-
*
|
|
1060
|
-
*
|
|
1061
|
-
*
|
|
779
|
+
* Tab-group presenter - brain of every CNGX tab flow. \
|
|
780
|
+
* Owns the active-index model, the tab registry, orientation, loop policy,
|
|
781
|
+
* and the commit-controller lifecycle. \
|
|
782
|
+
* Provides {@link CNGX_TAB_GROUP_HOST} for atoms and {@link CNGX_STATEFUL}
|
|
783
|
+
* so `<cngx-toast-on />` / `<cngx-banner-on />` compose without
|
|
784
|
+
* `[state]` wiring.
|
|
1062
785
|
*
|
|
1063
|
-
*
|
|
1064
|
-
*
|
|
786
|
+
* **Layer:** `@cngx/common/tabs`. \
|
|
787
|
+
* Directive-only - organisms compose via `hostDirectives`, consumers attach
|
|
788
|
+
* `[cngxTabGroup]` directly.
|
|
1065
789
|
*
|
|
1066
790
|
* @category common/tabs
|
|
791
|
+
* @docsKind primary
|
|
792
|
+
* @wcag AA
|
|
793
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/presenter.directive.ts
|
|
794
|
+
* @since 0.1.0
|
|
795
|
+
* @relatedTo CngxTab, CngxTabContent, CngxTabLabel, CngxTabsFragmentSync
|
|
796
|
+
* <example-url>http://localhost:4200/#/ui/tabs/tab-commit-action/optimistic-pessimistic-commits-with-bridge-directives</example-url>
|
|
1067
797
|
*/
|
|
1068
|
-
|
|
1069
|
-
|
|
798
|
+
class CngxTabGroupPresenter {
|
|
799
|
+
config = injectTabsConfig();
|
|
800
|
+
activeIndex = model(0, ...(ngDevMode ? [{ debugName: "activeIndex" }] : /* istanbul ignore next */ []));
|
|
801
|
+
/**
|
|
802
|
+
* @internal Two-field alias - bind the public `[orientation]`; read
|
|
803
|
+
* the resolved {@link orientation} computed (input ?? config ?? default).
|
|
804
|
+
*/
|
|
805
|
+
orientationInput = input(undefined, { ...(ngDevMode ? { debugName: "orientationInput" } : /* istanbul ignore next */ {}), alias: 'orientation' });
|
|
806
|
+
orientation = computed(() => this.orientationInput() ?? this.config.defaultOrientation ?? 'horizontal', ...(ngDevMode ? [{ debugName: "orientation" }] : /* istanbul ignore next */ []));
|
|
807
|
+
/**
|
|
808
|
+
* @internal Two-field alias - bind the public `[loop]`; read the
|
|
809
|
+
* resolved {@link loop} computed (input ?? config ?? default).
|
|
810
|
+
*/
|
|
811
|
+
loopInput = input(undefined, { ...(ngDevMode ? { debugName: "loopInput" } : /* istanbul ignore next */ {}), alias: 'loop' });
|
|
812
|
+
loop = computed(() => this.loopInput() ?? this.config.defaultLoop ?? true, ...(ngDevMode ? [{ debugName: "loop" }] : /* istanbul ignore next */ []));
|
|
813
|
+
/**
|
|
814
|
+
* Async-commit action gating the transition.
|
|
815
|
+
* When non-null, `select(...)` routes through {@link CngxTabsCommitHandler}; the
|
|
816
|
+
* action's resolution decides whether the change lands. Supersede
|
|
817
|
+
* semantics come from the commit-controller - a rapid second
|
|
818
|
+
* `select(...)` cancels the in-flight runner.
|
|
819
|
+
*
|
|
820
|
+
* @internal Two-field alias - bind the public `[commitAction]`; read
|
|
821
|
+
* the resolved {@link commitAction} computed (input ?? DI fallback).
|
|
822
|
+
*/
|
|
823
|
+
commitActionInput = input(null, { ...(ngDevMode ? { debugName: "commitActionInput" } : /* istanbul ignore next */ {}), alias: 'commitAction' });
|
|
824
|
+
/**
|
|
825
|
+
* Default `'optimistic'` - tab change is navigation, not a save,
|
|
826
|
+
* so eager visual feedback matches the user's mental model.
|
|
827
|
+
* Switch to `'pessimistic'` when the new tab must wait for the
|
|
828
|
+
* action to confirm.
|
|
829
|
+
*
|
|
830
|
+
* @internal Two-field alias - bind the public `[commitMode]`; read
|
|
831
|
+
* the resolved {@link commitMode} computed (DI fallback mode wins
|
|
832
|
+
* when a routed action is active, else input ?? config ?? default).
|
|
833
|
+
*/
|
|
834
|
+
commitModeInput = input(undefined, { ...(ngDevMode ? { debugName: "commitModeInput" } : /* istanbul ignore next */ {}), alias: 'commitMode' });
|
|
835
|
+
injector = inject(Injector);
|
|
836
|
+
// Resolved lazily, never in a field initialiser: a sync directive
|
|
837
|
+
// (e.g. [cngxTabsRouteSync]) provides CNGX_TABS_COMMIT_ACTION via
|
|
838
|
+
// useExisting and itself injects this presenter as its host, so
|
|
839
|
+
// eager injection here would close a construction cycle (NG0200).
|
|
840
|
+
// First read happens at select()/template time - after both
|
|
841
|
+
// directives exist. The source is static per element, so memoising
|
|
842
|
+
// the resolution is safe.
|
|
843
|
+
injectedActionSource;
|
|
844
|
+
resolveInjectedAction() {
|
|
845
|
+
if (this.injectedActionSource === undefined) {
|
|
846
|
+
this.injectedActionSource = this.injector.get(CNGX_TABS_COMMIT_ACTION, null);
|
|
847
|
+
}
|
|
848
|
+
return this.injectedActionSource;
|
|
849
|
+
}
|
|
850
|
+
/**
|
|
851
|
+
* Resolved commit-action: the `[commitAction]` input when bound, else
|
|
852
|
+
* the {@link CNGX_TABS_COMMIT_ACTION} DI fallback (routed path), else
|
|
853
|
+
* `null`. `select()` reads this.
|
|
854
|
+
*/
|
|
855
|
+
commitAction = computed(() => this.commitActionInput() ?? this.resolveInjectedAction()?.action() ?? null, ...(ngDevMode ? [{ debugName: "commitAction" }] : /* istanbul ignore next */ []));
|
|
856
|
+
/**
|
|
857
|
+
* Resolved commit mode. When the DI fallback supplies an active
|
|
858
|
+
* action its `mode` wins - the routed path pins `'pessimistic'` so a
|
|
859
|
+
* stray `[commitMode]="'optimistic'"` cannot break the
|
|
860
|
+
* route-follows-resolution invariant. Otherwise the `[commitMode]`
|
|
861
|
+
* input drives.
|
|
862
|
+
*/
|
|
863
|
+
commitMode = computed(() => {
|
|
864
|
+
const source = this.resolveInjectedAction();
|
|
865
|
+
if (source?.action()) {
|
|
866
|
+
return source.mode();
|
|
867
|
+
}
|
|
868
|
+
return this.commitModeInput() ?? this.config.defaultCommitMode ?? 'optimistic';
|
|
869
|
+
}, ...(ngDevMode ? [{ debugName: "commitMode" }] : /* istanbul ignore next */ []));
|
|
870
|
+
/**
|
|
871
|
+
* Emitted when a tab's close affordance is activated (the close
|
|
872
|
+
* button or Delete on the focused tab). The presenter has
|
|
873
|
+
* already moved the active index onto the surviving neighbour; the
|
|
874
|
+
* consumer removes the tab from its own data in the handler.
|
|
875
|
+
*/
|
|
876
|
+
tabClose = output();
|
|
877
|
+
/**
|
|
878
|
+
* Emitted when the add-tab affordance is activated. The consumer
|
|
879
|
+
* appends a tab to its own data; the presenter owns no creation logic.
|
|
880
|
+
*/
|
|
881
|
+
tabAdd = output();
|
|
882
|
+
genericFactory = inject(CNGX_COMMIT_CONTROLLER_FACTORY);
|
|
883
|
+
commitController = this.genericFactory();
|
|
884
|
+
commitHandler = inject(CNGX_TABS_COMMIT_HANDLER_FACTORY)({
|
|
885
|
+
controller: this.commitController,
|
|
886
|
+
});
|
|
887
|
+
/** Producer surface for the `CNGX_STATEFUL` bridge contract. */
|
|
888
|
+
state = this.commitController.state;
|
|
889
|
+
commitState = this.commitController.state;
|
|
890
|
+
/**
|
|
891
|
+
* Index the user is currently trying to commit to. Tracked
|
|
892
|
+
* separately from `state.data()` (which only updates on success)
|
|
893
|
+
* to drive per-tab `aria-busy`.
|
|
894
|
+
*/
|
|
895
|
+
intendedIndex = this.commitController.intendedValue;
|
|
896
|
+
/**
|
|
897
|
+
* Current/previous pair for `commitState.status()`. Skin
|
|
898
|
+
* sub-components feed `<span cngxLiveRegion>` from this tracker
|
|
899
|
+
* for declarative SR announcements. Shared across consumers so
|
|
900
|
+
* the tracker's `linkedSignal` is allocated once per presenter.
|
|
901
|
+
*/
|
|
902
|
+
commitTransition = createTransitionTracker(() => this.commitController.state.status());
|
|
903
|
+
// Persistence-of-rejection surface - see `CngxTabGroupHost.lastOutcome`,
|
|
904
|
+
// `lastFailedIndex` and `originIndexDuringCommit` for the contract. Two
|
|
905
|
+
// event sources, never synced: the settle record and the sequence whose
|
|
906
|
+
// visual marker was cleared. `lastFailedIndex` derives from both, so
|
|
907
|
+
// clearing the marker never touches the announcement record.
|
|
908
|
+
lastOutcomeState = signal(undefined, ...(ngDevMode ? [{ debugName: "lastOutcomeState" }] : /* istanbul ignore next */ []));
|
|
909
|
+
clearedSequenceState = signal(undefined, ...(ngDevMode ? [{ debugName: "clearedSequenceState" }] : /* istanbul ignore next */ []));
|
|
910
|
+
// Bumped once per settled refusal or failure. Plain field - only read
|
|
911
|
+
// inside the resolve handler.
|
|
912
|
+
outcomeSequence = 0;
|
|
913
|
+
originIndexDuringCommitState = signal(undefined, ...(ngDevMode ? [{ debugName: "originIndexDuringCommitState" }] : /* istanbul ignore next */ []));
|
|
914
|
+
/** {@inheritDoc CngxTabGroupHost.lastOutcome} */
|
|
915
|
+
lastOutcome = this.lastOutcomeState.asReadonly();
|
|
916
|
+
/** {@inheritDoc CngxTabGroupHost.lastFailedIndex} */
|
|
917
|
+
lastFailedIndex = computed(() => {
|
|
918
|
+
const outcome = this.lastOutcomeState();
|
|
919
|
+
return outcome && outcome.sequence !== this.clearedSequenceState() ? outcome.index : undefined;
|
|
920
|
+
}, ...(ngDevMode ? [{ debugName: "lastFailedIndex" }] : /* istanbul ignore next */ []));
|
|
921
|
+
/** {@inheritDoc CngxTabGroupHost.originIndexDuringCommit} */
|
|
922
|
+
originIndexDuringCommit = this.originIndexDuringCommitState.asReadonly();
|
|
923
|
+
tabsState = signal([], { ...(ngDevMode ? { debugName: "tabsState" } : /* istanbul ignore next */ {}), equal: tabsEqual });
|
|
924
|
+
tabs = this.tabsState.asReadonly();
|
|
925
|
+
clampedIndex = computed(() => {
|
|
926
|
+
const count = this.tabs().length;
|
|
927
|
+
if (count === 0) {
|
|
928
|
+
return 0;
|
|
929
|
+
}
|
|
930
|
+
return Math.max(0, Math.min(this.activeIndex(), count - 1));
|
|
931
|
+
}, ...(ngDevMode ? [{ debugName: "clampedIndex" }] : /* istanbul ignore next */ []));
|
|
932
|
+
activeId = computed(() => this.tabs()[this.clampedIndex()]?.id ?? null, { ...(ngDevMode ? { debugName: "activeId" } : /* istanbul ignore next */ {}), equal: Object.is });
|
|
933
|
+
register(handle) {
|
|
934
|
+
const current = this.tabsState();
|
|
935
|
+
const idx = current.findIndex((h) => h.id === handle.id);
|
|
936
|
+
if (idx >= 0) {
|
|
937
|
+
const next = current.slice();
|
|
938
|
+
next[idx] = handle;
|
|
939
|
+
this.tabsState.set(next);
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
942
|
+
this.tabsState.set([...current, handle]);
|
|
943
|
+
}
|
|
944
|
+
unregister(id, handle) {
|
|
945
|
+
const current = this.tabsState();
|
|
946
|
+
const entry = current.find((h) => h.id === id);
|
|
947
|
+
if (entry === undefined) {
|
|
948
|
+
return;
|
|
949
|
+
}
|
|
950
|
+
// Instance guard: after an idempotent re-register replaced the stored
|
|
951
|
+
// handle, the superseded instance's destroy is a no-op.
|
|
952
|
+
if (handle !== undefined && entry !== handle) {
|
|
953
|
+
return;
|
|
954
|
+
}
|
|
955
|
+
this.tabsState.set(current.filter((h) => h !== entry));
|
|
956
|
+
}
|
|
957
|
+
/** {@inheritDoc CngxTabGroupHost.clearLastFailed} */
|
|
958
|
+
clearLastFailed() {
|
|
959
|
+
this.clearedSequenceState.set(this.lastOutcomeState()?.sequence);
|
|
960
|
+
}
|
|
961
|
+
select(index) {
|
|
962
|
+
const tabs = this.tabs();
|
|
963
|
+
if (tabs.length === 0) {
|
|
964
|
+
return;
|
|
965
|
+
}
|
|
966
|
+
const target = Math.max(0, Math.min(index, tabs.length - 1));
|
|
967
|
+
if (tabs[target].disabled()) {
|
|
968
|
+
return;
|
|
969
|
+
}
|
|
970
|
+
const previous = this.activeIndex();
|
|
971
|
+
if (target === previous) {
|
|
972
|
+
return;
|
|
973
|
+
}
|
|
974
|
+
const action = this.commitAction();
|
|
975
|
+
if (!action) {
|
|
976
|
+
// No-action fast path - `originIndexDuringCommit` stays
|
|
977
|
+
// untouched, so a stale origin can never leak into the
|
|
978
|
+
// live-region announcement.
|
|
979
|
+
this.activeIndex.set(target);
|
|
980
|
+
if (this.lastFailedIndex() === target) {
|
|
981
|
+
this.clearLastFailed();
|
|
982
|
+
}
|
|
983
|
+
return;
|
|
984
|
+
}
|
|
985
|
+
// Open the commit window - origin is captured ONLY here so a
|
|
986
|
+
// stale value never lingers into a non-commit navigation.
|
|
987
|
+
this.originIndexDuringCommitState.set(previous);
|
|
988
|
+
const mode = this.commitMode();
|
|
989
|
+
if (mode === 'optimistic') {
|
|
990
|
+
this.activeIndex.set(target);
|
|
991
|
+
}
|
|
992
|
+
this.commitHandler.beginTransition(previous, target, action, (outcome) => {
|
|
993
|
+
if (outcome === 'accepted') {
|
|
994
|
+
// Window closes on success - origin label no longer needed;
|
|
995
|
+
// clear the rejection marker if the user re-picked the
|
|
996
|
+
// rejected target successfully.
|
|
997
|
+
this.originIndexDuringCommitState.set(undefined);
|
|
998
|
+
if (this.lastFailedIndex() === target) {
|
|
999
|
+
this.clearLastFailed();
|
|
1000
|
+
}
|
|
1001
|
+
if (mode === 'pessimistic') {
|
|
1002
|
+
this.activeIndex.set(target);
|
|
1003
|
+
}
|
|
1004
|
+
return;
|
|
1005
|
+
}
|
|
1006
|
+
// Refused or failed - record the outcome on the target; RETAIN the
|
|
1007
|
+
// origin so the announcements can resolve the origin label for the
|
|
1008
|
+
// rich phrase. Both kinds roll back: optimistic returns to the
|
|
1009
|
+
// origin, pessimistic never moved.
|
|
1010
|
+
this.lastOutcomeState.set({
|
|
1011
|
+
kind: outcome,
|
|
1012
|
+
index: target,
|
|
1013
|
+
sequence: ++this.outcomeSequence,
|
|
1014
|
+
});
|
|
1015
|
+
if (mode === 'optimistic') {
|
|
1016
|
+
this.activeIndex.set(previous);
|
|
1017
|
+
}
|
|
1018
|
+
});
|
|
1019
|
+
}
|
|
1020
|
+
selectNext() {
|
|
1021
|
+
const tabs = this.tabs();
|
|
1022
|
+
if (tabs.length === 0) {
|
|
1023
|
+
return;
|
|
1024
|
+
}
|
|
1025
|
+
let next = this.activeIndex() + 1;
|
|
1026
|
+
while (next < tabs.length && tabs[next].disabled()) {
|
|
1027
|
+
next++;
|
|
1028
|
+
}
|
|
1029
|
+
if (next < tabs.length) {
|
|
1030
|
+
this.select(next);
|
|
1031
|
+
return;
|
|
1032
|
+
}
|
|
1033
|
+
if (this.loop()) {
|
|
1034
|
+
let i = 0;
|
|
1035
|
+
while (i < tabs.length && tabs[i].disabled()) {
|
|
1036
|
+
i++;
|
|
1037
|
+
}
|
|
1038
|
+
if (i < tabs.length && i !== this.activeIndex()) {
|
|
1039
|
+
this.select(i);
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
selectPrevious() {
|
|
1044
|
+
const tabs = this.tabs();
|
|
1045
|
+
if (tabs.length === 0) {
|
|
1046
|
+
return;
|
|
1047
|
+
}
|
|
1048
|
+
let prev = this.activeIndex() - 1;
|
|
1049
|
+
while (prev >= 0 && tabs[prev].disabled()) {
|
|
1050
|
+
prev--;
|
|
1051
|
+
}
|
|
1052
|
+
if (prev >= 0) {
|
|
1053
|
+
this.select(prev);
|
|
1054
|
+
return;
|
|
1055
|
+
}
|
|
1056
|
+
if (this.loop()) {
|
|
1057
|
+
let i = tabs.length - 1;
|
|
1058
|
+
while (i >= 0 && tabs[i].disabled()) {
|
|
1059
|
+
i--;
|
|
1060
|
+
}
|
|
1061
|
+
if (i >= 0 && i !== this.activeIndex()) {
|
|
1062
|
+
this.select(i);
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
selectById(id) {
|
|
1067
|
+
const tabs = this.tabs();
|
|
1068
|
+
const idx = tabs.findIndex((h) => h.id === id);
|
|
1069
|
+
if (idx >= 0) {
|
|
1070
|
+
this.select(idx);
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
requestClose(id) {
|
|
1074
|
+
const tabs = this.tabs();
|
|
1075
|
+
const index = tabs.findIndex((h) => h.id === id);
|
|
1076
|
+
if (index < 0) {
|
|
1077
|
+
return;
|
|
1078
|
+
}
|
|
1079
|
+
const active = this.clampedIndex();
|
|
1080
|
+
// Closing a tab BEFORE the active one needs a pre-emptive index
|
|
1081
|
+
// shift: the active tab moves down one slot once the consumer
|
|
1082
|
+
// removes the closed tab, so decrement to keep the same tab active.
|
|
1083
|
+
// Closing the active tab mid-strip (or one after the active) needs
|
|
1084
|
+
// no write - `clampedIndex` re-derives against the shorter array
|
|
1085
|
+
// and lands on the next tab.
|
|
1086
|
+
if (index < active) {
|
|
1087
|
+
this.activeIndex.set(active - 1);
|
|
1088
|
+
}
|
|
1089
|
+
else if (index === active && index === tabs.length - 1 && index > 0) {
|
|
1090
|
+
// Closing the ACTIVE LAST tab: the derived clamp would land on the
|
|
1091
|
+
// new last, but the [(activeIndex)] model itself would keep the
|
|
1092
|
+
// now out-of-range value - clamp-write so two-way consumers see
|
|
1093
|
+
// the real position.
|
|
1094
|
+
this.activeIndex.set(index - 1);
|
|
1095
|
+
}
|
|
1096
|
+
// The rejection markers are flat indices into the same registry, so a
|
|
1097
|
+
// close before them drifts the decoration onto the wrong tab (reachable
|
|
1098
|
+
// only via the dismissable affordance the organism layers on top). Shift
|
|
1099
|
+
// them the same way `activeIndex` shifts, and drop the outcome outright
|
|
1100
|
+
// when its own tab is the one closed. A shift copies the sequence, so
|
|
1101
|
+
// nothing downstream treats it as a new outcome.
|
|
1102
|
+
this.lastOutcomeState.update((outcome) => shiftOutcomeOnClose(outcome, index));
|
|
1103
|
+
this.originIndexDuringCommitState.update((origin) => shiftIndexOnClose(origin, index));
|
|
1104
|
+
this.tabClose.emit({ id, index });
|
|
1105
|
+
}
|
|
1106
|
+
requestAdd() {
|
|
1107
|
+
this.tabAdd.emit();
|
|
1108
|
+
}
|
|
1109
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabGroupPresenter, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1110
|
+
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: [
|
|
1111
|
+
{ provide: CNGX_TAB_GROUP_HOST, useExisting: CngxTabGroupPresenter },
|
|
1112
|
+
{ provide: CNGX_STATEFUL, useExisting: CngxTabGroupPresenter },
|
|
1113
|
+
], exportAs: ["cngxTabGroup"], ngImport: i0 });
|
|
1070
1114
|
}
|
|
1115
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabGroupPresenter, decorators: [{
|
|
1116
|
+
type: Directive,
|
|
1117
|
+
args: [{
|
|
1118
|
+
selector: '[cngxTabGroup]',
|
|
1119
|
+
exportAs: 'cngxTabGroup',
|
|
1120
|
+
standalone: true,
|
|
1121
|
+
providers: [
|
|
1122
|
+
{ provide: CNGX_TAB_GROUP_HOST, useExisting: CngxTabGroupPresenter },
|
|
1123
|
+
{ provide: CNGX_STATEFUL, useExisting: CngxTabGroupPresenter },
|
|
1124
|
+
],
|
|
1125
|
+
}]
|
|
1126
|
+
}], 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"] }] } });
|
|
1071
1127
|
/**
|
|
1072
|
-
*
|
|
1073
|
-
* (
|
|
1074
|
-
*
|
|
1075
|
-
*
|
|
1128
|
+
* Follow a stored flat rejection index across the removal of the tab at
|
|
1129
|
+
* `removed`. The referenced tab going away drops the marker (`undefined`);
|
|
1130
|
+
* a removal ahead of it shifts it down one slot; a removal after it leaves
|
|
1131
|
+
* it put. Keeps `lastFailedIndex` / `originIndexDuringCommit` pointing at the
|
|
1132
|
+
* same handle once the consumer removes a dismissed tab from its data.
|
|
1076
1133
|
*
|
|
1077
|
-
* @
|
|
1134
|
+
* @internal
|
|
1078
1135
|
*/
|
|
1079
|
-
function
|
|
1080
|
-
|
|
1136
|
+
function shiftIndexOnClose(stored, removed) {
|
|
1137
|
+
if (stored === undefined || removed === stored) {
|
|
1138
|
+
return undefined;
|
|
1139
|
+
}
|
|
1140
|
+
return removed < stored ? stored - 1 : stored;
|
|
1081
1141
|
}
|
|
1082
1142
|
/**
|
|
1083
|
-
*
|
|
1084
|
-
*
|
|
1085
|
-
*
|
|
1143
|
+
* {@link shiftIndexOnClose} for a settle record: the same object when the
|
|
1144
|
+
* index stays put (no re-emission), a copy with the shifted index and the
|
|
1145
|
+
* SAME sequence when it moves, `undefined` when its own tab is closed.
|
|
1086
1146
|
*
|
|
1087
|
-
* @
|
|
1147
|
+
* @internal
|
|
1088
1148
|
*/
|
|
1089
|
-
function
|
|
1090
|
-
|
|
1149
|
+
function shiftOutcomeOnClose(outcome, removed) {
|
|
1150
|
+
if (outcome === undefined) {
|
|
1151
|
+
return undefined;
|
|
1152
|
+
}
|
|
1153
|
+
const index = shiftIndexOnClose(outcome.index, removed);
|
|
1154
|
+
if (index === undefined) {
|
|
1155
|
+
return undefined;
|
|
1156
|
+
}
|
|
1157
|
+
return index === outcome.index ? outcome : { ...outcome, index };
|
|
1091
1158
|
}
|
|
1092
1159
|
/**
|
|
1093
|
-
*
|
|
1094
|
-
*
|
|
1095
|
-
*
|
|
1160
|
+
* Registry equality for the tab registry signal: element-wise reference
|
|
1161
|
+
* identity, not structural comparison. Two arrays are equal only when
|
|
1162
|
+
* they carry the exact same handle instances in the same order.
|
|
1096
1163
|
*
|
|
1097
|
-
*
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
*
|
|
1104
|
-
*
|
|
1105
|
-
*
|
|
1164
|
+
* Handles are stable per-tab references - `label`, `disabled`,
|
|
1165
|
+
* `hasError` and friends propagate through the handle's signals, so
|
|
1166
|
+
* consumers update off the handle without the registry array
|
|
1167
|
+
* re-emitting, and value comparison here would be redundant for an
|
|
1168
|
+
* unchanged handle. For a REPLACED handle (idempotent re-register
|
|
1169
|
+
* under an id collision) a value compare is actively wrong: it reports
|
|
1170
|
+
* the value-identical new instance as equal, discards the write, and
|
|
1171
|
+
* leaves the registry serving the destroyed instance's signals.
|
|
1172
|
+
* Reference inequality is the change signal.
|
|
1106
1173
|
*
|
|
1107
|
-
* @
|
|
1174
|
+
* @internal
|
|
1108
1175
|
*/
|
|
1109
|
-
function
|
|
1110
|
-
|
|
1176
|
+
function tabsEqual(a, b) {
|
|
1177
|
+
if (a === b) {
|
|
1178
|
+
return true;
|
|
1179
|
+
}
|
|
1180
|
+
if (a.length !== b.length) {
|
|
1181
|
+
return false;
|
|
1182
|
+
}
|
|
1183
|
+
for (let i = 0; i < a.length; i++) {
|
|
1184
|
+
if (a[i] !== b[i]) {
|
|
1185
|
+
return false;
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
return true;
|
|
1111
1189
|
}
|
|
1190
|
+
|
|
1112
1191
|
/**
|
|
1113
|
-
*
|
|
1114
|
-
*
|
|
1192
|
+
* DI token the organism provides via `useExisting`.\
|
|
1193
|
+
* The overflow molecule and consumer-authored skin sub-components inject this
|
|
1194
|
+
* instead of the concrete component class.
|
|
1115
1195
|
*
|
|
1116
1196
|
* @category common/tabs
|
|
1197
|
+
* @wcag AA
|
|
1198
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/tab-panel-host.token.ts
|
|
1199
|
+
* @since 0.1.0
|
|
1117
1200
|
*/
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
...cfg,
|
|
1121
|
-
ariaLabels: { ...cfg.ariaLabels, ...labels },
|
|
1122
|
-
}));
|
|
1123
|
-
}
|
|
1201
|
+
const CNGX_TAB_PANEL_HOST = new InjectionToken('CngxTabPanelHost');
|
|
1202
|
+
|
|
1124
1203
|
/**
|
|
1125
|
-
*
|
|
1126
|
-
*
|
|
1204
|
+
* Marks a tab presenter as the **navigation** flavour rather than the
|
|
1205
|
+
* tablist flavour. \
|
|
1206
|
+
* Provided by `<cngx-tab-nav>` (`@cngx/ui/tabs`) and `[cngxMatTabNav]`
|
|
1207
|
+
* (`@cngx/ui/mat-tabs`); deliberately not provided by `<cngx-tab-group>`.
|
|
1127
1208
|
*
|
|
1128
|
-
*
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
}));
|
|
1135
|
-
}
|
|
1136
|
-
/**
|
|
1137
|
-
* Override the IO-debounce window (ms). See
|
|
1138
|
-
* {@link CngxTabsConfig.overflowStabilizeMs}.
|
|
1209
|
+
* Presence-only by design. There is no contract interface: providers
|
|
1210
|
+
* register `{ provide: CNGX_TAB_NAV_HOST, useValue: true }` and readers
|
|
1211
|
+
* only ever test `navHost != null`. Nothing here can be widened into a
|
|
1212
|
+
* second host contract - {@link CNGX_TAB_GROUP_HOST} already owns the
|
|
1213
|
+
* presenter surface, and this token sits beside it so the tablist path
|
|
1214
|
+
* gains no dead field.
|
|
1139
1215
|
*
|
|
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}.
|
|
1216
|
+
* **Why a token and not the host class.** A sub-directive talks to its
|
|
1217
|
+
* host through DI, never through a concrete class: importing `CngxTabNav`
|
|
1218
|
+
* from `@cngx/common` would be a `common -> ui` edge that Sheriff rejects,
|
|
1219
|
+
* and element-tag sniffing breaks the moment a decomposed skin renames the
|
|
1220
|
+
* element.
|
|
1151
1221
|
*
|
|
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.
|
|
1222
|
+
* **What reads it.** {@link CngxTabsRouteSync} injects it
|
|
1223
|
+
* `{ optional: true, host: true }` to pick its URL-matching semantics: a
|
|
1224
|
+
* nav link owns a whole subtree and stays current for every URL beneath it
|
|
1225
|
+
* (prefix), while a tablist tab is a leaf and matches only its own route
|
|
1226
|
+
* (suffix). The `[match]` input overrides the token-derived default when a
|
|
1227
|
+
* consumer needs the other mode.
|
|
1163
1228
|
*
|
|
1164
1229
|
* ```ts
|
|
1165
|
-
*
|
|
1166
|
-
* '
|
|
1167
|
-
* {
|
|
1168
|
-
*
|
|
1169
|
-
*
|
|
1170
|
-
*
|
|
1230
|
+
* @Component({
|
|
1231
|
+
* selector: 'my-section-nav',
|
|
1232
|
+
* providers: [{ provide: CNGX_TAB_NAV_HOST, useValue: true }],
|
|
1233
|
+
* hostDirectives: [CngxTabGroupPresenter],
|
|
1234
|
+
* })
|
|
1235
|
+
* export class MySectionNav {}
|
|
1171
1236
|
* ```
|
|
1172
1237
|
*
|
|
1173
1238
|
* @category common/tabs
|
|
1239
|
+
* @wcag AA
|
|
1240
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/tab-nav-host.token.ts
|
|
1241
|
+
* @since 0.1.0
|
|
1242
|
+
* @relatedTo CngxTabsRouteSync, CNGX_TAB_GROUP_HOST, CngxTabNav, CngxMatTabNav
|
|
1174
1243
|
*/
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
...cfg,
|
|
1178
|
-
templates: { ...cfg.templates, overflowTrigger: template },
|
|
1179
|
-
}));
|
|
1180
|
-
}
|
|
1244
|
+
const CNGX_TAB_NAV_HOST = new InjectionToken('CngxTabNavHost');
|
|
1245
|
+
|
|
1181
1246
|
/**
|
|
1182
|
-
*
|
|
1183
|
-
*
|
|
1184
|
-
*
|
|
1185
|
-
* @category common/tabs
|
|
1247
|
+
* Path-segment count of a resolved `UrlTree`, used to rank prefix
|
|
1248
|
+
* matches: `/rounds/explorer` outranks `/rounds` on a URL both match.
|
|
1186
1249
|
*/
|
|
1187
|
-
function
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1250
|
+
function urlTreeSegmentCount(tree) {
|
|
1251
|
+
let count = 0;
|
|
1252
|
+
const walk = (group) => {
|
|
1253
|
+
count += group.segments.length;
|
|
1254
|
+
for (const key of Object.keys(group.children)) {
|
|
1255
|
+
walk(group.children[key]);
|
|
1256
|
+
}
|
|
1257
|
+
};
|
|
1258
|
+
walk(tree.root);
|
|
1259
|
+
return count;
|
|
1260
|
+
}
|
|
1261
|
+
/**
|
|
1262
|
+
* Primary-outlet path segments of the current URL, decoded. Going
|
|
1263
|
+
* through `router.parseUrl` (not a hand-rolled split) keeps matrix
|
|
1264
|
+
* params (`;theme=dark`) out of the compared paths, decodes
|
|
1265
|
+
* percent-encoded segments so they compare against raw `routeFor`
|
|
1266
|
+
* commands, and confines the walk to the primary outlet so an aux
|
|
1267
|
+
* outlet (`(aside:x)`) can neither pollute the tail nor match.
|
|
1199
1268
|
*/
|
|
1200
|
-
function
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1269
|
+
function primaryPathSegments(router) {
|
|
1270
|
+
const segments = [];
|
|
1271
|
+
let group = router.parseUrl(router.url).root;
|
|
1272
|
+
while (group !== undefined) {
|
|
1273
|
+
segments.push(...group.segments.map((segment) => segment.path));
|
|
1274
|
+
group = group.children[PRIMARY_OUTLET];
|
|
1275
|
+
}
|
|
1276
|
+
return segments;
|
|
1205
1277
|
}
|
|
1206
1278
|
/**
|
|
1207
|
-
*
|
|
1208
|
-
*
|
|
1209
|
-
*
|
|
1210
|
-
*
|
|
1211
|
-
*
|
|
1212
|
-
*
|
|
1279
|
+
* Find the tab whose route is the trailing segment(s) of the current URL
|
|
1280
|
+
* path. Anchors on position, not a loose "appears anywhere" scan - a tab
|
|
1281
|
+
* id that happens to equal an unrelated parent segment cannot win. The
|
|
1282
|
+
* path is the decoded primary-outlet segment list (query, fragment,
|
|
1283
|
+
* matrix params, and aux outlets excluded). If two tabs produce the same
|
|
1284
|
+
* trailing segment(s) (only possible with a colliding custom `routeFor`),
|
|
1285
|
+
* the first registered tab wins; the default id-based mapping never
|
|
1286
|
+
* collides.
|
|
1213
1287
|
*/
|
|
1214
|
-
function
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1288
|
+
function resolveBySuffix(ctx) {
|
|
1289
|
+
const segments = primaryPathSegments(ctx.router);
|
|
1290
|
+
for (const tab of ctx.tabs) {
|
|
1291
|
+
const route = ctx.routeFor(tab).map((command) => String(command));
|
|
1292
|
+
if (route.length === 0 || route.length > segments.length) {
|
|
1293
|
+
continue;
|
|
1294
|
+
}
|
|
1295
|
+
const tail = segments.slice(-route.length);
|
|
1296
|
+
if (tail.every((segment, i) => segment === route[i])) {
|
|
1297
|
+
return tab.id;
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
return null;
|
|
1219
1301
|
}
|
|
1220
1302
|
/**
|
|
1221
|
-
*
|
|
1222
|
-
*
|
|
1223
|
-
*
|
|
1303
|
+
* Find the tab that owns the current URL's subtree: the one whose
|
|
1304
|
+
* resolved `UrlTree` is a subset of the active tree, ignoring query
|
|
1305
|
+
* params, fragment, and matrix params.
|
|
1224
1306
|
*
|
|
1225
|
-
*
|
|
1307
|
+
* Routes resolve `{ relativeTo: ActivatedRoute }` rather than against the
|
|
1308
|
+
* URL root. A root-anchored segment compare breaks a nav mounted under a
|
|
1309
|
+
* base path - at `/app/rounds` a `['rounds']` route would compare
|
|
1310
|
+
* `'app' === 'rounds'`, resolve `null`, and hand the first link a wrong
|
|
1311
|
+
* `aria-current`, which is the exact defect prefix mode exists to fix.
|
|
1312
|
+
* Relative resolution is safe on the read side because the nav path is
|
|
1313
|
+
* commit-free: links navigate through their own `routerLink`, so nothing
|
|
1314
|
+
* here can diverge from a commit navigation.
|
|
1315
|
+
*
|
|
1316
|
+
* Longest route wins, so a `/rounds` tab cannot shadow `/rounds/explorer`
|
|
1317
|
+
* in the same set.
|
|
1226
1318
|
*/
|
|
1227
|
-
function
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1319
|
+
function resolveByPrefix(ctx) {
|
|
1320
|
+
let winner = null;
|
|
1321
|
+
let winnerDepth = -1;
|
|
1322
|
+
for (const tab of ctx.tabs) {
|
|
1323
|
+
const route = ctx.routeFor(tab);
|
|
1324
|
+
if (route.length === 0) {
|
|
1325
|
+
continue;
|
|
1326
|
+
}
|
|
1327
|
+
const tree = ctx.router.createUrlTree(route, { relativeTo: ctx.activatedRoute });
|
|
1328
|
+
const active = ctx.router.isActive(tree, {
|
|
1329
|
+
paths: 'subset',
|
|
1330
|
+
queryParams: 'ignored',
|
|
1331
|
+
fragment: 'ignored',
|
|
1332
|
+
matrixParams: 'ignored',
|
|
1333
|
+
});
|
|
1334
|
+
if (!active) {
|
|
1335
|
+
continue;
|
|
1336
|
+
}
|
|
1337
|
+
const depth = urlTreeSegmentCount(tree);
|
|
1338
|
+
if (depth > winnerDepth) {
|
|
1339
|
+
winner = tab.id;
|
|
1340
|
+
winnerDepth = depth;
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
return winner;
|
|
1232
1344
|
}
|
|
1233
1345
|
/**
|
|
1234
|
-
*
|
|
1235
|
-
*
|
|
1236
|
-
*
|
|
1346
|
+
* The two URL-matching policies `[cngxTabsRouteSync]` ships, dispatched
|
|
1347
|
+
* on {@link CngxTabUrlMatchContext.mode}. Same exact-versus-prefix
|
|
1348
|
+
* distinction `routerLinkActive` draws.
|
|
1349
|
+
*
|
|
1350
|
+
* Pure: no injection context, no signal reads. The directive resolves the
|
|
1351
|
+
* mode cascade and the tab registry, then hands both in.
|
|
1237
1352
|
*
|
|
1238
1353
|
* @category common/tabs
|
|
1239
1354
|
*/
|
|
1240
|
-
function
|
|
1241
|
-
return
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1355
|
+
function createTabUrlMatch() {
|
|
1356
|
+
return {
|
|
1357
|
+
resolve(ctx) {
|
|
1358
|
+
return ctx.mode === 'prefix' ? resolveByPrefix(ctx) : resolveBySuffix(ctx);
|
|
1359
|
+
},
|
|
1360
|
+
};
|
|
1245
1361
|
}
|
|
1246
1362
|
/**
|
|
1247
|
-
*
|
|
1248
|
-
*
|
|
1363
|
+
* Swap point for how a routed tab set decides which tab the URL belongs
|
|
1364
|
+
* to. Default {@link createTabUrlMatch}.
|
|
1365
|
+
*
|
|
1366
|
+
* Override when neither shipped policy fits: locale-segment-insensitive
|
|
1367
|
+
* comparison (`/de/rounds` and `/en/rounds` are the same tab), matching
|
|
1368
|
+
* on a route `data` key instead of the path, or a permission-aware read
|
|
1369
|
+
* that skips tabs the user cannot open. `routeFor` only changes what a
|
|
1370
|
+
* tab's route *is*; this changes how it is *compared*.
|
|
1371
|
+
*
|
|
1372
|
+
* Mirrors {@link CNGX_TABS_COMMIT_ACTION} on the write side: the
|
|
1373
|
+
* navigation a tab switch performs is already swappable, so the read that
|
|
1374
|
+
* mirrors navigation back onto `activeIndex` should be too.
|
|
1249
1375
|
*
|
|
1250
1376
|
* @category common/tabs
|
|
1377
|
+
* @wcag AA
|
|
1378
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/url-match.ts
|
|
1379
|
+
* @since 0.1.0
|
|
1380
|
+
* @relatedTo CngxTabsRouteSync, createTabUrlMatch, createTabRouterCommit
|
|
1251
1381
|
*/
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
}
|
|
1382
|
+
const CNGX_TAB_URL_MATCH_STRATEGY = new InjectionToken('CngxTabUrlMatchStrategy', {
|
|
1383
|
+
providedIn: 'root',
|
|
1384
|
+
factory: () => createTabUrlMatch(),
|
|
1385
|
+
});
|
|
1386
|
+
|
|
1258
1387
|
/**
|
|
1259
|
-
*
|
|
1260
|
-
*
|
|
1388
|
+
* Structural slot directive marking the per-tab panel-body template. \
|
|
1389
|
+
* Discovered by `<cngx-tab-group>` via `contentChild` on each
|
|
1390
|
+
* `CngxTab` and projected into the matching `role="tabpanel"`.
|
|
1391
|
+
*
|
|
1392
|
+
* ```html
|
|
1393
|
+
* <div cngxTab [label]="'Settings'">
|
|
1394
|
+
* <ng-template cngxTabContent>
|
|
1395
|
+
* <p>Settings panel body…</p>
|
|
1396
|
+
* </ng-template>
|
|
1397
|
+
* </div>
|
|
1398
|
+
* ```
|
|
1261
1399
|
*
|
|
1262
1400
|
* @category common/tabs
|
|
1401
|
+
* @wcag AA
|
|
1402
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/tab-content.directive.ts
|
|
1403
|
+
* @since 0.1.0
|
|
1404
|
+
* @relatedTo CngxTab, CngxTabLabel
|
|
1263
1405
|
*/
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
}));
|
|
1269
|
-
}
|
|
1270
|
-
function resolveFeatures(features) {
|
|
1271
|
-
return features.reduce((cfg, feat) => feat(cfg), TABS_CONFIG_DEFAULTS);
|
|
1406
|
+
class CngxTabContent {
|
|
1407
|
+
templateRef = inject((TemplateRef));
|
|
1408
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabContent, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1409
|
+
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
1410
|
}
|
|
1411
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabContent, decorators: [{
|
|
1412
|
+
type: Directive,
|
|
1413
|
+
args: [{
|
|
1414
|
+
selector: 'ng-template[cngxTabContent]',
|
|
1415
|
+
exportAs: 'cngxTabContent',
|
|
1416
|
+
standalone: true,
|
|
1417
|
+
}]
|
|
1418
|
+
}] });
|
|
1419
|
+
|
|
1273
1420
|
/**
|
|
1274
|
-
*
|
|
1275
|
-
*
|
|
1276
|
-
*
|
|
1421
|
+
* Structural slot directive marking the per-tab label template. \
|
|
1422
|
+
* Discovered by `<cngx-tab-group>` via `contentChild` on each
|
|
1423
|
+
* `CngxTab` and projected into the tab strip.
|
|
1424
|
+
*
|
|
1425
|
+
* ```html
|
|
1426
|
+
* <div cngxTab id="settings">
|
|
1427
|
+
* <ng-template cngxTabLabel>Settings</ng-template>
|
|
1428
|
+
* ... tab content ...
|
|
1429
|
+
* </div>
|
|
1430
|
+
* ```
|
|
1277
1431
|
*
|
|
1278
1432
|
* @category common/tabs
|
|
1433
|
+
* @wcag AA
|
|
1434
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/tab-label.directive.ts
|
|
1435
|
+
* @since 0.1.0
|
|
1436
|
+
* @relatedTo CngxTab, CngxTabContent
|
|
1279
1437
|
*/
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
]);
|
|
1438
|
+
class CngxTabLabel {
|
|
1439
|
+
templateRef = inject((TemplateRef));
|
|
1440
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabLabel, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1441
|
+
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
1442
|
}
|
|
1443
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabLabel, decorators: [{
|
|
1444
|
+
type: Directive,
|
|
1445
|
+
args: [{
|
|
1446
|
+
selector: 'ng-template[cngxTabLabel]',
|
|
1447
|
+
exportAs: 'cngxTabLabel',
|
|
1448
|
+
standalone: true,
|
|
1449
|
+
}]
|
|
1450
|
+
}] });
|
|
1451
|
+
|
|
1285
1452
|
/**
|
|
1286
|
-
*
|
|
1287
|
-
*
|
|
1288
|
-
*
|
|
1289
|
-
*
|
|
1453
|
+
* Structural slot directive marking a tab's secondary label template. \
|
|
1454
|
+
* Discovered by `<cngx-tab-group>` via `contentChild` on each
|
|
1455
|
+
* `CngxTab` and rendered as a stacked second line under the primary
|
|
1456
|
+
* label. \
|
|
1290
1457
|
*
|
|
1291
|
-
*
|
|
1292
|
-
*
|
|
1293
|
-
*
|
|
1294
|
-
*
|
|
1458
|
+
* Per-tab content, mirroring `CngxTabLabel` - the convenience
|
|
1459
|
+
* `[subLabel]` string input on `CngxTab` covers the plain-text case.
|
|
1460
|
+
*
|
|
1461
|
+
* ```html
|
|
1462
|
+
* <div cngxTab id="bookmarks">
|
|
1463
|
+
* <ng-template cngxTabLabel>Bookmarks</ng-template>
|
|
1464
|
+
* <ng-template cngxTabSubLabel>45 saved</ng-template>
|
|
1465
|
+
* <ng-template cngxTabContent>...</ng-template>
|
|
1466
|
+
* </div>
|
|
1295
1467
|
* ```
|
|
1296
1468
|
*
|
|
1297
|
-
* @category common/tabs
|
|
1469
|
+
* @category common/tabs/slots
|
|
1470
|
+
* @wcag AA
|
|
1471
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/slots/tab-sub-label.directive.ts
|
|
1472
|
+
* @since 0.1.0
|
|
1473
|
+
* @relatedTo CngxTab, CngxTabLabel, CngxTabContent
|
|
1474
|
+
* <example-url>http://localhost:4200/#/ui/tabs/tab-sub-label/label-with-count</example-url>
|
|
1298
1475
|
*/
|
|
1299
|
-
|
|
1300
|
-
|
|
1476
|
+
class CngxTabSubLabel {
|
|
1477
|
+
/**
|
|
1478
|
+
* The captured `<ng-template>`, projected by `<cngx-tab-group>` as the
|
|
1479
|
+
* tab's secondary label line under the primary label.
|
|
1480
|
+
*/
|
|
1481
|
+
templateRef = inject((TemplateRef));
|
|
1482
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabSubLabel, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1483
|
+
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
1484
|
}
|
|
1485
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabSubLabel, decorators: [{
|
|
1486
|
+
type: Directive,
|
|
1487
|
+
args: [{
|
|
1488
|
+
selector: 'ng-template[cngxTabSubLabel]',
|
|
1489
|
+
exportAs: 'cngxTabSubLabel',
|
|
1490
|
+
standalone: true,
|
|
1491
|
+
}]
|
|
1492
|
+
}] });
|
|
1493
|
+
|
|
1302
1494
|
/**
|
|
1303
|
-
*
|
|
1495
|
+
* Single-tab atom. \
|
|
1496
|
+
* Registers with the enclosing presenter via
|
|
1497
|
+
* {@link CNGX_TAB_GROUP_HOST} on construction; deregisters via
|
|
1498
|
+
* {@link DestroyRef} on teardown. \
|
|
1499
|
+
* The presenter holds the atom's
|
|
1500
|
+
* input signals by reference, so input changes propagate without
|
|
1501
|
+
* re-registration. \
|
|
1502
|
+
* `labelTemplate` / `contentTemplate` are projected
|
|
1503
|
+
* by the organism - the atom carries no rendering logic.
|
|
1304
1504
|
*
|
|
1505
|
+
* ```html
|
|
1506
|
+
* <div cngxTab [label]="'Settings'">
|
|
1507
|
+
* ... content templates here ...
|
|
1508
|
+
* </div>
|
|
1509
|
+
* ```
|
|
1305
1510
|
* @category common/tabs
|
|
1511
|
+
* @docsKind primary
|
|
1512
|
+
* @wcag AA
|
|
1513
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/tab.directive.ts
|
|
1514
|
+
* @since 0.1.0
|
|
1515
|
+
* @relatedTo CngxTabGroupPresenter, CngxTabLabel, CngxTabContent, CngxTabErrorBadge
|
|
1516
|
+
* @slot cngxTabLabel The tab's own header label.
|
|
1517
|
+
* @slot cngxTabSubLabel Secondary line under the label, e.g. a count or status.
|
|
1518
|
+
* @slot cngxTabContent The panel body, rendered lazily when the tab activates.
|
|
1306
1519
|
*/
|
|
1307
|
-
|
|
1308
|
-
|
|
1520
|
+
class CngxTab {
|
|
1521
|
+
id = input(nextUid('cngx-tab-'), ...(ngDevMode ? [{ debugName: "id" }] : /* istanbul ignore next */ []));
|
|
1522
|
+
disabled = input(false, ...(ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []));
|
|
1523
|
+
label = input(undefined, ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
|
|
1524
|
+
/**
|
|
1525
|
+
* Optional secondary text line under the primary label (a count, a
|
|
1526
|
+
* status word, a short detail). Convenience for the common text
|
|
1527
|
+
* case, parallel to `[label]`; the `*cngxTabSubLabel` slot covers
|
|
1528
|
+
* richer content. Folds into the tab's accessible name.
|
|
1529
|
+
*/
|
|
1530
|
+
subLabel = input(undefined, ...(ngDevMode ? [{ debugName: "subLabel" }] : /* istanbul ignore next */ []));
|
|
1531
|
+
errorAggregator = input(undefined, ...(ngDevMode ? [{ debugName: "errorAggregator" }] : /* istanbul ignore next */ []));
|
|
1532
|
+
/**
|
|
1533
|
+
* Direct error flag for the common "this tab is invalid" case - no
|
|
1534
|
+
* `errorAggregator` boilerplate required. `true` or a non-empty string
|
|
1535
|
+
* drives the error state; a string doubles as the inline message
|
|
1536
|
+
* (surfaced via the `*cngxTabErrorBadge` slot context). `false` / `''`
|
|
1537
|
+
* clear it. The aggregator stays the rich multi-source forms path; the
|
|
1538
|
+
* two channels compose (either errors). Mirrors `CngxStep.error`.
|
|
1539
|
+
*/
|
|
1540
|
+
error = input(false, ...(ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []));
|
|
1541
|
+
/**
|
|
1542
|
+
* Resolved direct-error message: the `[error]` string when non-empty,
|
|
1543
|
+
* else `undefined`. Carried onto the registration handle so the error
|
|
1544
|
+
* badge slot can render it. `computed` over the input - never written.
|
|
1545
|
+
*/
|
|
1546
|
+
errorMessage = computed(() => {
|
|
1547
|
+
const value = this.error();
|
|
1548
|
+
return typeof value === 'string' && value !== '' ? value : undefined;
|
|
1549
|
+
}, ...(ngDevMode ? [{ debugName: "errorMessage" }] : /* istanbul ignore next */ []));
|
|
1550
|
+
/**
|
|
1551
|
+
* Per-tab error fold driving the badge + SR descriptor. `true` when
|
|
1552
|
+
* the direct `[error]` flag is set OR the optional aggregator wants to
|
|
1553
|
+
* reveal (`shouldShow()` = `hasError` AND scope reveal-state). The
|
|
1554
|
+
* aggregator arm reads `shouldShow`, not `hasError`, so deferred-reveal
|
|
1555
|
+
* validation stays silent until revealed - the direct flag has no
|
|
1556
|
+
* reveal concept (the consumer sets it when it wants it shown). A
|
|
1557
|
+
* boolean, not a status enum: tabs carry no success/completed/disabled
|
|
1558
|
+
* model (Pillar 3).
|
|
1559
|
+
*/
|
|
1560
|
+
hasError = computed(() => {
|
|
1561
|
+
const directError = this.error();
|
|
1562
|
+
return ((directError !== false && directError !== '') ||
|
|
1563
|
+
(this.errorAggregator()?.shouldShow?.() ?? false));
|
|
1564
|
+
}, { ...(ngDevMode ? { debugName: "hasError" } : /* istanbul ignore next */ {}), equal: Object.is });
|
|
1565
|
+
/**
|
|
1566
|
+
* Per-tab close-affordance override. `undefined` (default) inherits
|
|
1567
|
+
* the group-level `[closable]` resolution; set `false` to pin this
|
|
1568
|
+
* tab open inside a dismissable group, or `true` to make a single tab
|
|
1569
|
+
* closable while the group default is off.
|
|
1570
|
+
*/
|
|
1571
|
+
closable = input(undefined, ...(ngDevMode ? [{ debugName: "closable" }] : /* istanbul ignore next */ []));
|
|
1572
|
+
labelTemplate = contentChild(CngxTabLabel, ...(ngDevMode ? [{ debugName: "labelTemplate" }] : /* istanbul ignore next */ []));
|
|
1573
|
+
subLabelTemplate = contentChild(CngxTabSubLabel, ...(ngDevMode ? [{ debugName: "subLabelTemplate" }] : /* istanbul ignore next */ []));
|
|
1574
|
+
contentTemplate = contentChild(CngxTabContent, ...(ngDevMode ? [{ debugName: "contentTemplate" }] : /* istanbul ignore next */ []));
|
|
1575
|
+
host = inject(CNGX_TAB_GROUP_HOST, { optional: true });
|
|
1576
|
+
destroyRef = inject(DestroyRef);
|
|
1577
|
+
/** `true` when the presenter's `activeId` equals this tab's id. */
|
|
1578
|
+
selected = computed(() => this.host?.activeId() === this.id(), { ...(ngDevMode ? { debugName: "selected" } : /* istanbul ignore next */ {}), equal: Object.is });
|
|
1579
|
+
constructor() {
|
|
1580
|
+
if (!this.host) {
|
|
1581
|
+
throw new CngxRuntimeError('CNGX1045', typeof ngDevMode !== 'undefined' &&
|
|
1582
|
+
ngDevMode &&
|
|
1583
|
+
'[cngxTab] must be placed inside <cngx-tab-group> or an element with [cngxTabGroup].');
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
ngOnInit() {
|
|
1587
|
+
// Register in ngOnInit, NOT the constructor: a dynamically-bound
|
|
1588
|
+
// `[id]` (or `[label]`) signal input is not applied until the first
|
|
1589
|
+
// change detection, so a constructor read would capture the default
|
|
1590
|
+
// auto-id. The handle id is the stable key consumers map `(tabClose)`
|
|
1591
|
+
// back to their data with, so it must reflect the bound `[id]`.
|
|
1592
|
+
// The id is captured once here - init-stable by contract. A later
|
|
1593
|
+
// `[id]` rebind does not re-register; the auto-uid default makes a
|
|
1594
|
+
// stable consumer-supplied id the normal case. Mirrors CngxStep.
|
|
1595
|
+
const host = this.host;
|
|
1596
|
+
const tabId = this.id();
|
|
1597
|
+
const handle = {
|
|
1598
|
+
id: tabId,
|
|
1599
|
+
label: this.label,
|
|
1600
|
+
subLabel: this.subLabel,
|
|
1601
|
+
disabled: this.disabled,
|
|
1602
|
+
errorAggregator: this.errorAggregator,
|
|
1603
|
+
hasError: this.hasError,
|
|
1604
|
+
errorMessage: this.errorMessage,
|
|
1605
|
+
closable: this.closable,
|
|
1606
|
+
};
|
|
1607
|
+
host.register(handle);
|
|
1608
|
+
this.destroyRef.onDestroy(() => host.unregister(tabId, handle));
|
|
1609
|
+
}
|
|
1610
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTab, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1611
|
+
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
1612
|
}
|
|
1613
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTab, decorators: [{
|
|
1614
|
+
type: Directive,
|
|
1615
|
+
args: [{
|
|
1616
|
+
selector: '[cngxTab]',
|
|
1617
|
+
exportAs: 'cngxTab',
|
|
1618
|
+
standalone: true,
|
|
1619
|
+
}]
|
|
1620
|
+
}], 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
1621
|
|
|
1311
1622
|
/**
|
|
1312
1623
|
* Turns a consumer `<a routerLink>` into a registered {@link CngxTabHandle}
|
|
@@ -1408,16 +1719,20 @@ class CngxTabLink {
|
|
|
1408
1719
|
/** `true` when the presenter's `activeId` equals this link's id. */
|
|
1409
1720
|
selected = computed(() => this.host?.activeId() === this.id(), { ...(ngDevMode ? { debugName: "selected" } : /* istanbul ignore next */ {}), equal: Object.is });
|
|
1410
1721
|
/**
|
|
1411
|
-
* Id of the injected SR error-message descriptor.
|
|
1412
|
-
*
|
|
1413
|
-
*
|
|
1722
|
+
* Id of the injected SR error-message descriptor. The `aria-describedby`
|
|
1723
|
+
* host binding emits it only while `hasError()` - `aria-hidden` on a
|
|
1724
|
+
* directly-referenced node does not suppress it (accname 1.2 traverses
|
|
1725
|
+
* the reference), so the id reference itself is gated, not just the
|
|
1726
|
+
* span's visibility.
|
|
1414
1727
|
*/
|
|
1415
1728
|
descriptorId = computed(() => `${this.id()}-desc`, ...(ngDevMode ? [{ debugName: "descriptorId" }] : /* istanbul ignore next */ []));
|
|
1416
1729
|
/** The injected descriptor `<span>`, created in {@link ngOnInit}. */
|
|
1417
1730
|
descriptorEl = null;
|
|
1418
1731
|
constructor() {
|
|
1419
1732
|
if (!this.host) {
|
|
1420
|
-
throw new
|
|
1733
|
+
throw new CngxRuntimeError('CNGX1045', typeof ngDevMode !== 'undefined' &&
|
|
1734
|
+
ngDevMode &&
|
|
1735
|
+
'[cngxTabLink] must be placed inside <cngx-tab-nav> or an element with [cngxTabGroup].');
|
|
1421
1736
|
}
|
|
1422
1737
|
// Mirror the direct-error message into the describedby span. DOM side
|
|
1423
1738
|
// effect only - no signal writes. Guards until the span exists (created
|
|
@@ -1458,7 +1773,7 @@ class CngxTabLink {
|
|
|
1458
1773
|
this.descriptorEl = descriptor;
|
|
1459
1774
|
this.syncDescriptor(descriptor);
|
|
1460
1775
|
this.destroyRef.onDestroy(() => {
|
|
1461
|
-
host.unregister(handle.id);
|
|
1776
|
+
host.unregister(handle.id, handle);
|
|
1462
1777
|
if (parent) {
|
|
1463
1778
|
this.renderer.removeChild(parent, descriptor);
|
|
1464
1779
|
}
|
|
@@ -1482,7 +1797,7 @@ class CngxTabLink {
|
|
|
1482
1797
|
}
|
|
1483
1798
|
}
|
|
1484
1799
|
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 });
|
|
1800
|
+
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
1801
|
}
|
|
1487
1802
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabLink, decorators: [{
|
|
1488
1803
|
type: Directive,
|
|
@@ -1494,7 +1809,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1494
1809
|
class: 'cngx-tab-nav__link',
|
|
1495
1810
|
'[attr.aria-current]': 'selected() ? resolvedAriaCurrent() : null',
|
|
1496
1811
|
'[attr.aria-invalid]': "hasError() ? 'true' : null",
|
|
1497
|
-
'[attr.aria-describedby]': 'descriptorId()',
|
|
1812
|
+
'[attr.aria-describedby]': 'hasError() ? descriptorId() : null',
|
|
1498
1813
|
'[class.cngx-tab-nav__link--active]': 'selected()',
|
|
1499
1814
|
'[class.cngx-tab-nav__link--error]': 'hasError()',
|
|
1500
1815
|
},
|
|
@@ -1511,8 +1826,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1511
1826
|
*
|
|
1512
1827
|
* @internal
|
|
1513
1828
|
*/
|
|
1514
|
-
function warnTabsRouterAbsent(
|
|
1515
|
-
|
|
1829
|
+
function warnTabsRouterAbsent(selector, enables) {
|
|
1830
|
+
if (!(typeof ngDevMode !== 'undefined' && ngDevMode)) {
|
|
1831
|
+
return;
|
|
1832
|
+
}
|
|
1833
|
+
cngxDevWarn('CNGX1031', `[${selector}] no Router / ActivatedRoute available - the URL sync is a no-op. ` +
|
|
1516
1834
|
`Provide @angular/router via provideRouter(...) to enable ${enables}.`);
|
|
1517
1835
|
}
|
|
1518
1836
|
|
|
@@ -1555,8 +1873,15 @@ function warnTabsRouterAbsent(directive, enables) {
|
|
|
1555
1873
|
* @relatedTo CngxTabGroupPresenter, CngxTab
|
|
1556
1874
|
*/
|
|
1557
1875
|
class CngxTabsFragmentSync {
|
|
1558
|
-
|
|
1559
|
-
|
|
1876
|
+
// Default undefined so the cascade resolves through CNGX_TABS_CONFIG.
|
|
1877
|
+
// Init-only: the seed and the write effect capture the resolved mode /
|
|
1878
|
+
// param on their first run; changing either after init leaves the old
|
|
1879
|
+
// URL key behind. Rebuild the directive to change them.
|
|
1880
|
+
modeInput = input(undefined, { ...(ngDevMode ? { debugName: "modeInput" } : /* istanbul ignore next */ {}), alias: 'mode' });
|
|
1881
|
+
paramNameInput = input(undefined, { ...(ngDevMode ? { debugName: "paramNameInput" } : /* istanbul ignore next */ {}), alias: 'paramName' });
|
|
1882
|
+
config = injectTabsConfig();
|
|
1883
|
+
mode = computed(() => this.modeInput() ?? this.config.fragmentSyncMode ?? 'fragment', ...(ngDevMode ? [{ debugName: "mode" }] : /* istanbul ignore next */ []));
|
|
1884
|
+
paramName = computed(() => this.paramNameInput() ?? this.config.fragmentSyncParam ?? 'tab', ...(ngDevMode ? [{ debugName: "paramName" }] : /* istanbul ignore next */ []));
|
|
1560
1885
|
/**
|
|
1561
1886
|
* Whether reflecting the active tab into the URL replaces the current
|
|
1562
1887
|
* history entry instead of pushing a new one. Default `true`, which is
|
|
@@ -1568,7 +1893,7 @@ class CngxTabsFragmentSync {
|
|
|
1568
1893
|
* history entry.
|
|
1569
1894
|
*/
|
|
1570
1895
|
replaceUrl = input(true, ...(ngDevMode ? [{ debugName: "replaceUrl" }] : /* istanbul ignore next */ []));
|
|
1571
|
-
host =
|
|
1896
|
+
host = injectTabGroupHost('cngxTabsFragmentSync');
|
|
1572
1897
|
router = inject(Router, { optional: true });
|
|
1573
1898
|
/**
|
|
1574
1899
|
* Latched once the URL seed has reached a registered tab, so the
|
|
@@ -1584,8 +1909,13 @@ class CngxTabsFragmentSync {
|
|
|
1584
1909
|
*/
|
|
1585
1910
|
seeded = false;
|
|
1586
1911
|
constructor() {
|
|
1587
|
-
|
|
1588
|
-
|
|
1912
|
+
// Router is providedIn: 'root' and resolves without provideRouter(...);
|
|
1913
|
+
// ActivatedRoute does not, so it is the "router is set up" signal.
|
|
1914
|
+
const route = inject(ActivatedRoute, { optional: true });
|
|
1915
|
+
if (!this.router || !route) {
|
|
1916
|
+
if (typeof ngDevMode !== 'undefined' && ngDevMode) {
|
|
1917
|
+
afterNextRender(() => warnTabsRouterAbsent('cngxTabsFragmentSync', 'deep-linking'));
|
|
1918
|
+
}
|
|
1589
1919
|
return;
|
|
1590
1920
|
}
|
|
1591
1921
|
const router = this.router;
|
|
@@ -1597,27 +1927,21 @@ class CngxTabsFragmentSync {
|
|
|
1597
1927
|
afterNextRender(() => {
|
|
1598
1928
|
this.seedFromUrl(router);
|
|
1599
1929
|
});
|
|
1930
|
+
let initialReflect = true;
|
|
1600
1931
|
effect(() => {
|
|
1601
1932
|
const id = this.host.activeId();
|
|
1602
1933
|
if (!id) {
|
|
1603
1934
|
return;
|
|
1604
1935
|
}
|
|
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
|
-
});
|
|
1936
|
+
if (initialReflect) {
|
|
1937
|
+
// Bare mount is not an interaction: the first resolved active id
|
|
1938
|
+
// (default tab or URL seed) must not stamp the URL - a page that
|
|
1939
|
+
// merely renders tabs would otherwise rewrite its own history
|
|
1940
|
+
// entry. The URL starts changing when the active tab does.
|
|
1941
|
+
initialReflect = false;
|
|
1942
|
+
return;
|
|
1943
|
+
}
|
|
1944
|
+
untracked(() => this.writeUrl(router, id));
|
|
1621
1945
|
});
|
|
1622
1946
|
const navEnd = toSignal(router.events.pipe(filter((e) => e instanceof NavigationEnd), takeUntilDestroyed(destroyRef)), { initialValue: null });
|
|
1623
1947
|
effect(() => {
|
|
@@ -1671,6 +1995,36 @@ class CngxTabsFragmentSync {
|
|
|
1671
1995
|
this.seeded = true;
|
|
1672
1996
|
untracked(() => this.host.selectById(initial));
|
|
1673
1997
|
}
|
|
1998
|
+
/**
|
|
1999
|
+
* Reflect `id` into the URL. Fragment mode re-serializes the existing
|
|
2000
|
+
* fragment params so foreign state (`#foo=1&tab=x`) survives the
|
|
2001
|
+
* write; values are URI-encoded symmetric to {@link parseFragment}.
|
|
2002
|
+
*/
|
|
2003
|
+
writeUrl(router, id) {
|
|
2004
|
+
const replaceUrl = this.replaceUrl();
|
|
2005
|
+
const navigation = this.mode() === 'fragment'
|
|
2006
|
+
? router.navigate([], {
|
|
2007
|
+
fragment: this.serializeFragment(router, id),
|
|
2008
|
+
queryParamsHandling: 'merge',
|
|
2009
|
+
replaceUrl,
|
|
2010
|
+
})
|
|
2011
|
+
: router.navigate([], {
|
|
2012
|
+
queryParams: { [this.paramName()]: id },
|
|
2013
|
+
queryParamsHandling: 'merge',
|
|
2014
|
+
replaceUrl,
|
|
2015
|
+
});
|
|
2016
|
+
// Router rejection (e.g. cancelled navigation) has no recovery path.
|
|
2017
|
+
navigation.catch?.(() => undefined);
|
|
2018
|
+
}
|
|
2019
|
+
serializeFragment(router, id) {
|
|
2020
|
+
const param = this.paramName();
|
|
2021
|
+
const current = router.routerState.snapshot.root.fragment ?? '';
|
|
2022
|
+
const segments = current
|
|
2023
|
+
.split('&')
|
|
2024
|
+
.filter((seg) => seg !== '' && seg.split('=')[0] !== param);
|
|
2025
|
+
segments.push(`${param}=${encodeURIComponent(id)}`);
|
|
2026
|
+
return segments.join('&');
|
|
2027
|
+
}
|
|
1674
2028
|
readUrlValue(router) {
|
|
1675
2029
|
if (this.mode() === 'fragment') {
|
|
1676
2030
|
const fragment = router.routerState.snapshot.root.fragment ?? '';
|
|
@@ -1684,13 +2038,13 @@ class CngxTabsFragmentSync {
|
|
|
1684
2038
|
for (const seg of segments) {
|
|
1685
2039
|
const [key, val] = seg.split('=');
|
|
1686
2040
|
if (key === param && val) {
|
|
1687
|
-
return val;
|
|
2041
|
+
return decodeURIComponent(val);
|
|
1688
2042
|
}
|
|
1689
2043
|
}
|
|
1690
2044
|
return null;
|
|
1691
2045
|
}
|
|
1692
2046
|
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: {
|
|
2047
|
+
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
2048
|
}
|
|
1695
2049
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTabsFragmentSync, decorators: [{
|
|
1696
2050
|
type: Directive,
|
|
@@ -1699,7 +2053,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1699
2053
|
exportAs: 'cngxTabsFragmentSync',
|
|
1700
2054
|
standalone: true,
|
|
1701
2055
|
}]
|
|
1702
|
-
}], ctorParameters: () => [], propDecorators: {
|
|
2056
|
+
}], 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
2057
|
|
|
1704
2058
|
/**
|
|
1705
2059
|
* Default tab-to-route mapping: the tab id is the child segment.
|
|
@@ -1712,19 +2066,30 @@ const cngxDefaultTabRoute = (handle) => [handle.id];
|
|
|
1712
2066
|
/**
|
|
1713
2067
|
* Builds a {@link CngxTabsCommitAction} that gates a tab switch through
|
|
1714
2068
|
* `@angular/router`. The action navigates to the target tab's route and
|
|
1715
|
-
* resolves on
|
|
2069
|
+
* resolves on this navigation's own `navigate()` promise:
|
|
1716
2070
|
*
|
|
1717
|
-
* - `NavigationEnd` → `true` (commit the switch)
|
|
1718
|
-
* - `
|
|
1719
|
-
*
|
|
2071
|
+
* - resolved `true` (`NavigationEnd`) → `true` (commit the switch)
|
|
2072
|
+
* - resolved `null` (a skipped same-URL navigation, the route is
|
|
2073
|
+
* already active) → `true`
|
|
2074
|
+
* - resolved `false` (`NavigationCancel` - a `CanDeactivate` guard
|
|
2075
|
+
* blocked, or a newer navigation superseded this one) → `false`, a
|
|
2076
|
+
* refused switch: nothing failed, the commit state stores no error
|
|
2077
|
+
* - rejected (`NavigationError` - a guard or resolver threw) → the
|
|
2078
|
+
* observable errors with the router's original error, a failed
|
|
2079
|
+
* switch: the commit state goes to `'error'` and keeps that error
|
|
2080
|
+
*
|
|
2081
|
+
* This is the router's own model: a guard answering `false` cancels,
|
|
2082
|
+
* only a throw is an error.
|
|
1720
2083
|
*
|
|
1721
2084
|
* Routed tabs reuse the presenter's commit lifecycle verbatim - the
|
|
1722
2085
|
* router navigation is simply the async op. \
|
|
1723
2086
|
* 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()`
|
|
2087
|
+
* the old tab with zero extra gate machinery. Correlating on the
|
|
2088
|
+
* promise (not `router.events`) means a concurrent unrelated
|
|
2089
|
+
* navigation's outcome can never resolve this commit; the commit
|
|
2090
|
+
* controller's `cancel()` closes the subscriber on supersede, and a
|
|
2091
|
+
* late promise resolution lands on the closed subscriber and is
|
|
2092
|
+
* dropped by RxJS itself.
|
|
1728
2093
|
*
|
|
1729
2094
|
* @category common/tabs
|
|
1730
2095
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/tabs/router-commit.ts
|
|
@@ -1739,20 +2104,22 @@ function createTabRouterCommit(opts) {
|
|
|
1739
2104
|
subscriber.complete();
|
|
1740
2105
|
return;
|
|
1741
2106
|
}
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
2107
|
+
// Resolve from THIS call's promise - correlated by construction.
|
|
2108
|
+
// A take(1) on router.events would grab the first terminal event
|
|
2109
|
+
// of ANY navigation, so a concurrent unrelated navigation could
|
|
2110
|
+
// resolve this commit with a foreign outcome.
|
|
2111
|
+
opts.router.navigate(routeFor(target)).then((result) => {
|
|
2112
|
+
// `false` is a cancelled or superseded navigation. A skipped
|
|
2113
|
+
// same-URL navigation resolves `null` - the tab's route is
|
|
2114
|
+
// already active, which commits.
|
|
2115
|
+
subscriber.next(result !== false);
|
|
1748
2116
|
subscriber.complete();
|
|
2117
|
+
}, (err) => {
|
|
2118
|
+
// A guard or resolver threw (`NavigationError`): a failure,
|
|
2119
|
+
// not a refusal. Hand the router's own error on so the commit
|
|
2120
|
+
// state stores what actually went wrong.
|
|
2121
|
+
subscriber.error(err);
|
|
1749
2122
|
});
|
|
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
2123
|
});
|
|
1757
2124
|
}
|
|
1758
2125
|
|
|
@@ -1884,7 +2251,7 @@ class CngxTabsRouteSync {
|
|
|
1884
2251
|
* replaces the policies themselves.
|
|
1885
2252
|
*/
|
|
1886
2253
|
match = input(undefined, ...(ngDevMode ? [{ debugName: "match" }] : /* istanbul ignore next */ []));
|
|
1887
|
-
host =
|
|
2254
|
+
host = injectTabGroupHost('cngxTabsRouteSync');
|
|
1888
2255
|
router = inject(Router, { optional: true });
|
|
1889
2256
|
navHost = inject(CNGX_TAB_NAV_HOST, { optional: true, host: true });
|
|
1890
2257
|
config = injectTabsConfig();
|
|
@@ -1900,13 +2267,13 @@ class CngxTabsRouteSync {
|
|
|
1900
2267
|
mode = signal('pessimistic', ...(ngDevMode ? [{ debugName: "mode" }] : /* istanbul ignore next */ []));
|
|
1901
2268
|
/**
|
|
1902
2269
|
* Router commit-action read by the presenter via the DI fallback.
|
|
1903
|
-
* `null` when
|
|
2270
|
+
* `null` when the router is not set up (graceful no-op). Rebuilt only
|
|
1904
2271
|
* when `routeFor` changes; the navigation gate itself is the async
|
|
1905
2272
|
* op inside the action.
|
|
1906
2273
|
*/
|
|
1907
2274
|
action = computed(() => {
|
|
1908
2275
|
const router = this.router;
|
|
1909
|
-
if (!router) {
|
|
2276
|
+
if (!router || !this.activatedRoute) {
|
|
1910
2277
|
return null;
|
|
1911
2278
|
}
|
|
1912
2279
|
return createTabRouterCommit({
|
|
@@ -1916,8 +2283,12 @@ class CngxTabsRouteSync {
|
|
|
1916
2283
|
});
|
|
1917
2284
|
}, ...(ngDevMode ? [{ debugName: "action" }] : /* istanbul ignore next */ []));
|
|
1918
2285
|
constructor() {
|
|
1919
|
-
|
|
1920
|
-
|
|
2286
|
+
// Router is providedIn: 'root' and resolves without provideRouter(...);
|
|
2287
|
+
// ActivatedRoute does not, so it is the "router is set up" signal.
|
|
2288
|
+
if (!this.router || !this.activatedRoute) {
|
|
2289
|
+
if (typeof ngDevMode !== 'undefined' && ngDevMode) {
|
|
2290
|
+
afterNextRender(() => warnTabsRouterAbsent('cngxTabsRouteSync', 'routed tabs'));
|
|
2291
|
+
}
|
|
1921
2292
|
return;
|
|
1922
2293
|
}
|
|
1923
2294
|
const router = this.router;
|
|
@@ -2023,88 +2394,7 @@ function createTabsHostAttrs(inputs) {
|
|
|
2023
2394
|
};
|
|
2024
2395
|
}
|
|
2025
2396
|
|
|
2026
|
-
|
|
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
|
-
function partitionFeatures(features) {
|
|
2397
|
+
function partitionFeatures(features, caller) {
|
|
2108
2398
|
const config = [];
|
|
2109
2399
|
const i18n = [];
|
|
2110
2400
|
for (const feat of features) {
|
|
@@ -2119,11 +2409,17 @@ function partitionFeatures(features) {
|
|
|
2119
2409
|
// Unbranded feature - runtime escape from the `_target` type.
|
|
2120
2410
|
// Drop with dev-warn so an i18n-shaped override never lands
|
|
2121
2411
|
// silently in `CNGX_TABS_CONFIG`.
|
|
2122
|
-
if (
|
|
2123
|
-
|
|
2124
|
-
'
|
|
2125
|
-
|
|
2126
|
-
|
|
2412
|
+
if (typeof ngDevMode !== 'undefined' && ngDevMode) {
|
|
2413
|
+
if (caller === 'provideCngxTabsAt') {
|
|
2414
|
+
cngxDevWarn('CNGX1041', 'provideCngxTabsAt(): dropped feature without a `_target` ' +
|
|
2415
|
+
'discriminator. Pass config through the `with*` helpers of @cngx/common/tabs ' +
|
|
2416
|
+
'and labels through `withTabsI18nLabels(...)`.');
|
|
2417
|
+
}
|
|
2418
|
+
else {
|
|
2419
|
+
cngxDevWarn('CNGX1041', 'provideCngxTabs(): dropped feature without a `_target` ' +
|
|
2420
|
+
'discriminator. Pass config through the `with*` helpers of @cngx/common/tabs ' +
|
|
2421
|
+
'and labels through `withTabsI18nLabels(...)`.');
|
|
2422
|
+
}
|
|
2127
2423
|
}
|
|
2128
2424
|
}
|
|
2129
2425
|
return { config, i18n };
|
|
@@ -2158,7 +2454,7 @@ function partitionFeatures(features) {
|
|
|
2158
2454
|
* @relatedTo CngxTabGroup, CngxTabsConfig, provideCngxTabsAt
|
|
2159
2455
|
*/
|
|
2160
2456
|
function provideCngxTabs(...features) {
|
|
2161
|
-
const { config, i18n } = partitionFeatures(features);
|
|
2457
|
+
const { config, i18n } = partitionFeatures(features, 'provideCngxTabs');
|
|
2162
2458
|
return makeEnvironmentProviders([
|
|
2163
2459
|
provideTabsConfig(...config),
|
|
2164
2460
|
...(i18n.length > 0 ? [provideTabsI18n(...i18n)] : []),
|
|
@@ -2186,9 +2482,11 @@ function provideCngxTabs(...features) {
|
|
|
2186
2482
|
* @relatedTo CngxTabGroup, CngxTabsConfig, provideCngxTabs
|
|
2187
2483
|
*/
|
|
2188
2484
|
function provideCngxTabsAt(...features) {
|
|
2189
|
-
const { config, i18n } = partitionFeatures(features);
|
|
2485
|
+
const { config, i18n } = partitionFeatures(features, 'provideCngxTabsAt');
|
|
2190
2486
|
return [
|
|
2191
|
-
|
|
2487
|
+
// Gate like i18n: an i18n-only call must not plant an empty config
|
|
2488
|
+
// at this injector level and shadow an app-wide provideTabsConfig.
|
|
2489
|
+
...(config.length > 0 ? provideTabsConfigAt(...config) : []),
|
|
2192
2490
|
...(i18n.length > 0 ? [provideTabsI18n(...i18n)] : []),
|
|
2193
2491
|
];
|
|
2194
2492
|
}
|
|
@@ -2439,7 +2737,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
2439
2737
|
* Structural slot for the rejection-decoration template. 3-stage
|
|
2440
2738
|
* cascade: per-instance directive >
|
|
2441
2739
|
* `CNGX_TABS_CONFIG.templates.rejectionIcon` >
|
|
2442
|
-
* `CNGX_TABS_GLYPHS.rejectionIcon
|
|
2740
|
+
* `CNGX_TABS_GLYPHS.rejectionIcon` (a failed commit) or
|
|
2741
|
+
* `CNGX_TABS_GLYPHS.refusedIcon` (a refused one).
|
|
2443
2742
|
*
|
|
2444
2743
|
* ```html
|
|
2445
2744
|
* <cngx-tab-group>
|
|
@@ -2660,33 +2959,107 @@ function createTabDismissals(opts) {
|
|
|
2660
2959
|
const resolvedAddable = computed(() => opts.addable() ?? opts.config.addable ?? false, ...(ngDevMode ? [{ debugName: "resolvedAddable" }] : /* istanbul ignore next */ []));
|
|
2661
2960
|
const closeIconContextCache = new WeakMap();
|
|
2662
2961
|
const isTabClosable = (tab) => tab.closable() ?? resolvedClosable();
|
|
2962
|
+
// 1-based position per tab id, derived once per tab list, so a close-button
|
|
2963
|
+
// label never scans the strip.
|
|
2964
|
+
const tabIds = computed(() => opts.host.tabs().map((tab) => tab.id), { ...(ngDevMode ? { debugName: "tabIds" } : /* istanbul ignore next */ {}), equal: arrayEqual });
|
|
2965
|
+
const positionById = computed(() => new Map(tabIds().map((id, index) => [id, index + 1])), ...(ngDevMode ? [{ debugName: "positionById" }] : /* istanbul ignore next */ []));
|
|
2966
|
+
// The close request only ASKS the consumer to remove the tab - the
|
|
2967
|
+
// removal may land asynchronously (or never). Focus restore and the
|
|
2968
|
+
// closed announcement key on a requested id actually leaving the
|
|
2969
|
+
// registry, not on the next render after the request. Requests enter
|
|
2970
|
+
// via handleClose (the only writer); landed ids are pruned on the
|
|
2971
|
+
// next request, so the map stays interaction-bounded.
|
|
2972
|
+
const pendingCloseLabels = signal(new Map(), ...(ngDevMode ? [{ debugName: "pendingCloseLabels" }] : /* istanbul ignore next */ []));
|
|
2973
|
+
// Landed-close phrase, purely derived from the registry transition:
|
|
2974
|
+
// an id that was present in the previous registry emission, carries a
|
|
2975
|
+
// pending close request, and is gone from the current one has landed.
|
|
2976
|
+
// `prev.source` supplies the departed handle (and its label) without
|
|
2977
|
+
// a managed side-slot.
|
|
2978
|
+
const closedAnnouncement = linkedSignal({ ...(ngDevMode ? { debugName: "closedAnnouncement" } : /* istanbul ignore next */ {}), source: () => opts.host.tabs(),
|
|
2979
|
+
computation: (tabs, prev) => {
|
|
2980
|
+
if (prev === undefined) {
|
|
2981
|
+
return '';
|
|
2982
|
+
}
|
|
2983
|
+
const pending = pendingCloseLabels();
|
|
2984
|
+
const currentIds = new Set(tabs.map((tab) => tab.id));
|
|
2985
|
+
const landed = prev.source.find((tab) => !currentIds.has(tab.id) && pending.has(tab.id));
|
|
2986
|
+
if (landed === undefined) {
|
|
2987
|
+
return prev.value;
|
|
2988
|
+
}
|
|
2989
|
+
// Feeds the live region: copy is read untracked so a language
|
|
2990
|
+
// switch does not re-announce the last close.
|
|
2991
|
+
const label = pending.get(landed.id) ?? '';
|
|
2992
|
+
return untracked(() => opts.i18n().closedTab(label));
|
|
2993
|
+
} });
|
|
2994
|
+
const restoreFocus = () => {
|
|
2995
|
+
// Skin-agnostic lookup: `[role="tab"]` + `data-tab-id` are the
|
|
2996
|
+
// ARIA/data contract every skin must honour (mirrors the keyboard
|
|
2997
|
+
// nav's focus targeting); class names are skin-owned and a rename
|
|
2998
|
+
// must not silently break focus restoration.
|
|
2999
|
+
const activeId = opts.host.activeId();
|
|
3000
|
+
const active = activeId === null
|
|
3001
|
+
? null
|
|
3002
|
+
: (Array.from(opts.hostElement.querySelectorAll('[role="tab"]')).find((button) => button.getAttribute('data-tab-id') === activeId) ?? null);
|
|
3003
|
+
const add = opts.hostElement.querySelector('[data-tab-add]');
|
|
3004
|
+
const target = active ?? add;
|
|
3005
|
+
if (target) {
|
|
3006
|
+
target.focus();
|
|
3007
|
+
return;
|
|
3008
|
+
}
|
|
3009
|
+
opts.hostElement.tabIndex = -1;
|
|
3010
|
+
opts.hostElement.focus();
|
|
3011
|
+
};
|
|
3012
|
+
// Pure side effect - no signal writes. The once-per-landing guard is
|
|
3013
|
+
// plain imperative bookkeeping, not reactive state.
|
|
3014
|
+
const focusRestoredIds = new Set();
|
|
3015
|
+
effect(() => {
|
|
3016
|
+
const tabs = opts.host.tabs();
|
|
3017
|
+
const pending = pendingCloseLabels();
|
|
3018
|
+
untracked(() => {
|
|
3019
|
+
const landed = [...pending.keys()].filter((id) => !tabs.some((tab) => tab.id === id) && !focusRestoredIds.has(id));
|
|
3020
|
+
if (landed.length === 0) {
|
|
3021
|
+
return;
|
|
3022
|
+
}
|
|
3023
|
+
for (const id of landed) {
|
|
3024
|
+
focusRestoredIds.add(id);
|
|
3025
|
+
}
|
|
3026
|
+
// Restore focus once the removal has rendered: the new active
|
|
3027
|
+
// tab, then the add button, and finally the group element itself
|
|
3028
|
+
// (made programmatically focusable) so focus never falls to
|
|
3029
|
+
// `<body>` when the strip empties with no add button (APG).
|
|
3030
|
+
afterNextRender(restoreFocus, { injector: opts.injector });
|
|
3031
|
+
});
|
|
3032
|
+
}, { injector: opts.injector });
|
|
2663
3033
|
const handleClose = (tab, event) => {
|
|
2664
3034
|
event?.stopPropagation();
|
|
2665
3035
|
if (!isTabClosable(tab)) {
|
|
2666
3036
|
return;
|
|
2667
3037
|
}
|
|
3038
|
+
pendingCloseLabels.update((current) => {
|
|
3039
|
+
const next = new Map(
|
|
3040
|
+
// Prune requests that already landed - keeps the map bounded and
|
|
3041
|
+
// stops a later consumer-driven removal of a RE-ADDED same id
|
|
3042
|
+
// from reading as a close.
|
|
3043
|
+
[...current].filter(([id]) => opts.host.tabs().some((tab2) => tab2.id === id)));
|
|
3044
|
+
next.set(tab.id, tab.label() ?? '');
|
|
3045
|
+
focusRestoredIds.delete(tab.id);
|
|
3046
|
+
return next;
|
|
3047
|
+
});
|
|
2668
3048
|
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
3049
|
};
|
|
2685
3050
|
return {
|
|
2686
3051
|
resolvedClosable,
|
|
2687
3052
|
resolvedAddable,
|
|
2688
3053
|
isTabClosable,
|
|
2689
|
-
|
|
3054
|
+
// An unlabelled tab is named by position, never as `Close ""`.
|
|
3055
|
+
closeButtonLabel: (tab) => {
|
|
3056
|
+
const i18n = opts.i18n();
|
|
3057
|
+
const label = tab.label() ?? '';
|
|
3058
|
+
if (label !== '') {
|
|
3059
|
+
return i18n.closeTab(label);
|
|
3060
|
+
}
|
|
3061
|
+
return i18n.closeTab(i18n.unlabeledTab(positionById().get(tab.id) ?? 0));
|
|
3062
|
+
},
|
|
2690
3063
|
closeIconContextFor: (tab) => {
|
|
2691
3064
|
let ctx = closeIconContextCache.get(tab);
|
|
2692
3065
|
if (!ctx) {
|
|
@@ -2695,6 +3068,7 @@ function createTabDismissals(opts) {
|
|
|
2695
3068
|
}
|
|
2696
3069
|
return ctx;
|
|
2697
3070
|
},
|
|
3071
|
+
closedAnnouncement: closedAnnouncement.asReadonly(),
|
|
2698
3072
|
handleClose,
|
|
2699
3073
|
handleTabKeydown: (tab, event) => {
|
|
2700
3074
|
if (event.key === 'Delete' && isTabClosable(tab)) {
|
|
@@ -2797,6 +3171,37 @@ function createTabKeyboardNav(opts) {
|
|
|
2797
3171
|
const buttons = Array.from(opts.hostElement.querySelectorAll('[role="tab"]'));
|
|
2798
3172
|
buttons.find((button) => button.getAttribute('data-tab-id') === id)?.focus();
|
|
2799
3173
|
};
|
|
3174
|
+
if (opts.injector) {
|
|
3175
|
+
// Keyed on the outcome sequence, not the commit status: a refusal
|
|
3176
|
+
// settles to 'idle' and never reaches 'error'. A number compares with
|
|
3177
|
+
// `Object.is`, so the close shift (index moved, sequence copied) never
|
|
3178
|
+
// re-runs the release, and a cleared outcome (`undefined`) is ignored.
|
|
3179
|
+
const outcomeSequence = computed(() => opts.host.lastOutcome()?.sequence, ...(ngDevMode ? [{ debugName: "outcomeSequence" }] : /* istanbul ignore next */ []));
|
|
3180
|
+
effect(() => {
|
|
3181
|
+
if (outcomeSequence() === undefined) {
|
|
3182
|
+
return;
|
|
3183
|
+
}
|
|
3184
|
+
untracked(() => {
|
|
3185
|
+
// Only release focus that this tablist is actually holding on a
|
|
3186
|
+
// non-active tab button - never steal focus from elsewhere.
|
|
3187
|
+
const focused = document.activeElement;
|
|
3188
|
+
if (!(focused instanceof HTMLElement) || !opts.hostElement.contains(focused)) {
|
|
3189
|
+
return;
|
|
3190
|
+
}
|
|
3191
|
+
if (focused.getAttribute('role') !== 'tab') {
|
|
3192
|
+
return;
|
|
3193
|
+
}
|
|
3194
|
+
const activeId = opts.host.activeId();
|
|
3195
|
+
if (activeId === null || focused.getAttribute('data-tab-id') === activeId) {
|
|
3196
|
+
return;
|
|
3197
|
+
}
|
|
3198
|
+
const idx = opts.host.tabs().findIndex((tab) => tab.id === activeId);
|
|
3199
|
+
if (idx >= 0) {
|
|
3200
|
+
focusTabAt(idx);
|
|
3201
|
+
}
|
|
3202
|
+
});
|
|
3203
|
+
}, { injector: opts.injector });
|
|
3204
|
+
}
|
|
2800
3205
|
return {
|
|
2801
3206
|
tabTabindex: (tab) => (tab.id === opts.host.activeId() ? 0 : -1),
|
|
2802
3207
|
handleKeydown: (event) => {
|
|
@@ -2925,13 +3330,18 @@ function createTabGroupTemplateBindings(opts) {
|
|
|
2925
3330
|
*/
|
|
2926
3331
|
function createTabGroupAnnouncements(options) {
|
|
2927
3332
|
const { presenter, i18n, config, ariaLabel, ariaLabelledBy } = options;
|
|
2928
|
-
const
|
|
2929
|
-
const
|
|
3333
|
+
const closedAnnouncement = options.closedAnnouncement ?? (() => '');
|
|
3334
|
+
const fallbackLabels = coerceSignal(config.fallbackLabels);
|
|
3335
|
+
const defaultFallbackLabels = coerceSignal(TABS_CONFIG_DEFAULTS.fallbackLabels);
|
|
3336
|
+
const ariaLabels = coerceSignal(config.ariaLabels);
|
|
3337
|
+
const tabsRoleDescription = computed(() => fallbackLabels()?.tabRoleDescription ?? defaultFallbackLabels().tabRoleDescription, ...(ngDevMode ? [{ debugName: "tabsRoleDescription" }] : /* istanbul ignore next */ []));
|
|
3338
|
+
const tabPanelRoleDescription = computed(() => fallbackLabels()?.tabPanelRoleDescription ??
|
|
3339
|
+
defaultFallbackLabels().tabPanelRoleDescription, ...(ngDevMode ? [{ debugName: "tabPanelRoleDescription" }] : /* istanbul ignore next */ []));
|
|
2930
3340
|
const resolvedAriaLabel = computed(() => {
|
|
2931
3341
|
if (ariaLabelledBy()) {
|
|
2932
3342
|
return null;
|
|
2933
3343
|
}
|
|
2934
|
-
return ariaLabel() ??
|
|
3344
|
+
return ariaLabel() ?? ariaLabels()?.tabsRegion ?? i18n().tabsLabel;
|
|
2935
3345
|
}, ...(ngDevMode ? [{ debugName: "resolvedAriaLabel" }] : /* istanbul ignore next */ []));
|
|
2936
3346
|
// `prev?.source` = source value before the most recent change -
|
|
2937
3347
|
// prior activeIndex without an `effect`-driven slot (Pillar 1).
|
|
@@ -2939,25 +3349,88 @@ function createTabGroupAnnouncements(options) {
|
|
|
2939
3349
|
const priorActiveIndex = linkedSignal({ ...(ngDevMode ? { debugName: "priorActiveIndex" } : /* istanbul ignore next */ {}), source: () => presenter.activeIndex(),
|
|
2940
3350
|
computation: (curr, prev) => prev?.source ?? curr,
|
|
2941
3351
|
equal: Object.is });
|
|
3352
|
+
// Close phrase with commit-activity expiry: a NEW phrase (re)arms; a
|
|
3353
|
+
// commit status change while armed spends the phrase, so a later
|
|
3354
|
+
// return to idle re-renders '' instead of re-announcing the stale
|
|
3355
|
+
// close. A new refused or failed outcome spends it too: a synchronous
|
|
3356
|
+
// refusal never changes the status, and the close phrase must not
|
|
3357
|
+
// resurface once the refused phrase is spent. Mount seeds with the
|
|
3358
|
+
// current phrase (never empty-coerced).
|
|
3359
|
+
const closedPhrase = createAnnouncementPhrase({
|
|
3360
|
+
source: () => ({
|
|
3361
|
+
phrase: closedAnnouncement(),
|
|
3362
|
+
status: presenter.commitTransition.current(),
|
|
3363
|
+
sequence: presenter.lastOutcome()?.sequence,
|
|
3364
|
+
}),
|
|
3365
|
+
arm: (curr, prev) => (curr.phrase !== prev.phrase ? curr.phrase : null),
|
|
3366
|
+
spend: (curr, prev) => curr.status !== prev.status || curr.sequence !== prev.sequence,
|
|
3367
|
+
seed: (src) => src.phrase,
|
|
3368
|
+
});
|
|
3369
|
+
// A refusal leaves the commit status at 'idle', so no status edge can
|
|
3370
|
+
// voice it. The phrase arms on each new refused outcome (a new
|
|
3371
|
+
// sequence) and is spent by the next commit activity, an active-index
|
|
3372
|
+
// move, a cleared outcome (its own tab closed) or a new close phrase,
|
|
3373
|
+
// so closing another tab after a refusal is announced. Arm wins over
|
|
3374
|
+
// spend in the same flush, so an optimistic rollback still arms.
|
|
3375
|
+
const refusedPhrase = createRefusedPhrase({
|
|
3376
|
+
outcome: () => presenter.lastOutcome(),
|
|
3377
|
+
status: () => presenter.commitTransition.current(),
|
|
3378
|
+
activeIndex: () => presenter.activeIndex(),
|
|
3379
|
+
copy: refusedCopy,
|
|
3380
|
+
extraSpend: () => closedAnnouncement(),
|
|
3381
|
+
});
|
|
3382
|
+
function refusedCopy() {
|
|
3383
|
+
const originIdx = presenter.originIndexDuringCommit();
|
|
3384
|
+
const origin = originIdx !== undefined ? presenter.tabs()[originIdx] : undefined;
|
|
3385
|
+
const copy = i18n();
|
|
3386
|
+
// An origin index past the end names a removed tab: the generic copy.
|
|
3387
|
+
if (!origin || originIdx === undefined) {
|
|
3388
|
+
return copy.commitRefusedGeneric;
|
|
3389
|
+
}
|
|
3390
|
+
return copy.commitRefused(originName(origin, originIdx, copy));
|
|
3391
|
+
}
|
|
3392
|
+
// A label-less origin is named by its position.
|
|
3393
|
+
function originName(origin, originIdx, copy) {
|
|
3394
|
+
const label = origin.label();
|
|
3395
|
+
if (label) {
|
|
3396
|
+
return label;
|
|
3397
|
+
}
|
|
3398
|
+
return copy.unlabeledTab(originIdx + 1);
|
|
3399
|
+
}
|
|
3400
|
+
// Copy and tab labels (which a consumer may translate) are read untracked
|
|
3401
|
+
// in the live region: a language switch must not re-speak the last phrase;
|
|
3402
|
+
// the next transition speaks the new language.
|
|
2942
3403
|
const liveAnnouncement = computed(() => {
|
|
3404
|
+
// Read both phrases EAGERLY: linkedSignal only observes snapshots it
|
|
3405
|
+
// is actually read under, so a lazy read behind an earlier arm would
|
|
3406
|
+
// skip the intermediate 'pending' and never spend the phrase.
|
|
3407
|
+
const refused = refusedPhrase();
|
|
3408
|
+
const closeConfirmation = closedPhrase();
|
|
3409
|
+
if (refused) {
|
|
3410
|
+
return refused;
|
|
3411
|
+
}
|
|
2943
3412
|
const current = presenter.commitTransition.current();
|
|
2944
3413
|
if (current === 'pending') {
|
|
2945
|
-
return i18n.commitInFlight;
|
|
3414
|
+
return untracked(() => i18n().commitInFlight);
|
|
2946
3415
|
}
|
|
2947
3416
|
if (current === 'error') {
|
|
2948
|
-
// No `previous === 'pending'` guard - sync
|
|
3417
|
+
// No `previous === 'pending'` guard - sync failures collapse
|
|
2949
3418
|
// pending → error in one flush, so the tracker captures
|
|
2950
3419
|
// `previous = 'idle'` and an unguarded read keeps the
|
|
2951
|
-
// announcement reachable for
|
|
3420
|
+
// announcement reachable for a synchronously throwing
|
|
3421
|
+
// `commitAction`. A `false` answer never reaches this arm: it
|
|
3422
|
+
// settles to 'idle' as a refusal.
|
|
2952
3423
|
const failedIdx = presenter.lastFailedIndex();
|
|
2953
3424
|
const originIdx = presenter.originIndexDuringCommit();
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
}
|
|
3425
|
+
const origin = failedIdx !== undefined && originIdx !== undefined ? presenter.tabs()[originIdx] : undefined;
|
|
3426
|
+
// No origin, or an origin index past the end (a removed tab): retry copy.
|
|
3427
|
+
if (!origin || originIdx === undefined) {
|
|
3428
|
+
return untracked(() => i18n().commitFailedRetry);
|
|
2959
3429
|
}
|
|
2960
|
-
return
|
|
3430
|
+
return untracked(() => {
|
|
3431
|
+
const copy = i18n();
|
|
3432
|
+
return copy.commitRolledBackTo(originName(origin, originIdx, copy));
|
|
3433
|
+
});
|
|
2961
3434
|
}
|
|
2962
3435
|
if (current === 'success') {
|
|
2963
3436
|
const tabs = presenter.tabs();
|
|
@@ -2966,18 +3439,26 @@ function createTabGroupAnnouncements(options) {
|
|
|
2966
3439
|
if (!tab) {
|
|
2967
3440
|
return '';
|
|
2968
3441
|
}
|
|
2969
|
-
const label = tab.label
|
|
2970
|
-
const
|
|
3442
|
+
const label = untracked(tab.label) ?? '';
|
|
3443
|
+
const count = tabs.length;
|
|
2971
3444
|
const prevIdx = priorActiveIndex();
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
3445
|
+
return untracked(() => {
|
|
3446
|
+
const copy = i18n();
|
|
3447
|
+
const positionPhrase = label
|
|
3448
|
+
? copy.selectedTab(label, idx + 1, count)
|
|
3449
|
+
: copy.unlabeledTabOfCount(idx + 1, count);
|
|
3450
|
+
if (idx > prevIdx) {
|
|
3451
|
+
return copy.nextTab(positionPhrase);
|
|
3452
|
+
}
|
|
3453
|
+
if (idx < prevIdx) {
|
|
3454
|
+
return copy.previousTab(positionPhrase);
|
|
3455
|
+
}
|
|
3456
|
+
return positionPhrase;
|
|
3457
|
+
});
|
|
2979
3458
|
}
|
|
2980
|
-
|
|
3459
|
+
// Idle: the landed-close confirmation is the only phrase that may
|
|
3460
|
+
// hold the region, and only until the next commit activity.
|
|
3461
|
+
return closeConfirmation;
|
|
2981
3462
|
}, ...(ngDevMode ? [{ debugName: "liveAnnouncement" }] : /* istanbul ignore next */ []));
|
|
2982
3463
|
function statusPhrase(tab) {
|
|
2983
3464
|
if (!tab.hasError()) {
|
|
@@ -2992,14 +3473,34 @@ function createTabGroupAnnouncements(options) {
|
|
|
2992
3473
|
if (directMessage) {
|
|
2993
3474
|
return directMessage;
|
|
2994
3475
|
}
|
|
2995
|
-
return i18n.tabHasErrors(aggregator?.errorCount() ?? 1);
|
|
3476
|
+
return i18n().tabHasErrors(aggregator?.errorCount() ?? 1);
|
|
2996
3477
|
}
|
|
2997
3478
|
function tabAriaLabel(tab, position) {
|
|
2998
3479
|
const tabs = presenter.tabs();
|
|
2999
|
-
const label = tab.label()
|
|
3480
|
+
const label = tab.label();
|
|
3000
3481
|
const detail = tab.subLabel();
|
|
3001
|
-
const
|
|
3002
|
-
|
|
3482
|
+
const copy = i18n();
|
|
3483
|
+
if (!label) {
|
|
3484
|
+
const positionName = copy.unlabeledTabOfCount(position, tabs.length);
|
|
3485
|
+
return detail ? copy.tabLabelWithDetail(positionName, detail) : positionName;
|
|
3486
|
+
}
|
|
3487
|
+
const labelPart = detail ? copy.tabLabelWithDetail(label, detail) : label;
|
|
3488
|
+
return copy.selectedTab(labelPart, position, tabs.length);
|
|
3489
|
+
}
|
|
3490
|
+
function tabLabelId(tab) {
|
|
3491
|
+
return `${tab.id}-label`;
|
|
3492
|
+
}
|
|
3493
|
+
function tabSubLabelId(tab) {
|
|
3494
|
+
return `${tab.id}-sublabel`;
|
|
3495
|
+
}
|
|
3496
|
+
function tabLabelledBy(tab, hasLabelTemplate, hasSubLabelTemplate) {
|
|
3497
|
+
if (tab.label() || !hasLabelTemplate) {
|
|
3498
|
+
return null;
|
|
3499
|
+
}
|
|
3500
|
+
if (hasSubLabelTemplate || tab.subLabel()) {
|
|
3501
|
+
return `${tabLabelId(tab)} ${tabSubLabelId(tab)}`;
|
|
3502
|
+
}
|
|
3503
|
+
return tabLabelId(tab);
|
|
3003
3504
|
}
|
|
3004
3505
|
// Eager seed - `linkedSignal` is lazy and the success arm doesn't
|
|
3005
3506
|
// touch the tracker at construction (commitTransition is `idle`),
|
|
@@ -3013,6 +3514,9 @@ function createTabGroupAnnouncements(options) {
|
|
|
3013
3514
|
liveAnnouncement,
|
|
3014
3515
|
statusPhrase,
|
|
3015
3516
|
tabAriaLabel,
|
|
3517
|
+
tabLabelledBy,
|
|
3518
|
+
tabLabelId,
|
|
3519
|
+
tabSubLabelId,
|
|
3016
3520
|
};
|
|
3017
3521
|
}
|
|
3018
3522
|
|
|
@@ -3065,7 +3569,13 @@ function createTabNavAnnouncement(options) {
|
|
|
3065
3569
|
if (id === null || id === priorActiveId()) {
|
|
3066
3570
|
return '';
|
|
3067
3571
|
}
|
|
3068
|
-
|
|
3572
|
+
// The label may be translated by the consumer; read untracked so a
|
|
3573
|
+
// language switch does not re-announce the landing section.
|
|
3574
|
+
const landed = presenter.tabs().find((tab) => tab.id === id);
|
|
3575
|
+
if (!landed) {
|
|
3576
|
+
return '';
|
|
3577
|
+
}
|
|
3578
|
+
return untracked(landed.label) ?? '';
|
|
3069
3579
|
}, ...(ngDevMode ? [{ debugName: "liveAnnouncement" }] : /* istanbul ignore next */ []));
|
|
3070
3580
|
afterNextRender(() => {
|
|
3071
3581
|
queueMicrotask(() => {
|
|
@@ -3091,8 +3601,14 @@ function createTabNavAnnouncement(options) {
|
|
|
3091
3601
|
const CNGX_TABS_GLYPHS = {
|
|
3092
3602
|
/** Default visual for `*cngxTabErrorBadge` when no override is bound. */
|
|
3093
3603
|
errorBadge: '!',
|
|
3094
|
-
/** Default visual for `*cngxTabRejectionIcon` when no override is bound. */
|
|
3604
|
+
/** Default visual for `*cngxTabRejectionIcon` on a failed commit when no override is bound. */
|
|
3095
3605
|
rejectionIcon: '!',
|
|
3606
|
+
/**
|
|
3607
|
+
* Default visual for `*cngxTabRejectionIcon` on a refused commit (the
|
|
3608
|
+
* action answered `false`). A distinct glyph, so a refusal never differs
|
|
3609
|
+
* from a failure by colour alone (WCAG 1.4.1).
|
|
3610
|
+
*/
|
|
3611
|
+
refusedIcon: '\u2298',
|
|
3096
3612
|
/** Default visual for a tab's close button when no override is bound. */
|
|
3097
3613
|
closeIcon: '×',
|
|
3098
3614
|
/** Default visual for the add-tab button when no override is bound. */
|
|
@@ -3122,10 +3638,12 @@ function triggerContextEqual(a, b) {
|
|
|
3122
3638
|
return a.count === b.count && a.hiddenTabs === b.hiddenTabs;
|
|
3123
3639
|
}
|
|
3124
3640
|
/**
|
|
3125
|
-
* Structural equal - same length + per-index `id` and
|
|
3126
|
-
* Without this, every IO emission yields fresh
|
|
3641
|
+
* Structural equal - same length + per-index `id`, `label`, and
|
|
3642
|
+
* `disabled`. Without this, every IO emission yields fresh
|
|
3127
3643
|
* `ActiveDescendantItem[]` references and AD's `resolvedItems`
|
|
3128
|
-
* cascade fires for an unchanged visible-tab set.
|
|
3644
|
+
* cascade fires for an unchanged visible-tab set. `label` is compared
|
|
3645
|
+
* because typeahead matches on it - omitting it would leave the
|
|
3646
|
+
* overflow list matching against stale labels after a rename.
|
|
3129
3647
|
*
|
|
3130
3648
|
* @internal
|
|
3131
3649
|
*/
|
|
@@ -3137,7 +3655,7 @@ function adItemsEqual(a, b) {
|
|
|
3137
3655
|
return false;
|
|
3138
3656
|
}
|
|
3139
3657
|
for (let i = 0; i < a.length; i++) {
|
|
3140
|
-
if (a[i].id !== b[i].id || a[i].disabled !== b[i].disabled) {
|
|
3658
|
+
if (a[i].id !== b[i].id || a[i].label !== b[i].label || a[i].disabled !== b[i].disabled) {
|
|
3141
3659
|
return false;
|
|
3142
3660
|
}
|
|
3143
3661
|
}
|
|
@@ -3180,10 +3698,20 @@ function createTabOverflowTemplateBindings(opts) {
|
|
|
3180
3698
|
itemContextCache.set(tab, { context, disabled, index });
|
|
3181
3699
|
return context;
|
|
3182
3700
|
};
|
|
3701
|
+
// 1-based strip position per tab id, derived once per tab list.
|
|
3702
|
+
const tabIds = computed(() => opts.tabs().map((tab) => tab.id), { ...(ngDevMode ? { debugName: "tabIds" } : /* istanbul ignore next */ {}), equal: arrayEqual });
|
|
3703
|
+
const positionById = computed(() => new Map(tabIds().map((id, index) => [id, index + 1])), ...(ngDevMode ? [{ debugName: "positionById" }] : /* istanbul ignore next */ []));
|
|
3704
|
+
const itemLabel = (tab) => {
|
|
3705
|
+
const label = tab.label() ?? '';
|
|
3706
|
+
if (label !== '') {
|
|
3707
|
+
return label;
|
|
3708
|
+
}
|
|
3709
|
+
return opts.i18n().unlabeledTab(positionById().get(tab.id) ?? 0);
|
|
3710
|
+
};
|
|
3183
3711
|
const adItems = computed(() => opts.hiddenTabs().map((tab) => ({
|
|
3184
3712
|
id: tabOverflowOptionId(tab),
|
|
3185
3713
|
value: tab,
|
|
3186
|
-
label: tab
|
|
3714
|
+
label: itemLabel(tab),
|
|
3187
3715
|
disabled: tab.disabled(),
|
|
3188
3716
|
})), { ...(ngDevMode ? { debugName: "adItems" } : /* istanbul ignore next */ {}), equal: adItemsEqual });
|
|
3189
3717
|
return {
|
|
@@ -3191,6 +3719,7 @@ function createTabOverflowTemplateBindings(opts) {
|
|
|
3191
3719
|
itemTemplate,
|
|
3192
3720
|
triggerContext,
|
|
3193
3721
|
buildItemContext,
|
|
3722
|
+
itemLabel,
|
|
3194
3723
|
adItems,
|
|
3195
3724
|
};
|
|
3196
3725
|
}
|
|
@@ -3405,5 +3934,5 @@ const CNGX_DIRECTIVE_BY_ID_MAP_FACTORY = new InjectionToken('CngxDirectiveByIdMa
|
|
|
3405
3934
|
* Generated bundle index. Do not edit.
|
|
3406
3935
|
*/
|
|
3407
3936
|
|
|
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 };
|
|
3937
|
+
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
3938
|
//# sourceMappingURL=cngx-common-tabs.mjs.map
|