mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-30 11:11:53 +00:00
clean up onPointerDown
This commit is contained in:
@@ -436,60 +436,65 @@ export function useSlotLinkInteraction({
|
|||||||
)
|
)
|
||||||
if (!layout) return
|
if (!layout) return
|
||||||
|
|
||||||
const resolvedNode = graph.getNodeById(Number(nodeId))
|
const numericNodeId = Number(nodeId)
|
||||||
const inputSlot =
|
const isInputSlot = type === 'input'
|
||||||
type === 'input' ? resolvedNode?.inputs?.[index] : undefined
|
const isOutputSlot = type === 'output'
|
||||||
|
|
||||||
|
const resolvedNode = graph.getNodeById(numericNodeId)
|
||||||
|
const inputSlot = isInputSlot ? resolvedNode?.inputs?.[index] : undefined
|
||||||
|
const outputSlot = isOutputSlot ? resolvedNode?.outputs?.[index] : undefined
|
||||||
|
|
||||||
const ctrlOrMeta = event.ctrlKey || event.metaKey
|
const ctrlOrMeta = event.ctrlKey || event.metaKey
|
||||||
const hasExistingInputLink = Boolean(
|
|
||||||
inputSlot && (inputSlot.link != null || inputSlot._floatingLinks?.size)
|
|
||||||
)
|
|
||||||
|
|
||||||
const shouldBreakExistingLink =
|
const inputLinkId = inputSlot?.link ?? null
|
||||||
hasExistingInputLink && ctrlOrMeta && event.altKey && !event.shiftKey
|
const inputFloatingCount = inputSlot?._floatingLinks?.size ?? 0
|
||||||
|
const hasExistingInputLink = inputLinkId != null || inputFloatingCount > 0
|
||||||
|
|
||||||
const existingLink =
|
const outputLinkCount = outputSlot?.links?.length ?? 0
|
||||||
type === 'input' && inputSlot?.link != null
|
const outputFloatingCount = outputSlot?._floatingLinks?.size ?? 0
|
||||||
? graph.getLink(inputSlot.link)
|
const hasExistingOutputLink = outputLinkCount > 0 || outputFloatingCount > 0
|
||||||
|
|
||||||
|
const shouldBreakExistingInputLink =
|
||||||
|
isInputSlot &&
|
||||||
|
hasExistingInputLink &&
|
||||||
|
ctrlOrMeta &&
|
||||||
|
event.altKey &&
|
||||||
|
!event.shiftKey
|
||||||
|
|
||||||
|
const existingInputLink =
|
||||||
|
isInputSlot && inputLinkId != null
|
||||||
|
? graph.getLink(inputLinkId)
|
||||||
: undefined
|
: undefined
|
||||||
|
|
||||||
if (shouldBreakExistingLink && resolvedNode) {
|
if (shouldBreakExistingInputLink && resolvedNode) {
|
||||||
resolvedNode.disconnectInput(index, true)
|
resolvedNode.disconnectInput(index, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
const baseDirection =
|
const baseDirection = isInputSlot
|
||||||
type === 'input'
|
? inputSlot?.dir ?? LinkDirection.LEFT
|
||||||
? inputSlot?.dir ?? LinkDirection.LEFT
|
: outputSlot?.dir ?? LinkDirection.RIGHT
|
||||||
: resolvedNode?.outputs?.[index]?.dir ?? LinkDirection.RIGHT
|
|
||||||
|
|
||||||
const existingAnchor =
|
const existingAnchor =
|
||||||
type === 'input' && !shouldBreakExistingLink
|
isInputSlot && !shouldBreakExistingInputLink
|
||||||
? resolveExistingInputLinkAnchor(graph, inputSlot)
|
? resolveExistingInputLinkAnchor(graph, inputSlot)
|
||||||
: null
|
: null
|
||||||
|
|
||||||
const outputSlot =
|
|
||||||
type === 'output' ? resolvedNode?.outputs?.[index] : undefined
|
|
||||||
const hasExistingOutputLink = Boolean(
|
|
||||||
outputSlot &&
|
|
||||||
((outputSlot.links?.length ?? 0) > 0 ||
|
|
||||||
(outputSlot._floatingLinks?.size ?? 0) > 0)
|
|
||||||
)
|
|
||||||
const shouldMoveExistingOutput =
|
const shouldMoveExistingOutput =
|
||||||
type === 'output' && event.shiftKey && hasExistingOutputLink
|
isOutputSlot && event.shiftKey && hasExistingOutputLink
|
||||||
|
|
||||||
|
const shouldMoveExistingInput =
|
||||||
|
isInputSlot && !shouldBreakExistingInputLink && hasExistingInputLink
|
||||||
|
|
||||||
adapter ??= createLinkConnectorAdapter()
|
adapter ??= createLinkConnectorAdapter()
|
||||||
if (adapter) {
|
if (adapter) {
|
||||||
if (type === 'output') {
|
if (isOutputSlot) {
|
||||||
adapter.beginFromOutput(Number(nodeId), index, {
|
adapter.beginFromOutput(numericNodeId, index, {
|
||||||
moveExisting: shouldMoveExistingOutput
|
moveExisting: shouldMoveExistingOutput
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
const moveExisting = !!(
|
adapter.beginFromInput(numericNodeId, index, {
|
||||||
inputSlot &&
|
moveExisting: shouldMoveExistingInput
|
||||||
!shouldBreakExistingLink &&
|
})
|
||||||
(inputSlot.link != null || inputSlot._floatingLinks?.size)
|
|
||||||
)
|
|
||||||
adapter.beginFromInput(Number(nodeId), index, { moveExisting })
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -506,7 +511,9 @@ export function useSlotLinkInteraction({
|
|||||||
type,
|
type,
|
||||||
direction,
|
direction,
|
||||||
position: startPosition,
|
position: startPosition,
|
||||||
linkId: !shouldBreakExistingLink ? existingLink?.id : undefined,
|
linkId: !shouldBreakExistingInputLink
|
||||||
|
? existingInputLink?.id
|
||||||
|
: undefined,
|
||||||
movingExistingOutput: shouldMoveExistingOutput
|
movingExistingOutput: shouldMoveExistingOutput
|
||||||
},
|
},
|
||||||
event.pointerId
|
event.pointerId
|
||||||
|
|||||||
Reference in New Issue
Block a user