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): redesign SAM tool options

joshistoast89138bc57aa3
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.json
index 99b9d899e1..c1c38dafa0 100644
--- a/invokeai/frontend/webv2/public/locales/en.json
+++ b/invokeai/frontend/webv2/public/locales/en.json
@@ -1327,7 +1327,7 @@
},
"selectObject": {
"autoProcess": "Auto Process",
- "autoProcessCompact": "Auto",
+ "bbox": "BBox",
"bboxActive": "Bounding box active",
"bboxInactive": "No bounding box",
"errorDecode": "The object preview could not be decoded.",
@@ -1347,7 +1347,6 @@
"includeCount": "Include {{count}}",
"invert": "Invert",
"isolatedPreview": "Isolated Preview",
- "isolatedPreviewCompact": "Isolate",
"model": "Model",
"modelHuge": "SAM Huge",
"modelSam2Large": "SAM 2 Large",
@@ -1364,6 +1363,7 @@
"saveAs_inpaint_mask": "Inpaint mask",
"saveAs_raster": "Raster layer",
"saveAs_regional_guidance": "Regional guidance",
+ "settings": "Select Object settings",
"sourceDimensions": "{{width}} × {{height}}",
"sourceDimensionsLabel": "Generation area: {{width}} × {{height}}",
"statusCommitting": "Applying object result…",
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/CanvasBottomOverlay.test.tsx b/invokeai/frontend/webv2/src/workbench/widgets/canvas/CanvasBottomOverlay.test.tsx
index ed826d0ae1..964abaffd0 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/CanvasBottomOverlay.test.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/CanvasBottomOverlay.test.tsx
@@ -42,7 +42,7 @@ describe('CanvasBottomOverlay', () => {
<CanvasBottomOverlay.Root data-layout="overlay">
<CanvasBottomOverlay.Staging data-layout="staging">Staging</CanvasBottomOverlay.Staging>
<CanvasBottomOverlay.Controls data-layout="controls">
- <CanvasOperationPanel.Root aria-label="Filter" operation="filter">
+ <CanvasOperationPanel.Root aria-label="Filter">
<CanvasOperationPanel.Header>Header</CanvasOperationPanel.Header>
<CanvasOperationPanel.Body>{'Large body '.repeat(500)}</CanvasOperationPanel.Body>
<CanvasOperationPanel.Feedback>Ready</CanvasOperationPanel.Feedback>
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/CanvasOperationBar.tsx b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/CanvasOperationBar.tsx
index a3c312a333..240a0af1fd 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/CanvasOperationBar.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/CanvasOperationBar.tsx
@@ -4,7 +4,11 @@ import type { CanvasEngine } from '@workbench/canvas-engine/engine';
import { FilterOptions } from './FilterOptions';
import { SamOptions } from './SamOptions';
-/** Bottom-center controls for the active guarded operation, independent of temporary tools. */
+/**
+ * Bottom-center controls for the active guarded operation, independent of
+ * temporary tools. Select Object renders single-row bar chrome (like the
+ * per-tool options bars); Filter renders the full operation panel.
+ */
export const CanvasOperationBar = ({
engine,
isExternalInteractionLocked,
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/CanvasOperationPanel.test.tsx b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/CanvasOperationPanel.test.tsx
index 5fd4061bc6..31079335ac 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/CanvasOperationPanel.test.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/CanvasOperationPanel.test.tsx
@@ -9,7 +9,6 @@ import {
CANVAS_OPERATION_FOOTER_LAYOUT,
CANVAS_OPERATION_PANEL_LAYOUT,
CANVAS_OPERATION_SLOT_LAYOUT,
- CANVAS_SELECT_OBJECT_PANEL_LAYOUT,
CanvasOperationPanel,
} from './CanvasOperationPanel';
@@ -17,9 +16,9 @@ describe('CanvasOperationPanel', () => {
it('renders the operation panel slots as semantic regions in stable order', () => {
const markup = renderToStaticMarkup(
<ChakraProvider value={system}>
- <CanvasOperationPanel.Root aria-labelledby="operation-title" operation="select-object">
+ <CanvasOperationPanel.Root aria-labelledby="operation-title">
<CanvasOperationPanel.Header>
- <h2 id="operation-title">Select Object</h2>
+ <h2 id="operation-title">Filter</h2>
</CanvasOperationPanel.Header>
<CanvasOperationPanel.Body>Inputs</CanvasOperationPanel.Body>
<CanvasOperationPanel.Feedback>Status</CanvasOperationPanel.Feedback>
@@ -33,7 +32,7 @@ describe('CanvasOperationPanel', () => {
expect(markup).toContain('role="region"');
expect(markup).toContain('aria-labelledby="operation-title"');
- expect(markup).toContain('data-operation="select-object"');
+ expect(markup).toContain('data-operation="filter"');
expect(markup).toContain('data-slot="header"');
expect(markup).toContain('data-slot="body"');
expect(markup).toContain('data-slot="feedback"');
@@ -55,19 +54,6 @@ describe('CanvasOperationPanel', () => {
w: '30rem',
});
expect(CANVAS_OPERATION_FOOTER_LAYOUT).toMatchObject({ flexWrap: 'wrap', minW: '0' });
- });
-
- it('gives Select Object a compact 26.25rem variant without changing Filter', () => {
- expect(CANVAS_SELECT_OBJECT_PANEL_LAYOUT).toEqual({
- flex: '0 1 26.25rem',
- maxH: 'full',
- maxW: 'full',
- minH: '0',
- minW: '0',
- overflow: 'hidden',
- w: '26.25rem',
- });
- expect(CANVAS_OPERATION_PANEL_LAYOUT.w).toBe('30rem');
expect(CANVAS_OPERATION_SLOT_LAYOUT).toEqual({ px: '4', py: '3' });
});
@@ -81,7 +67,7 @@ describe('CanvasOperationPanel', () => {
expect(CANVAS_OPERATION_FIXED_SECTION_LAYOUT).toEqual({ flexShrink: '0' });
const markup = renderToStaticMarkup(
<ChakraProvider value={system}>
- <CanvasOperationPanel.Root aria-label="Filter" operation="filter">
+ <CanvasOperationPanel.Root aria-label="Filter">
<CanvasOperationPanel.Header>Filter</CanvasOperationPanel.Header>
<CanvasOperationPanel.Body>Parameters</CanvasOperationPanel.Body>
<CanvasOperationPanel.Feedback>Ready</CanvasOperationPanel.Feedback>
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/CanvasOperationPanel.tsx b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/CanvasOperationPanel.tsx
index 0e9f1fde57..3685f635e3 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/CanvasOperationPanel.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/CanvasOperationPanel.tsx
@@ -2,9 +2,6 @@ import type { BoxProps, FlexProps } from '@chakra-ui/react';
import { Box, Flex } from '@chakra-ui/react';
import { Panel } from '@workbench/components/ui';
-import { createContext, useContext } from 'react';
-
-type Operation = 'filter' | 'select-object';
export const CANVAS_OPERATION_PANEL_LAYOUT = {
flex: '0 1 30rem',
@@ -16,16 +13,6 @@ export const CANVAS_OPERATION_PANEL_LAYOUT = {
w: '30rem',
} satisfies BoxProps;
-export const CANVAS_SELECT_OBJECT_PANEL_LAYOUT = {
- flex: '0 1 26.25rem',
- maxH: 'full',
- maxW: 'full',
- minH: '0',
- minW: '0',
- overflow: 'hidden',
- w: '26.25rem',
-} satisfies BoxProps;
-
export const CANVAS_OPERATION_SLOT_LAYOUT = {
px: '4',
py: '3',
@@ -45,73 +32,56 @@ export const CANVAS_OPERATION_BODY_LAYOUT = {
export const CANVAS_OPERATION_FIXED_SECTION_LAYOUT = { flexShrink: '0' } satisfies BoxProps;
-const OperationContext = createContext<Operation>('filter');
-
-const Root = ({ children, operation, ...rest }: BoxProps & { operation: Operation }) => {
- const layout = operation === 'select-object' ? CANVAS_SELECT_OBJECT_PANEL_LAYOUT : CANVAS_OPERATION_PANEL_LAYOUT;
- return (
- <OperationContext value={operation}>
- <Panel
- data-operation={operation}
- density="none"
- display="flex"
- flexDirection="column"
- pointerEvents="auto"
- role="region"
- rounded="xl"
- shadow="lg"
- tone="raised"
- {...layout}
- {...rest}
- >
- {children}
- </Panel>
- </OperationContext>
- );
-};
+const Root = ({ children, ...rest }: BoxProps) => (
+ <Panel
+ data-operation="filter"
+ density="none"
+ display="flex"
+ flexDirection="column"
+ pointerEvents="auto"
+ role="region"
+ rounded="xl"
+ shadow="lg"
+ tone="raised"
+ {...CANVAS_OPERATION_PANEL_LAYOUT}
+ {...rest}
+ >
+ {children}
+ </Panel>
+);
-const Header = (props: BoxProps) => {
- const operation = useContext(OperationContext);
- return (
- <Box
- as="header"
- borderBottomWidth={operation === 'select-object' ? undefined : '1px'}
- data-slot="header"
- {...CANVAS_OPERATION_SLOT_LAYOUT}
- {...CANVAS_OPERATION_FIXED_SECTION_LAYOUT}
- {...props}
- />
- );
-};
+const Header = (props: BoxProps) => (
+ <Box
+ as="header"
+ borderBottomWidth="1px"
+ data-slot="header"
+ {...CANVAS_OPERATION_SLOT_LAYOUT}
+ {...CANVAS_OPERATION_FIXED_SECTION_LAYOUT}
+ {...props}
+ />
+);
-const Body = (props: BoxProps) => {
- const operation = useContext(OperationContext);
- return (
- <Box
- data-scroll-container="body"
- data-slot="body"
- {...CANVAS_OPERATION_SLOT_LAYOUT}
- {...CANVAS_OPERATION_BODY_LAYOUT}
- flex={operation === 'select-object' ? '0 1 auto' : CANVAS_OPERATION_BODY_LAYOUT.flex}
- {...props}
- />
- );
-};
+const Body = (props: BoxProps) => (
+ <Box
+ data-scroll-container="body"
+ data-slot="body"
+ {...CANVAS_OPERATION_SLOT_LAYOUT}
+ {...CANVAS_OPERATION_BODY_LAYOUT}
+ {...props}
+ />
+);
-const Feedback = (props: BoxProps) => {
- const operation = useContext(OperationContext);
- return (
- <Box
- borderTopWidth={operation === 'select-object' ? undefined : '1px'}
- data-slot="feedback"
- minH={operation === 'select-object' ? undefined : '16'}
- px="4"
- py="2"
- {...CANVAS_OPERATION_FIXED_SECTION_LAYOUT}
- {...props}
- />
- );
-};
+const Feedback = (props: BoxProps) => (
+ <Box
+ borderTopWidth="1px"
+ data-slot="feedback"
+ minH="16"
+ px="4"
+ py="2"
+ {...CANVAS_OPERATION_FIXED_SECTION_LAYOUT}
+ {...props}
+ />
+);
const Footer = (props: FlexProps) => (
<Flex
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/FilterOptions.tsx b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/FilterOptions.tsx
index 3317d6a940..c5d9c478cf 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/FilterOptions.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/FilterOptions.tsx
@@ -127,7 +127,7 @@ export const FilterOptions = ({
};
return (
- <CanvasOperationPanel.Root aria-labelledby="filter-operation-title" operation="filter">
+ <CanvasOperationPanel.Root aria-labelledby="filter-operation-title">
<CanvasOperationPanel.Header>
<FilterPanelHeading
layerName={session.layerName}
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/SamOptions.test.ts b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/SamOptions.test.ts
index cac536a639..3067464d18 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/SamOptions.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/SamOptions.test.ts
@@ -15,20 +15,11 @@ import {
getSamActionHandlers,
getSamErrorTranslationKey,
getSamStatusTranslationKey,
- SAM_COMPACT_BUTTON_LAYOUT,
- SAM_COMPACT_CONTROL_LAYOUT,
- SAM_COMPACT_FOOTER_LAYOUT,
- SAM_COMPACT_GROUP_LAYOUT,
- SAM_COMPACT_SLOT_LAYOUT,
- SAM_COMPACT_SWITCH_LAYOUT,
- SAM_MODEL_SELECT_LAYOUT,
- SAM_VISUAL_BUTTON_LAYOUT,
SamPromptBody,
SamModeToggle,
- SamOptionsPanel,
- SamProcessFeedback,
- SamSwitch,
- SamVisualBody,
+ SamOptionsBar,
+ SamStatusSlot,
+ SamVisualInput,
} from './SamOptions';
const englishCatalogModules = import.meta.glob('../../../../../public/locales/en.json', {
@@ -179,36 +170,6 @@ describe('getSamPanelViewModel', () => {
});
describe('SamModeToggle', () => {
- it('uses compact controls and wraps only when the card runs out of inline space', () => {
- expect(SAM_COMPACT_CONTROL_LAYOUT).toEqual({ h: '8', minH: '8', size: 'xs' });
- expect(SAM_COMPACT_BUTTON_LAYOUT).toEqual({ h: '8', minH: '8', px: '2', size: 'xs' });
- expect(SAM_COMPACT_FOOTER_LAYOUT).toMatchObject({ flexWrap: 'wrap', gap: '1' });
- expect(SAM_COMPACT_GROUP_LAYOUT).toEqual({ maxW: 'full', minW: '0' });
- expect(SAM_COMPACT_SLOT_LAYOUT).toEqual({ px: '3', py: '2' });
- expect(SAM_COMPACT_SWITCH_LAYOUT).toEqual({ flex: '0 1 auto', maxW: 'full', minW: '0' });
- expect(SAM_VISUAL_BUTTON_LAYOUT).toMatchObject({ fontSize: '2xs', px: '1' });
- expect(SAM_MODEL_SELECT_LAYOUT).toEqual({ flex: '0 1 11rem', maxW: 'full', minW: '0', w: '11rem' });
- });
-
- it('renders compact switch copy with the full localized accessible name', () => {
- const markup = renderToStaticMarkup(
- createElement(
- ChakraProvider,
- { value: system } as ComponentProps<typeof ChakraProvider>,
- createElement(SamSwitch, {
- accessibleLabel: 'Auto Process',
- checked: false,
- disabled: false,
- label: 'Auto',
- onChange: () => undefined,
- })
- )
- );
-
- expect(markup).toContain('>Auto<');
- expect(markup).toContain('aria-label="Auto Process"');
- });
-
it('uses ordinary pressed buttons without incomplete tab relationships', () => {
const markup = renderToStaticMarkup(
createElement(
@@ -233,7 +194,7 @@ describe('SamModeToggle', () => {
});
});
-describe('SamProcessFeedback', () => {
+describe('SamStatusSlot', () => {
it.each([
'ready',
'scheduled',
@@ -274,7 +235,7 @@ describe('SamProcessFeedback', () => {
createElement(
ChakraProvider,
{ value: system } as ComponentProps<typeof ChakraProvider>,
- createElement(SamProcessFeedback, {
+ createElement(SamStatusSlot, {
error: null,
errorText: null,
isBusy: true,
@@ -290,18 +251,25 @@ describe('SamProcessFeedback', () => {
expect(markup).not.toContain('role="alert"');
});
- it('renders nothing when ready without an error', () => {
+ it('reserves an empty polite live region when ready without an error', () => {
const markup = renderToStaticMarkup(
- createElement(SamProcessFeedback, {
- error: null,
- errorText: null,
- isBusy: false,
- statusText: 'Ready',
- technicalDetailsLabel: 'Technical details',
- })
+ createElement(
+ ChakraProvider,
+ { value: system } as ComponentProps<typeof ChakraProvider>,
+ createElement(SamStatusSlot, {
+ error: null,
+ errorText: null,
+ isBusy: false,
+ statusText: 'Ready',
+ technicalDetailsLabel: 'Technical details',
+ })
+ )
);
- expect(markup).toBe('');
+ expect(markup).toContain('role="status"');
+ expect(markup).toContain('aria-live="polite"');
+ expect(markup).not.toContain('Ready');
+ expect(markup).not.toContain('role="alert"');
});
it('server-renders a known localized error as the assertive primary message', () => {
@@ -309,7 +277,7 @@ describe('SamProcessFeedback', () => {
createElement(
ChakraProvider,
{ value: system } as ComponentProps<typeof ChakraProvider>,
- createElement(SamProcessFeedback, {
+ createElement(SamStatusSlot, {
error: { code: 'decode' },
errorText: 'The object preview could not be decoded.',
isBusy: false,
@@ -329,7 +297,7 @@ describe('SamProcessFeedback', () => {
createElement(
ChakraProvider,
{ value: system } as ComponentProps<typeof ChakraProvider>,
- createElement(SamProcessFeedback, {
+ createElement(SamStatusSlot, {
error: { code: 'unknown', detail: 'GPU worker disconnected' },
errorText: 'Select Object could not finish.',
isBusy: false,
@@ -353,7 +321,7 @@ describe('SamProcessFeedback', () => {
createElement(
ChakraProvider,
{ value: system } as ComponentProps<typeof ChakraProvider>,
- createElement(SamProcessFeedback, {
+ createElement(SamStatusSlot, {
error: { code: 'queue', detail: 'AttributeError' },
errorText,
isBusy: false,
@@ -371,19 +339,21 @@ describe('SamProcessFeedback', () => {
});
});
-describe('compact SAM inputs', () => {
- it('uses compact model-row copy without the removed stacked section heading', () => {
+describe('single-row SAM inputs', () => {
+ it('uses bar-scale copy including the settings popover and bbox indicator labels', () => {
expect(en.widgets.layers.selectObject.model).toBe('Model');
expect(en.widgets.layers.selectObject.refine).toBe('Refine');
- expect(en.widgets.layers.selectObject.autoProcessCompact).toBe('Auto');
- expect(en.widgets.layers.selectObject.isolatedPreviewCompact).toBe('Isolate');
+ expect(en.widgets.layers.selectObject.autoProcess).toBe('Auto Process');
+ expect(en.widgets.layers.selectObject.isolatedPreview).toBe('Isolated Preview');
+ expect(en.widgets.layers.selectObject.settings).toBe('Select Object settings');
+ expect(en.widgets.layers.selectObject.bbox).toBe('BBox');
expect(en.widgets.layers.selectObject.technicalDetails).toBe('Technical details');
expect(en.widgets.layers.selectObject.sourceDimensions).toBe('{{width}} × {{height}}');
expect(en.widgets.layers.selectObject.sourceDimensionsLabel).toContain('{{width}}');
expect(en.widgets.layers.selectObject.includeCount).toBe('Include {{count}}');
expect(en.widgets.layers.selectObject.excludeCount).toBe('Exclude {{count}}');
- expect(en.widgets.layers.selectObject).not.toHaveProperty('modelAndRefinement');
- expect(en.widgets.layers.selectObject).not.toHaveProperty('sourceSummary');
+ expect(en.widgets.layers.selectObject).not.toHaveProperty('autoProcessCompact');
+ expect(en.widgets.layers.selectObject).not.toHaveProperty('isolatedPreviewCompact');
});
it('server-renders Prompt as a one-line accessible input', () => {
@@ -403,7 +373,7 @@ describe('compact SAM inputs', () => {
expect(markup).not.toContain('<textarea');
});
- it('server-renders the visual controls as one labeled row without permanent guidance', () => {
+ it('server-renders the visual controls as one labeled group without permanent guidance', () => {
const session = snapshot({
input: {
bbox: { height: 8, width: 12, x: 1, y: 2 },
@@ -416,19 +386,21 @@ describe('compact SAM inputs', () => {
createElement(
ChakraProvider,
{ value: system } as ComponentProps<typeof ChakraProvider>,
- createElement(SamVisualBody, {
- disabled: false,
- onExclude: () => undefined,
- onInclude: () => undefined,
- session: session as SamSessionSnapshot & {
- input: Extract<SamSessionSnapshot['input'], { type: 'visual' }>;
- },
- viewModel: getSamPanelViewModel(
- session,
- (width, height) => `${width} × ${height}`,
- (width, height) => `Generation area ${width} × ${height}`
- ),
- })
+ createElement(
+ I18nextProvider,
+ { i18n: testI18n },
+ createElement(SamVisualInput, {
+ disabled: false,
+ onExclude: () => undefined,
+ onInclude: () => undefined,
+ pointLabel: session.pointLabel,
+ viewModel: getSamPanelViewModel(
+ session,
+ (width, height) => `${width} × ${height}`,
+ (width, height) => `Generation area ${width} × ${height}`
+ ),
+ })
+ )
)
);
@@ -437,12 +409,15 @@ describe('compact SAM inputs', () => {
expect(markup).not.toContain('title=');
expect(markup).toContain('aria-describedby="sam-visual-guidance"');
expect(markup).toContain('id="sam-visual-guidance"');
+ expect(markup).toContain('Include 1');
+ expect(markup).toContain('Exclude 1');
+ expect(markup).toContain('Bounding box active');
expect(markup).not.toContain('>widgets.layers.selectObject.pointType<');
});
});
describe('getSamActionHandlers', () => {
- it('wires every compact footer action and save target to the engine', () => {
+ it('wires every bar action and save target to the engine', () => {
const engine = {
applySelectObjectSession: vi.fn(),
cancelSelectObjectSession: vi.fn(),
@@ -472,8 +447,8 @@ describe('getSamActionHandlers', () => {
});
});
-describe('SamOptionsPanel', () => {
- it('server-renders the compact ready state in semantic order with one footer action row', () => {
+describe('SamOptionsBar', () => {
+ it('server-renders one row of controls in stable order without panel slots', () => {
const engine = {
applySelectObjectSession: vi.fn(),
cancelSelectObjectSession: vi.fn(),
@@ -489,7 +464,7 @@ describe('SamOptionsPanel', () => {
createElement(
I18nextProvider,
{ i18n: testI18n },
- createElement(SamOptionsPanel, {
+ createElement(SamOptionsBar, {
engine: engine as never,
session: snapshot({
hasPreview: true,
@@ -501,15 +476,20 @@ describe('SamOptionsPanel', () => {
)
);
- expect(markup.indexOf('data-slot="header"')).toBeLessThan(markup.indexOf('data-slot="body"'));
- expect(markup.indexOf('data-slot="body"')).toBeLessThan(markup.indexOf('data-slot="footer"'));
- expect(markup).not.toContain('data-slot="feedback"');
- expect(markup).toContain('>Auto<');
- expect(markup).toContain('>Isolate<');
- expect(markup).toContain('aria-label="Generation area: 1024 × 768"');
+ expect(markup).not.toContain('data-slot="header"');
+ expect(markup).not.toContain('data-slot="body"');
+ expect(markup).not.toContain('data-slot="footer"');
+ expect(markup).not.toContain('data-operation=');
+ expect(markup).toContain('Generation area: 1024 × 768');
+ expect(markup).toContain('aria-label="Select Object settings"');
+ expect(markup).toContain('aria-label="Save As"');
+ expect(markup.indexOf('>Visual<')).toBeLessThan(markup.indexOf('Include 1'));
+ expect(markup.indexOf('Include 1')).toBeLessThan(markup.indexOf('>Invert<'));
+ expect(markup.indexOf('>Invert<')).toBeLessThan(markup.indexOf('aria-label="Select Object settings"'));
+ expect(markup.indexOf('aria-label="Select Object settings"')).toBeLessThan(markup.indexOf('>Process<'));
expect(markup.indexOf('>Process<')).toBeLessThan(markup.indexOf('>Reset<'));
expect(markup.indexOf('>Reset<')).toBeLessThan(markup.indexOf('>Apply<'));
- expect(markup.indexOf('>Apply<')).toBeLessThan(markup.indexOf('Save As'));
- expect(markup.indexOf('Save As')).toBeLessThan(markup.indexOf('>Cancel<'));
+ expect(markup.indexOf('>Apply<')).toBeLessThan(markup.indexOf('aria-label="Save As"'));
+ expect(markup.indexOf('aria-label="Save As"')).toBeLessThan(markup.indexOf('>Cancel<'));
});
});
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/SamOptions.tsx b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/SamOptions.tsx
index 48d78caa36..fd2a30196e 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/SamOptions.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/canvas/tool-options/SamOptions.tsx
@@ -1,18 +1,18 @@
-import type { FlexProps } from '@chakra-ui/react';
/* oxlint-disable react-perf/jsx-no-jsx-as-prop, react-perf/jsx-no-new-function-as-prop, react-perf/jsx-no-new-object-as-prop */
import type { SelectObjectSaveTarget } from '@workbench/canvas-engine/engine';
import type { SamSessionError, SamSessionErrorCode, SamSessionSnapshot } from '@workbench/canvas-engine/engineStores';
import type { SamModel } from '@workbench/generation/canvas/samGraph';
-import type { ChangeEvent } from 'react';
+import type { ChangeEvent, CSSProperties } from 'react';
import {
Flex,
Group,
- Heading,
+ HStack,
IconButton,
Input,
Menu,
NativeSelect,
+ Popover,
Portal,
Spinner,
Stack,
@@ -23,14 +23,13 @@ import {
import { Button, MenuContent, Tooltip } from '@workbench/components/ui';
import { makeImageDurable } from '@workbench/gallery/api';
import { isSamDocumentInputValid } from '@workbench/generation/canvas/samGraph';
+import { CanvasFloatingBar, CanvasFloatingBarDivider } from '@workbench/widgets/canvas/CanvasFloatingBar';
import { useSamSession } from '@workbench/widgets/canvas/engineStoreHooks';
-import { ChevronDownIcon, InfoIcon } from 'lucide-react';
+import { ChevronDownIcon, InfoIcon, SettingsIcon } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import type { ToolOptionsComponentProps } from './ToolOptionsBar';
-import { CanvasOperationPanel } from './CanvasOperationPanel';
-
export interface SamActionEligibility {
canApply: boolean;
canCancel: boolean;
@@ -48,26 +47,18 @@ export interface SamPanelViewModel {
sourceSummary: string;
}
-export const SAM_COMPACT_CONTROL_LAYOUT = { h: '8', minH: '8', size: 'xs' } as const;
-export const SAM_COMPACT_BUTTON_LAYOUT = { ...SAM_COMPACT_CONTROL_LAYOUT, px: '2' } as const;
-export const SAM_COMPACT_FOOTER_LAYOUT = { flexWrap: 'wrap', gap: '1' } satisfies FlexProps;
-export const SAM_COMPACT_GROUP_LAYOUT = { maxW: 'full', minW: '0' } as const;
-export const SAM_COMPACT_SLOT_LAYOUT = { px: '3', py: '2' } as const;
-export const SAM_COMPACT_SWITCH_LAYOUT = { flex: '0 1 auto', maxW: 'full', minW: '0' } as const;
-export const SAM_MODEL_SELECT_LAYOUT = { flex: '0 1 11rem', maxW: 'full', minW: '0', w: '11rem' } as const;
-
-const SAM_SEGMENT_BUTTON_LAYOUT = {
- ...SAM_COMPACT_BUTTON_LAYOUT,
- flex: '1 1 0',
- minW: '0',
- overflow: 'hidden',
-} as const;
-
-export const SAM_VISUAL_BUTTON_LAYOUT = { ...SAM_SEGMENT_BUTTON_LAYOUT, fontSize: '2xs', px: '1' } as const;
-
const SAM_PROMPT_GUIDANCE_ID = 'sam-prompt-guidance';
const SAM_VISUAL_GUIDANCE_ID = 'sam-visual-guidance';
+const SAM_UPWARD_POSITIONING = { placement: 'top-end' } as const;
+
+const SAM_ERROR_CLAMP_STYLE: CSSProperties = {
+ display: '-webkit-box',
+ overflow: 'hidden',
+ WebkitBoxOrient: 'vertical',
+ WebkitLineClamp: 2,
+};
+
const SAM_STATUS_TRANSLATION_KEYS: Record<SamSessionSnapshot['status'], string> = {
committing: 'widgets.layers.selectObject.statusCommitting',
error: 'widgets.layers.selectObject.statusError',
@@ -95,6 +86,12 @@ const SAM_ERROR_TRANSLATION_KEYS: Record<SamSessionErrorCode, string> = {
const SAVE_TARGETS: readonly SelectObjectSaveTarget[] = ['raster', 'control', 'inpaint_mask', 'regional_guidance'];
+const isSamProcessingStatus = (status: SamSessionSnapshot['status']): boolean =>
+ status === 'preparing-composite' ||
+ status === 'uploading' ||
+ status === 'processing-sam' ||
+ status === 'rendering-preview';
+
export const getSamStatusTranslationKey = (status: SamSessionSnapshot['status']): string =>
SAM_STATUS_TRANSLATION_KEYS[status];
@@ -112,7 +109,12 @@ export const getSamPanelViewModel = (
sourceSummary: formatSourceSummary(session.sourceRect.width, session.sourceRect.height),
});
-export const SamProcessFeedback = ({
+/**
+ * The always-mounted status slot: reserves its width so status/error text
+ * appearing never shifts the surrounding controls, and keeps the polite live
+ * region in the tree before content arrives so announcements are reliable.
+ */
+export const SamStatusSlot = ({
error,
errorText,
isBusy,
@@ -126,35 +128,41 @@ export const SamProcessFeedback = ({
technicalDetailsLabel: string;
}) => {
const detail = error?.detail?.trim();
- if (error && errorText) {
- return (
- <Flex align="center" gap="1" minW="0">
- <span
- aria-live="assertive"
- role="alert"
- style={{ WebkitBoxOrient: 'vertical', WebkitLineClamp: 2, display: '-webkit-box', overflow: 'hidden' }}
- >
- {errorText}
- </span>
- {detail && detail !== errorText ? (
- <Tooltip content={detail}>
- <IconButton aria-label={technicalDetailsLabel} flexShrink="0" size="xs" tabIndex={0} variant="ghost">
- <InfoIcon />
- </IconButton>
- </Tooltip>
- ) : null}
- </Flex>
- );
- }
- if (isBusy) {
- return (
- <Flex align="center" aria-live="polite" gap="2" role="status">
- <Spinner boxSize="5" flexShrink="0" />
- <span>{statusText}</span>
- </Flex>
- );
- }
- return null;
+ return (
+ <Flex
+ align="center"
+ color={error ? 'fg.error' : 'fg.muted'}
+ flex="0 1 auto"
+ fontSize="xs"
+ gap="1"
+ maxW="16rem"
+ minW="8rem"
+ >
+ {error && errorText ? (
+ <>
+ <span aria-live="assertive" role="alert" style={SAM_ERROR_CLAMP_STYLE}>
+ {errorText}
+ </span>
+ {detail && detail !== errorText ? (
+ <Tooltip content={detail}>
+ <IconButton aria-label={technicalDetailsLabel} flexShrink="0" size="xs" tabIndex={0} variant="ghost">
+ <InfoIcon />
+ </IconButton>
+ </Tooltip>
+ ) : null}
+ </>
+ ) : (
+ <Flex align="center" aria-live="polite" gap="2" minW="0" role="status">
+ {isBusy ? (
+ <>
+ <Spinner flexShrink="0" size="xs" />
+ <span>{statusText}</span>
+ </>
+ ) : null}
+ </Flex>
+ )}
+ </Flex>
+ );
};
export const getSamActionHandlers = (engine: ToolOptionsComponentProps['engine']) => ({
@@ -169,11 +177,7 @@ export const getSamActionEligibility = (
session: SamSessionSnapshot,
isExternalInteractionLocked = false
): SamActionEligibility => {
- const isProcessing =
- session.status === 'preparing-composite' ||
- session.status === 'uploading' ||
- session.status === 'processing-sam' ||
- session.status === 'rendering-preview';
+ const isProcessing = isSamProcessingStatus(session.status);
const actionsBlocked = session.status === 'committing' || isExternalInteractionLocked;
const hasReadyPreview = session.hasPreview && !isProcessing && !actionsBlocked;
return {
@@ -186,38 +190,6 @@ export const getSamActionEligibility = (
};
};
-export const SamSwitch = ({
- accessibleLabel,
- checked,
- disabled,
- label,
- onChange,
-}: {
- accessibleLabel: string;
- checked: boolean;
- disabled?: boolean;
- label: string;
- onChange(checked: boolean): void;
-}) => (
- <Tooltip content={accessibleLabel}>
- <Switch.Root
- checked={checked}
- disabled={disabled}
- {...SAM_COMPACT_CONTROL_LAYOUT}
- {...SAM_COMPACT_SWITCH_LAYOUT}
- onCheckedChange={({ checked: next }) => onChange(next)}
- >
- <Switch.HiddenInput aria-label={accessibleLabel} />
- <Switch.Control flexShrink="0">
- <Switch.Thumb />
- </Switch.Control>
- <Switch.Label fontSize="xs" minW="0" overflow="hidden" textOverflow="ellipsis" whiteSpace="nowrap">
- {label}
- </Switch.Label>
- </Switch.Root>
- </Tooltip>
-);
-
export const SamModeToggle = ({
disabled,
groupLabel = 'Selection mode',
@@ -235,11 +207,11 @@ export const SamModeToggle = ({
promptLabel: string;
visualLabel: string;
}) => (
- <Group aria-label={groupLabel} attached flex="1 1 10rem" role="group" {...SAM_COMPACT_GROUP_LAYOUT}>
+ <Group aria-label={groupLabel} attached flexShrink="0" role="group">
<Button
aria-pressed={mode === 'visual'}
disabled={disabled}
- {...SAM_SEGMENT_BUTTON_LAYOUT}
+ size="xs"
variant={mode === 'visual' ? 'solid' : 'ghost'}
onClick={onVisual}
>
@@ -248,7 +220,7 @@ export const SamModeToggle = ({
<Button
aria-pressed={mode === 'prompt'}
disabled={disabled}
- {...SAM_SEGMENT_BUTTON_LAYOUT}
+ size="xs"
variant={mode === 'prompt' ? 'solid' : 'ghost'}
onClick={onPrompt}
>
@@ -257,67 +229,69 @@ export const SamModeToggle = ({
</Group>
);
-export const SamVisualBody = ({
+export const SamVisualInput = ({
disabled,
- session,
+ pointLabel,
viewModel,
onExclude,
onInclude,
}: {
disabled: boolean;
- session: SamSessionSnapshot & { input: Extract<SamSessionSnapshot['input'], { type: 'visual' }> };
+ pointLabel: SamSessionSnapshot['pointLabel'];
viewModel: SamPanelViewModel;
onExclude(): void;
onInclude(): void;
}) => {
const { t } = useTranslation();
+ const bboxText = viewModel.bboxActive
+ ? t('widgets.layers.selectObject.bboxActive')
+ : t('widgets.layers.selectObject.bboxInactive');
return (
<Flex
align="center"
aria-describedby={SAM_VISUAL_GUIDANCE_ID}
aria-label={t('widgets.layers.selectObject.pointType')}
- flexWrap="wrap"
- gap="2"
+ gap="1"
+ minW="0"
role="group"
>
<VisuallyHidden id={SAM_VISUAL_GUIDANCE_ID}>{t('widgets.layers.selectObject.visualGuidance')}</VisuallyHidden>
- <Group attached flex="1 1 10rem" {...SAM_COMPACT_GROUP_LAYOUT}>
+ <Group attached flexShrink="0">
<Button
- aria-pressed={session.pointLabel === 'include'}
+ aria-pressed={pointLabel === 'include'}
disabled={disabled}
- {...SAM_VISUAL_BUTTON_LAYOUT}
- variant={session.pointLabel === 'include' ? 'solid' : 'outline'}
+ size="xs"
+ variant={pointLabel === 'include' ? 'solid' : 'outline'}
onClick={onInclude}
>
- <Text as="span" fontVariantNumeric="tabular-nums" overflow="hidden" textOverflow="ellipsis">
+ <Text as="span" fontVariantNumeric="tabular-nums">
{t('widgets.layers.selectObject.includeCount', { count: viewModel.includeCount })}
</Text>
</Button>
<Button
- aria-pressed={session.pointLabel === 'exclude'}
+ aria-pressed={pointLabel === 'exclude'}
disabled={disabled}
- {...SAM_VISUAL_BUTTON_LAYOUT}
- variant={session.pointLabel === 'exclude' ? 'solid' : 'outline'}
+ size="xs"
+ variant={pointLabel === 'exclude' ? 'solid' : 'outline'}
onClick={onExclude}
>
- <Text as="span" fontVariantNumeric="tabular-nums" overflow="hidden" textOverflow="ellipsis">
+ <Text as="span" fontVariantNumeric="tabular-nums">
{t('widgets.layers.selectObject.excludeCount', { count: viewModel.excludeCount })}
</Text>
</Button>
</Group>
- <Text
- color={viewModel.bboxActive ? 'fg' : 'fg.muted'}
- flex="0 1 auto"
- fontSize="xs"
- fontWeight="medium"
- maxW="full"
- minW="0"
- overflowWrap="anywhere"
- >
- {viewModel.bboxActive
- ? t('widgets.layers.selectObject.bboxActive')
- : t('widgets.layers.selectObject.bboxInactive')}
- </Text>
+ <Tooltip content={bboxText}>
+ <Text
+ color={viewModel.bboxActive ? 'fg' : 'fg.subtle'}
+ fontSize="2xs"
+ fontWeight="medium"
+ px="1"
+ whiteSpace="nowrap"
+ >
+ <span aria-hidden="true">{t('widgets.layers.selectObject.bbox')}</span>
+ <VisuallyHidden>{bboxText}</VisuallyHidden>
+ </Text>
+ </Tooltip>
</Flex>
);
};
@@ -339,10 +313,13 @@ export const SamPromptBody = ({
aria-label={t('widgets.layers.selectObject.prompt')}
autoComplete="off"
disabled={disabled}
- minW="0"
+ flex="0 1 13rem"
+ h="8"
+ minW="6rem"
placeholder={t('widgets.layers.selectObject.promptGuidance')}
+ size="xs"
value={prompt}
- {...SAM_COMPACT_CONTROL_LAYOUT}
+ w="13rem"
onChange={onChange}
/>
<VisuallyHidden id={SAM_PROMPT_GUIDANCE_ID}>{t('widgets.layers.selectObject.promptGuidance')}</VisuallyHidden>
@@ -350,6 +327,107 @@ export const SamPromptBody = ({
);
};
+const SamSettingsSwitch = ({
+ checked,
+ disabled,
+ label,
+ onChange,
+}: {
+ checked: boolean;
+ disabled?: boolean;
+ label: string;
+ onChange(checked: boolean): void;
+}) => (
+ <Switch.Root
+ checked={checked}
+ disabled={disabled}
+ justifyContent="space-between"
+ size="sm"
+ w="full"
+ onCheckedChange={({ checked: next }) => onChange(next)}
+ >
+ <Switch.Label fontSize="xs">{label}</Switch.Label>
+ <Switch.HiddenInput />
+ <Switch.Control>
+ <Switch.Thumb />
+ </Switch.Control>
+ </Switch.Root>
+);
+
+/** Set-once session settings (model, refinement, preview behavior) demoted out of the bar. */
+export const SamSettingsPopover = ({
+ eligibility,
+ isProcessing,
+ session,
+ onModelChange,
+ onToggle,
+}: {
+ eligibility: SamActionEligibility;
+ isProcessing: boolean;
+ session: SamSessionSnapshot;
+ onModelChange(model: SamModel): void;
+ onToggle(key: 'applyPolygonRefinement' | 'autoProcess' | 'isolatedPreview', value: boolean): void;
+}) => {
+ const { t } = useTranslation();
+ return (
+ <Popover.Root lazyMount positioning={SAM_UPWARD_POSITIONING} unmountOnExit>
+ <Popover.Trigger asChild>
+ <Tooltip content={t('widgets.layers.selectObject.settings')}>
+ <IconButton aria-label={t('widgets.layers.selectObject.settings')} size="xs" variant="ghost">
+ <SettingsIcon />
+ </IconButton>
+ </Tooltip>
+ </Popover.Trigger>
+ <Portal>
+ <Popover.Positioner>
+ <Popover.Content bg="bg.muted" borderColor="border.emphasized" borderWidth="1px" w="16rem">
+ <Popover.Body p="2.5">
+ <Stack gap="2.5">
+ <Stack gap="1">
+ <Text asChild fontSize="xs" fontWeight="semibold">
+ <label htmlFor="sam-model">{t('widgets.layers.selectObject.model')}</label>
+ </Text>
+ <NativeSelect.Root disabled={isProcessing || !eligibility.canEditInputs} size="xs">
+ <NativeSelect.Field
+ id="sam-model"
+ value={session.model}
+ onChange={(event) => onModelChange(event.currentTarget.value as SamModel)}
+ >
+ <option value="segment-anything-2-large">
+ {t('widgets.layers.selectObject.modelSam2Large')}
+ </option>
+ <option value="segment-anything-huge">{t('widgets.layers.selectObject.modelHuge')}</option>
+ </NativeSelect.Field>
+ <NativeSelect.Indicator />
+ </NativeSelect.Root>
+ </Stack>
+ <SamSettingsSwitch
+ checked={session.applyPolygonRefinement}
+ disabled={isProcessing || !eligibility.canEditInputs}
+ label={t('widgets.layers.selectObject.refine')}
+ onChange={(value) => onToggle('applyPolygonRefinement', value)}
+ />
+ <SamSettingsSwitch
+ checked={session.autoProcess}
+ disabled={!eligibility.canEditInputs}
+ label={t('widgets.layers.selectObject.autoProcess')}
+ onChange={(value) => onToggle('autoProcess', value)}
+ />
+ <SamSettingsSwitch
+ checked={session.isolatedPreview}
+ disabled={!eligibility.canEditInputs}
+ label={t('widgets.layers.selectObject.isolatedPreview')}
+ onChange={(value) => onToggle('isolatedPreview', value)}
+ />
+ </Stack>
+ </Popover.Body>
+ </Popover.Content>
+ </Popover.Positioner>
+ </Portal>
+ </Popover.Root>
+ );
+};
+
const SamSaveItem = ({
disabled,
onSave,
@@ -367,7 +445,7 @@ const SamSaveItem = ({
);
};
-export const SamOptionsPanel = ({
+export const SamOptionsBar = ({
engine,
session,
isExternalInteractionLocked = false,
@@ -383,184 +461,132 @@ export const SamOptionsPanel = ({
(width, height) => t('widgets.layers.selectObject.sourceDimensionsLabel', { height, width })
);
const actions = getSamActionHandlers(engine);
- const isProcessing =
- session.status === 'preparing-composite' ||
- session.status === 'uploading' ||
- session.status === 'processing-sam' ||
- session.status === 'rendering-preview';
+ const isProcessing = isSamProcessingStatus(session.status);
+ const isBusy = !session.error && (isProcessing || session.status === 'scheduled' || session.status === 'committing');
const setBoolean = (key: 'applyPolygonRefinement' | 'autoProcess' | 'invert' | 'isolatedPreview', value: boolean) =>
engine.updateSelectObjectSession({ [key]: value });
return (
- <CanvasOperationPanel.Root aria-labelledby="sam-operation-title" operation="select-object">
- <CanvasOperationPanel.Header {...SAM_COMPACT_SLOT_LAYOUT}>
- <Flex align="center" flexWrap="wrap" gap="2" justify="space-between" maxW="full" minW="0">
- <Flex align="baseline" flex="0 1 auto" flexWrap="wrap" gap="1" maxW="full" minW="0">
- <Heading fontSize="sm" id="sam-operation-title" maxW="full" whiteSpace="nowrap">
- {t('widgets.layers.selectObject.title')}
- </Heading>
- <Text
- aria-label={viewModel.sourceLabel}
- color="fg.muted"
- fontSize="xs"
- fontVariantNumeric="tabular-nums"
- maxW="full"
- minW="0"
- whiteSpace="nowrap"
- >
- {viewModel.sourceSummary}
- </Text>
- </Flex>
- <Flex align="center" flex="0 1 auto" flexWrap="wrap" gap="2" maxW="full" minW="0">
- <SamSwitch
- accessibleLabel={t('widgets.layers.selectObject.autoProcess')}
- checked={session.autoProcess}
- disabled={!eligibility.canEditInputs}
- label={t('widgets.layers.selectObject.autoProcessCompact')}
- onChange={(value) => setBoolean('autoProcess', value)}
- />
- <SamSwitch
- accessibleLabel={t('widgets.layers.selectObject.isolatedPreview')}
- checked={session.isolatedPreview}
- disabled={!eligibility.canEditInputs}
- label={t('widgets.layers.selectObject.isolatedPreviewCompact')}
- onChange={(value) => setBoolean('isolatedPreview', value)}
- />
- </Flex>
- </Flex>
- </CanvasOperationPanel.Header>
- <CanvasOperationPanel.Body {...SAM_COMPACT_SLOT_LAYOUT}>
- <Stack gap="2">
- <Flex align="center" flexWrap="wrap" gap="1" justify="space-between" minW="0">
- <SamModeToggle
- disabled={!eligibility.canEditInputs}
- groupLabel={t('widgets.layers.selectObject.mode')}
- mode={session.input.type}
- promptLabel={t('widgets.layers.selectObject.promptMode')}
- visualLabel={t('widgets.layers.selectObject.visual')}
- onPrompt={() => engine.updateSelectObjectSession({ input: { prompt: '', type: 'prompt' } })}
- onVisual={() =>
- engine.updateSelectObjectSession({
- input: { bbox: null, excludePoints: [], includePoints: [], type: 'visual' },
- })
- }
- />
- <SamSwitch
- accessibleLabel={t('widgets.layers.selectObject.invert')}
- checked={session.invert}
- disabled={!eligibility.canEditInputs}
- label={t('widgets.layers.selectObject.invert')}
- onChange={(value) => setBoolean('invert', value)}
- />
- </Flex>
- {session.input.type === 'visual' ? (
- <SamVisualBody
- disabled={!eligibility.canEditInputs}
- session={{ ...session, input: session.input }}
- viewModel={viewModel}
- onExclude={() => engine.updateSelectObjectSession({ pointLabel: 'exclude' })}
- onInclude={() => engine.updateSelectObjectSession({ pointLabel: 'include' })}
- />
- ) : (
- <SamPromptBody
- disabled={!eligibility.canEditInputs}
- prompt={session.input.prompt}
- onChange={(event) =>
- engine.updateSelectObjectSession({ input: { prompt: event.currentTarget.value, type: 'prompt' } })
- }
- />
- )}
- <Flex align="center" flexWrap="wrap" gap="1" minW="0">
- <Text asChild fontSize="xs" fontWeight="semibold">
- <label htmlFor="sam-model">{t('widgets.layers.selectObject.model')}</label>
- </Text>
- <NativeSelect.Root
- disabled={isProcessing || !eligibility.canEditInputs}
- {...SAM_COMPACT_CONTROL_LAYOUT}
- {...SAM_MODEL_SELECT_LAYOUT}
- >
- <NativeSelect.Field
- aria-label={t('widgets.layers.selectObject.model')}
- id="sam-model"
- value={session.model}
- onChange={(event) => engine.updateSelectObjectSession({ model: event.currentTarget.value as SamModel })}
- >
- <option value="segment-anything-2-large">{t('widgets.layers.selectObject.modelSam2Large')}</option>
- <option value="segment-anything-huge">{t('widgets.layers.selectObject.modelHuge')}</option>
- </NativeSelect.Field>
- <NativeSelect.Indicator />
- </NativeSelect.Root>
- <SamSwitch
- accessibleLabel={t('widgets.layers.selectObject.refine')}
- checked={session.applyPolygonRefinement}
- disabled={isProcessing || !eligibility.canEditInputs}
- label={t('widgets.layers.selectObject.refine')}
- onChange={(value) => setBoolean('applyPolygonRefinement', value)}
- />
- </Flex>
- </Stack>
- </CanvasOperationPanel.Body>
- {session.error || isProcessing || session.status === 'scheduled' || session.status === 'committing' ? (
- <CanvasOperationPanel.Feedback
- {...SAM_COMPACT_SLOT_LAYOUT}
- color={session.error ? 'fg.error' : 'fg.muted'}
- fontSize="xs"
- >
- <SamProcessFeedback
- error={session.error}
- errorText={session.error ? t(getSamErrorTranslationKey(session.error.code)) : null}
- isBusy={!session.error}
- statusText={t(getSamStatusTranslationKey(session.status))}
- technicalDetailsLabel={t('widgets.layers.selectObject.technicalDetails')}
+ <CanvasFloatingBar maxW="full">
+ <Flex
+ align="center"
+ aria-label={t('widgets.layers.selectObject.title')}
+ flexWrap="wrap"
+ gap="1"
+ minW="0"
+ role="group"
+ >
+ <Tooltip content={viewModel.sourceLabel}>
+ <Text flexShrink="0" fontSize="xs" fontWeight="semibold" px="1" whiteSpace="nowrap">
+ {t('widgets.layers.selectObject.title')}
+ <VisuallyHidden>{viewModel.sourceLabel}</VisuallyHidden>
+ </Text>
+ </Tooltip>
+ <CanvasFloatingBarDivider />
+ <SamModeToggle
+ disabled={!eligibility.canEditInputs}
+ groupLabel={t('widgets.layers.selectObject.mode')}
+ mode={session.input.type}
+ promptLabel={t('widgets.layers.selectObject.promptMode')}
+ visualLabel={t('widgets.layers.selectObject.visual')}
+ onPrompt={() => engine.updateSelectObjectSession({ input: { prompt: '', type: 'prompt' } })}
+ onVisual={() =>
+ engine.updateSelectObjectSession({
+ input: { bbox: null, excludePoints: [], includePoints: [], type: 'visual' },
+ })
+ }
+ />
+ {session.input.type === 'visual' ? (
+ <SamVisualInput
+ disabled={!eligibility.canEditInputs}
+ pointLabel={session.pointLabel}
+ viewModel={viewModel}
+ onExclude={() => engine.updateSelectObjectSession({ pointLabel: 'exclude' })}
+ onInclude={() => engine.updateSelectObjectSession({ pointLabel: 'include' })}
/>
- </CanvasOperationPanel.Feedback>
- ) : null}
- <CanvasOperationPanel.Footer {...SAM_COMPACT_FOOTER_LAYOUT} {...SAM_COMPACT_SLOT_LAYOUT}>
- <Button
- disabled={!eligibility.canProcess}
- loading={isProcessing}
- {...SAM_COMPACT_BUTTON_LAYOUT}
- onClick={actions.process}
- >
- {t('widgets.layers.selectObject.process')}
- </Button>
- <Button disabled={!eligibility.canReset} variant="ghost" {...SAM_COMPACT_BUTTON_LAYOUT} onClick={actions.reset}>
- {t('widgets.layers.selectObject.reset')}
- </Button>
- <Button
- colorPalette="accent"
- disabled={!eligibility.canApply}
- {...SAM_COMPACT_BUTTON_LAYOUT}
- onClick={actions.apply}
- >
- {t('common.apply')}
- </Button>
- <Menu.Root>
- <Menu.Trigger asChild>
- <Button disabled={!eligibility.canSave} variant="outline" {...SAM_COMPACT_BUTTON_LAYOUT}>
- {t('widgets.layers.selectObject.saveAs')} <ChevronDownIcon size={14} />
- </Button>
- </Menu.Trigger>
- <Portal>
- <Menu.Positioner>
- <MenuContent minW="11rem" py="1">
- {SAVE_TARGETS.map((target) => (
- <SamSaveItem key={target} disabled={!eligibility.canSave} target={target} onSave={actions.save} />
- ))}
- </MenuContent>
- </Menu.Positioner>
- </Portal>
- </Menu.Root>
+ ) : (
+ <SamPromptBody
+ disabled={!eligibility.canEditInputs}
+ prompt={session.input.prompt}
+ onChange={(event) =>
+ engine.updateSelectObjectSession({ input: { prompt: event.currentTarget.value, type: 'prompt' } })
+ }
+ />
+ )}
+ <CanvasFloatingBarDivider />
<Button
- disabled={!eligibility.canCancel}
- variant="ghost"
- {...SAM_COMPACT_BUTTON_LAYOUT}
- onClick={actions.cancel}
+ aria-pressed={session.invert}
+ disabled={!eligibility.canEditInputs}
+ size="xs"
+ variant={session.invert ? 'solid' : 'ghost'}
+ onClick={() => setBoolean('invert', !session.invert)}
>
- {t('common.cancel')}
+ {t('widgets.layers.selectObject.invert')}
</Button>
- </CanvasOperationPanel.Footer>
- </CanvasOperationPanel.Root>
+ <CanvasFloatingBarDivider />
+ <SamStatusSlot
+ error={session.error}
+ errorText={session.error ? t(getSamErrorTranslationKey(session.error.code)) : null}
+ isBusy={isBusy}
+ statusText={t(getSamStatusTranslationKey(session.status))}
+ technicalDetailsLabel={t('widgets.layers.selectObject.technicalDetails')}
+ />
+ <SamSettingsPopover
+ eligibility={eligibility}
+ isProcessing={isProcessing}
+ session={session}
+ onModelChange={(model) => engine.updateSelectObjectSession({ model })}
+ onToggle={setBoolean}
+ />
+ <CanvasFloatingBarDivider />
+ <HStack flexShrink="0" gap="1">
+ <Button disabled={!eligibility.canProcess} loading={isProcessing} size="xs" onClick={actions.process}>
+ {t('widgets.layers.selectObject.process')}
+ </Button>
+ <Button disabled={!eligibility.canReset} size="xs" variant="ghost" onClick={actions.reset}>
+ {t('widgets.layers.selectObject.reset')}
+ </Button>
+ <Menu.Root positioning={SAM_UPWARD_POSITIONING}>
+ <Group attached>
+ <Button
+ colorPalette="accent"
+ disabled={!eligibility.canApply}
+ roundedEnd="none"
+ size="xs"
+ onClick={actions.apply}
+ >
+ {t('common.apply')}
+ </Button>
+ <Menu.Trigger asChild>
+ <IconButton
+ aria-label={t('widgets.layers.selectObject.saveAs')}
+ colorPalette="accent"
+ disabled={!eligibility.canSave}
+ minW="0"
+ roundedStart="none"
+ size="xs"
+ w="6"
+ >
+ <ChevronDownIcon />
+ </IconButton>
+ </Menu.Trigger>
+ </Group>
+ <Portal>
+ <Menu.Positioner>
+ <MenuContent minW="11rem" py="1">
+ {SAVE_TARGETS.map((target) => (
+ <SamSaveItem key={target} disabled={!eligibility.canSave} target={target} onSave={actions.save} />
+ ))}
+ </MenuContent>
+ </Menu.Positioner>
+ </Portal>
+ </Menu.Root>
+ <Button disabled={!eligibility.canCancel} size="xs" variant="ghost" onClick={actions.cancel}>
+ {t('common.cancel')}
+ </Button>
+ </HStack>
+ </Flex>
+ </CanvasFloatingBar>
);
};
@@ -572,7 +598,5 @@ export const SamOptions = ({
if (!session) {
return null;
}
- return (
- <SamOptionsPanel engine={engine} isExternalInteractionLocked={isExternalInteractionLocked} session={session} />
- );
+ return <SamOptionsBar engine={engine} isExternalInteractionLocked={isExternalInteractionLocked} session={session} />;
};