|
| 1 | +import { updateCursorStyle } from "../cursor/updateCursorStyle"; |
| 2 | +import { read, update } from "../mutableState"; |
| 3 | +import { findMatchingHitRegions } from "../utils/findMatchingHitRegions"; |
| 4 | +import { updateActiveHitRegions } from "../utils/updateActiveHitRegion"; |
| 5 | + |
| 6 | +export function onWindowPointerMove(event: PointerEvent) { |
| 7 | + if (event.defaultPrevented) { |
| 8 | + return; |
| 9 | + } |
| 10 | + |
| 11 | + const { interactionState, mountedGroups } = read(); |
| 12 | + |
| 13 | + switch (interactionState.state) { |
| 14 | + case "active": { |
| 15 | + // Edge case (see #340) |
| 16 | + // Detect when the pointer has been released outside an iframe on a different domain |
| 17 | + if ( |
| 18 | + // Skip this check for "pointerleave" events, else Firefox triggers a false positive (see #514) |
| 19 | + event.type !== "pointerleave" && |
| 20 | + event.buttons === 0 |
| 21 | + ) { |
| 22 | + update((prevState) => |
| 23 | + prevState.interactionState.state === "inactive" |
| 24 | + ? prevState |
| 25 | + : { |
| 26 | + cursorFlags: 0, |
| 27 | + interactionState: { |
| 28 | + state: "inactive" |
| 29 | + } |
| 30 | + } |
| 31 | + ); |
| 32 | + |
| 33 | + return; |
| 34 | + } |
| 35 | + |
| 36 | + updateActiveHitRegions({ |
| 37 | + event, |
| 38 | + hitRegions: interactionState.hitRegions, |
| 39 | + initialLayoutMap: interactionState.initialLayoutMap, |
| 40 | + mountedGroups, |
| 41 | + pointerDownAtPoint: interactionState.pointerDownAtPoint |
| 42 | + }); |
| 43 | + break; |
| 44 | + } |
| 45 | + default: { |
| 46 | + // Update HitRegions if a drag has not been started |
| 47 | + const hitRegions = findMatchingHitRegions(event, mountedGroups); |
| 48 | + |
| 49 | + if (hitRegions.length === 0) { |
| 50 | + if (interactionState.state !== "inactive") { |
| 51 | + update({ |
| 52 | + interactionState: { state: "inactive" } |
| 53 | + }); |
| 54 | + } |
| 55 | + } else { |
| 56 | + update({ |
| 57 | + interactionState: { |
| 58 | + hitRegions, |
| 59 | + state: "hover" |
| 60 | + } |
| 61 | + }); |
| 62 | + } |
| 63 | + |
| 64 | + updateCursorStyle(); |
| 65 | + break; |
| 66 | + } |
| 67 | + } |
| 68 | +} |
0 commit comments