Skip to content

The VS Code of video editing, built for agents.

TypeScript

feat: add generate command and update auto-captions command title

konstantin-paulus29f214bc39f3
diff --git a/apps/web/src/components/commands/auto-captions.tsx b/apps/web/src/components/commands/auto-captions.tsx
index 14b72231..e933ae69 100644
--- a/apps/web/src/components/commands/auto-captions.tsx
+++ b/apps/web/src/components/commands/auto-captions.tsx
@@ -10,10 +10,10 @@ import { ActionBar, ActionBarCancel, ActionBarConfirm, ActionBarTarget } from "@
export function AutoCaptionsCommand() {
useCommand({
id: "auto-captions",
- title: "Auto-captions",
+ title: "Generate captions",
group: "Media",
icon: "captions",
- keywords: ["subtitles", "transcribe"],
+ keywords: ["auto-captions", "subtitles", "transcribe"],
bar: AutoCaptionsBar,
});
diff --git a/apps/web/src/components/commands/generate.tsx b/apps/web/src/components/commands/generate.tsx
new file mode 100644
index 00000000..ac0b1228
--- /dev/null
+++ b/apps/web/src/components/commands/generate.tsx
@@ -0,0 +1,34 @@
+/* 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 { useCommand } from "@/context/commands";
+import { usePromptInput } from "@/context/prompt-input";
+import { PROMPT_INPUT_MODE_OPTIONS } from "@/components/genai/config";
+import { restoreConfig } from "@/components/genai/saved-config";
+
+import type { PromptMode } from "@/components/genai/config";
+
+const KEYWORDS: Record<PromptMode, string[]> = {
+ IMAGE: ["picture", "photo", "text to image"],
+ VIDEO: ["clip", "animate", "text to video"],
+ VOICE: ["speech", "narration", "voiceover", "text to speech", "tts"],
+ AUDIO: ["sound", "music", "sound effect", "sfx"],
+};
+
+/** Opens the prompt box in `mode`, as it was last left in that mode. */
+export function GenerateCommand(props: { mode: PromptMode }) {
+ const { openPromptInput } = usePromptInput();
+ const option = PROMPT_INPUT_MODE_OPTIONS.find((entry) => entry.value === props.mode)!;
+
+ useCommand({
+ id: `generate:${props.mode}`,
+ title: `Generate ${option.label.toLowerCase()}`,
+ group: "Generate",
+ icon: option.icon,
+ keywords: ["ai", "prompt", "create", ...KEYWORDS[props.mode]],
+ run: () => openPromptInput(restoreConfig(props.mode)),
+ });
+
+ return null;
+}
diff --git a/apps/web/src/components/commands/index.tsx b/apps/web/src/components/commands/index.tsx
index 84754225..25bfefcc 100644
--- a/apps/web/src/components/commands/index.tsx
+++ b/apps/web/src/components/commands/index.tsx
@@ -2,28 +2,48 @@
* 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 { ToolType } from "@diffusionstudio/runtime";
import { AutoCaptionsCommand } from "./auto-captions";
import { EditWithPromptCommand } from "./edit-with-prompt";
+import { GenerateCommand } from "./generate";
import { MakeVideoCommand } from "./make-video";
import { RemoveBackgroundCommand } from "./remove-background";
import { RerunCommand } from "./rerun";
import { ReuseSettingsCommand } from "./reuse-settings";
+import { ToolCommand } from "./tool";
import { UpscaleCommand } from "./upscale";
export { CommandBar } from "./command-bar";
export { CommandPalette } from "./palette";
-/** The commands on the selection in the canvas: what the media can be run through, and generated from. */
+/**
+ * The canvas's commands: what to generate, what the selected media can be
+ * run through, and the toolbar's tools. Sections are listed in the order
+ * they are first mounted here.
+ */
export function CanvasCommands() {
return (
<>
- <UpscaleCommand />
- <RemoveBackgroundCommand />
- <AutoCaptionsCommand />
+ <GenerateCommand mode="IMAGE" />
+ <GenerateCommand mode="VIDEO" />
+ <GenerateCommand mode="VOICE" />
+ <GenerateCommand mode="AUDIO" />
<EditWithPromptCommand />
<MakeVideoCommand />
<RerunCommand />
<ReuseSettingsCommand />
+ <UpscaleCommand />
+ <RemoveBackgroundCommand />
+ <AutoCaptionsCommand />
+ <ToolCommand tool={ToolType.MOVE} />
+ <ToolCommand tool={ToolType.HAND} />
+ <ToolCommand tool={ToolType.OBJECT_MASK} />
+ <ToolCommand tool={ToolType.SCENE} />
+ <ToolCommand tool={ToolType.RECT} />
+ <ToolCommand tool={ToolType.ELLIPSE} />
+ <ToolCommand tool={ToolType.POLYGON} />
+ <ToolCommand tool={ToolType.PEN} />
+ <ToolCommand tool={ToolType.TEXT} />
</>
);
}
diff --git a/apps/web/src/components/commands/palette.tsx b/apps/web/src/components/commands/palette.tsx
index 105981af..27c542b1 100644
--- a/apps/web/src/components/commands/palette.tsx
+++ b/apps/web/src/components/commands/palette.tsx
@@ -129,7 +129,7 @@ function PaletteContent(props: { onPick(command: RegisteredCommand): void }) {
<CommandPrimitive.Item
value={command.id}
onSelect={() => props.onPick(command)}
- class="flex h-8 cursor-default items-center gap-1.5 rounded-lg px-1.5 text-sm text-foreground outline-hidden select-none data-[selected=true]:bg-input [&_svg]:text-muted-foreground data-[selected=true]:[&_svg]:text-foreground"
+ class="flex h-10 cursor-default items-center gap-1.5 rounded-lg px-1.5 text-sm text-foreground outline-hidden select-none data-[selected=true]:bg-input [&_svg]:text-muted-foreground data-[selected=true]:[&_svg]:text-foreground"
>
<Show when={command.icon} fallback={<span class="size-[25px] shrink-0" />}>
{(icon) => <Icon name={icon()} />}
diff --git a/apps/web/src/components/commands/tool.tsx b/apps/web/src/components/commands/tool.tsx
new file mode 100644
index 00000000..8ce1c34e
--- /dev/null
+++ b/apps/web/src/components/commands/tool.tsx
@@ -0,0 +1,51 @@
+/* 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 { Tool, ToolType } from "@diffusionstudio/runtime";
+import { useCommand } from "@/context/commands";
+
+type ToolEntry = {
+ title: string;
+ icon: string;
+ /** The key that picks it outside the palette. */
+ key?: string;
+ keywords: string[];
+};
+
+/** The toolbar's tools, as the palette lists them. */
+const TOOLS: Partial<Record<ToolType, ToolEntry>> = {
+ [ToolType.MOVE]: { title: "Move objects", icon: "move", key: "V", keywords: ["select", "pointer", "cursor"] },
+ [ToolType.HAND]: { title: "Pan canvas", icon: "hand", key: "H", keywords: ["hand", "scroll"] },
+ [ToolType.OBJECT_MASK]: {
+ title: "Mask object",
+ icon: "object-mask",
+ key: "M",
+ keywords: ["smart object mask", "segment", "track", "cutout", "sam", "rotoscope"],
+ },
+ [ToolType.SCENE]: { title: "Create frame", icon: "scene-frame-small", key: "F", keywords: ["scene", "artboard"] },
+ [ToolType.RECT]: { title: "Draw rectangle", icon: "tool.rectangle", key: "R", keywords: ["shape", "square", "box"] },
+ [ToolType.ELLIPSE]: { title: "Draw ellipse", icon: "tool.ellipse", key: "O", keywords: ["shape", "circle", "oval"] },
+ [ToolType.POLYGON]: { title: "Draw polygon", icon: "tool.polygon", keywords: ["shape", "triangle", "star"] },
+ [ToolType.PEN]: { title: "Draw path", icon: "tool.pen", key: "P", keywords: ["pen", "vector", "bezier", "curve"] },
+ [ToolType.TEXT]: { title: "Add text", icon: "tool.text", key: "T", keywords: ["type", "title", "label"] },
+};
+
+/** Picks `tool`, as its toolbar button does. */
+export function ToolCommand(props: { tool: ToolType }) {
+ const world = useWorld();
+ const entry = TOOLS[props.tool]!;
+
+ useCommand({
+ id: `tool:${props.tool}`,
+ title: entry.title,
+ group: "Tools",
+ icon: entry.icon,
+ keywords: ["tool", ...entry.keywords],
+ shortcut: entry.key ? [entry.key] : undefined,
+ run: () => world.set(Tool, { value: props.tool }),
+ });
+
+ return null;
+}