Skip to content

Commit fdad225

Browse files
committed
Group filtering (initial)
1 parent c9ad0f3 commit fdad225

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

src_web/comfyui/fast_node_muter.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from "typings/litegraph.js";
1212
import { RgthreeToggleNavWidget } from "./utils_widgets.js";
1313
import { filterByColor, filterByTitle, sortBy, type SortType } from "./utils_fast.js";
14+
import { SERVICE as FAST_GROUPS_SERVICE } from "./fast_groups_service.js";
1415

1516
declare const LiteGraph: typeof TLiteGraph;
1617
declare const LGraphCanvas: typeof TLGraphCanvas;
@@ -19,6 +20,7 @@ const PROPERTY_SORT = "sort";
1920
const PROPERTY_SORT_CUSTOM_ALPHA = "customSortAlphabet";
2021
const PROPERTY_MATCH_COLORS = "matchColors";
2122
const PROPERTY_MATCH_TITLE = "matchTitle";
23+
const PROPERTY_MATCH_TITLE_GROUP = "matchGroupTitle";
2224
const PROPERTY_RESTRICTION = "toggleRestriction";
2325

2426
/**
@@ -31,19 +33,34 @@ export class FastNodeMuter extends FastGroupsMuter {
3133
override readonly modeOn = LiteGraph.ALWAYS;
3234
override readonly modeOff = LiteGraph.NEVER;
3335

36+
static "@matchTitleGroup" = { type: "string" };
37+
3438
constructor(title = FastNodeMuter.title) {
3539
super(title);
40+
this.properties[PROPERTY_MATCH_TITLE_GROUP] = "";
3641
}
3742

3843
static override setUp<T extends RgthreeBaseNode>(clazz: new (title?: string) => T) {
3944
LiteGraph.registerNodeType((clazz as any).type, clazz);
4045
(clazz as any).category = (clazz as any)._category;
4146
}
4247

48+
private getNodes(sort: SortType): LGraphNode[] {
49+
const matchGroup = this.properties?.[PROPERTY_MATCH_TITLE_GROUP];
50+
if (!matchGroup) {
51+
const graph: LGraph = app.graph;
52+
return [...(graph._nodes ?? [])].filter((n) => !n.isVirtualNode);
53+
}
54+
const pattern = new RegExp(matchGroup, "i");
55+
const allGroups = FAST_GROUPS_SERVICE.getGroups(sort);
56+
const filteredGroups = allGroups.filter((group) => pattern.exec(group.title));
57+
return Array.from(new Set(filteredGroups.map((group) => group._nodes).flat()));
58+
}
59+
4360
override refreshWidgets() {
44-
const graph: LGraph = app.graph;
4561
let sort: SortType = this.properties?.[PROPERTY_SORT] || "position";
46-
const nodes: LGraphNode[] = [...(graph._nodes ?? [])].filter((n) => !n.isVirtualNode);
62+
const nodes = this.getNodes(sort);
63+
4764
// The service will return pre-sorted groups for alphanumeric and position. If this node has a
4865
// custom sort, then we need to sort it manually.
4966
const alphaSorted = sortBy(nodes, {

web/comfyui/fast_node_muter.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,50 @@ import { NodeTypesString } from "./constants.js";
33
import { FastGroupsMuter } from "./fast_groups_muter.js";
44
import { RgthreeToggleNavWidget } from "./utils_widgets.js";
55
import { filterByColor, filterByTitle, sortBy } from "./utils_fast.js";
6+
import { SERVICE as FAST_GROUPS_SERVICE } from "./fast_groups_service.js";
67
const PROPERTY_SORT = "sort";
78
const PROPERTY_SORT_CUSTOM_ALPHA = "customSortAlphabet";
89
const PROPERTY_MATCH_COLORS = "matchColors";
910
const PROPERTY_MATCH_TITLE = "matchTitle";
11+
const PROPERTY_MATCH_TITLE_GROUP = "matchGroupTitle";
1012
const PROPERTY_RESTRICTION = "toggleRestriction";
1113
export class FastNodeMuter extends FastGroupsMuter {
1214
constructor(title = FastNodeMuter.title) {
1315
super(title);
1416
this.modeOn = LiteGraph.ALWAYS;
1517
this.modeOff = LiteGraph.NEVER;
18+
this.properties[PROPERTY_MATCH_TITLE_GROUP] = "";
1619
}
1720
static setUp(clazz) {
1821
LiteGraph.registerNodeType(clazz.type, clazz);
1922
clazz.category = clazz._category;
2023
}
24+
getNodes(sort) {
25+
var _a, _b;
26+
const matchGroup = (_a = this.properties) === null || _a === void 0 ? void 0 : _a[PROPERTY_MATCH_TITLE_GROUP];
27+
if (!matchGroup) {
28+
const graph = app.graph;
29+
return [...((_b = graph._nodes) !== null && _b !== void 0 ? _b : [])].filter((n) => !n.isVirtualNode);
30+
}
31+
const pattern = new RegExp(matchGroup, "i");
32+
const allGroups = FAST_GROUPS_SERVICE.getGroups(sort);
33+
const filteredGroups = allGroups.filter((group) => pattern.exec(group.title));
34+
return Array.from(new Set(filteredGroups.map((group) => group._nodes).flat()));
35+
}
2136
refreshWidgets() {
22-
var _a, _b, _c, _d, _e, _f, _g;
23-
const graph = app.graph;
37+
var _a, _b, _c, _d, _e, _f;
2438
let sort = ((_a = this.properties) === null || _a === void 0 ? void 0 : _a[PROPERTY_SORT]) || "position";
25-
const nodes = [...((_b = graph._nodes) !== null && _b !== void 0 ? _b : [])].filter((n) => !n.isVirtualNode);
39+
const nodes = this.getNodes(sort);
2640
const alphaSorted = sortBy(nodes, {
27-
customAlphabet: (_d = (_c = this.properties) === null || _c === void 0 ? void 0 : _c[PROPERTY_SORT_CUSTOM_ALPHA]) === null || _d === void 0 ? void 0 : _d.replace(/\n/g, ""),
41+
customAlphabet: (_c = (_b = this.properties) === null || _b === void 0 ? void 0 : _b[PROPERTY_SORT_CUSTOM_ALPHA]) === null || _c === void 0 ? void 0 : _c.replace(/\n/g, ""),
2842
sort,
2943
});
3044
const colorFiltered = filterByColor(alphaSorted, {
31-
matchColors: (_e = this.properties) === null || _e === void 0 ? void 0 : _e[PROPERTY_MATCH_COLORS],
45+
matchColors: (_d = this.properties) === null || _d === void 0 ? void 0 : _d[PROPERTY_MATCH_COLORS],
3246
nodeColorOption: "color",
3347
});
3448
const titleFiltered = filterByTitle(colorFiltered, {
35-
matchTitle: (_g = (_f = this.properties) === null || _f === void 0 ? void 0 : _f[PROPERTY_MATCH_TITLE]) === null || _g === void 0 ? void 0 : _g.trim(),
49+
matchTitle: (_f = (_e = this.properties) === null || _e === void 0 ? void 0 : _e[PROPERTY_MATCH_TITLE]) === null || _f === void 0 ? void 0 : _f.trim(),
3650
});
3751
let index = 0;
3852
for (const node of titleFiltered) {
@@ -90,6 +104,7 @@ export class FastNodeMuter extends FastGroupsMuter {
90104
}
91105
FastNodeMuter.type = NodeTypesString.FAST_NODE_MUTER;
92106
FastNodeMuter.title = NodeTypesString.FAST_NODE_MUTER;
107+
FastNodeMuter["@matchTitleGroup"] = { type: "string" };
93108
app.registerExtension({
94109
name: "rgthree.FastNodeMuter",
95110
registerCustomNodes() {

0 commit comments

Comments
 (0)