@fuadnafiz98/grab 0.2.0-dev.1c5343a
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/LICENSE +21 -0
- package/README.md +163 -0
- package/bin/cli.js +12 -0
- package/dist/copy-content-CGMz3X7m.d.cts +864 -0
- package/dist/copy-content-DDha1TvA.d.ts +864 -0
- package/dist/core/index.cjs +9 -0
- package/dist/core/index.d.cts +11 -0
- package/dist/core/index.d.ts +11 -0
- package/dist/core/index.js +9 -0
- package/dist/core-B6ewlEl-.cjs +11 -0
- package/dist/core-D10aG0bT.js +11 -0
- package/dist/errors-BEgowzRA.d.ts +29 -0
- package/dist/errors-CTlIFDQs.d.cts +29 -0
- package/dist/execute-context-menu-action-Che0nlbU.cjs +9 -0
- package/dist/execute-context-menu-action-rLG0Vr3d.js +9 -0
- package/dist/freeze-updates-DJW5eM-i.cjs +43 -0
- package/dist/freeze-updates-Dq-WbRwR.js +43 -0
- package/dist/index-Bqe1Iy_L.d.cts +27 -0
- package/dist/index-WLhSTqMb.d.ts +27 -0
- package/dist/index.cjs +9 -0
- package/dist/index.d.cts +33 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.global.js +40 -0
- package/dist/index.js +9 -0
- package/dist/open-file-CYelj0h2.js +29 -0
- package/dist/open-file-R5hAPZtH.cjs +20 -0
- package/dist/primitives.cjs +10 -0
- package/dist/primitives.d.cts +131 -0
- package/dist/primitives.d.ts +131 -0
- package/dist/primitives.js +10 -0
- package/dist/renderer-KMGRDlFt.cjs +11 -0
- package/dist/renderer-pleCTv1a.js +11 -0
- package/dist/styles.css +2 -0
- package/package.json +84 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Aiden Bai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# <img src="https://github.com/fuadnafiz98/react-grab/blob/main/.github/public/logo.png?raw=true" width="60" align="center" /> Grab Fork
|
|
2
|
+
|
|
3
|
+
[](https://npmjs.com/package/@fuadnafiz98/grab)
|
|
4
|
+
[](https://npmjs.com/package/@fuadnafiz98/grab)
|
|
5
|
+
|
|
6
|
+
> [!IMPORTANT]
|
|
7
|
+
> This is [Fuad Nafiz's fork](https://github.com/fuadnafiz98/react-grab) of the [original React Grab project](https://github.com/aidenybai/react-grab). This fork restores removed features and adds missing or experimental features. Fork-specific code stays isolated where possible so upstream updates can be merged with fewer conflicts.
|
|
8
|
+
|
|
9
|
+
Copy any UI element for your agent.
|
|
10
|
+
|
|
11
|
+
React Grab points agents to the actual source behind each selection. Agents are [**2× faster**](https://react-grab.com/benchmarks) and more accurate when using React Grab.
|
|
12
|
+
|
|
13
|
+
[**Website →**](https://react-grab.com)
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
Run this at your project root:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npx @fuadnafiz98/grab@latest init
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## How It Works
|
|
24
|
+
|
|
25
|
+
React Grab turns a browser selection into source context your agent can use:
|
|
26
|
+
|
|
27
|
+
1. Hover any UI element in your app.
|
|
28
|
+
2. Press **⌘C** or **Ctrl+C**.
|
|
29
|
+
3. Paste the copied context into your agent.
|
|
30
|
+
|
|
31
|
+
The copied context includes the selected element and its component stack with source locations:
|
|
32
|
+
|
|
33
|
+
```txt
|
|
34
|
+
[<a class="ml-auto inline-block text-sm" href="#">Forgot your password?</a> in LoginForm (at components/login-form.tsx:46:19)]
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Manual Installation
|
|
38
|
+
|
|
39
|
+
If you cannot use the CLI, install React Grab manually for your framework:
|
|
40
|
+
|
|
41
|
+
#### Next.js (App router)
|
|
42
|
+
|
|
43
|
+
Add this inside your `app/layout.tsx`:
|
|
44
|
+
|
|
45
|
+
```jsx
|
|
46
|
+
import Script from "next/script";
|
|
47
|
+
|
|
48
|
+
export default function RootLayout({ children }) {
|
|
49
|
+
return (
|
|
50
|
+
<html>
|
|
51
|
+
<head>
|
|
52
|
+
{process.env.NODE_ENV === "development" && (
|
|
53
|
+
<Script
|
|
54
|
+
src="//unpkg.com/@fuadnafiz98/grab/dist/index.global.js"
|
|
55
|
+
crossOrigin="anonymous"
|
|
56
|
+
strategy="beforeInteractive"
|
|
57
|
+
/>
|
|
58
|
+
)}
|
|
59
|
+
</head>
|
|
60
|
+
<body>{children}</body>
|
|
61
|
+
</html>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
#### Next.js (Pages router)
|
|
67
|
+
|
|
68
|
+
Add this into your `pages/_document.tsx`:
|
|
69
|
+
|
|
70
|
+
```jsx
|
|
71
|
+
import { Html, Head, Main, NextScript } from "next/document";
|
|
72
|
+
import Script from "next/script";
|
|
73
|
+
|
|
74
|
+
export default function Document() {
|
|
75
|
+
return (
|
|
76
|
+
<Html lang="en">
|
|
77
|
+
<Head>
|
|
78
|
+
{process.env.NODE_ENV === "development" && (
|
|
79
|
+
<Script
|
|
80
|
+
src="//unpkg.com/@fuadnafiz98/grab/dist/index.global.js"
|
|
81
|
+
crossOrigin="anonymous"
|
|
82
|
+
strategy="beforeInteractive"
|
|
83
|
+
/>
|
|
84
|
+
)}
|
|
85
|
+
</Head>
|
|
86
|
+
<body>
|
|
87
|
+
<Main />
|
|
88
|
+
<NextScript />
|
|
89
|
+
</body>
|
|
90
|
+
</Html>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
#### Vite
|
|
96
|
+
|
|
97
|
+
Add this at the top of your main entry file (e.g., `src/main.tsx`):
|
|
98
|
+
|
|
99
|
+
```tsx
|
|
100
|
+
if (import.meta.env.DEV) {
|
|
101
|
+
import("@fuadnafiz98/grab");
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
#### Webpack
|
|
106
|
+
|
|
107
|
+
First, install React Grab:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
npm install @fuadnafiz98/grab
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Then add this at the top of your main entry file (e.g., `src/index.tsx` or `src/main.tsx`):
|
|
114
|
+
|
|
115
|
+
```tsx
|
|
116
|
+
if (process.env.NODE_ENV === "development") {
|
|
117
|
+
import("@fuadnafiz98/grab");
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Build your own React Grab
|
|
122
|
+
|
|
123
|
+
Build a custom interface with the selection engine from `@fuadnafiz98/grab/primitives`. Use its APIs for hit testing, source context, page freezing, clipboard access, and editor navigation.
|
|
124
|
+
|
|
125
|
+
### Customize hit testing
|
|
126
|
+
|
|
127
|
+
Scope hit testing to a container or replace the default element filter with your own rules.
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
import { getElementAtPoint, isElementGrabbable } from "@fuadnafiz98/grab/primitives";
|
|
131
|
+
|
|
132
|
+
export const getPickerTarget = (
|
|
133
|
+
event: PointerEvent,
|
|
134
|
+
appElement: Element,
|
|
135
|
+
toolbarElement: Element,
|
|
136
|
+
): Element | null =>
|
|
137
|
+
getElementAtPoint(event.clientX, event.clientY, {
|
|
138
|
+
container: appElement,
|
|
139
|
+
filter: (candidate) => isElementGrabbable(candidate) && !toolbarElement.contains(candidate),
|
|
140
|
+
});
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Add `data-react-grab-ignore` to your picker interface so hit testing skips its subtree.
|
|
144
|
+
|
|
145
|
+
## Resources & Contributing Back
|
|
146
|
+
|
|
147
|
+
Want to try it out? Check out [our demo](https://react-grab.com).
|
|
148
|
+
|
|
149
|
+
Looking to contribute to this fork? Check out the [Contributing Guide](https://github.com/fuadnafiz98/react-grab/blob/main/CONTRIBUTING.md).
|
|
150
|
+
|
|
151
|
+
Want to talk to the community? Hop in our [Discord](https://discord.com/invite/G7zxfUzkm7) and share your ideas and what you've built with React Grab.
|
|
152
|
+
|
|
153
|
+
Find a fork-specific bug? Use the [fork issue tracker](https://github.com/fuadnafiz98/react-grab/issues). Report upstream regressions to the [original project](https://github.com/aidenybai/react-grab/issues).
|
|
154
|
+
|
|
155
|
+
We expect all contributors to abide by the terms of our [Code of Conduct](https://github.com/fuadnafiz98/react-grab/blob/main/.github/CODE_OF_CONDUCT.md).
|
|
156
|
+
|
|
157
|
+
[**Start contributing on GitHub**](https://github.com/fuadnafiz98/react-grab/blob/main/CONTRIBUTING.md)
|
|
158
|
+
|
|
159
|
+
### License
|
|
160
|
+
|
|
161
|
+
React Grab is MIT-licensed open-source software.
|
|
162
|
+
|
|
163
|
+
_Thank you to [Andrew Luetgers](https://github.com/andrewluetgers) for donating the `grab` npm package name._
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import module from "node:module";
|
|
3
|
+
|
|
4
|
+
if (module.enableCompileCache && !process.env.NODE_DISABLE_COMPILE_CACHE) {
|
|
5
|
+
try {
|
|
6
|
+
module.enableCompileCache();
|
|
7
|
+
} catch {
|
|
8
|
+
// Ignore compile-cache errors.
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
await import("@fuadnafiz98/react-grab-cli");
|