From cfaf769a65b08e49090289892bd5e9d599d58321 Mon Sep 17 00:00:00 2001 From: Chenlei Hu Date: Tue, 1 Apr 2025 15:13:46 -0400 Subject: [PATCH] [TS] Properly type slot widget (#3305) --- package-lock.json | 8 ++++---- package.json | 2 +- src/extensions/core/groupNode.ts | 2 +- src/extensions/core/widgetInputs.ts | 24 ++++++++++-------------- src/types/litegraph-augmentation.d.ts | 2 +- 5 files changed, 17 insertions(+), 21 deletions(-) diff --git a/package-lock.json b/package-lock.json index 397920390..60870ce58 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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": { diff --git a/package.json b/package.json index 204ded0ca..cf4942854 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/extensions/core/groupNode.ts b/src/extensions/core/groupNode.ts index 3b52522c2..b74f28c67 100644 --- a/src/extensions/core/groupNode.ts +++ b/src/extensions/core/groupNode.ts @@ -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, diff --git a/src/extensions/core/widgetInputs.ts b/src/extensions/core/widgetInputs.ts index 648a2275f..89026d7f9 100644 --- a/src/extensions/core/widgetInputs.ts +++ b/src/extensions/core/widgetInputs.ts @@ -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) diff --git a/src/types/litegraph-augmentation.d.ts b/src/types/litegraph-augmentation.d.ts index b8239cb7e..8a6d18a4d 100644 --- a/src/types/litegraph-augmentation.d.ts +++ b/src/types/litegraph-augmentation.d.ts @@ -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 } } }