Skip to content

The VS Code of video editing, built for agents.

TypeScript

Refactor Appearance Settings and Source Rows Integration

konstantin-paulusa2ff21575a7d
diff --git a/apps/web/src/components/sidebar-right/inspector/appearance.tsx b/apps/web/src/components/sidebar-right/inspector/appearance.tsx
index ab88f341..1ec01169 100644
--- a/apps/web/src/components/sidebar-right/inspector/appearance.tsx
+++ b/apps/web/src/components/sidebar-right/inspector/appearance.tsx
@@ -38,6 +38,7 @@ import {
} from "@diffusionstudio/runtime";
import { useDerived, useEditor } from "@/engine/hooks";
import { removeKeyframeTrack, syncKeyframe } from "@/engine/keyframes";
+import { SourceRows } from "./source";
import { BLEND_MODE_ORDER, BLEND_MODE_SEPARATORS, blendModeName, displayBlendMode } from "./blend-modes";
import type { Entity } from "koota";
@@ -70,19 +71,22 @@ type Corner = 'cornerRadiusTopLeft' | 'cornerRadiusTopRight' | 'cornerRadiusBott
const CORNERS: Corner[] = ['cornerRadiusTopLeft', 'cornerRadiusTopRight', 'cornerRadiusBottomRight', 'cornerRadiusBottomLeft'];
/**
- * Opacity, blending, visibility and corner radii. All of them are props
+ * Opacity, blending, source, visibility and corner radii. All of them are props
* (`opacity`, `blendMode`, `hidden`, `cornerRadius` and the four per-corner
* radii) written through the editor; the shown values are Computed, which
* the motion system writes, hence `useDerived`. A radius the panel leaves
* at its default is unset rather than written as 0, and a mode switch
* drops the other mode's props and tracks: uniform is `cornerRadius`,
- * separate is the four corners with `cornerRadius` gone.
+ * separate is the four corners with `cornerRadius` gone. The source rows
+ * show only when the node has an intrinsic paint or fill (see `SourceRows`).
*/
export function AppearanceSettings(props: AppearanceSettingsProps) {
const world = useWorld();
const editor = useEditor();
const entity = () => props.selection[0]!;
+ let anchorRef!: HTMLDivElement;
+
const opacity = useDerived(() => entity().get(Computed)?.opacity ?? 1);
const blendModeTrait = useTrait(entity, BlendMode);
const blendMode = () => blendModeTrait()?.value ?? BlendModeType.SOURCE_OVER;
@@ -181,6 +185,7 @@ export function AppearanceSettings(props: AppearanceSettingsProps) {
return (
<PanelSection
title="Appearance"
+ ref={anchorRef}
actions={
<Tooltip>
<TooltipTrigger
@@ -243,6 +248,8 @@ export function AppearanceSettings(props: AppearanceSettingsProps) {
</div>
</ControlRow>
+ <SourceRows node={entity()} anchorRef={anchorRef} />
+
<Show when={isRect(entity()) && !isAudio(entity())}>
<ContextMenu>
<ContextMenuTrigger<typeof ControlRow>
diff --git a/apps/web/src/components/sidebar-right/inspector/inspector.tsx b/apps/web/src/components/sidebar-right/inspector/inspector.tsx
index 7b5efd75..7b8db6f2 100644
--- a/apps/web/src/components/sidebar-right/inspector/inspector.tsx
+++ b/apps/web/src/components/sidebar-right/inspector/inspector.tsx
@@ -32,7 +32,6 @@ import { TransformSettings } from "./transform";
import { CaptionSettings } from "./caption-settings";
import { TextPanel } from "./text";
import { FillsSettings } from "./fills";
-import { SourceSettings } from "./source";
import { StrokesSettings } from "./strokes";
import { ShadowsSettings } from "./shadows";
import { EffectsSettings } from "./effects";
@@ -157,10 +156,6 @@ export function Inspector() {
<FillsSettings selection={nodes()} />
</Show>
- <Show when={includesTarget("shape", "text", "caption")}>
- <SourceSettings selection={nodes()} />
- </Show>
-
<Show when={includesTarget("shape")}>
<TrackingSettings selection={nodes()} />
</Show>
diff --git a/apps/web/src/components/sidebar-right/inspector/source.tsx b/apps/web/src/components/sidebar-right/inspector/source.tsx
index ef7edeac..d0336e2b 100644
--- a/apps/web/src/components/sidebar-right/inspector/source.tsx
+++ b/apps/web/src/components/sidebar-right/inspector/source.tsx
@@ -12,7 +12,6 @@ import {
FloatingInspectorTitle,
} from "@/components/ui/floating-inspector";
import { Icon } from "@/components/ui/icon";
-import { PanelSection } from "@/components/ui/panel-section";
import { ControlRow } from "@/components/ui/control-group";
import { AssetThumbnail } from "@/components/ui/asset-thumbnail";
import { OpacitySwatch } from "@/components/ui/opacity-swatch";
@@ -29,7 +28,7 @@ import { AssetFillPicker } from "./asset-picker";
import type { Asset } from "@diffusionstudio/assets";
import type { Entity } from "koota";
-/** The row label, like a fill row's: which kind of media the node is. */
+/** Which kind of media the node is, for the row's empty state and tooltip. */
const MEDIA_LABELS: Partial<Record<PaintType, string>> = {
[PaintType.VIDEO]: "Video",
[PaintType.IMAGE]: "Image",
@@ -42,30 +41,29 @@ const INTRINSIC_LABELS: Partial<Record<PaintType, string>> = {
[PaintType.WAVEFORM]: "Audio waveform",
};
-type SourceSettingsProps = {
- selection: Entity[];
+type SourceRowsProps = {
+ node: Entity;
+ anchorRef: HTMLElement;
};
/**
- * What the node is intrinsically painted with, as its own section beneath
- * Fill, which mirrors the canvas: the intrinsics draw beneath every paint
- * child. Two rows can show — the intrinsic paint (a `<video>`'s footage, an
- * `<image>`'s picture, a `<surface>`'s canvas) and, beneath it as it draws,
- * the intrinsic solid (the `fill` prop). An intrinsic is not an element of
- * its own, so it offers exactly two things: another value (a `src` or `fill`
+ * What the node is intrinsically painted with, as "Source" rows inside
+ * Appearance; they render only when the node has an intrinsic. Two can
+ * show — the intrinsic paint (a `<video>`'s footage, an `<image>`'s
+ * picture, a `<surface>`'s canvas) and, beneath it as it draws, the
+ * intrinsic solid (the `fill` prop). An intrinsic is not an element of its
+ * own, so it offers exactly two things: another value (a `src` or `fill`
* write, `objectFit` through the picker's fit menu — the node keeps its
* identity) or removal. Removing the solid takes the prop off; removing the
* media takes the element's nature off, rewriting it as the `<rect>` it
- * otherwise was (see `DocumentEditor.removeIntrinsicPaint`), and the section
+ * otherwise was (see `DocumentEditor.removeIntrinsicPaint`), and the row
* goes with it. A surface or html intrinsic has neither; its row just says
* what the node is made of.
*/
-export function SourceSettings(props: SourceSettingsProps) {
+export function SourceRows(props: SourceRowsProps) {
const editor = useEditor();
const library = useLibrary();
- const entity = () => props.selection[0]!;
-
- let anchorRef!: HTMLDivElement;
+ const entity = () => props.node;
// One picker at a time: they anchor to the same section and would overlap.
const [picking, setPicking] = createSignal<"media" | "solid">();
@@ -90,29 +88,27 @@ export function SourceSettings(props: SourceSettingsProps) {
};
// Removal is the element ceasing to be a media element: the node is
- // rewritten as the <rect> it otherwise was, and this section goes with it.
+ // rewritten as the <rect> it otherwise was, and this row goes with it.
const handleRemoveMedia = () => {
setPicking(undefined);
editor.removeIntrinsicPaint(entity());
};
return (
- <Show when={intrinsic() !== undefined || hasFill()}>
- <PanelSection title="Source" ref={anchorRef}>
- <Show
- when={isMedia()}
- fallback={
- <Show when={intrinsic() !== undefined}>
+ <>
+ <Show when={intrinsic() !== undefined}>
+ <ControlRow label="Source">
+ <Show
+ when={isMedia()}
+ fallback={
<div class="flex h-7 items-center gap-2 rounded-md bg-input px-2 text-xs text-muted-foreground select-none">
<Icon name="html-small" />
<span class="min-w-0 truncate">
{INTRINSIC_LABELS[intrinsic()!] ?? "Intrinsic paint"}
</span>
</div>
- </Show>
- }
- >
- <ControlRow label={MEDIA_LABELS[intrinsic()!]}>
+ }
+ >
<div class="flex h-7 w-full items-center overflow-hidden rounded-md border border-transparent bg-input text-foreground focus-within:border-primary">
<button
class="flex h-full min-w-0 flex-1 items-center gap-2 pl-1 text-left"
@@ -136,7 +132,7 @@ export function SourceSettings(props: SourceSettingsProps) {
</Show>
</span>
<span class="min-w-0 flex-1 truncate text-xxs">
- {asset() ? assetName(asset()!) : "No media"}
+ {asset() ? assetName(asset()!) : `No ${MEDIA_LABELS[intrinsic()!]?.toLowerCase() ?? "media"}`}
</span>
</button>
<Tooltip>
@@ -149,24 +145,25 @@ export function SourceSettings(props: SourceSettingsProps) {
>
<Icon name="close-remove-small" />
</TooltipTrigger>
- <TooltipContent>Remove media</TooltipContent>
+ <TooltipContent>Remove {MEDIA_LABELS[intrinsic()!]?.toLowerCase() ?? "media"}</TooltipContent>
</Tooltip>
</div>
- </ControlRow>
- </Show>
+ </Show>
+ </ControlRow>
+ </Show>
- <Show when={hasFill()}>
- <SolidFillRow
- node={entity()}
- anchorRef={anchorRef}
- picking={picking() === "solid"}
- onPickingChange={(open) => setPicking(open ? "solid" : undefined)}
- />
- </Show>
- </PanelSection>
+ <Show when={hasFill()}>
+ <SolidFillRow
+ node={entity()}
+ label={intrinsic() === undefined ? "Source" : ""}
+ anchorRef={props.anchorRef}
+ picking={picking() === "solid"}
+ onPickingChange={(open) => setPicking(open ? "solid" : undefined)}
+ />
+ </Show>
<Show when={picking() === "media"}>
- <FloatingInspector open anchorRef={anchorRef}>
+ <FloatingInspector open anchorRef={props.anchorRef}>
<FloatingInspectorHeader>
<FloatingInspectorTitle>Source</FloatingInspectorTitle>
<div class="ml-auto flex items-center gap-1">
@@ -194,12 +191,13 @@ export function SourceSettings(props: SourceSettingsProps) {
</FloatingInspectorContent>
</FloatingInspector>
</Show>
- </Show>
+ </>
);
}
type SolidFillRowProps = {
node: Entity;
+ label: string;
anchorRef: HTMLElement;
picking: boolean;
onPickingChange(open: boolean): void;
@@ -276,7 +274,7 @@ function SolidFillRow(props: SolidFillRowProps) {
};
return (
- <ControlRow label="Solid">
+ <ControlRow label={props.label}>
<div class="flex h-7 w-full items-center overflow-hidden rounded-md border border-transparent bg-input text-foreground focus-within:border-primary">
<div class="flex h-full min-w-0 flex-1 items-center gap-2 pl-1">
<button