|
1 | 1 | <script lang="ts" setup> |
2 | | -import type { Elements } from '@vue-flow/core' |
3 | | -import { Panel, VueFlow, isNode, useVueFlow } from '@vue-flow/core' |
| 2 | +import type { Edge, Node, ValidConnectionFunc } from '@vue-flow/core' |
| 3 | +import { ConnectionMode, Panel, VueFlow, isNode, useVueFlow } from '@vue-flow/core' |
4 | 4 |
|
5 | 5 | import { Background } from '@vue-flow/background' |
6 | 6 | import { Controls } from '@vue-flow/controls' |
7 | 7 | import { MiniMap } from '@vue-flow/minimap' |
8 | 8 |
|
9 | | -const nodes = ref<Elements>([ |
| 9 | +const nodes = ref<Node[]>([ |
10 | 10 | { id: '1', type: 'input', label: 'Node 1', position: { x: 250, y: 5 }, class: 'light' }, |
11 | 11 | { id: '2', label: 'Node 2', position: { x: 100, y: 100 }, class: 'light' }, |
12 | 12 | { id: '3', label: 'Node 3', position: { x: 400, y: 100 }, class: 'light' }, |
13 | 13 | { id: '4', label: 'Node 4', position: { x: 400, y: 200 }, class: 'light' }, |
14 | 14 | ]) |
15 | 15 |
|
16 | | -const edges = ref<Elements>([ |
| 16 | +const edges = ref<Edge[]>([ |
17 | 17 | { id: 'e1-2', source: '1', target: '2', animated: true }, |
18 | 18 | { id: 'e1-3', source: '1', target: '3' }, |
19 | 19 | ]) |
@@ -45,32 +45,30 @@ function resetViewport() { |
45 | 45 | function toggleclass() { |
46 | 46 | return nodes.value.forEach((el) => (el.class = el.class === 'light' ? 'dark' : 'light')) |
47 | 47 | } |
| 48 | +
|
| 49 | +const isValidConnection: ValidConnectionFunc = (...args) => { |
| 50 | + console.log(args) |
| 51 | + return true |
| 52 | +} |
48 | 53 | </script> |
49 | 54 |
|
50 | 55 | <template> |
51 | 56 | <VueFlow |
52 | 57 | :nodes="nodes" |
53 | 58 | :edges="edges" |
54 | | - :delete-key-code="['Backspace', 'Delete']" |
| 59 | + :connection-mode="ConnectionMode.Strict" |
| 60 | + :is-valid-connection="isValidConnection" |
55 | 61 | fit-view-on-init |
56 | 62 | class="vue-flow-basic-example" |
57 | 63 | > |
58 | 64 | <Background /> |
59 | | - <MiniMap node-color="red" :nodes="nodes" :edges="edges" /> |
| 65 | + <MiniMap /> |
60 | 66 | <Controls /> |
61 | 67 | <Panel position="top-right" style="display: flex; gap: 5px"> |
62 | | - <input /> |
63 | 68 | <button @click="resetViewport">reset viewport</button> |
64 | 69 | <button @click="updatePos">change pos</button> |
65 | 70 | <button @click="toggleclass">toggle class</button> |
66 | 71 | <button @click="logToObject">toObject</button> |
67 | 72 | </Panel> |
68 | 73 | </VueFlow> |
69 | 74 | </template> |
70 | | - |
71 | | -<style> |
72 | | -.vue-flow__minimap { |
73 | | - transform: scale(75%); |
74 | | - transform-origin: bottom right; |
75 | | -} |
76 | | -</style> |
0 commit comments