Create professional demos and 3D mockups in seconds, directly in your browser
feat: add onDeviceClickOutside prop to mockup components for improved interaction handling
CristianOlivera174fa6716750e
diff --git a/app/components/ui/editor/VideoCanvas.tsx b/app/components/ui/editor/VideoCanvas.tsxindex 1f212a5..c6502d6 100644--- a/app/components/ui/editor/VideoCanvas.tsx+++ b/app/components/ui/editor/VideoCanvas.tsx@@ -1797,6 +1797,12 @@ function VideoCanvasInner({setEditingTextId(id);}, []);+ const handleDeviceClickOutside = useCallback(() => {+ if (onElementSelect) onElementSelect(null);+ setIsVideoSelected(false);+ setCanvasSelectedIds([]);+ }, [onElementSelect]);+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"@@ -2024,7 +2030,7 @@ function VideoCanvasInner({if (!hasMedia || !onVideoTransformChange) return;const targetEl = e.target as HTMLElement;if (targetEl.closest('[data-rotation-handle]')) return;- if (targetEl.closest('input, textarea, [contenteditable="true"]')) return; // π NUEVO+ if (targetEl.closest('input, textarea, [contenteditable="true"]')) return;e.preventDefault();wasDragRef.current = false;const isGroupMember = isVideoSelected && canvasSelectedIds.length > 0;@@ -2060,7 +2066,7 @@ function VideoCanvasInner({onClick={(e) => {const targetEl = e.target as HTMLElement;if (targetEl.closest('[data-rotation-handle]')) return;- if (targetEl.closest('input, textarea, [contenteditable="true"]')) return; // π NUEVO+ if (targetEl.closest('input, textarea, [contenteditable="true"]')) return;if (!onMockupClick) return;if (mockupId === "none" || mockupId === undefined) return;const start = clickStartPosRef.current;@@ -2113,6 +2119,7 @@ function VideoCanvasInner({isHovered={isVideoHovered}onDeviceHoverChange={(hovered) => setIsVideoHovered(hovered && hasMedia)}onDeviceRectChange={setPhotoDeviceRect}+ onDeviceClickOutside={handleDeviceClickOutside}onConfigChange={onMockupConfigChange}>{mockupChildren}diff --git a/app/components/ui/editor/mockups/MacBookMockup.tsx b/app/components/ui/editor/mockups/MacBookMockup.tsxindex 923ceb4..b8dcc96 100644--- a/app/components/ui/editor/mockups/MacBookMockup.tsx+++ b/app/components/ui/editor/mockups/MacBookMockup.tsx@@ -9,6 +9,7 @@ interface MacBookMockupProps extends MockupRenderProps {isSelected?: boolean;onDeviceHoverChange?: (hovered: boolean) => void;onDeviceRectChange?: (rect: Rect | null) => void;+ onDeviceClickOutside?: () => void;}export function MacBookMockup({@@ -19,6 +20,7 @@ export function MacBookMockup({isSelected = false,onDeviceHoverChange,onDeviceRectChange,+ onDeviceClickOutside,}: MacBookMockupProps) {const { imageSrc, screenRect } = MACBOOK_PHOTO_MOCKUP;const containerRef = useRef<HTMLDivElement>(null);@@ -51,8 +53,11 @@ export function MacBookMockup({}, [isOnDevice]);const handleClickCapture = useCallback((e: React.MouseEvent) => {- if (!isOnDevice(e.clientX, e.clientY)) e.stopPropagation();- }, [isOnDevice]);+ if (!isOnDevice(e.clientX, e.clientY)) {+ e.stopPropagation();+ onDeviceClickOutside?.();+ }+ }, [isOnDevice, onDeviceClickOutside]);const physicalShadow = shadows > 0? `drop-shadow(0 ${shadows * 0.4}px ${shadows * 1.1}px rgba(0,0,0,0.5))`diff --git a/app/components/ui/editor/mockups/MockupWrapper.tsx b/app/components/ui/editor/mockups/MockupWrapper.tsxindex 0b09a4c..1b3aedb 100644--- a/app/components/ui/editor/mockups/MockupWrapper.tsx+++ b/app/components/ui/editor/mockups/MockupWrapper.tsx@@ -38,9 +38,10 @@ interface MockupWrapperProps {onDeviceHoverChange?: (hovered: boolean) => void;onDeviceRectChange?: (rect: { x: number; y: number; width: number; height: number } | null) => void;onConfigChange?: (config: Partial<MockupConfig>) => void;+ onDeviceClickOutside?: () => void;}-function MockupWrapperInner({ mockupId, config, children, roundedCorners = 12, shadows = 20, className = "", maskStyles, isSelected = false, isHovered = false, onDeviceHoverChange, onDeviceRectChange, onConfigChange }: MockupWrapperProps) {+function MockupWrapperInner({ mockupId, config, children, roundedCorners = 12, shadows = 20, className = "", maskStyles, isSelected = false, isHovered = false, onDeviceHoverChange, onDeviceRectChange, onConfigChange,onDeviceClickOutside }: MockupWrapperProps) {switch (mockupId) {case "none":return (@@ -328,6 +329,7 @@ function MockupWrapperInner({ mockupId, config, children, roundedCorners = 12, sisSelected={isSelected}onDeviceHoverChange={onDeviceHoverChange}onDeviceRectChange={onDeviceRectChange}+ onDeviceClickOutside = {onDeviceClickOutside}>{children}</MacBookMockup>