The VS Code of video editing, built for agents.
TypeScript
Refactor inspector component and introduce selection handling
konstantin-paulus077a335b5edb
diff --git a/apps/web/src/components/sidebar-right/inspector/inspector.tsx b/apps/web/src/components/sidebar-right/inspector/inspector.tsxindex b30a5c66..5950bc4a 100644--- a/apps/web/src/components/sidebar-right/inspector/inspector.tsx+++ b/apps/web/src/components/sidebar-right/inspector/inspector.tsx@@ -4,88 +4,108 @@import { ControlScrollArea } from "@/components/ui/control-scrollarea";import { Show, createMemo } from "solid-js";+import {+ ToolType,+ // getParentNode,+ isAdjustmentLayer,+ isAudio,+ isCaption,+ isGroup,+ isMask,+ isScene,+ isSequence,+ isShape,+ isText,+} from "@diffusionstudio/runtime";+import { useSelection, useTool } from "@/engine/hooks";import { InspectorHeader } from "./inspector-header";-import { Alignment } from "./alignment";-import { AnimationsSettings } from "./animations";-import { AudioSettings } from "./audio";-import { LayoutPanel } from "./layout";-import { EffectsSettings } from "./effects";-import { ExportPanel } from "./export";-import { FillsSettings } from "./fills";-import { AppearanceSettings } from "./appearance";-import { ShadowsSettings } from "./shadows";-import { StrokesSettings } from "./strokes";-import { AssetInfoPanel } from "./asset-info";-import { TimeSettings } from "./time";-import { TransformSettings } from "./transform";import { BackgroundSettings } from "./background";-import { TransitionSettings } from "./transition";-import { MasksSettings } from "./masks";-import { InterpolationSettings } from "./interpolation";-import { CaptionSettings } from "./caption-settings";-import { getParentEntity, isAdjustmentLayer, isAudio, isCaption, isGroup, isMask, isScene, isSequence, isShape, isText, ToolType, useAssets } from "@/components/engine";-import { useEngine } from "@/context/engine";-import { SceneTemplatePanel } from "./scene-template";-import { TextPanel } from "./text";-import { useECS } from "@/context/ecs";+// import { SceneTemplatePanel } from "./scene-template";+// import { Alignment } from "./alignment";+// import { ExportPanel } from "./export";+// import { TimeSettings } from "./time";+// import { TransformSettings } from "./transform";+// import { LayoutPanel } from "./layout";+// import { AppearanceSettings } from "./appearance";+// import { CaptionSettings } from "./caption-settings";+// import { TextPanel } from "./text";+// import { FillsSettings } from "./fills";+// import { StrokesSettings } from "./strokes";+// import { ShadowsSettings } from "./shadows";+// import { EffectsSettings } from "./effects";+// import { AnimationsSettings } from "./animations";+// import { TransitionSettings } from "./transition";+// import { MasksSettings } from "./masks";+// import { AudioSettings } from "./audio";+// import { AssetInfoPanel } from "./asset-info";+// import { InterpolationSettings } from "./interpolation";++import type { Entity } from "koota";++/**+ * What the inspector is looking at. Decided by the armed tool first, then the+ * selection: keyframes win over nodes, then a selected library asset (not+ * wired yet: asset selection is local to the assets panel), a single node is classified by its+ * traits (order matters: a scene is also RECT + ClipsContent), and anything+ * else falls back to the stage.+ */+export type SelectionTarget =+ | "scene-tool"+ | "keyframe"+ | "asset"+ | "scene"+ | "mask"+ | "sequence"+ | "caption"+ | "audio"+ | "adjustment"+ | "text"+ | "shape"+ | "group"+ | "stage";++function classifyNode(entity: Entity): SelectionTarget {+ if (isScene(entity)) return "scene";+ if (isMask(entity)) return "mask";+ if (isSequence(entity)) return "sequence";+ if (isCaption(entity)) return "caption";+ if (isAudio(entity)) return "audio";+ if (isAdjustmentLayer(entity)) return "adjustment";+ if (isText(entity)) return "text";+ if (isShape(entity)) return "shape";+ if (isGroup(entity)) return "group";+ return "stage";+}+// Panels still on the bitecs world are commented out below; each comes back+// in place as it moves onto the koota world.export function Inspector() {- const { world } = useEngine();- const assets = useAssets(world);- const { selectedKeyframes, selectedTool, selectedNodes } = useECS();--- const firstEid = createMemo(() => selectedNodes().values().next().value);- const parentEid = createMemo(() => getParentEntity(world, firstEid()));- const isNested = createMemo(() => parentEid() != null);-- const isSequenceChild = createMemo(() => {- const eid = parentEid();- if (eid && isSequence(world, eid)) {- return true;- }-- return false;- });-- const selectionTarget = createMemo(() => {- const eid = firstEid();-- if (selectedTool() === ToolType.SCENE) {- return "scene-tool";- }-- if (selectedKeyframes().size > 0) {- return "keyframe";- }-- if (assets.selected().size > 0) {- return "asset";- }-- if (selectedNodes().size === 1 && eid) {- // Order matters: scene check before plain group/shape since scenes are RECT+Group+ClipsContent.- if (isScene(world, eid)) return "scene";- if (isMask(world, eid)) return "mask";- if (isSequence(world, eid)) return "sequence";- if (isCaption(world, eid)) return "caption";- if (isAudio(world, eid)) return "audio";- if (isAdjustmentLayer(world, eid)) return "adjustment";- if (isText(world, eid)) return "text";- if (isShape(world, eid)) return "shape";- if (isGroup(world, eid)) return "group";- }-+ const tool = useTool();+ const { nodes, keyframes, first } = useSelection();++ // For ExportPanel (root scenes only) and TransitionSettings (sequence items).+ // const parent = createMemo(() => getParentNode(first()));+ // const isNested = createMemo(() => parent() !== null);+ // const isSequenceChild = createMemo(() => {+ // const entity = parent();+ // return entity !== null && isSequence(entity);+ // });++ const selectionTarget = createMemo<SelectionTarget>(() => {+ if (tool() === ToolType.SCENE) return "scene-tool";+ if (keyframes().length > 0) return "keyframe";+ const entity = first();+ if (nodes().length === 1 && entity) return classifyNode(entity);return "stage";});+ // Remounts the panels when the selection changes, so per-panel local state+ // (open pickers, text fields mid-edit) never carries over to another entity.const selectionHash = createMemo(() => {- const nodes = Array.from(selectedNodes());- const keyframes = Array.from(selectedKeyframes());- return [...nodes, ...keyframes].join(',') + selectionTarget();+ return [...nodes(), ...keyframes()].join(",") + selectionTarget();});- const includesTarget = (...targets: ReturnType<typeof selectionTarget>[]) => {+ const includesTarget = (...targets: SelectionTarget[]) => {return targets.includes(selectionTarget());};@@ -94,86 +114,85 @@ export function Inspector() {<InspectorHeader /><Show when={selectionHash()} keyed><ControlScrollArea class="flex-1 min-h-0">- <Show when={includesTarget("scene-tool")}>+ {/* <Show when={includesTarget("scene-tool")}><SceneTemplatePanel />- </Show>+ </Show> */}- <Show when={selectedNodes().size > 1}>+ {/* <Show when={nodes().length > 1}><Alignment />- </Show>+ </Show> */}- <Show when={includesTarget("scene") && !isNested()}>- <ExportPanel selection={selectedNodes()} />- </Show>+ {/* <Show when={includesTarget("scene") && !isNested()}>+ <ExportPanel selection={nodes()} />+ </Show> */}<Show when={includesTarget("stage")}><BackgroundSettings /></Show>- <Show when={includesTarget("shape", "text", "audio", "scene", "caption", "group", "mask", "adjustment")}>- <TimeSettings selection={selectedNodes()} />- </Show>-+ {/* <Show when={includesTarget("shape", "text", "audio", "scene", "caption", "group", "mask", "adjustment")}>+ <TimeSettings selection={nodes()} />+ </Show> */}- <Show when={includesTarget("shape", "text", "audio", "scene", "caption", "group", "mask", "adjustment")}>- <TransformSettings selection={selectedNodes()} />- </Show>+ {/* <Show when={includesTarget("shape", "text", "audio", "scene", "caption", "group", "mask", "adjustment")}>+ <TransformSettings selection={nodes()} />+ </Show> */}- <Show when={includesTarget("shape", "text", "audio", "scene", "caption", "mask")}>- <LayoutPanel selection={selectedNodes()} />- </Show>+ {/* <Show when={includesTarget("shape", "text", "audio", "scene", "caption", "mask")}>+ <LayoutPanel selection={nodes()} />+ </Show> */}- <Show when={includesTarget("shape", "text", "scene", "caption", "group", "audio", "mask")}>- <AppearanceSettings selection={selectedNodes()} />- </Show>+ {/* <Show when={includesTarget("shape", "text", "scene", "caption", "group", "audio", "mask")}>+ <AppearanceSettings selection={nodes()} />+ </Show> */}- <Show when={includesTarget("caption")}>- <CaptionSettings selection={selectedNodes()} />- </Show>+ {/* <Show when={includesTarget("caption")}>+ <CaptionSettings selection={nodes()} />+ </Show> */}- <Show when={includesTarget("text", "caption")}>- <TextPanel selection={selectedNodes()} />- </Show>+ {/* <Show when={includesTarget("text", "caption")}>+ <TextPanel selection={nodes()} />+ </Show> */}- <Show when={includesTarget("shape", "text", "scene", "caption")}>- <FillsSettings selection={selectedNodes()} />- </Show>+ {/* <Show when={includesTarget("shape", "text", "scene", "caption")}>+ <FillsSettings selection={nodes()} />+ </Show> */}- <Show when={includesTarget("shape", "text", "scene", "caption")}>- <StrokesSettings selection={selectedNodes()} />- </Show>+ {/* <Show when={includesTarget("shape", "text", "scene", "caption")}>+ <StrokesSettings selection={nodes()} />+ </Show> */}- <Show when={includesTarget("shape", "text", "scene", "caption")}>- <ShadowsSettings selection={selectedNodes()} />- </Show>+ {/* <Show when={includesTarget("shape", "text", "scene", "caption")}>+ <ShadowsSettings selection={nodes()} />+ </Show> */}- <Show when={includesTarget("shape", "text", "scene", "caption")}>- <EffectsSettings selection={selectedNodes()} />- </Show>+ {/* <Show when={includesTarget("shape", "text", "scene", "caption")}>+ <EffectsSettings selection={nodes()} />+ </Show> */}- <Show when={includesTarget("shape", "text", "caption", "group", "mask")}>- <AnimationsSettings selection={selectedNodes()} />- </Show>+ {/* <Show when={includesTarget("shape", "text", "caption", "group", "mask")}>+ <AnimationsSettings selection={nodes()} />+ </Show> */}- <Show when={includesTarget("shape") && isSequenceChild()}>- <TransitionSettings selection={selectedNodes()} />- </Show>+ {/* <Show when={includesTarget("shape") && isSequenceChild()}>+ <TransitionSettings selection={nodes()} />+ </Show> */}- <Show when={includesTarget("shape", "text", "caption", "group")}>- <MasksSettings selection={selectedNodes()} />- </Show>+ {/* <Show when={includesTarget("shape", "text", "caption", "group")}>+ <MasksSettings selection={nodes()} />+ </Show> */}- <Show when={includesTarget("shape", "audio", "group")}>- <AudioSettings selection={selectedNodes()} />- </Show>+ {/* <Show when={includesTarget("shape", "audio", "group")}>+ <AudioSettings selection={nodes()} />+ </Show> */}- <Show when={includesTarget("asset")}>+ {/* <Show when={includesTarget("asset")}><AssetInfoPanel />- </Show>+ </Show> */}- <Show when={includesTarget("keyframe")}>+ {/* <Show when={includesTarget("keyframe")}><InterpolationSettings />- </Show>+ </Show> */}</ControlScrollArea></Show></div>diff --git a/apps/web/src/engine/hooks/index.ts b/apps/web/src/engine/hooks/index.tsindex e2b0f41e..7a75700a 100644--- a/apps/web/src/engine/hooks/index.ts+++ b/apps/web/src/engine/hooks/index.ts@@ -6,3 +6,4 @@ export * from './use-active-scene';export * from './use-camera';export * from './use-editor';export * from './use-tool';+export * from './use-selection';diff --git a/apps/web/src/engine/hooks/use-selection.ts b/apps/web/src/engine/hooks/use-selection.tsnew file mode 100644index 00000000..ce073aed--- /dev/null+++ b/apps/web/src/engine/hooks/use-selection.ts@@ -0,0 +1,24 @@+/* This Source Code Form is subject to the terms of the Mozilla Public+ * License, v. 2.0. If a copy of the MPL was not distributed with this+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */++import { AdjustmentLayer, Geometry, Group, Keyframe, Selected } from '@diffusionstudio/runtime';+import { useQuery } from '@diffusionstudio/koota-solid';+import { createMemo } from 'solid-js';++/**+ * Reactive read of the Selected trait, split into the two kinds the editor+ * selects. Write it via `useEditor().select/deselect/clearSelection`, which+ * report the change to the source; never by touching the trait.+ */+export function useSelection() {+ const selected = useQuery(Selected);++ const nodes = createMemo(() =>+ selected().filter(entity => entity.has(Geometry) || entity.has(Group) || entity.has(AdjustmentLayer)),+ );+ const keyframes = createMemo(() => selected().filter(entity => entity.has(Keyframe)));+ const first = createMemo(() => nodes()[0] ?? null);++ return { nodes, keyframes, first };+}diff --git a/packages/runtime/MIGRATION.md b/packages/runtime/MIGRATION.mdindex f2ef18b5..8108ec9a 100644--- a/packages/runtime/MIGRATION.md+++ b/packages/runtime/MIGRATION.md@@ -161,6 +161,8 @@ apps/web now depends on `@diffusionstudio/runtime` and `@diffusionstudio/koota-s**`mask` is a `<rect>` prop** (`RectProps.mask?: boolean` in `@diffusionstudio/jsx`; no new tag). In the engine a mask is nothing but a geometry with the `IsMask` tag, `ChildOf` the node it clips: `rebuildCaches` files it under `Cache.masks` instead of `Cache.children`, `renderNode` skips drawing it and uses `drawRectPath` of it as a `clip()` (several intersect), hit-testing and the timeline index treat it apart, and the transform, visibility and motion systems see an ordinary geometry — so a keyframed mask `width` is a wipe with nothing new. The prop mirrors that one to one: `setProperty('mask')` adds/removes `IsMask` on the rect's entity, and every other prop is the rect's (`fill`/`opacity`/`blendMode`/paint children are accepted by the type but do nothing on a mask, as they do nothing in the engine). A tag (`<mask>`) was tried first and dropped: the recipe was `<rect>` minus a default paint, and a tag would have made "make this rect a mask" a retag instead of a prop flip. Host behaviour: a `<rect mask>` with no `width`/`height` is 500×500 instead of the rect's 100×100 (`setProperty('mask')` resizes only the dimensions not yet authored, so prop order does not matter); sizing to the parent, which the old editor's "Add mask" did, was tried and dropped for a plain default. Runtime changes: `recomputeEntityTimeRange` gives a mask with no `End`/`SourceOut` of its own its parent's `Computed.end` instead of the sourceless 16 s default (a mask silently letting go at 16 s on a 30 s clip is a surprise nobody authored; `Ignorable` gained `IsMask` so a removal can recompute as if the tag were gone), `bubbleTimeRangeUp` re-propagates into a fitted container's masks after recomputing it (they are not in `Cache.children`, so they would otherwise keep the stale end), the transform system's group-bounds union skips `IsMask` children (a mask clips a group's box, it does not extend it), and `world/observers.ts` watches `IsMask` add/remove on an attached geometry — `refileMask` (new in `actions/cache.ts`) moves it between the parent's `children` and `masks` by hand, since koota fires onRemove with the tag still on and the queries cannot be trusted, then the time range is re-derived and bubbled — so `mask` toggles live like any other prop. Not exposed: `hidden` on a mask does not switch it off (`renderNode` skips masks by role before it looks at `Hidden`, and `computed.visibility` is timing only); text-shaped masks are not a runtime feature either (`drawRectPath` is the only mask path).+ **Inspector shell is on the koota world.** `useSelection()` (`apps/web/src/engine/hooks/use-selection.ts`) reads `Selected` via `useQuery` and splits it into `nodes` (Geometry/Group/AdjustmentLayer), `keyframes`, and `first`; selection is written through `useEditor().select/...` only. `sidebar-right/inspector/inspector.tsx` classifies the target with the runtime predicates (`isScene`, `isMask`, ..., `ToolType.SCENE` from `useTool()`) and mounts only the panels already migrated (`InspectorHeader`, `BackgroundSettings`); the rest of the panels are listed in a comment in their previous order and return one at a time, each following `background.tsx`'s pattern (`useTrait` to read, `editor.editProperty` to write). The `asset` target needs a shared asset-selection state first (today it is a signal local to `sidebar-left/assets.tsx`).+**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)