UNPKG

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