fix(react): return user nodes for selection change handlers closes #3904

This commit is contained in:
moklick
2024-04-17 12:32:35 +02:00
parent 6181c2d472
commit fca0dd750f
@@ -14,10 +14,24 @@ type SelectionListenerProps = {
onSelectionChange?: OnSelectionChangeFunc; onSelectionChange?: OnSelectionChangeFunc;
}; };
const selector = (s: ReactFlowState) => ({ const selector = (s: ReactFlowState) => {
selectedNodes: Array.from(s.nodeLookup.values()).filter((n) => n.selected), const selectedNodes = [];
selectedEdges: s.edges.filter((e) => e.selected), const selectedEdges = [];
});
for (const [, node] of s.nodeLookup) {
if (node.selected) {
selectedNodes.push(node.internals.userNode);
}
}
for (const [, edge] of s.edgeLookup) {
if (edge.selected) {
selectedEdges.push(edge);
}
}
return { selectedNodes, selectedEdges };
};
type SelectorSlice = ReturnType<typeof selector>; type SelectorSlice = ReturnType<typeof selector>;