Skip to main content

Plugin

The main interface for creating React Grab plugins. Plugins can extend functionality, customize appearance, add actions, and hook into lifecycle events.

Properties

string
required
Unique identifier for the plugin. Used for registration and unregistration.
DeepPartial<Theme>
Theme customizations applied when the plugin is active. See Theme for available options.
SettableOptions
Configuration options that modify React Grab behavior. See Options.
PluginAction[]
Custom actions to add to context menus or toolbar. Array of ContextMenuAction or ToolbarMenuAction.
PluginHooks
Lifecycle hooks and event handlers. See PluginHooks below.
(api: ReactGrabAPI, hooks: ActionContextHooks) => PluginConfig | void
Optional setup function called when the plugin is registered. Receives the React Grab API and action hooks. Can return a PluginConfig object for dynamic configuration.

PluginConfig

Configuration object returned by the plugin’s setup function or used for runtime configuration.

Properties

DeepPartial<Theme>
Theme customizations to apply.
SettableOptions
Runtime options to apply.
PluginAction[]
Actions to register.
PluginHooks
Event hooks to register.
() => void
Optional cleanup function called when the plugin is unregistered or when React Grab is disposed.

PluginHooks

Lifecycle hooks and event handlers for plugins. All hooks are optional.

Activation Hooks

() => void
Called when React Grab is activated (enters selection mode).
() => void
Called when React Grab is deactivated (exits selection mode).
() => void
Called to cancel any pending toolbar actions. Useful for cleanup.

Element Interaction Hooks

(element: Element) => void
Called when the user hovers over an element during selection.
(element: Element) => boolean | void | Promise<boolean>
Called when an element is selected. Return false to prevent the default selection behavior.
(startX: number, startY: number) => void
Called when the user starts dragging to select multiple elements. Receives starting coordinates.
(elements: Element[], bounds: DragRect) => void
Called when drag selection ends. Receives selected elements and drag bounds.

Copy Hooks

(elements: Element[]) => void | Promise<void>
Called before copying elements to clipboard. Use for validation or preparation.
(content: string, elements: Element[]) => string | Promise<string>
Transform the content before copying to clipboard. Return modified content string.
(elements: Element[], success: boolean) => void
Called after copy operation completes, regardless of success.
(elements: Element[], content: string) => void
Called when copy succeeds. Receives elements and copied content.
(error: Error) => void
Called when copy fails. Receives the error.

State & UI Hooks

(state: ReactGrabState) => void
Called whenever React Grab state changes. Receives the new state.
(isPromptMode: boolean, context: PromptModeContext) => void
Called when prompt mode is toggled. Receives mode state and context with cursor position and target element.
(visible: boolean, bounds: OverlayBounds | null, element: Element | null) => void
Called when selection box visibility or bounds change.
(visible: boolean, bounds: OverlayBounds | null) => void
Called when drag box visibility or bounds change.
(bounds: OverlayBounds, element: Element) => void
Called when a grabbed box (success flash) is shown.
(visible: boolean, variant: ElementLabelVariant, context: ElementLabelContext) => void
Called when element label visibility or content changes. Variant can be “hover”, “processing”, or “success”.
(visible: boolean, context: CrosshairContext) => void
Called when crosshair visibility or position changes.
(element: Element, position: { x: number; y: number }) => void
Called when context menu is opened. Receives target element and menu position.

File & Navigation Hooks

(filePath: string, lineNumber?: number) => boolean | void
Called when a file should be opened in the editor. Return false to prevent default behavior.
(url: string, filePath: string, lineNumber?: number) => string
Transform the URL used for opening files. Return modified URL.

Transform Hooks

(html: string, elements: Element[]) => string | Promise<string>
Transform HTML content before it’s used. Return modified HTML string.
(context: AgentContext, elements: Element[]) => AgentContext | Promise<AgentContext>
Transform agent context before sending to agent provider. Return modified context.
(context: ActionContext) => ActionContext
Transform action context before actions execute. Return modified context.
(snippet: string, element: Element) => string | Promise<string>
Transform code snippet for an element. Return modified snippet.

Usage

Basic Plugin

Plugin with Setup Function

Plugin with Transform Hooks

Plugin Registration

Type Definitions

See Also

  • Actions - Define custom actions for plugins
  • Agent - Configure AI agent providers
  • Theme - Theme customization options