@rcarls/rc-common 0.5.0 → 0.6.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/CHANGELOG.md +20 -0
- package/README.md +45 -4
- package/dist/rc-common.js +311 -175
- package/dist/rc-common.umd.cjs +9 -9
- package/dist/types/AnchorController.d.ts +48 -1
- package/dist/types/RovingTabIndexMixin.d.ts +1 -1
- package/dist/types/clickDelegate.d.ts +116 -0
- package/dist/types/index.d.ts +21 -20
- package/package.json +1 -1
- package/dist/types/DragGestureController.test.d.ts +0 -1
- package/dist/types/KeyboardInteractionDirective.test.d.ts +0 -1
- package/dist/types/KeyboardNavigationDirective.test.d.ts +0 -1
- package/dist/types/MouseMoveDirective.test.d.ts +0 -1
- package/dist/types/MutationObserverController.test.d.ts +0 -1
- package/dist/types/RafScheduler.test.d.ts +0 -1
- package/dist/types/ScrollObserverController.test.d.ts +0 -1
- package/dist/types/TypeaheadController.test.d.ts +0 -1
- package/dist/types/isFocusable.test.d.ts +0 -1
- package/dist/types/nativeChild.test.d.ts +0 -1
- package/dist/types/snapUtils.unit.test.d.ts +0 -1
|
@@ -37,9 +37,14 @@ export declare class AnchorController implements ReactiveController {
|
|
|
37
37
|
private readonly _uid;
|
|
38
38
|
private _styleEl;
|
|
39
39
|
private _adoptedSheet;
|
|
40
|
+
private _connected;
|
|
41
|
+
private _clampLoopActive;
|
|
42
|
+
private _clampFrame;
|
|
43
|
+
private _appliedDx;
|
|
44
|
+
private _appliedDy;
|
|
40
45
|
constructor(host: ReactiveControllerHost, options: AnchorOptions);
|
|
41
46
|
setOptions(next: Partial<AnchorOptions>): void;
|
|
42
|
-
/** Re-apply positioning
|
|
47
|
+
/** Re-apply positioning after the popup becomes visible or the anchor moves. */
|
|
43
48
|
update(): void;
|
|
44
49
|
hostConnected(): void;
|
|
45
50
|
hostDisconnected(): void;
|
|
@@ -47,9 +52,51 @@ export declare class AnchorController implements ReactiveController {
|
|
|
47
52
|
private _floating;
|
|
48
53
|
private _shadowHost;
|
|
49
54
|
private _applyAndPolyfill;
|
|
55
|
+
/**
|
|
56
|
+
* Checks viewport overflow on every frame while the floating element is
|
|
57
|
+
* visible. Anchor geometry can settle well after the popup opens, so the
|
|
58
|
+
* loop follows visibility rather than a fixed timeout. A hidden initial
|
|
59
|
+
* state stops immediately; consumers restart positioning after showing the
|
|
60
|
+
* popup by calling `update()`.
|
|
61
|
+
*/
|
|
62
|
+
private _scheduleClamp;
|
|
63
|
+
private _stopClampLoop;
|
|
64
|
+
/**
|
|
65
|
+
* Nudges the floating element back on-screen via `translate` if whatever
|
|
66
|
+
* positioned it (native or otherwise) still left it overflowing the
|
|
67
|
+
* viewport. `translate` is used rather than adjusting `left`/`top`/etc.
|
|
68
|
+
* directly because it's a pure visual offset on top of the existing
|
|
69
|
+
* positioning, independent of which mechanism produced it — no need to
|
|
70
|
+
* know or reconstruct the underlying `left`/`right`/`position-anchor`
|
|
71
|
+
* values to correct them. It's safe to apply even to a popover-promoted
|
|
72
|
+
* element with its own further-nested anchor-positioned descendants (e.g.
|
|
73
|
+
* a submenu): top-layer promotion means a nested popover isn't contained
|
|
74
|
+
* by this element's box for `position: fixed` purposes, so translating
|
|
75
|
+
* this one doesn't drag a nested popup along or break its own anchoring.
|
|
76
|
+
*
|
|
77
|
+
* `getBoundingClientRect()` reflects whatever `translate` the previous
|
|
78
|
+
* update applied, and computing the new correction directly
|
|
79
|
+
* off that rect would see the already-corrected (on-screen) position,
|
|
80
|
+
* clear the correction as unnecessary, then reapply it next frame once
|
|
81
|
+
* the underlying overflow reappears — an every-frame flicker confirmed
|
|
82
|
+
* by a real click landing on a mid-flicker frame in the browser test
|
|
83
|
+
* suite. `_appliedDx`/`_appliedDy` track the offset this method itself
|
|
84
|
+
* last applied so it can subtract it back out and compute against the
|
|
85
|
+
* element's natural, uncorrected position each time.
|
|
86
|
+
*/
|
|
87
|
+
private _clampToViewport;
|
|
50
88
|
private _applyPolyfillOrFallback;
|
|
51
89
|
private _apply;
|
|
52
90
|
private _injectStyles;
|
|
91
|
+
/**
|
|
92
|
+
* Hand-rolled positioning for browsers where neither native anchor
|
|
93
|
+
* positioning nor the polyfill is usable. Handles all four placement
|
|
94
|
+
* sides (not just top/bottom — a side flyout like a cascading submenu
|
|
95
|
+
* needs its primary axis to be horizontal, offsetting by the anchor's
|
|
96
|
+
* own width/height rather than always stacking below it), with the
|
|
97
|
+
* `-start`/`-end` suffix controlling cross-axis alignment and an
|
|
98
|
+
* unsuffixed placement centering on the cross axis.
|
|
99
|
+
*/
|
|
53
100
|
private _positionFallback;
|
|
54
101
|
private _cleanup;
|
|
55
102
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LitElement } from 'lit';
|
|
2
|
-
import { FocusableElement } from './isFocusable';
|
|
2
|
+
import { FocusableElement } from './isFocusable.js';
|
|
3
3
|
type Constructor<T = object> = new (...args: any[]) => T;
|
|
4
4
|
/**
|
|
5
5
|
* Ambient class declaration exposing the public + protected shape added by
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { ReactiveController, ReactiveControllerHost } from 'lit';
|
|
2
|
+
/**
|
|
3
|
+
* Descendants a click delegate treats as already self-sufficiently
|
|
4
|
+
* interactive. A click that lands on, or inside, one of these is left
|
|
5
|
+
* alone — the descendant already handles its own click (natively, or via
|
|
6
|
+
* its own listener), so forwarding it too would double-handle it.
|
|
7
|
+
*/
|
|
8
|
+
export declare const DEFAULT_INTERACTIVE_SELECTOR: string;
|
|
9
|
+
export interface InteractiveDescendantOptions {
|
|
10
|
+
/** Selector for descendants that already handle their own clicks. */
|
|
11
|
+
interactiveSelector?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* True when `event`'s composed path already passes through an interactive
|
|
15
|
+
* descendant of `host` before reaching `host` itself.
|
|
16
|
+
*
|
|
17
|
+
* Walking `composedPath()` (rather than `event.target`) is what makes this
|
|
18
|
+
* shadow-DOM-safe: a click inside a slotted control composes back through
|
|
19
|
+
* the light tree the same way regardless of which shadow boundaries it
|
|
20
|
+
* crosses, so this works whether `host` renders the descendant directly or
|
|
21
|
+
* receives it through a slot.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* host.addEventListener('click', (event) => {
|
|
26
|
+
* if (!isEventFromInteractiveDescendant(event, host)) {
|
|
27
|
+
* openDetails();
|
|
28
|
+
* }
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function isEventFromInteractiveDescendant(event: Event, host: HTMLElement, options?: InteractiveDescendantOptions): boolean;
|
|
33
|
+
export interface DelegateClickOptions extends InteractiveDescendantOptions {
|
|
34
|
+
/** Skip delegation entirely, e.g. while the host is disabled. */
|
|
35
|
+
disabled?: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Forwards `event` to `target` via a genuine `.click()` call — but only for
|
|
39
|
+
* a plain, primary-button click on `host` that hasn't already landed on one
|
|
40
|
+
* of its own interactive descendants. Returns whether it delegated.
|
|
41
|
+
*
|
|
42
|
+
* This is the "stretched link" / "block link" pattern's click-anywhere-in-
|
|
43
|
+
* the-container half, implemented at the JS layer rather than via a CSS
|
|
44
|
+
* `::after` overlay on the target itself. Reach for the CSS technique first
|
|
45
|
+
* where it's available — it keeps the container's enhancement layer
|
|
46
|
+
* entirely CSS (no JS dependency at all) and, for an anchor target,
|
|
47
|
+
* preserves modified clicks (the browser's own click lands on the real
|
|
48
|
+
* anchor). It doesn't fit every shadow-DOM host, though: an overlay
|
|
49
|
+
* anchored to a slotted element's own containing block can end up scoped to
|
|
50
|
+
* whatever shadow-internal wrapper establishes that block (not the host you
|
|
51
|
+
* meant to fill), and clipped by any `overflow` on an ancestor between the
|
|
52
|
+
* two — both true of `rc-list-item`'s content region, which needs its own
|
|
53
|
+
* `overflow: hidden` for label truncation. This function is for exactly
|
|
54
|
+
* that case: a host that can't offer a working CSS overlay for its slotted
|
|
55
|
+
* content.
|
|
56
|
+
*
|
|
57
|
+
* Two things it deliberately can never do, both for the same underlying
|
|
58
|
+
* reason: `.click()` and dispatched events are untrusted
|
|
59
|
+
* (`Event.isTrusted === false`), and browsers restrict trusted-only
|
|
60
|
+
* behavior to genuine, direct clicks.
|
|
61
|
+
* - Forward a modified click. Ctrl/Cmd/Shift/Alt or non-primary clicks may
|
|
62
|
+
* invoke alternate browser or application behavior that cannot survive a
|
|
63
|
+
* synthetic `.click()`. They are excluded rather than silently degraded
|
|
64
|
+
* into an unintended plain activation. A modifier-clicking user gets
|
|
65
|
+
* nothing from the host's dead space and full native behavior from
|
|
66
|
+
* clicking the target directly — the honest degradation, not a broken one.
|
|
67
|
+
* - Make `target` itself keyboard-reachable. `target` needs its own
|
|
68
|
+
* tab stop regardless (a native `<a>`/`<button>`) — this only extends
|
|
69
|
+
* *pointer* reach, the same as the CSS technique would.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* host.addEventListener('click', (event) => {
|
|
74
|
+
* delegateClickTo(event, host, host.querySelector(':scope > a[href]'));
|
|
75
|
+
* });
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export declare function delegateClickTo(event: MouseEvent, host: HTMLElement, target: HTMLElement | null | undefined, options?: DelegateClickOptions): boolean;
|
|
79
|
+
export interface ClickDelegateControllerOptions extends InteractiveDescendantOptions {
|
|
80
|
+
/** Resolves the element to forward qualifying host clicks to. */
|
|
81
|
+
target: () => HTMLElement | null | undefined;
|
|
82
|
+
/** Skip delegation entirely, e.g. while the host is disabled. */
|
|
83
|
+
disabled?: () => boolean;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Wires {@link delegateClickTo} to a host's own clicks for the lifetime of
|
|
87
|
+
* its connection — the ergonomic entry point for a `LitElement` host; call
|
|
88
|
+
* {@link delegateClickTo} directly outside a `ReactiveController` context.
|
|
89
|
+
*
|
|
90
|
+
* `target` and `disabled` are getters, not static values, so a host can
|
|
91
|
+
* resolve its target dynamically (an `action-target` id-ref looked up by
|
|
92
|
+
* attribute, a structural query for a designated child, one that only
|
|
93
|
+
* matters once some other condition is met) without re-constructing the
|
|
94
|
+
* controller.
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* class ActionRow extends LitElement {
|
|
99
|
+
* constructor() {
|
|
100
|
+
* super();
|
|
101
|
+
* new ClickDelegateController(this, {
|
|
102
|
+
* target: () => this.querySelector<HTMLElement>(':scope > a[href]'),
|
|
103
|
+
* });
|
|
104
|
+
* }
|
|
105
|
+
* }
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export declare class ClickDelegateController implements ReactiveController {
|
|
109
|
+
private readonly _host;
|
|
110
|
+
private readonly _options;
|
|
111
|
+
constructor(host: ReactiveControllerHost & HTMLElement, options: ClickDelegateControllerOptions);
|
|
112
|
+
hostConnected(): void;
|
|
113
|
+
hostDisconnected(): void;
|
|
114
|
+
private readonly _handleClick;
|
|
115
|
+
}
|
|
116
|
+
export default ClickDelegateController;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
export * from './ActiveDescendantController';
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './
|
|
9
|
-
export * from './
|
|
10
|
-
export * from './
|
|
11
|
-
export * from './
|
|
12
|
-
export * from './
|
|
13
|
-
export * from './
|
|
14
|
-
export * from './
|
|
15
|
-
export * from './
|
|
16
|
-
export * from './
|
|
17
|
-
export * from './
|
|
18
|
-
export * from './
|
|
19
|
-
export * from './
|
|
20
|
-
export * from './
|
|
1
|
+
export * from './ActiveDescendantController.js';
|
|
2
|
+
export * from './clickDelegate.js';
|
|
3
|
+
export * from './ItemsCollectionController.js';
|
|
4
|
+
export * from './KeyboardInteractionDirective.js';
|
|
5
|
+
export * from './KeyboardNavigationDirective.js';
|
|
6
|
+
export * from './MouseMoveDirective.js';
|
|
7
|
+
export * from './DragController.js';
|
|
8
|
+
export * from './DragGestureController.js';
|
|
9
|
+
export * from './ResizeController.js';
|
|
10
|
+
export * from './AnchorController.js';
|
|
11
|
+
export * from './ScrollObserverController.js';
|
|
12
|
+
export * from './MutationObserverController.js';
|
|
13
|
+
export * from './NavigationIndicatorController.js';
|
|
14
|
+
export * from './RafScheduler.js';
|
|
15
|
+
export * from './TypeaheadController.js';
|
|
16
|
+
export * from './findNearestScrollAncestor.js';
|
|
17
|
+
export * from './isFocusable.js';
|
|
18
|
+
export * from './nativeChild.js';
|
|
19
|
+
export * from './RovingTabIndexMixin.js';
|
|
20
|
+
export * from './sliderUtils.js';
|
|
21
|
+
export * from './snapUtils.js';
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|