update: use controlledComputed for edges/nodes
Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
@@ -1,13 +1,28 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { CSSProperties } from 'vue'
|
import { CSSProperties } from 'vue'
|
||||||
import { getBezierPath, getSmoothStepPath } from '../Edges/utils'
|
import { getBezierPath, getSmoothStepPath } from '../Edges/utils'
|
||||||
import { useStore } from '../../composables'
|
import {
|
||||||
import { ConnectionLineType, HandleElement, GraphNode, Position } from '../../types'
|
ConnectionLineType,
|
||||||
|
HandleElement,
|
||||||
|
Position,
|
||||||
|
ElementId,
|
||||||
|
HandleType,
|
||||||
|
XYPosition,
|
||||||
|
ConnectionMode,
|
||||||
|
VFInternals,
|
||||||
|
Transform,
|
||||||
|
} from '../../types'
|
||||||
|
|
||||||
interface ConnectionLineProps {
|
interface ConnectionLineProps {
|
||||||
sourceNode: GraphNode
|
vf: VFInternals
|
||||||
connectionLineType?: ConnectionLineType
|
connectionLineType?: ConnectionLineType
|
||||||
connectionLineStyle?: CSSProperties
|
connectionLineStyle?: CSSProperties
|
||||||
|
connectionHandleId: ElementId
|
||||||
|
connectionNodeId: ElementId
|
||||||
|
connectionHandleType: HandleType
|
||||||
|
connectionPosition: XYPosition
|
||||||
|
connectionMode: ConnectionMode
|
||||||
|
transform: Transform
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = withDefaults(defineProps<ConnectionLineProps>(), {
|
const props = withDefaults(defineProps<ConnectionLineProps>(), {
|
||||||
@@ -15,24 +30,20 @@ const props = withDefaults(defineProps<ConnectionLineProps>(), {
|
|||||||
connectionLineStyle: () => ({}),
|
connectionLineStyle: () => ({}),
|
||||||
})
|
})
|
||||||
|
|
||||||
const store = useStore()
|
|
||||||
|
|
||||||
const sourceHandle =
|
const sourceHandle =
|
||||||
store.connectionHandleId && store.connectionHandleType
|
props.connectionHandleId && props.connectionHandleType
|
||||||
? props.sourceNode.__vf.handleBounds[store.connectionHandleType]?.find(
|
? props.vf.handleBounds[props.connectionHandleType]?.find((d: HandleElement) => d.id === props.connectionHandleId)
|
||||||
(d: HandleElement) => d.id === store.connectionHandleId,
|
: props.connectionHandleType && props.vf.handleBounds[props.connectionHandleType ?? 'source']?.[0]
|
||||||
)
|
const sourceHandleX = sourceHandle ? sourceHandle.x + sourceHandle.width / 2 : (props.vf.width as number) / 2
|
||||||
: store.connectionHandleType && props.sourceNode.__vf.handleBounds[store.connectionHandleType ?? 'source']?.[0]
|
const sourceHandleY = sourceHandle ? sourceHandle.y + sourceHandle.height / 2 : props.vf.height
|
||||||
const sourceHandleX = sourceHandle ? sourceHandle.x + sourceHandle.width / 2 : (props.sourceNode.__vf?.width as number) / 2
|
const sourceX = props.vf.position.x + sourceHandleX
|
||||||
const sourceHandleY = sourceHandle ? sourceHandle.y + sourceHandle.height / 2 : props.sourceNode.__vf?.height
|
const sourceY = props.vf.position.y + sourceHandleY
|
||||||
const sourceX = props.sourceNode.__vf?.position?.x + sourceHandleX
|
|
||||||
const sourceY = props.sourceNode.__vf?.position?.y + sourceHandleY
|
|
||||||
|
|
||||||
const isRightOrLeft = sourceHandle?.position === Position.Left || sourceHandle?.position === Position.Right
|
const isRightOrLeft = sourceHandle?.position === Position.Left || sourceHandle?.position === Position.Right
|
||||||
const targetPosition = isRightOrLeft ? Position.Left : Position.Top
|
const targetPosition = isRightOrLeft ? Position.Left : Position.Top
|
||||||
|
|
||||||
const targetX = computed(() => (store.connectionPosition.x - store.transform[0]) / store.transform[2])
|
const targetX = computed(() => (props.connectionPosition.x - props.transform[0]) / props.transform[2])
|
||||||
const targetY = computed(() => (store.connectionPosition.y - store.transform[1]) / store.transform[2])
|
const targetY = computed(() => (props.connectionPosition.y - props.transform[1]) / props.transform[2])
|
||||||
|
|
||||||
const dAttr = computed(() => {
|
const dAttr = computed(() => {
|
||||||
let path = `M${sourceX},${sourceY} ${targetX.value},${targetY.value}`
|
let path = `M${sourceX},${sourceY} ${targetX.value},${targetY.value}`
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ interface EdgeWrapper {
|
|||||||
| string
|
| string
|
||||||
| {
|
| {
|
||||||
component: any
|
component: any
|
||||||
props?: EdgeTextProps
|
props?: EdgeTextProps | any
|
||||||
}
|
}
|
||||||
labelStyle?: any
|
labelStyle?: any
|
||||||
labelShowBg?: boolean
|
labelShowBg?: boolean
|
||||||
|
|||||||
@@ -1,6 +1,17 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { CSSProperties } from 'vue'
|
import { CSSProperties } from 'vue'
|
||||||
import { ConnectionLineType, Dimensions, Edge, EdgeComponent, GraphNode, HandleType, Transform } from '../../types'
|
import {
|
||||||
|
ConnectionLineType,
|
||||||
|
ConnectionMode,
|
||||||
|
Dimensions,
|
||||||
|
Edge,
|
||||||
|
EdgeComponent,
|
||||||
|
ElementId,
|
||||||
|
GraphNode,
|
||||||
|
HandleType,
|
||||||
|
Transform,
|
||||||
|
XYPosition,
|
||||||
|
} from '../../types'
|
||||||
import { getSourceTargetNodes } from '../../utils'
|
import { getSourceTargetNodes } from '../../utils'
|
||||||
import EdgeWrapper from '../../components/Edges/EdgeWrapper.vue'
|
import EdgeWrapper from '../../components/Edges/EdgeWrapper.vue'
|
||||||
import ConnectionLine from '../../components/ConnectionLine/ConnectionLine.vue'
|
import ConnectionLine from '../../components/ConnectionLine/ConnectionLine.vue'
|
||||||
@@ -18,8 +29,11 @@ interface EdgeRendererProps {
|
|||||||
markerEndId?: string
|
markerEndId?: string
|
||||||
elementsSelectable?: boolean
|
elementsSelectable?: boolean
|
||||||
edgeUpdaterRadius?: number
|
edgeUpdaterRadius?: number
|
||||||
connectionNodeId?: string
|
connectionNodeId?: ElementId
|
||||||
connectionHandleType?: HandleType
|
connectionHandleType?: HandleType
|
||||||
|
connectionHandleId?: ElementId
|
||||||
|
connectionPosition?: XYPosition
|
||||||
|
connectionMode: ConnectionMode
|
||||||
nodesConnectable?: boolean
|
nodesConnectable?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,17 +53,22 @@ const getType = (type: string) => {
|
|||||||
return edgeType
|
return edgeType
|
||||||
}
|
}
|
||||||
|
|
||||||
const sourceNode = computed(() => props.nodes.find((n) => n.id === props.connectionNodeId))
|
const sourceNode = controlledComputed(
|
||||||
const connectionLineVisible = computed(
|
() => props.connectionNodeId,
|
||||||
|
() => {
|
||||||
|
if (props.connectionNodeId) return props.nodes[props.nodes.map((n) => n.id).indexOf(props.connectionNodeId)]
|
||||||
|
},
|
||||||
|
)
|
||||||
|
const connectionLineVisible = controlledComputed(
|
||||||
|
() => props.connectionNodeId,
|
||||||
() =>
|
() =>
|
||||||
!!(
|
!!(
|
||||||
sourceNode.value &&
|
sourceNode.value &&
|
||||||
(typeof sourceNode.value.selectable === 'undefined' ? props.nodesConnectable : sourceNode.value.selectable) &&
|
(typeof sourceNode.value.connectable === 'undefined' ? props.nodesConnectable : sourceNode.value.connectable) &&
|
||||||
props.connectionNodeId &&
|
props.connectionNodeId &&
|
||||||
props.connectionHandleType
|
props.connectionHandleType
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
const transform = computed(() => `translate(${props.transform[0]},${props.transform[1]}) scale(${props.transform[2]})`)
|
const transform = computed(() => `translate(${props.transform[0]},${props.transform[1]}) scale(${props.transform[2]})`)
|
||||||
|
|
||||||
const sourceTargetNodes = (edge: Edge) => {
|
const sourceTargetNodes = (edge: Edge) => {
|
||||||
@@ -105,9 +124,15 @@ export default {
|
|||||||
</EdgeWrapper>
|
</EdgeWrapper>
|
||||||
<ConnectionLine
|
<ConnectionLine
|
||||||
v-if="connectionLineVisible && sourceNode"
|
v-if="connectionLineVisible && sourceNode"
|
||||||
:source-node="sourceNode"
|
|
||||||
:connection-line-style="props.connectionLineStyle"
|
:connection-line-style="props.connectionLineStyle"
|
||||||
:connection-line-type="props.connectionLineType"
|
:connection-line-type="props.connectionLineType"
|
||||||
|
:connection-handle-id="props.connectionHandleId"
|
||||||
|
:vf="sourceNode?.__vf"
|
||||||
|
:connection-node-id="props.connectionNodeId"
|
||||||
|
:connection-handle-type="props.connectionHandleType"
|
||||||
|
:connection-position="props.connectionPosition"
|
||||||
|
:connection-mode="props.connectionMode"
|
||||||
|
:transform="props.transform"
|
||||||
>
|
>
|
||||||
<template #default="customConnectionLineProps">
|
<template #default="customConnectionLineProps">
|
||||||
<slot name="custom-connection-line" v-bind="customConnectionLineProps"></slot>
|
<slot name="custom-connection-line" v-bind="customConnectionLineProps"></slot>
|
||||||
|
|||||||
@@ -238,7 +238,10 @@ const transitionName = computed(() => {
|
|||||||
:nodes="store.getNodes"
|
:nodes="store.getNodes"
|
||||||
:elements-selectable="store.elementsSelectable"
|
:elements-selectable="store.elementsSelectable"
|
||||||
:connection-node-id="store.connectionNodeId"
|
:connection-node-id="store.connectionNodeId"
|
||||||
|
:connction-handle-id="store.connectionHandleId"
|
||||||
:connection-handle-type="store.connectionHandleType"
|
:connection-handle-type="store.connectionHandleType"
|
||||||
|
:connection-position="store.connectionPosition"
|
||||||
|
:connection-mode="store.connectionMode"
|
||||||
:nodes-connectable="store.nodesConnectable"
|
:nodes-connectable="store.nodesConnectable"
|
||||||
:connection-line-type="store.connectionLineType"
|
:connection-line-type="store.connectionLineType"
|
||||||
:connection-line-style="store.connectionLineStyle"
|
:connection-line-style="store.connectionLineStyle"
|
||||||
|
|||||||
Reference in New Issue
Block a user