@react-aria/dnd 3.0.0-nightly.3262 → 3.0.0-nightly.3268

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,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
- function $parcel$export(e, n, v, s) {
29
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
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,7 +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;
862
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
+ });
863
870
  let items = options.getItems();
864
871
  $4620ae0dc40f0031$export$f9c1490890ddd063(e1.dataTransfer, items);
865
872
  if (typeof options.getAllowedDropOperations === 'function') {
@@ -868,41 +875,25 @@ function $dc204e8ec58447a6$export$7941f8aafa4b6021(options) {
868
875
  for (let operation of allowedOperations)allowed |= $76b1e110a27b1ccd$export$60b7b4bcf3903d8e[operation] || $76b1e110a27b1ccd$export$60b7b4bcf3903d8e.none;
869
876
  e1.dataTransfer.effectAllowed = $76b1e110a27b1ccd$export$dd0165308d8bff45[allowed] || 'none';
870
877
  }
871
- // If there is a renderPreview function, use it to render a custom preview image that will
878
+ // If there is a preview option, use it to render a custom preview image that will
872
879
  // appear under the pointer while dragging. If not, the element itself is dragged by the browser.
873
- if (typeof options.renderPreview === 'function') {
874
- let preview = options.renderPreview(items);
875
- if (preview) {
876
- // Create an off-screen div to render the preview into.
877
- let node = document.createElement('div');
878
- node.style.zIndex = '-100';
879
- node.style.position = 'absolute';
880
- node.style.top = '0';
881
- node.style.left = '-100000px';
882
- document.body.appendChild(node);
883
- // Call renderPreview to get a JSX element, and render it into the div with React DOM.
884
- ($parcel$interopDefault($4vY0V$reactdom)).render(preview, node);
885
- // Compute the offset that the preview will appear under the mouse.
886
- // If possible, this is based on the point the user clicked on the target.
887
- // If the preview is much smaller, then just use the center point of the preview.
888
- let size = node.getBoundingClientRect();
889
- let rect = e1.currentTarget.getBoundingClientRect();
890
- let x = e1.clientX - rect.x;
891
- let y = e1.clientY - rect.y;
892
- if (x > size.width || y > size.height) {
893
- x = size.width / 2;
894
- y = size.height / 2;
895
- }
896
- // Rounding height to an even number prevents blurry preview seen on some screens
897
- let height = 2 * Math.round(rect.height / 2);
898
- node.style.height = `${height}px`;
899
- e1.dataTransfer.setDragImage(node, x, y);
900
- // Remove the preview from the DOM after a frame so the browser has time to paint.
901
- requestAnimationFrame(()=>{
902
- document.body.removeChild(node);
903
- });
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;
904
891
  }
905
- }
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
+ });
906
897
  // Enforce that drops are handled by useDrop.
907
898
  addGlobalListener(window, 'drop', (e)=>{
908
899
  if (!$28e10663603f5ea1$export$7454aff2e161f241(e.target)) {
@@ -914,11 +905,6 @@ function $dc204e8ec58447a6$export$7941f8aafa4b6021(options) {
914
905
  capture: true,
915
906
  once: true
916
907
  });
917
- if (typeof options.onDragStart === 'function') options.onDragStart({
918
- type: 'dragstart',
919
- x: e1.clientX,
920
- y: e1.clientY
921
- });
922
908
  state.x = e1.clientX;
923
909
  state.y = e1.clientY;
924
910
  // Wait a frame before we set dragging to true so that the browser has time to
@@ -1740,9 +1726,7 @@ function $0cbbd00cda972c67$export$b35afafff42da2d9(props, state) {
1740
1726
  getItems () {
1741
1727
  return state.getItems(props.key);
1742
1728
  },
1743
- renderPreview () {
1744
- return state.renderPreview(props.key);
1745
- },
1729
+ preview: state.preview,
1746
1730
  onDragStart (e) {
1747
1731
  state.startDrag(props.key, e);
1748
1732
  },
@@ -1860,6 +1844,42 @@ function $74f3dedaa4d234b4$export$2314ca2a3e892862(options1) {
1860
1844
  }
1861
1845
 
1862
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
+
1863
1883
  $parcel$exportWildcard(module.exports, $dc204e8ec58447a6$exports);
1864
1884
  $parcel$exportWildcard(module.exports, $1ca228bc9257ca16$exports);
1865
1885
  $parcel$exportWildcard(module.exports, $7f93a158ac20b90a$exports);