'use client'; import { useEffect, useState } from 'react'; import { useCanvasStore, useLayerStore } from '@/store'; import { useHistoryStore } from '@/store/history-store'; import { CanvasWithTools } from '@/components/canvas/canvas-with-tools'; import { FileMenu } from './file-menu'; import { ImageMenu } from './image-menu'; import { ToolOptions } from './tool-options'; import { PanelDock } from './panel-dock'; import { ThemeToggle } from './theme-toggle'; import { StatusBar } from './status-bar'; import { ShortcutsHelpPanel } from './shortcuts-help-panel'; import { ToolPalette } from '@/components/tools'; import { useKeyboardShortcuts } from '@/hooks/use-keyboard-shortcuts'; import { useFileOperations } from '@/hooks/use-file-operations'; import { useDragDrop } from '@/hooks/use-drag-drop'; import { useClipboard } from '@/hooks/use-clipboard'; import { createLayerWithHistory } from '@/lib/layer-operations'; import { Plus, ZoomIn, ZoomOut, Maximize, Undo, Redo, Upload } from 'lucide-react'; import { cn } from '@/lib/utils'; export function EditorLayout() { const { zoom, zoomIn, zoomOut, zoomToFit } = useCanvasStore(); const { layers } = useLayerStore(); const { undo, redo, canUndo, canRedo } = useHistoryStore(); const { handleDataTransfer } = useFileOperations(); const [cursorPos, setCursorPos] = useState<{ x: number; y: number } | undefined>(); const [showShortcuts, setShowShortcuts] = useState(false); // Handle ? and F1 keys for shortcuts panel useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { if (e.key === '?' || e.key === 'F1') { e.preventDefault(); setShowShortcuts(true); } }; window.addEventListener('keydown', handleKeyDown); return () => window.removeEventListener('keydown', handleKeyDown); }, []); // Enable keyboard shortcuts useKeyboardShortcuts(); // Enable drag & drop const { isDragging, handleDragOver, handleDragLeave, handleDrop } = useDragDrop(handleDataTransfer); // Enable clipboard paste useClipboard(handleDataTransfer); // Initialize with a default layer (without history) useEffect(() => { if (layers.length === 0) { const { createLayer } = useLayerStore.getState(); createLayer({ name: 'Layer 1', width: 800, height: 600, // No fillColor - layer is transparent by default }); } }, []); const handleNewLayer = () => { createLayerWithHistory({ name: `Layer ${layers.length + 1}`, width: 800, height: 600, }); }; const handleZoomToFit = () => { // Approximate viewport size (accounting for panels) const viewportWidth = window.innerWidth - 344; // Subtract sidebar width (64px tools + 280px panels) const viewportHeight = window.innerHeight - 88; // Subtract toolbar height (48px header + 40px tool adjustments) zoomToFit(viewportWidth, viewportHeight); }; return (
Drop image or project file
Supports: PNG, JPG, WEBP, .paint