节点

一个可组合的节点组件,用于基于 Vue Flow 的画布,具有基于 Card 的样式。

Node 组件为 Vue Flow 画布提供了一个可组合的、基于 Card 的节点。 它包括连接句柄支持、结构化布局和使用 shadcn/vue 组件的一致样式。

使用 CLI 安装

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

手动安装

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

Node.vue
NodeHeader.vue
NodeTitle.vue
NodeDescription.vue
NodeAction.vue
NodeContent.vue
NodeFooter.vue
index.ts
<script setup lang="ts">
import type { HTMLAttributes } from 'vue'
import Card from '@repo/shadcn-vue/components/ui/card/Card.vue'
import { cn } from '@repo/shadcn-vue/lib/utils'
import { Handle, Position } from '@vue-flow/core'
import { reactiveOmit } from '@vueuse/core'

interface NodeHandles {
  target?: boolean
  source?: boolean
}

interface NodeProps {
  class?: HTMLAttributes['class']
  handles?: NodeHandles
}

const props = defineProps<NodeProps>()
const delegatedProps = reactiveOmit(props, 'class')
</script>

<template>
  <Card
    v-bind="delegatedProps"
    :class="cn('node-container relative size-full h-auto w-sm gap-0 rounded-md p-0', props.class)"
  >
    <Handle v-if="props.handles?.target" :position="Position.Left" type="target" />
    <Handle v-if="props.handles?.source" :position="Position.Right" type="source" />
    <slot />
  </Card>
</template>

特性

  • 基于 shadcn/vue Card 组件构建,具有一致的样式
  • 自动句柄放置(左侧为目标,右侧为源)
  • 可组合的子组件(Header、Title、Description、Action、Content、Footer)
  • 用于组织节点信息的语义结构
  • 预样式的部分,带有边框和背景
  • 响应式大小,具有固定的小宽度
  • 具有适当类型定义的完整 TypeScript 支持
  • 与 Vue Flow 的节点系统兼容

Props

<Node />

classstring
''
应用于节点的额外 CSS 类。
handles{ target: boolean; source: boolean; }
连接句柄的配置。目标在左侧渲染,源在右侧渲染。

<NodeHeader />

classstring
''
应用于标题的额外 CSS 类。

<NodeTitle />

此组件不接受任何 props。

<NodeDescription />

此组件不接受任何 props。

<NodeAction />

此组件不接受任何 props。

<NodeContent />

classstring
''
应用于内容的额外 CSS 类。

<NodeFooter />

classstring
''
应用于页脚的额外 CSS 类。