From 30907f99f12034842b88b779f8c5f13fdc230cba Mon Sep 17 00:00:00 2001 From: Rizumu Ayaka Date: Sun, 18 Jan 2026 11:30:00 +0700 Subject: [PATCH] chore: move renameWidget function to widgetUtil.ts (#8042) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit related: https://github.com/Comfy-Org/ComfyUI_frontend/pull/7812#discussion_r2685121387 ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-8042-chore-move-renameWidget-function-to-widgetUtil-ts-2e86d73d3650813fa502d38b1ca53ab0) by [Unito](https://www.unito.io) --- .../rightSidePanel/parameters/WidgetItem.vue | 2 +- src/components/rightSidePanel/shared.ts | 66 ------------------ src/utils/widgetUtil.ts | 68 +++++++++++++++++++ 3 files changed, 69 insertions(+), 67 deletions(-) create mode 100644 src/utils/widgetUtil.ts diff --git a/src/components/rightSidePanel/parameters/WidgetItem.vue b/src/components/rightSidePanel/parameters/WidgetItem.vue index debfb02e7..85069f890 100644 --- a/src/components/rightSidePanel/parameters/WidgetItem.vue +++ b/src/components/rightSidePanel/parameters/WidgetItem.vue @@ -16,8 +16,8 @@ import { import { useFavoritedWidgetsStore } from '@/stores/workspace/favoritedWidgetsStore' import { getNodeByExecutionId } from '@/utils/graphTraversalUtil' import { cn } from '@/utils/tailwindUtil' +import { renameWidget } from '@/utils/widgetUtil' -import { renameWidget } from '../shared' import WidgetActions from './WidgetActions.vue' const { diff --git a/src/components/rightSidePanel/shared.ts b/src/components/rightSidePanel/shared.ts index 01432d9f2..8c802eed9 100644 --- a/src/components/rightSidePanel/shared.ts +++ b/src/components/rightSidePanel/shared.ts @@ -1,11 +1,9 @@ import type { InjectionKey, MaybeRefOrGetter } from 'vue' import { computed, toValue } from 'vue' -import { isProxyWidget } from '@/core/graph/subgraph/proxyWidget' import type { Positionable } from '@/lib/litegraph/src/interfaces' import type { LGraphGroup } from '@/lib/litegraph/src/LGraphGroup' import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' -import type { SubgraphNode } from '@/lib/litegraph/src/subgraph/SubgraphNode' import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets' import { isLGraphGroup, isLGraphNode } from '@/utils/litegraphUtil' @@ -205,67 +203,3 @@ function repeatItems(items: T[]): T[] { } return result } - -/** - * Renames a widget and its corresponding input. - * Handles both regular widgets and proxy widgets in subgraphs. - * - * @param widget The widget to rename - * @param node The node containing the widget - * @param newLabel The new label for the widget (empty string or undefined to clear) - * @param parents Optional array of parent SubgraphNodes (for proxy widgets) - * @returns true if the rename was successful, false otherwise - */ -export function renameWidget( - widget: IBaseWidget, - node: LGraphNode, - newLabel: string, - parents?: SubgraphNode[] -): boolean { - // For proxy widgets in subgraphs, we need to rename the original interior widget - if (isProxyWidget(widget) && parents?.length) { - const subgraph = parents[0].subgraph - if (!subgraph) { - console.error('Could not find subgraph for proxy widget') - return false - } - const interiorNode = subgraph.getNodeById(parseInt(widget._overlay.nodeId)) - - if (!interiorNode) { - console.error('Could not find interior node for proxy widget') - return false - } - - const originalWidget = interiorNode.widgets?.find( - (w) => w.name === widget._overlay.widgetName - ) - - if (!originalWidget) { - console.error('Could not find original widget for proxy widget') - return false - } - - // Rename the original widget - originalWidget.label = newLabel || undefined - - // Also rename the corresponding input on the interior node - const interiorInput = interiorNode.inputs?.find( - (inp) => inp.widget?.name === widget._overlay.widgetName - ) - if (interiorInput) { - interiorInput.label = newLabel || undefined - } - } - - // Always rename the widget on the current node (either regular widget or proxy widget) - const input = node.inputs?.find((inp) => inp.widget?.name === widget.name) - - // Intentionally mutate the widget object here as it's a reference - // to the actual widget in the graph - widget.label = newLabel || undefined - if (input) { - input.label = newLabel || undefined - } - - return true -} diff --git a/src/utils/widgetUtil.ts b/src/utils/widgetUtil.ts new file mode 100644 index 000000000..c90283156 --- /dev/null +++ b/src/utils/widgetUtil.ts @@ -0,0 +1,68 @@ +import { isProxyWidget } from '@/core/graph/subgraph/proxyWidget' +import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' +import type { SubgraphNode } from '@/lib/litegraph/src/subgraph/SubgraphNode' +import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets' + +/** + * Renames a widget and its corresponding input. + * Handles both regular widgets and proxy widgets in subgraphs. + * + * @param widget The widget to rename + * @param node The node containing the widget + * @param newLabel The new label for the widget (empty string or undefined to clear) + * @param parents Optional array of parent SubgraphNodes (for proxy widgets) + * @returns true if the rename was successful, false otherwise + */ +export function renameWidget( + widget: IBaseWidget, + node: LGraphNode, + newLabel: string, + parents?: SubgraphNode[] +): boolean { + // For proxy widgets in subgraphs, we need to rename the original interior widget + if (isProxyWidget(widget) && parents?.length) { + const subgraph = parents[0].subgraph + if (!subgraph) { + console.error('Could not find subgraph for proxy widget') + return false + } + const interiorNode = subgraph.getNodeById(widget._overlay.nodeId) + + if (!interiorNode) { + console.error('Could not find interior node for proxy widget') + return false + } + + const originalWidget = interiorNode.widgets?.find( + (w) => w.name === widget._overlay.widgetName + ) + + if (!originalWidget) { + console.error('Could not find original widget for proxy widget') + return false + } + + // Rename the original widget + originalWidget.label = newLabel || undefined + + // Also rename the corresponding input on the interior node + const interiorInput = interiorNode.inputs?.find( + (inp) => inp.widget?.name === widget._overlay.widgetName + ) + if (interiorInput) { + interiorInput.label = newLabel || undefined + } + } + + // Always rename the widget on the current node (either regular widget or proxy widget) + const input = node.inputs?.find((inp) => inp.widget?.name === widget.name) + + // Intentionally mutate the widget object here as it's a reference + // to the actual widget in the graph + widget.label = newLabel || undefined + if (input) { + input.label = newLabel || undefined + } + + return true +}