@@ -7,80 +7,78 @@ import { MiniMap } from '@vue-flow/minimap'
7
7
8
8
import ColorSelectorNode from ' ./ColorSelectorNode.vue'
9
9
10
- const elements = ref <Elements >([])
11
10
const bgColor = ref (' #1A192B' )
12
11
const connectionLineStyle = { stroke: ' #fff' }
13
12
const snapGrid: SnapGrid = [16 , 16 ]
14
13
15
- const nodeStroke = (n : Node ): string => {
14
+ const elements = ref <Elements >([
15
+ {
16
+ id: ' 1' ,
17
+ type: ' input' ,
18
+ label: ' An input node' ,
19
+ position: { x: 0 , y: 50 },
20
+ sourcePosition: Position .Right ,
21
+ },
22
+ {
23
+ id: ' 2' ,
24
+ type: ' selectorNode' ,
25
+ data: { onChange , color: bgColor },
26
+ style: { border: ' 1px solid #777' , padding: ' 10px' },
27
+ parentNode: ' 1' ,
28
+ position: { x: 250 , y: 50 },
29
+ },
30
+ {
31
+ id: ' 3' ,
32
+ type: ' output' ,
33
+ label: ' Output A' ,
34
+ position: { x: 650 , y: 25 },
35
+ targetPosition: Position .Left ,
36
+ },
37
+ {
38
+ id: ' 4' ,
39
+ type: ' output' ,
40
+ label: ' Output B' ,
41
+ position: { x: 650 , y: 100 },
42
+ targetPosition: Position .Left ,
43
+ },
44
+
45
+ { id: ' e1-2' , source: ' 1' , target: ' 2' , animated: true , style: { stroke: ' #fff' } },
46
+ { id: ' e2a-3' , source: ' 2' , sourceHandle: ' a' , target: ' 3' , animated: true , style: { stroke: ' #fff' } },
47
+ { id: ' e2b-4' , source: ' 2' , sourceHandle: ' b' , target: ' 4' , animated: true , style: { stroke: ' #fff' } },
48
+ ])
49
+
50
+ useVueFlow ({
51
+ connectionMode: ConnectionMode .Loose ,
52
+ connectionLineOptions: {
53
+ style: connectionLineStyle ,
54
+ },
55
+ snapToGrid: true ,
56
+ snapGrid ,
57
+ })
58
+
59
+ function nodeStroke(n : Node ) {
16
60
if (n .type === ' input' ) return ' #0041d0'
17
61
if (n .type === ' selectorNode' ) return bgColor .value
18
62
if (n .type === ' output' ) return ' #ff0072'
19
63
return ' #eee'
20
64
}
21
- const nodeColor = (n : Node ): string => {
65
+ function nodeColor(n : Node ) {
22
66
if (n .type === ' selectorNode' ) return bgColor .value
23
67
return ' #fff'
24
68
}
25
69
26
- const onChange = (event : Event ) => {
70
+ function onChange(event : InputEvent ) {
27
71
elements .value .forEach ((e ) => {
28
72
if (isEdge (e ) || e .id !== ' 2' ) return e
29
73
bgColor .value = (event .target as HTMLInputElement ).value
30
74
})
31
75
}
32
-
33
- onMounted (() => {
34
- elements .value = [
35
- {
36
- id: ' 1' ,
37
- type: ' input' ,
38
- label: ' An input node' ,
39
- position: { x: 0 , y: 50 },
40
- sourcePosition: Position .Right ,
41
- },
42
- {
43
- id: ' 2' ,
44
- type: ' selectorNode' ,
45
- data: { onChange , color: bgColor },
46
- style: { border: ' 1px solid #777' , padding: ' 10px' },
47
- position: { x: 250 , y: 50 },
48
- },
49
- {
50
- id: ' 3' ,
51
- type: ' output' ,
52
- label: ' Output A' ,
53
- position: { x: 650 , y: 25 },
54
- targetPosition: Position .Left ,
55
- },
56
- {
57
- id: ' 4' ,
58
- type: ' output' ,
59
- label: ' Output B' ,
60
- position: { x: 650 , y: 100 },
61
- targetPosition: Position .Left ,
62
- },
63
-
64
- { id: ' e1-2' , source: ' 1' , target: ' 2' , animated: true , style: { stroke: ' #fff' } },
65
- { id: ' e2a-3' , source: ' 2' , sourceHandle: ' a' , target: ' 3' , animated: true , style: { stroke: ' #fff' } },
66
- { id: ' e2b-4' , source: ' 2' , sourceHandle: ' b' , target: ' 4' , animated: true , style: { stroke: ' #fff' } },
67
- ]
68
- })
69
-
70
- useVueFlow ({
71
- connectionMode: ConnectionMode .Loose ,
72
- connectionLineOptions: {
73
- style: connectionLineStyle ,
74
- },
75
- snapToGrid: true ,
76
- snapGrid ,
77
- })
78
76
</script >
79
77
80
78
<template >
81
79
<VueFlow v-model =" elements" fit-view-on-init :style =" { backgroundColor: bgColor }" >
82
80
<template #node-selectorNode =" props " >
83
- <ColorSelectorNode v-bind =" props" />
81
+ <ColorSelectorNode :data = " props.data " :parent-node =" props.parentNode " :position = " props.position " />
84
82
</template >
85
83
<MiniMap :node-stroke-color =" nodeStroke" :node-color =" nodeColor" />
86
84
<Controls />
0 commit comments