@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/main.js CHANGED
@@ -1,5 +1,8 @@
1
1
  var $goTMa$reactariautils = require("@react-aria/utils");
2
2
  var $goTMa$react = require("react");
3
+ var $goTMa$swchelperscjs_class_private_field_getcjs = require("@swc/helpers/cjs/_class_private_field_get.cjs");
4
+ var $goTMa$swchelperscjs_class_private_field_initcjs = require("@swc/helpers/cjs/_class_private_field_init.cjs");
5
+ var $goTMa$swchelperscjs_class_private_field_setcjs = require("@swc/helpers/cjs/_class_private_field_set.cjs");
3
6
  var $goTMa$reactariassr = require("@react-aria/ssr");
4
7
 
5
8
  function $parcel$export(e, n, v, s) {
@@ -61,6 +64,9 @@ $parcel$export(module.exports, "useLongPress", () => $3cd7b5d0eebf0ca9$export$c2
61
64
  // Original licensing for the following can be found in the
62
65
  // NOTICE file in the root directory of this source tree.
63
66
  // See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
67
+
68
+
69
+
64
70
  /*
65
71
  * Copyright 2020 Adobe. All rights reserved.
66
72
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
@@ -152,6 +158,29 @@ function $0294ea432cd92340$var$usePressResponderContext(props) {
152
158
  (0, $goTMa$reactariautils.useSyncRef)(context, props.ref);
153
159
  return props;
154
160
  }
161
+ var $0294ea432cd92340$var$_shouldStopPropagation = /*#__PURE__*/ new WeakMap();
162
+ class $0294ea432cd92340$var$PressEvent {
163
+ continuePropagation() {
164
+ (0, $goTMa$swchelperscjs_class_private_field_setcjs._)(this, $0294ea432cd92340$var$_shouldStopPropagation, false);
165
+ }
166
+ get shouldStopPropagation() {
167
+ return (0, $goTMa$swchelperscjs_class_private_field_getcjs._)(this, $0294ea432cd92340$var$_shouldStopPropagation);
168
+ }
169
+ constructor(type, pointerType, originalEvent){
170
+ (0, $goTMa$swchelperscjs_class_private_field_initcjs._)(this, $0294ea432cd92340$var$_shouldStopPropagation, {
171
+ writable: true,
172
+ value: void 0
173
+ });
174
+ (0, $goTMa$swchelperscjs_class_private_field_setcjs._)(this, $0294ea432cd92340$var$_shouldStopPropagation, true);
175
+ this.type = type;
176
+ this.pointerType = pointerType;
177
+ this.target = originalEvent.currentTarget;
178
+ this.shiftKey = originalEvent.shiftKey;
179
+ this.metaKey = originalEvent.metaKey;
180
+ this.ctrlKey = originalEvent.ctrlKey;
181
+ this.altKey = originalEvent.altKey;
182
+ }
183
+ }
155
184
  function $0294ea432cd92340$export$45712eceda6fad21(props) {
156
185
  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
157
186
  ref: _ , ...domProps } = $0294ea432cd92340$var$usePressResponderContext(props);
@@ -170,56 +199,45 @@ function $0294ea432cd92340$export$45712eceda6fad21(props) {
170
199
  let triggerPressStart = (0, $goTMa$reactariautils.useEffectEvent)((originalEvent, pointerType)=>{
171
200
  let state = ref.current;
172
201
  if (isDisabled || state.didFirePressStart) return;
173
- if (onPressStart) onPressStart({
174
- type: "pressstart",
175
- pointerType: pointerType,
176
- target: originalEvent.currentTarget,
177
- shiftKey: originalEvent.shiftKey,
178
- metaKey: originalEvent.metaKey,
179
- ctrlKey: originalEvent.ctrlKey,
180
- altKey: originalEvent.altKey
181
- });
202
+ let shouldStopPropagation = true;
203
+ if (onPressStart) {
204
+ let event = new $0294ea432cd92340$var$PressEvent("pressstart", pointerType, originalEvent);
205
+ onPressStart(event);
206
+ shouldStopPropagation = event.shouldStopPropagation;
207
+ }
182
208
  if (onPressChange) onPressChange(true);
183
209
  state.didFirePressStart = true;
184
210
  setPressed(true);
211
+ return shouldStopPropagation;
185
212
  });
186
213
  let triggerPressEnd = (0, $goTMa$reactariautils.useEffectEvent)((originalEvent, pointerType, wasPressed = true)=>{
187
214
  let state = ref.current;
188
215
  if (!state.didFirePressStart) return;
189
216
  state.ignoreClickAfterPress = true;
190
217
  state.didFirePressStart = false;
191
- if (onPressEnd) onPressEnd({
192
- type: "pressend",
193
- pointerType: pointerType,
194
- target: originalEvent.currentTarget,
195
- shiftKey: originalEvent.shiftKey,
196
- metaKey: originalEvent.metaKey,
197
- ctrlKey: originalEvent.ctrlKey,
198
- altKey: originalEvent.altKey
199
- });
218
+ let shouldStopPropagation = true;
219
+ if (onPressEnd) {
220
+ let event = new $0294ea432cd92340$var$PressEvent("pressend", pointerType, originalEvent);
221
+ onPressEnd(event);
222
+ shouldStopPropagation = event.shouldStopPropagation;
223
+ }
200
224
  if (onPressChange) onPressChange(false);
201
225
  setPressed(false);
202
- if (onPress && wasPressed && !isDisabled) onPress({
203
- type: "press",
204
- pointerType: pointerType,
205
- target: originalEvent.currentTarget,
206
- shiftKey: originalEvent.shiftKey,
207
- metaKey: originalEvent.metaKey,
208
- ctrlKey: originalEvent.ctrlKey,
209
- altKey: originalEvent.altKey
210
- });
226
+ if (onPress && wasPressed && !isDisabled) {
227
+ let event = new $0294ea432cd92340$var$PressEvent("press", pointerType, originalEvent);
228
+ onPress(event);
229
+ shouldStopPropagation && (shouldStopPropagation = event.shouldStopPropagation);
230
+ }
231
+ return shouldStopPropagation;
211
232
  });
212
233
  let triggerPressUp = (0, $goTMa$reactariautils.useEffectEvent)((originalEvent, pointerType)=>{
213
234
  if (isDisabled) return;
214
- if (onPressUp) onPressUp({
215
- type: "pressup",
216
- pointerType: pointerType,
217
- target: originalEvent.currentTarget,
218
- shiftKey: originalEvent.shiftKey,
219
- metaKey: originalEvent.metaKey,
220
- ctrlKey: originalEvent.ctrlKey,
221
- altKey: originalEvent.altKey
222
- });
235
+ if (onPressUp) {
236
+ let event = new $0294ea432cd92340$var$PressEvent("pressup", pointerType, originalEvent);
237
+ onPressUp(event);
238
+ return event.shouldStopPropagation;
239
+ }
240
+ return true;
223
241
  });
224
242
  let cancel = (0, $goTMa$reactariautils.useEffectEvent)((e)=>{
225
243
  let state = ref.current;
@@ -242,18 +260,19 @@ function $0294ea432cd92340$export$45712eceda6fad21(props) {
242
260
  onKeyDown (e) {
243
261
  if ($0294ea432cd92340$var$isValidKeyboardEvent(e.nativeEvent, e.currentTarget) && e.currentTarget.contains(e.target)) {
244
262
  if ($0294ea432cd92340$var$shouldPreventDefaultKeyboard(e.target, e.key)) e.preventDefault();
245
- e.stopPropagation();
246
263
  // If the event is repeating, it may have started on a different element
247
264
  // after which focus moved to the current element. Ignore these events and
248
265
  // only handle the first key down event.
266
+ let shouldStopPropagation = true;
249
267
  if (!state.isPressed && !e.repeat) {
250
268
  state.target = e.currentTarget;
251
269
  state.isPressed = true;
252
- triggerPressStart(e, "keyboard");
270
+ shouldStopPropagation = triggerPressStart(e, "keyboard");
253
271
  // Focus may move before the key up event, so register the event on the document
254
272
  // instead of the same element where the key down event occurred.
255
273
  addGlobalListener(document, "keyup", onKeyUp, false);
256
274
  }
275
+ if (shouldStopPropagation) e.stopPropagation();
257
276
  } else if (e.key === "Enter" && $0294ea432cd92340$var$isHTMLAnchorLink(e.currentTarget)) // If the target is a link, we won't have handled this above because we want the default
258
277
  // browser behavior to open the link when pressing Enter. But we still need to prevent
259
278
  // default so that elements above do not also handle it (e.g. table row).
@@ -265,30 +284,32 @@ function $0294ea432cd92340$export$45712eceda6fad21(props) {
265
284
  onClick (e) {
266
285
  if (e && !e.currentTarget.contains(e.target)) return;
267
286
  if (e && e.button === 0) {
268
- e.stopPropagation();
287
+ let shouldStopPropagation = true;
269
288
  if (isDisabled) e.preventDefault();
270
289
  // If triggered from a screen reader or by using element.click(),
271
290
  // trigger as if it were a keyboard click.
272
291
  if (!state.ignoreClickAfterPress && !state.ignoreEmulatedMouseEvents && (state.pointerType === "virtual" || (0, $goTMa$reactariautils.isVirtualClick)(e.nativeEvent))) {
273
292
  // Ensure the element receives focus (VoiceOver on iOS does not do this)
274
293
  if (!isDisabled && !preventFocusOnPress) (0, $goTMa$reactariautils.focusWithoutScrolling)(e.currentTarget);
275
- triggerPressStart(e, "virtual");
276
- triggerPressUp(e, "virtual");
277
- triggerPressEnd(e, "virtual");
294
+ let stopPressStart = triggerPressStart(e, "virtual");
295
+ let stopPressUp = triggerPressUp(e, "virtual");
296
+ let stopPressEnd = triggerPressEnd(e, "virtual");
297
+ shouldStopPropagation = stopPressStart && stopPressUp && stopPressEnd;
278
298
  }
279
299
  state.ignoreEmulatedMouseEvents = false;
280
300
  state.ignoreClickAfterPress = false;
301
+ if (shouldStopPropagation) e.stopPropagation();
281
302
  }
282
303
  }
283
304
  };
284
305
  let onKeyUp = (e)=>{
285
306
  if (state.isPressed && $0294ea432cd92340$var$isValidKeyboardEvent(e, state.target)) {
286
307
  if ($0294ea432cd92340$var$shouldPreventDefaultKeyboard(e.target, e.key)) e.preventDefault();
287
- e.stopPropagation();
288
308
  state.isPressed = false;
289
309
  let target = e.target;
290
- triggerPressEnd($0294ea432cd92340$var$createEvent(state.target, e), "keyboard", state.target.contains(target));
310
+ let shouldStopPropagation = triggerPressEnd($0294ea432cd92340$var$createEvent(state.target, e), "keyboard", state.target.contains(target));
291
311
  removeAllGlobalListeners();
312
+ if (shouldStopPropagation) e.stopPropagation();
292
313
  // If the target is a link, trigger the click method to open the URL,
293
314
  // but defer triggering pressEnd until onClick event handler.
294
315
  if (state.target instanceof HTMLElement && state.target.contains(target) && ($0294ea432cd92340$var$isHTMLAnchorLink(state.target) || state.target.getAttribute("role") === "link")) state.target.click();
@@ -310,7 +331,7 @@ function $0294ea432cd92340$export$45712eceda6fad21(props) {
310
331
  // default on pointer down and handle focusing the pressable element ourselves.
311
332
  if ($0294ea432cd92340$var$shouldPreventDefault(e.currentTarget)) e.preventDefault();
312
333
  state.pointerType = e.pointerType;
313
- e.stopPropagation();
334
+ let shouldStopPropagation = true;
314
335
  if (!state.isPressed) {
315
336
  state.isPressed = true;
316
337
  state.isOverTarget = true;
@@ -318,11 +339,12 @@ function $0294ea432cd92340$export$45712eceda6fad21(props) {
318
339
  state.target = e.currentTarget;
319
340
  if (!isDisabled && !preventFocusOnPress) (0, $goTMa$reactariautils.focusWithoutScrolling)(e.currentTarget);
320
341
  if (!allowTextSelectionOnPress) (0, $f7e14e656343df57$export$16a4697467175487)(state.target);
321
- triggerPressStart(e, state.pointerType);
342
+ shouldStopPropagation = triggerPressStart(e, state.pointerType);
322
343
  addGlobalListener(document, "pointermove", onPointerMove, false);
323
344
  addGlobalListener(document, "pointerup", onPointerUp, false);
324
345
  addGlobalListener(document, "pointercancel", onPointerCancel, false);
325
346
  }
347
+ if (shouldStopPropagation) e.stopPropagation();
326
348
  };
327
349
  pressProps.onMouseDown = (e)=>{
328
350
  if (!e.currentTarget.contains(e.target)) return;
@@ -385,32 +407,37 @@ function $0294ea432cd92340$export$45712eceda6fad21(props) {
385
407
  // Due to browser inconsistencies, especially on mobile browsers, we prevent
386
408
  // default on mouse down and handle focusing the pressable element ourselves.
387
409
  if ($0294ea432cd92340$var$shouldPreventDefault(e.currentTarget)) e.preventDefault();
388
- e.stopPropagation();
389
- if (state.ignoreEmulatedMouseEvents) return;
410
+ if (state.ignoreEmulatedMouseEvents) {
411
+ e.stopPropagation();
412
+ return;
413
+ }
390
414
  state.isPressed = true;
391
415
  state.isOverTarget = true;
392
416
  state.target = e.currentTarget;
393
417
  state.pointerType = (0, $goTMa$reactariautils.isVirtualClick)(e.nativeEvent) ? "virtual" : "mouse";
394
418
  if (!isDisabled && !preventFocusOnPress) (0, $goTMa$reactariautils.focusWithoutScrolling)(e.currentTarget);
395
- triggerPressStart(e, state.pointerType);
419
+ let shouldStopPropagation = triggerPressStart(e, state.pointerType);
420
+ if (shouldStopPropagation) e.stopPropagation();
396
421
  addGlobalListener(document, "mouseup", onMouseUp, false);
397
422
  };
398
423
  pressProps.onMouseEnter = (e)=>{
399
424
  if (!e.currentTarget.contains(e.target)) return;
400
- e.stopPropagation();
425
+ let shouldStopPropagation = true;
401
426
  if (state.isPressed && !state.ignoreEmulatedMouseEvents) {
402
427
  state.isOverTarget = true;
403
- triggerPressStart(e, state.pointerType);
428
+ shouldStopPropagation = triggerPressStart(e, state.pointerType);
404
429
  }
430
+ if (shouldStopPropagation) e.stopPropagation();
405
431
  };
406
432
  pressProps.onMouseLeave = (e)=>{
407
433
  if (!e.currentTarget.contains(e.target)) return;
408
- e.stopPropagation();
434
+ let shouldStopPropagation = true;
409
435
  if (state.isPressed && !state.ignoreEmulatedMouseEvents) {
410
436
  state.isOverTarget = false;
411
- triggerPressEnd(e, state.pointerType, false);
437
+ shouldStopPropagation = triggerPressEnd(e, state.pointerType, false);
412
438
  cancelOnPointerExit(e);
413
439
  }
440
+ if (shouldStopPropagation) e.stopPropagation();
414
441
  };
415
442
  pressProps.onMouseUp = (e)=>{
416
443
  if (!e.currentTarget.contains(e.target)) return;
@@ -431,7 +458,6 @@ function $0294ea432cd92340$export$45712eceda6fad21(props) {
431
458
  };
432
459
  pressProps.onTouchStart = (e)=>{
433
460
  if (!e.currentTarget.contains(e.target)) return;
434
- e.stopPropagation();
435
461
  let touch = $0294ea432cd92340$var$getTouchFromEvent(e.nativeEvent);
436
462
  if (!touch) return;
437
463
  state.activePointerId = touch.identifier;
@@ -444,34 +470,43 @@ function $0294ea432cd92340$export$45712eceda6fad21(props) {
444
470
  // on the emulated mouse event and handle focusing the pressable element ourselves.
445
471
  if (!isDisabled && !preventFocusOnPress) (0, $goTMa$reactariautils.focusWithoutScrolling)(e.currentTarget);
446
472
  if (!allowTextSelectionOnPress) (0, $f7e14e656343df57$export$16a4697467175487)(state.target);
447
- triggerPressStart(e, state.pointerType);
473
+ let shouldStopPropagation = triggerPressStart(e, state.pointerType);
474
+ if (shouldStopPropagation) e.stopPropagation();
448
475
  addGlobalListener(window, "scroll", onScroll, true);
449
476
  };
450
477
  pressProps.onTouchMove = (e)=>{
451
478
  if (!e.currentTarget.contains(e.target)) return;
452
- e.stopPropagation();
453
- if (!state.isPressed) return;
479
+ if (!state.isPressed) {
480
+ e.stopPropagation();
481
+ return;
482
+ }
454
483
  let touch = $0294ea432cd92340$var$getTouchById(e.nativeEvent, state.activePointerId);
484
+ let shouldStopPropagation = true;
455
485
  if (touch && $0294ea432cd92340$var$isOverTarget(touch, e.currentTarget)) {
456
486
  if (!state.isOverTarget) {
457
487
  state.isOverTarget = true;
458
- triggerPressStart(e, state.pointerType);
488
+ shouldStopPropagation = triggerPressStart(e, state.pointerType);
459
489
  }
460
490
  } else if (state.isOverTarget) {
461
491
  state.isOverTarget = false;
462
- triggerPressEnd(e, state.pointerType, false);
492
+ shouldStopPropagation = triggerPressEnd(e, state.pointerType, false);
463
493
  cancelOnPointerExit(e);
464
494
  }
495
+ if (shouldStopPropagation) e.stopPropagation();
465
496
  };
466
497
  pressProps.onTouchEnd = (e)=>{
467
498
  if (!e.currentTarget.contains(e.target)) return;
468
- e.stopPropagation();
469
- if (!state.isPressed) return;
499
+ if (!state.isPressed) {
500
+ e.stopPropagation();
501
+ return;
502
+ }
470
503
  let touch = $0294ea432cd92340$var$getTouchById(e.nativeEvent, state.activePointerId);
504
+ let shouldStopPropagation = true;
471
505
  if (touch && $0294ea432cd92340$var$isOverTarget(touch, e.currentTarget)) {
472
506
  triggerPressUp(e, state.pointerType);
473
- triggerPressEnd(e, state.pointerType);
474
- } else if (state.isOverTarget) triggerPressEnd(e, state.pointerType, false);
507
+ shouldStopPropagation = triggerPressEnd(e, state.pointerType);
508
+ } else if (state.isOverTarget) shouldStopPropagation = triggerPressEnd(e, state.pointerType, false);
509
+ if (shouldStopPropagation) e.stopPropagation();
475
510
  state.isPressed = false;
476
511
  state.activePointerId = null;
477
512
  state.isOverTarget = false;
@@ -590,7 +625,7 @@ function $0294ea432cd92340$var$shouldPreventDefault(target) {
590
625
  }
591
626
  function $0294ea432cd92340$var$shouldPreventDefaultKeyboard(target, key) {
592
627
  if (target instanceof HTMLInputElement) return !$0294ea432cd92340$var$isValidInputKey(target, key);
593
- if (target instanceof HTMLButtonElement) return target.type !== "submit";
628
+ if (target instanceof HTMLButtonElement) return target.type !== "submit" && target.type !== "reset";
594
629
  return true;
595
630
  }
596
631
  const $0294ea432cd92340$var$nonTextInputTypes = new Set([
@@ -1608,6 +1643,7 @@ function $3cd7b5d0eebf0ca9$export$c24ed0104d07eab9(props) {
1608
1643
  let { pressProps: pressProps } = (0, $0294ea432cd92340$export$45712eceda6fad21)({
1609
1644
  isDisabled: isDisabled,
1610
1645
  onPressStart (e) {
1646
+ e.continuePropagation();
1611
1647
  if (e.pointerType === "mouse" || e.pointerType === "touch") {
1612
1648
  if (onLongPressStart) onLongPressStart({
1613
1649
  ...e,