@zargaryanvh/react-component-inspector 1.0.2 โ 1.0.4
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 +72 -25
- package/dist/InspectionContext.d.ts +37 -35
- package/dist/InspectionContext.js +211 -253
- package/dist/InspectionHighlight.d.ts +2 -6
- package/dist/InspectionHighlight.js +258 -65
- package/dist/InspectionOverlays.d.ts +7 -0
- package/dist/InspectionOverlays.js +32 -0
- package/dist/InspectionTooltip.d.ts +6 -6
- package/dist/InspectionTooltip.js +406 -232
- package/dist/InspectionWrapper.d.ts +28 -28
- package/dist/InspectionWrapper.js +102 -102
- package/dist/autoInspection.d.ts +18 -14
- package/dist/autoInspection.js +329 -320
- package/dist/index.d.ts +10 -8
- package/dist/index.js +10 -9
- package/dist/inspection.d.ts +78 -29
- package/dist/inspection.js +493 -140
- package/dist/inspectionInterceptors.d.ts +27 -27
- package/dist/inspectionInterceptors.js +68 -64
- package/dist/useInspectionMetadata.d.ts +34 -34
- package/dist/useInspectionMetadata.js +67 -67
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -23,13 +23,19 @@ When working with AI assistants to fix or modify frontend code, you often need t
|
|
|
23
23
|
|
|
24
24
|
### The Solution
|
|
25
25
|
React Component Inspector provides:
|
|
26
|
-
- **One-click component identification** -
|
|
26
|
+
- **One-click component identification** - Hold CTRL and hover over any element
|
|
27
|
+
- **Margin, padding & gap inspection** - Hold CTRL+ALT to see spacing (margin, padding, flex/grid gap) and copy it for Cursor
|
|
27
28
|
- **Rich metadata extraction** - Component name, props, file path, usage context
|
|
28
|
-
- **AI-optimized format** - Copy-paste ready metadata for AI assistants
|
|
29
|
+
- **AI-optimized format** - Copy-paste ready metadata for AI assistants (Component, Margin, Padding, Gap)
|
|
30
|
+
- **How to find in code** - Tooltip shows DOM path, target element, and step-by-step how to find and modify in Cursor
|
|
29
31
|
- **Zero production overhead** - Completely disabled in production builds
|
|
30
32
|
|
|
31
33
|
## ๐ What Data Does It Provide?
|
|
32
34
|
|
|
35
|
+
When you hold **CTRL** and hover over an element, a tooltip appears showing component metadata, copy buttons (Component / Margin / Padding / Gap), and the "How to find in code" section:
|
|
36
|
+
|
|
37
|
+

