@react-aria/interactions 3.16.0 → 3.17.0

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/module.js CHANGED
@@ -1,5 +1,8 @@
1
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, isMac as $bx7SL$isMac, 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
+ import {_ as $bx7SL$_} from "@swc/helpers/_/_class_private_field_get";
4
+ import {_ as $bx7SL$_1} from "@swc/helpers/_/_class_private_field_init";
5
+ import {_ as $bx7SL$_2} from "@swc/helpers/_/_class_private_field_set";
3
6
  import {useIsSSR as $bx7SL$useIsSSR} from "@react-aria/ssr";
4
7
 
5
8
  /*
@@ -37,6 +40,9 @@ import {useIsSSR as $bx7SL$useIsSSR} from "@react-aria/ssr";
37
40
  // Original licensing for the following can be found in the
38
41
  // NOTICE file in the root directory of this source tree.
39
42
  // See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
43
+
44
+
45
+
40
46
  /*
41
47
  * Copyright 2020 Adobe. All rights reserved.
42
48
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
@@ -128,6 +134,29 @@ function $f6c31cce2adf654f$var$usePressResponderContext(props) {
128
134
  (0, $bx7SL$useSyncRef)(context, props.ref);
129
135
  return props;
130
136
  }
137
+ var $f6c31cce2adf654f$var$_shouldStopPropagation = /*#__PURE__*/ new WeakMap();
138
+ class $f6c31cce2adf654f$var$PressEvent {
139
+ continuePropagation() {
140
+ (0, $bx7SL$_2)(this, $f6c31cce2adf654f$var$_shouldStopPropagation, false);
141
+ }
142
+ get shouldStopPropagation() {
143
+ return (0, $bx7SL$_)(this, $f6c31cce2adf654f$var$_shouldStopPropagation);
144
+ }
145
+ constructor(type, pointerType, originalEvent){
146
+ (0, $bx7SL$_1)(this, $f6c31cce2adf654f$var$_shouldStopPropagation, {
147
+ writable: true,
148
+ value: void 0
149
+ });
150
+ (0, $bx7SL$_2)(this, $f6c31cce2adf654f$var$_shouldStopPropagation, true);
151
+ this.type = type;
152
+ this.pointerType = pointerType;
153
+ this.target = originalEvent.currentTarget;
154
+ this.shiftKey = originalEvent.shiftKey;
155
+ this.metaKey = originalEvent.metaKey;
156
+ this.ctrlKey = originalEvent.ctrlKey;
157
+ this.altKey = originalEvent.altKey;
158
+ }
159
+ }
131
160
  function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
132
161
  let { onPress: onPress , onPressChange: onPressChange , onPressStart: onPressStart , onPressEnd: onPressEnd , onPressUp: onPressUp , isDisabled: isDisabled , isPressed: isPressedProp , preventFocusOnPress: preventFocusOnPress , shouldCancelOnPointerExit: shouldCancelOnPointerExit , allowTextSelectionOnPress: allowTextSelectionOnPress , // eslint-disable-next-line @typescript-eslint/no-unused-vars
133
162
  ref: _ , ...domProps } = $f6c31cce2adf654f$var$usePressResponderContext(props);
@@ -146,56 +175,45 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
146
175
  let triggerPressStart = (0, $bx7SL$useEffectEvent)((originalEvent, pointerType)=>{
147
176
  let state = ref.current;
148
177
  if (isDisabled || state.didFirePressStart) return;
149
- if (onPressStart) onPressStart({
150
- type: "pressstart",
151
- pointerType: pointerType,
152
- target: originalEvent.currentTarget,
153
- shiftKey: originalEvent.shiftKey,
154
- metaKey: originalEvent.metaKey,
155
- ctrlKey: originalEvent.ctrlKey,
156
- altKey: originalEvent.altKey
157
- });
178
+ let shouldStopPropagation = true;
179
+ if (onPressStart) {
180
+ let event = new $f6c31cce2adf654f$var$PressEvent("pressstart", pointerType, originalEvent);
181
+ onPressStart(event);
182
+ shouldStopPropagation = event.shouldStopPropagation;
183
+ }
158
184
  if (onPressChange) onPressChange(true);
159
185
  state.didFirePressStart = true;
160
186
  setPressed(true);
187
+ return shouldStopPropagation;
161
188
  });
