()
| 34 | }; |
| 35 | |
| 36 | const FloatingToolbar = () => { |
| 37 | const selectedTool = useStateStore((s: StateStore) => s.selectedTool); |
| 38 | const setSelectedTool = useStateStore((s) => s.setSelectedTool); |
| 39 | const [isLocked, setIsLocked] = useState(false); |
| 40 | |
| 41 | // History store |
| 42 | const undo = useHistoryStore((state) => state.undo); |
| 43 | const redo = useHistoryStore((state) => state.redo); |
| 44 | const canUndo = useHistoryStore((state) => state.past.length > 0); |
| 45 | const canRedo = useHistoryStore((state) => state.future.length > 0); |
| 46 | |
| 47 | // Keyboard shortcuts for undo/redo |
| 48 | const handleKeyDown = useCallback( |
| 49 | (e: KeyboardEvent) => { |
| 50 | if ((e.ctrlKey || e.metaKey) && e.key === "z") { |
| 51 | e.preventDefault(); |
| 52 | if (e.shiftKey) { |
| 53 | redo(); |
| 54 | } else { |
| 55 | undo(); |
| 56 | } |
| 57 | } |
| 58 | if ((e.ctrlKey || e.metaKey) && e.key === "y") { |
| 59 | e.preventDefault(); |
| 60 | redo(); |
| 61 | } |
| 62 | }, |
| 63 | [undo, redo] |
| 64 | ); |
| 65 | |
| 66 | useEffect(() => { |
| 67 | window.addEventListener("keydown", handleKeyDown); |
| 68 | return () => window.removeEventListener("keydown", handleKeyDown); |
| 69 | }, [handleKeyDown]); |
| 70 | |
| 71 | const tools: Tool[] = [ |
| 72 | { id: "lock", icon: Lock, label: "Lock", special: true }, |
| 73 | { id: "hand", icon: Hand, label: "Hand Tool" }, |
| 74 | { id: "pointer", icon: MousePointer, label: "Select", isDefault: true }, |
| 75 | { id: "rectangle", icon: Square, label: "Rectangle" }, |
| 76 | { id: "ellipse", icon: Circle, label: "Ellipse" }, |
| 77 | { id: "arrow", icon: ArrowRight, label: "Arrow" }, |
| 78 | { id: "line", icon: Minus, label: "Line" }, |
| 79 | { id: "pen", icon: Edit3, label: "Pen" }, |
| 80 | { id: "eraser", icon: Eraser, label: "Eraser" }, |
| 81 | { id: "text", icon: Type, label: "Text" }, |
| 82 | { id: "image", icon: Image, label: "Image" }, |
| 83 | { id: "duplicate", icon: Copy, label: "Duplicate" }, |
| 84 | { id: "connect", icon: Share2, label: "Connect" }, |
| 85 | ]; |
| 86 | |
| 87 | const handleToolClick = (toolId: selectedToolType) => { |
| 88 | if (toolId === "lock") { |
| 89 | setIsLocked(!isLocked); |
| 90 | } else { |
| 91 | setSelectedTool(toolId); |
| 92 | } |
| 93 | }; |
nothing calls this directly
no test coverage detected