first commit
Some checks failed
Build / run (push) Has been cancelled

This commit is contained in:
maher
2025-10-29 11:42:25 +01:00
commit 703f50a09d
4595 changed files with 385164 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
import {RefObject, useLayoutEffect, useRef} from 'react';
import {droppables} from '../drag-state';
import {InteractableRect} from '../../interactable-event';
import {DraggableId} from '../use-draggable';
export interface ConnectedMouseSelectable {
id: DraggableId;
onSelected?: () => void;
onDeselected?: () => void;
ref: RefObject<HTMLElement>;
rect?: InteractableRect;
}
export const mouseSelectables = new Map<
DraggableId,
ConnectedMouseSelectable
>();
export function useMouseSelectable(options: ConnectedMouseSelectable) {
const {id, ref} = options;
const optionsRef = useRef(options);
optionsRef.current = options;
useLayoutEffect(() => {
if (!ref.current) return;
// register droppable regardless if it's enabled or not, it might be used by mouse selection box
mouseSelectables.set(id, {
...mouseSelectables.get(id),
id,
ref,
// avoid stale closures
onSelected: () => {
optionsRef.current.onSelected?.();
},
onDeselected: () => optionsRef.current.onDeselected?.(),
});
return () => {
droppables.delete(id);
};
}, [id, optionsRef, ref]);
}