@zargaryanvh/react-component-inspector 1.0.0 → 1.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/dist/InspectionContext.js +50 -19
- package/dist/InspectionTooltip.js +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import React, { createContext, useContext, useState, useCallback, useEffect } from "react";
|
|
2
|
+
import React, { createContext, useContext, useState, useCallback, useEffect, useRef } from "react";
|
|
3
3
|
import { setInspectionActive } from "./inspectionInterceptors";
|
|
4
4
|
import { setupAutoInspection } from "./autoInspection";
|
|
5
5
|
const InspectionContext = createContext(undefined);
|
|
@@ -11,34 +11,47 @@ export const InspectionProvider = ({ children }) => {
|
|
|
11
11
|
const [isLocked, setIsLocked] = useState(false);
|
|
12
12
|
const [hoveredComponent, setHoveredComponentState] = useState(null);
|
|
13
13
|
const [hoveredElement, setHoveredElement] = useState(null);
|
|
14
|
+
// Use refs to always access latest state values in event handlers
|
|
15
|
+
const isInspectionActiveRef = useRef(isInspectionActive);
|
|
16
|
+
const isLockedRef = useRef(isLocked);
|
|
17
|
+
const hoveredComponentRef = useRef(hoveredComponent);
|
|
18
|
+
const hKeyPressedRef = useRef(false); // Track if H key is currently being held
|
|
19
|
+
// Keep refs in sync with state
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
isInspectionActiveRef.current = isInspectionActive;
|
|
22
|
+
}, [isInspectionActive]);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
isLockedRef.current = isLocked;
|
|
25
|
+
}, [isLocked]);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
hoveredComponentRef.current = hoveredComponent;
|
|
28
|
+
}, [hoveredComponent]);
|
|
14
29
|
// Track CTRL key state and CTRL+H for locking
|
|
15
30
|
React.useEffect(() => {
|
|
16
31
|
if (process.env.NODE_ENV !== "development") {
|
|
17
32
|
return; // Only in development
|
|
18
33
|
}
|
|
19
34
|
const handleKeyDown = (e) => {
|
|
20
|
-
// H key pressed
|
|
21
|
-
if (e.key.toLowerCase() === "h") {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
console.log("[Inspection] Tooltip locked - position fixed. Press H again or release CTRL to unlock.");
|
|
28
|
-
}
|
|
35
|
+
// H key pressed while CTRL is held - lock tooltip position
|
|
36
|
+
if (e.key.toLowerCase() === "h" && e.ctrlKey) {
|
|
37
|
+
e.preventDefault();
|
|
38
|
+
e.stopPropagation();
|
|
39
|
+
// Ignore repeated keydown events (when key is held down)
|
|
40
|
+
if (e.repeat) {
|
|
41
|
+
return;
|
|
29
42
|
}
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
setIsLocked(
|
|
43
|
+
// Only lock if inspection is active, we have a hovered component, and H is not already being held
|
|
44
|
+
if (isInspectionActiveRef.current && hoveredComponentRef.current && !hKeyPressedRef.current) {
|
|
45
|
+
hKeyPressedRef.current = true;
|
|
46
|
+
setIsLocked(true);
|
|
34
47
|
if (process.env.NODE_ENV === "development") {
|
|
35
|
-
console.log("[Inspection] Tooltip
|
|
48
|
+
console.log("[Inspection] Tooltip LOCKED - Hold H to keep locked. Release H to unlock.");
|
|
36
49
|
}
|
|
37
50
|
}
|
|
38
51
|
return;
|
|
39
52
|
}
|
|
40
53
|
// CTRL key pressed
|
|
41
|
-
if (e.key === "Control"
|
|
54
|
+
if (e.key === "Control" && !e.repeat) {
|
|
42
55
|
setIsInspectionActive(true);
|
|
43
56
|
setInspectionActive(true);
|
|
44
57
|
if (process.env.NODE_ENV === "development") {
|
|
@@ -47,10 +60,29 @@ export const InspectionProvider = ({ children }) => {
|
|
|
47
60
|
}
|
|
48
61
|
};
|
|
49
62
|
const handleKeyUp = (e) => {
|
|
63
|
+
// H key released - unlock tooltip but keep inspection active if CTRL is still held
|
|
64
|
+
if (e.key.toLowerCase() === "h") {
|
|
65
|
+
e.preventDefault();
|
|
66
|
+
e.stopPropagation();
|
|
67
|
+
// Only process if H was actually being held
|
|
68
|
+
if (hKeyPressedRef.current) {
|
|
69
|
+
const wasLocked = isLockedRef.current;
|
|
70
|
+
hKeyPressedRef.current = false;
|
|
71
|
+
// Only unlock if we were locked and CTRL is still held
|
|
72
|
+
if (wasLocked && e.ctrlKey && isInspectionActiveRef.current) {
|
|
73
|
+
setIsLocked(false);
|
|
74
|
+
if (process.env.NODE_ENV === "development") {
|
|
75
|
+
console.log("[Inspection] Tooltip UNLOCKED - inspection continues while CTRL is held.");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
50
81
|
// CTRL key released - unlock and clear
|
|
51
|
-
if (e.key === "Control"
|
|
82
|
+
if (e.key === "Control") {
|
|
52
83
|
setIsInspectionActive(false);
|
|
53
84
|
setIsLocked(false);
|
|
85
|
+
hKeyPressedRef.current = false;
|
|
54
86
|
setInspectionActive(false);
|
|
55
87
|
setHoveredComponentState(null);
|
|
56
88
|
setHoveredElement(null);
|
|
@@ -58,7 +90,6 @@ export const InspectionProvider = ({ children }) => {
|
|
|
58
90
|
console.log("[Inspection] Deactivated");
|
|
59
91
|
}
|
|
60
92
|
}
|
|
61
|
-
// Note: H key release doesn't unlock anymore - use H key press to toggle lock state
|
|
62
93
|
};
|
|
63
94
|
window.addEventListener("keydown", handleKeyDown);
|
|
64
95
|
window.addEventListener("keyup", handleKeyUp);
|
|
@@ -66,7 +97,7 @@ export const InspectionProvider = ({ children }) => {
|
|
|
66
97
|
window.removeEventListener("keydown", handleKeyDown);
|
|
67
98
|
window.removeEventListener("keyup", handleKeyUp);
|
|
68
99
|
};
|
|
69
|
-
}, [
|
|
100
|
+
}, []); // Empty deps - refs handle state access
|
|
70
101
|
const setHoveredComponent = useCallback((component, element) => {
|
|
71
102
|
if (process.env.NODE_ENV !== "development") {
|
|
72
103
|
return; // Only in development
|
|
@@ -224,7 +224,7 @@ export const InspectionTooltip = () => {
|
|
|
224
224
|
backdropFilter: "blur(8px)",
|
|
225
225
|
border: "1px solid rgba(255, 255, 255, 0.1)",
|
|
226
226
|
transition: stablePosition ? "none" : "left 0.1s ease-out, top 0.1s ease-out",
|
|
227
|
-
}, children: [_jsxs(Box, { sx: { display: "flex", justifyContent: "space-between", alignItems: "flex-start", mb: 1 }, children: [_jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [_jsx(Typography, { variant: "subtitle2", sx: { color: "#fff", fontWeight: 600, fontSize: "0.875rem" }, children: "Component Inspector" }), isLocked && (_jsx(Typography, { variant: "caption", sx: { color: "#4caf50", fontSize: "0.7rem", fontStyle: "italic" }, children: "(Locked - Release
|
|
227
|
+
}, children: [_jsxs(Box, { sx: { display: "flex", justifyContent: "space-between", alignItems: "flex-start", mb: 1 }, children: [_jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [_jsx(Typography, { variant: "subtitle2", sx: { color: "#fff", fontWeight: 600, fontSize: "0.875rem" }, children: "Component Inspector" }), isLocked && (_jsx(Typography, { variant: "caption", sx: { color: "#4caf50", fontSize: "0.7rem", fontStyle: "italic" }, children: "(Locked - Release H to unlock)" }))] }), _jsx(MuiTooltip, { title: copied ? "Copied!" : "Copy metadata", children: _jsx(IconButton, { size: "small", onClick: handleCopy, sx: {
|
|
228
228
|
color: copied ? "#4caf50" : "#fff",
|
|
229
229
|
"&:hover": { backgroundColor: "rgba(255, 255, 255, 0.1)" },
|
|
230
230
|
p: 0.5,
|
package/package.json
CHANGED