Skip to content

Create professional demos and 3D mockups in seconds, directly in your browser

feat: implement inline text editing and text tool activation in the editor

CristianOlivera193d9c37ed1e4
diff --git a/app/[locale]/(editor)/editor/page.tsx b/app/[locale]/(editor)/editor/page.tsx
index cb2927e..a13d1bc 100644
--- a/app/[locale]/(editor)/editor/page.tsx
+++ b/app/[locale]/(editor)/editor/page.tsx
@@ -113,6 +113,7 @@ export default function Editor() {
const [videoMaskConfig, setVideoMaskConfig] = useState<ImageMaskConfig>(DEFAULT_MASK_CONFIG);
const [activeTool, setActiveTool] = useState<Tool>("screenshot");
+ const [elementsTextTabTrigger, setElementsTextTabTrigger] = useState(0);
const [backgroundTab, setBackgroundTab] = useState<BackgroundTab>("wallpaper");
const [selectedWallpaper, setSelectedWallpaper] = useState(0);
const [backgroundBlur, setBackgroundBlur] = useState(0);
@@ -978,6 +979,9 @@ export default function Editor() {
setMockupConfig(prev => ({ ...prev, cornerRadius: value }));
}, []);
+ // Text tool (Figma-style T key) — activates crosshair + canvas click to place text
+ const [textToolActive, setTextToolActive] = useState(false);
+
// Canvas elements handlers
const addCanvasElement = useCallback((element: CanvasElement) => {
setCanvasElements(prev => [...prev, element]);
@@ -2559,6 +2563,15 @@ export default function Editor() {
if (e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement) {
return;
}
+ // Also skip if inside a contenteditable element
+ if ((e.target as HTMLElement)?.isContentEditable) return;
+
+ // T key — Figma-style text tool: activate crosshair cursor to place text on canvas
+ if (e.key === 't' && !e.ctrlKey && !e.metaKey && !e.shiftKey && !e.altKey) {
+ e.preventDefault();
+ setTextToolActive(true);
+ return;
+ }
if ((e.ctrlKey || e.metaKey) && e.key === 'c' && selectedElementId) {
e.preventDefault();
@@ -2601,6 +2614,10 @@ export default function Editor() {
if (e.key === "Escape") {
e.preventDefault();
+ if (textToolActive) {
+ setTextToolActive(false);
+ return;
+ }
if (selectedElementId) {
setSelectedElementId(null);
} else if (selectedVideoClipId) {
@@ -2616,7 +2633,7 @@ export default function Editor() {
document.addEventListener("keydown", handleKeyDown);
return () => document.removeEventListener("keydown", handleKeyDown);
- }, [selectedElementId, selectedZoomFragmentId, selectedAudioTrackId, selectedVideoClipId, deleteCanvasElement, handleDeleteZoomFragment, handleDeleteAudioTrack, handleDeleteVideoClip, copySelectedElement, pasteElement, isPhotoMode, copiedElement]);
+ }, [selectedElementId, selectedZoomFragmentId, selectedAudioTrackId, selectedVideoClipId, deleteCanvasElement, handleDeleteZoomFragment, handleDeleteAudioTrack, handleDeleteVideoClip, copySelectedElement, pasteElement, isPhotoMode, copiedElement, textToolActive]);
useEffect(() => {
const checkMobile = () => {
@@ -2764,6 +2781,7 @@ export default function Editor() {
onAddImageToCanvas={handleAddImageToCanvas}
onDeleteImageProject={handleDeleteImageProject}
onUploadImageToHistory={handleUploadImageToHistory}
+ elementsTextTabTrigger={elementsTextTabTrigger}
/>
</Suspense>
</motion.div>
@@ -2856,6 +2874,9 @@ export default function Editor() {
onElementUpdate={updateCanvasElement}
onElementSelect={selectCanvasElement}
onElementDelete={deleteCanvasElement}
+ onAddElement={addCanvasElement}
+ textToolActive={textToolActive}
+ onTextToolDeactivate={() => setTextToolActive(false)}
cameraUrl={effectiveCameraUrl}
cameraConfig={cameraConfig}
onCameraConfigChange={handleCameraConfigChange}
diff --git a/app/components/ui/CarouselDemos.tsx b/app/components/ui/CarouselDemos.tsx
index bc56fb3..db6c00a 100644
--- a/app/components/ui/CarouselDemos.tsx
+++ b/app/components/ui/CarouselDemos.tsx
@@ -91,7 +91,19 @@ export function CarouselDemos() {
}
`}</style>
- <div className="scene-3d">
+ <div className="scene-3d relative">
+ <div className="absolute bottom-20 sm:-bottom-4 sm:left-120 z-0 pointer-events-none opacity-50">
+ <img
+ src="/images/carousel/decorators/sparkle.png"
+ className="size-20 md:size-48 animate-pulse"
+ />
+ </div>
+ <div className="absolute bottom-10 sm:bottom-0 right-1/4 z-10 pointer-events-none">
+ <img
+ src="/images/carousel/decorators/sparkle-move.svg"
+ className="size-8 md:size-10"
+ />
+ </div>
<div className="a3d-container row-videos" style={{ "--n": videos.length } as React.CSSProperties}>
{videos.map((vid, index) => (
<video
diff --git a/app/components/ui/EditorPreview.tsx b/app/components/ui/EditorPreview.tsx
index 6cd42c8..21f8a1f 100644
--- a/app/components/ui/EditorPreview.tsx
+++ b/app/components/ui/EditorPreview.tsx
@@ -24,10 +24,15 @@ export default function EditorPreview() {
}, []);
return (
<div className="relative max-w-6xl mx-auto mt-30 sm:mt-0 isolate">
- <div className="absolute top-0 left-1/2 -translate-x-1/2 w-140 h-80 rounded-full bg-[#0095ED]/40 blur-[120px] pointer-events-none -z-10" />
-
- <div className="absolute top-20 left-1/3 w-60 h-60 rounded-full bg-blue-600/20 blur-[80px] pointer-events-none -z-10" />
-
+ <div className="hidden sm:block absolute top-0 left-1/2 -translate-x-1/2 w-140 h-80 rounded-full bg-[#0095ED]/40 blur-[120px] pointer-events-none -z-10" />
+ <div className="hidden sm:block absolute top-20 left-1/3 w-60 h-60 rounded-full bg-blue-600/20 blur-[80px] pointer-events-none -z-10" />
+ <div className="absolute top-0 right-0 md:-right-10 z-30 pointer-events-none">
+ <img
+ src="/images/carousel/decorators/sparkle-blur.png"
+ alt="decoración"
+ className="size-40 md:size-50 object-contain opacity-80 animate-pulse"
+ />
+ </div>
<h2 className="relative text-4xl md:text-6xl text-center font-bold tracking-tighter text-white mb-10 leading-tight drop-shadow-[0_0_30px_rgba(183,203,248,0.3)] z-20">
{t('title')} <br />
<span className="bg-linear-to-r from-[#003780] to-white bg-clip-text text-transparent">
@@ -39,9 +44,9 @@ export default function EditorPreview() {
<div className="absolute bottom-0 left-1/2 -translate-x-1/2 w-140 h-80 rounded-full bg-[#0095ED80] blur-[120px] pointer-events-none -z-10" />
<div className="hero-3d-wrapper relative w-full">
- <div className="absolute -left-20 top-1/2 -translate-y-1/2 w-96 h-96 rounded-full bg-[#06b6d433] blur-[110px] pointer-events-none -z-10" />
+ <div className="hidden sm:block absolute -left-20 top-1/2 -translate-y-1/2 w-96 h-96 rounded-full bg-[#06b6d433] blur-[110px] pointer-events-none -z-10" />
- <div className="absolute -right-20 top-1/2 -translate-y-1/2 w-96 h-96 rounded-full bg-[#6366f126] blur-[110px] pointer-events-none -z-10" />
+ <div className="hidden sm:block absolute -right-20 top-1/2 -translate-y-1/2 w-96 h-96 rounded-full bg-[#6366f126] blur-[110px] pointer-events-none -z-10" />
<div ref={atroposRef} className="atropos w-full rounded-2xl">
<div className="atropos-scale">
@@ -67,16 +72,37 @@ export default function EditorPreview() {
</div>
</div>
</div>
+ <div
+ className="absolute bottom-10 right-4 md:right-4 z-30 pointer-events-none"
+ data-atropos-offset="8"
+ >
+ <img
+ src="/images/carousel/decorators/sparkle-move.svg"
+ alt="decor"
+ className="size-6 md:size-8"
+ />
+ </div>
+
+ <div
+ className="absolute top-48 -left-4 md:-left-16 z-30 pointer-events-none opacity-80"
+ data-atropos-offset="6"
+ >
+ <img
+ src="/images/carousel/decorators/sparkle-static.svg"
+ alt="decor-left"
+ className="size-4 md:size-6"
+ />
+ </div>
</div>
</div>
- <div className="absolute top-10 left-0 w-90 h-60 rounded-full bg-[#29b1ff33] blur-[100px] pointer-events-none -z-10" />
- <div className="absolute bottom-10 left-0 w-90 h-60 rounded-full bg-[#0095ED33] blur-[100px] pointer-events-none -z-10" />
- <div className="absolute bottom-10 right-0 w-100 h-60 rounded-full bg-[#ffffff33] blur-[100px] pointer-events-none -z-10" />
+ <div className="hidden sm:block absolute top-10 left-0 w-90 h-60 rounded-full bg-[#29b1ff33] blur-[100px] pointer-events-none -z-10" />
+ <div className="hidden sm:block absolute bottom-10 left-0 w-90 h-60 rounded-full bg-[#0095ED33] blur-[100px] pointer-events-none -z-10" />
+ <div className="hidden sm:block absolute bottom-10 right-0 w-100 h-60 rounded-full bg-[#ffffff33] blur-[100px] pointer-events-none -z-10" />
</div>
- <div className="absolute -bottom-10 left-0 w-80 h-60 rounded-full bg-[#0095ED33] blur-[100px] pointer-events-none -z-10" />
- <div className="absolute bottom-0 left-1/2 -translate-x-1/2 w-140 h-80 rounded-full bg-[#0095ED] blur-[120px] pointer-events-none -z-10" />
- <div className="absolute -bottom-10 right-0 w-80 h-60 rounded-full bg-[#01a2ff33] blur-[100px] pointer-events-none -z-10" />
+ <div className="hidden sm:block absolute -bottom-10 left-0 w-80 h-60 rounded-full bg-[#0095ED33] blur-[100px] pointer-events-none -z-10" />
+ <div className="hidden sm:block absolute bottom-0 left-1/2 -translate-x-1/2 w-140 h-80 rounded-full bg-[#0095ED] blur-[120px] pointer-events-none -z-10" />
+ <div className="hidden sm:block absolute -bottom-10 right-0 w-80 h-60 rounded-full bg-[#01a2ff33] blur-[100px] pointer-events-none -z-10" />
</div>
);
}
\ No newline at end of file
diff --git a/app/components/ui/editor/CanvasElementsLayer.tsx b/app/components/ui/editor/CanvasElementsLayer.tsx
index 80ff39d..c2c9bf1 100644
--- a/app/components/ui/editor/CanvasElementsLayer.tsx
+++ b/app/components/ui/editor/CanvasElementsLayer.tsx
@@ -1,9 +1,79 @@
import { SVG_COMPONENTS } from "@/components/canvas-svg";
import { RotationHandleIcon } from "@/components/ui/RotationHandleIcon";
import { Corner, VIDEO_Z_INDEX, getNearestCorner, getCornerStyle } from "@/lib";
-import { CanvasElement, SvgElement, ImageElement } from "@/types/canvas-elements.types";
+import { CanvasElement, SvgElement, ImageElement, TextElement } from "@/types/canvas-elements.types";
import { useRef, useState, useEffect, useCallback } from "react";
+function InlineTextEditor({
+ element,
+ refSize,
+ onEnd,
+}: {
+ element: TextElement;
+ refSize: number;
+ onEnd: (content: string) => void;
+}) {
+ const divRef = useRef<HTMLDivElement>(null);
+ const committed = useRef(false);
+
+ const commit = useCallback((node: HTMLElement) => {
+ if (committed.current) return;
+ committed.current = true;
+ onEnd(node.textContent ?? "");
+ }, [onEnd]);
+
+ useEffect(() => {
+ const node = divRef.current;
+ if (!node) return;
+ node.textContent = element.content;
+ node.focus();
+ const range = document.createRange();
+ range.selectNodeContents(node);
+ range.collapse(false);
+ const sel = window.getSelection();
+ sel?.removeAllRanges();
+ sel?.addRange(range);
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, []);
+
+ const fontSize = refSize > 0 ? element.fontSize * (refSize / 1080) : element.fontSize;
+
+ return (
+ <div
+ ref={divRef}
+ contentEditable
+ suppressContentEditableWarning
+ spellCheck={false}
+ style={{
+ fontSize: `${fontSize}px`,
+ fontFamily: element.fontFamily,
+ fontWeight: element.fontWeight === "normal" ? 400 : element.fontWeight === "medium" ? 500 : 700,
+ color: element.color,
+ opacity: element.opacity,
+ outline: "none",
+ border: "1.5px solid #3b82f6",
+ borderRadius: "3px",
+ padding: "2px 6px",
+ whiteSpace: "pre",
+ minWidth: "20px",
+ cursor: "text",
+ pointerEvents: "auto",
+ background: "transparent",
+ lineHeight: 1.2,
+ letterSpacing: "normal",
+ userSelect: "text",
+ }}
+ onBlur={(e) => commit(e.currentTarget)}
+ onKeyDown={(e) => {
+ e.stopPropagation();
+ if (e.key === "Escape") { e.preventDefault(); commit(e.currentTarget); }
+ if (e.key === "Enter" && !e.shiftKey) { e.preventDefault(); commit(e.currentTarget); }
+ }}
+ onPointerDown={(e) => e.stopPropagation()}
+ />
+ );
+}
+
export function CanvasElementsLayer({
canvasContainerRef,
canvasElements,
@@ -23,6 +93,9 @@ export function CanvasElementsLayer({
hitTestOnly = false,
elementCorners: elementCornersProp,
setElementCorners: setElementCornersProp,
+ editingTextId = null,
+ onDoubleClickText,
+ onTextEditEnd,
}: {
canvasContainerRef?: React.RefObject<HTMLDivElement | null>;
canvasElements: CanvasElement[];
@@ -42,6 +115,9 @@ export function CanvasElementsLayer({
hitTestOnly?: boolean;
elementCorners?: Record<string, Corner | null>;
setElementCorners?: React.Dispatch<React.SetStateAction<Record<string, Corner | null>>>;
+ editingTextId?: string | null;
+ onDoubleClickText?: (id: string) => void;
+ onTextEditEnd?: (id: string, content: string) => void;
}) {
const layerRef = useRef<HTMLDivElement>(null);
const [refSize, setRefSize] = useState(0);
@@ -197,6 +273,7 @@ export function CanvasElementsLayer({
if (hitTestOnly) {
if (element.visible === false) return null;
+ if (editingTextId === element.id) return null;
const TOP_Z_INDEX = 2147483647;
@@ -227,6 +304,11 @@ export function CanvasElementsLayer({
onMouseLeave={handleMouseLeave}
onMouseMove={handleMouseMove}
onMouseDown={handleMouseDown}
+ onDoubleClick={(e) => {
+ if (element.locked) return;
+ e.stopPropagation();
+ if (onDoubleClickText) onDoubleClickText(element.id);
+ }}
>
{expandedHitArea}
@@ -307,32 +389,46 @@ export function CanvasElementsLayer({
}
if (element.type === "text") {
+ const isEditing = editingTextId === element.id;
return (
<div
key={element.id}
- className="absolute pointer-events-none"
+ className="absolute"
style={{
left: `${element.x}%`,
top: `${element.y}%`,
transform: `translate(-50%, -50%) rotate(${element.rotation}deg)`,
- zIndex: element.zIndex,
+ zIndex: isEditing ? 9999 : element.zIndex,
transition: isDraggingElement ? 'none' : 'transform 0.1s ease-out',
+ pointerEvents: isEditing ? 'auto' : 'none',
}}
>
- <div
- className="whitespace-nowrap"
- style={{
- fontSize: refSize > 0 ? `${element.fontSize * (refSize / 1080)}px` : `${element.fontSize}px`,
- fontFamily: element.fontFamily,
- fontWeight: element.fontWeight === 'normal' ? 400 : element.fontWeight === 'medium' ? 500 : 700,
- textAlign: 'center',
- color: element.color,
- pointerEvents: 'none',
- opacity: element.opacity,
- }}
- >
- {element.content}
- </div>
+ {isEditing ? (
+ <InlineTextEditor
+ element={element as TextElement}
+ refSize={refSize}
+ onEnd={(content) => {
+ if (onTextEditEnd) onTextEditEnd(element.id, content);
+ }}
+ />
+ ) : (
+ <div
+ className="whitespace-nowrap"
+ style={{
+ fontSize: refSize > 0 ? `${element.fontSize * (refSize / 1080)}px` : `${element.fontSize}px`,
+ fontFamily: element.fontFamily,
+ fontWeight: element.fontWeight === 'normal' ? 400 : element.fontWeight === 'medium' ? 500 : 700,
+ textAlign: 'left',
+ color: element.color,
+ pointerEvents: 'none',
+ opacity: element.opacity,
+ lineHeight: 1.2,
+ padding: '2px 6px',
+ }}
+ >
+ {element.content}
+ </div>
+ )}
</div>
);
}
diff --git a/app/components/ui/editor/ControlPanel.tsx b/app/components/ui/editor/ControlPanel.tsx
index eda92d4..a8b4629 100644
--- a/app/components/ui/editor/ControlPanel.tsx
+++ b/app/components/ui/editor/ControlPanel.tsx
@@ -44,6 +44,7 @@ const HistoryMenu = lazy(() => import("./HistoryMenu").then(mod => ({ default: m
interface ExtendedControlPanelProps extends ControlPanelProps {
onTogglePanel?: () => void;
isOpen?: boolean;
+ elementsTextTabTrigger?: number;
}
export function ControlPanel({
@@ -68,6 +69,7 @@ export function ControlPanel({
onImageRemove,
onBackgroundColorChange,
onTogglePanel,
+ elementsTextTabTrigger = 0,
isOpen = true,
// Zoom props
zoomFragments = [],
@@ -305,6 +307,7 @@ export function ControlPanel({
onDeleteElement={onDeleteCanvasElement}
onBringToFront={onBringToFront}
onSendToBack={onSendToBack}
+ textTabTrigger={elementsTextTabTrigger}
/>
</Suspense>
)}
diff --git a/app/components/ui/editor/ElementsMenu.tsx b/app/components/ui/editor/ElementsMenu.tsx
index e35eddd..83dae6e 100644
--- a/app/components/ui/editor/ElementsMenu.tsx
+++ b/app/components/ui/editor/ElementsMenu.tsx
@@ -13,12 +13,17 @@ import { SVG_COMPONENTS } from "@/components/canvas-svg";
import { TooltipAction } from "@/components/ui/tooltip-action";
import { ProgressiveImg } from "@/components/ui/ProgressiveImg";
+interface ExtendedElementsMenuProps extends ElementsMenuProps {
+ textTabTrigger?: number;
+}
+
export function ElementsMenu({
onAddElement,
selectedElement,
onUpdateElement,
onDeleteElement,
-}: ElementsMenuProps) {
+ textTabTrigger = 0,
+}: ExtendedElementsMenuProps) {
const t = useTranslations("elementsMenu");
const [mode, setMode] = useState<"text" | "elements" | "uploads">("elements");
@@ -49,6 +54,15 @@ export function ElementsMenu({
const isSyncing = useRef(false);
const lastSelectedId = useRef<string | null>(null);
+ // Switch to text tab when the parent triggers it (e.g. 'T' key shortcut)
+ useEffect(() => {
+ if (textTabTrigger > 0) {
+ startTransition(() => {
+ setMode("text");
+ });
+ }
+ }, [textTabTrigger]);
+
useEffect(() => {
const currentId = selectedElement?.id || null;
if (lastSelectedId.current === currentId) return;
diff --git a/app/components/ui/editor/VideoCanvas.tsx b/app/components/ui/editor/VideoCanvas.tsx
index 4ca3454..3fbf78a 100644
--- a/app/components/ui/editor/VideoCanvas.tsx
+++ b/app/components/ui/editor/VideoCanvas.tsx
@@ -73,6 +73,9 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(funct
onCameraClick,
videoMaskConfig,
layersPanelToolbar,
+ textToolActive = false,
+ onTextToolDeactivate,
+ onAddElement,
}, ref) {
const wallpaperUrl = getWallpaperUrl(selectedWallpaper);
@@ -271,6 +274,9 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(funct
const [isDraggingOver, setIsDraggingOver] = useState(false);
const canvasContainerRef = useRef<HTMLDivElement>(null);
+ // Inline text editing (Figma-style)
+ const [editingTextId, setEditingTextId] = useState<string | null>(null);
+
// Multi-select and canvas right-click context menu
const [canvasSelectedIds, setCanvasSelectedIds] = useState<string[]>([]);
const [canvasCtxMenu, setCanvasCtxMenu] = useState<{ x: number; y: number } | null>(null);
@@ -1524,6 +1530,12 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(funct
layerZIndex={1}
elementCorners={elementCorners}
setElementCorners={setElementCorners}
+ editingTextId={editingTextId}
+ onTextEditEnd={(id, content) => {
+ if (!content.trim()) { if (onElementDelete) onElementDelete(id); }
+ else { if (onElementUpdate) onElementUpdate(id, { content }); }
+ setEditingTextId(null);
+ }}
/>
{/* 3D rotation layer — solo envuelve el mockup, el fondo queda plano */}
@@ -1747,6 +1759,12 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(funct
layerZIndex={3}
elementCorners={elementCorners}
setElementCorners={setElementCorners}
+ editingTextId={editingTextId}
+ onTextEditEnd={(id, content) => {
+ if (!content.trim()) { if (onElementDelete) onElementDelete(id); }
+ else { if (onElementUpdate) onElementUpdate(id, { content }); }
+ setEditingTextId(null);
+ }}
/>
{/* Capa HIT: invisible, todos los elementos, para recibir eventos */}
@@ -1782,6 +1800,13 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(funct
hitTestOnly={true}
elementCorners={elementCorners}
setElementCorners={setElementCorners}
+ editingTextId={editingTextId}
+ onDoubleClickText={(id) => setEditingTextId(id)}
+ onTextEditEnd={(id, content) => {
+ if (!content.trim()) { if (onElementDelete) onElementDelete(id); }
+ else { if (onElementUpdate) onElementUpdate(id, { content }); }
+ setEditingTextId(null);
+ }}
/>
</div>
@@ -1899,6 +1924,43 @@ export const VideoCanvas = forwardRef<VideoCanvasHandle, VideoCanvasProps>(funct
</div>
</div>
)}
+
+ {/* Text tool crosshair overlay — captures clicks to place text */}
+ {textToolActive && (
+ <div
+ className="absolute inset-0 cursor-crosshair"
+ style={{ zIndex: 99999 }}
+ onClick={(e) => {
+ e.stopPropagation();
+ if (!onAddElement) return;
+ const rect = (e.currentTarget.parentElement as HTMLDivElement).getBoundingClientRect();
+ const x = ((e.clientX - rect.left) / rect.width) * 100;
+ const y = ((e.clientY - rect.top) / rect.height) * 100;
+ const maxZ = canvasElements.length > 0
+ ? Math.max(...canvasElements.map(el => el.zIndex))
+ : 1000;
+ const newId = `text-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
+ const newEl = {
+ id: newId,
+ type: "text" as const,
+ x, y,
+ width: 30,
+ height: 5,
+ rotation: 0,
+ opacity: 1,
+ zIndex: maxZ + 1,
+ content: "",
+ fontSize: 48,
+ fontFamily: "Inter, sans-serif",
+ fontWeight: "bold" as const,
+ color: "#ffffff",
+ };
+ onAddElement(newEl);
+ setEditingTextId(newId);
+ if (onTextToolDeactivate) onTextToolDeactivate();
+ }}
+ />
+ )}
</div>
</div>
</div>