From e3e1b47aa63df213b6c11ed243a0db6845adb412 Mon Sep 17 00:00:00 2001 From: pythongosssss <125205205+pythongosssss@users.noreply.github.com> Date: Thu, 22 Feb 2024 20:38:59 +0000 Subject: [PATCH] Support inserting workflows Move buttosn to top of lists --- web/scripts/app.js | 2 +- web/scripts/ui/menu/menu.css | 8 +++---- web/scripts/ui/menu/viewList.js | 2 +- web/scripts/ui/menu/workflows.js | 37 ++++++++++++++++++++++---------- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/web/scripts/app.js b/web/scripts/app.js index 6d1d58657..746856759 100644 --- a/web/scripts/app.js +++ b/web/scripts/app.js @@ -1793,7 +1793,7 @@ export class ComfyApp { } try { - this.graph.configure(graphData, keepOld); + this.graph.configure(graphData); } catch (error) { let errorHint = []; // Try extracting filename to see if it was caused by an extension script diff --git a/web/scripts/ui/menu/menu.css b/web/scripts/ui/menu/menu.css index 7c9bafdd9..0cf529527 100644 --- a/web/scripts/ui/menu/menu.css +++ b/web/scripts/ui/menu/menu.css @@ -484,15 +484,15 @@ text-align: center; padding: 0 2px; } -.comfyui-view-list-popup footer { - margin-top: 10px; +.comfyui-view-list-popup header { + margin-bottom: 10px; display: flex; gap: 5px; } -.comfyui-view-list-popup footer .comfyui-button { +.comfyui-view-list-popup header .comfyui-button { border: 1px solid transparent; } -.comfyui-view-list-popup footer .comfyui-button:not(:disabled):hover { +.comfyui-view-list-popup header .comfyui-button:not(:disabled):hover { border: 1px solid var(--comfy-menu-bg); } /* Queue button */ diff --git a/web/scripts/ui/menu/viewList.js b/web/scripts/ui/menu/viewList.js index 9e891f4ff..693ca335c 100644 --- a/web/scripts/ui/menu/viewList.js +++ b/web/scripts/ui/menu/viewList.js @@ -71,8 +71,8 @@ export class ComfyViewList { this.element = $el(`div.comfyui-${this.type}-popup.comfyui-view-list-popup`, [ $el("h3", mode), + $el("header", [this.clear.element, this.refresh.element]), this.items, - $el("footer", [this.clear.element, this.refresh.element]), ]); api.addEventListener("status", () => { diff --git a/web/scripts/ui/menu/workflows.js b/web/scripts/ui/menu/workflows.js index f491c615b..166401497 100644 --- a/web/scripts/ui/menu/workflows.js +++ b/web/scripts/ui/menu/workflows.js @@ -343,35 +343,50 @@ class FileNode { deleteButton.element.style.removeProperty("background"); }); - const loadWorkflow = async (e) => { + const getWorkflow = async (e) => { e.stopImmediatePropagation(); const resp = await api.getUserData(fileName); if (resp.status !== 200) { - alert(`Error storing user data file '${fileName}': ${resp.status} ${resp.statusText}`); + alert(`Error loading user data file '${fileName}': ${resp.status} ${resp.statusText}`); return; } - const data = await resp.json(); + return await resp.json(); + }; + + const loadWorkflow = async (e) => { + const data = await getWorkflow(e); await this.parent.app.loadGraphData(data, true, this.path); this.parent.popup.open = false; }; + const insertWorkflow = async (e) => { + const data = await getWorkflow(e); + const old = localStorage.getItem("litegrapheditor_clipboard"); + const graph = new LGraph(data); + const canvas = new LGraphCanvas(null, graph, { skip_events: true, skip_render: true }); + canvas.selectNodes(); + canvas.copyToClipboard(); + this.parent.app.canvas.pasteFromClipboard(); + localStorage.setItem("litegrapheditor_clipboard", old); + }; + const name = trimJsonExt(this.part); this.element = $el( tagName + ".comfyui-workflows-tree-file", { - onclick: (e) => loadWorkflow(e), + onclick: loadWorkflow, title: this.path, }, [ this.nodeIcon, $el("span", name), - // new ComfyButton({ - // icon: "file-move-outline", - // tooltip: "Insert this workflow into the current view", - // classList: "comfyui-button comfyui-workflows-file-action", - // iconSize: 18, - // action: (e) => loadWorkflow(e, true), - // }).element, + new ComfyButton({ + icon: "file-move-outline", + tooltip: "Insert this workflow into the current view", + classList: "comfyui-button comfyui-workflows-file-action", + iconSize: 18, + action: insertWorkflow, + }).element, new ComfyButton({ icon: "pencil", tooltip: "Rename this workflow",