chore(utils): cleanup
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { HandleType } from './types';
|
import { CoordinateExtent, HandleType } from './types';
|
||||||
|
|
||||||
// @todo: update URLs to xyflow
|
// @todo: update URLs to xyflow
|
||||||
export const errorMessages = {
|
export const errorMessages = {
|
||||||
@@ -24,3 +24,8 @@ export const errorMessages = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const internalsSymbol = Symbol.for('internals');
|
export const internalsSymbol = Symbol.for('internals');
|
||||||
|
|
||||||
|
export const infiniteExtent: CoordinateExtent = [
|
||||||
|
[Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY],
|
||||||
|
[Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY],
|
||||||
|
];
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
isNumeric,
|
isNumeric,
|
||||||
rectToBox,
|
rectToBox,
|
||||||
nodeToRect,
|
nodeToRect,
|
||||||
|
getEventPosition,
|
||||||
} from './utils';
|
} from './utils';
|
||||||
import {
|
import {
|
||||||
type Connection,
|
type Connection,
|
||||||
@@ -334,8 +335,7 @@ export function getPointerPosition(
|
|||||||
event: MouseEvent | TouchEvent,
|
event: MouseEvent | TouchEvent,
|
||||||
{ snapGrid = [0, 0], snapToGrid = false, transform }: GetPointerPositionParams
|
{ snapGrid = [0, 0], snapToGrid = false, transform }: GetPointerPositionParams
|
||||||
): XYPosition & { xSnapped: number; ySnapped: number } {
|
): XYPosition & { xSnapped: number; ySnapped: number } {
|
||||||
const x = 'touches' in event ? event.touches[0].clientX : event.clientX;
|
const { x, y } = getEventPosition(event);
|
||||||
const y = 'touches' in event ? event.touches[0].clientY : event.clientY;
|
|
||||||
|
|
||||||
const pointerPos = {
|
const pointerPos = {
|
||||||
x: (x - transform[0]) / transform[2],
|
x: (x - transform[0]) / transform[2],
|
||||||
|
|||||||
@@ -128,9 +128,9 @@ export function isInputDOMNode(event: KeyboardEvent): boolean {
|
|||||||
export const isMouseEvent = (event: MouseEvent | TouchEvent): event is MouseEvent => 'clientX' in event;
|
export const isMouseEvent = (event: MouseEvent | TouchEvent): event is MouseEvent => 'clientX' in event;
|
||||||
|
|
||||||
export const getEventPosition = (event: MouseEvent | TouchEvent, bounds?: DOMRect) => {
|
export const getEventPosition = (event: MouseEvent | TouchEvent, bounds?: DOMRect) => {
|
||||||
const isMouseTriggered = isMouseEvent(event);
|
const isMouse = isMouseEvent(event);
|
||||||
const evtX = isMouseTriggered ? event.clientX : event.touches?.[0].clientX;
|
const evtX = isMouse ? event.clientX : event.touches?.[0].clientX;
|
||||||
const evtY = isMouseTriggered ? event.clientY : event.touches?.[0].clientY;
|
const evtY = isMouse ? event.clientY : event.touches?.[0].clientY;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
x: evtX - (bounds?.left ?? 0),
|
x: evtX - (bounds?.left ?? 0),
|
||||||
@@ -138,11 +138,6 @@ export const getEventPosition = (event: MouseEvent | TouchEvent, bounds?: DOMRec
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const infiniteExtent: CoordinateExtent = [
|
|
||||||
[Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY],
|
|
||||||
[Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY],
|
|
||||||
];
|
|
||||||
|
|
||||||
// helper function to get arrays of nodes and edges that can be deleted
|
// helper function to get arrays of nodes and edges that can be deleted
|
||||||
// you can pass in a list of nodes and edges that should be deleted
|
// you can pass in a list of nodes and edges that should be deleted
|
||||||
// and the function only returns elements that are deletable and also handles connected nodes and child nodes
|
// and the function only returns elements that are deletable and also handles connected nodes and child nodes
|
||||||
|
|||||||
Reference in New Issue
Block a user