Skip to content

Commit

Permalink
fix: nodeposdiff not updating correctly on node selection
Browse files Browse the repository at this point in the history
  • Loading branch information
bcakmakoglu committed Oct 21, 2021
1 parent 5d3845b commit c062601
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions src/store/useFlowStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,28 +112,39 @@ export default function useFlowStore(preloadedState: FlowState): StoreDefinition
})
},
updateNodePosDiff({ id, diff, isDragging }) {
const i = this.nodes.map((x) => x.id || this.selectedElements?.find((sNode) => sNode.id === id)).indexOf(id)
const node = this.nodes[i]

const updatedNode = {
...node,
__rf: {
...node.__rf,
isDragging,
},
}
const update = (node: Node, i: number) => {
const updatedNode = {
...node,
__rf: {
...node.__rf,
isDragging,
},
}

if (diff) {
updatedNode.__rf.position = {
x: node.__rf.position.x + diff.x,
y: node.__rf.position.y + diff.y,
if (diff) {
updatedNode.__rf.position = {
x: node.__rf.position.x + diff.x,
y: node.__rf.position.y + diff.y,
}
}

this.nodes.splice(i, 1, {
...node,
...updatedNode,
})
}

this.nodes.splice(i, 1, {
...node,
...updatedNode,
})
if (!id) {
const selectedNodes = this.nodes.filter((x) => this.selectedElements?.find((sNode) => sNode.id === x.id))
selectedNodes.forEach((node) => {
const i = this.nodes.map((x) => x.id).indexOf((node as Node).id)
update(node as Node, i)
})
} else {
const i = this.nodes.map((x) => x.id).indexOf(id)
const node = this.nodes[i]
update(node, i)
}
},
setUserSelection(mousePos) {
this.selectionActive = true
Expand Down Expand Up @@ -181,6 +192,7 @@ export default function useFlowStore(preloadedState: FlowState): StoreDefinition
}
},
addSelectedElements(elements) {
console.log(elements)
const selectedElementsArr = Array.isArray(elements) ? elements : [elements]
const selectedElementsUpdated = !isEqual(selectedElementsArr, this.selectedElements)
this.selectedElements = selectedElementsUpdated ? selectedElementsArr : this.selectedElements
Expand Down

1 comment on commit c062601

@vercel
Copy link

@vercel vercel bot commented on c062601 Oct 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.