@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
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { useOnOpen } from "../../hooks/use-on-open.js";
|
|
3
|
+
import { useRowCursor } from "../../hooks/use-row-cursor.js";
|
|
2
4
|
import { useTouchCapable } from "../../hooks/use-touch-capable.js";
|
|
3
5
|
import { EASE_OUT } from "../../lib/ease.js";
|
|
4
6
|
import { t as PresenceGate } from "../../presence-gate-BekdC4Bo.js";
|
|
@@ -35,16 +37,11 @@ function CommandPalette({ items, shortcut = "k", placeholder = "Type a command o
|
|
|
35
37
|
onOpenChange?.(v);
|
|
36
38
|
}, [controlled, onOpenChange]);
|
|
37
39
|
const [query, setQuery] = useState("");
|
|
38
|
-
const [active, setActive] = useState(0);
|
|
39
40
|
const [mounted, setMounted] = useState(false);
|
|
40
41
|
useEffect(() => setMounted(true), []);
|
|
41
42
|
const uid = useId();
|
|
42
43
|
const reduce = useReducedMotion();
|
|
43
44
|
const canTouch = useTouchCapable();
|
|
44
|
-
const updateQuery = useCallback((value) => {
|
|
45
|
-
setQuery(value);
|
|
46
|
-
setActive(0);
|
|
47
|
-
}, []);
|
|
48
45
|
const inputRef = useRef(null);
|
|
49
46
|
const listRef = useRef(null);
|
|
50
47
|
useEffect(() => {
|
|
@@ -66,13 +63,6 @@ function CommandPalette({ items, shortcut = "k", placeholder = "Type a command o
|
|
|
66
63
|
shortcut,
|
|
67
64
|
setOpen
|
|
68
65
|
]);
|
|
69
|
-
useEffect(() => {
|
|
70
|
-
if (open) {
|
|
71
|
-
updateQuery("");
|
|
72
|
-
setActive(0);
|
|
73
|
-
requestAnimationFrame(() => inputRef.current?.focus());
|
|
74
|
-
}
|
|
75
|
-
}, [open, updateQuery]);
|
|
76
66
|
useEffect(() => {
|
|
77
67
|
if (!open) return;
|
|
78
68
|
const root = document.documentElement;
|
|
@@ -106,16 +96,27 @@ function CommandPalette({ items, shortcut = "k", placeholder = "Type a command o
|
|
|
106
96
|
});
|
|
107
97
|
return Array.from(map.entries());
|
|
108
98
|
}, [filtered]);
|
|
99
|
+
const rows = useMemo(() => grouped.flatMap(([, list]) => list), [grouped]);
|
|
100
|
+
const { activeIndex: active, moveTo, moveActive } = useRowCursor(rows, query);
|
|
101
|
+
useOnOpen(open, () => {
|
|
102
|
+
setQuery("");
|
|
103
|
+
moveTo(null);
|
|
104
|
+
});
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
if (!open) return;
|
|
107
|
+
const frame = requestAnimationFrame(() => inputRef.current?.focus());
|
|
108
|
+
return () => cancelAnimationFrame(frame);
|
|
109
|
+
}, [open]);
|
|
109
110
|
const onKeyDown = (e) => {
|
|
110
111
|
if (e.key === "ArrowDown") {
|
|
111
112
|
e.preventDefault();
|
|
112
|
-
|
|
113
|
+
moveActive(1);
|
|
113
114
|
} else if (e.key === "ArrowUp") {
|
|
114
115
|
e.preventDefault();
|
|
115
|
-
|
|
116
|
+
moveActive(-1);
|
|
116
117
|
} else if (e.key === "Enter") {
|
|
117
118
|
e.preventDefault();
|
|
118
|
-
const it =
|
|
119
|
+
const it = rows[active];
|
|
119
120
|
if (it) {
|
|
120
121
|
it.onSelect();
|
|
121
122
|
setOpen(false);
|
|
@@ -126,12 +127,6 @@ function CommandPalette({ items, shortcut = "k", placeholder = "Type a command o
|
|
|
126
127
|
if (!open) return;
|
|
127
128
|
(listRef.current?.querySelector(`[data-index="${active}"]`))?.scrollIntoView({ block: "nearest" });
|
|
128
129
|
}, [active, open]);
|
|
129
|
-
const indexOfItem = useMemo(() => {
|
|
130
|
-
const indices = /* @__PURE__ */ new Map();
|
|
131
|
-
let next = 0;
|
|
132
|
-
for (const [, list] of grouped) for (const it of list) indices.set(it.id, next++);
|
|
133
|
-
return indices;
|
|
134
|
-
}, [grouped]);
|
|
135
130
|
if (!mounted) return null;
|
|
136
131
|
return createPortal(/* @__PURE__ */ jsxs(AnimatePresence, {
|
|
137
132
|
initial: false,
|
|
@@ -191,12 +186,12 @@ function CommandPalette({ items, shortcut = "k", placeholder = "Type a command o
|
|
|
191
186
|
/* @__PURE__ */ jsx("input", {
|
|
192
187
|
ref: inputRef,
|
|
193
188
|
value: query,
|
|
194
|
-
onChange: (e) =>
|
|
189
|
+
onChange: (e) => setQuery(e.target.value),
|
|
195
190
|
placeholder,
|
|
196
191
|
role: "combobox",
|
|
197
192
|
"aria-expanded": "true",
|
|
198
193
|
"aria-controls": `${uid}-list`,
|
|
199
|
-
"aria-activedescendant":
|
|
194
|
+
"aria-activedescendant": rows.length > 0 ? `${uid}-opt-${active}` : void 0,
|
|
200
195
|
"aria-autocomplete": "list",
|
|
201
196
|
className: cn("h-12 flex-1 bg-transparent text-foreground text-sm outline-none placeholder:text-muted-foreground", canTouch && "text-base")
|
|
202
197
|
}),
|
|
@@ -211,7 +206,7 @@ function CommandPalette({ items, shortcut = "k", placeholder = "Type a command o
|
|
|
211
206
|
role: "listbox",
|
|
212
207
|
"aria-label": "Commands",
|
|
213
208
|
className: "max-h-[60vh] overflow-y-auto overscroll-contain p-2 [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",
|
|
214
|
-
children:
|
|
209
|
+
children: rows.length === 0 ? /* @__PURE__ */ jsx("div", {
|
|
215
210
|
className: "p-8 text-center text-muted-foreground text-sm",
|
|
216
211
|
children: emptyMessage
|
|
217
212
|
}) : grouped.map(([group, list]) => /* @__PURE__ */ jsxs("div", {
|
|
@@ -221,7 +216,7 @@ function CommandPalette({ items, shortcut = "k", placeholder = "Type a command o
|
|
|
221
216
|
className: "px-2 py-1.5 font-semibold text-[10px] text-muted-foreground uppercase tracking-wider",
|
|
222
217
|
children: group
|
|
223
218
|
}), list.map((it) => {
|
|
224
|
-
const idx =
|
|
219
|
+
const idx = rows.indexOf(it);
|
|
225
220
|
const isActive = idx === active;
|
|
226
221
|
const Icon = it.icon;
|
|
227
222
|
return /* @__PURE__ */ jsxs("button", {
|
|
@@ -230,7 +225,7 @@ function CommandPalette({ items, shortcut = "k", placeholder = "Type a command o
|
|
|
230
225
|
role: "option",
|
|
231
226
|
"aria-selected": isActive,
|
|
232
227
|
"data-index": idx,
|
|
233
|
-
onMouseEnter: () =>
|
|
228
|
+
onMouseEnter: () => moveTo(it.id),
|
|
234
229
|
onClick: () => {
|
|
235
230
|
it.onSelect();
|
|
236
231
|
setOpen(false);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-palette.js","names":[],"sources":["../../../src/components/motion/command-palette.tsx"],"sourcesContent":["\"use client\";\n\nimport { type ReactNode, useCallback, useEffect, useId, useMemo, useRef, useState } from \"react\";\nimport { type LucideIcon, Search } from \"lucide-react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { createPortal } from \"react-dom\";\n\nimport { cn } from \"@kumix/utils\";\nimport { useTouchCapable } from \"../../hooks/use-touch-capable\";\nimport { EASE_OUT } from \"../../lib/ease\";\nimport { PresenceGate } from \"../../lib/presence-gate\";\n\nexport type CommandItem = {\n id: string;\n label: string;\n group?: string;\n hint?: string;\n keywords?: string[];\n icon?: LucideIcon;\n badge?: ReactNode;\n onSelect: () => void;\n};\n\nexport interface CommandPaletteProps {\n items: CommandItem[];\n /** Opens with Cmd/Ctrl + this key. Default: \"k\" */\n shortcut?: string;\n placeholder?: string;\n emptyMessage?: string;\n open?: boolean;\n onOpenChange?: (open: boolean) => void;\n}\n\nfunction fuzzyMatch(needle: string, hay: string) {\n if (!needle) return true;\n needle = needle.toLowerCase();\n hay = hay.toLowerCase();\n let i = 0;\n for (const ch of hay) {\n if (ch === needle[i]) i++;\n if (i === needle.length) return true;\n }\n return false;\n}\n\n// Opened via a keyboard shortcut many times a day — entrance must read as\n// instant. Tight spring, even faster exit.\nconst PANEL_SPRING = {\n type: \"spring\",\n stiffness: 560,\n damping: 40,\n mass: 0.5,\n} as const;\n\nexport function CommandPalette({\n items,\n shortcut = \"k\",\n placeholder = \"Type a command or search…\",\n emptyMessage = \"No results found.\",\n open: controlledOpen,\n onOpenChange,\n}: CommandPaletteProps) {\n const [internalOpen, setInternalOpen] = useState(false);\n const controlled = controlledOpen !== undefined;\n const open = controlled ? controlledOpen : internalOpen;\n const setOpen = useCallback(\n (v: boolean) => {\n if (!controlled) setInternalOpen(v);\n onOpenChange?.(v);\n },\n [controlled, onOpenChange],\n );\n\n const [query, setQuery] = useState(\"\");\n const [active, setActive] = useState(0);\n // Portal target only exists client-side; render nothing during SSR/hydration.\n const [mounted, setMounted] = useState(false);\n useEffect(() => setMounted(true), []);\n const uid = useId();\n const reduce = useReducedMotion();\n const canTouch = useTouchCapable();\n const updateQuery = useCallback((value: string) => {\n setQuery(value);\n setActive(0);\n }, []);\n const inputRef = useRef<HTMLInputElement>(null);\n const listRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n const onKey = (e: KeyboardEvent) => {\n if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === shortcut.toLowerCase()) {\n e.preventDefault();\n setOpen(!open);\n return;\n }\n if (e.key === \"Escape\" && open) {\n e.preventDefault();\n setOpen(false);\n }\n };\n window.addEventListener(\"keydown\", onKey);\n return () => window.removeEventListener(\"keydown\", onKey);\n }, [open, shortcut, setOpen]);\n\n useEffect(() => {\n if (open) {\n updateQuery(\"\");\n setActive(0);\n requestAnimationFrame(() => inputRef.current?.focus());\n }\n }, [open, updateQuery]);\n\n useEffect(() => {\n if (!open) return;\n const root = document.documentElement;\n const previousRootOverflow = root.style.overflow;\n const previousBodyOverflow = document.body.style.overflow;\n root.style.overflow = \"hidden\";\n document.body.style.overflow = \"hidden\";\n return () => {\n root.style.overflow = previousRootOverflow;\n document.body.style.overflow = previousBodyOverflow;\n };\n }, [open]);\n\n const filtered = useMemo(() => {\n if (!query) return items;\n return items.filter((it) => {\n const haystacks = [it.label, it.group ?? \"\", ...(it.keywords ?? [])];\n return haystacks.some((h) => fuzzyMatch(query, h));\n });\n }, [items, query]);\n\n // Reserve the icon column only when at least one item brings an icon, so\n // icon-less lists don't render a dead gap before every label.\n const hasIcons = useMemo(() => items.some((it) => it.icon), [items]);\n\n const grouped = useMemo(() => {\n const map = new Map<string, CommandItem[]>();\n filtered.forEach((it) => {\n const g = it.group ?? \"Results\";\n const groupItems = map.get(g) ?? [];\n groupItems.push(it);\n map.set(g, groupItems);\n });\n return Array.from(map.entries());\n }, [filtered]);\n\n const onKeyDown = (e: React.KeyboardEvent) => {\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n setActive((a) => Math.min(filtered.length - 1, a + 1));\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n setActive((a) => Math.max(0, a - 1));\n } else if (e.key === \"Enter\") {\n e.preventDefault();\n const it = filtered[active];\n if (it) {\n it.onSelect();\n setOpen(false);\n }\n }\n };\n\n useEffect(() => {\n if (!open) return;\n const el = listRef.current?.querySelector<HTMLButtonElement>(`[data-index=\"${active}\"]`);\n el?.scrollIntoView({ block: \"nearest\" });\n }, [active, open]);\n\n // A row's index is its position in the flattened group order, derived once\n // per change of `grouped` rather than counted while the rows render. The rows\n // hang off `PresenceGate`'s render prop, which is its own component: a\n // counter declared in this body would be incremented on the gate's render\n // passes, after this body had already run, and would never be reset again —\n // the ids, `aria-selected` and the highlight all drift with it.\n const indexOfItem = useMemo(() => {\n const indices = new Map<string, number>();\n let next = 0;\n for (const [, list] of grouped) {\n for (const it of list) indices.set(it.id, next++);\n }\n return indices;\n }, [grouped]);\n\n if (!mounted) return null;\n\n // Portaled to <body> so ancestors with transforms, filters, or fixed\n // positioning can't trap the overlay in their stacking context, and mounted\n // only while open. The chrome is two fixed siblings rather than one wrapper:\n // the backdrop spans the viewport edges but carries the scrim colour, and the\n // layer positioning the panel is inset off every edge. Both hang off\n // `PresenceGate`, so interaction releases in the same commit that starts the\n // exit rather than when it ends — `open` is already false for those frames.\n return createPortal(\n <AnimatePresence initial={false}>\n {open ? (\n <PresenceGate key=\"backdrop\">\n {({ gate }) => (\n <motion.button\n type=\"button\"\n aria-label=\"Close command palette\"\n initial={{ opacity: 0 }}\n animate={{ opacity: 1 }}\n exit={{\n opacity: 0,\n transition: { duration: 0.12, ease: EASE_OUT },\n }}\n transition={{ duration: 0.18, ease: EASE_OUT }}\n {...gate}\n onClick={() => setOpen(false)}\n className=\"pointer-events-auto fixed inset-0 z-100 bg-background/5 [-webkit-backdrop-filter:blur(12px)_saturate(140%)] [backdrop-filter:blur(12px)_saturate(140%)]\"\n />\n )}\n </PresenceGate>\n ) : null}\n\n {open ? (\n <PresenceGate key=\"panel-layer\">\n {({ isPresent, gate }) => (\n // The layer itself never takes pointer events, so it carries\n // `inert` alone rather than the gate's pointer-events value.\n <div\n inert={!isPresent}\n className=\"pointer-events-none fixed inset-x-4 top-[18vh] bottom-4 z-100 flex items-start justify-center\"\n >\n <motion.div\n role=\"dialog\"\n aria-modal=\"true\"\n aria-label=\"Command palette\"\n initial={{\n opacity: 0,\n y: reduce ? 0 : -8,\n scale: reduce ? 1 : 0.97,\n }}\n animate={{ opacity: 1, y: 0, scale: 1 }}\n exit={{\n opacity: 0,\n y: reduce ? 0 : -8,\n scale: reduce ? 1 : 0.97,\n transition: { duration: 0.12, ease: EASE_OUT },\n }}\n transition={reduce ? { duration: 0.1 } : PANEL_SPRING}\n {...gate}\n onKeyDown={onKeyDown}\n className=\"pointer-events-auto w-full max-w-xl overflow-hidden rounded-2xl border border-border bg-card shadow-2xl will-change-transform\"\n >\n <div className=\"flex items-center gap-3 border-border border-b px-4\">\n <Search className=\"h-4 w-4 text-muted-foreground\" />\n <input\n ref={inputRef}\n value={query}\n onChange={(e) => updateQuery(e.target.value)}\n placeholder={placeholder}\n role=\"combobox\"\n // The field only exists while the palette is open.\n aria-expanded=\"true\"\n aria-controls={`${uid}-list`}\n aria-activedescendant={filtered.length > 0 ? `${uid}-opt-${active}` : undefined}\n aria-autocomplete=\"list\"\n className={cn(\n \"h-12 flex-1 bg-transparent text-foreground text-sm outline-none placeholder:text-muted-foreground\",\n // The palette focuses this field the moment it opens, and iOS\n // zooms the page in on a focused field under 16px: the fixed\n // overlay is magnified off-center — clipped leading edge, half\n // an icon column — and the zoom outlives the palette. 16px on\n // touch keeps the page at scale 1; pointer devices keep 14px.\n canTouch && \"text-base\",\n )}\n />\n <kbd className=\"hidden rounded border border-border bg-background px-1.5 py-0.5 text-[10px] text-muted-foreground sm:inline-block\">\n ESC\n </kbd>\n </div>\n <div\n ref={listRef}\n id={`${uid}-list`}\n role=\"listbox\"\n aria-label=\"Commands\"\n className=\"max-h-[60vh] overflow-y-auto overscroll-contain p-2 [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden\"\n >\n {filtered.length === 0 ? (\n <div className=\"p-8 text-center text-muted-foreground text-sm\">\n {emptyMessage}\n </div>\n ) : (\n grouped.map(([group, list]) => (\n <div key={group} className=\"mb-1 last:mb-0\">\n <div\n aria-hidden\n className=\"px-2 py-1.5 font-semibold text-[10px] text-muted-foreground uppercase tracking-wider\"\n >\n {group}\n </div>\n {list.map((it) => {\n const idx = indexOfItem.get(it.id) ?? 0;\n const isActive = idx === active;\n const Icon = it.icon;\n return (\n <button\n key={it.id}\n type=\"button\"\n id={`${uid}-opt-${idx}`}\n role=\"option\"\n aria-selected={isActive}\n data-index={idx}\n onMouseEnter={() => setActive(idx)}\n onClick={() => {\n it.onSelect();\n setOpen(false);\n }}\n className={cn(\n \"relative isolate flex w-full items-center gap-3 rounded-md px-2 py-2 text-left text-sm transition-colors\",\n isActive ? \"text-foreground\" : \"text-muted-foreground\",\n )}\n >\n {isActive ? (\n <motion.span\n layoutId={`${uid}-active`}\n className=\"absolute inset-0 z-0 rounded-md bg-primary/5\"\n transition={\n reduce\n ? { duration: 0 }\n : // Tracks rapid arrow-key navigation — keep it tighter\n // than SPRING_LAYOUT so it never lags the active row.\n {\n type: \"spring\",\n stiffness: 480,\n damping: 38,\n }\n }\n />\n ) : null}\n {Icon ? (\n <Icon className=\"relative z-10 h-4 w-4\" />\n ) : hasIcons ? (\n <span className=\"relative z-10 h-4 w-4\" />\n ) : null}\n <span className=\"relative z-10 flex-1 truncate\">{it.label}</span>\n {it.badge ? (\n <span className=\"relative z-10 shrink-0\">{it.badge}</span>\n ) : null}\n {it.hint ? (\n <kbd className=\"relative z-10 rounded border border-border bg-background px-1.5 py-0.5 text-[10px] text-muted-foreground\">\n {it.hint}\n </kbd>\n ) : null}\n </button>\n );\n })}\n </div>\n ))\n )}\n </div>\n </motion.div>\n </div>\n )}\n </PresenceGate>\n ) : null}\n </AnimatePresence>,\n document.body,\n );\n}\n"],"mappings":";;;;;;;;;;;AAiCA,SAAS,WAAW,QAAgB,KAAa;CAC/C,IAAI,CAAC,QAAQ,OAAO;CACpB,SAAS,OAAO,YAAY;CAC5B,MAAM,IAAI,YAAY;CACtB,IAAI,IAAI;CACR,KAAK,MAAM,MAAM,KAAK;EACpB,IAAI,OAAO,OAAO,IAAI;EACtB,IAAI,MAAM,OAAO,QAAQ,OAAO;CAClC;CACA,OAAO;AACT;AAIA,MAAM,eAAe;CACnB,MAAM;CACN,WAAW;CACX,SAAS;CACT,MAAM;AACR;AAEA,SAAgB,eAAe,EAC7B,OACA,WAAW,KACX,cAAc,6BACd,eAAe,qBACf,MAAM,gBACN,gBACsB;CACtB,MAAM,CAAC,cAAc,mBAAmB,SAAS,KAAK;CACtD,MAAM,aAAa,mBAAmB,KAAA;CACtC,MAAM,OAAO,aAAa,iBAAiB;CAC3C,MAAM,UAAU,aACb,MAAe;EACd,IAAI,CAAC,YAAY,gBAAgB,CAAC;EAClC,eAAe,CAAC;CAClB,GACA,CAAC,YAAY,YAAY,CAC3B;CAEA,MAAM,CAAC,OAAO,YAAY,SAAS,EAAE;CACrC,MAAM,CAAC,QAAQ,aAAa,SA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AAA,GAAG;SAAY,CAAA,IACvD;SACH,GAAG,OACF,oBAAC,OAAD;UAAK,WAAU;UACZ,UAAA,GAAG;SACD,CAAA,IACH;QACE;OA/CD,GAAA,GAAG,EA+CF;MAEZ,CAAC,CACE;KA/DK,GAAA,KA+DL,CACN;IAEA,CAAA,CACK;;EACT,CAAA,EAEK,GA3II,aA2IJ,IACZ,IACW;CACjB,CAAA,GAAA,SAAS,IACX;AACF"}
|
|
1
|
+
{"version":3,"file":"command-palette.js","names":[],"sources":["../../../src/components/motion/command-palette.tsx"],"sourcesContent":["\"use client\";\n\nimport { type ReactNode, useCallback, useEffect, useId, useMemo, useRef, useState } from \"react\";\nimport { type LucideIcon, Search } from \"lucide-react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { createPortal } from \"react-dom\";\n\nimport { cn } from \"@kumix/utils\";\nimport { useOnOpen } from \"../../hooks/use-on-open\";\nimport { useRowCursor } from \"../../hooks/use-row-cursor\";\nimport { useTouchCapable } from \"../../hooks/use-touch-capable\";\nimport { EASE_OUT } from \"../../lib/ease\";\nimport { PresenceGate } from \"../../lib/presence-gate\";\n\nexport type CommandItem = {\n id: string;\n label: string;\n group?: string;\n hint?: string;\n keywords?: string[];\n icon?: LucideIcon;\n badge?: ReactNode;\n onSelect: () => void;\n};\n\nexport interface CommandPaletteProps {\n items: CommandItem[];\n /** Opens with Cmd/Ctrl + this key. Default: \"k\" */\n shortcut?: string;\n placeholder?: string;\n emptyMessage?: string;\n open?: boolean;\n onOpenChange?: (open: boolean) => void;\n}\n\nfunction fuzzyMatch(needle: string, hay: string) {\n if (!needle) return true;\n needle = needle.toLowerCase();\n hay = hay.toLowerCase();\n let i = 0;\n for (const ch of hay) {\n if (ch === needle[i]) i++;\n if (i === needle.length) return true;\n }\n return false;\n}\n\n// Opened via a keyboard shortcut many times a day — entrance must read as\n// instant. Tight spring, even faster exit.\nconst PANEL_SPRING = {\n type: \"spring\",\n stiffness: 560,\n damping: 40,\n mass: 0.5,\n} as const;\n\nexport function CommandPalette({\n items,\n shortcut = \"k\",\n placeholder = \"Type a command or search…\",\n emptyMessage = \"No results found.\",\n open: controlledOpen,\n onOpenChange,\n}: CommandPaletteProps) {\n const [internalOpen, setInternalOpen] = useState(false);\n const controlled = controlledOpen !== undefined;\n const open = controlled ? controlledOpen : internalOpen;\n const setOpen = useCallback(\n (v: boolean) => {\n if (!controlled) setInternalOpen(v);\n onOpenChange?.(v);\n },\n [controlled, onOpenChange],\n );\n\n const [query, setQuery] = useState(\"\");\n // Portal target only exists client-side; render nothing during SSR/hydration.\n const [mounted, setMounted] = useState(false);\n useEffect(() => setMounted(true), []);\n const uid = useId();\n const reduce = useReducedMotion();\n const canTouch = useTouchCapable();\n const inputRef = useRef<HTMLInputElement>(null);\n const listRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n const onKey = (e: KeyboardEvent) => {\n if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === shortcut.toLowerCase()) {\n e.preventDefault();\n setOpen(!open);\n return;\n }\n if (e.key === \"Escape\" && open) {\n e.preventDefault();\n setOpen(false);\n }\n };\n window.addEventListener(\"keydown\", onKey);\n return () => window.removeEventListener(\"keydown\", onKey);\n }, [open, shortcut, setOpen]);\n\n useEffect(() => {\n if (!open) return;\n const root = document.documentElement;\n const previousRootOverflow = root.style.overflow;\n const previousBodyOverflow = document.body.style.overflow;\n root.style.overflow = \"hidden\";\n document.body.style.overflow = \"hidden\";\n return () => {\n root.style.overflow = previousRootOverflow;\n document.body.style.overflow = previousBodyOverflow;\n };\n }, [open]);\n\n const filtered = useMemo(() => {\n if (!query) return items;\n return items.filter((it) => {\n const haystacks = [it.label, it.group ?? \"\", ...(it.keywords ?? [])];\n return haystacks.some((h) => fuzzyMatch(query, h));\n });\n }, [items, query]);\n\n // Reserve the icon column only when at least one item brings an icon, so\n // icon-less lists don't render a dead gap before every label.\n const hasIcons = useMemo(() => items.some((it) => it.icon), [items]);\n\n const grouped = useMemo(() => {\n const map = new Map<string, CommandItem[]>();\n filtered.forEach((it) => {\n const g = it.group ?? \"Results\";\n const groupItems = map.get(g) ?? [];\n groupItems.push(it);\n map.set(g, groupItems);\n });\n return Array.from(map.entries());\n }, [filtered]);\n\n // Grouping reorders the list, so the rendered order is not the filtered\n // order whenever two groups interleave. Everything that has to agree on\n // \"which row\" — the highlight, the ids, Enter, the scroll — reads this one\n // array, so they cannot drift apart.\n const rows = useMemo(() => grouped.flatMap(([, list]) => list), [grouped]);\n\n const { activeIndex: active, moveTo, moveActive } = useRowCursor(rows, query);\n\n // Clearing the query would drop the cursor on its own, but only if it had\n // changed; `moveTo(null)` covers reopening on an already-empty query.\n useOnOpen(open, () => {\n setQuery(\"\");\n moveTo(null);\n });\n\n useEffect(() => {\n if (!open) return;\n const frame = requestAnimationFrame(() => inputRef.current?.focus());\n return () => cancelAnimationFrame(frame);\n }, [open]);\n\n const onKeyDown = (e: React.KeyboardEvent) => {\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n moveActive(1);\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n moveActive(-1);\n } else if (e.key === \"Enter\") {\n e.preventDefault();\n const it = rows[active];\n if (it) {\n it.onSelect();\n setOpen(false);\n }\n }\n };\n\n useEffect(() => {\n if (!open) return;\n const el = listRef.current?.querySelector<HTMLButtonElement>(`[data-index=\"${active}\"]`);\n el?.scrollIntoView({ block: \"nearest\" });\n }, [active, open]);\n\n if (!mounted) return null;\n\n // Portaled to <body> so ancestors with transforms, filters, or fixed\n // positioning can't trap the overlay in their stacking context, and mounted\n // only while open. The chrome is two fixed siblings rather than one wrapper:\n // the backdrop spans the viewport edges but carries the scrim colour, and the\n // layer positioning the panel is inset off every edge. Both hang off\n // `PresenceGate`, so interaction releases in the same commit that starts the\n // exit rather than when it ends — `open` is already false for those frames.\n // See tests/fixed-overlay-edge-sampling.test.tsx.\n return createPortal(\n <AnimatePresence initial={false}>\n {open ? (\n <PresenceGate key=\"backdrop\">\n {({ gate }) => (\n <motion.button\n type=\"button\"\n aria-label=\"Close command palette\"\n initial={{ opacity: 0 }}\n animate={{ opacity: 1 }}\n exit={{\n opacity: 0,\n transition: { duration: 0.12, ease: EASE_OUT },\n }}\n transition={{ duration: 0.18, ease: EASE_OUT }}\n {...gate}\n onClick={() => setOpen(false)}\n className=\"pointer-events-auto fixed inset-0 z-100 bg-background/5 [-webkit-backdrop-filter:blur(12px)_saturate(140%)] [backdrop-filter:blur(12px)_saturate(140%)]\"\n />\n )}\n </PresenceGate>\n ) : null}\n\n {open ? (\n <PresenceGate key=\"panel-layer\">\n {({ isPresent, gate }) => (\n // The layer itself never takes pointer events, so it carries\n // `inert` alone rather than the gate's pointer-events value.\n <div\n inert={!isPresent}\n className=\"pointer-events-none fixed inset-x-4 top-[18vh] bottom-4 z-100 flex items-start justify-center\"\n >\n <motion.div\n role=\"dialog\"\n aria-modal=\"true\"\n aria-label=\"Command palette\"\n initial={{\n opacity: 0,\n y: reduce ? 0 : -8,\n scale: reduce ? 1 : 0.97,\n }}\n animate={{ opacity: 1, y: 0, scale: 1 }}\n exit={{\n opacity: 0,\n y: reduce ? 0 : -8,\n scale: reduce ? 1 : 0.97,\n transition: { duration: 0.12, ease: EASE_OUT },\n }}\n transition={reduce ? { duration: 0.1 } : PANEL_SPRING}\n {...gate}\n onKeyDown={onKeyDown}\n className=\"pointer-events-auto w-full max-w-xl overflow-hidden rounded-2xl border border-border bg-card shadow-2xl will-change-transform\"\n >\n <div className=\"flex items-center gap-3 border-border border-b px-4\">\n <Search className=\"h-4 w-4 text-muted-foreground\" />\n <input\n ref={inputRef}\n value={query}\n onChange={(e) => setQuery(e.target.value)}\n placeholder={placeholder}\n role=\"combobox\"\n // The field only exists while the palette is open.\n aria-expanded=\"true\"\n aria-controls={`${uid}-list`}\n aria-activedescendant={rows.length > 0 ? `${uid}-opt-${active}` : undefined}\n aria-autocomplete=\"list\"\n className={cn(\n \"h-12 flex-1 bg-transparent text-foreground text-sm outline-none placeholder:text-muted-foreground\",\n // The palette focuses this field the moment it opens, and iOS\n // zooms the page in on a focused field under 16px: the fixed\n // overlay is magnified off-center — clipped leading edge, half\n // an icon column — and the zoom outlives the palette. 16px on\n // touch keeps the page at scale 1; pointer devices keep 14px.\n canTouch && \"text-base\",\n )}\n />\n <kbd className=\"hidden rounded border border-border bg-background px-1.5 py-0.5 text-[10px] text-muted-foreground sm:inline-block\">\n ESC\n </kbd>\n </div>\n <div\n ref={listRef}\n id={`${uid}-list`}\n role=\"listbox\"\n aria-label=\"Commands\"\n className=\"max-h-[60vh] overflow-y-auto overscroll-contain p-2 [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden\"\n >\n {rows.length === 0 ? (\n <div className=\"p-8 text-center text-muted-foreground text-sm\">\n {emptyMessage}\n </div>\n ) : (\n grouped.map(([group, list]) => (\n <div key={group} className=\"mb-1 last:mb-0\">\n <div\n aria-hidden\n className=\"px-2 py-1.5 font-semibold text-[10px] text-muted-foreground uppercase tracking-wider\"\n >\n {group}\n </div>\n {list.map((it) => {\n // `rows` holds these very objects, in render order.\n const idx = rows.indexOf(it);\n const isActive = idx === active;\n const Icon = it.icon;\n return (\n <button\n key={it.id}\n type=\"button\"\n id={`${uid}-opt-${idx}`}\n role=\"option\"\n aria-selected={isActive}\n data-index={idx}\n onMouseEnter={() => moveTo(it.id)}\n onClick={() => {\n it.onSelect();\n setOpen(false);\n }}\n className={cn(\n \"relative isolate flex w-full items-center gap-3 rounded-md px-2 py-2 text-left text-sm transition-colors\",\n isActive ? \"text-foreground\" : \"text-muted-foreground\",\n )}\n >\n {isActive ? (\n <motion.span\n layoutId={`${uid}-active`}\n className=\"absolute inset-0 z-0 rounded-md bg-primary/5\"\n transition={\n reduce\n ? { duration: 0 }\n : // Tracks rapid arrow-key navigation — keep it tighter\n // than SPRING_LAYOUT so it never lags the active row.\n {\n type: \"spring\",\n stiffness: 480,\n damping: 38,\n }\n }\n />\n ) : null}\n {Icon ? (\n <Icon className=\"relative z-10 h-4 w-4\" />\n ) : hasIcons ? (\n <span className=\"relative z-10 h-4 w-4\" />\n ) : null}\n <span className=\"relative z-10 flex-1 truncate\">{it.label}</span>\n {it.badge ? (\n <span className=\"relative z-10 shrink-0\">{it.badge}</span>\n ) : null}\n {it.hint ? (\n <kbd className=\"relative z-10 rounded border border-border bg-background px-1.5 py-0.5 text-[10px] text-muted-foreground\">\n {it.hint}\n </kbd>\n ) : null}\n </button>\n );\n })}\n </div>\n ))\n )}\n </div>\n </motion.div>\n </div>\n )}\n </PresenceGate>\n ) : null}\n </AnimatePresence>,\n document.body,\n );\n}\n"],"mappings":";;;;;;;;;;;;;AAmCA,SAAS,WAAW,QAAgB,KAAa;CAC/C,IAAI,CAAC,QAAQ,OAAO;CACpB,SAAS,OAAO,YAAY;CAC5B,MAAM,IAAI,YAAY;CACtB,IAAI,IAAI;CACR,KAAK,MAAM,MAAM,KAAK;EACpB,IAAI,OAAO,OAAO,IAAI;EACtB,IAAI,MAAM,OAAO,QAAQ,OAAO;CAClC;CACA,OAAO;AACT;AAIA,MAAM,eAAe;CACnB,MAAM;CACN,WAAW;CACX,SAAS;CACT,MAAM;AACR;AAEA,SAAgB,eAAe,EAC7B,OACA,WAAW,KACX,cAAc,6BACd,eAAe,qBACf,MAAM,gBACN,gBACsB;CACtB,MAAM,CAAC,cAAc,mBAAmB,SAAS,KAAK;CACtD,MAAM,aAAa,mBAAmB,KAAA;CACtC,MAAM,OAAO,aAAa,iBAAiB;CAC3C,MAAM,UAAU,aACb,MAAe;EACd,IAAI,CAAC,YAAY,gBAAgB,CAAC;EAClC,eAAe,CAAC;CAClB,GACA,CAAC,YAAY,YAAY,CAC3B;CAEA,MAAM,CAAC,OAAO,YAAY,SAAS,EAAE;CAErC,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAC5C,gBAAgB,WAAW,IAAI,GAAG,CAAC,CAAC;CACpC,MAAM,MAAM,MAAM;CAClB,MAAM,SAAS,iBAAiB;CAChC,MAAM,WAAW,gBA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/components/motion/morphing-search.tsx"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"morphing-search.d.ts","names":[],"sources":["../../../src/components/motion/morphing-search.tsx"],"mappings":";;KAyCY;EACV;EACA;EACA;EACA;EACA,OAAO;EACP;;UAGe;EACf,OAAO;EACP;EACA;;EAEA;EACA;EACA;EACA;EACA,gBAAgB;EAChB,iBAAiB;EACjB,YAAY,MAAM;EAClB;;iBAmBc,iBACd,OACA,aACA,UACA,UACA,cACA,MAAM,gBACN,aACA,cACA,eACA,UACA,aACC,sCAAmB,IAAA"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { useOnOpen } from "../../hooks/use-on-open.js";
|
|
3
|
+
import { useRowCursor } from "../../hooks/use-row-cursor.js";
|
|
2
4
|
import { EASE_OUT, SPRING_LAYOUT } from "../../lib/ease.js";
|
|
3
|
-
import { useCallback, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
5
|
+
import { useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
4
6
|
import { cn } from "@kumix/utils";
|
|
5
7
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
6
8
|
import { AnimatePresence, LayoutGroup, motion, useReducedMotion } from "motion/react";
|
|
@@ -23,7 +25,6 @@ function isEditableTarget(target) {
|
|
|
23
25
|
function MorphingSearch({ items, placeholder = "Search", shortcut = "f", iconOnly = false, emptyMessage = "No results found.", open: controlledOpen, defaultOpen = false, onOpenChange, onQueryChange, onSelect, className }) {
|
|
24
26
|
const [internalOpen, setInternalOpen] = useState(defaultOpen);
|
|
25
27
|
const [query, setQuery] = useState("");
|
|
26
|
-
const [activeIndex, setActiveIndex] = useState(0);
|
|
27
28
|
const [mounted, setMounted] = useState(false);
|
|
28
29
|
const [backgroundScrollLocked, setBackgroundScrollLocked] = useState(defaultOpen);
|
|
29
30
|
const [anchorRect, setAnchorRect] = useState({
|
|
@@ -63,9 +64,18 @@ function MorphingSearch({ items, placeholder = "Search", shortcut = "f", iconOnl
|
|
|
63
64
|
previousFocusRef.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
64
65
|
setOpen(true);
|
|
65
66
|
}, [measureAnchor, setOpen]);
|
|
67
|
+
const filteredItems = useMemo(() => {
|
|
68
|
+
const needle = query.trim().toLowerCase();
|
|
69
|
+
if (!needle) return items;
|
|
70
|
+
return items.filter((item) => [
|
|
71
|
+
item.title,
|
|
72
|
+
item.description ?? "",
|
|
73
|
+
...item.keywords ?? []
|
|
74
|
+
].join(" ").toLowerCase().includes(needle));
|
|
75
|
+
}, [items, query]);
|
|
76
|
+
const { activeIndex, moveTo, moveActive } = useRowCursor(filteredItems, query);
|
|
66
77
|
const updateQuery = useCallback((next) => {
|
|
67
78
|
setQuery(next);
|
|
68
|
-
setActiveIndex(0);
|
|
69
79
|
onQueryChange?.(next);
|
|
70
80
|
}, [onQueryChange]);
|
|
71
81
|
const closeSearch = useCallback(() => {
|
|
@@ -132,9 +142,17 @@ function MorphingSearch({ items, placeholder = "Search", shortcut = "f", iconOnl
|
|
|
132
142
|
openSearch,
|
|
133
143
|
shortcut
|
|
134
144
|
]);
|
|
145
|
+
useOnOpen(open, () => {
|
|
146
|
+
setQuery("");
|
|
147
|
+
moveTo(null);
|
|
148
|
+
});
|
|
149
|
+
const notifyQuery = useRef(onQueryChange);
|
|
150
|
+
useLayoutEffect(() => {
|
|
151
|
+
notifyQuery.current = onQueryChange;
|
|
152
|
+
});
|
|
135
153
|
useEffect(() => {
|
|
136
154
|
if (open) {
|
|
137
|
-
|
|
155
|
+
notifyQuery.current?.("");
|
|
138
156
|
const frame = requestAnimationFrame(() => inputRef.current?.focus());
|
|
139
157
|
return () => cancelAnimationFrame(frame);
|
|
140
158
|
}
|
|
@@ -145,23 +163,10 @@ function MorphingSearch({ items, placeholder = "Search", shortcut = "f", iconOnl
|
|
|
145
163
|
});
|
|
146
164
|
return () => cancelAnimationFrame(frame);
|
|
147
165
|
}
|
|
148
|
-
}, [open
|
|
166
|
+
}, [open]);
|
|
149
167
|
useEffect(() => {
|
|
150
168
|
wasOpenRef.current = open;
|
|
151
169
|
}, [open]);
|
|
152
|
-
const filteredItems = useMemo(() => {
|
|
153
|
-
const needle = query.trim().toLowerCase();
|
|
154
|
-
if (!needle) return items;
|
|
155
|
-
return items.filter((item) => [
|
|
156
|
-
item.title,
|
|
157
|
-
item.description ?? "",
|
|
158
|
-
...item.keywords ?? []
|
|
159
|
-
].join(" ").toLowerCase().includes(needle));
|
|
160
|
-
}, [items, query]);
|
|
161
|
-
useEffect(() => {
|
|
162
|
-
if (activeIndex < filteredItems.length) return;
|
|
163
|
-
setActiveIndex(Math.max(0, filteredItems.length - 1));
|
|
164
|
-
}, [activeIndex, filteredItems.length]);
|
|
165
170
|
useEffect(() => {
|
|
166
171
|
if (!open) return;
|
|
167
172
|
listRef.current?.querySelector(`[data-index="${activeIndex}"]`)?.scrollIntoView({ block: "nearest" });
|
|
@@ -174,13 +179,12 @@ function MorphingSearch({ items, placeholder = "Search", shortcut = "f", iconOnl
|
|
|
174
179
|
const handleDialogKeyDown = (event) => {
|
|
175
180
|
if (event.key === "ArrowDown") {
|
|
176
181
|
event.preventDefault();
|
|
177
|
-
|
|
178
|
-
setActiveIndex((current) => Math.min(current + 1, filteredItems.length - 1));
|
|
182
|
+
moveActive(1);
|
|
179
183
|
return;
|
|
180
184
|
}
|
|
181
185
|
if (event.key === "ArrowUp") {
|
|
182
186
|
event.preventDefault();
|
|
183
|
-
|
|
187
|
+
moveActive(-1);
|
|
184
188
|
return;
|
|
185
189
|
}
|
|
186
190
|
if (event.key === "Enter") {
|
|
@@ -342,8 +346,8 @@ function MorphingSearch({ items, placeholder = "Search", shortcut = "f", iconOnl
|
|
|
342
346
|
role: "option",
|
|
343
347
|
"aria-selected": active,
|
|
344
348
|
"data-index": index,
|
|
345
|
-
onMouseMove: () =>
|
|
346
|
-
onFocus: () =>
|
|
349
|
+
onMouseMove: () => moveTo(item.id),
|
|
350
|
+
onFocus: () => moveTo(item.id),
|
|
347
351
|
onClick: () => selectItem(item),
|
|
348
352
|
className: "relative flex w-full items-center gap-2.5 rounded-lg px-3 py-2.5 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",
|
|
349
353
|
children: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"morphing-search.js","names":[],"sources":["../../../src/components/motion/morphing-search.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type KeyboardEvent as ReactKeyboardEvent,\n useCallback,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { type LucideIcon, Search } from \"lucide-react\";\nimport {\n AnimatePresence,\n LayoutGroup,\n motion,\n type Transition,\n useReducedMotion,\n} from \"motion/react\";\nimport { createPortal } from \"react-dom\";\n\nimport { cn } from \"@kumix/utils\";\nimport { EASE_OUT, SPRING_LAYOUT } from \"../../lib/ease\";\n\n// Keeps the Wallet Card feel with a little more time to read the morph.\nconst SEARCH_MORPH: Transition = {\n type: \"spring\",\n duration: 0.58,\n bounce: 0.22,\n};\n\n// Keep the spring on the shell, but unfold complex clip-path values with the\n// same progressive tween as Morph Popover so the content never snaps ahead.\nconst SEARCH_CLIP_TRANSITION: Transition = {\n duration: 0.32,\n ease: EASE_OUT,\n};\n\nexport type MorphingSearchItem = {\n id: string;\n title: string;\n description?: string;\n keywords?: string[];\n icon?: LucideIcon;\n onSelect?: () => void;\n};\n\nexport interface MorphingSearchProps {\n items: MorphingSearchItem[];\n placeholder?: string;\n shortcut?: string;\n /** Render the closed trigger as a compact search icon. */\n iconOnly?: boolean;\n emptyMessage?: string;\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n onQueryChange?: (query: string) => void;\n onSelect?: (item: MorphingSearchItem) => void;\n className?: string;\n}\n\ntype AnchorRect = {\n top: number;\n left: number;\n width: number;\n};\n\nfunction isEditableTarget(target: EventTarget | null) {\n if (!(target instanceof HTMLElement)) return false;\n return (\n target.isContentEditable ||\n target instanceof HTMLInputElement ||\n target instanceof HTMLTextAreaElement ||\n target instanceof HTMLSelectElement\n );\n}\n\nexport function MorphingSearch({\n items,\n placeholder = \"Search\",\n shortcut = \"f\",\n iconOnly = false,\n emptyMessage = \"No results found.\",\n open: controlledOpen,\n defaultOpen = false,\n onOpenChange,\n onQueryChange,\n onSelect,\n className,\n}: MorphingSearchProps) {\n const [internalOpen, setInternalOpen] = useState(defaultOpen);\n const [query, setQuery] = useState(\"\");\n const [activeIndex, setActiveIndex] = useState(0);\n const [mounted, setMounted] = useState(false);\n const [backgroundScrollLocked, setBackgroundScrollLocked] = useState(defaultOpen);\n const [anchorRect, setAnchorRect] = useState<AnchorRect>({\n top: 16,\n left: 16,\n width: 288,\n });\n const open = controlledOpen ?? internalOpen;\n const controlled = controlledOpen !== undefined;\n const reduce = useReducedMotion();\n const uid = useId();\n const anchorRef = useRef<HTMLDivElement>(null);\n const triggerRef = useRef<HTMLButtonElement>(null);\n const inputRef = useRef<HTMLInputElement>(null);\n const dialogRef = useRef<HTMLDivElement>(null);\n const listRef = useRef<HTMLDivElement>(null);\n const previousFocusRef = useRef<HTMLElement | null>(null);\n const wasOpenRef = useRef(open);\n const transition: Transition = reduce ? { duration: 0 } : SPRING_LAYOUT;\n const morphTransition: Transition = reduce ? { duration: 0 } : SEARCH_MORPH;\n\n const setOpen = useCallback(\n (next: boolean) => {\n if (!controlled) setInternalOpen(next);\n onOpenChange?.(next);\n },\n [controlled, onOpenChange],\n );\n\n const measureAnchor = useCallback(() => {\n const rect = anchorRef.current?.getBoundingClientRect();\n if (!rect || rect.width === 0) return;\n setAnchorRect({ top: rect.top, left: rect.left, width: rect.width });\n }, []);\n\n const openSearch = useCallback(() => {\n measureAnchor();\n setBackgroundScrollLocked(true);\n previousFocusRef.current =\n document.activeElement instanceof HTMLElement ? document.activeElement : null;\n setOpen(true);\n }, [measureAnchor, setOpen]);\n\n const updateQuery = useCallback(\n (next: string) => {\n setQuery(next);\n setActiveIndex(0);\n onQueryChange?.(next);\n },\n [onQueryChange],\n );\n\n const closeSearch = useCallback(() => {\n updateQuery(\"\");\n setOpen(false);\n }, [setOpen, updateQuery]);\n\n useEffect(() => setMounted(true), []);\n\n useEffect(() => {\n if (open) setBackgroundScrollLocked(true);\n }, [open]);\n\n useEffect(() => {\n measureAnchor();\n const anchor = anchorRef.current;\n const observer =\n anchor && typeof ResizeObserver !== \"undefined\" ? new ResizeObserver(measureAnchor) : null;\n if (anchor) observer?.observe(anchor);\n window.addEventListener(\"resize\", measureAnchor);\n document.addEventListener(\"scroll\", measureAnchor, true);\n window.visualViewport?.addEventListener(\"resize\", measureAnchor);\n window.visualViewport?.addEventListener(\"scroll\", measureAnchor);\n return () => {\n observer?.disconnect();\n window.removeEventListener(\"resize\", measureAnchor);\n document.removeEventListener(\"scroll\", measureAnchor, true);\n window.visualViewport?.removeEventListener(\"resize\", measureAnchor);\n window.visualViewport?.removeEventListener(\"scroll\", measureAnchor);\n };\n }, [measureAnchor]);\n\n useEffect(() => {\n if (!backgroundScrollLocked) return;\n\n const preventBackgroundWheel = (event: WheelEvent) => {\n const target = event.target;\n if (target instanceof Node && listRef.current?.contains(target)) return;\n event.preventDefault();\n };\n const preventBackgroundTouch = (event: TouchEvent) => {\n const target = event.target;\n if (target instanceof Node && listRef.current?.contains(target)) return;\n event.preventDefault();\n };\n\n document.addEventListener(\"wheel\", preventBackgroundWheel, {\n passive: false,\n });\n document.addEventListener(\"touchmove\", preventBackgroundTouch, {\n passive: false,\n });\n return () => {\n document.removeEventListener(\"wheel\", preventBackgroundWheel);\n document.removeEventListener(\"touchmove\", preventBackgroundTouch);\n };\n }, [backgroundScrollLocked]);\n\n useEffect(() => {\n const handleShortcut = (event: KeyboardEvent) => {\n if (event.key === \"Escape\" && open) {\n event.preventDefault();\n closeSearch();\n return;\n }\n\n if (\n !open &&\n shortcut &&\n event.key.toLowerCase() === shortcut.toLowerCase() &&\n !event.repeat &&\n !event.metaKey &&\n !event.ctrlKey &&\n !event.altKey &&\n !event.shiftKey &&\n !isEditableTarget(event.target)\n ) {\n event.preventDefault();\n openSearch();\n }\n };\n\n window.addEventListener(\"keydown\", handleShortcut);\n return () => window.removeEventListener(\"keydown\", handleShortcut);\n }, [closeSearch, open, openSearch, shortcut]);\n\n useEffect(() => {\n if (open) {\n updateQuery(\"\");\n const frame = requestAnimationFrame(() => inputRef.current?.focus());\n return () => cancelAnimationFrame(frame);\n }\n\n if (wasOpenRef.current) {\n const frame = requestAnimationFrame(() => {\n const previousFocus = previousFocusRef.current;\n const focusTarget = previousFocus?.isConnected ? previousFocus : triggerRef.current;\n focusTarget?.focus();\n });\n return () => cancelAnimationFrame(frame);\n }\n }, [open, updateQuery]);\n\n useEffect(() => {\n wasOpenRef.current = open;\n }, [open]);\n\n const filteredItems = useMemo(() => {\n const needle = query.trim().toLowerCase();\n if (!needle) return items;\n\n return items.filter((item) =>\n [item.title, item.description ?? \"\", ...(item.keywords ?? [])]\n .join(\" \")\n .toLowerCase()\n .includes(needle),\n );\n }, [items, query]);\n\n useEffect(() => {\n if (activeIndex < filteredItems.length) return;\n setActiveIndex(Math.max(0, filteredItems.length - 1));\n }, [activeIndex, filteredItems.length]);\n\n useEffect(() => {\n if (!open) return;\n listRef.current\n ?.querySelector<HTMLElement>(`[data-index=\"${activeIndex}\"]`)\n ?.scrollIntoView({ block: \"nearest\" });\n }, [activeIndex, open]);\n\n const selectItem = useCallback(\n (item: MorphingSearchItem) => {\n item.onSelect?.();\n onSelect?.(item);\n closeSearch();\n },\n [closeSearch, onSelect],\n );\n\n const handleDialogKeyDown = (event: ReactKeyboardEvent<HTMLDivElement>) => {\n if (event.key === \"ArrowDown\") {\n event.preventDefault();\n if (filteredItems.length === 0) return;\n setActiveIndex((current) => Math.min(current + 1, filteredItems.length - 1));\n return;\n }\n\n if (event.key === \"ArrowUp\") {\n event.preventDefault();\n setActiveIndex((current) => Math.max(current - 1, 0));\n return;\n }\n\n if (event.key === \"Enter\") {\n event.preventDefault();\n const item = filteredItems[activeIndex];\n if (item) selectItem(item);\n return;\n }\n\n if (event.key !== \"Tab\" || !dialogRef.current) return;\n const focusable = Array.from(\n dialogRef.current.querySelectorAll<HTMLElement>(\n 'input, button:not([disabled]), [tabindex]:not([tabindex=\"-1\"])',\n ),\n );\n const first = focusable[0];\n const last = focusable.at(-1);\n if (!first || !last) return;\n\n if (event.shiftKey && document.activeElement === first) {\n event.preventDefault();\n last.focus();\n } else if (!event.shiftKey && document.activeElement === last) {\n event.preventDefault();\n first.focus();\n }\n };\n\n const shellLayoutId = `${uid}-shell`;\n const listboxId = `${uid}-results`;\n const panelWidth = mounted\n ? Math.max(anchorRect.width, Math.min(448, window.innerWidth - anchorRect.left - 16))\n : anchorRect.width;\n const resultsHeight = mounted\n ? Math.max(96, Math.min(288, window.innerHeight - anchorRect.top - 80))\n : 288;\n const collapsedContentClip = `inset(0px ${Math.max(\n 0,\n panelWidth - anchorRect.width,\n )}px ${resultsHeight}px 0px round 12px)`;\n const expandedContentClip = \"inset(0px 0px 0px 0px round 12px)\";\n\n // Neither grouping layer carries a box: they only hold `inert`/`aria-hidden`,\n // the z-index and the presence key, and every child below is `fixed` and\n // resolves against the viewport itself. The click catcher spans the viewport\n // edges but has no children and filters nothing, so it is not a sampling\n const overlay = mounted\n ? createPortal(\n <div\n aria-hidden={!open}\n inert={!open}\n className=\"pointer-events-none fixed top-0 left-0 z-50 size-0\"\n >\n <AnimatePresence\n initial={false}\n mode=\"popLayout\"\n onExitComplete={() => setBackgroundScrollLocked(false)}\n >\n {open ? (\n <motion.div key=\"morphing-search-overlay\" className=\"fixed top-0 left-0 size-0\">\n <button\n type=\"button\"\n aria-label=\"Close search\"\n className=\"pointer-events-auto fixed inset-0 cursor-default bg-transparent\"\n onClick={closeSearch}\n />\n\n <motion.div\n layoutId={shellLayoutId}\n aria-hidden=\"true\"\n className=\"fixed z-10 rounded-xl bg-background/90 backdrop-blur-xl\"\n style={{\n top: anchorRect.top,\n left: anchorRect.left,\n width: panelWidth,\n height: 48 + resultsHeight,\n boxShadow: \"inset 0 0 0 1px var(--color-border)\",\n }}\n transition={morphTransition}\n />\n\n <motion.div\n ref={dialogRef}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-label=\"Search\"\n onKeyDown={handleDialogKeyDown}\n initial={reduce ? false : { opacity: 0, clipPath: collapsedContentClip }}\n animate={{ opacity: 1, clipPath: expandedContentClip }}\n exit={{\n opacity: 0,\n clipPath: collapsedContentClip,\n transition: reduce\n ? { duration: 0 }\n : {\n clipPath: SEARCH_CLIP_TRANSITION,\n opacity: SEARCH_MORPH,\n },\n }}\n transition={\n reduce\n ? { duration: 0 }\n : {\n clipPath: SEARCH_CLIP_TRANSITION,\n opacity: SEARCH_MORPH,\n }\n }\n className=\"pointer-events-auto fixed z-20 overflow-hidden rounded-xl\"\n style={{\n top: anchorRect.top,\n left: anchorRect.left,\n width: panelWidth,\n }}\n >\n <div\n className={cn(\n \"flex h-12 items-center gap-2.5 border-border border-b\",\n iconOnly ? \"px-4\" : \"px-3.5\",\n )}\n >\n <span className=\"shrink-0\">\n <Search className=\"size-4 text-muted-foreground\" />\n </span>\n <div className=\"flex h-10 min-w-0 flex-1 items-center\">\n <input\n ref={inputRef}\n value={query}\n onChange={(event) => updateQuery(event.target.value)}\n role=\"combobox\"\n aria-label={placeholder}\n aria-expanded=\"true\"\n aria-controls={listboxId}\n aria-autocomplete=\"list\"\n aria-activedescendant={\n filteredItems.length > 0 ? `${uid}-option-${activeIndex}` : undefined\n }\n placeholder={placeholder}\n className=\"size-full bg-transparent text-foreground text-sm outline-none placeholder:text-muted-foreground\"\n />\n </div>\n <kbd className=\"flex h-7 shrink-0 items-center rounded-md border border-border px-2 text-muted-foreground text-xs\">\n Esc\n </kbd>\n </div>\n\n <motion.div\n ref={listRef}\n id={listboxId}\n role=\"listbox\"\n aria-label=\"Search results\"\n transition={reduce ? { duration: 0 } : undefined}\n variants={\n reduce\n ? undefined\n : {\n closed: {\n opacity: 0,\n transform: \"translateY(6px)\",\n transition: {\n duration: 0.16,\n delay: 0.18,\n ease: EASE_OUT,\n },\n },\n open: {\n opacity: 1,\n transform: \"translateY(0px)\",\n transition: {\n duration: 0.16,\n ease: EASE_OUT,\n },\n },\n }\n }\n initial={reduce ? { opacity: 1, transform: \"translateY(0px)\" } : \"closed\"}\n animate={reduce ? { opacity: 1, transform: \"translateY(0px)\" } : \"open\"}\n exit={reduce ? undefined : \"closed\"}\n className=\"overflow-y-auto overscroll-contain p-2\"\n style={{\n maxHeight: resultsHeight,\n }}\n >\n {filteredItems.length > 0 ? (\n filteredItems.map((item, index) => {\n const Icon = item.icon;\n const active = index === activeIndex;\n return (\n <button\n key={item.id}\n id={`${uid}-option-${index}`}\n type=\"button\"\n role=\"option\"\n aria-selected={active}\n data-index={index}\n onMouseMove={() => setActiveIndex(index)}\n onFocus={() => setActiveIndex(index)}\n onClick={() => selectItem(item)}\n className=\"relative flex w-full items-center gap-2.5 rounded-lg px-3 py-2.5 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset\"\n >\n {active ? (\n <motion.span\n layoutId={`${uid}-active-result`}\n className=\"absolute inset-0 rounded-lg bg-foreground/5\"\n transition={transition}\n />\n ) : null}\n {Icon ? (\n <Icon className=\"relative size-4 shrink-0 text-muted-foreground\" />\n ) : null}\n <span className=\"relative min-w-0\">\n <span className=\"block truncate font-medium text-foreground text-sm\">\n {item.title}\n </span>\n {item.description ? (\n <span className=\"block truncate text-muted-foreground text-xs\">\n {item.description}\n </span>\n ) : null}\n </span>\n </button>\n );\n })\n ) : (\n <p className=\"px-3 py-8 text-center text-muted-foreground text-sm\">\n {emptyMessage}\n </p>\n )}\n </motion.div>\n </motion.div>\n </motion.div>\n ) : null}\n </AnimatePresence>\n </div>,\n document.body,\n )\n : null;\n\n return (\n <LayoutGroup id={uid}>\n <div\n ref={anchorRef}\n className={cn(\"relative\", iconOnly ? \"size-12\" : \"h-12 w-72 max-w-full\", className)}\n >\n {!open ? (\n <motion.button\n ref={triggerRef}\n key=\"morphing-search-trigger\"\n layoutId={shellLayoutId}\n type=\"button\"\n aria-haspopup=\"dialog\"\n aria-expanded=\"false\"\n aria-label={placeholder}\n onClick={openSearch}\n transition={morphTransition}\n style={{\n boxShadow: \"inset 0 0 0 1px var(--search-trigger-stroke)\",\n }}\n className={cn(\n \"flex size-full items-center rounded-xl bg-background/60 text-left outline-none backdrop-blur-md [--search-trigger-stroke:var(--color-border)] focus-visible:ring-2 focus-visible:ring-ring hover:[--search-trigger-stroke:var(--color-border-strong)]\",\n iconOnly ? \"cursor-pointer justify-center\" : \"cursor-text px-3.5\",\n )}\n />\n ) : null}\n <motion.div\n aria-hidden=\"true\"\n initial={false}\n animate={{ opacity: open ? 0 : 1 }}\n transition={\n reduce\n ? { duration: 0 }\n : {\n duration: 0.1,\n delay: open ? 0.1 : 0.12,\n ease: EASE_OUT,\n }\n }\n className={cn(\n \"pointer-events-none absolute inset-0 flex items-center\",\n backgroundScrollLocked && \"z-60\",\n iconOnly ? \"justify-center\" : \"gap-2.5 px-3.5\",\n )}\n >\n <Search className=\"size-4 shrink-0 text-muted-foreground\" />\n {iconOnly ? null : (\n <>\n <span className=\"min-w-0 flex-1 truncate text-muted-foreground text-sm\">\n {placeholder}\n </span>\n {shortcut ? (\n <kbd className=\"flex h-7 min-w-7 shrink-0 items-center justify-center rounded-md border border-border px-2 text-muted-foreground text-xs\">\n {shortcut.toUpperCase()}\n </kbd>\n ) : null}\n </>\n )}\n </motion.div>\n </div>\n {overlay}\n </LayoutGroup>\n );\n}\n"],"mappings":";;;;;;;;;AAyBA,MAAM,eAA2B;CAC/B,MAAM;CACN,UAAU;CACV,QAAQ;AACV;AAIA,MAAM,yBAAqC;CACzC,UAAU;CACV,MAAM;AACR;AAgCA,SAAS,iBAAiB,QAA4B;CACpD,IAAI,EAAE,kBAAkB,cAAc,OAAO;CAC7C,OACE,OAAO,qBACP,kBAAkB,oBAClB,kBAAkB,uBAClB,kBA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PACA,WAAW,kCAAkC,oBAC/C;GACD,GAfK,yBAeL,IACC,MACJ,qBAAC,OAAO,KAAR;IACE,eAAY;IACZ,SAAS;IACT,SAAS,EAAE,SAAS,OAAO,IAAI,EAAE;IACjC,YACE,SACI,EAAE,UAAU,EAAE,IACd;KACE,UAAU;KACV,OAAO,OAAO,KAAM;KACpB,MAAM;IACR;IAEN,WAAW,GACT,0DACA,0BAA0B,QAC1B,WAAW,mBAAmB,gBAChC;IAjBF,UAAA,CAmBE,oBAAC,QAAD,EAAQ,WAAU,wCAAyC,CAAA,GAC1D,WAAW,OACV,qBAAA,YAAA,EAAA,UAAA,CACE,oBAAC,QAAD;KAAM,WAAU;KACb,UAAA;IACG,CAAA,GACL,WACC,oBAAC,OAAD;KAAK,WAAU;KACZ,UAAA,SAAS,YAAY;IACnB,CAAA,IACH,IACJ,EAAA,CAAA,CAEM;GACT,CAAA,CAAA;EACJ,CAAA,GAAA,OACU;;AAEjB"}
|
|
1
|
+
{"version":3,"file":"morphing-search.js","names":[],"sources":["../../../src/components/motion/morphing-search.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type KeyboardEvent as ReactKeyboardEvent,\n useCallback,\n useEffect,\n useId,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { type LucideIcon, Search } from \"lucide-react\";\nimport {\n AnimatePresence,\n LayoutGroup,\n motion,\n type Transition,\n useReducedMotion,\n} from \"motion/react\";\nimport { createPortal } from \"react-dom\";\n\nimport { cn } from \"@kumix/utils\";\nimport { useOnOpen } from \"../../hooks/use-on-open\";\nimport { useRowCursor } from \"../../hooks/use-row-cursor\";\nimport { EASE_OUT, SPRING_LAYOUT } from \"../../lib/ease\";\n\n// Keeps the Wallet Card feel with a little more time to read the morph.\nconst SEARCH_MORPH: Transition = {\n type: \"spring\",\n duration: 0.58,\n bounce: 0.22,\n};\n\n// Keep the spring on the shell, but unfold complex clip-path values with the\n// same progressive tween as Morph Popover so the content never snaps ahead.\nconst SEARCH_CLIP_TRANSITION: Transition = {\n duration: 0.32,\n ease: EASE_OUT,\n};\n\nexport type MorphingSearchItem = {\n id: string;\n title: string;\n description?: string;\n keywords?: string[];\n icon?: LucideIcon;\n onSelect?: () => void;\n};\n\nexport interface MorphingSearchProps {\n items: MorphingSearchItem[];\n placeholder?: string;\n shortcut?: string;\n /** Render the closed trigger as a compact search icon. */\n iconOnly?: boolean;\n emptyMessage?: string;\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n onQueryChange?: (query: string) => void;\n onSelect?: (item: MorphingSearchItem) => void;\n className?: string;\n}\n\ntype AnchorRect = {\n top: number;\n left: number;\n width: number;\n};\n\nfunction isEditableTarget(target: EventTarget | null) {\n if (!(target instanceof HTMLElement)) return false;\n return (\n target.isContentEditable ||\n target instanceof HTMLInputElement ||\n target instanceof HTMLTextAreaElement ||\n target instanceof HTMLSelectElement\n );\n}\n\nexport function MorphingSearch({\n items,\n placeholder = \"Search\",\n shortcut = \"f\",\n iconOnly = false,\n emptyMessage = \"No results found.\",\n open: controlledOpen,\n defaultOpen = false,\n onOpenChange,\n onQueryChange,\n onSelect,\n className,\n}: MorphingSearchProps) {\n const [internalOpen, setInternalOpen] = useState(defaultOpen);\n const [query, setQuery] = useState(\"\");\n const [mounted, setMounted] = useState(false);\n const [backgroundScrollLocked, setBackgroundScrollLocked] = useState(defaultOpen);\n const [anchorRect, setAnchorRect] = useState<AnchorRect>({\n top: 16,\n left: 16,\n width: 288,\n });\n const open = controlledOpen ?? internalOpen;\n const controlled = controlledOpen !== undefined;\n const reduce = useReducedMotion();\n const uid = useId();\n const anchorRef = useRef<HTMLDivElement>(null);\n const triggerRef = useRef<HTMLButtonElement>(null);\n const inputRef = useRef<HTMLInputElement>(null);\n const dialogRef = useRef<HTMLDivElement>(null);\n const listRef = useRef<HTMLDivElement>(null);\n const previousFocusRef = useRef<HTMLElement | null>(null);\n const wasOpenRef = useRef(open);\n const transition: Transition = reduce ? { duration: 0 } : SPRING_LAYOUT;\n const morphTransition: Transition = reduce ? { duration: 0 } : SEARCH_MORPH;\n\n const setOpen = useCallback(\n (next: boolean) => {\n if (!controlled) setInternalOpen(next);\n onOpenChange?.(next);\n },\n [controlled, onOpenChange],\n );\n\n const measureAnchor = useCallback(() => {\n const rect = anchorRef.current?.getBoundingClientRect();\n if (!rect || rect.width === 0) return;\n setAnchorRect({ top: rect.top, left: rect.left, width: rect.width });\n }, []);\n\n const openSearch = useCallback(() => {\n measureAnchor();\n setBackgroundScrollLocked(true);\n previousFocusRef.current =\n document.activeElement instanceof HTMLElement ? document.activeElement : null;\n setOpen(true);\n }, [measureAnchor, setOpen]);\n\n const filteredItems = useMemo(() => {\n const needle = query.trim().toLowerCase();\n if (!needle) return items;\n\n return items.filter((item) =>\n [item.title, item.description ?? \"\", ...(item.keywords ?? [])]\n .join(\" \")\n .toLowerCase()\n .includes(needle),\n );\n }, [items, query]);\n\n const { activeIndex, moveTo, moveActive } = useRowCursor(filteredItems, query);\n\n // The cursor is stamped with the query, so changing it drops the highlight\n // without this having to say so.\n const updateQuery = useCallback(\n (next: string) => {\n setQuery(next);\n onQueryChange?.(next);\n },\n [onQueryChange],\n );\n\n const closeSearch = useCallback(() => {\n updateQuery(\"\");\n setOpen(false);\n }, [setOpen, updateQuery]);\n\n useEffect(() => setMounted(true), []);\n\n useEffect(() => {\n if (open) setBackgroundScrollLocked(true);\n }, [open]);\n\n useEffect(() => {\n measureAnchor();\n const anchor = anchorRef.current;\n const observer =\n anchor && typeof ResizeObserver !== \"undefined\" ? new ResizeObserver(measureAnchor) : null;\n if (anchor) observer?.observe(anchor);\n window.addEventListener(\"resize\", measureAnchor);\n document.addEventListener(\"scroll\", measureAnchor, true);\n window.visualViewport?.addEventListener(\"resize\", measureAnchor);\n window.visualViewport?.addEventListener(\"scroll\", measureAnchor);\n return () => {\n observer?.disconnect();\n window.removeEventListener(\"resize\", measureAnchor);\n document.removeEventListener(\"scroll\", measureAnchor, true);\n window.visualViewport?.removeEventListener(\"resize\", measureAnchor);\n window.visualViewport?.removeEventListener(\"scroll\", measureAnchor);\n };\n }, [measureAnchor]);\n\n useEffect(() => {\n if (!backgroundScrollLocked) return;\n\n const preventBackgroundWheel = (event: WheelEvent) => {\n const target = event.target;\n if (target instanceof Node && listRef.current?.contains(target)) return;\n event.preventDefault();\n };\n const preventBackgroundTouch = (event: TouchEvent) => {\n const target = event.target;\n if (target instanceof Node && listRef.current?.contains(target)) return;\n event.preventDefault();\n };\n\n document.addEventListener(\"wheel\", preventBackgroundWheel, {\n passive: false,\n });\n document.addEventListener(\"touchmove\", preventBackgroundTouch, {\n passive: false,\n });\n return () => {\n document.removeEventListener(\"wheel\", preventBackgroundWheel);\n document.removeEventListener(\"touchmove\", preventBackgroundTouch);\n };\n }, [backgroundScrollLocked]);\n\n useEffect(() => {\n const handleShortcut = (event: KeyboardEvent) => {\n if (event.key === \"Escape\" && open) {\n event.preventDefault();\n closeSearch();\n return;\n }\n\n if (\n !open &&\n shortcut &&\n event.key.toLowerCase() === shortcut.toLowerCase() &&\n !event.repeat &&\n !event.metaKey &&\n !event.ctrlKey &&\n !event.altKey &&\n !event.shiftKey &&\n !isEditableTarget(event.target)\n ) {\n event.preventDefault();\n openSearch();\n }\n };\n\n window.addEventListener(\"keydown\", handleShortcut);\n return () => window.removeEventListener(\"keydown\", handleShortcut);\n }, [closeSearch, open, openSearch, shortcut]);\n\n // Only this component's own state. Telling the consumer the query changed is\n // a side effect, so it waits for the effect below.\n useOnOpen(open, () => {\n setQuery(\"\");\n moveTo(null);\n });\n\n // Keyed to `open` alone. `onQueryChange` is read through a ref because an\n // inline one changes identity on every keystroke, and this effect clearing\n // the field on every keystroke is exactly what that costs. Written after\n // commit for the reason `lib/hooks/use-row-cursor.ts` gives at length.\n const notifyQuery = useRef(onQueryChange);\n useLayoutEffect(() => {\n notifyQuery.current = onQueryChange;\n });\n\n useEffect(() => {\n if (open) {\n notifyQuery.current?.(\"\");\n const frame = requestAnimationFrame(() => inputRef.current?.focus());\n return () => cancelAnimationFrame(frame);\n }\n\n if (wasOpenRef.current) {\n const frame = requestAnimationFrame(() => {\n const previousFocus = previousFocusRef.current;\n const focusTarget = previousFocus?.isConnected ? previousFocus : triggerRef.current;\n focusTarget?.focus();\n });\n return () => cancelAnimationFrame(frame);\n }\n }, [open]);\n\n useEffect(() => {\n wasOpenRef.current = open;\n }, [open]);\n\n useEffect(() => {\n if (!open) return;\n listRef.current\n ?.querySelector<HTMLElement>(`[data-index=\"${activeIndex}\"]`)\n ?.scrollIntoView({ block: \"nearest\" });\n }, [activeIndex, open]);\n\n const selectItem = useCallback(\n (item: MorphingSearchItem) => {\n item.onSelect?.();\n onSelect?.(item);\n closeSearch();\n },\n [closeSearch, onSelect],\n );\n\n const handleDialogKeyDown = (event: ReactKeyboardEvent<HTMLDivElement>) => {\n if (event.key === \"ArrowDown\") {\n event.preventDefault();\n moveActive(1);\n return;\n }\n\n if (event.key === \"ArrowUp\") {\n event.preventDefault();\n moveActive(-1);\n return;\n }\n\n if (event.key === \"Enter\") {\n event.preventDefault();\n const item = filteredItems[activeIndex];\n if (item) selectItem(item);\n return;\n }\n\n if (event.key !== \"Tab\" || !dialogRef.current) return;\n const focusable = Array.from(\n dialogRef.current.querySelectorAll<HTMLElement>(\n 'input, button:not([disabled]), [tabindex]:not([tabindex=\"-1\"])',\n ),\n );\n const first = focusable[0];\n const last = focusable.at(-1);\n if (!first || !last) return;\n\n if (event.shiftKey && document.activeElement === first) {\n event.preventDefault();\n last.focus();\n } else if (!event.shiftKey && document.activeElement === last) {\n event.preventDefault();\n first.focus();\n }\n };\n\n const shellLayoutId = `${uid}-shell`;\n const listboxId = `${uid}-results`;\n const panelWidth = mounted\n ? Math.max(anchorRect.width, Math.min(448, window.innerWidth - anchorRect.left - 16))\n : anchorRect.width;\n const resultsHeight = mounted\n ? Math.max(96, Math.min(288, window.innerHeight - anchorRect.top - 80))\n : 288;\n const collapsedContentClip = `inset(0px ${Math.max(\n 0,\n panelWidth - anchorRect.width,\n )}px ${resultsHeight}px 0px round 12px)`;\n const expandedContentClip = \"inset(0px 0px 0px 0px round 12px)\";\n\n // Neither grouping layer carries a box: they only hold `inert`/`aria-hidden`,\n // the z-index and the presence key, and every child below is `fixed` and\n // resolves against the viewport itself. The click catcher spans the viewport\n // edges but has no children and filters nothing, so it is not a sampling\n // layer either. See tests/fixed-overlay-edge-sampling.test.tsx.\n const overlay = mounted\n ? createPortal(\n <div\n aria-hidden={!open}\n inert={!open}\n className=\"pointer-events-none fixed top-0 left-0 z-50 size-0\"\n >\n <AnimatePresence\n initial={false}\n mode=\"popLayout\"\n onExitComplete={() => setBackgroundScrollLocked(false)}\n >\n {open ? (\n <motion.div key=\"morphing-search-overlay\" className=\"fixed top-0 left-0 size-0\">\n <button\n type=\"button\"\n aria-label=\"Close search\"\n className=\"pointer-events-auto fixed inset-0 cursor-default bg-transparent\"\n onClick={closeSearch}\n />\n\n <motion.div\n layoutId={shellLayoutId}\n aria-hidden=\"true\"\n className=\"fixed z-10 rounded-xl bg-background/90 backdrop-blur-xl\"\n style={{\n top: anchorRect.top,\n left: anchorRect.left,\n width: panelWidth,\n height: 48 + resultsHeight,\n boxShadow: \"inset 0 0 0 1px var(--color-border)\",\n }}\n transition={morphTransition}\n />\n\n <motion.div\n ref={dialogRef}\n role=\"dialog\"\n aria-modal=\"true\"\n aria-label=\"Search\"\n onKeyDown={handleDialogKeyDown}\n initial={reduce ? false : { opacity: 0, clipPath: collapsedContentClip }}\n animate={{ opacity: 1, clipPath: expandedContentClip }}\n exit={{\n opacity: 0,\n clipPath: collapsedContentClip,\n transition: reduce\n ? { duration: 0 }\n : {\n clipPath: SEARCH_CLIP_TRANSITION,\n opacity: SEARCH_MORPH,\n },\n }}\n transition={\n reduce\n ? { duration: 0 }\n : {\n clipPath: SEARCH_CLIP_TRANSITION,\n opacity: SEARCH_MORPH,\n }\n }\n className=\"pointer-events-auto fixed z-20 overflow-hidden rounded-xl\"\n style={{\n top: anchorRect.top,\n left: anchorRect.left,\n width: panelWidth,\n }}\n >\n <div\n className={cn(\n \"flex h-12 items-center gap-2.5 border-border border-b\",\n iconOnly ? \"px-4\" : \"px-3.5\",\n )}\n >\n <span className=\"shrink-0\">\n <Search className=\"size-4 text-muted-foreground\" />\n </span>\n <div className=\"flex h-10 min-w-0 flex-1 items-center\">\n <input\n ref={inputRef}\n value={query}\n onChange={(event) => updateQuery(event.target.value)}\n role=\"combobox\"\n aria-label={placeholder}\n aria-expanded=\"true\"\n aria-controls={listboxId}\n aria-autocomplete=\"list\"\n aria-activedescendant={\n filteredItems.length > 0 ? `${uid}-option-${activeIndex}` : undefined\n }\n placeholder={placeholder}\n className=\"size-full bg-transparent text-foreground text-sm outline-none placeholder:text-muted-foreground\"\n />\n </div>\n <kbd className=\"flex h-7 shrink-0 items-center rounded-md border border-border px-2 text-muted-foreground text-xs\">\n Esc\n </kbd>\n </div>\n\n <motion.div\n ref={listRef}\n id={listboxId}\n role=\"listbox\"\n aria-label=\"Search results\"\n transition={reduce ? { duration: 0 } : undefined}\n variants={\n reduce\n ? undefined\n : {\n closed: {\n opacity: 0,\n transform: \"translateY(6px)\",\n transition: {\n duration: 0.16,\n delay: 0.18,\n ease: EASE_OUT,\n },\n },\n open: {\n opacity: 1,\n transform: \"translateY(0px)\",\n transition: {\n duration: 0.16,\n ease: EASE_OUT,\n },\n },\n }\n }\n initial={reduce ? { opacity: 1, transform: \"translateY(0px)\" } : \"closed\"}\n animate={reduce ? { opacity: 1, transform: \"translateY(0px)\" } : \"open\"}\n exit={reduce ? undefined : \"closed\"}\n className=\"overflow-y-auto overscroll-contain p-2\"\n style={{\n maxHeight: resultsHeight,\n }}\n >\n {filteredItems.length > 0 ? (\n filteredItems.map((item, index) => {\n const Icon = item.icon;\n const active = index === activeIndex;\n return (\n <button\n key={item.id}\n id={`${uid}-option-${index}`}\n type=\"button\"\n role=\"option\"\n aria-selected={active}\n data-index={index}\n onMouseMove={() => moveTo(item.id)}\n onFocus={() => moveTo(item.id)}\n onClick={() => selectItem(item)}\n className=\"relative flex w-full items-center gap-2.5 rounded-lg px-3 py-2.5 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset\"\n >\n {active ? (\n <motion.span\n layoutId={`${uid}-active-result`}\n className=\"absolute inset-0 rounded-lg bg-foreground/5\"\n transition={transition}\n />\n ) : null}\n {Icon ? (\n <Icon className=\"relative size-4 shrink-0 text-muted-foreground\" />\n ) : null}\n <span className=\"relative min-w-0\">\n <span className=\"block truncate font-medium text-foreground text-sm\">\n {item.title}\n </span>\n {item.description ? (\n <span className=\"block truncate text-muted-foreground text-xs\">\n {item.description}\n </span>\n ) : null}\n </span>\n </button>\n );\n })\n ) : (\n <p className=\"px-3 py-8 text-center text-muted-foreground text-sm\">\n {emptyMessage}\n </p>\n )}\n </motion.div>\n </motion.div>\n </motion.div>\n ) : null}\n </AnimatePresence>\n </div>,\n document.body,\n )\n : null;\n\n return (\n <LayoutGroup id={uid}>\n <div\n ref={anchorRef}\n className={cn(\"relative\", iconOnly ? \"size-12\" : \"h-12 w-72 max-w-full\", className)}\n >\n {!open ? (\n <motion.button\n ref={triggerRef}\n key=\"morphing-search-trigger\"\n layoutId={shellLayoutId}\n type=\"button\"\n aria-haspopup=\"dialog\"\n aria-expanded=\"false\"\n aria-label={placeholder}\n onClick={openSearch}\n transition={morphTransition}\n style={{\n boxShadow: \"inset 0 0 0 1px var(--search-trigger-stroke)\",\n }}\n className={cn(\n \"flex size-full items-center rounded-xl bg-background/60 text-left outline-none backdrop-blur-md [--search-trigger-stroke:var(--color-border)] focus-visible:ring-2 focus-visible:ring-ring hover:[--search-trigger-stroke:var(--color-border-strong)]\",\n iconOnly ? \"cursor-pointer justify-center\" : \"cursor-text px-3.5\",\n )}\n />\n ) : null}\n <motion.div\n aria-hidden=\"true\"\n initial={false}\n animate={{ opacity: open ? 0 : 1 }}\n transition={\n reduce\n ? { duration: 0 }\n : {\n duration: 0.1,\n delay: open ? 0.1 : 0.12,\n ease: EASE_OUT,\n }\n }\n className={cn(\n \"pointer-events-none absolute inset-0 flex items-center\",\n backgroundScrollLocked && \"z-60\",\n iconOnly ? \"justify-center\" : \"gap-2.5 px-3.5\",\n )}\n >\n <Search className=\"size-4 shrink-0 text-muted-foreground\" />\n {iconOnly ? null : (\n <>\n <span className=\"min-w-0 flex-1 truncate text-muted-foreground text-sm\">\n {placeholder}\n </span>\n {shortcut ? (\n <kbd className=\"flex h-7 min-w-7 shrink-0 items-center justify-center rounded-md border border-border px-2 text-muted-foreground text-xs\">\n {shortcut.toUpperCase()}\n </kbd>\n ) : null}\n </>\n )}\n </motion.div>\n </div>\n {overlay}\n </LayoutGroup>\n );\n}\n"],"mappings":";;;;;;;;;;;AA4BA,MAAM,eAA2B;CAC/B,MAAM;CACN,UAAU;CACV,QAAQ;AACV;AAIA,MAAM,yBAAqC;CACzC,UAAU;CACV,MAAM;AACR;AAgCA,SAAS,iBAAiB,QAA4B;CACpD,IAAI,EAAE,kBAAkB,cAAc,OAAO;CAC7C,OACE,OAAO,qBACP,kBAAkB,oBAClB,kBAAkB,uBAClB,kBAAkB;AAEtB;AAEA,SAAgB,eAAe,EAC7B,OACA,cAAc,UACd,WAAW,KACX,WAAW,OACX,eAAe,qBACf,MAAM,gBACN,cAAc,OACd,cACA,eACA,UACA,aACsB;CACtB,MAAM,CAAC,cAAc,mBAAmB,SAAS,WAAW;CAC5D,MAAM,CAAC,OAAO,YAAY,SAAS,EAAE;CACrC,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAC5C,MAAM,CAAC,wBAAwB,6BAA6B,SAAS,WAAW;CAChF,MAAM,CAAC,YAAY,iBAAiB,SAAqB;EACvD,KAAK;EACL,MAAM;EACN,OAAO;CACT,CAAC;CACD,MAAM,OAAO,kBAAkB;CAC/B,MAAM,aAAa,mBAAmB,KAAA;CACtC,MAAM,SAAS,iBAAiB;CAChC,MAAM,MAAM,MAAM;CAClB,MAAM,YAAY,OAAuB,IAAI;CAC7C,MA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2
|
//#region src/components/reui/alert.d.ts
|
|
3
3
|
declare const alertVariants: (props?: ({
|
|
4
|
-
variant?: "default" | "destructive" | "
|
|
4
|
+
variant?: "default" | "destructive" | "success" | "info" | "warning" | "invert" | null | undefined;
|
|
5
5
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
6
6
|
declare function Alert({ className, variant, ...props }: React.ComponentProps<"div"> & VariantProps<typeof alertVariants>): import("react").JSX.Element;
|
|
7
7
|
declare function AlertTitle({ className, ...props }: React.ComponentProps<"div">): import("react").JSX.Element;
|
|
@@ -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/reui/badge.d.ts
|
|
4
4
|
declare const badgeVariants: (props?: ({
|
|
5
|
-
variant?: "
|
|
5
|
+
variant?: "outline" | "secondary" | "default" | "destructive" | "success" | "info" | "warning" | "invert" | "focus" | "primary-light" | "warning-light" | "success-light" | "info-light" | "destructive-light" | "invert-light" | "focus-light" | "primary-outline" | "warning-outline" | "success-outline" | "info-outline" | "destructive-outline" | "invert-outline" | "focus-outline" | null | undefined;
|
|
6
6
|
size?: "default" | "sm" | "lg" | "xs" | "xl" | null | undefined;
|
|
7
7
|
radius?: "default" | "full" | null | undefined;
|
|
8
8
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Button } from "../../ui/button.js";
|
|
3
3
|
import { Popover, PopoverContent, PopoverTrigger } from "../../ui/popover.js";
|
|
4
|
-
import { Cascader, CascaderEmpty, CascaderList, CascaderPanel, CascaderStatus } from "../cascader/cascader.js";
|
|
5
4
|
import { CascaderFooter } from "../cascader/cascader-footer.js";
|
|
6
5
|
import { CascaderBreadcrumb, CascaderInput, CascaderNav } from "../cascader/cascader-nav.js";
|
|
7
6
|
import { CascaderVirtualItems } from "../cascader/cascader-virtual.js";
|
|
7
|
+
import { Cascader, CascaderEmpty, CascaderList, CascaderPanel, CascaderStatus } from "../cascader/cascader.js";
|
|
8
8
|
import { filterControlSizes, filterReadOnlyProps, useFilterActions, useFilterState } from "./filters-context.js";
|
|
9
9
|
import { FILTER_FIELD_PICKER_CLASS, getFilterField, getFilterFieldCount, joinFilterPath, splitFilterPath } from "./filters-lib.js";
|
|
10
10
|
import { getDefaultFilterOperator } from "./filters-operators.js";
|