mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-04 07:00:23 +00:00
[TS] Properly type slot widget (#3305)
This commit is contained in:
8
package-lock.json
generated
8
package-lock.json
generated
@@ -12,7 +12,7 @@
|
||||
"@alloc/quick-lru": "^5.2.0",
|
||||
"@atlaskit/pragmatic-drag-and-drop": "^1.3.1",
|
||||
"@comfyorg/comfyui-electron-types": "^0.4.31",
|
||||
"@comfyorg/litegraph": "^0.11.7",
|
||||
"@comfyorg/litegraph": "^0.11.8",
|
||||
"@primevue/forms": "^4.2.5",
|
||||
"@primevue/themes": "^4.2.5",
|
||||
"@sentry/vue": "^8.48.0",
|
||||
@@ -478,9 +478,9 @@
|
||||
"license": "GPL-3.0-only"
|
||||
},
|
||||
"node_modules/@comfyorg/litegraph": {
|
||||
"version": "0.11.7",
|
||||
"resolved": "https://registry.npmjs.org/@comfyorg/litegraph/-/litegraph-0.11.7.tgz",
|
||||
"integrity": "sha512-ftz9QOD53ZVLLyu3m5Hi+FKHp+y7k+wHvrsgvX/X6a0l840kGlnOI+W3em8yajIuOIgqbjDsu5ZeXZn2l1FUpw==",
|
||||
"version": "0.11.8",
|
||||
"resolved": "https://registry.npmjs.org/@comfyorg/litegraph/-/litegraph-0.11.8.tgz",
|
||||
"integrity": "sha512-N2RJvLCD5m53WeJ4Ip5ZLG26LncqBisHfeKZegNOwADoaJiHoSFuJrqdLu4LFVTr9JxP7gI2dyTRW9gYI8njbg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@cspotcode/source-map-support": {
|
||||
|
||||
@@ -71,7 +71,7 @@
|
||||
"@alloc/quick-lru": "^5.2.0",
|
||||
"@atlaskit/pragmatic-drag-and-drop": "^1.3.1",
|
||||
"@comfyorg/comfyui-electron-types": "^0.4.31",
|
||||
"@comfyorg/litegraph": "^0.11.7",
|
||||
"@comfyorg/litegraph": "^0.11.8",
|
||||
"@primevue/forms": "^4.2.5",
|
||||
"@primevue/themes": "^4.2.5",
|
||||
"@sentry/vue": "^8.48.0",
|
||||
|
||||
@@ -384,8 +384,8 @@ export class GroupNodeConfig {
|
||||
|
||||
const widget = [targetWidget[0], config]
|
||||
const res = mergeIfValid(
|
||||
// @ts-expect-error invalid slot type
|
||||
{
|
||||
// @ts-expect-error fixme ts strict error
|
||||
widget
|
||||
},
|
||||
targetWidget,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { LGraphNode, LiteGraph } from '@comfyorg/litegraph'
|
||||
import { LGraphNode, LiteGraph, RenderShape } from '@comfyorg/litegraph'
|
||||
import type {
|
||||
IFoundSlot,
|
||||
INodeInputSlot,
|
||||
@@ -94,6 +94,7 @@ export class PrimitiveNode extends LGraphNode {
|
||||
refreshComboInNode() {
|
||||
const widget = this.widgets?.[0]
|
||||
if (widget?.type === 'combo') {
|
||||
// @ts-expect-error fixme ts strict error
|
||||
widget.options.values = this.outputs[0].widget[GET_CONFIG]()[0]
|
||||
|
||||
// @ts-expect-error fixme ts strict error
|
||||
@@ -210,7 +211,6 @@ export class PrimitiveNode extends LGraphNode {
|
||||
this.outputs[0].widget = widget
|
||||
|
||||
this.#createWidget(
|
||||
// @ts-expect-error fixme ts strict error
|
||||
widget[CONFIG] ?? config,
|
||||
theirNode,
|
||||
widget.name,
|
||||
@@ -341,9 +341,9 @@ export class PrimitiveNode extends LGraphNode {
|
||||
const output = this.outputs[0]
|
||||
const links = output.links
|
||||
|
||||
const hasConfig = !!output.widget[CONFIG]
|
||||
const hasConfig = !!output.widget?.[CONFIG]
|
||||
if (hasConfig) {
|
||||
delete output.widget[CONFIG]
|
||||
delete output.widget?.[CONFIG]
|
||||
}
|
||||
|
||||
// @ts-expect-error fixme ts strict error
|
||||
@@ -356,8 +356,8 @@ export class PrimitiveNode extends LGraphNode {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
const config1 = output.widget[GET_CONFIG]()
|
||||
// @ts-expect-error fixme ts strict error
|
||||
const config1 = output.widget?.[GET_CONFIG]?.()
|
||||
const isNumber = config1[0] === 'INT' || config1[0] === 'FLOAT'
|
||||
if (!isNumber) return
|
||||
|
||||
@@ -387,6 +387,7 @@ export class PrimitiveNode extends LGraphNode {
|
||||
if (!isConvertibleWidget(targetWidget, config2)) return false
|
||||
|
||||
const output = this.outputs[originSlot]
|
||||
// @ts-expect-error fixme ts strict error
|
||||
if (!(output.widget?.[CONFIG] ?? output.widget?.[GET_CONFIG]())) {
|
||||
// No widget defined for this primitive yet so allow it
|
||||
return true
|
||||
@@ -447,6 +448,7 @@ export class PrimitiveNode extends LGraphNode {
|
||||
}
|
||||
|
||||
export function getWidgetConfig(slot: INodeInputSlot | INodeOutputSlot) {
|
||||
// @ts-expect-error fixme ts strict error
|
||||
return slot.widget[CONFIG] ?? slot.widget[GET_CONFIG]?.() ?? ['*', {}]
|
||||
}
|
||||
|
||||
@@ -540,9 +542,8 @@ export function convertToInput(
|
||||
const [oldWidth, oldHeight] = node.size
|
||||
const inputIsOptional = !!widget.options?.inputIsOptional
|
||||
const input = node.addInput(widget.name, type, {
|
||||
// @ts-expect-error [GET_CONFIG] is not a valid property of IWidget
|
||||
widget: { name: widget.name, [GET_CONFIG]: () => config },
|
||||
...(inputIsOptional ? { shape: LiteGraph.SlotShape.HollowCircle } : {})
|
||||
...(inputIsOptional ? { shape: RenderShape.HollowCircle } : {})
|
||||
})
|
||||
|
||||
// @ts-expect-error fixme ts strict error
|
||||
@@ -631,6 +632,7 @@ export function mergeIfValid(
|
||||
|
||||
if (customSpec || forceUpdate) {
|
||||
if (customSpec) {
|
||||
// @ts-expect-error fixme ts strict error
|
||||
output.widget[CONFIG] = customSpec
|
||||
}
|
||||
|
||||
@@ -826,16 +828,13 @@ app.registerExtension({
|
||||
|
||||
for (const input of this.inputs) {
|
||||
if (input.widget) {
|
||||
// @ts-expect-error fixme ts strict error
|
||||
if (!input.widget[GET_CONFIG]) {
|
||||
// @ts-expect-error fixme ts strict error
|
||||
input.widget[GET_CONFIG] = () =>
|
||||
// @ts-expect-error fixme ts strict error
|
||||
getConfig.call(this, input.widget.name)
|
||||
}
|
||||
|
||||
// Cleanup old widget config
|
||||
// @ts-expect-error WidgetRef
|
||||
if (input.widget.config) {
|
||||
// @ts-expect-error WidgetRef
|
||||
if (input.widget.config[0] instanceof Array) {
|
||||
@@ -848,7 +847,6 @@ app.registerExtension({
|
||||
link.type = input.type
|
||||
}
|
||||
}
|
||||
// @ts-expect-error WidgetRef
|
||||
delete input.widget.config
|
||||
}
|
||||
|
||||
@@ -892,9 +890,7 @@ app.registerExtension({
|
||||
if (!app.configuringGraph && this.inputs) {
|
||||
// On copy + paste of nodes, ensure that widget configs are set up
|
||||
for (const input of this.inputs) {
|
||||
// @ts-expect-error fixme ts strict error
|
||||
if (input.widget && !input.widget[GET_CONFIG]) {
|
||||
// @ts-expect-error fixme ts strict error
|
||||
input.widget[GET_CONFIG] = () =>
|
||||
// @ts-expect-error fixme ts strict error
|
||||
getConfig.call(this, input.widget.name)
|
||||
|
||||
2
src/types/litegraph-augmentation.d.ts
vendored
2
src/types/litegraph-augmentation.d.ts
vendored
@@ -186,7 +186,7 @@ declare module '@comfyorg/litegraph' {
|
||||
* We should remove this hacky solution once we have a proper solution.
|
||||
*/
|
||||
interface INodeOutputSlot {
|
||||
widget?: IWidget
|
||||
widget?: { name: string; [key: symbol]: unknown }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user