|
@@ -3,9 +3,9 @@
|
|
<div>
|
|
<div>
|
|
fn:
|
|
fn:
|
|
<button
|
|
<button
|
|
- :key="i"
|
|
|
|
- v-for="(r,k,i) of nodeData.registry"
|
|
|
|
- @click="nodeAdd(r)">
|
|
|
|
|
|
+ :key="k"
|
|
|
|
+ v-for="(r,k) of registry"
|
|
|
|
+ @click="nodeAdd(k)">
|
|
{{ k }}
|
|
{{ k }}
|
|
</button>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
@@ -16,12 +16,12 @@
|
|
:height="height">
|
|
:height="height">
|
|
<flow-pan-zoom
|
|
<flow-pan-zoom
|
|
ref="panzoom"
|
|
ref="panzoom"
|
|
- v-model="nodeData.panzoom">
|
|
|
|
|
|
+ v-model="panzoom">
|
|
<flow-link
|
|
<flow-link
|
|
v-for="(l,i) in nodeData.links"
|
|
v-for="(l,i) in nodeData.links"
|
|
:key="i"
|
|
:key="i"
|
|
v-bind="linkProps(l)"
|
|
v-bind="linkProps(l)"
|
|
- @click="removeLink(i)"
|
|
|
|
|
|
+ @click="linkRemove(i)"
|
|
/>
|
|
/>
|
|
<!-- mouse link-->
|
|
<!-- mouse link-->
|
|
<flow-link
|
|
<flow-link
|
|
@@ -42,7 +42,7 @@
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</template>
|
|
<script>
|
|
<script>
|
|
-import nodeData from '../nodedata'
|
|
|
|
|
|
+// import nodeData from '../nodedata'
|
|
import FlowNode from './node'
|
|
import FlowNode from './node'
|
|
import FlowLink from './link'
|
|
import FlowLink from './link'
|
|
import FlowPanZoom from './panzoom'
|
|
import FlowPanZoom from './panzoom'
|
|
@@ -51,12 +51,16 @@ export default {
|
|
name: 'FlowManager',
|
|
name: 'FlowManager',
|
|
components: {FlowNode, FlowLink, FlowPanZoom},
|
|
components: {FlowNode, FlowLink, FlowPanZoom},
|
|
props: {
|
|
props: {
|
|
|
|
+ 'value': {type: Object, default: () => {}},
|
|
|
|
+ 'registry': {type: Object, default: () => {}},
|
|
'width': {type: String, default: '800px'},
|
|
'width': {type: String, default: '800px'},
|
|
'height': {type: String, default: '600px'}
|
|
'height': {type: String, default: '600px'}
|
|
},
|
|
},
|
|
data () {
|
|
data () {
|
|
|
|
+ const cloned = JSON.parse(JSON.stringify(this.value)) // initial?
|
|
return {
|
|
return {
|
|
- nodeData: nodeData,
|
|
|
|
|
|
+ panzoom: { x: 0, y: 0, zoom: 1 },
|
|
|
|
+ nodeData: cloned,
|
|
pointerLink: {active: false, props: {}, src: {}}
|
|
pointerLink: {active: false, props: {}, src: {}}
|
|
}
|
|
}
|
|
},
|
|
},
|
|
@@ -71,7 +75,7 @@ export default {
|
|
match = {in: this.pointerLink.src.type}
|
|
match = {in: this.pointerLink.src.type}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- const nodeClass = this.nodeData.registry[node.src]
|
|
|
|
|
|
+ const nodeClass = this.registry[node.src]
|
|
return {
|
|
return {
|
|
transform: `translate(${node.x} ${node.y})`,
|
|
transform: `translate(${node.x} ${node.y})`,
|
|
id: node.id,
|
|
id: node.id,
|
|
@@ -108,6 +112,17 @@ export default {
|
|
}
|
|
}
|
|
|
|
|
|
},
|
|
},
|
|
|
|
+ watch: {
|
|
|
|
+ value: {
|
|
|
|
+ handler (val) {
|
|
|
|
+ this.nodeData = JSON.parse(JSON.stringify(this.value)) // deepClone
|
|
|
|
+ this.$nextTick(() => {
|
|
|
|
+ this.$forceUpdate()
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+ deep: true
|
|
|
|
+ }
|
|
|
|
+ },
|
|
mounted () {
|
|
mounted () {
|
|
this.$nextTick(() => {
|
|
this.$nextTick(() => {
|
|
this.$forceUpdate()
|
|
this.$forceUpdate()
|
|
@@ -141,9 +156,9 @@ export default {
|
|
|
|
|
|
this.pointerLink.active = true
|
|
this.pointerLink.active = true
|
|
if (isInput) {
|
|
if (isInput) {
|
|
- this.pointerLink.src = {nodeId: nodeId, type: this.nodeData.registry[node.src].inputs[socket.in], in: socket.in}
|
|
|
|
|
|
+ this.pointerLink.src = {nodeId: nodeId, type: this.registry[node.src].inputs[socket.in], in: socket.in}
|
|
} else {
|
|
} else {
|
|
- this.pointerLink.src = {nodeId: nodeId, type: this.nodeData.registry[node.src].output, out: 0}
|
|
|
|
|
|
+ this.pointerLink.src = {nodeId: nodeId, type: this.registry[node.src].output, out: 0}
|
|
}
|
|
}
|
|
|
|
|
|
// What socket is this
|
|
// What socket is this
|
|
@@ -194,8 +209,8 @@ export default {
|
|
const nodeFrom = this.nodeData.nodes.find(n => n.id === link.from)
|
|
const nodeFrom = this.nodeData.nodes.find(n => n.id === link.from)
|
|
const nodeTo = this.nodeData.nodes.find(n => n.id === link.to)
|
|
const nodeTo = this.nodeData.nodes.find(n => n.id === link.to)
|
|
// Type checking
|
|
// Type checking
|
|
- if (this.nodeData.registry[ nodeFrom.src ].output !==
|
|
|
|
- this.nodeData.registry[ nodeTo.src ].inputs[link.in]) {
|
|
|
|
|
|
+ if (this.registry[ nodeFrom.src ].output !==
|
|
|
|
+ this.registry[ nodeTo.src ].inputs[link.in]) {
|
|
console.error('LINK: Invalid type')
|
|
console.error('LINK: Invalid type')
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -209,6 +224,7 @@ export default {
|
|
}
|
|
}
|
|
|
|
|
|
this.nodeData.links.push(link)
|
|
this.nodeData.links.push(link)
|
|
|
|
+ this.$emit('input', this.nodeData)
|
|
}
|
|
}
|
|
document.addEventListener('mousemove', drag)
|
|
document.addEventListener('mousemove', drag)
|
|
document.addEventListener('mouseup', drop)
|
|
document.addEventListener('mouseup', drop)
|
|
@@ -220,6 +236,7 @@ export default {
|
|
// remove related links
|
|
// remove related links
|
|
this.nodeData.links = this.nodeData.links.filter(l => l.from !== tnode.id && l.to !== tnode.id)
|
|
this.nodeData.links = this.nodeData.links.filter(l => l.from !== tnode.id && l.to !== tnode.id)
|
|
this.nodeData.nodes.splice(i, 1)
|
|
this.nodeData.nodes.splice(i, 1)
|
|
|
|
+ this.$emit('input', this.nodeData)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
if (e.button !== 0) return // first button
|
|
if (e.button !== 0) return // first button
|
|
@@ -236,16 +253,18 @@ export default {
|
|
const point = this.transformedPoint(e.clientX, e.clientY)
|
|
const point = this.transformedPoint(e.clientX, e.clientY)
|
|
tnode.x = point.x - delta.x
|
|
tnode.x = point.x - delta.x
|
|
tnode.y = point.y - delta.y
|
|
tnode.y = point.y - delta.y
|
|
|
|
+ // Bad possibly
|
|
|
|
+ this.$emit('input', this.nodeData)
|
|
}
|
|
}
|
|
const drop = (e) => {
|
|
const drop = (e) => {
|
|
document.removeEventListener('mousemove', drag)
|
|
document.removeEventListener('mousemove', drag)
|
|
document.removeEventListener('mouseup', drop)
|
|
document.removeEventListener('mouseup', drop)
|
|
|
|
+ this.$emit('input', this.nodeData)
|
|
}
|
|
}
|
|
document.addEventListener('mousemove', drag)
|
|
document.addEventListener('mousemove', drag)
|
|
document.addEventListener('mouseup', drop)
|
|
document.addEventListener('mouseup', drop)
|
|
},
|
|
},
|
|
nodeAdd (k) {
|
|
nodeAdd (k) {
|
|
- console.log('Adding:', k)
|
|
|
|
this.nodeData.nodes.push({
|
|
this.nodeData.nodes.push({
|
|
id: guid(),
|
|
id: guid(),
|
|
x: 100,
|
|
x: 100,
|
|
@@ -253,10 +272,13 @@ export default {
|
|
label: k,
|
|
label: k,
|
|
src: k
|
|
src: k
|
|
})
|
|
})
|
|
|
|
+ this.$emit('input', this.nodeData)
|
|
},
|
|
},
|
|
- removeLink (i) {
|
|
|
|
|
|
+ linkRemove (i) {
|
|
this.nodeData.links.splice(i, 1)
|
|
this.nodeData.links.splice(i, 1)
|
|
|
|
+ this.$emit('input', this.nodeData)
|
|
},
|
|
},
|
|
|
|
+
|
|
createSVGPoint (x, y) {
|
|
createSVGPoint (x, y) {
|
|
const p = this.$refs.svg.createSVGPoint()
|
|
const p = this.$refs.svg.createSVGPoint()
|
|
p.x = x; p.y = y
|
|
p.x = x; p.y = y
|