MCPcopy Create free account
hub / github.com/EsperoTech/yaade / hover

Function hover

client/src/components/collectionView/MoveableScript.tsx:76–126  ·  view source on GitHub ↗
(item, monitor)

Source from the content-addressed store, hash-verified

74 >({
75 accept: DragTypes.SCRIPT,
76 hover(item, monitor) {
77 if (!ref.current || !monitor.isOver()) {
78 return;
79 }
80
81 if (!ref.current || !monitor || !item || item.id === id) {
82 return {
83 handlerId: null,
84 hoveredDownwards: false,
85 hoveredUpwards: false,
86 };
87 }
88
89 const hoverBoundingRect = ref.current.getBoundingClientRect();
90 const clientOffset = monitor.getClientOffset();
91 if (!clientOffset) {
92 return;
93 }
94
95 const hoverClientY = clientOffset.y - hoverBoundingRect.top;
96
97 const hoveredTop = hoverClientY < hoverBoundingRect.height / 2;
98 const hoveredBottom = hoverClientY > hoverBoundingRect.height / 2;
99
100 if (hoveredTop) {
101 const newRank = calculateTopHoveredRank(
102 index,
103 item.index,
104 script.collectionId,
105 item.collectionId,
106 );
107 if (newRank === item.index && item.collectionId === script.collectionId) {
108 return;
109 }
110 }
111
112 if (hoveredBottom) {
113 const newRank = calculateBottomHoveredRank(
114 index,
115 item.index,
116 script.collectionId,
117 item.collectionId,
118 );
119 if (newRank === item.index && item.collectionId === script.collectionId) {
120 return;
121 }
122 }
123
124 setIsTopHovered(hoveredTop);
125 setIsBottomHovered(hoveredBottom);
126 },
127 collect(monitor) {
128 if (!ref.current || !monitor || !monitor.getItem() || monitor.getItem().id === id) {
129 setIsTopHovered(false);

Callers

nothing calls this directly

Calls 2

calculateTopHoveredRankFunction · 0.70

Tested by

no test coverage detected