"use client"; import { useEffect, useRef, useState } from "react"; import { useTheme } from "next-themes"; import { Frame, GitCompare, Image, Moon, Sparkles, StickyNote, Sun, Type, type LucideIcon, } from "lucide-react"; import { useCanvasPlacement } from "@/components/canvas/canvas-placement-context"; import { Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, } from "@/components/ui/command"; import { CANVAS_NODE_TEMPLATES, type CanvasNodeTemplate, } from "@/lib/canvas-node-templates"; const NODE_ICONS: Record = { image: Image, text: Type, prompt: Sparkles, note: StickyNote, frame: Frame, compare: GitCompare, }; const NODE_SEARCH_KEYWORDS: Partial< Record > = { image: ["image", "photo", "foto"], text: ["text", "typo"], prompt: ["prompt", "ai", "generate"], note: ["note", "sticky", "notiz"], frame: ["frame", "artboard"], compare: ["compare", "before", "after"], }; export function CanvasCommandPalette() { const [open, setOpen] = useState(false); const { createNodeWithIntersection } = useCanvasPlacement(); const { setTheme } = useTheme(); const nodeCountRef = useRef(0); useEffect(() => { const onKeyDown = (e: KeyboardEvent) => { if (!e.metaKey && !e.ctrlKey) return; if (e.key.toLowerCase() !== "k") return; e.preventDefault(); setOpen((prev) => !prev); }; document.addEventListener("keydown", onKeyDown); return () => document.removeEventListener("keydown", onKeyDown); }, []); const handleAddNode = async ( type: CanvasNodeTemplate["type"], data: CanvasNodeTemplate["defaultData"], width: number, height: number, ) => { const offset = (nodeCountRef.current % 8) * 24; nodeCountRef.current += 1; await createNodeWithIntersection({ type, position: { x: 100 + offset, y: 100 + offset }, width, height, data, }); setOpen(false); }; return ( Keine Treffer. {CANVAS_NODE_TEMPLATES.map((template) => { const Icon = NODE_ICONS[template.type]; return ( void handleAddNode( template.type, template.defaultData, template.width, template.height, ) } > {template.label} ); })} { setTheme("light"); setOpen(false); }} > Hell { setTheme("dark"); setOpen(false); }} > Dunkel
⌘K · Ctrl+K Palette umschalten
); }