Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ storybook-static

# MCP Servers
.playwright-mcp/*
/tools/devtools/web/widgetAugmentations.js

vite.config.*.timestamp*
vitest.config.*.timestamp*
Expand Down
53 changes: 53 additions & 0 deletions browser_tests/tests/vueNodes/widgets/text/textEditorDialog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,59 @@ test.describe(
}
)

test('accepts an imported prompt tag with native undo and redo', async ({
comfyPage
}) => {
const node = comfyPage.vueNodes
.getNodeByTitle('CLIP Text Encode (Prompt)')
.first()
const widget = node.getByRole('textbox', { name: 'text' })
const dialog = new TextEditorDialog(comfyPage.page)

await test.step('import a catalog in the expanded prompt editor', async () => {
await widget.fill('')
await widget.hover()
await node
.getByRole('group', { name: 'Actions' })
.getByRole('button', { name: 'Expand' })
.click()
await dialog.root.getByLabel('Import prompt tags').setInputFiles({
name: 'tags.txt',
mimeType: 'text/plain',
buffer: Buffer.from('blue_eyes,20\nblue_hair,10')
})
await expect(
dialog.root.getByText('2 tags loaded for this session', {
exact: true
})
).toBeVisible()
})

await test.step('navigate and accept without leaving the textarea', async () => {
await dialog.editor.pressSequentially('blue')
await expect(
dialog.root.getByRole('option', { selected: true })
).toHaveText('blue eyes')
await dialog.editor.press('ArrowDown')
await expect(
dialog.root.getByRole('option', { selected: true })
).toHaveText('blue hair')
await dialog.editor.press('Enter')
await expect(dialog.editor).toHaveValue('blue hair')
await expect(dialog.editor).toBeFocused()
await expect(dialog.root.getByRole('listbox')).toBeHidden()
})

await test.step('undo and redo the insertion through the native editor', async () => {
await dialog.editor.press('ControlOrMeta+z')
await expect(dialog.editor).toHaveValue('blue')
await dialog.editor.press('ControlOrMeta+Shift+z')
await expect(dialog.editor).toHaveValue('blue hair')
await dialog.close()
await expect(widget).toHaveValue('blue hair')
})
})

test('opens long text scrolled to the top', async ({ comfyPage }) => {
const node = comfyPage.vueNodes
.getNodeByTitle('CLIP Text Encode (Prompt)')
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# ADR-WIDGET-AUGMENTATION-0057: Core renders extension contributions

Date: 2026-11-14

## Status

Proposed

## Context

A custom-node author wants to help someone write a prompt, not maintain another
editor. Today that help can require replacing widget factories, attaching DOM
listeners, or assigning widget values. Those integrations inherit each
renderer's selection, focus, undo, and teardown problems. Expanding the same
prompt into a dialog can leave the extension's behavior behind.

## Decision

Let extensions register declarative contributions against named node widgets.
Core resolves active contributions and renders their controls beside the
existing input. Start with completion suggestions, live text hints, and
synchronous text transformations. The devtools example tells this story with
lighting suggestions, a tag count, and a Normalize tags action on one ordinary
multiline widget, leaving its neighboring notes field alone.

Registration supplies behavior without handing the extension an input element.

![Core resolves and renders targeted contributions](./WIDGET-AUGMENTATION-0057-core-renders-extension-contributions/registration.svg)

An accepted suggestion or transformation goes through core's guarded native
editing operation, then the input's existing value pipeline. There is no second
widget-value writer. The node editor and expanded editor share contributions,
not selection or browser undo history. Refusing an edit leaves the value intact.

![Guarded insertion rejoins the existing widget update path](./WIDGET-AUGMENTATION-0057-core-renders-extension-contributions/editing.svg)

## Migration stories

**Custom Scripts could keep its dictionaries and stop owning the input.** Its
[autocomplete integration](https://github.com/pythongosssss/ComfyUI-Custom-Scripts/blob/609f3afaa74b2f88ef9ce8d939626065e3247469/web/js/autocompleter.js)
replaces the string-widget factory and attaches an autocomplete engine to each
eligible textarea. Already-loaded words could supply completion providers for
explicit widget targets. This migrates cached lookup, not its global widget
discovery, rich dropdown, or custom escaping and insertion rules.

**Impact Pack could offer prompt help without mutating prompt widgets.** Its
[wildcard integration](https://github.com/ltdrdata/ComfyUI-Impact-Pack/blob/9e2d41da75c185bf7638f860d5d004035f378e9b/js/impact-pack.js)
appends wildcard and LoRA tokens through combo callbacks and writes guidance
directly to textareas. Cached wildcard tokens could supply completions for
`ImpactWildcardProcessor.wildcard_text` and
`ImpactWildcardEncode.wildcard_text`; static guidance could become hints.
Completion would be a different discovery UI, not a drop-in combo replacement.
Population, serialization overrides, and mode-dependent editability stay
outside this API. These are source-based migration candidates, not tested
migrations or promises of full compatibility.

## Tradeoffs and limits

Keep native textareas instead of replacing prompt editing with a rich editor.
Reuse existing positioning and design-system controls instead of adding an
autocomplete library. A general mount callback would admit arbitrary UI, but
would also require a public focus, keyboard, accessibility, and edit-lifecycle
contract. Defer that until a concrete contribution cannot fit this model.

The prototype covers multiline native textareas, not every widget or the
agent's structured ProseMirror editor. Exact targets and synchronous callbacks
deliberately limit discovery and remote suggestions. Native insertion still
depends on deprecated `execCommand`. Core skips unsupported insertion to
preserve undo. Cross-browser undo and automatic loading of the
built devtools extension remain release gates. Existing extension behavior is
not removed or intercepted by this proposal.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions knip.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const config: KnipConfig = {
'src/scripts/ui/menu/index.ts',
'src/types/index.ts',
'src/storybook/mocks/**/*.ts',
'tools/devtools/build.ts',
'tools/devtools/widgetAugmentations.ts',
'tools/oxlint-plugins/comfyIngestTypes.ts',
'tools/oxlint-plugins/serverFacts.ts',
'tools/oxlint-plugins/vitestCleanup.ts'
Expand Down
34 changes: 33 additions & 1 deletion src/components/graph/widgets/DomWidget.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { render } from '@testing-library/vue'
import { render, screen } from '@testing-library/vue'
import userEvent from '@testing-library/user-event'
import { fromPartial } from '@total-typescript/shoehorn'
import { beforeEach, afterEach, describe, expect, it, vi } from 'vitest'
import { nextTick, reactive, ref } from 'vue'

