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): toggle the preview into the center with z
Josh Corbettea499c4e90fa
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.jsonindex 4c59d3d7d3..b2ae819f6f 100644--- a/invokeai/frontend/webv2/public/locales/en.json+++ b/invokeai/frontend/webv2/public/locales/en.json@@ -1442,10 +1442,10 @@"executionCompleted": "Completed","executionFailed": "Failed","forLoopBodyBoundary": "For loop body",- "forLoopBodyBoundaryStatus": {- "missing_linkage": "missing loop linkage","imageCollectionCount_one": "{{count}} image","imageCollectionCount_other": "{{count}} images",+ "forLoopBodyBoundaryStatus": {+ "missing_linkage": "missing loop linkage","invalid_linkage": "invalid loop linkage","duplicate_linkage": "duplicate loop linkage","missing_return": "missing ForReturn",@@ -2479,7 +2479,6 @@"nextComparisonMode": "Next comparison mode","swapComparisonImages": "Swap comparison images","toggleFilmstrip": "Toggle filmstrip",- "togglePreview": "Toggle preview","zoomToActual": "Zoom preview to 100%","zoomToFit": "Zoom preview to fit"},diff --git a/invokeai/frontend/webv2/src/workbench/hotkeys/catalog.test.ts b/invokeai/frontend/webv2/src/workbench/hotkeys/catalog.test.tsindex a27b2cfa4b..6273f3ce29 100644--- a/invokeai/frontend/webv2/src/workbench/hotkeys/catalog.test.ts+++ b/invokeai/frontend/webv2/src/workbench/hotkeys/catalog.test.ts@@ -10,7 +10,9 @@ describe('firstPartyHotkeyCatalog', () => {// save, and alt+1..4) + `app.openSettings` (mod+,) + `gallery.toggleStarredOnly`// (webv2 starred-only listing filter, unbound) + the two unbound canvas// gallery saves (`canvas.saveToGallery`, `canvas.saveBboxToGallery`).+ // `app.togglePreview` (z) replaces the legacy `viewer.toggleViewer`.expect(firstPartyHotkeyCatalog).toHaveLength(104);+ expect(firstPartyHotkeyCatalog.map((hotkey) => hotkey.id)).toContain('app.togglePreview');expect(firstPartyHotkeyCatalog.map((hotkey) => hotkey.id)).toContain('app.invoke');expect(firstPartyHotkeyCatalog.map((hotkey) => hotkey.id)).toContain('app.openCommandPalette');expect(firstPartyHotkeyCatalog.map((hotkey) => hotkey.id)).toContain('canvas.mergeDown');diff --git a/invokeai/frontend/webv2/src/workbench/hotkeys/catalog.ts b/invokeai/frontend/webv2/src/workbench/hotkeys/catalog.tsindex 194ef3dca9..ee7e9236fa 100644--- a/invokeai/frontend/webv2/src/workbench/hotkeys/catalog.ts+++ b/invokeai/frontend/webv2/src/workbench/hotkeys/catalog.ts@@ -68,6 +68,7 @@ const implemented = new Set(['app.selectWorkflowsTab','app.toggleLeftPanel','app.togglePanels',+ 'app.togglePreview','app.toggleRightPanel','canvas.deleteSelected','canvas.fitBboxToLayers',@@ -102,7 +103,6 @@ const implemented = new Set(['viewer.recallSeed','viewer.remix','viewer.swapImages',- 'viewer.toggleViewer','viewer.useSize','workflows.addNode','workflows.copySelection',@@ -211,6 +211,7 @@ export const firstPartyHotkeyCatalog: HotkeyDefinition[] = [hotkey('app', 'toggleRightPanel', ['g']),hotkey('app', 'resetPanelLayout', ['shift+r']),hotkey('app', 'togglePanels', ['f']),+ hotkey('app', 'togglePreview', ['z']),hotkey('canvas', 'selectBrushTool', ['b']),hotkey('canvas', 'selectBboxTool', ['c']),hotkey('canvas', 'decrementToolWidth', ['[']),@@ -263,7 +264,6 @@ export const firstPartyHotkeyCatalog: HotkeyDefinition[] = [hotkey('workflows', 'deleteSelection', ['delete', 'backspace']),hotkey('workflows', 'undo', ['mod+z']),hotkey('workflows', 'redo', ['mod+shift+z', 'mod+y']),- hotkey('viewer', 'toggleViewer', ['z']),hotkey('viewer', 'swapImages', ['c']),hotkey('viewer', 'nextComparisonMode', ['m']),hotkey('viewer', 'deleteImage', ['delete', 'backspace']),diff --git a/invokeai/frontend/webv2/src/workbench/hotkeys/firstPartyCommands.ts b/invokeai/frontend/webv2/src/workbench/hotkeys/firstPartyCommands.tsindex 96b9309c93..598635c29e 100644--- a/invokeai/frontend/webv2/src/workbench/hotkeys/firstPartyCommands.ts+++ b/invokeai/frontend/webv2/src/workbench/hotkeys/firstPartyCommands.ts@@ -24,7 +24,8 @@ import { toggleCommandPalette } from '@workbench/palette/paletteStore';import { openWorkbenchSettings } from '@workbench/settings/settingsDialogStore';import { getWorkbenchPreferences } from '@workbench/settings/store';import { openProjectSwitcher } from '@workbench/shell/topbar/projectSwitcherStore';-import { openWidgetPlacement } from '@workbench/widgetPlacementCommands';+import { openWidgetPlacement, toggleCenterPreview } from '@workbench/widgetPlacementCommands';+import { getWidgetPlacementProject } from '@workbench/widgetPlacementMeta';import { getWidgetsForRegion } from '@workbench/widgetRegistry';import { getProjectWidgetValues } from '@workbench/widgetState';import { useWorkbenchCommands, useWorkbenchExtensions, useWorkbenchQueries } from '@workbench/WorkbenchContext';@@ -71,6 +72,7 @@ export const FIRST_PARTY_APP_COMMAND_IDS = ['app.toggleRightPanel','app.resetPanelLayout','app.togglePanels',+ 'app.togglePreview',] as const;export const FIRST_PARTY_IMAGE_RECALL_COMMAND_IDS = Object.keys(imageRecallCommands);@@ -363,6 +365,16 @@ export const useRegisterFirstPartyCommands = () => {id: 'app.togglePanels',title: 'Toggle panels',}),+ commandApi.register({+ handler: () =>+ toggleCenterPreview({+ getWidgetsForRegion,+ project: getWidgetPlacementProject(queries.getSnapshot().activeProject),+ widgets,+ }),+ id: 'app.togglePreview',+ title: 'Toggle preview in center',+ }),...Object.entries(imageRecallCommands).map(([id, kind]) =>commandApi.register({ handler: () => recallSelectedImage(kind), id, title: id })),diff --git a/invokeai/frontend/webv2/src/workbench/palette/entries.ts b/invokeai/frontend/webv2/src/workbench/palette/entries.tsindex 3794815500..e338bbb2af 100644--- a/invokeai/frontend/webv2/src/workbench/palette/entries.ts+++ b/invokeai/frontend/webv2/src/workbench/palette/entries.ts@@ -194,6 +194,7 @@ const APP_COMMAND_GROUPS: Record<string, string> = {'app.selectWorkflowsTab': 'Navigation','app.toggleLeftPanel': 'Layout','app.togglePanels': 'Layout',+ 'app.togglePreview': 'Layout','app.toggleRightPanel': 'Layout',};diff --git a/invokeai/frontend/webv2/src/workbench/widgetPlacementCommands.test.ts b/invokeai/frontend/webv2/src/workbench/widgetPlacementCommands.test.tsindex ab3de80dea..9ef217d4b6 100644--- a/invokeai/frontend/webv2/src/workbench/widgetPlacementCommands.test.ts+++ b/invokeai/frontend/webv2/src/workbench/widgetPlacementCommands.test.ts@@ -8,7 +8,14 @@ import type { WorkbenchAction } from './workbenchState.testing';import type { WorkbenchWidgetCommands } from './workbenchStore';import { createWidgetImplementationResource } from './widgetImplementationResource';-import { closeWidgetPlacement, openWidgetPlacement, revealWidgetPlacement } from './widgetPlacementCommands';+import {+ closeWidgetPlacement,+ getCenterPreviewToggleState,+ openWidgetPlacement,+ revealWidgetPlacement,+ toggleCenterPreview,+} from './widgetPlacementCommands';+import { getWidgetPlacementProject } from './widgetPlacementMeta';import { createInitialWorkbenchState, workbenchReducer } from './workbenchState.testing';const TestIcon = () => null;@@ -260,3 +267,65 @@ describe('widget placement commands', () => {expect(rightRegion.activeInstanceId).toBe('gallery');});});++const previewRegistry = createRegistry({ center: [createWidget({ id: 'preview', label: 'Preview' })] });++const createPreviewToggleHarness = () => {+ let state = workbenchReducer(createInitialWorkbenchState(), { presetId: 'automate', type: 'applyPreset' });+ const dispatch = (action: WorkbenchAction): void => {+ state = workbenchReducer(state, action);+ };+ const widgets = {+ open: (options) => dispatch({ ...options, type: 'openRegionWidget' }),+ select: (options) => dispatch({ ...options, type: 'selectRegionWidget' }),+ } as WorkbenchWidgetCommands;+ const toggle = () =>+ toggleCenterPreview({+ getWidgetsForRegion: previewRegistry,+ project: getWidgetPlacementProject(getActiveProject(state)),+ widgets,+ });++ return { getRegions: () => getActiveProject(state).widgetRegions, select: widgets.select, toggle };+};++describe('toggleCenterPreview', () => {+ it('swaps the preview into the center and back to the view it replaced', () => {+ const { getRegions, toggle } = createPreviewToggleHarness();++ expect(getRegions().center.activeInstanceId).toBe('workflow:center');+ expect(toggle()).toBe(true);+ expect(getRegions().center.activeInstanceId).toBe('preview');+ expect(toggle()).toBe(true);+ expect(getRegions().center.activeInstanceId).toBe('workflow:center');+ });++ it('moves a rail actively showing the same preview instance to its neighbour first', () => {+ const { getRegions, select, toggle } = createPreviewToggleHarness();++ select({ region: 'right', widgetId: 'preview' });+ expect(getRegions().right.activeInstanceId).toBe('preview');++ toggle();++ expect(getRegions().center.activeInstanceId).toBe('preview');+ expect(getRegions().right.activeInstanceId).toBe('queue');+ });++ it('falls back to another center view when nothing was remembered', () => {+ const { getRegions } = createPreviewToggleHarness();+ const project = {+ projectId: 'other-project',+ widgetInstances: {+ canvas: { id: 'canvas', typeId: 'canvas' },+ preview: { id: 'preview', typeId: 'preview' },+ },+ widgetRegions: {+ ...getRegions(),+ center: { activeInstanceId: 'preview', instanceIds: ['canvas', 'preview'] },+ },+ };++ expect(getCenterPreviewToggleState(project)).toMatchObject({ isPreviewActive: true, returnInstanceId: 'canvas' });+ });+});diff --git a/invokeai/frontend/webv2/src/workbench/widgetPlacementCommands.ts b/invokeai/frontend/webv2/src/workbench/widgetPlacementCommands.tsindex cd23ba890f..928d2bd40d 100644--- a/invokeai/frontend/webv2/src/workbench/widgetPlacementCommands.ts+++ b/invokeai/frontend/webv2/src/workbench/widgetPlacementCommands.ts@@ -8,6 +8,8 @@ import type {} from '@workbench/widgetContracts';import { flushWorkbenchDrafts } from '@platform/react/draftRegistry';+import { registerAccountOwnedResource } from '@platform/state/accountLifecycle';+import { createExternalStore } from '@platform/state/externalStore';import type { WidgetDragEndResolution } from './widgetDnd';import type { WidgetPlacementMeta } from './widgetRegionViewModel';@@ -209,3 +211,93 @@ export const dispatchWidgetDragEndPlacement = ({return { ok: true, region: resolution.toRegion };};++const PREVIEW_TYPE_ID = 'preview';++/** The center view each project showed before the preview was swapped in; session-lived. */+const returnStore = createExternalStore<{ byProject: Record<string, WidgetInstanceId> }>({ byProject: {} });++registerAccountOwnedResource({+ clear: () => returnStore.setSnapshot({ byProject: {} }),+ name: 'center-preview-toggle',+});++export interface CenterPreviewToggleState {+ isPreviewActive: boolean;+ previewInstanceId: WidgetInstanceId | null;+ returnInstanceId: WidgetInstanceId | null;+}++export const getCenterPreviewToggleState = (project: WidgetPlacementProject): CenterPreviewToggleState => {+ const center = project.widgetRegions.center;+ const previewInstanceId =+ center.instanceIds.find((id) => project.widgetInstances[id]?.typeId === PREVIEW_TYPE_ID) ?? null;+ const isPreviewActive = previewInstanceId !== null && center.activeInstanceId === previewInstanceId;+ const remembered = project.projectId ? returnStore.getSnapshot().byProject[project.projectId] : undefined;+ const returnInstanceId =+ remembered && remembered !== previewInstanceId && center.instanceIds.includes(remembered)+ ? remembered+ : (center.instanceIds.find((id) => id !== previewInstanceId) ?? null);++ return { isPreviewActive, previewInstanceId, returnInstanceId };+};++const rememberReturnView = (project: WidgetPlacementProject): void => {+ if (!project.projectId) {+ return;+ }++ const { byProject } = returnStore.getSnapshot();++ returnStore.setSnapshot({+ byProject: { ...byProject, [project.projectId]: project.widgetRegions.center.activeInstanceId },+ });+};++/**+ * Swaps the preview into the center and back to the view it replaced. One preview instance can+ * sit in the center and a rail at once, so a rail actively showing it moves to its neighbour first.+ */+export const toggleCenterPreview = ({+ getWidgetsForRegion,+ project,+ widgets,+}: {+ getWidgetsForRegion: (region: WidgetRegion) => RegisteredWidget[];+ project: WidgetPlacementProject;+ widgets: WorkbenchWidgetCommands;+}): boolean => {+ const { isPreviewActive, previewInstanceId, returnInstanceId } = getCenterPreviewToggleState(project);++ if (isPreviewActive) {+ return (+ returnInstanceId !== null &&+ revealWidgetPlacement({ instanceId: returnInstanceId, project, region: 'center', widgets }).ok+ );+ }++ rememberReturnView(project);++ for (const [region, state] of Object.entries(project.widgetRegions) as [+ WidgetRegion,+ { activeInstanceId: string; instanceIds: string[] },+ ][]) {+ if (region === 'center' || state.activeInstanceId !== previewInstanceId) {+ continue;+ }++ const neighbour = state.instanceIds.find((id) => id !== previewInstanceId);++ if (neighbour) {+ widgets.select({ projectId: project.projectId, region, widgetId: neighbour });+ }+ }++ return openWidgetPlacement({+ getWidgetsForRegion,+ options: { preferredRegions: ['center'], requireCenterView: true },+ projectId: project.projectId,+ typeId: PREVIEW_TYPE_ID,+ widgets,+ }).ok;+};diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsxindex 9cf4c62ca7..082f1c9e2b 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewWidgetView.tsx@@ -543,11 +543,6 @@ export const PreviewWidgetView = ({ region, runtime }: WidgetViewProps) => {useEffect(() => () => previewHeaderStore.clear(), []);const executeViewerHotkey = useEffectEvent((commandId: string) => {- if (commandId === 'viewer.toggleViewer') {- runtime.workbench.closeWidgetInstance(runtime.instanceId);- return;- }-if (commandId === 'viewer.swapImages' && selectedItem?.kind === 'image' && compareImage) {swapCompareImages();return;@@ -575,7 +570,6 @@ export const PreviewWidgetView = ({ region, runtime }: WidgetViewProps) => {useEffect(() => {const hotkeys = [- ['viewer.toggleViewer', t('widgets.preview.commands.togglePreview'), ['z']],['viewer.deleteImage', t('widgets.preview.commands.deletePreviewImage'), ['delete', 'backspace']],['viewer.toggleFilmstrip', t('widgets.preview.commands.toggleFilmstrip'), ['t']],...(selectedItem?.kind === 'image'