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): keep a rail slot for floating widgets
Josh Corbett46483089c9ce
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.jsonindex 12498a092d..d9b76f09e5 100644--- a/invokeai/frontend/webv2/public/locales/en.json+++ b/invokeai/frontend/webv2/public/locales/en.json@@ -1867,10 +1867,11 @@"floatWindow": "Float Window","maximize": "Maximize","move": "Move {{label}} window",+ "railSlot": "{{label}} (floating — click to dock)","resize": "Resize window","restore": "Restore",- "shade": "Shade",- "unshade": "Unshade"+ "shade": "Collapse",+ "unshade": "Expand"},"loadingLabel": "Loading {{label}}","moveToLeftSide": "Move to left side",@@ -2512,7 +2513,6 @@"hideInProgressDiffusion": "Hide in-progress diffusion","imageCount_one": "{{count}} image","imageCount_other": "{{count}} images",- "invoke": "Invoke","itemCount_one": "{{count}} item","itemCount_other": "{{count}} items","loadingBoard": "Loading board",diff --git a/invokeai/frontend/webv2/src/workbench/floatingWidgets.test.ts b/invokeai/frontend/webv2/src/workbench/floatingWidgets.test.tsindex 3921580050..2bf59e2f98 100644--- a/invokeai/frontend/webv2/src/workbench/floatingWidgets.test.ts+++ b/invokeai/frontend/webv2/src/workbench/floatingWidgets.test.ts@@ -139,6 +139,27 @@ describe('floatWidget', () => {});});+describe('closeFloatingWidget', () => {+ it('drops the window without docking, leaving the rail and its disclosure untouched', () => {+ const floated = floatGallery();+ const rightBefore = getActiveProject(floated).widgetRegions.right;+ const state = workbenchReducer(floated, { instanceId: 'gallery', type: 'closeFloatingWidget' });+ const project = getActiveProject(state);++ expect(project.floatingWidgets).toBeUndefined();+ expect(project.widgetRegions.right).toBe(rightBefore);+ expect(getRegionsHolding(project, 'gallery')).toEqual([]);+ // The instance survives for a later placement, as a closed tab's does.+ expect(project.widgetInstances.gallery).toBeDefined();+ });++ it('is a no-op for an instance that is not floating', () => {+ const state = createInitialWorkbenchState();++ expect(workbenchReducer(state, { instanceId: 'gallery', type: 'closeFloatingWidget' })).toBe(state);+ });+});+describe('dockFloatingWidget', () => {it('returns the instance to its origin region as the active widget', () => {const state = workbenchReducer(floatGallery(), { instanceId: 'gallery', type: 'dockFloatingWidget' });diff --git a/invokeai/frontend/webv2/src/workbench/shell/WorkbenchShell.tsx b/invokeai/frontend/webv2/src/workbench/shell/WorkbenchShell.tsxindex e053e74cd0..ddf589bdcd 100644--- a/invokeai/frontend/webv2/src/workbench/shell/WorkbenchShell.tsx+++ b/invokeai/frontend/webv2/src/workbench/shell/WorkbenchShell.tsx@@ -1,3 +1,5 @@+import type { Project } from '@workbench/projectContracts';+import { Flex, HStack, Text, VisuallyHidden } from '@chakra-ui/react';import {DndContext,@@ -11,6 +13,7 @@ import {import { restrictToWindowEdges } from '@dnd-kit/modifiers';import { sortableKeyboardCoordinates } from '@dnd-kit/sortable';import { GalleryDragCursor } from '@features/gallery/utility';+import { flushWorkbenchDrafts } from '@platform/react/draftRegistry';import { useMountEffect } from '@platform/react/useMountEffect';import { FocusRegionProvider } from '@workbench/focusRegions';import { WidgetIcon } from '@workbench/iconResolver';@@ -68,6 +71,7 @@ const DND_MODIFIERS = [restrictToWindowEdges];* widgetCollisionDetection, not by shrinking zones.*/const DND_AUTO_SCROLL = { acceleration: 5 };+const EMPTY_FLOATING: NonNullable<Project['floatingWidgets']> = {};export const WorkbenchShell = () => {const { notifications, widgets } = useWorkbenchCommands();@@ -76,6 +80,7 @@ export const WorkbenchShell = () => {const projectName = useActiveProjectSelector((project) => project.name);const leftRegion = useActiveProjectSelector((project) => project.widgetRegions.left);const rightRegion = useActiveProjectSelector((project) => project.widgetRegions.right);+ const floatingWidgets = useActiveProjectSelector((project) => project.floatingWidgets ?? EMPTY_FLOATING);const placementProject = useActiveProjectSelector(getWidgetPlacementProject, areWidgetPlacementProjectsEqual);const sensors = useSensors(// `PrimaryMouseSensor`/`HoldToDragSensor` replace the stock `PointerSensor`:@@ -94,24 +99,26 @@ export const WorkbenchShell = () => {const leftRegionViewModel = useMemo(() =>createWidgetRegionViewModelFromState({+ floatingWidgets,region: 'left',regionState: leftRegion,widgetInstances: placementProject.widgetInstances,widgets: getWidgetsForRegion('left'),getWidgetLabel,}),- [getWidgetLabel, leftRegion, placementProject.widgetInstances]+ [floatingWidgets, getWidgetLabel, leftRegion, placementProject.widgetInstances]);const rightRegionViewModel = useMemo(() =>createWidgetRegionViewModelFromState({+ floatingWidgets,region: 'right',regionState: rightRegion,widgetInstances: placementProject.widgetInstances,widgets: getWidgetsForRegion('right'),getWidgetLabel,}),- [getWidgetLabel, placementProject.widgetInstances, rightRegion]+ [floatingWidgets, getWidgetLabel, placementProject.widgetInstances, rightRegion]);const leftMenuItems = useMemo(() => getWidgetRegionItems(leftRegionViewModel), [leftRegionViewModel]);const rightMenuItems = useMemo(() => getWidgetRegionItems(rightRegionViewModel), [rightRegionViewModel]);@@ -192,46 +199,69 @@ export const WorkbenchShell = () => {[placementProject, widgets]);const handleDragCancel = useCallback(() => setActiveDrag(null), []);+ // A floating slot's click is the rail-side dock control, the mirror of the+ // window's own; the drafts flush for the same reason that control's does.const handleSelect = useCallback(- (region: WidgetBarGroup['region'], instanceId: string) =>- revealWidgetPlacement({ instanceId, project: placementProject, region, widgets }),- [placementProject, widgets]+ (region: WidgetBarGroup['region'], instanceId: string) => {+ if (floatingWidgets[instanceId]) {+ flushWorkbenchDrafts();+ widgets.dockFloating(instanceId);++ return;+ }++ revealWidgetPlacement({ instanceId, project: placementProject, region, widgets });+ },+ [floatingWidgets, placementProject, widgets]+ );+ // Removing a floating slot closes the window outright — never dock-then-+ // toggle, which would pop the panel open and retarget the route on the way.+ const closeFloating = useCallback(+ (instanceId: string) => {+ flushWorkbenchDrafts();+ widgets.closeFloating(instanceId);+ },+ [widgets]);const handleToggleLeft = useCallback((item: (typeof leftMenuItems)[number]) =>- item.isEnabled- ? closeWidgetPlacement({- widgets,- getWidgetById,- instanceId: item.id,- project: placementProject,- region: 'left',- })- : openWidgetPlacement({- widgets,- getWidgetsForRegion,- options: { createNew: item.allowMultiple, preferredRegions: ['left'] },- typeId: item.typeId,- }),- [placementProject, widgets]+ item.isEnabled && item.isFloating+ ? closeFloating(item.id)+ : item.isEnabled+ ? closeWidgetPlacement({+ widgets,+ getWidgetById,+ instanceId: item.id,+ project: placementProject,+ region: 'left',+ })+ : openWidgetPlacement({+ widgets,+ getWidgetsForRegion,+ options: { createNew: item.allowMultiple, preferredRegions: ['left'] },+ typeId: item.typeId,+ }),+ [closeFloating, placementProject, widgets]);const handleToggleRight = useCallback((item: (typeof rightMenuItems)[number]) =>- item.isEnabled- ? closeWidgetPlacement({- widgets,- getWidgetById,- instanceId: item.id,- project: placementProject,- region: 'right',- })- : openWidgetPlacement({- widgets,- getWidgetsForRegion,- options: { createNew: item.allowMultiple, preferredRegions: ['right'] },- typeId: item.typeId,- }),- [placementProject, widgets]+ item.isEnabled && item.isFloating+ ? closeFloating(item.id)+ : item.isEnabled+ ? closeWidgetPlacement({+ widgets,+ getWidgetById,+ instanceId: item.id,+ project: placementProject,+ region: 'right',+ })+ : openWidgetPlacement({+ widgets,+ getWidgetsForRegion,+ options: { createNew: item.allowMultiple, preferredRegions: ['right'] },+ typeId: item.typeId,+ }),+ [closeFloating, placementProject, widgets]);const leftRailGroups = useMemo(() => [diff --git a/invokeai/frontend/webv2/src/workbench/widget-frame/FloatingWidgetWindow.tsx b/invokeai/frontend/webv2/src/workbench/widget-frame/FloatingWidgetWindow.tsxindex e9b96ae857..700e365e87 100644--- a/invokeai/frontend/webv2/src/workbench/widget-frame/FloatingWidgetWindow.tsx+++ b/invokeai/frontend/webv2/src/workbench/widget-frame/FloatingWidgetWindow.tsx@@ -1,7 +1,7 @@import type { FloatingWidgetState } from '@workbench/layoutContracts';import type { WidgetInstanceId } from '@workbench/widgetContracts';-import { Box, Flex, HStack, Icon, Text } from '@chakra-ui/react';+import { Box, Flex, HStack, Icon, Separator, Text } from '@chakra-ui/react';import { flushWorkbenchDrafts } from '@platform/react/draftRegistry';import { IconButton } from '@platform/ui/Button';import { Tooltip } from '@platform/ui/Tooltip';@@ -376,6 +376,7 @@ export const FloatingWidgetWindow = ({</Suspense></FloatingChromeBoundary>) : null}+ {isEnabled && widget ? <Separator h="4" mx="0.5" orientation="vertical" /> : null}<Tooltip content={isShaded ? t('widgets.floating.unshade') : t('widgets.floating.shade')}><IconButtonaria-label={isShaded ? t('widgets.floating.unshade') : t('widgets.floating.shade')}diff --git a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetBar.tsx b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetBar.tsxindex 6412ea462b..6690ec9b9a 100644--- a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetBar.tsx+++ b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetBar.tsx@@ -133,7 +133,10 @@ const RailGroup = ({separated: boolean;side: 'left' | 'right';}) => {- const sortableInstanceIds = useMemo(() => group.railItems.map((item) => item.id), [group.railItems]);+ const sortableInstanceIds = useMemo(+ () => group.railItems.filter((item) => !item.isFloating).map((item) => item.id),+ [group.railItems]+ );const select = useCallback((instanceId: WidgetInstanceId) => onSelect(group.region, instanceId),[group.region, onSelect]@@ -198,6 +201,13 @@ export const WIDGET_ITEM_SX: SystemStyleObject = {bg: 'bg.emphasized',color: 'brand.fg',},+ // A floating slot reads as a placeholder for the window: outlined, not filled.+ '&[data-floating]': {+ outline: '1px dashed',+ outlineColor: 'border.emphasized',+ outlineOffset: '-1px',+ color: 'fg.subtle',+ },_disabled: WIDGET_SLOT_DISABLED_PROPS,};@@ -216,7 +226,12 @@ const WidgetSlot = ({region: WidgetRegion;tooltipPlacement: 'left' | 'right';}) => {- const tooltipLabel = item.failureMessage ? `${item.label}: ${item.failureMessage}` : item.label;+ const { t } = useTranslation();+ const tooltipLabel = item.isFloating+ ? t('widgets.floating.railSlot', { label: item.label })+ : item.failureMessage+ ? `${item.label}: ${item.failureMessage}`+ : item.label;const isDisabled = item.status === 'disabled';const positioning = useMemo(() => ({ placement: tooltipPlacement }) as const, [tooltipPlacement]);@@ -230,7 +245,7 @@ const WidgetSlot = ({const handleContextMenu = useCallback((event: MouseEvent) => onContextMenu(item, event), [item, onContextMenu]);const { dragHandleProps, setNodeRef, style } = useWidgetSortable({- disabled: isDisabled,+ disabled: isDisabled || item.isFloating === true,instanceId: item.id,region,typeId: item.typeId,@@ -242,11 +257,12 @@ const WidgetSlot = ({<Row{...dragHandleProps}css={WIDGET_ITEM_SX}- aria-label={item.label}+ aria-label={tooltipLabel}aria-disabled={isDisabled}aria-pressed={isActive}as="button"data-disabled={isDisabled ? '' : undefined}+ data-floating={item.isFloating ? '' : undefined}tabIndex={isDisabled ? -1 : undefined}{...intentPreloadProps}onClick={handleClick}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 ff2bda580b..bfd0ebf87e 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@@ -133,13 +133,11 @@ describe('WidgetFloatButton', () => {expect(await renderButton('right', false)).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 nothing for a center view, even one that is not the last', async () => {+ expect(await renderButton('center')).toBeNull();- it('renders for a center view that is not the last one', async () => {floatMocks.centerInstanceIds = ['image-map-instance', 'canvas-instance'];- expect(await renderButton('center')).not.toBeNull();+ expect(await renderButton('center')).toBeNull();});});diff --git a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetFrames.tsx b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetFrames.tsxindex 36a9f99690..a331c81cfd 100644--- a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetFrames.tsx+++ b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetFrames.tsx@@ -311,9 +311,10 @@ export const WidgetFloatButton = ({}) => {const { t } = useTranslation();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;+ // A dialog or popover's chrome never floats, and neither does the center:+ // its views are the work surface, and a window over an emptied surface is a+ // view the rails cannot reach. Panels are the dock-back target.+ const dockableRegion = isWidgetRegion(region) && region !== 'center' ? region : undefined;// Floating unmounts the docked subtree; the draft registry's cleanup only// deregisters the flusher, so an uncommitted edit is lost without this. The// region rides along: one instance may be placed in several regions (the@@ -328,10 +329,7 @@ export const WidgetFloatButton = ({widgets.float(instanceId, dockableRegion);}, [dockableRegion, instanceId, widgets]);// Floating is offered only from dockable regions; the floating window's own- // 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.+ // chrome carries the dock control.const canFloat = Boolean(manifest.allowFloating) && dockableRegion !== undefined;if (!canFloat) {diff --git a/invokeai/frontend/webv2/src/workbench/widget-frame/createWidgetRuntime.test.ts b/invokeai/frontend/webv2/src/workbench/widget-frame/createWidgetRuntime.test.tsindex 87b6f30240..9dae9f664c 100644--- a/invokeai/frontend/webv2/src/workbench/widget-frame/createWidgetRuntime.test.ts+++ b/invokeai/frontend/webv2/src/workbench/widget-frame/createWidgetRuntime.test.ts@@ -54,6 +54,7 @@ const createDispatch = () => {const widgets: WorkbenchWidgetCommands = {dockFloating: (instanceId) => dispatch({ instanceId, type: 'dockFloatingWidget' }),+ closeFloating: (instanceId) => dispatch({ instanceId, type: 'closeFloatingWidget' }),float: (instanceId, region) =>dispatch(region ? { instanceId, region, type: 'floatWidget' } : { instanceId, type: 'floatWidget' }),focusFloating: (instanceId) => dispatch({ instanceId, type: 'focusFloatingWidget' }),diff --git a/invokeai/frontend/webv2/src/workbench/widgetPlacementCommands.test.ts b/invokeai/frontend/webv2/src/workbench/widgetPlacementCommands.test.tsindex 9ef217d4b6..d7d472313c 100644--- a/invokeai/frontend/webv2/src/workbench/widgetPlacementCommands.test.ts+++ b/invokeai/frontend/webv2/src/workbench/widgetPlacementCommands.test.ts@@ -67,6 +67,7 @@ const applyCommand = (state: WorkbenchState, command: (widgets: WorkbenchWidgetCconst createWidgetCommands = (dispatch: (action: WorkbenchAction) => void): WorkbenchWidgetCommands => ({dockFloating: (instanceId) => dispatch({ instanceId, type: 'dockFloatingWidget' }),+ closeFloating: (instanceId) => dispatch({ instanceId, type: 'closeFloatingWidget' }),float: (instanceId) => dispatch({ instanceId, type: 'floatWidget' }),focusFloating: (instanceId) => dispatch({ instanceId, type: 'focusFloatingWidget' }),move: (options) => dispatch({ ...options, type: 'moveWidgetInstance' }),diff --git a/invokeai/frontend/webv2/src/workbench/widgetRegionItems.ts b/invokeai/frontend/webv2/src/workbench/widgetRegionItems.tsindex 3184db93f3..f96fd7caf9 100644--- a/invokeai/frontend/webv2/src/workbench/widgetRegionItems.ts+++ b/invokeai/frontend/webv2/src/workbench/widgetRegionItems.ts@@ -4,6 +4,7 @@ export {getWidgetRegionItems,isPlacedWidgetRegionItem,type AvailableWidgetTypeItem,+ type FloatingWidgetPlacement,type PlacedWidgetRegionItem,type WidgetPlacementInstanceMeta,type WidgetPlacementMeta,diff --git a/invokeai/frontend/webv2/src/workbench/widgetRegionViewModel.test.ts b/invokeai/frontend/webv2/src/workbench/widgetRegionViewModel.test.tsindex 85664be8ba..c2f6d76064 100644--- a/invokeai/frontend/webv2/src/workbench/widgetRegionViewModel.test.ts+++ b/invokeai/frontend/webv2/src/workbench/widgetRegionViewModel.test.ts@@ -60,6 +60,53 @@ describe('widget region view model', () => {expect(getWidgetRegionItems(viewModel).map((item) => item.label)).toEqual(['Alpha', 'Beta']);});+ it('keeps a floated widget in the rail at the slot it docks back to, outside the sortable list', () => {+ const widgets = [createWidget({ id: 'a', label: 'A' }), createWidget({ id: 'b', label: 'B' })];+ const widgetInstances = { 'a:1': createInstance('a:1', 'a'), 'b:1': createInstance('b:1', 'b') };+ const viewModel = createWidgetRegionViewModel({+ activeInstanceId: 'b:1',+ floatingWidgets: {+ 'a:1': { returnIndex: 0, returnRegion: 'left' },+ 'b:1': { returnIndex: 0, returnRegion: 'right' },+ },+ instanceIds: ['b:1'],+ region: 'left',+ widgetInstances,+ widgets,+ });++ expect(viewModel.placedItems.map((item) => [item.id, item.isFloating ?? false])).toEqual([+ ['a:1', true],+ ['b:1', false],+ ]);+ expect(viewModel.sortableInstanceIds).toEqual(['b:1']);+ expect(viewModel.availableItems.map((item) => item.typeId)).toEqual([]);+ });++ it('orders floating slots by their return index and clamps indices the rail no longer has', () => {+ const widgets = ['a', 'b', 'c', 'd', 'e'].map((id) => createWidget({ id, label: id.toUpperCase() }));+ const widgetInstances = Object.fromEntries(+ widgets.map((widget) => [widget.manifest.id, createInstance(widget.manifest.id, widget.manifest.id)])+ );+ const viewModel = createWidgetRegionViewModel({+ floatingWidgets: {+ // Later-sorted insertions must not displace earlier ones.+ d: { returnIndex: 2, returnRegion: 'left' },+ a: { returnIndex: 0, returnRegion: 'left' },+ // Beyond the rail: appended, as docking would.+ e: { returnIndex: 99, returnRegion: 'left' },+ c: { returnRegion: 'left' },+ },+ instanceIds: ['b'],+ region: 'left',+ widgetInstances,+ widgets,+ });++ expect(viewModel.placedItems.map((item) => item.id)).toEqual(['a', 'b', 'd', 'e', 'c']);+ expect(viewModel.sortableInstanceIds).toEqual(['b']);+ });+it('filters already placed singleton widget types from available items', () => {const viewModel = createWidgetRegionViewModel({instanceIds: ['alpha'],diff --git a/invokeai/frontend/webv2/src/workbench/widgetRegionViewModel.ts b/invokeai/frontend/webv2/src/workbench/widgetRegionViewModel.tsindex 72ccb13903..7309a310c3 100644--- a/invokeai/frontend/webv2/src/workbench/widgetRegionViewModel.ts+++ b/invokeai/frontend/webv2/src/workbench/widgetRegionViewModel.ts@@ -1,4 +1,4 @@-import type { WidgetRegion, WidgetRegionState } from '@workbench/layoutContracts';+import type { FloatingWidgetState, WidgetRegion, WidgetRegionState } from '@workbench/layoutContracts';import type {NormalizedWidgetManifest,RegisteredWidget,@@ -32,11 +32,17 @@ export interface PlacedWidgetRegionItem<> extends BaseWidgetRegionItem {instance: Instance;isEnabled: true;+ /** Detached into a floating window; the rail keeps its slot, at the position it docks back to. */+ isFloating?: true;}+/** Only the placement half of a window: the slot this region keeps for it. */+export type FloatingWidgetPlacement = Pick<FloatingWidgetState, 'returnIndex' | 'returnRegion'>;+export interface AvailableWidgetTypeItem extends BaseWidgetRegionItem {instance?: undefined;isEnabled: false;+ isFloating?: undefined;}export type WidgetRegionItem<Instance extends WidgetPlacementInstanceMeta = WidgetInstanceContract> =@@ -51,8 +57,38 @@ export interface WidgetRegionViewModel<Instance extends WidgetPlacementInstanceMsortableInstanceIds: WidgetInstanceId[];}+/**+ * A floated widget leaves its region's `instanceIds`, but the rail still shows+ * its slot — at the index it docks back to — so the window stays one click+ * from the strip it came from. Ascending by index keeps later insertions from+ * displacing earlier ones.+ */+const withFloatingSlots = (+ instanceIds: WidgetInstanceId[],+ region: WidgetRegion,+ floatingWidgets: Record<WidgetInstanceId, FloatingWidgetPlacement> | undefined+): { instanceId: WidgetInstanceId; isFloating: boolean }[] => {+ const slots = instanceIds.map((instanceId) => ({ instanceId, isFloating: false }));++ if (!floatingWidgets) {+ return slots;+ }++ const floating = (Object.entries(floatingWidgets) as [WidgetInstanceId, FloatingWidgetPlacement][])+ .filter(([instanceId, state]) => state.returnRegion === region && !instanceIds.includes(instanceId))+ .map(([instanceId, state]) => ({ index: state.returnIndex ?? Number.POSITIVE_INFINITY, instanceId }))+ .sort((left, right) => left.index - right.index);++ for (const { index, instanceId } of floating) {+ slots.splice(Math.min(Math.max(0, Math.floor(index)), slots.length), 0, { instanceId, isFloating: true });+ }++ return slots;+};+export const createWidgetRegionViewModel = <Instance extends WidgetPlacementInstanceMeta>({activeInstanceId,+ floatingWidgets,instanceIds,region,widgetInstances,@@ -60,6 +96,8 @@ export const createWidgetRegionViewModel = <Instance extends WidgetPlacementInstgetWidgetLabel = (manifest) => (typeof manifest.label === 'string' ? manifest.label : manifest.id),}: {activeInstanceId?: WidgetInstanceId;+ /** Windows floated out of regions; those returning here keep a rail slot. */+ floatingWidgets?: Record<WidgetInstanceId, FloatingWidgetPlacement>;instanceIds: WidgetInstanceId[];region: WidgetRegion;widgetInstances: Record<string, Instance>;@@ -67,29 +105,32 @@ export const createWidgetRegionViewModel = <Instance extends WidgetPlacementInstgetWidgetLabel?: (manifest: NormalizedWidgetManifest) => string;}): WidgetRegionViewModel<Instance> => {const widgetsByType = new Map(widgets.map((widget) => [widget.manifest.id, widget]));- const placedItems = instanceIds.flatMap((instanceId): PlacedWidgetRegionItem<Instance>[] => {- const instance = widgetInstances[instanceId];- const widget = instance ? widgetsByType.get(instance.typeId) : undefined;-- if (!instance || !widget) {- return [];+ const placedItems = withFloatingSlots(instanceIds, region, floatingWidgets).flatMap(+ ({ instanceId, isFloating }): PlacedWidgetRegionItem<Instance>[] => {+ const instance = widgetInstances[instanceId];+ const widget = instance ? widgetsByType.get(instance.typeId) : undefined;++ if (!instance || !widget) {+ return [];+ }++ return [+ {+ failureMessage: widget.failure?.message,+ allowMultiple: widget.manifest.allowMultiple,+ icon: widget.manifest.icon,+ id: instance.id,+ instance,+ isEnabled: true,+ ...(isFloating ? { isFloating: true } : {}),+ label: instance.title ?? getWidgetLabel(widget.manifest),+ status: widget.status,+ typeId: instance.typeId,+ widget,+ },+ ];}-- return [- {- failureMessage: widget.failure?.message,- allowMultiple: widget.manifest.allowMultiple,- icon: widget.manifest.icon,- id: instance.id,- instance,- isEnabled: true,- label: instance.title ?? getWidgetLabel(widget.manifest),- status: widget.status,- typeId: instance.typeId,- widget,- },- ];- });+ );const placedTypeIds = new Set(placedItems.map((item) => item.typeId));const availableItems: AvailableWidgetTypeItem[] = widgets.filter((widget) => widget.manifest.allowMultiple || !placedTypeIds.has(widget.manifest.id))@@ -111,17 +152,21 @@ export const createWidgetRegionViewModel = <Instance extends WidgetPlacementInstavailableItems,placedItems,region,- sortableInstanceIds: placedItems.map((item) => item.id),+ // A floating slot is a pointer to the window, not a tab: it neither drags nor+ // gives the strip a drop index, so it stays out of the sortable list.+ sortableInstanceIds: placedItems.filter((item) => !item.isFloating).map((item) => item.id),};};export const createWidgetRegionViewModelFromState = <Instance extends WidgetPlacementInstanceMeta>({+ floatingWidgets,region,regionState,widgetInstances,widgets,getWidgetLabel,}: {+ floatingWidgets?: Record<WidgetInstanceId, FloatingWidgetPlacement>;region: WidgetRegion;regionState: WidgetRegionState;widgetInstances: Record<string, Instance>;@@ -130,6 +175,7 @@ export const createWidgetRegionViewModelFromState = <Instance extends WidgetPlac}): WidgetRegionViewModel<Instance> =>createWidgetRegionViewModel({activeInstanceId: regionState.activeInstanceId,+ floatingWidgets,getWidgetLabel,instanceIds: regionState.instanceIds,region,diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewHeaderActions.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewHeaderActions.browser.test.tsxindex 1091d3498e..1c312e28db 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewHeaderActions.browser.test.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewHeaderActions.browser.test.tsx@@ -18,12 +18,10 @@ void i18n.use(initReactI18next).init({resources: {en: {translation: {- topbar: { invoke: { unavailable: 'Invoke unavailable: {{reason}}', unrunnable: 'Unrunnable' } },widgets: {preview: {hideFilmstrip: 'Hide filmstrip',hideInProgressDiffusion: 'Hide in-progress diffusion',- invoke: 'Invoke',showFilmstrip: 'Show filmstrip',showInProgressDiffusion: 'Show in-progress diffusion',},@@ -36,13 +34,6 @@ void i18n.use(initReactI18next).init({const state = vi.hoisted(() => ({ filmstripVisible: true, showProgressImagesInViewer: true }));const patchValues = vi.hoisted(() => vi.fn());const updateProjectPreferences = vi.hoisted(() => vi.fn());-const executeCommand = vi.hoisted(() => vi.fn(() => Promise.resolve()));-const invocationState = vi.hoisted(() => ({ blockingReasons: [] as string[], isPreparing: false, isValid: true }));--vi.mock('@workbench/shell/topbar/useInvocationState', () => ({- useInvocationState: () => invocationState,-}));-vi.mock('@features/queue/react', () => ({ useProgressImage: () => null }));vi.mock('./previewHeaderStore', () => ({@@ -90,9 +81,7 @@ const render = async (region: WidgetViewProps['region'] = 'center') => {root?.render(<I18nextProvider i18n={i18n}><ChakraProvider value={system}>- <PreviewHeaderActions- {...({ region, runtime: { commands: { execute: executeCommand } } } as unknown as WidgetViewProps)}- />+ <PreviewHeaderActions {...({ region, runtime: {} } as unknown as WidgetViewProps)} /></ChakraProvider></I18nextProvider>);@@ -107,10 +96,6 @@ beforeEach(() => {state.showProgressImagesInViewer = true;patchValues.mockClear();updateProjectPreferences.mockClear();- executeCommand.mockClear();- invocationState.blockingReasons = [];- invocationState.isPreparing = false;- invocationState.isValid = true;});afterEach(async () => {@@ -150,46 +135,6 @@ describe('preview header toggles', () => {});});-describe('preview floating Invoke control', () => {- it('is offered only while the widget floats', async () => {- await render('center');- expect(host?.querySelector('button[aria-label="Invoke"]')).toBeNull();-- await settle(() => root?.unmount());- host?.remove();-- await render('right');- expect(host?.querySelector('button[aria-label="Invoke"]')).toBeNull();-- await settle(() => root?.unmount());- host?.remove();-- await render('floating');- expect(host?.querySelector('button[aria-label="Invoke"]')).not.toBeNull();- });-- it('runs the app-level Invoke command, the same path as the topbar button', async () => {- await render('floating');-- await settle(() => button('Invoke').click());-- expect(executeCommand).toHaveBeenCalledWith('app.invoke');- });-- it('dims, names the blocking reason, and refuses the click when Invoke cannot run', async () => {- invocationState.isValid = false;- invocationState.blockingReasons = ['The backend is disconnected.'];- await render('floating');-- const control = button('Invoke unavailable: The backend is disconnected.');- expect(control.getAttribute('aria-disabled')).toBe('true');-- await settle(() => control.click());-- expect(executeCommand).not.toHaveBeenCalled();- });-});-vi.mock('./livePreviewFollow', () => ({useLivePreviewFollow: () => ({ sessions: [], pinnedSessionId: null, pin: vi.fn(), showAll: vi.fn() }),}));diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewHeaderActions.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewHeaderActions.tsxindex 944dacaffb..59b3425d60 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewHeaderActions.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewHeaderActions.tsx@@ -1,11 +1,10 @@import type { WidgetViewProps } from '@workbench/widgetContracts';-import { Box, HStack, Icon } from '@chakra-ui/react';-import { IconButton, ToggleIconButton, Tooltip } from '@platform/ui';-import { useInvocationState } from '@workbench/shell/topbar/useInvocationState';+import { Box, HStack } from '@chakra-ui/react';+import { ToggleIconButton } from '@platform/ui';import { getProjectWidgetValues } from '@workbench/widgetState';import { useActiveProjectSelector, useWorkbenchCommands } from '@workbench/WorkbenchContext';-import { GalleryThumbnailsIcon, HourglassIcon, SparklesIcon } from 'lucide-react';+import { GalleryThumbnailsIcon, HourglassIcon } from 'lucide-react';import { useCallback } from 'react';import { useTranslation } from 'react-i18next';@@ -19,14 +18,8 @@ import { getPreviewFilmstripVisible } from './previewSettings';* selection (published by the view via `previewHeaderStore`) plus the* in-progress diffusion toggle. Actions live here — in the frame's standard* header slot — like every other widget, not in the widget body.- *- * Floated, the widget also carries an Invoke control: a floating preview is- * typically parked over a maximized work surface, or on a second display, with- * the topbar's Invoke button out of easy reach — so the window that shows the- * result offers the one action that produces the next one. Docked, the topbar- * is right there and a second Invoke button would only compete with it.*/-export const PreviewHeaderActions = ({ region, runtime }: WidgetViewProps) => {+export const PreviewHeaderActions = ({ region }: WidgetViewProps) => {const { t } = useTranslation();const livePreview = useLivePreviewFollow();const showProgressImagesInViewer = useActiveProjectSelector((project) => project.settings.showProgressImagesInViewer);@@ -69,7 +62,6 @@ export const PreviewHeaderActions = ({ region, runtime }: WidgetViewProps) => {{/* Both toggles go through `ToggleIconButton` so they read as one controltype: the filled variant carries "on", `aria-pressed` carries it forassistive tech, and the label doubles as the tooltip. */}- {region === 'floating' ? <FloatingInvokeButton runtime={runtime} /> : null}<ToggleIconButtonchecked={isFilmstripVisible}icon={GalleryThumbnailsIcon}@@ -88,43 +80,3 @@ export const PreviewHeaderActions = ({ region, runtime }: WidgetViewProps) => {</HStack>);};--/**- * The floating window's Invoke control. It reads the same invocation state as- * the topbar button, so it dims and names the blocking reason under exactly- * the conditions the topbar does, instead of silently doing nothing when the- * route is invalid or the backend is disconnected. Submission goes through the- * registered `app.invoke` command — the topbar button's and the hotkey's path- * — so the validation and disconnect guards are not duplicated here.- *- * Split out so the hook's subscriptions (models, dynamic prompt expansion)- * only run while the widget floats.- */-const FloatingInvokeButton = ({ runtime }: Pick<WidgetViewProps, 'runtime'>) => {- const { t } = useTranslation();- const { blockingReasons, isPreparing, isValid } = useInvocationState();- const canInvoke = isValid && !isPreparing;- const label = canInvoke- ? t('widgets.preview.invoke')- : isPreparing- ? t('topbar.invoke.preparing')- : t('topbar.invoke.unavailable', { reason: blockingReasons[0] ?? t('topbar.invoke.unrunnable') });- const invoke = useCallback(() => void runtime.commands.execute('app.invoke'), [runtime]);-- return (- <Tooltip content={label}>- <IconButton- aria-disabled={!canInvoke}- aria-label={label}- color="yellow.fg"- cursor={canInvoke ? undefined : 'not-allowed'}- opacity={canInvoke ? undefined : 0.55}- size="2xs"- variant="ghost"- onClick={canInvoke ? invoke : undefined}- >- <Icon as={SparklesIcon} boxSize="3.5" />- </IconButton>- </Tooltip>- );-};diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.tsindex ae43e8dcf6..e644ad585a 100644--- a/invokeai/frontend/webv2/src/workbench/workbenchState.ts+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.ts@@ -251,6 +251,7 @@ type WorkbenchReducerAction =region?: WidgetRegion;}| { type: 'dockFloatingWidget'; instanceId: WidgetInstanceId }+ | { type: 'closeFloatingWidget'; instanceId: WidgetInstanceId }| {type: 'setFloatingWidgetGeometry';instanceId: WidgetInstanceId;@@ -3955,6 +3956,19 @@ export const __workbenchReducerInternal = ();});}+ case 'closeFloatingWidget': {+ // The window is the instance's only placement, so closing it is one+ // change: the entry goes, nothing docks, and no surface is revealed.+ return updateActiveProject(state, (project) => {+ if (!project.floatingWidgets?.[action.instanceId]) {+ return project;+ }++ const { [action.instanceId]: _closed, ...remaining } = project.floatingWidgets;++ return { ...project, floatingWidgets: Object.keys(remaining).length > 0 ? remaining : undefined };+ });+ }case 'setFloatingWidgetGeometry': {return updateActiveProject(state, (project) => {const floating = project.floatingWidgets?.[action.instanceId];diff --git a/invokeai/frontend/webv2/src/workbench/workbenchStore.ts b/invokeai/frontend/webv2/src/workbench/workbenchStore.tsindex 9dc4770d9d..7327345f8b 100644--- a/invokeai/frontend/webv2/src/workbench/workbenchStore.ts+++ b/invokeai/frontend/webv2/src/workbench/workbenchStore.ts@@ -422,6 +422,7 @@ const createCommands = (},widgets: {dockFloating: command('dockFloatingWidget', (instanceId: string) => ({ instanceId })),+ closeFloating: command('closeFloatingWidget', (instanceId: string) => ({ instanceId })),float: command('floatWidget', (instanceId: string, region?: ActionPayload<'floatWidget'>['region']) =>region ? { instanceId, region } : { instanceId }),