mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-24 00:09:32 +00:00
Manage widget definitions with Pinia store (#1510)
* Fix compile * nit * Remove extensions.test * nit
This commit is contained in:
45
src/stores/widgetStore.ts
Normal file
45
src/stores/widgetStore.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { ComfyWidgets, ComfyWidgetConstructor } from '@/scripts/widgets'
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref, computed } from 'vue'
|
||||
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
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user