MCPcopy Create free account
hub / github.com/composify-js/composify / Droppable

Function Droppable

packages/react/src/editor/Droppable/Droppable.tsx:16–59  ·  view source on GitHub ↗
({ item, index, fullScreen, onDrop, ...props })

Source from the content-addressed store, hash-verified

14}>;
15
16export const Droppable: FC<Props> = ({ item, index, fullScreen, onDrop, ...props }) => {
17 const { isDragging, focusedBlock, relocateFocusedBlock, insertBlock } = useEditing();
18
19 const [{ isOver }, dropRef] = useDrop<Node, unknown, { isOver: boolean }>({
20 accept: [TargetType.Canvas, TargetType.Library],
21 hover: throttle((target: Node) => {
22 if (target.id === item.id || !target.id || !item.id) {
23 return;
24 }
25
26 relocateFocusedBlock({ id: item.id, index });
27 }, 300),
28 drop: (target, monitor) => {
29 if (monitor.getItemType() !== TargetType.Library || !item.id) {
30 return;
31 }
32
33 if (onDrop) {
34 onDrop(target);
35 return;
36 }
37
38 insertBlock(target, { id: item.id, index });
39 },
40 collect: (monitor) => ({
41 isOver: monitor.isOver() && monitor.getItemType() === TargetType.Library,
42 }),
43 });
44
45 return (
46 <span
47 data-composify-role="droppable"
48 data-fullscreen={!!fullScreen}
49 data-over={isOver}
50 data-active={isDragging}
51 data-dragging={focusedBlock?.id === item.id}
52 className={styles.droppable}
53 ref={(node) => {
54 dropRef(node);
55 }}
56 {...props}
57 />
58 );
59};

Callers

nothing calls this directly

Calls 1

useEditingFunction · 0.90

Tested by

no test coverage detected