@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/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);
|
|
@@ -833,7 +835,6 @@ $d624b4da796f302a$exports = {
|
|
|
833
835
|
|
|
834
836
|
|
|
835
837
|
|
|
836
|
-
|
|
837
838
|
const $dc204e8ec58447a6$var$MESSAGES = {
|
|
838
839
|
keyboard: {
|
|
839
840
|
start: 'dragDescriptionKeyboard',
|
|
@@ -859,6 +860,13 @@ function $dc204e8ec58447a6$export$7941f8aafa4b6021(options) {
|
|
|
859
860
|
let [isDragging, setDragging] = $4vY0V$react.useState(false);
|
|
860
861
|
let { addGlobalListener: addGlobalListener , removeAllGlobalListeners: removeAllGlobalListeners } = $4vY0V$reactariautils.useGlobalListeners();
|
|
861
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
|
+
});
|
|
862
870
|
let items = options.getItems();
|
|
863
871
|
$4620ae0dc40f0031$export$f9c1490890ddd063(e1.dataTransfer, items);
|
|
864
872
|
if (typeof options.getAllowedDropOperations === 'function') {
|
|
@@ -867,41 +875,25 @@ function $dc204e8ec58447a6$export$7941f8aafa4b6021(options) {
|
|
|
867
875
|
for (let operation of allowedOperations)allowed |= $76b1e110a27b1ccd$export$60b7b4bcf3903d8e[operation] || $76b1e110a27b1ccd$export$60b7b4bcf3903d8e.none;
|
|
868
876
|
e1.dataTransfer.effectAllowed = $76b1e110a27b1ccd$export$dd0165308d8bff45[allowed] || 'none';
|
|
869
877
|
}
|
|
870
|
-
// If there is a
|
|
878
|
+
// If there is a preview option, use it to render a custom preview image that will
|
|
871
879
|
// appear under the pointer while dragging. If not, the element itself is dragged by the browser.
|
|
872
|
-
if (typeof options.
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
($parcel$interopDefault($4vY0V$reactdom)).render(preview, node);
|
|
884
|
-
// Compute the offset that the preview will appear under the mouse.
|
|
885
|
-
// If possible, this is based on the point the user clicked on the target.
|
|
886
|
-
// If the preview is much smaller, then just use the center point of the preview.
|
|
887
|
-
let size = node.getBoundingClientRect();
|
|
888
|
-
let rect = e1.currentTarget.getBoundingClientRect();
|
|
889
|
-
let x = e1.clientX - rect.x;
|
|
890
|
-
let y = e1.clientY - rect.y;
|
|
891
|
-
if (x > size.width || y > size.height) {
|
|
892
|
-
x = size.width / 2;
|
|
893
|
-
y = size.height / 2;
|
|
894
|
-
}
|
|
895
|
-
// Rounding height to an even number prevents blurry preview seen on some screens
|
|
896
|
-
let height = 2 * Math.round(rect.height / 2);
|
|
897
|
-
node.style.height = `${height}px`;
|
|
898
|
-
e1.dataTransfer.setDragImage(node, x, y);
|
|
899
|
-
// Remove the preview from the DOM after a frame so the browser has time to paint.
|
|
900
|
-
requestAnimationFrame(()=>{
|
|
901
|
-
document.body.removeChild(node);
|
|
902
|
-
});
|
|
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;
|
|
903
891
|
}
|
|
904
|
-
|
|
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
|
+
});
|
|
905
897
|
// Enforce that drops are handled by useDrop.
|
|
906
898
|
addGlobalListener(window, 'drop', (e)=>{
|
|
907
899
|
if (!$28e10663603f5ea1$export$7454aff2e161f241(e.target)) {
|
|
@@ -913,11 +905,6 @@ function $dc204e8ec58447a6$export$7941f8aafa4b6021(options) {
|
|
|
913
905
|
capture: true,
|
|
914
906
|
once: true
|
|
915
907
|
});
|
|
916
|
-
if (typeof options.onDragStart === 'function') options.onDragStart({
|
|
917
|
-
type: 'dragstart',
|
|
918
|
-
x: e1.clientX,
|
|
919
|
-
y: e1.clientY
|
|
920
|
-
});
|
|
921
908
|
state.x = e1.clientX;
|
|
922
909
|
state.y = e1.clientY;
|
|
923
910
|
// Wait a frame before we set dragging to true so that the browser has time to
|
|
@@ -1290,10 +1277,6 @@ function $7f93a158ac20b90a$export$f4e2f423c21f7b04(props, state1, ref2) {
|
|
|
1290
1277
|
localState.nextTarget = null;
|
|
1291
1278
|
return 'cancel';
|
|
1292
1279
|
}
|
|
1293
|
-
if (state1.isDropTarget(target)) {
|
|
1294
|
-
localState.nextTarget = target;
|
|
1295
|
-
return localState.dropOperation;
|
|
1296
|
-
}
|
|
1297
1280
|
localState.dropOperation = state1.getDropOperation(target, types, allowedOperations);
|
|
1298
1281
|
// If the target doesn't accept the drop, see if the root accepts it instead.
|
|
1299
1282
|
if (localState.dropOperation === 'cancel') {
|
|
@@ -1743,9 +1726,7 @@ function $0cbbd00cda972c67$export$b35afafff42da2d9(props, state) {
|
|
|
1743
1726
|
getItems () {
|
|
1744
1727
|
return state.getItems(props.key);
|
|
1745
1728
|
},
|
|
1746
|
-
|
|
1747
|
-
return state.renderPreview(props.key);
|
|
1748
|
-
},
|
|
1729
|
+
preview: state.preview,
|
|
1749
1730
|
onDragStart (e) {
|
|
1750
1731
|
state.startDrag(props.key, e);
|
|
1751
1732
|
},
|
|
@@ -1863,6 +1844,42 @@ function $74f3dedaa4d234b4$export$2314ca2a3e892862(options1) {
|
|
|
1863
1844
|
}
|
|
1864
1845
|
|
|
1865
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
|
+
|
|
1866
1883
|
$parcel$exportWildcard(module.exports, $dc204e8ec58447a6$exports);
|
|
1867
1884
|
$parcel$exportWildcard(module.exports, $1ca228bc9257ca16$exports);
|
|
1868
1885
|
$parcel$exportWildcard(module.exports, $7f93a158ac20b90a$exports);
|