11import { Type } from '@angular/core' ;
2- import { CanAssignSignal , ClassicPreset , getUID } from 'rete' ;
2+ import { ClassicPreset , getUID } from 'rete' ;
33import { AreaPlugin } from 'rete-area-plugin' ;
4- import { classicConnectionPath , loopConnectionPath , SocketPositionWatcher , useDOMSocketPosition } from 'rete-render-utils' ;
5- import { AngularArea2D , ClassicScheme , RenderPayload , ExtractPayload } from './types' ;
4+ import { classicConnectionPath , loopConnectionPath , SocketPositionWatcher , getDOMSocketPosition } from 'rete-render-utils' ;
5+ import { AngularArea2D , ClassicScheme , ExtractPayload } from './types' ;
66import { NodeComponent } from './components/node/node.component' ;
77import { SocketComponent } from './components/socket/socket.component' ;
88import { ControlComponent } from './components/control/control.component' ;
99import { ConnectionComponent } from './components/connection/connection.component' ;
1010import { ConnectionWrapperComponent } from './components/connection/connection-wrapper.component' ;
11- import { ExtraRender , Position , RenderPreset } from '../../types' ;
11+ import { Position } from '../../types' ;
12+ import { RenderPreset } from '../types'
1213
1314type AngularComponent = Type < any >
1415type CustomizationProps < Schemes extends ClassicScheme > = {
@@ -18,26 +19,24 @@ type CustomizationProps <Schemes extends ClassicScheme>= {
1819 control ?: ( data : ExtractPayload < Schemes , 'control' > ) => AngularComponent | null
1920}
2021
21- type IsCompatible < K > = Extract < K , { type : 'render' | 'rendered' } > extends { type : 'render' | 'rendered' , data : infer P } ? CanAssignSignal < P , RenderPayload < ClassicScheme > > : false
22- type Substitute < K , Schemes extends ClassicScheme > = IsCompatible < K > extends true ? K : AngularArea2D < Schemes >
23-
24- type ClasssicProps < Schemes extends ClassicScheme , K extends ExtraRender > = (
25- | { socketPositionWatcher : SocketPositionWatcher }
26- | { area : AreaPlugin < Schemes , Substitute < K , Schemes > > }
27- ) & {
22+ type ClassicProps < Schemes extends ClassicScheme , K > = {
23+ socketPositionWatcher ?: SocketPositionWatcher < AreaPlugin < Schemes , K > >
2824 customize ?: CustomizationProps < Schemes >
2925}
3026
31- export function setup < Schemes extends ClassicScheme , K extends ExtraRender > (
32- props : ClasssicProps < Schemes , K >
33- ) : RenderPreset < Schemes , AngularArea2D < Schemes > | K > {
34- const positionWatcher = ' socketPositionWatcher' in props
35- ? props . socketPositionWatcher
36- : useDOMSocketPosition ( props . area as AreaPlugin < Schemes , AngularArea2D < Schemes > > )
37- const { node, connection, socket, control } = props . customize || { }
27+ export function setup < Schemes extends ClassicScheme , K extends AngularArea2D < Schemes > > (
28+ props ?: ClassicProps < Schemes , K >
29+ ) : RenderPreset < Schemes , K > {
30+ const positionWatcher = typeof props ?. socketPositionWatcher === 'undefined'
31+ ? getDOMSocketPosition < Schemes , any > ( ) // fix Type instantiation is excessively deep and possibly infinite.
32+ : props ?. socketPositionWatcher
33+ const { node, connection, socket, control } = props ? .customize || { }
3834
3935
4036 return {
37+ attach ( plugin ) {
38+ positionWatcher . attach ( plugin . parentScope < AreaPlugin < Schemes , any > > ( AreaPlugin ) )
39+ } ,
4140 update ( context ) {
4241 const data = context . data . payload
4342
@@ -84,8 +83,8 @@ export function setup<Schemes extends ClassicScheme, K extends ExtraRender>(
8483 props : {
8584 connectionComponent : component ,
8685 data : payload ,
87- start : start || ( ( change : any ) => positionWatcher ( source , 'output' , sourceOutput , change ) ) ,
88- end : end || ( ( change : any ) => positionWatcher ( target , 'input' , targetInput , change ) ) ,
86+ start : start || ( ( change : any ) => positionWatcher . listen ( source , 'output' , sourceOutput , change ) ) ,
87+ end : end || ( ( change : any ) => positionWatcher . listen ( target , 'input' , targetInput , change ) ) ,
8988 path : async ( start , end ) => {
9089 const response = await plugin . emit ( { type : 'connectionpath' , data : { payload, points : [ start , end ] } } )
9190 const { path, points } = response . data
0 commit comments