@cngx/common 0.1.0-rc.8 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/a11y/README.md +15 -2
- package/button/README.md +258 -0
- package/command/README.md +42 -2
- package/data/README.md +15 -12
- package/fesm2022/cngx-common-a11y.mjs +1076 -319
- package/fesm2022/cngx-common-a11y.mjs.map +1 -1
- package/fesm2022/cngx-common-audio.mjs +99 -77
- package/fesm2022/cngx-common-audio.mjs.map +1 -1
- package/fesm2022/cngx-common-button.mjs +1084 -0
- package/fesm2022/cngx-common-button.mjs.map +1 -0
- package/fesm2022/cngx-common-card.mjs +138 -78
- package/fesm2022/cngx-common-card.mjs.map +1 -1
- package/fesm2022/cngx-common-chart.mjs +799 -327
- package/fesm2022/cngx-common-chart.mjs.map +1 -1
- package/fesm2022/cngx-common-command.mjs +101 -25
- package/fesm2022/cngx-common-command.mjs.map +1 -1
- package/fesm2022/cngx-common-data.mjs +861 -423
- package/fesm2022/cngx-common-data.mjs.map +1 -1
- package/fesm2022/cngx-common-dialog.mjs +198 -160
- package/fesm2022/cngx-common-dialog.mjs.map +1 -1
- package/fesm2022/cngx-common-display.mjs +693 -329
- package/fesm2022/cngx-common-display.mjs.map +1 -1
- package/fesm2022/cngx-common-interactive.mjs +7303 -2774
- package/fesm2022/cngx-common-interactive.mjs.map +1 -1
- package/fesm2022/cngx-common-layout.mjs +2174 -442
- package/fesm2022/cngx-common-layout.mjs.map +1 -1
- package/fesm2022/cngx-common-menu-button.mjs +557 -0
- package/fesm2022/cngx-common-menu-button.mjs.map +1 -0
- package/fesm2022/cngx-common-popover.mjs +2109 -557
- package/fesm2022/cngx-common-popover.mjs.map +1 -1
- package/fesm2022/cngx-common-stepper.mjs +548 -419
- package/fesm2022/cngx-common-stepper.mjs.map +1 -1
- package/fesm2022/cngx-common-tabs.mjs +442 -331
- package/fesm2022/cngx-common-tabs.mjs.map +1 -1
- package/fesm2022/cngx-common-timeline.mjs +44 -71
- package/fesm2022/cngx-common-timeline.mjs.map +1 -1
- package/fesm2022/cngx-common.mjs +10 -10
- package/fesm2022/cngx-common.mjs.map +1 -1
- package/interactive/README.md +30 -19
- package/layout/README.md +17 -1
- package/menu-button/README.md +234 -0
- package/package.json +31 -8
- package/popover/README.md +81 -4
- package/popover/tooltip-indicator.scss +52 -0
- package/schematics/collection.json +9 -0
- package/schematics/ng-add/index.js +9 -0
- package/schematics/ng-add/schema.json +96 -0
- package/schematics/package.json +3 -0
- package/stepper/README.md +5 -5
- package/theming/components/cngx-accordion.css +36 -7
- package/theming/components/cngx-async.css +185 -37
- package/theming/components/cngx-backdrop.css +3 -1
- package/theming/components/cngx-badge.css +20 -5
- package/theming/components/cngx-bottom-sheet.css +2 -0
- package/theming/components/cngx-breadcrumb.css +3 -1
- package/theming/components/cngx-button-group.css +325 -0
- package/theming/components/cngx-button-toggle.css +55 -23
- package/theming/components/cngx-button.css +975 -0
- package/theming/components/cngx-data-grid.css +2 -0
- package/theming/components/cngx-dialog.css +3 -1
- package/theming/components/cngx-divider.css +24 -9
- package/theming/components/cngx-drawer.css +153 -0
- package/theming/components/cngx-icon-glyph.css +76 -0
- package/theming/components/cngx-listbox.css +79 -25
- package/theming/components/cngx-menu.css +112 -52
- package/theming/components/cngx-nav.css +1220 -0
- package/theming/components/cngx-popover-sheet.css +434 -0
- package/theming/components/cngx-popover.css +37 -9
- package/theming/components/cngx-recycler-placeholder.css +2 -0
- package/theming/components/cngx-ripple.css +74 -16
- package/theming/components/cngx-sidebar.css +71 -0
- package/theming/components/cngx-slider.css +3 -1
- package/theming/components/cngx-tooltip.css +2 -0
- package/timeline/README.md +2 -2
- package/types/cngx-common-a11y.d.ts +488 -112
- package/types/cngx-common-audio.d.ts +60 -88
- package/types/cngx-common-button.d.ts +698 -0
- package/types/cngx-common-card.d.ts +104 -78
- package/types/cngx-common-chart.d.ts +677 -389
- package/types/cngx-common-command.d.ts +55 -41
- package/types/cngx-common-data.d.ts +506 -360
- package/types/cngx-common-dialog.d.ts +94 -127
- package/types/cngx-common-display.d.ts +475 -300
- package/types/cngx-common-interactive.d.ts +4383 -1721
- package/types/cngx-common-layout.d.ts +1399 -288
- package/types/cngx-common-menu-button.d.ts +382 -0
- package/types/cngx-common-popover.d.ts +990 -268
- package/types/cngx-common-stepper.d.ts +374 -465
- package/types/cngx-common-tabs.d.ts +309 -403
- package/types/cngx-common-timeline.d.ts +50 -109
|
@@ -1,13 +1,122 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { input, output, inject, ElementRef, signal, afterNextRender, effect, Directive, computed,
|
|
2
|
+
import { input, output, inject, ElementRef, signal, afterNextRender, effect, Directive, InjectionToken, computed, Injector, HostAttributeToken, DestroyRef, untracked, ViewEncapsulation, ChangeDetectionStrategy, Component, model, PLATFORM_ID, linkedSignal, TemplateRef, contentChild } from '@angular/core';
|
|
3
|
+
import { CNGX_LIVE_SURFACE_SELECTOR, createSlotRegistry, createOverrideMerge, createCloseWatcher, observeMediaQuery, createMediaQuerySignal, coerceSignal, nextUid, createTransitionTracker } from '@cngx/core/utils';
|
|
4
|
+
import { cngxDevWarn, CNGX_ICON_X, CNGX_ICON_MENU, CNGX_ICON_PANEL_CLOSE, CNGX_ICON_PANEL_OPEN, clamp } from '@cngx/utils';
|
|
3
5
|
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';
|
|
7
6
|
import * as i1 from '@cngx/common/a11y';
|
|
8
|
-
import { CngxFocusTrap } from '@cngx/common/a11y';
|
|
7
|
+
import { CngxFocusTrap, CNGX_FOCUS_TRAP_DRIVER, CNGX_FOCUS_RESTORE_DRIVER, CngxFocusRestore } from '@cngx/common/a11y';
|
|
8
|
+
import * as i2 from '@cngx/common/interactive';
|
|
9
|
+
import { createHotkeyScope, CNGX_HOTKEY_SCOPE, CngxClickOutside, CNGX_CLICK_OUTSIDE_DRIVER, createActivationKeyHandler, CngxHoverIntent, CNGX_HOVER_INTENT_DRIVER } from '@cngx/common/interactive';
|
|
10
|
+
import { injectWindow } from '@cngx/core/tokens';
|
|
11
|
+
import { createLanguageSection, formatMessage, createSectionBundle } from '@cngx/core/i18n';
|
|
12
|
+
import { toSignal } from '@angular/core/rxjs-interop';
|
|
9
13
|
import { Router, ActivatedRoute } from '@angular/router';
|
|
10
|
-
import
|
|
14
|
+
import * as i2$1 from '@cngx/common/button';
|
|
15
|
+
import { CngxButtonAdornment, provideButtonHost, CngxButtonBrain } from '@cngx/common/button';
|
|
16
|
+
import { CngxIconSvg } from '@cngx/common/display';
|
|
17
|
+
import { injectDirection, injectEffectiveMotion } from '@cngx/core';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @internal Elements that stay live in every scope:
|
|
21
|
+
*
|
|
22
|
+
* - CDK focus-trap anchors: an inert anchor cannot take focus, so the trap
|
|
23
|
+
* next to it stops wrapping and Tab leaves the modal.
|
|
24
|
+
* - Live regions, announcer containers (the CDK announcer) and every
|
|
25
|
+
* element marked with `CNGX_LIVE_SURFACE_ATTR` (the toast and banner
|
|
26
|
+
* outlets): inert content leaves the accessibility tree, and an
|
|
27
|
+
* announcement written into it is never spoken.
|
|
28
|
+
* - The CDK overlay container: overlays opened from inside the modal render
|
|
29
|
+
* there, outside the host.
|
|
30
|
+
* - A `CngxBackdrop` (static `data-cngx-backdrop` marker): it holds no
|
|
31
|
+
* focusable content, and inerting it would swallow its `backdropClick`. The
|
|
32
|
+
* marker does not wait for the visible class, which can land after a modal
|
|
33
|
+
* surface engaged in the same pass.
|
|
34
|
+
*/
|
|
35
|
+
const KEEP_LIVE_SELECTOR = [
|
|
36
|
+
'.cdk-focus-trap-anchor',
|
|
37
|
+
'[aria-live]',
|
|
38
|
+
'[role="status"]',
|
|
39
|
+
'[role="alert"]',
|
|
40
|
+
'[role="log"]',
|
|
41
|
+
'.cdk-live-announcer-element',
|
|
42
|
+
CNGX_LIVE_SURFACE_SELECTOR,
|
|
43
|
+
'.cdk-overlay-container',
|
|
44
|
+
'[data-cngx-backdrop]',
|
|
45
|
+
].join(', ');
|
|
46
|
+
/**
|
|
47
|
+
* @internal Top-layer surfaces that render outside the host after it engaged
|
|
48
|
+
* (a dialog the service appends to `<body>`, a tooltip placed next to its
|
|
49
|
+
* trigger) were opened from inside the modal and stay live. Only late
|
|
50
|
+
* additions get this exemption.
|
|
51
|
+
*/
|
|
52
|
+
const LATE_LIVE_SELECTOR = 'dialog, [popover]';
|
|
53
|
+
/**
|
|
54
|
+
* @internal Marks the elements around `host` as `inert` and returns the
|
|
55
|
+
* release function. Shared by `CngxBackdrop` (`'siblings'`) and
|
|
56
|
+
* `CngxDrawerSurface` (`'outside'`).
|
|
57
|
+
*
|
|
58
|
+
* The set is queried at call time and then followed: an element rendered
|
|
59
|
+
* later next to the host or next to one of its ancestors inside the scope
|
|
60
|
+
* (`@if`, `@defer`, a routed view) is inerted as it arrives, unless it is or
|
|
61
|
+
* holds a `<dialog>` or `[popover]`, which a late addition only is when the
|
|
62
|
+
* modal opened it. Elements that already carry
|
|
63
|
+
* `inert` are skipped and never touched on release, so a consumer-set or
|
|
64
|
+
* other-owner `inert` survives. Focus-trap anchors, live regions, the CDK
|
|
65
|
+
* overlay container, marked live surfaces and a backdrop
|
|
66
|
+
* stay live; an element that only contains one of them is not inerted as a
|
|
67
|
+
* whole, its other children are.
|
|
68
|
+
* Release is idempotent and stops following the scope.
|
|
69
|
+
*/
|
|
70
|
+
function createInertSiblings(host, options = {}) {
|
|
71
|
+
const { scope = 'siblings', exclude = () => false, within, keepLive } = options;
|
|
72
|
+
const root = scope === 'outside' ? (within ?? host.ownerDocument.body) : host.parentElement;
|
|
73
|
+
const liveSelector = keepLive ? `${KEEP_LIVE_SELECTOR}, ${keepLive}` : KEEP_LIVE_SELECTOR;
|
|
74
|
+
const lateLiveSelector = `${liveSelector}, ${LATE_LIVE_SELECTOR}`;
|
|
75
|
+
const targets = [];
|
|
76
|
+
const Observer = host.ownerDocument.defaultView?.MutationObserver;
|
|
77
|
+
const observer = Observer
|
|
78
|
+
? new Observer((records) => {
|
|
79
|
+
for (const record of records) {
|
|
80
|
+
record.addedNodes.forEach((node) => visit(node, lateLiveSelector));
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
: null;
|
|
84
|
+
const keepsLive = (element, selector) => element.matches(selector) || exclude(element);
|
|
85
|
+
const containsLive = (element, selector) => element.contains(host) ||
|
|
86
|
+
Array.from(element.querySelectorAll(selector)).some((node) => !host.contains(node));
|
|
87
|
+
const visit = (child, selector) => {
|
|
88
|
+
if (child === host || !(child instanceof HTMLElement) || child.hasAttribute('inert')) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (keepsLive(child, selector)) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (containsLive(child, selector)) {
|
|
95
|
+
collect(child, selector);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
child.setAttribute('inert', '');
|
|
99
|
+
targets.push(child);
|
|
100
|
+
};
|
|
101
|
+
const collect = (container, selector) => {
|
|
102
|
+
observer?.observe(container, { childList: true });
|
|
103
|
+
for (const child of Array.from(container.children)) {
|
|
104
|
+
visit(child, selector);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
if (root && root !== host && root.contains(host)) {
|
|
108
|
+
collect(root, liveSelector);
|
|
109
|
+
}
|
|
110
|
+
let released = false;
|
|
111
|
+
return () => {
|
|
112
|
+
if (released) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
released = true;
|
|
116
|
+
observer?.disconnect();
|
|
117
|
+
targets.forEach((target) => target.removeAttribute('inert'));
|
|
118
|
+
};
|
|
119
|
+
}
|
|
11
120
|
|
|
12
121
|
/**
|
|
13
122
|
* Manages backdrop overlay behavior: visibility, click-to-close, and
|
|
@@ -17,13 +126,18 @@ import { createLanguageSection } from '@cngx/core/i18n';
|
|
|
17
126
|
* attribute, preventing focus and interaction behind the backdrop.
|
|
18
127
|
* This is critical for a11y in modal/drawer overlays. A sibling drawer
|
|
19
128
|
* panel (`.cngx-drawer-panel`) is excluded - it is the surface the
|
|
20
|
-
* backdrop guards, not content behind it.
|
|
129
|
+
* backdrop guards, not content behind it. Focus-trap anchors (the
|
|
130
|
+
* panel's trap would stop wrapping) and live regions (announcements would
|
|
131
|
+
* go silent) stay live too; a sibling that only contains a live region has
|
|
132
|
+
* its other children inerted instead. Siblings that already carry
|
|
21
133
|
* `inert` are left alone, so a consumer-set `inert` survives the
|
|
22
134
|
* show/hide cycle. The sibling set is re-queried on every show, so
|
|
23
135
|
* siblings rendered after init are covered too.
|
|
24
136
|
*
|
|
25
137
|
* The directive is purely behavioral - it toggles the
|
|
26
|
-
* `.cngx-backdrop--visible` class and `aria-hidden` attribute
|
|
138
|
+
* `.cngx-backdrop--visible` class and `aria-hidden` attribute, and marks
|
|
139
|
+
* its host with `data-cngx-backdrop`, which keeps it live under the inert
|
|
140
|
+
* set of a page-modal drawer so its `backdropClick` still fires. Visual
|
|
27
141
|
* styling is opt-in: either consume the shipped default stylesheet or
|
|
28
142
|
* provide your own.
|
|
29
143
|
*
|
|
@@ -67,12 +181,12 @@ import { createLanguageSection } from '@cngx/core/i18n';
|
|
|
67
181
|
* }
|
|
68
182
|
* ```
|
|
69
183
|
*
|
|
70
|
-
* @category common/layout
|
|
71
184
|
* @wcag AA
|
|
72
185
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/drawer/backdrop.directive.ts
|
|
73
|
-
* @since 0.
|
|
186
|
+
* @since 0.3.0
|
|
74
187
|
* @relatedTo CngxDrawer, CngxDrawerPanel, CngxScrollLock
|
|
75
|
-
* <example-url
|
|
188
|
+
* <example-url>/#/common/layout/backdrop/overlay-with-inert</example-url>
|
|
189
|
+
* @axis level atom
|
|
76
190
|
*/
|
|
77
191
|
class CngxBackdrop {
|
|
78
192
|
/** Whether the backdrop is visible and siblings are inert. */
|
|
@@ -92,18 +206,11 @@ class CngxBackdrop {
|
|
|
92
206
|
// Re-queried on every show: siblings rendered after init (@if/@defer)
|
|
93
207
|
// must be inerted too. The drawer panel keeps working - it is the
|
|
94
208
|
// surface the backdrop guards, not content behind it.
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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')));
|
|
209
|
+
const release = createInertSiblings(this.el.nativeElement, {
|
|
210
|
+
scope: 'siblings',
|
|
211
|
+
exclude: (sibling) => sibling.classList.contains('cngx-drawer-panel'),
|
|
212
|
+
});
|
|
213
|
+
onCleanup(release);
|
|
107
214
|
});
|
|
108
215
|
}
|
|
109
216
|
/** @internal */
|
|
@@ -113,7 +220,7 @@ class CngxBackdrop {
|
|
|
113
220
|
}
|
|
114
221
|
}
|
|
115
222
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxBackdrop, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
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 });
|
|
223
|
+
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", "data-cngx-backdrop": "" }, listeners: { "click": "handleHostClick()" }, properties: { "class.cngx-backdrop--visible": "visible()" } }, exportAs: ["cngxBackdrop"], ngImport: i0 });
|
|
117
224
|
}
|
|
118
225
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxBackdrop, decorators: [{
|
|
119
226
|
type: Directive,
|
|
@@ -124,11 +231,64 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
124
231
|
host: {
|
|
125
232
|
'[class.cngx-backdrop--visible]': 'visible()',
|
|
126
233
|
'aria-hidden': 'true',
|
|
234
|
+
'data-cngx-backdrop': '',
|
|
127
235
|
'(click)': 'handleHostClick()',
|
|
128
236
|
},
|
|
129
237
|
}]
|
|
130
238
|
}], ctorParameters: () => [], propDecorators: { visible: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxBackdrop", required: false }] }], closeOnClick: [{ type: i0.Input, args: [{ isSignal: true, alias: "closeOnClick", required: false }] }], backdropClick: [{ type: i0.Output, args: ["backdropClick"] }] } });
|
|
131
239
|
|
|
240
|
+
/**
|
|
241
|
+
* The panel target of the surrounding drawer, sidebar or sidenav, for a
|
|
242
|
+
* `CngxPanelTrigger` placed inside it (a pin or close button). A trigger
|
|
243
|
+
* outside the panel takes the target as an explicit reference instead.
|
|
244
|
+
*
|
|
245
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/panel-trigger/panel-target.ts
|
|
246
|
+
* @since 0.3.0
|
|
247
|
+
* @relatedTo CngxPanelTrigger, CngxDrawer
|
|
248
|
+
*/
|
|
249
|
+
const CNGX_PANEL_TARGET = new InjectionToken('CngxPanelTarget');
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* The drawer host of a `CngxDrawerPanel` on the same element. `CngxDrawer`
|
|
253
|
+
* provides it via `useExisting`, so a bare `cngxDrawerPanel` attribute next
|
|
254
|
+
* to `cngxDrawer` resolves its drawer without injecting the concrete class.
|
|
255
|
+
* An explicit `[cngxDrawerPanel]` reference wins over it.
|
|
256
|
+
*
|
|
257
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/drawer/drawer-host.ts
|
|
258
|
+
* @since 0.3.0
|
|
259
|
+
* @relatedTo CngxDrawer, CngxDrawerPanel
|
|
260
|
+
*/
|
|
261
|
+
const CNGX_DRAWER_HOST = new InjectionToken('CngxDrawerHost');
|
|
262
|
+
|
|
263
|
+
// Escape is dismissed one layer at a time. Host listeners bubble from the
|
|
264
|
+
// innermost surface outwards and run before CngxPopover's document listener,
|
|
265
|
+
// so each layer checks for a closer owner before it acts.
|
|
266
|
+
const claimed = new WeakSet();
|
|
267
|
+
/**
|
|
268
|
+
* @internal Whether a layer closer to the keypress than `host` owns this
|
|
269
|
+
* Escape: an inner surface or drawer already handled it, or an open popover
|
|
270
|
+
* inside `host` (a menu, a select panel) takes it through its own listener.
|
|
271
|
+
*/
|
|
272
|
+
function escapeOwnedAbove(event, host) {
|
|
273
|
+
return claimed.has(event) || hasOpenPopover(host);
|
|
274
|
+
}
|
|
275
|
+
/** @internal Marks the Escape as handled for the layers around the handler. */
|
|
276
|
+
function claimEscape(event) {
|
|
277
|
+
claimed.add(event);
|
|
278
|
+
}
|
|
279
|
+
function hasOpenPopover(host) {
|
|
280
|
+
return Array.from(host.querySelectorAll('[popover]')).some(isOpenPopover);
|
|
281
|
+
}
|
|
282
|
+
// Engines without the Popover API reject the pseudo-class.
|
|
283
|
+
function isOpenPopover(element) {
|
|
284
|
+
try {
|
|
285
|
+
return element.matches(':popover-open');
|
|
286
|
+
}
|
|
287
|
+
catch {
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
132
292
|
/**
|
|
133
293
|
* State owner for a drawer / sidebar system.
|
|
134
294
|
*
|
|
@@ -138,6 +298,30 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
138
298
|
*
|
|
139
299
|
* Child directives (`CngxDrawerPanel`, `CngxDrawerContent`) receive a
|
|
140
300
|
* reference to this directive via an explicit input - no ancestor injection.
|
|
301
|
+
* The panel reads it through the `CngxDrawerHost` contract, which the drawer
|
|
302
|
+
* also provides as `CNGX_DRAWER_HOST` for a panel on its own element.
|
|
303
|
+
*
|
|
304
|
+
* The drawer is a `CngxPanelTarget`: a `[cngxPanelTrigger]="drawer"` button
|
|
305
|
+
* mirrors `opened` as `aria-expanded` and points `aria-controls` at
|
|
306
|
+
* `panelId`, which the panel takes as its `id`. Inside the drawer it provides
|
|
307
|
+
* `CNGX_PANEL_TARGET` for a bare `cngxPanelTrigger`. Its `mode`, `modal`
|
|
308
|
+
* and `side` follow the panel's `mode`, resolved modality and `position`,
|
|
309
|
+
* so a `CngxPanelToggle` draws the glyph of the current presentation.
|
|
310
|
+
*
|
|
311
|
+
* The drawer host is also the boundary of a `'contained'` panel and the
|
|
312
|
+
* area its scrim covers: with the opt-in `cngx-drawer` class (stylesheet
|
|
313
|
+
* `@cngx/common/theming/components/cngx-drawer.css`, part of the cngx
|
|
314
|
+
* bundle) the host places the panel on its side, lets the content fill the
|
|
315
|
+
* rest and paints a scrim over itself while a modal panel inside it is
|
|
316
|
+
* open. Keep an app header that must stay live outside the host.
|
|
317
|
+
*
|
|
318
|
+
* ### With a panel trigger
|
|
319
|
+
* ```html
|
|
320
|
+
* <button type="button" [cngxPanelTrigger]="drawer">Menu</button>
|
|
321
|
+
* <div cngxDrawer #drawer="cngxDrawer" panelId="main-nav">
|
|
322
|
+
* <nav [cngxDrawerPanel]="drawer">…</nav>
|
|
323
|
+
* </div>
|
|
324
|
+
* ```
|
|
141
325
|
*
|
|
142
326
|
* ### Uncontrolled
|
|
143
327
|
* ```html
|
|
@@ -156,27 +340,49 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
156
340
|
* </div>
|
|
157
341
|
* ```
|
|
158
342
|
*
|
|
159
|
-
* @category common/layout
|
|
160
|
-
* @docsKind primary
|
|
161
343
|
* @wcag AA
|
|
162
344
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/drawer/drawer.directive.ts
|
|
163
|
-
* @since 0.
|
|
345
|
+
* @since 0.3.0
|
|
164
346
|
* @relatedTo CngxDrawerPanel, CngxDrawerContent, CngxBackdrop, CngxScrollLock
|
|
165
|
-
* <example-url
|
|
166
|
-
* <example-url
|
|
167
|
-
* <example-url
|
|
168
|
-
* <example-url
|
|
169
|
-
* <example-url
|
|
170
|
-
* <example-url
|
|
347
|
+
* <example-url>/#/common/layout/drawer/basic-scroll-lock-backdrop</example-url>
|
|
348
|
+
* <example-url>/#/common/layout/drawer/controlled-mode</example-url>
|
|
349
|
+
* <example-url>/#/common/layout/drawer/direction-all-four-sides</example-url>
|
|
350
|
+
* <example-url>/#/common/layout/drawer/events-openedchange-closed</example-url>
|
|
351
|
+
* <example-url>/#/common/layout/drawer/app-header-clipped</example-url>
|
|
352
|
+
* <example-url>/#/common/layout/drawer/full-height-modal</example-url>
|
|
353
|
+
* <example-url>/#/common/layout/drawer/filter-panel-push</example-url>
|
|
354
|
+
* <example-url>/#/common/layout/drawer/pattern-consumer-wiring</example-url>
|
|
355
|
+
* @axis level organism
|
|
171
356
|
*/
|
|
172
357
|
class CngxDrawer {
|
|
173
|
-
/** @internal Host element ref
|
|
358
|
+
/** @internal Host element ref. */
|
|
174
359
|
elementRef = inject((ElementRef));
|
|
360
|
+
host = inject(ElementRef).nativeElement;
|
|
361
|
+
/**
|
|
362
|
+
* The `id` of the drawer's panel element. `CngxDrawerPanel` renders it as
|
|
363
|
+
* its `id` unless the panel carries a static one, and a panel trigger
|
|
364
|
+
* points `aria-controls` at it.
|
|
365
|
+
*/
|
|
366
|
+
panelId = input(undefined, ...(ngDevMode ? [{ debugName: "panelId" }] : /* istanbul ignore next */ []));
|
|
175
367
|
/** Controlled opened state. When bound, takes precedence over internal state. */
|
|
176
368
|
openedInput = input(undefined, { ...(ngDevMode ? { debugName: "openedInput" } : /* istanbul ignore next */ {}), alias: 'cngxDrawerOpened' });
|
|
177
369
|
openedState = signal(false, ...(ngDevMode ? [{ debugName: "openedState" }] : /* istanbul ignore next */ []));
|
|
178
370
|
/** Resolved opened state - controlled input wins over internal state. */
|
|
179
371
|
opened = computed(() => this.openedInput() ?? this.openedState(), ...(ngDevMode ? [{ debugName: "opened" }] : /* istanbul ignore next */ []));
|
|
372
|
+
/** {@link CngxPanelTarget} view of {@link panelId}; empty when unset. */
|
|
373
|
+
id = computed(() => this.panelId() ?? '', ...(ngDevMode ? [{ debugName: "id" }] : /* istanbul ignore next */ []));
|
|
374
|
+
/** {@link CngxPanelTarget} view of {@link opened}. */
|
|
375
|
+
expanded = this.opened;
|
|
376
|
+
panelSlot = createSlotRegistry();
|
|
377
|
+
/** {@link CngxPanelTarget} view of the panel's `mode`; `over` until a panel registers. */
|
|
378
|
+
mode = computed(() => this.panelSlot.current()?.mode() ?? 'over', ...(ngDevMode ? [{ debugName: "mode" }] : /* istanbul ignore next */ []));
|
|
379
|
+
/**
|
|
380
|
+
* {@link CngxPanelTarget}: whether the panel's resolved modality blocks
|
|
381
|
+
* anything; `false` until a panel connects, like an unset `modal`.
|
|
382
|
+
*/
|
|
383
|
+
modal = computed(() => this.panelSlot.current()?.modal() ?? false, ...(ngDevMode ? [{ debugName: "modal" }] : /* istanbul ignore next */ []));
|
|
384
|
+
/** {@link CngxPanelTarget} view of the panel's `position`; `left` until a panel registers. */
|
|
385
|
+
side = computed(() => this.panelSlot.current()?.position() ?? 'left', ...(ngDevMode ? [{ debugName: "side" }] : /* istanbul ignore next */ []));
|
|
180
386
|
/** Emitted when the opened state changes. Wire to a signal for two-way binding. */
|
|
181
387
|
openedChange = output();
|
|
182
388
|
/** Emitted when the drawer closes. Convenience shorthand for close-only listeners. */
|
|
@@ -198,6 +404,27 @@ class CngxDrawer {
|
|
|
198
404
|
this.openedChange.emit(false);
|
|
199
405
|
this.closed.emit();
|
|
200
406
|
}
|
|
407
|
+
// The open panel's surface already closed the drawer for an Escape inside
|
|
408
|
+
// it. A controlled drawer still reads the bound input as open until the
|
|
409
|
+
// owner writes it back, so a second close() here would emit twice. An open
|
|
410
|
+
// popover inside the drawer (a menu in the content) takes the keypress
|
|
411
|
+
// first.
|
|
412
|
+
handleEscape(event) {
|
|
413
|
+
if (!this.opened() || escapeOwnedAbove(event, this.host)) {
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
const panel = this.panelSlot.current()?.element;
|
|
417
|
+
if (panel && event.target instanceof Node && panel.contains(event.target)) {
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
claimEscape(event);
|
|
421
|
+
this.close();
|
|
422
|
+
}
|
|
423
|
+
/** {@link CngxDrawerHost}: connects a panel; the latest panel wins. */
|
|
424
|
+
connectPanel(panel) {
|
|
425
|
+
this.panelSlot.register(panel);
|
|
426
|
+
return () => this.panelSlot.unregister(panel);
|
|
427
|
+
}
|
|
201
428
|
/** Toggles the drawer between open and closed. */
|
|
202
429
|
toggle() {
|
|
203
430
|
if (this.opened()) {
|
|
@@ -208,7 +435,10 @@ class CngxDrawer {
|
|
|
208
435
|
}
|
|
209
436
|
}
|
|
210
437
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDrawer, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
211
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxDrawer, isStandalone: true, selector: "[cngxDrawer]", inputs: { openedInput: { classPropertyName: "openedInput", publicName: "cngxDrawerOpened", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { openedChange: "openedChange", closed: "closed" }, host: { listeners: { "keydown.escape": "
|
|
438
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxDrawer, isStandalone: true, selector: "[cngxDrawer]", inputs: { panelId: { classPropertyName: "panelId", publicName: "panelId", isSignal: true, isRequired: false, transformFunction: null }, openedInput: { classPropertyName: "openedInput", publicName: "cngxDrawerOpened", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { openedChange: "openedChange", closed: "closed" }, host: { listeners: { "keydown.escape": "handleEscape($event)" }, properties: { "class.cngx-drawer--opened": "opened()" } }, providers: [
|
|
439
|
+
{ provide: CNGX_PANEL_TARGET, useExisting: CngxDrawer },
|
|
440
|
+
{ provide: CNGX_DRAWER_HOST, useExisting: CngxDrawer },
|
|
441
|
+
], exportAs: ["cngxDrawer"], ngImport: i0 });
|
|
212
442
|
}
|
|
213
443
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDrawer, decorators: [{
|
|
214
444
|
type: Directive,
|
|
@@ -216,137 +446,867 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
216
446
|
selector: '[cngxDrawer]',
|
|
217
447
|
exportAs: 'cngxDrawer',
|
|
218
448
|
standalone: true,
|
|
449
|
+
providers: [
|
|
450
|
+
{ provide: CNGX_PANEL_TARGET, useExisting: CngxDrawer },
|
|
451
|
+
{ provide: CNGX_DRAWER_HOST, useExisting: CngxDrawer },
|
|
452
|
+
],
|
|
219
453
|
host: {
|
|
220
454
|
'[class.cngx-drawer--opened]': 'opened()',
|
|
221
|
-
'(keydown.escape)': '
|
|
455
|
+
'(keydown.escape)': 'handleEscape($event)',
|
|
222
456
|
},
|
|
223
457
|
}]
|
|
224
|
-
}], propDecorators: { openedInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxDrawerOpened", required: false }] }], openedChange: [{ type: i0.Output, args: ["openedChange"] }], closed: [{ type: i0.Output, args: ["closed"] }] } });
|
|
458
|
+
}], propDecorators: { panelId: [{ type: i0.Input, args: [{ isSignal: true, alias: "panelId", required: false }] }], openedInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxDrawerOpened", required: false }] }], openedChange: [{ type: i0.Output, args: ["openedChange"] }], closed: [{ type: i0.Output, args: ["closed"] }] } });
|
|
225
459
|
|
|
226
460
|
/**
|
|
227
|
-
* The
|
|
228
|
-
* `
|
|
461
|
+
* The English layout section: the single source of the layout atoms'
|
|
462
|
+
* English copy. `CNGX_LAYOUT_I18N` defaults to it.
|
|
463
|
+
*
|
|
464
|
+
* @since 0.3.0
|
|
465
|
+
* @relatedTo CNGX_LAYOUT_I18N
|
|
466
|
+
*/
|
|
467
|
+
const CNGX_LAYOUT_LANGUAGE_EN = {
|
|
468
|
+
expandableTextMore: 'Show more',
|
|
469
|
+
expandableTextLess: 'Show less',
|
|
470
|
+
resizeHandle: 'Resize',
|
|
471
|
+
resizeValueText: '{size} pixels',
|
|
472
|
+
panelTrigger: 'Panel',
|
|
473
|
+
sidebarRegion: 'Sidebar',
|
|
474
|
+
drawerDialog: 'Drawer',
|
|
475
|
+
};
|
|
476
|
+
|
|
477
|
+
/** @internal The English section with the active pack's layout section on top. */
|
|
478
|
+
const injectLayoutSection = createLanguageSection('layout', CNGX_LAYOUT_LANGUAGE_EN);
|
|
479
|
+
/** @internal Turns a layout section into the token's keys for a locale. */
|
|
480
|
+
function layoutBundleFrom(section, locale) {
|
|
481
|
+
return {
|
|
482
|
+
expandableTextMore: section.expandableTextMore,
|
|
483
|
+
expandableTextLess: section.expandableTextLess,
|
|
484
|
+
resizeHandle: section.resizeHandle,
|
|
485
|
+
resizeValueText: (size) => formatMessage(section.resizeValueText, { size }, locale),
|
|
486
|
+
panelTrigger: section.panelTrigger,
|
|
487
|
+
sidebarRegion: section.sidebarRegion,
|
|
488
|
+
drawerDialog: section.drawerDialog,
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
/** @internal Builds and reads the token, formatted for the reading locale. */
|
|
492
|
+
const layoutBundle = createSectionBundle({
|
|
493
|
+
section: injectLayoutSection,
|
|
494
|
+
toBundle: layoutBundleFrom,
|
|
495
|
+
});
|
|
496
|
+
/**
|
|
497
|
+
* DI token for the layout i18n bundle. `providedIn: 'root'`: the layout
|
|
498
|
+
* section of the active language pack over the English defaults; the value
|
|
499
|
+
* is a `Signal`, shared by every reader under one injector.
|
|
500
|
+
*
|
|
501
|
+
* @wcag AA
|
|
502
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/i18n/layout-i18n.ts
|
|
503
|
+
* @since 0.3.0
|
|
504
|
+
* @relatedTo CngxExpandableText, CngxResizable, CngxPanelTrigger, CngxSidebar, CngxDrawerPanel
|
|
505
|
+
*/
|
|
506
|
+
const CNGX_LAYOUT_I18N = new InjectionToken('CngxLayoutI18n', {
|
|
507
|
+
providedIn: 'root',
|
|
508
|
+
factory: () => layoutBundle.build(),
|
|
509
|
+
});
|
|
510
|
+
/**
|
|
511
|
+
* Override layout labels via a partial bundle - unset keys keep the
|
|
512
|
+
* language pack's copy, or the English default. Pass a `Signal` of a partial
|
|
513
|
+
* bundle to switch languages at runtime.
|
|
514
|
+
*
|
|
515
|
+
* @since 0.3.0
|
|
516
|
+
*/
|
|
517
|
+
function withLayoutI18nLabels(overrides) {
|
|
518
|
+
return (bundle) => createOverrideMerge(bundle, overrides);
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Provider for the layout i18n bundle. Returns a plain `Provider`, so it
|
|
522
|
+
* also scopes a subtree through `viewProviders`. The features apply on top
|
|
523
|
+
* of the active language pack.
|
|
524
|
+
*
|
|
525
|
+
* ```ts
|
|
526
|
+
* bootstrapApplication(AppComponent, {
|
|
527
|
+
* providers: [
|
|
528
|
+
* provideLayoutI18n(
|
|
529
|
+
* withLayoutI18nLabels({ expandableTextMore: 'Mehr anzeigen', expandableTextLess: 'Weniger anzeigen' }),
|
|
530
|
+
* ),
|
|
531
|
+
* ],
|
|
532
|
+
* });
|
|
533
|
+
* ```
|
|
534
|
+
*
|
|
535
|
+
* @since 0.3.0
|
|
536
|
+
*/
|
|
537
|
+
function provideLayoutI18n(...features) {
|
|
538
|
+
return {
|
|
539
|
+
provide: CNGX_LAYOUT_I18N,
|
|
540
|
+
useFactory: () => layoutBundle.build(features),
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* Inject the resolved layout i18n bundle signal. Read it inside a
|
|
545
|
+
* `computed()` or template so a runtime override flip re-derives.
|
|
546
|
+
*
|
|
547
|
+
* @since 0.3.0
|
|
548
|
+
*/
|
|
549
|
+
function injectLayoutI18n() {
|
|
550
|
+
return layoutBundle.resolve(inject(CNGX_LAYOUT_I18N));
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* Ref-count per locked element. Module-private on purpose: this file is the
|
|
555
|
+
* single owner of the lock state. A second copy of this map (the pre-extraction
|
|
556
|
+
* state: one in `CngxScrollLock`, one in `CngxDialog`) shares the dataset keys
|
|
557
|
+
* below without sharing the count, so interleaved acquire/release across the
|
|
558
|
+
* two owners corrupts each other's saved overflow values.
|
|
559
|
+
*
|
|
560
|
+
* @internal
|
|
561
|
+
*/
|
|
562
|
+
const lockCounts = new WeakMap();
|
|
563
|
+
/**
|
|
564
|
+
* Acquire a ref-counted scroll lock on an element and get back the matching
|
|
565
|
+
* release function.
|
|
566
|
+
*
|
|
567
|
+
* The target is the element that scrolls: the document root
|
|
568
|
+
* (`document.documentElement`) for the page, or any scroll container (a
|
|
569
|
+
* panel with `overflow-y: auto`) for a surface that overlays only that
|
|
570
|
+
* container. Each element keeps its own count, so locks on two containers
|
|
571
|
+
* never interfere.
|
|
572
|
+
*
|
|
573
|
+
* The first active lock on a target saves its inline `overflow` /
|
|
574
|
+
* `scrollbar-gutter` and sets `overflow: hidden` + `scrollbar-gutter: stable`
|
|
575
|
+
* (no layout shift when the scrollbar disappears). Releasing the last active
|
|
576
|
+
* lock on that target restores the saved values. The returned release
|
|
577
|
+
* function is idempotent - calling it twice cannot over-decrement the count.
|
|
578
|
+
*
|
|
579
|
+
* Shared engine behind `CngxScrollLock` and `CngxDialog`'s modal scroll lock;
|
|
580
|
+
* consumers composing their own overlay primitives can use it directly.
|
|
581
|
+
*
|
|
582
|
+
* ```typescript
|
|
583
|
+
* const release = createScrollLock(document.documentElement);
|
|
584
|
+
* // ... overlay open ...
|
|
585
|
+
* release();
|
|
586
|
+
* ```
|
|
587
|
+
*
|
|
588
|
+
* @param target - The scrolling element to lock.
|
|
589
|
+
* @returns Release function for this acquisition. Idempotent.
|
|
590
|
+
*
|
|
591
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/scroll/scroll-lock-core.ts
|
|
592
|
+
* @since 0.3.0
|
|
593
|
+
* @relatedTo CngxScrollLock, CngxDialog
|
|
594
|
+
*/
|
|
595
|
+
function createScrollLock(target) {
|
|
596
|
+
const count = lockCounts.get(target) ?? 0;
|
|
597
|
+
if (count === 0) {
|
|
598
|
+
target.dataset['cngxPrevOverflow'] = target.style.overflow;
|
|
599
|
+
target.dataset['cngxPrevScrollbarGutter'] = target.style.scrollbarGutter;
|
|
600
|
+
target.style.overflow = 'hidden';
|
|
601
|
+
target.style.scrollbarGutter = 'stable';
|
|
602
|
+
}
|
|
603
|
+
lockCounts.set(target, count + 1);
|
|
604
|
+
let released = false;
|
|
605
|
+
return () => {
|
|
606
|
+
if (released) {
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
released = true;
|
|
610
|
+
const current = lockCounts.get(target) ?? 0;
|
|
611
|
+
if (current <= 1) {
|
|
612
|
+
target.style.overflow = target.dataset['cngxPrevOverflow'] ?? '';
|
|
613
|
+
target.style.scrollbarGutter = target.dataset['cngxPrevScrollbarGutter'] ?? '';
|
|
614
|
+
delete target.dataset['cngxPrevOverflow'];
|
|
615
|
+
delete target.dataset['cngxPrevScrollbarGutter'];
|
|
616
|
+
lockCounts.set(target, 0);
|
|
617
|
+
}
|
|
618
|
+
else {
|
|
619
|
+
lockCounts.set(target, current - 1);
|
|
620
|
+
}
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
// The body properties the pin writes. Only these are saved and restored, so a
|
|
624
|
+
// style another owner sets on body while the pin is held survives the release.
|
|
625
|
+
const PINNED_BODY_PROPERTIES = ['position', 'top', 'inset-inline', 'overflow'];
|
|
626
|
+
/**
|
|
627
|
+
* Pin state per document root, separate from `lockCounts`: a pin also holds
|
|
628
|
+
* one `createScrollLock` acquisition, so the html overflow stays shared with
|
|
629
|
+
* every other owner.
|
|
630
|
+
*
|
|
631
|
+
* @internal
|
|
632
|
+
*/
|
|
633
|
+
const pins = new WeakMap();
|
|
634
|
+
/**
|
|
635
|
+
* Acquire a ref-counted scroll lock that pins the page body in place, for
|
|
636
|
+
* overlays that must hold on iOS Safari.
|
|
637
|
+
*
|
|
638
|
+
* `overflow: hidden` on the root does not stop iOS Safari from scrolling a
|
|
639
|
+
* page that was already scrolled, and the visual viewport drifts with it, so
|
|
640
|
+
* a bottom-fixed overlay ends above the visible bottom. The first pin saves
|
|
641
|
+
* the body's inline `position`, `top`, `inset-inline` and `overflow` and the
|
|
642
|
+
* scroll position, fixes the body at `top: -scrollY`, and acquires
|
|
643
|
+
* {@link createScrollLock} on the root. The last
|
|
644
|
+
* release restores the body, releases the root lock and scrolls back to the
|
|
645
|
+
* saved position. The returned release function is idempotent.
|
|
646
|
+
*
|
|
647
|
+
* `CngxDialog` and `CngxScrollLock` keep {@link createScrollLock}; reach for
|
|
648
|
+
* this one when the overlay is pinned to the viewport bottom on touch devices.
|
|
649
|
+
*
|
|
650
|
+
* ```typescript
|
|
651
|
+
* const release = createPinnedScrollLock(document.documentElement);
|
|
652
|
+
* // ... sheet open ...
|
|
653
|
+
* release();
|
|
654
|
+
* ```
|
|
655
|
+
*
|
|
656
|
+
* @param html - The document root (`document.documentElement`) to lock.
|
|
657
|
+
* @returns Release function for this acquisition. Idempotent.
|
|
658
|
+
*
|
|
659
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/scroll/scroll-lock-core.ts
|
|
660
|
+
* @since 0.3.0
|
|
661
|
+
* @relatedTo createScrollLock, CngxPopoverSheet
|
|
662
|
+
*/
|
|
663
|
+
function createPinnedScrollLock(html) {
|
|
664
|
+
const body = html.ownerDocument.body;
|
|
665
|
+
const view = html.ownerDocument.defaultView;
|
|
666
|
+
const existing = pins.get(html);
|
|
667
|
+
if (existing) {
|
|
668
|
+
existing.count += 1;
|
|
669
|
+
}
|
|
670
|
+
else {
|
|
671
|
+
const scrollX = view?.scrollX ?? 0;
|
|
672
|
+
const scrollY = view?.scrollY ?? 0;
|
|
673
|
+
pins.set(html, {
|
|
674
|
+
count: 1,
|
|
675
|
+
saved: new Map(PINNED_BODY_PROPERTIES.map((name) => [
|
|
676
|
+
name,
|
|
677
|
+
{
|
|
678
|
+
value: body.style.getPropertyValue(name),
|
|
679
|
+
priority: body.style.getPropertyPriority(name),
|
|
680
|
+
},
|
|
681
|
+
])),
|
|
682
|
+
scrollX,
|
|
683
|
+
scrollY,
|
|
684
|
+
releaseHtml: createScrollLock(html),
|
|
685
|
+
});
|
|
686
|
+
body.style.position = 'fixed';
|
|
687
|
+
body.style.top = `${-scrollY}px`;
|
|
688
|
+
body.style.insetInline = '0';
|
|
689
|
+
body.style.overflow = 'hidden';
|
|
690
|
+
}
|
|
691
|
+
let released = false;
|
|
692
|
+
return () => {
|
|
693
|
+
if (released) {
|
|
694
|
+
return;
|
|
695
|
+
}
|
|
696
|
+
released = true;
|
|
697
|
+
const state = pins.get(html);
|
|
698
|
+
if (!state) {
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
state.count -= 1;
|
|
702
|
+
if (state.count > 0) {
|
|
703
|
+
return;
|
|
704
|
+
}
|
|
705
|
+
pins.delete(html);
|
|
706
|
+
for (const [name, { value, priority }] of state.saved) {
|
|
707
|
+
if (value) {
|
|
708
|
+
body.style.setProperty(name, value, priority);
|
|
709
|
+
}
|
|
710
|
+
else {
|
|
711
|
+
body.style.removeProperty(name);
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
state.releaseHtml();
|
|
715
|
+
view?.scrollTo({ left: state.scrollX, top: state.scrollY, behavior: 'instant' });
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
/** @internal See {@link CngxDrawerSurfaceDriver}. */
|
|
720
|
+
const CNGX_DRAWER_SURFACE_DRIVER = new InjectionToken('CngxDrawerSurfaceDriver');
|
|
721
|
+
const SCROLLING_OVERFLOW = new Set(['auto', 'scroll']);
|
|
722
|
+
/**
|
|
723
|
+
* The transient-surface behaviour of a drawer or an overlay rail, with an
|
|
724
|
+
* explicit modality.
|
|
725
|
+
*
|
|
726
|
+
* While `active`, the surface asks to be dismissed on Escape with focus
|
|
727
|
+
* inside (in every browser: the close Chromium derives from an Escape
|
|
728
|
+
* keypress is not a back gesture and is dropped), on the platform back
|
|
729
|
+
* gesture (`CloseWatcher`) and on a press outside the
|
|
730
|
+
* host. A press on the element whose `aria-controls` names the host `id` is
|
|
731
|
+
* not outside, so the trigger can toggle the surface itself. One Escape
|
|
732
|
+
* dismisses one layer: an inner surface or an open popover inside the host
|
|
733
|
+
* (a menu, a select panel) takes the keypress first. Focus returns
|
|
734
|
+
* to the element focused at activation when the surface deactivates.
|
|
735
|
+
*
|
|
736
|
+
* `modality` decides how far the engaged surface takes over the page:
|
|
737
|
+
*
|
|
738
|
+
* - `'page'` (default) additionally traps focus, renders `role="dialog"` +
|
|
739
|
+
* `aria-modal="true"`, makes everything outside the host `inert` up to
|
|
740
|
+
* `<body>` (the siblings of the host and of every ancestor, like a modal
|
|
741
|
+
* dialog) and locks scrolling on the nearest scroll container above the
|
|
742
|
+
* host (the nearest ancestor with a computed `overflow-y` of `auto` or
|
|
743
|
+
* `scroll`, else the document root).
|
|
744
|
+
* - `'contained'` does the same inside a boundary only: the host's siblings
|
|
745
|
+
* inside the boundary are `inert`, the nearest scroll container between
|
|
746
|
+
* the host and the boundary (inclusive) is locked if there is one, and
|
|
747
|
+
* nothing outside the boundary is touched. The element whose `aria-controls`
|
|
748
|
+
* names the host stays live wherever it sits. No trap and no
|
|
749
|
+
* `aria-modal` (the page around the boundary is operable, so the surface
|
|
750
|
+
* must not claim it is not); the landmark role stays and focus moves to
|
|
751
|
+
* the first tabbable element inside the host on activation. The
|
|
752
|
+
* boundary is the host's parent element unless a composer names one
|
|
753
|
+
* (`CngxDrawerPanel` names its `[cngxDrawer]` host).
|
|
754
|
+
* - `'none'` keeps the page around it operable: no trap, no lock, no
|
|
755
|
+
* inert, the landmark `role` (default `complementary`, `null` keeps the
|
|
756
|
+
* host's implicit role).
|
|
757
|
+
*
|
|
758
|
+
* In every modality focus-trap anchors, live regions, the CDK overlay
|
|
759
|
+
* container, the toast and banner outlets and a visible `CngxBackdrop` stay
|
|
760
|
+
* live, and an `inert` set by someone else is kept on release. Escape, the
|
|
761
|
+
* back gesture and an outside press ask for dismissal in all three.
|
|
762
|
+
*
|
|
763
|
+
* The surface does not own the open state: it reports `dismiss` and the
|
|
764
|
+
* owner decides. It composes `CngxFocusTrap`, `CngxFocusRestore` and
|
|
765
|
+
* `CngxClickOutside` and drives them; none of their inputs is re-exposed.
|
|
229
766
|
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
767
|
+
* ```html
|
|
768
|
+
* <aside id="filters" cngxDrawerSurface [active]="open()" modality="none"
|
|
769
|
+
* (dismiss)="open.set(false)">…</aside>
|
|
770
|
+
* <button aria-controls="filters" [attr.aria-expanded]="open()"
|
|
771
|
+
* (click)="open.set(!open())">Filters</button>
|
|
772
|
+
* ```
|
|
232
773
|
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
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).
|
|
774
|
+
* `CngxDrawerPanel` hosts the surface for drawers; consumers rarely bind it
|
|
775
|
+
* directly.
|
|
241
776
|
*
|
|
242
|
-
*
|
|
243
|
-
*
|
|
777
|
+
* @wcag AA
|
|
778
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/drawer/drawer-surface.directive.ts
|
|
779
|
+
* @since 0.3.0
|
|
780
|
+
* @relatedTo CngxDrawerPanel, CngxFocusTrap, CngxFocusRestore, CngxClickOutside, createScrollLock
|
|
781
|
+
* <example-url>/#/common/layout/drawer/standalone-surface</example-url>
|
|
782
|
+
* @axis level molecule
|
|
783
|
+
*/
|
|
784
|
+
class CngxDrawerSurface {
|
|
785
|
+
/**
|
|
786
|
+
* Whether the surface is engaged (the drawer or overlay is open). Bind it
|
|
787
|
+
* to the owner's open state.
|
|
788
|
+
*/
|
|
789
|
+
active = input(false, ...(ngDevMode ? [{ debugName: "active" }] : /* istanbul ignore next */ []));
|
|
790
|
+
/**
|
|
791
|
+
* How far the engaged surface takes over the page: `'page'` (modal dialog,
|
|
792
|
+
* inert up to `<body>`), `'contained'` (inert and scroll lock inside the
|
|
793
|
+
* boundary only, no trap) or `'none'`. See {@link CngxDrawerModality}.
|
|
794
|
+
*/
|
|
795
|
+
modality = input('page', ...(ngDevMode ? [{ debugName: "modality" }] : /* istanbul ignore next */ []));
|
|
796
|
+
/**
|
|
797
|
+
* Landmark role while the surface is not an engaged page modal. Defaults
|
|
798
|
+
* to `complementary`; pass `navigation` for a nav surface, or `null` on a
|
|
799
|
+
* `<nav>` / `<aside>` host to keep its implicit role. A composer's driver
|
|
800
|
+
* wins over it.
|
|
801
|
+
*/
|
|
802
|
+
role = input('complementary', ...(ngDevMode ? [{ debugName: "role" }] : /* istanbul ignore next */ []));
|
|
803
|
+
/**
|
|
804
|
+
* Accessible name of the surface. An engaged page modal (a `dialog`)
|
|
805
|
+
* without one falls back to a static `aria-label` on the host, then to
|
|
806
|
+
* `CNGX_LAYOUT_I18N.drawerDialog`; a host with a static `aria-labelledby`
|
|
807
|
+
* keeps that name. Outside an engaged page modal only a bound label or a
|
|
808
|
+
* static `aria-label` names the landmark.
|
|
809
|
+
*/
|
|
810
|
+
labelInput = input(undefined, { ...(ngDevMode ? { debugName: "labelInput" } : /* istanbul ignore next */ {}), alias: 'label' });
|
|
811
|
+
/**
|
|
812
|
+
* Emitted when the user asks to dismiss the engaged surface: Escape, the
|
|
813
|
+
* back gesture, or a press outside the host. The owner closes it.
|
|
814
|
+
*/
|
|
815
|
+
dismiss = output();
|
|
816
|
+
injector = inject(Injector);
|
|
817
|
+
host = inject(ElementRef).nativeElement;
|
|
818
|
+
doc = inject(DOCUMENT);
|
|
819
|
+
domReady = signal(false, ...(ngDevMode ? [{ debugName: "domReady" }] : /* istanbul ignore next */ []));
|
|
820
|
+
focusTrap = inject(CngxFocusTrap, { self: true });
|
|
821
|
+
i18n = injectLayoutI18n();
|
|
822
|
+
staticLabel = inject(new HostAttributeToken('aria-label'), { optional: true });
|
|
823
|
+
staticLabelledBy = inject(new HostAttributeToken('aria-labelledby'), {
|
|
824
|
+
optional: true,
|
|
825
|
+
});
|
|
826
|
+
staticTabindex = inject(new HostAttributeToken('tabindex'), { optional: true });
|
|
827
|
+
destroyed = false;
|
|
828
|
+
// Chromium also turns an unhandled Escape keydown, wherever focus is, into
|
|
829
|
+
// a CloseWatcher close. Escape belongs to the keydown path (focus inside
|
|
830
|
+
// the host, the drawer for its content), so a watcher close from the same
|
|
831
|
+
// keypress is not a back gesture. The flag lives for the keydown task only.
|
|
832
|
+
escapeKeyTimer = null;
|
|
833
|
+
escapeKeydown = (event) => {
|
|
834
|
+
if (event.key !== 'Escape') {
|
|
835
|
+
return;
|
|
836
|
+
}
|
|
837
|
+
this.clearEscapeKey();
|
|
838
|
+
this.escapeKeyTimer = setTimeout(() => {
|
|
839
|
+
this.escapeKeyTimer = null;
|
|
840
|
+
});
|
|
841
|
+
};
|
|
842
|
+
// Swallows the click that trails the outside press which dismissed an
|
|
843
|
+
// engaged page modal. iOS Safari fires pointerdown at touchstart but hit
|
|
844
|
+
// tests the synthesized click again after touchend; by then the dismissal
|
|
845
|
+
// has dropped `inert` and the click lands on the live opener, reopening it.
|
|
846
|
+
releaseTrailingClick = null;
|
|
847
|
+
resolvedDriver = undefined;
|
|
848
|
+
driver() {
|
|
849
|
+
if (this.resolvedDriver === undefined) {
|
|
850
|
+
this.resolvedDriver = this.injector.get(CNGX_DRAWER_SURFACE_DRIVER, null, { self: true });
|
|
851
|
+
}
|
|
852
|
+
return this.resolvedDriver;
|
|
853
|
+
}
|
|
854
|
+
/** Whether the surface is engaged, after the driver. */
|
|
855
|
+
isActive = computed(() => this.driver()?.surfaceActive() ?? this.active(), ...(ngDevMode ? [{ debugName: "isActive" }] : /* istanbul ignore next */ []));
|
|
856
|
+
/** The modality of the surface, after the driver. */
|
|
857
|
+
resolvedModality = computed(() => this.driver()?.surfaceModality() ?? this.modality(), ...(ngDevMode ? [{ debugName: "resolvedModality" }] : /* istanbul ignore next */ []));
|
|
858
|
+
/** The modality while engaged; `'none'` while the surface is not active. */
|
|
859
|
+
engagedModality = computed(() => this.isActive() ? this.resolvedModality() : 'none', ...(ngDevMode ? [{ debugName: "engagedModality" }] : /* istanbul ignore next */ []));
|
|
860
|
+
engagedPage = computed(() => this.engagedModality() === 'page', ...(ngDevMode ? [{ debugName: "engagedPage" }] : /* istanbul ignore next */ []));
|
|
861
|
+
/**
|
|
862
|
+
* @internal Hotkey scope of the surface subtree: modal while engaged as
|
|
863
|
+
* `'page'` or `'contained'`, so app bindings outside stay quiet while focus
|
|
864
|
+
* is inside. Always active: the drawer's own bindings (toggle, close) must
|
|
865
|
+
* fire whether the surface is engaged or not.
|
|
866
|
+
*/
|
|
867
|
+
hotkeyScope = createHotkeyScope({
|
|
868
|
+
element: this.host,
|
|
869
|
+
modal: computed(() => this.engagedModality() !== 'none'),
|
|
870
|
+
parent: inject(CNGX_HOTKEY_SCOPE, { optional: true, skipSelf: true }),
|
|
871
|
+
destroyRef: inject(DestroyRef),
|
|
872
|
+
});
|
|
873
|
+
surfaceRole = computed(() => {
|
|
874
|
+
if (this.engagedPage()) {
|
|
875
|
+
return 'dialog';
|
|
876
|
+
}
|
|
877
|
+
const landmark = this.driver()?.surfaceLandmarkRole;
|
|
878
|
+
return landmark ? landmark() : this.role();
|
|
879
|
+
}, ...(ngDevMode ? [{ debugName: "surfaceRole" }] : /* istanbul ignore next */ []));
|
|
880
|
+
// A static aria-label or aria-labelledby names the host already; the
|
|
881
|
+
// fallback only fills a nameless engaged dialog.
|
|
882
|
+
namesWithFallback = computed(() => this.engagedPage() && this.staticLabel === null && this.staticLabelledBy === null, ...(ngDevMode ? [{ debugName: "namesWithFallback" }] : /* istanbul ignore next */ []));
|
|
883
|
+
/**
|
|
884
|
+
* The resolved accessible name: the bound `label`, else a static
|
|
885
|
+
* `aria-label`, else (engaged page modal without a static name)
|
|
886
|
+
* `CNGX_LAYOUT_I18N.drawerDialog`.
|
|
887
|
+
*/
|
|
888
|
+
label = computed(() => {
|
|
889
|
+
const driven = this.driver()?.surfaceLabel;
|
|
890
|
+
if (driven) {
|
|
891
|
+
return driven();
|
|
892
|
+
}
|
|
893
|
+
return this.namesWithFallback()
|
|
894
|
+
? (this.labelInput() ?? this.i18n().drawerDialog)
|
|
895
|
+
: (this.labelInput() ?? this.staticLabel ?? undefined);
|
|
896
|
+
}, ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
|
|
897
|
+
ariaLabel = computed(() => this.label() ?? null, ...(ngDevMode ? [{ debugName: "ariaLabel" }] : /* istanbul ignore next */ []));
|
|
898
|
+
/** @internal Drives the composed `CngxFocusTrap`. */
|
|
899
|
+
focusTrapEnabled = this.engagedPage;
|
|
900
|
+
/** @internal Drives the composed `CngxFocusTrap`. */
|
|
901
|
+
focusTrapAutoFocus = true;
|
|
902
|
+
/**
|
|
903
|
+
* @internal Drives the composed `CngxFocusRestore`. The restore edge can
|
|
904
|
+
* run before the scope effect below releases `inert` around the host; the
|
|
905
|
+
* restore then focuses the opener after the render, once it is live.
|
|
906
|
+
*/
|
|
907
|
+
focusRestoreActive = this.isActive;
|
|
908
|
+
/**
|
|
909
|
+
* @internal Drives the composed `CngxFocusRestore`: when the surface was
|
|
910
|
+
* engaged with focus already inside it (a docked rail that turned into a
|
|
911
|
+
* drawer), there is no opener to return to, so focus goes to the element
|
|
912
|
+
* whose `aria-controls` names the host, the same relation an outside press
|
|
913
|
+
* is exempted by.
|
|
914
|
+
*/
|
|
915
|
+
focusRestoreFallback() {
|
|
916
|
+
const id = this.host.id;
|
|
917
|
+
if (!id) {
|
|
918
|
+
return null;
|
|
919
|
+
}
|
|
920
|
+
const trigger = this.doc.querySelector(`[aria-controls~="${id.replace(/["\\]/g, '\\$&')}"]`);
|
|
921
|
+
return trigger instanceof HTMLElement && !this.host.contains(trigger) ? trigger : null;
|
|
922
|
+
}
|
|
923
|
+
// A press on a non-focusable spot inside an engaged surface would drop
|
|
924
|
+
// focus to <body>, out of reach of the host Escape listener (and of the
|
|
925
|
+
// page modal's own boundary). tabindex="-1" keeps focus on the host there,
|
|
926
|
+
// like a native <dialog>; it adds no Tab stop. A consumer tabindex wins.
|
|
927
|
+
hostTabindex = computed(() => this.staticTabindex ?? (this.isActive() ? '-1' : null), ...(ngDevMode ? [{ debugName: "hostTabindex" }] : /* istanbul ignore next */ []));
|
|
928
|
+
/** @internal Drives the composed `CngxClickOutside`. */
|
|
929
|
+
clickOutsideEnabled = computed(() => this.isActive() && (this.driver()?.surfaceOutsideDismiss?.() ?? true), ...(ngDevMode ? [{ debugName: "clickOutsideEnabled" }] : /* istanbul ignore next */ []));
|
|
930
|
+
closeWatcher = createCloseWatcher(() => this.handleCloseRequest(), injectWindow());
|
|
931
|
+
constructor() {
|
|
932
|
+
afterNextRender(() => this.domReady.set(true));
|
|
933
|
+
inject(DestroyRef).onDestroy(() => {
|
|
934
|
+
this.destroyed = true;
|
|
935
|
+
this.clearEscapeKey();
|
|
936
|
+
this.closeWatcher.disarm();
|
|
937
|
+
this.releaseTrailingClick?.();
|
|
938
|
+
});
|
|
939
|
+
inject(CngxClickOutside, { self: true }).clickOutside.subscribe(() => {
|
|
940
|
+
if (untracked(this.engagedPage)) {
|
|
941
|
+
this.swallowTrailingClick();
|
|
942
|
+
}
|
|
943
|
+
this.requestDismiss();
|
|
944
|
+
});
|
|
945
|
+
effect((onCleanup) => {
|
|
946
|
+
if (!this.isActive()) {
|
|
947
|
+
return;
|
|
948
|
+
}
|
|
949
|
+
untracked(() => {
|
|
950
|
+
this.doc.addEventListener('keydown', this.escapeKeydown, true);
|
|
951
|
+
this.closeWatcher.arm();
|
|
952
|
+
});
|
|
953
|
+
onCleanup(() => {
|
|
954
|
+
this.doc.removeEventListener('keydown', this.escapeKeydown, true);
|
|
955
|
+
this.clearEscapeKey();
|
|
956
|
+
this.closeWatcher.disarm();
|
|
957
|
+
});
|
|
958
|
+
});
|
|
959
|
+
effect((onCleanup) => {
|
|
960
|
+
const modality = this.engagedModality();
|
|
961
|
+
if (!this.domReady() || modality === 'none') {
|
|
962
|
+
return;
|
|
963
|
+
}
|
|
964
|
+
const release = untracked(() => modality === 'page' ? this.holdPageScope() : this.holdContainedScope());
|
|
965
|
+
onCleanup(release);
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
holdPageScope() {
|
|
969
|
+
const releaseInert = createInertSiblings(this.host, { scope: 'outside' });
|
|
970
|
+
const releaseLock = createScrollLock(this.scrollScope(this.doc.documentElement));
|
|
971
|
+
return () => {
|
|
972
|
+
releaseInert();
|
|
973
|
+
releaseLock();
|
|
974
|
+
};
|
|
975
|
+
}
|
|
976
|
+
// No trap: focus moves in once, Tab may leave for the live page around
|
|
977
|
+
// the boundary. The trap's focusFirst() waits for the render that drops
|
|
978
|
+
// the closed panel's inert.
|
|
979
|
+
holdContainedScope() {
|
|
980
|
+
const boundary = this.containedBoundary();
|
|
981
|
+
const id = this.host.id;
|
|
982
|
+
const releaseInert = createInertSiblings(this.host, {
|
|
983
|
+
scope: 'outside',
|
|
984
|
+
within: boundary,
|
|
985
|
+
keepLive: id ? `[aria-controls~="${id.replace(/["\\]/g, '\\$&')}"]` : undefined,
|
|
986
|
+
});
|
|
987
|
+
const scroller = this.scrollScope(null, boundary);
|
|
988
|
+
const releaseLock = scroller ? createScrollLock(scroller) : null;
|
|
989
|
+
this.focusTrap.focusFirst();
|
|
990
|
+
return () => {
|
|
991
|
+
releaseInert();
|
|
992
|
+
releaseLock?.();
|
|
993
|
+
};
|
|
994
|
+
}
|
|
995
|
+
containedBoundary() {
|
|
996
|
+
const named = this.driver()?.surfaceBoundary?.();
|
|
997
|
+
if (named && named !== this.host && named.contains(this.host)) {
|
|
998
|
+
return named;
|
|
999
|
+
}
|
|
1000
|
+
return this.host.parentElement ?? this.doc.body;
|
|
1001
|
+
}
|
|
1002
|
+
// An inner surface or an open popover inside the host takes the keypress
|
|
1003
|
+
// first; one Escape dismisses one layer.
|
|
1004
|
+
handleEscape(event) {
|
|
1005
|
+
if (!this.isActive() || escapeOwnedAbove(event, this.host)) {
|
|
1006
|
+
return;
|
|
1007
|
+
}
|
|
1008
|
+
claimEscape(event);
|
|
1009
|
+
this.emitDismiss();
|
|
1010
|
+
}
|
|
1011
|
+
clearEscapeKey() {
|
|
1012
|
+
if (this.escapeKeyTimer !== null) {
|
|
1013
|
+
clearTimeout(this.escapeKeyTimer);
|
|
1014
|
+
this.escapeKeyTimer = null;
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
handleCloseRequest() {
|
|
1018
|
+
if (this.escapeKeyTimer === null) {
|
|
1019
|
+
this.emitDismiss();
|
|
1020
|
+
}
|
|
1021
|
+
this.rearmIfEngaged();
|
|
1022
|
+
}
|
|
1023
|
+
// One shot: the next click is the trailing one of the dismissing gesture.
|
|
1024
|
+
// A gesture that ends without a click (a scroll, a cancelled touch) is
|
|
1025
|
+
// followed by a pointerdown or a keydown before any later click, so either
|
|
1026
|
+
// drops the guard. Listeners added during the dismissing pointerdown's
|
|
1027
|
+
// bubble phase do not see that same event.
|
|
1028
|
+
swallowTrailingClick() {
|
|
1029
|
+
this.releaseTrailingClick?.();
|
|
1030
|
+
const doc = this.doc;
|
|
1031
|
+
const swallow = (event) => {
|
|
1032
|
+
event.preventDefault();
|
|
1033
|
+
event.stopImmediatePropagation();
|
|
1034
|
+
release();
|
|
1035
|
+
};
|
|
1036
|
+
const release = () => {
|
|
1037
|
+
doc.removeEventListener('click', swallow, true);
|
|
1038
|
+
doc.removeEventListener('pointerdown', release, true);
|
|
1039
|
+
doc.removeEventListener('keydown', release, true);
|
|
1040
|
+
this.releaseTrailingClick = null;
|
|
1041
|
+
};
|
|
1042
|
+
doc.addEventListener('click', swallow, true);
|
|
1043
|
+
doc.addEventListener('pointerdown', release, true);
|
|
1044
|
+
doc.addEventListener('keydown', release, true);
|
|
1045
|
+
this.releaseTrailingClick = release;
|
|
1046
|
+
}
|
|
1047
|
+
requestDismiss() {
|
|
1048
|
+
this.emitDismiss();
|
|
1049
|
+
this.rearmIfEngaged();
|
|
1050
|
+
}
|
|
1051
|
+
emitDismiss() {
|
|
1052
|
+
this.dismiss.emit();
|
|
1053
|
+
this.driver()?.surfaceDismiss();
|
|
1054
|
+
}
|
|
1055
|
+
// A blocked dismissal leaves the surface engaged; the spent watcher would
|
|
1056
|
+
// let the next back gesture leave the page.
|
|
1057
|
+
rearmIfEngaged() {
|
|
1058
|
+
if (!this.destroyed && untracked(this.isActive)) {
|
|
1059
|
+
this.closeWatcher.arm();
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
// The nearest ancestor with a scrolling overflow-y, searched up to `stop`
|
|
1063
|
+
// (inclusive) or to the document root.
|
|
1064
|
+
scrollScope(fallback, stop) {
|
|
1065
|
+
const view = this.doc.defaultView;
|
|
1066
|
+
let node = this.host.parentElement;
|
|
1067
|
+
while (node && node !== this.doc.body && node !== this.doc.documentElement) {
|
|
1068
|
+
const overflowY = view?.getComputedStyle(node).overflowY ?? '';
|
|
1069
|
+
if (SCROLLING_OVERFLOW.has(overflowY)) {
|
|
1070
|
+
return node;
|
|
1071
|
+
}
|
|
1072
|
+
if (node === stop) {
|
|
1073
|
+
break;
|
|
1074
|
+
}
|
|
1075
|
+
node = node.parentElement;
|
|
1076
|
+
}
|
|
1077
|
+
return fallback;
|
|
1078
|
+
}
|
|
1079
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDrawerSurface, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1080
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxDrawerSurface, isStandalone: true, selector: "[cngxDrawerSurface]", inputs: { active: { classPropertyName: "active", publicName: "active", isSignal: true, isRequired: false, transformFunction: null }, modality: { classPropertyName: "modality", publicName: "modality", isSignal: true, isRequired: false, transformFunction: null }, role: { classPropertyName: "role", publicName: "role", isSignal: true, isRequired: false, transformFunction: null }, labelInput: { classPropertyName: "labelInput", publicName: "label", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { dismiss: "dismiss" }, host: { listeners: { "keydown.escape": "handleEscape($event)" }, properties: { "attr.role": "surfaceRole()", "attr.aria-modal": "engagedPage() ? 'true' : null", "attr.aria-label": "ariaLabel()", "attr.tabindex": "hostTabindex()" } }, providers: [
|
|
1081
|
+
{ provide: CNGX_FOCUS_TRAP_DRIVER, useExisting: CngxDrawerSurface },
|
|
1082
|
+
{ provide: CNGX_FOCUS_RESTORE_DRIVER, useExisting: CngxDrawerSurface },
|
|
1083
|
+
{ provide: CNGX_CLICK_OUTSIDE_DRIVER, useExisting: CngxDrawerSurface },
|
|
1084
|
+
{ provide: CNGX_HOTKEY_SCOPE, useFactory: () => inject(CngxDrawerSurface).hotkeyScope },
|
|
1085
|
+
], exportAs: ["cngxDrawerSurface"], hostDirectives: [{ directive: i1.CngxFocusTrap }, { directive: i1.CngxFocusRestore }, { directive: i2.CngxClickOutside }], ngImport: i0 });
|
|
1086
|
+
}
|
|
1087
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDrawerSurface, decorators: [{
|
|
1088
|
+
type: Directive,
|
|
1089
|
+
args: [{
|
|
1090
|
+
selector: '[cngxDrawerSurface]',
|
|
1091
|
+
exportAs: 'cngxDrawerSurface',
|
|
1092
|
+
standalone: true,
|
|
1093
|
+
hostDirectives: [
|
|
1094
|
+
{ directive: CngxFocusTrap, inputs: [], outputs: [] },
|
|
1095
|
+
{ directive: CngxFocusRestore, inputs: [], outputs: [] },
|
|
1096
|
+
{ directive: CngxClickOutside, inputs: [], outputs: [] },
|
|
1097
|
+
],
|
|
1098
|
+
providers: [
|
|
1099
|
+
{ provide: CNGX_FOCUS_TRAP_DRIVER, useExisting: CngxDrawerSurface },
|
|
1100
|
+
{ provide: CNGX_FOCUS_RESTORE_DRIVER, useExisting: CngxDrawerSurface },
|
|
1101
|
+
{ provide: CNGX_CLICK_OUTSIDE_DRIVER, useExisting: CngxDrawerSurface },
|
|
1102
|
+
{ provide: CNGX_HOTKEY_SCOPE, useFactory: () => inject(CngxDrawerSurface).hotkeyScope },
|
|
1103
|
+
],
|
|
1104
|
+
host: {
|
|
1105
|
+
'[attr.role]': 'surfaceRole()',
|
|
1106
|
+
'[attr.aria-modal]': "engagedPage() ? 'true' : null",
|
|
1107
|
+
'[attr.aria-label]': 'ariaLabel()',
|
|
1108
|
+
'[attr.tabindex]': 'hostTabindex()',
|
|
1109
|
+
'(keydown.escape)': 'handleEscape($event)',
|
|
1110
|
+
},
|
|
1111
|
+
}]
|
|
1112
|
+
}], ctorParameters: () => [], propDecorators: { active: [{ type: i0.Input, args: [{ isSignal: true, alias: "active", required: false }] }], modality: [{ type: i0.Input, args: [{ isSignal: true, alias: "modality", required: false }] }], role: [{ type: i0.Input, args: [{ isSignal: true, alias: "role", required: false }] }], labelInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], dismiss: [{ type: i0.Output, args: ["dismiss"] }] } });
|
|
1113
|
+
|
|
1114
|
+
/**
|
|
1115
|
+
* The sliding panel of a drawer. Reads its open state from an explicit
|
|
1116
|
+
* `[cngxDrawerPanel]` reference, or from the `CNGX_DRAWER_HOST` a
|
|
1117
|
+
* `CngxDrawer` on the same element provides when the attribute is bare - no
|
|
1118
|
+
* ancestor injection. Both go through the `CngxDrawerHost` contract, never
|
|
1119
|
+
* the concrete `CngxDrawer` class.
|
|
1120
|
+
*
|
|
1121
|
+
* The open panel is a transient surface (`CngxDrawerSurface`): Escape, the
|
|
1122
|
+
* Android back gesture and a press outside the panel close the drawer
|
|
1123
|
+
* (`closeOnClickOutside`, default `true`). A press on the trigger whose
|
|
1124
|
+
* `aria-controls` names the panel `id` is not outside, so the trigger
|
|
1125
|
+
* toggles the drawer itself. While closed the panel
|
|
1126
|
+
* is `aria-hidden` AND `inert`. On close, focus returns to the element that
|
|
1127
|
+
* was focused when the drawer opened - unless the user moved focus to
|
|
1128
|
+
* another element themselves.
|
|
1129
|
+
*
|
|
1130
|
+
* **Modality.** `modality` defaults to `'page'` for `over` and `'none'` for
|
|
1131
|
+
* `push`:
|
|
1132
|
+
*
|
|
1133
|
+
* - `'page'`: the open panel traps focus, renders `role="dialog"` +
|
|
1134
|
+
* `aria-modal="true"` (named by `label`, else a static `aria-label` /
|
|
1135
|
+
* `aria-labelledby`, else `CNGX_LAYOUT_I18N.drawerDialog`), makes
|
|
1136
|
+
* everything outside it `inert` up to `<body>`
|
|
1137
|
+
* (focus-trap anchors, live regions and a visible backdrop stay live) and
|
|
1138
|
+
* locks scrolling on the nearest scroll container above it (else the
|
|
1139
|
+
* document root). The full-height drawer that covers the app header.
|
|
1140
|
+
* - `'contained'`: the same inside the `[cngxDrawer]` host only. The
|
|
1141
|
+
* panel's siblings inside the host are `inert` and a scroll container
|
|
1142
|
+
* between the panel and the host is locked; everything outside the host
|
|
1143
|
+
* stays live. No trap and no `aria-modal`: focus moves into the panel on
|
|
1144
|
+
* open, returns to the opener on close, and Tab can reach the page
|
|
1145
|
+
* around the host. The clipped drawer below a live app header: place the
|
|
1146
|
+
* header outside `[cngxDrawer]`.
|
|
1147
|
+
* - `'none'`: the page around the panel stays operable.
|
|
1148
|
+
*
|
|
1149
|
+
* `push` is never modal: it lays the panel out next to the content, which
|
|
1150
|
+
* stays in use; `'page'` or `'contained'` with `push` resolve to `'none'`
|
|
1151
|
+
* and warn [`CNGX1076`](/error-codes/cngx1076.md) in development.
|
|
1152
|
+
*
|
|
1153
|
+
* **Scrim.** The panel renders `cngx-drawer-panel--modal` while its
|
|
1154
|
+
* resolved modality is `'page'` or `'contained'` (plus
|
|
1155
|
+
* `cngx-drawer-panel--contained` for the latter). The opt-in stylesheet
|
|
1156
|
+
* `cngx-drawer.css` skins the panel from its classes: add the `cngx-drawer`
|
|
1157
|
+
* class to the `[cngxDrawer]` host and the panel sits on its `position`
|
|
1158
|
+
* side with a surface and a border toward the content, slides in (in
|
|
1159
|
+
* `push` mode the content moves aside by its size), and the host shows a scrim over itself
|
|
1160
|
+
* while a modal panel inside it is open (`--cngx-drawer-scrim-bg`, default
|
|
1161
|
+
* `--cngx-backdrop-bg`). A press on the scrim is a press outside the panel
|
|
1162
|
+
* and closes the drawer. The panel sits above the scrim
|
|
1163
|
+
* (`--cngx-drawer-panel-z-index`, `2`, over `--cngx-drawer-scrim-z-index`,
|
|
1164
|
+
* `1`).
|
|
1165
|
+
*
|
|
1166
|
+
* The `role` input (landmark while not an open page modal) defaults to
|
|
1167
|
+
* `complementary`. On a `<nav>` host pass `[role]="null"` so the implicit
|
|
1168
|
+
* navigation landmark survives:
|
|
244
1169
|
*
|
|
245
1170
|
* ```html
|
|
246
|
-
* <
|
|
247
|
-
*
|
|
1171
|
+
* <button aria-controls="nav-panel" [attr.aria-expanded]="drawer.opened()"
|
|
1172
|
+
* (click)="drawer.toggle()">Menu</button>
|
|
1173
|
+
* <nav id="nav-panel" [cngxDrawerPanel]="drawer" position="left" mode="over" [role]="null">
|
|
248
1174
|
* <a href="/home">Home</a>
|
|
249
1175
|
* </nav>
|
|
250
1176
|
* ```
|
|
251
1177
|
*
|
|
252
|
-
* @category common/layout
|
|
253
1178
|
* @wcag AA
|
|
254
1179
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/drawer/drawer-panel.directive.ts
|
|
255
|
-
* @since 0.
|
|
1180
|
+
* @since 0.3.0
|
|
256
1181
|
* @relatedTo CngxDrawer, CngxDrawerContent, CngxFocusTrap
|
|
257
|
-
* <example-url
|
|
258
|
-
* <example-url
|
|
259
|
-
* <example-url
|
|
260
|
-
* <example-url
|
|
261
|
-
* <example-url
|
|
262
|
-
* <example-url
|
|
1182
|
+
* <example-url>/#/common/layout/drawer/basic-scroll-lock-backdrop</example-url>
|
|
1183
|
+
* <example-url>/#/common/layout/drawer/controlled-mode</example-url>
|
|
1184
|
+
* <example-url>/#/common/layout/drawer/direction-all-four-sides</example-url>
|
|
1185
|
+
* <example-url>/#/common/layout/drawer/events-openedchange-closed</example-url>
|
|
1186
|
+
* <example-url>/#/common/layout/drawer/app-header-clipped</example-url>
|
|
1187
|
+
* <example-url>/#/common/layout/drawer/full-height-modal</example-url>
|
|
1188
|
+
* <example-url>/#/common/layout/drawer/filter-panel-push</example-url>
|
|
1189
|
+
* <example-url>/#/common/layout/drawer/pattern-consumer-wiring</example-url>
|
|
263
1190
|
*/
|
|
264
1191
|
class CngxDrawerPanel {
|
|
265
|
-
/**
|
|
266
|
-
|
|
1192
|
+
/**
|
|
1193
|
+
* The drawer state owner (a `CngxDrawer`, or anything implementing
|
|
1194
|
+
* `CngxDrawerHost`). Bind it explicitly (`[cngxDrawerPanel]="drawer"`), or
|
|
1195
|
+
* leave the attribute bare on an element that also carries `cngxDrawer`.
|
|
1196
|
+
*/
|
|
1197
|
+
drawerInput = input(undefined, { ...(ngDevMode ? { debugName: "drawerInput" } : /* istanbul ignore next */ {}), alias: 'cngxDrawerPanel',
|
|
1198
|
+
transform: (v) => (typeof v === 'string' ? undefined : v) });
|
|
267
1199
|
/** Direction the panel slides from. */
|
|
268
1200
|
position = input('left', ...(ngDevMode ? [{ debugName: "position" }] : /* istanbul ignore next */ []));
|
|
269
1201
|
/**
|
|
270
1202
|
* How the panel interacts with the content area:
|
|
271
1203
|
* - `'over'` (default) - overlays content (absolute positioned)
|
|
272
1204
|
* - `'push'` - pushes content aside (content gets margin)
|
|
273
|
-
* - `'side'` - always visible, no toggle behavior
|
|
274
1205
|
*/
|
|
275
1206
|
mode = input('over', ...(ngDevMode ? [{ debugName: "mode" }] : /* istanbul ignore next */ []));
|
|
276
|
-
/**
|
|
1207
|
+
/**
|
|
1208
|
+
* How much of the page the open panel blocks:
|
|
1209
|
+
*
|
|
1210
|
+
* - `'page'`: the whole page is blocked. The panel is a modal dialog,
|
|
1211
|
+
* focus is trapped in it and everything outside it is `inert` up to
|
|
1212
|
+
* `<body>`.
|
|
1213
|
+
* - `'contained'`: only the `[cngxDrawer]` host is blocked. The content
|
|
1214
|
+
* beside the panel is `inert` and scroll-locked, everything outside the
|
|
1215
|
+
* host (an app header above it) stays clickable, and focus moves into
|
|
1216
|
+
* the panel without being trapped.
|
|
1217
|
+
* - `'none'`: nothing is blocked. No `inert`, no lock, no trap.
|
|
1218
|
+
*
|
|
1219
|
+
* With the `cngx-drawer` stylesheet, `'page'` and `'contained'` show a
|
|
1220
|
+
* scrim over the `[cngxDrawer]` host. Unbound, it follows the mode: `over`
|
|
1221
|
+
* is `'page'`, `push` is `'none'`. `push` never blocks: `'page'` or
|
|
1222
|
+
* `'contained'` with `push` resolve to `'none'` and warn [`CNGX1076`](/error-codes/cngx1076.md) in
|
|
1223
|
+
* development. See {@link CngxDrawerModality}.
|
|
1224
|
+
*/
|
|
1225
|
+
modality = input(undefined, ...(ngDevMode ? [{ debugName: "modality" }] : /* istanbul ignore next */ []));
|
|
1226
|
+
/** Whether a press outside the panel closes the drawer. */
|
|
277
1227
|
closeOnClickOutside = input(true, ...(ngDevMode ? [{ debugName: "closeOnClickOutside" }] : /* istanbul ignore next */ []));
|
|
278
1228
|
/**
|
|
279
|
-
* Landmark role rendered on the panel
|
|
280
|
-
*
|
|
281
|
-
*
|
|
1229
|
+
* Landmark role rendered on the panel while it is not an open page modal
|
|
1230
|
+
* (an open `'page'` panel is a `dialog`; a `'contained'` one keeps this
|
|
1231
|
+
* role). Defaults to `complementary`; pass `navigation` for nav drawers or
|
|
1232
|
+
* `null` to keep the element's implicit role (e.g. on a `<nav>` host).
|
|
282
1233
|
*/
|
|
283
1234
|
role = input('complementary', ...(ngDevMode ? [{ debugName: "role" }] : /* istanbul ignore next */ []));
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
1235
|
+
hostDrawer = inject(CNGX_DRAWER_HOST, { self: true, optional: true });
|
|
1236
|
+
/** The resolved drawer: the explicit reference wins over a drawer host on the element. */
|
|
1237
|
+
drawerRef = computed(() => this.drawerInput() ?? this.hostDrawer, ...(ngDevMode ? [{ debugName: "drawerRef" }] : /* istanbul ignore next */ []));
|
|
1238
|
+
staticId = inject(new HostAttributeToken('id'), { optional: true });
|
|
1239
|
+
/** The panel's `id`: a static `id` attribute wins over the drawer's `panelId`. */
|
|
1240
|
+
panelId = computed(() => {
|
|
1241
|
+
const fromDrawer = this.drawerRef()?.panelId();
|
|
1242
|
+
if (this.staticId !== null) {
|
|
1243
|
+
return this.staticId;
|
|
1244
|
+
}
|
|
1245
|
+
return fromDrawer === undefined || fromDrawer === '' ? null : fromDrawer;
|
|
1246
|
+
}, ...(ngDevMode ? [{ debugName: "panelId" }] : /* istanbul ignore next */ []));
|
|
1247
|
+
/** Whether the drawer is currently open (derived from the drawer ref). */
|
|
1248
|
+
isOpen = computed(() => this.drawerRef()?.opened() ?? false, ...(ngDevMode ? [{ debugName: "isOpen" }] : /* istanbul ignore next */ []));
|
|
1249
|
+
/** @internal Drives the composed `CngxDrawerSurface`. */
|
|
1250
|
+
surfaceActive = this.isOpen;
|
|
1251
|
+
/** @internal Drives the composed `CngxDrawerSurface`. */
|
|
1252
|
+
surfaceModality = computed(() => this.mode() === 'push' ? 'none' : (this.modality() ?? 'page'), ...(ngDevMode ? [{ debugName: "surfaceModality" }] : /* istanbul ignore next */ []));
|
|
1253
|
+
/** @internal Drives the composed `CngxDrawerSurface`: the `[cngxDrawer]` host. */
|
|
1254
|
+
surfaceBoundary = computed(() => this.drawerRef()?.elementRef.nativeElement ?? null, ...(ngDevMode ? [{ debugName: "surfaceBoundary" }] : /* istanbul ignore next */ []));
|
|
1255
|
+
/** @internal Drives the composed `CngxDrawerSurface`. */
|
|
1256
|
+
surfaceLandmarkRole = this.role;
|
|
1257
|
+
presentation = {
|
|
1258
|
+
mode: this.mode,
|
|
1259
|
+
modal: computed(() => this.surfaceModality() !== 'none'),
|
|
1260
|
+
position: this.position,
|
|
1261
|
+
element: inject(ElementRef).nativeElement,
|
|
1262
|
+
};
|
|
1263
|
+
/** @internal Drives the composed `CngxDrawerSurface`. */
|
|
1264
|
+
surfaceOutsideDismiss = this.closeOnClickOutside;
|
|
1265
|
+
connection = null;
|
|
288
1266
|
constructor() {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
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;
|
|
1267
|
+
inject(DestroyRef).onDestroy(() => this.disconnect());
|
|
1268
|
+
if (typeof ngDevMode !== 'undefined' && ngDevMode) {
|
|
1269
|
+
effect(() => {
|
|
1270
|
+
const requested = this.modality();
|
|
1271
|
+
if (this.mode() !== 'push' || requested === undefined || requested === 'none') {
|
|
308
1272
|
return;
|
|
309
1273
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
el.nativeElement.contains(active);
|
|
314
|
-
if (focusLost && this.restoreTarget?.isConnected) {
|
|
315
|
-
this.restoreTarget.focus();
|
|
316
|
-
}
|
|
317
|
-
this.restoreTarget = null;
|
|
1274
|
+
untracked(() => cngxDevWarn('CNGX1076', '[cngxDrawerPanel] mode="push" is never modal; a page or contained modality resolves to "none". ' +
|
|
1275
|
+
'A push drawer lays out next to the content, which stays in use. ' +
|
|
1276
|
+
'Use mode="over" for a modal drawer.', { modality: requested }));
|
|
318
1277
|
});
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
.
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
// Connecting registers the presentation in the drawer's slot, a signal
|
|
1281
|
+
// write; lifecycle hooks are no reactive context. ngOnChanges follows a
|
|
1282
|
+
// rebound reference, ngOnInit covers a panel without bound inputs.
|
|
1283
|
+
ngOnChanges() {
|
|
1284
|
+
this.syncConnection();
|
|
1285
|
+
}
|
|
1286
|
+
ngOnInit() {
|
|
1287
|
+
this.syncConnection();
|
|
1288
|
+
}
|
|
1289
|
+
syncConnection() {
|
|
1290
|
+
const drawer = untracked(this.drawerRef);
|
|
1291
|
+
if (this.connection?.drawer === drawer) {
|
|
1292
|
+
return;
|
|
1293
|
+
}
|
|
1294
|
+
this.disconnect();
|
|
1295
|
+
if (drawer) {
|
|
1296
|
+
this.connection = { drawer, disconnect: drawer.connectPanel(this.presentation) };
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
disconnect() {
|
|
1300
|
+
const connection = this.connection;
|
|
1301
|
+
this.connection = null;
|
|
1302
|
+
connection?.disconnect();
|
|
1303
|
+
}
|
|
1304
|
+
/** @internal Drives the composed `CngxDrawerSurface`. */
|
|
1305
|
+
surfaceDismiss() {
|
|
1306
|
+
this.drawerRef()?.close();
|
|
347
1307
|
}
|
|
348
1308
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDrawerPanel, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
349
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxDrawerPanel, isStandalone: true, selector: "[cngxDrawerPanel]", inputs: {
|
|
1309
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxDrawerPanel, isStandalone: true, selector: "[cngxDrawerPanel]", inputs: { drawerInput: { classPropertyName: "drawerInput", publicName: "cngxDrawerPanel", isSignal: true, isRequired: false, transformFunction: null }, position: { classPropertyName: "position", publicName: "position", isSignal: true, isRequired: false, transformFunction: null }, mode: { classPropertyName: "mode", publicName: "mode", isSignal: true, isRequired: false, transformFunction: null }, modality: { classPropertyName: "modality", publicName: "modality", 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--modal": "surfaceModality() !== 'none'", "class.cngx-drawer-panel--contained": "surfaceModality() === 'contained'", "attr.id": "panelId()", "attr.aria-hidden": "isOpen() ? null : true", "attr.inert": "isOpen() ? null : ''" } }, providers: [{ provide: CNGX_DRAWER_SURFACE_DRIVER, useExisting: CngxDrawerPanel }], exportAs: ["cngxDrawerPanel"], usesOnChanges: true, hostDirectives: [{ directive: CngxDrawerSurface, inputs: ["label", "label"] }], ngImport: i0 });
|
|
350
1310
|
}
|
|
351
1311
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDrawerPanel, decorators: [{
|
|
352
1312
|
type: Directive,
|
|
@@ -354,7 +1314,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
354
1314
|
selector: '[cngxDrawerPanel]',
|
|
355
1315
|
exportAs: 'cngxDrawerPanel',
|
|
356
1316
|
standalone: true,
|
|
357
|
-
hostDirectives: [{ directive:
|
|
1317
|
+
hostDirectives: [{ directive: CngxDrawerSurface, inputs: ['label'], outputs: [] }],
|
|
1318
|
+
providers: [{ provide: CNGX_DRAWER_SURFACE_DRIVER, useExisting: CngxDrawerPanel }],
|
|
358
1319
|
host: {
|
|
359
1320
|
'[class.cngx-drawer-panel]': 'true',
|
|
360
1321
|
'[class.cngx-drawer-panel--open]': 'isOpen()',
|
|
@@ -364,19 +1325,23 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
364
1325
|
'[class.cngx-drawer-panel--bottom]': "position() === 'bottom'",
|
|
365
1326
|
'[class.cngx-drawer-panel--over]': "mode() === 'over'",
|
|
366
1327
|
'[class.cngx-drawer-panel--push]': "mode() === 'push'",
|
|
367
|
-
'[class.cngx-drawer-panel--
|
|
368
|
-
'[
|
|
369
|
-
'[attr.
|
|
370
|
-
'[attr.
|
|
1328
|
+
'[class.cngx-drawer-panel--modal]': "surfaceModality() !== 'none'",
|
|
1329
|
+
'[class.cngx-drawer-panel--contained]': "surfaceModality() === 'contained'",
|
|
1330
|
+
'[attr.id]': 'panelId()',
|
|
1331
|
+
'[attr.aria-hidden]': 'isOpen() ? null : true',
|
|
1332
|
+
'[attr.inert]': "isOpen() ? null : ''",
|
|
371
1333
|
},
|
|
372
1334
|
}]
|
|
373
|
-
}], ctorParameters: () => [], propDecorators: {
|
|
1335
|
+
}], ctorParameters: () => [], propDecorators: { drawerInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxDrawerPanel", required: false }] }], position: [{ type: i0.Input, args: [{ isSignal: true, alias: "position", required: false }] }], mode: [{ type: i0.Input, args: [{ isSignal: true, alias: "mode", required: false }] }], modality: [{ type: i0.Input, args: [{ isSignal: true, alias: "modality", required: false }] }], closeOnClickOutside: [{ type: i0.Input, args: [{ isSignal: true, alias: "closeOnClickOutside", required: false }] }], role: [{ type: i0.Input, args: [{ isSignal: true, alias: "role", required: false }] }] } });
|
|
374
1336
|
|
|
375
1337
|
/**
|
|
376
1338
|
* Marks the main content area adjacent to a drawer panel.
|
|
377
1339
|
*
|
|
378
1340
|
* Adds a CSS class when the drawer is open so the consumer can offset
|
|
379
|
-
* the content via CSS transitions or transforms.
|
|
1341
|
+
* the content via CSS transitions or transforms. While a `push` panel is
|
|
1342
|
+
* open it also writes `data-drawer-push` with the panel's side (`left`,
|
|
1343
|
+
* `right`, `top`, `bottom`); `cngx-drawer.css` moves the content aside by
|
|
1344
|
+
* the panel size from it, so the panel itself slides at full size.
|
|
380
1345
|
*
|
|
381
1346
|
* ```html
|
|
382
1347
|
* <main [cngxDrawerContent]="drawer">
|
|
@@ -384,24 +1349,31 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
384
1349
|
* </main>
|
|
385
1350
|
* ```
|
|
386
1351
|
*
|
|
387
|
-
* @category common/layout
|
|
388
1352
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/drawer/drawer-content.directive.ts
|
|
389
|
-
* @since 0.
|
|
1353
|
+
* @since 0.3.0
|
|
390
1354
|
* @relatedTo CngxDrawer, CngxDrawerPanel
|
|
391
|
-
* <example-url
|
|
392
|
-
* <example-url
|
|
393
|
-
* <example-url
|
|
394
|
-
* <example-url
|
|
395
|
-
* <example-url
|
|
396
|
-
* <example-url
|
|
1355
|
+
* <example-url>/#/common/layout/drawer/basic-scroll-lock-backdrop</example-url>
|
|
1356
|
+
* <example-url>/#/common/layout/drawer/controlled-mode</example-url>
|
|
1357
|
+
* <example-url>/#/common/layout/drawer/direction-all-four-sides</example-url>
|
|
1358
|
+
* <example-url>/#/common/layout/drawer/events-openedchange-closed</example-url>
|
|
1359
|
+
* <example-url>/#/common/layout/drawer/app-header-clipped</example-url>
|
|
1360
|
+
* <example-url>/#/common/layout/drawer/full-height-modal</example-url>
|
|
1361
|
+
* <example-url>/#/common/layout/drawer/filter-panel-push</example-url>
|
|
1362
|
+
* <example-url>/#/common/layout/drawer/pattern-consumer-wiring</example-url>
|
|
397
1363
|
*/
|
|
398
1364
|
class CngxDrawerContent {
|
|
399
1365
|
/** Reference to the parent `CngxDrawer` state owner. */
|
|
400
1366
|
drawerRef = input.required({ ...(ngDevMode ? { debugName: "drawerRef" } : /* istanbul ignore next */ {}), alias: 'cngxDrawerContent' });
|
|
401
1367
|
/** Whether the drawer is currently open (derived from the drawer ref). */
|
|
402
1368
|
isOpen = computed(() => this.drawerRef().opened(), ...(ngDevMode ? [{ debugName: "isOpen" }] : /* istanbul ignore next */ []));
|
|
1369
|
+
/** Side of the open `push` panel the content gives way to; `null` otherwise. */
|
|
1370
|
+
pushSide = computed(() => {
|
|
1371
|
+
const drawer = this.drawerRef();
|
|
1372
|
+
const pushing = drawer.opened() && drawer.mode() === 'push';
|
|
1373
|
+
return pushing ? drawer.side() : null;
|
|
1374
|
+
}, ...(ngDevMode ? [{ debugName: "pushSide" }] : /* istanbul ignore next */ []));
|
|
403
1375
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDrawerContent, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
404
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxDrawerContent, isStandalone: true, selector: "[cngxDrawerContent]", inputs: { drawerRef: { classPropertyName: "drawerRef", publicName: "cngxDrawerContent", isSignal: true, isRequired: true, transformFunction: null } }, host: { properties: { "class.cngx-drawer-content": "true", "class.cngx-drawer-content--shifted": "isOpen()" } }, exportAs: ["cngxDrawerContent"], ngImport: i0 });
|
|
1376
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxDrawerContent, isStandalone: true, selector: "[cngxDrawerContent]", inputs: { drawerRef: { classPropertyName: "drawerRef", publicName: "cngxDrawerContent", isSignal: true, isRequired: true, transformFunction: null } }, host: { properties: { "class.cngx-drawer-content": "true", "class.cngx-drawer-content--shifted": "isOpen()", "attr.data-drawer-push": "pushSide()" } }, exportAs: ["cngxDrawerContent"], ngImport: i0 });
|
|
405
1377
|
}
|
|
406
1378
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxDrawerContent, decorators: [{
|
|
407
1379
|
type: Directive,
|
|
@@ -412,6 +1384,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
412
1384
|
host: {
|
|
413
1385
|
'[class.cngx-drawer-content]': 'true',
|
|
414
1386
|
'[class.cngx-drawer-content--shifted]': 'isOpen()',
|
|
1387
|
+
'[attr.data-drawer-push]': 'pushSide()',
|
|
415
1388
|
},
|
|
416
1389
|
}]
|
|
417
1390
|
}], propDecorators: { drawerRef: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxDrawerContent", required: true }] }] } });
|
|
@@ -450,12 +1423,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
450
1423
|
* </div>
|
|
451
1424
|
* ```
|
|
452
1425
|
*
|
|
453
|
-
* @category common/layout
|
|
454
|
-
* @docsKind primary
|
|
455
1426
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/observers/intersection-observer.directive.ts
|
|
456
|
-
* @since 0.
|
|
1427
|
+
* @since 0.3.0
|
|
457
1428
|
* @relatedTo CngxResizeObserver, CngxMediaQuery, CngxInfiniteScroll, CngxScrollSpy
|
|
458
|
-
* <example-url
|
|
1429
|
+
* <example-url>/#/common/layout/intersection-observer/scroll-sentinel</example-url>
|
|
1430
|
+
* @axis level atom
|
|
459
1431
|
*/
|
|
460
1432
|
class CngxIntersectionObserver {
|
|
461
1433
|
/** CSS selector for the scroll container root. `null` (default) uses the viewport. */
|
|
@@ -487,8 +1459,8 @@ class CngxIntersectionObserver {
|
|
|
487
1459
|
const rootMargin = this.rootMargin();
|
|
488
1460
|
const threshold = this.threshold();
|
|
489
1461
|
const resolvedRoot = root ? this.doc.querySelector(root) : null;
|
|
490
|
-
if (
|
|
491
|
-
|
|
1462
|
+
if (typeof ngDevMode !== 'undefined' && ngDevMode && root && !resolvedRoot) {
|
|
1463
|
+
cngxDevWarn('CNGX1032', `[cngxIntersectionObserver] root selector "${root}" matched no element - ` +
|
|
492
1464
|
'falling back to the viewport. A late-rendered root needs a re-bind of [root].');
|
|
493
1465
|
}
|
|
494
1466
|
const observer = new IntersectionObserver((entries) => {
|
|
@@ -531,7 +1503,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
531
1503
|
* ```html
|
|
532
1504
|
* <div cngxMediaQuery="(min-width: 1024px)" #mq="cngxMediaQuery">
|
|
533
1505
|
* <nav [cngxDrawerPanel]="drawer"
|
|
534
|
-
* [mode]="mq.matches() ? '
|
|
1506
|
+
* [mode]="mq.matches() ? 'push' : 'over'">
|
|
535
1507
|
* …
|
|
536
1508
|
* </nav>
|
|
537
1509
|
* </div>
|
|
@@ -544,12 +1516,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
544
1516
|
* </div>
|
|
545
1517
|
* ```
|
|
546
1518
|
*
|
|
547
|
-
* @category common/layout
|
|
548
|
-
* @docsKind primary
|
|
549
1519
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/observers/media-query.directive.ts
|
|
550
|
-
* @since 0.
|
|
1520
|
+
* @since 0.3.0
|
|
551
1521
|
* @relatedTo CngxResizeObserver, CngxIntersectionObserver
|
|
552
|
-
* <example-url
|
|
1522
|
+
* <example-url>/#/common/layout/media-query/viewport-breakpoints</example-url>
|
|
1523
|
+
* <example-url>/#/ui/breadcrumb/recipes/mobile-parent-only</example-url>
|
|
1524
|
+
* @axis level atom
|
|
553
1525
|
*/
|
|
554
1526
|
class CngxMediaQuery {
|
|
555
1527
|
/** The CSS media query string to evaluate. */
|
|
@@ -605,11 +1577,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
605
1577
|
*
|
|
606
1578
|
* @param query A CSS media query string, e.g. `(max-width: 640px)`.
|
|
607
1579
|
* @returns A reactive `Signal<boolean>` tracking the query's match state.
|
|
608
|
-
* @category common/layout
|
|
609
1580
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/observers/inject-media-query.ts
|
|
610
|
-
* @since 0.
|
|
1581
|
+
* @since 0.3.0
|
|
611
1582
|
* @relatedTo CngxMediaQuery, CngxResizeObserver
|
|
612
|
-
* <example-url
|
|
1583
|
+
* <example-url>/#/common/layout/media-query/inject-breakpoint-signal</example-url>
|
|
613
1584
|
*/
|
|
614
1585
|
function injectMediaQuery(query) {
|
|
615
1586
|
return createMediaQuerySignal(query, inject(DestroyRef), inject(DOCUMENT).defaultView);
|
|
@@ -619,17 +1590,17 @@ function injectMediaQuery(query) {
|
|
|
619
1590
|
* Dev-warning the query-param sync kernel emits when `@angular/router` is
|
|
620
1591
|
* not provided. Mirrors {@link warnTabsRouterAbsent} in `@cngx/common/tabs`
|
|
621
1592
|
* so the message stays identical across the two sync surfaces; only the
|
|
622
|
-
* `enables` clause differs
|
|
623
|
-
*
|
|
624
|
-
* `
|
|
1593
|
+
* `enables` clause differs. A deliberate small copy rather than a shared
|
|
1594
|
+
* import - sharing would force the helper onto a `public-api.ts`, and
|
|
1595
|
+
* `warn*` matches no approved public-API prefix.
|
|
625
1596
|
*
|
|
626
1597
|
* @internal
|
|
627
1598
|
*/
|
|
628
|
-
function warnRouterAbsent(
|
|
629
|
-
if (!
|
|
1599
|
+
function warnRouterAbsent(enables) {
|
|
1600
|
+
if (!(typeof ngDevMode !== 'undefined' && ngDevMode)) {
|
|
630
1601
|
return;
|
|
631
1602
|
}
|
|
632
|
-
|
|
1603
|
+
cngxDevWarn('CNGX1031', `injectQueryParamSync(): no Router / ActivatedRoute available - the URL sync is a no-op. ` +
|
|
633
1604
|
`Provide @angular/router via provideRouter(...) to enable ${enables}.`);
|
|
634
1605
|
}
|
|
635
1606
|
|
|
@@ -639,6 +1610,15 @@ function warnRouterAbsent(directive, enables) {
|
|
|
639
1610
|
* signal is the source and reflects outward. Re-hydrates on browser
|
|
640
1611
|
* back/forward. Dev-warns once and no-ops when `@angular/router` is absent.
|
|
641
1612
|
*
|
|
1613
|
+
* The key, the initial hydrate and the bookkeeping are resolved on the first
|
|
1614
|
+
* effect run, not in the call: a `Signal<string>` key backed by an input is
|
|
1615
|
+
* read after the input is bound, and in a directive the hydrated state is in
|
|
1616
|
+
* place before the caller's view first renders. A read of `state()` in the
|
|
1617
|
+
* caller's constructor or `ngOnInit` still sees the un-hydrated value. Called
|
|
1618
|
+
* from an environment injector (a service, `runInInjectionContext`), the
|
|
1619
|
+
* effects are root effects: `state()` is hydrated on the first application
|
|
1620
|
+
* tick, not when the call returns.
|
|
1621
|
+
*
|
|
642
1622
|
* Loop-safety (the core of this helper): the reflect effect writes the URL in
|
|
643
1623
|
* `untracked()` and skips `navigate` when the serialized `state()` equals the
|
|
644
1624
|
* last value it wrote - a local closure seeded from the initial URL read, not
|
|
@@ -647,44 +1627,58 @@ function warnRouterAbsent(directive, enables) {
|
|
|
647
1627
|
* back/forward re-hydration never triggers a reflex navigate. A `param` rename
|
|
648
1628
|
* is migrated in one navigate (`{ [old]: null, [new]: serialize(state()) }`)
|
|
649
1629
|
* by a dedicated effect whose only tracked source is the normalized param
|
|
650
|
-
* signal; its first run
|
|
1630
|
+
* signal; its first run finds the key `init()` seeded and never navigates.
|
|
651
1631
|
*
|
|
652
1632
|
* The `state.set` inside the hydrate effect is a deliberate signal-write-in-
|
|
653
1633
|
* effect: the URL is an external system and `state` is a caller-owned signal
|
|
654
1634
|
* the consumer must stay able to toggle, so hydrate cannot be a `computed`. It
|
|
655
1635
|
* is edge-guarded by serialized equality and wrapped in `untracked()`.
|
|
656
1636
|
*
|
|
657
|
-
* @category common/layout
|
|
658
1637
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/router/inject-query-param-sync.ts
|
|
659
|
-
* @since 0.
|
|
1638
|
+
* @since 0.3.0
|
|
660
1639
|
* @relatedTo CngxStepperRouterSync
|
|
661
|
-
* <example-url
|
|
1640
|
+
* <example-url>/#/common/layout/router/persisted-toggle</example-url>
|
|
662
1641
|
*/
|
|
663
1642
|
function injectQueryParamSync(state, opts) {
|
|
664
1643
|
const router = inject(Router, { optional: true });
|
|
665
|
-
|
|
666
|
-
|
|
1644
|
+
// Router is providedIn: 'root' and resolves without provideRouter(...);
|
|
1645
|
+
// ActivatedRoute does not, so it is the "router is set up" signal.
|
|
1646
|
+
const route = inject(ActivatedRoute, { optional: true });
|
|
1647
|
+
if (!router || !route) {
|
|
1648
|
+
if (typeof ngDevMode !== 'undefined' && ngDevMode) {
|
|
1649
|
+
warnRouterAbsent('query-param URL sync');
|
|
1650
|
+
}
|
|
667
1651
|
return;
|
|
668
1652
|
}
|
|
669
|
-
const route = inject(ActivatedRoute);
|
|
670
1653
|
const paramSignal = coerceSignal(opts.param);
|
|
671
1654
|
const serialize = opts.serialize ?? ((value) => (value ? 'open' : null));
|
|
672
1655
|
const deserialize = opts.deserialize ?? ((raw) => (raw != null));
|
|
673
|
-
// Closure bookkeeping, seeded from the initial URL read.
|
|
674
|
-
// the serialized value the reflect path last pushed to the
|
|
675
|
-
// path also updates it so an accepted URL value is not
|
|
676
|
-
|
|
677
|
-
let lastWritten =
|
|
678
|
-
let previousParam =
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
1656
|
+
// Closure bookkeeping, seeded by `init()` from the initial URL read.
|
|
1657
|
+
// `lastWritten` is the serialized value the reflect path last pushed to the
|
|
1658
|
+
// URL; the hydrate path also updates it so an accepted URL value is not
|
|
1659
|
+
// reflected back.
|
|
1660
|
+
let lastWritten = null;
|
|
1661
|
+
let previousParam = '';
|
|
1662
|
+
let initialized = false;
|
|
1663
|
+
// Runs once, on the first run of whichever effect runs first, so an
|
|
1664
|
+
// input-backed key is read after binding. URL wins on initial load.
|
|
1665
|
+
const init = () => {
|
|
1666
|
+
if (initialized) {
|
|
1667
|
+
return;
|
|
684
1668
|
}
|
|
685
|
-
|
|
1669
|
+
initialized = true;
|
|
1670
|
+
previousParam = paramSignal();
|
|
1671
|
+
lastWritten = route.snapshot.queryParamMap.get(previousParam) ?? null;
|
|
1672
|
+
if (lastWritten != null) {
|
|
1673
|
+
const hydrated = deserialize(lastWritten);
|
|
1674
|
+
if (!Object.is(hydrated, state())) {
|
|
1675
|
+
state.set(hydrated);
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
};
|
|
686
1679
|
// Reflect: signal change -> URL. Tracks `state()` only; param read untracked.
|
|
687
1680
|
effect(() => {
|
|
1681
|
+
untracked(init);
|
|
688
1682
|
const raw = serialize(state());
|
|
689
1683
|
untracked(() => {
|
|
690
1684
|
if (raw === lastWritten) {
|
|
@@ -702,7 +1696,7 @@ function injectQueryParamSync(state, opts) {
|
|
|
702
1696
|
});
|
|
703
1697
|
// Re-hydrate: URL change (back/forward) -> signal. Tracks the query-param
|
|
704
1698
|
// emission only; param and state reads are untracked. The first run mirrors
|
|
705
|
-
// the initial snapshot already handled
|
|
1699
|
+
// the initial snapshot already handled by `init()`, so it is skipped
|
|
706
1700
|
// - processing it would race the reflect effect's still-pending initial
|
|
707
1701
|
// navigate and reset `state` to a stale value. Later runs skip our own
|
|
708
1702
|
// reflect echo via the `lastWritten` guard.
|
|
@@ -713,6 +1707,7 @@ function injectQueryParamSync(state, opts) {
|
|
|
713
1707
|
effect(() => {
|
|
714
1708
|
const map = queryMap();
|
|
715
1709
|
untracked(() => {
|
|
1710
|
+
init();
|
|
716
1711
|
if (!hydrateInitialized) {
|
|
717
1712
|
hydrateInitialized = true;
|
|
718
1713
|
return;
|
|
@@ -730,10 +1725,12 @@ function injectQueryParamSync(state, opts) {
|
|
|
730
1725
|
});
|
|
731
1726
|
// Rename migration: param change -> one merged navigate that removes the old
|
|
732
1727
|
// key and writes the current value under the new one. Tracks the param
|
|
733
|
-
// signal only; the first run
|
|
1728
|
+
// signal only; the first run finds the `previousParam` `init()` seeded and
|
|
1729
|
+
// never navigates.
|
|
734
1730
|
effect(() => {
|
|
735
1731
|
const param = paramSignal();
|
|
736
1732
|
untracked(() => {
|
|
1733
|
+
init();
|
|
737
1734
|
if (param === previousParam) {
|
|
738
1735
|
return;
|
|
739
1736
|
}
|
|
@@ -752,6 +1749,10 @@ function injectQueryParamSync(state, opts) {
|
|
|
752
1749
|
});
|
|
753
1750
|
}
|
|
754
1751
|
|
|
1752
|
+
/** @internal Whether `host` can observe at all: false on SSR and jsdom hosts. */
|
|
1753
|
+
function canObserveResize(host) {
|
|
1754
|
+
return typeof host?.ResizeObserver === 'function';
|
|
1755
|
+
}
|
|
755
1756
|
/**
|
|
756
1757
|
* Subscribes `apply` to size changes of `element` on `host`.
|
|
757
1758
|
*
|
|
@@ -771,12 +1772,11 @@ function injectQueryParamSync(state, opts) {
|
|
|
771
1772
|
* @param box Which box model to report.
|
|
772
1773
|
* @param apply Receives the first entry of every observation batch.
|
|
773
1774
|
* @returns Teardown that disconnects the observer.
|
|
774
|
-
* @category common/layout/observers
|
|
775
1775
|
* @relatedTo createResizeSignal, observeMediaQuery
|
|
776
|
-
* @since 0.
|
|
1776
|
+
* @since 0.3.0
|
|
777
1777
|
*/
|
|
778
1778
|
function observeResize(host, element, box, apply) {
|
|
779
|
-
if (!host
|
|
1779
|
+
if (!canObserveResize(host)) {
|
|
780
1780
|
return () => undefined;
|
|
781
1781
|
}
|
|
782
1782
|
const observer = new host.ResizeObserver((entries) => apply(entries[0]));
|
|
@@ -810,9 +1810,8 @@ function observeResize(host, element, box, apply) {
|
|
|
810
1810
|
* @param destroyRef Scope whose destruction disconnects the observer.
|
|
811
1811
|
* @param host The window-like object to read `ResizeObserver` from.
|
|
812
1812
|
* @returns A readonly signal carrying the latest entry.
|
|
813
|
-
* @category common/layout/observers
|
|
814
1813
|
* @relatedTo observeResize, createMediaQuerySignal
|
|
815
|
-
* @since 0.
|
|
1814
|
+
* @since 0.3.0
|
|
816
1815
|
*/
|
|
817
1816
|
function createResizeSignal(element, box, destroyRef, host) {
|
|
818
1817
|
const entry = signal(null, ...(ngDevMode ? [{ debugName: "entry" }] : /* istanbul ignore next */ []));
|
|
@@ -845,12 +1844,12 @@ function createResizeSignal(element, box, destroyRef, host) {
|
|
|
845
1844
|
* readonly columns = computed(() => (this.ro()?.width() ?? 0) > 600 ? 3 : 1);
|
|
846
1845
|
* ```
|
|
847
1846
|
*
|
|
848
|
-
* @category common/layout
|
|
849
|
-
* @docsKind primary
|
|
850
1847
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/observers/resize-observer.directive.ts
|
|
851
|
-
* @since 0.
|
|
1848
|
+
* @since 0.3.0
|
|
852
1849
|
* @relatedTo CngxIntersectionObserver, CngxMediaQuery
|
|
853
|
-
* <example-url
|
|
1850
|
+
* <example-url>/#/common/layout/resize-observer/live-size</example-url>
|
|
1851
|
+
* <example-url>/#/ui/breadcrumb/recipes/responsive-collapse</example-url>
|
|
1852
|
+
* @axis level atom
|
|
854
1853
|
*/
|
|
855
1854
|
class CngxResizeObserver {
|
|
856
1855
|
/** Which box model to observe. `'content-box'` (default), `'border-box'`, or `'device-pixel-content-box'`. */
|
|
@@ -899,8 +1898,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
899
1898
|
* needs a container and finds none must say so (a dev-mode warning), not
|
|
900
1899
|
* silently observe itself.
|
|
901
1900
|
*
|
|
902
|
-
* @
|
|
903
|
-
* @since 0.1.0
|
|
1901
|
+
* @since 0.3.0
|
|
904
1902
|
*/
|
|
905
1903
|
const CNGX_CONTAINER_SIZE = new InjectionToken('CNGX_CONTAINER_SIZE');
|
|
906
1904
|
/**
|
|
@@ -915,9 +1913,8 @@ const CNGX_CONTAINER_SIZE = new InjectionToken('CNGX_CONTAINER_SIZE');
|
|
|
915
1913
|
* @param element The container host.
|
|
916
1914
|
* @param destroyRef Scope whose destruction disconnects the observer.
|
|
917
1915
|
* @param win The window-like object providing `ResizeObserver` and `getComputedStyle`.
|
|
918
|
-
* @category common/layout/observers
|
|
919
1916
|
* @relatedTo injectContainerSize, CngxContainer
|
|
920
|
-
* @since 0.
|
|
1917
|
+
* @since 0.3.0
|
|
921
1918
|
*/
|
|
922
1919
|
function createContainerSize(element, destroyRef, win) {
|
|
923
1920
|
const entry = createResizeSignal(element, 'border-box', destroyRef, win);
|
|
@@ -957,7 +1954,7 @@ function createContainerSize(element, destroyRef, win) {
|
|
|
957
1954
|
byName.set(key, value);
|
|
958
1955
|
return value;
|
|
959
1956
|
};
|
|
960
|
-
return { inlineSize, blockSize, isReady, property };
|
|
1957
|
+
return { inlineSize, blockSize, isReady, observes: canObserveResize(win), property };
|
|
961
1958
|
}
|
|
962
1959
|
/**
|
|
963
1960
|
* Reads the nearest query container declared by a `[cngxContainer]` ancestor,
|
|
@@ -970,7 +1967,7 @@ function createContainerSize(element, destroyRef, win) {
|
|
|
970
1967
|
* ```typescript
|
|
971
1968
|
* private readonly container = inject(CNGX_CONTAINER_SIZE, { optional: true });
|
|
972
1969
|
* private readonly wide = this.container?.property('--cngx-thing-wide', this.host) ?? signal('').asReadonly();
|
|
973
|
-
* readonly mode = computed(() => (this.wide() === '1' ? '
|
|
1970
|
+
* readonly mode = computed(() => (this.wide() === '1' ? 'push' : 'over'));
|
|
974
1971
|
* ```
|
|
975
1972
|
*
|
|
976
1973
|
* A component that declares the container in its own stylesheet and reads it
|
|
@@ -984,9 +1981,8 @@ function createContainerSize(element, destroyRef, win) {
|
|
|
984
1981
|
* ```
|
|
985
1982
|
*
|
|
986
1983
|
* @param target Element to observe when no ancestor container exists.
|
|
987
|
-
* @category common/layout/observers
|
|
988
1984
|
* @relatedTo CngxContainer, injectMediaQuery
|
|
989
|
-
* @since 0.
|
|
1985
|
+
* @since 0.3.0
|
|
990
1986
|
*/
|
|
991
1987
|
function injectContainerSize(target) {
|
|
992
1988
|
const ancestor = inject(CNGX_CONTAINER_SIZE, { optional: true, skipSelf: true });
|
|
@@ -1036,12 +2032,11 @@ function injectContainerSize(target) {
|
|
|
1036
2032
|
* content (an inline chip, a `width: max-content` bar) must not be a
|
|
1037
2033
|
* container.
|
|
1038
2034
|
*
|
|
1039
|
-
* @category common/layout
|
|
1040
|
-
* @docsKind primary
|
|
1041
2035
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/observers/container.directive.ts
|
|
1042
|
-
* @since 0.
|
|
2036
|
+
* @since 0.3.0
|
|
1043
2037
|
* @relatedTo injectContainerSize, CngxResizeObserver, CngxMediaQuery
|
|
1044
|
-
* <example-url
|
|
2038
|
+
* <example-url>/#/common/layout/container/css-decides-js-reads</example-url>
|
|
2039
|
+
* @axis level atom
|
|
1045
2040
|
*/
|
|
1046
2041
|
class CngxContainer {
|
|
1047
2042
|
size = createContainerSize(inject(ElementRef).nativeElement, inject(DestroyRef), inject(DOCUMENT).defaultView);
|
|
@@ -1051,6 +2046,8 @@ class CngxContainer {
|
|
|
1051
2046
|
blockSize = this.size.blockSize;
|
|
1052
2047
|
/** `true` once the first observation has arrived. */
|
|
1053
2048
|
isReady = this.size.isReady;
|
|
2049
|
+
/** `false` on a host without `ResizeObserver` (SSR, jsdom). */
|
|
2050
|
+
observes = this.size.observes;
|
|
1054
2051
|
/**
|
|
1055
2052
|
* The resolved value of a custom property on `on` (default: this host),
|
|
1056
2053
|
* re-read on every resize. The `@container` rule must style a descendant,
|
|
@@ -1060,94 +2057,561 @@ class CngxContainer {
|
|
|
1060
2057
|
property(name, on, pseudo) {
|
|
1061
2058
|
return this.size.property(name, on, pseudo);
|
|
1062
2059
|
}
|
|
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 });
|
|
2060
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxContainer, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
2061
|
+
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 });
|
|
2062
|
+
}
|
|
2063
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxContainer, decorators: [{
|
|
2064
|
+
type: Directive,
|
|
2065
|
+
args: [{
|
|
2066
|
+
selector: '[cngxContainer]',
|
|
2067
|
+
exportAs: 'cngxContainer',
|
|
2068
|
+
standalone: true,
|
|
2069
|
+
providers: [{ provide: CNGX_CONTAINER_SIZE, useExisting: CngxContainer }],
|
|
2070
|
+
}]
|
|
2071
|
+
}] });
|
|
2072
|
+
|
|
2073
|
+
/**
|
|
2074
|
+
* The trigger of a drawer, sidebar or sidenav panel. It owns no state: it
|
|
2075
|
+
* mirrors the target's `expanded` as `aria-expanded`, points
|
|
2076
|
+
* `aria-controls` at the target's `id`, and calls `toggle()` (or `peek()`)
|
|
2077
|
+
* on click, Enter and Space.
|
|
2078
|
+
*
|
|
2079
|
+
* The target is an explicit reference (`[cngxPanelTrigger]="drawer"`). A
|
|
2080
|
+
* bare `cngxPanelTrigger` inside the panel resolves the surrounding
|
|
2081
|
+
* `CNGX_PANEL_TARGET` (a pin or close button). Because the trigger names
|
|
2082
|
+
* the panel in `aria-controls`, a press on it is not an outside press for
|
|
2083
|
+
* the panel's dismissal, so one press toggles once.
|
|
2084
|
+
*
|
|
2085
|
+
* On a native `<button>` the browser turns Enter and Space into the click.
|
|
2086
|
+
* Any other host gets `role="button"`, `tabindex="0"` and its own
|
|
2087
|
+
* Enter / Space handling. An icon-only trigger (no text content; text
|
|
2088
|
+
* inside `hidden` or `aria-hidden` elements does not count) is named after
|
|
2089
|
+
* the panel: a bound `label`, else a static `aria-label`, else the
|
|
2090
|
+
* target's `label`, else
|
|
2091
|
+
* `CNGX_LAYOUT_I18N.panelTrigger`. The name stays the same while the panel
|
|
2092
|
+
* opens and closes; `aria-expanded` carries the state. A trigger with
|
|
2093
|
+
* visible text keeps its text as its name. The check follows the host
|
|
2094
|
+
* content: text added to or removed from the trigger later (an
|
|
2095
|
+
* interpolation, an `@if`) switches between the two.
|
|
2096
|
+
*
|
|
2097
|
+
* The trigger draws nothing: the host's content is the consumer's. For an
|
|
2098
|
+
* icon button with a glyph that follows the panel, use
|
|
2099
|
+
* `button[cngxPanelToggle]`, which composes this directive.
|
|
2100
|
+
*
|
|
2101
|
+
* ```html
|
|
2102
|
+
* <button type="button" [cngxPanelTrigger]="drawer">Menu</button>
|
|
2103
|
+
* <div cngxDrawer #drawer="cngxDrawer" panelId="nav">
|
|
2104
|
+
* <nav [cngxDrawerPanel]="drawer">…</nav>
|
|
2105
|
+
* </div>
|
|
2106
|
+
* ```
|
|
2107
|
+
*
|
|
2108
|
+
* @wcag AA
|
|
2109
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/panel-trigger/panel-trigger.directive.ts
|
|
2110
|
+
* @since 0.3.0
|
|
2111
|
+
* @relatedTo CngxPanelToggle, CngxPanelTarget, CNGX_PANEL_TARGET, CngxDrawer, CngxSidebar
|
|
2112
|
+
* <example-url>/#/common/layout/sidebar/clipped-below-header</example-url>
|
|
2113
|
+
* <example-url>/#/common/layout/sidebar/collapsible-rail</example-url>
|
|
2114
|
+
* <example-url>/#/common/layout/sidebar/inset-app-sidebar</example-url>
|
|
2115
|
+
* <example-url>/#/common/layout/drawer/app-header-clipped</example-url>
|
|
2116
|
+
* <example-url>/#/common/layout/drawer/full-height-modal</example-url>
|
|
2117
|
+
* @axis level atom
|
|
2118
|
+
*/
|
|
2119
|
+
class CngxPanelTrigger {
|
|
2120
|
+
/**
|
|
2121
|
+
* The panel to control. Bind it explicitly, or leave the attribute bare
|
|
2122
|
+
* inside a panel that provides `CNGX_PANEL_TARGET`.
|
|
2123
|
+
*/
|
|
2124
|
+
targetInput = input(undefined, { ...(ngDevMode ? { debugName: "targetInput" } : /* istanbul ignore next */ {}), alias: 'cngxPanelTrigger',
|
|
2125
|
+
transform: (v) => (typeof v === 'string' ? undefined : v) });
|
|
2126
|
+
/**
|
|
2127
|
+
* `toggle` (default) flips the panel. `peek` shows it temporarily; a target
|
|
2128
|
+
* without `peek()` toggles instead.
|
|
2129
|
+
*/
|
|
2130
|
+
action = input('toggle', ...(ngDevMode ? [{ debugName: "action" }] : /* istanbul ignore next */ []));
|
|
2131
|
+
/**
|
|
2132
|
+
* Accessible name. Unbound, a static `aria-label` on the host stays; on a
|
|
2133
|
+
* trigger without text content or a static `aria-label` it falls back to
|
|
2134
|
+
* the target's `label`, then to `CNGX_LAYOUT_I18N.panelTrigger`. It does
|
|
2135
|
+
* not follow the panel state; `aria-expanded` does.
|
|
2136
|
+
*/
|
|
2137
|
+
label = input(undefined, ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
|
|
2138
|
+
host = inject(ElementRef).nativeElement;
|
|
2139
|
+
providedTarget = inject(CNGX_PANEL_TARGET, { optional: true });
|
|
2140
|
+
i18n = injectLayoutI18n();
|
|
2141
|
+
// The aria-label binding would drop a static aria-label, so it renders it.
|
|
2142
|
+
staticLabel = inject(new HostAttributeToken('aria-label'), { optional: true });
|
|
2143
|
+
rendered = signal(false, ...(ngDevMode ? [{ debugName: "rendered" }] : /* istanbul ignore next */ []));
|
|
2144
|
+
// Bumped by a MutationObserver on the host: the text and the attributes
|
|
2145
|
+
// that decide the name are not signals, so hasOwnName reads the DOM and
|
|
2146
|
+
// tracks this version instead of a written copy.
|
|
2147
|
+
nameVersion = signal(0, ...(ngDevMode ? [{ debugName: "nameVersion" }] : /* istanbul ignore next */ []));
|
|
2148
|
+
// Until the first render the projected content is not there yet; assume a
|
|
2149
|
+
// named trigger so no fallback label flashes onto a text trigger.
|
|
2150
|
+
hasOwnName = computed(() => {
|
|
2151
|
+
if (!this.rendered()) {
|
|
2152
|
+
return true;
|
|
2153
|
+
}
|
|
2154
|
+
this.nameVersion();
|
|
2155
|
+
return nameText(this.host).trim() !== '' || this.host.hasAttribute('aria-labelledby');
|
|
2156
|
+
}, ...(ngDevMode ? [{ debugName: "hasOwnName" }] : /* istanbul ignore next */ []));
|
|
2157
|
+
nativeButton = this.host.tagName === 'BUTTON';
|
|
2158
|
+
/** The resolved target: the explicit reference wins over the provided one. */
|
|
2159
|
+
target = computed(() => this.targetInput() ?? this.providedTarget, ...(ngDevMode ? [{ debugName: "target" }] : /* istanbul ignore next */ []));
|
|
2160
|
+
/**
|
|
2161
|
+
* Whether the controlled panel is shown in its resting state. A peek is
|
|
2162
|
+
* transient pointer presentation, so a peeked target reads as collapsed.
|
|
2163
|
+
*/
|
|
2164
|
+
expanded = computed(() => {
|
|
2165
|
+
const target = this.target();
|
|
2166
|
+
return !!target && target.expanded() && !(target.peeked?.() ?? false);
|
|
2167
|
+
}, ...(ngDevMode ? [{ debugName: "expanded" }] : /* istanbul ignore next */ []));
|
|
2168
|
+
controls = computed(() => {
|
|
2169
|
+
const id = this.target()?.id();
|
|
2170
|
+
return id === undefined || id === '' ? null : id;
|
|
2171
|
+
}, ...(ngDevMode ? [{ debugName: "controls" }] : /* istanbul ignore next */ []));
|
|
2172
|
+
fallbackLabel = computed(() => {
|
|
2173
|
+
if (this.hasOwnName()) {
|
|
2174
|
+
return null;
|
|
2175
|
+
}
|
|
2176
|
+
return this.target()?.label?.() ?? this.i18n().panelTrigger;
|
|
2177
|
+
}, ...(ngDevMode ? [{ debugName: "fallbackLabel" }] : /* istanbul ignore next */ []));
|
|
2178
|
+
resolvedLabel = computed(() => this.label() ?? this.staticLabel ?? this.fallbackLabel(), ...(ngDevMode ? [{ debugName: "resolvedLabel" }] : /* istanbul ignore next */ []));
|
|
2179
|
+
handleActivationKey = createActivationKeyHandler(this.host, () => this.activate());
|
|
2180
|
+
constructor() {
|
|
2181
|
+
let observer = null;
|
|
2182
|
+
inject(DestroyRef).onDestroy(() => observer?.disconnect());
|
|
2183
|
+
afterNextRender(() => {
|
|
2184
|
+
this.rendered.set(true);
|
|
2185
|
+
if (typeof MutationObserver === 'undefined') {
|
|
2186
|
+
return;
|
|
2187
|
+
}
|
|
2188
|
+
observer = new MutationObserver(() => this.nameVersion.update((v) => v + 1));
|
|
2189
|
+
observer.observe(this.host, {
|
|
2190
|
+
characterData: true,
|
|
2191
|
+
childList: true,
|
|
2192
|
+
subtree: true,
|
|
2193
|
+
attributes: true,
|
|
2194
|
+
attributeFilter: ['hidden', 'aria-hidden', 'aria-labelledby'],
|
|
2195
|
+
});
|
|
2196
|
+
});
|
|
2197
|
+
}
|
|
2198
|
+
/** Runs the action on the target. */
|
|
2199
|
+
activate() {
|
|
2200
|
+
const target = this.target();
|
|
2201
|
+
if (!target) {
|
|
2202
|
+
return;
|
|
2203
|
+
}
|
|
2204
|
+
if (this.action() === 'peek' && target.peek) {
|
|
2205
|
+
target.peek();
|
|
2206
|
+
return;
|
|
2207
|
+
}
|
|
2208
|
+
target.toggle();
|
|
2209
|
+
}
|
|
2210
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxPanelTrigger, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
2211
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxPanelTrigger, isStandalone: true, selector: "[cngxPanelTrigger]", inputs: { targetInput: { classPropertyName: "targetInput", publicName: "cngxPanelTrigger", isSignal: true, isRequired: false, transformFunction: null }, action: { classPropertyName: "action", publicName: "action", isSignal: true, isRequired: false, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null } }, host: { listeners: { "click": "activate()", "keydown.enter": "handleActivationKey($event)", "keydown.space": "handleActivationKey($event)" }, properties: { "attr.aria-expanded": "expanded()", "attr.aria-controls": "controls()", "attr.aria-label": "resolvedLabel()", "attr.role": "nativeButton ? null : 'button'", "attr.tabindex": "nativeButton ? null : '0'" } }, exportAs: ["cngxPanelTrigger"], ngImport: i0 });
|
|
1065
2212
|
}
|
|
1066
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type:
|
|
2213
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxPanelTrigger, decorators: [{
|
|
1067
2214
|
type: Directive,
|
|
1068
2215
|
args: [{
|
|
1069
|
-
selector: '[
|
|
1070
|
-
exportAs: '
|
|
2216
|
+
selector: '[cngxPanelTrigger]',
|
|
2217
|
+
exportAs: 'cngxPanelTrigger',
|
|
1071
2218
|
standalone: true,
|
|
1072
|
-
|
|
2219
|
+
host: {
|
|
2220
|
+
'[attr.aria-expanded]': 'expanded()',
|
|
2221
|
+
'[attr.aria-controls]': 'controls()',
|
|
2222
|
+
'[attr.aria-label]': 'resolvedLabel()',
|
|
2223
|
+
'[attr.role]': "nativeButton ? null : 'button'",
|
|
2224
|
+
'[attr.tabindex]': "nativeButton ? null : '0'",
|
|
2225
|
+
'(click)': 'activate()',
|
|
2226
|
+
'(keydown.enter)': 'handleActivationKey($event)',
|
|
2227
|
+
'(keydown.space)': 'handleActivationKey($event)',
|
|
2228
|
+
},
|
|
1073
2229
|
}]
|
|
1074
|
-
}] });
|
|
1075
|
-
|
|
2230
|
+
}], ctorParameters: () => [], propDecorators: { targetInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxPanelTrigger", required: false }] }], action: [{ type: i0.Input, args: [{ isSignal: true, alias: "action", required: false }] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }] } });
|
|
1076
2231
|
/**
|
|
1077
|
-
*
|
|
1078
|
-
*
|
|
1079
|
-
*
|
|
1080
|
-
* below without sharing the count, so interleaved acquire/release across the
|
|
1081
|
-
* two owners corrupts each other's saved overflow values.
|
|
1082
|
-
*
|
|
1083
|
-
* @internal
|
|
2232
|
+
* The text that names the host: its text content without `hidden` and
|
|
2233
|
+
* `aria-hidden` subtrees, which the accessible name skips as well (a
|
|
2234
|
+
* component's hidden disabled reason, an `aria-hidden` glyph slot).
|
|
1084
2235
|
*/
|
|
1085
|
-
|
|
2236
|
+
function nameText(node) {
|
|
2237
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
2238
|
+
return node.textContent ?? '';
|
|
2239
|
+
}
|
|
2240
|
+
return Array.from(node.childNodes)
|
|
2241
|
+
.filter((child) => !(child instanceof Element) ||
|
|
2242
|
+
!(child.hasAttribute('hidden') || child.getAttribute('aria-hidden') === 'true'))
|
|
2243
|
+
.map(nameText)
|
|
2244
|
+
.join('');
|
|
2245
|
+
}
|
|
2246
|
+
|
|
1086
2247
|
/**
|
|
1087
|
-
*
|
|
1088
|
-
*
|
|
2248
|
+
* Icon button that opens and closes a drawer or sidebar and draws its own
|
|
2249
|
+
* glyph. The behaviour is a composed `CngxPanelTrigger`: `aria-expanded`
|
|
2250
|
+
* mirrors the panel, `aria-controls` names it, a press toggles it (or peeks
|
|
2251
|
+
* it with `action="peek"`), and the accessible name is the panel's: a
|
|
2252
|
+
* bound `label`, else the target's `label`, else
|
|
2253
|
+
* `CNGX_LAYOUT_I18N.panelTrigger`. The name stays the same while the panel
|
|
2254
|
+
* opens and closes.
|
|
2255
|
+
*
|
|
2256
|
+
* The glyph follows how the target presents the panel right now, so it
|
|
2257
|
+
* changes with a breakpoint that switches the panel's `mode`:
|
|
2258
|
+
*
|
|
2259
|
+
* - a modal over-drawer (the mobile nav: `mode="over"` with a `page` or
|
|
2260
|
+
* `contained` modality) shows three bars while closed and a cross while
|
|
2261
|
+
* open;
|
|
2262
|
+
* - every other presentation (an inline sidebar or rail, a push drawer, a
|
|
2263
|
+
* non-modal over-drawer) shows a panel glyph that draws what a press
|
|
2264
|
+
* does: a frame with a column on the panel's side and a chevron pointing
|
|
2265
|
+
* away from the column while the panel is closed (open it), toward the
|
|
2266
|
+
* column while it is open (close it). `aria-expanded` carries the same
|
|
2267
|
+
* state for assistive technology. The glyph mirrors for a panel
|
|
2268
|
+
* on the right: `position="right"`, or the end side in LTR and the start
|
|
2269
|
+
* side in RTL (`CNGX_DIRECTION`).
|
|
2270
|
+
*
|
|
2271
|
+
* A target without `mode` / `modal` / `side` (a consumer-built
|
|
2272
|
+
* `CngxPanelTarget`) reads as an inline panel on the start side. The glyph
|
|
2273
|
+
* is `aria-hidden`; project an icon to replace it. The state the default
|
|
2274
|
+
* glyph follows is public on the exported instance (`expanded`,
|
|
2275
|
+
* `modalOverlay`, `mirrored`), so a projected glyph can follow it too:
|
|
1089
2276
|
*
|
|
1090
|
-
*
|
|
1091
|
-
*
|
|
1092
|
-
* (
|
|
1093
|
-
*
|
|
1094
|
-
*
|
|
2277
|
+
* ```html
|
|
2278
|
+
* <button type="button" [cngxPanelToggle]="nav" #toggle="cngxPanelToggle">
|
|
2279
|
+
* <cngx-icon [style.transform]="toggle.mirrored() ? 'scaleX(-1)' : null">
|
|
2280
|
+
* <mat-icon>{{ toggle.expanded() ? 'menu_open' : 'menu' }}</mat-icon>
|
|
2281
|
+
* </cngx-icon>
|
|
2282
|
+
* </button>
|
|
2283
|
+
* ```
|
|
1095
2284
|
*
|
|
1096
|
-
*
|
|
1097
|
-
*
|
|
2285
|
+
* Shares the button family's state surface: `disabled` renders
|
|
2286
|
+
* `aria-disabled` (the button stays focusable and swallows activation) and
|
|
2287
|
+
* `disabledReason` is read through `aria-describedby`. The emphasis stays
|
|
2288
|
+
* `ghost` unless `variant` is set; `size` and `tone` fall through to the
|
|
2289
|
+
* group, `provideButtonConfig` and the icon-button defaults.
|
|
1098
2290
|
*
|
|
1099
|
-
* ```
|
|
1100
|
-
*
|
|
1101
|
-
*
|
|
1102
|
-
*
|
|
2291
|
+
* ```html
|
|
2292
|
+
* <button type="button" [cngxPanelToggle]="nav"></button>
|
|
2293
|
+
* <div cngxDrawer #nav="cngxDrawer" panelId="main-nav">
|
|
2294
|
+
* <nav [cngxDrawerPanel]="nav" [mode]="mobile() ? 'over' : 'push'">…</nav>
|
|
2295
|
+
* </div>
|
|
1103
2296
|
* ```
|
|
1104
2297
|
*
|
|
1105
|
-
* @
|
|
1106
|
-
* @
|
|
2298
|
+
* @wcag AA
|
|
2299
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/panel-toggle/panel-toggle.component.ts
|
|
2300
|
+
* @since 0.3.0
|
|
2301
|
+
* @relatedTo CngxPanelTrigger, CngxPanelTarget, CngxDrawer, CngxSidebar, CngxIconButton
|
|
2302
|
+
* <example-url>/#/common/layout/sidebar/inset-app-sidebar</example-url>
|
|
2303
|
+
* <example-url>/#/common/layout/sidebar/collapsible-rail</example-url>
|
|
2304
|
+
* <example-url>/#/common/layout/drawer/app-header-clipped</example-url>
|
|
2305
|
+
* <example-url>/#/common/layout/drawer/full-height-modal</example-url>
|
|
2306
|
+
* <example-url>/#/common/layout/drawer/filter-panel-push</example-url>
|
|
2307
|
+
* <example-url>/#/common/layout/sidebar/projected-toggle-glyph</example-url>
|
|
2308
|
+
* @axis level molecule
|
|
2309
|
+
*/
|
|
2310
|
+
class CngxPanelToggle {
|
|
2311
|
+
trigger = inject(CngxPanelTrigger, { host: true });
|
|
2312
|
+
direction = injectDirection();
|
|
2313
|
+
/**
|
|
2314
|
+
* Whether the target shows the panel right now. Read it from a projected
|
|
2315
|
+
* glyph through `#toggle="cngxPanelToggle"`.
|
|
2316
|
+
*/
|
|
2317
|
+
expanded = this.trigger.expanded;
|
|
2318
|
+
/**
|
|
2319
|
+
* Whether the target presents the panel as a modal over-drawer right now
|
|
2320
|
+
* (`mode="over"` with a blocking modality). The default glyph draws menu
|
|
2321
|
+
* bars and a cross then; a projected glyph can follow the same switch.
|
|
2322
|
+
*/
|
|
2323
|
+
modalOverlay = computed(() => {
|
|
2324
|
+
const target = this.trigger.target();
|
|
2325
|
+
const mode = target?.mode?.() ?? 'inline';
|
|
2326
|
+
return mode === 'over' && (target?.modal?.() ?? false);
|
|
2327
|
+
}, ...(ngDevMode ? [{ debugName: "modalOverlay" }] : /* istanbul ignore next */ []));
|
|
2328
|
+
/**
|
|
2329
|
+
* Whether a panel glyph drawn for a left panel must be flipped: the panel
|
|
2330
|
+
* sits on the right (`right`, `end` in LTR, `start` in RTL). Always
|
|
2331
|
+
* `false` while {@link modalOverlay} holds.
|
|
2332
|
+
*/
|
|
2333
|
+
mirrored = computed(() => {
|
|
2334
|
+
if (this.modalOverlay()) {
|
|
2335
|
+
return false;
|
|
2336
|
+
}
|
|
2337
|
+
const side = this.trigger.target()?.side?.() ?? 'start';
|
|
2338
|
+
const rtl = this.direction() === 'rtl';
|
|
2339
|
+
switch (side) {
|
|
2340
|
+
case 'right':
|
|
2341
|
+
return true;
|
|
2342
|
+
case 'start':
|
|
2343
|
+
return rtl;
|
|
2344
|
+
case 'end':
|
|
2345
|
+
return !rtl;
|
|
2346
|
+
default:
|
|
2347
|
+
return false;
|
|
2348
|
+
}
|
|
2349
|
+
}, ...(ngDevMode ? [{ debugName: "mirrored" }] : /* istanbul ignore next */ []));
|
|
2350
|
+
/** @internal - the default glyph for the current presentation and state. */
|
|
2351
|
+
icon = computed(() => {
|
|
2352
|
+
const expanded = this.expanded();
|
|
2353
|
+
if (this.modalOverlay()) {
|
|
2354
|
+
return expanded ? CNGX_ICON_X : CNGX_ICON_MENU;
|
|
2355
|
+
}
|
|
2356
|
+
return expanded ? CNGX_ICON_PANEL_CLOSE : CNGX_ICON_PANEL_OPEN;
|
|
2357
|
+
}, ...(ngDevMode ? [{ debugName: "icon" }] : /* istanbul ignore next */ []));
|
|
2358
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxPanelToggle, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
2359
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.2.4", type: CngxPanelToggle, isStandalone: true, selector: "button[cngxPanelToggle]", host: { classAttribute: "cngx-button cngx-icon-button cngx-panel-toggle" }, providers: [provideButtonHost('cngxPanelToggle', { defaultVariant: 'ghost', iconOnly: true })], exportAs: ["cngxPanelToggle"], hostDirectives: [{ directive: CngxPanelTrigger, inputs: ["cngxPanelTrigger", "cngxPanelToggle", "action", "action", "label", "label"] }, { directive: i2$1.CngxButtonBrain, inputs: ["variant", "variant", "tone", "tone", "size", "size", "disabled", "disabled", "disabledReason", "disabledReason", "cngxDescribedBy", "cngxDescribedBy", "type", "type"] }], ngImport: i0, template: `
|
|
2360
|
+
<span class="cngx-button__label cngx-icon-button__glyph" aria-hidden="true">
|
|
2361
|
+
<ng-content>
|
|
2362
|
+
<svg
|
|
2363
|
+
class="cngx-panel-toggle__icon"
|
|
2364
|
+
[class.cngx-panel-toggle__icon--mirrored]="mirrored()"
|
|
2365
|
+
[cngxIconSvg]="icon()"
|
|
2366
|
+
></svg>
|
|
2367
|
+
</ng-content>
|
|
2368
|
+
</span>
|
|
2369
|
+
<cngx-button-adornment />
|
|
2370
|
+
`, isInline: true, styles: ["@layer cngx.components{@scope(.cngx-panel-toggle){.cngx-panel-toggle__icon--mirrored{transform:scaleX(-1)}}}\n"], dependencies: [{ kind: "component", type: CngxIconSvg, selector: "svg[cngxIconSvg]", inputs: ["cngxIconSvg"] }, { kind: "component", type: CngxButtonAdornment, selector: "cngx-button-adornment" }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
2371
|
+
}
|
|
2372
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxPanelToggle, decorators: [{
|
|
2373
|
+
type: Component,
|
|
2374
|
+
args: [{ selector: 'button[cngxPanelToggle]', standalone: true, exportAs: 'cngxPanelToggle', imports: [CngxIconSvg, CngxButtonAdornment], changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, hostDirectives: [
|
|
2375
|
+
{
|
|
2376
|
+
directive: CngxPanelTrigger,
|
|
2377
|
+
inputs: ['cngxPanelTrigger: cngxPanelToggle', 'action', 'label'],
|
|
2378
|
+
},
|
|
2379
|
+
{
|
|
2380
|
+
directive: CngxButtonBrain,
|
|
2381
|
+
inputs: ['variant', 'tone', 'size', 'disabled', 'disabledReason', 'cngxDescribedBy', 'type'],
|
|
2382
|
+
},
|
|
2383
|
+
], providers: [provideButtonHost('cngxPanelToggle', { defaultVariant: 'ghost', iconOnly: true })], host: { class: 'cngx-button cngx-icon-button cngx-panel-toggle' }, template: `
|
|
2384
|
+
<span class="cngx-button__label cngx-icon-button__glyph" aria-hidden="true">
|
|
2385
|
+
<ng-content>
|
|
2386
|
+
<svg
|
|
2387
|
+
class="cngx-panel-toggle__icon"
|
|
2388
|
+
[class.cngx-panel-toggle__icon--mirrored]="mirrored()"
|
|
2389
|
+
[cngxIconSvg]="icon()"
|
|
2390
|
+
></svg>
|
|
2391
|
+
</ng-content>
|
|
2392
|
+
</span>
|
|
2393
|
+
<cngx-button-adornment />
|
|
2394
|
+
`, styles: ["@layer cngx.components{@scope(.cngx-panel-toggle){.cngx-panel-toggle__icon--mirrored{transform:scaleX(-1)}}}\n"] }]
|
|
2395
|
+
}] });
|
|
2396
|
+
|
|
2397
|
+
/**
|
|
2398
|
+
* Optional DI fallback for `CngxResizable`'s `min` / `max` / `step` input
|
|
2399
|
+
* defaults. Resolution is `bound input -> injected default -> literal`
|
|
2400
|
+
* (120 / 600 / 16). A hostDirective input default cannot be overridden by the
|
|
2401
|
+
* host that composes it, so this token is the layered extension point a
|
|
2402
|
+
* resizable organism uses to set app-wide bounds. `optional`, so standalone
|
|
2403
|
+
* `[cngxResizable]` stays byte-identical when the token is absent.
|
|
2404
|
+
*
|
|
2405
|
+
* @relatedTo CngxResizable
|
|
2406
|
+
* @since 0.3.0
|
|
2407
|
+
*/
|
|
2408
|
+
const CNGX_RESIZABLE_DEFAULTS = new InjectionToken('CNGX_RESIZABLE_DEFAULTS');
|
|
2409
|
+
/**
|
|
2410
|
+
* A resize handle for a side panel: the WAI-ARIA window-splitter pattern on
|
|
2411
|
+
* the handle element.
|
|
2412
|
+
*
|
|
2413
|
+
* The handle owns no layout. It reads and writes `size` (px) through a
|
|
2414
|
+
* two-way binding; the consumer applies the size to the panel (an inline
|
|
2415
|
+
* size or a custom property). Pointer drag runs with pointer capture and
|
|
2416
|
+
* writes at most once per animation frame; the handle sets
|
|
2417
|
+
* `touch-action: none`, so a touch drag resizes instead of panning the page.
|
|
2418
|
+
* The keyboard path makes the handle operable without a pointer (WCAG
|
|
2419
|
+
* 2.1.1): Arrow Left / Right move the handle by `step`, Home / End jump to
|
|
2420
|
+
* `min` / `max`. Modified keys pass through.
|
|
2421
|
+
*
|
|
2422
|
+
* `edge` names the panel edge the handle sits on: `inline-end` for a panel at
|
|
2423
|
+
* the start of the row (the handle grows the panel toward the end),
|
|
2424
|
+
* `inline-start` for a panel at the end. Under `dir="rtl"` the physical
|
|
2425
|
+
* directions flip with the writing direction.
|
|
2426
|
+
*
|
|
2427
|
+
* ARIA lives in the `computed()` graph: `role="separator"`,
|
|
2428
|
+
* `aria-orientation="vertical"`, `aria-valuenow` / `-min` / `-max`,
|
|
2429
|
+
* `aria-valuetext` and `aria-label` (copy from `CNGX_LAYOUT_I18N` unless the
|
|
2430
|
+
* `label` / `valueText` inputs are bound).
|
|
2431
|
+
* The pattern also refers the handle to the resized panel through
|
|
2432
|
+
* `aria-controls`; the handle does not know the panel, so set it on the host
|
|
2433
|
+
* (`aria-controls="filters"`) next to the panel's `id`. The handle never binds
|
|
2434
|
+
* it, so a static attribute stays.
|
|
2435
|
+
*
|
|
2436
|
+
* `min`, `max` and `step` fall back to `CNGX_RESIZABLE_DEFAULTS`, then to
|
|
2437
|
+
* 120 / 600 / 16.
|
|
1107
2438
|
*
|
|
1108
|
-
*
|
|
1109
|
-
*
|
|
1110
|
-
*
|
|
1111
|
-
*
|
|
2439
|
+
* ```html
|
|
2440
|
+
* <aside id="side" [style.inline-size.px]="width()">…</aside>
|
|
2441
|
+
* <div cngxResizable [(size)]="width" [min]="200" [max]="480" aria-controls="side"></div>
|
|
2442
|
+
* ```
|
|
2443
|
+
*
|
|
2444
|
+
* @wcag AA
|
|
2445
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/resizable/resizable.directive.ts
|
|
2446
|
+
* @since 0.3.0
|
|
2447
|
+
* @relatedTo CngxSidebar, CngxDrawerPanel, CNGX_LAYOUT_I18N
|
|
2448
|
+
* <example-url>/#/common/layout/resizable/side-panel</example-url>
|
|
2449
|
+
* @axis level atom
|
|
1112
2450
|
*/
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
2451
|
+
class CngxResizable {
|
|
2452
|
+
/**
|
|
2453
|
+
* Optional app-wide bounds. Declared first so the input initialisers below
|
|
2454
|
+
* can source their fallback from it. Absent by default - standalone
|
|
2455
|
+
* `[cngxResizable]` then keeps the 120 / 600 / 16 literals.
|
|
2456
|
+
*/
|
|
2457
|
+
defaults = inject(CNGX_RESIZABLE_DEFAULTS, { optional: true });
|
|
2458
|
+
/** Size of the resized panel in px. Two-way: `[(size)]="width"`. */
|
|
2459
|
+
size = model.required(...(ngDevMode ? [{ debugName: "size" }] : /* istanbul ignore next */ []));
|
|
2460
|
+
/** Smallest size in px a drag or key can reach. */
|
|
2461
|
+
min = input(this.defaults?.min ?? 120, ...(ngDevMode ? [{ debugName: "min" }] : /* istanbul ignore next */ []));
|
|
2462
|
+
/** Largest size in px a drag or key can reach. */
|
|
2463
|
+
max = input(this.defaults?.max ?? 600, ...(ngDevMode ? [{ debugName: "max" }] : /* istanbul ignore next */ []));
|
|
2464
|
+
/** The panel edge the handle sits on; sets the drag and arrow-key direction. */
|
|
2465
|
+
edge = input('inline-end', ...(ngDevMode ? [{ debugName: "edge" }] : /* istanbul ignore next */ []));
|
|
2466
|
+
/** Size change in px per arrow-key press. */
|
|
2467
|
+
step = input(this.defaults?.step ?? 16, ...(ngDevMode ? [{ debugName: "step" }] : /* istanbul ignore next */ []));
|
|
2468
|
+
/** Accessible name of the handle. Falls back to `CNGX_LAYOUT_I18N.resizeHandle`. */
|
|
2469
|
+
label = input(undefined, ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
|
|
2470
|
+
/**
|
|
2471
|
+
* `aria-valuetext` for a px size. Falls back to
|
|
2472
|
+
* `CNGX_LAYOUT_I18N.resizeValueText`.
|
|
2473
|
+
*/
|
|
2474
|
+
valueText = input(undefined, ...(ngDevMode ? [{ debugName: "valueText" }] : /* istanbul ignore next */ []));
|
|
2475
|
+
doc = inject(DOCUMENT);
|
|
2476
|
+
direction = injectDirection();
|
|
2477
|
+
i18n = injectLayoutI18n();
|
|
2478
|
+
resizingState = signal(false, ...(ngDevMode ? [{ debugName: "resizingState" }] : /* istanbul ignore next */ []));
|
|
2479
|
+
dragAbort = null;
|
|
2480
|
+
/** Whether a pointer drag is in progress. */
|
|
2481
|
+
resizing = this.resizingState.asReadonly();
|
|
2482
|
+
valueNow = computed(() => Math.round(this.clamped(this.size())), ...(ngDevMode ? [{ debugName: "valueNow" }] : /* istanbul ignore next */ []));
|
|
2483
|
+
resolvedLabel = computed(() => this.label() ?? this.i18n().resizeHandle, ...(ngDevMode ? [{ debugName: "resolvedLabel" }] : /* istanbul ignore next */ []));
|
|
2484
|
+
resolvedValueText = computed(() => {
|
|
2485
|
+
const format = this.valueText() ?? this.i18n().resizeValueText;
|
|
2486
|
+
return format(this.valueNow());
|
|
2487
|
+
}, ...(ngDevMode ? [{ debugName: "resolvedValueText" }] : /* istanbul ignore next */ []));
|
|
2488
|
+
/** +1 when moving the handle physically right grows the panel, else -1. */
|
|
2489
|
+
growSign = computed(() => {
|
|
2490
|
+
const endIsRight = this.direction() !== 'rtl';
|
|
2491
|
+
const onRight = this.edge() === 'inline-end' ? endIsRight : !endIsRight;
|
|
2492
|
+
return onRight ? 1 : -1;
|
|
2493
|
+
}, ...(ngDevMode ? [{ debugName: "growSign" }] : /* istanbul ignore next */ []));
|
|
2494
|
+
constructor() {
|
|
2495
|
+
inject(DestroyRef).onDestroy(() => this.dragAbort?.abort());
|
|
1120
2496
|
}
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
return () => {
|
|
1124
|
-
if (released) {
|
|
2497
|
+
handleKeydown(event) {
|
|
2498
|
+
if (event.ctrlKey || event.altKey || event.metaKey || event.shiftKey) {
|
|
1125
2499
|
return;
|
|
1126
2500
|
}
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
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);
|
|
2501
|
+
const target = this.keyTarget(event.key);
|
|
2502
|
+
if (target === null) {
|
|
2503
|
+
return;
|
|
1135
2504
|
}
|
|
1136
|
-
|
|
1137
|
-
|
|
2505
|
+
event.preventDefault();
|
|
2506
|
+
this.size.set(Math.round(this.clamped(target)));
|
|
2507
|
+
}
|
|
2508
|
+
handlePointerDown(event) {
|
|
2509
|
+
if (event.button !== 0) {
|
|
2510
|
+
return;
|
|
1138
2511
|
}
|
|
1139
|
-
|
|
2512
|
+
event.preventDefault();
|
|
2513
|
+
const handle = event.currentTarget;
|
|
2514
|
+
handle.setPointerCapture?.(event.pointerId);
|
|
2515
|
+
this.dragAbort?.abort();
|
|
2516
|
+
const controller = new AbortController();
|
|
2517
|
+
this.dragAbort = controller;
|
|
2518
|
+
this.resizingState.set(true);
|
|
2519
|
+
const startX = event.clientX;
|
|
2520
|
+
const startSize = this.size();
|
|
2521
|
+
const sign = this.growSign();
|
|
2522
|
+
const view = this.doc.defaultView;
|
|
2523
|
+
let pending = startSize;
|
|
2524
|
+
let frame = 0;
|
|
2525
|
+
// Destroying the handle mid-drag aborts the controller; the queued
|
|
2526
|
+
// frame must not write the size of a gone handle.
|
|
2527
|
+
controller.signal.addEventListener('abort', () => {
|
|
2528
|
+
if (frame) {
|
|
2529
|
+
view?.cancelAnimationFrame(frame);
|
|
2530
|
+
frame = 0;
|
|
2531
|
+
}
|
|
2532
|
+
});
|
|
2533
|
+
const flush = () => {
|
|
2534
|
+
frame = 0;
|
|
2535
|
+
this.size.set(pending);
|
|
2536
|
+
};
|
|
2537
|
+
const onMove = (ev) => {
|
|
2538
|
+
pending = Math.round(this.clamped(startSize + (ev.clientX - startX) * sign));
|
|
2539
|
+
if (!frame) {
|
|
2540
|
+
frame = view?.requestAnimationFrame(flush) ?? 0;
|
|
2541
|
+
}
|
|
2542
|
+
};
|
|
2543
|
+
const onEnd = () => {
|
|
2544
|
+
if (frame) {
|
|
2545
|
+
view?.cancelAnimationFrame(frame);
|
|
2546
|
+
}
|
|
2547
|
+
flush();
|
|
2548
|
+
this.resizingState.set(false);
|
|
2549
|
+
controller.abort();
|
|
2550
|
+
if (this.dragAbort === controller) {
|
|
2551
|
+
this.dragAbort = null;
|
|
2552
|
+
}
|
|
2553
|
+
};
|
|
2554
|
+
const options = { signal: controller.signal };
|
|
2555
|
+
this.doc.addEventListener('pointermove', onMove, options);
|
|
2556
|
+
this.doc.addEventListener('pointerup', onEnd, options);
|
|
2557
|
+
this.doc.addEventListener('pointercancel', onEnd, options);
|
|
2558
|
+
}
|
|
2559
|
+
keyTarget(key) {
|
|
2560
|
+
const current = this.size();
|
|
2561
|
+
const step = this.step() * this.growSign();
|
|
2562
|
+
switch (key) {
|
|
2563
|
+
case 'ArrowRight':
|
|
2564
|
+
return current + step;
|
|
2565
|
+
case 'ArrowLeft':
|
|
2566
|
+
return current - step;
|
|
2567
|
+
case 'Home':
|
|
2568
|
+
return this.min();
|
|
2569
|
+
case 'End':
|
|
2570
|
+
return this.max();
|
|
2571
|
+
default:
|
|
2572
|
+
return null;
|
|
2573
|
+
}
|
|
2574
|
+
}
|
|
2575
|
+
clamped(value) {
|
|
2576
|
+
return clamp(value, this.min(), this.max());
|
|
2577
|
+
}
|
|
2578
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxResizable, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
2579
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxResizable, isStandalone: true, selector: "[cngxResizable]", inputs: { size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: true, transformFunction: null }, min: { classPropertyName: "min", publicName: "min", isSignal: true, isRequired: false, transformFunction: null }, max: { classPropertyName: "max", publicName: "max", isSignal: true, isRequired: false, transformFunction: null }, edge: { classPropertyName: "edge", publicName: "edge", isSignal: true, isRequired: false, transformFunction: null }, step: { classPropertyName: "step", publicName: "step", isSignal: true, isRequired: false, transformFunction: null }, label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, valueText: { classPropertyName: "valueText", publicName: "valueText", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { size: "sizeChange" }, host: { attributes: { "role": "separator", "tabindex": "0", "aria-orientation": "vertical" }, listeners: { "keydown": "handleKeydown($event)", "pointerdown": "handlePointerDown($event)" }, properties: { "attr.aria-valuenow": "valueNow()", "attr.aria-valuemin": "min()", "attr.aria-valuemax": "max()", "attr.aria-valuetext": "resolvedValueText()", "attr.aria-label": "resolvedLabel()", "class.cngx-resizable--resizing": "resizing()" }, styleAttribute: "touch-action: none" }, exportAs: ["cngxResizable"], ngImport: i0 });
|
|
1140
2580
|
}
|
|
2581
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxResizable, decorators: [{
|
|
2582
|
+
type: Directive,
|
|
2583
|
+
args: [{
|
|
2584
|
+
selector: '[cngxResizable]',
|
|
2585
|
+
exportAs: 'cngxResizable',
|
|
2586
|
+
standalone: true,
|
|
2587
|
+
host: {
|
|
2588
|
+
role: 'separator',
|
|
2589
|
+
tabindex: '0',
|
|
2590
|
+
'aria-orientation': 'vertical',
|
|
2591
|
+
style: 'touch-action: none',
|
|
2592
|
+
'[attr.aria-valuenow]': 'valueNow()',
|
|
2593
|
+
'[attr.aria-valuemin]': 'min()',
|
|
2594
|
+
'[attr.aria-valuemax]': 'max()',
|
|
2595
|
+
'[attr.aria-valuetext]': 'resolvedValueText()',
|
|
2596
|
+
'[attr.aria-label]': 'resolvedLabel()',
|
|
2597
|
+
'[class.cngx-resizable--resizing]': 'resizing()',
|
|
2598
|
+
'(keydown)': 'handleKeydown($event)',
|
|
2599
|
+
'(pointerdown)': 'handlePointerDown($event)',
|
|
2600
|
+
},
|
|
2601
|
+
}]
|
|
2602
|
+
}], ctorParameters: () => [], propDecorators: { size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: true }] }, { type: i0.Output, args: ["sizeChange"] }], min: [{ type: i0.Input, args: [{ isSignal: true, alias: "min", required: false }] }], max: [{ type: i0.Input, args: [{ isSignal: true, alias: "max", required: false }] }], edge: [{ type: i0.Input, args: [{ isSignal: true, alias: "edge", required: false }] }], step: [{ type: i0.Input, args: [{ isSignal: true, alias: "step", required: false }] }], label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], valueText: [{ type: i0.Input, args: [{ isSignal: true, alias: "valueText", required: false }] }] } });
|
|
1141
2603
|
|
|
1142
2604
|
/**
|
|
1143
|
-
* Prevents scrolling on the document
|
|
2605
|
+
* Prevents scrolling on the document, or on a given scroll container, when
|
|
2606
|
+
* enabled.
|
|
1144
2607
|
*
|
|
1145
|
-
* Sets `overflow: hidden` and `scrollbar-gutter: stable` on
|
|
2608
|
+
* Sets `overflow: hidden` and `scrollbar-gutter: stable` on the target
|
|
2609
|
+
* (`<html>` unless `[cngxScrollLockTarget]` names another element) to
|
|
1146
2610
|
* prevent layout shift when the scrollbar disappears. Restores original
|
|
1147
|
-
* values when all lock instances are released.
|
|
2611
|
+
* values when all lock instances on that target are released.
|
|
1148
2612
|
*
|
|
1149
|
-
* Multiple instances are ref-counted - the original styles are
|
|
1150
|
-
* restored when the last lock is released.
|
|
2613
|
+
* Multiple instances are ref-counted per target - the original styles are
|
|
2614
|
+
* only restored when the last lock on that element is released.
|
|
1151
2615
|
*
|
|
1152
2616
|
* ### With a drawer
|
|
1153
2617
|
* ```html
|
|
@@ -1161,34 +2625,46 @@ function createScrollLock(html) {
|
|
|
1161
2625
|
* <div [cngxScrollLock]="isModalOpen()">…</div>
|
|
1162
2626
|
* ```
|
|
1163
2627
|
*
|
|
1164
|
-
*
|
|
1165
|
-
*
|
|
2628
|
+
* ### Inside a scroll container
|
|
2629
|
+
* ```html
|
|
2630
|
+
* <section #pane class="pane">
|
|
2631
|
+
* <aside [cngxScrollLock]="open()" [cngxScrollLockTarget]="pane">…</aside>
|
|
2632
|
+
* </section>
|
|
2633
|
+
* ```
|
|
2634
|
+
*
|
|
1166
2635
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/scroll/scroll-lock.directive.ts
|
|
1167
|
-
* @since 0.
|
|
2636
|
+
* @since 0.3.0
|
|
1168
2637
|
* @relatedTo CngxDrawer, CngxBackdrop
|
|
1169
|
-
* <example-url
|
|
2638
|
+
* <example-url>/#/common/layout/scroll-lock/toggle</example-url>
|
|
2639
|
+
* @axis level atom
|
|
1170
2640
|
*/
|
|
1171
2641
|
class CngxScrollLock {
|
|
1172
2642
|
/** Whether scroll lock is active. */
|
|
1173
2643
|
enabled = input(false, { ...(ngDevMode ? { debugName: "enabled" } : /* istanbul ignore next */ {}), alias: 'cngxScrollLock' });
|
|
2644
|
+
/**
|
|
2645
|
+
* The scrolling element to lock. Defaults to the document root
|
|
2646
|
+
* (`document.documentElement`). Changing it while locked moves the lock.
|
|
2647
|
+
*/
|
|
2648
|
+
target = input(undefined, { ...(ngDevMode ? { debugName: "target" } : /* istanbul ignore next */ {}), alias: 'cngxScrollLockTarget' });
|
|
1174
2649
|
constructor() {
|
|
1175
|
-
const
|
|
2650
|
+
const root = inject(DOCUMENT).documentElement;
|
|
2651
|
+
let locked = null;
|
|
1176
2652
|
let release = null;
|
|
1177
2653
|
effect(() => {
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
else if (!this.enabled() && release) {
|
|
1182
|
-
release();
|
|
1183
|
-
release = null;
|
|
2654
|
+
const wanted = this.enabled() ? (this.target() ?? root) : null;
|
|
2655
|
+
if (wanted === locked) {
|
|
2656
|
+
return;
|
|
1184
2657
|
}
|
|
2658
|
+
release?.();
|
|
2659
|
+
release = wanted ? createScrollLock(wanted) : null;
|
|
2660
|
+
locked = wanted;
|
|
1185
2661
|
});
|
|
1186
2662
|
inject(DestroyRef).onDestroy(() => {
|
|
1187
2663
|
release?.();
|
|
1188
2664
|
});
|
|
1189
2665
|
}
|
|
1190
2666
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxScrollLock, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1191
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxScrollLock, isStandalone: true, selector: "[cngxScrollLock]", inputs: { enabled: { classPropertyName: "enabled", publicName: "cngxScrollLock", isSignal: true, isRequired: false, transformFunction: null } }, exportAs: ["cngxScrollLock"], ngImport: i0 });
|
|
2667
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxScrollLock, isStandalone: true, selector: "[cngxScrollLock]", inputs: { enabled: { classPropertyName: "enabled", publicName: "cngxScrollLock", isSignal: true, isRequired: false, transformFunction: null }, target: { classPropertyName: "target", publicName: "cngxScrollLockTarget", isSignal: true, isRequired: false, transformFunction: null } }, exportAs: ["cngxScrollLock"], ngImport: i0 });
|
|
1192
2668
|
}
|
|
1193
2669
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxScrollLock, decorators: [{
|
|
1194
2670
|
type: Directive,
|
|
@@ -1197,7 +2673,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1197
2673
|
exportAs: 'cngxScrollLock',
|
|
1198
2674
|
standalone: true,
|
|
1199
2675
|
}]
|
|
1200
|
-
}], ctorParameters: () => [], propDecorators: { enabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxScrollLock", required: false }] }] } });
|
|
2676
|
+
}], ctorParameters: () => [], propDecorators: { enabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxScrollLock", required: false }] }], target: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxScrollLockTarget", required: false }] }] } });
|
|
1201
2677
|
|
|
1202
2678
|
/** Distances up to this many px count as "at the edge" (sub-pixel and zoom rounding). */
|
|
1203
2679
|
const EDGE_TOLERANCE = 1;
|
|
@@ -1213,19 +2689,32 @@ function sameEdges(a, b) {
|
|
|
1213
2689
|
a.inlineStart === b.inlineStart &&
|
|
1214
2690
|
a.inlineEnd === b.inlineEnd);
|
|
1215
2691
|
}
|
|
2692
|
+
/** `vertical-*` and `sideways-*` both lay the block axis out horizontally. */
|
|
2693
|
+
function isVerticalWritingMode(writingMode) {
|
|
2694
|
+
return writingMode.startsWith('vertical-') || writingMode.startsWith('sideways-');
|
|
2695
|
+
}
|
|
1216
2696
|
/**
|
|
1217
2697
|
* One read of the six scroll metrics. RTL `scrollLeft` runs over `[-max, 0]`
|
|
1218
2698
|
* in every evergreen engine and LTR over `[0, max]`, so its magnitude is the
|
|
1219
2699
|
* distance from the inline-start edge in both directions - no direction lookup
|
|
1220
|
-
*
|
|
2700
|
+
* in the scroll path. A vertical writing mode swaps the axes: the block axis
|
|
2701
|
+
* runs on `scrollLeft` (negative under `vertical-rl`, whose block-start is the
|
|
2702
|
+
* right edge) and the inline axis on `scrollTop`.
|
|
1221
2703
|
*/
|
|
1222
|
-
function readEdges(element) {
|
|
1223
|
-
const
|
|
2704
|
+
function readEdges(element, vertical) {
|
|
2705
|
+
const horizontalOffset = Math.abs(element.scrollLeft);
|
|
2706
|
+
const verticalOffset = Math.abs(element.scrollTop);
|
|
2707
|
+
const horizontalMax = element.scrollWidth - element.clientWidth;
|
|
2708
|
+
const verticalMax = element.scrollHeight - element.clientHeight;
|
|
2709
|
+
const blockOffset = vertical ? horizontalOffset : verticalOffset;
|
|
2710
|
+
const blockMax = vertical ? horizontalMax : verticalMax;
|
|
2711
|
+
const inlineOffset = vertical ? verticalOffset : horizontalOffset;
|
|
2712
|
+
const inlineMax = vertical ? verticalMax : horizontalMax;
|
|
1224
2713
|
return {
|
|
1225
|
-
blockStart:
|
|
1226
|
-
blockEnd:
|
|
2714
|
+
blockStart: blockOffset > EDGE_TOLERANCE,
|
|
2715
|
+
blockEnd: blockMax - blockOffset > EDGE_TOLERANCE,
|
|
1227
2716
|
inlineStart: inlineOffset > EDGE_TOLERANCE,
|
|
1228
|
-
inlineEnd:
|
|
2717
|
+
inlineEnd: inlineMax - inlineOffset > EDGE_TOLERANCE,
|
|
1229
2718
|
};
|
|
1230
2719
|
}
|
|
1231
2720
|
/**
|
|
@@ -1252,7 +2741,7 @@ function readEdges(element) {
|
|
|
1252
2741
|
* inject(DestroyRef),
|
|
1253
2742
|
* inject(DOCUMENT).defaultView,
|
|
1254
2743
|
* );
|
|
1255
|
-
* const
|
|
2744
|
+
* const showStartShadow = edges.canScrollBlockStart;
|
|
1256
2745
|
* ```
|
|
1257
2746
|
*
|
|
1258
2747
|
* @param element The scrollport to read.
|
|
@@ -1260,9 +2749,8 @@ function readEdges(element) {
|
|
|
1260
2749
|
* every observer and cancels a pending frame.
|
|
1261
2750
|
* @param host The window-like object to read the observer and frame APIs from.
|
|
1262
2751
|
* @returns The four per-edge signals.
|
|
1263
|
-
* @category common/layout
|
|
1264
2752
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/scroll/scroll-edges-core.ts
|
|
1265
|
-
* @since 0.
|
|
2753
|
+
* @since 0.3.0
|
|
1266
2754
|
* @relatedTo CngxScrollEdges, observeResize
|
|
1267
2755
|
*/
|
|
1268
2756
|
function createScrollEdges(element, destroyRef, host) {
|
|
@@ -1279,12 +2767,16 @@ function createScrollEdges(element, destroyRef, host) {
|
|
|
1279
2767
|
let destroyed = false;
|
|
1280
2768
|
let framePending = false;
|
|
1281
2769
|
let frameHandle = 0;
|
|
2770
|
+
// Resolved on the first frame read, not here: a getComputedStyle at
|
|
2771
|
+
// construction would force a style recalc before the first render.
|
|
2772
|
+
let vertical = null;
|
|
1282
2773
|
const read = () => {
|
|
1283
2774
|
framePending = false;
|
|
1284
2775
|
if (destroyed) {
|
|
1285
2776
|
return;
|
|
1286
2777
|
}
|
|
1287
|
-
|
|
2778
|
+
vertical ??= isVerticalWritingMode(host.getComputedStyle?.(element).writingMode ?? '');
|
|
2779
|
+
edges.set(readEdges(element, vertical));
|
|
1288
2780
|
};
|
|
1289
2781
|
const schedule = () => {
|
|
1290
2782
|
if (destroyed || framePending) {
|
|
@@ -1350,14 +2842,17 @@ function createScrollEdges(element, destroyRef, host) {
|
|
|
1350
2842
|
* the scroll metrics per animation frame; the attributes are present (empty
|
|
1351
2843
|
* value) while true and absent otherwise:
|
|
1352
2844
|
*
|
|
1353
|
-
* - `data-scroll-block-start` / `canScrollBlockStart()` -
|
|
1354
|
-
* - `data-scroll-block-end` / `canScrollBlockEnd()` -
|
|
2845
|
+
* - `data-scroll-block-start` / `canScrollBlockStart()` - hidden toward block start
|
|
2846
|
+
* - `data-scroll-block-end` / `canScrollBlockEnd()` - hidden toward block end
|
|
1355
2847
|
* - `data-scroll-inline-start` / `canScrollInlineStart()` - hidden toward inline start
|
|
1356
2848
|
* - `data-scroll-inline-end` / `canScrollInlineEnd()` - hidden toward inline end
|
|
1357
2849
|
*
|
|
1358
|
-
*
|
|
1359
|
-
*
|
|
1360
|
-
*
|
|
2850
|
+
* In a horizontal writing mode block start / end are the top and bottom
|
|
2851
|
+
* edges; under a `vertical-*` or `sideways-*` writing mode they are the
|
|
2852
|
+
* horizontal ones. Inline start / end follow the writing direction: in
|
|
2853
|
+
* `dir="rtl"` the start edge is on the right. The direction is derived from
|
|
2854
|
+
* the scroll offset itself, so a `dir="rtl"` subtree inside an LTR page
|
|
2855
|
+
* reports correctly.
|
|
1361
2856
|
*
|
|
1362
2857
|
* The directive paints nothing. The four attributes (present only while true)
|
|
1363
2858
|
* are its public, stable contract; every visual belongs to the consumer CSS,
|
|
@@ -1397,23 +2892,22 @@ function createScrollEdges(element, destroyRef, host) {
|
|
|
1397
2892
|
* `@container scroll-state(scrollable: block-start)` and its siblings, so the
|
|
1398
2893
|
* CSS can swap to native scroll-state queries once they are Baseline.
|
|
1399
2894
|
*
|
|
1400
|
-
* @category common/layout
|
|
1401
|
-
* @docsKind primary
|
|
1402
2895
|
* @wcag AA
|
|
1403
2896
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/scroll/scroll-edges.directive.ts
|
|
1404
|
-
* @since 0.
|
|
2897
|
+
* @since 0.3.0
|
|
1405
2898
|
* @relatedTo CngxStickyHeader, CngxScrollSpy, createScrollEdges
|
|
1406
|
-
* <example-url
|
|
2899
|
+
* <example-url>/#/common/layout/scroll-edges/edge-shadows</example-url>
|
|
2900
|
+
* @axis level atom
|
|
1407
2901
|
*/
|
|
1408
2902
|
class CngxScrollEdges {
|
|
1409
2903
|
edges = createScrollEdges(inject(ElementRef).nativeElement, inject(DestroyRef), isPlatformBrowser(inject(PLATFORM_ID)) ? inject(DOCUMENT).defaultView : null);
|
|
1410
|
-
/** Content is hidden toward the block-start edge (
|
|
2904
|
+
/** Content is hidden toward the block-start edge (top in horizontal writing modes). */
|
|
1411
2905
|
canScrollBlockStart = this.edges.canScrollBlockStart;
|
|
1412
|
-
/** Content is hidden toward the block-end edge (
|
|
2906
|
+
/** Content is hidden toward the block-end edge (bottom in horizontal writing modes). */
|
|
1413
2907
|
canScrollBlockEnd = this.edges.canScrollBlockEnd;
|
|
1414
|
-
/** Content is hidden toward the inline-start edge (left in LTR, right in RTL). */
|
|
2908
|
+
/** Content is hidden toward the inline-start edge (left in LTR, right in RTL, horizontally). */
|
|
1415
2909
|
canScrollInlineStart = this.edges.canScrollInlineStart;
|
|
1416
|
-
/** Content is hidden toward the inline-end edge (right in LTR, left in RTL). */
|
|
2910
|
+
/** Content is hidden toward the inline-end edge (right in LTR, left in RTL, horizontally). */
|
|
1417
2911
|
canScrollInlineEnd = this.edges.canScrollInlineEnd;
|
|
1418
2912
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxScrollEdges, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1419
2913
|
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 });
|
|
@@ -1433,6 +2927,331 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1433
2927
|
}]
|
|
1434
2928
|
}] });
|
|
1435
2929
|
|
|
2930
|
+
/** @internal See {@link CngxSidebarDriver}. */
|
|
2931
|
+
const CNGX_SIDEBAR_DRIVER = new InjectionToken('CngxSidebarDriver');
|
|
2932
|
+
/**
|
|
2933
|
+
* The brain of a persistent side region: a sidebar that stays in the layout
|
|
2934
|
+
* and reserves inline space, unlike a drawer, which is transient.
|
|
2935
|
+
*
|
|
2936
|
+
* `collapsed` (two-way) switches between the expanded size and the
|
|
2937
|
+
* collapsed rest, `collapsedAs` picks the rest: a `rail` stays operable at
|
|
2938
|
+
* `--cngx-sidebar-rail-size`, `hidden` reserves nothing and becomes `inert`
|
|
2939
|
+
* + `aria-hidden`. A collapsed sidebar can **peek**: it shows at full size
|
|
2940
|
+
* over the content without reflowing it (the reserved space stays at the
|
|
2941
|
+
* rest size). Peek comes from the pointer resting on the host
|
|
2942
|
+
* (`CngxHoverIntent`, gated by `expandOnHover`) or from `peek()`, and ends
|
|
2943
|
+
* on Escape (wherever focus is, so a hover peek over the page is
|
|
2944
|
+
* dismissible without moving focus, WCAG 1.4.13), on a press outside the
|
|
2945
|
+
* host (a press on the trigger whose `aria-controls` names the sidebar is
|
|
2946
|
+
* left to the trigger), when focus leaves the host, or when the pointer
|
|
2947
|
+
* leaves the host after resting on it. A `peek()` from a trigger outside the
|
|
2948
|
+
* host therefore stays until one of these happens, even if the pointer never
|
|
2949
|
+
* enters.
|
|
2950
|
+
* `pin()` turns a peek into the expanded state.
|
|
2951
|
+
*
|
|
2952
|
+
* `side` names the edge the sidebar sits on (`start`, default, or `end` for
|
|
2953
|
+
* an inspector after the content); a peek grows away from it.
|
|
2954
|
+
*
|
|
2955
|
+
* Sizes are tokens with fallbacks: `--cngx-sidebar-size` (expanded, default
|
|
2956
|
+
* `16rem`) and `--cngx-sidebar-rail-size` (default `3.5rem`), plus
|
|
2957
|
+
* `--cngx-sidebar-peek-z-index`. The host renders `data-sidebar-state`
|
|
2958
|
+
* (`expanded | rail | hidden | peek`) and `data-sidebar-side` for skins.
|
|
2959
|
+
* The base skin is opt-in with the `cngx-sidebar` class (`cngx-sidebar.css`
|
|
2960
|
+
* in `@cngx/themes/cngx.css`): surface, border and peek shadow of the box,
|
|
2961
|
+
* nothing for its content.
|
|
2962
|
+
*
|
|
2963
|
+
* The sidebar is a `CngxPanelTarget` and provides `CNGX_PANEL_TARGET`: a
|
|
2964
|
+
* `[cngxPanelTrigger]="sidebar"` mirrors `expanded` and toggles `collapsed`;
|
|
2965
|
+
* `action="peek"` peeks. It knows no nav model; `[cngxNavRailed]` crops the
|
|
2966
|
+
* nav rows inside it on the rail and adds the rail tooltip and group flyout.
|
|
2967
|
+
*
|
|
2968
|
+
* ```html
|
|
2969
|
+
* <button type="button" [cngxPanelTrigger]="sidebar"></button>
|
|
2970
|
+
* <div style="display: flex">
|
|
2971
|
+
* <nav cngxSidebar #sidebar="cngxSidebar" [(collapsed)]="collapsed" [role]="null">…</nav>
|
|
2972
|
+
* <main>…</main>
|
|
2973
|
+
* </div>
|
|
2974
|
+
* ```
|
|
2975
|
+
*
|
|
2976
|
+
* @wcag AA
|
|
2977
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/sidebar/sidebar.directive.ts
|
|
2978
|
+
* @since 0.3.0
|
|
2979
|
+
* @relatedTo CngxPanelTrigger, CngxDrawer, CngxHoverIntent, CngxResizable
|
|
2980
|
+
* <example-url>/#/common/layout/sidebar/clipped-below-header</example-url>
|
|
2981
|
+
* <example-url>/#/common/layout/sidebar/collapsible-rail</example-url>
|
|
2982
|
+
* <example-url>/#/common/layout/sidebar/inset-app-sidebar</example-url>
|
|
2983
|
+
* <example-url>/#/common/layout/sidebar/projected-toggle-glyph</example-url>
|
|
2984
|
+
* @axis level molecule
|
|
2985
|
+
*/
|
|
2986
|
+
class CngxSidebar {
|
|
2987
|
+
/** Whether the sidebar rests collapsed. Two-way: `[(collapsed)]`. */
|
|
2988
|
+
collapsed = model(false, ...(ngDevMode ? [{ debugName: "collapsed" }] : /* istanbul ignore next */ []));
|
|
2989
|
+
/** How a collapsed sidebar rests: an operable `rail` or `hidden`. */
|
|
2990
|
+
collapsedAs = input('rail', ...(ngDevMode ? [{ debugName: "collapsedAs" }] : /* istanbul ignore next */ []));
|
|
2991
|
+
/**
|
|
2992
|
+
* {@link CngxPanelTarget}: the edge the sidebar sits on, in the writing
|
|
2993
|
+
* direction. A peek grows away from it.
|
|
2994
|
+
*/
|
|
2995
|
+
side = input('start', ...(ngDevMode ? [{ debugName: "side" }] : /* istanbul ignore next */ []));
|
|
2996
|
+
/** Whether the pointer resting on a collapsed sidebar peeks it. */
|
|
2997
|
+
expandOnHover = input(true, ...(ngDevMode ? [{ debugName: "expandOnHover" }] : /* istanbul ignore next */ []));
|
|
2998
|
+
/**
|
|
2999
|
+
* ms the pointer rests on a collapsed sidebar before it peeks. Unbound,
|
|
3000
|
+
* `CNGX_HOVER_INTENT_DEFAULTS` applies, then 120.
|
|
3001
|
+
*/
|
|
3002
|
+
expandDelay = input(undefined, ...(ngDevMode ? [{ debugName: "expandDelay" }] : /* istanbul ignore next */ []));
|
|
3003
|
+
/**
|
|
3004
|
+
* ms after the pointer leaves before a hover peek ends. Unbound,
|
|
3005
|
+
* `CNGX_HOVER_INTENT_DEFAULTS` applies, then 0.
|
|
3006
|
+
*/
|
|
3007
|
+
collapseDelay = input(undefined, ...(ngDevMode ? [{ debugName: "collapseDelay" }] : /* istanbul ignore next */ []));
|
|
3008
|
+
/** @internal Drives the composed `CngxHoverIntent`. */
|
|
3009
|
+
hoverEnterDelay = this.expandDelay;
|
|
3010
|
+
/** @internal Drives the composed `CngxHoverIntent`. */
|
|
3011
|
+
hoverLeaveDelay = this.collapseDelay;
|
|
3012
|
+
/**
|
|
3013
|
+
* Landmark role. Defaults to `complementary`; pass `navigation` for a nav
|
|
3014
|
+
* sidebar, or `null` on a `<nav>` / `<aside>` host to keep its implicit role.
|
|
3015
|
+
*/
|
|
3016
|
+
roleInput = input(undefined, { ...(ngDevMode ? { debugName: "roleInput" } : /* istanbul ignore next */ {}), alias: 'role' });
|
|
3017
|
+
/**
|
|
3018
|
+
* Accessible name of the region. Falls back to `CNGX_LAYOUT_I18N.sidebarRegion`
|
|
3019
|
+
* while the role is `complementary`.
|
|
3020
|
+
*/
|
|
3021
|
+
labelInput = input(undefined, { ...(ngDevMode ? { debugName: "labelInput" } : /* istanbul ignore next */ {}), alias: 'label' });
|
|
3022
|
+
hover = inject(CngxHoverIntent, { self: true });
|
|
3023
|
+
injector = inject(Injector);
|
|
3024
|
+
resolvedDriver = undefined;
|
|
3025
|
+
driver() {
|
|
3026
|
+
if (this.resolvedDriver === undefined) {
|
|
3027
|
+
this.resolvedDriver = this.injector.get(CNGX_SIDEBAR_DRIVER, null, { self: true });
|
|
3028
|
+
}
|
|
3029
|
+
return this.resolvedDriver;
|
|
3030
|
+
}
|
|
3031
|
+
// What the sidebar renders: the driver wins over the inputs.
|
|
3032
|
+
restCollapsed = computed(() => this.driver()?.sidebarCollapsed() ?? this.collapsed(), ...(ngDevMode ? [{ debugName: "restCollapsed" }] : /* istanbul ignore next */ []));
|
|
3033
|
+
restAs = computed(() => this.driver()?.sidebarCollapsedAs?.() ?? this.collapsedAs(), ...(ngDevMode ? [{ debugName: "restAs" }] : /* istanbul ignore next */ []));
|
|
3034
|
+
host = inject(ElementRef).nativeElement;
|
|
3035
|
+
doc = inject(DOCUMENT);
|
|
3036
|
+
i18n = injectLayoutI18n();
|
|
3037
|
+
// An explicit peek ends when the pointer leaves the host after resting on
|
|
3038
|
+
// it; a pointer that never entered (a peek from an outside trigger) keeps
|
|
3039
|
+
// it until a press outside, Escape or focus leaving.
|
|
3040
|
+
peekState = linkedSignal({ ...(ngDevMode ? { debugName: "peekState" } : /* istanbul ignore next */ {}), source: this.hover.active,
|
|
3041
|
+
computation: (active, previous) => active && (previous?.value ?? false) });
|
|
3042
|
+
// Escape ends a hover peek while the pointer still rests on the host; the
|
|
3043
|
+
// next hover edge lifts the suppression.
|
|
3044
|
+
hoverSuppressed = linkedSignal({ ...(ngDevMode ? { debugName: "hoverSuppressed" } : /* istanbul ignore next */ {}), source: this.hover.active,
|
|
3045
|
+
computation: () => false });
|
|
3046
|
+
/**
|
|
3047
|
+
* The host `id` (a static `id` attribute, else a generated one); the
|
|
3048
|
+
* trigger's `aria-controls`.
|
|
3049
|
+
*/
|
|
3050
|
+
id = signal(inject(new HostAttributeToken('id'), { optional: true }) ?? nextUid('cngx-sidebar')).asReadonly();
|
|
3051
|
+
/** {@link CngxPanelTarget}: a sidebar reserves inline space, it is never an overlay. */
|
|
3052
|
+
mode = signal('inline').asReadonly();
|
|
3053
|
+
/** Whether a collapsed sidebar currently shows at full size over the content. */
|
|
3054
|
+
peeked = computed(() => {
|
|
3055
|
+
if (!this.restCollapsed()) {
|
|
3056
|
+
return false;
|
|
3057
|
+
}
|
|
3058
|
+
if (this.peekState() || (this.driver()?.sidebarPeek?.() ?? false)) {
|
|
3059
|
+
return true;
|
|
3060
|
+
}
|
|
3061
|
+
return this.expandOnHover() && this.hover.active() && !this.hoverSuppressed();
|
|
3062
|
+
}, ...(ngDevMode ? [{ debugName: "peeked" }] : /* istanbul ignore next */ []));
|
|
3063
|
+
/** Whether the sidebar shows at full size: expanded, or collapsed and peeked. */
|
|
3064
|
+
expanded = computed(() => !this.restCollapsed() || this.peeked(), ...(ngDevMode ? [{ debugName: "expanded" }] : /* istanbul ignore next */ []));
|
|
3065
|
+
/** The rendered state: `expanded`, `peek`, or the collapsed rest. */
|
|
3066
|
+
state = computed(() => {
|
|
3067
|
+
if (!this.restCollapsed()) {
|
|
3068
|
+
return 'expanded';
|
|
3069
|
+
}
|
|
3070
|
+
return this.peeked() ? 'peek' : this.restAs();
|
|
3071
|
+
}, ...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
|
|
3072
|
+
/**
|
|
3073
|
+
* The rendered landmark role: the bound `role` (`null` keeps the host's
|
|
3074
|
+
* implicit role), else the composer's, else `complementary`.
|
|
3075
|
+
*/
|
|
3076
|
+
role = computed(() => {
|
|
3077
|
+
const bound = this.roleInput();
|
|
3078
|
+
if (bound !== undefined) {
|
|
3079
|
+
return bound;
|
|
3080
|
+
}
|
|
3081
|
+
return this.driver()?.sidebarRole?.() ?? 'complementary';
|
|
3082
|
+
}, ...(ngDevMode ? [{ debugName: "role" }] : /* istanbul ignore next */ []));
|
|
3083
|
+
concealed = computed(() => this.state() === 'hidden' || (this.driver()?.sidebarConcealed?.() ?? false), ...(ngDevMode ? [{ debugName: "concealed" }] : /* istanbul ignore next */ []));
|
|
3084
|
+
/**
|
|
3085
|
+
* {@link CngxPanelTarget}: the region's resolved accessible name, the bound
|
|
3086
|
+
* `label`, else `CNGX_LAYOUT_I18N.sidebarRegion` while the role is
|
|
3087
|
+
* `complementary` (a `navigation` landmark announces its role already). An
|
|
3088
|
+
* icon-only trigger takes it as its name.
|
|
3089
|
+
*/
|
|
3090
|
+
label = computed(() => {
|
|
3091
|
+
// A composer that names the region itself wins outright; its own
|
|
3092
|
+
// cascade already resolved input, config and copy.
|
|
3093
|
+
const driven = this.driver()?.sidebarLabel;
|
|
3094
|
+
if (driven) {
|
|
3095
|
+
return driven();
|
|
3096
|
+
}
|
|
3097
|
+
const fallback = this.role() === 'complementary' ? this.i18n().sidebarRegion : undefined;
|
|
3098
|
+
return this.labelInput() ?? fallback;
|
|
3099
|
+
}, ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
|
|
3100
|
+
inlineSize = computed(() => {
|
|
3101
|
+
switch (this.state()) {
|
|
3102
|
+
case 'rail':
|
|
3103
|
+
return 'var(--cngx-sidebar-rail-size, 3.5rem)';
|
|
3104
|
+
case 'hidden':
|
|
3105
|
+
return '0px';
|
|
3106
|
+
default:
|
|
3107
|
+
return 'var(--cngx-sidebar-size, 16rem)';
|
|
3108
|
+
}
|
|
3109
|
+
}, ...(ngDevMode ? [{ debugName: "inlineSize" }] : /* istanbul ignore next */ []));
|
|
3110
|
+
// A peek keeps the rest footprint: a negative margin on the edge facing
|
|
3111
|
+
// the content cancels the growth, so the content does not reflow.
|
|
3112
|
+
peekOffset = computed(() => {
|
|
3113
|
+
if (!this.peeked()) {
|
|
3114
|
+
return null;
|
|
3115
|
+
}
|
|
3116
|
+
const rest = this.restAs() === 'rail' ? 'var(--cngx-sidebar-rail-size, 3.5rem)' : '0px';
|
|
3117
|
+
return `calc(${rest} - var(--cngx-sidebar-size, 16rem))`;
|
|
3118
|
+
}, ...(ngDevMode ? [{ debugName: "peekOffset" }] : /* istanbul ignore next */ []));
|
|
3119
|
+
constructor() {
|
|
3120
|
+
// The hidden rest moves focus out first: aria-hidden on an element that
|
|
3121
|
+
// holds focus is blocked (and warned about) by the browser, and inert
|
|
3122
|
+
// alone would only drop focus on the next rendering step. A composer that
|
|
3123
|
+
// conceals through the driver owns that move, since it may keep focus
|
|
3124
|
+
// inside by changing its own state in the same pass.
|
|
3125
|
+
effect(() => {
|
|
3126
|
+
if (this.state() !== 'hidden') {
|
|
3127
|
+
return;
|
|
3128
|
+
}
|
|
3129
|
+
untracked(() => {
|
|
3130
|
+
const active = this.doc.activeElement;
|
|
3131
|
+
if (active instanceof HTMLElement && this.host.contains(active)) {
|
|
3132
|
+
active.blur();
|
|
3133
|
+
}
|
|
3134
|
+
});
|
|
3135
|
+
});
|
|
3136
|
+
// A peek is content shown on hover: Escape must dismiss it even while
|
|
3137
|
+
// focus sits elsewhere on the page. Listen on the document only while
|
|
3138
|
+
// peeked; an Escape inside the host is the host binding's.
|
|
3139
|
+
effect((onCleanup) => {
|
|
3140
|
+
if (!this.peeked()) {
|
|
3141
|
+
return;
|
|
3142
|
+
}
|
|
3143
|
+
const onKeydown = (event) => {
|
|
3144
|
+
if (event.key !== 'Escape') {
|
|
3145
|
+
return;
|
|
3146
|
+
}
|
|
3147
|
+
if (event.target instanceof Node && this.host.contains(event.target)) {
|
|
3148
|
+
return;
|
|
3149
|
+
}
|
|
3150
|
+
this.unpeek();
|
|
3151
|
+
};
|
|
3152
|
+
// A press on the page beside the peek ends it; the trigger that names
|
|
3153
|
+
// the sidebar in aria-controls handles its own press.
|
|
3154
|
+
const onPointerDown = (event) => {
|
|
3155
|
+
const target = event.target;
|
|
3156
|
+
if (!(target instanceof Element) || this.host.contains(target)) {
|
|
3157
|
+
return;
|
|
3158
|
+
}
|
|
3159
|
+
if (this.isController(target)) {
|
|
3160
|
+
return;
|
|
3161
|
+
}
|
|
3162
|
+
this.unpeek();
|
|
3163
|
+
};
|
|
3164
|
+
this.doc.addEventListener('keydown', onKeydown);
|
|
3165
|
+
this.doc.addEventListener('pointerdown', onPointerDown, true);
|
|
3166
|
+
onCleanup(() => {
|
|
3167
|
+
this.doc.removeEventListener('keydown', onKeydown);
|
|
3168
|
+
this.doc.removeEventListener('pointerdown', onPointerDown, true);
|
|
3169
|
+
});
|
|
3170
|
+
});
|
|
3171
|
+
}
|
|
3172
|
+
/** Collapses an expanded sidebar, expands a collapsed one. Ends a peek. */
|
|
3173
|
+
toggle() {
|
|
3174
|
+
this.peekState.set(false);
|
|
3175
|
+
this.collapsed.update((collapsed) => !collapsed);
|
|
3176
|
+
}
|
|
3177
|
+
/** Shows a collapsed sidebar at full size over the content until dismissed. */
|
|
3178
|
+
peek() {
|
|
3179
|
+
if (this.restCollapsed()) {
|
|
3180
|
+
this.peekState.set(true);
|
|
3181
|
+
}
|
|
3182
|
+
}
|
|
3183
|
+
/** Ends a peek without changing `collapsed`. */
|
|
3184
|
+
unpeek() {
|
|
3185
|
+
this.peekState.set(false);
|
|
3186
|
+
if (this.hover.active()) {
|
|
3187
|
+
this.hoverSuppressed.set(true);
|
|
3188
|
+
}
|
|
3189
|
+
}
|
|
3190
|
+
/** Keeps the sidebar expanded: `collapsed = false`, any peek ends. */
|
|
3191
|
+
pin() {
|
|
3192
|
+
this.peekState.set(false);
|
|
3193
|
+
this.collapsed.set(false);
|
|
3194
|
+
}
|
|
3195
|
+
isController(target) {
|
|
3196
|
+
const controller = target.closest('[aria-controls]');
|
|
3197
|
+
const ids = controller?.getAttribute('aria-controls')?.split(/\s+/) ?? [];
|
|
3198
|
+
return ids.includes(this.id());
|
|
3199
|
+
}
|
|
3200
|
+
// One Escape dismisses one layer: an open popover inside the host or an
|
|
3201
|
+
// inner surface goes first. A driven peek is the composer's to dismiss, so
|
|
3202
|
+
// its Escape stays unclaimed for the composer's own surface.
|
|
3203
|
+
handleEscape(event) {
|
|
3204
|
+
if (!this.peeked() || escapeOwnedAbove(event, this.host)) {
|
|
3205
|
+
return;
|
|
3206
|
+
}
|
|
3207
|
+
if (this.driver()?.sidebarPeek?.()) {
|
|
3208
|
+
return;
|
|
3209
|
+
}
|
|
3210
|
+
claimEscape(event);
|
|
3211
|
+
this.unpeek();
|
|
3212
|
+
}
|
|
3213
|
+
handleFocusOut(event) {
|
|
3214
|
+
const next = event.relatedTarget;
|
|
3215
|
+
if (next instanceof Node && this.host.contains(next)) {
|
|
3216
|
+
return;
|
|
3217
|
+
}
|
|
3218
|
+
this.peekState.set(false);
|
|
3219
|
+
}
|
|
3220
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxSidebar, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
3221
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxSidebar, isStandalone: true, selector: "[cngxSidebar]", inputs: { collapsed: { classPropertyName: "collapsed", publicName: "collapsed", isSignal: true, isRequired: false, transformFunction: null }, collapsedAs: { classPropertyName: "collapsedAs", publicName: "collapsedAs", isSignal: true, isRequired: false, transformFunction: null }, side: { classPropertyName: "side", publicName: "side", isSignal: true, isRequired: false, transformFunction: null }, expandOnHover: { classPropertyName: "expandOnHover", publicName: "expandOnHover", isSignal: true, isRequired: false, transformFunction: null }, expandDelay: { classPropertyName: "expandDelay", publicName: "expandDelay", isSignal: true, isRequired: false, transformFunction: null }, collapseDelay: { classPropertyName: "collapseDelay", publicName: "collapseDelay", isSignal: true, isRequired: false, transformFunction: null }, roleInput: { classPropertyName: "roleInput", publicName: "role", isSignal: true, isRequired: false, transformFunction: null }, labelInput: { classPropertyName: "labelInput", publicName: "label", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { collapsed: "collapsedChange" }, host: { listeners: { "keydown.escape": "handleEscape($event)", "focusout": "handleFocusOut($event)" }, properties: { "attr.id": "id()", "attr.role": "role()", "attr.aria-label": "label() ?? null", "attr.inert": "concealed() ? '' : null", "attr.aria-hidden": "concealed() ? 'true' : null", "attr.data-sidebar-state": "state()", "attr.data-sidebar-side": "side()", "style.inline-size": "inlineSize()", "style.margin-inline-end": "side() === 'start' ? peekOffset() : null", "style.margin-inline-start": "side() === 'end' ? peekOffset() : null", "style.z-index": "peeked() ? 'var(--cngx-sidebar-peek-z-index, 2)' : null" } }, providers: [
|
|
3222
|
+
{ provide: CNGX_PANEL_TARGET, useExisting: CngxSidebar },
|
|
3223
|
+
{ provide: CNGX_HOVER_INTENT_DRIVER, useExisting: CngxSidebar },
|
|
3224
|
+
], exportAs: ["cngxSidebar"], hostDirectives: [{ directive: i2.CngxHoverIntent }], ngImport: i0 });
|
|
3225
|
+
}
|
|
3226
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxSidebar, decorators: [{
|
|
3227
|
+
type: Directive,
|
|
3228
|
+
args: [{
|
|
3229
|
+
selector: '[cngxSidebar]',
|
|
3230
|
+
exportAs: 'cngxSidebar',
|
|
3231
|
+
standalone: true,
|
|
3232
|
+
hostDirectives: [CngxHoverIntent],
|
|
3233
|
+
providers: [
|
|
3234
|
+
{ provide: CNGX_PANEL_TARGET, useExisting: CngxSidebar },
|
|
3235
|
+
{ provide: CNGX_HOVER_INTENT_DRIVER, useExisting: CngxSidebar },
|
|
3236
|
+
],
|
|
3237
|
+
host: {
|
|
3238
|
+
'[attr.id]': 'id()',
|
|
3239
|
+
'[attr.role]': 'role()',
|
|
3240
|
+
'[attr.aria-label]': 'label() ?? null',
|
|
3241
|
+
'[attr.inert]': "concealed() ? '' : null",
|
|
3242
|
+
'[attr.aria-hidden]': "concealed() ? 'true' : null",
|
|
3243
|
+
'[attr.data-sidebar-state]': 'state()',
|
|
3244
|
+
'[attr.data-sidebar-side]': 'side()',
|
|
3245
|
+
'[style.inline-size]': 'inlineSize()',
|
|
3246
|
+
'[style.margin-inline-end]': "side() === 'start' ? peekOffset() : null",
|
|
3247
|
+
'[style.margin-inline-start]': "side() === 'end' ? peekOffset() : null",
|
|
3248
|
+
'[style.z-index]': "peeked() ? 'var(--cngx-sidebar-peek-z-index, 2)' : null",
|
|
3249
|
+
'(keydown.escape)': 'handleEscape($event)',
|
|
3250
|
+
'(focusout)': 'handleFocusOut($event)',
|
|
3251
|
+
},
|
|
3252
|
+
}]
|
|
3253
|
+
}], ctorParameters: () => [], propDecorators: { collapsed: [{ type: i0.Input, args: [{ isSignal: true, alias: "collapsed", required: false }] }, { type: i0.Output, args: ["collapsedChange"] }], collapsedAs: [{ type: i0.Input, args: [{ isSignal: true, alias: "collapsedAs", required: false }] }], side: [{ type: i0.Input, args: [{ isSignal: true, alias: "side", required: false }] }], expandOnHover: [{ type: i0.Input, args: [{ isSignal: true, alias: "expandOnHover", required: false }] }], expandDelay: [{ type: i0.Input, args: [{ isSignal: true, alias: "expandDelay", required: false }] }], collapseDelay: [{ type: i0.Input, args: [{ isSignal: true, alias: "collapseDelay", required: false }] }], roleInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "role", required: false }] }], labelInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }] } });
|
|
3254
|
+
|
|
1436
3255
|
/**
|
|
1437
3256
|
* Headless skeleton loading placeholder.
|
|
1438
3257
|
*
|
|
@@ -1440,7 +3259,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1440
3259
|
* No template -- the consumer renders the skeleton UI.
|
|
1441
3260
|
*
|
|
1442
3261
|
* Exposes an `indices()` signal for `@for` rendering of repeated skeleton elements.
|
|
1443
|
-
* Respects
|
|
3262
|
+
* Respects reduced motion, the in-app `CNGX_MOTION` pick or the OS query
|
|
3263
|
+
* (disables shimmer animation class).
|
|
1444
3264
|
*
|
|
1445
3265
|
* ### Basic loading placeholder
|
|
1446
3266
|
* ```html
|
|
@@ -1473,14 +3293,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1473
3293
|
* </div>
|
|
1474
3294
|
* ```
|
|
1475
3295
|
*
|
|
1476
|
-
* @category common/layout
|
|
1477
|
-
* @docsKind primary
|
|
1478
3296
|
* @wcag AA
|
|
1479
3297
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/text/skeleton.directive.ts
|
|
1480
|
-
* @since 0.
|
|
3298
|
+
* @since 0.3.0
|
|
1481
3299
|
* @relatedTo CngxTruncate, CngxExpandableText, CngxHighlight
|
|
1482
|
-
* <example-url
|
|
1483
|
-
*
|
|
3300
|
+
* <example-url>/#/common/layout/skeleton/basic-skeleton</example-url>
|
|
3301
|
+
* @axis level atom
|
|
1484
3302
|
*/
|
|
1485
3303
|
class CngxSkeleton {
|
|
1486
3304
|
/** Controls the loading state. */
|
|
@@ -1489,18 +3307,15 @@ class CngxSkeleton {
|
|
|
1489
3307
|
shimmer = input(true, ...(ngDevMode ? [{ debugName: "shimmer" }] : /* istanbul ignore next */ []));
|
|
1490
3308
|
/** Repeat count - exposed via the `indices()` signal for `@for` rendering. */
|
|
1491
3309
|
count = input(1, ...(ngDevMode ? [{ debugName: "count" }] : /* istanbul ignore next */ []));
|
|
1492
|
-
|
|
1493
|
-
constructor() {
|
|
1494
|
-
this.prefersReducedMotion = createMediaQuerySignal('(prefers-reduced-motion: reduce)', inject(DestroyRef), inject(DOCUMENT).defaultView);
|
|
1495
|
-
}
|
|
3310
|
+
motion = injectEffectiveMotion();
|
|
1496
3311
|
/** Whether the skeleton is in loading state. Mirrors the `cngxSkeleton` input. */
|
|
1497
3312
|
loading = computed(() => this.skeleton(), ...(ngDevMode ? [{ debugName: "loading" }] : /* istanbul ignore next */ []));
|
|
1498
3313
|
/** Array of indices for `@for` rendering of repeated skeleton elements. */
|
|
1499
3314
|
indices = computed(() => Array.from({ length: this.count() }, (_, i) => i), ...(ngDevMode ? [{ debugName: "indices" }] : /* istanbul ignore next */ []));
|
|
1500
3315
|
/** @internal - shimmer class condition. */
|
|
1501
|
-
showShimmer = computed(() => this.loading() && this.shimmer() &&
|
|
3316
|
+
showShimmer = computed(() => this.loading() && this.shimmer() && this.motion() !== 'reduced', ...(ngDevMode ? [{ debugName: "showShimmer" }] : /* istanbul ignore next */ []));
|
|
1502
3317
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxSkeleton, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
1503
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxSkeleton, isStandalone: true, selector: "[cngxSkeleton]", inputs: { skeleton: { classPropertyName: "skeleton", publicName: "cngxSkeleton", isSignal: true, isRequired: false, transformFunction: null }, shimmer: { classPropertyName: "shimmer", publicName: "shimmer", isSignal: true, isRequired: false, transformFunction: null }, count: { classPropertyName: "count", publicName: "count", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "class.cngx-skeleton--loading": "loading()", "class.cngx-skeleton--shimmer": "showShimmer()", "attr.aria-busy": "loading() || null" }, classAttribute: "cngx-skeleton" }, exportAs: ["cngxSkeleton"], ngImport: i0 });
|
|
3318
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: CngxSkeleton, isStandalone: true, selector: "[cngxSkeleton]", inputs: { skeleton: { classPropertyName: "skeleton", publicName: "cngxSkeleton", isSignal: true, isRequired: false, transformFunction: null }, shimmer: { classPropertyName: "shimmer", publicName: "shimmer", isSignal: true, isRequired: false, transformFunction: null }, count: { classPropertyName: "count", publicName: "count", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "class.cngx-skeleton--loading": "loading()", "class.cngx-skeleton--shimmer": "showShimmer()", "attr.aria-busy": "loading() || null", "attr.data-cngx-busy": "loading() || null" }, classAttribute: "cngx-skeleton" }, exportAs: ["cngxSkeleton"], ngImport: i0 });
|
|
1504
3319
|
}
|
|
1505
3320
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: CngxSkeleton, decorators: [{
|
|
1506
3321
|
type: Directive,
|
|
@@ -1513,9 +3328,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1513
3328
|
'[class.cngx-skeleton--loading]': 'loading()',
|
|
1514
3329
|
'[class.cngx-skeleton--shimmer]': 'showShimmer()',
|
|
1515
3330
|
'[attr.aria-busy]': 'loading() || null',
|
|
3331
|
+
'[attr.data-cngx-busy]': 'loading() || null',
|
|
1516
3332
|
},
|
|
1517
3333
|
}]
|
|
1518
|
-
}],
|
|
3334
|
+
}], propDecorators: { skeleton: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxSkeleton", required: false }] }], shimmer: [{ type: i0.Input, args: [{ isSignal: true, alias: "shimmer", required: false }] }], count: [{ type: i0.Input, args: [{ isSignal: true, alias: "count", required: false }] }] } });
|
|
1519
3335
|
|
|
1520
3336
|
/**
|
|
1521
3337
|
* Infinite scroll trigger using `IntersectionObserver`.
|
|
@@ -1562,13 +3378,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1562
3378
|
* </div>
|
|
1563
3379
|
* ```
|
|
1564
3380
|
*
|
|
1565
|
-
* @category common/layout
|
|
1566
|
-
* @docsKind primary
|
|
1567
3381
|
* @wcag AA
|
|
1568
3382
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/scroll/infinite-scroll.directive.ts
|
|
1569
|
-
* @since 0.
|
|
3383
|
+
* @since 0.3.0
|
|
1570
3384
|
* @relatedTo CngxIntersectionObserver, CngxScrollSpy, CngxStickyHeader
|
|
1571
|
-
* <example-url
|
|
3385
|
+
* <example-url>/#/common/layout/infinite-scroll/scrollable-list</example-url>
|
|
3386
|
+
* @axis level atom
|
|
1572
3387
|
*/
|
|
1573
3388
|
class CngxInfiniteScroll {
|
|
1574
3389
|
/** IntersectionObserver threshold (0–1). */
|
|
@@ -1607,8 +3422,8 @@ class CngxInfiniteScroll {
|
|
|
1607
3422
|
}
|
|
1608
3423
|
const isLoading = () => this.loading();
|
|
1609
3424
|
const resolvedRoot = root ? this.doc.querySelector(root) : null;
|
|
1610
|
-
if (
|
|
1611
|
-
|
|
3425
|
+
if (typeof ngDevMode !== 'undefined' && ngDevMode && root && !resolvedRoot) {
|
|
3426
|
+
cngxDevWarn('CNGX1032', `[cngxInfiniteScroll] root selector "${root}" matched no element - ` +
|
|
1612
3427
|
'falling back to the viewport. A late-rendered root needs a re-bind of [root].');
|
|
1613
3428
|
}
|
|
1614
3429
|
const observer = new IntersectionObserver((entries) => {
|
|
@@ -1700,13 +3515,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1700
3515
|
* .cngx-sticky--active { box-shadow: 0 2px 4px rgba(0,0,0,.1); }
|
|
1701
3516
|
* ```
|
|
1702
3517
|
*
|
|
1703
|
-
* @category common/layout
|
|
1704
|
-
* @docsKind primary
|
|
1705
3518
|
* @wcag AA
|
|
1706
3519
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/scroll/sticky-header.directive.ts
|
|
1707
|
-
* @since 0.
|
|
3520
|
+
* @since 0.3.0
|
|
1708
3521
|
* @relatedTo CngxScrollSpy, CngxIntersectionObserver
|
|
1709
|
-
* <example-url
|
|
3522
|
+
* <example-url>/#/common/layout/sticky-header/sticky-header-with-shadow</example-url>
|
|
3523
|
+
* @axis level atom
|
|
1710
3524
|
*/
|
|
1711
3525
|
class CngxStickyHeader {
|
|
1712
3526
|
/** Intersection threshold - `0` triggers as soon as the sentinel leaves. */
|
|
@@ -1737,10 +3551,11 @@ class CngxStickyHeader {
|
|
|
1737
3551
|
// exactly what `afterNextRender` is for (no reactive-graph node, unlike a
|
|
1738
3552
|
// dep-less effect). The 1px tolerance absorbs sub-pixel layout and browser-zoom
|
|
1739
3553
|
// rounding: "cannot meaningfully scroll" instead of exact equality.
|
|
1740
|
-
if (
|
|
3554
|
+
if (typeof ngDevMode !== 'undefined' &&
|
|
3555
|
+
ngDevMode &&
|
|
1741
3556
|
scrollport &&
|
|
1742
3557
|
scrollport.scrollHeight - scrollport.clientHeight <= 1) {
|
|
1743
|
-
|
|
3558
|
+
cngxDevWarn('CNGX1034', '[cngxStickyHeader] resolves against a scroll container that cannot scroll ' +
|
|
1744
3559
|
'in the block axis (client height equals scroll height), so this header ' +
|
|
1745
3560
|
'will never pin. Give the scrollport a bounded block-size, or drop ' +
|
|
1746
3561
|
'cngxStickyHeader.', { host, scrollport });
|
|
@@ -1779,16 +3594,17 @@ class CngxStickyHeader {
|
|
|
1779
3594
|
/**
|
|
1780
3595
|
* The nearest ancestor that is a scroll container in the block axis - the scrollport
|
|
1781
3596
|
* `position: sticky` resolves against. Walks up from the host's parent to the first
|
|
1782
|
-
* ancestor whose computed `overflow-y` is
|
|
1783
|
-
* ancestor, i.e. the header sticks to the viewport.
|
|
1784
|
-
*
|
|
1785
|
-
*
|
|
3597
|
+
* ancestor whose computed `overflow-y` is `auto`, `scroll` or `hidden`; `null` means
|
|
3598
|
+
* no such ancestor, i.e. the header sticks to the viewport. `clip` clips without
|
|
3599
|
+
* creating a scroll container, so it is skipped. A used `overflow-x` of `auto`,
|
|
3600
|
+
* `scroll` or `hidden` coerces the computed `overflow-y` to `auto`, so this also
|
|
3601
|
+
* catches a horizontal scroll container (e.g. a data grid that scrolls sideways).
|
|
1786
3602
|
*/
|
|
1787
3603
|
resolveScrollParent(host) {
|
|
1788
3604
|
const view = this.doc.defaultView;
|
|
1789
3605
|
for (let node = host.parentElement; node; node = node.parentElement) {
|
|
1790
3606
|
const overflowY = view?.getComputedStyle(node).overflowY;
|
|
1791
|
-
if (overflowY
|
|
3607
|
+
if (overflowY === 'auto' || overflowY === 'scroll' || overflowY === 'hidden') {
|
|
1792
3608
|
return node;
|
|
1793
3609
|
}
|
|
1794
3610
|
}
|
|
@@ -1835,13 +3651,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1835
3651
|
* <section id="pricing">…</section>
|
|
1836
3652
|
* ```
|
|
1837
3653
|
*
|
|
1838
|
-
* @category common/layout
|
|
1839
|
-
* @docsKind primary
|
|
1840
3654
|
* @wcag AA
|
|
1841
3655
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/scroll/scroll-spy.directive.ts
|
|
1842
|
-
* @since 0.
|
|
3656
|
+
* @since 0.3.0
|
|
1843
3657
|
* @relatedTo CngxIntersectionObserver, CngxStickyHeader, CngxInfiniteScroll
|
|
1844
|
-
* <example-url
|
|
3658
|
+
* <example-url>/#/common/layout/scroll-spy/scroll-based-navigation</example-url>
|
|
3659
|
+
* @axis level atom
|
|
1845
3660
|
*/
|
|
1846
3661
|
class CngxScrollSpy {
|
|
1847
3662
|
/** IDs of the sections to observe. */
|
|
@@ -1893,17 +3708,17 @@ class CngxScrollSpy {
|
|
|
1893
3708
|
const elements = ids
|
|
1894
3709
|
.map((id) => this.doc.getElementById(id))
|
|
1895
3710
|
.filter((el) => el !== null);
|
|
1896
|
-
if (
|
|
3711
|
+
if (typeof ngDevMode !== 'undefined' && ngDevMode && elements.length < ids.length) {
|
|
1897
3712
|
const missing = ids.filter((id) => !this.doc.getElementById(id));
|
|
1898
|
-
|
|
3713
|
+
cngxDevWarn('CNGX1033', `[cngxScrollSpy] section id(s) not found: ${missing.join(', ')}. ` +
|
|
1899
3714
|
'Late-rendered sections are not observed - re-bind [cngxScrollSpy] once they exist.');
|
|
1900
3715
|
}
|
|
1901
3716
|
if (elements.length === 0) {
|
|
1902
3717
|
return undefined;
|
|
1903
3718
|
}
|
|
1904
3719
|
const resolvedRoot = rootSelector ? this.doc.querySelector(rootSelector) : null;
|
|
1905
|
-
if (
|
|
1906
|
-
|
|
3720
|
+
if (typeof ngDevMode !== 'undefined' && ngDevMode && rootSelector && !resolvedRoot) {
|
|
3721
|
+
cngxDevWarn('CNGX1032', `[cngxScrollSpy] root selector "${rootSelector}" matched no element - ` +
|
|
1907
3722
|
'falling back to the viewport. A late-rendered root needs a re-bind of [root].');
|
|
1908
3723
|
}
|
|
1909
3724
|
const observer = new IntersectionObserver((entries) => {
|
|
@@ -1954,14 +3769,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1954
3769
|
* </button> * }
|
|
1955
3770
|
* ```
|
|
1956
3771
|
*
|
|
1957
|
-
* @category common/layout
|
|
1958
|
-
* @docsKind primary
|
|
1959
3772
|
* @wcag AA
|
|
1960
3773
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/text/truncate.directive.ts
|
|
1961
|
-
* @since 0.
|
|
3774
|
+
* @since 0.3.0
|
|
1962
3775
|
* @relatedTo CngxExpandableText, CngxExpandableToggle, CngxHighlight
|
|
1963
|
-
* <example-url
|
|
1964
|
-
* <example-url
|
|
3776
|
+
* <example-url>/#/common/layout/truncate/short-text-no-toggle</example-url>
|
|
3777
|
+
* <example-url>/#/common/layout/truncate/truncated-text-with-toggle</example-url>
|
|
3778
|
+
* @axis level atom
|
|
1965
3779
|
*/
|
|
1966
3780
|
class CngxTruncate {
|
|
1967
3781
|
/** Maximum number of visible lines when collapsed. */
|
|
@@ -2069,14 +3883,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
2069
3883
|
* </p>
|
|
2070
3884
|
* ```
|
|
2071
3885
|
*
|
|
2072
|
-
* @category common/layout
|
|
2073
|
-
* @docsKind primary
|
|
2074
3886
|
* @wcag AA
|
|
2075
3887
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/text/highlight.directive.ts
|
|
2076
|
-
* @since 0.
|
|
3888
|
+
* @since 0.3.0
|
|
2077
3889
|
* @relatedTo CngxTruncate, CngxExpandableText
|
|
2078
|
-
* <example-url
|
|
2079
|
-
* <example-url
|
|
3890
|
+
* <example-url>/#/common/layout/highlight/live-search-highlighting</example-url>
|
|
3891
|
+
* <example-url>/#/common/layout/highlight/multiple-paragraphs</example-url>
|
|
3892
|
+
* @axis level atom
|
|
2080
3893
|
*/
|
|
2081
3894
|
class CngxHighlight {
|
|
2082
3895
|
/** The search term to highlight. Empty string clears all highlights. */
|
|
@@ -2194,86 +4007,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
2194
4007
|
}]
|
|
2195
4008
|
}], ctorParameters: () => [], propDecorators: { term: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxHighlight", required: false }] }], caseSensitive: [{ type: i0.Input, args: [{ isSignal: true, alias: "highlightCaseSensitive", required: false }] }] } });
|
|
2196
4009
|
|
|
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
|
-
|
|
2277
4010
|
/**
|
|
2278
4011
|
* Marks a custom toggle template inside `cngx-expandable-text`.
|
|
2279
4012
|
*
|
|
@@ -2288,9 +4021,8 @@ function injectLayoutI18n() {
|
|
|
2288
4021
|
* </cngx-expandable-text>
|
|
2289
4022
|
* ```
|
|
2290
4023
|
*
|
|
2291
|
-
* @category common/layout
|
|
2292
4024
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/text/expandable-text.ts
|
|
2293
|
-
* @since 0.
|
|
4025
|
+
* @since 0.3.0
|
|
2294
4026
|
* @relatedTo CngxExpandableText, CngxTruncate
|
|
2295
4027
|
*/
|
|
2296
4028
|
class CngxExpandableToggle {
|
|
@@ -2339,16 +4071,16 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
2339
4071
|
* </cngx-expandable-text>
|
|
2340
4072
|
* ```
|
|
2341
4073
|
*
|
|
2342
|
-
* @category common/layout
|
|
2343
|
-
* @docsKind primary
|
|
2344
4074
|
* @wcag AA
|
|
2345
4075
|
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/text/expandable-text.ts
|
|
2346
|
-
* @since 0.
|
|
4076
|
+
* @since 0.3.0
|
|
2347
4077
|
* @relatedTo CngxTruncate, CngxExpandableToggle, CngxHighlight
|
|
2348
4078
|
* @slot cngxExpandableToggle Replaces the show-more control; gets the current expanded state.
|
|
2349
|
-
* <example-url
|
|
2350
|
-
* <example-url
|
|
2351
|
-
* <example-url
|
|
4079
|
+
* <example-url>/#/common/layout/expandable-text/auto-toggle</example-url>
|
|
4080
|
+
* <example-url>/#/common/layout/expandable-text/custom-labels</example-url>
|
|
4081
|
+
* <example-url>/#/common/layout/expandable-text/custom-toggle-template</example-url>
|
|
4082
|
+
* <example-url>/#/common/layout/expandable-text/card-with-expandable-text</example-url>
|
|
4083
|
+
* @axis level molecule
|
|
2352
4084
|
*/
|
|
2353
4085
|
class CngxExpandableText {
|
|
2354
4086
|
i18n = injectLayoutI18n();
|
|
@@ -2444,12 +4176,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
2444
4176
|
}], propDecorators: { lines: [{ type: i0.Input, args: [{ isSignal: true, alias: "lines", required: false }] }], expanded: [{ type: i0.Input, args: [{ isSignal: true, alias: "expanded", required: false }] }, { type: i0.Output, args: ["expandedChange"] }], moreLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "moreLabel", required: false }] }], lessLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "lessLabel", required: false }] }], customToggle: [{ type: i0.ContentChild, args: [i0.forwardRef(() => CngxExpandableToggle), { isSignal: true }] }] } });
|
|
2445
4177
|
|
|
2446
4178
|
/**
|
|
2447
|
-
* @module
|
|
4179
|
+
* @module `@cngx/common/layout`
|
|
2448
4180
|
*/
|
|
2449
4181
|
|
|
2450
4182
|
/**
|
|
2451
4183
|
* Generated bundle index. Do not edit.
|
|
2452
4184
|
*/
|
|
2453
4185
|
|
|
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 };
|
|
4186
|
+
export { CNGX_CONTAINER_SIZE, CNGX_DRAWER_HOST, CNGX_DRAWER_SURFACE_DRIVER, CNGX_LAYOUT_I18N, CNGX_LAYOUT_LANGUAGE_EN, CNGX_PANEL_TARGET, CNGX_RESIZABLE_DEFAULTS, CNGX_SIDEBAR_DRIVER, CngxBackdrop, CngxContainer, CngxDrawer, CngxDrawerContent, CngxDrawerPanel, CngxDrawerSurface, CngxExpandableText, CngxExpandableToggle, CngxHighlight, CngxInfiniteScroll, CngxIntersectionObserver, CngxMediaQuery, CngxPanelToggle, CngxPanelTrigger, CngxResizable, CngxResizeObserver, CngxScrollEdges, CngxScrollLock, CngxScrollSpy, CngxSidebar, CngxSkeleton, CngxStickyHeader, CngxTruncate, createContainerSize, createPinnedScrollLock, createResizeSignal, createScrollEdges, createScrollLock, injectContainerSize, injectLayoutI18n, injectMediaQuery, injectQueryParamSync, observeResize, provideLayoutI18n, withLayoutI18nLabels };
|
|
2455
4187
|
//# sourceMappingURL=cngx-common-layout.mjs.map
|