scmJS docs

api.contextMenu

ContextMenuApi

Items in the right-click menus of the map and the terrain palette.

Members

add

add(surface: ContextSurface, item: ContextItemSpec): Disposable;
// Right-click the map: copy the tile's position.
api.contextMenu.add("viewport", {
  label: (ctx) => (ctx.tile ? `Copy position (${ctx.tile.x}, ${ctx.tile.y})` : "Copy position"),
  enabled: (ctx) => ctx.tile !== null,
  run: (ctx) => { if (ctx.tile) void navigator.clipboard.writeText(`${ctx.tile.x}, ${ctx.tile.y}`); },
});
Try it

Types

Declarations only this group names.

ContextSurfacetype

type ContextSurface = "viewport" | "terrainPalette";

ContextMenuContextinterface

interface ContextMenuContext
surface: ContextSurface
tile: { x: number; y: number; } | null

The tile under the pointer (viewport only).

point: { px: number; py: number; } | null

The map pixel under the pointer (viewport only).

layer: EditorLayer
terrainMode: TerrainMode
terrain: number

The palette's active terrain id.

markedArea: Rect | null

ContextItemSpecinterface

interface ContextItemSpec
label: string | ((ctx: ContextMenuContext) => string)

A fixed label is given in English and shown through the plugin's registered catalogues; a function is called when the menu opens, so it translates with i18n.t itself.

enabled?: (ctx: ContextMenuContext) => boolean
visible?: (ctx: ContextMenuContext) => boolean
run?: (ctx: ContextMenuContext) => void

Give this or command (which is run with the context as its argument).

command?: string

scmJS 0.7.3 + main@e2d8ba5 · Generated from the repository. The source is under the MIT license, which does not cover what ATTRIBUTION.md lists. StarCraft and Brood War are trademarks of Blizzard Entertainment; this project ships none of their data.