The VS Code of video editing, built for agents.
TypeScript
Refactor LayoutPanel and Inspector integration
konstantin-paulus55dd6ab3d082
diff --git a/apps/web/src/components/sidebar-right/inspector/inspector.tsx b/apps/web/src/components/sidebar-right/inspector/inspector.tsxindex 698f5499..1236d966 100644--- a/apps/web/src/components/sidebar-right/inspector/inspector.tsx+++ b/apps/web/src/components/sidebar-right/inspector/inspector.tsx@@ -26,8 +26,8 @@ import { TimeSettings } from "./time";import { AppearanceSettings } from "./appearance";import { Alignment } from "./alignment";import { ExportPanel } from "./export";+import { LayoutPanel } from "./layout";// import { TransformSettings } from "./transform";-// import { LayoutPanel } from "./layout";// import { CaptionSettings } from "./caption-settings";// import { TextPanel } from "./text";// import { FillsSettings } from "./fills";@@ -133,9 +133,9 @@ export function Inspector() {<TransformSettings selection={nodes()} /></Show> */}- {/* <Show when={includesTarget("shape", "text", "audio", "scene", "caption", "mask")}>+ <Show when={includesTarget("shape", "text", "audio", "scene", "caption", "mask")}><LayoutPanel selection={nodes()} />- </Show> */}+ </Show><Show when={includesTarget("shape", "text", "scene", "caption", "group", "audio", "mask")}><AppearanceSettings selection={nodes()} />diff --git a/apps/web/src/components/sidebar-right/inspector/layout.tsx b/apps/web/src/components/sidebar-right/inspector/layout.tsxindex a0d53206..cfb4c6fd 100644--- a/apps/web/src/components/sidebar-right/inspector/layout.tsx+++ b/apps/web/src/components/sidebar-right/inspector/layout.tsx@@ -8,16 +8,18 @@ import { ControlledTextField } from "@/components/ui/text-field";import { Icon } from "@/components/ui/icon";import { PanelSection } from "@/components/ui/panel-section";import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";-import { Keyframe } from "@/components/ui/keyframe-bitecs";-import { useEntityState, useEntityTag, isScene, addComponent, removeComponent, setComponent, resizeEntity } from "@/components/engine";+import { Keyframe } from "@/components/ui/keyframe";import {Checkbox,CheckboxControl,CheckboxInput,CheckboxLabel,} from "@/components/ui/checkbox";-import { useEngine } from "@/context/engine";import { createMemo, For, Show } from "solid-js";+import { useHas, useWorld } from "@diffusionstudio/koota-solid";+import { ClipsContent, Computed, KeepAspectRatio, isScene } from "@diffusionstudio/runtime";+import { useDerived, useEditor } from "@/engine/hooks";+import { syncKeyframe } from "@/engine/keyframes";import {DropdownMenu,DropdownMenuTrigger,@@ -32,63 +34,91 @@ import {import { PRESET_CATEGORIES } from "@/lib/layout-presets";+import type { Entity } from "koota";type LayoutPanelProps = {- selection: Set<number>;+ selection: Entity[];};const DEFAULT_WIDTH = 1920;const DEFAULT_HEIGHT = 1080;export function LayoutPanel(props: LayoutPanelProps) {- const { world } = useEngine();- const c = world.components;+ const world = useWorld();+ const editor = useEditor();+ const entity = () => props.selection[0]!;- const eid = () => props.selection.values().next().value!;- const sceneSelected = createMemo(() => isScene(world, eid()));- const width = useEntityState(c.Computed.width, eid, 0);- const height = useEntityState(c.Computed.height, eid, 0);+ const sceneSelected = createMemo(() => isScene(entity()));+ const width = useDerived(() => entity().get(Computed)?.width ?? 0);+ const height = useDerived(() => entity().get(Computed)?.height ?? 0);- const keepAspectRatio = useEntityTag(c.KeepAspectRatio, eid);- const clipsContent = useEntityTag(c.ClipsContent, eid);+ const keepAspectRatio = useHas(entity, KeepAspectRatio);+ const clipsContent = useHas(entity, ClipsContent);const toggleClipsContent = (checked: boolean) => {if (checked) {- addComponent(world, eid(), c.ClipsContent);+ entity().add(ClipsContent);} else {- removeComponent(world, eid(), c.ClipsContent);+ entity().remove(ClipsContent);}};const orientation = createMemo<"square" | "horizontal" | "vertical">(() => {- const currentWidth = width() ?? DEFAULT_WIDTH;- const currentHeight = height() ?? DEFAULT_HEIGHT;+ const currentWidth = width() || DEFAULT_WIDTH;+ const currentHeight = height() || DEFAULT_HEIGHT;if (currentWidth === currentHeight) return "square";return currentWidth > currentHeight ? "horizontal" : "vertical";});+ /** Pins the lock to `width`×`height`, the ratio later edits keep. */+ const lockAspectRatio = (width: number, height: number) => {+ if (width <= 0 || height <= 0) return;+ entity().add(KeepAspectRatio);+ entity().set(KeepAspectRatio, { width, height });+ };++ const resize = (params: { width?: number; height?: number }) => {+ let { width, height } = params;++ const aspect = entity().get(KeepAspectRatio);+ if (aspect && aspect.width > 0 && aspect.height > 0) {+ const ratio = aspect.width / aspect.height;+ if (width !== undefined) {+ height = Math.round(width / ratio);+ } else if (height !== undefined) {+ width = Math.round(height * ratio);+ }+ }++ if (width !== undefined) {+ width = Math.round(width);+ syncKeyframe(world, editor, entity(), "width", width);+ editor.editProperty(entity(), "width", width);+ }+ if (height !== undefined) {+ height = Math.round(height);+ syncKeyframe(world, editor, entity(), "height", height);+ editor.editProperty(entity(), "height", height);+ }+ };+const handleWidthChange = (width: number) => {- resizeEntity(world, eid(), { width });+ resize({ width });};const handleHeightChange = (height: number) => {- resizeEntity(world, eid(), { height });+ resize({ height });};const toggleAspectRatio = () => {if (keepAspectRatio()) {- removeComponent(world, eid(), c.KeepAspectRatio);+ entity().remove(KeepAspectRatio);return;}// Lock: snapshot current absolute dimensions- const width = c.Computed.width[eid()];- const height = c.Computed.height[eid()];-- if (width > 0 && height > 0) {- setComponent(world, eid(), c.KeepAspectRatio, { width, height });- }+ lockAspectRatio(width(), height());};const aspectIcon = () => {@@ -115,26 +145,22 @@ export function LayoutPanel(props: LayoutPanelProps) {return "Square";};- const toggleAspectOrientation = () => {- const currentWidth = width() ?? DEFAULT_WIDTH;- const currentHeight = height() ?? DEFAULT_HEIGHT;+ /** A size chosen outright (orientation swap, preset): the lock follows it rather than fighting it. */+ const setSize = (width: number, height: number) => {+ if (keepAspectRatio()) {+ lockAspectRatio(width, height);+ }+ resize({ width, height });+ };- setComponent(world, eid(), c.KeepAspectRatio, {- width: currentHeight,- height: currentWidth,- });+ const toggleAspectOrientation = () => {+ const currentWidth = width() || DEFAULT_WIDTH;+ const currentHeight = height() || DEFAULT_HEIGHT;// Swap width and height- resizeEntity(world, eid(), {- width: currentHeight,- height: currentWidth- });+ setSize(currentHeight, currentWidth);};- const handleResizeEntity = (width: number, height: number) => {- resizeEntity(world, eid(), { width, height });- }-return (<PanelSectiontitle={@@ -165,7 +191,7 @@ export function LayoutPanel(props: LayoutPanelProps) {<DropdownMenuGroupLabel>{category.label}</DropdownMenuGroupLabel><For each={category.items}>{(item) => (- <DropdownMenuItem {...item} onSelect={() => handleResizeEntity(item.width, item.height)}>+ <DropdownMenuItem {...item} onSelect={() => setSize(item.width, item.height)}><span class="flex-1 min-w-0 overflow-hidden text-ellipsis whitespace-nowrap">{item.label}</span>@@ -231,7 +257,7 @@ export function LayoutPanel(props: LayoutPanelProps) {limitEventsskipEmptysliderEnabled- keyframe={<Keyframe target={eid()} property="width" />}+ keyframe={<Keyframe target={entity()} property="width" />}/><ControlledTextFieldclass="group"@@ -243,7 +269,7 @@ export function LayoutPanel(props: LayoutPanelProps) {limitEventsskipEmptysliderEnabled- keyframe={<Keyframe target={eid()} property="height" />}+ keyframe={<Keyframe target={entity()} property="height" />}/></ControlRow>diff --git a/packages/runtime/MIGRATION.md b/packages/runtime/MIGRATION.mdindex f636e67e..ae0a458c 100644--- a/packages/runtime/MIGRATION.md+++ b/packages/runtime/MIGRATION.md@@ -171,6 +171,8 @@ apps/web now depends on `@diffusionstudio/runtime` and `@diffusionstudio/koota-s**Keyframes as edits** live in `apps/web/src/engine/keyframes.tsx`, the runtime's `toggleKeyframeTrack`/`syncKeyframeTrack`/`removeKeyframeTrack` in the JSX's vocabulary: properties are `AnimatableProperty` names (what `<keyframeTrack property>` takes; the reconciler exports `trackPropertyPath(holder, name)` to resolve them, and `BLEND_MODES`), and every change goes through the editor. `writeKeyframe(world, editor, target, property, value?)` edits the `value` of the keyframe at the node's current local frame or inserts `<Keyframe time value />` (time as seconds, like the timing props) into the track, or the whole `<KeyframeTrack property><Keyframe/></KeyframeTrack>` when there is none; `value` defaults to the shown (Computed) value, colors as hex. `toggleKeyframe` adds or removes the keyframe at the current frame, removing the track with its last keyframe (`editor.remove`). `syncKeyframe(world, editor, target, property, value)` is what an editing surface calls after writing a prop that has a track, since the motion system would overwrite the edit on the next tick (the observers slice dropped auto-sync on purpose); the appearance panel does so for opacity and the radii. `removeKeyframeTrack` removes the track element. `components/ui/keyframe.tsx` is the koota `Keyframe` diamond (`target: Entity`, `property: AnimatableProperty`; track/active state sampled per tick with `useDerived`, shown only for an element with a `Source`); the bitecs one moved to `components/ui/keyframe-bitecs.tsx` and the unmigrated panels import it from there until they move. Not built: the timeline's keyframe layer and InterpolationSettings (keyframe `easing` edits) are still on the bitecs world.+ **LayoutPanel is on the koota world.** Size reads are `Computed.width/height` via `useDerived`; writes are the `width`/`height` props through `editor.editProperty`, each preceded by `syncKeyframe` rather than followed by it: the document's `width`/`height` handler is `resizeEntity`, which calls the runtime's `syncKeyframeTrack` itself and would otherwise mint an unsourced keyframe on an existing track before the editor gets to write one (the later `writeKeyframe` then finds that entity in `Cache.keyframes` and edits a value the file never hears of). The canvas resize in `input/interactions.ts` writes `width`/`height` without any sync and has the same gap; fix it the same way when it grows keyframe support. The aspect lock (`KeepAspectRatio`) and "Clip content" (`ClipsContent`) have no JSX spelling, so the panel writes the traits alone and they last until the project is rendered again, like `Skew` on the canvas; because the lock is trait-only, the panel couples the axes itself and writes both props, so the file says what the canvas shows and the runtime's own enforcement underneath is a no-op. A size chosen outright (a scene preset, the orientation swap) re-pins the lock to it instead of letting the old ratio squash it, which the bitecs panel did. Not carried over: nothing else; if the lock or clipping should survive a recompile, they want props on `<scene>`/`<rect>` (order-sensitive at mount if the snapshot is taken on set, so snapshot from the authored `width`/`height` then), which is a separate decision.+**Left stale on purpose** (deferred to a docs/examples pass): all eight `examples/*.tsx` still open with `<rect scene="...">` and no `<stage>`, so `tsc -p examples --noEmit` fails on them; `reference/jsx/{scene,roots}.md` still describes the pre-`<stage>` model where a mount grafts roots into an existing document; and `reference/jsx/{audio-sync,video,audio,elements}.md` still document `key` as the `syncTo` target. Deliberately not half-migrated: `reference/jsx` is stale as a whole, and patching the `key` rows alone would hide that.## Remaining work (suggested order)