Skip to content

Commit dd46505

Browse files
authored
fix(core): use correct handlesuffix in getHandleConnections (#1880)
* fix(core): use correct handlesuffix in `getHandleConnections` Signed-off-by: braks <[email protected]> * chore(changeset): add --------- Signed-off-by: braks <[email protected]>
1 parent 420b067 commit dd46505

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

.changeset/twelve-olives-fly.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@vue-flow/core": patch
3+
---
4+
5+
Use correct handlesuffix for connection lookup in `getHandleConnections` action.

examples/vite/src/Basic/Basic.vue

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ import { Background } from '@vue-flow/background'
66
import { Controls } from '@vue-flow/controls'
77
import { MiniMap } from '@vue-flow/minimap'
88
9-
const elements = ref<Elements>([
9+
const nodes = ref<Elements>([
1010
{ id: '1', type: 'input', label: 'Node 1', position: { x: 250, y: 5 }, class: 'light' },
1111
{ id: '2', label: 'Node 2', position: { x: 100, y: 100 }, class: 'light' },
1212
{ id: '3', label: 'Node 3', position: { x: 400, y: 100 }, class: 'light' },
1313
{ id: '4', label: 'Node 4', position: { x: 400, y: 200 }, class: 'light' },
14+
])
15+
16+
const edges = ref<Elements>([
1417
{ id: 'e1-2', source: '1', target: '2', animated: true },
1518
{ id: 'e1-3', source: '1', target: '3' },
1619
])
@@ -23,7 +26,7 @@ const { onConnect, addEdges, setViewport, toObject } = useVueFlow({
2326
onConnect(addEdges)
2427
2528
function updatePos() {
26-
return elements.value.forEach((el) => {
29+
return nodes.value.forEach((el) => {
2730
if (isNode(el)) {
2831
el.position = {
2932
x: Math.random() * 400,
@@ -40,20 +43,34 @@ function resetViewport() {
4043
return setViewport({ x: 0, y: 0, zoom: 1 })
4144
}
4245
function toggleclass() {
43-
return elements.value.forEach((el) => (el.class = el.class === 'light' ? 'dark' : 'light'))
46+
return nodes.value.forEach((el) => (el.class = el.class === 'light' ? 'dark' : 'light'))
4447
}
4548
</script>
4649

4750
<template>
48-
<VueFlow v-model="elements" fit-view-on-init class="vue-flow-basic-example">
51+
<VueFlow
52+
:nodes="nodes"
53+
:edges="edges"
54+
:delete-key-code="['Backspace', 'Delete']"
55+
fit-view-on-init
56+
class="vue-flow-basic-example"
57+
>
4958
<Background />
50-
<MiniMap />
59+
<MiniMap node-color="red" :nodes="nodes" :edges="edges" />
5160
<Controls />
5261
<Panel position="top-right" style="display: flex; gap: 5px">
62+
<input />
5363
<button @click="resetViewport">reset viewport</button>
5464
<button @click="updatePos">change pos</button>
5565
<button @click="toggleclass">toggle class</button>
5666
<button @click="logToObject">toObject</button>
5767
</Panel>
5868
</VueFlow>
5969
</template>
70+
71+
<style>
72+
.vue-flow__minimap {
73+
transform: scale(75%);
74+
transform-origin: bottom right;
75+
}
76+
</style>

packages/core/src/store/actions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ export function useActions(state: State, nodeLookup: ComputedRef<NodeLookup>, ed
7373
}
7474

7575
const getHandleConnections: Actions['getHandleConnections'] = ({ id, type, nodeId }) => {
76-
return Array.from(state.connectionLookup.get(`${nodeId}-${type}-${id ?? null}`)?.values() ?? [])
76+
const handleSuffix = id ? `-${type}-${id}` : `-${type}`
77+
return Array.from(state.connectionLookup.get(`${nodeId}${handleSuffix}`)?.values() ?? [])
7778
}
7879

7980
const findNode: Actions['findNode'] = (id) => {

0 commit comments

Comments
 (0)