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
fix(widgets): snap the panel shut during the drag, like legacy
joshistoast76a5a0844f5c
diff --git a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetFrames.tsx b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetFrames.tsxindex 19469f835e..b271e96144 100644--- a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetFrames.tsx+++ b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetFrames.tsx@@ -17,7 +17,7 @@ import { useFocusRegionProps } from '@workbench/focusRegions';import { openWorkbenchSettings } from '@workbench/settings/settingsDialogStore';import { resolveWidgetInstanceLabel } from '@workbench/widgetLabels';import { useActiveProjectSelector, useWorkbenchCommands } from '@workbench/WorkbenchContext';-import { clampPanelSize, getPanelSizeBounds, isPanelCollapseOvershoot } from '@workbench/workbenchState';+import { clampPanelSize, getPanelSizeBounds, shouldSnapPanelShut } from '@workbench/workbenchState';import { SettingsIcon } from 'lucide-react';import {useCallback,@@ -36,9 +36,9 @@ import { WidgetSourceLockBadge } from './WidgetSourceLockBadge';const PANEL_SIZE_STEP_PX = 16;-/** `sizePx` is the floored size the panel renders at; the flag survives the flooring. */+/** `sizePx` is the floored tracked size; `isSnappedShut` survives the flooring. */interface PanelResizeDrag {- isCollapseOvershoot: boolean;+ isSnappedShut: boolean;sizePx: number;}@@ -70,7 +70,10 @@ export const WidgetPanelFrame = ({// Clamped at render, not just on commit, so a persisted size from before a// bounds change heals on screen immediately instead of on the next resize.const displaySizePx = clampPanelSize(region, drag?.sizePx ?? regionState.sizePx);- const isCollapseArmed = drag?.isCollapseOvershoot ?? false;+ // Mid-drag past the threshold the panel snaps shut on screen, dockview-style;+ // the store's collapse is only committed on release.+ const isSnappedShut = drag?.isSnappedShut ?? false;+ const renderSizePx = isSnappedShut ? 0 : displaySizePx;const { max: maxPanelSizePx, min: minPanelSizePx } = getPanelSizeBounds(region);const focusRegionProps = useFocusRegionProps(region);@@ -97,7 +100,7 @@ export const WidgetPanelFrame = ({pointerSessionRef.current = pointerSession;- let nextDrag: PanelResizeDrag = { isCollapseOvershoot: false, sizePx: clampPanelSize(region, startSizePx) };+ let nextDrag: PanelResizeDrag = { isSnappedShut: false, sizePx: clampPanelSize(region, startSizePx) };// Keeps the gesture alive when the pointer leaves the window, which is// where it goes when dragging the bottom strip shut. Throws if the@@ -112,10 +115,8 @@ export const WidgetPanelFrame = ({const deltaPx = isBottom ? startY - moveEvent.clientY : (moveEvent.clientX - startX) * direction;const rawSizePx = startSizePx + deltaPx;- // Derived from the live position, never latched, so dragging back- // inside the floor disarms the collapse.nextDrag = {- isCollapseOvershoot: isPanelCollapseOvershoot(region, rawSizePx),+ isSnappedShut: shouldSnapPanelShut(region, rawSizePx, nextDrag.isSnappedShut),sizePx: clampPanelSize(region, rawSizePx),};setDrag(nextDrag);@@ -125,7 +126,7 @@ export const WidgetPanelFrame = ({pointerSession.abort();setDrag(null);- if (nextDrag.isCollapseOvershoot) {+ if (nextDrag.isSnappedShut) {// Visibility change, not a resize — `sizePx` keeps the width the user// chose so the rail button reopens the panel where they left it.layout.setRegionCollapsed(region, true);@@ -178,8 +179,8 @@ export const WidgetPanelFrame = ({[commitSize, displaySizePx, isBottom, isLeft, maxPanelSizePx, minPanelSizePx]);const panelSizeProps = useMemo(- () => (isBottom ? { h: `${displaySizePx}px`, w: 'full' } : { h: 'full', w: `${displaySizePx}px` }),- [displaySizePx, isBottom]+ () => (isBottom ? { h: `${renderSizePx}px`, w: 'full' } : { h: 'full', w: `${renderSizePx}px` }),+ [renderSizePx, isBottom]);// Inside the panel's box, never straddling its edge: the frame clips its// overflow, so a handle hung outside loses that half and leaves a ~4px@@ -199,9 +200,9 @@ export const WidgetPanelFrame = ({as="aside"bg="bg.subtle"borderColor="border.subtle"- borderRightWidth={isLeft ? '1px' : '0'}- borderLeftWidth={!isLeft && !isBottom ? '1px' : '0'}- borderTopWidth={isBottom ? '1px' : '0'}+ borderRightWidth={isLeft && !isSnappedShut ? '1px' : '0'}+ borderLeftWidth={!isLeft && !isBottom && !isSnappedShut ? '1px' : '0'}+ borderTopWidth={isBottom && !isSnappedShut ? '1px' : '0'}direction="column"flexShrink={0}overflow="hidden"@@ -224,10 +225,8 @@ export const WidgetPanelFrame = ({position="absolute"role="separator"tabIndex={0}- // Hover is lost the moment the drag starts, so the armed state paints itself.- bg={isCollapseArmed ? 'accent.solid' : undefined}- data-collapse-armed={isCollapseArmed ? '' : undefined}- opacity={isCollapseArmed ? '1' : '0'}+ data-collapse-armed={isSnappedShut ? '' : undefined}+ opacity="0"transition="opacity var(--wb-motion-duration-fast) ease, background var(--wb-motion-duration-fast) ease"zIndex="1"{...resizeOrientationProps}diff --git a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetPanelFrame.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetPanelFrame.browser.test.tsxindex ee2610c6ab..b003bfaf15 100644--- a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetPanelFrame.browser.test.tsx+++ b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetPanelFrame.browser.test.tsx@@ -131,7 +131,7 @@ describe('WidgetPanelFrame resize', () => {expect(frameMocks.setRegionSize).not.toHaveBeenCalled();});- it('disarms when the drag comes back inside the floor', async () => {+ it('reopens when the drag comes back inside the floor', async () => {const separator = await renderFrame();await interact(() => separator.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, clientX: 0 })));@@ -170,7 +170,7 @@ describe('WidgetPanelFrame resize', () => {expect(handle.bottom).toBeLessThanOrEqual(panel.bottom);});- it('holds the panel at the floor while the drag keeps going', async () => {+ it('holds at the floor, then snaps shut on screen at the threshold', async () => {const separator = await renderFrame();// Chakra emits the width as a class rather than an inline style.const panelWidth = () => getComputedStyle(separator.parentElement!).width;@@ -180,7 +180,7 @@ describe('WidgetPanelFrame resize', () => {expect(separator.hasAttribute('data-collapse-armed')).toBe(false);await interact(() => window.dispatchEvent(new PointerEvent('pointermove', { clientX: -400 })));- expect(panelWidth()).toBe('350px');+ expect(panelWidth()).toBe('0px');expect(separator.hasAttribute('data-collapse-armed')).toBe(true);});diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.test.tsindex 8cec3ebe2c..be16fc3c23 100644--- a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts@@ -28,8 +28,8 @@ import {clampPanelSize,getPanelCollapseThreshold,GRAPH_HISTORY_BYTE_BUDGET,- isPanelCollapseOvershoot,normalizeGraphHistory,+ shouldSnapPanelShut,normalizeWorkbenchAccount,} from './workbenchState';import {@@ -674,16 +674,19 @@ describe('workbench panel resize bounds', () => {expect(clampPanelSize('left', 100)).toBe(350);});- it('arms collapse only once a drag clears the floor by the overshoot', () => {- expect(isPanelCollapseOvershoot('left', 350)).toBe(false);- expect(isPanelCollapseOvershoot('left', 271)).toBe(false);- expect(isPanelCollapseOvershoot('left', 270)).toBe(true);+ it('snaps shut past the overshoot and reopens with hysteresis', () => {+ expect(shouldSnapPanelShut('left', 350, false)).toBe(false);+ expect(shouldSnapPanelShut('left', 271, false)).toBe(false);+ expect(shouldSnapPanelShut('left', 270, false)).toBe(true);+ // Once shut, dragging back only reopens past the halfway band.+ expect(shouldSnapPanelShut('left', 290, true)).toBe(true);+ expect(shouldSnapPanelShut('left', 311, true)).toBe(false);});it('measures the overshoot against whichever floor the region has', () => {- expect(isPanelCollapseOvershoot('bottom', 96)).toBe(false);- expect(isPanelCollapseOvershoot('bottom', 17)).toBe(false);- expect(isPanelCollapseOvershoot('bottom', 16)).toBe(true);+ expect(shouldSnapPanelShut('bottom', 96, false)).toBe(false);+ expect(shouldSnapPanelShut('bottom', 17, false)).toBe(false);+ expect(shouldSnapPanelShut('bottom', 16, false)).toBe(true);});it('exposes the collapse threshold as a size below the floor', () => {diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.tsindex d8095f047a..2a3c9b9180 100644--- a/invokeai/frontend/webv2/src/workbench/workbenchState.ts+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.ts@@ -427,13 +427,17 @@ export const getPanelSizeBounds = (region: WidgetRegion): { max: number; min: nureturn { max: MAX_PANEL_SIZE_PX, min: MIN_PANEL_SIZE_PX };};-/** The size at or below which releasing a resize drag collapses the region. */+/** The size at or below which a resize drag snaps the region shut. */export const getPanelCollapseThreshold = (region: WidgetRegion): number =>getPanelSizeBounds(region).min - PANEL_COLLAPSE_OVERSHOOT_PX;-/** True once a drag has pushed past the floor far enough that releasing collapses. */-export const isPanelCollapseOvershoot = (region: WidgetRegion, sizePx: number): boolean =>- sizePx <= getPanelCollapseThreshold(region);+/**+ * Whether a live drag should have the panel snapped shut, dockview-style: it+ * snaps at the overshoot threshold and reopens halfway back, so the boundary+ * has hysteresis instead of flapping a whole panel on one pixel.+ */+export const shouldSnapPanelShut = (region: WidgetRegion, rawSizePx: number, isSnapped: boolean): boolean =>+ rawSizePx <= getPanelCollapseThreshold(region) + (isSnapped ? PANEL_COLLAPSE_OVERSHOOT_PX / 2 : 0);const now = (): string => new Date().toISOString();