rete-area-plugin
packageA union of all possible signals that can be emitted by any area plugin
type BaseArea<Schemes extends BaseSchemes> =
| { data: Object; type: "nodepicked" }
| { data: Schemes["Node"]; type: "nodedragged" }
| { data: Object & NodeTranslateEventParams; type: "nodetranslate" }
| { data: Object & NodeTranslateEventParams; type: "nodetranslated" }
| { data: Object; type: "contextmenu" }
| { data: Object; type: "pointerdown" }
| { data: Object; type: "pointermove" }
| { data: Object; type: "pointerup" }
| { data: Object & NodeResizeEventParams; type: "noderesize" }
| { data: Object & NodeResizeEventParams; type: "noderesized" }
| RenderSignal<"node", { payload: Schemes["Node"] }>
| RenderSignal<
"connection",
{ end: Position; payload: Schemes["Connection"]; start: Position }
>
| { data: Object; type: "unmount" }
| { data: Object; type: "reordered" };
Parameter | Extends | Description |
---|---|---|
Schemes | BaseSchemes |
A union of all possible signals that can be emitted by the area
type Area2D<Schemes extends BaseSchemes> =
| BaseArea<Schemes>
| { data: TranslateEventParams; type: "translate" }
| { data: TranslateEventParams; type: "translated" }
| { data: ZoomEventParams; type: "zoom" }
| { data: ZoomEventParams; type: "zoomed" }
| { data: Object; type: "resized" };
Parameter | Extends | Description |
---|---|---|
Schemes | BaseSchemes |
A plugin that provides a 2D area for nodes and connections
class AreaPlugin<Schemes extends BaseSchemes, ExtraSignals extends unknown>
Parameter | Extends | Description |
---|---|---|
Schemes | BaseSchemes | |
ExtraSignals | unknown |
Extends BaseAreaPlugin<Schemes, Area2D
Emits render
rendered
unmount
Listens nodecreated
noderemoved
connectioncreated
connectionremoved
Destroy all views and remove all event listeners
destroy(): void
Returns void
Resize node
resize(id: string, width: number, height: number): Promise<undefined | boolean>
Parameter | Type | Description |
---|---|---|
id | string | Node id |
width | number | Desired width |
height | number | Desired height |
Returns Promise<undefined | boolean>
Translate node to position
translate(id: string, position: Position): Promise<undefined | boolean>
Parameter | Type | Description |
---|---|---|
id | string | Node id |
position | Position | Position |
Returns Promise<undefined | boolean>
Force update rendered element by id (node, connection, etc.)
update(type: "node" | "connection" | GetRenderTypes<ExtraSignals>, id: string): Promise<void>
Emits render
Parameter | Type | Description |
---|---|---|
type | `"node" | "connection" |
id | string | Element id |
Returns Promise<void>
Area extensions
Selector class. Used to collect selected entities (nodes, connections, etc.) and synchronize them (select, unselect, translate, etc.). Can be extended to add custom functionality.
class Selector<E extends SelectorEntity>
Parameter | Extends | Description |
---|---|---|
E | SelectorEntity |
Restrictor extension parameters
type Restrictor = {
scaling: ScaleRange | Function | boolean;
translation: TranslateRange | Function | boolean;
};
Snap grid extension parameters
type SnapGrid = { dynamic: boolean; size: number };
Zoom extension parameters
type ZoomAt = { scale: number };
Selector's accumulate function, activated when the ctrl key is pressed
accumulateOnCtrl(): { active: unknown, destroy: unknown }
Returns { active: unknown, destroy: unknown }
src/extensions/bounding-box.ts
Get the bounding box of the given nodes
getBoundingBox(plugin: BaseAreaPlugin<Schemes, K>, nodes: NodeRef<Schemes>[]): { bottom: number, center: Object, height: number, left: number, right: number, top: number, width: number }
Parameter | Type | Description |
---|---|---|
plugin | BaseAreaPlugin<Schemes, K> | The area plugin |
nodes | NodeRef<Schemes>[] | The nodes to get the bounding box of |
Returns { bottom: number, center: Object, height: number, left: number, right: number, top: number, width: number }
The bounding box
Restrictor extension. Restricts the area zoom and position
restrictor(plugin: AreaPlugin<Schemes, K>, params: Restrictor): void
Listens zoom
zoomed
translated
Parameter | Type | Description |
---|---|---|
plugin | AreaPlugin<Schemes, K> | The area plugin |
params | Restrictor | The restrictor parameters |
Returns void
Selectable nodes extension. Adds the ability to select nodes in the area.
selectableNodes(base: BaseAreaPlugin<Schemes, T>, core: Selector<SelectorEntity>, options: { accumulating: Accumulating }): { select: Function, unselect: Function }
Listens nodepicked
nodetranslated
pointerdown
pointermove
pointerup
Parameter | Type | Description |
---|---|---|
base | BaseAreaPlugin<Schemes, T> | BaseAreaPlugin instance |
core | Selector<SelectorEntity> | Selectable instance |
options | { accumulating: Accumulating } |
Returns { select: Function, unselect: Function }
Selector factory, uses default Selector class
selector(): Selector<E>
Returns Selector<E>
Selector instance
src/extensions/show-input-control.ts
Show input control extension. It will show the input's control when there is no connection and hide it when there is a connection.
showInputControl(area: BaseAreaPlugin<BaseSchemes, any>, visible: Visible<S>): void
Listens connectioncreated
connectionremoved
Parameter | Type | Description |
---|---|---|
area | BaseAreaPlugin<BaseSchemes, any> | The base area plugin |
visible | Visible<S> | The visible function |
Returns void
Simple nodes order extension
simpleNodesOrder(base: BaseAreaPlugin<Schemes, T>): void
Listens nodepicked
connectioncreated
Parameter | Type | Description |
---|---|---|
base | BaseAreaPlugin<Schemes, T> | The base area plugin |
Returns void
Snap grid extension
snapGrid(base: BaseAreaPlugin<Schemes, K>, params: SnapGrid): void
Listens nodetranslate
nodedragged
Parameter | Type | Description |
---|---|---|
base | BaseAreaPlugin<Schemes, K> | The base area plugin |
params | SnapGrid | The snap parameters |
Returns void
Zooms the area to fit the given nodes
zoomAt(plugin: AreaPlugin<Schemes, K>, nodes: NodeRef<Schemes>[], params: ZoomAt): Promise<void>
Parameter | Type | Description |
---|---|---|
plugin | AreaPlugin<Schemes, K> | The area plugin |
nodes | NodeRef<Schemes>[] | The nodes to fit |
params | ZoomAt | The zoom parameters |
Returns Promise<void>
Base abstract class for area plugins that provides a common interface
class BaseAreaPlugin<Schemes extends BaseSchemes, Signals extends unknown>
Parameter | Extends | Description |
---|---|---|
Schemes | BaseSchemes | |
Signals | unknown |
Extended by AreaPlugin
Extends Scope<Signals, Root
Drag handler, used to handle dragging of the area and nodes. Can be extended to add custom behavior.
class Drag
Zoom class, used to handle zooming of the area. Can be extended to add custom behavior.
class Zoom
listen to pointerdown, window's pointermove and pointerup events, where last two not active before pointerdown triggered for performance reasons
usePointerListener(element: HTMLElement, handlers: PointerListenerHandlers): PointerListener
Parameter | Type | Description |
---|---|---|
element | HTMLElement | |
handlers | PointerListenerHandlers |
Returns PointerListener