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 +30 -15
- package/dist/chunk-4HEJMPYD.cjs +26 -0
- package/dist/chunk-5O2BUFAV.js +101 -0
- package/dist/chunk-POAWRTGI.cjs +101 -0
- package/dist/chunk-STWQGYJG.js +26 -0
- package/dist/core/index.cjs +1 -1
- package/dist/core/index.d.cts +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/{index-BurXddDF.d.cts → index-CN8HkCli.d.cts} +2 -2
- package/dist/{index-BurXddDF.d.ts → index-CN8HkCli.d.ts} +2 -2
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +6 -3
- package/dist/index.d.ts +6 -3
- package/dist/index.global.js +37 -37
- package/dist/index.js +2 -2
- package/dist/primitives.cjs +2 -2
- package/dist/primitives.js +2 -2
- package/dist/styles.css +1 -1
- package/package.json +5 -13
- package/scripts/postinstall.cjs +21 -0
- package/dist/chunk-2J7DC6YX.cjs +0 -101
- package/dist/chunk-3NX6LHF6.cjs +0 -26
- package/dist/chunk-MG2QQPFZ.js +0 -101
- package/dist/chunk-T6Z6IZX5.js +0 -26
- package/dist/react.cjs +0 -19239
- package/dist/react.d.cts +0 -345
- package/dist/react.d.ts +0 -345
- package/dist/react.js +0 -19225
package/README.md
CHANGED
|
@@ -140,12 +140,14 @@ if (process.env.NODE_ENV === "development") {
|
|
|
140
140
|
|
|
141
141
|
## Plugins
|
|
142
142
|
|
|
143
|
-
|
|
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
|
|
145
|
+
Register a plugin using the `registerPlugin` and `unregisterPlugin` exports:
|
|
146
146
|
|
|
147
147
|
```js
|
|
148
|
-
|
|
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
|
|
160
|
+
In React, register inside a `useEffect`:
|
|
159
161
|
|
|
160
162
|
```jsx
|
|
161
|
-
|
|
162
|
-
const api = window.__REACT_GRAB__;
|
|
163
|
-
if (!api) return;
|
|
163
|
+
import { registerPlugin, unregisterPlugin } from "react-grab";
|
|
164
164
|
|
|
165
|
-
|
|
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 () =>
|
|
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
|
-
|
|
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 {
|
|
221
|
-
|
|
222
|
-
|
|
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 = () => {
|