refactor(react): use array for nodeInternals, rename to nodes

This commit is contained in:
moklick
2023-06-12 16:56:02 +02:00
parent cefdfd4e70
commit c6501aff62
33 changed files with 146 additions and 197 deletions
+3 -7
View File
@@ -33,13 +33,11 @@ export type GroupedEdges<EdgeType extends BaseEdge> = {
export function groupEdgesByZLevel<EdgeType extends BaseEdge>(
edges: EdgeType[],
nodes: Map<string, BaseNode> | BaseNode[],
nodes: BaseNode[],
elevateEdgesOnSelect = false
): GroupedEdges<EdgeType>[] {
let maxLevel = -1;
const isNodeInternals = 'get' in nodes;
const levelLookup = edges.reduce<Record<string, EdgeType[]>>((tree, edge) => {
const hasZIndex = isNumeric(edge.zIndex);
let z = hasZIndex ? edge.zIndex! : 0;
@@ -48,10 +46,8 @@ export function groupEdgesByZLevel<EdgeType extends BaseEdge>(
z = hasZIndex
? edge.zIndex!
: Math.max(
(isNodeInternals ? nodes.get(edge.source) : nodes.find((n) => n.id === edge.source))?.[internalsSymbol]
?.z || 0,
(isNodeInternals ? nodes.get(edge.target) : nodes.find((n) => n.id === edge.target))?.[internalsSymbol]
?.z || 0
nodes.find((n) => n.id === edge.source)?.[internalsSymbol]?.z || 0,
nodes.find((n) => n.id === edge.target)?.[internalsSymbol]?.z || 0
);
}