https://antv-xflow.gitee.io/zh-CN/docs/tutorial-advanced/hook
    支持的 hooks

    1. graphOptions x6 graph 配置项
    2. x6Events 绑定X6的事件
    3. reactNodeRender 自定义节点React组件
    4. reactEdgeLabelRender 自定义连线label的React组件
    5. afterGraphInit 在Graph 实例化后执行的逻辑
    6. beforeGraphDestroy 在Graph 销毁前执行的逻辑

    image.png

    1. const useGraphHookConfig = createHookConfig((config, proxy) => {
    2. // 获取 Props
    3. const props = proxy.getValue()
    4. config.setRegisterHook(hooks => {
    5. const disposableList = [
    6. // 注册增加 react Node Render
    7. hooks.reactNodeRender.registerHook({
    8. name: 'add react node',
    9. handler: async renderMap => {
    10. renderMap.set(DND_RENDER_ID, AlgoNode)
    11. renderMap.set(GROUP_NODE_RENDER_ID, GroupNode)
    12. },
    13. }),
    14. // 注册修改graphOptions配置的钩子
    15. hooks.graphOptions.registerHook({
    16. name: 'custom-x6-options',
    17. after: 'dag-extension-x6-options',
    18. handler: async options => {
    19. // 画布配置
    20. options.grid = {
    21. size: 8,
    22. visible: true,
    23. }
    24. options.keyboard = {
    25. enabled: true,
    26. }
    27. },
    28. }),
    29. // 注册增加 graph event
    30. hooks.x6Events.registerHook({
    31. name: 'add',
    32. handler: async events => {
    33. events.push({
    34. eventName: 'node:moved',
    35. callback: (e, cmds) => {
    36. const {node} = e
    37. cmds.executeCommand<NsNodeCmd.MoveNode.IArgs>(XFlowNodeCommands.MOVE_NODE.id, {
    38. id: node.id,
    39. position: node.getPosition(),
    40. })
    41. },
    42. } as NsGraph.IEvent<'node:moved'>)
    43. },
    44. }),
    45. ]
    46. const toDispose = new DisposableCollection()
    47. toDispose.pushAll(disposableList)
    48. return toDispose
    49. })
    50. })