refactor(resizer): handle default nodes

This commit is contained in:
moklick
2022-12-04 15:18:32 +01:00
parent 8e43021050
commit 9da984f3e4
2 changed files with 10 additions and 1 deletions
+1
View File
@@ -22,6 +22,7 @@ export {
getNodePositionWithOrigin,
} from './utils/graph';
export { applyNodeChanges, applyEdgeChanges } from './utils/changes';
export { createNodeInternals } from './store/utils';
export { getMarkerEnd } from './components/Edges/utils';
export { default as ReactFlowProvider } from './components/ReactFlowProvider';
export { default as Panel } from './components/Panel';
+9 -1
View File
@@ -8,6 +8,8 @@ import {
NodeChange,
NodePositionChange,
NodeDimensionChange,
applyNodeChanges,
createNodeInternals,
} from '@reactflow/core';
import type { Dimensions, Node, XYPosition } from '@reactflow/core';
@@ -56,7 +58,7 @@ function ResizeControl({
nodeElementRef.current = document.querySelector(`.react-flow__node[data-id="${nodeId}"]`) as HTMLDivElement;
})
.on('drag', (event: ResizeDragEvent) => {
const { updateNodePositions, nodeInternals, onNodesChange } = store.getState();
const { updateNodePositions, nodeInternals, onNodesChange, hasDefaultNodes, nodeOrigin } = store.getState();
const pointerPos = getPointerPosition(event);
const nodeEl = nodeElementRef.current;
const node = nodeInternals.get(nodeId);
@@ -109,6 +111,12 @@ function ResizeControl({
}
if (changes.length) {
if (hasDefaultNodes) {
const nodes = applyNodeChanges(changes, Array.from(nodeInternals.values()));
const nextNodeInternals = createNodeInternals(nodes, nodeInternals, nodeOrigin);
store.setState({ nodeInternals: nextNodeInternals });
}
onNodesChange?.(changes);
}
}