边缘

用于 Vue Flow 画布的可自定义边缘组件,具有动画和临时状态。

Edge 组件为 Vue Flow 画布提供了两种预样式边缘类型:Temporary 用于虚线临时连接,Animated 用于带有动画指示器的连接。

使用 CLI 安装

AI Elements Vue
shadcn-vue CLI
npx ai-elements-vue@latest add edge

手动安装

将以下代码复制并粘贴到同一文件夹中。

Temporary.vue
Animated.vue
index.ts
<script setup lang="ts">
import type { EdgeProps } from '@vue-flow/core'
import { BaseEdge, getSimpleBezierPath } from '@vue-flow/core'
import { computed } from 'vue'

const props = defineProps<EdgeProps>()

const path = computed(() => {
  const [edgePath] = getSimpleBezierPath({
    sourceX: props.sourceX,
    sourceY: props.sourceY,
    sourcePosition: props.sourcePosition,
    targetX: props.targetX,
    targetY: props.targetY,
    targetPosition: props.targetPosition,
  })
  return edgePath
})
</script>

<template>
  <BaseEdge
    :id="props.id"
    :path="path"
    class="stroke-1 stroke-ring"
    :style="{ strokeDasharray: '5, 5' }"
  />
</template>

特性

  • 两种不同的边缘类型:Temporary 和 Animated
  • Temporary 边缘使用带环颜色的虚线
  • Animated 边缘包括一个移动的圆形指示器
  • 自动句柄位置计算
  • 基于句柄类型和位置的智能偏移计算
  • 使用贝塞尔曲线实现平滑、自然的连接
  • 完全兼容 Vue Flow 的边缘系统
  • 使用 TypeScript 的类型安全实现

边缘类型

<Temporary />

用于临时或预览连接的虚线边缘样式。使用带有虚线描边图案的简单贝塞尔路径。

<Animated />

一条实心边缘,带有一个沿路径移动的动画圆圈。动画无限重复,持续时间为 2 秒,为活动连接提供视觉反馈。

Props

<Animated /><Temporary /> 组件都接受标准 Vue Flow EdgeProps。以下是最常用的 props:

idstring
边缘的唯一标识符。
sourcestring
源节点的 ID。
targetstring
目标节点的 ID。
sourceXnumber
源连接点的 x 坐标。
sourceYnumber
源连接点的 y 坐标。
targetXnumber
目标连接点的 x 坐标。
targetYnumber
目标连接点的 y 坐标。
sourcePositionPosition
源句柄的位置。
targetPositionPosition
目标句柄的位置。
styleCSSProperties
应用于边缘的自定义 CSS 样式。
markerStartstring
边缘起点的标记 ID。
markerEndstring
边缘终点的标记 ID。