Write HTML. Render video. Built for agents.
JavaScript aiai-agentsanimationclaude-codeffmpegframeworkgsaphtmlhtml-to-videomcpmotion-graphicspuppeteerrenderingtypescriptvideo-editor
feat(studio): redesign left panel — Code tab, Renders header, Lint bottom (#141)
Miguel Ángel7b18c0352e9a
diff --git a/packages/studio/src/App.tsx b/packages/studio/src/App.tsxindex cb790ece76..bc95048084 100644--- a/packages/studio/src/App.tsx+++ b/packages/studio/src/App.tsx@@ -2,7 +2,6 @@ import { useState, useCallback, useRef, useEffect, type ReactNode } from "react"import { useMountEffect } from "./hooks/useMountEffect";import { NLELayout } from "./components/nle/NLELayout";import { SourceEditor } from "./components/editor/SourceEditor";-import { FileTree } from "./components/editor/FileTree";import { LeftSidebar } from "./components/sidebar/LeftSidebar";import { RenderQueue } from "./components/renders/RenderQueue";import { useRenderQueue } from "./components/renders/useRenderQueue";@@ -277,7 +276,6 @@ export function StudioApp() {}, []);const [editingFile, setEditingFile] = useState<EditingFile | null>(null);- const [rightTab, setRightTab] = useState<"code" | "renders">("code");const [activeCompPath, setActiveCompPath] = useState<string | null>(null);const [fileTree, setFileTree] = useState<string[]>([]);const [compIdToSrc, setCompIdToSrc] = useState<Map<string, string>>(new Map());@@ -287,10 +285,12 @@ export function StudioApp() {const [leftWidth, setLeftWidth] = useState(240);const [rightWidth, setRightWidth] = useState(400);const [leftCollapsed, setLeftCollapsed] = useState(false);- const [rightCollapsed, setRightCollapsed] = useState(false);- const panelDragRef = useRef<{ side: "left" | "right"; startX: number; startW: number } | null>(- null,- );+ const [rightCollapsed, setRightCollapsed] = useState(true);+ const panelDragRef = useRef<{+ side: "left" | "right";+ startX: number;+ startW: number;+ } | null>(null);// Derive active preview URL from composition path (for drilled-down thumbnails)const activePreviewUrl = activeCompPath@@ -431,6 +431,8 @@ export function StudioApp() {const handleFileSelect = useCallback((path: string) => {const pid = projectIdRef.current;if (!pid) return;+ // Expand left panel to 50vw when opening a file in Code tab+ setLeftWidth((prev) => Math.max(prev, Math.floor(window.innerWidth * 0.5)));// Skip fetching binary content for media files — just set the path for previewif (isMediaFile(path)) {setEditingFile({ path, content: null });@@ -509,9 +511,13 @@ export function StudioApp() {const drag = panelDragRef.current;if (!drag) return;const delta = e.clientX - drag.startX;+ const maxLeft = Math.floor(window.innerWidth * 0.5);const newW = Math.max(160,- Math.min(600, drag.startW + (drag.side === "left" ? delta : -delta)),+ Math.min(+ drag.side === "left" ? maxLeft : 600,+ drag.startW + (drag.side === "left" ? delta : -delta),+ ),);if (drag.side === "left") setLeftWidth(newW);else setRightWidth(newW);@@ -540,38 +546,16 @@ export function StudioApp() {<div className="flex flex-col h-screen w-screen bg-neutral-950">{/* Header bar */}<div className="flex items-center justify-between h-10 px-3 bg-neutral-900 border-b border-neutral-800 flex-shrink-0">- {/* Left: back button + project name */}+ {/* Left: project name */}<div className="flex items-center gap-2">- <button- onClick={() => {- window.location.hash = "";- setProjectId(null);- }}- className="flex items-center gap-1.5 px-2 py-1 rounded-md text-neutral-500 hover:text-neutral-200 hover:bg-neutral-800 transition-colors"- >- <svg- width="14"- height="14"- viewBox="0 0 24 24"- fill="none"- stroke="currentColor"- strokeWidth="2"- strokeLinecap="round"- strokeLinejoin="round"- >- <polyline points="15 18 9 12 15 6" />- </svg>- <span className="text-xs">Projects</span>- </button>- <span className="text-[11px] text-neutral-600">/</span>- <span className="text-[11px] font-medium text-neutral-300">{projectId}</span>+ <span className="text-[11px] font-medium text-neutral-400">{projectId}</span></div>{/* Right: toolbar buttons */}<div className="flex items-center gap-1.5"><buttononClick={() => setLeftCollapsed((v) => !v)}className={`h-7 w-7 flex items-center justify-center rounded-md border transition-colors ${- leftCollapsed+ !leftCollapsed? "bg-neutral-800 border-neutral-700 text-neutral-300": "bg-transparent border-transparent text-neutral-500 hover:text-neutral-300 hover:bg-neutral-800"}`}@@ -591,35 +575,27 @@ export function StudioApp() {<path d="M9 3v18" /></svg></button>- <button- onClick={handleLint}- disabled={linting}- className="h-7 px-2.5 rounded-md text-[11px] font-medium text-neutral-500 hover:text-amber-300 hover:bg-neutral-800 transition-colors disabled:opacity-40"- >- {linting ? "Linting..." : "Lint"}- </button><buttononClick={() => setRightCollapsed((v) => !v)}- className={`h-7 w-7 flex items-center justify-center rounded-md border transition-colors ${- rightCollapsed- ? "bg-neutral-800 border-neutral-700 text-neutral-300"- : "bg-transparent border-transparent text-neutral-500 hover:text-neutral-300 hover:bg-neutral-800"+ className={`h-7 flex items-center gap-1.5 px-2.5 rounded-md text-[11px] font-medium border transition-colors ${+ !rightCollapsed+ ? "text-[#3CE6AC] bg-[#3CE6AC]/10 border-[#3CE6AC]/30"+ : "text-neutral-500 hover:text-neutral-300 hover:bg-neutral-800 border-transparent"}`}- title={rightCollapsed ? "Show code panel" : "Hide code panel"}><svg- width="14"- height="14"+ width="12"+ height="12"viewBox="0 0 24 24"fill="none"stroke="currentColor"- strokeWidth="1.5"- strokeLinecap="round"- strokeLinejoin="round"+ strokeWidth="2">- <rect x="3" y="3" width="18" height="18" rx="2" />- <path d="M15 3v18" />+ <circle cx="12" cy="12" r="10" />+ <polygon points="10 8 16 12 10 16" fill="currentColor" stroke="none" /></svg>+ Renders+ {renderQueue.jobs.length > 0 ? ` (${renderQueue.jobs.length})` : ""}</button></div></div>@@ -649,6 +625,24 @@ export function StudioApp() {.then((data) => setEditingFile({ path: comp, content: data.content })).catch(() => {});}}+ fileTree={fileTree}+ editingFile={editingFile}+ onSelectFile={handleFileSelect}+ codeChildren={+ editingFile ? (+ isMediaFile(editingFile.path) ? (+ <MediaPreview projectId={projectId} filePath={editingFile.path} />+ ) : (+ <SourceEditor+ content={editingFile.content ?? ""}+ filePath={editingFile.path}+ onChange={handleContentChange}+ />+ )+ ) : undefined+ }+ onLint={handleLint}+ linting={linting}/>)}@@ -682,80 +676,20 @@ export function StudioApp() {/></div>- {/* Right resize handle */}+ {/* Right panel: Renders-only (resizable, collapsible via header Renders button) */}{!rightCollapsed && (- <div- className="w-1 flex-shrink-0 bg-neutral-800 hover:bg-blue-500 cursor-col-resize transition-colors active:bg-blue-400"- style={{ touchAction: "none" }}- onPointerDown={(e) => handlePanelResizeStart("right", e)}- onPointerMove={handlePanelResizeMove}- onPointerUp={handlePanelResizeEnd}- />- )}-- {/* Right panel: Code + Renders tabs (resizable, collapsible) */}- {!rightCollapsed && (- <div- className="flex flex-col border-l border-neutral-800 bg-neutral-900 flex-shrink-0"- style={{ width: rightWidth }}- >- {/* Tab bar */}- <div className="flex items-center border-b border-neutral-800 flex-shrink-0">- <button- onClick={() => setRightTab("code")}- className={`flex-1 py-2 text-[11px] font-medium transition-colors ${- rightTab === "code"- ? "text-neutral-200 border-b-2 border-[#3CE6AC]"- : "text-neutral-500 hover:text-neutral-400"- }`}- >- Code- </button>- <button- onClick={() => setRightTab("renders")}- className={`flex-1 py-2 text-[11px] font-medium transition-colors ${- rightTab === "renders"- ? "text-neutral-200 border-b-2 border-[#3CE6AC]"- : "text-neutral-500 hover:text-neutral-400"- }`}- >- Renders{renderQueue.jobs.length > 0 ? ` (${renderQueue.jobs.length})` : ""}- </button>- </div>-- {/* Tab content */}- {rightTab === "code" ? (- <div className="flex flex-1 min-h-0">- {/* File tree sidebar */}- {fileTree.length > 0 && (- <div className="w-[140px] flex-shrink-0 border-r border-neutral-800 overflow-y-auto">- <FileTree- files={fileTree}- activeFile={editingFile?.path ?? null}- onSelectFile={handleFileSelect}- />- </div>- )}- {/* Code editor or media preview */}- <div className="flex-1 overflow-hidden min-w-0">- {editingFile ? (- isMediaFile(editingFile.path) ? (- <MediaPreview projectId={projectId} filePath={editingFile.path} />- ) : (- <SourceEditor- content={editingFile.content ?? ""}- filePath={editingFile.path}- onChange={handleContentChange}- />- )- ) : (- <div className="flex items-center justify-center h-full text-neutral-600 text-sm">- Select a file to edit- </div>- )}- </div>- </div>- ) : (+ <>+ <div+ className="w-1 flex-shrink-0 bg-neutral-800 hover:bg-blue-500 cursor-col-resize transition-colors active:bg-blue-400"+ style={{ touchAction: "none" }}+ onPointerDown={(e) => handlePanelResizeStart("right", e)}+ onPointerMove={handlePanelResizeMove}+ onPointerUp={handlePanelResizeEnd}+ />+ <div+ className="flex flex-col border-l border-neutral-800 bg-neutral-900 flex-shrink-0"+ style={{ width: rightWidth }}+ ><RenderQueuejobs={renderQueue.jobs}onDelete={renderQueue.deleteRender}@@ -763,8 +697,8 @@ export function StudioApp() {onStartRender={(format) => renderQueue.startRender(30, "standard", format)}isRendering={renderQueue.isRendering}/>- )}- </div>+ </div>+ </>)}</div>diff --git a/packages/studio/src/components/editor/FileTree.tsx b/packages/studio/src/components/editor/FileTree.tsxindex b416c68c5e..31a0977eec 100644--- a/packages/studio/src/components/editor/FileTree.tsx+++ b/packages/studio/src/components/editor/FileTree.tsx@@ -1,13 +1,5 @@import { memo, useState, useCallback } from "react";-import {- FileCode,- Image,- Film,- Music,- File,- ChevronDown,- ChevronRight,-} from "../../icons/SystemIcons";+import { Film, Music, Image, ChevronDown, ChevronRight } from "../../icons/SystemIcons";interface FileTreeProps {files: string[];@@ -15,34 +7,65 @@ interface FileTreeProps {onSelectFile: (path: string) => void;}-const FILE_ICONS: Record<string, { icon: typeof File; color: string }> = {- html: { icon: FileCode, color: "#3B82F6" },- css: { icon: FileCode, color: "#A855F7" },- js: { icon: FileCode, color: "#F59E0B" },- ts: { icon: FileCode, color: "#3B82F6" },- json: { icon: File, color: "#22C55E" },- md: { icon: File, color: "#737373" },- png: { icon: Image, color: "#22C55E" },- jpg: { icon: Image, color: "#22C55E" },- jpeg: { icon: Image, color: "#22C55E" },- webp: { icon: Image, color: "#22C55E" },- gif: { icon: Image, color: "#22C55E" },- svg: { icon: Image, color: "#F97316" },- mp4: { icon: Film, color: "#A855F7" },- webm: { icon: Film, color: "#A855F7" },- mov: { icon: Film, color: "#A855F7" },- mp3: { icon: Music, color: "#F59E0B" },- wav: { icon: Music, color: "#F59E0B" },- ogg: { icon: Music, color: "#F59E0B" },- m4a: { icon: Music, color: "#F59E0B" },- woff: { icon: File, color: "#525252" },- woff2: { icon: File, color: "#525252" },- ttf: { icon: File, color: "#525252" },-};+/** VS Code–style language badge: colored rounded rect with a 2–3 letter label. */+function Badge({ label, bg, text = "#fff" }: { label: string; bg: string; text?: string }) {+ return (+ <span+ className="flex-shrink-0 inline-flex items-center justify-center rounded"+ style={{+ width: 16,+ height: 16,+ background: bg,+ color: text,+ fontSize: 7,+ fontWeight: 700,+ fontFamily: "monospace",+ letterSpacing: "-0.02em",+ lineHeight: 1,+ }}+ >+ {label}+ </span>+ );+}-function getFileIcon(path: string) {+/** Render a file-type icon for a given file path. */+function FileIcon({ path }: { path: string }) {const ext = path.split(".").pop()?.toLowerCase() ?? "";- return FILE_ICONS[ext] ?? { icon: File, color: "#737373" };+ // Language badges+ if (ext === "html") return <Badge label="HTML" bg="#E44D26" />;+ if (ext === "js" || ext === "mjs" || ext === "cjs")+ return <Badge label="JS" bg="#F0DB4F" text="#323330" />;+ if (ext === "ts" || ext === "mts") return <Badge label="TS" bg="#3178C6" />;+ if (ext === "css") return <Badge label="CSS" bg="#264DE4" />;+ if (ext === "json") return <Badge label="{}" bg="#1E7F34" />;+ if (ext === "md" || ext === "mdx") return <Badge label="MD" bg="#555" />;+ if (ext === "svg") return <Badge label="SVG" bg="#FF9900" />;+ if (ext === "wav" || ext === "mp3" || ext === "ogg" || ext === "m4a")+ return <Music size={13} style={{ color: "#3CE6AC" }} className="flex-shrink-0" />;+ if (ext === "mp4" || ext === "webm" || ext === "mov")+ return <Film size={13} style={{ color: "#A855F7" }} className="flex-shrink-0" />;+ if (ext === "png" || ext === "jpg" || ext === "jpeg" || ext === "webp" || ext === "gif")+ return <Image size={13} style={{ color: "#22C55E" }} className="flex-shrink-0" />;+ if (ext === "woff" || ext === "woff2" || ext === "ttf" || ext === "otf")+ return <Badge label="Aa" bg="#525252" />;+ if (ext === "txt") return <Badge label="TXT" bg="#4B5563" />;+ // Generic document+ return (+ <svg+ width="13"+ height="13"+ viewBox="0 0 24 24"+ fill="none"+ stroke="#6B7280"+ strokeWidth="1.5"+ strokeLinecap="round"+ className="flex-shrink-0"+ >+ <path d="M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z" />+ <polyline points="14 2 14 8 20 8" />+ </svg>+ );}interface TreeNode {@@ -160,7 +183,6 @@ function TreeFile({activeFile: string | null;onSelectFile: (path: string) => void;}) {- const { icon: Icon, color } = getFileIcon(node.name);const isActive = node.fullPath === activeFile;return (@@ -173,7 +195,7 @@ function TreeFile({}`}style={{ paddingLeft: `${8 + depth * 12 + 14}px` }}>- <Icon size={12} style={{ color }} className="flex-shrink-0" />+ <FileIcon path={node.name} /><span className="truncate">{node.name}</span></button>);@@ -194,9 +216,6 @@ export const FileTree = memo(function FileTree({ files, activeFile, onSelectFilereturn (<div className="flex flex-col h-full min-h-0">- <div className="px-2.5 py-1.5 border-b border-neutral-800 flex-shrink-0">- <span className="text-2xs font-medium text-neutral-500 uppercase tracking-caps">Files</span>- </div><div className="flex-1 overflow-y-auto py-1">{children.map((child) =>child.isFile && child.children.size === 0 ? (diff --git a/packages/studio/src/components/renders/RenderQueue.tsx b/packages/studio/src/components/renders/RenderQueue.tsxindex 522fbf6620..9a6e23a53f 100644--- a/packages/studio/src/components/renders/RenderQueue.tsx+++ b/packages/studio/src/components/renders/RenderQueue.tsx@@ -63,11 +63,8 @@ export const RenderQueue = memo(function RenderQueue({return (<div className="flex flex-col h-full">- {/* Header */}- <div className="flex items-center justify-between px-3 py-2 border-b border-neutral-800/50 flex-shrink-0">- <span className="text-[11px] font-medium text-neutral-500 uppercase tracking-wider">- Renders ({jobs.length})- </span>+ {/* Header — no title, already shown in header button */}+ <div className="flex items-center justify-end px-3 py-2 border-b border-neutral-800/50 flex-shrink-0"><div className="flex items-center gap-1.5">{completedCount > 0 && (<buttondiff --git a/packages/studio/src/components/sidebar/AssetsTab.tsx b/packages/studio/src/components/sidebar/AssetsTab.tsxindex ced161cad9..9c2169303c 100644--- a/packages/studio/src/components/sidebar/AssetsTab.tsx+++ b/packages/studio/src/components/sidebar/AssetsTab.tsx@@ -1,6 +1,4 @@import { memo, useState, useCallback, useRef } from "react";-import { ExpandOnHover } from "../ui/ExpandOnHover";-import { ExpandedVideoPreview } from "../ui/ExpandedVideoPreview";import { VideoFrameThumbnail } from "../ui/VideoFrameThumbnail";interface AssetsTabProps {@@ -14,6 +12,7 @@ const IMAGE_EXT = /\.(jpg|jpeg|png|gif|webp|svg)$/i;const VIDEO_EXT = /\.(mp4|webm|mov)$/i;const AUDIO_EXT = /\.(mp3|wav|ogg|m4a)$/i;+/** Inline thumbnail content — rendered inside the container div in AssetCard. */function AssetThumbnail({serveUrl,name,@@ -28,7 +27,7 @@ function AssetThumbnail({isAudio: boolean;}) {return (- <div className="w-16 h-10 rounded overflow-hidden bg-neutral-900 flex-shrink-0 relative">+ <>{isImage && (<imgsrc={serveUrl}@@ -42,7 +41,7 @@ function AssetThumbnail({)}{isVideo && <VideoFrameThumbnail src={serveUrl} />}{isAudio && (- <div className="w-full h-full flex items-center justify-center bg-neutral-900">+ <div className="w-full h-full flex items-center justify-center"><svgwidth="16"height="16"@@ -59,7 +58,7 @@ function AssetThumbnail({</div>)}{!isImage && !isVideo && !isAudio && (- <div className="w-full h-full flex items-center justify-center bg-neutral-900">+ <div className="w-full h-full flex items-center justify-center"><svgwidth="14"height="14"@@ -78,89 +77,7 @@ function AssetThumbnail({</svg></div>)}- </div>- );-}--function ExpandedAssetPreview({- serveUrl,- name,- asset,- isImage,- isVideo,- isAudio,- onCopy,-}: {- serveUrl: string;- name: string;- asset: string;- isImage: boolean;- isVideo: boolean;- isAudio: boolean;- onCopy: () => void;-}) {- if (isVideo) {- return (- <ExpandedVideoPreview- src={serveUrl}- name={name}- subtitle={asset}- action={- <button- onClick={(e) => {- e.stopPropagation();- onCopy();- }}- className="px-4 py-1.5 text-xs font-semibold text-[#09090B] bg-[#3CE6AC] rounded-lg hover:brightness-110 transition-colors flex-shrink-0"- >- Copy Path- </button>- }- />- );- }-- return (- <div className="w-full h-full bg-neutral-950 rounded-[16px] overflow-hidden flex flex-col">- <div className="flex-1 min-h-0 flex items-center justify-center bg-black p-4">- {isImage && (- <img src={serveUrl} alt={name} className="max-w-full max-h-full object-contain rounded" />- )}- {isAudio && (- <div className="flex flex-col items-center gap-4">- <svg- width="48"- height="48"- viewBox="0 0 24 24"- fill="none"- stroke="currentColor"- strokeWidth="1.5"- className="text-purple-400"- >- <path d="M9 18V5l12-2v13" strokeLinecap="round" strokeLinejoin="round" />- <circle cx="6" cy="18" r="3" />- <circle cx="18" cy="16" r="3" />- </svg>- <audio src={serveUrl} controls autoPlay className="w-64" />- </div>- )}- </div>- <div className="px-5 py-3 bg-neutral-900 border-t border-neutral-800/50 flex items-center justify-between flex-shrink-0">- <div>- <div className="text-sm font-medium text-neutral-200">{name}</div>- <div className="text-[10px] text-neutral-600 font-mono mt-0.5">{asset}</div>- </div>- <button- onClick={(e) => {- e.stopPropagation();- onCopy();- }}- className="px-4 py-1.5 text-xs font-semibold text-[#09090B] bg-[#3CE6AC] rounded-lg hover:brightness-110 transition-colors"- >- Copy Path- </button>- </div>- </div>+ </>);}@@ -175,28 +92,42 @@ function AssetCard({onCopy: (path: string) => void;isCopied: boolean;}) {+ const [hovered, setHovered] = useState(false);const name = asset.split("/").pop() ?? asset;const serveUrl = `/api/projects/${projectId}/preview/${asset}`;- const isImage = IMAGE_EXT.test(asset);const isVideo = VIDEO_EXT.test(asset);- const isAudio = AUDIO_EXT.test(asset);- const hasExpandablePreview = isImage || isVideo || isAudio;- const card = (+ return (<div+ onClick={() => onCopy(asset)}+ onPointerEnter={() => setHovered(true)}+ onPointerLeave={() => setHovered(false)}className={`w-full text-left px-2 py-1.5 flex items-center gap-2.5 transition-colors cursor-pointer ${isCopied? "bg-[#3CE6AC]/10 border-l-2 border-[#3CE6AC]": "border-l-2 border-transparent hover:bg-neutral-800/50"}`}>- <AssetThumbnail- serveUrl={serveUrl}- name={name}- isImage={isImage}- isVideo={isVideo}- isAudio={isAudio}- />+ <div className="w-16 h-10 rounded overflow-hidden bg-neutral-900 flex-shrink-0 relative">+ <AssetThumbnail+ serveUrl={serveUrl}+ name={name}+ isImage={IMAGE_EXT.test(asset)}+ isVideo={isVideo}+ isAudio={AUDIO_EXT.test(asset)}+ />+ {/* Inline video autoplay on hover — same pattern as renders */}+ {isVideo && hovered && (+ <video+ src={serveUrl}+ autoPlay+ muted+ loop+ playsInline+ className="absolute inset-0 w-full h-full object-contain"+ />+ )}+ </div><div className="min-w-0 flex-1"><span className="text-[11px] font-medium text-neutral-300 truncate block">{name}</span>{isCopied ? (@@ -207,43 +138,6 @@ function AssetCard({</div></div>);-- if (!hasExpandablePreview) {- return (- <button- type="button"- onClick={() => onCopy(asset)}- title="Click to copy path"- className="w-full"- >- {card}- </button>- );- }-- return (- <ExpandOnHover- expandedContent={(closeExpand) => (- <ExpandedAssetPreview- serveUrl={serveUrl}- name={name}- asset={asset}- isImage={isImage}- isVideo={isVideo}- isAudio={isAudio}- onCopy={() => {- closeExpand();- onCopy(asset);- }}- />- )}- onClick={() => onCopy(asset)}- expandScale={0.45}- delay={500}- >- {card}- </ExpandOnHover>- );}export const AssetsTab = memo(function AssetsTab({ projectId, assets, onImport }: AssetsTabProps) {diff --git a/packages/studio/src/components/sidebar/CompositionsTab.tsx b/packages/studio/src/components/sidebar/CompositionsTab.tsxindex fefc971955..6a2d66bbb3 100644--- a/packages/studio/src/components/sidebar/CompositionsTab.tsx+++ b/packages/studio/src/components/sidebar/CompositionsTab.tsx@@ -1,5 +1,4 @@-import { memo, useRef, useState, useCallback, useEffect } from "react";-import { ExpandOnHover } from "../ui/ExpandOnHover";+import { memo, useState } from "react";interface CompositionsTabProps {projectId: string;@@ -8,132 +7,6 @@ interface CompositionsTabProps {onSelect: (comp: string) => void;}-function ExpandedCompPreview({- previewUrl,- name,- comp,- onSelect,-}: {- previewUrl: string;- name: string;- comp: string;- onSelect: () => void;-}) {- const containerRef = useRef<HTMLDivElement>(null);- const iframeRef = useRef<HTMLIFrameElement>(null);- const [dims, setDims] = useState({ w: 1920, h: 1080 });- const [scale, setScale] = useState(1);-- const updateScale = useCallback(() => {- const el = containerRef.current;- if (!el) return;- const s = Math.min(el.clientWidth / dims.w, el.clientHeight / dims.h);- setScale(s);- }, [dims]);-- // eslint-disable-next-line no-restricted-syntax- useEffect(() => {- updateScale();- const el = containerRef.current;- if (!el) return;- const ro = new ResizeObserver(updateScale);- ro.observe(el);- return () => ro.disconnect();- }, [updateScale]);-- const handleLoad = useCallback(() => {- const iframe = iframeRef.current;- if (!iframe) return;- // Detect dimensions from composition- try {- const doc = iframe.contentDocument;- if (doc) {- const root = doc.querySelector("[data-composition-id]");- if (root) {- const w = parseInt(root.getAttribute("data-width") ?? "0", 10);- const h = parseInt(root.getAttribute("data-height") ?? "0", 10);- if (w > 0 && h > 0) setDims({ w, h });- }- }- } catch {- /* cross-origin */- }-- let attempts = 0;- const interval = setInterval(() => {- try {- const win = iframe.contentWindow as Window & {- __player?: { play: () => void; seek: (t: number) => void };- __timelines?: Record<string, { play: () => void; seek: (t: number) => void }>;- };- if (win?.__player) {- win.__player.seek(0.5);- win.__player.play();- clearInterval(interval);- return;- }- if (win?.__timelines) {- const keys = Object.keys(win.__timelines);- const tl = keys.length > 0 ? win.__timelines[keys[keys.length - 1]] : null;- if (tl) {- tl.seek(0.5);- tl.play();- clearInterval(interval);- }- }- } catch {- /* cross-origin */- }- if (++attempts > 15) clearInterval(interval);- }, 200);- }, []);-- const offsetX = containerRef.current- ? (containerRef.current.clientWidth - dims.w * scale) / 2- : 0;- const offsetY = containerRef.current- ? (containerRef.current.clientHeight - dims.h * scale) / 2- : 0;-- return (- <div className="w-full h-full bg-neutral-950 rounded-[16px] overflow-hidden flex flex-col">- <div ref={containerRef} className="flex-1 min-h-0 relative overflow-hidden bg-black">- <iframe- ref={iframeRef}- src={previewUrl}- sandbox="allow-scripts allow-same-origin"- onLoad={handleLoad}- className="absolute border-none"- style={{- left: Math.max(0, offsetX),- top: Math.max(0, offsetY),- width: dims.w,- height: dims.h,- transformOrigin: "0 0",- transform: `scale(${scale})`,- }}- tabIndex={-1}- />- </div>- <div className="px-5 py-3 bg-neutral-900 border-t border-neutral-800/50 flex items-center justify-between flex-shrink-0">- <div>- <div className="text-sm font-medium text-neutral-200">{name}</div>- <div className="text-[10px] text-neutral-600 font-mono mt-0.5">{comp}</div>- </div>- <button- onClick={(e) => {- e.stopPropagation();- onSelect();- }}- className="px-4 py-1.5 text-xs font-semibold text-[#09090B] bg-[#3CE6AC] rounded-lg hover:brightness-110 transition-colors"- >- Open- </button>- </div>- </div>- );-}-function CompCard({projectId,comp,@@ -145,28 +18,51 @@ function CompCard({isActive: boolean;onSelect: () => void;}) {+ const [hovered, setHovered] = useState(false);const name = comp.replace(/^compositions\//, "").replace(/\.html$/, "");const thumbnailUrl = `/api/projects/${projectId}/thumbnail/${comp}?t=2`;const previewUrl = `/api/projects/${projectId}/preview/comp/${comp}`;- const card = (+ return (<div+ onClick={onSelect}+ onPointerEnter={() => setHovered(true)}+ onPointerLeave={() => setHovered(false)}className={`w-full text-left px-2 py-1.5 flex items-center gap-2.5 transition-colors cursor-pointer ${isActive? "bg-[#3CE6AC]/10 border-l-2 border-[#3CE6AC]": "border-l-2 border-transparent hover:bg-neutral-800/50"}`}>- <div className="w-20 h-[45px] rounded overflow-hidden bg-neutral-900 flex-shrink-0">- <img- src={thumbnailUrl}- alt={name}- loading="lazy"- className="w-full h-full object-contain"- onError={(e) => {- (e.target as HTMLImageElement).style.display = "none";- }}- />+ <div className="w-20 h-[45px] rounded overflow-hidden bg-neutral-900 flex-shrink-0 relative">+ {/* Live iframe preview on hover */}+ {hovered && (+ <iframe+ src={previewUrl}+ sandbox="allow-scripts allow-same-origin"+ className="absolute inset-0 w-[1920px] h-[1080px] border-none pointer-events-none"+ style={{+ transformOrigin: "0 0",+ transform: `scale(${80 / 1920})`,+ }}+ tabIndex={-1}+ />+ )}+ {/* Static thumbnail — hidden while hovering */}+ <div+ className="absolute inset-0 transition-opacity duration-150"+ style={{ opacity: hovered ? 0 : 1 }}+ >+ <img+ src={thumbnailUrl}+ alt={name}+ loading="lazy"+ className="w-full h-full object-contain"+ onError={(e) => {+ (e.target as HTMLImageElement).style.display = "none";+ }}+ />+ </div></div><div className="min-w-0 flex-1"><span className="text-[11px] font-medium text-neutral-300 truncate block">{name}</span>@@ -174,27 +70,6 @@ function CompCard({</div></div>);-- return (- <ExpandOnHover- expandedContent={(closeExpand) => (- <ExpandedCompPreview- previewUrl={previewUrl}- name={name}- comp={comp}- onSelect={() => {- closeExpand();- onSelect();- }}- />- )}- onClick={onSelect}- expandScale={0.5}- delay={500}- >- {card}- </ExpandOnHover>- );}export const CompositionsTab = memo(function CompositionsTab({diff --git a/packages/studio/src/components/sidebar/LeftSidebar.tsx b/packages/studio/src/components/sidebar/LeftSidebar.tsxindex 9aedd18912..2632161fc5 100644--- a/packages/studio/src/components/sidebar/LeftSidebar.tsx+++ b/packages/studio/src/components/sidebar/LeftSidebar.tsx@@ -1,15 +1,18 @@-import { memo, useState, useCallback } from "react";+import { memo, useState, useCallback, type ReactNode } from "react";import { useMountEffect } from "../../hooks/useMountEffect";import { CompositionsTab } from "./CompositionsTab";import { AssetsTab } from "./AssetsTab";+import { FileTree } from "../editor/FileTree";-type SidebarTab = "compositions" | "assets";+type SidebarTab = "compositions" | "assets" | "code";const STORAGE_KEY = "hf-studio-sidebar-tab";function getPersistedTab(): SidebarTab {const stored = localStorage.getItem(STORAGE_KEY);- return stored === "assets" ? "assets" : "compositions";+ if (stored === "assets") return "assets";+ if (stored === "code") return "code";+ return "compositions";}interface LeftSidebarProps {@@ -20,6 +23,12 @@ interface LeftSidebarProps {activeComposition: string | null;onSelectComposition: (comp: string) => void;onImportFiles?: (files: FileList) => void;+ fileTree?: string[];+ editingFile?: { path: string; content: string | null } | null;+ onSelectFile?: (path: string) => void;+ codeChildren?: ReactNode;+ onLint?: () => void;+ linting?: boolean;}export const LeftSidebar = memo(function LeftSidebar({@@ -30,6 +39,12 @@ export const LeftSidebar = memo(function LeftSidebar({activeComposition,onSelectComposition,onImportFiles,+ fileTree: fileProp,+ editingFile,+ onSelectFile,+ codeChildren,+ onLint,+ linting,}: LeftSidebarProps) {const [tab, setTab] = useState<SidebarTab>(getPersistedTab);@@ -60,8 +75,19 @@ export const LeftSidebar = memo(function LeftSidebar({className="flex flex-col h-full bg-neutral-950 border-r border-neutral-800/50"style={{ width }}>- {/* Tabs */}+ {/* Tabs — Code first */}<div className="flex border-b border-neutral-800/50 flex-shrink-0">+ <button+ type="button"+ onClick={() => selectTab("code")}+ className={`flex-1 py-2 text-[11px] font-medium transition-colors ${+ tab === "code"+ ? "text-neutral-200 border-b-2 border-[#3CE6AC]"+ : "text-neutral-500 hover:text-neutral-400"+ }`}+ >+ Code+ </button><buttontype="button"onClick={() => selectTab("compositions")}@@ -87,16 +113,61 @@ export const LeftSidebar = memo(function LeftSidebar({</div>{/* Tab content */}- {tab === "compositions" ? (+ {tab === "compositions" && (<CompositionsTabprojectId={projectId}compositions={compositions}activeComposition={activeComposition}onSelect={onSelectComposition}/>- ) : (+ )}+ {tab === "assets" && (<AssetsTab projectId={projectId} assets={assets} onImport={onImportFiles} />)}+ {tab === "code" && (+ <div className="flex flex-1 min-h-0">+ {(fileProp?.length ?? 0) > 0 && (+ <div className="w-[140px] flex-shrink-0 border-r border-neutral-800 overflow-y-auto">+ <FileTree+ files={fileProp ?? []}+ activeFile={editingFile?.path ?? null}+ onSelectFile={onSelectFile ?? (() => {})}+ />+ </div>+ )}+ <div className="flex-1 overflow-hidden min-w-0">+ {codeChildren ?? (+ <div className="flex items-center justify-center h-full text-neutral-600 text-sm">+ Select a file to edit+ </div>+ )}+ </div>+ </div>+ )}++ {/* Lint button pinned at the bottom */}+ {onLint && (+ <div className="border-t border-neutral-800 p-2 flex-shrink-0">+ <button+ onClick={onLint}+ disabled={linting}+ className="w-full flex items-center justify-center gap-1.5 px-2 py-1.5 rounded-md text-[11px] font-medium text-neutral-500 hover:text-amber-300 hover:bg-neutral-800 transition-colors disabled:opacity-40"+ >+ <svg+ width="12"+ height="12"+ viewBox="0 0 24 24"+ fill="none"+ stroke="currentColor"+ strokeWidth="2"+ >+ <path d="M9 11l3 3L22 4" />+ <path d="M21 12v7a2 2 0 01-2 2H5a2 2 0 01-2-2V5a2 2 0 012-2h11" />+ </svg>+ {linting ? "Linting…" : "Lint"}+ </button>+ </div>+ )}</div>);});diff --git a/packages/studio/src/components/ui/ExpandOnHover.tsx b/packages/studio/src/components/ui/ExpandOnHover.tsxdeleted file mode 100644index 6d4583cdc4..0000000000--- a/packages/studio/src/components/ui/ExpandOnHover.tsx+++ /dev/null@@ -1,194 +0,0 @@-import React, { useState, useRef, useCallback, useEffect, type ReactNode } from "react";-import { motion, AnimatePresence } from "motion/react";--interface ExpandOnHoverProps {- children: ReactNode;- expandedContent?: ReactNode | ((close: () => void) => ReactNode);- expandScale?: number;- delay?: number;- className?: string;- onClick?: () => void;-}--export function ExpandOnHover({- children,- expandedContent,- expandScale = 0.75,- delay = 300,- className = "",- onClick,-}: ExpandOnHoverProps) {- const [isExpanded, setIsExpanded] = useState(false);- const [origin, setOrigin] = useState({ x: 0, y: 0, w: 0, h: 0 });- const containerRef = useRef<HTMLDivElement>(null);- const expandedRef = useRef<HTMLDivElement>(null);- const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);- const closeTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);-- const close = useCallback(() => {- if (timerRef.current) {- clearTimeout(timerRef.current);- timerRef.current = null;- }- if (closeTimerRef.current) {- clearTimeout(closeTimerRef.current);- closeTimerRef.current = null;- }- setIsExpanded(false);- }, []);-- const open = useCallback(() => {- if (!containerRef.current) return;- const rect = containerRef.current.getBoundingClientRect();- setOrigin({ x: rect.left, y: rect.top, w: rect.width, h: rect.height });- setIsExpanded(true);- }, []);-- const handleCardEnter = useCallback(() => {- if (isExpanded) return;- if (timerRef.current) clearTimeout(timerRef.current);- timerRef.current = setTimeout(open, delay);- }, [delay, open, isExpanded]);-- const handleCardLeave = useCallback(() => {- if (isExpanded) return;- if (timerRef.current) {- clearTimeout(timerRef.current);- timerRef.current = null;- }- }, [isExpanded]);-- // When expanded: track mouse position. If mouse stays outside the expanded- // card for 600ms continuously, close. Any re-entry resets the timer.- // Note: useEffect with [isExpanded] is acceptable — subscribes to window mousemove- // only while expanded, with cleanup on collapse. Can't be a mount effect.- // eslint-disable-next-line no-restricted-syntax- useEffect(() => {- if (!isExpanded) return;-- const CLOSE_DELAY = 600; // ms mouse must be outside to close- const START_DELAY = 400; // ms before we start checking (let animation settle)- let tracking = false;-- const startTracking = setTimeout(() => {- tracking = true;- }, START_DELAY);-- const handleMouseMove = (e: MouseEvent) => {- if (!tracking) return;- const el = expandedRef.current;- if (!el) return;-- const rect = el.getBoundingClientRect();- // Add generous padding so edge movements don't trigger close- const pad = 20;- const inside =- e.clientX >= rect.left - pad &&- e.clientX <= rect.right + pad &&- e.clientY >= rect.top - pad &&- e.clientY <= rect.bottom + pad;-- if (inside) {- // Mouse is inside — cancel any pending close- if (closeTimerRef.current) {- clearTimeout(closeTimerRef.current);- closeTimerRef.current = null;- }- } else {- // Mouse is outside — start close countdown if not already started- if (!closeTimerRef.current) {- closeTimerRef.current = setTimeout(() => {- setIsExpanded(false);- }, CLOSE_DELAY);- }- }- };-- window.addEventListener("mousemove", handleMouseMove);-- return () => {- clearTimeout(startTracking);- if (closeTimerRef.current) {- clearTimeout(closeTimerRef.current);- closeTimerRef.current = null;- }- window.removeEventListener("mousemove", handleMouseMove);- };- }, [isExpanded]);-- const vw = typeof window !== "undefined" ? window.innerWidth : 1440;- const vh = typeof window !== "undefined" ? window.innerHeight : 900;- const targetW = vw * expandScale;- const targetH = vh * expandScale;- const targetX = (vw - targetW) / 2;- const targetY = (vh - targetH) / 2;-- return (- <>- <div- ref={containerRef}- className={className}- onMouseEnter={handleCardEnter}- onMouseLeave={handleCardLeave}- onClick={onClick}- style={{ opacity: isExpanded ? 0 : 1, transition: "opacity 100ms ease-out" }}- >- {children}- </div>-- <AnimatePresence>- {isExpanded && (- <>- {/* Backdrop */}- <motion.div- initial={{ opacity: 0 }}- animate={{ opacity: 1 }}- exit={{ opacity: 0 }}- transition={{ duration: 0.15 }}- className="fixed inset-0 z-40 bg-black/60 backdrop-blur-sm"- onClick={close}- />- {/* Expanded card */}- <motion.div- ref={expandedRef}- initial={{- left: origin.x,- top: origin.y,- width: origin.w,- height: origin.h,- }}- animate={{- left: targetX,- top: targetY,- width: targetW,- height: targetH,- }}- exit={{- left: origin.x,- top: origin.y,- width: origin.w,- height: origin.h,- }}- transition={{- type: "spring",- stiffness: 280,- damping: 28,- mass: 0.8,- }}- className="fixed z-50 overflow-hidden rounded-[16px] shadow-dialog"- onClick={(e: React.MouseEvent) => {- e.stopPropagation();- close();- onClick?.();- }}- >- {typeof expandedContent === "function"- ? expandedContent(close)- : (expandedContent ?? children)}- </motion.div>- </>- )}- </AnimatePresence>- </>- );-}diff --git a/packages/studio/src/components/ui/ExpandedVideoPreview.tsx b/packages/studio/src/components/ui/ExpandedVideoPreview.tsxdeleted file mode 100644index 591fe5573a..0000000000--- a/packages/studio/src/components/ui/ExpandedVideoPreview.tsx+++ /dev/null@@ -1,37 +0,0 @@-import type { ReactNode } from "react";--interface ExpandedVideoPreviewProps {- src: string;- name: string;- subtitle: string;- action: ReactNode;-}--/**- * Shared expanded video preview used by AssetsTab (video assets) and- * the Renders panel. Autoplays the video muted+looped inside a full-bleed- * card. Caller provides the footer action slot (Copy Path, Open, etc.).- */-export function ExpandedVideoPreview({ src, name, subtitle, action }: ExpandedVideoPreviewProps) {- return (- <div className="w-full h-full bg-neutral-950 rounded-[16px] overflow-hidden flex flex-col">- <div className="flex-1 min-h-0 flex items-center justify-center bg-black p-4">- <video- src={src}- autoPlay- muted- loop- playsInline- className="max-w-full max-h-full object-contain rounded"- />- </div>- <div className="px-5 py-3 bg-neutral-900 border-t border-neutral-800/50 flex items-center justify-between flex-shrink-0">- <div className="min-w-0 flex-1 mr-4">- <div className="text-sm font-medium text-neutral-200 truncate">{name}</div>- <div className="text-[10px] text-neutral-600 font-mono mt-0.5 truncate">{subtitle}</div>- </div>- {action}- </div>- </div>- );-}