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(workbench): float the last center view, and dock it back where it floated from
Lincoln Stein88b49fd79f41
diff --git a/invokeai/frontend/webv2/src/workbench/floatingWidgets.test.ts b/invokeai/frontend/webv2/src/workbench/floatingWidgets.test.tsindex d272d0c518..24e93e72ac 100644--- a/invokeai/frontend/webv2/src/workbench/floatingWidgets.test.ts+++ b/invokeai/frontend/webv2/src/workbench/floatingWidgets.test.ts@@ -64,7 +64,7 @@ describe('floatWidget', () => {expect(floating?.queue.x).toBeGreaterThan(floating?.gallery.x ?? 0);});- it('refuses to float the last center view, which would blank the work surface', () => {+ it('floats the last center view, leaving the surface to its fallback view', () => {let state = createInitialWorkbenchState();const centerInstanceIds = getActiveProject(state).widgetRegions.center.instanceIds;@@ -74,7 +74,52 @@ describe('floatWidget', () => {const lastCenterInstanceId = centerInstanceIds[0];expect(getActiveProject(state).widgetRegions.center.instanceIds).toEqual([lastCenterInstanceId]);- expect(workbenchReducer(state, { instanceId: lastCenterInstanceId, type: 'floatWidget' })).toBe(state);++ state = workbenchReducer(state, { instanceId: lastCenterInstanceId, type: 'floatWidget' });+ const center = getActiveProject(state).widgetRegions.center;++ // The surface may go empty — the fallback view carries it — and the+ // window remembers the center as its dock-back target. The active pointer+ // holds the floated instance so docking restores it as the active view,+ // and the center takes no collapsed state.+ expect(center.instanceIds).toEqual([]);+ expect(center.activeInstanceId).toBe(lastCenterInstanceId);+ expect(center.isCollapsed).toBe(false);+ expect(getActiveProject(state).floatingWidgets?.[lastCenterInstanceId]).toMatchObject({+ returnRegion: 'center',+ });+ });++ it('docks back into the region the float was asked from, not the first member region', () => {+ // The Edit preset places the preview in the center AND the right rail, and+ // `right` precedes `center` in the region map — without the origin hint,+ // floating it from the center chrome would detach the rail's membership+ // and dock it back there.+ let state = workbenchReducer(createInitialWorkbenchState(), { presetId: 'edit', type: 'applyPreset' });+ state = workbenchReducer(state, { instanceId: 'preview', region: 'center', type: 'floatWidget' });+ const project = getActiveProject(state);++ expect(project.widgetRegions.center.instanceIds).not.toContain('preview');+ expect(project.widgetRegions.right.instanceIds).toContain('preview');+ expect(project.floatingWidgets?.preview).toMatchObject({ returnRegion: 'center' });++ const docked = workbenchReducer(state, { instanceId: 'preview', type: 'dockFloatingWidget' });++ expect(getActiveProject(docked).widgetRegions.center.instanceIds).toContain('preview');+ expect(getActiveProject(docked).widgetRegions.center.activeInstanceId).toBe('preview');+ });++ it('falls back to a member region when the float carries no region hint', () => {+ let state = workbenchReducer(createInitialWorkbenchState(), { presetId: 'edit', type: 'applyPreset' });+ state = workbenchReducer(state, { instanceId: 'preview', type: 'floatWidget' });+ const project = getActiveProject(state);+ const floating = project.floatingWidgets?.preview;++ // The hint is what makes dock-back deterministic; without it some member+ // region still hosts the float — which one is region map order, not a+ // contract.+ expect(floating).toBeDefined();+ expect(['center', 'right']).toContain(floating!.returnRegion);});it('collapses a rail it empties instead of leaving it open and blank', () => {@@ -337,7 +382,11 @@ describe('normalization of persisted floating windows', () => {});});- it('docks rather than empties the center region', () => {+ it('lets a sole center view keep floating across a reload', () => {+ // Floating the last center view empties the work surface into its fallback+ // view, and the window's dock control is one click from restoring it — so+ // normalization honours the float instead of re-docking it, exactly as it+ // does for a floated rail widget.const project = getActiveProject(createInitialWorkbenchState());const [onlyCenterInstanceId] = project.widgetRegions.center.instanceIds;const normalized = normalizeWorkbenchProject({@@ -359,8 +408,8 @@ describe('normalization of persisted floating windows', () => {},});- expect(normalized.floatingWidgets).toBeUndefined();- expect(normalized.widgetRegions.center.instanceIds).toEqual([onlyCenterInstanceId]);+ expect(normalized.floatingWidgets?.[onlyCenterInstanceId]).toMatchObject({ returnRegion: 'center' });+ expect(normalized.widgetRegions.center.instanceIds).toEqual([]);});});diff --git a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetFloatButton.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetFloatButton.browser.test.tsxindex 5cae5619f2..1275837c03 100644--- a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetFloatButton.browser.test.tsx+++ b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetFloatButton.browser.test.tsx@@ -12,9 +12,11 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';/*** The float control replaced a menu item, so the conditions that used to hide- * that item now decide whether a button renders at all: a widget that may not- * float, and the last center view — floating it out would leave the work- * surface empty. Docking is covered by the floating window's own chrome.+ * that item now decide whether a button renders at all: only a widget whose+ * manifest forbids floating, and the floating region itself. Even the last+ * center view may float — the emptied surface falls back to the center's+ * fallback view until the window docks back. Docking is covered by the+ * floating window's own chrome.*/const floatMocks = vi.hoisted(() => ({@@ -119,7 +121,7 @@ describe('WidgetFloatButton', () => {});expect(floatMocks.flushWorkbenchDrafts).toHaveBeenCalled();- expect(floatMocks.float).toHaveBeenCalledWith('image-map-instance');+ expect(floatMocks.float).toHaveBeenCalledWith('image-map-instance', 'right');expect(floatMocks.flushWorkbenchDrafts.mock.invocationCallOrder[0]).toBeLessThan(floatMocks.float.mock.invocationCallOrder[0]);@@ -129,8 +131,8 @@ describe('WidgetFloatButton', () => {expect(await renderButton('right', false)).toBeNull();});- it('renders nothing for the last enabled center view', async () => {- expect(await renderButton('center')).toBeNull();+ it('renders for the last enabled center view — the emptied surface falls back until it docks back', async () => {+ expect(await renderButton('center')).not.toBeNull();});it('renders for a center view that is not the last one', async () => {diff --git a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetFrames.tsx b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetFrames.tsxindex 292e9b4c99..7ae1d9ed4e 100644--- a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetFrames.tsx+++ b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetFrames.tsx@@ -16,10 +16,9 @@ import { useMountEffect } from '@platform/react/useMountEffect';import { IconButton } from '@platform/ui/Button';import { Tooltip } from '@platform/ui/Tooltip';import { useFocusRegionProps } from '@workbench/focusRegions';+import { isWidgetRegion } from '@workbench/layoutContracts';import { openWorkbenchSettings } from '@workbench/settings/settingsDialogStore';import { resolveWidgetInstanceLabel } from '@workbench/widgetLabels';-import { getEnabledCenterViewCount } from '@workbench/widgetPlacementCommands';-import { areWidgetPlacementProjectsEqual, getWidgetPlacementProject } from '@workbench/widgetPlacementMeta';import { useActiveProjectSelector, useWorkbenchCommands } from '@workbench/WorkbenchContext';import {clampPanelSize,@@ -27,7 +26,6 @@ import {getVisiblePanelCollapseThreshold,shouldSnapPanelShutAt,} from '@workbench/workbenchState';-import { useWorkbenchWidgetRegistry } from '@workbench/WorkbenchWidgetRegistryContext';import { PictureInPicture2Icon, SettingsIcon } from 'lucide-react';import {useCallback,@@ -310,23 +308,29 @@ export const WidgetFloatButton = ({region: WorkbenchRegion;}) => {const { t } = useTranslation();- const placementProject = useActiveProjectSelector(getWidgetPlacementProject, areWidgetPlacementProjectsEqual);- const { getWidgetById } = useWorkbenchWidgetRegistry();const { widgets } = useWorkbenchCommands();+ // A dialog or popover's chrome never floats; anything else is a dockable+ // layout region, which is also the dock-back target.+ const dockableRegion = isWidgetRegion(region) ? region : undefined;// Floating unmounts the docked subtree; the draft registry's cleanup only- // deregisters the flusher, so an uncommitted edit is lost without this.+ // deregisters the flusher, so an uncommitted edit is lost without this. The+ // region rides along: one instance may be placed in several regions (the+ // preview lives in the center and a rail), and the window docks back into+ // the one whose button was clicked.const handleFloat = useCallback(() => {+ if (!dockableRegion) {+ return;+ }+flushWorkbenchDrafts();- widgets.float(instanceId);- }, [instanceId, widgets]);+ widgets.float(instanceId, dockableRegion);+ }, [dockableRegion, instanceId, widgets]);// Floating is offered only from dockable regions; the floating window's own- // chrome carries the dock control. The last center *view* is not offered it- // either — floating it out would leave the work surface with nothing to- // show, which is why `closeWidgetPlacement` refuses the same removal.- const canFloat =- Boolean(manifest.allowFloating) &&- region !== 'floating' &&- !(region === 'center' && getEnabledCenterViewCount(placementProject, getWidgetById) === 1);+ // chrome carries the dock control. Even the last center *view* may float:+ // the emptied surface falls back to the center's fallback view, and the+ // window's dock control restores it — only the destructive placements+ // (`closeWidgetPlacement`, `toggleRegionWidget`) still refuse that.+ const canFloat = Boolean(manifest.allowFloating) && dockableRegion !== undefined;if (!canFloat) {return null;diff --git a/invokeai/frontend/webv2/src/workbench/widget-frame/createWidgetRuntime.test.ts b/invokeai/frontend/webv2/src/workbench/widget-frame/createWidgetRuntime.test.tsindex 1c2e7feeb9..c09f1790b3 100644--- a/invokeai/frontend/webv2/src/workbench/widget-frame/createWidgetRuntime.test.ts+++ b/invokeai/frontend/webv2/src/workbench/widget-frame/createWidgetRuntime.test.ts@@ -54,7 +54,8 @@ const createDispatch = () => {const widgets: WorkbenchWidgetCommands = {dockFloating: (instanceId) => dispatch({ instanceId, type: 'dockFloatingWidget' }),- float: (instanceId) => dispatch({ instanceId, type: 'floatWidget' }),+ float: (instanceId, region) =>+ dispatch(region ? { instanceId, region, type: 'floatWidget' } : { instanceId, type: 'floatWidget' }),focusFloating: (instanceId) => dispatch({ instanceId, type: 'focusFloatingWidget' }),move: (options) => dispatch({ ...options, type: 'moveWidgetInstance' }),open: (options) => dispatch({ ...options, type: 'openRegionWidget' }),diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.tsindex 73373d5d18..7fb1f47bae 100644--- a/invokeai/frontend/webv2/src/workbench/workbenchState.ts+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.ts@@ -237,7 +237,12 @@ type WorkbenchReducerAction =}| { type: 'setRegionWidgetCollapsed'; region: WidgetRegion; isCollapsed: boolean }| { type: 'setRegionWidgetSize'; region: WidgetRegion; sizePx: number }- | { type: 'floatWidget'; instanceId: WidgetInstanceId }+ | {+ type: 'floatWidget';+ instanceId: WidgetInstanceId;+ /** The chrome the float was asked from; docking returns the window there. */+ region?: WidgetRegion;+ }| { type: 'dockFloatingWidget'; instanceId: WidgetInstanceId }| {type: 'setFloatingWidgetGeometry';@@ -1669,9 +1674,10 @@ const normalizeFloatingWidgets = (* reload they hand back a widget the person had floated. Floating wins: it is* the deliberate act, while the region entry is the migration's guess.*- * The center region is the exception, because it must always hold a view. If- * honouring the floating entries would empty it, they lose and the widget- * stays docked.+ * That holds for the center too, even when its last view is the one floating:+ * the surface falls back to the center's fallback view, and the window's dock+ * control is one click from restoring it. Only the destructive placements+ * (`toggleRegionWidget`, `closeWidgetPlacement`) still refuse to empty it.*/const reconcileFloatingWidgets = (widgetRegions: Record<WidgetRegion, WidgetRegionState>,@@ -1695,13 +1701,6 @@ const reconcileFloatingWidgets = (continue;}- if (regionId === 'center' && instanceIds.length === 0) {- remainingFloating = Object.fromEntries(- Object.entries(remainingFloating).filter(([instanceId]) => !region.instanceIds.includes(instanceId))- );- continue;- }-reconciledRegions[regionId] = {...region,activeInstanceId: instanceIds.includes(region.activeInstanceId)@@ -3893,23 +3892,32 @@ export const __workbenchReducerInternal = (return project;}- const hostEntry = (Object.entries(project.widgetRegions) as [WidgetRegion, WidgetRegionState][]).find(- ([, region]) => region.instanceIds.includes(action.instanceId)- );+ // One instance may be a member of several regions (the preview is+ // placed in the center and a rail by default), so the region the float+ // was asked from — the chrome whose button was clicked — decides where+ // the window docks back to. The unhinted fallback takes the first+ // member region in the region map's order, which persisted projects+ // do not agree on.+ const findHost = (match: (regionId: WidgetRegion, region: WidgetRegionState) => boolean) =>+ (Object.entries(project.widgetRegions) as [WidgetRegion, WidgetRegionState][]).find(([regionId, region]) =>+ match(regionId, region)+ );+ const hostEntry = action.region+ ? findHost((regionId, region) => regionId === action.region && region.instanceIds.includes(action.instanceId))+ : undefined;+ const resolvedHostEntry = hostEntry ?? findHost((_, region) => region.instanceIds.includes(action.instanceId));- if (!hostEntry || !project.widgetInstances[action.instanceId]) {+ if (!resolvedHostEntry || !project.widgetInstances[action.instanceId]) {return project;}- const [hostRegionId, hostRegion] = hostEntry;-- // The work surface must keep a view. `toggleRegionWidget` and- // `closeWidgetPlacement` refuse the same removal; floating it out is- // the same removal with a window attached.- if (hostRegionId === 'center' && hostRegion.instanceIds.length === 1) {- return project;- }+ const [hostRegionId, hostRegion] = resolvedHostEntry;+ // Floating may empty the center, unlike `toggleRegionWidget` and+ // `closeWidgetPlacement`, which still refuse the same removal: those+ // discard the view outright, while a float keeps it one dock click+ // away, and the emptied surface falls back to the center's fallback+ // view rather than standing blank.const instanceIds = hostRegion.instanceIds.filter((instanceId) => instanceId !== action.instanceId);const fallbackInstanceId = getNextInstanceId(hostRegion, action.instanceId);const floating: FloatingWidgetState = {@@ -3935,8 +3943,9 @@ export const __workbenchReducerInternal = (instanceIds,// Floating the last widget out of a rail leaves nothing to show,// so the rail collapses rather than standing open and empty —- // the same repair `toggleRegionWidget` makes.- isCollapsed: instanceIds.length === 0 ? true : hostRegion.isCollapsed,+ // the same repair `toggleRegionWidget` makes. The center has no+ // collapsed state; its fallback view carries the empty surface.+ isCollapsed: instanceIds.length === 0 && hostRegionId !== 'center' ? true : hostRegion.isCollapsed,},},},diff --git a/invokeai/frontend/webv2/src/workbench/workbenchStore.ts b/invokeai/frontend/webv2/src/workbench/workbenchStore.tsindex 3ba92be276..2e87ff5a77 100644--- a/invokeai/frontend/webv2/src/workbench/workbenchStore.ts+++ b/invokeai/frontend/webv2/src/workbench/workbenchStore.ts@@ -389,7 +389,9 @@ const createCommands = (},widgets: {dockFloating: command('dockFloatingWidget', (instanceId: string) => ({ instanceId })),- float: command('floatWidget', (instanceId: string) => ({ instanceId })),+ float: command('floatWidget', (instanceId: string, region?: ActionPayload<'floatWidget'>['region']) =>+ region ? { instanceId, region } : { instanceId }+ ),focusFloating: command('focusFloatingWidget', (instanceId: string) => ({ instanceId })),move: command('moveWidgetInstance'),open: command('openRegionWidget'),