Skip to content

Commit 6d0712a

Browse files
committed
nits
1 parent 756e391 commit 6d0712a

File tree

4 files changed

+19
-21
lines changed

4 files changed

+19
-21
lines changed

src/core/graph/widgets/dynamicWidgets.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useLitegraphService } from '@/services/litegraphService'
66
import { app } from '@/scripts/app'
77
import type { ComfyApp } from '@/scripts/app'
88

9-
function COMFY_DYNAMICCOMBO_V3(
9+
function dynamicComboWidget(
1010
node: LGraphNode,
1111
inputName: string,
1212
untypedInputData: InputSpec,
@@ -111,4 +111,4 @@ function COMFY_DYNAMICCOMBO_V3(
111111
return { widget, minWidth, minHeight }
112112
}
113113

114-
export const dynamicWidgets = { COMFY_DYNAMICCOMBO_V3 }
114+
export const dynamicWidgets = { COMFY_DYNAMICCOMBO_V3: dynamicComboWidget }

src/lib/litegraph/src/LGraphNode.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -847,12 +847,13 @@ export class LGraphNode
847847
if (info.widgets_values) {
848848
const widgetsWithValue = this.widgets
849849
.values()
850-
.filter((w) => w.serialize !== false)
851-
widgetsWithValue.forEach((widget, i) => {
852-
if (widget && i < info.widgets_values!.length) {
853-
widget.value = info.widgets_values![i]
854-
}
855-
})
850+
.filter(
851+
(w, idx) =>
852+
w.serialize !== false && idx < info.widgets_values!.length
853+
)
854+
widgetsWithValue.forEach(
855+
(widget, i) => (widget.value = info.widgets_values![i])
856+
)
856857
}
857858
}
858859

@@ -1653,15 +1654,12 @@ export class LGraphNode
16531654
deleteCount = -1,
16541655
...toAdd: INodeInputSlot[]
16551656
): INodeInputSlot[] {
1656-
if (deleteCount === -1) deleteCount = this.inputs.length - startIndex
1657-
1658-
const lengthDelta = toAdd.length - deleteCount
1657+
if (deleteCount < 0) return this.inputs.splice(startIndex)
16591658
const ret = this.inputs.splice(startIndex, deleteCount, ...toAdd)
1660-
for (const input of this.inputs.slice(startIndex + toAdd.length)) {
1659+
this.inputs.slice(startIndex).forEach((input, index) => {
16611660
const link = input.link && this.graph?.links?.get(input.link)
1662-
if (!link) continue
1663-
link.target_slot += lengthDelta
1664-
}
1661+
if (link) link.target_slot = startIndex + index
1662+
})
16651663
return ret
16661664
}
16671665

src/services/litegraphService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ import { getOrderedInputSpecs } from '@/workbench/utils/nodeDefOrderingUtil'
5959

6060
import { useExtensionService } from './extensionService'
6161

62-
interface HasInitialMinSize {
62+
export interface HasInitialMinSize {
6363
_initialMinSize: { width: number; height: number }
6464
}
6565

tests-ui/tests/widgets/dynamicCombo.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { createPinia, setActivePinia } from 'pinia'
1+
import { setActivePinia } from 'pinia'
2+
import { createTestingPinia } from '@pinia/testing'
23
import { describe, expect, test } from 'vitest'
34
import { LGraphNode } from '@/lib/litegraph/src/litegraph'
45
import { transformInputSpecV1ToV2 } from '@/schemas/nodeDef/migration'
56
import type { InputSpec } from '@/schemas/nodeDefSchema'
67
import { useLitegraphService } from '@/services/litegraphService'
8+
import type { HasInitialMinSize } from '@/services/litegraphService'
79

8-
setActivePinia(createPinia())
10+
setActivePinia(createTestingPinia())
911
type DynamicInputs = ('INT' | 'STRING' | 'IMAGE' | DynamicInputs)[][]
1012

1113
const { addNodeInput } = useLitegraphService()
@@ -39,9 +41,7 @@ function addDynamicCombo(node: LGraphNode, inputs: DynamicInputs) {
3941
)
4042
}
4143
function testNode() {
42-
const node: LGraphNode & {
43-
_initialMinSize?: { width: number; height: number }
44-
} = new LGraphNode('test')
44+
const node: LGraphNode & Partial<HasInitialMinSize> = new LGraphNode('test')
4545
node.widgets = []
4646
node._initialMinSize = { width: 1, height: 1 }
4747
node.constructor.nodeData = {

0 commit comments

Comments
 (0)