Overview
The WeaveNodesSelectionPlugin class that provides node selection capabilities on the canvas. It allows users to click to select individual nodes, multi-select with modifier keys, or drag-select multiple elements at once using a selection rectangle (marquee).
Selection is a critical foundation for enabling further interactions like moving, grouping, deleting, copying, or applying bulk actions on nodes.
The class extends the WeavePlugin class
TypeScript types
type WeaveElementAttributes = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[key: string]: any;
id?: string;
nodeType?: string;
children?: WeaveStateElement[];
};
type WeaveStateElement = {
key: string;
type: string;
props: WeaveElementAttributes;
};
type WeaveSelection = {
instance: Konva.Shape | Konva.Group;
node: WeaveStateElement;
};
type WeaveNodesSelectionPluginOnSelectionStateEvent = boolean;
type WeaveNodesSelectionPluginOnNodesChangeEvent = WeaveSelection[];
type WeaveNodesSelectionPluginOnStageSelectionEvent = undefined;
type WeaveNodesSelectionPluginOnGroupContextChangeEvent = string | null;
type WeaveNodesSelectionOnSelectionParams = {
resizeEnabled: boolean;
rotateEnabled: boolean;
enabledAnchors: string[];
};
type WeaveNodesSelectionBehaviorsConfig = {
singleSelection: {
enabled: boolean;
};
multipleSelection: {
enabled: boolean;
};
onMultipleSelection?: (
selectedNodes: Konva.Node[]
) => Partial<WeaveNodesSelectionOnSelectionParams>;
};
type WeaveNodesSelectionPanningOnSelectionConfig = {
edgeThreshold: number;
minScrollSpeed: number;
maxScrollSpeed: number;
};
type WeaveNodesSelectionConfig = {
selection: Konva.TransformerConfig;
hover: Konva.TransformerConfig;
selectionArea: Konva.RectConfig;
panningWhenSelection: WeaveNodesSelectionPanningOnSelectionConfig;
behaviors: WeaveNodesSelectionBehaviorsConfig;
};
type WeaveNodesSelectionPluginConfig = Partial<WeaveNodesSelectionConfig>;
type WeaveNodesSelectionPluginParams = {
config?: WeaveNodesSelectionPluginConfig;
};
Parameters
For WeaveNodesSelectionPluginParams:
| Property | Type | Required | Description |
|---|---|---|---|
|
|
Config parameters for the plugin. |
For WeaveNodesSelectionPluginConfig:
| Property | Type | Required | Description |
|---|---|---|---|
|
|
Selector config (Konva Transformer configuration). |
|
|
|
Hover config (Konva Transformer configuration). |
|
|
|
Selection Area style (Konva Rect configuration). |
|
|
|
Panning when selecting by are configuration. |
|
|
|
Selection anchors behaviors configuration. |
For WeaveNodesSelectionPanningOnSelectionConfig:
| Property | Type | Required | Default | Description |
|---|---|---|---|---|
|
|
|
Stage edge threshold when to start panning when selecting by area. |
|
|
|
|
Panning minimum speed when scrolling on selecting by area. |
|
|
|
|
Panning maximum speed when scrolling on selecting by area. |
For WeaveNodesSelectionBehaviorsConfig:
| Property | Type | Required | Default | Description |
|---|---|---|---|---|
|
|
|
Enables transformer anchor handles on single selection. |
|
|
|
|
Enables transformer anchor handles on multiple selection. |
|
|
|
Function that allows to define the transformer behavior when multi-selecting nodes |
Methods
getTransformer
getTransformer(): Konva.Transformer
This method returns the underlying Transformer of the plugin.
setSelectedNodes
setSelectedNodes(nodes: Konva.Node[]): void
This method set the specified nodes as selected on the underlying Transformer of the plugin.
getSelectedNodes
getSelectedNodes(): (Konva.Group | Konva.Shape)[]
This method returns the selected nodes from the underlying Transformer of the plugin.
getSelectedNodesExtended
getSelectedNodesExtended(): WeaveSelection[]
This method returns the selected nodes but using the WeaveSelection format from the underlying Transformer of the plugin.
selectAll
selectAll(): void
This method selects all nodes using the underlying Transformer of the plugin.
Group context
getActiveGroupContext
getActiveGroupContext(): string | null
This method returns the ID of the group currently in edit context, or null if no group context
is active.
Events
onSelectionState
onSelectionState: WeaveNodesSelectionPluginOnSelectionStateEvent;
The onSelectionState event is called when the user is selecting (true) or not selecting
(false).
onNodesChange
onNodesChange: WeaveNodesSelectionPluginOnNodesChangeEvent;
The onNodesChange event is called when the selected nodes changed.