diff --git a/pyproject.toml b/pyproject.toml index 8890044..51cc214 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "rgthree-comfy" description = "Making ComfyUI more comfortable." -version = "1.0.2508161414" +version = "1.0.2508161550" license = { file = "LICENSE" } dependencies = [] diff --git a/src_web/comfyui/bookmark.ts b/src_web/comfyui/bookmark.ts index 5a707e2..9dcbac8 100644 --- a/src_web/comfyui/bookmark.ts +++ b/src_web/comfyui/bookmark.ts @@ -1,10 +1,18 @@ -import type {LGraph, LGraphCanvas, LGraphNode, Point, CanvasMouseEvent} from "@comfyorg/frontend"; +import type { + LGraph, + LGraphCanvas, + LGraphNode, + Point, + CanvasMouseEvent, + Subgraph, +} from "@comfyorg/frontend"; import {app} from "scripts/app.js"; import {RgthreeBaseVirtualNode} from "./base_node.js"; import {SERVICE as KEY_EVENT_SERVICE} from "./services/key_events_services.js"; import {NodeTypesString} from "./constants.js"; import {getClosestOrSelf, query} from "rgthree/common/utils_dom.js"; +import {wait} from "rgthree/common/shared_utils.js"; /** * A bookmark node. Can be placed anywhere in the workflow, and given a shortcut key that will @@ -119,8 +127,12 @@ export class Bookmark extends RgthreeBaseVirtualNode { return false; } - canvasToBookmark() { + async canvasToBookmark() { const canvas = app.canvas as LGraphCanvas; + if (this.graph !== app.canvas.getCurrentGraph()) { + canvas.openSubgraph(this.graph as Subgraph); + await wait(16); + } // ComfyUI seemed to break us again, but couldn't repro. No reason to not check, I guess. // https://github.com/rgthree/rgthree-comfy/issues/71 if (canvas?.ds?.offset) { diff --git a/src_web/comfyui/rgthree.ts b/src_web/comfyui/rgthree.ts index e45764a..14591ed 100644 --- a/src_web/comfyui/rgthree.ts +++ b/src_web/comfyui/rgthree.ts @@ -17,10 +17,11 @@ import type {ComfyApp} from "@comfyorg/frontend"; import {app} from "scripts/app.js"; import {api} from "scripts/api.js"; import {SERVICE as CONFIG_SERVICE} from "./services/config_service.js"; +import {SERVICE as BOOKMARKS_SERVICE} from "./services/bookmarks_services.js"; import {SERVICE as KEY_EVENT_SERVICE} from "./services/key_events_services.js"; import {WorkflowLinkFixer} from "rgthree/common/link_fixer.js"; import {injectCss, wait} from "rgthree/common/shared_utils.js"; -import {replaceNode, waitForCanvas, waitForGraph} from "./utils.js"; +import {replaceNode, traverseNodesDepthFirst, waitForCanvas, waitForGraph} from "./utils.js"; import {NodeTypesString, addRgthree, getNodeTypeStrings, stripRgthree} from "./constants.js"; import {RgthreeProgressBar} from "rgthree/common/progress_bar.js"; import {RgthreeConfigDialog} from "./config.js"; @@ -998,22 +999,16 @@ class Rgthree extends EventTarget { } function getBookmarks(): IContextMenuValue[] { - const graph: TLGraph = app.graph; + const bookmarks = BOOKMARKS_SERVICE.getCurrentBookmarks(); + const bookmarkItems = bookmarks.map((n) => ({ + content: `[${n.shortcutKey}] ${n.title}`, + className: "rgthree-contextmenu-item", + callback: () => { + n.canvasToBookmark(); + }, + })); - // Sorts by Title. - // I could see an option to sort by either Shortcut, Title, or Position. - const bookmarks = graph._nodes - .filter((n): n is Bookmark => n.type === NodeTypesString.BOOKMARK) - .sort((a, b) => a.title.localeCompare(b.title)) - .map((n) => ({ - content: `[${n.shortcutKey}] ${n.title}`, - className: "rgthree-contextmenu-item", - callback: () => { - n.canvasToBookmark(); - }, - })); - - return !bookmarks.length + return !bookmarkItems.length ? [] : [ { @@ -1021,7 +1016,7 @@ function getBookmarks(): IContextMenuValue[] { disabled: true, className: "rgthree-contextmenu-item rgthree-contextmenu-label", }, - ...bookmarks, + ...bookmarkItems, ]; } diff --git a/src_web/comfyui/services/bookmarks_services.ts b/src_web/comfyui/services/bookmarks_services.ts index 8f55c5c..40a16ef 100644 --- a/src_web/comfyui/services/bookmarks_services.ts +++ b/src_web/comfyui/services/bookmarks_services.ts @@ -2,15 +2,20 @@ import type {Bookmark} from "../bookmark.js"; import {app} from "scripts/app.js"; import {NodeTypesString} from "../constants.js"; +import {traverseNodesDepthFirst} from "../utils.js"; class BookmarksService { /** * Gets a list of the current bookmarks within the current workflow. */ - getCurrentBookmarks() { - return app.graph._nodes - .filter((n): n is Bookmark => n.type === NodeTypesString.BOOKMARK) - .sort((a, b) => a.title.localeCompare(b.title)); + getCurrentBookmarks(): Bookmark[] { + const bookmarks: Bookmark[] = []; + traverseNodesDepthFirst(app.graph.nodes, (n) => { + if (n.type === NodeTypesString.BOOKMARK) { + bookmarks.push(n as Bookmark); + } + }); + return bookmarks.sort((a, b) => a.title.localeCompare(b.title)); } } diff --git a/web/comfyui/bookmark.js b/web/comfyui/bookmark.js index cb9631b..59c09ce 100644 --- a/web/comfyui/bookmark.js +++ b/web/comfyui/bookmark.js @@ -3,6 +3,7 @@ import { RgthreeBaseVirtualNode } from "./base_node.js"; import { SERVICE as KEY_EVENT_SERVICE } from "./services/key_events_services.js"; import { NodeTypesString } from "./constants.js"; import { getClosestOrSelf, query } from "../../rgthree/common/utils_dom.js"; +import { wait } from "../../rgthree/common/shared_utils.js"; export class Bookmark extends RgthreeBaseVirtualNode { get _collapsed_width() { return this.___collapsed_width; @@ -72,9 +73,13 @@ export class Bookmark extends RgthreeBaseVirtualNode { } return false; } - canvasToBookmark() { + async canvasToBookmark() { var _a, _b; const canvas = app.canvas; + if (this.graph !== app.canvas.getCurrentGraph()) { + canvas.openSubgraph(this.graph); + await wait(16); + } if ((_a = canvas === null || canvas === void 0 ? void 0 : canvas.ds) === null || _a === void 0 ? void 0 : _a.offset) { canvas.ds.offset[0] = -this.pos[0] + 16; canvas.ds.offset[1] = -this.pos[1] + 40; diff --git a/web/comfyui/rgthree.js b/web/comfyui/rgthree.js index f07df18..5009b56 100644 --- a/web/comfyui/rgthree.js +++ b/web/comfyui/rgthree.js @@ -1,6 +1,7 @@ import { app } from "../../scripts/app.js"; import { api } from "../../scripts/api.js"; import { SERVICE as CONFIG_SERVICE } from "./services/config_service.js"; +import { SERVICE as BOOKMARKS_SERVICE } from "./services/bookmarks_services.js"; import { SERVICE as KEY_EVENT_SERVICE } from "./services/key_events_services.js"; import { WorkflowLinkFixer } from "../../rgthree/common/link_fixer.js"; import { injectCss, wait } from "../../rgthree/common/shared_utils.js"; @@ -700,18 +701,15 @@ class Rgthree extends EventTarget { } } function getBookmarks() { - const graph = app.graph; - const bookmarks = graph._nodes - .filter((n) => n.type === NodeTypesString.BOOKMARK) - .sort((a, b) => a.title.localeCompare(b.title)) - .map((n) => ({ + const bookmarks = BOOKMARKS_SERVICE.getCurrentBookmarks(); + const bookmarkItems = bookmarks.map((n) => ({ content: `[${n.shortcutKey}] ${n.title}`, className: "rgthree-contextmenu-item", callback: () => { n.canvasToBookmark(); }, })); - return !bookmarks.length + return !bookmarkItems.length ? [] : [ { @@ -719,7 +717,7 @@ function getBookmarks() { disabled: true, className: "rgthree-contextmenu-item rgthree-contextmenu-label", }, - ...bookmarks, + ...bookmarkItems, ]; } export const rgthree = new Rgthree(); diff --git a/web/comfyui/services/bookmarks_services.js b/web/comfyui/services/bookmarks_services.js index 59ac6e2..b10e5db 100644 --- a/web/comfyui/services/bookmarks_services.js +++ b/web/comfyui/services/bookmarks_services.js @@ -1,10 +1,15 @@ import { app } from "../../../scripts/app.js"; import { NodeTypesString } from "../constants.js"; +import { traverseNodesDepthFirst } from "../utils.js"; class BookmarksService { getCurrentBookmarks() { - return app.graph._nodes - .filter((n) => n.type === NodeTypesString.BOOKMARK) - .sort((a, b) => a.title.localeCompare(b.title)); + const bookmarks = []; + traverseNodesDepthFirst(app.graph.nodes, (n) => { + if (n.type === NodeTypesString.BOOKMARK) { + bookmarks.push(n); + } + }); + return bookmarks.sort((a, b) => a.title.localeCompare(b.title)); } } export const SERVICE = new BookmarksService();