Overview
The abstract WeavePlugin class represents the base structure for all plugins in the Weave.js ecosystem. Plugins are modular components that extend the functionality of the canvas environment without modifying the core Weave.js system itself.
The WeavePlugin class provides the foundational API that all specific plugins—such as selection tools, grid rendering, snapping systems, or user pointers—inherit and build upon. It defines the lifecycle hooks and integration points necessary to inject custom behavior into a Weave.js app.
Plugins are ideal for:
-
Building reusable visual or behavioral extensions for the canvas.
-
Enabling domain-specific tools (e.g., diagramming tools, design tool overlays).
-
Keeping the core system clean and lightweight, while scaling with feature complexity.
-
Supporting collaborative behaviors (e.g., multi-user cursors, collaborative selection).
All plugins must extend this class.
|
Don’t directly use
Don’t instantiate this WeavePlugin class directly. |
Lifecycle
A Weave.js plugin lifecycle is pretty simple:
|
Decoupled from the lifecycle
The following methods are called outside the lifecycle:
|
Name
All plugins must define a property:
name: string;
Which defines the plugin identity, for example the plugin that handles the stage grid it’s name is
stageGrid. The name must be unique among other plugins.
Optional Hooks
initialize
initialize?(): void
This method resets the internal state of the plugin. It’s called each time the Weave instance is reset, for example when switching rooms. Built-in plugins also call it from their constructor.
onInit
onInit?(): void
This method is called once after the Weave instance is set up, and is the ideal place to initialize all necessary Konva elements needed and their events.
|
initialize vs onInit
Use |