MCPcopy Create free account
hub / github.com/donghaxkim/react-rewrite / selectElement

Function selectElement

packages/overlay/src/selection.ts:640–718  ·  view source on GitHub ↗
(el: HTMLElement, options?: { skipSidebar?: boolean })

Source from the content-addressed store, hash-verified

638}
639
640export async function selectElement(el: HTMLElement, options?: { skipSidebar?: boolean }): Promise<void> {
641 try {
642 const displayRect = el.getBoundingClientRect();
643
644 // Show selection overlay with loading dots immediately, before async resolve
645 selectedElement = el;
646 showSelectionOverlay(displayRect, null);
647 hideHoverOverlay();
648
649 const resolved = (await resolveComponentFromElement(el)) ?? buildFallbackSelection(el);
650
651 // Layer 2: grep-based discovery when filePath is empty
652 if (!resolved.filePath && resolved.componentName) {
653 const cached = getCachedFilePath(resolved.componentName);
654 if (cached === undefined) {
655 // Not looked up yet — ask CLI
656 const discovered = await requestFileDiscovery(resolved.componentName);
657 setCachedFilePath(resolved.componentName, discovered);
658 if (discovered) {
659 resolved.filePath = discovered;
660 if (resolved.stack) {
661 for (const frame of resolved.stack) {
662 if (frame.componentName === resolved.componentName && !frame.filePath) {
663 frame.filePath = discovered;
664 }
665 }
666 }
667 }
668 } else if (cached) {
669 resolved.filePath = cached;
670 if (resolved.stack) {
671 for (const frame of resolved.stack) {
672 if (frame.componentName === resolved.componentName && !frame.filePath) {
673 frame.filePath = cached;
674 }
675 }
676 }
677 }
678 }
679
680 console.log("[ReactRewrite] selectElement:", el.tagName, "→", resolved.componentName, resolved.filePath, "stack:", resolved.stack?.map(s => s.componentName));
681
682 currentSelection = {
683 tagName: resolved.tagName,
684 componentName: resolved.componentName,
685 filePath: resolved.filePath,
686 lineNumber: resolved.lineNumber,
687 columnNumber: resolved.columnNumber,
688 stack: resolved.stack,
689 boundingRect: {
690 top: displayRect.top,
691 left: displayRect.left,
692 width: displayRect.width,
693 height: displayRect.height,
694 },
695 jsxPath: resolved.jsxPath,
696 };
697

Callers 5

focusEntryTargetFunction · 0.85
handleMouseUpFunction · 0.85
handleKeyDownFunction · 0.85
selectElementForMoveFunction · 0.85
commitAndExitFunction · 0.85

Calls 9

showSelectionOverlayFunction · 0.85
hideHoverOverlayFunction · 0.85
buildFallbackSelectionFunction · 0.85
getCachedFilePathFunction · 0.85
requestFileDiscoveryFunction · 0.85
setCachedFilePathFunction · 0.85
inspectFunction · 0.85
updateComponentDetailFunction · 0.85

Tested by

no test coverage detected