* fix(core): calculate handle positions correctly Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> * fix(core): remove handleId check Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> * chore(core): cleanup Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> * chore(core): cleanup click connect handlers Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> * fix(core): add flow id to handle ids Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> * tests: correct updateEdge test Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> * fix(core): use center position of handle Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> * chore(examples): cleanup easy connect example Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> * refactor(tests): run actions on chrome Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> * chore(workflows): correctly hash lock file Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> --------- Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
import type { Ref } from 'vue'
|
|
import { nextTick } from 'vue'
|
|
import type { Actions, GraphNode, HandleElement, HandleType, Position } from '../types'
|
|
import { getDimensions } from '.'
|
|
|
|
export function getHandleBounds(
|
|
type: HandleType,
|
|
nodeElement: HTMLDivElement,
|
|
nodeBounds: DOMRect,
|
|
zoom: number,
|
|
): HandleElement[] {
|
|
const handles = nodeElement.querySelectorAll(`.vue-flow__handle.${type}`)
|
|
|
|
const handlesArray = Array.from(handles) as HTMLDivElement[]
|
|
|
|
return handlesArray.map((handle): HandleElement => {
|
|
const handleBounds = handle.getBoundingClientRect()
|
|
|
|
return {
|
|
id: handle.getAttribute('data-handleid'),
|
|
position: handle.getAttribute('data-handlepos') as unknown as Position,
|
|
nodeId: handle.getAttribute('data-nodeid') as string,
|
|
type,
|
|
x: (handleBounds.left - nodeBounds.left) / zoom,
|
|
y: (handleBounds.top - nodeBounds.top) / zoom,
|
|
...getDimensions(handle),
|
|
}
|
|
})
|
|
}
|
|
|
|
export function handleNodeClick(
|
|
node: GraphNode,
|
|
multiSelectionActive: boolean,
|
|
addSelectedNodes: Actions['addSelectedNodes'],
|
|
removeSelectedNodes: Actions['removeSelectedNodes'],
|
|
nodesSelectionActive: Ref<boolean>,
|
|
unselect = false,
|
|
nodeEl: HTMLDivElement,
|
|
) {
|
|
nodesSelectionActive.value = false
|
|
|
|
if (!node.selected) {
|
|
addSelectedNodes([node])
|
|
} else if (unselect || (node.selected && multiSelectionActive)) {
|
|
removeSelectedNodes([node])
|
|
|
|
nextTick(() => {
|
|
nodeEl.blur()
|
|
})
|
|
}
|
|
}
|