diff --git a/src_web/comfyui/fast_node_muter.ts b/src_web/comfyui/fast_node_muter.ts index e0a47b6..ce36a72 100644 --- a/src_web/comfyui/fast_node_muter.ts +++ b/src_web/comfyui/fast_node_muter.ts @@ -11,6 +11,7 @@ import { } from "typings/litegraph.js"; import { RgthreeToggleNavWidget } from "./utils_widgets.js"; import { filterByColor, filterByTitle, sortBy, type SortType } from "./utils_fast.js"; +import { SERVICE as FAST_GROUPS_SERVICE } from "./fast_groups_service.js"; declare const LiteGraph: typeof TLiteGraph; declare const LGraphCanvas: typeof TLGraphCanvas; @@ -19,6 +20,7 @@ const PROPERTY_SORT = "sort"; const PROPERTY_SORT_CUSTOM_ALPHA = "customSortAlphabet"; const PROPERTY_MATCH_COLORS = "matchColors"; const PROPERTY_MATCH_TITLE = "matchTitle"; +const PROPERTY_MATCH_TITLE_GROUP = "matchGroupTitle"; const PROPERTY_RESTRICTION = "toggleRestriction"; /** @@ -31,8 +33,11 @@ export class FastNodeMuter extends FastGroupsMuter { override readonly modeOn = LiteGraph.ALWAYS; override readonly modeOff = LiteGraph.NEVER; + static "@matchTitleGroup" = { type: "string" }; + constructor(title = FastNodeMuter.title) { super(title); + this.properties[PROPERTY_MATCH_TITLE_GROUP] = ""; } static override setUp(clazz: new (title?: string) => T) { @@ -40,10 +45,22 @@ export class FastNodeMuter extends FastGroupsMuter { (clazz as any).category = (clazz as any)._category; } + private getNodes(sort: SortType): LGraphNode[] { + const matchGroup = this.properties?.[PROPERTY_MATCH_TITLE_GROUP]; + if (!matchGroup) { + const graph: LGraph = app.graph; + return [...(graph._nodes ?? [])].filter((n) => !n.isVirtualNode); + } + const pattern = new RegExp(matchGroup, "i"); + const allGroups = FAST_GROUPS_SERVICE.getGroups(sort); + const filteredGroups = allGroups.filter((group) => pattern.exec(group.title)); + return Array.from(new Set(filteredGroups.map((group) => group._nodes).flat())); + } + override refreshWidgets() { - const graph: LGraph = app.graph; let sort: SortType = this.properties?.[PROPERTY_SORT] || "position"; - const nodes: LGraphNode[] = [...(graph._nodes ?? [])].filter((n) => !n.isVirtualNode); + const nodes = this.getNodes(sort); + // The service will return pre-sorted groups for alphanumeric and position. If this node has a // custom sort, then we need to sort it manually. const alphaSorted = sortBy(nodes, { diff --git a/web/comfyui/fast_node_muter.js b/web/comfyui/fast_node_muter.js index 3abfcb3..6da3780 100644 --- a/web/comfyui/fast_node_muter.js +++ b/web/comfyui/fast_node_muter.js @@ -3,36 +3,50 @@ import { NodeTypesString } from "./constants.js"; import { FastGroupsMuter } from "./fast_groups_muter.js"; import { RgthreeToggleNavWidget } from "./utils_widgets.js"; import { filterByColor, filterByTitle, sortBy } from "./utils_fast.js"; +import { SERVICE as FAST_GROUPS_SERVICE } from "./fast_groups_service.js"; const PROPERTY_SORT = "sort"; const PROPERTY_SORT_CUSTOM_ALPHA = "customSortAlphabet"; const PROPERTY_MATCH_COLORS = "matchColors"; const PROPERTY_MATCH_TITLE = "matchTitle"; +const PROPERTY_MATCH_TITLE_GROUP = "matchGroupTitle"; const PROPERTY_RESTRICTION = "toggleRestriction"; export class FastNodeMuter extends FastGroupsMuter { constructor(title = FastNodeMuter.title) { super(title); this.modeOn = LiteGraph.ALWAYS; this.modeOff = LiteGraph.NEVER; + this.properties[PROPERTY_MATCH_TITLE_GROUP] = ""; } static setUp(clazz) { LiteGraph.registerNodeType(clazz.type, clazz); clazz.category = clazz._category; } + getNodes(sort) { + var _a, _b; + const matchGroup = (_a = this.properties) === null || _a === void 0 ? void 0 : _a[PROPERTY_MATCH_TITLE_GROUP]; + if (!matchGroup) { + const graph = app.graph; + return [...((_b = graph._nodes) !== null && _b !== void 0 ? _b : [])].filter((n) => !n.isVirtualNode); + } + const pattern = new RegExp(matchGroup, "i"); + const allGroups = FAST_GROUPS_SERVICE.getGroups(sort); + const filteredGroups = allGroups.filter((group) => pattern.exec(group.title)); + return Array.from(new Set(filteredGroups.map((group) => group._nodes).flat())); + } refreshWidgets() { - var _a, _b, _c, _d, _e, _f, _g; - const graph = app.graph; + var _a, _b, _c, _d, _e, _f; let sort = ((_a = this.properties) === null || _a === void 0 ? void 0 : _a[PROPERTY_SORT]) || "position"; - const nodes = [...((_b = graph._nodes) !== null && _b !== void 0 ? _b : [])].filter((n) => !n.isVirtualNode); + const nodes = this.getNodes(sort); const alphaSorted = sortBy(nodes, { - 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, ""), + 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, ""), sort, }); const colorFiltered = filterByColor(alphaSorted, { - matchColors: (_e = this.properties) === null || _e === void 0 ? void 0 : _e[PROPERTY_MATCH_COLORS], + matchColors: (_d = this.properties) === null || _d === void 0 ? void 0 : _d[PROPERTY_MATCH_COLORS], nodeColorOption: "color", }); const titleFiltered = filterByTitle(colorFiltered, { - matchTitle: (_g = (_f = this.properties) === null || _f === void 0 ? void 0 : _f[PROPERTY_MATCH_TITLE]) === null || _g === void 0 ? void 0 : _g.trim(), + matchTitle: (_f = (_e = this.properties) === null || _e === void 0 ? void 0 : _e[PROPERTY_MATCH_TITLE]) === null || _f === void 0 ? void 0 : _f.trim(), }); let index = 0; for (const node of titleFiltered) { @@ -90,6 +104,7 @@ export class FastNodeMuter extends FastGroupsMuter { } FastNodeMuter.type = NodeTypesString.FAST_NODE_MUTER; FastNodeMuter.title = NodeTypesString.FAST_NODE_MUTER; +FastNodeMuter["@matchTitleGroup"] = { type: "string" }; app.registerExtension({ name: "rgthree.FastNodeMuter", registerCustomNodes() {