Skip to content

The VS Code of video editing, built for agents.

TypeScript

feat: add layer toggle commands and integrate context menus in timeline and canvas

konstantin-paulus6c6349a38f49
diff --git a/apps/web/src/components/commands/index.tsx b/apps/web/src/components/commands/index.tsx
index 6a302340..8a2eb60d 100644
--- a/apps/web/src/components/commands/index.tsx
+++ b/apps/web/src/components/commands/index.tsx
@@ -8,6 +8,7 @@ import { EditWithPromptCommand } from "./edit-with-prompt";
import { ExportCurrentFrameCommand } from "./export-current-frame";
import { ExportVideoCommand } from "./export-video";
import { GenerateCommand } from "./generate";
+import { LayerToggleCommands } from "./layer-toggles";
import { MakeVideoCommand } from "./make-video";
import { ProjectFolderCommands } from "./project-folder";
import { RemoveBackgroundCommand } from "./remove-background";
@@ -20,7 +21,7 @@ import { UpscaleCommand } from "./upscale";
export { CommandBar } from "./command-bar";
export { CommandPalette } from "./palette";
-export { NodeContextMenu } from "./node-menu";
+export { CANVAS_MENU, NodeContextMenu, TIMELINE_MENU } from "./node-menu";
export { ReloadWindowCommand } from "./reload-window";
/**
@@ -55,6 +56,7 @@ export function CanvasCommands() {
<ToolCommand tool={ToolType.PEN} />
<ToolCommand tool={ToolType.TEXT} />
<ShortcutCommands />
+ <LayerToggleCommands />
<ProjectFolderCommands />
</>
);
diff --git a/apps/web/src/components/commands/layer-toggles.tsx b/apps/web/src/components/commands/layer-toggles.tsx
new file mode 100644
index 00000000..7740cbd4
--- /dev/null
+++ b/apps/web/src/components/commands/layer-toggles.tsx
@@ -0,0 +1,35 @@
+/* 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 { useWorld } from "@diffusionstudio/koota-solid";
+import { useCommand } from "@/context/commands";
+import { toggleSelectionMuted, toggleSelectionSoloed, useSelection } from "@/engine";
+
+/** What the layer list's mute and solo buttons do, over the selection. */
+export function LayerToggleCommands() {
+ const world = useWorld();
+ const { nodes } = useSelection();
+
+ useCommand({
+ id: "toggle-muted",
+ title: "Toggle mute",
+ group: "Object",
+ icon: "mute",
+ keywords: ["mute", "unmute", "audio", "sound", "silence"],
+ available: () => nodes().length > 0,
+ run: () => toggleSelectionMuted(world),
+ });
+
+ useCommand({
+ id: "toggle-soloed",
+ title: "Toggle solo",
+ group: "Object",
+ icon: "solo",
+ keywords: ["solo", "unsolo", "audio", "listen"],
+ available: () => nodes().length > 0,
+ run: () => toggleSelectionSoloed(world),
+ });
+
+ return null;
+}
diff --git a/apps/web/src/components/commands/node-menu.tsx b/apps/web/src/components/commands/node-menu.tsx
index ca303397..f82dbf43 100644
--- a/apps/web/src/components/commands/node-menu.tsx
+++ b/apps/web/src/components/commands/node-menu.tsx
@@ -8,7 +8,7 @@
// offers for that selection. Every surface that shows nodes wraps itself in
// one, and says which nodes are under the pointer.
-import { createSignal, For, Show } from "solid-js";
+import { createSignal, For, Show, splitProps } from "solid-js";
import { useWorld } from "@diffusionstudio/koota-solid";
import {
ContextMenu,
@@ -28,36 +28,67 @@ import type { JSX } from "solid-js";
import type { RegisteredCommand } from "@/context/commands";
/**
- * The commands listed over a selection, by id, a rule between sections. One
- * that has nothing in the selection to work on is left out, and a section
- * left with none goes with it.
+ * What a menu lists, by command id, a rule between sections: over a
+ * selection, and over nothing. A command that has nothing in the selection to
+ * work on is left out, and a section left with none goes with it.
*/
-const NODE_SECTIONS = [
- ["shortcut:copy", "shortcut:cut", "shortcut:paste", "shortcut:duplicate", "shortcut:delete"],
- [
- "shortcut:group",
- "shortcut:ungroup",
- "shortcut:wrap-in-scene",
- "shortcut:wrap-in-sequence",
- "shortcut:unwrap-sequence",
- ],
- ["shortcut:bring-to-front", "shortcut:send-to-back", "shortcut:toggle-hidden"],
- ["upscale", "remove-background", "remove-silence", "auto-captions"],
- ["edit-with-prompt", "make-video", "rerun", "reuse-settings"],
+export type NodeMenuLayout = {
+ nodes: string[][];
+ empty: string[][];
+};
+
+const CLIPBOARD = ["shortcut:copy", "shortcut:cut", "shortcut:paste", "shortcut:duplicate", "shortcut:delete"];
+const STRUCTURE = [
+ "shortcut:group",
+ "shortcut:ungroup",
+ "shortcut:wrap-in-scene",
+ "shortcut:wrap-in-sequence",
+ "shortcut:unwrap-sequence",
];
+const MEDIA = ["upscale", "remove-background", "remove-silence", "auto-captions"];
+const GENERATE = ["edit-with-prompt", "make-video", "rerun", "reuse-settings"];
-/** The commands listed over nothing. */
-const STAGE_SECTIONS = [["shortcut:paste", "shortcut:select-all"]];
+export const CANVAS_MENU: NodeMenuLayout = {
+ nodes: [
+ CLIPBOARD,
+ STRUCTURE,
+ ["shortcut:bring-to-front", "shortcut:send-to-back", "shortcut:toggle-hidden"],
+ MEDIA,
+ GENERATE,
+ ],
+ empty: [["shortcut:paste", "shortcut:select-all"]],
+};
+
+/**
+ * The timeline's: cuts at the playhead and the layer list's monitoring
+ * toggles besides. Select all would select what the stage holds rather than
+ * the clips in view, so it is not offered over nothing.
+ */
+export const TIMELINE_MENU: NodeMenuLayout = {
+ nodes: [
+ CLIPBOARD,
+ ["shortcut:split"],
+ STRUCTURE,
+ ["shortcut:bring-to-front", "shortcut:send-to-back", "shortcut:toggle-hidden", "toggle-muted", "toggle-soloed"],
+ MEDIA,
+ GENERATE,
+ ],
+ empty: [["shortcut:paste"]],
+};
/** Whether `command` would run over the selection rather than ask for a target. */
const offered = (command: RegisteredCommand) => (command.available?.() ?? true) && (command.ready?.() ?? true);
-export function NodeContextMenu(props: {
+export type NodeContextMenuProps = Omit<JSX.HTMLAttributes<HTMLDivElement>, "onContextMenu"> & {
/** The nodes a right-click at `event` is on; empty over nothing. */
pick(event: MouseEvent): Entity[];
- class?: string;
- children: JSX.Element;
-}) {
+ /** `CANVAS_MENU` when left out. */
+ layout?: NodeMenuLayout;
+};
+
+/** The rest of the props go to the element that answers the right-click, which holds `children`. */
+export function NodeContextMenu(props: NodeContextMenuProps) {
+ const [local, rest] = splitProps(props, ["pick", "layout", "children"]);
const world = useWorld();
const { commands, execute } = useCommands();
const { nodes } = useSelection();
@@ -65,11 +96,15 @@ export function NodeContextMenu(props: {
const select = (event: MouseEvent) => {
const editor = getDocumentEditor(world);
- const picked = props.pick(event);
+ const picked = local.pick(event);
const selected = nodes();
if (!picked.length) editor.clearSelection();
else if (!picked.every((node) => selected.includes(node))) editor.select(picked);
+
+ // Nothing to offer (over nothing, with nothing to paste): no menu at all,
+ // rather than an empty one. Prevented, the trigger leaves it closed.
+ if (live().length === 0) event.preventDefault();
};
/**
@@ -80,8 +115,8 @@ export function NodeContextMenu(props: {
*/
const live = () => {
const byId = new Map(commands().map((command) => [command.id, command]));
- const layout = nodes().length ? NODE_SECTIONS : STAGE_SECTIONS;
- return layout
+ const layout = local.layout ?? CANVAS_MENU;
+ return (nodes().length ? layout.nodes : layout.empty)
.map((ids) => ids.map((id) => byId.get(id)).filter((command) => command !== undefined).filter(offered))
.filter((section) => section.length > 0);
};
@@ -99,8 +134,8 @@ export function NodeContextMenu(props: {
return (
<ContextMenu onOpenChange={(open) => (open ? setFrozen(null) : freeze())}>
- <ContextMenuTrigger class={props.class} onContextMenu={select}>
- {props.children}
+ <ContextMenuTrigger {...rest} onContextMenu={select}>
+ {local.children}
</ContextMenuTrigger>
<ContextMenuPortal>
<ContextMenuContent class="w-[220px]">
diff --git a/apps/web/src/components/timeline/layers/node.tsx b/apps/web/src/components/timeline/layers/node.tsx
index 5a819eb7..001366df 100644
--- a/apps/web/src/components/timeline/layers/node.tsx
+++ b/apps/web/src/components/timeline/layers/node.tsx
@@ -14,8 +14,6 @@ import {
Selected,
Soloed,
findGeometryAsset,
- getEntityChildren,
- getParentEntity,
isAdjustmentLayer,
isCaption,
isGroup,
@@ -29,15 +27,7 @@ import {
} from '@diffusionstudio/runtime';
import { Button } from '@/components/ui/button';
import { Icon } from '@/components/ui/icon';
-import {
- ContextMenu,
- ContextMenuContent,
- ContextMenuItem,
- ContextMenuPortal,
- ContextMenuSeparator,
- ContextMenuShortcut,
- ContextMenuTrigger,
-} from '@/components/ui/context-menu';
+import { NodeContextMenu, TIMELINE_MENU } from '@/components/commands';
import { Tooltip, TooltipContent, TooltipPortal, TooltipTrigger } from '@/components/ui/tooltip';
import { useEditor } from '@/engine/hooks';
import { DEFAULT_CLIP_HEIGHT, MAX_CLIP_HEIGHT, MIN_CLIP_HEIGHT, getClipFallbackName } from '@/engine/timeline';
@@ -141,21 +131,6 @@ export function NodeLayer(props: LayerRowProps) {
document.addEventListener('pointerup', handleResizeEnd);
};
- const handleRemove = () => editor.remove(entity());
-
- /**
- * The column reads top-down while the file reads bottom-up: the last child
- * of an element is the one drawn on top, so "front" is the end of the file
- * and "back" is the beginning.
- */
- const handleReorder = (target: 'front' | 'back') => {
- const parent = getParentEntity(entity());
- if (!parent) return;
-
- const siblings = getEntityChildren(world, parent).filter((sibling) => sibling !== entity());
- editor.reparent(entity(), parent, target === 'back' ? siblings[0] : undefined);
- };
-
const startEditing = () => {
originalName = name();
setEditing(true);
@@ -193,161 +168,142 @@ export function NodeLayer(props: LayerRowProps) {
};
return (
- <ContextMenu>
- <ContextMenuTrigger
- as="div"
- data-layer-row
- class="w-full text-muted-foreground group relative select-none"
- onPointerEnter={() => setRowHover(world, entity())}
- onPointerLeave={() => setRowHover(world, null)}
- onPointerDown={handleRowPointerDown}
- classList={{
- 'bg-accent': selected(),
- 'bg-accent/70': !selected() && hovering() && resized() === null && drag.dragging() === null,
- 'bg-accent/40': !selected() && !(hovering() && resized() === null) && props.ancestorSelected,
- 'opacity-60': drag.dragging() === entity(),
- }}
- style={{ height: height() + 'px' }}
- >
- <div class="w-full pl-0.5 pr-2 flex items-center justify-between h-full">
+ <NodeContextMenu
+ layout={TIMELINE_MENU}
+ pick={() => [entity()]}
+ data-layer-row
+ class="w-full text-muted-foreground group relative select-none"
+ onPointerEnter={() => setRowHover(world, entity())}
+ onPointerLeave={() => setRowHover(world, null)}
+ onPointerDown={handleRowPointerDown}
+ classList={{
+ 'bg-accent': selected(),
+ 'bg-accent/70': !selected() && hovering() && resized() === null && drag.dragging() === null,
+ 'bg-accent/40': !selected() && !(hovering() && resized() === null) && props.ancestorSelected,
+ 'opacity-60': drag.dragging() === entity(),
+ }}
+ style={{ height: height() + 'px' }}
+ >
+ <div class="w-full pl-0.5 pr-2 flex items-center justify-between h-full">
+ <div
+ data-layer-label
+ class="flex-1 min-w-0 overflow-hidden"
+ style={{
+ 'mask-image': controlsVisible() && !editing() ? 'linear-gradient(to right, #000 calc(100% - 1.25rem), transparent)' : undefined,
+ '-webkit-mask-image': controlsVisible() && !editing() ? 'linear-gradient(to right, #000 calc(100% - 1.25rem), transparent)' : undefined,
+ }}
+ >
<div
- data-layer-label
- class="flex-1 min-w-0 overflow-hidden"
+ class="flex items-center gap-0.5 w-max"
style={{
- 'mask-image': controlsVisible() && !editing() ? 'linear-gradient(to right, #000 calc(100% - 1.25rem), transparent)' : undefined,
- '-webkit-mask-image': controlsVisible() && !editing() ? 'linear-gradient(to right, #000 calc(100% - 1.25rem), transparent)' : undefined,
+ 'padding-left': `${props.depth * NESTED_INDENT_PX}px`,
+ transform: editing() ? 'none' : 'translateX(calc(var(--layer-x, 0px) * -1))',
}}
>
- <div
- class="flex items-center gap-0.5 w-max"
- style={{
- 'padding-left': `${props.depth * NESTED_INDENT_PX}px`,
- transform: editing() ? 'none' : 'translateX(calc(var(--layer-x, 0px) * -1))',
- }}
+ <button
+ disabled={!props.layer.expandable}
+ onClick={toggleExpanded}
+ class="size-4 shrink-0 flex items-center justify-center overflow-clip invisible group-hover/layers:visible focus-ring rounded-sm"
>
- <button
- disabled={!props.layer.expandable}
- onClick={toggleExpanded}
- class="size-4 shrink-0 flex items-center justify-center overflow-clip invisible group-hover/layers:visible focus-ring rounded-sm"
- >
- <Show when={props.layer.expandable}>
- <Icon name={props.expanded ? "chevron-down" : "chevron-right"} class="hover:text-foreground" />
- </Show>
- </button>
- <div class="size-4 shrink-0 flex items-center justify-center overflow-clip mr-0.5">
- <Icon name={icon()} />
- </div>
- <Show
- when={editing()}
- fallback={
- <span class="text-xs px-0.5 shrink-0 whitespace-nowrap text-foreground" onDblClick={startEditing}>
- {name()}
- </span>
- }
- >
- <input
- ref={mountNameInput}
- type="text"
- class="text-xs bg-input border border-primary rounded-sm outline-none px-0.5 w-32 text-foreground"
- value={name()}
- onInput={handleNameInput}
- onKeyDown={handleNameKeyDown}
- onBlur={(e) => finishEditing(e.currentTarget)}
- onPointerDown={(e) => e.stopPropagation()}
- onDblClick={(e) => e.stopPropagation()}
- />
+ <Show when={props.layer.expandable}>
+ <Icon name={props.expanded ? "chevron-down" : "chevron-right"} class="hover:text-foreground" />
</Show>
+ </button>
+ <div class="size-4 shrink-0 flex items-center justify-center overflow-clip mr-0.5">
+ <Icon name={icon()} />
</div>
- </div>
-
- <div
- class="items-center flex gap-0.5 shrink-0 overflow-hidden group-hover:w-auto"
- classList={{
- 'hidden': resized() !== null,
- 'w-0': !(muted() || soloed() || hidden()),
- 'w-auto': muted() || soloed() || hidden(),
- }}
- >
- <Tooltip placement="bottom">
- <TooltipTrigger
- as={Button}
- variant={muted() ? "on" : "ghost"}
- size="icon"
- class="invisible group-hover:visible"
- style={{ visibility: muted() ? 'visible' : undefined }}
- onClick={toggleMuted}
- >
- <Icon name="mute" />
- </TooltipTrigger>
- <TooltipPortal>
- <TooltipContent>{muted() ? "Unmute" : "Mute"}</TooltipContent>
- </TooltipPortal>
- </Tooltip>
- <Tooltip placement="bottom">
- <TooltipTrigger
- as={Button}
- variant={soloed() ? "on" : "ghost"}
- size="icon"
- class="invisible group-hover:visible"
- style={{ visibility: soloed() ? 'visible' : undefined }}
- onClick={toggleSoloed}
- >
- <Icon name="solo" />
- </TooltipTrigger>
- <TooltipPortal>
- <TooltipContent>{soloed() ? "Unsolo" : "Solo"}</TooltipContent>
- </TooltipPortal>
- </Tooltip>
- <Tooltip placement="bottom">
- <TooltipTrigger
- as={Button}
- variant="ghost"
- size="icon"
- class="invisible group-hover:visible"
- onClick={toggleHidden}
- style={{ visibility: hidden() ? 'visible' : undefined }}
- >
- <Show when={!hidden()} fallback={<Icon name="eye-off" />}>
- <Icon name="eye-on" />
- </Show>
- </TooltipTrigger>
- <TooltipPortal>
- <TooltipContent>{hidden() ? "Show" : "Hide"}</TooltipContent>
- </TooltipPortal>
- </Tooltip>
+ <Show
+ when={editing()}
+ fallback={
+ <span class="text-xs px-0.5 shrink-0 whitespace-nowrap text-foreground" onDblClick={startEditing}>
+ {name()}
+ </span>
+ }
+ >
+ <input
+ ref={mountNameInput}
+ type="text"
+ class="text-xs bg-input border border-primary rounded-sm outline-none px-0.5 w-32 text-foreground"
+ value={name()}
+ onInput={handleNameInput}
+ onKeyDown={handleNameKeyDown}
+ onBlur={(e) => finishEditing(e.currentTarget)}
+ onPointerDown={(e) => e.stopPropagation()}
+ onDblClick={(e) => e.stopPropagation()}
+ />
+ </Show>
</div>
</div>
- {/* Drag the bottom edge to make the row taller. */}
<div
- class="absolute bottom-0 left-0 right-0 h-[3px] cursor-ns-resize translate-y-0.5 z-20 group/resize"
- onPointerDown={handleResizeStart}
+ class="items-center flex gap-0.5 shrink-0 overflow-hidden group-hover:w-auto"
+ classList={{
+ 'hidden': resized() !== null,
+ 'w-0': !(muted() || soloed() || hidden()),
+ 'w-auto': muted() || soloed() || hidden(),
+ }}
>
- <div
- class="absolute left-0 right-0 top-px h-px transition-colors group-hover/resize:bg-primary"
- classList={{ 'bg-primary': resized() === entity() }}
- />
+ <Tooltip placement="bottom">
+ <TooltipTrigger
+ as={Button}
+ variant={muted() ? "on" : "ghost"}
+ size="icon"
+ class="invisible group-hover:visible"
+ style={{ visibility: muted() ? 'visible' : undefined }}
+ onClick={toggleMuted}
+ >
+ <Icon name="mute" />
+ </TooltipTrigger>
+ <TooltipPortal>
+ <TooltipContent>{muted() ? "Unmute" : "Mute"}</TooltipContent>
+ </TooltipPortal>
+ </Tooltip>
+ <Tooltip placement="bottom">
+ <TooltipTrigger
+ as={Button}
+ variant={soloed() ? "on" : "ghost"}
+ size="icon"
+ class="invisible group-hover:visible"
+ style={{ visibility: soloed() ? 'visible' : undefined }}
+ onClick={toggleSoloed}
+ >
+ <Icon name="solo" />
+ </TooltipTrigger>
+ <TooltipPortal>
+ <TooltipContent>{soloed() ? "Unsolo" : "Solo"}</TooltipContent>
+ </TooltipPortal>
+ </Tooltip>
+ <Tooltip placement="bottom">
+ <TooltipTrigger
+ as={Button}
+ variant="ghost"
+ size="icon"
+ class="invisible group-hover:visible"
+ onClick={toggleHidden}
+ style={{ visibility: hidden() ? 'visible' : undefined }}
+ >
+ <Show when={!hidden()} fallback={<Icon name="eye-off" />}>
+ <Icon name="eye-on" />
+ </Show>
+ </TooltipTrigger>
+ <TooltipPortal>
+ <TooltipContent>{hidden() ? "Show" : "Hide"}</TooltipContent>
+ </TooltipPortal>
+ </Tooltip>
</div>
- </ContextMenuTrigger>
- <ContextMenuPortal>
- <ContextMenuContent class="w-[160px]">
- <ContextMenuItem onSelect={toggleMuted}>{muted() ? 'Unmute' : 'Mute'}</ContextMenuItem>
- <ContextMenuItem onSelect={toggleSoloed}>{soloed() ? 'Unsolo' : 'Solo'}</ContextMenuItem>
- <ContextMenuItem onSelect={toggleHidden}>{hidden() ? 'Unhide' : 'Hide'}</ContextMenuItem>
- <ContextMenuSeparator />
- <ContextMenuItem onSelect={() => handleReorder('front')}>
- Bring to front
- <ContextMenuShortcut>]</ContextMenuShortcut>
- </ContextMenuItem>
- <ContextMenuItem onSelect={() => handleReorder('back')}>
- Send to back
- <ContextMenuShortcut>[</ContextMenuShortcut>
- </ContextMenuItem>
- <ContextMenuSeparator />
- <ContextMenuItem onSelect={handleRemove}>Remove</ContextMenuItem>
- </ContextMenuContent>
- </ContextMenuPortal>
- </ContextMenu>
+ </div>
+
+ {/* Drag the bottom edge to make the row taller. */}
+ <div
+ class="absolute bottom-0 left-0 right-0 h-[3px] cursor-ns-resize translate-y-0.5 z-20 group/resize"
+ onPointerDown={handleResizeStart}
+ >
+ <div
+ class="absolute left-0 right-0 top-px h-px transition-colors group-hover/resize:bg-primary"
+ classList={{ 'bg-primary': resized() === entity() }}
+ />
+ </div>
+ </NodeContextMenu>
)
}
diff --git a/apps/web/src/components/timeline/timeline.tsx b/apps/web/src/components/timeline/timeline.tsx
index 77064060..13c1756f 100644
--- a/apps/web/src/components/timeline/timeline.tsx
+++ b/apps/web/src/components/timeline/timeline.tsx
@@ -12,6 +12,7 @@ import { insertAssetsInNewScene } from '@/engine/new-scene';
import { useLibrary } from '@/engine/library';
import { useTimeline } from '@/context/timeline';
import { ASSET_DRAG_TYPE } from '@/components/sidebar-left/folder-item';
+import { NodeContextMenu, TIMELINE_MENU } from '@/components/commands';
/**
* The timeline's canvas. What is drawn on it is the timeline system's
@@ -74,13 +75,13 @@ export function Timeline() {
};
return (
- <div class="relative size-full">
+ <NodeContextMenu class="relative size-full" layout={TIMELINE_MENU} pick={timeline.nodesAt}>
<canvas
class="absolute inset-0"
id="timeline-canvas"
on:drop={handleDrop}
on:dragover={handleDragOver}
/>
- </div>
+ </NodeContextMenu>
);
}
diff --git a/apps/web/src/engine/input/shortcuts.ts b/apps/web/src/engine/input/shortcuts.ts
index 9707e227..64a17b29 100644
--- a/apps/web/src/engine/input/shortcuts.ts
+++ b/apps/web/src/engine/input/shortcuts.ts
@@ -10,9 +10,11 @@ import {
Geometry,
Group,
Hidden,
+ Muted,
Position,
Root,
Selected,
+ Soloed,
Time,
Tool,
ToolType,
@@ -343,6 +345,33 @@ export function toggleSelectionHidden(world: World): void {
for (const entity of selected) editor.editProperty(entity, 'hidden', hide);
}
+/**
+ * Mutes the selection, or unmutes it once all of it is muted — the property
+ * the mute button in the layer list writes, one write per node.
+ */
+export function toggleSelectionMuted(world: World): void {
+ const editor = getDocumentEditor(world);
+ const selected = [...world.query(Selected, NODES)];
+ if (!selected.length) return;
+
+ const mute = selected.some(entity => !entity.has(Muted));
+ for (const entity of selected) editor.editProperty(entity, 'muted', mute);
+}
+
+/**
+ * Solos the first selected node, or takes the solo off it. Solo is
+ * monitoring rather than composition, so it is the trait alone, never an
+ * edit, and only one node holds it (as the layer list's solo button has it).
+ */
+export function toggleSelectionSoloed(world: World): void {
+ const [entity] = world.query(Selected, NODES);
+ if (entity === undefined) return;
+
+ const wasSoloed = entity.has(Soloed);
+ for (const other of world.query(Soloed)) other.remove(Soloed);
+ if (!wasSoloed) entity.add(Soloed);
+}
+
/**
* Sends the selection to the front or the back of its siblings. Which of two
* nodes is drawn on top is which of them the file lists last, so a restack is
diff --git a/apps/web/src/engine/timeline/controller.ts b/apps/web/src/engine/timeline/controller.ts
index 1e89b120..4f40c8a7 100644
--- a/apps/web/src/engine/timeline/controller.ts
+++ b/apps/web/src/engine/timeline/controller.ts
@@ -9,7 +9,8 @@
* controller itself never paints.
*/
-import { getTimelineView } from '@diffusionstudio/runtime';
+import { AdjustmentLayer, Geometry, Group, getSelection, getTimelineView } from '@diffusionstudio/runtime';
+import { Or } from 'koota';
import { assert, clamp } from '@/utils';
import { getDocumentEditor } from '@/engine/editor';
@@ -219,6 +220,24 @@ export function createTimelineController(world: World) {
const clientToTime = (clientX: number): number => clientToFrame(clientX) / getFrameRate(world);
+ /**
+ * The nodes a right-click at `event` is on. A clip's regions are scoped
+ * to its entity's id (see `renderClip`), so the scope names the node; a
+ * keyframe's is scoped to its track, which is not one, and stands for
+ * what is selected, as do the ruler and the work area. Empty over the
+ * space behind the rows.
+ */
+ const nodesAt = (event: MouseEvent): Entity[] => {
+ const rect = surface.canvas?.getBoundingClientRect();
+ if (!rect) return [];
+
+ const scope = pointer.regionAt(event.clientX - rect.left, event.clientY - rect.top)?.split('/')[0];
+ if (scope === undefined || scope === 'canvas') return [];
+
+ const node = world.query(Or(Geometry, Group, AdjustmentLayer)).find((entity) => String(entity.id()) === scope);
+ return node ? [node] : getSelection(world);
+ };
+
const setMinimized = (minimized: boolean): void => {
surface.minimized = minimized;
};
@@ -293,6 +312,7 @@ export function createTimelineController(world: World) {
scrollBy,
clientToFrame,
clientToTime,
+ nodesAt,
setMinimized,
};
}
diff --git a/apps/web/src/engine/timeline/pointer.ts b/apps/web/src/engine/timeline/pointer.ts
index 6807f79d..50f29bba 100644
--- a/apps/web/src/engine/timeline/pointer.ts
+++ b/apps/web/src/engine/timeline/pointer.ts
@@ -237,6 +237,26 @@ export function createPointer(options: PointerOptions) {
};
}
+ /**
+ * The id of the region on top at `x`, `y` (CSS pixels of the canvas) among
+ * those the last frame drew, passthrough ones aside; null over none. For
+ * asking between frames, where `region` answers only while drawing.
+ */
+ function regionAt(x: number, y: number): string | null {
+ const canvasX = x * window.devicePixelRatio;
+ const canvasY = y * window.devicePixelRatio;
+
+ const match = hitRegions.prev.findLast(({ minX, minY, maxX, maxY, passthrough }) => (
+ !passthrough &&
+ canvasX >= minX &&
+ canvasX < maxX &&
+ canvasY >= minY &&
+ canvasY < maxY
+ ));
+
+ return match?.id ?? null;
+ }
+
function reset() {
hitRegions.prev = [...hitRegions.next];
hitRegions.next.length = 0;
@@ -273,6 +293,7 @@ export function createPointer(options: PointerOptions) {
up,
scope,
region,
+ regionAt,
reset,
};