feat(nodes): Add PositionFunc as node position type

* Allows position to be set relative to another node
This commit is contained in:
Braks
2022-04-11 11:30:10 +02:00
parent 342d0305a6
commit 1e9cbc0643
3 changed files with 41 additions and 27 deletions
+7 -1
View File
@@ -99,10 +99,16 @@ const createGraphNodes = (nodes: Node[], getNode: Getters['getNode'], currGraphN
})
graphNodes.forEach((node) => {
if (node.parentNode && ![...graphNodes, ...currGraphNodes].find((n) => n.id === node.parentNode)) {
const nextNodes = [...graphNodes, ...currGraphNodes]
if (node.parentNode && !nextNodes.find((n) => n.id === node.parentNode)) {
console.warn(`[vueflow]: Parent node ${node.parentNode} not found`)
}
const position =
(<any>node).position instanceof Function
? (<any>node).position(node, currGraphNodes, node.parentNode ? getNode(node.parentNode) : undefined)
: node.position
if (position) node.position = position
if (node.parentNode || parentNodes[node.id]) {
if (parentNodes[node.id]) {
node.isParent = true