mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-30 03:01:54 +00:00
Move widget link drop conversion to widgetInputs (#2001)
Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
@@ -3,8 +3,13 @@ import { ComfyWidgets, addValueControlWidgets } from '../../scripts/widgets'
|
|||||||
import { app } from '../../scripts/app'
|
import { app } from '../../scripts/app'
|
||||||
import { applyTextReplacements } from '../../scripts/utils'
|
import { applyTextReplacements } from '../../scripts/utils'
|
||||||
import { LiteGraph, LGraphNode } from '@comfyorg/litegraph'
|
import { LiteGraph, LGraphNode } from '@comfyorg/litegraph'
|
||||||
import type { INodeInputSlot, IWidget } from '@comfyorg/litegraph'
|
import type {
|
||||||
|
INodeInputSlot,
|
||||||
|
IWidget,
|
||||||
|
LiteGraphCanvasEvent
|
||||||
|
} from '@comfyorg/litegraph'
|
||||||
import type { InputSpec } from '@/types/apiTypes'
|
import type { InputSpec } from '@/types/apiTypes'
|
||||||
|
import { useNodeDefStore } from '@/stores/nodeDefStore'
|
||||||
|
|
||||||
const CONVERTED_TYPE = 'converted-widget'
|
const CONVERTED_TYPE = 'converted-widget'
|
||||||
const VALID_TYPES = [
|
const VALID_TYPES = [
|
||||||
@@ -721,6 +726,40 @@ app.registerExtension({
|
|||||||
defaultValue: true
|
defaultValue: true
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
setup() {
|
||||||
|
app.canvas.getWidgetLinkType = function (widget, node) {
|
||||||
|
const nodeDefStore = useNodeDefStore()
|
||||||
|
const nodeDef = nodeDefStore.nodeDefsByName[node.type]
|
||||||
|
const input = nodeDef.inputs.getInput(widget.name)
|
||||||
|
return input?.type
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener(
|
||||||
|
'litegraph:canvas',
|
||||||
|
async (e: LiteGraphCanvasEvent) => {
|
||||||
|
if (e.detail.subType === 'connectingWidgetLink') {
|
||||||
|
const { node, link, widget } = e.detail
|
||||||
|
if (!node || !link || !widget) return
|
||||||
|
|
||||||
|
const nodeData = node.constructor.nodeData
|
||||||
|
if (!nodeData) return
|
||||||
|
const all = {
|
||||||
|
...nodeData?.input?.required,
|
||||||
|
...nodeData?.input?.optional
|
||||||
|
}
|
||||||
|
const inputSpec = all[widget.name]
|
||||||
|
if (!inputSpec) return
|
||||||
|
|
||||||
|
const input = convertToInput(node, widget, inputSpec)
|
||||||
|
if (!input) return
|
||||||
|
|
||||||
|
const originNode = link.node
|
||||||
|
|
||||||
|
originNode.connect(link.slot, node, node.inputs.lastIndexOf(input))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
async beforeRegisterNodeDef(nodeType, nodeData, app) {
|
async beforeRegisterNodeDef(nodeType, nodeData, app) {
|
||||||
// Add menu options to convert to/from widgets
|
// Add menu options to convert to/from widgets
|
||||||
const origGetExtraMenuOptions = nodeType.prototype.getExtraMenuOptions
|
const origGetExtraMenuOptions = nodeType.prototype.getExtraMenuOptions
|
||||||
|
|||||||
@@ -312,6 +312,24 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"CLIPTextEncodePixArtAlpha": {
|
||||||
|
"display_name": "CLIPTextEncodePixArtAlpha",
|
||||||
|
"description": "Encodes text and sets the resolution conditioning for PixArt Alpha. Does not apply to PixArt Sigma.",
|
||||||
|
"inputs": {
|
||||||
|
"width": {
|
||||||
|
"name": "width"
|
||||||
|
},
|
||||||
|
"height": {
|
||||||
|
"name": "height"
|
||||||
|
},
|
||||||
|
"text": {
|
||||||
|
"name": "text"
|
||||||
|
},
|
||||||
|
"clip": {
|
||||||
|
"name": "clip"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"CLIPTextEncodeSD3": {
|
"CLIPTextEncodeSD3": {
|
||||||
"display_name": "CLIPTextEncodeSD3",
|
"display_name": "CLIPTextEncodeSD3",
|
||||||
"inputs": {
|
"inputs": {
|
||||||
|
|||||||
@@ -249,6 +249,24 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"CLIPTextEncodePixArtAlpha": {
|
||||||
|
"description": "テキストをエンコードし、PixArt Alphaの解像度条件を設定します。PixArt Sigmaには適用されません。",
|
||||||
|
"display_name": "CLIPTextEncodePixArtAlpha",
|
||||||
|
"inputs": {
|
||||||
|
"clip": {
|
||||||
|
"name": "clip"
|
||||||
|
},
|
||||||
|
"height": {
|
||||||
|
"name": "高さ"
|
||||||
|
},
|
||||||
|
"text": {
|
||||||
|
"name": "テキスト"
|
||||||
|
},
|
||||||
|
"width": {
|
||||||
|
"name": "幅"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"CLIPTextEncodeSD3": {
|
"CLIPTextEncodeSD3": {
|
||||||
"display_name": "CLIPテキストエンコードSD3",
|
"display_name": "CLIPテキストエンコードSD3",
|
||||||
"inputs": {
|
"inputs": {
|
||||||
|
|||||||
@@ -249,6 +249,24 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"CLIPTextEncodePixArtAlpha": {
|
||||||
|
"description": "텍스트를 인코딩하고 PixArt Alpha의 해상도 조건을 설정합니다. PixArt Sigma에는 적용되지 않습니다.",
|
||||||
|
"display_name": "CLIPTextEncodePixArtAlpha",
|
||||||
|
"inputs": {
|
||||||
|
"clip": {
|
||||||
|
"name": "클립"
|
||||||
|
},
|
||||||
|
"height": {
|
||||||
|
"name": "높이"
|
||||||
|
},
|
||||||
|
"text": {
|
||||||
|
"name": "텍스트"
|
||||||
|
},
|
||||||
|
"width": {
|
||||||
|
"name": "너비"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"CLIPTextEncodeSD3": {
|
"CLIPTextEncodeSD3": {
|
||||||
"display_name": "CLIP 텍스트 인코딩 (SD3)",
|
"display_name": "CLIP 텍스트 인코딩 (SD3)",
|
||||||
"inputs": {
|
"inputs": {
|
||||||
|
|||||||
@@ -249,6 +249,24 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"CLIPTextEncodePixArtAlpha": {
|
||||||
|
"description": "Кодирует текст и устанавливает условие разрешения для PixArt Alpha. Не применяется к PixArt Sigma.",
|
||||||
|
"display_name": "CLIPTextEncodePixArtAlpha",
|
||||||
|
"inputs": {
|
||||||
|
"clip": {
|
||||||
|
"name": "clip"
|
||||||
|
},
|
||||||
|
"height": {
|
||||||
|
"name": "высота"
|
||||||
|
},
|
||||||
|
"text": {
|
||||||
|
"name": "текст"
|
||||||
|
},
|
||||||
|
"width": {
|
||||||
|
"name": "ширина"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"CLIPTextEncodeSD3": {
|
"CLIPTextEncodeSD3": {
|
||||||
"display_name": "Кодирование текста CLIP SD3",
|
"display_name": "Кодирование текста CLIP SD3",
|
||||||
"inputs": {
|
"inputs": {
|
||||||
|
|||||||
@@ -249,6 +249,24 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"CLIPTextEncodePixArtAlpha": {
|
||||||
|
"description": "对文本进行编码并为PixArt Alpha设置分辨率条件。不适用于PixArt Sigma。",
|
||||||
|
"display_name": "CLIPTextEncodePixArtAlpha",
|
||||||
|
"inputs": {
|
||||||
|
"clip": {
|
||||||
|
"name": "clip"
|
||||||
|
},
|
||||||
|
"height": {
|
||||||
|
"name": "高度"
|
||||||
|
},
|
||||||
|
"text": {
|
||||||
|
"name": "文本"
|
||||||
|
},
|
||||||
|
"width": {
|
||||||
|
"name": "宽度"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"CLIPTextEncodeSD3": {
|
"CLIPTextEncodeSD3": {
|
||||||
"display_name": "CLIP文本编码SD3",
|
"display_name": "CLIP文本编码SD3",
|
||||||
"inputs": {
|
"inputs": {
|
||||||
|
|||||||
@@ -63,7 +63,6 @@ import { useWidgetStore } from '@/stores/widgetStore'
|
|||||||
import { deserialiseAndCreate } from '@/extensions/core/vintageClipboard'
|
import { deserialiseAndCreate } from '@/extensions/core/vintageClipboard'
|
||||||
import { st } from '@/i18n'
|
import { st } from '@/i18n'
|
||||||
import { normalizeI18nKey } from '@/utils/formatUtil'
|
import { normalizeI18nKey } from '@/utils/formatUtil'
|
||||||
import { ISerialisedGraph } from '@comfyorg/litegraph'
|
|
||||||
|
|
||||||
export const ANIM_PREVIEW_WIDGET = '$$comfy_animation_preview'
|
export const ANIM_PREVIEW_WIDGET = '$$comfy_animation_preview'
|
||||||
|
|
||||||
@@ -1610,52 +1609,6 @@ export class ComfyApp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#addWidgetLinkHandling() {
|
|
||||||
app.canvas.getWidgetLinkType = function (widget, node) {
|
|
||||||
const nodeDefStore = useNodeDefStore()
|
|
||||||
const nodeDef = nodeDefStore.nodeDefsByName[node.type]
|
|
||||||
const input = nodeDef.inputs.getInput(widget.name)
|
|
||||||
return input?.type
|
|
||||||
}
|
|
||||||
|
|
||||||
type ConnectingWidgetLink = {
|
|
||||||
subType: 'connectingWidgetLink'
|
|
||||||
widget: IWidget
|
|
||||||
node: LGraphNode
|
|
||||||
link: { node: LGraphNode; slot: number }
|
|
||||||
}
|
|
||||||
|
|
||||||
document.addEventListener(
|
|
||||||
'litegraph:canvas',
|
|
||||||
async (e: CustomEvent<ConnectingWidgetLink>) => {
|
|
||||||
if (e.detail.subType === 'connectingWidgetLink') {
|
|
||||||
const { convertToInput } = await import(
|
|
||||||
'@/extensions/core/widgetInputs'
|
|
||||||
)
|
|
||||||
|
|
||||||
const { node, link, widget } = e.detail
|
|
||||||
if (!node || !link || !widget) return
|
|
||||||
|
|
||||||
const nodeData = node.constructor.nodeData
|
|
||||||
if (!nodeData) return
|
|
||||||
const all = {
|
|
||||||
...nodeData?.input?.required,
|
|
||||||
...nodeData?.input?.optional
|
|
||||||
}
|
|
||||||
const inputSpec = all[widget.name]
|
|
||||||
if (!inputSpec) return
|
|
||||||
|
|
||||||
const input = convertToInput(node, widget, inputSpec)
|
|
||||||
if (!input) return
|
|
||||||
|
|
||||||
const originNode = link.node
|
|
||||||
|
|
||||||
originNode.connect(link.slot, node, node.inputs.lastIndexOf(input))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#addAfterConfigureHandler() {
|
#addAfterConfigureHandler() {
|
||||||
const app = this
|
const app = this
|
||||||
const onConfigure = app.graph.onConfigure
|
const onConfigure = app.graph.onConfigure
|
||||||
@@ -1782,7 +1735,6 @@ export class ComfyApp {
|
|||||||
this.#addDropHandler()
|
this.#addDropHandler()
|
||||||
this.#addCopyHandler()
|
this.#addCopyHandler()
|
||||||
this.#addPasteHandler()
|
this.#addPasteHandler()
|
||||||
this.#addWidgetLinkHandling()
|
|
||||||
|
|
||||||
await this.#invokeExtensionsAsync('setup')
|
await this.#invokeExtensionsAsync('setup')
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user