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
fix(webv2): unify prompt list row interactions
joshistoastbfbf82c75f4c
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/DynamicPromptsButton.browser.test.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/DynamicPromptsButton.browser.test.tsxindex 79b6862dc0..3da7820ad0 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/DynamicPromptsButton.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/DynamicPromptsButton.browser.test.tsx@@ -3,6 +3,7 @@ import type { DynamicPromptsConfig } from '@features/generation/core/dynamicPromimport { ChakraProvider } from '@chakra-ui/react';import { DynamicPromptsButton } from '@features/generation/ui/promptFields/DynamicPromptsButton';import { PromptTextarea } from '@features/generation/ui/promptFields/PromptTextarea';+import { Row } from '@platform/ui/Row';import { QueryClient, QueryClientProvider } from '@tanstack/react-query';import { system } from '@theme/system';import { act } from 'react';@@ -37,6 +38,7 @@ const config: DynamicPromptsConfig & { onChange: () => void } = {const render = async (prompt: string, onUsePrompt = vi.fn()) => {host = document.createElement('div');+ host.style.width = '400px';document.body.append(host);root = createRoot(host);@@ -44,6 +46,11 @@ const render = async (prompt: string, onUsePrompt = vi.fn()) => {root?.render(<QueryClientProvider client={new QueryClient()}><ChakraProvider value={system}>+ <Row asChild>+ <button aria-label="Row probe" type="button">+ Row probe+ </button>+ </Row><PromptTextareaaria-label="Prompt"defaultHeightPx={100}@@ -122,6 +129,30 @@ describe('dynamic prompts in the positive prompt field', () => {expect(onUsePrompt).toHaveBeenCalledWith('a red cat');});+ it('uses the shared Row interaction contract for each selectable expanded prompt', async () => {+ const { onUsePrompt } = await render('a {red|green} cat');+ const probe = host!.querySelector<HTMLButtonElement>('button[aria-label="Row probe"]')!;+ const expected = await getRowInteractionStyles(probe);++ await vi.waitFor(() => expect(findButton().textContent).toContain('2'));+ await act(async () => {+ await userEvent.click(findButton());+ });++ const row = [...document.querySelectorAll<HTMLButtonElement>('button')].find(+ (button) =>+ button.title === 'widgets.generate.dynamicPrompts.usePrompt' && button.textContent?.includes('a red cat')+ )!;++ await expectRowInteractionsToMatch(expected, row);++ await act(async () => {+ await userEvent.click(row);+ });++ expect(onUsePrompt).toHaveBeenCalledWith('a red cat');+ });+it('colours attention syntax inside the previewed prompts', async () => {parseDynamicPrompts.mockResolvedValue({ error: null, prompts: ['a (red)1.2 cat', 'a green+ cat'] });await render('a {(red)1.2|green+} cat');@@ -155,3 +186,61 @@ describe('dynamic prompts in the positive prompt field', () => {expect(findButton().textContent).not.toMatch(/\d/);});});++const getRowInteractionStyles = async (probe: HTMLButtonElement) => {+ await act(async () => {+ await userEvent.tab();+ await userEvent.hover(probe);+ await waitForTransition();+ });+ const expected = getInteractionStyles(probe);++ await act(async () => {+ await userEvent.unhover(probe);+ });++ return expected;+};++const expectRowInteractionsToMatch = async (+ expected: ReturnType<typeof getInteractionStyles>,+ row: HTMLButtonElement+) => {+ await act(async () => {+ await focusWithKeyboard(row);+ await userEvent.hover(row);+ await waitForTransition();+ });++ expect(getInteractionStyles(row)).toEqual(expected);+};++const focusWithKeyboard = async (element: HTMLButtonElement) => {+ for (let index = 0; index < 12; index += 1) {+ if (document.activeElement === element) {+ return;+ }+ await userEvent.tab();+ }++ throw new Error(`Could not focus ${element.title} with the keyboard`);+};++const getInteractionStyles = (element: HTMLElement) => {+ const styles = getComputedStyle(element);++ return {+ backgroundColor: styles.backgroundColor,+ borderRadius: styles.borderRadius,+ outline: styles.outline,+ outlineOffset: styles.outlineOffset,+ transitionDuration: styles.transitionDuration,+ transitionProperty: styles.transitionProperty,+ transitionTimingFunction: styles.transitionTimingFunction,+ };+};++const waitForTransition = () =>+ new Promise<void>((resolve) => {+ globalThis.setTimeout(resolve, 200);+ });diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/DynamicPromptsPanel.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/DynamicPromptsPanel.tsxindex 6732f30191..c1d82f0f61 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/DynamicPromptsPanel.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/DynamicPromptsPanel.tsx@@ -13,6 +13,7 @@ import { PANEL_HEADER_CONTROL_HEIGHT, PromptPanelHeader } from '@features/generaimport { Button, IconButton } from '@platform/ui/Button';import { Field } from '@platform/ui/Field';import { MenuContent } from '@platform/ui/Menu';+import { Row } from '@platform/ui/Row';import { Scrollable } from '@platform/ui/Scrollable';import { Tooltip } from '@platform/ui/Tooltip';import { ChevronDownIcon, ShuffleIcon } from 'lucide-react';@@ -241,27 +242,26 @@ const DynamicPromptRow = ({const handleClick = useCallback(() => onUsePrompt(prompt), [onUsePrompt, prompt]);return (- <Button+ <RowalignItems="start"+ asChildgap="2"h="auto"justifyContent="start"px="2"py="1.5"- size="xs"title={t('widgets.generate.dynamicPrompts.usePrompt')}- transitionDuration="faster"- variant="ghost"- onClick={handleClick}>- <Text as="span" color="fg.subtle" css={TABULAR_NUMS} fontSize="2xs">- {index + 1}- </Text>- <Text as="span" color="fg" fontFamily="mono" fontSize="0.72rem" textAlign="start" wordBreak="break-word">- {/* An expanded prompt has no dynamic syntax left in it, so the useful- colouring here is attention and embeddings — the defaults. */}- <HighlightedPrompt enabled={showSyntaxHighlighting} prompt={prompt} />- </Text>- </Button>+ <button type="button" onClick={handleClick}>+ <Text as="span" color="fg.subtle" css={TABULAR_NUMS} fontSize="2xs">+ {index + 1}+ </Text>+ <Text as="span" color="fg" fontFamily="mono" fontSize="0.72rem" textAlign="start" wordBreak="break-word">+ {/* An expanded prompt has no dynamic syntax left in it, so the useful+ colouring here is attention and embeddings — the defaults. */}+ <HighlightedPrompt enabled={showSyntaxHighlighting} prompt={prompt} />+ </Text>+ </button>+ </Row>);};diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplates.browser.test.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplates.browser.test.tsxindex b01db1eeba..5d5991acaa 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplates.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PromptTemplates.browser.test.tsx@@ -8,6 +8,7 @@ import { PromptTemplateEditor } from '@features/generation/ui/promptFields/Prompimport { PromptTemplateImage } from '@features/generation/ui/promptFields/PromptTemplateImage';import { PromptTemplatesPanel } from '@features/generation/ui/promptFields/PromptTemplatesPanel';import { accountLifecycle } from '@platform/state/accountLifecycle';+import { Row } from '@platform/ui/Row';import { QueryClient, QueryClientProvider } from '@tanstack/react-query';import { system } from '@theme/system';import i18next from 'i18next';@@ -178,6 +179,11 @@ const StatefulPromptTemplatesPanel = ({ catalog }: { catalog: PromptTemplateCatareturn (<><Box aria-hidden bg="accent.solid" color="accent.contrast" data-testid="accent-style-probe" />+ <Row asChild>+ <button aria-label="Row probe" type="button">+ Row probe+ </button>+ </Row><PromptTemplatesPanelactiveTemplate={activeTemplate}catalog={catalog}@@ -289,6 +295,21 @@ describe('the prompt templates panel', () => {expect(getComputedStyle(activeText[1]!).color).toBe(probeStyle.color);});+ it('uses the shared Row interaction contract for inactive templates and keeps management controls separate', async () => {+ await render(<StatefulPromptTemplatesPanel catalog={createCatalog()} />);++ const probe = host!.querySelector<HTMLButtonElement>('button[aria-label="Row probe"]')!;+ const row = buttonWithText('Cinematic');+ const edit = host!.querySelector<HTMLButtonElement>('button[aria-label="Edit"]')!;+ const remove = host!.querySelector<HTMLButtonElement>('button[aria-label="Delete"]')!;++ expect(row.getAttribute('aria-current')).toBeNull();+ expect(row.contains(edit)).toBe(false);+ expect(row.contains(remove)).toBe(false);++ await expectRowInteractionsToMatch(probe, row);+ });+it('clears the applied template', async () => {const onApply = vi.fn();@@ -812,3 +833,51 @@ describe('prompt template image outlines', () => {expect(getComputedStyle(image).outlineOffset).toBe('0px');});});++const expectRowInteractionsToMatch = async (probe: HTMLButtonElement, row: HTMLButtonElement) => {+ await act(async () => {+ await userEvent.tab();+ await userEvent.hover(probe);+ await waitForTransition();+ });+ const expected = getInteractionStyles(probe);++ await act(async () => {+ await userEvent.unhover(probe);+ await focusWithKeyboard(row);+ await userEvent.hover(row);+ await waitForTransition();+ });++ expect(getInteractionStyles(row)).toEqual(expected);+};++const focusWithKeyboard = async (element: HTMLButtonElement) => {+ for (let index = 0; index < 12; index += 1) {+ if (document.activeElement === element) {+ return;+ }+ await userEvent.tab();+ }++ throw new Error(`Could not focus ${element.textContent} with the keyboard`);+};++const getInteractionStyles = (element: HTMLElement) => {+ const styles = getComputedStyle(element);++ return {+ backgroundColor: styles.backgroundColor,+ borderRadius: styles.borderRadius,+ outline: styles.outline,+ outlineOffset: styles.outlineOffset,+ transitionDuration: styles.transitionDuration,+ transitionProperty: styles.transitionProperty,+ transitionTimingFunction: styles.transitionTimingFunction,+ };+};++const waitForTransition = () =>+ new Promise<void>((resolve) => {+ globalThis.setTimeout(resolve, 200);+ });diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/WildcardsPanel.browser.test.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/WildcardsPanel.browser.test.tsxindex d0755d9cba..b1f41e9f56 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/WildcardsPanel.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/WildcardsPanel.browser.test.tsx@@ -4,6 +4,7 @@ import { ChakraProvider } from '@chakra-ui/react';import { WildcardsPanel } from '@features/generation/ui/promptFields/WildcardsPanel';import { WILDCARD_COLLECTION_FORMATS } from '@features/generation/ui/wildcardFiles';import { accountLifecycle } from '@platform/state/accountLifecycle';+import { Row } from '@platform/ui/Row';import { system } from '@theme/system';import { act } from 'react';import { createRoot, type Root } from 'react-dom/client';@@ -31,7 +32,12 @@ const catalog: WildcardCatalog = {wildcards: [{ id: 'w1', name: 'colors', values: ['red', 'green'] }],};-const renderPanel = async (showSyntaxHighlighting = true, panelCatalog: WildcardCatalog = catalog) => {+const renderPanel = async (+ showSyntaxHighlighting = true,+ panelCatalog: WildcardCatalog = catalog,+ onInsert = vi.fn(),+ includeRowProbe = false+) => {host = document.createElement('div');host.style.width = '380px';document.body.append(host);@@ -40,7 +46,14 @@ const renderPanel = async (showSyntaxHighlighting = true, panelCatalog: Wildcardawait act(() => {root?.render(<ChakraProvider value={system}>- <WildcardsPanel catalog={panelCatalog} showSyntaxHighlighting={showSyntaxHighlighting} onInsert={vi.fn()} />+ {includeRowProbe ? (+ <Row asChild>+ <button aria-label="Row probe" type="button">+ Row probe+ </button>+ </Row>+ ) : null}+ <WildcardsPanel catalog={panelCatalog} showSyntaxHighlighting={showSyntaxHighlighting} onInsert={onInsert} /></ChakraProvider>);});@@ -287,6 +300,32 @@ describe('finding a wildcard', () => {});});+describe('wildcard list interactions', () => {+ const selectableWildcardButton = () =>+ host!.querySelector<HTMLButtonElement>('button[title="widgets.generate.dynamicPrompts.insertWildcard"]')!;++ it('uses the shared Row interaction contract without nesting the edit controls', async () => {+ const onInsert = vi.fn();+ await renderPanel(true, catalog, onInsert, true);++ const probe = host!.querySelector<HTMLButtonElement>('button[aria-label="Row probe"]')!;+ const row = selectableWildcardButton();+ const edit = host!.querySelector<HTMLButtonElement>('button[aria-label="common.edit"]')!;+ const remove = host!.querySelector<HTMLButtonElement>('button[aria-label="common.delete"]')!;++ expect(row.contains(edit)).toBe(false);+ expect(row.contains(remove)).toBe(false);++ await expectRowInteractionsToMatch(probe, row);++ await act(async () => {+ await userEvent.click(row);+ });++ expect(onInsert).toHaveBeenCalledWith('__colors__');+ });+});+describe('deleting a wildcard', () => {const clickDelete = async () => {// By label, not by position: the panel footer has its own controls after the@@ -333,3 +372,51 @@ describe('deleting a wildcard', () => {expect(catalog.remove).toHaveBeenCalledWith('w1');});});++const expectRowInteractionsToMatch = async (probe: HTMLButtonElement, row: HTMLButtonElement) => {+ await act(async () => {+ await userEvent.tab();+ await userEvent.hover(probe);+ await waitForTransition();+ });+ const expected = getInteractionStyles(probe);++ await act(async () => {+ await userEvent.unhover(probe);+ await focusWithKeyboard(row);+ await userEvent.hover(row);+ await waitForTransition();+ });++ expect(getInteractionStyles(row)).toEqual(expected);+};++const focusWithKeyboard = async (element: HTMLButtonElement) => {+ for (let index = 0; index < 12; index += 1) {+ if (document.activeElement === element) {+ return;+ }+ await userEvent.tab();+ }++ throw new Error(`Could not focus ${element.title} with the keyboard`);+};++const getInteractionStyles = (element: HTMLElement) => {+ const styles = getComputedStyle(element);++ return {+ backgroundColor: styles.backgroundColor,+ borderRadius: styles.borderRadius,+ outline: styles.outline,+ outlineOffset: styles.outlineOffset,+ transitionDuration: styles.transitionDuration,+ transitionProperty: styles.transitionProperty,+ transitionTimingFunction: styles.transitionTimingFunction,+ };+};++const waitForTransition = () =>+ new Promise<void>((resolve) => {+ globalThis.setTimeout(resolve, 200);+ });diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/WildcardsPanel.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/WildcardsPanel.tsxindex cf0ffb5f98..c6893892da 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/WildcardsPanel.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/WildcardsPanel.tsx@@ -18,6 +18,7 @@ import { getApiErrorMessage } from '@platform/transport/http';import { Button, IconButton } from '@platform/ui/Button';import { ConfirmDialog } from '@platform/ui/ConfirmDialog';import { Field } from '@platform/ui/Field';+import { Row } from '@platform/ui/Row';import { Scrollable } from '@platform/ui/Scrollable';import { Tooltip } from '@platform/ui/Tooltip';import { CheckIcon, PencilIcon, PlusIcon, TrashIcon, XIcon } from 'lucide-react';@@ -300,30 +301,34 @@ const WildcardRow = ({return (<HStack align="start" gap="1" pr="1">- <Button+ <RowalignItems="start"+ asChildflex="1"h="auto"justifyContent="start"minW="0"px="2"py="1.5"- size="xs"title={t('widgets.generate.dynamicPrompts.insertWildcard')}- variant="ghost"- onClick={() => onInsert(`__${wildcard.name}__`)}>- <Stack align="start" gap="0" minW="0">- <Text as="span" color="fg" fontFamily="mono" fontSize="0.72rem">- __{wildcard.name}__- </Text>- <Text as="span" color="fg.subtle" fontSize="2xs" truncate>- {wildcard.values.length > 0- ? wildcard.values.join(', ')- : t('widgets.generate.dynamicPrompts.wildcardHasNoValues')}- </Text>- </Stack>- </Button>+ <button+ aria-label={t('widgets.generate.dynamicPrompts.insertWildcard')}+ type="button"+ onClick={() => onInsert(`__${wildcard.name}__`)}+ >+ <Stack align="start" gap="0" minW="0">+ <Text as="span" color="fg" fontFamily="mono" fontSize="0.72rem">+ __{wildcard.name}__+ </Text>+ <Text as="span" color="fg.subtle" fontSize="2xs" truncate>+ {wildcard.values.length > 0+ ? wildcard.values.join(', ')+ : t('widgets.generate.dynamicPrompts.wildcardHasNoValues')}+ </Text>+ </Stack>+ </button>+ </Row><Tooltip content={t('common.edit')}><IconButton aria-label={t('common.edit')} size="2xs" variant="ghost" onClick={() => onEdit(wildcard)}><PencilIcon />