react-grab 0.1.25 → 0.1.27

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
@@ -140,12 +140,14 @@ if (process.env.NODE_ENV === "development") {
140
140
 
141
141
  ## Plugins
142
142
 
143
- React Grab can be extended with plugins. A plugin can add context menu actions, toolbar menu items, lifecycle hooks, and theme overrides.
143
+ Use plugins to extend React Grab's built-in UI with context menu actions, toolbar menu items, lifecycle hooks, and theme overrides. Plugins run within React Grab.
144
144
 
145
- Register a plugin via `window.__REACT_GRAB__`:
145
+ Register a plugin using the `registerPlugin` and `unregisterPlugin` exports:
146
146
 
147
147
  ```js
148
- window.__REACT_GRAB__.registerPlugin({
148
+ import { registerPlugin } from "react-grab";
149
+
150
+ registerPlugin({
149
151
  name: "my-plugin",
150
152
  hooks: {
151
153
  onElementSelect: (element) => {
@@ -155,14 +157,13 @@ window.__REACT_GRAB__.registerPlugin({
155
157
  });
156
158
  ```
157
159
 
158
- In React, register inside a `useEffect` after React Grab loads:
160
+ In React, register inside a `useEffect`:
159
161
 
160
162
  ```jsx
161
- useEffect(() => {
162
- const api = window.__REACT_GRAB__;
163
- if (!api) return;
163
+ import { registerPlugin, unregisterPlugin } from "react-grab";
164
164
 
165
- api.registerPlugin({
165
+ useEffect(() => {
166
+ registerPlugin({
166
167
  name: "my-plugin",
167
168
  actions: [
168
169
  {
@@ -177,7 +178,7 @@ useEffect(() => {
177
178
  ],
178
179
  });
179
180
 
180
- return () => api.unregisterPlugin("my-plugin");
181
+ return () => unregisterPlugin("my-plugin");
181
182
  }, []);
182
183
  ```
183
184
 
@@ -205,7 +206,15 @@ See [`packages/react-grab/src/types.ts`](https://github.com/aidenybai/react-grab
205
206
 
206
207
  ## Primitives
207
208
 
208
- React Grab provides a set of primitives for building your own mini React Grab.
209
+ Use primitives to build your own element selector from scratch. Unlike plugins, primitives are standalone utility functions that don't depend on React Grab being initialized.
210
+
211
+ If you're using primitives to build a custom UI and don't want the default React Grab overlay, disable auto-initialization before importing `react-grab`:
212
+
213
+ ```html
214
+ <script>
215
+ window.__REACT_GRAB_DISABLED__ = true;
216
+ </script>
217
+ ```
209
218
 
210
219
  Here's a simple example of how to build your own element selector with hover highlight and one-click inspection:
211
220
 
@@ -213,13 +222,19 @@ Here's a simple example of how to build your own element selector with hover hig
213
222
  npm install react-grab@latest
214
223
  ```
215
224
 
216
- Then, put this in your React app:
217
-
218
225
  ```tsx
219
226
  import { useState } from "react";
220
- import { getElementContext, freeze, unfreeze, openFile, type ReactGrabElementContext } from "react-grab/primitives";
221
-
222
- const useElementSelector = (onSelect: (context: ReactGrabElementContext) => void) => {
227
+ import {
228
+ getElementContext,
229
+ freeze,
230
+ unfreeze,
231
+ openFile,
232
+ type ReactGrabElementContext,
233
+ } from "react-grab/primitives";
234
+
235
+ const useElementSelector = (
236
+ onSelect: (context: ReactGrabElementContext) => void,
237
+ ) => {
223
238
  const [isActive, setIsActive] = useState(false);
224
239
 
225
240
  const startSelecting = () => {