Support associated socket for widgets (#3326)

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Chenlei Hu
2025-04-06 11:50:21 -04:00
committed by GitHub
parent 6eb2b76621
commit ac53296b2e
41 changed files with 212 additions and 534 deletions

View File

@@ -10,23 +10,21 @@ import { ComfyWidgetConstructor, ComfyWidgets } from '@/scripts/widgets'
export const useWidgetStore = defineStore('widget', () => {
const coreWidgets = ComfyWidgets
const customWidgets = ref<Record<string, ComfyWidgetConstructor>>({})
const widgets = computed(() => ({
...customWidgets.value,
...coreWidgets
}))
const customWidgets = ref<Map<string, ComfyWidgetConstructor>>(new Map())
const widgets = computed<Map<string, ComfyWidgetConstructor>>(
() => new Map([...customWidgets.value, ...Object.entries(coreWidgets)])
)
function inputIsWidget(spec: InputSpecV2 | InputSpecV1) {
const type = Array.isArray(spec) ? getInputSpecType(spec) : spec.type
return type in widgets.value
return widgets.value.has(type)
}
function registerCustomWidgets(
newWidgets: Record<string, ComfyWidgetConstructor>
) {
customWidgets.value = {
...customWidgets.value,
...newWidgets
for (const [type, widget] of Object.entries(newWidgets)) {
customWidgets.value.set(type, widget)
}
}