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): tab the layer tree with History

Josh Corbett0464e5cf7306
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.json
index 39b1910ab2..3a64a60a9d 100644
--- a/invokeai/frontend/webv2/public/locales/en.json
+++ b/invokeai/frontend/webv2/public/locales/en.json
@@ -3028,7 +3028,8 @@
},
"overviewPane": {
"pan": "Pan the canvas view"
- }
+ },
+ "treeTabs": "Layer panel views"
},
"gallery": {
"alwaysShowDimensions": "Always show dimensions",
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersWidgetView.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersWidgetView.tsx
index c8b7ee4591..2249157764 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersWidgetView.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersWidgetView.tsx
@@ -9,13 +9,15 @@ import { useCanvasDocumentEditingLocked } from '@workbench/widgets/canvas/engine
import { useCanvasEngine } from '@workbench/widgets/canvas/useCanvasEngine';
import { useActiveProjectId, useActiveProjectSelector } from '@workbench/WorkbenchContext';
import { LayersIcon } from 'lucide-react';
-import { useCallback, useMemo } from 'react';
+import { useCallback, useEffect, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
-import type { LayerColorPaneLayout, LayerEditorPaneLayout } from './panes/editorPaneLayout';
+import type { LayerColorPaneLayout, LayerEditorPaneLayout, LayerTreeTabId } from './panes/editorPaneLayout';
import { LayerMultiSelectionActions } from './LayerMultiSelectionActions';
import { LAYER_PANEL_DEGRADE_THRESHOLD } from './layerPanelRows';
+import { useCurrentLayerPropertiesRequest } from './layerPropertiesRequestStore';
+import { LayersHeaderActions } from './LayersHeaderActions';
import { LayersPanelFooter } from './LayersPanelFooter';
import { LayersTree } from './LayersTree';
import { buildLayerStackRows } from './layerTreeRows';
@@ -24,14 +26,17 @@ import {
areLayerEditorPaneLayoutsEqual,
readColorPaneLayout,
readLayerEditorPaneLayout,
+ readLayerTreeTab,
} from './panes/editorPaneLayout';
-import { LayerColorPane, LayerEditorPanes } from './panes/LayerEditorPanes';
+import { HistoryPane } from './panes/HistoryPane';
+import { LAYER_TREE_PANEL_ID, LayerColorPane, LayerEditorPanes, LayerTreeStrip } from './panes/LayerEditorPanes';
/**
- * The layers panel: the Color pane at the top, a fixed selection toolbar, the virtualized tree
- * of the four stacks, a fixed footer (summary, filter, density), and the editor panes at the
- * bottom — the selected layer's own editors live in the Properties pane. Regions keep their
- * geometry; their controls disable instead of appearing and disappearing.
+ * The layers panel: the Color pane at the top, then the flexible middle region tabbed between
+ * the virtualized tree of the four stacks (with its selection toolbar and footer) and the edit
+ * history, and the editor panes (Properties, Transform, Overview) at the bottom — the selected
+ * layer's own editors live in the Properties pane. Regions keep their geometry; their controls
+ * disable instead of appearing and disappearing.
*/
export const LayersWidgetView = ({ runtime }: WidgetViewProps) => {
const { t } = useTranslation();
@@ -84,6 +89,18 @@ export const LayersWidgetView = ({ runtime }: WidgetViewProps) => {
(next: LayerColorPaneLayout) => runtime.state.patch({ colorPane: next }),
[runtime.state]
);
+ const treeTab = useActiveProjectSelector((project) =>
+ readLayerTreeTab(project.widgetInstances[runtime.instanceId]?.state.values ?? {})
+ );
+ const handleTreeTab = useCallback((tab: LayerTreeTabId) => runtime.state.patch({ treeTab: tab }), [runtime.state]);
+ // A properties request (canvas context menu) must reach the tree, which only
+ // mounts on the Layers tab — switch back so the reveal actually happens.
+ const propertiesRequest = useCurrentLayerPropertiesRequest();
+ useEffect(() => {
+ if (propertiesRequest && treeTab === 'history') {
+ runtime.state.patch({ treeTab: 'layers' });
+ }
+ }, [propertiesRequest, runtime.state, treeTab]);
const revealProperties = useCallback(
(layerId: string) => {
dispatch({ id: layerId, type: 'setCanvasSelectedLayer' });
@@ -95,59 +112,80 @@ export const LayersWidgetView = ({ runtime }: WidgetViewProps) => {
return (
<Stack gap="1" h="full" minH="0">
<LayerColorPane layout={colorPaneLayout} onLayoutChange={handleColorPaneLayout} />
- <LayerMultiSelectionActions
- document={document}
- editingLocked={editingLocked}
- engine={engine}
- projectId={projectId}
- selectedIds={panel.selectedIds}
- />
- {nodeCount === 0 ? (
- <Flex
- align="center"
- borderColor="border.subtle"
- borderStyle="dashed"
- borderWidth="1px"
- color="fg.subtle"
- direction="column"
- flex="1"
- gap="2"
- justify="center"
- minH="8rem"
- mx="2"
- p="4"
- rounded="md"
- >
- <Icon as={LayersIcon} boxSize="6" />
- <Text fontSize="2xs" textAlign="center">
- {t('widgets.layers.empty')}
- </Text>
- </Flex>
- ) : (
- <Flex direction="column" flex="1" minH="8rem">
- <LayersTree
- degraded={degraded}
- dispatch={dispatch}
- document={document}
- editingLocked={editingLocked}
- engine={engine}
- panel={panel}
- projectId={projectId}
- stacks={stacks}
- onRevealProperties={revealProperties}
- />
- </Flex>
- )}
- <LayersPanelFooter
- degraded={degraded}
- density={panel.density}
- filter={panel.filter}
- groupCount={counts.groups}
- leafCount={counts.leaves}
- selectedCount={panel.selectedIds.length}
- onDensityChange={handleDensity}
- onFilterChange={handleFilter}
- />
+ <LayerTreeStrip activeTab={treeTab} onSelectTab={handleTreeTab}>
+ <LayersHeaderActions />
+ </LayerTreeStrip>
+ <Flex
+ aria-labelledby={`layer-tree-tab-${treeTab}`}
+ direction="column"
+ flex="1"
+ id={LAYER_TREE_PANEL_ID}
+ // The toolbar (40px) + tree floor (128px) + footer (40px); anything
+ // less lets the unshrinkable rows paint under the editor panes.
+ minH="13rem"
+ overflow="hidden"
+ role="tabpanel"
+ >
+ {treeTab === 'history' ? (
+ <HistoryPane />
+ ) : (
+ <>
+ <LayerMultiSelectionActions
+ document={document}
+ editingLocked={editingLocked}
+ engine={engine}
+ projectId={projectId}
+ selectedIds={panel.selectedIds}
+ />
+ {nodeCount === 0 ? (
+ <Flex
+ align="center"
+ borderColor="border.subtle"
+ borderStyle="dashed"
+ borderWidth="1px"
+ color="fg.subtle"
+ direction="column"
+ flex="1"
+ gap="2"
+ justify="center"
+ minH="8rem"
+ mx="2"
+ p="4"
+ rounded="md"
+ >
+ <Icon as={LayersIcon} boxSize="6" />
+ <Text fontSize="2xs" textAlign="center">
+ {t('widgets.layers.empty')}
+ </Text>
+ </Flex>
+ ) : (
+ <Flex direction="column" flex="1" minH="8rem">
+ <LayersTree
+ degraded={degraded}
+ dispatch={dispatch}
+ document={document}
+ editingLocked={editingLocked}
+ engine={engine}
+ panel={panel}
+ projectId={projectId}
+ stacks={stacks}
+ onRevealProperties={revealProperties}
+ />
+ </Flex>
+ )}
+ <LayersPanelFooter
+ degraded={degraded}
+ density={panel.density}
+ filter={panel.filter}
+ groupCount={counts.groups}
+ leafCount={counts.leaves}
+ selectedCount={panel.selectedIds.length}
+ onDensityChange={handleDensity}
+ onFilterChange={handleFilter}
+ />
+ </>
+ )}
+ </Flex>
<LayerEditorPanes layout={paneLayout} onLayoutChange={handlePaneLayout} />
</Stack>
);
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/implementation.ts b/invokeai/frontend/webv2/src/workbench/widgets/layers/implementation.ts
index 3348b9386f..6380ccfae1 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/implementation.ts
+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/implementation.ts
@@ -1,9 +1,7 @@
import type { WidgetImplementation } from '@workbench/widgetContracts';
-import { LayersHeaderActions } from './LayersHeaderActions';
import { LayersWidgetView } from './LayersWidgetView';
export const widgetImplementation = {
- headerActions: LayersHeaderActions,
view: LayersWidgetView,
} satisfies WidgetImplementation;
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/panes/LayerEditorPanes.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/panes/LayerEditorPanes.browser.test.tsx
index 0c4f1bad78..3af266199f 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/panes/LayerEditorPanes.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/panes/LayerEditorPanes.browser.test.tsx
@@ -75,12 +75,12 @@ vi.mock('@workbench/useCanvasProjectMutationDispatch', () => ({
}));
vi.mock('@workbench/widgets/canvas/useCanvasEngine', () => ({ useCanvasEngine: () => harness.engine }));
-import type { LayerEditorPaneLayout } from './editorPaneLayout';
+import type { LayerEditorPaneLayout, LayerTreeTabId } from './editorPaneLayout';
import { ColorPane } from './ColorPane';
import { LAYER_EDITOR_PANE_DEFAULTS } from './editorPaneLayout';
import { HistoryPane } from './HistoryPane';
-import { LayerEditorPanes } from './LayerEditorPanes';
+import { LAYER_TREE_PANEL_ID, LayerEditorPanes, LayerTreeStrip } from './LayerEditorPanes';
import { OverviewPane } from './OverviewPane';
import { PropertiesPane } from './PropertiesPane';
import { SwatchesPane } from './SwatchesPane';
@@ -428,6 +428,36 @@ const OverviewHarness = () => (
</Box>
);
+const TreeStripHarness = () => {
+ const [tab, setTab] = useState<LayerTreeTabId>('layers');
+ return (
+ <>
+ <LayerTreeStrip activeTab={tab} onSelectTab={setTab}>
+ <span>trailing-slot</span>
+ </LayerTreeStrip>
+ <Box id={LAYER_TREE_PANEL_ID} role="tabpanel">
+ {tab === 'history' ? 'history-panel' : 'layers-panel'}
+ </Box>
+ </>
+ );
+};
+
+describe('Layer tree strip', () => {
+ it('switches the middle region between the tree and history', async () => {
+ await mount(TreeStripHarness);
+ const layersTab = page.getByRole('tab', { exact: true, name: 'Layers' });
+ const historyTab = page.getByRole('tab', { exact: true, name: 'History' });
+ await expect.element(layersTab).toHaveAttribute('aria-selected', 'true');
+ expect(host!.textContent).toContain('layers-panel');
+ expect(host!.textContent).toContain('trailing-slot');
+ await act(async () => {
+ await userEvent.click(historyTab);
+ });
+ await expect.element(historyTab).toHaveAttribute('aria-selected', 'true');
+ expect(host!.textContent).toContain('history-panel');
+ });
+});
+
describe('History pane', () => {
it('shows the empty state with undo and redo disabled', async () => {
await mount(HistoryPane);
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/panes/LayerEditorPanes.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/panes/LayerEditorPanes.tsx
index 97dcf3e98c..7b00cb95b7 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/panes/LayerEditorPanes.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/panes/LayerEditorPanes.tsx
@@ -13,6 +13,7 @@ import type {
LayerColorPaneLayout,
LayerEditorPaneId,
LayerEditorPaneLayout,
+ LayerTreeTabId,
PaneBlockLayout,
} from './editorPaneLayout';
@@ -25,7 +26,6 @@ import {
LAYER_EDITOR_PANE_MAX_SIZE_PX,
LAYER_EDITOR_PANE_MIN_SIZE_PX,
} from './editorPaneLayout';
-import { HistoryPane } from './HistoryPane';
import { OverviewPane } from './OverviewPane';
import { PropertiesPane } from './PropertiesPane';
import { SwatchesPane } from './SwatchesPane';
@@ -47,6 +47,26 @@ interface PaneBlockLabels {
tabs: string;
}
+/** Roving focus for a horizontal tablist: arrows cycle, Home/End jump. */
+const focusSibling = (event: ReactKeyboardEvent<HTMLElement>) => {
+ if (event.key !== 'ArrowLeft' && event.key !== 'ArrowRight' && event.key !== 'Home' && event.key !== 'End') {
+ return;
+ }
+ const tabs = [...event.currentTarget.querySelectorAll<HTMLElement>('[role="tab"]')];
+ const current = tabs.indexOf(document.activeElement as HTMLElement);
+ if (current === -1) {
+ return;
+ }
+ event.preventDefault();
+ const next =
+ event.key === 'Home'
+ ? 0
+ : event.key === 'End'
+ ? tabs.length - 1
+ : (current + (event.key === 'ArrowRight' ? 1 : tabs.length - 1)) % tabs.length;
+ tabs[next]?.focus();
+};
+
/**
* One fixed pane block of the Layers panel: a tab strip over a panel, with a
* preferred height, a resize separator on its inner edge, and collapse down to
@@ -171,25 +191,6 @@ const LayerPaneBlock = ({
},
[commitSize, edge, maxSizePx, minSizePx, patch, sizePx]
);
- const focusSibling = useCallback((event: ReactKeyboardEvent<HTMLElement>) => {
- if (event.key !== 'ArrowLeft' && event.key !== 'ArrowRight' && event.key !== 'Home' && event.key !== 'End') {
- return;
- }
- const tabs = [...event.currentTarget.querySelectorAll<HTMLElement>('[role="tab"]')];
- const current = tabs.indexOf(document.activeElement as HTMLElement);
- if (current === -1) {
- return;
- }
- event.preventDefault();
- const next =
- event.key === 'Home'
- ? 0
- : event.key === 'End'
- ? tabs.length - 1
- : (current + (event.key === 'ArrowRight' ? 1 : tabs.length - 1)) % tabs.length;
- tabs[next]?.focus();
- }, []);
-
const collapseLabel = isCollapsed ? labels.expand : labels.collapse;
const collapseIcon =
edge === 'top' ? (isCollapsed ? ChevronDownIcon : ChevronUpIcon) : isCollapsed ? ChevronUpIcon : ChevronDownIcon;
@@ -301,12 +302,13 @@ const LayerPaneBlock = ({
const EDITOR_PANES: ReadonlyArray<{ id: LayerEditorPaneId; labelKey: string }> = [
{ id: 'properties', labelKey: 'widgets.labels.properties' },
{ id: 'transform', labelKey: 'widgets.labels.transform' },
- { id: 'history', labelKey: 'widgets.labels.history' },
+ { id: 'overview', labelKey: 'widgets.labels.overview' },
];
/**
- * The editor panes under the tree: the active tool's Properties and the
- * selected layer's Transform, persisted through the widget's project state.
+ * The editor panes under the tree: the active tool's Properties, the selected
+ * layer's Transform, and the document Overview, persisted through the widget's
+ * project state.
*/
export const LayerEditorPanes = ({
layout,
@@ -355,7 +357,13 @@ export const LayerEditorPanes = ({
onSelectPane={onSelectPane}
panes={panes}
>
- {activePane === 'transform' ? <TransformPane /> : activePane === 'history' ? <HistoryPane /> : <PropertiesPane />}
+ {activePane === 'transform' ? (
+ <TransformPane />
+ ) : activePane === 'overview' ? (
+ <OverviewPane />
+ ) : (
+ <PropertiesPane />
+ )}
</LayerPaneBlock>
);
};
@@ -363,7 +371,6 @@ export const LayerEditorPanes = ({
const COLOR_PANES: ReadonlyArray<{ id: LayerColorPaneId; labelKey: string }> = [
{ id: 'color', labelKey: 'widgets.labels.color' },
{ id: 'swatches', labelKey: 'widgets.labels.swatches' },
- { id: 'overview', labelKey: 'widgets.labels.overview' },
];
/**
@@ -418,11 +425,66 @@ export const LayerColorPane = ({
onSelectPane={onSelectPane}
panes={panes}
>
- {activePane === 'swatches' ? <SwatchesPane /> : activePane === 'overview' ? <OverviewPane /> : <ColorPane />}
+ {activePane === 'swatches' ? <SwatchesPane /> : <ColorPane />}
</LayerPaneBlock>
);
};
+const TREE_TABS: ReadonlyArray<{ id: LayerTreeTabId; labelKey: string }> = [
+ { id: 'layers', labelKey: 'widgets.labels.layers' },
+ { id: 'history', labelKey: 'widgets.labels.history' },
+];
+
+/** The middle region announces itself as this strip's tabpanel. */
+export const LAYER_TREE_PANEL_ID = 'layer-tree-panel';
+
+/**
+ * The strip over the flexible middle region: the layer tree and the edit
+ * history as sibling tabs, with the add-layer menu at the trailing edge. The
+ * middle region is the tabpanel — it has no preferred size and no collapse.
+ */
+export const LayerTreeStrip = ({
+ activeTab,
+ children,
+ onSelectTab,
+}: {
+ activeTab: LayerTreeTabId;
+ children?: ReactNode;
+ onSelectTab: (tab: LayerTreeTabId) => void;
+}) => {
+ const { t } = useTranslation();
+ const tabs = useMemo(() => TREE_TABS.map(({ id, labelKey }) => ({ id, label: t(labelKey) })), [t]);
+ const onSelect = useCallback((tab: string) => onSelectTab(tab as LayerTreeTabId), [onSelectTab]);
+
+ return (
+ <HStack align="center" flexShrink={0} gap="0.5" h={`${STRIP_HEIGHT_PX}px`} minW="0" px="1.5">
+ <HStack
+ aria-label={t('widgets.layers.treeTabs')}
+ aria-orientation="horizontal"
+ flex="1"
+ gap="0.5"
+ minW="0"
+ overflow="hidden"
+ role="tablist"
+ onKeyDown={focusSibling}
+ >
+ {tabs.map((tab) => (
+ <PaneTab
+ key={tab.id}
+ blockId="layer-tree"
+ id={tab.id}
+ isExpanded
+ isSelected={tab.id === activeTab}
+ label={tab.label}
+ onSelect={onSelect}
+ />
+ ))}
+ </HStack>
+ {children}
+ </HStack>
+ );
+};
+
const PaneTab = ({
blockId,
id,
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/panes/editorPaneLayout.ts b/invokeai/frontend/webv2/src/workbench/widgets/layers/panes/editorPaneLayout.ts
index 5613750a2f..84be8c4a1d 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/panes/editorPaneLayout.ts
+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/panes/editorPaneLayout.ts
@@ -1,6 +1,6 @@
/** Pure layout contracts for the Layers widget's pane blocks; the manifest seeds them, so no React here. */
-export type LayerEditorPaneId = 'properties' | 'transform' | 'history';
+export type LayerEditorPaneId = 'properties' | 'transform' | 'overview';
/** What every pane block persists: its preferred height and whether it is collapsed to its strip. */
export interface PaneBlockLayout {
@@ -25,7 +25,7 @@ export const clampLayerEditorPaneSize = (sizePx: number): number =>
Math.min(LAYER_EDITOR_PANE_MAX_SIZE_PX, Math.max(LAYER_EDITOR_PANE_MIN_SIZE_PX, Math.round(sizePx)));
const isPaneId = (value: unknown): value is LayerEditorPaneId =>
- value === 'properties' || value === 'transform' || value === 'history';
+ value === 'properties' || value === 'transform' || value === 'overview';
/** The persisted widget values are untyped; anything malformed falls back per field. */
export const readLayerEditorPaneLayout = (values: Record<string, unknown>): LayerEditorPaneLayout => {
@@ -44,7 +44,7 @@ export const readLayerEditorPaneLayout = (values: Record<string, unknown>): Laye
export const areLayerEditorPaneLayoutsEqual = (a: LayerEditorPaneLayout, b: LayerEditorPaneLayout): boolean =>
a.activePane === b.activePane && a.isCollapsed === b.isCollapsed && a.sizePx === b.sizePx;
-export type LayerColorPaneId = 'color' | 'swatches' | 'overview';
+export type LayerColorPaneId = 'color' | 'swatches';
export interface LayerColorPaneLayout extends PaneBlockLayout {
activePane: LayerColorPaneId;
@@ -65,8 +65,7 @@ const LEGACY_COLOR_PANE_DEFAULT_SIZES = new Set([300, 420]);
export const clampColorPaneSize = (sizePx: number): number =>
Math.min(COLOR_PANE_MAX_SIZE_PX, Math.max(COLOR_PANE_MIN_SIZE_PX, Math.round(sizePx)));
-const isColorPaneId = (value: unknown): value is LayerColorPaneId =>
- value === 'color' || value === 'swatches' || value === 'overview';
+const isColorPaneId = (value: unknown): value is LayerColorPaneId => value === 'color' || value === 'swatches';
export const readColorPaneLayout = (values: Record<string, unknown>): LayerColorPaneLayout => {
const raw = values.colorPane;
@@ -85,3 +84,10 @@ export const readColorPaneLayout = (values: Record<string, unknown>): LayerColor
export const areColorPaneLayoutsEqual = (a: LayerColorPaneLayout, b: LayerColorPaneLayout): boolean =>
a.activePane === b.activePane && a.isCollapsed === b.isCollapsed && a.sizePx === b.sizePx;
+
+export type LayerTreeTabId = 'layers' | 'history';
+
+export const LAYER_TREE_TAB_DEFAULT: LayerTreeTabId = 'layers';
+
+export const readLayerTreeTab = (values: Record<string, unknown>): LayerTreeTabId =>
+ values.treeTab === 'history' ? 'history' : LAYER_TREE_TAB_DEFAULT;