Skip to content

Commit 82e79a6

Browse files
committed
fix(core): clamp node extent by node dimensions to avoid overflow (#1014)
1 parent 6967067 commit 82e79a6

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@vue-flow/core": patch
3+
---
4+
5+
Clamp node extent by node dimensions to avoid node overflowing the extent by its size

packages/core/src/utils/drag.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import { markRaw } from 'vue'
22
import { ErrorCode, VueFlowError, clampPosition, isNumber, isParentSelected } from '.'
3-
import type { Actions, CoordinateExtent, CoordinateExtentRange, GraphNode, NodeDragItem, State, XYPosition } from '~/types'
3+
import type {
4+
Actions,
5+
CoordinateExtent,
6+
CoordinateExtentRange,
7+
Dimensions,
8+
GraphNode,
9+
NodeDragItem,
10+
State,
11+
XYPosition,
12+
} from '~/types'
413

514
export function hasSelector(target: Element, selector: string, node: Element): boolean {
615
let current = target
@@ -157,14 +166,19 @@ export function getExtent<T extends NodeDragItem | GraphNode>(
157166

158167
return currentExtent as CoordinateExtent
159168
}
169+
170+
function clampNodeExtent({ width, height }: Dimensions, extent: CoordinateExtent): CoordinateExtent {
171+
return [extent[0], [extent[1][0] - (width || 0), extent[1][1] - (height || 0)]]
172+
}
173+
160174
export function calcNextPosition(
161175
node: GraphNode | NodeDragItem,
162176
nextPosition: XYPosition,
163177
onError: State['hooks']['error']['trigger'],
164178
nodeExtent?: State['nodeExtent'],
165179
parentNode?: GraphNode,
166180
) {
167-
const extent = getExtent(node, onError, nodeExtent, parentNode)
181+
const extent = clampNodeExtent(node.dimensions, getExtent(node, onError, nodeExtent, parentNode))
168182

169183
const clampedPos = clampPosition(nextPosition, extent)
170184

0 commit comments

Comments
 (0)