Skip to content

Commit 7c2a768

Browse files
authored
More forgiving connections in vue (#6565)
The previous link connection code uses [closest](https://developer.mozilla.org/en-US/docs/Web/API/Element/closest) to find a slot. Closest only checks parents, not siblings. Since the sought element has no children, this meant connection to a slot required the mouse be directly over the slot. This is changed by finding the closest (parent) widget or slot, and then querying for the slot. For simplicity, this means introducing an `lg-node-widget` class. As a result, connections can be made by hovering anywhere over a valid widget. ![vue-connections_00001](https://github.com/user-attachments/assets/e556ff3f-8cbb-4198-998d-9c2aadf2c73c) Resolves #6488 ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-6565-More-forgiving-connections-in-vue-2a16d73d365081e1bf46f5d54ec382d6) by [Unito](https://www.unito.io)
1 parent a4fc68a commit 7c2a768

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

src/renderer/core/canvas/links/linkDropOrchestrator.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ export const resolveSlotTargetCandidate = (
2020
const { state: dragState, setCompatibleForKey } = useSlotLinkDragUIState()
2121
if (!(target instanceof HTMLElement)) return null
2222

23-
const elWithKey = target.closest<HTMLElement>('[data-slot-key]')
23+
const elWithKey = target
24+
.closest('.lg-slot, .lg-node-widget')
25+
?.querySelector<HTMLElement>('[data-slot-key]')
2426
const key = elWithKey?.dataset['slotKey']
2527
if (!key) return null
2628

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<div
2020
v-for="(widget, index) in processedWidgets"
2121
:key="`widget-${index}-${widget.name}`"
22-
class="group flex items-stretch has-[.widget-expands]:flex-1"
22+
class="lg-node-widget group flex items-stretch has-[.widget-expands]:flex-1"
2323
>
2424
<!-- Widget Input Slot Dot -->
2525

src/renderer/extensions/vueNodes/composables/useSlotLinkInteraction.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -301,14 +301,12 @@ export function useSlotLinkInteraction({
301301
hoveredSlotKey = dragContext.lastPointerTargetSlotKey
302302
hoveredNodeId = dragContext.lastPointerTargetNodeId
303303
} else if (target instanceof HTMLElement) {
304-
const elWithSlot = target.closest<HTMLElement>('[data-slot-key]')
305-
const elWithNode = elWithSlot
306-
? null
307-
: target.closest<HTMLElement>('[data-node-id]')
304+
const elWithSlot = target
305+
.closest('.lg-slot, .lg-node-widget')
306+
?.querySelector<HTMLElement>('[data-slot-key]')
307+
const elWithNode = target.closest<HTMLElement>('[data-node-id]')
308308
hoveredSlotKey = elWithSlot?.dataset['slotKey'] ?? null
309-
hoveredNodeId = hoveredSlotKey
310-
? null
311-
: (elWithNode?.dataset['nodeId'] ?? null)
309+
hoveredNodeId = elWithNode?.dataset['nodeId'] ?? null
312310
dragContext.lastPointerEventTarget = target
313311
dragContext.lastPointerTargetSlotKey = hoveredSlotKey
314312
dragContext.lastPointerTargetNodeId = hoveredNodeId
@@ -325,10 +323,8 @@ export function useSlotLinkInteraction({
325323
const graph = app.canvas?.graph ?? null
326324
const context = { adapter, graph, session: dragContext }
327325
const slotCandidate = resolveSlotTargetCandidate(target, context)
328-
const nodeCandidate = slotCandidate
329-
? null
330-
: resolveNodeSurfaceSlotCandidate(target, context)
331-
candidate = slotCandidate ?? nodeCandidate
326+
const nodeCandidate = resolveNodeSurfaceSlotCandidate(target, context)
327+
candidate = slotCandidate?.compatible ? slotCandidate : nodeCandidate
332328
dragContext.lastHoverSlotKey = hoveredSlotKey
333329
dragContext.lastHoverNodeId = hoveredNodeId
334330

@@ -339,7 +335,8 @@ export function useSlotLinkInteraction({
339335
slotCandidate.layout.type === 'input'
340336
)
341337
setCompatibleForKey(key, !!slotCandidate.compatible)
342-
} else if (nodeCandidate) {
338+
}
339+
if (nodeCandidate && !slotCandidate?.compatible) {
343340
const key = getSlotKey(
344341
nodeCandidate.layout.nodeId,
345342
nodeCandidate.layout.index,

0 commit comments

Comments
 (0)