@cngx/common 0.0.1-rc.0
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/LICENSE +21 -0
- package/README.md +18 -0
- package/a11y/README.md +77 -0
- package/card/README.md +79 -0
- package/chart/README.md +31 -0
- package/data/README.md +883 -0
- package/dialog/README.md +84 -0
- package/display/README.md +30 -0
- package/fesm2022/cngx-common-a11y.mjs +1260 -0
- package/fesm2022/cngx-common-a11y.mjs.map +1 -0
- package/fesm2022/cngx-common-card.mjs +765 -0
- package/fesm2022/cngx-common-card.mjs.map +1 -0
- package/fesm2022/cngx-common-chart.mjs +2943 -0
- package/fesm2022/cngx-common-chart.mjs.map +1 -0
- package/fesm2022/cngx-common-data.mjs +2886 -0
- package/fesm2022/cngx-common-data.mjs.map +1 -0
- package/fesm2022/cngx-common-dialog.mjs +1366 -0
- package/fesm2022/cngx-common-dialog.mjs.map +1 -0
- package/fesm2022/cngx-common-display.mjs +1603 -0
- package/fesm2022/cngx-common-display.mjs.map +1 -0
- package/fesm2022/cngx-common-interactive.mjs +8185 -0
- package/fesm2022/cngx-common-interactive.mjs.map +1 -0
- package/fesm2022/cngx-common-layout.mjs +1335 -0
- package/fesm2022/cngx-common-layout.mjs.map +1 -0
- package/fesm2022/cngx-common-popover.mjs +1200 -0
- package/fesm2022/cngx-common-popover.mjs.map +1 -0
- package/fesm2022/cngx-common-stepper.mjs +1350 -0
- package/fesm2022/cngx-common-stepper.mjs.map +1 -0
- package/fesm2022/cngx-common-tabs.mjs +1551 -0
- package/fesm2022/cngx-common-tabs.mjs.map +1 -0
- package/fesm2022/cngx-common.mjs +34 -0
- package/fesm2022/cngx-common.mjs.map +1 -0
- package/interactive/README.md +211 -0
- package/layout/README.md +117 -0
- package/package.json +100 -0
- package/popover/README.md +218 -0
- package/stepper/README.md +102 -0
- package/tabs/README.md +32 -0
- package/types/cngx-common-a11y.d.ts +616 -0
- package/types/cngx-common-card.d.ts +413 -0
- package/types/cngx-common-chart.d.ts +1081 -0
- package/types/cngx-common-data.d.ts +1460 -0
- package/types/cngx-common-dialog.d.ts +772 -0
- package/types/cngx-common-display.d.ts +1136 -0
- package/types/cngx-common-interactive.d.ts +5013 -0
- package/types/cngx-common-layout.d.ts +737 -0
- package/types/cngx-common-popover.d.ts +520 -0
- package/types/cngx-common-stepper.d.ts +982 -0
- package/types/cngx-common-tabs.d.ts +1237 -0
- package/types/cngx-common.d.ts +13 -0
|
@@ -0,0 +1,1350 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { InjectionToken, makeEnvironmentProviders, inject, model, input, computed, signal, Directive, TemplateRef, contentChild, linkedSignal, DestroyRef, output, afterNextRender, effect, untracked, isDevMode } from '@angular/core';
|
|
3
|
+
import { CNGX_COMMIT_CONTROLLER_FACTORY } from '@cngx/common/data';
|
|
4
|
+
import { createTransitionTracker, CNGX_STATEFUL, nextUid } from '@cngx/core/utils';
|
|
5
|
+
import { isObservable } from 'rxjs';
|
|
6
|
+
import { toSignal, takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
7
|
+
import { Router, NavigationEnd } from '@angular/router';
|
|
8
|
+
import { filter } from 'rxjs/operators';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Build a stepper commit handler over an existing {@link CngxCommitController}.
|
|
12
|
+
* Resolves `Observable<boolean>` / `Promise<boolean>` / `boolean` returns into
|
|
13
|
+
* a unified `accept: boolean` outcome.
|
|
14
|
+
*/
|
|
15
|
+
function createStepperCommitHandler(opts) {
|
|
16
|
+
const { controller } = opts;
|
|
17
|
+
return {
|
|
18
|
+
isCommitting: controller.isCommitting,
|
|
19
|
+
beginTransition(fromIndex, toIndex, action, onResolve) {
|
|
20
|
+
controller.begin((handlers) => runStepperAction(action, fromIndex, toIndex, handlers), toIndex, fromIndex, {
|
|
21
|
+
onSuccess: () => onResolve(true),
|
|
22
|
+
onError: () => onResolve(false),
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
cancel() {
|
|
26
|
+
controller.cancel();
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function runStepperAction(action, fromIndex, toIndex, handlers) {
|
|
31
|
+
let cancelled = false;
|
|
32
|
+
let unsubscribe = null;
|
|
33
|
+
const safeSuccess = (accept) => {
|
|
34
|
+
if (cancelled) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (accept) {
|
|
38
|
+
handlers.onSuccess(toIndex);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
handlers.onError(new Error('Stepper transition refused by commitAction'));
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const safeError = (err) => {
|
|
45
|
+
if (cancelled) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
handlers.onError(err);
|
|
49
|
+
};
|
|
50
|
+
let result;
|
|
51
|
+
try {
|
|
52
|
+
result = action(fromIndex, toIndex);
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
safeError(err);
|
|
56
|
+
return { cancel: () => { cancelled = true; } };
|
|
57
|
+
}
|
|
58
|
+
if (isObservable(result)) {
|
|
59
|
+
// Synchronous Observables (`of(true)`) emit inside `.subscribe`
|
|
60
|
+
// before the assignment binds — `sub` would be in TDZ. Declare
|
|
61
|
+
// the handle on a `let` first.
|
|
62
|
+
let sub = null;
|
|
63
|
+
sub = result.subscribe({
|
|
64
|
+
next: (accept) => {
|
|
65
|
+
safeSuccess(accept);
|
|
66
|
+
sub?.unsubscribe();
|
|
67
|
+
},
|
|
68
|
+
error: (err) => safeError(err),
|
|
69
|
+
});
|
|
70
|
+
unsubscribe = () => sub?.unsubscribe();
|
|
71
|
+
}
|
|
72
|
+
else if (result != null && typeof result.then === 'function') {
|
|
73
|
+
result.then(safeSuccess, safeError);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
safeSuccess(result);
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
cancel: () => {
|
|
80
|
+
cancelled = true;
|
|
81
|
+
unsubscribe?.();
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* DI token carrying the factory the presenter uses to allocate its commit
|
|
87
|
+
* handler. Symmetric to the select family's `CNGX_ARRAY_COMMIT_HANDLER_FACTORY`.
|
|
88
|
+
*/
|
|
89
|
+
const CNGX_STEPPER_COMMIT_HANDLER_FACTORY = new InjectionToken('CngxStepperCommitHandlerFactory', {
|
|
90
|
+
providedIn: 'root',
|
|
91
|
+
factory: () => createStepperCommitHandler,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const STEPPER_CONFIG_DEFAULTS = {
|
|
95
|
+
defaultOrientation: 'horizontal',
|
|
96
|
+
defaultLinear: false,
|
|
97
|
+
defaultCommitMode: 'pessimistic',
|
|
98
|
+
routerSyncMode: 'fragment',
|
|
99
|
+
routerSyncParam: 'step',
|
|
100
|
+
ariaLabels: {
|
|
101
|
+
stepperRegion: 'Stepper',
|
|
102
|
+
},
|
|
103
|
+
fallbackLabels: {
|
|
104
|
+
groupRoleDescription: 'step group',
|
|
105
|
+
stepRoleDescription: 'stepper',
|
|
106
|
+
},
|
|
107
|
+
templates: {},
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* DI token for the resolved stepper config. `providedIn: 'root'` with
|
|
111
|
+
* library defaults; override via {@link provideStepperConfig} (root)
|
|
112
|
+
* or {@link provideStepperConfigAt} (component scope).
|
|
113
|
+
*/
|
|
114
|
+
const CNGX_STEPPER_CONFIG = new InjectionToken('CngxStepperConfig', { providedIn: 'root', factory: () => STEPPER_CONFIG_DEFAULTS });
|
|
115
|
+
/**
|
|
116
|
+
* Brands a config mutator with `_target: 'config'`. Every `with*`
|
|
117
|
+
* config feature returns one of these.
|
|
118
|
+
*
|
|
119
|
+
* @internal
|
|
120
|
+
*/
|
|
121
|
+
function defineStepperConfigFeature(fn) {
|
|
122
|
+
return Object.assign(fn, { _target: 'config' });
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Override the default orientation. Per-instance `[orientation]`
|
|
126
|
+
* Input still wins; this only moves the cascade default.
|
|
127
|
+
*/
|
|
128
|
+
function withStepperDefaultOrientation(orientation) {
|
|
129
|
+
return defineStepperConfigFeature((cfg) => ({
|
|
130
|
+
...cfg,
|
|
131
|
+
defaultOrientation: orientation,
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Override the default linear-progression setting. Per-instance
|
|
136
|
+
* `[linear]` Input still wins.
|
|
137
|
+
*/
|
|
138
|
+
function withStepperLinear(linear) {
|
|
139
|
+
return defineStepperConfigFeature((cfg) => ({ ...cfg, defaultLinear: linear }));
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Override the default commit mode for async step transitions.
|
|
143
|
+
* `'optimistic'` advances on action dispatch and rolls back on error;
|
|
144
|
+
* `'pessimistic'` waits for success. Per-instance `[commitMode]`
|
|
145
|
+
* Input still wins.
|
|
146
|
+
*/
|
|
147
|
+
function withStepperCommitMode(mode) {
|
|
148
|
+
return defineStepperConfigFeature((cfg) => ({
|
|
149
|
+
...cfg,
|
|
150
|
+
defaultCommitMode: mode,
|
|
151
|
+
}));
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Configure router synchronisation for the active step. `mode` chooses
|
|
155
|
+
* the URL surface (URL fragment or query parameter); `param` names the
|
|
156
|
+
* key (default `'step'`).
|
|
157
|
+
*/
|
|
158
|
+
function withStepperRouterSync(mode, param = 'step') {
|
|
159
|
+
return defineStepperConfigFeature((cfg) => ({
|
|
160
|
+
...cfg,
|
|
161
|
+
routerSyncMode: mode,
|
|
162
|
+
routerSyncParam: param,
|
|
163
|
+
}));
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Merge ARIA labels into the cascade. Keys not provided keep their
|
|
167
|
+
* library defaults; per-instance overrides on the stepper still win.
|
|
168
|
+
*/
|
|
169
|
+
function withStepperAriaLabels(labels) {
|
|
170
|
+
return defineStepperConfigFeature((cfg) => ({
|
|
171
|
+
...cfg,
|
|
172
|
+
ariaLabels: { ...cfg.ariaLabels, ...labels },
|
|
173
|
+
}));
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Merge text fallback labels (button captions, error strings) into the
|
|
177
|
+
* cascade. Used when a slot directive is not present.
|
|
178
|
+
*/
|
|
179
|
+
function withStepperFallbackLabels(labels) {
|
|
180
|
+
return defineStepperConfigFeature((cfg) => ({
|
|
181
|
+
...cfg,
|
|
182
|
+
fallbackLabels: { ...cfg.fallbackLabels, ...labels },
|
|
183
|
+
}));
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Override the default `*cngxStepIndicator` template app-wide.
|
|
187
|
+
* Per-instance directive still wins; this only moves the cascade
|
|
188
|
+
* middle tier.
|
|
189
|
+
*/
|
|
190
|
+
function withStepIndicatorTemplate(template) {
|
|
191
|
+
return defineStepperConfigFeature((cfg) => ({
|
|
192
|
+
...cfg,
|
|
193
|
+
templates: { ...cfg.templates, indicator: template },
|
|
194
|
+
}));
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Override the default `*cngxStepBadge` template app-wide.
|
|
198
|
+
*/
|
|
199
|
+
function withStepBadgeTemplate(template) {
|
|
200
|
+
return defineStepperConfigFeature((cfg) => ({
|
|
201
|
+
...cfg,
|
|
202
|
+
templates: { ...cfg.templates, badge: template },
|
|
203
|
+
}));
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Override the default `*cngxStepBusySpinner` template app-wide.
|
|
207
|
+
*/
|
|
208
|
+
function withStepBusySpinnerTemplate(template) {
|
|
209
|
+
return defineStepperConfigFeature((cfg) => ({
|
|
210
|
+
...cfg,
|
|
211
|
+
templates: { ...cfg.templates, busySpinner: template },
|
|
212
|
+
}));
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Override the default `*cngxStepRejection` template app-wide.
|
|
216
|
+
* Symmetric with the upcoming tabs `cngxTabRejectionIcon` (Phase 4).
|
|
217
|
+
*/
|
|
218
|
+
function withStepRejectionTemplate(template) {
|
|
219
|
+
return defineStepperConfigFeature((cfg) => ({
|
|
220
|
+
...cfg,
|
|
221
|
+
templates: { ...cfg.templates, rejection: template },
|
|
222
|
+
}));
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Override the default `*cngxStepGroupHeader` template app-wide.
|
|
226
|
+
*/
|
|
227
|
+
function withStepGroupHeaderTemplate(template) {
|
|
228
|
+
return defineStepperConfigFeature((cfg) => ({
|
|
229
|
+
...cfg,
|
|
230
|
+
templates: { ...cfg.templates, groupHeader: template },
|
|
231
|
+
}));
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Override the default `*cngxStepperEmpty` template app-wide.
|
|
235
|
+
*/
|
|
236
|
+
function withStepperEmptyTemplate(template) {
|
|
237
|
+
return defineStepperConfigFeature((cfg) => ({
|
|
238
|
+
...cfg,
|
|
239
|
+
templates: { ...cfg.templates, empty: template },
|
|
240
|
+
}));
|
|
241
|
+
}
|
|
242
|
+
function resolveFeatures(features) {
|
|
243
|
+
return features.reduce((cfg, feat) => feat(cfg), STEPPER_CONFIG_DEFAULTS);
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Root-level provider for the stepper config. Apply once in the
|
|
247
|
+
* application providers array. Sibling of `provideTabsConfig` /
|
|
248
|
+
* `provideSelectConfig`.
|
|
249
|
+
*/
|
|
250
|
+
function provideStepperConfig(...features) {
|
|
251
|
+
return makeEnvironmentProviders([
|
|
252
|
+
{ provide: CNGX_STEPPER_CONFIG, useValue: resolveFeatures(features) },
|
|
253
|
+
]);
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Component-scoped config override. Spread the returned `Provider[]`
|
|
257
|
+
* into `providers` or `viewProviders` — `viewProviders` cannot accept
|
|
258
|
+
* opaque {@link EnvironmentProviders}, so the twin returns a list.
|
|
259
|
+
* Sibling of `provideTabsConfigAt`.
|
|
260
|
+
*
|
|
261
|
+
* Resolution priority: per-instance Input > viewProviders (`At`) >
|
|
262
|
+
* root provider > library default.
|
|
263
|
+
*
|
|
264
|
+
* ```ts
|
|
265
|
+
* @Component({
|
|
266
|
+
* viewProviders: [...provideStepperConfigAt(withStepperLinear(true))],
|
|
267
|
+
* })
|
|
268
|
+
* ```
|
|
269
|
+
*/
|
|
270
|
+
function provideStepperConfigAt(...features) {
|
|
271
|
+
return [{ provide: CNGX_STEPPER_CONFIG, useValue: resolveFeatures(features) }];
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Inject the resolved stepper config in an injection context.
|
|
275
|
+
*/
|
|
276
|
+
function injectStepperConfig() {
|
|
277
|
+
return inject(CNGX_STEPPER_CONFIG);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* DI token carrying the presenter's contract to atoms + organism shells.
|
|
282
|
+
* Atoms inject `optional: true` and either register here or fall through
|
|
283
|
+
* {@link CNGX_STEP_GROUP_HOST} when nested in a group.
|
|
284
|
+
*/
|
|
285
|
+
const CNGX_STEPPER_HOST = new InjectionToken('CngxStepperHost');
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* DFS-flatten a step tree. Group nodes emit before their children;
|
|
289
|
+
* the consumer keys off `kind` to render a panel container vs. a
|
|
290
|
+
* group header.
|
|
291
|
+
*/
|
|
292
|
+
function flattenStepTree(nodes) {
|
|
293
|
+
const out = [];
|
|
294
|
+
let flatIndex = 0;
|
|
295
|
+
const visit = (list) => {
|
|
296
|
+
for (const node of list) {
|
|
297
|
+
// Re-emit with the live flatIndex; registry-builder seeds -1
|
|
298
|
+
// so it doesn't need to know the final ordering.
|
|
299
|
+
out.push({ ...node, flatIndex: node.kind === 'step' ? flatIndex : -1 });
|
|
300
|
+
if (node.kind === 'step') {
|
|
301
|
+
flatIndex++;
|
|
302
|
+
}
|
|
303
|
+
if (node.children.length > 0) {
|
|
304
|
+
visit(node.children);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
visit(nodes);
|
|
309
|
+
return out;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Structural equality for the step-tree registry signal. Shape only —
|
|
313
|
+
* id, kind, depth, parentId, children length. Reactive fields
|
|
314
|
+
* (`label`, `disabled`, `state`, `errorAggregator`) are signals; their
|
|
315
|
+
* own subscribers track identity changes.
|
|
316
|
+
*/
|
|
317
|
+
function stepTreeEqual(a, b) {
|
|
318
|
+
if (a === b) {
|
|
319
|
+
return true;
|
|
320
|
+
}
|
|
321
|
+
if (a.length !== b.length) {
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
for (let i = 0; i < a.length; i++) {
|
|
325
|
+
const x = a[i];
|
|
326
|
+
const y = b[i];
|
|
327
|
+
if (x.id !== y.id || x.kind !== y.kind || x.depth !== y.depth || x.parentId !== y.parentId) {
|
|
328
|
+
return false;
|
|
329
|
+
}
|
|
330
|
+
if (!stepTreeEqual(x.children, y.children)) {
|
|
331
|
+
return false;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return true;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Structural equality for `flatSteps`. Adds `flatIndex` (shifts when
|
|
338
|
+
* a sibling is inserted) on top of the {@link stepTreeEqual} fields.
|
|
339
|
+
*
|
|
340
|
+
* Use only on projections where every step carries a real
|
|
341
|
+
* DFS-assigned `flatIndex` and `depth` — for `-1` placeholders, use
|
|
342
|
+
* {@link stepNodesEqual}.
|
|
343
|
+
*
|
|
344
|
+
* @internal Exported from `public-api.ts` so the cngx-stepper and
|
|
345
|
+
* cngx-mat-stepper organisms share the comparator across the
|
|
346
|
+
* secondary-entry boundary (Sheriff forbids deep-relative imports).
|
|
347
|
+
*/
|
|
348
|
+
function flatStepsEqual(a, b) {
|
|
349
|
+
if (a === b) {
|
|
350
|
+
return true;
|
|
351
|
+
}
|
|
352
|
+
if (a.length !== b.length) {
|
|
353
|
+
return false;
|
|
354
|
+
}
|
|
355
|
+
for (let i = 0; i < a.length; i++) {
|
|
356
|
+
if (a[i].id !== b[i].id ||
|
|
357
|
+
a[i].kind !== b[i].kind ||
|
|
358
|
+
a[i].depth !== b[i].depth ||
|
|
359
|
+
a[i].flatIndex !== b[i].flatIndex) {
|
|
360
|
+
return false;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return true;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Structural equality for any flat node array — `id`, `kind`,
|
|
367
|
+
* `parentId` only, ignoring `flatIndex` and `depth`. Use for
|
|
368
|
+
* `CngxStepGroup.children` and other `-1`-placeholder projections.
|
|
369
|
+
*/
|
|
370
|
+
function stepNodesEqual(a, b) {
|
|
371
|
+
if (a === b) {
|
|
372
|
+
return true;
|
|
373
|
+
}
|
|
374
|
+
if (a.length !== b.length) {
|
|
375
|
+
return false;
|
|
376
|
+
}
|
|
377
|
+
for (let i = 0; i < a.length; i++) {
|
|
378
|
+
if (a[i].id !== b[i].id ||
|
|
379
|
+
a[i].kind !== b[i].kind ||
|
|
380
|
+
a[i].parentId !== b[i].parentId) {
|
|
381
|
+
return false;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
return true;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Stepper presenter — the brain of every stepper / wizard flow.
|
|
389
|
+
* Holds the active-step model, registry, linear policy, orientation,
|
|
390
|
+
* and commit-controller lifecycle. Provides {@link CNGX_STEPPER_HOST}
|
|
391
|
+
* for atom registration and {@link CNGX_STATEFUL} so transition
|
|
392
|
+
* bridges (`<cngx-toast-on />`, `<cngx-banner-on />`) compose without
|
|
393
|
+
* explicit `[state]` wiring.
|
|
394
|
+
*
|
|
395
|
+
* Sheriff: common Level 2. Pure directive — zero template, zero CSS.
|
|
396
|
+
* Level-4 organisms compose this via `hostDirectives`.
|
|
397
|
+
*/
|
|
398
|
+
class CngxStepperPresenter {
|
|
399
|
+
config = injectStepperConfig();
|
|
400
|
+
activeStepIndex = model(0, ...(ngDevMode ? [{ debugName: "activeStepIndex" }] : /* istanbul ignore next */ []));
|
|
401
|
+
// Raw *Input slots default undefined so the cascade resolves through
|
|
402
|
+
// CNGX_STEPPER_CONFIG. Must stay public — the template type-checker
|
|
403
|
+
// rejects protected/private on hostDirective alias bindings.
|
|
404
|
+
linearInput = input(undefined, { ...(ngDevMode ? { debugName: "linearInput" } : /* istanbul ignore next */ {}), alias: 'linear' });
|
|
405
|
+
linear = computed(() => this.linearInput() ?? this.config.defaultLinear ?? false, ...(ngDevMode ? [{ debugName: "linear" }] : /* istanbul ignore next */ []));
|
|
406
|
+
orientationInput = input(undefined, { ...(ngDevMode ? { debugName: "orientationInput" } : /* istanbul ignore next */ {}), alias: 'orientation' });
|
|
407
|
+
orientation = computed(() => this.orientationInput() ?? this.config.defaultOrientation ?? 'horizontal', ...(ngDevMode ? [{ debugName: "orientation" }] : /* istanbul ignore next */ []));
|
|
408
|
+
commitAction = input(null, ...(ngDevMode ? [{ debugName: "commitAction" }] : /* istanbul ignore next */ []));
|
|
409
|
+
commitModeInput = input(undefined, { ...(ngDevMode ? { debugName: "commitModeInput" } : /* istanbul ignore next */ {}), alias: 'commitMode' });
|
|
410
|
+
commitMode = computed(() => this.commitModeInput() ?? this.config.defaultCommitMode ?? 'pessimistic', ...(ngDevMode ? [{ debugName: "commitMode" }] : /* istanbul ignore next */ []));
|
|
411
|
+
genericFactory = inject(CNGX_COMMIT_CONTROLLER_FACTORY);
|
|
412
|
+
commitController = this.genericFactory();
|
|
413
|
+
commitHandler = inject(CNGX_STEPPER_COMMIT_HANDLER_FACTORY)({ controller: this.commitController });
|
|
414
|
+
/** Producer surface for the `CNGX_STATEFUL` bridge contract. */
|
|
415
|
+
state = this.commitController.state;
|
|
416
|
+
/**
|
|
417
|
+
* Step index the user is committing to. Tracked separately from
|
|
418
|
+
* `state.data()` because the AsyncState data slot only updates on
|
|
419
|
+
* success. Drives per-step `aria-busy` in the organism.
|
|
420
|
+
*/
|
|
421
|
+
intendedStepIndex = this.commitController.intendedValue;
|
|
422
|
+
/**
|
|
423
|
+
* Reactive current/previous pair for the commit-state status. Skin
|
|
424
|
+
* sub-components mount a `<span cngxLiveRegion>` reading this
|
|
425
|
+
* tracker. Allocated once per presenter — the underlying
|
|
426
|
+
* `linkedSignal` is shared across all consumers.
|
|
427
|
+
*/
|
|
428
|
+
commitTransition = createTransitionTracker(() => this.commitController.state.status());
|
|
429
|
+
// Persistence-of-error surface — see CngxStepperHost.lastFailedIndex
|
|
430
|
+
// / originIndexDuringCommit for the contract.
|
|
431
|
+
lastFailedIndexState = signal(undefined, ...(ngDevMode ? [{ debugName: "lastFailedIndexState" }] : /* istanbul ignore next */ []));
|
|
432
|
+
originIndexDuringCommitState = signal(undefined, ...(ngDevMode ? [{ debugName: "originIndexDuringCommitState" }] : /* istanbul ignore next */ []));
|
|
433
|
+
/** {@inheritDoc CngxStepperHost.lastFailedIndex} */
|
|
434
|
+
lastFailedIndex = this.lastFailedIndexState.asReadonly();
|
|
435
|
+
/** {@inheritDoc CngxStepperHost.originIndexDuringCommit} */
|
|
436
|
+
originIndexDuringCommit = this.originIndexDuringCommitState.asReadonly();
|
|
437
|
+
treeState = signal([], { ...(ngDevMode ? { debugName: "treeState" } : /* istanbul ignore next */ {}), equal: stepTreeEqual });
|
|
438
|
+
stepTree = this.treeState.asReadonly();
|
|
439
|
+
flatSteps = computed(() => flattenStepTree(this.stepTree()), { ...(ngDevMode ? { debugName: "flatSteps" } : /* istanbul ignore next */ {}), equal: flatStepsEqual });
|
|
440
|
+
/**
|
|
441
|
+
* Step-only flat projection — terminal nodes in DFS order.
|
|
442
|
+
* Structural-equal via `flatStepsEqual` so downstream computeds
|
|
443
|
+
* don't cascade on shape-stable re-emits. Single source for every
|
|
444
|
+
* `select*` / `clamp` / `activeStepId` lookup — never re-filter
|
|
445
|
+
* `flatSteps()`.
|
|
446
|
+
*/
|
|
447
|
+
stepsOnly = computed(() => this.flatSteps().filter((n) => n.kind === 'step'), { ...(ngDevMode ? { debugName: "stepsOnly" } : /* istanbul ignore next */ {}), equal: flatStepsEqual });
|
|
448
|
+
clampedIndex = computed(() => {
|
|
449
|
+
const stepCount = this.stepsOnly().length;
|
|
450
|
+
if (stepCount === 0) {
|
|
451
|
+
return 0;
|
|
452
|
+
}
|
|
453
|
+
const i = this.activeStepIndex();
|
|
454
|
+
return Math.max(0, Math.min(i, stepCount - 1));
|
|
455
|
+
}, ...(ngDevMode ? [{ debugName: "clampedIndex" }] : /* istanbul ignore next */ []));
|
|
456
|
+
activeStepId = computed(() => {
|
|
457
|
+
const idx = this.clampedIndex();
|
|
458
|
+
return this.stepsOnly()[idx]?.id ?? null;
|
|
459
|
+
}, ...(ngDevMode ? [{ debugName: "activeStepId" }] : /* istanbul ignore next */ []));
|
|
460
|
+
commitState = this.commitController.state;
|
|
461
|
+
// Flat id lookup; rebuilt into the hierarchical tree on each
|
|
462
|
+
// register/unregister.
|
|
463
|
+
registry = new Map();
|
|
464
|
+
insertionOrder = [];
|
|
465
|
+
register(handle, parentId = null) {
|
|
466
|
+
if (this.registry.has(handle.id)) {
|
|
467
|
+
// Idempotent re-register — replace the handle, keep the ordering slot.
|
|
468
|
+
const entry = this.registry.get(handle.id);
|
|
469
|
+
entry.reg = handle;
|
|
470
|
+
entry.parentId = parentId;
|
|
471
|
+
}
|
|
472
|
+
else {
|
|
473
|
+
this.registry.set(handle.id, { reg: handle, parentId, childIds: [] });
|
|
474
|
+
this.insertionOrder.push(handle.id);
|
|
475
|
+
if (parentId !== null) {
|
|
476
|
+
const parent = this.registry.get(parentId);
|
|
477
|
+
if (parent) {
|
|
478
|
+
parent.childIds.push(handle.id);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
this.rebuildTree();
|
|
483
|
+
}
|
|
484
|
+
unregister(id) {
|
|
485
|
+
const entry = this.registry.get(id);
|
|
486
|
+
if (!entry) {
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
if (entry.parentId !== null) {
|
|
490
|
+
const parent = this.registry.get(entry.parentId);
|
|
491
|
+
if (parent) {
|
|
492
|
+
parent.childIds = parent.childIds.filter((c) => c !== id);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
this.registry.delete(id);
|
|
496
|
+
const insertIdx = this.insertionOrder.indexOf(id);
|
|
497
|
+
if (insertIdx >= 0) {
|
|
498
|
+
this.insertionOrder.splice(insertIdx, 1);
|
|
499
|
+
}
|
|
500
|
+
this.rebuildTree();
|
|
501
|
+
}
|
|
502
|
+
rebuildTree() {
|
|
503
|
+
const buildNode = (id, depth) => {
|
|
504
|
+
const entry = this.registry.get(id);
|
|
505
|
+
const children = entry.childIds.map((cid) => buildNode(cid, depth + 1));
|
|
506
|
+
return {
|
|
507
|
+
id,
|
|
508
|
+
kind: entry.reg.kind,
|
|
509
|
+
label: entry.reg.label,
|
|
510
|
+
disabled: entry.reg.disabled,
|
|
511
|
+
state: entry.reg.state,
|
|
512
|
+
errorAggregator: entry.reg.errorAggregator,
|
|
513
|
+
children,
|
|
514
|
+
depth,
|
|
515
|
+
parentId: entry.parentId,
|
|
516
|
+
flatIndex: -1,
|
|
517
|
+
};
|
|
518
|
+
};
|
|
519
|
+
const rootIds = this.insertionOrder.filter((id) => this.registry.get(id).parentId === null);
|
|
520
|
+
this.treeState.set(rootIds.map((id) => buildNode(id, 0)));
|
|
521
|
+
}
|
|
522
|
+
/** {@inheritDoc CngxStepperHost.clearLastFailed} */
|
|
523
|
+
clearLastFailed() {
|
|
524
|
+
this.lastFailedIndexState.set(undefined);
|
|
525
|
+
}
|
|
526
|
+
select(index) {
|
|
527
|
+
const stepsOnly = this.stepsOnly();
|
|
528
|
+
if (stepsOnly.length === 0) {
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
const target = Math.max(0, Math.min(index, stepsOnly.length - 1));
|
|
532
|
+
if (this.linear() && target > this.activeStepIndex()) {
|
|
533
|
+
// Linear: refuse jumps that skip an incomplete step.
|
|
534
|
+
const blocking = stepsOnly
|
|
535
|
+
.slice(this.activeStepIndex(), target)
|
|
536
|
+
.find((n) => n.state() !== 'success' && !n.disabled());
|
|
537
|
+
if (blocking) {
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
if (stepsOnly[target].disabled()) {
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
const previous = this.activeStepIndex();
|
|
545
|
+
if (target === previous) {
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
const action = this.commitAction();
|
|
549
|
+
if (!action) {
|
|
550
|
+
// No-action fast path — sync move, no commit window opens, so
|
|
551
|
+
// `originIndexDuringCommit` stays untouched. Clear the rejection
|
|
552
|
+
// flag if the user re-picked a previously-failed target.
|
|
553
|
+
this.activeStepIndex.set(target);
|
|
554
|
+
if (this.lastFailedIndexState() === target) {
|
|
555
|
+
this.lastFailedIndexState.set(undefined);
|
|
556
|
+
}
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
// Commit-gated transition. Pessimistic holds at `previous` until
|
|
560
|
+
// the action resolves; optimistic advances now and rolls back on
|
|
561
|
+
// rejection. Supersede comes from the lifted commit-controller —
|
|
562
|
+
// a rapid second select() cancels the in-flight runner.
|
|
563
|
+
//
|
|
564
|
+
// Capture the safe-harbour origin exactly once on commit-window
|
|
565
|
+
// open. Written ONLY on this path so a stale origin never lingers
|
|
566
|
+
// into a non-commit navigation.
|
|
567
|
+
this.originIndexDuringCommitState.set(previous);
|
|
568
|
+
const mode = this.commitMode();
|
|
569
|
+
if (mode === 'optimistic') {
|
|
570
|
+
this.activeStepIndex.set(target);
|
|
571
|
+
}
|
|
572
|
+
this.commitHandler.beginTransition(previous, target, action, (accept) => {
|
|
573
|
+
if (accept) {
|
|
574
|
+
// Success — origin no longer needed; clear the rejection
|
|
575
|
+
// flag if the user re-picked the failed target.
|
|
576
|
+
this.originIndexDuringCommitState.set(undefined);
|
|
577
|
+
if (this.lastFailedIndexState() === target) {
|
|
578
|
+
this.lastFailedIndexState.set(undefined);
|
|
579
|
+
}
|
|
580
|
+
if (mode === 'pessimistic') {
|
|
581
|
+
this.activeStepIndex.set(target);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
else {
|
|
585
|
+
// Reject — flag the target; RETAIN the origin so
|
|
586
|
+
// `liveAnnouncement` can resolve the origin label for the
|
|
587
|
+
// rich rollback phrase. Optimistic rolls back; pessimistic
|
|
588
|
+
// never moved.
|
|
589
|
+
this.lastFailedIndexState.set(target);
|
|
590
|
+
if (mode === 'optimistic') {
|
|
591
|
+
this.activeStepIndex.set(previous);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
selectNext() {
|
|
597
|
+
const stepsOnly = this.stepsOnly();
|
|
598
|
+
let next = this.activeStepIndex() + 1;
|
|
599
|
+
while (next < stepsOnly.length && stepsOnly[next].disabled()) {
|
|
600
|
+
next++;
|
|
601
|
+
}
|
|
602
|
+
if (next < stepsOnly.length) {
|
|
603
|
+
this.select(next);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
selectPrevious() {
|
|
607
|
+
const stepsOnly = this.stepsOnly();
|
|
608
|
+
let prev = this.activeStepIndex() - 1;
|
|
609
|
+
while (prev >= 0 && stepsOnly[prev].disabled()) {
|
|
610
|
+
prev--;
|
|
611
|
+
}
|
|
612
|
+
if (prev >= 0) {
|
|
613
|
+
this.activeStepIndex.set(prev);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
selectById(id) {
|
|
617
|
+
const stepsOnly = this.stepsOnly();
|
|
618
|
+
const idx = stepsOnly.findIndex((n) => n.id === id);
|
|
619
|
+
if (idx >= 0) {
|
|
620
|
+
this.select(idx);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
reset() {
|
|
624
|
+
this.activeStepIndex.set(0);
|
|
625
|
+
this.commitController.cancel();
|
|
626
|
+
}
|
|
627
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStepperPresenter, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
628
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxStepperPresenter, isStandalone: true, selector: "[cngxStepper]", inputs: { activeStepIndex: { classPropertyName: "activeStepIndex", publicName: "activeStepIndex", isSignal: true, isRequired: false, transformFunction: null }, linearInput: { classPropertyName: "linearInput", publicName: "linear", isSignal: true, isRequired: false, transformFunction: null }, orientationInput: { classPropertyName: "orientationInput", publicName: "orientation", isSignal: true, isRequired: false, transformFunction: null }, commitAction: { classPropertyName: "commitAction", publicName: "commitAction", isSignal: true, isRequired: false, transformFunction: null }, commitModeInput: { classPropertyName: "commitModeInput", publicName: "commitMode", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { activeStepIndex: "activeStepIndexChange" }, providers: [
|
|
629
|
+
{ provide: CNGX_STEPPER_HOST, useExisting: CngxStepperPresenter },
|
|
630
|
+
{ provide: CNGX_STATEFUL, useExisting: CngxStepperPresenter },
|
|
631
|
+
], exportAs: ["cngxStepper"], ngImport: i0 });
|
|
632
|
+
}
|
|
633
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStepperPresenter, decorators: [{
|
|
634
|
+
type: Directive,
|
|
635
|
+
args: [{
|
|
636
|
+
selector: '[cngxStepper]',
|
|
637
|
+
exportAs: 'cngxStepper',
|
|
638
|
+
standalone: true,
|
|
639
|
+
providers: [
|
|
640
|
+
{ provide: CNGX_STEPPER_HOST, useExisting: CngxStepperPresenter },
|
|
641
|
+
{ provide: CNGX_STATEFUL, useExisting: CngxStepperPresenter },
|
|
642
|
+
],
|
|
643
|
+
}]
|
|
644
|
+
}], propDecorators: { activeStepIndex: [{ type: i0.Input, args: [{ isSignal: true, alias: "activeStepIndex", required: false }] }, { type: i0.Output, args: ["activeStepIndexChange"] }], linearInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "linear", required: false }] }], orientationInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "orientation", required: false }] }], commitAction: [{ type: i0.Input, args: [{ isSignal: true, alias: "commitAction", required: false }] }], commitModeInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "commitMode", required: false }] }] } });
|
|
645
|
+
|
|
646
|
+
/**
|
|
647
|
+
* DI token providing a `CngxStepGroup`'s contract to nested `CngxStep` atoms.
|
|
648
|
+
* Steps inject this `optional: true` and fall back to {@link CNGX_STEPPER_HOST}.
|
|
649
|
+
*/
|
|
650
|
+
const CNGX_STEP_GROUP_HOST = new InjectionToken('CngxStepGroupHost');
|
|
651
|
+
|
|
652
|
+
/**
|
|
653
|
+
* DI token providing the rendering-surface contract to organism shells
|
|
654
|
+
* (`<cngx-stepper>`, `<cngx-mat-stepper>`) and consumer-authored skins.
|
|
655
|
+
*/
|
|
656
|
+
const CNGX_STEP_PANEL_HOST = new InjectionToken('CngxStepPanelHost');
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* Marker directive carrying a `CngxStep`'s content template.
|
|
660
|
+
* Discovered via `contentChild(CngxStepContent)`. Typed with
|
|
661
|
+
* {@link CngxStepContentContext} so `let-busy="busy"` etc. gives
|
|
662
|
+
* typed access to live step state.
|
|
663
|
+
*
|
|
664
|
+
* ```html
|
|
665
|
+
* <ng-template cngxStepContent let-busy="busy">
|
|
666
|
+
* <input [disabled]="busy">
|
|
667
|
+
* </ng-template>
|
|
668
|
+
* ```
|
|
669
|
+
*/
|
|
670
|
+
class CngxStepContent {
|
|
671
|
+
templateRef = inject(TemplateRef);
|
|
672
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStepContent, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
673
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxStepContent, isStandalone: true, selector: "ng-template[cngxStepContent]", ngImport: i0 });
|
|
674
|
+
}
|
|
675
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStepContent, decorators: [{
|
|
676
|
+
type: Directive,
|
|
677
|
+
args: [{
|
|
678
|
+
selector: 'ng-template[cngxStepContent]',
|
|
679
|
+
standalone: true,
|
|
680
|
+
}]
|
|
681
|
+
}] });
|
|
682
|
+
|
|
683
|
+
/**
|
|
684
|
+
* Marker directive carrying a `CngxStep`'s label template.
|
|
685
|
+
* Discovered via `contentChild(CngxStepLabel)`. Typed with
|
|
686
|
+
* {@link CngxStepLabelContext} for typed `let-node="node"` /
|
|
687
|
+
* `let-active="active"` access.
|
|
688
|
+
*
|
|
689
|
+
* ```html
|
|
690
|
+
* <ng-template cngxStepLabel let-node="node">
|
|
691
|
+
* {{ node.label() }}
|
|
692
|
+
* </ng-template>
|
|
693
|
+
* ```
|
|
694
|
+
*/
|
|
695
|
+
class CngxStepLabel {
|
|
696
|
+
templateRef = inject(TemplateRef);
|
|
697
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStepLabel, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
698
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxStepLabel, isStandalone: true, selector: "ng-template[cngxStepLabel]", ngImport: i0 });
|
|
699
|
+
}
|
|
700
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStepLabel, decorators: [{
|
|
701
|
+
type: Directive,
|
|
702
|
+
args: [{
|
|
703
|
+
selector: 'ng-template[cngxStepLabel]',
|
|
704
|
+
standalone: true,
|
|
705
|
+
}]
|
|
706
|
+
}] });
|
|
707
|
+
|
|
708
|
+
/**
|
|
709
|
+
* Single-step atom. Registers with the nearest host — either a
|
|
710
|
+
* `CngxStepGroup` ({@link CNGX_STEP_GROUP_HOST}) or the root
|
|
711
|
+
* `CngxStepperPresenter` ({@link CNGX_STEPPER_HOST}).
|
|
712
|
+
*
|
|
713
|
+
* `state` is a `linkedSignal` over `[disabled]`, `[completed]`, and
|
|
714
|
+
* the optional `[errorAggregator]`'s `hasError()`.
|
|
715
|
+
*/
|
|
716
|
+
class CngxStep {
|
|
717
|
+
id = input(nextUid('cngx-step'), ...(ngDevMode ? [{ debugName: "id" }] : /* istanbul ignore next */ []));
|
|
718
|
+
disabled = input(false, ...(ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []));
|
|
719
|
+
completed = input(false, ...(ngDevMode ? [{ debugName: "completed" }] : /* istanbul ignore next */ []));
|
|
720
|
+
label = input('', ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
|
|
721
|
+
errorAggregator = input(undefined, ...(ngDevMode ? [{ debugName: "errorAggregator" }] : /* istanbul ignore next */ []));
|
|
722
|
+
labelSlot = contentChild(CngxStepLabel, ...(ngDevMode ? [{ debugName: "labelSlot" }] : /* istanbul ignore next */ []));
|
|
723
|
+
contentSlot = contentChild(CngxStepContent, ...(ngDevMode ? [{ debugName: "contentSlot" }] : /* istanbul ignore next */ []));
|
|
724
|
+
labelTemplate = this.labelSlot;
|
|
725
|
+
contentTemplate = this.contentSlot;
|
|
726
|
+
/**
|
|
727
|
+
* Per-step status derived from inputs + aggregator. `linkedSignal`
|
|
728
|
+
* with structural equal — never written via `effect`.
|
|
729
|
+
*/
|
|
730
|
+
state = linkedSignal({ ...(ngDevMode ? { debugName: "state" } : /* istanbul ignore next */ {}), source: () => ({
|
|
731
|
+
disabled: this.disabled(),
|
|
732
|
+
completed: this.completed(),
|
|
733
|
+
errored: this.errorAggregator()?.hasError?.() ?? false,
|
|
734
|
+
}),
|
|
735
|
+
computation: ({ disabled, completed, errored }) => {
|
|
736
|
+
if (disabled) {
|
|
737
|
+
return 'disabled';
|
|
738
|
+
}
|
|
739
|
+
if (errored) {
|
|
740
|
+
return 'error';
|
|
741
|
+
}
|
|
742
|
+
if (completed) {
|
|
743
|
+
return 'success';
|
|
744
|
+
}
|
|
745
|
+
return 'idle';
|
|
746
|
+
},
|
|
747
|
+
equal: Object.is });
|
|
748
|
+
constructor() {
|
|
749
|
+
const groupHost = inject(CNGX_STEP_GROUP_HOST, { optional: true });
|
|
750
|
+
const stepperHost = inject(CNGX_STEPPER_HOST, { optional: true });
|
|
751
|
+
const host = groupHost ?? stepperHost;
|
|
752
|
+
if (!host) {
|
|
753
|
+
// No enclosing presenter or group — atom can't register. Fail loud.
|
|
754
|
+
throw new Error('CngxStep: no enclosing CngxStepperPresenter or CngxStepGroup found. ' +
|
|
755
|
+
'Wrap the step inside an element carrying [cngxStepper] or [cngxStepGroup].');
|
|
756
|
+
}
|
|
757
|
+
const stepId = this.id();
|
|
758
|
+
host.register({
|
|
759
|
+
id: stepId,
|
|
760
|
+
kind: 'step',
|
|
761
|
+
label: this.label,
|
|
762
|
+
disabled: this.disabled,
|
|
763
|
+
state: this.state,
|
|
764
|
+
errorAggregator: this.errorAggregator,
|
|
765
|
+
});
|
|
766
|
+
inject(DestroyRef).onDestroy(() => host.unregister(stepId));
|
|
767
|
+
}
|
|
768
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStep, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
769
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.2.0", version: "21.2.4", type: CngxStep, isStandalone: true, selector: "[cngxStep]", inputs: { id: { classPropertyName: "id", publicName: "id", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, completed: { classPropertyName: "completed", publicName: "completed", isSignal: true, isRequired: false, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, errorAggregator: { classPropertyName: "errorAggregator", publicName: "errorAggregator", isSignal: true, isRequired: false, transformFunction: null } }, queries: [{ propertyName: "labelSlot", first: true, predicate: CngxStepLabel, descendants: true, isSignal: true }, { propertyName: "contentSlot", first: true, predicate: CngxStepContent, descendants: true, isSignal: true }], exportAs: ["cngxStep"], ngImport: i0 });
|
|
770
|
+
}
|
|
771
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStep, decorators: [{
|
|
772
|
+
type: Directive,
|
|
773
|
+
args: [{
|
|
774
|
+
selector: '[cngxStep]',
|
|
775
|
+
exportAs: 'cngxStep',
|
|
776
|
+
standalone: true,
|
|
777
|
+
}]
|
|
778
|
+
}], ctorParameters: () => [], propDecorators: { id: [{ type: i0.Input, args: [{ isSignal: true, alias: "id", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], completed: [{ type: i0.Input, args: [{ isSignal: true, alias: "completed", required: false }] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], errorAggregator: [{ type: i0.Input, args: [{ isSignal: true, alias: "errorAggregator", required: false }] }], labelSlot: [{ type: i0.ContentChild, args: [i0.forwardRef(() => CngxStepLabel), { isSignal: true }] }], contentSlot: [{ type: i0.ContentChild, args: [i0.forwardRef(() => CngxStepContent), { isSignal: true }] }] } });
|
|
779
|
+
|
|
780
|
+
/**
|
|
781
|
+
* Step-group atom. Registers with the root presenter as a `kind: 'group'`
|
|
782
|
+
* node and provides {@link CNGX_STEP_GROUP_HOST} so nested `CngxStep`
|
|
783
|
+
* atoms register with the group, not the root.
|
|
784
|
+
*
|
|
785
|
+
* `aggregatedStatus` rolls up child states: `error` if any errored,
|
|
786
|
+
* `success` if all are success, `pending` if any is pending or busy,
|
|
787
|
+
* otherwise `idle`.
|
|
788
|
+
*/
|
|
789
|
+
class CngxStepGroup {
|
|
790
|
+
id = input(nextUid('cngx-step-group'), ...(ngDevMode ? [{ debugName: "id" }] : /* istanbul ignore next */ []));
|
|
791
|
+
disabled = input(false, ...(ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []));
|
|
792
|
+
label = input('', ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
|
|
793
|
+
// Local child registry — only feeds `aggregatedStatus` below.
|
|
794
|
+
// The presenter owns the canonical tree.
|
|
795
|
+
childRegistry = signal([], ...(ngDevMode ? [{ debugName: "childRegistry" }] : /* istanbul ignore next */ []));
|
|
796
|
+
aggregatedStatus = computed(() => {
|
|
797
|
+
const states = this.childRegistry().map((c) => c.state());
|
|
798
|
+
if (states.length === 0) {
|
|
799
|
+
return 'idle';
|
|
800
|
+
}
|
|
801
|
+
if (states.some((s) => s === 'error')) {
|
|
802
|
+
return 'error';
|
|
803
|
+
}
|
|
804
|
+
if (states.some((s) => s === 'pending' || s === 'busy')) {
|
|
805
|
+
return 'pending';
|
|
806
|
+
}
|
|
807
|
+
if (states.every((s) => s === 'success')) {
|
|
808
|
+
return 'success';
|
|
809
|
+
}
|
|
810
|
+
return 'idle';
|
|
811
|
+
}, { ...(ngDevMode ? { debugName: "aggregatedStatus" } : /* istanbul ignore next */ {}), equal: Object.is });
|
|
812
|
+
stepperHost = inject(CNGX_STEPPER_HOST, { optional: true });
|
|
813
|
+
constructor() {
|
|
814
|
+
if (!this.stepperHost) {
|
|
815
|
+
throw new Error('CngxStepGroup: no enclosing CngxStepperPresenter found. ' +
|
|
816
|
+
'Wrap the group inside an element carrying [cngxStepper].');
|
|
817
|
+
}
|
|
818
|
+
const groupId = this.id();
|
|
819
|
+
this.stepperHost.register({
|
|
820
|
+
id: groupId,
|
|
821
|
+
kind: 'group',
|
|
822
|
+
label: this.label,
|
|
823
|
+
disabled: this.disabled,
|
|
824
|
+
state: this.aggregatedStatus,
|
|
825
|
+
});
|
|
826
|
+
const stepperHost = this.stepperHost;
|
|
827
|
+
inject(DestroyRef).onDestroy(() => stepperHost.unregister(groupId));
|
|
828
|
+
}
|
|
829
|
+
register(handle) {
|
|
830
|
+
this.childRegistry.update((cur) => [...cur, handle]);
|
|
831
|
+
// Forward to the root with this group as parent so the tree shape is correct.
|
|
832
|
+
this.stepperHost.register(handle, this.id());
|
|
833
|
+
}
|
|
834
|
+
unregister(id) {
|
|
835
|
+
this.childRegistry.update((cur) => cur.filter((c) => c.id !== id));
|
|
836
|
+
this.stepperHost.unregister(id);
|
|
837
|
+
}
|
|
838
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStepGroup, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
839
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxStepGroup, isStandalone: true, selector: "[cngxStepGroup]", 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 } }, providers: [{ provide: CNGX_STEP_GROUP_HOST, useExisting: CngxStepGroup }], exportAs: ["cngxStepGroup"], ngImport: i0 });
|
|
840
|
+
}
|
|
841
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStepGroup, decorators: [{
|
|
842
|
+
type: Directive,
|
|
843
|
+
args: [{
|
|
844
|
+
selector: '[cngxStepGroup]',
|
|
845
|
+
exportAs: 'cngxStepGroup',
|
|
846
|
+
standalone: true,
|
|
847
|
+
providers: [{ provide: CNGX_STEP_GROUP_HOST, useExisting: CngxStepGroup }],
|
|
848
|
+
}]
|
|
849
|
+
}], 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 }] }] } });
|
|
850
|
+
|
|
851
|
+
/**
|
|
852
|
+
* Slot directive for the indicator-glyph template on `<cngx-stepper>`.
|
|
853
|
+
* Discovered via `contentChild`; cascades through
|
|
854
|
+
* `CNGX_STEPPER_CONFIG.templates.indicator` before falling back to
|
|
855
|
+
* the built-in numeric span (`{{ position }}`).
|
|
856
|
+
*
|
|
857
|
+
* ```html
|
|
858
|
+
* <cngx-stepper>
|
|
859
|
+
* <ng-template cngxStepIndicator let-position let-node="node" let-status="status">
|
|
860
|
+
* @if (status === 'success') {
|
|
861
|
+
* <my-icon name="check" />
|
|
862
|
+
* } @else if (status === 'error') {
|
|
863
|
+
* <my-icon name="alert" />
|
|
864
|
+
* } @else {
|
|
865
|
+
* <span class="my-step-num">{{ position }}</span>
|
|
866
|
+
* }
|
|
867
|
+
* </ng-template>
|
|
868
|
+
* </cngx-stepper>
|
|
869
|
+
* ```
|
|
870
|
+
*/
|
|
871
|
+
class CngxStepIndicator {
|
|
872
|
+
templateRef = inject(TemplateRef);
|
|
873
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStepIndicator, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
874
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxStepIndicator, isStandalone: true, selector: "ng-template[cngxStepIndicator]", exportAs: ["cngxStepIndicator"], ngImport: i0 });
|
|
875
|
+
}
|
|
876
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStepIndicator, decorators: [{
|
|
877
|
+
type: Directive,
|
|
878
|
+
args: [{
|
|
879
|
+
selector: 'ng-template[cngxStepIndicator]',
|
|
880
|
+
exportAs: 'cngxStepIndicator',
|
|
881
|
+
standalone: true,
|
|
882
|
+
}]
|
|
883
|
+
}] });
|
|
884
|
+
|
|
885
|
+
/**
|
|
886
|
+
* Slot directive for the error-badge template on `<cngx-stepper>`.
|
|
887
|
+
* Discovered via `contentChild`; cascades through
|
|
888
|
+
* `CNGX_STEPPER_CONFIG.templates.badge` before falling back to
|
|
889
|
+
* `CNGX_STEPPER_GLYPHS.errorBadge`.
|
|
890
|
+
*
|
|
891
|
+
* ```html
|
|
892
|
+
* <cngx-stepper>
|
|
893
|
+
* <ng-template cngxStepBadge let-count="count">
|
|
894
|
+
* <span class="my-badge-pill">{{ count }}</span>
|
|
895
|
+
* </ng-template>
|
|
896
|
+
* </cngx-stepper>
|
|
897
|
+
* ```
|
|
898
|
+
*/
|
|
899
|
+
class CngxStepBadge {
|
|
900
|
+
templateRef = inject(TemplateRef);
|
|
901
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStepBadge, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
902
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxStepBadge, isStandalone: true, selector: "ng-template[cngxStepBadge]", exportAs: ["cngxStepBadge"], ngImport: i0 });
|
|
903
|
+
}
|
|
904
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStepBadge, decorators: [{
|
|
905
|
+
type: Directive,
|
|
906
|
+
args: [{
|
|
907
|
+
selector: 'ng-template[cngxStepBadge]',
|
|
908
|
+
exportAs: 'cngxStepBadge',
|
|
909
|
+
standalone: true,
|
|
910
|
+
}]
|
|
911
|
+
}] });
|
|
912
|
+
|
|
913
|
+
/**
|
|
914
|
+
* Slot directive for the busy-spinner template on `<cngx-stepper>`.
|
|
915
|
+
* Discovered via `contentChild`; cascades through
|
|
916
|
+
* `CNGX_STEPPER_CONFIG.templates.busySpinner` before falling back to
|
|
917
|
+
* the built-in pulse-animation span.
|
|
918
|
+
*
|
|
919
|
+
* ```html
|
|
920
|
+
* <cngx-stepper>
|
|
921
|
+
* <ng-template cngxStepBusySpinner>
|
|
922
|
+
* <my-spinner size="sm" />
|
|
923
|
+
* </ng-template>
|
|
924
|
+
* </cngx-stepper>
|
|
925
|
+
* ```
|
|
926
|
+
*/
|
|
927
|
+
class CngxStepBusySpinner {
|
|
928
|
+
templateRef = inject(TemplateRef);
|
|
929
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStepBusySpinner, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
930
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxStepBusySpinner, isStandalone: true, selector: "ng-template[cngxStepBusySpinner]", exportAs: ["cngxStepBusySpinner"], ngImport: i0 });
|
|
931
|
+
}
|
|
932
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStepBusySpinner, decorators: [{
|
|
933
|
+
type: Directive,
|
|
934
|
+
args: [{
|
|
935
|
+
selector: 'ng-template[cngxStepBusySpinner]',
|
|
936
|
+
exportAs: 'cngxStepBusySpinner',
|
|
937
|
+
standalone: true,
|
|
938
|
+
}]
|
|
939
|
+
}] });
|
|
940
|
+
|
|
941
|
+
/**
|
|
942
|
+
* Slot directive for the rejection-decoration template on
|
|
943
|
+
* `<cngx-stepper>`. Discovered via `contentChild`; cascades through
|
|
944
|
+
* `CNGX_STEPPER_CONFIG.templates.rejection` before falling back to
|
|
945
|
+
* `CNGX_STEPPER_GLYPHS.rejectionIcon`.
|
|
946
|
+
*
|
|
947
|
+
* Symmetric context shape with the upcoming tabs `cngxTabRejectionIcon`
|
|
948
|
+
* slot so consumer templates port directly between the two families.
|
|
949
|
+
*
|
|
950
|
+
* ```html
|
|
951
|
+
* <cngx-stepper>
|
|
952
|
+
* <ng-template cngxStepRejection let-failedIndex="failedIndex" let-originLabel="originLabel">
|
|
953
|
+
* <my-icon name="rollback" />
|
|
954
|
+
* @if (originLabel) {
|
|
955
|
+
* <span class="cngx-sr-only">Rolled back to {{ originLabel }}</span>
|
|
956
|
+
* }
|
|
957
|
+
* </ng-template>
|
|
958
|
+
* </cngx-stepper>
|
|
959
|
+
* ```
|
|
960
|
+
*/
|
|
961
|
+
class CngxStepRejection {
|
|
962
|
+
templateRef = inject(TemplateRef);
|
|
963
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStepRejection, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
964
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxStepRejection, isStandalone: true, selector: "ng-template[cngxStepRejection]", exportAs: ["cngxStepRejection"], ngImport: i0 });
|
|
965
|
+
}
|
|
966
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStepRejection, decorators: [{
|
|
967
|
+
type: Directive,
|
|
968
|
+
args: [{
|
|
969
|
+
selector: 'ng-template[cngxStepRejection]',
|
|
970
|
+
exportAs: 'cngxStepRejection',
|
|
971
|
+
standalone: true,
|
|
972
|
+
}]
|
|
973
|
+
}] });
|
|
974
|
+
|
|
975
|
+
/**
|
|
976
|
+
* Slot directive for the group-header template on `<cngx-stepper>`.
|
|
977
|
+
* Discovered via `contentChild`; cascades through
|
|
978
|
+
* `CNGX_STEPPER_CONFIG.templates.groupHeader` before falling back to
|
|
979
|
+
* the built-in `<span class="cngx-stepper__group-label">`.
|
|
980
|
+
*
|
|
981
|
+
* ```html
|
|
982
|
+
* <cngx-stepper>
|
|
983
|
+
* <ng-template cngxStepGroupHeader let-group="group" let-status="status">
|
|
984
|
+
* <h4 [class.is-error]="status === 'error'">{{ group.label() }}</h4>
|
|
985
|
+
* </ng-template>
|
|
986
|
+
* </cngx-stepper>
|
|
987
|
+
* ```
|
|
988
|
+
*/
|
|
989
|
+
class CngxStepGroupHeader {
|
|
990
|
+
templateRef = inject(TemplateRef);
|
|
991
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStepGroupHeader, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
992
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxStepGroupHeader, isStandalone: true, selector: "ng-template[cngxStepGroupHeader]", exportAs: ["cngxStepGroupHeader"], ngImport: i0 });
|
|
993
|
+
}
|
|
994
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStepGroupHeader, decorators: [{
|
|
995
|
+
type: Directive,
|
|
996
|
+
args: [{
|
|
997
|
+
selector: 'ng-template[cngxStepGroupHeader]',
|
|
998
|
+
exportAs: 'cngxStepGroupHeader',
|
|
999
|
+
standalone: true,
|
|
1000
|
+
}]
|
|
1001
|
+
}] });
|
|
1002
|
+
|
|
1003
|
+
/**
|
|
1004
|
+
* Slot directive for the empty-state placeholder on `<cngx-stepper>`.
|
|
1005
|
+
* Rendered when `flatSteps()` is empty — async-loading or
|
|
1006
|
+
* server-driven step lists get a "no steps yet" landmark rather than
|
|
1007
|
+
* a collapsed strip.
|
|
1008
|
+
*
|
|
1009
|
+
* Discovered via `contentChild`; cascades through
|
|
1010
|
+
* `CNGX_STEPPER_CONFIG.templates.empty` before falling back to no
|
|
1011
|
+
* markup (Honest-Absence default).
|
|
1012
|
+
*
|
|
1013
|
+
* ```html
|
|
1014
|
+
* <cngx-stepper>
|
|
1015
|
+
* <ng-template cngxStepperEmpty>
|
|
1016
|
+
* <cngx-empty-state heading="No steps configured yet" />
|
|
1017
|
+
* </ng-template>
|
|
1018
|
+
* </cngx-stepper>
|
|
1019
|
+
* ```
|
|
1020
|
+
*/
|
|
1021
|
+
class CngxStepperEmpty {
|
|
1022
|
+
templateRef = inject(TemplateRef);
|
|
1023
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStepperEmpty, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1024
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxStepperEmpty, isStandalone: true, selector: "ng-template[cngxStepperEmpty]", exportAs: ["cngxStepperEmpty"], ngImport: i0 });
|
|
1025
|
+
}
|
|
1026
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStepperEmpty, decorators: [{
|
|
1027
|
+
type: Directive,
|
|
1028
|
+
args: [{
|
|
1029
|
+
selector: 'ng-template[cngxStepperEmpty]',
|
|
1030
|
+
exportAs: 'cngxStepperEmpty',
|
|
1031
|
+
standalone: true,
|
|
1032
|
+
}]
|
|
1033
|
+
}] });
|
|
1034
|
+
|
|
1035
|
+
/**
|
|
1036
|
+
* Wires the 3-stage template cascade for the six `<cngx-stepper>`
|
|
1037
|
+
* skin slots: per-instance directive > `CNGX_STEPPER_CONFIG.templates.<key>`
|
|
1038
|
+
* > `null` (built-in default).
|
|
1039
|
+
*
|
|
1040
|
+
* Pure — no DI, no side effects. Safe to call from a field-init
|
|
1041
|
+
* block. Sibling of `createTabOverflowTemplateBindings` and the
|
|
1042
|
+
* family-wide `createTemplateRegistry`.
|
|
1043
|
+
*
|
|
1044
|
+
* Tabs has no parallel slot surface yet — see
|
|
1045
|
+
* `stepper-accepted-debt §3` for the planned Phase-4 closure.
|
|
1046
|
+
*/
|
|
1047
|
+
function createStepperTemplateBindings(opts) {
|
|
1048
|
+
return {
|
|
1049
|
+
indicator: computed(() => opts.indicatorSlot()?.templateRef ??
|
|
1050
|
+
opts.config.templates?.indicator ??
|
|
1051
|
+
null),
|
|
1052
|
+
badge: computed(() => opts.badgeSlot()?.templateRef ??
|
|
1053
|
+
opts.config.templates?.badge ??
|
|
1054
|
+
null),
|
|
1055
|
+
busySpinner: computed(() => opts.busySpinnerSlot()?.templateRef ??
|
|
1056
|
+
opts.config.templates?.busySpinner ??
|
|
1057
|
+
null),
|
|
1058
|
+
rejection: computed(() => opts.rejectionSlot()?.templateRef ??
|
|
1059
|
+
opts.config.templates?.rejection ??
|
|
1060
|
+
null),
|
|
1061
|
+
groupHeader: computed(() => opts.groupHeaderSlot()?.templateRef ??
|
|
1062
|
+
opts.config.templates?.groupHeader ??
|
|
1063
|
+
null),
|
|
1064
|
+
empty: computed(() => opts.emptySlot()?.templateRef ??
|
|
1065
|
+
opts.config.templates?.empty ??
|
|
1066
|
+
null),
|
|
1067
|
+
};
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
/**
|
|
1071
|
+
* Default glyphs for `<cngx-stepper>` skin slots. Used when neither a
|
|
1072
|
+
* per-instance slot directive nor `CNGX_STEPPER_CONFIG.templates.<key>`
|
|
1073
|
+
* overrides the built-in span. Sibling of `CNGX_SELECT_GLYPHS` /
|
|
1074
|
+
* `CNGX_TABS_GLYPHS`.
|
|
1075
|
+
*
|
|
1076
|
+
* Exported with `@internal` so the organism (and mat-twin) can share
|
|
1077
|
+
* the literals across the secondary-entry boundary that Sheriff
|
|
1078
|
+
* forbids deep-relative imports across. Consumers customise via
|
|
1079
|
+
* `*cngxStep*` slots or `withStep*Template` features.
|
|
1080
|
+
*
|
|
1081
|
+
* @internal
|
|
1082
|
+
*/
|
|
1083
|
+
const CNGX_STEPPER_GLYPHS = {
|
|
1084
|
+
/** Default visual for `*cngxStepBadge` when no override is bound. */
|
|
1085
|
+
errorBadge: '!',
|
|
1086
|
+
/** Default visual for `*cngxStepRejection` when no override is bound. */
|
|
1087
|
+
rejectionIcon: '!',
|
|
1088
|
+
};
|
|
1089
|
+
|
|
1090
|
+
/**
|
|
1091
|
+
* URL deep-linking for the stepper. Bidirectional sync between
|
|
1092
|
+
* `activeStepId` and a URL fragment / query-param. Opt-in via
|
|
1093
|
+
* `[cngxStepperRouterSync]` on the presenter element.
|
|
1094
|
+
*
|
|
1095
|
+
* - `mode = 'fragment'` (default) → `#step=customer`
|
|
1096
|
+
* - `mode = 'queryParam'` with `paramName = 'step'` → `?step=customer`
|
|
1097
|
+
*
|
|
1098
|
+
* `Router` is optional — without `@angular/router` the directive
|
|
1099
|
+
* dev-warns once and becomes a no-op.
|
|
1100
|
+
*/
|
|
1101
|
+
class CngxStepperRouterSync {
|
|
1102
|
+
// Default undefined so the cascade resolves through CNGX_STEPPER_CONFIG.
|
|
1103
|
+
modeInput = input(undefined, { ...(ngDevMode ? { debugName: "modeInput" } : /* istanbul ignore next */ {}), alias: 'mode' });
|
|
1104
|
+
paramNameInput = input(undefined, { ...(ngDevMode ? { debugName: "paramNameInput" } : /* istanbul ignore next */ {}), alias: 'paramName' });
|
|
1105
|
+
config = injectStepperConfig();
|
|
1106
|
+
mode = computed(() => this.modeInput() ?? this.config.routerSyncMode ?? 'fragment', ...(ngDevMode ? [{ debugName: "mode" }] : /* istanbul ignore next */ []));
|
|
1107
|
+
paramName = computed(() => this.paramNameInput() ?? this.config.routerSyncParam ?? 'step', ...(ngDevMode ? [{ debugName: "paramName" }] : /* istanbul ignore next */ []));
|
|
1108
|
+
/** Emits when a `router.navigate` rejection is observed. */
|
|
1109
|
+
syncError = output();
|
|
1110
|
+
host = inject(CNGX_STEPPER_HOST, { host: true });
|
|
1111
|
+
router = inject(Router, { optional: true });
|
|
1112
|
+
constructor() {
|
|
1113
|
+
if (!this.router) {
|
|
1114
|
+
afterNextRender(() => {
|
|
1115
|
+
console.warn('CngxStepperRouterSync: no Router available — directive is a no-op. ' +
|
|
1116
|
+
'Provide @angular/router via provideRouter(...) to enable deep-linking.');
|
|
1117
|
+
});
|
|
1118
|
+
return;
|
|
1119
|
+
}
|
|
1120
|
+
const router = this.router;
|
|
1121
|
+
afterNextRender(() => {
|
|
1122
|
+
const initial = this.mode() === 'fragment'
|
|
1123
|
+
? router.routerState.snapshot.root.fragment
|
|
1124
|
+
: (router.routerState.snapshot.root.queryParamMap.get(this.paramName()) ?? null);
|
|
1125
|
+
if (initial) {
|
|
1126
|
+
const value = this.mode() === 'fragment' ? this.parseFragment(initial) : initial;
|
|
1127
|
+
if (value) {
|
|
1128
|
+
this.host.selectById(value);
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
});
|
|
1132
|
+
effect(() => {
|
|
1133
|
+
const id = this.host.activeStepId();
|
|
1134
|
+
if (!id) {
|
|
1135
|
+
return;
|
|
1136
|
+
}
|
|
1137
|
+
untracked(() => {
|
|
1138
|
+
const navigation = this.mode() === 'fragment'
|
|
1139
|
+
? router.navigate([], {
|
|
1140
|
+
fragment: `${this.paramName()}=${id}`,
|
|
1141
|
+
queryParamsHandling: 'merge',
|
|
1142
|
+
replaceUrl: true,
|
|
1143
|
+
})
|
|
1144
|
+
: router.navigate([], {
|
|
1145
|
+
queryParams: { [this.paramName()]: id },
|
|
1146
|
+
queryParamsHandling: 'merge',
|
|
1147
|
+
replaceUrl: true,
|
|
1148
|
+
});
|
|
1149
|
+
navigation.catch?.((err) => this.syncError.emit(err));
|
|
1150
|
+
});
|
|
1151
|
+
});
|
|
1152
|
+
const navEnd = toSignal(router.events.pipe(filter((e) => e instanceof NavigationEnd), takeUntilDestroyed(inject(DestroyRef))), { initialValue: null });
|
|
1153
|
+
effect(() => {
|
|
1154
|
+
const e = navEnd();
|
|
1155
|
+
if (!e) {
|
|
1156
|
+
return;
|
|
1157
|
+
}
|
|
1158
|
+
untracked(() => {
|
|
1159
|
+
const next = this.mode() === 'fragment'
|
|
1160
|
+
? this.parseFragment(router.routerState.snapshot.root.fragment ?? '')
|
|
1161
|
+
: (router.routerState.snapshot.root.queryParamMap.get(this.paramName()) ?? null);
|
|
1162
|
+
if (next && next !== this.host.activeStepId()) {
|
|
1163
|
+
this.host.selectById(next);
|
|
1164
|
+
}
|
|
1165
|
+
});
|
|
1166
|
+
});
|
|
1167
|
+
}
|
|
1168
|
+
parseFragment(fragment) {
|
|
1169
|
+
const param = this.paramName();
|
|
1170
|
+
const segments = fragment.split('&');
|
|
1171
|
+
for (const seg of segments) {
|
|
1172
|
+
const [key, val] = seg.split('=');
|
|
1173
|
+
if (key === param && val) {
|
|
1174
|
+
return val;
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
return null;
|
|
1178
|
+
}
|
|
1179
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStepperRouterSync, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1180
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxStepperRouterSync, isStandalone: true, selector: "[cngxStepperRouterSync]", inputs: { modeInput: { classPropertyName: "modeInput", publicName: "mode", isSignal: true, isRequired: false, transformFunction: null }, paramNameInput: { classPropertyName: "paramNameInput", publicName: "paramName", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { syncError: "syncError" }, exportAs: ["cngxStepperRouterSync"], ngImport: i0 });
|
|
1181
|
+
}
|
|
1182
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStepperRouterSync, decorators: [{
|
|
1183
|
+
type: Directive,
|
|
1184
|
+
args: [{
|
|
1185
|
+
selector: '[cngxStepperRouterSync]',
|
|
1186
|
+
exportAs: 'cngxStepperRouterSync',
|
|
1187
|
+
standalone: true,
|
|
1188
|
+
}]
|
|
1189
|
+
}], ctorParameters: () => [], propDecorators: { modeInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "mode", required: false }] }], paramNameInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "paramName", required: false }] }], syncError: [{ type: i0.Output, args: ["syncError"] }] } });
|
|
1190
|
+
|
|
1191
|
+
const STEPPER_I18N_DEFAULTS = {
|
|
1192
|
+
stepperLabel: 'Stepper',
|
|
1193
|
+
selectedStep: (label, position, count) => `Step ${position} of ${count}: ${label}`,
|
|
1194
|
+
stepCompleted: 'Completed',
|
|
1195
|
+
stepErrored: 'Has errors',
|
|
1196
|
+
stepHasErrors: (count) => `${count} error${count === 1 ? '' : 's'}`,
|
|
1197
|
+
previousStep: 'Previous step',
|
|
1198
|
+
nextStep: 'Next step',
|
|
1199
|
+
commitFailedRetry: 'Commit failed — retry?',
|
|
1200
|
+
commitInFlight: 'Committing step…',
|
|
1201
|
+
commitRolledBackTo: (originLabel) => `Reverted to step "${originLabel}".`,
|
|
1202
|
+
stepRolledBackSuffix: 'This step was rolled back.',
|
|
1203
|
+
};
|
|
1204
|
+
/**
|
|
1205
|
+
* DI token for the resolved stepper i18n bundle. `providedIn: 'root'`
|
|
1206
|
+
* with English defaults.
|
|
1207
|
+
*/
|
|
1208
|
+
const CNGX_STEPPER_I18N = new InjectionToken('CngxStepperI18n', { providedIn: 'root', factory: () => STEPPER_I18N_DEFAULTS });
|
|
1209
|
+
/**
|
|
1210
|
+
* Brands an i18n mutator with `_target: 'i18n'`. Every `with*` i18n
|
|
1211
|
+
* feature returns one of these.
|
|
1212
|
+
*
|
|
1213
|
+
* @internal
|
|
1214
|
+
*/
|
|
1215
|
+
function defineStepperI18nFeature(fn) {
|
|
1216
|
+
return Object.assign(fn, { _target: 'i18n' });
|
|
1217
|
+
}
|
|
1218
|
+
/**
|
|
1219
|
+
* Override stepper i18n labels. Partial override — unset keys keep
|
|
1220
|
+
* the English default. Sibling of `withStepperAriaLabels` /
|
|
1221
|
+
* `withStepperFallbackLabels`.
|
|
1222
|
+
*/
|
|
1223
|
+
function withStepperI18nLabels(overrides) {
|
|
1224
|
+
return defineStepperI18nFeature((bundle) => ({ ...bundle, ...overrides }));
|
|
1225
|
+
}
|
|
1226
|
+
function resolveI18nFeatures(features) {
|
|
1227
|
+
return features.reduce((bundle, feat) => feat(bundle), STEPPER_I18N_DEFAULTS);
|
|
1228
|
+
}
|
|
1229
|
+
/**
|
|
1230
|
+
* Provider for the stepper i18n bundle. Compose `withStepperI18nLabels(...)`
|
|
1231
|
+
* (plus any future i18n `with*`) — unset keys fall back to English.
|
|
1232
|
+
*
|
|
1233
|
+
* ```ts
|
|
1234
|
+
* bootstrapApplication(AppComponent, {
|
|
1235
|
+
* providers: [
|
|
1236
|
+
* provideStepperI18n(
|
|
1237
|
+
* withStepperI18nLabels({ stepperLabel: 'Schrittfolge', previousStep: 'Vorheriger' }),
|
|
1238
|
+
* ),
|
|
1239
|
+
* ],
|
|
1240
|
+
* });
|
|
1241
|
+
* ```
|
|
1242
|
+
*/
|
|
1243
|
+
function provideStepperI18n(...features) {
|
|
1244
|
+
return {
|
|
1245
|
+
provide: CNGX_STEPPER_I18N,
|
|
1246
|
+
useValue: resolveI18nFeatures(features),
|
|
1247
|
+
};
|
|
1248
|
+
}
|
|
1249
|
+
/**
|
|
1250
|
+
* Inject the resolved stepper i18n bundle in an injection context.
|
|
1251
|
+
*/
|
|
1252
|
+
function injectStepperI18n() {
|
|
1253
|
+
return inject(CNGX_STEPPER_I18N);
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
function partitionFeatures(features) {
|
|
1257
|
+
const config = [];
|
|
1258
|
+
const i18n = [];
|
|
1259
|
+
for (const feat of features) {
|
|
1260
|
+
if (feat._target === 'i18n') {
|
|
1261
|
+
i18n.push(feat);
|
|
1262
|
+
continue;
|
|
1263
|
+
}
|
|
1264
|
+
if (feat._target === 'config') {
|
|
1265
|
+
config.push(feat);
|
|
1266
|
+
continue;
|
|
1267
|
+
}
|
|
1268
|
+
// Unbranded feature — drop + dev-warn (mirrors `provideCngxTabs`).
|
|
1269
|
+
if (isDevMode()) {
|
|
1270
|
+
console.warn('[provideCngxStepper] Dropped feature without a `_target` ' +
|
|
1271
|
+
'discriminator. Brand config-side mutators with ' +
|
|
1272
|
+
'`defineStepperConfigFeature(...)` (or use a `with*` helper) ' +
|
|
1273
|
+
'and i18n-side mutators with `withStepperI18nLabels(...)`.');
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
return { config, i18n };
|
|
1277
|
+
}
|
|
1278
|
+
/**
|
|
1279
|
+
* Unified aggregator for the stepper family. Filters by `_target` and
|
|
1280
|
+
* forwards: config features to {@link provideStepperConfig}, i18n
|
|
1281
|
+
* features to {@link provideStepperI18n}. Mirrors `provideCngxTabs` /
|
|
1282
|
+
* `provideCngxSelect`.
|
|
1283
|
+
*
|
|
1284
|
+
* Returns {@link EnvironmentProviders} for app-root use; the
|
|
1285
|
+
* component-scoped twin {@link provideCngxStepperAt} returns
|
|
1286
|
+
* `Provider[]` because `viewProviders` cannot accept opaque
|
|
1287
|
+
* `EnvironmentProviders`.
|
|
1288
|
+
*
|
|
1289
|
+
* ```ts
|
|
1290
|
+
* bootstrapApplication(AppComponent, {
|
|
1291
|
+
* providers: [
|
|
1292
|
+
* provideCngxStepper(
|
|
1293
|
+
* withStepperDefaultOrientation('vertical'),
|
|
1294
|
+
* withStepperLinear(true),
|
|
1295
|
+
* withStepperAriaLabels({ stepperRegion: 'Schrittfolge' }),
|
|
1296
|
+
* withStepperI18nLabels({ stepperLabel: 'Schrittfolge', previousStep: 'Vorheriger' }),
|
|
1297
|
+
* ),
|
|
1298
|
+
* ],
|
|
1299
|
+
* });
|
|
1300
|
+
* ```
|
|
1301
|
+
*/
|
|
1302
|
+
function provideCngxStepper(...features) {
|
|
1303
|
+
const { config, i18n } = partitionFeatures(features);
|
|
1304
|
+
// `provideStepperConfig` returns EnvironmentProviders, `provideStepperI18n`
|
|
1305
|
+
// returns Provider — `makeEnvironmentProviders` takes both.
|
|
1306
|
+
return makeEnvironmentProviders([
|
|
1307
|
+
provideStepperConfig(...config),
|
|
1308
|
+
...(i18n.length > 0 ? [provideStepperI18n(...i18n)] : []),
|
|
1309
|
+
]);
|
|
1310
|
+
}
|
|
1311
|
+
/**
|
|
1312
|
+
* Component-scoped twin of {@link provideCngxStepper}. Spread into
|
|
1313
|
+
* `viewProviders` or `providers`. Same dispatch semantics — only the
|
|
1314
|
+
* provider scope differs.
|
|
1315
|
+
*
|
|
1316
|
+
* ```ts
|
|
1317
|
+
* @Component({
|
|
1318
|
+
* viewProviders: [
|
|
1319
|
+
* ...provideCngxStepperAt(
|
|
1320
|
+
* withStepperDefaultOrientation('vertical'),
|
|
1321
|
+
* withStepperI18nLabels({ stepperLabel: 'Schrittfolge' }),
|
|
1322
|
+
* ),
|
|
1323
|
+
* ],
|
|
1324
|
+
* })
|
|
1325
|
+
* ```
|
|
1326
|
+
*/
|
|
1327
|
+
function provideCngxStepperAt(...features) {
|
|
1328
|
+
const { config, i18n } = partitionFeatures(features);
|
|
1329
|
+
return [
|
|
1330
|
+
...provideStepperConfigAt(...config),
|
|
1331
|
+
...(i18n.length > 0 ? [provideStepperI18n(...i18n)] : []),
|
|
1332
|
+
];
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
/**
|
|
1336
|
+
* @module @cngx/common/stepper
|
|
1337
|
+
*
|
|
1338
|
+
* Level-2 directive-only logic for stepper / wizard flows. Ships the
|
|
1339
|
+
* presenter brain, atom directives, host tokens, router-sync, config
|
|
1340
|
+
* cascade, and i18n. Zero `@Component`, zero `.html`, zero `.css` —
|
|
1341
|
+
* those live in `@cngx/ui/stepper` (CNGX-standard skin) and
|
|
1342
|
+
* `@cngx/ui/mat-stepper` (Material twin).
|
|
1343
|
+
*/
|
|
1344
|
+
|
|
1345
|
+
/**
|
|
1346
|
+
* Generated bundle index. Do not edit.
|
|
1347
|
+
*/
|
|
1348
|
+
|
|
1349
|
+
export { CNGX_STEPPER_COMMIT_HANDLER_FACTORY, CNGX_STEPPER_CONFIG, CNGX_STEPPER_GLYPHS, CNGX_STEPPER_HOST, CNGX_STEPPER_I18N, CNGX_STEP_GROUP_HOST, CNGX_STEP_PANEL_HOST, CngxStep, CngxStepBadge, CngxStepBusySpinner, CngxStepContent, CngxStepGroup, CngxStepGroupHeader, CngxStepIndicator, CngxStepLabel, CngxStepRejection, CngxStepperEmpty, CngxStepperPresenter, CngxStepperRouterSync, createStepperCommitHandler, createStepperTemplateBindings, flatStepsEqual, injectStepperConfig, injectStepperI18n, provideCngxStepper, provideCngxStepperAt, provideStepperConfig, provideStepperConfigAt, provideStepperI18n, withStepBadgeTemplate, withStepBusySpinnerTemplate, withStepGroupHeaderTemplate, withStepIndicatorTemplate, withStepRejectionTemplate, withStepperAriaLabels, withStepperCommitMode, withStepperDefaultOrientation, withStepperEmptyTemplate, withStepperFallbackLabels, withStepperI18nLabels, withStepperLinear, withStepperRouterSync };
|
|
1350
|
+
//# sourceMappingURL=cngx-common-stepper.mjs.map
|