fix(store): calc handle pos
This commit is contained in:
@@ -1,13 +1,4 @@
|
||||
import type {
|
||||
Transform,
|
||||
XYPosition,
|
||||
SnapGrid,
|
||||
Dimensions,
|
||||
NodeOrigin,
|
||||
HandleElement,
|
||||
Position,
|
||||
InternalNodeBase,
|
||||
} from '../types';
|
||||
import type { Transform, XYPosition, SnapGrid, Dimensions, HandleElement, Position } from '../types';
|
||||
import { snapPosition, pointToRendererPoint } from './general';
|
||||
|
||||
export type GetPointerPositionParams = {
|
||||
@@ -69,11 +60,9 @@ export const getEventPosition = (event: MouseEvent | TouchEvent, bounds?: DOMRec
|
||||
// unnecessary recalculations.
|
||||
export const getHandleBounds = (
|
||||
selector: string,
|
||||
node: InternalNodeBase,
|
||||
nodeElement: HTMLDivElement,
|
||||
nodeBounds: DOMRect,
|
||||
zoom: number,
|
||||
nodeOrigin: NodeOrigin = [0, 0]
|
||||
zoom: number
|
||||
): HandleElement[] | null => {
|
||||
const handles = nodeElement.querySelectorAll(selector);
|
||||
|
||||
@@ -81,22 +70,15 @@ export const getHandleBounds = (
|
||||
return null;
|
||||
}
|
||||
|
||||
const handlesArray = Array.from(handles) as HTMLDivElement[];
|
||||
|
||||
const nodeOffset = {
|
||||
x: nodeBounds.left + nodeBounds.width * nodeOrigin[0],
|
||||
y: nodeBounds.top + nodeBounds.height * nodeOrigin[1],
|
||||
};
|
||||
|
||||
return handlesArray.map((handle): HandleElement => {
|
||||
return Array.from(handles).map((handle): HandleElement => {
|
||||
const handleBounds = handle.getBoundingClientRect();
|
||||
|
||||
return {
|
||||
id: handle.getAttribute('data-handleid'),
|
||||
position: handle.getAttribute('data-handlepos') as unknown as Position,
|
||||
x: (handleBounds.left - nodeOffset.x) / zoom,
|
||||
y: (handleBounds.top - nodeOffset.y) / zoom,
|
||||
...getDimensions(handle),
|
||||
x: (handleBounds.left - nodeBounds.left) / zoom,
|
||||
y: (handleBounds.top - nodeBounds.top) / zoom,
|
||||
...getDimensions(handle as HTMLDivElement),
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
@@ -248,6 +248,7 @@ export function evaluateAbsolutePosition(
|
||||
nodeLookup: NodeLookup,
|
||||
nodeOrigin: NodeOrigin
|
||||
): XYPosition {
|
||||
let nextParentId: string | undefined = parentId;
|
||||
const positionAbsolute = { ...position };
|
||||
|
||||
while (nextParentId) {
|
||||
|
||||
@@ -283,11 +283,11 @@ export function updateNodeInternals<NodeType extends InternalNodeBase>(
|
||||
|
||||
if (doUpdate) {
|
||||
const nodeBounds = update.nodeElement.getBoundingClientRect();
|
||||
|
||||
|
||||
node.measured = dimensions;
|
||||
node.internals = {
|
||||
...node.internals,
|
||||
positionAbsolute,
|
||||
positionAbsolute: getNodePositionWithOrigin(node, nodeOrigin),
|
||||
handleBounds: {
|
||||
source: getHandleBounds('.source', update.nodeElement, nodeBounds, zoom),
|
||||
target: getHandleBounds('.target', update.nodeElement, nodeBounds, zoom),
|
||||
|
||||
Reference in New Issue
Block a user