|
1 | | -import { |
2 | | - CURSOR_FLAG_HORIZONTAL_MAX, |
3 | | - CURSOR_FLAG_HORIZONTAL_MIN, |
4 | | - CURSOR_FLAG_VERTICAL_MAX, |
5 | | - CURSOR_FLAG_VERTICAL_MIN |
6 | | -} from "../../constants"; |
7 | | -import { updateCursorStyle } from "../cursor/updateCursorStyle"; |
8 | 1 | import { read, update } from "../mutableState"; |
9 | | -import { adjustLayoutByDelta } from "../utils/adjustLayoutByDelta"; |
10 | | -import { findMatchingHitRegions } from "../utils/findMatchingHitRegions"; |
11 | | -import { layoutsEqual } from "../utils/layoutsEqual"; |
| 2 | +import { updateActiveHitRegions } from "../utils/updateActiveHitRegion"; |
12 | 3 |
|
13 | 4 | export function onWindowPointerMove(event: PointerEvent) { |
14 | 5 | if (event.defaultPrevented) { |
@@ -40,117 +31,13 @@ export function onWindowPointerMove(event: PointerEvent) { |
40 | 31 | return; |
41 | 32 | } |
42 | 33 |
|
43 | | - let cursorFlags = 0; |
44 | | - const nextMountedGroups = new Map(mountedGroups); |
45 | | - |
46 | | - // Note that HitRegions are frozen once a drag has started |
47 | | - // Modify the Group layouts for all matching HitRegions though |
48 | | - interactionState.hitRegions.forEach((current) => { |
49 | | - const { disableCursor, element, orientation, panels } = current.group; |
50 | | - |
51 | | - let deltaAsPercentage = 0; |
52 | | - if (interactionState.state === "active") { |
53 | | - if (orientation === "horizontal") { |
54 | | - deltaAsPercentage = |
55 | | - ((event.clientX - interactionState.pointerDownAtPoint.x) / |
56 | | - element.offsetWidth) * |
57 | | - 100; |
58 | | - } else { |
59 | | - deltaAsPercentage = |
60 | | - ((event.clientY - interactionState.pointerDownAtPoint.y) / |
61 | | - element.offsetHeight) * |
62 | | - 100; |
63 | | - } |
64 | | - } |
65 | | - |
66 | | - const initialLayout = interactionState.initialLayoutMap.get( |
67 | | - current.group |
68 | | - ); |
69 | | - const { |
70 | | - derivedPanelConstraints, |
71 | | - layout: prevLayout, |
72 | | - separatorToPanels |
73 | | - } = mountedGroups.get(current.group) ?? {}; |
74 | | - if ( |
75 | | - derivedPanelConstraints && |
76 | | - initialLayout && |
77 | | - prevLayout && |
78 | | - separatorToPanels |
79 | | - ) { |
80 | | - const nextLayout = adjustLayoutByDelta({ |
81 | | - delta: deltaAsPercentage, |
82 | | - initialLayout, |
83 | | - panelConstraints: derivedPanelConstraints, |
84 | | - pivotIndices: current.panels.map((panel) => panels.indexOf(panel)), |
85 | | - prevLayout, |
86 | | - trigger: "mouse-or-touch" |
87 | | - }); |
88 | | - |
89 | | - if (layoutsEqual(nextLayout, prevLayout)) { |
90 | | - if (deltaAsPercentage !== 0 && !disableCursor) { |
91 | | - // An unchanged means the cursor has exceeded the allowed bounds |
92 | | - switch (orientation) { |
93 | | - case "horizontal": { |
94 | | - cursorFlags |= |
95 | | - deltaAsPercentage < 0 |
96 | | - ? CURSOR_FLAG_HORIZONTAL_MIN |
97 | | - : CURSOR_FLAG_HORIZONTAL_MAX; |
98 | | - break; |
99 | | - } |
100 | | - case "vertical": { |
101 | | - cursorFlags |= |
102 | | - deltaAsPercentage < 0 |
103 | | - ? CURSOR_FLAG_VERTICAL_MIN |
104 | | - : CURSOR_FLAG_VERTICAL_MAX; |
105 | | - break; |
106 | | - } |
107 | | - } |
108 | | - } |
109 | | - } else { |
110 | | - nextMountedGroups.set(current.group, { |
111 | | - derivedPanelConstraints: derivedPanelConstraints, |
112 | | - layout: nextLayout, |
113 | | - separatorToPanels |
114 | | - }); |
115 | | - |
116 | | - // Save the most recent layout for this group of panels in-memory |
117 | | - // so that layouts will be remembered between different sets of conditionally rendered panels |
118 | | - const panelIdsKey = current.group.panels |
119 | | - .map(({ id }) => id) |
120 | | - .join(","); |
121 | | - current.group.inMemoryLayouts[panelIdsKey] = nextLayout; |
122 | | - } |
123 | | - } |
| 34 | + updateActiveHitRegions({ |
| 35 | + event, |
| 36 | + hitRegions: interactionState.hitRegions, |
| 37 | + initialLayoutMap: interactionState.initialLayoutMap, |
| 38 | + mountedGroups, |
| 39 | + pointerDownAtPoint: interactionState.pointerDownAtPoint |
124 | 40 | }); |
125 | | - |
126 | | - update({ |
127 | | - cursorFlags, |
128 | | - mountedGroups: nextMountedGroups |
129 | | - }); |
130 | | - |
131 | | - updateCursorStyle(); |
132 | | - break; |
133 | | - } |
134 | | - default: { |
135 | | - // Update HitRegions if a drag has not been started |
136 | | - const hitRegions = findMatchingHitRegions(event, mountedGroups); |
137 | | - |
138 | | - if (hitRegions.length === 0) { |
139 | | - if (interactionState.state !== "inactive") { |
140 | | - update({ |
141 | | - interactionState: { state: "inactive" } |
142 | | - }); |
143 | | - } |
144 | | - } else { |
145 | | - update({ |
146 | | - interactionState: { |
147 | | - hitRegions, |
148 | | - state: "hover" |
149 | | - } |
150 | | - }); |
151 | | - } |
152 | | - |
153 | | - updateCursorStyle(); |
154 | 41 | break; |
155 | 42 | } |
156 | 43 | } |
|
0 commit comments