@rcarls/rc-common 0.4.2 → 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.
@@ -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 — call when the popup opens or the anchor moves. */
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
  }
@@ -52,6 +52,13 @@ export declare class ItemsCollectionController implements ReactiveController {
52
52
  private _filterStrategy;
53
53
  private _checkmark;
54
54
  private _optionsInitialized;
55
+ /**
56
+ * Movement (in CSS pixels) beyond which a pending touch activation is
57
+ * treated as a scroll gesture instead of a tap.
58
+ */
59
+ private static readonly _TOUCH_TAP_THRESHOLD;
60
+ /** Touch pointerdown awaiting pointerup to confirm a tap versus a scroll. */
61
+ private _pendingTouchActivation;
55
62
  constructor(host: ReactiveControllerHost & Element, options: ItemsCollectionControllerOptions);
56
63
  hostConnected(): void;
57
64
  hostDisconnected(): void;
@@ -96,5 +103,17 @@ export declare class ItemsCollectionController implements ReactiveController {
96
103
  private _syncFilterToDom;
97
104
  private _applyFilterToLi;
98
105
  private _isVisible;
106
+ private _resolveOptionLi;
107
+ /**
108
+ * Claims a pointer event as an option activation: stops it from continuing
109
+ * to bubble/compose past this point (left unstopped, a composed event can
110
+ * still be observed by ancestors outside this component — e.g. a <label>
111
+ * wrapping an unrelated sibling control — and be reinterpreted as an
112
+ * interaction with something else entirely), then activates the option.
113
+ */
114
+ private _activateLi;
99
115
  private _onPointerDown;
116
+ private _onPointerMove;
117
+ private _onPointerUp;
118
+ private _onPointerCancel;
100
119
  }
@@ -55,15 +55,13 @@ declare class KeyboardNavigationDirective extends AsyncDirective {
55
55
  protected _init(): void;
56
56
  /**
57
57
  * @param _cb - Callback function invoked with the navigation action
58
- * @param _options - Options object or deprecated boolean (deprecated).
59
- * @deprecated Passing a boolean as the second parameter is deprecated.
60
- * Use an options object instead.
58
+ * @param _options - Keyboard navigation behavior options.
61
59
  */
62
- render(_cb: (action: KeyboardNavigationAction) => void, _options?: KeyNavigationOptions | boolean): symbol;
63
- update(part: ElementPart, [cb, optionsOrBoolean]: Parameters<this['render']>): void;
60
+ render(_cb: (action: KeyboardNavigationAction) => void, _options?: KeyNavigationOptions): symbol;
61
+ update(part: ElementPart, [cb, options]: Parameters<this['render']>): void;
64
62
  disconnected(): void;
65
63
  reconnected(): void;
66
64
  }
67
- export declare const keyNavigation: (_cb: (action: KeyboardNavigationAction) => void, _options?: boolean | KeyNavigationOptions | undefined) => import('lit/directive.js').DirectiveResult<typeof KeyboardNavigationDirective>;
65
+ export declare const keyNavigation: (_cb: (action: KeyboardNavigationAction) => void, _options?: KeyNavigationOptions | undefined) => import('lit/directive.js').DirectiveResult<typeof KeyboardNavigationDirective>;
68
66
  export type { KeyboardNavigationDirective };
69
67
  export default keyNavigation;
@@ -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;
@@ -1,20 +1,21 @@
1
- export * from './ActiveDescendantController';
2
- export * from './ItemsCollectionController';
3
- export * from './KeyboardInteractionDirective';
4
- export * from './KeyboardNavigationDirective';
5
- export * from './MouseMoveDirective';
6
- export * from './DragController';
7
- export * from './DragGestureController';
8
- export * from './ResizeController';
9
- export * from './AnchorController';
10
- export * from './ScrollObserverController';
11
- export * from './MutationObserverController';
12
- export * from './NavigationIndicatorController';
13
- export * from './RafScheduler';
14
- export * from './TypeaheadController';
15
- export * from './findNearestScrollAncestor';
16
- export * from './isFocusable';
17
- export * from './nativeChild';
18
- export * from './RovingTabIndexMixin';
19
- export * from './sliderUtils';
20
- export * from './snapUtils';
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
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.4.2",
6
+ "version": "0.6.0",
7
7
  "description": "Shared controllers, directives, and DOM utilities for rc-webcomponents.",
8
8
  "repository": {
9
9
  "type": "git",
@@ -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 {};