Skip to content

Commit 1cb9828

Browse files
committed
0.1.25
1 parent 0ee0709 commit 1cb9828

File tree

33 files changed

+249
-23
lines changed

33 files changed

+249
-23
lines changed

packages/cli/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @react-grab/cli
22

3+
## 0.1.25
4+
5+
### Patch Changes
6+
7+
- fix: primtiives
8+
39
## 0.1.24
410

511
### Patch Changes

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@react-grab/cli",
3-
"version": "0.1.24",
3+
"version": "0.1.25",
44
"bin": {
55
"react-grab": "./dist/cli.js"
66
},

packages/demo/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# @react-grab/demo
22

3+
## 0.1.4
4+
5+
### Patch Changes
6+
7+
- fix: primtiives
8+
- Updated dependencies
9+
- react-grab@0.1.25
10+
311
## 0.1.3
412

513
### Patch Changes

packages/demo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@react-grab/demo",
3-
"version": "0.1.3",
3+
"version": "0.1.4",
44
"private": true,
55
"scripts": {
66
"dev": "next dev --turbopack",

packages/grab/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# grab
22

3+
## 0.1.25
4+
5+
### Patch Changes
6+
7+
- fix: primtiives
8+
- Updated dependencies
9+
- @react-grab/cli@0.1.25
10+
311
## 0.1.24
412

513
### Patch Changes

packages/grab/README.md

Lines changed: 101 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,109 @@ actions: [
201201
];
202202
```
203203
204-
A plugin can provide any combination of:
204+
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.
205205
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
206+
## Primitives
211207
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.
208+
React Grab provides a set of primitives for building your own mini React Grab.
209+
210+
Here's a simple example of how to build your own element selector with hover highlight and one-click inspection:
211+
212+
```bash
213+
npm install grab@latest
214+
```
215+
216+
Then, put this in your React app:
217+
218+
```tsx
219+
import { useState } from "react";
220+
import { getElementContext, freeze, unfreeze, openFile, type ReactGrabElementContext } from "react-grab/primitives";
221+
222+
const useElementSelector = (onSelect: (context: ReactGrabElementContext) => void) => {
223+
const [isActive, setIsActive] = useState(false);
224+
225+
const startSelecting = () => {
226+
setIsActive(true);
227+
228+
const highlightOverlay = document.createElement("div");
229+
Object.assign(highlightOverlay.style, {
230+
position: "fixed",
231+
pointerEvents: "none",
232+
zIndex: "999999",
233+
border: "2px solid #3b82f6",
234+
transition: "all 75ms ease-out",
235+
display: "none",
236+
});
237+
document.body.appendChild(highlightOverlay);
238+
239+
const handleMouseMove = ({ clientX, clientY }: MouseEvent) => {
240+
highlightOverlay.style.display = "none";
241+
const target = document.elementFromPoint(clientX, clientY);
242+
if (!target) return;
243+
const { top, left, width, height } = target.getBoundingClientRect();
244+
Object.assign(highlightOverlay.style, {
245+
top: `${top}px`,
246+
left: `${left}px`,
247+
width: `${width}px`,
248+
height: `${height}px`,
249+
display: "block",
250+
});
251+
};
252+
253+
const handleClick = async ({ clientX, clientY }: MouseEvent) => {
254+
highlightOverlay.style.display = "none";
255+
const target = document.elementFromPoint(clientX, clientY);
256+
teardown();
257+
if (!target) return;
258+
freeze();
259+
onSelect(await getElementContext(target));
260+
unfreeze();
261+
};
262+
263+
const teardown = () => {
264+
document.removeEventListener("mousemove", handleMouseMove);
265+
document.removeEventListener("click", handleClick, true);
266+
highlightOverlay.remove();
267+
setIsActive(false);
268+
};
269+
270+
document.addEventListener("mousemove", handleMouseMove);
271+
document.addEventListener("click", handleClick, true);
272+
};
273+
274+
return { isActive, startSelecting };
275+
};
276+
277+
const ElementSelector = () => {
278+
const [context, setContext] = useState<ReactGrabElementContext | null>(null);
279+
const selector = useElementSelector(setContext);
280+
281+
return (
282+
<div>
283+
<button onClick={selector.startSelecting} disabled={selector.isActive}>
284+
{selector.isActive ? "Selecting…" : "Select Element"}
285+
</button>
286+
{context && (
287+
<div>
288+
<p>Component: {context.componentName}</p>
289+
<p>Selector: {context.selector}</p>
290+
<pre>{context.stackString}</pre>
291+
<button
292+
onClick={() => {
293+
const frame = context.stack[0];
294+
if (frame?.fileName) openFile(frame.fileName, frame.lineNumber);
295+
}}
296+
>
297+
Open in Editor
298+
</button>
299+
</div>
300+
)}
301+
</div>
302+
);
303+
};
304+
```
305+
306+
See [`packages/react-grab/src/primitives.ts`](https://github.com/aidenybai/react-grab/blob/main/packages/react-grab/src/primitives.ts) for the full `ReactGrabElementContext`, `getElementContext`, `freeze`, `unfreeze`, and `openFile` primitives.
213307
214308
## Resources & Contributing Back
215309

packages/grab/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "grab",
3-
"version": "0.1.24",
3+
"version": "0.1.25",
44
"description": "Select context for coding agents directly from your website",
55
"keywords": [
66
"agent",

packages/mcp/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# @react-grab/mcp
22

3+
## 0.1.25
4+
5+
### Patch Changes
6+
7+
- fix: primtiives
8+
- Updated dependencies
9+
- react-grab@0.1.25
10+
311
## 0.1.24
412

513
### Patch Changes

packages/mcp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@react-grab/mcp",
3-
"version": "0.1.24",
3+
"version": "0.1.25",
44
"bin": {
55
"react-grab-mcp": "./dist/cli.cjs"
66
},

packages/provider-ami/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# @react-grab/ami
22

3+
## 0.1.25
4+
5+
### Patch Changes
6+
7+
- fix: primtiives
8+
- Updated dependencies
9+
- react-grab@0.1.25
10+
311
## 0.1.24
412

513
### Patch Changes

0 commit comments

Comments
 (0)