fixdog 0.0.1
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 +478 -0
- package/USAGE.md +77 -0
- package/dist/client/index.d.mts +110 -0
- package/dist/client/index.d.ts +110 -0
- package/dist/client/index.js +1601 -0
- package/dist/client/index.mjs +1582 -0
- package/dist/client/init.d.mts +67 -0
- package/dist/client/init.d.ts +67 -0
- package/dist/client/init.js +1609 -0
- package/dist/client/init.mjs +1593 -0
- package/dist/index.d.mts +158 -0
- package/dist/index.d.ts +158 -0
- package/dist/index.js +1635 -0
- package/dist/index.mjs +1606 -0
- package/package.json +57 -0
- package/src/api/client.ts +141 -0
- package/src/client/index.ts +75 -0
- package/src/client/init.tsx +78 -0
- package/src/components/ConversationalInputReact.tsx +406 -0
- package/src/components/ElementInfoDisplayReact.tsx +84 -0
- package/src/components/UiDogSidebarReact.tsx +49 -0
- package/src/element-detector.ts +186 -0
- package/src/index.ts +228 -0
- package/src/instrument.ts +171 -0
- package/src/sidebar-initializer.ts +171 -0
- package/src/source-resolver.ts +121 -0
- package/src/styles/sidebarStyles.ts +597 -0
- package/src/types/css.d.ts +9 -0
- package/src/types/sidebar.ts +56 -0
- package/src/types.ts +119 -0
- package/tsconfig.json +23 -0
- package/tsup.config.ts +40 -0
package/README.md
ADDED
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
# uidog-sdk-next
|
|
2
|
+
|
|
3
|
+
Next.js integration for UiDog using [Bippy](https://github.com/aidenybai/bippy) - element source detection for React apps.
|
|
4
|
+
|
|
5
|
+
This package provides **Alt+click element inspection** for Next.js applications, allowing you to click on any element in your app and see its source location (file, line, column) in a sidebar UI.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Alt+click** any element to inspect its source location
|
|
10
|
+
- **Hover highlighting** when Alt is pressed
|
|
11
|
+
- **Sidebar UI** for viewing element info and making edit requests
|
|
12
|
+
- Supports **VS Code, Cursor, WebStorm, Atom, Sublime** editors
|
|
13
|
+
- Works with **Next.js 14+** (App Router and Pages Router)
|
|
14
|
+
- **Zero build configuration** - just import and use
|
|
15
|
+
|
|
16
|
+
## Requirements
|
|
17
|
+
|
|
18
|
+
- Next.js 14.0.0 or higher
|
|
19
|
+
- React 17.0.0 or higher
|
|
20
|
+
- Development mode only (`_debugSource` is stripped in production)
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install uidog-sdk-next
|
|
26
|
+
# or
|
|
27
|
+
yarn add uidog-sdk-next
|
|
28
|
+
# or
|
|
29
|
+
pnpm add uidog-sdk-next
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Quick Start
|
|
33
|
+
|
|
34
|
+
### Step 1: Create the instrumentation file
|
|
35
|
+
|
|
36
|
+
Bippy must load **before React** to properly hook into React's internals. The setup differs based on your Next.js version.
|
|
37
|
+
|
|
38
|
+
#### Next.js 15.3+ (Recommended)
|
|
39
|
+
|
|
40
|
+
Create `instrumentation-client.ts` in your project root (same level as `package.json`):
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
// instrumentation-client.ts
|
|
44
|
+
import "uidog-sdk-next/client";
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
That's it! The package will auto-initialize with default settings.
|
|
48
|
+
|
|
49
|
+
#### Next.js 14.x - 15.2
|
|
50
|
+
|
|
51
|
+
For older Next.js versions, add the import at the very top of your `_app.tsx` or root layout:
|
|
52
|
+
|
|
53
|
+
**Pages Router (`pages/_app.tsx`):**
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
// pages/_app.tsx
|
|
57
|
+
import "uidog-sdk-next/client"; // MUST be the first import!
|
|
58
|
+
|
|
59
|
+
import type { AppProps } from "next/app";
|
|
60
|
+
|
|
61
|
+
export default function App({ Component, pageProps }: AppProps) {
|
|
62
|
+
return <Component {...pageProps} />;
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
**App Router (`app/layout.tsx`):**
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
// app/layout.tsx
|
|
70
|
+
import "uidog-sdk-next/client"; // MUST be the first import!
|
|
71
|
+
|
|
72
|
+
export default function RootLayout({
|
|
73
|
+
children,
|
|
74
|
+
}: {
|
|
75
|
+
children: React.ReactNode;
|
|
76
|
+
}) {
|
|
77
|
+
return (
|
|
78
|
+
<html lang="en">
|
|
79
|
+
<body>{children}</body>
|
|
80
|
+
</html>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Step 2: Start your development server
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
npm run dev
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Step 3: Use it!
|
|
92
|
+
|
|
93
|
+
1. Hold **Alt** (Option on Mac) and hover over elements - you'll see a blue highlight
|
|
94
|
+
2. **Alt+click** on any element to open the sidebar
|
|
95
|
+
3. The sidebar shows the element's source location (file, line, column)
|
|
96
|
+
4. Type a message describing changes you want to make
|
|
97
|
+
|
|
98
|
+
## Configuration
|
|
99
|
+
|
|
100
|
+
### Using UiDogProvider (Optional)
|
|
101
|
+
|
|
102
|
+
For more control over configuration, wrap your app with `UiDogProvider`:
|
|
103
|
+
|
|
104
|
+
```tsx
|
|
105
|
+
// app/layout.tsx (App Router)
|
|
106
|
+
import "uidog-sdk-next/client"; // Still need this first!
|
|
107
|
+
import { UiDogProvider } from "uidog-sdk-next/init";
|
|
108
|
+
|
|
109
|
+
export default function RootLayout({
|
|
110
|
+
children,
|
|
111
|
+
}: {
|
|
112
|
+
children: React.ReactNode;
|
|
113
|
+
}) {
|
|
114
|
+
return (
|
|
115
|
+
<html lang="en">
|
|
116
|
+
<body>
|
|
117
|
+
<UiDogProvider
|
|
118
|
+
editor="cursor" // Editor to open: 'vscode' | 'cursor' | 'webstorm' | 'atom' | 'sublime'
|
|
119
|
+
modifier="alt" // Key modifier: 'alt' | 'ctrl' | 'meta' | 'shift'
|
|
120
|
+
enableSidebar={true} // Show sidebar UI (set to false for console-only mode)
|
|
121
|
+
apiEndpoint="https://api.ui.dog" // API endpoint for edit requests
|
|
122
|
+
>
|
|
123
|
+
{children}
|
|
124
|
+
</UiDogProvider>
|
|
125
|
+
</body>
|
|
126
|
+
</html>
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Configuration Options
|
|
132
|
+
|
|
133
|
+
| Option | Type | Default | Description |
|
|
134
|
+
| --------------- | --------- | ---------------------- | --------------------------------------------------------------------------------------------------------- |
|
|
135
|
+
| `editor` | `string` | `'cursor'` | Editor to open. Options: `'vscode'`, `'vscode-insiders'`, `'cursor'`, `'webstorm'`, `'atom'`, `'sublime'` |
|
|
136
|
+
| `modifier` | `string` | `'alt'` | Key to hold for element selection. Options: `'alt'`, `'ctrl'`, `'meta'`, `'shift'` |
|
|
137
|
+
| `enableSidebar` | `boolean` | `true` | Show the sidebar UI. If `false`, logs to console instead |
|
|
138
|
+
| `apiEndpoint` | `string` | `'https://api.ui.dog'` | API endpoint for edit session requests |
|
|
139
|
+
| `projectPath` | `string` | `''` | Project root path for resolving relative file paths |
|
|
140
|
+
|
|
141
|
+
### Programmatic Configuration
|
|
142
|
+
|
|
143
|
+
You can also configure before auto-initialization:
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
// instrumentation-client.ts
|
|
147
|
+
import { configureUiDogNext } from "uidog-sdk-next/client";
|
|
148
|
+
|
|
149
|
+
configureUiDogNext({
|
|
150
|
+
editor: "vscode",
|
|
151
|
+
modifier: "alt",
|
|
152
|
+
enableSidebar: true,
|
|
153
|
+
});
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Manual Initialization
|
|
157
|
+
|
|
158
|
+
If you need full control, disable auto-init and initialize manually:
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
// instrumentation-client.ts
|
|
162
|
+
import { disableAutoInit } from "uidog-sdk-next/client";
|
|
163
|
+
disableAutoInit();
|
|
164
|
+
|
|
165
|
+
// Later, in your app code:
|
|
166
|
+
import { initializeUiDogNext } from "uidog-sdk-next";
|
|
167
|
+
|
|
168
|
+
initializeUiDogNext({
|
|
169
|
+
editor: "cursor",
|
|
170
|
+
enableSidebar: true,
|
|
171
|
+
});
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Complete Example: Next.js 15 App Router
|
|
175
|
+
|
|
176
|
+
### Project Structure
|
|
177
|
+
|
|
178
|
+
```
|
|
179
|
+
my-next-app/
|
|
180
|
+
├── instrumentation-client.ts # UiDog initialization
|
|
181
|
+
├── app/
|
|
182
|
+
│ ├── layout.tsx # Root layout with UiDogProvider
|
|
183
|
+
│ ├── page.tsx # Home page
|
|
184
|
+
│ └── components/
|
|
185
|
+
│ └── Button.tsx # Example component
|
|
186
|
+
├── package.json
|
|
187
|
+
└── next.config.js
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Step-by-Step Setup
|
|
191
|
+
|
|
192
|
+
**1. Install the package:**
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
npm install uidog-sdk-next
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
**2. Create `instrumentation-client.ts` in project root:**
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
// instrumentation-client.ts
|
|
202
|
+
import "uidog-sdk-next/client";
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
**3. Update `app/layout.tsx`:**
|
|
206
|
+
|
|
207
|
+
```tsx
|
|
208
|
+
// app/layout.tsx
|
|
209
|
+
import { UiDogProvider } from "uidog-sdk-next/init";
|
|
210
|
+
import "./globals.css";
|
|
211
|
+
|
|
212
|
+
export const metadata = {
|
|
213
|
+
title: "My App",
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
export default function RootLayout({
|
|
217
|
+
children,
|
|
218
|
+
}: {
|
|
219
|
+
children: React.ReactNode;
|
|
220
|
+
}) {
|
|
221
|
+
return (
|
|
222
|
+
<html lang="en">
|
|
223
|
+
<body>
|
|
224
|
+
<UiDogProvider editor="cursor">{children}</UiDogProvider>
|
|
225
|
+
</body>
|
|
226
|
+
</html>
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
**4. Create a component to test (`app/components/Button.tsx`):**
|
|
232
|
+
|
|
233
|
+
```tsx
|
|
234
|
+
// app/components/Button.tsx
|
|
235
|
+
"use client";
|
|
236
|
+
|
|
237
|
+
interface ButtonProps {
|
|
238
|
+
children: React.ReactNode;
|
|
239
|
+
onClick?: () => void;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export function Button({ children, onClick }: ButtonProps) {
|
|
243
|
+
return (
|
|
244
|
+
<button
|
|
245
|
+
onClick={onClick}
|
|
246
|
+
className="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600"
|
|
247
|
+
>
|
|
248
|
+
{children}
|
|
249
|
+
</button>
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
**5. Use the component (`app/page.tsx`):**
|
|
255
|
+
|
|
256
|
+
```tsx
|
|
257
|
+
// app/page.tsx
|
|
258
|
+
import { Button } from "./components/Button";
|
|
259
|
+
|
|
260
|
+
export default function Home() {
|
|
261
|
+
return (
|
|
262
|
+
<main className="p-8">
|
|
263
|
+
<h1 className="text-2xl font-bold mb-4">My App</h1>
|
|
264
|
+
<Button>Click me</Button>
|
|
265
|
+
</main>
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
**6. Start the dev server:**
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
npm run dev
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
**7. Test it:**
|
|
277
|
+
|
|
278
|
+
- Open http://localhost:3000
|
|
279
|
+
- Hold **Alt** and hover over the button - you'll see a blue highlight
|
|
280
|
+
- **Alt+click** on the button
|
|
281
|
+
- The sidebar opens showing `Button.tsx` with line and column numbers
|
|
282
|
+
|
|
283
|
+
## Complete Example: Next.js 14 Pages Router
|
|
284
|
+
|
|
285
|
+
### Project Structure
|
|
286
|
+
|
|
287
|
+
```
|
|
288
|
+
my-next-app/
|
|
289
|
+
├── pages/
|
|
290
|
+
│ ├── _app.tsx # App wrapper with UiDog
|
|
291
|
+
│ ├── index.tsx # Home page
|
|
292
|
+
│ └── components/
|
|
293
|
+
│ └── Card.tsx # Example component
|
|
294
|
+
├── package.json
|
|
295
|
+
└── next.config.js
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
### Step-by-Step Setup
|
|
299
|
+
|
|
300
|
+
**1. Install the package:**
|
|
301
|
+
|
|
302
|
+
```bash
|
|
303
|
+
npm install uidog-sdk-next
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
**2. Update `pages/_app.tsx`:**
|
|
307
|
+
|
|
308
|
+
```tsx
|
|
309
|
+
// pages/_app.tsx
|
|
310
|
+
import "uidog-sdk-next/client"; // MUST be first!
|
|
311
|
+
|
|
312
|
+
import type { AppProps } from "next/app";
|
|
313
|
+
import { UiDogProvider } from "uidog-sdk-next/init";
|
|
314
|
+
import "../styles/globals.css";
|
|
315
|
+
|
|
316
|
+
export default function App({ Component, pageProps }: AppProps) {
|
|
317
|
+
return (
|
|
318
|
+
<UiDogProvider editor="vscode">
|
|
319
|
+
<Component {...pageProps} />
|
|
320
|
+
</UiDogProvider>
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
**3. Create a component (`pages/components/Card.tsx`):**
|
|
326
|
+
|
|
327
|
+
```tsx
|
|
328
|
+
// pages/components/Card.tsx
|
|
329
|
+
interface CardProps {
|
|
330
|
+
title: string;
|
|
331
|
+
description: string;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export function Card({ title, description }: CardProps) {
|
|
335
|
+
return (
|
|
336
|
+
<div className="border rounded-lg p-4 shadow-sm">
|
|
337
|
+
<h2 className="text-xl font-semibold">{title}</h2>
|
|
338
|
+
<p className="text-gray-600 mt-2">{description}</p>
|
|
339
|
+
</div>
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
**4. Use the component (`pages/index.tsx`):**
|
|
345
|
+
|
|
346
|
+
```tsx
|
|
347
|
+
// pages/index.tsx
|
|
348
|
+
import { Card } from "./components/Card";
|
|
349
|
+
|
|
350
|
+
export default function Home() {
|
|
351
|
+
return (
|
|
352
|
+
<div className="p-8">
|
|
353
|
+
<h1 className="text-2xl font-bold mb-4">My App</h1>
|
|
354
|
+
<Card
|
|
355
|
+
title="Welcome"
|
|
356
|
+
description="Alt+click on this card to see its source location!"
|
|
357
|
+
/>
|
|
358
|
+
</div>
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
**5. Start and test:**
|
|
364
|
+
|
|
365
|
+
```bash
|
|
366
|
+
npm run dev
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
## Vite (React) quick start
|
|
370
|
+
|
|
371
|
+
- Development only. Import before React mounts so Bippy can hook DevTools.
|
|
372
|
+
- Add at the very top of your entry (e.g., `src/main.tsx`):
|
|
373
|
+
|
|
374
|
+
```ts
|
|
375
|
+
if (import.meta.env.DEV) {
|
|
376
|
+
import("uidog-sdk-next/client");
|
|
377
|
+
}
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
- Start Vite with `npm run dev` and use Alt+click. For library DOM (or anything without `_debugSource`), you'll see the DOM snapshot fallback instead of source mapping.
|
|
381
|
+
|
|
382
|
+
## API Reference
|
|
383
|
+
|
|
384
|
+
### Main Exports (`uidog-sdk-next`)
|
|
385
|
+
|
|
386
|
+
```typescript
|
|
387
|
+
import {
|
|
388
|
+
initializeUiDogNext, // Initialize UiDog manually
|
|
389
|
+
cleanupUiDogNext, // Cleanup all listeners and UI
|
|
390
|
+
isUiDogNextInitialized, // Check if initialized
|
|
391
|
+
openSidebar, // Programmatically open sidebar
|
|
392
|
+
closeSidebar, // Programmatically close sidebar
|
|
393
|
+
buildEditorUrl, // Build editor URL from source location
|
|
394
|
+
} from "uidog-sdk-next";
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
### Client Exports (`uidog-sdk-next/client`)
|
|
398
|
+
|
|
399
|
+
```typescript
|
|
400
|
+
import {
|
|
401
|
+
configureUiDogNext, // Configure options before auto-init
|
|
402
|
+
disableAutoInit, // Disable auto-initialization
|
|
403
|
+
initializeUiDogNext, // Manual initialization
|
|
404
|
+
} from "uidog-sdk-next/client";
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
### Provider Export (`uidog-sdk-next/init`)
|
|
408
|
+
|
|
409
|
+
```typescript
|
|
410
|
+
import { UiDogProvider } from "uidog-sdk-next/init";
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
## Troubleshooting
|
|
414
|
+
|
|
415
|
+
### "Could not find source for element"
|
|
416
|
+
|
|
417
|
+
This can happen when:
|
|
418
|
+
|
|
419
|
+
1. **Production mode**: Source info (`_debugSource`) is stripped in production builds. Make sure you're running in development mode (`npm run dev`).
|
|
420
|
+
|
|
421
|
+
2. **Server Components**: React Server Components render on the server and don't have fibers on the client. Only client components can be inspected.
|
|
422
|
+
|
|
423
|
+
3. **Library components**: Components from `node_modules` are filtered out. You can only inspect your own source code.
|
|
424
|
+
|
|
425
|
+
When source isn't available (e.g., server-rendered DOM), the sidebar will show a **DOM snapshot** instead: trimmed `outerHTML`, text content, attributes, and bounding box. This gives you “something to grab,” but still no file/line info without a client boundary.
|
|
426
|
+
|
|
427
|
+
### Sidebar doesn't appear
|
|
428
|
+
|
|
429
|
+
1. Make sure you imported `'uidog-sdk-next/client'` **before** any React imports
|
|
430
|
+
2. Check the browser console for `[UiDog Next] Initialized` message
|
|
431
|
+
3. Verify you're holding the correct modifier key (Alt by default)
|
|
432
|
+
|
|
433
|
+
### Element highlighting doesn't work
|
|
434
|
+
|
|
435
|
+
1. Check that `enableSidebar` is `true` (default)
|
|
436
|
+
2. Try a different modifier key: `modifier="ctrl"` or `modifier="meta"`
|
|
437
|
+
3. Some browser extensions may intercept Alt+click - try disabling them
|
|
438
|
+
|
|
439
|
+
### Import order issues
|
|
440
|
+
|
|
441
|
+
The import **must** be first:
|
|
442
|
+
|
|
443
|
+
```typescript
|
|
444
|
+
// CORRECT
|
|
445
|
+
import "uidog-sdk-next/client";
|
|
446
|
+
import { useState } from "react";
|
|
447
|
+
|
|
448
|
+
// WRONG - React loads before bippy can hook in
|
|
449
|
+
import { useState } from "react";
|
|
450
|
+
import "uidog-sdk-next/client";
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
## How It Works
|
|
454
|
+
|
|
455
|
+
1. **Bippy hooks into React**: When you import `'uidog-sdk-next/client'`, Bippy installs a hook at `window.__REACT_DEVTOOLS_GLOBAL_HOOK__` before React loads.
|
|
456
|
+
|
|
457
|
+
2. **React reports fiber info**: As React renders, it reports fiber tree data to the hook, including `_debugSource` metadata.
|
|
458
|
+
|
|
459
|
+
3. **Alt+click detection**: When you Alt+click an element, we find its React fiber and extract the source location.
|
|
460
|
+
|
|
461
|
+
4. **Sidebar UI**: The sidebar displays the source info and allows you to describe changes you want to make.
|
|
462
|
+
|
|
463
|
+
## Limitations
|
|
464
|
+
|
|
465
|
+
- **Development only**: `_debugSource` is stripped in production React builds
|
|
466
|
+
- **Client components only**: Server Components don't have client-side fibers
|
|
467
|
+
- **React 17-19**: Bippy supports these React versions
|
|
468
|
+
- **Next.js 14+**: Older versions may work but are not tested
|
|
469
|
+
|
|
470
|
+
## License
|
|
471
|
+
|
|
472
|
+
MIT
|
|
473
|
+
|
|
474
|
+
## Related
|
|
475
|
+
|
|
476
|
+
- [uidog-sdk](https://github.com/your-org/uidog-sdk) - Original SDK for Vite/Webpack apps
|
|
477
|
+
- [Bippy](https://github.com/aidenybai/bippy) - React fiber inspection toolkit
|
|
478
|
+
- [LocatorJS](https://github.com/nicepkg/locatorjs) - Alternative approach using Babel transforms
|
package/USAGE.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# Usage Guide
|
|
2
|
+
|
|
3
|
+
## Next.js
|
|
4
|
+
|
|
5
|
+
### Next.js 15.3+ (recommended)
|
|
6
|
+
|
|
7
|
+
1. Create `instrumentation-client.ts` at project root:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import "uidog-sdk-next/client";
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
2. Run `npm run dev` and use Alt+click in the browser.
|
|
14
|
+
|
|
15
|
+
### Next.js 14.x – 15.2
|
|
16
|
+
|
|
17
|
+
- App Router (`app/layout.tsx`), first import:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import "uidog-sdk-next/client";
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
- Pages Router (`pages/_app.tsx`), first import:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import "uidog-sdk-next/client"; // must be first!
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
- Start dev server and Alt+click.
|
|
30
|
+
|
|
31
|
+
### Optional: Provider config (sidebar, editor, modifier)
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
// app/layout.tsx or pages/_app.tsx
|
|
35
|
+
import "uidog-sdk-next/client";
|
|
36
|
+
import { UiDogProvider } from "uidog-sdk-next/init";
|
|
37
|
+
|
|
38
|
+
export default function RootLayout({ children }) {
|
|
39
|
+
return (
|
|
40
|
+
<UiDogProvider
|
|
41
|
+
editor="cursor"
|
|
42
|
+
modifier="alt"
|
|
43
|
+
enableSidebar={true}
|
|
44
|
+
apiEndpoint="https://api.ui.dog"
|
|
45
|
+
>
|
|
46
|
+
{children}
|
|
47
|
+
</UiDogProvider>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Vite (React)
|
|
53
|
+
|
|
54
|
+
Load the client only in dev and **before React mounts**.
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
// src/main.tsx (or entry), top of file
|
|
58
|
+
if (import.meta.env.DEV) {
|
|
59
|
+
import("uidog-sdk-next/client");
|
|
60
|
+
}
|
|
61
|
+
// then your normal React render
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Start Vite with `npm run dev` and Alt+click elements in the browser.
|
|
65
|
+
|
|
66
|
+
## How to use
|
|
67
|
+
|
|
68
|
+
1. Run the dev server.
|
|
69
|
+
2. Hold **Alt** (default modifier) and hover to see highlight.
|
|
70
|
+
3. **Alt+click** an element to open the sidebar.
|
|
71
|
+
4. Sidebar shows source file/line when available; otherwise a DOM snapshot (for server-rendered or library DOM).
|
|
72
|
+
|
|
73
|
+
## Notes & limits
|
|
74
|
+
|
|
75
|
+
- Dev-only; production builds strip source metadata.
|
|
76
|
+
- Server Components and library DOM won’t have source locations; the sidebar shows a DOM snapshot instead.
|
|
77
|
+
- The import must run before any React import so Bippy can hook DevTools.
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
type ElementInfoKind = "source" | "dom";
|
|
2
|
+
interface DomSnapshot {
|
|
3
|
+
outerHTML: string;
|
|
4
|
+
text: string;
|
|
5
|
+
attributes: Record<string, string>;
|
|
6
|
+
}
|
|
7
|
+
interface ElementInfo {
|
|
8
|
+
kind: ElementInfoKind;
|
|
9
|
+
componentName?: string;
|
|
10
|
+
filePath?: string;
|
|
11
|
+
line?: number;
|
|
12
|
+
column?: number;
|
|
13
|
+
domSnapshot?: DomSnapshot;
|
|
14
|
+
box?: {
|
|
15
|
+
x: number;
|
|
16
|
+
y: number;
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
type EditorType = "vscode" | "vscode-insiders" | "cursor" | "webstorm" | "atom" | "sublime";
|
|
22
|
+
interface UiDogNextOptions {
|
|
23
|
+
/**
|
|
24
|
+
* Editor to open when clicking elements
|
|
25
|
+
* @default 'cursor'
|
|
26
|
+
*/
|
|
27
|
+
editor?: EditorType;
|
|
28
|
+
/**
|
|
29
|
+
* Project root path for resolving file paths
|
|
30
|
+
*/
|
|
31
|
+
projectPath?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Modifier key for element selection
|
|
34
|
+
* @default 'alt'
|
|
35
|
+
*/
|
|
36
|
+
modifier?: "alt" | "ctrl" | "meta" | "shift";
|
|
37
|
+
/**
|
|
38
|
+
* Enable sidebar mode
|
|
39
|
+
* @default true
|
|
40
|
+
*/
|
|
41
|
+
enableSidebar?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* API endpoint for edit requests
|
|
44
|
+
* @default 'https://api.ui.dog'
|
|
45
|
+
*/
|
|
46
|
+
apiEndpoint?: string;
|
|
47
|
+
}
|
|
48
|
+
declare global {
|
|
49
|
+
interface Window {
|
|
50
|
+
__UIDOG_NEXT_INITIALIZED__?: boolean;
|
|
51
|
+
__UIDOG_SIDEBAR__?: {
|
|
52
|
+
isOpen: boolean;
|
|
53
|
+
elementInfo: ElementInfo | null;
|
|
54
|
+
editorUrl: string | null;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* UiDog SDK for Next.js - Main entry point
|
|
61
|
+
*
|
|
62
|
+
* Uses Bippy to hook into React's internals for element source detection,
|
|
63
|
+
* providing a seamless developer experience for inspecting component locations.
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Initialize UiDog for Next.js
|
|
68
|
+
*
|
|
69
|
+
* This function sets up Bippy instrumentation, element detection, and the sidebar UI.
|
|
70
|
+
* It should be called early in your application's lifecycle, ideally via
|
|
71
|
+
* instrumentation-client.ts (Next.js 15.3+) or at the top of _app.tsx.
|
|
72
|
+
*/
|
|
73
|
+
declare function initializeUiDogNext(options?: UiDogNextOptions): void;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Client entry point for UiDog Next.js integration
|
|
77
|
+
*
|
|
78
|
+
* This file is designed to be imported in:
|
|
79
|
+
* - Next.js 15.3+: instrumentation-client.ts at project root
|
|
80
|
+
* - Next.js 14.x / Pages Router: top of _app.tsx (must be first import)
|
|
81
|
+
*
|
|
82
|
+
* IMPORTANT: This file MUST be imported BEFORE React loads to properly
|
|
83
|
+
* install Bippy's React DevTools hook.
|
|
84
|
+
*
|
|
85
|
+
* Usage:
|
|
86
|
+
* ```typescript
|
|
87
|
+
* // instrumentation-client.ts (Next.js 15.3+)
|
|
88
|
+
* import 'uidog-sdk-next/client';
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* ```typescript
|
|
92
|
+
* // pages/_app.tsx (Next.js 14.x / Pages Router)
|
|
93
|
+
* import 'uidog-sdk-next/client'; // MUST be first import
|
|
94
|
+
* import type { AppProps } from 'next/app';
|
|
95
|
+
* // ... rest of your imports
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Configure UiDog options before initialization
|
|
101
|
+
* Call this before auto-initialization happens (at DOMContentLoaded)
|
|
102
|
+
*/
|
|
103
|
+
declare function configureUiDogNext(options: UiDogNextOptions): void;
|
|
104
|
+
/**
|
|
105
|
+
* Disable auto-initialization
|
|
106
|
+
* Use this if you want to manually initialize UiDog later
|
|
107
|
+
*/
|
|
108
|
+
declare function disableAutoInit(): void;
|
|
109
|
+
|
|
110
|
+
export { UiDogNextOptions, configureUiDogNext, disableAutoInit, initializeUiDogNext };
|