@huanban/rulego-editor-vue 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 CHANGED
@@ -10,7 +10,8 @@
10
10
  - **开箱即用** — 提供 `<RuleGoEditor />` 组件,一行代码嵌入编辑器
11
11
  - **Vue 3 Composables** — `useEditorCore`、`useEditorTheme`、`useEditorI18n`
12
12
  - **事件监听** — 支持 `@save`、`@node-click`、`@ready` 等 Vue 事件
13
- - **插槽系统** — 通过 `#sidebar`、`#toolbar`、`#panel` 插槽自定义 UI
13
+ - **完整内置 UI** — 工具栏、侧边栏、属性抽屉、设置、AI 助理、运行调试由 core 统一提供
14
+ - **独立管理组件** — `WorkflowList` / `WorkflowInfoPanel` 可组合出列表、详情和编辑器联动页面
14
15
  - **响应式状态** — 所有状态自动转为 Vue `ref`,模板中直接使用
15
16
  - **TypeScript** — 完整类型定义
16
17
  - **兼容 Vue 3.2+** — 支持 Composition API
@@ -31,17 +32,32 @@ npm install @huanban/rulego-editor-ui
31
32
  ```vue
32
33
  <template>
33
34
  <RuleGoEditor
34
- height="600px"
35
+ height="100vh"
35
36
  :data="ruleChainData"
37
+ :components="components"
38
+ :options="editorOptions"
36
39
  @save="onSave"
37
40
  @node-click="onNodeClick"
38
41
  />
39
42
  </template>
40
43
 
41
44
  <script setup lang="ts">
45
+ import { computed, ref } from 'vue'
42
46
  import { RuleGoEditor } from '@huanban/rulego-editor-vue'
47
+ import '@huanban/rulego-editor-vue/style.css'
43
48
 
44
- const ruleChainData = ref(null)
49
+ const apiBase = ref('http://127.0.0.1:9090/api/v1')
50
+ const ruleChainData = ref<any>(null)
51
+ const components = ref<any[]>([])
52
+
53
+ const editorOptions = computed(() => ({
54
+ apiBase: apiBase.value,
55
+ showToolbar: true,
56
+ showSidebar: true,
57
+ showSettingsButton: true,
58
+ showAiChatButton: true,
59
+ showRunButton: true,
60
+ }))
45
61
 
46
62
  const onSave = (data) => console.log('保存:', data)
47
63
  const onNodeClick = (node) => console.log('点击节点:', node)
@@ -74,11 +90,15 @@ watch(isReady, (ready) => {
74
90
 
75
91
  | 属性 | 类型 | 说明 |
76
92
  |------|------|------|
77
- | `data` | `RuleChainData` | 规则链数据 |
78
- | `options` | `EditorOptions` | 编辑器配置选项 |
79
- | `height` | `string` | 编辑器高度 (默认 `100%`) |
80
- | `width` | `string` | 编辑器宽度 (默认 `100%`) |
81
- | `builtinUi` | `boolean` | 是否使用内置 UI (默认 `true`) |
93
+ | `data` | `RuleChainData \| null` | 规则链数据 |
94
+ | `components` | `RawComponentData` | 组件列表,可不传;有 `options.apiBase` 时会自动请求 `/components` |
95
+ | `options` | `Partial<HuanbanRulegoEditorOptions>` | 透传 core 配置,如 `apiBase/fetchHeaders/onSettingsSubmit/onLoginClick` |
96
+ | `height` | `string \| number` | 编辑器高度,默认 `100%` |
97
+ | `width` | `string \| number` | 编辑器宽度,默认 `100%` |
98
+ | `theme` | `string` | 主题名称 |
99
+ | `className` | `string` | 自定义 class |
100
+ | `customStyle` | `Record<string,string \| number>` | 自定义内联样式 |
101
+ | `renderNode` | `(type, data, model) => VNode` | 自定义 Headless 节点渲染 |
82
102
 
83
103
  ### 事件
84
104
 
@@ -87,14 +107,84 @@ watch(isReady, (ready) => {
87
107
  | `@save` | `SaveEventData` | 保存时触发 |
88
108
  | `@node-click` | `NodeData` | 节点点击时触发 |
89
109
  | `@ready` | — | 编辑器就绪时触发 |
110
+ | `@change` | — | 画布数据变化 |
111
+ | `@edge-click` | `EdgeData` | 连线点击 |
112
+ | `@deploy` | `chainId, action` | 部署/下线/重载 |
90
113
 
91
- ### 插槽
114
+ ### `<WorkflowList />` 管理列表
92
115
 
93
- | 插槽 | 参数 | 说明 |
94
- |------|------|------|
95
- | `#sidebar` | `{ groups, core }` | 自定义侧边栏 |
96
- | `#toolbar` | `{ canUndo, canRedo, core }` | 自定义工具栏 |
97
- | `#panel` | `{ nodeView, nodeModel, core }` | 自定义属性面板 |
116
+ `WorkflowList` 是独立管理组件,不是编辑器。它负责查询、搜索、创建、上线/下线、复制、删除和选择规则链;进入画布编辑需要通过 `:on-design` 切换到 `<RuleGoEditor />`。
117
+
118
+ ```vue
119
+ <template>
120
+ <section class="workspace">
121
+ <WorkflowList
122
+ :api-base="apiBase"
123
+ layout="grid"
124
+ :on-info="workflow => selectedWorkflow = workflow"
125
+ :on-design="openEditor"
126
+ />
127
+ <WorkflowInfoPanel
128
+ :api-base="apiBase"
129
+ :workflow="selectedWorkflow"
130
+ />
131
+ </section>
132
+ </template>
133
+
134
+ <script setup lang="ts">
135
+ import { ref } from 'vue'
136
+ import { WorkflowInfoPanel, WorkflowList } from '@huanban/rulego-editor-vue'
137
+
138
+ const apiBase = 'http://127.0.0.1:9090/api/v1'
139
+ const selectedWorkflow = ref<any>(null)
140
+
141
+ async function openEditor(id: string) {
142
+ const response = await fetch(`${apiBase}/rules/${encodeURIComponent(id)}`)
143
+ const chainData = await response.json()
144
+ console.log('switch to editor with', chainData)
145
+ }
146
+ </script>
147
+ ```
148
+
149
+ 常用属性:
150
+
151
+ | 属性 | 说明 |
152
+ |------|------|
153
+ | `layout` | 默认 `grid` 卡片布局;传 `list` 使用紧凑列表 |
154
+ | `autoOpenAfterCreate` | 传了 `onDesign` 时默认开启;新建成功后自动进入编辑器 |
155
+ | `onDesign` | 双击卡片或点击菜单“设计”时触发,宿主在这里打开编辑器 |
156
+ | `onInfo` | 单击卡片或点击菜单“信息”时触发,宿主在这里联动详情 |
157
+
158
+ 默认新建弹窗包含 ID、名称、主链/子链、初始状态、调试模式、分类、描述。ID 自动生成,也可手动输入;为兼容后台路由,ID 不能包含 `/`、`\` 或 `.`。
159
+
160
+ ### 服务地址、设置和登录
161
+
162
+ Vue 版通过 `:options` 传入后台地址、认证和设置回调:
163
+
164
+ ```ts
165
+ const editorOptions = computed(() => ({
166
+ apiBase: apiBase.value,
167
+ allowedApiOrigins: [new URL(apiBase.value, window.location.origin).origin],
168
+ showSettingsButton: true,
169
+ fetchHeaders: () => {
170
+ const token = localStorage.getItem('token') || localStorage.getItem('access_token')
171
+ return token ? { Authorization: `Bearer ${token}` } : {}
172
+ },
173
+ onSettingsSubmit: ({ apiBase: nextApiBase }: { apiBase: string }) => {
174
+ localStorage.setItem('huanban_rulego_api_base', nextApiBase)
175
+ apiBase.value = nextApiBase
176
+ },
177
+ onLoginClick: () => window.dispatchEvent(new CustomEvent('open-login')),
178
+ onAuthExpired: () => window.dispatchEvent(new CustomEvent('open-login')),
179
+ clearToken: () => {
180
+ localStorage.removeItem('token')
181
+ localStorage.removeItem('access_token')
182
+ localStorage.removeItem('username')
183
+ },
184
+ }))
185
+ ```
186
+
187
+ 如果不传 `onLoginClick`,内置设置页会打开默认登录弹窗,并请求 `POST {apiBase}/login`。完整新项目接入说明见根目录 [docs/CLIENT_INTEGRATION.md](../../docs/CLIENT_INTEGRATION.md)。
98
188
 
99
189
  ### `useEditorCore(options?)` 返回值
100
190
 
@@ -40,10 +40,10 @@ export interface WorkflowInfoPanelProps {
40
40
  declare var __VLS_1: {
41
41
  workflow: WorkflowItem;
42
42
  defaultPanel: null;
43
- }, __VLS_3: {
43
+ }, __VLS_13: {
44
44
  workflow: WorkflowItem;
45
45
  defaultPanel: null;
46
- }, __VLS_19: {
46
+ }, __VLS_29: {
47
47
  workflow: WorkflowItem;
48
48
  apiBase: any;
49
49
  defaultPanel: null;
@@ -51,9 +51,9 @@ declare var __VLS_1: {
51
51
  type __VLS_Slots = {} & {
52
52
  baseInfo?: (props: typeof __VLS_1) => any;
53
53
  } & {
54
- varsSecrets?: (props: typeof __VLS_3) => any;
54
+ varsSecrets?: (props: typeof __VLS_13) => any;
55
55
  } & {
56
- integration?: (props: typeof __VLS_19) => any;
56
+ integration?: (props: typeof __VLS_29) => any;
57
57
  };
58
58
  declare const __VLS_base: import("vue").DefineComponent<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<WorkflowInfoPanelProps>, {
59
59
  theme: string;
@@ -5,6 +5,8 @@ export interface WorkflowListProps {
5
5
  apiOptions?: Partial<RuleChainAPIOptions>;
6
6
  fetcher?: WorkflowFetcher;
7
7
  pageSize?: number;
8
+ layout?: 'grid' | 'list';
9
+ autoOpenAfterCreate?: boolean;
8
10
  theme?: WorkflowTheme;
9
11
  className?: string;
10
12
  style?: object;
@@ -51,7 +53,7 @@ declare var __VLS_1: {}, __VLS_3: {}, __VLS_5: {}, __VLS_7: {}, __VLS_9: {}, __V
51
53
  };
52
54
  }, __VLS_23: {}, __VLS_25: {}, __VLS_27: {}, __VLS_29: {}, __VLS_31: {}, __VLS_33: {}, __VLS_35: {}, __VLS_37: {
53
55
  submit: (data?: Record<string, unknown>) => Promise<void>;
54
- close: () => boolean;
56
+ close: () => void;
55
57
  };
56
58
  type __VLS_Slots = {} & {
57
59
  header?: (props: typeof __VLS_1) => any;
@@ -94,6 +96,7 @@ type __VLS_Slots = {} & {
94
96
  };
95
97
  declare const __VLS_base: import("vue").DefineComponent<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<WorkflowListProps>, {
96
98
  pageSize: number;
99
+ layout: string;
97
100
  theme: string;
98
101
  className: string;
99
102
  showSearch: boolean;
@@ -101,6 +104,7 @@ declare const __VLS_base: import("vue").DefineComponent<import("vue").ExtractPro
101
104
  showRefresh: boolean;
102
105
  }>>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<WorkflowListProps>, {
103
106
  pageSize: number;
107
+ layout: string;
104
108
  theme: string;
105
109
  className: string;
106
110
  showSearch: boolean;
@@ -110,6 +114,7 @@ declare const __VLS_base: import("vue").DefineComponent<import("vue").ExtractPro
110
114
  theme: WorkflowTheme;
111
115
  className: string;
112
116
  pageSize: number;
117
+ layout: "grid" | "list";
113
118
  showSearch: boolean;
114
119
  showCreate: boolean;
115
120
  showRefresh: boolean;