@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 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** - Just hold CTRL and hover
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
+ ![Inspector tooltip showing component data, copy buttons, and how to find in code](docs/screenshots/tooltip-preview.png)
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
- Element ID: save-button
59
- Element Classes: MuiButton-root, primary-button
60
- CSS Selector: button#save-button
61
- Position: (450, 320)
62
- Size: 120x36px
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
- Component Name: SaveButton
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
- 1. **Activate**: Hold the `CTRL` key (or `Cmd` on Mac)
212
- 2. **Inspect**: Hover over any component with inspection metadata
213
- 3. **View**: A tooltip appears showing component metadata
214
- 4. **Lock**: Press `CTRL+H` to lock the tooltip position
215
- 5. **Copy**: Click the copy icon to copy metadata to clipboard
216
- 6. **Deactivate**: Release `CTRL` to exit inspection mode
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
- - โœ… Copy-to-clipboard functionality
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
- hoveredComponent: ComponentMetadata | null;
22
- hoveredElement: HTMLElement | null;
23
- setHoveredComponent: (component: ComponentMetadata | null, element: HTMLElement | null) => void;
24
- }
25
- /**
26
- * Inspection Provider - Only active in development
27
- */
28
- export declare const InspectionProvider: React.FC<{
29
- children: ReactNode;
30
- }>;
31
- /**
32
- * Hook to access inspection context
33
- */
34
- export declare const useInspection: () => InspectionState;
35
- export {};
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 {};