From 92ae379ee9434c67a710f1ea3bf62f781e3771ca Mon Sep 17 00:00:00 2001 From: space-nuko <24979496+space-nuko@users.noreply.github.com> Date: Sat, 6 May 2023 20:48:27 -0500 Subject: [PATCH] Fix widget autoconfig --- src/lib/nodes/ComfyWidgetNodes.ts | 6 ++++-- src/lib/utils.ts | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/lib/nodes/ComfyWidgetNodes.ts b/src/lib/nodes/ComfyWidgetNodes.ts index 095cce6..1f37939 100644 --- a/src/lib/nodes/ComfyWidgetNodes.ts +++ b/src/lib/nodes/ComfyWidgetNodes.ts @@ -10,7 +10,7 @@ import type { SvelteComponentDev } from "svelte/internal"; import { Watch } from "@litegraph-ts/nodes-basic"; import type IComfyInputSlot from "$lib/IComfyInputSlot"; import { writable, type Unsubscriber, type Writable, get } from "svelte/store"; -import { clamp } from "$lib/utils" +import { clamp, range } from "$lib/utils" import layoutState from "$lib/stores/layoutState"; import type { FileData as GradioFileData } from "@gradio/upload"; import queueState from "$lib/stores/queueState"; @@ -143,7 +143,9 @@ export abstract class ComfyWidgetNode extends ComfyGraphNode { inputNode: LGraphNode, inputIndex: number ): boolean { - if (this.autoConfig && "config" in input && this.outputs.length === 0) { + const anyConnected = range(this.outputs.length).some(i => this.getOutputLinks(i).length > 0); + + if (this.autoConfig && "config" in input && !anyConnected) { this.doAutoConfig(input as IComfyInputSlot) } diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 0e1d224..ddf2e4a 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -11,6 +11,10 @@ export function clamp(n: number, min: number, max: number): number { return Math.min(Math.max(n, min), max) } +export function range(size: number, startAt: number = 0): ReadonlyArray { + return [...Array(size).keys()].map(i => i + startAt); +} + export function download(filename: string, text: string, type: string = "text/plain") { const blob = new Blob([text], { type: type }); const url = URL.createObjectURL(blob);