MCPcopy Create free account
hub / github.com/adobe/react-spectrum / onDragOver

Function onDragOver

packages/react-aria/src/dnd/useDrop.ts:149–233  ·  view source on GitHub ↗
(e: DragEvent)

Source from the content-addressed store, hash-verified

147 };
148
149 let onDragOver = (e: DragEvent) => {
150 e.preventDefault();
151 e.stopPropagation();
152
153 let allowedOperations = getAllowedOperations(e);
154 if (
155 e.clientX === state.x &&
156 e.clientY === state.y &&
157 allowedOperations === state.allowedOperations
158 ) {
159 e.dataTransfer.dropEffect = state.dropEffect;
160 return;
161 }
162
163 state.x = e.clientX;
164 state.y = e.clientY;
165
166 let prevDropEffect = state.dropEffect;
167
168 // Update drop effect if allowed drop operations changed (e.g. user pressed modifier key).
169 if (allowedOperations !== state.allowedOperations) {
170 let allowedOps = allowedOperationsToArray(allowedOperations);
171 let dropOperation = allowedOps[0];
172 if (typeof options.getDropOperation === 'function') {
173 let types = new DragTypes(e.dataTransfer);
174 dropOperation = getDropOperation(
175 allowedOperations,
176 options.getDropOperation(types, allowedOps)
177 );
178 }
179 state.dropEffect = DROP_OPERATION_TO_DROP_EFFECT[dropOperation] || 'none';
180 }
181
182 if (typeof options.getDropOperationForPoint === 'function') {
183 let types = new DragTypes(e.dataTransfer);
184 let rect = (e.currentTarget as HTMLElement).getBoundingClientRect();
185 let dropOperation = getDropOperation(
186 allowedOperations,
187 options.getDropOperationForPoint(
188 types,
189 allowedOperationsToArray(allowedOperations),
190 state.x - rect.x,
191 state.y - rect.y
192 )
193 );
194 state.dropEffect = DROP_OPERATION_TO_DROP_EFFECT[dropOperation] || 'none';
195 }
196
197 state.allowedOperations = allowedOperations;
198 e.dataTransfer.dropEffect = state.dropEffect;
199
200 // If the drop operation changes, update state and fire events appropriately.
201 if (state.dropEffect === 'none' && prevDropEffect !== 'none') {
202 fireDropExit(e);
203 } else if (state.dropEffect !== 'none' && prevDropEffect === 'none') {
204 fireDropEnter(e);
205 }
206

Callers

nothing calls this directly

Calls 6

getAllowedOperationsFunction · 0.85
allowedOperationsToArrayFunction · 0.85
fireDropExitFunction · 0.85
fireDropEnterFunction · 0.85
getDropOperationMethod · 0.80
getDropOperationFunction · 0.70

Tested by

no test coverage detected