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(canvas): tool-strip flyouts for shape and select families

Josh Corbett9e881b4dc042
diff --git a/invokeai/frontend/webv2/performance/browser-baseline.json b/invokeai/frontend/webv2/performance/browser-baseline.json
index 38fc80756e..23946f7337 100644
--- a/invokeai/frontend/webv2/performance/browser-baseline.json
+++ b/invokeai/frontend/webv2/performance/browser-baseline.json
@@ -25,12 +25,12 @@
"scriptRequestCount": 0,
"totalRawBytes": 0
},
- "domContentLoadedMedianMs": 127.19999998807907,
+ "domContentLoadedMedianMs": 122.59999999403954,
"id": "launchpad",
"layoutAckMedianMs": 0,
"layoutReturnSwitchMedianMs": 0,
"layoutSwitchMedianMs": 0,
- "loadMedianMs": 127.3999999910593,
+ "loadMedianMs": 122.7999999821186,
"longestTaskMaxMs": 76,
"owner": "app",
"projectSwitchMedianMs": 0,
@@ -43,9 +43,9 @@
"largestAssetRawBytes": 746400,
"otherRawBytes": 162626,
"requestCount": 38,
- "scriptRawBytes": 1636642,
+ "scriptRawBytes": 1636776,
"scriptRequestCount": 34,
- "totalRawBytes": 1825091
+ "totalRawBytes": 1825225
},
"resourceLimits": {
"cssRawBytes": 2181,
@@ -54,11 +54,11 @@
"largestAssetRawBytes": 753864,
"otherRawBytes": 164253,
"requestCount": 38,
- "scriptRawBytes": 1653009,
+ "scriptRawBytes": 1653144,
"scriptRequestCount": 34,
- "totalRawBytes": 1843342
+ "totalRawBytes": 1843478
},
- "routeReadyMedianMs": 284.3999999910593,
+ "routeReadyMedianMs": 269.69999998807907,
"scriptSourceOwnerSet": "launchpad-static",
"stateProfile": "empty"
},
@@ -85,13 +85,13 @@
"scriptRequestCount": 0,
"totalRawBytes": 0
},
- "domContentLoadedMedianMs": 123.3999999910593,
+ "domContentLoadedMedianMs": 136.7000000178814,
"id": "launchpad",
"layoutAckMedianMs": 0,
"layoutReturnSwitchMedianMs": 0,
"layoutSwitchMedianMs": 0,
- "loadMedianMs": 123.59999999403954,
- "longestTaskMaxMs": 73,
+ "loadMedianMs": 136.80000001192093,
+ "longestTaskMaxMs": 83,
"owner": "app",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:launchpad",
@@ -103,9 +103,9 @@
"largestAssetRawBytes": 746400,
"otherRawBytes": 162626,
"requestCount": 38,
- "scriptRawBytes": 1636642,
+ "scriptRawBytes": 1636776,
"scriptRequestCount": 34,
- "totalRawBytes": 1825091
+ "totalRawBytes": 1825225
},
"resourceLimits": {
"cssRawBytes": 2181,
@@ -114,11 +114,11 @@
"largestAssetRawBytes": 753864,
"otherRawBytes": 164253,
"requestCount": 38,
- "scriptRawBytes": 1653009,
+ "scriptRawBytes": 1653144,
"scriptRequestCount": 34,
- "totalRawBytes": 1843342
+ "totalRawBytes": 1843478
},
- "routeReadyMedianMs": 297.5,
+ "routeReadyMedianMs": 326,
"scriptSourceOwnerSet": "launchpad-static",
"stateProfile": "representative"
},
@@ -145,15 +145,15 @@
"scriptRequestCount": 0,
"totalRawBytes": 0
},
- "domContentLoadedMedianMs": 128.40000000596046,
+ "domContentLoadedMedianMs": 134.2000000178814,
"id": "editor-minimal",
"layoutAckMedianMs": 0,
"layoutReturnSwitchMedianMs": 0,
"layoutSwitchMedianMs": 0,
- "loadMedianMs": 128.5,
- "longestTaskMaxMs": 115,
+ "loadMedianMs": 134.40000000596046,
+ "longestTaskMaxMs": 114,
"owner": "workbench",
- "projectSwitchMedianMs": 44.5,
+ "projectSwitchMedianMs": 44.900000005960464,
"readyMark": "invokeai:ready:widget:center:preview",
"remediationTicket": "deepen-widget-registry-loading",
"resourceBaseline": {
@@ -163,9 +163,9 @@
"largestAssetRawBytes": 746400,
"otherRawBytes": 162626,
"requestCount": 115,
- "scriptRawBytes": 3287820,
+ "scriptRawBytes": 3288069,
"scriptRequestCount": 110,
- "totalRawBytes": 3632645
+ "totalRawBytes": 3632894
},
"resourceLimits": {
"cssRawBytes": 2181,
@@ -174,11 +174,11 @@
"largestAssetRawBytes": 753864,
"otherRawBytes": 164253,
"requestCount": 115,
- "scriptRawBytes": 3320699,
+ "scriptRawBytes": 3320950,
"scriptRequestCount": 110,
- "totalRawBytes": 3668972
+ "totalRawBytes": 3669223
},
- "routeReadyMedianMs": 709.7000000029802,
+ "routeReadyMedianMs": 724.6999999880791,
"scriptSourceOwnerSet": "editor-minimal-static",
"stateProfile": "empty"
},
@@ -205,15 +205,15 @@
"scriptRequestCount": 0,
"totalRawBytes": 0
},
- "domContentLoadedMedianMs": 123.79999999701977,
+ "domContentLoadedMedianMs": 128.30000001192093,
"id": "editor-minimal",
"layoutAckMedianMs": 0,
"layoutReturnSwitchMedianMs": 0,
"layoutSwitchMedianMs": 0,
- "loadMedianMs": 123.8999999910593,
- "longestTaskMaxMs": 210,
+ "loadMedianMs": 128.5,
+ "longestTaskMaxMs": 225,
"owner": "workbench",
- "projectSwitchMedianMs": 78.79999999701977,
+ "projectSwitchMedianMs": 86.09999999403954,
"readyMark": "invokeai:ready:widget:center:preview",
"remediationTicket": "deepen-widget-registry-loading",
"resourceBaseline": {
@@ -223,9 +223,9 @@
"largestAssetRawBytes": 746400,
"otherRawBytes": 162626,
"requestCount": 115,
- "scriptRawBytes": 3287820,
+ "scriptRawBytes": 3288069,
"scriptRequestCount": 110,
- "totalRawBytes": 3632645
+ "totalRawBytes": 3632894
},
"resourceLimits": {
"cssRawBytes": 2181,
@@ -234,11 +234,11 @@
"largestAssetRawBytes": 753864,
"otherRawBytes": 164253,
"requestCount": 115,
- "scriptRawBytes": 3320699,
+ "scriptRawBytes": 3320950,
"scriptRequestCount": 110,
- "totalRawBytes": 3668972
+ "totalRawBytes": 3669223
},
- "routeReadyMedianMs": 460.09999999403954,
+ "routeReadyMedianMs": 508.09999999403954,
"scriptSourceOwnerSet": "editor-minimal-static",
"stateProfile": "representative"
},
@@ -247,31 +247,31 @@
"cssRawBytes": 0,
"fontRawBytes": 0,
"imageRawBytes": 0,
- "largestAssetRawBytes": 315016,
+ "largestAssetRawBytes": 314995,
"otherRawBytes": 0,
"requestCount": 7,
- "scriptRawBytes": 474650,
+ "scriptRawBytes": 482406,
"scriptRequestCount": 7,
- "totalRawBytes": 474650
+ "totalRawBytes": 482406
},
"activatedResourceLimits": {
"cssRawBytes": 0,
"fontRawBytes": 0,
"imageRawBytes": 0,
- "largestAssetRawBytes": 318167,
+ "largestAssetRawBytes": 318145,
"otherRawBytes": 0,
"requestCount": 7,
- "scriptRawBytes": 479397,
+ "scriptRawBytes": 487231,
"scriptRequestCount": 7,
- "totalRawBytes": 479397
+ "totalRawBytes": 487231
},
- "domContentLoadedMedianMs": 119.40000000596046,
+ "domContentLoadedMedianMs": 135.10000002384186,
"id": "editor-canvas",
- "layoutAckMedianMs": 2.7999999970197678,
- "layoutReturnSwitchMedianMs": 59.29999999701977,
- "layoutSwitchMedianMs": 93.59999999403954,
- "loadMedianMs": 119.5,
- "longestTaskMaxMs": 139,
+ "layoutAckMedianMs": 3.4000000059604645,
+ "layoutReturnSwitchMedianMs": 64.09999999403954,
+ "layoutSwitchMedianMs": 98,
+ "loadMedianMs": 135.2000000178814,
+ "longestTaskMaxMs": 158,
"owner": "canvas",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:canvas",
@@ -283,9 +283,9 @@
"largestAssetRawBytes": 746400,
"otherRawBytes": 162626,
"requestCount": 122,
- "scriptRawBytes": 3762470,
+ "scriptRawBytes": 3770475,
"scriptRequestCount": 117,
- "totalRawBytes": 4107295
+ "totalRawBytes": 4115300
},
"resourceLimits": {
"cssRawBytes": 2181,
@@ -294,11 +294,11 @@
"largestAssetRawBytes": 753864,
"otherRawBytes": 164253,
"requestCount": 122,
- "scriptRawBytes": 3800095,
+ "scriptRawBytes": 3808180,
"scriptRequestCount": 117,
- "totalRawBytes": 4148368
+ "totalRawBytes": 4156453
},
- "routeReadyMedianMs": 1060.7000000029802,
+ "routeReadyMedianMs": 1118.699999988079,
"scriptSourceOwnerSet": "editor-canvas-static",
"stateProfile": "empty"
},
@@ -307,31 +307,31 @@
"cssRawBytes": 0,
"fontRawBytes": 0,
"imageRawBytes": 0,
- "largestAssetRawBytes": 315016,
+ "largestAssetRawBytes": 314995,
"otherRawBytes": 0,
"requestCount": 7,
- "scriptRawBytes": 474650,
+ "scriptRawBytes": 482406,
"scriptRequestCount": 7,
- "totalRawBytes": 474650
+ "totalRawBytes": 482406
},
"activatedResourceLimits": {
"cssRawBytes": 0,
"fontRawBytes": 0,
"imageRawBytes": 0,
- "largestAssetRawBytes": 318167,
+ "largestAssetRawBytes": 318145,
"otherRawBytes": 0,
"requestCount": 7,
- "scriptRawBytes": 479397,
+ "scriptRawBytes": 487231,
"scriptRequestCount": 7,
- "totalRawBytes": 479397
+ "totalRawBytes": 487231
},
- "domContentLoadedMedianMs": 130.09999999403954,
+ "domContentLoadedMedianMs": 133.5,
"id": "editor-canvas",
- "layoutAckMedianMs": 3.2000000029802322,
- "layoutReturnSwitchMedianMs": 51.29999999701977,
- "layoutSwitchMedianMs": 98.40000000596046,
- "loadMedianMs": 130.19999998807907,
- "longestTaskMaxMs": 212,
+ "layoutAckMedianMs": 3,
+ "layoutReturnSwitchMedianMs": 49.900000005960464,
+ "layoutSwitchMedianMs": 101.2000000178814,
+ "loadMedianMs": 133.59999999403954,
+ "longestTaskMaxMs": 229,
"owner": "canvas",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:canvas",
@@ -343,9 +343,9 @@
"largestAssetRawBytes": 746400,
"otherRawBytes": 162626,
"requestCount": 122,
- "scriptRawBytes": 3762470,
+ "scriptRawBytes": 3770475,
"scriptRequestCount": 117,
- "totalRawBytes": 4107295
+ "totalRawBytes": 4115300
},
"resourceLimits": {
"cssRawBytes": 2181,
@@ -354,11 +354,11 @@
"largestAssetRawBytes": 753864,
"otherRawBytes": 164253,
"requestCount": 122,
- "scriptRawBytes": 3800095,
+ "scriptRawBytes": 3808180,
"scriptRequestCount": 117,
- "totalRawBytes": 4148368
+ "totalRawBytes": 4156453
},
- "routeReadyMedianMs": 1260,
+ "routeReadyMedianMs": 1314.300000011921,
"scriptSourceOwnerSet": "editor-canvas-static",
"stateProfile": "representative"
},
@@ -370,9 +370,9 @@
"largestAssetRawBytes": 173980,
"otherRawBytes": 0,
"requestCount": 7,
- "scriptRawBytes": 364221,
+ "scriptRawBytes": 364235,
"scriptRequestCount": 6,
- "totalRawBytes": 379634
+ "totalRawBytes": 379648
},
"activatedResourceLimits": {
"cssRawBytes": 15568,
@@ -381,17 +381,17 @@
"largestAssetRawBytes": 175720,
"otherRawBytes": 0,
"requestCount": 7,
- "scriptRawBytes": 367864,
+ "scriptRawBytes": 367878,
"scriptRequestCount": 6,
- "totalRawBytes": 383431
+ "totalRawBytes": 383445
},
- "domContentLoadedMedianMs": 126.79999999701977,
+ "domContentLoadedMedianMs": 133.40000000596046,
"id": "editor-workflow",
- "layoutAckMedianMs": 3.2999999970197678,
- "layoutReturnSwitchMedianMs": 34.69999998807907,
- "layoutSwitchMedianMs": 91,
- "loadMedianMs": 127,
- "longestTaskMaxMs": 108,
+ "layoutAckMedianMs": 3.2999999821186066,
+ "layoutReturnSwitchMedianMs": 36.5,
+ "layoutSwitchMedianMs": 91.60000002384186,
+ "loadMedianMs": 133.5,
+ "longestTaskMaxMs": 126,
"owner": "workflow",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:workflow",
@@ -403,9 +403,9 @@
"largestAssetRawBytes": 746400,
"otherRawBytes": 162626,
"requestCount": 122,
- "scriptRawBytes": 3652041,
+ "scriptRawBytes": 3652304,
"scriptRequestCount": 116,
- "totalRawBytes": 4012279
+ "totalRawBytes": 4012542
},
"resourceLimits": {
"cssRawBytes": 17748,
@@ -414,11 +414,11 @@
"largestAssetRawBytes": 753864,
"otherRawBytes": 164253,
"requestCount": 122,
- "scriptRawBytes": 3688562,
+ "scriptRawBytes": 3688828,
"scriptRequestCount": 116,
- "totalRawBytes": 4052402
+ "totalRawBytes": 4052668
},
- "routeReadyMedianMs": 1085.5999999940395,
+ "routeReadyMedianMs": 1111.5,
"scriptSourceOwnerSet": "editor-workflow-static",
"stateProfile": "empty"
},
@@ -430,9 +430,9 @@
"largestAssetRawBytes": 173980,
"otherRawBytes": 0,
"requestCount": 7,
- "scriptRawBytes": 364221,
+ "scriptRawBytes": 364235,
"scriptRequestCount": 6,
- "totalRawBytes": 379634
+ "totalRawBytes": 379648
},
"activatedResourceLimits": {
"cssRawBytes": 15568,
@@ -441,17 +441,17 @@
"largestAssetRawBytes": 175720,
"otherRawBytes": 0,
"requestCount": 7,
- "scriptRawBytes": 367864,
+ "scriptRawBytes": 367878,
"scriptRequestCount": 6,
- "totalRawBytes": 383431
+ "totalRawBytes": 383445
},
- "domContentLoadedMedianMs": 121.29999999701977,
+ "domContentLoadedMedianMs": 131.30000001192093,
"id": "editor-workflow",
- "layoutAckMedianMs": 3.2999999970197678,
- "layoutReturnSwitchMedianMs": 46.5,
- "layoutSwitchMedianMs": 135.1000000089407,
- "loadMedianMs": 121.5,
- "longestTaskMaxMs": 400,
+ "layoutAckMedianMs": 3.2999999821186066,
+ "layoutReturnSwitchMedianMs": 45.19999998807907,
+ "layoutSwitchMedianMs": 145.5,
+ "loadMedianMs": 131.59999999403954,
+ "longestTaskMaxMs": 422,
"owner": "workflow",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:workflow",
@@ -463,9 +463,9 @@
"largestAssetRawBytes": 746400,
"otherRawBytes": 162626,
"requestCount": 122,
- "scriptRawBytes": 3652041,
+ "scriptRawBytes": 3652304,
"scriptRequestCount": 116,
- "totalRawBytes": 4012279
+ "totalRawBytes": 4012542
},
"resourceLimits": {
"cssRawBytes": 17748,
@@ -474,11 +474,11 @@
"largestAssetRawBytes": 753864,
"otherRawBytes": 164253,
"requestCount": 122,
- "scriptRawBytes": 3688562,
+ "scriptRawBytes": 3688828,
"scriptRequestCount": 116,
- "totalRawBytes": 4052402
+ "totalRawBytes": 4052668
},
- "routeReadyMedianMs": 1246,
+ "routeReadyMedianMs": 1370.199999988079,
"scriptSourceOwnerSet": "editor-workflow-static",
"stateProfile": "representative"
},
@@ -505,13 +505,13 @@
"scriptRequestCount": 0,
"totalRawBytes": 0
},
- "domContentLoadedMedianMs": 120.5,
+ "domContentLoadedMedianMs": 118.89999997615814,
"id": "editor-gallery",
"layoutAckMedianMs": 0,
"layoutReturnSwitchMedianMs": 0,
- "layoutSwitchMedianMs": 27.600000008940697,
- "loadMedianMs": 120.69999998807907,
- "longestTaskMaxMs": 103,
+ "layoutSwitchMedianMs": 30,
+ "loadMedianMs": 119,
+ "longestTaskMaxMs": 117,
"owner": "gallery",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:gallery",
@@ -523,9 +523,9 @@
"largestAssetRawBytes": 746400,
"otherRawBytes": 162626,
"requestCount": 115,
- "scriptRawBytes": 3287820,
+ "scriptRawBytes": 3288069,
"scriptRequestCount": 110,
- "totalRawBytes": 3632645
+ "totalRawBytes": 3632894
},
"resourceLimits": {
"cssRawBytes": 2181,
@@ -534,11 +534,11 @@
"largestAssetRawBytes": 753864,
"otherRawBytes": 164253,
"requestCount": 115,
- "scriptRawBytes": 3320699,
+ "scriptRawBytes": 3320950,
"scriptRequestCount": 110,
- "totalRawBytes": 3668972
+ "totalRawBytes": 3669223
},
- "routeReadyMedianMs": 1277.3999999910593,
+ "routeReadyMedianMs": 1280,
"scriptSourceOwnerSet": "editor-minimal-static",
"stateProfile": "empty"
},
@@ -565,13 +565,13 @@
"scriptRequestCount": 0,
"totalRawBytes": 0
},
- "domContentLoadedMedianMs": 120.79999999701977,
+ "domContentLoadedMedianMs": 135.30000001192093,
"id": "editor-gallery",
"layoutAckMedianMs": 0,
"layoutReturnSwitchMedianMs": 0,
- "layoutSwitchMedianMs": 92.20000000298023,
- "loadMedianMs": 121,
- "longestTaskMaxMs": 189,
+ "layoutSwitchMedianMs": 106.7999999821186,
+ "loadMedianMs": 135.40000000596046,
+ "longestTaskMaxMs": 236,
"owner": "gallery",
"projectSwitchMedianMs": 0,
"readyMark": "invokeai:ready:widget:center:gallery",
@@ -583,9 +583,9 @@
"largestAssetRawBytes": 746400,
"otherRawBytes": 162626,
"requestCount": 115,
- "scriptRawBytes": 3287820,
+ "scriptRawBytes": 3288069,
"scriptRequestCount": 110,
- "totalRawBytes": 3632645
+ "totalRawBytes": 3632894
},
"resourceLimits": {
"cssRawBytes": 2181,
@@ -594,11 +594,11 @@
"largestAssetRawBytes": 753864,
"otherRawBytes": 164253,
"requestCount": 115,
- "scriptRawBytes": 3320699,
+ "scriptRawBytes": 3320950,
"scriptRequestCount": 110,
- "totalRawBytes": 3668972
+ "totalRawBytes": 3669223
},
- "routeReadyMedianMs": 1473.7000000029802,
+ "routeReadyMedianMs": 1642.4000000059605,
"scriptSourceOwnerSet": "editor-minimal-static",
"stateProfile": "representative"
}
@@ -2800,6 +2800,7 @@
"source:src/workbench/widgets/canvas/StagingBar.tsx",
"source:src/workbench/widgets/canvas/TextEditPortal.tsx",
"source:src/workbench/widgets/canvas/ToolStrip.tsx",
+ "source:src/workbench/widgets/canvas/ToolStripFlyout.tsx",
"source:src/workbench/widgets/canvas/bboxGrid.ts",
"source:src/workbench/widgets/canvas/canvasClipboard.ts",
"source:src/workbench/widgets/canvas/canvasContextMenu.ts",
@@ -2844,6 +2845,7 @@
"source:src/workbench/widgets/canvas/tool-presentation/PropertyPrimitives.tsx",
"source:src/workbench/widgets/canvas/tool-presentation/propertyGroupStore.ts",
"source:src/workbench/widgets/canvas/tool-presentation/toolAdapters.ts",
+ "source:src/workbench/widgets/canvas/toolFamilyStore.ts",
"source:src/workbench/widgets/canvas/useCanvasEngine.ts",
"source:src/workbench/widgets/canvas/useCanvasGallerySave.ts",
"source:src/workbench/widgets/canvas/useColorSampler.ts",
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/ToolStrip.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widgets/canvas/ToolStrip.browser.test.tsx
new file mode 100644
index 0000000000..3a90db9104
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/ToolStrip.browser.test.tsx
@@ -0,0 +1,245 @@
+import type { ComponentProps } from 'react';
+
+import { ChakraProvider } from '@chakra-ui/react';
+import { system } from '@theme/system';
+import i18n from 'i18next';
+import { act } from 'react';
+import { createRoot, type Root } from 'react-dom/client';
+import { initReactI18next } from 'react-i18next';
+import { afterEach, beforeAll, beforeEach, describe, expect, it } from 'vitest';
+import { page, userEvent } from 'vitest/browser';
+
+import { recordSelectFamilyTool } from './toolFamilyStore';
+import { ToolStrip } from './ToolStrip';
+
+(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
+
+type StripEngine = ComponentProps<typeof ToolStrip>['engine'];
+
+/** A live interaction-store double: real get/set/subscribe so the strip re-renders on changes. */
+const createFakeEngine = () => {
+ const values = new Map<string, unknown>([
+ ['activeTool', 'view'],
+ ['shapeOptions', { fillEnabled: true, kind: 'rect', strokeEnabled: false, strokeWidth: 8 }],
+ ]);
+ const listeners = new Map<string, Set<() => void>>();
+ const interaction = {
+ get: (key: string) => values.get(key),
+ getLayerThumbnailStatus: () => 'idle' as const,
+ getLayerThumbnailVersion: () => 0,
+ set: (key: string, value: unknown) => {
+ values.set(key, value);
+ listeners.get(key)?.forEach((listener) => listener());
+ },
+ subscribe: (key: string, listener: () => void) => {
+ const bucket = listeners.get(key) ?? new Set<() => void>();
+ listeners.set(key, bucket);
+ bucket.add(listener);
+ return () => bucket.delete(listener);
+ },
+ subscribeLayerThumbnailStatus: () => () => {},
+ subscribeLayerThumbnailVersion: () => () => {},
+ };
+ const engine = {
+ interaction,
+ tools: { setTool: (toolId: string) => interaction.set('activeTool', toolId) },
+ };
+ return {
+ engine: engine as unknown as StripEngine,
+ get activeTool() {
+ return values.get('activeTool');
+ },
+ get shapeKind() {
+ return (values.get('shapeOptions') as { kind: string }).kind;
+ },
+ };
+};
+
+const pointerAt = (type: string, x: number, y: number): PointerEvent =>
+ new PointerEvent(type, { bubbles: true, button: 0, clientX: x, clientY: y, pointerId: 1 });
+
+const centre = (element: Element): { x: number; y: number } => {
+ const rect = element.getBoundingClientRect();
+ return { x: rect.left + rect.width / 2, y: rect.top + rect.height / 2 };
+};
+
+const wait = (ms: number) =>
+ new Promise<void>((resolve) => {
+ setTimeout(resolve, ms);
+ });
+
+describe('tool strip family slots', () => {
+ let container: HTMLDivElement | null = null;
+ let root: Root | null = null;
+
+ beforeAll(async () => {
+ const translation = await fetch('/locales/en.json').then((response) => response.json());
+ await i18n.use(initReactI18next).init({
+ fallbackLng: 'en',
+ initAsync: false,
+ interpolation: { escapeValue: false },
+ lng: 'en',
+ resources: { en: { translation } },
+ });
+ });
+
+ beforeEach(() => {
+ recordSelectFamilyTool('marquee');
+ localStorage.removeItem('invokeai:v7:webv2:select-family-tool');
+ });
+
+ afterEach(async () => {
+ await act(() => root?.unmount());
+ container?.remove();
+ container = null;
+ root = null;
+ });
+
+ const renderStrip = async (props: Partial<ComponentProps<typeof ToolStrip>> = {}) => {
+ const fake = createFakeEngine();
+ container = document.createElement('div');
+ document.body.appendChild(container);
+ root = createRoot(container);
+ await act(() => {
+ root?.render(
+ <ChakraProvider value={system}>
+ <ToolStrip engine={fake.engine} {...props} />
+ </ChakraProvider>
+ );
+ });
+ return fake;
+ };
+
+ const button = (name: string) => page.getByRole('button', { name, exact: true });
+
+ it('selects the current subtool on a plain click and shows no flyout', async () => {
+ const fake = await renderStrip();
+ await act(() => userEvent.click(button('Shape')));
+ expect(fake.activeTool).toBe('shape');
+ expect(fake.shapeKind).toBe('rect');
+ expect(document.querySelector('[role="menu"]')).toBeNull();
+ });
+
+ it('opens on hold and selects the entry under the released pointer', async () => {
+ const fake = await renderStrip();
+ const shape = (await button('Shape').element()) as HTMLElement;
+ const at = centre(shape);
+ await act(() => {
+ shape.dispatchEvent(pointerAt('pointerdown', at.x, at.y));
+ });
+ expect(document.querySelector('[role="menu"]')).toBeNull();
+ await act(() => wait(450));
+ expect(document.querySelector('[role="menu"]')).not.toBeNull();
+
+ // Pointer capture routes the release to the button; the coordinates say
+ // which entry it landed on.
+ const triangle = (await page.getByRole('menuitemradio', { name: 'Triangle' }).element()) as HTMLElement;
+ const over = centre(triangle);
+ await act(() => {
+ shape.dispatchEvent(pointerAt('pointerup', over.x, over.y));
+ });
+ expect(fake.shapeKind).toBe('triangle');
+ expect(fake.activeTool).toBe('shape');
+ expect(document.querySelector('[role="menu"]')).toBeNull();
+ });
+
+ it('keeps the flyout open after a hold released on the button, then selects by click', async () => {
+ const fake = await renderStrip();
+ const shape = (await button('Shape').element()) as HTMLElement;
+ const at = centre(shape);
+ await act(() => {
+ shape.dispatchEvent(pointerAt('pointerdown', at.x, at.y));
+ });
+ await act(() => wait(450));
+ await act(() => {
+ shape.dispatchEvent(pointerAt('pointerup', at.x, at.y));
+ });
+ expect(document.querySelector('[role="menu"]')).not.toBeNull();
+ await act(() => userEvent.click(page.getByRole('menuitemradio', { name: 'Star' })));
+ expect(fake.shapeKind).toBe('star');
+ expect(fake.activeTool).toBe('shape');
+ expect(document.querySelector('[role="menu"]')).toBeNull();
+ });
+
+ it('marks the slot current entry checked, follows it on the strip icon, and cycles state via right-click', async () => {
+ const fake = await renderStrip();
+ const shape = (await button('Shape').element()) as HTMLElement;
+ await act(() => {
+ shape.dispatchEvent(new MouseEvent('contextmenu', { bubbles: true, cancelable: true }));
+ });
+ expect(document.querySelector('[role="menu"]')).not.toBeNull();
+ await expect
+ .element(page.getByRole('menuitemradio', { name: 'Rectangle' }))
+ .toHaveAttribute('aria-checked', 'true');
+ await act(() => userEvent.click(page.getByRole('menuitemradio', { name: 'Ellipse' })));
+ expect(fake.shapeKind).toBe('ellipse');
+
+ // The slot now stands for the ellipse: reopen and the check moved with it.
+ await act(() => {
+ shape.dispatchEvent(new MouseEvent('contextmenu', { bubbles: true, cancelable: true }));
+ });
+ await expect.element(page.getByRole('menuitemradio', { name: 'Ellipse' })).toHaveAttribute('aria-checked', 'true');
+ await expect
+ .element(page.getByRole('menuitemradio', { name: 'Rectangle' }))
+ .toHaveAttribute('aria-checked', 'false');
+ });
+
+ it('closes on Escape and returns focus to the slot', async () => {
+ await renderStrip();
+ const shape = (await button('Shape').element()) as HTMLElement;
+ await act(() => {
+ shape.dispatchEvent(new MouseEvent('contextmenu', { bubbles: true, cancelable: true }));
+ });
+ expect(document.querySelector('[role="menu"]')).not.toBeNull();
+ await act(() => userEvent.keyboard('{Escape}'));
+ expect(document.querySelector('[role="menu"]')).toBeNull();
+ expect(document.activeElement).toBe(shape);
+ });
+
+ it('opens from the keyboard with ArrowRight and focuses the first entry', async () => {
+ await renderStrip();
+ const shape = (await button('Shape').element()) as HTMLElement;
+ await act(async () => {
+ shape.focus();
+ await userEvent.keyboard('{ArrowRight}');
+ await wait(50);
+ });
+ expect(document.querySelector('[role="menu"]')).not.toBeNull();
+ expect((document.activeElement as HTMLElement | null)?.dataset.subtoolId).toBe('rect');
+ });
+
+ it('remembers the last-used selection tool across tool switches', async () => {
+ const fake = await renderStrip();
+ await act(() => userEvent.click(button('Marquee select')));
+ expect(fake.activeTool).toBe('marquee');
+
+ const select = (await button('Marquee select').element()) as HTMLElement;
+ await act(() => {
+ select.dispatchEvent(new MouseEvent('contextmenu', { bubbles: true, cancelable: true }));
+ });
+ await act(() => userEvent.click(page.getByRole('menuitemradio', { name: 'Lasso select' })));
+ expect(fake.activeTool).toBe('lasso');
+
+ // Leave the family and come back with a plain click: the slot restores lasso.
+ await act(() => userEvent.click(button('Brush')));
+ expect(fake.activeTool).toBe('brush');
+ await act(() => userEvent.click(button('Lasso select')));
+ expect(fake.activeTool).toBe('lasso');
+ });
+
+ it('disables the family slots under an interaction lock, hold included', async () => {
+ await renderStrip({ isInteractionLocked: true });
+ const shape = (await button('Shape').element()) as HTMLElement;
+ expect((shape as HTMLButtonElement).disabled).toBe(true);
+ const at = centre(shape);
+ await act(() => {
+ shape.dispatchEvent(pointerAt('pointerdown', at.x, at.y));
+ });
+ await act(() => wait(450));
+ expect(document.querySelector('[role="menu"]')).toBeNull();
+ await act(() => {
+ shape.dispatchEvent(new MouseEvent('contextmenu', { bubbles: true, cancelable: true }));
+ });
+ expect(document.querySelector('[role="menu"]')).toBeNull();
+ });
+});
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/ToolStrip.tsx b/invokeai/frontend/webv2/src/workbench/widgets/canvas/ToolStrip.tsx
index 6bbaccdc0b..61ab35205a 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/ToolStrip.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/ToolStrip.tsx
@@ -1,9 +1,15 @@
-import type { CanvasCoreStoreCapability, CanvasToolCapability, ToolId } from '@workbench/canvas-engine/api';
+import type {
+ CanvasCoreStoreCapability,
+ CanvasToolCapability,
+ ParametricShapeKind,
+ ToolId,
+} from '@workbench/canvas-engine/api';
import { Box } from '@chakra-ui/react';
import { Toolbar, ToolbarButton } from '@platform/ui/Toolbar';
import {
BrushIcon,
+ CircleIcon,
EraserIcon,
FrameIcon,
HandIcon,
@@ -11,15 +17,19 @@ import {
MoveIcon,
PaintBucketIcon,
Rotate3dIcon,
- ShapesIcon,
SquareDashedIcon,
+ SquareIcon,
+ StarIcon,
+ TriangleIcon,
TypeIcon,
} from 'lucide-react';
-import { useCallback } from 'react';
+import { useCallback, useEffect, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { isCanvasToolEnabled } from './canvasInteractionLock';
-import { useCanvasActiveTool } from './engineStoreHooks';
+import { useCanvasActiveTool, useShapeOptions } from './engineStoreHooks';
+import { recordSelectFamilyTool, useSelectFamilyTool, type SelectFamilyTool } from './toolFamilyStore';
+import { ToolFamilyButton, type ToolFlyoutItem } from './ToolStripFlyout';
type ToolStripEngine = CanvasCoreStoreCapability & { readonly tools: CanvasToolCapability };
@@ -42,6 +52,109 @@ const ToolStripButton = ({ engine, icon, isInteractionLocked, label, toolId }: T
);
};
+const SHAPE_KIND_ICONS: Record<ParametricShapeKind, React.ElementType> = {
+ ellipse: CircleIcon,
+ rect: SquareIcon,
+ star: StarIcon,
+ triangle: TriangleIcon,
+};
+const SHAPE_KIND_ORDER: readonly ParametricShapeKind[] = ['rect', 'ellipse', 'triangle', 'star'];
+const SHAPE_KIND_LABEL_KEYS: Record<ParametricShapeKind, string> = {
+ ellipse: 'widgets.canvas.toolOptions.shapeEllipse',
+ rect: 'widgets.canvas.toolOptions.shapeRect',
+ star: 'widgets.canvas.toolOptions.shapeStar',
+ triangle: 'widgets.canvas.toolOptions.shapeTriangle',
+};
+
+/** The Shape slot: one tool id, the flyout switching which kind the next drag draws. */
+const ShapeFamilyButton = ({
+ engine,
+ isInteractionLocked,
+}: {
+ engine: ToolStripEngine;
+ isInteractionLocked: boolean;
+}) => {
+ const { t } = useTranslation();
+ const activeTool = useCanvasActiveTool(engine);
+ const options = useShapeOptions(engine);
+ const items: ToolFlyoutItem[] = useMemo(
+ () =>
+ SHAPE_KIND_ORDER.map((kind) => ({
+ icon: SHAPE_KIND_ICONS[kind],
+ id: kind,
+ label: t(SHAPE_KIND_LABEL_KEYS[kind]),
+ })),
+ [t]
+ );
+ const onActivate = useCallback(() => engine.tools.setTool('shape'), [engine]);
+ const onSelectSubtool = useCallback(
+ (id: string) => {
+ engine.interaction.set('shapeOptions', { ...options, kind: id as ParametricShapeKind });
+ engine.tools.setTool('shape');
+ },
+ [engine, options]
+ );
+ return (
+ <ToolFamilyButton
+ currentId={options.kind}
+ disabled={!isCanvasToolEnabled('shape', isInteractionLocked)}
+ icon={SHAPE_KIND_ICONS[options.kind]}
+ isActive={activeTool === 'shape'}
+ items={items}
+ label={t('widgets.canvas.tools.shape')}
+ onActivate={onActivate}
+ onSelectSubtool={onSelectSubtool}
+ />
+ );
+};
+
+/** The Select slot: marquee and lasso as one family; the slot stands for the last one used. */
+const SelectFamilyButton = ({
+ engine,
+ isInteractionLocked,
+}: {
+ engine: ToolStripEngine;
+ isInteractionLocked: boolean;
+}) => {
+ const { t } = useTranslation();
+ const activeTool = useCanvasActiveTool(engine);
+ const stored = useSelectFamilyTool();
+ // A hotkey or programmatic switch into the family also becomes its memory.
+ useEffect(() => {
+ if (activeTool === 'marquee' || activeTool === 'lasso') {
+ recordSelectFamilyTool(activeTool);
+ }
+ }, [activeTool]);
+ const current: SelectFamilyTool = activeTool === 'marquee' || activeTool === 'lasso' ? activeTool : stored;
+ const items: ToolFlyoutItem[] = useMemo(
+ () => [
+ { icon: SquareDashedIcon, id: 'marquee', label: t('widgets.canvas.tools.marquee') },
+ { icon: LassoIcon, id: 'lasso', label: t('widgets.canvas.tools.lasso') },
+ ],
+ [t]
+ );
+ const onActivate = useCallback(() => engine.tools.setTool(current), [current, engine]);
+ const onSelectSubtool = useCallback(
+ (id: string) => {
+ recordSelectFamilyTool(id as SelectFamilyTool);
+ engine.tools.setTool(id as ToolId);
+ },
+ [engine]
+ );
+ return (
+ <ToolFamilyButton
+ currentId={current}
+ disabled={!isCanvasToolEnabled(current, isInteractionLocked)}
+ icon={current === 'lasso' ? LassoIcon : SquareDashedIcon}
+ isActive={activeTool === 'marquee' || activeTool === 'lasso'}
+ items={items}
+ label={t(current === 'lasso' ? 'widgets.canvas.tools.lasso' : 'widgets.canvas.tools.marquee')}
+ onActivate={onActivate}
+ onSelectSubtool={onSelectSubtool}
+ />
+ );
+};
+
/**
* Clears the center region's floating chrome, whose inset already includes the
* gap below the islands. Outside the center the variable is undefined and the
@@ -109,13 +222,7 @@ const ToolStripRoot = ({
label={t('widgets.canvas.tools.eraser')}
toolId="eraser"
/>
- <ToolStripButton
- engine={engine}
- icon={ShapesIcon}
- isInteractionLocked={isInteractionLocked}
- label={t('widgets.canvas.tools.shape')}
- toolId="shape"
- />
+ <ShapeFamilyButton engine={engine} isInteractionLocked={isInteractionLocked} />
<ToolStripButton
engine={engine}
icon={PaintBucketIcon}
@@ -130,20 +237,7 @@ const ToolStripRoot = ({
label={t('widgets.canvas.tools.text')}
toolId="text"
/>
- <ToolStripButton
- engine={engine}
- icon={SquareDashedIcon}
- isInteractionLocked={isInteractionLocked}
- label={t('widgets.canvas.tools.marquee')}
- toolId="marquee"
- />
- <ToolStripButton
- engine={engine}
- icon={LassoIcon}
- isInteractionLocked={isInteractionLocked}
- label={t('widgets.canvas.tools.lasso')}
- toolId="lasso"
- />
+ <SelectFamilyButton engine={engine} isInteractionLocked={isInteractionLocked} />
</Toolbar>
</Box>
);
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/ToolStripFlyout.tsx b/invokeai/frontend/webv2/src/workbench/widgets/canvas/ToolStripFlyout.tsx
new file mode 100644
index 0000000000..6c5fe64396
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/ToolStripFlyout.tsx
@@ -0,0 +1,314 @@
+import type { KeyboardEvent, PointerEvent as ReactPointerEvent } from 'react';
+
+import { Box, Icon } from '@chakra-ui/react';
+import { IconButton } from '@platform/ui/Button';
+import { Tooltip } from '@platform/ui/Tooltip';
+import { useCallback, useEffect, useRef, useState } from 'react';
+
+const HOLD_OPEN_MS = 350;
+const TOOLTIP_POSITIONING = { placement: 'right' } as const;
+
+export interface ToolFlyoutItem {
+ id: string;
+ icon: React.ElementType;
+ label: string;
+}
+
+/**
+ * A tool-strip slot that owns subtools, Photoshop-style: plain click selects
+ * the slot's current subtool; press-and-hold (or right-click, or ArrowRight /
+ * the context-menu key) opens a flyout beside the button. Releasing the held
+ * pointer over an entry selects it; a quick release leaves the flyout open for
+ * a click. The corner tick marks the slot as holding more tools.
+ */
+export const ToolFamilyButton = ({
+ currentId,
+ disabled,
+ icon,
+ isActive,
+ items,
+ label,
+ onActivate,
+ onSelectSubtool,
+}: {
+ /** The subtool the slot currently stands for (checked in the flyout). */
+ currentId: string;
+ disabled?: boolean;
+ icon: React.ElementType;
+ isActive: boolean;
+ items: readonly ToolFlyoutItem[];
+ label: string;
+ /** Plain click: select the current subtool. */
+ onActivate: () => void;
+ onSelectSubtool: (id: string) => void;
+}) => {
+ const [open, setOpen] = useState(false);
+ const rootRef = useRef<HTMLDivElement | null>(null);
+ const buttonRef = useRef<HTMLButtonElement | null>(null);
+ const holdTimer = useRef<number | null>(null);
+ const openedByHold = useRef(false);
+
+ const clearHoldTimer = useCallback(() => {
+ if (holdTimer.current !== null) {
+ window.clearTimeout(holdTimer.current);
+ holdTimer.current = null;
+ }
+ }, []);
+ const close = useCallback(() => {
+ setOpen(false);
+ openedByHold.current = false;
+ }, []);
+
+ // Outside pointers and Escape close the flyout; the listener lives only while open.
+ useEffect(() => {
+ if (!open) {
+ return;
+ }
+ const onOutside = (event: PointerEvent) => {
+ if (!rootRef.current?.contains(event.target as Node)) {
+ close();
+ }
+ };
+ const onEscape = (event: globalThis.KeyboardEvent) => {
+ if (event.key === 'Escape') {
+ close();
+ buttonRef.current?.focus();
+ }
+ };
+ window.addEventListener('pointerdown', onOutside, true);
+ window.addEventListener('keydown', onEscape, true);
+ return () => {
+ window.removeEventListener('pointerdown', onOutside, true);
+ window.removeEventListener('keydown', onEscape, true);
+ };
+ }, [close, open]);
+ useEffect(() => clearHoldTimer, [clearHoldTimer]);
+
+ const select = useCallback(
+ (id: string) => {
+ // The focused entry unmounts with the flyout; keep focus in the strip.
+ const restoreFocus = rootRef.current?.contains(document.activeElement) ?? false;
+ onSelectSubtool(id);
+ close();
+ if (restoreFocus) {
+ buttonRef.current?.focus();
+ }
+ },
+ [close, onSelectSubtool]
+ );
+ const onMenuKeyDown = useCallback((event: KeyboardEvent<HTMLDivElement>) => {
+ if (event.key !== 'ArrowRight' && event.key !== 'ArrowLeft' && event.key !== 'Home' && event.key !== 'End') {
+ return;
+ }
+ const entries = Array.from(rootRef.current?.querySelectorAll<HTMLElement>('[data-subtool-id]') ?? []);
+ if (entries.length === 0) {
+ return;
+ }
+ event.preventDefault();
+ const index = entries.indexOf(document.activeElement as HTMLElement);
+ const next =
+ event.key === 'Home'
+ ? 0
+ : event.key === 'End'
+ ? entries.length - 1
+ : (index + (event.key === 'ArrowRight' ? 1 : -1) + entries.length) % entries.length;
+ entries[next]?.focus();
+ }, []);
+
+ const onPointerDown = useCallback(
+ (event: ReactPointerEvent<HTMLButtonElement>) => {
+ if (disabled || event.button !== 0) {
+ return;
+ }
+ openedByHold.current = false;
+ clearHoldTimer();
+ try {
+ // Without capture the release over a flyout entry targets the entry,
+ // not this button, and the release-to-select path never runs.
+ event.currentTarget.setPointerCapture(event.pointerId);
+ } catch {
+ // Synthetic pointers have no active id to capture.
+ }
+ holdTimer.current = window.setTimeout(() => {
+ holdTimer.current = null;
+ openedByHold.current = true;
+ setOpen(true);
+ }, HOLD_OPEN_MS);
+ },
+ [clearHoldTimer, disabled]
+ );
+ const onPointerUp = useCallback(
+ (event: ReactPointerEvent<HTMLButtonElement>) => {
+ if (disabled) {
+ return;
+ }
+ if (holdTimer.current !== null) {
+ clearHoldTimer();
+ // Short press: an ordinary click on the slot — but only released over
+ // it. Capture retargets the release here even after a drag-off, and a
+ // drag-off release must cancel, like any button.
+ const rect = event.currentTarget.getBoundingClientRect();
+ const overButton =
+ event.clientX >= rect.left &&
+ event.clientX <= rect.right &&
+ event.clientY >= rect.top &&
+ event.clientY <= rect.bottom;
+ if (!overButton) {
+ return;
+ }
+ if (!open) {
+ onActivate();
+ } else {
+ close();
+ }
+ return;
+ }
+ if (open && openedByHold.current) {
+ // Held open: releasing over an entry selects it; elsewhere keeps the
+ // flyout open for a click.
+ const under = document.elementFromPoint(event.clientX, event.clientY);
+ const item = under?.closest<HTMLElement>('[data-subtool-id]');
+ if (item?.dataset.subtoolId) {
+ select(item.dataset.subtoolId);
+ }
+ openedByHold.current = false;
+ }
+ },
+ [clearHoldTimer, close, disabled, onActivate, open, select]
+ );
+ const onPointerMove = useCallback(
+ (event: ReactPointerEvent<HTMLButtonElement>) => {
+ // Dragging off the button mid-hold cancels the pending open but keeps an
+ // already-open flyout (the pointer is heading for it). Capture suppresses
+ // pointerleave, so the bounds check runs on the retargeted moves instead.
+ if (holdTimer.current === null) {
+ return;
+ }
+ const rect = event.currentTarget.getBoundingClientRect();
+ if (
+ event.clientX < rect.left ||
+ event.clientX > rect.right ||
+ event.clientY < rect.top ||
+ event.clientY > rect.bottom
+ ) {
+ clearHoldTimer();
+ }
+ },
+ [clearHoldTimer]
+ );
+ const onPointerCancel = useCallback(() => {
+ // A canceled pointer (touch scroll takeover, OS gesture) must not open the
+ // flyout later; an already-open flyout stays for a click, like quick release.
+ clearHoldTimer();
+ openedByHold.current = false;
+ }, [clearHoldTimer]);
+ const onContextMenu = useCallback(
+ (event: ReactPointerEvent<HTMLButtonElement> | React.MouseEvent<HTMLButtonElement>) => {
+ event.preventDefault();
+ if (!disabled) {
+ setOpen(true);
+ }
+ },
+ [disabled]
+ );
+ const onKeyDown = useCallback((event: KeyboardEvent<HTMLButtonElement>) => {
+ if (event.key === 'ArrowRight' || event.key === 'ContextMenu') {
+ event.preventDefault();
+ setOpen(true);
+ requestAnimationFrame(() => {
+ rootRef.current?.querySelector<HTMLElement>('[data-subtool-id]')?.focus();
+ });
+ }
+ }, []);
+
+ return (
+ <Box ref={rootRef} position="relative">
+ {/* Forcing `open={false}` (not `disabled`) suppresses the tooltip while
+ the flyout sits in its spot: the disabled path unwraps the trigger and
+ remounts the button, dropping pointer capture mid-hold. */}
+ <Tooltip content={label} open={open ? false : undefined} positioning={TOOLTIP_POSITIONING}>
+ <IconButton
+ ref={buttonRef}
+ aria-expanded={open}
+ aria-haspopup="menu"
+ aria-label={label}
+ aria-pressed={isActive}
+ disabled={disabled}
+ size="xs"
+ variant={isActive ? 'solid' : 'ghost'}
+ onContextMenu={onContextMenu}
+ onKeyDown={onKeyDown}
+ onPointerCancel={onPointerCancel}
+ onPointerDown={onPointerDown}
+ onPointerMove={onPointerMove}
+ onPointerUp={onPointerUp}
+ >
+ <Icon as={icon} boxSize="3.5" />
+ {/* The corner tick: this slot holds more tools. */}
+ <Box
+ borderBottomColor="fg.subtle"
+ borderBottomWidth="4px"
+ borderLeftColor="transparent"
+ borderLeftWidth="4px"
+ bottom="0.5"
+ h="0"
+ pointerEvents="none"
+ position="absolute"
+ right="0.5"
+ w="0"
+ />
+ </IconButton>
+ </Tooltip>
+ {open ? (
+ <Box
+ aria-label={label}
+ bg="bg.panel"
+ borderColor="border.subtle"
+ borderWidth="1px"
+ display="flex"
+ gap="0.5"
+ left="calc(100% + 4px)"
+ p="0.5"
+ position="absolute"
+ role="menu"
+ rounded="md"
+ shadow="md"
+ top="0"
+ zIndex="3"
+ onKeyDown={onMenuKeyDown}
+ >
+ {items.map((item) => (
+ <FlyoutItem key={item.id} checked={item.id === currentId} item={item} onSelect={select} />
+ ))}
+ </Box>
+ ) : null}
+ </Box>
+ );
+};
+
+const FlyoutItem = ({
+ checked,
+ item,
+ onSelect,
+}: {
+ checked: boolean;
+ item: ToolFlyoutItem;
+ onSelect: (id: string) => void;
+}) => {
+ const onClick = useCallback(() => onSelect(item.id), [item.id, onSelect]);
+ return (
+ <Tooltip content={item.label} positioning={TOOLTIP_POSITIONING}>
+ <IconButton
+ aria-checked={checked}
+ aria-label={item.label}
+ data-subtool-id={item.id}
+ role="menuitemradio"
+ size="xs"
+ variant={checked ? 'solid' : 'ghost'}
+ onClick={onClick}
+ >
+ <Icon as={item.icon} boxSize="3.5" />
+ </IconButton>
+ </Tooltip>
+ );
+};
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/canvasHotkeyCommands.test.ts b/invokeai/frontend/webv2/src/workbench/widgets/canvas/canvasHotkeyCommands.test.ts
index 6c1a91b26e..e770c443f8 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/canvasHotkeyCommands.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/canvasHotkeyCommands.test.ts
@@ -417,6 +417,29 @@ describe('tool selection', () => {
});
expect(engine.interaction.set).toHaveBeenCalledWith('marqueeOptions', { kind: 'rect' });
});
+
+ it('shape selects the tool when it is not active', () => {
+ const engine = run('canvas.tool.shape', {
+ engine: createEngine({ shapeOptions: { kind: 'triangle' } as never }),
+ });
+ expect(engine.tools.setTool).toHaveBeenCalledWith('shape');
+ expect(engine.interaction.set).not.toHaveBeenCalledWith('shapeOptions', expect.anything());
+ });
+
+ it('shape cycles rect → ellipse when already active, keeping the other options', () => {
+ const engine = run('canvas.tool.shape', {
+ engine: createEngine({ activeTool: 'shape', shapeOptions: { fillEnabled: true, kind: 'rect' } as never }),
+ });
+ expect(engine.tools.setTool).not.toHaveBeenCalled();
+ expect(engine.interaction.set).toHaveBeenCalledWith('shapeOptions', { fillEnabled: true, kind: 'ellipse' });
+ });
+
+ it('shape cycles star back around to rect', () => {
+ const engine = run('canvas.tool.shape', {
+ engine: createEngine({ activeTool: 'shape', shapeOptions: { kind: 'star' } as never }),
+ });
+ expect(engine.interaction.set).toHaveBeenCalledWith('shapeOptions', { kind: 'rect' });
+ });
});
describe('history, selection, and brush size', () => {
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/canvasHotkeyCommands.ts b/invokeai/frontend/webv2/src/workbench/widgets/canvas/canvasHotkeyCommands.ts
index 7a32dcb9f8..5d4b1b5fa2 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/canvasHotkeyCommands.ts
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/canvasHotkeyCommands.ts
@@ -235,7 +235,17 @@ export const executeCanvasHotkeyCommand = (commandId: string, ctx: CanvasHotkeyC
}
}
} else if (commandId === 'canvas.tool.shape') {
- engine?.tools.setTool('shape');
+ if (engine) {
+ if (engine.interaction.get('activeTool') === 'shape') {
+ // Repeat presses cycle the kind, like the marquee hotkey.
+ const shape = engine.interaction.get('shapeOptions');
+ const order = ['rect', 'ellipse', 'triangle', 'star'] as const;
+ const next = order[(order.indexOf(shape.kind) + 1) % order.length]!;
+ engine.interaction.set('shapeOptions', { ...shape, kind: next });
+ } else {
+ engine.tools.setTool('shape');
+ }
+ }
} else if (commandId === 'canvas.tool.text') {
engine?.tools.setTool('text');
} else if (commandId === 'canvas.tool.gradient') {
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/toolFamilyStore.ts b/invokeai/frontend/webv2/src/workbench/widgets/canvas/toolFamilyStore.ts
new file mode 100644
index 0000000000..7940501fc4
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/toolFamilyStore.ts
@@ -0,0 +1,42 @@
+import type { ToolId } from '@workbench/canvas-engine/api';
+
+import { createExternalStore } from '@platform/state/externalStore';
+
+const STORAGE_KEY = 'invokeai:v7:webv2:select-family-tool';
+
+export type SelectFamilyTool = Extract<ToolId, 'marquee' | 'lasso'>;
+
+const isSelectFamilyTool = (value: unknown): value is SelectFamilyTool => value === 'marquee' || value === 'lasso';
+
+const readStored = (): SelectFamilyTool => {
+ if (typeof window === 'undefined') {
+ return 'marquee';
+ }
+ try {
+ const stored = window.localStorage.getItem(STORAGE_KEY);
+ return isSelectFamilyTool(stored) ? stored : 'marquee';
+ } catch {
+ return 'marquee';
+ }
+};
+
+/**
+ * Which selection tool the strip's Select family slot stands for right now —
+ * the last one used, remembered per user, so the slot's plain click restores
+ * the tool the user actually works with.
+ */
+const store = createExternalStore<{ tool: SelectFamilyTool }>({ tool: readStored() });
+
+export const recordSelectFamilyTool = (tool: SelectFamilyTool): void => {
+ if (store.getSnapshot().tool === tool) {
+ return;
+ }
+ store.setSnapshot({ tool });
+ try {
+ window.localStorage.setItem(STORAGE_KEY, tool);
+ } catch {
+ // Storage failures are non-fatal; this is a convenience.
+ }
+};
+
+export const useSelectFamilyTool = (): SelectFamilyTool => store.useSelector((snapshot) => snapshot.tool, Object.is);
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersTree.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersTree.browser.test.tsx
index 4e20e34c05..686907a3ee 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersTree.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersTree.browser.test.tsx
@@ -554,27 +554,39 @@ describe('LayersTree selection, surfaces and structure', () => {
});
expect(scroller.scrollTop).toBeGreaterThan(0);
await act(() => pointer('pointermove', document, start.x, rect.top + rect.height / 2));
- // A queued edge-band tick may still land after the move, so the invariant
- // is that scrolling STOPS: wait for scrollTop to hold still, then assert
- // it stays put — not that it equals a value captured mid-flight.
- let settled = scroller.scrollTop;
- for (let attempt = 0; attempt < 20; attempt += 1) {
- await new Promise<void>((resolve) => {
- setTimeout(resolve, 30);
+ // The move reaches the scroller through dnd-kit's rAF listener and the
+ // scroll loop itself is rAF-driven, so settle in frame time, not timer
+ // time: timers keep firing while rAF is starved under suite load, and a
+ // timer-based poll can declare "settled" before the queued frames flush.
+ // Ten consecutive frames with an unchanged scrollTop means both the move
+ // was delivered and the loop is parked.
+ const nextFrame = () =>
+ new Promise<void>((resolve) => {
+ requestAnimationFrame(() => resolve());
});
+ let settled = scroller.scrollTop;
+ let stillFrames = 0;
+ for (let attempt = 0; attempt < 600 && stillFrames < 10; attempt += 1) {
+ await nextFrame();
const next = scroller.scrollTop;
if (next === settled) {
- break;
+ stillFrames += 1;
+ } else {
+ settled = next;
+ stillFrames = 0;
}
- settled = next;
}
- await new Promise<void>((resolve) => {
- setTimeout(resolve, 60);
- });
+ expect(stillFrames).toBe(10);
expect(scroller.scrollTop).toBe(settled);
- const checks = refusalChecks.mock.calls.length;
+ // "Once per target": how many rows scrolled under the pointer depends on
+ // timing, so assert dedup, not a count — every check was for a distinct
+ // drop target, never a repeat for the target already under the pointer.
+ // Holds because the edge only recomputes on dragMove/over transitions;
+ // (row N, below) and (row N+1, above) map to the same command, so an
+ // edge recompute per scroll tick would break this.
+ const checked = refusalChecks.mock.calls.map(([command]) => JSON.stringify(command));
await act(() => pointer('pointerup', document, start.x, rect.top + rect.height / 2));
- expect(checks).toBeLessThanOrEqual(6);
+ expect(new Set(checked).size).toBe(checked.length);
});
it('reorders with a pointer drag and reparents from the keyboard', async () => {