Rework minsize code to better support tests

This commit is contained in:
Austin Mroz
2026-03-30 11:24:02 -07:00
parent d63e5b4257
commit 64c7ebc1a9
3 changed files with 7 additions and 17 deletions

View File

@@ -2,20 +2,10 @@ import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
import type { InputSpec } from '@/schemas/nodeDefSchema'
import { transformInputSpecV1ToV2 } from '@/schemas/nodeDef/migration'
import { useLitegraphService } from '@/services/litegraphService'
import type { HasInitialMinSize } from '@/services/litegraphService'
type DynamicInputs = ('INT' | 'STRING' | 'IMAGE' | DynamicInputs)[][]
function ensureNodeState(node: LGraphNode & Partial<HasInitialMinSize>) {
node._initialMinSize ??= { width: 1, height: 1 }
;(node.constructor as { nodeData?: { name: string } }).nodeData ??= {
name: 'testnode'
}
node.widgets ??= []
}
export function addDynamicCombo(node: LGraphNode, inputs: DynamicInputs) {
ensureNodeState(node)
const namePrefix = `${node.widgets?.length ?? 0}`
function getSpec(
inputs: DynamicInputs,
@@ -45,7 +35,6 @@ export function addDynamicCombo(node: LGraphNode, inputs: DynamicInputs) {
}
export function addAutogrow(node: LGraphNode, template: unknown) {
ensureNodeState(node)
useLitegraphService().addNodeInput(
node,
transformInputSpecV1ToV2(['COMFY_AUTOGROW_V3', { template }], {

View File

@@ -8,7 +8,6 @@ import {
} from '@/core/graph/widgets/__fixtures__/dynamicInputHelpers'
import { LGraph, LGraphNode } from '@/lib/litegraph/src/litegraph'
import { useLitegraphService } from '@/services/litegraphService'
import type { HasInitialMinSize } from '@/services/litegraphService'
setActivePinia(createTestingPinia())
@@ -25,7 +24,7 @@ function connectInput(node: LGraphNode, inputIndex: number, graph: LGraph) {
node2.connect(0, node, inputIndex)
}
function testNode() {
const node: LGraphNode & Partial<HasInitialMinSize> = new LGraphNode('test')
const node = new LGraphNode('test')
node.widgets = []
return node as LGraphNode & Required<Pick<LGraphNode, 'widgets'>>
}

View File

@@ -119,7 +119,7 @@ async function reencodeAsPngBlob(
}
export interface HasInitialMinSize {
_initialMinSize: { width: number; height: number }
_initialMinSize?: { width: number; height: number }
}
export const CONFIG = Symbol()
@@ -206,7 +206,7 @@ export const useLitegraphService = () => {
* @internal The key for the node definition in the i18n file.
*/
function nodeKey(node: LGraphNode): string {
return `nodeDefs.${normalizeI18nKey(node.constructor.nodeData!.name)}`
return `nodeDefs.${normalizeI18nKey(node.constructor.nodeData?.name ?? '')}`
}
/**
* @internal Add input sockets to the node. (No widget)
@@ -313,6 +313,7 @@ export const useLitegraphService = () => {
})
}
const castedNode = node as LGraphNode & HasInitialMinSize
castedNode._initialMinSize ??= { width: 1, height: 1 }
castedNode._initialMinSize.width = Math.max(
castedNode._initialMinSize.width,
minWidth
@@ -370,8 +371,9 @@ export const useLitegraphService = () => {
node.widgets?.length &&
!useSettingStore().get('LiteGraph.Node.DefaultPadding')
const castedNode = node as LGraphNode & HasInitialMinSize
s[0] = Math.max(castedNode._initialMinSize.width, s[0] + (pad ? 60 : 0))
s[1] = Math.max(castedNode._initialMinSize.height, s[1])
const minSize = castedNode._initialMinSize ?? { width: 1, height: 1 }
s[0] = Math.max(minSize.width, s[0] + (pad ? 60 : 0))
s[1] = Math.max(minSize.height, s[1])
node.setSize(s)
}