Skip to content

Commit f42fee4

Browse files
committed
api docs
1 parent ff68b09 commit f42fee4

11 files changed

Lines changed: 179 additions & 40 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
22
dist
3+
docs

.npmignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

package-lock.json

Lines changed: 107 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "",
55
"scripts": {
66
"build": "rete build -c rete.config.ts",
7-
"lint": "rete lint"
7+
"lint": "rete lint",
8+
"doc": "rete doc --entries src/index.tsx"
89
},
910
"author": "Vitaliy Stoliarov",
1011
"license": "MIT",

src/index.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ export * from './shared'
1313
export * from './types'
1414
export { useRete } from './utils'
1515

16+
/**
17+
* Signals that can be emitted by the plugin
18+
* @priority 9
19+
*/
1620
export type Produces<Schemes extends BaseSchemes> =
1721
| { type: 'connectionpath', data: { payload: Schemes['Connection'], path?: string, points: Position[] } }
1822

@@ -21,10 +25,21 @@ type Requires<Schemes extends BaseSchemes> =
2125
| RenderSignal<'connection', { payload: Schemes['Connection'], start?: Position, end?: Position }>
2226
| { type: 'unmount', data: { element: HTMLElement } }
2327

24-
type Props = {
28+
/**
29+
* Plugin props
30+
*/
31+
export type Props = {
32+
/** root factory for React.js 18+ */
2533
createRoot?: (container: Element | DocumentFragment) => any
2634
}
2735

36+
/**
37+
* React plugin. Renders nodes, connections and other elements using React.
38+
* @priority 10
39+
* @emits connectionpath
40+
* @listens render
41+
* @listens unmount
42+
*/
2843
export class ReactPlugin<Schemes extends BaseSchemes, T = Requires<Schemes>> extends Scope<Produces<Schemes>, [Requires<Schemes> | T]> {
2944
renderer: Renderer
3045
presets: RenderPreset<Schemes, T>[] = []
@@ -87,6 +102,10 @@ export class ReactPlugin<Schemes extends BaseSchemes, T = Requires<Schemes>> ext
87102
this.renderer.unmount(element)
88103
}
89104

105+
/**
106+
* Adds a preset to the plugin.
107+
* @param preset Preset that can render nodes, connections and other elements.
108+
*/
90109
public addPreset<K>(preset: RenderPreset<Schemes, CanAssignSignal<T, K> extends true ? K : 'Cannot apply preset. Provided signals are not compatible'>) {
91110
const local = preset as RenderPreset<Schemes, T>
92111

src/presets/classic/index.tsx

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import * as React from 'react'
22
import { ClassicPreset, Scope } from 'rete'
33
import {
44
classicConnectionPath, getDOMSocketPosition,
5-
loopConnectionPath, SocketPositionWatcher } from 'rete-render-utils'
5+
loopConnectionPath, SocketPositionWatcher
6+
} from 'rete-render-utils'
67

78
import { Position } from '../../types'
89
import { RenderPreset } from '../types'
@@ -27,7 +28,7 @@ export { Socket } from './components/Socket'
2728
export type { ClassicScheme, ReactArea2D, RenderEmit } from './types'
2829
export * 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+
*/
4246
export 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

src/presets/context-menu/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ type Props = {
1616
customize?: Customize
1717
}
1818

19+
/**
20+
* Preset for rendering context menu.
21+
*/
1922
export function setup<Schemes extends BaseSchemes, K extends ContextMenuRender>(props?: Props): RenderPreset<Schemes, K> {
2023
const delay = typeof props?.delay === 'undefined' ? 1000 : props.delay
2124

src/presets/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Built-in presets, responsible for rendering different parts of the editor.
3+
* @module
4+
*/
15
export * as classic from './classic'
26
export * as contextMenu from './context-menu'
37
export * as minimap from './minimap'

src/presets/minimap/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import { RenderPreset } from '../types'
66
import { Minimap } from './components/Minimap'
77
import { MinimapRender } from './types'
88

9+
/**
10+
* Preset for rendering minimap.
11+
*/
912
export function setup<Schemes extends BaseSchemes, K extends MinimapRender>(props?: { size?: number }): RenderPreset<Schemes, K> {
1013
return {
1114
render(context) {

0 commit comments

Comments
 (0)