11import nullthrows from "nullthrows" ;
2+ import { useState } from "react" ;
23import { theme } from "../../../../common/theme" ;
34import type { CCConnectionId } from "../../../../store/connection" ;
45import { useStore } from "../../../../store/react" ;
56import ensureStoreItem from "../../../../store/react/error" ;
67import { useNode } from "../../../../store/react/selectors" ;
7- import getCCComponentEditorRendererNodeGeometry from "./Node.geometry" ;
88import { useComponentEditorStore } from "../store" ;
9+ import getCCComponentEditorRendererNodeGeometry from "./Node.geometry" ;
910
1011export type CCComponentEditorRendererConnectionCoreProps = {
1112 from : { x : number ; y : number } ;
1213 to : { x : number ; y : number } ;
1314 connectionId ?: CCConnectionId ;
15+ onMouseEnter ?: React . MouseEventHandler < SVGPathElement > ;
16+ onMouseLeave ?: React . MouseEventHandler < SVGPathElement > ;
1417} ;
18+
1519export function CCComponentEditorRendererConnectionCore ( {
1620 from,
1721 to,
1822 connectionId,
23+ onMouseEnter,
24+ onMouseLeave,
1925} : CCComponentEditorRendererConnectionCoreProps ) {
2026 const straightGap = 10 ;
2127 const direction = from . x < to . x ? 1 : - 1 ;
2228
2329 const componentEditorState = useComponentEditorStore ( ) ( ) ;
2430
25-
2631 const handleClick = ( e : React . MouseEvent ) => {
2732 if ( ! connectionId ) {
2833 return ;
2934 }
30- componentEditorState . selectConnection (
31- [ connectionId ] ,
32- ! e . shiftKey
33- )
34- }
35+ componentEditorState . selectConnection ( [ connectionId ] , ! e . shiftKey ) ;
36+ } ;
3537
3638 return (
39+ // biome-ignore lint/a11y/noStaticElementInteractions: SVG
3740 < path
3841 d = { [
3942 `M ${ from . x } ${ from . y } ` ,
@@ -48,7 +51,12 @@ export function CCComponentEditorRendererConnectionCore({
4851 ] . join ( " " ) } `,
4952 `h ${ straightGap * direction } ` ,
5053 ] . join ( " " ) }
51- stroke = { connectionId && componentEditorState . selectedConnectionIds . has ( connectionId ) ? theme . palette . primary : theme . palette . textPrimary }
54+ stroke = {
55+ connectionId &&
56+ componentEditorState . selectedConnectionIds . has ( connectionId )
57+ ? theme . palette . primary
58+ : theme . palette . textPrimary
59+ }
5260 strokeWidth = "2"
5361 fill = "none"
5462 onClick = { handleClick }
@@ -58,12 +66,12 @@ export function CCComponentEditorRendererConnectionCore({
5866 }
5967 e . preventDefault ( ) ;
6068 e . stopPropagation ( ) ;
61- componentEditorState . selectConnection (
62- [ connectionId ] ,
63- true
64- ) ;
69+ componentEditorState . selectConnection ( [ connectionId ] , true ) ;
6570 componentEditorState . openContextMenu ( e ) ;
6671 } }
72+ id = { connectionId }
73+ onMouseEnter = { onMouseEnter }
74+ onMouseLeave = { onMouseLeave }
6775 />
6876 ) ;
6977}
@@ -75,6 +83,7 @@ const CCComponentEditorRendererConnection = ensureStoreItem(
7583 ( props , store ) => store . connections . get ( props . connectionId ) ,
7684 ( { connectionId } : CCComponentEditorRendererConnectionProps ) => {
7785 const { store } = useStore ( ) ;
86+ const componentEditorState = useComponentEditorStore ( ) ( ) ;
7887 const connection = nullthrows ( store . connections . get ( connectionId ) ) ;
7988 const fromNodePin = nullthrows ( store . nodePins . get ( connection . from ) ) ;
8089 const toNodePin = nullthrows ( store . nodePins . get ( connection . to ) ) ;
@@ -95,12 +104,35 @@ const CCComponentEditorRendererConnection = ensureStoreItem(
95104 toNodeGeometry . nodePinPositionById . get ( toNodePin . id ) ,
96105 ) ;
97106
107+ const [ isHovered , setIsHovered ] = useState ( false ) ;
108+
109+ // const fromNodePinValue = componentEditorState.getNodePinValue(fromNodePin.id);
110+
98111 return (
99- < CCComponentEditorRendererConnectionCore
100- from = { fromNodePinPosition }
101- to = { toNodePinPosition }
102- connectionId = { connectionId }
103- />
112+ < >
113+ < CCComponentEditorRendererConnectionCore
114+ from = { fromNodePinPosition }
115+ to = { toNodePinPosition }
116+ connectionId = { connectionId }
117+ onMouseEnter = { ( ) => {
118+ setIsHovered ( true ) ;
119+ } }
120+ onMouseLeave = { ( ) => {
121+ setIsHovered ( false ) ;
122+ } }
123+ />
124+ { isHovered && componentEditorState . editorMode === "play" && (
125+ < text fontSize = { 10 } fill = { theme . palette . textPrimary } >
126+ < textPath
127+ href = { `#${ connectionId } ` }
128+ startOffset = "50%"
129+ textAnchor = "middle"
130+ >
131+ hoge
132+ </ textPath >
133+ </ text >
134+ ) }
135+ </ >
104136 ) ;
105137 } ,
106138) ;
0 commit comments