162
189
  let triggerPressEnd = (0, $bx7SL$useEffectEvent)((originalEvent, pointerType, wasPressed = true)=>{
163
190
  let state = ref.current;
164
191
  if (!state.didFirePressStart) return;
165
192
  state.ignoreClickAfterPress = true;
166
193
  state.didFirePressStart = false;
167
- if (onPressEnd) onPressEnd({
168
- type: "pressend",
169
- pointerType: pointerType,
170
- target: originalEvent.currentTarget,
171
- shiftKey: originalEvent.shiftKey,
172
- metaKey: originalEvent.metaKey,
173
- ctrlKey: originalEvent.ctrlKey,
174
- altKey: originalEvent.altKey
175
- });
194
+ let shouldStopPropagation = true;
195
+ if (onPressEnd) {
196
+ let event = new $f6c31cce2adf654f$var$PressEvent("pressend", pointerType, originalEvent);
197
+ onPressEnd(event);
198
+ shouldStopPropagation = event.shouldStopPropagation;
199
+ }
176
200
  if (onPressChange) onPressChange(false);
177
201
  setPressed(false);
178
- if (onPress && wasPressed && !isDisabled) onPress({
179
- type: "press",
180
- pointerType: pointerType,
181
- target: originalEvent.currentTarget,
182
- shiftKey: originalEvent.shiftKey,
183
- metaKey: originalEvent.metaKey,
184
- ctrlKey: originalEvent.ctrlKey,
185
- altKey: originalEvent.altKey
186
- });
202
+ if (onPress && wasPressed && !isDisabled) {
203
+ let event = new $f6c31cce2adf654f$var$PressEvent("press", pointerType, originalEvent);
204
+ onPress(event);
205
+ shouldStopPropagation && (shouldStopPropagation = event.shouldStopPropagation);
206
+ }
207
+ return shouldStopPropagation;
187
208
  });
188
209
  let triggerPressUp = (0, $bx7SL$useEffectEvent)((originalEvent, pointerType)=>{
189
210
  if (isDisabled) return;
190
- if (onPressUp) onPressUp({
191
- type: "pressup",
192
- pointerType: pointerType,
193
- target: originalEvent.currentTarget,
194
- shiftKey: originalEvent.shiftKey,
195
- metaKey: originalEvent.metaKey,
196
- ctrlKey: originalEvent.ctrlKey,
197
- altKey: originalEvent.altKey
198
- });
211
+ if (onPressUp) {
212
+ let event = new $f6c31cce2adf654f$var$PressEvent("pressup", pointerType, originalEvent);
213
+ onPressUp(event);
214
+ return event.shouldStopPropagation;
215
+ }
216
+ return true;
199
217
  });
