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(webv2): let side panels yield to a narrow viewport instead of the center
Lincoln Steinac81dbb29d2d
diff --git a/invokeai/frontend/webv2/src/workbench/shell/CenterArea.tsx b/invokeai/frontend/webv2/src/workbench/shell/CenterArea.tsxindex 8261e5a64b..bd7b221e8d 100644--- a/invokeai/frontend/webv2/src/workbench/shell/CenterArea.tsx+++ b/invokeai/frontend/webv2/src/workbench/shell/CenterArea.tsx@@ -45,6 +45,10 @@ const CENTER_MENU_POSITIONING = { placement: 'bottom-start' } as const;const CENTER_PREFERRED_REGIONS = ['center'] as const;const CENTER_CHROME_INSET_STYLE = { '--wb-center-chrome-inset': '3rem' } as React.CSSProperties;+// The work surface's floor. Side panels shrink to honour it (see+// `WidgetPanelFrame`), so on a portrait tablet the center stays usable instead+// of collapsing to nothing between two fixed-width panels.+const CENTER_MIN_WIDTH = '20rem';export const CenterArea = () => {const { t } = useTranslation();@@ -150,7 +154,7 @@ export const CenterArea = () => {direction="column"flex="1"minH="0"- minW="0"+ minW={CENTER_MIN_WIDTH}style={CENTER_CHROME_INSET_STYLE}{...focusRegionProps}>diff --git a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetFrames.tsx b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetFrames.tsxindex d227060242..9f6052366c 100644--- a/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetFrames.tsx+++ b/invokeai/frontend/webv2/src/workbench/widget-frame/WidgetFrames.tsx@@ -20,11 +20,17 @@ import { resolveWidgetInstanceLabel } from '@workbench/widgetLabels';import { getEnabledCenterViewCount } from '@workbench/widgetPlacementCommands';import { areWidgetPlacementProjectsEqual, getWidgetPlacementProject } from '@workbench/widgetPlacementMeta';import { useActiveProjectSelector, useWorkbenchCommands } from '@workbench/WorkbenchContext';-import { clampPanelSize, getPanelSizeBounds, shouldSnapPanelShut } from '@workbench/workbenchState';+import {+ clampPanelSize,+ getPanelSizeBounds,+ getVisiblePanelCollapseThreshold,+ shouldSnapPanelShutAt,+} from '@workbench/workbenchState';import { useWorkbenchWidgetRegistry } from '@workbench/WorkbenchWidgetRegistryContext';import { PictureInPicture2Icon, SettingsIcon } from 'lucide-react';import {useCallback,+ useEffect,useMemo,useRef,useState,@@ -78,6 +84,28 @@ export const WidgetPanelFrame = ({// the store's collapse is only committed on release.const isSnappedShut = drag?.isSnappedShut ?? false;const renderSizePx = isSnappedShut ? 0 : displaySizePx;+ // Side panels yield to a viewport that cannot hold them (see+ // `panelSizeProps`), so the width on screen can sit below the stored one.+ // The gesture, the keyboard floor and the separator's announced value all+ // work from what is on screen; the store keeps the preferred size.+ const frameRef = useRef<HTMLDivElement | null>(null);+ const [measuredSizePx, setMeasuredSizePx] = useState<number | null>(null);++ useEffect(() => {+ const frame = frameRef.current;++ if (isBottom || !frame || typeof ResizeObserver === 'undefined') {+ return;+ }++ const observer = new ResizeObserver(() => setMeasuredSizePx(Math.round(frame.getBoundingClientRect().width)));++ observer.observe(frame);++ return () => observer.disconnect();+ }, [isBottom]);+ const visibleSizePx =+ isSnappedShut || measuredSizePx === null ? displaySizePx : Math.min(measuredSizePx, displaySizePx);const { max: maxPanelSizePx, min: minPanelSizePx } = getPanelSizeBounds(region);const focusRegionProps = useFocusRegionProps(region);@@ -99,6 +127,9 @@ export const WidgetPanelFrame = ({const startX = event.clientX;const startY = event.clientY;const startSizePx = regionState.sizePx;+ // How far the viewport has squeezed the panel below its stored size.+ const squeezePx = clampPanelSize(region, startSizePx) - visibleSizePx;+ const collapseThresholdPx = getVisiblePanelCollapseThreshold(region, visibleSizePx);const direction = isLeft ? 1 : -1;const pointerSession = new AbortController();@@ -120,7 +151,7 @@ export const WidgetPanelFrame = ({const rawSizePx = startSizePx + deltaPx;nextDrag = {- isSnappedShut: shouldSnapPanelShut(region, rawSizePx, nextDrag.isSnappedShut),+ isSnappedShut: shouldSnapPanelShutAt(collapseThresholdPx, rawSizePx - squeezePx, nextDrag.isSnappedShut),sizePx: clampPanelSize(region, rawSizePx),};setDrag(nextDrag);@@ -152,7 +183,7 @@ export const WidgetPanelFrame = ({window.addEventListener('pointerup', handlePointerUp, { signal: pointerSession.signal });window.addEventListener('pointercancel', handlePointerCancel, { signal: pointerSession.signal });},- [commitSize, isBottom, isLeft, layout, region, regionState.sizePx]+ [commitSize, isBottom, isLeft, layout, region, regionState.sizePx, visibleSizePx]);const handleKeyDown = useCallback(@@ -180,8 +211,9 @@ export const WidgetPanelFrame = ({event.preventDefault();// Keyboard parity with the drag: a further collapse-ward step at the- // floor collapses, instead of silently clamping forever.- if (sizeChange < 0 && displaySizePx <= minPanelSizePx) {+ // floor collapses, instead of silently clamping forever. A squeezed+ // panel is already below the floor on screen, so it collapses too.+ if (sizeChange < 0 && visibleSizePx <= minPanelSizePx) {layout.setRegionCollapsed(region, true);return;@@ -189,10 +221,18 @@ export const WidgetPanelFrame = ({commitSize(displaySizePx + sizeChange);},- [commitSize, displaySizePx, isBottom, isLeft, layout, maxPanelSizePx, minPanelSizePx, region]+ [commitSize, displaySizePx, isBottom, isLeft, layout, maxPanelSizePx, minPanelSizePx, region, visibleSizePx]);+ // The stored size is a preference, not a guarantee: side panels yield+ // (`flexShrink`) when the viewport cannot hold both of them plus the+ // center's minimum — a portrait tablet — so the center never collapses and+ // the opposite rail never gets pushed offscreen. The bottom panel keeps a+ // hard height because the column has no minimum-width peer to protect.const panelSizeProps = useMemo(- () => (isBottom ? { h: `${renderSizePx}px`, w: 'full' } : { h: 'full', w: `${renderSizePx}px` }),+ () =>+ isBottom+ ? { flexShrink: 0, h: `${renderSizePx}px`, w: 'full' }+ : { flexShrink: 1, h: 'full', w: `${renderSizePx}px` },[renderSizePx, isBottom]);// Inside the panel's box, never straddling its edge: the frame clips its@@ -217,9 +257,9 @@ export const WidgetPanelFrame = ({borderLeftWidth={!isLeft && !isBottom && !isSnappedShut ? '1px' : '0'}borderTopWidth={isBottom && !isSnappedShut ? '1px' : '0'}direction="column"- flexShrink={0}overflow="hidden"minW="0"+ ref={frameRef}data-hotkey-widget-instance-id={instanceId}data-hotkey-widget-region={region}data-hotkey-widget-type-id={typeId}@@ -231,8 +271,8 @@ export const WidgetPanelFrame = ({aria-label={`Resize ${region} widget panel`}aria-orientation={isBottom ? 'horizontal' : 'vertical'}aria-valuemax={maxPanelSizePx}- aria-valuemin={minPanelSizePx}- aria-valuenow={displaySizePx}+ aria-valuemin={Math.min(minPanelSizePx, visibleSizePx)}+ aria-valuenow={visibleSizePx}as="div"cursor={isBottom ? 'ns-resize' : 'ew-resize'}position="absolute"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 91ee80c341..4c38015f60 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@@ -254,3 +254,74 @@ describe('WidgetPanelFrame resize', () => {expect(frameMocks.setRegionSize).toHaveBeenCalledExactlyOnceWith('bottom', 96);});});++// A viewport too narrow for the stored size (a portrait tablet) squeezes the+// side panel below its floor on screen. The gesture, the keyboard floor and+// the announced value then work from the width that is actually there.+describe('WidgetPanelFrame squeezed by the viewport', () => {+ const renderSqueezed = async () => {+ host!.style.cssText = 'display:flex;height:600px;width:400px;';+ await interact(() =>+ root?.render(+ <I18nextProvider i18n={i18n}>+ <ChakraProvider value={system}>+ <FocusRegionProvider>+ <WidgetPanelFrame instanceId="test-instance" region="left" typeId="gallery">+ <div />+ </WidgetPanelFrame>+ <div style={{ flex: 1, minWidth: '200px' }} />+ </FocusRegionProvider>+ </ChakraProvider>+ </I18nextProvider>+ )+ );+ // The frame learns its on-screen width from a ResizeObserver, which+ // reports after layout.+ await interact(() => {});+ await act(+ () =>+ new Promise<void>((resolve) => {+ requestAnimationFrame(() => resolve());+ })+ );++ const separator = host?.querySelector('[role="separator"]');++ if (!separator) {+ throw new Error('panel frame did not render a resize handle');+ }++ return separator;+ };++ it('yields to a rigid sibling instead of pushing it out of the row', async () => {+ const separator = await renderSqueezed();++ expect(separator.parentElement!.getBoundingClientRect().width).toBe(200);+ expect(separator.getAttribute('aria-valuenow')).toBe('200');+ expect(separator.getAttribute('aria-valuemin')).toBe('200');+ });++ it('snaps shut after the overshoot from the width on screen, not from the floor', async () => {+ const separator = await renderSqueezed();++ await interact(() => separator.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, clientX: 0 })));+ await interact(() => window.dispatchEvent(new PointerEvent('pointermove', { clientX: -79 })));+ expect(separator.hasAttribute('data-collapse-armed')).toBe(false);++ await interact(() => window.dispatchEvent(new PointerEvent('pointermove', { clientX: -80 })));+ expect(separator.hasAttribute('data-collapse-armed')).toBe(true);++ await interact(() => window.dispatchEvent(new PointerEvent('pointerup', { clientX: -80 })));+ expect(frameMocks.setRegionCollapsed).toHaveBeenCalledExactlyOnceWith('left', true);+ expect(frameMocks.setRegionSize).not.toHaveBeenCalled();+ });++ it('collapses on a collapse-ward key press, being already below the floor', async () => {+ const separator = await renderSqueezed();++ await interact(() => separator.dispatchEvent(new KeyboardEvent('keydown', { bubbles: true, key: 'ArrowLeft' })));++ expect(frameMocks.setRegionCollapsed).toHaveBeenCalledExactlyOnceWith('left', true);+ });+});diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.tsindex f057d2b294..164010d5e5 100644--- a/invokeai/frontend/webv2/src/workbench/workbenchState.ts+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.ts@@ -461,7 +461,20 @@ export const getPanelCollapseThreshold = (region: WidgetRegion): number =>* 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);+ shouldSnapPanelShutAt(getPanelCollapseThreshold(region), rawSizePx, isSnapped);++/**+ * `shouldSnapPanelShut` against an explicit threshold, for a panel the+ * viewport has squeezed below its floor: the overshoot is then measured from+ * the width actually on screen, so a drag on a 213px panel collapses it after+ * 80px instead of demanding the pointer travel to where the floor would be.+ */+export const shouldSnapPanelShutAt = (thresholdPx: number, rawSizePx: number, isSnapped: boolean): boolean =>+ rawSizePx <= thresholdPx + (isSnapped ? PANEL_COLLAPSE_OVERSHOOT_PX / 2 : 0);++/** The collapse threshold for a panel currently rendered at `visibleSizePx`. */+export const getVisiblePanelCollapseThreshold = (region: WidgetRegion, visibleSizePx: number): number =>+ Math.min(getPanelCollapseThreshold(region), visibleSizePx - PANEL_COLLAPSE_OVERSHOOT_PX);const now = (): string => new Date().toISOString();