@react-aria/dnd 3.0.0-alpha.6 → 3.0.0-alpha.9
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 +99 -61
- package/dist/main.js.map +1 -1
- package/dist/module.js +96 -60
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +13 -9
- package/dist/types.d.ts.map +1 -1
- package/package.json +14 -14
- package/src/DragManager.ts +37 -13
- package/src/DragPreview.tsx +54 -0
- package/src/index.ts +3 -0
- package/src/useDrag.ts +23 -33
- package/src/useDraggableItem.ts +4 -6
- package/src/useDropIndicator.ts +2 -2
- package/src/useDroppableCollection.ts +2 -7
- package/src/useDroppableItem.ts +2 -2
package/dist/main.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
var $4vY0V$react = require("react");
|
|
2
|
-
var $4vY0V$reactdom = require("react-dom");
|
|
3
2
|
var $4vY0V$reactariautils = require("@react-aria/utils");
|
|
4
3
|
var $4vY0V$reactariai18n = require("@react-aria/i18n");
|
|
5
4
|
var $4vY0V$reactarialiveannouncer = require("@react-aria/live-announcer");
|
|
6
5
|
var $4vY0V$reactariaoverlays = require("@react-aria/overlays");
|
|
7
6
|
var $4vY0V$reactariainteractions = require("@react-aria/interactions");
|
|
7
|
+
var $4vY0V$reactdom = require("react-dom");
|
|
8
8
|
|
|
9
|
+
function $parcel$export(e, n, v, s) {
|
|
10
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
11
|
+
}
|
|
9
12
|
function $parcel$exportWildcard(dest, source) {
|
|
10
13
|
Object.keys(source).forEach(function(key) {
|
|
11
14
|
if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
|
|
@@ -25,9 +28,8 @@ function $parcel$exportWildcard(dest, source) {
|
|
|
25
28
|
function $parcel$interopDefault(a) {
|
|
26
29
|
return a && a.__esModule ? a.default : a;
|
|
27
30
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
+
|
|
32
|
+
$parcel$export(module.exports, "DragPreview", () => $2dccaca1f4baa446$export$905ab40ac2179daa);
|
|
31
33
|
var $dc204e8ec58447a6$exports = {};
|
|
32
34
|
|
|
33
35
|
$parcel$export($dc204e8ec58447a6$exports, "useDrag", () => $dc204e8ec58447a6$export$7941f8aafa4b6021);
|
|
@@ -363,6 +365,7 @@ class $28e10663603f5ea1$var$DragSession {
|
|
|
363
365
|
window.addEventListener('focus', this.onFocus, true);
|
|
364
366
|
window.addEventListener('blur', this.onBlur, true);
|
|
365
367
|
document.addEventListener('click', this.onClick, true);
|
|
368
|
+
document.addEventListener('pointerdown', this.onPointerDown, true);
|
|
366
369
|
for (let event of $28e10663603f5ea1$var$CANCELED_EVENTS)document.addEventListener(event, this.cancelEvent, true);
|
|
367
370
|
this.mutationObserver = new MutationObserver(()=>this.updateValidDropTargets()
|
|
368
371
|
);
|
|
@@ -374,6 +377,7 @@ class $28e10663603f5ea1$var$DragSession {
|
|
|
374
377
|
window.removeEventListener('focus', this.onFocus, true);
|
|
375
378
|
window.removeEventListener('blur', this.onBlur, true);
|
|
376
379
|
document.removeEventListener('click', this.onClick, true);
|
|
380
|
+
document.removeEventListener('pointerdown', this.onPointerDown, true);
|
|
377
381
|
for (let event of $28e10663603f5ea1$var$CANCELED_EVENTS)document.removeEventListener(event, this.cancelEvent, true);
|
|
378
382
|
this.mutationObserver.disconnect();
|
|
379
383
|
this.restoreAriaHidden();
|
|
@@ -423,19 +427,26 @@ class $28e10663603f5ea1$var$DragSession {
|
|
|
423
427
|
}
|
|
424
428
|
onClick(e) {
|
|
425
429
|
this.cancelEvent(e);
|
|
426
|
-
if (e.detail
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
430
|
+
if (e.detail === 0 || this.isVirtualClick) {
|
|
431
|
+
if (e.target === this.dragTarget.element) {
|
|
432
|
+
this.cancel();
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
let dropTarget = this.validDropTargets.find((target)=>target.element.contains(e.target)
|
|
436
|
+
);
|
|
437
|
+
if (dropTarget) {
|
|
438
|
+
let item = $28e10663603f5ea1$var$dropItems.get(e.target);
|
|
439
|
+
this.setCurrentDropTarget(dropTarget, item);
|
|
440
|
+
this.drop(item);
|
|
441
|
+
}
|
|
437
442
|
}
|
|
438
443
|
}
|
|
444
|
+
onPointerDown(e) {
|
|
445
|
+
// Android Talkback double tap has e.detail = 1 for onClick. Detect the virtual click in onPointerDown before onClick fires
|
|
446
|
+
// so we can properly perform cancel and drop operations.
|
|
447
|
+
this.cancelEvent(e);
|
|
448
|
+
this.isVirtualClick = $28e10663603f5ea1$var$isVirtualPointerEvent(e);
|
|
449
|
+
}
|
|
439
450
|
cancelEvent(e) {
|
|
440
451
|
var ref;
|
|
441
452
|
// Allow focusin and focusout on the drag target so focus ring works properly.
|
|
@@ -620,6 +631,7 @@ class $28e10663603f5ea1$var$DragSession {
|
|
|
620
631
|
this.onFocus = this.onFocus.bind(this);
|
|
621
632
|
this.onBlur = this.onBlur.bind(this);
|
|
622
633
|
this.onClick = this.onClick.bind(this);
|
|
634
|
+
this.onPointerDown = this.onPointerDown.bind(this);
|
|
623
635
|
this.cancelEvent = this.cancelEvent.bind(this);
|
|
624
636
|
}
|
|
625
637
|
}
|
|
@@ -633,6 +645,14 @@ function $28e10663603f5ea1$var$findValidDropTargets(options) {
|
|
|
633
645
|
return true;
|
|
634
646
|
});
|
|
635
647
|
}
|
|
648
|
+
function $28e10663603f5ea1$var$isVirtualPointerEvent(event) {
|
|
649
|
+
// If the pointer size is zero, then we assume it's from a screen reader.
|
|
650
|
+
// Android TalkBack double tap will sometimes return a event with width and height of 1
|
|
651
|
+
// and pointerType === 'mouse' so we need to check for a specific combination of event attributes.
|
|
652
|
+
// Cannot use "event.pressure === 0" as the sole check due to Safari pointer events always returning pressure === 0
|
|
653
|
+
// instead of .5, see https://bugs.webkit.org/show_bug.cgi?id=206216
|
|
654
|
+
return event.width === 0 && event.height === 0 || event.width === 1 && event.height === 1 && event.pressure === 0 && event.detail === 0;
|
|
655
|
+
}
|
|
636
656
|
|
|
637
657
|
|
|
638
658
|
|
|
@@ -815,7 +835,6 @@ $d624b4da796f302a$exports = {
|
|
|
815
835
|
|
|
816
836
|
|
|
817
837
|
|
|
818
|
-
|
|
819
838
|
const $dc204e8ec58447a6$var$MESSAGES = {
|
|
820
839
|
keyboard: {
|
|
821
840
|
start: 'dragDescriptionKeyboard',
|
|
@@ -841,6 +860,13 @@ function $dc204e8ec58447a6$export$7941f8aafa4b6021(options) {
|
|
|
841
860
|
let [isDragging, setDragging] = $4vY0V$react.useState(false);
|
|
842
861
|
let { addGlobalListener: addGlobalListener , removeAllGlobalListeners: removeAllGlobalListeners } = $4vY0V$reactariautils.useGlobalListeners();
|
|
843
862
|
let onDragStart = (e1)=>{
|
|
863
|
+
var ref;
|
|
864
|
+
if (e1.defaultPrevented) return;
|
|
865
|
+
if (typeof options.onDragStart === 'function') options.onDragStart({
|
|
866
|
+
type: 'dragstart',
|
|
867
|
+
x: e1.clientX,
|
|
868
|
+
y: e1.clientY
|
|
869
|
+
});
|
|
844
870
|
let items = options.getItems();
|
|
845
871
|
$4620ae0dc40f0031$export$f9c1490890ddd063(e1.dataTransfer, items);
|
|
846
872
|
if (typeof options.getAllowedDropOperations === 'function') {
|
|
@@ -849,38 +875,25 @@ function $dc204e8ec58447a6$export$7941f8aafa4b6021(options) {
|
|
|
849
875
|
for (let operation of allowedOperations)allowed |= $76b1e110a27b1ccd$export$60b7b4bcf3903d8e[operation] || $76b1e110a27b1ccd$export$60b7b4bcf3903d8e.none;
|
|
850
876
|
e1.dataTransfer.effectAllowed = $76b1e110a27b1ccd$export$dd0165308d8bff45[allowed] || 'none';
|
|
851
877
|
}
|
|
852
|
-
// If there is a
|
|
878
|
+
// If there is a preview option, use it to render a custom preview image that will
|
|
853
879
|
// appear under the pointer while dragging. If not, the element itself is dragged by the browser.
|
|
854
|
-
if (typeof options.
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
($parcel$interopDefault($4vY0V$reactdom)).render(preview, node);
|
|
866
|
-
// Compute the offset that the preview will appear under the mouse.
|
|
867
|
-
// If possible, this is based on the point the user clicked on the target.
|
|
868
|
-
// If the preview is much smaller, then just use the center point of the preview.
|
|
869
|
-
let size = node.getBoundingClientRect();
|
|
870
|
-
let rect = e1.currentTarget.getBoundingClientRect();
|
|
871
|
-
let x = e1.clientX - rect.x;
|
|
872
|
-
let y = e1.clientY - rect.y;
|
|
873
|
-
if (x > size.width || y > size.height) {
|
|
874
|
-
x = size.width / 2;
|
|
875
|
-
y = size.height / 2;
|
|
876
|
-
}
|
|
877
|
-
e1.dataTransfer.setDragImage(node, x, y);
|
|
878
|
-
// Remove the preview from the DOM after a frame so the browser has time to paint.
|
|
879
|
-
requestAnimationFrame(()=>{
|
|
880
|
-
document.body.removeChild(node);
|
|
881
|
-
});
|
|
880
|
+
if (typeof ((ref = options.preview) === null || ref === void 0 ? void 0 : ref.current) === 'function') options.preview.current(items, (node)=>{
|
|
881
|
+
// Compute the offset that the preview will appear under the mouse.
|
|
882
|
+
// If possible, this is based on the point the user clicked on the target.
|
|
883
|
+
// If the preview is much smaller, then just use the center point of the preview.
|
|
884
|
+
let size = node.getBoundingClientRect();
|
|
885
|
+
let rect = e1.currentTarget.getBoundingClientRect();
|
|
886
|
+
let x = e1.clientX - rect.x;
|
|
887
|
+
let y = e1.clientY - rect.y;
|
|
888
|
+
if (x > size.width || y > size.height) {
|
|
889
|
+
x = size.width / 2;
|
|
890
|
+
y = size.height / 2;
|
|
882
891
|
}
|
|
883
|
-
|
|
892
|
+
// Rounding height to an even number prevents blurry preview seen on some screens
|
|
893
|
+
let height = 2 * Math.round(rect.height / 2);
|
|
894
|
+
node.style.height = `${height}px`;
|
|
895
|
+
e1.dataTransfer.setDragImage(node, x, y);
|
|
896
|
+
});
|
|
884
897
|
// Enforce that drops are handled by useDrop.
|
|
885
898
|
addGlobalListener(window, 'drop', (e)=>{
|
|
886
899
|
if (!$28e10663603f5ea1$export$7454aff2e161f241(e.target)) {
|
|
@@ -892,11 +905,6 @@ function $dc204e8ec58447a6$export$7941f8aafa4b6021(options) {
|
|
|
892
905
|
capture: true,
|
|
893
906
|
once: true
|
|
894
907
|
});
|
|
895
|
-
if (typeof options.onDragStart === 'function') options.onDragStart({
|
|
896
|
-
type: 'dragstart',
|
|
897
|
-
x: e1.clientX,
|
|
898
|
-
y: e1.clientY
|
|
899
|
-
});
|
|
900
908
|
state.x = e1.clientX;
|
|
901
909
|
state.y = e1.clientY;
|
|
902
910
|
// Wait a frame before we set dragging to true so that the browser has time to
|
|
@@ -1269,10 +1277,6 @@ function $7f93a158ac20b90a$export$f4e2f423c21f7b04(props, state1, ref2) {
|
|
|
1269
1277
|
localState.nextTarget = null;
|
|
1270
1278
|
return 'cancel';
|
|
1271
1279
|
}
|
|
1272
|
-
if (state1.isDropTarget(target)) {
|
|
1273
|
-
localState.nextTarget = target;
|
|
1274
|
-
return localState.dropOperation;
|
|
1275
|
-
}
|
|
1276
1280
|
localState.dropOperation = state1.getDropOperation(target, types, allowedOperations);
|
|
1277
1281
|
// If the target doesn't accept the drop, see if the root accepts it instead.
|
|
1278
1282
|
if (localState.dropOperation === 'cancel') {
|
|
@@ -1722,9 +1726,7 @@ function $0cbbd00cda972c67$export$b35afafff42da2d9(props, state) {
|
|
|
1722
1726
|
getItems () {
|
|
1723
1727
|
return state.getItems(props.key);
|
|
1724
1728
|
},
|
|
1725
|
-
|
|
1726
|
-
return state.renderPreview(props.key);
|
|
1727
|
-
},
|
|
1729
|
+
preview: state.preview,
|
|
1728
1730
|
onDragStart (e) {
|
|
1729
1731
|
state.startDrag(props.key, e);
|
|
1730
1732
|
},
|
|
@@ -1736,12 +1738,12 @@ function $0cbbd00cda972c67$export$b35afafff42da2d9(props, state) {
|
|
|
1736
1738
|
}
|
|
1737
1739
|
});
|
|
1738
1740
|
let item = state.collection.getItem(props.key);
|
|
1739
|
-
let
|
|
1741
|
+
let numKeysForDrag = state.getKeysForDrag(props.key).size;
|
|
1740
1742
|
let isSelected = state.selectionManager.isSelected(props.key);
|
|
1741
1743
|
let message;
|
|
1742
1744
|
var ref;
|
|
1743
|
-
if (isSelected &&
|
|
1744
|
-
count:
|
|
1745
|
+
if (isSelected && numKeysForDrag > 1) message = formatMessage('dragSelectedItems', {
|
|
1746
|
+
count: numKeysForDrag
|
|
1745
1747
|
});
|
|
1746
1748
|
else message = formatMessage('dragItem', {
|
|
1747
1749
|
itemText: (ref = item === null || item === void 0 ? void 0 : item.textValue) !== null && ref !== void 0 ? ref : ''
|
|
@@ -1842,6 +1844,42 @@ function $74f3dedaa4d234b4$export$2314ca2a3e892862(options1) {
|
|
|
1842
1844
|
}
|
|
1843
1845
|
|
|
1844
1846
|
|
|
1847
|
+
|
|
1848
|
+
|
|
1849
|
+
function $2dccaca1f4baa446$var$DragPreview(props, ref) {
|
|
1850
|
+
let render = props.children;
|
|
1851
|
+
let [children, setChildren] = $4vY0V$react.useState(null);
|
|
1852
|
+
let domRef = $4vY0V$react.useRef(null);
|
|
1853
|
+
$4vY0V$react.useImperativeHandle(ref, ()=>(items, callback)=>{
|
|
1854
|
+
// This will be called during the onDragStart event by useDrag. We need to render the
|
|
1855
|
+
// preview synchronously before this event returns so we can call event.dataTransfer.setDragImage.
|
|
1856
|
+
$4vY0V$reactdom.flushSync(()=>{
|
|
1857
|
+
setChildren(render(items));
|
|
1858
|
+
});
|
|
1859
|
+
// Yield back to useDrag to set the drag image.
|
|
1860
|
+
callback(domRef.current);
|
|
1861
|
+
// Remove the preview from the DOM after a frame so the browser has time to paint.
|
|
1862
|
+
requestAnimationFrame(()=>{
|
|
1863
|
+
setChildren(null);
|
|
1864
|
+
});
|
|
1865
|
+
}
|
|
1866
|
+
, [
|
|
1867
|
+
render
|
|
1868
|
+
]);
|
|
1869
|
+
if (!children) return null;
|
|
1870
|
+
return(/*#__PURE__*/ ($parcel$interopDefault($4vY0V$react)).createElement("div", {
|
|
1871
|
+
style: {
|
|
1872
|
+
zIndex: -100,
|
|
1873
|
+
position: 'absolute',
|
|
1874
|
+
top: 0,
|
|
1875
|
+
left: -100000
|
|
1876
|
+
},
|
|
1877
|
+
ref: domRef
|
|
1878
|
+
}, children));
|
|
1879
|
+
}
|
|
1880
|
+
let $2dccaca1f4baa446$export$905ab40ac2179daa = /*#__PURE__*/ ($parcel$interopDefault($4vY0V$react)).forwardRef($2dccaca1f4baa446$var$DragPreview);
|
|
1881
|
+
|
|
1882
|
+
|
|
1845
1883
|
$parcel$exportWildcard(module.exports, $dc204e8ec58447a6$exports);
|
|
1846
1884
|
$parcel$exportWildcard(module.exports, $1ca228bc9257ca16$exports);
|
|
1847
1885
|
$parcel$exportWildcard(module.exports, $7f93a158ac20b90a$exports);
|