update(types): remove null types and use undefined
Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
@@ -10,8 +10,9 @@ import {
|
|||||||
SourceTargetNode,
|
SourceTargetNode,
|
||||||
Position,
|
Position,
|
||||||
FlowEvents,
|
FlowEvents,
|
||||||
|
EdgePositions,
|
||||||
} from '../../types'
|
} from '../../types'
|
||||||
import { isEdge, getEdgePositions, getHandle } from '../../utils'
|
import { isEdge, getEdgePositions, getHandle, isEdgeVisible } from '../../utils'
|
||||||
import EdgeAnchor from './EdgeAnchor.vue'
|
import EdgeAnchor from './EdgeAnchor.vue'
|
||||||
|
|
||||||
interface EdgeWrapper {
|
interface EdgeWrapper {
|
||||||
@@ -22,8 +23,8 @@ interface EdgeWrapper {
|
|||||||
component?: any
|
component?: any
|
||||||
source: ElementId
|
source: ElementId
|
||||||
target: ElementId
|
target: ElementId
|
||||||
sourceHandle?: ElementId | null
|
sourceHandle?: ElementId
|
||||||
targetHandle?: ElementId | null
|
targetHandle?: ElementId
|
||||||
selected?: boolean
|
selected?: boolean
|
||||||
sourcePosition?: Position
|
sourcePosition?: Position
|
||||||
targetPosition?: Position
|
targetPosition?: Position
|
||||||
@@ -153,12 +154,12 @@ const sourceHandle = controlledComputed(
|
|||||||
() => props.sourceTargetNodes,
|
() => props.sourceTargetNodes,
|
||||||
() => {
|
() => {
|
||||||
if (props.sourceTargetNodes.sourceNode && props.sourceTargetNodes.sourceNode.__vf.handleBounds.source)
|
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
|
else return null
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
const targetHandle = computed(() => {
|
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
|
else return null
|
||||||
})
|
})
|
||||||
const sourcePosition = eagerComputed(() => (sourceHandle.value ? sourceHandle.value.position : Position.Bottom))
|
const sourcePosition = eagerComputed(() => (sourceHandle.value ? sourceHandle.value.position : Position.Bottom))
|
||||||
@@ -178,6 +179,17 @@ const edgePos = computed(() =>
|
|||||||
targetPosition.value,
|
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
|
||||||
</script>
|
</script>
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
export default {
|
export default {
|
||||||
@@ -186,6 +198,7 @@ export default {
|
|||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<g
|
<g
|
||||||
|
v-show="isVisible(edgePos)"
|
||||||
:class="[
|
:class="[
|
||||||
'vue-flow__edge',
|
'vue-flow__edge',
|
||||||
`vue-flow__edge-${props.type || 'default'}`,
|
`vue-flow__edge-${props.type || 'default'}`,
|
||||||
|
|||||||
@@ -236,6 +236,7 @@ const transitionName = computed(() => {
|
|||||||
:edges="store.getEdges"
|
:edges="store.getEdges"
|
||||||
:edge-types="store.getEdgeTypes"
|
:edge-types="store.getEdgeTypes"
|
||||||
:nodes="store.getNodes"
|
:nodes="store.getNodes"
|
||||||
|
:selected-elements="store.selectedElements"
|
||||||
:elements-selectable="store.elementsSelectable"
|
:elements-selectable="store.elementsSelectable"
|
||||||
:connection-node-id="store.connectionNodeId"
|
:connection-node-id="store.connectionNodeId"
|
||||||
:connction-handle-id="store.connectionHandleId"
|
:connction-handle-id="store.connectionHandleId"
|
||||||
@@ -247,6 +248,7 @@ const transitionName = computed(() => {
|
|||||||
:connection-line-style="store.connectionLineStyle"
|
:connection-line-style="store.connectionLineStyle"
|
||||||
:arrow-head-color="store.arrowHeadColor"
|
:arrow-head-color="store.arrowHeadColor"
|
||||||
:marker-end-id="store.markerEndId"
|
:marker-end-id="store.markerEndId"
|
||||||
|
:only-render-visible-elements="store.onlyRenderVisibleElements"
|
||||||
>
|
>
|
||||||
<template
|
<template
|
||||||
v-for="edgeName of Object.keys(store.getEdgeTypes)"
|
v-for="edgeName of Object.keys(store.getEdgeTypes)"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Component, CSSProperties, DefineComponent } from 'vue'
|
import { CSSProperties } from 'vue'
|
||||||
import { BackgroundVariant, Dimensions, ElementId, FitViewParams, Position, XYPosition } from './flow'
|
import { BackgroundVariant, Dimensions, ElementId, FitViewParams, Position, XYPosition } from './flow'
|
||||||
import { Connection } from './connection'
|
import { Connection } from './connection'
|
||||||
import { Node } from './node'
|
import { Node } from './node'
|
||||||
@@ -6,7 +6,7 @@ import { Node } from './node'
|
|||||||
export type HandleType = 'source' | 'target'
|
export type HandleType = 'source' | 'target'
|
||||||
|
|
||||||
export interface HandleElement extends XYPosition, Dimensions {
|
export interface HandleElement extends XYPosition, Dimensions {
|
||||||
id?: ElementId | null
|
id?: ElementId
|
||||||
position: Position
|
position: Position
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ export interface EdgeTextProps {
|
|||||||
| string
|
| string
|
||||||
| {
|
| {
|
||||||
component: any
|
component: any
|
||||||
props?: Record<string, any>
|
props?: any
|
||||||
}
|
}
|
||||||
labelStyle?: CSSProperties
|
labelStyle?: CSSProperties
|
||||||
labelShowBg?: boolean
|
labelShowBg?: boolean
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ export enum ConnectionLineType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface Connection {
|
export interface Connection {
|
||||||
source: ElementId | null
|
source: ElementId
|
||||||
target: ElementId | null
|
target: ElementId
|
||||||
sourceHandle: ElementId | null
|
sourceHandle: ElementId
|
||||||
targetHandle: ElementId | null
|
targetHandle: ElementId
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ConnectionLineProps = {
|
export type ConnectionLineProps = {
|
||||||
|
|||||||
+2
-2
@@ -7,8 +7,8 @@ export interface Edge<T = any> {
|
|||||||
type?: string
|
type?: string
|
||||||
source: ElementId
|
source: ElementId
|
||||||
target: ElementId
|
target: ElementId
|
||||||
sourceHandle?: ElementId | null
|
sourceHandle?: ElementId
|
||||||
targetHandle?: ElementId | null
|
targetHandle?: ElementId
|
||||||
selected?: boolean
|
selected?: boolean
|
||||||
sourcePosition?: Position
|
sourcePosition?: Position
|
||||||
targetPosition?: Position
|
targetPosition?: Position
|
||||||
|
|||||||
+2
-2
@@ -8,8 +8,8 @@ export interface VFInternals {
|
|||||||
width: number
|
width: number
|
||||||
height: number
|
height: number
|
||||||
handleBounds: {
|
handleBounds: {
|
||||||
source: HandleElement[] | null
|
source?: HandleElement[]
|
||||||
target: HandleElement[] | null
|
target?: HandleElement[]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -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
|
if (!bounds) return undefined
|
||||||
|
|
||||||
// there is no handleId when there are no multiple handles/ handles with ids
|
// 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)
|
handle = bounds.find((d) => d.id === handleId)
|
||||||
}
|
}
|
||||||
|
|
||||||
return typeof handle === 'undefined' ? undefined : handle
|
return !handle ? undefined : handle
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getEdgePositions = (
|
export const getEdgePositions = (
|
||||||
|
|||||||
+4
-4
@@ -171,8 +171,8 @@ export const parseNode = (node: Node, nodeExtent: NodeExtent): GraphNode => ({
|
|||||||
width: 0,
|
width: 0,
|
||||||
height: 0,
|
height: 0,
|
||||||
handleBounds: {
|
handleBounds: {
|
||||||
source: null,
|
source: undefined,
|
||||||
target: null,
|
target: undefined,
|
||||||
},
|
},
|
||||||
isDragging: false,
|
isDragging: false,
|
||||||
},
|
},
|
||||||
@@ -182,8 +182,8 @@ export const parseEdge = (edge: Edge): Edge => ({
|
|||||||
...edge,
|
...edge,
|
||||||
source: edge.source.toString(),
|
source: edge.source.toString(),
|
||||||
target: edge.target.toString(),
|
target: edge.target.toString(),
|
||||||
sourceHandle: edge.sourceHandle ? edge.sourceHandle.toString() : null,
|
sourceHandle: edge.sourceHandle ? edge.sourceHandle.toString() : undefined,
|
||||||
targetHandle: edge.targetHandle ? edge.targetHandle.toString() : null,
|
targetHandle: edge.targetHandle ? edge.targetHandle.toString() : undefined,
|
||||||
id: edge.id.toString(),
|
id: edge.id.toString(),
|
||||||
type: edge.type || 'default',
|
type: edge.type || 'default',
|
||||||
})
|
})
|
||||||
|
|||||||
+3
-3
@@ -18,7 +18,7 @@ export const getHandleBoundsByHandleType = (
|
|||||||
return handlesArray.map((handle): HandleElement => {
|
return handlesArray.map((handle): HandleElement => {
|
||||||
const bounds = handle.getBoundingClientRect()
|
const bounds = handle.getBoundingClientRect()
|
||||||
const dimensions = getDimensions(handle)
|
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
|
const handlePosition = handle.getAttribute('data-handlepos') as Position
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -35,7 +35,7 @@ export const getHandleBounds = (nodeElement: HTMLDivElement, scale: number) => {
|
|||||||
const bounds = nodeElement.getBoundingClientRect()
|
const bounds = nodeElement.getBoundingClientRect()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
source: getHandleBoundsByHandleType('.source', nodeElement, bounds, scale),
|
source: getHandleBoundsByHandleType('.source', nodeElement, bounds, scale) ?? undefined,
|
||||||
target: getHandleBoundsByHandleType('.target', nodeElement, bounds, scale),
|
target: getHandleBoundsByHandleType('.target', nodeElement, bounds, scale) ?? undefined,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user