200
218
  let cancel = (0, $bx7SL$useEffectEvent)((e)=>{
201
219
  let state = ref.current;
@@ -218,18 +236,19 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
218
236
  onKeyDown (e) {
219
237
  if ($f6c31cce2adf654f$var$isValidKeyboardEvent(e.nativeEvent, e.currentTarget) && e.currentTarget.contains(e.target)) {
220
238
  if ($f6c31cce2adf654f$var$shouldPreventDefaultKeyboard(e.target, e.key)) e.preventDefault();
221
- e.stopPropagation();
222
239
  // If the event is repeating, it may have started on a different element
223
240
  // after which focus moved to the current element. Ignore these events and
224
241
  // only handle the first key down event.
242
+ let shouldStopPropagation = true;
225
243
  if (!state.isPressed && !e.repeat) {
226
244
  state.target = e.currentTarget;
227
245
  state.isPressed = true;
228
- triggerPressStart(e, "keyboard");
246
+ shouldStopPropagation = triggerPressStart(e, "keyboard");
229
247
  // Focus may move before the key up event, so register the event on the document
230
248
  // instead of the same element where the key down event occurred.
231
249
  addGlobalListener(document, "keyup", onKeyUp, false);
232
250
  }
251
+ if (shouldStopPropagation) e.stopPropagation();
233
252
  } else if (e.key === "Enter" && $f6c31cce2adf654f$var$isHTMLAnchorLink(e.currentTarget)) // If the target is a link, we won't have handled this above because we want the default
234
253
  // browser behavior to open the link when pressing Enter. But we still need to prevent
235
254
  // default so that elements above do not also handle it (e.g. table row).
@@ -241,30 +260,32 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
241
260
  onClick (e) {
242
261
  if (e && !e.currentTarget.contains(e.target)) return;
243
262
  if (e && e.button === 0) {
244
- e.stopPropagation();
263
+ let shouldStopPropagation = true;
245
264
  if (isDisabled) e.preventDefault();
246
265
  // If triggered from a screen reader or by using element.click(),
247
266
  // trigger as if it were a keyboard click.
248
267
  if (!state.ignoreClickAfterPress && !state.ignoreEmulatedMouseEvents && (state.pointerType === "virtual" || (0, $bx7SL$isVirtualClick)(e.nativeEvent))) {
249
268
  // Ensure the element receives focus (VoiceOver on iOS does not do this)
250
269
  if (!isDisabled && !preventFocusOnPress) (0, $bx7SL$focusWithoutScrolling)(e.currentTarget);
251
- triggerPressStart(e, "virtual");
252
- triggerPressUp(e, "virtual");
253
- triggerPressEnd(e, "virtual");
270
+ let stopPressStart = triggerPressStart(e, "virtual");
271
+ let stopPressUp = triggerPressUp(e, "virtual");
272
+ let stopPressEnd = triggerPressEnd(e, "virtual");
273
+ shouldStopPropagation = stopPressStart && stopPressUp && stopPressEnd;
254
274
  }
255
275
  state.ignoreEmulatedMouseEvents = false;
256
276
  state.ignoreClickAfterPress = false;
277
+ if (shouldStopPropagation) e.stopPropagation();
257
278
  }
258
279
  }
259
280
  };
260
281
  let onKeyUp = (e)=>{
261
282
  if (state.isPressed && $f6c31cce2adf654f$var$isValidKeyboardEvent(e, state.target)) {
262
283
  if ($f6c31cce2adf654f$var$shouldPreventDefaultKeyboard(e.target, e.key)) e.preventDefault();
263
- e.stopPropagation();
264
284
  state.isPressed = false;
265
285
  let target = e.target;
266
- triggerPressEnd($f6c31cce2adf654f$var$createEvent(state.target, e), "keyboard", state.target.contains(target));
286
+ let shouldStopPropagation = triggerPressEnd($f6c31cce2adf654f$var$createEvent(state.target, e), "keyboard", state.target.contains(target));
267
287
  removeAllGlobalListeners();
288
+ if (shouldStopPropagation) e.stopPropagation();
268
289
  // If the target is a link, trigger the click method to open the URL,
269
290
  // but defer triggering pressEnd until onClick event handler.
270
291
  if (state.target instanceof HTMLElement && state.target.contains(target) && ($f6c31cce2adf654f$var$isHTMLAnchorLink(state.target) || state.target.getAttribute("role") === "link")) state.target.click();
@@ -286,7 +307,7 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
286
307
  // default on pointer down and handle focusing the pressable element ourselves.
287
308
  if ($f6c31cce2adf654f$var$shouldPreventDefault(e.currentTarget)) e.preventDefault();
288
309
  state.pointerType = e.pointerType;
289
- e.stopPropagation();
310
+ let shouldStopPropagation = true;
290
311
  if (!state.isPressed) {
291
312
  state.isPressed = true;
292
313
  state.isOverTarget = true;
@@ -294,11 +315,12 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
294
315
  state.target = e.currentTarget;
295
316
  if (!isDisabled && !preventFocusOnPress) (0, $bx7SL$focusWithoutScrolling)(e.currentTarget);
296
317
  if (!allowTextSelectionOnPress) (0, $14c0b72509d70225$export$16a4697467175487)(state.target);
297
- triggerPressStart(e, state.pointerType);
318
+ shouldStopPropagation = triggerPressStart(e, state.pointerType);
298
319
  addGlobalListener(document, "pointermove", onPointerMove, false);
299
320
  addGlobalListener(document, "pointerup", onPointerUp, false);
300
321
  addGlobalListener(document, "pointercancel", onPointerCancel, false);
301
322
  }
323
+ if (shouldStopPropagation) e.stopPropagation();
302
324
  };
303
325
  pressProps.onMouseDown = (e)=>{
304
326
  if (!e.currentTarget.contains(e.target)) return;
@@ -361,32 +383,37 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
361
383
  // Due to browser inconsistencies, especially on mobile browsers, we prevent
362
384
  // default on mouse down and handle focusing the pressable element ourselves.
363
385
  if ($f6c31cce2adf654f$var$shouldPreventDefault(e.currentTarget)) e.preventDefault();
364
- e.stopPropagation();
365
- if (state.ignoreEmulatedMouseEvents) return;
386
+ if (state.ignoreEmulatedMouseEvents) {
387
+ e.stopPropagation();
388
+ return;
389
+ }
366
390
  state.isPressed = true;
367
391
  state.isOverTarget = true;
368
392
  state.target = e.currentTarget;
369
393
  state.pointerType = (0, $bx7SL$isVirtualClick)(e.nativeEvent) ? "virtual" : "mouse";
370
394
  if (!isDisabled && !preventFocusOnPress) (0, $bx7SL$focusWithoutScrolling)(e.currentTarget);
371
- triggerPressStart(e, state.pointerType);
395
+ let shouldStopPropagation = triggerPressStart(e, state.pointerType);
396
+ if (shouldStopPropagation) e.stopPropagation();
372
397
  addGlobalListener(document, "mouseup", onMouseUp, false);
373
398
  };
374
399
  pressProps.onMouseEnter = (e)=>{
375
400
  if (!e.currentTarget.contains(e.target)) return;
376
- e.stopPropagation();
401
+ let shouldStopPropagation = true;
377
402
  if (state.isPressed && !state.ignoreEmulatedMouseEvents) {
378
403
  state.isOverTarget = true;
379
- triggerPressStart(e, state.pointerType);
404
+ shouldStopPropagation = triggerPressStart(e, state.pointerType);
380
405
  }
406
+ if (shouldStopPropagation) e.stopPropagation();
381
407
  };
382
408
  pressProps.onMouseLeave = (e)=>{
383
409
  if (!e.currentTarget.contains(e.target)) return;
384
- e.stopPropagation();
410
+ let shouldStopPropagation = true;
385
411
  if (state.isPressed && !state.ignoreEmulatedMouseEvents) {
386
412
  state.isOverTarget = false;
387
- triggerPressEnd(e, state.pointerType, false);
413
+ shouldStopPropagation = triggerPressEnd(e, state.pointerType, false);
388
414
  cancelOnPointerExit(e);
389
415
  }
416
+ if (shouldStopPropagation) e.stopPropagation();
390
417
  };
391
418
  pressProps.onMouseUp = (e)=>{
392
419
  if (!e.currentTarget.contains(e.target)) return;
@@ -407,7 +434,6 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
407
434
  };
408
435
  pressProps.onTouchStart = (e)=>{
409
436
  if (!e.currentTarget.contains(e.target)) return;
410
- e.stopPropagation();
411
437
  let touch = $f6c31cce2adf654f$var$getTouchFromEvent(e.nativeEvent);
412
438
  if (!touch) return;
413
439
  state.activePointerId = touch.identifier;
@@ -420,34 +446,43 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
420
446
  // on the emulated mouse event and handle focusing the pressable element ourselves.
421
447
  if (!isDisabled && !preventFocusOnPress) (0, $bx7SL$focusWithoutScrolling)(e.currentTarget);
422
448
  if (!allowTextSelectionOnPress) (0, $14c0b72509d70225$export$16a4697467175487)(state.target);
423
- triggerPressStart(e, state.pointerType);
449
+ let shouldStopPropagation = triggerPressStart(e, state.pointerType);
450
+ if (shouldStopPropagation) e.stopPropagation();
424
451
  addGlobalListener(window, "scroll", onScroll, true);
425
452
  };
426
453
  pressProps.onTouchMove = (e)=>{
427
454
  if (!e.currentTarget.contains(e.target)) return;
428
- e.stopPropagation();
429
- if (!state.isPressed) return;
455
+ if (!state.isPressed) {
456
+ e.stopPropagation();
457
+ return;
458
+ }
430
459
  let touch = $f6c31cce2adf654f$var$getTouchById(e.nativeEvent, state.activePointerId);
460
+ let shouldStopPropagation = true;
431
461
  if (touch && $f6c31cce2adf654f$var$isOverTarget(touch, e.currentTarget)) {
432
462
  if (!state.isOverTarget) {
433
463
  state.isOverTarget = true;
434
- triggerPressStart(e, state.pointerType);
464
+ shouldStopPropagation = triggerPressStart(e, state.pointerType);
435
465
  }
436
466
  } else if (state.isOverTarget) {
437
467
  state.isOverTarget = false;
438
- triggerPressEnd(e, state.pointerType, false);
468
+ shouldStopPropagation = triggerPressEnd(e, state.pointerType, false);
439
469
  cancelOnPointerExit(e);
440
470
  }
471
+ if (shouldStopPropagation) e.stopPropagation();
441
472
  };
442
473
  pressProps.onTouchEnd = (e)=>{
443
474
  if (!e.currentTarget.contains(e.target)) return;
444
- e.stopPropagation();
445
- if (!state.isPressed) return;
475
+ if (!state.isPressed) {
476
+ e.stopPropagation();
477
+ return;
478
+ }
446
479
  let touch = $f6c31cce2adf654f$var$getTouchById(e.nativeEvent, state.activePointerId);
480
+ let shouldStopPropagation = true;
447
481
  if (touch && $f6c31cce2adf654f$var$isOverTarget(touch, e.currentTarget)) {
448
482
  triggerPressUp(e, state.pointerType);
449
- triggerPressEnd(e, state.pointerType);
450
- } else if (state.isOverTarget) triggerPressEnd(e, state.pointerType, false);
483
+ shouldStopPropagation = triggerPressEnd(e, state.pointerType);
484
+ } else if (state.isOverTarget) shouldStopPropagation = triggerPressEnd(e, state.pointerType, false);
485
+ if (shouldStopPropagation) e.stopPropagation();
451
486
  state.isPressed = false;
452
487
  state.activePointerId = null;
453
488
  state.isOverTarget = false;
@@ -566,7 +601,7 @@ function $f6c31cce2adf654f$var$shouldPreventDefault(target) {
566
601
  }
567
602
  function $f6c31cce2adf654f$var$shouldPreventDefaultKeyboard(target, key) {
568
603
  if (target instanceof HTMLInputElement) return !$f6c31cce2adf654f$var$isValidInputKey(target, key);
569
- if (target instanceof HTMLButtonElement) return target.type !== "submit";
604
+ if (target instanceof HTMLButtonElement) return target.type !== "submit" && target.type !== "reset";
570
605
  return true;
571
606
  }
572
607
  const $f6c31cce2adf654f$var$nonTextInputTypes = new Set([
@@ -1584,6 +1619,7 @@ function $8a26561d2877236e$export$c24ed0104d07eab9(props) {
1584
1619
  let { pressProps: pressProps } = (0, $f6c31cce2adf654f$export$45712eceda6fad21)({
1585
1620
  isDisabled: isDisabled,
1586
1621
  onPressStart (e) {
1622
+ e.continuePropagation();
1587
1623
  if (e.pointerType === "mouse" || e.pointerType === "touch") {
1588
1624
  if (onLongPressStart) onLongPressStart({
1589
1625
  ...e,