From b9bb3cfb1a64f7b8ff2059c4d50573c96e8af327 Mon Sep 17 00:00:00 2001
From: Braks <78412429+bcakmakoglu@users.noreply.github.com>
Date: Mon, 22 Nov 2021 17:14:57 +0100
Subject: [PATCH] update(types): remove null types and use undefined
Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
---
src/components/Edges/EdgeWrapper.vue | 23 ++++++++++++++++++-----
src/container/VueFlow/VueFlow.vue | 2 ++
src/types/components.ts | 6 +++---
src/types/connection.ts | 8 ++++----
src/types/edge.ts | 4 ++--
src/types/node.ts | 4 ++--
src/utils/edge.ts | 4 ++--
src/utils/graph.ts | 8 ++++----
src/utils/node.ts | 6 +++---
9 files changed, 40 insertions(+), 25 deletions(-)
diff --git a/src/components/Edges/EdgeWrapper.vue b/src/components/Edges/EdgeWrapper.vue
index 743fafef..ca14ddd8 100644
--- a/src/components/Edges/EdgeWrapper.vue
+++ b/src/components/Edges/EdgeWrapper.vue
@@ -10,8 +10,9 @@ import {
SourceTargetNode,
Position,
FlowEvents,
+ EdgePositions,
} from '../../types'
-import { isEdge, getEdgePositions, getHandle } from '../../utils'
+import { isEdge, getEdgePositions, getHandle, isEdgeVisible } from '../../utils'
import EdgeAnchor from './EdgeAnchor.vue'
interface EdgeWrapper {
@@ -22,8 +23,8 @@ interface EdgeWrapper {
component?: any
source: ElementId
target: ElementId
- sourceHandle?: ElementId | null
- targetHandle?: ElementId | null
+ sourceHandle?: ElementId
+ targetHandle?: ElementId
selected?: boolean
sourcePosition?: Position
targetPosition?: Position
@@ -153,12 +154,12 @@ const sourceHandle = controlledComputed(
() => props.sourceTargetNodes,
() => {
if (props.sourceTargetNodes.sourceNode && props.sourceTargetNodes.sourceNode.__vf.handleBounds.source)
- return getHandle(props.sourceTargetNodes.sourceNode.__vf.handleBounds.source, props.sourceHandle ?? null)
+ return getHandle(props.sourceTargetNodes.sourceNode.__vf.handleBounds.source, props.sourceHandle)
else return null
},
)
const targetHandle = computed(() => {
- if (targetNodeHandles.value) return getHandle(targetNodeHandles.value, props.targetHandle ?? null)
+ if (targetNodeHandles.value) return getHandle(targetNodeHandles.value, props.targetHandle)
else return null
})
const sourcePosition = eagerComputed(() => (sourceHandle.value ? sourceHandle.value.position : Position.Bottom))
@@ -178,6 +179,17 @@ const edgePos = computed(() =>
targetPosition.value,
),
)
+
+const isVisible = ({ sourceX, sourceY, targetX, targetY }: EdgePositions) =>
+ store.onlyRenderVisibleElements
+ ? isEdgeVisible({
+ sourcePos: { x: sourceX, y: sourceY },
+ targetPos: { x: targetX, y: targetY },
+ width: store.dimensions.width,
+ height: store.dimensions.height,
+ transform: store.transform,
+ })
+ : true
{
:connection-line-style="store.connectionLineStyle"
:arrow-head-color="store.arrowHeadColor"
:marker-end-id="store.markerEndId"
+ :only-render-visible-elements="store.onlyRenderVisibleElements"
>
+ props?: any
}
labelStyle?: CSSProperties
labelShowBg?: boolean
diff --git a/src/types/connection.ts b/src/types/connection.ts
index 1a929f0c..0b613e3c 100644
--- a/src/types/connection.ts
+++ b/src/types/connection.ts
@@ -9,10 +9,10 @@ export enum ConnectionLineType {
}
export interface Connection {
- source: ElementId | null
- target: ElementId | null
- sourceHandle: ElementId | null
- targetHandle: ElementId | null
+ source: ElementId
+ target: ElementId
+ sourceHandle: ElementId
+ targetHandle: ElementId
}
export type ConnectionLineProps = {
diff --git a/src/types/edge.ts b/src/types/edge.ts
index eb6cbf0e..52922c96 100644
--- a/src/types/edge.ts
+++ b/src/types/edge.ts
@@ -7,8 +7,8 @@ export interface Edge {
type?: string
source: ElementId
target: ElementId
- sourceHandle?: ElementId | null
- targetHandle?: ElementId | null
+ sourceHandle?: ElementId
+ targetHandle?: ElementId
selected?: boolean
sourcePosition?: Position
targetPosition?: Position
diff --git a/src/types/node.ts b/src/types/node.ts
index 66966235..6ef9797a 100644
--- a/src/types/node.ts
+++ b/src/types/node.ts
@@ -8,8 +8,8 @@ export interface VFInternals {
width: number
height: number
handleBounds: {
- source: HandleElement[] | null
- target: HandleElement[] | null
+ source?: HandleElement[]
+ target?: HandleElement[]
}
}
diff --git a/src/utils/edge.ts b/src/utils/edge.ts
index 9b8e194c..d4b2c8f3 100644
--- a/src/utils/edge.ts
+++ b/src/utils/edge.ts
@@ -41,7 +41,7 @@ export function getHandlePosition(position: Position, node: GraphNode, handle: a
}
}
-export function getHandle(bounds: HandleElement[], handleId: ElementId | null): HandleElement | undefined {
+export function getHandle(bounds: HandleElement[], handleId?: ElementId): HandleElement | undefined {
if (!bounds) return undefined
// there is no handleId when there are no multiple handles/ handles with ids
@@ -53,7 +53,7 @@ export function getHandle(bounds: HandleElement[], handleId: ElementId | null):
handle = bounds.find((d) => d.id === handleId)
}
- return typeof handle === 'undefined' ? undefined : handle
+ return !handle ? undefined : handle
}
export const getEdgePositions = (
diff --git a/src/utils/graph.ts b/src/utils/graph.ts
index 33d71e71..d143433a 100644
--- a/src/utils/graph.ts
+++ b/src/utils/graph.ts
@@ -171,8 +171,8 @@ export const parseNode = (node: Node, nodeExtent: NodeExtent): GraphNode => ({
width: 0,
height: 0,
handleBounds: {
- source: null,
- target: null,
+ source: undefined,
+ target: undefined,
},
isDragging: false,
},
@@ -182,8 +182,8 @@ export const parseEdge = (edge: Edge): Edge => ({
...edge,
source: edge.source.toString(),
target: edge.target.toString(),
- sourceHandle: edge.sourceHandle ? edge.sourceHandle.toString() : null,
- targetHandle: edge.targetHandle ? edge.targetHandle.toString() : null,
+ sourceHandle: edge.sourceHandle ? edge.sourceHandle.toString() : undefined,
+ targetHandle: edge.targetHandle ? edge.targetHandle.toString() : undefined,
id: edge.id.toString(),
type: edge.type || 'default',
})
diff --git a/src/utils/node.ts b/src/utils/node.ts
index b82cc4de..e4b49de3 100644
--- a/src/utils/node.ts
+++ b/src/utils/node.ts
@@ -18,7 +18,7 @@ export const getHandleBoundsByHandleType = (
return handlesArray.map((handle): HandleElement => {
const bounds = handle.getBoundingClientRect()
const dimensions = getDimensions(handle)
- const handleId = handle.getAttribute('data-handleid')
+ const handleId = handle.getAttribute('data-handleid') ?? undefined
const handlePosition = handle.getAttribute('data-handlepos') as Position
return {
@@ -35,7 +35,7 @@ export const getHandleBounds = (nodeElement: HTMLDivElement, scale: number) => {
const bounds = nodeElement.getBoundingClientRect()
return {
- source: getHandleBoundsByHandleType('.source', nodeElement, bounds, scale),
- target: getHandleBoundsByHandleType('.target', nodeElement, bounds, scale),
+ source: getHandleBoundsByHandleType('.source', nodeElement, bounds, scale) ?? undefined,
+ target: getHandleBoundsByHandleType('.target', nodeElement, bounds, scale) ?? undefined,
}
}