diff --git a/app/builder/[appId]/page.tsx b/app/builder/[appId]/page.tsx index f35b7b1..25e9666 100644 --- a/app/builder/[appId]/page.tsx +++ b/app/builder/[appId]/page.tsx @@ -9,6 +9,13 @@ import { useSyncExternalStore, Suspense, } from "react"; +import { AppForgeLogo } from "@/components/ui/appforge-logo"; +import { + ResizablePanelGroup, + ResizablePanel, + ResizableHandle, +} from "@/components/ui/resizable"; +import type { ImperativePanelHandle } from "react-resizable-panels"; import { ConfigEditor } from "@/components/builder/ConfigEditor"; import { CopilotFloatingPill } from "@/components/builder/CopilotFloatingPill"; import { LivePreview } from "@/components/builder/LivePreview"; @@ -19,7 +26,7 @@ import { IconButton } from "@/components/ui/icon-button"; import { StatusPill } from "@/components/ui/status-pill"; import { ThemeToggle } from "@/components/layout/ThemeToggle"; import { Kbd } from "@/components/ui/kbd"; -import { motion, AnimatePresence } from "framer-motion"; +import { motion, AnimatePresence } from "motion/react"; import { MOTION_TOKENS } from "@/lib/motion-tokens"; import { ArrowLeft, @@ -81,7 +88,7 @@ function getEditorCollapsedSnapshot(): boolean { try { const saved = localStorage.getItem(EDITOR_COLLAPSED_KEY); if (saved !== null) return saved === "true"; - } catch {} + } catch { } return false; } @@ -97,7 +104,7 @@ function getEditorWidthSnapshot(): number { const parsed = parseInt(saved, 10); if (!isNaN(parsed) && parsed >= MIN_EDITOR_WIDTH) return parsed; } - } catch {} + } catch { } return DEFAULT_EDITOR_WIDTH; } @@ -248,7 +255,7 @@ function BuilderContent() { inMemoryEditorCollapsed = next; try { localStorage.setItem(EDITOR_COLLAPSED_KEY, String(next)); - } catch {} + } catch { } emitLayoutChange(); }, [], @@ -261,14 +268,75 @@ function BuilderContent() { inMemoryEditorWidth = next; try { localStorage.setItem(EDITOR_WIDTH_KEY, String(next)); - } catch {} + } catch { } emitLayoutChange(); }, [], ); - // Dragging active state for editor/preview divider - const [activeDrag, setActiveDrag] = useState<"editor" | null>(null); + // Dragging active state for editor/preview divider & panel sizes + const BUILDER_PANEL_SIZES_KEY = "appforge_builder_panel_sizes"; + const DEFAULT_EDITOR_PANEL_SIZE = 42; + + const editorPanelRef = useRef(null); + const [isHandleDragging, setIsHandleDragging] = useState(false); + const [panelSizes, setPanelSizes] = useState(() => { + try { + const saved = + typeof window !== "undefined" + ? localStorage.getItem(BUILDER_PANEL_SIZES_KEY) + : null; + if (saved) { + const parsed = JSON.parse(saved); + if ( + Array.isArray(parsed) && + parsed.length >= 2 && + typeof parsed[0] === "number" + ) { + return parsed; + } + } + } catch { } + return [DEFAULT_EDITOR_PANEL_SIZE, 100 - DEFAULT_EDITOR_PANEL_SIZE]; + }); + + const handlePanelLayout = useCallback((sizes: number[]) => { + setPanelSizes(sizes); + try { + localStorage.setItem(BUILDER_PANEL_SIZES_KEY, JSON.stringify(sizes)); + } catch { } + }, []); + + const handleDraggingChange = useCallback((dragging: boolean) => { + setIsHandleDragging(dragging); + if (dragging) { + document.body.style.cursor = "col-resize"; + document.body.style.userSelect = "none"; + } else { + document.body.style.removeProperty("cursor"); + document.body.style.removeProperty("user-select"); + } + }, []); + + const handleResetPanels = useCallback(() => { + editorPanelRef.current?.resize(DEFAULT_EDITOR_PANEL_SIZE); + try { + localStorage.setItem( + BUILDER_PANEL_SIZES_KEY, + JSON.stringify([ + DEFAULT_EDITOR_PANEL_SIZE, + 100 - DEFAULT_EDITOR_PANEL_SIZE, + ]), + ); + } catch { } + }, []); + + useEffect(() => { + return () => { + document.body.style.removeProperty("cursor"); + document.body.style.removeProperty("user-select"); + }; + }, []); const { isSignedIn } = useAuth(); const isGuestRoute = @@ -340,7 +408,7 @@ function BuilderContent() { if (parsed && typeof parsed.app === "string" && parsed.app.trim()) { return parsed.app.trim(); } - } catch {} + } catch { } return appId; }, [configStr, appId]); @@ -418,45 +486,6 @@ function BuilderContent() { }); }, [setIsEditorCollapsed]); - // Window mousemove / mouseup handlers for divider dragging (Editor vs Preview) - useEffect(() => { - if (!activeDrag) return; - - const handleMouseMove = (e: MouseEvent) => { - if (!containerRef.current) return; - const rect = containerRef.current.getBoundingClientRect(); - const containerWidth = rect.width; - - if (activeDrag === "editor") { - const relativeX = e.clientX - rect.left; - const maxEditor = containerWidth - MIN_PREVIEW_WIDTH - 12; - const boundedWidth = Math.max( - MIN_EDITOR_WIDTH, - Math.min(maxEditor, relativeX), - ); - setEditorWidth(Math.round(boundedWidth)); - } - }; - - const handleMouseUp = () => { - setActiveDrag(null); - document.body.style.removeProperty("cursor"); - document.body.style.removeProperty("user-select"); - }; - - document.body.style.cursor = "col-resize"; - document.body.style.userSelect = "none"; - window.addEventListener("mousemove", handleMouseMove); - window.addEventListener("mouseup", handleMouseUp); - - return () => { - window.removeEventListener("mousemove", handleMouseMove); - window.removeEventListener("mouseup", handleMouseUp); - document.body.style.removeProperty("cursor"); - document.body.style.removeProperty("user-select"); - }; - }, [activeDrag, setEditorWidth]); - const handleSave = async () => { setIsSaving(true); setSaveState("saving"); @@ -640,7 +669,7 @@ function BuilderContent() { TOP APPLICATION TOOLBAR (h-14, 56px) - Glass top bar Sans breadcrumb with App Name, Copilot ⌘K toggle, Save Draft, Publish ========================================================================= */} -
+
{/* Left: Navigation & Breadcrumb with App Name */}
- {/* Breadcrumb shows app's name, not UUID */} + {/* Breadcrumb shows AppForge logo mark tile + app's name */}
- AppForge + +
+ +
+ AppForge + / {/* PANE 1: CONFIG EDITOR (LEFT) */} {isEditorCollapsed ? ( - - {/* Validation Log */} - - - )} + {/* PANE 2: PREVIEW (RIGHT) when editor is collapsed */} +
+
+
+ + + Preview + +
+ +
+ + + +
+
- {/* DIVIDER: Between Editor and Preview */} - {!isEditorCollapsed && ( -
setActiveDrag("editor")} - onDoubleClick={() => setEditorWidth(DEFAULT_EDITOR_WIDTH)} - onKeyDown={(e) => { - if (e.key === "ArrowLeft") { - e.preventDefault(); - setEditorWidth((w) => Math.max(MIN_EDITOR_WIDTH, w - 10)); - } else if (e.key === "ArrowRight") { - e.preventDefault(); - setEditorWidth((w) => w + 10); - } else if (e.key === "Home" || e.key === "Enter") { - e.preventDefault(); - setEditorWidth(DEFAULT_EDITOR_WIDTH); - } - }} - className={`relative w-[6px] -mx-[3px] h-full cursor-col-resize z-30 shrink-0 group outline-none select-none transition-colors ${ - activeDrag === "editor" - ? "bg-brand/30" - : "hover:bg-brand/20 focus-visible:bg-brand/30" - }`} - title="Drag to resize, double-click to reset, arrow keys to adjust" +
+ +
+
+ + ) : ( + -
+ {/* Editor Panel Header: 36px (h-9) consistent with Preview header, styled with glass-1 */} +
+
+ + + Config + +
+ setIsEditorCollapsed(true)} + className="text-muted-foreground hover:text-foreground" + aria-label="Collapse Config Editor to slim rail" + title="Collapse to slim rail" + > + + +
+ + {/* Monaco Editor (automaticLayout: true + ResizeObserver) */} +
+ setConfigStr(val || "")} + /> + {/* Floating Copilot Chat Pill anchored at bottom-right corner of Monaco editor pane */} + +
+ + {/* Validation Log */} + + + + {/* RESIZABLE HANDLE with 8px hit area, 1px line, small grip, col-resize, brand hover/drag, double-click reset */} + -
- )} - {/* PANE 2: PREVIEW (RIGHT) - fills remaining space, sits on solid surface */} -
- {/* Preview Panel Header: 36px (h-9) consistent with Editor header, styled with glass-1 */} -
-
- - - Preview - -
+ {/* PANE 2: PREVIEW (RIGHT) - fills remaining space, sits on solid surface */} + + {/* Preview Panel Header: 36px (h-9) consistent with Editor header, styled with glass-1 */} +
+
+ + + Preview + +
+ + {/* Viewport Width Controls in preview panel header - styled with glass-2-nested */} +
+ + + +
+
- {/* Viewport Width Controls in preview panel header - styled with glass-2-nested */} -
- - - -
-
+ {/* Framed Browser Viewport Container on solid surface */} +
+ +
+ + + )} - {/* Framed Browser Viewport Container on solid surface */} -
- -
-
+ {/* Transparent Drag Overlay: while dragging, prevents Monaco / iframe from swallowing mouse events or hiding cursor */} + {isHandleDragging && ( +
); } diff --git a/components/layout/ThemeToggle.tsx b/components/layout/ThemeToggle.tsx index daeab24..1c82d4e 100644 --- a/components/layout/ThemeToggle.tsx +++ b/components/layout/ThemeToggle.tsx @@ -1,14 +1,15 @@ "use client"; -import { useEffect, useState } from "react"; +import { useEffect, useState, useRef } from "react"; import { useTheme } from "next-themes"; -import { motion, AnimatePresence } from "framer-motion"; +import { flushSync } from "react-dom"; import { Moon, Sun } from "lucide-react"; import { IconButton } from "@/components/ui/icon-button"; export function ThemeToggle() { const { resolvedTheme, setTheme } = useTheme(); const [mounted, setMounted] = useState(false); + const buttonRef = useRef(null); useEffect(() => { // eslint-disable-next-line react-hooks/set-state-in-effect @@ -22,55 +23,118 @@ export function ThemeToggle() { setTheme(nextTheme); if (nextDark) { document.documentElement.classList.add("dark"); + document.documentElement.style.colorScheme = "dark"; } else { document.documentElement.classList.remove("dark"); + document.documentElement.style.colorScheme = "light"; + } + try { + localStorage.setItem("theme", nextTheme); + } catch { + // ignore } }; - const toggleTheme = (event: React.MouseEvent) => { - (event.currentTarget as HTMLElement)?.blur(); + const toggleTheme = (event: React.MouseEvent) => { + event.currentTarget?.blur(); const nextDark = !isDark; const prefersReduced = typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)")?.matches; - if (prefersReduced || !document.startViewTransition) { + // Reduced motion: instant + if (prefersReduced) { applyTheme(nextDark); return; } - document.startViewTransition(() => { + // Fallback for browsers without View Transitions: a 200ms crossfade + if (typeof document === "undefined" || !document.startViewTransition) { + const currentColor = + getComputedStyle(document.documentElement).getPropertyValue("--background").trim() || + (isDark ? "#0F0F0E" : "#FBFBFA"); + const overlay = document.createElement("div"); + overlay.style.position = "fixed"; + overlay.style.inset = "0"; + overlay.style.zIndex = "9998"; + overlay.style.pointerEvents = "none"; + overlay.style.backgroundColor = currentColor; + overlay.style.transition = "opacity 200ms ease-out"; + overlay.style.opacity = "1"; + document.body.appendChild(overlay); + applyTheme(nextDark); + + requestAnimationFrame(() => { + overlay.style.opacity = "0"; + setTimeout(() => { + overlay.remove(); + }, 220); + }); + return; + } + + // View Transitions API: circular reveal radiating from toggle button center + const rect = event.currentTarget.getBoundingClientRect(); + const x = rect.left + rect.width / 2; + const y = rect.top + rect.height / 2; + + const endRadius = Math.hypot( + Math.max(x, window.innerWidth - x), + Math.max(y, window.innerHeight - y) + ); + + const transition = document.startViewTransition(() => { + flushSync(() => { + applyTheme(nextDark); + }); }); + + transition.ready + .then(() => { + const clipPath = [ + `circle(0px at ${x}px ${y}px)`, + `circle(${endRadius}px at ${x}px ${y}px)`, + ]; + + document.documentElement.animate( + { + clipPath, + }, + { + duration: 450, + easing: "ease-out", + pseudoElement: "::view-transition-new(root)", + } + ); + }) + .catch(() => { + // Fallback if animation fails + }); }; if (!mounted) return
; return ( - - - {isDark ? ( - - ) : ( - - )} - - + + {isDark ? ( + + ) : ( + + )} + ); } diff --git a/components/templates/TemplatesView.tsx b/components/templates/TemplatesView.tsx index dc8137f..b4185d6 100644 --- a/components/templates/TemplatesView.tsx +++ b/components/templates/TemplatesView.tsx @@ -39,7 +39,7 @@ export function TemplatesView() {
{CATEGORIES.map((cat) => { const isSelected = selectedCategory === cat; @@ -67,7 +67,7 @@ export function TemplatesView() { {filteredTemplates.map((tpl) => (
{/* Live cropped thumbnail at top with bottom fade */} @@ -99,7 +99,7 @@ export function TemplatesView() {
{/* Actions row: Preview (secondary sm) + Use template (primary sm) on ONE row */} -
+