The VS Code of video editing, built for agents.
TypeScript
feat: enhance command structure with ready state and update execution logic
konstantin-paulusec84c73d62ee
diff --git a/apps/web/src/components/commands/auto-captions.tsx b/apps/web/src/components/commands/auto-captions.tsxindex e933ae69..364f2969 100644--- a/apps/web/src/components/commands/auto-captions.tsx+++ b/apps/web/src/components/commands/auto-captions.tsx@@ -5,15 +5,21 @@import { Separator } from "@/components/ui/separator";import { useCommand, useCommands } from "@/context/commands";import { useAutoCaptions } from "@/components/genai/use-auto-captions";+import { useSelection } from "@/engine/hooks";import { ActionBar, ActionBarCancel, ActionBarConfirm, ActionBarTarget } from "@/components/canvas/action-bar";export function AutoCaptionsCommand() {+ const { nodes } = useSelection();+ const { scene, generate } = useAutoCaptions();+useCommand({id: "auto-captions",title: "Generate captions",group: "Media",icon: "captions",keywords: ["auto-captions", "subtitles", "transcribe"],+ ready: () => !!scene() && nodes().includes(scene()!),+ run: generate,bar: AutoCaptionsBar,});diff --git a/apps/web/src/components/commands/remove-background.tsx b/apps/web/src/components/commands/remove-background.tsxindex 69da62d6..c356499f 100644--- a/apps/web/src/components/commands/remove-background.tsx+++ b/apps/web/src/components/commands/remove-background.tsx@@ -3,15 +3,20 @@* file, You can obtain one at http://mozilla.org/MPL/2.0/. */import { useCommand } from "@/context/commands";+import { useTransforms } from "@/components/genai/use-transforms";import { TransformBar } from "./transform-bar";export function RemoveBackgroundCommand() {+ const { targets, run } = useTransforms();+useCommand({id: "remove-background",title: "Remove background",group: "Media",icon: "ai-generate",keywords: ["cutout", "matte", "transparent"],+ ready: () => targets("removeBackground").length > 0,+ run: () => run("removeBackground"),bar: () => (<TransformBar type="removeBackground" verb="Remove the background of" empty="Select an image to cut out" />),diff --git a/apps/web/src/components/commands/upscale.tsx b/apps/web/src/components/commands/upscale.tsxindex 45d1e310..4a11528d 100644--- a/apps/web/src/components/commands/upscale.tsx+++ b/apps/web/src/components/commands/upscale.tsx@@ -3,15 +3,20 @@* file, You can obtain one at http://mozilla.org/MPL/2.0/. */import { useCommand } from "@/context/commands";+import { useTransforms } from "@/components/genai/use-transforms";import { TransformBar } from "./transform-bar";export function UpscaleCommand() {+ const { targets, run } = useTransforms();+useCommand({id: "upscale",title: "Upscale",group: "Media",icon: "arrow-scale",keywords: ["resolution", "enhance", "sharpen"],+ ready: () => targets("upscale").length > 0,+ run: () => run("upscale"),bar: () => <TransformBar type="upscale" verb="Upscale" empty="Select an image or video to upscale" />,});diff --git a/apps/web/src/context/commands.tsx b/apps/web/src/context/commands.tsxindex 0cdef395..13ad9244 100644--- a/apps/web/src/context/commands.tsx+++ b/apps/web/src/context/commands.tsx@@ -25,6 +25,7 @@ type CommandAction =/** What picking it does. */run(): void;bar?: never;+ ready?: never;}| {/**@@ -34,6 +35,15 @@ type CommandAction =*/bar: Component;run?: never;+ ready?: never;+ }+ | {+ /** What picking it does while `ready`: what the bar would ask for is settled already. */+ run(): void;+ /** The bar picking it puts up otherwise. */+ bar: Component;+ /** Whether it can run without the bar (what it runs over is selected). */+ ready(): boolean;};export type Command = CommandAction & {@@ -77,8 +87,11 @@ export function CommandsProvider(props: { children: JSX.Element }) {const execute = (command: RegisteredCommand) => {setPaletteOpen(false);- if (command.bar) setActive(command);- else command.run();+ if (!command.bar || command.ready?.()) {+ command.run?.();+ } else {+ setActive(command);+ }};const register = (command: RegisteredCommand) => {