Skip to content

Commit 0fea54c

Browse files
authored
Typing: Slots in VueNodeData (#5759)
## Summary Replace the unknown type with the interface in Litegraph. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-5759-Typing-Slots-in-VueNodeData-2786d73d36508194b286fad172b13c51) by [Unito](https://www.unito.io)
1 parent cd7666e commit 0fea54c

File tree

3 files changed

+40
-15
lines changed

3 files changed

+40
-15
lines changed

src/composables/graph/useGraphNodeManager.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import { reactive } from 'vue'
66

77
import { useChainCallback } from '@/composables/functional/useChainCallback'
8+
import type { INodeOutputSlot } from '@/lib/litegraph/src/interfaces'
9+
import type { INodeInputSlot } from '@/lib/litegraph/src/interfaces'
810
import { useLayoutMutations } from '@/renderer/core/layout/operations/layoutMutations'
911
import { LayoutSource } from '@/renderer/core/layout/types'
1012
import type { WidgetValue } from '@/types/simplifiedWidget'
@@ -28,8 +30,8 @@ export interface VueNodeData {
2830
executing: boolean
2931
subgraphId?: string | null
3032
widgets?: SafeWidgetData[]
31-
inputs?: unknown[]
32-
outputs?: unknown[]
33+
inputs?: INodeInputSlot[]
34+
outputs?: INodeOutputSlot[]
3335
hasErrors?: boolean
3436
flags?: {
3537
collapsed?: boolean

src/renderer/extensions/vueNodes/components/LGraphNodePreview.vue

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
import { computed } from 'vue'
3939
4040
import type { VueNodeData } from '@/composables/graph/useGraphNodeManager'
41+
import type {
42+
INodeInputSlot,
43+
INodeOutputSlot
44+
} from '@/lib/litegraph/src/interfaces'
45+
import { RenderShape } from '@/lib/litegraph/src/litegraph'
4146
import NodeContent from '@/renderer/extensions/vueNodes/components/NodeContent.vue'
4247
import NodeHeader from '@/renderer/extensions/vueNodes/components/NodeHeader.vue'
4348
import NodeSlots from '@/renderer/extensions/vueNodes/components/NodeSlots.vue'
@@ -74,26 +79,29 @@ const nodeData = computed<VueNodeData>(() => {
7479
}
7580
}))
7681
77-
const inputs = Object.entries(nodeDef.inputs || {})
82+
const inputs: INodeInputSlot[] = Object.entries(nodeDef.inputs || {})
7883
.filter(([_, input]) => !widgetStore.inputIsWidget(input))
7984
.map(([name, input]) => ({
8085
name,
8186
type: input.type,
82-
shape: input.isOptional ? 'HollowCircle' : undefined,
83-
boundingRect: [0, 0, 0, 0]
87+
shape: input.isOptional ? RenderShape.HollowCircle : undefined,
88+
boundingRect: [0, 0, 0, 0],
89+
link: null
8490
}))
8591
86-
const outputs = (nodeDef.outputs || []).map((output) => {
92+
const outputs: INodeOutputSlot[] = (nodeDef.outputs || []).map((output) => {
8793
if (typeof output === 'string') {
8894
return {
8995
name: output,
9096
type: output,
91-
boundingRect: [0, 0, 0, 0]
97+
boundingRect: [0, 0, 0, 0],
98+
links: []
9299
}
93100
}
94101
return {
95102
...output,
96-
boundingRect: [0, 0, 0, 0]
103+
boundingRect: [0, 0, 0, 0],
104+
links: []
97105
}
98106
})
99107

src/renderer/extensions/vueNodes/components/NodeSlots.spec.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { type PropType, defineComponent } from 'vue'
55
import { createI18n } from 'vue-i18n'
66

77
import type { VueNodeData } from '@/composables/graph/useGraphNodeManager'
8+
import type { INodeOutputSlot } from '@/lib/litegraph/src/interfaces'
9+
import type { INodeInputSlot } from '@/lib/litegraph/src/interfaces'
810
import enMessages from '@/locales/en/main.json' with { type: 'json' }
911

1012
import NodeSlots from './NodeSlots.vue'
@@ -94,15 +96,17 @@ describe('NodeSlots.vue', () => {
9496
const inputObjNoWidget = {
9597
name: 'objNoWidget',
9698
type: 'number',
97-
boundingRect: [0, 0, 0, 0]
99+
boundingRect: new Float32Array([0, 0, 0, 0]),
100+
link: null
98101
}
99102
const inputObjWithWidget = {
100103
name: 'objWithWidget',
101104
type: 'number',
102-
boundingRect: [0, 0, 0, 0],
103-
widget: { name: 'objWithWidget' }
105+
boundingRect: new Float32Array([0, 0, 0, 0]),
106+
widget: { name: 'objWithWidget' },
107+
link: null
104108
}
105-
const inputs = [inputObjNoWidget, inputObjWithWidget, 'stringInput']
109+
const inputs: INodeInputSlot[] = [inputObjNoWidget, inputObjWithWidget]
106110

107111
const wrapper = mountSlots(makeNodeData({ inputs }))
108112

@@ -143,8 +147,19 @@ describe('NodeSlots.vue', () => {
143147
})
144148

145149
it('maps outputs and passes correct indexes', () => {
146-
const outputObj = { name: 'outA', type: 'any', boundingRect: [0, 0, 0, 0] }
147-
const outputs = [outputObj, 'outB']
150+
const outputObj = {
151+
name: 'outA',
152+
type: 'any',
153+
boundingRect: new Float32Array([0, 0, 0, 0]),
154+
links: []
155+
}
156+
const outputObjB = {
157+
name: 'outB',
158+
type: 'any',
159+
boundingRect: new Float32Array([0, 0, 0, 0]),
160+
links: []
161+
}
162+
const outputs: INodeOutputSlot[] = [outputObj, outputObjB]
148163

149164
const wrapper = mountSlots(makeNodeData({ outputs }))
150165
const outputEls = wrapper
@@ -174,7 +189,7 @@ describe('NodeSlots.vue', () => {
174189

175190
it('passes readonly to child slots', () => {
176191
const wrapper = mountSlots(
177-
makeNodeData({ inputs: ['a'], outputs: ['b'] }),
192+
makeNodeData({ inputs: [], outputs: [] }),
178193
/* readonly */ true
179194
)
180195
const all = [

0 commit comments

Comments
 (0)