mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-01 22:09:55 +00:00
48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
import { defineStore } from 'pinia'
|
|
import { computed, ref } from 'vue'
|
|
|
|
import { ComfyWidgetConstructor, ComfyWidgets } from '@/scripts/widgets'
|
|
|
|
import type { BaseInputSpec } from './nodeDefStore'
|
|
|
|
export const useWidgetStore = defineStore('widget', () => {
|
|
const coreWidgets = ComfyWidgets
|
|
const customWidgets = ref<Record<string, ComfyWidgetConstructor>>({})
|
|
const widgets = computed(() => ({
|
|
...customWidgets.value,
|
|
...coreWidgets
|
|
}))
|
|
|
|
function getWidgetType(type: string, inputName: string) {
|
|
if (type === 'COMBO') {
|
|
return 'COMBO'
|
|
} else if (`${type}:${inputName}` in widgets.value) {
|
|
return `${type}:${inputName}`
|
|
} else if (type in widgets.value) {
|
|
return type
|
|
} else {
|
|
return null
|
|
}
|
|
}
|
|
|
|
function inputIsWidget(spec: BaseInputSpec) {
|
|
return getWidgetType(spec.type, spec.name) !== null
|
|
}
|
|
|
|
function registerCustomWidgets(
|
|
newWidgets: Record<string, ComfyWidgetConstructor>
|
|
) {
|
|
customWidgets.value = {
|
|
...customWidgets.value,
|
|
...newWidgets
|
|
}
|
|
}
|
|
|
|
return {
|
|
widgets,
|
|
getWidgetType,
|
|
inputIsWidget,
|
|
registerCustomWidgets
|
|
}
|
|
})
|