11import nullthrows from "nullthrows" ;
22import { useState } from "react" ;
3- import { theme } from "../../../../common/theme" ;
4- import type { CCConnectionId } from "../../../../store/connection" ;
5- import { useStore } from "../../../../store/react" ;
6- import ensureStoreItem from "../../../../store/react/error" ;
7- import { useNode } from "../../../../store/react/selectors" ;
8- import { useComponentEditorStore } from "../store" ;
9- import { stringifySimulationValue } from "../store/slices/core/index" ;
10- import getCCComponentEditorRendererNodeGeometry from "./Node.geometry" ;
3+ import { theme } from "../../../../../common/theme" ;
4+ import type { Vector2 } from "../../../../../common/vector2" ;
5+ import type { CCComponentPinType } from "../../../../../store/componentPin" ;
6+ import type { CCConnectionId } from "../../../../../store/connection" ;
7+ import { useStore } from "../../../../../store/react" ;
8+ import ensureStoreItem from "../../../../../store/react/error" ;
9+ import { useNode } from "../../../../../store/react/selectors" ;
10+ import { useComponentEditorStore } from "../../store" ;
11+ import { stringifySimulationValue } from "../../store/slices/core/index" ;
12+ import getCCComponentEditorRendererNodeGeometry from "../Node/geometry" ;
13+
14+ export type CCComponentEditorRendererConnectionEndpoint = {
15+ direction : CCComponentPinType ;
16+ position : Vector2 ;
17+ } ;
1118
1219export type CCComponentEditorRendererConnectionCoreProps = {
13- from : { x : number ; y : number } ;
14- to : { x : number ; y : number } ;
20+ from : CCComponentEditorRendererConnectionEndpoint ;
21+ to : CCComponentEditorRendererConnectionEndpoint ;
1522 connectionId ?: CCConnectionId ;
1623 onMouseEnter ?: React . MouseEventHandler < SVGPathElement > ;
1724 onMouseLeave ?: React . MouseEventHandler < SVGPathElement > ;
1825} ;
1926
27+ const straightGap = 10 ;
28+ const polarity : Record < CCComponentPinType , number > = {
29+ input : - 1 ,
30+ output : 1 ,
31+ } ;
2032export function CCComponentEditorRendererConnectionCore ( {
2133 from,
2234 to,
2335 connectionId,
2436 onMouseEnter,
2537 onMouseLeave,
2638} : CCComponentEditorRendererConnectionCoreProps ) {
27- const straightGap = 10 ;
28- const direction = from . x < to . x ? 1 : - 1 ;
29-
3039 const componentEditorState = useComponentEditorStore ( ) ( ) ;
3140
3241 const handleClick = ( e : React . MouseEvent ) => {
@@ -40,17 +49,17 @@ export function CCComponentEditorRendererConnectionCore({
4049 // biome-ignore lint/a11y/noStaticElementInteractions: SVG
4150 < path
4251 d = { [
43- `M ${ from . x } ${ from . y } ` ,
44- `h ${ straightGap * direction } ` ,
52+ `M ${ from . position . x } ${ from . position . y } ` ,
53+ `h ${ straightGap * polarity [ from . direction ] } ` ,
4554 `C ${ [
46- from . x + 4 * straightGap * direction ,
47- from . y ,
48- to . x - 4 * straightGap * direction ,
49- to . y ,
50- to . x - straightGap * direction ,
51- to . y ,
55+ from . position . x + 4 * straightGap * polarity [ from . direction ] ,
56+ from . position . y ,
57+ to . position . x + 4 * straightGap * polarity [ to . direction ] ,
58+ to . position . y ,
59+ to . position . x + straightGap * polarity [ to . direction ] ,
60+ to . position . y ,
5261 ] . join ( " " ) } `,
53- `h ${ straightGap * direction } ` ,
62+ `h ${ straightGap * polarity [ from . direction ] } ` ,
5463 ] . join ( " " ) }
5564 stroke = {
5665 connectionId &&
@@ -87,7 +96,13 @@ const CCComponentEditorRendererConnection = ensureStoreItem(
8796 const componentEditorState = useComponentEditorStore ( ) ( ) ;
8897 const connection = nullthrows ( store . connections . get ( connectionId ) ) ;
8998 const fromNodePin = nullthrows ( store . nodePins . get ( connection . from ) ) ;
99+ const fromComponentPin = nullthrows (
100+ store . componentPins . get ( fromNodePin . componentPinId ) ,
101+ ) ;
90102 const toNodePin = nullthrows ( store . nodePins . get ( connection . to ) ) ;
103+ const toComponentPin = nullthrows (
104+ store . componentPins . get ( toNodePin . componentPinId ) ,
105+ ) ;
91106 const fromNode = useNode ( fromNodePin . nodeId ) ;
92107 const toNode = useNode ( toNodePin . nodeId ) ;
93108 const fromNodeGeometry = getCCComponentEditorRendererNodeGeometry (
@@ -110,8 +125,11 @@ const CCComponentEditorRendererConnection = ensureStoreItem(
110125 return (
111126 < >
112127 < CCComponentEditorRendererConnectionCore
113- from = { fromNodePinPosition }
114- to = { toNodePinPosition }
128+ from = { {
129+ direction : fromComponentPin . type ,
130+ position : fromNodePinPosition ,
131+ } }
132+ to = { { direction : toComponentPin . type , position : toNodePinPosition } }
115133 connectionId = { connectionId }
116134 onMouseEnter = { ( ) => {
117135 setIsHovered ( true ) ;
0 commit comments