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.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
feat(webv2): open a workflow tile's actions from a menu button beside its title
Josh Corbettfe9673dbb78a
diff --git a/docs/src/content/docs/features/Workflows/editor-interface.mdx b/docs/src/content/docs/features/Workflows/editor-interface.mdxindex 3377619d1f..2c88429a37 100644--- a/docs/src/content/docs/features/Workflows/editor-interface.mdx+++ b/docs/src/content/docs/features/Workflows/editor-interface.mdx@@ -31,7 +31,7 @@ Earlier releases wrote every edit of a workflow opened from the library straight- **This project** lists the workflows saved with the current project, with the active one marked. Open, rename, duplicate or remove them here, start a **New workflow**, or choose **Add workflow** to bring in a template. The active workflow can also be renamed from the editor header's **Workflow actions** menu.- **Browse** lists curated bundled templates, filterable by a fixed set of category tags.- - **Yours** lists templates you have saved; each can be renamed, duplicated, downloaded or deleted from its card menu. The tag filter here is **dynamic** — it shows every unique tag found across your own templates, with a count per tag.+ - **Yours** lists templates you have saved; each can be renamed, duplicated, downloaded or deleted from its card menu, opened from the **⋯** button beside the title or with a right-click. The tag filter here is **dynamic** — it shows every unique tag found across your own templates, with a count per tag.Opening a template adds an independent copy to your project; the template itself is untouched. If the project already has a copy, **Open project copy** switches to it, and **Add another copy** makes a second one.diff --git a/invokeai/frontend/webv2/scripts/run-project-file-journey.mjs b/invokeai/frontend/webv2/scripts/run-project-file-journey.mjsindex 787c0f7a83..d152e827c0 100644--- a/invokeai/frontend/webv2/scripts/run-project-file-journey.mjs+++ b/invokeai/frontend/webv2/scripts/run-project-file-journey.mjs@@ -579,7 +579,11 @@ const runWorkflowCollection = async ({ browser, contexts, errors, imported }) =>// Editing the copy: rename it through the local view. The library is not written.await openProjectWorkflows();assert.equal(await cards.count(), 2);- await dialog.getByRole('button', { exact: true, name: 'More actions' }).click();+ // The rail's menu, not a tile's: every tile now carries its own More-actions button.+ await dialog+ .locator('[data-project-workflow-detail]')+ .getByRole('button', { exact: true, name: 'More actions' })+ .click();await page.getByRole('menuitem', { name: /^Rename…/ }).click();const renameDialog = page.getByRole('dialog', { exact: true, name: 'Rename workflow' });await renameDialog.waitFor();diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/library/ProjectWorkflowsView.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/library/ProjectWorkflowsView.tsxindex dfe0c6d401..4bd09d40aa 100644--- a/invokeai/frontend/webv2/src/features/workflow/ui/library/ProjectWorkflowsView.tsx+++ b/invokeai/frontend/webv2/src/features/workflow/ui/library/ProjectWorkflowsView.tsx@@ -32,7 +32,13 @@ import {toProjectWorkflowLibraryEntries,} from './projectWorkflowEntries';import { formatRelativeTime } from './relativeTime';-import { getWorkflowLibraryCardId } from './WorkflowLibraryCard';+import {+ getWorkflowLibraryCardId,+ getWorkflowLibraryCardMenuContentId,+ keepCardMenuOpenForRetarget,+ type WorkflowCardMenuAnchor,+ type WorkflowLibraryCardProps,+} from './WorkflowLibraryCard';import { WorkflowLibraryGrid } from './WorkflowLibraryGrid';import {resolveEntryRequirements,@@ -50,31 +56,22 @@ const DETAIL_RAIL_WIDTH = '18rem';const THUMBNAIL_ASPECT_RATIO = 3 / 2;export interface ProjectWorkflowsViewProps {- contextMenuPoint: { x: number; y: number } | null;+ contextMenuPoint: WorkflowCardMenuAnchor | null;+ /** What opened the menu last, kept through its close so focus returns there. */+ contextMenuTriggerId: string | null;selectedWorkflowId: string | null;onAddWorkflow: () => void;onClose: () => void;- onContextMenu: (workflowId: string, point: { x: number; y: number }) => void;+ onContextMenu: WorkflowLibraryCardProps['onContextMenu'];onContextMenuClose: () => void;onPreview: (entry: ProjectWorkflowEntry) => void;onSelect: (workflowId: string | null) => void;}-const keepOpenForCardRightClick = (event: { detail: { originalEvent: Event }; preventDefault(): void }) => {- const original = event.detail.originalEvent;-- if (- original instanceof PointerEvent &&- original.button === 2 &&- original.target instanceof Element &&- original.target.closest('[data-workflow-card]') !== null- ) {- event.preventDefault();- }-};export const ProjectWorkflowsView = ({contextMenuPoint,+ contextMenuTriggerId,selectedWorkflowId,onAddWorkflow,onClose,@@ -170,6 +167,7 @@ export const ProjectWorkflowsView = ({entries={entries}error={null}missingCounts={missingCounts}+ openMenuAnchor={contextMenuPoint}selectedWorkflowId={activeSelectionId}status="loaded"onContextMenu={onContextMenu}@@ -178,6 +176,7 @@ export const ProjectWorkflowsView = ({/><ProjectWorkflowDetailPanelcontextMenuPoint={contextMenuPoint}+ contextMenuTriggerId={contextMenuTriggerId}entry={selectedEntry ? selectedEntry.projectWorkflow : null}isActive={selectedEntry?.item.workflow_id === activeWorkflowId}missingCount={selectedEntry ? (missingCounts.get(selectedEntry.item.workflow_id) ?? 0) : 0}@@ -215,7 +214,9 @@ export const ProjectWorkflowsView = ({};interface ProjectWorkflowDetailPanelProps {- contextMenuPoint: { x: number; y: number } | null;+ contextMenuPoint: WorkflowCardMenuAnchor | null;+ /** What opened the menu last, kept through its close so focus returns there. */+ contextMenuTriggerId: string | null;entry: ProjectWorkflowEntry | null;isActive: boolean;missingCount: number;@@ -229,6 +230,7 @@ interface ProjectWorkflowDetailPanelProps {const ProjectWorkflowDetailPanel = ({contextMenuPoint,+ contextMenuTriggerId,entry,isActive,missingCount,@@ -261,12 +263,15 @@ const ProjectWorkflowDetailPanel = ({[deps, libraryEntry]);+ // A pointer point is a fixed rect; the tile button is the menu's trigger, so the menu follows it as it scrolls.const contextMenuPositioning = useMemo(- () => ({- getAnchorRect: () =>- contextMenuPoint ? { height: 1, width: 1, x: contextMenuPoint.x, y: contextMenuPoint.y } : null,- placement: 'bottom-start' as const,- }),+ () =>+ contextMenuPoint?.kind === 'point'+ ? {+ getAnchorRect: () => ({ height: 1, width: 1, x: contextMenuPoint.x, y: contextMenuPoint.y }),+ placement: 'bottom-start' as const,+ }+ : { placement: 'bottom-end' as const },[contextMenuPoint]);const handleContextMenuOpenChange = useCallback(@@ -277,9 +282,16 @@ const ProjectWorkflowDetailPanel = ({},[onContextMenuClose]);+ // Focus returns to whatever opened the menu: the title's menu button, or the right-clicked card.const contextMenuIds = useMemo(- () => (entry ? { trigger: getWorkflowLibraryCardId(entry.document.id) } : undefined),- [entry]+ () =>+ entry+ ? {+ content: getWorkflowLibraryCardMenuContentId(entry.document.id),+ trigger: contextMenuTriggerId ?? getWorkflowLibraryCardId(entry.document.id),+ }+ : undefined,+ [contextMenuTriggerId, entry]);const moreActionsIds = useTooltipTriggerIds();const handleThumbnailError = useCallback(@@ -494,7 +506,7 @@ const ProjectWorkflowDetailPanel = ({open={contextMenuPoint !== null}positioning={contextMenuPositioning}onOpenChange={handleContextMenuOpenChange}- onPointerDownOutside={keepOpenForCardRightClick}+ onPointerDownOutside={keepCardMenuOpenForRetarget}><Portal><Menu.Positioner>diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryCard.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryCard.tsxindex 32fef041e2..c68ab3e19e 100644--- a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryCard.tsx+++ b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryCard.tsx@@ -2,14 +2,16 @@ import type { WorkflowLibraryEntry } from '@features/workflow/data/libraryBrowseimport { Badge, Box, Flex, HStack, Icon, Image, Skeleton, Stack, Text } from '@chakra-ui/react';import { getModelBaseLabel } from '@features/models';+import { IconButton } from '@platform/ui/Button';import { MiddleTruncate } from '@platform/ui/MiddleTruncate';-import { ImageOffIcon } from 'lucide-react';+import { Tooltip } from '@platform/ui/Tooltip';+import { EllipsisIcon, ImageOffIcon } from 'lucide-react';import { useCallback, useState, type MouseEvent } from 'react';import { useTranslation } from 'react-i18next';/**- * Select on click, open on double-click, and select/context-menu on right-click. Reserve enrichment height so- * async facts cannot reflow the grid.+ * Select on click, open on double-click, and select/context-menu on right-click or from the title's own menu+ * button. Reserve enrichment height so async facts cannot reflow the grid.*/const CARD_HOVER = { bg: 'bg.muted', borderColor: 'border.emphasized' } as const;@@ -21,14 +23,59 @@ const THUMBNAIL_ASPECT_RATIO = 3 / 2;/** The card's DOM id, which the rail's context menu names as its trigger so it nests under the dialog's layer. */export const getWorkflowLibraryCardId = (workflowId: string): string => `workflow-library-card-${workflowId}`;+/** The title's menu button; when it opened the menu, it is the trigger focus returns to. */+export const getWorkflowLibraryCardMenuId = (workflowId: string): string =>+ `${getWorkflowLibraryCardId(workflowId)}-menu`;++/**+ * The rail's actions menu content, named so the tile button can point at it: the dialog's focus trap only lets+ * focus into portalled content that an expanded control inside the dialog names with aria-controls.+ */+export const getWorkflowLibraryCardMenuContentId = (workflowId: string): string =>+ `${getWorkflowLibraryCardId(workflowId)}-actions`;++/** What opened a card's actions menu: a pointer position on the card, or the tile's own menu button. */+export type WorkflowCardMenuAnchor =+ | { kind: 'point'; workflowId: string; x: number; y: number }+ | { kind: 'trigger'; workflowId: string; triggerId: string };++/**+ * A right-click on a card, or a click on a tile's menu button, re-anchors or toggles the open menu through its own+ * handler rather than dismissing it as an outside press.+ */+export const keepCardMenuOpenForRetarget = (event: {+ detail: { originalEvent: Event };+ preventDefault(): void;+}): void => {+ const original = event.detail.originalEvent;++ if (!(original instanceof PointerEvent) || !(original.target instanceof Element)) {+ return;+ }++ if (+ (original.button === 2 && original.target.closest('[data-workflow-card]') !== null) ||+ (original.button === 0 && original.target.closest('[data-workflow-card-menu]') !== null)+ ) {+ event.preventDefault();+ }+};++/** The title row's fixed height; the sibling menu button sits on it from outside the card button. */+const TITLE_ROW_HEIGHT = '6';+/** Body padding (2.5) plus the facts row (4) plus the gap (1) below the title row, in px. */+const TITLE_ROW_BOTTOM_PX = 30;+export interface WorkflowLibraryCardProps {entry: WorkflowLibraryEntry;/** The project's active workflow; the card says so in the header. */isActive?: boolean;+ /** Which of the tile's controls has the actions menu open, if any; that control names the menu for the dialog. */+ menuOpenedBy?: 'card' | 'button' | null;isSelected: boolean;/** Models this workflow needs that are not installed; 0 hides the badge. */missingCount: number;- onContextMenu: (workflowId: string, point: { x: number; y: number }) => void;+ onContextMenu: (workflowId: string, anchor: WorkflowCardMenuAnchor) => void;onOpen: (workflowId: string) => void;onSelect: (workflowId: string) => void;}@@ -37,6 +84,7 @@ export const WorkflowLibraryCard = ({entry,isActive = false,isSelected,+ menuOpenedBy = null,missingCount,onContextMenu,onOpen,@@ -60,87 +108,120 @@ export const WorkflowLibraryCard = ({onContextMenu(workflowId,- fromKeyboard ? { x: rect.left + 16, y: rect.top + 16 } : { x: event.clientX, y: event.clientY }+ fromKeyboard+ ? { kind: 'point', workflowId, x: rect.left + 16, y: rect.top + 16 }+ : { kind: 'point', workflowId, x: event.clientX, y: event.clientY });},[onContextMenu, workflowId]);+ const handleMenuButton = useCallback(+ () =>+ onContextMenu(workflowId, { kind: 'trigger', triggerId: getWorkflowLibraryCardMenuId(workflowId), workflowId }),+ [onContextMenu, workflowId]+ );const handleThumbnailError = useCallback(() => setHasThumbnailFailed(true), []);const showThumbnail = Boolean(item.thumbnail_url) && !hasThumbnailFailed;const primaryBase = enrichment.status === 'ready' ? enrichment.requirements.primaryBase : null;+ const menuContentId = getWorkflowLibraryCardMenuContentId(workflowId);++ // The menu button is a sibling of the card button, never nested in it: a button cannot hold another control.return (- <Box- as="button"- aria-pressed={isSelected}- bg={isSelected ? 'bg.emphasized' : 'bg.subtle'}- borderColor={isSelected ? 'accent.solid' : 'border.subtle'}- borderWidth="1px"- data-workflow-card={workflowId}- id={getWorkflowLibraryCardId(workflowId)}- minW="0"- overflow="hidden"- rounded="lg"- textAlign="start"- transition={CARD_TRANSITION}- w="full"- _focusVisible={CARD_FOCUS_VISIBLE}- _hover={CARD_HOVER}- onClick={handleSelect}- onContextMenu={handleContextMenu}- onDoubleClick={handleOpen}- >- <Box aspectRatio={THUMBNAIL_ASPECT_RATIO} bg="bg.muted" overflow="hidden" w="full">- {showThumbnail ? (- <Image- alt=""- h="full"- objectFit="cover"- src={item.thumbnail_url ?? undefined}- w="full"- onError={handleThumbnailError}- />- ) : (- <Flex align="center" direction="column" gap="1" h="full" justify="center" w="full">- <Icon aria-hidden as={ImageOffIcon} boxSize="5" color="fg.subtle" opacity={0.6} />- <Text color="fg.subtle" fontSize="2xs">- {t('workflowLibrary.notRunYet')}- </Text>- </Flex>- )}+ <Box minW="0" position="relative" w="full">+ <Box+ as="button"+ aria-controls={menuOpenedBy === 'card' ? menuContentId : undefined}+ aria-expanded={menuOpenedBy === 'card' ? true : undefined}+ aria-pressed={isSelected}+ bg={isSelected ? 'bg.emphasized' : 'bg.subtle'}+ borderColor={isSelected ? 'accent.solid' : 'border.subtle'}+ borderWidth="1px"+ data-workflow-card={workflowId}+ id={getWorkflowLibraryCardId(workflowId)}+ minW="0"+ overflow="hidden"+ rounded="lg"+ textAlign="start"+ transition={CARD_TRANSITION}+ w="full"+ _focusVisible={CARD_FOCUS_VISIBLE}+ _hover={CARD_HOVER}+ onClick={handleSelect}+ onContextMenu={handleContextMenu}+ onDoubleClick={handleOpen}+ >+ <Box aspectRatio={THUMBNAIL_ASPECT_RATIO} bg="bg.muted" overflow="hidden" w="full">+ {showThumbnail ? (+ <Image+ alt=""+ h="full"+ objectFit="cover"+ src={item.thumbnail_url ?? undefined}+ w="full"+ onError={handleThumbnailError}+ />+ ) : (+ <Flex align="center" direction="column" gap="1" h="full" justify="center" w="full">+ <Icon aria-hidden as={ImageOffIcon} boxSize="5" color="fg.subtle" opacity={0.6} />+ <Text color="fg.subtle" fontSize="2xs">+ {t('workflowLibrary.notRunYet')}+ </Text>+ </Flex>+ )}+ </Box>+ <Stack gap="1" minW="0" p="2.5" w="full">+ <HStack gap="1.5" h={TITLE_ROW_HEIGHT} minW="0" pe="7">+ <MiddleTruncate fontSize="xs" fontWeight="600" minW="0" text={item.name || t('workflowLibrary.untitled')} />+ {isActive ? (+ <Badge data-active-workflow flexShrink={0} size="xs" variant="solid">+ {t('workflowLibrary.activeWorkflow')}+ </Badge>+ ) : null}+ </HStack>+ <HStack gap="1.5" h="4" minW="0">+ {enrichment.status === 'pending' ? (+ // Show placeholders only while enriching; unreadable workflows leave facts absent.+ <Skeleton data-enrichment-placeholder h="3" rounded="sm" w="14" />+ ) : null}+ {primaryBase ? (+ <Badge flexShrink={0} size="xs" variant="subtle">+ {getModelBaseLabel(primaryBase)}+ </Badge>+ ) : null}+ {enrichment.status === 'ready' ? (+ <Text color="fg.muted" fontSize="2xs" truncate>+ {t('workflowLibrary.nodeCount', { count: enrichment.nodeCount })}+ </Text>+ ) : null}+ {missingCount > 0 ? (+ <Badge bg="bg.warning" color="fg.warning" flexShrink={0} size="xs" variant="subtle">+ {t('workflowLibrary.installModels', { count: missingCount })}+ </Badge>+ ) : null}+ </HStack>+ </Stack></Box>- <Stack gap="1" minW="0" p="2.5" w="full">- <HStack gap="1.5" minW="0">- <MiddleTruncate fontSize="xs" fontWeight="600" minW="0" text={item.name || t('workflowLibrary.untitled')} />- {isActive ? (- <Badge data-active-workflow flexShrink={0} size="xs" variant="solid">- {t('workflowLibrary.activeWorkflow')}- </Badge>- ) : null}- </HStack>- <HStack gap="1.5" h="4" minW="0">- {enrichment.status === 'pending' ? (- // Show placeholders only while enriching; unreadable workflows leave facts absent.- <Skeleton data-enrichment-placeholder h="3" rounded="sm" w="14" />- ) : null}- {primaryBase ? (- <Badge flexShrink={0} size="xs" variant="subtle">- {getModelBaseLabel(primaryBase)}- </Badge>- ) : null}- {enrichment.status === 'ready' ? (- <Text color="fg.muted" fontSize="2xs" truncate>- {t('workflowLibrary.nodeCount', { count: enrichment.nodeCount })}- </Text>- ) : null}- {missingCount > 0 ? (- <Badge bg="bg.warning" color="fg.warning" flexShrink={0} size="xs" variant="subtle">- {t('workflowLibrary.installModels', { count: missingCount })}- </Badge>- ) : null}- </HStack>- </Stack>+ <Tooltip content={t('workflowLibrary.moreActions')}>+ <IconButton+ aria-controls={menuOpenedBy === 'button' ? menuContentId : undefined}+ aria-expanded={menuOpenedBy === 'button'}+ aria-haspopup="menu"+ aria-label={t('workflowLibrary.moreActions')}+ bottom={`${TITLE_ROW_BOTTOM_PX}px`}+ color="fg.muted"+ data-workflow-card-menu={workflowId}+ id={getWorkflowLibraryCardMenuId(workflowId)}+ insetEnd="2.5"+ position="absolute"+ size="2xs"+ variant="ghost"+ onClick={handleMenuButton}+ >+ <EllipsisIcon />+ </IconButton>+ </Tooltip></Box>);};diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDetailPanel.browser.test.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDetailPanel.browser.test.tsxindex 69cd45482f..74338db949 100644--- a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDetailPanel.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDetailPanel.browser.test.tsx@@ -326,6 +326,7 @@ describe('WorkflowLibraryDetailPanel', () => {<WorkflowGraphPreviewProvider adapter={GRAPH_PREVIEW}><WorkflowLibraryDetailPanelcontextMenuPoint={null}+ contextMenuTriggerId={null}entry={selected}projectWorkflows={projectWorkflows}onClose={onClose}diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDetailPanel.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDetailPanel.tsxindex c6fa5d06a4..70df297482 100644--- a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDetailPanel.tsx+++ b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDetailPanel.tsx@@ -56,7 +56,12 @@ import type { OpenLibraryWorkflowMode } from './useOpenLibraryWorkflow';import { formatRelativeTime } from './relativeTime';import { planLibraryWorkflowOpen } from './useOpenLibraryWorkflow';-import { getWorkflowLibraryCardId } from './WorkflowLibraryCard';+import {+ getWorkflowLibraryCardId,+ getWorkflowLibraryCardMenuContentId,+ keepCardMenuOpenForRetarget,+ type WorkflowCardMenuAnchor,+} from './WorkflowLibraryCard';import {resolveEntryRequirements,useModelRequirementDeps,@@ -71,7 +76,9 @@ const INSTALL_HOVER = { opacity: 0.85 } as const;export interface WorkflowLibraryDetailPanelProps {/** Where a card's right-click asked for the actions menu; null while it is closed. */- contextMenuPoint: { x: number; y: number } | null;+ contextMenuPoint: WorkflowCardMenuAnchor | null;+ /** What opened the menu last, kept through its close so focus returns there. */+ contextMenuTriggerId: string | null;entry: WorkflowLibraryEntry | null;/** The shell closes the library when a fork takes the user to a new project. */onClose: () => void;@@ -87,18 +94,6 @@ export interface WorkflowLibraryDetailPanelProps {projectWorkflows: readonly ProjectWorkflowEntry[];}-/** A right-click on another card moves the menu there (its own handler re-anchors it) rather than dismissing it. */-const keepOpenForCardRightClick = (event: { detail: { originalEvent: Event }; preventDefault(): void }) => {- const original = event.detail.originalEvent;-- if (original instanceof PointerEvent && original.button === 2 && isCardTarget(original.target)) {- event.preventDefault();- }-};--const isCardTarget = (target: EventTarget | null): boolean =>- target instanceof Element && target.closest('[data-workflow-card]') !== null;-const toFileSlug = (name: string): string => name.trim().replaceAll(/\s+/g, '-').toLowerCase() || 'workflow';const CHOOSER_POSITIONING = { placement: 'top-start' } as const;@@ -125,6 +120,7 @@ const ProjectCopyItem = ({export const WorkflowLibraryDetailPanel = ({contextMenuPoint,+ contextMenuTriggerId,entry,onClose,onContextMenuClose,@@ -381,12 +377,15 @@ export const WorkflowLibraryDetailPanel = ({const openDeleteConfirm = useCallback(() => setIsDeleteConfirmOpen(true), []);const closeDeleteConfirm = useCallback(() => setIsDeleteConfirmOpen(false), []);+ // A pointer point is a fixed rect; the tile button is the menu's trigger, so the menu follows it as it scrolls.const contextMenuPositioning = useMemo(- () => ({- getAnchorRect: () =>- contextMenuPoint ? { height: 1, width: 1, x: contextMenuPoint.x, y: contextMenuPoint.y } : null,- placement: 'bottom-start' as const,- }),+ () =>+ contextMenuPoint?.kind === 'point'+ ? {+ getAnchorRect: () => ({ height: 1, width: 1, x: contextMenuPoint.x, y: contextMenuPoint.y }),+ placement: 'bottom-start' as const,+ }+ : { placement: 'bottom-end' as const },[contextMenuPoint]);const handleContextMenuOpenChange = useCallback(@@ -397,9 +396,16 @@ export const WorkflowLibraryDetailPanel = ({},[onContextMenuClose]);+ // Focus returns to whatever opened the menu: the title's menu button, or the right-clicked card.const contextMenuIds = useMemo(- () => (entry ? { trigger: getWorkflowLibraryCardId(entry.item.workflow_id) } : undefined),- [entry]+ () =>+ entry+ ? {+ content: getWorkflowLibraryCardMenuContentId(entry.item.workflow_id),+ trigger: contextMenuTriggerId ?? getWorkflowLibraryCardId(entry.item.workflow_id),+ }+ : undefined,+ [contextMenuTriggerId, entry]);// The chooser is anchored to the button that opened it, so closing returns focus there.const openButtonId = entry ? `${getWorkflowLibraryCardId(entry.item.workflow_id)}-open` : undefined;@@ -630,7 +636,7 @@ export const WorkflowLibraryDetailPanel = ({open={contextMenuPoint !== null}positioning={contextMenuPositioning}onOpenChange={handleContextMenuOpenChange}- onPointerDownOutside={keepOpenForCardRightClick}+ onPointerDownOutside={keepCardMenuOpenForRetarget}><Portal><Menu.Positioner>diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDialog.browser.test.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDialog.browser.test.tsxindex ba6a95b71f..0b005adfe9 100644--- a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDialog.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDialog.browser.test.tsx@@ -461,6 +461,18 @@ describe('WorkflowLibraryDialog', () => {const buttonWithText = (text: string) =>[...document.querySelectorAll('button')].find((candidate) => (candidate.textContent ?? '') === text);+ /** A pointer press on a tile's menu button: pointerdown (an outside press for an open menu), then the click. */+ const pressTileMenuButton = async (button: HTMLElement | null) => {+ expect(button).not.toBeNull();+ await act(async () => {+ button?.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, button: 0, pointerType: 'mouse' }));+ await settleFrame();+ button?.click();+ await settleFrame();+ await settleFrame();+ });+ };+const clickText = async (text: string) => {const button = buttonWithText(text);expect(button).not.toBeUndefined();@@ -738,6 +750,67 @@ describe('WorkflowLibraryDialog', () => {expect(detail()?.textContent).toContain('Landscape Pass');});+ it("opens a tile's actions from its own menu button, toggles it closed, and hands focus back to the button", async () => {+ await openWith(LOADED_SNAPSHOT);++ const button = document.querySelector<HTMLButtonElement>('[data-workflow-card-menu="wf-landscape"]');+ expect(button).not.toBeNull();+ // A sibling of the card button, never nested inside it.+ expect(document.querySelector('[data-workflow-card="wf-landscape"]')?.tagName).toBe('BUTTON');+ expect(document.querySelector('[data-workflow-card="wf-landscape"]')?.contains(button)).toBe(false);++ await act(async () => {+ button?.click();+ await settleFrame();+ });++ // The button selects its tile and opens the same actions the right-click offers, anchored to the button.+ expect(document.querySelector<HTMLElement>('[data-workflow-detail]')?.dataset.workflowDetail).toBe('wf-landscape');+ const open = () =>+ document.querySelector<HTMLElement>('[data-workflow-context-menu][data-state="open"] [data-menu-item="open"]');+ await vi.waitFor(() => expect(open()).not.toBeNull());+ await vi.waitFor(() => expect(document.activeElement?.closest('[role="menu"]')).not.toBeNull(), { timeout: 2000 });++ await act(async () => {+ await userEvent.keyboard('{Escape}');+ });+ await vi.waitFor(() =>+ expect(document.querySelector('[data-workflow-context-menu][data-state="open"]')).toBeNull()+ );+ expect(document.activeElement).toBe(button);++ // A second press on the same button closes the menu instead of reopening it elsewhere. The press is a pointer+ // sequence, since the pointerdown lands outside the menu and must be kept from dismissing it first.+ await pressTileMenuButton(button);+ await vi.waitFor(() => expect(open()).not.toBeNull());+ expect(button?.getAttribute('aria-expanded')).toBe('true');+ await pressTileMenuButton(button);+ await vi.waitFor(() =>+ expect(document.querySelector('[data-workflow-context-menu][data-state="open"]')).toBeNull()+ );+ expect(button?.getAttribute('aria-expanded')).toBe('false');+ });++ it("moves the open menu to another tile's button and hands the expanded state over", async () => {+ await openWith(LOADED_SNAPSHOT);++ const first = document.querySelector<HTMLButtonElement>('[data-workflow-card-menu="wf-landscape"]');+ const second = document.querySelector<HTMLButtonElement>('[data-workflow-card-menu="wf-portrait"]');+ expect(second).not.toBeNull();++ await pressTileMenuButton(first);+ await vi.waitFor(() => expect(first?.getAttribute('aria-expanded')).toBe('true'));++ await pressTileMenuButton(second);++ await vi.waitFor(() => expect(second?.getAttribute('aria-expanded')).toBe('true'));+ expect(first?.getAttribute('aria-expanded')).toBe('false');+ expect(document.querySelector<HTMLElement>('[data-workflow-detail]')?.dataset.workflowDetail).toBe('wf-portrait');+ await vi.waitFor(() =>+ expect(document.querySelector('[data-workflow-context-menu][data-state="open"]')).not.toBeNull()+ );+ });+it('hands focus to the template rail menu it opens', async () => {await openWith(LOADED_SNAPSHOT);await act(() => card('wf-landscape')?.click());@@ -1136,6 +1209,21 @@ describe('WorkflowLibraryDialog — This project', () => {expect(onOpenChange).toHaveBeenCalledTimes(2);});+ it("opens a project tile's actions from its menu button, including rename", async () => {+ await renderDialog();++ const button = document.querySelector<HTMLButtonElement>('[data-workflow-card-menu="wf-bundled"]');+ await act(async () => {+ button?.click();+ await settleFrame();+ });++ await vi.waitFor(() =>+ expect(document.querySelector('[data-workflow-context-menu] [data-menu-item="rename"]')).not.toBeNull()+ );+ expect(rail()?.dataset.projectWorkflowDetail).toBe('wf-bundled');+ });+it('hands focus to the rail menu it opens, so the pointer can move onto it without closing it', async () => {await renderDialog();diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDialog.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDialog.tsxindex ff89106762..291b50eac1 100644--- a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDialog.tsx+++ b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDialog.tsx@@ -23,6 +23,8 @@ import { CloseButton, SegmentTabs, segmentTabsPanelId, segmentTabsTabId } from 'import { lazy, Suspense, useCallback, useId, useMemo, useRef, useState } from 'react';import { useTranslation } from 'react-i18next';+import type { WorkflowCardMenuAnchor } from './WorkflowLibraryCard';+import { buildLibraryGraphPreviewSource } from './libraryPreviewSource';import { ProjectWorkflowsView } from './ProjectWorkflowsView';import {@@ -109,7 +111,10 @@ export const WorkflowLibraryDialog = ({const [previewRequest, setPreviewRequest] = useState<PreviewRequest | null>(null);// Close before clearing the request so the lazy dialog remains mounted through its exit transition.const [isPreviewOpen, setIsPreviewOpen] = useState(false);- const [contextMenuPoint, setContextMenuPoint] = useState<{ x: number; y: number } | null>(null);+ const [contextMenuPoint, setContextMenuPoint] = useState<WorkflowCardMenuAnchor | null>(null);+ // The element focus returns to when the menu closes. It outlives the open menu: the menu is told it closed only+ // after React has rendered the close, so the trigger it restores focus to must still be the one that opened it.+ const [contextMenuTriggerId, setContextMenuTriggerId] = useState<string | null>(null);const searchTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);const closeDialog = useCallback(() => {@@ -262,13 +267,25 @@ export const WorkflowLibraryDialog = ({setContextMenuPoint(null);}, []);const handleCardContextMenu = useCallback(- (workflowId: string, point: { x: number; y: number }) => {+ (workflowId: string, point: WorkflowCardMenuAnchor) => {if (tab === 'project') {setWorkflowLibrarySelection({ projectId, workflowId });} else {setSelectedWorkflowId(workflowId);}+ setContextMenuTriggerId(point.kind === 'trigger' ? point.triggerId : null);++ // The menu button that opened the menu closes it again.+ if (+ point.kind === 'trigger' &&+ contextMenuPoint?.kind === 'trigger' &&+ contextMenuPoint.triggerId === point.triggerId+ ) {+ setContextMenuPoint(null);+ return;+ }+// An open menu does not follow a new anchor: close it and reopen it at the// new point once that close has rendered, as a native menu relocates.if (contextMenuPoint) {@@ -379,6 +396,7 @@ export const WorkflowLibraryDialog = ({{isProjectTab ? (<ProjectWorkflowsViewcontextMenuPoint={contextMenuPoint}+ contextMenuTriggerId={contextMenuTriggerId}selectedWorkflowId={projectSelectionId}onAddWorkflow={goToTemplates}onClose={closeDialog}@@ -393,6 +411,7 @@ export const WorkflowLibraryDialog = ({entries={entries}error={error}missingCounts={missingCounts}+ openMenuAnchor={contextMenuPoint}selectedWorkflowId={activeWorkflowId}status={status}onContextMenu={handleCardContextMenu}@@ -401,6 +420,7 @@ export const WorkflowLibraryDialog = ({/><WorkflowLibraryDetailPanelcontextMenuPoint={contextMenuPoint}+ contextMenuTriggerId={contextMenuTriggerId}entry={activeEntry}projectWorkflows={projectWorkflows}onClose={closeDialog}diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryGrid.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryGrid.tsxindex 4554105529..ccdea3581b 100644--- a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryGrid.tsx+++ b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryGrid.tsx@@ -7,7 +7,7 @@ import { Scrollable } from '@platform/ui';import { useMemo, useRef } from 'react';import { useTranslation } from 'react-i18next';-import { WorkflowLibraryCard, type WorkflowLibraryCardProps } from './WorkflowLibraryCard';+import { WorkflowLibraryCard, type WorkflowCardMenuAnchor, type WorkflowLibraryCardProps } from './WorkflowLibraryCard';/** How close to the bottom (in viewports) counts as "fetch the next page". */const NEAR_BOTTOM_VIEWPORTS = 1.5;@@ -19,6 +19,8 @@ export interface WorkflowLibraryGridProps {activeWorkflowId?: string | null;entries: readonly WorkflowLibraryEntry[];error: string | null;+ /** What has the actions menu open, so that tile's control can name it. */+ openMenuAnchor?: WorkflowCardMenuAnchor | null;/** Missing-model counts by workflow id; absent ids render no badge. */missingCounts?: ReadonlyMap<string, number>;selectedWorkflowId: string | null;@@ -52,6 +54,7 @@ export const WorkflowLibraryGrid = ({entries,error,missingCounts = NO_MISSING_COUNTS,+ openMenuAnchor = null,onContextMenu,onOpen,onSelect,@@ -106,6 +109,13 @@ export const WorkflowLibraryGrid = ({entry={entry}isActive={entry.item.workflow_id === activeWorkflowId}isSelected={entry.item.workflow_id === selectedWorkflowId}+ menuOpenedBy={+ openMenuAnchor?.workflowId === entry.item.workflow_id+ ? openMenuAnchor.kind === 'trigger'+ ? 'button'+ : 'card'+ : null+ }missingCount={missingCounts.get(entry.item.workflow_id) ?? 0}onContextMenu={onContextMenu}onOpen={onOpen}