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(webv2): move widget actions into manifest chrome
joshistoast0a1680189ec3
diff --git a/invokeai/frontend/webv2/src/workbench/components/WidgetRenderer.tsx b/invokeai/frontend/webv2/src/workbench/components/WidgetRenderer.tsxindex f44cdaeef1..79ce094a1e 100644--- a/invokeai/frontend/webv2/src/workbench/components/WidgetRenderer.tsx+++ b/invokeai/frontend/webv2/src/workbench/components/WidgetRenderer.tsx@@ -1,5 +1,8 @@+import { Box, Flex, Text } from '@chakra-ui/react';+import type { RegisteredWidget, WidgetViewProps } from '../types';import { WidgetFailureBoundary } from './WidgetFailureBoundary';+import { WidgetHeader, WidgetPanelFrame } from './WidgetFrames';interface WidgetRendererProps extends Omit<WidgetViewProps, 'manifest'> {widget: RegisteredWidget;@@ -13,10 +16,115 @@ export const WidgetRenderer = ({ presentation, region, widget }: WidgetRendererP}const content = <View manifest={widget.manifest} presentation={presentation} region={region} />;+ const framedContent = (+ <WidgetShellFrame content={content} presentation={presentation} region={region} widget={widget} />+ );if (!widget.manifest.failurePolicy.isolateRenderFailure) {+ return framedContent;+ }++ return <WidgetFailureBoundary widgetId={widget.manifest.id}>{framedContent}</WidgetFailureBoundary>;+};++const WidgetShellFrame = ({+ content,+ presentation,+ region,+ widget,+}: {+ content: React.ReactNode;+ presentation: WidgetViewProps['presentation'];+ region: WidgetViewProps['region'];+ widget: RegisteredWidget;+}) => {+ if (region === 'popover' || region === 'dialog' || presentation === 'compact' || presentation === 'tooltip') {return content;}- return <WidgetFailureBoundary widgetId={widget.manifest.id}>{content}</WidgetFailureBoundary>;+ if (region === 'left' || region === 'right' || region === 'bottom') {+ return (+ <WidgetPanelFrame region={region}>+ <HeaderSlot presentation={presentation} region={region} widget={widget} />+ <PanelBodySlot>{content}</PanelBodySlot>+ <FooterSlot presentation={presentation} region={region} widget={widget} />+ </WidgetPanelFrame>+ );+ }++ return (+ <Flex bg="bg.canvas" direction="column" gap="3" h="full" minH="0" p="3" w="full">+ <HeaderSlot presentation={presentation} region={region} widget={widget} />+ <Box flex="1" minH="0" overflow="hidden" position="relative">+ {content}+ </Box>+ <FooterSlot presentation={presentation} region={region} widget={widget} />+ </Flex>+ );+};++const HeaderSlot = ({+ presentation,+ region,+ widget,+}: {+ presentation: WidgetViewProps['presentation'];+ region: WidgetViewProps['region'];+ widget: RegisteredWidget;+}) => {+ if (widget.manifest.chrome?.header === 'hidden') {+ return null;+ }++ const HeaderActions = widget.manifest.headerActions;+ const actions = HeaderActions ? (+ <HeaderActions manifest={widget.manifest} presentation={presentation} region={region} />+ ) : null;+ const bg = region === 'center' ? 'bg.canvas' : 'bg.shell';++ return (+ <Box bg={bg} flexShrink={0}>+ <WidgetHeader actions={actions} manifest={widget.manifest} region={region} />+ </Box>+ );+};++const PanelBodySlot = ({ children }: { children: React.ReactNode }) => (+ <Flex direction="column" flex="1" minH="0" minW="0" overflowX="hidden" overflowY="auto">+ {children}+ </Flex>+);++const FooterSlot = ({+ presentation,+ region,+ widget,+}: {+ presentation: WidgetViewProps['presentation'];+ region: WidgetViewProps['region'];+ widget: RegisteredWidget;+}) => {+ const Footer = widget.manifest.footer;++ if (!Footer) {+ return null;+ }+ const bg = region === 'center' ? 'bg.canvas' : 'bg.shell';++ return (+ <Box bg={bg} flexShrink={0}>+ <Footer manifest={widget.manifest} presentation={presentation} region={region} />+ </Box>+ );};++export const MissingWidgetFrame = ({ label, region }: { label: string; region: 'bottom' | 'left' | 'right' }) => (+ <WidgetPanelFrame region={region}>+ <Text fontSize="xs" fontWeight="700">+ {label}+ </Text>+ <Text color="fg.subtle" fontSize="2xs">+ Widget view unavailable.+ </Text>+ </WidgetPanelFrame>+);diff --git a/invokeai/frontend/webv2/src/workbench/widgets/history-controls/index.ts b/invokeai/frontend/webv2/src/workbench/widgets/history-controls/index.tsindex dc2bd532ad..0d94d5ad56 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/history-controls/index.ts+++ b/invokeai/frontend/webv2/src/workbench/widgets/history-controls/index.ts@@ -2,12 +2,13 @@ import type { WidgetManifest } from '../../types';import { HistoryControlsWidgetView } from './HistoryControlsWidgetView';export const historyControlsWidgetManifest: WidgetManifest = {+ centerPlacement: 'toolbar',failurePolicy: { isolateRenderFailure: true, onRegistrationFailure: 'disable' },icon: 'lucide-react:undo-2',id: 'history-controls',label: 'History Controls',labelText: 'History Controls',- regions: ['bottom'],+ regions: ['bottom', 'center'],version: 1,view: HistoryControlsWidgetView,};diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersHeaderActions.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersHeaderActions.tsxnew file mode 100644index 0000000000..9b05682735--- /dev/null+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersHeaderActions.tsx@@ -0,0 +1,8 @@+import { IconButton } from '@chakra-ui/react';+import { PiDotsThreeBold } from 'react-icons/pi';++export const LayersHeaderActions = () => (+ <IconButton aria-label="Layer options" color="fg.muted" size="2xs" variant="ghost">+ <PiDotsThreeBold />+ </IconButton>+);diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersWidgetView.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersWidgetView.tsxindex 8721eaff10..d63e3d714d 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersWidgetView.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersWidgetView.tsx@@ -1,58 +1,81 @@-import { Flex, HStack, Icon, IconButton, Stack, Text } from '@chakra-ui/react';-import { PiDotsThreeBold, PiStackBold } from 'react-icons/pi';+import { Box, Flex, HStack, Icon, Stack, Text } from '@chakra-ui/react';+import { PiStackBold } from 'react-icons/pi';-import { WidgetPanelFrame } from '../../components/WidgetFrames';-import { WidgetFailureBoundary } from '../../components/WidgetFailureBoundary';import { useWorkbench } from '../../WorkbenchContext';export const LayersWidgetView = () => {const { activeProject } = useWorkbench();+ const layers = activeProject.canvas.document.layers;return (- <WidgetFailureBoundary widgetId="layers">- <WidgetPanelFrame region="right">- <HStack justify="space-between">- <Text fontSize="xs" fontWeight="700">- Layers- </Text>- <IconButton aria-label="Layer options" color="fg.muted" size="2xs" variant="ghost">- <PiDotsThreeBold />- </IconButton>- </HStack>- <Flex- align="center"- borderWidth="1px"- borderColor="border.subtle"- borderStyle="dashed"- color="fg.subtle"- direction="column"- gap="2"- justify="center"- minH="8rem"- rounded="md"- p="4"- >- <Icon as={PiStackBold} boxSize="6" />- <Text fontSize="2xs" textAlign="center">- {activeProject.canvas.layers.length} layers, {activeProject.canvas.stagingArea.pendingImageIds.length}{' '}- staged images.- </Text>- </Flex>- <Stack bg="bg.surface" borderWidth="1px" borderColor="border.subtle" gap="1" p="2" rounded="md">- <Text color="fg.muted" fontSize="2xs" fontWeight="700" textTransform="uppercase">- Project Contracts- </Text>- <Text color="fg.subtle" fontSize="2xs">- Graph history: {activeProject.graphHistory.length}- </Text>- <Text color="fg.subtle" fontSize="2xs">- Events: {activeProject.events.length}- </Text>+ <>+ <Flex+ align="center"+ borderWidth="1px"+ borderColor="border.subtle"+ borderStyle="dashed"+ color="fg.subtle"+ direction="column"+ gap="2"+ justify="center"+ minH="8rem"+ rounded="md"+ p="4"+ >+ <Icon as={PiStackBold} boxSize="6" />+ <Text fontSize="2xs" textAlign="center">+ {layers.length} layers, {activeProject.canvas.stagingArea.pendingImageIds.length} staged images.+ </Text>+ </Flex>+ <Stack bg="bg.surface" borderWidth="1px" borderColor="border.subtle" gap="2" p="2" rounded="md">+ {layers.length === 0 ? (<Text color="fg.subtle" fontSize="2xs">- Undo: {activeProject.undoRedo.past.length} / Redo: {activeProject.undoRedo.future.length}+ Accepted canvas layers will appear here.</Text>- </Stack>- </WidgetPanelFrame>- </WidgetFailureBoundary>+ ) : (+ layers.map((layer) => (+ <HStack key={layer.id} gap="2">+ <Box+ bg="bg.panel"+ borderWidth="1px"+ borderColor="border.subtle"+ h="10"+ overflow="hidden"+ rounded="sm"+ w="10"+ >+ <img+ alt={layer.label}+ src={layer.thumbnailUrl || layer.imageUrl}+ style={{ height: '100%', objectFit: 'cover', width: '100%' }}+ />+ </Box>+ <Stack gap="0" minW="0">+ <Text fontSize="2xs" fontWeight="700" truncate>+ {layer.label}+ </Text>+ <Text color="fg.subtle" fontSize="2xs" truncate>+ {layer.width} x {layer.height}+ </Text>+ </Stack>+ </HStack>+ ))+ )}+ </Stack>+ <Stack bg="bg.surface" borderWidth="1px" borderColor="border.subtle" gap="1" p="2" rounded="md">+ <Text color="fg.muted" fontSize="2xs" fontWeight="700" textTransform="uppercase">+ Project Contracts+ </Text>+ <Text color="fg.subtle" fontSize="2xs">+ Graph history: {activeProject.graphHistory.length}+ </Text>+ <Text color="fg.subtle" fontSize="2xs">+ Events: {activeProject.events.length}+ </Text>+ <Text color="fg.subtle" fontSize="2xs">+ Undo: {activeProject.undoRedo.past.length} / Redo: {activeProject.undoRedo.future.length}+ </Text>+ </Stack>+ </>);};diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/index.ts b/invokeai/frontend/webv2/src/workbench/widgets/layers/index.tsindex c9ee9c139e..c1f3464c7b 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/index.ts+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/index.ts@@ -1,8 +1,10 @@import type { WidgetManifest } from '../../types';+import { LayersHeaderActions } from './LayersHeaderActions';import { LayersWidgetView } from './LayersWidgetView';export const layersWidgetManifest: WidgetManifest = {failurePolicy: { isolateRenderFailure: true, onRegistrationFailure: 'disable' },+ headerActions: LayersHeaderActions,icon: 'lucide-react:layers',id: 'layers',label: 'Layers',diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layout-actions/LayoutActionsWidgetView.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layout-actions/LayoutActionsWidgetView.tsxindex 6890352042..8dc39e8b49 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/layout-actions/LayoutActionsWidgetView.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/layout-actions/LayoutActionsWidgetView.tsx@@ -1,69 +1,7 @@-import { Button, HStack, Stack, Text } from '@chakra-ui/react';+import { Text } from '@chakra-ui/react';-import type { WidgetViewProps } from '../../types';-import { useWorkbench } from '../../WorkbenchContext';--export const LayoutActionsWidgetView = ({ presentation }: WidgetViewProps) => {- const { dispatch } = useWorkbench();-- if (presentation === 'expanded') {- return (- <Stack align="start" gap="2">- <Text fontSize="xs" fontWeight="700">- Layout Actions- </Text>- <LayoutButtons- onRecoverLayout={() => dispatch({ type: 'recoverShellLayout' })}- onResetLayout={() => dispatch({ type: 'resetActiveLayout' })}- />- <Text color="fg.subtle" fontSize="2xs">- Reset restores the active preset. Recover reopens the shell regions.- </Text>- </Stack>- );- }-- return (- <LayoutButtons- onRecoverLayout={() => dispatch({ type: 'recoverShellLayout' })}- onResetLayout={() => dispatch({ type: 'resetActiveLayout' })}- />- );-};--const LayoutButtons = ({- onRecoverLayout,- onResetLayout,-}: {- onRecoverLayout: () => void;- onResetLayout: () => void;-}) => (- <HStack gap="1">- <Button- color="fg.muted"- fontSize="2xs"- size="2xs"- variant="ghost"- _hover={{ color: 'fg.default' }}- onClick={(event) => {- event.stopPropagation();- onResetLayout();- }}- >- Reset Layout- </Button>- <Button- color="fg.muted"- fontSize="2xs"- size="2xs"- variant="ghost"- _hover={{ color: 'fg.default' }}- onClick={(event) => {- event.stopPropagation();- onRecoverLayout();- }}- >- Recover Layout- </Button>- </HStack>+export const LayoutActionsWidgetView = () => (+ <Text color="fg.subtle" fontSize="2xs">+ Reset restores the active preset. Recover reopens the shell regions.+ </Text>);diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layout-actions/LayoutHeaderActions.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layout-actions/LayoutHeaderActions.tsxnew file mode 100644index 0000000000..b907747229--- /dev/null+++ b/invokeai/frontend/webv2/src/workbench/widgets/layout-actions/LayoutHeaderActions.tsx@@ -0,0 +1,38 @@+import { Button, HStack } from '@chakra-ui/react';++import { useWorkbench } from '../../WorkbenchContext';++export const LayoutHeaderActions = () => {+ const { dispatch } = useWorkbench();++ return (+ <HStack gap="1">+ <Button+ color="fg.muted"+ fontSize="2xs"+ size="2xs"+ variant="ghost"+ _hover={{ color: 'fg.default' }}+ onClick={(event) => {+ event.stopPropagation();+ dispatch({ type: 'resetActiveLayout' });+ }}+ >+ Reset Layout+ </Button>+ <Button+ color="fg.muted"+ fontSize="2xs"+ size="2xs"+ variant="ghost"+ _hover={{ color: 'fg.default' }}+ onClick={(event) => {+ event.stopPropagation();+ dispatch({ type: 'recoverShellLayout' });+ }}+ >+ Recover Layout+ </Button>+ </HStack>+ );+};diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layout-actions/index.ts b/invokeai/frontend/webv2/src/workbench/widgets/layout-actions/index.tsindex 7352e40c6f..a6c342ff2a 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/layout-actions/index.ts+++ b/invokeai/frontend/webv2/src/workbench/widgets/layout-actions/index.ts@@ -1,8 +1,10 @@import type { WidgetManifest } from '../../types';+import { LayoutHeaderActions } from './LayoutHeaderActions';import { LayoutActionsWidgetView } from './LayoutActionsWidgetView';export const layoutActionsWidgetManifest: WidgetManifest = {failurePolicy: { isolateRenderFailure: true, onRegistrationFailure: 'disable' },+ headerActions: LayoutHeaderActions,icon: 'lucide-react:panel-bottom',id: 'layout-actions',label: 'Layout Actions',