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

Property Type Required Default Description

preset

string

pentagon

The default preset ID to use when the action is triggered. Defaults to 'pentagon'.

Trigger parameters

type WeavePolygonToolActionTriggerParams = {
  presetId?: string;
};
Property Type Required Description

presetId

string

Override the active preset ID for this trigger invocation.

Events

Event Payload Description

onAddingPolygon

undefined

Fired when the action enters the adding state (user is about to place the polygon).

onAddedPolygon

undefined

Fired 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).