refactor(store)!: use stored node data when re-parsing elements
Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
+44
-30
@@ -163,40 +163,54 @@ export const pointToRendererPoint = (
|
||||
export const onLoadProject = (currentStore: FlowStore) => (position: XYPosition) =>
|
||||
pointToRendererPoint(position, currentStore.transform, currentStore.snapToGrid, currentStore.snapGrid)
|
||||
|
||||
export const parseNode = (node: Node, nodeExtent: CoordinateExtent, defaults?: Partial<GraphNode>): GraphNode => ({
|
||||
...defaults,
|
||||
...node,
|
||||
id: node.id.toString(),
|
||||
type: node.type ?? 'default',
|
||||
dimensions: {
|
||||
width: 0,
|
||||
height: 0,
|
||||
},
|
||||
handleBounds: {
|
||||
source: [],
|
||||
target: [],
|
||||
},
|
||||
computedPosition: {
|
||||
z: typeof node.style?.zIndex === 'string' ? parseInt(node.style?.zIndex) : node.style?.zIndex ?? 0,
|
||||
...clampPosition(node.position, nodeExtent),
|
||||
},
|
||||
isParent: !!(node.children && node.children.length),
|
||||
dragging: false,
|
||||
})
|
||||
export const parseNode = (node: Node, nodeExtent: CoordinateExtent, defaults?: Partial<GraphNode>): GraphNode => {
|
||||
defaults = !isGraphNode(node)
|
||||
? {
|
||||
type: node.type ?? 'default',
|
||||
dimensions: {
|
||||
width: 0,
|
||||
height: 0,
|
||||
},
|
||||
handleBounds: {
|
||||
source: [],
|
||||
target: [],
|
||||
},
|
||||
computedPosition: {
|
||||
z: typeof node.style?.zIndex === 'string' ? parseInt(node.style?.zIndex) : node.style?.zIndex ?? 0,
|
||||
...clampPosition(node.position, nodeExtent),
|
||||
},
|
||||
isParent: !!(node.children && node.children.length),
|
||||
dragging: false,
|
||||
...defaults,
|
||||
}
|
||||
: defaults
|
||||
return {
|
||||
...node,
|
||||
...(defaults as GraphNode),
|
||||
id: node.id.toString(),
|
||||
}
|
||||
}
|
||||
|
||||
export const parseEdge = (
|
||||
edge: Edge,
|
||||
defaults: Partial<GraphEdge> & { sourceNode: GraphNode; targetNode: GraphNode },
|
||||
): GraphEdge => ({
|
||||
...defaults,
|
||||
...edge,
|
||||
source: edge.source.toString(),
|
||||
target: edge.target.toString(),
|
||||
sourceHandle: edge.sourceHandle ? edge.sourceHandle.toString() : undefined,
|
||||
targetHandle: edge.targetHandle ? edge.targetHandle.toString() : undefined,
|
||||
id: edge.id.toString(),
|
||||
type: edge.type ?? 'default',
|
||||
})
|
||||
): GraphEdge => {
|
||||
defaults = !isGraphEdge(edge)
|
||||
? {
|
||||
sourceHandle: edge.sourceHandle ? edge.sourceHandle.toString() : undefined,
|
||||
targetHandle: edge.targetHandle ? edge.targetHandle.toString() : undefined,
|
||||
type: edge.type ?? 'default',
|
||||
source: edge.source.toString(),
|
||||
target: edge.target.toString(),
|
||||
...defaults,
|
||||
}
|
||||
: defaults
|
||||
return {
|
||||
...edge,
|
||||
...defaults,
|
||||
id: edge.id.toString(),
|
||||
}
|
||||
}
|
||||
|
||||
const getBoundsOfBoxes = (box1: Box, box2: Box): Box => ({
|
||||
x: Math.min(box1.x, box2.x),
|
||||
|
||||
Reference in New Issue
Block a user