fix(core): clamp node extent by node dimensions to avoid overflow (#1014)
This commit is contained in:
5
.changeset/perfect-kings-complain.md
Normal file
5
.changeset/perfect-kings-complain.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@vue-flow/core": patch
|
||||
---
|
||||
|
||||
Clamp node extent by node dimensions to avoid node overflowing the extent by its size
|
||||
@@ -1,6 +1,15 @@
|
||||
import { markRaw } from 'vue'
|
||||
import { ErrorCode, VueFlowError, clampPosition, isNumber, isParentSelected } from '.'
|
||||
import type { Actions, CoordinateExtent, CoordinateExtentRange, GraphNode, NodeDragItem, State, XYPosition } from '~/types'
|
||||
import type {
|
||||
Actions,
|
||||
CoordinateExtent,
|
||||
CoordinateExtentRange,
|
||||
Dimensions,
|
||||
GraphNode,
|
||||
NodeDragItem,
|
||||
State,
|
||||
XYPosition,
|
||||
} from '~/types'
|
||||
|
||||
export function hasSelector(target: Element, selector: string, node: Element): boolean {
|
||||
let current = target
|
||||
@@ -157,6 +166,11 @@ export function getExtent<T extends NodeDragItem | GraphNode>(
|
||||
|
||||
return currentExtent as CoordinateExtent
|
||||
}
|
||||
|
||||
function clampNodeExtent({ width, height }: Dimensions, extent: CoordinateExtent): CoordinateExtent {
|
||||
return [extent[0], [extent[1][0] - (width || 0), extent[1][1] - (height || 0)]]
|
||||
}
|
||||
|
||||
export function calcNextPosition(
|
||||
node: GraphNode | NodeDragItem,
|
||||
nextPosition: XYPosition,
|
||||
@@ -164,7 +178,7 @@ export function calcNextPosition(
|
||||
nodeExtent?: State['nodeExtent'],
|
||||
parentNode?: GraphNode,
|
||||
) {
|
||||
const extent = getExtent(node, onError, nodeExtent, parentNode)
|
||||
const extent = clampNodeExtent(node.dimensions, getExtent(node, onError, nodeExtent, parentNode))
|
||||
|
||||
const clampedPos = clampPosition(nextPosition, extent)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user