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
Merge remote-tracking branch 'origin/main' into perf/image-map-cluster-selection
Lincoln Stein7557d2b9d5fa
diff --cc invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetView.browser.test.tsxindex b737040f1c,0c19781ad6..6c9ebc3177--- a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetView.browser.test.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetView.browser.test.tsx@@@ -7,22 -7,12 +7,24 @@@ import { act } from 'react'import { createRoot, type Root } from 'react-dom/client';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';- // The gallery's values drive the cluster chip and the Esc clear; the image- // map's own settings read as off.++// Stand-ins for the gallery's values and the workbench commands the chip and Esc write through.+const workbench = vi.hoisted(() => ({+ galleryValues: {} as Record<string, unknown>,+ patchValues: vi.fn(),+}));+vi.mock('@workbench/WorkbenchContext', () => ({- useWidgetValuesSelector: (widgetId: string, selector: (values: Record<string, unknown>) => unknown) =>- widgetId === 'gallery' ? selector(workbench.galleryValues) : false,- // Applied to an empty value bag rather than answering `false` to every- // selector: each accessor owns its own default, and handing a boolean to a- // setting that is a number or null makes the widget act on a value it could- // never be given in production.- useWidgetValuesSelector: (_widgetId: string, select: (values: Record<string, unknown>) => unknown) => select({}),++ // The gallery's values drive the cluster chip and the Esc clear. Every other widget's selector is applied to an++ // empty value bag rather than answering `false`: each accessor owns its own default, and handing a boolean to a++ // setting that is a number or null makes the widget act on a value it could never be given in production.++ useWidgetValuesSelector: (widgetId: string, select: (values: Record<string, unknown>) => unknown) =>++ select(widgetId === 'gallery' ? workbench.galleryValues : {}),+ useWorkbenchCommands: () => ({ widgets: { patchValues: workbench.patchValues } }),+ useWorkbenchQueries: () => ({ getSnapshot: () => ({ activeProject: {} }) }),+}));+vi.mock('@workbench/widgetState', async (importOriginal) => ({+ ...(await importOriginal<Record<string, unknown>>()),+ getProjectWidgetValues: () => workbench.galleryValues,}));// Stub the heavy Plotly sibling; this test owns the progress badge.@@@ -421,155 -379,3 +425,156 @@@ describe('Image Map indexing activity'expect(host?.textContent).not.toContain('indexing');});});++describe('Image Map cluster selection chip', () => {+ const POINTS = [+ { cluster: 2, item: { kind: 'image' as const, name: 'a.png' }, key: 'image:a.png' as const, x: 0, y: 0 },+ { cluster: 2, item: { kind: 'image' as const, name: 'b.png' }, key: 'image:b.png' as const, x: 1, y: 1 },+ { cluster: 5, item: { kind: 'image' as const, name: 'c.png' }, key: 'image:c.png' as const, x: 9, y: 9 },+ ];++ const renderMap = async (+ counts: { total: number; embedded: number; pending: number; failed: number } | null,+ props: WidgetViewProps = viewProps,+ centerChromeInset?: string+ ) => {+ imageMapStore.setSnapshot({+ clusterLabels: null,++ clusterLabelsEps: null,+ clusterLabelsHash: null,+ data: {+ clusterEps: null,+ modelName: null,+ pointCount: POINTS.length,+ points: POINTS,+ stale: false,+ state: 'ready',+ updatedAt: '2026-09-23T01:00:00',+ visibleHash: 'hash',+ },+ error: null,+ indexCounts: counts,+ indexUpdatedAt: counts ? Date.now() : null,+ loadState: 'loaded',+ renderError: null,+ });++ await act(() =>+ root?.render(+ <ChakraProvider value={system}>+ <div+ style={{+ height: 400,+ width: 500,+ ...(centerChromeInset ? { '--wb-center-chrome-inset': centerChromeInset } : {}),+ }}+ >+ <ImageMapWidgetView {...props} />+ </div>+ </ChakraProvider>+ )+ );+ };++ const selectCluster = (label: string, count = 2) => {+ const keys = POINTS.slice(0, count).map((point) => point.key);+ const clusterId = registerImageCluster(keys, label);++ workbench.galleryValues = { semanticImageQuery: { clusterId, kind: 'cluster', label }, searchTerm: '' };+ };++ const chip = () => host?.querySelector<HTMLElement>('[role="group"][aria-label="Selected cluster"]') ?? null;+ const CLEARED = { galleryPage: 0, searchTerm: '', semanticImageQuery: null, semanticSearchText: null };++ it('names the selected cluster with its size and colour, above the indexing badge', async () => {+ selectCluster('sunset beach');+ await renderMap({ embedded: 10, failed: 0, pending: 5, total: 15 });++ expect(chip()?.textContent).toBe('sunset beach· 2 items');+ // Cluster 2's palette colour: both members are in it.+ expect(getComputedStyle(chip()!.querySelector('[aria-hidden="true"]')!).backgroundColor).toBe('rgb(225, 87, 89)');+ // Stacked in one corner rather than drawn over each other, the selection first.+ const badge = host?.querySelector('[role="progressbar"]');+ expect(chip()!.compareDocumentPosition(badge!) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();+ expect(badge!.getBoundingClientRect().top).toBeGreaterThanOrEqual(chip()!.getBoundingClientRect().bottom);+ });++ it('shows only the current size for an unlabeled cluster, even after members were deleted', async () => {+ // Named "2 items" at click time; one member has since gone.+ selectCluster('2 items', 1);+ await renderMap(null);++ expect(chip()?.textContent).toBe('1 item');+ });++ it('starts below the floating view selector when the map is in the center area', async () => {+ selectCluster('sunset beach');+ await renderMap(null, viewProps, '3rem');++ const surface = host!.querySelector<HTMLElement>('[data-image-map-surface]')!;+ // 3rem of center chrome plus the corner's own spacing.+ expect(chip()!.getBoundingClientRect().top - surface.getBoundingClientRect().top).toBeGreaterThanOrEqual(48 + 8);+ });++ it('clears the gallery cluster listing from its button', async () => {+ selectCluster('sunset beach');+ await renderMap(null);++ const clear = chip()!.querySelector<HTMLButtonElement>('button[aria-label="Clear cluster selection"]')!;+ clear.focus();+ await act(() => clear.click());++ expect(workbench.patchValues).toHaveBeenCalledWith('gallery', CLEARED);+ // The button is about to unmount with the chip; focus stays on the map, where Esc keeps working.+ expect(document.activeElement).toBe(host!.querySelector('[data-image-map-surface]'));+ });++ it('moves the Esc binding to the new project when the runtime changes without a remount', async () => {+ await renderMap(null);+ await renderMap(null, makeViewProps('project-b'));++ const escBindings = registered.hotkeys.filter((entry) => entry.defaultKeys.includes('esc'));+ // Registrations carry the project they were made for; a binding left on the+ // old project's runtime would never resolve in the new one.+ expect(escBindings.map((entry) => [entry.runtime, entry.disposed])).toEqual([+ ['project-a', true],+ ['project-b', false],+ ]);+ expect(+ registered.commands+ .filter((entry) => entry.id === escBindings[0]!.commandId)+ .map((entry) => [entry.runtime, entry.disposed])+ ).toEqual([+ ['project-a', true],+ ['project-b', false],+ ]);+ });++ it('shows nothing when the gallery is not listing a cluster', async () => {+ workbench.galleryValues = { searchTerm: 'cats' };+ await renderMap(null);++ expect(chip()).toBeNull();+ });++ it('binds Esc to the clear, which leaves an ordinary search alone', async () => {+ workbench.galleryValues = { searchTerm: 'cats' };+ await renderMap(null);++ const hotkey = registered.hotkeys.find((entry) => entry.defaultKeys.includes('esc'));+ const command = registered.commands.find((entry) => entry.id === hotkey?.commandId);+ expect(command).toBeDefined();++ // Esc with no cluster selected must not wipe the user's search.+ await act(() => {+ command!.handler();+ });+ expect(workbench.patchValues).not.toHaveBeenCalled();++ selectCluster('sunset beach');+ await act(() => {+ command!.handler();+ });+ expect(workbench.patchValues).toHaveBeenCalledWith('gallery', CLEARED);+ });+});diff --cc invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetView.tsxindex 04b8420f1a,8a2e2618ab..7cb30db64f--- a/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetView.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/image-map/ImageMapWidgetView.tsx@@@ -58,39 -55,18 +63,46 @@@ const plotLoadingFallback =);/** Show backend embeddings projected by UMAP and colored by cluster; point selection drives Gallery and Preview. */-export const ImageMapWidgetView = (_props: WidgetViewProps) => {+export const ImageMapWidgetView = ({ runtime }: WidgetViewProps) => {const { data, error, indexCounts, indexUpdatedAt, loadState, renderError } = imageMapStore.useSnapshot();const clickSelectsCluster = useWidgetValuesSelector('image-map', getImageMapClickSelectsCluster);+ const clusterEps = useWidgetValuesSelector('image-map', getImageMapClusterEps);const showClusterLabels = useWidgetValuesSelector('image-map', getImageMapShowClusterLabels);+ const clearClusterSelection = useClearClusterSelection();++ // Esc while the map owns focus, the keyboard path to the chip's clear. Also+ // a palette command. The runtime stamps registrations with the active+ // project and is rebuilt on a project switch without remounting this view,+ // so registration follows it; the clear reads the selection when it fires.+ const { commands: runtimeCommands, hotkeys: runtimeHotkeys } = runtime;++ useEffect(() => {+ const disposers = [+ runtimeCommands.register({+ handler: clearClusterSelection,+ id: CLEAR_CLUSTER_SELECTION_COMMAND,+ title: CLEAR_CLUSTER_SELECTION_LABEL,+ }),+ runtimeHotkeys.register({+ allowInEditable: false,+ commandId: CLEAR_CLUSTER_SELECTION_COMMAND,+ defaultKeys: ['esc'],+ id: CLEAR_CLUSTER_SELECTION_COMMAND,+ title: CLEAR_CLUSTER_SELECTION_LABEL,+ }),+ ];++ return () => {+ disposers.forEach((dispose) => dispose());+ };+ }, [clearClusterSelection, runtimeCommands, runtimeHotkeys]);+ // Before the first load, so it carries the chosen strength rather than+ // fetching at the default and immediately refetching.+ useEffect(() => {+ setClusterEps(clusterEps);+ }, [clusterEps]);+useEffect(() => {ensureImageMapLoaded();}, []);