File tree Expand file tree Collapse file tree 4 files changed +19
-1
lines changed
demo/nodeSetting/fullDemo Expand file tree Collapse file tree 4 files changed +19
-1
lines changed Original file line number Diff line number Diff line change 8080| hideAutoLayout | 是否隐藏整理画布功能 | ` boolean ` | false |
8181| hideFullscreen | 是否隐藏全屏功能 | ` boolean ` | false |
8282| hideInteractionMode | 是否隐藏指针和手形工具切换功能 | ` boolean ` | false |
83+ | onAutoLayoutCompleted | 整理画布完成后的回调函数,接收整理后的节点数组作为参数,支持异步函数 | ` (nodes: node[]) => void \| Promise<void> ` | - |
8384
8485
8586
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import XFlow from '@xrenders/xflow';
33import { settings } from './settings' ;
44import CustomSvg from './CustomSvg' ;
55import CustomImg from './CustomImg' ;
6+ import { message } from 'antd' ;
67
78
89const 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 ) ;
Original file line number Diff line number Diff 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' ) {
Original file line number Diff line number Diff 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
143144export interface THandle {
You can’t perform that action at this time.
0 commit comments