Skip to content

AI-powered video editor that turns raw footage and a creative brief into a polished ad using an ensemble of AI agents (Google Gemini + FFmpeg)

Python

Timeline editor: drag-and-drop clips, trim handles, zoom controls

poseljacob89be0b60a40f
diff --git a/src/web/studio/src/app/editor/[projectId]/page.tsx b/src/web/studio/src/app/editor/[projectId]/page.tsx
index 66cbe73..2975311 100644
--- a/src/web/studio/src/app/editor/[projectId]/page.tsx
+++ b/src/web/studio/src/app/editor/[projectId]/page.tsx
@@ -1,6 +1,6 @@
"use client";
-import { useEffect } from "react";
+import { useEffect, useCallback } from "react";
import { useParams } from "next/navigation";
import { useProjectStore } from "@/stores/projectStore";
import { useMediaStore } from "@/stores/mediaStore";
@@ -58,6 +58,47 @@ export default function EditorPage() {
// Stream pipeline progress.
useJobStream(currentJobId);
+ // Keyboard shortcuts
+ useEffect(() => {
+ const handler = (e: KeyboardEvent) => {
+ // Skip if user is typing in an input/textarea/select
+ const tag = (e.target as HTMLElement).tagName;
+ if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return;
+
+ const timeline = useTimelineStore.getState();
+ const entries = timeline.plan?.entries ?? [];
+
+ switch (e.key) {
+ case "Delete":
+ case "Backspace": {
+ if (timeline.selectedIndex !== null) {
+ e.preventDefault();
+ timeline.deleteEntry(timeline.selectedIndex);
+ }
+ break;
+ }
+ case "ArrowRight": {
+ e.preventDefault();
+ const next = timeline.selectedIndex === null ? 0 : Math.min(entries.length - 1, timeline.selectedIndex + 1);
+ timeline.selectEntry(next);
+ break;
+ }
+ case "ArrowLeft": {
+ e.preventDefault();
+ const prev = timeline.selectedIndex === null ? 0 : Math.max(0, timeline.selectedIndex - 1);
+ timeline.selectEntry(prev);
+ break;
+ }
+ case "Escape": {
+ timeline.selectEntry(null);
+ break;
+ }
+ }
+ };
+ window.addEventListener("keydown", handler);
+ return () => window.removeEventListener("keydown", handler);
+ }, []);
+
return (
<div className="h-full flex flex-col">
<Toolbar projectName={project?.name ?? "Loading..."} projectId={projectId} />
diff --git a/src/web/studio/src/components/MediaBrowser.tsx b/src/web/studio/src/components/MediaBrowser.tsx
index edc82f1..2045f67 100644
--- a/src/web/studio/src/components/MediaBrowser.tsx
+++ b/src/web/studio/src/components/MediaBrowser.tsx
@@ -2,13 +2,35 @@
import { useEffect, useRef, useCallback } from "react";
import { useMediaStore } from "@/stores/mediaStore";
+import { useTimelineStore } from "@/stores/timelineStore";
import { useUiStore } from "@/stores/uiStore";
import { toMediaUrl } from "@/lib/media";
-import { FolderOpen, Search, Loader2 } from "lucide-react";
+import type { ShotSearchResult } from "@/types/api";
+import type { EnrichedEditPlanEntry } from "@/types/api";
+import { FolderOpen, Search, Loader2, Plus } from "lucide-react";
+
+function shotToEntry(shot: ShotSearchResult): EnrichedEditPlanEntry {
+ return {
+ position: 0,
+ shot_id: shot.shot_id,
+ source_file: shot.source_file,
+ source_filename: shot.source_filename,
+ source_timestamp: shot.start_time,
+ display_label: shot.display_label,
+ start_trim: shot.start_time,
+ end_trim: shot.end_time,
+ duration: shot.duration,
+ text_overlay: null,
+ transition: null,
+ roll_type: shot.roll_type,
+ thumbnail_url: "",
+ };
+}
export function MediaBrowser() {
const { catalog, searchResults, query, filter, loading, fetchCatalog, searchFootage, setQuery, setFilter } =
useMediaStore();
+ const addEntry = useTimelineStore((s) => s.addEntry);
const setSourceMonitorSrc = useUiStore((s) => s.setSourceMonitorSrc);
const debounceRef = useRef<ReturnType<typeof setTimeout>>(undefined);
@@ -27,6 +49,14 @@ export function MediaBrowser() {
[setQuery, searchFootage],
);
+ const handleDragStart = useCallback(
+ (e: React.DragEvent, shot: ShotSearchResult) => {
+ e.dataTransfer.setData("application/json", JSON.stringify(shot));
+ e.dataTransfer.effectAllowed = "copy";
+ },
+ [],
+ );
+
const shots = query.trim() ? searchResults : catalog;
const filtered =
filter === "all" ? shots : shots.filter((s) => s.roll_type === filter);
@@ -88,18 +118,29 @@ export function MediaBrowser() {
)}
{filtered.map((shot, i) => (
- <button
+ <div
key={`${shot.shot_id}-${i}`}
- onClick={() => {
- setSourceMonitorSrc(toMediaUrl(shot.source_file));
- }}
- className="w-full text-left px-2 py-2 border-b border-border hover:bg-surface-hover transition-colors"
+ draggable
+ onDragStart={(e) => handleDragStart(e, shot)}
+ className="w-full text-left px-2 py-2 border-b border-border hover:bg-surface-hover transition-colors cursor-grab active:cursor-grabbing group"
>
<div className="flex items-center gap-1.5 mb-0.5">
<span className={`px-1.5 py-0.5 rounded text-[9px] font-medium ${rollBadge(shot.roll_type)}`}>
{shot.roll_type}
</span>
- <span className="text-xs font-medium truncate">{shot.display_label}</span>
+ <span
+ className="text-xs font-medium truncate flex-1 cursor-pointer hover:text-accent"
+ onClick={() => setSourceMonitorSrc(toMediaUrl(shot.source_file))}
+ >
+ {shot.display_label}
+ </span>
+ <button
+ onClick={() => addEntry(shotToEntry(shot))}
+ className="opacity-0 group-hover:opacity-100 p-0.5 text-muted hover:text-accent transition-all"
+ title="Add to timeline"
+ >
+ <Plus className="w-3.5 h-3.5" />
+ </button>
</div>
<p className="text-[10px] text-muted truncate">
{shot.duration.toFixed(1)}s
@@ -110,7 +151,7 @@ export function MediaBrowser() {
&ldquo;{shot.transcript.slice(0, 80)}&rdquo;
</p>
)}
- </button>
+ </div>
))}
{!loading && filtered.length === 0 && (
diff --git a/src/web/studio/src/components/inspector/ClipPanel.tsx b/src/web/studio/src/components/inspector/ClipPanel.tsx
index b29bbb9..0d893dc 100644
--- a/src/web/studio/src/components/inspector/ClipPanel.tsx
+++ b/src/web/studio/src/components/inspector/ClipPanel.tsx
@@ -2,7 +2,7 @@
import { useTimelineStore } from "@/stores/timelineStore";
import type { EnrichedEditPlanEntry } from "@/types/api";
-import { Scissors, Trash2, Film } from "lucide-react";
+import { Scissors, Trash2, Film, Clock } from "lucide-react";
interface ClipPanelProps {
entry: EnrichedEditPlanEntry;
@@ -17,6 +17,8 @@ export function ClipPanel({ entry, index, jobId }: ClipPanelProps) {
const isDirty = useTimelineStore((s) => s.isDirty);
const duration = entry.end_trim - entry.start_trim;
+ // Max range for the trim sliders (use source clip end or a generous bound)
+ const maxTime = Math.max(entry.end_trim + 10, entry.duration + entry.source_timestamp);
return (
<div className="p-3 space-y-4 text-xs">
@@ -35,46 +37,124 @@ export function ClipPanel({ entry, index, jobId }: ClipPanelProps) {
>
{entry.roll_type}
</span>
- <span className="text-muted">{duration.toFixed(1)}s</span>
+ <div className="flex items-center gap-1 text-muted">
+ <Clock className="w-3 h-3" />
+ <span>{duration.toFixed(1)}s</span>
+ </div>
</div>
<p className="text-muted text-[10px] break-all">{entry.source_filename}</p>
</div>
- {/* Trim controls */}
+ {/* Trim controls with visual range */}
<div>
- <div className="flex items-center gap-1 mb-2 text-muted">
+ <div className="flex items-center gap-1 mb-3 text-muted">
<Scissors className="w-3 h-3" />
<span className="font-medium">Trim</span>
</div>
+ {/* Visual range bar */}
+ <div className="mb-3">
+ <div className="h-6 bg-surface rounded border border-border relative overflow-hidden">
+ {/* Active region */}
+ <div
+ className={`absolute top-0 bottom-0 ${
+ entry.roll_type === "a-roll"
+ ? "bg-blue-500/30"
+ : entry.roll_type === "b-roll"
+ ? "bg-emerald-500/30"
+ : "bg-slate-500/30"
+ }`}
+ style={{
+ left: `${(entry.start_trim / maxTime) * 100}%`,
+ width: `${(duration / maxTime) * 100}%`,
+ }}
+ />
+ {/* Markers */}
+ <div
+ className="absolute top-0 bottom-0 w-0.5 bg-accent"
+ style={{ left: `${(entry.start_trim / maxTime) * 100}%` }}
+ />
+ <div
+ className="absolute top-0 bottom-0 w-0.5 bg-accent"
+ style={{ left: `${(entry.end_trim / maxTime) * 100}%` }}
+ />
+ {/* Labels inside */}
+ <div className="absolute inset-0 flex items-center justify-center">
+ <span className="text-[9px] text-foreground/60">
+ {entry.start_trim.toFixed(1)}s -- {entry.end_trim.toFixed(1)}s
+ </span>
+ </div>
+ </div>
+ </div>
+
+ {/* In point */}
<label className="block mb-2">
- <span className="text-muted">Start (s)</span>
+ <div className="flex items-center justify-between mb-1">
+ <span className="text-muted">In point</span>
+ <span className="text-muted tabular-nums">{entry.start_trim.toFixed(1)}s</span>
+ </div>
<input
- type="number"
+ type="range"
step={0.1}
min={0}
max={entry.end_trim - 0.1}
value={entry.start_trim}
onChange={(e) =>
- updateEntry(index, { start_trim: parseFloat(e.target.value) || 0 })
+ updateEntry(index, { start_trim: parseFloat(e.target.value) })
}
- className="w-full mt-0.5 px-2 py-1 rounded border border-border bg-surface text-foreground focus:outline-none focus:border-accent"
+ className="w-full h-1.5 accent-accent"
/>
</label>
+ {/* Out point */}
<label className="block mb-2">
- <span className="text-muted">End (s)</span>
+ <div className="flex items-center justify-between mb-1">
+ <span className="text-muted">Out point</span>
+ <span className="text-muted tabular-nums">{entry.end_trim.toFixed(1)}s</span>
+ </div>
<input
- type="number"
+ type="range"
step={0.1}
min={entry.start_trim + 0.1}
+ max={maxTime}
value={entry.end_trim}
onChange={(e) =>
- updateEntry(index, { end_trim: parseFloat(e.target.value) || 0 })
+ updateEntry(index, { end_trim: parseFloat(e.target.value) })
}
- className="w-full mt-0.5 px-2 py-1 rounded border border-border bg-surface text-foreground focus:outline-none focus:border-accent"
+ className="w-full h-1.5 accent-accent"
/>
</label>
+
+ {/* Fine-tune number inputs */}
+ <div className="flex gap-2">
+ <label className="flex-1">
+ <span className="text-[10px] text-muted">In (s)</span>
+ <input
+ type="number"
+ step={0.1}
+ min={0}
+ max={entry.end_trim - 0.1}
+ value={entry.start_trim}
+ onChange={(e) =>
+ updateEntry(index, { start_trim: parseFloat(e.target.value) || 0 })
+ }
+ className="w-full mt-0.5 px-2 py-1 rounded border border-border bg-surface text-foreground text-[11px] tabular-nums focus:outline-none focus:border-accent"
+ />
+ </label>
+ <label className="flex-1">
+ <span className="text-[10px] text-muted">Out (s)</span>
+ <input
+ type="number"
+ step={0.1}
+ min={entry.start_trim + 0.1}
+ value={entry.end_trim}
+ onChange={(e) =>
+ updateEntry(index, { end_trim: parseFloat(e.target.value) || 0 })
+ }
+ className="w-full mt-0.5 px-2 py-1 rounded border border-border bg-surface text-foreground text-[11px] tabular-nums focus:outline-none focus:border-accent"
+ />
+ </label>
+ </div>
</div>
{/* Text overlay */}
diff --git a/src/web/studio/src/components/timeline/Timeline.tsx b/src/web/studio/src/components/timeline/Timeline.tsx
index 3cd3ace..d06ef2e 100644
--- a/src/web/studio/src/components/timeline/Timeline.tsx
+++ b/src/web/studio/src/components/timeline/Timeline.tsx
@@ -1,6 +1,6 @@
"use client";
-import { useCallback } from "react";
+import { useCallback, useRef, useState, useEffect } from "react";
import {
DndContext,
closestCenter,
@@ -8,6 +8,7 @@ import {
useSensor,
useSensors,
type DragEndEvent,
+ DragOverlay,
} from "@dnd-kit/core";
import {
SortableContext,
@@ -17,17 +18,27 @@ import { useTimelineStore } from "@/stores/timelineStore";
import { useUiStore } from "@/stores/uiStore";
import { TimelineClip } from "./TimelineClip";
import { toMediaUrl } from "@/lib/media";
-import { Layers } from "lucide-react";
+import { Layers, ZoomIn, ZoomOut, Plus } from "lucide-react";
+import type { EnrichedEditPlanEntry } from "@/types/api";
+
+const MIN_PX_PER_SEC = 30;
+const MAX_PX_PER_SEC = 300;
+const DEFAULT_PX_PER_SEC = 80;
export function Timeline() {
const plan = useTimelineStore((s) => s.plan);
const selectedIndex = useTimelineStore((s) => s.selectedIndex);
const selectEntry = useTimelineStore((s) => s.selectEntry);
const reorderEntries = useTimelineStore((s) => s.reorderEntries);
+ const addEntry = useTimelineStore((s) => s.addEntry);
const setSourceMonitorSrc = useUiStore((s) => s.setSourceMonitorSrc);
+ const [pxPerSecond, setPxPerSecond] = useState(DEFAULT_PX_PER_SEC);
+ const [dragOverTimeline, setDragOverTimeline] = useState(false);
+ const trackRef = useRef<HTMLDivElement>(null);
+
const sensors = useSensors(
- useSensor(PointerSensor, { activationConstraint: { distance: 5 } }),
+ useSensor(PointerSensor, { activationConstraint: { distance: 8 } }),
);
const handleDragEnd = useCallback(
@@ -42,51 +53,159 @@ export function Timeline() {
[reorderEntries],
);
+ // Handle drops from media browser (via native drag/drop)
+ const handleExternalDrop = useCallback(
+ (e: React.DragEvent) => {
+ e.preventDefault();
+ setDragOverTimeline(false);
+ const raw = e.dataTransfer.getData("application/json");
+ if (!raw) return;
+ try {
+ const shot = JSON.parse(raw) as {
+ shot_id: string;
+ source_file: string;
+ source_filename: string;
+ start_time: number;
+ end_time: number;
+ duration: number;
+ description: string;
+ roll_type: string;
+ display_label: string;
+ };
+ const entry: EnrichedEditPlanEntry = {
+ position: 0,
+ shot_id: shot.shot_id,
+ source_file: shot.source_file,
+ source_filename: shot.source_filename,
+ source_timestamp: shot.start_time,
+ display_label: shot.display_label,
+ start_trim: shot.start_time,
+ end_trim: shot.end_time,
+ duration: shot.duration,
+ text_overlay: null,
+ transition: null,
+ roll_type: shot.roll_type,
+ thumbnail_url: "",
+ };
+ addEntry(entry);
+ } catch {
+ // ignore malformed data
+ }
+ },
+ [addEntry],
+ );
+
+ const handleDragOver = useCallback((e: React.DragEvent) => {
+ e.preventDefault();
+ e.dataTransfer.dropEffect = "copy";
+ setDragOverTimeline(true);
+ }, []);
+
+ const handleDragLeave = useCallback(() => {
+ setDragOverTimeline(false);
+ }, []);
+
+ // Zoom with scroll wheel (Cmd/Ctrl + scroll)
+ useEffect(() => {
+ const el = trackRef.current;
+ if (!el) return;
+ const handler = (e: WheelEvent) => {
+ if (e.metaKey || e.ctrlKey) {
+ e.preventDefault();
+ setPxPerSecond((prev) =>
+ Math.min(MAX_PX_PER_SEC, Math.max(MIN_PX_PER_SEC, prev - e.deltaY * 0.5)),
+ );
+ }
+ };
+ el.addEventListener("wheel", handler, { passive: false });
+ return () => el.removeEventListener("wheel", handler);
+ }, []);
+
const entries = plan?.entries ?? [];
+ const totalDuration = plan?.total_duration ?? 0;
+ const rulerSeconds = Math.ceil(totalDuration) + 2;
+ // Tick interval adapts to zoom level
+ const tickInterval = pxPerSecond >= 100 ? 1 : pxPerSecond >= 50 ? 2 : 5;
return (
<div className="h-full flex flex-col bg-background">
+ {/* Header */}
<div className="px-3 py-1.5 text-xs font-medium text-muted border-b border-border flex items-center gap-1.5">
<Layers className="w-3 h-3" />
Timeline
{plan && (
- <span className="ml-auto text-[10px]">
- {entries.length} clips -- {plan.total_duration.toFixed(1)}s
+ <span className="ml-2 text-[10px]">
+ {entries.length} clips -- {totalDuration.toFixed(1)}s
</span>
)}
+
+ {/* Zoom controls */}
+ <div className="ml-auto flex items-center gap-1">
+ <button
+ onClick={() => setPxPerSecond((p) => Math.max(MIN_PX_PER_SEC, p - 20))}
+ className="p-0.5 hover:text-foreground transition-colors"
+ title="Zoom out"
+ >
+ <ZoomOut className="w-3.5 h-3.5" />
+ </button>
+ <div className="w-16 h-1 bg-border rounded-full relative">
+ <div
+ className="absolute top-0 left-0 h-full bg-accent/60 rounded-full"
+ style={{ width: `${((pxPerSecond - MIN_PX_PER_SEC) / (MAX_PX_PER_SEC - MIN_PX_PER_SEC)) * 100}%` }}
+ />
+ </div>
+ <button
+ onClick={() => setPxPerSecond((p) => Math.min(MAX_PX_PER_SEC, p + 20))}
+ className="p-0.5 hover:text-foreground transition-colors"
+ title="Zoom in"
+ >
+ <ZoomIn className="w-3.5 h-3.5" />
+ </button>
+ </div>
</div>
{/* Ruler */}
- {plan && entries.length > 0 && (
- <div className="h-5 border-b border-border bg-surface flex items-end px-2">
- {Array.from({ length: Math.ceil(plan.total_duration) + 1 }, (_, i) => {
- const pct = (i / plan.total_duration) * 100;
+ {entries.length > 0 && (
+ <div className="h-6 border-b border-border bg-surface relative overflow-hidden shrink-0" style={{ minWidth: `${rulerSeconds * pxPerSecond}px` }}>
+ {Array.from({ length: Math.floor(rulerSeconds / tickInterval) + 1 }, (_, i) => {
+ const sec = i * tickInterval;
+ const left = sec * pxPerSecond;
+ const isMajor = sec % 5 === 0;
return (
- <div
- key={i}
- className="absolute text-[8px] text-muted"
- style={{ left: `${pct}%` }}
- >
- {i % 5 === 0 ? `${i}s` : ""}
+ <div key={sec} className="absolute top-0 bottom-0" style={{ left: `${left}px` }}>
+ <div className={`absolute bottom-0 w-px ${isMajor ? "h-3 bg-muted/60" : "h-1.5 bg-muted/30"}`} />
+ {isMajor && (
+ <span className="absolute top-0.5 left-1 text-[9px] text-muted whitespace-nowrap">
+ {sec}s
+ </span>
+ )}
</div>
);
})}
</div>
)}
- {/* Track */}
- <div className="flex-1 overflow-x-auto overflow-y-hidden">
+ {/* Track area */}
+ <div
+ ref={trackRef}
+ className={`flex-1 overflow-x-auto overflow-y-hidden transition-colors ${
+ dragOverTimeline ? "bg-accent/5 ring-1 ring-inset ring-accent/30" : ""
+ }`}
+ onDrop={handleExternalDrop}
+ onDragOver={handleDragOver}
+ onDragLeave={handleDragLeave}
+ >
{entries.length > 0 ? (
<DndContext sensors={sensors} collisionDetection={closestCenter} onDragEnd={handleDragEnd}>
<SortableContext items={entries.map((_, i) => i)} strategy={horizontalListSortingStrategy}>
- <div className="flex items-stretch h-full p-2 gap-1 min-w-max">
+ <div className="flex items-stretch h-full p-2 gap-0.5 min-w-max">
{entries.map((entry, i) => (
<TimelineClip
- key={`${entry.shot_id}-${entry.position}`}
+ key={`${entry.shot_id}-${i}`}
entry={entry}
index={i}
isSelected={selectedIndex === i}
- totalDuration={plan!.total_duration}
+ pxPerSecond={pxPerSecond}
onClick={() => {
selectEntry(i);
if (entry.source_file) {
@@ -100,9 +219,18 @@ export function Timeline() {
</DndContext>
) : (
<div className="h-full flex items-center justify-center">
- <p className="text-muted text-xs">
- {plan ? "Empty timeline" : "Run a pipeline to populate the timeline"}
- </p>
+ {dragOverTimeline ? (
+ <div className="flex flex-col items-center gap-2 text-accent">
+ <Plus className="w-6 h-6" />
+ <p className="text-xs font-medium">Drop clip here</p>
+ </div>
+ ) : (
+ <p className="text-muted text-xs">
+ {plan
+ ? "Drag clips from the media browser to add them"
+ : "Run a pipeline to populate the timeline"}
+ </p>
+ )}
</div>
)}
</div>
diff --git a/src/web/studio/src/components/timeline/TimelineClip.tsx b/src/web/studio/src/components/timeline/TimelineClip.tsx
index e4ab6f1..60572fb 100644
--- a/src/web/studio/src/components/timeline/TimelineClip.tsx
+++ b/src/web/studio/src/components/timeline/TimelineClip.tsx
@@ -1,86 +1,164 @@
"use client";
+import { useCallback, useRef } from "react";
import { useSortable } from "@dnd-kit/sortable";
import { CSS } from "@dnd-kit/utilities";
import type { EnrichedEditPlanEntry } from "@/types/api";
+import { useTimelineStore } from "@/stores/timelineStore";
import { Type } from "lucide-react";
interface TimelineClipProps {
entry: EnrichedEditPlanEntry;
index: number;
isSelected: boolean;
- totalDuration: number;
+ pxPerSecond: number;
onClick: () => void;
}
-export function TimelineClip({ entry, index, isSelected, totalDuration, onClick }: TimelineClipProps) {
+export function TimelineClip({ entry, index, isSelected, pxPerSecond, onClick }: TimelineClipProps) {
const { attributes, listeners, setNodeRef, transform, transition, isDragging } =
useSortable({ id: index });
+ const updateEntry = useTimelineStore((s) => s.updateEntry);
+
+ const dragRef = useRef<{
+ side: "left" | "right";
+ startX: number;
+ origStart: number;
+ origEnd: number;
+ } | null>(null);
+
+ const duration = entry.end_trim - entry.start_trim;
+ const widthPx = Math.max(40, duration * pxPerSecond);
+
+ const handleTrimStart = useCallback(
+ (side: "left" | "right", e: React.PointerEvent) => {
+ e.stopPropagation();
+ e.preventDefault();
+ const el = e.currentTarget as HTMLElement;
+ el.setPointerCapture(e.pointerId);
+ dragRef.current = {
+ side,
+ startX: e.clientX,
+ origStart: entry.start_trim,
+ origEnd: entry.end_trim,
+ };
+ },
+ [entry.start_trim, entry.end_trim],
+ );
+
+ const handleTrimMove = useCallback(
+ (e: React.PointerEvent) => {
+ if (!dragRef.current) return;
+ const dx = e.clientX - dragRef.current.startX;
+ const dt = dx / pxPerSecond;
+
+ if (dragRef.current.side === "left") {
+ const newStart = Math.max(0, Math.min(dragRef.current.origEnd - 0.1, dragRef.current.origStart + dt));
+ updateEntry(index, { start_trim: Math.round(newStart * 10) / 10 });
+ } else {
+ const newEnd = Math.max(dragRef.current.origStart + 0.1, dragRef.current.origEnd + dt);
+ updateEntry(index, { end_trim: Math.round(newEnd * 10) / 10 });
+ }
+ },
+ [index, pxPerSecond, updateEntry],
+ );
+
+ const handleTrimEnd = useCallback(() => {
+ dragRef.current = null;
+ }, []);
const style = {
transform: CSS.Transform.toString(transform),
transition,
- opacity: isDragging ? 0.5 : 1,
+ opacity: isDragging ? 0.4 : 1,
+ width: `${widthPx}px`,
};
- const duration = entry.end_trim - entry.start_trim;
- // Min width 60px, scale proportionally.
- const widthPx = Math.max(60, (duration / Math.max(totalDuration, 1)) * 800);
-
- const borderColor = () => {
- if (isSelected) return "border-accent";
- switch (entry.roll_type) {
- case "a-roll":
- return "border-blue-500/60";
- case "b-roll":
- return "border-emerald-500/60";
- default:
- return "border-slate-600";
- }
- };
+ const borderColor = isSelected
+ ? "border-accent"
+ : entry.roll_type === "a-roll"
+ ? "border-blue-500/60"
+ : entry.roll_type === "b-roll"
+ ? "border-emerald-500/60"
+ : "border-slate-600";
- const bgColor = () => {
- switch (entry.roll_type) {
- case "a-roll":
- return "bg-blue-500/10";
- case "b-roll":
- return "bg-emerald-500/10";
- default:
- return "bg-slate-500/10";
- }
- };
+ const bgColor =
+ entry.roll_type === "a-roll"
+ ? "bg-blue-500/15"
+ : entry.roll_type === "b-roll"
+ ? "bg-emerald-500/15"
+ : "bg-slate-500/15";
+
+ const fillColor =
+ entry.roll_type === "a-roll"
+ ? "bg-blue-500/30"
+ : entry.roll_type === "b-roll"
+ ? "bg-emerald-500/30"
+ : "bg-slate-500/30";
return (
<div
ref={setNodeRef}
- style={{ ...style, width: `${widthPx}px` }}
- {...attributes}
- {...listeners}
- onClick={onClick}
- className={`shrink-0 rounded border-2 ${borderColor()} ${bgColor()} cursor-pointer hover:brightness-110 transition-all flex flex-col justify-between p-1.5 select-none`}
+ style={style}
+ className={`group relative shrink-0 rounded border-2 ${borderColor} ${bgColor} select-none flex flex-col justify-between overflow-hidden ${
+ isDragging ? "z-50 shadow-lg" : ""
+ }`}
>
- <div>
- <div className="text-[10px] font-medium truncate">{entry.display_label}</div>
- <div className="text-[9px] text-muted">{duration.toFixed(1)}s</div>
+ {/* Left trim handle */}
+ <div
+ className="absolute left-0 top-0 bottom-0 w-2 cursor-col-resize z-10 hover:bg-white/20 active:bg-white/30 transition-colors"
+ onPointerDown={(e) => handleTrimStart("left", e)}
+ onPointerMove={handleTrimMove}
+ onPointerUp={handleTrimEnd}
+ onPointerCancel={handleTrimEnd}
+ >
+ <div className="absolute left-0.5 top-1/2 -translate-y-1/2 w-0.5 h-6 bg-white/40 rounded-full opacity-0 group-hover:opacity-100 transition-opacity" />
</div>
- {entry.text_overlay && (
- <div className="flex items-center gap-0.5 mt-1">
- <Type className="w-2.5 h-2.5 text-amber-400" />
- <span className="text-[8px] text-amber-400 truncate">{entry.text_overlay}</span>
+ {/* Main clickable/draggable area */}
+ <div
+ {...attributes}
+ {...listeners}
+ onClick={onClick}
+ className="flex-1 flex flex-col justify-between px-3 py-1.5 cursor-grab active:cursor-grabbing"
+ >
+ {/* Top fill bar showing proportional fill */}
+ <div className={`absolute top-0 left-0 h-1 ${fillColor}`} style={{ width: "100%" }} />
+
+ <div className="mt-1">
+ <div className="text-[11px] font-medium truncate">{entry.display_label}</div>
+ <div className="text-[10px] text-muted">{duration.toFixed(1)}s</div>
</div>
- )}
-
- <div className="mt-auto">
- <span className={`inline-block px-1 py-0.5 rounded text-[8px] font-medium ${
- entry.roll_type === "a-roll"
- ? "bg-blue-500/20 text-blue-400"
- : entry.roll_type === "b-roll"
- ? "bg-emerald-500/20 text-emerald-400"
- : "bg-slate-500/20 text-slate-400"
- }`}>
- {entry.roll_type}
- </span>
+
+ {entry.text_overlay && (
+ <div className="flex items-center gap-0.5 mt-1">
+ <Type className="w-2.5 h-2.5 text-amber-400" />
+ <span className="text-[9px] text-amber-400 truncate">{entry.text_overlay}</span>
+ </div>
+ )}
+
+ <div className="mt-auto pt-1">
+ <span className={`inline-block px-1 py-0.5 rounded text-[8px] font-medium ${
+ entry.roll_type === "a-roll"
+ ? "bg-blue-500/20 text-blue-400"
+ : entry.roll_type === "b-roll"
+ ? "bg-emerald-500/20 text-emerald-400"
+ : "bg-slate-500/20 text-slate-400"
+ }`}>
+ {entry.roll_type}
+ </span>
+ </div>
+ </div>
+
+ {/* Right trim handle */}
+ <div
+ className="absolute right-0 top-0 bottom-0 w-2 cursor-col-resize z-10 hover:bg-white/20 active:bg-white/30 transition-colors"
+ onPointerDown={(e) => handleTrimStart("right", e)}
+ onPointerMove={handleTrimMove}
+ onPointerUp={handleTrimEnd}
+ onPointerCancel={handleTrimEnd}
+ >
+ <div className="absolute right-0.5 top-1/2 -translate-y-1/2 w-0.5 h-6 bg-white/40 rounded-full opacity-0 group-hover:opacity-100 transition-opacity" />
</div>
</div>
);
diff --git a/src/web/studio/src/stores/timelineStore.ts b/src/web/studio/src/stores/timelineStore.ts
index 03ac451..ce3aa45 100644
--- a/src/web/studio/src/stores/timelineStore.ts
+++ b/src/web/studio/src/stores/timelineStore.ts
@@ -16,6 +16,7 @@ interface TimelineState {
updateEntry: (index: number, patch: Partial<EnrichedEditPlanEntry>) => void;
reorderEntries: (fromIndex: number, toIndex: number) => void;
deleteEntry: (index: number) => void;
+ addEntry: (entry: EnrichedEditPlanEntry, atIndex?: number) => void;
savePlan: (jobId: string) => Promise<void>;
setPlan: (plan: EnrichedEditPlan | null) => void;
reset: () => void;
@@ -76,6 +77,19 @@ export const useTimelineStore = create<TimelineState>((set, get) => ({
});
},
+ addEntry: (entry, atIndex) => {
+ const { plan } = get();
+ const entries = plan ? [...plan.entries] : [];
+ const insertAt = atIndex ?? entries.length;
+ entries.splice(insertAt, 0, entry);
+ entries.forEach((e, i) => (e.position = i));
+ const totalDuration = entries.reduce((sum, e) => sum + (e.end_trim - e.start_trim), 0);
+ const newPlan: EnrichedEditPlan = plan
+ ? { ...plan, entries, entry_count: entries.length, total_duration: totalDuration }
+ : { job_id: "", entries, entry_count: entries.length, total_duration: totalDuration };
+ set({ plan: newPlan, isDirty: true, selectedIndex: insertAt });
+ },
+
savePlan: async (jobId) => {
const { plan } = get();
if (!plan) return;