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
refactor(ui): share routing segments
joshistoastf4877b39530d
diff --git a/invokeai/frontend/webv2/src/workbench/launchpad/intents.ts b/invokeai/frontend/webv2/src/workbench/launchpad/intents.tsindex 1100ca8f83..68c7e6ac04 100644--- a/invokeai/frontend/webv2/src/workbench/launchpad/intents.ts+++ b/invokeai/frontend/webv2/src/workbench/launchpad/intents.ts@@ -5,10 +5,9 @@ import type { BuiltInLayoutPresetId } from '@workbench/layoutContracts';* What the user said they wanted to make, translated into how the editor* should open.*- * A layout preset deliberately does not imply an invocation source — several- * graph widgets are placed in every preset, which is why `builtInLayoutPresets`- * warns against inferring one from the other. An intent therefore names both- * explicitly rather than deriving one from the other.+ * A layout preset supplies the account's default route, while an intent names+ * its source explicitly because it can be more specific. For example, Generate+ * and Upscale share Compose but need different invocation sources.** This is the whole contract behind `/app?new=true&intent=…`: the Launchpad* writes the id into the URL, and the editor's session controller applies itdiff --git a/invokeai/frontend/webv2/src/workbench/layoutPresets.ts b/invokeai/frontend/webv2/src/workbench/layoutPresets.tsindex 2cc64250a5..0351092efe 100644--- a/invokeai/frontend/webv2/src/workbench/layoutPresets.ts+++ b/invokeai/frontend/webv2/src/workbench/layoutPresets.ts@@ -137,10 +137,9 @@ const createPresetDescriptor = ({});/**- * The three shipped presets. Each is an arrangement, named for the work it- * supports rather than the widget it happens to open — several graph widgets- * are placed in every one of them, which is exactly why a preset can never- * imply an invocation source.+ * The three shipped presets. Each combines an arrangement with an editable+ * default route. The route is explicit preset data rather than something+ * inferred from whichever graph widgets happen to be placed in the layout.*/export const builtInLayoutPresetDescriptors: BuiltInLayoutPresetDescriptor[] = [createPresetDescriptor({diff --git a/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetDialog.tsx b/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetDialog.tsxindex 453f3251f8..f60214214a 100644--- a/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetDialog.tsx+++ b/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetDialog.tsx@@ -11,7 +11,6 @@ import {Icon,Input,Portal,- SegmentGroup,SimpleGrid,Stack,Text,@@ -22,7 +21,6 @@ import { Select } from '@platform/ui/Select';import { Tooltip } from '@platform/ui/Tooltip';import { getNaturalDestination } from '@workbench/graphWidgets';import { WidgetIcon } from '@workbench/iconResolver';-import { getDestinationLabel, resultDestinations } from '@workbench/invocation';import { getWidgetById } from '@workbench/widgetRegistry';import { useCallback, useMemo, useRef, useState } from 'react';import { useTranslation } from 'react-i18next';@@ -31,12 +29,9 @@ import type { LayoutPresetDialogValue } from './layoutPresetDialogModel';import { getInitialLayoutPresetIconId, getInitialLayoutPresetRoute } from './layoutPresetDialogModel';import { layoutPresetIconGroups } from './layoutPresetIcons';+import { RoutingDestinationSegments } from './RoutingDestinationSegments';const layoutPresetIconIds = layoutPresetIconGroups.flatMap((group) => group.options.map((option) => option.id));-const destinationWidgetTypeIds: Record<ResultDestination, 'canvas' | 'gallery'> = {- canvas: 'canvas',- gallery: 'gallery',-};type SourceSelectItem = GraphWidgetSource & { value: InvocationSourceId };@@ -174,12 +169,8 @@ export const LayoutPresetDialog = ({sourceId,}));}, []);- const handleDestinationChange = useCallback((event: { value: string | null }) => {- if (!event.value) {- return;- }-- setDefaultRoute((route) => (route ? { ...route, destination: event.value as ResultDestination } : route));+ const handleDestinationChange = useCallback((destination: ResultDestination) => {+ setDefaultRoute((route) => (route ? { ...route, destination } : route));}, []);return (@@ -257,27 +248,12 @@ export const LayoutPresetDialog = ({/></Field><Field disabled={!defaultRoute} label={t('topbar.presets.defaultDestination')}>- <SegmentGroup.Root- aria-label={t('topbar.presets.defaultDestination')}+ <RoutingDestinationSegments+ ariaLabel={t('topbar.presets.defaultDestination')}disabled={!defaultRoute}- size="xs"value={defaultRoute?.destination ?? null}- onValueChange={handleDestinationChange}- >- <SegmentGroup.Indicator />- {resultDestinations.map((destination) => (- <SegmentGroup.Item key={destination.id} flex="1" justifyContent="center" value={destination.id}>- <SegmentGroup.ItemHiddenInput />- <SegmentGroup.ItemText display="flex" alignItems="center" gap="1.5">- <WidgetIcon- boxSize="3.5"- icon={getWidgetById(destinationWidgetTypeIds[destination.id])?.manifest.icon}- />- {getDestinationLabel(destination.id)}- </SegmentGroup.ItemText>- </SegmentGroup.Item>- ))}- </SegmentGroup.Root>+ onChange={handleDestinationChange}+ /></Field></Stack></Dialog.Body>diff --git a/invokeai/frontend/webv2/src/workbench/shell/topbar/RoutingControl.tsx b/invokeai/frontend/webv2/src/workbench/shell/topbar/RoutingControl.tsxindex 7ce20b1c01..3a05ad11e1 100644--- a/invokeai/frontend/webv2/src/workbench/shell/topbar/RoutingControl.tsx+++ b/invokeai/frontend/webv2/src/workbench/shell/topbar/RoutingControl.tsx@@ -1,13 +1,12 @@import type { GraphWidgetSource } from '@workbench/graphWidgets';import type { InvocationSourceId, ResultDestination } from '@workbench/invocationContracts';-import { Box, Icon, Menu, Portal, SegmentGroup, Stack, Status, Text } from '@chakra-ui/react';+import { Box, Icon, Menu, Portal, Stack, Status, Text } from '@chakra-ui/react';import { Button } from '@platform/ui/Button';import { MenuContent } from '@platform/ui/Menu';import { Tooltip } from '@platform/ui/Tooltip';import { describeRoute, getWidgetTypeIdForSourceId } from '@workbench/graphWidgets';import { WidgetIcon } from '@workbench/iconResolver';-import { getDestinationLabel, resultDestinations } from '@workbench/invocation';import { getWidgetById } from '@workbench/widgetRegistry';import { useWorkbenchCommands } from '@workbench/WorkbenchContext';import { LockKeyholeIcon, UnlockKeyholeIcon } from 'lucide-react';@@ -16,6 +15,8 @@ import { useTranslation } from 'react-i18next';import type { InvocationState } from './useInvocationState';+import { RoutingDestinationSegments } from './RoutingDestinationSegments';+const MENU_POSITIONING = { placement: 'bottom-end' } as const;const destinationWidgetTypeIds: Record<ResultDestination, 'canvas' | 'gallery'> = {@@ -167,31 +168,15 @@ const DestinationSegments = ({ destination }: { destination: ResultDestination }const { generation } = useWorkbenchCommands();const { t } = useTranslation();const handleChange = useCallback(- (event: { value: string | null }) => {- if (event.value) {- generation.setDestination(event.value as ResultDestination);- }- },+ (nextDestination: ResultDestination) => generation.setDestination(nextDestination),[generation]);return (- <SegmentGroup.Root- aria-label={t('topbar.routing.destination')}- size="xs"+ <RoutingDestinationSegments+ ariaLabel={t('topbar.routing.destination')}value={destination}- onValueChange={handleChange}- >- <SegmentGroup.Indicator />- {resultDestinations.map((option) => (- <SegmentGroup.Item key={option.id} flex="1" justifyContent="center" value={option.id}>- <SegmentGroup.ItemHiddenInput />- <SegmentGroup.ItemText display="flex" alignItems="center" gap="1.5">- <WidgetIcon boxSize="3.5" icon={getWidgetById(destinationWidgetTypeIds[option.id])?.manifest.icon} />- {getDestinationLabel(option.id)}- </SegmentGroup.ItemText>- </SegmentGroup.Item>- ))}- </SegmentGroup.Root>+ onChange={handleChange}+ />);};diff --git a/invokeai/frontend/webv2/src/workbench/shell/topbar/RoutingDestinationSegments.tsx b/invokeai/frontend/webv2/src/workbench/shell/topbar/RoutingDestinationSegments.tsxnew file mode 100644index 0000000000..4329408b35--- /dev/null+++ b/invokeai/frontend/webv2/src/workbench/shell/topbar/RoutingDestinationSegments.tsx@@ -0,0 +1,48 @@+import type { ResultDestination } from '@workbench/invocationContracts';++import { SegmentGroup } from '@chakra-ui/react';+import { WidgetIcon } from '@workbench/iconResolver';+import { getDestinationLabel, resultDestinations } from '@workbench/invocation';+import { getWidgetById } from '@workbench/widgetRegistry';+import { useCallback } from 'react';++const destinationWidgetTypeIds: Record<ResultDestination, 'canvas' | 'gallery'> = {+ canvas: 'canvas',+ gallery: 'gallery',+};++export const RoutingDestinationSegments = ({+ ariaLabel,+ disabled,+ onChange,+ value,+}: {+ ariaLabel: string;+ disabled?: boolean;+ onChange: (destination: ResultDestination) => void;+ value: ResultDestination | null;+}) => {+ const handleChange = useCallback(+ (event: { value: string | null }) => {+ if (event.value) {+ onChange(event.value as ResultDestination);+ }+ },+ [onChange]+ );++ return (+ <SegmentGroup.Root aria-label={ariaLabel} disabled={disabled} size="xs" value={value} onValueChange={handleChange}>+ <SegmentGroup.Indicator />+ {resultDestinations.map((destination) => (+ <SegmentGroup.Item key={destination.id} flex="1" justifyContent="center" value={destination.id}>+ <SegmentGroup.ItemHiddenInput />+ <SegmentGroup.ItemText display="flex" alignItems="center" gap="1.5">+ <WidgetIcon boxSize="3.5" icon={getWidgetById(destinationWidgetTypeIds[destination.id])?.manifest.icon} />+ {getDestinationLabel(destination.id)}+ </SegmentGroup.ItemText>+ </SegmentGroup.Item>+ ))}+ </SegmentGroup.Root>+ );+};diff --git a/invokeai/frontend/webv2/src/workbench/workbenchStore.ts b/invokeai/frontend/webv2/src/workbench/workbenchStore.tsindex 713d5c61f5..79e0a9ec91 100644--- a/invokeai/frontend/webv2/src/workbench/workbenchStore.ts+++ b/invokeai/frontend/webv2/src/workbench/workbenchStore.ts@@ -299,7 +299,7 @@ const createCommands = (savePreset: command('saveLayoutPreset', (presetId: ActionPayload<'saveLayoutPreset'>['presetId']) => ({presetId,})),- /** Drops saved edits to a built-in preset, restoring its shipped arrangement. */+ /** Drops saved arrangement, identity, and route edits from a built-in preset. */restorePresetDefault: command('restoreLayoutPresetDefault',(presetId: ActionPayload<'restoreLayoutPresetDefault'>['presetId']) => ({ presetId })