UNPKG

81.1 kBJavaScriptView Raw
1import {mergeProps as $bx7SL$mergeProps, useSyncRef as $bx7SL$useSyncRef, useGlobalListeners as $bx7SL$useGlobalListeners, isVirtualClick as $bx7SL$isVirtualClick, focusWithoutScrolling as $bx7SL$focusWithoutScrolling, isVirtualPointerEvent as $bx7SL$isVirtualPointerEvent, isIOS as $bx7SL$isIOS, runAfterTransition as $bx7SL$runAfterTransition, useLayoutEffect as $bx7SL$useLayoutEffect, isMac as $bx7SL$isMac, useEvent as $bx7SL$useEvent, useDescription as $bx7SL$useDescription} from "@react-aria/utils";
2import $bx7SL$react, {useRef as $bx7SL$useRef, useContext as $bx7SL$useContext, useState as $bx7SL$useState, useMemo as $bx7SL$useMemo, useEffect as $bx7SL$useEffect, useCallback as $bx7SL$useCallback} from "react";
3import {useIsSSR as $bx7SL$useIsSSR} from "@react-aria/ssr";
4
5/*
6 * Copyright 2020 Adobe. All rights reserved.
7 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License. You may obtain a copy
9 * of the License at http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software distributed under
12 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
13 * OF ANY KIND, either express or implied. See the License for the specific language
14 * governing permissions and limitations under the License.
15 */ /*
16 * Copyright 2020 Adobe. All rights reserved.
17 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
18 * you may not use this file except in compliance with the License. You may obtain a copy
19 * of the License at http://www.apache.org/licenses/LICENSE-2.0
20 *
21 * Unless required by applicable law or agreed to in writing, software distributed under
22 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
23 * OF ANY KIND, either express or implied. See the License for the specific language
24 * governing permissions and limitations under the License.
25 */
26/*
27 * Copyright 2020 Adobe. All rights reserved.
28 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
29 * you may not use this file except in compliance with the License. You may obtain a copy
30 * of the License at http://www.apache.org/licenses/LICENSE-2.0
31 *
32 * Unless required by applicable law or agreed to in writing, software distributed under
33 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
34 * OF ANY KIND, either express or implied. See the License for the specific language
35 * governing permissions and limitations under the License.
36 */ // Portions of the code in this file are based on code from react.
37// Original licensing for the following can be found in the
38// NOTICE file in the root directory of this source tree.
39// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
40/*
41 * Copyright 2020 Adobe. All rights reserved.
42 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
43 * you may not use this file except in compliance with the License. You may obtain a copy
44 * of the License at http://www.apache.org/licenses/LICENSE-2.0
45 *
46 * Unless required by applicable law or agreed to in writing, software distributed under
47 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
48 * OF ANY KIND, either express or implied. See the License for the specific language
49 * governing permissions and limitations under the License.
50 */
51// Note that state only matters here for iOS. Non-iOS gets user-select: none applied to the target element
52// rather than at the document level so we just need to apply/remove user-select: none for each pressed element individually
53let $14c0b72509d70225$var$state = "default";
54let $14c0b72509d70225$var$savedUserSelect = "";
55let $14c0b72509d70225$var$modifiedElementMap = new WeakMap();
56function $14c0b72509d70225$export$16a4697467175487(target) {
57 if ((0, $bx7SL$isIOS)()) {
58 if ($14c0b72509d70225$var$state === "default") {
59 $14c0b72509d70225$var$savedUserSelect = document.documentElement.style.webkitUserSelect;
60 document.documentElement.style.webkitUserSelect = "none";
61 }
62 $14c0b72509d70225$var$state = "disabled";
63 } else if (target instanceof HTMLElement || target instanceof SVGElement) {
64 // If not iOS, store the target's original user-select and change to user-select: none
65 // Ignore state since it doesn't apply for non iOS
66 $14c0b72509d70225$var$modifiedElementMap.set(target, target.style.userSelect);
67 target.style.userSelect = "none";
68 }
69}
70function $14c0b72509d70225$export$b0d6fa1ab32e3295(target) {
71 if ((0, $bx7SL$isIOS)()) {
72 // If the state is already default, there's nothing to do.
73 // If it is restoring, then there's no need to queue a second restore.
74 if ($14c0b72509d70225$var$state !== "disabled") return;
75 $14c0b72509d70225$var$state = "restoring";
76 // There appears to be a delay on iOS where selection still might occur
77 // after pointer up, so wait a bit before removing user-select.
78 setTimeout(()=>{
79 // Wait for any CSS transitions to complete so we don't recompute style
80 // for the whole page in the middle of the animation and cause jank.
81 (0, $bx7SL$runAfterTransition)(()=>{
82 // Avoid race conditions
83 if ($14c0b72509d70225$var$state === "restoring") {
84 if (document.documentElement.style.webkitUserSelect === "none") document.documentElement.style.webkitUserSelect = $14c0b72509d70225$var$savedUserSelect || "";
85 $14c0b72509d70225$var$savedUserSelect = "";
86 $14c0b72509d70225$var$state = "default";
87 }
88 });
89 }, 300);
90 } else if (target instanceof HTMLElement || target instanceof SVGElement) // If not iOS, restore the target's original user-select if any
91 // Ignore state since it doesn't apply for non iOS
92 {
93 if (target && $14c0b72509d70225$var$modifiedElementMap.has(target)) {
94 let targetOldUserSelect = $14c0b72509d70225$var$modifiedElementMap.get(target);
95 if (target.style.userSelect === "none") target.style.userSelect = targetOldUserSelect;
96 if (target.getAttribute("style") === "") target.removeAttribute("style");
97 $14c0b72509d70225$var$modifiedElementMap.delete(target);
98 }
99 }
100}
101
102
103
104/*
105 * Copyright 2020 Adobe. All rights reserved.
106 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
107 * you may not use this file except in compliance with the License. You may obtain a copy
108 * of the License at http://www.apache.org/licenses/LICENSE-2.0
109 *
110 * Unless required by applicable law or agreed to in writing, software distributed under
111 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
112 * OF ANY KIND, either express or implied. See the License for the specific language
113 * governing permissions and limitations under the License.
114 */
115const $ae1eeba8b9eafd08$export$5165eccb35aaadb5 = (0, $bx7SL$react).createContext(null);
116$ae1eeba8b9eafd08$export$5165eccb35aaadb5.displayName = "PressResponderContext";
117
118
119
120function $f6c31cce2adf654f$var$usePressResponderContext(props) {
121 // Consume context from <PressResponder> and merge with props.
122 let context = (0, $bx7SL$useContext)((0, $ae1eeba8b9eafd08$export$5165eccb35aaadb5));
123 if (context) {
124 let { register: register , ...contextProps } = context;
125 props = (0, $bx7SL$mergeProps)(contextProps, props);
126 register();
127 }
128 (0, $bx7SL$useSyncRef)(context, props.ref);
129 return props;
130}
131function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
132 let { onPress: onPress , onPressChange: onPressChange , onPressStart: onPressStart , onPressEnd: onPressEnd , onPressUp: onPressUp , isDisabled: isDisabled , isPressed: isPressedProp , preventFocusOnPress: preventFocusOnPress , shouldCancelOnPointerExit: shouldCancelOnPointerExit , allowTextSelectionOnPress: allowTextSelectionOnPress , // eslint-disable-next-line @typescript-eslint/no-unused-vars
133 ref: _ , ...domProps } = $f6c31cce2adf654f$var$usePressResponderContext(props);
134 let propsRef = (0, $bx7SL$useRef)(null);
135 propsRef.current = {
136 onPress: onPress,
137 onPressChange: onPressChange,
138 onPressStart: onPressStart,
139 onPressEnd: onPressEnd,
140 onPressUp: onPressUp,
141 isDisabled: isDisabled,
142 shouldCancelOnPointerExit: shouldCancelOnPointerExit
143 };
144 let [isPressed, setPressed] = (0, $bx7SL$useState)(false);
145 let ref = (0, $bx7SL$useRef)({
146 isPressed: false,
147 ignoreEmulatedMouseEvents: false,
148 ignoreClickAfterPress: false,
149 didFirePressStart: false,
150 activePointerId: null,
151 target: null,
152 isOverTarget: false,
153 pointerType: null
154 });
155 let { addGlobalListener: addGlobalListener , removeAllGlobalListeners: removeAllGlobalListeners } = (0, $bx7SL$useGlobalListeners)();
156 let pressProps = (0, $bx7SL$useMemo)(()=>{
157 let state = ref.current;
158 let triggerPressStart = (originalEvent, pointerType)=>{
159 let { onPressStart: onPressStart , onPressChange: onPressChange , isDisabled: isDisabled } = propsRef.current;
160 if (isDisabled || state.didFirePressStart) return;
161 if (onPressStart) onPressStart({
162 type: "pressstart",
163 pointerType: pointerType,
164 target: originalEvent.currentTarget,
165 shiftKey: originalEvent.shiftKey,
166 metaKey: originalEvent.metaKey,
167 ctrlKey: originalEvent.ctrlKey,
168 altKey: originalEvent.altKey
169 });
170 if (onPressChange) onPressChange(true);
171 state.didFirePressStart = true;
172 setPressed(true);
173 };
174 let triggerPressEnd = (originalEvent, pointerType, wasPressed = true)=>{
175 let { onPressEnd: onPressEnd , onPressChange: onPressChange , onPress: onPress , isDisabled: isDisabled } = propsRef.current;
176 if (!state.didFirePressStart) return;
177 state.ignoreClickAfterPress = true;
178 state.didFirePressStart = false;
179 if (onPressEnd) onPressEnd({
180 type: "pressend",
181 pointerType: pointerType,
182 target: originalEvent.currentTarget,
183 shiftKey: originalEvent.shiftKey,
184 metaKey: originalEvent.metaKey,
185 ctrlKey: originalEvent.ctrlKey,
186 altKey: originalEvent.altKey
187 });
188 if (onPressChange) onPressChange(false);
189 setPressed(false);
190 if (onPress && wasPressed && !isDisabled) onPress({
191 type: "press",
192 pointerType: pointerType,
193 target: originalEvent.currentTarget,
194 shiftKey: originalEvent.shiftKey,
195 metaKey: originalEvent.metaKey,
196 ctrlKey: originalEvent.ctrlKey,
197 altKey: originalEvent.altKey
198 });
199 };
200 let triggerPressUp = (originalEvent, pointerType)=>{
201 let { onPressUp: onPressUp , isDisabled: isDisabled } = propsRef.current;
202 if (isDisabled) return;
203 if (onPressUp) onPressUp({
204 type: "pressup",
205 pointerType: pointerType,
206 target: originalEvent.currentTarget,
207 shiftKey: originalEvent.shiftKey,
208 metaKey: originalEvent.metaKey,
209 ctrlKey: originalEvent.ctrlKey,
210 altKey: originalEvent.altKey
211 });
212 };
213 let cancel = (e)=>{
214 if (state.isPressed) {
215 if (state.isOverTarget) triggerPressEnd($f6c31cce2adf654f$var$createEvent(state.target, e), state.pointerType, false);
216 state.isPressed = false;
217 state.isOverTarget = false;
218 state.activePointerId = null;
219 state.pointerType = null;
220 removeAllGlobalListeners();
221 if (!allowTextSelectionOnPress) (0, $14c0b72509d70225$export$b0d6fa1ab32e3295)(state.target);
222 }
223 };
224 let pressProps = {
225 onKeyDown (e) {
226 if ($f6c31cce2adf654f$var$isValidKeyboardEvent(e.nativeEvent, e.currentTarget) && e.currentTarget.contains(e.target)) {
227 if ($f6c31cce2adf654f$var$shouldPreventDefaultKeyboard(e.target, e.key)) e.preventDefault();
228 e.stopPropagation();
229 // If the event is repeating, it may have started on a different element
230 // after which focus moved to the current element. Ignore these events and
231 // only handle the first key down event.
232 if (!state.isPressed && !e.repeat) {
233 state.target = e.currentTarget;
234 state.isPressed = true;
235 triggerPressStart(e, "keyboard");
236 // Focus may move before the key up event, so register the event on the document
237 // instead of the same element where the key down event occurred.
238 addGlobalListener(document, "keyup", onKeyUp, false);
239 }
240 } else if (e.key === "Enter" && $f6c31cce2adf654f$var$isHTMLAnchorLink(e.currentTarget)) // If the target is a link, we won't have handled this above because we want the default
241 // browser behavior to open the link when pressing Enter. But we still need to prevent
242 // default so that elements above do not also handle it (e.g. table row).
243 e.stopPropagation();
244 },
245 onKeyUp (e) {
246 if ($f6c31cce2adf654f$var$isValidKeyboardEvent(e.nativeEvent, e.currentTarget) && !e.repeat && e.currentTarget.contains(e.target)) triggerPressUp($f6c31cce2adf654f$var$createEvent(state.target, e), "keyboard");
247 },
248 onClick (e) {
249 if (e && !e.currentTarget.contains(e.target)) return;
250 if (e && e.button === 0) {
251 e.stopPropagation();
252 if (isDisabled) e.preventDefault();
253 // If triggered from a screen reader or by using element.click(),
254 // trigger as if it were a keyboard click.
255 if (!state.ignoreClickAfterPress && !state.ignoreEmulatedMouseEvents && (state.pointerType === "virtual" || (0, $bx7SL$isVirtualClick)(e.nativeEvent))) {
256 // Ensure the element receives focus (VoiceOver on iOS does not do this)
257 if (!isDisabled && !preventFocusOnPress) (0, $bx7SL$focusWithoutScrolling)(e.currentTarget);
258 triggerPressStart(e, "virtual");
259 triggerPressUp(e, "virtual");
260 triggerPressEnd(e, "virtual");
261 }
262 state.ignoreEmulatedMouseEvents = false;
263 state.ignoreClickAfterPress = false;
264 }
265 }
266 };
267 let onKeyUp = (e)=>{
268 if (state.isPressed && $f6c31cce2adf654f$var$isValidKeyboardEvent(e, state.target)) {
269 if ($f6c31cce2adf654f$var$shouldPreventDefaultKeyboard(e.target, e.key)) e.preventDefault();
270 e.stopPropagation();
271 state.isPressed = false;
272 let target = e.target;
273 triggerPressEnd($f6c31cce2adf654f$var$createEvent(state.target, e), "keyboard", state.target.contains(target));
274 removeAllGlobalListeners();
275 // If the target is a link, trigger the click method to open the URL,
276 // but defer triggering pressEnd until onClick event handler.
277 if (state.target instanceof HTMLElement && state.target.contains(target) && ($f6c31cce2adf654f$var$isHTMLAnchorLink(state.target) || state.target.getAttribute("role") === "link")) state.target.click();
278 }
279 };
280 if (typeof PointerEvent !== "undefined") {
281 pressProps.onPointerDown = (e)=>{
282 // Only handle left clicks, and ignore events that bubbled through portals.
283 if (e.button !== 0 || !e.currentTarget.contains(e.target)) return;
284 // iOS safari fires pointer events from VoiceOver with incorrect coordinates/target.
285 // Ignore and let the onClick handler take care of it instead.
286 // https://bugs.webkit.org/show_bug.cgi?id=222627
287 // https://bugs.webkit.org/show_bug.cgi?id=223202
288 if ((0, $bx7SL$isVirtualPointerEvent)(e.nativeEvent)) {
289 state.pointerType = "virtual";
290 return;
291 }
292 // Due to browser inconsistencies, especially on mobile browsers, we prevent
293 // default on pointer down and handle focusing the pressable element ourselves.
294 if ($f6c31cce2adf654f$var$shouldPreventDefault(e.currentTarget)) e.preventDefault();
295 state.pointerType = e.pointerType;
296 e.stopPropagation();
297 if (!state.isPressed) {
298 state.isPressed = true;
299 state.isOverTarget = true;
300 state.activePointerId = e.pointerId;
301 state.target = e.currentTarget;
302 if (!isDisabled && !preventFocusOnPress) (0, $bx7SL$focusWithoutScrolling)(e.currentTarget);
303 if (!allowTextSelectionOnPress) (0, $14c0b72509d70225$export$16a4697467175487)(state.target);
304 triggerPressStart(e, state.pointerType);
305 addGlobalListener(document, "pointermove", onPointerMove, false);
306 addGlobalListener(document, "pointerup", onPointerUp, false);
307 addGlobalListener(document, "pointercancel", onPointerCancel, false);
308 }
309 };
310 pressProps.onMouseDown = (e)=>{
311 if (!e.currentTarget.contains(e.target)) return;
312 if (e.button === 0) {
313 // Chrome and Firefox on touch Windows devices require mouse down events
314 // to be canceled in addition to pointer events, or an extra asynchronous
315 // focus event will be fired.
316 if ($f6c31cce2adf654f$var$shouldPreventDefault(e.currentTarget)) e.preventDefault();
317 e.stopPropagation();
318 }
319 };
320 pressProps.onPointerUp = (e)=>{
321 // iOS fires pointerup with zero width and height, so check the pointerType recorded during pointerdown.
322 if (!e.currentTarget.contains(e.target) || state.pointerType === "virtual") return;
323 // Only handle left clicks
324 // Safari on iOS sometimes fires pointerup events, even
325 // when the touch isn't over the target, so double check.
326 if (e.button === 0 && $f6c31cce2adf654f$var$isOverTarget(e, e.currentTarget)) triggerPressUp(e, state.pointerType || e.pointerType);
327 };
328 // Safari on iOS < 13.2 does not implement pointerenter/pointerleave events correctly.
329 // Use pointer move events instead to implement our own hit testing.
330 // See https://bugs.webkit.org/show_bug.cgi?id=199803
331 let onPointerMove = (e)=>{
332 if (e.pointerId !== state.activePointerId) return;
333 if ($f6c31cce2adf654f$var$isOverTarget(e, state.target)) {
334 if (!state.isOverTarget) {
335 state.isOverTarget = true;
336 triggerPressStart($f6c31cce2adf654f$var$createEvent(state.target, e), state.pointerType);
337 }
338 } else if (state.isOverTarget) {
339 state.isOverTarget = false;
340 triggerPressEnd($f6c31cce2adf654f$var$createEvent(state.target, e), state.pointerType, false);
341 if (propsRef.current.shouldCancelOnPointerExit) cancel(e);
342 }
343 };
344 let onPointerUp = (e)=>{
345 if (e.pointerId === state.activePointerId && state.isPressed && e.button === 0) {
346 if ($f6c31cce2adf654f$var$isOverTarget(e, state.target)) triggerPressEnd($f6c31cce2adf654f$var$createEvent(state.target, e), state.pointerType);
347 else if (state.isOverTarget) triggerPressEnd($f6c31cce2adf654f$var$createEvent(state.target, e), state.pointerType, false);
348 state.isPressed = false;
349 state.isOverTarget = false;
350 state.activePointerId = null;
351 state.pointerType = null;
352 removeAllGlobalListeners();
353 if (!allowTextSelectionOnPress) (0, $14c0b72509d70225$export$b0d6fa1ab32e3295)(state.target);
354 }
355 };
356 let onPointerCancel = (e)=>{
357 cancel(e);
358 };
359 pressProps.onDragStart = (e)=>{
360 if (!e.currentTarget.contains(e.target)) return;
361 // Safari does not call onPointerCancel when a drag starts, whereas Chrome and Firefox do.
362 cancel(e);
363 };
364 } else {
365 pressProps.onMouseDown = (e)=>{
366 // Only handle left clicks
367 if (e.button !== 0 || !e.currentTarget.contains(e.target)) return;
368 // Due to browser inconsistencies, especially on mobile browsers, we prevent
369 // default on mouse down and handle focusing the pressable element ourselves.
370 if ($f6c31cce2adf654f$var$shouldPreventDefault(e.currentTarget)) e.preventDefault();
371 e.stopPropagation();
372 if (state.ignoreEmulatedMouseEvents) return;
373 state.isPressed = true;
374 state.isOverTarget = true;
375 state.target = e.currentTarget;
376 state.pointerType = (0, $bx7SL$isVirtualClick)(e.nativeEvent) ? "virtual" : "mouse";
377 if (!isDisabled && !preventFocusOnPress) (0, $bx7SL$focusWithoutScrolling)(e.currentTarget);
378 triggerPressStart(e, state.pointerType);
379 addGlobalListener(document, "mouseup", onMouseUp, false);
380 };
381 pressProps.onMouseEnter = (e)=>{
382 if (!e.currentTarget.contains(e.target)) return;
383 e.stopPropagation();
384 if (state.isPressed && !state.ignoreEmulatedMouseEvents) {
385 state.isOverTarget = true;
386 triggerPressStart(e, state.pointerType);
387 }
388 };
389 pressProps.onMouseLeave = (e)=>{
390 if (!e.currentTarget.contains(e.target)) return;
391 e.stopPropagation();
392 if (state.isPressed && !state.ignoreEmulatedMouseEvents) {
393 state.isOverTarget = false;
394 triggerPressEnd(e, state.pointerType, false);
395 if (propsRef.current.shouldCancelOnPointerExit) cancel(e);
396 }
397 };
398 pressProps.onMouseUp = (e)=>{
399 if (!e.currentTarget.contains(e.target)) return;
400 if (!state.ignoreEmulatedMouseEvents && e.button === 0) triggerPressUp(e, state.pointerType);
401 };
402 let onMouseUp = (e)=>{
403 // Only handle left clicks
404 if (e.button !== 0) return;
405 state.isPressed = false;
406 removeAllGlobalListeners();
407 if (state.ignoreEmulatedMouseEvents) {
408 state.ignoreEmulatedMouseEvents = false;
409 return;
410 }
411 if ($f6c31cce2adf654f$var$isOverTarget(e, state.target)) triggerPressEnd($f6c31cce2adf654f$var$createEvent(state.target, e), state.pointerType);
412 else if (state.isOverTarget) triggerPressEnd($f6c31cce2adf654f$var$createEvent(state.target, e), state.pointerType, false);
413 state.isOverTarget = false;
414 };
415 pressProps.onTouchStart = (e)=>{
416 if (!e.currentTarget.contains(e.target)) return;
417 e.stopPropagation();
418 let touch = $f6c31cce2adf654f$var$getTouchFromEvent(e.nativeEvent);
419 if (!touch) return;
420 state.activePointerId = touch.identifier;
421 state.ignoreEmulatedMouseEvents = true;
422 state.isOverTarget = true;
423 state.isPressed = true;
424 state.target = e.currentTarget;
425 state.pointerType = "touch";
426 // Due to browser inconsistencies, especially on mobile browsers, we prevent default
427 // on the emulated mouse event and handle focusing the pressable element ourselves.
428 if (!isDisabled && !preventFocusOnPress) (0, $bx7SL$focusWithoutScrolling)(e.currentTarget);
429 if (!allowTextSelectionOnPress) (0, $14c0b72509d70225$export$16a4697467175487)(state.target);
430 triggerPressStart(e, state.pointerType);
431 addGlobalListener(window, "scroll", onScroll, true);
432 };
433 pressProps.onTouchMove = (e)=>{
434 if (!e.currentTarget.contains(e.target)) return;
435 e.stopPropagation();
436 if (!state.isPressed) return;
437 let touch = $f6c31cce2adf654f$var$getTouchById(e.nativeEvent, state.activePointerId);
438 if (touch && $f6c31cce2adf654f$var$isOverTarget(touch, e.currentTarget)) {
439 if (!state.isOverTarget) {
440 state.isOverTarget = true;
441 triggerPressStart(e, state.pointerType);
442 }
443 } else if (state.isOverTarget) {
444 state.isOverTarget = false;
445 triggerPressEnd(e, state.pointerType, false);
446 if (propsRef.current.shouldCancelOnPointerExit) cancel(e);
447 }
448 };
449 pressProps.onTouchEnd = (e)=>{
450 if (!e.currentTarget.contains(e.target)) return;
451 e.stopPropagation();
452 if (!state.isPressed) return;
453 let touch = $f6c31cce2adf654f$var$getTouchById(e.nativeEvent, state.activePointerId);
454 if (touch && $f6c31cce2adf654f$var$isOverTarget(touch, e.currentTarget)) {
455 triggerPressUp(e, state.pointerType);
456 triggerPressEnd(e, state.pointerType);
457 } else if (state.isOverTarget) triggerPressEnd(e, state.pointerType, false);
458 state.isPressed = false;
459 state.activePointerId = null;
460 state.isOverTarget = false;
461 state.ignoreEmulatedMouseEvents = true;
462 if (!allowTextSelectionOnPress) (0, $14c0b72509d70225$export$b0d6fa1ab32e3295)(state.target);
463 removeAllGlobalListeners();
464 };
465 pressProps.onTouchCancel = (e)=>{
466 if (!e.currentTarget.contains(e.target)) return;
467 e.stopPropagation();
468 if (state.isPressed) cancel(e);
469 };
470 let onScroll = (e)=>{
471 if (state.isPressed && e.target.contains(state.target)) cancel({
472 currentTarget: state.target,
473 shiftKey: false,
474 ctrlKey: false,
475 metaKey: false,
476 altKey: false
477 });
478 };
479 pressProps.onDragStart = (e)=>{
480 if (!e.currentTarget.contains(e.target)) return;
481 cancel(e);
482 };
483 }
484 return pressProps;
485 }, [
486 addGlobalListener,
487 isDisabled,
488 preventFocusOnPress,
489 removeAllGlobalListeners,
490 allowTextSelectionOnPress
491 ]);
492 // Remove user-select: none in case component unmounts immediately after pressStart
493 // eslint-disable-next-line arrow-body-style
494 (0, $bx7SL$useEffect)(()=>{
495 return ()=>{
496 if (!allowTextSelectionOnPress) // eslint-disable-next-line react-hooks/exhaustive-deps
497 (0, $14c0b72509d70225$export$b0d6fa1ab32e3295)(ref.current.target);
498 };
499 }, [
500 allowTextSelectionOnPress
501 ]);
502 return {
503 isPressed: isPressedProp || isPressed,
504 pressProps: (0, $bx7SL$mergeProps)(domProps, pressProps)
505 };
506}
507function $f6c31cce2adf654f$var$isHTMLAnchorLink(target) {
508 return target.tagName === "A" && target.hasAttribute("href");
509}
510function $f6c31cce2adf654f$var$isValidKeyboardEvent(event, currentTarget) {
511 const { key: key , code: code } = event;
512 const element = currentTarget;
513 const role = element.getAttribute("role");
514 // Accessibility for keyboards. Space and Enter only.
515 // "Spacebar" is for IE 11
516 return (key === "Enter" || key === " " || key === "Spacebar" || code === "Space") && !(element instanceof HTMLInputElement && !$f6c31cce2adf654f$var$isValidInputKey(element, key) || element instanceof HTMLTextAreaElement || element.isContentEditable) && // A link with a valid href should be handled natively,
517 // unless it also has role='button' and was triggered using Space.
518 (!$f6c31cce2adf654f$var$isHTMLAnchorLink(element) || role === "button" && key !== "Enter") && // An element with role='link' should only trigger with Enter key
519 !(role === "link" && key !== "Enter");
520}
521function $f6c31cce2adf654f$var$getTouchFromEvent(event) {
522 const { targetTouches: targetTouches } = event;
523 if (targetTouches.length > 0) return targetTouches[0];
524 return null;
525}
526function $f6c31cce2adf654f$var$getTouchById(event, pointerId) {
527 const changedTouches = event.changedTouches;
528 for(let i = 0; i < changedTouches.length; i++){
529 const touch = changedTouches[i];
530 if (touch.identifier === pointerId) return touch;
531 }
532 return null;
533}
534function $f6c31cce2adf654f$var$createEvent(target, e) {
535 return {
536 currentTarget: target,
537 shiftKey: e.shiftKey,
538 ctrlKey: e.ctrlKey,
539 metaKey: e.metaKey,
540 altKey: e.altKey
541 };
542}
543function $f6c31cce2adf654f$var$getPointClientRect(point) {
544 let offsetX = point.width / 2 || point.radiusX || 0;
545 let offsetY = point.height / 2 || point.radiusY || 0;
546 return {
547 top: point.clientY - offsetY,
548 right: point.clientX + offsetX,
549 bottom: point.clientY + offsetY,
550 left: point.clientX - offsetX
551 };
552}
553function $f6c31cce2adf654f$var$areRectanglesOverlapping(a, b) {
554 // check if they cannot overlap on x axis
555 if (a.left > b.right || b.left > a.right) return false;
556 // check if they cannot overlap on y axis
557 if (a.top > b.bottom || b.top > a.bottom) return false;
558 return true;
559}
560function $f6c31cce2adf654f$var$isOverTarget(point, target) {
561 let rect = target.getBoundingClientRect();
562 let pointRect = $f6c31cce2adf654f$var$getPointClientRect(point);
563 return $f6c31cce2adf654f$var$areRectanglesOverlapping(rect, pointRect);
564}
565function $f6c31cce2adf654f$var$shouldPreventDefault(target) {
566 // We cannot prevent default if the target is a draggable element.
567 return !(target instanceof HTMLElement) || !target.draggable;
568}
569function $f6c31cce2adf654f$var$shouldPreventDefaultKeyboard(target, key) {
570 if (target instanceof HTMLInputElement) return !$f6c31cce2adf654f$var$isValidInputKey(target, key);
571 if (target instanceof HTMLButtonElement) return target.type !== "submit";
572 return true;
573}
574const $f6c31cce2adf654f$var$nonTextInputTypes = new Set([
575 "checkbox",
576 "radio",
577 "range",
578 "color",
579 "file",
580 "image",
581 "button",
582 "submit",
583 "reset"
584]);
585function $f6c31cce2adf654f$var$isValidInputKey(target, key) {
586 // Only space should toggle checkboxes and radios, not enter.
587 return target.type === "checkbox" || target.type === "radio" ? key === " " : $f6c31cce2adf654f$var$nonTextInputTypes.has(target.type);
588}
589
590
591
592const $3b117e43dc0ca95d$export$27c701ed9e449e99 = /*#__PURE__*/ (0, $bx7SL$react).forwardRef(({ children: children , ...props }, ref)=>{
593 let newRef = (0, $bx7SL$useRef)();
594 ref = ref !== null && ref !== void 0 ? ref : newRef;
595 let { pressProps: pressProps } = (0, $f6c31cce2adf654f$export$45712eceda6fad21)({
596 ...props,
597 ref: ref
598 });
599 let child = (0, $bx7SL$react).Children.only(children);
600 return /*#__PURE__*/ (0, $bx7SL$react).cloneElement(child, // @ts-ignore
601 {
602 ref: ref,
603 ...(0, $bx7SL$mergeProps)(child.props, pressProps)
604 });
605});
606
607
608/*
609 * Copyright 2020 Adobe. All rights reserved.
610 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
611 * you may not use this file except in compliance with the License. You may obtain a copy
612 * of the License at http://www.apache.org/licenses/LICENSE-2.0
613 *
614 * Unless required by applicable law or agreed to in writing, software distributed under
615 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
616 * OF ANY KIND, either express or implied. See the License for the specific language
617 * governing permissions and limitations under the License.
618 */
619
620
621const $f1ab8c75478c6f73$export$3351871ee4b288b8 = /*#__PURE__*/ (0, $bx7SL$react).forwardRef(({ children: children , ...props }, ref)=>{
622 let isRegistered = (0, $bx7SL$useRef)(false);
623 let prevContext = (0, $bx7SL$useContext)((0, $ae1eeba8b9eafd08$export$5165eccb35aaadb5));
624 let context = (0, $bx7SL$mergeProps)(prevContext || {}, {
625 ...props,
626 ref: ref || (prevContext === null || prevContext === void 0 ? void 0 : prevContext.ref),
627 register () {
628 isRegistered.current = true;
629 if (prevContext) prevContext.register();
630 }
631 });
632 (0, $bx7SL$useSyncRef)(prevContext, ref);
633 (0, $bx7SL$useEffect)(()=>{
634 if (!isRegistered.current) console.warn("A PressResponder was rendered without a pressable child. Either call the usePress hook, or wrap your DOM node with <Pressable> component.");
635 }, []);
636 return /*#__PURE__*/ (0, $bx7SL$react).createElement((0, $ae1eeba8b9eafd08$export$5165eccb35aaadb5).Provider, {
637 value: context
638 }, children);
639});
640
641
642/*
643 * Copyright 2020 Adobe. All rights reserved.
644 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
645 * you may not use this file except in compliance with the License. You may obtain a copy
646 * of the License at http://www.apache.org/licenses/LICENSE-2.0
647 *
648 * Unless required by applicable law or agreed to in writing, software distributed under
649 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
650 * OF ANY KIND, either express or implied. See the License for the specific language
651 * governing permissions and limitations under the License.
652 */ // Portions of the code in this file are based on code from react.
653// Original licensing for the following can be found in the
654// NOTICE file in the root directory of this source tree.
655// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
656
657/*
658 * Copyright 2020 Adobe. All rights reserved.
659 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
660 * you may not use this file except in compliance with the License. You may obtain a copy
661 * of the License at http://www.apache.org/licenses/LICENSE-2.0
662 *
663 * Unless required by applicable law or agreed to in writing, software distributed under
664 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
665 * OF ANY KIND, either express or implied. See the License for the specific language
666 * governing permissions and limitations under the License.
667 */
668
669class $8a9cb279dc87e130$export$905e7fc544a71f36 {
670 isDefaultPrevented() {
671 return this.nativeEvent.defaultPrevented;
672 }
673 preventDefault() {
674 this.defaultPrevented = true;
675 this.nativeEvent.preventDefault();
676 }
677 stopPropagation() {
678 this.nativeEvent.stopPropagation();
679 this.isPropagationStopped = ()=>true;
680 }
681 isPropagationStopped() {
682 return false;
683 }
684 persist() {}
685 constructor(type, nativeEvent){
686 this.nativeEvent = nativeEvent;
687 this.target = nativeEvent.target;
688 this.currentTarget = nativeEvent.currentTarget;
689 this.relatedTarget = nativeEvent.relatedTarget;
690 this.bubbles = nativeEvent.bubbles;
691 this.cancelable = nativeEvent.cancelable;
692 this.defaultPrevented = nativeEvent.defaultPrevented;
693 this.eventPhase = nativeEvent.eventPhase;
694 this.isTrusted = nativeEvent.isTrusted;
695 this.timeStamp = nativeEvent.timeStamp;
696 this.type = type;
697 }
698}
699function $8a9cb279dc87e130$export$715c682d09d639cc(onBlur) {
700 let stateRef = (0, $bx7SL$useRef)({
701 isFocused: false,
702 onBlur: onBlur,
703 observer: null
704 });
705 stateRef.current.onBlur = onBlur;
706 // Clean up MutationObserver on unmount. See below.
707 // eslint-disable-next-line arrow-body-style
708 (0, $bx7SL$useLayoutEffect)(()=>{
709 const state = stateRef.current;
710 return ()=>{
711 if (state.observer) {
712 state.observer.disconnect();
713 state.observer = null;
714 }
715 };
716 }, []);
717 // This function is called during a React onFocus event.
718 return (0, $bx7SL$useCallback)((e)=>{
719 // React does not fire onBlur when an element is disabled. https://github.com/facebook/react/issues/9142
720 // Most browsers fire a native focusout event in this case, except for Firefox. In that case, we use a
721 // MutationObserver to watch for the disabled attribute, and dispatch these events ourselves.
722 // For browsers that do, focusout fires before the MutationObserver, so onBlur should not fire twice.
723 if (e.target instanceof HTMLButtonElement || e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement || e.target instanceof HTMLSelectElement) {
724 stateRef.current.isFocused = true;
725 let target = e.target;
726 let onBlurHandler = (e)=>{
727 var // For backward compatibility, dispatch a (fake) React synthetic event.
728 _stateRef_current, _stateRef_current_onBlur;
729 stateRef.current.isFocused = false;
730 if (target.disabled) (_stateRef_current_onBlur = (_stateRef_current = stateRef.current).onBlur) === null || _stateRef_current_onBlur === void 0 ? void 0 : _stateRef_current_onBlur.call(_stateRef_current, new $8a9cb279dc87e130$export$905e7fc544a71f36("blur", e));
731 // We no longer need the MutationObserver once the target is blurred.
732 if (stateRef.current.observer) {
733 stateRef.current.observer.disconnect();
734 stateRef.current.observer = null;
735 }
736 };
737 target.addEventListener("focusout", onBlurHandler, {
738 once: true
739 });
740 stateRef.current.observer = new MutationObserver(()=>{
741 if (stateRef.current.isFocused && target.disabled) {
742 stateRef.current.observer.disconnect();
743 target.dispatchEvent(new FocusEvent("blur"));
744 target.dispatchEvent(new FocusEvent("focusout", {
745 bubbles: true
746 }));
747 }
748 });
749 stateRef.current.observer.observe(target, {
750 attributes: true,
751 attributeFilter: [
752 "disabled"
753 ]
754 });
755 }
756 }, []);
757}
758
759
760function $a1ea59d68270f0dd$export$f8168d8dd8fd66e6(props) {
761 let { isDisabled: isDisabled , onFocus: onFocusProp , onBlur: onBlurProp , onFocusChange: onFocusChange } = props;
762 const onBlur = (0, $bx7SL$useCallback)((e)=>{
763 if (e.target === e.currentTarget) {
764 if (onBlurProp) onBlurProp(e);
765 if (onFocusChange) onFocusChange(false);
766 return true;
767 }
768 }, [
769 onBlurProp,
770 onFocusChange
771 ]);
772 const onSyntheticFocus = (0, $8a9cb279dc87e130$export$715c682d09d639cc)(onBlur);
773 const onFocus = (0, $bx7SL$useCallback)((e)=>{
774 // Double check that document.activeElement actually matches e.target in case a previously chained
775 // focus handler already moved focus somewhere else.
776 if (e.target === e.currentTarget && document.activeElement === e.target) {
777 if (onFocusProp) onFocusProp(e);
778 if (onFocusChange) onFocusChange(true);
779 onSyntheticFocus(e);
780 }
781 }, [
782 onFocusChange,
783 onFocusProp,
784 onSyntheticFocus
785 ]);
786 return {
787 focusProps: {
788 onFocus: !isDisabled && (onFocusProp || onFocusChange || onBlurProp) ? onFocus : undefined,
789 onBlur: !isDisabled && (onBlurProp || onFocusChange) ? onBlur : undefined
790 }
791 };
792}
793
794
795/*
796 * Copyright 2020 Adobe. All rights reserved.
797 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
798 * you may not use this file except in compliance with the License. You may obtain a copy
799 * of the License at http://www.apache.org/licenses/LICENSE-2.0
800 *
801 * Unless required by applicable law or agreed to in writing, software distributed under
802 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
803 * OF ANY KIND, either express or implied. See the License for the specific language
804 * governing permissions and limitations under the License.
805 */ // Portions of the code in this file are based on code from react.
806// Original licensing for the following can be found in the
807// NOTICE file in the root directory of this source tree.
808// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
809
810
811
812let $507fabe10e71c6fb$var$currentModality = null;
813let $507fabe10e71c6fb$var$changeHandlers = new Set();
814let $507fabe10e71c6fb$var$hasSetupGlobalListeners = false;
815let $507fabe10e71c6fb$var$hasEventBeforeFocus = false;
816let $507fabe10e71c6fb$var$hasBlurredWindowRecently = false;
817// Only Tab or Esc keys will make focus visible on text input elements
818const $507fabe10e71c6fb$var$FOCUS_VISIBLE_INPUT_KEYS = {
819 Tab: true,
820 Escape: true
821};
822function $507fabe10e71c6fb$var$triggerChangeHandlers(modality, e) {
823 for (let handler of $507fabe10e71c6fb$var$changeHandlers)handler(modality, e);
824}
825/**
826 * Helper function to determine if a KeyboardEvent is unmodified and could make keyboard focus styles visible.
827 */ function $507fabe10e71c6fb$var$isValidKey(e) {
828 // Control and Shift keys trigger when navigating back to the tab with keyboard.
829 return !(e.metaKey || !(0, $bx7SL$isMac)() && e.altKey || e.ctrlKey || e.key === "Control" || e.key === "Shift" || e.key === "Meta");
830}
831function $507fabe10e71c6fb$var$handleKeyboardEvent(e) {
832 $507fabe10e71c6fb$var$hasEventBeforeFocus = true;
833 if ($507fabe10e71c6fb$var$isValidKey(e)) {
834 $507fabe10e71c6fb$var$currentModality = "keyboard";
835 $507fabe10e71c6fb$var$triggerChangeHandlers("keyboard", e);
836 }
837}
838function $507fabe10e71c6fb$var$handlePointerEvent(e) {
839 $507fabe10e71c6fb$var$currentModality = "pointer";
840 if (e.type === "mousedown" || e.type === "pointerdown") {
841 $507fabe10e71c6fb$var$hasEventBeforeFocus = true;
842 $507fabe10e71c6fb$var$triggerChangeHandlers("pointer", e);
843 }
844}
845function $507fabe10e71c6fb$var$handleClickEvent(e) {
846 if ((0, $bx7SL$isVirtualClick)(e)) {
847 $507fabe10e71c6fb$var$hasEventBeforeFocus = true;
848 $507fabe10e71c6fb$var$currentModality = "virtual";
849 }
850}
851function $507fabe10e71c6fb$var$handleFocusEvent(e) {
852 // Firefox fires two extra focus events when the user first clicks into an iframe:
853 // first on the window, then on the document. We ignore these events so they don't
854 // cause keyboard focus rings to appear.
855 if (e.target === window || e.target === document) return;
856 // If a focus event occurs without a preceding keyboard or pointer event, switch to virtual modality.
857 // This occurs, for example, when navigating a form with the next/previous buttons on iOS.
858 if (!$507fabe10e71c6fb$var$hasEventBeforeFocus && !$507fabe10e71c6fb$var$hasBlurredWindowRecently) {
859 $507fabe10e71c6fb$var$currentModality = "virtual";
860 $507fabe10e71c6fb$var$triggerChangeHandlers("virtual", e);
861 }
862 $507fabe10e71c6fb$var$hasEventBeforeFocus = false;
863 $507fabe10e71c6fb$var$hasBlurredWindowRecently = false;
864}
865function $507fabe10e71c6fb$var$handleWindowBlur() {
866 // When the window is blurred, reset state. This is necessary when tabbing out of the window,
867 // for example, since a subsequent focus event won't be fired.
868 $507fabe10e71c6fb$var$hasEventBeforeFocus = false;
869 $507fabe10e71c6fb$var$hasBlurredWindowRecently = true;
870}
871/**
872 * Setup global event listeners to control when keyboard focus style should be visible.
873 */ function $507fabe10e71c6fb$var$setupGlobalFocusEvents() {
874 if (typeof window === "undefined" || $507fabe10e71c6fb$var$hasSetupGlobalListeners) return;
875 // Programmatic focus() calls shouldn't affect the current input modality.
876 // However, we need to detect other cases when a focus event occurs without
877 // a preceding user event (e.g. screen reader focus). Overriding the focus
878 // method on HTMLElement.prototype is a bit hacky, but works.
879 let focus = HTMLElement.prototype.focus;
880 HTMLElement.prototype.focus = function() {
881 $507fabe10e71c6fb$var$hasEventBeforeFocus = true;
882 focus.apply(this, arguments);
883 };
884 document.addEventListener("keydown", $507fabe10e71c6fb$var$handleKeyboardEvent, true);
885 document.addEventListener("keyup", $507fabe10e71c6fb$var$handleKeyboardEvent, true);
886 document.addEventListener("click", $507fabe10e71c6fb$var$handleClickEvent, true);
887 // Register focus events on the window so they are sure to happen
888 // before React's event listeners (registered on the document).
889 window.addEventListener("focus", $507fabe10e71c6fb$var$handleFocusEvent, true);
890 window.addEventListener("blur", $507fabe10e71c6fb$var$handleWindowBlur, false);
891 if (typeof PointerEvent !== "undefined") {
892 document.addEventListener("pointerdown", $507fabe10e71c6fb$var$handlePointerEvent, true);
893 document.addEventListener("pointermove", $507fabe10e71c6fb$var$handlePointerEvent, true);
894 document.addEventListener("pointerup", $507fabe10e71c6fb$var$handlePointerEvent, true);
895 } else {
896 document.addEventListener("mousedown", $507fabe10e71c6fb$var$handlePointerEvent, true);
897 document.addEventListener("mousemove", $507fabe10e71c6fb$var$handlePointerEvent, true);
898 document.addEventListener("mouseup", $507fabe10e71c6fb$var$handlePointerEvent, true);
899 }
900 $507fabe10e71c6fb$var$hasSetupGlobalListeners = true;
901}
902if (typeof document !== "undefined") {
903 if (document.readyState !== "loading") $507fabe10e71c6fb$var$setupGlobalFocusEvents();
904 else document.addEventListener("DOMContentLoaded", $507fabe10e71c6fb$var$setupGlobalFocusEvents);
905}
906function $507fabe10e71c6fb$export$b9b3dfddab17db27() {
907 return $507fabe10e71c6fb$var$currentModality !== "pointer";
908}
909function $507fabe10e71c6fb$export$630ff653c5ada6a9() {
910 return $507fabe10e71c6fb$var$currentModality;
911}
912function $507fabe10e71c6fb$export$8397ddfc504fdb9a(modality) {
913 $507fabe10e71c6fb$var$currentModality = modality;
914 $507fabe10e71c6fb$var$triggerChangeHandlers(modality, null);
915}
916function $507fabe10e71c6fb$export$98e20ec92f614cfe() {
917 $507fabe10e71c6fb$var$setupGlobalFocusEvents();
918 let [modality, setModality] = (0, $bx7SL$useState)($507fabe10e71c6fb$var$currentModality);
919 (0, $bx7SL$useEffect)(()=>{
920 let handler = ()=>{
921 setModality($507fabe10e71c6fb$var$currentModality);
922 };
923 $507fabe10e71c6fb$var$changeHandlers.add(handler);
924 return ()=>{
925 $507fabe10e71c6fb$var$changeHandlers.delete(handler);
926 };
927 }, []);
928 return (0, $bx7SL$useIsSSR)() ? null : modality;
929}
930/**
931 * If this is attached to text input component, return if the event is a focus event (Tab/Escape keys pressed) so that
932 * focus visible style can be properly set.
933 */ function $507fabe10e71c6fb$var$isKeyboardFocusEvent(isTextInput, modality, e) {
934 return !(isTextInput && modality === "keyboard" && e instanceof KeyboardEvent && !$507fabe10e71c6fb$var$FOCUS_VISIBLE_INPUT_KEYS[e.key]);
935}
936function $507fabe10e71c6fb$export$ffd9e5021c1fb2d6(props = {}) {
937 let { isTextInput: isTextInput , autoFocus: autoFocus } = props;
938 let [isFocusVisibleState, setFocusVisible] = (0, $bx7SL$useState)(autoFocus || $507fabe10e71c6fb$export$b9b3dfddab17db27());
939 $507fabe10e71c6fb$export$ec71b4b83ac08ec3((isFocusVisible)=>{
940 setFocusVisible(isFocusVisible);
941 }, [
942 isTextInput
943 ], {
944 isTextInput: isTextInput
945 });
946 return {
947 isFocusVisible: isFocusVisibleState
948 };
949}
950function $507fabe10e71c6fb$export$ec71b4b83ac08ec3(fn, deps, opts) {
951 $507fabe10e71c6fb$var$setupGlobalFocusEvents();
952 (0, $bx7SL$useEffect)(()=>{
953 let handler = (modality, e)=>{
954 if (!$507fabe10e71c6fb$var$isKeyboardFocusEvent(opts === null || opts === void 0 ? void 0 : opts.isTextInput, modality, e)) return;
955 fn($507fabe10e71c6fb$export$b9b3dfddab17db27());
956 };
957 $507fabe10e71c6fb$var$changeHandlers.add(handler);
958 return ()=>{
959 $507fabe10e71c6fb$var$changeHandlers.delete(handler);
960 };
961 // eslint-disable-next-line react-hooks/exhaustive-deps
962 }, deps);
963}
964
965
966/*
967 * Copyright 2020 Adobe. All rights reserved.
968 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
969 * you may not use this file except in compliance with the License. You may obtain a copy
970 * of the License at http://www.apache.org/licenses/LICENSE-2.0
971 *
972 * Unless required by applicable law or agreed to in writing, software distributed under
973 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
974 * OF ANY KIND, either express or implied. See the License for the specific language
975 * governing permissions and limitations under the License.
976 */ // Portions of the code in this file are based on code from react.
977// Original licensing for the following can be found in the
978// NOTICE file in the root directory of this source tree.
979// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
980
981
982function $9ab94262bd0047c7$export$420e68273165f4ec(props) {
983 let { isDisabled: isDisabled , onBlurWithin: onBlurWithin , onFocusWithin: onFocusWithin , onFocusWithinChange: onFocusWithinChange } = props;
984 let state = (0, $bx7SL$useRef)({
985 isFocusWithin: false
986 });
987 let onBlur = (0, $bx7SL$useCallback)((e)=>{
988 // We don't want to trigger onBlurWithin and then immediately onFocusWithin again
989 // when moving focus inside the element. Only trigger if the currentTarget doesn't
990 // include the relatedTarget (where focus is moving).
991 if (state.current.isFocusWithin && !e.currentTarget.contains(e.relatedTarget)) {
992 state.current.isFocusWithin = false;
993 if (onBlurWithin) onBlurWithin(e);
994 if (onFocusWithinChange) onFocusWithinChange(false);
995 }
996 }, [
997 onBlurWithin,
998 onFocusWithinChange,
999 state
1000 ]);
1001 let onSyntheticFocus = (0, $8a9cb279dc87e130$export$715c682d09d639cc)(onBlur);
1002 let onFocus = (0, $bx7SL$useCallback)((e)=>{
1003 // Double check that document.activeElement actually matches e.target in case a previously chained
1004 // focus handler already moved focus somewhere else.
1005 if (!state.current.isFocusWithin && document.activeElement === e.target) {
1006 if (onFocusWithin) onFocusWithin(e);
1007 if (onFocusWithinChange) onFocusWithinChange(true);
1008 state.current.isFocusWithin = true;
1009 onSyntheticFocus(e);
1010 }
1011 }, [
1012 onFocusWithin,
1013 onFocusWithinChange,
1014 onSyntheticFocus
1015 ]);
1016 if (isDisabled) return {
1017 focusWithinProps: {
1018 onFocus: null,
1019 onBlur: null
1020 }
1021 };
1022 return {
1023 focusWithinProps: {
1024 onFocus: onFocus,
1025 onBlur: onBlur
1026 }
1027 };
1028}
1029
1030
1031/*
1032 * Copyright 2020 Adobe. All rights reserved.
1033 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
1034 * you may not use this file except in compliance with the License. You may obtain a copy
1035 * of the License at http://www.apache.org/licenses/LICENSE-2.0
1036 *
1037 * Unless required by applicable law or agreed to in writing, software distributed under
1038 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
1039 * OF ANY KIND, either express or implied. See the License for the specific language
1040 * governing permissions and limitations under the License.
1041 */ // Portions of the code in this file are based on code from react.
1042// Original licensing for the following can be found in the
1043// NOTICE file in the root directory of this source tree.
1044// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
1045
1046// iOS fires onPointerEnter twice: once with pointerType="touch" and again with pointerType="mouse".
1047// We want to ignore these emulated events so they do not trigger hover behavior.
1048// See https://bugs.webkit.org/show_bug.cgi?id=214609.
1049let $6179b936705e76d3$var$globalIgnoreEmulatedMouseEvents = false;
1050let $6179b936705e76d3$var$hoverCount = 0;
1051function $6179b936705e76d3$var$setGlobalIgnoreEmulatedMouseEvents() {
1052 $6179b936705e76d3$var$globalIgnoreEmulatedMouseEvents = true;
1053 // Clear globalIgnoreEmulatedMouseEvents after a short timeout. iOS fires onPointerEnter
1054 // with pointerType="mouse" immediately after onPointerUp and before onFocus. On other
1055 // devices that don't have this quirk, we don't want to ignore a mouse hover sometime in
1056 // the distant future because a user previously touched the element.
1057 setTimeout(()=>{
1058 $6179b936705e76d3$var$globalIgnoreEmulatedMouseEvents = false;
1059 }, 50);
1060}
1061function $6179b936705e76d3$var$handleGlobalPointerEvent(e) {
1062 if (e.pointerType === "touch") $6179b936705e76d3$var$setGlobalIgnoreEmulatedMouseEvents();
1063}
1064function $6179b936705e76d3$var$setupGlobalTouchEvents() {
1065 if (typeof document === "undefined") return;
1066 if (typeof PointerEvent !== "undefined") document.addEventListener("pointerup", $6179b936705e76d3$var$handleGlobalPointerEvent);
1067 else document.addEventListener("touchend", $6179b936705e76d3$var$setGlobalIgnoreEmulatedMouseEvents);
1068 $6179b936705e76d3$var$hoverCount++;
1069 return ()=>{
1070 $6179b936705e76d3$var$hoverCount--;
1071 if ($6179b936705e76d3$var$hoverCount > 0) return;
1072 if (typeof PointerEvent !== "undefined") document.removeEventListener("pointerup", $6179b936705e76d3$var$handleGlobalPointerEvent);
1073 else document.removeEventListener("touchend", $6179b936705e76d3$var$setGlobalIgnoreEmulatedMouseEvents);
1074 };
1075}
1076function $6179b936705e76d3$export$ae780daf29e6d456(props) {
1077 let { onHoverStart: onHoverStart , onHoverChange: onHoverChange , onHoverEnd: onHoverEnd , isDisabled: isDisabled } = props;
1078 let [isHovered, setHovered] = (0, $bx7SL$useState)(false);
1079 let state = (0, $bx7SL$useRef)({
1080 isHovered: false,
1081 ignoreEmulatedMouseEvents: false,
1082 pointerType: "",
1083 target: null
1084 }).current;
1085 (0, $bx7SL$useEffect)($6179b936705e76d3$var$setupGlobalTouchEvents, []);
1086 let { hoverProps: hoverProps , triggerHoverEnd: triggerHoverEnd } = (0, $bx7SL$useMemo)(()=>{
1087 let triggerHoverStart = (event, pointerType)=>{
1088 state.pointerType = pointerType;
1089 if (isDisabled || pointerType === "touch" || state.isHovered || !event.currentTarget.contains(event.target)) return;
1090 state.isHovered = true;
1091 let target = event.currentTarget;
1092 state.target = target;
1093 if (onHoverStart) onHoverStart({
1094 type: "hoverstart",
1095 target: target,
1096 pointerType: pointerType
1097 });
1098 if (onHoverChange) onHoverChange(true);
1099 setHovered(true);
1100 };
1101 let triggerHoverEnd = (event, pointerType)=>{
1102 state.pointerType = "";
1103 state.target = null;
1104 if (pointerType === "touch" || !state.isHovered) return;
1105 state.isHovered = false;
1106 let target = event.currentTarget;
1107 if (onHoverEnd) onHoverEnd({
1108 type: "hoverend",
1109 target: target,
1110 pointerType: pointerType
1111 });
1112 if (onHoverChange) onHoverChange(false);
1113 setHovered(false);
1114 };
1115 let hoverProps = {};
1116 if (typeof PointerEvent !== "undefined") {
1117 hoverProps.onPointerEnter = (e)=>{
1118 if ($6179b936705e76d3$var$globalIgnoreEmulatedMouseEvents && e.pointerType === "mouse") return;
1119 triggerHoverStart(e, e.pointerType);
1120 };
1121 hoverProps.onPointerLeave = (e)=>{
1122 if (!isDisabled && e.currentTarget.contains(e.target)) triggerHoverEnd(e, e.pointerType);
1123 };
1124 } else {
1125 hoverProps.onTouchStart = ()=>{
1126 state.ignoreEmulatedMouseEvents = true;
1127 };
1128 hoverProps.onMouseEnter = (e)=>{
1129 if (!state.ignoreEmulatedMouseEvents && !$6179b936705e76d3$var$globalIgnoreEmulatedMouseEvents) triggerHoverStart(e, "mouse");
1130 state.ignoreEmulatedMouseEvents = false;
1131 };
1132 hoverProps.onMouseLeave = (e)=>{
1133 if (!isDisabled && e.currentTarget.contains(e.target)) triggerHoverEnd(e, "mouse");
1134 };
1135 }
1136 return {
1137 hoverProps: hoverProps,
1138 triggerHoverEnd: triggerHoverEnd
1139 };
1140 }, [
1141 onHoverStart,
1142 onHoverChange,
1143 onHoverEnd,
1144 isDisabled,
1145 state
1146 ]);
1147 (0, $bx7SL$useEffect)(()=>{
1148 // Call the triggerHoverEnd as soon as isDisabled changes to true
1149 // Safe to call triggerHoverEnd, it will early return if we aren't currently hovering
1150 if (isDisabled) triggerHoverEnd({
1151 currentTarget: state.target
1152 }, state.pointerType);
1153 // eslint-disable-next-line react-hooks/exhaustive-deps
1154 }, [
1155 isDisabled
1156 ]);
1157 return {
1158 hoverProps: hoverProps,
1159 isHovered: isHovered
1160 };
1161}
1162
1163
1164/*
1165 * Copyright 2020 Adobe. All rights reserved.
1166 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
1167 * you may not use this file except in compliance with the License. You may obtain a copy
1168 * of the License at http://www.apache.org/licenses/LICENSE-2.0
1169 *
1170 * Unless required by applicable law or agreed to in writing, software distributed under
1171 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
1172 * OF ANY KIND, either express or implied. See the License for the specific language
1173 * governing permissions and limitations under the License.
1174 */ // Portions of the code in this file are based on code from react.
1175// Original licensing for the following can be found in the
1176// NOTICE file in the root directory of this source tree.
1177// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
1178
1179function $e0b6e0b68ec7f50f$export$872b660ac5a1ff98(props) {
1180 let { ref: ref , onInteractOutside: onInteractOutside , isDisabled: isDisabled , onInteractOutsideStart: onInteractOutsideStart } = props;
1181 let stateRef = (0, $bx7SL$useRef)({
1182 isPointerDown: false,
1183 ignoreEmulatedMouseEvents: false,
1184 onInteractOutside: onInteractOutside,
1185 onInteractOutsideStart: onInteractOutsideStart
1186 });
1187 let state = stateRef.current;
1188 state.onInteractOutside = onInteractOutside;
1189 state.onInteractOutsideStart = onInteractOutsideStart;
1190 (0, $bx7SL$useEffect)(()=>{
1191 if (isDisabled) return;
1192 let onPointerDown = (e)=>{
1193 if ($e0b6e0b68ec7f50f$var$isValidEvent(e, ref) && state.onInteractOutside) {
1194 if (state.onInteractOutsideStart) state.onInteractOutsideStart(e);
1195 state.isPointerDown = true;
1196 }
1197 };
1198 // Use pointer events if available. Otherwise, fall back to mouse and touch events.
1199 if (typeof PointerEvent !== "undefined") {
1200 let onPointerUp = (e)=>{
1201 if (state.isPointerDown && state.onInteractOutside && $e0b6e0b68ec7f50f$var$isValidEvent(e, ref)) state.onInteractOutside(e);
1202 state.isPointerDown = false;
1203 };
1204 // changing these to capture phase fixed combobox
1205 document.addEventListener("pointerdown", onPointerDown, true);
1206 document.addEventListener("pointerup", onPointerUp, true);
1207 return ()=>{
1208 document.removeEventListener("pointerdown", onPointerDown, true);
1209 document.removeEventListener("pointerup", onPointerUp, true);
1210 };
1211 } else {
1212 let onMouseUp = (e)=>{
1213 if (state.ignoreEmulatedMouseEvents) state.ignoreEmulatedMouseEvents = false;
1214 else if (state.isPointerDown && state.onInteractOutside && $e0b6e0b68ec7f50f$var$isValidEvent(e, ref)) state.onInteractOutside(e);
1215 state.isPointerDown = false;
1216 };
1217 let onTouchEnd = (e)=>{
1218 state.ignoreEmulatedMouseEvents = true;
1219 if (state.onInteractOutside && state.isPointerDown && $e0b6e0b68ec7f50f$var$isValidEvent(e, ref)) state.onInteractOutside(e);
1220 state.isPointerDown = false;
1221 };
1222 document.addEventListener("mousedown", onPointerDown, true);
1223 document.addEventListener("mouseup", onMouseUp, true);
1224 document.addEventListener("touchstart", onPointerDown, true);
1225 document.addEventListener("touchend", onTouchEnd, true);
1226 return ()=>{
1227 document.removeEventListener("mousedown", onPointerDown, true);
1228 document.removeEventListener("mouseup", onMouseUp, true);
1229 document.removeEventListener("touchstart", onPointerDown, true);
1230 document.removeEventListener("touchend", onTouchEnd, true);
1231 };
1232 }
1233 }, [
1234 ref,
1235 state,
1236 isDisabled
1237 ]);
1238}
1239function $e0b6e0b68ec7f50f$var$isValidEvent(event, ref) {
1240 if (event.button > 0) return false;
1241 if (event.target) {
1242 // if the event target is no longer in the document, ignore
1243 const ownerDocument = event.target.ownerDocument;
1244 if (!ownerDocument || !ownerDocument.documentElement.contains(event.target)) return false;
1245 // If the target is within a top layer element (e.g. toasts), ignore.
1246 if (event.target.closest("[data-react-aria-top-layer]")) return false;
1247 }
1248 return ref.current && !ref.current.contains(event.target);
1249}
1250
1251
1252/*
1253 * Copyright 2020 Adobe. All rights reserved.
1254 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
1255 * you may not use this file except in compliance with the License. You may obtain a copy
1256 * of the License at http://www.apache.org/licenses/LICENSE-2.0
1257 *
1258 * Unless required by applicable law or agreed to in writing, software distributed under
1259 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
1260 * OF ANY KIND, either express or implied. See the License for the specific language
1261 * governing permissions and limitations under the License.
1262 */ /*
1263 * Copyright 2020 Adobe. All rights reserved.
1264 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
1265 * you may not use this file except in compliance with the License. You may obtain a copy
1266 * of the License at http://www.apache.org/licenses/LICENSE-2.0
1267 *
1268 * Unless required by applicable law or agreed to in writing, software distributed under
1269 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
1270 * OF ANY KIND, either express or implied. See the License for the specific language
1271 * governing permissions and limitations under the License.
1272 */ function $93925083ecbb358c$export$48d1ea6320830260(handler) {
1273 if (!handler) return;
1274 let shouldStopPropagation = true;
1275 return (e)=>{
1276 let event = {
1277 ...e,
1278 preventDefault () {
1279 e.preventDefault();
1280 },
1281 isDefaultPrevented () {
1282 return e.isDefaultPrevented();
1283 },
1284 stopPropagation () {
1285 console.error("stopPropagation is now the default behavior for events in React Spectrum. You can use continuePropagation() to revert this behavior.");
1286 },
1287 continuePropagation () {
1288 shouldStopPropagation = false;
1289 }
1290 };
1291 handler(event);
1292 if (shouldStopPropagation) e.stopPropagation();
1293 };
1294}
1295
1296
1297function $46d819fcbaf35654$export$8f71654801c2f7cd(props) {
1298 return {
1299 keyboardProps: props.isDisabled ? {} : {
1300 onKeyDown: (0, $93925083ecbb358c$export$48d1ea6320830260)(props.onKeyDown),
1301 onKeyUp: (0, $93925083ecbb358c$export$48d1ea6320830260)(props.onKeyUp)
1302 }
1303 };
1304}
1305
1306
1307/*
1308 * Copyright 2020 Adobe. All rights reserved.
1309 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
1310 * you may not use this file except in compliance with the License. You may obtain a copy
1311 * of the License at http://www.apache.org/licenses/LICENSE-2.0
1312 *
1313 * Unless required by applicable law or agreed to in writing, software distributed under
1314 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
1315 * OF ANY KIND, either express or implied. See the License for the specific language
1316 * governing permissions and limitations under the License.
1317 */
1318
1319
1320function $e8a7022cf87cba2a$export$36da96379f79f245(props) {
1321 let { onMoveStart: onMoveStart , onMove: onMove , onMoveEnd: onMoveEnd } = props;
1322 let state = (0, $bx7SL$useRef)({
1323 didMove: false,
1324 lastPosition: null,
1325 id: null
1326 });
1327 let { addGlobalListener: addGlobalListener , removeGlobalListener: removeGlobalListener } = (0, $bx7SL$useGlobalListeners)();
1328 let moveProps = (0, $bx7SL$useMemo)(()=>{
1329 let moveProps = {};
1330 let start = ()=>{
1331 (0, $14c0b72509d70225$export$16a4697467175487)();
1332 state.current.didMove = false;
1333 };
1334 let move = (originalEvent, pointerType, deltaX, deltaY)=>{
1335 if (deltaX === 0 && deltaY === 0) return;
1336 if (!state.current.didMove) {
1337 state.current.didMove = true;
1338 onMoveStart === null || onMoveStart === void 0 ? void 0 : onMoveStart({
1339 type: "movestart",
1340 pointerType: pointerType,
1341 shiftKey: originalEvent.shiftKey,
1342 metaKey: originalEvent.metaKey,
1343 ctrlKey: originalEvent.ctrlKey,
1344 altKey: originalEvent.altKey
1345 });
1346 }
1347 onMove({
1348 type: "move",
1349 pointerType: pointerType,
1350 deltaX: deltaX,
1351 deltaY: deltaY,
1352 shiftKey: originalEvent.shiftKey,
1353 metaKey: originalEvent.metaKey,
1354 ctrlKey: originalEvent.ctrlKey,
1355 altKey: originalEvent.altKey
1356 });
1357 };
1358 let end = (originalEvent, pointerType)=>{
1359 (0, $14c0b72509d70225$export$b0d6fa1ab32e3295)();
1360 if (state.current.didMove) onMoveEnd === null || onMoveEnd === void 0 ? void 0 : onMoveEnd({
1361 type: "moveend",
1362 pointerType: pointerType,
1363 shiftKey: originalEvent.shiftKey,
1364 metaKey: originalEvent.metaKey,
1365 ctrlKey: originalEvent.ctrlKey,
1366 altKey: originalEvent.altKey
1367 });
1368 };
1369 if (typeof PointerEvent === "undefined") {
1370 let onMouseMove = (e)=>{
1371 if (e.button === 0) {
1372 move(e, "mouse", e.pageX - state.current.lastPosition.pageX, e.pageY - state.current.lastPosition.pageY);
1373 state.current.lastPosition = {
1374 pageX: e.pageX,
1375 pageY: e.pageY
1376 };
1377 }
1378 };
1379 let onMouseUp = (e)=>{
1380 if (e.button === 0) {
1381 end(e, "mouse");
1382 removeGlobalListener(window, "mousemove", onMouseMove, false);
1383 removeGlobalListener(window, "mouseup", onMouseUp, false);
1384 }
1385 };
1386 moveProps.onMouseDown = (e)=>{
1387 if (e.button === 0) {
1388 start();
1389 e.stopPropagation();
1390 e.preventDefault();
1391 state.current.lastPosition = {
1392 pageX: e.pageX,
1393 pageY: e.pageY
1394 };
1395 addGlobalListener(window, "mousemove", onMouseMove, false);
1396 addGlobalListener(window, "mouseup", onMouseUp, false);
1397 }
1398 };
1399 let onTouchMove = (e)=>{
1400 let touch = [
1401 ...e.changedTouches
1402 ].findIndex(({ identifier: identifier })=>identifier === state.current.id);
1403 if (touch >= 0) {
1404 let { pageX: pageX , pageY: pageY } = e.changedTouches[touch];
1405 move(e, "touch", pageX - state.current.lastPosition.pageX, pageY - state.current.lastPosition.pageY);
1406 state.current.lastPosition = {
1407 pageX: pageX,
1408 pageY: pageY
1409 };
1410 }
1411 };
1412 let onTouchEnd = (e)=>{
1413 let touch = [
1414 ...e.changedTouches
1415 ].findIndex(({ identifier: identifier })=>identifier === state.current.id);
1416 if (touch >= 0) {
1417 end(e, "touch");
1418 state.current.id = null;
1419 removeGlobalListener(window, "touchmove", onTouchMove);
1420 removeGlobalListener(window, "touchend", onTouchEnd);
1421 removeGlobalListener(window, "touchcancel", onTouchEnd);
1422 }
1423 };
1424 moveProps.onTouchStart = (e)=>{
1425 if (e.changedTouches.length === 0 || state.current.id != null) return;
1426 let { pageX: pageX , pageY: pageY , identifier: identifier } = e.changedTouches[0];
1427 start();
1428 e.stopPropagation();
1429 e.preventDefault();
1430 state.current.lastPosition = {
1431 pageX: pageX,
1432 pageY: pageY
1433 };
1434 state.current.id = identifier;
1435 addGlobalListener(window, "touchmove", onTouchMove, false);
1436 addGlobalListener(window, "touchend", onTouchEnd, false);
1437 addGlobalListener(window, "touchcancel", onTouchEnd, false);
1438 };
1439 } else {
1440 let onPointerMove = (e)=>{
1441 if (e.pointerId === state.current.id) {
1442 let pointerType = e.pointerType || "mouse";
1443 // Problems with PointerEvent#movementX/movementY:
1444 // 1. it is always 0 on macOS Safari.
1445 // 2. On Chrome Android, it's scaled by devicePixelRatio, but not on Chrome macOS
1446 move(e, pointerType, e.pageX - state.current.lastPosition.pageX, e.pageY - state.current.lastPosition.pageY);
1447 state.current.lastPosition = {
1448 pageX: e.pageX,
1449 pageY: e.pageY
1450 };
1451 }
1452 };
1453 let onPointerUp = (e)=>{
1454 if (e.pointerId === state.current.id) {
1455 let pointerType = e.pointerType || "mouse";
1456 end(e, pointerType);
1457 state.current.id = null;
1458 removeGlobalListener(window, "pointermove", onPointerMove, false);
1459 removeGlobalListener(window, "pointerup", onPointerUp, false);
1460 removeGlobalListener(window, "pointercancel", onPointerUp, false);
1461 }
1462 };
1463 moveProps.onPointerDown = (e)=>{
1464 if (e.button === 0 && state.current.id == null) {
1465 start();
1466 e.stopPropagation();
1467 e.preventDefault();
1468 state.current.lastPosition = {
1469 pageX: e.pageX,
1470 pageY: e.pageY
1471 };
1472 state.current.id = e.pointerId;
1473 addGlobalListener(window, "pointermove", onPointerMove, false);
1474 addGlobalListener(window, "pointerup", onPointerUp, false);
1475 addGlobalListener(window, "pointercancel", onPointerUp, false);
1476 }
1477 };
1478 }
1479 let triggerKeyboardMove = (e, deltaX, deltaY)=>{
1480 start();
1481 move(e, "keyboard", deltaX, deltaY);
1482 end(e, "keyboard");
1483 };
1484 moveProps.onKeyDown = (e)=>{
1485 switch(e.key){
1486 case "Left":
1487 case "ArrowLeft":
1488 e.preventDefault();
1489 e.stopPropagation();
1490 triggerKeyboardMove(e, -1, 0);
1491 break;
1492 case "Right":
1493 case "ArrowRight":
1494 e.preventDefault();
1495 e.stopPropagation();
1496 triggerKeyboardMove(e, 1, 0);
1497 break;
1498 case "Up":
1499 case "ArrowUp":
1500 e.preventDefault();
1501 e.stopPropagation();
1502 triggerKeyboardMove(e, 0, -1);
1503 break;
1504 case "Down":
1505 case "ArrowDown":
1506 e.preventDefault();
1507 e.stopPropagation();
1508 triggerKeyboardMove(e, 0, 1);
1509 break;
1510 }
1511 };
1512 return moveProps;
1513 }, [
1514 state,
1515 onMoveStart,
1516 onMove,
1517 onMoveEnd,
1518 addGlobalListener,
1519 removeGlobalListener
1520 ]);
1521 return {
1522 moveProps: moveProps
1523 };
1524}
1525
1526
1527
1528/*
1529 * Copyright 2021 Adobe. All rights reserved.
1530 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
1531 * you may not use this file except in compliance with the License. You may obtain a copy
1532 * of the License at http://www.apache.org/licenses/LICENSE-2.0
1533 *
1534 * Unless required by applicable law or agreed to in writing, software distributed under
1535 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
1536 * OF ANY KIND, either express or implied. See the License for the specific language
1537 * governing permissions and limitations under the License.
1538 */
1539
1540function $7d0a636d7a4dcefd$export$2123ff2b87c81ca(props, ref) {
1541 let { onScroll: onScroll , isDisabled: isDisabled } = props;
1542 let onScrollHandler = (0, $bx7SL$useCallback)((e)=>{
1543 // If the ctrlKey is pressed, this is a zoom event, do nothing.
1544 if (e.ctrlKey) return;
1545 // stop scrolling the page
1546 e.preventDefault();
1547 e.stopPropagation();
1548 if (onScroll) onScroll({
1549 deltaX: e.deltaX,
1550 deltaY: e.deltaY
1551 });
1552 }, [
1553 onScroll
1554 ]);
1555 (0, $bx7SL$useEvent)(ref, "wheel", isDisabled ? null : onScrollHandler);
1556}
1557
1558
1559/*
1560 * Copyright 2020 Adobe. All rights reserved.
1561 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
1562 * you may not use this file except in compliance with the License. You may obtain a copy
1563 * of the License at http://www.apache.org/licenses/LICENSE-2.0
1564 *
1565 * Unless required by applicable law or agreed to in writing, software distributed under
1566 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
1567 * OF ANY KIND, either express or implied. See the License for the specific language
1568 * governing permissions and limitations under the License.
1569 */
1570
1571
1572const $8a26561d2877236e$var$DEFAULT_THRESHOLD = 500;
1573function $8a26561d2877236e$export$c24ed0104d07eab9(props) {
1574 let { isDisabled: isDisabled , onLongPressStart: onLongPressStart , onLongPressEnd: onLongPressEnd , onLongPress: onLongPress , threshold: threshold = $8a26561d2877236e$var$DEFAULT_THRESHOLD , accessibilityDescription: accessibilityDescription } = props;
1575 const timeRef = (0, $bx7SL$useRef)(null);
1576 let { addGlobalListener: addGlobalListener , removeGlobalListener: removeGlobalListener } = (0, $bx7SL$useGlobalListeners)();
1577 let { pressProps: pressProps } = (0, $f6c31cce2adf654f$export$45712eceda6fad21)({
1578 isDisabled: isDisabled,
1579 onPressStart (e) {
1580 if (e.pointerType === "mouse" || e.pointerType === "touch") {
1581 if (onLongPressStart) onLongPressStart({
1582 ...e,
1583 type: "longpressstart"
1584 });
1585 timeRef.current = setTimeout(()=>{
1586 // Prevent other usePress handlers from also handling this event.
1587 e.target.dispatchEvent(new PointerEvent("pointercancel", {
1588 bubbles: true
1589 }));
1590 if (onLongPress) onLongPress({
1591 ...e,
1592 type: "longpress"
1593 });
1594 timeRef.current = null;
1595 }, threshold);
1596 // Prevent context menu, which may be opened on long press on touch devices
1597 if (e.pointerType === "touch") {
1598 let onContextMenu = (e)=>{
1599 e.preventDefault();
1600 };
1601 addGlobalListener(e.target, "contextmenu", onContextMenu, {
1602 once: true
1603 });
1604 addGlobalListener(window, "pointerup", ()=>{
1605 // If no contextmenu event is fired quickly after pointerup, remove the handler
1606 // so future context menu events outside a long press are not prevented.
1607 setTimeout(()=>{
1608 removeGlobalListener(e.target, "contextmenu", onContextMenu);
1609 }, 30);
1610 }, {
1611 once: true
1612 });
1613 }
1614 }
1615 },
1616 onPressEnd (e) {
1617 if (timeRef.current) clearTimeout(timeRef.current);
1618 if (onLongPressEnd && (e.pointerType === "mouse" || e.pointerType === "touch")) onLongPressEnd({
1619 ...e,
1620 type: "longpressend"
1621 });
1622 }
1623 });
1624 let descriptionProps = (0, $bx7SL$useDescription)(onLongPress && !isDisabled ? accessibilityDescription : null);
1625 return {
1626 longPressProps: (0, $bx7SL$mergeProps)(pressProps, descriptionProps)
1627 };
1628}
1629
1630
1631
1632
1633export {$3b117e43dc0ca95d$export$27c701ed9e449e99 as Pressable, $f1ab8c75478c6f73$export$3351871ee4b288b8 as PressResponder, $a1ea59d68270f0dd$export$f8168d8dd8fd66e6 as useFocus, $507fabe10e71c6fb$export$b9b3dfddab17db27 as isFocusVisible, $507fabe10e71c6fb$export$630ff653c5ada6a9 as getInteractionModality, $507fabe10e71c6fb$export$8397ddfc504fdb9a as setInteractionModality, $507fabe10e71c6fb$export$98e20ec92f614cfe as useInteractionModality, $507fabe10e71c6fb$export$ffd9e5021c1fb2d6 as useFocusVisible, $507fabe10e71c6fb$export$ec71b4b83ac08ec3 as useFocusVisibleListener, $9ab94262bd0047c7$export$420e68273165f4ec as useFocusWithin, $6179b936705e76d3$export$ae780daf29e6d456 as useHover, $e0b6e0b68ec7f50f$export$872b660ac5a1ff98 as useInteractOutside, $46d819fcbaf35654$export$8f71654801c2f7cd as useKeyboard, $e8a7022cf87cba2a$export$36da96379f79f245 as useMove, $f6c31cce2adf654f$export$45712eceda6fad21 as usePress, $7d0a636d7a4dcefd$export$2123ff2b87c81ca as useScrollWheel, $8a26561d2877236e$export$c24ed0104d07eab9 as useLongPress};
1634//# sourceMappingURL=module.js.map