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(canvas): layers panel tweaks
Josh Corbett9f1936d0e1f9
diff --git a/invokeai/frontend/webv2/src/platform/ui/Select.tsx b/invokeai/frontend/webv2/src/platform/ui/Select.tsxindex 36d4eadc8e..5c470cfb67 100644--- a/invokeai/frontend/webv2/src/platform/ui/Select.tsx+++ b/invokeai/frontend/webv2/src/platform/ui/Select.tsx@@ -25,6 +25,11 @@ const renderDefaultItem = <T extends CollectionItem>(item: T): ReactNode => {export interface SelectProps<T extends CollectionItem> extends Omit<SelectRootProps<T>, 'children'> {contentProps?: SelectContentProps;+ /**+ * Caps the open menu's height; the content element itself scrolls, which is+ * the element the select machine scrolls the highlighted item within.+ */+ itemsMaxH?: string;getItemKey?: (item: T, index: number) => Key;indicatorGroupProps?: SelectIndicatorGroupProps;itemIndicator?: boolean;@@ -43,6 +48,7 @@ export const Select = <T extends CollectionItem>({contentProps,getItemKey = getDefaultItemKey,indicatorGroupProps,+ itemsMaxH,itemIndicator = true,portalled = true,positionerProps,@@ -73,7 +79,7 @@ export const Select = <T extends CollectionItem>({</ChakraSelect.Control><Portal disabled={!portalled}><ChakraSelect.Positioner {...positionerProps}>- <ChakraSelect.Content {...contentProps}>+ <ChakraSelect.Content maxH={itemsMaxH} overflowY={itemsMaxH ? 'auto' : undefined} {...contentProps}>{collection.items.map((item, index) => (<ChakraSelect.Item key={getItemKey(item, index)} item={item}><ChakraSelect.ItemText>{renderItem(item)}</ChakraSelect.ItemText>diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerBlendRow.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerBlendRow.tsxindex 617721f255..886efbde22 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerBlendRow.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerBlendRow.tsx@@ -1,14 +1,9 @@import type { NumberInput as ChakraNumberInput, SelectValueChangeDetails } from '@chakra-ui/react';-import type {- CanvasBlendMode,- CanvasDocumentContractV3,- CanvasLayerContract,- CanvasMaskFillContract,-} from '@workbench/canvas-engine/api';+import type { CanvasBlendMode, CanvasDocumentContractV3, CanvasLayerContract } from '@workbench/canvas-engine/api';import type { CanvasEngineHandle } from '@workbench/widgets/canvas/useCanvasEngine';-import { Box, createListCollection, Flex, HStack, NumberInput } from '@chakra-ui/react';-import { ColorPicker, Field, Select } from '@platform/ui';+import { createListCollection, Flex, HStack, NumberInput } from '@chakra-ui/react';+import { Field, Select } from '@platform/ui';import { getDocumentLayer } from '@workbench/canvas-engine/api';import { useCanvasDocumentEditingLocked } from '@workbench/widgets/canvas/engineStoreHooks';import { usePreparedCommit } from '@workbench/widgets/canvas/useStructuralCommit';@@ -23,12 +18,6 @@ const SELECT_POSITIONING = { placement: 'bottom-start', sameWidth: true } as conconst clamp01 = (value: number): number => Math.min(1, Math.max(0, value));-/** A mask layer whose fill colour the row's swatch edits (inpaint mask / region). */-type MaskLayer = Extract<CanvasLayerContract, { type: 'inpaint_mask' | 'regional_guidance' }>;--const isMaskLayer = (layer: CanvasLayerContract | null): layer is MaskLayer =>- layer !== null && (layer.type === 'inpaint_mask' || layer.type === 'regional_guidance');-// Reference equality is exact: the document index hands back the same node// object until the layer itself changes.const selectSelectedLayer = (project: {@@ -101,6 +90,7 @@ const BlendModeControl = ({aria-label={t('widgets.layers.actions.blendMode')}collection={blendCollection}disabled={disabled}+ itemsMaxH="16rem"minW="7rem"positioning={SELECT_POSITIONING}size="xs"@@ -224,78 +214,7 @@ const OpacityRow = ({onKeyUp={handleInputKeyUp}/></NumberInput.Root>- {isMaskLayer(layer) ? <MaskFillSwatch disabled={editingLocked} engine={engine} layer={layer} /> : null}</HStack></Field>);};--/**- * The selected mask layer's fill-colour swatch (legacy `ActionBarFill`): a colour- * swatch that opens the picker. Live edits during the drag are un-recorded; the- * final colour lands as one undoable history entry, mirroring the slider pattern.- */-const MaskFillSwatch = ({- disabled,- engine,- layer,-}: {- disabled: boolean;- engine: LayerBlendRowEngine | null;- layer: MaskLayer;-}) => {- const commitPrepared = usePreparedCommit(engine);- const { t } = useTranslation();- const fillBeforeRef = useRef<CanvasMaskFillContract | null>(null);- const fill = layer.mask.fill;-- const patchFill = useCallback(- (next: CanvasMaskFillContract, before: CanvasMaskFillContract) => {- const configFor = (value: CanvasMaskFillContract) =>- layer.type === 'inpaint_mask'- ? ({ layerType: 'inpaint_mask', mask: { fill: value } } as const)- : ({ layerType: 'regional_guidance', mask: { fill: value } } as const);- commitPrepared(t('widgets.layers.maskFill.fill'), (model) =>- model.prepare({ before: configFor(before), config: configFor(next), id: layer.id, type: 'patch-config' })- );- },- [commitPrepared, layer.id, layer.type, t]- );-- const handleColorChange = useCallback(- (hex: string) => {- const next = { ...fill, color: hex };- const config =- layer.type === 'inpaint_mask'- ? ({ layerType: 'inpaint_mask', mask: { fill: next } } as const)- : ({ layerType: 'regional_guidance', mask: { fill: next } } as const);- if (!applyStructuralPreview(engine, { config, id: layer.id, type: 'updateCanvasLayerConfig' })) {- return;- }- if (fillBeforeRef.current === null) {- fillBeforeRef.current = fill;- }- },- [engine, fill, layer.id, layer.type]- );-- const handleColorChangeEnd = useCallback(- (hex: string) => {- const before = fillBeforeRef.current ?? fill;- fillBeforeRef.current = null;- patchFill({ ...before, color: hex }, before);- },- [fill, patchFill]- );-- return (- <Box aria-disabled={disabled} inert={disabled} opacity={disabled ? 0.5 : 1}>- <ColorPicker- aria-label={t('widgets.layers.maskFill.color')}- value={fill.color}- onValueChange={handleColorChange}- onValueChangeEnd={handleColorChangeEnd}- />- </Box>- );-};diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerStackHeader.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerStackHeader.tsxindex 29de5842b2..0118e5bf5c 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerStackHeader.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerStackHeader.tsx@@ -93,7 +93,7 @@ const LayerStackHeaderComponent = ({aria-level={1}aria-posinset={posInSet}aria-setsize={setSize}- bg="bg.panel"+ bg={pinned ? 'bg.panel' : 'transparent'}data-layer-row-id={pinned ? undefined : rowKey}h="full"role={pinned ? undefined : 'treeitem'}diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersTree.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersTree.tsxindex 4241cf57b2..5246edfc52 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersTree.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersTree.tsx@@ -63,7 +63,8 @@ interface DragState {/** How many selected rows travel, the number the ghost shows. */readonly selectedCount: number;readonly overId: string | null;- readonly edge: 'above' | 'below';+ readonly overIsGroup: boolean;+ readonly edge: 'above' | 'inside' | 'below';readonly depthOffset: number;}@@ -81,8 +82,24 @@ interface LayersTreeProps {}/** Which half of the row under the pointer it sits in. */-const edgeOf = (rect: { top: number; height: number } | undefined, y: number): 'above' | 'below' =>- rect && y >= rect.top + rect.height / 2 ? 'below' : 'above';+/**+ * Groups expose a middle band that drops INTO them — the only comfortable way+ * into an empty group; leaves split at the midline as before.+ */+const edgeOf = (+ rect: { top: number; height: number } | undefined,+ y: number,+ overIsGroup: boolean+): 'above' | 'inside' | 'below' => {+ if (!rect) {+ return 'above';+ }+ if (overIsGroup) {+ const fraction = (y - rect.top) / rect.height;+ return fraction < 0.3 ? 'above' : fraction > 0.7 ? 'below' : 'inside';+ }+ return y >= rect.top + rect.height / 2 ? 'below' : 'above';+};const isMenuKey = (event: KeyboardEvent<HTMLElement>): boolean =>event.key === 'ContextMenu' || (event.key === 'F10' && event.shiftKey);@@ -97,7 +114,9 @@ const anchorOfItem = (host: HTMLElement | null, key: string): LayerSurfaceAnchorconst VirtualSlot = ({ children, size, start }: { children: ReactNode; size: number; start: number }) => {const style = useMemo(() => ({ height: size, top: start }), [size, start]);return (- <Box left="0" position="absolute" right="0" role="presentation" style={style}>+ // Absolute children ignore the container's padding; the slot carries the+ // panel-edge inset itself, and the indicator and pinned header match it.+ <Box left="1.5" position="absolute" right="1.5" role="presentation" style={style}>{children}</Box>);@@ -600,6 +619,7 @@ export const LayersTree = ({depthOffset: 0,edge: 'above',overId: null,+ overIsGroup: false,selectedCount: [...travelling].filter((id) => selected.has(id)).length,stack,travelling,@@ -611,27 +631,31 @@ export const LayersTree = ({const depthOffset = Math.round(event.delta.x / LAYER_TREE_INDENT_PX);pointerY.current = pointerStart.current.y + event.delta.y;autoScroller.current?.update(pointerY.current);- const edge = edgeOf(event.over?.rect, pointerY.current);- setDrag((current) =>- current && (current.depthOffset !== depthOffset || current.edge !== edge)- ? { ...current, depthOffset, edge }- : current- );+ setDrag((current) => {+ if (!current) {+ return current;+ }+ const edge = edgeOf(event.over?.rect, pointerY.current, current.overIsGroup);+ return current.depthOffset !== depthOffset || current.edge !== edge ? { ...current, depthOffset, edge } : current;+ });}, []);const handleDragOver = useCallback((event: DragOverEvent) => {const overId = event.over ? String(event.over.id) : null;- // The pointer may enter a row between move events; the edge follows the row it is over now.- const edge = edgeOf(event.over?.rect, pointerY.current);- setDrag((current) =>- current && (current.overId !== overId || current.edge !== edge) ? { ...current, edge, overId } : current- );clearHoverTimer();const current = dragRef.current;const over =overId && current && overId !== current.activeId? stacks[current.stack].rows.find((row) => row.id === overId): undefined;+ const overIsGroup = over?.vm.kind === 'group';+ // The pointer may enter a row between move events; the edge follows the row it is over now.+ const edge = edgeOf(event.over?.rect, pointerY.current, overIsGroup);+ setDrag((state) =>+ state && (state.overId !== overId || state.edge !== edge || state.overIsGroup !== overIsGroup)+ ? { ...state, edge, overId, overIsGroup }+ : state+ );if (over && over.vm.kind === 'group' && !over.expanded && over.vm.childCount > 0) {hoverTimer.current = setTimeout(() => setLayerGroupExpanded(projectId, primaryId, [over.id], true),@@ -698,7 +722,7 @@ export const LayersTree = ({const last = stackRows[stackRows.length - 1]!;top = offsets[rowIndexByKey.get(last.id)! + 1]!;}- return { left: target.depth * LAYER_TREE_INDENT_PX + 8, top };+ return { left: target.depth * LAYER_TREE_INDENT_PX + 14, top };}, [drag, offsets, rowIndexByKey, stacks, target]);const refusalReason = refusal@@ -859,9 +883,9 @@ export const LayersTree = ({borderBottomWidth="1px"borderColor="border.subtle"h={`${LAYER_HEADER_HEIGHT_PX}px`}- left="0"+ left="1.5"position="absolute"- right="0"+ right="1.5"style={pinnedStyle}top="0"zIndex="1"diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/layerTreeDrop.ts b/invokeai/frontend/webv2/src/workbench/widgets/layers/layerTreeDrop.tsindex a2f9662250..3536952523 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/layerTreeDrop.ts+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/layerTreeDrop.ts@@ -1,6 +1,6 @@import type { LayerStackKind } from '@workbench/canvas-engine/api';-import { CANVAS_MAX_NODE_DEPTH } from '@workbench/canvas-engine/api';+import { CANVAS_MAX_NODE_DEPTH, isGroupNode } from '@workbench/canvas-engine/api';import type { LayerTreeRow } from './layerTreeRows';@@ -24,8 +24,8 @@ export interface LayerDropInput {/** Every selected id that drags along; descendants of another dragged id are folded in. */readonly activeIds: readonly string[];readonly overId: string;- /** Whether the pointer sits in the upper or lower half of the row it is over. */- readonly edge: 'above' | 'below';+ /** Where the pointer sits on the row it is over; `inside` (group rows only) nests into it. */+ readonly edge: 'above' | 'inside' | 'below';/** How many indent steps the pointer has moved horizontally since the drag began. */readonly depthOffset: number;}@@ -94,6 +94,32 @@ export const projectLayerDrop = (input: LayerDropInput): LayerDropTarget | nullif (overIndex < 0) {return null;}+ if (input.edge === 'inside') {+ // Straight into the hovered group, at its top — the one comfortable way+ // into an empty group. The depth limit still applies to the whole block.+ const over = remaining[overIndex]!;+ if (over.vm.kind !== 'group') {+ return null;+ }+ const depth = over.vm.depth + 1;+ if (depth + deepestSubtree > CANVAS_MAX_NODE_DEPTH) {+ return null;+ }+ const next = remaining[overIndex + 1];+ // Top of the group: the first rendered child, or — for a collapsed group,+ // whose children render nothing — its first model child, so the landing+ // matches the indicator instead of quietly falling to the bottom.+ const firstModelChildId = isGroupNode(over.vm.node) ? (over.vm.node.children[0]?.id ?? null) : null;+ const beforeId = next && next.vm.parentId === over.id ? next.id : over.expanded ? null : firstModelChildId;+ return {+ beforeId,+ beforeRowId: next?.id ?? null,+ depth,+ ids: outer.map((row) => row.id),+ parentId: over.id,+ stack: rows[0]!.vm.stack,+ };+ }const insertAt = input.edge === 'above' ? overIndex : overIndex + 1;const previous = remaining[insertAt - 1];const next = remaining[insertAt];diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/layerTreeRows.test.ts b/invokeai/frontend/webv2/src/workbench/widgets/layers/layerTreeRows.test.tsindex 8e649fb8ab..897cdeb401 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/layerTreeRows.test.ts+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/layerTreeRows.test.ts@@ -83,6 +83,46 @@ describe('buildLayerStackRows', () => {describe('projectLayerDrop', () => {const rows = () => buildLayerStackRows(document().stacks, new Set(['G', 'H'])).raster.rows;+ it('nests into a hovered group on the inside edge, including an empty one', () => {+ // Into G, at its top, above its first rendered child.+ expect(+ projectLayerDrop({ activeIds: ['r5'], depthOffset: 0, edge: 'inside', overId: 'G', rows: rows() })+ ).toMatchObject({+ beforeId: 'r2',+ depth: 1,+ ids: ['r5'],+ parentId: 'G',+ stack: 'raster',+ });+ // An empty expanded group has no child rows; the inside edge is the way in.+ const withEmpty = documentFrom([layer('r1'), group('E', []), layer('r5')]);+ const emptyRows = buildLayerStackRows(withEmpty.stacks, new Set(['E'])).raster.rows;+ expect(+ projectLayerDrop({ activeIds: ['r5'], depthOffset: 0, edge: 'inside', overId: 'E', rows: emptyRows })+ ).toMatchObject({+ beforeId: null,+ depth: 1,+ ids: ['r5'],+ parentId: 'E',+ stack: 'raster',+ });+ // A COLLAPSED group with children drops at its top via the model child.+ const collapsedRows = buildLayerStackRows(document().stacks, new Set()).raster.rows;+ expect(+ projectLayerDrop({ activeIds: ['r5'], depthOffset: 0, edge: 'inside', overId: 'G', rows: collapsedRows })+ ).toMatchObject({+ beforeId: 'r2',+ depth: 1,+ ids: ['r5'],+ parentId: 'G',+ stack: 'raster',+ });+ // The inside edge means nothing on a leaf.+ expect(+ projectLayerDrop({ activeIds: ['r5'], depthOffset: 0, edge: 'inside', overId: 'r1', rows: rows() })+ ).toBeNull();+ });+it('drops between siblings at the same depth', () => {expect(projectLayerDrop({ activeIds: ['r5'], depthOffset: 0, edge: 'above', overId: 'r1', rows: rows() })