@cngx/common 0.0.1-rc.0 → 0.1.0-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/a11y/README.md +13 -16
- package/card/README.md +2 -21
- package/chart/README.md +5 -8
- package/data/README.md +45 -47
- package/dialog/README.md +12 -15
- package/display/README.md +5 -9
- package/fesm2022/cngx-common-a11y.mjs +140 -40
- package/fesm2022/cngx-common-a11y.mjs.map +1 -1
- package/fesm2022/cngx-common-card.mjs +157 -69
- package/fesm2022/cngx-common-card.mjs.map +1 -1
- package/fesm2022/cngx-common-chart.mjs +389 -92
- package/fesm2022/cngx-common-chart.mjs.map +1 -1
- package/fesm2022/cngx-common-data.mjs +311 -151
- package/fesm2022/cngx-common-data.mjs.map +1 -1
- package/fesm2022/cngx-common-dialog.mjs +167 -29
- package/fesm2022/cngx-common-dialog.mjs.map +1 -1
- package/fesm2022/cngx-common-display.mjs +445 -110
- package/fesm2022/cngx-common-display.mjs.map +1 -1
- package/fesm2022/cngx-common-interactive.mjs +2025 -435
- package/fesm2022/cngx-common-interactive.mjs.map +1 -1
- package/fesm2022/cngx-common-layout.mjs +188 -31
- package/fesm2022/cngx-common-layout.mjs.map +1 -1
- package/fesm2022/cngx-common-popover.mjs +711 -90
- package/fesm2022/cngx-common-popover.mjs.map +1 -1
- package/fesm2022/cngx-common-stepper.mjs +1258 -60
- package/fesm2022/cngx-common-stepper.mjs.map +1 -1
- package/fesm2022/cngx-common-tabs.mjs +247 -41
- package/fesm2022/cngx-common-tabs.mjs.map +1 -1
- package/fesm2022/cngx-common.mjs +2 -2
- package/fesm2022/cngx-common.mjs.map +1 -1
- package/interactive/README.md +5 -5
- package/layout/README.md +2 -2
- package/package.json +5 -4
- package/popover/README.md +8 -34
- package/stepper/README.md +49 -8
- package/tabs/README.md +6 -6
- package/theming/components/cngx-async.css +74 -0
- package/theming/components/cngx-backdrop.css +73 -0
- package/theming/components/cngx-badge.css +340 -0
- package/theming/components/cngx-bottom-sheet.css +201 -0
- package/theming/components/cngx-button-toggle.css +99 -0
- package/theming/components/cngx-dialog.css +358 -0
- package/theming/components/cngx-divider.css +145 -0
- package/theming/components/cngx-listbox.css +220 -0
- package/theming/components/cngx-menu.css +371 -0
- package/theming/components/cngx-ripple.css +116 -0
- package/theming/components/cngx-tooltip.css +265 -0
- package/theming/system-tokens.css +24 -0
- package/types/cngx-common-a11y.d.ts +136 -36
- package/types/cngx-common-card.d.ts +137 -22
- package/types/cngx-common-chart.d.ts +337 -40
- package/types/cngx-common-data.d.ts +277 -45
- package/types/cngx-common-dialog.d.ts +162 -22
- package/types/cngx-common-display.d.ts +422 -78
- package/types/cngx-common-interactive.d.ts +1862 -305
- package/types/cngx-common-layout.d.ts +191 -28
- package/types/cngx-common-popover.d.ts +632 -87
- package/types/cngx-common-stepper.d.ts +1110 -38
- package/types/cngx-common-tabs.d.ts +306 -32
- package/types/cngx-common.d.ts +1 -1
- package/README.md +0 -18
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { InjectionToken, makeEnvironmentProviders, inject, model, input, computed, signal, Directive, TemplateRef, contentChild, linkedSignal, DestroyRef, output,
|
|
2
|
+
import { InjectionToken, makeEnvironmentProviders, inject, model, input, computed, signal, isDevMode, afterNextRender, Directive, TemplateRef, contentChild, linkedSignal, DestroyRef, output, effect, untracked, ViewEncapsulation, ChangeDetectionStrategy, Component } from '@angular/core';
|
|
3
3
|
import { CNGX_COMMIT_CONTROLLER_FACTORY } from '@cngx/common/data';
|
|
4
|
-
import { createTransitionTracker, CNGX_STATEFUL, nextUid } from '@cngx/core/utils';
|
|
4
|
+
import { createTransitionTracker, CNGX_STATEFUL, nextUid, buildAsyncStateView } from '@cngx/core/utils';
|
|
5
5
|
import { isObservable } from 'rxjs';
|
|
6
6
|
import { toSignal, takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
7
7
|
import { Router, NavigationEnd } from '@angular/router';
|
|
8
8
|
import { filter } from 'rxjs/operators';
|
|
9
|
+
import * as i1 from '@cngx/common/interactive';
|
|
10
|
+
import { CngxAsyncClick } from '@cngx/common/interactive';
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
13
|
* Build a stepper commit handler over an existing {@link CngxCommitController}.
|
|
12
14
|
* Resolves `Observable<boolean>` / `Promise<boolean>` / `boolean` returns into
|
|
13
15
|
* a unified `accept: boolean` outcome.
|
|
16
|
+
*
|
|
17
|
+
* @category common/stepper
|
|
14
18
|
*/
|
|
15
19
|
function createStepperCommitHandler(opts) {
|
|
16
20
|
const { controller } = opts;
|
|
@@ -27,6 +31,7 @@ function createStepperCommitHandler(opts) {
|
|
|
27
31
|
},
|
|
28
32
|
};
|
|
29
33
|
}
|
|
34
|
+
/** @internal */
|
|
30
35
|
function runStepperAction(action, fromIndex, toIndex, handlers) {
|
|
31
36
|
let cancelled = false;
|
|
32
37
|
let unsubscribe = null;
|
|
@@ -53,11 +58,15 @@ function runStepperAction(action, fromIndex, toIndex, handlers) {
|
|
|
53
58
|
}
|
|
54
59
|
catch (err) {
|
|
55
60
|
safeError(err);
|
|
56
|
-
return {
|
|
61
|
+
return {
|
|
62
|
+
cancel: () => {
|
|
63
|
+
cancelled = true;
|
|
64
|
+
},
|
|
65
|
+
};
|
|
57
66
|
}
|
|
58
67
|
if (isObservable(result)) {
|
|
59
68
|
// Synchronous Observables (`of(true)`) emit inside `.subscribe`
|
|
60
|
-
// before the assignment binds
|
|
69
|
+
// before the assignment binds - `sub` would be in TDZ. Declare
|
|
61
70
|
// the handle on a `let` first.
|
|
62
71
|
let sub = null;
|
|
63
72
|
sub = result.subscribe({
|
|
@@ -85,18 +94,38 @@ function runStepperAction(action, fromIndex, toIndex, handlers) {
|
|
|
85
94
|
/**
|
|
86
95
|
* DI token carrying the factory the presenter uses to allocate its commit
|
|
87
96
|
* handler. Symmetric to the select family's `CNGX_ARRAY_COMMIT_HANDLER_FACTORY`.
|
|
97
|
+
*
|
|
98
|
+
* @category common/stepper
|
|
99
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/stepper/commit-handler.ts
|
|
100
|
+
* @since 0.1.0
|
|
88
101
|
*/
|
|
89
102
|
const CNGX_STEPPER_COMMIT_HANDLER_FACTORY = new InjectionToken('CngxStepperCommitHandlerFactory', {
|
|
90
103
|
providedIn: 'root',
|
|
91
104
|
factory: () => createStepperCommitHandler,
|
|
92
105
|
});
|
|
93
106
|
|
|
107
|
+
/**
|
|
108
|
+
* Default media query the mobile auto-collapse policy reacts to. The
|
|
109
|
+
* literal lives on a single exported const so the runtime, the config
|
|
110
|
+
* default, and any JSDoc cross-references stay in lockstep. Consumers
|
|
111
|
+
* override the query via {@link withStepperMobileBreakpoint}.
|
|
112
|
+
*
|
|
113
|
+
* @category common/stepper
|
|
114
|
+
*/
|
|
115
|
+
const STEPPER_DEFAULT_MOBILE_BREAKPOINT = '(max-width: 480px)';
|
|
116
|
+
/** @internal */
|
|
94
117
|
const STEPPER_CONFIG_DEFAULTS = {
|
|
95
118
|
defaultOrientation: 'horizontal',
|
|
96
119
|
defaultLinear: false,
|
|
97
120
|
defaultCommitMode: 'pessimistic',
|
|
98
121
|
routerSyncMode: 'fragment',
|
|
99
122
|
routerSyncParam: 'step',
|
|
123
|
+
skin: 'classic',
|
|
124
|
+
connectors: false,
|
|
125
|
+
mobileCollapse: 'text',
|
|
126
|
+
mobileBreakpoint: STEPPER_DEFAULT_MOBILE_BREAKPOINT,
|
|
127
|
+
mobileIndicatorPosition: 'top',
|
|
128
|
+
mobileSwipe: true,
|
|
100
129
|
ariaLabels: {
|
|
101
130
|
stepperRegion: 'Stepper',
|
|
102
131
|
},
|
|
@@ -110,8 +139,16 @@ const STEPPER_CONFIG_DEFAULTS = {
|
|
|
110
139
|
* DI token for the resolved stepper config. `providedIn: 'root'` with
|
|
111
140
|
* library defaults; override via {@link provideStepperConfig} (root)
|
|
112
141
|
* or {@link provideStepperConfigAt} (component scope).
|
|
142
|
+
*
|
|
143
|
+
* @category common/stepper
|
|
144
|
+
* @wcag AA
|
|
145
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/stepper/stepper-config.ts
|
|
146
|
+
* @since 0.1.0
|
|
113
147
|
*/
|
|
114
|
-
const CNGX_STEPPER_CONFIG = new InjectionToken('CngxStepperConfig', {
|
|
148
|
+
const CNGX_STEPPER_CONFIG = new InjectionToken('CngxStepperConfig', {
|
|
149
|
+
providedIn: 'root',
|
|
150
|
+
factory: () => STEPPER_CONFIG_DEFAULTS,
|
|
151
|
+
});
|
|
115
152
|
/**
|
|
116
153
|
* Brands a config mutator with `_target: 'config'`. Every `with*`
|
|
117
154
|
* config feature returns one of these.
|
|
@@ -124,6 +161,8 @@ function defineStepperConfigFeature(fn) {
|
|
|
124
161
|
/**
|
|
125
162
|
* Override the default orientation. Per-instance `[orientation]`
|
|
126
163
|
* Input still wins; this only moves the cascade default.
|
|
164
|
+
*
|
|
165
|
+
* @category common/stepper
|
|
127
166
|
*/
|
|
128
167
|
function withStepperDefaultOrientation(orientation) {
|
|
129
168
|
return defineStepperConfigFeature((cfg) => ({
|
|
@@ -134,6 +173,8 @@ function withStepperDefaultOrientation(orientation) {
|
|
|
134
173
|
/**
|
|
135
174
|
* Override the default linear-progression setting. Per-instance
|
|
136
175
|
* `[linear]` Input still wins.
|
|
176
|
+
*
|
|
177
|
+
* @category common/stepper
|
|
137
178
|
*/
|
|
138
179
|
function withStepperLinear(linear) {
|
|
139
180
|
return defineStepperConfigFeature((cfg) => ({ ...cfg, defaultLinear: linear }));
|
|
@@ -143,6 +184,8 @@ function withStepperLinear(linear) {
|
|
|
143
184
|
* `'optimistic'` advances on action dispatch and rolls back on error;
|
|
144
185
|
* `'pessimistic'` waits for success. Per-instance `[commitMode]`
|
|
145
186
|
* Input still wins.
|
|
187
|
+
*
|
|
188
|
+
* @category common/stepper
|
|
146
189
|
*/
|
|
147
190
|
function withStepperCommitMode(mode) {
|
|
148
191
|
return defineStepperConfigFeature((cfg) => ({
|
|
@@ -154,6 +197,8 @@ function withStepperCommitMode(mode) {
|
|
|
154
197
|
* Configure router synchronisation for the active step. `mode` chooses
|
|
155
198
|
* the URL surface (URL fragment or query parameter); `param` names the
|
|
156
199
|
* key (default `'step'`).
|
|
200
|
+
*
|
|
201
|
+
* @category common/stepper
|
|
157
202
|
*/
|
|
158
203
|
function withStepperRouterSync(mode, param = 'step') {
|
|
159
204
|
return defineStepperConfigFeature((cfg) => ({
|
|
@@ -162,9 +207,84 @@ function withStepperRouterSync(mode, param = 'step') {
|
|
|
162
207
|
routerSyncParam: param,
|
|
163
208
|
}));
|
|
164
209
|
}
|
|
210
|
+
/**
|
|
211
|
+
* Select the visual skin for the cngx-standard `<cngx-stepper>`. The
|
|
212
|
+
* default is `'classic'`. Per-instance `[skin]` Input still wins; this
|
|
213
|
+
* moves the cascade default. Structure, slots, ARIA, and keyboard
|
|
214
|
+
* behaviour are identical across skins - only the `[data-skin]` host
|
|
215
|
+
* attribute changes the CSS layer that paints the strip.
|
|
216
|
+
*
|
|
217
|
+
* @category common/stepper
|
|
218
|
+
*/
|
|
219
|
+
function withStepperSkin(skin) {
|
|
220
|
+
return defineStepperConfigFeature((cfg) => ({ ...cfg, skin }));
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Opt the classic `<cngx-stepper>` skin into the connector-rail
|
|
224
|
+
* presentation: a solid completed/upcoming rail between adjacent step
|
|
225
|
+
* indicators, horizontal and vertical, with per-segment coloring driven
|
|
226
|
+
* by the preceding step's `[data-state]`. The rule is double-scoped on
|
|
227
|
+
* `[data-skin='classic']`; the four other skins each ship their own
|
|
228
|
+
* inter-step decoration and ignore this flag. Per-instance
|
|
229
|
+
* `[connectors]` Input still wins.
|
|
230
|
+
*
|
|
231
|
+
* @category common/stepper
|
|
232
|
+
*/
|
|
233
|
+
function withStepperConnectors(on) {
|
|
234
|
+
return defineStepperConfigFeature((cfg) => ({ ...cfg, connectors: on }));
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Configure the mobile auto-collapse target for `<cngx-stepper>`. Under
|
|
238
|
+
* a narrow viewport (`max-width: 480px`), the classic strip swaps to
|
|
239
|
+
* the chosen variant - `'text'` (default) renders `<cngx-text-stepper>`,
|
|
240
|
+
* `'dots'` renders `<cngx-dot-stepper>`, `'off'` keeps the classic
|
|
241
|
+
* strip. The Material twin `<cngx-mat-stepper>` ignores this setting.
|
|
242
|
+
*
|
|
243
|
+
* @category common/stepper
|
|
244
|
+
*/
|
|
245
|
+
function withStepperMobileCollapse(mode) {
|
|
246
|
+
return defineStepperConfigFeature((cfg) => ({ ...cfg, mobileCollapse: mode }));
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Override the media query the mobile auto-collapse policy reacts to.
|
|
250
|
+
* Default `'(max-width: 480px)'`. Useful for tablet-tier consumers
|
|
251
|
+
* who want the collapse to engage at 768px or for design systems
|
|
252
|
+
* aligned with `--mat-sys-breakpoint-*` tokens.
|
|
253
|
+
*
|
|
254
|
+
* @category common/stepper
|
|
255
|
+
*/
|
|
256
|
+
function withStepperMobileBreakpoint(query) {
|
|
257
|
+
return defineStepperConfigFeature((cfg) => ({ ...cfg, mobileBreakpoint: query }));
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Set the app-wide default position of the mobile auto-collapse
|
|
261
|
+
* indicator relative to panel content. `'top'` keeps the indicator
|
|
262
|
+
* above (library default); `'bottom'` flips it below so panel content
|
|
263
|
+
* reads first and the navigation cue sits at thumb height. Per-
|
|
264
|
+
* instance `[mobileIndicatorPosition]` on `<cngx-stepper>` still
|
|
265
|
+
* wins.
|
|
266
|
+
*
|
|
267
|
+
* @category common/stepper
|
|
268
|
+
*/
|
|
269
|
+
function withStepperMobileIndicatorPosition(position) {
|
|
270
|
+
return defineStepperConfigFeature((cfg) => ({ ...cfg, mobileIndicatorPosition: position }));
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Toggle the built-in horizontal-swipe navigation on `<cngx-stepper>`
|
|
274
|
+
* in mobile-collapse mode. Default `true` - the `'dots'` and `'text'`
|
|
275
|
+
* variants read as carousels, so users expect to swipe. Per-instance
|
|
276
|
+
* `[mobileSwipe]` Input still wins; the classic strip is unaffected.
|
|
277
|
+
*
|
|
278
|
+
* @category common/stepper
|
|
279
|
+
*/
|
|
280
|
+
function withStepperMobileSwipe(enabled) {
|
|
281
|
+
return defineStepperConfigFeature((cfg) => ({ ...cfg, mobileSwipe: enabled }));
|
|
282
|
+
}
|
|
165
283
|
/**
|
|
166
284
|
* Merge ARIA labels into the cascade. Keys not provided keep their
|
|
167
285
|
* library defaults; per-instance overrides on the stepper still win.
|
|
286
|
+
*
|
|
287
|
+
* @category common/stepper
|
|
168
288
|
*/
|
|
169
289
|
function withStepperAriaLabels(labels) {
|
|
170
290
|
return defineStepperConfigFeature((cfg) => ({
|
|
@@ -175,6 +295,8 @@ function withStepperAriaLabels(labels) {
|
|
|
175
295
|
/**
|
|
176
296
|
* Merge text fallback labels (button captions, error strings) into the
|
|
177
297
|
* cascade. Used when a slot directive is not present.
|
|
298
|
+
*
|
|
299
|
+
* @category common/stepper
|
|
178
300
|
*/
|
|
179
301
|
function withStepperFallbackLabels(labels) {
|
|
180
302
|
return defineStepperConfigFeature((cfg) => ({
|
|
@@ -186,6 +308,8 @@ function withStepperFallbackLabels(labels) {
|
|
|
186
308
|
* Override the default `*cngxStepIndicator` template app-wide.
|
|
187
309
|
* Per-instance directive still wins; this only moves the cascade
|
|
188
310
|
* middle tier.
|
|
311
|
+
*
|
|
312
|
+
* @category common/stepper
|
|
189
313
|
*/
|
|
190
314
|
function withStepIndicatorTemplate(template) {
|
|
191
315
|
return defineStepperConfigFeature((cfg) => ({
|
|
@@ -195,6 +319,8 @@ function withStepIndicatorTemplate(template) {
|
|
|
195
319
|
}
|
|
196
320
|
/**
|
|
197
321
|
* Override the default `*cngxStepBadge` template app-wide.
|
|
322
|
+
*
|
|
323
|
+
* @category common/stepper
|
|
198
324
|
*/
|
|
199
325
|
function withStepBadgeTemplate(template) {
|
|
200
326
|
return defineStepperConfigFeature((cfg) => ({
|
|
@@ -204,6 +330,8 @@ function withStepBadgeTemplate(template) {
|
|
|
204
330
|
}
|
|
205
331
|
/**
|
|
206
332
|
* Override the default `*cngxStepBusySpinner` template app-wide.
|
|
333
|
+
*
|
|
334
|
+
* @category common/stepper
|
|
207
335
|
*/
|
|
208
336
|
function withStepBusySpinnerTemplate(template) {
|
|
209
337
|
return defineStepperConfigFeature((cfg) => ({
|
|
@@ -214,6 +342,8 @@ function withStepBusySpinnerTemplate(template) {
|
|
|
214
342
|
/**
|
|
215
343
|
* Override the default `*cngxStepRejection` template app-wide.
|
|
216
344
|
* Symmetric with the upcoming tabs `cngxTabRejectionIcon` (Phase 4).
|
|
345
|
+
*
|
|
346
|
+
* @category common/stepper
|
|
217
347
|
*/
|
|
218
348
|
function withStepRejectionTemplate(template) {
|
|
219
349
|
return defineStepperConfigFeature((cfg) => ({
|
|
@@ -223,6 +353,8 @@ function withStepRejectionTemplate(template) {
|
|
|
223
353
|
}
|
|
224
354
|
/**
|
|
225
355
|
* Override the default `*cngxStepGroupHeader` template app-wide.
|
|
356
|
+
*
|
|
357
|
+
* @category common/stepper
|
|
226
358
|
*/
|
|
227
359
|
function withStepGroupHeaderTemplate(template) {
|
|
228
360
|
return defineStepperConfigFeature((cfg) => ({
|
|
@@ -232,6 +364,8 @@ function withStepGroupHeaderTemplate(template) {
|
|
|
232
364
|
}
|
|
233
365
|
/**
|
|
234
366
|
* Override the default `*cngxStepperEmpty` template app-wide.
|
|
367
|
+
*
|
|
368
|
+
* @category common/stepper
|
|
235
369
|
*/
|
|
236
370
|
function withStepperEmptyTemplate(template) {
|
|
237
371
|
return defineStepperConfigFeature((cfg) => ({
|
|
@@ -239,6 +373,21 @@ function withStepperEmptyTemplate(template) {
|
|
|
239
373
|
templates: { ...cfg.templates, empty: template },
|
|
240
374
|
}));
|
|
241
375
|
}
|
|
376
|
+
/**
|
|
377
|
+
* Override the default `*cngxDotStepperDot` template app-wide. The
|
|
378
|
+
* `<cngx-dot-stepper>` variant resolves the cascade per dot:
|
|
379
|
+
* per-instance directive > this feature > built-in empty body
|
|
380
|
+
* (the dot fill is painted by `.cngx-dot-stepper__dot` regardless).
|
|
381
|
+
*
|
|
382
|
+
* @category common/stepper
|
|
383
|
+
*/
|
|
384
|
+
function withDotStepperDotTemplate(template) {
|
|
385
|
+
return defineStepperConfigFeature((cfg) => ({
|
|
386
|
+
...cfg,
|
|
387
|
+
templates: { ...cfg.templates, dotStepperDot: template },
|
|
388
|
+
}));
|
|
389
|
+
}
|
|
390
|
+
/** @internal */
|
|
242
391
|
function resolveFeatures(features) {
|
|
243
392
|
return features.reduce((cfg, feat) => feat(cfg), STEPPER_CONFIG_DEFAULTS);
|
|
244
393
|
}
|
|
@@ -246,6 +395,8 @@ function resolveFeatures(features) {
|
|
|
246
395
|
* Root-level provider for the stepper config. Apply once in the
|
|
247
396
|
* application providers array. Sibling of `provideTabsConfig` /
|
|
248
397
|
* `provideSelectConfig`.
|
|
398
|
+
*
|
|
399
|
+
* @category common/stepper
|
|
249
400
|
*/
|
|
250
401
|
function provideStepperConfig(...features) {
|
|
251
402
|
return makeEnvironmentProviders([
|
|
@@ -254,7 +405,7 @@ function provideStepperConfig(...features) {
|
|
|
254
405
|
}
|
|
255
406
|
/**
|
|
256
407
|
* Component-scoped config override. Spread the returned `Provider[]`
|
|
257
|
-
* into `providers` or `viewProviders`
|
|
408
|
+
* into `providers` or `viewProviders` - `viewProviders` cannot accept
|
|
258
409
|
* opaque {@link EnvironmentProviders}, so the twin returns a list.
|
|
259
410
|
* Sibling of `provideTabsConfigAt`.
|
|
260
411
|
*
|
|
@@ -266,12 +417,16 @@ function provideStepperConfig(...features) {
|
|
|
266
417
|
* viewProviders: [...provideStepperConfigAt(withStepperLinear(true))],
|
|
267
418
|
* })
|
|
268
419
|
* ```
|
|
420
|
+
*
|
|
421
|
+
* @category common/stepper
|
|
269
422
|
*/
|
|
270
423
|
function provideStepperConfigAt(...features) {
|
|
271
424
|
return [{ provide: CNGX_STEPPER_CONFIG, useValue: resolveFeatures(features) }];
|
|
272
425
|
}
|
|
273
426
|
/**
|
|
274
427
|
* Inject the resolved stepper config in an injection context.
|
|
428
|
+
*
|
|
429
|
+
* @category common/stepper
|
|
275
430
|
*/
|
|
276
431
|
function injectStepperConfig() {
|
|
277
432
|
return inject(CNGX_STEPPER_CONFIG);
|
|
@@ -281,6 +436,11 @@ function injectStepperConfig() {
|
|
|
281
436
|
* DI token carrying the presenter's contract to atoms + organism shells.
|
|
282
437
|
* Atoms inject `optional: true` and either register here or fall through
|
|
283
438
|
* {@link CNGX_STEP_GROUP_HOST} when nested in a group.
|
|
439
|
+
*
|
|
440
|
+
* @category common/stepper
|
|
441
|
+
* @wcag AA
|
|
442
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/stepper/stepper-host.token.ts
|
|
443
|
+
* @since 0.1.0
|
|
284
444
|
*/
|
|
285
445
|
const CNGX_STEPPER_HOST = new InjectionToken('CngxStepperHost');
|
|
286
446
|
|
|
@@ -288,6 +448,8 @@ const CNGX_STEPPER_HOST = new InjectionToken('CngxStepperHost');
|
|
|
288
448
|
* DFS-flatten a step tree. Group nodes emit before their children;
|
|
289
449
|
* the consumer keys off `kind` to render a panel container vs. a
|
|
290
450
|
* group header.
|
|
451
|
+
*
|
|
452
|
+
* @internal
|
|
291
453
|
*/
|
|
292
454
|
function flattenStepTree(nodes) {
|
|
293
455
|
const out = [];
|
|
@@ -309,10 +471,12 @@ function flattenStepTree(nodes) {
|
|
|
309
471
|
return out;
|
|
310
472
|
}
|
|
311
473
|
/**
|
|
312
|
-
* Structural equality for the step-tree registry signal. Shape only
|
|
474
|
+
* Structural equality for the step-tree registry signal. Shape only -
|
|
313
475
|
* id, kind, depth, parentId, children length. Reactive fields
|
|
314
476
|
* (`label`, `disabled`, `state`, `errorAggregator`) are signals; their
|
|
315
477
|
* own subscribers track identity changes.
|
|
478
|
+
*
|
|
479
|
+
* @internal
|
|
316
480
|
*/
|
|
317
481
|
function stepTreeEqual(a, b) {
|
|
318
482
|
if (a === b) {
|
|
@@ -338,12 +502,14 @@ function stepTreeEqual(a, b) {
|
|
|
338
502
|
* a sibling is inserted) on top of the {@link stepTreeEqual} fields.
|
|
339
503
|
*
|
|
340
504
|
* Use only on projections where every step carries a real
|
|
341
|
-
* DFS-assigned `flatIndex` and `depth`
|
|
505
|
+
* DFS-assigned `flatIndex` and `depth` - for `-1` placeholders, use
|
|
342
506
|
* {@link stepNodesEqual}.
|
|
343
507
|
*
|
|
344
508
|
* @internal Exported from `public-api.ts` so the cngx-stepper and
|
|
345
509
|
* cngx-mat-stepper organisms share the comparator across the
|
|
346
510
|
* secondary-entry boundary (Sheriff forbids deep-relative imports).
|
|
511
|
+
*
|
|
512
|
+
* @category common/stepper
|
|
347
513
|
*/
|
|
348
514
|
function flatStepsEqual(a, b) {
|
|
349
515
|
if (a === b) {
|
|
@@ -363,9 +529,11 @@ function flatStepsEqual(a, b) {
|
|
|
363
529
|
return true;
|
|
364
530
|
}
|
|
365
531
|
/**
|
|
366
|
-
* Structural equality for any flat node array
|
|
532
|
+
* Structural equality for any flat node array - `id`, `kind`,
|
|
367
533
|
* `parentId` only, ignoring `flatIndex` and `depth`. Use for
|
|
368
534
|
* `CngxStepGroup.children` and other `-1`-placeholder projections.
|
|
535
|
+
*
|
|
536
|
+
* @internal
|
|
369
537
|
*/
|
|
370
538
|
function stepNodesEqual(a, b) {
|
|
371
539
|
if (a === b) {
|
|
@@ -375,9 +543,7 @@ function stepNodesEqual(a, b) {
|
|
|
375
543
|
return false;
|
|
376
544
|
}
|
|
377
545
|
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) {
|
|
546
|
+
if (a[i].id !== b[i].id || a[i].kind !== b[i].kind || a[i].parentId !== b[i].parentId) {
|
|
381
547
|
return false;
|
|
382
548
|
}
|
|
383
549
|
}
|
|
@@ -385,21 +551,29 @@ function stepNodesEqual(a, b) {
|
|
|
385
551
|
}
|
|
386
552
|
|
|
387
553
|
/**
|
|
388
|
-
* Stepper presenter
|
|
554
|
+
* Stepper presenter - the brain of every stepper / wizard flow.
|
|
389
555
|
* Holds the active-step model, registry, linear policy, orientation,
|
|
390
556
|
* and commit-controller lifecycle. Provides {@link CNGX_STEPPER_HOST}
|
|
391
557
|
* for atom registration and {@link CNGX_STATEFUL} so transition
|
|
392
558
|
* bridges (`<cngx-toast-on />`, `<cngx-banner-on />`) compose without
|
|
393
559
|
* explicit `[state]` wiring.
|
|
394
560
|
*
|
|
395
|
-
* Sheriff: common Level 2. Pure directive
|
|
561
|
+
* Sheriff: common Level 2. Pure directive - zero template, zero CSS.
|
|
396
562
|
* Level-4 organisms compose this via `hostDirectives`.
|
|
563
|
+
*
|
|
564
|
+
* @category common/stepper
|
|
565
|
+
* @docsKind primary
|
|
566
|
+
* @wcag AA
|
|
567
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/stepper/presenter.directive.ts
|
|
568
|
+
* @since 0.1.0
|
|
569
|
+
* @relatedTo CngxStep, CngxStepGroup, CngxStepperRouterSync, CNGX_STEPPER_HOST, CNGX_STEPPER_CONFIG
|
|
570
|
+
* <example-url>http://localhost:4200/#/ui/stepper/stepper-commit-action/pessimistic-optimistic-commits-with-bridge-directives</example-url>
|
|
397
571
|
*/
|
|
398
572
|
class CngxStepperPresenter {
|
|
399
573
|
config = injectStepperConfig();
|
|
400
574
|
activeStepIndex = model(0, ...(ngDevMode ? [{ debugName: "activeStepIndex" }] : /* istanbul ignore next */ []));
|
|
401
575
|
// Raw *Input slots default undefined so the cascade resolves through
|
|
402
|
-
// CNGX_STEPPER_CONFIG. Must stay public
|
|
576
|
+
// CNGX_STEPPER_CONFIG. Must stay public - the template type-checker
|
|
403
577
|
// rejects protected/private on hostDirective alias bindings.
|
|
404
578
|
linearInput = input(undefined, { ...(ngDevMode ? { debugName: "linearInput" } : /* istanbul ignore next */ {}), alias: 'linear' });
|
|
405
579
|
linear = computed(() => this.linearInput() ?? this.config.defaultLinear ?? false, ...(ngDevMode ? [{ debugName: "linear" }] : /* istanbul ignore next */ []));
|
|
@@ -422,11 +596,11 @@ class CngxStepperPresenter {
|
|
|
422
596
|
/**
|
|
423
597
|
* Reactive current/previous pair for the commit-state status. Skin
|
|
424
598
|
* sub-components mount a `<span cngxLiveRegion>` reading this
|
|
425
|
-
* tracker. Allocated once per presenter
|
|
599
|
+
* tracker. Allocated once per presenter - the underlying
|
|
426
600
|
* `linkedSignal` is shared across all consumers.
|
|
427
601
|
*/
|
|
428
602
|
commitTransition = createTransitionTracker(() => this.commitController.state.status());
|
|
429
|
-
// Persistence-of-error surface
|
|
603
|
+
// Persistence-of-error surface - see CngxStepperHost.lastFailedIndex
|
|
430
604
|
// / originIndexDuringCommit for the contract.
|
|
431
605
|
lastFailedIndexState = signal(undefined, ...(ngDevMode ? [{ debugName: "lastFailedIndexState" }] : /* istanbul ignore next */ []));
|
|
432
606
|
originIndexDuringCommitState = signal(undefined, ...(ngDevMode ? [{ debugName: "originIndexDuringCommitState" }] : /* istanbul ignore next */ []));
|
|
@@ -438,10 +612,10 @@ class CngxStepperPresenter {
|
|
|
438
612
|
stepTree = this.treeState.asReadonly();
|
|
439
613
|
flatSteps = computed(() => flattenStepTree(this.stepTree()), { ...(ngDevMode ? { debugName: "flatSteps" } : /* istanbul ignore next */ {}), equal: flatStepsEqual });
|
|
440
614
|
/**
|
|
441
|
-
* Step-only flat projection
|
|
615
|
+
* Step-only flat projection - terminal nodes in DFS order.
|
|
442
616
|
* Structural-equal via `flatStepsEqual` so downstream computeds
|
|
443
617
|
* don't cascade on shape-stable re-emits. Single source for every
|
|
444
|
-
* `select*` / `clamp` / `activeStepId` lookup
|
|
618
|
+
* `select*` / `clamp` / `activeStepId` lookup - never re-filter
|
|
445
619
|
* `flatSteps()`.
|
|
446
620
|
*/
|
|
447
621
|
stepsOnly = computed(() => this.flatSteps().filter((n) => n.kind === 'step'), { ...(ngDevMode ? { debugName: "stepsOnly" } : /* istanbul ignore next */ {}), equal: flatStepsEqual });
|
|
@@ -458,13 +632,75 @@ class CngxStepperPresenter {
|
|
|
458
632
|
return this.stepsOnly()[idx]?.id ?? null;
|
|
459
633
|
}, ...(ngDevMode ? [{ debugName: "activeStepId" }] : /* istanbul ignore next */ []));
|
|
460
634
|
commitState = this.commitController.state;
|
|
635
|
+
/**
|
|
636
|
+
* Next enabled step-only index after the active one, skipping
|
|
637
|
+
* disabled steps. Returns `stepsOnly().length` when no enabled step
|
|
638
|
+
* follows. Single source for `selectNext()` and the `canGoNext`
|
|
639
|
+
* bound - the traversal lives here, never re-walked at the call site.
|
|
640
|
+
*/
|
|
641
|
+
nextEnabledIndex = computed(() => {
|
|
642
|
+
const stepsOnly = this.stepsOnly();
|
|
643
|
+
let next = this.activeStepIndex() + 1;
|
|
644
|
+
while (next < stepsOnly.length && stepsOnly[next].disabled()) {
|
|
645
|
+
next++;
|
|
646
|
+
}
|
|
647
|
+
return next;
|
|
648
|
+
}, ...(ngDevMode ? [{ debugName: "nextEnabledIndex" }] : /* istanbul ignore next */ []));
|
|
649
|
+
/**
|
|
650
|
+
* Previous enabled step-only index before the active one, skipping
|
|
651
|
+
* disabled steps. Returns `-1` when no enabled step precedes. Single
|
|
652
|
+
* source for `selectPrevious()` and the `canGoPrevious` bound.
|
|
653
|
+
*/
|
|
654
|
+
previousEnabledIndex = computed(() => {
|
|
655
|
+
const stepsOnly = this.stepsOnly();
|
|
656
|
+
let prev = this.activeStepIndex() - 1;
|
|
657
|
+
while (prev >= 0 && stepsOnly[prev].disabled()) {
|
|
658
|
+
prev--;
|
|
659
|
+
}
|
|
660
|
+
return prev;
|
|
661
|
+
}, ...(ngDevMode ? [{ debugName: "previousEnabledIndex" }] : /* istanbul ignore next */ []));
|
|
662
|
+
/** {@inheritDoc CngxStepperHost.stepCount} */
|
|
663
|
+
stepCount = computed(() => this.stepsOnly().length, ...(ngDevMode ? [{ debugName: "stepCount" }] : /* istanbul ignore next */ []));
|
|
664
|
+
/** {@inheritDoc CngxStepperHost.isFirstStep} */
|
|
665
|
+
isFirstStep = computed(() => this.clampedIndex() <= 0, ...(ngDevMode ? [{ debugName: "isFirstStep" }] : /* istanbul ignore next */ []));
|
|
666
|
+
/** {@inheritDoc CngxStepperHost.isLastStep} */
|
|
667
|
+
isLastStep = computed(() => this.clampedIndex() >= this.stepCount() - 1, ...(ngDevMode ? [{ debugName: "isLastStep" }] : /* istanbul ignore next */ []));
|
|
668
|
+
/**
|
|
669
|
+
* {@inheritDoc CngxStepperHost.canGoNext}
|
|
670
|
+
*
|
|
671
|
+
* Derives from the same `nextEnabledIndex` + `isLinearBlocked`
|
|
672
|
+
* predicates `select()`/`selectNext()` enforce, so the affordance can
|
|
673
|
+
* never drift from the navigation it gates.
|
|
674
|
+
*/
|
|
675
|
+
canGoNext = computed(() => {
|
|
676
|
+
const next = this.nextEnabledIndex();
|
|
677
|
+
return next < this.stepCount() && !this.isLinearBlocked(next);
|
|
678
|
+
}, ...(ngDevMode ? [{ debugName: "canGoNext" }] : /* istanbul ignore next */ []));
|
|
679
|
+
/** {@inheritDoc CngxStepperHost.canGoPrevious} */
|
|
680
|
+
canGoPrevious = computed(() => this.previousEnabledIndex() >= 0, ...(ngDevMode ? [{ debugName: "canGoPrevious" }] : /* istanbul ignore next */ []));
|
|
681
|
+
/** {@inheritDoc CngxStepperHost.busy} */
|
|
682
|
+
busy = computed(() => this.commitState.status() === 'pending', ...(ngDevMode ? [{ debugName: "busy" }] : /* istanbul ignore next */ []));
|
|
683
|
+
/** {@inheritDoc CngxStepperHost.nextStepLabel} */
|
|
684
|
+
nextStepLabel = computed(() => this.stepsOnly()[this.nextEnabledIndex()]?.label(), ...(ngDevMode ? [{ debugName: "nextStepLabel" }] : /* istanbul ignore next */ []));
|
|
685
|
+
/** {@inheritDoc CngxStepperHost.previousStepLabel} */
|
|
686
|
+
previousStepLabel = computed(() => this.stepsOnly()[this.previousEnabledIndex()]?.label(), ...(ngDevMode ? [{ debugName: "previousStepLabel" }] : /* istanbul ignore next */ []));
|
|
687
|
+
constructor() {
|
|
688
|
+
if (isDevMode()) {
|
|
689
|
+
afterNextRender(() => {
|
|
690
|
+
const stepNodes = this.flatSteps().filter((n) => n.kind === 'step');
|
|
691
|
+
if (stepNodes.length > 6 && stepNodes.every((n) => n.parentId === null)) {
|
|
692
|
+
console.warn('[cngx-stepper] more than 6 steps at the same depth; consider wrapping logical groups in <cngx-step-group> for better UX');
|
|
693
|
+
}
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
}
|
|
461
697
|
// Flat id lookup; rebuilt into the hierarchical tree on each
|
|
462
698
|
// register/unregister.
|
|
463
699
|
registry = new Map();
|
|
464
700
|
insertionOrder = [];
|
|
465
701
|
register(handle, parentId = null) {
|
|
466
702
|
if (this.registry.has(handle.id)) {
|
|
467
|
-
// Idempotent re-register
|
|
703
|
+
// Idempotent re-register - replace the handle, keep the ordering slot.
|
|
468
704
|
const entry = this.registry.get(handle.id);
|
|
469
705
|
entry.reg = handle;
|
|
470
706
|
entry.parentId = parentId;
|
|
@@ -523,20 +759,30 @@ class CngxStepperPresenter {
|
|
|
523
759
|
clearLastFailed() {
|
|
524
760
|
this.lastFailedIndexState.set(undefined);
|
|
525
761
|
}
|
|
762
|
+
/**
|
|
763
|
+
* Linear-gate predicate: `true` when linear mode forbids advancing to
|
|
764
|
+
* `target` because an incomplete (non-`success`, non-disabled) step
|
|
765
|
+
* sits between the active index and `target`. The single home for the
|
|
766
|
+
* linear slice check - `select()` and the `canGoNext` bound both
|
|
767
|
+
* consume it so the gate can never drift between navigation and its
|
|
768
|
+
* affordance.
|
|
769
|
+
*/
|
|
770
|
+
isLinearBlocked(target) {
|
|
771
|
+
if (!this.linear() || target <= this.activeStepIndex()) {
|
|
772
|
+
return false;
|
|
773
|
+
}
|
|
774
|
+
return this.stepsOnly()
|
|
775
|
+
.slice(this.activeStepIndex(), target)
|
|
776
|
+
.some((n) => n.state() !== 'success' && !n.disabled());
|
|
777
|
+
}
|
|
526
778
|
select(index) {
|
|
527
779
|
const stepsOnly = this.stepsOnly();
|
|
528
780
|
if (stepsOnly.length === 0) {
|
|
529
781
|
return;
|
|
530
782
|
}
|
|
531
783
|
const target = Math.max(0, Math.min(index, stepsOnly.length - 1));
|
|
532
|
-
if (this.
|
|
533
|
-
|
|
534
|
-
const blocking = stepsOnly
|
|
535
|
-
.slice(this.activeStepIndex(), target)
|
|
536
|
-
.find((n) => n.state() !== 'success' && !n.disabled());
|
|
537
|
-
if (blocking) {
|
|
538
|
-
return;
|
|
539
|
-
}
|
|
784
|
+
if (this.isLinearBlocked(target)) {
|
|
785
|
+
return;
|
|
540
786
|
}
|
|
541
787
|
if (stepsOnly[target].disabled()) {
|
|
542
788
|
return;
|
|
@@ -547,7 +793,7 @@ class CngxStepperPresenter {
|
|
|
547
793
|
}
|
|
548
794
|
const action = this.commitAction();
|
|
549
795
|
if (!action) {
|
|
550
|
-
// No-action fast path
|
|
796
|
+
// No-action fast path - sync move, no commit window opens, so
|
|
551
797
|
// `originIndexDuringCommit` stays untouched. Clear the rejection
|
|
552
798
|
// flag if the user re-picked a previously-failed target.
|
|
553
799
|
this.activeStepIndex.set(target);
|
|
@@ -558,7 +804,7 @@ class CngxStepperPresenter {
|
|
|
558
804
|
}
|
|
559
805
|
// Commit-gated transition. Pessimistic holds at `previous` until
|
|
560
806
|
// the action resolves; optimistic advances now and rolls back on
|
|
561
|
-
// rejection. Supersede comes from the lifted commit-controller
|
|
807
|
+
// rejection. Supersede comes from the lifted commit-controller -
|
|
562
808
|
// a rapid second select() cancels the in-flight runner.
|
|
563
809
|
//
|
|
564
810
|
// Capture the safe-harbour origin exactly once on commit-window
|
|
@@ -571,7 +817,7 @@ class CngxStepperPresenter {
|
|
|
571
817
|
}
|
|
572
818
|
this.commitHandler.beginTransition(previous, target, action, (accept) => {
|
|
573
819
|
if (accept) {
|
|
574
|
-
// Success
|
|
820
|
+
// Success - origin no longer needed; clear the rejection
|
|
575
821
|
// flag if the user re-picked the failed target.
|
|
576
822
|
this.originIndexDuringCommitState.set(undefined);
|
|
577
823
|
if (this.lastFailedIndexState() === target) {
|
|
@@ -582,7 +828,7 @@ class CngxStepperPresenter {
|
|
|
582
828
|
}
|
|
583
829
|
}
|
|
584
830
|
else {
|
|
585
|
-
// Reject
|
|
831
|
+
// Reject - flag the target; RETAIN the origin so
|
|
586
832
|
// `liveAnnouncement` can resolve the origin label for the
|
|
587
833
|
// rich rollback phrase. Optimistic rolls back; pessimistic
|
|
588
834
|
// never moved.
|
|
@@ -594,21 +840,13 @@ class CngxStepperPresenter {
|
|
|
594
840
|
});
|
|
595
841
|
}
|
|
596
842
|
selectNext() {
|
|
597
|
-
const
|
|
598
|
-
|
|
599
|
-
while (next < stepsOnly.length && stepsOnly[next].disabled()) {
|
|
600
|
-
next++;
|
|
601
|
-
}
|
|
602
|
-
if (next < stepsOnly.length) {
|
|
843
|
+
const next = this.nextEnabledIndex();
|
|
844
|
+
if (next < this.stepsOnly().length) {
|
|
603
845
|
this.select(next);
|
|
604
846
|
}
|
|
605
847
|
}
|
|
606
848
|
selectPrevious() {
|
|
607
|
-
const
|
|
608
|
-
let prev = this.activeStepIndex() - 1;
|
|
609
|
-
while (prev >= 0 && stepsOnly[prev].disabled()) {
|
|
610
|
-
prev--;
|
|
611
|
-
}
|
|
849
|
+
const prev = this.previousEnabledIndex();
|
|
612
850
|
if (prev >= 0) {
|
|
613
851
|
this.activeStepIndex.set(prev);
|
|
614
852
|
}
|
|
@@ -641,17 +879,25 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
641
879
|
{ provide: CNGX_STATEFUL, useExisting: CngxStepperPresenter },
|
|
642
880
|
],
|
|
643
881
|
}]
|
|
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 }] }] } });
|
|
882
|
+
}], ctorParameters: () => [], 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
883
|
|
|
646
884
|
/**
|
|
647
885
|
* DI token providing a `CngxStepGroup`'s contract to nested `CngxStep` atoms.
|
|
648
886
|
* Steps inject this `optional: true` and fall back to {@link CNGX_STEPPER_HOST}.
|
|
887
|
+
*
|
|
888
|
+
* @category common/stepper
|
|
889
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/stepper/step-group-host.token.ts
|
|
890
|
+
* @since 0.1.0
|
|
649
891
|
*/
|
|
650
892
|
const CNGX_STEP_GROUP_HOST = new InjectionToken('CngxStepGroupHost');
|
|
651
893
|
|
|
652
894
|
/**
|
|
653
895
|
* DI token providing the rendering-surface contract to organism shells
|
|
654
896
|
* (`<cngx-stepper>`, `<cngx-mat-stepper>`) and consumer-authored skins.
|
|
897
|
+
*
|
|
898
|
+
* @category common/stepper
|
|
899
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/stepper/step-panel-host.token.ts
|
|
900
|
+
* @since 0.1.0
|
|
655
901
|
*/
|
|
656
902
|
const CNGX_STEP_PANEL_HOST = new InjectionToken('CngxStepPanelHost');
|
|
657
903
|
|
|
@@ -666,6 +912,13 @@ const CNGX_STEP_PANEL_HOST = new InjectionToken('CngxStepPanelHost');
|
|
|
666
912
|
* <input [disabled]="busy">
|
|
667
913
|
* </ng-template>
|
|
668
914
|
* ```
|
|
915
|
+
*
|
|
916
|
+
* @category common/stepper
|
|
917
|
+
* @wcag AA
|
|
918
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/stepper/step-content.directive.ts
|
|
919
|
+
* @since 0.1.0
|
|
920
|
+
* @relatedTo CngxStep, CngxStepLabel
|
|
921
|
+
* <example-url>http://localhost:4200/#/ui/stepper/stepper-horizontal/three-step-wizard</example-url>
|
|
669
922
|
*/
|
|
670
923
|
class CngxStepContent {
|
|
671
924
|
templateRef = inject(TemplateRef);
|
|
@@ -691,6 +944,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
691
944
|
* {{ node.label() }}
|
|
692
945
|
* </ng-template>
|
|
693
946
|
* ```
|
|
947
|
+
*
|
|
948
|
+
* @category common/stepper
|
|
949
|
+
* @wcag AA
|
|
950
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/stepper/step-label.directive.ts
|
|
951
|
+
* @since 0.1.0
|
|
952
|
+
* @relatedTo CngxStep, CngxStepContent, CngxStepGroupHeader
|
|
953
|
+
* <example-url>http://localhost:4200/#/ui/stepper/stepper-custom-labels/mixing-code-label-code-input-with-code-cngxsteplabel-code-slot</example-url>
|
|
694
954
|
*/
|
|
695
955
|
class CngxStepLabel {
|
|
696
956
|
templateRef = inject(TemplateRef);
|
|
@@ -706,12 +966,20 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
706
966
|
}] });
|
|
707
967
|
|
|
708
968
|
/**
|
|
709
|
-
* Single-step atom. Registers with the nearest host
|
|
969
|
+
* Single-step atom. Registers with the nearest host - either a
|
|
710
970
|
* `CngxStepGroup` ({@link CNGX_STEP_GROUP_HOST}) or the root
|
|
711
971
|
* `CngxStepperPresenter` ({@link CNGX_STEPPER_HOST}).
|
|
712
972
|
*
|
|
713
973
|
* `state` is a `linkedSignal` over `[disabled]`, `[completed]`, and
|
|
714
974
|
* the optional `[errorAggregator]`'s `hasError()`.
|
|
975
|
+
*
|
|
976
|
+
* @category common/stepper
|
|
977
|
+
* @docsKind primary
|
|
978
|
+
* @wcag AA
|
|
979
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/stepper/step.directive.ts
|
|
980
|
+
* @since 0.1.0
|
|
981
|
+
* @relatedTo CngxStepGroup, CngxStepperPresenter, CngxStepLabel, CngxStepContent
|
|
982
|
+
* <example-url>http://localhost:4200/#/ui/stepper/stepper-horizontal/three-step-wizard</example-url>
|
|
715
983
|
*/
|
|
716
984
|
class CngxStep {
|
|
717
985
|
id = input(nextUid('cngx-step'), ...(ngDevMode ? [{ debugName: "id" }] : /* istanbul ignore next */ []));
|
|
@@ -725,7 +993,7 @@ class CngxStep {
|
|
|
725
993
|
contentTemplate = this.contentSlot;
|
|
726
994
|
/**
|
|
727
995
|
* Per-step status derived from inputs + aggregator. `linkedSignal`
|
|
728
|
-
* with structural equal
|
|
996
|
+
* with structural equal - never written via `effect`.
|
|
729
997
|
*/
|
|
730
998
|
state = linkedSignal({ ...(ngDevMode ? { debugName: "state" } : /* istanbul ignore next */ {}), source: () => ({
|
|
731
999
|
disabled: this.disabled(),
|
|
@@ -750,7 +1018,6 @@ class CngxStep {
|
|
|
750
1018
|
const stepperHost = inject(CNGX_STEPPER_HOST, { optional: true });
|
|
751
1019
|
const host = groupHost ?? stepperHost;
|
|
752
1020
|
if (!host) {
|
|
753
|
-
// No enclosing presenter or group — atom can't register. Fail loud.
|
|
754
1021
|
throw new Error('CngxStep: no enclosing CngxStepperPresenter or CngxStepGroup found. ' +
|
|
755
1022
|
'Wrap the step inside an element carrying [cngxStepper] or [cngxStepGroup].');
|
|
756
1023
|
}
|
|
@@ -785,12 +1052,20 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
785
1052
|
* `aggregatedStatus` rolls up child states: `error` if any errored,
|
|
786
1053
|
* `success` if all are success, `pending` if any is pending or busy,
|
|
787
1054
|
* otherwise `idle`.
|
|
1055
|
+
*
|
|
1056
|
+
* @category common/stepper
|
|
1057
|
+
* @docsKind primary
|
|
1058
|
+
* @wcag AA
|
|
1059
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/stepper/step-group.directive.ts
|
|
1060
|
+
* @since 0.1.0
|
|
1061
|
+
* @relatedTo CngxStep, CngxStepperPresenter, CngxStepGroupHeader
|
|
1062
|
+
* <example-url>http://localhost:4200/#/ui/stepper/stepper-hierarchical/group-nested-steps-trailing-root-step</example-url>
|
|
788
1063
|
*/
|
|
789
1064
|
class CngxStepGroup {
|
|
790
1065
|
id = input(nextUid('cngx-step-group'), ...(ngDevMode ? [{ debugName: "id" }] : /* istanbul ignore next */ []));
|
|
791
1066
|
disabled = input(false, ...(ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []));
|
|
792
1067
|
label = input('', ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
|
|
793
|
-
// Local child registry
|
|
1068
|
+
// Local child registry - only feeds `aggregatedStatus` below.
|
|
794
1069
|
// The presenter owns the canonical tree.
|
|
795
1070
|
childRegistry = signal([], ...(ngDevMode ? [{ debugName: "childRegistry" }] : /* istanbul ignore next */ []));
|
|
796
1071
|
aggregatedStatus = computed(() => {
|
|
@@ -867,6 +1142,14 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
867
1142
|
* </ng-template>
|
|
868
1143
|
* </cngx-stepper>
|
|
869
1144
|
* ```
|
|
1145
|
+
*
|
|
1146
|
+
* @category common/stepper/slots
|
|
1147
|
+
* @wcag AA
|
|
1148
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/stepper/slots/step-indicator.directive.ts
|
|
1149
|
+
* @since 0.1.0
|
|
1150
|
+
* @relatedTo CngxStepBadge, CngxStepBusySpinner, CngxStepRejection, CngxStepGroupHeader
|
|
1151
|
+
* <example-url>http://localhost:4200/#/ui/stepper/stepper-slot-overrides/custom-indicator-glyph-via-code-cngxstepindicator-code</example-url>
|
|
1152
|
+
* <example-url>http://localhost:4200/#/ui/stepper/stepper-slot-overrides/cross-skin-indicator-override</example-url>
|
|
870
1153
|
*/
|
|
871
1154
|
class CngxStepIndicator {
|
|
872
1155
|
templateRef = inject(TemplateRef);
|
|
@@ -895,6 +1178,14 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
895
1178
|
* </ng-template>
|
|
896
1179
|
* </cngx-stepper>
|
|
897
1180
|
* ```
|
|
1181
|
+
*
|
|
1182
|
+
* @category common/stepper/slots
|
|
1183
|
+
* @wcag AA
|
|
1184
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/stepper/slots/step-badge.directive.ts
|
|
1185
|
+
* @since 0.1.0
|
|
1186
|
+
* @relatedTo CngxStepIndicator, CngxStepBusySpinner, CngxStepRejection
|
|
1187
|
+
* <example-url>http://localhost:4200/#/ui/stepper/stepper-slot-overrides/custom-error-badge-via-code-cngxstepbadge-code</example-url>
|
|
1188
|
+
* <example-url>http://localhost:4200/#/ui/stepper/stepper-error-aggregation/per-step-error-badges</example-url>
|
|
898
1189
|
*/
|
|
899
1190
|
class CngxStepBadge {
|
|
900
1191
|
templateRef = inject(TemplateRef);
|
|
@@ -923,6 +1214,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
923
1214
|
* </ng-template>
|
|
924
1215
|
* </cngx-stepper>
|
|
925
1216
|
* ```
|
|
1217
|
+
*
|
|
1218
|
+
* @category common/stepper/slots
|
|
1219
|
+
* @wcag AA
|
|
1220
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/stepper/slots/step-busy-spinner.directive.ts
|
|
1221
|
+
* @since 0.1.0
|
|
1222
|
+
* @relatedTo CngxStepIndicator, CngxStepBadge, CngxStepRejection
|
|
1223
|
+
* <example-url>http://localhost:4200/#/ui/stepper/stepper-slot-overrides/custom-busy-spinner-via-code-cngxstepbusyspinner-code</example-url>
|
|
926
1224
|
*/
|
|
927
1225
|
class CngxStepBusySpinner {
|
|
928
1226
|
templateRef = inject(TemplateRef);
|
|
@@ -957,6 +1255,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
957
1255
|
* </ng-template>
|
|
958
1256
|
* </cngx-stepper>
|
|
959
1257
|
* ```
|
|
1258
|
+
*
|
|
1259
|
+
* @category common/stepper/slots
|
|
1260
|
+
* @wcag AA
|
|
1261
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/stepper/slots/step-rejection.directive.ts
|
|
1262
|
+
* @since 0.1.0
|
|
1263
|
+
* @relatedTo CngxStepBadge, CngxStepIndicator, CngxStepBusySpinner
|
|
1264
|
+
* <example-url>http://localhost:4200/#/ui/stepper/stepper-slot-overrides/rejection-decoration-via-code-cngxsteprejection-code</example-url>
|
|
960
1265
|
*/
|
|
961
1266
|
class CngxStepRejection {
|
|
962
1267
|
templateRef = inject(TemplateRef);
|
|
@@ -985,6 +1290,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
985
1290
|
* </ng-template>
|
|
986
1291
|
* </cngx-stepper>
|
|
987
1292
|
* ```
|
|
1293
|
+
*
|
|
1294
|
+
* @category common/stepper/slots
|
|
1295
|
+
* @wcag AA
|
|
1296
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/stepper/slots/step-group-header.directive.ts
|
|
1297
|
+
* @since 0.1.0
|
|
1298
|
+
* @relatedTo CngxStepGroup, CngxStepIndicator, CngxStepLabel
|
|
1299
|
+
* <example-url>http://localhost:4200/#/ui/stepper/stepper-slot-overrides/custom-group-header-via-code-cngxstepgroupheader-code</example-url>
|
|
988
1300
|
*/
|
|
989
1301
|
class CngxStepGroupHeader {
|
|
990
1302
|
templateRef = inject(TemplateRef);
|
|
@@ -1002,7 +1314,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1002
1314
|
|
|
1003
1315
|
/**
|
|
1004
1316
|
* Slot directive for the empty-state placeholder on `<cngx-stepper>`.
|
|
1005
|
-
* Rendered when `flatSteps()` is empty
|
|
1317
|
+
* Rendered when `flatSteps()` is empty - async-loading or
|
|
1006
1318
|
* server-driven step lists get a "no steps yet" landmark rather than
|
|
1007
1319
|
* a collapsed strip.
|
|
1008
1320
|
*
|
|
@@ -1017,6 +1329,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1017
1329
|
* </ng-template>
|
|
1018
1330
|
* </cngx-stepper>
|
|
1019
1331
|
* ```
|
|
1332
|
+
*
|
|
1333
|
+
* @category common/stepper/slots
|
|
1334
|
+
* @wcag AA
|
|
1335
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/stepper/slots/stepper-empty.directive.ts
|
|
1336
|
+
* @since 0.1.0
|
|
1337
|
+
* @relatedTo CngxStepIndicator, CngxStepGroupHeader
|
|
1338
|
+
* <example-url>http://localhost:4200/#/ui/stepper/stepper-slot-overrides/empty-state-placeholder-via-code-cngxstepperempty-code</example-url>
|
|
1020
1339
|
*/
|
|
1021
1340
|
class CngxStepperEmpty {
|
|
1022
1341
|
templateRef = inject(TemplateRef);
|
|
@@ -1032,6 +1351,48 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1032
1351
|
}]
|
|
1033
1352
|
}] });
|
|
1034
1353
|
|
|
1354
|
+
/**
|
|
1355
|
+
* Slot directive for the dot-body template on `<cngx-dot-stepper>`.
|
|
1356
|
+
* Discovered via `contentChild`; cascades through
|
|
1357
|
+
* `CNGX_STEPPER_CONFIG.templates.dotStepperDot` before falling back to
|
|
1358
|
+
* the built-in empty body (the span itself paints the dot fill via CSS).
|
|
1359
|
+
*
|
|
1360
|
+
* ```html
|
|
1361
|
+
* <cngx-dot-stepper [(activeStepIndex)]="active" aria-label="Carousel">
|
|
1362
|
+
* <ng-template cngxDotStepperDot let-index let-active="active" let-completed="completed">
|
|
1363
|
+
* @if (active) {
|
|
1364
|
+
* <svg viewBox="0 0 10 10" aria-hidden="true"><circle cx="5" cy="5" r="3" fill="currentColor" /></svg>
|
|
1365
|
+
* } @else if (completed) {
|
|
1366
|
+
* <svg viewBox="0 0 10 10" aria-hidden="true"><path d="M2 5l2 2 4-4" stroke="currentColor" fill="none" /></svg>
|
|
1367
|
+
* }
|
|
1368
|
+
* </ng-template>
|
|
1369
|
+
* <div cngxStep label="Slide 1"></div>
|
|
1370
|
+
* <div cngxStep label="Slide 2"></div>
|
|
1371
|
+
* </cngx-dot-stepper>
|
|
1372
|
+
* ```
|
|
1373
|
+
*
|
|
1374
|
+
* @category common/stepper/slots
|
|
1375
|
+
* @wcag AA
|
|
1376
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/stepper/slots/dot-stepper-dot.directive.ts
|
|
1377
|
+
* @since 0.1.0
|
|
1378
|
+
* @relatedTo CngxStepIndicator, CngxStepBadge, CngxStepBusySpinner, CngxStepRejection
|
|
1379
|
+
* <example-url>http://localhost:4200/#/ui/stepper/dot-stepper/icon-dots-via-code-cngxdotstepperdot-code</example-url>
|
|
1380
|
+
* <example-url>http://localhost:4200/#/ui/stepper/dot-stepper/mobile-carousel</example-url>
|
|
1381
|
+
*/
|
|
1382
|
+
class CngxDotStepperDot {
|
|
1383
|
+
templateRef = inject(TemplateRef);
|
|
1384
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDotStepperDot, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1385
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxDotStepperDot, isStandalone: true, selector: "ng-template[cngxDotStepperDot]", exportAs: ["cngxDotStepperDot"], ngImport: i0 });
|
|
1386
|
+
}
|
|
1387
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDotStepperDot, decorators: [{
|
|
1388
|
+
type: Directive,
|
|
1389
|
+
args: [{
|
|
1390
|
+
selector: 'ng-template[cngxDotStepperDot]',
|
|
1391
|
+
exportAs: 'cngxDotStepperDot',
|
|
1392
|
+
standalone: true,
|
|
1393
|
+
}]
|
|
1394
|
+
}] });
|
|
1395
|
+
|
|
1035
1396
|
/**
|
|
1036
1397
|
* Wires the 3-stage template cascade for the six `<cngx-stepper>`
|
|
1037
1398
|
* skin slots: per-instance directive > `CNGX_STEPPER_CONFIG.templates.<key>`
|
|
@@ -1043,6 +1404,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1043
1404
|
*
|
|
1044
1405
|
* Tabs has no parallel slot surface yet — see
|
|
1045
1406
|
* `stepper-accepted-debt §3` for the planned Phase-4 closure.
|
|
1407
|
+
*
|
|
1408
|
+
* @category common/stepper/slots
|
|
1046
1409
|
*/
|
|
1047
1410
|
function createStepperTemplateBindings(opts) {
|
|
1048
1411
|
return {
|
|
@@ -1079,6 +1442,9 @@ function createStepperTemplateBindings(opts) {
|
|
|
1079
1442
|
* `*cngxStep*` slots or `withStep*Template` features.
|
|
1080
1443
|
*
|
|
1081
1444
|
* @internal
|
|
1445
|
+
* @category common/stepper
|
|
1446
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/stepper/glyphs.ts
|
|
1447
|
+
* @since 0.1.0
|
|
1082
1448
|
*/
|
|
1083
1449
|
const CNGX_STEPPER_GLYPHS = {
|
|
1084
1450
|
/** Default visual for `*cngxStepBadge` when no override is bound. */
|
|
@@ -1095,8 +1461,16 @@ const CNGX_STEPPER_GLYPHS = {
|
|
|
1095
1461
|
* - `mode = 'fragment'` (default) → `#step=customer`
|
|
1096
1462
|
* - `mode = 'queryParam'` with `paramName = 'step'` → `?step=customer`
|
|
1097
1463
|
*
|
|
1098
|
-
* `Router` is optional
|
|
1464
|
+
* `Router` is optional - without `@angular/router` the directive
|
|
1099
1465
|
* dev-warns once and becomes a no-op.
|
|
1466
|
+
*
|
|
1467
|
+
* @category common/stepper
|
|
1468
|
+
* @docsKind primary
|
|
1469
|
+
* @wcag AA
|
|
1470
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/stepper/router-sync.directive.ts
|
|
1471
|
+
* @since 0.1.0
|
|
1472
|
+
* @relatedTo CngxStepperPresenter, CNGX_STEPPER_CONFIG
|
|
1473
|
+
* <example-url>http://localhost:4200/#/ui/stepper/stepper-router-sync/deep-linking-with-fragment-queryparam-modes</example-url>
|
|
1100
1474
|
*/
|
|
1101
1475
|
class CngxStepperRouterSync {
|
|
1102
1476
|
// Default undefined so the cascade resolves through CNGX_STEPPER_CONFIG.
|
|
@@ -1112,7 +1486,7 @@ class CngxStepperRouterSync {
|
|
|
1112
1486
|
constructor() {
|
|
1113
1487
|
if (!this.router) {
|
|
1114
1488
|
afterNextRender(() => {
|
|
1115
|
-
console.warn('CngxStepperRouterSync: no Router available
|
|
1489
|
+
console.warn('CngxStepperRouterSync: no Router available - directive is a no-op. ' +
|
|
1116
1490
|
'Provide @angular/router via provideRouter(...) to enable deep-linking.');
|
|
1117
1491
|
});
|
|
1118
1492
|
return;
|
|
@@ -1188,8 +1562,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1188
1562
|
}]
|
|
1189
1563
|
}], 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
1564
|
|
|
1565
|
+
/** @internal */
|
|
1191
1566
|
const STEPPER_I18N_DEFAULTS = {
|
|
1192
1567
|
stepperLabel: 'Stepper',
|
|
1568
|
+
stepIndicatorRoleDescription: 'Step indicator',
|
|
1193
1569
|
selectedStep: (label, position, count) => `Step ${position} of ${count}: ${label}`,
|
|
1194
1570
|
stepCompleted: 'Completed',
|
|
1195
1571
|
stepErrored: 'Has errors',
|
|
@@ -1200,12 +1576,27 @@ const STEPPER_I18N_DEFAULTS = {
|
|
|
1200
1576
|
commitInFlight: 'Committing step…',
|
|
1201
1577
|
commitRolledBackTo: (originLabel) => `Reverted to step "${originLabel}".`,
|
|
1202
1578
|
stepRolledBackSuffix: 'This step was rolled back.',
|
|
1579
|
+
statusLabels: {
|
|
1580
|
+
done: 'Done',
|
|
1581
|
+
inProgress: 'In progress',
|
|
1582
|
+
upNext: 'Up next',
|
|
1583
|
+
errored: 'Errored',
|
|
1584
|
+
},
|
|
1585
|
+
textStepperFormat: (current, total) => `Step ${current} of ${total}`,
|
|
1203
1586
|
};
|
|
1204
1587
|
/**
|
|
1205
1588
|
* DI token for the resolved stepper i18n bundle. `providedIn: 'root'`
|
|
1206
1589
|
* with English defaults.
|
|
1590
|
+
*
|
|
1591
|
+
* @category common/stepper/i18n
|
|
1592
|
+
* @wcag AA
|
|
1593
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/stepper/i18n/stepper-i18n.ts
|
|
1594
|
+
* @since 0.1.0
|
|
1207
1595
|
*/
|
|
1208
|
-
const CNGX_STEPPER_I18N = new InjectionToken('CngxStepperI18n', {
|
|
1596
|
+
const CNGX_STEPPER_I18N = new InjectionToken('CngxStepperI18n', {
|
|
1597
|
+
providedIn: 'root',
|
|
1598
|
+
factory: () => STEPPER_I18N_DEFAULTS,
|
|
1599
|
+
});
|
|
1209
1600
|
/**
|
|
1210
1601
|
* Brands an i18n mutator with `_target: 'i18n'`. Every `with*` i18n
|
|
1211
1602
|
* feature returns one of these.
|
|
@@ -1216,19 +1607,30 @@ function defineStepperI18nFeature(fn) {
|
|
|
1216
1607
|
return Object.assign(fn, { _target: 'i18n' });
|
|
1217
1608
|
}
|
|
1218
1609
|
/**
|
|
1219
|
-
* Override stepper i18n labels. Partial override
|
|
1220
|
-
* the English default.
|
|
1610
|
+
* Override stepper i18n labels. Partial override - unset keys keep
|
|
1611
|
+
* the English default. {@link CngxStepperStatusLabels} is merged
|
|
1612
|
+
* key-by-key so consumers can override one pill label without
|
|
1613
|
+
* restating the rest. Sibling of `withStepperAriaLabels` /
|
|
1221
1614
|
* `withStepperFallbackLabels`.
|
|
1615
|
+
*
|
|
1616
|
+
* @category common/stepper/i18n
|
|
1222
1617
|
*/
|
|
1223
1618
|
function withStepperI18nLabels(overrides) {
|
|
1224
|
-
return defineStepperI18nFeature((bundle) => ({
|
|
1619
|
+
return defineStepperI18nFeature((bundle) => ({
|
|
1620
|
+
...bundle,
|
|
1621
|
+
...overrides,
|
|
1622
|
+
statusLabels: overrides.statusLabels
|
|
1623
|
+
? { ...bundle.statusLabels, ...overrides.statusLabels }
|
|
1624
|
+
: bundle.statusLabels,
|
|
1625
|
+
}));
|
|
1225
1626
|
}
|
|
1627
|
+
/** @internal */
|
|
1226
1628
|
function resolveI18nFeatures(features) {
|
|
1227
1629
|
return features.reduce((bundle, feat) => feat(bundle), STEPPER_I18N_DEFAULTS);
|
|
1228
1630
|
}
|
|
1229
1631
|
/**
|
|
1230
1632
|
* Provider for the stepper i18n bundle. Compose `withStepperI18nLabels(...)`
|
|
1231
|
-
* (plus any future i18n `with*`)
|
|
1633
|
+
* (plus any future i18n `with*`) - unset keys fall back to English.
|
|
1232
1634
|
*
|
|
1233
1635
|
* ```ts
|
|
1234
1636
|
* bootstrapApplication(AppComponent, {
|
|
@@ -1239,6 +1641,8 @@ function resolveI18nFeatures(features) {
|
|
|
1239
1641
|
* ],
|
|
1240
1642
|
* });
|
|
1241
1643
|
* ```
|
|
1644
|
+
*
|
|
1645
|
+
* @category common/stepper/i18n
|
|
1242
1646
|
*/
|
|
1243
1647
|
function provideStepperI18n(...features) {
|
|
1244
1648
|
return {
|
|
@@ -1248,11 +1652,801 @@ function provideStepperI18n(...features) {
|
|
|
1248
1652
|
}
|
|
1249
1653
|
/**
|
|
1250
1654
|
* Inject the resolved stepper i18n bundle in an injection context.
|
|
1655
|
+
*
|
|
1656
|
+
* @category common/stepper/i18n
|
|
1251
1657
|
*/
|
|
1252
1658
|
function injectStepperI18n() {
|
|
1253
1659
|
return inject(CNGX_STEPPER_I18N);
|
|
1254
1660
|
}
|
|
1255
1661
|
|
|
1662
|
+
/**
|
|
1663
|
+
* Resolve the status-pill label for a step node against the resolved
|
|
1664
|
+
* i18n bundle. Used by skins that surface a per-step status pill
|
|
1665
|
+
* (e.g. `stripe-status-rich`). Pure factory - no injection context,
|
|
1666
|
+
* no signal graph involvement.
|
|
1667
|
+
*
|
|
1668
|
+
* Resolution order:
|
|
1669
|
+
* 1. `success` data-state -> `statusLabels.done`
|
|
1670
|
+
* 2. `error` data-state -> `statusLabels.errored`
|
|
1671
|
+
* 3. `aria-current="step"` -> `statusLabels.inProgress`
|
|
1672
|
+
* 4. otherwise -> `statusLabels.upNext`
|
|
1673
|
+
*
|
|
1674
|
+
* Group nodes (non-step) return an empty string.
|
|
1675
|
+
*
|
|
1676
|
+
* @category common/stepper
|
|
1677
|
+
*/
|
|
1678
|
+
function resolveStepperStatusLabel(node, i18n, isActive) {
|
|
1679
|
+
if (node.kind !== 'step') {
|
|
1680
|
+
return '';
|
|
1681
|
+
}
|
|
1682
|
+
const labels = i18n.statusLabels;
|
|
1683
|
+
const state = node.state();
|
|
1684
|
+
return state === 'success'
|
|
1685
|
+
? labels.done
|
|
1686
|
+
: state === 'error'
|
|
1687
|
+
? labels.errored
|
|
1688
|
+
: isActive
|
|
1689
|
+
? labels.inProgress
|
|
1690
|
+
: labels.upNext;
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1693
|
+
/**
|
|
1694
|
+
* Returns a reactive `Signal<boolean>` that reflects whether the host
|
|
1695
|
+
* window matches a CSS media query (e.g. `(max-width: 480px)`). Used by
|
|
1696
|
+
* `<cngx-stepper>` to drive its mobile auto-collapse template branch.
|
|
1697
|
+
*
|
|
1698
|
+
* In SSR / non-DOM environments the signal stays `false` and the
|
|
1699
|
+
* listener is never wired.
|
|
1700
|
+
*
|
|
1701
|
+
* @category common/stepper
|
|
1702
|
+
*/
|
|
1703
|
+
function createMobileViewportSignal(mediaQuery, destroyRef) {
|
|
1704
|
+
const matches = signal(false, ...(ngDevMode ? [{ debugName: "matches" }] : /* istanbul ignore next */ []));
|
|
1705
|
+
if (typeof globalThis.matchMedia !== 'function') {
|
|
1706
|
+
return matches.asReadonly();
|
|
1707
|
+
}
|
|
1708
|
+
const mql = globalThis.matchMedia(mediaQuery);
|
|
1709
|
+
matches.set(mql.matches);
|
|
1710
|
+
const listener = (event) => matches.set(event.matches);
|
|
1711
|
+
mql.addEventListener('change', listener);
|
|
1712
|
+
destroyRef.onDestroy(() => mql.removeEventListener('change', listener));
|
|
1713
|
+
return matches.asReadonly();
|
|
1714
|
+
}
|
|
1715
|
+
/**
|
|
1716
|
+
* Resolves the active stepper display mode by combining a viewport
|
|
1717
|
+
* media-query with the configured `mobileCollapse` policy.
|
|
1718
|
+
* `'classic'` keeps the full strip; `'text'` / `'dots'` swap to the
|
|
1719
|
+
* matching compact variant.
|
|
1720
|
+
*
|
|
1721
|
+
* @category common/stepper
|
|
1722
|
+
*/
|
|
1723
|
+
function createStepperDisplayMode(mediaQuery, mobileCollapse, destroyRef) {
|
|
1724
|
+
const viewport = createMobileViewportSignal(mediaQuery, destroyRef);
|
|
1725
|
+
return computed(() => {
|
|
1726
|
+
if (!viewport()) {
|
|
1727
|
+
return 'classic';
|
|
1728
|
+
}
|
|
1729
|
+
const mode = mobileCollapse() ?? 'text';
|
|
1730
|
+
return mode === 'off' ? 'classic' : mode;
|
|
1731
|
+
});
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1734
|
+
/**
|
|
1735
|
+
* Level-2 helper resolving the three host-attribute cascades for
|
|
1736
|
+
* `<cngx-stepper>` (skin / connectors / mobileIndicatorPosition). Keeps
|
|
1737
|
+
* the organism class under the LOC guard while making the cascade
|
|
1738
|
+
* pattern reusable for any future host-attr the strip surfaces.
|
|
1739
|
+
*
|
|
1740
|
+
* Each computed honors Pillar 1 (Ableitung statt Verwaltung): per-instance
|
|
1741
|
+
* input wins over root config wins over library default. No manual sync.
|
|
1742
|
+
*
|
|
1743
|
+
* @internal
|
|
1744
|
+
*/
|
|
1745
|
+
function createStepperHostAttrs(inputs) {
|
|
1746
|
+
return {
|
|
1747
|
+
resolvedSkin: computed(() => inputs.skin() ?? inputs.config.skin ?? 'classic'),
|
|
1748
|
+
resolvedConnectors: computed(() => inputs.connectors() ?? inputs.config.connectors ?? false),
|
|
1749
|
+
resolvedMobileIndicatorPosition: computed(() => inputs.mobileIndicatorPosition() ?? inputs.config.mobileIndicatorPosition ?? 'top'),
|
|
1750
|
+
};
|
|
1751
|
+
}
|
|
1752
|
+
|
|
1753
|
+
/**
|
|
1754
|
+
* Builds the WAI-ARIA APG arrow-key handler for a stepper strip. The
|
|
1755
|
+
* composed `CngxRovingTabindex` cannot reach view-template step buttons
|
|
1756
|
+
* (its `contentChildren` query only sees projected content), so the
|
|
1757
|
+
* organism wires this factory's return value to its host `(keydown)`
|
|
1758
|
+
* binding to honour the documented keyboard contract.
|
|
1759
|
+
*
|
|
1760
|
+
* Horizontal orientation: ArrowLeft / ArrowRight navigate. Vertical:
|
|
1761
|
+
* ArrowUp / ArrowDown. Home / End jump to the first / last flat step
|
|
1762
|
+
* regardless of orientation. The presenter's `select*` methods enforce
|
|
1763
|
+
* linear-mode gating so callers do not duplicate that check here.
|
|
1764
|
+
*
|
|
1765
|
+
* @internal
|
|
1766
|
+
*/
|
|
1767
|
+
function createStepperStripKeyboardNav(options) {
|
|
1768
|
+
const stepClass = options.stepClassName ?? 'cngx-stepper__step';
|
|
1769
|
+
const focusActive = () => {
|
|
1770
|
+
const activeId = options.presenter.activeStepId();
|
|
1771
|
+
if (!activeId) {
|
|
1772
|
+
return;
|
|
1773
|
+
}
|
|
1774
|
+
const buttonId = options.stepButtonIdFor(activeId);
|
|
1775
|
+
queueMicrotask(() => {
|
|
1776
|
+
const el = options.hostElement.querySelector(`[id="${buttonId}"]`);
|
|
1777
|
+
if (el instanceof HTMLElement) {
|
|
1778
|
+
el.focus();
|
|
1779
|
+
}
|
|
1780
|
+
});
|
|
1781
|
+
};
|
|
1782
|
+
return (event) => {
|
|
1783
|
+
const target = event.target;
|
|
1784
|
+
if (!target?.classList.contains(stepClass)) {
|
|
1785
|
+
return;
|
|
1786
|
+
}
|
|
1787
|
+
const isHorizontal = options.presenter.orientation() === 'horizontal';
|
|
1788
|
+
const nextKey = isHorizontal ? 'ArrowRight' : 'ArrowDown';
|
|
1789
|
+
const prevKey = isHorizontal ? 'ArrowLeft' : 'ArrowUp';
|
|
1790
|
+
if (event.key === nextKey) {
|
|
1791
|
+
event.preventDefault();
|
|
1792
|
+
options.presenter.selectNext();
|
|
1793
|
+
focusActive();
|
|
1794
|
+
}
|
|
1795
|
+
else if (event.key === prevKey) {
|
|
1796
|
+
event.preventDefault();
|
|
1797
|
+
options.presenter.selectPrevious();
|
|
1798
|
+
focusActive();
|
|
1799
|
+
}
|
|
1800
|
+
else if (event.key === 'Home') {
|
|
1801
|
+
event.preventDefault();
|
|
1802
|
+
options.presenter.select(0);
|
|
1803
|
+
focusActive();
|
|
1804
|
+
}
|
|
1805
|
+
else if (event.key === 'End') {
|
|
1806
|
+
event.preventDefault();
|
|
1807
|
+
options.presenter.select(options.flatStepCount() - 1);
|
|
1808
|
+
focusActive();
|
|
1809
|
+
}
|
|
1810
|
+
};
|
|
1811
|
+
}
|
|
1812
|
+
|
|
1813
|
+
/**
|
|
1814
|
+
* Wrap a `(node) => TContext` builder so identical results return the
|
|
1815
|
+
* same reference. Keyed by the node object via `WeakMap`, so step-list
|
|
1816
|
+
* re-emits drop stale entries automatically. The structural comparison
|
|
1817
|
+
* is shallow because every context shape is a flat object.
|
|
1818
|
+
*
|
|
1819
|
+
* @internal
|
|
1820
|
+
*/
|
|
1821
|
+
function memoizeByNode(build) {
|
|
1822
|
+
const cache = new WeakMap();
|
|
1823
|
+
return (node) => {
|
|
1824
|
+
const next = build(node);
|
|
1825
|
+
const prev = cache.get(node);
|
|
1826
|
+
if (prev !== undefined && shallowEqual(prev, next)) {
|
|
1827
|
+
return prev;
|
|
1828
|
+
}
|
|
1829
|
+
cache.set(node, next);
|
|
1830
|
+
return next;
|
|
1831
|
+
};
|
|
1832
|
+
}
|
|
1833
|
+
/** @internal */
|
|
1834
|
+
function shallowEqual(a, b) {
|
|
1835
|
+
if (a === b) {
|
|
1836
|
+
return true;
|
|
1837
|
+
}
|
|
1838
|
+
const keysA = Object.keys(a);
|
|
1839
|
+
if (keysA.length !== Object.keys(b).length) {
|
|
1840
|
+
return false;
|
|
1841
|
+
}
|
|
1842
|
+
const ra = a;
|
|
1843
|
+
const rb = b;
|
|
1844
|
+
for (const k of keysA) {
|
|
1845
|
+
if (ra[k] !== rb[k]) {
|
|
1846
|
+
return false;
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
return true;
|
|
1850
|
+
}
|
|
1851
|
+
/**
|
|
1852
|
+
* Bundle the six `*ContextFor` slot-context builders plus the small
|
|
1853
|
+
* `isActive` / `isStepBusy` / `showRejection` / `showErrorBadge` predicates
|
|
1854
|
+
* the organism's template reads. Lives at Level 2 so the `<cngx-stepper>`
|
|
1855
|
+
* organism stays a thin shell per `reference_atomic_decompose`.
|
|
1856
|
+
*
|
|
1857
|
+
* @internal
|
|
1858
|
+
*/
|
|
1859
|
+
function createStepperSlotContextBuilders(inputs) {
|
|
1860
|
+
const { presenter, stepsOnly } = inputs;
|
|
1861
|
+
const isActive = (node) => node.kind === 'step' && node.id === presenter.activeStepId();
|
|
1862
|
+
const isStepBusy = (node) => node.kind === 'step' &&
|
|
1863
|
+
presenter.commitState.status() === 'pending' &&
|
|
1864
|
+
presenter.intendedStepIndex() === node.flatIndex;
|
|
1865
|
+
const showRejection = (node) => node.kind === 'step' &&
|
|
1866
|
+
node.flatIndex >= 0 &&
|
|
1867
|
+
node.flatIndex === presenter.lastFailedIndex();
|
|
1868
|
+
const showErrorBadge = (node) => {
|
|
1869
|
+
if (node.kind !== 'step') {
|
|
1870
|
+
return false;
|
|
1871
|
+
}
|
|
1872
|
+
if (node.state() === 'error') {
|
|
1873
|
+
return true;
|
|
1874
|
+
}
|
|
1875
|
+
return !!node.errorAggregator?.()?.shouldShow?.();
|
|
1876
|
+
};
|
|
1877
|
+
// Memoize per-node so identical contexts return the same reference.
|
|
1878
|
+
// *ngTemplateOutlet pays an ngOnChanges shallow comparison on its
|
|
1879
|
+
// `context:` binding every CD pass; without this cache the outlet
|
|
1880
|
+
// sees a fresh literal each tick and re-pushes context to the
|
|
1881
|
+
// embedded view even when no source signal changed. Cache keys are
|
|
1882
|
+
// the node objects themselves so the WeakMap evicts naturally with
|
|
1883
|
+
// step-list re-emits.
|
|
1884
|
+
const indicatorContextFor = memoizeByNode((node) => {
|
|
1885
|
+
const position = node.flatIndex + 1;
|
|
1886
|
+
return {
|
|
1887
|
+
$implicit: position,
|
|
1888
|
+
position,
|
|
1889
|
+
node,
|
|
1890
|
+
active: isActive(node),
|
|
1891
|
+
status: node.state(),
|
|
1892
|
+
busy: isStepBusy(node),
|
|
1893
|
+
};
|
|
1894
|
+
});
|
|
1895
|
+
const badgeContextFor = memoizeByNode((node) => {
|
|
1896
|
+
const aggregator = node.errorAggregator?.();
|
|
1897
|
+
const count = aggregator?.errorCount() ?? 0;
|
|
1898
|
+
return { count, node };
|
|
1899
|
+
});
|
|
1900
|
+
const busySpinnerContextFor = memoizeByNode((node) => ({ node }));
|
|
1901
|
+
const rejectionContextFor = memoizeByNode((node) => {
|
|
1902
|
+
const failedIndex = node.flatIndex;
|
|
1903
|
+
const originIdx = presenter.originIndexDuringCommit();
|
|
1904
|
+
const originLabel = originIdx !== undefined ? stepsOnly()[originIdx]?.label() : undefined;
|
|
1905
|
+
return { failedIndex, originLabel, node };
|
|
1906
|
+
});
|
|
1907
|
+
const groupHeaderContextFor = memoizeByNode((node) => ({
|
|
1908
|
+
group: node,
|
|
1909
|
+
expanded: true,
|
|
1910
|
+
status: node.state(),
|
|
1911
|
+
}));
|
|
1912
|
+
const stepLabelContextFor = memoizeByNode((node) => ({
|
|
1913
|
+
node,
|
|
1914
|
+
index: node.flatIndex + 1,
|
|
1915
|
+
active: isActive(node),
|
|
1916
|
+
busy: isStepBusy(node),
|
|
1917
|
+
disabled: node.disabled(),
|
|
1918
|
+
}));
|
|
1919
|
+
// Independent builder + independent cache: content + label contexts
|
|
1920
|
+
// share a shape today but the slot directives are separate contracts
|
|
1921
|
+
// (CngxStepContentContext vs CngxStepLabelContext) and will diverge
|
|
1922
|
+
// when one side gains a field. Aliasing the function would couple
|
|
1923
|
+
// both call sites to that future divergence.
|
|
1924
|
+
const stepContentContextFor = memoizeByNode((node) => ({
|
|
1925
|
+
node,
|
|
1926
|
+
index: node.flatIndex + 1,
|
|
1927
|
+
active: isActive(node),
|
|
1928
|
+
busy: isStepBusy(node),
|
|
1929
|
+
disabled: node.disabled(),
|
|
1930
|
+
}));
|
|
1931
|
+
return {
|
|
1932
|
+
isActive,
|
|
1933
|
+
isStepBusy,
|
|
1934
|
+
showRejection,
|
|
1935
|
+
showErrorBadge,
|
|
1936
|
+
indicatorContextFor,
|
|
1937
|
+
badgeContextFor,
|
|
1938
|
+
busySpinnerContextFor,
|
|
1939
|
+
rejectionContextFor,
|
|
1940
|
+
groupHeaderContextFor,
|
|
1941
|
+
stepLabelContextFor,
|
|
1942
|
+
stepContentContextFor,
|
|
1943
|
+
};
|
|
1944
|
+
}
|
|
1945
|
+
|
|
1946
|
+
/**
|
|
1947
|
+
* Build the reactive SR-announcement surface for `<cngx-stepper>`.
|
|
1948
|
+
* Lives at Level 2 so the Level-4 organism stays a thin shell per
|
|
1949
|
+
* `reference_atomic_decompose`.
|
|
1950
|
+
*
|
|
1951
|
+
* @internal
|
|
1952
|
+
*/
|
|
1953
|
+
function createStepperAnnouncementBuilders(inputs) {
|
|
1954
|
+
const { presenter, stepsOnly, i18n } = inputs;
|
|
1955
|
+
const liveAnnouncement = computed(() => {
|
|
1956
|
+
const current = presenter.commitTransition.current();
|
|
1957
|
+
if (current === 'pending') {
|
|
1958
|
+
return i18n.commitInFlight;
|
|
1959
|
+
}
|
|
1960
|
+
if (current === 'error') {
|
|
1961
|
+
// Sync commit-handler errors collapse pending -> error in one signal
|
|
1962
|
+
// flush; tracker sees `previous === 'idle'`. Guard stays loose so
|
|
1963
|
+
// sync-rejection (`commitAction = () => false`) still announces.
|
|
1964
|
+
const failedIdx = presenter.lastFailedIndex();
|
|
1965
|
+
const originIdx = presenter.originIndexDuringCommit();
|
|
1966
|
+
if (failedIdx !== undefined && originIdx !== undefined) {
|
|
1967
|
+
const originLabel = stepsOnly()[originIdx]?.label();
|
|
1968
|
+
if (originLabel) {
|
|
1969
|
+
return i18n.commitRolledBackTo(originLabel);
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
return i18n.commitFailedRetry;
|
|
1973
|
+
}
|
|
1974
|
+
return '';
|
|
1975
|
+
}, ...(ngDevMode ? [{ debugName: "liveAnnouncement" }] : /* istanbul ignore next */ []));
|
|
1976
|
+
const statusPhrase = (node) => {
|
|
1977
|
+
const aggregator = node.errorAggregator?.();
|
|
1978
|
+
let base = aggregator?.shouldShow?.() ? (aggregator.announcement?.() ?? '') : '';
|
|
1979
|
+
if (!base && node.kind === 'step') {
|
|
1980
|
+
const idx = node.flatIndex;
|
|
1981
|
+
if (idx >= 0) {
|
|
1982
|
+
base = i18n.selectedStep(node.label(), idx + 1, stepsOnly().length);
|
|
1983
|
+
}
|
|
1984
|
+
}
|
|
1985
|
+
if (!base) {
|
|
1986
|
+
return '';
|
|
1987
|
+
}
|
|
1988
|
+
return node.kind === 'step' && node.flatIndex === presenter.lastFailedIndex()
|
|
1989
|
+
? `${base} ${i18n.stepRolledBackSuffix}`
|
|
1990
|
+
: base;
|
|
1991
|
+
};
|
|
1992
|
+
const groupStatusPhrase = (node) => {
|
|
1993
|
+
const status = node.state();
|
|
1994
|
+
if (status === 'error') {
|
|
1995
|
+
return i18n.stepErrored;
|
|
1996
|
+
}
|
|
1997
|
+
if (status === 'success') {
|
|
1998
|
+
return i18n.stepCompleted;
|
|
1999
|
+
}
|
|
2000
|
+
return '';
|
|
2001
|
+
};
|
|
2002
|
+
return { liveAnnouncement, statusPhrase, groupStatusPhrase };
|
|
2003
|
+
}
|
|
2004
|
+
|
|
2005
|
+
/**
|
|
2006
|
+
* Routes a `CngxSwipe` gesture into the stepper presenter so the
|
|
2007
|
+
* organism's mobile-collapse panels gain swipe-driven navigation
|
|
2008
|
+
* without duplicating pointer handling. Applied via `hostDirectives`
|
|
2009
|
+
* on `<cngx-stepper>`; consumer-facing input `[mobileSwipe]` is
|
|
2010
|
+
* forwarded through the host metadata.
|
|
2011
|
+
*
|
|
2012
|
+
* Cascade for `swipeEnabled`: per-instance `[mobileSwipe]` ->
|
|
2013
|
+
* `CNGX_STEPPER_CONFIG.mobileSwipe` -> library default `true`.
|
|
2014
|
+
*
|
|
2015
|
+
* Direction routing is asymmetric, matching the presenter's existing
|
|
2016
|
+
* navigation surface: `left` -> `selectNext()` -> `select()` (linear
|
|
2017
|
+
* gate + commit window apply identically to a click); `right` ->
|
|
2018
|
+
* `selectPrevious()` (ungated direct back-move, same path as the
|
|
2019
|
+
* existing strip back-nav).
|
|
2020
|
+
*
|
|
2021
|
+
* @category common/stepper
|
|
2022
|
+
* @docsKind primary
|
|
2023
|
+
* @wcag AA
|
|
2024
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/stepper/swipe-nav.directive.ts
|
|
2025
|
+
* @since 0.1.0
|
|
2026
|
+
*/
|
|
2027
|
+
class CngxStepperSwipeNav {
|
|
2028
|
+
/**
|
|
2029
|
+
* Per-instance opt-out for the built-in swipe navigation. `undefined`
|
|
2030
|
+
* defers to the config cascade.
|
|
2031
|
+
*/
|
|
2032
|
+
mobileSwipe = input(undefined, ...(ngDevMode ? [{ debugName: "mobileSwipe" }] : /* istanbul ignore next */ []));
|
|
2033
|
+
host = inject(CNGX_STEPPER_HOST);
|
|
2034
|
+
config = injectStepperConfig();
|
|
2035
|
+
/** Resolved enabled flag (Input -> config -> default(true)). Boolean output, no `equal` fn required. */
|
|
2036
|
+
swipeEnabled = computed(() => this.mobileSwipe() ?? this.config.mobileSwipe ?? true, ...(ngDevMode ? [{ debugName: "swipeEnabled" }] : /* istanbul ignore next */ []));
|
|
2037
|
+
/**
|
|
2038
|
+
* Route a swipe direction into the presenter. `left` and `right`
|
|
2039
|
+
* map onto `selectNext` and `selectPrevious`; vertical directions
|
|
2040
|
+
* are ignored.
|
|
2041
|
+
*/
|
|
2042
|
+
handleSwipe(direction) {
|
|
2043
|
+
if (direction === 'left') {
|
|
2044
|
+
this.host.selectNext();
|
|
2045
|
+
}
|
|
2046
|
+
else if (direction === 'right') {
|
|
2047
|
+
this.host.selectPrevious();
|
|
2048
|
+
}
|
|
2049
|
+
}
|
|
2050
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStepperSwipeNav, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
2051
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxStepperSwipeNav, isStandalone: true, selector: "[cngxStepperSwipeNav]", inputs: { mobileSwipe: { classPropertyName: "mobileSwipe", publicName: "mobileSwipe", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0 });
|
|
2052
|
+
}
|
|
2053
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStepperSwipeNav, decorators: [{
|
|
2054
|
+
type: Directive,
|
|
2055
|
+
args: [{
|
|
2056
|
+
selector: '[cngxStepperSwipeNav]',
|
|
2057
|
+
standalone: true,
|
|
2058
|
+
}]
|
|
2059
|
+
}], propDecorators: { mobileSwipe: [{ type: i0.Input, args: [{ isSignal: true, alias: "mobileSwipe", required: false }] }] } });
|
|
2060
|
+
|
|
2061
|
+
/**
|
|
2062
|
+
* Reusable progress-hint atom for any stepper organism. Renders the
|
|
2063
|
+
* resolved `CngxStepperI18n.textStepperFormat(current, total)` string
|
|
2064
|
+
* inside a `<span>` and pipes the value through an `aria-live` region
|
|
2065
|
+
* so screen readers announce step transitions.
|
|
2066
|
+
*
|
|
2067
|
+
* The text shape is fully owned by the i18n format function - drop the
|
|
2068
|
+
* atom inside any `<cngx-stepper>` / `<cngx-mat-stepper>` /
|
|
2069
|
+
* `<cngx-progress-bar-stepper>` tree and override the format upstream
|
|
2070
|
+
* to change every instance at once:
|
|
2071
|
+
*
|
|
2072
|
+
* ```ts
|
|
2073
|
+
* provideStepperI18n(withStepperI18nLabels({
|
|
2074
|
+
* textStepperFormat: (c, t) => `${c}/${t} complete`,
|
|
2075
|
+
* }));
|
|
2076
|
+
* ```
|
|
2077
|
+
*
|
|
2078
|
+
* Canonical shapes the atom supports without any markup changes:
|
|
2079
|
+
* - `Step N of M` (default)
|
|
2080
|
+
* - `N/M complete`
|
|
2081
|
+
* - `N/M`
|
|
2082
|
+
* - `Math.round(c/t * 100)%`
|
|
2083
|
+
* - any consumer-defined string the closure returns.
|
|
2084
|
+
*
|
|
2085
|
+
* `[live]="false"` opts the atom out of the `aria-live` region when
|
|
2086
|
+
* the caption sits next to another live region (e.g. a stepper that
|
|
2087
|
+
* already mounts its own live announcer) to prevent double announces.
|
|
2088
|
+
*
|
|
2089
|
+
* @category common/stepper
|
|
2090
|
+
* @docsKind primary
|
|
2091
|
+
* @since 0.1.0
|
|
2092
|
+
* @relatedTo CngxStepperHost, CngxStepperI18n
|
|
2093
|
+
* <example-url>http://localhost:4200/#/ui/stepper/stepper-count/multi-instance-format-overrides</example-url>
|
|
2094
|
+
*/
|
|
2095
|
+
class CngxStepperCount {
|
|
2096
|
+
/** When `true`, wraps the rendered string in an `aria-live="polite"` span. */
|
|
2097
|
+
live = input(true, ...(ngDevMode ? [{ debugName: "live" }] : /* istanbul ignore next */ []));
|
|
2098
|
+
/**
|
|
2099
|
+
* Per-instance format override. Receives `(current, total)` where
|
|
2100
|
+
* `current` is the 1-based active step position and `total` is
|
|
2101
|
+
* `host.stepsOnly().length`. When omitted, the resolved
|
|
2102
|
+
* `CngxStepperI18n.textStepperFormat` is used so two siblings can
|
|
2103
|
+
* each show a different shape inside the same stepper tree.
|
|
2104
|
+
*/
|
|
2105
|
+
format = input(undefined, ...(ngDevMode ? [{ debugName: "format" }] : /* istanbul ignore next */ []));
|
|
2106
|
+
/**
|
|
2107
|
+
* Explicit stepper-host reference. Set this when the atom sits
|
|
2108
|
+
* *outside* a `<cngx-stepper>` (e.g. in a sibling layout header)
|
|
2109
|
+
* by exporting the stepper as a template ref:
|
|
2110
|
+
* `<cngx-stepper #s="cngxStepper">` then `[host]="s.presenter"`.
|
|
2111
|
+
* When unset, the atom injects the ambient `CNGX_STEPPER_HOST` from
|
|
2112
|
+
* its DI tree. Accepts {@link CngxStepperCountHost} so a narrow stub
|
|
2113
|
+
* (active index + steps signal) also fits.
|
|
2114
|
+
*/
|
|
2115
|
+
host = input(null, ...(ngDevMode ? [{ debugName: "host" }] : /* istanbul ignore next */ []));
|
|
2116
|
+
injectedHost = inject(CNGX_STEPPER_HOST, { optional: true });
|
|
2117
|
+
i18n = injectStepperI18n();
|
|
2118
|
+
resolvedHost = computed(() => this.host() ?? this.injectedHost, ...(ngDevMode ? [{ debugName: "resolvedHost" }] : /* istanbul ignore next */ []));
|
|
2119
|
+
/** Resolved caption - reactive on activeStepIndex / stepsOnly / format / i18n. */
|
|
2120
|
+
label = computed(() => {
|
|
2121
|
+
const host = this.resolvedHost();
|
|
2122
|
+
if (!host) {
|
|
2123
|
+
return '';
|
|
2124
|
+
}
|
|
2125
|
+
const current = host.activeStepIndex() + 1;
|
|
2126
|
+
const total = host.stepsOnly().length;
|
|
2127
|
+
const fmt = this.format() ?? this.i18n.textStepperFormat;
|
|
2128
|
+
return fmt(current, total);
|
|
2129
|
+
}, ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
|
|
2130
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStepperCount, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
2131
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "21.2.4", type: CngxStepperCount, isStandalone: true, selector: "cngx-stepper-count", inputs: { live: { classPropertyName: "live", publicName: "live", isSignal: true, isRequired: false, transformFunction: null }, format: { classPropertyName: "format", publicName: "format", isSignal: true, isRequired: false, transformFunction: null }, host: { classPropertyName: "host", publicName: "host", isSignal: true, isRequired: false, transformFunction: null } }, host: { classAttribute: "cngx-stepper-count" }, ngImport: i0, template: '<span [attr.aria-live]="live() ? \'polite\' : null">{{ label() }}</span>', isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
2132
|
+
}
|
|
2133
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStepperCount, decorators: [{
|
|
2134
|
+
type: Component,
|
|
2135
|
+
args: [{
|
|
2136
|
+
selector: 'cngx-stepper-count',
|
|
2137
|
+
standalone: true,
|
|
2138
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
2139
|
+
encapsulation: ViewEncapsulation.None,
|
|
2140
|
+
template: '<span [attr.aria-live]="live() ? \'polite\' : null">{{ label() }}</span>',
|
|
2141
|
+
host: {
|
|
2142
|
+
class: 'cngx-stepper-count',
|
|
2143
|
+
},
|
|
2144
|
+
}]
|
|
2145
|
+
}], propDecorators: { live: [{ type: i0.Input, args: [{ isSignal: true, alias: "live", required: false }] }], format: [{ type: i0.Input, args: [{ isSignal: true, alias: "format", required: false }] }], host: [{ type: i0.Input, args: [{ isSignal: true, alias: "host", required: false }] }] } });
|
|
2146
|
+
|
|
2147
|
+
/**
|
|
2148
|
+
* Turns any clickable element into a stepper "Back" control. Resolves
|
|
2149
|
+
* its host the same way `CngxStepperCount` does - an explicit `[host]`
|
|
2150
|
+
* input (for placement outside the stepper tree) falling back to the
|
|
2151
|
+
* ambient {@link CNGX_STEPPER_HOST}.
|
|
2152
|
+
*
|
|
2153
|
+
* `(click)` retreats via `selectPrevious()`. The control disables itself
|
|
2154
|
+
* when there is no earlier step (`!canGoPrevious()`) OR while a commit is
|
|
2155
|
+
* in flight (`busy()`): `selectPrevious()` writes `activeStepIndex`
|
|
2156
|
+
* directly, bypassing the commit controller, so disabling it during an
|
|
2157
|
+
* in-flight forward commit prevents a navigate-mid-commit race. The gate
|
|
2158
|
+
* is the host's `canGoPrevious` bound - never re-derived from `stepsOnly`.
|
|
2159
|
+
*
|
|
2160
|
+
* Reflects the disabled state via `aria-disabled` only - never native
|
|
2161
|
+
* `disabled` - so the control stays focusable and AT-reachable; the
|
|
2162
|
+
* `handleClick` guard blocks the action while disabled.
|
|
2163
|
+
*
|
|
2164
|
+
* ```html
|
|
2165
|
+
* <button cngxStepperPrevious>Back</button>
|
|
2166
|
+
* ```
|
|
2167
|
+
*
|
|
2168
|
+
* @category common/stepper
|
|
2169
|
+
* @docsKind primary
|
|
2170
|
+
* @wcag AA
|
|
2171
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/stepper/controls/stepper-previous.directive.ts
|
|
2172
|
+
* @since 0.1.0
|
|
2173
|
+
* @relatedTo CngxStepperNext, CngxStepperComplete, CngxStepperHost
|
|
2174
|
+
*/
|
|
2175
|
+
class CngxStepperPrevious {
|
|
2176
|
+
/**
|
|
2177
|
+
* Explicit stepper-host reference for placement *outside* the stepper
|
|
2178
|
+
* tree (`[host]="s.presenter"`). When unset, the ambient
|
|
2179
|
+
* {@link CNGX_STEPPER_HOST} is injected.
|
|
2180
|
+
*/
|
|
2181
|
+
host = input(null, ...(ngDevMode ? [{ debugName: "host" }] : /* istanbul ignore next */ []));
|
|
2182
|
+
injectedHost = inject(CNGX_STEPPER_HOST, { optional: true });
|
|
2183
|
+
resolvedHost = computed(() => this.host() ?? this.injectedHost, ...(ngDevMode ? [{ debugName: "resolvedHost" }] : /* istanbul ignore next */ []));
|
|
2184
|
+
coPlacedAsyncClick = inject(CngxAsyncClick, { self: true, optional: true });
|
|
2185
|
+
constructor() {
|
|
2186
|
+
if (isDevMode() && this.coPlacedAsyncClick) {
|
|
2187
|
+
console.warn('CngxStepperPrevious: [cngxStepperPrevious] and [cngxAsyncClick] on the same element ' +
|
|
2188
|
+
'both gate aria-disabled. Use one or the other.');
|
|
2189
|
+
}
|
|
2190
|
+
}
|
|
2191
|
+
/** `true` when retreat is unavailable: no earlier step or commit busy. */
|
|
2192
|
+
disabled = computed(() => {
|
|
2193
|
+
const host = this.resolvedHost();
|
|
2194
|
+
return !host || !host.canGoPrevious() || host.busy();
|
|
2195
|
+
}, ...(ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []));
|
|
2196
|
+
/** @internal */
|
|
2197
|
+
handleClick(event) {
|
|
2198
|
+
if (this.disabled()) {
|
|
2199
|
+
event.preventDefault();
|
|
2200
|
+
return;
|
|
2201
|
+
}
|
|
2202
|
+
this.resolvedHost()?.selectPrevious();
|
|
2203
|
+
}
|
|
2204
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStepperPrevious, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
2205
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxStepperPrevious, isStandalone: true, selector: "[cngxStepperPrevious]", inputs: { host: { classPropertyName: "host", publicName: "host", isSignal: true, isRequired: false, transformFunction: null } }, host: { listeners: { "click": "handleClick($event)" }, properties: { "attr.aria-disabled": "disabled() || null" } }, exportAs: ["cngxStepperPrevious"], ngImport: i0 });
|
|
2206
|
+
}
|
|
2207
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStepperPrevious, decorators: [{
|
|
2208
|
+
type: Directive,
|
|
2209
|
+
args: [{
|
|
2210
|
+
selector: '[cngxStepperPrevious]',
|
|
2211
|
+
standalone: true,
|
|
2212
|
+
exportAs: 'cngxStepperPrevious',
|
|
2213
|
+
host: {
|
|
2214
|
+
'(click)': 'handleClick($event)',
|
|
2215
|
+
'[attr.aria-disabled]': 'disabled() || null',
|
|
2216
|
+
},
|
|
2217
|
+
}]
|
|
2218
|
+
}], ctorParameters: () => [], propDecorators: { host: [{ type: i0.Input, args: [{ isSignal: true, alias: "host", required: false }] }] } });
|
|
2219
|
+
|
|
2220
|
+
/**
|
|
2221
|
+
* Turns any clickable element into a stepper "Continue" control. Same
|
|
2222
|
+
* host resolution as `CngxStepperCount` - explicit `[host]` input
|
|
2223
|
+
* falling back to the ambient {@link CNGX_STEPPER_HOST}.
|
|
2224
|
+
*
|
|
2225
|
+
* `(click)` advances via `selectNext()`. A turnkey re-entrancy guard
|
|
2226
|
+
* disables the control when there is no enabled next step
|
|
2227
|
+
* (`!canGoNext()`) OR while a commit is in flight (`busy()`) - an opt-in
|
|
2228
|
+
* guard a consumer forgets is a silent double-commit (Pillar 2). The
|
|
2229
|
+
* gate reads the host's `canGoNext` bound, which derives from the same
|
|
2230
|
+
* `select()` predicates, so the affordance can never drift from the
|
|
2231
|
+
* navigation it triggers.
|
|
2232
|
+
*
|
|
2233
|
+
* Reflects the disabled state via `aria-disabled` only - never native
|
|
2234
|
+
* `disabled` (which would steal focus, so AT could not reach the control
|
|
2235
|
+
* to learn it is at-a-bound / busy) and never `aria-busy` (that is
|
|
2236
|
+
* `CngxAsyncStatus`'s sole responsibility). The `handleClick` guard
|
|
2237
|
+
* blocks the action while disabled. Co-placing `[cngxAsyncClick]` here
|
|
2238
|
+
* (which also gates `aria-disabled` and adds native `disabled`) warns in
|
|
2239
|
+
* dev mode.
|
|
2240
|
+
*
|
|
2241
|
+
* ```html
|
|
2242
|
+
* <button cngxStepperNext>Continue</button>
|
|
2243
|
+
* ```
|
|
2244
|
+
*
|
|
2245
|
+
* @category common/stepper
|
|
2246
|
+
* @docsKind primary
|
|
2247
|
+
* @wcag AA
|
|
2248
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/stepper/controls/stepper-next.directive.ts
|
|
2249
|
+
* @since 0.1.0
|
|
2250
|
+
* @relatedTo CngxStepperPrevious, CngxStepperComplete, CngxAsyncStatus, CngxStepperHost
|
|
2251
|
+
*/
|
|
2252
|
+
class CngxStepperNext {
|
|
2253
|
+
/**
|
|
2254
|
+
* Explicit stepper-host reference for placement *outside* the stepper
|
|
2255
|
+
* tree (`[host]="s.presenter"`). When unset, the ambient
|
|
2256
|
+
* {@link CNGX_STEPPER_HOST} is injected.
|
|
2257
|
+
*/
|
|
2258
|
+
host = input(null, ...(ngDevMode ? [{ debugName: "host" }] : /* istanbul ignore next */ []));
|
|
2259
|
+
injectedHost = inject(CNGX_STEPPER_HOST, { optional: true });
|
|
2260
|
+
resolvedHost = computed(() => this.host() ?? this.injectedHost, ...(ngDevMode ? [{ debugName: "resolvedHost" }] : /* istanbul ignore next */ []));
|
|
2261
|
+
coPlacedAsyncClick = inject(CngxAsyncClick, { self: true, optional: true });
|
|
2262
|
+
/** `true` when advancing is unavailable: no enabled next step or commit busy. */
|
|
2263
|
+
disabled = computed(() => {
|
|
2264
|
+
const host = this.resolvedHost();
|
|
2265
|
+
return !host || !host.canGoNext() || host.busy();
|
|
2266
|
+
}, ...(ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []));
|
|
2267
|
+
constructor() {
|
|
2268
|
+
if (isDevMode() && this.coPlacedAsyncClick) {
|
|
2269
|
+
console.warn('CngxStepperNext: [cngxStepperNext] and [cngxAsyncClick] on the same element ' +
|
|
2270
|
+
'both gate aria-disabled (and cngxAsyncClick adds native [disabled]). Use one or the other.');
|
|
2271
|
+
}
|
|
2272
|
+
}
|
|
2273
|
+
/** @internal */
|
|
2274
|
+
handleClick(event) {
|
|
2275
|
+
if (this.disabled()) {
|
|
2276
|
+
event.preventDefault();
|
|
2277
|
+
return;
|
|
2278
|
+
}
|
|
2279
|
+
this.resolvedHost()?.selectNext();
|
|
2280
|
+
}
|
|
2281
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStepperNext, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
2282
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxStepperNext, isStandalone: true, selector: "[cngxStepperNext]", inputs: { host: { classPropertyName: "host", publicName: "host", isSignal: true, isRequired: false, transformFunction: null } }, host: { listeners: { "click": "handleClick($event)" }, properties: { "attr.aria-disabled": "disabled() || null" } }, exportAs: ["cngxStepperNext"], ngImport: i0 });
|
|
2283
|
+
}
|
|
2284
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStepperNext, decorators: [{
|
|
2285
|
+
type: Directive,
|
|
2286
|
+
args: [{
|
|
2287
|
+
selector: '[cngxStepperNext]',
|
|
2288
|
+
standalone: true,
|
|
2289
|
+
exportAs: 'cngxStepperNext',
|
|
2290
|
+
host: {
|
|
2291
|
+
'(click)': 'handleClick($event)',
|
|
2292
|
+
'[attr.aria-disabled]': 'disabled() || null',
|
|
2293
|
+
},
|
|
2294
|
+
}]
|
|
2295
|
+
}], ctorParameters: () => [], propDecorators: { host: [{ type: i0.Input, args: [{ isSignal: true, alias: "host", required: false }] }] } });
|
|
2296
|
+
|
|
2297
|
+
/**
|
|
2298
|
+
* Turns any clickable element into a stepper "Finish" control. Unlike
|
|
2299
|
+
* `CngxStepperNext` (which *reflects* the commit state and advances),
|
|
2300
|
+
* the finish action *runs*: the directive composes `CngxAsyncClick` via
|
|
2301
|
+
* `hostDirectives`, so the runner owns the click lifecycle, `aria-busy`,
|
|
2302
|
+
* and the pending-disable exactly as it does on a standalone button. The
|
|
2303
|
+
* finish action is fed through the aliased `[cngxStepperComplete]` input.
|
|
2304
|
+
*
|
|
2305
|
+
* Resolves its host like the sibling controls - explicit `[host]` input
|
|
2306
|
+
* falling back to the ambient {@link CNGX_STEPPER_HOST}. {@link isActive}
|
|
2307
|
+
* exposes whether the active step is the last one, so a consumer renders
|
|
2308
|
+
* the finish control only on the final step. `(completed)` emits once
|
|
2309
|
+
* after the action resolves successfully.
|
|
2310
|
+
*
|
|
2311
|
+
* ```html
|
|
2312
|
+
* @if (s.presenter.isLastStep()) {
|
|
2313
|
+
* <button [cngxStepperComplete]="submit" (completed)="done()">Finish</button>
|
|
2314
|
+
* }
|
|
2315
|
+
* ```
|
|
2316
|
+
*
|
|
2317
|
+
* @category common/stepper
|
|
2318
|
+
* @docsKind primary
|
|
2319
|
+
* @wcag AA
|
|
2320
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/stepper/controls/stepper-complete.directive.ts
|
|
2321
|
+
* @since 0.1.0
|
|
2322
|
+
* @relatedTo CngxStepperNext, CngxStepperPrevious, CngxAsyncClick, CngxStepperHost
|
|
2323
|
+
*/
|
|
2324
|
+
class CngxStepperComplete {
|
|
2325
|
+
/**
|
|
2326
|
+
* Explicit stepper-host reference for placement *outside* the stepper
|
|
2327
|
+
* tree (`[host]="s.presenter"`). When unset, the ambient
|
|
2328
|
+
* {@link CNGX_STEPPER_HOST} is injected.
|
|
2329
|
+
*/
|
|
2330
|
+
host = input(null, ...(ngDevMode ? [{ debugName: "host" }] : /* istanbul ignore next */ []));
|
|
2331
|
+
/**
|
|
2332
|
+
* Emits once per `pending → success` transition of the finish action.
|
|
2333
|
+
* Does NOT re-emit when the `feedbackDuration` window resets the runner
|
|
2334
|
+
* back to idle - the transition tracker guards on the success edge only.
|
|
2335
|
+
*/
|
|
2336
|
+
completed = output();
|
|
2337
|
+
injectedHost = inject(CNGX_STEPPER_HOST, { optional: true });
|
|
2338
|
+
resolvedHost = computed(() => this.host() ?? this.injectedHost, ...(ngDevMode ? [{ debugName: "resolvedHost" }] : /* istanbul ignore next */ []));
|
|
2339
|
+
runner = inject(CngxAsyncClick, { host: true });
|
|
2340
|
+
/** `true` when the active step is the last one - the finish step. */
|
|
2341
|
+
isActive = computed(() => this.resolvedHost()?.isLastStep() ?? false, ...(ngDevMode ? [{ debugName: "isActive" }] : /* istanbul ignore next */ []));
|
|
2342
|
+
constructor() {
|
|
2343
|
+
const tracker = createTransitionTracker(() => this.runner.status());
|
|
2344
|
+
effect(() => {
|
|
2345
|
+
if (tracker.current() === 'success' && tracker.previous() !== 'success') {
|
|
2346
|
+
this.completed.emit();
|
|
2347
|
+
}
|
|
2348
|
+
});
|
|
2349
|
+
}
|
|
2350
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStepperComplete, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
2351
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxStepperComplete, isStandalone: true, selector: "[cngxStepperComplete]", inputs: { host: { classPropertyName: "host", publicName: "host", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { completed: "completed" }, exportAs: ["cngxStepperComplete"], hostDirectives: [{ directive: i1.CngxAsyncClick, inputs: ["cngxAsyncClick", "cngxStepperComplete", "feedbackDuration", "feedbackDuration", "enabled", "enabled", "succeededAnnouncement", "succeededAnnouncement", "failedAnnouncement", "failedAnnouncement"] }], ngImport: i0 });
|
|
2352
|
+
}
|
|
2353
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStepperComplete, decorators: [{
|
|
2354
|
+
type: Directive,
|
|
2355
|
+
args: [{
|
|
2356
|
+
selector: '[cngxStepperComplete]',
|
|
2357
|
+
standalone: true,
|
|
2358
|
+
exportAs: 'cngxStepperComplete',
|
|
2359
|
+
hostDirectives: [
|
|
2360
|
+
{
|
|
2361
|
+
directive: CngxAsyncClick,
|
|
2362
|
+
inputs: [
|
|
2363
|
+
'cngxAsyncClick: cngxStepperComplete',
|
|
2364
|
+
'feedbackDuration',
|
|
2365
|
+
'enabled',
|
|
2366
|
+
'succeededAnnouncement',
|
|
2367
|
+
'failedAnnouncement',
|
|
2368
|
+
],
|
|
2369
|
+
},
|
|
2370
|
+
],
|
|
2371
|
+
}]
|
|
2372
|
+
}], ctorParameters: () => [], propDecorators: { host: [{ type: i0.Input, args: [{ isSignal: true, alias: "host", required: false }] }], completed: [{ type: i0.Output, args: ["completed"] }] } });
|
|
2373
|
+
|
|
2374
|
+
const EMPTY_NODES = Object.freeze([]);
|
|
2375
|
+
/**
|
|
2376
|
+
* Builds a live delegating {@link CngxStepperHost} proxy over a supplier
|
|
2377
|
+
* signal. Every signal member is a `computed()` reading
|
|
2378
|
+
* `supplier()?.<member>()`, every method forwards to
|
|
2379
|
+
* `supplier()?.<method>(...)`. This is the spelled-out shape for
|
|
2380
|
+
* re-providing an input-derived host through DI - you cannot
|
|
2381
|
+
* `useExisting` an `input()` value, so the footer provides this proxy
|
|
2382
|
+
* once and it tracks whichever host the supplier currently resolves.
|
|
2383
|
+
*
|
|
2384
|
+
* **Null-supplier neutral set (the disabled-by-default contract).** When
|
|
2385
|
+
* the supplier resolves `null` (a standalone footer with neither `[host]`
|
|
2386
|
+
* nor an ambient stepper), every navigation affordance must render
|
|
2387
|
+
* *inert*, never falsely enabled: `canGoPrevious` / `canGoNext` collapse
|
|
2388
|
+
* to `false` so Back / Next render disabled, and every method is a no-op.
|
|
2389
|
+
*
|
|
2390
|
+
* `create*` pure factory - no injection context required (`computed()`
|
|
2391
|
+
* only). Single consumer (the footer); the surface is load-bearing, not
|
|
2392
|
+
* speculative.
|
|
2393
|
+
*
|
|
2394
|
+
* @category common/stepper
|
|
2395
|
+
* @since 0.1.0
|
|
2396
|
+
* @relatedTo CngxStepperFooter, CngxStepperHost
|
|
2397
|
+
*/
|
|
2398
|
+
function createStepperHostProxy(supplier) {
|
|
2399
|
+
return {
|
|
2400
|
+
// Core projection / state - empty / out-of-range when null. The array
|
|
2401
|
+
// fallbacks return the shared frozen EMPTY_NODES reference, so no `equal`
|
|
2402
|
+
// fn is needed: the output is reference-stable across reads (either the
|
|
2403
|
+
// supplier's own structural-equal signal value, or this one constant).
|
|
2404
|
+
stepTree: computed(() => supplier()?.stepTree() ?? EMPTY_NODES),
|
|
2405
|
+
flatSteps: computed(() => supplier()?.flatSteps() ?? EMPTY_NODES),
|
|
2406
|
+
stepsOnly: computed(() => supplier()?.stepsOnly() ?? EMPTY_NODES),
|
|
2407
|
+
activeStepIndex: computed(() => supplier()?.activeStepIndex() ?? -1),
|
|
2408
|
+
activeStepId: computed(() => supplier()?.activeStepId() ?? null),
|
|
2409
|
+
linear: computed(() => supplier()?.linear() ?? false),
|
|
2410
|
+
orientation: computed(() => supplier()?.orientation() ?? 'horizontal'),
|
|
2411
|
+
intendedStepIndex: computed(() => supplier()?.intendedStepIndex()),
|
|
2412
|
+
lastFailedIndex: computed(() => supplier()?.lastFailedIndex()),
|
|
2413
|
+
originIndexDuringCommit: computed(() => supplier()?.originIndexDuringCommit()),
|
|
2414
|
+
// Bounds + labels - the safety-critical canGo* pair collapses to
|
|
2415
|
+
// `false` so a null host yields disabled Back / Next, never clickable.
|
|
2416
|
+
stepCount: computed(() => supplier()?.stepCount() ?? 0),
|
|
2417
|
+
isFirstStep: computed(() => supplier()?.isFirstStep() ?? true),
|
|
2418
|
+
isLastStep: computed(() => supplier()?.isLastStep() ?? true),
|
|
2419
|
+
canGoPrevious: computed(() => supplier()?.canGoPrevious() ?? false),
|
|
2420
|
+
canGoNext: computed(() => supplier()?.canGoNext() ?? false),
|
|
2421
|
+
busy: computed(() => supplier()?.busy() ?? false),
|
|
2422
|
+
nextStepLabel: computed(() => supplier()?.nextStepLabel()),
|
|
2423
|
+
previousStepLabel: computed(() => supplier()?.previousStepLabel()),
|
|
2424
|
+
// Composite members delegate their sub-signals, idle when null. The
|
|
2425
|
+
// proxy only forwards - the real tracker is the presenter's, so build
|
|
2426
|
+
// the static neutral shape rather than calling createTransitionTracker.
|
|
2427
|
+
commitState: buildAsyncStateView({
|
|
2428
|
+
status: computed(() => supplier()?.commitState.status() ?? 'idle'),
|
|
2429
|
+
data: computed(() => supplier()?.commitState.data()),
|
|
2430
|
+
error: computed(() => supplier()?.commitState.error()),
|
|
2431
|
+
lastUpdated: computed(() => supplier()?.commitState.lastUpdated()),
|
|
2432
|
+
}),
|
|
2433
|
+
commitTransition: {
|
|
2434
|
+
current: computed(() => supplier()?.commitTransition.current() ?? 'idle'),
|
|
2435
|
+
previous: computed(() => supplier()?.commitTransition.previous() ?? 'idle'),
|
|
2436
|
+
},
|
|
2437
|
+
// Methods forward; no-op when null.
|
|
2438
|
+
select: (index) => supplier()?.select(index),
|
|
2439
|
+
selectNext: () => supplier()?.selectNext(),
|
|
2440
|
+
selectPrevious: () => supplier()?.selectPrevious(),
|
|
2441
|
+
selectById: (id) => supplier()?.selectById(id),
|
|
2442
|
+
reset: () => supplier()?.reset(),
|
|
2443
|
+
clearLastFailed: () => supplier()?.clearLastFailed(),
|
|
2444
|
+
register: (handle, parentId) => supplier()?.register(handle, parentId),
|
|
2445
|
+
unregister: (id) => supplier()?.unregister(id),
|
|
2446
|
+
};
|
|
2447
|
+
}
|
|
2448
|
+
|
|
2449
|
+
/** @internal */
|
|
1256
2450
|
function partitionFeatures(features) {
|
|
1257
2451
|
const config = [];
|
|
1258
2452
|
const i18n = [];
|
|
@@ -1265,7 +2459,7 @@ function partitionFeatures(features) {
|
|
|
1265
2459
|
config.push(feat);
|
|
1266
2460
|
continue;
|
|
1267
2461
|
}
|
|
1268
|
-
// Unbranded feature
|
|
2462
|
+
// Unbranded feature - drop + dev-warn (mirrors `provideCngxTabs`).
|
|
1269
2463
|
if (isDevMode()) {
|
|
1270
2464
|
console.warn('[provideCngxStepper] Dropped feature without a `_target` ' +
|
|
1271
2465
|
'discriminator. Brand config-side mutators with ' +
|
|
@@ -1298,11 +2492,13 @@ function partitionFeatures(features) {
|
|
|
1298
2492
|
* ],
|
|
1299
2493
|
* });
|
|
1300
2494
|
* ```
|
|
2495
|
+
*
|
|
2496
|
+
* @category common/stepper
|
|
1301
2497
|
*/
|
|
1302
2498
|
function provideCngxStepper(...features) {
|
|
1303
2499
|
const { config, i18n } = partitionFeatures(features);
|
|
1304
2500
|
// `provideStepperConfig` returns EnvironmentProviders, `provideStepperI18n`
|
|
1305
|
-
// returns Provider
|
|
2501
|
+
// returns Provider - `makeEnvironmentProviders` takes both.
|
|
1306
2502
|
return makeEnvironmentProviders([
|
|
1307
2503
|
provideStepperConfig(...config),
|
|
1308
2504
|
...(i18n.length > 0 ? [provideStepperI18n(...i18n)] : []),
|
|
@@ -1310,7 +2506,7 @@ function provideCngxStepper(...features) {
|
|
|
1310
2506
|
}
|
|
1311
2507
|
/**
|
|
1312
2508
|
* Component-scoped twin of {@link provideCngxStepper}. Spread into
|
|
1313
|
-
* `viewProviders` or `providers`. Same dispatch semantics
|
|
2509
|
+
* `viewProviders` or `providers`. Same dispatch semantics - only the
|
|
1314
2510
|
* provider scope differs.
|
|
1315
2511
|
*
|
|
1316
2512
|
* ```ts
|
|
@@ -1323,6 +2519,8 @@ function provideCngxStepper(...features) {
|
|
|
1323
2519
|
* ],
|
|
1324
2520
|
* })
|
|
1325
2521
|
* ```
|
|
2522
|
+
*
|
|
2523
|
+
* @category common/stepper
|
|
1326
2524
|
*/
|
|
1327
2525
|
function provideCngxStepperAt(...features) {
|
|
1328
2526
|
const { config, i18n } = partitionFeatures(features);
|
|
@@ -1346,5 +2544,5 @@ function provideCngxStepperAt(...features) {
|
|
|
1346
2544
|
* Generated bundle index. Do not edit.
|
|
1347
2545
|
*/
|
|
1348
2546
|
|
|
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 };
|
|
2547
|
+
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, CngxDotStepperDot, CngxStep, CngxStepBadge, CngxStepBusySpinner, CngxStepContent, CngxStepGroup, CngxStepGroupHeader, CngxStepIndicator, CngxStepLabel, CngxStepRejection, CngxStepperComplete, CngxStepperCount, CngxStepperEmpty, CngxStepperNext, CngxStepperPresenter, CngxStepperPrevious, CngxStepperRouterSync, CngxStepperSwipeNav, STEPPER_DEFAULT_MOBILE_BREAKPOINT, createMobileViewportSignal, createStepperAnnouncementBuilders, createStepperCommitHandler, createStepperDisplayMode, createStepperHostAttrs, createStepperHostProxy, createStepperSlotContextBuilders, createStepperStripKeyboardNav, createStepperTemplateBindings, flatStepsEqual, injectStepperConfig, injectStepperI18n, provideCngxStepper, provideCngxStepperAt, provideStepperConfig, provideStepperConfigAt, provideStepperI18n, resolveStepperStatusLabel, withDotStepperDotTemplate, withStepBadgeTemplate, withStepBusySpinnerTemplate, withStepGroupHeaderTemplate, withStepIndicatorTemplate, withStepRejectionTemplate, withStepperAriaLabels, withStepperCommitMode, withStepperConnectors, withStepperDefaultOrientation, withStepperEmptyTemplate, withStepperFallbackLabels, withStepperI18nLabels, withStepperLinear, withStepperMobileBreakpoint, withStepperMobileCollapse, withStepperMobileIndicatorPosition, withStepperMobileSwipe, withStepperRouterSync, withStepperSkin };
|
|
1350
2548
|
//# sourceMappingURL=cngx-common-stepper.mjs.map
|