Skip to content

The VS Code of video editing, built for agents.

TypeScript

feat: refactor context menu integration and add insert options for assets

konstantin-paulus82ebd30df733
diff --git a/apps/web/src/app.tsx b/apps/web/src/app.tsx
index 468317fc..f6f6f69e 100644
--- a/apps/web/src/app.tsx
+++ b/apps/web/src/app.tsx
@@ -6,7 +6,6 @@ import { Router, HashRouter, Route, useLocation } from '@solidjs/router';
import { ColorModeProvider } from '@kobalte/core';
import { Show, createEffect, createMemo, type JSX } from 'solid-js';
import { Toaster } from "@/components/ui/sonner";
-import { AppContextMenu } from "@/components/app-context-menu";
import { AuthProvider, useAuth } from '@/context/auth';
import { CommandsProvider } from '@/context/commands';
@@ -97,19 +96,17 @@ function App() {
<RouterComponent
root={(props) => (
<ColorModeProvider initialColorMode="dark">
- <AppContextMenu>
- <AuthProvider>
- <CommandsProvider>
- {props.children}
- <CommandPalette />
- <ReloadWindowCommand />
- <BootSplash />
- <UpgradeDialog />
- <PurchaseSuccess />
- <EditorApi />
- </CommandsProvider>
- </AuthProvider>
- </AppContextMenu>
+ <AuthProvider>
+ <CommandsProvider>
+ {props.children}
+ <CommandPalette />
+ <ReloadWindowCommand />
+ <BootSplash />
+ <UpgradeDialog />
+ <PurchaseSuccess />
+ <EditorApi />
+ </CommandsProvider>
+ </AuthProvider>
<Toaster />
<EnvironmentOverlays />
<PersistRoute />
diff --git a/apps/web/src/components/app-context-menu.tsx b/apps/web/src/components/app-context-menu.tsx
deleted file mode 100644
index dbee4b44..00000000
--- a/apps/web/src/components/app-context-menu.tsx
+++ /dev/null
@@ -1,105 +0,0 @@
-/* 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 type { JSX } from "solid-js"
-import {
- ContextMenu,
- ContextMenuContent,
- ContextMenuItem,
- ContextMenuPortal,
- ContextMenuSeparator,
- ContextMenuShortcut,
- ContextMenuTrigger,
-} from "@/components/ui/context-menu"
-
-export function AppContextMenu(props: { children: JSX.Element }) {
- const handleUndo = () => {
- document.execCommand("undo")
- }
-
- const handleRedo = () => {
- document.execCommand("redo")
- }
-
- const handleCut = () => {
- document.execCommand("cut")
- }
-
- const handleCopy = () => {
- document.execCommand("copy")
- }
-
- const handlePaste = async () => {
- try {
- const text = await navigator.clipboard.readText()
- document.execCommand("insertText", false, text)
- } catch {
- document.execCommand("paste")
- }
- }
-
- const handleSelectAll = () => {
- document.execCommand("selectAll")
- }
-
- const handleFullscreen = () => {
- if (document.fullscreenElement) {
- void document.exitFullscreen()
- } else {
- void document.documentElement.requestFullscreen()
- }
- }
-
- const handleReload = () => {
- window.location.reload()
- }
-
-
- return (
- <ContextMenu>
- <ContextMenuTrigger class="contents">
- {props.children}
- </ContextMenuTrigger>
- <ContextMenuPortal>
- <ContextMenuContent class="w-[200px]">
- <ContextMenuItem onSelect={handleUndo}>
- Undo
- <ContextMenuShortcut>⌘Z</ContextMenuShortcut>
- </ContextMenuItem>
- <ContextMenuItem onSelect={handleRedo}>
- Redo
- <ContextMenuShortcut>⇧⌘Z</ContextMenuShortcut>
- </ContextMenuItem>
- <ContextMenuSeparator />
- <ContextMenuItem onSelect={handleCut}>
- Cut
- <ContextMenuShortcut>⌘X</ContextMenuShortcut>
- </ContextMenuItem>
- <ContextMenuItem onSelect={handleCopy}>
- Copy
- <ContextMenuShortcut>⌘C</ContextMenuShortcut>
- </ContextMenuItem>
- <ContextMenuItem onSelect={handlePaste}>
- Paste
- <ContextMenuShortcut>⌘V</ContextMenuShortcut>
- </ContextMenuItem>
- <ContextMenuItem onSelect={handleSelectAll}>
- Select All
- <ContextMenuShortcut>⌘A</ContextMenuShortcut>
- </ContextMenuItem>
- <ContextMenuSeparator />
- <ContextMenuItem onSelect={handleFullscreen}>
- {document.fullscreenElement ? "Exit Fullscreen" : "Fullscreen"}
- <ContextMenuShortcut>F11</ContextMenuShortcut>
- </ContextMenuItem>
- <ContextMenuSeparator />
- <ContextMenuItem onSelect={handleReload}>
- Reload
- <ContextMenuShortcut>⌘R</ContextMenuShortcut>
- </ContextMenuItem>
- </ContextMenuContent>
- </ContextMenuPortal>
- </ContextMenu>
- )
-}
diff --git a/apps/web/src/components/sidebar-left/asset-item.tsx b/apps/web/src/components/sidebar-left/asset-item.tsx
index c49f557e..fe01be29 100644
--- a/apps/web/src/components/sidebar-left/asset-item.tsx
+++ b/apps/web/src/components/sidebar-left/asset-item.tsx
@@ -12,6 +12,9 @@ import {
ContextMenuPortal,
ContextMenuSeparator,
ContextMenuShortcut,
+ ContextMenuSub,
+ ContextMenuSubContent,
+ ContextMenuSubTrigger,
ContextMenuTrigger,
} from "../ui/context-menu";
import { AssetThumbnail } from "../ui/asset-thumbnail";
@@ -29,8 +32,10 @@ export type LazyAssetItemProps = {
onSelect(event: MouseEvent): void;
onContextSelect(): void;
onDragStart(event: DragEvent): void;
+ /** Inserts the selection at the start of the timeline. */
+ onInsertAtStart(): void;
/** Inserts the selection at the playhead. */
- onInsert(): void;
+ onInsertAtPlayhead(): void;
/** Deletes the selection. */
onDelete(): void;
};
@@ -149,9 +154,21 @@ export function LazyAssetItem(props: LazyAssetItemProps) {
</ContextMenuTrigger>
<ContextMenuPortal>
<ContextMenuContent class="w-[180px]">
- <ContextMenuItem onSelect={props.onInsert}>
- Insert at playhead
- </ContextMenuItem>
+ <ContextMenuSub>
+ <ContextMenuSubTrigger>Insert...</ContextMenuSubTrigger>
+ <ContextMenuPortal>
+ <ContextMenuSubContent class="w-[180px]">
+ <ContextMenuItem onSelect={props.onInsertAtStart}>
+ Insert at start
+ <ContextMenuShortcut>⇧,</ContextMenuShortcut>
+ </ContextMenuItem>
+ <ContextMenuItem onSelect={props.onInsertAtPlayhead}>
+ Insert at playhead
+ <ContextMenuShortcut>,</ContextMenuShortcut>
+ </ContextMenuItem>
+ </ContextMenuSubContent>
+ </ContextMenuPortal>
+ </ContextMenuSub>
<Show when={!props.multiple}>
<ContextMenuSeparator />
<ContextMenuItem onSelect={() => setIsRenaming(true)}>
diff --git a/apps/web/src/components/sidebar-left/assets.tsx b/apps/web/src/components/sidebar-left/assets.tsx
index 9837f528..9e6c152f 100644
--- a/apps/web/src/components/sidebar-left/assets.tsx
+++ b/apps/web/src/components/sidebar-left/assets.tsx
@@ -15,9 +15,17 @@ import {
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuPortal,
- DropdownMenuShortcut,
DropdownMenuTrigger,
} from "../ui/dropdown-menu";
+import {
+ ContextMenu,
+ ContextMenuContent,
+ ContextMenuItem,
+ ContextMenuPortal,
+ ContextMenuSeparator,
+ ContextMenuShortcut,
+ ContextMenuTrigger,
+} from "../ui/context-menu";
import { toast } from "somoto";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import {
@@ -32,7 +40,7 @@ import { LazyAssetItem } from "./asset-item";
import { FolderItem, handleFolderDrop, isAssetOrFolderDrag, ASSET_DRAG_TYPE, FOLDER_DRAG_TYPE } from "./folder-item";
import { useLibrary } from "@/engine/library";
import { useAssetSelection } from "@/engine/hooks";
-import { droppedFiles, importFiles, insertAssetsAtPlayhead, pickAndImport } from "@/engine/asset-actions";
+import { droppedFiles, importFiles, insertAssetsAtPlayhead, insertAssetsAtStart, pickAndImport } from "@/engine/asset-actions";
import { isInputTarget } from "@/utils";
import { useCommand } from "@/context/commands";
@@ -237,7 +245,8 @@ export function Assets() {
return assetSelection.ids().map((id) => lib.get(id)).filter((asset) => asset !== undefined);
};
- const insertSelection = () => insertAssetsAtPlayhead(world, selectedAssets());
+ const insertSelectionAtStart = () => insertAssetsAtStart(world, selectedAssets());
+ const insertSelectionAtPlayhead = () => insertAssetsAtPlayhead(world, selectedAssets());
const deleteSelection = async () => {
const lib = library();
@@ -308,7 +317,7 @@ export function Assets() {
return run(lib);
};
- const handleImportAssets = () => withLibrary((lib) => pickAndImport(lib, currentFolder()).then(() => {}));
+ const handleImportAssets = () => withLibrary((lib) => pickAndImport(lib, currentFolder()).then(() => { }));
const handleDrop = async (event: DragEvent) => {
event.preventDefault();
@@ -391,8 +400,9 @@ export function Assets() {
/**
* Finder's keys for the grid: arrows move the selection and Shift-arrows
* grow it, ⌘A selects every item in view and ⌥⌘A or Escape none, ⌘↓ opens
- * the selected folder and ⌘↑ goes up, ⌫ deletes the selection. Handled keys
- * stop here, so the canvas does not act on them too.
+ * the selected folder and ⌘↑ goes up, ⌫ deletes the selection, , inserts it
+ * at the playhead and ⇧, at the start of the timeline. Handled keys stop
+ * here, so the canvas does not act on them too.
*/
const handleKeyDown = (event: KeyboardEvent) => {
const target = event.target as HTMLElement | null;
@@ -422,6 +432,16 @@ export function Assets() {
return;
}
+ // By code: ⇧ turns the comma of ⇧, into another character.
+ if (!command && !event.altKey && event.code === "Comma") {
+ if (assetSelection.ids().length === 0) return;
+ event.preventDefault();
+ event.stopPropagation();
+ if (event.shiftKey) insertSelectionAtStart();
+ else insertSelectionAtPlayhead();
+ return;
+ }
+
// By code: ⌥ turns the A of ⌥⌘A into another character on a Mac.
if (command && event.code === "KeyA") {
event.preventDefault();
@@ -577,41 +597,19 @@ export function Assets() {
</DropdownMenuPortal>
</DropdownMenu>
</Show>
- <DropdownMenu placement="bottom-start">
- <Tooltip>
- <TooltipTrigger<typeof DropdownMenuTrigger>
- as={(triggerProps: object) => (
- <DropdownMenuTrigger<typeof Button>
- {...triggerProps}
- as={(buttonProps) => (
- <Button
- {...buttonProps}
- size="icon"
- variant="ghost"
- aria-label="Add assets"
- class="text-muted-foreground data-expanded:bg-accent data-expanded:text-foreground"
- >
- <Icon name="plus-add" />
- </Button>
- )}
- />
- )}
- />
- <TooltipContent shortcut="⌘I">Import assets</TooltipContent>
- </Tooltip>
- <DropdownMenuPortal>
- <DropdownMenuContent class="w-40">
- <DropdownMenuItem tone="neutral" onSelect={handleImportAssets}>
- Import assets
- <DropdownMenuShortcut>⌘I</DropdownMenuShortcut>
- </DropdownMenuItem>
- <DropdownMenuItem tone="neutral" onSelect={handleCreateFolder}>
- Create folder
- <DropdownMenuShortcut>⇧⌘N</DropdownMenuShortcut>
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenuPortal>
- </DropdownMenu>
+ <Tooltip>
+ <TooltipTrigger
+ as={Button}
+ size="icon"
+ variant="ghost"
+ aria-label="Import assets"
+ class="text-muted-foreground"
+ onClick={handleImportAssets}
+ >
+ <Icon name="plus-add" />
+ </TooltipTrigger>
+ <TooltipContent shortcut="⌘I">Import assets</TooltipContent>
+ </Tooltip>
</div>
</div>
@@ -697,74 +695,107 @@ export function Assets() {
</div>
</div>
</Show>
- <div
- ref={scroller}
- class="flex-1 min-h-0 overflow-y-auto p-4 pt-3"
- onClick={handleBackgroundClick}
- >
- <Show when={isEmptyView() && !isFiltering()}>
- <div class="h-full flex flex-col items-center justify-center gap-4 px-6 pb-[88px] pt-4">
- <div class="flex flex-col items-center gap-1">
- <Icon name="navigation.folder" class="size-8 text-muted-foreground" />
- <span class="text-xs font-450 text-muted-foreground">
- Add media
- </span>
- <p class="text-xxs text-muted-foreground text-center">
- Drag here, import from your computer,{"\n"}
- or, generate something new with AI.
- </p>
+ {/* The grid's own items open their own menus and stop the event,
+ so this one only answers a right-click on empty space. */}
+ <ContextMenu>
+ <ContextMenuTrigger
+ as="div"
+ ref={scroller}
+ class="flex-1 min-h-0 overflow-y-auto p-4 pt-3"
+ onClick={handleBackgroundClick}
+ >
+ <Show when={isEmptyView() && !isFiltering()}>
+ <div class="h-full flex flex-col items-center justify-center gap-4 px-6 pb-[88px] pt-4">
+ <div class="flex flex-col items-center gap-1">
+ <Icon name="navigation.folder" class="size-8 text-muted-foreground" />
+ <span class="text-xs font-450 text-muted-foreground">
+ Add media
+ </span>
+ <p class="text-xxs text-muted-foreground text-center">
+ Drag here, import from your computer,{"\n"}
+ or, generate something new with AI.
+ </p>
+ </div>
+ <div class="flex flex-col gap-2 w-full">
+ <Button variant="secondary" class="w-full" onClick={() => openPromptInput(restoreConfig("IMAGE"))}>
+ Generate with AI
+ </Button>
+ <Button variant="default" class="w-full" onClick={handleImportAssets}>
+ Import media
+ </Button>
+ </div>
</div>
- <div class="flex flex-col gap-2 w-full">
- <Button variant="secondary" class="w-full" onClick={() => openPromptInput(restoreConfig("IMAGE"))}>
- Generate with AI
- </Button>
- <Button variant="default" class="w-full" onClick={handleImportAssets}>
- Import media
- </Button>
+ </Show>
+ <Show when={isEmptyView() && isFiltering()}>
+ <div class="h-full flex items-center justify-center text-xs text-muted-foreground">
+ No matching assets
</div>
- </div>
- </Show>
- <Show when={isEmptyView() && isFiltering()}>
- <div class="h-full flex items-center justify-center text-xs text-muted-foreground">
- No matching assets
- </div>
- </Show>
- <Show when={!isEmptyView()}>
- <div class="grid grid-cols-2 gap-x-2 gap-y-4">
- <For each={visibleFolders()}>
- {(folder) => (
- <FolderItem
- path={folder}
- renaming={renamingFolder() === folder}
- selected={selectedKeys().has(folderKey(folder))}
- multiple={selectedKeys().size > 1 && selectedKeys().has(folderKey(folder))}
- onSelect={(event) => handleItemClick(folderKey(folder), event)}
- onContextSelect={() => handleItemContextMenu(folderKey(folder))}
- onDragStart={(event) => handleItemDragStart(folderKey(folder), event)}
- onRenameStart={() => setRenamingFolder(folder)}
- onRenameEnd={() => setRenamingFolder(null)}
- onOpen={() => openFolder(folder)}
- onDelete={deleteSelection}
- />
- )}
- </For>
- <For each={filteredAssets()}>
- {(asset) => (
- <LazyAssetItem
- asset={asset}
- selected={selectedKeys().has(assetKey(asset.id))}
- multiple={selectedKeys().size > 1 && selectedKeys().has(assetKey(asset.id))}
- onSelect={(event) => handleItemClick(assetKey(asset.id), event)}
- onContextSelect={() => handleItemContextMenu(assetKey(asset.id))}
- onDragStart={(event) => handleItemDragStart(assetKey(asset.id), event)}
- onInsert={insertSelection}
- onDelete={deleteSelection}
- />
- )}
- </For>
- </div>
- </Show>
- </div>
+ </Show>
+ <Show when={!isEmptyView()}>
+ <div class="grid grid-cols-2 gap-x-2 gap-y-4">
+ <For each={visibleFolders()}>
+ {(folder) => (
+ <FolderItem
+ path={folder}
+ renaming={renamingFolder() === folder}
+ selected={selectedKeys().has(folderKey(folder))}
+ multiple={selectedKeys().size > 1 && selectedKeys().has(folderKey(folder))}
+ onSelect={(event) => handleItemClick(folderKey(folder), event)}
+ onContextSelect={() => handleItemContextMenu(folderKey(folder))}
+ onDragStart={(event) => handleItemDragStart(folderKey(folder), event)}
+ onRenameStart={() => setRenamingFolder(folder)}
+ onRenameEnd={() => setRenamingFolder(null)}
+ onOpen={() => openFolder(folder)}
+ onDelete={deleteSelection}
+ />
+ )}
+ </For>
+ <For each={filteredAssets()}>
+ {(asset) => (
+ <LazyAssetItem
+ asset={asset}
+ selected={selectedKeys().has(assetKey(asset.id))}
+ multiple={selectedKeys().size > 1 && selectedKeys().has(assetKey(asset.id))}
+ onSelect={(event) => handleItemClick(assetKey(asset.id), event)}
+ onContextSelect={() => handleItemContextMenu(assetKey(asset.id))}
+ onDragStart={(event) => handleItemDragStart(assetKey(asset.id), event)}
+ onInsertAtStart={insertSelectionAtStart}
+ onInsertAtPlayhead={insertSelectionAtPlayhead}
+ onDelete={deleteSelection}
+ />
+ )}
+ </For>
+ </div>
+ </Show>
+ </ContextMenuTrigger>
+ <ContextMenuPortal>
+ <ContextMenuContent class="w-52">
+ <ContextMenuItem onSelect={handleImportAssets}>
+ Import assets
+ <ContextMenuShortcut>⌘I</ContextMenuShortcut>
+ </ContextMenuItem>
+ <ContextMenuItem onSelect={() => openPromptInput(restoreConfig("IMAGE"))}>
+ Generate with AI
+ </ContextMenuItem>
+ <ContextMenuSeparator />
+ <ContextMenuItem onSelect={handleCreateFolder}>
+ Create folder
+ <ContextMenuShortcut>⇧⌘N</ContextMenuShortcut>
+ </ContextMenuItem>
+ <ContextMenuSeparator />
+ <ContextMenuItem disabled={visibleKeys().length === 0} onSelect={selectAll}>
+ Select all
+ <ContextMenuShortcut>⌘A</ContextMenuShortcut>
+ </ContextMenuItem>
+ <Show when={currentFolder() !== ""}>
+ <ContextMenuItem onSelect={handleGoToParent}>
+ Go to parent folder
+ <ContextMenuShortcut>⌘↑</ContextMenuShortcut>
+ </ContextMenuItem>
+ </Show>
+ </ContextMenuContent>
+ </ContextMenuPortal>
+ </ContextMenu>
</div>
</div>
);
diff --git a/apps/web/src/components/sidebar-right/inspector/asset-picker.tsx b/apps/web/src/components/sidebar-right/inspector/asset-picker.tsx
index 82c7f4a0..7c64dbe6 100644
--- a/apps/web/src/components/sidebar-right/inspector/asset-picker.tsx
+++ b/apps/web/src/components/sidebar-right/inspector/asset-picker.tsx
@@ -23,7 +23,7 @@ import { assetName } from "@diffusionstudio/assets";
import { useTrait, useWorld } from "@diffusionstudio/koota-solid";
import { AssetId, isScene } from "@diffusionstudio/runtime";
import { useLibrary } from "@/engine/library";
-import { insertAssetAtPlayhead, pickAndImport } from "@/engine/asset-actions";
+import { insertAssetAtPlayhead, insertAssetsAtStart, pickAndImport } from "@/engine/asset-actions";
import { ASSET_DRAG_TYPE } from "@/components/sidebar-left/folder-item";
import type { Asset } from "@diffusionstudio/assets";
@@ -180,7 +180,8 @@ export function AssetFillPicker(props: AssetFillPickerProps) {
onSelect={() => props.onSelectAsset(asset)}
onContextSelect={() => props.onSelectAsset(asset)}
onDragStart={(event) => event.dataTransfer?.setData(ASSET_DRAG_TYPE, asset.id)}
- onInsert={() => insertAssetAtPlayhead(world, asset)}
+ onInsertAtStart={() => insertAssetsAtStart(world, [asset])}
+ onInsertAtPlayhead={() => insertAssetAtPlayhead(world, asset)}
onDelete={() => void handleDeleteAsset(asset)}
/>
)}
diff --git a/apps/web/src/engine/asset-actions.ts b/apps/web/src/engine/asset-actions.ts
index 157ba086..8114c31a 100644
--- a/apps/web/src/engine/asset-actions.ts
+++ b/apps/web/src/engine/asset-actions.ts
@@ -82,3 +82,13 @@ export function insertAssetsAtPlayhead(world: World, assets: ReadonlyArray<Asset
}
}
+/** Inserts each of `assets` at the start of the timeline, all starting there. */
+export function insertAssetsAtStart(world: World, assets: ReadonlyArray<Asset>): void {
+ for (const asset of assets) {
+ if (!insertAsset(world, asset, { start: 0 })) {
+ toast("Nothing to insert into", { description: "Open a project first." });
+ return;
+ }
+ }
+}
+