@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,11 +1,13 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { input, output, inject, ElementRef, signal, afterNextRender, effect, Directive, computed, DestroyRef,
|
|
3
|
-
import { DOCUMENT, NgTemplateOutlet } from '@angular/common';
|
|
4
|
-
import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';
|
|
5
|
-
import { fromEvent } from 'rxjs';
|
|
2
|
+
import { input, output, inject, ElementRef, signal, afterNextRender, effect, Directive, computed, untracked, isDevMode, DestroyRef, InjectionToken, PLATFORM_ID, model, TemplateRef, contentChild, ViewEncapsulation, ChangeDetectionStrategy, Component } from '@angular/core';
|
|
3
|
+
import { DOCUMENT, isPlatformBrowser, NgTemplateOutlet } from '@angular/common';
|
|
4
|
+
import { toObservable, outputToObservable, takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';
|
|
5
|
+
import { switchMap, fromEvent } from 'rxjs';
|
|
6
|
+
import { createTransitionTracker, observeMediaQuery, createMediaQuerySignal, coerceSignal, createOverrideMerge } from '@cngx/core/utils';
|
|
6
7
|
import * as i1 from '@cngx/common/a11y';
|
|
7
8
|
import { CngxFocusTrap } from '@cngx/common/a11y';
|
|
8
9
|
import { Router, ActivatedRoute } from '@angular/router';
|
|
10
|
+
import { createLanguageSection } from '@cngx/core/i18n';
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
13
|
* Manages backdrop overlay behavior: visibility, click-to-close, and
|
|
@@ -13,7 +15,12 @@ import { Router, ActivatedRoute } from '@angular/router';
|
|
|
13
15
|
*
|
|
14
16
|
* When visible, all sibling elements of the host receive the `inert`
|
|
15
17
|
* attribute, preventing focus and interaction behind the backdrop.
|
|
16
|
-
* This is critical for a11y in modal/drawer overlays.
|
|
18
|
+
* This is critical for a11y in modal/drawer overlays. A sibling drawer
|
|
19
|
+
* panel (`.cngx-drawer-panel`) is excluded - it is the surface the
|
|
20
|
+
* backdrop guards, not content behind it. Siblings that already carry
|
|
21
|
+
* `inert` are left alone, so a consumer-set `inert` survives the
|
|
22
|
+
* show/hide cycle. The sibling set is re-queried on every show, so
|
|
23
|
+
* siblings rendered after init are covered too.
|
|
17
24
|
*
|
|
18
25
|
* The directive is purely behavioral - it toggles the
|
|
19
26
|
* `.cngx-backdrop--visible` class and `aria-hidden` attribute. Visual
|
|
@@ -75,18 +82,28 @@ class CngxBackdrop {
|
|
|
75
82
|
/** Emitted when the backdrop is clicked (and `closeOnClick` is true). */
|
|
76
83
|
backdropClick = output();
|
|
77
84
|
el = inject((ElementRef));
|
|
78
|
-
|
|
85
|
+
domReady = signal(false, ...(ngDevMode ? [{ debugName: "domReady" }] : /* istanbul ignore next */ []));
|
|
79
86
|
constructor() {
|
|
80
|
-
afterNextRender(() =>
|
|
87
|
+
afterNextRender(() => this.domReady.set(true));
|
|
88
|
+
effect((onCleanup) => {
|
|
89
|
+
if (!this.domReady() || !this.visible()) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
// Re-queried on every show: siblings rendered after init (@if/@defer)
|
|
93
|
+
// must be inerted too. The drawer panel keeps working - it is the
|
|
94
|
+
// surface the backdrop guards, not content behind it.
|
|
81
95
|
const el = this.el.nativeElement;
|
|
82
96
|
const parent = el.parentElement;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
97
|
+
// skip siblings that are already inert - removing it on cleanup
|
|
98
|
+
// would clobber a consumer-set attribute that predated the show
|
|
99
|
+
const targets = parent
|
|
100
|
+
? Array.from(parent.children).filter((child) => child !== el &&
|
|
101
|
+
child instanceof HTMLElement &&
|
|
102
|
+
!child.classList.contains('cngx-drawer-panel') &&
|
|
103
|
+
!child.hasAttribute('inert'))
|
|
104
|
+
: [];
|
|
105
|
+
targets.forEach((target) => target.setAttribute('inert', ''));
|
|
106
|
+
onCleanup(() => targets.forEach((target) => target.removeAttribute('inert')));
|
|
90
107
|
});
|
|
91
108
|
}
|
|
92
109
|
/** @internal */
|
|
@@ -96,7 +113,7 @@ class CngxBackdrop {
|
|
|
96
113
|
}
|
|
97
114
|
}
|
|
98
115
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxBackdrop, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
99
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxBackdrop, isStandalone: true, selector: "[cngxBackdrop]", inputs: { visible: { classPropertyName: "visible", publicName: "cngxBackdrop", isSignal: true, isRequired: false, transformFunction: null }, closeOnClick: { classPropertyName: "closeOnClick", publicName: "closeOnClick", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { backdropClick: "backdropClick" }, host: { listeners: { "click": "handleHostClick()" }, properties: { "class.cngx-backdrop--visible": "visible()"
|
|
116
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxBackdrop, isStandalone: true, selector: "[cngxBackdrop]", inputs: { visible: { classPropertyName: "visible", publicName: "cngxBackdrop", isSignal: true, isRequired: false, transformFunction: null }, closeOnClick: { classPropertyName: "closeOnClick", publicName: "closeOnClick", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { backdropClick: "backdropClick" }, host: { attributes: { "aria-hidden": "true" }, listeners: { "click": "handleHostClick()" }, properties: { "class.cngx-backdrop--visible": "visible()" } }, exportAs: ["cngxBackdrop"], ngImport: i0 });
|
|
100
117
|
}
|
|
101
118
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxBackdrop, decorators: [{
|
|
102
119
|
type: Directive,
|
|
@@ -106,7 +123,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
106
123
|
standalone: true,
|
|
107
124
|
host: {
|
|
108
125
|
'[class.cngx-backdrop--visible]': 'visible()',
|
|
109
|
-
'
|
|
126
|
+
'aria-hidden': 'true',
|
|
110
127
|
'(click)': 'handleHostClick()',
|
|
111
128
|
},
|
|
112
129
|
}]
|
|
@@ -164,8 +181,11 @@ class CngxDrawer {
|
|
|
164
181
|
openedChange = output();
|
|
165
182
|
/** Emitted when the drawer closes. Convenience shorthand for close-only listeners. */
|
|
166
183
|
closed = output();
|
|
167
|
-
/** Opens the drawer. */
|
|
184
|
+
/** Opens the drawer. No-op when already open. */
|
|
168
185
|
open() {
|
|
186
|
+
if (this.opened()) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
169
189
|
this.openedState.set(true);
|
|
170
190
|
this.openedChange.emit(true);
|
|
171
191
|
}
|
|
@@ -211,10 +231,19 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
211
231
|
* the `[enabled]` and `[autoFocus]` inputs from the template.
|
|
212
232
|
*
|
|
213
233
|
* Optionally closes the drawer when the user clicks outside the panel
|
|
214
|
-
* (`closeOnClickOutside`, default `true`).
|
|
234
|
+
* (`closeOnClickOutside`, default `true`). The click that opened the
|
|
235
|
+
* drawer never counts as an outside click. While closed (except in
|
|
236
|
+
* `side` mode) the panel is `aria-hidden` AND `inert`, so its focusable
|
|
237
|
+
* children are unreachable for keyboard and AT alike. On close, focus
|
|
238
|
+
* returns to the element that was focused when the drawer opened -
|
|
239
|
+
* unless the user moved focus to another focusable element themselves
|
|
240
|
+
* (a click on a focusable outside target keeps its focus).
|
|
241
|
+
*
|
|
242
|
+
* The `role` input defaults to `complementary`. On a `<nav>` host pass
|
|
243
|
+
* `[role]="null"` so the implicit navigation landmark survives:
|
|
215
244
|
*
|
|
216
245
|
* ```html
|
|
217
|
-
* <nav [cngxDrawerPanel]="drawer" position="left" mode="over"
|
|
246
|
+
* <nav [cngxDrawerPanel]="drawer" position="left" mode="over" [role]="null"
|
|
218
247
|
* [enabled]="drawer.opened()" [autoFocus]="true">
|
|
219
248
|
* <a href="/home">Home</a>
|
|
220
249
|
* </nav>
|
|
@@ -246,16 +275,69 @@ class CngxDrawerPanel {
|
|
|
246
275
|
mode = input('over', ...(ngDevMode ? [{ debugName: "mode" }] : /* istanbul ignore next */ []));
|
|
247
276
|
/** Whether clicking outside the panel closes the drawer. */
|
|
248
277
|
closeOnClickOutside = input(true, ...(ngDevMode ? [{ debugName: "closeOnClickOutside" }] : /* istanbul ignore next */ []));
|
|
278
|
+
/**
|
|
279
|
+
* Landmark role rendered on the panel. Defaults to `complementary`;
|
|
280
|
+
* pass `navigation` for nav drawers or `null` to keep the element's
|
|
281
|
+
* implicit role (e.g. on a `<nav>` host).
|
|
282
|
+
*/
|
|
283
|
+
role = input('complementary', ...(ngDevMode ? [{ debugName: "role" }] : /* istanbul ignore next */ []));
|
|
249
284
|
/** Whether the drawer is currently open (derived from the drawer ref). In `side` mode, always `true`. */
|
|
250
285
|
isOpen = computed(() => this.mode() === 'side' || this.drawerRef().opened(), ...(ngDevMode ? [{ debugName: "isOpen" }] : /* istanbul ignore next */ []));
|
|
286
|
+
suppressOutsideClick = false;
|
|
287
|
+
restoreTarget = null;
|
|
251
288
|
constructor() {
|
|
252
289
|
const doc = inject(DOCUMENT);
|
|
290
|
+
const el = inject((ElementRef));
|
|
291
|
+
// Focus restoration: closing puts `inert` on the panel, which would
|
|
292
|
+
// silently drop focus to <body>. Capture the focused element at the
|
|
293
|
+
// open transition and hand focus back at the close transition when
|
|
294
|
+
// focus is still inside the panel (Escape) or already fell to <body>
|
|
295
|
+
// (outside click on a non-focusable area). A focusable outside target
|
|
296
|
+
// the user clicked keeps its focus.
|
|
297
|
+
const openTransition = createTransitionTracker(() => this.isOpen());
|
|
298
|
+
effect(() => {
|
|
299
|
+
const open = openTransition.current();
|
|
300
|
+
const wasOpen = openTransition.previous();
|
|
301
|
+
if (open === wasOpen) {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
untracked(() => {
|
|
305
|
+
if (open) {
|
|
306
|
+
const active = doc.activeElement;
|
|
307
|
+
this.restoreTarget = active instanceof HTMLElement ? active : null;
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
const active = doc.activeElement;
|
|
311
|
+
const focusLost = active === null ||
|
|
312
|
+
active === doc.body ||
|
|
313
|
+
el.nativeElement.contains(active);
|
|
314
|
+
if (focusLost && this.restoreTarget?.isConnected) {
|
|
315
|
+
this.restoreTarget.focus();
|
|
316
|
+
}
|
|
317
|
+
this.restoreTarget = null;
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
// A click on a toggle OUTSIDE the container opens the drawer and then
|
|
321
|
+
// bubbles on to the document listener below within the same dispatch -
|
|
322
|
+
// without suppression it would close its own drawer instantly. The
|
|
323
|
+
// openedChange emit is synchronous inside that dispatch; the flag is
|
|
324
|
+
// lifted on the next macrotask, after the bubble phase has finished
|
|
325
|
+
// (a microtask checkpoint can run between listeners of a native event).
|
|
326
|
+
toObservable(this.drawerRef)
|
|
327
|
+
.pipe(switchMap((drawer) => outputToObservable(drawer.openedChange)), takeUntilDestroyed())
|
|
328
|
+
.subscribe((opened) => {
|
|
329
|
+
if (opened) {
|
|
330
|
+
this.suppressOutsideClick = true;
|
|
331
|
+
setTimeout(() => (this.suppressOutsideClick = false));
|
|
332
|
+
}
|
|
333
|
+
});
|
|
253
334
|
// Hit-test against the container, not the panel - toggle buttons and backdrops
|
|
254
335
|
// sit inside the container and must not count as outside clicks.
|
|
255
336
|
fromEvent(doc, 'click')
|
|
256
337
|
.pipe(takeUntilDestroyed())
|
|
257
338
|
.subscribe((e) => {
|
|
258
|
-
if (this.
|
|
339
|
+
if (!this.suppressOutsideClick &&
|
|
340
|
+
this.mode() !== 'side' &&
|
|
259
341
|
this.isOpen() &&
|
|
260
342
|
this.closeOnClickOutside() &&
|
|
261
343
|
!this.drawerRef().elementRef.nativeElement.contains(e.target)) {
|
|
@@ -264,7 +346,7 @@ class CngxDrawerPanel {
|
|
|
264
346
|
});
|
|
265
347
|
}
|
|
266
348
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDrawerPanel, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
267
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxDrawerPanel, isStandalone: true, selector: "[cngxDrawerPanel]", inputs: { drawerRef: { classPropertyName: "drawerRef", publicName: "cngxDrawerPanel", isSignal: true, isRequired: true, transformFunction: null }, position: { classPropertyName: "position", publicName: "position", isSignal: true, isRequired: false, transformFunction: null }, mode: { classPropertyName: "mode", publicName: "mode", isSignal: true, isRequired: false, transformFunction: null }, closeOnClickOutside: { classPropertyName: "closeOnClickOutside", publicName: "closeOnClickOutside", isSignal: true, isRequired: false, transformFunction: null }
|
|
349
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxDrawerPanel, isStandalone: true, selector: "[cngxDrawerPanel]", inputs: { drawerRef: { classPropertyName: "drawerRef", publicName: "cngxDrawerPanel", isSignal: true, isRequired: true, transformFunction: null }, position: { classPropertyName: "position", publicName: "position", isSignal: true, isRequired: false, transformFunction: null }, mode: { classPropertyName: "mode", publicName: "mode", isSignal: true, isRequired: false, transformFunction: null }, closeOnClickOutside: { classPropertyName: "closeOnClickOutside", publicName: "closeOnClickOutside", isSignal: true, isRequired: false, transformFunction: null }, role: { classPropertyName: "role", publicName: "role", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "class.cngx-drawer-panel": "true", "class.cngx-drawer-panel--open": "isOpen()", "class.cngx-drawer-panel--left": "position() === 'left'", "class.cngx-drawer-panel--right": "position() === 'right'", "class.cngx-drawer-panel--top": "position() === 'top'", "class.cngx-drawer-panel--bottom": "position() === 'bottom'", "class.cngx-drawer-panel--over": "mode() === 'over'", "class.cngx-drawer-panel--push": "mode() === 'push'", "class.cngx-drawer-panel--side": "mode() === 'side'", "attr.aria-hidden": "mode() !== 'side' && !isOpen() ? true : null", "attr.inert": "mode() !== 'side' && !isOpen() ? '' : null", "attr.role": "role()" } }, exportAs: ["cngxDrawerPanel"], hostDirectives: [{ directive: i1.CngxFocusTrap, inputs: ["enabled", "enabled", "autoFocus", "autoFocus"] }], ngImport: i0 });
|
|
268
350
|
}
|
|
269
351
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDrawerPanel, decorators: [{
|
|
270
352
|
type: Directive,
|
|
@@ -283,11 +365,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
283
365
|
'[class.cngx-drawer-panel--over]': "mode() === 'over'",
|
|
284
366
|
'[class.cngx-drawer-panel--push]': "mode() === 'push'",
|
|
285
367
|
'[class.cngx-drawer-panel--side]': "mode() === 'side'",
|
|
286
|
-
'[attr.aria-hidden]': "mode()
|
|
287
|
-
|
|
368
|
+
'[attr.aria-hidden]': "mode() !== 'side' && !isOpen() ? true : null",
|
|
369
|
+
'[attr.inert]': "mode() !== 'side' && !isOpen() ? '' : null",
|
|
370
|
+
'[attr.role]': 'role()',
|
|
288
371
|
},
|
|
289
372
|
}]
|
|
290
|
-
}], ctorParameters: () => [], propDecorators: { drawerRef: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxDrawerPanel", required: true }] }], position: [{ type: i0.Input, args: [{ isSignal: true, alias: "position", required: false }] }], mode: [{ type: i0.Input, args: [{ isSignal: true, alias: "mode", required: false }] }], closeOnClickOutside: [{ type: i0.Input, args: [{ isSignal: true, alias: "closeOnClickOutside", required: false }] }] } });
|
|
373
|
+
}], ctorParameters: () => [], propDecorators: { drawerRef: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxDrawerPanel", required: true }] }], position: [{ type: i0.Input, args: [{ isSignal: true, alias: "position", required: false }] }], mode: [{ type: i0.Input, args: [{ isSignal: true, alias: "mode", required: false }] }], closeOnClickOutside: [{ type: i0.Input, args: [{ isSignal: true, alias: "closeOnClickOutside", required: false }] }], role: [{ type: i0.Input, args: [{ isSignal: true, alias: "role", required: false }] }] } });
|
|
291
374
|
|
|
292
375
|
/**
|
|
293
376
|
* Marks the main content area adjacent to a drawer panel.
|
|
@@ -404,8 +487,13 @@ class CngxIntersectionObserver {
|
|
|
404
487
|
const rootMargin = this.rootMargin();
|
|
405
488
|
const threshold = this.threshold();
|
|
406
489
|
const resolvedRoot = root ? this.doc.querySelector(root) : null;
|
|
490
|
+
if (isDevMode() && root && !resolvedRoot) {
|
|
491
|
+
console.warn(`[cngxIntersectionObserver] root selector "${root}" matched no element - ` +
|
|
492
|
+
'falling back to the viewport. A late-rendered root needs a re-bind of [root].');
|
|
493
|
+
}
|
|
407
494
|
const observer = new IntersectionObserver((entries) => {
|
|
408
|
-
|
|
495
|
+
// batched records arrive oldest-first; only the newest reflects reality
|
|
496
|
+
const entry = entries[entries.length - 1];
|
|
409
497
|
const wasIntersecting = this.entryState()?.isIntersecting ?? false;
|
|
410
498
|
this.entryState.set(entry);
|
|
411
499
|
this.intersectionChange.emit(entry);
|
|
@@ -472,16 +560,7 @@ class CngxMediaQuery {
|
|
|
472
560
|
matches = this.matchesState.asReadonly();
|
|
473
561
|
constructor() {
|
|
474
562
|
effect((onCleanup) => {
|
|
475
|
-
|
|
476
|
-
if (!win) {
|
|
477
|
-
this.matchesState.set(false);
|
|
478
|
-
return;
|
|
479
|
-
}
|
|
480
|
-
const mql = win.matchMedia(this.query());
|
|
481
|
-
this.matchesState.set(mql.matches);
|
|
482
|
-
const handler = (e) => this.matchesState.set(e.matches);
|
|
483
|
-
mql.addEventListener('change', handler);
|
|
484
|
-
onCleanup(() => mql.removeEventListener('change', handler));
|
|
563
|
+
onCleanup(observeMediaQuery(this.win, this.query(), (matches) => this.matchesState.set(matches)));
|
|
485
564
|
});
|
|
486
565
|
}
|
|
487
566
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxMediaQuery, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
@@ -533,29 +612,23 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
533
612
|
* <example-url>http://localhost:4200/#/common/layout/media-query/inject-breakpoint-signal</example-url>
|
|
534
613
|
*/
|
|
535
614
|
function injectMediaQuery(query) {
|
|
536
|
-
|
|
537
|
-
if (!win || typeof win.matchMedia !== 'function') {
|
|
538
|
-
return signal(false).asReadonly();
|
|
539
|
-
}
|
|
540
|
-
const mql = win.matchMedia(query);
|
|
541
|
-
const matches = signal(mql.matches, ...(ngDevMode ? [{ debugName: "matches" }] : /* istanbul ignore next */ []));
|
|
542
|
-
const handler = (event) => matches.set(event.matches);
|
|
543
|
-
mql.addEventListener('change', handler);
|
|
544
|
-
inject(DestroyRef).onDestroy(() => mql.removeEventListener('change', handler));
|
|
545
|
-
return matches.asReadonly();
|
|
615
|
+
return createMediaQuerySignal(query, inject(DestroyRef), inject(DOCUMENT).defaultView);
|
|
546
616
|
}
|
|
547
617
|
|
|
548
618
|
/**
|
|
549
619
|
* Dev-warning the query-param sync kernel emits when `@angular/router` is
|
|
550
620
|
* not provided. Mirrors {@link warnTabsRouterAbsent} in `@cngx/common/tabs`
|
|
551
621
|
* so the message stays identical across the two sync surfaces; only the
|
|
552
|
-
* `enables` clause differs
|
|
553
|
-
* import - sharing would force the helper onto a
|
|
554
|
-
* matches no approved public-API prefix.
|
|
622
|
+
* `enables` clause differs (and this copy is dev-gated). A deliberate small
|
|
623
|
+
* copy rather than a shared import - sharing would force the helper onto a
|
|
624
|
+
* `public-api.ts`, and `warn*` matches no approved public-API prefix.
|
|
555
625
|
*
|
|
556
626
|
* @internal
|
|
557
627
|
*/
|
|
558
628
|
function warnRouterAbsent(directive, enables) {
|
|
629
|
+
if (!isDevMode()) {
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
559
632
|
console.warn(`${directive}: no Router available - directive is a no-op. ` +
|
|
560
633
|
`Provide @angular/router via provideRouter(...) to enable ${enables}.`);
|
|
561
634
|
}
|
|
@@ -594,7 +667,7 @@ function injectQueryParamSync(state, opts) {
|
|
|
594
667
|
return;
|
|
595
668
|
}
|
|
596
669
|
const route = inject(ActivatedRoute);
|
|
597
|
-
const paramSignal =
|
|
670
|
+
const paramSignal = coerceSignal(opts.param);
|
|
598
671
|
const serialize = opts.serialize ?? ((value) => (value ? 'open' : null));
|
|
599
672
|
const deserialize = opts.deserialize ?? ((raw) => (raw != null));
|
|
600
673
|
// Closure bookkeeping, seeded from the initial URL read. `lastWritten` is
|
|
@@ -679,6 +752,75 @@ function injectQueryParamSync(state, opts) {
|
|
|
679
752
|
});
|
|
680
753
|
}
|
|
681
754
|
|
|
755
|
+
/**
|
|
756
|
+
* Subscribes `apply` to size changes of `element` on `host`.
|
|
757
|
+
*
|
|
758
|
+
* Re-applies on every observation and returns the teardown that disconnects
|
|
759
|
+
* the observer. On a host without `ResizeObserver` (SSR, jsdom) nothing is
|
|
760
|
+
* wired, `apply` never fires, and the returned teardown is a no-op. Unlike the
|
|
761
|
+
* media-query twin there is no synchronous seed: the first size is whatever the
|
|
762
|
+
* observer reports after the next layout.
|
|
763
|
+
*
|
|
764
|
+
* Reach for this low-level form when the observed element or the box model is
|
|
765
|
+
* reactive and the subscription must follow it (re-wire per `effect` run via
|
|
766
|
+
* `onCleanup`); for a static target, {@link createResizeSignal} owns the
|
|
767
|
+
* teardown via `DestroyRef`.
|
|
768
|
+
*
|
|
769
|
+
* @param host The window-like object to read `ResizeObserver` from.
|
|
770
|
+
* @param element The element to observe.
|
|
771
|
+
* @param box Which box model to report.
|
|
772
|
+
* @param apply Receives the first entry of every observation batch.
|
|
773
|
+
* @returns Teardown that disconnects the observer.
|
|
774
|
+
* @category common/layout/observers
|
|
775
|
+
* @relatedTo createResizeSignal, observeMediaQuery
|
|
776
|
+
* @since 0.1.0
|
|
777
|
+
*/
|
|
778
|
+
function observeResize(host, element, box, apply) {
|
|
779
|
+
if (!host || typeof host.ResizeObserver !== 'function') {
|
|
780
|
+
return () => undefined;
|
|
781
|
+
}
|
|
782
|
+
const observer = new host.ResizeObserver((entries) => apply(entries[0]));
|
|
783
|
+
observer.observe(element, { box });
|
|
784
|
+
return () => observer.disconnect();
|
|
785
|
+
}
|
|
786
|
+
/**
|
|
787
|
+
* Creates a `Signal<ResizeObserverEntry | null>` that carries the most recent
|
|
788
|
+
* observation of `element`, `null` until the first one arrives.
|
|
789
|
+
*
|
|
790
|
+
* Disconnects when `destroyRef` is destroyed. On a host without
|
|
791
|
+
* `ResizeObserver` (SSR, jsdom) the signal stays `null` and no observer is
|
|
792
|
+
* created, so it never throws off the browser.
|
|
793
|
+
*
|
|
794
|
+
* This is the shared kernel behind `CngxResizeObserver` and
|
|
795
|
+
* `createContainerSize`; consumers that hand-roll a `ResizeObserver` should
|
|
796
|
+
* route through it instead.
|
|
797
|
+
*
|
|
798
|
+
* ```typescript
|
|
799
|
+
* const entry = createResizeSignal(
|
|
800
|
+
* host,
|
|
801
|
+
* 'border-box',
|
|
802
|
+
* inject(DestroyRef),
|
|
803
|
+
* inject(DOCUMENT).defaultView,
|
|
804
|
+
* );
|
|
805
|
+
* const width = computed(() => entry()?.borderBoxSize[0]?.inlineSize ?? 0);
|
|
806
|
+
* ```
|
|
807
|
+
*
|
|
808
|
+
* @param element The element to observe.
|
|
809
|
+
* @param box Which box model to report.
|
|
810
|
+
* @param destroyRef Scope whose destruction disconnects the observer.
|
|
811
|
+
* @param host The window-like object to read `ResizeObserver` from.
|
|
812
|
+
* @returns A readonly signal carrying the latest entry.
|
|
813
|
+
* @category common/layout/observers
|
|
814
|
+
* @relatedTo observeResize, createMediaQuerySignal
|
|
815
|
+
* @since 0.1.0
|
|
816
|
+
*/
|
|
817
|
+
function createResizeSignal(element, box, destroyRef, host) {
|
|
818
|
+
const entry = signal(null, ...(ngDevMode ? [{ debugName: "entry" }] : /* istanbul ignore next */ []));
|
|
819
|
+
const unsubscribe = observeResize(host, element, box, (value) => entry.set(value));
|
|
820
|
+
destroyRef.onDestroy(unsubscribe);
|
|
821
|
+
return entry.asReadonly();
|
|
822
|
+
}
|
|
823
|
+
|
|
682
824
|
/**
|
|
683
825
|
* Observes size changes of the host element via the `ResizeObserver` API.
|
|
684
826
|
*
|
|
@@ -727,18 +869,16 @@ class CngxResizeObserver {
|
|
|
727
869
|
el = inject((ElementRef));
|
|
728
870
|
constructor() {
|
|
729
871
|
const win = inject(DOCUMENT).defaultView;
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
this.
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
observer.observe(this.el.nativeElement, { box: this.box() });
|
|
872
|
+
// One subscription per `box` value: `onCleanup` disconnects the previous
|
|
873
|
+
// observer before `observeResize` wires the next, which is also the
|
|
874
|
+
// teardown on destroy. The kernel no-ops when the host ships no
|
|
875
|
+
// `ResizeObserver` (SSR, jsdom), so no host guard is needed here.
|
|
876
|
+
effect((onCleanup) => {
|
|
877
|
+
onCleanup(observeResize(win, this.el.nativeElement, this.box(), (entry) => {
|
|
878
|
+
this.entryState.set(entry);
|
|
879
|
+
this.resize.emit(entry);
|
|
880
|
+
}));
|
|
740
881
|
});
|
|
741
|
-
inject(DestroyRef).onDestroy(() => observer.disconnect());
|
|
742
882
|
}
|
|
743
883
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxResizeObserver, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
744
884
|
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxResizeObserver, isStandalone: true, selector: "[cngxResizeObserver]", inputs: { box: { classPropertyName: "box", publicName: "box", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { resize: "resize" }, exportAs: ["cngxResizeObserver"], ngImport: i0 });
|
|
@@ -753,13 +893,224 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
753
893
|
}], ctorParameters: () => [], propDecorators: { box: [{ type: i0.Input, args: [{ isSignal: true, alias: "box", required: false }] }], resize: [{ type: i0.Output, args: ["resize"] }] } });
|
|
754
894
|
|
|
755
895
|
/**
|
|
756
|
-
*
|
|
896
|
+
* The nearest query container declared by {@link CngxContainer}.
|
|
897
|
+
*
|
|
898
|
+
* Deliberately has no root factory: absence is meaningful. A component that
|
|
899
|
+
* needs a container and finds none must say so (a dev-mode warning), not
|
|
900
|
+
* silently observe itself.
|
|
901
|
+
*
|
|
902
|
+
* @category common/layout/observers
|
|
903
|
+
* @since 0.1.0
|
|
904
|
+
*/
|
|
905
|
+
const CNGX_CONTAINER_SIZE = new InjectionToken('CNGX_CONTAINER_SIZE');
|
|
906
|
+
/**
|
|
907
|
+
* Creates a {@link CngxContainerSize} over `element`.
|
|
908
|
+
*
|
|
909
|
+
* Observes the border box, so the reported size matches what an
|
|
910
|
+
* `inline-size` container query measures. The `property()` reads are plain
|
|
911
|
+
* `computed()`s over the same resize signal - the browser has already
|
|
912
|
+
* re-evaluated every container query by the time a `ResizeObserver` callback
|
|
913
|
+
* runs, so the read returns the current value without a second scheduling hop.
|
|
914
|
+
*
|
|
915
|
+
* @param element The container host.
|
|
916
|
+
* @param destroyRef Scope whose destruction disconnects the observer.
|
|
917
|
+
* @param win The window-like object providing `ResizeObserver` and `getComputedStyle`.
|
|
918
|
+
* @category common/layout/observers
|
|
919
|
+
* @relatedTo injectContainerSize, CngxContainer
|
|
920
|
+
* @since 0.1.0
|
|
921
|
+
*/
|
|
922
|
+
function createContainerSize(element, destroyRef, win) {
|
|
923
|
+
const entry = createResizeSignal(element, 'border-box', destroyRef, win);
|
|
924
|
+
const inlineSize = computed(() => entry()?.borderBoxSize?.[0]?.inlineSize ?? 0, ...(ngDevMode ? [{ debugName: "inlineSize" }] : /* istanbul ignore next */ []));
|
|
925
|
+
const blockSize = computed(() => entry()?.borderBoxSize?.[0]?.blockSize ?? 0, ...(ngDevMode ? [{ debugName: "blockSize" }] : /* istanbul ignore next */ []));
|
|
926
|
+
const isReady = computed(() => entry() !== null, ...(ngDevMode ? [{ debugName: "isReady" }] : /* istanbul ignore next */ []));
|
|
927
|
+
// Weak on the element: the container outlives descendants that get
|
|
928
|
+
// destroyed, so a strong Map would pin every dead node it ever read.
|
|
929
|
+
const cache = new WeakMap();
|
|
930
|
+
const property = (name, on, pseudo) => {
|
|
931
|
+
const target = on ?? element;
|
|
932
|
+
let byName = cache.get(target);
|
|
933
|
+
if (!byName) {
|
|
934
|
+
byName = new Map();
|
|
935
|
+
cache.set(target, byName);
|
|
936
|
+
}
|
|
937
|
+
const key = `${pseudo ?? ''}|${name}`;
|
|
938
|
+
const cached = byName.get(key);
|
|
939
|
+
if (cached) {
|
|
940
|
+
return cached;
|
|
941
|
+
}
|
|
942
|
+
// A DOM read inside a computed() is deliberate here, not an oversight: the
|
|
943
|
+
// only tracked dependency is the resize entry, and a ResizeObserver
|
|
944
|
+
// callback runs after layout, when every container query has already been
|
|
945
|
+
// re-evaluated. The read is therefore idempotent for a given entry and
|
|
946
|
+
// never forces a recalc of its own. An effect writing into a signal would
|
|
947
|
+
// add a scheduling hop for nothing.
|
|
948
|
+
const value = computed(() => {
|
|
949
|
+
if (entry() === null || !win?.getComputedStyle) {
|
|
950
|
+
return '';
|
|
951
|
+
}
|
|
952
|
+
return win
|
|
953
|
+
.getComputedStyle(target, pseudo ?? null)
|
|
954
|
+
.getPropertyValue(name)
|
|
955
|
+
.trim();
|
|
956
|
+
}, ...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
|
|
957
|
+
byName.set(key, value);
|
|
958
|
+
return value;
|
|
959
|
+
};
|
|
960
|
+
return { inlineSize, blockSize, isReady, property };
|
|
961
|
+
}
|
|
962
|
+
/**
|
|
963
|
+
* Reads the nearest query container declared by a `[cngxContainer]` ancestor,
|
|
964
|
+
* or observes `target` (default: the host element) when there is none.
|
|
965
|
+
*
|
|
966
|
+
* Use it where a component must branch structurally on the width it was given
|
|
967
|
+
* - a different template, a focus move, an `aria-modal` flip. Purely visual
|
|
968
|
+
* adaptation needs no TypeScript at all: write a `@container` rule.
|
|
969
|
+
*
|
|
970
|
+
* ```typescript
|
|
971
|
+
* private readonly container = inject(CNGX_CONTAINER_SIZE, { optional: true });
|
|
972
|
+
* private readonly wide = this.container?.property('--cngx-thing-wide', this.host) ?? signal('').asReadonly();
|
|
973
|
+
* readonly mode = computed(() => (this.wide() === '1' ? 'side' : 'over'));
|
|
974
|
+
* ```
|
|
975
|
+
*
|
|
976
|
+
* A component that declares the container in its own stylesheet and reads it
|
|
977
|
+
* itself passes its host explicitly and reads the property off `::after` -
|
|
978
|
+
* there is no descendant to carry the value:
|
|
979
|
+
*
|
|
980
|
+
* ```typescript
|
|
981
|
+
* private readonly host = inject(ElementRef).nativeElement as Element;
|
|
982
|
+
* private readonly container = injectContainerSize(this.host);
|
|
983
|
+
* private readonly narrow = this.container.property('--cngx-thing-narrow', this.host, '::after');
|
|
984
|
+
* ```
|
|
985
|
+
*
|
|
986
|
+
* @param target Element to observe when no ancestor container exists.
|
|
987
|
+
* @category common/layout/observers
|
|
988
|
+
* @relatedTo CngxContainer, injectMediaQuery
|
|
989
|
+
* @since 0.1.0
|
|
990
|
+
*/
|
|
991
|
+
function injectContainerSize(target) {
|
|
992
|
+
const ancestor = inject(CNGX_CONTAINER_SIZE, { optional: true, skipSelf: true });
|
|
993
|
+
if (ancestor && !target) {
|
|
994
|
+
return ancestor;
|
|
995
|
+
}
|
|
996
|
+
const resolved = target instanceof ElementRef
|
|
997
|
+
? target.nativeElement
|
|
998
|
+
: (target ?? inject(ElementRef).nativeElement);
|
|
999
|
+
return createContainerSize(resolved, inject(DestroyRef), inject(DOCUMENT).defaultView);
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
/**
|
|
1003
|
+
* Observes a query container and publishes its size to descendants through
|
|
1004
|
+
* {@link CNGX_CONTAINER_SIZE}.
|
|
1005
|
+
*
|
|
1006
|
+
* The directive declares nothing visual. **Both `container-type` and
|
|
1007
|
+
* `container-name` belong in the stylesheet**, next to the `@container` rules
|
|
1008
|
+
* that use them: the name is API (an unnamed query matches the nearest
|
|
1009
|
+
* container of any name, so a consumer wrapping the component in their own
|
|
1010
|
+
* container would silently re-target it), and containment is a layout
|
|
1011
|
+
* decision a skin must be able to opt out of with a plain CSS rule rather
|
|
1012
|
+
* than `!important` against a host style.
|
|
1013
|
+
*
|
|
1014
|
+
* ```css
|
|
1015
|
+
* cngx-thing-layout {
|
|
1016
|
+
* container-type: inline-size;
|
|
1017
|
+
* container-name: cngx-thing-layout;
|
|
1018
|
+
* }
|
|
1019
|
+
*
|
|
1020
|
+
* cngx-thing-layout > cngx-thing { --cngx-thing-wide: 0; }
|
|
1021
|
+
*
|
|
1022
|
+
* @container cngx-thing-layout (min-inline-size: 64rem) {
|
|
1023
|
+
* cngx-thing-layout > cngx-thing { --cngx-thing-wide: 1; }
|
|
1024
|
+
* }
|
|
1025
|
+
* ```
|
|
1026
|
+
*
|
|
1027
|
+
* ```html
|
|
1028
|
+
* <div cngxContainer>
|
|
1029
|
+
* <app-panel />
|
|
1030
|
+
* </div>
|
|
1031
|
+
* ```
|
|
1032
|
+
*
|
|
1033
|
+
* A descendant reads the resolved value with `injectContainerSize()`, so the
|
|
1034
|
+
* breakpoint exists exactly once - in CSS. Note that `container-type:
|
|
1035
|
+
* inline-size` applies size containment: an element that must shrink-wrap its
|
|
1036
|
+
* content (an inline chip, a `width: max-content` bar) must not be a
|
|
1037
|
+
* container.
|
|
1038
|
+
*
|
|
1039
|
+
* @category common/layout
|
|
1040
|
+
* @docsKind primary
|
|
1041
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/observers/container.directive.ts
|
|
1042
|
+
* @since 0.1.0
|
|
1043
|
+
* @relatedTo injectContainerSize, CngxResizeObserver, CngxMediaQuery
|
|
1044
|
+
* <example-url>http://localhost:4200/#/common/layout/container/css-decides-js-reads</example-url>
|
|
1045
|
+
*/
|
|
1046
|
+
class CngxContainer {
|
|
1047
|
+
size = createContainerSize(inject(ElementRef).nativeElement, inject(DestroyRef), inject(DOCUMENT).defaultView);
|
|
1048
|
+
/** Border-box inline size in pixels. `0` before the first observation. */
|
|
1049
|
+
inlineSize = this.size.inlineSize;
|
|
1050
|
+
/** Border-box block size in pixels. `0` before the first observation. */
|
|
1051
|
+
blockSize = this.size.blockSize;
|
|
1052
|
+
/** `true` once the first observation has arrived. */
|
|
1053
|
+
isReady = this.size.isReady;
|
|
1054
|
+
/**
|
|
1055
|
+
* The resolved value of a custom property on `on` (default: this host),
|
|
1056
|
+
* re-read on every resize. The `@container` rule must style a descendant,
|
|
1057
|
+
* or a pseudo-element of the container itself - see
|
|
1058
|
+
* {@link CngxContainerSize.property}.
|
|
1059
|
+
*/
|
|
1060
|
+
property(name, on, pseudo) {
|
|
1061
|
+
return this.size.property(name, on, pseudo);
|
|
1062
|
+
}
|
|
1063
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxContainer, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1064
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxContainer, isStandalone: true, selector: "[cngxContainer]", providers: [{ provide: CNGX_CONTAINER_SIZE, useExisting: CngxContainer }], exportAs: ["cngxContainer"], ngImport: i0 });
|
|
1065
|
+
}
|
|
1066
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxContainer, decorators: [{
|
|
1067
|
+
type: Directive,
|
|
1068
|
+
args: [{
|
|
1069
|
+
selector: '[cngxContainer]',
|
|
1070
|
+
exportAs: 'cngxContainer',
|
|
1071
|
+
standalone: true,
|
|
1072
|
+
providers: [{ provide: CNGX_CONTAINER_SIZE, useExisting: CngxContainer }],
|
|
1073
|
+
}]
|
|
1074
|
+
}] });
|
|
1075
|
+
|
|
1076
|
+
/**
|
|
1077
|
+
* Ref-count per document root. Module-private on purpose: this file is the
|
|
1078
|
+
* single owner of the lock state. A second copy of this map (the pre-extraction
|
|
1079
|
+
* state: one in `CngxScrollLock`, one in `CngxDialog`) shares the dataset keys
|
|
1080
|
+
* below without sharing the count, so interleaved acquire/release across the
|
|
1081
|
+
* two owners corrupts each other's saved overflow values.
|
|
757
1082
|
*
|
|
758
1083
|
* @internal
|
|
759
1084
|
*/
|
|
760
1085
|
const lockCounts = new WeakMap();
|
|
761
|
-
/**
|
|
762
|
-
|
|
1086
|
+
/**
|
|
1087
|
+
* Acquire a ref-counted scroll lock on a document root and get back the
|
|
1088
|
+
* matching release function.
|
|
1089
|
+
*
|
|
1090
|
+
* The first active lock saves the current `overflow` / `scrollbar-gutter`
|
|
1091
|
+
* inline styles and sets `overflow: hidden` + `scrollbar-gutter: stable`
|
|
1092
|
+
* (no layout shift when the scrollbar disappears). Releasing the last active
|
|
1093
|
+
* lock restores the saved values. The returned release function is
|
|
1094
|
+
* idempotent - calling it twice cannot over-decrement the count.
|
|
1095
|
+
*
|
|
1096
|
+
* Shared engine behind `CngxScrollLock` and `CngxDialog`'s modal scroll lock;
|
|
1097
|
+
* consumers composing their own overlay primitives can use it directly.
|
|
1098
|
+
*
|
|
1099
|
+
* ```typescript
|
|
1100
|
+
* const release = createScrollLock(document.documentElement);
|
|
1101
|
+
* // ... overlay open ...
|
|
1102
|
+
* release();
|
|
1103
|
+
* ```
|
|
1104
|
+
*
|
|
1105
|
+
* @param html - The document root (`document.documentElement`) to lock.
|
|
1106
|
+
* @returns Release function for this acquisition. Idempotent.
|
|
1107
|
+
*
|
|
1108
|
+
* @category common/layout
|
|
1109
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/scroll/scroll-lock-core.ts
|
|
1110
|
+
* @since 0.1.0
|
|
1111
|
+
* @relatedTo CngxScrollLock, CngxDialog
|
|
1112
|
+
*/
|
|
1113
|
+
function createScrollLock(html) {
|
|
763
1114
|
const count = lockCounts.get(html) ?? 0;
|
|
764
1115
|
if (count === 0) {
|
|
765
1116
|
html.dataset['cngxPrevOverflow'] = html.style.overflow;
|
|
@@ -768,21 +1119,26 @@ function acquireScrollLock(html) {
|
|
|
768
1119
|
html.style.scrollbarGutter = 'stable';
|
|
769
1120
|
}
|
|
770
1121
|
lockCounts.set(html, count + 1);
|
|
1122
|
+
let released = false;
|
|
1123
|
+
return () => {
|
|
1124
|
+
if (released) {
|
|
1125
|
+
return;
|
|
1126
|
+
}
|
|
1127
|
+
released = true;
|
|
1128
|
+
const current = lockCounts.get(html) ?? 0;
|
|
1129
|
+
if (current <= 1) {
|
|
1130
|
+
html.style.overflow = html.dataset['cngxPrevOverflow'] ?? '';
|
|
1131
|
+
html.style.scrollbarGutter = html.dataset['cngxPrevScrollbarGutter'] ?? '';
|
|
1132
|
+
delete html.dataset['cngxPrevOverflow'];
|
|
1133
|
+
delete html.dataset['cngxPrevScrollbarGutter'];
|
|
1134
|
+
lockCounts.set(html, 0);
|
|
1135
|
+
}
|
|
1136
|
+
else {
|
|
1137
|
+
lockCounts.set(html, current - 1);
|
|
1138
|
+
}
|
|
1139
|
+
};
|
|
771
1140
|
}
|
|
772
|
-
|
|
773
|
-
function releaseScrollLock(html) {
|
|
774
|
-
const count = lockCounts.get(html) ?? 0;
|
|
775
|
-
if (count <= 1) {
|
|
776
|
-
html.style.overflow = html.dataset['cngxPrevOverflow'] ?? '';
|
|
777
|
-
html.style.scrollbarGutter = html.dataset['cngxPrevScrollbarGutter'] ?? '';
|
|
778
|
-
delete html.dataset['cngxPrevOverflow'];
|
|
779
|
-
delete html.dataset['cngxPrevScrollbarGutter'];
|
|
780
|
-
lockCounts.set(html, 0);
|
|
781
|
-
}
|
|
782
|
-
else {
|
|
783
|
-
lockCounts.set(html, count - 1);
|
|
784
|
-
}
|
|
785
|
-
}
|
|
1141
|
+
|
|
786
1142
|
/**
|
|
787
1143
|
* Prevents scrolling on the document body when enabled.
|
|
788
1144
|
*
|
|
@@ -817,21 +1173,18 @@ class CngxScrollLock {
|
|
|
817
1173
|
enabled = input(false, { ...(ngDevMode ? { debugName: "enabled" } : /* istanbul ignore next */ {}), alias: 'cngxScrollLock' });
|
|
818
1174
|
constructor() {
|
|
819
1175
|
const html = inject(DOCUMENT).documentElement;
|
|
820
|
-
let
|
|
1176
|
+
let release = null;
|
|
821
1177
|
effect(() => {
|
|
822
|
-
if (this.enabled() && !
|
|
823
|
-
|
|
824
|
-
locked = true;
|
|
1178
|
+
if (this.enabled() && !release) {
|
|
1179
|
+
release = createScrollLock(html);
|
|
825
1180
|
}
|
|
826
|
-
else if (!this.enabled() &&
|
|
827
|
-
|
|
828
|
-
|
|
1181
|
+
else if (!this.enabled() && release) {
|
|
1182
|
+
release();
|
|
1183
|
+
release = null;
|
|
829
1184
|
}
|
|
830
1185
|
});
|
|
831
1186
|
inject(DestroyRef).onDestroy(() => {
|
|
832
|
-
|
|
833
|
-
releaseScrollLock(html);
|
|
834
|
-
}
|
|
1187
|
+
release?.();
|
|
835
1188
|
});
|
|
836
1189
|
}
|
|
837
1190
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxScrollLock, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
@@ -846,6 +1199,240 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
846
1199
|
}]
|
|
847
1200
|
}], ctorParameters: () => [], propDecorators: { enabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxScrollLock", required: false }] }] } });
|
|
848
1201
|
|
|
1202
|
+
/** Distances up to this many px count as "at the edge" (sub-pixel and zoom rounding). */
|
|
1203
|
+
const EDGE_TOLERANCE = 1;
|
|
1204
|
+
const NO_EDGES = {
|
|
1205
|
+
blockStart: false,
|
|
1206
|
+
blockEnd: false,
|
|
1207
|
+
inlineStart: false,
|
|
1208
|
+
inlineEnd: false,
|
|
1209
|
+
};
|
|
1210
|
+
function sameEdges(a, b) {
|
|
1211
|
+
return (a.blockStart === b.blockStart &&
|
|
1212
|
+
a.blockEnd === b.blockEnd &&
|
|
1213
|
+
a.inlineStart === b.inlineStart &&
|
|
1214
|
+
a.inlineEnd === b.inlineEnd);
|
|
1215
|
+
}
|
|
1216
|
+
/**
|
|
1217
|
+
* One read of the six scroll metrics. RTL `scrollLeft` runs over `[-max, 0]`
|
|
1218
|
+
* in every evergreen engine and LTR over `[0, max]`, so its magnitude is the
|
|
1219
|
+
* distance from the inline-start edge in both directions - no direction lookup
|
|
1220
|
+
* and no `getComputedStyle` in the scroll path.
|
|
1221
|
+
*/
|
|
1222
|
+
function readEdges(element) {
|
|
1223
|
+
const inlineOffset = Math.abs(element.scrollLeft);
|
|
1224
|
+
return {
|
|
1225
|
+
blockStart: element.scrollTop > EDGE_TOLERANCE,
|
|
1226
|
+
blockEnd: element.scrollHeight - element.clientHeight - element.scrollTop > EDGE_TOLERANCE,
|
|
1227
|
+
inlineStart: inlineOffset > EDGE_TOLERANCE,
|
|
1228
|
+
inlineEnd: element.scrollWidth - element.clientWidth - inlineOffset > EDGE_TOLERANCE,
|
|
1229
|
+
};
|
|
1230
|
+
}
|
|
1231
|
+
/**
|
|
1232
|
+
* Tracks which edges of a scrollport still hide content, as four boolean
|
|
1233
|
+
* signals.
|
|
1234
|
+
*
|
|
1235
|
+
* Triggers are a passive `scroll` listener, one `observeResize` per observed
|
|
1236
|
+
* element (the scrollport itself plus every direct element child) and a
|
|
1237
|
+
* `childList`-only `MutationObserver` that keeps that child set current. All
|
|
1238
|
+
* of them only schedule work: the metrics are read once per animation frame
|
|
1239
|
+
* however many triggers fired, and the result lands in one snapshot signal
|
|
1240
|
+
* with a structural `equal`, so the four projections only notify when an edge
|
|
1241
|
+
* actually flips. A distance of 1px or less counts as "at the edge".
|
|
1242
|
+
*
|
|
1243
|
+
* Only direct children are resize-observed. A long item list should sit inside
|
|
1244
|
+
* one content element rather than be N direct children (one observer each);
|
|
1245
|
+
* growth deep inside a fixed-size child is picked up on the next scroll.
|
|
1246
|
+
*
|
|
1247
|
+
* A `null` host (SSR) wires nothing and all four signals stay `false`.
|
|
1248
|
+
*
|
|
1249
|
+
* ```typescript
|
|
1250
|
+
* const edges = createScrollEdges(
|
|
1251
|
+
* inject(ElementRef).nativeElement,
|
|
1252
|
+
* inject(DestroyRef),
|
|
1253
|
+
* inject(DOCUMENT).defaultView,
|
|
1254
|
+
* );
|
|
1255
|
+
* const showTopShadow = edges.canScrollBlockStart;
|
|
1256
|
+
* ```
|
|
1257
|
+
*
|
|
1258
|
+
* @param element The scrollport to read.
|
|
1259
|
+
* @param destroyRef Scope whose destruction removes the listener, disconnects
|
|
1260
|
+
* every observer and cancels a pending frame.
|
|
1261
|
+
* @param host The window-like object to read the observer and frame APIs from.
|
|
1262
|
+
* @returns The four per-edge signals.
|
|
1263
|
+
* @category common/layout
|
|
1264
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/scroll/scroll-edges-core.ts
|
|
1265
|
+
* @since 0.1.0
|
|
1266
|
+
* @relatedTo CngxScrollEdges, observeResize
|
|
1267
|
+
*/
|
|
1268
|
+
function createScrollEdges(element, destroyRef, host) {
|
|
1269
|
+
const edges = signal(NO_EDGES, { ...(ngDevMode ? { debugName: "edges" } : /* istanbul ignore next */ {}), equal: sameEdges });
|
|
1270
|
+
const state = {
|
|
1271
|
+
canScrollBlockStart: computed(() => edges().blockStart),
|
|
1272
|
+
canScrollBlockEnd: computed(() => edges().blockEnd),
|
|
1273
|
+
canScrollInlineStart: computed(() => edges().inlineStart),
|
|
1274
|
+
canScrollInlineEnd: computed(() => edges().inlineEnd),
|
|
1275
|
+
};
|
|
1276
|
+
if (!host) {
|
|
1277
|
+
return state;
|
|
1278
|
+
}
|
|
1279
|
+
let destroyed = false;
|
|
1280
|
+
let framePending = false;
|
|
1281
|
+
let frameHandle = 0;
|
|
1282
|
+
const read = () => {
|
|
1283
|
+
framePending = false;
|
|
1284
|
+
if (destroyed) {
|
|
1285
|
+
return;
|
|
1286
|
+
}
|
|
1287
|
+
edges.set(readEdges(element));
|
|
1288
|
+
};
|
|
1289
|
+
const schedule = () => {
|
|
1290
|
+
if (destroyed || framePending) {
|
|
1291
|
+
return;
|
|
1292
|
+
}
|
|
1293
|
+
if (typeof host.requestAnimationFrame !== 'function') {
|
|
1294
|
+
read();
|
|
1295
|
+
return;
|
|
1296
|
+
}
|
|
1297
|
+
framePending = true;
|
|
1298
|
+
frameHandle = host.requestAnimationFrame(read);
|
|
1299
|
+
};
|
|
1300
|
+
const resizeTeardowns = new Map();
|
|
1301
|
+
const observe = (target) => {
|
|
1302
|
+
if (resizeTeardowns.has(target)) {
|
|
1303
|
+
return;
|
|
1304
|
+
}
|
|
1305
|
+
resizeTeardowns.set(target, observeResize(host, target, 'border-box', () => schedule()));
|
|
1306
|
+
};
|
|
1307
|
+
const syncChildren = () => {
|
|
1308
|
+
const children = new Set(Array.from(element.children));
|
|
1309
|
+
for (const [target, teardown] of resizeTeardowns) {
|
|
1310
|
+
if (target !== element && !children.has(target)) {
|
|
1311
|
+
teardown();
|
|
1312
|
+
resizeTeardowns.delete(target);
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
children.forEach(observe);
|
|
1316
|
+
};
|
|
1317
|
+
element.addEventListener('scroll', schedule, { passive: true });
|
|
1318
|
+
observe(element);
|
|
1319
|
+
syncChildren();
|
|
1320
|
+
let mutationObserver = null;
|
|
1321
|
+
if (typeof host.MutationObserver === 'function') {
|
|
1322
|
+
mutationObserver = new host.MutationObserver(() => {
|
|
1323
|
+
syncChildren();
|
|
1324
|
+
schedule();
|
|
1325
|
+
});
|
|
1326
|
+
mutationObserver.observe(element, { childList: true });
|
|
1327
|
+
}
|
|
1328
|
+
schedule();
|
|
1329
|
+
destroyRef.onDestroy(() => {
|
|
1330
|
+
destroyed = true;
|
|
1331
|
+
element.removeEventListener('scroll', schedule);
|
|
1332
|
+
mutationObserver?.disconnect();
|
|
1333
|
+
resizeTeardowns.forEach((teardown) => teardown());
|
|
1334
|
+
resizeTeardowns.clear();
|
|
1335
|
+
if (framePending && typeof host.cancelAnimationFrame === 'function') {
|
|
1336
|
+
host.cancelAnimationFrame(frameHandle);
|
|
1337
|
+
}
|
|
1338
|
+
framePending = false;
|
|
1339
|
+
});
|
|
1340
|
+
return state;
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
/**
|
|
1344
|
+
* Reports which edges of a scrollport still hide content and reflects them as
|
|
1345
|
+
* host attributes, so an edge shadow or fade appears only while there really
|
|
1346
|
+
* is something to scroll to in that direction.
|
|
1347
|
+
*
|
|
1348
|
+
* Put it on the element that scrolls (`overflow: auto` / `scroll`). The four
|
|
1349
|
+
* signals and the four logical host attributes are derived from one read of
|
|
1350
|
+
* the scroll metrics per animation frame; the attributes are present (empty
|
|
1351
|
+
* value) while true and absent otherwise:
|
|
1352
|
+
*
|
|
1353
|
+
* - `data-scroll-block-start` / `canScrollBlockStart()` - content hidden above
|
|
1354
|
+
* - `data-scroll-block-end` / `canScrollBlockEnd()` - content hidden below
|
|
1355
|
+
* - `data-scroll-inline-start` / `canScrollInlineStart()` - hidden toward inline start
|
|
1356
|
+
* - `data-scroll-inline-end` / `canScrollInlineEnd()` - hidden toward inline end
|
|
1357
|
+
*
|
|
1358
|
+
* Inline start / end follow the writing direction: in `dir="rtl"` the start
|
|
1359
|
+
* edge is on the right. The direction is derived from the scroll offset
|
|
1360
|
+
* itself, so a `dir="rtl"` subtree inside an LTR page reports correctly.
|
|
1361
|
+
*
|
|
1362
|
+
* The directive paints nothing. The four attributes (present only while true)
|
|
1363
|
+
* are its public, stable contract; every visual belongs to the consumer CSS,
|
|
1364
|
+
* keyed on them. Three common cues:
|
|
1365
|
+
*
|
|
1366
|
+
* Shadow (Material 2 elevate-on-scroll):
|
|
1367
|
+
*
|
|
1368
|
+
* ```css
|
|
1369
|
+
* .sheet[data-scroll-block-start] .bar { box-shadow: 0 2px 4px -2px rgb(0 0 0 / 0.3); }
|
|
1370
|
+
* ```
|
|
1371
|
+
*
|
|
1372
|
+
* Hairline that appears (iOS scroll-edge appearance; transparent border at rest):
|
|
1373
|
+
*
|
|
1374
|
+
* ```css
|
|
1375
|
+
* .sheet[data-scroll-block-start] .bar { border-block-end-color: var(--cngx-color-border); }
|
|
1376
|
+
* ```
|
|
1377
|
+
*
|
|
1378
|
+
* Tonal surface change (Material 3 top app bar):
|
|
1379
|
+
*
|
|
1380
|
+
* ```css
|
|
1381
|
+
* .sheet[data-scroll-block-start] .bar { background: var(--app-bar-scrolled-surface); }
|
|
1382
|
+
* ```
|
|
1383
|
+
*
|
|
1384
|
+
* Forced colors strips `box-shadow`, so a shadow-only cue disappears there;
|
|
1385
|
+
* prefer a border or pair the shadow with one under `forced-colors: active`.
|
|
1386
|
+
*
|
|
1387
|
+
* ```html
|
|
1388
|
+
* <div class="sheet" cngxScrollEdges #edges="cngxScrollEdges">...</div>
|
|
1389
|
+
* ```
|
|
1390
|
+
*
|
|
1391
|
+
* The edge state is purely visual and is not announced: the hidden content
|
|
1392
|
+
* stays in the DOM and in the reading order, and the scrollport remains
|
|
1393
|
+
* reachable by keyboard scrolling. Make the scrollport focusable (and named)
|
|
1394
|
+
* when it holds no focusable content of its own.
|
|
1395
|
+
*
|
|
1396
|
+
* Upgrade path: the attributes map 1:1 onto CSS
|
|
1397
|
+
* `@container scroll-state(scrollable: block-start)` and its siblings, so the
|
|
1398
|
+
* CSS can swap to native scroll-state queries once they are Baseline.
|
|
1399
|
+
*
|
|
1400
|
+
* @category common/layout
|
|
1401
|
+
* @docsKind primary
|
|
1402
|
+
* @wcag AA
|
|
1403
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/scroll/scroll-edges.directive.ts
|
|
1404
|
+
* @since 0.1.0
|
|
1405
|
+
* @relatedTo CngxStickyHeader, CngxScrollSpy, createScrollEdges
|
|
1406
|
+
* <example-url>http://localhost:4200/#/common/layout/scroll-edges/edge-shadows</example-url>
|
|
1407
|
+
*/
|
|
1408
|
+
class CngxScrollEdges {
|
|
1409
|
+
edges = createScrollEdges(inject(ElementRef).nativeElement, inject(DestroyRef), isPlatformBrowser(inject(PLATFORM_ID)) ? inject(DOCUMENT).defaultView : null);
|
|
1410
|
+
/** Content is hidden toward the block-start edge (above). */
|
|
1411
|
+
canScrollBlockStart = this.edges.canScrollBlockStart;
|
|
1412
|
+
/** Content is hidden toward the block-end edge (below). */
|
|
1413
|
+
canScrollBlockEnd = this.edges.canScrollBlockEnd;
|
|
1414
|
+
/** Content is hidden toward the inline-start edge (left in LTR, right in RTL). */
|
|
1415
|
+
canScrollInlineStart = this.edges.canScrollInlineStart;
|
|
1416
|
+
/** Content is hidden toward the inline-end edge (right in LTR, left in RTL). */
|
|
1417
|
+
canScrollInlineEnd = this.edges.canScrollInlineEnd;
|
|
1418
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxScrollEdges, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1419
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxScrollEdges, isStandalone: true, selector: "[cngxScrollEdges]", host: { properties: { "attr.data-scroll-block-start": "canScrollBlockStart() ? '' : null", "attr.data-scroll-block-end": "canScrollBlockEnd() ? '' : null", "attr.data-scroll-inline-start": "canScrollInlineStart() ? '' : null", "attr.data-scroll-inline-end": "canScrollInlineEnd() ? '' : null" } }, exportAs: ["cngxScrollEdges"], ngImport: i0 });
|
|
1420
|
+
}
|
|
1421
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxScrollEdges, decorators: [{
|
|
1422
|
+
type: Directive,
|
|
1423
|
+
args: [{
|
|
1424
|
+
selector: '[cngxScrollEdges]',
|
|
1425
|
+
exportAs: 'cngxScrollEdges',
|
|
1426
|
+
standalone: true,
|
|
1427
|
+
host: {
|
|
1428
|
+
'[attr.data-scroll-block-start]': "canScrollBlockStart() ? '' : null",
|
|
1429
|
+
'[attr.data-scroll-block-end]': "canScrollBlockEnd() ? '' : null",
|
|
1430
|
+
'[attr.data-scroll-inline-start]': "canScrollInlineStart() ? '' : null",
|
|
1431
|
+
'[attr.data-scroll-inline-end]': "canScrollInlineEnd() ? '' : null",
|
|
1432
|
+
},
|
|
1433
|
+
}]
|
|
1434
|
+
}] });
|
|
1435
|
+
|
|
849
1436
|
/**
|
|
850
1437
|
* Headless skeleton loading placeholder.
|
|
851
1438
|
*
|
|
@@ -904,16 +1491,7 @@ class CngxSkeleton {
|
|
|
904
1491
|
count = input(1, ...(ngDevMode ? [{ debugName: "count" }] : /* istanbul ignore next */ []));
|
|
905
1492
|
prefersReducedMotion;
|
|
906
1493
|
constructor() {
|
|
907
|
-
|
|
908
|
-
const pref = signal(false, ...(ngDevMode ? [{ debugName: "pref" }] : /* istanbul ignore next */ []));
|
|
909
|
-
if (win?.matchMedia) {
|
|
910
|
-
const mq = win.matchMedia('(prefers-reduced-motion: reduce)');
|
|
911
|
-
pref.set(mq.matches);
|
|
912
|
-
const listener = (e) => pref.set(e.matches);
|
|
913
|
-
mq.addEventListener('change', listener);
|
|
914
|
-
inject(DestroyRef).onDestroy(() => mq.removeEventListener('change', listener));
|
|
915
|
-
}
|
|
916
|
-
this.prefersReducedMotion = pref.asReadonly();
|
|
1494
|
+
this.prefersReducedMotion = createMediaQuerySignal('(prefers-reduced-motion: reduce)', inject(DestroyRef), inject(DOCUMENT).defaultView);
|
|
917
1495
|
}
|
|
918
1496
|
/** Whether the skeleton is in loading state. Mirrors the `cngxSkeleton` input. */
|
|
919
1497
|
loading = computed(() => this.skeleton(), ...(ngDevMode ? [{ debugName: "loading" }] : /* istanbul ignore next */ []));
|
|
@@ -948,7 +1526,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
948
1526
|
*
|
|
949
1527
|
* The observer is automatically recreated when `root`, `rootMargin`, or
|
|
950
1528
|
* `threshold` inputs change, and disconnected on destroy or when `enabled`
|
|
951
|
-
* is set to `false`.
|
|
1529
|
+
* is set to `false`. When `loading` settles back to `false` the sentinel is
|
|
1530
|
+
* re-observed, so a fetched page that did not push the sentinel out of view
|
|
1531
|
+
* still re-fires `loadMore` instead of stalling the list.
|
|
952
1532
|
*
|
|
953
1533
|
* ### Basic infinite list
|
|
954
1534
|
* ```html
|
|
@@ -1010,6 +1590,7 @@ class CngxInfiniteScroll {
|
|
|
1010
1590
|
el = inject((ElementRef));
|
|
1011
1591
|
doc = inject(DOCUMENT);
|
|
1012
1592
|
lastEmitTime = 0;
|
|
1593
|
+
observer = null;
|
|
1013
1594
|
constructor() {
|
|
1014
1595
|
const win = this.doc.defaultView;
|
|
1015
1596
|
if (!win) {
|
|
@@ -1026,8 +1607,13 @@ class CngxInfiniteScroll {
|
|
|
1026
1607
|
}
|
|
1027
1608
|
const isLoading = () => this.loading();
|
|
1028
1609
|
const resolvedRoot = root ? this.doc.querySelector(root) : null;
|
|
1610
|
+
if (isDevMode() && root && !resolvedRoot) {
|
|
1611
|
+
console.warn(`[cngxInfiniteScroll] root selector "${root}" matched no element - ` +
|
|
1612
|
+
'falling back to the viewport. A late-rendered root needs a re-bind of [root].');
|
|
1613
|
+
}
|
|
1029
1614
|
const observer = new IntersectionObserver((entries) => {
|
|
1030
|
-
|
|
1615
|
+
// batched records arrive oldest-first; only the newest reflects reality
|
|
1616
|
+
const entry = entries[entries.length - 1];
|
|
1031
1617
|
if (!entry.isIntersecting) {
|
|
1032
1618
|
return;
|
|
1033
1619
|
}
|
|
@@ -1042,7 +1628,29 @@ class CngxInfiniteScroll {
|
|
|
1042
1628
|
this.loadMore.emit();
|
|
1043
1629
|
}, { root: resolvedRoot, rootMargin, threshold });
|
|
1044
1630
|
observer.observe(this.el.nativeElement);
|
|
1045
|
-
|
|
1631
|
+
this.observer = observer;
|
|
1632
|
+
onCleanup(() => {
|
|
1633
|
+
observer.disconnect();
|
|
1634
|
+
this.observer = null;
|
|
1635
|
+
});
|
|
1636
|
+
});
|
|
1637
|
+
const loadingTransition = createTransitionTracker(() => this.loading());
|
|
1638
|
+
effect(() => {
|
|
1639
|
+
const loading = loadingTransition.current();
|
|
1640
|
+
const wasLoading = loadingTransition.previous();
|
|
1641
|
+
if (!wasLoading || loading) {
|
|
1642
|
+
return;
|
|
1643
|
+
}
|
|
1644
|
+
// IO reports intersection CHANGES only: when a fetched page does not
|
|
1645
|
+
// push the sentinel out of view there is no new entry after loading
|
|
1646
|
+
// settles, and the list stalls. Re-observing forces a fresh entry;
|
|
1647
|
+
// the debounce window is reset so that entry may emit immediately.
|
|
1648
|
+
untracked(() => {
|
|
1649
|
+
const sentinel = this.el.nativeElement;
|
|
1650
|
+
this.lastEmitTime = 0;
|
|
1651
|
+
this.observer?.unobserve(sentinel);
|
|
1652
|
+
this.observer?.observe(sentinel);
|
|
1653
|
+
});
|
|
1046
1654
|
});
|
|
1047
1655
|
}
|
|
1048
1656
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxInfiniteScroll, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
@@ -1071,6 +1679,15 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1071
1679
|
* meaning the header is now stuck. Toggles a CSS class for shadow,
|
|
1072
1680
|
* elevation, or background changes.
|
|
1073
1681
|
*
|
|
1682
|
+
* The sentinel is observed against the **nearest scroll-container ancestor**
|
|
1683
|
+
* (the first ancestor whose computed `overflow-y` is not `visible`), not the
|
|
1684
|
+
* page - that is the scrollport `position: sticky` resolves against, so
|
|
1685
|
+
* `isSticky()` reports the state the host actually has. A scrollport whose
|
|
1686
|
+
* height is content-driven never scrolls in the block axis, so a header inside
|
|
1687
|
+
* it never pins; in dev mode the directive warns once when it resolves against
|
|
1688
|
+
* such a scrollport. The observer is recreated when `threshold` changes,
|
|
1689
|
+
* matching the sibling observer directives.
|
|
1690
|
+
*
|
|
1074
1691
|
* ### Sticky header with shadow
|
|
1075
1692
|
* ```html
|
|
1076
1693
|
* <header cngxStickyHeader #sh="cngxStickyHeader"
|
|
@@ -1101,11 +1718,33 @@ class CngxStickyHeader {
|
|
|
1101
1718
|
isSticky = this.isStickyState.asReadonly();
|
|
1102
1719
|
el = inject((ElementRef));
|
|
1103
1720
|
doc = inject(DOCUMENT);
|
|
1721
|
+
/** Sentinel + scrollport resolved once after render; the observer effect keys on it. */
|
|
1722
|
+
observeSetup = signal(null, ...(ngDevMode ? [{ debugName: "observeSetup" }] : /* istanbul ignore next */ []));
|
|
1104
1723
|
constructor() {
|
|
1105
1724
|
const destroyRef = inject(DestroyRef);
|
|
1106
|
-
// IntersectionObserver sentinel pattern - host is stuck once the 1px sentinel leaves
|
|
1725
|
+
// IntersectionObserver sentinel pattern - host is stuck once the 1px sentinel leaves
|
|
1726
|
+
// the scrollport the host actually sticks to.
|
|
1107
1727
|
afterNextRender(() => {
|
|
1108
1728
|
const host = this.el.nativeElement;
|
|
1729
|
+
// Root the sentinel at the scrollport `position: sticky` resolves against, not the
|
|
1730
|
+
// viewport. Observing against the viewport reports a different thing entirely: a
|
|
1731
|
+
// header inside a never-scrolling scrollport would read `isSticky() === true` while
|
|
1732
|
+
// it visibly scrolls away with its content.
|
|
1733
|
+
const scrollport = this.resolveScrollParent(host);
|
|
1734
|
+
// A scrollport whose content fits never scrolls in the block axis, so a header
|
|
1735
|
+
// inside it can never pin - `isSticky()` stays false while the whole scrollport
|
|
1736
|
+
// moves. Flag the misconfiguration once, in dev only; a one-shot read here is
|
|
1737
|
+
// exactly what `afterNextRender` is for (no reactive-graph node, unlike a
|
|
1738
|
+
// dep-less effect). The 1px tolerance absorbs sub-pixel layout and browser-zoom
|
|
1739
|
+
// rounding: "cannot meaningfully scroll" instead of exact equality.
|
|
1740
|
+
if (isDevMode() &&
|
|
1741
|
+
scrollport &&
|
|
1742
|
+
scrollport.scrollHeight - scrollport.clientHeight <= 1) {
|
|
1743
|
+
console.warn('[cngxStickyHeader] resolves against a scroll container that cannot scroll ' +
|
|
1744
|
+
'in the block axis (client height equals scroll height), so this header ' +
|
|
1745
|
+
'will never pin. Give the scrollport a bounded block-size, or drop ' +
|
|
1746
|
+
'cngxStickyHeader.', { host, scrollport });
|
|
1747
|
+
}
|
|
1109
1748
|
const sentinel = this.doc.createElement('div');
|
|
1110
1749
|
sentinel.style.height = '1px';
|
|
1111
1750
|
sentinel.style.width = '1px';
|
|
@@ -1114,20 +1753,47 @@ class CngxStickyHeader {
|
|
|
1114
1753
|
sentinel.style.pointerEvents = 'none';
|
|
1115
1754
|
sentinel.setAttribute('aria-hidden', 'true');
|
|
1116
1755
|
host.parentElement?.insertBefore(sentinel, host);
|
|
1756
|
+
this.observeSetup.set({ sentinel, scrollport });
|
|
1757
|
+
destroyRef.onDestroy(() => sentinel.remove());
|
|
1758
|
+
});
|
|
1759
|
+
// Observer creation lives in an effect so a later threshold change
|
|
1760
|
+
// recreates it - the one-shot afterNextRender above only resolves DOM.
|
|
1761
|
+
effect((onCleanup) => {
|
|
1762
|
+
const setup = this.observeSetup();
|
|
1763
|
+
const threshold = this.threshold();
|
|
1764
|
+
if (!setup) {
|
|
1765
|
+
return;
|
|
1766
|
+
}
|
|
1117
1767
|
const observer = new IntersectionObserver((entries) => {
|
|
1118
|
-
|
|
1768
|
+
// batched records arrive oldest-first; only the newest reflects reality
|
|
1769
|
+
const isSticky = !entries[entries.length - 1].isIntersecting;
|
|
1119
1770
|
if (isSticky !== this.isStickyState()) {
|
|
1120
1771
|
this.isStickyState.set(isSticky);
|
|
1121
1772
|
this.stickyChange.emit(isSticky);
|
|
1122
1773
|
}
|
|
1123
|
-
}, { threshold:
|
|
1124
|
-
observer.observe(sentinel);
|
|
1125
|
-
|
|
1126
|
-
observer.disconnect();
|
|
1127
|
-
sentinel.remove();
|
|
1128
|
-
});
|
|
1774
|
+
}, { threshold, root: setup.scrollport });
|
|
1775
|
+
observer.observe(setup.sentinel);
|
|
1776
|
+
onCleanup(() => observer.disconnect());
|
|
1129
1777
|
});
|
|
1130
1778
|
}
|
|
1779
|
+
/**
|
|
1780
|
+
* The nearest ancestor that is a scroll container in the block axis - the scrollport
|
|
1781
|
+
* `position: sticky` resolves against. Walks up from the host's parent to the first
|
|
1782
|
+
* ancestor whose computed `overflow-y` is not `visible`; `null` means no such
|
|
1783
|
+
* ancestor, i.e. the header sticks to the viewport. A used `overflow-x` other than
|
|
1784
|
+
* `visible` coerces the computed `overflow-y` to `auto`, so this also catches a
|
|
1785
|
+
* horizontal scroll container (e.g. a data grid that scrolls sideways).
|
|
1786
|
+
*/
|
|
1787
|
+
resolveScrollParent(host) {
|
|
1788
|
+
const view = this.doc.defaultView;
|
|
1789
|
+
for (let node = host.parentElement; node; node = node.parentElement) {
|
|
1790
|
+
const overflowY = view?.getComputedStyle(node).overflowY;
|
|
1791
|
+
if (overflowY && overflowY !== 'visible') {
|
|
1792
|
+
return node;
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
return null;
|
|
1796
|
+
}
|
|
1131
1797
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxStickyHeader, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1132
1798
|
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxStickyHeader, isStandalone: true, selector: "[cngxStickyHeader]", inputs: { threshold: { classPropertyName: "threshold", publicName: "threshold", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { stickyChange: "stickyChange" }, host: { properties: { "class.cngx-sticky--active": "isSticky()" }, styleAttribute: "position: sticky; top: 0; z-index: var(--cngx-sticky-z-index, 1)" }, exportAs: ["cngxStickyHeader"], ngImport: i0 });
|
|
1133
1799
|
}
|
|
@@ -1151,6 +1817,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1151
1817
|
* and reports the one with the highest intersection ratio as the active section.
|
|
1152
1818
|
* Ideal for scroll-based navigation highlighting and reading progress.
|
|
1153
1819
|
*
|
|
1820
|
+
* Section IDs are resolved when the inputs change - sections rendered later
|
|
1821
|
+
* (`@if`/`@defer`) are not picked up automatically; re-bind `[cngxScrollSpy]`
|
|
1822
|
+
* once they exist. In dev mode the directive warns about IDs it cannot find.
|
|
1823
|
+
*
|
|
1154
1824
|
* ### Navigation highlighting
|
|
1155
1825
|
* ```html
|
|
1156
1826
|
* <nav [cngxScrollSpy]="['intro', 'features', 'pricing']"
|
|
@@ -1223,10 +1893,19 @@ class CngxScrollSpy {
|
|
|
1223
1893
|
const elements = ids
|
|
1224
1894
|
.map((id) => this.doc.getElementById(id))
|
|
1225
1895
|
.filter((el) => el !== null);
|
|
1896
|
+
if (isDevMode() && elements.length < ids.length) {
|
|
1897
|
+
const missing = ids.filter((id) => !this.doc.getElementById(id));
|
|
1898
|
+
console.warn(`[cngxScrollSpy] section id(s) not found: ${missing.join(', ')}. ` +
|
|
1899
|
+
'Late-rendered sections are not observed - re-bind [cngxScrollSpy] once they exist.');
|
|
1900
|
+
}
|
|
1226
1901
|
if (elements.length === 0) {
|
|
1227
1902
|
return undefined;
|
|
1228
1903
|
}
|
|
1229
1904
|
const resolvedRoot = rootSelector ? this.doc.querySelector(rootSelector) : null;
|
|
1905
|
+
if (isDevMode() && rootSelector && !resolvedRoot) {
|
|
1906
|
+
console.warn(`[cngxScrollSpy] root selector "${rootSelector}" matched no element - ` +
|
|
1907
|
+
'falling back to the viewport. A late-rendered root needs a re-bind of [root].');
|
|
1908
|
+
}
|
|
1230
1909
|
const observer = new IntersectionObserver((entries) => {
|
|
1231
1910
|
entries.forEach((entry) => this.ratios.set(entry.target.id, entry.intersectionRatio));
|
|
1232
1911
|
const best = Array.from(this.ratios).reduce((acc, [id, ratio]) => ratio >= thresholdValue && ratio > acc.ratio ? { id, ratio } : acc, { id: null, ratio: 0 });
|
|
@@ -1293,23 +1972,27 @@ class CngxTruncate {
|
|
|
1293
1972
|
/** Whether the text content actually exceeds the line limit and is being clamped. */
|
|
1294
1973
|
isClamped = this.isClampedState.asReadonly();
|
|
1295
1974
|
el = inject((ElementRef));
|
|
1296
|
-
|
|
1975
|
+
stopResize = null;
|
|
1297
1976
|
rafHandle = null;
|
|
1298
1977
|
// null strips the host binding - preferred over an empty string for -webkit-line-clamp.
|
|
1299
1978
|
/** @internal */
|
|
1300
|
-
clampValue = () => (this.expanded() ? null : String(this.lines()));
|
|
1979
|
+
clampValue = computed(() => (this.expanded() ? null : String(this.lines())), ...(ngDevMode ? [{ debugName: "clampValue" }] : /* istanbul ignore next */ []));
|
|
1301
1980
|
/** @internal */
|
|
1302
|
-
displayValue = () => (this.expanded() ? null : '-webkit-box');
|
|
1981
|
+
displayValue = computed(() => (this.expanded() ? null : '-webkit-box'), ...(ngDevMode ? [{ debugName: "displayValue" }] : /* istanbul ignore next */ []));
|
|
1303
1982
|
/** @internal */
|
|
1304
|
-
orientValue = () => (this.expanded() ? null : 'vertical');
|
|
1983
|
+
orientValue = computed(() => (this.expanded() ? null : 'vertical'), ...(ngDevMode ? [{ debugName: "orientValue" }] : /* istanbul ignore next */ []));
|
|
1305
1984
|
/** @internal */
|
|
1306
|
-
overflowValue = () => (this.expanded() ? null : 'hidden');
|
|
1985
|
+
overflowValue = computed(() => (this.expanded() ? null : 'hidden'), ...(ngDevMode ? [{ debugName: "overflowValue" }] : /* istanbul ignore next */ []));
|
|
1307
1986
|
constructor() {
|
|
1308
1987
|
const destroyRef = inject(DestroyRef);
|
|
1988
|
+
// SSR guard: no window, no measuring - the style bindings above still render.
|
|
1989
|
+
const win = inject(DOCUMENT).defaultView;
|
|
1990
|
+
if (!win) {
|
|
1991
|
+
return;
|
|
1992
|
+
}
|
|
1309
1993
|
afterNextRender(() => {
|
|
1310
1994
|
this.checkClamped();
|
|
1311
|
-
this.
|
|
1312
|
-
this.observer.observe(this.el.nativeElement);
|
|
1995
|
+
this.stopResize = observeResize(win, this.el.nativeElement, 'content-box', () => this.checkClamped());
|
|
1313
1996
|
});
|
|
1314
1997
|
// Re-check after expanded/lines change; RAF ensures styles are applied first.
|
|
1315
1998
|
effect(() => {
|
|
@@ -1319,7 +2002,7 @@ class CngxTruncate {
|
|
|
1319
2002
|
this.rafHandle = requestAnimationFrame(() => this.checkClamped());
|
|
1320
2003
|
});
|
|
1321
2004
|
destroyRef.onDestroy(() => {
|
|
1322
|
-
this.
|
|
2005
|
+
this.stopResize?.();
|
|
1323
2006
|
this.cancelRaf();
|
|
1324
2007
|
});
|
|
1325
2008
|
}
|
|
@@ -1368,7 +2051,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1368
2051
|
* construction. The `<mark>` element has correct native SR semantics (announced
|
|
1369
2052
|
* as "highlighted" in most screen readers).
|
|
1370
2053
|
*
|
|
1371
|
-
*
|
|
2054
|
+
* The original text nodes are kept by reference and re-inserted when the
|
|
2055
|
+
* term changes or the directive is destroyed - Angular bindings targeting
|
|
2056
|
+
* them (interpolations, structural directives) stay live.
|
|
1372
2057
|
*
|
|
1373
2058
|
* ### Search result highlighting
|
|
1374
2059
|
* ```html
|
|
@@ -1403,20 +2088,26 @@ class CngxHighlight {
|
|
|
1403
2088
|
matchCount = this.matchCountState.asReadonly();
|
|
1404
2089
|
el = inject((ElementRef));
|
|
1405
2090
|
doc = inject(DOCUMENT);
|
|
1406
|
-
/**
|
|
1407
|
-
|
|
2091
|
+
/**
|
|
2092
|
+
* The text nodes replaced by the current highlight pass, by reference,
|
|
2093
|
+
* with the nodes standing in for them. Undone before every re-highlight
|
|
2094
|
+
* and on destroy - re-inserting the original references keeps LView
|
|
2095
|
+
* bindings (interpolations) attached to live DOM.
|
|
2096
|
+
*/
|
|
2097
|
+
replacements = [];
|
|
1408
2098
|
initialized = signal(false, ...(ngDevMode ? [{ debugName: "initialized" }] : /* istanbul ignore next */ []));
|
|
1409
2099
|
constructor() {
|
|
1410
|
-
inject(DestroyRef).onDestroy(() => this.
|
|
2100
|
+
inject(DestroyRef).onDestroy(() => this.restoreNodes());
|
|
1411
2101
|
afterNextRender(() => {
|
|
1412
2102
|
this.initialized.set(true);
|
|
1413
2103
|
});
|
|
1414
|
-
//
|
|
2104
|
+
// The highlight pass writes matchCountState - untracked, so the write
|
|
2105
|
+
// cannot re-trigger this effect.
|
|
1415
2106
|
effect(() => {
|
|
1416
2107
|
const term = this.term();
|
|
1417
2108
|
const caseSensitive = this.caseSensitive();
|
|
1418
2109
|
if (this.initialized()) {
|
|
1419
|
-
this.applyHighlight(term, caseSensitive);
|
|
2110
|
+
untracked(() => this.applyHighlight(term, caseSensitive));
|
|
1420
2111
|
}
|
|
1421
2112
|
});
|
|
1422
2113
|
}
|
|
@@ -1426,12 +2117,7 @@ class CngxHighlight {
|
|
|
1426
2117
|
*/
|
|
1427
2118
|
applyHighlight(term, caseSensitive) {
|
|
1428
2119
|
const host = this.el.nativeElement;
|
|
1429
|
-
|
|
1430
|
-
this.originalNodes = Array.from(host.childNodes).map((n) => n.cloneNode(true));
|
|
1431
|
-
}
|
|
1432
|
-
else {
|
|
1433
|
-
this.restoreNodes(host);
|
|
1434
|
-
}
|
|
2120
|
+
this.restoreNodes();
|
|
1435
2121
|
if (!term) {
|
|
1436
2122
|
this.matchCountState.set(0);
|
|
1437
2123
|
return;
|
|
@@ -1469,26 +2155,28 @@ class CngxHighlight {
|
|
|
1469
2155
|
if (lastIndex < text.length) {
|
|
1470
2156
|
fragment.appendChild(this.doc.createTextNode(text.slice(lastIndex)));
|
|
1471
2157
|
}
|
|
2158
|
+
// Capture before replaceChild - inserting a fragment empties it.
|
|
2159
|
+
const inserted = Array.from(fragment.childNodes);
|
|
1472
2160
|
textNode.parentNode.replaceChild(fragment, textNode);
|
|
2161
|
+
this.replacements.push({ original: textNode, inserted });
|
|
1473
2162
|
}
|
|
1474
2163
|
this.matchCountState.set(count);
|
|
1475
2164
|
}
|
|
1476
|
-
/**
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
for (const node of this.originalNodes) {
|
|
1490
|
-
host.appendChild(node.cloneNode(true));
|
|
2165
|
+
/** Puts the original text nodes back and removes the highlight nodes. */
|
|
2166
|
+
restoreNodes() {
|
|
2167
|
+
for (const { original, inserted } of this.replacements) {
|
|
2168
|
+
const parent = inserted[0]?.parentNode;
|
|
2169
|
+
if (!parent) {
|
|
2170
|
+
continue;
|
|
2171
|
+
}
|
|
2172
|
+
parent.insertBefore(original, inserted[0]);
|
|
2173
|
+
for (const node of inserted) {
|
|
2174
|
+
if (node.parentNode === parent) {
|
|
2175
|
+
parent.removeChild(node);
|
|
2176
|
+
}
|
|
2177
|
+
}
|
|
1491
2178
|
}
|
|
2179
|
+
this.replacements = [];
|
|
1492
2180
|
}
|
|
1493
2181
|
/** Escapes special regex characters in the search term. */
|
|
1494
2182
|
escapeRegex(str) {
|
|
@@ -1506,6 +2194,86 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1506
2194
|
}]
|
|
1507
2195
|
}], ctorParameters: () => [], propDecorators: { term: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxHighlight", required: false }] }], caseSensitive: [{ type: i0.Input, args: [{ isSignal: true, alias: "highlightCaseSensitive", required: false }] }] } });
|
|
1508
2196
|
|
|
2197
|
+
/**
|
|
2198
|
+
* The English layout section: the single source of the layout atoms'
|
|
2199
|
+
* English copy. `CNGX_LAYOUT_I18N` defaults to it.
|
|
2200
|
+
*
|
|
2201
|
+
* @category common/layout/i18n
|
|
2202
|
+
* @since 0.1.0
|
|
2203
|
+
* @relatedTo CNGX_LAYOUT_I18N
|
|
2204
|
+
*/
|
|
2205
|
+
const CNGX_LAYOUT_LANGUAGE_EN = {
|
|
2206
|
+
expandableTextMore: 'Show more',
|
|
2207
|
+
expandableTextLess: 'Show less',
|
|
2208
|
+
};
|
|
2209
|
+
|
|
2210
|
+
/** @internal The English section with the active pack's layout section on top. */
|
|
2211
|
+
const layoutBundleFromPack = createLanguageSection('layout', CNGX_LAYOUT_LANGUAGE_EN);
|
|
2212
|
+
/**
|
|
2213
|
+
* DI token for the layout i18n bundle. `providedIn: 'root'`: the layout
|
|
2214
|
+
* section of the active language pack over the English defaults; the value
|
|
2215
|
+
* is a `Signal`, shared by every reader under one injector.
|
|
2216
|
+
*
|
|
2217
|
+
* @category common/layout/i18n
|
|
2218
|
+
* @wcag AA
|
|
2219
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/i18n/layout-i18n.ts
|
|
2220
|
+
* @since 0.1.0
|
|
2221
|
+
* @relatedTo CngxExpandableText
|
|
2222
|
+
*/
|
|
2223
|
+
const CNGX_LAYOUT_I18N = new InjectionToken('CngxLayoutI18n', {
|
|
2224
|
+
providedIn: 'root',
|
|
2225
|
+
factory: layoutBundleFromPack,
|
|
2226
|
+
});
|
|
2227
|
+
/** @internal */
|
|
2228
|
+
function defineLayoutI18nFeature(fn) {
|
|
2229
|
+
return Object.assign(fn, { _target: 'i18n' });
|
|
2230
|
+
}
|
|
2231
|
+
/**
|
|
2232
|
+
* Override layout labels via a partial bundle - unset keys keep the
|
|
2233
|
+
* language pack's copy, or the English default. Pass a `Signal` of a partial
|
|
2234
|
+
* bundle to switch languages at runtime.
|
|
2235
|
+
*
|
|
2236
|
+
* @category common/layout/i18n
|
|
2237
|
+
* @since 0.1.0
|
|
2238
|
+
*/
|
|
2239
|
+
function withLayoutI18nLabels(overrides) {
|
|
2240
|
+
return defineLayoutI18nFeature((bundle) => createOverrideMerge(bundle, overrides));
|
|
2241
|
+
}
|
|
2242
|
+
/**
|
|
2243
|
+
* Provider for the layout i18n bundle. Returns a plain `Provider`, so it
|
|
2244
|
+
* also scopes a subtree through `viewProviders`. The features apply on top
|
|
2245
|
+
* of the active language pack.
|
|
2246
|
+
*
|
|
2247
|
+
* ```ts
|
|
2248
|
+
* bootstrapApplication(AppComponent, {
|
|
2249
|
+
* providers: [
|
|
2250
|
+
* provideLayoutI18n(
|
|
2251
|
+
* withLayoutI18nLabels({ expandableTextMore: 'Mehr anzeigen', expandableTextLess: 'Weniger anzeigen' }),
|
|
2252
|
+
* ),
|
|
2253
|
+
* ],
|
|
2254
|
+
* });
|
|
2255
|
+
* ```
|
|
2256
|
+
*
|
|
2257
|
+
* @category common/layout/i18n
|
|
2258
|
+
* @since 0.1.0
|
|
2259
|
+
*/
|
|
2260
|
+
function provideLayoutI18n(...features) {
|
|
2261
|
+
return {
|
|
2262
|
+
provide: CNGX_LAYOUT_I18N,
|
|
2263
|
+
useFactory: () => features.reduce((bundle, feat) => feat(bundle), layoutBundleFromPack()),
|
|
2264
|
+
};
|
|
2265
|
+
}
|
|
2266
|
+
/**
|
|
2267
|
+
* Inject the resolved layout i18n bundle signal. Read it inside a
|
|
2268
|
+
* `computed()` or template so a runtime override flip re-derives.
|
|
2269
|
+
*
|
|
2270
|
+
* @category common/layout/i18n
|
|
2271
|
+
* @since 0.1.0
|
|
2272
|
+
*/
|
|
2273
|
+
function injectLayoutI18n() {
|
|
2274
|
+
return inject(CNGX_LAYOUT_I18N);
|
|
2275
|
+
}
|
|
2276
|
+
|
|
1509
2277
|
/**
|
|
1510
2278
|
* Marks a custom toggle template inside `cngx-expandable-text`.
|
|
1511
2279
|
*
|
|
@@ -1526,11 +2294,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1526
2294
|
* @relatedTo CngxExpandableText, CngxTruncate
|
|
1527
2295
|
*/
|
|
1528
2296
|
class CngxExpandableToggle {
|
|
1529
|
-
templateRef;
|
|
1530
|
-
|
|
1531
|
-
this.templateRef = templateRef;
|
|
1532
|
-
}
|
|
1533
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxExpandableToggle, deps: [{ token: i0.TemplateRef }], target: i0.ɵɵFactoryTarget.Directive });
|
|
2297
|
+
templateRef = inject(TemplateRef);
|
|
2298
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxExpandableToggle, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1534
2299
|
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.4", type: CngxExpandableToggle, isStandalone: true, selector: "ng-template[cngxExpandableToggle]", ngImport: i0 });
|
|
1535
2300
|
}
|
|
1536
2301
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxExpandableToggle, decorators: [{
|
|
@@ -1539,7 +2304,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1539
2304
|
selector: 'ng-template[cngxExpandableToggle]',
|
|
1540
2305
|
standalone: true,
|
|
1541
2306
|
}]
|
|
1542
|
-
}]
|
|
2307
|
+
}] });
|
|
1543
2308
|
/**
|
|
1544
2309
|
* Molecule wrapping `CngxTruncate` with a built-in expand/collapse toggle.
|
|
1545
2310
|
*
|
|
@@ -1580,29 +2345,43 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1580
2345
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/text/expandable-text.ts
|
|
1581
2346
|
* @since 0.1.0
|
|
1582
2347
|
* @relatedTo CngxTruncate, CngxExpandableToggle, CngxHighlight
|
|
2348
|
+
* @slot cngxExpandableToggle Replaces the show-more control; gets the current expanded state.
|
|
1583
2349
|
* <example-url>http://localhost:4200/#/common/layout/expandable-text/auto-toggle</example-url>
|
|
1584
2350
|
* <example-url>http://localhost:4200/#/common/layout/expandable-text/custom-labels</example-url>
|
|
1585
2351
|
* <example-url>http://localhost:4200/#/common/layout/expandable-text/custom-toggle-template</example-url>
|
|
1586
2352
|
*/
|
|
1587
2353
|
class CngxExpandableText {
|
|
2354
|
+
i18n = injectLayoutI18n();
|
|
1588
2355
|
/** Maximum visible lines when collapsed. */
|
|
1589
2356
|
lines = input(3, ...(ngDevMode ? [{ debugName: "lines" }] : /* istanbul ignore next */ []));
|
|
1590
2357
|
/** Whether the text is expanded. Supports two-way `[(expanded)]` binding. */
|
|
1591
2358
|
expanded = model(false, ...(ngDevMode ? [{ debugName: "expanded" }] : /* istanbul ignore next */ []));
|
|
1592
|
-
/**
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
2359
|
+
/**
|
|
2360
|
+
* Label for the "show more" button. Unbound, it follows
|
|
2361
|
+
* `CNGX_LAYOUT_I18N.expandableTextMore`.
|
|
2362
|
+
*/
|
|
2363
|
+
moreLabel = input(undefined, ...(ngDevMode ? [{ debugName: "moreLabel" }] : /* istanbul ignore next */ []));
|
|
2364
|
+
/**
|
|
2365
|
+
* Label for the "show less" button. Unbound, it follows
|
|
2366
|
+
* `CNGX_LAYOUT_I18N.expandableTextLess`.
|
|
2367
|
+
*/
|
|
2368
|
+
lessLabel = input(undefined, ...(ngDevMode ? [{ debugName: "lessLabel" }] : /* istanbul ignore next */ []));
|
|
2369
|
+
resolvedMoreLabel = computed(() => this.moreLabel() ?? this.i18n().expandableTextMore, ...(ngDevMode ? [{ debugName: "resolvedMoreLabel" }] : /* istanbul ignore next */ []));
|
|
2370
|
+
resolvedLessLabel = computed(() => this.lessLabel() ?? this.i18n().expandableTextLess, ...(ngDevMode ? [{ debugName: "resolvedLessLabel" }] : /* istanbul ignore next */ []));
|
|
1596
2371
|
/** Optional custom toggle template projected by the consumer. */
|
|
1597
2372
|
customToggle = contentChild(CngxExpandableToggle, ...(ngDevMode ? [{ debugName: "customToggle" }] : /* istanbul ignore next */ []));
|
|
1598
|
-
/**
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
2373
|
+
/** Stable toggle closure - a fresh closure per context would defeat the equal fn below. */
|
|
2374
|
+
toggleFn = () => this.expanded.set(!this.expanded());
|
|
2375
|
+
/**
|
|
2376
|
+
* Template context for the custom toggle. Structural `equal` fn so
|
|
2377
|
+
* `ngTemplateOutletContext` does not rebind the embedded view on every
|
|
2378
|
+
* CD cycle (same rule as the CngxTag slot contexts).
|
|
2379
|
+
*/
|
|
2380
|
+
toggleContext = computed(() => ({
|
|
2381
|
+
$implicit: this.expanded(),
|
|
2382
|
+
expanded: this.expanded(),
|
|
2383
|
+
toggle: this.toggleFn,
|
|
2384
|
+
}), { ...(ngDevMode ? { debugName: "toggleContext" } : /* istanbul ignore next */ {}), equal: (a, b) => a.expanded === b.expanded });
|
|
1606
2385
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxExpandableText, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1607
2386
|
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.4", type: CngxExpandableText, isStandalone: true, selector: "cngx-expandable-text", inputs: { lines: { classPropertyName: "lines", publicName: "lines", isSignal: true, isRequired: false, transformFunction: null }, expanded: { classPropertyName: "expanded", publicName: "expanded", isSignal: true, isRequired: false, transformFunction: null }, moreLabel: { classPropertyName: "moreLabel", publicName: "moreLabel", isSignal: true, isRequired: false, transformFunction: null }, lessLabel: { classPropertyName: "lessLabel", publicName: "lessLabel", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { expanded: "expandedChange" }, host: { styleAttribute: "display:block" }, queries: [{ propertyName: "customToggle", first: true, predicate: CngxExpandableToggle, descendants: true, isSignal: true }], exportAs: ["cngxExpandableText"], ngImport: i0, template: `
|
|
1608
2387
|
<div [cngxTruncate]="lines()" [(expanded)]="expanded" #trunc="cngxTruncate">
|
|
@@ -1621,7 +2400,7 @@ class CngxExpandableText {
|
|
|
1621
2400
|
[attr.aria-expanded]="expanded()"
|
|
1622
2401
|
(click)="expanded.set(!expanded())"
|
|
1623
2402
|
>
|
|
1624
|
-
{{ expanded() ?
|
|
2403
|
+
{{ expanded() ? resolvedLessLabel() : resolvedMoreLabel() }}
|
|
1625
2404
|
</button>
|
|
1626
2405
|
}
|
|
1627
2406
|
}
|
|
@@ -1656,7 +2435,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1656
2435
|
[attr.aria-expanded]="expanded()"
|
|
1657
2436
|
(click)="expanded.set(!expanded())"
|
|
1658
2437
|
>
|
|
1659
|
-
{{ expanded() ?
|
|
2438
|
+
{{ expanded() ? resolvedLessLabel() : resolvedMoreLabel() }}
|
|
1660
2439
|
</button>
|
|
1661
2440
|
}
|
|
1662
2441
|
}
|
|
@@ -1672,5 +2451,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1672
2451
|
* Generated bundle index. Do not edit.
|
|
1673
2452
|
*/
|
|
1674
2453
|
|
|
1675
|
-
export { CngxBackdrop, CngxDrawer, CngxDrawerContent, CngxDrawerPanel, CngxExpandableText, CngxExpandableToggle, CngxHighlight, CngxInfiniteScroll, CngxIntersectionObserver, CngxMediaQuery, CngxResizeObserver, CngxScrollLock, CngxScrollSpy, CngxSkeleton, CngxStickyHeader, CngxTruncate, injectMediaQuery, injectQueryParamSync };
|
|
2454
|
+
export { CNGX_CONTAINER_SIZE, CNGX_LAYOUT_I18N, CNGX_LAYOUT_LANGUAGE_EN, CngxBackdrop, CngxContainer, CngxDrawer, CngxDrawerContent, CngxDrawerPanel, CngxExpandableText, CngxExpandableToggle, CngxHighlight, CngxInfiniteScroll, CngxIntersectionObserver, CngxMediaQuery, CngxResizeObserver, CngxScrollEdges, CngxScrollLock, CngxScrollSpy, CngxSkeleton, CngxStickyHeader, CngxTruncate, createContainerSize, createResizeSignal, createScrollEdges, createScrollLock, injectContainerSize, injectLayoutI18n, injectMediaQuery, injectQueryParamSync, observeResize, provideLayoutI18n, withLayoutI18nLabels };
|
|
1676
2455
|
//# sourceMappingURL=cngx-common-layout.mjs.map
|