Skip to content

Commit 55a76cd

Browse files
committed
chore(docs): update validation example
1 parent 889797e commit 55a76cd

File tree

4 files changed

+39
-23
lines changed

4 files changed

+39
-23
lines changed

docs/examples/validation/App.vue

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,42 @@ const { addEdges } = useVueFlow()
99
const nodes = ref([
1010
{
1111
id: '0',
12-
type: 'custominput',
12+
type: 'input',
1313
position: { x: 0, y: 150 },
14-
isValidTargetPos: (connection) => connection.target === 'B',
14+
// only target `B` is valid for this node
15+
data: { validTarget: 'B', validSource: '0' },
1516
},
1617
{
1718
id: 'A',
1819
type: 'custom',
1920
position: { x: 250, y: 0 },
20-
isValidSourcePos: () => false,
21+
// no valid connections can be made for this node
22+
data: {},
2123
},
2224
{
2325
id: 'B',
2426
type: 'custom',
2527
position: { x: 250, y: 150 },
26-
isValidSourcePos: (connection) => connection.target === 'B',
28+
// only source `0` is valid for this node
29+
data: { validTarget: 'B', validSource: '0' },
2730
},
2831
{
2932
id: 'C',
3033
type: 'custom',
3134
position: { x: 250, y: 300 },
32-
isValidSourcePos: (connection) => connection.target === 'B',
35+
// no valid connections can be made for this node
36+
data: {},
3337
},
3438
])
3539
3640
const edges = ref([])
3741
3842
function onConnectStart({ nodeId, handleType }) {
39-
return console.log('on connect start', { nodeId, handleType })
43+
console.log('on connect start', { nodeId, handleType })
4044
}
4145
4246
function onConnectEnd(event) {
43-
return console.log('on connect end', event)
47+
console.log('on connect end', event)
4448
}
4549
4650
function onConnect(params) {
@@ -59,12 +63,12 @@ function onConnect(params) {
5963
@connect-start="onConnectStart"
6064
@connect-end="onConnectEnd"
6165
>
62-
<template #node-custominput="props">
63-
<CustomInput v-bind="props" />
66+
<template #node-input="props">
67+
<CustomInput :data="props.data" />
6468
</template>
6569

6670
<template #node-custom="props">
67-
<CustomNode v-bind="props" />
71+
<CustomNode :id="props.id" :data="props.data" />
6872
</template>
6973
</VueFlow>
7074
</template>

docs/examples/validation/CustomInput.vue

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
import { Handle, Position } from '@vue-flow/core'
33
44
const props = defineProps({
5-
isValidTargetPos: {
6-
type: Function,
7-
required: false,
5+
data: {
6+
type: Object,
7+
required: true,
88
},
99
})
10+
11+
function isValidConnection(connection) {
12+
return connection.target === props.data.validTarget && connection.source === props.data.validSource
13+
}
1014
</script>
1115

1216
<script>
@@ -16,6 +20,6 @@ export default {
1620
</script>
1721

1822
<template>
19-
<div>Only connectable with B</div>
20-
<Handle type="source" :position="Position.Right" :is-valid-connection="props.isValidTargetPos" />
23+
<div>Only connectable with {{ data.validTarget }}</div>
24+
<Handle type="source" :position="Position.Right" :is-valid-connection="isValidConnection" />
2125
</template>

docs/examples/validation/CustomNode.vue

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ const props = defineProps({
66
type: String,
77
required: true,
88
},
9-
isValidSourcePos: {
10-
type: Function,
11-
required: false,
9+
data: {
10+
type: Object,
11+
required: true,
1212
},
1313
})
14+
15+
function isValidConnection(connection) {
16+
return connection.target === props.data.validTarget && connection.source === props.data.validSource
17+
}
1418
</script>
1519

1620
<script>
@@ -20,6 +24,6 @@ export default {
2024
</script>
2125

2226
<template>
23-
<Handle type="target" :position="Position.Left" :is-valid-connection="props.isValidSourcePos" />
27+
<Handle type="target" :position="Position.Left" :is-valid-connection="isValidConnection" />
2428
<div>{{ props.id }}</div>
2529
</template>

docs/src/examples/edges/validation.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ This function will be applied to *all* connections in the flow (even existing on
99
## Using a handle in a custom node
1010

1111
```vue
12-
<div>
13-
<!-- ... -->
14-
<Handle type="source" :is-valid-connection="isValidConnection"/>
15-
</div>
12+
<script setup>
13+
import { Handle, Position } from '@vue-flow/core'
14+
</script>
15+
16+
<template>
17+
<Handle type="source" :position="Position.Right" />
18+
<Handle type="target" :position="Position.Left" />
19+
</template>
1620
```
1721

1822
<div class="mt-6">

0 commit comments

Comments
 (0)