refactored updateNodePositions in svelte
This commit is contained in:
@@ -63,29 +63,23 @@ export function createStore({
|
|||||||
store.edges.set(addEdgeUtil(edgeParams, edges));
|
store.edges.set(addEdgeUtil(edgeParams, edges));
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateNodePositions: UpdateNodePositions = (nodeDragItems, dragging = false) => {
|
const updateNodePositions: UpdateNodePositions = (nodeDragItems, _, dragging = false) => {
|
||||||
store.nodes.update((nds) => {
|
const nodeLookup = get(store.nodeLookup);
|
||||||
return nds.map((node) => {
|
|
||||||
const nodeDragItem = (nodeDragItems as Array<Node | NodeDragItem>).find(
|
|
||||||
(ndi) => ndi.id === node.id
|
|
||||||
);
|
|
||||||
|
|
||||||
if (nodeDragItem) {
|
nodeDragItems.forEach((nodeDragItem) => {
|
||||||
return {
|
const node = nodeLookup.get(nodeDragItem.id);
|
||||||
...node,
|
|
||||||
dragging,
|
|
||||||
position: nodeDragItem.position,
|
|
||||||
computed: {
|
|
||||||
...node.computed,
|
|
||||||
positionAbsolute: nodeDragItem.computed?.positionAbsolute
|
|
||||||
},
|
|
||||||
[internalsSymbol]: node[internalsSymbol]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return node;
|
if (node) {
|
||||||
});
|
node.position = nodeDragItem.position;
|
||||||
|
node.dragging = dragging;
|
||||||
|
node.computed = {
|
||||||
|
...node.computed,
|
||||||
|
positionAbsolute: nodeDragItem.computed?.positionAbsolute
|
||||||
|
};
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
store.nodes.set(get(store.nodes));
|
||||||
};
|
};
|
||||||
|
|
||||||
function updateNodeDimensions(updates: Map<string, NodeDimensionUpdate>) {
|
function updateNodeDimensions(updates: Map<string, NodeDimensionUpdate>) {
|
||||||
|
|||||||
Reference in New Issue
Block a user