@cngx/common 0.1.0-rc.8 → 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/command/README.md +29 -0
- package/data/README.md +5 -2
- package/fesm2022/cngx-common-a11y.mjs +403 -84
- package/fesm2022/cngx-common-a11y.mjs.map +1 -1
- package/fesm2022/cngx-common-audio.mjs +16 -13
- package/fesm2022/cngx-common-audio.mjs.map +1 -1
- package/fesm2022/cngx-common-card.mjs +4 -3
- package/fesm2022/cngx-common-card.mjs.map +1 -1
- package/fesm2022/cngx-common-chart.mjs +55 -36
- package/fesm2022/cngx-common-chart.mjs.map +1 -1
- package/fesm2022/cngx-common-command.mjs +60 -6
- package/fesm2022/cngx-common-command.mjs.map +1 -1
- package/fesm2022/cngx-common-data.mjs +185 -37
- package/fesm2022/cngx-common-data.mjs.map +1 -1
- package/fesm2022/cngx-common-dialog.mjs +86 -48
- package/fesm2022/cngx-common-dialog.mjs.map +1 -1
- package/fesm2022/cngx-common-display.mjs +27 -23
- package/fesm2022/cngx-common-display.mjs.map +1 -1
- package/fesm2022/cngx-common-interactive.mjs +324 -122
- package/fesm2022/cngx-common-interactive.mjs.map +1 -1
- package/fesm2022/cngx-common-layout.mjs +129 -26
- package/fesm2022/cngx-common-layout.mjs.map +1 -1
- package/fesm2022/cngx-common-popover.mjs +947 -33
- package/fesm2022/cngx-common-popover.mjs.map +1 -1
- package/fesm2022/cngx-common-stepper.mjs +300 -166
- package/fesm2022/cngx-common-stepper.mjs.map +1 -1
- package/fesm2022/cngx-common-tabs.mjs +251 -80
- package/fesm2022/cngx-common-tabs.mjs.map +1 -1
- package/fesm2022/cngx-common-timeline.mjs +16 -10
- package/fesm2022/cngx-common-timeline.mjs.map +1 -1
- package/fesm2022/cngx-common.mjs +1 -1
- package/layout/README.md +16 -0
- package/package.json +20 -7
- package/popover/README.md +40 -0
- 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 +5 -4
- package/theming/components/cngx-popover-sheet.css +402 -0
- package/theming/components/cngx-popover.css +10 -6
- package/types/cngx-common-a11y.d.ts +167 -14
- package/types/cngx-common-chart.d.ts +8 -7
- package/types/cngx-common-command.d.ts +19 -2
- package/types/cngx-common-data.d.ts +164 -26
- package/types/cngx-common-dialog.d.ts +3 -7
- package/types/cngx-common-interactive.d.ts +52 -17
- package/types/cngx-common-layout.d.ts +37 -5
- package/types/cngx-common-popover.d.ts +353 -13
- package/types/cngx-common-stepper.d.ts +168 -129
- package/types/cngx-common-tabs.d.ts +149 -30
- package/types/cngx-common-timeline.d.ts +27 -7
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { InjectionToken, inject, computed, makeEnvironmentProviders, model, input, Injector, output, signal, Directive, TemplateRef, contentChild, DestroyRef, Renderer2, ElementRef, effect, afterNextRender, untracked,
|
|
3
|
-
import { CNGX_COMMIT_CONTROLLER_FACTORY } from '@cngx/common/data';
|
|
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
4
|
import { createOverrideMerge, createTransitionTracker, CNGX_STATEFUL, nextUid, coerceSignal, createAnnouncementPhrase } from '@cngx/core/utils';
|
|
5
|
-
import { recordEqual, arrayEqual } from '@cngx/utils';
|
|
5
|
+
import { recordEqual, CngxRuntimeError, cngxDevWarn, arrayEqual } from '@cngx/utils';
|
|
6
6
|
import { createLanguageSection, formatMessage, createSectionBundle } from '@cngx/core/i18n';
|
|
7
7
|
import { isObservable, Observable } from 'rxjs';
|
|
8
|
-
import { PRIMARY_OUTLET, Router,
|
|
8
|
+
import { PRIMARY_OUTLET, Router, ActivatedRoute, NavigationEnd } from '@angular/router';
|
|
9
9
|
import { toSignal, takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
10
10
|
import { filter } from 'rxjs/operators';
|
|
11
11
|
import { resolveInlineStep } from '@cngx/core';
|
|
@@ -41,6 +41,7 @@ const CNGX_TABS_LANGUAGE_EN = {
|
|
|
41
41
|
tabHasErrors: { one: '{count} error', other: '{count} errors' },
|
|
42
42
|
moreTabsLabel: '{count} more',
|
|
43
43
|
unlabeledTab: 'Tab {position}',
|
|
44
|
+
unlabeledTabOfCount: 'Tab {position} of {count}',
|
|
44
45
|
previousTab: 'Previous tab: {tab}',
|
|
45
46
|
nextTab: 'Next tab: {tab}',
|
|
46
47
|
closeTab: 'Close "{label}"',
|
|
@@ -50,6 +51,8 @@ const CNGX_TABS_LANGUAGE_EN = {
|
|
|
50
51
|
commitFailedRetry: 'Could not switch tab - retry?',
|
|
51
52
|
commitInFlight: 'Switching tab…',
|
|
52
53
|
commitRolledBackTo: 'Could not save changes - reverted to "{origin}".',
|
|
54
|
+
commitRefused: 'Tab switch not allowed - stayed on "{origin}".',
|
|
55
|
+
commitRefusedGeneric: 'Tab switch not allowed.',
|
|
53
56
|
};
|
|
54
57
|
|
|
55
58
|
/**
|
|
@@ -66,6 +69,7 @@ function tabsBundleFrom(section, locale) {
|
|
|
66
69
|
tabHasErrors: (count) => formatMessage(section.tabHasErrors, { count }, locale),
|
|
67
70
|
moreTabsLabel: (count) => formatMessage(section.moreTabsLabel, { count }, locale),
|
|
68
71
|
unlabeledTab: (position) => formatMessage(section.unlabeledTab, { position }, locale),
|
|
72
|
+
unlabeledTabOfCount: (position, count) => formatMessage(section.unlabeledTabOfCount, { position, count }, locale),
|
|
69
73
|
previousTab: (tab) => formatMessage(section.previousTab, { tab }, locale),
|
|
70
74
|
nextTab: (tab) => formatMessage(section.nextTab, { tab }, locale),
|
|
71
75
|
closeTab: (label) => formatMessage(section.closeTab, { label }, locale),
|
|
@@ -74,6 +78,8 @@ function tabsBundleFrom(section, locale) {
|
|
|
74
78
|
commitFailedRetry: section.commitFailedRetry,
|
|
75
79
|
commitInFlight: section.commitInFlight,
|
|
76
80
|
commitRolledBackTo: (origin) => formatMessage(section.commitRolledBackTo, { origin }, locale),
|
|
81
|
+
commitRefused: (origin) => formatMessage(section.commitRefused, { origin }, locale),
|
|
82
|
+
commitRefusedGeneric: section.commitRefusedGeneric,
|
|
77
83
|
};
|
|
78
84
|
}
|
|
79
85
|
/** @internal The tabs section of the active pack over English. */
|
|
@@ -613,8 +619,10 @@ function injectTabsConfig() {
|
|
|
613
619
|
|
|
614
620
|
/**
|
|
615
621
|
* Wraps a {@link CngxCommitController} with the action-shape adapter
|
|
616
|
-
* that
|
|
617
|
-
*
|
|
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.
|
|
618
626
|
*
|
|
619
627
|
* @category common/tabs
|
|
620
628
|
*/
|
|
@@ -624,8 +632,9 @@ function createTabsCommitHandler(opts) {
|
|
|
624
632
|
isCommitting: controller.isCommitting,
|
|
625
633
|
beginTransition(fromIndex, toIndex, action, onResolve) {
|
|
626
634
|
controller.begin((handlers) => runTabsAction(action, fromIndex, toIndex, handlers), toIndex, fromIndex, {
|
|
627
|
-
onSuccess: () => onResolve(
|
|
628
|
-
onError: () => onResolve(
|
|
635
|
+
onSuccess: () => onResolve('accepted'),
|
|
636
|
+
onError: () => onResolve('failed'),
|
|
637
|
+
onRefused: () => onResolve('refused'),
|
|
629
638
|
});
|
|
630
639
|
},
|
|
631
640
|
cancel() {
|
|
@@ -644,7 +653,7 @@ function runTabsAction(action, fromIndex, toIndex, handlers) {
|
|
|
644
653
|
handlers.onSuccess(toIndex);
|
|
645
654
|
}
|
|
646
655
|
else {
|
|
647
|
-
handlers.
|
|
656
|
+
handlers.onRefused();
|
|
648
657
|
}
|
|
649
658
|
};
|
|
650
659
|
const safeError = (err) => {
|
|
@@ -692,7 +701,9 @@ function runTabsAction(action, fromIndex, toIndex, handlers) {
|
|
|
692
701
|
// EMPTY-style sources complete without emitting; without this arm
|
|
693
702
|
// the commit stays 'pending' forever and busy() latches true.
|
|
694
703
|
if (!done) {
|
|
695
|
-
safeError(new
|
|
704
|
+
safeError(new CngxRuntimeError('CNGX1059', typeof ngDevMode !== 'undefined' &&
|
|
705
|
+
ngDevMode &&
|
|
706
|
+
'[cngxTabGroup] commitAction completed without emitting true or false.'));
|
|
696
707
|
}
|
|
697
708
|
},
|
|
698
709
|
});
|
|
@@ -745,6 +756,24 @@ const CNGX_TABS_COMMIT_HANDLER_FACTORY = new InjectionToken('CngxTabsCommitHandl
|
|
|
745
756
|
* @since 0.1.0
|
|
746
757
|
*/
|
|
747
758
|
const CNGX_TAB_GROUP_HOST = new InjectionToken('CngxTabGroupHost');
|
|
759
|
+
/**
|
|
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.
|
|
765
|
+
*
|
|
766
|
+
* @internal
|
|
767
|
+
*/
|
|
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;
|
|
776
|
+
}
|
|
748
777
|
|
|
749
778
|
/**
|
|
750
779
|
* Tab-group presenter - brain of every CNGX tab flow. \
|
|
@@ -871,12 +900,24 @@ class CngxTabGroupPresenter {
|
|
|
871
900
|
* the tracker's `linkedSignal` is allocated once per presenter.
|
|
872
901
|
*/
|
|
873
902
|
commitTransition = createTransitionTracker(() => this.commitController.state.status());
|
|
874
|
-
// Persistence-of-
|
|
875
|
-
// and `originIndexDuringCommit` for the contract.
|
|
876
|
-
|
|
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;
|
|
877
913
|
originIndexDuringCommitState = signal(undefined, ...(ngDevMode ? [{ debugName: "originIndexDuringCommitState" }] : /* istanbul ignore next */ []));
|
|
914
|
+
/** {@inheritDoc CngxTabGroupHost.lastOutcome} */
|
|
915
|
+
lastOutcome = this.lastOutcomeState.asReadonly();
|
|
878
916
|
/** {@inheritDoc CngxTabGroupHost.lastFailedIndex} */
|
|
879
|
-
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 */ []));
|
|
880
921
|
/** {@inheritDoc CngxTabGroupHost.originIndexDuringCommit} */
|
|
881
922
|
originIndexDuringCommit = this.originIndexDuringCommitState.asReadonly();
|
|
882
923
|
tabsState = signal([], { ...(ngDevMode ? { debugName: "tabsState" } : /* istanbul ignore next */ {}), equal: tabsEqual });
|
|
@@ -915,7 +956,7 @@ class CngxTabGroupPresenter {
|
|
|
915
956
|
}
|
|
916
957
|
/** {@inheritDoc CngxTabGroupHost.clearLastFailed} */
|
|
917
958
|
clearLastFailed() {
|
|
918
|
-
this.
|
|
959
|
+
this.clearedSequenceState.set(this.lastOutcomeState()?.sequence);
|
|
919
960
|
}
|
|
920
961
|
select(index) {
|
|
921
962
|
const tabs = this.tabs();
|
|
@@ -936,8 +977,8 @@ class CngxTabGroupPresenter {
|
|
|
936
977
|
// untouched, so a stale origin can never leak into the
|
|
937
978
|
// live-region announcement.
|
|
938
979
|
this.activeIndex.set(target);
|
|
939
|
-
if (this.
|
|
940
|
-
this.
|
|
980
|
+
if (this.lastFailedIndex() === target) {
|
|
981
|
+
this.clearLastFailed();
|
|
941
982
|
}
|
|
942
983
|
return;
|
|
943
984
|
}
|
|
@@ -948,28 +989,31 @@ class CngxTabGroupPresenter {
|
|
|
948
989
|
if (mode === 'optimistic') {
|
|
949
990
|
this.activeIndex.set(target);
|
|
950
991
|
}
|
|
951
|
-
this.commitHandler.beginTransition(previous, target, action, (
|
|
952
|
-
if (
|
|
992
|
+
this.commitHandler.beginTransition(previous, target, action, (outcome) => {
|
|
993
|
+
if (outcome === 'accepted') {
|
|
953
994
|
// Window closes on success - origin label no longer needed;
|
|
954
|
-
// clear the rejection
|
|
955
|
-
// target successfully.
|
|
995
|
+
// clear the rejection marker if the user re-picked the
|
|
996
|
+
// rejected target successfully.
|
|
956
997
|
this.originIndexDuringCommitState.set(undefined);
|
|
957
|
-
if (this.
|
|
958
|
-
this.
|
|
998
|
+
if (this.lastFailedIndex() === target) {
|
|
999
|
+
this.clearLastFailed();
|
|
959
1000
|
}
|
|
960
1001
|
if (mode === 'pessimistic') {
|
|
961
1002
|
this.activeIndex.set(target);
|
|
962
1003
|
}
|
|
1004
|
+
return;
|
|
963
1005
|
}
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
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);
|
|
973
1017
|
}
|
|
974
1018
|
});
|
|
975
1019
|
}
|
|
@@ -1052,9 +1096,10 @@ class CngxTabGroupPresenter {
|
|
|
1052
1096
|
// The rejection markers are flat indices into the same registry, so a
|
|
1053
1097
|
// close before them drifts the decoration onto the wrong tab (reachable
|
|
1054
1098
|
// only via the dismissable affordance the organism layers on top). Shift
|
|
1055
|
-
// them the same way `activeIndex` shifts, and drop the
|
|
1056
|
-
// when its own tab is the one closed.
|
|
1057
|
-
|
|
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));
|
|
1058
1103
|
this.originIndexDuringCommitState.update((origin) => shiftIndexOnClose(origin, index));
|
|
1059
1104
|
this.tabClose.emit({ id, index });
|
|
1060
1105
|
}
|
|
@@ -1094,6 +1139,23 @@ function shiftIndexOnClose(stored, removed) {
|
|
|
1094
1139
|
}
|
|
1095
1140
|
return removed < stored ? stored - 1 : stored;
|
|
1096
1141
|
}
|
|
1142
|
+
/**
|
|
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.
|
|
1146
|
+
*
|
|
1147
|
+
* @internal
|
|
1148
|
+
*/
|
|
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 };
|
|
1158
|
+
}
|
|
1097
1159
|
/**
|
|
1098
1160
|
* Registry equality for the tab registry signal: element-wise reference
|
|
1099
1161
|
* identity, not structural comparison. Two arrays are equal only when
|
|
@@ -1516,7 +1578,9 @@ class CngxTab {
|
|
|
1516
1578
|
selected = computed(() => this.host?.activeId() === this.id(), { ...(ngDevMode ? { debugName: "selected" } : /* istanbul ignore next */ {}), equal: Object.is });
|
|
1517
1579
|
constructor() {
|
|
1518
1580
|
if (!this.host) {
|
|
1519
|
-
throw new
|
|
1581
|
+
throw new CngxRuntimeError('CNGX1045', typeof ngDevMode !== 'undefined' &&
|
|
1582
|
+
ngDevMode &&
|
|
1583
|
+
'[cngxTab] must be placed inside <cngx-tab-group> or an element with [cngxTabGroup].');
|
|
1520
1584
|
}
|
|
1521
1585
|
}
|
|
1522
1586
|
ngOnInit() {
|
|
@@ -1666,7 +1730,9 @@ class CngxTabLink {
|
|
|
1666
1730
|
descriptorEl = null;
|
|
1667
1731
|
constructor() {
|
|
1668
1732
|
if (!this.host) {
|
|
1669
|
-
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].');
|
|
1670
1736
|
}
|
|
1671
1737
|
// Mirror the direct-error message into the describedby span. DOM side
|
|
1672
1738
|
// effect only - no signal writes. Guards until the span exists (created
|
|
@@ -1760,8 +1826,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1760
1826
|
*
|
|
1761
1827
|
* @internal
|
|
1762
1828
|
*/
|
|
1763
|
-
function warnTabsRouterAbsent(
|
|
1764
|
-
|
|
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. ` +
|
|
1765
1834
|
`Provide @angular/router via provideRouter(...) to enable ${enables}.`);
|
|
1766
1835
|
}
|
|
1767
1836
|
|
|
@@ -1824,7 +1893,7 @@ class CngxTabsFragmentSync {
|
|
|
1824
1893
|
* history entry.
|
|
1825
1894
|
*/
|
|
1826
1895
|
replaceUrl = input(true, ...(ngDevMode ? [{ debugName: "replaceUrl" }] : /* istanbul ignore next */ []));
|
|
1827
|
-
host =
|
|
1896
|
+
host = injectTabGroupHost('cngxTabsFragmentSync');
|
|
1828
1897
|
router = inject(Router, { optional: true });
|
|
1829
1898
|
/**
|
|
1830
1899
|
* Latched once the URL seed has reached a registered tab, so the
|
|
@@ -1840,8 +1909,13 @@ class CngxTabsFragmentSync {
|
|
|
1840
1909
|
*/
|
|
1841
1910
|
seeded = false;
|
|
1842
1911
|
constructor() {
|
|
1843
|
-
|
|
1844
|
-
|
|
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
|
+
}
|
|
1845
1919
|
return;
|
|
1846
1920
|
}
|
|
1847
1921
|
const router = this.router;
|
|
@@ -1995,9 +2069,17 @@ const cngxDefaultTabRoute = (handle) => [handle.id];
|
|
|
1995
2069
|
* resolves on this navigation's own `navigate()` promise:
|
|
1996
2070
|
*
|
|
1997
2071
|
* - resolved `true` (`NavigationEnd`) → `true` (commit the switch)
|
|
2072
|
+
* - resolved `null` (a skipped same-URL navigation, the route is
|
|
2073
|
+
* already active) → `true`
|
|
1998
2074
|
* - resolved `false` (`NavigationCancel` - a `CanDeactivate` guard
|
|
1999
|
-
* blocked, or a newer navigation superseded this one) → `false
|
|
2000
|
-
*
|
|
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.
|
|
2001
2083
|
*
|
|
2002
2084
|
* Routed tabs reuse the presenter's commit lifecycle verbatim - the
|
|
2003
2085
|
* router navigation is simply the async op. \
|
|
@@ -2032,9 +2114,11 @@ function createTabRouterCommit(opts) {
|
|
|
2032
2114
|
// already active, which commits.
|
|
2033
2115
|
subscriber.next(result !== false);
|
|
2034
2116
|
subscriber.complete();
|
|
2035
|
-
}, () => {
|
|
2036
|
-
|
|
2037
|
-
|
|
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);
|
|
2038
2122
|
});
|
|
2039
2123
|
});
|
|
2040
2124
|
}
|
|
@@ -2167,7 +2251,7 @@ class CngxTabsRouteSync {
|
|
|
2167
2251
|
* replaces the policies themselves.
|
|
2168
2252
|
*/
|
|
2169
2253
|
match = input(undefined, ...(ngDevMode ? [{ debugName: "match" }] : /* istanbul ignore next */ []));
|
|
2170
|
-
host =
|
|
2254
|
+
host = injectTabGroupHost('cngxTabsRouteSync');
|
|
2171
2255
|
router = inject(Router, { optional: true });
|
|
2172
2256
|
navHost = inject(CNGX_TAB_NAV_HOST, { optional: true, host: true });
|
|
2173
2257
|
config = injectTabsConfig();
|
|
@@ -2183,13 +2267,13 @@ class CngxTabsRouteSync {
|
|
|
2183
2267
|
mode = signal('pessimistic', ...(ngDevMode ? [{ debugName: "mode" }] : /* istanbul ignore next */ []));
|
|
2184
2268
|
/**
|
|
2185
2269
|
* Router commit-action read by the presenter via the DI fallback.
|
|
2186
|
-
* `null` when
|
|
2270
|
+
* `null` when the router is not set up (graceful no-op). Rebuilt only
|
|
2187
2271
|
* when `routeFor` changes; the navigation gate itself is the async
|
|
2188
2272
|
* op inside the action.
|
|
2189
2273
|
*/
|
|
2190
2274
|
action = computed(() => {
|
|
2191
2275
|
const router = this.router;
|
|
2192
|
-
if (!router) {
|
|
2276
|
+
if (!router || !this.activatedRoute) {
|
|
2193
2277
|
return null;
|
|
2194
2278
|
}
|
|
2195
2279
|
return createTabRouterCommit({
|
|
@@ -2199,8 +2283,12 @@ class CngxTabsRouteSync {
|
|
|
2199
2283
|
});
|
|
2200
2284
|
}, ...(ngDevMode ? [{ debugName: "action" }] : /* istanbul ignore next */ []));
|
|
2201
2285
|
constructor() {
|
|
2202
|
-
|
|
2203
|
-
|
|
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
|
+
}
|
|
2204
2292
|
return;
|
|
2205
2293
|
}
|
|
2206
2294
|
const router = this.router;
|
|
@@ -2306,7 +2394,7 @@ function createTabsHostAttrs(inputs) {
|
|
|
2306
2394
|
};
|
|
2307
2395
|
}
|
|
2308
2396
|
|
|
2309
|
-
function partitionFeatures(features) {
|
|
2397
|
+
function partitionFeatures(features, caller) {
|
|
2310
2398
|
const config = [];
|
|
2311
2399
|
const i18n = [];
|
|
2312
2400
|
for (const feat of features) {
|
|
@@ -2321,11 +2409,17 @@ function partitionFeatures(features) {
|
|
|
2321
2409
|
// Unbranded feature - runtime escape from the `_target` type.
|
|
2322
2410
|
// Drop with dev-warn so an i18n-shaped override never lands
|
|
2323
2411
|
// silently in `CNGX_TABS_CONFIG`.
|
|
2324
|
-
if (
|
|
2325
|
-
|
|
2326
|
-
'
|
|
2327
|
-
|
|
2328
|
-
|
|
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
|
+
}
|
|
2329
2423
|
}
|
|
2330
2424
|
}
|
|
2331
2425
|
return { config, i18n };
|
|
@@ -2360,7 +2454,7 @@ function partitionFeatures(features) {
|
|
|
2360
2454
|
* @relatedTo CngxTabGroup, CngxTabsConfig, provideCngxTabsAt
|
|
2361
2455
|
*/
|
|
2362
2456
|
function provideCngxTabs(...features) {
|
|
2363
|
-
const { config, i18n } = partitionFeatures(features);
|
|
2457
|
+
const { config, i18n } = partitionFeatures(features, 'provideCngxTabs');
|
|
2364
2458
|
return makeEnvironmentProviders([
|
|
2365
2459
|
provideTabsConfig(...config),
|
|
2366
2460
|
...(i18n.length > 0 ? [provideTabsI18n(...i18n)] : []),
|
|
@@ -2388,7 +2482,7 @@ function provideCngxTabs(...features) {
|
|
|
2388
2482
|
* @relatedTo CngxTabGroup, CngxTabsConfig, provideCngxTabs
|
|
2389
2483
|
*/
|
|
2390
2484
|
function provideCngxTabsAt(...features) {
|
|
2391
|
-
const { config, i18n } = partitionFeatures(features);
|
|
2485
|
+
const { config, i18n } = partitionFeatures(features, 'provideCngxTabsAt');
|
|
2392
2486
|
return [
|
|
2393
2487
|
// Gate like i18n: an i18n-only call must not plant an empty config
|
|
2394
2488
|
// at this injector level and shadow an app-wide provideTabsConfig.
|
|
@@ -2643,7 +2737,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
2643
2737
|
* Structural slot for the rejection-decoration template. 3-stage
|
|
2644
2738
|
* cascade: per-instance directive >
|
|
2645
2739
|
* `CNGX_TABS_CONFIG.templates.rejectionIcon` >
|
|
2646
|
-
* `CNGX_TABS_GLYPHS.rejectionIcon
|
|
2740
|
+
* `CNGX_TABS_GLYPHS.rejectionIcon` (a failed commit) or
|
|
2741
|
+
* `CNGX_TABS_GLYPHS.refusedIcon` (a refused one).
|
|
2647
2742
|
*
|
|
2648
2743
|
* ```html
|
|
2649
2744
|
* <cngx-tab-group>
|
|
@@ -3077,8 +3172,13 @@ function createTabKeyboardNav(opts) {
|
|
|
3077
3172
|
buttons.find((button) => button.getAttribute('data-tab-id') === id)?.focus();
|
|
3078
3173
|
};
|
|
3079
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 */ []));
|
|
3080
3180
|
effect(() => {
|
|
3081
|
-
if (
|
|
3181
|
+
if (outcomeSequence() === undefined) {
|
|
3082
3182
|
return;
|
|
3083
3183
|
}
|
|
3084
3184
|
untracked(() => {
|
|
@@ -3252,44 +3352,85 @@ function createTabGroupAnnouncements(options) {
|
|
|
3252
3352
|
// Close phrase with commit-activity expiry: a NEW phrase (re)arms; a
|
|
3253
3353
|
// commit status change while armed spends the phrase, so a later
|
|
3254
3354
|
// return to idle re-renders '' instead of re-announcing the stale
|
|
3255
|
-
// close.
|
|
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).
|
|
3256
3359
|
const closedPhrase = createAnnouncementPhrase({
|
|
3257
3360
|
source: () => ({
|
|
3258
3361
|
phrase: closedAnnouncement(),
|
|
3259
3362
|
status: presenter.commitTransition.current(),
|
|
3363
|
+
sequence: presenter.lastOutcome()?.sequence,
|
|
3260
3364
|
}),
|
|
3261
3365
|
arm: (curr, prev) => (curr.phrase !== prev.phrase ? curr.phrase : null),
|
|
3262
|
-
spend: (curr, prev) => curr.status !== prev.status,
|
|
3366
|
+
spend: (curr, prev) => curr.status !== prev.status || curr.sequence !== prev.sequence,
|
|
3263
3367
|
seed: (src) => src.phrase,
|
|
3264
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
|
+
}
|
|
3265
3400
|
// Copy and tab labels (which a consumer may translate) are read untracked
|
|
3266
3401
|
// in the live region: a language switch must not re-speak the last phrase;
|
|
3267
3402
|
// the next transition speaks the new language.
|
|
3268
3403
|
const liveAnnouncement = computed(() => {
|
|
3269
|
-
// Read
|
|
3270
|
-
//
|
|
3271
|
-
//
|
|
3272
|
-
|
|
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();
|
|
3273
3408
|
const closeConfirmation = closedPhrase();
|
|
3409
|
+
if (refused) {
|
|
3410
|
+
return refused;
|
|
3411
|
+
}
|
|
3274
3412
|
const current = presenter.commitTransition.current();
|
|
3275
3413
|
if (current === 'pending') {
|
|
3276
3414
|
return untracked(() => i18n().commitInFlight);
|
|
3277
3415
|
}
|
|
3278
3416
|
if (current === 'error') {
|
|
3279
|
-
// No `previous === 'pending'` guard - sync
|
|
3417
|
+
// No `previous === 'pending'` guard - sync failures collapse
|
|
3280
3418
|
// pending → error in one flush, so the tracker captures
|
|
3281
3419
|
// `previous = 'idle'` and an unguarded read keeps the
|
|
3282
|
-
// 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.
|
|
3283
3423
|
const failedIdx = presenter.lastFailedIndex();
|
|
3284
3424
|
const originIdx = presenter.originIndexDuringCommit();
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
return untracked(() => i18n().commitRolledBackTo(originLabel));
|
|
3290
|
-
}
|
|
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);
|
|
3291
3429
|
}
|
|
3292
|
-
return untracked(() =>
|
|
3430
|
+
return untracked(() => {
|
|
3431
|
+
const copy = i18n();
|
|
3432
|
+
return copy.commitRolledBackTo(originName(origin, originIdx, copy));
|
|
3433
|
+
});
|
|
3293
3434
|
}
|
|
3294
3435
|
if (current === 'success') {
|
|
3295
3436
|
const tabs = presenter.tabs();
|
|
@@ -3303,7 +3444,9 @@ function createTabGroupAnnouncements(options) {
|
|
|
3303
3444
|
const prevIdx = priorActiveIndex();
|
|
3304
3445
|
return untracked(() => {
|
|
3305
3446
|
const copy = i18n();
|
|
3306
|
-
const positionPhrase =
|
|
3447
|
+
const positionPhrase = label
|
|
3448
|
+
? copy.selectedTab(label, idx + 1, count)
|
|
3449
|
+
: copy.unlabeledTabOfCount(idx + 1, count);
|
|
3307
3450
|
if (idx > prevIdx) {
|
|
3308
3451
|
return copy.nextTab(positionPhrase);
|
|
3309
3452
|
}
|
|
@@ -3334,12 +3477,31 @@ function createTabGroupAnnouncements(options) {
|
|
|
3334
3477
|
}
|
|
3335
3478
|
function tabAriaLabel(tab, position) {
|
|
3336
3479
|
const tabs = presenter.tabs();
|
|
3337
|
-
const label = tab.label()
|
|
3480
|
+
const label = tab.label();
|
|
3338
3481
|
const detail = tab.subLabel();
|
|
3339
3482
|
const copy = i18n();
|
|
3483
|
+
if (!label) {
|
|
3484
|
+
const positionName = copy.unlabeledTabOfCount(position, tabs.length);
|
|
3485
|
+
return detail ? copy.tabLabelWithDetail(positionName, detail) : positionName;
|
|
3486
|
+
}
|
|
3340
3487
|
const labelPart = detail ? copy.tabLabelWithDetail(label, detail) : label;
|
|
3341
3488
|
return copy.selectedTab(labelPart, position, tabs.length);
|
|
3342
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);
|
|
3504
|
+
}
|
|
3343
3505
|
// Eager seed - `linkedSignal` is lazy and the success arm doesn't
|
|
3344
3506
|
// touch the tracker at construction (commitTransition is `idle`),
|
|
3345
3507
|
// so without this read `prev?.source` is undefined on the first
|
|
@@ -3352,6 +3514,9 @@ function createTabGroupAnnouncements(options) {
|
|
|
3352
3514
|
liveAnnouncement,
|
|
3353
3515
|
statusPhrase,
|
|
3354
3516
|
tabAriaLabel,
|
|
3517
|
+
tabLabelledBy,
|
|
3518
|
+
tabLabelId,
|
|
3519
|
+
tabSubLabelId,
|
|
3355
3520
|
};
|
|
3356
3521
|
}
|
|
3357
3522
|
|
|
@@ -3436,8 +3601,14 @@ function createTabNavAnnouncement(options) {
|
|
|
3436
3601
|
const CNGX_TABS_GLYPHS = {
|
|
3437
3602
|
/** Default visual for `*cngxTabErrorBadge` when no override is bound. */
|
|
3438
3603
|
errorBadge: '!',
|
|
3439
|
-
/** Default visual for `*cngxTabRejectionIcon` when no override is bound. */
|
|
3604
|
+
/** Default visual for `*cngxTabRejectionIcon` on a failed commit when no override is bound. */
|
|
3440
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',
|
|
3441
3612
|
/** Default visual for a tab's close button when no override is bound. */
|
|
3442
3613
|
closeIcon: '×',
|
|
3443
3614
|
/** Default visual for the add-tab button when no override is bound. */
|