refactor(svelte): cleanup node options and props

This commit is contained in:
moklick
2023-03-02 15:31:37 +01:00
parent df6c3381b1
commit 33b9a801fe
15 changed files with 141 additions and 59 deletions
+37 -1
View File
@@ -1,4 +1,13 @@
import type { Dimensions, XYPosition, CoordinateExtent, Box, Rect, BaseNode, BaseEdge } from '@reactflow/system';
import type {
Dimensions,
XYPosition,
CoordinateExtent,
Box,
Rect,
BaseNode,
BaseEdge,
NodeOrigin,
} from '@reactflow/system';
import { getConnectedEdgesBase } from './graph';
export const getDimensions = (node: HTMLDivElement): Dimensions => ({
@@ -157,3 +166,30 @@ export function getElementsToRemove<NodeType extends BaseNode = BaseNode, EdgeTy
matchingNodes,
};
}
export const getPositionWithOrigin = ({
x,
y,
width,
height,
origin,
}: {
x: number;
y: number;
width: number;
height: number;
origin: NodeOrigin;
}): XYPosition => {
if (!width || !height) {
return { x, y };
}
if (origin[0] < 0 || origin[1] < 0 || origin[0] > 1 || origin[1] > 1) {
return { x, y };
}
return {
x: x - width * origin[0],
y: y - height * origin[1],
};
};