@huanban/rulego-editor-react 1.4.2 → 2.0.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 +20 -12
- package/dist/components/AIChat.d.ts +7 -0
- package/dist/components/ComponentSidebar.d.ts +10 -0
- package/dist/components/EditorToolbar.d.ts +1 -0
- package/dist/components/MiniMap.d.ts +1 -1
- package/dist/components/RuleGoEditor.d.ts +53 -3
- package/dist/components/SharedNodeManager.d.ts +12 -0
- package/dist/components/WorkspaceTabs.d.ts +4 -1
- package/dist/hooks/useClipboard.d.ts +4 -2
- package/dist/hooks/useDialogConfirmation.d.ts +4 -0
- package/dist/index.cjs +9 -9
- package/dist/index.d.ts +7 -2
- package/dist/index.esm.js +5091 -4529
- package/dist/style.css +1 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -124,11 +124,11 @@ function EditorPage({ chainId }: { chainId: string }) {
|
|
|
124
124
|
| `data` | `RuleChainData \| null` | `null` | 规则链数据 |
|
|
125
125
|
| `apiBase` | `string` | - | 后端 API 地址(如 `http://localhost:9090/api/v1`)|
|
|
126
126
|
| `components` | `RawComponentData` | - | 可选组件表;不传时按 `apiBase` 请求真实 `/components` |
|
|
127
|
-
| `mode` | `EditorMode` | `'standalone'` | standalone / embedded /
|
|
127
|
+
| `mode` | `EditorMode` | `'standalone'` | standalone / app / embedded / readonly;Headless Core 是独立用法,不是 mode 值 |
|
|
128
128
|
| `capabilities` | `EditorCapabilitiesOverride` | - | 覆盖当前模式的能力树 |
|
|
129
129
|
| `disabled` | `boolean` | `false` | 禁用编辑动作但保留查看能力 |
|
|
130
|
-
| `dataUpdatePolicy` | `'preserve-dirty' \| 'replace'` | `'
|
|
131
|
-
| `theme` | `string` | `'default'` | 主题:`default` / `
|
|
130
|
+
| `dataUpdatePolicy` | `'preserve-dirty' \| 'replace'` | `'replace'` | 外部数据更新策略;需要保护未保存修改时显式设 preserve-dirty |
|
|
131
|
+
| `theme` | `string` | `'default'` | 主题:`default` / `nature` / `elegant` / `tech` / `modern` 等;旧 `dark` 值兼容回退为 `default` |
|
|
132
132
|
| `locale` | `string` | `'zh-CN'` | 语言:`zh-CN` / `en-US` |
|
|
133
133
|
| `toolbarTitle` | `string` | - | 工具栏标题 |
|
|
134
134
|
| `height` | `string \| number` | `'100%'` | 编辑器高度 |
|
|
@@ -296,28 +296,36 @@ Vue 适配器使用同一契约:通过 `<RuleGoEditor :key="structuralConfigVe
|
|
|
296
296
|
默认不要传 `onSave`。只要配置了 `apiBase`,保存按钮会直接调用:
|
|
297
297
|
|
|
298
298
|
```text
|
|
299
|
-
POST {apiBase}/rules/:id
|
|
299
|
+
POST {apiBase}/rules/:id?versionMark=1
|
|
300
300
|
GET {apiBase}/rules/:id
|
|
301
301
|
```
|
|
302
302
|
|
|
303
|
-
第二次 `GET`
|
|
303
|
+
第二次 `GET` 用于回读校验,只有后端返回的数据与本次提交快照一致时才会显示已保存,
|
|
304
|
+
保存期间的新编辑仍保持未保存。草稿入口使用 `save({ draft: true })`,不带 `versionMark`。
|
|
305
|
+
正式保存会部署规则链,停止状态会先确认;保存全部和保存并关闭保留当前运行状态。
|
|
304
306
|
|
|
305
307
|
只有宿主确实要完全接管保存时才设置 `saveMode="host"` 并传 `saveHandler`。执行器必须
|
|
306
308
|
返回明确结果:
|
|
307
309
|
|
|
308
310
|
```tsx
|
|
311
|
+
import { RuleChainAPI, createRuleChainSaveFingerprint } from '@huanban/rulego-editor-core'
|
|
312
|
+
|
|
309
313
|
<RuleGoEditor
|
|
310
314
|
apiBase={apiBase}
|
|
311
315
|
data={chainData}
|
|
312
316
|
saveMode="host"
|
|
313
|
-
saveHandler={async (data: any) => {
|
|
317
|
+
saveHandler={async (data: any, options) => {
|
|
314
318
|
const id = data?.ruleChain?.id
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
319
|
+
const api = new RuleChainAPI({ apiBase, headers: fetchHeaders() })
|
|
320
|
+
const result = await api.create(data, options)
|
|
321
|
+
if (!result.success) return { success: false, message: result.msg }
|
|
322
|
+
// 宿主接管后也必须确认业务响应和实际持久化内容,不能只判断 HTTP 200。
|
|
323
|
+
const persisted: any = await api.getContent(id)
|
|
324
|
+
const verified = persisted.ruleChain?.id === id
|
|
325
|
+
&& Array.isArray(persisted.metadata?.nodes) && Array.isArray(persisted.metadata?.connections)
|
|
326
|
+
&& createRuleChainSaveFingerprint(persisted) === createRuleChainSaveFingerprint(data)
|
|
327
|
+
&& (persisted.ruleChain.disabled === true) === (data.ruleChain.disabled === true)
|
|
328
|
+
return { success: verified, message: verified ? undefined : '服务端回读内容与提交内容不一致' }
|
|
321
329
|
}}
|
|
322
330
|
/>
|
|
323
331
|
```
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { AIChatConnectionOptions } from '@huanban/rulego-editor-core';
|
|
3
|
+
import type { CopilotChatProps } from './CopilotChat';
|
|
4
|
+
export interface AIChatProps extends AIChatConnectionOptions, Omit<CopilotChatProps, 'ruleChainId' | 'apiBase' | 'endpoint' | 'fetchHeaders'> {
|
|
5
|
+
}
|
|
6
|
+
export declare const AIChat: React.FC<AIChatProps>;
|
|
7
|
+
export default AIChat;
|
|
@@ -13,13 +13,16 @@ export interface RuleGoComponent {
|
|
|
13
13
|
type: string;
|
|
14
14
|
category: string;
|
|
15
15
|
categoryPath?: string;
|
|
16
|
+
categoryLabel?: string;
|
|
16
17
|
subgroup?: string;
|
|
17
18
|
categorySubgroups?: Array<Record<string, unknown>>;
|
|
18
19
|
label?: string;
|
|
19
20
|
desc?: string;
|
|
21
|
+
keywords?: string | string[];
|
|
20
22
|
fields?: ComponentField[];
|
|
21
23
|
icon?: string;
|
|
22
24
|
background?: string;
|
|
25
|
+
color?: string;
|
|
23
26
|
order?: number;
|
|
24
27
|
disabled?: boolean;
|
|
25
28
|
notInput?: boolean;
|
|
@@ -30,8 +33,15 @@ export interface ComponentSidebarProps {
|
|
|
30
33
|
components: RuleGoComponent[];
|
|
31
34
|
onDragStart?: (component: RuleGoComponent) => void;
|
|
32
35
|
recentComponentTypes?: string[];
|
|
36
|
+
showRecent?: boolean;
|
|
33
37
|
collapsed?: boolean;
|
|
38
|
+
defaultCollapsed?: boolean;
|
|
39
|
+
showSearch?: boolean;
|
|
40
|
+
search?: string;
|
|
41
|
+
onSearchChange?: (search: string) => void;
|
|
34
42
|
searchPlaceholder?: string;
|
|
43
|
+
showNodeMgt?: boolean;
|
|
44
|
+
onOpenNodeMgt?: () => void;
|
|
35
45
|
locale?: string;
|
|
36
46
|
messages?: LocaleMessages;
|
|
37
47
|
t?: EditorTranslate;
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { HuanbanRulegoEditor } from '@huanban/rulego-editor-core';
|
|
3
|
-
import type { AIAssistantOpenOptions, ComponentManageDialogTab, EditorOptionsUpdateResult, EditorActionSource, EditorSaveHandler, EditorSaveMode, EditorSaveResult, ExternalDataUpdatePolicy, EditorMode, EditorCapabilitiesOverride, ConnectionStatusState, HuanbanRulegoEditorOptions, HuanbanRulegoEditorLoadOptions, NodePickerOpenOptions } from '@huanban/rulego-editor-core';
|
|
3
|
+
import type { AIAssistantOpenOptions, ComponentManageDialogTab, EditorOptionsUpdateResult, EditorActionSource, EditorSaveHandler, EditorSaveMode, EditorSaveOptions, EditorSaveResult, ExternalDataUpdatePolicy, EditorMode, EditorCapabilitiesOverride, ConnectionStatusState, HuanbanRulegoEditorOptions, HuanbanRulegoEditorLoadOptions, NodePickerOpenOptions, SettingsDialogTab, EditorRegionContext, EditorRegionId } from '@huanban/rulego-editor-core';
|
|
4
4
|
import type { EditorCore } from '@huanban/rulego-editor-core';
|
|
5
5
|
import type { RuleChainData, RawComponentData } from '@huanban/rulego-editor-core';
|
|
6
6
|
import LogicFlow from '@logicflow/core';
|
|
7
|
+
export type RuleGoEditorSlot = React.ReactNode | ((context: EditorRegionContext) => React.ReactNode);
|
|
8
|
+
export type RuleGoEditorSlots = Partial<Record<EditorRegionId, RuleGoEditorSlot>>;
|
|
9
|
+
export type RuleGoEditorPanelSlots = Record<string, RuleGoEditorSlot>;
|
|
7
10
|
export interface RuleGoEditorProps {
|
|
8
11
|
height?: string | number;
|
|
9
12
|
width?: string | number;
|
|
10
13
|
className?: string;
|
|
11
14
|
style?: React.CSSProperties;
|
|
15
|
+
slots?: RuleGoEditorSlots;
|
|
16
|
+
panelSlots?: RuleGoEditorPanelSlots;
|
|
12
17
|
apiBase?: string;
|
|
13
18
|
fetchTimeout?: number;
|
|
14
19
|
fetchHeaders?: Record<string, string> | (() => Record<string, string>);
|
|
@@ -18,10 +23,17 @@ export interface RuleGoEditorProps {
|
|
|
18
23
|
dataUpdatePolicy?: ExternalDataUpdatePolicy;
|
|
19
24
|
components?: RawComponentData;
|
|
20
25
|
enableConnectionStatus?: boolean;
|
|
26
|
+
visible?: boolean;
|
|
21
27
|
onConnectionStatusChange?: (state: Readonly<ConnectionStatusState>) => void;
|
|
22
28
|
showToolbar?: boolean;
|
|
23
29
|
mode?: EditorMode;
|
|
24
30
|
capabilities?: EditorCapabilitiesOverride;
|
|
31
|
+
toolbar?: HuanbanRulegoEditorOptions['toolbar'];
|
|
32
|
+
showWorkspaceTabs?: boolean;
|
|
33
|
+
workflowFetcher?: HuanbanRulegoEditorOptions['workflowFetcher'];
|
|
34
|
+
versionsFetcher?: HuanbanRulegoEditorOptions['versionsFetcher'];
|
|
35
|
+
globalConfigFetcher?: HuanbanRulegoEditorOptions['globalConfigFetcher'];
|
|
36
|
+
settingsPanes?: HuanbanRulegoEditorOptions['settingsPanes'];
|
|
25
37
|
disabled?: boolean;
|
|
26
38
|
toolbarTitle?: string;
|
|
27
39
|
showToolbarButtonLabels?: boolean;
|
|
@@ -47,10 +59,14 @@ export interface RuleGoEditorProps {
|
|
|
47
59
|
showTraceButton?: boolean;
|
|
48
60
|
showDebugTab?: boolean;
|
|
49
61
|
locale?: string;
|
|
62
|
+
messages?: HuanbanRulegoEditorOptions['messages'];
|
|
63
|
+
autoLoadLocales?: HuanbanRulegoEditorOptions['autoLoadLocales'];
|
|
50
64
|
theme?: string;
|
|
51
65
|
lfOptions?: Record<string, unknown>;
|
|
52
66
|
lfPlugins?: any[];
|
|
53
67
|
coreOptions?: Record<string, unknown>;
|
|
68
|
+
exportDataTransform?: HuanbanRulegoEditorOptions['exportDataTransform'];
|
|
69
|
+
onNodeConfigRequest?: HuanbanRulegoEditorOptions['onNodeConfigRequest'];
|
|
54
70
|
options?: Partial<HuanbanRulegoEditorOptions>;
|
|
55
71
|
onReady?: (ctx: {
|
|
56
72
|
lf: LogicFlow;
|
|
@@ -73,6 +89,7 @@ export interface RuleGoEditorProps {
|
|
|
73
89
|
}) => void;
|
|
74
90
|
onImportDSL?: (data: RuleChainData) => void;
|
|
75
91
|
onRunClick?: (chainId: string) => void;
|
|
92
|
+
onFlow?: HuanbanRulegoEditorOptions['onFlow'];
|
|
76
93
|
onTraceClick?: (chainInfo: any) => void;
|
|
77
94
|
onComponentManage?: (initialTab?: ComponentManageDialogTab) => void;
|
|
78
95
|
onLocaleChange?: (locale: string) => void;
|
|
@@ -101,21 +118,54 @@ export interface RuleGoEditorRef {
|
|
|
101
118
|
connectionStatus: HuanbanRulegoEditor['connectionStatus'] | null;
|
|
102
119
|
runtimeFields: HuanbanRulegoEditor['runtimeFields'];
|
|
103
120
|
loadData: (data: RuleChainData, options?: HuanbanRulegoEditorLoadOptions) => void;
|
|
121
|
+
render: HuanbanRulegoEditor['render'];
|
|
122
|
+
getData: HuanbanRulegoEditor['getData'];
|
|
123
|
+
applyRuleChainDraft: HuanbanRulegoEditor['applyRuleChainDraft'];
|
|
104
124
|
activateWorkspaceTab: (tabId: string) => boolean;
|
|
125
|
+
openRuleChain: (chain: string | RuleChainData) => Promise<boolean>;
|
|
126
|
+
openChain: HuanbanRulegoEditor['openChain'];
|
|
127
|
+
newRuleChain: HuanbanRulegoEditor['newRuleChain'];
|
|
128
|
+
renameWorkspaceRuleChain: HuanbanRulegoEditor['renameWorkspaceRuleChain'];
|
|
129
|
+
closeWorkspaceTab: (tabId: string) => Promise<boolean>;
|
|
130
|
+
save: (options?: EditorSaveOptions) => Promise<boolean>;
|
|
131
|
+
saveAll: () => Promise<boolean>;
|
|
132
|
+
showVersionHistory: () => void;
|
|
133
|
+
openGlobalConfig: HuanbanRulegoEditor['openGlobalConfig'];
|
|
134
|
+
showNodeLogSettings: HuanbanRulegoEditor['showNodeLogSettings'];
|
|
135
|
+
showChainLogSettings: HuanbanRulegoEditor['showChainLogSettings'];
|
|
136
|
+
setLocale: (locale: string) => void;
|
|
137
|
+
setLocales: HuanbanRulegoEditor['setLocales'];
|
|
138
|
+
reloadLocales: HuanbanRulegoEditor['reloadLocales'];
|
|
139
|
+
isDirty: HuanbanRulegoEditor['isDirty'];
|
|
140
|
+
flashNodes: HuanbanRulegoEditor['flashNodes'];
|
|
141
|
+
setSidebarExpanded: HuanbanRulegoEditor['setSidebarExpanded'];
|
|
105
142
|
loadComponents: (components: RawComponentData) => void;
|
|
106
143
|
exportData: () => RuleChainData | null;
|
|
107
144
|
toggleMiniMap: () => void;
|
|
108
145
|
autoLayout: () => void;
|
|
109
|
-
openSettings: (initialTab?:
|
|
110
|
-
|
|
146
|
+
openSettings: (initialTab?: SettingsDialogTab) => void;
|
|
147
|
+
getUiConfiguration: HuanbanRulegoEditor['getUiConfiguration'];
|
|
148
|
+
applyUiConfiguration: HuanbanRulegoEditor['applyUiConfiguration'];
|
|
149
|
+
resetUiConfiguration: HuanbanRulegoEditor['resetUiConfiguration'];
|
|
150
|
+
openAiAssistant: (options?: AIAssistantOpenOptions) => boolean;
|
|
151
|
+
openChat: HuanbanRulegoEditor['openChat'];
|
|
152
|
+
switchChatChain: HuanbanRulegoEditor['switchChatChain'];
|
|
111
153
|
closeAiAssistant: () => void;
|
|
112
154
|
startTour: () => boolean;
|
|
113
155
|
closeTour: () => void;
|
|
114
156
|
setTheme: (theme: string) => void;
|
|
157
|
+
refreshTheme: HuanbanRulegoEditor['refreshTheme'];
|
|
115
158
|
updateOptions: (patch: Partial<Omit<HuanbanRulegoEditorOptions, 'container'>>) => EditorOptionsUpdateResult | null;
|
|
116
159
|
refreshConnectionStatuses: () => void;
|
|
160
|
+
setVisible: HuanbanRulegoEditor['setVisible'];
|
|
117
161
|
acquireSharedConnectionStatuses: () => () => void;
|
|
118
162
|
invokeAction: (id: string, source?: EditorActionSource) => Promise<boolean>;
|
|
163
|
+
listActions: HuanbanRulegoEditor['listActions'];
|
|
164
|
+
addAction: HuanbanRulegoEditor['addAction'];
|
|
165
|
+
removeAction: HuanbanRulegoEditor['removeAction'];
|
|
166
|
+
registerPropertyComponent: HuanbanRulegoEditor['registerPropertyComponent'];
|
|
167
|
+
resolvePropertyComponent: HuanbanRulegoEditor['resolvePropertyComponent'];
|
|
168
|
+
unregisterPropertyComponent: HuanbanRulegoEditor['unregisterPropertyComponent'];
|
|
119
169
|
openCommandPalette: () => void;
|
|
120
170
|
openShortcutHelp: () => void;
|
|
121
171
|
openNodePicker: (options?: NodePickerOpenOptions) => void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { SharedNodeManager as Manager, SharedNodeManagerContext } from '@huanban/rulego-editor-core';
|
|
3
|
+
import type { FrameworkI18nProps } from '../i18n';
|
|
4
|
+
export interface SharedNodeManagerProps extends Omit<SharedNodeManagerContext, 't' | '_activeDrawerWrapper'>, FrameworkI18nProps {
|
|
5
|
+
active?: boolean;
|
|
6
|
+
theme?: string;
|
|
7
|
+
className?: string;
|
|
8
|
+
style?: React.CSSProperties;
|
|
9
|
+
}
|
|
10
|
+
export type SharedNodeManagerRef = Pick<Manager, 'reload' | 'isDirty' | 'requestClose'>;
|
|
11
|
+
export declare const SharedNodeManager: React.ForwardRefExoticComponent<SharedNodeManagerProps & React.RefAttributes<SharedNodeManagerRef>>;
|
|
12
|
+
export default SharedNodeManager;
|
|
@@ -12,6 +12,9 @@ export interface WorkspaceTabsProps {
|
|
|
12
12
|
onEditInfo?: (tabId: string) => void;
|
|
13
13
|
onTabAction?: (tabId: string, action: EditorWorkspaceTabAction) => void;
|
|
14
14
|
hideAdd?: boolean;
|
|
15
|
+
hideOverflow?: boolean;
|
|
16
|
+
hideClose?: boolean;
|
|
17
|
+
hiddenTabActions?: readonly EditorWorkspaceTabAction[];
|
|
15
18
|
}
|
|
16
|
-
export declare function WorkspaceTabs({ tabs, activeTabId, locale, t, onActivate, onClose, onAdd, onEditInfo, onTabAction, hideAdd, }: WorkspaceTabsProps): React.JSX.Element;
|
|
19
|
+
export declare function WorkspaceTabs({ tabs, activeTabId, locale, t, onActivate, onClose, onAdd, onEditInfo, onTabAction, hideAdd, hideOverflow, hideClose, hiddenTabActions, }: WorkspaceTabsProps): React.JSX.Element;
|
|
17
20
|
export default WorkspaceTabs;
|
|
@@ -10,7 +10,9 @@ export interface ClipboardNode {
|
|
|
10
10
|
export interface ClipboardCallbacks {
|
|
11
11
|
getSelectedNodes?: () => ClipboardNode[];
|
|
12
12
|
getExistingNodeIds?: () => Iterable<string>;
|
|
13
|
-
confirmDeleteNodes?: (nodeIds: string[]) => boolean
|
|
13
|
+
confirmDeleteNodes?: (nodeIds: string[]) => boolean | Promise<boolean>;
|
|
14
|
+
getContext?: () => unknown;
|
|
15
|
+
canDeleteNodes?: () => boolean;
|
|
14
16
|
onDeleteNodes?: (nodeIds: string[]) => void;
|
|
15
17
|
onAddNodes?: (nodes: ClipboardNode[]) => void;
|
|
16
18
|
onSelectAll?: () => void;
|
|
@@ -18,7 +20,7 @@ export interface ClipboardCallbacks {
|
|
|
18
20
|
}
|
|
19
21
|
export interface ClipboardManager {
|
|
20
22
|
copy: () => void;
|
|
21
|
-
cut: () => void
|
|
23
|
+
cut: () => Promise<void>;
|
|
22
24
|
paste: () => void;
|
|
23
25
|
selectAll: () => void;
|
|
24
26
|
hasContent: boolean;
|