( options: DroppableItemOptions, state: DroppableCollectionState, ref: RefObject<HTMLElement | null> )
| 40 | * Handles drop interactions for an item within a collection component. |
| 41 | */ |
| 42 | export function useDroppableItem( |
| 43 | options: DroppableItemOptions, |
| 44 | state: DroppableCollectionState, |
| 45 | ref: RefObject<HTMLElement | null> |
| 46 | ): DroppableItemResult { |
| 47 | let {dropProps} = useVirtualDrop(); |
| 48 | let droppableCollectionRef = getDroppableCollectionRef(state); |
| 49 | useEffect(() => { |
| 50 | if (ref.current) { |
| 51 | return DragManager.registerDropItem({ |
| 52 | element: ref.current, |
| 53 | target: options.target, |
| 54 | getDropOperation(types, allowedOperations) { |
| 55 | let {draggingKeys} = globalDndState; |
| 56 | let isInternal = isInternalDropOperation(droppableCollectionRef); |
| 57 | return state.getDropOperation({ |
| 58 | target: options.target, |
| 59 | types, |
| 60 | allowedOperations, |
| 61 | isInternal, |
| 62 | draggingKeys |
| 63 | }); |
| 64 | }, |
| 65 | activateButtonRef: options.activateButtonRef |
| 66 | }); |
| 67 | } |
| 68 | }, [ref, options.target, state, droppableCollectionRef, options.activateButtonRef]); |
| 69 | |
| 70 | let dragSession = DragManager.useDragSession(); |
| 71 | let {draggingKeys} = globalDndState; |
| 72 | let isInternal = isInternalDropOperation(droppableCollectionRef); |
| 73 | let isValidDropTarget = |
| 74 | dragSession && |
| 75 | state.getDropOperation({ |
| 76 | target: options.target, |
| 77 | types: getTypes(dragSession.dragTarget.items), |
| 78 | allowedOperations: dragSession.dragTarget.allowedDropOperations, |
| 79 | isInternal, |
| 80 | draggingKeys |
| 81 | }) !== 'cancel'; |
| 82 | |
| 83 | let isDropTarget = state.isDropTarget(options.target); |
| 84 | useEffect(() => { |
| 85 | if (dragSession && isDropTarget && ref.current) { |
| 86 | ref.current.focus(); |
| 87 | } |
| 88 | }, [isDropTarget, dragSession, ref]); |
| 89 | |
| 90 | return { |
| 91 | dropProps: { |
| 92 | ...dropProps, |
| 93 | 'aria-hidden': !dragSession || isValidDropTarget ? undefined : 'true' |
| 94 | }, |
| 95 | isDropTarget |
| 96 | }; |
| 97 | } |
no test coverage detected