|
1 | 1 | import { markRaw } from 'vue' |
2 | 2 | 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' |
4 | 13 |
|
5 | 14 | export function hasSelector(target: Element, selector: string, node: Element): boolean { |
6 | 15 | let current = target |
@@ -157,14 +166,19 @@ export function getExtent<T extends NodeDragItem | GraphNode>( |
157 | 166 |
|
158 | 167 | return currentExtent as CoordinateExtent |
159 | 168 | } |
| 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 | + |
160 | 174 | export function calcNextPosition( |
161 | 175 | node: GraphNode | NodeDragItem, |
162 | 176 | nextPosition: XYPosition, |
163 | 177 | onError: State['hooks']['error']['trigger'], |
164 | 178 | nodeExtent?: State['nodeExtent'], |
165 | 179 | parentNode?: GraphNode, |
166 | 180 | ) { |
167 | | - const extent = getExtent(node, onError, nodeExtent, parentNode) |
| 181 | + const extent = clampNodeExtent(node.dimensions, getExtent(node, onError, nodeExtent, parentNode)) |
168 | 182 |
|
169 | 183 | const clampedPos = clampPosition(nextPosition, extent) |
170 | 184 |
|
|
0 commit comments