From babfb8a4b45be274a83950ce5bfe738d1bfebb5a Mon Sep 17 00:00:00 2001 From: space-nuko <24979496+space-nuko@users.noreply.github.com> Date: Tue, 9 May 2023 18:40:35 -0500 Subject: [PATCH] Things for ControlNet --- litegraph | 2 +- src/lib/ComfyGraph.ts | 3 +- src/lib/components/AccordionContainer.svelte | 5 ++- src/lib/nodes/ComfyActionNodes.ts | 35 +++++++++++++++++++- src/lib/nodes/ComfyWidgetNodes.ts | 3 ++ src/lib/notify.ts | 19 ++++++++--- src/lib/stores/layoutState.ts | 6 ++++ 7 files changed, 65 insertions(+), 8 deletions(-) diff --git a/litegraph b/litegraph index ed3ae7c..5a13f7a 160000 --- a/litegraph +++ b/litegraph @@ -1 +1 @@ -Subproject commit ed3ae7c4772d27c3ed9acaecc08a8045b7ad3c54 +Subproject commit 5a13f7adab694ebb4d713be6285344662f49530e diff --git a/src/lib/ComfyGraph.ts b/src/lib/ComfyGraph.ts index 0fb058b..17a9836 100644 --- a/src/lib/ComfyGraph.ts +++ b/src/lib/ComfyGraph.ts @@ -90,7 +90,8 @@ export default class ComfyGraph extends LGraph { } if (get(uiState).autoAddUI) { - if (!("svelteComponentType" in node) && !options.addedByDeserialize) { + console.warn("ADD", node.type, options) + if (!("svelteComponentType" in node) && options.addedByDeserialize == null) { console.debug("[ComfyGraph] AutoAdd UI") const comfyNode = node as ComfyGraphNode; const widgetNodesAdded = [] diff --git a/src/lib/components/AccordionContainer.svelte b/src/lib/components/AccordionContainer.svelte index 0849883..79ca884 100644 --- a/src/lib/components/AccordionContainer.svelte +++ b/src/lib/components/AccordionContainer.svelte @@ -32,6 +32,9 @@ $: if (container) { children = $layoutState.allItems[container.id].children; attrsChanged = container.attrsChanged + if (container.isOpen == null) { + container.isOpen = container.attrs.openOnStartup + } } else { children = null; @@ -97,7 +100,7 @@ {:else} - + {#each children.filter(item => item.id !== SHADOW_PLACEHOLDER_ITEM_ID) as item(item.id)} {/each} diff --git a/src/lib/nodes/ComfyActionNodes.ts b/src/lib/nodes/ComfyActionNodes.ts index bc47b30..660fd95 100644 --- a/src/lib/nodes/ComfyActionNodes.ts +++ b/src/lib/nodes/ComfyActionNodes.ts @@ -213,7 +213,8 @@ export class ComfyNotifyAction extends ComfyGraphNode { return; const options: NotifyOptions = { - type: this.properties.type + type: this.properties.type, + showOn: "all" } // Check if this event was triggered from a backend node and has the @@ -546,3 +547,35 @@ LiteGraph.registerNodeType({ desc: "Turns multiple groups of nodes on/off at once based on an array of rules [{ tag: string, enable: boolean }, ...]", type: "actions/set_node_mode_advanced" }) + +export class ComfyNoChangeEvent extends ComfyGraphNode { + static slotLayout: SlotLayout = { + inputs: [ + { name: "in", type: BuiltInSlotType.ACTION }, + ], + outputs: [ + { name: "out", type: BuiltInSlotType.EVENT }, + ], + } + + override onAction(action: any, param: any, options: { action_call?: string }) { + if (param && typeof param === "object" && "noChangedEvent" in param) { + param.noChangedEvent = true; + } + else { + param = { + value: param, + noChangedEvent: true + } + } + + this.triggerSlot(0, param, null, options); + } +} + +LiteGraph.registerNodeType({ + class: ComfyNoChangeEvent, + title: "Comfy.NoChangeEvent", + desc: "Wraps an event's parameter such that passing it into a ComfyWidgetNode's 'store' action will not trigger its 'changed' event", + type: "events/no_change" +}) diff --git a/src/lib/nodes/ComfyWidgetNodes.ts b/src/lib/nodes/ComfyWidgetNodes.ts index b5545dc..df8b356 100644 --- a/src/lib/nodes/ComfyWidgetNodes.ts +++ b/src/lib/nodes/ComfyWidgetNodes.ts @@ -827,6 +827,7 @@ export class ComfyImageUploadNode extends ComfyWidgetNode> { name: "filename", type: "string" }, // TODO support batches { name: "width", type: "number" }, { name: "height", type: "number" }, + { name: "image_count", type: "number" }, { name: "changed", type: BuiltInSlotType.EVENT }, ] } @@ -851,11 +852,13 @@ export class ComfyImageUploadNode extends ComfyWidgetNode> this.setOutputData(0, value[0].name) // TODO when ComfyUI LoadImage supports loading an image batch this.setOutputData(1, this.imageSize[0]) this.setOutputData(2, this.imageSize[1]) + this.setOutputData(3, value.length) } else { this.setOutputData(0, "") this.setOutputData(1, 1) this.setOutputData(2, 1) + this.setOutputData(3, 0) } } diff --git a/src/lib/notify.ts b/src/lib/notify.ts index 97fc382..531c0ba 100644 --- a/src/lib/notify.ts +++ b/src/lib/notify.ts @@ -7,7 +7,8 @@ export type NotifyOptions = { title?: string, type?: "neutral" | "info" | "warning" | "error" | "success", imageUrl?: string, - timeout?: number | null + timeout?: number | null, + showOn?: "web" | "native" | "all" | "none" } function notifyf7(text: string, options: NotifyOptions) { @@ -76,7 +77,17 @@ function notifyNative(text: string, options: NotifyOptions) { } export default function notify(text: string, options: NotifyOptions = {}) { - notifyf7(text, options); - notifyToast(text, options); - notifyNative(text, options) + const showOn = options.showOn || "web"; + + if (showOn === "none") + return; + + if (showOn === "all" || showOn === "web") { + notifyf7(text, options); + notifyToast(text, options); + } + + if (showOn === "all" || showOn === "native") { + notifyNative(text, options) + } } diff --git a/src/lib/stores/layoutState.ts b/src/lib/stores/layoutState.ts index fae9cdd..eebef67 100644 --- a/src/lib/stores/layoutState.ts +++ b/src/lib/stores/layoutState.ts @@ -591,6 +591,12 @@ export interface IDragItem { */ export interface ContainerLayout extends IDragItem { type: "container", + + // Ephemeral state to preserve when the component gets recreated by Svelte + // (not serialized) + + // Accordion + isOpen?: boolean, } /*