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'; import { CoordinateExtent, ReactFlowStore, ConnectionMode } from '../types';
const infiniteExtent: CoordinateExtent = [ export const infiniteExtent: CoordinateExtent = [
[Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY], [Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY],
[Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY], [Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY],
]; ];
+17 -11
View File
@@ -16,6 +16,7 @@ import {
XYZPosition, XYZPosition,
FitViewOptions, FitViewOptions,
} from '../types'; } from '../types';
import { infiniteExtent } from './initialState';
type ParentNodes = Record<string, boolean>; type ParentNodes = Record<string, boolean>;
@@ -128,20 +129,25 @@ export function createPositionChange({
if (diff) { if (diff) {
const nextPosition = { x: node.position.x + diff.x, y: node.position.y + diff.y }; 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) { if (node.extent === 'parent') {
const parent = nodeInternals.get(node.parentNode); if (node.parentNode && node.width && node.height) {
currentExtent = const parent = nodeInternals.get(node.parentNode);
parent?.width && parent?.height currentExtent =
? [ parent?.width && parent?.height
[0, 0], ? [
[parent.width - node.width, parent.height - node.height], [0, 0],
] [parent.width - node.width, parent.height - node.height],
: currentExtent; ]
: 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; return change;