refactor(internals): use non enumerable props
This commit is contained in:
+2
-2
@@ -1,7 +1,7 @@
|
||||
import create from 'zustand';
|
||||
import createContext from 'zustand/context';
|
||||
|
||||
import { clampPosition, getDimensions } from '../utils';
|
||||
import { clampPosition, getDimensions, handleBoundsSymbol } from '../utils';
|
||||
import { applyNodeChanges } from '../utils/changes';
|
||||
import {
|
||||
ReactFlowState,
|
||||
@@ -60,7 +60,7 @@ const createStore = () =>
|
||||
const handleBounds = getHandleBounds(update.nodeElement, transform[2]);
|
||||
nodeInternals.set(node.id, {
|
||||
...node,
|
||||
handleBounds,
|
||||
[handleBoundsSymbol]: handleBounds,
|
||||
...dimensions,
|
||||
});
|
||||
|
||||
|
||||
+17
-7
@@ -1,7 +1,7 @@
|
||||
import { zoomIdentity } from 'd3-zoom';
|
||||
import { GetState, SetState } from 'zustand';
|
||||
|
||||
import { isNumeric } from '../utils';
|
||||
import { handleBoundsSymbol, isNumeric, isParentSymbol, zSymbol } from '../utils';
|
||||
import { getD3Transition, getRectOfNodes, getTransformForBounds } from '../utils/graph';
|
||||
import {
|
||||
Edge,
|
||||
@@ -30,7 +30,7 @@ function calculateXYZPosition(
|
||||
return calculateXYZPosition(parentNode, nodeInternals, parentNodes, {
|
||||
x: (result.x ?? 0) + (parentNode.position?.x ?? 0),
|
||||
y: (result.y ?? 0) + (parentNode.position?.y ?? 0),
|
||||
z: (parentNode.z ?? 0) > (result.z ?? 0) ? parentNode.z ?? 0 : result.z ?? 0,
|
||||
z: (parentNode[zSymbol] ?? 0) > (result.z ?? 0) ? parentNode[zSymbol] ?? 0 : result.z ?? 0,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -45,18 +45,28 @@ export function createNodeInternals(nodes: Node[], nodeInternals: NodeInternals)
|
||||
const internals: Node = {
|
||||
width: currInternals?.width,
|
||||
height: currInternals?.height,
|
||||
handleBounds: currInternals?.handleBounds,
|
||||
...node,
|
||||
positionAbsolute: {
|
||||
x: node.position.x,
|
||||
y: node.position.y,
|
||||
},
|
||||
z,
|
||||
};
|
||||
|
||||
if (node.parentNode) {
|
||||
internals.parentNode = node.parentNode;
|
||||
parentNodes[node.parentNode] = true;
|
||||
}
|
||||
|
||||
Object.defineProperty(internals, handleBoundsSymbol, {
|
||||
enumerable: false,
|
||||
value: currInternals?.[handleBoundsSymbol],
|
||||
});
|
||||
|
||||
Object.defineProperty(internals, zSymbol, {
|
||||
enumerable: false,
|
||||
value: z,
|
||||
});
|
||||
|
||||
nextNodeInternals.set(node.id, internals);
|
||||
});
|
||||
|
||||
@@ -68,7 +78,7 @@ export function createNodeInternals(nodes: Node[], nodeInternals: NodeInternals)
|
||||
if (node.parentNode || parentNodes[node.id]) {
|
||||
const { x, y, z } = calculateXYZPosition(node, nextNodeInternals, parentNodes, {
|
||||
...node.position,
|
||||
z: node.z ?? 0,
|
||||
z: node[zSymbol] ?? 0,
|
||||
});
|
||||
|
||||
node.positionAbsolute = {
|
||||
@@ -76,10 +86,10 @@ export function createNodeInternals(nodes: Node[], nodeInternals: NodeInternals)
|
||||
y,
|
||||
};
|
||||
|
||||
node.z = z;
|
||||
node[zSymbol] = z;
|
||||
|
||||
if (parentNodes[node.id]) {
|
||||
node.isParent = true;
|
||||
node[isParentSymbol] = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user