MCPcopy Index your code
hub / github.com/bytedance/flow-builder

github.com/bytedance/flow-builder @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
233 symbols 428 edges 60 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

简介

English | 简体中文

高度可定制的流式流程引擎。注册能力可以灵活定制你的节点类型以及不同类型的节点展示和节点表单等。

demo1 demo2

试一试

https://bytedance.github.io/flow-builder

Github

https://github.com/bytedance/flow-builder

安装

yarn add react-flow-builder

或

npm install react-flow-builder

Usage

// index.tsx
import React, { useState, useContext } from 'react';
import FlowBuilder, {
  NodeContext,
  INode,
  IRegisterNode,
} from 'react-flow-builder';

import './index.css';

const StartNodeDisplay: React.FC = () => {
  const node = useContext(NodeContext);
  return 

{node.name}

;
};

const EndNodeDisplay: React.FC = () => {
  const node = useContext(NodeContext);
  return 

{node.name}

;
};

const OtherNodeDisplay: React.FC = () => {
  const node = useContext(NodeContext);
  return 

{node.name}

;
};

const ConditionNodeDisplay: React.FC = () => {
  const node = useContext(NodeContext);
  return 

{node.name}

;
};

const registerNodes: IRegisterNode[] = [
  {
    type: 'start',
    name: '开始节点',
    displayComponent: StartNodeDisplay,
    isStart: true,
  },
  {
    type: 'end',
    name: '结束节点',
    displayComponent: EndNodeDisplay,
    isEnd: true,
  },
  {
    type: 'node',
    name: '普通节点',
    displayComponent: OtherNodeDisplay,
  },
  {
    type: 'condition',
    name: '条件节点',
    displayComponent: ConditionNodeDisplay,
  },
  {
    type: 'branch',
    name: '分支节点',
    conditionNodeType: 'condition',
  },
];

const Demo = () => {
  const [nodes, setNodes] = useState<INode[]>([]);

  const handleChange = (nodes: INode[]) => {
    console.log('nodes change', nodes);
    setNodes(nodes);
  };

  return (
    <FlowBuilder
      nodes={nodes}
      onChange={handleChange}
      registerNodes={registerNodes}
    />
  );
};

export default Demo;

// index.css
.start-node, .end-node {
  height: 64px;
  width: 64px;
  border-radius: 50%;
  line-height: 64px;
  color: #fff;
  text-align: center;
}

.start-node {
  background-color: #338aff;
}

.end-node {
  background-color: #666;
}

.other-node, .condition-node {
  width: 224px;
  border-radius: 4px;
  color: #666;
  background: #fff;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.08);
}

.other-node {
  height: 118px;
  padding: 16px;
  display: flex;
  flex-direction: column;
}

.condition-node {
  height: 44px;
  padding: 12px 16px;
}

API

FlowBuilder

参数 说明 类型 必须 默认值 版本
backgroundColor 背景颜色 string #F7F7F7
className 外层容器的类名 string -
draggable 是否启用拖拽能力 boolean false 1.0.0
DragComponent 自定义拖拽组件 React.FC\<DragComponent> - 1.0.0
DropComponent 自定义放置组件 React.FC\<DropComponent> - 1.0.0
createUuid 自定义节点的 uuid (type?: string) => string - 2.0.0
DrawerComponent Drawer 组件 React.FC\<DrawerComponent> - 2.0.0
PopoverComponent Popover 组件 React.FC\<PopoverComponent> - 2.0.0
PopconfirmComponent Popconfirm 组件 React.FC\<PopconfirmComponent> - 2.0.0
drawerProps 传给 DrawerComponent 额外的属性 any -
drawerVisibleWhenAddNode 增加节点时打开抽屉 boolean false
historyTool 撤销,重做 boolean | HistoryToolConfig false
layout 垂直/水平布局 vertical | horizontal vertical
lineColor 连线的颜色 string #999999
nodes 流程引擎的节点 Node[] -
readonly 只读模式,不能进行节点的增加、删除、配置 boolean false
registerNodes 注册节点 RegisterNode[] -
registerRemoteNodes 注册远程节点 RegisterRemoteNode[] - 1.3.0
showPracticalBranchNode - boolean false 1.1.0
showPracticalBranchRemove - boolean false 1.1.0
sortable 条件节点在分支内可拖拽排序 boolean false 1.4.0
sortableAnchor 自定义拖拽排序的锚点序 ReactNode - 1.4.0
spaceX 节点之间水平方向的间距 number 16
spaceY 节点之间垂直方向的间距 number 16
zoomTool 缩放 boolean | ZoomToolConfig false
onChange 节点数据改变时的回调函数 (nodes: Node[], changeEvent: string, nodeChanged?: INode) => void -
onHistoryChange 历史状态变化之后的回调,两个参数分别代表是否需要禁用撤销和重做 (undoDisabled: boolean, redoDisabled: boolean) => void -
onZoomChange 缩放变化之后的回调,三个参数分别代表是否需要禁用缩小、当前的缩放值、是否需要禁用放大 (outDisabled: boolean, value: number, inDisabled: boolean) => void -
showArrow 显示箭头 boolean false 1.4.5
arrowIcon 自定义箭头 ReactNode - 1.4.5
onAddNodeSuccess 增加节点成功之后的回调 (type: string, node: INode) => void - 1.4.9
onDropNodeSuccess 放置节点成功之后的回调 (type: string, node: INode) => void - 1.4.9
onRemoveNodeSuccess 删除节点成功之后的回调 (node: INode) => void - 2.2.0
allowStartConfig 允许配置开始节点 boolean - 2.1.0
allowEndConfig 允许配置结束节点 boolean - 2.1.0
scrollByDrag 通过拖动画布进行滚动 boolean - 2.6.0

