feat(core,nodes): implement a11y in nodes

Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
braks
2022-12-20 00:38:56 +01:00
committed by Braks
parent 0267b2f19e
commit 9f50dd0865
17 changed files with 167 additions and 35 deletions
+28 -2
View File
@@ -26,7 +26,8 @@ export function getDragItems(
.map((n) =>
markRaw({
id: n.id,
position: n.computedPosition || { x: 0, y: 0, z: 0 },
position: n.position || { x: 0, y: 0 },
computedPosition: n.computedPosition || { x: 0, y: 0, z: 1 },
distance: {
x: mousePos.x - n.computedPosition?.x || 0,
y: mousePos.y - n.computedPosition?.y || 0,
@@ -59,7 +60,7 @@ export function getEventHandlerParams({
return [id ? extendedDragItems.find((n) => n.id === id)! : extendedDragItems[0], extendedDragItems]
}
export function applyExtent<T extends NodeDragItem | GraphNode>(item: T, extent?: CoordinateExtent, parent?: GraphNode) {
export function getExtent<T extends NodeDragItem | GraphNode>(item: T, extent?: CoordinateExtent, parent?: GraphNode) {
let currentExtent = item.extent || extent
if (item.extent === 'parent') {
@@ -95,3 +96,28 @@ export function applyExtent<T extends NodeDragItem | GraphNode>(item: T, extent?
return currentExtent as CoordinateExtent
}
export const calcNextPosition = (
node: GraphNode | NodeDragItem,
nextPosition: XYPosition,
nodeExtent?: CoordinateExtent,
parentNode?: GraphNode,
) => {
const extent = getExtent(node, nodeExtent, parentNode)
const clampedPos = clampPosition(nextPosition, extent)
const parentPosition = { x: 0, y: 0 }
if (parentNode) {
parentPosition.x = parentNode.computedPosition.x
parentPosition.y = parentNode.computedPosition.y
}
return {
position: {
x: clampedPos.x - parentPosition.x,
y: clampedPos.y - parentPosition.y,
},
computedPosition: clampedPos,
}
}