import React, { ComponentType, useEffect } from "react"; import { useDragSelectContext } from "./DragSelectProvider"; interface SelectableProps { id: string; index: number; isSelected?: boolean; onMouseDown?: (e: React.MouseEvent) => void; onMouseEnter?: () => void; } export function createSelectable(Component: ComponentType) { return function SelectableComponent(props: T & { id: string; index: number }) { const { registerItem, unregisterItem, startDrag, updateSelection, isSelected } = useDragSelectContext(); const { id, index } = props; useEffect(() => { registerItem(id, index); return () => unregisterItem(id); }, [id, index, registerItem, unregisterItem]); const handleMouseDown = (e: React.MouseEvent) => { const mode = e.ctrlKey || e.metaKey ? "replace" : "toggle"; startDrag(id, mode); }; const handleMouseEnter = () => { updateSelection(id); }; return ( ); }; }