uilint-react 0.1.37 → 0.1.39

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.
@@ -1,8 +1,9 @@
1
1
  "use client";
2
2
  "use client";
3
3
  import {
4
- useUILintContext
5
- } from "./chunk-DEHJKJNT.js";
4
+ useUILintContext,
5
+ useUILintStore
6
+ } from "./chunk-ILK73X6L.js";
6
7
 
7
8
  // src/components/ui-lint/ElementBadges.tsx
8
9
  import React, { useState, useEffect, useCallback, useMemo } from "react";
@@ -153,8 +154,7 @@ function getScaleFromDistance(distance) {
153
154
  }
154
155
  function getBadgeColor(issueCount) {
155
156
  if (issueCount === 0) return STYLES.success;
156
- if (issueCount <= 2) return STYLES.warning;
157
- return STYLES.error;
157
+ return STYLES.warning;
158
158
  }
159
159
  function formatElementLabel(element) {
160
160
  const tag = element.tagName.toLowerCase();
@@ -163,8 +163,7 @@ function formatElementLabel(element) {
163
163
  const fileName = source.fileName.split("/").pop() || "Unknown";
164
164
  return `${tag} > ${fileName}`;
165
165
  }
166
- const componentName = element.componentStack[0]?.name;
167
- return componentName ? `${tag} > ${componentName}` : tag;
166
+ return tag;
168
167
  }
169
168
  var NEARBY_THRESHOLD = 30;
170
169
  var WINDOW_EDGE_THRESHOLD = 20;
@@ -204,6 +203,10 @@ function ElementBadges() {
204
203
  const [cursorPos, setCursorPos] = useState({ x: 0, y: 0 });
205
204
  const [badgePositions, setBadgePositions] = useState([]);
206
205
  const [isAltKeyPressed, setIsAltKeyPressed] = useState(false);
206
+ const hoveredFilePath = useUILintStore((s) => s.hoveredFilePath);
207
+ const selectedFilePath = useUILintStore(
208
+ (s) => s.selectedFilePath
209
+ );
207
210
  useEffect(() => {
208
211
  setMounted(true);
209
212
  }, []);
@@ -257,21 +260,39 @@ function ElementBadges() {
257
260
  }
258
261
  setBadgePositions(positions);
259
262
  };
260
- updatePositions();
261
- let rafId;
262
- const loop = () => {
263
- updatePositions();
264
- rafId = requestAnimationFrame(loop);
263
+ let rafId = null;
264
+ const scheduleUpdate = () => {
265
+ if (rafId !== null) return;
266
+ rafId = requestAnimationFrame(() => {
267
+ rafId = null;
268
+ updatePositions();
269
+ });
270
+ };
271
+ scheduleUpdate();
272
+ const handleScroll = () => scheduleUpdate();
273
+ const handleResize = () => scheduleUpdate();
274
+ const handleVisibility = () => {
275
+ if (document.visibilityState === "visible") {
276
+ scheduleUpdate();
277
+ }
278
+ };
279
+ window.addEventListener("scroll", handleScroll, true);
280
+ window.addEventListener("resize", handleResize);
281
+ document.addEventListener("visibilitychange", handleVisibility);
282
+ return () => {
283
+ if (rafId !== null) {
284
+ cancelAnimationFrame(rafId);
285
+ }
286
+ window.removeEventListener("scroll", handleScroll, true);
287
+ window.removeEventListener("resize", handleResize);
288
+ document.removeEventListener("visibilitychange", handleVisibility);
265
289
  };
266
- rafId = requestAnimationFrame(loop);
267
- return () => cancelAnimationFrame(rafId);
268
- }, [autoScanState, elementIssuesCache]);
290
+ }, [autoScanState.status, autoScanState.elements, elementIssuesCache]);
269
291
  const handleSelect = useCallback(
270
292
  (element, issue) => {
271
293
  const inspected = {
272
294
  element: element.element,
273
295
  source: element.source,
274
- componentStack: element.componentStack,
275
296
  rect: element.element.getBoundingClientRect(),
276
297
  scannedElementId: element.id
277
298
  };
@@ -284,15 +305,25 @@ function ElementBadges() {
284
305
  [badgePositions]
285
306
  );
286
307
  const visibleBadges = useMemo(() => {
287
- return nudgedPositions.filter(
308
+ let filtered = nudgedPositions.filter(
288
309
  (pos) => shouldShowBadge(pos.issue, isAltKeyPressed)
289
310
  );
290
- }, [nudgedPositions, isAltKeyPressed]);
311
+ const activeFilePath = selectedFilePath || hoveredFilePath;
312
+ if (activeFilePath) {
313
+ filtered = filtered.filter(
314
+ (pos) => pos.element.source.fileName === activeFilePath
315
+ );
316
+ }
317
+ return filtered;
318
+ }, [nudgedPositions, isAltKeyPressed, selectedFilePath, hoveredFilePath]);
291
319
  if (!mounted) return null;
292
320
  if (autoScanState.status === "idle") return null;
293
321
  const content = /* @__PURE__ */ jsxs("div", { "data-ui-lint": true, children: [
294
322
  /* @__PURE__ */ jsx(BadgeAnimationStyles, {}),
295
- visibleBadges.map((nudgedPos) => {
323
+ visibleBadges.filter((pos, idx, arr) => {
324
+ const id = pos.element.id;
325
+ return arr.findIndex((p) => p.element.id === id) === idx;
326
+ }).map((nudgedPos) => {
296
327
  const distance = Math.hypot(
297
328
  nudgedPos.nudgedX - cursorPos.x,
298
329
  nudgedPos.nudgedY - cursorPos.y
@@ -2,8 +2,8 @@
2
2
  "use client";
3
3
  import {
4
4
  InspectionPanel
5
- } from "./chunk-ITKEGCAZ.js";
6
- import "./chunk-DEHJKJNT.js";
5
+ } from "./chunk-NCNRCF5A.js";
6
+ import "./chunk-ILK73X6L.js";
7
7
  export {
8
8
  InspectionPanel
9
9
  };
@@ -3,8 +3,8 @@
3
3
  import {
4
4
  InspectedElementHighlight,
5
5
  LocatorOverlay
6
- } from "./chunk-LZX53CPI.js";
7
- import "./chunk-DEHJKJNT.js";
6
+ } from "./chunk-7434TUMX.js";
7
+ import "./chunk-ILK73X6L.js";
8
8
  export {
9
9
  InspectedElementHighlight,
10
10
  LocatorOverlay
@@ -2,8 +2,8 @@
2
2
  "use client";
3
3
  import {
4
4
  UILintToolbar
5
- } from "./chunk-EYWLUDXI.js";
6
- import "./chunk-DEHJKJNT.js";
5
+ } from "./chunk-4TLFW7LD.js";
6
+ import "./chunk-ILK73X6L.js";
7
7
  export {
8
8
  UILintToolbar
9
9
  };