-
-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathindex.tsx
More file actions
52 lines (46 loc) · 1.32 KB
/
index.tsx
File metadata and controls
52 lines (46 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import * as React from 'react'
import { BaseSchemes } from 'rete'
import { BaseAreaPlugin } from 'rete-area-plugin'
import { Position } from '../../types'
import { RenderPreset } from '../types'
import { Pin } from './Pin'
import { PinData, PinsRender } from './types'
type Props = {
translate?: (id: string, dx: number, dy: number) => void
contextMenu?: (id: string) => void
pointerdown?: (id: string) => void
}
/**
* Preset for rendering pins.
*/
export function setup<Schemes extends BaseSchemes, K extends PinsRender>(props?: Props): RenderPreset<Schemes, K> {
function renderPins(data: PinData, pointer: () => Position) {
return <>
{data.pins.map(pin => (
<Pin
{...pin}
key={pin.id}
contextMenu={() => {
props?.contextMenu?.(pin.id)
}}
translate={(dx, dy) => {
props?.translate?.(pin.id, dx, dy)
}}
pointerdown={() => {
props?.pointerdown?.(pin.id)
}}
pointer={pointer}
/>
))}
</>
}
return {
render(context, plugin) {
const data = context.data
const area = plugin.parentScope<BaseAreaPlugin<Schemes, PinsRender>>(BaseAreaPlugin)
if (data.type === 'reroute-pins') {
return renderPins(data.data, () => area.area.pointer)
}
}
}
}