import type { Data } from '@dnd-kit/abstract'; import type { Draggable, Droppable, DragDropManager } from '@dnd-kit/dom'; import { subSlot } from '../../internal'; import { useComputed } from '../../hooks/useComputed'; import { useDragDropManager } from './useDragDropManager'; export function useDragOperation< T extends Data = Data, U extends Draggable = Draggable, V extends Droppable = Droppable, W extends DragDropManager = DragDropManager, >(slot?: symbol): { readonly source: U | null | undefined; readonly target: V | null | undefined } { const manager = useDragDropManager(); const source = useComputed( () => manager?.dragOperation.source, [manager], false, subSlot(slot, 'source'), ); const target = useComputed( () => manager?.dragOperation.target, [manager], false, subSlot(slot, 'target'), ); return { get source() { return source.value as U | null | undefined; }, get target() { return target.value as V | null | undefined; }, }; }