@react-aria/interactions 3.0.0-nightly.2429 → 3.0.0-nightly.2436
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/import.mjs +52 -18
- package/dist/main.js +51 -16
- package/dist/main.js.map +1 -1
- package/dist/module.js +52 -18
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +3 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/PressResponder.tsx +8 -0
- package/src/index.ts +1 -1
- package/src/usePress.ts +58 -22
package/dist/import.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {mergeProps as $bx7SL$mergeProps, useSyncRef as $bx7SL$useSyncRef, useGlobalListeners as $bx7SL$useGlobalListeners, useEffectEvent as $bx7SL$useEffectEvent, isVirtualClick as $bx7SL$isVirtualClick, focusWithoutScrolling as $bx7SL$focusWithoutScrolling, isVirtualPointerEvent as $bx7SL$isVirtualPointerEvent, isIOS as $bx7SL$isIOS, runAfterTransition as $bx7SL$runAfterTransition, useLayoutEffect as $bx7SL$useLayoutEffect,
|
|
1
|
+
import {mergeProps as $bx7SL$mergeProps, useSyncRef as $bx7SL$useSyncRef, useGlobalListeners as $bx7SL$useGlobalListeners, useEffectEvent as $bx7SL$useEffectEvent, isMac as $bx7SL$isMac, openLink as $bx7SL$openLink, isVirtualClick as $bx7SL$isVirtualClick, focusWithoutScrolling as $bx7SL$focusWithoutScrolling, isVirtualPointerEvent as $bx7SL$isVirtualPointerEvent, isIOS as $bx7SL$isIOS, runAfterTransition as $bx7SL$runAfterTransition, useLayoutEffect as $bx7SL$useLayoutEffect, useEvent as $bx7SL$useEvent, useDescription as $bx7SL$useDescription} from "@react-aria/utils";
|
|
2
2
|
import $bx7SL$react, {useRef as $bx7SL$useRef, useContext as $bx7SL$useContext, useState as $bx7SL$useState, useMemo as $bx7SL$useMemo, useEffect as $bx7SL$useEffect, useCallback as $bx7SL$useCallback} from "react";
|
|
3
3
|
import {_ as $bx7SL$_} from "@swc/helpers/_/_class_private_field_get";
|
|
4
4
|
import {_ as $bx7SL$_1} from "@swc/helpers/_/_class_private_field_init";
|
|
@@ -157,6 +157,7 @@ class $f6c31cce2adf654f$var$PressEvent {
|
|
|
157
157
|
this.altKey = originalEvent.altKey;
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
|
+
const $f6c31cce2adf654f$var$LINK_CLICKED = Symbol("linkClicked");
|
|
160
161
|
function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
|
|
161
162
|
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
|
|
162
163
|
ref: _ , ...domProps } = $f6c31cce2adf654f$var$usePressResponderContext(props);
|
|
@@ -166,6 +167,7 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
|
|
|
166
167
|
ignoreEmulatedMouseEvents: false,
|
|
167
168
|
ignoreClickAfterPress: false,
|
|
168
169
|
didFirePressStart: false,
|
|
170
|
+
isTriggeringEvent: false,
|
|
169
171
|
activePointerId: null,
|
|
170
172
|
target: null,
|
|
171
173
|
isOverTarget: false,
|
|
@@ -176,12 +178,14 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
|
|
|
176
178
|
let state = ref.current;
|
|
177
179
|
if (isDisabled || state.didFirePressStart) return;
|
|
178
180
|
let shouldStopPropagation = true;
|
|
181
|
+
state.isTriggeringEvent = true;
|
|
179
182
|
if (onPressStart) {
|
|
180
183
|
let event = new $f6c31cce2adf654f$var$PressEvent("pressstart", pointerType, originalEvent);
|
|
181
184
|
onPressStart(event);
|
|
182
185
|
shouldStopPropagation = event.shouldStopPropagation;
|
|
183
186
|
}
|
|
184
187
|
if (onPressChange) onPressChange(true);
|
|
188
|
+
state.isTriggeringEvent = false;
|
|
185
189
|
state.didFirePressStart = true;
|
|
186
190
|
setPressed(true);
|
|
187
191
|
return shouldStopPropagation;
|
|
@@ -191,6 +195,7 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
|
|
|
191
195
|
if (!state.didFirePressStart) return;
|
|
192
196
|
state.ignoreClickAfterPress = true;
|
|
193
197
|
state.didFirePressStart = false;
|
|
198
|
+
state.isTriggeringEvent = true;
|
|
194
199
|
let shouldStopPropagation = true;
|
|
195
200
|
if (onPressEnd) {
|
|
196
201
|
let event = new $f6c31cce2adf654f$var$PressEvent("pressend", pointerType, originalEvent);
|
|
@@ -204,13 +209,17 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
|
|
|
204
209
|
onPress(event);
|
|
205
210
|
shouldStopPropagation && (shouldStopPropagation = event.shouldStopPropagation);
|
|
206
211
|
}
|
|
212
|
+
state.isTriggeringEvent = false;
|
|
207
213
|
return shouldStopPropagation;
|
|
208
214
|
});
|
|
209
215
|
let triggerPressUp = (0, $bx7SL$useEffectEvent)((originalEvent, pointerType)=>{
|
|
216
|
+
let state = ref.current;
|
|
210
217
|
if (isDisabled) return;
|
|
211
218
|
if (onPressUp) {
|
|
219
|
+
state.isTriggeringEvent = true;
|
|
212
220
|
let event = new $f6c31cce2adf654f$var$PressEvent("pressup", pointerType, originalEvent);
|
|
213
221
|
onPressUp(event);
|
|
222
|
+
state.isTriggeringEvent = false;
|
|
214
223
|
return event.shouldStopPropagation;
|
|
215
224
|
}
|
|
216
225
|
return true;
|
|
@@ -249,22 +258,27 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
|
|
|
249
258
|
addGlobalListener(document, "keyup", onKeyUp, false);
|
|
250
259
|
}
|
|
251
260
|
if (shouldStopPropagation) e.stopPropagation();
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
261
|
+
// Keep track of the keydown events that occur while the Meta (e.g. Command) key is held.
|
|
262
|
+
// macOS has a bug where keyup events are not fired while the Meta key is down.
|
|
263
|
+
// When the Meta key itself is released we will get an event for that, and we'll act as if
|
|
264
|
+
// all of these other keys were released as well.
|
|
265
|
+
// https://bugs.chromium.org/p/chromium/issues/detail?id=1393524
|
|
266
|
+
// https://bugs.webkit.org/show_bug.cgi?id=55291
|
|
267
|
+
// https://bugzilla.mozilla.org/show_bug.cgi?id=1299553
|
|
268
|
+
if (e.metaKey && (0, $bx7SL$isMac)()) state.metaKeyEvents.set(e.key, e.nativeEvent);
|
|
269
|
+
} else if (e.key === "Meta") state.metaKeyEvents = new Map();
|
|
256
270
|
},
|
|
257
271
|
onKeyUp (e) {
|
|
258
272
|
if ($f6c31cce2adf654f$var$isValidKeyboardEvent(e.nativeEvent, e.currentTarget) && !e.repeat && e.currentTarget.contains(e.target)) triggerPressUp($f6c31cce2adf654f$var$createEvent(state.target, e), "keyboard");
|
|
259
273
|
},
|
|
260
274
|
onClick (e) {
|
|
261
275
|
if (e && !e.currentTarget.contains(e.target)) return;
|
|
262
|
-
if (e && e.button === 0) {
|
|
276
|
+
if (e && e.button === 0 && !state.isTriggeringEvent && !(0, $bx7SL$openLink).isOpening) {
|
|
263
277
|
let shouldStopPropagation = true;
|
|
264
278
|
if (isDisabled) e.preventDefault();
|
|
265
279
|
// If triggered from a screen reader or by using element.click(),
|
|
266
280
|
// trigger as if it were a keyboard click.
|
|
267
|
-
if (!state.ignoreClickAfterPress && !state.ignoreEmulatedMouseEvents && (state.pointerType === "virtual" || (0, $bx7SL$isVirtualClick)(e.nativeEvent))) {
|
|
281
|
+
if (!state.ignoreClickAfterPress && !state.ignoreEmulatedMouseEvents && !state.isPressed && (state.pointerType === "virtual" || (0, $bx7SL$isVirtualClick)(e.nativeEvent))) {
|
|
268
282
|
// Ensure the element receives focus (VoiceOver on iOS does not do this)
|
|
269
283
|
if (!isDisabled && !preventFocusOnPress) (0, $bx7SL$focusWithoutScrolling)(e.currentTarget);
|
|
270
284
|
let stopPressStart = triggerPressStart(e, "virtual");
|
|
@@ -279,16 +293,32 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
|
|
|
279
293
|
}
|
|
280
294
|
};
|
|
281
295
|
let onKeyUp = (e)=>{
|
|
296
|
+
var _state_metaKeyEvents;
|
|
282
297
|
if (state.isPressed && $f6c31cce2adf654f$var$isValidKeyboardEvent(e, state.target)) {
|
|
298
|
+
var _state_metaKeyEvents1;
|
|
283
299
|
if ($f6c31cce2adf654f$var$shouldPreventDefaultKeyboard(e.target, e.key)) e.preventDefault();
|
|
284
|
-
state.isPressed = false;
|
|
285
300
|
let target = e.target;
|
|
286
301
|
let shouldStopPropagation = triggerPressEnd($f6c31cce2adf654f$var$createEvent(state.target, e), "keyboard", state.target.contains(target));
|
|
287
302
|
removeAllGlobalListeners();
|
|
288
303
|
if (shouldStopPropagation) e.stopPropagation();
|
|
289
|
-
// If
|
|
290
|
-
//
|
|
291
|
-
|
|
304
|
+
// If a link was triggered with a key other than Enter, open the URL ourselves.
|
|
305
|
+
// This means the link has a role override, and the default browser behavior
|
|
306
|
+
// only applies when using the Enter key.
|
|
307
|
+
if (e.key !== "Enter" && $f6c31cce2adf654f$var$isHTMLAnchorLink(state.target) && state.target.contains(target) && !e[$f6c31cce2adf654f$var$LINK_CLICKED]) {
|
|
308
|
+
// Store a hidden property on the event so we only trigger link click once,
|
|
309
|
+
// even if there are multiple usePress instances attached to the element.
|
|
310
|
+
e[$f6c31cce2adf654f$var$LINK_CLICKED] = true;
|
|
311
|
+
(0, $bx7SL$openLink)(state.target, e, false);
|
|
312
|
+
}
|
|
313
|
+
state.isPressed = false;
|
|
314
|
+
(_state_metaKeyEvents1 = state.metaKeyEvents) === null || _state_metaKeyEvents1 === void 0 ? void 0 : _state_metaKeyEvents1.delete(e.key);
|
|
315
|
+
} else if (e.key === "Meta" && ((_state_metaKeyEvents = state.metaKeyEvents) === null || _state_metaKeyEvents === void 0 ? void 0 : _state_metaKeyEvents.size)) {
|
|
316
|
+
// If we recorded keydown events that occurred while the Meta key was pressed,
|
|
317
|
+
// and those haven't received keyup events already, fire keyup events ourselves.
|
|
318
|
+
// See comment above for more info about the macOS bug causing this.
|
|
319
|
+
let events = state.metaKeyEvents;
|
|
320
|
+
state.metaKeyEvents = null;
|
|
321
|
+
for (let event of events.values())state.target.dispatchEvent(new KeyboardEvent("keyup", event));
|
|
292
322
|
}
|
|
293
323
|
};
|
|
294
324
|
if (typeof PointerEvent !== "undefined") {
|
|
@@ -417,7 +447,7 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
|
|
|
417
447
|
};
|
|
418
448
|
pressProps.onMouseUp = (e)=>{
|
|
419
449
|
if (!e.currentTarget.contains(e.target)) return;
|
|
420
|
-
if (!state.ignoreEmulatedMouseEvents && e.button === 0) triggerPressUp(e, state.pointerType);
|
|
450
|
+
if (!state.ignoreEmulatedMouseEvents && e.button === 0) triggerPressUp(e, state.pointerType || "mouse");
|
|
421
451
|
};
|
|
422
452
|
let onMouseUp = (e)=>{
|
|
423
453
|
// Only handle left clicks
|
|
@@ -546,10 +576,8 @@ function $f6c31cce2adf654f$var$isValidKeyboardEvent(event, currentTarget) {
|
|
|
546
576
|
const role = element.getAttribute("role");
|
|
547
577
|
// Accessibility for keyboards. Space and Enter only.
|
|
548
578
|
// "Spacebar" is for IE 11
|
|
549
|
-
return (key === "Enter" || key === " " || key === "Spacebar" || code === "Space") && !(element instanceof HTMLInputElement && !$f6c31cce2adf654f$var$isValidInputKey(element, key) || element instanceof HTMLTextAreaElement || element.isContentEditable) && //
|
|
550
|
-
|
|
551
|
-
(!$f6c31cce2adf654f$var$isHTMLAnchorLink(element) || role === "button" && key !== "Enter") && // An element with role='link' should only trigger with Enter key
|
|
552
|
-
!(role === "link" && key !== "Enter");
|
|
579
|
+
return (key === "Enter" || key === " " || key === "Spacebar" || code === "Space") && !(element instanceof HTMLInputElement && !$f6c31cce2adf654f$var$isValidInputKey(element, key) || element instanceof HTMLTextAreaElement || element.isContentEditable) && // Links should only trigger with Enter key
|
|
580
|
+
!((role === "link" || !role && $f6c31cce2adf654f$var$isHTMLAnchorLink(element)) && key !== "Enter");
|
|
553
581
|
}
|
|
554
582
|
function $f6c31cce2adf654f$var$getTouchFromEvent(event) {
|
|
555
583
|
const { targetTouches: targetTouches } = event;
|
|
@@ -597,11 +625,12 @@ function $f6c31cce2adf654f$var$isOverTarget(point, target) {
|
|
|
597
625
|
}
|
|
598
626
|
function $f6c31cce2adf654f$var$shouldPreventDefault(target) {
|
|
599
627
|
// We cannot prevent default if the target is a draggable element.
|
|
600
|
-
return !(target instanceof HTMLElement) || !target.draggable;
|
|
628
|
+
return !(target instanceof HTMLElement) || !target.hasAttribute("draggable");
|
|
601
629
|
}
|
|
602
630
|
function $f6c31cce2adf654f$var$shouldPreventDefaultKeyboard(target, key) {
|
|
603
631
|
if (target instanceof HTMLInputElement) return !$f6c31cce2adf654f$var$isValidInputKey(target, key);
|
|
604
632
|
if (target instanceof HTMLButtonElement) return target.type !== "submit" && target.type !== "reset";
|
|
633
|
+
if ($f6c31cce2adf654f$var$isHTMLAnchorLink(target)) return false;
|
|
605
634
|
return true;
|
|
606
635
|
}
|
|
607
636
|
const $f6c31cce2adf654f$var$nonTextInputTypes = new Set([
|
|
@@ -673,6 +702,11 @@ const $f1ab8c75478c6f73$export$3351871ee4b288b8 = /*#__PURE__*/ (0, $bx7SL$react
|
|
|
673
702
|
value: context
|
|
674
703
|
}, children);
|
|
675
704
|
});
|
|
705
|
+
function $f1ab8c75478c6f73$export$cf75428e0b9ed1ea({ children: children }) {
|
|
706
|
+
return /*#__PURE__*/ (0, $bx7SL$react).createElement((0, $ae1eeba8b9eafd08$export$5165eccb35aaadb5).Provider, {
|
|
707
|
+
value: undefined
|
|
708
|
+
}, children);
|
|
709
|
+
}
|
|
676
710
|
|
|
677
711
|
|
|
678
712
|
/*
|
|
@@ -1673,5 +1707,5 @@ function $8a26561d2877236e$export$c24ed0104d07eab9(props) {
|
|
|
1673
1707
|
|
|
1674
1708
|
|
|
1675
1709
|
|
|
1676
|
-
export {$3b117e43dc0ca95d$export$27c701ed9e449e99 as Pressable, $f1ab8c75478c6f73$export$3351871ee4b288b8 as PressResponder, $a1ea59d68270f0dd$export$f8168d8dd8fd66e6 as useFocus, $507fabe10e71c6fb$export$b9b3dfddab17db27 as isFocusVisible, $507fabe10e71c6fb$export$630ff653c5ada6a9 as getInteractionModality, $507fabe10e71c6fb$export$8397ddfc504fdb9a as setInteractionModality, $507fabe10e71c6fb$export$98e20ec92f614cfe as useInteractionModality, $507fabe10e71c6fb$export$ffd9e5021c1fb2d6 as useFocusVisible, $507fabe10e71c6fb$export$ec71b4b83ac08ec3 as useFocusVisibleListener, $9ab94262bd0047c7$export$420e68273165f4ec as useFocusWithin, $6179b936705e76d3$export$ae780daf29e6d456 as useHover, $e0b6e0b68ec7f50f$export$872b660ac5a1ff98 as useInteractOutside, $46d819fcbaf35654$export$8f71654801c2f7cd as useKeyboard, $e8a7022cf87cba2a$export$36da96379f79f245 as useMove, $f6c31cce2adf654f$export$45712eceda6fad21 as usePress, $7d0a636d7a4dcefd$export$2123ff2b87c81ca as useScrollWheel, $8a26561d2877236e$export$c24ed0104d07eab9 as useLongPress};
|
|
1710
|
+
export {$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};
|
|
1677
1711
|
//# sourceMappingURL=module.js.map
|
package/dist/main.js
CHANGED
|
@@ -14,6 +14,7 @@ function $parcel$interopDefault(a) {
|
|
|
14
14
|
|
|
15
15
|
$parcel$export(module.exports, "Pressable", () => $e1dbec26039c051d$export$27c701ed9e449e99);
|
|
16
16
|
$parcel$export(module.exports, "PressResponder", () => $3596bae48579386f$export$3351871ee4b288b8);
|
|
17
|
+
$parcel$export(module.exports, "ClearPressResponder", () => $3596bae48579386f$export$cf75428e0b9ed1ea);
|
|
17
18
|
$parcel$export(module.exports, "useFocus", () => $5cb73d0ce355b0dc$export$f8168d8dd8fd66e6);
|
|
18
19
|
$parcel$export(module.exports, "isFocusVisible", () => $e77252a287ef94ab$export$b9b3dfddab17db27);
|
|
19
20
|
$parcel$export(module.exports, "getInteractionModality", () => $e77252a287ef94ab$export$630ff653c5ada6a9);
|
|
@@ -181,6 +182,7 @@ class $0294ea432cd92340$var$PressEvent {
|
|
|
181
182
|
this.altKey = originalEvent.altKey;
|
|
182
183
|
}
|
|
183
184
|
}
|
|
185
|
+
const $0294ea432cd92340$var$LINK_CLICKED = Symbol("linkClicked");
|
|
184
186
|
function $0294ea432cd92340$export$45712eceda6fad21(props) {
|
|
185
187
|
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
|
|
186
188
|
ref: _ , ...domProps } = $0294ea432cd92340$var$usePressResponderContext(props);
|
|
@@ -190,6 +192,7 @@ function $0294ea432cd92340$export$45712eceda6fad21(props) {
|
|
|
190
192
|
ignoreEmulatedMouseEvents: false,
|
|
191
193
|
ignoreClickAfterPress: false,
|
|
192
194
|
didFirePressStart: false,
|
|
195
|
+
isTriggeringEvent: false,
|
|
193
196
|
activePointerId: null,
|
|
194
197
|
target: null,
|
|
195
198
|
isOverTarget: false,
|
|
@@ -200,12 +203,14 @@ function $0294ea432cd92340$export$45712eceda6fad21(props) {
|
|
|
200
203
|
let state = ref.current;
|
|
201
204
|
if (isDisabled || state.didFirePressStart) return;
|
|
202
205
|
let shouldStopPropagation = true;
|
|
206
|
+
state.isTriggeringEvent = true;
|
|
203
207
|
if (onPressStart) {
|
|
204
208
|
let event = new $0294ea432cd92340$var$PressEvent("pressstart", pointerType, originalEvent);
|
|
205
209
|
onPressStart(event);
|
|
206
210
|
shouldStopPropagation = event.shouldStopPropagation;
|
|
207
211
|
}
|
|
208
212
|
if (onPressChange) onPressChange(true);
|
|
213
|
+
state.isTriggeringEvent = false;
|
|
209
214
|
state.didFirePressStart = true;
|
|
210
215
|
setPressed(true);
|
|
211
216
|
return shouldStopPropagation;
|
|
@@ -215,6 +220,7 @@ function $0294ea432cd92340$export$45712eceda6fad21(props) {
|
|
|
215
220
|
if (!state.didFirePressStart) return;
|
|
216
221
|
state.ignoreClickAfterPress = true;
|
|
217
222
|
state.didFirePressStart = false;
|
|
223
|
+
state.isTriggeringEvent = true;
|
|
218
224
|
let shouldStopPropagation = true;
|
|
219
225
|
if (onPressEnd) {
|
|
220
226
|
let event = new $0294ea432cd92340$var$PressEvent("pressend", pointerType, originalEvent);
|
|
@@ -228,13 +234,17 @@ function $0294ea432cd92340$export$45712eceda6fad21(props) {
|
|
|
228
234
|
onPress(event);
|
|
229
235
|
shouldStopPropagation && (shouldStopPropagation = event.shouldStopPropagation);
|
|
230
236
|
}
|
|
237
|
+
state.isTriggeringEvent = false;
|
|
231
238
|
return shouldStopPropagation;
|
|
232
239
|
});
|
|
233
240
|
let triggerPressUp = (0, $goTMa$reactariautils.useEffectEvent)((originalEvent, pointerType)=>{
|
|
241
|
+
let state = ref.current;
|
|
234
242
|
if (isDisabled) return;
|
|
235
243
|
if (onPressUp) {
|
|
244
|
+
state.isTriggeringEvent = true;
|
|
236
245
|
let event = new $0294ea432cd92340$var$PressEvent("pressup", pointerType, originalEvent);
|
|
237
246
|
onPressUp(event);
|
|
247
|
+
state.isTriggeringEvent = false;
|
|
238
248
|
return event.shouldStopPropagation;
|
|
239
249
|
}
|
|
240
250
|
return true;
|
|
@@ -273,22 +283,27 @@ function $0294ea432cd92340$export$45712eceda6fad21(props) {
|
|
|
273
283
|
addGlobalListener(document, "keyup", onKeyUp, false);
|
|
274
284
|
}
|
|
275
285
|
if (shouldStopPropagation) e.stopPropagation();
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
286
|
+
// Keep track of the keydown events that occur while the Meta (e.g. Command) key is held.
|
|
287
|
+
// macOS has a bug where keyup events are not fired while the Meta key is down.
|
|
288
|
+
// When the Meta key itself is released we will get an event for that, and we'll act as if
|
|
289
|
+
// all of these other keys were released as well.
|
|
290
|
+
// https://bugs.chromium.org/p/chromium/issues/detail?id=1393524
|
|
291
|
+
// https://bugs.webkit.org/show_bug.cgi?id=55291
|
|
292
|
+
// https://bugzilla.mozilla.org/show_bug.cgi?id=1299553
|
|
293
|
+
if (e.metaKey && (0, $goTMa$reactariautils.isMac)()) state.metaKeyEvents.set(e.key, e.nativeEvent);
|
|
294
|
+
} else if (e.key === "Meta") state.metaKeyEvents = new Map();
|
|
280
295
|
},
|
|
281
296
|
onKeyUp (e) {
|
|
282
297
|
if ($0294ea432cd92340$var$isValidKeyboardEvent(e.nativeEvent, e.currentTarget) && !e.repeat && e.currentTarget.contains(e.target)) triggerPressUp($0294ea432cd92340$var$createEvent(state.target, e), "keyboard");
|
|
283
298
|
},
|
|
284
299
|
onClick (e) {
|
|
285
300
|
if (e && !e.currentTarget.contains(e.target)) return;
|
|
286
|
-
if (e && e.button === 0) {
|
|
301
|
+
if (e && e.button === 0 && !state.isTriggeringEvent && !(0, $goTMa$reactariautils.openLink).isOpening) {
|
|
287
302
|
let shouldStopPropagation = true;
|
|
288
303
|
if (isDisabled) e.preventDefault();
|
|
289
304
|
// If triggered from a screen reader or by using element.click(),
|
|
290
305
|
// trigger as if it were a keyboard click.
|
|
291
|
-
if (!state.ignoreClickAfterPress && !state.ignoreEmulatedMouseEvents && (state.pointerType === "virtual" || (0, $goTMa$reactariautils.isVirtualClick)(e.nativeEvent))) {
|
|
306
|
+
if (!state.ignoreClickAfterPress && !state.ignoreEmulatedMouseEvents && !state.isPressed && (state.pointerType === "virtual" || (0, $goTMa$reactariautils.isVirtualClick)(e.nativeEvent))) {
|
|
292
307
|
// Ensure the element receives focus (VoiceOver on iOS does not do this)
|
|
293
308
|
if (!isDisabled && !preventFocusOnPress) (0, $goTMa$reactariautils.focusWithoutScrolling)(e.currentTarget);
|
|
294
309
|
let stopPressStart = triggerPressStart(e, "virtual");
|
|
@@ -303,16 +318,32 @@ function $0294ea432cd92340$export$45712eceda6fad21(props) {
|
|
|
303
318
|
}
|
|
304
319
|
};
|
|
305
320
|
let onKeyUp = (e)=>{
|
|
321
|
+
var _state_metaKeyEvents;
|
|
306
322
|
if (state.isPressed && $0294ea432cd92340$var$isValidKeyboardEvent(e, state.target)) {
|
|
323
|
+
var _state_metaKeyEvents1;
|
|
307
324
|
if ($0294ea432cd92340$var$shouldPreventDefaultKeyboard(e.target, e.key)) e.preventDefault();
|
|
308
|
-
state.isPressed = false;
|
|
309
325
|
let target = e.target;
|
|
310
326
|
let shouldStopPropagation = triggerPressEnd($0294ea432cd92340$var$createEvent(state.target, e), "keyboard", state.target.contains(target));
|
|
311
327
|
removeAllGlobalListeners();
|
|
312
328
|
if (shouldStopPropagation) e.stopPropagation();
|
|
313
|
-
// If
|
|
314
|
-
//
|
|
315
|
-
|
|
329
|
+
// If a link was triggered with a key other than Enter, open the URL ourselves.
|
|
330
|
+
// This means the link has a role override, and the default browser behavior
|
|
331
|
+
// only applies when using the Enter key.
|
|
332
|
+
if (e.key !== "Enter" && $0294ea432cd92340$var$isHTMLAnchorLink(state.target) && state.target.contains(target) && !e[$0294ea432cd92340$var$LINK_CLICKED]) {
|
|
333
|
+
// Store a hidden property on the event so we only trigger link click once,
|
|
334
|
+
// even if there are multiple usePress instances attached to the element.
|
|
335
|
+
e[$0294ea432cd92340$var$LINK_CLICKED] = true;
|
|
336
|
+
(0, $goTMa$reactariautils.openLink)(state.target, e, false);
|
|
337
|
+
}
|
|
338
|
+
state.isPressed = false;
|
|
339
|
+
(_state_metaKeyEvents1 = state.metaKeyEvents) === null || _state_metaKeyEvents1 === void 0 ? void 0 : _state_metaKeyEvents1.delete(e.key);
|
|
340
|
+
} else if (e.key === "Meta" && ((_state_metaKeyEvents = state.metaKeyEvents) === null || _state_metaKeyEvents === void 0 ? void 0 : _state_metaKeyEvents.size)) {
|
|
341
|
+
// If we recorded keydown events that occurred while the Meta key was pressed,
|
|
342
|
+
// and those haven't received keyup events already, fire keyup events ourselves.
|
|
343
|
+
// See comment above for more info about the macOS bug causing this.
|
|
344
|
+
let events = state.metaKeyEvents;
|
|
345
|
+
state.metaKeyEvents = null;
|
|
346
|
+
for (let event of events.values())state.target.dispatchEvent(new KeyboardEvent("keyup", event));
|
|
316
347
|
}
|
|
317
348
|
};
|
|
318
349
|
if (typeof PointerEvent !== "undefined") {
|
|
@@ -441,7 +472,7 @@ function $0294ea432cd92340$export$45712eceda6fad21(props) {
|
|
|
441
472
|
};
|
|
442
473
|
pressProps.onMouseUp = (e)=>{
|
|
443
474
|
if (!e.currentTarget.contains(e.target)) return;
|
|
444
|
-
if (!state.ignoreEmulatedMouseEvents && e.button === 0) triggerPressUp(e, state.pointerType);
|
|
475
|
+
if (!state.ignoreEmulatedMouseEvents && e.button === 0) triggerPressUp(e, state.pointerType || "mouse");
|
|
445
476
|
};
|
|
446
477
|
let onMouseUp = (e)=>{
|
|
447
478
|
// Only handle left clicks
|
|
@@ -570,10 +601,8 @@ function $0294ea432cd92340$var$isValidKeyboardEvent(event, currentTarget) {
|
|
|
570
601
|
const role = element.getAttribute("role");
|
|
571
602
|
// Accessibility for keyboards. Space and Enter only.
|
|
572
603
|
// "Spacebar" is for IE 11
|
|
573
|
-
return (key === "Enter" || key === " " || key === "Spacebar" || code === "Space") && !(element instanceof HTMLInputElement && !$0294ea432cd92340$var$isValidInputKey(element, key) || element instanceof HTMLTextAreaElement || element.isContentEditable) && //
|
|
574
|
-
|
|
575
|
-
(!$0294ea432cd92340$var$isHTMLAnchorLink(element) || role === "button" && key !== "Enter") && // An element with role='link' should only trigger with Enter key
|
|
576
|
-
!(role === "link" && key !== "Enter");
|
|
604
|
+
return (key === "Enter" || key === " " || key === "Spacebar" || code === "Space") && !(element instanceof HTMLInputElement && !$0294ea432cd92340$var$isValidInputKey(element, key) || element instanceof HTMLTextAreaElement || element.isContentEditable) && // Links should only trigger with Enter key
|
|
605
|
+
!((role === "link" || !role && $0294ea432cd92340$var$isHTMLAnchorLink(element)) && key !== "Enter");
|
|
577
606
|
}
|
|
578
607
|
function $0294ea432cd92340$var$getTouchFromEvent(event) {
|
|
579
608
|
const { targetTouches: targetTouches } = event;
|
|
@@ -621,11 +650,12 @@ function $0294ea432cd92340$var$isOverTarget(point, target) {
|
|
|
621
650
|
}
|
|
622
651
|
function $0294ea432cd92340$var$shouldPreventDefault(target) {
|
|
623
652
|
// We cannot prevent default if the target is a draggable element.
|
|
624
|
-
return !(target instanceof HTMLElement) || !target.draggable;
|
|
653
|
+
return !(target instanceof HTMLElement) || !target.hasAttribute("draggable");
|
|
625
654
|
}
|
|
626
655
|
function $0294ea432cd92340$var$shouldPreventDefaultKeyboard(target, key) {
|
|
627
656
|
if (target instanceof HTMLInputElement) return !$0294ea432cd92340$var$isValidInputKey(target, key);
|
|
628
657
|
if (target instanceof HTMLButtonElement) return target.type !== "submit" && target.type !== "reset";
|
|
658
|
+
if ($0294ea432cd92340$var$isHTMLAnchorLink(target)) return false;
|
|
629
659
|
return true;
|
|
630
660
|
}
|
|
631
661
|
const $0294ea432cd92340$var$nonTextInputTypes = new Set([
|
|
@@ -697,6 +727,11 @@ const $3596bae48579386f$export$3351871ee4b288b8 = /*#__PURE__*/ (0, ($parcel$int
|
|
|
697
727
|
value: context
|
|
698
728
|
}, children);
|
|
699
729
|
});
|
|
730
|
+
function $3596bae48579386f$export$cf75428e0b9ed1ea({ children: children }) {
|
|
731
|
+
return /*#__PURE__*/ (0, ($parcel$interopDefault($goTMa$react))).createElement((0, $01d3f539e91688c8$export$5165eccb35aaadb5).Provider, {
|
|
732
|
+
value: undefined
|
|
733
|
+
}, children);
|
|
734
|
+
}
|
|
700
735
|
|
|
701
736
|
|
|
702
737
|
/*
|