Skip to main content

ContextMenuAction

Defines a custom action that appears in the context menu when elements are selected.

Properties

string
required
Unique identifier for this action. Used for deduplication and tracking.
string
required
Display text shown in the context menu.
'context-menu'
Optional target specification. Use “context-menu” to explicitly mark this as a context menu action.
string
Keyboard shortcut hint displayed next to the action. Example: “⌘K” or “Ctrl+K”.
boolean | ((context: ActionContext) => boolean)
Whether this action is enabled. Can be a boolean or a function that receives the action context and returns a boolean. Disabled actions appear greyed out.
(context: ContextMenuActionContext) => void | Promise<void>
required
Called when the action is triggered. Receives the action context with element data and helper functions.
AgentOptions
Optional agent configuration. When provided, this action can trigger AI-assisted operations. See AgentOptions.

ToolbarMenuAction

Defines a custom action that appears in the toolbar dropdown menu.

Properties

string
required
Unique identifier for this action.
string
required
Display text shown in the toolbar menu.
string
Keyboard shortcut hint. Example: “⌘K” or “Ctrl+K”.
'toolbar'
required
Must be “toolbar” to identify this as a toolbar action.
boolean | (() => boolean)
Whether this action is enabled. Can be a boolean or a function that returns a boolean.
() => boolean
Function that returns whether this action is currently active. Active actions are visually highlighted.
() => void | Promise<void>
required
Called when the action is triggered. No context is provided for toolbar actions.

ActionContext

Context object passed to action handlers with information about selected elements and helper functions.

Properties

Element
required
The primary selected element. If multiple elements are selected, this is typically the first one.
Element[]
required
Array of all selected elements.
string
File path where the element’s component is defined.
number
Line number where the element’s component is defined.
string
Name of the React component for this element.
string
HTML tag name of the element (lowercase).
(agent?: AgentOptions) => void
Function to enter prompt mode for AI-assisted operations. Optionally pass agent configuration.
ActionContextHooks
required
Helper hooks for common operations. See ActionContextHooks.
(action: () => Promise<boolean>) => Promise<void>
required
Execute an async action with visual feedback. Shows success/error flash based on return value.
  • Return true for success (shows success flash)
  • Return false for failure (shows error state)
  • Throws errors are caught and shown as errors
() => void
required
Programmatically hide the context menu.
() => void
required
Clean up any temporary state or UI elements. Call before exiting action.

ContextMenuActionContext

Extends ActionContext with additional context menu-specific functionality.

Properties

Inherits all properties from ActionContext plus:
() => void
Helper function to copy selected elements to clipboard using default behavior.

ActionContextHooks

Helper hooks provided in the action context for common operations.

Properties

(html: string, elements: Element[]) => Promise<string>
required
Transform HTML content through all registered plugin transform hooks.
(filePath: string, lineNumber?: number) => boolean | void
required
Trigger file opening with plugin hooks. Returns false if opening was prevented.
(url: string, filePath: string, lineNumber?: number) => string
required
Transform file opening URL through all registered plugin hooks.

Usage

Basic Context Menu Action

Conditional Action Enabling

Action with Feedback

Action with AI Agent

Toolbar Action

Action with Copy Helper

Action with Transform Hook

Registering Actions via Plugin

Type Definitions

See Also

  • Plugin - Register actions via plugins
  • Agent - Configure AI agents for actions