import { i18n } from '@/i18n'
import { LGraphNode } from '@/lib/litegraph/src/litegraph'
import { useSettingStore } from '@/platform/settings/settingStore'
import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
import { usePromptTagCatalogStore } from '@/renderer/extensions/textEditor/promptTagCatalogStore'
import type { BaseDOMWidget } from '@/types/domWidget'
import type { DomWidgetState } from '@/stores/domWidgetStore'
import { useDomWidgetStore } from '@/stores/domWidgetStore'
Expand Down Expand Up @@ -273,6 +276,35 @@ describe('native DOM widget interaction lifecycle', () => {
useDomWidgetStore().clear()
})

it('offers shared catalog suggestions for a native multiline widget and restores its attributes on removal', async () => {
const user = userEvent.setup()
usePromptTagCatalogStore().importCatalog('blue_eyes')
const widgetState = createWidgetState(false)
const textarea = document.createElement('textarea')
textarea.setAttribute('aria-label', 'Prompt')
textarea.setAttribute('aria-autocomplete', 'none')
Object.assign(widgetState.widget, { element: textarea, type: 'customtext' })
const view = render(DomWidget, {
props: { widgetState },
global: { plugins: [i18n] }
})
await nextTick()
const editor = await screen.findByRole('textbox', { name: 'Prompt' })

await user.type(editor, 'blue')

expect(
await screen.findByRole('option', { name: 'blue eyes' })
).toBeVisible()
expect(editor).toHaveFocus()
expect(editor).toHaveAttribute('aria-autocomplete', 'list')

view.unmount()

expect(screen.queryByRole('listbox')).toBeNull()
expect(textarea).toHaveAttribute('aria-autocomplete', 'none')
})

