mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-20 06:20:11 +00:00
Backport of #10195 to core/1.42.
Cherry-picked merge commit 657ae6a with conflict resolution in
`src/utils/widgetUtil.test.ts` (added missing mock imports for the new
`renameWidget` tests).
All other files applied cleanly.
┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-10413-backport-core-1-42-fix-subgraph-promoted-widget-input-label-rename-32d6d73d3650817fb524d220c340b758)
by [Unito](https://www.unito.io)
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import type { Page } from '@playwright/test'
|
|
|
|
import type { LGraph, Subgraph } from '../../src/lib/litegraph/src/litegraph'
|
|
import { isSubgraph } from '../../src/utils/typeGuardUtil'
|
|
|
|
/**
|
|
* Assertion helper for tests where being in a subgraph is a precondition.
|
|
* Throws a clear error if the graph is not a Subgraph.
|
|
*/
|
|
export function assertSubgraph(
|
|
graph: LGraph | Subgraph | null | undefined
|
|
): asserts graph is Subgraph {
|
|
if (!isSubgraph(graph)) {
|
|
throw new Error(
|
|
'Expected to be in a subgraph context, but graph is not a Subgraph'
|
|
)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Returns the widget-input slot Y position and the node title height
|
|
* for the promoted "text" input on the SubgraphNode.
|
|
*
|
|
* The slot Y should be at the widget row, not the header. A value near
|
|
* zero or negative indicates the slot is positioned at the header (the bug).
|
|
*/
|
|
export function getTextSlotPosition(page: Page, nodeId: string) {
|
|
return page.evaluate((id) => {
|
|
const node = window.app!.canvas.graph!.getNodeById(id)
|
|
if (!node) return null
|
|
|
|
const titleHeight = window.LiteGraph!.NODE_TITLE_HEIGHT
|
|
|
|
for (const input of node.inputs) {
|
|
if (!input.widget || input.type !== 'STRING') continue
|
|
return {
|
|
hasPos: !!input.pos,
|
|
posY: input.pos?.[1] ?? null,
|
|
widgetName: input.widget.name,
|
|
titleHeight
|
|
}
|
|
}
|
|
return null
|
|
}, nodeId)
|
|
}
|