chore(core): replace getNode with findNode

Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
braks
2023-01-18 20:47:32 +01:00
committed by Braks
parent 73de601f79
commit 203b4815f8
8 changed files with 114 additions and 151 deletions
+6 -20
View File
@@ -1,14 +1,6 @@
import type { Ref } from 'vue'
import { isNumber } from '@vueuse/shared'
import type {
ComputedGetters,
CoordinateExtent,
ExtendedParentExtent,
Getters,
GraphNode,
NodeDragItem,
XYPosition,
} from '~/types'
import type { Actions, CoordinateExtent, ExtendedParentExtent, GraphNode, NodeDragItem, XYPosition } from '~/types'
export function hasSelector(target: Element, selector: string, node: Ref<Element>): boolean {
let current = target
@@ -26,11 +18,11 @@ export function hasSelector(target: Element, selector: string, node: Ref<Element
export function getDragItems(
nodes: GraphNode[],
mousePos: XYPosition,
getNode: Getters['getNode'],
findNode: Actions['findNode'],
nodeId?: string,
): NodeDragItem[] {
return nodes
.filter((n) => (n.selected || n.id === nodeId) && (!n.parentNode || !isParentSelected(n, getNode)))
.filter((n) => (n.selected || n.id === nodeId) && (!n.parentNode || !isParentSelected(n, findNode)))
.map((n) =>
markRaw({
id: n.id,
@@ -50,19 +42,13 @@ export function getDragItems(
export function getEventHandlerParams({
id,
dragItems,
getNode,
findNode,
}: {
id?: string
dragItems: NodeDragItem[]
getNode: ComputedGetters['getNode']
findNode: Actions['findNode']
}): [GraphNode, GraphNode[]] {
const extendedDragItems: GraphNode[] = dragItems.map((n) => {
const node = getNode.value(n.id)!
return {
...node,
}
})
const extendedDragItems: GraphNode[] = dragItems.map((n) => findNode(n.id)!)
return [id ? extendedDragItems.find((n) => n.id === id)! : extendedDragItems[0], extendedDragItems]
}
+4 -4
View File
@@ -1,5 +1,6 @@
import { isString } from '@vueuse/core'
import type {
Actions,
Box,
Connection,
CoordinateExtent,
@@ -10,7 +11,6 @@ import type {
ElementData,
Elements,
FlowElement,
Getters,
GraphEdge,
GraphNode,
Node,
@@ -354,12 +354,12 @@ export const getXYZPos = (parentPos: XYZPosition, computedPosition: XYZPosition)
}
}
export const isParentSelected = (node: GraphNode, getNode: Getters['getNode']): boolean => {
export const isParentSelected = (node: GraphNode, findNode: Actions['findNode']): boolean => {
if (!node.parentNode) return false
const parent = getNode(node.parentNode)
const parent = findNode(node.parentNode)
if (!parent) return false
if (parent.selected) return true
return isParentSelected(parent, getNode)
return isParentSelected(parent, findNode)
}
export const getMarkerId = (marker: EdgeMarkerType | undefined, vueFlowId?: string): string => {
+4 -4
View File
@@ -1,4 +1,4 @@
import type { Connection, CoordinateExtent, Edge, Getters, GraphEdge, GraphNode, Node } from '~/types'
import type { Actions, Connection, CoordinateExtent, Edge, GraphEdge, GraphNode, Node } from '~/types'
export const isDef = <T>(val: T): val is NonNullable<T> => typeof unref(val) !== 'undefined'
@@ -51,7 +51,7 @@ export const updateEdgeAction = (edge: GraphEdge, newConnection: Connection, edg
export const createGraphNodes = (
nodes: Node[],
getNode: Getters['getNode'],
findNode: Actions['findNode'],
currGraphNodes: GraphNode[],
extent: CoordinateExtent,
) => {
@@ -59,7 +59,7 @@ export const createGraphNodes = (
const graphNodes = nodes.map((node) => {
const parsed = parseNode(node, extent, {
...getNode(node.id),
...findNode(node.id),
parentNode: node.parentNode,
})
@@ -80,7 +80,7 @@ export const createGraphNodes = (
if (parentNodes[node.id]) {
node.isParent = true
}
const parent = node.parentNode ? getNode(node.parentNode) : undefined
const parent = node.parentNode ? findNode(node.parentNode) : undefined
if (parent) parent.isParent = true
}
})