import { Layer, Line } from "react-konva"; import type { Guide } from "./useSnap"; type GuidesLayerProps = { guides: Guide[]; stageWidth: number; stageHeight: number; activeGuideIds: string[]; selectedGuideId: string | null; draftGuide: { orientation: Guide["orientation"]; position: number } | null; onGuideSelect: (id: string) => void; onGuideDragEnd: (id: string, position: number, shouldRemove: boolean) => void; }; const GuidesLayer = ({ guides, stageWidth, stageHeight, activeGuideIds, selectedGuideId, draftGuide, onGuideSelect, onGuideDragEnd, }: GuidesLayerProps) => { return ( {guides.map((guide) => { const isVertical = guide.orientation === "vertical"; const isActive = activeGuideIds.includes(guide.id); const isSelected = selectedGuideId === guide.id; return ( isVertical ? { x: pos.x, y: 0 } : { x: 0, y: pos.y } } onMouseDown={() => onGuideSelect(guide.id)} onDragEnd={(e) => { const node = e.target; const nextPosition = isVertical ? node.x() : node.y(); const shouldRemove = isVertical ? nextPosition < 0 || nextPosition > stageWidth : nextPosition < 0 || nextPosition > stageHeight; onGuideDragEnd(guide.id, nextPosition, shouldRemove); }} /> ); })} {draftGuide && ( )} ); }; export default GuidesLayer;