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(workbench): drag bottom widgets into the right cluster

Josh Corbett5d33d117717f
diff --git a/invokeai/frontend/webv2/src/workbench/shell/StatusBar.tsx b/invokeai/frontend/webv2/src/workbench/shell/StatusBar.tsx
index 8abaaf6916..18234cd5a8 100644
--- a/invokeai/frontend/webv2/src/workbench/shell/StatusBar.tsx
+++ b/invokeai/frontend/webv2/src/workbench/shell/StatusBar.tsx
@@ -3,6 +3,7 @@ import type { WidgetRegionDropState } from '@workbench/widgetDnd';
import type { PlacedWidgetRegionItem, WidgetPlacementInstanceMeta } from '@workbench/widgetRegionViewModel';
import { Box, Popover, Portal } from '@chakra-ui/react';
+import { useDroppable } from '@dnd-kit/core';
import { horizontalListSortingStrategy } from '@dnd-kit/sortable';
import { PopoverContent, Row, Tooltip } from '@platform/ui';
import {
@@ -14,6 +15,7 @@ import {
type WidgetEnableMenuItem,
type WidgetInstanceContextMenuTarget,
} from '@workbench/widget-frame';
+import { getWidgetRegionEndDropData, getWidgetRegionEndDropId } from '@workbench/widgetDnd';
import { resolveWidgetLabel } from '@workbench/widgetLabels';
import { closeWidgetPlacement, openWidgetPlacement, revealWidgetPlacement } from '@workbench/widgetPlacementCommands';
import { areWidgetPlacementProjectsEqual, getWidgetPlacementProject } from '@workbench/widgetPlacementMeta';
@@ -44,6 +46,16 @@ const BOTTOM_MENU_TRIGGER = { kind: 'bottom' } as const;
* theme.
*/
const COMPACT_ROW_HOVER_PROPS = { bg: 'bg.emphasized', color: 'fg' };
+
+/** The stretch between the clusters doubles as the "move to the right side" drop target. */
+const BottomEndDropZone = () => {
+ const { setNodeRef } = useDroppable({
+ data: getWidgetRegionEndDropData('bottom'),
+ id: getWidgetRegionEndDropId('bottom'),
+ });
+
+ return <Box ref={setNodeRef} alignSelf="stretch" flex="1" />;
+};
const COMPACT_ROW_ACTIVE_PROPS = { bg: 'bg.emphasized', color: 'brand.fg' };
const COMPACT_ROW_ACTIVE_HOVER_PROPS = { bg: 'bg.emphasized', color: 'brand.fg' };
const TOOLTIP_POSITIONING = { placement: 'top' } as const;
@@ -76,8 +88,8 @@ export const StatusBar = ({ dropState }: { dropState: WidgetRegionDropState }) =
});
// The trailing cluster: placement stays in `instanceIds` order within each
// side, so drag-reorders keep working; only the render splits. Cluster
- // membership moves through the context menu alone — a drag across the
- // spacer reorders within the item's own cluster rather than migrating it.
+ // membership moves via the context menu, by dropping onto the spacer, or by
+ // landing beside a widget of the other cluster (see `resolveWidgetDragEnd`).
const alignEndIds = useMemo(
() => new Set(bottomRegion.alignEndInstanceIds ?? []),
[bottomRegion.alignEndInstanceIds]
@@ -168,7 +180,7 @@ export const StatusBar = ({ dropState }: { dropState: WidgetRegionDropState }) =
onToggle={toggleBottomWidget}
/>
- <Box flex="1" />
+ <BottomEndDropZone />
{endItems.map((item) => (
<CompactBottomWidget
key={item.id}
diff --git a/invokeai/frontend/webv2/src/workbench/widgetDnd.test.ts b/invokeai/frontend/webv2/src/workbench/widgetDnd.test.ts
index 2028cf40dc..a0df7ee007 100644
--- a/invokeai/frontend/webv2/src/workbench/widgetDnd.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/widgetDnd.test.ts
@@ -10,6 +10,8 @@ import {
getWidgetInstanceDragData,
getWidgetInstanceDragId,
getWidgetRegionDropData,
+ getWidgetRegionEndDropData,
+ getWidgetRegionEndDropId,
resolveWidgetDragEnd,
widgetCollisionDetection,
} from './widgetDnd';
@@ -92,6 +94,98 @@ const createProjectWithPreviewInCenterAndRight = (): Project => {
};
};
+const createProjectWithBottomEndCluster = (): Project => {
+ const project = getActiveProject(createInitialWorkbenchState());
+
+ return {
+ ...project,
+ widgetRegions: {
+ ...project.widgetRegions,
+ bottom: {
+ ...project.widgetRegions.bottom,
+ alignEndInstanceIds: ['notifications'],
+ },
+ },
+ };
+};
+
+const getBottomWidget = (_typeId: WidgetTypeId) => ({
+ manifest: { allowedRegions: ['bottom' as const], allowMultiple: false },
+});
+
+describe('bottom cluster drops', () => {
+ it('dropping on the trailing spacer joins the end cluster at the end', () => {
+ const project = createProjectWithBottomEndCluster();
+ const [first] = project.widgetRegions.bottom.instanceIds;
+ const resolution = resolveWidgetDragEnd(
+ project,
+ getWidgetInstanceDragData('bottom', first!, first as WidgetTypeId),
+ getWidgetRegionEndDropData('bottom'),
+ getBottomWidget
+ );
+
+ expect(resolution).toMatchObject({ align: 'end', type: 'reorder' });
+ expect((resolution as { instanceIds: string[] }).instanceIds.at(-1)).toBe(first);
+ });
+
+ it("landing beside a widget adopts that widget's cluster", () => {
+ const project = createProjectWithBottomEndCluster();
+ const [first] = project.widgetRegions.bottom.instanceIds;
+ const resolution = resolveWidgetDragEnd(
+ project,
+ getWidgetInstanceDragData('bottom', first!, first as WidgetTypeId),
+ getWidgetInstanceDragData('bottom', 'notifications', 'notifications'),
+ getBottomWidget
+ );
+
+ expect(resolution).toMatchObject({ align: 'end', type: 'reorder' });
+ });
+
+ it('keeps a same-cluster reorder free of alignment changes', () => {
+ const project = createProjectWithBottomEndCluster();
+ const [first, second] = project.widgetRegions.bottom.instanceIds;
+ const resolution = resolveWidgetDragEnd(
+ project,
+ getWidgetInstanceDragData('bottom', first!, first as WidgetTypeId),
+ getWidgetInstanceDragData('bottom', second!, second as WidgetTypeId),
+ getBottomWidget
+ );
+
+ expect(resolution).toMatchObject({ type: 'reorder' });
+ expect(resolution).not.toHaveProperty('align');
+ });
+});
+
+describe('bottom cluster collisions', () => {
+ it('a pointer over the spacer wins the end zone, not the nearest chip', () => {
+ // The spacer sits inside the strip's own region droppable, which used to
+ // shadow it into the nearest-chip fallback — the drop then landed beside
+ // a start chip and the gesture silently did nothing.
+ const collisions = widgetCollisionDetection(
+ createCollisionArgs({
+ activeData: getWidgetInstanceDragData('bottom', 'server-status', 'server-status'),
+ collisionRect: getRect(200, 0, 10, 10),
+ droppables: [
+ { data: getWidgetRegionDropData('bottom'), id: 'widget-region:bottom', rect: getRect(0, 0, 600, 24) },
+ {
+ data: getWidgetInstanceDragData('bottom', 'notifications', 'notifications'),
+ id: getWidgetInstanceDragId('bottom', 'notifications'),
+ rect: getRect(0, 0, 80, 24),
+ },
+ {
+ data: getWidgetRegionEndDropData('bottom'),
+ id: getWidgetRegionEndDropId('bottom'),
+ rect: getRect(100, 0, 400, 24),
+ },
+ ],
+ pointerCoordinates: { x: 205, y: 12 },
+ })
+ );
+
+ expect(collisions.map((collision) => collision.id)).toEqual([getWidgetRegionEndDropId('bottom')]);
+ });
+});
+
describe('widget dnd helpers', () => {
it('uses region-scoped draggable ids for duplicated widget instances', () => {
expect(getWidgetInstanceDragId('center', 'preview')).not.toBe(getWidgetInstanceDragId('right', 'preview'));
diff --git a/invokeai/frontend/webv2/src/workbench/widgetDnd.ts b/invokeai/frontend/webv2/src/workbench/widgetDnd.ts
index 36ce43f1d3..8a7b098d82 100644
--- a/invokeai/frontend/webv2/src/workbench/widgetDnd.ts
+++ b/invokeai/frontend/webv2/src/workbench/widgetDnd.ts
@@ -56,7 +56,10 @@ export const measureDroppableVisibleRect = (element: HTMLElement): ClientRect =>
export interface WidgetDndProject {
widgetInstances: Record<WidgetInstanceId, { typeId: WidgetTypeId; title?: string }>;
- widgetRegions: Record<WidgetRegion, Pick<WidgetRegionState, 'activeInstanceId' | 'instanceIds'>>;
+ widgetRegions: Record<
+ WidgetRegion,
+ Pick<WidgetRegionState, 'activeInstanceId' | 'alignEndInstanceIds' | 'instanceIds'>
+ >;
}
export interface ActiveWidgetDrag {
@@ -79,7 +82,13 @@ export interface WidgetRegionDropData {
region: WidgetRegion;
}
-export type WidgetDndData = WidgetInstanceDragData | WidgetRegionDropData;
+/** The trailing cluster of a strip (the flex spacer): dropping here aligns the widget to the end. */
+export interface WidgetRegionEndDropData {
+ kind: 'widget-region-end';
+ region: WidgetRegion;
+}
+
+export type WidgetDndData = WidgetInstanceDragData | WidgetRegionDropData | WidgetRegionEndDropData;
export interface WidgetDndManifestLookupResult {
manifest: {
@@ -102,6 +111,8 @@ export type WidgetDragEndResolution =
instanceIds: WidgetInstanceId[];
region: WidgetRegion;
type: 'reorder';
+ /** Cluster the drop landed in, when it differs from the widget's current one. */
+ align?: 'start' | 'end';
}
| {
fromRegion: WidgetRegion;
@@ -109,6 +120,7 @@ export type WidgetDragEndResolution =
toIndex: number;
toRegion: WidgetRegion;
type: 'move';
+ align?: 'start' | 'end';
};
export const getWidgetInstanceDragId = (region: WidgetRegion, instanceId: WidgetInstanceId): string =>
@@ -116,6 +128,13 @@ export const getWidgetInstanceDragId = (region: WidgetRegion, instanceId: Widget
export const getWidgetRegionDropId = (region: WidgetRegion): string => `widget-region:${region}`;
+export const getWidgetRegionEndDropId = (region: WidgetRegion): string => `widget-region-end:${region}`;
+
+export const getWidgetRegionEndDropData = (region: WidgetRegion): WidgetRegionEndDropData => ({
+ kind: 'widget-region-end',
+ region,
+});
+
export const getWidgetInstanceDragData = (
region: WidgetRegion,
instanceId: WidgetInstanceId,
@@ -137,8 +156,11 @@ export const isWidgetInstanceDragData = (data: unknown): data is WidgetInstanceD
export const isWidgetRegionDropData = (data: unknown): data is WidgetRegionDropData =>
isRecord(data) && data.kind === 'widget-region' && isWidgetRegion(data.region);
+export const isWidgetRegionEndDropData = (data: unknown): data is WidgetRegionEndDropData =>
+ isRecord(data) && data.kind === 'widget-region-end' && isWidgetRegion(data.region);
+
export const isWidgetDndData = (data: unknown): data is WidgetDndData =>
- isWidgetInstanceDragData(data) || isWidgetRegionDropData(data);
+ isWidgetInstanceDragData(data) || isWidgetRegionDropData(data) || isWidgetRegionEndDropData(data);
export const regionHasWidgetType = (
project: WidgetDndProject,
@@ -225,11 +247,31 @@ export const resolveWidgetDragEnd = (
}
if (fromRegion === overRegion) {
+ const overRegionState = project.widgetRegions[overRegion];
+ const alignEndIds = overRegionState.alignEndInstanceIds ?? [];
+ const isActiveEnd = alignEndIds.includes(activeData.instanceId);
+
+ // Dropping on the strip's trailing spacer joins the end cluster.
+ if (overData.kind === 'widget-region-end') {
+ const oldIndex = overRegionState.instanceIds.indexOf(activeData.instanceId);
+
+ if (oldIndex === -1) {
+ return null;
+ }
+
+ return {
+ activeInstanceId: activeData.instanceId,
+ ...(isActiveEnd ? {} : { align: 'end' }),
+ instanceIds: arrayMove(overRegionState.instanceIds, oldIndex, overRegionState.instanceIds.length - 1),
+ region: overRegion,
+ type: 'reorder',
+ };
+ }
+
if (overData.kind !== 'widget-instance') {
return null;
}
- const overRegionState = project.widgetRegions[overRegion];
const oldIndex = overRegionState.instanceIds.indexOf(activeData.instanceId);
const toIndex = Math.max(0, overRegionState.instanceIds.indexOf(overData.instanceId));
@@ -237,8 +279,12 @@ export const resolveWidgetDragEnd = (
return null;
}
+ // Landing beside a widget adopts that widget's cluster.
+ const isOverEnd = alignEndIds.includes(overData.instanceId);
+
return {
activeInstanceId: activeData.instanceId,
+ ...(isOverEnd === isActiveEnd ? {} : { align: isOverEnd ? 'end' : 'start' }),
instanceIds: arrayMove(overRegionState.instanceIds, oldIndex, toIndex),
region: overRegion,
type: 'reorder',
@@ -251,11 +297,19 @@ export const resolveWidgetDragEnd = (
const overRegionState = project.widgetRegions[overRegion];
const toIndex =
- overData.kind === 'widget-region'
- ? overRegionState.instanceIds.length
- : Math.max(0, overRegionState.instanceIds.indexOf(overData.instanceId));
+ overData.kind === 'widget-instance'
+ ? Math.max(0, overRegionState.instanceIds.indexOf(overData.instanceId))
+ : overRegionState.instanceIds.length;
+ // Entering a region adopts the drop target's cluster; a remembered end
+ // alignment from an earlier placement is cleared when landing at the start.
+ const targetIsEnd =
+ overData.kind === 'widget-region-end' ||
+ (overData.kind === 'widget-instance' && (overRegionState.alignEndInstanceIds ?? []).includes(overData.instanceId));
+ const hasStaleEndAlignment = (overRegionState.alignEndInstanceIds ?? []).includes(activeData.instanceId);
+ const align = targetIsEnd ? ('end' as const) : hasStaleEndAlignment ? ('start' as const) : undefined;
return {
+ ...(align ? { align } : {}),
fromRegion,
instanceId: activeData.instanceId,
toIndex,
@@ -318,6 +372,17 @@ export const widgetCollisionDetection: CollisionDetection = (args) => {
}
if (isWidgetInstanceDragData(activeData)) {
+ // The trailing-cluster spacer sits inside its strip's own region
+ // droppable, which would otherwise shadow it into the nearest-chip
+ // fallback below; a direct pointer hit on it wins like a chip hit.
+ const endZoneCollisions = pointerCollisions.filter((collision) =>
+ isWidgetRegionEndDropData(getCollisionData(args, collision.id))
+ );
+
+ if (endZoneCollisions.length > 0) {
+ return endZoneCollisions;
+ }
+
const widgetRegionCollisions = pointerCollisions.filter((collision) => {
return isWidgetRegionDropData(getCollisionData(args, collision.id));
});
diff --git a/invokeai/frontend/webv2/src/workbench/widgetPlacementCommands.ts b/invokeai/frontend/webv2/src/workbench/widgetPlacementCommands.ts
index 279ffdbec3..cd23ba890f 100644
--- a/invokeai/frontend/webv2/src/workbench/widgetPlacementCommands.ts
+++ b/invokeai/frontend/webv2/src/workbench/widgetPlacementCommands.ts
@@ -185,6 +185,14 @@ export const dispatchWidgetDragEndPlacement = ({
region: resolution.region,
});
+ if (resolution.align) {
+ widgets.setAlignment({
+ align: resolution.align,
+ instanceId: resolution.activeInstanceId,
+ region: resolution.region,
+ });
+ }
+
return { ok: true, region: resolution.region };
}
@@ -195,5 +203,9 @@ export const dispatchWidgetDragEndPlacement = ({
toRegion: resolution.toRegion,
});
+ if (resolution.align) {
+ widgets.setAlignment({ align: resolution.align, instanceId: resolution.instanceId, region: resolution.toRegion });
+ }
+
return { ok: true, region: resolution.toRegion };
};