fix(nodeExtent): nodes node extent over global node extent

This commit is contained in:
moklick
2022-03-21 22:03:31 +01:00
parent 2e5e5285c5
commit 3d446a6adb
2 changed files with 18 additions and 12 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
import { CoordinateExtent, ReactFlowStore, ConnectionMode } from '../types';
const infiniteExtent: CoordinateExtent = [
export const infiniteExtent: CoordinateExtent = [
[Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY],
[Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY],
];
+17 -11
View File
@@ -16,6 +16,7 @@ import {
XYZPosition,
FitViewOptions,
} from '../types';
import { infiniteExtent } from './initialState';
type ParentNodes = Record<string, boolean>;
@@ -128,20 +129,25 @@ export function createPositionChange({
if (diff) {
const nextPosition = { x: node.position.x + diff.x, y: node.position.y + diff.y };
let currentExtent = nodeExtent || node.extent;
let currentExtent = node.extent || nodeExtent;
if (node.extent === 'parent' && node.parentNode && node.width && node.height) {
const parent = nodeInternals.get(node.parentNode);
currentExtent =
parent?.width && parent?.height
? [
[0, 0],
[parent.width - node.width, parent.height - node.height],
]
: currentExtent;
if (node.extent === 'parent') {
if (node.parentNode && node.width && node.height) {
const parent = nodeInternals.get(node.parentNode);
currentExtent =
parent?.width && parent?.height
? [
[0, 0],
[parent.width - node.width, parent.height - node.height],
]
: currentExtent;
} else {
console.warn('Only child nodes can use parent extent');
currentExtent = infiniteExtent;
}
}
change.position = currentExtent ? clampPosition(nextPosition, currentExtent) : nextPosition;
change.position = currentExtent ? clampPosition(nextPosition, currentExtent as CoordinateExtent) : nextPosition;
}
return change;