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
feat(workbench): palette theme live-preview and queue provider wiring
joshistoast99fd31c54588
diff --git a/invokeai/frontend/webv2/src/app/ThemeController.tsx b/invokeai/frontend/webv2/src/app/ThemeController.tsxindex 8568094540..7ab3b19b43 100644--- a/invokeai/frontend/webv2/src/app/ThemeController.tsx+++ b/invokeai/frontend/webv2/src/app/ThemeController.tsx@@ -1,4 +1,5 @@import { shallowEqual } from '@platform/state/selectors';+import { applyThemeToRoot } from '@theme/applyTheme';import { DEFAULT_THEME, THEMES_BY_ID } from '@theme/system';import { useWorkbenchSettingsSelector } from '@workbench/settings/store';import { useLayoutEffect } from 'react';@@ -38,15 +39,9 @@ export const ThemeController = () => {return;}- const root = document.documentElement;const theme = THEMES_BY_ID[themeId] ?? DEFAULT_THEME;- root.dataset.theme = theme.id;- root.style.colorScheme = theme.colorScheme;- // Keep the native color-mode class in sync for unthemed browser chrome- // (scrollbars, native pickers) and any Chakra defaults we don't override.- root.classList.toggle('dark', theme.colorScheme === 'dark');- root.classList.toggle('light', theme.colorScheme === 'light');+ applyThemeToRoot(theme.id);try {window.localStorage.setItem(THEME_HINT_STORAGE_KEY, theme.id);diff --git a/invokeai/frontend/webv2/src/platform/ui/theme/applyTheme.ts b/invokeai/frontend/webv2/src/platform/ui/theme/applyTheme.tsnew file mode 100644index 0000000000..08bdaf9074--- /dev/null+++ b/invokeai/frontend/webv2/src/platform/ui/theme/applyTheme.ts@@ -0,0 +1,20 @@+import { DEFAULT_THEME, THEMES_BY_ID } from './themes';++/**+ * Applies a theme to the document root. Semantic tokens key off+ * `:root[data-theme]`, so these attribute writes restyle the whole shell with+ * no React re-render. Deliberately does NOT touch the pre-paint localStorage+ * hint — callers that persist (ThemeController) own that; transient callers+ * (palette live-preview) must not.+ */+export const applyThemeToRoot = (themeId: string): void => {+ const root = document.documentElement;+ const theme = THEMES_BY_ID[themeId as keyof typeof THEMES_BY_ID] ?? DEFAULT_THEME;++ root.dataset.theme = theme.id;+ root.style.colorScheme = theme.colorScheme;+ // Keep the native color-mode class in sync for unthemed browser chrome+ // (scrollbars, native pickers) and any Chakra defaults we don't override.+ root.classList.toggle('dark', theme.colorScheme === 'dark');+ root.classList.toggle('light', theme.colorScheme === 'light');+};diff --git a/invokeai/frontend/webv2/src/workbench/palette/CommandPaletteDialog.tsx b/invokeai/frontend/webv2/src/workbench/palette/CommandPaletteDialog.tsxindex 9ef8081e1c..08d77c19b3 100644--- a/invokeai/frontend/webv2/src/workbench/palette/CommandPaletteDialog.tsx+++ b/invokeai/frontend/webv2/src/workbench/palette/CommandPaletteDialog.tsx@@ -20,6 +20,7 @@ import {buildStageEntries,PROVIDER_MIN_QUERY_LENGTH,searchPaletteRows,+ STAGE_ENTRY_ID_PREFIX,} from './entries';import { getRecentEntryIds, recordRecentEntry } from './recents';@@ -428,6 +429,27 @@ const CommandPaletteContent = ({const effectiveActiveIndex = navigableRowIndexes.includes(activeIndex) ? activeIndex : (navigableRowIndexes[0] ?? -1);const activeRow = effectiveActiveIndex === -1 ? undefined : rows[effectiveActiveIndex];+ // --- Stage preview -----------------------------------------------------+ // Leaving a previewing stage always changes `stage` (pop sets it null, close+ // unmounts), so this cleanup reverts the preview on every exit path. A pick+ // persists first, making the revert an idempotent no-op.+ useEffect(() => {+ if (!stage?.clearPreview) {+ return;+ }++ return stage.clearPreview;+ }, [stage]);++ // Preview follows the highlight, including the first match while typing.+ useEffect(() => {+ if (!stage?.preview || activeRow?.kind !== 'entry' || !activeRow.entry.id.startsWith(STAGE_ENTRY_ID_PREFIX)) {+ return;+ }++ stage.preview(activeRow.entry.id.slice(STAGE_ENTRY_ID_PREFIX.length));+ }, [activeRow, stage]);+const estimateRowSize = useCallback((index: number) => (rows[index]?.kind === 'label' ? LABEL_ROW_HEIGHT_PX : ENTRY_ROW_HEIGHT_PX),[rows]@@ -466,7 +488,11 @@ const CommandPaletteContent = ({if (row.entry.stage) {setStage(row.entry.stage);setQuery('');- setActiveIndex(-1);+ // Land the highlight on the current value (+1 skips the single group+ // label row) — matches native pickers, and keeps a previewing stage+ // from flashing the first option's preview on open.+ const currentIndex = row.entry.stage.options.findIndex((option) => option.isCurrent);+ setActiveIndex(currentIndex === -1 ? -1 : currentIndex + 1);return;}diff --git a/invokeai/frontend/webv2/src/workbench/palette/LaunchpadCommandPalette.tsx b/invokeai/frontend/webv2/src/workbench/palette/LaunchpadCommandPalette.tsxindex 08d4aeb75f..0c8d23fc4a 100644--- a/invokeai/frontend/webv2/src/workbench/palette/LaunchpadCommandPalette.tsx+++ b/invokeai/frontend/webv2/src/workbench/palette/LaunchpadCommandPalette.tsx@@ -1,7 +1,7 @@import { useCapabilities } from '@features/identity';import { useNavigate, useSearch } from '@tanstack/react-router';import { openWorkbenchSettings } from '@workbench/settings/settingsDialogStore';-import { patchWorkbenchPreferences, useWorkbenchPreferences } from '@workbench/settings/store';+import { useWorkbenchPreferences } from '@workbench/settings/store';import { useEffect, useMemo } from 'react';import { tinykeys } from 'tinykeys';@@ -10,6 +10,7 @@ import type { PaletteEntry } from './entries';import { CommandPaletteDialog } from './CommandPaletteDialog';import { buildSettingsEntries } from './entries';import { closeCommandPalette, commandPaletteStore, toggleCommandPalette } from './paletteStore';+import { SETTINGS_ENTRY_DEPS } from './settingsEntryDeps';/*** Launchpad host: the editor's hotkey runtime is not mounted here, so this@@ -18,11 +19,6 @@ import { closeCommandPalette, commandPaletteStore, toggleCommandPalette } from '* that works "sometimes" trains users not to trust it.*/-const SETTINGS_ENTRY_DEPS = {- openSettingsSection: openWorkbenchSettings,- patchPreferences: patchWorkbenchPreferences,-};-export const LaunchpadCommandPalette = () => {const isOpen = commandPaletteStore.useSelector((snapshot) => snapshot.isOpen);const navigate = useNavigate();diff --git a/invokeai/frontend/webv2/src/workbench/palette/WorkbenchCommandPalette.tsx b/invokeai/frontend/webv2/src/workbench/palette/WorkbenchCommandPalette.tsxindex 3daec65419..cd3981aeb0 100644--- a/invokeai/frontend/webv2/src/workbench/palette/WorkbenchCommandPalette.tsx+++ b/invokeai/frontend/webv2/src/workbench/palette/WorkbenchCommandPalette.tsx@@ -1,5 +1,7 @@+import { getQueueQueryScope } from '@features/queue/queries';+import { requestQueueItemReveal } from '@features/queue/react';import { openWorkbenchSettings } from '@workbench/settings/settingsDialogStore';-import { patchWorkbenchPreferences, useWorkbenchPreferences } from '@workbench/settings/store';+import { getWorkbenchPreferences, useWorkbenchPreferences } from '@workbench/settings/store';import { openWidgetPlacement } from '@workbench/widgetPlacementCommands';import { getWidgetsForRegion } from '@workbench/widgetRegistry';import { getProjectWidgetValues } from '@workbench/widgetState';@@ -20,9 +22,11 @@ import {createImagesProvider,createModelsProvider,createPromptHistoryProvider,+ createQueueItemsProvider,createWorkflowsProvider,} from './paletteProviders';import { closeCommandPalette, commandPaletteStore } from './paletteStore';+import { SETTINGS_ENTRY_DEPS } from './settingsEntryDeps';/*** Editor host: aggregates the hotkey catalog, extension palette contributions,@@ -31,11 +35,6 @@ import { closeCommandPalette, commandPaletteStore } from './paletteStore';* own source so widget handlers resolve exactly as they do for hotkeys.*/-const SETTINGS_ENTRY_DEPS = {- openSettingsSection: openWorkbenchSettings,- patchPreferences: patchWorkbenchPreferences,-};-const STATIC_APP_ENTRIES: PaletteEntry[] = [{group: 'App',@@ -104,7 +103,7 @@ export const WorkbenchCommandPalette = () => {const extensionSearchProviders = useSyncExternalStore(searchStore.subscribe, searchStore.list, searchStore.list);const providers = useMemo<PaletteSearchProvider[]>(() => {const { gallery, widgets } = workbenchCommands;- const openWidget = (typeId: 'workflow' | 'gallery' | 'generate' | 'preview') =>+ const openWidget = (typeId: 'workflow' | 'gallery' | 'generate' | 'preview' | 'queue') =>openWidgetPlacement({getWidgetsForRegion,options:@@ -112,7 +111,9 @@ export const WorkbenchCommandPalette = () => {? { preferredRegions: ['center'], requireCenterView: true }: typeId === 'generate'? { preferredRegions: ['left'] }- : { preferredRegions: ['center', 'right'] },+ : typeId === 'queue'+ ? { preferredRegions: ['right'] }+ : { preferredRegions: ['center', 'right'] },typeId,widgets,});@@ -142,6 +143,17 @@ export const WorkbenchCommandPalette = () => {selectBoard: (boardId) => gallery.selectBoard(boardId),selectImage: (image) => gallery.selectImage(image),}),+ createQueueItemsProvider({+ // Scope must be read at search time — the jobs-scope pref is itself+ // editable from the palette.+ getScope: () =>+ getQueueQueryScope({+ projectId: queries.getSnapshot().activeProject.id,+ queueJobsScope: getWorkbenchPreferences().queueJobsScope,+ }),+ openQueueWidget: () => openWidget('queue'),+ revealItem: (itemId) => requestQueueItemReveal(itemId),+ }),createPromptHistoryProvider({getPromptHistory: () => queries.getSnapshot().activeProject.promptHistory,openGenerateWidget: () => openWidget('generate'),diff --git a/invokeai/frontend/webv2/src/workbench/palette/entries.test.ts b/invokeai/frontend/webv2/src/workbench/palette/entries.test.tsindex f4b612088f..bc4613502d 100644--- a/invokeai/frontend/webv2/src/workbench/palette/entries.test.ts+++ b/invokeai/frontend/webv2/src/workbench/palette/entries.test.ts@@ -122,6 +122,32 @@ describe('buildSettingsEntries', () => {edgeStyle?.stage?.options[1]?.apply();expect(patchPreferences).toHaveBeenCalledWith({ workflowEdgeStyle: 'square' });});++ it('wires theme stage preview hooks only when the host provides them', () => {+ const previewTheme = vi.fn();+ const clearThemePreview = vi.fn();+ const withPreview = buildSettingsEntries(DEFAULT_PREFERENCES, {+ clearThemePreview,+ openSettingsSection: vi.fn(),+ patchPreferences: vi.fn(),+ previewTheme,+ });+ const theme = withPreview.find((entry) => entry.id === 'setting.themeId');++ theme?.stage?.preview?.('light');+ theme?.stage?.clearPreview?.();+ expect(previewTheme).toHaveBeenCalledWith('light');+ expect(clearThemePreview).toHaveBeenCalled();++ const withoutPreview = buildSettingsEntries(DEFAULT_PREFERENCES, {+ openSettingsSection: vi.fn(),+ patchPreferences: vi.fn(),+ });+ const bareTheme = withoutPreview.find((entry) => entry.id === 'setting.themeId');++ expect(bareTheme?.stage?.preview).toBeUndefined();+ expect(bareTheme?.stage?.clearPreview).toBeUndefined();+ });});describe('buildStageEntries', () => {diff --git a/invokeai/frontend/webv2/src/workbench/palette/entries.ts b/invokeai/frontend/webv2/src/workbench/palette/entries.tsindex ac791e25bc..ac18ca54eb 100644--- a/invokeai/frontend/webv2/src/workbench/palette/entries.ts+++ b/invokeai/frontend/webv2/src/workbench/palette/entries.ts@@ -27,6 +27,10 @@ export interface PaletteStageOption {export interface PaletteStage {title: string;options: PaletteStageOption[];+ /** Transient preview of the highlighted option (must not persist anything). */+ preview?: (optionId: string) => void;+ /** Revert any active preview; called on every stage exit path. */+ clearPreview?: () => void;}export interface PaletteEntry {@@ -234,6 +238,10 @@ const SETTINGS_SECTIONS: ReadonlyArray<{ id: SettingsSectionId; title: string }>export interface SettingsEntryDeps {openSettingsSection: (sectionId: SettingsSectionId) => void;patchPreferences: (patch: Partial<WorkbenchPreferences>) => unknown;+ /** Transient theme preview while the Theme stage is open (no persistence). */+ previewTheme?: (themeId: string) => void;+ /** Revert a theme preview to the stored preference. */+ clearThemePreview?: () => void;}export const buildSettingsEntries = (preferences: WorkbenchPreferences, deps: SettingsEntryDeps): PaletteEntry[] => {@@ -254,6 +262,7 @@ export const buildSettingsEntries = (preferences: WorkbenchPreferences, deps: Sekeywords,options,sectionId,+ stagePreview,subtitle,title,}: {@@ -261,6 +270,7 @@ export const buildSettingsEntries = (preferences: WorkbenchPreferences, deps: Sekeywords: string;options: PaletteStageOption[];sectionId: SettingsSectionId;+ stagePreview?: Pick<PaletteStage, 'clearPreview' | 'preview'>;subtitle: string;title: string;}): PaletteEntry => ({@@ -269,7 +279,7 @@ export const buildSettingsEntries = (preferences: WorkbenchPreferences, deps: Sekeywords,run: () => deps.openSettingsSection(sectionId),secondary: { label: 'Open in Settings', run: () => deps.openSettingsSection(sectionId) },- stage: { options, title },+ stage: { options, title, ...stagePreview },subtitle,title,});@@ -285,6 +295,10 @@ export const buildSettingsEntries = (preferences: WorkbenchPreferences, deps: Selabel: theme.label,})),sectionId: 'appearance',+ stagePreview:+ deps.previewTheme && deps.clearThemePreview+ ? { clearPreview: deps.clearThemePreview, preview: deps.previewTheme }+ : undefined,subtitle: THEMES_BY_ID[preferences.themeId]?.label ?? preferences.themeId,title: 'Theme',}),@@ -475,11 +489,14 @@ export const searchPaletteRows = (// Stage / provider row assembly// ---------------------------------------------------------------------------+/** Row-id prefix for stage options; the dialog strips it to recover the option id. */+export const STAGE_ENTRY_ID_PREFIX = 'stage:';+/** Turn a value-picker stage into filterable entry rows; picking applies and pops. */export const buildStageEntries = (stage: PaletteStage, onApplied: () => void): PaletteEntry[] =>stage.options.map((option) => ({group: stage.title,- id: `stage:${option.id}`,+ id: `${STAGE_ENTRY_ID_PREFIX}${option.id}`,keepOpen: true,run: () => {void option.apply();diff --git a/invokeai/frontend/webv2/src/workbench/palette/settingsEntryDeps.ts b/invokeai/frontend/webv2/src/workbench/palette/settingsEntryDeps.tsnew file mode 100644index 0000000000..96ad020741--- /dev/null+++ b/invokeai/frontend/webv2/src/workbench/palette/settingsEntryDeps.ts@@ -0,0 +1,18 @@+import { applyThemeToRoot } from '@theme/applyTheme';+import { openWorkbenchSettings } from '@workbench/settings/settingsDialogStore';+import { getWorkbenchPreferences, patchWorkbenchPreferences } from '@workbench/settings/store';++import type { SettingsEntryDeps } from './entries';++/**+ * Live workbench bindings for the palette's settings entries, shared by both+ * palette hosts. Theme preview writes the DOM directly and never persists;+ * clearing re-applies whatever the store holds at that moment, so a preview+ * followed by an actual pick reverts to the picked value (a no-op).+ */+export const SETTINGS_ENTRY_DEPS: SettingsEntryDeps = {+ clearThemePreview: () => applyThemeToRoot(getWorkbenchPreferences().themeId),+ openSettingsSection: openWorkbenchSettings,+ patchPreferences: patchWorkbenchPreferences,+ previewTheme: applyThemeToRoot,+};