"use client"; import styles from "@prototype/lib/prototype-comments/ui/capture-styles.module.scss"; import { PrototypeTargetHighlightLayer, toHighlightPortalStyle, useHighlightPortalContainer, } from "@prototype/components/prototypes/prototype-target-highlight-layer"; type HighlightRect = { left: number; top: number; width: number; height: number; }; type HoverInfo = { element: string; rect: DOMRect | null; }; type MultiSelectItem = { element: HTMLElement; }; type PendingAnnotation = { targetElement?: HTMLElement | null; multiSelectElements?: HTMLElement[]; boundingBox?: { x: number; y: number; width: number; height: number }; isMultiSelect?: boolean; }; type CommentCaptureTargetHighlightsProps = { hoverInfo: HoverInfo | null; pendingAnnotation: PendingAnnotation | null; pendingExiting: boolean; pendingMultiSelectElements: MultiSelectItem[]; scrollY: number; }; function toPortalRect( rect: HighlightRect, portal: HTMLElement | null, ): HighlightRect { return toHighlightPortalStyle(rect, portal); } export function CommentCaptureTargetHighlights({ hoverInfo, pendingAnnotation, pendingExiting, pendingMultiSelectElements, scrollY, }: CommentCaptureTargetHighlightsProps) { const highlightPortal = useHighlightPortalContainer(); return ( {hoverInfo?.rect && !pendingAnnotation ? (
) : null} {pendingMultiSelectElements.map((item, index) => { const rect = toPortalRect( item.element.getBoundingClientRect(), highlightPortal, ); return (
); })} {pendingAnnotation ? pendingAnnotation.multiSelectElements?.length ? pendingAnnotation.multiSelectElements .filter((el) => document.contains(el)) .map((el, index) => { const rect = toPortalRect( el.getBoundingClientRect(), highlightPortal, ); return (
); }) : pendingAnnotation.targetElement && document.contains(pendingAnnotation.targetElement) ? (() => { const rect = toPortalRect( pendingAnnotation.targetElement!.getBoundingClientRect(), highlightPortal, ); return (
); })() : pendingAnnotation.boundingBox ? (() => { const rect = toPortalRect( { left: pendingAnnotation.boundingBox!.x, top: pendingAnnotation.boundingBox!.y - scrollY, width: pendingAnnotation.boundingBox!.width, height: pendingAnnotation.boundingBox!.height, }, highlightPortal, ); return (
); })() : null : null} ); }