UNPKG

@selenite/graph-editor

Version:

A graph editor for visual programming, based on rete and svelte.

34 lines (33 loc) 1.14 kB
import { getElementCenter } from 'rete-render-utils'; import { BaseSocketPosition } from './base-socket-position'; /** * Class for socket position calculation based on DOM elements. It uses `getElementCenter` function to calculate the position. */ export class DOMSocketPosition extends BaseSocketPosition { props; constructor(props) { super(); this.props = props; } async calculatePosition(nodeId, side, key, element) { const view = this.area?.nodeViews.get(nodeId); // console.debug('calculate position'); if (!view?.element) return null; const position = await getElementCenter(element, view.element); if (this.props?.offset) return this.props?.offset(position, nodeId, side, key); return { // x: position.x + 12 * (side === 'input' ? -1 : 1), x: position.x, y: position.y }; } } /** * Wrapper function for `DOMSocketPosition` class. * @param props Props for `DOMSocketPosition` class */ export function getDOMSocketPosition(props) { return new DOMSocketPosition(props); }