Skip to content

Commit baf11d1

Browse files
committed
More subgraph cleanup.
1 parent 5b45e10 commit baf11d1

22 files changed

+198
-128
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "rgthree-comfy"
33
description = "Making ComfyUI more comfortable."
4-
version = "1.0.2508161550"
4+
version = "1.0.2508162219"
55
license = { file = "LICENSE" }
66
dependencies = []
77

src_web/comfyui/bookmark.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type {
1010
import {app} from "scripts/app.js";
1111
import {RgthreeBaseVirtualNode} from "./base_node.js";
1212
import {SERVICE as KEY_EVENT_SERVICE} from "./services/key_events_services.js";
13+
import {SERVICE as BOOKMARKS_SERVICE} from "./services/bookmarks_services.js";
1314
import {NodeTypesString} from "./constants.js";
1415
import {getClosestOrSelf, query} from "rgthree/common/utils_dom.js";
1516
import {wait} from "rgthree/common/shared_utils.js";
@@ -52,7 +53,7 @@ export class Bookmark extends RgthreeBaseVirtualNode {
5253

5354
constructor(title = Bookmark.title) {
5455
super(title);
55-
const nextShortcutChar = getNextShortcut();
56+
const nextShortcutChar = BOOKMARKS_SERVICE.getNextShortcut();
5657
this.addWidget(
5758
"text",
5859
"shortcut_key",
@@ -152,20 +153,3 @@ app.registerExtension({
152153
Bookmark.setUp();
153154
},
154155
});
155-
156-
function isBookmark(node: LGraphNode): node is Bookmark {
157-
return node.type === NodeTypesString.BOOKMARK;
158-
}
159-
160-
function getExistingShortcuts() {
161-
const graph: LGraph = app.graph;
162-
const bookmarkNodes = graph._nodes.filter(isBookmark);
163-
const usedShortcuts = new Set(bookmarkNodes.map((n) => n.shortcutKey));
164-
return usedShortcuts;
165-
}
166-
167-
const SHORTCUT_DEFAULTS = "1234567890abcdefghijklmnopqrstuvwxyz".split("");
168-
function getNextShortcut() {
169-
const existingShortcuts = getExistingShortcuts();
170-
return SHORTCUT_DEFAULTS.find((char) => !existingShortcuts.has(char)) ?? "1";
171-
}

src_web/comfyui/fast_groups_muter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {NodeTypesString} from "./constants.js";
1515
import {SERVICE as FAST_GROUPS_SERVICE} from "./services/fast_groups_service.js";
1616
import {drawNodeWidget, fitString} from "./utils_canvas.js";
1717
import {RgthreeBaseWidget} from "./utils_widgets.js";
18-
import { changeModeOfNodes } from "./utils.js";
18+
import { changeModeOfNodes, getGroupNodes } from "./utils.js";
1919

2020
const PROPERTY_SORT = "sort";
2121
const PROPERTY_SORT_CUSTOM_ALPHA = "customSortAlphabet";
@@ -395,7 +395,7 @@ class FastGroupsToggleRowWidget extends RgthreeBaseWidget<{toggled: boolean}> {
395395

396396
doModeChange(force?: boolean, skipOtherNodeCheck?: boolean) {
397397
this.group.recomputeInsideNodes();
398-
const hasAnyActiveNodes = this.group._nodes.some((n) => n.mode === LiteGraph.ALWAYS);
398+
const hasAnyActiveNodes = getGroupNodes(this.group).some((n) => n.mode === LiteGraph.ALWAYS);
399399
let newValue = force != null ? force : !hasAnyActiveNodes;
400400
if (skipOtherNodeCheck !== true) {
401401
// TODO: This work should probably live in BaseFastGroupsModeChanger instead of the widgets.
@@ -409,7 +409,7 @@ class FastGroupsToggleRowWidget extends RgthreeBaseWidget<{toggled: boolean}> {
409409
newValue = this.node.widgets.every((w) => !w.value || w === this);
410410
}
411411
}
412-
changeModeOfNodes(this.group._nodes, (newValue ? this.node.modeOn : this.node.modeOff));
412+
changeModeOfNodes(getGroupNodes(this.group), (newValue ? this.node.modeOn : this.node.modeOff));
413413
this.group.rgthree_hasAnyActiveNode = newValue;
414414
this.toggled = newValue;
415415
this.group.graph?.setDirtyCanvas(true, false);

src_web/comfyui/menu_queue_node.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {ComfyNodeDef} from "typings/comfy.js";
77

88
import {app} from "scripts/app.js";
99
import {rgthree} from "./rgthree.js";
10-
import {getOutputNodes} from "./utils.js";
10+
import {getGroupNodes, getOutputNodes} from "./utils.js";
1111
import {SERVICE as CONFIG_SERVICE} from "./services/config_service.js";
1212

1313
function showQueueNodesMenuIfOutputNodesAreSelected(
@@ -40,12 +40,12 @@ function showQueueGroupNodesMenuIfGroupIsSelected(
4040
}
4141
const group =
4242
rgthree.lastCanvasMouseEvent &&
43-
app.graph.getGroupOnPos(
43+
(app.canvas.getCurrentGraph() || app.graph).getGroupOnPos(
4444
rgthree.lastCanvasMouseEvent.canvasX,
4545
rgthree.lastCanvasMouseEvent.canvasY,
4646
);
4747

48-
const outputNodes: LGraphNode[] | null = (group && getOutputNodes(group._nodes)) || null;
48+
const outputNodes: LGraphNode[] | null = (group && getOutputNodes(getGroupNodes(group))) || null;
4949
const menuItem = {
5050
content: `Queue Group Output Nodes (rgthree) &nbsp;`,
5151
className: "rgthree-contextmenu-item",

src_web/comfyui/node_collector.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,20 @@ async function updateCombinerToCollector(node: TLGraphNode) {
107107
// We now collect the links data, inputs and outputs, of the old node since these will be
108108
// lost when we remove it.
109109
const links: any[] = [];
110+
const graph = (node.graph || app.graph);
110111
for (const [index, output] of node.outputs.entries()) {
111112
for (const linkId of output.links || []) {
112-
const link: LLink = (app.graph as LGraph).links[linkId]!;
113+
const link: LLink = graph.links[linkId]!;
113114
if (!link) continue;
114-
const targetNode = app.graph.getNodeById(link.target_id);
115+
const targetNode = graph.getNodeById(link.target_id);
115116
links.push({node: newNode, slot: index, targetNode, targetSlot: link.target_slot});
116117
}
117118
}
118119
for (const [index, input] of node.inputs.entries()) {
119120
const linkId = input.link;
120121
if (linkId) {
121-
const link: LLink = (app.graph as LGraph).links[linkId]!;
122-
const originNode = app.graph.getNodeById(link.origin_id);
122+
const link: LLink = graph.links[linkId]!;
123+
const originNode = graph.getNodeById(link.origin_id);
123124
links.push({
124125
node: originNode,
125126
slot: link.origin_slot,
@@ -129,14 +130,14 @@ async function updateCombinerToCollector(node: TLGraphNode) {
129130
}
130131
}
131132
// Add the new node, remove the old node.
132-
app.graph.add(newNode);
133+
graph.add(newNode);
133134
await wait();
134135
// Now go through and connect the other nodes up as they were.
135136
for (const link of links) {
136137
link.node.connect(link.slot, link.targetNode, link.targetSlot);
137138
}
138139
await wait();
139-
app.graph.remove(node);
140+
graph.remove(node);
140141
}
141142
}
142143

src_web/comfyui/node_mode_repeater.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
changeModeOfNodes,
1717
getConnectedInputNodesAndFilterPassThroughs,
1818
getConnectedOutputNodesAndFilterPassThroughs,
19+
getGroupNodes,
1920
} from "./utils.js";
2021

2122
class NodeModeRepeater extends BaseCollectorNode {
@@ -161,12 +162,13 @@ class NodeModeRepeater extends BaseCollectorNode {
161162
changeModeOfNodes(node, to);
162163
}
163164
}
164-
} else if (app.graph._groups?.length) {
165+
} else if (this.graph?._groups?.length) {
165166
// No linked nodes.. check if we're in a group.
166-
for (const group of app.graph._groups as LGraphGroup[]) {
167+
for (const group of this.graph._groups as LGraphGroup[]) {
167168
group.recomputeInsideNodes();
168-
if (group._nodes?.includes(this)) {
169-
for (const node of group._nodes) {
169+
const groupNodes = getGroupNodes(group);
170+
if (groupNodes?.includes(this)) {
171+
for (const node of groupNodes) {
170172
if (node !== this) {
171173
// Use "to" as there may be other getters in the way to access this.mode directly.
172174
changeModeOfNodes(node, to);

src_web/comfyui/power_conductor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {RgthreeBetterButtonWidget} from "./utils_widgets.js";
88
import {NodeTypesString} from "./constants.js";
99
import {ComfyWidgets} from "scripts/widgets.js";
1010
import {SERVICE as CONFIG_SERVICE} from "./services/config_service.js";
11-
import { changeModeOfNodes } from "./utils.js";
11+
import { changeModeOfNodes, getNodeById } from "./utils.js";
1212

1313
const BUILT_INS = {
1414
node: {
@@ -63,7 +63,7 @@ class ComfyNodeWrapper {
6363
}
6464

6565
private getNode() {
66-
return app.graph.getNodeById(this.#id)!;
66+
return getNodeById(this.#id)!;
6767
}
6868

6969
@Exposed get id() {

src_web/comfyui/power_prompt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ app.registerExtension({
3333
node.outputs[3]!.links = node.outputs[3]!.links || [];
3434
for (const link of node.outputs[0]!.links) {
3535
node.outputs[3]!.links.push(link);
36-
app.graph.links[link]!.origin_slot = 3;
36+
(node.graph || app.graph).links[link]!.origin_slot = 3;
3737
}
3838
node.outputs[0]!.links = null;
3939
}

src_web/comfyui/rgthree.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import type {
1111
ISerialisedNode,
1212
} from "@comfyorg/frontend";
1313
import type {ComfyApiFormat, ComfyApiPrompt} from "typings/comfy.js";
14-
import type {Bookmark} from "./bookmark.js";
1514
import type {ComfyApp} from "@comfyorg/frontend";
1615

1716
import {app} from "scripts/app.js";
@@ -21,8 +20,8 @@ import {SERVICE as BOOKMARKS_SERVICE} from "./services/bookmarks_services.js";
2120
import {SERVICE as KEY_EVENT_SERVICE} from "./services/key_events_services.js";
2221
import {WorkflowLinkFixer} from "rgthree/common/link_fixer.js";
2322
import {injectCss, wait} from "rgthree/common/shared_utils.js";
24-
import {replaceNode, traverseNodesDepthFirst, waitForCanvas, waitForGraph} from "./utils.js";
25-
import {NodeTypesString, addRgthree, getNodeTypeStrings, stripRgthree} from "./constants.js";
23+
import {replaceNode, waitForCanvas, waitForGraph} from "./utils.js";
24+
import {NodeTypesString, addRgthree, getNodeTypeStrings} from "./constants.js";
2625
import {RgthreeProgressBar} from "rgthree/common/progress_bar.js";
2726
import {RgthreeConfigDialog} from "./config.js";
2827
import {

src_web/comfyui/services/bookmarks_services.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,31 @@ import type {Bookmark} from "../bookmark.js";
22

33
import {app} from "scripts/app.js";
44
import {NodeTypesString} from "../constants.js";
5-
import {traverseNodesDepthFirst} from "../utils.js";
5+
import {reduceNodesDepthFirst} from "../utils.js";
6+
7+
const SHORTCUT_DEFAULTS = "1234567890abcdefghijklmnopqrstuvwxyz".split("");
68

79
class BookmarksService {
810
/**
911
* Gets a list of the current bookmarks within the current workflow.
1012
*/
1113
getCurrentBookmarks(): Bookmark[] {
12-
const bookmarks: Bookmark[] = [];
13-
traverseNodesDepthFirst(app.graph.nodes, (n) => {
14+
return reduceNodesDepthFirst<Bookmark[]>(app.graph.nodes, (n, acc) => {
1415
if (n.type === NodeTypesString.BOOKMARK) {
15-
bookmarks.push(n as Bookmark);
16+
acc.push(n as Bookmark);
1617
}
17-
});
18-
return bookmarks.sort((a, b) => a.title.localeCompare(b.title));
18+
}, []).sort((a, b) => a.title.localeCompare(b.title));
19+
}
20+
21+
getExistingShortcuts() {
22+
const bookmarkNodes = this.getCurrentBookmarks();
23+
const usedShortcuts = new Set(bookmarkNodes.map((n) => n.shortcutKey));
24+
return usedShortcuts;
25+
}
26+
27+
getNextShortcut() {
28+
const existingShortcuts = this.getExistingShortcuts();
29+
return SHORTCUT_DEFAULTS.find((char) => !existingShortcuts.has(char)) ?? "1";
1930
}
2031
}
2132

0 commit comments

Comments
 (0)