@react-aria/dnd 3.0.0-alpha.7 → 3.0.0-alpha.8

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
@@ -347,6 +347,7 @@ class $67560de7c78cb232$var$DragSession {
347
347
  window.addEventListener('focus', this.onFocus, true);
348
348
  window.addEventListener('blur', this.onBlur, true);
349
349
  document.addEventListener('click', this.onClick, true);
350
+ document.addEventListener('pointerdown', this.onPointerDown, true);
350
351
  for (let event of $67560de7c78cb232$var$CANCELED_EVENTS)document.addEventListener(event, this.cancelEvent, true);
351
352
  this.mutationObserver = new MutationObserver(()=>this.updateValidDropTargets()
352
353
  );
@@ -358,6 +359,7 @@ class $67560de7c78cb232$var$DragSession {
358
359
  window.removeEventListener('focus', this.onFocus, true);
359
360
  window.removeEventListener('blur', this.onBlur, true);
360
361
  document.removeEventListener('click', this.onClick, true);
362
+ document.removeEventListener('pointerdown', this.onPointerDown, true);
361
363
  for (let event of $67560de7c78cb232$var$CANCELED_EVENTS)document.removeEventListener(event, this.cancelEvent, true);
362
364
  this.mutationObserver.disconnect();
363
365
  this.restoreAriaHidden();
@@ -407,19 +409,26 @@ class $67560de7c78cb232$var$DragSession {
407
409
  }
408
410
  onClick(e) {
409
411
  this.cancelEvent(e);
410
- if (e.detail !== 0) return;
411
- if (e.target === this.dragTarget.element) {
412
- this.cancel();
413
- return;
414
- }
415
- let dropTarget = this.validDropTargets.find((target)=>target.element.contains(e.target)
416
- );
417
- if (dropTarget) {
418
- let item = $67560de7c78cb232$var$dropItems.get(e.target);
419
- this.setCurrentDropTarget(dropTarget, item);
420
- this.drop(item);
412
+ if (e.detail === 0 || this.isVirtualClick) {
413
+ if (e.target === this.dragTarget.element) {
414
+ this.cancel();
415
+ return;
416
+ }
417
+ let dropTarget = this.validDropTargets.find((target)=>target.element.contains(e.target)
418
+ );
419
+ if (dropTarget) {
420
+ let item = $67560de7c78cb232$var$dropItems.get(e.target);
421
+ this.setCurrentDropTarget(dropTarget, item);
422
+ this.drop(item);
423
+ }
421
424
  }
422
425
  }
426
+ onPointerDown(e) {
427
+ // Android Talkback double tap has e.detail = 1 for onClick. Detect the virtual click in onPointerDown before onClick fires
428
+ // so we can properly perform cancel and drop operations.
429
+ this.cancelEvent(e);
430
+ this.isVirtualClick = $67560de7c78cb232$var$isVirtualPointerEvent(e);
431
+ }
423
432
  cancelEvent(e) {
424
433
  var ref;
425
434
  // Allow focusin and focusout on the drag target so focus ring works properly.
@@ -604,6 +613,7 @@ class $67560de7c78cb232$var$DragSession {
604
613
  this.onFocus = this.onFocus.bind(this);
605
614
  this.onBlur = this.onBlur.bind(this);
606
615
  this.onClick = this.onClick.bind(this);
616
+ this.onPointerDown = this.onPointerDown.bind(this);
607
617
  this.cancelEvent = this.cancelEvent.bind(this);
608
618
  }
609
619
  }
@@ -617,6 +627,14 @@ function $67560de7c78cb232$var$findValidDropTargets(options) {
617
627
  return true;
618
628
  });
619
629
  }
630
+ function $67560de7c78cb232$var$isVirtualPointerEvent(event) {
631
+ // If the pointer size is zero, then we assume it's from a screen reader.
632
+ // Android TalkBack double tap will sometimes return a event with width and height of 1
633
+ // and pointerType === 'mouse' so we need to check for a specific combination of event attributes.
634
+ // Cannot use "event.pressure === 0" as the sole check due to Safari pointer events always returning pressure === 0
635
+ // instead of .5, see https://bugs.webkit.org/show_bug.cgi?id=206216
636
+ return event.width === 0 && event.height === 0 || event.width === 1 && event.height === 1 && event.pressure === 0 && event.detail === 0;
637
+ }
620
638
 
621
639
 
622
640
 
@@ -858,6 +876,9 @@ function $8253ed7ece74b463$export$7941f8aafa4b6021(options) {
858
876
  x = size.width / 2;
859
877
  y = size.height / 2;
860
878
  }
879
+ // Rounding height to an even number prevents blurry preview seen on some screens
880
+ let height = 2 * Math.round(rect.height / 2);
881
+ node.style.height = `${height}px`;
861
882
  e1.dataTransfer.setDragImage(node, x, y);
862
883
  // Remove the preview from the DOM after a frame so the browser has time to paint.
863
884
  requestAnimationFrame(()=>{
@@ -1720,12 +1741,12 @@ function $fd98cf7cbf233429$export$b35afafff42da2d9(props, state) {
1720
1741
  }
1721
1742
  });
1722
1743
  let item = state.collection.getItem(props.key);
1723
- let numSelectedKeys = state.selectionManager.selectedKeys.size;
1744
+ let numKeysForDrag = state.getKeysForDrag(props.key).size;
1724
1745
  let isSelected = state.selectionManager.isSelected(props.key);
1725
1746
  let message;
1726
1747
  var ref;
1727
- if (isSelected && numSelectedKeys > 1) message = formatMessage('dragSelectedItems', {
1728
- count: numSelectedKeys
1748
+ if (isSelected && numKeysForDrag > 1) message = formatMessage('dragSelectedItems', {
1749
+ count: numKeysForDrag
1729
1750
  });
1730
1751
  else message = formatMessage('dragItem', {
1731
1752
  itemText: (ref = item === null || item === void 0 ? void 0 : item.textValue) !== null && ref !== void 0 ? ref : ''