Create professional demos and 3D mockups in seconds, directly in your browser
refactor: improve UI components and functionality in editor
CristianOlivera126720497ffff
diff --git a/app/[locale]/(editor)/editor/page.tsx b/app/[locale]/(editor)/editor/page.tsxindex 126d387..ab08694 100644--- a/app/[locale]/(editor)/editor/page.tsx+++ b/app/[locale]/(editor)/editor/page.tsx@@ -1006,6 +1006,17 @@ export default function Editor() {const activeClipDataRef = useRef<VideoTrackClip | null>(null);const clipAudioStateRef = useRef<Map<string, boolean>>(new Map());const muteOriginalAudioRef = useRef<boolean>(false);++ const lastTimeUpdateRef = useRef(0);+ const REACT_TIME_UPDATE_INTERVAL_MS = 33;++ const setCurrentTimeThrottled = useCallback((time: number) => {+ const now = performance.now();+ if (now - lastTimeUpdateRef.current >= REACT_TIME_UPDATE_INTERVAL_MS) {+ lastTimeUpdateRef.current = now;+ setCurrentTime(time);+ }+ }, []);useEffect(() => {muteOriginalAudioRef.current = muteOriginalAudio;}, [muteOriginalAudio]);@@ -2552,7 +2563,7 @@ export default function Editor() {return;}- setCurrentTime(timelineTime);+ setCurrentTimeThrottled(timelineTime);syncAudioPlayback(timelineTime, true);}} else {@@ -2568,7 +2579,7 @@ export default function Editor() {return;}- setCurrentTime(currentVideoTime);+ setCurrentTimeThrottled(currentVideoTime);syncAudioPlayback(currentVideoTime, true);}}@@ -2596,7 +2607,7 @@ export default function Editor() {};}, [isPlaying, isDraggingPlayhead]);- const handleTimeUpdate = () => {+ const handleTimeUpdate = useCallback(() => {if (videoRef.current && !isPlaying && !justEndedRef.current && !isSeekingToClipRef.current) {const clips = videoClipsRef.current;if (clips.length > 0 && activeClipDataRef.current) {@@ -2608,7 +2619,7 @@ export default function Editor() {setCurrentTime(videoRef.current.currentTime);}}- };+ }, [isPlaying]);const handlePlayheadDragStart = useCallback(() => {setIsDraggingPlayhead(true);@@ -3084,6 +3095,43 @@ export default function Editor() {setCropArea(crop);}, []);+ const handleVideoEnded = useCallback(() => {+ const clips = videoClipsRef.current;+ if (clips.length > 1) {+ const sortedClips = [...clips].sort((a, b) => a.startTime - b.startTime);+ const currentIndex = sortedClips.findIndex(c => c.id === activeClipIdRef.current);+ if (currentIndex >= 0 && currentIndex < sortedClips.length - 1) {+ return;+ }+ }+ setIsPlaying(false);+ justEndedRef.current = true;+ const endTime = trimRange.end > 0 ? trimRange.end : videoDuration;+ setCurrentTime(endTime);+ setTimeout(() => { justEndedRef.current = false; }, 300);+ }, [trimRange.end, videoDuration]);++ const layersPanelToolbar = useMemo(() => (+ <EditorTopBar+ onExport={handleExport}+ exportProgress={exportProgress}+ hasTransparentBackground={selectedWallpaper === -1}+ onUndo={handleUndo}+ onRedo={handleRedo}+ canUndo={canUndo}+ canRedo={canRedo}+ editorMode={editorMode}+ onImageExport={handleImageExport}+ imageExportProgress={imageExportProgress}+ canvasWidth={customAspectRatio?.width || 1920}+ canvasHeight={customAspectRatio?.height || 1080}+ />+ ), [+ handleExport, exportProgress, selectedWallpaper, handleUndo, handleRedo,+ canUndo, canRedo, editorMode, handleImageExport, imageExportProgress,+ customAspectRatio?.width, customAspectRatio?.height,+ ]);+// Only show camera if the active clip has camera supportconst activeClip = findActiveClipAtTime(currentTime);const shouldShowCamera = activeClip?.hasCamera === true;@@ -3243,22 +3291,7 @@ export default function Editor() {isPlaying={isPlaying}onMockupClick={handleMockupClick}isRestoringProjectRef={isRestoringProjectRef}- layersPanelToolbar={- <EditorTopBar- onExport={handleExport}- exportProgress={exportProgress}- hasTransparentBackground={selectedWallpaper === -1}- onUndo={handleUndo}- onRedo={handleRedo}- canUndo={canUndo}- canRedo={canRedo}- editorMode={editorMode}- onImageExport={handleImageExport}- imageExportProgress={imageExportProgress}- canvasWidth={customAspectRatio?.width || 1920}- canvasHeight={customAspectRatio?.height || 1080}- />- }+ layersPanelToolbar={layersPanelToolbar}ref={canvasRef}videoUrl={videoUrl}videoRef={videoRef}@@ -3309,24 +3342,7 @@ export default function Editor() {cameraConfig={cameraConfig}onCameraConfigChange={handleCameraConfigChange}onCameraClick={handleCameraClick}- onEnded={() => {- const clips = videoClipsRef.current;- if (clips.length > 1) {- const sortedClips = [...clips].sort((a, b) => a.startTime - b.startTime);- const currentIndex = sortedClips.findIndex(c => c.id === activeClipIdRef.current);- if (currentIndex >= 0 && currentIndex < sortedClips.length - 1) {- return;- }- }-- setIsPlaying(false);- justEndedRef.current = true;- const endTime = trimRange.end > 0 ? trimRange.end : videoDuration;- setCurrentTime(endTime);- setTimeout(() => {- justEndedRef.current = false;- }, 300);- }}+ onEnded={handleVideoEnded}/>{/* Video mode: Show player controls and timeline */}diff --git a/app/components/ui/editor/CanvasElementsLayer.tsx b/app/components/ui/editor/CanvasElementsLayer.tsxindex 4e38610..39ea3aa 100644--- a/app/components/ui/editor/CanvasElementsLayer.tsx+++ b/app/components/ui/editor/CanvasElementsLayer.tsx@@ -99,6 +99,8 @@ export function CanvasElementsLayer({editingTextId = null,onDoubleClickText,onTextEditEnd,+ onGroupDragStart,+ videoIncludedInSelection,}: {canvasContainerRef?: React.RefObject<HTMLDivElement | null>;canvasElements: CanvasElement[];@@ -121,6 +123,8 @@ export function CanvasElementsLayer({editingTextId?: string | null;onDoubleClickText?: (id: string) => void;onTextEditEnd?: (id: string, content: string) => void;+ onGroupDragStart?: (e: React.MouseEvent) => void;+ videoIncludedInSelection?: boolean;}) {const layerRef = useRef<HTMLDivElement>(null);const [refSize, setRefSize] = useState(0);@@ -227,12 +231,14 @@ export function CanvasElementsLayer({e.preventDefault();e.stopPropagation();const current = selectedElementIds ?? (selectedElementId ? [selectedElementId] : []);+ const isGroupMember = current.includes(element.id) && (current.length > 1 || !!videoIncludedInSelection);+if (e.shiftKey && onMultiSelect) {const next = current.includes(element.id)? current.filter(id => id !== element.id): [...current, element.id];onMultiSelect(next);- } else if (current.includes(element.id) && current.length > 1) {+ } else if (isGroupMember) {onElementSelect(element.id);} else {onElementSelect(element.id);@@ -240,12 +246,13 @@ export function CanvasElementsLayer({}setIsDraggingElement(true);elementDragStart.current = {- x: e.clientX,- y: e.clientY,- initialX: element.x,- initialY: element.y,- initialRotation: element.rotation,+ x: e.clientX, y: e.clientY,+ initialX: element.x, initialY: element.y, initialRotation: element.rotation,};++ if (isGroupMember && videoIncludedInSelection && onGroupDragStart) {+ onGroupDragStart(e);+ }};const rotationHandle = (isSelected) && activeCorner && onElementUpdate ? (diff --git a/app/components/ui/editor/LabelSidebar.tsx b/app/components/ui/editor/LabelSidebar.tsxindex bf7bb73..3e0e469 100644--- a/app/components/ui/editor/LabelSidebar.tsx+++ b/app/components/ui/editor/LabelSidebar.tsx@@ -4,14 +4,14 @@ interface LabelSidebarProps {export default function LabelSidebar({ audioTracksCount = 0 }: LabelSidebarProps) {return (- <div className="absolute left-0 top-0 bottom-0 w-16 shrink-0 border-r border-white/5 flex flex-col bg-[#0D0D11] z-30">- <div className="h-7 border-b border-white/5" />+ <div className="absolute left-0 top-0 bottom-0 w-14 shrink-0 border-r border-white/5 flex flex-col bg-[#0D0D11] z-30">+ <div className="h-5.5 border-b border-white/5" /><div className="flex-1 flex items-center px-3"><span className="text-[9px] uppercase font-semibold tracking-wider text-zinc-500">Video</span></div>- <div className={`flex items-center px-3 border-t border-white/5 transition-all duration-300 ${audioTracksCount > 0 ? 'h-12' : 'h-15'+ <div className={`flex items-center px-3 border-t border-white/5 transition-all duration-300 ${audioTracksCount > 0 ? 'h-12' : 'h-16'}`}><span className="text-[9px] uppercase font-semibold tracking-wider text-zinc-500">Zoom</span></div>diff --git a/app/components/ui/editor/LayersPanel.tsx b/app/components/ui/editor/LayersPanel.tsxindex c750396..75afae0 100644--- a/app/components/ui/editor/LayersPanel.tsx+++ b/app/components/ui/editor/LayersPanel.tsx@@ -1,6 +1,6 @@"use client";-import { useState, useEffect, useRef, useCallback, useMemo } from "react";+import { useState, useEffect, useRef, useCallback, useMemo, memo } from "react";import { createPortal } from "react-dom";import { Icon } from "@iconify/react";import type { CanvasElement } from "@/types/canvas-elements.types";@@ -11,7 +11,7 @@ import { useTranslations } from "next-intl";import { TooltipAction } from "@/components/ui/tooltip-action";const VIDEO_SENTINEL = "__video__";-export function LayersPanel({+export function LayersPanelInner({elements,selectedId,selectedMultiIds,@@ -1015,4 +1015,6 @@ export function LayersPanel({})()}</div>);-}\ No newline at end of file+}++export const LayersPanel = memo(LayersPanelInner);\ No newline at end of filediff --git a/app/components/ui/editor/PhotoEditorPlaceholder.tsx b/app/components/ui/editor/PhotoEditorPlaceholder.tsxindex 47e4392..4f3448e 100644--- a/app/components/ui/editor/PhotoEditorPlaceholder.tsx+++ b/app/components/ui/editor/PhotoEditorPlaceholder.tsx@@ -2,7 +2,7 @@import { Icon } from "@iconify/react";import { useTranslations } from "next-intl";-import { useState, useCallback } from "react";+import { useState, useCallback, useEffect, useRef } from "react";import { SliderControl } from "../../../../components/ui/SliderControl";import { Button } from "@/components/ui/button";import { AspectRatioSelect } from "@/app/components/ui/AspectRatioSelect";@@ -99,6 +99,24 @@ export function PhotoEditorPlaceholder({[customConfig, onSelectPreview, selectedPreviewId]);+ const scrollContainerRef = useRef<HTMLDivElement>(null);++ useEffect(() => {+ const container = scrollContainerRef.current;+ if (!container) return;++ const handleWheel = (e: WheelEvent) => {+ if (e.deltaY !== 0 && !e.shiftKey) {+ e.preventDefault();+ container.scrollLeft += e.deltaY;+ }+ };++ container.addEventListener("wheel", handleWheel, { passive: false });++ return () => container.removeEventListener("wheel", handleWheel);+ }, []);+const allPreviews: Preview3DConfig[] = [{ ...customConfig, label: t("photoPreview.custom.label") },...PREVIEW_CONFIGS.map((config) => ({@@ -133,7 +151,7 @@ export function PhotoEditorPlaceholder({const renderPreviewCard = (config: Preview3DConfig) => {const isSelected = selectedPreviewId === config.id;const isCustom = config.id === "custom";-+ const showCustomPlaceholder = isCustom && (!isSelected || isCustomUntouched);const ButtonCard = (<buttononClick={() => {@@ -179,7 +197,7 @@ export function PhotoEditorPlaceholder({}}className={`group relative shrink-0 w-32 sm:w-62 aspect-video squircle-element p-px transition-all duration-300 ease-out outline-none ${isSelected? `shadow-[0_0_20px_rgba(0,163,255,0.15)]`- : isCustom && isCustomUntouched+ : showCustomPlaceholder // <--- AQUI? "bg-gradient-radial-primary border border-dashed border-white/20 hover:border-white/40": "bg-white/10 hover:bg-white/20"}`}@@ -187,10 +205,10 @@ export function PhotoEditorPlaceholder({aria-pressed={isSelected}><div- className={`relative w-full h-full rounded-[10px] overflow-hidden transition-colors ${isCustom && isCustomUntouched ? "bg-transparent" : "bg-black/90"+ className={`relative w-full h-full rounded-[10px] overflow-hidden transition-colors ${showCustomPlaceholder ? "bg-transparent" : "bg-black/90"}`}>- {(!isCustom || !isCustomUntouched) && (+ {!showCustomPlaceholder && (<divclassName="absolute inset-0 opacity-10 pointer-events-none group-hover:opacity-[0.3] transition-opacity duration-300"style={{@@ -200,7 +218,7 @@ export function PhotoEditorPlaceholder({/>)}- {isCustom && isCustomUntouched ? (+ {showCustomPlaceholder ? (<div className="absolute inset-0 flex flex-col items-center justify-center gap-1.5 bg-white/3 group-hover:bg-white/5 border border-white/10 transition-colors"><div className="size-8 rounded-full bg-white/5 border border-white/5 flex items-center justify-center"><Icon@@ -497,7 +515,7 @@ export function PhotoEditorPlaceholder({return (<div className={`flex flex-col bg-black border-t border-white/10 ${className}`}>- <div className="h-13 shrink-0 border-t border-white/10 flex items-center justify-between px-5 bg-[#0D0D11] overflow-x-auto [scrollbar-width:none] [-ms-overflow-style:none] [&::-webkit-scrollbar]:hidden">+ <div className="h-13 shrink-0 border-t border-white/10 flex items-center justify-between px-3 bg-[#0D0D11] overflow-x-auto [scrollbar-width:none] [-ms-overflow-style:none] [&::-webkit-scrollbar]:hidden"><div className="flex items-center gap-2 text-white/60 whitespace-nowrap shrink-0"><Icon icon="mdi:tune-vertical" width={16} aria-hidden="true" /><span className="hidden sm:flex text-xs font-semibold tracking-wide uppercase">@@ -593,7 +611,7 @@ export function PhotoEditorPlaceholder({</div></div>- <div className="flex gap-1 sm:gap-3 px-5 overflow-x-auto custom-scrollbar mask-r-from-90%">+ <div ref={scrollContainerRef} className="flex gap-1 sm:gap-3 px-5 overflow-x-auto custom-scrollbar mask-r-from-90%">{imagePhoneActive ? (<>{renderPreviewCard(allPreviews[0])}diff --git a/app/components/ui/editor/PlayerControls.tsx b/app/components/ui/editor/PlayerControls.tsxindex 0e6e88a..5a9f910 100644--- a/app/components/ui/editor/PlayerControls.tsx+++ b/app/components/ui/editor/PlayerControls.tsx@@ -105,7 +105,7 @@ export function PlayerControls({return (<div- className="h-13 shrink-0 border-t border-white/10 flex items-center justify-between px-5 bg-[#0D0D11]"+ className="h-13 shrink-0 border-t border-white/10 flex items-center justify-between px-3 bg-[#0D0D11]"role="toolbar"aria-label={t("toolbar")}>diff --git a/app/components/ui/editor/Timeline.tsx b/app/components/ui/editor/Timeline.tsxindex b8fa5ab..2f12282 100644--- a/app/components/ui/editor/Timeline.tsx+++ b/app/components/ui/editor/Timeline.tsx@@ -46,7 +46,7 @@ export function Timeline({onUpdateAudioTrack,}: TimelineProps) {const t = useTranslations("timeline");-+const trackRef = useRef<HTMLDivElement>(null);const containerRef = useRef<HTMLDivElement>(null);const [trackWidth, setTrackWidth] = useState(0);@@ -73,7 +73,7 @@ export function Timeline({const pendingTrimRef = useRef<{ start: number; end: number } | null>(null);- const TRACK_PADDING = 16;+ const TRACK_PADDING = 0;const contentWidth = useMemo(() => {if (trackWidth === 0) return 0;@@ -131,9 +131,10 @@ export function Timeline({useEffect(() => {const updateTrackWidth = () => {if (containerRef.current) {- setTrackWidth(containerRef.current.clientWidth - TIMELINE_LABEL_WIDTH);+ setTrackWidth(containerRef.current.clientWidth - 12 - TIMELINE_LABEL_WIDTH - 5);}};+updateTrackWidth();window.addEventListener("resize", updateTrackWidth);return () => window.removeEventListener("resize", updateTrackWidth);@@ -318,21 +319,25 @@ export function Timeline({);return (- <div ref={containerRef} className="flex flex-col w-full">+ <div ref={containerRef} className="flex flex-col w-full pr-2"><div className="h-38 shrink-0 bg-[#0D0D11] border-t border-white/10 flex flex-col font-mono text-[10px]"><div className="flex-1 flex flex-col relative overflow-hidden">- {/* Label sidebar */}<LabelSidebar audioTracksCount={audioTracks.length} />{/* Scrollable content */}<divref={trackRef}data-scrollable- className="flex-1 flex flex-col overflow-x-auto overflow-y-hidden custom-scrollbar pl-18"+ className="flex-1 flex flex-col overflow-x-auto overflow-y-hidden custom-scrollbar pl-14 pr-2"style={{ scrollBehavior: 'smooth' }}>- <div style={{ width: contentWidth > 0 ? contentWidth : '100%' }} className="relative flex flex-col h-full">-+ <div+ className="relative flex flex-col h-full"+ style={{+ width: contentWidth > 0 ? contentWidth : '100%',+ minWidth: '100%'+ }}+ >{/* Playhead */}<motion.divclassName="absolute top-0 bottom-0 z-20 flex flex-col items-center cursor-ew-resize group select-none"@@ -354,38 +359,40 @@ export function Timeline({onDragStart={handleDragStart}onDragEnd={handleDragEnd}>- <div className={`w-2.5 h-2.5 bg-blue-400 rotate-45 rounded-[2px] mt-0.75 shrink-0 shadow-[0_0_8px_rgba(96,165,250,0.6)] transition-colors ${isDragging ? 'bg-blue-300 scale-110' : 'group-hover:bg-blue-300'}`} />- <div className={`w-px flex-1 transition-colors ${isDragging ? 'bg-blue-300 w-0.5' : 'bg-blue-400 group-hover:bg-blue-300'}`} />+ <div className={`w-3.5 h-3.5 mt-0.75 shrink-0 transition-all duration-150 origin-top ${isDragging ? 'bg-blue-200 scale-135 shadow-[0_0_15px_rgba(147,197,253,0.9)] ease-out' : 'bg-blue-400 shadow-[0_0_8px_rgba(96,165,250,0.4)] group-hover:bg-blue-300 group-hover:scale-110 ease-in-out'}`}+ style={{ clipPath: 'polygon(0% 0%, 100% 0%, 100% 60%, 50% 100%, 0% 60%)' }}+ />+ <div className={`w-px flex-1 transition-all duration-150 ${isDragging ? 'bg-blue-200 w-[2px] shadow-[0_0_8px_rgba(147,197,253,0.5)] ease-out' : 'bg-blue-400 group-hover:bg-blue-300'}`} /></motion.div>{/* Ruler */}<div- className="h-7 border-b border-white/10 relative shrink-0 cursor-pointer bg-zinc-900/40 select-none"+ className="h-[22px] border-b border-white/10 relative shrink-0 cursor-pointer bg-zinc-900/40 select-none overflow-hidden"onClick={handleTrackClick}><divclassName="absolute inset-0 opacity-20 pointer-events-none"style={{backgroundImage: `linear-gradient(to right, #ccc 1px, transparent 1px)`,- backgroundSize: `${10 * zoomLevel}px 4px`,+ backgroundSize: `${10 * zoomLevel}px 6px`,+ backgroundPosition: `0px 6px`,backgroundRepeat: 'repeat-x'}}/><div className="absolute inset-0 pointer-events-none">{validDuration > 0 && timeMarkers.map((marker, i) => (- <div+ <spankey={i}- className="absolute top-0 h-full flex flex-col items-start"- style={{ left: marker.position }}+ className="absolute top-1 select-none text-[10px] leading-none text-zinc-500 font-mono"+ style={{+ left: marker.position,+ transform: i === 0 ? 'translateX(0)' : i === timeMarkers.length - 1 ? 'translateX(-100%)' : 'translateX(-50%)',+ textShadow: '0 0 2px #0D0D11, 0 0 4px #0D0D11'+ }}>- <div className="w-px h-3 bg-zinc-500/60" />-- <span className={`text-[9px] font-mono text-zinc-500 mt-1 tabular-nums ${i === 0 ? 'ml-1' : i === timeMarkers.length - 1 ? '-ml-7' : '-ml-3'- }`}>- {formatTime(marker.time)}- </span>- </div>+ {formatTime(marker.time)}+ </span>))}</div></div>@@ -396,8 +403,7 @@ export function Timeline({{/* Video track */}<div className="flex-1 flex items-center py-0.5 relative"><div- className="h-full rounded-md flex items-center relative bg-[#0a1510] border border-white/5"- style={{ width: contentWidth > 0 ? contentWidth : '100%' }}+ className="h-full w-full rounded-md flex items-center relative bg-[#0a1510] border border-white/5">{/* Multi-video clips mode */}{videoClips.length > 0 ? (@@ -543,10 +549,7 @@ export function Timeline({}}}>- <div- className="h-full flex items-center relative"- style={{ width: contentWidth > 0 ? contentWidth : '100%' }}- >+ <div className="h-full w-full flex items-center relative">{/* Dynamic zoom fragments with drag/resize */}{zoomFragments.map((fragment) => (<ZoomFragmentTrackItem@@ -622,10 +625,7 @@ export function Timeline({{/* Audio track - only show if there are audio tracks */}{audioTracks.length > 0 && (<div className="h-5 shrink-0 flex items-center border-t border-white/5 relative">- <div- className="h-full flex items-center relative"- style={{ width: contentWidth > 0 ? contentWidth : '100%' }}- >+ <div className="h-full w-full flex items-center relative">{audioTracks.map((track) => {const audio = uploadedAudios?.find(a => a.id === track.audioId);return (diff --git a/app/components/ui/editor/VideoCanvas.tsx b/app/components/ui/editor/VideoCanvas.tsxindex 315a9eb..5ae94e1 100644--- a/app/components/ui/editor/VideoCanvas.tsx+++ b/app/components/ui/editor/VideoCanvas.tsx@@ -1,6 +1,6 @@"use client";-import { useRef, useEffect, useImperativeHandle, forwardRef, useMemo, useState, useCallback, memo } from "react";+import { useRef, useEffect, useImperativeHandle, useMemo, useState, useCallback, memo } from "react";import dynamic from "next/dynamic";import type { VideoCanvasHandle, VideoCanvasProps, VideoThumbnail } from "@/types";import type { ImageElement, SvgElement } from "@/types/canvas-elements.types";@@ -24,12 +24,13 @@ import { EditorHoverTooltip } from "./EditorHoverTooltip";import DropImage from "@/components/ui/DropImage";import { LayersPanel } from "./LayersPanel";import { useMockup3dContext } from "@/app/contexts/Mockup3dContext";-import { PHONE_H, PHONE_W, DEVICE_3D_DIMENSIONS, DEVICE_VIEWER_DEFAULTS } from "@/lib/phone3d.utils";+import { PHONE_H, PHONE_W, DEVICE_3D_DIMENSIONS, DEVICE_VIEWER_DEFAULTS, PHONE_DEVICE_URLS } from "@/lib/phone3d.utils";import { Viewer3DControls } from "@/lib/viewer-controls3d";import { ControlsPopup } from "@/components/ui/ControlsPopup";import { CanvasContextMenu } from "@/components/ui/CanvasContextMenu";import { Viewer3DControlsBridge } from "@/components/ui/Viewer3DControlsBridge";import { applyGradientMaskToRegion, GetMediaMaskStyles } from "@/lib/media-mask.utils";+import { MediaContent } from "@/components/ui/MediaContent";export type { VideoCanvasHandle, VideoCanvasProps };@@ -63,7 +64,7 @@ const IPadMini63DViewer = dynamic({ ssr: false });-const VideoCanvasInner = forwardRef<VideoCanvasHandle, VideoCanvasProps>(function VideoCanvas({+function VideoCanvasInner({activeTool: _activeTool,mediaType = "video",imageUrl = null,@@ -117,7 +118,8 @@ const VideoCanvasInner = forwardRef<VideoCanvasHandle, VideoCanvasProps>(functioonAddElement,onMockupClick,isRestoringProjectRef,-}, ref) {+ ref,+}: VideoCanvasProps & { ref?: React.Ref<VideoCanvasHandle> }) {const wallpaperUrl = getWallpaperUrl(selectedWallpaper);const hasMedia = mediaType === "video" ? !!videoUrl : !!imageUrl;@@ -166,17 +168,8 @@ const VideoCanvasInner = forwardRef<VideoCanvasHandle, VideoCanvasProps>(functioconst [phoneTransitioning, setPhoneTransitioning] = useState(false);const rafDragRef = useRef<number | null>(null);const pendingUpdateRef = useRef<{ id: string; x: number; y: number } | null>(null);+ const pendingMultiUpdatesRef = useRef<Map<string, { x: number; y: number }>>(new Map());- // Model URL for the active device- const PHONE_DEVICE_URLS: Record<string, string | undefined> = {- phone: '/models/phone-gltf.glb',- iphone: '/models/iphone-15-pro-max.glb',- 'iphone-13-pro-max': '/models/apple_iphone_13_pro_max.glb',- 'double_iphone_13_pro': '/models/double_iphone_13_pro.glb',- 'iphone-17-pro-max': '/models/iphone-17-pro-max.glb',- 'ipad_mini_6_2021': '/models/ipad_mini_6_2021.glb',- laptop: '/models/mac-book.glb',- };const imagePhoneModelUrl = PHONE_DEVICE_URLS[imagePhoneDevice];// Get current thumbnail for scrubbing preview@@ -440,6 +433,19 @@ const VideoCanvasInner = forwardRef<VideoCanvasHandle, VideoCanvasProps>(functio// When clicking a multi-selected element, track potential collapse to single (cleared on actual drag)const pendingCollapseRef = useRef<string | null>(null);const wasDragRef = useRef(false);+ const pendingVideoCollapseRef = useRef(false);+ const pendingElementsCollapseRef = useRef(false);++ // Drag & drop state for images (photo mode only)+ 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; isVideo?: boolean } | null>(null);// Smart guides state for element alignmentconst [alignmentGuides, setAlignmentGuides] = useState<{@@ -454,25 +460,83 @@ const VideoCanvasInner = forwardRef<VideoCanvasHandle, VideoCanvasProps>(functio}>({ vertical: [], horizontal: [] });// Wrapper for onElementSelect that also deselects the mockup/video- const handleElementSelect = (id: string | null) => {- if (id !== null) {+ const handleElementSelect = useCallback((id: string | null, preserveVideoSelection: boolean = false) => {+ if (id !== null && !preserveVideoSelection) {setIsVideoSelected(false);}- if (onElementSelect) {- onElementSelect(id);+ if (onElementSelect) onElementSelect(id);+ }, [onElementSelect]);++ const handleLayersSelect = useCallback((id: string | null) => {+ handleElementSelect(id);+ }, [handleElementSelect]);++ const handleLayersMultiSelect = useCallback((ids: string[]) => {+ setCanvasSelectedIds(ids);+ if (ids.length === 1) handleElementSelect(ids[0]);+ else if (ids.length === 0) handleElementSelect(null);+ }, [handleElementSelect]);++ const handleLayersDelete = useCallback((idOrIds: string | string[]) => {+ if (onElementDelete) onElementDelete(idOrIds);+ }, [onElementDelete]);++ const handleLayersReorder = useCallback((frontIds: string[], backIds: string[]) => {+ frontIds.forEach((id, pos) => {+ if (onElementUpdate) onElementUpdate(id, { zIndex: VIDEO_Z_INDEX + frontIds.length - pos });+ });+ backIds.forEach((id, pos) => {+ if (onElementUpdate) onElementUpdate(id, { zIndex: Math.max(1, VIDEO_Z_INDEX - 1 - pos) });+ });+ }, [onElementUpdate]);++ const handleLayersSetGroupId = useCallback((id: string, groupId: string | undefined) => {+ if (onElementUpdate) onElementUpdate(id, { groupId });+ }, [onElementUpdate]);++ const handleLayersToggleVisible = useCallback((id: string, visible: boolean) => {+ if (onElementUpdate) onElementUpdate(id, { visible });+ }, [onElementUpdate]);++ const handleLayersToggleLock = useCallback((id: string, locked: boolean) => {+ if (onElementUpdate) onElementUpdate(id, { locked });+ }, [onElementUpdate]);++ const handleLayersBringToFront = useCallback((id: string) => {+ const maxZ = Math.max(...canvasElements.map(e => e.zIndex), VIDEO_Z_INDEX);+ if (onElementUpdate) onElementUpdate(id, { zIndex: maxZ + 1 });+ }, [canvasElements, onElementUpdate]);++ const handleLayersSendToBack = useCallback((id: string) => {+ const el = canvasElements.find(e => e.id === id);+ if (!el || !onElementUpdate) return;+ if (el.zIndex >= VIDEO_Z_INDEX) {+ onElementUpdate(id, { zIndex: VIDEO_Z_INDEX - 1 });+ } else {+ const minZ = Math.min(...canvasElements.map(e => e.zIndex));+ onElementUpdate(id, { zIndex: Math.max(1, minZ - 1) });}- };+ }, [canvasElements, onElementUpdate]);- // Drag & drop state for images (photo mode only)- const [isDraggingOver, setIsDraggingOver] = useState(false);- const canvasContainerRef = useRef<HTMLDivElement>(null);+ const handleLayersGroup = useCallback((ids: string[]) => {+ const newGroupId = crypto.randomUUID();+ ids.forEach(id => { if (onElementUpdate) onElementUpdate(id, { groupId: newGroupId }); });+ }, [onElementUpdate]);- // Inline text editing (Figma-style)- const [editingTextId, setEditingTextId] = useState<string | null>(null);+ const handleLayersUngroup = useCallback((ids: string[]) => {+ const groupIds = new Set(+ ids.map(id => canvasElements.find(e => e.id === id)?.groupId).filter(Boolean)+ );+ canvasElements+ .filter(e => e.groupId && groupIds.has(e.groupId))+ .forEach(e => { if (onElementUpdate) onElementUpdate(e.id, { groupId: undefined }); });+ }, [canvasElements, onElementUpdate]);- // Multi-select and canvas right-click context menu- const [canvasSelectedIds, setCanvasSelectedIds] = useState<string[]>([]);- const [canvasCtxMenu, setCanvasCtxMenu] = useState<{ x: number; y: number; isVideo?: boolean } | null>(null);+ const handleVideoLayerSelect = useCallback(() => {+ handleElementSelect(null);+ setCanvasSelectedIds([]);+ setIsVideoSelected(true);+ }, [handleElementSelect]);useEffect(() => {if (!canvasCtxMenu) return;@@ -734,11 +798,12 @@ const VideoCanvasInner = forwardRef<VideoCanvasHandle, VideoCanvasProps>(functioif (!isDraggingElement && !isDraggingElementRotation) return;const handleMouseMove = (e: MouseEvent) => {- if (!selectedElementId || !onElementUpdate) return;- const selectedElement = canvasElements.find(el => el.id === selectedElementId);- if (!selectedElement) return;+ if (!onElementUpdate) return;if (isDraggingElementRotation) {+ if (!selectedElementId) return;+ const selectedElement = canvasElements.find(el => el.id === selectedElementId);+ if (!selectedElement) return;const container = canvasContainerRef.current;if (!container) return;const rect = container.getBoundingClientRect();@@ -760,41 +825,47 @@ const VideoCanvasInner = forwardRef<VideoCanvasHandle, VideoCanvasProps>(functioconst deltaX = e.clientX - elementDragStart.current.x;const deltaY = e.clientY - elementDragStart.current.y;- // Only commit to drag after 3px threshold — avoids jitter on clickif (!wasDragRef.current && Math.abs(deltaX) < 3 && Math.abs(deltaY) < 3) return;wasDragRef.current = true;- pendingCollapseRef.current = null; // confirmed drag — cancel pending click-collapse+ pendingCollapseRef.current = null;+ pendingVideoCollapseRef.current = false;const percentX = (deltaX / rect.width) * 100;const percentY = (deltaY / rect.height) * 100;- if (canvasSelectedIds.length > 1) {- // Multi-element drag: move all selected elements by the same delta- // Use the stable ref (captured once at drag start) to avoid cumulative drift+ const combinedWithVideo = isVideoSelected && canvasSelectedIds.length >= 1;++ if (canvasSelectedIds.length > 1 || combinedWithVideo) {multiDragStartRef.current.forEach((startPos, id) => {const el = canvasElements.find(e => e.id === id);if (!el || el.locked) return;const newX = Math.max(0, Math.min(100, startPos.x + percentX));const newY = Math.max(0, Math.min(100, startPos.y + percentY));- onElementUpdate(id, { x: newX, y: newY });+ pendingMultiUpdatesRef.current.set(id, { x: newX, y: newY });});- } else {+ if (!rafDragRef.current) {+ rafDragRef.current = requestAnimationFrame(() => {+ if (onElementUpdate) {+ pendingMultiUpdatesRef.current.forEach((pos, elId) => onElementUpdate(elId, pos));+ }+ pendingMultiUpdatesRef.current.clear();+ rafDragRef.current = null;+ });+ }+ } else if (selectedElementId) {let newX = Math.max(0, Math.min(100, elementDragStart.current.initialX + percentX));let newY = Math.max(0, Math.min(100, elementDragStart.current.initialY + percentY));- // Smart guides: snap to center (horizontal and vertical)const SNAP_THRESHOLD = 2;const centerX = 50;const centerY = 50;const guides: { vertical: number[]; horizontal: number[] } = { vertical: [], horizontal: [] };- // Check horizontal center alignmentif (Math.abs(newX - centerX) < SNAP_THRESHOLD) {newX = centerX;guides.vertical.push(centerX);}- // Check vertical center alignmentif (Math.abs(newY - centerY) < SNAP_THRESHOLD) {newY = centerY;guides.horizontal.push(centerY);@@ -825,11 +896,17 @@ const VideoCanvasInner = forwardRef<VideoCanvasHandle, VideoCanvasProps>(functioif (pendingCollapseRef.current && !wasDragRef.current) {const id = pendingCollapseRef.current;setCanvasSelectedIds([id]);+ if (pendingVideoCollapseRef.current) setIsVideoSelected(false);+ }+ if (pendingElementsCollapseRef.current && !wasDragRef.current) {+ setCanvasSelectedIds([]);+ if (onElementSelect) onElementSelect(null);}pendingCollapseRef.current = null;+ pendingVideoCollapseRef.current = false;+ pendingElementsCollapseRef.current = false;wasDragRef.current = false;- // Flush any pending RAF update antes de limpiar estadoif (rafDragRef.current) {cancelAnimationFrame(rafDragRef.current);rafDragRef.current = null;@@ -838,6 +915,10 @@ const VideoCanvasInner = forwardRef<VideoCanvasHandle, VideoCanvasProps>(functioonElementUpdate(id, { x, y });}pendingUpdateRef.current = null;+ if (onElementUpdate) {+ pendingMultiUpdatesRef.current.forEach((pos, elId) => onElementUpdate(elId, pos));+ }+ pendingMultiUpdatesRef.current.clear();}setIsDraggingElement(false);@@ -851,7 +932,7 @@ const VideoCanvasInner = forwardRef<VideoCanvasHandle, VideoCanvasProps>(functiowindow.removeEventListener("mousemove", handleMouseMove);window.removeEventListener("mouseup", handleMouseUp);};- }, [isDraggingElement, isDraggingElementRotation, selectedElementId, canvasElements, canvasSelectedIds, onElementUpdate]);+ }, [isDraggingElement, isDraggingElementRotation, selectedElementId, canvasElements, canvasSelectedIds, isVideoSelected, onElementUpdate,]);// Image zoom with mouse wheel (photo mode only)useEffect(() => {@@ -1673,6 +1754,86 @@ const VideoCanvasInner = forwardRef<VideoCanvasHandle, VideoCanvasProps>(functio},}));+ const handleTextEditEnd = useCallback((id: string, content: string) => {+ if (!content.trim()) {+ if (onElementDelete) onElementDelete(id);+ } else {+ if (onElementUpdate) onElementUpdate(id, { content });+ }+ setEditingTextId(null);+ }, [onElementDelete, onElementUpdate]);++ const mockupChildren = useMemo(() => (+ hasMedia ? (+ <div className="relative flex items-center justify-center overflow-hidden w-full h-full rounded-[inherit]">+ <MediaContent+ mediaType={mediaType}+ videoUrl={videoUrl}+ videoRef={videoRef}+ imageUrl={imageUrl}+ imageRef={imageRef}+ cropArea={cropArea}+ hasMask={hasMask}+ hasMockup={!!hasMockup}+ maskStyles={maskStyles}+ currentThumbnail={currentThumbnail}+ isVideoHovered={isVideoHovered}+ onTimeUpdate={onTimeUpdate}+ onLoadedMetadata={onLoadedMetadata}+ onEnded={onEnded}+ />+ </div>+ ) : (+ <div className="w-full h-full aspect-video min-w-75 bg-[#1E1E1E] border border-white/10 flex flex-col overflow-hidden">+ <PlaceholderEditor+ onVideoUpload={mediaType === "video" ? onVideoUpload : onImageUpload}+ isUploading={isUploading}+ mediaType={mediaType}+ />+ </div>+ )+ ), [+ hasMedia, mediaType, videoUrl, videoRef, imageUrl, imageRef,+ cropArea, hasMask, hasMockup, maskStyles, currentThumbnail, isVideoHovered,+ onTimeUpdate, onLoadedMetadata, onEnded, onVideoUpload, onImageUpload, isUploading,+ ]);++ const handleHitTestElementSelect = useCallback((id: string | null) => {+ wasDragRef.current = false;+ if (id) {+ const isGroupMember = canvasSelectedIds.includes(id) && (canvasSelectedIds.length > 1 || isVideoSelected);+ handleElementSelect(id, isGroupMember);+ if (!canvasSelectedIds.includes(id)) {+ setCanvasSelectedIds([id]);+ pendingCollapseRef.current = null;+ pendingVideoCollapseRef.current = false;+ } else if (isGroupMember) {+ pendingCollapseRef.current = id;+ }+ } else {+ handleElementSelect(null);+ setCanvasSelectedIds([]);+ pendingCollapseRef.current = null;+ pendingVideoCollapseRef.current = false;+ }+ }, [canvasSelectedIds, isVideoSelected, handleElementSelect]);++ const handleGroupDragStart = useCallback((e: React.MouseEvent) => {+ wasDragRef.current = false;+ setIsDraggingVideo(true);+ dragStartPos.current = {+ x: e.clientX, y: e.clientY,+ initialRotation: videoTransform.rotation,+ initialTranslateX: videoTransform.translateX,+ initialTranslateY: videoTransform.translateY,+ };+ pendingVideoCollapseRef.current = true;+ }, [videoTransform]);++ const handleDoubleClickText = useCallback((id: string) => {+ setEditingTextId(id);+ }, []);+return (<divclassName="flex-1 flex items-center justify-center min-h-0 min-w-0 overflow-hidden bg-[#09090B] p-2 sm:p-4 lg:p-1 relative"@@ -1822,11 +1983,7 @@ const VideoCanvasInner = forwardRef<VideoCanvasHandle, VideoCanvasProps>(functioelementCorners={elementCorners}setElementCorners={setElementCorners}editingTextId={editingTextId}- onTextEditEnd={(id, content) => {- if (!content.trim()) { if (onElementDelete) onElementDelete(id); }- else { if (onElementUpdate) onElementUpdate(id, { content }); }- setEditingTextId(null);- }}+ onTextEditEnd={handleTextEditEnd}/>{/* 3D rotation layer — solo envuelve el mockup, el fondo queda plano */}@@ -1881,9 +2038,10 @@ const VideoCanvasInner = forwardRef<VideoCanvasHandle, VideoCanvasProps>(functio`: `translate(${videoTransform.translateX}%, ${videoTransform.translateY}%) rotate(${videoTransform.rotation}deg)`,cursor: isDraggingVideo ? 'move' : (isVideoHovered && hasMedia ? 'move' : 'default'),- transition: (mediaType === "image" && imageTransform && !apply3DToBackground)- ? 'transform 300ms cubic-bezier(0.25, 0.46, 0.45, 0.94)'- : isDraggingVideo || isDraggingRotation ? 'none' : 'transform 0.15s cubic-bezier(0.25, 0.46, 0.45, 0.94)',+ transition: (isDraggingVideo || isDraggingRotation)+ ? 'none' : (mediaType === "image" && imageTransform && !apply3DToBackground)+ ? 'transform 300ms cubic-bezier(0.25, 0.46, 0.45, 0.94)'+ : 'transform 0.15s cubic-bezier(0.25, 0.46, 0.45, 0.94)',pointerEvents: imagePhoneActive ? 'none' : 'auto',transformStyle: mediaType === "image" && !apply3DToBackground ? 'preserve-3d' : undefined,}}@@ -1895,22 +2053,35 @@ const VideoCanvasInner = forwardRef<VideoCanvasHandle, VideoCanvasProps>(functioonMouseDown={(e) => {if (!hasMedia || !onVideoTransformChange) return;if ((e.target as HTMLElement).closest('[data-rotation-handle]')) return;-e.preventDefault();- setIsVideoSelected(true);- if (onElementSelect) onElementSelect(null);- setCanvasSelectedIds([]);+ wasDragRef.current = false;++ const isGroupMember = isVideoSelected && canvasSelectedIds.length > 0;++ if (e.shiftKey) {+ setIsVideoSelected((prev) => !prev);+ } else if (isGroupMember) {+ pendingElementsCollapseRef.current = true;+ } else {+ setIsVideoSelected(true);+ if (onElementSelect) onElementSelect(null);+ setCanvasSelectedIds([]);+ }+setVideoHoverCorner(getNearestCorner(e, videoTransform.rotation));setIsDraggingVideo(true);dragStartPos.current = {- x: e.clientX,- y: e.clientY,+ x: e.clientX, y: e.clientY,initialRotation: videoTransform.rotation,initialTranslateX: videoTransform.translateX,initialTranslateY: videoTransform.translateY,};- // Track click vs drag for onMockupClick dispatchclickStartPosRef.current = { x: e.clientX, y: e.clientY };++ if (canvasSelectedIds.length > 0) {+ setIsDraggingElement(true);+ elementDragStart.current = { x: e.clientX, y: e.clientY, initialX: 0, initialY: 0, initialRotation: 0 };+ }}}onMouseMove={(e) => { if (hasMedia) setVideoHoverCorner(getNearestCorner(e, videoTransform.rotation)); }}onClick={(e) => {@@ -1974,73 +2145,7 @@ const VideoCanvasInner = forwardRef<VideoCanvasHandle, VideoCanvasProps>(functioroundedCorners={roundedCorners}shadows={shadows}>- {hasMedia ? (- <div className="relative flex items-center justify-center overflow-hidden w-full h-full rounded-[inherit]">- {mediaType === "video" && videoUrl ? (- <>- <video- key={videoUrl}- ref={videoRef}- preload="auto"- playsInline- className="w-full h-full object-contain"- style={{- ...(cropArea && (cropArea.width < 100 || cropArea.height < 100 || cropArea.x > 0 || cropArea.y > 0)- ? { objectViewBox: `inset(${cropArea.y}% ${100 - cropArea.x - cropArea.width}% ${100 - cropArea.y - cropArea.height}% ${cropArea.x}%)` }- : {}),- ...(hasMask && !hasMockup ? maskStyles : {}),- opacity: currentThumbnail ? 0 : 1,- }}- onTimeUpdate={onTimeUpdate}- onLoadedMetadata={onLoadedMetadata}- onEnded={onEnded}- />- {currentThumbnail && (- <img- src={currentThumbnail.dataUrl}- alt="Preview"- crossOrigin="anonymous"- className="absolute inset-0 w-full h-full object-contain"- style={hasMask && !hasMockup ? maskStyles : {}}- />- )}- </>- ) : mediaType === "image" && imageUrl ? (- <>- <img- ref={imageRef as React.RefObject<HTMLImageElement>}- src={imageUrl}- alt="Editing image"- crossOrigin="anonymous"- className="w-full h-full object-contain"- style={{- ...(cropArea && (cropArea.width < 100 || cropArea.height < 100 || cropArea.x > 0 || cropArea.y > 0) ? {- objectViewBox: `inset(${cropArea.y}% ${100 - cropArea.x - cropArea.width}% ${100 - cropArea.y - cropArea.height}% ${cropArea.x}%)`- } : {}),- ...(hasMask && !hasMockup ? maskStyles : {}),- }}- onLoad={onLoadedMetadata}- />- <div- className="absolute inset-0 pointer-events-none transition-opacity duration-300"- style={{- background: "radial-gradient(circle at center, transparent 30%, rgba(0, 0, 0, 0.75) 100%)",- opacity: isVideoHovered ? 1 : 0,- zIndex: 10- }}- />- </>- ) : null}- </div>- ) : (- <div className="w-full h-full aspect-video min-w-75 bg-[#1E1E1E] border border-white/10 flex flex-col overflow-hidden">- <PlaceholderEditor- onVideoUpload={mediaType === "video" ? onVideoUpload : onImageUpload}- isUploading={isUploading}- mediaType={mediaType}- />- </div>- )}+ {mockupChildren}</MockupWrapper></div></div>@@ -2077,11 +2182,7 @@ const VideoCanvasInner = forwardRef<VideoCanvasHandle, VideoCanvasProps>(functioelementCorners={elementCorners}setElementCorners={setElementCorners}editingTextId={editingTextId}- onTextEditEnd={(id, content) => {- if (!content.trim()) { if (onElementDelete) onElementDelete(id); }- else { if (onElementUpdate) onElementUpdate(id, { content }); }- setEditingTextId(null);- }}+ onTextEditEnd={handleTextEditEnd}/>{/* Capa HIT: invisible, todos los elementos, para recibir eventos */}@@ -2093,21 +2194,10 @@ const VideoCanvasInner = forwardRef<VideoCanvasHandle, VideoCanvasProps>(functiohoveredElementId={hoveredElementId}isDraggingElement={isDraggingElement}behindVideo={true}- onElementSelect={(id) => {- handleElementSelect(id);- if (id) {- if (!canvasSelectedIds.includes(id)) {- setCanvasSelectedIds([id]);- pendingCollapseRef.current = null;- } else if (canvasSelectedIds.length > 1) {- pendingCollapseRef.current = id;- }- } else {- setCanvasSelectedIds([]);- pendingCollapseRef.current = null;- }- }}+ onElementSelect={handleHitTestElementSelect}onMultiSelect={setCanvasSelectedIds}+ videoIncludedInSelection={isVideoSelected}+ onGroupDragStart={handleGroupDragStart}onElementUpdate={onElementUpdate}setHoveredElementId={setHoveredElementId}setIsDraggingElement={setIsDraggingElement}@@ -2118,12 +2208,8 @@ const VideoCanvasInner = forwardRef<VideoCanvasHandle, VideoCanvasProps>(functioelementCorners={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);- }}+ onDoubleClickText={handleDoubleClickText}+ onTextEditEnd={handleTextEditEnd}/>{/* ── 3D phone overlay (video & image mode) ── */}@@ -2515,64 +2601,21 @@ const VideoCanvasInner = forwardRef<VideoCanvasHandle, VideoCanvasProps>(functioelements={canvasElements}selectedId={selectedElementId}selectedMultiIds={canvasSelectedIds}- onSelect={(id) => { if (handleElementSelect) handleElementSelect(id); }}- onMultiSelect={(ids) => {- setCanvasSelectedIds(ids);- if (ids.length === 1) handleElementSelect(ids[0]);- else if (ids.length === 0) handleElementSelect(null);- }}- onDelete={(idOrIds) => { if (onElementDelete) onElementDelete(idOrIds); }}- onReorder={(frontIds, backIds) => {- frontIds.forEach((id, pos) => {- if (onElementUpdate) onElementUpdate(id, { zIndex: VIDEO_Z_INDEX + frontIds.length - pos });- });- backIds.forEach((id, pos) => {- if (onElementUpdate) onElementUpdate(id, { zIndex: Math.max(1, VIDEO_Z_INDEX - 1 - pos) });- });- }}- onSetGroupId={(id, groupId) => {- if (onElementUpdate) onElementUpdate(id, { groupId });- }}- onToggleVisible={(id, visible) => {- if (onElementUpdate) onElementUpdate(id, { visible });- }}- onToggleLock={(id, locked) => {- if (onElementUpdate) onElementUpdate(id, { locked });- }}- onBringToFront={(id) => {- const maxZ = Math.max(...canvasElements.map(e => e.zIndex), VIDEO_Z_INDEX);- if (onElementUpdate) onElementUpdate(id, { zIndex: maxZ + 1 });- }}- onSendToBack={(id) => {- const el = canvasElements.find(e => e.id === id);- if (!el || !onElementUpdate) return;- if (el.zIndex >= VIDEO_Z_INDEX) {- onElementUpdate(id, { zIndex: VIDEO_Z_INDEX - 1 });- } else {- const minZ = Math.min(...canvasElements.map(e => e.zIndex));- onElementUpdate(id, { zIndex: Math.max(1, minZ - 1) });- }- }}- onGroup={(ids) => {- const newGroupId = crypto.randomUUID();- ids.forEach(id => { if (onElementUpdate) onElementUpdate(id, { groupId: newGroupId }); });- }}- onUngroup={(ids) => {- const groupIds = new Set(- ids.map(id => canvasElements.find(e => e.id === id)?.groupId).filter(Boolean)- );- canvasElements- .filter(e => e.groupId && groupIds.has(e.groupId))- .forEach(e => { if (onElementUpdate) onElementUpdate(e.id, { groupId: undefined }); });- }}+ onSelect={handleLayersSelect}+ onMultiSelect={handleLayersMultiSelect}+ onDelete={handleLayersDelete}+ onReorder={handleLayersReorder}+ onSetGroupId={handleLayersSetGroupId}+ onToggleVisible={handleLayersToggleVisible}+ onToggleLock={handleLayersToggleLock}+ onBringToFront={handleLayersBringToFront}+ onSendToBack={handleLayersSendToBack}+ onGroup={handleLayersGroup}+ onUngroup={handleLayersUngroup}toolbar={layersPanelToolbar}videoLayerVisible={!!(videoUrl || imageUrl)}isVideoLayerSelected={isVideoSelected}- onVideoLayerSelect={() => {- handleElementSelect(null);- setCanvasSelectedIds([]);- setIsVideoSelected(true);- }}+ onVideoLayerSelect={handleVideoLayerSelect}mediaType={mediaType}hoveredElementId={hoveredElementId}onHoverElement={setHoveredElementId}@@ -2582,5 +2625,5 @@ const VideoCanvasInner = forwardRef<VideoCanvasHandle, VideoCanvasProps>(functio</div></div>);-});-export const VideoCanvas = memo(VideoCanvasInner);\ No newline at end of file+}+export const VideoCanvas = memo(VideoCanvasInner);diff --git a/app/components/ui/editor/mockups/MockupWrapper.tsx b/app/components/ui/editor/mockups/MockupWrapper.tsxindex c0562d2..e6b0cd4 100644--- a/app/components/ui/editor/mockups/MockupWrapper.tsx+++ b/app/components/ui/editor/mockups/MockupWrapper.tsx@@ -22,6 +22,7 @@ import { GlassFullMockup } from "./GlassFullMockup";import { HardShellMockup } from "./HardShellMockup";import { S24UltraMockup } from "./S24UltraMockup";import { OutlineMockup } from "./OutlineMockup";+import { memo } from "react";interface MockupWrapperProps {mockupId: string;@@ -32,7 +33,7 @@ interface MockupWrapperProps {className?: string;}-export function MockupWrapper({+function MockupWrapperInner({mockupId,config,children,@@ -299,3 +300,5 @@ export function MockupWrapper({);}}++export const MockupWrapper = memo(MockupWrapperInner);\ No newline at end of filediff --git a/components/ui/CanvasContextMenu.tsx b/components/ui/CanvasContextMenu.tsxindex 49511b7..7a9b35d 100644--- a/components/ui/CanvasContextMenu.tsx+++ b/components/ui/CanvasContextMenu.tsx@@ -37,6 +37,7 @@ export function CanvasContextMenu({onVideoSendToBack,}: CanvasContextMenuProps) {const t = useTranslations("elementsMenu");+ const t2 = useTranslations("editor");if (!canvasCtxMenu) return null;@@ -138,7 +139,7 @@ export function CanvasContextMenu({}}><Icon icon="solar:layers-minimalistic-bold" className="size-3.5 shrink-0 opacity-70" />- {t("group", { count: ids.length })}+ {t2("layerPanel.groupAction", { count: ids.length })}</button><button@@ -156,7 +157,7 @@ export function CanvasContextMenu({}}><Icon icon="solar:layers-bold" className="size-3.5 shrink-0 opacity-70" />- {t("ungroup")}+ {t2("layerPanel.ungroupAction")}</button><div className="my-1 h-px bg-white/6" />diff --git a/components/ui/MediaContent.tsx b/components/ui/MediaContent.tsxnew file mode 100644index 0000000..bc81193--- /dev/null+++ b/components/ui/MediaContent.tsx@@ -0,0 +1,88 @@+import { VideoCanvasProps, VideoThumbnail } from "@/types";+import { memo } from "react";++export const MediaContent = memo(function MediaContent({+ mediaType, videoUrl, videoRef, imageUrl, imageRef,+ cropArea, hasMask, hasMockup, maskStyles,+ currentThumbnail, isVideoHovered,+ onTimeUpdate, onLoadedMetadata, onEnded,+}: {+ mediaType: "video" | "image";+ videoUrl: string | null;+ videoRef: React.RefObject<HTMLVideoElement | null>;+ imageUrl: string | null;+ imageRef?: React.RefObject<HTMLImageElement | null>;+ cropArea?: VideoCanvasProps["cropArea"];+ hasMask: boolean;+ hasMockup: boolean;+ maskStyles: React.CSSProperties;+ currentThumbnail: VideoThumbnail | null;+ isVideoHovered: boolean;+ onTimeUpdate?: () => void;+ onLoadedMetadata?: () => void;+ onEnded?: () => void;+}) {+ if (mediaType === "video" && videoUrl) {+ return (+ <>+ <video+ key={videoUrl}+ ref={videoRef}+ preload="auto"+ playsInline+ className="w-full h-full object-contain"+ style={{+ ...(cropArea && (cropArea.width < 100 || cropArea.height < 100 || cropArea.x > 0 || cropArea.y > 0)+ ? { objectViewBox: `inset(${cropArea.y}% ${100 - cropArea.x - cropArea.width}% ${100 - cropArea.y - cropArea.height}% ${cropArea.x}%)` }+ : {}),+ ...(hasMask && !hasMockup ? maskStyles : {}),+ opacity: currentThumbnail ? 0 : 1,+ }}+ onTimeUpdate={onTimeUpdate}+ onLoadedMetadata={onLoadedMetadata}+ onEnded={onEnded}+ />+ {currentThumbnail && (+ <img+ src={currentThumbnail.dataUrl}+ alt="Preview"+ crossOrigin="anonymous"+ className="absolute inset-0 w-full h-full object-contain"+ style={hasMask && !hasMockup ? maskStyles : {}}+ />+ )}+ </>+ );+ }++ if (mediaType === "image" && imageUrl) {+ return (+ <>+ <img+ ref={imageRef as React.RefObject<HTMLImageElement>}+ src={imageUrl}+ alt="Editing image"+ crossOrigin="anonymous"+ className="w-full h-full object-contain"+ style={{+ ...(cropArea && (cropArea.width < 100 || cropArea.height < 100 || cropArea.x > 0 || cropArea.y > 0) ? {+ objectViewBox: `inset(${cropArea.y}% ${100 - cropArea.x - cropArea.width}% ${100 - cropArea.y - cropArea.height}% ${cropArea.x}%)`+ } : {}),+ ...(hasMask && !hasMockup ? maskStyles : {}),+ }}+ onLoad={onLoadedMetadata}+ />+ <div+ className="absolute inset-0 pointer-events-none transition-opacity duration-300"+ style={{+ background: "radial-gradient(circle at center, transparent 30%, rgba(0, 0, 0, 0.75) 100%)",+ opacity: isVideoHovered ? 1 : 0,+ zIndex: 10,+ }}+ />+ </>+ );+ }++ return null;+});\ No newline at end of file