@sdxc/ui 2026.10.8 → 2026.10.10
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/README.md +71 -2
- package/dist/behaviors/announcer.d.ts +19 -1
- package/dist/behaviors/announcer.js +32 -4
- package/dist/behaviors/toaster.d.ts +1 -1
- package/dist/behaviors/toaster.js +1 -1
- package/dist/components/color-swatch.js +1 -1
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/components/marker.js +1 -1
- package/dist/components/shortcut-list.d.ts +49 -0
- package/dist/components/shortcut-list.js +39 -0
- package/dist/components/skeleton.d.ts +1 -1
- package/dist/components/skeleton.js +2 -2
- package/dist/mixins/calendar-keys.js +5 -7
- package/dist/mixins/command-filter.js +9 -7
- package/dist/mixins/command-keys.js +6 -19
- package/dist/mixins/drag-reorder.js +6 -6
- package/dist/mixins/drop-zone.js +6 -8
- package/dist/mixins/grid-list-keys.js +8 -8
- package/dist/mixins/hotkey.d.ts +2 -1
- package/dist/mixins/hotkey.js +8 -54
- package/dist/mixins/index.d.ts +2 -0
- package/dist/mixins/index.js +2 -0
- package/dist/mixins/keymap.d.ts +61 -0
- package/dist/mixins/keymap.js +88 -0
- package/dist/mixins/message-follow.js +13 -11
- package/dist/mixins/range-preview.js +5 -7
- package/dist/mixins/resize-handle.js +9 -9
- package/dist/mixins/track-host-node.d.ts +8 -6
- package/dist/mixins/track-host-node.js +8 -6
- package/dist/mixins/treeKeys.js +11 -9
- package/dist/mixins/view-transition.js +14 -13
- package/dist/mixins/while-live.d.ts +24 -0
- package/dist/mixins/while-live.js +56 -0
- package/dist/utils/color-math.js +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/key-combo.d.ts +69 -0
- package/dist/utils/key-combo.js +142 -0
- package/package.json +2 -2
- package/src/reset.css +18 -8
package/dist/mixins/hotkey.js
CHANGED
|
@@ -8,58 +8,8 @@
|
|
|
8
8
|
* @copyright Sergio Xalambrí 2026
|
|
9
9
|
*/
|
|
10
10
|
import { createMixin } from "remix/component";
|
|
11
|
+
import { matchesKeyCombo, parseKeyCombo } from "../utils/key-combo.js";
|
|
11
12
|
import { trackHostNode } from "./track-host-node.js";
|
|
12
|
-
/** Modifier token spellings {@link parseCombo} resolves to the platform's primary modifier, checked as `event.ctrlKey || event.metaKey`. */
|
|
13
|
-
const MOD_ALIASES = new Set(["mod", "ctrl", "control", "cmd", "command", "meta"]);
|
|
14
|
-
/** Modifier token spellings {@link parseCombo} resolves to `event.altKey`. */
|
|
15
|
-
const ALT_ALIASES = new Set(["alt", "option"]);
|
|
16
|
-
/** Modifier token spelling {@link parseCombo} resolves to `event.shiftKey`. */
|
|
17
|
-
const SHIFT_ALIAS = "shift";
|
|
18
|
-
/**
|
|
19
|
-
* Parses a `+`-joined combo string (`"mod+k"`, `"mod+shift+p"`) into the
|
|
20
|
-
* modifier flags and literal trigger key {@link matchesCombo} compares a
|
|
21
|
-
* `keydown` event against, matching tokens case-insensitively.
|
|
22
|
-
*
|
|
23
|
-
* @param combo Combo string as passed to {@link hotkey}.
|
|
24
|
-
* @returns The parsed modifier flags and trigger key.
|
|
25
|
-
*/
|
|
26
|
-
function parseCombo(combo) {
|
|
27
|
-
let tokens = combo
|
|
28
|
-
.split("+")
|
|
29
|
-
.map((token) => token.trim().toLowerCase())
|
|
30
|
-
.filter((token) => token.length > 0);
|
|
31
|
-
let key = tokens.at(-1) ?? "";
|
|
32
|
-
let modifiers = tokens.slice(0, -1);
|
|
33
|
-
if (key === "" && import.meta.env.DEV) {
|
|
34
|
-
console.warn(`hotkey(): "${combo}" has no trigger key and will never match.`);
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
key,
|
|
38
|
-
mod: modifiers.some((token) => MOD_ALIASES.has(token)),
|
|
39
|
-
alt: modifiers.some((token) => ALT_ALIASES.has(token)),
|
|
40
|
-
shift: modifiers.includes(SHIFT_ALIAS),
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Reports whether `event` strikes exactly the key and modifier combination
|
|
45
|
-
* `combo` describes, requiring every modifier `combo` lists and none it
|
|
46
|
-
* doesn't, so a combo never fires on a superset chord.
|
|
47
|
-
*
|
|
48
|
-
* @param event `keydown` event observed on the document.
|
|
49
|
-
* @param combo Parsed combo to compare `event` against.
|
|
50
|
-
* @returns Whether `event` is an exact match for `combo`.
|
|
51
|
-
*/
|
|
52
|
-
function matchesCombo(event, combo) {
|
|
53
|
-
if (event.key.toLowerCase() !== combo.key)
|
|
54
|
-
return false;
|
|
55
|
-
if ((event.ctrlKey || event.metaKey) !== combo.mod)
|
|
56
|
-
return false;
|
|
57
|
-
if (event.altKey !== combo.alt)
|
|
58
|
-
return false;
|
|
59
|
-
if (event.shiftKey !== combo.shift)
|
|
60
|
-
return false;
|
|
61
|
-
return true;
|
|
62
|
-
}
|
|
63
13
|
/**
|
|
64
14
|
* Reads `host`'s current native open state: `HTMLDialogElement.open` for a
|
|
65
15
|
* `<dialog>`, or the `:popover-open` pseudo-class for anything else.
|
|
@@ -104,7 +54,8 @@ function setOpen(host, open) {
|
|
|
104
54
|
* closed, and closes it again on the same combo while it's already open,
|
|
105
55
|
* driving the host's own native `<dialog>` or `[popover]` open state.
|
|
106
56
|
*
|
|
107
|
-
* @param combo Key combination that opens or closes the host, e.g. `"mod+k"
|
|
57
|
+
* @param combo Key combination that opens or closes the host, e.g. `"mod+k"`, where `mod`
|
|
58
|
+
* is Command on Apple keyboards and Control elsewhere.
|
|
108
59
|
* @example
|
|
109
60
|
* <dialog id="command-palette" mix={[hotkey("mod+k")]}>
|
|
110
61
|
* <Command>...</Command>
|
|
@@ -127,13 +78,16 @@ export const hotkey = createMixin((handle) => {
|
|
|
127
78
|
let hostNode = getHostNode();
|
|
128
79
|
if (hostNode === undefined || parsed === undefined)
|
|
129
80
|
return;
|
|
130
|
-
if (keyEvent.repeat || !
|
|
81
|
+
if (keyEvent.repeat || !matchesKeyCombo(keyEvent, parsed))
|
|
131
82
|
return;
|
|
132
83
|
keyEvent.preventDefault();
|
|
133
84
|
setOpen(hostNode, !isOpen(hostNode));
|
|
134
85
|
}, { signal: handle.signal });
|
|
135
86
|
});
|
|
136
87
|
return (combo) => {
|
|
137
|
-
parsed =
|
|
88
|
+
parsed = parseKeyCombo(combo);
|
|
89
|
+
if (parsed.key === "" && import.meta.env.DEV) {
|
|
90
|
+
console.warn(`hotkey(): "${combo}" has no trigger key and will never match.`);
|
|
91
|
+
}
|
|
138
92
|
};
|
|
139
93
|
});
|
package/dist/mixins/index.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ export * from "./grid-list-keys.js";
|
|
|
29
29
|
export * from "./heading-level-fallback.js";
|
|
30
30
|
export * from "./hotkey.js";
|
|
31
31
|
export * from "./image-fallback.js";
|
|
32
|
+
export * from "./keymap.js";
|
|
32
33
|
export * from "./listbox-keys.js";
|
|
33
34
|
export * from "./long-press.js";
|
|
34
35
|
export * from "./menu-keys.js";
|
|
@@ -47,3 +48,4 @@ export * from "./track-host-node.js";
|
|
|
47
48
|
export * from "./treeKeys.js";
|
|
48
49
|
export * from "./validate.js";
|
|
49
50
|
export * from "./view-transition.js";
|
|
51
|
+
export * from "./while-live.js";
|
package/dist/mixins/index.js
CHANGED
|
@@ -29,6 +29,7 @@ export * from "./grid-list-keys.js";
|
|
|
29
29
|
export * from "./heading-level-fallback.js";
|
|
30
30
|
export * from "./hotkey.js";
|
|
31
31
|
export * from "./image-fallback.js";
|
|
32
|
+
export * from "./keymap.js";
|
|
32
33
|
export * from "./listbox-keys.js";
|
|
33
34
|
export * from "./long-press.js";
|
|
34
35
|
export * from "./menu-keys.js";
|
|
@@ -47,3 +48,4 @@ export * from "./track-host-node.js";
|
|
|
47
48
|
export * from "./treeKeys.js";
|
|
48
49
|
export * from "./validate.js";
|
|
49
50
|
export * from "./view-transition.js";
|
|
51
|
+
export * from "./while-live.js";
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why JS: a page-wide shortcut answers a key pressed anywhere in the document, and HTML
|
|
3
|
+
* has no declarative wiring from a keystroke to an action.
|
|
4
|
+
* No-JS baseline: every action stays reachable through the controls it presses, by `Tab`
|
|
5
|
+
* and the pointer.
|
|
6
|
+
*
|
|
7
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
8
|
+
* @copyright Sergio Xalambrí 2026
|
|
9
|
+
*/
|
|
10
|
+
import type { MixinFactory } from "remix/component";
|
|
11
|
+
/**
|
|
12
|
+
* Types for {@link keymap} and {@link bindKeymap}.
|
|
13
|
+
*/
|
|
14
|
+
export declare namespace Keymap {
|
|
15
|
+
/**
|
|
16
|
+
* Each combo, as {@link parseKeyCombo} reads it, mapped to what pressing it runs. The
|
|
17
|
+
* first entry a keystroke matches runs, and the keystroke is then default-prevented.
|
|
18
|
+
*/
|
|
19
|
+
interface Bindings {
|
|
20
|
+
[combo: string]: (event: KeyboardEvent) => void;
|
|
21
|
+
}
|
|
22
|
+
/** Options for {@link bindKeymap}. */
|
|
23
|
+
interface Options {
|
|
24
|
+
/** Takes the bindings off the document. */
|
|
25
|
+
signal: AbortSignal;
|
|
26
|
+
/**
|
|
27
|
+
* The element the bindings belong to. A keystroke inside a `<dialog>` stands the
|
|
28
|
+
* bindings down unless that dialog sits inside this element, so a modal layered over
|
|
29
|
+
* the page keeps its keys while the keymap's own help panel still answers them.
|
|
30
|
+
*/
|
|
31
|
+
scope?: Element | null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Whether a keystroke belongs to someone else: handled nearer its target already, part
|
|
36
|
+
* of an IME composition, typed into a field, or pressed inside a dialog outside `scope`.
|
|
37
|
+
*
|
|
38
|
+
* @param event The keystroke as it reached the document.
|
|
39
|
+
* @param scope The element whose own dialogs still answer the bindings.
|
|
40
|
+
* @returns Whether the bindings stand down for this keystroke.
|
|
41
|
+
*/
|
|
42
|
+
export declare function isClaimedKeystroke(event: KeyboardEvent, scope?: Element | null): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Listens for `bindings` on `document` in the bubble phase, so a handler nearer the
|
|
45
|
+
* target that claims the keystroke first keeps it.
|
|
46
|
+
*
|
|
47
|
+
* @param document The document to listen on.
|
|
48
|
+
* @param bindings Combos mapped to what each runs.
|
|
49
|
+
* @param options The signal that removes the listener, and the bindings' own scope.
|
|
50
|
+
* @example bindKeymap(document, { j: next, k: previous, "?": openHelp }, { signal });
|
|
51
|
+
*/
|
|
52
|
+
export declare function bindKeymap(document: Document, bindings: Keymap.Bindings, options: Keymap.Options): void;
|
|
53
|
+
/**
|
|
54
|
+
* Binds a map of page-wide shortcuts for as long as the host stays mounted, with the host
|
|
55
|
+
* as the bindings' scope: a dialog inside it answers them, any other dialog and any field
|
|
56
|
+
* being typed in keeps its keys. The latest map passed is the one a keystroke runs.
|
|
57
|
+
*
|
|
58
|
+
* @param bindings Combos mapped to what each runs.
|
|
59
|
+
* @example <div mix={[keymap({ j: next, k: previous, "?": openHelp })]}>…</div>
|
|
60
|
+
*/
|
|
61
|
+
export declare const keymap: MixinFactory<HTMLElement, [bindings: Keymap.Bindings]>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why JS: a page-wide shortcut answers a key pressed anywhere in the document, and HTML
|
|
3
|
+
* has no declarative wiring from a keystroke to an action.
|
|
4
|
+
* No-JS baseline: every action stays reachable through the controls it presses, by `Tab`
|
|
5
|
+
* and the pointer.
|
|
6
|
+
*
|
|
7
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
8
|
+
* @copyright Sergio Xalambrí 2026
|
|
9
|
+
*/
|
|
10
|
+
import { createMixin } from "remix/component";
|
|
11
|
+
import { isTypingTarget, matchesKeyCombo, parseKeyCombo } from "../utils/key-combo.js";
|
|
12
|
+
/**
|
|
13
|
+
* Whether a keystroke belongs to someone else: handled nearer its target already, part
|
|
14
|
+
* of an IME composition, typed into a field, or pressed inside a dialog outside `scope`.
|
|
15
|
+
*
|
|
16
|
+
* @param event The keystroke as it reached the document.
|
|
17
|
+
* @param scope The element whose own dialogs still answer the bindings.
|
|
18
|
+
* @returns Whether the bindings stand down for this keystroke.
|
|
19
|
+
*/
|
|
20
|
+
export function isClaimedKeystroke(event, scope) {
|
|
21
|
+
if (event.defaultPrevented || event.isComposing)
|
|
22
|
+
return true;
|
|
23
|
+
if (isTypingTarget(event.target))
|
|
24
|
+
return true;
|
|
25
|
+
let target = event.target;
|
|
26
|
+
if (typeof Element === "undefined" || !(target instanceof Element))
|
|
27
|
+
return false;
|
|
28
|
+
let dialog = target.closest("dialog");
|
|
29
|
+
if (dialog === null)
|
|
30
|
+
return false;
|
|
31
|
+
return !(scope?.contains(dialog) ?? false);
|
|
32
|
+
}
|
|
33
|
+
/** Parses every combo once, keeping the binding order a keystroke is matched in. */
|
|
34
|
+
function compile(bindings) {
|
|
35
|
+
return Object.entries(bindings).map(([combo, run]) => [parseKeyCombo(combo), run]);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Runs the first binding a keystroke matches, reading the bindings at keystroke time so
|
|
39
|
+
* a caller that swaps its map keeps one listener.
|
|
40
|
+
*/
|
|
41
|
+
function listen(document, bindings, options) {
|
|
42
|
+
document.addEventListener("keydown", (event) => {
|
|
43
|
+
if (isClaimedKeystroke(event, options.scope))
|
|
44
|
+
return;
|
|
45
|
+
let match = bindings().find(([combo]) => matchesKeyCombo(event, combo));
|
|
46
|
+
if (match === undefined)
|
|
47
|
+
return;
|
|
48
|
+
match[1](event);
|
|
49
|
+
event.preventDefault();
|
|
50
|
+
}, { signal: options.signal });
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Listens for `bindings` on `document` in the bubble phase, so a handler nearer the
|
|
54
|
+
* target that claims the keystroke first keeps it.
|
|
55
|
+
*
|
|
56
|
+
* @param document The document to listen on.
|
|
57
|
+
* @param bindings Combos mapped to what each runs.
|
|
58
|
+
* @param options The signal that removes the listener, and the bindings' own scope.
|
|
59
|
+
* @example bindKeymap(document, { j: next, k: previous, "?": openHelp }, { signal });
|
|
60
|
+
*/
|
|
61
|
+
export function bindKeymap(document, bindings, options) {
|
|
62
|
+
let compiled = compile(bindings);
|
|
63
|
+
listen(document, () => compiled, options);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Binds a map of page-wide shortcuts for as long as the host stays mounted, with the host
|
|
67
|
+
* as the bindings' scope: a dialog inside it answers them, any other dialog and any field
|
|
68
|
+
* being typed in keeps its keys. The latest map passed is the one a keystroke runs.
|
|
69
|
+
*
|
|
70
|
+
* @param bindings Combos mapped to what each runs.
|
|
71
|
+
* @example <div mix={[keymap({ j: next, k: previous, "?": openHelp })]}>…</div>
|
|
72
|
+
*/
|
|
73
|
+
export const keymap = createMixin((handle) => {
|
|
74
|
+
let compiled = [];
|
|
75
|
+
/**
|
|
76
|
+
* The listener goes on the document the host was inserted into, which leaves the mixin
|
|
77
|
+
* inert wherever the host renders without one, such as on a server.
|
|
78
|
+
*/
|
|
79
|
+
handle.addEventListener("insert", (event) => {
|
|
80
|
+
listen(event.node.ownerDocument, () => compiled, {
|
|
81
|
+
signal: handle.signal,
|
|
82
|
+
scope: event.node,
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
return (bindings) => {
|
|
86
|
+
compiled = compile(bindings);
|
|
87
|
+
};
|
|
88
|
+
});
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import { createElement, createMixin, on } from "remix/component";
|
|
15
15
|
import { prefersReducedMotion } from "../utils/prefers-reduced-motion.js";
|
|
16
|
+
import { whileLive } from "./while-live.js";
|
|
16
17
|
/**
|
|
17
18
|
* Attribute every conversational turn exposes itself on, its value the
|
|
18
19
|
* turn's stable id; `messageFollow()` reads it to find the anchor turn and
|
|
@@ -257,6 +258,16 @@ export const messageFollow = createMixin((handle) => {
|
|
|
257
258
|
let userScrollIntent = false;
|
|
258
259
|
let itemsObserver;
|
|
259
260
|
let observedItems = new Set();
|
|
261
|
+
let follow = whileLive(handle, (model, signal) => {
|
|
262
|
+
model.addEventListener("change", () => {
|
|
263
|
+
if (!hostNode)
|
|
264
|
+
return;
|
|
265
|
+
syncAttributesFromModel(hostNode, model);
|
|
266
|
+
let request = model.consumeScrollRequest();
|
|
267
|
+
if (request)
|
|
268
|
+
fulfillScrollRequest(hostNode, request);
|
|
269
|
+
}, { signal });
|
|
270
|
+
});
|
|
260
271
|
/**
|
|
261
272
|
* Lazily creates the visibility observer the first time a turn exists
|
|
262
273
|
* beneath `host`, then keeps it watching exactly the turns currently
|
|
@@ -373,17 +384,8 @@ export const messageFollow = createMixin((handle) => {
|
|
|
373
384
|
hostNode = undefined;
|
|
374
385
|
});
|
|
375
386
|
return (model) => {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
model.addEventListener("change", () => {
|
|
379
|
-
if (!hostNode)
|
|
380
|
-
return;
|
|
381
|
-
syncAttributesFromModel(hostNode, model);
|
|
382
|
-
let request = model.consumeScrollRequest();
|
|
383
|
-
if (request)
|
|
384
|
-
fulfillScrollRequest(hostNode, request);
|
|
385
|
-
}, { signal: handle.signal });
|
|
386
|
-
}
|
|
387
|
+
boundModel = model;
|
|
388
|
+
follow(model);
|
|
387
389
|
return createElement(handle.element, {
|
|
388
390
|
mix: [
|
|
389
391
|
on("scroll", (event) => {
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
import { createElement, createMixin, on } from "remix/component";
|
|
15
15
|
import { CALENDAR_DAY_DATE_ATTRIBUTE } from "./calendar-keys.js";
|
|
16
16
|
import { trackHostNode } from "./track-host-node.js";
|
|
17
|
+
import { whileLive } from "./while-live.js";
|
|
17
18
|
/**
|
|
18
19
|
* Parses a day cell's {@link CALENDAR_DAY_DATE_ATTRIBUTE} value into a
|
|
19
20
|
* `Date` built from its numeric year/month/day components, keeping the
|
|
@@ -66,7 +67,9 @@ function classifyRangePosition(date, range) {
|
|
|
66
67
|
*/
|
|
67
68
|
export const rangePreview = createMixin((handle) => {
|
|
68
69
|
let getHostNode = trackHostNode(handle);
|
|
69
|
-
let
|
|
70
|
+
let follow = whileLive(handle, (model, signal) => {
|
|
71
|
+
model.addEventListener("change", () => syncRangePreview(model), { signal });
|
|
72
|
+
});
|
|
70
73
|
/** Mirrors `model`'s anchor day and preview range onto the grid's day cells. */
|
|
71
74
|
function syncRangePreview(model) {
|
|
72
75
|
let hostNode = getHostNode();
|
|
@@ -100,12 +103,7 @@ export const rangePreview = createMixin((handle) => {
|
|
|
100
103
|
model.updateRangePreview(date);
|
|
101
104
|
}
|
|
102
105
|
return (model) => {
|
|
103
|
-
|
|
104
|
-
boundModel = model;
|
|
105
|
-
model.addEventListener("change", () => syncRangePreview(model), {
|
|
106
|
-
signal: handle.signal,
|
|
107
|
-
});
|
|
108
|
-
}
|
|
106
|
+
follow(model);
|
|
109
107
|
return createElement(handle.element, {
|
|
110
108
|
mix: [
|
|
111
109
|
on("pointerover", (event) => {
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
import { createElement, createMixin, on } from "remix/component";
|
|
16
16
|
import { isNewPrimaryPress } from "../utils/is-new-primary-press.js";
|
|
17
17
|
import { trackHostNode } from "./track-host-node.js";
|
|
18
|
+
import { whileLive } from "./while-live.js";
|
|
18
19
|
/**
|
|
19
20
|
* Attribute a Resizable panel group's own host element carries.
|
|
20
21
|
* `resizeHandle()` walks up to the nearest ancestor carrying it to find the
|
|
@@ -195,8 +196,14 @@ function roundPercent(value) {
|
|
|
195
196
|
*/
|
|
196
197
|
export const resizeHandle = createMixin((handle) => {
|
|
197
198
|
let getHostNode = trackHostNode(handle);
|
|
198
|
-
let boundSession;
|
|
199
199
|
let activePointerId;
|
|
200
|
+
let follow = whileLive(handle, (session, signal) => {
|
|
201
|
+
session.addEventListener("change", () => syncLayout(session), { signal });
|
|
202
|
+
signal.addEventListener("abort", () => {
|
|
203
|
+
if (activePointerId !== undefined)
|
|
204
|
+
session.cancel();
|
|
205
|
+
});
|
|
206
|
+
});
|
|
200
207
|
/** Mirrors `session`'s resolved sizes onto their panel elements, and this handle's adjacent panel onto its own ARIA value attributes. */
|
|
201
208
|
function syncLayout(session) {
|
|
202
209
|
let hostNode = getHostNode();
|
|
@@ -224,14 +231,7 @@ export const resizeHandle = createMixin((handle) => {
|
|
|
224
231
|
hostNode.setAttribute("aria-valuemax", String(Math.round(adjacentPanel.max)));
|
|
225
232
|
}
|
|
226
233
|
return (axis, session) => {
|
|
227
|
-
|
|
228
|
-
boundSession = session;
|
|
229
|
-
session.addEventListener("change", () => syncLayout(session), { signal: handle.signal });
|
|
230
|
-
handle.signal.addEventListener("abort", () => {
|
|
231
|
-
if (activePointerId !== undefined)
|
|
232
|
-
session.cancel();
|
|
233
|
-
});
|
|
234
|
-
}
|
|
234
|
+
follow(session);
|
|
235
235
|
return createElement(handle.element, {
|
|
236
236
|
mix: [
|
|
237
237
|
on("pointerdown", (event) => {
|
|
@@ -20,12 +20,14 @@ import type { MixinHandle } from "remix/component";
|
|
|
20
20
|
* export const example = createMixin<HTMLElement>((handle) => {
|
|
21
21
|
* let hostNode = trackHostNode(handle);
|
|
22
22
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
23
|
+
* handle.queueTask(() => {
|
|
24
|
+
* addEventListeners(document, handle.signal, {
|
|
25
|
+
* keydown() {
|
|
26
|
+
* let node = hostNode();
|
|
27
|
+
* if (node === undefined) return;
|
|
28
|
+
* // ...
|
|
29
|
+
* },
|
|
30
|
+
* });
|
|
29
31
|
* });
|
|
30
32
|
*
|
|
31
33
|
* return () => {};
|
|
@@ -19,12 +19,14 @@
|
|
|
19
19
|
* export const example = createMixin<HTMLElement>((handle) => {
|
|
20
20
|
* let hostNode = trackHostNode(handle);
|
|
21
21
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
22
|
+
* handle.queueTask(() => {
|
|
23
|
+
* addEventListeners(document, handle.signal, {
|
|
24
|
+
* keydown() {
|
|
25
|
+
* let node = hostNode();
|
|
26
|
+
* if (node === undefined) return;
|
|
27
|
+
* // ...
|
|
28
|
+
* },
|
|
29
|
+
* });
|
|
28
30
|
* });
|
|
29
31
|
*
|
|
30
32
|
* return () => {};
|
package/dist/mixins/treeKeys.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { createElement, createMixin, on } from "remix/component";
|
|
13
13
|
import { isPrintableKey, labelFor, setRovingTabindex } from "../utils/keyboard-nav.js";
|
|
14
|
+
import { whileLive } from "./while-live.js";
|
|
14
15
|
/**
|
|
15
16
|
* Attribute every Tree row exposes itself on; its value doubles as the
|
|
16
17
|
* `SelectionModel.Key` {@link treeKeys} toggles, ranges over, and mirrors
|
|
@@ -155,6 +156,14 @@ export const treeKeys = createMixin((handle) => {
|
|
|
155
156
|
let boundModel;
|
|
156
157
|
let buffer = "";
|
|
157
158
|
let resetBufferId;
|
|
159
|
+
let follow = whileLive(handle, (model, signal) => {
|
|
160
|
+
model.addEventListener("change", () => {
|
|
161
|
+
if (hostNode === undefined)
|
|
162
|
+
return;
|
|
163
|
+
syncSelection(hostNode, model);
|
|
164
|
+
dispatchTreeChange(hostNode, model);
|
|
165
|
+
}, { signal });
|
|
166
|
+
});
|
|
158
167
|
handle.addEventListener("insert", (event) => {
|
|
159
168
|
hostNode = event.node;
|
|
160
169
|
let rows = collectRows(hostNode);
|
|
@@ -172,15 +181,8 @@ export const treeKeys = createMixin((handle) => {
|
|
|
172
181
|
});
|
|
173
182
|
handle.signal.addEventListener("abort", () => clearTimeout(resetBufferId));
|
|
174
183
|
return (model) => {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
model.addEventListener("change", () => {
|
|
178
|
-
if (hostNode === undefined)
|
|
179
|
-
return;
|
|
180
|
-
syncSelection(hostNode, model);
|
|
181
|
-
dispatchTreeChange(hostNode, model);
|
|
182
|
-
}, { signal: handle.signal });
|
|
183
|
-
}
|
|
184
|
+
boundModel = model;
|
|
185
|
+
follow(model);
|
|
184
186
|
return createElement(handle.element, {
|
|
185
187
|
mix: [
|
|
186
188
|
on("focusin", (event) => {
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
import { createElement, createMixin } from "remix/component";
|
|
12
12
|
import { prefersReducedMotion } from "../utils/prefers-reduced-motion.js";
|
|
13
13
|
import { trackHostNode } from "./track-host-node.js";
|
|
14
|
+
import { whileLive } from "./while-live.js";
|
|
14
15
|
/**
|
|
15
16
|
* `data-*` attribute {@link viewTransition} sets on a SharedElement's host
|
|
16
17
|
* while its Frame's transition is in flight, so styling can suppress hover
|
|
@@ -93,19 +94,19 @@ function settleFrameTransition(frame) {
|
|
|
93
94
|
*/
|
|
94
95
|
export const viewTransition = createMixin((handle) => {
|
|
95
96
|
let getHostNode = trackHostNode(handle);
|
|
96
|
-
let
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
signal: handle.signal,
|
|
97
|
+
let follow = whileLive(handle, (frame, signal) => {
|
|
98
|
+
frame.addEventListener("reloadStart", () => {
|
|
99
|
+
let state = ensureFrameTransition(frame);
|
|
100
|
+
let hostNode = getHostNode();
|
|
101
|
+
hostNode?.dispatchEvent(new ViewTransitionEvent(state.transition));
|
|
102
|
+
if (!state.transition)
|
|
103
|
+
return;
|
|
104
|
+
let stopTransitioning = () => getHostNode()?.removeAttribute(TRANSITIONING_ATTRIBUTE);
|
|
105
|
+
hostNode?.toggleAttribute(TRANSITIONING_ATTRIBUTE, true);
|
|
106
|
+
void state.transition.finished.then(stopTransitioning, stopTransitioning);
|
|
107
|
+
}, { signal });
|
|
108
|
+
frame.addEventListener("reloadComplete", () => settleFrameTransition(frame), { signal });
|
|
109
109
|
});
|
|
110
|
+
follow(handle.frame);
|
|
110
111
|
return () => createElement(handle.element, {});
|
|
111
112
|
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ties a subscription to a model, session, frame or global to the time a mixin's host or an
|
|
3
|
+
* island component is live in a document, so code that renders on a server as well as in a
|
|
4
|
+
* browser subscribes only in the browser, with a real signal that detaches the listeners.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { Handle, MixinHandle } from "remix/component";
|
|
10
|
+
/**
|
|
11
|
+
* Keeps `subscribe` bound to the latest target handed to the returned function while the host
|
|
12
|
+
* is inserted, or once an island component's first render commits: server rendering never
|
|
13
|
+
* subscribes, and a new target detaches the previous one's listeners. Call it during setup.
|
|
14
|
+
*
|
|
15
|
+
* @param handle Handle of the mixin or island component whose lifetime bounds every subscription.
|
|
16
|
+
* @param subscribe Registers listeners on `target` with `signal`, which aborts once that target
|
|
17
|
+
* is replaced or the mixin slot or component is disposed.
|
|
18
|
+
* @returns A function to call with the current target, from render or straight after setup.
|
|
19
|
+
* @template target The model, session, frame or global being listened to.
|
|
20
|
+
* @template node The host element a mixin is applied to.
|
|
21
|
+
* @example let follow = whileLive(handle, (model, signal) => model.addEventListener("change", sync, { signal }));
|
|
22
|
+
* @example whileLive(handle, (model: Toaster, signal) => model.addEventListener("change", () => void handle.update(), { signal }))(toaster);
|
|
23
|
+
*/
|
|
24
|
+
export declare function whileLive<target extends object, node extends EventTarget = Element>(handle: MixinHandle<node> | Pick<Handle, "signal" | "queueTask">, subscribe: (target: target, signal: AbortSignal) => void): (target: target) => void;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ties a subscription to a model, session, frame or global to the time a mixin's host or an
|
|
3
|
+
* island component is live in a document, so code that renders on a server as well as in a
|
|
4
|
+
* browser subscribes only in the browser, with a real signal that detaches the listeners.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Keeps `subscribe` bound to the latest target handed to the returned function while the host
|
|
11
|
+
* is inserted, or once an island component's first render commits: server rendering never
|
|
12
|
+
* subscribes, and a new target detaches the previous one's listeners. Call it during setup.
|
|
13
|
+
*
|
|
14
|
+
* @param handle Handle of the mixin or island component whose lifetime bounds every subscription.
|
|
15
|
+
* @param subscribe Registers listeners on `target` with `signal`, which aborts once that target
|
|
16
|
+
* is replaced or the mixin slot or component is disposed.
|
|
17
|
+
* @returns A function to call with the current target, from render or straight after setup.
|
|
18
|
+
* @template target The model, session, frame or global being listened to.
|
|
19
|
+
* @template node The host element a mixin is applied to.
|
|
20
|
+
* @example let follow = whileLive(handle, (model, signal) => model.addEventListener("change", sync, { signal }));
|
|
21
|
+
* @example whileLive(handle, (model: Toaster, signal) => model.addEventListener("change", () => void handle.update(), { signal }))(toaster);
|
|
22
|
+
*/
|
|
23
|
+
export function whileLive(handle, subscribe) {
|
|
24
|
+
let lifetime = handle.signal;
|
|
25
|
+
let live = false;
|
|
26
|
+
let latest;
|
|
27
|
+
let bound;
|
|
28
|
+
let binding;
|
|
29
|
+
/** Subscribes to the latest target once the host is live and that target is not yet bound. */
|
|
30
|
+
function bind() {
|
|
31
|
+
if (!live || latest === undefined || latest === bound)
|
|
32
|
+
return;
|
|
33
|
+
binding?.abort();
|
|
34
|
+
binding = new AbortController();
|
|
35
|
+
bound = latest;
|
|
36
|
+
subscribe(latest, AbortSignal.any([lifetime, binding.signal]));
|
|
37
|
+
}
|
|
38
|
+
/** Marks the host or component live and binds whatever target arrived before it was. */
|
|
39
|
+
function goLive() {
|
|
40
|
+
live = true;
|
|
41
|
+
bind();
|
|
42
|
+
}
|
|
43
|
+
if ("addEventListener" in handle) {
|
|
44
|
+
handle.addEventListener("insert", goLive);
|
|
45
|
+
handle.addEventListener("remove", () => {
|
|
46
|
+
live = false;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
handle.queueTask(goLive);
|
|
51
|
+
}
|
|
52
|
+
return (target) => {
|
|
53
|
+
latest = target;
|
|
54
|
+
bind();
|
|
55
|
+
};
|
|
56
|
+
}
|
package/dist/utils/color-math.js
CHANGED
|
@@ -220,7 +220,7 @@ function parseAlphaToken(token) {
|
|
|
220
220
|
}
|
|
221
221
|
/** Parses an `hsl()`/`hsla()` hue token — a plain number optionally suffixed with `deg` — to its numeric degree value, or `null` when `token` matches neither shape. */
|
|
222
222
|
function parseHueToken(token) {
|
|
223
|
-
let match = /^(
|
|
223
|
+
let match = /^(-?(?:\d+(?:\.\d+)?|\.\d+))(deg)?$/i.exec(token);
|
|
224
224
|
if (match === null)
|
|
225
225
|
return null;
|
|
226
226
|
let value = Number(match[1]);
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export * from "./geometry.js";
|
|
|
21
21
|
export * from "./has-accessible-text.js";
|
|
22
22
|
export * from "./hue-spectrum.js";
|
|
23
23
|
export * from "./is-new-primary-press.js";
|
|
24
|
+
export * from "./key-combo.js";
|
|
24
25
|
export * from "./keyboard-nav.js";
|
|
25
26
|
export * from "./merge-style.js";
|
|
26
27
|
export * from "./paired-range-inputs.js";
|
package/dist/utils/index.js
CHANGED
|
@@ -21,6 +21,7 @@ export * from "./geometry.js";
|
|
|
21
21
|
export * from "./has-accessible-text.js";
|
|
22
22
|
export * from "./hue-spectrum.js";
|
|
23
23
|
export * from "./is-new-primary-press.js";
|
|
24
|
+
export * from "./key-combo.js";
|
|
24
25
|
export * from "./keyboard-nav.js";
|
|
25
26
|
export * from "./merge-style.js";
|
|
26
27
|
export * from "./paired-range-inputs.js";
|