@cngx/common 0.1.0-rc.6 → 0.1.0-rc.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/card/README.md +2 -1
- package/chart/README.md +85 -0
- package/command/README.md +157 -0
- package/data/README.md +33 -1
- package/dialog/README.md +23 -1
- package/fesm2022/cngx-common-a11y.mjs +356 -180
- package/fesm2022/cngx-common-a11y.mjs.map +1 -1
- package/fesm2022/cngx-common-audio.mjs +84 -42
- package/fesm2022/cngx-common-audio.mjs.map +1 -1
- package/fesm2022/cngx-common-card.mjs +311 -53
- package/fesm2022/cngx-common-card.mjs.map +1 -1
- package/fesm2022/cngx-common-chart.mjs +4360 -1625
- package/fesm2022/cngx-common-chart.mjs.map +1 -1
- package/fesm2022/cngx-common-command.mjs +171 -0
- package/fesm2022/cngx-common-command.mjs.map +1 -0
- package/fesm2022/cngx-common-data.mjs +1556 -616
- package/fesm2022/cngx-common-data.mjs.map +1 -1
- package/fesm2022/cngx-common-dialog.mjs +518 -112
- package/fesm2022/cngx-common-dialog.mjs.map +1 -1
- package/fesm2022/cngx-common-display.mjs +468 -87
- package/fesm2022/cngx-common-display.mjs.map +1 -1
- package/fesm2022/cngx-common-interactive.mjs +2725 -1303
- package/fesm2022/cngx-common-interactive.mjs.map +1 -1
- package/fesm2022/cngx-common-layout.mjs +943 -164
- package/fesm2022/cngx-common-layout.mjs.map +1 -1
- package/fesm2022/cngx-common-popover.mjs +769 -103
- package/fesm2022/cngx-common-popover.mjs.map +1 -1
- package/fesm2022/cngx-common-stepper.mjs +816 -348
- package/fesm2022/cngx-common-stepper.mjs.map +1 -1
- package/fesm2022/cngx-common-tabs.mjs +2330 -1554
- package/fesm2022/cngx-common-tabs.mjs.map +1 -1
- package/fesm2022/cngx-common-timeline.mjs +1170 -0
- package/fesm2022/cngx-common-timeline.mjs.map +1 -0
- package/fesm2022/cngx-common.mjs +2 -2
- package/fesm2022/cngx-common.mjs.map +1 -1
- package/interactive/README.md +15 -4
- package/layout/README.md +21 -1
- package/package.json +11 -1
- package/popover/README.md +18 -2
- package/stepper/README.md +7 -5
- package/theming/components/cngx-accordion.css +4 -1
- package/theming/components/cngx-backdrop.css +12 -0
- package/theming/components/cngx-badge.css +22 -0
- package/theming/components/cngx-bottom-sheet.css +14 -2
- package/theming/components/cngx-breadcrumb.css +8 -0
- package/theming/components/cngx-button-toggle.css +73 -5
- package/theming/components/cngx-data-grid.css +234 -1
- package/theming/components/cngx-dialog.css +25 -0
- package/theming/components/cngx-divider.css +12 -0
- package/theming/components/cngx-listbox.css +48 -12
- package/theming/components/cngx-menu.css +91 -15
- package/theming/components/cngx-popover.css +24 -0
- package/theming/components/cngx-recycler-placeholder.css +196 -0
- package/theming/components/cngx-ripple.css +2 -2
- package/theming/components/cngx-slider.css +32 -1
- package/theming/components/cngx-tooltip.css +23 -0
- package/timeline/README.md +155 -0
- package/types/cngx-common-a11y.d.ts +101 -31
- package/types/cngx-common-audio.d.ts +32 -32
- package/types/cngx-common-card.d.ts +211 -20
- package/types/cngx-common-chart.d.ts +1605 -169
- package/types/cngx-common-command.d.ts +190 -0
- package/types/cngx-common-data.d.ts +842 -163
- package/types/cngx-common-dialog.d.ts +372 -28
- package/types/cngx-common-display.d.ts +432 -148
- package/types/cngx-common-interactive.d.ts +1553 -370
- package/types/cngx-common-layout.d.ts +613 -27
- package/types/cngx-common-popover.d.ts +376 -36
- package/types/cngx-common-stepper.d.ts +414 -114
- package/types/cngx-common-tabs.d.ts +597 -72
- package/types/cngx-common-timeline.d.ts +1125 -0
- package/types/cngx-common.d.ts +1 -1
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { input, signal, afterNextRender, computed, output, Directive, inject, TemplateRef, model, contentChild,
|
|
2
|
+
import { input, signal, afterNextRender, computed, output, Directive, inject, TemplateRef, model, contentChild, effect, untracked, ChangeDetectionStrategy, Component, DestroyRef, InjectionToken, Injector, Injectable, makeEnvironmentProviders, ViewContainerRef, ViewEncapsulation, isDevMode, isSignal, ElementRef, Renderer2, runInInjectionContext } from '@angular/core';
|
|
3
3
|
import { NgTemplateOutlet, DOCUMENT } from '@angular/common';
|
|
4
4
|
import { CngxChip } from '@cngx/common/display';
|
|
5
5
|
import { CngxMultiChipGroup, CngxChipInGroup, CngxSearch } from '@cngx/common/interactive';
|
|
6
6
|
import { takeUntilDestroyed, toObservable } from '@angular/core/rxjs-interop';
|
|
7
7
|
import { Router, ActivatedRoute } from '@angular/router';
|
|
8
8
|
import { DataSource } from '@angular/cdk/collections';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { isObservable, firstValueFrom, defer, tap, filter, map
|
|
9
|
+
import { foldForMatching, memoize, injectLocale, buildAsyncStateView, nextUid, createAggregateAsyncState, CNGX_STATEFUL, createLatencyProbe, numberFormatterFor, createOverrideMerge, createVisibilityGate, createTransitionTracker, createMediaQuerySignal } from '@cngx/core/utils';
|
|
10
|
+
import { arrayEqual, clamp } from '@cngx/utils';
|
|
11
|
+
import { isObservable, firstValueFrom, defer, tap, finalize, filter, map } from 'rxjs';
|
|
12
12
|
import { HttpContextToken, HttpContext, HttpEventType, provideHttpClient, withInterceptors } from '@angular/common/http';
|
|
13
|
+
import { formatMessage, createLanguageSection, createSectionBundle } from '@cngx/core/i18n';
|
|
14
|
+
import { observeResize } from '@cngx/common/layout';
|
|
13
15
|
|
|
16
|
+
function entryEqual(a, b) {
|
|
17
|
+
return a === b || (!!a && !!b && a.active === b.active && a.direction === b.direction);
|
|
18
|
+
}
|
|
19
|
+
function entriesEqual(a, b) {
|
|
20
|
+
return a === b || (a.length === b.length && a.every((entry, i) => entryEqual(entry, b[i])));
|
|
21
|
+
}
|
|
14
22
|
/**
|
|
15
23
|
* Atom directive that tracks sort state (active field + direction).
|
|
16
24
|
*
|
|
@@ -28,6 +36,8 @@ import { HttpContextToken, HttpContext, HttpEventType, provideHttpClient, withIn
|
|
|
28
36
|
* adds it as a secondary (tertiary, …) sort key instead of replacing the
|
|
29
37
|
* primary one. Shift-clicking an active column cycles it asc → desc → removed.
|
|
30
38
|
* Multi-sort state is always uncontrolled; use `sortsChange` to read it.
|
|
39
|
+
* While a controlled pin is bound, additive clicks degrade to the
|
|
40
|
+
* single-sort cycle.
|
|
31
41
|
*
|
|
32
42
|
* Consumer connects this to a table or list via a `computed()` - nothing is
|
|
33
43
|
* injected automatically.
|
|
@@ -73,19 +83,31 @@ class CngxSort {
|
|
|
73
83
|
});
|
|
74
84
|
}
|
|
75
85
|
/** The active sort column of the primary entry (controlled takes precedence in single-sort mode). */
|
|
76
|
-
active = computed(() => this.activeInput() ?? this.
|
|
86
|
+
active = computed(() => this.activeInput() ?? this.sorts()[0]?.active, ...(ngDevMode ? [{ debugName: "active" }] : /* istanbul ignore next */ []));
|
|
77
87
|
/** The active sort direction of the primary entry (controlled takes precedence in single-sort mode). */
|
|
78
|
-
direction = computed(() => this.directionInput() ?? this.
|
|
88
|
+
direction = computed(() => this.directionInput() ?? this.sorts()[0]?.direction, ...(ngDevMode ? [{ debugName: "direction" }] : /* istanbul ignore next */ []));
|
|
79
89
|
/**
|
|
80
90
|
* The primary sort state, or `null` when no sort is active.
|
|
81
91
|
* In multi-sort mode this is the first entry in `sorts`.
|
|
82
92
|
*/
|
|
83
|
-
sort = computed(() => this.active() ? { active: this.active(), direction: this.direction() ?? 'asc' } : null, ...(ngDevMode ?
|
|
93
|
+
sort = computed(() => (this.active() ? { active: this.active(), direction: this.direction() ?? 'asc' } : null), { ...(ngDevMode ? { debugName: "sort" } : /* istanbul ignore next */ {}), equal: entryEqual });
|
|
84
94
|
/**
|
|
85
95
|
* All active sort entries in priority order.
|
|
86
96
|
* Contains at most one entry when additive mode has not been used.
|
|
97
|
+
* In controlled mode the entry is derived from `cngxSortActive` /
|
|
98
|
+
* `cngxSortDirection` (a falsy active key means no sort); headers and
|
|
99
|
+
* data sources read this signal, so the controlled pin drives them too.
|
|
87
100
|
*/
|
|
88
|
-
sorts =
|
|
101
|
+
sorts = computed(() => {
|
|
102
|
+
const controlledActive = this.activeInput();
|
|
103
|
+
if (controlledActive !== undefined) {
|
|
104
|
+
if (!controlledActive) {
|
|
105
|
+
return [];
|
|
106
|
+
}
|
|
107
|
+
return [{ active: controlledActive, direction: this.directionInput() ?? 'asc' }];
|
|
108
|
+
}
|
|
109
|
+
return this.sortsState();
|
|
110
|
+
}, { ...(ngDevMode ? { debugName: "sorts" } : /* istanbul ignore next */ {}), equal: entriesEqual });
|
|
89
111
|
/** `true` when at least one sort is active. */
|
|
90
112
|
isActive = computed(() => this.sorts().length > 0, ...(ngDevMode ? [{ debugName: "isActive" }] : /* istanbul ignore next */ []));
|
|
91
113
|
/** Emitted when the primary sort state changes. Emits `undefined` on clear. */
|
|
@@ -106,9 +128,15 @@ class CngxSort {
|
|
|
106
128
|
* - Field not in stack → append as asc
|
|
107
129
|
* - Field in stack as asc → change to desc
|
|
108
130
|
* - Field in stack as desc → remove from stack
|
|
131
|
+
*
|
|
132
|
+
* With a controlled `cngxSortActive` pin bound, the sort is event-only: the
|
|
133
|
+
* cycle is computed off the effective entry and emitted, the internal state
|
|
134
|
+
* stays untouched (nothing stale surfaces if the pin unbinds later). Since
|
|
135
|
+
* multi-sort is always uncontrolled, an additive call degrades to the
|
|
136
|
+
* non-additive controlled cycle while a pin is bound.
|
|
109
137
|
*/
|
|
110
138
|
setSort(field, additive = false) {
|
|
111
|
-
if (additive) {
|
|
139
|
+
if (additive && this.activeInput() === undefined) {
|
|
112
140
|
const current = this.sortsState();
|
|
113
141
|
const idx = current.findIndex((s) => s.active === field);
|
|
114
142
|
let next;
|
|
@@ -126,17 +154,27 @@ class CngxSort {
|
|
|
126
154
|
this.sortChange.emit(next[0]);
|
|
127
155
|
}
|
|
128
156
|
else {
|
|
129
|
-
|
|
157
|
+
// Cycle off the effective state: with a controlled pin bound, the first
|
|
158
|
+
// click on the pinned column must continue the cycle (asc -> desc), not
|
|
159
|
+
// restart it from the empty internal state. In that case the write is
|
|
160
|
+
// skipped too - the consumer owns the state, and a shadow copy would
|
|
161
|
+
// surface as stale sort once the pin unbinds.
|
|
162
|
+
const controlled = this.activeInput() !== undefined;
|
|
163
|
+
const current = this.sorts();
|
|
130
164
|
if (field === current[0]?.active && current[0].direction === 'desc') {
|
|
131
165
|
// Third click on the active column: cycle desc -> cleared.
|
|
132
|
-
|
|
166
|
+
if (!controlled) {
|
|
167
|
+
this.sortsState.set([]);
|
|
168
|
+
}
|
|
133
169
|
this.sortChange.emit(undefined);
|
|
134
170
|
this.sortsChange.emit([]);
|
|
135
171
|
}
|
|
136
172
|
else {
|
|
137
173
|
const dir = field === current[0]?.active ? 'desc' : 'asc';
|
|
138
174
|
const entry = { active: field, direction: dir };
|
|
139
|
-
|
|
175
|
+
if (!controlled) {
|
|
176
|
+
this.sortsState.set([entry]);
|
|
177
|
+
}
|
|
140
178
|
this.sortChange.emit(entry);
|
|
141
179
|
this.sortsChange.emit([entry]);
|
|
142
180
|
}
|
|
@@ -454,17 +492,19 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
454
492
|
* is intentionally out of scope. Consumers needing a single-select
|
|
455
493
|
* filter wire `<cngx-chip-group>` to a custom predicate themselves.
|
|
456
494
|
*
|
|
457
|
-
* **Sync contract - derivation, not effect.**
|
|
458
|
-
* `filterRef.addPredicate(filterKey, predicateFn)` EXACTLY ONCE
|
|
459
|
-
* during mount (in `afterNextRender`, because `input.required()`
|
|
460
|
-
* cannot be read from the constructor body). `predicateFn` is a
|
|
495
|
+
* **Sync contract - derivation, not effect.** `predicateFn` is a
|
|
461
496
|
* closure that reads `this.selectedValues()` and
|
|
462
|
-
* `this.
|
|
497
|
+
* `this.optionValue()` on every invocation. Because
|
|
463
498
|
* `CngxFilter.predicate` is itself a `computed()` consumed by
|
|
464
499
|
* downstream filtered lists, each item-evaluation flows through
|
|
465
500
|
* `selectedValues()` in the consumer's reactive context - chip
|
|
466
501
|
* toggles propagate without any `effect()` writing back into the
|
|
467
|
-
* filter.
|
|
502
|
+
* filter. Registration itself is reactive: a binding effect tracks
|
|
503
|
+
* `filterRef`/`filterKey` (a rebind moves the registration), and an
|
|
504
|
+
* eviction watcher re-registers the key after `filter.clear()` wiped
|
|
505
|
+
* the stack, so visible chip selection and predicate stack cannot
|
|
506
|
+
* diverge. Selections whose option vanished from `[options]` are
|
|
507
|
+
* pruned - a removed option never keeps filtering invisibly.
|
|
468
508
|
*
|
|
469
509
|
* **Empty-selection semantics.** When `selectedValues()` is `[]`,
|
|
470
510
|
* the closure returns `true` for every item - equivalent to "no
|
|
@@ -474,13 +514,21 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
474
514
|
* re-registering on every empty/non-empty boundary, and keeps the
|
|
475
515
|
* predicate-stack stable (no `predicatesChange` emission churn).
|
|
476
516
|
*
|
|
477
|
-
* **Teardown.**
|
|
478
|
-
*
|
|
479
|
-
*
|
|
480
|
-
*
|
|
481
|
-
*
|
|
482
|
-
*
|
|
483
|
-
* `
|
|
517
|
+
* **Teardown.** The binding effect's cleanup removes the key only
|
|
518
|
+
* while it still maps to this strip's own `predicateFn` (identity
|
|
519
|
+
* guard) - destroying one of two strips that share a key never
|
|
520
|
+
* detaches the live sibling's registration.
|
|
521
|
+
*
|
|
522
|
+
* **Visible caption.** The required `label` renders as a
|
|
523
|
+
* `.cngx-filter-chips__label` caption above the strip so a sighted user
|
|
524
|
+
* can tell which facet a chip row belongs to. The caption is
|
|
525
|
+
* `aria-hidden="true"`: the inner `<cngx-multi-chip-group>` is already
|
|
526
|
+
* named by the same string via `[label]`, so exposing the visible node
|
|
527
|
+
* to AT would announce the facet twice. Spacing between caption and
|
|
528
|
+
* strip is the `--cngx-filter-chips-gap` token; the caption's own
|
|
529
|
+
* appearance is `--cngx-filter-chips-label-color`,
|
|
530
|
+
* `--cngx-filter-chips-label-font-size` and
|
|
531
|
+
* `--cngx-filter-chips-label-font-weight`.
|
|
484
532
|
*
|
|
485
533
|
* ```html
|
|
486
534
|
* <cngx-filter-chips
|
|
@@ -505,6 +553,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
505
553
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/data/filter-chips/filter-chips.component.ts
|
|
506
554
|
* @since 0.1.0
|
|
507
555
|
* @relatedTo CngxFilter, CngxFilterChip, CngxMultiChipGroup
|
|
556
|
+
* @slot cngxFilterChip Renders one active filter chip; gets the filter entry and a remove callback.
|
|
508
557
|
*
|
|
509
558
|
* <example-url>http://localhost:4200/#/common/data/filter-chips/custom-chip-decoration-via-cngxfilterchip</example-url>
|
|
510
559
|
* <example-url>http://localhost:4200/#/common/data/filter-chips/multi-role-filter-wired-to-a-list</example-url>
|
|
@@ -577,7 +626,6 @@ class CngxFilterChips {
|
|
|
577
626
|
* `CngxFilter.predicate`.
|
|
578
627
|
*/
|
|
579
628
|
selectedValues = model([], ...(ngDevMode ? [{ debugName: "selectedValues" }] : /* istanbul ignore next */ []));
|
|
580
|
-
registered = false;
|
|
581
629
|
constructor() {
|
|
582
630
|
const predicateFn = (item) => {
|
|
583
631
|
const values = this.selectedValues();
|
|
@@ -588,19 +636,47 @@ class CngxFilterChips {
|
|
|
588
636
|
const key = extract(this.optionValue()(item));
|
|
589
637
|
return values.some((v) => Object.is(extract(v), key));
|
|
590
638
|
};
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
639
|
+
// Binding effect: tracks only filterRef/filterKey, so a rebind moves the
|
|
640
|
+
// registration. Cleanup is identity-guarded - it removes the key only
|
|
641
|
+
// while it still maps to THIS strip's predicate, so tearing down one of
|
|
642
|
+
// two strips sharing a key never detaches the live sibling.
|
|
643
|
+
effect((onCleanup) => {
|
|
644
|
+
const filter = this.filterRef();
|
|
645
|
+
const key = this.filterKey();
|
|
646
|
+
untracked(() => filter.addPredicate(key, predicateFn));
|
|
647
|
+
onCleanup(() => {
|
|
648
|
+
if (untracked(filter.predicates).get(key) === predicateFn) {
|
|
649
|
+
untracked(() => filter.removePredicate(key));
|
|
650
|
+
}
|
|
651
|
+
});
|
|
594
652
|
});
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
653
|
+
// Eviction watcher: filter.clear() wipes the whole predicate map while
|
|
654
|
+
// the chips stay visually selected. Re-register when our key is missing
|
|
655
|
+
// so UI and predicate stack cannot diverge. A foreign same-key
|
|
656
|
+
// registration is present, not missing - it is left alone (no fighting,
|
|
657
|
+
// no loop).
|
|
658
|
+
effect(() => {
|
|
659
|
+
const filter = this.filterRef();
|
|
660
|
+
const key = this.filterKey();
|
|
661
|
+
if (!filter.predicates().has(key)) {
|
|
662
|
+
untracked(() => filter.addPredicate(key, predicateFn));
|
|
663
|
+
}
|
|
664
|
+
});
|
|
665
|
+
// Prune selections whose option vanished from [options]: without this a
|
|
666
|
+
// removed option keeps filtering invisibly (no chip renders for it).
|
|
667
|
+
effect(() => {
|
|
668
|
+
const extract = this.keyFn();
|
|
669
|
+
const valid = new Set(this.options().map((o) => extract(this.optionValue()(o))));
|
|
670
|
+
const current = untracked(this.selectedValues);
|
|
671
|
+
const pruned = current.filter((v) => valid.has(extract(v)));
|
|
672
|
+
if (pruned.length !== current.length) {
|
|
673
|
+
untracked(() => this.selectedValues.set(pruned));
|
|
598
674
|
}
|
|
599
|
-
this.filterRef().removePredicate(this.filterKey());
|
|
600
675
|
});
|
|
601
676
|
}
|
|
602
677
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxFilterChips, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
603
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.4", type: CngxFilterChips, isStandalone: true, selector: "cngx-filter-chips", inputs: { label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: true, transformFunction: null }, options: { classPropertyName: "options", publicName: "options", isSignal: true, isRequired: true, transformFunction: null }, optionLabel: { classPropertyName: "optionLabel", publicName: "optionLabel", isSignal: true, isRequired: true, transformFunction: null }, optionValue: { classPropertyName: "optionValue", publicName: "optionValue", isSignal: true, isRequired: true, transformFunction: null }, filterRef: { classPropertyName: "filterRef", publicName: "filterRef", isSignal: true, isRequired: true, transformFunction: null }, filterKey: { classPropertyName: "filterKey", publicName: "filterKey", isSignal: true, isRequired: true, transformFunction: null }, state: { classPropertyName: "state", publicName: "state", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null }, invalid: { classPropertyName: "invalid", publicName: "invalid", isSignal: true, isRequired: false, transformFunction: null }, errorMessageId: { classPropertyName: "errorMessageId", publicName: "errorMessageId", isSignal: true, isRequired: false, transformFunction: null }, orientation: { classPropertyName: "orientation", publicName: "orientation", isSignal: true, isRequired: false, transformFunction: null }, keyFn: { classPropertyName: "keyFn", publicName: "keyFn", isSignal: true, isRequired: false, transformFunction: null }, selectedValues: { classPropertyName: "selectedValues", publicName: "selectedValues", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { disabled: "disabledChange", required: "requiredChange", invalid: "invalidChange", selectedValues: "selectedValuesChange" }, queries: [{ propertyName: "chipTemplate", first: true, predicate: (CngxFilterChip), descendants: true, isSignal: true }], exportAs: ["cngxFilterChips"], ngImport: i0, template: `
|
|
678
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.4", type: CngxFilterChips, isStandalone: true, selector: "cngx-filter-chips", inputs: { label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: true, transformFunction: null }, options: { classPropertyName: "options", publicName: "options", isSignal: true, isRequired: true, transformFunction: null }, optionLabel: { classPropertyName: "optionLabel", publicName: "optionLabel", isSignal: true, isRequired: true, transformFunction: null }, optionValue: { classPropertyName: "optionValue", publicName: "optionValue", isSignal: true, isRequired: true, transformFunction: null }, filterRef: { classPropertyName: "filterRef", publicName: "filterRef", isSignal: true, isRequired: true, transformFunction: null }, filterKey: { classPropertyName: "filterKey", publicName: "filterKey", isSignal: true, isRequired: true, transformFunction: null }, state: { classPropertyName: "state", publicName: "state", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null }, invalid: { classPropertyName: "invalid", publicName: "invalid", isSignal: true, isRequired: false, transformFunction: null }, errorMessageId: { classPropertyName: "errorMessageId", publicName: "errorMessageId", isSignal: true, isRequired: false, transformFunction: null }, orientation: { classPropertyName: "orientation", publicName: "orientation", isSignal: true, isRequired: false, transformFunction: null }, keyFn: { classPropertyName: "keyFn", publicName: "keyFn", isSignal: true, isRequired: false, transformFunction: null }, selectedValues: { classPropertyName: "selectedValues", publicName: "selectedValues", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { disabled: "disabledChange", required: "requiredChange", invalid: "invalidChange", selectedValues: "selectedValuesChange" }, host: { properties: { "class.cngx-filter-chips--vertical": "orientation() === \"vertical\"" }, classAttribute: "cngx-filter-chips" }, queries: [{ propertyName: "chipTemplate", first: true, predicate: (CngxFilterChip), descendants: true, isSignal: true }], exportAs: ["cngxFilterChips"], ngImport: i0, template: `
|
|
679
|
+
<span class="cngx-filter-chips__label" aria-hidden="true">{{ label() }}</span>
|
|
604
680
|
<cngx-multi-chip-group
|
|
605
681
|
[label]="label()"
|
|
606
682
|
[(selectedValues)]="selectedValues"
|
|
@@ -622,17 +698,15 @@ class CngxFilterChips {
|
|
|
622
698
|
</cngx-chip>
|
|
623
699
|
}
|
|
624
700
|
</cngx-multi-chip-group>
|
|
625
|
-
`, isInline: true, dependencies: [{ kind: "component", type: CngxChip, selector: "cngx-chip", inputs: ["removable", "id", "removeAriaLabel"], outputs: ["remove"], exportAs: ["cngxChip"] }, { kind: "component", type: CngxMultiChipGroup, selector: "cngx-multi-chip-group, [cngxMultiChipGroup]", inputs: ["selectedValues", "disabled", "required", "invalid", "errorMessageId", "orientation", "label", "state", "keyFn"], outputs: ["selectedValuesChange", "disabledChange", "requiredChange", "invalidChange"], exportAs: ["cngxMultiChipGroup"] }, { kind: "directive", type: CngxChipInGroup, selector: "[cngxChipInGroup]", inputs: ["value", "disabled", "cngxDescribedBy"], exportAs: ["cngxChipInGroup"] }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
701
|
+
`, isInline: true, styles: [":host{display:flex;flex-direction:row;align-items:center;--cngx-filter-chips-gap: var(--cngx-space-sm, 8px);gap:var(--cngx-filter-chips-gap, 8px)}:host(.cngx-filter-chips--vertical){flex-direction:column;align-items:flex-start}.cngx-filter-chips__label{color:var(--cngx-filter-chips-label-color, inherit);font-size:var(--cngx-filter-chips-label-font-size, .8125rem);font-weight:var(--cngx-filter-chips-label-font-weight, 600)}\n"], dependencies: [{ kind: "component", type: CngxChip, selector: "cngx-chip", inputs: ["removable", "id", "removeAriaLabel"], outputs: ["remove"], exportAs: ["cngxChip"] }, { kind: "component", type: CngxMultiChipGroup, selector: "cngx-multi-chip-group, [cngxMultiChipGroup]", inputs: ["selectedValues", "disabled", "required", "invalid", "errorMessageId", "orientation", "label", "labelledBy", "state", "keyFn"], outputs: ["selectedValuesChange", "disabledChange", "requiredChange", "invalidChange"], exportAs: ["cngxMultiChipGroup"] }, { kind: "directive", type: CngxChipInGroup, selector: "[cngxChipInGroup]", inputs: ["value", "disabled", "cngxDescribedBy"], exportAs: ["cngxChipInGroup"] }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
626
702
|
}
|
|
627
703
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxFilterChips, decorators: [{
|
|
628
704
|
type: Component,
|
|
629
|
-
args: [{
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
imports: [CngxChip, CngxMultiChipGroup, CngxChipInGroup, NgTemplateOutlet],
|
|
635
|
-
template: `
|
|
705
|
+
args: [{ selector: 'cngx-filter-chips', exportAs: 'cngxFilterChips', standalone: true, changeDetection: ChangeDetectionStrategy.OnPush, imports: [CngxChip, CngxMultiChipGroup, CngxChipInGroup, NgTemplateOutlet], host: {
|
|
706
|
+
class: 'cngx-filter-chips',
|
|
707
|
+
'[class.cngx-filter-chips--vertical]': 'orientation() === "vertical"',
|
|
708
|
+
}, template: `
|
|
709
|
+
<span class="cngx-filter-chips__label" aria-hidden="true">{{ label() }}</span>
|
|
636
710
|
<cngx-multi-chip-group
|
|
637
711
|
[label]="label()"
|
|
638
712
|
[(selectedValues)]="selectedValues"
|
|
@@ -654,8 +728,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
654
728
|
</cngx-chip>
|
|
655
729
|
}
|
|
656
730
|
</cngx-multi-chip-group>
|
|
657
|
-
`,
|
|
658
|
-
}]
|
|
731
|
+
`, styles: [":host{display:flex;flex-direction:row;align-items:center;--cngx-filter-chips-gap: var(--cngx-space-sm, 8px);gap:var(--cngx-filter-chips-gap, 8px)}:host(.cngx-filter-chips--vertical){flex-direction:column;align-items:flex-start}.cngx-filter-chips__label{color:var(--cngx-filter-chips-label-color, inherit);font-size:var(--cngx-filter-chips-label-font-size, .8125rem);font-weight:var(--cngx-filter-chips-label-font-weight, 600)}\n"] }]
|
|
659
732
|
}], ctorParameters: () => [], propDecorators: { label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: true }] }], options: [{ type: i0.Input, args: [{ isSignal: true, alias: "options", required: true }] }], optionLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "optionLabel", required: true }] }], optionValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "optionValue", required: true }] }], filterRef: [{ type: i0.Input, args: [{ isSignal: true, alias: "filterRef", required: true }] }], filterKey: [{ type: i0.Input, args: [{ isSignal: true, alias: "filterKey", required: true }] }], state: [{ type: i0.Input, args: [{ isSignal: true, alias: "state", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }, { type: i0.Output, args: ["disabledChange"] }], required: [{ type: i0.Input, args: [{ isSignal: true, alias: "required", required: false }] }, { type: i0.Output, args: ["requiredChange"] }], invalid: [{ type: i0.Input, args: [{ isSignal: true, alias: "invalid", required: false }] }, { type: i0.Output, args: ["invalidChange"] }], errorMessageId: [{ type: i0.Input, args: [{ isSignal: true, alias: "errorMessageId", required: false }] }], orientation: [{ type: i0.Input, args: [{ isSignal: true, alias: "orientation", required: false }] }], keyFn: [{ type: i0.Input, args: [{ isSignal: true, alias: "keyFn", required: false }] }], chipTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => CngxFilterChip), { isSignal: true }] }], selectedValues: [{ type: i0.Input, args: [{ isSignal: true, alias: "selectedValues", required: false }] }, { type: i0.Output, args: ["selectedValuesChange"] }] } });
|
|
660
733
|
|
|
661
734
|
/**
|
|
@@ -744,6 +817,22 @@ class CngxPaginate {
|
|
|
744
817
|
* stops a fresh-array identity from cascading downstream.
|
|
745
818
|
*/
|
|
746
819
|
cumulativeRange = computed(() => [0, (this.pageIndex() + 1) * this.pageSize()], { ...(ngDevMode ? { debugName: "cumulativeRange" } : /* istanbul ignore next */ {}), equal: (a, b) => a[0] === b[0] && a[1] === b[1] });
|
|
820
|
+
/**
|
|
821
|
+
* `range()` with both bounds capped at `total` - the honest in-bounds window
|
|
822
|
+
* for readouts and announcements. `range()`'s upper bound is
|
|
823
|
+
* `start + pageSize`, so a partial final page overshoots `total`; this caps
|
|
824
|
+
* it (and yields `[0, 0]` while the list is empty). The capped end doubles as
|
|
825
|
+
* the cumulative reveal count for load-more consumers: `range()[1]` and
|
|
826
|
+
* `cumulativeRange()[1]` are the same number (`(pageIndex + 1) * pageSize`),
|
|
827
|
+
* so `clampedRange()[1]` is "items shown so far" in both replace and append
|
|
828
|
+
* modes. The explicit tuple `equal` stops a fresh-array identity from
|
|
829
|
+
* cascading downstream.
|
|
830
|
+
*/
|
|
831
|
+
clampedRange = computed(() => {
|
|
832
|
+
const total = this.total();
|
|
833
|
+
const [start, end] = this.range();
|
|
834
|
+
return [Math.min(start, total), Math.min(end, total)];
|
|
835
|
+
}, { ...(ngDevMode ? { debugName: "clampedRange" } : /* istanbul ignore next */ {}), equal: (a, b) => a[0] === b[0] && a[1] === b[1] });
|
|
747
836
|
/** Emitted when the page index changes. */
|
|
748
837
|
pageChange = output();
|
|
749
838
|
/** Emitted when the page size changes. */
|
|
@@ -883,7 +972,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
883
972
|
* brain's `pageIndex()` stays pinned to the input until the consumer feeds it
|
|
884
973
|
* back;
|
|
885
974
|
* - an `effect()` reads the effective `pageIndex()` / `pageSize()` and covers a
|
|
886
|
-
* `total`-shrink clamp the nav-only output misses.
|
|
975
|
+
* `total`-shrink clamp the nav-only output misses. The index half of the
|
|
976
|
+
* clamp path is suppressed while the brain is busy or `total` is 0, so a
|
|
977
|
+
* transient total drop during a refetch never persists a page-0 clamp into a
|
|
978
|
+
* controlled consumer; a clamp that survives the settle emits then.
|
|
887
979
|
*
|
|
888
980
|
* The shared guard makes a value one path already emitted a no-op on the other,
|
|
889
981
|
* so each change emits exactly once. Seeded with the current effective values,
|
|
@@ -928,16 +1020,27 @@ function connectPaginateEmit(paginate, handlers) {
|
|
|
928
1020
|
// nav path already emitted is a no-op here, so each change emits once.
|
|
929
1021
|
effect(() => {
|
|
930
1022
|
const index = paginate.pageIndex();
|
|
1023
|
+
// A transient total drop (a refetch clearing [total] to 0) clamps the
|
|
1024
|
+
// effective index to 0; forwarding that would persist the clamp into a
|
|
1025
|
+
// controlled consumer's two-way state and pin page 0 after the data
|
|
1026
|
+
// returns, where the brain's read-time clamp alone would recover. Both
|
|
1027
|
+
// gates are tracked reads, so a clamp that survives the settle (a real
|
|
1028
|
+
// total shrink) emits when busy flips off / total refills.
|
|
1029
|
+
if (paginate.isBusy() || paginate.total() === 0) {
|
|
1030
|
+
return;
|
|
1031
|
+
}
|
|
931
1032
|
if (index !== lastIndex) {
|
|
932
1033
|
lastIndex = index;
|
|
933
|
-
handlers
|
|
1034
|
+
// Consumer handlers run synchronously - keep their signal reads/writes
|
|
1035
|
+
// out of this effect's dependency graph.
|
|
1036
|
+
untracked(() => handlers.onIndex(index));
|
|
934
1037
|
}
|
|
935
1038
|
});
|
|
936
1039
|
effect(() => {
|
|
937
1040
|
const size = paginate.pageSize();
|
|
938
1041
|
if (size !== lastSize) {
|
|
939
1042
|
lastSize = size;
|
|
940
|
-
handlers.onSize(size);
|
|
1043
|
+
untracked(() => handlers.onSize(size));
|
|
941
1044
|
}
|
|
942
1045
|
});
|
|
943
1046
|
}
|
|
@@ -977,9 +1080,18 @@ class CngxPaginateRouting {
|
|
|
977
1080
|
pageParam = input('page', { ...(ngDevMode ? { debugName: "pageParam" } : /* istanbul ignore next */ {}), alias: 'cngxPaginatePageParam' });
|
|
978
1081
|
/** Query-param name for the page size. */
|
|
979
1082
|
sizeParam = input('pageSize', { ...(ngDevMode ? { debugName: "sizeParam" } : /* istanbul ignore next */ {}), alias: 'cngxPaginateSizeParam' });
|
|
980
|
-
// Set
|
|
981
|
-
//
|
|
1083
|
+
// Set synchronously around brain writes driven by the URL, so the
|
|
1084
|
+
// pageChange subscription below can tell a URL-driven change from a user
|
|
1085
|
+
// navigation (setPage/setPageSize emit synchronously).
|
|
982
1086
|
applyingFromUrl = false;
|
|
1087
|
+
// A deep-linked page index the brain could not represent yet: setPage
|
|
1088
|
+
// clamps against totalPages (1 while the default total=0 is still in
|
|
1089
|
+
// effect) and no-ops entirely while the bound async state is busy. The raw
|
|
1090
|
+
// index is parked here and re-applied once total/busy settle; while it is
|
|
1091
|
+
// parked, the brain -> URL effect leaves the URL alone so the deep link
|
|
1092
|
+
// survives until the data lands. `size` is null once the size half has
|
|
1093
|
+
// been applied.
|
|
1094
|
+
pendingUrl = signal(null, { ...(ngDevMode ? { debugName: "pendingUrl" } : /* istanbul ignore next */ {}), equal: (a, b) => a?.index === b?.index && a?.size === b?.size });
|
|
983
1095
|
constructor() {
|
|
984
1096
|
const router = this.router;
|
|
985
1097
|
const route = this.route;
|
|
@@ -990,17 +1102,38 @@ class CngxPaginateRouting {
|
|
|
990
1102
|
}
|
|
991
1103
|
return;
|
|
992
1104
|
}
|
|
1105
|
+
// A user navigation supersedes a still-parked deep link. The brain is
|
|
1106
|
+
// resolved through the element injector and may live on an ancestor, so
|
|
1107
|
+
// the subscription is torn down explicitly instead of relying on shared
|
|
1108
|
+
// lifecycles.
|
|
1109
|
+
const pageChangeSub = this.paginate.pageChange.subscribe(() => {
|
|
1110
|
+
if (!this.applyingFromUrl) {
|
|
1111
|
+
this.pendingUrl.set(null);
|
|
1112
|
+
}
|
|
1113
|
+
});
|
|
1114
|
+
this.destroyRef.onDestroy(() => pageChangeSub.unsubscribe());
|
|
993
1115
|
// brain -> URL. Tracks the effective page / size; merges into the existing
|
|
994
1116
|
// query string and replaces history so paging does not stack back entries.
|
|
995
1117
|
// The param-name inputs are read lazily inside untracked, so a late-bound
|
|
996
|
-
// alias is already set by the time the first navigation fires.
|
|
1118
|
+
// alias is already set by the time the first navigation fires. Skipped
|
|
1119
|
+
// while a deep link is parked and when the URL already carries the values
|
|
1120
|
+
// (the echo after a URL -> brain apply must not renavigate).
|
|
997
1121
|
effect(() => {
|
|
998
1122
|
const page = this.paginate.pageIndex() + 1;
|
|
999
1123
|
const size = this.paginate.pageSize();
|
|
1000
|
-
if (this.
|
|
1124
|
+
if (this.pendingUrl() !== null) {
|
|
1001
1125
|
return;
|
|
1002
1126
|
}
|
|
1003
1127
|
untracked(() => {
|
|
1128
|
+
// Snapshot read while router.navigate is async: a still-pending
|
|
1129
|
+
// navigation can slip past this check and renavigate - benign under
|
|
1130
|
+
// replaceUrl + merge (same params, no history entry).
|
|
1131
|
+
const params = route.snapshot.queryParamMap;
|
|
1132
|
+
const samePage = Number(params.get(this.pageParam())) === page;
|
|
1133
|
+
const sameSize = Number(params.get(this.sizeParam())) === size;
|
|
1134
|
+
if (samePage && sameSize) {
|
|
1135
|
+
return;
|
|
1136
|
+
}
|
|
1004
1137
|
void router.navigate([], {
|
|
1005
1138
|
relativeTo: route,
|
|
1006
1139
|
queryParams: { [this.pageParam()]: page, [this.sizeParam()]: size },
|
|
@@ -1009,6 +1142,20 @@ class CngxPaginateRouting {
|
|
|
1009
1142
|
});
|
|
1010
1143
|
});
|
|
1011
1144
|
});
|
|
1145
|
+
// Re-apply a parked deep link whenever the clamp inputs move (total
|
|
1146
|
+
// landed, busy released). Only those two triggers are tracked; the parked
|
|
1147
|
+
// value is read untracked, so the re-park write inside applyFromUrl can
|
|
1148
|
+
// never feed back into this effect's own dependency graph.
|
|
1149
|
+
effect(() => {
|
|
1150
|
+
this.paginate.totalPages();
|
|
1151
|
+
this.paginate.isBusy();
|
|
1152
|
+
untracked(() => {
|
|
1153
|
+
const pending = this.pendingUrl();
|
|
1154
|
+
if (pending !== null) {
|
|
1155
|
+
this.applyFromUrl(pending.index, pending.size);
|
|
1156
|
+
}
|
|
1157
|
+
});
|
|
1158
|
+
});
|
|
1012
1159
|
}
|
|
1013
1160
|
ngOnInit() {
|
|
1014
1161
|
const route = this.route;
|
|
@@ -1020,22 +1167,41 @@ class CngxPaginateRouting {
|
|
|
1020
1167
|
// deep-linked page / size therefore lands before first paint). The
|
|
1021
1168
|
// subscription stays live for back / forward navigation.
|
|
1022
1169
|
route.queryParamMap.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((params) => {
|
|
1023
|
-
const
|
|
1024
|
-
const
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1170
|
+
const rawSize = Number(params.get(this.sizeParam()));
|
|
1171
|
+
const rawPage = Number(params.get(this.pageParam()));
|
|
1172
|
+
const size = Number.isFinite(rawSize) && rawSize > 0 ? rawSize : null;
|
|
1173
|
+
const index = (Number.isFinite(rawPage) && rawPage > 0 ? rawPage : 1) - 1;
|
|
1174
|
+
this.applyFromUrl(index, size);
|
|
1175
|
+
});
|
|
1176
|
+
}
|
|
1177
|
+
applyFromUrl(index, size) {
|
|
1178
|
+
const paginate = this.paginate;
|
|
1179
|
+
if (paginate.isBusy()) {
|
|
1180
|
+
// Both setters no-op while busy - park the whole request and retry.
|
|
1181
|
+
this.pendingUrl.set({ index, size });
|
|
1182
|
+
return;
|
|
1183
|
+
}
|
|
1184
|
+
this.applyingFromUrl = true;
|
|
1185
|
+
try {
|
|
1186
|
+
if (size !== null && size !== paginate.pageSize()) {
|
|
1187
|
+
paginate.setPageSize(size, false);
|
|
1034
1188
|
}
|
|
1035
|
-
|
|
1036
|
-
|
|
1189
|
+
if (index !== paginate.pageIndex()) {
|
|
1190
|
+
paginate.setPage(index);
|
|
1037
1191
|
}
|
|
1038
|
-
}
|
|
1192
|
+
}
|
|
1193
|
+
finally {
|
|
1194
|
+
this.applyingFromUrl = false;
|
|
1195
|
+
}
|
|
1196
|
+
if (paginate.pageIndex() === index || paginate.total() > 0) {
|
|
1197
|
+
// Landed, or clamped against a real total - the deep link is resolved.
|
|
1198
|
+
this.pendingUrl.set(null);
|
|
1199
|
+
}
|
|
1200
|
+
else {
|
|
1201
|
+
// Clamped against the default total=0: the real total has not arrived
|
|
1202
|
+
// yet, so keep the raw index parked (size, if any, is applied already).
|
|
1203
|
+
this.pendingUrl.set({ index, size: null });
|
|
1204
|
+
}
|
|
1039
1205
|
}
|
|
1040
1206
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxPaginateRouting, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1041
1207
|
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxPaginateRouting, isStandalone: true, selector: "[cngxPaginateRouting]", inputs: { pageParam: { classPropertyName: "pageParam", publicName: "cngxPaginatePageParam", isSignal: true, isRequired: false, transformFunction: null }, sizeParam: { classPropertyName: "sizeParam", publicName: "cngxPaginateSizeParam", isSignal: true, isRequired: false, transformFunction: null } }, exportAs: ["cngxPaginateRouting"], ngImport: i0 });
|
|
@@ -1221,22 +1387,61 @@ function injectDataSource(data) {
|
|
|
1221
1387
|
return new CngxDataSource(data);
|
|
1222
1388
|
}
|
|
1223
1389
|
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1390
|
+
/**
|
|
1391
|
+
* @internal Folded field values per row object. Keyed by the row, so it
|
|
1392
|
+
* cannot thrash and is collected with the rows; the raw strings are compared
|
|
1393
|
+
* on every read, so a row mutated in place is folded again.
|
|
1394
|
+
*/
|
|
1395
|
+
const FOLDED_FIELDS = new WeakMap();
|
|
1396
|
+
function rawFieldsOf(item) {
|
|
1397
|
+
const raw = [];
|
|
1398
|
+
for (const v of Object.values(item)) {
|
|
1399
|
+
if (v !== null && v !== undefined && typeof v !== 'object') {
|
|
1400
|
+
raw.push(String(v));
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
return raw;
|
|
1404
|
+
}
|
|
1405
|
+
function foldedFieldsOf(item, locale) {
|
|
1406
|
+
const raw = rawFieldsOf(item);
|
|
1407
|
+
const cached = FOLDED_FIELDS.get(item);
|
|
1408
|
+
if (cached?.locale === locale && arrayEqual(cached.raw, raw)) {
|
|
1409
|
+
return cached.folded;
|
|
1410
|
+
}
|
|
1411
|
+
const folded = raw.map((value) => foldForMatching(value, locale));
|
|
1412
|
+
FOLDED_FIELDS.set(item, { locale, raw, folded });
|
|
1413
|
+
return folded;
|
|
1231
1414
|
}
|
|
1232
|
-
|
|
1415
|
+
/**
|
|
1416
|
+
* @internal The default search: primitive field values, case and accents
|
|
1417
|
+
* ignored in `locale`. The term is folded once per term, each row's field
|
|
1418
|
+
* values once per row and locale, not on every keystroke.
|
|
1419
|
+
*/
|
|
1420
|
+
const defaultSearchFnFor = memoize((locale) => {
|
|
1421
|
+
let lastTerm = '';
|
|
1422
|
+
let lastFolded = '';
|
|
1423
|
+
return (item, term) => {
|
|
1424
|
+
if (term !== lastTerm) {
|
|
1425
|
+
lastTerm = term;
|
|
1426
|
+
lastFolded = foldForMatching(term, locale);
|
|
1427
|
+
}
|
|
1428
|
+
if (typeof item !== 'object' || item === null) {
|
|
1429
|
+
return foldForMatching(String(item), locale).includes(lastFolded);
|
|
1430
|
+
}
|
|
1431
|
+
return foldedFieldsOf(item, locale).some((value) => value.includes(lastFolded));
|
|
1432
|
+
};
|
|
1433
|
+
}, { cacheLimit: 8 });
|
|
1434
|
+
const collatorFor = memoize((locale) => new Intl.Collator(locale, { numeric: true, sensitivity: 'base' }), { cacheLimit: 32 });
|
|
1435
|
+
/** @internal The default comparator: field values as text, collated in `locale`. */
|
|
1436
|
+
function defaultSortFnFor(locale) {
|
|
1437
|
+
const collator = collatorFor(locale);
|
|
1233
1438
|
const toStr = (v) => v === null || v === undefined || typeof v === 'object'
|
|
1234
1439
|
? ''
|
|
1235
1440
|
: String(v);
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1441
|
+
return (a, b, field, dir) => {
|
|
1442
|
+
const cmp = collator.compare(toStr(a[field]), toStr(b[field]));
|
|
1443
|
+
return dir === 'asc' ? cmp : -cmp;
|
|
1444
|
+
};
|
|
1240
1445
|
}
|
|
1241
1446
|
function isAsyncState(source) {
|
|
1242
1447
|
return 'status' in source && 'data' in source && 'isFirstLoad' in source;
|
|
@@ -1247,6 +1452,22 @@ function isAsyncState(source) {
|
|
|
1247
1452
|
* tree. Each directive is injected optionally - if absent, that processing
|
|
1248
1453
|
* step is skipped.
|
|
1249
1454
|
*
|
|
1455
|
+
* Injection resolves UPWARD only. Any atom hosted by a descendant component
|
|
1456
|
+
* - a `hostDirective` on an element below the consumer's injector - is
|
|
1457
|
+
* invisible to these injects, and the matching step is silently skipped:
|
|
1458
|
+
* the atom's own state still toggles (headers flip their arrows) while the
|
|
1459
|
+
* rows never move. `CngxDataGridAccordion` is the case where this is always
|
|
1460
|
+
* true: it hosts `CngxSort` and `CngxFilter` on the group element. Hand
|
|
1461
|
+
* such atoms in through the options thunks instead:
|
|
1462
|
+
*
|
|
1463
|
+
* ```typescript
|
|
1464
|
+
* readonly grid = viewChild(CngxDataGridAccordion);
|
|
1465
|
+
* readonly dataSource = injectSmartDataSource(this.rows, {
|
|
1466
|
+
* sort: () => this.grid()?.sort,
|
|
1467
|
+
* filter: () => this.grid()?.filter,
|
|
1468
|
+
* });
|
|
1469
|
+
* ```
|
|
1470
|
+
*
|
|
1250
1471
|
* Accepts either a plain `Signal<T[]>` or a `CngxAsyncState<T[]>`.
|
|
1251
1472
|
* When a `CngxAsyncState` is provided, the data source exposes the full
|
|
1252
1473
|
* UX state (`isLoading`, `isRefreshing`, `error`, `isEmpty`) so the
|
|
@@ -1273,14 +1494,14 @@ function isAsyncState(source) {
|
|
|
1273
1494
|
class CngxSmartDataSource extends DataSource {
|
|
1274
1495
|
options;
|
|
1275
1496
|
injector = inject(Injector);
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
//
|
|
1279
|
-
//
|
|
1280
|
-
//
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1497
|
+
injectedSort = inject(CngxSort, { optional: true });
|
|
1498
|
+
injectedFilter = inject(CngxFilter, { optional: true });
|
|
1499
|
+
// Injection resolves upward only; an atom below this injector (child
|
|
1500
|
+
// <input> search, a hosting organism's sort/filter) arrives via the
|
|
1501
|
+
// matching options thunk instead.
|
|
1502
|
+
injectedSearch = inject(CngxSearch, { optional: true });
|
|
1503
|
+
injectedPaginate = inject(CngxPaginate, { optional: true });
|
|
1504
|
+
locale = injectLocale();
|
|
1284
1505
|
/**
|
|
1285
1506
|
* Items after filter and search are applied, before sort and pagination.
|
|
1286
1507
|
* Use `filteredCount()` to get the pre-pagination count for paginator `total`.
|
|
@@ -1327,9 +1548,13 @@ class CngxSmartDataSource extends DataSource {
|
|
|
1327
1548
|
this.isFirstLoad = computed(() => s?.isFirstLoad() ?? false, ...(ngDevMode ? [{ debugName: "isFirstLoad" }] : /* istanbul ignore next */ []));
|
|
1328
1549
|
this.error = computed(() => s?.error(), ...(ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []));
|
|
1329
1550
|
this.filtered = computed(() => {
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
const
|
|
1551
|
+
// Resolve at read time: an options thunk pointing at a not-yet-mounted
|
|
1552
|
+
// viewChild returns undefined now and the instance on a later pass.
|
|
1553
|
+
const filter = this.options?.filter?.() ?? this.injectedFilter;
|
|
1554
|
+
const search = this.options?.search?.() ?? this.injectedSearch;
|
|
1555
|
+
const predicate = filter?.predicate();
|
|
1556
|
+
const term = search?.term();
|
|
1557
|
+
const searchFn = this.options?.searchFn ?? defaultSearchFnFor(this.locale());
|
|
1333
1558
|
// Pipeline: raw → filter → search. Cast required: CngxFilter injected as unknown.
|
|
1334
1559
|
return data()
|
|
1335
1560
|
.filter((v) => !predicate || predicate(v))
|
|
@@ -1344,12 +1569,14 @@ class CngxSmartDataSource extends DataSource {
|
|
|
1344
1569
|
return this.filteredCount() === 0;
|
|
1345
1570
|
}, ...(ngDevMode ? [{ debugName: "isEmpty" }] : /* istanbul ignore next */ []));
|
|
1346
1571
|
this.processed = computed(() => {
|
|
1347
|
-
const
|
|
1348
|
-
const
|
|
1572
|
+
const sort = this.options?.sort?.() ?? this.injectedSort;
|
|
1573
|
+
const sorts = sort?.sorts() ?? [];
|
|
1574
|
+
const sortFn = this.options?.sortFn ?? defaultSortFnFor(this.locale());
|
|
1349
1575
|
const sorted = sorts.length > 0
|
|
1350
1576
|
? [...this.filtered()].sort((a, b) => sorts.reduce((cmp, { active, direction }) => cmp || sortFn(a, b, active, direction), 0))
|
|
1351
1577
|
: this.filtered();
|
|
1352
|
-
const
|
|
1578
|
+
const paginate = this.options?.paginate?.() ?? this.injectedPaginate;
|
|
1579
|
+
const range = paginate?.range();
|
|
1353
1580
|
return range ? sorted.slice(range[0], range[1]) : sorted;
|
|
1354
1581
|
}, { ...(ngDevMode ? { debugName: "processed" } : /* istanbul ignore next */ {}), equal: arrayEqual });
|
|
1355
1582
|
}
|
|
@@ -1383,10 +1610,10 @@ function injectSmartDataSource(source, options) {
|
|
|
1383
1610
|
}
|
|
1384
1611
|
|
|
1385
1612
|
/**
|
|
1386
|
-
* Create a fully manual async state
|
|
1613
|
+
* Create a fully manual async state - no HTTP, no automatic loading.
|
|
1387
1614
|
*
|
|
1388
1615
|
* Use for local operations: heavy computations, Web Workers, complex local processes.
|
|
1389
|
-
* Does **not** require an injection context
|
|
1616
|
+
* Does **not** require an injection context - uses only `signal()` and `computed()`.
|
|
1390
1617
|
*
|
|
1391
1618
|
* ```typescript
|
|
1392
1619
|
* readonly processState = createManualState<ProcessResult>();
|
|
@@ -1421,6 +1648,10 @@ function createManualState() {
|
|
|
1421
1648
|
set(newStatus) {
|
|
1422
1649
|
statusState.set(newStatus);
|
|
1423
1650
|
if (newStatus === 'success') {
|
|
1651
|
+
// Parity with setSuccess: a success transition must not leave stale
|
|
1652
|
+
// error/progress residue behind.
|
|
1653
|
+
errorState.set(undefined);
|
|
1654
|
+
progressState.set(undefined);
|
|
1424
1655
|
hadSuccess.set(true);
|
|
1425
1656
|
lastUpdatedState.set(new Date());
|
|
1426
1657
|
}
|
|
@@ -1452,83 +1683,6 @@ function createManualState() {
|
|
|
1452
1683
|
};
|
|
1453
1684
|
}
|
|
1454
1685
|
|
|
1455
|
-
/**
|
|
1456
|
-
* Create a mutation async state — for explicit user-triggered actions.
|
|
1457
|
-
*
|
|
1458
|
-
* Must be called in an injection context (field initializer or constructor)
|
|
1459
|
-
* because it uses `inject(DestroyRef)` for cleanup.
|
|
1460
|
-
*
|
|
1461
|
-
* ```typescript
|
|
1462
|
-
* readonly saveResident = createAsyncState<Resident>();
|
|
1463
|
-
*
|
|
1464
|
-
* async handleSave(): Promise<void> {
|
|
1465
|
-
* await this.saveResident.execute(
|
|
1466
|
-
* () => this.api.save(this.form().value())
|
|
1467
|
-
* );
|
|
1468
|
-
* }
|
|
1469
|
-
* ```
|
|
1470
|
-
*
|
|
1471
|
-
* @category common/data/async-state
|
|
1472
|
-
*/
|
|
1473
|
-
function createAsyncState() {
|
|
1474
|
-
const destroyRef = inject(DestroyRef);
|
|
1475
|
-
const state = createManualState();
|
|
1476
|
-
let abortController;
|
|
1477
|
-
destroyRef.onDestroy(() => {
|
|
1478
|
-
abortController?.abort();
|
|
1479
|
-
abortController = undefined;
|
|
1480
|
-
});
|
|
1481
|
-
return {
|
|
1482
|
-
status: state.status,
|
|
1483
|
-
data: state.data,
|
|
1484
|
-
error: state.error,
|
|
1485
|
-
progress: state.progress,
|
|
1486
|
-
isLoading: state.isLoading,
|
|
1487
|
-
isPending: state.isPending,
|
|
1488
|
-
isRefreshing: state.isRefreshing,
|
|
1489
|
-
isBusy: state.isBusy,
|
|
1490
|
-
isFirstLoad: state.isFirstLoad,
|
|
1491
|
-
isEmpty: state.isEmpty,
|
|
1492
|
-
hasData: state.hasData,
|
|
1493
|
-
isSettled: state.isSettled,
|
|
1494
|
-
lastUpdated: state.lastUpdated,
|
|
1495
|
-
async execute(fn) {
|
|
1496
|
-
abortController?.abort();
|
|
1497
|
-
const controller = new AbortController();
|
|
1498
|
-
abortController = controller;
|
|
1499
|
-
state.set('pending');
|
|
1500
|
-
state.setProgress(undefined);
|
|
1501
|
-
try {
|
|
1502
|
-
const result$ = fn();
|
|
1503
|
-
const result = isObservable(result$) ? await firstValueFrom(result$) : await result$;
|
|
1504
|
-
if (controller.signal.aborted) {
|
|
1505
|
-
return;
|
|
1506
|
-
}
|
|
1507
|
-
state.setSuccess(result);
|
|
1508
|
-
}
|
|
1509
|
-
catch (err) {
|
|
1510
|
-
if (controller.signal.aborted) {
|
|
1511
|
-
return;
|
|
1512
|
-
}
|
|
1513
|
-
state.setError(err);
|
|
1514
|
-
}
|
|
1515
|
-
finally {
|
|
1516
|
-
if (abortController === controller) {
|
|
1517
|
-
abortController = undefined;
|
|
1518
|
-
}
|
|
1519
|
-
}
|
|
1520
|
-
},
|
|
1521
|
-
reportProgress(value) {
|
|
1522
|
-
state.setProgress(value);
|
|
1523
|
-
},
|
|
1524
|
-
reset() {
|
|
1525
|
-
abortController?.abort();
|
|
1526
|
-
abortController = undefined;
|
|
1527
|
-
state.reset();
|
|
1528
|
-
},
|
|
1529
|
-
};
|
|
1530
|
-
}
|
|
1531
|
-
|
|
1532
1686
|
/** @internal Length-then-key-set equality for the operations Map signal. */
|
|
1533
1687
|
function mapKeySetEqual(a, b) {
|
|
1534
1688
|
if (a === b) {
|
|
@@ -1664,11 +1818,148 @@ function injectAsyncRegistry() {
|
|
|
1664
1818
|
return inject(CngxAsyncRegistry, { optional: true });
|
|
1665
1819
|
}
|
|
1666
1820
|
|
|
1821
|
+
/**
|
|
1822
|
+
* Create a mutation async state - for explicit user-triggered actions.
|
|
1823
|
+
*
|
|
1824
|
+
* Must be called in an injection context (field initializer or constructor)
|
|
1825
|
+
* because it uses `inject(DestroyRef)` for cleanup.
|
|
1826
|
+
*
|
|
1827
|
+
* ```typescript
|
|
1828
|
+
* readonly saveResident = createAsyncState<Resident>();
|
|
1829
|
+
*
|
|
1830
|
+
* async handleSave(): Promise<void> {
|
|
1831
|
+
* await this.saveResident.execute(
|
|
1832
|
+
* () => this.api.save(this.form().value())
|
|
1833
|
+
* );
|
|
1834
|
+
* }
|
|
1835
|
+
* ```
|
|
1836
|
+
*
|
|
1837
|
+
* @category common/data/async-state
|
|
1838
|
+
*/
|
|
1839
|
+
function createAsyncState(options) {
|
|
1840
|
+
const destroyRef = inject(DestroyRef);
|
|
1841
|
+
const state = createManualState();
|
|
1842
|
+
let abortController;
|
|
1843
|
+
destroyRef.onDestroy(() => {
|
|
1844
|
+
abortController?.abort();
|
|
1845
|
+
abortController = undefined;
|
|
1846
|
+
});
|
|
1847
|
+
// Same opt-in observability injectAsyncState offers: without it, mutations
|
|
1848
|
+
// built here are invisible to CngxAsyncRegistry.isAnythingLoading.
|
|
1849
|
+
if (options?.register) {
|
|
1850
|
+
const registry = injectAsyncRegistry();
|
|
1851
|
+
if (registry) {
|
|
1852
|
+
const operationId = registry.register(state, options.label);
|
|
1853
|
+
destroyRef.onDestroy(() => registry.unregister(operationId));
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
return {
|
|
1857
|
+
status: state.status,
|
|
1858
|
+
data: state.data,
|
|
1859
|
+
error: state.error,
|
|
1860
|
+
progress: state.progress,
|
|
1861
|
+
isLoading: state.isLoading,
|
|
1862
|
+
isPending: state.isPending,
|
|
1863
|
+
isRefreshing: state.isRefreshing,
|
|
1864
|
+
isBusy: state.isBusy,
|
|
1865
|
+
isFirstLoad: state.isFirstLoad,
|
|
1866
|
+
isEmpty: state.isEmpty,
|
|
1867
|
+
hasData: state.hasData,
|
|
1868
|
+
isSettled: state.isSettled,
|
|
1869
|
+
lastUpdated: state.lastUpdated,
|
|
1870
|
+
async execute(fn) {
|
|
1871
|
+
abortController?.abort();
|
|
1872
|
+
const controller = new AbortController();
|
|
1873
|
+
abortController = controller;
|
|
1874
|
+
state.set('pending');
|
|
1875
|
+
state.setProgress(undefined);
|
|
1876
|
+
try {
|
|
1877
|
+
const result$ = fn();
|
|
1878
|
+
const result = isObservable(result$) ? await firstValueFrom(result$) : await result$;
|
|
1879
|
+
if (controller.signal.aborted) {
|
|
1880
|
+
return;
|
|
1881
|
+
}
|
|
1882
|
+
state.setSuccess(result);
|
|
1883
|
+
}
|
|
1884
|
+
catch (err) {
|
|
1885
|
+
if (controller.signal.aborted) {
|
|
1886
|
+
return;
|
|
1887
|
+
}
|
|
1888
|
+
state.setError(err);
|
|
1889
|
+
}
|
|
1890
|
+
finally {
|
|
1891
|
+
if (abortController === controller) {
|
|
1892
|
+
abortController = undefined;
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
},
|
|
1896
|
+
reportProgress(value) {
|
|
1897
|
+
state.setProgress(value);
|
|
1898
|
+
},
|
|
1899
|
+
reset() {
|
|
1900
|
+
abortController?.abort();
|
|
1901
|
+
abortController = undefined;
|
|
1902
|
+
state.reset();
|
|
1903
|
+
},
|
|
1904
|
+
};
|
|
1905
|
+
}
|
|
1906
|
+
|
|
1907
|
+
/**
|
|
1908
|
+
* Wraps a *changing* source of async state in a stable
|
|
1909
|
+
* {@link CngxAsyncState} façade.
|
|
1910
|
+
*
|
|
1911
|
+
* A component that receives its state through an `Input` cannot publish that
|
|
1912
|
+
* object through `CNGX_STATEFUL` directly: the token is resolved once when a
|
|
1913
|
+
* bridge injects it, while the input can be rebound or absent. Capturing the
|
|
1914
|
+
* object would hand the bridge a stale state - or `undefined` before the
|
|
1915
|
+
* first binding.
|
|
1916
|
+
*
|
|
1917
|
+
* This returns one object whose every member is a `computed()` that reads the
|
|
1918
|
+
* source on each access, so bridges observe transitions of whatever is bound
|
|
1919
|
+
* right now. With nothing bound it reports a quiet `idle` state rather than
|
|
1920
|
+
* throwing, which is what lets a bridge sit inside a timeline that has not
|
|
1921
|
+
* been given a state yet.
|
|
1922
|
+
*
|
|
1923
|
+
* Contrast the select family, which provides `CNGX_STATEFUL` with
|
|
1924
|
+
* `useFactory` over a concrete `commitState` field - no forwarding needed
|
|
1925
|
+
* there, because the state is created by the component rather than passed in.
|
|
1926
|
+
* The split is not about the component, it is about where the state is born:
|
|
1927
|
+
* created locally, capture it; arriving through an `Input`, forward it.
|
|
1928
|
+
*
|
|
1929
|
+
* ```ts
|
|
1930
|
+
* readonly asyncState = createForwardedAsyncState(this.state);
|
|
1931
|
+
*
|
|
1932
|
+
* // providers:
|
|
1933
|
+
* { provide: CNGX_STATEFUL, useFactory: () => ({ state: inject(Host).asyncState }) }
|
|
1934
|
+
* ```
|
|
1935
|
+
*
|
|
1936
|
+
* @category common/data/async-state
|
|
1937
|
+
* @relatedTo createAsyncState, createManualState
|
|
1938
|
+
* @since 0.1.0
|
|
1939
|
+
*/
|
|
1940
|
+
function createForwardedAsyncState(source) {
|
|
1941
|
+
return {
|
|
1942
|
+
status: computed(() => source()?.status() ?? 'idle'),
|
|
1943
|
+
data: computed(() => source()?.data()),
|
|
1944
|
+
error: computed(() => source()?.error()),
|
|
1945
|
+
progress: computed(() => source()?.progress()),
|
|
1946
|
+
isLoading: computed(() => source()?.isLoading() ?? false),
|
|
1947
|
+
isPending: computed(() => source()?.isPending() ?? false),
|
|
1948
|
+
isRefreshing: computed(() => source()?.isRefreshing() ?? false),
|
|
1949
|
+
isBusy: computed(() => source()?.isBusy() ?? false),
|
|
1950
|
+
isFirstLoad: computed(() => source()?.isFirstLoad() ?? true),
|
|
1951
|
+
isEmpty: computed(() => source()?.isEmpty() ?? true),
|
|
1952
|
+
hasData: computed(() => source()?.hasData() ?? false),
|
|
1953
|
+
isSettled: computed(() => source()?.isSettled() ?? false),
|
|
1954
|
+
lastUpdated: computed(() => source()?.lastUpdated()),
|
|
1955
|
+
};
|
|
1956
|
+
}
|
|
1957
|
+
|
|
1667
1958
|
/**
|
|
1668
1959
|
* Create a reactive async state that auto-loads when signal dependencies change.
|
|
1669
1960
|
*
|
|
1670
1961
|
* Must be called in an injection context (field initializer or constructor).
|
|
1671
|
-
* The computation function is tracked by Angular's `effect()`
|
|
1962
|
+
* The computation function is tracked by Angular's `effect()` - any signal
|
|
1672
1963
|
* read inside `fn` will cause a re-load when it changes.
|
|
1673
1964
|
*
|
|
1674
1965
|
* ```typescript
|
|
@@ -1762,7 +2053,7 @@ function injectAsyncState(fn, options) {
|
|
|
1762
2053
|
result = fn();
|
|
1763
2054
|
}
|
|
1764
2055
|
catch (err) {
|
|
1765
|
-
// sync throw (e.g. required signal not yet set)
|
|
2056
|
+
// sync throw (e.g. required signal not yet set) - debounce the error
|
|
1766
2057
|
// to match the async path
|
|
1767
2058
|
if (debounceTimer !== undefined) {
|
|
1768
2059
|
clearTimeout(debounceTimer);
|
|
@@ -1777,6 +2068,13 @@ function injectAsyncState(fn, options) {
|
|
|
1777
2068
|
clearTimeout(debounceTimer);
|
|
1778
2069
|
}
|
|
1779
2070
|
const captured = result;
|
|
2071
|
+
if (!isObservable(captured)) {
|
|
2072
|
+
// The promise's work is already running (the invocation is the
|
|
2073
|
+
// tracking probe). A rapid follow-up change supersedes this capture
|
|
2074
|
+
// before the timer consumes it - observe the rejection here so a
|
|
2075
|
+
// superseded failure never surfaces as an unhandled rejection.
|
|
2076
|
+
captured.then(undefined, () => undefined);
|
|
2077
|
+
}
|
|
1780
2078
|
debounceTimer = setTimeout(() => {
|
|
1781
2079
|
debounceTimer = undefined;
|
|
1782
2080
|
void executeQuery(() => captured);
|
|
@@ -1809,7 +2107,7 @@ function injectAsyncState(fn, options) {
|
|
|
1809
2107
|
/**
|
|
1810
2108
|
* Pure function that resolves which view to show based on async state.
|
|
1811
2109
|
*
|
|
1812
|
-
* Encodes the state machine as a lookup table
|
|
2110
|
+
* Encodes the state machine as a lookup table - no branching:
|
|
1813
2111
|
*
|
|
1814
2112
|
* | status | firstLoad | empty | view |
|
|
1815
2113
|
* |-------------|-----------|-------|---------------|
|
|
@@ -1847,37 +2145,78 @@ function resolveAsyncView(status, firstLoad, empty) {
|
|
|
1847
2145
|
}
|
|
1848
2146
|
|
|
1849
2147
|
/**
|
|
1850
|
-
*
|
|
2148
|
+
* Headless boundary that aggregates N keyed `CngxAsyncState`s into one derived
|
|
2149
|
+
* `CngxAsyncState` and provides it as `CNGX_STATEFUL`.
|
|
1851
2150
|
*
|
|
1852
|
-
*
|
|
1853
|
-
*
|
|
2151
|
+
* The aggregate `state` is a first-class `CngxAsyncState`, so it renders
|
|
2152
|
+
* through `<cngx-async-container [state]="b.state">` and every other consumer
|
|
2153
|
+
* unchanged, and any transition bridge (`cngxToastOn`, `cngxAlertOn`,
|
|
2154
|
+
* `cngxBannerOn`) nested in the host fires on the combined status with zero
|
|
2155
|
+
* `[state]` wiring. `failures` exposes the errored sources - keyed, so a
|
|
2156
|
+
* consumer's `@for` can render per-source attribution through any feedback
|
|
2157
|
+
* component. `state.error` stays the first error for the single-error path.
|
|
1854
2158
|
*
|
|
1855
|
-
*
|
|
1856
|
-
*
|
|
2159
|
+
* ```html
|
|
2160
|
+
* <div [cngxAsyncBoundary]="sources" #b="cngxAsyncBoundary">
|
|
2161
|
+
* <cngx-async-container [state]="b.state"> ... </cngx-async-container>
|
|
2162
|
+
* <cngx-toast-on />
|
|
2163
|
+
* @for (f of b.failures(); track f.key) {
|
|
2164
|
+
* <cngx-banner>{{ f.label }} failed</cngx-banner>
|
|
2165
|
+
* }
|
|
2166
|
+
* </div>
|
|
2167
|
+
* ```
|
|
1857
2168
|
*
|
|
1858
|
-
*
|
|
1859
|
-
*
|
|
1860
|
-
*
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
2169
|
+
* @category common/data/async-state
|
|
2170
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/data/async-state/async-boundary.directive.ts
|
|
2171
|
+
* @since 0.1.0
|
|
2172
|
+
*/
|
|
2173
|
+
class CngxAsyncBoundary {
|
|
2174
|
+
/** The keyed source list to aggregate. */
|
|
2175
|
+
sources = input.required({ ...(ngDevMode ? { debugName: "sources" } : /* istanbul ignore next */ {}), alias: 'cngxAsyncBoundary' });
|
|
2176
|
+
states = computed(() => this.sources().map((s) => s.state), { ...(ngDevMode ? { debugName: "states" } : /* istanbul ignore next */ {}), equal: (a, b) => a.length === b.length && a.every((s, i) => s === b[i]) });
|
|
2177
|
+
/** The derived aggregate state - also exposed via `CNGX_STATEFUL`. */
|
|
2178
|
+
state = createAggregateAsyncState(this.states);
|
|
2179
|
+
/** The errored sources, keyed for per-source attribution. */
|
|
2180
|
+
failures = computed(() => this.sources()
|
|
2181
|
+
.filter((s) => s.state.status() === 'error')
|
|
2182
|
+
.map((s) => ({ key: s.key, label: s.label, error: s.state.error() })), { ...(ngDevMode ? { debugName: "failures" } : /* istanbul ignore next */ {}), equal: (a, b) => a.length === b.length &&
|
|
2183
|
+
a.every((f, i) => f.key === b[i].key && Object.is(f.error, b[i].error)) });
|
|
2184
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxAsyncBoundary, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
2185
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxAsyncBoundary, isStandalone: true, selector: "[cngxAsyncBoundary]", inputs: { sources: { classPropertyName: "sources", publicName: "cngxAsyncBoundary", isSignal: true, isRequired: true, transformFunction: null } }, host: { properties: { "attr.aria-busy": "state.isBusy() || null" } }, providers: [{ provide: CNGX_STATEFUL, useExisting: CngxAsyncBoundary }], exportAs: ["cngxAsyncBoundary"], ngImport: i0 });
|
|
2186
|
+
}
|
|
2187
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxAsyncBoundary, decorators: [{
|
|
2188
|
+
type: Directive,
|
|
2189
|
+
args: [{
|
|
2190
|
+
selector: '[cngxAsyncBoundary]',
|
|
2191
|
+
standalone: true,
|
|
2192
|
+
exportAs: 'cngxAsyncBoundary',
|
|
2193
|
+
providers: [{ provide: CNGX_STATEFUL, useExisting: CngxAsyncBoundary }],
|
|
2194
|
+
host: {
|
|
2195
|
+
'[attr.aria-busy]': 'state.isBusy() || null',
|
|
2196
|
+
},
|
|
2197
|
+
}]
|
|
2198
|
+
}], propDecorators: { sources: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxAsyncBoundary", required: true }] }] } });
|
|
2199
|
+
|
|
2200
|
+
/**
|
|
2201
|
+
* Shared projection core for the two resource bridges (`fromResource`,
|
|
2202
|
+
* `fromHttpResource`). Derives every flag through `buildAsyncStateView`, so
|
|
2203
|
+
* the family semantics (`isLoading` includes pending/refreshing,
|
|
2204
|
+
* `isBusy === isLoading`) cannot drift between the bridges and the factories.
|
|
1865
2205
|
*
|
|
1866
|
-
*
|
|
1867
|
-
* // items.status(), items.data(), items.isFirstLoad() — all work
|
|
1868
|
-
* // <cngx-async-container [state]="items"> — direct binding
|
|
1869
|
-
* ```
|
|
2206
|
+
* Must be called in an injection context (the tracking `effect()` requires one).
|
|
1870
2207
|
*
|
|
1871
|
-
* @
|
|
2208
|
+
* @internal
|
|
1872
2209
|
*/
|
|
1873
|
-
function
|
|
1874
|
-
//
|
|
1875
|
-
//
|
|
2210
|
+
function buildResourceBridge(ref, progress) {
|
|
2211
|
+
// ResourceStatus has no "first load" concept, so a successful load is
|
|
2212
|
+
// latched here together with its timestamp.
|
|
1876
2213
|
const hadSuccess = signal(false, ...(ngDevMode ? [{ debugName: "hadSuccess" }] : /* istanbul ignore next */ []));
|
|
2214
|
+
const lastUpdated = signal(undefined, ...(ngDevMode ? [{ debugName: "lastUpdated" }] : /* istanbul ignore next */ []));
|
|
1877
2215
|
effect(() => {
|
|
1878
2216
|
const s = ref.status();
|
|
1879
2217
|
if (s === 'resolved' || s === 'local') {
|
|
1880
2218
|
hadSuccess.set(true);
|
|
2219
|
+
lastUpdated.set(new Date());
|
|
1881
2220
|
}
|
|
1882
2221
|
});
|
|
1883
2222
|
const status = computed(() => {
|
|
@@ -1895,44 +2234,44 @@ function fromResource(ref) {
|
|
|
1895
2234
|
return 'error';
|
|
1896
2235
|
}
|
|
1897
2236
|
}, ...(ngDevMode ? [{ debugName: "status" }] : /* istanbul ignore next */ []));
|
|
1898
|
-
|
|
1899
|
-
const error = computed(() => ref.error(), ...(ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []));
|
|
1900
|
-
const isLoading = computed(() => status() === 'loading', ...(ngDevMode ? [{ debugName: "isLoading" }] : /* istanbul ignore next */ []));
|
|
1901
|
-
const isPending = computed(() => false, ...(ngDevMode ? [{ debugName: "isPending" }] : /* istanbul ignore next */ [])); // resource() has no mutation concept
|
|
1902
|
-
const isRefreshing = computed(() => status() === 'refreshing', ...(ngDevMode ? [{ debugName: "isRefreshing" }] : /* istanbul ignore next */ []));
|
|
1903
|
-
const isBusy = computed(() => ref.isLoading(), ...(ngDevMode ? [{ debugName: "isBusy" }] : /* istanbul ignore next */ []));
|
|
1904
|
-
const isFirstLoad = computed(() => !hadSuccess() && (isBusy() || status() === 'idle'), ...(ngDevMode ? [{ debugName: "isFirstLoad" }] : /* istanbul ignore next */ []));
|
|
1905
|
-
const isEmpty = computed(() => {
|
|
1906
|
-
const d = data();
|
|
1907
|
-
return d == null || (Array.isArray(d) && d.length === 0);
|
|
1908
|
-
}, ...(ngDevMode ? [{ debugName: "isEmpty" }] : /* istanbul ignore next */ []));
|
|
1909
|
-
const hasData = computed(() => ref.hasValue() && !isEmpty(), ...(ngDevMode ? [{ debugName: "hasData" }] : /* istanbul ignore next */ []));
|
|
1910
|
-
const isSettled = computed(() => {
|
|
1911
|
-
const s = status();
|
|
1912
|
-
return s === 'success' || s === 'error';
|
|
1913
|
-
}, ...(ngDevMode ? [{ debugName: "isSettled" }] : /* istanbul ignore next */ []));
|
|
1914
|
-
const lastUpdated = signal(undefined, ...(ngDevMode ? [{ debugName: "lastUpdated" }] : /* istanbul ignore next */ []));
|
|
1915
|
-
effect(() => {
|
|
1916
|
-
const s = ref.status();
|
|
1917
|
-
if (s === 'resolved' || s === 'local') {
|
|
1918
|
-
lastUpdated.set(new Date());
|
|
1919
|
-
}
|
|
1920
|
-
});
|
|
1921
|
-
return {
|
|
2237
|
+
return buildAsyncStateView({
|
|
1922
2238
|
status,
|
|
1923
|
-
data,
|
|
1924
|
-
error,
|
|
1925
|
-
progress
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
isBusy,
|
|
1930
|
-
isFirstLoad,
|
|
1931
|
-
isEmpty,
|
|
1932
|
-
hasData,
|
|
1933
|
-
isSettled,
|
|
2239
|
+
data: computed(() => (ref.hasValue() ? ref.value() : undefined)),
|
|
2240
|
+
error: computed(() => ref.error()),
|
|
2241
|
+
progress,
|
|
2242
|
+
// Idle counts as "before the first load": a not-yet-triggered resource
|
|
2243
|
+
// still shows the skeleton, not the empty state.
|
|
2244
|
+
isFirstLoad: computed(() => !hadSuccess() && (ref.isLoading() || status() === 'idle')),
|
|
1934
2245
|
lastUpdated: lastUpdated.asReadonly(),
|
|
1935
|
-
};
|
|
2246
|
+
});
|
|
2247
|
+
}
|
|
2248
|
+
|
|
2249
|
+
/**
|
|
2250
|
+
* Bridge that projects an Angular `Resource<T>` onto `CngxAsyncState<T>`.
|
|
2251
|
+
*
|
|
2252
|
+
* Must be called in an injection context (the `effect()` that tracks
|
|
2253
|
+
* `hadSuccess` requires one).
|
|
2254
|
+
*
|
|
2255
|
+
* All signals are derived reactively from the resource - no manual
|
|
2256
|
+
* synchronization. The resource stays the single source of truth.
|
|
2257
|
+
*
|
|
2258
|
+
* ```typescript
|
|
2259
|
+
* private readonly res = resource({
|
|
2260
|
+
* request: () => ({ filter: this.filter() }),
|
|
2261
|
+
* loader: ({ request, abortSignal }) =>
|
|
2262
|
+
* fetch(`/api/items?q=${request.filter}`, { signal: abortSignal })
|
|
2263
|
+
* .then(r => r.json()),
|
|
2264
|
+
* });
|
|
2265
|
+
*
|
|
2266
|
+
* readonly items = fromResource(this.res);
|
|
2267
|
+
* // items.status(), items.data(), items.isFirstLoad() - all work
|
|
2268
|
+
* // <cngx-async-container [state]="items"> - direct binding
|
|
2269
|
+
* ```
|
|
2270
|
+
*
|
|
2271
|
+
* @category common/data/async-state
|
|
2272
|
+
*/
|
|
2273
|
+
function fromResource(ref) {
|
|
2274
|
+
return buildResourceBridge(ref);
|
|
1936
2275
|
}
|
|
1937
2276
|
|
|
1938
2277
|
/**
|
|
@@ -1951,37 +2290,13 @@ function fromResource(ref) {
|
|
|
1951
2290
|
*
|
|
1952
2291
|
* readonly items = fromHttpResource(this.res);
|
|
1953
2292
|
* // items.progress() tracks upload/download progress
|
|
1954
|
-
* // <cngx-progress [state]="items">
|
|
2293
|
+
* // <cngx-progress [state]="items"> - auto-wired progress bar
|
|
1955
2294
|
* ```
|
|
1956
2295
|
*
|
|
1957
2296
|
* @category common/data/async-state
|
|
1958
2297
|
*/
|
|
1959
2298
|
function fromHttpResource(ref) {
|
|
1960
|
-
|
|
1961
|
-
effect(() => {
|
|
1962
|
-
const s = ref.status();
|
|
1963
|
-
if (s === 'resolved' || s === 'local') {
|
|
1964
|
-
hadSuccess.set(true);
|
|
1965
|
-
}
|
|
1966
|
-
});
|
|
1967
|
-
const status = computed(() => {
|
|
1968
|
-
switch (ref.status()) {
|
|
1969
|
-
case 'idle':
|
|
1970
|
-
return 'idle';
|
|
1971
|
-
case 'loading':
|
|
1972
|
-
return 'loading';
|
|
1973
|
-
case 'reloading':
|
|
1974
|
-
return 'refreshing';
|
|
1975
|
-
case 'resolved':
|
|
1976
|
-
case 'local':
|
|
1977
|
-
return 'success';
|
|
1978
|
-
case 'error':
|
|
1979
|
-
return 'error';
|
|
1980
|
-
}
|
|
1981
|
-
}, ...(ngDevMode ? [{ debugName: "status" }] : /* istanbul ignore next */ []));
|
|
1982
|
-
const data = computed(() => (ref.hasValue() ? ref.value() : undefined), ...(ngDevMode ? [{ debugName: "data" }] : /* istanbul ignore next */ []));
|
|
1983
|
-
const error = computed(() => ref.error(), ...(ngDevMode ? [{ debugName: "error" }] : /* istanbul ignore next */ []));
|
|
1984
|
-
// Map HTTP progress (0–1 float) to 0–100 integer, clamped
|
|
2299
|
+
// Map HTTP progress (0-1 float) to 0-100 integer, clamped.
|
|
1985
2300
|
const progress = computed(() => {
|
|
1986
2301
|
const p = ref.progress();
|
|
1987
2302
|
if (p == null) {
|
|
@@ -1989,52 +2304,20 @@ function fromHttpResource(ref) {
|
|
|
1989
2304
|
}
|
|
1990
2305
|
return Math.round(Math.min(p, 1) * 100);
|
|
1991
2306
|
}, ...(ngDevMode ? [{ debugName: "progress" }] : /* istanbul ignore next */ []));
|
|
1992
|
-
|
|
1993
|
-
const isPending = computed(() => false, ...(ngDevMode ? [{ debugName: "isPending" }] : /* istanbul ignore next */ []));
|
|
1994
|
-
const isRefreshing = computed(() => status() === 'refreshing', ...(ngDevMode ? [{ debugName: "isRefreshing" }] : /* istanbul ignore next */ []));
|
|
1995
|
-
const isBusy = computed(() => ref.isLoading(), ...(ngDevMode ? [{ debugName: "isBusy" }] : /* istanbul ignore next */ []));
|
|
1996
|
-
const isFirstLoad = computed(() => !hadSuccess() && isBusy(), ...(ngDevMode ? [{ debugName: "isFirstLoad" }] : /* istanbul ignore next */ []));
|
|
1997
|
-
const isEmpty = computed(() => {
|
|
1998
|
-
const d = data();
|
|
1999
|
-
return d == null || (Array.isArray(d) && d.length === 0);
|
|
2000
|
-
}, ...(ngDevMode ? [{ debugName: "isEmpty" }] : /* istanbul ignore next */ []));
|
|
2001
|
-
const hasData = computed(() => ref.hasValue() && !isEmpty(), ...(ngDevMode ? [{ debugName: "hasData" }] : /* istanbul ignore next */ []));
|
|
2002
|
-
const isSettled = computed(() => {
|
|
2003
|
-
const s = status();
|
|
2004
|
-
return s === 'success' || s === 'error';
|
|
2005
|
-
}, ...(ngDevMode ? [{ debugName: "isSettled" }] : /* istanbul ignore next */ []));
|
|
2006
|
-
const lastUpdated = signal(undefined, ...(ngDevMode ? [{ debugName: "lastUpdated" }] : /* istanbul ignore next */ []));
|
|
2007
|
-
effect(() => {
|
|
2008
|
-
const s = ref.status();
|
|
2009
|
-
if (s === 'resolved' || s === 'local') {
|
|
2010
|
-
lastUpdated.set(new Date());
|
|
2011
|
-
}
|
|
2012
|
-
});
|
|
2013
|
-
return {
|
|
2014
|
-
status,
|
|
2015
|
-
data,
|
|
2016
|
-
error,
|
|
2017
|
-
progress,
|
|
2018
|
-
isLoading,
|
|
2019
|
-
isPending,
|
|
2020
|
-
isRefreshing,
|
|
2021
|
-
isBusy,
|
|
2022
|
-
isFirstLoad,
|
|
2023
|
-
isEmpty,
|
|
2024
|
-
hasData,
|
|
2025
|
-
isSettled,
|
|
2026
|
-
lastUpdated: lastUpdated.asReadonly(),
|
|
2027
|
-
};
|
|
2307
|
+
return buildResourceBridge(ref, progress);
|
|
2028
2308
|
}
|
|
2029
2309
|
|
|
2030
2310
|
/**
|
|
2031
2311
|
* RxJS operator that wires an Observable's lifecycle to a `ManualAsyncState`.
|
|
2032
2312
|
*
|
|
2033
|
-
* On subscribe: sets `loading` (or `refreshing` if data was already loaded
|
|
2313
|
+
* On subscribe: sets `loading` (or `refreshing` if data was already loaded,
|
|
2314
|
+
* read via the sink's `isFirstLoad`; an explicit `options.status` wins).
|
|
2034
2315
|
* On next: calls `setSuccess(value)`.
|
|
2035
2316
|
* On error: calls `setError(err)` and **re-throws** (does not swallow).
|
|
2317
|
+
* On teardown without a value (unsubscribe mid-flight, empty complete):
|
|
2318
|
+
* resets the sink to `idle` so a cancelled request never leaves it busy.
|
|
2036
2319
|
*
|
|
2037
|
-
* The Observable passes through unchanged
|
|
2320
|
+
* The Observable passes through unchanged - `tapAsyncState` is a side-effect operator.
|
|
2038
2321
|
*
|
|
2039
2322
|
* ```typescript
|
|
2040
2323
|
* readonly residents = createManualState<Resident[]>();
|
|
@@ -2051,10 +2334,23 @@ function fromHttpResource(ref) {
|
|
|
2051
2334
|
*/
|
|
2052
2335
|
function tapAsyncState(state, options) {
|
|
2053
2336
|
return (source) => defer(() => {
|
|
2054
|
-
state.set(options?.status ?? 'loading');
|
|
2337
|
+
state.set(options?.status ?? (state.isFirstLoad?.() === false ? 'refreshing' : 'loading'));
|
|
2338
|
+
let settled = false;
|
|
2055
2339
|
return source.pipe(tap({
|
|
2056
|
-
next: (value) =>
|
|
2057
|
-
|
|
2340
|
+
next: (value) => {
|
|
2341
|
+
settled = true;
|
|
2342
|
+
state.setSuccess(value);
|
|
2343
|
+
},
|
|
2344
|
+
error: (err) => {
|
|
2345
|
+
settled = true;
|
|
2346
|
+
state.setError(err);
|
|
2347
|
+
},
|
|
2348
|
+
}), finalize(() => {
|
|
2349
|
+
// Torn down without ever settling (cancelled mid-flight or an
|
|
2350
|
+
// empty complete) - do not leave the sink busy forever.
|
|
2351
|
+
if (!settled) {
|
|
2352
|
+
state.set('idle');
|
|
2353
|
+
}
|
|
2058
2354
|
}));
|
|
2059
2355
|
});
|
|
2060
2356
|
}
|
|
@@ -2122,7 +2418,7 @@ function tapAsyncProgress(state) {
|
|
|
2122
2418
|
* tapHttpAsyncState(this.upload),
|
|
2123
2419
|
* takeUntilDestroyed(this.destroyRef),
|
|
2124
2420
|
* ).subscribe();
|
|
2125
|
-
* // upload.status(), upload.progress(), upload.data()
|
|
2421
|
+
* // upload.status(), upload.progress(), upload.data() - all wired
|
|
2126
2422
|
* }
|
|
2127
2423
|
* ```
|
|
2128
2424
|
*
|
|
@@ -2131,6 +2427,7 @@ function tapAsyncProgress(state) {
|
|
|
2131
2427
|
function tapHttpAsyncState(state, options) {
|
|
2132
2428
|
return (source) => defer(() => {
|
|
2133
2429
|
state.set(options?.status ?? 'loading');
|
|
2430
|
+
let settled = false;
|
|
2134
2431
|
return source.pipe(tapAsyncProgress(state), filter((event) => {
|
|
2135
2432
|
return event.type === RESPONSE;
|
|
2136
2433
|
}), map((response) => {
|
|
@@ -2139,12 +2436,49 @@ function tapHttpAsyncState(state, options) {
|
|
|
2139
2436
|
}
|
|
2140
2437
|
return response.body;
|
|
2141
2438
|
}), tap({
|
|
2142
|
-
next: (value) =>
|
|
2143
|
-
|
|
2439
|
+
next: (value) => {
|
|
2440
|
+
settled = true;
|
|
2441
|
+
state.setSuccess(value);
|
|
2442
|
+
},
|
|
2443
|
+
error: (err) => {
|
|
2444
|
+
settled = true;
|
|
2445
|
+
state.setError(err);
|
|
2446
|
+
},
|
|
2447
|
+
}), finalize(() => {
|
|
2448
|
+
if (!settled) {
|
|
2449
|
+
state.set('idle');
|
|
2450
|
+
}
|
|
2144
2451
|
}));
|
|
2145
2452
|
});
|
|
2146
2453
|
}
|
|
2147
2454
|
|
|
2455
|
+
/**
|
|
2456
|
+
* Bridges {@link CngxAsyncRegistry} into a {@link CngxLatencyProbe} measuring the
|
|
2457
|
+
* registry's observed busy-envelope: how long the app was "anything loading"
|
|
2458
|
+
* during the last in-flight window.
|
|
2459
|
+
*
|
|
2460
|
+
* An app-shell indicator compares `lastDuration()` against
|
|
2461
|
+
* `CNGX_LOADING_CONFIG.spinnerVsSkeletonCutoff` to pick a spinner (fast last
|
|
2462
|
+
* aggregate) vs a skeleton (slow last aggregate) before the next load renders.
|
|
2463
|
+
*
|
|
2464
|
+
* When the registry is absent (`provideAsyncRegistry` never called),
|
|
2465
|
+
* `injectAsyncRegistry()` returns `null`, so the probe's source is permanently
|
|
2466
|
+
* `false`: it is never busy and never throws.
|
|
2467
|
+
*
|
|
2468
|
+
* Must run in an injection context.
|
|
2469
|
+
*
|
|
2470
|
+
* @returns A probe over `CngxAsyncRegistry.isAnythingLoading`.
|
|
2471
|
+
*
|
|
2472
|
+
* @category common/data/async-registry
|
|
2473
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/data/async-registry/inject-latency-probe.ts
|
|
2474
|
+
* @since 0.1.0
|
|
2475
|
+
* @relatedTo provideAsyncRegistry, injectAsyncRegistry, createLatencyProbe
|
|
2476
|
+
*/
|
|
2477
|
+
function injectLatencyProbe() {
|
|
2478
|
+
const registry = injectAsyncRegistry();
|
|
2479
|
+
return createLatencyProbe(() => registry?.isAnythingLoading() ?? false);
|
|
2480
|
+
}
|
|
2481
|
+
|
|
2148
2482
|
/**
|
|
2149
2483
|
* Per-request label surfaced in `CngxAsyncRegistry.activeOperations` when the
|
|
2150
2484
|
* request is tracked by `cngxAsyncInterceptor`. Display only, never a key.
|
|
@@ -2267,7 +2601,10 @@ function provideAsyncHttpObservability() {
|
|
|
2267
2601
|
* - **success + empty** → empty template (or nothing)
|
|
2268
2602
|
* - **error (first load)** → error template (or nothing)
|
|
2269
2603
|
* - **refreshing / loading (with data)** → content template (old data stays visible)
|
|
2270
|
-
* - **error (with data)** → content template (old data stays visible)
|
|
2604
|
+
* - **error (with data)** → content template (old data stays visible) -
|
|
2605
|
+
* `resolveAsyncView` reports this as `content+error`, but a structural
|
|
2606
|
+
* directive renders exactly one template, so the error half is flattened
|
|
2607
|
+
* away here; surface it separately (toast, alert) when it must be visible
|
|
2271
2608
|
*
|
|
2272
2609
|
* ### Minimal - just content
|
|
2273
2610
|
* ```html
|
|
@@ -2324,7 +2661,10 @@ class CngxAsync {
|
|
|
2324
2661
|
const s = this.cngxAsync();
|
|
2325
2662
|
return resolveAsyncView(s.status(), s.isFirstLoad(), s.isEmpty());
|
|
2326
2663
|
}, ...(ngDevMode ? [{ debugName: "view" }] : /* istanbul ignore next */ []));
|
|
2327
|
-
|
|
2664
|
+
// Plain field, not a signal: it is only ever read and written inside the
|
|
2665
|
+
// render effect - as a signal it fed the effect's own dependency graph and
|
|
2666
|
+
// caused one spurious re-run per view switch.
|
|
2667
|
+
currentView = 'none';
|
|
2328
2668
|
contentViewRef = null;
|
|
2329
2669
|
constructor() {
|
|
2330
2670
|
effect(() => {
|
|
@@ -2332,13 +2672,13 @@ class CngxAsync {
|
|
|
2332
2672
|
const s = this.cngxAsync();
|
|
2333
2673
|
// content+error → show content (structural directive has no dual-render)
|
|
2334
2674
|
const effective = view === 'content+error' ? 'content' : view;
|
|
2335
|
-
if (effective === this.currentView
|
|
2675
|
+
if (effective === this.currentView) {
|
|
2336
2676
|
this.updateContentContext(s);
|
|
2337
2677
|
return;
|
|
2338
2678
|
}
|
|
2339
2679
|
this.vcr.clear();
|
|
2340
2680
|
this.contentViewRef = null;
|
|
2341
|
-
this.currentView
|
|
2681
|
+
this.currentView = effective;
|
|
2342
2682
|
this.renderView(effective, s);
|
|
2343
2683
|
});
|
|
2344
2684
|
}
|
|
@@ -2396,11 +2736,139 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
2396
2736
|
}]
|
|
2397
2737
|
}], ctorParameters: () => [], propDecorators: { cngxAsync: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxAsync", required: true }] }], cngxAsyncSkeleton: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxAsyncSkeleton", required: false }] }], cngxAsyncEmpty: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxAsyncEmpty", required: false }] }], cngxAsyncError: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxAsyncError", required: false }] }] } });
|
|
2398
2738
|
|
|
2739
|
+
/**
|
|
2740
|
+
* The English kpi section: the single source of the KPI atoms' English copy.
|
|
2741
|
+
* `CNGX_KPI_I18N` defaults to it.
|
|
2742
|
+
*
|
|
2743
|
+
* @category common/data/i18n
|
|
2744
|
+
* @since 0.1.0
|
|
2745
|
+
* @relatedTo CNGX_KPI_I18N
|
|
2746
|
+
*/
|
|
2747
|
+
const CNGX_KPI_LANGUAGE_EN = {
|
|
2748
|
+
deltaLabel: '{value} {sentiment}',
|
|
2749
|
+
deltaImproved: 'improved',
|
|
2750
|
+
deltaDeclined: 'declined',
|
|
2751
|
+
deltaUnchanged: 'unchanged',
|
|
2752
|
+
trendLabel: '{value} {direction}',
|
|
2753
|
+
trendUp: 'up',
|
|
2754
|
+
trendDown: 'down',
|
|
2755
|
+
trendFlat: 'unchanged',
|
|
2756
|
+
goalValueText: '{now} of {max}',
|
|
2757
|
+
metricValueWithUnit: '{value} {unit}',
|
|
2758
|
+
metricPlaceholder: '\u2013',
|
|
2759
|
+
metricNoValue: 'No value',
|
|
2760
|
+
};
|
|
2761
|
+
|
|
2762
|
+
const GOAL_NUMBER = {};
|
|
2763
|
+
/** @internal Turns a kpi section into the token's keys for a locale. */
|
|
2764
|
+
function kpiBundleFrom(section, locale) {
|
|
2765
|
+
const sentiment = {
|
|
2766
|
+
positive: section.deltaImproved,
|
|
2767
|
+
negative: section.deltaDeclined,
|
|
2768
|
+
neutral: section.deltaUnchanged,
|
|
2769
|
+
};
|
|
2770
|
+
const direction = {
|
|
2771
|
+
up: section.trendUp,
|
|
2772
|
+
down: section.trendDown,
|
|
2773
|
+
flat: section.trendFlat,
|
|
2774
|
+
};
|
|
2775
|
+
const goalNumber = numberFormatterFor(locale, GOAL_NUMBER);
|
|
2776
|
+
return {
|
|
2777
|
+
deltaLabel: (value, s) => formatMessage(section.deltaLabel, { value, sentiment: sentiment[s] }, locale),
|
|
2778
|
+
trendLabel: (value, d) => formatMessage(section.trendLabel, { value, direction: direction[d] }, locale),
|
|
2779
|
+
goalValueText: (now, max) => formatMessage(section.goalValueText, { now: goalNumber.format(now), max: goalNumber.format(max) }, locale),
|
|
2780
|
+
metricValueWithUnit: section.metricValueWithUnit,
|
|
2781
|
+
metricPlaceholder: section.metricPlaceholder,
|
|
2782
|
+
metricNoValue: section.metricNoValue,
|
|
2783
|
+
};
|
|
2784
|
+
}
|
|
2785
|
+
/** @internal The kpi section of the active pack over English. */
|
|
2786
|
+
const injectKpiSection = createLanguageSection('kpi', CNGX_KPI_LANGUAGE_EN);
|
|
2787
|
+
/** @internal Builds and reads the token, formatted for the reading locale. */
|
|
2788
|
+
const kpiBundle = createSectionBundle({
|
|
2789
|
+
section: injectKpiSection,
|
|
2790
|
+
toBundle: kpiBundleFrom,
|
|
2791
|
+
});
|
|
2792
|
+
/**
|
|
2793
|
+
* DI token for the KPI i18n bundle. `providedIn: 'root'`: the kpi section
|
|
2794
|
+
* of the active language pack over the English defaults, formatted for the
|
|
2795
|
+
* app locale; the value is a `Signal`, shared by every reader under one
|
|
2796
|
+
* injector.
|
|
2797
|
+
*
|
|
2798
|
+
* @category common/data/i18n
|
|
2799
|
+
* @wcag AA
|
|
2800
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/data/display/shared/kpi-i18n.ts
|
|
2801
|
+
* @since 0.1.0
|
|
2802
|
+
* @relatedTo CngxDelta, CngxTrend, CngxGoal
|
|
2803
|
+
*/
|
|
2804
|
+
const CNGX_KPI_I18N = new InjectionToken('CngxKpiI18n', {
|
|
2805
|
+
providedIn: 'root',
|
|
2806
|
+
factory: () => kpiBundle.build(),
|
|
2807
|
+
});
|
|
2808
|
+
/** @internal */
|
|
2809
|
+
function defineKpiI18nFeature(fn) {
|
|
2810
|
+
return Object.assign(fn, { _target: 'i18n' });
|
|
2811
|
+
}
|
|
2812
|
+
/**
|
|
2813
|
+
* Override KPI labels via a partial bundle - unset keys keep the language
|
|
2814
|
+
* pack's copy, or the English default. Pass a `Signal` of a partial bundle to switch languages at
|
|
2815
|
+
* runtime.
|
|
2816
|
+
*
|
|
2817
|
+
* @category common/data/i18n
|
|
2818
|
+
* @since 0.1.0
|
|
2819
|
+
*/
|
|
2820
|
+
function withKpiI18nLabels(overrides) {
|
|
2821
|
+
return defineKpiI18nFeature((bundle) => createOverrideMerge(bundle, overrides));
|
|
2822
|
+
}
|
|
2823
|
+
/**
|
|
2824
|
+
* Provider for the KPI i18n bundle. Returns a plain `Provider`, so it also
|
|
2825
|
+
* scopes a subtree through `viewProviders`. The features apply on top of the
|
|
2826
|
+
* active language pack.
|
|
2827
|
+
*
|
|
2828
|
+
* ```ts
|
|
2829
|
+
* bootstrapApplication(AppComponent, {
|
|
2830
|
+
* providers: [
|
|
2831
|
+
* provideKpiI18n(
|
|
2832
|
+
* withKpiI18nLabels({
|
|
2833
|
+
* goalValueText: (now, max) => `${now} von ${max}`,
|
|
2834
|
+
* }),
|
|
2835
|
+
* ),
|
|
2836
|
+
* ],
|
|
2837
|
+
* });
|
|
2838
|
+
* ```
|
|
2839
|
+
*
|
|
2840
|
+
* @category common/data/i18n
|
|
2841
|
+
* @since 0.1.0
|
|
2842
|
+
*/
|
|
2843
|
+
function provideKpiI18n(...features) {
|
|
2844
|
+
return {
|
|
2845
|
+
provide: CNGX_KPI_I18N,
|
|
2846
|
+
useFactory: () => kpiBundle.build(features),
|
|
2847
|
+
};
|
|
2848
|
+
}
|
|
2849
|
+
/**
|
|
2850
|
+
* Inject the resolved KPI i18n bundle signal. Read it inside a `computed()`
|
|
2851
|
+
* or template so a runtime override flip re-derives.
|
|
2852
|
+
*
|
|
2853
|
+
* @category common/data/i18n
|
|
2854
|
+
* @since 0.1.0
|
|
2855
|
+
*/
|
|
2856
|
+
function injectKpiI18n() {
|
|
2857
|
+
return kpiBundle.resolve(inject(CNGX_KPI_I18N));
|
|
2858
|
+
}
|
|
2859
|
+
|
|
2860
|
+
const UNIT_PLACEHOLDER = /\{(value|unit)\}/;
|
|
2861
|
+
/** @internal `true` when the language reads the unit before the value. */
|
|
2862
|
+
function readsUnitFirst(message) {
|
|
2863
|
+
const [, first] = UNIT_PLACEHOLDER.exec(message) ?? [];
|
|
2864
|
+
return first === 'unit';
|
|
2865
|
+
}
|
|
2399
2866
|
/**
|
|
2400
2867
|
* Displays a formatted numeric value with optional unit.
|
|
2401
2868
|
*
|
|
2402
|
-
* Uses `Intl.NumberFormat` with the
|
|
2403
|
-
*
|
|
2869
|
+
* Uses `Intl.NumberFormat` with the app locale (`CNGX_LOCALE`, falling back to
|
|
2870
|
+
* the nearest `LOCALE_ID`) for locale-aware formatting; a locale flip
|
|
2871
|
+
* re-formats. A `null` value renders the placeholder glyph without its unit.
|
|
2404
2872
|
*
|
|
2405
2873
|
* Composable - works inside any card variant, header, body, or standalone.
|
|
2406
2874
|
*
|
|
@@ -2433,8 +2901,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
2433
2901
|
* <example-url>http://localhost:4200/#/common/data/metric/standalone-metrics</example-url>
|
|
2434
2902
|
*/
|
|
2435
2903
|
class CngxMetric {
|
|
2436
|
-
locale =
|
|
2437
|
-
|
|
2904
|
+
locale = injectLocale();
|
|
2905
|
+
i18n = injectKpiI18n();
|
|
2906
|
+
/**
|
|
2907
|
+
* Numeric or string value. `null` renders the `metricPlaceholder` glyph of
|
|
2908
|
+
* the kpi language section and is announced as its `metricNoValue` text.
|
|
2909
|
+
*/
|
|
2438
2910
|
value = input.required(...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
|
|
2439
2911
|
/** Unit suffix (e.g. "bpm", "h", "%", "kg"). */
|
|
2440
2912
|
unit = input(undefined, ...(ngDevMode ? [{ debugName: "unit" }] : /* istanbul ignore next */ []));
|
|
@@ -2444,28 +2916,43 @@ class CngxMetric {
|
|
|
2444
2916
|
formattedValue = computed(() => {
|
|
2445
2917
|
const v = this.value();
|
|
2446
2918
|
if (v === null) {
|
|
2447
|
-
return
|
|
2919
|
+
return this.i18n().metricPlaceholder;
|
|
2448
2920
|
}
|
|
2449
2921
|
if (typeof v === 'string') {
|
|
2450
2922
|
return v;
|
|
2451
2923
|
}
|
|
2452
|
-
return this.format()
|
|
2453
|
-
? new Intl.NumberFormat(this.locale, this.format()).format(v)
|
|
2454
|
-
: v.toLocaleString(this.locale);
|
|
2924
|
+
return numberFormatterFor(this.locale(), this.format() ?? {}).format(v);
|
|
2455
2925
|
}, ...(ngDevMode ? [{ debugName: "formattedValue" }] : /* istanbul ignore next */ []));
|
|
2926
|
+
/**
|
|
2927
|
+
* @internal The unit to render, `undefined` while there is no value: a
|
|
2928
|
+
* missing reading has no unit, so "No value km" is never shown or spoken.
|
|
2929
|
+
*/
|
|
2930
|
+
shownUnit = computed(() => {
|
|
2931
|
+
const unit = this.unit();
|
|
2932
|
+
return this.value() === null || unit === '' ? undefined : unit;
|
|
2933
|
+
}, ...(ngDevMode ? [{ debugName: "shownUnit" }] : /* istanbul ignore next */ []));
|
|
2934
|
+
/** @internal Unit before value, per the `metricValueWithUnit` message. */
|
|
2935
|
+
unitFirst = computed(() => readsUnitFirst(this.i18n().metricValueWithUnit), ...(ngDevMode ? [{ debugName: "unitFirst" }] : /* istanbul ignore next */ []));
|
|
2456
2936
|
/** @internal Full accessible description including unit. */
|
|
2457
2937
|
accessibleValue = computed(() => {
|
|
2458
|
-
const
|
|
2459
|
-
|
|
2460
|
-
|
|
2938
|
+
const i18n = this.i18n();
|
|
2939
|
+
if (this.value() === null) {
|
|
2940
|
+
return i18n.metricNoValue;
|
|
2941
|
+
}
|
|
2942
|
+
const value = this.formattedValue();
|
|
2943
|
+
const unit = this.shownUnit();
|
|
2944
|
+
return unit ? formatMessage(i18n.metricValueWithUnit, { value, unit }, this.locale()) : value;
|
|
2461
2945
|
}, ...(ngDevMode ? [{ debugName: "accessibleValue" }] : /* istanbul ignore next */ []));
|
|
2462
2946
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxMetric, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
2463
2947
|
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.4", type: CngxMetric, isStandalone: true, selector: "cngx-metric", inputs: { value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: true, transformFunction: null }, unit: { classPropertyName: "unit", publicName: "unit", isSignal: true, isRequired: false, transformFunction: null }, format: { classPropertyName: "format", publicName: "format", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "role": "img" }, properties: { "attr.aria-label": "accessibleValue()" }, classAttribute: "cngx-metric" }, ngImport: i0, template: `
|
|
2948
|
+
@if (shownUnit() && unitFirst()) {
|
|
2949
|
+
<span class="cngx-metric__unit">{{ shownUnit() }}</span>
|
|
2950
|
+
}
|
|
2464
2951
|
<span class="cngx-metric__value">{{ formattedValue() }}</span>
|
|
2465
|
-
@if (
|
|
2466
|
-
<span class="cngx-metric__unit">{{
|
|
2952
|
+
@if (shownUnit() && !unitFirst()) {
|
|
2953
|
+
<span class="cngx-metric__unit">{{ shownUnit() }}</span>
|
|
2467
2954
|
}
|
|
2468
|
-
`, isInline: true, styles: ["@layer cngx.tokens{@property --cngx-metric-gap{syntax: \"<length>\"; inherits: false; initial-value: 2px;}@property --cngx-metric-value-size{syntax: \"*\"; inherits: true; initial-value: 1.75rem;}@property --cngx-metric-value-weight{syntax: \"<number>\"; inherits: true; initial-value: 600;}@property --cngx-metric-value-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.2 .01 290);}@property --cngx-metric-unit-size{syntax: \"*\"; inherits: true; initial-value: .875rem;}@property --cngx-metric-unit-weight{syntax: \"<number>\"; inherits: true; initial-value: 400;}@property --cngx-metric-unit-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.36 .02 290);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-metric-value-color: oklch(.95 .01 290);--cngx-metric-unit-color: oklch(.7 .01 290)}}[data-color-scheme=dark],.dark{--cngx-metric-value-color: oklch(.95 .01 290);--cngx-metric-unit-color: oklch(.7 .01 290)}[data-color-scheme=light],.light{--cngx-metric-value-color: oklch(.2 .01 290);--cngx-metric-unit-color: oklch(.36 .02 290)}}@layer cngx.components{@scope(.cngx-metric){:scope{--cngx-metric-gap: var(--cngx-space-xs);display:inline-flex;align-items:baseline;gap:var(--cngx-metric-gap, 2px)}.cngx-metric__value{font-size:var(--cngx-metric-value-size, 1.75rem);font-weight:var(--cngx-metric-value-weight, 600);color:var(--cngx-metric-value-color, var(--cngx-color-text, oklch(.2 .01 290)));line-height:1.2}.cngx-metric__unit{font-size:var(--cngx-metric-unit-size, .875rem);font-weight:var(--cngx-metric-unit-weight, 400);color:var(--cngx-metric-unit-color, oklch(.36 .02 290))}}}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
2955
|
+
`, isInline: true, styles: ["@layer cngx.tokens{@property --cngx-metric-gap{syntax: \"<length>\"; inherits: false; initial-value: 2px;}@property --cngx-metric-value-size{syntax: \"*\"; inherits: true; initial-value: 1.75rem;}@property --cngx-metric-value-weight{syntax: \"<number>\"; inherits: true; initial-value: 600;}@property --cngx-metric-value-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.2 .01 290);}@property --cngx-metric-unit-size{syntax: \"*\"; inherits: true; initial-value: .875rem;}@property --cngx-metric-unit-weight{syntax: \"<number>\"; inherits: true; initial-value: 400;}@property --cngx-metric-unit-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.36 .02 290);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-metric-value-color: oklch(.95 .01 290);--cngx-metric-unit-color: oklch(.7 .01 290)}}[data-color-scheme=dark],.dark{--cngx-metric-value-color: oklch(.95 .01 290);--cngx-metric-unit-color: oklch(.7 .01 290)}[data-color-scheme=light],.light{--cngx-metric-value-color: oklch(.2 .01 290);--cngx-metric-unit-color: oklch(.36 .02 290)}}@layer cngx.components{@scope(.cngx-metric){:scope{--cngx-metric-gap: var(--cngx-space-xs);display:inline-flex;align-items:baseline;gap:var(--cngx-metric-gap, 2px)}.cngx-metric__value{font-size:var(--cngx-metric-value-size, 1.75rem);font-weight:var(--cngx-metric-value-weight, 600);color:var(--cngx-metric-value-color, var(--cngx-color-text, oklch(.2 .01 290)));line-height:1.2;unicode-bidi:var(--cngx-metric-bidi, isolate)}.cngx-metric__unit{font-size:var(--cngx-metric-unit-size, .875rem);font-weight:var(--cngx-metric-unit-weight, 400);color:var(--cngx-metric-unit-color, oklch(.36 .02 290))}}}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
2469
2956
|
}
|
|
2470
2957
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxMetric, decorators: [{
|
|
2471
2958
|
type: Component,
|
|
@@ -2478,11 +2965,14 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
2478
2965
|
role: 'img',
|
|
2479
2966
|
'[attr.aria-label]': 'accessibleValue()',
|
|
2480
2967
|
}, template: `
|
|
2968
|
+
@if (shownUnit() && unitFirst()) {
|
|
2969
|
+
<span class="cngx-metric__unit">{{ shownUnit() }}</span>
|
|
2970
|
+
}
|
|
2481
2971
|
<span class="cngx-metric__value">{{ formattedValue() }}</span>
|
|
2482
|
-
@if (
|
|
2483
|
-
<span class="cngx-metric__unit">{{
|
|
2972
|
+
@if (shownUnit() && !unitFirst()) {
|
|
2973
|
+
<span class="cngx-metric__unit">{{ shownUnit() }}</span>
|
|
2484
2974
|
}
|
|
2485
|
-
`, styles: ["@layer cngx.tokens{@property --cngx-metric-gap{syntax: \"<length>\"; inherits: false; initial-value: 2px;}@property --cngx-metric-value-size{syntax: \"*\"; inherits: true; initial-value: 1.75rem;}@property --cngx-metric-value-weight{syntax: \"<number>\"; inherits: true; initial-value: 600;}@property --cngx-metric-value-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.2 .01 290);}@property --cngx-metric-unit-size{syntax: \"*\"; inherits: true; initial-value: .875rem;}@property --cngx-metric-unit-weight{syntax: \"<number>\"; inherits: true; initial-value: 400;}@property --cngx-metric-unit-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.36 .02 290);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-metric-value-color: oklch(.95 .01 290);--cngx-metric-unit-color: oklch(.7 .01 290)}}[data-color-scheme=dark],.dark{--cngx-metric-value-color: oklch(.95 .01 290);--cngx-metric-unit-color: oklch(.7 .01 290)}[data-color-scheme=light],.light{--cngx-metric-value-color: oklch(.2 .01 290);--cngx-metric-unit-color: oklch(.36 .02 290)}}@layer cngx.components{@scope(.cngx-metric){:scope{--cngx-metric-gap: var(--cngx-space-xs);display:inline-flex;align-items:baseline;gap:var(--cngx-metric-gap, 2px)}.cngx-metric__value{font-size:var(--cngx-metric-value-size, 1.75rem);font-weight:var(--cngx-metric-value-weight, 600);color:var(--cngx-metric-value-color, var(--cngx-color-text, oklch(.2 .01 290)));line-height:1.2}.cngx-metric__unit{font-size:var(--cngx-metric-unit-size, .875rem);font-weight:var(--cngx-metric-unit-weight, 400);color:var(--cngx-metric-unit-color, oklch(.36 .02 290))}}}\n"] }]
|
|
2975
|
+
`, styles: ["@layer cngx.tokens{@property --cngx-metric-gap{syntax: \"<length>\"; inherits: false; initial-value: 2px;}@property --cngx-metric-value-size{syntax: \"*\"; inherits: true; initial-value: 1.75rem;}@property --cngx-metric-value-weight{syntax: \"<number>\"; inherits: true; initial-value: 600;}@property --cngx-metric-value-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.2 .01 290);}@property --cngx-metric-unit-size{syntax: \"*\"; inherits: true; initial-value: .875rem;}@property --cngx-metric-unit-weight{syntax: \"<number>\"; inherits: true; initial-value: 400;}@property --cngx-metric-unit-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.36 .02 290);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-metric-value-color: oklch(.95 .01 290);--cngx-metric-unit-color: oklch(.7 .01 290)}}[data-color-scheme=dark],.dark{--cngx-metric-value-color: oklch(.95 .01 290);--cngx-metric-unit-color: oklch(.7 .01 290)}[data-color-scheme=light],.light{--cngx-metric-value-color: oklch(.2 .01 290);--cngx-metric-unit-color: oklch(.36 .02 290)}}@layer cngx.components{@scope(.cngx-metric){:scope{--cngx-metric-gap: var(--cngx-space-xs);display:inline-flex;align-items:baseline;gap:var(--cngx-metric-gap, 2px)}.cngx-metric__value{font-size:var(--cngx-metric-value-size, 1.75rem);font-weight:var(--cngx-metric-value-weight, 600);color:var(--cngx-metric-value-color, var(--cngx-color-text, oklch(.2 .01 290)));line-height:1.2;unicode-bidi:var(--cngx-metric-bidi, isolate)}.cngx-metric__unit{font-size:var(--cngx-metric-unit-size, .875rem);font-weight:var(--cngx-metric-unit-weight, 400);color:var(--cngx-metric-unit-color, oklch(.36 .02 290))}}}\n"] }]
|
|
2486
2976
|
}], propDecorators: { value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: true }] }], unit: [{ type: i0.Input, args: [{ isSignal: true, alias: "unit", required: false }] }], format: [{ type: i0.Input, args: [{ isSignal: true, alias: "format", required: false }] }] } });
|
|
2487
2977
|
|
|
2488
2978
|
/**
|
|
@@ -2521,20 +3011,26 @@ function directionGlyph(direction) {
|
|
|
2521
3011
|
/**
|
|
2522
3012
|
* Format the magnitude. The sign is carried by the arrow and colour, not the
|
|
2523
3013
|
* digits: a positive value gains a leading `+`, everything else prints its
|
|
2524
|
-
* absolute value unsigned. Percent mode
|
|
2525
|
-
* and defaults to one fraction digit;
|
|
3014
|
+
* absolute value unsigned. Percent mode formats with `Intl` `style: 'percent'`
|
|
3015
|
+
* (so the locale places the `%` sign) and defaults to one fraction digit;
|
|
3016
|
+
* absolute mode uses the locale grouping.
|
|
2526
3017
|
* A supplied `Intl.NumberFormatOptions` overrides the default digit handling
|
|
2527
3018
|
* in both modes.
|
|
2528
3019
|
*/
|
|
2529
3020
|
function formatDelta(value, mode, locale, format) {
|
|
2530
3021
|
const abs = Math.abs(value);
|
|
2531
|
-
|
|
3022
|
+
// The locale places and draws the plus sign; a negative prints unsigned.
|
|
3023
|
+
const signDisplay = value > 0 ? 'exceptZero' : 'never';
|
|
2532
3024
|
if (mode === 'percent') {
|
|
2533
|
-
|
|
2534
|
-
|
|
3025
|
+
// The input is already in percent units; Intl's percent style multiplies
|
|
3026
|
+
// by 100, so scale down first.
|
|
3027
|
+
return numberFormatterFor(locale, {
|
|
3028
|
+
...(format ?? { minimumFractionDigits: 1, maximumFractionDigits: 1 }),
|
|
3029
|
+
style: 'percent',
|
|
3030
|
+
signDisplay,
|
|
3031
|
+
}).format(abs / 100);
|
|
2535
3032
|
}
|
|
2536
|
-
|
|
2537
|
-
return `${prefix}${num}`;
|
|
3033
|
+
return numberFormatterFor(locale, { ...format, signDisplay }).format(abs);
|
|
2538
3034
|
}
|
|
2539
3035
|
|
|
2540
3036
|
/**
|
|
@@ -2575,7 +3071,8 @@ function formatDelta(value, mode, locale, format) {
|
|
|
2575
3071
|
* <example-url>http://localhost:4200/#/common/data/trend/trend-directions</example-url>
|
|
2576
3072
|
*/
|
|
2577
3073
|
class CngxTrend {
|
|
2578
|
-
locale =
|
|
3074
|
+
locale = injectLocale();
|
|
3075
|
+
i18n = injectKpiI18n();
|
|
2579
3076
|
/** Trend percentage. Positive = up, negative = down, zero = flat. */
|
|
2580
3077
|
value = input.required(...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
|
|
2581
3078
|
/** Consumer-provided SR label override. When set, replaces the generated default. */
|
|
@@ -2583,21 +3080,15 @@ class CngxTrend {
|
|
|
2583
3080
|
/** @internal */
|
|
2584
3081
|
icon = computed(() => directionGlyph(deltaDirection(this.value())), ...(ngDevMode ? [{ debugName: "icon" }] : /* istanbul ignore next */ []));
|
|
2585
3082
|
/** @internal */
|
|
2586
|
-
formattedValue = computed(() => formatDelta(this.value(), 'percent', this.locale), ...(ngDevMode ? [{ debugName: "formattedValue" }] : /* istanbul ignore next */ []));
|
|
3083
|
+
formattedValue = computed(() => formatDelta(this.value(), 'percent', this.locale()), ...(ngDevMode ? [{ debugName: "formattedValue" }] : /* istanbul ignore next */ []));
|
|
2587
3084
|
/** @internal */
|
|
2588
|
-
resolvedLabel = computed(() =>
|
|
2589
|
-
|
|
2590
|
-
return this.label();
|
|
2591
|
-
}
|
|
2592
|
-
const direction = deltaDirection(this.value());
|
|
2593
|
-
const dir = direction === 'up' ? 'up' : direction === 'down' ? 'down' : 'unchanged';
|
|
2594
|
-
return `${this.formattedValue()} ${dir}`;
|
|
2595
|
-
}, ...(ngDevMode ? [{ debugName: "resolvedLabel" }] : /* istanbul ignore next */ []));
|
|
3085
|
+
resolvedLabel = computed(() => this.label() ??
|
|
3086
|
+
this.i18n().trendLabel(this.formattedValue(), deltaDirection(this.value())), ...(ngDevMode ? [{ debugName: "resolvedLabel" }] : /* istanbul ignore next */ []));
|
|
2596
3087
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTrend, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
2597
3088
|
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "21.2.4", type: CngxTrend, isStandalone: true, selector: "cngx-trend", inputs: { value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: true, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "role": "img" }, properties: { "class.cngx-trend--up": "value() > 0", "class.cngx-trend--down": "value() < 0", "attr.aria-label": "resolvedLabel()" }, classAttribute: "cngx-trend" }, ngImport: i0, template: `
|
|
2598
3089
|
<span aria-hidden="true">{{ icon() }}</span>
|
|
2599
3090
|
{{ formattedValue() }}
|
|
2600
|
-
`, isInline: true, styles: ["@layer cngx.tokens{@property --cngx-trend-gap{syntax: \"<length>\"; inherits: false; initial-value: 2px;}@property --cngx-trend-size{syntax: \"*\"; inherits: true; initial-value: .8125rem;}@property --cngx-trend-weight{syntax: \"<number>\"; inherits: true; initial-value: 500;}@property --cngx-trend-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.36 .02 290);}@property --cngx-trend-up-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .18 145);}@property --cngx-trend-down-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .22 25);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-trend-color: oklch(.7 .01 290);--cngx-trend-up-color: oklch(.78 .16 145);--cngx-trend-down-color: oklch(.75 .18 25)}}[data-color-scheme=dark],.dark{--cngx-trend-color: oklch(.7 .01 290);--cngx-trend-up-color: oklch(.78 .16 145);--cngx-trend-down-color: oklch(.75 .18 25)}[data-color-scheme=light],.light{--cngx-trend-color: oklch(.36 .02 290);--cngx-trend-up-color: oklch(.65 .18 145);--cngx-trend-down-color: oklch(.65 .22 25)}}@layer cngx.components{@scope(.cngx-trend){:scope{--cngx-trend-gap: var(--cngx-space-xs);display:inline-flex;align-items:center;gap:var(--cngx-trend-gap, 2px);font-size:var(--cngx-trend-size, .8125rem);font-weight:var(--cngx-trend-weight, 500);color:var(--cngx-trend-color, oklch(.36 .02 290))}:scope.cngx-trend--up{color:var(--cngx-trend-up-color, var(--cngx-color-success, oklch(.65 .18 145)))}:scope.cngx-trend--down{color:var(--cngx-trend-down-color, var(--cngx-color-danger, oklch(.65 .22 25)))}}}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
3091
|
+
`, isInline: true, styles: ["@layer cngx.tokens{@property --cngx-trend-gap{syntax: \"<length>\"; inherits: false; initial-value: 2px;}@property --cngx-trend-size{syntax: \"*\"; inherits: true; initial-value: .8125rem;}@property --cngx-trend-weight{syntax: \"<number>\"; inherits: true; initial-value: 500;}@property --cngx-trend-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.36 .02 290);}@property --cngx-trend-up-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .18 145);}@property --cngx-trend-down-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .22 25);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-trend-color: oklch(.7 .01 290);--cngx-trend-up-color: oklch(.78 .16 145);--cngx-trend-down-color: oklch(.75 .18 25)}}[data-color-scheme=dark],.dark{--cngx-trend-color: oklch(.7 .01 290);--cngx-trend-up-color: oklch(.78 .16 145);--cngx-trend-down-color: oklch(.75 .18 25)}[data-color-scheme=light],.light{--cngx-trend-color: oklch(.36 .02 290);--cngx-trend-up-color: oklch(.65 .18 145);--cngx-trend-down-color: oklch(.65 .22 25)}}@layer cngx.components{@scope(.cngx-trend){:scope{--cngx-trend-gap: var(--cngx-space-xs);display:inline-flex;align-items:center;gap:var(--cngx-trend-gap, 2px);font-size:var(--cngx-trend-size, .8125rem);font-weight:var(--cngx-trend-weight, 500);color:var(--cngx-trend-color, oklch(.36 .02 290));unicode-bidi:var(--cngx-trend-bidi, isolate);direction:var(--cngx-trend-direction, ltr)}:scope.cngx-trend--up{color:var(--cngx-trend-up-color, var(--cngx-color-success, oklch(.65 .18 145)))}:scope.cngx-trend--down{color:var(--cngx-trend-down-color, var(--cngx-color-danger, oklch(.65 .22 25)))}}}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
2601
3092
|
}
|
|
2602
3093
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxTrend, decorators: [{
|
|
2603
3094
|
type: Component,
|
|
@@ -2613,14 +3104,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
2613
3104
|
}, template: `
|
|
2614
3105
|
<span aria-hidden="true">{{ icon() }}</span>
|
|
2615
3106
|
{{ formattedValue() }}
|
|
2616
|
-
`, styles: ["@layer cngx.tokens{@property --cngx-trend-gap{syntax: \"<length>\"; inherits: false; initial-value: 2px;}@property --cngx-trend-size{syntax: \"*\"; inherits: true; initial-value: .8125rem;}@property --cngx-trend-weight{syntax: \"<number>\"; inherits: true; initial-value: 500;}@property --cngx-trend-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.36 .02 290);}@property --cngx-trend-up-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .18 145);}@property --cngx-trend-down-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .22 25);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-trend-color: oklch(.7 .01 290);--cngx-trend-up-color: oklch(.78 .16 145);--cngx-trend-down-color: oklch(.75 .18 25)}}[data-color-scheme=dark],.dark{--cngx-trend-color: oklch(.7 .01 290);--cngx-trend-up-color: oklch(.78 .16 145);--cngx-trend-down-color: oklch(.75 .18 25)}[data-color-scheme=light],.light{--cngx-trend-color: oklch(.36 .02 290);--cngx-trend-up-color: oklch(.65 .18 145);--cngx-trend-down-color: oklch(.65 .22 25)}}@layer cngx.components{@scope(.cngx-trend){:scope{--cngx-trend-gap: var(--cngx-space-xs);display:inline-flex;align-items:center;gap:var(--cngx-trend-gap, 2px);font-size:var(--cngx-trend-size, .8125rem);font-weight:var(--cngx-trend-weight, 500);color:var(--cngx-trend-color, oklch(.36 .02 290))}:scope.cngx-trend--up{color:var(--cngx-trend-up-color, var(--cngx-color-success, oklch(.65 .18 145)))}:scope.cngx-trend--down{color:var(--cngx-trend-down-color, var(--cngx-color-danger, oklch(.65 .22 25)))}}}\n"] }]
|
|
3107
|
+
`, styles: ["@layer cngx.tokens{@property --cngx-trend-gap{syntax: \"<length>\"; inherits: false; initial-value: 2px;}@property --cngx-trend-size{syntax: \"*\"; inherits: true; initial-value: .8125rem;}@property --cngx-trend-weight{syntax: \"<number>\"; inherits: true; initial-value: 500;}@property --cngx-trend-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.36 .02 290);}@property --cngx-trend-up-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .18 145);}@property --cngx-trend-down-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .22 25);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-trend-color: oklch(.7 .01 290);--cngx-trend-up-color: oklch(.78 .16 145);--cngx-trend-down-color: oklch(.75 .18 25)}}[data-color-scheme=dark],.dark{--cngx-trend-color: oklch(.7 .01 290);--cngx-trend-up-color: oklch(.78 .16 145);--cngx-trend-down-color: oklch(.75 .18 25)}[data-color-scheme=light],.light{--cngx-trend-color: oklch(.36 .02 290);--cngx-trend-up-color: oklch(.65 .18 145);--cngx-trend-down-color: oklch(.65 .22 25)}}@layer cngx.components{@scope(.cngx-trend){:scope{--cngx-trend-gap: var(--cngx-space-xs);display:inline-flex;align-items:center;gap:var(--cngx-trend-gap, 2px);font-size:var(--cngx-trend-size, .8125rem);font-weight:var(--cngx-trend-weight, 500);color:var(--cngx-trend-color, oklch(.36 .02 290));unicode-bidi:var(--cngx-trend-bidi, isolate);direction:var(--cngx-trend-direction, ltr)}:scope.cngx-trend--up{color:var(--cngx-trend-up-color, var(--cngx-color-success, oklch(.65 .18 145)))}:scope.cngx-trend--down{color:var(--cngx-trend-down-color, var(--cngx-color-danger, oklch(.65 .22 25)))}}}\n"] }]
|
|
2617
3108
|
}], propDecorators: { value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: true }] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }] } });
|
|
2618
3109
|
|
|
2619
|
-
const SENTIMENT_WORD = {
|
|
2620
|
-
positive: 'improved',
|
|
2621
|
-
negative: 'declined',
|
|
2622
|
-
neutral: 'unchanged',
|
|
2623
|
-
};
|
|
2624
3110
|
/**
|
|
2625
3111
|
* Sentiment-aware delta indicator. Where `CngxTrend` colours strictly by
|
|
2626
3112
|
* direction (up = green), `CngxDelta` colours by **sentiment**: a `polarity`
|
|
@@ -2659,7 +3145,8 @@ const SENTIMENT_WORD = {
|
|
|
2659
3145
|
* <example-url>http://localhost:4200/#/common/data/delta/sentiment-polarity</example-url>
|
|
2660
3146
|
*/
|
|
2661
3147
|
class CngxDelta {
|
|
2662
|
-
locale =
|
|
3148
|
+
locale = injectLocale();
|
|
3149
|
+
i18n = injectKpiI18n();
|
|
2663
3150
|
/** Signed delta. Positive = up, negative = down, zero = flat. */
|
|
2664
3151
|
value = input.required(...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
|
|
2665
3152
|
/**
|
|
@@ -2681,20 +3168,17 @@ class CngxDelta {
|
|
|
2681
3168
|
/** @internal Arrow glyph bound from direction only. */
|
|
2682
3169
|
glyph = computed(() => directionGlyph(this.direction()), ...(ngDevMode ? [{ debugName: "glyph" }] : /* istanbul ignore next */ []));
|
|
2683
3170
|
/** @internal Formatted magnitude. */
|
|
2684
|
-
formattedValue = computed(() => formatDelta(this.value(), this.mode(), this.locale, this.format()), ...(ngDevMode ? [{ debugName: "formattedValue" }] : /* istanbul ignore next */ []));
|
|
2685
|
-
/**
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
}
|
|
2691
|
-
return `${this.formattedValue()} ${SENTIMENT_WORD[this.sentiment()]}`;
|
|
2692
|
-
}, ...(ngDevMode ? [{ debugName: "resolvedLabel" }] : /* istanbul ignore next */ []));
|
|
3171
|
+
formattedValue = computed(() => formatDelta(this.value(), this.mode(), this.locale(), this.format()), ...(ngDevMode ? [{ debugName: "formattedValue" }] : /* istanbul ignore next */ []));
|
|
3172
|
+
/**
|
|
3173
|
+
* @internal Full SR label: magnitude plus the sentiment word, composed by
|
|
3174
|
+
* `CNGX_KPI_I18N.deltaLabel` unless `[label]` is bound.
|
|
3175
|
+
*/
|
|
3176
|
+
resolvedLabel = computed(() => this.label() ?? this.i18n().deltaLabel(this.formattedValue(), this.sentiment()), ...(ngDevMode ? [{ debugName: "resolvedLabel" }] : /* istanbul ignore next */ []));
|
|
2693
3177
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDelta, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
2694
3178
|
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "21.2.4", type: CngxDelta, isStandalone: true, selector: "cngx-delta", inputs: { value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: true, transformFunction: null }, polarity: { classPropertyName: "polarity", publicName: "polarity", isSignal: true, isRequired: false, transformFunction: null }, mode: { classPropertyName: "mode", publicName: "mode", isSignal: true, isRequired: false, transformFunction: null }, format: { classPropertyName: "format", publicName: "format", isSignal: true, isRequired: false, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "role": "img" }, properties: { "class.cngx-delta--positive": "sentiment() === 'positive'", "class.cngx-delta--negative": "sentiment() === 'negative'", "class.cngx-delta--neutral": "sentiment() === 'neutral'", "attr.aria-label": "resolvedLabel()" }, classAttribute: "cngx-delta" }, ngImport: i0, template: `
|
|
2695
3179
|
<span aria-hidden="true">{{ glyph() }}</span>
|
|
2696
3180
|
{{ formattedValue() }}
|
|
2697
|
-
`, isInline: true, styles: ["@layer cngx.tokens{@property --cngx-delta-gap{syntax: \"<length>\"; inherits: false; initial-value: 2px;}@property --cngx-delta-size{syntax: \"*\"; inherits: true; initial-value: .8125rem;}@property --cngx-delta-weight{syntax: \"<number>\"; inherits: true; initial-value: 500;}@property --cngx-delta-neutral-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.36 .02 290);}@property --cngx-delta-positive-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .18 145);}@property --cngx-delta-negative-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .22 25);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-delta-neutral-color: oklch(.7 .01 290);--cngx-delta-positive-color: oklch(.78 .16 145);--cngx-delta-negative-color: oklch(.75 .18 25)}}[data-color-scheme=dark],.dark{--cngx-delta-neutral-color: oklch(.7 .01 290);--cngx-delta-positive-color: oklch(.78 .16 145);--cngx-delta-negative-color: oklch(.75 .18 25)}[data-color-scheme=light],.light{--cngx-delta-neutral-color: oklch(.36 .02 290);--cngx-delta-positive-color: oklch(.65 .18 145);--cngx-delta-negative-color: oklch(.65 .22 25)}}@layer cngx.components{@scope(.cngx-delta){:scope{--cngx-delta-gap: var(--cngx-space-xs);display:inline-flex;align-items:center;gap:var(--cngx-delta-gap, 2px);font-size:var(--cngx-delta-size, .8125rem);font-weight:var(--cngx-delta-weight, 500);color:var(--cngx-delta-neutral-color, oklch(.36 .02 290))}:scope.cngx-delta--positive{color:var(--cngx-delta-positive-color, var(--cngx-color-success, oklch(.65 .18 145)))}:scope.cngx-delta--negative{color:var(--cngx-delta-negative-color, var(--cngx-color-danger, oklch(.65 .22 25)))}:scope.cngx-delta--neutral{color:var(--cngx-delta-neutral-color, oklch(.36 .02 290))}}}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
3181
|
+
`, isInline: true, styles: ["@layer cngx.tokens{@property --cngx-delta-gap{syntax: \"<length>\"; inherits: false; initial-value: 2px;}@property --cngx-delta-size{syntax: \"*\"; inherits: true; initial-value: .8125rem;}@property --cngx-delta-weight{syntax: \"<number>\"; inherits: true; initial-value: 500;}@property --cngx-delta-neutral-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.36 .02 290);}@property --cngx-delta-positive-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .18 145);}@property --cngx-delta-negative-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .22 25);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-delta-neutral-color: oklch(.7 .01 290);--cngx-delta-positive-color: oklch(.78 .16 145);--cngx-delta-negative-color: oklch(.75 .18 25)}}[data-color-scheme=dark],.dark{--cngx-delta-neutral-color: oklch(.7 .01 290);--cngx-delta-positive-color: oklch(.78 .16 145);--cngx-delta-negative-color: oklch(.75 .18 25)}[data-color-scheme=light],.light{--cngx-delta-neutral-color: oklch(.36 .02 290);--cngx-delta-positive-color: oklch(.65 .18 145);--cngx-delta-negative-color: oklch(.65 .22 25)}}@layer cngx.components{@scope(.cngx-delta){:scope{--cngx-delta-gap: var(--cngx-space-xs);display:inline-flex;align-items:center;gap:var(--cngx-delta-gap, 2px);font-size:var(--cngx-delta-size, .8125rem);font-weight:var(--cngx-delta-weight, 500);color:var(--cngx-delta-neutral-color, oklch(.36 .02 290));unicode-bidi:var(--cngx-delta-bidi, isolate);direction:var(--cngx-delta-direction, ltr)}:scope.cngx-delta--positive{color:var(--cngx-delta-positive-color, var(--cngx-color-success, oklch(.65 .18 145)))}:scope.cngx-delta--negative{color:var(--cngx-delta-negative-color, var(--cngx-color-danger, oklch(.65 .22 25)))}:scope.cngx-delta--neutral{color:var(--cngx-delta-neutral-color, oklch(.36 .02 290))}}}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
2698
3182
|
}
|
|
2699
3183
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDelta, decorators: [{
|
|
2700
3184
|
type: Component,
|
|
@@ -2712,16 +3196,89 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
2712
3196
|
}, template: `
|
|
2713
3197
|
<span aria-hidden="true">{{ glyph() }}</span>
|
|
2714
3198
|
{{ formattedValue() }}
|
|
2715
|
-
`, styles: ["@layer cngx.tokens{@property --cngx-delta-gap{syntax: \"<length>\"; inherits: false; initial-value: 2px;}@property --cngx-delta-size{syntax: \"*\"; inherits: true; initial-value: .8125rem;}@property --cngx-delta-weight{syntax: \"<number>\"; inherits: true; initial-value: 500;}@property --cngx-delta-neutral-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.36 .02 290);}@property --cngx-delta-positive-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .18 145);}@property --cngx-delta-negative-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .22 25);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-delta-neutral-color: oklch(.7 .01 290);--cngx-delta-positive-color: oklch(.78 .16 145);--cngx-delta-negative-color: oklch(.75 .18 25)}}[data-color-scheme=dark],.dark{--cngx-delta-neutral-color: oklch(.7 .01 290);--cngx-delta-positive-color: oklch(.78 .16 145);--cngx-delta-negative-color: oklch(.75 .18 25)}[data-color-scheme=light],.light{--cngx-delta-neutral-color: oklch(.36 .02 290);--cngx-delta-positive-color: oklch(.65 .18 145);--cngx-delta-negative-color: oklch(.65 .22 25)}}@layer cngx.components{@scope(.cngx-delta){:scope{--cngx-delta-gap: var(--cngx-space-xs);display:inline-flex;align-items:center;gap:var(--cngx-delta-gap, 2px);font-size:var(--cngx-delta-size, .8125rem);font-weight:var(--cngx-delta-weight, 500);color:var(--cngx-delta-neutral-color, oklch(.36 .02 290))}:scope.cngx-delta--positive{color:var(--cngx-delta-positive-color, var(--cngx-color-success, oklch(.65 .18 145)))}:scope.cngx-delta--negative{color:var(--cngx-delta-negative-color, var(--cngx-color-danger, oklch(.65 .22 25)))}:scope.cngx-delta--neutral{color:var(--cngx-delta-neutral-color, oklch(.36 .02 290))}}}\n"] }]
|
|
3199
|
+
`, styles: ["@layer cngx.tokens{@property --cngx-delta-gap{syntax: \"<length>\"; inherits: false; initial-value: 2px;}@property --cngx-delta-size{syntax: \"*\"; inherits: true; initial-value: .8125rem;}@property --cngx-delta-weight{syntax: \"<number>\"; inherits: true; initial-value: 500;}@property --cngx-delta-neutral-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.36 .02 290);}@property --cngx-delta-positive-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .18 145);}@property --cngx-delta-negative-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .22 25);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-delta-neutral-color: oklch(.7 .01 290);--cngx-delta-positive-color: oklch(.78 .16 145);--cngx-delta-negative-color: oklch(.75 .18 25)}}[data-color-scheme=dark],.dark{--cngx-delta-neutral-color: oklch(.7 .01 290);--cngx-delta-positive-color: oklch(.78 .16 145);--cngx-delta-negative-color: oklch(.75 .18 25)}[data-color-scheme=light],.light{--cngx-delta-neutral-color: oklch(.36 .02 290);--cngx-delta-positive-color: oklch(.65 .18 145);--cngx-delta-negative-color: oklch(.65 .22 25)}}@layer cngx.components{@scope(.cngx-delta){:scope{--cngx-delta-gap: var(--cngx-space-xs);display:inline-flex;align-items:center;gap:var(--cngx-delta-gap, 2px);font-size:var(--cngx-delta-size, .8125rem);font-weight:var(--cngx-delta-weight, 500);color:var(--cngx-delta-neutral-color, oklch(.36 .02 290));unicode-bidi:var(--cngx-delta-bidi, isolate);direction:var(--cngx-delta-direction, ltr)}:scope.cngx-delta--positive{color:var(--cngx-delta-positive-color, var(--cngx-color-success, oklch(.65 .18 145)))}:scope.cngx-delta--negative{color:var(--cngx-delta-negative-color, var(--cngx-color-danger, oklch(.65 .22 25)))}:scope.cngx-delta--neutral{color:var(--cngx-delta-neutral-color, oklch(.36 .02 290))}}}\n"] }]
|
|
2716
3200
|
}], propDecorators: { value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: true }] }], polarity: [{ type: i0.Input, args: [{ isSignal: true, alias: "polarity", required: false }] }], mode: [{ type: i0.Input, args: [{ isSignal: true, alias: "mode", required: false }] }], format: [{ type: i0.Input, args: [{ isSignal: true, alias: "format", required: false }] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }] } });
|
|
2717
3201
|
|
|
2718
|
-
/** DI token carrying the {@link CngxStatRegistry} a `CngxStat` provides. */
|
|
2719
|
-
const CNGX_STAT = new InjectionToken('CNGX_STAT');
|
|
2720
|
-
|
|
2721
3202
|
/** Fixed reading order for the coordinated slots. */
|
|
2722
3203
|
const SLOT_ORDER = ['label', 'value', 'delta', 'caption'];
|
|
2723
3204
|
/** Structural equality so an unchanged id set never cascades `labelledBy`. */
|
|
2724
3205
|
const idsEqual = (a, b) => a.length === b.length && a.every((id, i) => id === b[i]);
|
|
3206
|
+
/** Structural equality so an unchanged slot set never cascades to a placeholder. */
|
|
3207
|
+
const kindsEqual = (a, b) => a.length === b.length && a.every((kind, i) => kind === b[i]);
|
|
3208
|
+
/**
|
|
3209
|
+
* The slot-id coordination brain behind {@link CNGX_STAT}. Collects the id each
|
|
3210
|
+
* `cngxStat*` slot registers and derives one `aria-labelledby` that reads the
|
|
3211
|
+
* whole stat as a single accessible name in reading order.
|
|
3212
|
+
*
|
|
3213
|
+
* Lives as a host directive rather than inside `CngxStat` because the slot
|
|
3214
|
+
* directives resolve `CNGX_STAT` against their **declaration** site: content
|
|
3215
|
+
* written inside an organism never reaches a `<cngx-stat>` that sits in that
|
|
3216
|
+
* organism's own template. Any component that wants to host the four slots
|
|
3217
|
+
* therefore applies this brain and re-points the token at it:
|
|
3218
|
+
*
|
|
3219
|
+
* ```ts
|
|
3220
|
+
* hostDirectives: [CngxStatCoordinator],
|
|
3221
|
+
* providers: [{ provide: CNGX_STAT, useExisting: CngxStatCoordinator }],
|
|
3222
|
+
* ```
|
|
3223
|
+
*
|
|
3224
|
+
* Same shape as `CngxPaginate` behind `CNGX_PAGINATOR_HOST`, which
|
|
3225
|
+
* `CngxPaginator` and `CngxIncrementalList` share the same way.
|
|
3226
|
+
*
|
|
3227
|
+
* @category common/data/metric
|
|
3228
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/data/display/stat/stat-coordinator.directive.ts
|
|
3229
|
+
* @since 0.1.0
|
|
3230
|
+
* @relatedTo CngxStat, CNGX_STAT
|
|
3231
|
+
*/
|
|
3232
|
+
class CngxStatCoordinator {
|
|
3233
|
+
slots = signal(new Map(), ...(ngDevMode ? [{ debugName: "slots" }] : /* istanbul ignore next */ []));
|
|
3234
|
+
/** {@inheritDoc CngxStatRegistry.register} */
|
|
3235
|
+
register(kind, id) {
|
|
3236
|
+
this.slots.update((prev) => new Map(prev).set(kind, id));
|
|
3237
|
+
}
|
|
3238
|
+
/** {@inheritDoc CngxStatRegistry.unregister} */
|
|
3239
|
+
unregister(kind, id) {
|
|
3240
|
+
this.slots.update((prev) => {
|
|
3241
|
+
if (id !== undefined && prev.get(kind) !== id) {
|
|
3242
|
+
// Register-before-destroy replacement: the outgoing slot must not
|
|
3243
|
+
// evict the live slot's id from aria-labelledby.
|
|
3244
|
+
return prev;
|
|
3245
|
+
}
|
|
3246
|
+
const next = new Map(prev);
|
|
3247
|
+
next.delete(kind);
|
|
3248
|
+
return next;
|
|
3249
|
+
});
|
|
3250
|
+
}
|
|
3251
|
+
/** Present slot ids in reading order; structurally stable. */
|
|
3252
|
+
orderedIds = computed(() => {
|
|
3253
|
+
const map = this.slots();
|
|
3254
|
+
return SLOT_ORDER.map((kind) => map.get(kind)).filter((id) => id !== undefined);
|
|
3255
|
+
}, { ...(ngDevMode ? { debugName: "orderedIds" } : /* istanbul ignore next */ {}), equal: idsEqual });
|
|
3256
|
+
/** Combined accessible name for the host; `null` when no slot is present. */
|
|
3257
|
+
labelledBy = computed(() => this.orderedIds().join(' ') || null, ...(ngDevMode ? [{ debugName: "labelledBy" }] : /* istanbul ignore next */ []));
|
|
3258
|
+
/**
|
|
3259
|
+
* Which slots a consumer actually projected, in reading order. Registration
|
|
3260
|
+
* happens when the slot directive is constructed in the consumer's template,
|
|
3261
|
+
* so this stays accurate even while the host renders a branch that does not
|
|
3262
|
+
* include the `<ng-content>` outlets - which is what lets a placeholder mirror
|
|
3263
|
+
* the real tile instead of guessing at it.
|
|
3264
|
+
*/
|
|
3265
|
+
presentKinds = computed(() => {
|
|
3266
|
+
const map = this.slots();
|
|
3267
|
+
return SLOT_ORDER.filter((kind) => map.has(kind));
|
|
3268
|
+
}, { ...(ngDevMode ? { debugName: "presentKinds" } : /* istanbul ignore next */ {}), equal: kindsEqual });
|
|
3269
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStatCoordinator, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
3270
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxStatCoordinator, isStandalone: true, ngImport: i0 });
|
|
3271
|
+
}
|
|
3272
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStatCoordinator, decorators: [{
|
|
3273
|
+
type: Directive,
|
|
3274
|
+
args: [{
|
|
3275
|
+
standalone: true,
|
|
3276
|
+
}]
|
|
3277
|
+
}] });
|
|
3278
|
+
|
|
3279
|
+
/** DI token carrying the {@link CngxStatRegistry} a `CngxStat` provides. */
|
|
3280
|
+
const CNGX_STAT = new InjectionToken('CNGX_STAT');
|
|
3281
|
+
|
|
2725
3282
|
/**
|
|
2726
3283
|
* Coordination molecule for a KPI stat. Its sole reason to exist is the
|
|
2727
3284
|
* screen-reader layer (Pillar 2): hand-assembling a heading, a `<cngx-metric>`
|
|
@@ -2730,9 +3287,10 @@ const idsEqual = (a, b) => a.length === b.length && a.every((id, i) => id === b[
|
|
|
2730
3287
|
* collects the id each slot registers, and derives one `aria-labelledby` that
|
|
2731
3288
|
* reads the whole stat as a single accessible name in reading order.
|
|
2732
3289
|
*
|
|
2733
|
-
* Composition, never a config bag (Pillar 3): the
|
|
2734
|
-
*
|
|
2735
|
-
*
|
|
3290
|
+
* Composition, never a config bag (Pillar 3): the id coordination lives in the
|
|
3291
|
+
* {@link CngxStatCoordinator} host directive, so another component that hosts
|
|
3292
|
+
* the same four slots applies the identical brain instead of reimplementing it.
|
|
3293
|
+
* The visuals stay whatever atoms the consumer projects into the slots.
|
|
2736
3294
|
*
|
|
2737
3295
|
* ```html
|
|
2738
3296
|
* <cngx-stat aria-live="polite">
|
|
@@ -2748,38 +3306,20 @@ const idsEqual = (a, b) => a.length === b.length && a.every((id, i) => id === b[
|
|
|
2748
3306
|
* @wcag AA
|
|
2749
3307
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/data/display/stat/stat.component.ts
|
|
2750
3308
|
* @since 0.1.0
|
|
2751
|
-
* @relatedTo CngxMetric, CngxDelta, CngxTrend
|
|
3309
|
+
* @relatedTo CngxMetric, CngxDelta, CngxTrend, CngxStatCoordinator
|
|
2752
3310
|
*
|
|
2753
3311
|
* <example-url>http://localhost:4200/#/common/data/stat/composed-kpi</example-url>
|
|
2754
3312
|
*/
|
|
2755
3313
|
class CngxStat {
|
|
2756
|
-
|
|
3314
|
+
/** @internal The shared slot-id brain, applied as a host directive. */
|
|
3315
|
+
coordinator = inject(CngxStatCoordinator, { host: true });
|
|
2757
3316
|
/**
|
|
2758
3317
|
* Politeness of the live region. `off` (default) for a static stat;
|
|
2759
3318
|
* `polite` / `assertive` for a KPI whose value updates in place.
|
|
2760
3319
|
*/
|
|
2761
3320
|
live = input('off', ...(ngDevMode ? [{ debugName: "live" }] : /* istanbul ignore next */ []));
|
|
2762
|
-
/** {@inheritDoc CngxStatRegistry.register} */
|
|
2763
|
-
register(kind, id) {
|
|
2764
|
-
this.slots.update((prev) => new Map(prev).set(kind, id));
|
|
2765
|
-
}
|
|
2766
|
-
/** {@inheritDoc CngxStatRegistry.unregister} */
|
|
2767
|
-
unregister(kind) {
|
|
2768
|
-
this.slots.update((prev) => {
|
|
2769
|
-
const next = new Map(prev);
|
|
2770
|
-
next.delete(kind);
|
|
2771
|
-
return next;
|
|
2772
|
-
});
|
|
2773
|
-
}
|
|
2774
|
-
/** @internal Present slot ids in reading order; structurally stable. */
|
|
2775
|
-
orderedIds = computed(() => {
|
|
2776
|
-
const map = this.slots();
|
|
2777
|
-
return SLOT_ORDER.map((kind) => map.get(kind)).filter((id) => id !== undefined);
|
|
2778
|
-
}, { ...(ngDevMode ? { debugName: "orderedIds" } : /* istanbul ignore next */ {}), equal: idsEqual });
|
|
2779
|
-
/** @internal Combined accessible name; `null` when no slot is present. */
|
|
2780
|
-
labelledBy = computed(() => this.orderedIds().join(' ') || null, ...(ngDevMode ? [{ debugName: "labelledBy" }] : /* istanbul ignore next */ []));
|
|
2781
3321
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStat, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
2782
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "21.2.4", type: CngxStat, isStandalone: true, selector: "cngx-stat", inputs: { live: { classPropertyName: "live", publicName: "live", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "role": "group" }, properties: { "attr.aria-labelledby": "labelledBy()", "attr.aria-live": "live()" }, classAttribute: "cngx-stat" }, providers: [{ provide: CNGX_STAT, useExisting:
|
|
3322
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "21.2.4", type: CngxStat, isStandalone: true, selector: "cngx-stat", inputs: { live: { classPropertyName: "live", publicName: "live", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "role": "group" }, properties: { "attr.aria-labelledby": "coordinator.labelledBy()", "attr.aria-live": "live()" }, classAttribute: "cngx-stat" }, providers: [{ provide: CNGX_STAT, useExisting: CngxStatCoordinator }], hostDirectives: [{ directive: CngxStatCoordinator }], ngImport: i0, template: `
|
|
2783
3323
|
<ng-content select="[cngxStatLabel]" />
|
|
2784
3324
|
<div class="cngx-stat__row">
|
|
2785
3325
|
<ng-content select="[cngxStatValue]" />
|
|
@@ -2790,10 +3330,10 @@ class CngxStat {
|
|
|
2790
3330
|
}
|
|
2791
3331
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStat, decorators: [{
|
|
2792
3332
|
type: Component,
|
|
2793
|
-
args: [{ selector: 'cngx-stat', standalone: true, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, providers: [{ provide: CNGX_STAT, useExisting:
|
|
3333
|
+
args: [{ selector: 'cngx-stat', standalone: true, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, hostDirectives: [CngxStatCoordinator], providers: [{ provide: CNGX_STAT, useExisting: CngxStatCoordinator }], host: {
|
|
2794
3334
|
class: 'cngx-stat',
|
|
2795
3335
|
role: 'group',
|
|
2796
|
-
'[attr.aria-labelledby]': 'labelledBy()',
|
|
3336
|
+
'[attr.aria-labelledby]': 'coordinator.labelledBy()',
|
|
2797
3337
|
'[attr.aria-live]': 'live()',
|
|
2798
3338
|
}, template: `
|
|
2799
3339
|
<ng-content select="[cngxStatLabel]" />
|
|
@@ -2814,7 +3354,7 @@ function useStatSlot(kind) {
|
|
|
2814
3354
|
const registry = inject(CNGX_STAT, { optional: true });
|
|
2815
3355
|
const id = nextUid(`cngx-stat-${kind}`);
|
|
2816
3356
|
registry?.register(kind, id);
|
|
2817
|
-
inject(DestroyRef).onDestroy(() => registry?.unregister(kind));
|
|
3357
|
+
inject(DestroyRef).onDestroy(() => registry?.unregister(kind, id));
|
|
2818
3358
|
return id;
|
|
2819
3359
|
}
|
|
2820
3360
|
/**
|
|
@@ -2906,95 +3446,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
2906
3446
|
}]
|
|
2907
3447
|
}] });
|
|
2908
3448
|
|
|
2909
|
-
/** Tone glyph rendered inside the decorative dot - the non-colour signal. */
|
|
2910
|
-
const TONE_GLYPH = {
|
|
2911
|
-
success: '✓',
|
|
2912
|
-
warning: '!',
|
|
2913
|
-
danger: '✕',
|
|
2914
|
-
info: 'i',
|
|
2915
|
-
neutral: '•',
|
|
2916
|
-
};
|
|
2917
|
-
/**
|
|
2918
|
-
* Semantic health indicator - a decorative tone dot paired with a visible
|
|
2919
|
-
* label. Distinct from `CngxBadge` (count overlay), `CngxChip` (interactive)
|
|
2920
|
-
* and `CngxTag` (labeled token): its single job is to communicate a status
|
|
2921
|
-
* (operational / degraded / down / info).
|
|
2922
|
-
*
|
|
2923
|
-
* Colour is never the only signal (Pillar 2): the tone drives the dot colour
|
|
2924
|
-
* *and* a tone glyph, so a colour-blind reader still distinguishes the states,
|
|
2925
|
-
* and the visible `label` carries the meaning for assistive tech (the dot is
|
|
2926
|
-
* `aria-hidden`). Set `live` for a status that changes in place.
|
|
2927
|
-
*
|
|
2928
|
-
* ### Basic
|
|
2929
|
-
* ```html
|
|
2930
|
-
* <cngx-status tone="success" label="Operational" />
|
|
2931
|
-
* ```
|
|
2932
|
-
*
|
|
2933
|
-
* ### Live-updating
|
|
2934
|
-
* ```html
|
|
2935
|
-
* <cngx-status tone="danger" label="Outage" live="assertive" />
|
|
2936
|
-
* ```
|
|
2937
|
-
*
|
|
2938
|
-
* @category common/data/metric
|
|
2939
|
-
* @docsKind primary
|
|
2940
|
-
* @wcag AA
|
|
2941
|
-
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/data/display/status/status.component.ts
|
|
2942
|
-
* @since 0.1.0
|
|
2943
|
-
* @relatedTo CngxBadge, CngxTag, CngxChip
|
|
2944
|
-
*
|
|
2945
|
-
* <example-url>http://localhost:4200/#/common/data/status/tone-matrix</example-url>
|
|
2946
|
-
*/
|
|
2947
|
-
class CngxStatus {
|
|
2948
|
-
elRef = inject((ElementRef));
|
|
2949
|
-
/** Semantic health. Drives both the dot colour and the tone glyph. */
|
|
2950
|
-
tone = input('neutral', ...(ngDevMode ? [{ debugName: "tone" }] : /* istanbul ignore next */ []));
|
|
2951
|
-
/** Visible status text. Carries the meaning for assistive tech. */
|
|
2952
|
-
label = input(undefined, ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
|
|
2953
|
-
/**
|
|
2954
|
-
* Politeness of the live region. `off` (default) for a static status;
|
|
2955
|
-
* `polite` / `assertive` for a status that changes in place.
|
|
2956
|
-
*/
|
|
2957
|
-
live = input('off', ...(ngDevMode ? [{ debugName: "live" }] : /* istanbul ignore next */ []));
|
|
2958
|
-
/** @internal Tone glyph bound into the decorative dot. */
|
|
2959
|
-
glyph = computed(() => TONE_GLYPH[this.tone()], ...(ngDevMode ? [{ debugName: "glyph" }] : /* istanbul ignore next */ []));
|
|
2960
|
-
constructor() {
|
|
2961
|
-
if (isDevMode()) {
|
|
2962
|
-
afterNextRender(() => {
|
|
2963
|
-
const el = this.elRef.nativeElement;
|
|
2964
|
-
if (!this.label() && !el.getAttribute('aria-label') && !el.getAttribute('aria-labelledby')) {
|
|
2965
|
-
console.warn('cngx-status: no `label` and no external `aria-label`/`aria-labelledby`; ' +
|
|
2966
|
-
'the status has no accessible name and reads only as a coloured dot. ' +
|
|
2967
|
-
'Set [label] or an aria-label on the host.');
|
|
2968
|
-
}
|
|
2969
|
-
});
|
|
2970
|
-
}
|
|
2971
|
-
}
|
|
2972
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStatus, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
2973
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.4", type: CngxStatus, isStandalone: true, selector: "cngx-status", inputs: { tone: { classPropertyName: "tone", publicName: "tone", isSignal: true, isRequired: false, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, live: { classPropertyName: "live", publicName: "live", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "class.cngx-status--success": "tone() === 'success'", "class.cngx-status--warning": "tone() === 'warning'", "class.cngx-status--danger": "tone() === 'danger'", "class.cngx-status--info": "tone() === 'info'", "class.cngx-status--neutral": "tone() === 'neutral'", "attr.aria-live": "live()" }, classAttribute: "cngx-status" }, ngImport: i0, template: `
|
|
2974
|
-
<span class="cngx-status__dot" aria-hidden="true">{{ glyph() }}</span>
|
|
2975
|
-
@if (label()) {
|
|
2976
|
-
<span class="cngx-status__label">{{ label() }}</span>
|
|
2977
|
-
}
|
|
2978
|
-
`, isInline: true, styles: ["@layer cngx.tokens{@property --cngx-status-gap{syntax: \"<length>\"; inherits: false; initial-value: 6px;}@property --cngx-status-dot-size{syntax: \"<length>\"; inherits: false; initial-value: 16px;}@property --cngx-status-glyph-size{syntax: \"*\"; inherits: true; initial-value: .7em;}@property --cngx-status-dot-fg{syntax: \"<color>\"; inherits: true; initial-value: white;}@property --cngx-status-size{syntax: \"*\"; inherits: true; initial-value: .8125rem;}@property --cngx-status-weight{syntax: \"<number>\"; inherits: true; initial-value: 500;}@property --cngx-status-success-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .18 145);}@property --cngx-status-warning-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.75 .15 85);}@property --cngx-status-danger-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .22 25);}@property --cngx-status-info-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.6 .14 250);}@property --cngx-status-neutral-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.6 .02 290);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-status-success-color: oklch(.78 .16 145);--cngx-status-warning-color: oklch(.82 .13 85);--cngx-status-danger-color: oklch(.75 .18 25);--cngx-status-info-color: oklch(.72 .12 250);--cngx-status-neutral-color: oklch(.7 .02 290)}}[data-color-scheme=dark],.dark{--cngx-status-success-color: oklch(.78 .16 145);--cngx-status-warning-color: oklch(.82 .13 85);--cngx-status-danger-color: oklch(.75 .18 25);--cngx-status-info-color: oklch(.72 .12 250);--cngx-status-neutral-color: oklch(.7 .02 290)}[data-color-scheme=light],.light{--cngx-status-success-color: oklch(.65 .18 145);--cngx-status-warning-color: oklch(.75 .15 85);--cngx-status-danger-color: oklch(.65 .22 25);--cngx-status-info-color: oklch(.6 .14 250);--cngx-status-neutral-color: oklch(.6 .02 290)}}@layer cngx.components{@scope(.cngx-status){:scope{--cngx-status-gap: var(--cngx-space-sm);display:inline-flex;align-items:center;gap:var(--cngx-status-gap, 6px);font-size:var(--cngx-status-size, .8125rem);font-weight:var(--cngx-status-weight, 500)}.cngx-status__dot{display:inline-flex;align-items:center;justify-content:center;inline-size:var(--cngx-status-dot-size, 1rem);block-size:var(--cngx-status-dot-size, 1rem);border-radius:50%;font-size:var(--cngx-status-glyph-size, .7em);line-height:1;color:var(--cngx-status-dot-fg, white);background:var(--cngx-status-neutral-color, oklch(.6 .02 290))}:scope.cngx-status--success .cngx-status__dot{background:var(--cngx-status-success-color, var(--cngx-color-success, oklch(.65 .18 145)))}:scope.cngx-status--warning .cngx-status__dot{background:var(--cngx-status-warning-color, oklch(.75 .15 85))}:scope.cngx-status--danger .cngx-status__dot{background:var(--cngx-status-danger-color, var(--cngx-color-danger, oklch(.65 .22 25)))}:scope.cngx-status--info .cngx-status__dot{background:var(--cngx-status-info-color, oklch(.6 .14 250))}:scope.cngx-status--neutral .cngx-status__dot{background:var(--cngx-status-neutral-color, oklch(.6 .02 290))}}}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
2979
|
-
}
|
|
2980
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStatus, decorators: [{
|
|
2981
|
-
type: Component,
|
|
2982
|
-
args: [{ selector: 'cngx-status', standalone: true, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, host: {
|
|
2983
|
-
class: 'cngx-status',
|
|
2984
|
-
'[class.cngx-status--success]': "tone() === 'success'",
|
|
2985
|
-
'[class.cngx-status--warning]': "tone() === 'warning'",
|
|
2986
|
-
'[class.cngx-status--danger]': "tone() === 'danger'",
|
|
2987
|
-
'[class.cngx-status--info]': "tone() === 'info'",
|
|
2988
|
-
'[class.cngx-status--neutral]': "tone() === 'neutral'",
|
|
2989
|
-
'[attr.aria-live]': 'live()',
|
|
2990
|
-
}, template: `
|
|
2991
|
-
<span class="cngx-status__dot" aria-hidden="true">{{ glyph() }}</span>
|
|
2992
|
-
@if (label()) {
|
|
2993
|
-
<span class="cngx-status__label">{{ label() }}</span>
|
|
2994
|
-
}
|
|
2995
|
-
`, styles: ["@layer cngx.tokens{@property --cngx-status-gap{syntax: \"<length>\"; inherits: false; initial-value: 6px;}@property --cngx-status-dot-size{syntax: \"<length>\"; inherits: false; initial-value: 16px;}@property --cngx-status-glyph-size{syntax: \"*\"; inherits: true; initial-value: .7em;}@property --cngx-status-dot-fg{syntax: \"<color>\"; inherits: true; initial-value: white;}@property --cngx-status-size{syntax: \"*\"; inherits: true; initial-value: .8125rem;}@property --cngx-status-weight{syntax: \"<number>\"; inherits: true; initial-value: 500;}@property --cngx-status-success-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .18 145);}@property --cngx-status-warning-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.75 .15 85);}@property --cngx-status-danger-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .22 25);}@property --cngx-status-info-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.6 .14 250);}@property --cngx-status-neutral-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.6 .02 290);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-status-success-color: oklch(.78 .16 145);--cngx-status-warning-color: oklch(.82 .13 85);--cngx-status-danger-color: oklch(.75 .18 25);--cngx-status-info-color: oklch(.72 .12 250);--cngx-status-neutral-color: oklch(.7 .02 290)}}[data-color-scheme=dark],.dark{--cngx-status-success-color: oklch(.78 .16 145);--cngx-status-warning-color: oklch(.82 .13 85);--cngx-status-danger-color: oklch(.75 .18 25);--cngx-status-info-color: oklch(.72 .12 250);--cngx-status-neutral-color: oklch(.7 .02 290)}[data-color-scheme=light],.light{--cngx-status-success-color: oklch(.65 .18 145);--cngx-status-warning-color: oklch(.75 .15 85);--cngx-status-danger-color: oklch(.65 .22 25);--cngx-status-info-color: oklch(.6 .14 250);--cngx-status-neutral-color: oklch(.6 .02 290)}}@layer cngx.components{@scope(.cngx-status){:scope{--cngx-status-gap: var(--cngx-space-sm);display:inline-flex;align-items:center;gap:var(--cngx-status-gap, 6px);font-size:var(--cngx-status-size, .8125rem);font-weight:var(--cngx-status-weight, 500)}.cngx-status__dot{display:inline-flex;align-items:center;justify-content:center;inline-size:var(--cngx-status-dot-size, 1rem);block-size:var(--cngx-status-dot-size, 1rem);border-radius:50%;font-size:var(--cngx-status-glyph-size, .7em);line-height:1;color:var(--cngx-status-dot-fg, white);background:var(--cngx-status-neutral-color, oklch(.6 .02 290))}:scope.cngx-status--success .cngx-status__dot{background:var(--cngx-status-success-color, var(--cngx-color-success, oklch(.65 .18 145)))}:scope.cngx-status--warning .cngx-status__dot{background:var(--cngx-status-warning-color, oklch(.75 .15 85))}:scope.cngx-status--danger .cngx-status__dot{background:var(--cngx-status-danger-color, var(--cngx-color-danger, oklch(.65 .22 25)))}:scope.cngx-status--info .cngx-status__dot{background:var(--cngx-status-info-color, oklch(.6 .14 250))}:scope.cngx-status--neutral .cngx-status__dot{background:var(--cngx-status-neutral-color, oklch(.6 .02 290))}}}\n"] }]
|
|
2996
|
-
}], ctorParameters: () => [], propDecorators: { tone: [{ type: i0.Input, args: [{ isSignal: true, alias: "tone", required: false }] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], live: [{ type: i0.Input, args: [{ isSignal: true, alias: "live", required: false }] }] } });
|
|
2997
|
-
|
|
2998
3449
|
/**
|
|
2999
3450
|
* Determinate attainment bar - a continuous progress toward a target
|
|
3000
3451
|
* (quota reached, budget spent, goal met). Named `CngxGoal` because
|
|
@@ -3008,7 +3459,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
3008
3459
|
* derived percent bound as a CSS custom property.
|
|
3009
3460
|
*
|
|
3010
3461
|
* ```html
|
|
3011
|
-
* <cngx-goal [value]="73" [max]="100" />
|
|
3462
|
+
* <cngx-goal [value]="73" [max]="100" label="Quota attainment" />
|
|
3012
3463
|
* <cngx-goal [value]="q()" [max]="target()" [valueTextFormat]="quotaText" />
|
|
3013
3464
|
* ```
|
|
3014
3465
|
*
|
|
@@ -3022,14 +3473,23 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
3022
3473
|
* <example-url>http://localhost:4200/#/common/data/goal/quota-attainment</example-url>
|
|
3023
3474
|
*/
|
|
3024
3475
|
class CngxGoal {
|
|
3476
|
+
i18n = injectKpiI18n();
|
|
3025
3477
|
/** Current attainment. Clamped to `[0, max]`. */
|
|
3026
3478
|
value = input.required(...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
|
|
3027
3479
|
/** Target the value works toward. Defaults to `100`. */
|
|
3028
3480
|
max = input(100, ...(ngDevMode ? [{ debugName: "max" }] : /* istanbul ignore next */ []));
|
|
3481
|
+
/**
|
|
3482
|
+
* Accessible name for the progressbar (what the attainment measures, e.g.
|
|
3483
|
+
* "Quarterly quota"). Mirrors the `label` input of the sibling KPI atoms;
|
|
3484
|
+
* omit it only when an external `aria-labelledby` (e.g. a `cngxStatLabel`)
|
|
3485
|
+
* names the bar instead.
|
|
3486
|
+
*/
|
|
3487
|
+
label = input(undefined, ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
|
|
3029
3488
|
/**
|
|
3030
3489
|
* Override the `aria-valuetext` string. Receives `(now, max)` - the clamped
|
|
3031
|
-
* value and the target.
|
|
3032
|
-
*
|
|
3490
|
+
* value and the target. Wins over the app-wide `CNGX_KPI_I18N.goalValueText`
|
|
3491
|
+
* (English default `(now, max) => \`${now} of ${max}\``). Supply a closure
|
|
3492
|
+
* for richer per-instance text (e.g.
|
|
3033
3493
|
* `(n, m) => \`${n} of ${m}, ${Math.round((n / m) * 100)}% of quota\``).
|
|
3034
3494
|
*/
|
|
3035
3495
|
valueTextFormat = input(undefined, ...(ngDevMode ? [{ debugName: "valueTextFormat" }] : /* istanbul ignore next */ []));
|
|
@@ -3044,11 +3504,11 @@ class CngxGoal {
|
|
|
3044
3504
|
}, ...(ngDevMode ? [{ debugName: "fillPercent" }] : /* istanbul ignore next */ []));
|
|
3045
3505
|
/** `aria-valuetext` - human-readable attainment via the resolved closure. */
|
|
3046
3506
|
valueText = computed(() => {
|
|
3047
|
-
const fmt = this.valueTextFormat() ?? (
|
|
3507
|
+
const fmt = this.valueTextFormat() ?? this.i18n().goalValueText;
|
|
3048
3508
|
return fmt(this.now(), this.maxValue());
|
|
3049
3509
|
}, ...(ngDevMode ? [{ debugName: "valueText" }] : /* istanbul ignore next */ []));
|
|
3050
3510
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxGoal, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
3051
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "21.2.4", type: CngxGoal, isStandalone: true, selector: "cngx-goal", inputs: { value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: true, transformFunction: null }, max: { classPropertyName: "max", publicName: "max", isSignal: true, isRequired: false, transformFunction: null }, valueTextFormat: { classPropertyName: "valueTextFormat", publicName: "valueTextFormat", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "role": "progressbar" }, properties: { "attr.aria-valuemin": "0", "attr.aria-valuemax": "maxValue()", "attr.aria-valuenow": "now()", "attr.aria-valuetext": "valueText()", "style.--cngx-goal-fill.%": "fillPercent()" }, classAttribute: "cngx-goal" }, ngImport: i0, template: `<span class="cngx-goal__track"><span class="cngx-goal__fill"></span></span>`, isInline: true, styles: ["@layer cngx.tokens{@property --cngx-goal-fill{syntax: \"<percentage>\"; inherits: true; initial-value: 0%;}@property --cngx-goal-height{syntax: \"<length>\"; inherits: false; initial-value: 8px;}@property --cngx-goal-radius{syntax: \"<length>\"; inherits: false; initial-value: 999px;}@property --cngx-goal-track-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.92 .01 290);}@property --cngx-goal-fill-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .18 145);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-goal-track-color: oklch(.3 .01 290);--cngx-goal-fill-color: oklch(.78 .16 145)}}[data-color-scheme=dark],.dark{--cngx-goal-track-color: oklch(.3 .01 290);--cngx-goal-fill-color: oklch(.78 .16 145)}[data-color-scheme=light],.light{--cngx-goal-track-color: oklch(.92 .01 290);--cngx-goal-fill-color: oklch(.65 .18 145)}}@layer cngx.components{@scope(.cngx-goal){:scope{display:block;inline-size:100%}.cngx-goal__track{display:block;inline-size:100%;block-size:var(--cngx-goal-height, 8px);border-radius:var(--cngx-goal-radius, 999px);background:var(--cngx-goal-track-color, oklch(.92 .01 290));overflow:hidden}.cngx-goal__fill{display:block;block-size:100%;inline-size:var(--cngx-goal-fill, 0%);border-radius:inherit;background:var(--cngx-goal-fill-color, var(--cngx-color-success, oklch(.65 .18 145)))}}}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
3511
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "21.2.4", type: CngxGoal, isStandalone: true, selector: "cngx-goal", inputs: { value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: true, transformFunction: null }, max: { classPropertyName: "max", publicName: "max", isSignal: true, isRequired: false, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, valueTextFormat: { classPropertyName: "valueTextFormat", publicName: "valueTextFormat", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "role": "progressbar" }, properties: { "attr.aria-valuemin": "0", "attr.aria-valuemax": "maxValue()", "attr.aria-valuenow": "now()", "attr.aria-valuetext": "valueText()", "attr.aria-label": "label() ?? null", "style.--cngx-goal-fill.%": "fillPercent()" }, classAttribute: "cngx-goal" }, ngImport: i0, template: `<span class="cngx-goal__track"><span class="cngx-goal__fill"></span></span>`, isInline: true, styles: ["@layer cngx.tokens{@property --cngx-goal-fill{syntax: \"<percentage>\"; inherits: true; initial-value: 0%;}@property --cngx-goal-height{syntax: \"<length>\"; inherits: false; initial-value: 8px;}@property --cngx-goal-radius{syntax: \"<length>\"; inherits: false; initial-value: 999px;}@property --cngx-goal-track-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.92 .01 290);}@property --cngx-goal-fill-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .18 145);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-goal-track-color: oklch(.3 .01 290);--cngx-goal-fill-color: oklch(.78 .16 145)}}[data-color-scheme=dark],.dark{--cngx-goal-track-color: oklch(.3 .01 290);--cngx-goal-fill-color: oklch(.78 .16 145)}[data-color-scheme=light],.light{--cngx-goal-track-color: oklch(.92 .01 290);--cngx-goal-fill-color: oklch(.65 .18 145)}}@layer cngx.components{@scope(.cngx-goal){:scope{display:block;inline-size:100%}.cngx-goal__track{display:block;inline-size:100%;block-size:var(--cngx-goal-height, 8px);border-radius:var(--cngx-goal-radius, 999px);background:var(--cngx-goal-track-color, oklch(.92 .01 290));overflow:hidden}.cngx-goal__fill{display:block;block-size:100%;inline-size:var(--cngx-goal-fill, 0%);border-radius:inherit;background:var(--cngx-goal-fill-color, var(--cngx-color-success, oklch(.65 .18 145)))}}}@media(forced-colors:active){.cngx-goal__track{box-sizing:border-box;border:1px solid CanvasText}.cngx-goal__fill{background:Highlight}}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
3052
3512
|
}
|
|
3053
3513
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxGoal, decorators: [{
|
|
3054
3514
|
type: Component,
|
|
@@ -3059,9 +3519,28 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
3059
3519
|
'[attr.aria-valuemax]': 'maxValue()',
|
|
3060
3520
|
'[attr.aria-valuenow]': 'now()',
|
|
3061
3521
|
'[attr.aria-valuetext]': 'valueText()',
|
|
3522
|
+
'[attr.aria-label]': 'label() ?? null',
|
|
3062
3523
|
'[style.--cngx-goal-fill.%]': 'fillPercent()',
|
|
3063
|
-
}, template: `<span class="cngx-goal__track"><span class="cngx-goal__fill"></span></span>`, styles: ["@layer cngx.tokens{@property --cngx-goal-fill{syntax: \"<percentage>\"; inherits: true; initial-value: 0%;}@property --cngx-goal-height{syntax: \"<length>\"; inherits: false; initial-value: 8px;}@property --cngx-goal-radius{syntax: \"<length>\"; inherits: false; initial-value: 999px;}@property --cngx-goal-track-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.92 .01 290);}@property --cngx-goal-fill-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .18 145);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-goal-track-color: oklch(.3 .01 290);--cngx-goal-fill-color: oklch(.78 .16 145)}}[data-color-scheme=dark],.dark{--cngx-goal-track-color: oklch(.3 .01 290);--cngx-goal-fill-color: oklch(.78 .16 145)}[data-color-scheme=light],.light{--cngx-goal-track-color: oklch(.92 .01 290);--cngx-goal-fill-color: oklch(.65 .18 145)}}@layer cngx.components{@scope(.cngx-goal){:scope{display:block;inline-size:100%}.cngx-goal__track{display:block;inline-size:100%;block-size:var(--cngx-goal-height, 8px);border-radius:var(--cngx-goal-radius, 999px);background:var(--cngx-goal-track-color, oklch(.92 .01 290));overflow:hidden}.cngx-goal__fill{display:block;block-size:100%;inline-size:var(--cngx-goal-fill, 0%);border-radius:inherit;background:var(--cngx-goal-fill-color, var(--cngx-color-success, oklch(.65 .18 145)))}}}\n"] }]
|
|
3064
|
-
}], propDecorators: { value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: true }] }], max: [{ type: i0.Input, args: [{ isSignal: true, alias: "max", required: false }] }], valueTextFormat: [{ type: i0.Input, args: [{ isSignal: true, alias: "valueTextFormat", required: false }] }] } });
|
|
3524
|
+
}, template: `<span class="cngx-goal__track"><span class="cngx-goal__fill"></span></span>`, styles: ["@layer cngx.tokens{@property --cngx-goal-fill{syntax: \"<percentage>\"; inherits: true; initial-value: 0%;}@property --cngx-goal-height{syntax: \"<length>\"; inherits: false; initial-value: 8px;}@property --cngx-goal-radius{syntax: \"<length>\"; inherits: false; initial-value: 999px;}@property --cngx-goal-track-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.92 .01 290);}@property --cngx-goal-fill-color{syntax: \"<color>\"; inherits: true; initial-value: oklch(.65 .18 145);}@media(prefers-color-scheme:dark){:root:not([data-color-scheme=light]):not(.light){--cngx-goal-track-color: oklch(.3 .01 290);--cngx-goal-fill-color: oklch(.78 .16 145)}}[data-color-scheme=dark],.dark{--cngx-goal-track-color: oklch(.3 .01 290);--cngx-goal-fill-color: oklch(.78 .16 145)}[data-color-scheme=light],.light{--cngx-goal-track-color: oklch(.92 .01 290);--cngx-goal-fill-color: oklch(.65 .18 145)}}@layer cngx.components{@scope(.cngx-goal){:scope{display:block;inline-size:100%}.cngx-goal__track{display:block;inline-size:100%;block-size:var(--cngx-goal-height, 8px);border-radius:var(--cngx-goal-radius, 999px);background:var(--cngx-goal-track-color, oklch(.92 .01 290));overflow:hidden}.cngx-goal__fill{display:block;block-size:100%;inline-size:var(--cngx-goal-fill, 0%);border-radius:inherit;background:var(--cngx-goal-fill-color, var(--cngx-color-success, oklch(.65 .18 145)))}}}@media(forced-colors:active){.cngx-goal__track{box-sizing:border-box;border:1px solid CanvasText}.cngx-goal__fill{background:Highlight}}\n"] }]
|
|
3525
|
+
}], propDecorators: { value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: true }] }], max: [{ type: i0.Input, args: [{ isSignal: true, alias: "max", required: false }] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], valueTextFormat: [{ type: i0.Input, args: [{ isSignal: true, alias: "valueTextFormat", required: false }] }] } });
|
|
3526
|
+
|
|
3527
|
+
/**
|
|
3528
|
+
* The English recycler section: the single source of the recycler's English
|
|
3529
|
+
* copy. `CNGX_RECYCLER_I18N` defaults to it.
|
|
3530
|
+
*
|
|
3531
|
+
* @category common/data/i18n
|
|
3532
|
+
* @since 0.1.0
|
|
3533
|
+
* @relatedTo CNGX_RECYCLER_I18N
|
|
3534
|
+
*/
|
|
3535
|
+
const CNGX_RECYCLER_LANGUAGE_EN = {
|
|
3536
|
+
loaded: {
|
|
3537
|
+
one: '{count} more item loaded. {total} total.',
|
|
3538
|
+
other: '{count} more items loaded. {total} total.',
|
|
3539
|
+
},
|
|
3540
|
+
filtered: { one: '{count} result found.', other: '{count} results found.' },
|
|
3541
|
+
empty: 'No results',
|
|
3542
|
+
error: 'Error loading data',
|
|
3543
|
+
};
|
|
3065
3544
|
|
|
3066
3545
|
const EMPTY_RANGE = {
|
|
3067
3546
|
start: 0,
|
|
@@ -3080,31 +3559,58 @@ const EMPTY_RANGE = {
|
|
|
3080
3559
|
* @param clientHeight Viewport height in px.
|
|
3081
3560
|
* @param totalCount Total number of items.
|
|
3082
3561
|
* @param estimateSize Fixed item height in px, or a function returning height per index.
|
|
3083
|
-
* @param
|
|
3562
|
+
* @param overscanBefore Extra items to render above the viewport (leading edge
|
|
3563
|
+
* when scrolling up).
|
|
3084
3564
|
* @param columns Column count for grid mode (default 1). When > 1, range is row-aligned.
|
|
3085
3565
|
* Variable `estimateSize` ignores columns (grid + variable heights not supported).
|
|
3566
|
+
* @param overscanAfter Extra items to render below the viewport (leading edge when
|
|
3567
|
+
* scrolling down). Defaults to `overscanBefore` for a symmetric range. Callers pass
|
|
3568
|
+
* an asymmetric pair to pre-render into the scroll direction.
|
|
3086
3569
|
* @returns The computed range with spacer offsets.
|
|
3087
3570
|
* @internal
|
|
3088
3571
|
*/
|
|
3089
|
-
function computeRange(scrollTop, clientHeight, totalCount, estimateSize,
|
|
3090
|
-
if (totalCount <= 0
|
|
3572
|
+
function computeRange(scrollTop, clientHeight, totalCount, estimateSize, overscanBefore, columns = 1, overscanAfter = overscanBefore) {
|
|
3573
|
+
if (totalCount <= 0) {
|
|
3091
3574
|
return EMPTY_RANGE;
|
|
3092
3575
|
}
|
|
3576
|
+
if (clientHeight <= 0) {
|
|
3577
|
+
// Degenerate viewport (0px). A content-driven scrollport gets its height
|
|
3578
|
+
// FROM the spacers this result sizes, so reporting `totalSize: 0` here
|
|
3579
|
+
// deadlocks: no spacer, no height, no spacer. Report the full totalSize
|
|
3580
|
+
// with an empty window instead - the after-spacer gives the viewport its
|
|
3581
|
+
// height, the ResizeObserver-fed `clientHeight` turns non-zero, and the
|
|
3582
|
+
// next computation renders the real range.
|
|
3583
|
+
const totalSize = estimateTotalSize(totalCount, estimateSize, columns);
|
|
3584
|
+
return { start: 0, end: 0, offsetBefore: 0, offsetAfter: totalSize, totalSize };
|
|
3585
|
+
}
|
|
3093
3586
|
if (typeof estimateSize === 'number') {
|
|
3094
|
-
return computeFixedRange(scrollTop, clientHeight, totalCount, estimateSize,
|
|
3587
|
+
return computeFixedRange(scrollTop, clientHeight, totalCount, estimateSize, overscanBefore, overscanAfter, columns);
|
|
3095
3588
|
}
|
|
3096
3589
|
// variable heights: grid mode unsupported, columns ignored
|
|
3097
|
-
return computeVariableRange(scrollTop, clientHeight, totalCount, estimateSize,
|
|
3590
|
+
return computeVariableRange(scrollTop, clientHeight, totalCount, estimateSize, overscanBefore, overscanAfter);
|
|
3591
|
+
}
|
|
3592
|
+
function estimateTotalSize(totalCount, estimateSize, columns) {
|
|
3593
|
+
if (typeof estimateSize === 'number') {
|
|
3594
|
+
const rows = columns > 1 ? Math.ceil(totalCount / columns) : totalCount;
|
|
3595
|
+
return rows * estimateSize;
|
|
3596
|
+
}
|
|
3597
|
+
// variable heights: grid mode unsupported, columns ignored (same contract
|
|
3598
|
+
// as computeVariableRange)
|
|
3599
|
+
let totalSize = 0;
|
|
3600
|
+
for (let i = 0; i < totalCount; i++) {
|
|
3601
|
+
totalSize += estimateSize(i);
|
|
3602
|
+
}
|
|
3603
|
+
return totalSize;
|
|
3098
3604
|
}
|
|
3099
|
-
function computeFixedRange(scrollTop, clientHeight, totalCount, itemSize,
|
|
3605
|
+
function computeFixedRange(scrollTop, clientHeight, totalCount, itemSize, overscanBefore, overscanAfter, columns) {
|
|
3100
3606
|
if (columns > 1) {
|
|
3101
|
-
return computeGridRange(scrollTop, clientHeight, totalCount, itemSize,
|
|
3607
|
+
return computeGridRange(scrollTop, clientHeight, totalCount, itemSize, overscanBefore, overscanAfter, columns);
|
|
3102
3608
|
}
|
|
3103
3609
|
const totalSize = totalCount * itemSize;
|
|
3104
3610
|
const rawStart = Math.floor(scrollTop / itemSize);
|
|
3105
3611
|
const rawEnd = Math.ceil((scrollTop + clientHeight) / itemSize);
|
|
3106
|
-
const start = Math.max(0, rawStart -
|
|
3107
|
-
const end = Math.min(totalCount, rawEnd +
|
|
3612
|
+
const start = Math.max(0, rawStart - overscanBefore);
|
|
3613
|
+
const end = Math.min(totalCount, rawEnd + overscanAfter);
|
|
3108
3614
|
return {
|
|
3109
3615
|
start,
|
|
3110
3616
|
end,
|
|
@@ -3121,16 +3627,17 @@ function computeFixedRange(scrollTop, clientHeight, totalCount, itemSize, oversc
|
|
|
3121
3627
|
*
|
|
3122
3628
|
* @internal
|
|
3123
3629
|
*/
|
|
3124
|
-
function computeGridRange(scrollTop, clientHeight, totalCount, rowHeight,
|
|
3630
|
+
function computeGridRange(scrollTop, clientHeight, totalCount, rowHeight, overscanBefore, overscanAfter, columns) {
|
|
3125
3631
|
const totalRows = Math.ceil(totalCount / columns);
|
|
3126
3632
|
const totalSize = totalRows * rowHeight;
|
|
3127
3633
|
// raw rows (inherently row-aligned)
|
|
3128
3634
|
const rawStartRow = Math.floor(scrollTop / rowHeight);
|
|
3129
3635
|
const rawEndRow = Math.ceil((scrollTop + clientHeight) / rowHeight);
|
|
3130
3636
|
// overscan applied in rows so full rows always render
|
|
3131
|
-
const
|
|
3132
|
-
const
|
|
3133
|
-
const
|
|
3637
|
+
const overscanRowsBefore = Math.ceil(overscanBefore / columns);
|
|
3638
|
+
const overscanRowsAfter = Math.ceil(overscanAfter / columns);
|
|
3639
|
+
const startRow = Math.max(0, rawStartRow - overscanRowsBefore);
|
|
3640
|
+
const endRow = Math.min(totalRows, rawEndRow + overscanRowsAfter);
|
|
3134
3641
|
const start = startRow * columns;
|
|
3135
3642
|
const end = Math.min(endRow * columns, totalCount);
|
|
3136
3643
|
return {
|
|
@@ -3141,7 +3648,7 @@ function computeGridRange(scrollTop, clientHeight, totalCount, rowHeight, oversc
|
|
|
3141
3648
|
totalSize,
|
|
3142
3649
|
};
|
|
3143
3650
|
}
|
|
3144
|
-
function computeVariableRange(scrollTop, clientHeight, totalCount, estimateSize,
|
|
3651
|
+
function computeVariableRange(scrollTop, clientHeight, totalCount, estimateSize, overscanBefore, overscanAfter) {
|
|
3145
3652
|
let totalSize = 0;
|
|
3146
3653
|
const offsets = new Array(totalCount + 1);
|
|
3147
3654
|
offsets[0] = 0;
|
|
@@ -3152,8 +3659,8 @@ function computeVariableRange(scrollTop, clientHeight, totalCount, estimateSize,
|
|
|
3152
3659
|
// binary search: first item whose bottom edge is past scrollTop
|
|
3153
3660
|
const rawStart = binarySearch(offsets, scrollTop, totalCount);
|
|
3154
3661
|
const rawEnd = binarySearch(offsets, scrollTop + clientHeight, totalCount);
|
|
3155
|
-
const start = Math.max(0, rawStart -
|
|
3156
|
-
const end = Math.min(totalCount, rawEnd + 1 +
|
|
3662
|
+
const start = Math.max(0, rawStart - overscanBefore);
|
|
3663
|
+
const end = Math.min(totalCount, rawEnd + 1 + overscanAfter);
|
|
3157
3664
|
return {
|
|
3158
3665
|
start,
|
|
3159
3666
|
end,
|
|
@@ -3190,7 +3697,7 @@ function binarySearch(offsets, target, totalCount) {
|
|
|
3190
3697
|
*
|
|
3191
3698
|
* Element resolution happens **lazily inside the effect**, not at call time.
|
|
3192
3699
|
* This is critical because `injectRecycler` is called in a field initializer
|
|
3193
|
-
* where template DOM does not yet exist
|
|
3700
|
+
* where template DOM does not yet exist - `querySelector` would return `null`.
|
|
3194
3701
|
* The effect runs after the first CD cycle when the DOM is stable.
|
|
3195
3702
|
*
|
|
3196
3703
|
* @internal Not exported from `@cngx/common/data` public API.
|
|
@@ -3200,7 +3707,7 @@ function createScrollObserver(elementRef, destroyRef) {
|
|
|
3200
3707
|
const scrollTopState = signal(0, ...(ngDevMode ? [{ debugName: "scrollTopState" }] : /* istanbul ignore next */ []));
|
|
3201
3708
|
const clientHeightState = signal(0, ...(ngDevMode ? [{ debugName: "clientHeightState" }] : /* istanbul ignore next */ []));
|
|
3202
3709
|
const elementState = signal(null, ...(ngDevMode ? [{ debugName: "elementState" }] : /* istanbul ignore next */ []));
|
|
3203
|
-
// Retry trigger
|
|
3710
|
+
// Retry trigger - incremented by afterNextRender to re-run the effect
|
|
3204
3711
|
// when the element wasn't found on the first attempt (routed components,
|
|
3205
3712
|
// content projection, lazy rendering).
|
|
3206
3713
|
const retryTick = signal(0, ...(ngDevMode ? [{ debugName: "retryTick" }] : /* istanbul ignore next */ []));
|
|
@@ -3217,35 +3724,28 @@ function createScrollObserver(elementRef, destroyRef) {
|
|
|
3217
3724
|
}
|
|
3218
3725
|
function attachListeners(el, onCleanup) {
|
|
3219
3726
|
// A viewport resolved: the late-mount watcher has done its job. Disconnect
|
|
3220
|
-
// it on attach so it can never outlive a resolved element
|
|
3727
|
+
// it on attach so it can never outlive a resolved element - the node is
|
|
3221
3728
|
// already in the DOM, so the observer would otherwise never fire again and
|
|
3222
3729
|
// leak until destroy.
|
|
3223
3730
|
disconnectMutationObserver();
|
|
3224
3731
|
elementState.set(el);
|
|
3225
3732
|
scrollTopState.set(el.scrollTop);
|
|
3226
3733
|
clientHeightState.set(el.clientHeight);
|
|
3227
|
-
|
|
3734
|
+
// Read scrollTop synchronously on the scroll event rather than deferring to
|
|
3735
|
+
// a requestAnimationFrame. The rAF hop delayed the range by a frame, so a
|
|
3736
|
+
// fast scroll outran the rendered window and flashed a blank strip. Scroll
|
|
3737
|
+
// events already fire at most once per frame, and the signal scheduler
|
|
3738
|
+
// coalesces bursts, so the synchronous read carries no extra recompute cost.
|
|
3228
3739
|
const handleScroll = () => {
|
|
3229
|
-
|
|
3230
|
-
return;
|
|
3231
|
-
}
|
|
3232
|
-
rafId = requestAnimationFrame(() => {
|
|
3233
|
-
rafId = null;
|
|
3234
|
-
scrollTopState.set(el.scrollTop);
|
|
3235
|
-
clientHeightState.set(el.clientHeight);
|
|
3236
|
-
});
|
|
3740
|
+
scrollTopState.set(el.scrollTop);
|
|
3237
3741
|
};
|
|
3238
3742
|
el.addEventListener('scroll', handleScroll, { passive: true });
|
|
3239
|
-
const
|
|
3743
|
+
const stopResize = observeResize(doc.defaultView, el, 'content-box', () => {
|
|
3240
3744
|
clientHeightState.set(el.clientHeight);
|
|
3241
3745
|
});
|
|
3242
|
-
resizeObserver.observe(el);
|
|
3243
3746
|
onCleanup(() => {
|
|
3244
3747
|
el.removeEventListener('scroll', handleScroll);
|
|
3245
|
-
|
|
3246
|
-
cancelAnimationFrame(rafId);
|
|
3247
|
-
}
|
|
3248
|
-
resizeObserver.disconnect();
|
|
3748
|
+
stopResize();
|
|
3249
3749
|
elementState.set(null);
|
|
3250
3750
|
});
|
|
3251
3751
|
}
|
|
@@ -3258,7 +3758,7 @@ function createScrollObserver(elementRef, destroyRef) {
|
|
|
3258
3758
|
attachListeners(el, onCleanup);
|
|
3259
3759
|
});
|
|
3260
3760
|
// If the element wasn't found on the first effect run (before DOM is ready),
|
|
3261
|
-
// retry after the next render cycle. Fires for ALL input shapes
|
|
3761
|
+
// retry after the next render cycle. Fires for ALL input shapes - string
|
|
3262
3762
|
// selectors resolve lazily via `querySelector`, but `ElementRef` from a
|
|
3263
3763
|
// `viewChild` also starts out with `nativeElement == null` until Angular
|
|
3264
3764
|
// resolves the query. `HTMLElement` inputs that are non-null at call time
|
|
@@ -3274,7 +3774,7 @@ function createScrollObserver(elementRef, destroyRef) {
|
|
|
3274
3774
|
// next-render mount (routed component, content projection, lazy rendering).
|
|
3275
3775
|
retryTick.update((v) => v + 1);
|
|
3276
3776
|
// A string selector can still be unresolved because its viewport mounts
|
|
3277
|
-
// arbitrarily late
|
|
3777
|
+
// arbitrarily late - an async-gated list, a skeleton->content swap. Watch
|
|
3278
3778
|
// the document and attach the instant it appears. Non-string refs
|
|
3279
3779
|
// (HTMLElement / ElementRef) are not document-queryable, so the watcher
|
|
3280
3780
|
// cannot help them; they stay on the single-retry path. Guard MutationObserver
|
|
@@ -3359,9 +3859,27 @@ function createSizeCache() {
|
|
|
3359
3859
|
};
|
|
3360
3860
|
}
|
|
3361
3861
|
|
|
3862
|
+
/** @internal Turns a recycler section into the token's keys for a locale. */
|
|
3863
|
+
function recyclerBundleFrom(section, locale) {
|
|
3864
|
+
return {
|
|
3865
|
+
loaded: (count, total) => formatMessage(section.loaded, { count, total }, locale),
|
|
3866
|
+
filtered: (count) => formatMessage(section.filtered, { count }, locale),
|
|
3867
|
+
empty: () => section.empty,
|
|
3868
|
+
error: () => section.error,
|
|
3869
|
+
};
|
|
3870
|
+
}
|
|
3871
|
+
/** @internal The recycler section of the active pack over English. */
|
|
3872
|
+
const injectRecyclerSection = createLanguageSection('recycler', CNGX_RECYCLER_LANGUAGE_EN);
|
|
3873
|
+
/** @internal Builds and reads the token, formatted for the reading locale. */
|
|
3874
|
+
const recyclerBundle = createSectionBundle({
|
|
3875
|
+
section: injectRecyclerSection,
|
|
3876
|
+
toBundle: recyclerBundleFrom,
|
|
3877
|
+
});
|
|
3362
3878
|
/**
|
|
3363
|
-
* Injection token for recycler SR announcement texts
|
|
3364
|
-
*
|
|
3879
|
+
* Injection token for recycler SR announcement texts, a `Signal` so the
|
|
3880
|
+
* texts follow a runtime language switch. Defaults to the recycler section
|
|
3881
|
+
* of the active language pack over English, counts formatted for the app
|
|
3882
|
+
* locale. Override with `provideRecyclerI18n()`.
|
|
3365
3883
|
*
|
|
3366
3884
|
* @category common/data/recycler
|
|
3367
3885
|
* @wcag AA
|
|
@@ -3369,62 +3887,44 @@ function createSizeCache() {
|
|
|
3369
3887
|
* @since 0.1.0
|
|
3370
3888
|
*/
|
|
3371
3889
|
const CNGX_RECYCLER_I18N = new InjectionToken('CngxRecyclerI18n', {
|
|
3372
|
-
factory: () => (
|
|
3373
|
-
loaded: (n, t) => `${n} more items loaded. ${t} total.`,
|
|
3374
|
-
filtered: (c) => `${c} results found.`,
|
|
3375
|
-
empty: () => 'No results.',
|
|
3376
|
-
error: () => 'Error loading data.',
|
|
3377
|
-
}),
|
|
3890
|
+
factory: () => recyclerBundle.build(),
|
|
3378
3891
|
});
|
|
3892
|
+
/** @internal */
|
|
3893
|
+
function defineRecyclerI18nFeature(fn) {
|
|
3894
|
+
return Object.assign(fn, { _target: 'i18n' });
|
|
3895
|
+
}
|
|
3379
3896
|
/**
|
|
3380
|
-
*
|
|
3381
|
-
*
|
|
3382
|
-
*
|
|
3383
|
-
* providers: [provideRecyclerI18n({
|
|
3384
|
-
* loaded: (n, t) => `${n} weitere Einträge. ${t} gesamt.`,
|
|
3385
|
-
* filtered: (c) => `${c} Ergebnisse.`,
|
|
3386
|
-
* empty: () => 'Keine Ergebnisse.',
|
|
3387
|
-
* error: () => 'Fehler beim Laden.',
|
|
3388
|
-
* })]
|
|
3389
|
-
* ```
|
|
3897
|
+
* Override recycler announcements via a partial bundle - keys you leave out
|
|
3898
|
+
* keep the language pack's text, or the English default. Pass a `Signal` to
|
|
3899
|
+
* switch the language at runtime.
|
|
3390
3900
|
*
|
|
3391
3901
|
* @category common/data/recycler
|
|
3392
3902
|
*/
|
|
3393
|
-
function
|
|
3394
|
-
return
|
|
3903
|
+
function withRecyclerI18nLabels(overrides) {
|
|
3904
|
+
return defineRecyclerI18nFeature((bundle) => createOverrideMerge(bundle, overrides));
|
|
3395
3905
|
}
|
|
3396
3906
|
/**
|
|
3397
|
-
*
|
|
3907
|
+
* Provider for the recycler announcement texts. The features apply on top of
|
|
3908
|
+
* the active language pack.
|
|
3398
3909
|
*
|
|
3399
|
-
*
|
|
3400
|
-
*
|
|
3401
|
-
*
|
|
3402
|
-
*
|
|
3910
|
+
* ```typescript
|
|
3911
|
+
* providers: [
|
|
3912
|
+
* provideRecyclerI18n(
|
|
3913
|
+
* withRecyclerI18nLabels({
|
|
3914
|
+
* empty: () => 'Keine Ergebnisse.',
|
|
3915
|
+
* error: () => 'Fehler beim Laden.',
|
|
3916
|
+
* }),
|
|
3917
|
+
* ),
|
|
3918
|
+
* ]
|
|
3919
|
+
* ```
|
|
3403
3920
|
*
|
|
3404
|
-
* @
|
|
3405
|
-
* @param delayMs Delay in milliseconds before the flag becomes `true`.
|
|
3406
|
-
* @returns A readonly signal that becomes `true` after `delayMs` when `source` is `true`.
|
|
3407
|
-
* @internal
|
|
3921
|
+
* @category common/data/recycler
|
|
3408
3922
|
*/
|
|
3409
|
-
function
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
effect((onCleanup) => {
|
|
3415
|
-
const active = source();
|
|
3416
|
-
if (active) {
|
|
3417
|
-
const timer = setTimeout(() => flag.set(true), delayMs);
|
|
3418
|
-
onCleanup(() => {
|
|
3419
|
-
clearTimeout(timer);
|
|
3420
|
-
flag.set(false);
|
|
3421
|
-
});
|
|
3422
|
-
}
|
|
3423
|
-
else {
|
|
3424
|
-
flag.set(false);
|
|
3425
|
-
}
|
|
3426
|
-
});
|
|
3427
|
-
return flag.asReadonly();
|
|
3923
|
+
function provideRecyclerI18n(...features) {
|
|
3924
|
+
return {
|
|
3925
|
+
provide: CNGX_RECYCLER_I18N,
|
|
3926
|
+
useFactory: () => recyclerBundle.build(features),
|
|
3927
|
+
};
|
|
3428
3928
|
}
|
|
3429
3929
|
/**
|
|
3430
3930
|
* Creates a Signal-based virtualizer for DOM recycling.
|
|
@@ -3457,7 +3957,7 @@ function createDelayedFlag(source, delayMs) {
|
|
|
3457
3957
|
*/
|
|
3458
3958
|
function injectRecycler(config) {
|
|
3459
3959
|
const destroyRef = inject(DestroyRef);
|
|
3460
|
-
const i18n = inject(CNGX_RECYCLER_I18N);
|
|
3960
|
+
const i18n = recyclerBundle.resolve(inject(CNGX_RECYCLER_I18N));
|
|
3461
3961
|
const overscan = config.overscan ?? 5;
|
|
3462
3962
|
const isGrid = (config.layout ?? 'list') === 'grid';
|
|
3463
3963
|
if (isGrid && config.columns == null && isDevMode()) {
|
|
@@ -3474,9 +3974,7 @@ function injectRecycler(config) {
|
|
|
3474
3974
|
// per-index measurement - it carries no O(n) per-frame cost, so exclude it
|
|
3475
3975
|
// from the variable-height warning (a reactive scalar estimate is a
|
|
3476
3976
|
// sanctioned pattern; see the resolveSize note below).
|
|
3477
|
-
if (typeof config.estimateSize === 'function' &&
|
|
3478
|
-
!isSignal(config.estimateSize) &&
|
|
3479
|
-
isDevMode()) {
|
|
3977
|
+
if (typeof config.estimateSize === 'function' && !isSignal(config.estimateSize) && isDevMode()) {
|
|
3480
3978
|
const count = config.totalCount();
|
|
3481
3979
|
if (count > 10_000) {
|
|
3482
3980
|
console.warn(`[CngxRecycler] estimateSize as a function with ${count} items has O(n) ` +
|
|
@@ -3492,12 +3990,40 @@ function injectRecycler(config) {
|
|
|
3492
3990
|
sizeCache.version(); // track dependency
|
|
3493
3991
|
return sizeCache.resolve(index, config.estimateSize);
|
|
3494
3992
|
};
|
|
3993
|
+
// Signed scroll delta between consecutive scrollTop updates. A fast flick
|
|
3994
|
+
// produces large per-event deltas, so this doubles as a velocity proxy
|
|
3995
|
+
// regardless of whether scrollTop is sampled per-frame or per-event.
|
|
3996
|
+
const scrollVelocity = signal(0, ...(ngDevMode ? [{ debugName: "scrollVelocity" }] : /* istanbul ignore next */ []));
|
|
3997
|
+
let lastScrollTop = 0;
|
|
3998
|
+
effect(() => {
|
|
3999
|
+
const st = scrollState.scrollTop();
|
|
4000
|
+
untracked(() => {
|
|
4001
|
+
scrollVelocity.set(st - lastScrollTop);
|
|
4002
|
+
lastScrollTop = st;
|
|
4003
|
+
});
|
|
4004
|
+
});
|
|
3495
4005
|
// Grid mode uses raw estimateSize (uniform row height, no SizeCache).
|
|
3496
4006
|
// List mode uses resolveSize (SizeCache-backed).
|
|
3497
4007
|
const range = computed(() => {
|
|
3498
4008
|
const cols = columns();
|
|
3499
4009
|
const size = isGrid ? config.estimateSize : resolveSize;
|
|
3500
|
-
|
|
4010
|
+
const scrollTop = scrollState.scrollTop();
|
|
4011
|
+
const clientHeight = scrollState.clientHeight();
|
|
4012
|
+
const total = config.totalCount();
|
|
4013
|
+
// Directional overscan: the rendered range trails scroll by up to a frame,
|
|
4014
|
+
// so pre-render extra items into the scroll direction to keep the leading
|
|
4015
|
+
// edge populated (otherwise a fast scroll flashes a blank strip). Scale the
|
|
4016
|
+
// lead with velocity, capped at one viewport of items so a teleport jump
|
|
4017
|
+
// never expands the window unbounded. Trailing edge keeps the base overscan.
|
|
4018
|
+
const estimate = config.estimateSize;
|
|
4019
|
+
const refPx = typeof estimate === 'number' && estimate > 0 ? estimate : Math.max(1, clientHeight / 8);
|
|
4020
|
+
const itemsPerViewport = Math.max(1, Math.ceil(clientHeight / refPx));
|
|
4021
|
+
const velocity = scrollVelocity();
|
|
4022
|
+
const leadItems = Math.min(Math.ceil(Math.abs(velocity) / refPx), itemsPerViewport);
|
|
4023
|
+
const scrollingDown = velocity >= 0;
|
|
4024
|
+
const overscanBefore = overscan + (scrollingDown ? 0 : leadItems);
|
|
4025
|
+
const overscanAfter = overscan + (scrollingDown ? leadItems : 0);
|
|
4026
|
+
return computeRange(scrollTop, clientHeight, total, size, overscanBefore, cols, overscanAfter);
|
|
3501
4027
|
}, ...(ngDevMode ? [{ debugName: "range" }] : /* istanbul ignore next */ []));
|
|
3502
4028
|
const start = computed(() => range().start, ...(ngDevMode ? [{ debugName: "start" }] : /* istanbul ignore next */ []));
|
|
3503
4029
|
const end = computed(() => range().end, ...(ngDevMode ? [{ debugName: "end" }] : /* istanbul ignore next */ []));
|
|
@@ -3505,6 +4031,23 @@ function injectRecycler(config) {
|
|
|
3505
4031
|
const offsetBefore = computed(() => (isGrid ? 0 : range().offsetBefore), ...(ngDevMode ? [{ debugName: "offsetBefore" }] : /* istanbul ignore next */ []));
|
|
3506
4032
|
const offsetAfter = computed(() => (isGrid ? 0 : range().offsetAfter), ...(ngDevMode ? [{ debugName: "offsetAfter" }] : /* istanbul ignore next */ []));
|
|
3507
4033
|
const totalSize = computed(() => range().totalSize, ...(ngDevMode ? [{ debugName: "totalSize" }] : /* istanbul ignore next */ []));
|
|
4034
|
+
// Representative row height for a placeholder layer's repeat interval. Derived,
|
|
4035
|
+
// never stored: a uniform estimate (number or signal) is the rhythm directly;
|
|
4036
|
+
// a per-index estimate has no single height, so the running average stands in.
|
|
4037
|
+
const rowSizeHint = computed(() => {
|
|
4038
|
+
const estimate = config.estimateSize;
|
|
4039
|
+
if (typeof estimate === 'number') {
|
|
4040
|
+
return estimate;
|
|
4041
|
+
}
|
|
4042
|
+
if (isSignal(estimate)) {
|
|
4043
|
+
return estimate();
|
|
4044
|
+
}
|
|
4045
|
+
const total = config.totalCount();
|
|
4046
|
+
if (total <= 0) {
|
|
4047
|
+
return 0;
|
|
4048
|
+
}
|
|
4049
|
+
return totalSize() / total;
|
|
4050
|
+
}, ...(ngDevMode ? [{ debugName: "rowSizeHint" }] : /* istanbul ignore next */ []));
|
|
3508
4051
|
const placeholdersBefore = computed(() => (isGrid ? start() : 0), ...(ngDevMode ? [{ debugName: "placeholdersBefore" }] : /* istanbul ignore next */ []));
|
|
3509
4052
|
const placeholdersAfter = computed(() => (isGrid ? Math.max(0, config.totalCount() - end()) : 0), ...(ngDevMode ? [{ debugName: "placeholdersAfter" }] : /* istanbul ignore next */ []));
|
|
3510
4053
|
// start/end include overscan. firstVisible/lastVisible strip it back
|
|
@@ -3529,7 +4072,7 @@ function injectRecycler(config) {
|
|
|
3529
4072
|
if (total === 0) {
|
|
3530
4073
|
return 0;
|
|
3531
4074
|
}
|
|
3532
|
-
return
|
|
4075
|
+
return clamp(end() - effectiveOverscan() - 1, 0, total - 1);
|
|
3533
4076
|
}, ...(ngDevMode ? [{ debugName: "lastVisible" }] : /* istanbul ignore next */ []));
|
|
3534
4077
|
const visibleCount = computed(() => {
|
|
3535
4078
|
const total = config.totalCount();
|
|
@@ -3556,7 +4099,7 @@ function injectRecycler(config) {
|
|
|
3556
4099
|
const itemHeight = typeof config.estimateSize === 'number' ? config.estimateSize : config.estimateSize(0);
|
|
3557
4100
|
return Math.ceil(ch / itemHeight);
|
|
3558
4101
|
}, ...(ngDevMode ? [{ debugName: "skeletonSlots" }] : /* istanbul ignore next */ []));
|
|
3559
|
-
const showSkeleton =
|
|
4102
|
+
const showSkeleton = createVisibilityGate(isLoading, computed(() => config.skeletonDelay ?? 0), computed(() => 0));
|
|
3560
4103
|
// previousTotal is a signal, not a mutable let - reactive, no stale-value risk.
|
|
3561
4104
|
const announcementState = signal('', ...(ngDevMode ? [{ debugName: "announcementState" }] : /* istanbul ignore next */ []));
|
|
3562
4105
|
const previousTotal = signal(config.totalCount(), ...(ngDevMode ? [{ debugName: "previousTotal" }] : /* istanbul ignore next */ []));
|
|
@@ -3573,21 +4116,24 @@ function injectRecycler(config) {
|
|
|
3573
4116
|
if (previous === current) {
|
|
3574
4117
|
return;
|
|
3575
4118
|
}
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
4119
|
+
// Copy is read untracked: a language switch must not re-run the
|
|
4120
|
+
// effect and re-voice the region; the next transition speaks it.
|
|
4121
|
+
untracked(() => {
|
|
4122
|
+
const copy = i18n();
|
|
4123
|
+
// Route by result first: a load that settles with zero items is the
|
|
4124
|
+
// empty phrase, no matter which busy status preceded it - "0 results
|
|
4125
|
+
// found" is the filtered phrase, not the empty one.
|
|
4126
|
+
if (current === 'success' && total === 0) {
|
|
4127
|
+
announcementState.set(copy.empty());
|
|
3580
4128
|
}
|
|
3581
|
-
else {
|
|
3582
|
-
|
|
4129
|
+
else if (current === 'success' && (previous === 'loading' || previous === 'refreshing')) {
|
|
4130
|
+
const diff = total - prevTotal;
|
|
4131
|
+
announcementState.set(diff > 0 ? copy.loaded(diff, total) : copy.filtered(total));
|
|
3583
4132
|
}
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
}
|
|
3588
|
-
else if (current === 'success' && total === 0) {
|
|
3589
|
-
announcementState.set(i18n.empty());
|
|
3590
|
-
}
|
|
4133
|
+
else if (current === 'error') {
|
|
4134
|
+
announcementState.set(copy.error());
|
|
4135
|
+
}
|
|
4136
|
+
});
|
|
3591
4137
|
untracked(() => previousTotal.set(total));
|
|
3592
4138
|
});
|
|
3593
4139
|
}
|
|
@@ -3598,12 +4144,15 @@ function injectRecycler(config) {
|
|
|
3598
4144
|
// untracked: previousTotal is bookkeeping, not a dependency
|
|
3599
4145
|
const prevTotal = untracked(() => previousTotal());
|
|
3600
4146
|
const diff = total - prevTotal;
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
4147
|
+
untracked(() => {
|
|
4148
|
+
const copy = i18n();
|
|
4149
|
+
if (prevTotal > 0 && diff > 0) {
|
|
4150
|
+
announcementState.set(copy.loaded(diff, total));
|
|
4151
|
+
}
|
|
4152
|
+
else if (prevTotal > 0 && total === 0) {
|
|
4153
|
+
announcementState.set(copy.empty());
|
|
4154
|
+
}
|
|
4155
|
+
});
|
|
3607
4156
|
untracked(() => previousTotal.set(total));
|
|
3608
4157
|
});
|
|
3609
4158
|
}
|
|
@@ -3705,6 +4254,7 @@ function injectRecycler(config) {
|
|
|
3705
4254
|
offsetBefore,
|
|
3706
4255
|
offsetAfter,
|
|
3707
4256
|
totalSize,
|
|
4257
|
+
rowSizeHint,
|
|
3708
4258
|
placeholdersBefore,
|
|
3709
4259
|
placeholdersAfter,
|
|
3710
4260
|
isLoading,
|
|
@@ -3802,19 +4352,19 @@ class CngxMeasure {
|
|
|
3802
4352
|
/** The absolute index of this item in the full dataset. */
|
|
3803
4353
|
cngxMeasureIndex = input.required(...(ngDevMode ? [{ debugName: "cngxMeasureIndex" }] : /* istanbul ignore next */ []));
|
|
3804
4354
|
el = inject((ElementRef));
|
|
4355
|
+
win = inject(DOCUMENT).defaultView;
|
|
3805
4356
|
constructor() {
|
|
3806
4357
|
effect((onCleanup) => {
|
|
3807
4358
|
const recycler = this.cngxMeasure();
|
|
3808
4359
|
const index = this.cngxMeasureIndex();
|
|
3809
4360
|
const element = this.el.nativeElement;
|
|
3810
4361
|
recycler.measure(index, element);
|
|
3811
|
-
|
|
4362
|
+
// The observed element follows the inputs, so the subscription is
|
|
4363
|
+
// re-wired per effect run - the low-level kernel form, not the
|
|
4364
|
+
// DestroyRef-scoped one.
|
|
4365
|
+
onCleanup(observeResize(this.win, element, 'content-box', () => {
|
|
3812
4366
|
recycler.measure(index, element);
|
|
3813
|
-
});
|
|
3814
|
-
observer.observe(element);
|
|
3815
|
-
onCleanup(() => {
|
|
3816
|
-
observer.disconnect();
|
|
3817
|
-
});
|
|
4367
|
+
}));
|
|
3818
4368
|
});
|
|
3819
4369
|
}
|
|
3820
4370
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxMeasure, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
@@ -3889,6 +4439,380 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
3889
4439
|
}]
|
|
3890
4440
|
}], propDecorators: { cngxVirtualItem: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxVirtualItem", required: true }] }], cngxVirtualItemIndex: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxVirtualItemIndex", required: true }] }] } });
|
|
3891
4441
|
|
|
4442
|
+
/**
|
|
4443
|
+
* Paints a row-aligned skeleton background under a virtualized scroll region so
|
|
4444
|
+
* a fast fling or teleport jump reveals placeholder bars instead of the bare
|
|
4445
|
+
* panel/page surface for the single frame the rendered rows lag `scrollTop`.
|
|
4446
|
+
*
|
|
4447
|
+
* The mechanism is a static CSS layer, not a reactive template: by the time a
|
|
4448
|
+
* `@for` over "uncovered indices" could render, change detection has already
|
|
4449
|
+
* produced the real rows, so the lag frame is never painted reactively. A
|
|
4450
|
+
* `background` on the offset element always paints and also covers teleport
|
|
4451
|
+
* jumps no reactive window can, at zero per-frame cost.
|
|
4452
|
+
*
|
|
4453
|
+
* Host it on the **offset spacer element(s)** - the empty divs (or presentation
|
|
4454
|
+
* `<li>`s) whose height reserves `offsetBefore` / `offsetAfter` - one directive
|
|
4455
|
+
* instance per spacer. Do NOT host it on a `padding-block`ed content element
|
|
4456
|
+
* that also contains the rows: a background paints across the whole padding box,
|
|
4457
|
+
* so it would show through *behind* every rendered row, not just in the gap.
|
|
4458
|
+
* The spacers carry no rows, so the layer is only ever visible where the window
|
|
4459
|
+
* has not caught up.
|
|
4460
|
+
*
|
|
4461
|
+
* The repeat interval keys off a single representative row height: bind the
|
|
4462
|
+
* recycler to read its `rowSizeHint`, or pass an explicit `[rowHeight]`
|
|
4463
|
+
* fallback so the directive is usable standalone. Visuals are driven by
|
|
4464
|
+
* `--cngx-recycler-placeholder-*` CSS custom properties (see
|
|
4465
|
+
* `@cngx/common/theming/components/cngx-recycler-placeholder.css`); the shimmer
|
|
4466
|
+
* drops under `prefers-reduced-motion` via a spec-observable host class.
|
|
4467
|
+
*
|
|
4468
|
+
* ### One instance per offset spacer, keyed off the recycler's rhythm
|
|
4469
|
+
* ```html
|
|
4470
|
+
* <ul>
|
|
4471
|
+
* @if (recycler.offsetBefore(); as before) {
|
|
4472
|
+
* <li role="presentation" aria-hidden="true"
|
|
4473
|
+
* [cngxRecyclerPlaceholder]="recycler" [style.height.px]="before"></li>
|
|
4474
|
+
* }
|
|
4475
|
+
* @for (item of visibleItems(); track item.id) { <li>...</li> }
|
|
4476
|
+
* @if (recycler.offsetAfter(); as after) {
|
|
4477
|
+
* <li role="presentation" aria-hidden="true"
|
|
4478
|
+
* [cngxRecyclerPlaceholder]="recycler" [style.height.px]="after"></li>
|
|
4479
|
+
* }
|
|
4480
|
+
* </ul>
|
|
4481
|
+
* ```
|
|
4482
|
+
*
|
|
4483
|
+
* ### Standalone with an explicit row height
|
|
4484
|
+
* ```html
|
|
4485
|
+
* <div cngxRecyclerPlaceholder [rowHeight]="48"
|
|
4486
|
+
* [style.height.px]="recycler.offsetBefore()"></div>
|
|
4487
|
+
* ```
|
|
4488
|
+
*
|
|
4489
|
+
* @category common/data/recycler
|
|
4490
|
+
* @docsKind primary
|
|
4491
|
+
* @wcag AA
|
|
4492
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/data/recycler/recycler-placeholder.directive.ts
|
|
4493
|
+
* @since 0.1.0
|
|
4494
|
+
* @relatedTo injectRecycler, CngxRecyclerRow, CngxVirtualItem, CngxMeasure
|
|
4495
|
+
* <example-url>http://localhost:4200/#/common/data/recycler/fast-fling-placeholders</example-url>
|
|
4496
|
+
*/
|
|
4497
|
+
class CngxRecyclerPlaceholder {
|
|
4498
|
+
/**
|
|
4499
|
+
* The recycler whose `rowSizeHint` sets the placeholder repeat rhythm.
|
|
4500
|
+
* Optional: the directive also works from an explicit `[rowHeight]`, so this
|
|
4501
|
+
* follows the bridge-input shape (optional + empty-string transform) rather
|
|
4502
|
+
* than `input.required` - a bare `cngxRecyclerPlaceholder` attribute paired
|
|
4503
|
+
* with `[rowHeight]` is a valid, unbound usage.
|
|
4504
|
+
*/
|
|
4505
|
+
recycler = input(undefined, { ...(ngDevMode ? { debugName: "recycler" } : /* istanbul ignore next */ {}), alias: 'cngxRecyclerPlaceholder',
|
|
4506
|
+
transform: (value) => (typeof value === 'string' ? undefined : value) });
|
|
4507
|
+
/** Explicit row height (px) used when no recycler is bound, or as a fallback. */
|
|
4508
|
+
rowHeight = input(undefined, ...(ngDevMode ? [{ debugName: "rowHeight" }] : /* istanbul ignore next */ []));
|
|
4509
|
+
prefersReducedMotion;
|
|
4510
|
+
constructor() {
|
|
4511
|
+
this.prefersReducedMotion = createMediaQuerySignal('(prefers-reduced-motion: reduce)', inject(DestroyRef), inject(DOCUMENT).defaultView);
|
|
4512
|
+
}
|
|
4513
|
+
/**
|
|
4514
|
+
* Representative row height (px) for the repeat interval. The recycler's
|
|
4515
|
+
* `rowSizeHint` wins when it resolves to a positive value; otherwise the
|
|
4516
|
+
* explicit `[rowHeight]` fallback applies.
|
|
4517
|
+
*/
|
|
4518
|
+
resolvedRowHeight = computed(() => {
|
|
4519
|
+
const fromRecycler = this.recycler()?.rowSizeHint() ?? 0;
|
|
4520
|
+
if (fromRecycler > 0) {
|
|
4521
|
+
return fromRecycler;
|
|
4522
|
+
}
|
|
4523
|
+
return this.rowHeight() ?? 0;
|
|
4524
|
+
}, ...(ngDevMode ? [{ debugName: "resolvedRowHeight" }] : /* istanbul ignore next */ []));
|
|
4525
|
+
/**
|
|
4526
|
+
* The `--cngx-recycler-placeholder-row-height` style value. `null` when no
|
|
4527
|
+
* row height resolves, so the registered `@property` default (or an inherited
|
|
4528
|
+
* token from an ancestor mapping) applies instead of a broken `0px` interval.
|
|
4529
|
+
*/
|
|
4530
|
+
rowHeightVar = computed(() => {
|
|
4531
|
+
const height = this.resolvedRowHeight();
|
|
4532
|
+
return height > 0 ? `${height}px` : null;
|
|
4533
|
+
}, ...(ngDevMode ? [{ debugName: "rowHeightVar" }] : /* istanbul ignore next */ []));
|
|
4534
|
+
/** Whether the shimmer host class is applied (dropped under reduced-motion). */
|
|
4535
|
+
showShimmer = computed(() => !this.prefersReducedMotion(), ...(ngDevMode ? [{ debugName: "showShimmer" }] : /* istanbul ignore next */ []));
|
|
4536
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxRecyclerPlaceholder, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
4537
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxRecyclerPlaceholder, isStandalone: true, selector: "[cngxRecyclerPlaceholder]", inputs: { recycler: { classPropertyName: "recycler", publicName: "cngxRecyclerPlaceholder", isSignal: true, isRequired: false, transformFunction: null }, rowHeight: { classPropertyName: "rowHeight", publicName: "rowHeight", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "aria-hidden": "true" }, properties: { "class.cngx-recycler-placeholder--shimmer": "showShimmer()", "style.--cngx-recycler-placeholder-row-height": "rowHeightVar()" }, classAttribute: "cngx-recycler-placeholder" }, ngImport: i0 });
|
|
4538
|
+
}
|
|
4539
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxRecyclerPlaceholder, decorators: [{
|
|
4540
|
+
type: Directive,
|
|
4541
|
+
args: [{
|
|
4542
|
+
selector: '[cngxRecyclerPlaceholder]',
|
|
4543
|
+
standalone: true,
|
|
4544
|
+
host: {
|
|
4545
|
+
class: 'cngx-recycler-placeholder',
|
|
4546
|
+
// The layer is a decorative background on an offset spacer. Hide it from the
|
|
4547
|
+
// a11y tree at the host so it stays out regardless of the call site, not only
|
|
4548
|
+
// when a consumer remembers to add aria-hidden.
|
|
4549
|
+
'aria-hidden': 'true',
|
|
4550
|
+
'[class.cngx-recycler-placeholder--shimmer]': 'showShimmer()',
|
|
4551
|
+
'[style.--cngx-recycler-placeholder-row-height]': 'rowHeightVar()',
|
|
4552
|
+
},
|
|
4553
|
+
}]
|
|
4554
|
+
}], ctorParameters: () => [], propDecorators: { recycler: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxRecyclerPlaceholder", required: false }] }], rowHeight: [{ type: i0.Input, args: [{ isSignal: true, alias: "rowHeight", required: false }] }] } });
|
|
4555
|
+
|
|
4556
|
+
/**
|
|
4557
|
+
* App-wide default placeholder template for `*cngxRecyclerRow`. Middle rung of
|
|
4558
|
+
* the cascade: microsyntax `placeholder:` template wins over this, and this wins
|
|
4559
|
+
* over the built-in imperative `<li>` default. Defaults to `null` (imperative
|
|
4560
|
+
* default applies).
|
|
4561
|
+
*
|
|
4562
|
+
* @category common/data/recycler
|
|
4563
|
+
*/
|
|
4564
|
+
const CNGX_RECYCLER_PLACEHOLDER_ROW = new InjectionToken('CNGX_RECYCLER_PLACEHOLDER_ROW', { providedIn: 'root', factory: () => null });
|
|
4565
|
+
/**
|
|
4566
|
+
* Provides an app-wide default placeholder template for every `*cngxRecyclerRow`
|
|
4567
|
+
* that supplies no `placeholder:` template of its own.
|
|
4568
|
+
*
|
|
4569
|
+
* @category common/data/recycler
|
|
4570
|
+
*/
|
|
4571
|
+
function provideRecyclerPlaceholderRow(template) {
|
|
4572
|
+
return { provide: CNGX_RECYCLER_PLACEHOLDER_ROW, useValue: template };
|
|
4573
|
+
}
|
|
4574
|
+
/**
|
|
4575
|
+
* Per-window-position render switch for a sparse/windowed recycler: renders the
|
|
4576
|
+
* consumer's real-row template when the sliced item is defined, and a
|
|
4577
|
+
* placeholder branch when the item is still `undefined` (loaded window, data
|
|
4578
|
+
* not yet resolved).
|
|
4579
|
+
*
|
|
4580
|
+
* Mirrors the `*cngxAsync` structural-directive shape (own `TemplateRef` +
|
|
4581
|
+
* microsyntax alternate template + `ngTemplateContextGuard`). The switch axis is
|
|
4582
|
+
* data availability, not async status, so the two are siblings, not the same
|
|
4583
|
+
* class. Unlike `*cngxAsync` (which clears on every switch) the real-row view is
|
|
4584
|
+
* cached and re-attached across a placeholder detour, so a
|
|
4585
|
+
* defined -> undefined -> defined flip never remounts the expensive real row.
|
|
4586
|
+
*
|
|
4587
|
+
* The placeholder branch resolves through a 3-stage cascade: the microsyntax
|
|
4588
|
+
* `placeholder:` template, then {@link CNGX_RECYCLER_PLACEHOLDER_ROW}, then a
|
|
4589
|
+
* built-in imperative `<li>` default. The default assumes a `<ul>`/`<li>` list;
|
|
4590
|
+
* a non-`<li>` container (`<div role="list">`) supplies a `placeholder:`
|
|
4591
|
+
* template or the config token instead.
|
|
4592
|
+
*
|
|
4593
|
+
* The two placeholder layers are orthogonal and non-overlapping by
|
|
4594
|
+
* construction: {@link CngxRecyclerPlaceholder} paints a decorative background
|
|
4595
|
+
* on the offset spacers (indices outside the rendered window), while this
|
|
4596
|
+
* directive fills holes inside the window whose item is still `undefined`.
|
|
4597
|
+
*
|
|
4598
|
+
* ### Windowed list with the built-in placeholder row
|
|
4599
|
+
* ```html
|
|
4600
|
+
* <ul>
|
|
4601
|
+
* @for (item of visibleItems(); track item?.id ?? ('ph:' + (recycler.start() + $index)); let i = $index) {
|
|
4602
|
+
* <li *cngxRecyclerRow="item; index: recycler.start() + i; recycler: recycler; let row">
|
|
4603
|
+
* {{ row?.name }}
|
|
4604
|
+
* </li>
|
|
4605
|
+
* }
|
|
4606
|
+
* </ul>
|
|
4607
|
+
* ```
|
|
4608
|
+
*
|
|
4609
|
+
* ### Custom placeholder template
|
|
4610
|
+
* ```html
|
|
4611
|
+
* <ul>
|
|
4612
|
+
* @for (item of visibleItems(); track item?.id ?? ('ph:' + (recycler.start() + $index)); let i = $index) {
|
|
4613
|
+
* <li *cngxRecyclerRow="item; index: recycler.start() + i; recycler: recycler; placeholder: ph; let row">
|
|
4614
|
+
* {{ row?.name }}
|
|
4615
|
+
* </li>
|
|
4616
|
+
* }
|
|
4617
|
+
* <ng-template #ph let-index let-setSize="setSize">
|
|
4618
|
+
* <li role="listitem" aria-busy="true" [attr.aria-posinset]="index + 1" [attr.aria-setsize]="setSize">
|
|
4619
|
+
* Loading row {{ index + 1 }}
|
|
4620
|
+
* </li>
|
|
4621
|
+
* </ng-template>
|
|
4622
|
+
* </ul>
|
|
4623
|
+
* ```
|
|
4624
|
+
*
|
|
4625
|
+
* @category common/data/recycler
|
|
4626
|
+
* @docsKind primary
|
|
4627
|
+
* @wcag AA
|
|
4628
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/data/recycler/recycler-row.directive.ts
|
|
4629
|
+
* @since 0.1.0
|
|
4630
|
+
* @relatedTo injectRecycler, CngxRecyclerPlaceholder, CngxVirtualItem, CngxMeasure
|
|
4631
|
+
* <example-url>http://localhost:4200/#/common/data/recycler/windowed-data-availability</example-url>
|
|
4632
|
+
*/
|
|
4633
|
+
class CngxRecyclerRow {
|
|
4634
|
+
vcr = inject(ViewContainerRef);
|
|
4635
|
+
rowTpl = inject(TemplateRef);
|
|
4636
|
+
renderer = inject(Renderer2);
|
|
4637
|
+
configTpl = inject(CNGX_RECYCLER_PLACEHOLDER_ROW);
|
|
4638
|
+
/** The sliced item at this window position. `undefined` selects the placeholder branch. */
|
|
4639
|
+
cngxRecyclerRow = input(undefined, ...(ngDevMode ? [{ debugName: "cngxRecyclerRow" }] : /* istanbul ignore next */ []));
|
|
4640
|
+
/** Absolute dataset index of this slot (`recycler.start() + $index`). */
|
|
4641
|
+
cngxRecyclerRowIndex = input.required(...(ngDevMode ? [{ debugName: "cngxRecyclerRowIndex" }] : /* istanbul ignore next */ []));
|
|
4642
|
+
/** The recycler driving the window, read for `rowSizeHint` (-> `top`) and `ariaSetSize`. */
|
|
4643
|
+
cngxRecyclerRowRecycler = input.required(...(ngDevMode ? [{ debugName: "cngxRecyclerRowRecycler" }] : /* istanbul ignore next */ []));
|
|
4644
|
+
/** Optional placeholder template for the `undefined` branch. Context: {@link CngxRecyclerRowContext}. */
|
|
4645
|
+
cngxRecyclerRowPlaceholder = input(undefined, ...(ngDevMode ? [{ debugName: "cngxRecyclerRowPlaceholder" }] : /* istanbul ignore next */ []));
|
|
4646
|
+
// Plain fields, not signals: read and written only inside the render effect.
|
|
4647
|
+
// As signals they would feed the effect's own dependency graph and double-fire
|
|
4648
|
+
// per branch switch (the trap documented in async.directive.ts).
|
|
4649
|
+
currentBranch = 'none';
|
|
4650
|
+
rowViewRef = null;
|
|
4651
|
+
placeholderViewRef = null;
|
|
4652
|
+
defaultEl = null;
|
|
4653
|
+
constructor() {
|
|
4654
|
+
effect(() => {
|
|
4655
|
+
const item = this.cngxRecyclerRow();
|
|
4656
|
+
if (item === undefined) {
|
|
4657
|
+
// Placeholder branch tracks index + ariaSetSize (via buildPlaceholderContext)
|
|
4658
|
+
// so the announced position/size stay live while the slot remains unloaded
|
|
4659
|
+
// across a window shift or an infinite-scroll setSize growth - Pillar 2
|
|
4660
|
+
// keeps a11y in the reactive graph, never a one-time write. The row branch
|
|
4661
|
+
// tracks only the item value; the placeholder template ref is read untracked.
|
|
4662
|
+
this.showPlaceholder(this.buildPlaceholderContext());
|
|
4663
|
+
}
|
|
4664
|
+
else {
|
|
4665
|
+
this.showRow(item);
|
|
4666
|
+
}
|
|
4667
|
+
});
|
|
4668
|
+
inject(DestroyRef).onDestroy(() => {
|
|
4669
|
+
// The cached row view may be detached (not owned by the VCR), so the VCR
|
|
4670
|
+
// will not tear it down; destroy both views explicitly, guarding the
|
|
4671
|
+
// already-destroyed case when the VCR got there first.
|
|
4672
|
+
if (this.rowViewRef && !this.rowViewRef.destroyed) {
|
|
4673
|
+
this.rowViewRef.destroy();
|
|
4674
|
+
}
|
|
4675
|
+
this.teardownPlaceholder();
|
|
4676
|
+
});
|
|
4677
|
+
}
|
|
4678
|
+
showRow(item) {
|
|
4679
|
+
if (this.currentBranch === 'row') {
|
|
4680
|
+
this.setRowContext(item);
|
|
4681
|
+
this.rowViewRef?.markForCheck();
|
|
4682
|
+
return;
|
|
4683
|
+
}
|
|
4684
|
+
this.teardownPlaceholder();
|
|
4685
|
+
if (this.rowViewRef) {
|
|
4686
|
+
this.setRowContext(item);
|
|
4687
|
+
this.vcr.insert(this.rowViewRef);
|
|
4688
|
+
this.rowViewRef.markForCheck();
|
|
4689
|
+
}
|
|
4690
|
+
else {
|
|
4691
|
+
this.rowViewRef = this.vcr.createEmbeddedView(this.rowTpl, {
|
|
4692
|
+
$implicit: item,
|
|
4693
|
+
cngxRecyclerRow: item,
|
|
4694
|
+
});
|
|
4695
|
+
}
|
|
4696
|
+
this.currentBranch = 'row';
|
|
4697
|
+
}
|
|
4698
|
+
showPlaceholder(ctx) {
|
|
4699
|
+
if (this.currentBranch === 'placeholder') {
|
|
4700
|
+
this.refreshPlaceholder(ctx);
|
|
4701
|
+
return;
|
|
4702
|
+
}
|
|
4703
|
+
this.detachRow();
|
|
4704
|
+
this.renderPlaceholder(ctx);
|
|
4705
|
+
this.currentBranch = 'placeholder';
|
|
4706
|
+
}
|
|
4707
|
+
setRowContext(item) {
|
|
4708
|
+
if (this.rowViewRef) {
|
|
4709
|
+
this.rowViewRef.context.$implicit = item;
|
|
4710
|
+
this.rowViewRef.context.cngxRecyclerRow = item;
|
|
4711
|
+
}
|
|
4712
|
+
}
|
|
4713
|
+
// Remove the cached row view from the container WITHOUT destroying it, so the
|
|
4714
|
+
// next 'row' branch re-attaches the same EmbeddedViewRef (no remount).
|
|
4715
|
+
detachRow() {
|
|
4716
|
+
if (!this.rowViewRef) {
|
|
4717
|
+
return;
|
|
4718
|
+
}
|
|
4719
|
+
const at = this.vcr.indexOf(this.rowViewRef);
|
|
4720
|
+
if (at !== -1) {
|
|
4721
|
+
this.vcr.detach(at);
|
|
4722
|
+
}
|
|
4723
|
+
}
|
|
4724
|
+
teardownPlaceholder() {
|
|
4725
|
+
if (this.placeholderViewRef) {
|
|
4726
|
+
this.placeholderViewRef.destroy();
|
|
4727
|
+
this.placeholderViewRef = null;
|
|
4728
|
+
}
|
|
4729
|
+
this.removeDefault();
|
|
4730
|
+
}
|
|
4731
|
+
renderPlaceholder(ctx) {
|
|
4732
|
+
const tpl = untracked(() => this.cngxRecyclerRowPlaceholder()) ?? this.configTpl ?? null;
|
|
4733
|
+
if (tpl) {
|
|
4734
|
+
this.placeholderViewRef = this.vcr.createEmbeddedView(tpl, ctx);
|
|
4735
|
+
}
|
|
4736
|
+
else {
|
|
4737
|
+
this.stampDefault(ctx);
|
|
4738
|
+
}
|
|
4739
|
+
}
|
|
4740
|
+
// Slot stayed unloaded but its index/setSize moved: refresh the live a11y
|
|
4741
|
+
// position/size in place - custom template context or default element attrs -
|
|
4742
|
+
// without remounting the placeholder.
|
|
4743
|
+
refreshPlaceholder(ctx) {
|
|
4744
|
+
if (this.placeholderViewRef) {
|
|
4745
|
+
const context = this.placeholderViewRef.context;
|
|
4746
|
+
context.$implicit = ctx.$implicit;
|
|
4747
|
+
context.index = ctx.index;
|
|
4748
|
+
context.top = ctx.top;
|
|
4749
|
+
context.setSize = ctx.setSize;
|
|
4750
|
+
this.placeholderViewRef.markForCheck();
|
|
4751
|
+
}
|
|
4752
|
+
else if (this.defaultEl) {
|
|
4753
|
+
this.applyDefaultAttrs(this.defaultEl, ctx);
|
|
4754
|
+
}
|
|
4755
|
+
}
|
|
4756
|
+
// Terminal fallback: a module-level TemplateRef cannot exist, so the built-in
|
|
4757
|
+
// default is one imperative <li> reusing the shipped `cngx-recycler-placeholder`
|
|
4758
|
+
// ghost-row CSS. It holds a real dataset position, so it stays in the a11y tree
|
|
4759
|
+
// (aria-busy / role=listitem / posinset / setsize) - never aria-hidden.
|
|
4760
|
+
stampDefault(ctx) {
|
|
4761
|
+
const anchor = this.vcr.element.nativeElement;
|
|
4762
|
+
const parent = this.renderer.parentNode(anchor);
|
|
4763
|
+
if (!parent) {
|
|
4764
|
+
return;
|
|
4765
|
+
}
|
|
4766
|
+
const li = this.renderer.createElement('li');
|
|
4767
|
+
this.renderer.addClass(li, 'cngx-recycler-placeholder');
|
|
4768
|
+
this.renderer.setAttribute(li, 'role', 'listitem');
|
|
4769
|
+
this.renderer.setAttribute(li, 'aria-busy', 'true');
|
|
4770
|
+
this.applyDefaultAttrs(li, ctx);
|
|
4771
|
+
this.renderer.insertBefore(parent, li, anchor);
|
|
4772
|
+
this.defaultEl = li;
|
|
4773
|
+
}
|
|
4774
|
+
applyDefaultAttrs(li, ctx) {
|
|
4775
|
+
const height = untracked(() => this.cngxRecyclerRowRecycler().rowSizeHint());
|
|
4776
|
+
this.renderer.setAttribute(li, 'aria-posinset', String(ctx.index + 1));
|
|
4777
|
+
this.renderer.setAttribute(li, 'aria-setsize', String(ctx.setSize));
|
|
4778
|
+
this.renderer.setStyle(li, 'height', `${height}px`);
|
|
4779
|
+
this.renderer.setStyle(li, '--cngx-recycler-placeholder-row-height', `${height}px`);
|
|
4780
|
+
}
|
|
4781
|
+
removeDefault() {
|
|
4782
|
+
if (!this.defaultEl) {
|
|
4783
|
+
return;
|
|
4784
|
+
}
|
|
4785
|
+
const parent = this.renderer.parentNode(this.defaultEl);
|
|
4786
|
+
if (parent) {
|
|
4787
|
+
this.renderer.removeChild(parent, this.defaultEl);
|
|
4788
|
+
}
|
|
4789
|
+
this.defaultEl = null;
|
|
4790
|
+
}
|
|
4791
|
+
// Called only from the placeholder branch of the render effect: reading index
|
|
4792
|
+
// + ariaSetSize here (tracked) is what keeps the announced position/size
|
|
4793
|
+
// reactive. rowSizeHint is a stable layout hint, read untracked for `top`.
|
|
4794
|
+
buildPlaceholderContext() {
|
|
4795
|
+
const index = this.cngxRecyclerRowIndex();
|
|
4796
|
+
const recycler = this.cngxRecyclerRowRecycler();
|
|
4797
|
+
const setSize = recycler.ariaSetSize();
|
|
4798
|
+
const top = untracked(() => recycler.rowSizeHint()) * index;
|
|
4799
|
+
return { $implicit: index, index, top, setSize };
|
|
4800
|
+
}
|
|
4801
|
+
/** Narrows the directive's own template context to the loaded item type. */
|
|
4802
|
+
static ngTemplateContextGuard(_dir, _ctx) {
|
|
4803
|
+
return true;
|
|
4804
|
+
}
|
|
4805
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxRecyclerRow, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
4806
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxRecyclerRow, isStandalone: true, selector: "[cngxRecyclerRow]", inputs: { cngxRecyclerRow: { classPropertyName: "cngxRecyclerRow", publicName: "cngxRecyclerRow", isSignal: true, isRequired: false, transformFunction: null }, cngxRecyclerRowIndex: { classPropertyName: "cngxRecyclerRowIndex", publicName: "cngxRecyclerRowIndex", isSignal: true, isRequired: true, transformFunction: null }, cngxRecyclerRowRecycler: { classPropertyName: "cngxRecyclerRowRecycler", publicName: "cngxRecyclerRowRecycler", isSignal: true, isRequired: true, transformFunction: null }, cngxRecyclerRowPlaceholder: { classPropertyName: "cngxRecyclerRowPlaceholder", publicName: "cngxRecyclerRowPlaceholder", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0 });
|
|
4807
|
+
}
|
|
4808
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxRecyclerRow, decorators: [{
|
|
4809
|
+
type: Directive,
|
|
4810
|
+
args: [{
|
|
4811
|
+
selector: '[cngxRecyclerRow]',
|
|
4812
|
+
standalone: true,
|
|
4813
|
+
}]
|
|
4814
|
+
}], ctorParameters: () => [], propDecorators: { cngxRecyclerRow: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxRecyclerRow", required: false }] }], cngxRecyclerRowIndex: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxRecyclerRowIndex", required: true }] }], cngxRecyclerRowRecycler: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxRecyclerRowRecycler", required: true }] }], cngxRecyclerRowPlaceholder: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxRecyclerRowPlaceholder", required: false }] }] } });
|
|
4815
|
+
|
|
3892
4816
|
/**
|
|
3893
4817
|
* Convenience component that renders the `aria-live="polite"` region
|
|
3894
4818
|
* for recycler SR announcements. Eliminates manual boilerplate.
|
|
@@ -3944,7 +4868,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
3944
4868
|
* Must be called in an injection context (constructor or field initializer)
|
|
3945
4869
|
* **on the component that hosts both the recycler's scroll container and the
|
|
3946
4870
|
* `CngxRovingTabindex` directive**. The injected `ElementRef` is used to query
|
|
3947
|
-
* `[data-cngx-recycle-index]`
|
|
4871
|
+
* `[data-cngx-recycle-index]` - calling from a child component would query the
|
|
3948
4872
|
* wrong subtree.
|
|
3949
4873
|
*
|
|
3950
4874
|
* ```typescript
|
|
@@ -3968,7 +4892,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
3968
4892
|
function connectRecyclerToRoving(recycler, roving) {
|
|
3969
4893
|
const hostEl = inject(ElementRef).nativeElement;
|
|
3970
4894
|
// Debounce scrollToIndex via rAF to avoid scroll jitter on rapid keypresses.
|
|
3971
|
-
// Each keypress overwrites pendingFocus
|
|
4895
|
+
// Each keypress overwrites pendingFocus - only the latest target is scrolled to.
|
|
3972
4896
|
let scrollRafId = null;
|
|
3973
4897
|
effect((onCleanup) => {
|
|
3974
4898
|
const target = roving.pendingFocus();
|
|
@@ -4003,7 +4927,7 @@ function connectRecyclerToRoving(recycler, roving) {
|
|
|
4003
4927
|
if (target == null || target < s || target >= e) {
|
|
4004
4928
|
return;
|
|
4005
4929
|
}
|
|
4006
|
-
// Target is within rendered range
|
|
4930
|
+
// Target is within rendered range - DOM will be updated after CD.
|
|
4007
4931
|
// Use rAF to wait for Angular's rendering pass to complete.
|
|
4008
4932
|
focusRafId = requestAnimationFrame(() => {
|
|
4009
4933
|
focusRafId = null;
|
|
@@ -4042,7 +4966,7 @@ function connectRecyclerToRoving(recycler, roving) {
|
|
|
4042
4966
|
*
|
|
4043
4967
|
* Unlike {@link /projects/common/data/src/recycler/connect-recycler-roving.ts
|
|
4044
4968
|
* connectRecyclerToRoving}, we don't re-focus a DOM element after the
|
|
4045
|
-
* scroll
|
|
4969
|
+
* scroll - AD doesn't move real focus, it only rebinds
|
|
4046
4970
|
* `aria-activedescendant`. Once the target index enters the rendered
|
|
4047
4971
|
* range, the `[attr.aria-activedescendant]` binding on the combobox
|
|
4048
4972
|
* trigger resolves to the now-present option element for free.
|
|
@@ -4054,7 +4978,7 @@ function connectRecyclerToRoving(recycler, roving) {
|
|
|
4054
4978
|
* ```typescript
|
|
4055
4979
|
* @Component({
|
|
4056
4980
|
* hostDirectives: [
|
|
4057
|
-
* { directive: CngxActiveDescendant, inputs: ['items', 'virtualCount'] },
|
|
4981
|
+
* { directive: CngxActiveDescendant, inputs: ['items', 'virtualCount', 'windowStart'] },
|
|
4058
4982
|
* ],
|
|
4059
4983
|
* })
|
|
4060
4984
|
* class MyVirtualSelect {
|
|
@@ -4101,7 +5025,7 @@ function connectRecyclerToActiveDescendant(recycler, ad) {
|
|
|
4101
5025
|
/**
|
|
4102
5026
|
* Factory for the commit controller.
|
|
4103
5027
|
*
|
|
4104
|
-
* Plain function, not a class
|
|
5028
|
+
* Plain function, not a class - matches the rest of the repo
|
|
4105
5029
|
* (`createManualState`, `createAsyncState`, `createTransitionTracker`).
|
|
4106
5030
|
* See `reference_api_prefix_convention.md`.
|
|
4107
5031
|
*
|
|
@@ -4120,17 +5044,24 @@ function createCommitController() {
|
|
|
4120
5044
|
isCommitting: computed(() => slot.isPending()),
|
|
4121
5045
|
intendedValue: intendedState.asReadonly(),
|
|
4122
5046
|
begin(runner, intended, previous, handlers) {
|
|
4123
|
-
//
|
|
4124
|
-
//
|
|
4125
|
-
|
|
5047
|
+
// bump commitId BEFORE tearing down the previous runner: a runner that
|
|
5048
|
+
// cancels synchronously would otherwise still pass the supersede check
|
|
5049
|
+
// and fire its callbacks after all
|
|
4126
5050
|
const id = ++commitId;
|
|
5051
|
+
active?.cancel();
|
|
4127
5052
|
intendedState.set(intended);
|
|
4128
5053
|
slot.set('pending');
|
|
4129
|
-
|
|
5054
|
+
// A runner may settle synchronously, i.e. before its handle is even
|
|
5055
|
+
// returned. The settled flag keeps such a finished handle out of
|
|
5056
|
+
// `active`, so a later begin()/cancel() never calls cancel() on a
|
|
5057
|
+
// completed runner (CngxCommitHandle does not require idempotence).
|
|
5058
|
+
let settled = false;
|
|
5059
|
+
const handle = runner({
|
|
4130
5060
|
onSuccess: (committed) => {
|
|
4131
5061
|
if (id !== commitId) {
|
|
4132
5062
|
return;
|
|
4133
5063
|
}
|
|
5064
|
+
settled = true;
|
|
4134
5065
|
slot.setSuccess(committed);
|
|
4135
5066
|
active = null;
|
|
4136
5067
|
handlers.onSuccess(committed);
|
|
@@ -4139,17 +5070,26 @@ function createCommitController() {
|
|
|
4139
5070
|
if (id !== commitId) {
|
|
4140
5071
|
return;
|
|
4141
5072
|
}
|
|
5073
|
+
settled = true;
|
|
4142
5074
|
slot.setError(err);
|
|
4143
5075
|
active = null;
|
|
4144
5076
|
handlers.onError(err, previous);
|
|
4145
5077
|
},
|
|
4146
5078
|
});
|
|
5079
|
+
active = settled ? null : handle;
|
|
4147
5080
|
},
|
|
4148
|
-
cancel() {
|
|
5081
|
+
cancel(options) {
|
|
5082
|
+
// bump first: callbacks of a synchronously-cancelling runner must
|
|
5083
|
+
// already see themselves superseded
|
|
5084
|
+
commitId++;
|
|
4149
5085
|
active?.cancel();
|
|
4150
5086
|
active = null;
|
|
4151
|
-
|
|
4152
|
-
|
|
5087
|
+
if (options?.settle) {
|
|
5088
|
+
// Full settle: idle status plus cleared data/error, so a stale
|
|
5089
|
+
// rejection cannot resurface on the next commit window.
|
|
5090
|
+
slot.reset();
|
|
5091
|
+
intendedState.set(undefined);
|
|
5092
|
+
}
|
|
4153
5093
|
},
|
|
4154
5094
|
};
|
|
4155
5095
|
}
|
|
@@ -4191,7 +5131,7 @@ const CNGX_COMMIT_CONTROLLER_FACTORY = new InjectionToken('CngxCommitControllerF
|
|
|
4191
5131
|
* (`<mat-tab-group>`, `<mat-stepper>`, etc.).
|
|
4192
5132
|
*
|
|
4193
5133
|
* Lives at Level 2 in `@cngx/common/data` parallel to
|
|
4194
|
-
* `createCommitController`. Material types never enter the signature
|
|
5134
|
+
* `createCommitController`. Material types never enter the signature -
|
|
4195
5135
|
* the caller maps Material-specific events and property accessors to a
|
|
4196
5136
|
* host-agnostic shape at the directive boundary.
|
|
4197
5137
|
*
|
|
@@ -4205,7 +5145,7 @@ const CNGX_COMMIT_CONTROLLER_FACTORY = new InjectionToken('CngxCommitControllerF
|
|
|
4205
5145
|
* 2. A Material→presenter subscription that forwards each
|
|
4206
5146
|
* `selectionChange$` emission to `onMaterialSelection`
|
|
4207
5147
|
* (equality-guarded against `presenterIndex()` so a Material event
|
|
4208
|
-
* whose value already matches the presenter is dropped
|
|
5148
|
+
* whose value already matches the presenter is dropped - closes
|
|
4209
5149
|
* the re-entrancy loop).
|
|
4210
5150
|
*
|
|
4211
5151
|
* Both sides clean up via `destroyRef`.
|
|
@@ -4233,7 +5173,7 @@ const CNGX_COMMIT_CONTROLLER_FACTORY = new InjectionToken('CngxCommitControllerF
|
|
|
4233
5173
|
* load-bearing for an ASYNC commit-action: Material emits the echo a
|
|
4234
5174
|
* microtask later, by which point the commit may have advanced
|
|
4235
5175
|
* `presenterIndex`, so an equality-only guard (`presenterIndex() ===
|
|
4236
|
-
* idx`) would FAIL to drop the echo
|
|
5176
|
+
* idx`) would FAIL to drop the echo - it would re-enter the subscriber
|
|
4237
5177
|
* and ping-pong against the in-flight navigation (the demo freezes).
|
|
4238
5178
|
* Matching the echo by the value we wrote drops it regardless of where
|
|
4239
5179
|
* the presenter has moved.
|
|
@@ -4305,5 +5245,5 @@ function createMaterialBidirectionalSync(opts) {
|
|
|
4305
5245
|
* Generated bundle index. Do not edit.
|
|
4306
5246
|
*/
|
|
4307
5247
|
|
|
4308
|
-
export { CNGX_ASYNC_LABEL, CNGX_ASYNC_SKIP, CNGX_BUCKET_PAGINATE_HOST, CNGX_COMMIT_CONTROLLER_FACTORY, CNGX_RECYCLER_I18N, CNGX_STAT, CngxAsync, CngxAsyncRegistry, CngxBucketPaginate, CngxDataSource, CngxDelta, CngxFilter, CngxFilterChip, CngxFilterChips, CngxGoal, CngxMeasure, CngxMetric, CngxPaginate, CngxPaginateResetOn, CngxPaginateRouting, CngxRecyclerAnnouncer, CngxSmartDataSource, CngxSort, CngxSortHeader, CngxStat, CngxStatCaption, CngxStatDelta, CngxStatLabel, CngxStatValue,
|
|
5248
|
+
export { CNGX_ASYNC_LABEL, CNGX_ASYNC_SKIP, CNGX_BUCKET_PAGINATE_HOST, CNGX_COMMIT_CONTROLLER_FACTORY, CNGX_KPI_I18N, CNGX_KPI_LANGUAGE_EN, CNGX_RECYCLER_I18N, CNGX_RECYCLER_LANGUAGE_EN, CNGX_RECYCLER_PLACEHOLDER_ROW, CNGX_STAT, CngxAsync, CngxAsyncBoundary, CngxAsyncRegistry, CngxBucketPaginate, CngxDataSource, CngxDelta, CngxFilter, CngxFilterChip, CngxFilterChips, CngxGoal, CngxMeasure, CngxMetric, CngxPaginate, CngxPaginateResetOn, CngxPaginateRouting, CngxRecyclerAnnouncer, CngxRecyclerPlaceholder, CngxRecyclerRow, CngxSmartDataSource, CngxSort, CngxSortHeader, CngxStat, CngxStatCaption, CngxStatCoordinator, CngxStatDelta, CngxStatLabel, CngxStatValue, CngxTrend, CngxVirtualItem, cngxAsyncInterceptor, connectPaginateEmit, connectPaginateResetOn, connectRecyclerToActiveDescendant, connectRecyclerToRoving, createAsyncState, createCommitController, createForwardedAsyncState, createManualState, createMaterialBidirectionalSync, createSortHeaderState, fromHttpResource, fromResource, injectAsyncRegistry, injectAsyncState, injectDataSource, injectKpiI18n, injectLatencyProbe, injectRecycler, injectSmartDataSource, provideAsyncHttpObservability, provideAsyncRegistry, provideKpiI18n, provideRecyclerI18n, provideRecyclerPlaceholderRow, resolveAsyncView, tapAsyncProgress, tapAsyncState, tapHttpAsyncState, withAsyncLabel, withAsyncSkip, withKpiI18nLabels, withRecyclerI18nLabels };
|
|
4309
5249
|
//# sourceMappingURL=cngx-common-data.mjs.map
|