@alulore/kumiko 0.14.2 → 0.15.1

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.
@@ -0,0 +1,77 @@
1
+ /** How a card is built: a flat panel, a recessed panel, a drop target, a row with a lamp and actions, a button, or an add button. */
2
+ export type CardVariant = "surface" | "inset" | "well" | "banner" | "interactive" | "add";
3
+ /** The surface look: a flat fill, a fill with a hairline edge, a raised soft shadow, or an outline only. */
4
+ export type CardSurface = "flat" | "edge" | "raised" | "outline";
5
+ /** What a pressable card does on hover: grow slightly, lift with a deeper shadow, or only brighten. */
6
+ export type CardHover = "grow" | "lift" | "brighten";
7
+ /** What a pressable card does under a press: squash, sink (a tighter shadow and a darker fill), or nothing. */
8
+ export type CardPress = "squash" | "sink" | "none";
9
+ /** The look of an add card: a dashed outline, a dotted outline, or a soft fill with a plus mark. */
10
+ export type CardAddLook = "dashed" | "dotted" | "plus";
11
+ /** The looks every card shares. Each is a prop, or a word on any container such as `data-kumiko-card="hover-grow"`. */
12
+ export interface CardLooks {
13
+ /**
14
+ * Inset, well and add cards keep their own surface.
15
+ * Word: `surface-flat`, `surface-edge`, `surface-raised` or `surface-outline`.
16
+ * @defaultValue "flat"
17
+ */
18
+ surface?: CardSurface;
19
+ /**
20
+ * Only a pressable card reacts. Word: `hover-grow`, `hover-lift` or `hover-brighten`.
21
+ * @defaultValue "grow"
22
+ */
23
+ hover?: CardHover;
24
+ /**
25
+ * Only a pressable card reacts. Word: `press-squash`, `press-sink` or `press-none`.
26
+ * @defaultValue "squash"
27
+ */
28
+ press?: CardPress;
29
+ }
30
+ /** The data attributes the looks become. A look left out sets nothing, so a word on a container can pick. */
31
+ export declare function lookAttributes(looks: CardLooks): Record<string, string | undefined>;
32
+ export type CardProps = React.HTMLAttributes<HTMLElement> & CardLooks & {
33
+ /** @defaultValue "surface" */
34
+ variant?: CardVariant;
35
+ /**
36
+ * The look of an add card. Word: `add-dashed`, `add-dotted` or `add-plus`.
37
+ * @defaultValue "dashed"
38
+ */
39
+ addLook?: CardAddLook;
40
+ /** Dimmed, with a not-allowed cursor, and no hover or press. */
41
+ disabled?: boolean;
42
+ /** Shown as it is, with no hover, press or pointer cursor, and not dimmed. A button card becomes a plain box. */
43
+ readOnly?: boolean;
44
+ /** A well that a card is being dragged over takes a tint and a ring. */
45
+ over?: boolean;
46
+ /** A well with a solid fill, for use as a drop target on a busy background. */
47
+ solid?: boolean;
48
+ /**
49
+ * Whether the card shows hover, press and the press cursor. Left out, a button card (or an `asChild` one with an
50
+ * `onClick`) is pressable and a plain `div` is not. `true` makes a plain card react too, for a card that something
51
+ * else opens: it adds no role, tabindex or click handling, so that is yours to do. `false` turns the looks off even
52
+ * on a button. `disabled` and `readOnly` win over it. Kumiko sets `data-pressable` itself, and a stray one in the
53
+ * props is ignored.
54
+ */
55
+ pressable?: boolean;
56
+ /** The lamp at the start of a banner. */
57
+ lamp?: React.ReactNode;
58
+ /** The actions at the end of a banner. */
59
+ actions?: React.ReactNode;
60
+ /** The card's element: a `div`, or a `button` for a pressable card. */
61
+ ref?: React.Ref<HTMLDivElement>;
62
+ };
63
+ /** An empty data attribute when on, and none when off. */
64
+ export declare function flag(on: boolean | undefined): string | undefined;
65
+ /** Whether a card shows hover and press: the prop when given, otherwise whether it is a button, and never when disabled or read-only. */
66
+ export declare function isPressable(pressable: boolean | undefined, natural: boolean, off: {
67
+ disabled: boolean;
68
+ readOnly: boolean;
69
+ }): boolean;
70
+ /** The props without a `data-pressable`, which only the `pressable` prop may set. */
71
+ export declare function withoutPressable(props: object): Record<string, unknown>;
72
+ /**
73
+ * A panel in six variants. An `interactive` card with an `onClick`, and an `add` card, are buttons: only they
74
+ * (and not `disabled` or `readOnly` ones) react to hover and press. A `banner` shows `lamp`, the children and `actions` in a row.
75
+ * `surface`, `hover`, `press` and `addLook` pick looks; the same words work on any container.
76
+ */
77
+ export declare function Card({ variant, surface, hover, press, addLook, disabled, readOnly, pressable, over, solid, lamp, actions, children, onClick, ref, ...props }: CardProps): React.JSX.Element;
@@ -0,0 +1,56 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { renderElement } from "@ui-sdk/react/primitive";
3
+ /** The data attributes the looks become. A look left out sets nothing, so a word on a container can pick. */
4
+ export function lookAttributes(looks) {
5
+ return {
6
+ "data-look-surface": looks.surface,
7
+ "data-look-hover": looks.hover,
8
+ "data-look-press": looks.press
9
+ };
10
+ }
11
+ /** An empty data attribute when on, and none when off. */
12
+ export function flag(on) {
13
+ return on ? "" : undefined;
14
+ }
15
+ /** Whether a card shows hover and press: the prop when given, otherwise whether it is a button, and never when disabled or read-only. */
16
+ export function isPressable(pressable, natural, off) {
17
+ return !off.disabled && !off.readOnly && (pressable ?? natural);
18
+ }
19
+ /** The props without a `data-pressable`, which only the `pressable` prop may set. */
20
+ export function withoutPressable(props) {
21
+ return Object.fromEntries(Object.entries(props).filter(([name]) => name !== "data-pressable"));
22
+ }
23
+ /** A banner's row: the lamp, the body and the actions. */
24
+ function banner(lamp, children, actions) {
25
+ return (_jsxs(_Fragment, { children: [lamp ? _jsx("div", { "data-slot": "card-lamp", children: lamp }) : null, _jsx("div", { "data-slot": "card-body", children: children }), actions ? _jsx("div", { "data-slot": "card-actions", children: actions }) : null] }));
26
+ }
27
+ /**
28
+ * A panel in six variants. An `interactive` card with an `onClick`, and an `add` card, are buttons: only they
29
+ * (and not `disabled` or `readOnly` ones) react to hover and press. A `banner` shows `lamp`, the children and `actions` in a row.
30
+ * `surface`, `hover`, `press` and `addLook` pick looks; the same words work on any container.
31
+ */
32
+ export function Card({ variant = "surface", surface, hover, press, addLook, disabled = false, readOnly = false, pressable, over = false, solid = false, lamp, actions, children, onClick, ref, ...props }) {
33
+ const asButton = !readOnly && (variant === "add" || (variant === "interactive" && onClick !== undefined));
34
+ const common = {
35
+ "data-slot": "card",
36
+ "data-variant": variant,
37
+ ...lookAttributes({ surface, hover, press }),
38
+ "data-look-add": addLook,
39
+ "data-over": flag(over),
40
+ "data-solid": flag(solid),
41
+ "data-readonly": flag(readOnly),
42
+ "data-disabled": flag(disabled)
43
+ };
44
+ const kind = asButton
45
+ ? { type: "button", disabled, onClick }
46
+ : { "aria-disabled": disabled ? true : undefined };
47
+ const body = variant === "banner" ? banner(lamp, children, actions) : children;
48
+ return renderElement(asButton ? "button" : "div", {
49
+ ...common,
50
+ ...kind,
51
+ ...withoutPressable(props),
52
+ "data-pressable": flag(isPressable(pressable, asButton, { disabled, readOnly })),
53
+ ref,
54
+ children: body
55
+ });
56
+ }
@@ -0,0 +1,2 @@
1
+ export { Card, type CardAddLook, type CardHover, type CardLooks, type CardPress, type CardProps, type CardSurface, type CardVariant } from "./card";
2
+ export { ItemCard, ItemCardEyebrow, ItemCardMedia, ItemCardMeta, ItemCardPolaroid, ItemCardText, ItemCardTitle, type ItemCardDoneLook, type ItemCardDragLook, type ItemCardEyebrowProps, type ItemCardMetaProps, type ItemCardPolaroidProps, type ItemCardPolaroids, type ItemCardProps, type ItemCardSelectLook, type ItemCardTextProps, type ItemCardTone } from "./item-card";
@@ -0,0 +1,2 @@
1
+ export { Card } from "./card";
2
+ export { ItemCard, ItemCardEyebrow, ItemCardMedia, ItemCardMeta, ItemCardPolaroid, ItemCardText, ItemCardTitle } from "./item-card";
@@ -0,0 +1,92 @@
1
+ import { type CardLooks } from "./card";
2
+ /** The tone of an item card: a dark card or a paper card. */
3
+ export type ItemCardTone = "dark" | "paper";
4
+ /** How a selected item card shows it: a ring outside, a tinted fill with a ring, or a small check badge. */
5
+ export type ItemCardSelectLook = "ring" | "tint" | "check";
6
+ /** How a dragged item card looks: lifted with a bigger shadow, tilted, or grown slightly. */
7
+ export type ItemCardDragLook = "lift" | "tilt" | "grow";
8
+ /** How a done item card looks: struck through, quiet ink only, or a strike that draws across when it becomes done. */
9
+ export type ItemCardDoneLook = "strike" | "quiet" | "draw";
10
+ /** How polaroids sit: a tilted fan that stays, a fan that straightens on hover, or no tilt. */
11
+ export type ItemCardPolaroids = "fan" | "straighten" | "flat";
12
+ export type ItemCardProps = React.HTMLAttributes<HTMLElement> & CardLooks & {
13
+ /** @defaultValue "dark" */
14
+ tone?: ItemCardTone;
15
+ selected?: boolean;
16
+ done?: boolean;
17
+ dragging?: boolean;
18
+ /** Dimmed, with a not-allowed cursor, and no hover or press. */
19
+ disabled?: boolean;
20
+ /** Shown as it is, with no hover, press or pointer cursor, and not dimmed. */
21
+ readOnly?: boolean;
22
+ /**
23
+ * Whether the card shows hover, press and the press cursor. Left out, a button card (or an `asChild` one with an
24
+ * `onClick`) is pressable and a plain box is not. `true` makes a plain card react too, for a card that something
25
+ * else opens: it adds no role, tabindex or click handling, so that is yours to do. `false` turns the looks off even
26
+ * on a button. `disabled` and `readOnly` win over it. Kumiko sets `data-pressable` itself, and a stray one in the
27
+ * props is ignored.
28
+ */
29
+ pressable?: boolean;
30
+ /** Draws the card on its only child, which receives the props. */
31
+ asChild?: boolean;
32
+ /** The card's element. With `asChild` it goes to the child. */
33
+ ref?: React.Ref<HTMLDivElement>;
34
+ /**
35
+ * Word: `select-ring`, `select-tint` or `select-check`.
36
+ * @defaultValue "ring"
37
+ */
38
+ selectLook?: ItemCardSelectLook;
39
+ /**
40
+ * Word: `drag-lift`, `drag-tilt` or `drag-grow`.
41
+ * @defaultValue "lift"
42
+ */
43
+ dragLook?: ItemCardDragLook;
44
+ /**
45
+ * Word: `done-strike`, `done-quiet` or `done-draw`.
46
+ * @defaultValue "draw"
47
+ */
48
+ doneLook?: ItemCardDoneLook;
49
+ /**
50
+ * Word: `polaroid-fan`, `polaroid-straighten` or `polaroid-flat`.
51
+ * @defaultValue "straighten"
52
+ */
53
+ polaroids?: ItemCardPolaroids;
54
+ };
55
+ /**
56
+ * A card for one item, as a button when it has an `onClick` and a plain box otherwise; `asChild` draws it on your own element.
57
+ * Only a pressable card (not `disabled` or `readOnly`) reacts to hover and press.
58
+ * The looks are props, and the same words work on any container, such as `data-kumiko-card="select-check done-draw"`.
59
+ */
60
+ export declare function ItemCard({ asChild, pressable: pressableProp, onClick, children, ref, ...props }: ItemCardProps): React.JSX.Element;
61
+ export type ItemCardEyebrowProps = React.ComponentPropsWithoutRef<"span"> & {
62
+ /** The colour of the small diamond, any CSS colour. */
63
+ dot?: string;
64
+ };
65
+ /** A small line above the title, led by a coloured diamond. */
66
+ export declare function ItemCardEyebrow({ dot, children, ...props }: ItemCardEyebrowProps): React.JSX.Element;
67
+ /** The title. A done card shows it quiet, and struck through or drawn through, by its look. */
68
+ export declare function ItemCardTitle({ children, ...props }: React.ComponentPropsWithoutRef<"span">): React.JSX.Element;
69
+ export type ItemCardTextProps = React.ComponentPropsWithoutRef<"span"> & {
70
+ /**
71
+ * How many lines show before the text is cut.
72
+ * @defaultValue 2
73
+ */
74
+ lines?: number;
75
+ };
76
+ /** A few lines of quiet text, cut after `lines`. */
77
+ export declare function ItemCardText({ lines, style, ...props }: ItemCardTextProps): React.JSX.Element;
78
+ /** A row that holds up to three polaroids. */
79
+ export declare function ItemCardMedia({ children, ...props }: React.ComponentPropsWithoutRef<"span">): React.JSX.Element;
80
+ export type ItemCardPolaroidProps = React.ComponentPropsWithoutRef<"span"> & {
81
+ /** An image address. Without it the children (an inline SVG, say) fill the photo. */
82
+ src?: string;
83
+ alt?: string;
84
+ };
85
+ /** One photo with a white border. */
86
+ export declare function ItemCardPolaroid({ src, alt, children, ...props }: ItemCardPolaroidProps): React.JSX.Element;
87
+ export type ItemCardMetaProps = React.ComponentPropsWithoutRef<"span"> & {
88
+ /** A number or text shown in a count badge at the end. */
89
+ count?: React.ReactNode;
90
+ };
91
+ /** A row for small facts, with a count badge pushed to the end. It needs the badge styles (`badge.css`, which `card.css` imports). */
92
+ export declare function ItemCardMeta({ count, children, ...props }: ItemCardMetaProps): React.JSX.Element;
@@ -0,0 +1,79 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { mergeProps, renderElement } from "@ui-sdk/react/primitive";
3
+ import { Children, isValidElement } from "react";
4
+ import { Badge } from "../badge/badge";
5
+ import { flag, isPressable, lookAttributes, withoutPressable } from "./card";
6
+ /** Splits the props into the data attributes that carry the state and looks, and the rest for the element. */
7
+ function splitProps(props) {
8
+ const { tone, selected, done, dragging, disabled, readOnly, ...more } = props;
9
+ const { selectLook, dragLook, doneLook, polaroids, surface, hover, press, ...dom } = more;
10
+ const state = {
11
+ "data-slot": "item-card",
12
+ "data-tone": tone === "paper" ? "paper" : undefined,
13
+ "data-selected": flag(selected),
14
+ "data-done": flag(done),
15
+ "data-dragging": flag(dragging),
16
+ "data-readonly": flag(readOnly),
17
+ "data-disabled": flag(disabled),
18
+ "data-look-select": selectLook,
19
+ "data-look-drag": dragLook,
20
+ "data-look-done": doneLook,
21
+ "data-look-polaroid": polaroids,
22
+ "aria-disabled": disabled ? true : undefined,
23
+ ...lookAttributes({ surface, hover, press })
24
+ };
25
+ return {
26
+ state,
27
+ dom: withoutPressable(dom),
28
+ disabled: disabled === true,
29
+ readOnly: readOnly === true
30
+ };
31
+ }
32
+ /**
33
+ * A card for one item, as a button when it has an `onClick` and a plain box otherwise; `asChild` draws it on your own element.
34
+ * Only a pressable card (not `disabled` or `readOnly`) reacts to hover and press.
35
+ * The looks are props, and the same words work on any container, such as `data-kumiko-card="select-check done-draw"`.
36
+ */
37
+ export function ItemCard({ asChild = false, pressable: pressableProp, onClick, children, ref, ...props }) {
38
+ const { state, dom, disabled, readOnly } = splitProps(props);
39
+ const clickable = onClick !== undefined && !readOnly;
40
+ const on = isPressable(pressableProp, clickable, { disabled, readOnly });
41
+ const pressable = { ...state, "data-pressable": flag(on) };
42
+ if (asChild && isValidElement(children)) {
43
+ const own = { onClick: clickable && !disabled ? onClick : undefined, ref };
44
+ return renderElement("div", mergeProps(dom, own, pressable), children);
45
+ }
46
+ const button = clickable ? { type: "button", disabled, onClick } : {};
47
+ return renderElement(clickable ? "button" : "div", {
48
+ ...dom,
49
+ ...pressable,
50
+ ...button,
51
+ ref,
52
+ children
53
+ });
54
+ }
55
+ /** A small line above the title, led by a coloured diamond. */
56
+ export function ItemCardEyebrow({ dot, children, ...props }) {
57
+ return (_jsxs("span", { "data-slot": "item-card-eyebrow", ...props, children: [_jsx("i", { "aria-hidden": "true", style: dot ? { background: dot } : undefined }), children] }));
58
+ }
59
+ /** The title. A done card shows it quiet, and struck through or drawn through, by its look. */
60
+ export function ItemCardTitle({ children, ...props }) {
61
+ return (_jsx("span", { "data-slot": "item-card-title", ...props, children: _jsx("span", { "data-slot": "item-card-title-text", children: children }) }));
62
+ }
63
+ /** A few lines of quiet text, cut after `lines`. */
64
+ export function ItemCardText({ lines = 2, style, ...props }) {
65
+ const clamp = { WebkitLineClamp: lines, maxBlockSize: `${lines * 1.5}em` };
66
+ return _jsx("span", { "data-slot": "item-card-text", style: { ...style, ...clamp }, ...props });
67
+ }
68
+ /** A row that holds up to three polaroids. */
69
+ export function ItemCardMedia({ children, ...props }) {
70
+ return (_jsx("span", { "data-slot": "item-card-media", "data-count": Children.count(children), ...props, children: children }));
71
+ }
72
+ /** One photo with a white border. */
73
+ export function ItemCardPolaroid({ src, alt = "", children, ...props }) {
74
+ return (_jsx("span", { "data-slot": "item-card-polaroid", ...props, children: _jsx("span", { "data-slot": "item-card-photo", children: src ? _jsx("img", { src: src, alt: alt, draggable: false }) : children }) }));
75
+ }
76
+ /** A row for small facts, with a count badge pushed to the end. It needs the badge styles (`badge.css`, which `card.css` imports). */
77
+ export function ItemCardMeta({ count, children, ...props }) {
78
+ return (_jsxs("span", { "data-slot": "item-card-meta", ...props, children: [children, count !== undefined && count !== null ? (_jsx(Badge, { variant: "count", size: "md", children: count })) : null] }));
79
+ }
@@ -0,0 +1 @@
1
+ export { InfoRow, ListRow, RowList, type CurrentLook, type InfoRowProps, type ListRowProps, type RowHover, type RowListProps, type RowPress, type RowSize } from "./list-row";
@@ -0,0 +1 @@
1
+ export { InfoRow, ListRow, RowList } from "./list-row";
@@ -0,0 +1,10 @@
1
+ import { type ComponentProps, type RefObject } from "react";
2
+ export declare const ROW = "[data-slot=\"list-row\"]:not([data-static]):not(:disabled)";
3
+ export declare function isRoving(list: HTMLElement): boolean;
4
+ export declare function show(glider: HTMLElement | null, row: HTMLElement | null): void;
5
+ export declare function followFocus(list: HTMLElement, row: HTMLElement): void;
6
+ export declare function targetRow(list: HTMLElement, row: HTMLElement, key: string): HTMLElement | null;
7
+ type Handlers = Pick<ComponentProps<"div">, "onPointerOver" | "onPointerLeave" | "onFocus" | "onKeyDown">;
8
+ export declare function useListHandlers(app: Handlers, list: RefObject<HTMLElement | null>, hoverGlide: RefObject<HTMLElement | null>, stop: RefObject<HTMLElement | null>): Handlers;
9
+ export declare function useListSync(list: RefObject<HTMLElement | null>, glider: RefObject<HTMLElement | null>, stop: RefObject<HTMLElement | null>): void;
10
+ export {};
@@ -0,0 +1,142 @@
1
+ import { useLayoutEffect } from "react";
2
+ /* The rows a person can reach: not static, not disabled. */
3
+ export const ROW = '[data-slot="list-row"]:not([data-static]):not(:disabled)';
4
+ const OWNER = '[data-kumiko-list-row~="roving"], [data-kumiko-list-row~="no-roving"]';
5
+ /* Roving is on unless the nearest container that says anything about it says no-roving. */
6
+ export function isRoving(list) {
7
+ const owner = list.closest(OWNER);
8
+ return owner === null || !owner.dataset.kumikoListRow?.split(" ").includes("no-roving");
9
+ }
10
+ /* Puts a glider over a row and copies the row's look onto it. */
11
+ function place(glider, row) {
12
+ const style = glider.style;
13
+ const computed = getComputedStyle(row);
14
+ const name = glider.dataset.kind === "current" ? "--_cur-bg" : "--_hover-bg";
15
+ style.setProperty("--_x", `${row.offsetLeft}px`);
16
+ style.setProperty("--_y", `${row.offsetTop}px`);
17
+ style.setProperty("--_w", `${row.offsetWidth}px`);
18
+ style.setProperty("--_h", `${row.offsetHeight}px`);
19
+ style.setProperty("--_r", computed.borderRadius);
20
+ style.setProperty("--_bg", computed.getPropertyValue(name));
21
+ style.setProperty("--_bar", computed.getPropertyValue("--_bar"));
22
+ }
23
+ /* Shows a glider at a row, or hides it. It lands without sliding the first time it appears. */
24
+ export function show(glider, row) {
25
+ if (!glider) {
26
+ return;
27
+ }
28
+ if (!row) {
29
+ delete glider.dataset.visible;
30
+ return;
31
+ }
32
+ place(glider, row);
33
+ if (!Object.hasOwn(glider.dataset, "visible")) {
34
+ void glider.offsetWidth;
35
+ glider.dataset.visible = "";
36
+ }
37
+ }
38
+ /* Gives the Tab stop to one row when the list is roving, and takes every stop back when it is not. */
39
+ function syncRoving(list, stop) {
40
+ const rows = [...list.querySelectorAll(ROW)];
41
+ if (!isRoving(list)) {
42
+ for (const row of rows) {
43
+ if (Object.hasOwn(row.dataset, "roving")) {
44
+ row.removeAttribute("tabindex");
45
+ delete row.dataset.roving;
46
+ }
47
+ }
48
+ return;
49
+ }
50
+ const kept = stop && rows.includes(stop) ? stop : null;
51
+ const marked = (name) => rows.find((row) => Object.hasOwn(row.dataset, name));
52
+ const start = kept ?? marked("current") ?? marked("selected") ?? rows[0];
53
+ for (const row of rows) {
54
+ row.dataset.roving = "";
55
+ row.tabIndex = row === start ? 0 : -1;
56
+ }
57
+ }
58
+ /* Moves the Tab stop to the row that has focus. */
59
+ export function followFocus(list, row) {
60
+ for (const other of list.querySelectorAll("[data-roving]")) {
61
+ other.tabIndex = other === row ? 0 : -1;
62
+ }
63
+ }
64
+ /* The row an arrow key or Home or End moves to, or null when the key is not one of them. */
65
+ export function targetRow(list, row, key) {
66
+ const rows = [...list.querySelectorAll(ROW)];
67
+ const last = rows.length - 1;
68
+ const at = rows.indexOf(row);
69
+ const to = new Map([
70
+ ["Home", 0],
71
+ ["End", last],
72
+ ["ArrowDown", Math.min(last, at + 1)],
73
+ ["ArrowUp", Math.max(0, at - 1)]
74
+ ]).get(key);
75
+ return to === undefined ? null : (rows[to] ?? null);
76
+ }
77
+ /* The list's own handlers: the hover wash follows the mouse, focus moves the Tab stop and the arrows move focus. Each also calls the app's handler first. */
78
+ export function useListHandlers(app, list, hoverGlide, stop) {
79
+ const rowOf = (target) => {
80
+ const row = target instanceof Element ? target.closest(ROW) : null;
81
+ return row && list.current?.contains(row) ? row : null;
82
+ };
83
+ return {
84
+ onPointerOver: (event) => {
85
+ app.onPointerOver?.(event);
86
+ if (event.pointerType === "mouse") {
87
+ show(hoverGlide.current, rowOf(event.target));
88
+ }
89
+ },
90
+ onPointerLeave: (event) => {
91
+ app.onPointerLeave?.(event);
92
+ show(hoverGlide.current, null);
93
+ },
94
+ onFocus: (event) => {
95
+ app.onFocus?.(event);
96
+ const row = rowOf(event.target);
97
+ if (row && list.current && isRoving(list.current)) {
98
+ stop.current = row;
99
+ followFocus(list.current, row);
100
+ }
101
+ },
102
+ onKeyDown: (event) => {
103
+ app.onKeyDown?.(event);
104
+ const row = rowOf(event.target);
105
+ if (!list.current || !row || event.defaultPrevented || !isRoving(list.current)) {
106
+ return;
107
+ }
108
+ const to = targetRow(list.current, row, event.key);
109
+ if (to) {
110
+ event.preventDefault();
111
+ to.focus();
112
+ }
113
+ }
114
+ };
115
+ }
116
+ /* After every render and every change of the rows: place the current glider and set the Tab stop. */
117
+ export function useListSync(list, glider, stop) {
118
+ useLayoutEffect(() => {
119
+ const element = list.current;
120
+ if (!element) {
121
+ return undefined;
122
+ }
123
+ const sync = () => {
124
+ show(glider.current, element.querySelector("[data-current]"));
125
+ syncRoving(element, stop.current);
126
+ };
127
+ sync();
128
+ const mutations = new MutationObserver(sync);
129
+ mutations.observe(element, {
130
+ subtree: true,
131
+ childList: true,
132
+ attributes: true,
133
+ attributeFilter: ["data-current", "disabled"]
134
+ });
135
+ const sizes = new ResizeObserver(sync);
136
+ sizes.observe(element);
137
+ return () => {
138
+ mutations.disconnect();
139
+ sizes.disconnect();
140
+ };
141
+ });
142
+ }