|
|
38
|
+
|
|
33
39
|
When you inspect a component, you get:
|
|
34
40
|
|
|
35
41
|
### Element Identification
|
|
@@ -50,27 +56,44 @@ When you inspect a component, you get:
|
|
|
50
56
|
- Props signature (key props affecting behavior)
|
|
51
57
|
- Source file path
|
|
52
58
|
|
|
53
|
-
### Example Output
|
|
59
|
+
### Example Output (Copy Component)
|
|
54
60
|
```
|
|
61
|
+
=== TYPE: COMPONENT ===
|
|
62
|
+
|
|
55
63
|
=== ELEMENT IDENTIFICATION ===
|
|
56
64
|
Element Type: button
|
|
57
65
|
Element Text/Label: "Save Transaction"
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
66
|
+
...
|
|
67
|
+
DOM Path: body > div#root > div.MuiBox-root > button.MuiButton-root
|
|
68
|
+
Parent: div.MuiBox-root
|
|
69
|
+
Role in tree: leaf element; parent: div.MuiBox-root
|
|
70
|
+
|
|
71
|
+
=== TARGET (use this to instruct Cursor) ===
|
|
72
|
+
TARGET: The SaveButton with class MuiButton-root - position (450, 320), size 120x36px. It is the element in the DOM path above, NOT a child.
|
|
73
|
+
|
|
74
|
+
=== HOW TO FIND AND MODIFY THIS COMPONENT IN CODE ===
|
|
75
|
+
1. Use the DOM Path to locate the correct element...
|
|
76
|
+
2. Open src/components/buttons/SaveButton.tsx and find the component...
|
|
77
|
+
3. Modify the component's props, sx, or styles as needed.
|
|
63
78
|
|
|
64
79
|
=== COMPONENT METADATA ===
|
|
65
|
-
|
|
66
|
-
Component ID: save-button-0
|
|
67
|
-
Variant: primary
|
|
68
|
-
Usage Path: ActivityPage > EditTransactionModal > TransactionForm
|
|
69
|
-
Instance: 0
|
|
70
|
-
Props: variant=primary, disabled=false
|
|
71
|
-
Source File: src/components/buttons/SaveButton.tsx
|
|
80
|
+
...
|
|
72
81
|
```
|
|
73
82
|
|
|
83
|
+
When you copy **Margin**, **Padding**, or **Gap**, you get the same structure with current values and instructions for changing that spacing in code (e.g. `sx={{ m: 1 }}`, `sx={{ p: 0.5 }}`, `sx={{ gap: 1 }}`).
|
|
84
|
+
|
|
85
|
+
## ๐ How to Find and Modify in Cursor
|
|
86
|
+
|
|
87
|
+
The tooltip shows a **โHow to find in codeโ** section (same on desktop and mobile):
|
|
88
|
+
|
|
89
|
+
- **DOM Path** โ Full path from `body` to the element (e.g. `body > div#root > div.MuiBox-root > main.MuiBox-root > โฆ`)
|
|
90
|
+
- **Parent** โ Direct parent selector
|
|
91
|
+
- **Role in tree** โ e.g. โhas 3 child element(s); parent: div.MuiStack-rootโ
|
|
92
|
+
- **TARGET** โ One-line description for Cursor: โThe Card with class MuiPaper-root โ the element with margin 0px 0px 16px 0px. It is the PARENT in the DOM path above, NOT a child.โ
|
|
93
|
+
- **Steps** โ Numbered steps: use DOM path, open source file, then how to change (margin, padding, gap, or component)
|
|
94
|
+
|
|
95
|
+
When you click **Copy Component**, **Copy Margin**, **Copy Padding**, or **Copy Gap**, the clipboard gets the full block (element identification, DOM path, TARGET, and โHow to find and modify in codeโ). Paste that into Cursor and ask it to change the component, margin, padding, or gap; the text is written so Cursor can locate the right element and apply the change.
|
|
96
|
+
|
|
74
97
|
## ๐ How to Use This Data for AI-Powered Frontend Optimization
|
|
75
98
|
|
|
76
99
|
### 1. **Precise Component Targeting**
|
|
@@ -208,12 +231,33 @@ function MyComponent({ variant, children }) {
|
|
|
208
231
|
|
|
209
232
|
## ๐ฎ Usage
|
|
210
233
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
234
|
+
### Keyboard shortcuts (desktop)
|
|
235
|
+
|
|
236
|
+
| Shortcut | Action |
|
|
237
|
+
|----------|--------|
|
|
238
|
+
| **Hold CTRL** | Enter inspection mode. Hover to inspect component (box/element). |
|
|
239
|
+
| **Release CTRL** | Exit inspection mode and clear tooltip. |
|
|
240
|
+
| **Hold CTRL+ALT** | Enter margin/padding mode. See orange (margin), green (padding), purple (gap). |
|
|
241
|
+
| **CTRL+H** | Lock tooltip position so you can click copy buttons. |
|
|
242
|
+
| **CTRL+Shift+R** | Hard refresh (browser default; not captured by the inspector). |
|
|
243
|
+
|
|
244
|
+
### Basic flow
|
|
245
|
+
|
|
246
|
+
1. **Activate**: Hold `CTRL` (or `Cmd` on Mac)
|
|
247
|
+
2. **Inspect**: Hover over any element โ tooltip shows component metadata and **How to find in code**
|
|
248
|
+
3. **Copy**: Use the copy icon (component) or **Margin** / **Padding** / **Gap** buttons to copy metadata to clipboard
|
|
249
|
+
4. **Lock** (optional): Press `CTRL+H` to lock the tooltip so it doesnโt follow the cursor
|
|
250
|
+
5. **Deactivate**: Release `CTRL` to exit inspection mode
|
|
251
|
+
|
|
252
|
+
### Margin, padding & gap inspection
|
|
253
|
+
|
|
254
|
+
- **Hold CTRL+ALT** (while holding CTRL) to enter margin/padding mode. Overlays show:
|
|
255
|
+
- **Orange** = margin (outside the element)
|
|
256
|
+
- **Green** = padding (inside the element)
|
|
257
|
+
- **Purple dashed** = parentโs flex/grid gap (when the parent has `gap`)
|
|
258
|
+
- If the current element has no margin, **dashed orange** outlines show ancestors that have margin; **click an outline** to inspect that ancestor.
|
|
259
|
+
- Use the **Margin**, **Padding**, or **Gap** copy buttons in the tooltip to copy Cursor-ready text for that spacing.
|
|
260
|
+
- The tooltip always shows **DOM Path**, **Parent**, **Role in tree**, **TARGET**, and **How to find** steps so you (and Cursor) know exactly which element to change.
|
|
217
261
|
|
|
218
262
|
## ๐ก๏ธ Safety Features
|
|
219
263
|
|
|
@@ -231,15 +275,18 @@ function MyComponent({ variant, children }) {
|
|
|
231
275
|
|
|
232
276
|
## ๐จ Features
|
|
233
277
|
|
|
234
|
-
- โ
Visual component highlighting
|
|
278
|
+
- โ
Visual component highlighting (box/element outline)
|
|
279
|
+
- โ
**Margin, padding & gap inspection** (hold CTRL+ALT) with orange/green/purple overlays
|
|
280
|
+
- โ
**Ancestor margin detection** โ when the element has no margin, dashed outlines show ancestors with margin; click to inspect
|
|
281
|
+
- โ
**Copy Component / Margin / Padding / Gap** โ Cursor-ready text with DOM path, TARGET, and how to find in code
|
|
282
|
+
- โ
**โHow to find in codeโ in tooltip** โ DOM path, parent, role in tree, TARGET, and numbered steps (desktop & mobile)
|
|
235
283
|
- โ
Rich metadata extraction
|
|
236
|
-
- โ
|
|
237
|
-
- โ
Automatic component detection
|
|
284
|
+
- โ
Automatic component detection (with or without `data-inspection-*`)
|
|
238
285
|
- โ
CSS selector generation
|
|
239
286
|
- โ
Usage path tracking
|
|
240
287
|
- โ
Instance indexing
|
|
241
288
|
- โ
Props signature extraction
|
|
242
|
-
- โ
Request blocking during inspection
|
|
289
|
+
- โ
Request blocking during inspection (when CTRL is held)
|
|
243
290
|
- โ
Production-safe (zero overhead)
|
|
244
291
|
|
|
245
292
|
## ๐ค Designed by Cursor AI
|
|
@@ -1,35 +1,37 @@
|
|
|
1
|
-
import React, { ReactNode } from "react";
|
|
2
|
-
/**
|
|
3
|
-
* Component inspection metadata
|
|
4
|
-
*/
|
|
5
|
-
export interface ComponentMetadata {
|
|
6
|
-
componentName: string;
|
|
7
|
-
componentId: string;
|
|
8
|
-
variant?: string;
|
|
9
|
-
role?: string;
|
|
10
|
-
usagePath: string;
|
|
11
|
-
instanceIndex: number;
|
|
12
|
-
propsSignature: string;
|
|
13
|
-
sourceFile: string;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Inspection context state
|
|
17
|
-
*/
|
|
18
|
-
interface InspectionState {
|
|
19
|
-
isInspectionActive: boolean;
|
|
20
|
-
isLocked: boolean;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
1
|
+
import React, { ReactNode } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Component inspection metadata
|
|
4
|
+
*/
|
|
5
|
+
export interface ComponentMetadata {
|
|
6
|
+
componentName: string;
|
|
7
|
+
componentId: string;
|
|
8
|
+
variant?: string;
|
|
9
|
+
role?: string;
|
|
10
|
+
usagePath: string;
|
|
11
|
+
instanceIndex: number;
|
|
12
|
+
propsSignature: string;
|
|
13
|
+
sourceFile: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Inspection context state
|
|
17
|
+
*/
|
|
18
|
+
interface InspectionState {
|
|
19
|
+
isInspectionActive: boolean;
|
|
20
|
+
isLocked: boolean;
|
|
21
|
+
isMobile: boolean;
|
|
22
|
+
isMarginPaddingMode: boolean;
|
|
23
|
+
hoveredComponent: ComponentMetadata | null;
|
|
24
|
+
hoveredElement: HTMLElement | null;
|
|
25
|
+
setHoveredComponent: (component: ComponentMetadata | null, element: HTMLElement | null) => void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Inspection Provider - Only active in development
|
|
29
|
+
*/
|
|
30
|
+
export declare const InspectionProvider: React.FC<{
|
|
31
|
+
children: ReactNode;
|
|
32
|
+
}>;
|
|
33
|
+
/**
|
|
34
|
+
* Hook to access inspection context
|
|
35
|
+
*/
|
|
36
|
+
export declare const useInspection: () => InspectionState;
|
|
37
|
+
export {};
|