@@ -21,6 +21,15 @@ import PropTypes from "prop-types";
2121export const ConnectorProvider = ( { name, children} ) => {
2222 const shape = useShapeContext ( ) ;
2323 const divRef = useRef ( ) ;
24+ const prevNameRef = useRef ( name ) ;
25+ const directionRef = useRef ( {
26+ cursor : "crosshair" ,
27+ key : name ,
28+ color : "white" ,
29+ ax : "x" ,
30+ vector : 1 ,
31+ value : DIRECTION . E ,
32+ } ) ;
2433
2534 // 初始化之后,创建connector.
2635 useEffect ( ( ) => {
@@ -40,23 +49,14 @@ export const ConnectorProvider = ({name, children}) => {
4049 return ( rect . top - shapeRect . top + ( rect . bottom - rect . top ) / 2 ) / shape . page . scaleY ;
4150 } ;
4251
43- const c = connector ( shape , getX , getY , ( ) => {
44- return {
45- cursor : "crosshair" ,
46- key : name ,
47- color : "white" ,
48- ax : "x" ,
49- vector : 1 ,
50- value : DIRECTION . E
51- } ;
52- } ,
53- s => s . visible ,
54- ( ) => true ,
55- ( ) => true ,
56- ( ) => { } ,
57- ( ) => false
52+ const c = connector ( shape , getX , getY , ( ) => directionRef . current ,
53+ s => s . visible ,
54+ ( ) => true ,
55+ ( ) => true ,
56+ ( ) => { } ,
57+ ( ) => false ,
5858 ) ;
59- c . type = " dynamic" ;
59+ c . type = ' dynamic' ;
6060 shape . activeConnector ( c ) ;
6161 c . isSolid = true ;
6262 c . allowToLink = false ;
@@ -80,6 +80,22 @@ export const ConnectorProvider = ({name, children}) => {
8080 } ;
8181 } , [ ] ) ;
8282
83+ // 当name变化时更新相关线条的definedFromConnector
84+ useEffect ( ( ) => {
85+ if ( prevNameRef . current !== name ) {
86+ directionRef . current . key = name ;
87+
88+ const lines = shape . page . sm . getShapes ( s => s . fromShape === shape . id || s . toShape === shape . id )
89+ . filter ( l => l . definedFromConnector === prevNameRef . current ) ;
90+ lines . forEach ( l => {
91+ l . definedFromConnector = name ;
92+ l . follow ( ) ;
93+ } ) ;
94+
95+ prevNameRef . current = name ; // 更新前一个name值
96+ }
97+ } , [ name ] ) ;
98+
8399 const deleteLine = ( ) => {
84100 const lines = shape . page . sm . getShapes ( s => s . fromShape === shape . id || s . toShape === shape . id )
85101 . filter ( l => l . definedFromConnector === name ) ;
0 commit comments