22import React , { useEffect , useMemo , useRef } from "react" ;
33import type { NodePosition } from "../diagram/interfaces" ;
44import { useHoverStateContext } from "./HoverStateContext" ;
5- import type { ControlPoint , EdgeCell , EditableLine } from "./interfaces" ;
5+ import type {
6+ BaseEdgeCell ,
7+ ControlPoint ,
8+ EdgeCell ,
9+ EditableLine ,
10+ } from "./interfaces" ;
611import { isStraightType } from "./processors/asserts" ;
712
813const POINT_HELPER_IMAGE =
@@ -16,18 +21,22 @@ const POINT_HELPER_BG_SIZE = 22;
1621export interface LineEditorComponentProps {
1722 scale : number ;
1823 editableLineMap : WeakMap < EdgeCell , EditableLine > ;
24+ activeEditableEdge : EdgeCell ;
25+ updateCurActiveEditableEdge ?: (
26+ activeEditableEdge : BaseEdgeCell | null
27+ ) => void ;
1928}
2029
2130export function LineEditorComponent ( {
2231 scale,
2332 editableLineMap,
33+ activeEditableEdge,
34+ updateCurActiveEditableEdge,
2435} : LineEditorComponentProps ) : JSX . Element | null {
25- const { rootRef, activeEditableEdge, setLineEditorState } =
26- useHoverStateContext ( ) ;
36+ const { rootRef, setLineEditorState } = useHoverStateContext ( ) ;
2737 const exitRef = useRef < SVGImageElement > ( null ) ;
2838 const entryRef = useRef < SVGImageElement > ( null ) ;
2939 const controlPointsRef = useRef < ( SVGImageElement | null ) [ ] > ( [ ] ) ;
30-
3140 useEffect ( ( ) => {
3241 const exit = exitRef . current ;
3342 const entry = entryRef . current ;
@@ -44,6 +53,7 @@ export function LineEditorComponent({
4453 from : [ e . clientX , e . clientY ] ,
4554 type,
4655 } ) ;
56+ updateCurActiveEditableEdge ?.( activeEditableEdge ) ;
4757 } ;
4858 } ;
4959 const handleStartMouseDown = handleMouseDownFactory ( "exit" ) ;
@@ -54,14 +64,18 @@ export function LineEditorComponent({
5464 exit . removeEventListener ( "mousedown" , handleStartMouseDown ) ;
5565 entry . removeEventListener ( "mousedown" , handleEndMouseDown ) ;
5666 } ;
57- } , [ activeEditableEdge , rootRef , setLineEditorState ] ) ;
67+ } , [
68+ activeEditableEdge ,
69+ rootRef ,
70+ setLineEditorState ,
71+ updateCurActiveEditableEdge ,
72+ ] ) ;
5873
5974 const controlPoints = useMemo ( ( ) => {
6075 return activeEditableEdge && ! isStraightType ( activeEditableEdge . view ?. type )
6176 ? getControlPoints ( editableLineMap . get ( activeEditableEdge ) ! . points ! )
6277 : [ ] ;
6378 } , [ activeEditableEdge , editableLineMap ] ) ;
64-
6579 useEffect ( ( ) => {
6680 if ( ! activeEditableEdge ) {
6781 return ;
@@ -71,6 +85,7 @@ export function LineEditorComponent({
7185 return ( e : MouseEvent ) => {
7286 e . stopPropagation ( ) ;
7387 e . preventDefault ( ) ;
88+ updateCurActiveEditableEdge ?.( activeEditableEdge ) ;
7489 const rect = rootRef . current ! . getBoundingClientRect ( ) ;
7590 setLineEditorState ( {
7691 offset : [ rect . left , rect . top ] ,
@@ -91,7 +106,13 @@ export function LineEditorComponent({
91106 el ?. removeEventListener ( "mousedown" , handlers [ i ] ) ;
92107 } ) ;
93108 } ;
94- } , [ activeEditableEdge , controlPoints , rootRef , setLineEditorState ] ) ;
109+ } , [
110+ activeEditableEdge ,
111+ controlPoints ,
112+ rootRef ,
113+ setLineEditorState ,
114+ updateCurActiveEditableEdge ,
115+ ] ) ;
95116
96117 const gRef = useRef < SVGGElement > ( null ) ;
97118 useEffect ( ( ) => {
0 commit comments