The VS Code of video editing, built for agents.
TypeScript
feat: add reload window command and keyboard shortcuts for asset management
konstantin-paulusf964e5c7982f
diff --git a/apps/web/src/app.tsx b/apps/web/src/app.tsxindex cc1b92f9..468317fc 100644--- a/apps/web/src/app.tsx+++ b/apps/web/src/app.tsx@@ -10,7 +10,7 @@ import { AppContextMenu } from "@/components/app-context-menu";import { AuthProvider, useAuth } from '@/context/auth';import { CommandsProvider } from '@/context/commands';-import { CommandPalette } from '@/components/commands';+import { CommandPalette, ReloadWindowCommand } from '@/components/commands';import { PersistRoute } from '@/lib/persist-route';import { useColorMode } from "@kobalte/core";import { mainBridge } from "@/lib/ipc";@@ -102,6 +102,7 @@ function App() {<CommandsProvider>{props.children}<CommandPalette />+ <ReloadWindowCommand /><BootSplash /><UpgradeDialog /><PurchaseSuccess />diff --git a/apps/web/src/assets/icons/arrow-bottom.svg b/apps/web/src/assets/icons/arrow-bottom.svgnew file mode 100644index 00000000..36e118d2--- /dev/null+++ b/apps/web/src/assets/icons/arrow-bottom.svg@@ -0,0 +1,3 @@+<svg viewBox="0 0 25 25" fill="none" xmlns="http://www.w3.org/2000/svg">+<path fill-rule="evenodd" clip-rule="evenodd" d="M8.1464 13.1464C7.9512 13.3417 7.9512 13.6583 8.1464 13.8535L12.1465 17.8536C12.3417 18.0488 12.6583 18.0488 12.8536 17.8536L16.8536 13.8535C17.0488 13.6583 17.0488 13.3417 16.8536 13.1464C16.6583 12.9512 16.3417 12.9512 16.1464 13.1464L13 16.2929L13 7.5C13 7.2239 12.7761 7 12.5 7C12.2239 7 12 7.2239 12 7.5L12 16.2929L8.8536 13.1464C8.6583 12.9512 8.3417 12.9512 8.1464 13.1464Z" fill="currentColor"/>+</svg>diff --git a/apps/web/src/assets/icons/redo.svg b/apps/web/src/assets/icons/redo.svgnew file mode 100644index 00000000..56c226cf--- /dev/null+++ b/apps/web/src/assets/icons/redo.svg@@ -0,0 +1,3 @@+<svg viewBox="0 0 25 25" fill="none" xmlns="http://www.w3.org/2000/svg">+<path d="M17.5 9.5H11.5A4 4 0 0 0 11.5 17.5H14.5M14.5 6.5L17.5 9.5L14.5 12.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>+</svg>diff --git a/apps/web/src/assets/icons/reload.svg b/apps/web/src/assets/icons/reload.svgnew file mode 100644index 00000000..440dd52d--- /dev/null+++ b/apps/web/src/assets/icons/reload.svg@@ -0,0 +1,3 @@+<svg viewBox="0 0 25 25" fill="none" xmlns="http://www.w3.org/2000/svg">+<path d="M17.2817 8.462C15.3669 6.1957 12.0487 5.5535 9.3888 7.0891C6.3999 8.8148 5.3757 12.6362 7.1013 15.6252C8.8271 18.614 12.6494 19.6384 15.6383 17.9128C17.1682 17.0293 18.1838 15.5955 18.5785 14.0072C18.6425 13.7496 18.4849 13.4891 18.2273 13.425C17.9697 13.3612 17.7091 13.5177 17.6451 13.7753C17.3107 15.1208 16.4523 16.3332 15.1575 17.0808C12.6285 18.5409 9.3945 17.6733 7.9342 15.1444C6.4741 12.6153 7.3406 9.3813 9.8696 7.9211C12.1866 6.5838 15.0948 7.1993 16.6891 9.2565L15.0861 9.1175C14.8216 9.0944 14.5871 9.2906 14.564 9.5551C14.5411 9.8194 14.7374 10.053 15.0016 10.0763L17.5108 10.2951C17.826 10.3225 18.1039 10.0891 18.1315 9.7739L18.3513 7.2657C18.3744 7.0011 18.1782 6.7676 17.9137 6.7445C17.6492 6.7215 17.4166 6.9176 17.3934 7.1821L17.2817 8.462Z" fill="currentColor"/>+</svg>diff --git a/apps/web/src/assets/icons/undo.svg b/apps/web/src/assets/icons/undo.svgnew file mode 100644index 00000000..fc11bc53--- /dev/null+++ b/apps/web/src/assets/icons/undo.svg@@ -0,0 +1,3 @@+<svg viewBox="0 0 25 25" fill="none" xmlns="http://www.w3.org/2000/svg">+<path d="M7.5 9.5H13.5A4 4 0 0 1 13.5 17.5H10.5M10.5 6.5L7.5 9.5L10.5 12.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>+</svg>diff --git a/apps/web/src/components/commands/index.tsx b/apps/web/src/components/commands/index.tsxindex 25bfefcc..b3dbcbb9 100644--- a/apps/web/src/components/commands/index.tsx+++ b/apps/web/src/components/commands/index.tsx@@ -10,16 +10,17 @@ import { MakeVideoCommand } from "./make-video";import { RemoveBackgroundCommand } from "./remove-background";import { RerunCommand } from "./rerun";import { ReuseSettingsCommand } from "./reuse-settings";+import { ShortcutCommands } from "./shortcuts";import { ToolCommand } from "./tool";import { UpscaleCommand } from "./upscale";export { CommandBar } from "./command-bar";export { CommandPalette } from "./palette";+export { ReloadWindowCommand } from "./reload-window";/*** 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.+ * run through, the toolbar's tools, and the keyboard shortcuts.*/export function CanvasCommands() {return (@@ -44,6 +45,7 @@ export function CanvasCommands() {<ToolCommand tool={ToolType.POLYGON} /><ToolCommand tool={ToolType.PEN} /><ToolCommand tool={ToolType.TEXT} />+ <ShortcutCommands /></>);}diff --git a/apps/web/src/components/commands/palette.tsx b/apps/web/src/components/commands/palette.tsxindex 27c542b1..a34af160 100644--- a/apps/web/src/components/commands/palette.tsx+++ b/apps/web/src/components/commands/palette.tsx@@ -7,12 +7,19 @@ import { Dialog } from "@kobalte/core/dialog";import { Command as CommandPrimitive, defaultFilter } from "cmdk-solid";import { Icon } from "@/components/ui/icon";import { Kbd, KbdGroup } from "@/components/ui/kbd";-import { useCommands } from "@/context/commands";+import { SECTIONS, useCommands } from "@/context/commands";import type { RegisteredCommand } from "@/context/commands";const offered = (command: RegisteredCommand) => command.available?.() ?? true;+/**+ * The least score a match needs to be listed. cmdk matches letters anywhere+ * in order, so "group" finds g…r…o…u…p across a command's keywords; such a+ * match scores well under this, a word or prefix or initials well over.+ */+const MIN_SCORE = 0.05;+/*** The command palette, on ⌘K: the commands on offer, by section, found by* typing; the arrows pick one, Enter carries it out.@@ -62,14 +69,15 @@ export function CommandPalette() {);}-type Section = { name: string; commands: RegisteredCommand[] };+type ListedSection = { name: string; commands: RegisteredCommand[] };/*** The commands on offer that match `search`, in sections. Without a search,- * in the order they were registered; with one, the best match first, and the- * section it is in. cmdk scores, but leaves the order alone under Solid.+ * sections in `SECTIONS` order and commands in the order they registered;+ * with one, the best match first, and the section it is in. cmdk scores,+ * but leaves the order alone under Solid.*/-function rank(commands: RegisteredCommand[], search: string): Section[] {+function rank(commands: RegisteredCommand[], search: string): ListedSection[] {const query = search.trim();const matches = commands.filter(offered)@@ -77,8 +85,8 @@ function rank(commands: RegisteredCommand[], search: string): Section[] {command,score: query ? defaultFilter(command.title, query, [command.group, ...(command.keywords ?? [])]) : 1,}))- .filter((match) => match.score > 0)- .sort((a, b) => b.score - a.score);+ .filter((match) => match.score >= MIN_SCORE)+ .sort((a, b) => b.score - a.score || SECTIONS.indexOf(a.command.group) - SECTIONS.indexOf(b.command.group));const byName = new Map<string, RegisteredCommand[]>();for (const { command } of matches) {diff --git a/apps/web/src/components/commands/reload-window.tsx b/apps/web/src/components/commands/reload-window.tsxnew file mode 100644index 00000000..e9d4ad20--- /dev/null+++ b/apps/web/src/components/commands/reload-window.tsx@@ -0,0 +1,20 @@+/* 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";++/** Loads the window again, for when it is stuck; the project reopens from disk. */+export function ReloadWindowCommand() {+ useCommand({+ id: "reload-window",+ title: "Force reload window",+ group: "Window",+ icon: "reload",+ keywords: ["refresh", "restart"],+ shortcut: ["⌘", "R"],+ run: () => window.location.reload(),+ });++ return null;+}diff --git a/apps/web/src/components/commands/shortcuts.tsx b/apps/web/src/components/commands/shortcuts.tsxnew file mode 100644index 00000000..7f3e52a3--- /dev/null+++ b/apps/web/src/components/commands/shortcuts.tsx@@ -0,0 +1,205 @@+/* 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/. */++// The keyboard shortcuts worth finding by name, in the palette under the+// names the project menu gives them: each runs what its keys run, and shows+// the keys.++import { For } from "solid-js";+import { useWorld } from "@diffusionstudio/koota-solid";+import { getActiveEntity, isGroupLike, isSequence, togglePlayback } from "@diffusionstudio/runtime";+import { useCommand } from "@/context/commands";+import {+ getEditHistory,+ groupSelection,+ redoEdit,+ restackSelection,+ splitAtPlayhead,+ toggleSelectionHidden,+ undoEdit,+ ungroupSelection,+ unwrapSequenceSelection,+ useActiveScene,+ useSelection,+ wrapSelectionInScene,+ wrapSelectionInSequence,+} from "@/engine";++import type { Entity, World } from "koota";+import type { Section } from "@/context/commands";+import type { EditHistory } from "@/engine";++/** What a shortcut needs to have something to work on. */+type ShortcutState = {+ /** The selected nodes. */+ nodes: Entity[];+ history: EditHistory;+ scene: Entity | null;+};++type Shortcut = {+ id: string;+ title: string;+ group: Section;+ icon: string;+ /** Its keys, one cap each. */+ keys: string[];+ keywords?: string[];+ run(world: World): void;+ /** Whether it has something to work on; always, when left out. */+ available?(state: ShortcutState): boolean;+};++const selection = ({ nodes }: ShortcutState) => nodes.length > 0;+const activeScene = ({ scene }: ShortcutState) => scene !== null;++const SHORTCUTS: Shortcut[] = [+ {+ id: "group",+ title: "Group",+ group: "Object",+ icon: "group",+ keys: ["⌘", "G"],+ run: groupSelection,+ available: selection,+ },+ {+ id: "ungroup",+ title: "Ungroup",+ group: "Object",+ icon: "group",+ keys: ["⇧", "⌘", "G"],+ run: ungroupSelection,+ available: ({ nodes }) => nodes.some((node) => isGroupLike(node) || isSequence(node)),+ },+ {+ id: "wrap-in-scene",+ title: "Wrap in scene",+ group: "Object",+ icon: "scene-frame-small",+ keys: ["⌘", "↩︎"],+ keywords: ["frame"],+ run: wrapSelectionInScene,+ available: selection,+ },+ {+ id: "wrap-in-sequence",+ title: "Wrap in sequence",+ group: "Object",+ icon: "timeline-sequence-small",+ keys: ["⌥", "⌘", "↩︎"],+ run: wrapSelectionInSequence,+ available: selection,+ },+ {+ id: "unwrap-sequence",+ title: "Unwrap sequence",+ group: "Object",+ icon: "timeline-sequence-small",+ keys: ["⌥", "⇧", "⌘", "↩︎"],+ run: unwrapSequenceSelection,+ available: ({ nodes }) => nodes.some(isSequence),+ },+ {+ id: "bring-to-front",+ title: "Bring to front",+ group: "Object",+ icon: "arrow-top",+ keys: ["]"],+ keywords: ["arrange", "order"],+ run: (world) => restackSelection(world, "front"),+ available: selection,+ },+ {+ id: "send-to-back",+ title: "Send to back",+ group: "Object",+ icon: "arrow-bottom",+ keys: ["["],+ keywords: ["arrange", "order"],+ run: (world) => restackSelection(world, "back"),+ available: selection,+ },+ {+ id: "toggle-hidden",+ title: "Toggle visibility",+ group: "Object",+ icon: "eye-on",+ keys: ["⇧", "⌘", "H"],+ keywords: ["hide", "show"],+ run: toggleSelectionHidden,+ available: selection,+ },+ {+ id: "toggle-playback",+ title: "Play or pause",+ group: "Timeline",+ icon: "play",+ keys: ["Space"],+ keywords: ["playback", "stop"],+ run: (world) => {+ const scene = getActiveEntity(world);+ if (scene) togglePlayback(world, scene);+ },+ available: activeScene,+ },+ {+ id: "split",+ title: "Split at playhead",+ group: "Timeline",+ icon: "split",+ keys: ["⌘", "B"],+ keywords: ["cut", "razor", "blade"],+ run: splitAtPlayhead,+ available: activeScene,+ },+ {+ id: "undo",+ title: "Undo",+ group: "Edit",+ icon: "undo",+ keys: ["⌘", "Z"],+ run: undoEdit,+ available: ({ history }) => history.canUndo(),+ },+ {+ id: "redo",+ title: "Redo",+ group: "Edit",+ icon: "redo",+ keys: ["⇧", "⌘", "Z"],+ run: redoEdit,+ available: ({ history }) => history.canRedo(),+ },+];++/** Every shortcut as a command, sharing one read of what they work on. */+export function ShortcutCommands() {+ const world = useWorld();+ const { nodes } = useSelection();+ const scene = useActiveScene();+ const history = getEditHistory(world);++ const state = (): ShortcutState => ({ nodes: nodes(), history, scene: scene() });++ return <For each={SHORTCUTS}>{(shortcut) => <ShortcutCommand shortcut={shortcut} state={state} />}</For>;+}++function ShortcutCommand(props: { shortcut: Shortcut; state: () => ShortcutState }) {+ const world = useWorld();+ const { shortcut } = props;++ useCommand({+ id: `shortcut:${shortcut.id}`,+ title: shortcut.title,+ group: shortcut.group,+ icon: shortcut.icon,+ keywords: shortcut.keywords,+ shortcut: shortcut.keys,+ available: shortcut.available ? () => shortcut.available!(props.state()) : undefined,+ run: () => shortcut.run(world),+ });++ return null;+}diff --git a/apps/web/src/components/sidebar-left/assets.tsx b/apps/web/src/components/sidebar-left/assets.tsxindex ac581c27..9837f528 100644--- a/apps/web/src/components/sidebar-left/assets.tsx+++ b/apps/web/src/components/sidebar-left/assets.tsx@@ -34,6 +34,7 @@ import { useLibrary } from "@/engine/library";import { useAssetSelection } from "@/engine/hooks";import { droppedFiles, importFiles, insertAssetsAtPlayhead, pickAndImport } from "@/engine/asset-actions";import { isInputTarget } from "@/utils";+import { useCommand } from "@/context/commands";import type { AssetLibrary } from "@diffusionstudio/assets";@@ -494,6 +495,27 @@ export function Assets() {onCleanup(() => window.removeEventListener("keydown", handleShortcut));});+ // The same two in the palette, into the folder the panel is showing.+ useCommand({+ id: "import-assets",+ title: "Import media",+ group: "Assets",+ icon: "download",+ keywords: ["assets", "files", "upload", "add"],+ shortcut: ["⌘", "I"],+ run: () => void handleImportAssets(),+ });++ useCommand({+ id: "new-folder",+ title: "Create folder",+ group: "Assets",+ icon: "navigation.folder",+ keywords: ["new folder", "directory", "organize"],+ shortcut: ["⇧", "⌘", "N"],+ run: handleCreateFolder,+ });+return (<divon:drop={handleDrop}diff --git a/apps/web/src/context/commands.tsx b/apps/web/src/context/commands.tsxindex fb818893..a06306a8 100644--- a/apps/web/src/context/commands.tsx+++ b/apps/web/src/context/commands.tsx@@ -11,28 +11,37 @@ import { createContext, createSignal, getOwner, onCleanup, useContext } from "soimport type { Accessor, Component, JSX, Owner } from "solid-js";+/**+ * The palette's sections, in the order it lists them. Fixed here rather than+ * taken from the order commands register in, which depends on what mounted+ * first and changes as parts of the UI come and go.+ */+export const SECTIONS = ["Timeline", "Assets", "Media", "Object", "Generate", "Tools", "Edit", "Window"] as const;++export type Section = (typeof SECTIONS)[number];+type CommandAction =| {- /** What picking it does. */- run(): void;- bar?: never;- }+ /** What picking it does. */+ run(): void;+ bar?: never;+ }| {- /**- * The action bar picking it puts up, over the canvas until the bar- * closes it (see `useCommands().close`) or Esc does. For commands- * that need a target picked, or a go-ahead, before they run.- */- bar: Component;- run?: never;- };+ /**+ * The action bar picking it puts up, over the canvas until the bar+ * closes it (see `useCommands().close`) or Esc does. For commands+ * that need a target picked, or a go-ahead, before they run.+ */+ bar: Component;+ run?: never;+ };export type Command = CommandAction & {/** Unique among the commands registered at once. */id: string;title: string;- /** The palette section it is listed under; sections come in the order they were first registered. */- group: string;+ /** The palette section it is listed under. */+ group: Section;icon?: string;/** More words the palette finds it by. */keywords?: string[];