feat(general): add defaultNodes, defaultEdges and defaultEdgeOptions

This commit is contained in:
moklick
2022-01-18 13:05:41 +01:00
parent 660ec00be5
commit 634b592b3a
14 changed files with 364 additions and 60 deletions
+27
View File
@@ -2,10 +2,13 @@ import { zoomIdentity } from 'd3-zoom';
import { GetState } from 'zustand';
import {
CoordinateExtent,
Edge,
EdgeSelectionChange,
Node,
NodeDimensionChange,
NodeInternals,
NodeInternalsItem,
NodeSelectionChange,
ReactFlowState,
XYPosition,
XYZPosition,
@@ -163,3 +166,27 @@ export function fitView(get: GetState<ReactFlowState>) {
return fitViewOnInitDone;
}
export function handleControlledNodeSelectionChange(nodeChanges: NodeSelectionChange[], nodeInternals: NodeInternals) {
nodeChanges.forEach((change) => {
const node = nodeInternals.get(change.id);
if (node) {
nodeInternals.set(node.id, {
...node,
selected: change.selected,
});
}
});
return new Map(nodeInternals);
}
export function handleControlledEdgeSelectionChange(edgeChanges: EdgeSelectionChange[], edges: Edge[]) {
return edges.map((e) => {
const change = edgeChanges.find((change) => change.id === e.id);
if (change) {
e.selected = change.selected;
}
return e;
});
}