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(webv2): add workflow field reset controls
joshistoastec6ecf1afc65
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/workflow/editor/InvocationFlowNode.tsx b/invokeai/frontend/webv2/src/workbench/widgets/workflow/editor/InvocationFlowNode.tsxindex 5e399d1856..3e399ab8fa 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/workflow/editor/InvocationFlowNode.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/workflow/editor/InvocationFlowNode.tsx@@ -15,21 +15,32 @@ import { WorkflowFieldInput } from '@workbench/widgets/workflow/fields/WorkflowFimport { useWorkbenchDispatch } from '@workbench/WorkbenchContext';import { isExecutableInvocationType } from '@workbench/workflows/buildGraph';import {+ cloneWorkflowFieldDefault,getFieldTypeColor,getFieldTypeLabel,getWorkflowFieldInvalidReason,isDirectInputField,isExposableField,+ isWorkflowFieldValueDefault,isModelFieldType,} from '@workbench/workflows/fields';import { useInvocationTemplatesSnapshot } from '@workbench/workflows/templates';import { Handle, Position, useStore, type NodeProps } from '@xyflow/react';-import { ChevronDownIcon, ChevronRightIcon, InfoIcon, PinIcon, PinOffIcon, TriangleAlertIcon } from 'lucide-react';+import {+ ChevronDownIcon,+ ChevronRightIcon,+ InfoIcon,+ PinIcon,+ PinOffIcon,+ RotateCcwIcon,+ TriangleAlertIcon,+} from 'lucide-react';import { memo, useState, type ChangeEvent, type KeyboardEvent } from 'react';import type { InvocationFlowNode as InvocationFlowNodeType } from './flowAdapters';import { getHandleTypeTooltip } from './handleTooltip';+import { getWorkflowNodeChromeProps } from './nodeChrome';const NODE_WIDTH = '18rem';const HANDLE_SIZE = 12;@@ -97,16 +108,10 @@ const NodeShell = ({return (<Boxbg="bg"- borderColor={- isInvalid ? 'red.solid' : selected ? 'accent.solid' : isRunning ? 'brand.solid' : 'border.emphasized'- }- borderWidth="1px"fontSize="xs"rounded="lg"- shadow={isRunning ? '0 0 10px {colors.brand.solid/50}' : selected ? 'md' : 'sm'}- transition="border-color 0.12s ease, box-shadow 0.12s ease"w={NODE_WIDTH}- _hover={selected || isInvalid ? undefined : { borderColor: 'brand.solid', shadow: 'md' }}+ {...getWorkflowNodeChromeProps({ invalid: isInvalid, running: isRunning, selected })}>{children}</Box>@@ -352,6 +357,7 @@ const InputFieldRow = ({});const isInvalid = invalidReason !== null;const handleTooltip = getHandleTypeTooltip(template.type);+ const canReset = showsControl && !isWorkflowFieldValueDefault(template, instance?.value);if (isSkeleton) {return (@@ -418,6 +424,31 @@ const InputFieldRow = ({</Text></Tooltip><HStack flexShrink={0} gap="0" ml="auto">+ {canReset ? (+ <Tooltip content="Reset to default value">+ <IconButton+ aria-label={`Reset ${label} to default value`}+ className="nodrag"+ color="fg.subtle"+ size="2xs"+ title="Reset to default value"+ variant="ghost"+ onClick={() =>+ dispatch({+ action: {+ fieldName: template.name,+ nodeId: node.id,+ type: 'setFieldValue',+ value: cloneWorkflowFieldDefault(template),+ },+ type: 'applyProjectGraphAction',+ })+ }+ >+ <Icon as={RotateCcwIcon} boxSize="3" />+ </IconButton>+ </Tooltip>+ ) : null}<FieldDescriptionPopoverdescription={instance?.description}fieldName={template.name}diff --git a/invokeai/frontend/webv2/src/workbench/widgets/workflow/linear/NodeFieldControl.tsx b/invokeai/frontend/webv2/src/workbench/widgets/workflow/linear/NodeFieldControl.tsxindex 9c32421ee6..99121fc0d6 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/workflow/linear/NodeFieldControl.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/workflow/linear/NodeFieldControl.tsx@@ -1,13 +1,19 @@import type { NodeFieldFormElement, ProjectGraphState } from '@workbench/workflows/types';-import { Alert, Field, Input, Stack, Text } from '@chakra-ui/react';-import { FieldLabel, Tooltip } from '@workbench/components/ui';+import { Alert, Field, HStack, Icon, Input, Stack, Text } from '@chakra-ui/react';+import { FieldLabel, IconButton, Tooltip } from '@workbench/components/ui';import { WorkflowFieldInput } from '@workbench/widgets/workflow/fields/WorkflowFieldInput';import { useWorkbenchDispatch } from '@workbench/WorkbenchContext';import { getResolvedWorkflowEdges } from '@workbench/workflows/connectors';-import { getWorkflowFieldInvalidReason } from '@workbench/workflows/fields';+import {+ cloneWorkflowFieldDefault,+ getWorkflowFieldInvalidReason,+ isDirectInputField,+ isWorkflowFieldValueDefault,+} from '@workbench/workflows/fields';import { useInvocationTemplatesSnapshot } from '@workbench/workflows/templates';import { isInvocationNode } from '@workbench/workflows/types';+import { RotateCcwIcon } from 'lucide-react';import { useState, type ChangeEvent } from 'react';/**@@ -66,42 +72,70 @@ export const NodeFieldControl = ({const description = instance?.description || template.description;const invalidReason = getWorkflowFieldInvalidReason({ isConnected, template, value: instance?.value });const isInvalid = invalidReason !== null;+ const canReset =+ !isConnected && isDirectInputField(template) && !isWorkflowFieldValueDefault(template, instance?.value);const labelInputId = `${element.id}-label-input`;const valueInputId = `${element.id}-value`;+ const resetButton = canReset ? (+ <Tooltip content="Reset to default value">+ <IconButton+ aria-label={`Reset ${label} to default value`}+ color="fg.subtle"+ flexShrink={0}+ size="2xs"+ title="Reset to default value"+ variant="ghost"+ onClick={() =>+ dispatch({+ action: { fieldName, nodeId, type: 'setFieldValue', value: cloneWorkflowFieldDefault(template) },+ type: 'applyProjectGraphAction',+ })+ }+ >+ <Icon as={RotateCcwIcon} boxSize="3" />+ </IconButton>+ </Tooltip>+ ) : null;return (<Field.Root invalid={isInvalid} minW="0" w="full"><Stack gap="1" minW="0" w="full">{isLabelEditable ? (- <Input- aria-label="Field label"- color={isInvalid ? 'fg.error' : 'fg.muted'}- fontSize="2xs"- fontWeight="600"- h="5"- id={labelInputId}- placeholder={template.title}- size="2xs"- textTransform="uppercase"- value={draftLabel ?? label}- variant="flushed"- w="full"- onBlur={() => setDraftLabel(null)}- onChange={(event: ChangeEvent<HTMLInputElement>) => {- setDraftLabel(event.currentTarget.value);- dispatch({- action: { fieldName, label: event.currentTarget.value, nodeId, type: 'setFieldLabel' },- type: 'applyProjectGraphAction',- });- }}- onFocus={() => setDraftLabel(label)}- />+ <HStack gap="1" minW="0" w="full">+ <Input+ aria-label="Field label"+ color={isInvalid ? 'fg.error' : 'fg.muted'}+ fontSize="2xs"+ fontWeight="600"+ h="5"+ id={labelInputId}+ placeholder={template.title}+ size="2xs"+ textTransform="uppercase"+ value={draftLabel ?? label}+ variant="flushed"+ w="full"+ onBlur={() => setDraftLabel(null)}+ onChange={(event: ChangeEvent<HTMLInputElement>) => {+ setDraftLabel(event.currentTarget.value);+ dispatch({+ action: { fieldName, label: event.currentTarget.value, nodeId, type: 'setFieldLabel' },+ type: 'applyProjectGraphAction',+ });+ }}+ onFocus={() => setDraftLabel(label)}+ />+ {resetButton}+ </HStack>) : (- <Tooltip content={`${nodeContext} → ${template.title}`}>- <Stack color={isInvalid ? 'fg.error' : undefined} gap="0" minW="0" w="full">- <FieldLabel>{label}</FieldLabel>- </Stack>- </Tooltip>+ <HStack gap="1" minW="0" w="full">+ <Tooltip content={`${nodeContext} → ${template.title}`}>+ <Stack color={isInvalid ? 'fg.error' : undefined} flex="1" gap="0" minW="0">+ <FieldLabel>{label}</FieldLabel>+ </Stack>+ </Tooltip>+ {resetButton}+ </HStack>)}{element.data.showDescription && description ? (<Text color="fg.subtle" fontSize="2xs">diff --git a/invokeai/frontend/webv2/src/workbench/workflows/fields.ts b/invokeai/frontend/webv2/src/workbench/workflows/fields.tsindex 9d2ff02112..0d2430b85a 100644--- a/invokeai/frontend/webv2/src/workbench/workflows/fields.ts+++ b/invokeai/frontend/webv2/src/workbench/workflows/fields.ts@@ -41,6 +41,25 @@ export const isDirectInputField = (template: FieldInputTemplate): boolean =>/** A field can be exposed to the Linear UI when it can be edited directly. */export const isExposableField = (template: FieldInputTemplate): boolean => isDirectInputField(template);+export const cloneWorkflowFieldDefault = (template: FieldInputTemplate): unknown =>+ template.default === undefined ? undefined : structuredClone(template.default);++export const isWorkflowFieldValueDefault = (template: FieldInputTemplate, value: unknown): boolean => {+ if (value === template.default) {+ return true;+ }++ if (value === undefined || template.default === undefined) {+ return false;+ }++ try {+ return JSON.stringify(value) === JSON.stringify(template.default);+ } catch {+ return false;+ }+};+const isNonEmptyString = (value: unknown): value is string => typeof value === 'string' && value.trim().length > 0;const hasNonEmptyStringProp = (value: unknown, prop: string): boolean =>