Skip to content

Commit

Permalink
Merge pull request #1585 from alibaba/xflow
Browse files Browse the repository at this point in the history
Xflow
  • Loading branch information
lhbxs authored Dec 5, 2024
2 parents 01919f1 + b0804b8 commit ca45064
Show file tree
Hide file tree
Showing 40 changed files with 819 additions and 356 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

.yarn
.turbo/cookies
.turbo/daemon
.turbo

# turbo
*/*/.turbo
Expand Down
95 changes: 95 additions & 0 deletions .turbo/daemon/9af73f40ad414c73-turbo.log.2024-12-04

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion docs/xflow/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ title: API
| layout | 节点布局的方向 | `LR \| TB` | LR | - |
| widgets | 自定义组件 | `Record<string, ReactNode>` | - | - |
| settings | 节点配置,定义页面中可拖动的节点配置 | ( [TNodeGroup](#tnodegroup) \| [TNodeItem](#tnodeitem) )[ ] | |
| nodeSelector | 节点选择器配置,可控制节点的可搜索性 | `TNodeSelector` | |
| nodeSelector | 节点选择器配置,可控制节点的可搜索性 | `TNodeSelector`
| iconFontUrl | iconfont url,用于配置图标渲染 | `String` | |
| |

### TNodeGroup

Expand Down
2 changes: 1 addition & 1 deletion docs/xflow/demo/basic/setting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export default [
type: 'Switch',
description: '允许你根据 if/else 条件将 workflow 拆分成两个分支',
icon: {
type: 'icon-switch',
type: 'icon-fenzhi',
bgColor: '#06AED4',
},
settingSchema: {
Expand Down
2 changes: 1 addition & 1 deletion docs/xflow/demo/custom-flow/setting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default [
type: 'Switch',
description: '允许你根据 if/else 条件将 workflow 拆分成两个分支',
icon: {
type: 'icon-switch',
type: 'icon-fenzhi',
bgColor: '#06AED4',
},
},
Expand Down
2 changes: 1 addition & 1 deletion docs/xflow/demo/flow-provider/setting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export default [
type: 'Switch',
description: '允许你根据 if/else 条件将 workflow 拆分成两个分支',
icon: {
type: 'icon-switch',
type: 'icon-fenzhi',
bgColor: '#06AED4',
},
},
Expand Down
2 changes: 1 addition & 1 deletion docs/xflow/demo/layout/LR/setting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export default [
type: 'Switch',
description: '允许你根据 if/else 条件将 workflow 拆分成两个分支',
icon: {
type: 'icon-switch',
type: 'icon-fenzhi',
bgColor: '#06AED4',
},
},
Expand Down
2 changes: 1 addition & 1 deletion docs/xflow/demo/layout/TB/setting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export default [
type: 'Switch',
description: '允许你根据 if/else 条件将 workflow 拆分成两个分支',
icon: {
type: 'icon-switch',
type: 'icon-fenzhi',
bgColor: '#06AED4',
},
},
Expand Down
2 changes: 1 addition & 1 deletion docs/xflow/demo/nodeSetting/setting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export default [
type: 'Switch',
description: '允许你根据 if/else 条件将 workflow 拆分成两个分支',
icon: {
type: 'icon-switch',
type: 'icon-fenzhi',
bgColor: '#06AED4',
},
},
Expand Down
33 changes: 33 additions & 0 deletions docs/xflow/demo/switchNode/customSwitchNode/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import XFlow from '@xrenders/xflow';
import settings from './setting';
import React from 'react';

const customWidget = ({ data, key, item }) => {
return <p style={{ wordWrap: 'break-word' }}>{item?.value}</p>;
};

export default () => {
const nodes = [
{
type: 'Switch',
id: '2',
position: { x: 171.25, y: 218.75 },
data: { switchData:[{value:"条件1"}]}
},
];

const edges = [];

return (
<div style={{ height: '600px' }}>
<XFlow
initialValues={{ nodes, edges }}
settings={settings}
nodeSelector={{
showSearch: true,
}}
widgets={{ customWidget }}
/>
</div>
);
};
151 changes: 151 additions & 0 deletions docs/xflow/demo/switchNode/customSwitchNode/setting.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
export default [
{
title: 'Switch',
type: 'Switch',
description: '允许你根据 if/else 条件将 workflow 拆分成两个分支',
icon: {
type: 'icon-fenzhi',
bgColor: '#06AED4',
},
nodeWidget: "customWidget" // 自定义节点面板渲染
},
{
title: '开始',
type: 'Start',
hidden: true,
targetHandleHidden: true,
icon: {
type: 'icon-start',
bgColor: '#17B26A',
},
settingSchema: {
type: 'object',
properties: {
input: {
title: '变量一',
type: 'string',
widget: 'input',
},
select: {
title: '变量二',
type: 'string',
widget: 'select',
props: {
options: [
{ label: 'a', value: 'a' },
{ label: 'b', value: 'b' },
{ label: 'c', value: 'c' },
],
},
},
radio1: {
title: '点击单选',
type: 'string',
widget: 'radio',
props: {
options: [
{ label: '早', value: 'a' },
{ label: '中', value: 'b' },
{ label: '晚', value: 'c' }
]
}
},
textarea1: {
title: '长文本',
type: 'string',
widget: 'textArea'
},
date1: {
title: '日期选择',
type: 'string',
widget: 'datePicker'
},
dateRange1: {
title: '日期范围',
type: 'range',
widget: 'dateRange'
},
time1: {
title: '时间选择',
type: 'string',
widget: 'timePicker'
},
timeRange1: {
title: '时间范围',
type: 'range',
widget: 'timeRange'
},
},
},
},
{
title: '结束',
type: 'End',
hidden: true,
sourceHandleHidden: true,
icon: {
type: 'icon-end',
bgColor: '#F79009',
},
settingSchema: {
type: "object",
properties: {
input: {
title: '变量一',
type: 'string',
widget: 'input',
},
select: {
title: '变量二',
type: 'string',
widget: 'select',
props: {
options: [
{ label: 'a', value: 'a' },
{ label: 'b', value: 'b' },
{ label: 'c', value: 'c' },
],
},
},
}
}
},
{
title: 'Prompt',
type: 'Prompt',
description: '通过精心设计提示词,提升大语言模型回答效果',
icon: {
type: 'icon-prompt',
bgColor: '#17B26A',
},
settingSchema: {
type: "object",
properties: {
input: {
title: '提示词',
type: 'string',
widget: 'textArea',
},
}
},
},
{
title: '知识库',
type: 'knowledge',
description: '允许你从知识库中查询与用户问题相关的文本内容',
icon: {
type: 'icon-knowledge',
bgColor: '#6172F3',
},
settingSchema: {
type: "object",
properties: {
input: {
title: '知识库',
type: 'string',
widget: 'textArea',
},
}
},
},
];
61 changes: 57 additions & 4 deletions docs/xflow/demo/switchNode/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,66 @@
import React from 'react';
import XFlow from '@xrenders/xflow';
import settings from './setting';

export default () => {
const nodes = [
{ id: '1', type: 'Switch', data: { input: '开始节点', select: "b" }, position: { x: 40, y: 240 } },
{
type: 'Start',
id: '1',
position: { x: -130, y: 290 },
},
{
type: 'Switch',
id: '2',
position: { x: 171.25, y: 218.75 },
data: { switchData: [{ value: '条件1' }] },
},
{
type: 'End',
id: '3',
position: { x: 915, y: 287.5 },
},
{
id: 'g29rz9ol4ugqz8m8',
type: 'Prompt',
position: { x: 525, y: 210 },
},
{
id: 'swqutt73ihfa9lkb',
type: 'knowledge',
position: { x: 522.5, y: 472.5 },
},
];

const edges = []
const edges = [
{
source: '1',
target: '2',
id: 'xy-edge__1-2',
},
{
source: '2',
sourceHandle: 'id_0',
target: 'g29rz9ol4ugqz8m8',
id: 'xy-edge__2id_0-g29rz9ol4ugqz8m8',
},
{ id: 'w6vmrun9sos4t6ds', target: 'swqutt73ihfa9lkb' },
{
source: '2',
sourceHandle: 'id_else',
target: 'swqutt73ihfa9lkb',
id: 'xy-edge__2id_else-swqutt73ihfa9lkb',
},
{
source: 'g29rz9ol4ugqz8m8',
target: '3',
id: 'xy-edge__g29rz9ol4ugqz8m8-3',
},
{
source: 'swqutt73ihfa9lkb',
target: '3',
id: 'xy-edge__swqutt73ihfa9lkb-3',
},
];

return (
<div style={{ height: '600px' }}>
Expand All @@ -20,4 +73,4 @@ export default () => {
/>
</div>
);
}
};
Loading

0 comments on commit ca45064

Please sign in to comment.