@@ -2,7 +2,8 @@ import * as React from 'react'
22import { ClassicPreset , Scope } from 'rete'
33import {
44 classicConnectionPath , getDOMSocketPosition ,
5- loopConnectionPath , SocketPositionWatcher } from 'rete-render-utils'
5+ loopConnectionPath , SocketPositionWatcher
6+ } from 'rete-render-utils'
67
78import { Position } from '../../types'
89import { RenderPreset } from '../types'
@@ -27,7 +28,7 @@ export { Socket } from './components/Socket'
2728export type { ClassicScheme , ReactArea2D , RenderEmit } from './types'
2829export * as vars from './vars'
2930
30- type CustomizationProps < Schemes extends ClassicScheme > = {
31+ type CustomizationProps < Schemes extends ClassicScheme > = {
3132 node ?: ( data : ExtractPayload < Schemes , 'node' > ) => AcceptComponent < typeof data [ 'payload' ] , { emit : RenderEmit < Schemes > } > | null
3233 connection ?: ( data : ExtractPayload < Schemes , 'connection' > ) => AcceptComponent < typeof data [ 'payload' ] > | null
3334 socket ?: ( data : ExtractPayload < Schemes , 'socket' > ) => AcceptComponent < typeof data [ 'payload' ] > | null
@@ -39,6 +40,9 @@ type ClassicProps<Schemes extends ClassicScheme, K> = {
3940 customize ?: CustomizationProps < Schemes >
4041}
4142
43+ /**
44+ * Classic preset for rendering nodes, connections, controls and sockets.
45+ */
4246export function setup < Schemes extends ClassicScheme , K extends ReactArea2D < Schemes > > (
4347 props ?: ClassicProps < Schemes , K >
4448) : RenderPreset < Schemes , K > {
@@ -58,44 +62,44 @@ export function setup<Schemes extends ClassicScheme, K extends ReactArea2D<Schem
5862 const Component = ( node ? node ( context . data ) : Node ) as typeof Node
5963
6064 return ( Component &&
61- < Component
62- data = { context . data . payload }
63- emit = { data => parent . emit ( data as any ) }
64- />
65+ < Component
66+ data = { context . data . payload }
67+ emit = { data => parent . emit ( data as any ) }
68+ />
6569 )
6670 } else if ( context . data . type === 'connection' ) {
6771 const Component = ( connection ? connection ( context . data ) : Connection ) as typeof Connection
6872 const payload = context . data . payload
6973 const { sourceOutput, targetInput, source, target } = payload
7074
7175 return ( Component &&
72- < ConnectionWrapper
73- start = { context . data . start || ( change => positionWatcher . listen ( source , 'output' , sourceOutput , change ) ) }
74- end = { context . data . end || ( change => positionWatcher . listen ( target , 'input' , targetInput , change ) ) }
75- path = { async ( start , end ) => {
76- type FixImplicitAny = typeof plugin . __scope . produces | undefined
77- const response : FixImplicitAny = await plugin . emit ( {
78- type : 'connectionpath' , data : {
79- payload,
80- points : [ start , end ]
81- }
82- } )
76+ < ConnectionWrapper
77+ start = { context . data . start || ( change => positionWatcher . listen ( source , 'output' , sourceOutput , change ) ) }
78+ end = { context . data . end || ( change => positionWatcher . listen ( target , 'input' , targetInput , change ) ) }
79+ path = { async ( start , end ) => {
80+ type FixImplicitAny = typeof plugin . __scope . produces | undefined
81+ const response : FixImplicitAny = await plugin . emit ( {
82+ type : 'connectionpath' , data : {
83+ payload,
84+ points : [ start , end ]
85+ }
86+ } )
8387
84- if ( ! response ) return ''
88+ if ( ! response ) return ''
8589
86- const { path, points } = response . data
87- const curvature = 0.3
90+ const { path, points } = response . data
91+ const curvature = 0.3
8892
89- if ( ! path && points . length !== 2 ) throw new Error ( 'cannot render connection with a custom number of points' )
90- if ( ! path ) return payload . isLoop
91- ? loopConnectionPath ( points as [ Position , Position ] , curvature , 120 )
92- : classicConnectionPath ( points as [ Position , Position ] , curvature )
93+ if ( ! path && points . length !== 2 ) throw new Error ( 'cannot render connection with a custom number of points' )
94+ if ( ! path ) return payload . isLoop
95+ ? loopConnectionPath ( points as [ Position , Position ] , curvature , 120 )
96+ : classicConnectionPath ( points as [ Position , Position ] , curvature )
9397
94- return path
95- } }
96- >
97- < Component data = { context . data . payload } />
98- </ ConnectionWrapper >
98+ return path
99+ } }
100+ >
101+ < Component data = { context . data . payload } />
102+ </ ConnectionWrapper >
99103 )
100104 } else if ( context . data . type === 'socket' ) {
101105 const Component = ( socket ? socket ( context . data ) : Socket ) as typeof Socket
0 commit comments