refactor(edgeRendererUtils): cleanup
This commit is contained in:
@@ -115,7 +115,7 @@ function renderEdge(
|
|||||||
targetPosition
|
targetPosition
|
||||||
);
|
);
|
||||||
|
|
||||||
const isSelected = selectedElements ? selectedElements.some((elm) => isEdge(elm) && elm.id === edge.id) : false;
|
const isSelected = selectedElements?.some((elm) => isEdge(elm) && elm.id === edge.id) || false;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<EdgeComponent
|
<EdgeComponent
|
||||||
|
|||||||
@@ -29,62 +29,42 @@ export function createEdgeTypes(edgeTypes: EdgeTypesType): EdgeTypesType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getHandlePosition(position: Position, node: Node, handle: any | null = null): XYPosition {
|
export function getHandlePosition(position: Position, node: Node, handle: any | null = null): XYPosition {
|
||||||
if (!handle) {
|
const x = handle?.x || 0;
|
||||||
switch (position) {
|
const y = handle?.y || 0;
|
||||||
case Position.Top:
|
const width = handle?.width || node.__rf.width;
|
||||||
return {
|
const height = handle?.height || node.__rf.height;
|
||||||
x: node.__rf.width / 2,
|
|
||||||
y: 0,
|
|
||||||
};
|
|
||||||
case Position.Right:
|
|
||||||
return {
|
|
||||||
x: node.__rf.width,
|
|
||||||
y: node.__rf.height / 2,
|
|
||||||
};
|
|
||||||
case Position.Bottom:
|
|
||||||
return {
|
|
||||||
x: node.__rf.width / 2,
|
|
||||||
y: node.__rf.height,
|
|
||||||
};
|
|
||||||
case Position.Left:
|
|
||||||
return {
|
|
||||||
x: 0,
|
|
||||||
y: node.__rf.height / 2,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (position) {
|
switch (position) {
|
||||||
case Position.Top:
|
case Position.Top:
|
||||||
return {
|
return {
|
||||||
x: handle.x + handle.width / 2,
|
x: x + width / 2,
|
||||||
y: handle.y,
|
y,
|
||||||
};
|
};
|
||||||
case Position.Right:
|
case Position.Right:
|
||||||
return {
|
return {
|
||||||
x: handle.x + handle.width,
|
x: x + width,
|
||||||
y: handle.y + handle.height / 2,
|
y: y + height / 2,
|
||||||
};
|
};
|
||||||
case Position.Bottom:
|
case Position.Bottom:
|
||||||
return {
|
return {
|
||||||
x: handle.x + handle.width / 2,
|
x: x + width / 2,
|
||||||
y: handle.y + handle.height,
|
y: y + height,
|
||||||
};
|
};
|
||||||
case Position.Left:
|
case Position.Left:
|
||||||
return {
|
return {
|
||||||
x: handle.x,
|
x,
|
||||||
y: handle.y + handle.height / 2,
|
y: y + height / 2,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getHandle(bounds: HandleElement[], handleId: ElementId | null): HandleElement | null | undefined {
|
export function getHandle(bounds: HandleElement[], handleId: ElementId | null): HandleElement | null {
|
||||||
let handle = null;
|
|
||||||
|
|
||||||
if (!bounds) {
|
if (!bounds) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let handle = null;
|
||||||
|
|
||||||
// there is no handleId when there are no multiple handles/ handles with ids
|
// there is no handleId when there are no multiple handles/ handles with ids
|
||||||
// so we just pick the first one
|
// so we just pick the first one
|
||||||
if (bounds.length === 1 || !handleId) {
|
if (bounds.length === 1 || !handleId) {
|
||||||
|
|||||||
Reference in New Issue
Block a user