mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-09 01:20:09 +00:00
Support display of multitype slots (#7457)
Example with forcibly modified types for testing <img width="736" height="425" alt="image" src="https://github.com/user-attachments/assets/e885a7d0-5946-41be-b9b4-b9b195f50c92" /> Vue mode doesn't currently seem to display optional inputs, but the SVGs here include support for being made hollow with `--shape: url(#hollow)` <img width="765" height="360" alt="image" src="https://github.com/user-attachments/assets/0ea57179-99a4-4001-aa18-856e172287c0" /> ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-7457-Support-display-of-multitype-slots-2c86d73d3650818594afd988e73827e3) by [Unito](https://www.unito.io)
This commit is contained in:
@@ -30,6 +30,8 @@ export interface IDrawOptions {
|
||||
highlight?: boolean
|
||||
}
|
||||
|
||||
const ROTATION_OFFSET = -Math.PI / 2
|
||||
|
||||
/** Shared base class for {@link LGraphNode} input and output slots. */
|
||||
export abstract class NodeSlot extends SlotBase implements INodeSlot {
|
||||
pos?: Point
|
||||
@@ -130,6 +132,7 @@ export abstract class NodeSlot extends SlotBase implements INodeSlot {
|
||||
slot_type === SlotType.Array ? SlotShape.Grid : this.shape
|
||||
) as SlotShape
|
||||
|
||||
ctx.save()
|
||||
ctx.beginPath()
|
||||
let doFill = true
|
||||
|
||||
@@ -163,16 +166,52 @@ export abstract class NodeSlot extends SlotBase implements INodeSlot {
|
||||
if (lowQuality) {
|
||||
ctx.rect(pos[0] - 4, pos[1] - 4, 8, 8)
|
||||
} else {
|
||||
let radius: number
|
||||
if (slot_shape === SlotShape.HollowCircle) {
|
||||
const path = new Path2D()
|
||||
path.arc(pos[0], pos[1], 10, 0, Math.PI * 2)
|
||||
path.arc(pos[0], pos[1], highlight ? 2.5 : 1.5, 0, Math.PI * 2)
|
||||
ctx.clip(path, 'evenodd')
|
||||
}
|
||||
const radius = highlight ? 5 : 4
|
||||
const typesSet = new Set(
|
||||
`${this.type}`
|
||||
.split(',')
|
||||
.map(
|
||||
this.isConnected
|
||||
? (type) => colorContext.getConnectedColor(type)
|
||||
: (type) => colorContext.getDisconnectedColor(type)
|
||||
)
|
||||
)
|
||||
const types = [...typesSet].slice(0, 3)
|
||||
if (types.length > 1) {
|
||||
doFill = false
|
||||
doStroke = true
|
||||
ctx.lineWidth = 3
|
||||
ctx.strokeStyle = ctx.fillStyle
|
||||
radius = highlight ? 4 : 3
|
||||
} else {
|
||||
// Normal circle
|
||||
radius = highlight ? 5 : 4
|
||||
const arcLen = (Math.PI * 2) / types.length
|
||||
types.forEach((type, idx) => {
|
||||
ctx.moveTo(pos[0], pos[1])
|
||||
ctx.fillStyle = type
|
||||
ctx.arc(
|
||||
pos[0],
|
||||
pos[1],
|
||||
radius,
|
||||
arcLen * idx + ROTATION_OFFSET,
|
||||
Math.PI * 2 + ROTATION_OFFSET
|
||||
)
|
||||
ctx.fill()
|
||||
ctx.beginPath()
|
||||
})
|
||||
//add stroke dividers
|
||||
ctx.save()
|
||||
ctx.strokeStyle = 'black'
|
||||
ctx.lineWidth = 0.5
|
||||
types.forEach((_, idx) => {
|
||||
ctx.moveTo(pos[0], pos[1])
|
||||
const xOffset = Math.cos(arcLen * idx + ROTATION_OFFSET) * radius
|
||||
const yOffset = Math.sin(arcLen * idx + ROTATION_OFFSET) * radius
|
||||
ctx.lineTo(pos[0] + xOffset, pos[1] + yOffset)
|
||||
})
|
||||
ctx.stroke()
|
||||
ctx.restore()
|
||||
ctx.beginPath()
|
||||
}
|
||||
ctx.arc(pos[0], pos[1], radius, 0, Math.PI * 2)
|
||||
}
|
||||
@@ -180,6 +219,7 @@ export abstract class NodeSlot extends SlotBase implements INodeSlot {
|
||||
|
||||
if (doFill) ctx.fill()
|
||||
if (!lowQuality && doStroke) ctx.stroke()
|
||||
ctx.restore()
|
||||
|
||||
// render slot label
|
||||
const hideLabel = lowQuality || this.isWidgetInputSlot
|
||||
|
||||
@@ -20,13 +20,13 @@
|
||||
<!-- Connection Dot -->
|
||||
<SlotConnectionDot
|
||||
ref="connectionDotRef"
|
||||
:color="slotColor"
|
||||
:class="
|
||||
cn(
|
||||
'-translate-x-1/2 w-3',
|
||||
hasSlotError && 'ring-2 ring-error ring-offset-0 rounded-full'
|
||||
)
|
||||
"
|
||||
:slot-data
|
||||
@click="onClick"
|
||||
@dblclick="onDoubleClick"
|
||||
@pointerdown="onPointerDown"
|
||||
@@ -54,7 +54,6 @@ import { computed, onErrorCaptured, ref, watchEffect } from 'vue'
|
||||
import type { ComponentPublicInstance } from 'vue'
|
||||
|
||||
import { useErrorHandling } from '@/composables/useErrorHandling'
|
||||
import { getSlotColor } from '@/constants/slotColors'
|
||||
import type { INodeSlot } from '@/lib/litegraph/src/litegraph'
|
||||
import { useSlotLinkDragUIState } from '@/renderer/core/canvas/links/slotLinkDragUIState'
|
||||
import { getSlotKey } from '@/renderer/core/layout/slots/slotIdentifier'
|
||||
@@ -111,13 +110,6 @@ onErrorCaptured((error) => {
|
||||
return false
|
||||
})
|
||||
|
||||
const slotColor = computed(() => {
|
||||
if (hasSlotError.value) {
|
||||
return 'var(--color-error)'
|
||||
}
|
||||
return getSlotColor(props.slotData.type)
|
||||
})
|
||||
|
||||
const { state: dragState } = useSlotLinkDragUIState()
|
||||
const slotKey = computed(() =>
|
||||
getSlotKey(props.nodeId ?? '', props.index, true)
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
<!-- Connection Dot -->
|
||||
<SlotConnectionDot
|
||||
ref="connectionDotRef"
|
||||
:color="slotColor"
|
||||
class="w-3 translate-x-1/2"
|
||||
:slot-data
|
||||
@pointerdown="onPointerDown"
|
||||
/>
|
||||
</div>
|
||||
@@ -22,7 +22,6 @@ import { computed, onErrorCaptured, ref, watchEffect } from 'vue'
|
||||
import type { ComponentPublicInstance } from 'vue'
|
||||
|
||||
import { useErrorHandling } from '@/composables/useErrorHandling'
|
||||
import { getSlotColor } from '@/constants/slotColors'
|
||||
import type { INodeSlot } from '@/lib/litegraph/src/litegraph'
|
||||
import { useSlotLinkDragUIState } from '@/renderer/core/canvas/links/slotLinkDragUIState'
|
||||
import { getSlotKey } from '@/renderer/core/layout/slots/slotIdentifier'
|
||||
@@ -67,9 +66,6 @@ onErrorCaptured((error) => {
|
||||
return false
|
||||
})
|
||||
|
||||
// Get slot color based on type
|
||||
const slotColor = computed(() => getSlotColor(props.slotData.type))
|
||||
|
||||
const { state: dragState } = useSlotLinkDragUIState()
|
||||
const slotKey = computed(() =>
|
||||
getSlotKey(props.nodeId ?? '', props.index, false)
|
||||
|
||||
@@ -1,20 +1,45 @@
|
||||
<script setup lang="ts">
|
||||
import { useTemplateRef } from 'vue'
|
||||
import { computed, useTemplateRef } from 'vue'
|
||||
|
||||
import { getSlotColor } from '@/constants/slotColors'
|
||||
import type { INodeSlot } from '@/lib/litegraph/src/litegraph'
|
||||
import { cn } from '@/utils/tailwindUtil'
|
||||
import type { ClassValue } from '@/utils/tailwindUtil'
|
||||
|
||||
const props = defineProps<{
|
||||
color?: string
|
||||
multi?: boolean
|
||||
slotData?: INodeSlot
|
||||
class?: ClassValue
|
||||
hasError?: boolean
|
||||
multi?: boolean
|
||||
}>()
|
||||
|
||||
const slotElRef = useTemplateRef('slot-el')
|
||||
|
||||
function getTypes() {
|
||||
if (props.hasError) return ['var(--color-error)']
|
||||
//TODO Support connected/disconnected colors?
|
||||
if (!props.slotData) return [getSlotColor()]
|
||||
const typesSet = new Set(
|
||||
`${props.slotData.type}`.split(',').map(getSlotColor)
|
||||
)
|
||||
return [...typesSet].slice(0, 3)
|
||||
}
|
||||
const types = getTypes()
|
||||
|
||||
defineExpose({
|
||||
slotElRef
|
||||
})
|
||||
|
||||
const slotClass = computed(() =>
|
||||
cn(
|
||||
'bg-slate-300 rounded-full slot-dot',
|
||||
'transition-all duration-150',
|
||||
'border border-solid border-node-component-slot-dot-outline',
|
||||
props.multi
|
||||
? 'w-3 h-6'
|
||||
: 'size-3 cursor-crosshair group-hover/slot:[--node-component-slot-dot-outline-opacity-mult:5] group-hover/slot:scale-125'
|
||||
)
|
||||
)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -27,19 +52,26 @@ defineExpose({
|
||||
"
|
||||
>
|
||||
<div
|
||||
v-if="types.length === 1"
|
||||
ref="slot-el"
|
||||
class="slot-dot"
|
||||
:style="{ backgroundColor: color }"
|
||||
:class="
|
||||
cn(
|
||||
'bg-slate-300 rounded-full',
|
||||
'transition-all duration-150',
|
||||
'border border-solid border-node-component-slot-dot-outline',
|
||||
!multi &&
|
||||
'cursor-crosshair group-hover/slot:[--node-component-slot-dot-outline-opacity-mult:5] group-hover/slot:scale-125',
|
||||
multi ? 'w-3 h-6' : 'size-3'
|
||||
)
|
||||
"
|
||||
:style="{ backgroundColor: types[0] }"
|
||||
:class="slotClass"
|
||||
/>
|
||||
<div
|
||||
v-else
|
||||
ref="slot-el"
|
||||
:style="{
|
||||
'--type1': types[0],
|
||||
'--type2': types[1],
|
||||
'--type3': types[2]
|
||||
}"
|
||||
:class="slotClass"
|
||||
>
|
||||
<i-comfy:node-slot2
|
||||
v-if="types.length === 2"
|
||||
class="size-full -translate-y-1/2"
|
||||
/>
|
||||
<i-comfy:node-slot3 v-else class="size-full -translate-y-1/2" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user