@zargaryanvh/react-component-inspector 1.0.4 → 1.0.7

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.
Files changed (4) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +321 -321
  3. package/dist/index.d.ts +2 -1
  4. package/package.json +61 -54
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026
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.
1
+ MIT License
2
+
3
+ Copyright (c) 2026
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 CHANGED
@@ -1,321 +1,321 @@
1
- # React Component Inspector
2
-
3
- > **A powerful development tool for inspecting React components with AI-friendly metadata extraction. Fully designed by Cursor AI.**
4
-
5
- ## 🎯 What is This?
6
-
7
- React Component Inspector is a development-only tool that helps you identify, inspect, and extract detailed metadata from React components in your application. It's designed to work seamlessly with AI coding assistants (like Cursor) by providing structured, copyable metadata about any component in your UI.
8
-
9
- ## 🔍 What Problem Does It Solve?
10
-
11
- ### The Challenge
12
- When working with AI assistants to fix or modify frontend code, you often need to:
13
- - Identify which component is responsible for a specific UI element
14
- - Understand the component's props, variants, and usage context
15
- - Get the exact file path and component structure
16
- - Extract CSS selectors and element identifiers for precise targeting
17
-
18
- **Without this tool**, you'd need to:
19
- - Manually inspect the DOM
20
- - Search through codebases
21
- - Guess component names and file locations
22
- - Manually extract element information
23
-
24
- ### The Solution
25
- React Component Inspector provides:
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
28
- - **Rich metadata extraction** - Component name, props, file path, usage context
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
31
- - **Zero production overhead** - Completely disabled in production builds
32
-
33
- ## 📊 What Data Does It Provide?
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
-
39
- When you inspect a component, you get:
40
-
41
- ### Element Identification
42
- - Element type (HTML tag)
43
- - Element text/label content
44
- - Element ID
45
- - CSS classes
46
- - CSS selector
47
- - Position and size
48
- - Role and accessibility attributes
49
-
50
- ### Component Metadata
51
- - Component name
52
- - Component ID (unique instance identifier)
53
- - Variant (if applicable)
54
- - Usage path (component hierarchy)
55
- - Instance index
56
- - Props signature (key props affecting behavior)
57
- - Source file path
58
-
59
- ### Example Output (Copy Component)
60
- ```
61
- === TYPE: COMPONENT ===
62
-
63
- === ELEMENT IDENTIFICATION ===
64
- Element Type: button
65
- Element Text/Label: "Save Transaction"
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.
78
-
79
- === COMPONENT METADATA ===
80
- ...
81
- ```
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
-
97
- ## 🚀 How to Use This Data for AI-Powered Frontend Optimization
98
-
99
- ### 1. **Precise Component Targeting**
100
- Copy the metadata and ask your AI assistant:
101
- ```
102
- "I need to modify the SaveButton component. Here's the metadata:
103
- [paste metadata]
104
-
105
- Change the button color to green and add an icon."
106
- ```
107
-
108
- ### 2. **Context-Aware Refactoring**
109
- The usage path tells you exactly where the component is used:
110
- ```
111
- "Refactor the TransactionCard component used in:
112
- ActivityPage > TransactionList > TransactionCard
113
-
114
- Make it accept a new 'priority' prop."
115
- ```
116
-
117
- ### 3. **CSS Selector Generation**
118
- Use the CSS selector for automated testing or styling:
119
- ```javascript
120
- // The metadata provides: button#save-button
121
- const saveButton = document.querySelector('button#save-button');
122
- ```
123
-
124
- ### 4. **Component Discovery**
125
- Find all instances of a component:
126
- ```
127
- "Find all instances of TransactionCard in the codebase.
128
- The component is defined in: src/components/transactions/TransactionCard.tsx"
129
- ```
130
-
131
- ### 5. **AI-Powered Debugging**
132
- Share component metadata with AI to debug issues:
133
- ```
134
- "This button isn't working. Component metadata:
135
- [paste metadata]
136
-
137
- The onClick handler should be in: src/components/buttons/SaveButton.tsx"
138
- ```
139
-
140
- ## 📦 Installation
141
-
142
- ```bash
143
- npm install react-component-inspector
144
- ```
145
-
146
- ## 🔧 Setup
147
-
148
- ### 1. Wrap Your App
149
-
150
- ```tsx
151
- import { InspectionProvider } from 'react-component-inspector';
152
- import { InspectionTooltip } from 'react-component-inspector';
153
- import { InspectionHighlight } from 'react-component-inspector';
154
- import { setupInterceptors } from 'react-component-inspector';
155
-
156
- function App() {
157
- // Setup request interceptors (optional - blocks API calls when CTRL is held)
158
- useEffect(() => {
159
- setupInterceptors();
160
- }, []);
161
-
162
- return (
163
- <InspectionProvider>
164
- <YourApp />
165
- <InspectionTooltip />
166
- <InspectionHighlight />
167
- </InspectionProvider>
168
- );
169
- }
170
- ```
171
-
172
- ### 2. Add Metadata to Components
173
-
174
- #### Option A: Using the Hook (Recommended)
175
-
176
- ```tsx
177
- import { useInspectionMetadata } from 'react-component-inspector';
178
-
179
- function MyButton({ variant, disabled, onClick }) {
180
- const inspectionProps = useInspectionMetadata({
181
- componentName: "MyButton",
182
- variant: variant,
183
- usagePath: "HomePage > ActionBar",
184
- props: { variant, disabled },
185
- sourceFile: "src/components/MyButton.tsx",
186
- });
187
-
188
- return (
189
- <button {...inspectionProps} onClick={onClick}>
190
- Click me
191
- </button>
192
- );
193
- }
194
- ```
195
-
196
- #### Option B: Using the Wrapper Component
197
-
198
- ```tsx
199
- import { InspectionWrapper } from 'react-component-inspector';
200
-
201
- function MyComponent({ variant, children }) {
202
- return (
203
- <InspectionWrapper
204
- componentName="MyComponent"
205
- variant={variant}
206
- usagePath="HomePage > ContentArea"
207
- props={{ variant }}
208
- sourceFile="src/components/MyComponent.tsx"
209
- >
210
- <div>{children}</div>
211
- </InspectionWrapper>
212
- );
213
- }
214
- ```
215
-
216
- #### Option C: Using Data Attributes (Manual)
217
-
218
- ```tsx
219
- <div
220
- data-inspection-name="MyComponent"
221
- data-inspection-id="my-component-0"
222
- data-inspection-variant="primary"
223
- data-inspection-usage-path="HomePage > ContentArea"
224
- data-inspection-instance="0"
225
- data-inspection-props="variant=primary"
226
- data-inspection-file="src/components/MyComponent.tsx"
227
- >
228
- Content
229
- </div>
230
- ```
231
-
232
- ## 🎮 Usage
233
-
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.
261
-
262
- ## 🛡️ Safety Features
263
-
264
- - **Development Only**: Completely disabled in production (`NODE_ENV !== "development"`)
265
- - **Request Blocking**: When CTRL is held, all API/Firebase requests are blocked to prevent accidental mutations
266
- - **Zero Overhead**: No code included in production builds
267
- - **Non-Intrusive**: Doesn't modify your components or affect their behavior
268
-
269
- ## 📚 Documentation
270
-
271
- - [Quick Start Guide](./docs/QUICK_START.md)
272
- - [API Reference](./docs/API.md)
273
- - [Advanced Usage](./docs/ADVANCED.md)
274
- - [AI Integration Guide](./docs/AI_INTEGRATION.md)
275
-
276
- ## 🎨 Features
277
-
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)
283
- - ✅ Rich metadata extraction
284
- - ✅ Automatic component detection (with or without `data-inspection-*`)
285
- - ✅ CSS selector generation
286
- - ✅ Usage path tracking
287
- - ✅ Instance indexing
288
- - ✅ Props signature extraction
289
- - ✅ Request blocking during inspection (when CTRL is held)
290
- - ✅ Production-safe (zero overhead)
291
-
292
- ## 🤖 Designed by Cursor AI
293
-
294
- This tool was fully designed and developed using [Cursor](https://cursor.sh), an AI-powered code editor. The entire codebase, architecture, and documentation were created through AI-assisted development, demonstrating the power of AI in building developer tools.
295
-
296
- ## 📄 License
297
-
298
- MIT
299
-
300
- ## 🤝 Contributing
301
-
302
- Contributions are welcome! Please feel free to submit a Pull Request.
303
-
304
- ## ⚠️ Important Notes
305
-
306
- - This tool is **development-only** and will not work in production
307
- - Requires Material-UI (MUI) for the tooltip UI components
308
- - Works best with TypeScript but supports JavaScript
309
- - Request interceptors are optional but recommended for safety
310
-
311
- ## 💡 Tips for AI Integration
312
-
313
- 1. **Always copy the full metadata** - It contains all context needed
314
- 2. **Include the usage path** - Helps AI understand component hierarchy
315
- 3. **Share the source file** - Directs AI to the exact location
316
- 4. **Use CSS selectors** - For precise element targeting in AI prompts
317
- 5. **Copy element text** - Helps AI understand component purpose
318
-
319
- ---
320
-
321
- **Made with ❤️ using Cursor AI**
1
+ # React Component Inspector
2
+
3
+ > **A powerful development tool for inspecting React components with AI-friendly metadata extraction. Fully designed by Cursor AI.**
4
+
5
+ ## 🎯 What is This?
6
+
7
+ React Component Inspector is a development-only tool that helps you identify, inspect, and extract detailed metadata from React components in your application. It's designed to work seamlessly with AI coding assistants (like Cursor) by providing structured, copyable metadata about any component in your UI.
8
+
9
+ ## 🔍 What Problem Does It Solve?
10
+
11
+ ### The Challenge
12
+ When working with AI assistants to fix or modify frontend code, you often need to:
13
+ - Identify which component is responsible for a specific UI element
14
+ - Understand the component's props, variants, and usage context
15
+ - Get the exact file path and component structure
16
+ - Extract CSS selectors and element identifiers for precise targeting
17
+
18
+ **Without this tool**, you'd need to:
19
+ - Manually inspect the DOM
20
+ - Search through codebases
21
+ - Guess component names and file locations
22
+ - Manually extract element information
23
+
24
+ ### The Solution
25
+ React Component Inspector provides:
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
28
+ - **Rich metadata extraction** - Component name, props, file path, usage context
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
31
+ - **Zero production overhead** - Completely disabled in production builds
32
+
33
+ ## 📊 What Data Does It Provide?
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
+
39
+ When you inspect a component, you get:
40
+
41
+ ### Element Identification
42
+ - Element type (HTML tag)
43
+ - Element text/label content
44
+ - Element ID
45
+ - CSS classes
46
+ - CSS selector
47
+ - Position and size
48
+ - Role and accessibility attributes
49
+
50
+ ### Component Metadata
51
+ - Component name
52
+ - Component ID (unique instance identifier)
53
+ - Variant (if applicable)
54
+ - Usage path (component hierarchy)
55
+ - Instance index
56
+ - Props signature (key props affecting behavior)
57
+ - Source file path
58
+
59
+ ### Example Output (Copy Component)
60
+ ```
61
+ === TYPE: COMPONENT ===
62
+
63
+ === ELEMENT IDENTIFICATION ===
64
+ Element Type: button
65
+ Element Text/Label: "Save Transaction"
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.
78
+
79
+ === COMPONENT METADATA ===
80
+ ...
81
+ ```
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
+
97
+ ## 🚀 How to Use This Data for AI-Powered Frontend Optimization
98
+
99
+ ### 1. **Precise Component Targeting**
100
+ Copy the metadata and ask your AI assistant:
101
+ ```
102
+ "I need to modify the SaveButton component. Here's the metadata:
103
+ [paste metadata]
104
+
105
+ Change the button color to green and add an icon."
106
+ ```
107
+
108
+ ### 2. **Context-Aware Refactoring**
109
+ The usage path tells you exactly where the component is used:
110
+ ```
111
+ "Refactor the TransactionCard component used in:
112
+ ActivityPage > TransactionList > TransactionCard
113
+
114
+ Make it accept a new 'priority' prop."
115
+ ```
116
+
117
+ ### 3. **CSS Selector Generation**
118
+ Use the CSS selector for automated testing or styling:
119
+ ```javascript
120
+ // The metadata provides: button#save-button
121
+ const saveButton = document.querySelector('button#save-button');
122
+ ```
123
+
124
+ ### 4. **Component Discovery**
125
+ Find all instances of a component:
126
+ ```
127
+ "Find all instances of TransactionCard in the codebase.
128
+ The component is defined in: src/components/transactions/TransactionCard.tsx"
129
+ ```
130
+
131
+ ### 5. **AI-Powered Debugging**
132
+ Share component metadata with AI to debug issues:
133
+ ```
134
+ "This button isn't working. Component metadata:
135
+ [paste metadata]
136
+
137
+ The onClick handler should be in: src/components/buttons/SaveButton.tsx"
138
+ ```
139
+
140
+ ## 📦 Installation
141
+
142
+ ```bash
143
+ npm install react-component-inspector
144
+ ```
145
+
146
+ ## 🔧 Setup
147
+
148
+ ### 1. Wrap Your App
149
+
150
+ ```tsx
151
+ import { InspectionProvider } from 'react-component-inspector';
152
+ import { InspectionTooltip } from 'react-component-inspector';
153
+ import { InspectionHighlight } from 'react-component-inspector';
154
+ import { setupInterceptors } from 'react-component-inspector';
155
+
156
+ function App() {
157
+ // Setup request interceptors (optional - blocks API calls when CTRL is held)
158
+ useEffect(() => {
159
+ setupInterceptors();
160
+ }, []);
161
+
162
+ return (
163
+ <InspectionProvider>
164
+ <YourApp />
165
+ <InspectionTooltip />
166
+ <InspectionHighlight />
167
+ </InspectionProvider>
168
+ );
169
+ }
170
+ ```
171
+
172
+ ### 2. Add Metadata to Components
173
+
174
+ #### Option A: Using the Hook (Recommended)
175
+
176
+ ```tsx
177
+ import { useInspectionMetadata } from 'react-component-inspector';
178
+
179
+ function MyButton({ variant, disabled, onClick }) {
180
+ const inspectionProps = useInspectionMetadata({
181
+ componentName: "MyButton",
182
+ variant: variant,
183
+ usagePath: "HomePage > ActionBar",
184
+ props: { variant, disabled },
185
+ sourceFile: "src/components/MyButton.tsx",
186
+ });
187
+
188
+ return (
189
+ <button {...inspectionProps} onClick={onClick}>
190
+ Click me
191
+ </button>
192
+ );
193
+ }
194
+ ```
195
+
196
+ #### Option B: Using the Wrapper Component
197
+
198
+ ```tsx
199
+ import { InspectionWrapper } from 'react-component-inspector';
200
+
201
+ function MyComponent({ variant, children }) {
202
+ return (
203
+ <InspectionWrapper
204
+ componentName="MyComponent"
205
+ variant={variant}
206
+ usagePath="HomePage > ContentArea"
207
+ props={{ variant }}
208
+ sourceFile="src/components/MyComponent.tsx"
209
+ >
210
+ <div>{children}</div>
211
+ </InspectionWrapper>
212
+ );
213
+ }
214
+ ```
215
+
216
+ #### Option C: Using Data Attributes (Manual)
217
+
218
+ ```tsx
219
+ <div
220
+ data-inspection-name="MyComponent"
221
+ data-inspection-id="my-component-0"
222
+ data-inspection-variant="primary"
223
+ data-inspection-usage-path="HomePage > ContentArea"
224
+ data-inspection-instance="0"
225
+ data-inspection-props="variant=primary"
226
+ data-inspection-file="src/components/MyComponent.tsx"
227
+ >
228
+ Content
229
+ </div>
230
+ ```
231
+
232
+ ## 🎮 Usage
233
+
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.
261
+
262
+ ## 🛡️ Safety Features
263
+
264
+ - **Development Only**: Completely disabled in production (`NODE_ENV !== "development"`)
265
+ - **Request Blocking**: When CTRL is held, all API/Firebase requests are blocked to prevent accidental mutations
266
+ - **Zero Overhead**: No code included in production builds
267
+ - **Non-Intrusive**: Doesn't modify your components or affect their behavior
268
+
269
+ ## 📚 Documentation
270
+
271
+ - [Quick Start Guide](./docs/QUICK_START.md)
272
+ - [API Reference](./docs/API.md)
273
+ - [Advanced Usage](./docs/ADVANCED.md)
274
+ - [AI Integration Guide](./docs/AI_INTEGRATION.md)
275
+
276
+ ## 🎨 Features
277
+
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)
283
+ - ✅ Rich metadata extraction
284
+ - ✅ Automatic component detection (with or without `data-inspection-*`)
285
+ - ✅ CSS selector generation
286
+ - ✅ Usage path tracking
287
+ - ✅ Instance indexing
288
+ - ✅ Props signature extraction
289
+ - ✅ Request blocking during inspection (when CTRL is held)
290
+ - ✅ Production-safe (zero overhead)
291
+
292
+ ## 🤖 Designed by Cursor AI
293
+
294
+ This tool was fully designed and developed using [Cursor](https://cursor.sh), an AI-powered code editor. The entire codebase, architecture, and documentation were created through AI-assisted development, demonstrating the power of AI in building developer tools.
295
+
296
+ ## 📄 License
297
+
298
+ MIT
299
+
300
+ ## 🤝 Contributing
301
+
302
+ Contributions are welcome! Please feel free to submit a Pull Request.
303
+
304
+ ## ⚠️ Important Notes
305
+
306
+ - This tool is **development-only** and will not work in production
307
+ - Requires Material-UI (MUI) for the tooltip UI components
308
+ - Works best with TypeScript but supports JavaScript
309
+ - Request interceptors are optional but recommended for safety
310
+
311
+ ## 💡 Tips for AI Integration
312
+
313
+ 1. **Always copy the full metadata** - It contains all context needed
314
+ 2. **Include the usage path** - Helps AI understand component hierarchy
315
+ 3. **Share the source file** - Directs AI to the exact location
316
+ 4. **Use CSS selectors** - For precise element targeting in AI prompts
317
+ 5. **Copy element text** - Helps AI understand component purpose
318
+
319
+ ---
320
+
321
+ **Made with ❤️ using Cursor AI**
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export { InspectionProvider, useInspection, ComponentMetadata } from './InspectionContext';
1
+ export { InspectionProvider, useInspection } from './InspectionContext';
2
+ export type { ComponentMetadata } from './InspectionContext';
2
3
  export { InspectionTooltip } from './InspectionTooltip';
3
4
  export { InspectionHighlight } from './InspectionHighlight';
4
5
  export { InspectionOverlays } from './InspectionOverlays';
package/package.json CHANGED
@@ -1,54 +1,61 @@
1
- {
2
- "name": "@zargaryanvh/react-component-inspector",
3
- "version": "1.0.4",
4
- "description": "A development tool for inspecting React components with AI-friendly metadata extraction",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "exports": {
8
- ".": {
9
- "import": "./dist/index.js",
10
- "require": "./dist/index.js",
11
- "types": "./dist/index.d.ts"
12
- }
13
- },
14
- "files": [
15
- "dist/**/*",
16
- "README.md",
17
- "LICENSE",
18
- "package.json"
19
- ],
20
- "scripts": {
21
- "build": "tsc",
22
- "prepublishOnly": "npm run build",
23
- "test": "echo \"Error: no test specified\" && exit 1"
24
- },
25
- "keywords": [
26
- "react",
27
- "component",
28
- "inspection",
29
- "development",
30
- "debugging",
31
- "ai",
32
- "metadata",
33
- "tool",
34
- "cursor",
35
- "cursor-ai"
36
- ],
37
- "author": "zargaryanvh",
38
- "license": "MIT",
39
- "peerDependencies": {
40
- "react": ">=16.8.0",
41
- "react-dom": ">=16.8.0",
42
- "@mui/material": ">=5.0.0",
43
- "@mui/icons-material": ">=5.0.0"
44
- },
45
- "devDependencies": {
46
- "@types/react": "^18.0.0",
47
- "@types/react-dom": "^18.0.0",
48
- "typescript": "^5.0.0"
49
- },
50
- "repository": {
51
- "type": "git",
52
- "url": "git+https://github.com/zargaryanvh/react-component-inspector.git"
53
- }
54
- }
1
+ {
2
+ "name": "@zargaryanvh/react-component-inspector",
3
+ "version": "1.0.7",
4
+ "description": "A development tool for inspecting React components with AI-friendly metadata extraction",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/index.js",
10
+ "require": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist/**/*",
16
+ "README.md",
17
+ "LICENSE",
18
+ "package.json"
19
+ ],
20
+ "scripts": {
21
+ "build": "tsc",
22
+ "prepublishOnly": "npm run build",
23
+ "test": "echo \"Error: no test specified\" && exit 1"
24
+ },
25
+ "keywords": [
26
+ "react",
27
+ "component",
28
+ "inspection",
29
+ "development",
30
+ "debugging",
31
+ "ai",
32
+ "metadata",
33
+ "tool",
34
+ "cursor",
35
+ "cursor-ai"
36
+ ],
37
+ "author": "zargaryanvh",
38
+ "license": "MIT",
39
+ "peerDependencies": {
40
+ "@mui/icons-material": ">=5.0.0",
41
+ "@mui/material": ">=5.0.0",
42
+ "react": ">=16.8.0",
43
+ "react-dom": ">=16.8.0"
44
+ },
45
+ "devDependencies": {
46
+ "@emotion/react": "^11.14.0",
47
+ "@emotion/styled": "^11.14.1",
48
+ "@mui/icons-material": "^9.0.1",
49
+ "@mui/material": "^9.0.1",
50
+ "@types/node": "^20.0.0",
51
+ "@types/react": "^18.0.0",
52
+ "@types/react-dom": "^18.0.0",
53
+ "react": "^19.2.6",
54
+ "react-dom": "^19.2.6",
55
+ "typescript": "^5.0.0"
56
+ },
57
+ "repository": {
58
+ "type": "git",
59
+ "url": "git+https://github.com/zargaryanvh/react-component-inspector.git"
60
+ }
61
+ }