react-grab 0.1.15 → 0.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -22,32 +22,12 @@ Run this command at your project root (where `next.config.ts` or `vite.config.ts
22
22
  npx -y grab@latest init
23
23
  ```
24
24
 
25
- Use the `-y` flag to skip interactive prompts:
26
-
27
- ```bash
28
- npx -y grab@latest init -y
29
- ```
30
-
31
- ## Connect to Your Agent
32
-
33
- Connect React Grab directly to your coding agent (Cursor, Claude Code, Codex, Gemini, Amp, and more):
34
-
35
- ```bash
36
- npx -y grab@latest add [agent]
37
- ```
38
-
39
- Or connect via MCP:
25
+ ## Connect to MCP
40
26
 
41
27
  ```bash
42
28
  npx -y grab@latest add mcp
43
29
  ```
44
30
 
45
- Disconnect an agent:
46
-
47
- ```bash
48
- npx -y grab@latest remove [agent]
49
- ```
50
-
51
31
  ## Usage
52
32
 
53
33
  Once installed, hover over any UI element in your browser and press:
@@ -158,28 +138,78 @@ if (process.env.NODE_ENV === "development") {
158
138
  }
159
139
  ```
160
140
 
161
- ## Extending React Grab
141
+ ## Plugins
142
+
143
+ React Grab can be extended with plugins. A plugin can add context menu actions, toolbar menu items, lifecycle hooks, and theme overrides.
162
144
 
163
- React Grab exposes the `__REACT_GRAB__` API for extending functionality with plugins, hooks, actions, themes, and custom agents.
145
+ Register a plugin via `window.__REACT_GRAB__`:
164
146
 
165
- See [`packages/react-grab/src/types.ts`](https://github.com/aidenybai/react-grab/blob/main/packages/react-grab/src/types.ts) and [`packages/react-grab/src/core/plugin-registry.ts`](https://github.com/aidenybai/react-grab/blob/main/packages/react-grab/src/core/plugin-registry.ts) for reference.
147
+ ```js
148
+ window.__REACT_GRAB__.registerPlugin({
149
+ name: "my-plugin",
150
+ hooks: {
151
+ onElementSelect: (element) => {
152
+ console.log("Selected:", element.tagName);
153
+ },
154
+ },
155
+ });
156
+ ```
166
157
 
167
- Or copy this into an agent to generate a plugin:
158
+ In React, register inside a `useEffect` after React Grab loads:
168
159
 
169
- ```md
170
- Clone https://github.com/aidenybai/react-grab into /tmp
160
+ ```jsx
161
+ useEffect(() => {
162
+ const api = window.__REACT_GRAB__;
163
+ if (!api) return;
164
+
165
+ api.registerPlugin({
166
+ name: "my-plugin",
167
+ actions: [
168
+ {
169
+ id: "my-action",
170
+ label: "My Action",
171
+ shortcut: "M",
172
+ onAction: (context) => {
173
+ console.log("Action on:", context.element);
174
+ context.hideContextMenu();
175
+ },
176
+ },
177
+ ],
178
+ });
179
+
180
+ return () => api.unregisterPlugin("my-plugin");
181
+ }, []);
182
+ ```
171
183
 
172
- Check these files for reference:
184
+ Actions use a `target` field to control where they appear. Omit `target` (or set `"context-menu"`) for the right-click menu, or set `"toolbar"` for the toolbar dropdown:
173
185
 
174
- - packages/react-grab/src/types.ts (Plugin and PluginHooks interfaces)
175
- - packages/react-grab/src/core/plugin-registry.ts (implementation)
186
+ ```js
187
+ actions: [
188
+ {
189
+ id: "inspect",
190
+ label: "Inspect",
191
+ shortcut: "I",
192
+ onAction: (ctx) => console.dir(ctx.element),
193
+ },
194
+ {
195
+ id: "toggle-freeze",
196
+ label: "Freeze",
197
+ target: "toolbar",
198
+ isActive: () => isFrozen,
199
+ onAction: () => toggleFreeze(),
200
+ },
201
+ ];
202
+ ```
176
203
 
177
- Plugins are registered via `__REACT_GRAB__.registerPlugin({ name, hooks, actions, theme })`.
204
+ A plugin can provide any combination of:
178
205
 
179
- Add the code in client-side code (e.g., "use client" in Next.js) inside a useEffect after React Grab loads.
206
+ - **`actions`** context menu and/or toolbar items in a single array (use `target: "toolbar"` for toolbar items)
207
+ - **`hooks`** — lifecycle callbacks like `onActivate`, `onElementSelect`, `onCopySuccess`, `transformCopyContent`, etc. (see `PluginHooks`)
208
+ - **`theme`** — partial theme overrides (see `Theme`)
209
+ - **`options`** — override default options like `activationMode` or `keyHoldDuration`
210
+ - **`setup(api)`** — a function that receives the full `ReactGrabAPI` and can return additional config or a `cleanup` function
180
211
 
181
- Generate an example plugin that logs when an element is selected.
182
- ```
212
+ See [`packages/react-grab/src/types.ts`](https://github.com/aidenybai/react-grab/blob/main/packages/react-grab/src/types.ts) for the full `Plugin`, `PluginHooks`, and `PluginConfig` interfaces.
183
213
 
184
214
  ## Resources & Contributing Back
185
215