-
Notifications
You must be signed in to change notification settings - Fork 448
Support display of multitype slots #7457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
04cde3f
bf8d743
d98cc99
da8f01c
cf27bde
f0f5416
da29659
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this pulled out of the template?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's used twice. I wanted to avoid the extra lines and the chance that the two copies become desynced. I'm not 100% happy with how the border outline or scaling of optional multi-type inputs work and would like to eventually separate out/re-inline the class, but the amount of extra work this would require is not something I can justify right now. |
||
| /> | ||
| <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> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Truncation of types beyond 3 is silent.
The
.slice(0, 3)operation silently drops types beyond the first three with no indication to the user. While limiting visual complexity is reasonable, consider logging a warning or adding a visual indicator when types are truncated.🤖 Prompt for AI Agents