@react-aria/dnd 3.0.0-alpha.8 → 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 +67 -50
- package/dist/main.js.map +1 -1
- package/dist/module.js +64 -49
- 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/DragPreview.tsx +54 -0
- package/src/index.ts +3 -0
- package/src/useDrag.ts +20 -34
- package/src/useDraggableItem.ts +1 -3
- package/src/useDropIndicator.ts +2 -2
- package/src/useDroppableCollection.ts +2 -7
- package/src/useDroppableItem.ts +2 -2
package/dist/module.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {useRef as $fP8tg$useRef, useState as $fP8tg$useState, useEffect as $fP8tg$useEffect, useCallback as $fP8tg$useCallback} from "react";
|
|
2
|
-
import $fP8tg$reactdom from "react-dom";
|
|
1
|
+
import $fP8tg$react, {useRef as $fP8tg$useRef, useState as $fP8tg$useState, useEffect as $fP8tg$useEffect, useCallback as $fP8tg$useCallback, useImperativeHandle as $fP8tg$useImperativeHandle} from "react";
|
|
3
2
|
import {useGlobalListeners as $fP8tg$useGlobalListeners, useDescription as $fP8tg$useDescription, useId as $fP8tg$useId, useLayoutEffect as $fP8tg$useLayoutEffect, mergeProps as $fP8tg$mergeProps, getScrollParent as $fP8tg$getScrollParent, isWebKit as $fP8tg$isWebKit, isIOS as $fP8tg$isIOS, chain as $fP8tg$chain} from "@react-aria/utils";
|
|
4
3
|
import {useMessageFormatter as $fP8tg$useMessageFormatter} from "@react-aria/i18n";
|
|
5
4
|
import {announce as $fP8tg$announce} from "@react-aria/live-announcer";
|
|
6
5
|
import {ariaHideOutside as $fP8tg$ariaHideOutside} from "@react-aria/overlays";
|
|
7
6
|
import {useInteractionModality as $fP8tg$useInteractionModality, getInteractionModality as $fP8tg$getInteractionModality, setInteractionModality as $fP8tg$setInteractionModality, useFocus as $fP8tg$useFocus} from "@react-aria/interactions";
|
|
7
|
+
import {flushSync as $fP8tg$flushSync} from "react-dom";
|
|
8
8
|
|
|
9
9
|
function $parcel$interopDefault(a) {
|
|
10
10
|
return a && a.__esModule ? a.default : a;
|
|
@@ -817,7 +817,6 @@ $c530af5bd0e7e6c6$exports = {
|
|
|
817
817
|
|
|
818
818
|
|
|
819
819
|
|
|
820
|
-
|
|
821
820
|
const $8253ed7ece74b463$var$MESSAGES = {
|
|
822
821
|
keyboard: {
|
|
823
822
|
start: 'dragDescriptionKeyboard',
|
|
@@ -843,6 +842,13 @@ function $8253ed7ece74b463$export$7941f8aafa4b6021(options) {
|
|
|
843
842
|
let [isDragging, setDragging] = $fP8tg$useState(false);
|
|
844
843
|
let { addGlobalListener: addGlobalListener , removeAllGlobalListeners: removeAllGlobalListeners } = $fP8tg$useGlobalListeners();
|
|
845
844
|
let onDragStart = (e1)=>{
|
|
845
|
+
var ref;
|
|
846
|
+
if (e1.defaultPrevented) return;
|
|
847
|
+
if (typeof options.onDragStart === 'function') options.onDragStart({
|
|
848
|
+
type: 'dragstart',
|
|
849
|
+
x: e1.clientX,
|
|
850
|
+
y: e1.clientY
|
|
851
|
+
});
|
|
846
852
|
let items = options.getItems();
|
|
847
853
|
$7252cd45fc48c07c$export$f9c1490890ddd063(e1.dataTransfer, items);
|
|
848
854
|
if (typeof options.getAllowedDropOperations === 'function') {
|
|
@@ -851,41 +857,25 @@ function $8253ed7ece74b463$export$7941f8aafa4b6021(options) {
|
|
|
851
857
|
for (let operation of allowedOperations)allowed |= $103790afe9474d1c$export$60b7b4bcf3903d8e[operation] || $103790afe9474d1c$export$60b7b4bcf3903d8e.none;
|
|
852
858
|
e1.dataTransfer.effectAllowed = $103790afe9474d1c$export$dd0165308d8bff45[allowed] || 'none';
|
|
853
859
|
}
|
|
854
|
-
// If there is a
|
|
860
|
+
// If there is a preview option, use it to render a custom preview image that will
|
|
855
861
|
// appear under the pointer while dragging. If not, the element itself is dragged by the browser.
|
|
856
|
-
if (typeof options.
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
$fP8tg$reactdom.render(preview, node);
|
|
868
|
-
// Compute the offset that the preview will appear under the mouse.
|
|
869
|
-
// If possible, this is based on the point the user clicked on the target.
|
|
870
|
-
// If the preview is much smaller, then just use the center point of the preview.
|
|
871
|
-
let size = node.getBoundingClientRect();
|
|
872
|
-
let rect = e1.currentTarget.getBoundingClientRect();
|
|
873
|
-
let x = e1.clientX - rect.x;
|
|
874
|
-
let y = e1.clientY - rect.y;
|
|
875
|
-
if (x > size.width || y > size.height) {
|
|
876
|
-
x = size.width / 2;
|
|
877
|
-
y = size.height / 2;
|
|
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`;
|
|
882
|
-
e1.dataTransfer.setDragImage(node, x, y);
|
|
883
|
-
// Remove the preview from the DOM after a frame so the browser has time to paint.
|
|
884
|
-
requestAnimationFrame(()=>{
|
|
885
|
-
document.body.removeChild(node);
|
|
886
|
-
});
|
|
862
|
+
if (typeof ((ref = options.preview) === null || ref === void 0 ? void 0 : ref.current) === 'function') options.preview.current(items, (node)=>{
|
|
863
|
+
// Compute the offset that the preview will appear under the mouse.
|
|
864
|
+
// If possible, this is based on the point the user clicked on the target.
|
|
865
|
+
// If the preview is much smaller, then just use the center point of the preview.
|
|
866
|
+
let size = node.getBoundingClientRect();
|
|
867
|
+
let rect = e1.currentTarget.getBoundingClientRect();
|
|
868
|
+
let x = e1.clientX - rect.x;
|
|
869
|
+
let y = e1.clientY - rect.y;
|
|
870
|
+
if (x > size.width || y > size.height) {
|
|
871
|
+
x = size.width / 2;
|
|
872
|
+
y = size.height / 2;
|
|
887
873
|
}
|
|
888
|
-
|
|
874
|
+
// Rounding height to an even number prevents blurry preview seen on some screens
|
|
875
|
+
let height = 2 * Math.round(rect.height / 2);
|
|
876
|
+
node.style.height = `${height}px`;
|
|
877
|
+
e1.dataTransfer.setDragImage(node, x, y);
|
|
878
|
+
});
|
|
889
879
|
// Enforce that drops are handled by useDrop.
|
|
890
880
|
addGlobalListener(window, 'drop', (e)=>{
|
|
891
881
|
if (!$67560de7c78cb232$export$7454aff2e161f241(e.target)) {
|
|
@@ -897,11 +887,6 @@ function $8253ed7ece74b463$export$7941f8aafa4b6021(options) {
|
|
|
897
887
|
capture: true,
|
|
898
888
|
once: true
|
|
899
889
|
});
|
|
900
|
-
if (typeof options.onDragStart === 'function') options.onDragStart({
|
|
901
|
-
type: 'dragstart',
|
|
902
|
-
x: e1.clientX,
|
|
903
|
-
y: e1.clientY
|
|
904
|
-
});
|
|
905
890
|
state.x = e1.clientX;
|
|
906
891
|
state.y = e1.clientY;
|
|
907
892
|
// Wait a frame before we set dragging to true so that the browser has time to
|
|
@@ -1274,10 +1259,6 @@ function $4b52e4eff84e5217$export$f4e2f423c21f7b04(props, state1, ref2) {
|
|
|
1274
1259
|
localState.nextTarget = null;
|
|
1275
1260
|
return 'cancel';
|
|
1276
1261
|
}
|
|
1277
|
-
if (state1.isDropTarget(target)) {
|
|
1278
|
-
localState.nextTarget = target;
|
|
1279
|
-
return localState.dropOperation;
|
|
1280
|
-
}
|
|
1281
1262
|
localState.dropOperation = state1.getDropOperation(target, types, allowedOperations);
|
|
1282
1263
|
// If the target doesn't accept the drop, see if the root accepts it instead.
|
|
1283
1264
|
if (localState.dropOperation === 'cancel') {
|
|
@@ -1727,9 +1708,7 @@ function $fd98cf7cbf233429$export$b35afafff42da2d9(props, state) {
|
|
|
1727
1708
|
getItems () {
|
|
1728
1709
|
return state.getItems(props.key);
|
|
1729
1710
|
},
|
|
1730
|
-
|
|
1731
|
-
return state.renderPreview(props.key);
|
|
1732
|
-
},
|
|
1711
|
+
preview: state.preview,
|
|
1733
1712
|
onDragStart (e) {
|
|
1734
1713
|
state.startDrag(props.key, e);
|
|
1735
1714
|
},
|
|
@@ -1849,5 +1828,41 @@ function $9fcc7f0d70d084ee$export$2314ca2a3e892862(options1) {
|
|
|
1849
1828
|
|
|
1850
1829
|
|
|
1851
1830
|
|
|
1852
|
-
|
|
1831
|
+
function $ad0e3f3d9c50e4ba$var$DragPreview(props, ref) {
|
|
1832
|
+
let render = props.children;
|
|
1833
|
+
let [children, setChildren] = $fP8tg$useState(null);
|
|
1834
|
+
let domRef = $fP8tg$useRef(null);
|
|
1835
|
+
$fP8tg$useImperativeHandle(ref, ()=>(items, callback)=>{
|
|
1836
|
+
// This will be called during the onDragStart event by useDrag. We need to render the
|
|
1837
|
+
// preview synchronously before this event returns so we can call event.dataTransfer.setDragImage.
|
|
1838
|
+
$fP8tg$flushSync(()=>{
|
|
1839
|
+
setChildren(render(items));
|
|
1840
|
+
});
|
|
1841
|
+
// Yield back to useDrag to set the drag image.
|
|
1842
|
+
callback(domRef.current);
|
|
1843
|
+
// Remove the preview from the DOM after a frame so the browser has time to paint.
|
|
1844
|
+
requestAnimationFrame(()=>{
|
|
1845
|
+
setChildren(null);
|
|
1846
|
+
});
|
|
1847
|
+
}
|
|
1848
|
+
, [
|
|
1849
|
+
render
|
|
1850
|
+
]);
|
|
1851
|
+
if (!children) return null;
|
|
1852
|
+
return(/*#__PURE__*/ $fP8tg$react.createElement("div", {
|
|
1853
|
+
style: {
|
|
1854
|
+
zIndex: -100,
|
|
1855
|
+
position: 'absolute',
|
|
1856
|
+
top: 0,
|
|
1857
|
+
left: -100000
|
|
1858
|
+
},
|
|
1859
|
+
ref: domRef
|
|
1860
|
+
}, children));
|
|
1861
|
+
}
|
|
1862
|
+
let $ad0e3f3d9c50e4ba$export$905ab40ac2179daa = /*#__PURE__*/ $fP8tg$react.forwardRef($ad0e3f3d9c50e4ba$var$DragPreview);
|
|
1863
|
+
|
|
1864
|
+
|
|
1865
|
+
|
|
1866
|
+
|
|
1867
|
+
export {$ad0e3f3d9c50e4ba$export$905ab40ac2179daa as DragPreview, $8253ed7ece74b463$export$7941f8aafa4b6021 as useDrag, $5c06e4929e123553$export$ccdee5eaf73cf661 as useDrop, $4b52e4eff84e5217$export$f4e2f423c21f7b04 as useDroppableCollection, $bfaab576ce1c580e$export$f7b0c5d28b66b6a5 as useDroppableItem, $ddf25448c71fc93a$export$8d0e41d2815afac5 as useDropIndicator, $fd98cf7cbf233429$export$b35afafff42da2d9 as useDraggableItem, $9fcc7f0d70d084ee$export$2314ca2a3e892862 as useClipboard};
|
|
1853
1868
|
//# sourceMappingURL=module.js.map
|