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(ui): persist preset order
joshistoast47d94cb98ad1
diff --git a/invokeai/frontend/webv2/src/workbench/layoutPresetCollection.test.ts b/invokeai/frontend/webv2/src/workbench/layoutPresetCollection.test.tsnew file mode 100644index 0000000000..5a6fe10164--- /dev/null+++ b/invokeai/frontend/webv2/src/workbench/layoutPresetCollection.test.ts@@ -0,0 +1,43 @@+import { describe, expect, it } from 'vitest';++import type { LayoutPreset } from './layoutContracts';+import type { AccountState } from './projectContracts';++import { getOrderedLayoutPresets, normalizeLayoutPresetOrder, reorderLayoutPresetIds } from './layoutPresetCollection';+import { layoutPresets } from './layoutPresets';++const customPreset: LayoutPreset = {+ id: 'custom-1',+ label: 'Custom',+ snapshot: layoutPresets[0].snapshot,+};++const account: AccountState = {+ activeLayoutPresetId: 'compose',+ customLayoutPresets: [customPreset],+ layoutPresetOrder: ['custom-1', 'compose', 'edit', 'automate'],+};++describe('layout preset collection', () => {+ it('drops stale and duplicate ids before appending missing presets', () => {+ expect(normalizeLayoutPresetOrder(['automate', 'bogus', 'automate'], [...layoutPresets, customPreset])).toEqual([+ 'automate',+ 'compose',+ 'edit',+ 'custom-1',+ ]);+ });++ it('resolves built-in and custom presets through the account order', () => {+ expect(getOrderedLayoutPresets(account).map(({ id }) => id)).toEqual(['custom-1', 'compose', 'edit', 'automate']);+ });++ it('moves a preset relative to the drop target without losing ids', () => {+ expect(reorderLayoutPresetIds(account, 'compose', 'automate')).toEqual(['custom-1', 'edit', 'automate', 'compose']);+ });++ it('returns null for invalid and unchanged moves', () => {+ expect(reorderLayoutPresetIds(account, 'missing', 'automate')).toBeNull();+ expect(reorderLayoutPresetIds(account, 'compose', 'compose')).toBeNull();+ });+});diff --git a/invokeai/frontend/webv2/src/workbench/layoutPresetCollection.ts b/invokeai/frontend/webv2/src/workbench/layoutPresetCollection.tsnew file mode 100644index 0000000000..aeeaa54679--- /dev/null+++ b/invokeai/frontend/webv2/src/workbench/layoutPresetCollection.ts@@ -0,0 +1,66 @@+import type { LayoutPreset, LayoutPresetId } from './layoutContracts';+import type { AccountState } from './projectContracts';++import { layoutPresets } from './layoutPresets';+import { resolveSavedLayoutPreset } from './layoutPresetSnapshots';++export const normalizeLayoutPresetOrder = (value: unknown, presets: readonly LayoutPreset[]): LayoutPresetId[] => {+ const knownIds = new Set(presets.map(({ id }) => id));+ const seenIds = new Set<LayoutPresetId>();+ const orderedIds: LayoutPresetId[] = [];++ if (Array.isArray(value)) {+ for (const id of value) {+ if (typeof id === 'string' && knownIds.has(id) && !seenIds.has(id)) {+ orderedIds.push(id);+ seenIds.add(id);+ }+ }+ }++ for (const { id } of presets) {+ if (!seenIds.has(id)) {+ orderedIds.push(id);+ seenIds.add(id);+ }+ }++ return orderedIds;+};++export const getOrderedLayoutPresets = (account: AccountState): LayoutPreset[] => {+ const availablePresets = [...layoutPresets, ...(account.customLayoutPresets ?? [])].map(({ id }) =>+ resolveSavedLayoutPreset(account, id)+ );+ const presetById = new Map(availablePresets.map((preset) => [preset.id, preset]));++ return normalizeLayoutPresetOrder(account.layoutPresetOrder, availablePresets).flatMap((id) => {+ const preset = presetById.get(id);++ return preset ? [preset] : [];+ });+};++export const reorderLayoutPresetIds = (+ account: AccountState,+ activeId: LayoutPresetId,+ overId: LayoutPresetId+): LayoutPresetId[] | null => {+ if (activeId === overId) {+ return null;+ }++ const orderedIds = getOrderedLayoutPresets(account).map(({ id }) => id);+ const activeIndex = orderedIds.indexOf(activeId);+ const overIndex = orderedIds.indexOf(overId);++ if (activeIndex < 0 || overIndex < 0) {+ return null;+ }++ const nextIds = [...orderedIds];+ const [movedId] = nextIds.splice(activeIndex, 1);+ nextIds.splice(overIndex, 0, movedId);++ return nextIds;+};diff --git a/invokeai/frontend/webv2/src/workbench/projectContracts.ts b/invokeai/frontend/webv2/src/workbench/projectContracts.tsindex 2261bf5e1c..3ec6b106e4 100644--- a/invokeai/frontend/webv2/src/workbench/projectContracts.ts+++ b/invokeai/frontend/webv2/src/workbench/projectContracts.ts@@ -130,6 +130,8 @@ export interface AutosaveState {export interface AccountState {activeLayoutPresetId: LayoutPresetId;customLayoutPresets?: LayoutPreset[];+ /** One account-wide order shared by every layout-preset surface. */+ layoutPresetOrder?: LayoutPresetId[];/** Saved edits to a built-in preset's arrangement; see {@link LayoutPresetOverrides}. */layoutPresetOverrides?: LayoutPresetOverrides;/** Saved edits to built-in preset routes, kept separate from spatial layout drift. */diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.test.tsindex 9dd9a02008..c1f3f92cc4 100644--- a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts@@ -18,6 +18,7 @@ import type { CanvasProjectMutation } from './canvasProjectMutations';import { createEmptyCanvasDocumentV2 } from './canvasMigration';import { getCanvasStagingCandidateFingerprint, getCanvasStagingSlots } from './canvasStagingView';+import { layoutPresets } from './layoutPresets';import { DEFAULT_PROJECT_SETTINGS } from './settings/store';import { getProjectWidgetValues } from './widgetState';import { GRAPH_HISTORY_BYTE_BUDGET, normalizeGraphHistory } from './workbenchState';@@ -826,6 +827,52 @@ describe('workbench layout presets', () => {expect(project.widgetRegions.center.activeInstanceId).toBe('preview');});+ it('persists one account-wide order through reordering and custom preset deletion', () => {+ let state = createInitialWorkbenchState();++ state = workbenchReducer(state, {+ label: 'Custom',+ presetId: 'custom-layout-1',+ type: 'addLayoutPreset',+ });++ expect(state.account.layoutPresetOrder).toEqual(['compose', 'edit', 'automate', 'custom-layout-1']);++ state = workbenchReducer(state, {+ activeId: 'custom-layout-1',+ overId: 'edit',+ type: 'reorderLayoutPresets',+ });++ expect(state.account.layoutPresetOrder).toEqual(['compose', 'custom-layout-1', 'edit', 'automate']);++ state = workbenchReducer(state, { presetId: 'custom-layout-1', type: 'deleteLayoutPreset' });++ expect(state.account.layoutPresetOrder).toEqual(['compose', 'edit', 'automate']);+ });++ it('normalizes stale and duplicate preset ids when hydrating an account', () => {+ const initial = createInitialWorkbenchState();+ const custom = {+ id: 'custom-layout-1',+ label: 'Custom',+ snapshot: layoutPresets[0].snapshot,+ };+ const state = workbenchReducer(initial, {+ state: {+ ...initial,+ account: {+ ...initial.account,+ customLayoutPresets: [custom],+ layoutPresetOrder: ['automate', 'missing', 'automate'],+ },+ },+ type: 'hydrateWorkbench',+ });++ expect(state.account.layoutPresetOrder).toEqual(['automate', 'compose', 'edit', 'custom-layout-1']);+ });+it('captures the live source and destination without routing locks when creating a custom preset', () => {let state = createInitialWorkbenchState();@@ -2732,6 +2779,7 @@ describe('workbench account and project settings', () => {expect(state.account).toEqual({activeLayoutPresetId: 'compose',customLayoutPresets: [],+ layoutPresetOrder: ['compose', 'edit', 'automate'],layoutPresetOverrides: {},layoutPresetRouteOverrides: {},});diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.tsindex 762572cb26..753191fa27 100644--- a/invokeai/frontend/webv2/src/workbench/workbenchState.ts+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.ts@@ -130,8 +130,15 @@ import {isResultDestinationAvailable,resolveInvocationRoute,} from './invocation';+import { getOrderedLayoutPresets, normalizeLayoutPresetOrder, reorderLayoutPresetIds } from './layoutPresetCollection';import { getInvocationAfterLayoutPreset } from './layoutPresetRouting';-import { defaultLayoutPreset, getLayoutPreset, isBuiltInLayoutPresetId, resolveLayoutPresetId } from './layoutPresets';+import {+ defaultLayoutPreset,+ getLayoutPreset,+ isBuiltInLayoutPresetId,+ layoutPresets,+ resolveLayoutPresetId,+} from './layoutPresets';import {cloneLayoutPresetWidgetRegions,createLayoutPresetSnapshot,@@ -154,6 +161,7 @@ type WorkbenchReducerAction =| { type: 'switchProject'; projectId: string }| { type: 'setCenterView'; centerViewId: CenterViewId }| { type: 'applyPreset'; presetId: LayoutPresetId }+ | { type: 'reorderLayoutPresets'; activeId: LayoutPresetId; overId: LayoutPresetId }| {type: 'addLayoutPreset';presetId: LayoutPresetId;@@ -1636,12 +1644,20 @@ const normalizeLayoutPresetOverrides = (overrides: unknown): LayoutPresetOverrid);};-const normalizeAccount = (account: Partial<WorkbenchState['account']> | undefined): WorkbenchState['account'] => ({- activeLayoutPresetId: resolveLayoutPresetId(account?.activeLayoutPresetId ?? defaultLayoutPreset.id),- customLayoutPresets: normalizeCustomLayoutPresets(account?.customLayoutPresets),- layoutPresetOverrides: normalizeLayoutPresetOverrides(account?.layoutPresetOverrides),- layoutPresetRouteOverrides: normalizeLayoutPresetRouteOverrides(account?.layoutPresetRouteOverrides),-});+const normalizeAccount = (account: Partial<WorkbenchState['account']> | undefined): WorkbenchState['account'] => {+ const customLayoutPresets = normalizeCustomLayoutPresets(account?.customLayoutPresets);++ return {+ activeLayoutPresetId: resolveLayoutPresetId(account?.activeLayoutPresetId ?? defaultLayoutPreset.id),+ customLayoutPresets,+ layoutPresetOrder: normalizeLayoutPresetOrder(account?.layoutPresetOrder, [+ ...layoutPresets,+ ...customLayoutPresets,+ ]),+ layoutPresetOverrides: normalizeLayoutPresetOverrides(account?.layoutPresetOverrides),+ layoutPresetRouteOverrides: normalizeLayoutPresetRouteOverrides(account?.layoutPresetRouteOverrides),+ };+};const normalizeWorkbenchState = (state: WorkbenchState): WorkbenchState => ({...state,@@ -2602,6 +2618,11 @@ export const __workbenchReducerInternal = (account: { ...state.account, activeLayoutPresetId: preset.id },};}+ case 'reorderLayoutPresets': {+ const layoutPresetOrder = reorderLayoutPresetIds(state.account, action.activeId, action.overId);++ return layoutPresetOrder ? { ...state, account: { ...state.account, layoutPresetOrder } } : state;+ }case 'addLayoutPreset': {const activeProject = state.projects.find((project) => project.id === state.activeProjectId);@@ -2629,10 +2650,16 @@ export const __workbenchReducerInternal = (...(state.account.customLayoutPresets ?? []).filter((candidate) => candidate.id !== action.presetId),preset,];+ const layoutPresetOrder = [+ ...getOrderedLayoutPresets(state.account)+ .map(({ id }) => id)+ .filter((id) => id !== preset.id),+ preset.id,+ ];return {...state,- account: { ...state.account, activeLayoutPresetId: preset.id, customLayoutPresets },+ account: { ...state.account, activeLayoutPresetId: preset.id, customLayoutPresets, layoutPresetOrder },};}case 'saveLayoutPreset': {@@ -2748,6 +2775,9 @@ export const __workbenchReducerInternal = (};}case 'deleteLayoutPreset': {+ const layoutPresetOrder = getOrderedLayoutPresets(state.account)+ .map(({ id }) => id)+ .filter((id) => id !== action.presetId);const customLayoutPresets = (state.account.customLayoutPresets ?? []).filter((preset) => preset.id !== action.presetId);@@ -2766,6 +2796,7 @@ export const __workbenchReducerInternal = (? defaultLayoutPreset.id: state.account.activeLayoutPresetId,customLayoutPresets,+ layoutPresetOrder,},projects,};diff --git a/invokeai/frontend/webv2/src/workbench/workbenchStore.test.ts b/invokeai/frontend/webv2/src/workbench/workbenchStore.test.tsindex c625f6b3a5..7f6b8703fc 100644--- a/invokeai/frontend/webv2/src/workbench/workbenchStore.test.ts+++ b/invokeai/frontend/webv2/src/workbench/workbenchStore.test.ts@@ -141,6 +141,14 @@ describe('createWorkbenchStore', () => {});});+ it('reorders presets through the layout capability', () => {+ const store = createWorkbenchStore();++ store.commands.layout.reorderPresets('compose', 'edit');++ expect(store.getSnapshot().account.layoutPresetOrder).toEqual(['edit', 'compose', 'automate']);+ });+it('creates a custom preset with an explicitly selected default route in one command', () => {const store = createWorkbenchStore();const defaultRoute: LayoutPresetRoute = { destination: 'gallery', sourceId: 'workflow' };diff --git a/invokeai/frontend/webv2/src/workbench/workbenchStore.ts b/invokeai/frontend/webv2/src/workbench/workbenchStore.tsindex c80c2c3276..57467a0163 100644--- a/invokeai/frontend/webv2/src/workbench/workbenchStore.ts+++ b/invokeai/frontend/webv2/src/workbench/workbenchStore.ts@@ -255,6 +255,13 @@ const createCommands = (dispatch: WorkbenchDispatch, getState: () => WorkbenchStpresetId,})),+ reorderPresets: command(+ 'reorderLayoutPresets',+ (+ activeId: ActionPayload<'reorderLayoutPresets'>['activeId'],+ overId: ActionPayload<'reorderLayoutPresets'>['overId']+ ) => ({ activeId, overId })+ ),setPresetIcon: command('setLayoutPresetIcon',(presetId: ActionPayload<'setLayoutPresetIcon'>['presetId'], iconId: string) => ({ iconId, presetId })