@react-grab/cursor 0.0.60 → 0.0.61
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 +36 -21
- package/dist/cli.cjs +16 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +13 -0
- package/dist/client.cjs +1 -0
- package/dist/client.global.js +4 -0
- package/dist/client.js +1 -0
- package/dist/server.cjs +4 -0
- package/dist/server.js +3 -0
- package/package.json +10 -4
package/README.md
CHANGED
|
@@ -18,46 +18,61 @@ yarn add @react-grab/cursor
|
|
|
18
18
|
|
|
19
19
|
The server runs on port `5567` by default.
|
|
20
20
|
|
|
21
|
+
### Quick Start (CLI)
|
|
22
|
+
|
|
23
|
+
Start the server in the background before running your dev server:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npx @react-grab/cursor && pnpm run dev
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The server will run as a detached background process. **Note:** Stopping your dev server (Ctrl+C) won't stop the React Grab server. To stop it:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pkill -f "react-grab.*server"
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Recommended: Config File (Automatic Lifecycle)
|
|
36
|
+
|
|
37
|
+
For better lifecycle management, start the server from your config file. This ensures the server stops when your dev server stops:
|
|
38
|
+
|
|
21
39
|
### Vite
|
|
22
40
|
|
|
23
41
|
```ts
|
|
24
42
|
// vite.config.ts
|
|
25
|
-
import "@react-grab/cursor/server";
|
|
43
|
+
import { startServer } from "@react-grab/cursor/server";
|
|
44
|
+
|
|
45
|
+
if (process.env.NODE_ENV === "development") {
|
|
46
|
+
startServer();
|
|
47
|
+
}
|
|
26
48
|
```
|
|
27
49
|
|
|
28
50
|
### Next.js
|
|
29
51
|
|
|
30
52
|
```ts
|
|
31
53
|
// next.config.ts
|
|
32
|
-
import "@react-grab/cursor/server";
|
|
54
|
+
import { startServer } from "@react-grab/cursor/server";
|
|
55
|
+
|
|
56
|
+
if (process.env.NODE_ENV === "development") {
|
|
57
|
+
startServer();
|
|
58
|
+
}
|
|
33
59
|
```
|
|
34
60
|
|
|
35
61
|
## Client Usage
|
|
36
62
|
|
|
37
|
-
|
|
38
|
-
import { init } from "react-grab/core";
|
|
39
|
-
import { createCursorAgentProvider } from "@react-grab/cursor/client";
|
|
40
|
-
|
|
41
|
-
const agentProvider = createCursorAgentProvider();
|
|
63
|
+
### Script Tag
|
|
42
64
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
},
|
|
47
|
-
});
|
|
65
|
+
```html
|
|
66
|
+
<script src="//unpkg.com/react-grab/dist/index.global.js"></script>
|
|
67
|
+
<script src="//unpkg.com/@react-grab/cursor/dist/client.global.js"></script>
|
|
48
68
|
```
|
|
49
69
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
You can customize the server URL and default options:
|
|
70
|
+
### ES Module
|
|
53
71
|
|
|
54
72
|
```tsx
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
workspace: "/path/to/workspace",
|
|
59
|
-
}),
|
|
60
|
-
});
|
|
73
|
+
import { attachAgent } from "@react-grab/cursor/client";
|
|
74
|
+
|
|
75
|
+
attachAgent();
|
|
61
76
|
```
|
|
62
77
|
|
|
63
78
|
## How It Works
|
package/dist/cli.cjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var child_process = require('child_process');
|
|
5
|
+
var url = require('url');
|
|
6
|
+
var path = require('path');
|
|
7
|
+
|
|
8
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
9
|
+
var __filename$1 = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli.cjs', document.baseURI).href)));
|
|
10
|
+
var __dirname$1 = path.dirname(__filename$1);
|
|
11
|
+
var serverPath = path.join(__dirname$1, "server.js");
|
|
12
|
+
child_process.spawn(process.execPath, [serverPath], {
|
|
13
|
+
detached: true,
|
|
14
|
+
stdio: "ignore"
|
|
15
|
+
}).unref();
|
|
16
|
+
console.log("[React Grab] Server starting on port 5567...");
|
package/dist/cli.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawn } from 'child_process';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
import { dirname, join } from 'path';
|
|
5
|
+
|
|
6
|
+
var __filename = fileURLToPath(import.meta.url);
|
|
7
|
+
var __dirname = dirname(__filename);
|
|
8
|
+
var serverPath = join(__dirname, "server.js");
|
|
9
|
+
spawn(process.execPath, [serverPath], {
|
|
10
|
+
detached: true,
|
|
11
|
+
stdio: "ignore"
|
|
12
|
+
}).unref();
|
|
13
|
+
console.log("[React Grab] Server starting on port 5567...");
|
package/dist/client.cjs
CHANGED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
var ReactGrabCursor=(function(exports){'use strict';var l=`http://localhost:${5567}`,A="react-grab:agent-sessions",f=n=>{let t="",r="";for(let e of n.split(`
|
|
2
|
+
`))e.startsWith("event:")?t=e.slice(6).trim():e.startsWith("data:")&&(r=e.slice(5).trim());return {eventType:t,data:r}};async function*y(n){let t=n.getReader(),r=new TextDecoder,e="";try{for(;;){let{done:o,value:i}=await t.read();i&&(e+=r.decode(i,{stream:!0}));let s;for(;(s=e.indexOf(`
|
|
3
|
+
|
|
4
|
+
`))!==-1;){let{eventType:c,data:a}=f(e.slice(0,s));if(e=e.slice(s+2),c==="done")return;if(c==="error")throw new Error(a||"Agent error");a&&(yield a);}if(o)break}}finally{t.releaseLock();}}async function*d(n,t,r){let e=await fetch(`${n}/agent`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t),signal:r});if(!e.ok)throw new Error(`Server error: ${e.status}`);if(!e.body)throw new Error("No response body");yield*y(e.body);}var E=(n={})=>{let{serverUrl:t=l,getOptions:r}=n,e=o=>({...r?.()??{},...o??{}});return {send:async function*(o,i){let s={...o,options:e(o.options)};yield*d(t,s,i);},resume:async function*(o,i){let s=sessionStorage.getItem(A);if(!s)throw new Error("No sessions to resume");let a=JSON.parse(s)[o];if(!a)throw new Error(`Session ${o} not found`);let g=a.context,p={...g,options:e(g.options)};yield "Resuming...",yield*d(t,p,i);},supportsResume:true}},C=async()=>{if(typeof window>"u")return;let n=E(),t=window.__REACT_GRAB__;if(t){t.setAgent({provider:n});return}window.addEventListener("react-grab:init",r=>{r.detail.setAgent({provider:n});},{once:true});};C();exports.attachAgent=C;exports.createCursorAgentProvider=E;return exports;})({});
|
package/dist/client.js
CHANGED
package/dist/server.cjs
CHANGED
|
@@ -7,6 +7,7 @@ var http2 = require('http2');
|
|
|
7
7
|
var stream = require('stream');
|
|
8
8
|
var crypto = require('crypto');
|
|
9
9
|
|
|
10
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
10
11
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
12
|
|
|
12
13
|
var net__default = /*#__PURE__*/_interopDefault(net);
|
|
@@ -2418,6 +2419,9 @@ var startServer = async (port = DEFAULT_PORT) => {
|
|
|
2418
2419
|
serve({ fetch: app.fetch, port });
|
|
2419
2420
|
console.log(`[React Grab] Server started on port ${port}`);
|
|
2420
2421
|
};
|
|
2422
|
+
if ((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('server.cjs', document.baseURI).href)) === `file://${process.argv[1]}`) {
|
|
2423
|
+
startServer(DEFAULT_PORT).catch(console.error);
|
|
2424
|
+
}
|
|
2421
2425
|
|
|
2422
2426
|
exports.createServer = createServer;
|
|
2423
2427
|
exports.startServer = startServer;
|
package/dist/server.js
CHANGED
|
@@ -2411,5 +2411,8 @@ var startServer = async (port = DEFAULT_PORT) => {
|
|
|
2411
2411
|
serve({ fetch: app.fetch, port });
|
|
2412
2412
|
console.log(`[React Grab] Server started on port ${port}`);
|
|
2413
2413
|
};
|
|
2414
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
2415
|
+
startServer(DEFAULT_PORT).catch(console.error);
|
|
2416
|
+
}
|
|
2414
2417
|
|
|
2415
2418
|
export { createServer, startServer };
|
package/package.json
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-grab/cursor",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.61",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"bin": {
|
|
6
|
+
"react-grab-cursor": "./dist/cli.js"
|
|
7
|
+
},
|
|
5
8
|
"exports": {
|
|
6
9
|
"./client": {
|
|
7
10
|
"types": "./dist/client.d.ts",
|
|
@@ -12,8 +15,11 @@
|
|
|
12
15
|
"types": "./dist/server.d.ts",
|
|
13
16
|
"import": "./dist/server.js",
|
|
14
17
|
"require": "./dist/server.cjs"
|
|
15
|
-
}
|
|
18
|
+
},
|
|
19
|
+
"./dist/*": "./dist/*.js",
|
|
20
|
+
"./dist/*.js": "./dist/*.js"
|
|
16
21
|
},
|
|
22
|
+
"browser": "dist/client.global.js",
|
|
17
23
|
"files": [
|
|
18
24
|
"dist"
|
|
19
25
|
],
|
|
@@ -23,10 +29,10 @@
|
|
|
23
29
|
"dependencies": {
|
|
24
30
|
"@hono/node-server": "^1.19.6",
|
|
25
31
|
"hono": "^4.0.0",
|
|
26
|
-
"react-grab": "0.0.
|
|
32
|
+
"react-grab": "0.0.61"
|
|
27
33
|
},
|
|
28
34
|
"scripts": {
|
|
29
35
|
"dev": "tsup --watch",
|
|
30
|
-
"build": "NODE_ENV=production tsup"
|
|
36
|
+
"build": "rm -rf dist && NODE_ENV=production tsup"
|
|
31
37
|
}
|
|
32
38
|
}
|