UNPKG

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