* docs: Animations * docs: add confetti gun * docs: update basic example on home page * docs(deps): Add stackblitz sdk to deps * chore: update yarn.lock * docs: use vue repl * docs: remove stackblitz sdk * docs: basic repl example * docs: use repl for examples/index.md (basic example) * docs: pass ext to repl * docs: add copy plugin * docs: use import map instead of dynamic imports * docs: use repl for custom node example * docs: hide repl errors * docs: use repl for custom connectionline example * docs: use repl for edges example * docs: exclude repl from ssr * docs: use repl for nested example * docs: use repl for stress example * docs: rename customNode to custom-node * docs: use repl for update-edge example * docs: use repl for update-node example * docs: use repl for validation example * docs: use repl for save-restore example * docs: scale down minimap in repl examples * docs: use repl for dnd example * docs: use repl for empty example * docs: use repl for hidden example * docs: use repl for interaction example * docs: use repl for multi example * docs: add pinia example with stackblitz * docs: update basic example * docs: update examples * docs: remove transition from intro * docs: update features * update: README.md * docs: scope css
78 lines
1.8 KiB
Vue
78 lines
1.8 KiB
Vue
<script lang="ts" setup>
|
||
import type { EdgeProps, Position } from '@braks/vue-flow'
|
||
import { getBezierPath, getEdgeCenter, useVueFlow } from '@braks/vue-flow'
|
||
|
||
interface CustomEdgeProps<T = any> extends EdgeProps<T> {
|
||
id: string
|
||
sourceX: number
|
||
sourceY: number
|
||
targetX: number
|
||
targetY: number
|
||
sourcePosition: Position
|
||
targetPosition: Position
|
||
data?: T
|
||
markerEnd: string
|
||
}
|
||
|
||
const props = defineProps<CustomEdgeProps>()
|
||
const { id: storeId, applyEdgeChanges, getEdges } = useVueFlow()
|
||
|
||
const onClick = (evt: Event, id: string) => {
|
||
applyEdgeChanges([{ type: 'remove', id }])
|
||
evt.stopPropagation()
|
||
}
|
||
|
||
const foreignObjectSize = 40
|
||
|
||
const edgePath = computed(() =>
|
||
getBezierPath({
|
||
sourceX: props.sourceX,
|
||
sourceY: props.sourceY,
|
||
sourcePosition: props.sourcePosition,
|
||
targetX: props.targetX,
|
||
targetY: props.targetY,
|
||
targetPosition: props.targetPosition,
|
||
}),
|
||
)
|
||
const center = computed(() =>
|
||
getEdgeCenter({
|
||
sourceX: props.sourceX,
|
||
sourceY: props.sourceY,
|
||
targetX: props.targetX,
|
||
targetY: props.targetY,
|
||
}),
|
||
)
|
||
</script>
|
||
|
||
<script lang="ts">
|
||
export default {
|
||
inheritAttrs: false,
|
||
}
|
||
</script>
|
||
|
||
<template>
|
||
<path :id="props.id" :style="props.style" class="vue-flow__edge-path" :d="edgePath" :marker-end="props.markerEnd" />
|
||
<foreignObject
|
||
:width="foreignObjectSize"
|
||
:height="foreignObjectSize"
|
||
:x="center[0] - foreignObjectSize / 2"
|
||
:y="center[1] - foreignObjectSize / 2"
|
||
class="edgebutton-foreignobject"
|
||
requiredExtensions="http://www.w3.org/1999/xhtml"
|
||
>
|
||
<body>
|
||
<button class="edgebutton" @click="(event) => onClick(event, props.id)">×</button>
|
||
</body>
|
||
</foreignObject>
|
||
</template>
|
||
|
||
<style>
|
||
.edgebutton {
|
||
border-radius: 999px;
|
||
cursor: pointer;
|
||
}
|
||
.edgebutton:hover {
|
||
box-shadow: 0 0 0 2px pink, 0 0 0 4px #f05f75;
|
||
}
|
||
</style>
|