mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-10 01:50:08 +00:00
[Refactor] Remove app.getWidgetType (#2880)
This commit is contained in:
@@ -12,6 +12,7 @@ import type { ComfyNodeDef } from '@/schemas/nodeDefSchema'
|
||||
import { useDialogService } from '@/services/dialogService'
|
||||
import { useNodeDefStore } from '@/stores/nodeDefStore'
|
||||
import { useToastStore } from '@/stores/toastStore'
|
||||
import { useWidgetStore } from '@/stores/widgetStore'
|
||||
import { ComfyExtension } from '@/types/comfy'
|
||||
import { deserialiseAndCreate, serialise } from '@/utils/vintageClipboard'
|
||||
|
||||
@@ -442,8 +443,7 @@ export class GroupNodeConfig {
|
||||
const converted = new Map()
|
||||
const widgetMap = (this.oldToNewWidgetMap[node.index] = {})
|
||||
for (const inputName of inputNames) {
|
||||
let widgetType = app.getWidgetType(inputs[inputName], inputName)
|
||||
if (widgetType) {
|
||||
if (useWidgetStore().inputIsWidget(inputs[inputName])) {
|
||||
const convertedIndex = node.inputs?.findIndex(
|
||||
(inp) => inp.name === inputName && inp.widget?.name === inputName
|
||||
)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// @ts-strict-ignore
|
||||
import type { IWidget } from '@comfyorg/litegraph'
|
||||
import type { IWidget, LGraphNode } from '@comfyorg/litegraph'
|
||||
import type { IStringWidget } from '@comfyorg/litegraph/dist/types/widgets'
|
||||
|
||||
import { useNodeDragAndDrop } from '@/composables/node/useNodeDragAndDrop'
|
||||
@@ -97,7 +97,7 @@ app.registerExtension({
|
||||
},
|
||||
getCustomWidgets() {
|
||||
return {
|
||||
AUDIO_UI(node, inputName: string) {
|
||||
AUDIO_UI(node: LGraphNode, inputName: string) {
|
||||
const audio = document.createElement('audio')
|
||||
audio.controls = true
|
||||
audio.classList.add('comfy-audio')
|
||||
|
||||
@@ -19,11 +19,7 @@ import {
|
||||
type NodeId,
|
||||
validateComfyWorkflow
|
||||
} from '@/schemas/comfyWorkflowSchema'
|
||||
import {
|
||||
type ComfyNodeDef as ComfyNodeDefV2,
|
||||
isComboInputSpec,
|
||||
isComfyNodeDef as isComfyNodeDefV2
|
||||
} from '@/schemas/nodeDef/nodeDefSchemaV2'
|
||||
import { type ComfyNodeDef as ComfyNodeDefV2 } from '@/schemas/nodeDef/nodeDefSchemaV2'
|
||||
import type { ComfyNodeDef as ComfyNodeDefV1 } from '@/schemas/nodeDefSchema'
|
||||
import { getFromWebmFile } from '@/scripts/metadata/ebml'
|
||||
import { useDialogService } from '@/services/dialogService'
|
||||
@@ -35,11 +31,7 @@ import { useExecutionStore } from '@/stores/executionStore'
|
||||
import { useExtensionStore } from '@/stores/extensionStore'
|
||||
import { KeyComboImpl, useKeybindingStore } from '@/stores/keybindingStore'
|
||||
import { useModelStore } from '@/stores/modelStore'
|
||||
import {
|
||||
ComfyNodeDefImpl,
|
||||
SYSTEM_NODE_DEFS,
|
||||
useNodeDefStore
|
||||
} from '@/stores/nodeDefStore'
|
||||
import { SYSTEM_NODE_DEFS, useNodeDefStore } from '@/stores/nodeDefStore'
|
||||
import { useSettingStore } from '@/stores/settingStore'
|
||||
import { useToastStore } from '@/stores/toastStore'
|
||||
import { useWidgetStore } from '@/stores/widgetStore'
|
||||
@@ -64,7 +56,7 @@ import {
|
||||
} from './pnginfo'
|
||||
import { $el, ComfyUI } from './ui'
|
||||
import { ComfyAppMenu } from './ui/menu/index'
|
||||
import { clone, getStorageValue } from './utils'
|
||||
import { clone } from './utils'
|
||||
import { type ComfyWidgetConstructor, ComfyWidgets } from './widgets'
|
||||
|
||||
export const ANIM_PREVIEW_WIDGET = '$$comfy_animation_preview'
|
||||
@@ -93,10 +85,6 @@ type Clipspace = {
|
||||
img_paste_mode: string
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {import("types/comfy").ComfyExtension} ComfyExtension
|
||||
*/
|
||||
|
||||
export class ComfyApp {
|
||||
/**
|
||||
* List of entries to queue
|
||||
@@ -925,22 +913,6 @@ export class ComfyApp {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the impl after groupNode unit tests are removed.
|
||||
* @deprecated Use useWidgetStore().getWidgetType instead
|
||||
*/
|
||||
getWidgetType(inputData, inputName: string) {
|
||||
const type = inputData[0]
|
||||
|
||||
if (Array.isArray(type)) {
|
||||
return 'COMBO'
|
||||
} else if (type in this.widgets) {
|
||||
return type
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
async registerNodeDef(nodeId: string, nodeDef: ComfyNodeDefV1) {
|
||||
return await useLitegraphService().registerNodeDef(nodeId, nodeDef)
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import { IWidget } from '@comfyorg/litegraph/dist/types/widgets'
|
||||
import { useNodeImage, useNodeVideo } from '@/composables/node/useNodeImage'
|
||||
import { st } from '@/i18n'
|
||||
import type { NodeId } from '@/schemas/comfyWorkflowSchema'
|
||||
import { transformInputSpecV2ToV1 } from '@/schemas/nodeDef/migration'
|
||||
import type { ComfyNodeDef as ComfyNodeDefV2 } from '@/schemas/nodeDef/nodeDefSchemaV2'
|
||||
import type { ComfyNodeDef as ComfyNodeDefV1 } from '@/schemas/nodeDefSchema'
|
||||
import { ANIM_PREVIEW_WIDGET, ComfyApp, app } from '@/scripts/app'
|
||||
@@ -22,6 +23,7 @@ import { useCanvasStore } from '@/stores/graphStore'
|
||||
import { useNodeOutputStore } from '@/stores/imagePreviewStore'
|
||||
import { ComfyNodeDefImpl } from '@/stores/nodeDefStore'
|
||||
import { useToastStore } from '@/stores/toastStore'
|
||||
import { useWidgetStore } from '@/stores/widgetStore'
|
||||
import { normalizeI18nKey } from '@/utils/formatUtil'
|
||||
import { is_all_same_aspect_ratio } from '@/utils/imageUtil'
|
||||
import { getImageTop, isImageNode, isVideoNode } from '@/utils/litegraphUtil'
|
||||
@@ -34,6 +36,7 @@ import { useExtensionService } from './extensionService'
|
||||
export const useLitegraphService = () => {
|
||||
const extensionService = useExtensionService()
|
||||
const toastStore = useToastStore()
|
||||
const widgetStore = useWidgetStore()
|
||||
const canvasStore = useCanvasStore()
|
||||
|
||||
async function registerNodeDef(nodeId: string, nodeDefV1: ComfyNodeDefV1) {
|
||||
@@ -52,19 +55,16 @@ export const useLitegraphService = () => {
|
||||
const inputType = inputSpec.type
|
||||
const nameKey = `nodeDefs.${normalizeI18nKey(nodeDef.name)}.inputs.${normalizeI18nKey(inputName)}.name`
|
||||
|
||||
const widgetType = app.getWidgetType(
|
||||
[inputType, inputSpec],
|
||||
inputName
|
||||
)
|
||||
if (widgetType) {
|
||||
const widgetConstructor = widgetStore.widgets[inputType]
|
||||
if (widgetConstructor) {
|
||||
const {
|
||||
widget,
|
||||
minWidth = 1,
|
||||
minHeight = 1
|
||||
} = app.widgets[widgetType](
|
||||
} = widgetConstructor(
|
||||
this,
|
||||
inputName,
|
||||
[inputType, inputSpec],
|
||||
transformInputSpecV2ToV1(inputSpec),
|
||||
app
|
||||
) ?? {}
|
||||
|
||||
|
||||
@@ -2,6 +2,10 @@ import { defineStore } from 'pinia'
|
||||
import { computed, ref } from 'vue'
|
||||
|
||||
import type { InputSpec as InputSpecV2 } from '@/schemas/nodeDef/nodeDefSchemaV2'
|
||||
import {
|
||||
type InputSpec as InputSpecV1,
|
||||
getInputSpecType
|
||||
} from '@/schemas/nodeDefSchema'
|
||||
import { ComfyWidgetConstructor, ComfyWidgets } from '@/scripts/widgets'
|
||||
|
||||
export const useWidgetStore = defineStore('widget', () => {
|
||||
@@ -12,8 +16,9 @@ export const useWidgetStore = defineStore('widget', () => {
|
||||
...coreWidgets
|
||||
}))
|
||||
|
||||
function inputIsWidget(spec: InputSpecV2) {
|
||||
return spec.type in widgets.value
|
||||
function inputIsWidget(spec: InputSpecV2 | InputSpecV1) {
|
||||
const type = Array.isArray(spec) ? getInputSpecType(spec) : spec.type
|
||||
return type in widgets.value
|
||||
}
|
||||
|
||||
function registerCustomWidgets(
|
||||
|
||||
Reference in New Issue
Block a user