HistoryToolConfig

参数 说明 类型 默认值
hidden 是否隐藏默认的历史工具栏 boolean false
max 最多保存的数量 number 10

ZoomToolConfig

参数 说明 类型 默认值
hidden 是否隐藏默认的缩放工具栏 boolean false
initialValue 初始值 number 100
min 最小值 number 10
max 最大值 number 200
step 每次缩放比例的变化大小 number 10

DragComponent

参数 说明 类型 版本
onDragStart 自定义拖拽组件的 dragStart 事件需要调用此方法,设置正在拖拽的节点类型( BuilderContext 中的 dragType ) (nodeType: string) => void 1.0.0
onDragEnd 自定义拖拽组件的 dragEnd 事件需要调用此方法,清空正在拖拽的节点类型( BuilderContext 中的 dragType ) () => void 1.0.0

DropComponent

参数 说明 类型 版本
onDrop 自定义放置组件的 drop 事件需要调用此方法,完成放置动作增加对应的节点 () => void 1.0.0

DrawerComponent

参数 说明 类型 版本
visible 也可以自行判断 selectedNode 的布尔值 any 2.0.0
onClose 也可以自行调用 closeDrawer any 2.0.0
children any 2.0.0
title any 2.0.0
width any 2.0.0
destroyOnClose any 2.0.0
maskClosable any 2.0.0
configComponentRef React.MutableRefObject\<any> 2.5.0

PopoverComponent

参数 说明 类型 版本
visible any 2.0.0
onVisibleChange any 2.0.0
children any 2.0.0
overlayClassName any 2.0.0
placement any 2.0.0
trigger any 2.0.0
content any 2.0.0
getPopupContainer any 2.0.0

PopconfirmComponent

参数 说明 类型 版本
title

Extension points exported contracts — how you extend this code

IDisplayComponent (Interface)
(no doc)
src/index.tsx
Window (Interface)
(no doc)
src/utils/index.ts
IProps (Interface)
(no doc)
src/Lines/SplitLine.tsx
IProps (Interface)
(no doc)
src/Nodes/ConditionNode.tsx
IProps (Interface)
(no doc)
src/AddButton/index.tsx
IProps (Interface)
(no doc)
src/ActionButton/index.tsx
IProps (Interface)
(no doc)
src/DefaultNode/index.tsx
IConfigComponent (Interface)
(no doc)
src/index.tsx

Core symbols most depended-on inside this repo

getRegisterNode
called by 19
src/utils/index.ts
useAction
called by 10
src/hooks/useAction.ts
clickNode
called by 10
src/hooks/useAction.ts
getIsConditionNode
called by 9
src/utils/index.ts
exchangeNodes
called by 9
src/utils/index.ts
getIsBranchNode
called by 8
src/utils/index.ts
pushHistory
called by 5
src/hooks/useHistory.ts
createNewNode
called by 4
src/utils/index.ts

Shape

Function 203
Interface 30

Languages

TypeScript100%

Modules by API surface

src/utils/index.ts22 symbols
src/index.tsx20 symbols
docs/demo/sortable/hook.tsx10 symbols
src/Nodes/BranchNode.tsx9 symbols
src/hooks/useAction.ts7 symbols
docs/demo/zoom/custom.tsx7 symbols
docs/demo/node/addableComponent/index.tsx7 symbols
docs/demo/history/custom.tsx7 symbols
docs/demo/dragdrop/drop.tsx7 symbols
docs/demo/dragdrop/drag.tsx7 symbols
src/Builder/index.tsx6 symbols
docs/demo/zoom/index.tsx6 symbols

For agents

$ claude mcp add flow-builder \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact