@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
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ bun add @base-ui/react class-variance-authority lucide-react motion react @kumix
|
|
|
40
40
|
|
|
41
41
|
| Peer | Used by |
|
|
42
42
|
| --------------------------------------------------- | ---------------------------------------------- |
|
|
43
|
-
| `next-themes` | `use-meta-color`
|
|
43
|
+
| `next-themes` | `use-meta-color`, `motion/theme-toggle` |
|
|
44
44
|
| `@shadcn/react` | `message-scroller`, `questionnaire` |
|
|
45
45
|
| `@tanstack/react-table` · `@tanstack/react-virtual` | data-grid |
|
|
46
46
|
| `@dnd-kit/*` | kanban, sortable, data-grid DnD |
|
|
@@ -343,10 +343,8 @@ function AISidebar({ items, defaultItems = [], onItemsChange, onMove, onMoveErro
|
|
|
343
343
|
if (items) setInternalItems(items);
|
|
344
344
|
}, [items]);
|
|
345
345
|
const flat = useMemo(() => flattenResources(renderedItems, expandedIds), [expandedIds, renderedItems]);
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
setFocusedId(flat[0]?.item.id ?? null);
|
|
349
|
-
}, [flat, focusedId]);
|
|
346
|
+
const focusedRow = focusedId !== null && flat.some((row) => row.item.id === focusedId) ? focusedId : flat[0]?.item.id ?? null;
|
|
347
|
+
if (focusedId !== focusedRow) setFocusedId(focusedRow);
|
|
350
348
|
useEffect(() => {
|
|
351
349
|
if (!menuOpenId) return;
|
|
352
350
|
const frame = requestAnimationFrame(() => {
|
|
@@ -568,7 +566,7 @@ function AISidebar({ items, defaultItems = [], onItemsChange, onMove, onMoveErro
|
|
|
568
566
|
row,
|
|
569
567
|
active: selectedId === row.item.id,
|
|
570
568
|
expanded: expandedIds.has(row.item.id),
|
|
571
|
-
focused:
|
|
569
|
+
focused: focusedRow === row.item.id,
|
|
572
570
|
draggingId,
|
|
573
571
|
dropTarget,
|
|
574
572
|
menuOpen: menuOpenId === row.item.id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-sidebar.js","names":[],"sources":["../../../src/components/agents/ai-sidebar.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type DragEvent,\n type KeyboardEvent,\n type ReactNode,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport {\n ArrowDown,\n ArrowUp,\n Bookmark,\n FileText,\n Folder,\n FolderInput,\n FolderOpen,\n type LucideIcon,\n MoreHorizontal,\n Pencil,\n Undo2,\n} from \"lucide-react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { useTouchCapable } from \"../../hooks/use-touch-capable\";\nimport { EASE_OUT, SPRING_LAYOUT } from \"../../lib/ease\";\nimport { MorphPopover, MorphPopoverContent, MorphPopoverTrigger } from \"../motion/popover-morph\";\n\nexport type SidebarResourceKind = \"folder\" | \"project\" | \"file\" | \"bookmark\";\n\nexport interface SidebarResource {\n id: string;\n label: string;\n kind: SidebarResourceKind;\n children?: SidebarResource[];\n disabled?: boolean;\n}\n\nexport type SidebarResourceDropPosition = \"before\" | \"inside\" | \"after\";\n\nexport interface SidebarResourceMove {\n itemId: string;\n targetId: string | null;\n position: SidebarResourceDropPosition;\n}\n\n/**\n * The moves this row can make right now, the same four the keyboard offers on\n * `Alt+Shift+Arrow`. A pointer drag is the fast path for them; a finger has no\n * drag to give, so the row menu carries them too. Absent keys are moves this\n * row cannot make from where it sits.\n */\nexport interface SidebarResourceMoveCommands {\n up?: () => void;\n down?: () => void;\n into?: { label: string; run: () => void };\n out?: () => void;\n}\n\nexport interface SidebarResourceMenuControls {\n close: () => void;\n rename: () => void;\n moves: SidebarResourceMoveCommands;\n}\n\nexport interface AISidebarProps {\n items?: SidebarResource[];\n defaultItems?: SidebarResource[];\n onItemsChange?: (items: SidebarResource[]) => void;\n /** Reject the promise to roll the optimistic move back. */\n onMove?: (move: SidebarResourceMove) => void | Promise<void>;\n onMoveError?: (error: unknown, move: SidebarResourceMove) => void;\n onRename?: (item: SidebarResource, label: string) => void | Promise<void>;\n activeId?: string | null;\n defaultActiveId?: string | null;\n onActiveChange?: (id: string) => void;\n defaultExpandedIds?: string[];\n renderIcon?: (item: SidebarResource) => ReactNode;\n renderMenu?: (item: SidebarResource, controls: SidebarResourceMenuControls) => ReactNode;\n ariaLabel?: string;\n className?: string;\n}\n\ninterface FlatResource {\n item: SidebarResource;\n depth: number;\n parentId: string | null;\n}\n\ninterface DropTarget {\n id: string | null;\n position: SidebarResourceDropPosition;\n}\n\nconst ROW_REVEAL = {\n duration: 0.16,\n ease: EASE_OUT,\n} as const;\n\nfunction canContain(item: SidebarResource) {\n return item.kind === \"folder\" || item.kind === \"project\";\n}\n\nfunction flattenResources(\n items: SidebarResource[],\n expanded: Set<string>,\n depth = 0,\n parentId: string | null = null,\n): FlatResource[] {\n return items.flatMap((item) => {\n const row = { item, depth, parentId };\n if (!item.children?.length || !expanded.has(item.id)) return [row];\n return [row, ...flattenResources(item.children, expanded, depth + 1, item.id)];\n });\n}\n\nfunction findResource(items: SidebarResource[], id: string): SidebarResource | undefined {\n for (const item of items) {\n if (item.id === id) return item;\n const child = item.children ? findResource(item.children, id) : undefined;\n if (child) return child;\n }\n}\n\nfunction containsResource(item: SidebarResource, id: string): boolean {\n return item.id === id || item.children?.some((child) => containsResource(child, id)) === true;\n}\n\nfunction removeResource(\n items: SidebarResource[],\n id: string,\n): { items: SidebarResource[]; removed?: SidebarResource } {\n let removed: SidebarResource | undefined;\n const next: SidebarResource[] = [];\n\n for (const item of items) {\n if (item.id === id) {\n removed = item;\n continue;\n }\n\n if (item.children?.length) {\n const childResult = removeResource(item.children, id);\n if (childResult.removed) {\n removed = childResult.removed;\n next.push({ ...item, children: childResult.items });\n continue;\n }\n }\n\n next.push(item);\n }\n\n return { items: next, removed };\n}\n\nfunction insertResource(\n items: SidebarResource[],\n resource: SidebarResource,\n targetId: string | null,\n position: SidebarResourceDropPosition,\n): SidebarResource[] {\n if (targetId === null) return [...items, resource];\n\n const next: SidebarResource[] = [];\n for (const item of items) {\n if (item.id === targetId) {\n if (position === \"before\") next.push(resource, item);\n else if (position === \"after\") next.push(item, resource);\n else next.push({ ...item, children: [...(item.children ?? []), resource] });\n continue;\n }\n\n if (item.children?.length) {\n next.push({\n ...item,\n children: insertResource(item.children, resource, targetId, position),\n });\n } else {\n next.push(item);\n }\n }\n return next;\n}\n\nfunction moveResource(\n items: SidebarResource[],\n move: SidebarResourceMove,\n): SidebarResource[] | null {\n const source = findResource(items, move.itemId);\n if (!source || source.disabled) return null;\n if (move.targetId && containsResource(source, move.targetId)) return null;\n\n const target = move.targetId ? findResource(items, move.targetId) : undefined;\n if (move.position === \"inside\" && (!target || target.disabled || !canContain(target)))\n return null;\n\n const removed = removeResource(items, move.itemId);\n if (!removed.removed) return null;\n return insertResource(removed.items, removed.removed, move.targetId, move.position);\n}\n\nfunction renameResource(items: SidebarResource[], id: string, label: string): SidebarResource[] {\n return items.map((item) => ({\n ...item,\n label: item.id === id ? label : item.label,\n children: item.children ? renameResource(item.children, id, label) : undefined,\n }));\n}\n\nfunction defaultIcon(item: SidebarResource, expanded: boolean) {\n const Icon =\n item.kind === \"folder\" || item.kind === \"project\"\n ? expanded\n ? FolderOpen\n : Folder\n : item.kind === \"bookmark\"\n ? Bookmark\n : FileText;\n return <Icon className=\"size-4\" />;\n}\n\nfunction MarqueeLabel({ active, children }: { active: boolean; children: string }) {\n const reduce = useReducedMotion() ?? false;\n const viewportRef = useRef<HTMLSpanElement>(null);\n const labelRef = useRef<HTMLSpanElement>(null);\n const [distance, setDistance] = useState(0);\n\n useEffect(() => {\n const measure = () => {\n const viewport = viewportRef.current;\n const label = labelRef.current;\n if (!viewport || !label) return;\n setDistance(label.scrollWidth > viewport.clientWidth ? label.scrollWidth + 24 : 0);\n };\n measure();\n const observer = new ResizeObserver(measure);\n if (viewportRef.current) observer.observe(viewportRef.current);\n if (labelRef.current) observer.observe(labelRef.current);\n return () => observer.disconnect();\n }, []);\n\n const running = active && distance > 0 && !reduce;\n\n return (\n <span ref={viewportRef} className=\"block min-w-0 flex-1 overflow-hidden\">\n <motion.span\n className=\"flex w-max items-center gap-6 whitespace-nowrap\"\n animate={{ x: running ? [0, -distance] : 0 }}\n transition={\n running\n ? {\n duration: Math.max(2.4, distance / 34),\n ease: \"linear\",\n repeat: Number.POSITIVE_INFINITY,\n repeatDelay: 2,\n }\n : ROW_REVEAL\n }\n >\n <span ref={labelRef}>{children}</span>\n {running ? <span aria-hidden=\"true\">{children}</span> : null}\n </motion.span>\n </span>\n );\n}\n\nfunction ResourceMenuAction({\n icon: Icon,\n onSelect,\n children,\n}: {\n icon: LucideIcon;\n onSelect: () => void;\n children: ReactNode;\n}) {\n return (\n <button\n type=\"button\"\n onClick={onSelect}\n className=\"flex h-8 w-full items-center gap-2 rounded-lg px-2.5 text-left text-foreground text-xs outline-none transition-colors hover:bg-muted focus-visible:bg-muted focus-visible:ring-2 focus-visible:ring-ring\"\n >\n <Icon aria-hidden=\"true\" className=\"size-3.5 shrink-0\" />\n <span className=\"min-w-0 truncate\">{children}</span>\n </button>\n );\n}\n\ninterface ResourceRowProps {\n row: FlatResource;\n active: boolean;\n expanded: boolean;\n focused: boolean;\n draggingId: string | null;\n dropTarget: DropTarget | null;\n menuOpen: boolean;\n moves: SidebarResourceMoveCommands;\n renaming: boolean;\n onDragEnd: () => void;\n onDragOver: (event: DragEvent<HTMLDivElement>, row: FlatResource) => void;\n onDragStart: (event: DragEvent<HTMLDivElement>, id: string) => void;\n onDrop: (event: DragEvent<HTMLDivElement>) => void;\n onFocus: () => void;\n onKeyDown: (event: KeyboardEvent<HTMLDivElement>) => void;\n onMenuOpenChange: (open: boolean) => void;\n onRenameCancel: () => void;\n onRenameCommit: (label: string) => void;\n onRenameStart: () => void;\n onSelect: () => void;\n onToggle: () => void;\n renderIcon?: (item: SidebarResource) => ReactNode;\n renderMenu?: AISidebarProps[\"renderMenu\"];\n setRef: (node: HTMLDivElement | null) => void;\n}\n\nfunction ResourceRow({\n row,\n active,\n expanded,\n focused,\n draggingId,\n dropTarget,\n menuOpen,\n moves,\n renaming,\n onDragEnd,\n onDragOver,\n onDragStart,\n onDrop,\n onFocus,\n onKeyDown,\n onMenuOpenChange,\n onRenameCancel,\n onRenameCommit,\n onRenameStart,\n onSelect,\n onToggle,\n renderIcon,\n renderMenu,\n setRef,\n}: ResourceRowProps) {\n const reduce = useReducedMotion() ?? false;\n const canTouch = useTouchCapable();\n const [hovered, setHovered] = useState(false);\n const inputRef = useRef<HTMLInputElement>(null);\n const skipRenameBlurRef = useRef(false);\n const draggedRef = useRef(false);\n const [draft, setDraft] = useState(row.item.label);\n const acceptsChildren = canContain(row.item);\n const isDragging = draggingId === row.item.id;\n const dropPosition = dropTarget?.id === row.item.id ? dropTarget.position : null;\n\n useEffect(() => {\n if (!renaming) return;\n skipRenameBlurRef.current = false;\n setDraft(row.item.label);\n requestAnimationFrame(() => {\n inputRef.current?.focus();\n inputRef.current?.select();\n });\n }, [renaming, row.item.label]);\n\n const runFromMenu = (action: () => void) => () => {\n onMenuOpenChange(false);\n action();\n };\n\n const menu = renderMenu?.(row.item, {\n close: () => onMenuOpenChange(false),\n rename: () => {\n onMenuOpenChange(false);\n onRenameStart();\n },\n moves,\n }) ?? (\n <>\n <ResourceMenuAction icon={Pencil} onSelect={runFromMenu(onRenameStart)}>\n Rename\n </ResourceMenuAction>\n {moves.up || moves.down || moves.into || moves.out ? (\n <div aria-hidden=\"true\" className=\"my-1 h-px bg-border\" />\n ) : null}\n {moves.up ? (\n <ResourceMenuAction icon={ArrowUp} onSelect={runFromMenu(moves.up)}>\n Move up\n </ResourceMenuAction>\n ) : null}\n {moves.down ? (\n <ResourceMenuAction icon={ArrowDown} onSelect={runFromMenu(moves.down)}>\n Move down\n </ResourceMenuAction>\n ) : null}\n {moves.into ? (\n <ResourceMenuAction icon={FolderInput} onSelect={runFromMenu(moves.into.run)}>\n Move into {moves.into.label}\n </ResourceMenuAction>\n ) : null}\n {moves.out ? (\n <ResourceMenuAction icon={Undo2} onSelect={runFromMenu(moves.out)}>\n Move out\n </ResourceMenuAction>\n ) : null}\n </>\n );\n\n return (\n <motion.div\n ref={setRef}\n layout=\"position\"\n transition={reduce ? { duration: 0 } : SPRING_LAYOUT}\n role=\"treeitem\"\n aria-level={row.depth + 1}\n aria-selected={acceptsChildren ? undefined : active}\n aria-expanded={acceptsChildren ? expanded : undefined}\n aria-disabled={row.item.disabled || undefined}\n tabIndex={focused ? 0 : -1}\n draggable={!row.item.disabled && !renaming}\n data-menu-open={menuOpen || undefined}\n data-drop={dropPosition ?? undefined}\n data-dragging={isDragging || undefined}\n onFocus={onFocus}\n onKeyDown={onKeyDown}\n onClick={(event) => {\n if (event.defaultPrevented || draggedRef.current || renaming || row.item.disabled) return;\n if (acceptsChildren) onToggle();\n else onSelect();\n }}\n onDoubleClick={(event) => {\n if (acceptsChildren || row.item.disabled) return;\n event.preventDefault();\n onRenameStart();\n }}\n onMouseEnter={() => setHovered(true)}\n onMouseLeave={() => setHovered(false)}\n onDragStartCapture={(event) => {\n draggedRef.current = true;\n onDragStart(event, row.item.id);\n }}\n onDragEndCapture={() => {\n onDragEnd();\n requestAnimationFrame(() => {\n draggedRef.current = false;\n });\n }}\n onDragOver={(event) => onDragOver(event, row)}\n onDrop={onDrop}\n className={cn(\n \"group/resource relative flex min-h-9 min-w-0 cursor-pointer items-center gap-2.5 rounded-xl pr-3 text-sm outline-none\",\n \"text-muted-foreground transition-colors hover:bg-muted hover:text-foreground\",\n \"focus-visible:bg-muted/70 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset\",\n \"data-[menu-open=true]:bg-muted data-[menu-open=true]:text-foreground\",\n \"data-[dragging=true]:opacity-40\",\n \"data-[drop=inside]:bg-primary/10 data-[drop=inside]:ring-1 data-[drop=inside]:ring-primary/45\",\n \"data-[drop=before]:before:absolute data-[drop=before]:before:-top-0.5 data-[drop=before]:before:right-2 data-[drop=before]:before:left-2 data-[drop=before]:before:h-0.5 data-[drop=before]:before:rounded-full data-[drop=before]:before:bg-primary\",\n \"data-[drop=after]:after:absolute data-[drop=after]:after:right-2 data-[drop=after]:after:-bottom-0.5 data-[drop=after]:after:left-2 data-[drop=after]:after:h-0.5 data-[drop=after]:after:rounded-full data-[drop=after]:after:bg-primary\",\n !acceptsChildren && active && \"bg-muted text-foreground\",\n row.item.disabled && \"cursor-not-allowed opacity-45\",\n )}\n style={{ paddingLeft: `${12 + row.depth * 16}px` }}\n >\n <span aria-hidden=\"true\" className=\"grid size-5 shrink-0 place-items-center\">\n {renderIcon?.(row.item) ?? defaultIcon(row.item, expanded)}\n </span>\n\n {renaming ? (\n <input\n ref={inputRef}\n value={draft}\n aria-label={`Rename ${row.item.label}`}\n onChange={(event) => setDraft(event.target.value)}\n draggable={false}\n onClick={(event) => event.stopPropagation()}\n onDoubleClick={(event) => event.stopPropagation()}\n onBlur={() => {\n if (!skipRenameBlurRef.current) onRenameCommit(draft);\n }}\n onKeyDown={(event) => {\n event.stopPropagation();\n if (event.key === \"Enter\") {\n skipRenameBlurRef.current = true;\n onRenameCommit(draft);\n }\n if (event.key === \"Escape\") {\n skipRenameBlurRef.current = true;\n onRenameCancel();\n }\n }}\n className=\"mx-1 h-7 min-w-0 flex-1 rounded-md border border-border bg-background px-2 text-foreground text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n />\n ) : (\n <MarqueeLabel active={hovered || menuOpen}>{row.item.label}</MarqueeLabel>\n )}\n\n {!renaming && !row.item.disabled ? (\n <MorphPopover open={menuOpen} onOpenChange={onMenuOpenChange}>\n <MorphPopoverTrigger>\n <button\n type=\"button\"\n draggable={false}\n tabIndex={-1}\n aria-label={`Actions for ${row.item.label}`}\n onClick={(event) => event.stopPropagation()}\n className={cn(\n \"grid size-7 shrink-0 place-items-center rounded-lg outline-none transition-opacity hover:bg-foreground/5 focus-visible:opacity-100 focus-visible:ring-2 focus-visible:ring-ring group-hover/resource:opacity-100 group-data-[menu-open=true]/resource:opacity-100\",\n // A finger never hovers, and this menu is the only path to\n // rename and move without a drag — keep it on screen there.\n canTouch ? \"opacity-100\" : \"opacity-0\",\n )}\n >\n <MoreHorizontal aria-hidden=\"true\" className=\"size-4\" />\n </button>\n </MorphPopoverTrigger>\n <MorphPopoverContent\n side=\"bottom\"\n align=\"end\"\n sideOffset={8}\n radius={12}\n className=\"w-40 p-1.5\"\n >\n <div data-sidebar-resource-menu={row.item.id}>{menu}</div>\n </MorphPopoverContent>\n </MorphPopover>\n ) : null}\n </motion.div>\n );\n}\n\nexport function AISidebar({\n items,\n defaultItems = [],\n onItemsChange,\n onMove,\n onMoveError,\n onRename,\n activeId,\n defaultActiveId = null,\n onActiveChange,\n defaultExpandedIds = [],\n renderIcon,\n renderMenu,\n ariaLabel = \"Resources\",\n className,\n}: AISidebarProps) {\n const [internalItems, setInternalItems] = useState(items ?? defaultItems);\n const [internalActiveId, setInternalActiveId] = useState(defaultActiveId);\n const [expandedIds, setExpandedIds] = useState(() => new Set(defaultExpandedIds));\n const [focusedId, setFocusedId] = useState<string | null>(activeId ?? defaultActiveId);\n const [draggingId, setDraggingId] = useState<string | null>(null);\n const [dropTarget, setDropTarget] = useState<DropTarget | null>(null);\n const [menuOpenId, setMenuOpenId] = useState<string | null>(null);\n const [renamingId, setRenamingId] = useState<string | null>(null);\n const [announcement, setAnnouncement] = useState(\"\");\n const rowRefs = useRef(new Map<string, HTMLDivElement>());\n const movePendingRef = useRef(false);\n const renderedItems = internalItems;\n const selectedId = activeId ?? internalActiveId;\n\n useEffect(() => {\n if (items) setInternalItems(items);\n }, [items]);\n\n const flat = useMemo(\n () => flattenResources(renderedItems, expandedIds),\n [expandedIds, renderedItems],\n );\n\n useEffect(() => {\n if (focusedId && flat.some((row) => row.item.id === focusedId)) return;\n setFocusedId(flat[0]?.item.id ?? null);\n }, [flat, focusedId]);\n\n useEffect(() => {\n if (!menuOpenId) return;\n const frame = requestAnimationFrame(() => {\n const menus = Array.from(\n document.querySelectorAll<HTMLElement>(\"[data-sidebar-resource-menu]\"),\n );\n menus\n .find((menu) => menu.dataset.sidebarResourceMenu === menuOpenId)\n ?.querySelector<HTMLElement>(\"button, a[href]\")\n ?.focus();\n });\n return () => cancelAnimationFrame(frame);\n }, [menuOpenId]);\n\n const updateItems = useCallback(\n (next: SidebarResource[]) => {\n setInternalItems(next);\n onItemsChange?.(next);\n },\n [onItemsChange],\n );\n\n const performMove = useCallback(\n async (move: SidebarResourceMove) => {\n if (movePendingRef.current) {\n setAnnouncement(\"Wait for the current move to finish.\");\n return;\n }\n const before = renderedItems;\n const next = moveResource(before, move);\n if (!next || next === before) return;\n\n movePendingRef.current = true;\n updateItems(next);\n setDropTarget(null);\n setDraggingId(null);\n const moved = findResource(before, move.itemId);\n const target = move.targetId ? findResource(before, move.targetId) : null;\n setAnnouncement(\n target\n ? `Moved ${moved?.label ?? \"item\"} ${move.position} ${target.label}.`\n : `Moved ${moved?.label ?? \"item\"} to the top level.`,\n );\n\n try {\n await onMove?.(move);\n } catch (error) {\n updateItems(before);\n setAnnouncement(`Move failed. ${moved?.label ?? \"Item\"} was restored.`);\n onMoveError?.(error, move);\n } finally {\n movePendingRef.current = false;\n }\n },\n [onMove, onMoveError, renderedItems, updateItems],\n );\n\n const focusRow = useCallback((id: string) => {\n setFocusedId(id);\n requestAnimationFrame(() => rowRefs.current.get(id)?.focus());\n }, []);\n\n const select = useCallback(\n (id: string) => {\n if (activeId === undefined) setInternalActiveId(id);\n onActiveChange?.(id);\n },\n [activeId, onActiveChange],\n );\n\n const toggle = useCallback((id: string) => {\n setExpandedIds((current) => {\n const next = new Set(current);\n if (next.has(id)) next.delete(id);\n else next.add(id);\n return next;\n });\n }, []);\n\n // The same four moves `Alt+Shift+Arrow` performs, handed to the row menu so\n // they survive on a device with no drag and no modifier keys.\n const moveCommands = useCallback(\n (row: FlatResource): SidebarResourceMoveCommands => {\n if (row.item.disabled) return {};\n const index = flat.findIndex(({ item }) => item.id === row.item.id);\n const previous = flat[index - 1];\n const next = flat[index + 1];\n const parentId = row.parentId;\n const commands: SidebarResourceMoveCommands = {};\n\n if (previous) {\n commands.up = () =>\n void performMove({\n itemId: row.item.id,\n targetId: previous.item.id,\n position: \"before\",\n });\n }\n if (next) {\n commands.down = () =>\n void performMove({\n itemId: row.item.id,\n targetId: next.item.id,\n position: \"after\",\n });\n }\n // Only offer the reparent when it lands somewhere new — the row above a\n // folder's first child is the folder it already lives in.\n if (previous && canContain(previous.item) && previous.item.id !== parentId) {\n commands.into = {\n label: previous.item.label,\n run: () => {\n setExpandedIds((current) => new Set(current).add(previous.item.id));\n void performMove({\n itemId: row.item.id,\n targetId: previous.item.id,\n position: \"inside\",\n });\n },\n };\n }\n if (parentId) {\n commands.out = () =>\n void performMove({\n itemId: row.item.id,\n targetId: parentId,\n position: \"after\",\n });\n }\n\n return commands;\n },\n [flat, performMove],\n );\n\n const handleKeyDown = useCallback(\n (event: KeyboardEvent<HTMLDivElement>, row: FlatResource) => {\n const index = flat.findIndex(({ item }) => item.id === row.item.id);\n const previous = flat[index - 1];\n const next = flat[index + 1];\n const moveModifier = event.altKey && event.shiftKey;\n\n if (event.key === \"ArrowDown\" && !moveModifier && next) {\n event.preventDefault();\n focusRow(next.item.id);\n return;\n }\n if (event.key === \"ArrowUp\" && !moveModifier && previous) {\n event.preventDefault();\n focusRow(previous.item.id);\n return;\n }\n if (event.key === \"Home\" && flat[0]) {\n event.preventDefault();\n focusRow(flat[0].item.id);\n return;\n }\n if (event.key === \"End\" && flat.at(-1)) {\n event.preventDefault();\n focusRow(flat.at(-1)?.item.id ?? row.item.id);\n return;\n }\n\n if (row.item.disabled) {\n if (event.key === \"ArrowLeft\" && row.parentId) {\n event.preventDefault();\n focusRow(row.parentId);\n } else if (\n moveModifier ||\n [\"ArrowRight\", \"Enter\", \" \", \"F2\", \"ContextMenu\"].includes(event.key) ||\n (event.shiftKey && event.key === \"F10\")\n ) {\n event.preventDefault();\n }\n return;\n }\n\n if (moveModifier && event.key === \"ArrowUp\" && previous) {\n event.preventDefault();\n void performMove({ itemId: row.item.id, targetId: previous.item.id, position: \"before\" });\n return;\n }\n if (moveModifier && event.key === \"ArrowDown\" && next) {\n event.preventDefault();\n void performMove({ itemId: row.item.id, targetId: next.item.id, position: \"after\" });\n return;\n }\n if (moveModifier && event.key === \"ArrowRight\" && previous && canContain(previous.item)) {\n event.preventDefault();\n setExpandedIds((current) => new Set(current).add(previous.item.id));\n void performMove({ itemId: row.item.id, targetId: previous.item.id, position: \"inside\" });\n return;\n }\n if (moveModifier && event.key === \"ArrowLeft\" && row.parentId) {\n event.preventDefault();\n void performMove({ itemId: row.item.id, targetId: row.parentId, position: \"after\" });\n return;\n }\n\n if (event.key === \"ArrowRight\" && canContain(row.item)) {\n event.preventDefault();\n if (!expandedIds.has(row.item.id)) toggle(row.item.id);\n else if (next?.parentId === row.item.id) focusRow(next.item.id);\n } else if (event.key === \"ArrowLeft\") {\n event.preventDefault();\n if (expandedIds.has(row.item.id)) toggle(row.item.id);\n else if (row.parentId) focusRow(row.parentId);\n } else if (event.key === \"Enter\" || event.key === \" \") {\n event.preventDefault();\n if (canContain(row.item)) toggle(row.item.id);\n else select(row.item.id);\n } else if (event.key === \"F2\") {\n event.preventDefault();\n setRenamingId(row.item.id);\n } else if (event.key === \"ContextMenu\" || (event.shiftKey && event.key === \"F10\")) {\n event.preventDefault();\n setMenuOpenId(row.item.id);\n }\n },\n [expandedIds, flat, focusRow, performMove, select, toggle],\n );\n\n return (\n <>\n <div\n role=\"tree\"\n aria-label={ariaLabel}\n aria-multiselectable=\"false\"\n onDragOver={(event) => {\n if (!draggingId || event.target !== event.currentTarget) return;\n event.preventDefault();\n setDropTarget({ id: null, position: \"after\" });\n }}\n onDrop={(event) => {\n event.preventDefault();\n if (draggingId && dropTarget) {\n void performMove({\n itemId: draggingId,\n targetId: dropTarget.id,\n position: dropTarget.position,\n });\n }\n }}\n className={cn(\n \"relative flex min-w-0 flex-col gap-0.5 [overflow-anchor:none] group-data-[state=collapsed]/sidebar:hidden\",\n draggingId && \"select-none pb-9\",\n className,\n )}\n >\n <AnimatePresence initial={false}>\n {flat.map((row) => (\n <ResourceRow\n key={row.item.id}\n row={row}\n active={selectedId === row.item.id}\n expanded={expandedIds.has(row.item.id)}\n focused={focusedId === row.item.id}\n draggingId={draggingId}\n dropTarget={dropTarget}\n menuOpen={menuOpenId === row.item.id}\n moves={moveCommands(row)}\n renaming={renamingId === row.item.id}\n onFocus={() => setFocusedId(row.item.id)}\n onSelect={() => select(row.item.id)}\n onToggle={() => toggle(row.item.id)}\n onKeyDown={(event) => handleKeyDown(event, row)}\n onRenameStart={() => setRenamingId(row.item.id)}\n onRenameCancel={() => setRenamingId(null)}\n onRenameCommit={(label) => {\n const trimmed = label.trim();\n setRenamingId(null);\n if (!trimmed || trimmed === row.item.label) return;\n const before = renderedItems;\n updateItems(renameResource(before, row.item.id, trimmed));\n void Promise.resolve(onRename?.(row.item, trimmed)).catch(() => {\n updateItems(before);\n setAnnouncement(`Rename failed. ${row.item.label} was restored.`);\n });\n }}\n onMenuOpenChange={(open) => {\n setMenuOpenId(open ? row.item.id : null);\n if (!open) focusRow(row.item.id);\n }}\n onDragStart={(event, id) => {\n setDraggingId(id);\n event.dataTransfer.effectAllowed = \"move\";\n event.dataTransfer.setData(\"text/plain\", id);\n }}\n onDragEnd={() => {\n setDraggingId(null);\n setDropTarget(null);\n }}\n onDragOver={(event, targetRow) => {\n if (!draggingId || draggingId === targetRow.item.id) return;\n const source = findResource(renderedItems, draggingId);\n if (source && containsResource(source, targetRow.item.id)) return;\n event.preventDefault();\n event.stopPropagation();\n const rect = event.currentTarget.getBoundingClientRect();\n const ratio = (event.clientY - rect.top) / rect.height;\n const position =\n !targetRow.item.disabled &&\n canContain(targetRow.item) &&\n ratio >= 0.25 &&\n ratio <= 0.75\n ? \"inside\"\n : ratio < 0.5\n ? \"before\"\n : \"after\";\n setDropTarget({ id: targetRow.item.id, position });\n }}\n onDrop={(event) => {\n event.preventDefault();\n event.stopPropagation();\n if (draggingId && dropTarget) {\n void performMove({\n itemId: draggingId,\n targetId: dropTarget.id,\n position: dropTarget.position,\n });\n }\n }}\n renderIcon={renderIcon}\n renderMenu={renderMenu}\n setRef={(node) => {\n if (node) rowRefs.current.set(row.item.id, node);\n else rowRefs.current.delete(row.item.id);\n }}\n />\n ))}\n </AnimatePresence>\n\n {draggingId ? (\n <div\n aria-hidden=\"true\"\n data-active={dropTarget?.id === null || undefined}\n className=\"absolute inset-x-1 bottom-0 flex h-8 items-center justify-center rounded-lg border border-border border-dashed text-[10px] text-muted-foreground data-[active=true]:border-primary/50 data-[active=true]:bg-primary/10 data-[active=true]:text-foreground\"\n >\n Move to top level\n </div>\n ) : null}\n </div>\n <span className=\"sr-only\" aria-live=\"polite\">\n {announcement}\n </span>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;AAkGA,MAAM,aAAa;CACjB,UAAU;CACV,MAAM;AACR;AAEA,SAAS,WAAW,MAAuB;CACzC,OAAO,KAAK,SAAS,YAAY,KAAK,SAAS;AACjD;AAEA,SAAS,iBACP,OACA,UACA,QAAQ,GACR,WAA0B,MACV;CAChB,OAAO,MAAM,SAAS,SAAS;EAC7B,MAAM,MAAM;GAAE;GAAM;GAAO;EAAS;EACpC,IAAI,CAAC,KAAK,UAAU,UAAU,CAAC,SAAS,IAAI,KAAK,EAAE,GAAG,OAAO,CAAC,GAAG;EACjE,OAAO,CAAC,KAAK,GAAG,iBAAiB,KAAK,UAAU,UAAU,QAAQ,GAAG,KAAK,EAAE,CAAC;CAC/E,CAAC;AACH;AAEA,SAAS,aAAa,OAA0B,IAAyC;CACvF,KAAK,MAAM,QAAQ,OAAO;EACxB,IAAI,KAAK,OAAO,IAAI,OAAO;EAC3B,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Q,cAAc,EAAE;IAC7C;IACA,iBAAiB;KACf,cAAc,IAAI;KAClB,cAAc,IAAI;IACpB;IACA,aAAa,OAAO,cAAc;KAChC,IAAI,CAAC,cAAc,eAAe,UAAU,KAAK,IAAI;KACrD,MAAM,SAAS,aAAa,eAAe,UAAU;KACrD,IAAI,UAAU,iBAAiB,QAAQ,UAAU,KAAK,EAAE,GAAG;KAC3D,MAAM,eAAe;KACrB,MAAM,gBAAgB;KACtB,MAAM,OAAO,MAAM,cAAc,sBAAsB;KACvD,MAAM,SAAS,MAAM,UAAU,KAAK,OAAO,KAAK;KAChD,MAAM,WACJ,CAAC,UAAU,KAAK,YAChB,WAAW,UAAU,IAAI,KACzB,SAAS,OACT,SAAS,MACL,WACA,QAAQ,KACN,WACA;KACR,cAAc;MAAE,IAAI,UAAU,KAAK;MAAI;KAAS,CAAC;IACnD;IACA,SAAS,UAAU;KACjB,MAAM,eAAe;KACrB,MAAM,gBAAgB;KACtB,IAAI,cAAc,YAChB,YAAiB;MACf,QAAQ;MACR,UAAU,WAAW;MACrB,UAAU,WAAW;KACvB,CAAC;IAEL;IACY;IACA;IACZ,SAAS,SAAS;KAChB,IAAI,MAAM,QAAQ,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI;UAC1C,QAAQ,QAAQ,OAAO,IAAI,KAAK,EAAE;IACzC;GACD,GA5EM,IAAI,KAAK,EA4Ef,CACF;EACc,CAAA,GAEhB,aACC,oBAAC,OAAD;GACE,eAAY;GACZ,eAAa,YAAY,OAAO,QAAQ,KAAA;GACxC,WAAU;GACX,UAAA;EAEI,CAAA,IACH,IACD;CACL,CAAA,GAAA,oBAAC,QAAD;EAAM,WAAU;EAAU,aAAU;EACjC,UAAA;CACG,CAAA,CACN,EAAA,CAAA;AAEN"}
|
|
1
|
+
{"version":3,"file":"ai-sidebar.js","names":[],"sources":["../../../src/components/agents/ai-sidebar.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type DragEvent,\n type KeyboardEvent,\n type ReactNode,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport {\n ArrowDown,\n ArrowUp,\n Bookmark,\n FileText,\n Folder,\n FolderInput,\n FolderOpen,\n type LucideIcon,\n MoreHorizontal,\n Pencil,\n Undo2,\n} from \"lucide-react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { useTouchCapable } from \"../../hooks/use-touch-capable\";\nimport { EASE_OUT, SPRING_LAYOUT } from \"../../lib/ease\";\nimport { MorphPopover, MorphPopoverContent, MorphPopoverTrigger } from \"../motion/popover-morph\";\n\nexport type SidebarResourceKind = \"folder\" | \"project\" | \"file\" | \"bookmark\";\n\nexport interface SidebarResource {\n id: string;\n label: string;\n kind: SidebarResourceKind;\n children?: SidebarResource[];\n disabled?: boolean;\n}\n\nexport type SidebarResourceDropPosition = \"before\" | \"inside\" | \"after\";\n\nexport interface SidebarResourceMove {\n itemId: string;\n targetId: string | null;\n position: SidebarResourceDropPosition;\n}\n\n/**\n * The moves this row can make right now, the same four the keyboard offers on\n * `Alt+Shift+Arrow`. A pointer drag is the fast path for them; a finger has no\n * drag to give, so the row menu carries them too. Absent keys are moves this\n * row cannot make from where it sits.\n */\nexport interface SidebarResourceMoveCommands {\n up?: () => void;\n down?: () => void;\n into?: { label: string; run: () => void };\n out?: () => void;\n}\n\nexport interface SidebarResourceMenuControls {\n close: () => void;\n rename: () => void;\n moves: SidebarResourceMoveCommands;\n}\n\nexport interface AISidebarProps {\n items?: SidebarResource[];\n defaultItems?: SidebarResource[];\n onItemsChange?: (items: SidebarResource[]) => void;\n /** Reject the promise to roll the optimistic move back. */\n onMove?: (move: SidebarResourceMove) => void | Promise<void>;\n onMoveError?: (error: unknown, move: SidebarResourceMove) => void;\n onRename?: (item: SidebarResource, label: string) => void | Promise<void>;\n activeId?: string | null;\n defaultActiveId?: string | null;\n onActiveChange?: (id: string) => void;\n defaultExpandedIds?: string[];\n renderIcon?: (item: SidebarResource) => ReactNode;\n renderMenu?: (item: SidebarResource, controls: SidebarResourceMenuControls) => ReactNode;\n ariaLabel?: string;\n className?: string;\n}\n\ninterface FlatResource {\n item: SidebarResource;\n depth: number;\n parentId: string | null;\n}\n\ninterface DropTarget {\n id: string | null;\n position: SidebarResourceDropPosition;\n}\n\nconst ROW_REVEAL = {\n duration: 0.16,\n ease: EASE_OUT,\n} as const;\n\nfunction canContain(item: SidebarResource) {\n return item.kind === \"folder\" || item.kind === \"project\";\n}\n\nfunction flattenResources(\n items: SidebarResource[],\n expanded: Set<string>,\n depth = 0,\n parentId: string | null = null,\n): FlatResource[] {\n return items.flatMap((item) => {\n const row = { item, depth, parentId };\n if (!item.children?.length || !expanded.has(item.id)) return [row];\n return [row, ...flattenResources(item.children, expanded, depth + 1, item.id)];\n });\n}\n\nfunction findResource(items: SidebarResource[], id: string): SidebarResource | undefined {\n for (const item of items) {\n if (item.id === id) return item;\n const child = item.children ? findResource(item.children, id) : undefined;\n if (child) return child;\n }\n}\n\nfunction containsResource(item: SidebarResource, id: string): boolean {\n return item.id === id || item.children?.some((child) => containsResource(child, id)) === true;\n}\n\nfunction removeResource(\n items: SidebarResource[],\n id: string,\n): { items: SidebarResource[]; removed?: SidebarResource } {\n let removed: SidebarResource | undefined;\n const next: SidebarResource[] = [];\n\n for (const item of items) {\n if (item.id === id) {\n removed = item;\n continue;\n }\n\n if (item.children?.length) {\n const childResult = removeResource(item.children, id);\n if (childResult.removed) {\n removed = childResult.removed;\n next.push({ ...item, children: childResult.items });\n continue;\n }\n }\n\n next.push(item);\n }\n\n return { items: next, removed };\n}\n\nfunction insertResource(\n items: SidebarResource[],\n resource: SidebarResource,\n targetId: string | null,\n position: SidebarResourceDropPosition,\n): SidebarResource[] {\n if (targetId === null) return [...items, resource];\n\n const next: SidebarResource[] = [];\n for (const item of items) {\n if (item.id === targetId) {\n if (position === \"before\") next.push(resource, item);\n else if (position === \"after\") next.push(item, resource);\n else next.push({ ...item, children: [...(item.children ?? []), resource] });\n continue;\n }\n\n if (item.children?.length) {\n next.push({\n ...item,\n children: insertResource(item.children, resource, targetId, position),\n });\n } else {\n next.push(item);\n }\n }\n return next;\n}\n\nfunction moveResource(\n items: SidebarResource[],\n move: SidebarResourceMove,\n): SidebarResource[] | null {\n const source = findResource(items, move.itemId);\n if (!source || source.disabled) return null;\n if (move.targetId && containsResource(source, move.targetId)) return null;\n\n const target = move.targetId ? findResource(items, move.targetId) : undefined;\n if (move.position === \"inside\" && (!target || target.disabled || !canContain(target)))\n return null;\n\n const removed = removeResource(items, move.itemId);\n if (!removed.removed) return null;\n return insertResource(removed.items, removed.removed, move.targetId, move.position);\n}\n\nfunction renameResource(items: SidebarResource[], id: string, label: string): SidebarResource[] {\n return items.map((item) => ({\n ...item,\n label: item.id === id ? label : item.label,\n children: item.children ? renameResource(item.children, id, label) : undefined,\n }));\n}\n\nfunction defaultIcon(item: SidebarResource, expanded: boolean) {\n const Icon =\n item.kind === \"folder\" || item.kind === \"project\"\n ? expanded\n ? FolderOpen\n : Folder\n : item.kind === \"bookmark\"\n ? Bookmark\n : FileText;\n return <Icon className=\"size-4\" />;\n}\n\nfunction MarqueeLabel({ active, children }: { active: boolean; children: string }) {\n const reduce = useReducedMotion() ?? false;\n const viewportRef = useRef<HTMLSpanElement>(null);\n const labelRef = useRef<HTMLSpanElement>(null);\n const [distance, setDistance] = useState(0);\n\n useEffect(() => {\n const measure = () => {\n const viewport = viewportRef.current;\n const label = labelRef.current;\n if (!viewport || !label) return;\n setDistance(label.scrollWidth > viewport.clientWidth ? label.scrollWidth + 24 : 0);\n };\n measure();\n const observer = new ResizeObserver(measure);\n if (viewportRef.current) observer.observe(viewportRef.current);\n if (labelRef.current) observer.observe(labelRef.current);\n return () => observer.disconnect();\n }, []);\n\n const running = active && distance > 0 && !reduce;\n\n return (\n <span ref={viewportRef} className=\"block min-w-0 flex-1 overflow-hidden\">\n <motion.span\n className=\"flex w-max items-center gap-6 whitespace-nowrap\"\n animate={{ x: running ? [0, -distance] : 0 }}\n transition={\n running\n ? {\n duration: Math.max(2.4, distance / 34),\n ease: \"linear\",\n repeat: Number.POSITIVE_INFINITY,\n repeatDelay: 2,\n }\n : ROW_REVEAL\n }\n >\n <span ref={labelRef}>{children}</span>\n {running ? <span aria-hidden=\"true\">{children}</span> : null}\n </motion.span>\n </span>\n );\n}\n\nfunction ResourceMenuAction({\n icon: Icon,\n onSelect,\n children,\n}: {\n icon: LucideIcon;\n onSelect: () => void;\n children: ReactNode;\n}) {\n return (\n <button\n type=\"button\"\n onClick={onSelect}\n className=\"flex h-8 w-full items-center gap-2 rounded-lg px-2.5 text-left text-foreground text-xs outline-none transition-colors hover:bg-muted focus-visible:bg-muted focus-visible:ring-2 focus-visible:ring-ring\"\n >\n <Icon aria-hidden=\"true\" className=\"size-3.5 shrink-0\" />\n <span className=\"min-w-0 truncate\">{children}</span>\n </button>\n );\n}\n\ninterface ResourceRowProps {\n row: FlatResource;\n active: boolean;\n expanded: boolean;\n focused: boolean;\n draggingId: string | null;\n dropTarget: DropTarget | null;\n menuOpen: boolean;\n moves: SidebarResourceMoveCommands;\n renaming: boolean;\n onDragEnd: () => void;\n onDragOver: (event: DragEvent<HTMLDivElement>, row: FlatResource) => void;\n onDragStart: (event: DragEvent<HTMLDivElement>, id: string) => void;\n onDrop: (event: DragEvent<HTMLDivElement>) => void;\n onFocus: () => void;\n onKeyDown: (event: KeyboardEvent<HTMLDivElement>) => void;\n onMenuOpenChange: (open: boolean) => void;\n onRenameCancel: () => void;\n onRenameCommit: (label: string) => void;\n onRenameStart: () => void;\n onSelect: () => void;\n onToggle: () => void;\n renderIcon?: (item: SidebarResource) => ReactNode;\n renderMenu?: AISidebarProps[\"renderMenu\"];\n setRef: (node: HTMLDivElement | null) => void;\n}\n\nfunction ResourceRow({\n row,\n active,\n expanded,\n focused,\n draggingId,\n dropTarget,\n menuOpen,\n moves,\n renaming,\n onDragEnd,\n onDragOver,\n onDragStart,\n onDrop,\n onFocus,\n onKeyDown,\n onMenuOpenChange,\n onRenameCancel,\n onRenameCommit,\n onRenameStart,\n onSelect,\n onToggle,\n renderIcon,\n renderMenu,\n setRef,\n}: ResourceRowProps) {\n const reduce = useReducedMotion() ?? false;\n const canTouch = useTouchCapable();\n const [hovered, setHovered] = useState(false);\n const inputRef = useRef<HTMLInputElement>(null);\n const skipRenameBlurRef = useRef(false);\n const draggedRef = useRef(false);\n const [draft, setDraft] = useState(row.item.label);\n const acceptsChildren = canContain(row.item);\n const isDragging = draggingId === row.item.id;\n const dropPosition = dropTarget?.id === row.item.id ? dropTarget.position : null;\n\n useEffect(() => {\n if (!renaming) return;\n skipRenameBlurRef.current = false;\n setDraft(row.item.label);\n requestAnimationFrame(() => {\n inputRef.current?.focus();\n inputRef.current?.select();\n });\n }, [renaming, row.item.label]);\n\n const runFromMenu = (action: () => void) => () => {\n onMenuOpenChange(false);\n action();\n };\n\n const menu = renderMenu?.(row.item, {\n close: () => onMenuOpenChange(false),\n rename: () => {\n onMenuOpenChange(false);\n onRenameStart();\n },\n moves,\n }) ?? (\n <>\n <ResourceMenuAction icon={Pencil} onSelect={runFromMenu(onRenameStart)}>\n Rename\n </ResourceMenuAction>\n {moves.up || moves.down || moves.into || moves.out ? (\n <div aria-hidden=\"true\" className=\"my-1 h-px bg-border\" />\n ) : null}\n {moves.up ? (\n <ResourceMenuAction icon={ArrowUp} onSelect={runFromMenu(moves.up)}>\n Move up\n </ResourceMenuAction>\n ) : null}\n {moves.down ? (\n <ResourceMenuAction icon={ArrowDown} onSelect={runFromMenu(moves.down)}>\n Move down\n </ResourceMenuAction>\n ) : null}\n {moves.into ? (\n <ResourceMenuAction icon={FolderInput} onSelect={runFromMenu(moves.into.run)}>\n Move into {moves.into.label}\n </ResourceMenuAction>\n ) : null}\n {moves.out ? (\n <ResourceMenuAction icon={Undo2} onSelect={runFromMenu(moves.out)}>\n Move out\n </ResourceMenuAction>\n ) : null}\n </>\n );\n\n return (\n <motion.div\n ref={setRef}\n layout=\"position\"\n transition={reduce ? { duration: 0 } : SPRING_LAYOUT}\n role=\"treeitem\"\n aria-level={row.depth + 1}\n aria-selected={acceptsChildren ? undefined : active}\n aria-expanded={acceptsChildren ? expanded : undefined}\n aria-disabled={row.item.disabled || undefined}\n tabIndex={focused ? 0 : -1}\n draggable={!row.item.disabled && !renaming}\n data-menu-open={menuOpen || undefined}\n data-drop={dropPosition ?? undefined}\n data-dragging={isDragging || undefined}\n onFocus={onFocus}\n onKeyDown={onKeyDown}\n onClick={(event) => {\n if (event.defaultPrevented || draggedRef.current || renaming || row.item.disabled) return;\n if (acceptsChildren) onToggle();\n else onSelect();\n }}\n onDoubleClick={(event) => {\n if (acceptsChildren || row.item.disabled) return;\n event.preventDefault();\n onRenameStart();\n }}\n onMouseEnter={() => setHovered(true)}\n onMouseLeave={() => setHovered(false)}\n onDragStartCapture={(event) => {\n draggedRef.current = true;\n onDragStart(event, row.item.id);\n }}\n onDragEndCapture={() => {\n onDragEnd();\n requestAnimationFrame(() => {\n draggedRef.current = false;\n });\n }}\n onDragOver={(event) => onDragOver(event, row)}\n onDrop={onDrop}\n className={cn(\n \"group/resource relative flex min-h-9 min-w-0 cursor-pointer items-center gap-2.5 rounded-xl pr-3 text-sm outline-none\",\n \"text-muted-foreground transition-colors hover:bg-muted hover:text-foreground\",\n \"focus-visible:bg-muted/70 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset\",\n \"data-[menu-open=true]:bg-muted data-[menu-open=true]:text-foreground\",\n \"data-[dragging=true]:opacity-40\",\n \"data-[drop=inside]:bg-primary/10 data-[drop=inside]:ring-1 data-[drop=inside]:ring-primary/45\",\n \"data-[drop=before]:before:absolute data-[drop=before]:before:-top-0.5 data-[drop=before]:before:right-2 data-[drop=before]:before:left-2 data-[drop=before]:before:h-0.5 data-[drop=before]:before:rounded-full data-[drop=before]:before:bg-primary\",\n \"data-[drop=after]:after:absolute data-[drop=after]:after:right-2 data-[drop=after]:after:-bottom-0.5 data-[drop=after]:after:left-2 data-[drop=after]:after:h-0.5 data-[drop=after]:after:rounded-full data-[drop=after]:after:bg-primary\",\n !acceptsChildren && active && \"bg-muted text-foreground\",\n row.item.disabled && \"cursor-not-allowed opacity-45\",\n )}\n style={{ paddingLeft: `${12 + row.depth * 16}px` }}\n >\n <span aria-hidden=\"true\" className=\"grid size-5 shrink-0 place-items-center\">\n {renderIcon?.(row.item) ?? defaultIcon(row.item, expanded)}\n </span>\n\n {renaming ? (\n <input\n ref={inputRef}\n value={draft}\n aria-label={`Rename ${row.item.label}`}\n onChange={(event) => setDraft(event.target.value)}\n draggable={false}\n onClick={(event) => event.stopPropagation()}\n onDoubleClick={(event) => event.stopPropagation()}\n onBlur={() => {\n if (!skipRenameBlurRef.current) onRenameCommit(draft);\n }}\n onKeyDown={(event) => {\n event.stopPropagation();\n if (event.key === \"Enter\") {\n skipRenameBlurRef.current = true;\n onRenameCommit(draft);\n }\n if (event.key === \"Escape\") {\n skipRenameBlurRef.current = true;\n onRenameCancel();\n }\n }}\n className=\"mx-1 h-7 min-w-0 flex-1 rounded-md border border-border bg-background px-2 text-foreground text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n />\n ) : (\n <MarqueeLabel active={hovered || menuOpen}>{row.item.label}</MarqueeLabel>\n )}\n\n {!renaming && !row.item.disabled ? (\n <MorphPopover open={menuOpen} onOpenChange={onMenuOpenChange}>\n <MorphPopoverTrigger>\n <button\n type=\"button\"\n draggable={false}\n tabIndex={-1}\n aria-label={`Actions for ${row.item.label}`}\n onClick={(event) => event.stopPropagation()}\n className={cn(\n \"grid size-7 shrink-0 place-items-center rounded-lg outline-none transition-opacity hover:bg-foreground/5 focus-visible:opacity-100 focus-visible:ring-2 focus-visible:ring-ring group-hover/resource:opacity-100 group-data-[menu-open=true]/resource:opacity-100\",\n // A finger never hovers, and this menu is the only path to\n // rename and move without a drag — keep it on screen there.\n canTouch ? \"opacity-100\" : \"opacity-0\",\n )}\n >\n <MoreHorizontal aria-hidden=\"true\" className=\"size-4\" />\n </button>\n </MorphPopoverTrigger>\n <MorphPopoverContent\n side=\"bottom\"\n align=\"end\"\n sideOffset={8}\n radius={12}\n className=\"w-40 p-1.5\"\n >\n <div data-sidebar-resource-menu={row.item.id}>{menu}</div>\n </MorphPopoverContent>\n </MorphPopover>\n ) : null}\n </motion.div>\n );\n}\n\nexport function AISidebar({\n items,\n defaultItems = [],\n onItemsChange,\n onMove,\n onMoveError,\n onRename,\n activeId,\n defaultActiveId = null,\n onActiveChange,\n defaultExpandedIds = [],\n renderIcon,\n renderMenu,\n ariaLabel = \"Resources\",\n className,\n}: AISidebarProps) {\n const [internalItems, setInternalItems] = useState(items ?? defaultItems);\n const [internalActiveId, setInternalActiveId] = useState(defaultActiveId);\n const [expandedIds, setExpandedIds] = useState(() => new Set(defaultExpandedIds));\n const [focusedId, setFocusedId] = useState<string | null>(activeId ?? defaultActiveId);\n const [draggingId, setDraggingId] = useState<string | null>(null);\n const [dropTarget, setDropTarget] = useState<DropTarget | null>(null);\n const [menuOpenId, setMenuOpenId] = useState<string | null>(null);\n const [renamingId, setRenamingId] = useState<string | null>(null);\n const [announcement, setAnnouncement] = useState(\"\");\n const rowRefs = useRef(new Map<string, HTMLDivElement>());\n const movePendingRef = useRef(false);\n const renderedItems = internalItems;\n const selectedId = activeId ?? internalActiveId;\n\n useEffect(() => {\n if (items) setInternalItems(items);\n }, [items]);\n\n const flat = useMemo(\n () => flattenResources(renderedItems, expandedIds),\n [expandedIds, renderedItems],\n );\n\n // Which row carries the roving tabindex is resolved during render, never in\n // a passive effect: an effect lands after the browser paints, so the first\n // commit — and, on a server-rendered page, the markup itself — would have no\n // tabbable row and Tab would skip the whole tree. The same hole opens again\n // whenever a collapse or a rolled-back move takes the focused row out of it.\n const focusedRow =\n focusedId !== null && flat.some((row) => row.item.id === focusedId)\n ? focusedId\n : (flat[0]?.item.id ?? null);\n if (focusedId !== focusedRow) setFocusedId(focusedRow);\n\n useEffect(() => {\n if (!menuOpenId) return;\n const frame = requestAnimationFrame(() => {\n const menus = Array.from(\n document.querySelectorAll<HTMLElement>(\"[data-sidebar-resource-menu]\"),\n );\n menus\n .find((menu) => menu.dataset.sidebarResourceMenu === menuOpenId)\n ?.querySelector<HTMLElement>(\"button, a[href]\")\n ?.focus();\n });\n return () => cancelAnimationFrame(frame);\n }, [menuOpenId]);\n\n const updateItems = useCallback(\n (next: SidebarResource[]) => {\n setInternalItems(next);\n onItemsChange?.(next);\n },\n [onItemsChange],\n );\n\n const performMove = useCallback(\n async (move: SidebarResourceMove) => {\n if (movePendingRef.current) {\n setAnnouncement(\"Wait for the current move to finish.\");\n return;\n }\n const before = renderedItems;\n const next = moveResource(before, move);\n if (!next || next === before) return;\n\n movePendingRef.current = true;\n updateItems(next);\n setDropTarget(null);\n setDraggingId(null);\n const moved = findResource(before, move.itemId);\n const target = move.targetId ? findResource(before, move.targetId) : null;\n setAnnouncement(\n target\n ? `Moved ${moved?.label ?? \"item\"} ${move.position} ${target.label}.`\n : `Moved ${moved?.label ?? \"item\"} to the top level.`,\n );\n\n try {\n await onMove?.(move);\n } catch (error) {\n updateItems(before);\n setAnnouncement(`Move failed. ${moved?.label ?? \"Item\"} was restored.`);\n onMoveError?.(error, move);\n } finally {\n movePendingRef.current = false;\n }\n },\n [onMove, onMoveError, renderedItems, updateItems],\n );\n\n const focusRow = useCallback((id: string) => {\n setFocusedId(id);\n requestAnimationFrame(() => rowRefs.current.get(id)?.focus());\n }, []);\n\n const select = useCallback(\n (id: string) => {\n if (activeId === undefined) setInternalActiveId(id);\n onActiveChange?.(id);\n },\n [activeId, onActiveChange],\n );\n\n const toggle = useCallback((id: string) => {\n setExpandedIds((current) => {\n const next = new Set(current);\n if (next.has(id)) next.delete(id);\n else next.add(id);\n return next;\n });\n }, []);\n\n // The same four moves `Alt+Shift+Arrow` performs, handed to the row menu so\n // they survive on a device with no drag and no modifier keys.\n const moveCommands = useCallback(\n (row: FlatResource): SidebarResourceMoveCommands => {\n if (row.item.disabled) return {};\n const index = flat.findIndex(({ item }) => item.id === row.item.id);\n const previous = flat[index - 1];\n const next = flat[index + 1];\n const parentId = row.parentId;\n const commands: SidebarResourceMoveCommands = {};\n\n if (previous) {\n commands.up = () =>\n void performMove({\n itemId: row.item.id,\n targetId: previous.item.id,\n position: \"before\",\n });\n }\n if (next) {\n commands.down = () =>\n void performMove({\n itemId: row.item.id,\n targetId: next.item.id,\n position: \"after\",\n });\n }\n // Only offer the reparent when it lands somewhere new — the row above a\n // folder's first child is the folder it already lives in.\n if (previous && canContain(previous.item) && previous.item.id !== parentId) {\n commands.into = {\n label: previous.item.label,\n run: () => {\n setExpandedIds((current) => new Set(current).add(previous.item.id));\n void performMove({\n itemId: row.item.id,\n targetId: previous.item.id,\n position: \"inside\",\n });\n },\n };\n }\n if (parentId) {\n commands.out = () =>\n void performMove({\n itemId: row.item.id,\n targetId: parentId,\n position: \"after\",\n });\n }\n\n return commands;\n },\n [flat, performMove],\n );\n\n const handleKeyDown = useCallback(\n (event: KeyboardEvent<HTMLDivElement>, row: FlatResource) => {\n const index = flat.findIndex(({ item }) => item.id === row.item.id);\n const previous = flat[index - 1];\n const next = flat[index + 1];\n const moveModifier = event.altKey && event.shiftKey;\n\n if (event.key === \"ArrowDown\" && !moveModifier && next) {\n event.preventDefault();\n focusRow(next.item.id);\n return;\n }\n if (event.key === \"ArrowUp\" && !moveModifier && previous) {\n event.preventDefault();\n focusRow(previous.item.id);\n return;\n }\n if (event.key === \"Home\" && flat[0]) {\n event.preventDefault();\n focusRow(flat[0].item.id);\n return;\n }\n if (event.key === \"End\" && flat.at(-1)) {\n event.preventDefault();\n focusRow(flat.at(-1)?.item.id ?? row.item.id);\n return;\n }\n\n if (row.item.disabled) {\n if (event.key === \"ArrowLeft\" && row.parentId) {\n event.preventDefault();\n focusRow(row.parentId);\n } else if (\n moveModifier ||\n [\"ArrowRight\", \"Enter\", \" \", \"F2\", \"ContextMenu\"].includes(event.key) ||\n (event.shiftKey && event.key === \"F10\")\n ) {\n event.preventDefault();\n }\n return;\n }\n\n if (moveModifier && event.key === \"ArrowUp\" && previous) {\n event.preventDefault();\n void performMove({ itemId: row.item.id, targetId: previous.item.id, position: \"before\" });\n return;\n }\n if (moveModifier && event.key === \"ArrowDown\" && next) {\n event.preventDefault();\n void performMove({ itemId: row.item.id, targetId: next.item.id, position: \"after\" });\n return;\n }\n if (moveModifier && event.key === \"ArrowRight\" && previous && canContain(previous.item)) {\n event.preventDefault();\n setExpandedIds((current) => new Set(current).add(previous.item.id));\n void performMove({ itemId: row.item.id, targetId: previous.item.id, position: \"inside\" });\n return;\n }\n if (moveModifier && event.key === \"ArrowLeft\" && row.parentId) {\n event.preventDefault();\n void performMove({ itemId: row.item.id, targetId: row.parentId, position: \"after\" });\n return;\n }\n\n if (event.key === \"ArrowRight\" && canContain(row.item)) {\n event.preventDefault();\n if (!expandedIds.has(row.item.id)) toggle(row.item.id);\n else if (next?.parentId === row.item.id) focusRow(next.item.id);\n } else if (event.key === \"ArrowLeft\") {\n event.preventDefault();\n if (expandedIds.has(row.item.id)) toggle(row.item.id);\n else if (row.parentId) focusRow(row.parentId);\n } else if (event.key === \"Enter\" || event.key === \" \") {\n event.preventDefault();\n if (canContain(row.item)) toggle(row.item.id);\n else select(row.item.id);\n } else if (event.key === \"F2\") {\n event.preventDefault();\n setRenamingId(row.item.id);\n } else if (event.key === \"ContextMenu\" || (event.shiftKey && event.key === \"F10\")) {\n event.preventDefault();\n setMenuOpenId(row.item.id);\n }\n },\n [expandedIds, flat, focusRow, performMove, select, toggle],\n );\n\n return (\n <>\n <div\n role=\"tree\"\n aria-label={ariaLabel}\n aria-multiselectable=\"false\"\n onDragOver={(event) => {\n if (!draggingId || event.target !== event.currentTarget) return;\n event.preventDefault();\n setDropTarget({ id: null, position: \"after\" });\n }}\n onDrop={(event) => {\n event.preventDefault();\n if (draggingId && dropTarget) {\n void performMove({\n itemId: draggingId,\n targetId: dropTarget.id,\n position: dropTarget.position,\n });\n }\n }}\n className={cn(\n \"relative flex min-w-0 flex-col gap-0.5 [overflow-anchor:none] group-data-[state=collapsed]/sidebar:hidden\",\n draggingId && \"select-none pb-9\",\n className,\n )}\n >\n <AnimatePresence initial={false}>\n {flat.map((row) => (\n <ResourceRow\n key={row.item.id}\n row={row}\n active={selectedId === row.item.id}\n expanded={expandedIds.has(row.item.id)}\n focused={focusedRow === row.item.id}\n draggingId={draggingId}\n dropTarget={dropTarget}\n menuOpen={menuOpenId === row.item.id}\n moves={moveCommands(row)}\n renaming={renamingId === row.item.id}\n onFocus={() => setFocusedId(row.item.id)}\n onSelect={() => select(row.item.id)}\n onToggle={() => toggle(row.item.id)}\n onKeyDown={(event) => handleKeyDown(event, row)}\n onRenameStart={() => setRenamingId(row.item.id)}\n onRenameCancel={() => setRenamingId(null)}\n onRenameCommit={(label) => {\n const trimmed = label.trim();\n setRenamingId(null);\n if (!trimmed || trimmed === row.item.label) return;\n const before = renderedItems;\n updateItems(renameResource(before, row.item.id, trimmed));\n void Promise.resolve(onRename?.(row.item, trimmed)).catch(() => {\n updateItems(before);\n setAnnouncement(`Rename failed. ${row.item.label} was restored.`);\n });\n }}\n onMenuOpenChange={(open) => {\n setMenuOpenId(open ? row.item.id : null);\n if (!open) focusRow(row.item.id);\n }}\n onDragStart={(event, id) => {\n setDraggingId(id);\n event.dataTransfer.effectAllowed = \"move\";\n event.dataTransfer.setData(\"text/plain\", id);\n }}\n onDragEnd={() => {\n setDraggingId(null);\n setDropTarget(null);\n }}\n onDragOver={(event, targetRow) => {\n if (!draggingId || draggingId === targetRow.item.id) return;\n const source = findResource(renderedItems, draggingId);\n if (source && containsResource(source, targetRow.item.id)) return;\n event.preventDefault();\n event.stopPropagation();\n const rect = event.currentTarget.getBoundingClientRect();\n const ratio = (event.clientY - rect.top) / rect.height;\n const position =\n !targetRow.item.disabled &&\n canContain(targetRow.item) &&\n ratio >= 0.25 &&\n ratio <= 0.75\n ? \"inside\"\n : ratio < 0.5\n ? \"before\"\n : \"after\";\n setDropTarget({ id: targetRow.item.id, position });\n }}\n onDrop={(event) => {\n event.preventDefault();\n event.stopPropagation();\n if (draggingId && dropTarget) {\n void performMove({\n itemId: draggingId,\n targetId: dropTarget.id,\n position: dropTarget.position,\n });\n }\n }}\n renderIcon={renderIcon}\n renderMenu={renderMenu}\n setRef={(node) => {\n if (node) rowRefs.current.set(row.item.id, node);\n else rowRefs.current.delete(row.item.id);\n }}\n />\n ))}\n </AnimatePresence>\n\n {draggingId ? (\n <div\n aria-hidden=\"true\"\n data-active={dropTarget?.id === null || undefined}\n className=\"absolute inset-x-1 bottom-0 flex h-8 items-center justify-center rounded-lg border border-border border-dashed text-[10px] text-muted-foreground data-[active=true]:border-primary/50 data-[active=true]:bg-primary/10 data-[active=true]:text-foreground\"\n >\n Move to top level\n </div>\n ) : null}\n </div>\n <span className=\"sr-only\" aria-live=\"polite\">\n {announcement}\n </span>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;AAkGA,MAAM,aAAa;CACjB,UAAU;CACV,MAAM;AACR;AAEA,SAAS,WAAW,MAAuB;CACzC,OAAO,KAAK,SAAS,YAAY,KAAK,SAAS;AACjD;AAEA,SAAS,iBACP,OACA,UACA,QAAQ,GACR,WAA0B,MACV;CAChB,OAAO,MAAM,SAAS,SAAS;EAC7B,MAAM,MAAM;GAAE;GAAM;GAAO;EAAS;EACpC,IAAI,CAAC,KAAK,UAAU,UAAU,CAAC,SAAS,IAAI,KAAK,EAAE,GAAG,OAAO,CAAC,GAAG;EACjE,OAAO,CAAC,KAAK,GAAG,iBAAiB,KAAK,UAAU,UAAU,QAAQ,GAAG,KAAK,EAAE,CAAC;CAC/E,CAAC;AACH;AAEA,SAAS,aAAa,OAA0B,IAAyC;CACvF,KAAK,MAAM,QAAQ,OAAO;EACxB,IAAI,KAAK,OAAO,IAAI,OAAO;EAC3B,MAAM,QAAQ,KAAK,WAAW,aAAa,KAAK,UAAU,EAAE,IAAI,KAAA;EAChE,IAAI,OAAO,OAAO;CACpB;AACF;AAEA,SAAS,iBAAiB,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,UAAU,KAAK,IAAI;KACrD,MAAM,SAAS,aAAa,eAAe,UAAU;KACrD,IAAI,UAAU,iBAAiB,QAAQ,UAAU,KAAK,EAAE,GAAG;KAC3D,MAAM,eAAe;KACrB,MAAM,gBAAgB;KACtB,MAAM,OAAO,MAAM,cAAc,sBAAsB;KACvD,MAAM,SAAS,MAAM,UAAU,KAAK,OAAO,KAAK;KAChD,MAAM,WACJ,CAAC,UAAU,KAAK,YAChB,WAAW,UAAU,IAAI,KACzB,SAAS,OACT,SAAS,MACL,WACA,QAAQ,KACN,WACA;KACR,cAAc;MAAE,IAAI,UAAU,KAAK;MAAI;KAAS,CAAC;IACnD;IACA,SAAS,UAAU;KACjB,MAAM,eAAe;KACrB,MAAM,gBAAgB;KACtB,IAAI,cAAc,YAChB,YAAiB;MACf,QAAQ;MACR,UAAU,WAAW;MACrB,UAAU,WAAW;KACvB,CAAC;IAEL;IACY;IACA;IACZ,SAAS,SAAS;KAChB,IAAI,MAAM,QAAQ,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI;UAC1C,QAAQ,QAAQ,OAAO,IAAI,KAAK,EAAE;IACzC;GACD,GA5EM,IAAI,KAAK,EA4Ef,CACF;EACc,CAAA,GAEhB,aACC,oBAAC,OAAD;GACE,eAAY;GACZ,eAAa,YAAY,OAAO,QAAQ,KAAA;GACxC,WAAU;GACX,UAAA;EAEI,CAAA,IACH,IACD;CACL,CAAA,GAAA,oBAAC,QAAD;EAAM,WAAU;EAAU,aAAU;EACjC,UAAA;CACG,CAAA,CACN,EAAA,CAAA;AAEN"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { t as usePopoverPortalPosition } from "../../../popover-position-BUqYCq8X.js";
|
|
3
|
-
import { useComboboxContext } from "
|
|
3
|
+
import { a as useComboboxContext } from "../../../context-BizvUNZv.js";
|
|
4
4
|
import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
5
5
|
import { cn } from "@kumix/utils";
|
|
6
6
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -17,7 +17,13 @@ type ComboboxContextValue = {
|
|
|
17
17
|
select: (value: string) => void;
|
|
18
18
|
query: string;
|
|
19
19
|
setQuery: (query: string) => void;
|
|
20
|
+
/** The option the list is currently pointing at, resolved during render. */
|
|
20
21
|
activeValue: string | null;
|
|
22
|
+
/**
|
|
23
|
+
* Records where the pointer or keyboard moved to. The recorded value is
|
|
24
|
+
* dropped when the query or the result set changes, so it does not always
|
|
25
|
+
* survive to the next `activeValue`.
|
|
26
|
+
*/
|
|
21
27
|
setActiveValue: (value: string | null) => void;
|
|
22
28
|
moveActive: (direction: 1 | -1 | "first" | "last") => void;
|
|
23
29
|
selectActive: () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","names":[],"sources":["../../../../src/components/motion/combobox/context.tsx"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"context.d.ts","names":[],"sources":["../../../../src/components/motion/combobox/context.tsx"],"mappings":";;KAoBY;EACV;EACA;EACA;EACA;EACA;EACA;EACA,KAAK,iBAAiB;;KAGZ,kBAAkB,eAAe,eAAe;KAehD;EACV;EACA,UAAU,eAAe;EACzB;EACA,SAAS;EACT;EACA,WAAW;;EAEX;;;;;;EAMA,iBAAiB;EACjB,aAAa;EACb;EACA,eAAe,MAAM;EACrB,iBAAiB;EACjB,WAAW;EACX,YAAY;EACZ,kBAAkB;EAClB;EACA;EACA;EACA;EACA;EACA;EACA;EACA,YAAY,iBAAiB;EAC7B,YAAY,iBAAiB;EAC7B,UAAU,iBAAiB;EAC3B;;cAGW,iCAAe,QAAA;cACf,sCAAoB;iBAEjB,mBAAmB,oBAAiB;iBAMpC,UAAU,MAAM,MAAM,MAAM,IAAI,mBACtC,MAAM;UAQC;EACf,UAAU;EACV;EACA;EACA,iBAAiB;EACjB;EACA;EACA,gBAAgB;EAChB;EACA;EACA,iBAAiB;EACjB,SAAS;EACT;EACA;;iBAGc,WACd,UACA,OAAO,iBACP,cACA,eACA,MAAM,gBACN,aACA,cACA,OAAO,iBACP,cACA,eACA,QACA,UACA,aACC,gCAAa,IAAA"}
|
|
@@ -1,235 +1,3 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import { cn } from "@kumix/utils";
|
|
4
|
-
import { jsx } from "react/jsx-runtime";
|
|
5
|
-
import { useReducedMotion } from "motion/react";
|
|
6
|
-
//#region src/components/motion/combobox/context.tsx
|
|
7
|
-
const defaultFilter = (value, query, keywords) => {
|
|
8
|
-
const needle = query.trim().toLocaleLowerCase();
|
|
9
|
-
if (!needle) return true;
|
|
10
|
-
const haystack = [value, ...keywords].join(" ").toLocaleLowerCase();
|
|
11
|
-
let queryIndex = 0;
|
|
12
|
-
for (const character of haystack) {
|
|
13
|
-
if (character === needle[queryIndex]) queryIndex += 1;
|
|
14
|
-
if (queryIndex === needle.length) return true;
|
|
15
|
-
}
|
|
16
|
-
return false;
|
|
17
|
-
};
|
|
18
|
-
const ComboboxContext = createContext(null);
|
|
19
|
-
const ComboboxGroupContext = createContext(null);
|
|
20
|
-
function useComboboxContext(component) {
|
|
21
|
-
const context = useContext(ComboboxContext);
|
|
22
|
-
if (!context) throw new Error(`${component} must be used within <Combobox>`);
|
|
23
|
-
return context;
|
|
24
|
-
}
|
|
25
|
-
function mergeRefs(...refs) {
|
|
26
|
-
return (node) => {
|
|
27
|
-
for (const ref of refs) if (typeof ref === "function") ref(node);
|
|
28
|
-
else if (ref && typeof ref === "object") ref.current = node;
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
function Combobox({ children, value: controlledValue, defaultValue, onValueChange, open: controlledOpen, defaultOpen = false, onOpenChange, query: controlledQuery, defaultQuery = "", onQueryChange, filter = defaultFilter, disabled = false, className }) {
|
|
32
|
-
const reduce = useReducedMotion() ?? false;
|
|
33
|
-
const baseId = useId();
|
|
34
|
-
const rootRef = useRef(null);
|
|
35
|
-
const triggerRef = useRef(null);
|
|
36
|
-
const contentRef = useRef(null);
|
|
37
|
-
const inputRef = useRef(null);
|
|
38
|
-
const [internalValue, setInternalValue] = useState(defaultValue);
|
|
39
|
-
const [internalOpen, setInternalOpen] = useState(defaultOpen);
|
|
40
|
-
const [internalQuery, setInternalQuery] = useState(defaultQuery);
|
|
41
|
-
const [activeValue, setActiveValue] = useState(null);
|
|
42
|
-
const [items, setItems] = useState(/* @__PURE__ */ new Map());
|
|
43
|
-
const valueControlled = controlledValue !== void 0;
|
|
44
|
-
const openControlled = controlledOpen !== void 0;
|
|
45
|
-
const queryControlled = controlledQuery !== void 0;
|
|
46
|
-
const value = valueControlled ? controlledValue : internalValue;
|
|
47
|
-
const open = openControlled ? controlledOpen : internalOpen;
|
|
48
|
-
const query = queryControlled ? controlledQuery : internalQuery;
|
|
49
|
-
const updateQuery = useCallback((next) => {
|
|
50
|
-
if (!queryControlled) setInternalQuery(next);
|
|
51
|
-
onQueryChange?.(next);
|
|
52
|
-
}, [onQueryChange, queryControlled]);
|
|
53
|
-
const updateOpen = useCallback((next, restoreFocus = false) => {
|
|
54
|
-
if (disabled && next) return;
|
|
55
|
-
if (!openControlled) setInternalOpen(next);
|
|
56
|
-
onOpenChange?.(next);
|
|
57
|
-
if (!next) updateQuery("");
|
|
58
|
-
if (restoreFocus) requestAnimationFrame(() => inputRef.current?.focus({ preventScroll: true }));
|
|
59
|
-
}, [
|
|
60
|
-
disabled,
|
|
61
|
-
onOpenChange,
|
|
62
|
-
openControlled,
|
|
63
|
-
updateQuery
|
|
64
|
-
]);
|
|
65
|
-
const registerItem = useCallback((item) => {
|
|
66
|
-
setItems((current) => {
|
|
67
|
-
const existing = current.get(item.value);
|
|
68
|
-
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;
|
|
69
|
-
const next = new Map(current);
|
|
70
|
-
next.set(item.value, item);
|
|
71
|
-
return next;
|
|
72
|
-
});
|
|
73
|
-
}, []);
|
|
74
|
-
const unregisterItem = useCallback((itemValue) => {
|
|
75
|
-
setItems((current) => {
|
|
76
|
-
if (!current.has(itemValue)) return current;
|
|
77
|
-
const next = new Map(current);
|
|
78
|
-
next.delete(itemValue);
|
|
79
|
-
return next;
|
|
80
|
-
});
|
|
81
|
-
}, []);
|
|
82
|
-
const visibleItems = useMemo(() => Array.from(items.values()).filter((item) => filter(item.value, query, [item.label, ...item.keywords])), [
|
|
83
|
-
filter,
|
|
84
|
-
items,
|
|
85
|
-
query
|
|
86
|
-
]);
|
|
87
|
-
const enabledVisibleItems = useMemo(() => visibleItems.filter((item) => !item.disabled), [visibleItems]);
|
|
88
|
-
const visibleValues = useMemo(() => new Set(visibleItems.map((item) => item.value)), [visibleItems]);
|
|
89
|
-
const visibleGroupIds = useMemo(() => new Set(visibleItems.map((item) => item.groupId)), [visibleItems]);
|
|
90
|
-
const select = useCallback((next) => {
|
|
91
|
-
if (items.get(next)?.disabled) return;
|
|
92
|
-
if (!valueControlled) setInternalValue(next);
|
|
93
|
-
onValueChange?.(next);
|
|
94
|
-
updateOpen(false, true);
|
|
95
|
-
}, [
|
|
96
|
-
items,
|
|
97
|
-
onValueChange,
|
|
98
|
-
updateOpen,
|
|
99
|
-
valueControlled
|
|
100
|
-
]);
|
|
101
|
-
const moveActive = useCallback((direction) => {
|
|
102
|
-
if (!enabledVisibleItems.length) {
|
|
103
|
-
setActiveValue(null);
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
if (direction === "first") {
|
|
107
|
-
setActiveValue(enabledVisibleItems[0].value);
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
if (direction === "last") {
|
|
111
|
-
setActiveValue(enabledVisibleItems.at(-1)?.value ?? null);
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
const currentIndex = enabledVisibleItems.findIndex((item) => item.value === activeValue);
|
|
115
|
-
const nextIndex = currentIndex < 0 ? direction === 1 ? 0 : enabledVisibleItems.length - 1 : (currentIndex + direction + enabledVisibleItems.length) % enabledVisibleItems.length;
|
|
116
|
-
setActiveValue(enabledVisibleItems[nextIndex].value);
|
|
117
|
-
}, [activeValue, enabledVisibleItems]);
|
|
118
|
-
const selectActive = useCallback(() => {
|
|
119
|
-
if (activeValue) select(activeValue);
|
|
120
|
-
}, [activeValue, select]);
|
|
121
|
-
useEffect(() => {
|
|
122
|
-
if (!open) return;
|
|
123
|
-
const selectedVisible = value && visibleValues.has(value) ? value : null;
|
|
124
|
-
const activeVisible = activeValue && visibleValues.has(activeValue) ? activeValue : null;
|
|
125
|
-
setActiveValue(activeVisible ?? selectedVisible ?? enabledVisibleItems[0]?.value ?? null);
|
|
126
|
-
}, [
|
|
127
|
-
activeValue,
|
|
128
|
-
enabledVisibleItems,
|
|
129
|
-
open,
|
|
130
|
-
value,
|
|
131
|
-
visibleValues
|
|
132
|
-
]);
|
|
133
|
-
useEffect(() => {
|
|
134
|
-
if (!open) return;
|
|
135
|
-
requestAnimationFrame(() => inputRef.current?.focus({ preventScroll: true }));
|
|
136
|
-
}, [open]);
|
|
137
|
-
useEffect(() => {
|
|
138
|
-
if (!activeValue || !open) return;
|
|
139
|
-
const item = items.get(activeValue)?.ref.current;
|
|
140
|
-
const list = item?.closest("[role='listbox']");
|
|
141
|
-
if (!item || !list) return;
|
|
142
|
-
const itemRect = item.getBoundingClientRect();
|
|
143
|
-
const listRect = list.getBoundingClientRect();
|
|
144
|
-
if (itemRect.top < listRect.top) list.scrollTop -= listRect.top - itemRect.top;
|
|
145
|
-
else if (itemRect.bottom > listRect.bottom) list.scrollTop += itemRect.bottom - listRect.bottom;
|
|
146
|
-
}, [
|
|
147
|
-
activeValue,
|
|
148
|
-
items,
|
|
149
|
-
open
|
|
150
|
-
]);
|
|
151
|
-
useEffect(() => {
|
|
152
|
-
if (!open) return;
|
|
153
|
-
const isInside = (target) => rootRef.current?.contains(target) || contentRef.current?.contains(target);
|
|
154
|
-
const onPointerDown = (event) => {
|
|
155
|
-
if (!isInside(event.target)) updateOpen(false);
|
|
156
|
-
};
|
|
157
|
-
const onFocusIn = (event) => {
|
|
158
|
-
if (!isInside(event.target)) updateOpen(false);
|
|
159
|
-
};
|
|
160
|
-
const onKeyDown = (event) => {
|
|
161
|
-
if (event.key !== "Escape") return;
|
|
162
|
-
event.preventDefault();
|
|
163
|
-
updateOpen(false, true);
|
|
164
|
-
};
|
|
165
|
-
window.addEventListener("pointerdown", onPointerDown);
|
|
166
|
-
window.addEventListener("focusin", onFocusIn);
|
|
167
|
-
window.addEventListener("keydown", onKeyDown);
|
|
168
|
-
return () => {
|
|
169
|
-
window.removeEventListener("pointerdown", onPointerDown);
|
|
170
|
-
window.removeEventListener("focusin", onFocusIn);
|
|
171
|
-
window.removeEventListener("keydown", onKeyDown);
|
|
172
|
-
};
|
|
173
|
-
}, [open, updateOpen]);
|
|
174
|
-
const activeItem = activeValue ? items.get(activeValue) : void 0;
|
|
175
|
-
const context = useMemo(() => ({
|
|
176
|
-
open,
|
|
177
|
-
setOpen: updateOpen,
|
|
178
|
-
value,
|
|
179
|
-
select,
|
|
180
|
-
query,
|
|
181
|
-
setQuery: updateQuery,
|
|
182
|
-
activeValue,
|
|
183
|
-
setActiveValue,
|
|
184
|
-
moveActive,
|
|
185
|
-
selectActive,
|
|
186
|
-
registerItem,
|
|
187
|
-
unregisterItem,
|
|
188
|
-
labelFor: (itemValue) => itemValue === void 0 ? void 0 : items.get(itemValue)?.label,
|
|
189
|
-
isVisible: (itemValue) => !query.trim() || visibleValues.has(itemValue),
|
|
190
|
-
hasVisibleItems: (groupId) => visibleGroupIds.has(groupId),
|
|
191
|
-
visibleCount: visibleItems.length,
|
|
192
|
-
activeItemId: activeItem?.id,
|
|
193
|
-
triggerId: `${baseId}-trigger`,
|
|
194
|
-
listId: `${baseId}-list`,
|
|
195
|
-
inputId: `${baseId}-input`,
|
|
196
|
-
disabled,
|
|
197
|
-
reduce,
|
|
198
|
-
triggerRef,
|
|
199
|
-
contentRef,
|
|
200
|
-
inputRef,
|
|
201
|
-
activeLayoutId: `${baseId}-active`
|
|
202
|
-
}), [
|
|
203
|
-
activeItem?.id,
|
|
204
|
-
activeValue,
|
|
205
|
-
baseId,
|
|
206
|
-
disabled,
|
|
207
|
-
items,
|
|
208
|
-
moveActive,
|
|
209
|
-
open,
|
|
210
|
-
query,
|
|
211
|
-
reduce,
|
|
212
|
-
registerItem,
|
|
213
|
-
select,
|
|
214
|
-
selectActive,
|
|
215
|
-
unregisterItem,
|
|
216
|
-
updateOpen,
|
|
217
|
-
updateQuery,
|
|
218
|
-
value,
|
|
219
|
-
visibleItems.length,
|
|
220
|
-
visibleGroupIds,
|
|
221
|
-
visibleValues
|
|
222
|
-
]);
|
|
223
|
-
return /* @__PURE__ */ jsx(ComboboxContext.Provider, {
|
|
224
|
-
value: context,
|
|
225
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
226
|
-
ref: rootRef,
|
|
227
|
-
className: cn("relative w-full", className),
|
|
228
|
-
children
|
|
229
|
-
})
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
//#endregion
|
|
2
|
+
import { a as useComboboxContext, i as mergeRefs, n as ComboboxContext, r as ComboboxGroupContext, t as Combobox } from "../../../context-BizvUNZv.js";
|
|
233
3
|
export { Combobox, ComboboxContext, ComboboxGroupContext, mergeRefs, useComboboxContext };
|
|
234
|
-
|
|
235
|
-
//# sourceMappingURL=context.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { EASE_OUT, SPRING_LAYOUT } from "../../../lib/ease.js";
|
|
3
|
-
import {
|
|
3
|
+
import { a as useComboboxContext, r as ComboboxGroupContext } from "../../../context-BizvUNZv.js";
|
|
4
4
|
import { useContext, useId, useLayoutEffect, useMemo, useRef } from "react";
|
|
5
5
|
import { cn } from "@kumix/utils";
|
|
6
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { a as useComboboxContext, i as mergeRefs } from "../../../context-BizvUNZv.js";
|
|
3
3
|
import { cn } from "@kumix/utils";
|
|
4
4
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
5
|
import { ChevronsUpDown, Search } from "lucide-react";
|
|
@@ -42,14 +42,13 @@ function ComboboxInput({ ref, className, wrapperClassName, "aria-label": ariaLab
|
|
|
42
42
|
const handleKeyDown = (event) => {
|
|
43
43
|
onKeyDown?.(event);
|
|
44
44
|
if (event.defaultPrevented) return;
|
|
45
|
-
if (event.key === "ArrowDown") {
|
|
45
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
46
46
|
event.preventDefault();
|
|
47
|
-
context.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
context.
|
|
52
|
-
context.moveActive(-1);
|
|
47
|
+
if (!context.open) {
|
|
48
|
+
context.setOpen(true);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
context.moveActive(event.key === "ArrowDown" ? 1 : -1);
|
|
53
52
|
} else if (event.key === "Home" && context.open) {
|
|
54
53
|
event.preventDefault();
|
|
55
54
|
context.moveActive("first");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trigger.js","names":[],"sources":["../../../../src/components/motion/combobox/trigger.tsx"],"sourcesContent":["\"use client\";\n\nimport type {\n InputHTMLAttributes,\n KeyboardEvent as ReactKeyboardEvent,\n ReactNode,\n Ref,\n} from \"react\";\nimport { ChevronsUpDown, Search } from \"lucide-react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { mergeRefs, useComboboxContext } from \"./context\";\n\nexport interface ComboboxTriggerProps {\n children: ReactNode;\n className?: string;\n}\n\nexport function ComboboxTrigger({ children, className }: ComboboxTriggerProps) {\n const context = useComboboxContext(\"ComboboxTrigger\");\n\n return (\n <div\n ref={context.triggerRef}\n id={context.triggerId}\n data-state={context.open ? \"open\" : \"closed\"}\n onPointerDown={(event) => {\n if (context.disabled || event.target === context.inputRef.current) return;\n event.preventDefault();\n context.inputRef.current?.focus({ preventScroll: true });\n context.setOpen(true);\n }}\n className={cn(\n \"relative z-20 flex h-10 w-full min-w-52 cursor-text items-center justify-between gap-3 rounded-xl border border-border bg-transparent px-3 text-foreground text-sm transition-[border-color] hover:border-(--color-border-strong)\",\n \"focus-within:ring-2 focus-within:ring-foreground/20\",\n context.disabled && \"pointer-events-none opacity-50\",\n className,\n )}\n >\n <span className=\"min-w-0 flex-1 text-left\">{children}</span>\n <span aria-hidden className=\"shrink-0 text-muted-foreground\">\n <ChevronsUpDown className=\"size-4\" />\n </span>\n </div>\n );\n}\n\nexport interface ComboboxValueProps {\n placeholder?: ReactNode;\n children?: ReactNode | ((value: string | undefined, label: string | undefined) => ReactNode);\n className?: string;\n}\n\nexport function ComboboxValue({\n placeholder = \"Select an option\",\n children,\n className,\n}: ComboboxValueProps) {\n const context = useComboboxContext(\"ComboboxValue\");\n const label = context.labelFor(context.value);\n const content =\n typeof children === \"function\"\n ? children(context.value, label)\n : (children ?? label ?? placeholder);\n\n return (\n <span\n className={cn(\n \"block truncate\",\n context.value === undefined ? \"text-muted-foreground\" : \"text-foreground\",\n className,\n )}\n >\n {content}\n </span>\n );\n}\n\nexport interface ComboboxInputProps\n extends Omit<InputHTMLAttributes<HTMLInputElement>, \"defaultValue\" | \"value\"> {\n ref?: Ref<HTMLInputElement>;\n wrapperClassName?: string;\n}\n\nexport function ComboboxInput({\n ref,\n className,\n wrapperClassName,\n \"aria-label\": ariaLabel = \"Search options\",\n onChange,\n onClick,\n onFocus,\n onKeyDown,\n onPointerDown,\n placeholder = \"Search…\",\n ...props\n}: ComboboxInputProps) {\n const context = useComboboxContext(\"ComboboxInput\");\n const selectedLabel = context.labelFor(context.value);\n\n const handleKeyDown = (event: ReactKeyboardEvent<HTMLInputElement>) => {\n onKeyDown?.(event);\n if (event.defaultPrevented) return;\n\n if (event.key === \"ArrowDown\") {\n event.preventDefault();\n
|
|
1
|
+
{"version":3,"file":"trigger.js","names":[],"sources":["../../../../src/components/motion/combobox/trigger.tsx"],"sourcesContent":["\"use client\";\n\nimport type {\n InputHTMLAttributes,\n KeyboardEvent as ReactKeyboardEvent,\n ReactNode,\n Ref,\n} from \"react\";\nimport { ChevronsUpDown, Search } from \"lucide-react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { mergeRefs, useComboboxContext } from \"./context\";\n\nexport interface ComboboxTriggerProps {\n children: ReactNode;\n className?: string;\n}\n\nexport function ComboboxTrigger({ children, className }: ComboboxTriggerProps) {\n const context = useComboboxContext(\"ComboboxTrigger\");\n\n return (\n <div\n ref={context.triggerRef}\n id={context.triggerId}\n data-state={context.open ? \"open\" : \"closed\"}\n onPointerDown={(event) => {\n if (context.disabled || event.target === context.inputRef.current) return;\n event.preventDefault();\n context.inputRef.current?.focus({ preventScroll: true });\n context.setOpen(true);\n }}\n className={cn(\n \"relative z-20 flex h-10 w-full min-w-52 cursor-text items-center justify-between gap-3 rounded-xl border border-border bg-transparent px-3 text-foreground text-sm transition-[border-color] hover:border-(--color-border-strong)\",\n \"focus-within:ring-2 focus-within:ring-foreground/20\",\n context.disabled && \"pointer-events-none opacity-50\",\n className,\n )}\n >\n <span className=\"min-w-0 flex-1 text-left\">{children}</span>\n <span aria-hidden className=\"shrink-0 text-muted-foreground\">\n <ChevronsUpDown className=\"size-4\" />\n </span>\n </div>\n );\n}\n\nexport interface ComboboxValueProps {\n placeholder?: ReactNode;\n children?: ReactNode | ((value: string | undefined, label: string | undefined) => ReactNode);\n className?: string;\n}\n\nexport function ComboboxValue({\n placeholder = \"Select an option\",\n children,\n className,\n}: ComboboxValueProps) {\n const context = useComboboxContext(\"ComboboxValue\");\n const label = context.labelFor(context.value);\n const content =\n typeof children === \"function\"\n ? children(context.value, label)\n : (children ?? label ?? placeholder);\n\n return (\n <span\n className={cn(\n \"block truncate\",\n context.value === undefined ? \"text-muted-foreground\" : \"text-foreground\",\n className,\n )}\n >\n {content}\n </span>\n );\n}\n\nexport interface ComboboxInputProps\n extends Omit<InputHTMLAttributes<HTMLInputElement>, \"defaultValue\" | \"value\"> {\n ref?: Ref<HTMLInputElement>;\n wrapperClassName?: string;\n}\n\nexport function ComboboxInput({\n ref,\n className,\n wrapperClassName,\n \"aria-label\": ariaLabel = \"Search options\",\n onChange,\n onClick,\n onFocus,\n onKeyDown,\n onPointerDown,\n placeholder = \"Search…\",\n ...props\n}: ComboboxInputProps) {\n const context = useComboboxContext(\"ComboboxInput\");\n const selectedLabel = context.labelFor(context.value);\n\n const handleKeyDown = (event: ReactKeyboardEvent<HTMLInputElement>) => {\n onKeyDown?.(event);\n if (event.defaultPrevented) return;\n\n if (event.key === \"ArrowDown\" || event.key === \"ArrowUp\") {\n event.preventDefault();\n // Opening is the whole action. While closed the list is still filtering\n // by the query the last session left, so a step taken here would be\n // measured against rows the next render replaces — and stamped with a\n // query it no longer has, which discards it. Open onto the selection,\n // and let the next key step through the list the user can see.\n if (!context.open) {\n context.setOpen(true);\n return;\n }\n context.moveActive(event.key === \"ArrowDown\" ? 1 : -1);\n } else if (event.key === \"Home\" && context.open) {\n event.preventDefault();\n context.moveActive(\"first\");\n } else if (event.key === \"End\" && context.open) {\n event.preventDefault();\n context.moveActive(\"last\");\n } else if (event.key === \"Enter\") {\n event.preventDefault();\n if (context.open) context.selectActive();\n else context.setOpen(true);\n } else if (event.key === \"Escape\" && context.open) {\n event.preventDefault();\n context.setOpen(false, true);\n }\n };\n\n return (\n <div className={cn(\"flex min-w-0 flex-1 items-center gap-2\", wrapperClassName)}>\n <Search aria-hidden className=\"size-4 shrink-0 text-muted-foreground\" />\n <input\n {...props}\n ref={mergeRefs(ref, context.inputRef)}\n id={context.inputId}\n role=\"combobox\"\n aria-label={ariaLabel}\n aria-autocomplete=\"list\"\n aria-expanded={context.open}\n aria-controls={context.listId}\n aria-activedescendant={context.open ? context.activeItemId : undefined}\n autoComplete=\"off\"\n disabled={context.disabled}\n value={context.open ? context.query : (selectedLabel ?? \"\")}\n placeholder={placeholder}\n onPointerDown={(event) => {\n onPointerDown?.(event);\n if (event.defaultPrevented || context.open) return;\n event.preventDefault();\n context.inputRef.current?.focus({ preventScroll: true });\n context.setOpen(true);\n }}\n onFocus={(event) => {\n context.setOpen(true);\n onFocus?.(event);\n }}\n onClick={(event) => {\n context.setOpen(true);\n onClick?.(event);\n }}\n onChange={(event) => {\n context.setOpen(true);\n context.setQuery(event.target.value);\n onChange?.(event);\n }}\n onKeyDown={handleKeyDown}\n className={cn(\n \"h-10 min-w-0 flex-1 bg-transparent text-foreground text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed\",\n className,\n )}\n />\n </div>\n );\n}\n"],"mappings":";;;;;;AAkBA,SAAgB,gBAAgB,EAAE,UAAU,aAAmC;CAC7E,MAAM,UAAU,mBAAmB,iBAAiB;CAEpD,OACE,qBAAC,OAAD;EACE,KAAK,QAAQ;EACb,IAAI,QAAQ;EACZ,cAAY,QAAQ,OAAO,SAAS;EACpC,gBAAgB,UAAU;GACxB,IAAI,QAAQ,YAAY,MAAM,WAAW,QAAQ,SAAS,SAAS;GACnE,MAAM,eAAe;GACrB,QAAQ,SAAS,SAAS,MAAM,EAAE,eAAe,KAAK,CAAC;GACvD,QAAQ,QAAQ,IAAI;EACtB;EACA,WAAW,GACT,qOACA,uDACA,QAAQ,YAAY,kCACpB,SACF;EAfF,UAAA,CAiBE,oBAAC,QAAD;GAAM,WAAU;GAA4B;EAAe,CAAA,GAC3D,oBAAC,QAAD;GAAM,eAAA;GAAY,WAAU;GAC1B,UAAA,oBAAC,gBAAD,EAAgB,WAAU,SAAU,CAAA;EAChC,CAAA,CACH;;AAET;AAQA,SAAgB,cAAc,EAC5B,cAAc,oBACd,UACA,aACqB;CACrB,MAAM,UAAU,mBAAmB,eAAe;CAClD,MAAM,QAAQ,QAAQ,SAAS,QAAQ,KAAK;CAC5C,MAAM,UACJ,OAAO,aAAa,aAChB,SAAS,QAAQ,OAAO,KAAK,IAC5B,YAAY,SAAS;CAE5B,OACE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,qBAAkB;GAClB,iBAAe,QAAQ;GACvB,iBAAe,QAAQ;GACvB,yBAAuB,QAAQ,OAAO,QAAQ,eAAe,KAAA;GAC7D,cAAa;GACb,UAAU,QAAQ;GAClB,OAAO,QAAQ,OAAO,QAAQ,QAAS,iBAAiB;GAC3C;GACb,gBAAgB,UAAU;IACxB,gBAAgB,KAAK;IACrB,IAAI,MAAM,oBAAoB,QAAQ,MAAM;IAC5C,MAAM,eAAe;IACrB,QAAQ,SAAS,SAAS,MAAM,EAAE,eAAe,KAAK,CAAC;IACvD,QAAQ,QAAQ,IAAI;GACtB;GACA,UAAU,UAAU;IAClB,QAAQ,QAAQ,IAAI;IACpB,UAAU,KAAK;GACjB;GACA,UAAU,UAAU;IAClB,QAAQ,QAAQ,IAAI;IACpB,UAAU,KAAK;GACjB;GACA,WAAW,UAAU;IACnB,QAAQ,QAAQ,IAAI;IACpB,QAAQ,SAAS,MAAM,OAAO,KAAK;IACnC,WAAW,KAAK;GAClB;GACA,WAAW;GACX,WAAW,GACT,yIACA,SACF;EACD,CAAA,CACE;;AAET"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { Combobox } from "
|
|
2
|
+
import { t as Combobox } from "../../context-BizvUNZv.js";
|
|
3
3
|
import { ComboboxContent } from "./combobox/content.js";
|
|
4
4
|
import { ComboboxEmpty, ComboboxGroup, ComboboxItem, ComboboxLabel, ComboboxList, ComboboxSeparator } from "./combobox/list.js";
|
|
5
5
|
import { ComboboxInput, ComboboxTrigger, ComboboxValue } from "./combobox/trigger.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-palette.d.ts","names":[],"sources":["../../../src/components/motion/command-palette.tsx"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"command-palette.d.ts","names":[],"sources":["../../../src/components/motion/command-palette.tsx"],"mappings":";;;KAcY;EACV;EACA;EACA;EACA;EACA;EACA,OAAO;EACP,QAAQ;EACR;;UAGe;EACf,OAAO;;EAEP;EACA;EACA;EACA;EACA,gBAAgB;;iBAwBF,iBACd,OACA,UACA,aACA,cACA,MAAM,gBACN,gBACC,sCAAmB"}
|