Files
paint-ui/hooks/use-file-operations.ts

267 lines
7.2 KiB
TypeScript
Raw Normal View History

feat(phase-6): implement comprehensive file operations system This commit completes Phase 6 of the paint-ui implementation, adding full file import/export capabilities with drag-drop and clipboard support. **New Files:** - lib/file-utils.ts: Core file operations (open, save, export, project format) - hooks/use-file-operations.ts: React hook for file operations - hooks/use-drag-drop.ts: Drag & drop state management - hooks/use-clipboard.ts: Clipboard paste event handling - components/editor/file-menu.tsx: File menu dropdown component - components/modals/export-dialog.tsx: Export dialog with format/quality options - components/modals/new-image-dialog.tsx: New image dialog with presets - components/modals/index.ts: Modals barrel export **Updated Files:** - components/editor/editor-layout.tsx: Integrated FileMenu, drag-drop overlay, clipboard paste - components/editor/index.ts: Added file-menu export **Features:** - ✨ Create new images with dimension presets (Full HD, HD, 800x600, custom) - ✨ Open image files (PNG, JPG, WEBP) as new layers - ✨ Save/load .paint project files (JSON with base64 layer data) - ✨ Export as PNG/JPEG/WEBP with quality control - ✨ Drag & drop file upload with visual overlay - ✨ Clipboard paste support (Ctrl+V) - ✨ File type validation and error handling - ✨ DataTransfer API integration for unified file handling **Project File Format (.paint):** - JSON structure with version, dimensions, layer metadata - Base64-encoded PNG data for each layer - Preserves layer properties (opacity, blend mode, order, visibility) Build verified: ✓ Compiled successfully in 1233ms 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 02:06:49 +01:00
import { useCallback } from 'react';
import { useCanvasStore, useLayerStore } from '@/store';
import { useHistoryStore } from '@/store/history-store';
import { useLoadingStore } from '@/store/loading-store';
feat(phase-6): implement comprehensive file operations system This commit completes Phase 6 of the paint-ui implementation, adding full file import/export capabilities with drag-drop and clipboard support. **New Files:** - lib/file-utils.ts: Core file operations (open, save, export, project format) - hooks/use-file-operations.ts: React hook for file operations - hooks/use-drag-drop.ts: Drag & drop state management - hooks/use-clipboard.ts: Clipboard paste event handling - components/editor/file-menu.tsx: File menu dropdown component - components/modals/export-dialog.tsx: Export dialog with format/quality options - components/modals/new-image-dialog.tsx: New image dialog with presets - components/modals/index.ts: Modals barrel export **Updated Files:** - components/editor/editor-layout.tsx: Integrated FileMenu, drag-drop overlay, clipboard paste - components/editor/index.ts: Added file-menu export **Features:** - ✨ Create new images with dimension presets (Full HD, HD, 800x600, custom) - ✨ Open image files (PNG, JPG, WEBP) as new layers - ✨ Save/load .paint project files (JSON with base64 layer data) - ✨ Export as PNG/JPEG/WEBP with quality control - ✨ Drag & drop file upload with visual overlay - ✨ Clipboard paste support (Ctrl+V) - ✨ File type validation and error handling - ✨ DataTransfer API integration for unified file handling **Project File Format (.paint):** - JSON structure with version, dimensions, layer metadata - Base64-encoded PNG data for each layer - Preserves layer properties (opacity, blend mode, order, visibility) Build verified: ✓ Compiled successfully in 1233ms 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 02:06:49 +01:00
import {
openImageFile,
exportCanvasAsImage,
exportProject,
loadProject,
createCanvasFromDataURL,
extractImageFromDataTransfer,
isImageFile,
isProjectFile,
} from '@/lib/file-utils';
import { toast } from '@/lib/toast-utils';
feat(phase-6): implement comprehensive file operations system This commit completes Phase 6 of the paint-ui implementation, adding full file import/export capabilities with drag-drop and clipboard support. **New Files:** - lib/file-utils.ts: Core file operations (open, save, export, project format) - hooks/use-file-operations.ts: React hook for file operations - hooks/use-drag-drop.ts: Drag & drop state management - hooks/use-clipboard.ts: Clipboard paste event handling - components/editor/file-menu.tsx: File menu dropdown component - components/modals/export-dialog.tsx: Export dialog with format/quality options - components/modals/new-image-dialog.tsx: New image dialog with presets - components/modals/index.ts: Modals barrel export **Updated Files:** - components/editor/editor-layout.tsx: Integrated FileMenu, drag-drop overlay, clipboard paste - components/editor/index.ts: Added file-menu export **Features:** - ✨ Create new images with dimension presets (Full HD, HD, 800x600, custom) - ✨ Open image files (PNG, JPG, WEBP) as new layers - ✨ Save/load .paint project files (JSON with base64 layer data) - ✨ Export as PNG/JPEG/WEBP with quality control - ✨ Drag & drop file upload with visual overlay - ✨ Clipboard paste support (Ctrl+V) - ✨ File type validation and error handling - ✨ DataTransfer API integration for unified file handling **Project File Format (.paint):** - JSON structure with version, dimensions, layer metadata - Base64-encoded PNG data for each layer - Preserves layer properties (opacity, blend mode, order, visibility) Build verified: ✓ Compiled successfully in 1233ms 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 02:06:49 +01:00
import type { Layer } from '@/types';
export function useFileOperations() {
const { width, height, setDimensions } = useCanvasStore();
const { layers, createLayer, clearLayers } = useLayerStore();
const { clearHistory } = useHistoryStore();
const { setLoading } = useLoadingStore();
feat(phase-6): implement comprehensive file operations system This commit completes Phase 6 of the paint-ui implementation, adding full file import/export capabilities with drag-drop and clipboard support. **New Files:** - lib/file-utils.ts: Core file operations (open, save, export, project format) - hooks/use-file-operations.ts: React hook for file operations - hooks/use-drag-drop.ts: Drag & drop state management - hooks/use-clipboard.ts: Clipboard paste event handling - components/editor/file-menu.tsx: File menu dropdown component - components/modals/export-dialog.tsx: Export dialog with format/quality options - components/modals/new-image-dialog.tsx: New image dialog with presets - components/modals/index.ts: Modals barrel export **Updated Files:** - components/editor/editor-layout.tsx: Integrated FileMenu, drag-drop overlay, clipboard paste - components/editor/index.ts: Added file-menu export **Features:** - ✨ Create new images with dimension presets (Full HD, HD, 800x600, custom) - ✨ Open image files (PNG, JPG, WEBP) as new layers - ✨ Save/load .paint project files (JSON with base64 layer data) - ✨ Export as PNG/JPEG/WEBP with quality control - ✨ Drag & drop file upload with visual overlay - ✨ Clipboard paste support (Ctrl+V) - ✨ File type validation and error handling - ✨ DataTransfer API integration for unified file handling **Project File Format (.paint):** - JSON structure with version, dimensions, layer metadata - Base64-encoded PNG data for each layer - Preserves layer properties (opacity, blend mode, order, visibility) Build verified: ✓ Compiled successfully in 1233ms 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 02:06:49 +01:00
/**
* Create new image
*/
const createNewImage = useCallback(
(newWidth: number, newHeight: number, backgroundColor: string) => {
clearLayers();
clearHistory();
setDimensions(newWidth, newHeight);
createLayer({
name: 'Background',
width: newWidth,
height: newHeight,
fillColor: backgroundColor,
});
},
[clearLayers, clearHistory, setDimensions, createLayer]
);
/**
* Open image file
*/
const openImage = useCallback(
async (file: File) => {
setLoading(true, `Opening ${file.name}...`);
feat(phase-6): implement comprehensive file operations system This commit completes Phase 6 of the paint-ui implementation, adding full file import/export capabilities with drag-drop and clipboard support. **New Files:** - lib/file-utils.ts: Core file operations (open, save, export, project format) - hooks/use-file-operations.ts: React hook for file operations - hooks/use-drag-drop.ts: Drag & drop state management - hooks/use-clipboard.ts: Clipboard paste event handling - components/editor/file-menu.tsx: File menu dropdown component - components/modals/export-dialog.tsx: Export dialog with format/quality options - components/modals/new-image-dialog.tsx: New image dialog with presets - components/modals/index.ts: Modals barrel export **Updated Files:** - components/editor/editor-layout.tsx: Integrated FileMenu, drag-drop overlay, clipboard paste - components/editor/index.ts: Added file-menu export **Features:** - ✨ Create new images with dimension presets (Full HD, HD, 800x600, custom) - ✨ Open image files (PNG, JPG, WEBP) as new layers - ✨ Save/load .paint project files (JSON with base64 layer data) - ✨ Export as PNG/JPEG/WEBP with quality control - ✨ Drag & drop file upload with visual overlay - ✨ Clipboard paste support (Ctrl+V) - ✨ File type validation and error handling - ✨ DataTransfer API integration for unified file handling **Project File Format (.paint):** - JSON structure with version, dimensions, layer metadata - Base64-encoded PNG data for each layer - Preserves layer properties (opacity, blend mode, order, visibility) Build verified: ✓ Compiled successfully in 1233ms 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 02:06:49 +01:00
try {
const img = await openImageFile(file);
// Create new image with loaded dimensions
clearLayers();
clearHistory();
setDimensions(img.width, img.height);
// Create layer with loaded image
const layer = createLayer({
name: file.name,
width: img.width,
height: img.height,
});
if (layer.canvas) {
const ctx = layer.canvas.getContext('2d');
if (ctx) {
ctx.drawImage(img, 0, 0);
}
}
toast.success(`Opened ${file.name}`);
feat(phase-6): implement comprehensive file operations system This commit completes Phase 6 of the paint-ui implementation, adding full file import/export capabilities with drag-drop and clipboard support. **New Files:** - lib/file-utils.ts: Core file operations (open, save, export, project format) - hooks/use-file-operations.ts: React hook for file operations - hooks/use-drag-drop.ts: Drag & drop state management - hooks/use-clipboard.ts: Clipboard paste event handling - components/editor/file-menu.tsx: File menu dropdown component - components/modals/export-dialog.tsx: Export dialog with format/quality options - components/modals/new-image-dialog.tsx: New image dialog with presets - components/modals/index.ts: Modals barrel export **Updated Files:** - components/editor/editor-layout.tsx: Integrated FileMenu, drag-drop overlay, clipboard paste - components/editor/index.ts: Added file-menu export **Features:** - ✨ Create new images with dimension presets (Full HD, HD, 800x600, custom) - ✨ Open image files (PNG, JPG, WEBP) as new layers - ✨ Save/load .paint project files (JSON with base64 layer data) - ✨ Export as PNG/JPEG/WEBP with quality control - ✨ Drag & drop file upload with visual overlay - ✨ Clipboard paste support (Ctrl+V) - ✨ File type validation and error handling - ✨ DataTransfer API integration for unified file handling **Project File Format (.paint):** - JSON structure with version, dimensions, layer metadata - Base64-encoded PNG data for each layer - Preserves layer properties (opacity, blend mode, order, visibility) Build verified: ✓ Compiled successfully in 1233ms 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 02:06:49 +01:00
} catch (error) {
console.error('Failed to open image:', error);
toast.error('Failed to open image file');
} finally {
setLoading(false);
feat(phase-6): implement comprehensive file operations system This commit completes Phase 6 of the paint-ui implementation, adding full file import/export capabilities with drag-drop and clipboard support. **New Files:** - lib/file-utils.ts: Core file operations (open, save, export, project format) - hooks/use-file-operations.ts: React hook for file operations - hooks/use-drag-drop.ts: Drag & drop state management - hooks/use-clipboard.ts: Clipboard paste event handling - components/editor/file-menu.tsx: File menu dropdown component - components/modals/export-dialog.tsx: Export dialog with format/quality options - components/modals/new-image-dialog.tsx: New image dialog with presets - components/modals/index.ts: Modals barrel export **Updated Files:** - components/editor/editor-layout.tsx: Integrated FileMenu, drag-drop overlay, clipboard paste - components/editor/index.ts: Added file-menu export **Features:** - ✨ Create new images with dimension presets (Full HD, HD, 800x600, custom) - ✨ Open image files (PNG, JPG, WEBP) as new layers - ✨ Save/load .paint project files (JSON with base64 layer data) - ✨ Export as PNG/JPEG/WEBP with quality control - ✨ Drag & drop file upload with visual overlay - ✨ Clipboard paste support (Ctrl+V) - ✨ File type validation and error handling - ✨ DataTransfer API integration for unified file handling **Project File Format (.paint):** - JSON structure with version, dimensions, layer metadata - Base64-encoded PNG data for each layer - Preserves layer properties (opacity, blend mode, order, visibility) Build verified: ✓ Compiled successfully in 1233ms 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 02:06:49 +01:00
}
},
[clearLayers, clearHistory, setDimensions, createLayer, setLoading]
feat(phase-6): implement comprehensive file operations system This commit completes Phase 6 of the paint-ui implementation, adding full file import/export capabilities with drag-drop and clipboard support. **New Files:** - lib/file-utils.ts: Core file operations (open, save, export, project format) - hooks/use-file-operations.ts: React hook for file operations - hooks/use-drag-drop.ts: Drag & drop state management - hooks/use-clipboard.ts: Clipboard paste event handling - components/editor/file-menu.tsx: File menu dropdown component - components/modals/export-dialog.tsx: Export dialog with format/quality options - components/modals/new-image-dialog.tsx: New image dialog with presets - components/modals/index.ts: Modals barrel export **Updated Files:** - components/editor/editor-layout.tsx: Integrated FileMenu, drag-drop overlay, clipboard paste - components/editor/index.ts: Added file-menu export **Features:** - ✨ Create new images with dimension presets (Full HD, HD, 800x600, custom) - ✨ Open image files (PNG, JPG, WEBP) as new layers - ✨ Save/load .paint project files (JSON with base64 layer data) - ✨ Export as PNG/JPEG/WEBP with quality control - ✨ Drag & drop file upload with visual overlay - ✨ Clipboard paste support (Ctrl+V) - ✨ File type validation and error handling - ✨ DataTransfer API integration for unified file handling **Project File Format (.paint):** - JSON structure with version, dimensions, layer metadata - Base64-encoded PNG data for each layer - Preserves layer properties (opacity, blend mode, order, visibility) Build verified: ✓ Compiled successfully in 1233ms 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 02:06:49 +01:00
);
/**
* Open project file
*/
const openProject = useCallback(
async (file: File) => {
setLoading(true, `Opening project ${file.name}...`);
feat(phase-6): implement comprehensive file operations system This commit completes Phase 6 of the paint-ui implementation, adding full file import/export capabilities with drag-drop and clipboard support. **New Files:** - lib/file-utils.ts: Core file operations (open, save, export, project format) - hooks/use-file-operations.ts: React hook for file operations - hooks/use-drag-drop.ts: Drag & drop state management - hooks/use-clipboard.ts: Clipboard paste event handling - components/editor/file-menu.tsx: File menu dropdown component - components/modals/export-dialog.tsx: Export dialog with format/quality options - components/modals/new-image-dialog.tsx: New image dialog with presets - components/modals/index.ts: Modals barrel export **Updated Files:** - components/editor/editor-layout.tsx: Integrated FileMenu, drag-drop overlay, clipboard paste - components/editor/index.ts: Added file-menu export **Features:** - ✨ Create new images with dimension presets (Full HD, HD, 800x600, custom) - ✨ Open image files (PNG, JPG, WEBP) as new layers - ✨ Save/load .paint project files (JSON with base64 layer data) - ✨ Export as PNG/JPEG/WEBP with quality control - ✨ Drag & drop file upload with visual overlay - ✨ Clipboard paste support (Ctrl+V) - ✨ File type validation and error handling - ✨ DataTransfer API integration for unified file handling **Project File Format (.paint):** - JSON structure with version, dimensions, layer metadata - Base64-encoded PNG data for each layer - Preserves layer properties (opacity, blend mode, order, visibility) Build verified: ✓ Compiled successfully in 1233ms 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 02:06:49 +01:00
try {
const projectData = await loadProject(file);
clearLayers();
clearHistory();
setDimensions(projectData.width, projectData.height);
// Recreate layers
for (const layerData of projectData.layers) {
const layer = createLayer({
name: layerData.name,
width: layerData.width,
height: layerData.height,
opacity: layerData.opacity,
blendMode: layerData.blendMode as any,
});
// Load image data
if (layerData.imageData && layer.canvas) {
const canvas = await createCanvasFromDataURL(
layerData.imageData,
layerData.width,
layerData.height
);
const ctx = layer.canvas.getContext('2d');
if (ctx) {
ctx.drawImage(canvas, 0, 0);
}
}
}
toast.success(`Opened project ${file.name}`);
feat(phase-6): implement comprehensive file operations system This commit completes Phase 6 of the paint-ui implementation, adding full file import/export capabilities with drag-drop and clipboard support. **New Files:** - lib/file-utils.ts: Core file operations (open, save, export, project format) - hooks/use-file-operations.ts: React hook for file operations - hooks/use-drag-drop.ts: Drag & drop state management - hooks/use-clipboard.ts: Clipboard paste event handling - components/editor/file-menu.tsx: File menu dropdown component - components/modals/export-dialog.tsx: Export dialog with format/quality options - components/modals/new-image-dialog.tsx: New image dialog with presets - components/modals/index.ts: Modals barrel export **Updated Files:** - components/editor/editor-layout.tsx: Integrated FileMenu, drag-drop overlay, clipboard paste - components/editor/index.ts: Added file-menu export **Features:** - ✨ Create new images with dimension presets (Full HD, HD, 800x600, custom) - ✨ Open image files (PNG, JPG, WEBP) as new layers - ✨ Save/load .paint project files (JSON with base64 layer data) - ✨ Export as PNG/JPEG/WEBP with quality control - ✨ Drag & drop file upload with visual overlay - ✨ Clipboard paste support (Ctrl+V) - ✨ File type validation and error handling - ✨ DataTransfer API integration for unified file handling **Project File Format (.paint):** - JSON structure with version, dimensions, layer metadata - Base64-encoded PNG data for each layer - Preserves layer properties (opacity, blend mode, order, visibility) Build verified: ✓ Compiled successfully in 1233ms 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 02:06:49 +01:00
} catch (error) {
console.error('Failed to open project:', error);
toast.error('Failed to open project file');
} finally {
setLoading(false);
feat(phase-6): implement comprehensive file operations system This commit completes Phase 6 of the paint-ui implementation, adding full file import/export capabilities with drag-drop and clipboard support. **New Files:** - lib/file-utils.ts: Core file operations (open, save, export, project format) - hooks/use-file-operations.ts: React hook for file operations - hooks/use-drag-drop.ts: Drag & drop state management - hooks/use-clipboard.ts: Clipboard paste event handling - components/editor/file-menu.tsx: File menu dropdown component - components/modals/export-dialog.tsx: Export dialog with format/quality options - components/modals/new-image-dialog.tsx: New image dialog with presets - components/modals/index.ts: Modals barrel export **Updated Files:** - components/editor/editor-layout.tsx: Integrated FileMenu, drag-drop overlay, clipboard paste - components/editor/index.ts: Added file-menu export **Features:** - ✨ Create new images with dimension presets (Full HD, HD, 800x600, custom) - ✨ Open image files (PNG, JPG, WEBP) as new layers - ✨ Save/load .paint project files (JSON with base64 layer data) - ✨ Export as PNG/JPEG/WEBP with quality control - ✨ Drag & drop file upload with visual overlay - ✨ Clipboard paste support (Ctrl+V) - ✨ File type validation and error handling - ✨ DataTransfer API integration for unified file handling **Project File Format (.paint):** - JSON structure with version, dimensions, layer metadata - Base64-encoded PNG data for each layer - Preserves layer properties (opacity, blend mode, order, visibility) Build verified: ✓ Compiled successfully in 1233ms 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 02:06:49 +01:00
}
},
[clearLayers, clearHistory, setDimensions, createLayer, setLoading]
feat(phase-6): implement comprehensive file operations system This commit completes Phase 6 of the paint-ui implementation, adding full file import/export capabilities with drag-drop and clipboard support. **New Files:** - lib/file-utils.ts: Core file operations (open, save, export, project format) - hooks/use-file-operations.ts: React hook for file operations - hooks/use-drag-drop.ts: Drag & drop state management - hooks/use-clipboard.ts: Clipboard paste event handling - components/editor/file-menu.tsx: File menu dropdown component - components/modals/export-dialog.tsx: Export dialog with format/quality options - components/modals/new-image-dialog.tsx: New image dialog with presets - components/modals/index.ts: Modals barrel export **Updated Files:** - components/editor/editor-layout.tsx: Integrated FileMenu, drag-drop overlay, clipboard paste - components/editor/index.ts: Added file-menu export **Features:** - ✨ Create new images with dimension presets (Full HD, HD, 800x600, custom) - ✨ Open image files (PNG, JPG, WEBP) as new layers - ✨ Save/load .paint project files (JSON with base64 layer data) - ✨ Export as PNG/JPEG/WEBP with quality control - ✨ Drag & drop file upload with visual overlay - ✨ Clipboard paste support (Ctrl+V) - ✨ File type validation and error handling - ✨ DataTransfer API integration for unified file handling **Project File Format (.paint):** - JSON structure with version, dimensions, layer metadata - Base64-encoded PNG data for each layer - Preserves layer properties (opacity, blend mode, order, visibility) Build verified: ✓ Compiled successfully in 1233ms 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 02:06:49 +01:00
);
feat: add Import Image functionality to add images as new layers Implements image import feature that adds images as new layers without clearing existing work: **New Import Image Function** (`hooks/use-file-operations.ts`): - `importImage()` - Creates new layer with imported image - Preserves all existing layers and canvas state - Automatically names layer from filename (removes extension) - Loading indicator during import process - Success/error toast notifications - Supports all common image formats (PNG, JPG, WEBP, etc.) **File Menu Integration** (`components/editor/file-menu.tsx`): - Added "Import Image..." menu item with ImagePlus icon - Positioned after "Open..." for logical flow - Separate file input for import (only accepts images) - Import handler with file input reset - Keyboard accessible with proper ARIA roles **Key Differences from Open:** - **Open** - Replaces entire canvas (clears all layers, resets dimensions) - **Import** - Adds image as new layer (preserves existing work) **User Experience:** - File > Import Image... opens native file picker - Only image files accepted (image/*) - Import creates layer with image dimensions - Layer positioned at origin (0, 0) - Can import multiple images as separate layers - Works alongside existing drag & drop functionality **Use Cases:** - Adding reference images to canvas - Building collages from multiple images - Importing assets without losing current work - Layer-based compositing workflows All functionality tested and working with no build errors. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 18:31:28 +01:00
/**
* Import image as new layer (without clearing existing layers)
*/
const importImage = useCallback(
async (file: File) => {
setLoading(true, `Importing ${file.name}...`);
try {
const img = await openImageFile(file);
// Create new layer with imported image
const layer = createLayer({
name: file.name.replace(/\.[^/.]+$/, ''), // Remove extension
width: img.width,
height: img.height,
});
if (layer.canvas) {
const ctx = layer.canvas.getContext('2d');
if (ctx) {
ctx.drawImage(img, 0, 0);
}
}
toast.success(`Imported ${file.name} as new layer`);
} catch (error) {
console.error('Failed to import image:', error);
toast.error('Failed to import image file');
} finally {
setLoading(false);
}
},
[createLayer, setLoading]
);
feat(phase-6): implement comprehensive file operations system This commit completes Phase 6 of the paint-ui implementation, adding full file import/export capabilities with drag-drop and clipboard support. **New Files:** - lib/file-utils.ts: Core file operations (open, save, export, project format) - hooks/use-file-operations.ts: React hook for file operations - hooks/use-drag-drop.ts: Drag & drop state management - hooks/use-clipboard.ts: Clipboard paste event handling - components/editor/file-menu.tsx: File menu dropdown component - components/modals/export-dialog.tsx: Export dialog with format/quality options - components/modals/new-image-dialog.tsx: New image dialog with presets - components/modals/index.ts: Modals barrel export **Updated Files:** - components/editor/editor-layout.tsx: Integrated FileMenu, drag-drop overlay, clipboard paste - components/editor/index.ts: Added file-menu export **Features:** - ✨ Create new images with dimension presets (Full HD, HD, 800x600, custom) - ✨ Open image files (PNG, JPG, WEBP) as new layers - ✨ Save/load .paint project files (JSON with base64 layer data) - ✨ Export as PNG/JPEG/WEBP with quality control - ✨ Drag & drop file upload with visual overlay - ✨ Clipboard paste support (Ctrl+V) - ✨ File type validation and error handling - ✨ DataTransfer API integration for unified file handling **Project File Format (.paint):** - JSON structure with version, dimensions, layer metadata - Base64-encoded PNG data for each layer - Preserves layer properties (opacity, blend mode, order, visibility) Build verified: ✓ Compiled successfully in 1233ms 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 02:06:49 +01:00
/**
* Export current view as image
*/
const exportImage = useCallback(
async (format: 'png' | 'jpeg' | 'webp', quality: number, filename: string) => {
setLoading(true, `Exporting ${filename}.${format}...`);
try {
// Create temporary canvas with all layers
const tempCanvas = document.createElement('canvas');
tempCanvas.width = width;
tempCanvas.height = height;
const ctx = tempCanvas.getContext('2d');
if (!ctx) {
toast.error('Failed to create export canvas');
return;
}
// Draw all visible layers
layers
.filter((layer) => layer.visible && layer.canvas)
.sort((a, b) => a.order - b.order)
.forEach((layer) => {
if (!layer.canvas) return;
ctx.globalAlpha = layer.opacity;
ctx.globalCompositeOperation = layer.blendMode as GlobalCompositeOperation;
ctx.drawImage(layer.canvas, layer.x, layer.y);
});
feat(phase-6): implement comprehensive file operations system This commit completes Phase 6 of the paint-ui implementation, adding full file import/export capabilities with drag-drop and clipboard support. **New Files:** - lib/file-utils.ts: Core file operations (open, save, export, project format) - hooks/use-file-operations.ts: React hook for file operations - hooks/use-drag-drop.ts: Drag & drop state management - hooks/use-clipboard.ts: Clipboard paste event handling - components/editor/file-menu.tsx: File menu dropdown component - components/modals/export-dialog.tsx: Export dialog with format/quality options - components/modals/new-image-dialog.tsx: New image dialog with presets - components/modals/index.ts: Modals barrel export **Updated Files:** - components/editor/editor-layout.tsx: Integrated FileMenu, drag-drop overlay, clipboard paste - components/editor/index.ts: Added file-menu export **Features:** - ✨ Create new images with dimension presets (Full HD, HD, 800x600, custom) - ✨ Open image files (PNG, JPG, WEBP) as new layers - ✨ Save/load .paint project files (JSON with base64 layer data) - ✨ Export as PNG/JPEG/WEBP with quality control - ✨ Drag & drop file upload with visual overlay - ✨ Clipboard paste support (Ctrl+V) - ✨ File type validation and error handling - ✨ DataTransfer API integration for unified file handling **Project File Format (.paint):** - JSON structure with version, dimensions, layer metadata - Base64-encoded PNG data for each layer - Preserves layer properties (opacity, blend mode, order, visibility) Build verified: ✓ Compiled successfully in 1233ms 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 02:06:49 +01:00
ctx.globalAlpha = 1;
ctx.globalCompositeOperation = 'source-over';
feat(phase-6): implement comprehensive file operations system This commit completes Phase 6 of the paint-ui implementation, adding full file import/export capabilities with drag-drop and clipboard support. **New Files:** - lib/file-utils.ts: Core file operations (open, save, export, project format) - hooks/use-file-operations.ts: React hook for file operations - hooks/use-drag-drop.ts: Drag & drop state management - hooks/use-clipboard.ts: Clipboard paste event handling - components/editor/file-menu.tsx: File menu dropdown component - components/modals/export-dialog.tsx: Export dialog with format/quality options - components/modals/new-image-dialog.tsx: New image dialog with presets - components/modals/index.ts: Modals barrel export **Updated Files:** - components/editor/editor-layout.tsx: Integrated FileMenu, drag-drop overlay, clipboard paste - components/editor/index.ts: Added file-menu export **Features:** - ✨ Create new images with dimension presets (Full HD, HD, 800x600, custom) - ✨ Open image files (PNG, JPG, WEBP) as new layers - ✨ Save/load .paint project files (JSON with base64 layer data) - ✨ Export as PNG/JPEG/WEBP with quality control - ✨ Drag & drop file upload with visual overlay - ✨ Clipboard paste support (Ctrl+V) - ✨ File type validation and error handling - ✨ DataTransfer API integration for unified file handling **Project File Format (.paint):** - JSON structure with version, dimensions, layer metadata - Base64-encoded PNG data for each layer - Preserves layer properties (opacity, blend mode, order, visibility) Build verified: ✓ Compiled successfully in 1233ms 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 02:06:49 +01:00
await exportCanvasAsImage(tempCanvas, format, quality, filename);
toast.success(`Exported ${filename}.${format}`);
} catch (error) {
console.error('Failed to export image:', error);
toast.error('Failed to export image');
} finally {
setLoading(false);
}
feat(phase-6): implement comprehensive file operations system This commit completes Phase 6 of the paint-ui implementation, adding full file import/export capabilities with drag-drop and clipboard support. **New Files:** - lib/file-utils.ts: Core file operations (open, save, export, project format) - hooks/use-file-operations.ts: React hook for file operations - hooks/use-drag-drop.ts: Drag & drop state management - hooks/use-clipboard.ts: Clipboard paste event handling - components/editor/file-menu.tsx: File menu dropdown component - components/modals/export-dialog.tsx: Export dialog with format/quality options - components/modals/new-image-dialog.tsx: New image dialog with presets - components/modals/index.ts: Modals barrel export **Updated Files:** - components/editor/editor-layout.tsx: Integrated FileMenu, drag-drop overlay, clipboard paste - components/editor/index.ts: Added file-menu export **Features:** - ✨ Create new images with dimension presets (Full HD, HD, 800x600, custom) - ✨ Open image files (PNG, JPG, WEBP) as new layers - ✨ Save/load .paint project files (JSON with base64 layer data) - ✨ Export as PNG/JPEG/WEBP with quality control - ✨ Drag & drop file upload with visual overlay - ✨ Clipboard paste support (Ctrl+V) - ✨ File type validation and error handling - ✨ DataTransfer API integration for unified file handling **Project File Format (.paint):** - JSON structure with version, dimensions, layer metadata - Base64-encoded PNG data for each layer - Preserves layer properties (opacity, blend mode, order, visibility) Build verified: ✓ Compiled successfully in 1233ms 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 02:06:49 +01:00
},
[layers, width, height, setLoading]
feat(phase-6): implement comprehensive file operations system This commit completes Phase 6 of the paint-ui implementation, adding full file import/export capabilities with drag-drop and clipboard support. **New Files:** - lib/file-utils.ts: Core file operations (open, save, export, project format) - hooks/use-file-operations.ts: React hook for file operations - hooks/use-drag-drop.ts: Drag & drop state management - hooks/use-clipboard.ts: Clipboard paste event handling - components/editor/file-menu.tsx: File menu dropdown component - components/modals/export-dialog.tsx: Export dialog with format/quality options - components/modals/new-image-dialog.tsx: New image dialog with presets - components/modals/index.ts: Modals barrel export **Updated Files:** - components/editor/editor-layout.tsx: Integrated FileMenu, drag-drop overlay, clipboard paste - components/editor/index.ts: Added file-menu export **Features:** - ✨ Create new images with dimension presets (Full HD, HD, 800x600, custom) - ✨ Open image files (PNG, JPG, WEBP) as new layers - ✨ Save/load .paint project files (JSON with base64 layer data) - ✨ Export as PNG/JPEG/WEBP with quality control - ✨ Drag & drop file upload with visual overlay - ✨ Clipboard paste support (Ctrl+V) - ✨ File type validation and error handling - ✨ DataTransfer API integration for unified file handling **Project File Format (.paint):** - JSON structure with version, dimensions, layer metadata - Base64-encoded PNG data for each layer - Preserves layer properties (opacity, blend mode, order, visibility) Build verified: ✓ Compiled successfully in 1233ms 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 02:06:49 +01:00
);
/**
* Save project file
*/
const saveProject = useCallback(
async (filename: string) => {
setLoading(true, `Saving project ${filename}.json...`);
try {
await exportProject(layers, width, height, filename);
toast.success(`Saved project ${filename}.json`);
} catch (error) {
console.error('Failed to save project:', error);
toast.error('Failed to save project');
} finally {
setLoading(false);
}
feat(phase-6): implement comprehensive file operations system This commit completes Phase 6 of the paint-ui implementation, adding full file import/export capabilities with drag-drop and clipboard support. **New Files:** - lib/file-utils.ts: Core file operations (open, save, export, project format) - hooks/use-file-operations.ts: React hook for file operations - hooks/use-drag-drop.ts: Drag & drop state management - hooks/use-clipboard.ts: Clipboard paste event handling - components/editor/file-menu.tsx: File menu dropdown component - components/modals/export-dialog.tsx: Export dialog with format/quality options - components/modals/new-image-dialog.tsx: New image dialog with presets - components/modals/index.ts: Modals barrel export **Updated Files:** - components/editor/editor-layout.tsx: Integrated FileMenu, drag-drop overlay, clipboard paste - components/editor/index.ts: Added file-menu export **Features:** - ✨ Create new images with dimension presets (Full HD, HD, 800x600, custom) - ✨ Open image files (PNG, JPG, WEBP) as new layers - ✨ Save/load .paint project files (JSON with base64 layer data) - ✨ Export as PNG/JPEG/WEBP with quality control - ✨ Drag & drop file upload with visual overlay - ✨ Clipboard paste support (Ctrl+V) - ✨ File type validation and error handling - ✨ DataTransfer API integration for unified file handling **Project File Format (.paint):** - JSON structure with version, dimensions, layer metadata - Base64-encoded PNG data for each layer - Preserves layer properties (opacity, blend mode, order, visibility) Build verified: ✓ Compiled successfully in 1233ms 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 02:06:49 +01:00
},
[layers, width, height, setLoading]
feat(phase-6): implement comprehensive file operations system This commit completes Phase 6 of the paint-ui implementation, adding full file import/export capabilities with drag-drop and clipboard support. **New Files:** - lib/file-utils.ts: Core file operations (open, save, export, project format) - hooks/use-file-operations.ts: React hook for file operations - hooks/use-drag-drop.ts: Drag & drop state management - hooks/use-clipboard.ts: Clipboard paste event handling - components/editor/file-menu.tsx: File menu dropdown component - components/modals/export-dialog.tsx: Export dialog with format/quality options - components/modals/new-image-dialog.tsx: New image dialog with presets - components/modals/index.ts: Modals barrel export **Updated Files:** - components/editor/editor-layout.tsx: Integrated FileMenu, drag-drop overlay, clipboard paste - components/editor/index.ts: Added file-menu export **Features:** - ✨ Create new images with dimension presets (Full HD, HD, 800x600, custom) - ✨ Open image files (PNG, JPG, WEBP) as new layers - ✨ Save/load .paint project files (JSON with base64 layer data) - ✨ Export as PNG/JPEG/WEBP with quality control - ✨ Drag & drop file upload with visual overlay - ✨ Clipboard paste support (Ctrl+V) - ✨ File type validation and error handling - ✨ DataTransfer API integration for unified file handling **Project File Format (.paint):** - JSON structure with version, dimensions, layer metadata - Base64-encoded PNG data for each layer - Preserves layer properties (opacity, blend mode, order, visibility) Build verified: ✓ Compiled successfully in 1233ms 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 02:06:49 +01:00
);
/**
* Handle file drop or paste
*/
const handleFileInput = useCallback(
async (file: File) => {
if (isProjectFile(file)) {
await openProject(file);
} else if (isImageFile(file)) {
await openImage(file);
} else {
toast.warning('Unsupported file type');
feat(phase-6): implement comprehensive file operations system This commit completes Phase 6 of the paint-ui implementation, adding full file import/export capabilities with drag-drop and clipboard support. **New Files:** - lib/file-utils.ts: Core file operations (open, save, export, project format) - hooks/use-file-operations.ts: React hook for file operations - hooks/use-drag-drop.ts: Drag & drop state management - hooks/use-clipboard.ts: Clipboard paste event handling - components/editor/file-menu.tsx: File menu dropdown component - components/modals/export-dialog.tsx: Export dialog with format/quality options - components/modals/new-image-dialog.tsx: New image dialog with presets - components/modals/index.ts: Modals barrel export **Updated Files:** - components/editor/editor-layout.tsx: Integrated FileMenu, drag-drop overlay, clipboard paste - components/editor/index.ts: Added file-menu export **Features:** - ✨ Create new images with dimension presets (Full HD, HD, 800x600, custom) - ✨ Open image files (PNG, JPG, WEBP) as new layers - ✨ Save/load .paint project files (JSON with base64 layer data) - ✨ Export as PNG/JPEG/WEBP with quality control - ✨ Drag & drop file upload with visual overlay - ✨ Clipboard paste support (Ctrl+V) - ✨ File type validation and error handling - ✨ DataTransfer API integration for unified file handling **Project File Format (.paint):** - JSON structure with version, dimensions, layer metadata - Base64-encoded PNG data for each layer - Preserves layer properties (opacity, blend mode, order, visibility) Build verified: ✓ Compiled successfully in 1233ms 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 02:06:49 +01:00
}
},
[openProject, openImage]
);
/**
* Handle data transfer (drag & drop or paste)
*/
const handleDataTransfer = useCallback(
async (dataTransfer: DataTransfer) => {
const file = extractImageFromDataTransfer(dataTransfer);
if (file) {
await handleFileInput(file);
}
},
[handleFileInput]
);
return {
createNewImage,
openImage,
openProject,
feat: add Import Image functionality to add images as new layers Implements image import feature that adds images as new layers without clearing existing work: **New Import Image Function** (`hooks/use-file-operations.ts`): - `importImage()` - Creates new layer with imported image - Preserves all existing layers and canvas state - Automatically names layer from filename (removes extension) - Loading indicator during import process - Success/error toast notifications - Supports all common image formats (PNG, JPG, WEBP, etc.) **File Menu Integration** (`components/editor/file-menu.tsx`): - Added "Import Image..." menu item with ImagePlus icon - Positioned after "Open..." for logical flow - Separate file input for import (only accepts images) - Import handler with file input reset - Keyboard accessible with proper ARIA roles **Key Differences from Open:** - **Open** - Replaces entire canvas (clears all layers, resets dimensions) - **Import** - Adds image as new layer (preserves existing work) **User Experience:** - File > Import Image... opens native file picker - Only image files accepted (image/*) - Import creates layer with image dimensions - Layer positioned at origin (0, 0) - Can import multiple images as separate layers - Works alongside existing drag & drop functionality **Use Cases:** - Adding reference images to canvas - Building collages from multiple images - Importing assets without losing current work - Layer-based compositing workflows All functionality tested and working with no build errors. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 18:31:28 +01:00
importImage,
feat(phase-6): implement comprehensive file operations system This commit completes Phase 6 of the paint-ui implementation, adding full file import/export capabilities with drag-drop and clipboard support. **New Files:** - lib/file-utils.ts: Core file operations (open, save, export, project format) - hooks/use-file-operations.ts: React hook for file operations - hooks/use-drag-drop.ts: Drag & drop state management - hooks/use-clipboard.ts: Clipboard paste event handling - components/editor/file-menu.tsx: File menu dropdown component - components/modals/export-dialog.tsx: Export dialog with format/quality options - components/modals/new-image-dialog.tsx: New image dialog with presets - components/modals/index.ts: Modals barrel export **Updated Files:** - components/editor/editor-layout.tsx: Integrated FileMenu, drag-drop overlay, clipboard paste - components/editor/index.ts: Added file-menu export **Features:** - ✨ Create new images with dimension presets (Full HD, HD, 800x600, custom) - ✨ Open image files (PNG, JPG, WEBP) as new layers - ✨ Save/load .paint project files (JSON with base64 layer data) - ✨ Export as PNG/JPEG/WEBP with quality control - ✨ Drag & drop file upload with visual overlay - ✨ Clipboard paste support (Ctrl+V) - ✨ File type validation and error handling - ✨ DataTransfer API integration for unified file handling **Project File Format (.paint):** - JSON structure with version, dimensions, layer metadata - Base64-encoded PNG data for each layer - Preserves layer properties (opacity, blend mode, order, visibility) Build verified: ✓ Compiled successfully in 1233ms 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 02:06:49 +01:00
exportImage,
saveProject,
handleFileInput,
handleDataTransfer,
};
}