Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

feat(preview): open full image context menu from header dropdown like legacy viewer

joshistoastdf502df814c0
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewActionStrip.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewActionStrip.tsx
index 9b62d1daab..7f4bcedca6 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewActionStrip.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewActionStrip.tsx
@@ -1,42 +1,32 @@
import type { GalleryImage } from '@workbench/gallery/api';
+import type { ImageActions } from '@workbench/image-actions';
-import { HStack, Icon, Menu, Portal, Text } from '@chakra-ui/react';
-import { IconButton, MenuContent, Tooltip } from '@workbench/components/ui';
-import { getGalleryCanvasImportMenuItems, type ImageActions } from '@workbench/image-actions';
-import {
- CopyIcon,
- DownloadIcon,
- ImagesIcon,
- LayersIcon,
- MoreHorizontalIcon,
- StarIcon,
- Trash2Icon,
- type LucideIcon,
-} from 'lucide-react';
-import { useCallback, useMemo } from 'react';
-import { useTranslation } from 'react-i18next';
+import { HStack, Icon } from '@chakra-ui/react';
+import { IconButton, Tooltip } from '@workbench/components/ui';
+import { CopyIcon, DownloadIcon, EllipsisVerticalIcon, ImagesIcon, StarIcon, type LucideIcon } from 'lucide-react';
+import { useCallback, type MouseEvent } from 'react';
import type { PreviewDensity } from './previewDensity';
/**
- * The footer's always-visible action row: the most-used image verbs, one click
- * away instead of buried in the context menu. At full density every action is
- * an icon button; compact/minimal collapse to star + an overflow menu.
+ * The header's always-visible action row: quick verbs one click away, plus an
+ * "image actions" dropdown that opens the full right-click context menu
+ * (anchored under the button) — one source of truth for every image verb,
+ * mirroring the legacy viewer's menu button. Compact densities collapse to
+ * star + the dropdown.
*/
-
-const MENU_POSITIONING = { placement: 'bottom-end' } as const;
-
export const PreviewActionStrip = ({
actions,
density,
image,
+ onOpenMenu,
}: {
actions: ImageActions;
density: PreviewDensity;
image: GalleryImage;
+ /** Opens the view's image context menu at viewport coordinates. */
+ onOpenMenu: ((x: number, y: number) => void) | null;
}) => {
- const { t } = useTranslation();
- const canvasImportItems = useMemo(() => getGalleryCanvasImportMenuItems(false), []);
const toggleStar = useCallback(
() => void actions.setImagesStarred([image.imageName], !image.starred),
[actions, image.imageName, image.starred]
@@ -44,10 +34,13 @@ export const PreviewActionStrip = ({
const selectForCompare = useCallback(() => actions.selectForCompare(image), [actions, image]);
const copyImage = useCallback(() => void actions.copyImage(image), [actions, image]);
const downloadImage = useCallback(() => void actions.downloadImage(image), [actions, image]);
- const deleteImage = useCallback(() => void actions.deleteImages([image.imageName]), [actions, image.imageName]);
- const sendToCanvas = useCallback(
- (destination: (typeof canvasImportItems)[number]['destination']) => void actions.sendToCanvas([image], destination),
- [actions, image]
+ const openMenu = useCallback(
+ (event: MouseEvent<HTMLButtonElement>) => {
+ const rect = event.currentTarget.getBoundingClientRect();
+
+ onOpenMenu?.(rect.left, rect.bottom + 4);
+ },
+ [onOpenMenu]
);
const starLabel = image.starred ? 'Unstar image' : 'Star image';
const starButton = (
@@ -57,50 +50,19 @@ export const PreviewActionStrip = ({
</IconButton>
</Tooltip>
);
+ const menuButton = onOpenMenu ? (
+ <Tooltip content="Image actions">
+ <IconButton aria-label="Image actions" color="fg.muted" size="2xs" variant="ghost" onClick={openMenu}>
+ <Icon as={EllipsisVerticalIcon} boxSize="3.5" />
+ </IconButton>
+ </Tooltip>
+ ) : null;
if (density !== 'full') {
return (
<HStack flexShrink={0} gap="0.5">
{starButton}
- <Menu.Root positioning={MENU_POSITIONING}>
- <Menu.Trigger asChild>
- <IconButton aria-label="Image actions" color="fg.muted" size="2xs" variant="ghost">
- <Icon as={MoreHorizontalIcon} boxSize="3.5" />
- </IconButton>
- </Menu.Trigger>
- <Portal>
- <Menu.Positioner>
- <MenuContent minW="12rem">
- <StripMenuItem
- icon={ImagesIcon}
- label="Select for Compare"
- value="compare"
- onClick={selectForCompare}
- />
- <StripMenuItem icon={CopyIcon} label="Copy to clipboard" value="copy" onClick={copyImage} />
- <StripMenuItem icon={DownloadIcon} label="Download image" value="download" onClick={downloadImage} />
- <Menu.Separator borderColor="border.subtle" />
- {canvasImportItems.map((item) => (
- <StripCanvasImportMenuItem
- key={item.value}
- destination={item.destination}
- label={t(item.label)}
- value={item.value}
- onSend={sendToCanvas}
- />
- ))}
- <Menu.Separator borderColor="border.subtle" />
- <StripMenuItem
- color="fg.error"
- icon={Trash2Icon}
- label="Delete Image"
- value="delete"
- onClick={deleteImage}
- />
- </MenuContent>
- </Menu.Positioner>
- </Portal>
- </Menu.Root>
+ {menuButton}
</HStack>
);
}
@@ -111,29 +73,7 @@ export const PreviewActionStrip = ({
<StripIconButton icon={ImagesIcon} label="Select for Compare" onClick={selectForCompare} />
<StripIconButton icon={CopyIcon} label="Copy to clipboard" onClick={copyImage} />
<StripIconButton icon={DownloadIcon} label="Download image" onClick={downloadImage} />
- <Menu.Root positioning={MENU_POSITIONING}>
- <Menu.Trigger asChild>
- <IconButton aria-label="Send to canvas" color="fg.muted" size="2xs" variant="ghost">
- <Icon as={LayersIcon} boxSize="3.5" />
- </IconButton>
- </Menu.Trigger>
- <Portal>
- <Menu.Positioner>
- <MenuContent minW="12rem">
- {canvasImportItems.map((item) => (
- <StripCanvasImportMenuItem
- key={item.value}
- destination={item.destination}
- label={t(item.label)}
- value={item.value}
- onSend={sendToCanvas}
- />
- ))}
- </MenuContent>
- </Menu.Positioner>
- </Portal>
- </Menu.Root>
- <StripIconButton icon={Trash2Icon} label="Delete Image" onClick={deleteImage} />
+ {menuButton}
</HStack>
);
};
@@ -145,38 +85,3 @@ const StripIconButton = ({ icon, label, onClick }: { icon: LucideIcon; label: st
</IconButton>
</Tooltip>
);
-
-const StripMenuItem = ({
- color,
- icon,
- label,
- value,
- onClick,
-}: {
- color?: string;
- icon: LucideIcon;
- label: string;
- value: string;
- onClick: () => void;
-}) => (
- <Menu.Item color={color} value={value} onClick={onClick}>
- <Icon as={icon} boxSize="3.5" color={color ?? 'fg.subtle'} />
- <Text fontSize="xs">{label}</Text>
- </Menu.Item>
-);
-
-const StripCanvasImportMenuItem = ({
- destination,
- label,
- value,
- onSend,
-}: {
- destination: Parameters<ImageActions['sendToCanvas']>[1];
- label: string;
- value: string;
- onSend: (destination: Parameters<ImageActions['sendToCanvas']>[1]) => void;
-}) => {
- const handleClick = useCallback(() => onSend(destination), [destination, onSend]);
-
- return <StripMenuItem icon={LayersIcon} label={label} value={value} onClick={handleClick} />;
-};
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewHeaderActions.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewHeaderActions.tsx
index 7633f84a3f..5c0bf7b7ff 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewHeaderActions.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewHeaderActions.tsx
@@ -23,7 +23,7 @@ export const PreviewHeaderActions = ({ region }: WidgetViewProps) => {
const { t } = useTranslation();
const showProgressImagesInViewer = useActiveProjectSelector((project) => project.settings.showProgressImagesInViewer);
const hasProgressImage = useProgressImage() !== null;
- const { actionImage, actions } = usePreviewHeaderContext();
+ const { actionImage, actions, openImageMenu } = usePreviewHeaderContext();
const isFilmstripVisible = useActiveProjectSelector((project) =>
getPreviewFilmstripVisible(getProjectWidgetValues(project, 'preview'))
);
@@ -54,6 +54,7 @@ export const PreviewHeaderActions = ({ region }: WidgetViewProps) => {
actions={actions}
density={region === 'center' ? 'full' : 'compact'}
image={actionImage}
+ onOpenMenu={openImageMenu}
/>
<Box bg="border.subtle" flexShrink={0} h="4" w="1px" />
</>
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsx
index 9d0d0ac112..b5ed1785d4 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsx
@@ -436,8 +436,9 @@ export const PreviewWidgetView = ({ region, runtime }: WidgetViewProps) => {
actions: imageActions,
boardName: selectedImageName === null ? null : boardName,
imageName: selectedImageName,
+ openImageMenu: openImageContextMenu,
});
- }, [boardName, contextMenuImage, imageActions, selectedImageName]);
+ }, [boardName, contextMenuImage, imageActions, openImageContextMenu, selectedImageName]);
useEffect(() => () => previewHeaderStore.clear(), []);
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/previewHeaderStore.ts b/invokeai/frontend/webv2/src/workbench/widgets/preview/previewHeaderStore.ts
index 224dd03628..10489446a3 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/previewHeaderStore.ts
+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/previewHeaderStore.ts
@@ -18,9 +18,21 @@ export interface PreviewHeaderContext {
actions: ImageActions | null;
boardName: string | null;
imageName: string | null;
+ /**
+ * Opens the view's full image context menu anchored at viewport coordinates.
+ * The header's "image actions" dropdown reuses the exact right-click menu —
+ * one source of truth for every image verb.
+ */
+ openImageMenu: ((x: number, y: number) => void) | null;
}
-const emptyContext: PreviewHeaderContext = { actionImage: null, actions: null, boardName: null, imageName: null };
+const emptyContext: PreviewHeaderContext = {
+ actionImage: null,
+ actions: null,
+ boardName: null,
+ imageName: null,
+ openImageMenu: null,
+};
const store = createExternalStore<PreviewHeaderContext>(emptyContext);