Skip to content

Commit c8347d1

Browse files
author
昔梦
committed
feat:整理画布完成后透出一个函数onAutoLayoutCompleted,让用户可以自定义
1 parent 14bcbc8 commit c8347d1

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

docs/xflow/api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ group:
8080
| hideAutoLayout | 是否隐藏整理画布功能 | `boolean` | false |
8181
| hideFullscreen | 是否隐藏全屏功能 | `boolean` | false |
8282
| hideInteractionMode | 是否隐藏指针和手形工具切换功能 | `boolean` | false |
83+
| onAutoLayoutCompleted | 整理画布完成后的回调函数,接收整理后的节点数组作为参数,支持异步函数 | `(nodes: node[]) => void \| Promise<void>` | - |
8384

8485

8586

docs/xflow/demo/nodeSetting/fullDemo/index.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import XFlow from '@xrenders/xflow';
33
import { settings } from './settings';
44
import CustomSvg from './CustomSvg';
55
import CustomImg from './CustomImg';
6+
import { message } from 'antd';
67

78

89
const initialValues = {
@@ -94,6 +95,15 @@ const Demo = () => {
9495
nodeSelector={{
9596
showSearch: true,
9697
}}
98+
globalConfig={{
99+
controls: {
100+
onAutoLayoutCompleted: async (nodes) => {
101+
console.log('整理画布完成,节点数量:', nodes.length);
102+
console.log('整理后的节点数据:', nodes);
103+
message.success(`画布已整理完成,共 ${nodes.length} 个节点`);
104+
}
105+
}
106+
}}
97107
/>
98108
</div>
99109
);

packages/x-flow/src/XFlow.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ const XFlow: FC<FlowProps> = memo(props => {
210210
);
211211

212212
const { eventEmitter } = useEventEmitterContextContext();
213-
eventEmitter?.useSubscription((v: any) => {
213+
eventEmitter?.useSubscription(async (v: any) => {
214214
// 整理画布
215215
if (v.type === 'auto-layout-nodes') {
216216
const newNodes: any = autoLayoutNodes(
@@ -219,6 +219,12 @@ const XFlow: FC<FlowProps> = memo(props => {
219219
layout
220220
);
221221
setNodes(newNodes, false);
222+
223+
// 整理画布完成后执行回调
224+
const onAutoLayoutCompleted = globalConfig?.controls?.onAutoLayoutCompleted;
225+
if (onAutoLayoutCompleted) {
226+
await onAutoLayoutCompleted(newNodes);
227+
}
222228
}
223229

224230
if (v.type === 'deleteNode') {

packages/x-flow/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ export interface TControl{
138138
hideAutoLayout?: boolean
139139
hideFullscreen?: boolean
140140
hideInteractionMode?: boolean
141+
onAutoLayoutCompleted?: (nodes: node[]) => void | Promise<void>; // 整理画布完成后的回调函数
141142
}
142143

143144
export interface THandle{

0 commit comments

Comments
 (0)