@@ -7,80 +7,78 @@ import { MiniMap } from '@vue-flow/minimap'
77
88import ColorSelectorNode from ' ./ColorSelectorNode.vue'
99
10- const elements = ref <Elements >([])
1110const bgColor = ref (' #1A192B' )
1211const connectionLineStyle = { stroke: ' #fff' }
1312const snapGrid: SnapGrid = [16 , 16 ]
1413
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 ) {
1660 if (n .type === ' input' ) return ' #0041d0'
1761 if (n .type === ' selectorNode' ) return bgColor .value
1862 if (n .type === ' output' ) return ' #ff0072'
1963 return ' #eee'
2064}
21- const nodeColor = (n : Node ): string => {
65+ function nodeColor(n : Node ) {
2266 if (n .type === ' selectorNode' ) return bgColor .value
2367 return ' #fff'
2468}
2569
26- const onChange = (event : Event ) => {
70+ function onChange(event : InputEvent ) {
2771 elements .value .forEach ((e ) => {
2872 if (isEdge (e ) || e .id !== ' 2' ) return e
2973 bgColor .value = (event .target as HTMLInputElement ).value
3074 })
3175}
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- })
7876 </script >
7977
8078<template >
8179 <VueFlow v-model =" elements" fit-view-on-init :style =" { backgroundColor: bgColor }" >
8280 <template #node-selectorNode =" props " >
83- <ColorSelectorNode v-bind =" props" />
81+ <ColorSelectorNode :data = " props.data " :parent-node =" props.parentNode " :position = " props.position " />
8482 </template >
8583 <MiniMap :node-stroke-color =" nodeStroke" :node-color =" nodeColor" />
8684 <Controls />
0 commit comments