@huanban/rulego-editor-react 1.1.5 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -19
- package/dist/components/WorkflowInfoPanel.d.ts +6 -2
- package/dist/components/WorkflowList.d.ts +4 -0
- package/dist/index.cjs.js +849 -755
- package/dist/index.esm.js +19249 -18308
- package/dist/style.css +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
2. React Hooks 封装(方便在函数组件中使用)
|
|
14
14
|
3. Props → Options 的桥接
|
|
15
15
|
|
|
16
|
+
同时,React 包导出 `WorkflowList`、`WorkflowInfoPanel` 等独立管理组件。它们可以和 `RuleGoEditor` 组合成完整工作台,但不把业务套壳写进 core,也不改变编辑器本体职责。
|
|
17
|
+
|
|
16
18
|
## 📦 安装
|
|
17
19
|
|
|
18
20
|
```bash
|
|
@@ -41,7 +43,7 @@ import '@huanban/rulego-editor-react/style.css'
|
|
|
41
43
|
| 组件 | 用途 | 说明 |
|
|
42
44
|
|------|------|------|
|
|
43
45
|
| `RuleGoEditor` | 规则链编辑器 | 完整的可视化编辑器(内置工具栏、侧边栏、属性面板等全部 UI)|
|
|
44
|
-
| `WorkflowList` | 工作流列表 |
|
|
46
|
+
| `WorkflowList` | 工作流列表 | 卡片/列表两种布局,支持搜索、创建、上线/下线、复制、删除、详情联动和设计跳转 |
|
|
45
47
|
| `WorkflowInfoPanel` | 工作流信息面板 | 展示单条链的详细信息和配置 |
|
|
46
48
|
|
|
47
49
|
---
|
|
@@ -60,7 +62,7 @@ function EditorPage({ chainId }: { chainId: string }) {
|
|
|
60
62
|
const [chainData, setChainData] = useState(null)
|
|
61
63
|
|
|
62
64
|
useEffect(() => {
|
|
63
|
-
fetch(`http://localhost:9090/api/v1/
|
|
65
|
+
fetch(`http://localhost:9090/api/v1/rules/${encodeURIComponent(chainId)}`)
|
|
64
66
|
.then(res => res.json())
|
|
65
67
|
.then(data => setChainData(data))
|
|
66
68
|
}, [chainId])
|
|
@@ -95,25 +97,65 @@ function EditorPage({ chainId }: { chainId: string }) {
|
|
|
95
97
|
| `data` | `RuleChainData \| null` | `null` | 规则链数据 |
|
|
96
98
|
| `apiBase` | `string` | - | 后端 API 地址(如 `http://localhost:9090/api/v1`)|
|
|
97
99
|
| `theme` | `string` | `'modern'` | 主题:`classic` / `dark` / `nature` / `elegant` / `tech` / `modern` |
|
|
98
|
-
| `
|
|
100
|
+
| `locale` | `string` | `'zh-CN'` | 语言:`zh-CN` / `en-US` |
|
|
99
101
|
| `toolbarTitle` | `string` | - | 工具栏标题 |
|
|
100
102
|
| `showChainInfo` | `boolean` | `true` | 是否显示链信息头部 |
|
|
101
103
|
| `height` | `string \| number` | `'100%'` | 编辑器高度 |
|
|
102
104
|
| `width` | `string \| number` | `'100%'` | 编辑器宽度 |
|
|
103
105
|
| `className` | `string` | `''` | 自定义 className |
|
|
104
106
|
| `style` | `CSSProperties` | `{}` | 自定义样式 |
|
|
107
|
+
| `fetchHeaders` | `Record<string,string> \| () => Record<string,string>` | - | 给编辑器内部请求注入认证 headers |
|
|
108
|
+
| `customFetch` | `(url, init) => Promise<Response>` | - | 完全替换请求逻辑 |
|
|
109
|
+
| `showSettingsButton` | `boolean` | `true` | 是否显示设置入口 |
|
|
110
|
+
| `showAiChatButton` | `boolean` | `true` | 是否显示 AI 助理入口 |
|
|
111
|
+
| `showRunButton` | `boolean` | `true` | 是否显示运行调试入口 |
|
|
112
|
+
| `options` | `Partial<HuanbanRulegoEditorOptions>` | - | 透传 core 扩展配置,如 `onSettingsSubmit/onLoginClick/allowedApiOrigins` |
|
|
105
113
|
| `onReady` | `({ core, lf }) => void` | - | 编辑器就绪回调 |
|
|
106
114
|
| `onNodeClick` | `(node) => void` | - | 节点点击回调 |
|
|
107
115
|
| `onNodeDbClick` | `(node) => void` | - | 节点双击回调 |
|
|
108
116
|
| `onEdgeClick` | `(edge) => void` | - | 边点击回调 |
|
|
109
|
-
| `
|
|
110
|
-
| `
|
|
117
|
+
| `onSave` | `(data) => void \| Promise<void>` | - | 保存回调 |
|
|
118
|
+
| `onDeploy` | `(chainId, action) => void \| Promise<void>` | - | 部署/下线/重载回调 |
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
### 服务地址、设置和登录
|
|
123
|
+
|
|
124
|
+
完整编辑器内置设置入口。客户项目通常需要把后台地址和登录态交给宿主管理:
|
|
125
|
+
|
|
126
|
+
```tsx
|
|
127
|
+
<RuleGoEditor
|
|
128
|
+
apiBase={apiBase}
|
|
129
|
+
data={chainData}
|
|
130
|
+
fetchHeaders={() => {
|
|
131
|
+
const token = localStorage.getItem('token') || localStorage.getItem('access_token')
|
|
132
|
+
return token ? { Authorization: `Bearer ${token}` } : {}
|
|
133
|
+
}}
|
|
134
|
+
showSettingsButton
|
|
135
|
+
options={{
|
|
136
|
+
allowedApiOrigins: [new URL(apiBase, window.location.origin).origin],
|
|
137
|
+
onSettingsSubmit: ({ apiBase }) => {
|
|
138
|
+
localStorage.setItem('huanban_rulego_api_base', apiBase)
|
|
139
|
+
setApiBase(apiBase)
|
|
140
|
+
},
|
|
141
|
+
onLoginClick: () => window.dispatchEvent(new CustomEvent('open-login')),
|
|
142
|
+
onAuthExpired: () => window.dispatchEvent(new CustomEvent('open-login')),
|
|
143
|
+
clearToken: () => {
|
|
144
|
+
localStorage.removeItem('token')
|
|
145
|
+
localStorage.removeItem('access_token')
|
|
146
|
+
localStorage.removeItem('username')
|
|
147
|
+
},
|
|
148
|
+
}}
|
|
149
|
+
/>
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
如果不传 `onLoginClick`,内置设置页会打开默认登录弹窗,并请求 `POST {apiBase}/login`。完整新项目接入说明见根目录 [docs/CLIENT_INTEGRATION.md](../../docs/CLIENT_INTEGRATION.md)。
|
|
111
153
|
|
|
112
154
|
---
|
|
113
155
|
|
|
114
156
|
## 二、WorkflowList — 工作流列表
|
|
115
157
|
|
|
116
|
-
|
|
158
|
+
展示所有规则链,支持搜索、分页、创建、上线/下线、复制、删除、详情联动和编辑跳转。它是独立管理组件,不是编辑器;进入画布编辑需要在 `onDesign` 中切换到 `RuleGoEditor`。
|
|
117
159
|
|
|
118
160
|
### 基本用法
|
|
119
161
|
|
|
@@ -125,8 +167,9 @@ function WorkflowPage() {
|
|
|
125
167
|
return (
|
|
126
168
|
<WorkflowList
|
|
127
169
|
apiBase="http://localhost:9090/api/v1"
|
|
128
|
-
|
|
129
|
-
|
|
170
|
+
layout="grid"
|
|
171
|
+
onDesign={(id) => {
|
|
172
|
+
window.location.href = `/editor/${id}`
|
|
130
173
|
}}
|
|
131
174
|
/>
|
|
132
175
|
)
|
|
@@ -138,11 +181,19 @@ function WorkflowPage() {
|
|
|
138
181
|
| 属性 | 类型 | 必填 | 说明 |
|
|
139
182
|
|------|------|------|------|
|
|
140
183
|
| `apiBase` | `string` | ✅ | 后端 API 地址 |
|
|
141
|
-
| `
|
|
142
|
-
| `
|
|
143
|
-
| `
|
|
184
|
+
| `apiOptions` | `Partial<RuleChainAPIOptions>` | ❌ | 传给内置 `RuleChainAPI` 的请求配置 |
|
|
185
|
+
| `fetcher` | `WorkflowFetcher` | ❌ | 自定义请求适配器,传入后忽略 `apiBase` |
|
|
186
|
+
| `layout` | `'grid' \| 'list'` | ❌ | 默认 `grid`,卡片管理页;传 `list` 使用紧凑列表 |
|
|
187
|
+
| `autoOpenAfterCreate` | `boolean` | ❌ | 传了 `onDesign` 时默认开启;新建成功后自动进入编辑器 |
|
|
188
|
+
| `onDesign` | `(chainId: string) => void` | ❌ | 点击“设计”按钮的回调,宿主在这里进入编辑器 |
|
|
189
|
+
| `onInfo` | `(workflow: WorkflowItem) => void` | ❌ | 单击卡片或点击“信息”后的回调 |
|
|
190
|
+
| `onViewLogs` | `(chainId: string) => void` | ❌ | 点击“日志”按钮的回调 |
|
|
191
|
+
| `onCreateSuccess` | `(chainId: string) => void` | ❌ | 创建成功后的通知回调;进入编辑器建议交给 `onDesign` |
|
|
192
|
+
| `icons` | `WorkflowListIcons` | ❌ | 自定义图标 |
|
|
144
193
|
| `theme` | `WorkflowTheme` | ❌ | 自定义主题色 |
|
|
145
194
|
|
|
195
|
+
默认新建弹窗包含 ID、名称、主链/子链、初始状态、调试模式、分类、描述。ID 自动生成,也可手动输入;为兼容后台路由,ID 不能包含 `/`、`\` 或 `.`。卡片单击会调用 `onInfo`,双击或菜单“设计”会调用 `onDesign`。
|
|
196
|
+
|
|
146
197
|
---
|
|
147
198
|
|
|
148
199
|
## 三、WorkflowInfoPanel — 工作流信息面板
|
|
@@ -155,11 +206,11 @@ function WorkflowPage() {
|
|
|
155
206
|
import { WorkflowInfoPanel } from '@huanban/rulego-editor-react'
|
|
156
207
|
import '@huanban/rulego-editor-react/style.css'
|
|
157
208
|
|
|
158
|
-
function InfoPage({
|
|
209
|
+
function InfoPage({ workflow }) {
|
|
159
210
|
return (
|
|
160
211
|
<WorkflowInfoPanel
|
|
161
212
|
apiBase="http://localhost:9090/api/v1"
|
|
162
|
-
|
|
213
|
+
workflow={workflow}
|
|
163
214
|
onRefresh={() => { /* 重新加载数据 */ }}
|
|
164
215
|
/>
|
|
165
216
|
)
|
|
@@ -171,11 +222,11 @@ function InfoPage({ workflowItem }) {
|
|
|
171
222
|
| 属性 | 类型 | 必填 | 说明 |
|
|
172
223
|
|------|------|------|------|
|
|
173
224
|
| `apiBase` | `string` | ✅ | 后端 API 地址 |
|
|
174
|
-
| `
|
|
225
|
+
| `workflow` | `WorkflowItem \| null` | ✅ | 工作流数据 |
|
|
175
226
|
| `onRefresh` | `() => void` | ❌ | 刷新回调 |
|
|
176
227
|
| `extraTabs` | `ExtraTab[]` | ❌ | 自定义扩展 Tab |
|
|
177
|
-
| `
|
|
178
|
-
| `
|
|
228
|
+
| `fetcher` | `WorkflowFetcher` | ❌ | 自定义请求适配器,传入后忽略 `apiBase` |
|
|
229
|
+
| `icons` | `WorkflowInfoIcons` | ❌ | 自定义图标 |
|
|
179
230
|
| `theme` | `WorkflowTheme` | ❌ | 自定义主题色 |
|
|
180
231
|
|
|
181
232
|
---
|
|
@@ -198,7 +249,7 @@ function App() {
|
|
|
198
249
|
|
|
199
250
|
useEffect(() => {
|
|
200
251
|
if (!chainId) return
|
|
201
|
-
fetch(`${API_BASE}/
|
|
252
|
+
fetch(`${API_BASE}/rules/${encodeURIComponent(chainId)}`)
|
|
202
253
|
.then(res => res.json())
|
|
203
254
|
.then(data => setChainData(data))
|
|
204
255
|
}, [chainId])
|
|
@@ -207,8 +258,9 @@ function App() {
|
|
|
207
258
|
return (
|
|
208
259
|
<WorkflowList
|
|
209
260
|
apiBase={API_BASE}
|
|
210
|
-
|
|
211
|
-
|
|
261
|
+
layout="grid"
|
|
262
|
+
onDesign={(id) => {
|
|
263
|
+
setChainId(id)
|
|
212
264
|
setView('editor')
|
|
213
265
|
}}
|
|
214
266
|
/>
|
|
@@ -11,8 +11,9 @@
|
|
|
11
11
|
* 6. 事件回调: onSave / onError / onRefresh
|
|
12
12
|
*
|
|
13
13
|
* Tab 页:
|
|
14
|
-
* -
|
|
15
|
-
* -
|
|
14
|
+
* - 基础信息(ID/名称/根规则链/调试模式/分类/描述/状态)
|
|
15
|
+
* - 输入定义(可视化/JSON Schema 编辑)
|
|
16
|
+
* - 变量(变量与秘钥 key-value 编辑)
|
|
16
17
|
* - 应用集成(API/MCP 地址展示)
|
|
17
18
|
* - 自定义 Tab(通过 renderExtraTabs 扩展)
|
|
18
19
|
*
|
|
@@ -63,6 +64,9 @@ export interface WorkflowInfoPanelProps {
|
|
|
63
64
|
export interface WorkflowIntegrationUrls {
|
|
64
65
|
executeUrl: string;
|
|
65
66
|
notifyUrl: string;
|
|
67
|
+
openaiUrl: string;
|
|
68
|
+
mcpStreamableUrl: string;
|
|
69
|
+
mcpGroupUrl: string;
|
|
66
70
|
mcpSseUrl: string;
|
|
67
71
|
debugWsUrl: string;
|
|
68
72
|
runtimeWsUrl: string;
|
|
@@ -42,6 +42,10 @@ export interface WorkflowListProps {
|
|
|
42
42
|
fetcher?: WorkflowFetcher;
|
|
43
43
|
/** 每页条数,默认 10 */
|
|
44
44
|
pageSize?: number;
|
|
45
|
+
/** 列表布局。grid 更适合作为管理页卡片墙,list 保留旧列表风格。 */
|
|
46
|
+
layout?: 'grid' | 'list';
|
|
47
|
+
/** 新建成功后是否自动调用 onDesign 进入编辑器。默认在传入 onDesign 时开启。 */
|
|
48
|
+
autoOpenAfterCreate?: boolean;
|
|
45
49
|
/** 主题 */
|
|
46
50
|
theme?: WorkflowTheme;
|
|
47
51
|
/** 额外 CSS 类名 */
|