diff --git a/web/scripts/ui/components/button.js b/web/scripts/ui/components/button.js index 4d2b7227b..130562e83 100644 --- a/web/scripts/ui/components/button.js +++ b/web/scripts/ui/components/button.js @@ -10,6 +10,7 @@ import { prop } from "../../utils.js"; * iconSize?: number; * content?: string | HTMLElement; * tooltip?: string; + * enabled?: boolean; * action?: (e: Event, btn: ComfyButton) => void, * classList?: import("../utils.js").ClassList, * visibilitySetting?: { id: string, showValue: any }, @@ -18,6 +19,7 @@ import { prop } from "../../utils.js"; */ export class ComfyButton { #over = 0; + #popupOpen = false; iconElement = $el("i.mdi"); contentElement = $el("span"); /** @@ -28,7 +30,7 @@ export class ComfyButton { /** * @param {ComfyButtonProps} opts */ - constructor({ icon, iconSize, content, tooltip, action, classList = "comfyui-button", visibilitySetting, app }) { + constructor({ icon, iconSize, content, tooltip, action, classList = "comfyui-button", visibilitySetting, app, enabled = true }) { this.element = $el("button", [this.iconElement, this.contentElement]); this.icon = prop(this, "icon", icon, toggleElement(this.iconElement, { onShow: this.updateIcon })); @@ -48,9 +50,19 @@ export class ComfyButton { }) ); - this.tooltip = prop(this, "tooltip", tooltip, (v) => (this.element.title = v ?? "")); + this.tooltip = prop(this, "tooltip", tooltip, (v) => { + if (v) { + this.element.title = v; + } else { + this.element.removeAttribute("title"); + } + }); this.classList = prop(this, "classList", classList, this.updateClasses); this.hidden = prop(this, "hidden", false, this.updateClasses); + this.enabled = prop(this, "enabled", enabled, () => { + this.updateClasses(); + this.element.disabled = !this.enabled; + }); this.action = prop(this, "action", action); this.element.addEventListener("click", (e) => { if (this.popup) { @@ -72,7 +84,21 @@ export class ComfyButton { } updateIcon = () => (this.iconElement.className = `mdi mdi-${this.icon}${this.iconSize ? " mdi-" + this.iconSize : ""}`); - updateClasses = () => applyClasses(this.element, this.classList, ...(this.hidden ? ["hidden"] : [])); + updateClasses = () => { + const internalClasses = []; + if (this.hidden) { + internalClasses.push("hidden"); + } + if (!this.enabled) { + internalClasses.push("disabled"); + } + if (this.#popupOpen) { + internalClasses.push("popup-open"); + } else { + internalClasses.push("popup-closed"); + } + applyClasses(this.element, this.classList, ...internalClasses); + }; /** * @@ -93,6 +119,11 @@ export class ComfyButton { } } + popup.addEventListener("change", () => { + this.#popupOpen = popup.open; + this.updateClasses(); + }); + return this; } } diff --git a/web/scripts/ui/components/buttonGroup.js b/web/scripts/ui/components/buttonGroup.js index ee25a6e17..573572fd0 100644 --- a/web/scripts/ui/components/buttonGroup.js +++ b/web/scripts/ui/components/buttonGroup.js @@ -7,7 +7,7 @@ import { prop } from "../../utils.js"; export class ComfyButtonGroup { element = $el("div.comfyui-button-group"); - /** @param {Array} buttons */ + /** @param {Array} buttons */ constructor(...buttons) { this.buttons = prop(this, "buttons", buttons, () => this.update()); } @@ -40,6 +40,6 @@ export class ComfyButtonGroup { } update() { - this.element.replaceChildren(...this.buttons.map((b) => b.element)); + this.element.replaceChildren(...this.buttons.map((b) => b["element"] ?? b)); } } diff --git a/web/scripts/ui/components/popup.js b/web/scripts/ui/components/popup.js index b9a2f50f6..e3631c200 100644 --- a/web/scripts/ui/components/popup.js +++ b/web/scripts/ui/components/popup.js @@ -41,7 +41,10 @@ export class ComfyPopup extends EventTarget { container.append(this.element); - this.children = prop(this, "children", children, () => this.element.replaceChildren(...this.children)); + this.children = prop(this, "children", children, () => { + this.element.replaceChildren(...this.children); + this.update(); + }); this.classList = prop(this, "classList", classList, () => applyClasses(this.element, this.classList, "comfyui-popup", horizontal)); this.open = prop(this, "open", false, (v, o) => { if (v === o) return; @@ -59,7 +62,7 @@ export class ComfyPopup extends EventTarget { #hide() { this.element.classList.remove("open"); - window.removeEventListener("resize", this.#update); + window.removeEventListener("resize", this.update); window.removeEventListener("click", this.#clickHandler, { capture: true }); window.removeEventListener("keydown", this.#escHandler, { capture: true }); @@ -69,9 +72,9 @@ export class ComfyPopup extends EventTarget { #show() { this.element.classList.add("open"); - this.#update(); + this.update(); - window.addEventListener("resize", this.#update); + window.addEventListener("resize", this.update); window.addEventListener("click", this.#clickHandler, { capture: true }); if (this.closeOnEscape) { window.addEventListener("keydown", this.#escHandler, { capture: true }); @@ -97,7 +100,7 @@ export class ComfyPopup extends EventTarget { } }; - #update = () => { + update = () => { const rect = this.target.getBoundingClientRect(); if (this.position === "absolute") { if (this.horizontal === "left") { diff --git a/web/scripts/ui/menu/history.js b/web/scripts/ui/menu/history.js deleted file mode 100644 index e69de29bb..000000000 diff --git a/web/scripts/ui/menu/index.js b/web/scripts/ui/menu/index.js index 5477a3cc8..98eb08623 100644 --- a/web/scripts/ui/menu/index.js +++ b/web/scripts/ui/menu/index.js @@ -5,8 +5,11 @@ import { addStylesheet, downloadBlob } from "../../utils.js"; import { ComfyButton } from "../components/button.js"; import { ComfyButtonGroup } from "../components/buttonGroup.js"; import { ComfySplitButton } from "../components/splitButton.js"; +import { ComfyViewHistoryButton } from "./viewHistory.js"; import { ComfyQueueButton } from "./queueButton.js"; import { ComfyWorkflows } from "./workflows.js"; +import { ComfyViewQueueButton } from "./viewQueue.js"; +import { getInteruptButton } from "./interruptButton.js"; addStylesheet("menu.css", import.meta.url); @@ -49,6 +52,15 @@ export class ComfyAppMenu { icon: "content-save-edit", content: "Save As", tooltip: "Save the current graph as a new workflow", + action: () => { + let filename = prompt("Save workflow as:", "workflow"); + if (!filename) return; + if (!filename.toLowerCase().endsWith(".json")) { + filename += ".json"; + } + + this.exportWorkflow("workflow", "workflow"); + }, }), new ComfyButton({ icon: "download", @@ -61,8 +73,8 @@ export class ComfyAppMenu { content: "Export (API Format)", tooltip: "Export the current workflow as JSON for use with the ComfyUI API", action: () => this.exportWorkflow("workflow_api", "output"), - visibilitySetting: { id: "Comfy.DevMode", showValue: "true" }, - app + visibilitySetting: { id: "Comfy.DevMode", showValue: true }, + app, }) ).element, collapseOnMobile( @@ -70,22 +82,24 @@ export class ComfyAppMenu { new ComfyButton({ icon: "refresh", content: "Refresh", - action: () => { - console.log("refresh"); - }, + tooltip: "Refresh widgets in nodes to find new models or files", + action: () => app.refreshComboInNodes(), }), new ComfyButton({ icon: "clipboard-edit-outline", content: "Clipspace", - action: () => { - console.log("clipboard-edit-outline"); - }, + tooltip: "Open Clipspace window", + action: () => app["openClipspace"](), }), new ComfyButton({ icon: "cancel", content: "Clear", + tooltip: "Clears current workflow", action: () => { - console.log("cancel"); + if (!app.ui.settings.getSettingValue("Comfy.ConfirmClear", true) || confirm("Clear workflow?")) { + app.clean(); + app.graph.clear(); + } }, }) ) @@ -95,6 +109,7 @@ export class ComfyAppMenu { new ComfyButton({ icon: "cog", content: "Settings", + tooltip: "Open settings", action: () => { app.ui.settings.show(); }, @@ -102,28 +117,19 @@ export class ComfyAppMenu { ).element, collapseOnMobile( new ComfyButtonGroup( - new ComfyButton({ - icon: "history", - content: "View History", - action: () => { - console.log("history"); - }, - }), - new ComfyButton({ - icon: "format-list-numbered", - content: "View Queue", - action: () => { - console.log("format-list-numbered"); - }, - }) + new ComfyViewHistoryButton(app).element, + new ComfyViewQueueButton(app).element, + getInteruptButton("sm-hide").element ) ).element, - new ComfyQueueButton().element, + + getInteruptButton("sm-show").element, + new ComfyQueueButton(app).element, showOnMobile( new ComfyButton({ icon: "menu", action: (_, btn) => { - btn.icon = this.element.classList.toggle("expanded") ? "close" : "menu"; + btn.icon = this.element.classList.toggle("expanded") ? "menu-open" : "menu"; }, classList: "comfyui-button comfyui-menu-button", }) diff --git a/web/scripts/ui/menu/interruptButton.js b/web/scripts/ui/menu/interruptButton.js new file mode 100644 index 000000000..b285005b5 --- /dev/null +++ b/web/scripts/ui/menu/interruptButton.js @@ -0,0 +1,22 @@ +// @ts-check + +import { api } from "../../api.js"; +import { ComfyButton } from "../components/button.js"; + +export function getInteruptButton(visibility) { + const btn = new ComfyButton({ + icon: "close", + enabled: false, + action: () => { + api.interrupt(); + }, + classList: ["comfyui-button", "comfyui-interrupt-button", visibility], + }); + + api.addEventListener("status", ({ detail }) => { + const sz = detail?.exec_info?.queue_remaining; + btn.enabled = sz > 0; + }); + + return btn; +} diff --git a/web/scripts/ui/menu/menu.css b/web/scripts/ui/menu/menu.css index 6c32a7fce..d22ad6711 100644 --- a/web/scripts/ui/menu/menu.css +++ b/web/scripts/ui/menu/menu.css @@ -1,520 +1,373 @@ /* Utilities */ @media only screen and (max-width: 779px) { - .sm-hide { - display: none !important; - } + .sm-hide { + display: none !important; + } } @media only screen and (min-width: 780px) { - .sm-show { - display: none !important; - } + .sm-show { + display: none !important; + } } +.relative { + position: relative; +} .hidden { - display: none !important; + display: none !important; } /* Generic */ .comfyui-button { - display: flex; - align-items: center; - gap: 0.5em; - cursor: pointer; - border: none; - border-radius: 4px; - padding: 4px 8px; + display: flex; + align-items: center; + gap: 0.5em; + cursor: pointer; + border: none; + border-radius: 4px; + padding: 4px 8px; + box-sizing: border-box; } +.comfyui-button:disabled { + opacity: 0.5; + cursor: not-allowed; +} .primary .comfyui-button { - background-color: var(--primary-bg) !important; - color: var(--primary-fg) !important; + background-color: var(--primary-bg) !important; + color: var(--primary-fg) !important; } -.primary .comfyui-button:hover { - background-color: var(--primary-hover-bg) !important; - color: var(--primary-hover-fg) !important; +.primary .comfyui-button:not(:disabled):hover { + background-color: var(--primary-hover-bg) !important; + color: var(--primary-hover-fg) !important; } /* Popup */ .comfyui-popup { - position: absolute; - left: var(--left); - right: var(--right); - top: var(--top); - z-index: 1000; - max-height: calc(100vh - var(--top) - 10px); - max-width: calc(100vw - var(--left) - 10px); + position: absolute; + left: var(--left); + right: var(--right); + top: var(--top); + z-index: 1000; + max-height: calc(100vh - var(--top) - 10px); + max-width: calc(100vw - var(--left) - 10px); } .comfyui-popup:not(.open) { - display: none; + display: none; } /* Split button */ .comfyui-split-button { - position: relative; - display: flex; + position: relative; + display: flex; } .comfyui-split-primary { - flex: auto; + flex: auto; } .comfyui-split-primary .comfyui-button { - border-top-right-radius: 0; - border-bottom-right-radius: 0; - border-right: 1px solid var(--comfy-menu-bg); - width: 100%; + border-top-right-radius: 0; + border-bottom-right-radius: 0; + border-right: 1px solid var(--comfy-menu-bg); + width: 100%; } .comfyui-split-arrow .comfyui-button { - border-top-left-radius: 0; - border-bottom-left-radius: 0; - padding-left: 2px; - padding-right: 2px; + border-top-left-radius: 0; + border-bottom-left-radius: 0; + padding-left: 2px; + padding-right: 2px; } .comfyui-split-button-popup { - white-space: nowrap; - background-color: var(--border-color); - display: flex; - flex-direction: column; - overflow: auto; + white-space: nowrap; + background-color: var(--border-color); + display: flex; + flex-direction: column; + overflow: auto; } -.comfyui-split-button-popup>.comfyui-button { - border: none; - background-color: transparent; - color: var(--fg-color); - padding: 8px 12px 8px 8px; +.comfyui-split-button-popup > .comfyui-button { + border: none; + background-color: transparent; + color: var(--fg-color); + padding: 8px 12px 8px 8px; } -.comfyui-split-button-popup>.comfyui-button:hover { - background-color: var(--comfy-input-bg) +.comfyui-split-button-popup > .comfyui-button:not(:disabled):hover { + background-color: var(--comfy-input-bg); } /* Button group */ .comfyui-button-group { - display: flex; - border-radius: 4px; - overflow: hidden; + display: flex; + border-radius: 4px; + overflow: hidden; } -.comfyui-button-group>.comfyui-button { - padding: 4px 10px; - border-radius: 0; +.comfyui-button-group > .comfyui-button, +.comfyui-button-group > .comfyui-button-wrapper > .comfyui-button { + padding: 4px 10px; + border-radius: 0; } /* Menu */ .comfyui-menu { - position: absolute; - top: 0; - left: 0; - width: 100vw; - background: var(--comfy-menu-bg); - color: var(--fg-color); - font-family: Arial, Helvetica, sans-serif; - font-size: 0.8em; - display: flex; - padding: 4px 8px; - align-items: center; - gap: 0.8em; - box-sizing: border-box; + position: absolute; + top: 0; + left: 0; + width: 100vw; + background: var(--comfy-menu-bg); + color: var(--fg-color); + font-family: Arial, Helvetica, sans-serif; + font-size: 0.8em; + display: flex; + padding: 4px 8px; + align-items: center; + gap: 0.8em; + box-sizing: border-box; + z-index: 1000; } .comfyui-menu .mdi::before { - font-size: 18px; + font-size: 18px; } .comfyui-menu .comfyui-button { - background: var(--comfy-input-bg); - color: var(--fg-color); - white-space: nowrap; + background: var(--comfy-input-bg); + color: var(--fg-color); + white-space: nowrap; } -.comfyui-menu .comfyui-button:hover { - background: var(--border-color); +.comfyui-menu .comfyui-button:not(:disabled):hover { + background: var(--border-color); } -.comfyui-menu .comfyui-split-button-popup>.comfyui-button { - border-radius: 0; - background-color: transparent; +.comfyui-menu .comfyui-split-button-popup > .comfyui-button { + border-radius: 0; + background-color: transparent; } -.comfyui-menu .comfyui-split-button-popup>.comfyui-button:hover { - background-color: var(--comfy-input-bg); +.comfyui-menu .comfyui-split-button-popup > .comfyui-button:not(:disabled):hover { + background-color: var(--comfy-input-bg); } .comfyui-menu .comfyui-split-button-popup.left { - border-top-right-radius: 4px; - border-bottom-left-radius: 4px; - border-bottom-right-radius: 4px; + border-top-right-radius: 4px; + border-bottom-left-radius: 4px; + border-bottom-right-radius: 4px; } +.comfyui-menu .comfyui-button.popup-open { + background-color: var(--border-color); +} .comfyui-menu-push { - margin-left: -0.8em; - flex: auto; + margin-left: -0.8em; + flex: auto; } .comfyui-logo { - font-size: 1.2em; - margin: 0; - user-select: none; - cursor: default; + font-size: 1.2em; + margin: 0; + user-select: none; + cursor: default; } @media only screen and (min-width: 780px) { - - .comfyui-menu>.comfyui-menu-mobile-collapse .comfyui-button span, - .comfyui-menu>.comfyui-menu-mobile-collapse.comfyui-button span { - display: none; - } + .comfyui-menu > .comfyui-menu-mobile-collapse .comfyui-button span, + .comfyui-menu > .comfyui-menu-mobile-collapse.comfyui-button span { + display: none; + } + .comfyui-menu > .comfyui-menu-mobile-collapse .comfyui-popup .comfyui-button span { + display: unset; + } } @media only screen and (max-width: 779px) { - .comfyui-menu { - flex-wrap: wrap; - } + .comfyui-menu { + flex-wrap: wrap; + } - .comfyui-menu>*:not(.comfyui-menu-mobile-collapse) { - order: 1; - } + .comfyui-menu > *:not(.comfyui-menu-mobile-collapse) { + order: 1; + } - .comfyui-menu>.comfyui-menu-mobile-collapse { - order: 9999; - width: 100%; - } + .comfyui-menu > .comfyui-menu-mobile-collapse { + order: 9999; + width: 100%; + } - .comfyui-menu>.comfyui-menu-mobile-collapse.comfyui-button-group { - flex-wrap: wrap; - } + .comfyui-menu > .comfyui-menu-mobile-collapse.comfyui-button-group { + flex-wrap: wrap; + } - .comfyui-menu>.comfyui-menu-mobile-collapse .comfyui-button, - .comfyui-menu>.comfyui-menu-mobile-collapse.comfyui-button { - padding: 10px; - } + .comfyui-menu > .comfyui-menu-mobile-collapse .comfyui-button, + .comfyui-menu > .comfyui-menu-mobile-collapse.comfyui-button { + padding: 10px; + } + .comfyui-menu > .comfyui-menu-mobile-collapse .comfyui-button, + .comfyui-menu > .comfyui-menu-mobile-collapse .comfyui-button-wrapper { + width: 100%; + } - .comfyui-menu>.comfyui-menu-mobile-collapse .comfyui-button { - width: 100%; - } + .comfyui-menu > .comfyui-menu-mobile-collapse .comfyui-popup { + position: static; + background-color: var(--comfy-input-bg); + max-width: unset; + max-height: 50vh; + overflow: auto; + } - .comfyui-menu:not(.expanded)>.comfyui-menu-mobile-collapse { - display: none; - } + .comfyui-menu:not(.expanded) > .comfyui-menu-mobile-collapse { + display: none; + } - .comfyui-queue-action { - margin-right: 44px; - } + .comfyui-queue-button { + margin-right: 44px; + } - .comfyui-menu-button { - position: absolute; - top: 4px; - right: 8px; - } + .comfyui-menu-button { + position: absolute; + top: 4px; + right: 8px; + } + + .comfyui-menu > .comfyui-menu-mobile-collapse .comfyui-view-list-popup { + border-radius: 0; + } } -@media only screen and (max-width: 480px) { - .comfyui-workflows-label { - display: none; - } +@media only screen and (max-width: 490px) { + .comfyui-workflows-label { + display: none; + } } -@media only screen and (max-width: 335px) { - .comfyui-queue-action { - margin-right: 0; - width: 100%; - } - .comfyui-queue-action .comfyui-button { - justify-content: center; - } +@media only screen and (max-width: 370px) { + .comfyui-queue-button { + margin-right: 0; + width: 100%; + } + .comfyui-queue-button .comfyui-button { + justify-content: center; + } + .comfyui-interrupt-button { + margin-right: 45px; + } } /* Workflows */ .comfyui-workflows-button { - flex-direction: row-reverse; + flex-direction: row-reverse; } .comfyui-workflows-button.unsaved { - font-style: italic; + font-style: italic; } .comfyui-workflows-button.unsaved .comfyui-workflows-label:after { - content: "*" + content: "*"; } .comfyui-workflows-button-inner { - display: flex; - align-items: center; - gap: 7px; + display: flex; + align-items: center; + gap: 7px; } .comfyui-workflows-button-inner .mdi-graph::before { - transform: rotate(-90deg); + transform: rotate(-90deg); } .comfyui-workflows-popup { - width: 100%; - max-width: 350px; - padding: 10px; - overflow: auto; - background-color: var(--border-color); - border-top-right-radius: 4px; - border-bottom-right-radius: 4px; - border-bottom-left-radius: 4px; + width: 100%; + max-width: 350px; + padding: 10px; + overflow: auto; + background-color: var(--border-color); + border-top-right-radius: 4px; + border-bottom-right-radius: 4px; + border-bottom-left-radius: 4px; } +/* View List */ +.comfyui-view-list-popup { + padding: 10px; + background-color: var(--border-color); + min-width: 170px; + min-height: 100px; + display: flex; + flex-direction: column; + align-items: center; + border-top-left-radius: 4px; + border-bottom-right-radius: 4px; + border-bottom-left-radius: 4px; + box-sizing: border-box; +} +.comfyui-view-list-popup h3 { + margin: 0 0 5px 0; +} +.comfyui-view-list-items { + width: 100%; + background: var(--comfy-menu-bg); + border-radius: 5px; + display: flex; + justify-content: center; + flex: auto; + align-items: center; + flex-direction: column; +} +.comfyui-view-list-items section { + max-height: 400px; + overflow: auto; + width: 100%; + display: grid; + grid-template-columns: auto auto auto; + align-items: center; + justify-content: center; + gap: 5px; + padding: 5px 0; +} +.comfyui-view-list-items section + section { + border-top: 1px solid var(--border-color); + margin-top: 10px; + padding-top: 5px; +} +.comfyui-view-list-items section h5 { + grid-column: 1 / 4; + text-align: center; + margin: 5px; +} +.comfyui-view-list-items span { + text-align: center; + padding: 0 2px; +} +.comfyui-view-list-popup footer { + margin-top: 10px; + display: flex; + gap: 5px; +} +.comfyui-view-list-popup footer .comfyui-button { + border: 1px solid transparent; +} +.comfyui-view-list-popup footer .comfyui-button:not(:disabled):hover { + border: 1px solid var(--comfy-menu-bg); +} /* Queue button */ -.comfyui-queue-action .comfyui-split-primary .comfyui-button { - padding-right: 12px; +.comfyui-queue-button .comfyui-split-primary .comfyui-button { + padding-right: 12px; } .comfyui-queue-count { - margin-left: 5px; - border-radius: 10px; - background-color: rgb(8, 80, 153); - padding: 2px 4px; - font-size: 10px; + margin-left: 5px; + border-radius: 10px; + background-color: rgb(8, 80, 153); + padding: 2px 4px; + font-size: 10px; + min-width: 1em; + display: inline-block; } - -/* -.comfy-app-menu { - position: absolute; - top: 0; - left: 0; - right: 0; - z-index: 99; - background: var(--comfy-menu-bg); - color: var(--fg-color); - font-family: Arial; - padding: 4px 8px; - display: flex; - gap: 0.8em; - align-items: center; - font-size: 0.8em; -} - -.comfy-app-logo { - font-size: 1.2em; - margin: 0; -} - -.comfy-app-menu .pull-right { - margin-left: auto; -} - -.comfy-app-menu button { - background: transparent; - border: none; - color: var(--fg-color); - height: 100%; - cursor: pointer; - padding: 0 10px; - display: flex; - align-items: center; - gap: 6px; - font-size: 1em; -} - -.comfy-app-menu button:hover, -.comfy-split-visible .comfy-split-open { - background: var(--border-color); -} - -.comfy-split-visible .comfy-split-open>.mdi { - pointer-events: none; -} - -.comfy-app-menu button:first-child { - border-top-left-radius: 4px; - border-bottom-left-radius: 4px; -} - -.comfy-app-menu button:last-child { - border-top-right-radius: 4px; - border-bottom-right-radius: 4px; -} - -.comfy-app-menu button:not(:last-child) { - border-right: 1px solid var(--comfy-menu-bg); -} - -.comfy-app-menu button .mdi { - font-size: 1.7em; -} - -.comfy-menu-item { - height: 2.5em; - border-radius: 4px; - display: flex; - align-items: center; - background: var(--comfy-input-bg); -} - -.comfy-split-button { - position: relative; -} - -.comfy-split-button button:hover, -.comfy-split-visible .comfy-split-open { - background: var(--border-color); -} - -.comfy-split-button .comfy-split-primary { - border-top-left-radius: 4px; - border-bottom-left-radius: 4px; - gap: 5px; -} - -.comfy-split-button .comfy-split-primary .mdi { - font-size: 1.4em; -} - -.comfy-split-button .comfy-split-open { - border-top-right-radius: 4px; - border-bottom-right-radius: 4px; - position: relative; - padding: 0 3px; -} - -.comfy-split-button .comfy-split-open:hover .comfy-split-menu, -.comfy-split-visible .comfy-split-menu { - display: block; -} - -.comfy-split-menu { - display: none; - position: absolute; -} - -.comfy-split-button ul { - margin: 0; - padding: 0; - list-style: none; - text-align: left; - white-space: nowrap; - position: absolute; - right: 0; - top: calc(100% - 2px); - background: var(--border-color); - border-radius: 4px; - border-top-right-radius: 0; - overflow: hidden; -} - -.comfy-split-button li { - padding: 5px 10px; - display: flex; - gap: 8px; - align-items: center; -} - -.comfy-split-button li:hover { - background: var(--comfy-menu-bg); -} - -.comfy-menu-item-text-hidden { - display: none; -} - -.comfy-queue-button { - display: contents; -} - -.comfy-queue-count { - border-radius: 10px; - background: #1260cc; - padding: 2px 4px; - font-size: 9px; -} - -.mobile-show { - display: none; -} - -@media only screen and (max-width: 780px) { - .comfy-app-menu { - flex-wrap: wrap; - font-size: 0.9em; - } - - .comfy-app-menu.open { - box-shadow: 0px 0px 15px black; - } - - .comfy-app-menu:not(.open) .comfy-menu-mobile-collapse { - display: none; - } - - .comfy-app-menu>* { - order: 1; - } - - .comfy-app-menu .mobile-hide { - display: none; - } - - .comfy-app-menu .comfy-menu-mobile-collapse { - order: 9999; - width: 100%; - } - - .comfy-menu-mobile-collapse .comfy-menu-item-text-hidden { - display: unset; - } - - .comfy-menu-mobile-collapse.comfy-menu-group { - flex-wrap: wrap; - height: auto; - margin: 0 -10px; - width: calc(100% + 10px); - padding-left: 10px; - } - - .comfy-menu-mobile-collapse .comfy-menu-item { - width: 100% - } - - .comfy-menu-mobile-collapse.comfy-menu-group button { - width: 100%; - padding: 10px; - gap: 10px; - } - - .mobile-pull-right { - margin-left: auto; - } - - .mobile-show { - display: block; - } - - .comfy-menu-item { - background: var(--comfy-input-bg) !important; - } - - .comfy-menu-mobile-collapse .comfy-split-button { - height: auto; - flex-wrap: wrap; - } - - .comfy-menu-mobile-collapse .comfy-split-menu { - position: static; - width: 100%; - border-radius: 0; - } -} - -@media only screen and (max-width: 480px) { - .comfy-app-menu { - padding: 4px 16px; - } - - .comfy-workflow-menu { - width: auto !important; - } - - .comfy-workflow-menu span { - display: none; - } -} */ \ No newline at end of file diff --git a/web/scripts/ui/menu/queue.js b/web/scripts/ui/menu/queue.js deleted file mode 100644 index e69de29bb..000000000 diff --git a/web/scripts/ui/menu/queueButton.js b/web/scripts/ui/menu/queueButton.js index bf0ff9309..2806a0868 100644 --- a/web/scripts/ui/menu/queueButton.js +++ b/web/scripts/ui/menu/queueButton.js @@ -2,12 +2,17 @@ import { ComfyButton } from "../components/button.js"; import { $el } from "../../ui.js"; +import { api } from "../../api.js"; import { ComfySplitButton } from "../components/splitButton.js"; export class ComfyQueueButton { - element = $el("div.comfyui-queue-action"); + element = $el("div.comfyui-queue-button"); + + constructor(app) { + this.queueSizeElement = $el("span.comfyui-queue-count", { + textContent: "?", + }); - constructor() { const btn = new ComfySplitButton( { primary: new ComfyButton({ @@ -15,13 +20,13 @@ export class ComfyQueueButton { $el("span", { textContent: "Queue", }), - $el("span.comfyui-queue-count", { - textContent: "99+", - title: "186 prompts queued" - }), + this.queueSizeElement, ]), icon: "play", classList: "comfyui-button", + action: () => { + app.queuePrompt(0, 1); + }, }), mode: "click", position: "absolute", @@ -33,5 +38,13 @@ export class ComfyQueueButton { ); btn.element.classList.add("primary"); this.element.append(btn.element); + + api.addEventListener("status", ({ detail }) => { + const sz = detail?.exec_info?.queue_remaining; + if (sz != null) { + this.queueSizeElement.textContent = sz > 99 ? "99+" : sz; + this.queueSizeElement.title = `${sz} promps in queue`; + } + }); } } diff --git a/web/scripts/ui/menu/viewHistory.js b/web/scripts/ui/menu/viewHistory.js new file mode 100644 index 000000000..e095151fe --- /dev/null +++ b/web/scripts/ui/menu/viewHistory.js @@ -0,0 +1,27 @@ +// @ts-check + +import { ComfyButton } from "../components/button.js"; +import { ComfyViewList, ComfyViewListButton } from "./viewList.js"; + +export class ComfyViewHistoryButton extends ComfyViewListButton { + constructor(app) { + super(app, { + button: new ComfyButton({ + content: "View History", + icon: "history", + tooltip: "View History", + classList: "comfyui-button comfyui-history-button", + }), + list: ComfyViewHistoryList, + mode: "History", + }); + } +} + +export class ComfyViewHistoryList extends ComfyViewList { + async loadItems() { + const items = await super.loadItems(); + items["History"].reverse(); + return items; + } +} diff --git a/web/scripts/ui/menu/viewList.js b/web/scripts/ui/menu/viewList.js new file mode 100644 index 000000000..6f1d9880a --- /dev/null +++ b/web/scripts/ui/menu/viewList.js @@ -0,0 +1,203 @@ +// @ts-check + +import { ComfyButton } from "../components/button.js"; +import { $el } from "../../ui.js"; +import { api } from "../../api.js"; +import { ComfyPopup } from "../components/popup.js"; + +export class ComfyViewListButton { + get open() { + return this.popup.open; + } + + set open(open) { + this.popup.open = open; + } + + constructor(app, { button, list, mode }) { + this.app = app; + this.button = button; + this.element = $el("div.comfyui-button-wrapper", this.button.element); + this.popup = new ComfyPopup({ + target: this.element, + container: this.element, + horizontal: "right", + }); + this.list = new (list ?? ComfyViewList)(app, mode, this.popup); + this.popup.children = [this.list.element]; + this.popup.addEventListener("open", () => { + this.list.update(); + }); + this.popup.addEventListener("close", () => { + this.list.close(); + }); + this.button.withPopup(this.popup); + + api.addEventListener("status", () => { + if (this.popup.open) { + this.popup.update(); + } + }); + } +} + +export class ComfyViewList { + popup; + + constructor(app, mode, popup) { + this.app = app; + this.mode = mode; + this.popup = popup; + this.type = mode.toLowerCase(); + + this.items = $el(`div.comfyui-${this.type}-items.comfyui-view-list-items`); + this.clear = new ComfyButton({ + icon: "cancel", + content: "Clear", + action: async () => { + this.showSpinner(false); + await api.clearItems(this.type); + await this.update(); + }, + }); + + this.refresh = new ComfyButton({ + icon: "refresh", + content: "Refresh", + action: async () => { + await this.update(false); + }, + }); + + this.element = $el(`div.comfyui-${this.type}-popup.comfyui-view-list-popup`, [ + $el("h3", mode), + this.items, + $el("footer", [this.clear.element, this.refresh.element]), + ]); + + api.addEventListener("status", () => { + if (this.popup.open) { + this.update(); + } + }); + } + + async close() { + this.items.replaceChildren(); + } + + async update(resize = true) { + this.showSpinner(resize); + const res = await this.loadItems(); + let any = false; + + const names = Object.keys(res); + const sections = names + .map((section) => { + const items = res[section]; + if (items?.length) { + any = true; + } else { + return; + } + + const rows = []; + if (names.length > 1) { + rows.push($el("h5", section)); + } + rows.push(...items.flatMap((item) => this.createRow(item, section))); + return $el("section", rows); + }) + .filter(Boolean); + + if (any) { + this.items.replaceChildren(...sections); + } else { + this.items.replaceChildren($el("h5", "None")); + } + + this.popup.update(); + this.clear.enabled = this.refresh.enabled = true; + this.element.style.removeProperty("height"); + } + + showSpinner(resize = true) { + // if (!this.spinner) { + // this.spinner = createSpinner(); + // } + // if (!resize) { + // this.element.style.height = this.element.clientHeight + "px"; + // } + // this.clear.enabled = this.refresh.enabled = false; + // this.items.replaceChildren( + // $el( + // "div", + // { + // style: { + // fontSize: "18px", + // }, + // }, + // this.spinner + // ) + // ); + // this.popup.update(); + } + + async loadItems() { + return await api.getItems(this.type); + } + + getRow = (item, section) => { + return { + text: item.prompt[0] + "", + actions: [ + { + text: "Load", + action: async () => { + try { + await this.app.loadGraphData(item.prompt[3].extra_pnginfo.workflow); + if (item.outputs) { + this.app.nodeOutputs = item.outputs; + } + } catch (error) { + alert("Error loading workflow: " + error.message); + console.error(error); + } + }, + }, + { + text: "Delete", + action: async () => { + try { + await api.deleteItem(this.type, item.prompt[1]); + this.update(); + } catch (error) {} + }, + }, + ], + }; + } + + createRow = (item, section) => { + const row = this.getRow(item, section); + return [ + $el("span", row.text), + ...row.actions.map( + (a) => + new ComfyButton({ + content: a.text, + action: async (e, btn) => { + btn.enabled = false; + try { + await a.action(); + } catch (error) { + throw error; + } finally { + btn.enabled = true; + } + }, + }).element + ), + ]; + }; +} diff --git a/web/scripts/ui/menu/viewQueue.js b/web/scripts/ui/menu/viewQueue.js new file mode 100644 index 000000000..cef7d15b8 --- /dev/null +++ b/web/scripts/ui/menu/viewQueue.js @@ -0,0 +1,55 @@ +// @ts-check + +import { ComfyButton } from "../components/button.js"; +import { ComfyViewList, ComfyViewListButton } from "./viewList.js"; +import { api } from "/scripts/api.js"; + +export class ComfyViewQueueButton extends ComfyViewListButton { + constructor(app) { + super(app, { + button: new ComfyButton({ + content: "View Queue", + icon: "format-list-numbered", + tooltip: "View Queue", + classList: "comfyui-button comfyui-queue-button", + }), + list: ComfyViewQueueList, + mode: "Queue", + }); + } +} + +export class ComfyViewQueueList extends ComfyViewList { + getRow(item, section) { + if (section !== "Running") { + return super.getRow(item, section); + } + return { + text: item.prompt[0] + "", + actions: [ + { + text: "Load", + action: async () => { + try { + await this.app.loadGraphData(item.prompt[3].extra_pnginfo.workflow); + if (item.outputs) { + this.app.nodeOutputs = item.outputs; + } + } catch (error) { + alert("Error loading workflow: " + error.message); + console.error(error); + } + }, + }, + { + text: "Cancel", + action: async () => { + try { + await api.interrupt(); + } catch (error) {} + }, + }, + ], + }; + } +} diff --git a/web/scripts/ui/settings.js b/web/scripts/ui/settings.js index 6cd3a3349..b75acdebd 100644 --- a/web/scripts/ui/settings.js +++ b/web/scripts/ui/settings.js @@ -140,6 +140,8 @@ export class ComfySettingsDialog extends ComfyDialog { onChange, name, render: () => { + if (type === "hidden") return; + const setter = (v) => { if (onChange) { onChange(v, value); @@ -314,7 +316,7 @@ export class ComfySettingsDialog extends ComfyDialog { }, [$el("th"), $el("th", { style: { width: "33%" } })] ), - ...this.settings.sort((a, b) => a.name.localeCompare(b.name)).map((s) => s.render()) + ...this.settings.sort((a, b) => a.name.localeCompare(b.name)).map((s) => s.render()).filter(Boolean) ); this.element.showModal(); } diff --git a/web/style.css b/web/style.css index 222f8f3f5..f32983445 100644 --- a/web/style.css +++ b/web/style.css @@ -103,7 +103,6 @@ body { padding: 10px; border-radius: 0 8px 8px 8px; box-shadow: 3px 3px 8px rgba(0, 0, 0, 0.4); - display: none; } .comfy-menu button,