AI media harness for planning, generating, and editing locally
TypeScript
Simplify Motion inspector and reference actions
Bitti97ae6742e896
diff --git a/src/components/workspace/MotionInspector.test.tsx b/src/components/workspace/MotionInspector.test.tsxindex 5808b6e..28a8b1c 100644--- a/src/components/workspace/MotionInspector.test.tsx+++ b/src/components/workspace/MotionInspector.test.tsx@@ -1,22 +1,25 @@// @vitest-environment jsdomimport "@testing-library/jest-dom/vitest";-import { afterEach, expect, it, vi } from "vitest";+import { afterEach, expect, it } from "vitest";import { cleanup, fireEvent, render, screen } from "@testing-library/react";import { useState } from "react";import { MotionInspector } from "./MotionInspector";import { emptyMotion, motionNodeSchema, type Motion } from "../../lib/motion";-afterEach(cleanup);+afterEach(() => { cleanup(); localStorage.clear(); });it("edits named elements and parameters without changing source until Apply", () => {let latest: Motion;- const bake = vi.fn();function Harness() {const [motion, change] = useState(() => ({ ...emptyMotion(), nodes: [motionNodeSchema.parse({ id: "title", name: "Title", kind: "text", text: "Hello" })],parameters: [{ id: "speed", label: "Speed", type: "number" as const, value: 2, min: 0, max: 10 }] } as Motion));latest = motion;- return <MotionInspector motion={motion} selectedId="title" onSelect={() => {}} onChange={change} onRenderReference={bake} />;+ return <MotionInspector motion={motion} selectedId="title" onChange={change} />;}render(<Harness />);+ expect(screen.queryByRole("button", { name: "Title" })).not.toBeInTheDocument();+ expect(screen.queryByRole("button", { name: "Render as reference video" })).not.toBeInTheDocument();+ expect(screen.getByRole("button", { name: "Parameters" }).compareDocumentPosition(screen.getByRole("button", { name: "Elements Title" })) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();+ expect(screen.getByRole("button", { name: "JavaScript" })).toHaveAttribute("aria-expanded", "false");fireEvent.change(screen.getByLabelText("Element text"), { target: { value: "Edited" } });fireEvent.change(screen.getByLabelText("Element Offset X"), { target: { value: "25" } });fireEvent.change(screen.getByLabelText("Speed"), { target: { value: "4" } });@@ -24,10 +27,9 @@ it("edits named elements and parameters without changing source until Apply", ()expect(latest!.nodes[0].text).toBe("Hello");expect(latest!.parameters[0].value).toBe(4);const source = "export function update({nodes,time}) { nodes[0].position[0] += time; }";+ fireEvent.click(screen.getByRole("button", { name: "JavaScript" }));fireEvent.change(screen.getByLabelText("Motion JavaScript source"), { target: { value: source } });expect(latest!.source).not.toBe(source);fireEvent.click(screen.getByRole("button", { name: "Apply source" }));expect(latest!.source).toBe(source);- fireEvent.click(screen.getByRole("button", { name: "Render as reference video" }));- expect(bake).toHaveBeenCalledOnce();});diff --git a/src/components/workspace/MotionInspector.tsx b/src/components/workspace/MotionInspector.tsxindex 9e7d63e..e0a814f 100644--- a/src/components/workspace/MotionInspector.tsx+++ b/src/components/workspace/MotionInspector.tsx@@ -3,9 +3,9 @@ import { motionOverride, motionOverrideSchema, motionSchema, type Motion } fromimport { PropSection, PropRow } from "../ui";import { SliderNumberInput } from "./SliderNumberInput";-export function MotionInspector({ motion, selectedId, onSelect, onChange, disabled = false, onRenderReference, rendering = false }: {- motion: Motion; selectedId: string | null; onSelect: (id: string | null) => void; onChange: (motion: Motion) => void;- disabled?: boolean; onRenderReference?: () => void; rendering?: boolean;+export function MotionInspector({ motion, selectedId, onChange, disabled = false }: {+ motion: Motion; selectedId: string | null; onChange: (motion: Motion) => void;+ disabled?: boolean;}) {const [source, setSource] = useState(motion.source);const [error, setError] = useState<string | null>(null);@@ -21,27 +21,6 @@ export function MotionInspector({ motion, selectedId, onSelect, onChange, disabl<PropSection title="Motion" persistKey="motion.document"><PropRow label="Duration"><SliderNumberInput aria-label="Motion duration" minimum={0.1} maximum={600} step={0.1} suffix="s" disabled={disabled}value={motion.duration} onCommit={(duration) => change({ ...motion, duration })} /></PropRow>- <button className="secondary-button inspector-action" disabled={rendering || !onRenderReference} onClick={onRenderReference}>{rendering ? "Rendering reference…" : "Render as reference video"}</button>- </PropSection>- <PropSection title="Elements" persistKey="motion.elements">- {!motion.nodes.length && <p className="settings-description">This Motion is empty. Ask the agent to add elements and animation.</p>}- {motion.nodes.map((item) => <button key={item.id} className="secondary-button" aria-pressed={selectedId === item.id} onClick={() => onSelect(item.id)}>{item.name}</button>)}- {node && edit && <>- {(["offset", "scale", "rotation"] as const).flatMap((property) => (property === "rotation" ? [2] : [0, 1]).map((axis) => {- const label = `${property === "offset" ? "Offset" : property === "scale" ? "Scale" : "Rotation"}${property === "rotation" ? "" : axis === 0 ? " X" : " Y"}`;- return <PropRow key={`${property}-${axis}`} label={label}><input className="text-field" type="number" aria-label={`Element ${label}`} disabled={disabled}- step={property === "scale" ? 0.05 : 1} value={edit[property][axis]} onChange={(e) => {- const value = Number(e.target.value); if (!Number.isFinite(value)) return;- const vector = [...edit[property]] as [number, number, number]; vector[axis] = value;- change({ ...motion, overrides: { ...motion.overrides, [node.id]: { ...edit, [property]: vector } } });- }} /></PropRow>;- }))}- <PropRow label="Fill"><input className="text-field" aria-label="Element fill" disabled={disabled} value={edit.fill ?? node.fill}- onChange={(e) => change({ ...motion, overrides: { ...motion.overrides, [node.id]: { ...edit, fill: e.target.value } } })} /></PropRow>- {node.kind === "text" && <PropRow label="Text"><input className="text-field" aria-label="Element text" disabled={disabled} value={edit.text ?? node.text}- onChange={(e) => change({ ...motion, overrides: { ...motion.overrides, [node.id]: { ...edit, text: e.target.value } } })} /></PropRow>}- <button className="secondary-button inspector-action" disabled={disabled} onClick={() => change({ ...motion, overrides: { ...motion.overrides, [node.id]: motionOverrideSchema.parse({}) } })}>Reset element adjustments</button>- </>}</PropSection><PropSection title="Parameters" persistKey="motion.parameters">{motion.parameters.length === 0 && <p className="settings-description">The agent can expose movement, timing, color and text controls here.</p>}@@ -54,7 +33,23 @@ export function MotionInspector({ motion, selectedId, onSelect, onChange, disabl...item, value: p.type === "boolean" ? e.target.checked : p.type === "number" ? Number(e.target.value) : e.target.value,}) })} />}</PropRow>)}</PropSection>- <PropSection title="JavaScript" persistKey="motion.source">+ {node && edit && <PropSection title="Elements" persistKey="motion.elements" summary={node.name}>+ {(["offset", "scale", "rotation"] as const).flatMap((property) => (property === "rotation" ? [2] : [0, 1]).map((axis) => {+ const label = `${property === "offset" ? "Offset" : property === "scale" ? "Scale" : "Rotation"}${property === "rotation" ? "" : axis === 0 ? " X" : " Y"}`;+ return <PropRow key={`${property}-${axis}`} label={label}><input className="text-field" type="number" aria-label={`Element ${label}`} disabled={disabled}+ step={property === "scale" ? 0.05 : 1} value={edit[property][axis]} onChange={(e) => {+ const value = Number(e.target.value); if (!Number.isFinite(value)) return;+ const vector = [...edit[property]] as [number, number, number]; vector[axis] = value;+ change({ ...motion, overrides: { ...motion.overrides, [node.id]: { ...edit, [property]: vector } } });+ }} /></PropRow>;+ }))}+ <PropRow label="Fill"><input className="text-field" aria-label="Element fill" disabled={disabled} value={edit.fill ?? node.fill}+ onChange={(e) => change({ ...motion, overrides: { ...motion.overrides, [node.id]: { ...edit, fill: e.target.value } } })} /></PropRow>+ {node.kind === "text" && <PropRow label="Text"><input className="text-field" aria-label="Element text" disabled={disabled} value={edit.text ?? node.text}+ onChange={(e) => change({ ...motion, overrides: { ...motion.overrides, [node.id]: { ...edit, text: e.target.value } } })} /></PropRow>}+ <button className="secondary-button inspector-action" disabled={disabled} onClick={() => change({ ...motion, overrides: { ...motion.overrides, [node.id]: motionOverrideSchema.parse({}) } })}>Reset element adjustments</button>+ </PropSection>}+ <PropSection title="JavaScript" defaultOpen={false}><textarea className="text-field motion-source" aria-label="Motion JavaScript source" spellCheck={false} disabled={disabled} value={source} onChange={(e) => setSource(e.target.value)} /><button className="secondary-button inspector-action" disabled={disabled || source === motion.source} onClick={() => change({ ...motion, source })}>Apply source</button>{error && <p role="alert">{error}</p>}diff --git a/src/components/workspace/TimelineView.tsx b/src/components/workspace/TimelineView.tsxindex c135da5..c728560 100644--- a/src/components/workspace/TimelineView.tsx+++ b/src/components/workspace/TimelineView.tsx@@ -1071,9 +1071,9 @@ export function TimelineView({ config, folderPath, generationCompletionTimes = {...asset, motion, width: motion.width, height: motion.height, durationMs: Math.round(motion.duration * 1000),}) }), `motion:${id}`);};- const renderMotionReference = async () => {- if (!selectedAsset?.motion || motionRendering || !isTauri()) return;- const asset = structuredClone(selectedAsset);+ const renderMotionReference = async (source: ProjectAsset) => {+ if (!source.motion || motionRendering || !isTauri()) return;+ const asset = structuredClone(source);setMotionRendering(true); setMotionNotice(null);try {const saved = await startMotionReferenceJob({ folderPath, ...motionReferenceExport(config, asset) });@@ -1112,6 +1112,7 @@ export function TimelineView({ config, folderPath, generationCompletionTimes = {const clipMenuItems = (clip: TimelineClip): MenuEntry[] => {const track = tracks.find((item) => item.id === clip.trackId);+ const asset = assetsById.get(clip.assetId);const locked = !track || track.locked;return [{ label: "Cut", shortcut: "Ctrl+X", disabled: locked, onSelect: () => cutClip(clip) },@@ -1121,6 +1122,7 @@ export function TimelineView({ config, folderPath, generationCompletionTimes = {{ label: "Split at playhead", icon: <Cut16 />, shortcut: "Ctrl+K", disabled: !canSplit(clip), onSelect: () => splitClip(clip) },{ label: "Duplicate", shortcut: "Ctrl+D", disabled: locked, onSelect: () => duplicateClip(clip) },{ label: "Rename", shortcut: "F2", onSelect: () => { setSelectedId(clip.id); renameSelected(); } },+ ...(asset?.motion ? [{ label: "Create Reference", disabled: motionRendering || !isTauri(), onSelect: () => void renderMotionReference(asset) }] : []),{ separator: true },{ label: "Delete", icon: <Delete16 />, shortcut: "Delete", danger: true, disabled: locked, onSelect: () => deleteClip(clip.id) },];@@ -1516,7 +1518,7 @@ export function TimelineView({ config, folderPath, generationCompletionTimes = {onClick={(event) => menu.open(event.currentTarget, clipMenuItems(selected), { "aria-label": `${selected.label} actions`, placement: "bottom-end", focusFirst: true })}><More16 aria-hidden="true" /></button>}/>- {selectedAsset?.motion && <MotionInspector key={selectedAsset.id} motion={selectedAsset.motion} selectedId={motionNodeId} onSelect={setMotionNodeId} onChange={updateMotion} disabled={visualControlsDisabled} onRenderReference={isTauri() ? () => void renderMotionReference() : undefined} rendering={motionRendering} />}+ {selectedAsset?.motion && <MotionInspector key={selectedAsset.id} motion={selectedAsset.motion} selectedId={motionNodeId} onChange={updateMotion} disabled={visualControlsDisabled} />}{motionNotice && <p className="panel-hint" role="status">{motionNotice}</p>}<PropSection title="Timing" persistKey="timeline.clip.timing" summary={`${shortTimecode(selected.startMs, fps)} → ${shortTimecode(clipEndMs(selected), fps)}`}><PropRow label="Speed" htmlFor="clip-speed" value={clipPlaybackRate(selected)} defaultValue={1}