function renderWithUnmountableElement(widgetState: DomWidgetState) {
const input = document.createElement('input')
Object.assign(widgetState.widget, { element: input })
Expand Down
28 changes: 25 additions & 3 deletions src/components/graph/widgets/DomWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
v-show="widgetState.visible"
ref="widgetElement"
class="dom-widget size-full"
:class="cn(widget.type === 'customtext' && 'flex flex-col')"
:title="tooltip"
:style="style"
>
Expand All @@ -15,6 +16,16 @@
v-bind="widget.props"
@update:model-value="emit('update:widgetValue', $event)"
/>
<TextareaAugmentations
v-if="widget.type === 'customtext' && isDOMWidget(widget)"
:element="textareaElement"
:target="{ nodeType: widget.node.type ?? '', widgetName: widget.name }"
:value="String(widget.value ?? '')"
:enabled="
widgetState.visible && !widgetState.readonly && !widget.computedDisabled
"
teleported
/>
</div>
</template>

Expand All @@ -23,11 +34,13 @@ import { useElementBounding, useEventListener, whenever } from '@vueuse/core'
import type { CSSProperties } from 'vue'
import { computed, nextTick, onMounted, ref, watch } from 'vue'

import { cn } from '@comfyorg/tailwind-utils'
import { useAbsolutePosition } from '@/composables/element/useAbsolutePosition'
import { useDomClipping } from '@/composables/element/useDomClipping'
import { findFirstNode } from '@/lib/litegraph/src/utils/collections'
import { useSettingStore } from '@/platform/settings/settingStore'
import { useCanvasStore } from '@/renderer/core/canvas/canvasStore'
import TextareaAugmentations from '@/renderer/extensions/textEditor/components/TextareaAugmentations.vue'
import { isComponentWidget, isDOMWidget } from '@/scripts/domWidget'
import type { DomWidgetState } from '@/stores/domWidgetStore'

Expand All @@ -38,6 +51,13 @@ const { widgetState } = defineProps<{
}>()
const widget = widgetState.widget

function textareaElement(): HTMLTextAreaElement | undefined {
if (!isDOMWidget(widget)) return undefined
return widget.element instanceof HTMLTextAreaElement
? widget.element
: undefined
}

const emit = defineEmits<{
'update:widgetValue': [value: string | object]
}>()
Expand Down Expand Up @@ -169,18 +189,20 @@ onMounted(() => {
const inputSpec = widget.node.constructor.nodeData
const tooltip = inputSpec?.inputs?.[widget.name]?.tooltip

// Mount DOM element when widget is or becomes visible
const mountElementIfVisible = () => {
if (!(widgetState.visible && isDOMWidget(widget) && widgetElement.value)) {
return
}
// Only append if not already a child
if (widgetElement.value.contains(widget.element)) {
return
}

try {
widget.element.classList.add('h-full', 'w-full')
widget.element.classList.add(
'h-full',
'w-full',
...(widget.type === 'customtext' ? ['min-h-0', 'flex-1'] : [])
)
widgetElement.value.appendChild(widget.element)
} catch (error) {
reportDomWidgetMountFailure(error, {
Expand Down
8 changes: 8 additions & 0 deletions src/locales/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -4414,8 +4414,16 @@
}
},
"textEditor": {
"actionTooLong": "This action exceeds the text limit. Shorten the text and try again.",
"actionUnavailable": "This action could not edit the text. Your text is unchanged. Edit it manually instead.",
"characterCount": "{count} char | {count} chars",
"expand": "Expand",
"importTags": "Import prompt tags",
"importTagsError": "Could not load tags. Choose a TXT list or a tag CSV (name, category, count, aliases), up to 10 MB. Your previous catalog is unchanged.",
"importTagsHint": "CSV or TXT · local to this session",
"suggestionCount": "{count} suggestion available | {count} suggestions available",
"suggestions": "Prompt suggestions",
"tagsLoaded": "{count} tag loaded for this session | {count} tags loaded for this session",
"title": "{widget} · {node}"
},
"widgetFileUpload": {
Expand Down
Loading
Loading