uilint-react 0.1.35 → 0.1.38
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/{ElementBadges-M7WT4MWJ.js → ElementBadges-J2ELN2PU.js} +27 -13
- package/dist/{InspectionPanel-Z2F7PDVS.js → InspectionPanel-7N56XBWA.js} +2 -2
- package/dist/{LocatorOverlay-YTDVYPJQ.js → LocatorOverlay-RDDLASGB.js} +2 -2
- package/dist/{UILintToolbar-WF5WHENS.js → UILintToolbar-OQY2V7Q7.js} +2 -2
- package/dist/{chunk-GKYWTCFU.js → chunk-GZOQ6QWC.js} +9 -133
- package/dist/{chunk-I4JDR36K.js → chunk-PU6XPNPN.js} +191 -222
- package/dist/{chunk-3YZH4UAT.js → chunk-V4273T5B.js} +23 -63
- package/dist/chunk-WEBVLQL5.js +911 -0
- package/dist/index.d.ts +27 -59
- package/dist/index.js +6 -12
- package/package.json +2 -2
- package/dist/chunk-IGVNY64A.js +0 -695
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
// src/components/ui-lint/
|
|
3
|
+
// src/components/ui-lint/dom-utils.ts
|
|
4
4
|
var DATA_ATTR = "data-ui-lint-id";
|
|
5
5
|
var COLORS = [
|
|
6
6
|
"#3B82F6",
|
|
@@ -27,30 +27,6 @@ var SKIP_TAGS = /* @__PURE__ */ new Set([
|
|
|
27
27
|
"LINK"
|
|
28
28
|
]);
|
|
29
29
|
var elementCounter = 0;
|
|
30
|
-
function generateStableId(element, source) {
|
|
31
|
-
const dataLoc = element.getAttribute("data-loc");
|
|
32
|
-
if (dataLoc) {
|
|
33
|
-
return `loc:${dataLoc}`;
|
|
34
|
-
}
|
|
35
|
-
if (source) {
|
|
36
|
-
return `src:${source.fileName}:${source.lineNumber}:${source.columnNumber ?? 0}`;
|
|
37
|
-
}
|
|
38
|
-
return `uilint-${++elementCounter}`;
|
|
39
|
-
}
|
|
40
|
-
function getFiberFromElement(element) {
|
|
41
|
-
const keys = Object.keys(element);
|
|
42
|
-
const fiberKey = keys.find((k) => k.startsWith("__reactFiber$"));
|
|
43
|
-
if (!fiberKey) return null;
|
|
44
|
-
return element[fiberKey];
|
|
45
|
-
}
|
|
46
|
-
function getDebugSource(fiber) {
|
|
47
|
-
if (!fiber._debugSource) return null;
|
|
48
|
-
return {
|
|
49
|
-
fileName: fiber._debugSource.fileName,
|
|
50
|
-
lineNumber: fiber._debugSource.lineNumber,
|
|
51
|
-
columnNumber: fiber._debugSource.columnNumber
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
30
|
function getSourceFromDataLoc(element) {
|
|
55
31
|
const loc = element.getAttribute("data-loc");
|
|
56
32
|
if (!loc) return null;
|
|
@@ -74,31 +50,6 @@ function getSourceFromDataLoc(element) {
|
|
|
74
50
|
}
|
|
75
51
|
return null;
|
|
76
52
|
}
|
|
77
|
-
function getDebugOwner(fiber) {
|
|
78
|
-
return fiber._debugOwner ?? null;
|
|
79
|
-
}
|
|
80
|
-
function getComponentName(fiber) {
|
|
81
|
-
if (!fiber.type) return "Unknown";
|
|
82
|
-
if (typeof fiber.type === "string") return fiber.type;
|
|
83
|
-
if (typeof fiber.type === "function") {
|
|
84
|
-
const fn = fiber.type;
|
|
85
|
-
return fn.displayName || fn.name || "Anonymous";
|
|
86
|
-
}
|
|
87
|
-
return "Unknown";
|
|
88
|
-
}
|
|
89
|
-
function getComponentStack(fiber) {
|
|
90
|
-
const stack = [];
|
|
91
|
-
let current = fiber._debugOwner ?? null;
|
|
92
|
-
while (current && stack.length < 20) {
|
|
93
|
-
const name = getComponentName(current);
|
|
94
|
-
const source = getDebugSource(current);
|
|
95
|
-
if (current.tag <= 2 && name !== "Unknown") {
|
|
96
|
-
stack.push({ name, source });
|
|
97
|
-
}
|
|
98
|
-
current = current._debugOwner ?? current.return;
|
|
99
|
-
}
|
|
100
|
-
return stack;
|
|
101
|
-
}
|
|
102
53
|
function isNodeModulesPath(path) {
|
|
103
54
|
return path.includes("node_modules");
|
|
104
55
|
}
|
|
@@ -120,56 +71,25 @@ function scanDOMForSources(root = document.body, hideNodeModules = true) {
|
|
|
120
71
|
const elements = [];
|
|
121
72
|
elementCounter = 0;
|
|
122
73
|
cleanupDataAttributes();
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
74
|
+
const locElements = root.querySelectorAll("[data-loc]");
|
|
75
|
+
for (const el of locElements) {
|
|
76
|
+
if (shouldSkipElement(el)) continue;
|
|
77
|
+
const source = getSourceFromDataLoc(el);
|
|
78
|
+
if (!source) continue;
|
|
79
|
+
if (hideNodeModules && isNodeModulesPath(source.fileName)) {
|
|
80
|
+
continue;
|
|
128
81
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
componentStack = getComponentStack(fiber);
|
|
142
|
-
}
|
|
143
|
-
if (!source) {
|
|
144
|
-
source = getSourceFromDataLoc(node);
|
|
145
|
-
}
|
|
146
|
-
if (hideNodeModules && source && isNodeModulesPath(source.fileName)) {
|
|
147
|
-
const appSource = componentStack.find(
|
|
148
|
-
(c) => c.source && !isNodeModulesPath(c.source.fileName)
|
|
149
|
-
);
|
|
150
|
-
if (appSource?.source) {
|
|
151
|
-
source = appSource.source;
|
|
152
|
-
} else {
|
|
153
|
-
node = walker.nextNode();
|
|
154
|
-
continue;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
if (source) {
|
|
158
|
-
const id = generateStableId(node, source);
|
|
159
|
-
node.setAttribute(DATA_ATTR, id);
|
|
160
|
-
const scannedElement = {
|
|
161
|
-
id,
|
|
162
|
-
element: node,
|
|
163
|
-
tagName: node.tagName.toLowerCase(),
|
|
164
|
-
className: typeof node.className === "string" ? node.className : "",
|
|
165
|
-
source,
|
|
166
|
-
componentStack,
|
|
167
|
-
rect: node.getBoundingClientRect()
|
|
168
|
-
};
|
|
169
|
-
elements.push(scannedElement);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
node = walker.nextNode();
|
|
82
|
+
const dataLoc = el.getAttribute("data-loc");
|
|
83
|
+
const id = `loc:${dataLoc}`;
|
|
84
|
+
el.setAttribute(DATA_ATTR, id);
|
|
85
|
+
elements.push({
|
|
86
|
+
id,
|
|
87
|
+
element: el,
|
|
88
|
+
tagName: el.tagName.toLowerCase(),
|
|
89
|
+
className: typeof el.className === "string" ? el.className : "",
|
|
90
|
+
source,
|
|
91
|
+
rect: el.getBoundingClientRect()
|
|
92
|
+
});
|
|
173
93
|
}
|
|
174
94
|
return elements;
|
|
175
95
|
}
|
|
@@ -184,12 +104,12 @@ function groupBySourceFile(elements) {
|
|
|
184
104
|
}
|
|
185
105
|
const sourceFiles = [];
|
|
186
106
|
let colorIndex = 0;
|
|
187
|
-
for (const [path,
|
|
107
|
+
for (const [path, fileElements] of fileMap) {
|
|
188
108
|
sourceFiles.push({
|
|
189
109
|
path,
|
|
190
110
|
displayName: getDisplayName(path),
|
|
191
111
|
color: COLORS[colorIndex % COLORS.length],
|
|
192
|
-
elements:
|
|
112
|
+
elements: fileElements
|
|
193
113
|
});
|
|
194
114
|
colorIndex++;
|
|
195
115
|
}
|
|
@@ -342,18 +262,6 @@ var useUILintStore = create()((set, get) => ({
|
|
|
342
262
|
setAltKeyHeld: (held) => set({ altKeyHeld: held }),
|
|
343
263
|
locatorTarget: null,
|
|
344
264
|
setLocatorTarget: (target) => set({ locatorTarget: target }),
|
|
345
|
-
locatorStackIndex: 0,
|
|
346
|
-
setLocatorStackIndex: (index) => set({ locatorStackIndex: index }),
|
|
347
|
-
locatorGoUp: () => {
|
|
348
|
-
const { locatorTarget, locatorStackIndex } = get();
|
|
349
|
-
if (!locatorTarget) return;
|
|
350
|
-
const maxIndex = locatorTarget.componentStack.length;
|
|
351
|
-
set({ locatorStackIndex: Math.min(locatorStackIndex + 1, maxIndex) });
|
|
352
|
-
},
|
|
353
|
-
locatorGoDown: () => {
|
|
354
|
-
const { locatorStackIndex } = get();
|
|
355
|
-
set({ locatorStackIndex: Math.max(locatorStackIndex - 1, 0) });
|
|
356
|
-
},
|
|
357
265
|
// ============ Inspection ============
|
|
358
266
|
inspectedElement: null,
|
|
359
267
|
setInspectedElement: (el) => set({ inspectedElement: el }),
|
|
@@ -380,7 +288,8 @@ var useUILintStore = create()((set, get) => ({
|
|
|
380
288
|
set({
|
|
381
289
|
scanLock: true,
|
|
382
290
|
scanPaused: false,
|
|
383
|
-
scanAborted: false
|
|
291
|
+
scanAborted: false,
|
|
292
|
+
pendingNewElements: 0
|
|
384
293
|
});
|
|
385
294
|
const elements = scanDOMForSources(document.body, hideNodeModules);
|
|
386
295
|
const initialCache = /* @__PURE__ */ new Map();
|
|
@@ -422,7 +331,8 @@ var useUILintStore = create()((set, get) => ({
|
|
|
422
331
|
scanPaused: false,
|
|
423
332
|
scanLock: false,
|
|
424
333
|
autoScanState: DEFAULT_AUTO_SCAN_STATE,
|
|
425
|
-
elementIssuesCache: /* @__PURE__ */ new Map()
|
|
334
|
+
elementIssuesCache: /* @__PURE__ */ new Map(),
|
|
335
|
+
pendingNewElements: 0
|
|
426
336
|
});
|
|
427
337
|
},
|
|
428
338
|
_runScanLoop: async (elements, startIndex) => {
|
|
@@ -484,6 +394,27 @@ var useUILintStore = create()((set, get) => ({
|
|
|
484
394
|
}
|
|
485
395
|
});
|
|
486
396
|
},
|
|
397
|
+
// ============ Navigation Detection ============
|
|
398
|
+
pendingNewElements: 0,
|
|
399
|
+
setPendingNewElements: (count) => set({ pendingNewElements: count }),
|
|
400
|
+
clearPendingNewElements: () => set({ pendingNewElements: 0 }),
|
|
401
|
+
removeStaleResults: (elementIds) => set((state) => {
|
|
402
|
+
const newCache = new Map(state.elementIssuesCache);
|
|
403
|
+
const newElements = state.autoScanState.elements.filter(
|
|
404
|
+
(el) => !elementIds.includes(el.id)
|
|
405
|
+
);
|
|
406
|
+
for (const id of elementIds) {
|
|
407
|
+
newCache.delete(id);
|
|
408
|
+
}
|
|
409
|
+
return {
|
|
410
|
+
elementIssuesCache: newCache,
|
|
411
|
+
autoScanState: {
|
|
412
|
+
...state.autoScanState,
|
|
413
|
+
elements: newElements,
|
|
414
|
+
totalElements: newElements.length
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
}),
|
|
487
418
|
// ============ WebSocket ============
|
|
488
419
|
wsConnection: null,
|
|
489
420
|
wsConnected: false,
|
|
@@ -735,27 +666,128 @@ var useUILintStore = create()((set, get) => ({
|
|
|
735
666
|
get().connectWebSocket(wsUrl);
|
|
736
667
|
}
|
|
737
668
|
}));
|
|
738
|
-
function useEffectiveLocatorTarget() {
|
|
739
|
-
const locatorTarget = useUILintStore((s) => s.locatorTarget);
|
|
740
|
-
const locatorStackIndex = useUILintStore(
|
|
741
|
-
(s) => s.locatorStackIndex
|
|
742
|
-
);
|
|
743
|
-
if (!locatorTarget) return null;
|
|
744
|
-
return {
|
|
745
|
-
...locatorTarget,
|
|
746
|
-
stackIndex: locatorStackIndex
|
|
747
|
-
};
|
|
748
|
-
}
|
|
749
669
|
|
|
750
670
|
// src/components/ui-lint/UILintProvider.tsx
|
|
751
671
|
import {
|
|
752
672
|
createContext,
|
|
753
673
|
useContext,
|
|
754
674
|
useState,
|
|
755
|
-
useEffect,
|
|
756
|
-
useCallback,
|
|
675
|
+
useEffect as useEffect2,
|
|
676
|
+
useCallback as useCallback2,
|
|
757
677
|
useMemo
|
|
758
678
|
} from "react";
|
|
679
|
+
|
|
680
|
+
// src/components/ui-lint/useDOMObserver.ts
|
|
681
|
+
import { useEffect, useRef, useCallback } from "react";
|
|
682
|
+
var RECONCILE_DEBOUNCE_MS = 100;
|
|
683
|
+
function useDOMObserver(enabled = true) {
|
|
684
|
+
const observerRef = useRef(null);
|
|
685
|
+
const reconcileTimeoutRef = useRef(
|
|
686
|
+
null
|
|
687
|
+
);
|
|
688
|
+
const lastScanElementIdsRef = useRef(/* @__PURE__ */ new Set());
|
|
689
|
+
const setPendingNewElements = useUILintStore(
|
|
690
|
+
(s) => s.setPendingNewElements
|
|
691
|
+
);
|
|
692
|
+
const removeStaleResults = useUILintStore(
|
|
693
|
+
(s) => s.removeStaleResults
|
|
694
|
+
);
|
|
695
|
+
const autoScanState = useUILintStore((s) => s.autoScanState);
|
|
696
|
+
useEffect(() => {
|
|
697
|
+
if (autoScanState.status === "complete") {
|
|
698
|
+
const ids = new Set(autoScanState.elements.map((el) => el.id));
|
|
699
|
+
lastScanElementIdsRef.current = ids;
|
|
700
|
+
}
|
|
701
|
+
}, [autoScanState.status, autoScanState.elements]);
|
|
702
|
+
const reconcileElements = useCallback(() => {
|
|
703
|
+
const currentElements = document.querySelectorAll("[data-loc]");
|
|
704
|
+
const currentIds = /* @__PURE__ */ new Set();
|
|
705
|
+
for (const el of currentElements) {
|
|
706
|
+
const dataLoc = el.getAttribute("data-loc");
|
|
707
|
+
if (dataLoc) {
|
|
708
|
+
currentIds.add(`loc:${dataLoc}`);
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
const lastScanIds = lastScanElementIdsRef.current;
|
|
712
|
+
if (lastScanIds.size === 0) return;
|
|
713
|
+
const newElementIds = [];
|
|
714
|
+
for (const id of currentIds) {
|
|
715
|
+
if (!lastScanIds.has(id)) {
|
|
716
|
+
newElementIds.push(id);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
const removedElementIds = [];
|
|
720
|
+
for (const id of lastScanIds) {
|
|
721
|
+
if (!currentIds.has(id)) {
|
|
722
|
+
removedElementIds.push(id);
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
if (newElementIds.length > 0) {
|
|
726
|
+
setPendingNewElements(newElementIds.length);
|
|
727
|
+
}
|
|
728
|
+
if (removedElementIds.length > 0) {
|
|
729
|
+
removeStaleResults(removedElementIds);
|
|
730
|
+
}
|
|
731
|
+
}, [setPendingNewElements, removeStaleResults]);
|
|
732
|
+
const debouncedReconcile = useCallback(() => {
|
|
733
|
+
if (reconcileTimeoutRef.current) {
|
|
734
|
+
clearTimeout(reconcileTimeoutRef.current);
|
|
735
|
+
}
|
|
736
|
+
reconcileTimeoutRef.current = setTimeout(() => {
|
|
737
|
+
reconcileElements();
|
|
738
|
+
reconcileTimeoutRef.current = null;
|
|
739
|
+
}, RECONCILE_DEBOUNCE_MS);
|
|
740
|
+
}, [reconcileElements]);
|
|
741
|
+
useEffect(() => {
|
|
742
|
+
if (!enabled) return;
|
|
743
|
+
if (typeof window === "undefined") return;
|
|
744
|
+
const observer = new MutationObserver((mutations) => {
|
|
745
|
+
let hasRelevantChanges = false;
|
|
746
|
+
for (const mutation of mutations) {
|
|
747
|
+
for (const node of mutation.addedNodes) {
|
|
748
|
+
if (node instanceof Element) {
|
|
749
|
+
if (node.hasAttribute("data-loc")) {
|
|
750
|
+
hasRelevantChanges = true;
|
|
751
|
+
break;
|
|
752
|
+
}
|
|
753
|
+
if (node.querySelector("[data-loc]")) {
|
|
754
|
+
hasRelevantChanges = true;
|
|
755
|
+
break;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
if (hasRelevantChanges) break;
|
|
760
|
+
for (const node of mutation.removedNodes) {
|
|
761
|
+
if (node instanceof Element) {
|
|
762
|
+
if (node.hasAttribute("data-loc") || node.querySelector("[data-loc]")) {
|
|
763
|
+
hasRelevantChanges = true;
|
|
764
|
+
break;
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
if (hasRelevantChanges) break;
|
|
769
|
+
}
|
|
770
|
+
if (hasRelevantChanges) {
|
|
771
|
+
debouncedReconcile();
|
|
772
|
+
}
|
|
773
|
+
});
|
|
774
|
+
observer.observe(document.body, {
|
|
775
|
+
childList: true,
|
|
776
|
+
subtree: true
|
|
777
|
+
});
|
|
778
|
+
observerRef.current = observer;
|
|
779
|
+
return () => {
|
|
780
|
+
observer.disconnect();
|
|
781
|
+
observerRef.current = null;
|
|
782
|
+
if (reconcileTimeoutRef.current) {
|
|
783
|
+
clearTimeout(reconcileTimeoutRef.current);
|
|
784
|
+
reconcileTimeoutRef.current = null;
|
|
785
|
+
}
|
|
786
|
+
};
|
|
787
|
+
}, [enabled, debouncedReconcile]);
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
// src/components/ui-lint/UILintProvider.tsx
|
|
759
791
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
760
792
|
var UILintContext = createContext(null);
|
|
761
793
|
function useUILintContext() {
|
|
@@ -777,17 +809,10 @@ function UILintProvider({
|
|
|
777
809
|
const updateSettings = useUILintStore((s) => s.updateSettings);
|
|
778
810
|
const altKeyHeld = useUILintStore((s) => s.altKeyHeld);
|
|
779
811
|
const setAltKeyHeld = useUILintStore((s) => s.setAltKeyHeld);
|
|
812
|
+
const locatorTarget = useUILintStore((s) => s.locatorTarget);
|
|
780
813
|
const setLocatorTarget = useUILintStore(
|
|
781
814
|
(s) => s.setLocatorTarget
|
|
782
815
|
);
|
|
783
|
-
const locatorStackIndex = useUILintStore(
|
|
784
|
-
(s) => s.locatorStackIndex
|
|
785
|
-
);
|
|
786
|
-
const setLocatorStackIndex = useUILintStore(
|
|
787
|
-
(s) => s.setLocatorStackIndex
|
|
788
|
-
);
|
|
789
|
-
const locatorGoUp = useUILintStore((s) => s.locatorGoUp);
|
|
790
|
-
const locatorGoDown = useUILintStore((s) => s.locatorGoDown);
|
|
791
816
|
const inspectedElement = useUILintStore(
|
|
792
817
|
(s) => s.inspectedElement
|
|
793
818
|
);
|
|
@@ -808,45 +833,24 @@ function UILintProvider({
|
|
|
808
833
|
const disconnectWebSocket = useUILintStore(
|
|
809
834
|
(s) => s.disconnectWebSocket
|
|
810
835
|
);
|
|
811
|
-
|
|
812
|
-
const getLocatorTargetFromElement =
|
|
836
|
+
useDOMObserver(enabled && isMounted);
|
|
837
|
+
const getLocatorTargetFromElement = useCallback2(
|
|
813
838
|
(element) => {
|
|
814
839
|
if (element.closest("[data-ui-lint]")) return null;
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
source = getDebugSource(fiber);
|
|
820
|
-
if (!source && fiber._debugOwner) {
|
|
821
|
-
source = getDebugSource(fiber._debugOwner);
|
|
822
|
-
}
|
|
823
|
-
componentStack = getComponentStack(fiber);
|
|
824
|
-
}
|
|
825
|
-
if (!source) {
|
|
826
|
-
source = getSourceFromDataLoc(element);
|
|
827
|
-
}
|
|
828
|
-
if (!source && componentStack.length === 0) return null;
|
|
829
|
-
if (settings.hideNodeModules && source && isNodeModulesPath(source.fileName)) {
|
|
830
|
-
const appSource = componentStack.find(
|
|
831
|
-
(c) => c.source && !isNodeModulesPath(c.source.fileName)
|
|
832
|
-
);
|
|
833
|
-
if (appSource?.source) {
|
|
834
|
-
source = appSource.source;
|
|
835
|
-
} else if (componentStack.length === 0) {
|
|
836
|
-
return null;
|
|
837
|
-
}
|
|
840
|
+
const source = getSourceFromDataLoc(element);
|
|
841
|
+
if (!source) return null;
|
|
842
|
+
if (settings.hideNodeModules && isNodeModulesPath(source.fileName)) {
|
|
843
|
+
return null;
|
|
838
844
|
}
|
|
839
845
|
return {
|
|
840
846
|
element,
|
|
841
847
|
source,
|
|
842
|
-
|
|
843
|
-
rect: element.getBoundingClientRect(),
|
|
844
|
-
stackIndex: 0
|
|
848
|
+
rect: element.getBoundingClientRect()
|
|
845
849
|
};
|
|
846
850
|
},
|
|
847
851
|
[settings.hideNodeModules]
|
|
848
852
|
);
|
|
849
|
-
const handleMouseMove =
|
|
853
|
+
const handleMouseMove = useCallback2(
|
|
850
854
|
(e) => {
|
|
851
855
|
if (!altKeyHeld && !inspectedElement) return;
|
|
852
856
|
const elementAtPoint = document.elementFromPoint(e.clientX, e.clientY);
|
|
@@ -872,58 +876,44 @@ function UILintProvider({
|
|
|
872
876
|
setLocatorTarget
|
|
873
877
|
]
|
|
874
878
|
);
|
|
875
|
-
const handleLocatorClick =
|
|
879
|
+
const handleLocatorClick = useCallback2(
|
|
876
880
|
(e) => {
|
|
877
|
-
if (!altKeyHeld && !inspectedElement || !
|
|
881
|
+
if (!altKeyHeld && !inspectedElement || !locatorTarget) return;
|
|
878
882
|
const targetEl = e.target;
|
|
879
883
|
if (targetEl?.closest?.("[data-ui-lint]")) return;
|
|
880
884
|
e.preventDefault();
|
|
881
885
|
e.stopPropagation();
|
|
882
|
-
let source = effectiveLocatorTarget.source;
|
|
883
|
-
if (locatorStackIndex > 0 && effectiveLocatorTarget.componentStack.length > 0) {
|
|
884
|
-
const stackItem = effectiveLocatorTarget.componentStack[locatorStackIndex - 1];
|
|
885
|
-
if (stackItem?.source) {
|
|
886
|
-
source = stackItem.source;
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
886
|
setInspectedElement({
|
|
890
|
-
element:
|
|
891
|
-
source,
|
|
892
|
-
|
|
893
|
-
rect: effectiveLocatorTarget.rect
|
|
887
|
+
element: locatorTarget.element,
|
|
888
|
+
source: locatorTarget.source,
|
|
889
|
+
rect: locatorTarget.rect
|
|
894
890
|
});
|
|
895
891
|
setLocatorTarget(null);
|
|
896
|
-
setLocatorStackIndex(0);
|
|
897
892
|
},
|
|
898
893
|
[
|
|
899
894
|
altKeyHeld,
|
|
900
|
-
|
|
895
|
+
locatorTarget,
|
|
901
896
|
inspectedElement,
|
|
902
|
-
locatorStackIndex,
|
|
903
897
|
setInspectedElement,
|
|
904
|
-
setLocatorTarget
|
|
905
|
-
setLocatorStackIndex
|
|
898
|
+
setLocatorTarget
|
|
906
899
|
]
|
|
907
900
|
);
|
|
908
|
-
|
|
901
|
+
useEffect2(() => {
|
|
909
902
|
if (!isBrowser() || !enabled) return;
|
|
910
903
|
const handleKeyDown = (e) => {
|
|
911
904
|
if (e.key === "Alt") {
|
|
912
905
|
setAltKeyHeld(true);
|
|
913
|
-
setLocatorStackIndex(0);
|
|
914
906
|
}
|
|
915
907
|
};
|
|
916
908
|
const handleKeyUp = (e) => {
|
|
917
909
|
if (e.key === "Alt") {
|
|
918
910
|
setAltKeyHeld(false);
|
|
919
911
|
setLocatorTarget(null);
|
|
920
|
-
setLocatorStackIndex(0);
|
|
921
912
|
}
|
|
922
913
|
};
|
|
923
914
|
const handleBlur = () => {
|
|
924
915
|
setAltKeyHeld(false);
|
|
925
916
|
setLocatorTarget(null);
|
|
926
|
-
setLocatorStackIndex(0);
|
|
927
917
|
};
|
|
928
918
|
window.addEventListener("keydown", handleKeyDown);
|
|
929
919
|
window.addEventListener("keyup", handleKeyUp);
|
|
@@ -933,8 +923,8 @@ function UILintProvider({
|
|
|
933
923
|
window.removeEventListener("keyup", handleKeyUp);
|
|
934
924
|
window.removeEventListener("blur", handleBlur);
|
|
935
925
|
};
|
|
936
|
-
}, [enabled, setAltKeyHeld, setLocatorTarget
|
|
937
|
-
|
|
926
|
+
}, [enabled, setAltKeyHeld, setLocatorTarget]);
|
|
927
|
+
useEffect2(() => {
|
|
938
928
|
if (!isBrowser() || !enabled) return;
|
|
939
929
|
if (!altKeyHeld && !inspectedElement) return;
|
|
940
930
|
window.addEventListener("mousemove", handleMouseMove);
|
|
@@ -950,21 +940,7 @@ function UILintProvider({
|
|
|
950
940
|
handleMouseMove,
|
|
951
941
|
handleLocatorClick
|
|
952
942
|
]);
|
|
953
|
-
|
|
954
|
-
if (!isBrowser() || !enabled || !altKeyHeld) return;
|
|
955
|
-
const handleWheel = (e) => {
|
|
956
|
-
if (!effectiveLocatorTarget) return;
|
|
957
|
-
e.preventDefault();
|
|
958
|
-
if (e.deltaY > 0) {
|
|
959
|
-
locatorGoUp();
|
|
960
|
-
} else {
|
|
961
|
-
locatorGoDown();
|
|
962
|
-
}
|
|
963
|
-
};
|
|
964
|
-
window.addEventListener("wheel", handleWheel, { passive: false });
|
|
965
|
-
return () => window.removeEventListener("wheel", handleWheel);
|
|
966
|
-
}, [enabled, altKeyHeld, effectiveLocatorTarget, locatorGoUp, locatorGoDown]);
|
|
967
|
-
useEffect(() => {
|
|
943
|
+
useEffect2(() => {
|
|
968
944
|
if (!isBrowser() || !enabled) return;
|
|
969
945
|
const handleKeyDown = (e) => {
|
|
970
946
|
if (e.key === "Escape" && inspectedElement) {
|
|
@@ -974,10 +950,10 @@ function UILintProvider({
|
|
|
974
950
|
window.addEventListener("keydown", handleKeyDown);
|
|
975
951
|
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
976
952
|
}, [enabled, inspectedElement, setInspectedElement]);
|
|
977
|
-
|
|
953
|
+
useEffect2(() => {
|
|
978
954
|
setIsMounted(true);
|
|
979
955
|
}, []);
|
|
980
|
-
|
|
956
|
+
useEffect2(() => {
|
|
981
957
|
if (!isBrowser() || !enabled) return;
|
|
982
958
|
if (!isMounted) return;
|
|
983
959
|
connectWebSocket();
|
|
@@ -985,7 +961,7 @@ function UILintProvider({
|
|
|
985
961
|
disconnectWebSocket();
|
|
986
962
|
};
|
|
987
963
|
}, [enabled, isMounted, connectWebSocket, disconnectWebSocket]);
|
|
988
|
-
const wrappedStartAutoScan =
|
|
964
|
+
const wrappedStartAutoScan = useCallback2(() => {
|
|
989
965
|
startAutoScan(settings.hideNodeModules);
|
|
990
966
|
}, [startAutoScan, settings.hideNodeModules]);
|
|
991
967
|
const contextValue = useMemo(
|
|
@@ -993,9 +969,7 @@ function UILintProvider({
|
|
|
993
969
|
settings,
|
|
994
970
|
updateSettings,
|
|
995
971
|
altKeyHeld,
|
|
996
|
-
locatorTarget
|
|
997
|
-
locatorGoUp,
|
|
998
|
-
locatorGoDown,
|
|
972
|
+
locatorTarget,
|
|
999
973
|
inspectedElement,
|
|
1000
974
|
setInspectedElement,
|
|
1001
975
|
autoScanState,
|
|
@@ -1009,9 +983,7 @@ function UILintProvider({
|
|
|
1009
983
|
settings,
|
|
1010
984
|
updateSettings,
|
|
1011
985
|
altKeyHeld,
|
|
1012
|
-
|
|
1013
|
-
locatorGoUp,
|
|
1014
|
-
locatorGoDown,
|
|
986
|
+
locatorTarget,
|
|
1015
987
|
inspectedElement,
|
|
1016
988
|
setInspectedElement,
|
|
1017
989
|
autoScanState,
|
|
@@ -1031,12 +1003,12 @@ function UILintProvider({
|
|
|
1031
1003
|
function UILintUI() {
|
|
1032
1004
|
const { altKeyHeld, inspectedElement, autoScanState } = useUILintContext();
|
|
1033
1005
|
const [components, setComponents] = useState(null);
|
|
1034
|
-
|
|
1006
|
+
useEffect2(() => {
|
|
1035
1007
|
Promise.all([
|
|
1036
|
-
import("./UILintToolbar-
|
|
1037
|
-
import("./InspectionPanel-
|
|
1038
|
-
import("./LocatorOverlay-
|
|
1039
|
-
import("./ElementBadges-
|
|
1008
|
+
import("./UILintToolbar-OQY2V7Q7.js"),
|
|
1009
|
+
import("./InspectionPanel-7N56XBWA.js"),
|
|
1010
|
+
import("./LocatorOverlay-RDDLASGB.js"),
|
|
1011
|
+
import("./ElementBadges-J2ELN2PU.js")
|
|
1040
1012
|
]).then(([toolbar, panel, locator, badges]) => {
|
|
1041
1013
|
setComponents({
|
|
1042
1014
|
Toolbar: toolbar.UILintToolbar,
|
|
@@ -1062,10 +1034,7 @@ function UILintUI() {
|
|
|
1062
1034
|
}
|
|
1063
1035
|
|
|
1064
1036
|
export {
|
|
1065
|
-
|
|
1066
|
-
getDebugSource,
|
|
1067
|
-
getDebugOwner,
|
|
1068
|
-
getComponentStack,
|
|
1037
|
+
getSourceFromDataLoc,
|
|
1069
1038
|
isNodeModulesPath,
|
|
1070
1039
|
getDisplayName,
|
|
1071
1040
|
scanDOMForSources,
|