Weave.js

WeavePolygonToolAction

Add a polygon to the canvas using a preset shape

Overview

The WeavePolygonToolAction class allows users to place a polygon node on the canvas by clicking or touching it.

The shape is selected via a preset — one of the six built-in polygon definitions shipped with the SDK. The preset can be set at construction time, changed programmatically, or overridden per-trigger via the presetId trigger parameter.

Each interaction results in the creation of a WeavePolygonNode, added to the shared state and synchronized across all users.

The class extends the WeaveAction class.

Name

This action name property value is polygonTool.

Import

import { WeavePolygonToolAction } from "@inditextech/weave-sdk";

Instantiation

new WeavePolygonToolAction(preset?: string);

Parameters

PropTypeDefault
preset?
string
'pentagon'

Trigger parameters

type WeavePolygonToolActionTriggerParams = {
  presetId?: string;
};
PropTypeDefault
presetId?
string
-

Events

EventPayloadDescription
onAddingPolygonundefinedFired when the action enters the adding state (user is about to place the polygon).
onAddedPolygonundefinedFired after the polygon node has been placed on the canvas.

Methods

getPolygonsPresets

getPolygonsPresets(): Record<string, WeavePolygonPresetDef>

Returns all available polygon presets. The built-in presets are: triangle, diamond, pentagon, hexagon, octagon, decagon.


getPolygonPreset

getPolygonPreset(): string

Returns the currently active preset ID.


setPolygonPreset

setPolygonPreset(preset: string): void

Sets the active preset ID. Takes effect on the next trigger call (unless presetId is supplied via trigger params, which takes precedence).