@zargaryanvh/react-component-inspector 1.0.2 → 1.0.3
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.d.ts +37 -35
- package/dist/InspectionContext.js +236 -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 +382 -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 +56 -29
- package/dist/inspection.js +420 -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
|
@@ -1,64 +1,68 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Interceptors to block API and Firebase requests when CTRL is pressed
|
|
3
|
-
* Only active in development
|
|
4
|
-
*/
|
|
5
|
-
let isInspectionActive = false;
|
|
6
|
-
/**
|
|
7
|
-
* Set inspection active state (called from InspectionContext)
|
|
8
|
-
*/
|
|
9
|
-
export const setInspectionActive = (active) => {
|
|
10
|
-
if (process.env.NODE_ENV !== "development") {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
isInspectionActive = active;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Check if inspection is active and requests should be blocked
|
|
17
|
-
*/
|
|
18
|
-
export const shouldBlockRequest = () => {
|
|
19
|
-
if (process.env.NODE_ENV !== "development") {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
return isInspectionActive;
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* Intercept fetch requests (for API calls)
|
|
26
|
-
*/
|
|
27
|
-
export const setupFetchInterceptor = () => {
|
|
28
|
-
if (process.env.NODE_ENV !== "development") {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
const originalFetch = window.fetch;
|
|
32
|
-
window.fetch = async (...args) => {
|
|
33
|
-
if (shouldBlockRequest()) {
|
|
34
|
-
|
|
35
|
-
//
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Interceptors to block API and Firebase requests when CTRL is pressed
|
|
3
|
+
* Only active in development
|
|
4
|
+
*/
|
|
5
|
+
let isInspectionActive = false;
|
|
6
|
+
/**
|
|
7
|
+
* Set inspection active state (called from InspectionContext)
|
|
8
|
+
*/
|
|
9
|
+
export const setInspectionActive = (active) => {
|
|
10
|
+
if (process.env.NODE_ENV !== "development") {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
isInspectionActive = active;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Check if inspection is active and requests should be blocked
|
|
17
|
+
*/
|
|
18
|
+
export const shouldBlockRequest = () => {
|
|
19
|
+
if (process.env.NODE_ENV !== "development") {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
return isInspectionActive;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Intercept fetch requests (for API calls)
|
|
26
|
+
*/
|
|
27
|
+
export const setupFetchInterceptor = () => {
|
|
28
|
+
if (process.env.NODE_ENV !== "development") {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const originalFetch = window.fetch;
|
|
32
|
+
window.fetch = async (...args) => {
|
|
33
|
+
if (shouldBlockRequest()) {
|
|
34
|
+
const url = typeof args[0] === "string" ? args[0] : args[0]?.url ?? "";
|
|
35
|
+
// Never block health/connection checks so the app doesn't report "connection lost"
|
|
36
|
+
if (url.includes("/health") || url.includes("health?")) {
|
|
37
|
+
return originalFetch(...args);
|
|
38
|
+
}
|
|
39
|
+
console.warn("[Inspection] Blocked API request (CTRL held):", args[0]);
|
|
40
|
+
return Promise.reject(new Error("Request blocked: Inspection mode active (CTRL held)"));
|
|
41
|
+
}
|
|
42
|
+
return originalFetch(...args);
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Intercept Firebase Firestore operations
|
|
47
|
+
* Note: Firestore operations are harder to intercept at the SDK level
|
|
48
|
+
* We'll rely on blocking at the fetch level (which Firestore uses internally)
|
|
49
|
+
* and also provide a wrapper utility for direct Firestore calls
|
|
50
|
+
*/
|
|
51
|
+
export const setupFirestoreInterceptor = () => {
|
|
52
|
+
if (process.env.NODE_ENV !== "development") {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
// Firestore uses fetch internally, so the fetch interceptor will catch most operations
|
|
56
|
+
// For direct Firestore SDK calls, we'll need to wrap them manually
|
|
57
|
+
// This is a limitation of the Firestore SDK architecture
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Setup all interceptors
|
|
61
|
+
*/
|
|
62
|
+
export const setupInterceptors = () => {
|
|
63
|
+
if (process.env.NODE_ENV !== "development") {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
setupFetchInterceptor();
|
|
67
|
+
setupFirestoreInterceptor();
|
|
68
|
+
};
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
/**
|
|
3
|
-
* Hook to add inspection metadata to a component
|
|
4
|
-
*
|
|
5
|
-
* Usage:
|
|
6
|
-
* ```tsx
|
|
7
|
-
* const MyComponent = (props) => {
|
|
8
|
-
* const inspectionProps = useInspectionMetadata({
|
|
9
|
-
* componentName: "MyComponent",
|
|
10
|
-
* variant: props.variant,
|
|
11
|
-
* usagePath: "ActivityPage > TransactionList",
|
|
12
|
-
* props,
|
|
13
|
-
* sourceFile: "src/components/MyComponent.tsx",
|
|
14
|
-
* });
|
|
15
|
-
*
|
|
16
|
-
* return <Box {...inspectionProps}>...</Box>;
|
|
17
|
-
* };
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export declare const useInspectionMetadata: (config: {
|
|
21
|
-
componentName: string;
|
|
22
|
-
variant?: string;
|
|
23
|
-
role?: string;
|
|
24
|
-
usagePath: string;
|
|
25
|
-
props: Record<string, any>;
|
|
26
|
-
sourceFile: string;
|
|
27
|
-
}) => {
|
|
28
|
-
onMouseEnter: (e: React.MouseEvent) => void;
|
|
29
|
-
onMouseLeave: () => void;
|
|
30
|
-
onTouchStart: (e: React.TouchEvent) => void;
|
|
31
|
-
onTouchEnd: () => void;
|
|
32
|
-
"data-inspection-id": string;
|
|
33
|
-
"data-inspection-name": string;
|
|
34
|
-
};
|
|
1
|
+
import React from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Hook to add inspection metadata to a component
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* ```tsx
|
|
7
|
+
* const MyComponent = (props) => {
|
|
8
|
+
* const inspectionProps = useInspectionMetadata({
|
|
9
|
+
* componentName: "MyComponent",
|
|
10
|
+
* variant: props.variant,
|
|
11
|
+
* usagePath: "ActivityPage > TransactionList",
|
|
12
|
+
* props,
|
|
13
|
+
* sourceFile: "src/components/MyComponent.tsx",
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* return <Box {...inspectionProps}>...</Box>;
|
|
17
|
+
* };
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare const useInspectionMetadata: (config: {
|
|
21
|
+
componentName: string;
|
|
22
|
+
variant?: string;
|
|
23
|
+
role?: string;
|
|
24
|
+
usagePath: string;
|
|
25
|
+
props: Record<string, any>;
|
|
26
|
+
sourceFile: string;
|
|
27
|
+
}) => {
|
|
28
|
+
onMouseEnter: (e: React.MouseEvent) => void;
|
|
29
|
+
onMouseLeave: () => void;
|
|
30
|
+
onTouchStart: (e: React.TouchEvent) => void;
|
|
31
|
+
onTouchEnd: () => void;
|
|
32
|
+
"data-inspection-id": string;
|
|
33
|
+
"data-inspection-name": string;
|
|
34
|
+
};
|
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
import { useMemo } from "react";
|
|
2
|
-
import { useInspection } from "./InspectionContext";
|
|
3
|
-
import { generateComponentId, formatPropsSignature, getNextInstanceIndex, } from "./inspection";
|
|
4
|
-
/**
|
|
5
|
-
* Hook to add inspection metadata to a component
|
|
6
|
-
*
|
|
7
|
-
* Usage:
|
|
8
|
-
* ```tsx
|
|
9
|
-
* const MyComponent = (props) => {
|
|
10
|
-
* const inspectionProps = useInspectionMetadata({
|
|
11
|
-
* componentName: "MyComponent",
|
|
12
|
-
* variant: props.variant,
|
|
13
|
-
* usagePath: "ActivityPage > TransactionList",
|
|
14
|
-
* props,
|
|
15
|
-
* sourceFile: "src/components/MyComponent.tsx",
|
|
16
|
-
* });
|
|
17
|
-
*
|
|
18
|
-
* return <Box {...inspectionProps}>...</Box>;
|
|
19
|
-
* };
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export const useInspectionMetadata = (config) => {
|
|
23
|
-
const { isInspectionActive, setHoveredComponent } = useInspection();
|
|
24
|
-
const instanceIndex = useMemo(() => getNextInstanceIndex(config.componentName), [config.componentName]);
|
|
25
|
-
const metadata = useMemo(() => ({
|
|
26
|
-
componentName: config.componentName,
|
|
27
|
-
componentId: generateComponentId(config.componentName, instanceIndex),
|
|
28
|
-
variant: config.variant,
|
|
29
|
-
role: config.role,
|
|
30
|
-
usagePath: config.usagePath,
|
|
31
|
-
instanceIndex,
|
|
32
|
-
propsSignature: formatPropsSignature(config.props),
|
|
33
|
-
sourceFile: config.sourceFile,
|
|
34
|
-
}), [config, instanceIndex]);
|
|
35
|
-
const handleMouseEnter = (e) => {
|
|
36
|
-
if (!isInspectionActive)
|
|
37
|
-
return;
|
|
38
|
-
const target = e.currentTarget;
|
|
39
|
-
setHoveredComponent(metadata, target);
|
|
40
|
-
};
|
|
41
|
-
const handleMouseLeave = () => {
|
|
42
|
-
if (!isInspectionActive)
|
|
43
|
-
return;
|
|
44
|
-
setHoveredComponent(null, null);
|
|
45
|
-
};
|
|
46
|
-
// Touch handlers for mobile
|
|
47
|
-
const handleTouchStart = (e) => {
|
|
48
|
-
if (!isInspectionActive)
|
|
49
|
-
return;
|
|
50
|
-
const target = e.currentTarget;
|
|
51
|
-
setHoveredComponent(metadata, target);
|
|
52
|
-
};
|
|
53
|
-
const handleTouchEnd = () => {
|
|
54
|
-
if (!isInspectionActive)
|
|
55
|
-
return;
|
|
56
|
-
// Don't clear on touch end - let autoInspection handle it
|
|
57
|
-
// This allows touch move to continue inspecting
|
|
58
|
-
};
|
|
59
|
-
return {
|
|
60
|
-
onMouseEnter: handleMouseEnter,
|
|
61
|
-
onMouseLeave: handleMouseLeave,
|
|
62
|
-
onTouchStart: handleTouchStart,
|
|
63
|
-
onTouchEnd: handleTouchEnd,
|
|
64
|
-
"data-inspection-id": metadata.componentId,
|
|
65
|
-
"data-inspection-name": config.componentName,
|
|
66
|
-
};
|
|
67
|
-
};
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { useInspection } from "./InspectionContext";
|
|
3
|
+
import { generateComponentId, formatPropsSignature, getNextInstanceIndex, } from "./inspection";
|
|
4
|
+
/**
|
|
5
|
+
* Hook to add inspection metadata to a component
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* ```tsx
|
|
9
|
+
* const MyComponent = (props) => {
|
|
10
|
+
* const inspectionProps = useInspectionMetadata({
|
|
11
|
+
* componentName: "MyComponent",
|
|
12
|
+
* variant: props.variant,
|
|
13
|
+
* usagePath: "ActivityPage > TransactionList",
|
|
14
|
+
* props,
|
|
15
|
+
* sourceFile: "src/components/MyComponent.tsx",
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* return <Box {...inspectionProps}>...</Box>;
|
|
19
|
+
* };
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export const useInspectionMetadata = (config) => {
|
|
23
|
+
const { isInspectionActive, setHoveredComponent } = useInspection();
|
|
24
|
+
const instanceIndex = useMemo(() => getNextInstanceIndex(config.componentName), [config.componentName]);
|
|
25
|
+
const metadata = useMemo(() => ({
|
|
26
|
+
componentName: config.componentName,
|
|
27
|
+
componentId: generateComponentId(config.componentName, instanceIndex),
|
|
28
|
+
variant: config.variant,
|
|
29
|
+
role: config.role,
|
|
30
|
+
usagePath: config.usagePath,
|
|
31
|
+
instanceIndex,
|
|
32
|
+
propsSignature: formatPropsSignature(config.props),
|
|
33
|
+
sourceFile: config.sourceFile,
|
|
34
|
+
}), [config, instanceIndex]);
|
|
35
|
+
const handleMouseEnter = (e) => {
|
|
36
|
+
if (!isInspectionActive)
|
|
37
|
+
return;
|
|
38
|
+
const target = e.currentTarget;
|
|
39
|
+
setHoveredComponent(metadata, target);
|
|
40
|
+
};
|
|
41
|
+
const handleMouseLeave = () => {
|
|
42
|
+
if (!isInspectionActive)
|
|
43
|
+
return;
|
|
44
|
+
setHoveredComponent(null, null);
|
|
45
|
+
};
|
|
46
|
+
// Touch handlers for mobile
|
|
47
|
+
const handleTouchStart = (e) => {
|
|
48
|
+
if (!isInspectionActive)
|
|
49
|
+
return;
|
|
50
|
+
const target = e.currentTarget;
|
|
51
|
+
setHoveredComponent(metadata, target);
|
|
52
|
+
};
|
|
53
|
+
const handleTouchEnd = () => {
|
|
54
|
+
if (!isInspectionActive)
|
|
55
|
+
return;
|
|
56
|
+
// Don't clear on touch end - let autoInspection handle it
|
|
57
|
+
// This allows touch move to continue inspecting
|
|
58
|
+
};
|
|
59
|
+
return {
|
|
60
|
+
onMouseEnter: handleMouseEnter,
|
|
61
|
+
onMouseLeave: handleMouseLeave,
|
|
62
|
+
onTouchStart: handleTouchStart,
|
|
63
|
+
onTouchEnd: handleTouchEnd,
|
|
64
|
+
"data-inspection-id": metadata.componentId,
|
|
65
|
+
"data-inspection-name": config.componentName,
|
|
66
|
+
};
|
|
67
|
+
};
|
package/package.json
CHANGED