diff --git a/components/canvas/canvas-with-tools.tsx b/components/canvas/canvas-with-tools.tsx index c7fc75e..6dc909d 100644 --- a/components/canvas/canvas-with-tools.tsx +++ b/components/canvas/canvas-with-tools.tsx @@ -20,6 +20,7 @@ import { MoveTool, FreeTransformTool, ShapeTool, + TextTool, type BaseTool, } from '@/tools'; import type { PointerState } from '@/types'; @@ -40,6 +41,7 @@ const tools: Record = { move: new MoveTool(), transform: new FreeTransformTool(), shape: new ShapeTool(), + text: new TextTool(), }; export function CanvasWithTools() { diff --git a/components/editor/editor-layout.tsx b/components/editor/editor-layout.tsx index 8cf5803..565bebc 100644 --- a/components/editor/editor-layout.tsx +++ b/components/editor/editor-layout.tsx @@ -9,6 +9,7 @@ import { ToolOptions } from './tool-options'; import { PanelDock } from './panel-dock'; import { ThemeToggle } from './theme-toggle'; import { ToolPalette } from '@/components/tools'; +import { TextDialog } from '@/components/modals/text-dialog'; import { useKeyboardShortcuts } from '@/hooks/use-keyboard-shortcuts'; import { useFileOperations } from '@/hooks/use-file-operations'; import { useDragDrop } from '@/hooks/use-drag-drop'; @@ -190,6 +191,9 @@ export function EditorLayout() { {/* Right: Panel Dock */} + + {/* Text Dialog */} + ); } diff --git a/components/modals/text-dialog.tsx b/components/modals/text-dialog.tsx new file mode 100644 index 0000000..5c1d3c5 --- /dev/null +++ b/components/modals/text-dialog.tsx @@ -0,0 +1,288 @@ +'use client'; + +import { useState, useEffect } from 'react'; +import { X, Type } from 'lucide-react'; +import { useTextStore } from '@/store/text-store'; +import { TextTool } from '@/tools/text-tool'; +import { WEB_SAFE_FONTS, GOOGLE_FONTS, loadGoogleFont } from '@/lib/text-utils'; +import type { FontStyle, FontWeight, TextAlign } from '@/types/text'; + +export function TextDialog() { + const { + settings, + isDialogOpen, + clickPosition, + setText, + setFontFamily, + setFontSize, + setFontStyle, + setFontWeight, + setColor, + setAlign, + setLineHeight, + setLetterSpacing, + closeDialog, + } = useTextStore(); + + const [text, setTextLocal] = useState(settings.text); + const [isLoadingFont, setIsLoadingFont] = useState(false); + + useEffect(() => { + if (isDialogOpen) { + setTextLocal(settings.text); + } + }, [isDialogOpen, settings.text]); + + if (!isDialogOpen || !clickPosition) return null; + + const handleInsert = async () => { + if (!text.trim()) { + closeDialog(); + return; + } + + // Update text in store + setText(text); + + // Load Google Font if needed + if (GOOGLE_FONTS.includes(settings.fontFamily as any)) { + try { + setIsLoadingFont(true); + await loadGoogleFont(settings.fontFamily); + } catch (error) { + console.error('Failed to load font:', error); + } finally { + setIsLoadingFont(false); + } + } + + // Render text on canvas + TextTool.renderTextOnCanvas(clickPosition.x, clickPosition.y); + + // Close dialog + closeDialog(); + setTextLocal(''); + }; + + const handleCancel = () => { + closeDialog(); + setTextLocal(''); + }; + + const allFonts = [...WEB_SAFE_FONTS, ...GOOGLE_FONTS]; + + return ( +
+
e.stopPropagation()} + > + {/* Header */} +
+
+ +

Add Text

+
+ +
+ + {/* Content */} +
+ {/* Text Input */} +
+ +