1- import { createApp , reactive , type Component } from 'vue'
1+ import { createApp , reactive , shallowReactive , type Component } from 'vue'
22import { cloneDeep } from 'lodash'
3- import { h as createLogicFlowElement , HtmlNode , HtmlNodeModel , type GraphModel , type IHtmlNodeProperties , type Model } from '@logicflow/core'
3+ import {
4+ Component as LogicFlowComponent ,
5+ createRef ,
6+ h as createLogicFlowElement ,
7+ HtmlNode ,
8+ HtmlNodeModel ,
9+ type GraphModel ,
10+ type IHtmlNodeProperties ,
11+ type Model ,
12+ } from '@logicflow/core'
413import { nodeDict } from '@/workflow-canvas/config/node-mapping'
514import { WorkflowKind , WorkflowNodeType , type WorkflowNodeField } from '@/workflow-canvas/types'
615import { connect , disconnect } from './teleport'
16+ import NodeAnchor from './node-container/NodeAnchor.vue'
717
818type NodeViewProps = ConstructorParameters < typeof HtmlNode > [ 0 ]
919type NodeFieldGroup = Record < string , WorkflowNodeField [ ] >
@@ -24,6 +34,31 @@ interface WorkflowNodeProperties extends IHtmlNodeProperties {
2434 user_input_field_list ?: unknown [ ]
2535}
2636
37+ /** 将 LogicFlow 锚点的挂载、更新和卸载同步到 Vue 组件。 */
38+ class WorkflowNodeAnchor extends LogicFlowComponent < InstanceType < typeof NodeAnchor > [ '$props' ] > {
39+ private readonly containerRef = createRef < HTMLDivElement > ( )
40+ private readonly anchorProps = shallowReactive ( { ...this . props } )
41+ private readonly teleportId = `${ this . props . nodeModel . graphModel . flowId } :${ this . props . nodeModel . id } :anchor:${ this . props . anchorData . id } `
42+
43+ componentDidMount ( ) {
44+ if ( this . containerRef . current ) {
45+ connect ( this . teleportId , NodeAnchor , this . containerRef . current , ( ) => ( { } ) , this . anchorProps )
46+ }
47+ }
48+
49+ componentDidUpdate ( ) {
50+ Object . assign ( this . anchorProps , this . props )
51+ }
52+
53+ componentWillUnmount ( ) {
54+ disconnect ( this . teleportId )
55+ }
56+
57+ render ( ) {
58+ return createLogicFlowElement ( 'div' , { ref : this . containerRef } )
59+ }
60+ }
61+
2762export class WorkflowNodeView extends HtmlNode {
2863 private nodeApp ?: ReturnType < typeof createApp >
2964 private readonly vueComponent : Component
@@ -69,38 +104,7 @@ export class WorkflowNodeView extends HtmlNode {
69104 return createLogicFlowElement (
70105 'foreignObject' ,
71106 { ...anchorData , className : 'workflow-node-anchor-wrapper' , x : x - 12 , y : y - 12 , width : 24 , height : 24 } ,
72- [
73- createLogicFlowElement (
74- 'div' ,
75- {
76- 'data-node-menu-node-id' : nodeModel . id ,
77- 'data-node-menu-anchor-id' : anchorData . id ,
78- className : `workflow-node-anchor${ type === 'right' ? ' is-right' : '' } ${ connected ? ' is-connected' : '' } ${ anchorData . id ?. endsWith ( '_exception_right' ) ? ' is-abnormal' : '' } ` ,
79- onClick : ( ) => {
80- if ( canOpenNodeMenu ) nodeModel . openNodeMenu ?.( anchorData )
81- } ,
82- onMouseEnter : ( event : MouseEvent ) => {
83- if ( canOpenNodeMenu && event . currentTarget instanceof HTMLElement ) nodeModel . setAnchorTooltip ?.( event . currentTarget )
84- } ,
85- onMouseLeave : ( ) => nodeModel . setAnchorTooltip ?.( ) ,
86- onPointerDown : ( ) => nodeModel . setAnchorTooltip ?.( ) ,
87- } ,
88- connected && type !== 'right'
89- ? [ ]
90- : [
91- createLogicFlowElement (
92- 'svg' ,
93- {
94- 'aria-hidden' : 'true' ,
95- className : 'workflow-node-add-icon' ,
96- fill : 'currentColor' ,
97- focusable : 'false' ,
98- } ,
99- [ createLogicFlowElement ( 'use' , { href : '#icon_add_bold_outlined' } ) ] ,
100- ) ,
101- ] ,
102- ) ,
103- ] ,
107+ [ createLogicFlowElement ( WorkflowNodeAnchor , { key : anchorData . id , anchorData, canOpenNodeMenu, connected, nodeModel } ) ] ,
104108 )
105109 }
106110
@@ -134,7 +138,6 @@ export class WorkflowNodeModel extends HtmlNodeModel<WorkflowNodeProperties> {
134138 private upNodeFieldDict ?: NodeFieldGroup
135139
136140 openNodeMenu ?: ( anchorData : Model . AnchorConfig ) => void
137- setAnchorTooltip ?: ( anchorElement ?: HTMLElement ) => void
138141 validate ?: ( ) => Promise < unknown >
139142
140143 setAttributes ( ) {
0 commit comments