@kumix/ui 0.3.8 → 0.3.9
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 +1 -1
- package/dist/components/agents/ai-sidebar.js +3 -5
- package/dist/components/agents/ai-sidebar.js.map +1 -1
- package/dist/components/motion/combobox/content.js +1 -1
- package/dist/components/motion/combobox/context.d.ts +6 -0
- package/dist/components/motion/combobox/context.d.ts.map +1 -1
- package/dist/components/motion/combobox/context.js +1 -233
- package/dist/components/motion/combobox/list.js +1 -1
- package/dist/components/motion/combobox/trigger.js +7 -8
- package/dist/components/motion/combobox/trigger.js.map +1 -1
- package/dist/components/motion/combobox.js +1 -1
- package/dist/components/motion/command-palette.d.ts.map +1 -1
- package/dist/components/motion/command-palette.js +21 -26
- package/dist/components/motion/command-palette.js.map +1 -1
- package/dist/components/motion/morphing-search.d.ts.map +1 -1
- package/dist/components/motion/morphing-search.js +27 -23
- package/dist/components/motion/morphing-search.js.map +1 -1
- package/dist/components/reui/alert.d.ts +1 -1
- package/dist/components/reui/badge.d.ts +1 -1
- package/dist/components/reui/filters/filters-builder.js +1 -1
- package/dist/components/reui/filters/filters-chip.js.map +1 -1
- package/dist/components/reui/filters/filters-editors.js +2 -2
- package/dist/components/reui/filters/filters-editors.js.map +1 -1
- package/dist/components/reui/frame.d.ts +1 -1
- package/dist/components/ui/attachment.d.ts +1 -1
- package/dist/components/ui/badge.d.ts +1 -1
- package/dist/components/ui/bubble.d.ts +1 -1
- package/dist/components/ui/button-group.d.ts +1 -1
- package/dist/components/ui/button.d.ts +1 -1
- package/dist/components/ui/field.d.ts +1 -1
- package/dist/components/ui/item.d.ts +1 -1
- package/dist/components/ui/sidebar.d.ts +1 -1
- package/dist/components/ui/toggle.d.ts +1 -1
- package/dist/context-BizvUNZv.js +298 -0
- package/dist/context-BizvUNZv.js.map +1 -0
- package/dist/hooks/use-on-open.d.ts +18 -0
- package/dist/hooks/use-on-open.d.ts.map +1 -0
- package/dist/hooks/use-on-open.js +27 -0
- package/dist/hooks/use-on-open.js.map +1 -0
- package/dist/hooks/use-row-cursor.d.ts +39 -0
- package/dist/hooks/use-row-cursor.d.ts.map +1 -0
- package/dist/hooks/use-row-cursor.js +77 -0
- package/dist/hooks/use-row-cursor.js.map +1 -0
- package/package.json +3 -3
- package/dist/components/motion/combobox/context.js.map +0 -1
|
@@ -13,7 +13,7 @@ import { VariantProps } from "class-variance-authority";
|
|
|
13
13
|
* :not() or !important needed
|
|
14
14
|
*/
|
|
15
15
|
declare const frameVariants: (props?: ({
|
|
16
|
-
variant?: "
|
|
16
|
+
variant?: "ghost" | "default" | "inverse" | null | undefined;
|
|
17
17
|
spacing?: "default" | "sm" | "lg" | "xs" | null | undefined;
|
|
18
18
|
stacked?: boolean | null | undefined;
|
|
19
19
|
dense?: boolean | null | undefined;
|
|
@@ -5,7 +5,7 @@ import { useRender } from "@base-ui/react/use-render";
|
|
|
5
5
|
//#region src/components/ui/attachment.d.ts
|
|
6
6
|
declare const attachmentVariants: (props?: ({
|
|
7
7
|
size?: "default" | "sm" | "xs" | null | undefined;
|
|
8
|
-
orientation?: "
|
|
8
|
+
orientation?: "vertical" | "horizontal" | null | undefined;
|
|
9
9
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
10
10
|
declare function Attachment({ className, state, size, orientation, ...props }: React$1.ComponentProps<"div"> & VariantProps<typeof attachmentVariants> & {
|
|
11
11
|
state?: "idle" | "uploading" | "processing" | "error" | "done";
|
|
@@ -2,7 +2,7 @@ import { VariantProps } from "class-variance-authority";
|
|
|
2
2
|
import { useRender } from "@base-ui/react/use-render";
|
|
3
3
|
//#region src/components/ui/badge.d.ts
|
|
4
4
|
declare const badgeVariants: (props?: ({
|
|
5
|
-
variant?: "
|
|
5
|
+
variant?: "ghost" | "outline" | "secondary" | "default" | "link" | "destructive" | null | undefined;
|
|
6
6
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
7
7
|
declare function Badge({ className, variant, render, ...props }: useRender.ComponentProps<"span"> & VariantProps<typeof badgeVariants>): import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
8
8
|
//#endregion
|
|
@@ -4,7 +4,7 @@ import { useRender } from "@base-ui/react/use-render";
|
|
|
4
4
|
//#region src/components/ui/bubble.d.ts
|
|
5
5
|
declare function BubbleGroup({ className, ...props }: React$1.ComponentProps<"div">): React$1.JSX.Element;
|
|
6
6
|
declare const bubbleVariants: (props?: ({
|
|
7
|
-
variant?: "
|
|
7
|
+
variant?: "ghost" | "outline" | "secondary" | "default" | "destructive" | "muted" | "tinted" | null | undefined;
|
|
8
8
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
9
9
|
declare function Bubble({ variant, align, className, ...props }: React$1.ComponentProps<"div"> & VariantProps<typeof bubbleVariants> & {
|
|
10
10
|
align?: "start" | "end";
|
|
@@ -3,7 +3,7 @@ import { VariantProps } from "class-variance-authority";
|
|
|
3
3
|
import { useRender } from "@base-ui/react/use-render";
|
|
4
4
|
//#region src/components/ui/button-group.d.ts
|
|
5
5
|
declare const buttonGroupVariants: (props?: ({
|
|
6
|
-
orientation?: "
|
|
6
|
+
orientation?: "vertical" | "horizontal" | null | undefined;
|
|
7
7
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
8
8
|
declare function ButtonGroup({ className, orientation, ...props }: React.ComponentProps<"div"> & VariantProps<typeof buttonGroupVariants>): import("react").JSX.Element;
|
|
9
9
|
declare function ButtonGroupText({ className, render, ...props }: useRender.ComponentProps<"div">): import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
@@ -2,7 +2,7 @@ import { Button as Button$1 } from "@base-ui/react/button";
|
|
|
2
2
|
import { VariantProps } from "class-variance-authority";
|
|
3
3
|
//#region src/components/ui/button.d.ts
|
|
4
4
|
declare const buttonVariants: (props?: ({
|
|
5
|
-
variant?: "
|
|
5
|
+
variant?: "ghost" | "outline" | "secondary" | "default" | "link" | "destructive" | null | undefined;
|
|
6
6
|
size?: "default" | "sm" | "lg" | "xs" | "icon" | "icon-xs" | "icon-sm" | "icon-lg" | null | undefined;
|
|
7
7
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
8
8
|
declare function Button({ className, variant, size, ...props }: Button$1.Props & VariantProps<typeof buttonVariants>): import("react").JSX.Element;
|
|
@@ -7,7 +7,7 @@ declare function FieldLegend({ className, variant, ...props }: React.ComponentPr
|
|
|
7
7
|
}): import("react").JSX.Element;
|
|
8
8
|
declare function FieldGroup({ className, ...props }: React.ComponentProps<"div">): import("react").JSX.Element;
|
|
9
9
|
declare const fieldVariants: (props?: ({
|
|
10
|
-
orientation?: "
|
|
10
|
+
orientation?: "vertical" | "horizontal" | "responsive" | null | undefined;
|
|
11
11
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
12
12
|
declare function Field({ className, orientation, ...props }: React.ComponentProps<"div"> & VariantProps<typeof fieldVariants>): import("react").JSX.Element;
|
|
13
13
|
declare function FieldContent({ className, ...props }: React.ComponentProps<"div">): import("react").JSX.Element;
|
|
@@ -6,7 +6,7 @@ import { useRender } from "@base-ui/react/use-render";
|
|
|
6
6
|
declare function ItemGroup({ className, ...props }: React$1.ComponentProps<"div">): React$1.JSX.Element;
|
|
7
7
|
declare function ItemSeparator({ className, ...props }: React$1.ComponentProps<typeof Separator>): React$1.JSX.Element;
|
|
8
8
|
declare const itemVariants: (props?: ({
|
|
9
|
-
variant?: "
|
|
9
|
+
variant?: "outline" | "default" | "muted" | null | undefined;
|
|
10
10
|
size?: "default" | "sm" | "xs" | null | undefined;
|
|
11
11
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
12
12
|
declare function Item({ className, variant, size, render, ...props }: useRender.ComponentProps<"div"> & VariantProps<typeof itemVariants>): React$1.ReactElement<unknown, string | React$1.JSXElementConstructor<any>>;
|
|
@@ -41,7 +41,7 @@ declare function SidebarGroupContent({ className, ...props }: React$1.ComponentP
|
|
|
41
41
|
declare function SidebarMenu({ className, ...props }: React$1.ComponentProps<"ul">): React$1.JSX.Element;
|
|
42
42
|
declare function SidebarMenuItem({ className, ...props }: React$1.ComponentProps<"li">): React$1.JSX.Element;
|
|
43
43
|
declare const sidebarMenuButtonVariants: (props?: ({
|
|
44
|
-
variant?: "
|
|
44
|
+
variant?: "outline" | "default" | null | undefined;
|
|
45
45
|
size?: "default" | "sm" | "lg" | null | undefined;
|
|
46
46
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
47
47
|
declare function SidebarMenuButton({ render, isActive, variant, size, tooltip, className, ...props }: useRender.ComponentProps<"button"> & React$1.ComponentProps<"button"> & {
|
|
@@ -2,7 +2,7 @@ import { VariantProps } from "class-variance-authority";
|
|
|
2
2
|
import { Toggle as Toggle$1 } from "@base-ui/react/toggle";
|
|
3
3
|
//#region src/components/ui/toggle.d.ts
|
|
4
4
|
declare const toggleVariants: (props?: ({
|
|
5
|
-
variant?: "
|
|
5
|
+
variant?: "outline" | "default" | null | undefined;
|
|
6
6
|
size?: "default" | "sm" | "lg" | null | undefined;
|
|
7
7
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
8
8
|
declare function Toggle({ className, variant, size, ...props }: Toggle$1.Props & VariantProps<typeof toggleVariants>): import("react").JSX.Element;
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import { createContext, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
import { cn } from "@kumix/utils";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
import { useReducedMotion } from "motion/react";
|
|
5
|
+
//#region src/components/motion/combobox/use-active-option.ts
|
|
6
|
+
const isEnabled = (enabledItems, candidate) => candidate !== void 0 && enabledItems.some((i) => i.value === candidate);
|
|
7
|
+
/**
|
|
8
|
+
* The cursor's option, or null once the query or the result set it was placed
|
|
9
|
+
* in has changed. A cursor that outlived either would steal Enter from the row
|
|
10
|
+
* the user is aiming at. The result-set half costs something: a live search
|
|
11
|
+
* that blanks its rows while fetching and returns the same ones loses the moved
|
|
12
|
+
* highlight. That is deliberate — a highlight visibly back at the top beats one
|
|
13
|
+
* silently in the wrong place.
|
|
14
|
+
*
|
|
15
|
+
* It is stamped with the query rather than with the identity of the visible
|
|
16
|
+
* list because callers routinely pass an inline `filter`, which makes that list
|
|
17
|
+
* a fresh array on every render.
|
|
18
|
+
*/
|
|
19
|
+
function liveCursorValue(cursor, options) {
|
|
20
|
+
if (cursor === null || cursor.query !== options.query) return null;
|
|
21
|
+
return isEnabled(options.enabledItems, cursor.value) ? cursor.value : null;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Where the highlight sits with no live cursor: the selection if it can be
|
|
25
|
+
* selected, otherwise the first option that can. Only enabled options qualify —
|
|
26
|
+
* an active disabled option would point `aria-activedescendant` at a row Enter
|
|
27
|
+
* then refuses to select.
|
|
28
|
+
*/
|
|
29
|
+
function fallbackActive({ value, enabledItems }) {
|
|
30
|
+
return isEnabled(enabledItems, value) ? value : enabledItems[0]?.value ?? null;
|
|
31
|
+
}
|
|
32
|
+
/** The active option, from a cursor that may or may not still be live. */
|
|
33
|
+
const resolveActive = (cursor, options) => liveCursorValue(cursor, options) ?? fallbackActive(options);
|
|
34
|
+
function useActiveOption({ open, ...options }) {
|
|
35
|
+
const { query, value, enabledItems } = options;
|
|
36
|
+
const [cursor, setCursor] = useState(null);
|
|
37
|
+
const live = liveCursorValue(cursor, options);
|
|
38
|
+
if (cursor !== null && live === null) setCursor(null);
|
|
39
|
+
const derived = live ?? fallbackActive(options);
|
|
40
|
+
const [opened, setOpened] = useState(open);
|
|
41
|
+
if (open && !opened) setOpened(true);
|
|
42
|
+
const activeValue = opened ? derived : null;
|
|
43
|
+
const latest = useRef({
|
|
44
|
+
open,
|
|
45
|
+
query,
|
|
46
|
+
value,
|
|
47
|
+
enabledItems
|
|
48
|
+
});
|
|
49
|
+
useLayoutEffect(() => {
|
|
50
|
+
latest.current = {
|
|
51
|
+
open,
|
|
52
|
+
query,
|
|
53
|
+
value,
|
|
54
|
+
enabledItems
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
return {
|
|
58
|
+
activeValue,
|
|
59
|
+
setActiveValue: useCallback((next) => {
|
|
60
|
+
setCursor(next === null ? null : {
|
|
61
|
+
value: next,
|
|
62
|
+
query: latest.current.query
|
|
63
|
+
});
|
|
64
|
+
}, []),
|
|
65
|
+
moveActive: useCallback((direction) => {
|
|
66
|
+
const options = latest.current;
|
|
67
|
+
if (!options.open) return;
|
|
68
|
+
const rows = options.enabledItems;
|
|
69
|
+
const last = rows.length - 1;
|
|
70
|
+
if (last < 0) {
|
|
71
|
+
setCursor(null);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
setCursor((current) => {
|
|
75
|
+
const from = resolveActive(current, options);
|
|
76
|
+
const at = rows.findIndex((item) => item.value === from);
|
|
77
|
+
const index = direction === "first" ? 0 : direction === "last" ? last : (at + direction + rows.length) % rows.length;
|
|
78
|
+
return {
|
|
79
|
+
value: rows[index].value,
|
|
80
|
+
query: options.query
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
}, [])
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/components/motion/combobox/context.tsx
|
|
88
|
+
const defaultFilter = (value, query, keywords) => {
|
|
89
|
+
const needle = query.trim().toLocaleLowerCase();
|
|
90
|
+
if (!needle) return true;
|
|
91
|
+
const haystack = [value, ...keywords].join(" ").toLocaleLowerCase();
|
|
92
|
+
let queryIndex = 0;
|
|
93
|
+
for (const character of haystack) {
|
|
94
|
+
if (character === needle[queryIndex]) queryIndex += 1;
|
|
95
|
+
if (queryIndex === needle.length) return true;
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
};
|
|
99
|
+
const ComboboxContext = createContext(null);
|
|
100
|
+
const ComboboxGroupContext = createContext(null);
|
|
101
|
+
function useComboboxContext(component) {
|
|
102
|
+
const context = useContext(ComboboxContext);
|
|
103
|
+
if (!context) throw new Error(`${component} must be used within <Combobox>`);
|
|
104
|
+
return context;
|
|
105
|
+
}
|
|
106
|
+
function mergeRefs(...refs) {
|
|
107
|
+
return (node) => {
|
|
108
|
+
for (const ref of refs) if (typeof ref === "function") ref(node);
|
|
109
|
+
else if (ref && typeof ref === "object") ref.current = node;
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function Combobox({ children, value: controlledValue, defaultValue, onValueChange, open: controlledOpen, defaultOpen = false, onOpenChange, query: controlledQuery, defaultQuery = "", onQueryChange, filter = defaultFilter, disabled = false, className }) {
|
|
113
|
+
const reduce = useReducedMotion() ?? false;
|
|
114
|
+
const baseId = useId();
|
|
115
|
+
const rootRef = useRef(null);
|
|
116
|
+
const triggerRef = useRef(null);
|
|
117
|
+
const contentRef = useRef(null);
|
|
118
|
+
const inputRef = useRef(null);
|
|
119
|
+
const [internalValue, setInternalValue] = useState(defaultValue);
|
|
120
|
+
const [internalOpen, setInternalOpen] = useState(defaultOpen);
|
|
121
|
+
const [internalQuery, setInternalQuery] = useState(defaultQuery);
|
|
122
|
+
const [items, setItems] = useState(/* @__PURE__ */ new Map());
|
|
123
|
+
const valueControlled = controlledValue !== void 0;
|
|
124
|
+
const openControlled = controlledOpen !== void 0;
|
|
125
|
+
const queryControlled = controlledQuery !== void 0;
|
|
126
|
+
const value = valueControlled ? controlledValue : internalValue;
|
|
127
|
+
const open = openControlled ? controlledOpen : internalOpen;
|
|
128
|
+
const query = queryControlled ? controlledQuery : internalQuery;
|
|
129
|
+
const updateQuery = useCallback((next) => {
|
|
130
|
+
if (!queryControlled) setInternalQuery(next);
|
|
131
|
+
onQueryChange?.(next);
|
|
132
|
+
}, [onQueryChange, queryControlled]);
|
|
133
|
+
const updateOpen = useCallback((next, restoreFocus = false) => {
|
|
134
|
+
if (disabled && next) return;
|
|
135
|
+
if (!openControlled) setInternalOpen(next);
|
|
136
|
+
onOpenChange?.(next);
|
|
137
|
+
if (!next) updateQuery("");
|
|
138
|
+
if (restoreFocus) requestAnimationFrame(() => inputRef.current?.focus({ preventScroll: true }));
|
|
139
|
+
}, [
|
|
140
|
+
disabled,
|
|
141
|
+
onOpenChange,
|
|
142
|
+
openControlled,
|
|
143
|
+
updateQuery
|
|
144
|
+
]);
|
|
145
|
+
const registerItem = useCallback((item) => {
|
|
146
|
+
setItems((current) => {
|
|
147
|
+
const existing = current.get(item.value);
|
|
148
|
+
if (existing?.label === item.label && existing.disabled === item.disabled && existing.id === item.id && existing.ref === item.ref && existing.groupId === item.groupId && existing.keywords.join("\0") === item.keywords.join("\0")) return current;
|
|
149
|
+
const next = new Map(current);
|
|
150
|
+
next.set(item.value, item);
|
|
151
|
+
return next;
|
|
152
|
+
});
|
|
153
|
+
}, []);
|
|
154
|
+
const unregisterItem = useCallback((itemValue) => {
|
|
155
|
+
setItems((current) => {
|
|
156
|
+
if (!current.has(itemValue)) return current;
|
|
157
|
+
const next = new Map(current);
|
|
158
|
+
next.delete(itemValue);
|
|
159
|
+
return next;
|
|
160
|
+
});
|
|
161
|
+
}, []);
|
|
162
|
+
const [openQuery, setOpenQuery] = useState(query);
|
|
163
|
+
if (open && openQuery !== query) setOpenQuery(query);
|
|
164
|
+
const listQuery = open ? query : openQuery;
|
|
165
|
+
const visibleItems = useMemo(() => Array.from(items.values()).filter((item) => filter(item.value, listQuery, [item.label, ...item.keywords])), [
|
|
166
|
+
filter,
|
|
167
|
+
items,
|
|
168
|
+
listQuery
|
|
169
|
+
]);
|
|
170
|
+
const enabledVisibleItems = useMemo(() => visibleItems.filter((item) => !item.disabled), [visibleItems]);
|
|
171
|
+
const visibleValues = useMemo(() => new Set(visibleItems.map((item) => item.value)), [visibleItems]);
|
|
172
|
+
const visibleGroupIds = useMemo(() => new Set(visibleItems.map((item) => item.groupId)), [visibleItems]);
|
|
173
|
+
const { activeValue, setActiveValue, moveActive } = useActiveOption({
|
|
174
|
+
open,
|
|
175
|
+
query: listQuery,
|
|
176
|
+
value,
|
|
177
|
+
enabledItems: enabledVisibleItems
|
|
178
|
+
});
|
|
179
|
+
const select = useCallback((next) => {
|
|
180
|
+
if (items.get(next)?.disabled) return;
|
|
181
|
+
if (!valueControlled) setInternalValue(next);
|
|
182
|
+
onValueChange?.(next);
|
|
183
|
+
updateOpen(false, true);
|
|
184
|
+
}, [
|
|
185
|
+
items,
|
|
186
|
+
onValueChange,
|
|
187
|
+
updateOpen,
|
|
188
|
+
valueControlled
|
|
189
|
+
]);
|
|
190
|
+
const selectActive = useCallback(() => {
|
|
191
|
+
if (activeValue) select(activeValue);
|
|
192
|
+
}, [activeValue, select]);
|
|
193
|
+
useEffect(() => {
|
|
194
|
+
if (!open) return;
|
|
195
|
+
const frame = requestAnimationFrame(() => inputRef.current?.focus({ preventScroll: true }));
|
|
196
|
+
return () => cancelAnimationFrame(frame);
|
|
197
|
+
}, [open]);
|
|
198
|
+
useEffect(() => {
|
|
199
|
+
if (!activeValue || !open) return;
|
|
200
|
+
const item = items.get(activeValue)?.ref.current;
|
|
201
|
+
const list = item?.closest("[role='listbox']");
|
|
202
|
+
if (!item || !list) return;
|
|
203
|
+
const itemRect = item.getBoundingClientRect();
|
|
204
|
+
const listRect = list.getBoundingClientRect();
|
|
205
|
+
if (itemRect.top < listRect.top) list.scrollTop -= listRect.top - itemRect.top;
|
|
206
|
+
else if (itemRect.bottom > listRect.bottom) list.scrollTop += itemRect.bottom - listRect.bottom;
|
|
207
|
+
}, [
|
|
208
|
+
activeValue,
|
|
209
|
+
items,
|
|
210
|
+
open
|
|
211
|
+
]);
|
|
212
|
+
useEffect(() => {
|
|
213
|
+
if (!open) return;
|
|
214
|
+
const isInside = (target) => rootRef.current?.contains(target) || contentRef.current?.contains(target);
|
|
215
|
+
const onPointerDown = (event) => {
|
|
216
|
+
if (!isInside(event.target)) updateOpen(false);
|
|
217
|
+
};
|
|
218
|
+
const onFocusIn = (event) => {
|
|
219
|
+
if (!isInside(event.target)) updateOpen(false);
|
|
220
|
+
};
|
|
221
|
+
const onKeyDown = (event) => {
|
|
222
|
+
if (event.key !== "Escape") return;
|
|
223
|
+
event.preventDefault();
|
|
224
|
+
updateOpen(false, true);
|
|
225
|
+
};
|
|
226
|
+
window.addEventListener("pointerdown", onPointerDown);
|
|
227
|
+
window.addEventListener("focusin", onFocusIn);
|
|
228
|
+
window.addEventListener("keydown", onKeyDown);
|
|
229
|
+
return () => {
|
|
230
|
+
window.removeEventListener("pointerdown", onPointerDown);
|
|
231
|
+
window.removeEventListener("focusin", onFocusIn);
|
|
232
|
+
window.removeEventListener("keydown", onKeyDown);
|
|
233
|
+
};
|
|
234
|
+
}, [open, updateOpen]);
|
|
235
|
+
const activeItem = activeValue ? items.get(activeValue) : void 0;
|
|
236
|
+
const context = useMemo(() => ({
|
|
237
|
+
open,
|
|
238
|
+
setOpen: updateOpen,
|
|
239
|
+
value,
|
|
240
|
+
select,
|
|
241
|
+
query,
|
|
242
|
+
setQuery: updateQuery,
|
|
243
|
+
activeValue,
|
|
244
|
+
setActiveValue,
|
|
245
|
+
moveActive,
|
|
246
|
+
selectActive,
|
|
247
|
+
registerItem,
|
|
248
|
+
unregisterItem,
|
|
249
|
+
labelFor: (itemValue) => itemValue === void 0 ? void 0 : items.get(itemValue)?.label,
|
|
250
|
+
isVisible: (itemValue) => !listQuery.trim() || visibleValues.has(itemValue),
|
|
251
|
+
hasVisibleItems: (groupId) => visibleGroupIds.has(groupId),
|
|
252
|
+
visibleCount: visibleItems.length,
|
|
253
|
+
activeItemId: activeItem?.id,
|
|
254
|
+
triggerId: `${baseId}-trigger`,
|
|
255
|
+
listId: `${baseId}-list`,
|
|
256
|
+
inputId: `${baseId}-input`,
|
|
257
|
+
disabled,
|
|
258
|
+
reduce,
|
|
259
|
+
triggerRef,
|
|
260
|
+
contentRef,
|
|
261
|
+
inputRef,
|
|
262
|
+
activeLayoutId: `${baseId}-active`
|
|
263
|
+
}), [
|
|
264
|
+
activeItem?.id,
|
|
265
|
+
activeValue,
|
|
266
|
+
baseId,
|
|
267
|
+
disabled,
|
|
268
|
+
items,
|
|
269
|
+
listQuery,
|
|
270
|
+
moveActive,
|
|
271
|
+
open,
|
|
272
|
+
query,
|
|
273
|
+
reduce,
|
|
274
|
+
registerItem,
|
|
275
|
+
select,
|
|
276
|
+
selectActive,
|
|
277
|
+
setActiveValue,
|
|
278
|
+
unregisterItem,
|
|
279
|
+
updateOpen,
|
|
280
|
+
updateQuery,
|
|
281
|
+
value,
|
|
282
|
+
visibleItems.length,
|
|
283
|
+
visibleGroupIds,
|
|
284
|
+
visibleValues
|
|
285
|
+
]);
|
|
286
|
+
return /* @__PURE__ */ jsx(ComboboxContext.Provider, {
|
|
287
|
+
value: context,
|
|
288
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
289
|
+
ref: rootRef,
|
|
290
|
+
className: cn("relative w-full", className),
|
|
291
|
+
children
|
|
292
|
+
})
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
//#endregion
|
|
296
|
+
export { useComboboxContext as a, mergeRefs as i, ComboboxContext as n, ComboboxGroupContext as r, Combobox as t };
|
|
297
|
+
|
|
298
|
+
//# sourceMappingURL=context-BizvUNZv.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-BizvUNZv.js","names":[],"sources":["../src/components/motion/combobox/use-active-option.ts","../src/components/motion/combobox/context.tsx"],"sourcesContent":["\"use client\";\n\nimport { useCallback, useLayoutEffect, useRef, useState } from \"react\";\n\n/**\n * Where the keyboard or the pointer last moved to, stamped with the query it\n * was placed under. Which option is *active* is resolved from this during\n * render, never in an effect: a passive effect runs after the commit, so a list\n * would briefly have none of its options active, and a key arriving in that\n * window would move from nowhere onto the row it was already about to\n * highlight.\n */\ntype ActiveCursor = { value: string; query: string };\n\ntype Options = {\n query: string;\n value: string | undefined;\n /** The enabled, visible options in list order — all this hook reads of them. */\n enabledItems: readonly { value: string }[];\n};\n\nconst isEnabled = (\n enabledItems: Options[\"enabledItems\"],\n candidate: string | undefined,\n): candidate is string =>\n candidate !== undefined && enabledItems.some((i) => i.value === candidate);\n\n/**\n * The cursor's option, or null once the query or the result set it was placed\n * in has changed. A cursor that outlived either would steal Enter from the row\n * the user is aiming at. The result-set half costs something: a live search\n * that blanks its rows while fetching and returns the same ones loses the moved\n * highlight. That is deliberate — a highlight visibly back at the top beats one\n * silently in the wrong place.\n *\n * It is stamped with the query rather than with the identity of the visible\n * list because callers routinely pass an inline `filter`, which makes that list\n * a fresh array on every render.\n */\nfunction liveCursorValue(cursor: ActiveCursor | null, options: Options) {\n if (cursor === null || cursor.query !== options.query) return null;\n return isEnabled(options.enabledItems, cursor.value) ? cursor.value : null;\n}\n\n/**\n * Where the highlight sits with no live cursor: the selection if it can be\n * selected, otherwise the first option that can. Only enabled options qualify —\n * an active disabled option would point `aria-activedescendant` at a row Enter\n * then refuses to select.\n */\nfunction fallbackActive({ value, enabledItems }: Options) {\n return isEnabled(enabledItems, value) ? value : (enabledItems[0]?.value ?? null);\n}\n\n/** The active option, from a cursor that may or may not still be live. */\nconst resolveActive = (cursor: ActiveCursor | null, options: Options) =>\n liveCursorValue(cursor, options) ?? fallbackActive(options);\n\nexport function useActiveOption({ open, ...options }: Options & { open: boolean }) {\n const { query, value, enabledItems } = options;\n const [cursor, setCursor] = useState<ActiveCursor | null>(null);\n\n const live = liveCursorValue(cursor, options);\n // Cleared rather than ignored: React re-runs this render with the cursor\n // gone, so a value that reappears later cannot revive it.\n if (cursor !== null && live === null) setCursor(null);\n const derived = live ?? fallbackActive(options);\n\n // Nothing is active until the list has been opened once. After that the\n // resolution above is already stable across a close — the list keeps\n // filtering by the query it was open with — so the highlight holds its row\n // through the exit without being frozen separately.\n const [opened, setOpened] = useState(open);\n if (open && !opened) setOpened(true);\n const activeValue = opened ? derived : null;\n\n // Both callbacks keep one identity for the life of the component, and read\n // the list through a ref to do it. A caller will put them in a `useMemo` or\n // an effect's dependencies — the exhaustive-deps rule makes it — and\n // `enabledItems` is a fresh array on every render for any consumer passing an\n // inline `filter`, so a callback keyed to it would be rebuilt every render.\n // Written after commit rather than during render: a render React discards\n // still runs the component body, and a handler reading this in that window\n // would step against a list the committed tree does not have.\n const latest = useRef({ open, query, value, enabledItems });\n useLayoutEffect(() => {\n latest.current = { open, query, value, enabledItems };\n });\n\n const setActiveValue = useCallback((next: string | null) => {\n setCursor(next === null ? null : { value: next, query: latest.current.query });\n }, []);\n\n // Steps from the option the cursor really resolves to, inside the update, so\n // that two keys landing in one batch move two rows rather than one.\n const moveActive = useCallback((direction: 1 | -1 | \"first\" | \"last\") => {\n const options = latest.current;\n // While closed the list is still filtering by the query it was open\n // with, so a step taken now would be measured against rows the next\n // render replaces. Opening is the caller's job; stepping waits for it.\n if (!options.open) return;\n const rows = options.enabledItems;\n const last = rows.length - 1;\n if (last < 0) {\n setCursor(null);\n return;\n }\n setCursor((current) => {\n // `resolveActive` always lands on a member of `enabledItems` once the\n // list is non-empty, which the early return above guarantees, so there\n // is always a row to step from.\n const from = resolveActive(current, options);\n const at = rows.findIndex((item) => item.value === from);\n const index =\n direction === \"first\"\n ? 0\n : direction === \"last\"\n ? last\n : (at + direction + rows.length) % rows.length;\n return { value: rows[index].value, query: options.query };\n });\n }, []);\n\n return { activeValue, setActiveValue, moveActive };\n}\n","\"use client\";\n\nimport {\n createContext,\n type MutableRefObject,\n type ReactNode,\n type Ref,\n useCallback,\n useContext,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { useReducedMotion } from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { useActiveOption } from \"./use-active-option\";\n\nexport type RegisteredItem = {\n value: string;\n label: string;\n keywords: string[];\n disabled: boolean;\n groupId: string | null;\n id: string;\n ref: MutableRefObject<HTMLButtonElement | null>;\n};\n\nexport type ComboboxFilter = (value: string, query: string, keywords: string[]) => boolean;\n\nconst defaultFilter: ComboboxFilter = (value, query, keywords) => {\n const needle = query.trim().toLocaleLowerCase();\n if (!needle) return true;\n\n const haystack = [value, ...keywords].join(\" \").toLocaleLowerCase();\n let queryIndex = 0;\n for (const character of haystack) {\n if (character === needle[queryIndex]) queryIndex += 1;\n if (queryIndex === needle.length) return true;\n }\n return false;\n};\n\nexport type ComboboxContextValue = {\n open: boolean;\n setOpen: (open: boolean, restoreFocus?: boolean) => void;\n value: string | undefined;\n select: (value: string) => void;\n query: string;\n setQuery: (query: string) => void;\n /** The option the list is currently pointing at, resolved during render. */\n activeValue: string | null;\n /**\n * Records where the pointer or keyboard moved to. The recorded value is\n * dropped when the query or the result set changes, so it does not always\n * survive to the next `activeValue`.\n */\n setActiveValue: (value: string | null) => void;\n moveActive: (direction: 1 | -1 | \"first\" | \"last\") => void;\n selectActive: () => void;\n registerItem: (item: RegisteredItem) => void;\n unregisterItem: (value: string) => void;\n labelFor: (value: string | undefined) => string | undefined;\n isVisible: (value: string) => boolean;\n hasVisibleItems: (groupId: string) => boolean;\n visibleCount: number;\n activeItemId: string | undefined;\n triggerId: string;\n listId: string;\n inputId: string;\n disabled: boolean;\n reduce: boolean;\n triggerRef: MutableRefObject<HTMLDivElement | null>;\n contentRef: MutableRefObject<HTMLDivElement | null>;\n inputRef: MutableRefObject<HTMLInputElement | null>;\n activeLayoutId: string;\n};\n\nexport const ComboboxContext = createContext<ComboboxContextValue | null>(null);\nexport const ComboboxGroupContext = createContext<string | null>(null);\n\nexport function useComboboxContext(component: string) {\n const context = useContext(ComboboxContext);\n if (!context) throw new Error(`${component} must be used within <Combobox>`);\n return context;\n}\n\nexport function mergeRefs<T>(...refs: Array<Ref<T> | undefined>) {\n return (node: T | null) => {\n for (const ref of refs) {\n if (typeof ref === \"function\") ref(node);\n else if (ref && typeof ref === \"object\") (ref as MutableRefObject<T | null>).current = node;\n }\n };\n}\n\nexport interface ComboboxProps {\n children: ReactNode;\n value?: string;\n defaultValue?: string;\n onValueChange?: (value: string) => void;\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n query?: string;\n defaultQuery?: string;\n onQueryChange?: (query: string) => void;\n filter?: ComboboxFilter;\n disabled?: boolean;\n className?: string;\n}\n\nexport function Combobox({\n children,\n value: controlledValue,\n defaultValue,\n onValueChange,\n open: controlledOpen,\n defaultOpen = false,\n onOpenChange,\n query: controlledQuery,\n defaultQuery = \"\",\n onQueryChange,\n filter = defaultFilter,\n disabled = false,\n className,\n}: ComboboxProps) {\n const reduce = useReducedMotion() ?? false;\n const baseId = useId();\n const rootRef = useRef<HTMLDivElement>(null);\n const triggerRef = useRef<HTMLDivElement>(null);\n const contentRef = useRef<HTMLDivElement>(null);\n const inputRef = useRef<HTMLInputElement>(null);\n const [internalValue, setInternalValue] = useState(defaultValue);\n const [internalOpen, setInternalOpen] = useState(defaultOpen);\n const [internalQuery, setInternalQuery] = useState(defaultQuery);\n const [items, setItems] = useState<Map<string, RegisteredItem>>(new Map());\n\n const valueControlled = controlledValue !== undefined;\n const openControlled = controlledOpen !== undefined;\n const queryControlled = controlledQuery !== undefined;\n const value = valueControlled ? controlledValue : internalValue;\n const open = openControlled ? controlledOpen : internalOpen;\n const query = queryControlled ? controlledQuery : internalQuery;\n\n const updateQuery = useCallback(\n (next: string) => {\n if (!queryControlled) setInternalQuery(next);\n onQueryChange?.(next);\n },\n [onQueryChange, queryControlled],\n );\n\n const updateOpen = useCallback(\n (next: boolean, restoreFocus = false) => {\n if (disabled && next) return;\n if (!openControlled) setInternalOpen(next);\n onOpenChange?.(next);\n if (!next) updateQuery(\"\");\n if (restoreFocus)\n requestAnimationFrame(() => inputRef.current?.focus({ preventScroll: true }));\n },\n [disabled, onOpenChange, openControlled, updateQuery],\n );\n\n const registerItem = useCallback((item: RegisteredItem) => {\n setItems((current) => {\n const existing = current.get(item.value);\n if (\n existing?.label === item.label &&\n existing.disabled === item.disabled &&\n existing.id === item.id &&\n existing.ref === item.ref &&\n existing.groupId === item.groupId &&\n existing.keywords.join(\"\\u0000\") === item.keywords.join(\"\\u0000\")\n ) {\n return current;\n }\n const next = new Map(current);\n next.set(item.value, item);\n return next;\n });\n }, []);\n\n const unregisterItem = useCallback((itemValue: string) => {\n setItems((current) => {\n if (!current.has(itemValue)) return current;\n const next = new Map(current);\n next.delete(itemValue);\n return next;\n });\n }, []);\n\n // The query the list filters by. Closing clears `query`, but the panel is\n // still on screen for its exit, so it keeps filtering by the query it was\n // open with rather than repopulating mid-collapse. The input already reads\n // `query` only while open, so nothing the user can see reads the other one.\n const [openQuery, setOpenQuery] = useState(query);\n if (open && openQuery !== query) setOpenQuery(query);\n const listQuery = open ? query : openQuery;\n\n const visibleItems = useMemo(\n () =>\n Array.from(items.values()).filter((item) =>\n filter(item.value, listQuery, [item.label, ...item.keywords]),\n ),\n [filter, items, listQuery],\n );\n const enabledVisibleItems = useMemo(\n () => visibleItems.filter((item) => !item.disabled),\n [visibleItems],\n );\n const visibleValues = useMemo(\n () => new Set(visibleItems.map((item) => item.value)),\n [visibleItems],\n );\n const visibleGroupIds = useMemo(\n () => new Set(visibleItems.map((item) => item.groupId)),\n [visibleItems],\n );\n\n const { activeValue, setActiveValue, moveActive } = useActiveOption({\n open,\n query: listQuery,\n value,\n enabledItems: enabledVisibleItems,\n });\n\n const select = useCallback(\n (next: string) => {\n if (items.get(next)?.disabled) return;\n if (!valueControlled) setInternalValue(next);\n onValueChange?.(next);\n updateOpen(false, true);\n },\n [items, onValueChange, updateOpen, valueControlled],\n );\n\n const selectActive = useCallback(() => {\n if (activeValue) select(activeValue);\n }, [activeValue, select]);\n\n useEffect(() => {\n if (!open) return;\n const frame = requestAnimationFrame(() => inputRef.current?.focus({ preventScroll: true }));\n return () => cancelAnimationFrame(frame);\n }, [open]);\n\n useEffect(() => {\n if (!activeValue || !open) return;\n const item = items.get(activeValue)?.ref.current;\n const list = item?.closest<HTMLElement>(\"[role='listbox']\");\n if (!item || !list) return;\n const itemRect = item.getBoundingClientRect();\n const listRect = list.getBoundingClientRect();\n if (itemRect.top < listRect.top) list.scrollTop -= listRect.top - itemRect.top;\n else if (itemRect.bottom > listRect.bottom) list.scrollTop += itemRect.bottom - listRect.bottom;\n }, [activeValue, items, open]);\n\n useEffect(() => {\n if (!open) return;\n const isInside = (target: Node) =>\n rootRef.current?.contains(target) || contentRef.current?.contains(target);\n const onPointerDown = (event: PointerEvent) => {\n if (!isInside(event.target as Node)) updateOpen(false);\n };\n const onFocusIn = (event: FocusEvent) => {\n if (!isInside(event.target as Node)) updateOpen(false);\n };\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.key !== \"Escape\") return;\n event.preventDefault();\n updateOpen(false, true);\n };\n window.addEventListener(\"pointerdown\", onPointerDown);\n window.addEventListener(\"focusin\", onFocusIn);\n window.addEventListener(\"keydown\", onKeyDown);\n return () => {\n window.removeEventListener(\"pointerdown\", onPointerDown);\n window.removeEventListener(\"focusin\", onFocusIn);\n window.removeEventListener(\"keydown\", onKeyDown);\n };\n }, [open, updateOpen]);\n\n const activeItem = activeValue ? items.get(activeValue) : undefined;\n const context = useMemo<ComboboxContextValue>(\n () => ({\n open,\n setOpen: updateOpen,\n value,\n select,\n query,\n setQuery: updateQuery,\n activeValue,\n setActiveValue,\n moveActive,\n selectActive,\n registerItem,\n unregisterItem,\n labelFor: (itemValue) => (itemValue === undefined ? undefined : items.get(itemValue)?.label),\n isVisible: (itemValue) => !listQuery.trim() || visibleValues.has(itemValue),\n hasVisibleItems: (groupId) => visibleGroupIds.has(groupId),\n visibleCount: visibleItems.length,\n activeItemId: activeItem?.id,\n triggerId: `${baseId}-trigger`,\n listId: `${baseId}-list`,\n inputId: `${baseId}-input`,\n disabled,\n reduce,\n triggerRef,\n contentRef,\n inputRef,\n activeLayoutId: `${baseId}-active`,\n }),\n [\n activeItem?.id,\n activeValue,\n baseId,\n disabled,\n items,\n listQuery,\n moveActive,\n open,\n query,\n reduce,\n registerItem,\n select,\n selectActive,\n setActiveValue,\n unregisterItem,\n updateOpen,\n updateQuery,\n value,\n visibleItems.length,\n visibleGroupIds,\n visibleValues,\n ],\n );\n\n return (\n <ComboboxContext.Provider value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QAAQ,UAAU;GAC5B,MAAM,eAAe;GACrB,WAAW,OAAO,IAAI;EACxB;EACA,OAAO,iBAAiB,eAAe,aAAa;EACpD,OAAO,iBAAiB,WAAW,SAAS;EAC5C,OAAO,iBAAiB,WAAW,SAAS;EAC5C,aAAa;GACX,OAAO,oBAAoB,eAAe,aAAa;GACvD,OAAO,oBAAoB,WAAW,SAAS;GAC/C,OAAO,oBAAoB,WAAW,SAAS;EACjD;CACF,GAAG,CAAC,MAAM,UAAU,CAAC;CAErB,MAAM,aAAa,cAAc,MAAM,IAAI,WAAW,IAAI,KAAA;CAC1D,MAAM,UAAU,eACP;EACL;EACA,SAAS;EACT;EACA;EACA;EACA,UAAU;EACV;EACA;EACA;EACA;EACA;EACA;EACA,WAAW,cAAe,cAAc,KAAA,IAAY,KAAA,IAAY,MAAM,IAAI,SAAS,CAAC,EAAE;EACtF,YAAY,cAAc,CAAC,UAAU,KAAK,KAAK,cAAc,IAAI,SAAS;EAC1E,kBAAkB,YAAY,gBAAgB,IAAI,OAAO;EACzD,cAAc,aAAa;EAC3B,cAAc,YAAY;EAC1B,WAAW,GAAG,OAAO;EACrB,QAAQ,GAAG,OAAO;EAClB,SAAS,GAAG,OAAO;EACnB;EACA;EACA;EACA;EACA;EACA,gBAAgB,GAAG,OAAO;CAC5B,IACA;EACE,YAAY;EACZ;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,aAAa;EACb;EACA;CACF,CACF;CAEA,OACE,oBAAC,gBAAgB,UAAjB;EAA0B,OAAO;EAC/B,UAAA,oBAAC,OAAD;GAAK,KAAK;GAAS,WAAW,GAAG,mBAAmB,SAAS;GAC1D;EACE,CAAA;CACmB,CAAA;AAE9B"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/hooks/use-on-open.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Runs `start` during the render in which `open` becomes true.
|
|
4
|
+
*
|
|
5
|
+
* Opening a list starts a fresh session — an empty query, the highlight back at
|
|
6
|
+
* the top — and that is a resolution, not a side effect: a passive effect runs
|
|
7
|
+
* after the commit, so the new session would carry the last one's state for a
|
|
8
|
+
* window in which a key press can land.
|
|
9
|
+
*
|
|
10
|
+
* `start` may only set state belonging to the calling component. Anything that
|
|
11
|
+
* reaches outside it — a consumer's callback, a DOM write, moving focus — is a
|
|
12
|
+
* side effect, and React rejects a callback that sets another component's state
|
|
13
|
+
* during this one's render. Put those in an effect keyed to `open`.
|
|
14
|
+
*/
|
|
15
|
+
declare function useOnOpen(open: boolean, start: () => void): void;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { useOnOpen };
|
|
18
|
+
//# sourceMappingURL=use-on-open.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-on-open.d.ts","names":[],"sources":["../../src/hooks/use-on-open.ts"],"mappings":";;;;;;;;;;;;;;iBAiBgB,UAAU,eAAe"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
//#region src/hooks/use-on-open.ts
|
|
4
|
+
/**
|
|
5
|
+
* Runs `start` during the render in which `open` becomes true.
|
|
6
|
+
*
|
|
7
|
+
* Opening a list starts a fresh session — an empty query, the highlight back at
|
|
8
|
+
* the top — and that is a resolution, not a side effect: a passive effect runs
|
|
9
|
+
* after the commit, so the new session would carry the last one's state for a
|
|
10
|
+
* window in which a key press can land.
|
|
11
|
+
*
|
|
12
|
+
* `start` may only set state belonging to the calling component. Anything that
|
|
13
|
+
* reaches outside it — a consumer's callback, a DOM write, moving focus — is a
|
|
14
|
+
* side effect, and React rejects a callback that sets another component's state
|
|
15
|
+
* during this one's render. Put those in an effect keyed to `open`.
|
|
16
|
+
*/
|
|
17
|
+
function useOnOpen(open, start) {
|
|
18
|
+
const [wasOpen, setWasOpen] = useState(open);
|
|
19
|
+
if (open !== wasOpen) {
|
|
20
|
+
setWasOpen(open);
|
|
21
|
+
if (open) start();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { useOnOpen };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=use-on-open.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-on-open.js","names":[],"sources":["../../src/hooks/use-on-open.ts"],"sourcesContent":["\"use client\";\n\nimport { useState } from \"react\";\n\n/**\n * Runs `start` during the render in which `open` becomes true.\n *\n * Opening a list starts a fresh session — an empty query, the highlight back at\n * the top — and that is a resolution, not a side effect: a passive effect runs\n * after the commit, so the new session would carry the last one's state for a\n * window in which a key press can land.\n *\n * `start` may only set state belonging to the calling component. Anything that\n * reaches outside it — a consumer's callback, a DOM write, moving focus — is a\n * side effect, and React rejects a callback that sets another component's state\n * during this one's render. Put those in an effect keyed to `open`.\n */\nexport function useOnOpen(open: boolean, start: () => void) {\n const [wasOpen, setWasOpen] = useState(open);\n if (open !== wasOpen) {\n setWasOpen(open);\n if (open) start();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAiBA,SAAgB,UAAU,MAAe,OAAmB;CAC1D,MAAM,CAAC,SAAS,cAAc,SAAS,IAAI;CAC3C,IAAI,SAAS,SAAS;EACpB,WAAW,IAAI;EACf,IAAI,MAAM,MAAM;CAClB;AACF"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//#region src/hooks/use-row-cursor.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The highlighted row of a list whose rows can change under it.
|
|
4
|
+
*
|
|
5
|
+
* Which row is highlighted is resolved during render, never in a passive
|
|
6
|
+
* effect: a passive effect runs after the commit, so a list that had just
|
|
7
|
+
* changed would carry an `aria-activedescendant` naming a row that has left it,
|
|
8
|
+
* and a key pressed in that window would commit the wrong row or nothing at
|
|
9
|
+
* all.
|
|
10
|
+
*
|
|
11
|
+
* The cursor holds the row's id, not its position. A position alone cannot tell
|
|
12
|
+
* a list that shrank from one that swapped its rows for a different set of the
|
|
13
|
+
* same length, and the second case is the one that silently hands Enter to a
|
|
14
|
+
* row the user never chose. A cursor whose row has left the list returns the
|
|
15
|
+
* highlight to the first row rather than to the nearest surviving one: the row
|
|
16
|
+
* the user aimed at is gone, and the first row is where a new query already
|
|
17
|
+
* puts the highlight.
|
|
18
|
+
*
|
|
19
|
+
* Pass the query the list is filtered by. The cursor is stamped with it and
|
|
20
|
+
* dropped when it changes, so a caller cannot forget to clear it — including a
|
|
21
|
+
* caller whose query arrives as a prop and so never runs its own handler. Rows
|
|
22
|
+
* that come back under a query that has moved on cannot revive it either.
|
|
23
|
+
* `moveTo(null)` is for deliberate resets, such as reopening the list.
|
|
24
|
+
*
|
|
25
|
+
* Both callbacks keep one identity for the life of the component, and read the
|
|
26
|
+
* rows and the query through a ref to do it. A caller will put them in an
|
|
27
|
+
* effect's dependencies — the exhaustive-deps rule makes it — and a `moveTo`
|
|
28
|
+
* rebuilt on every keystroke would re-run that effect on every keystroke.
|
|
29
|
+
*/
|
|
30
|
+
declare function useRowCursor(rows: readonly {
|
|
31
|
+
id: string;
|
|
32
|
+
}[], query: string): {
|
|
33
|
+
activeIndex: number;
|
|
34
|
+
moveTo: (id: string | null) => void;
|
|
35
|
+
moveActive: (direction: 1 | -1) => void;
|
|
36
|
+
};
|
|
37
|
+
//#endregion
|
|
38
|
+
export { useRowCursor };
|
|
39
|
+
//# sourceMappingURL=use-row-cursor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-row-cursor.d.ts","names":[],"sources":["../../src/hooks/use-row-cursor.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA4CgB,aAAa;EAAiB;KAAgB;;EAkBrD,SAAA;EAIoC,aAAA"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useLayoutEffect, useRef, useState } from "react";
|
|
3
|
+
//#region src/hooks/use-row-cursor.ts
|
|
4
|
+
/** The cursor's row, or -1 once the query has moved on or the row has left. */
|
|
5
|
+
function indexOfCursor(rows, query, cursor) {
|
|
6
|
+
if (cursor === null || cursor.query !== query) return -1;
|
|
7
|
+
return rows.findIndex((row) => row.id === cursor.id);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The highlighted row of a list whose rows can change under it.
|
|
11
|
+
*
|
|
12
|
+
* Which row is highlighted is resolved during render, never in a passive
|
|
13
|
+
* effect: a passive effect runs after the commit, so a list that had just
|
|
14
|
+
* changed would carry an `aria-activedescendant` naming a row that has left it,
|
|
15
|
+
* and a key pressed in that window would commit the wrong row or nothing at
|
|
16
|
+
* all.
|
|
17
|
+
*
|
|
18
|
+
* The cursor holds the row's id, not its position. A position alone cannot tell
|
|
19
|
+
* a list that shrank from one that swapped its rows for a different set of the
|
|
20
|
+
* same length, and the second case is the one that silently hands Enter to a
|
|
21
|
+
* row the user never chose. A cursor whose row has left the list returns the
|
|
22
|
+
* highlight to the first row rather than to the nearest surviving one: the row
|
|
23
|
+
* the user aimed at is gone, and the first row is where a new query already
|
|
24
|
+
* puts the highlight.
|
|
25
|
+
*
|
|
26
|
+
* Pass the query the list is filtered by. The cursor is stamped with it and
|
|
27
|
+
* dropped when it changes, so a caller cannot forget to clear it — including a
|
|
28
|
+
* caller whose query arrives as a prop and so never runs its own handler. Rows
|
|
29
|
+
* that come back under a query that has moved on cannot revive it either.
|
|
30
|
+
* `moveTo(null)` is for deliberate resets, such as reopening the list.
|
|
31
|
+
*
|
|
32
|
+
* Both callbacks keep one identity for the life of the component, and read the
|
|
33
|
+
* rows and the query through a ref to do it. A caller will put them in an
|
|
34
|
+
* effect's dependencies — the exhaustive-deps rule makes it — and a `moveTo`
|
|
35
|
+
* rebuilt on every keystroke would re-run that effect on every keystroke.
|
|
36
|
+
*/
|
|
37
|
+
function useRowCursor(rows, query) {
|
|
38
|
+
const [cursor, setCursor] = useState(null);
|
|
39
|
+
const latest = useRef({
|
|
40
|
+
rows,
|
|
41
|
+
query
|
|
42
|
+
});
|
|
43
|
+
useLayoutEffect(() => {
|
|
44
|
+
latest.current = {
|
|
45
|
+
rows,
|
|
46
|
+
query
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
const cursorRow = indexOfCursor(rows, query, cursor);
|
|
50
|
+
if (cursor !== null && cursorRow < 0) setCursor(null);
|
|
51
|
+
const moveTo = useCallback((id) => setCursor(id === null ? null : {
|
|
52
|
+
id,
|
|
53
|
+
query: latest.current.query
|
|
54
|
+
}), []);
|
|
55
|
+
const moveActive = useCallback((direction) => {
|
|
56
|
+
const { rows: live, query: liveQuery } = latest.current;
|
|
57
|
+
const last = live.length - 1;
|
|
58
|
+
if (last < 0) return;
|
|
59
|
+
setCursor((current) => {
|
|
60
|
+
const at = Math.max(indexOfCursor(live, liveQuery, current), 0);
|
|
61
|
+
const next = Math.min(Math.max(at + direction, 0), last);
|
|
62
|
+
return {
|
|
63
|
+
id: live[next].id,
|
|
64
|
+
query: liveQuery
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
}, []);
|
|
68
|
+
return {
|
|
69
|
+
activeIndex: cursorRow < 0 ? 0 : cursorRow,
|
|
70
|
+
moveTo,
|
|
71
|
+
moveActive
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
export { useRowCursor };
|
|
76
|
+
|
|
77
|
+
//# sourceMappingURL=use-row-cursor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-row-cursor.js","names":[],"sources":["../../src/hooks/use-row-cursor.ts"],"sourcesContent":["\"use client\";\n\nimport { useCallback, useLayoutEffect, useRef, useState } from \"react\";\n\n/**\n * Where the keyboard or the pointer last moved to: the row's id, stamped with\n * the query it was placed under.\n */\ntype RowCursor = { id: string; query: string };\n\n/** The cursor's row, or -1 once the query has moved on or the row has left. */\nfunction indexOfCursor(rows: readonly { id: string }[], query: string, cursor: RowCursor | null) {\n if (cursor === null || cursor.query !== query) return -1;\n return rows.findIndex((row) => row.id === cursor.id);\n}\n\n/**\n * The highlighted row of a list whose rows can change under it.\n *\n * Which row is highlighted is resolved during render, never in a passive\n * effect: a passive effect runs after the commit, so a list that had just\n * changed would carry an `aria-activedescendant` naming a row that has left it,\n * and a key pressed in that window would commit the wrong row or nothing at\n * all.\n *\n * The cursor holds the row's id, not its position. A position alone cannot tell\n * a list that shrank from one that swapped its rows for a different set of the\n * same length, and the second case is the one that silently hands Enter to a\n * row the user never chose. A cursor whose row has left the list returns the\n * highlight to the first row rather than to the nearest surviving one: the row\n * the user aimed at is gone, and the first row is where a new query already\n * puts the highlight.\n *\n * Pass the query the list is filtered by. The cursor is stamped with it and\n * dropped when it changes, so a caller cannot forget to clear it — including a\n * caller whose query arrives as a prop and so never runs its own handler. Rows\n * that come back under a query that has moved on cannot revive it either.\n * `moveTo(null)` is for deliberate resets, such as reopening the list.\n *\n * Both callbacks keep one identity for the life of the component, and read the\n * rows and the query through a ref to do it. A caller will put them in an\n * effect's dependencies — the exhaustive-deps rule makes it — and a `moveTo`\n * rebuilt on every keystroke would re-run that effect on every keystroke.\n */\nexport function useRowCursor(rows: readonly { id: string }[], query: string) {\n const [cursor, setCursor] = useState<RowCursor | null>(null);\n // Written after commit, not during render: a render React discards or has not\n // finished still runs the component body, and an event handler that read this\n // in that window would stamp the cursor with a query the committed tree does\n // not have.\n const latest = useRef({ rows, query });\n useLayoutEffect(() => {\n latest.current = { rows, query };\n });\n\n const cursorRow = indexOfCursor(rows, query, cursor);\n // Cleared rather than ignored: React re-runs this render with the cursor\n // already gone, so rows that come back cannot revive a highlight the user has\n // stopped aiming at.\n if (cursor !== null && cursorRow < 0) setCursor(null);\n\n const moveTo = useCallback(\n (id: string | null) => setCursor(id === null ? null : { id, query: latest.current.query }),\n [],\n );\n\n const moveActive = useCallback((direction: 1 | -1) => {\n const { rows: live, query: liveQuery } = latest.current;\n const last = live.length - 1;\n if (last < 0) return;\n // Steps from the row the cursor is really on, inside the update, so that\n // two keys landing in one batch move two rows rather than one.\n setCursor((current) => {\n const at = Math.max(indexOfCursor(live, liveQuery, current), 0);\n const next = Math.min(Math.max(at + direction, 0), last);\n return { id: live[next].id, query: liveQuery };\n });\n }, []);\n\n return { activeIndex: cursorRow < 0 ? 0 : cursorRow, moveTo, moveActive };\n}\n"],"mappings":";;;;AAWA,SAAS,cAAc,MAAiC,OAAe,QAA0B;CAC/F,IAAI,WAAW,QAAQ,OAAO,UAAU,OAAO,OAAO;CACtD,OAAO,KAAK,WAAW,QAAQ,IAAI,OAAO,OAAO,EAAE;AACrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,SAAgB,aAAa,MAAiC,OAAe;CAC3E,MAAM,CAAC,QAAQ,aAAa,SAA2B,IAAI;CAK3D,MAAM,SAAS,OAAO;EAAE;EAAM;CAAM,CAAC;CACrC,sBAAsB;EACpB,OAAO,UAAU;GAAE;GAAM;EAAM;CACjC,CAAC;CAED,MAAM,YAAY,cAAc,MAAM,OAAO,MAAM;CAInD,IAAI,WAAW,QAAQ,YAAY,GAAG,UAAU,IAAI;CAEpD,MAAM,SAAS,aACZ,OAAsB,UAAU,OAAO,OAAO,OAAO;EAAE;EAAI,OAAO,OAAO,QAAQ;CAAM,CAAC,GACzF,CAAC,CACH;CAEA,MAAM,aAAa,aAAa,cAAsB;EACpD,MAAM,EAAE,MAAM,MAAM,OAAO,cAAc,OAAO;EAChD,MAAM,OAAO,KAAK,SAAS;EAC3B,IAAI,OAAO,GAAG;EAGd,WAAW,YAAY;GACrB,MAAM,KAAK,KAAK,IAAI,cAAc,MAAM,WAAW,OAAO,GAAG,CAAC;GAC9D,MAAM,OAAO,KAAK,IAAI,KAAK,IAAI,KAAK,WAAW,CAAC,GAAG,IAAI;GACvD,OAAO;IAAE,IAAI,KAAK,KAAK,CAAC;IAAI,OAAO;GAAU;EAC/C,CAAC;CACH,GAAG,CAAC,CAAC;CAEL,OAAO;EAAE,aAAa,YAAY,IAAI,IAAI;EAAW;EAAQ;CAAW;AAC1E"}
|