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): more qol updates

joshistoastfa59a9fb9b0c
diff --git a/invokeai/frontend/webv2/src/workbench/canvasStagingView.test.ts b/invokeai/frontend/webv2/src/workbench/canvasStagingView.test.ts
index 5755674f6c..1d7a4c9b19 100644
--- a/invokeai/frontend/webv2/src/workbench/canvasStagingView.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/canvasStagingView.test.ts
@@ -3,7 +3,11 @@ import { describe, expect, it } from 'vitest';
import type { CanvasStagingCandidateContract, GeneratedImageContract, QueueItem, QueueItemStatus } from './types';
import { createEmptyCanvasStateV2 } from './canvasMigration';
-import { getCanvasQueuePlaceholderSlots, getCanvasStagingSlots } from './canvasStagingView';
+import {
+ getCancelableCanvasStagingQueueItemId,
+ getCanvasQueuePlaceholderSlots,
+ getCanvasStagingSlots,
+} from './canvasStagingView';
const createImage = (imageName: string, sourceQueueItemId: string): GeneratedImageContract => ({
height: 768,
@@ -204,4 +208,30 @@ describe('canvas staging view', () => {
)
).toEqual(['candidate:q-first:1', 'placeholder:q-first:2', 'placeholder:q-second:1']);
});
+
+ it('resolves a cancelable queue item only for placeholder slots', () => {
+ const candidate = createCandidate('ready.png', 'q-ready');
+
+ expect(
+ getCancelableCanvasStagingQueueItemId({
+ candidate,
+ height: 768,
+ id: 'candidate:q-ready:ready.png',
+ imageName: 'ready.png',
+ kind: 'candidate',
+ queueItemId: 'q-ready',
+ width: 512,
+ })
+ ).toBeNull();
+ expect(
+ getCancelableCanvasStagingQueueItemId({
+ height: 320,
+ id: 'q-pending:0',
+ itemIndex: 1,
+ kind: 'placeholder',
+ queueItemId: 'q-pending',
+ width: 640,
+ })
+ ).toBe('q-pending');
+ });
});
diff --git a/invokeai/frontend/webv2/src/workbench/canvasStagingView.ts b/invokeai/frontend/webv2/src/workbench/canvasStagingView.ts
index f38bc32fab..4e8c346df5 100644
--- a/invokeai/frontend/webv2/src/workbench/canvasStagingView.ts
+++ b/invokeai/frontend/webv2/src/workbench/canvasStagingView.ts
@@ -241,3 +241,6 @@ export const getFirstCanvasPlaceholderSlotIndex = (
canvas: CanvasStateContractV2,
queueItems: readonly QueueItem[]
): number => getCanvasStagingSlots(canvas, queueItems).findIndex((slot) => slot.kind === 'placeholder');
+
+export const getCancelableCanvasStagingQueueItemId = (slot: CanvasStagingSlot | undefined): string | null =>
+ slot?.kind === 'placeholder' ? slot.queueItemId : null;
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/CanvasWidgetView.tsx b/invokeai/frontend/webv2/src/workbench/widgets/canvas/CanvasWidgetView.tsx
index 21a17239c6..e07e0acfff 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/CanvasWidgetView.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/CanvasWidgetView.tsx
@@ -422,6 +422,7 @@ export const CanvasWidgetView = ({ runtime }: WidgetViewProps) => {
selectedSlot={selectedSlot}
slots={stagingSlots}
onAccept={() => dispatch({ type: 'acceptStagedImage' })}
+ onCancelQueueItem={(queueItemId) => dispatch({ queueItemId, type: 'cancelQueueItem' })}
onCycle={(direction) => dispatch({ direction, type: 'cycleStagedImage' })}
onDiscardAll={() => dispatch({ type: 'discardAllStagedImages' })}
onDiscardSelected={() => dispatch({ type: 'discardSelectedStagedImage' })}
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/StagingBar.tsx b/invokeai/frontend/webv2/src/workbench/widgets/canvas/StagingBar.tsx
index c6e64487d1..5ee1f34d02 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/StagingBar.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/StagingBar.tsx
@@ -16,6 +16,7 @@ import {
} from '@chakra-ui/react';
import { useQueueItemProgressImage } from '@workbench/backend/progressImageStore';
import { useQueueItemProgress } from '@workbench/backend/progressStore';
+import { getCancelableCanvasStagingQueueItemId } from '@workbench/canvasStagingView';
import { Button, IconButton, MenuContent, toaster, Tooltip } from '@workbench/components/ui';
import { getImageThumbnailUrl, saveImageToGallery } from '@workbench/gallery/api';
import { StreamingImageFrame } from '@workbench/images/StreamingImageFrame';
@@ -57,6 +58,7 @@ interface StagingBarProps {
selectedSlot: CanvasStagingSlot | undefined;
slots: CanvasStagingSlot[];
onAccept: () => void;
+ onCancelQueueItem: (queueItemId: string) => void;
onCycle: (direction: -1 | 1) => void;
onDiscardAll: () => void;
onDiscardSelected: () => void;
@@ -87,6 +89,7 @@ export const StagingBar = ({
selectedSlot,
slots,
onAccept,
+ onCancelQueueItem,
onCycle,
onDiscardAll,
onDiscardSelected,
@@ -98,6 +101,7 @@ export const StagingBar = ({
const { t } = useTranslation();
const [isSaving, setIsSaving] = useState(false);
const hasSlots = slots.length > 0;
+ const cancelableQueueItemId = getCancelableCanvasStagingQueueItemId(selectedSlot);
const handleSaveToGallery = async () => {
if (!selectedCandidate || isSaving) {
@@ -208,6 +212,13 @@ export const StagingBar = ({
<AutoSwitchMenu mode={autoSwitchMode} onSelect={onSetAutoSwitch} />
+ {cancelableQueueItemId ? (
+ <Button size="xs" variant="ghost" onClick={() => onCancelQueueItem(cancelableQueueItemId)}>
+ <XIcon />
+ {t('common.cancel')}
+ </Button>
+ ) : null}
+
{selectedCandidate ? (
<>
<Tooltip
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerContextMenu.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerContextMenu.tsx
index d5bd09c810..1aaa933e91 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerContextMenu.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerContextMenu.tsx
@@ -44,6 +44,13 @@ type MenuOpenChange = ComponentProps<typeof Menu.Root>['onOpenChange'];
const PANEL_POSITIONING: MenuPositioning = { placement: 'bottom-end' };
+// const layerBadgeKey = (layer: CanvasLayerContract): string => {
+// if (layer.type === 'raster') {
+// return layer.source.type === 'image' ? 'widgets.layers.types.image' : 'widgets.layers.types.paint';
+// }
+// return `widgets.layers.types.${layer.type}`;
+// };
+
interface LayerMenuProps {
dispatch: Dispatch<WorkbenchAction>;
engine: CanvasEngine | null;
@@ -266,19 +273,57 @@ const LayerMenu = ({
) : null}
<Portal>
<Menu.Positioner>
- <MenuContent minW="12rem">
+ <MenuContent minW="14rem" py="1">
+ <HStack gap="1">
+ <LayerMenuIconItem
+ disabled={!canMoveForward}
+ icon={ArrowUpToLineIcon}
+ label={t('widgets.layers.actions.moveToFront')}
+ value="move-to-front"
+ onSelect={handleMoveToFront}
+ />
+ <LayerMenuIconItem
+ disabled={!canMoveForward}
+ icon={ArrowUpIcon}
+ label={t('widgets.layers.actions.moveForward')}
+ value="move-forward"
+ onSelect={handleMoveForward}
+ />
+ <LayerMenuIconItem
+ disabled={!canMoveBackward}
+ icon={ArrowDownIcon}
+ label={t('widgets.layers.actions.moveBackward')}
+ value="move-backward"
+ onSelect={handleMoveBackward}
+ />
+ <LayerMenuIconItem
+ disabled={!canMoveBackward}
+ icon={ArrowDownToLineIcon}
+ label={t('widgets.layers.actions.moveToBack')}
+ value="move-to-back"
+ onSelect={handleMoveToBack}
+ />
+ <LayerMenuIconItem
+ icon={CopyIcon}
+ label={t('widgets.layers.actions.duplicate')}
+ value="duplicate"
+ onSelect={handleDuplicate}
+ />
+ {/*<LayerMenuIconItem
+ color="fg.error"
+ icon={Trash2Icon}
+ label={t('widgets.layers.actions.delete')}
+ value="delete"
+ onSelect={handleDelete}
+ />*/}
+ </HStack>
+ <Menu.Separator borderColor="border.subtle" />
<LayerMenuItem
icon={PencilIcon}
label={t('widgets.layers.actions.rename')}
value="rename"
onSelect={openRename}
/>
- <LayerMenuItem
- icon={CopyIcon}
- label={t('widgets.layers.actions.duplicate')}
- value="duplicate"
- onSelect={handleDuplicate}
- />
{canRasterize ? (
<LayerMenuItem
icon={ImageIcon}
@@ -304,35 +349,6 @@ const LayerMenu = ({
/>
) : null}
<Menu.Separator borderColor="border.subtle" />
- <LayerMenuItem
- disabled={!canMoveForward}
- icon={ArrowUpToLineIcon}
- label={t('widgets.layers.actions.moveToFront')}
- value="move-to-front"
- onSelect={handleMoveToFront}
- />
- <LayerMenuItem
- disabled={!canMoveForward}
- icon={ArrowUpIcon}
- label={t('widgets.layers.actions.moveForward')}
- value="move-forward"
- onSelect={handleMoveForward}
- />
- <LayerMenuItem
- disabled={!canMoveBackward}
- icon={ArrowDownIcon}
- label={t('widgets.layers.actions.moveBackward')}
- value="move-backward"
- onSelect={handleMoveBackward}
- />
- <LayerMenuItem
- disabled={!canMoveBackward}
- icon={ArrowDownToLineIcon}
- label={t('widgets.layers.actions.moveToBack')}
- value="move-to-back"
- onSelect={handleMoveToBack}
- />
- <Menu.Separator borderColor="border.subtle" />
<LayerMenuItem
disabled={!canMerge}
icon={MergeIcon}
@@ -352,13 +368,12 @@ const LayerMenu = ({
value="toggle-lock"
onSelect={handleToggleLock}
/>
- <Menu.Separator borderColor="border.subtle" />
<LayerMenuItem
- color="fg.error"
icon={Trash2Icon}
label={t('widgets.layers.actions.delete')}
value="delete"
onSelect={handleDelete}
+ color="fg.error"
/>
</MenuContent>
</Menu.Positioner>
@@ -509,3 +524,31 @@ const LayerMenuItem = ({
</HStack>
</Menu.Item>
);
+
+const LayerMenuIconItem = ({
+ color,
+ disabled,
+ icon,
+ label,
+ onSelect,
+ value,
+}: {
+ color?: string;
+ disabled?: boolean;
+ icon: LucideIcon;
+ label: string;
+ onSelect: () => void;
+ value: string;
+}) => (
+ <Menu.Item
+ aria-label={label}
+ color={color}
+ disabled={disabled}
+ flex="1"
+ justifyContent="center"
+ value={value}
+ onSelect={onSelect}
+ >
+ <Icon as={icon} boxSize="4" color={color ?? 'fg.subtle'} />
+ </Menu.Item>
+);
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/RegionalGuidanceSettings.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/RegionalGuidanceSettings.tsx
index 7aecbe5061..5f0e520a66 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/RegionalGuidanceSettings.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/RegionalGuidanceSettings.tsx
@@ -3,14 +3,16 @@ import type { CanvasEngine } from '@workbench/canvas-engine/engine';
import type { GenerateReferenceImage, GenerateReferenceImageAsset, IPAdapterMethod } from '@workbench/generation/types';
import type { ModelConfig } from '@workbench/models/types';
import type { CanvasMaskContract, CanvasMaskFillContract, CanvasRegionalGuidanceLayerContract } from '@workbench/types';
-import type { ChangeEvent, CSSProperties, FocusEvent } from 'react';
+import type { ChangeEvent, CSSProperties, FocusEvent, KeyboardEvent } from 'react';
-import { Box, createListCollection, HStack, IconButton, Input, Stack, Switch, Text, Textarea } from '@chakra-ui/react';
+import { Box, createListCollection, HStack, IconButton, Input, Stack, Switch, Text } from '@chakra-ui/react';
import { useDndMonitor, useDroppable } from '@dnd-kit/core';
import { Button, ColorPicker, Field, Select, Slider } from '@workbench/components/ui';
import { getGalleryImagesByNames, uploadGalleryImage } from '@workbench/gallery/api';
import { useModelsSelector } from '@workbench/models/modelsStore';
import { isGalleryImageDragData } from '@workbench/widgets/gallery/galleryDnd';
+import { PROMPT_ATTENTION_TARGET_PROPS } from '@workbench/widgets/generate/promptFields/promptAttentionHotkeys';
+import { PromptTextarea } from '@workbench/widgets/generate/promptFields/PromptTextarea';
import { FluxReduxControls } from '@workbench/widgets/generate/reference-images/ReferenceImageControls';
import { getProjectWidgetValues } from '@workbench/widgetState';
import { useActiveProjectSelector, useWorkbenchDispatch } from '@workbench/WorkbenchContext';
@@ -53,6 +55,8 @@ const COVER_IMG_STYLE: CSSProperties = { height: '100%', objectFit: 'cover', wid
const formatWeight = (value: number): string => value.toFixed(2);
+const REGIONAL_PROMPT_HEIGHT_PX = 72;
+
/** DnD droppable id for a specific region's reference-image slot (gallery-image drop target). */
const referenceImageDropId = (layerId: string, refId: string): string => `regional-ref-image:${layerId}:${refId}`;
@@ -91,7 +95,10 @@ export const RegionalGuidanceSettings = ({ engine, layer }: RegionalGuidanceSett
const dispatch = useWorkbenchDispatch();
const models = useModelsSelector((snapshot) => snapshot.models);
const base = useSelectedModelBase();
+ const showSyntaxHighlighting = useActiveProjectSelector((project) => project.settings.showPromptSyntaxHighlighting);
const fillBeforeRef = useRef<CanvasMaskFillContract | null>(null);
+ const [positivePrompt, setPositivePrompt] = useState(layer.positivePrompt ?? '');
+ const [negativePrompt, setNegativePrompt] = useState(layer.negativePrompt ?? '');
const fill = layer.mask.fill;
const isFlux = base === 'flux';
@@ -126,6 +133,11 @@ export const RegionalGuidanceSettings = ({ engine, layer }: RegionalGuidanceSett
[commitConfig, layer.positivePrompt, t]
);
+ const handlePositiveChange = useCallback(
+ (event: ChangeEvent<HTMLTextAreaElement>) => setPositivePrompt(event.currentTarget.value),
+ []
+ );
+
const handleNegativeBlur = useCallback(
(event: FocusEvent<HTMLTextAreaElement>) => {
const value = event.target.value;
@@ -143,6 +155,13 @@ export const RegionalGuidanceSettings = ({ engine, layer }: RegionalGuidanceSett
[commitConfig, layer.negativePrompt, t]
);
+ const handleNegativeChange = useCallback(
+ (event: ChangeEvent<HTMLTextAreaElement>) => setNegativePrompt(event.currentTarget.value),
+ []
+ );
+
+ const stopKeyboardPropagation = useCallback((event: KeyboardEvent) => event.stopPropagation(), []);
+
const handleAutoNegative = useCallback(
(details: { checked: boolean }) => {
commitConfig(
@@ -316,26 +335,38 @@ export const RegionalGuidanceSettings = ({ engine, layer }: RegionalGuidanceSett
const styleValue = useMemo(() => [fill.style], [fill.style]);
return (
- <Stack borderColor="border.subtle" borderWidth="1px" gap="2" p="2" rounded="md">
+ <Stack borderColor="border.subtle" borderWidth="1px" gap="2" p="2" rounded="md" onKeyDown={stopKeyboardPropagation}>
<Field label={t('widgets.layers.regionalGuidance.positivePrompt')}>
- <Textarea
- defaultValue={layer.positivePrompt ?? ''}
- key={`pos-${layer.id}`}
+ <PromptTextarea
+ {...PROMPT_ATTENTION_TARGET_PROPS}
+ aria-label={t('widgets.layers.regionalGuidance.positivePrompt')}
+ defaultHeightPx={REGIONAL_PROMPT_HEIGHT_PX}
+ maxHeightPx={180}
+ minHeightPx={REGIONAL_PROMPT_HEIGHT_PX}
placeholder={t('widgets.layers.regionalGuidance.positivePromptPlaceholder')}
- rows={2}
+ resizeHandleAriaLabel={t('widgets.layers.regionalGuidance.positivePrompt')}
+ showSyntaxHighlighting={showSyntaxHighlighting}
size="sm"
+ value={positivePrompt}
onBlur={handlePositiveBlur}
+ onChange={handlePositiveChange}
/>
</Field>
{!isFlux && (
<Field label={t('widgets.layers.regionalGuidance.negativePrompt')}>
- <Textarea
- defaultValue={layer.negativePrompt ?? ''}
- key={`neg-${layer.id}`}
+ <PromptTextarea
+ {...PROMPT_ATTENTION_TARGET_PROPS}
+ aria-label={t('widgets.layers.regionalGuidance.negativePrompt')}
+ defaultHeightPx={REGIONAL_PROMPT_HEIGHT_PX}
+ maxHeightPx={180}
+ minHeightPx={REGIONAL_PROMPT_HEIGHT_PX}
placeholder={t('widgets.layers.regionalGuidance.negativePromptPlaceholder')}
- rows={2}
+ resizeHandleAriaLabel={t('widgets.layers.regionalGuidance.negativePrompt')}
+ showSyntaxHighlighting={showSyntaxHighlighting}
size="sm"
+ value={negativePrompt}
onBlur={handleNegativeBlur}
+ onChange={handleNegativeChange}
/>
</Field>
)}