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(canvas): preview queued staging progress

joshistoastf6d3456b0f75
diff --git a/invokeai/frontend/webv2/src/workbench/WorkbenchRuntime.tsx b/invokeai/frontend/webv2/src/workbench/WorkbenchRuntime.tsx
index 49f8326b27..c5cd158854 100644
--- a/invokeai/frontend/webv2/src/workbench/WorkbenchRuntime.tsx
+++ b/invokeai/frontend/webv2/src/workbench/WorkbenchRuntime.tsx
@@ -214,17 +214,13 @@ const routeRunResults = async (
}
};
-/** Route one completed backend item from a still-running local batch into Gallery. */
+/** Route one completed backend item from a still-running local batch into its destination. */
const routeBackendItemResults = async (
projectId: string,
queueItem: QueueItem,
backendItemId: number,
dispatch: Dispatch<WorkbenchAction>
): Promise<void> => {
- if (queueItem.snapshot.destination !== 'gallery') {
- return;
- }
-
try {
const resultImageOptions = getQueueItemResultImageOptions(queueItem);
const allImages = resultImageOptions
@@ -232,17 +228,21 @@ const routeBackendItemResults = async (
: await getQueueItemResultImages(backendItemId, queueItem.id, queueItem.snapshot.submittedAt);
const images =
queueItem.snapshot.sourceId === 'workflow' ? allImages.filter((image) => !image.isIntermediate) : allImages;
- const selectedBoardId = getSnapshotGalleryBoardId(queueItem);
+ if (queueItem.snapshot.destination === 'gallery') {
+ const selectedBoardId = getSnapshotGalleryBoardId(queueItem);
- if (selectedBoardId && selectedBoardId !== 'none') {
- await addImagesToGalleryBoard(
- selectedBoardId,
- images.map((image) => image.imageName)
- );
+ if (selectedBoardId && selectedBoardId !== 'none') {
+ await addImagesToGalleryBoard(
+ selectedBoardId,
+ images.map((image) => image.imageName)
+ );
+ }
}
dispatch({ backendItemId, images, projectId, queueItemId: queueItem.id, type: 'routeQueueItemPartialResults' });
- dispatch({ type: 'refreshBackendData' });
+ if (queueItem.snapshot.destination === 'gallery') {
+ dispatch({ type: 'refreshBackendData' });
+ }
} catch (error) {
dispatch({
area: 'queue-results',
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/CanvasWidgetView.tsx b/invokeai/frontend/webv2/src/workbench/widgets/canvas/CanvasWidgetView.tsx
index 2aa9946383..21a17239c6 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/CanvasWidgetView.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/CanvasWidgetView.tsx
@@ -3,7 +3,7 @@ import type { WidgetViewProps } from '@workbench/types';
import type { MouseEvent as ReactMouseEvent } from 'react';
import { Box, Stack } from '@chakra-ui/react';
-import { useProgressImage } from '@workbench/backend/progressImageStore';
+import { useQueueItemProgressImage } from '@workbench/backend/progressImageStore';
import {
createLayerId,
deleteLayerActions,
@@ -12,15 +12,15 @@ import {
reorderIdsForHotkey,
reorderLayerActions,
} from '@workbench/canvasLayerOps';
+import { getCanvasStagingSlots } from '@workbench/canvasStagingView';
import { useWorkbenchSettingsSelector } from '@workbench/settings/store';
import { CanvasLayerContextMenu, type CanvasLayerContextMenuTarget } from '@workbench/widgets/layers/LayerContextMenu';
import { canMergeLayerDown } from '@workbench/widgets/layers/layerOps';
import { getProjectWidgetValues } from '@workbench/widgetState';
import { useActiveProjectSelector, useWorkbenchDispatch } from '@workbench/WorkbenchContext';
-import { useCallback, useEffect, useEffectEvent, useMemo, useState } from 'react';
+import { useCallback, useEffect, useEffectEvent, useState } from 'react';
import { useTranslation } from 'react-i18next';
-import { BboxDetailsBar } from './BboxDetailsBar';
import { gridSizeForModelBase } from './bboxGrid';
import { isCanvasStagingActive } from './canvasInteractionLock';
import {
@@ -32,7 +32,7 @@ import {
import { CanvasSurface } from './CanvasSurface';
import { resolveCheckerColors } from './checkerColors';
import { StagingBar } from './StagingBar';
-import { selectCanvasProgressImage, selectStagedPreviewSource, stagedPreviewKey } from './stagingPreview';
+import { selectStagedPreviewSource, stagedPreviewKey } from './stagingPreview';
import { INLINE_EDIT_SELECTOR } from './surfaceFocus';
import { ToolOptionsBar } from './tool-options/ToolOptionsBar';
import { ToolStrip } from './ToolStrip';
@@ -70,6 +70,8 @@ export const CanvasWidgetView = ({ runtime }: WidgetViewProps) => {
const dispatch = useWorkbenchDispatch();
const engine = useCanvasEngine();
const canvas = useActiveProjectSelector((project) => project.canvas);
+ const queueItems = useActiveProjectSelector((project) => project.queue.items);
+ const antialiasProgressImages = useActiveProjectSelector((project) => project.settings.antialiasProgressImages);
const { document, stagingArea } = canvas;
// Right-click on the canvas surface: hit-test the layer under the cursor, select
@@ -149,46 +151,40 @@ export const CanvasWidgetView = ({ runtime }: WidgetViewProps) => {
engine?.stores.checkerColors.set(resolveCheckerColors());
}, [engine, themeId]);
- const selectedCandidate = stagingArea.pendingImages[stagingArea.selectedImageIndex];
- const hasStagedCandidates = stagingArea.pendingImages.length > 0;
- const hasMultipleCandidates = stagingArea.pendingImages.length > 1;
+ const stagingSlots = getCanvasStagingSlots(canvas, queueItems);
+ const selectedSlot = stagingSlots[stagingArea.selectedImageIndex];
+ const selectedCandidate = selectedSlot?.kind === 'candidate' ? selectedSlot.candidate : undefined;
+ const selectedPlaceholder = selectedSlot?.kind === 'placeholder' ? selectedSlot : null;
+ const hasStagingSlots = stagingSlots.length > 0;
+ const hasMultipleStagingSlots = stagingSlots.length > 1;
- // The pending/running canvas-destination queue items for THIS project, as a
- // stable comma-joined key (so the selector's identity check stays cheap). The
- // staging bar keys off whether any exist; the live progress preview is gated
- // to only these items so a generate-widget run (same project) or another
- // project's run can't draw its denoise frames over this canvas's bbox.
- const canvasQueueItemIdsKey = useActiveProjectSelector((project) =>
- project.queue.items
- .filter(
- (item) =>
- item.snapshot.destination === 'canvas' &&
- (item.status === 'pending' || item.status === 'running') &&
- // Only this canvas SESSION's in-flight items: an item submitted before a
- // wholesale swap (new canvas / snapshot restore) belongs to a document
- // that no longer exists, so its denoise frames must not leak onto the
- // fresh canvas (F2). `documentRevision` bumps only on those swaps.
- item.snapshot.canvas.documentRevision === project.canvas.documentRevision
- )
- .map((item) => item.id)
- .join(',')
+ const isCanvasGenerationInFlight = queueItems.some(
+ (item) =>
+ item.snapshot.destination === 'canvas' &&
+ (item.status === 'pending' || item.status === 'running') &&
+ // Only this canvas SESSION's in-flight items: an item submitted before a
+ // wholesale swap (new canvas / snapshot restore) belongs to a document
+ // that no longer exists, so its denoise frames must not leak onto the
+ // fresh canvas (F2). `documentRevision` bumps only on those swaps.
+ item.snapshot.canvas.documentRevision === canvas.documentRevision
);
- const canvasQueueItemIds = useMemo(
- () => new Set(canvasQueueItemIdsKey ? canvasQueueItemIdsKey.split(',') : []),
- [canvasQueueItemIdsKey]
- );
- const isCanvasGenerationInFlight = canvasQueueItemIds.size > 0;
- const isInteractionLocked = isCanvasStagingActive({ hasStagedCandidates, isCanvasGenerationInFlight });
+ const isInteractionLocked = isCanvasStagingActive({
+ hasStagedCandidates: hasStagingSlots,
+ isCanvasGenerationInFlight,
+ });
useEffect(() => {
engine?.setInteractionLocked(isInteractionLocked);
return () => engine?.setInteractionLocked(false);
}, [engine, isInteractionLocked]);
- // "Show progress on canvas" gates ONLY the live denoise-frame preview; when off,
- // the accepted staged candidate still previews (that's staging, not progress).
- const liveProgressImage = selectCanvasProgressImage(useProgressImage(), canvasQueueItemIds);
- const progressImage = settings[CANVAS_SHOW_PROGRESS_KEY] ? liveProgressImage : null;
+ // "Show progress on canvas" gates ONLY the selected placeholder's live denoise
+ // frame; a selected finished candidate still previews (that's staging, not progress).
+ const selectedPlaceholderProgressImage = useQueueItemProgressImage(
+ selectedPlaceholder?.queueItemId ?? '',
+ selectedPlaceholder?.itemIndex ?? 0
+ );
+ const progressImage = settings[CANVAS_SHOW_PROGRESS_KEY] ? selectedPlaceholderProgressImage : null;
// What the engine should draw as the staged preview: the live denoise-progress
// frame while generating, else the selected candidate, else nothing. The pure
@@ -196,7 +192,7 @@ export const CanvasWidgetView = ({ runtime }: WidgetViewProps) => {
const previewSource = selectStagedPreviewSource({
bboxHeight: document.bbox.height,
bboxWidth: document.bbox.width,
- isGenerationInFlight: isCanvasGenerationInFlight,
+ isGenerationInFlight: selectedPlaceholder !== null,
isVisible: stagingArea.isVisible,
progressImage,
selectedImageName: selectedCandidate?.imageName ?? null,
@@ -225,17 +221,17 @@ export const CanvasWidgetView = ({ runtime }: WidgetViewProps) => {
const selectedIndex = selectedLayerId ? layers.findIndex((layer) => layer.id === selectedLayerId) : -1;
const selectedLayer = selectedIndex >= 0 ? layers[selectedIndex] : undefined;
- if (commandId === 'canvas.prevEntity' && hasStagedCandidates) {
+ if ((commandId === 'canvas.prevEntity' || commandId === 'canvas.nudgeLeft') && hasStagingSlots) {
dispatch({ direction: -1, type: 'cycleStagedImage' });
return;
}
- if (commandId === 'canvas.nextEntity' && hasStagedCandidates) {
+ if ((commandId === 'canvas.nextEntity' || commandId === 'canvas.nudgeRight') && hasStagingSlots) {
dispatch({ direction: 1, type: 'cycleStagedImage' });
return;
}
- if (commandId === 'canvas.deleteSelected' && hasStagedCandidates) {
+ if (commandId === 'canvas.deleteSelected' && selectedCandidate) {
dispatch({ type: 'discardSelectedStagedImage' });
return;
}
@@ -337,8 +333,8 @@ export const CanvasWidgetView = ({ runtime }: WidgetViewProps) => {
useEffect(() => {
const hotkeys = [
- // Staged-candidate cycling keeps `alt+[` / `alt+]`; the bare arrows now nudge
- // the selected layer (see below), so they are no longer bound here.
+ // Staging keeps `alt+[` / `alt+]`; bare left/right are registered as layer nudges,
+ // then intercepted above to cycle staging slots while any slot exists.
['canvas.prevEntity', t('widgets.canvas.commands.previousEntity'), ['alt+[']],
['canvas.nextEntity', t('widgets.canvas.commands.nextEntity'), ['alt+]']],
['canvas.deleteSelected', t('widgets.canvas.commands.deleteSelected'), ['delete', 'backspace']],
@@ -413,16 +409,18 @@ export const CanvasWidgetView = ({ runtime }: WidgetViewProps) => {
* interactive around the bars; each bar re-enables pointer events.
*/}
<Stack align="center" bottom="2" gap="2" left="2" pointerEvents="none" position="absolute" right="2" zIndex="3">
- {hasStagedCandidates || isCanvasGenerationInFlight ? (
+ {hasStagingSlots || isCanvasGenerationInFlight ? (
<StagingBar
+ antialiasProgressImages={antialiasProgressImages}
areThumbnailsVisible={stagingArea.areThumbnailsVisible}
autoSwitchMode={stagingArea.autoSwitchMode}
- hasMultipleCandidates={hasMultipleCandidates}
+ hasMultipleSlots={hasMultipleStagingSlots}
isGenerating={isCanvasGenerationInFlight}
isVisible={stagingArea.isVisible}
- pendingImages={stagingArea.pendingImages}
selectedCandidate={selectedCandidate}
selectedImageIndex={stagingArea.selectedImageIndex}
+ selectedSlot={selectedSlot}
+ slots={stagingSlots}
onAccept={() => dispatch({ type: 'acceptStagedImage' })}
onCycle={(direction) => dispatch({ direction, type: 'cycleStagedImage' })}
onDiscardAll={() => dispatch({ type: 'discardAllStagedImages' })}
@@ -433,7 +431,6 @@ export const CanvasWidgetView = ({ runtime }: WidgetViewProps) => {
onToggleVisibility={() => dispatch({ type: 'toggleCanvasStagingVisibility' })}
/>
) : null}
- {engine && !isInteractionLocked ? <BboxDetailsBar engine={engine} /> : null}
{engine && !isInteractionLocked ? (
<ToolOptionsBar documentHeight={document.height} documentWidth={document.width} engine={engine} />
) : null}
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/StagingBar.tsx b/invokeai/frontend/webv2/src/workbench/widgets/canvas/StagingBar.tsx
index 58f336a5e8..c6e64487d1 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/StagingBar.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/StagingBar.tsx
@@ -1,9 +1,25 @@
/* oxlint-disable react-perf/jsx-no-new-object-as-prop, react-perf/jsx-no-new-function-as-prop */
+import type { CanvasStagingSlot } from '@workbench/canvasStagingView';
import type { CanvasStagingAreaContractV2, CanvasStagingCandidateContract } from '@workbench/types';
-import { HStack, Menu, Portal, ScrollArea, Spinner, Stack, Text } from '@chakra-ui/react';
-import { Button, IconButton, MenuContent, toaster } from '@workbench/components/ui';
+import {
+ Flex,
+ HStack,
+ Menu,
+ Portal,
+ ProgressCircle,
+ ScrollArea,
+ Skeleton,
+ Spinner,
+ Stack,
+ Text,
+} from '@chakra-ui/react';
+import { useQueueItemProgressImage } from '@workbench/backend/progressImageStore';
+import { useQueueItemProgress } from '@workbench/backend/progressStore';
+import { Button, IconButton, MenuContent, toaster, Tooltip } from '@workbench/components/ui';
import { getImageThumbnailUrl, saveImageToGallery } from '@workbench/gallery/api';
+import { StreamingImageFrame } from '@workbench/images/StreamingImageFrame';
+import { progressImageToStreamingSource } from '@workbench/images/streamingImageSource';
import { CanvasOptionsBar } from '@workbench/widgets/canvas/tool-options/CanvasOptionsBar';
import {
CheckIcon,
@@ -13,28 +29,33 @@ import {
ChevronUpIcon,
EyeIcon,
EyeOffIcon,
- ImagePlusIcon,
+ SaveIcon,
SparklesIcon,
Trash2Icon,
+ XIcon,
} from 'lucide-react';
import { useState } from 'react';
import { useTranslation } from 'react-i18next';
+import { CanvasFloatingBarDivider } from './CanvasFloatingBar';
+
type AutoSwitchMode = CanvasStagingAreaContractV2['autoSwitchMode'];
const THUMBNAIL_STRIP_HEIGHT = '5rem';
-const AUTO_SWITCH_MODES: AutoSwitchMode[] = ['off', 'latest', 'oldest'];
+const AUTO_SWITCH_MODES: AutoSwitchMode[] = ['off', 'progress', 'latest'];
const MENU_POSITIONING = { placement: 'top-end' } as const;
interface StagingBarProps {
+ antialiasProgressImages: boolean;
areThumbnailsVisible: boolean;
autoSwitchMode: AutoSwitchMode;
- hasMultipleCandidates: boolean;
+ hasMultipleSlots: boolean;
isGenerating: boolean;
isVisible: boolean;
- pendingImages: CanvasStagingCandidateContract[];
selectedCandidate: CanvasStagingCandidateContract | undefined;
selectedImageIndex: number;
+ selectedSlot: CanvasStagingSlot | undefined;
+ slots: CanvasStagingSlot[];
onAccept: () => void;
onCycle: (direction: -1 | 1) => void;
onDiscardAll: () => void;
@@ -55,14 +76,16 @@ interface StagingBarProps {
* options bar; positioning is the parent's job.
*/
export const StagingBar = ({
+ antialiasProgressImages,
areThumbnailsVisible,
autoSwitchMode,
- hasMultipleCandidates,
+ hasMultipleSlots,
isGenerating,
isVisible,
- pendingImages,
selectedCandidate,
selectedImageIndex,
+ selectedSlot,
+ slots,
onAccept,
onCycle,
onDiscardAll,
@@ -74,7 +97,7 @@ export const StagingBar = ({
}: StagingBarProps) => {
const { t } = useTranslation();
const [isSaving, setIsSaving] = useState(false);
- const hasCandidates = pendingImages.length > 0;
+ const hasSlots = slots.length > 0;
const handleSaveToGallery = async () => {
if (!selectedCandidate || isSaving) {
@@ -97,7 +120,7 @@ export const StagingBar = ({
return (
<Stack align="center" gap="2" w="full">
- {hasCandidates ? (
+ {hasSlots ? (
<ScrollArea.Root
h={areThumbnailsVisible ? THUMBNAIL_STRIP_HEIGHT : '0'}
opacity={areThumbnailsVisible ? 1 : 0}
@@ -110,12 +133,13 @@ export const StagingBar = ({
<ScrollArea.Viewport h="full" w="full">
<ScrollArea.Content asChild>
<HStack h="full" justify="center">
- {pendingImages.map((candidate, index) => (
+ {slots.map((slot, index) => (
<StagingThumbnail
- key={`${candidate.sourceQueueItemId}-${candidate.imageName}`}
- candidate={candidate}
+ key={slot.id}
+ antialiasProgressImages={antialiasProgressImages}
index={index}
isSelected={index === selectedImageIndex}
+ slot={slot}
onSelect={() => onSelectImage(index)}
/>
))}
@@ -129,95 +153,117 @@ export const StagingBar = ({
) : null}
<CanvasOptionsBar>
- <HStack gap="2">
- {isGenerating ? (
- <HStack color="fg.muted" gap="1.5" px="1">
- <Spinner size="xs" />
- <Text fontSize="xs" fontWeight="600">
- {t('widgets.canvas.staging.generating')}
- </Text>
- </HStack>
- ) : null}
-
- {hasCandidates && selectedCandidate ? (
- <>
- <IconButton
- aria-label={
- areThumbnailsVisible
- ? t('widgets.canvas.hideStagingThumbnails')
- : t('widgets.canvas.showStagingThumbnails')
- }
- size="xs"
- variant="ghost"
- onClick={onToggleThumbnails}
- >
- {areThumbnailsVisible ? <ChevronDownIcon /> : <ChevronUpIcon />}
- </IconButton>
+ {isGenerating ? (
+ <HStack color="fg.muted" gap="1.5" px="1">
+ <Spinner size="xs" />
+ <Text fontSize="xs" fontWeight="600">
+ {t('widgets.canvas.staging.generating')}
+ </Text>
+ </HStack>
+ ) : null}
- <HStack gap="0.5">
- <IconButton
- aria-label={t('widgets.canvas.previousStagedCandidate')}
- disabled={!hasMultipleCandidates}
- size="xs"
- variant="ghost"
- onClick={() => onCycle(-1)}
- >
- <ChevronLeftIcon />
- </IconButton>
- <Text fontSize="xs" fontVariantNumeric="tabular-nums" minW="3.5rem" px="1" textAlign="center">
- {t('widgets.canvas.candidateCount', {
- current: selectedImageIndex + 1,
- total: pendingImages.length,
- })}
- </Text>
- <IconButton
- aria-label={t('widgets.canvas.nextStagedCandidate')}
- disabled={!hasMultipleCandidates}
- size="xs"
- variant="ghost"
- onClick={() => onCycle(1)}
- >
- <ChevronRightIcon />
- </IconButton>
- </HStack>
+ {hasSlots && selectedSlot ? (
+ <>
+ <IconButton
+ aria-label={
+ areThumbnailsVisible
+ ? t('widgets.canvas.hideStagingThumbnails')
+ : t('widgets.canvas.showStagingThumbnails')
+ }
+ size="xs"
+ variant="ghost"
+ onClick={onToggleThumbnails}
+ >
+ {areThumbnailsVisible ? <ChevronDownIcon /> : <ChevronUpIcon />}
+ </IconButton>
+ <HStack gap="0.5">
<IconButton
- aria-label={
- isVisible ? t('widgets.canvas.hideStagedResultPreview') : t('widgets.canvas.showStagedResultPreview')
- }
+ aria-label={t('widgets.canvas.previousStagedCandidate')}
+ disabled={!hasMultipleSlots}
size="xs"
variant="ghost"
- onClick={onToggleVisibility}
+ onClick={() => onCycle(-1)}
>
- {isVisible ? <EyeIcon /> : <EyeOffIcon />}
+ <ChevronLeftIcon />
</IconButton>
-
+ <Text fontSize="xs" fontVariantNumeric="tabular-nums" minW="3.5rem" px="1" textAlign="center">
+ {t('widgets.canvas.candidateCount', {
+ current: selectedImageIndex + 1,
+ total: slots.length,
+ })}
+ </Text>
<IconButton
- aria-label={t('widgets.canvas.staging.saveToGallery')}
- disabled={isSaving}
+ aria-label={t('widgets.canvas.nextStagedCandidate')}
+ disabled={!hasMultipleSlots}
size="xs"
variant="ghost"
- onClick={handleSaveToGallery}
+ onClick={() => onCycle(1)}
>
- {isSaving ? <Spinner size="xs" /> : <ImagePlusIcon />}
+ <ChevronRightIcon />
</IconButton>
+ </HStack>
- <IconButton aria-label={t('common.discard')} size="xs" variant="ghost" onClick={onDiscardSelected}>
- <Trash2Icon />
- </IconButton>
+ <CanvasFloatingBarDivider />
- <Button size="xs" variant="ghost" onClick={onDiscardAll}>
- {t('common.discardAll')}
- </Button>
+ <AutoSwitchMenu mode={autoSwitchMode} onSelect={onSetAutoSwitch} />
+
+ {selectedCandidate ? (
+ <>
+ <Tooltip
+ content={
+ isVisible
+ ? t('widgets.canvas.hideStagedResultPreview')
+ : t('widgets.canvas.showStagedResultPreview')
+ }
+ >
+ <IconButton
+ aria-label={
+ isVisible
+ ? t('widgets.canvas.hideStagedResultPreview')
+ : t('widgets.canvas.showStagedResultPreview')
+ }
+ size="xs"
+ variant="ghost"
+ onClick={onToggleVisibility}
+ >
+ {isVisible ? <EyeIcon /> : <EyeOffIcon />}
+ </IconButton>
+ </Tooltip>
- <AutoSwitchMenu mode={autoSwitchMode} onSelect={onSetAutoSwitch} />
+ <Tooltip content={t('widgets.canvas.staging.saveToGallery')}>
+ <IconButton
+ aria-label={t('widgets.canvas.staging.saveToGallery')}
+ disabled={isSaving}
+ size="xs"
+ variant="ghost"
+ onClick={handleSaveToGallery}
+ >
+ {isSaving ? <Spinner size="xs" /> : <SaveIcon />}
+ </IconButton>
+ </Tooltip>
- <Button size="xs" onClick={onAccept}>
- {t('widgets.canvas.acceptToLayer')}
- </Button>
- </>
- ) : null}
- </HStack>
+ <Tooltip content={t('common.discard')}>
+ <IconButton aria-label={t('common.discard')} size="xs" variant="ghost" onClick={onDiscardSelected}>
+ <XIcon />
+ </IconButton>
+ </Tooltip>
+
+ <CanvasFloatingBarDivider />
+
+ <Button size="xs" variant="ghost" onClick={onDiscardAll}>
+ <Trash2Icon />
+ {t('common.discardAll')}
+ </Button>
+
+ <Button size="xs" onClick={onAccept}>
+ <CheckIcon />
+ {t('widgets.canvas.acceptToLayer')}
+ </Button>
+ </>
+ ) : null}
+ </>
+ ) : null}
</CanvasOptionsBar>
</Stack>
);
@@ -229,30 +275,35 @@ const AutoSwitchMenu = ({ mode, onSelect }: { mode: AutoSwitchMode; onSelect: (m
t(
value === 'off'
? 'widgets.canvas.staging.autoSwitchOff'
- : value === 'latest'
- ? 'widgets.canvas.staging.autoSwitchLatest'
- : 'widgets.canvas.staging.autoSwitchOldest'
+ : value === 'progress'
+ ? 'widgets.canvas.staging.autoSwitchProgress'
+ : 'widgets.canvas.staging.autoSwitchLatest'
);
return (
<Menu.Root positioning={MENU_POSITIONING}>
- <Menu.Trigger asChild>
- <IconButton aria-label={t('widgets.canvas.staging.autoSwitch')} minW="unset" px="2" size="xs" variant="ghost">
- <HStack gap="1">
- <SparklesIcon size={13} />
- <Text fontSize="xs">{label(mode)}</Text>
- </HStack>
- </IconButton>
- </Menu.Trigger>
+ <Tooltip content={t('widgets.canvas.staging.autoSwitch')}>
+ <span style={{ display: 'inline-flex' }}>
+ <Menu.Trigger asChild>
+ <Button minW="unset" px="2" size="xs" variant="ghost">
+ <SparklesIcon size={13} />
+ <Text fontSize="xs">{label(mode)}</Text>
+ </Button>
+ </Menu.Trigger>
+ </span>
+ </Tooltip>
<Portal>
<Menu.Positioner>
<MenuContent minW="8rem" py="1">
- {AUTO_SWITCH_MODES.map((value) => (
- <Menu.Item key={value} value={value} onClick={() => onSelect(value)}>
- <CheckIcon size={12} opacity={mode === value ? 1 : 0} />
- <Menu.ItemText fontSize="xs">{label(value)}</Menu.ItemText>
- </Menu.Item>
- ))}
+ <Menu.ItemGroup>
+ <Menu.ItemGroupLabel>{t('widgets.canvas.staging.autoSwitch')}</Menu.ItemGroupLabel>
+ {AUTO_SWITCH_MODES.map((value) => (
+ <Menu.Item key={value} value={value} onClick={() => onSelect(value)}>
+ <CheckIcon size={12} opacity={mode === value ? 1 : 0} />
+ <Menu.ItemText fontSize="xs">{label(value)}</Menu.ItemText>
+ </Menu.Item>
+ ))}
+ </Menu.ItemGroup>
</MenuContent>
</Menu.Positioner>
</Portal>
@@ -261,14 +312,16 @@ const AutoSwitchMenu = ({ mode, onSelect }: { mode: AutoSwitchMode; onSelect: (m
};
const StagingThumbnail = ({
- candidate,
+ antialiasProgressImages,
index,
isSelected,
+ slot,
onSelect,
}: {
- candidate: CanvasStagingCandidateContract;
+ antialiasProgressImages: boolean;
index: number;
isSelected: boolean;
+ slot: CanvasStagingSlot;
onSelect: () => void;
}) => {
const { t } = useTranslation();
@@ -289,11 +342,15 @@ const StagingThumbnail = ({
style={{ aspectRatio: '1 / 1' }}
onClick={onSelect}
>
- <img
- alt={candidate.imageName}
- src={candidate.thumbnailUrl || getImageThumbnailUrl(candidate.imageName)}
- style={{ display: 'block', height: '100%', objectFit: 'cover', width: '100%' }}
- />
+ {slot.kind === 'candidate' ? (
+ <img
+ alt={slot.candidate.imageName}
+ src={slot.candidate.thumbnailUrl || getImageThumbnailUrl(slot.candidate.imageName)}
+ style={{ display: 'block', height: '100%', objectFit: 'cover', width: '100%' }}
+ />
+ ) : (
+ <StagingPlaceholderThumbnail antialiasProgressImages={antialiasProgressImages} slot={slot} />
+ )}
<Text
bg="blackAlpha.700"
bottom="1"
@@ -310,3 +367,58 @@ const StagingThumbnail = ({
</Stack>
);
};
+
+const StagingPlaceholderThumbnail = ({
+ antialiasProgressImages,
+ slot,
+}: {
+ antialiasProgressImages: boolean;
+ slot: Extract<CanvasStagingSlot, { kind: 'placeholder' }>;
+}) => {
+ const progressImage = useQueueItemProgressImage(slot.queueItemId, slot.itemIndex);
+ const progress = useQueueItemProgress(slot.queueItemId);
+ const isActive = progress?.activeItemIndex === slot.itemIndex;
+ const percentage = typeof progress?.percentage === 'number' ? Math.round(progress.percentage * 100) : null;
+
+ return (
+ <>
+ <StreamingImageFrame
+ fit="cover"
+ h="full"
+ liveImage={progressImageToStreamingSource(progressImage)}
+ shouldAntialiasLiveImage={antialiasProgressImages}
+ w="full"
+ >
+ <Skeleton h="full" w="full" />
+ </StreamingImageFrame>
+ {isActive ? <StagingPlaceholderProgress percentage={percentage} /> : null}
+ </>
+ );
+};
+
+const StagingPlaceholderProgress = ({ percentage }: { percentage: number | null }) => {
+ const { t } = useTranslation();
+
+ return (
+ <Flex
+ align="center"
+ aria-label={
+ percentage === null
+ ? t('widgets.gallery.generationProgress')
+ : t('widgets.gallery.generationProgressPercent', { percentage })
+ }
+ inset="0"
+ justify="center"
+ pointerEvents="none"
+ position="absolute"
+ zIndex="1"
+ >
+ <ProgressCircle.Root bg="bg/85" borderWidth={1} p={0.5} rounded="full" size="xs" value={percentage}>
+ <ProgressCircle.Circle>
+ <ProgressCircle.Track />
+ <ProgressCircle.Range />
+ </ProgressCircle.Circle>
+ </ProgressCircle.Root>
+ </Flex>
+ );
+};
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/stagingPreview.test.ts b/invokeai/frontend/webv2/src/workbench/widgets/canvas/stagingPreview.test.ts
index 342d527718..f65c3a7636 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/stagingPreview.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/stagingPreview.test.ts
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';
-import { selectCanvasProgressImage, selectStagedPreviewSource, stagedPreviewKey } from './stagingPreview';
+import { selectStagedPreviewSource, stagedPreviewKey } from './stagingPreview';
const base = {
bboxHeight: 512,
@@ -24,13 +24,24 @@ describe('selectStagedPreviewSource', () => {
expect(selectStagedPreviewSource({ ...base, isVisible: false, selectedImageName: 'img-1' })).toBeNull();
});
- it('prefers the live progress frame while generating, scaled to fill the bbox', () => {
+ it('returns the selected candidate even while another canvas slot is generating', () => {
+ expect(
+ selectStagedPreviewSource({
+ ...base,
+ isGenerationInFlight: true,
+ progressImage: { dataUrl: 'data:image/png;base64,AAAA', height: 64, width: 64 },
+ selectedImageName: 'img-1',
+ })
+ ).toEqual({ imageName: 'img-1' });
+ });
+
+ it('returns the selected placeholder progress frame while generating, scaled to fill the bbox', () => {
const source = selectStagedPreviewSource({
...base,
isGenerationInFlight: true,
progressImage: { dataUrl: 'data:image/png;base64,AAAA', height: 64, width: 64 },
- selectedImageName: 'img-1',
});
+
// Fills the bbox dims (512x512), not the progress frame's native 64x64.
expect(source).toEqual({ dataUrl: 'data:image/png;base64,AAAA', height: 512, width: 512 });
});
@@ -59,35 +70,6 @@ describe('selectStagedPreviewSource', () => {
});
});
-describe('selectCanvasProgressImage', () => {
- const frame = (queueItemId: string) => ({
- dataUrl: 'data:image/png;base64,AAAA',
- height: 64,
- target: { itemIndex: 1, queueItemId },
- width: 64,
- });
-
- it('returns the frame when its queue item belongs to this canvas', () => {
- const result = selectCanvasProgressImage(frame('q-canvas'), new Set(['q-canvas']));
- expect(result).toEqual({ dataUrl: 'data:image/png;base64,AAAA', height: 64, width: 64 });
- });
-
- it('ignores a frame from a foreign (non-canvas / other-project) queue item', () => {
- // A generate-widget run in the same project, or another project's run, shares
- // the app-global latest-progress store — its frames must not leak onto the canvas.
- expect(selectCanvasProgressImage(frame('q-generate'), new Set(['q-canvas']))).toBeNull();
- });
-
- it('returns null when there is no latest frame or the frame has no target', () => {
- expect(selectCanvasProgressImage(null, new Set(['q-canvas']))).toBeNull();
- expect(selectCanvasProgressImage({ dataUrl: 'x', height: 8, width: 8 }, new Set(['q-canvas']))).toBeNull();
- });
-
- it('returns null when no canvas queue items are in flight', () => {
- expect(selectCanvasProgressImage(frame('q-canvas'), new Set())).toBeNull();
- });
-});
-
describe('stagedPreviewKey', () => {
it('is stable per source and distinguishes the source kinds', () => {
expect(stagedPreviewKey(null)).toBe('none');
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/stagingPreview.ts b/invokeai/frontend/webv2/src/workbench/widgets/canvas/stagingPreview.ts
index 9d9680ce92..24d8b472fc 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/stagingPreview.ts
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/stagingPreview.ts
@@ -1,19 +1,19 @@
/**
* Pure selection of what the engine should draw as the canvas staged preview:
- * a live denoise-progress frame while a canvas generation is in flight,
- * otherwise the selected staged candidate, otherwise nothing. Kept React-free
- * so the progress-vs-candidate decision is unit-testable in node.
+ * the selected finished candidate when visible, otherwise the selected
+ * placeholder's live denoise-progress frame, otherwise nothing. Kept React-free
+ * so the candidate-vs-progress decision is unit-testable in node.
*/
import type { StagedPreviewInput } from '@workbench/canvas-engine/engine';
/** Inputs to {@link selectStagedPreviewSource}. */
export interface StagedPreviewSelection {
- /** Whether a canvas-destination generation is currently pending/running. */
+ /** Whether the selected slot is a canvas placeholder that may have live progress. */
isGenerationInFlight: boolean;
- /** The latest denoise-progress frame, if any (b64 data URL + native dims). */
+ /** The selected placeholder's denoise-progress frame, if any (b64 data URL + native dims). */
progressImage: { dataUrl: string; width: number; height: number } | null;
- /** Whether the staging area's preview toggle is on. */
+ /** Whether finished candidate previews are visible. Placeholder progress is controlled separately. */
isVisible: boolean;
/** The currently selected staged candidate's image name, if any. */
selectedImageName: string | null;
@@ -23,10 +23,9 @@ export interface StagedPreviewSelection {
}
/**
- * Resolves the staged-preview source. Progress wins while generating (so the
- * canvas shows live denoising over the bbox), handing off to the final
- * candidate once the result lands and the run settles. Returns `null` when the
- * preview is hidden or there is nothing to show.
+ * Resolves the staged-preview source. A selected finished candidate wins when
+ * candidate previews are visible; otherwise selected-placeholder progress fills
+ * the bbox. Returns `null` when neither source is available.
*/
export const selectStagedPreviewSource = ({
bboxHeight,
@@ -36,44 +35,16 @@ export const selectStagedPreviewSource = ({
progressImage,
selectedImageName,
}: StagedPreviewSelection): StagedPreviewInput | null => {
+ if (isVisible && selectedImageName) {
+ return { imageName: selectedImageName };
+ }
if (isGenerationInFlight && progressImage && bboxWidth > 0 && bboxHeight > 0) {
// Progress frames are low-res latents of the bbox region; scale to fill it.
return { dataUrl: progressImage.dataUrl, height: bboxHeight, width: bboxWidth };
}
- if (isVisible && selectedImageName) {
- return { imageName: selectedImageName };
- }
return null;
};
-/** The app-global latest progress frame, tagged with the queue item it belongs to. */
-export interface TargetedProgressImage {
- dataUrl: string;
- width: number;
- height: number;
- target?: { queueItemId: string };
-}
-
-/**
- * Gates the app-global latest denoise-progress frame to THIS canvas: returns the
- * frame only when its originating queue item is one of the project's pending/
- * running canvas-destination items. The progress store keeps a single global
- * "latest" frame, so without this filter a generate-widget run in the same
- * project — or a run in another project entirely — would draw its denoise frames
- * over this canvas's bbox. Returning `null` for a foreign frame also lets a
- * landed candidate win over another item's live progress (the candidate is the
- * next fallback in {@link selectStagedPreviewSource}).
- */
-export const selectCanvasProgressImage = (
- latest: TargetedProgressImage | null,
- canvasQueueItemIds: ReadonlySet<string>
-): { dataUrl: string; width: number; height: number } | null => {
- if (!latest?.target || !canvasQueueItemIds.has(latest.target.queueItemId)) {
- return null;
- }
- return { dataUrl: latest.dataUrl, height: latest.height, width: latest.width };
-};
-
/**
* A stable string key for a {@link StagedPreviewInput}, so a React effect only
* re-drives the (async, decoding) `setStagedPreview` when the source actually