@react-aria/dnd 3.10.1 → 3.11.1

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.
@@ -1 +1 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAUM,MAAM,0DAAc,CAAA,GAAA,YAAI,EAAE,UAAU,CAAC,SAAS,YAAY,KAAuB,EAAE,GAA6C;IACrI,IAAI,SAAS,MAAM,QAAQ;IAC3B,IAAI,CAAC,UAAU,YAAY,GAAG,CAAA,GAAA,eAAO,EAAsB;IAC3D,IAAI,SAAS,CAAA,GAAA,aAAK,EAAyB;IAC3C,IAAI,MAAM,CAAA,GAAA,aAAK,EAAwD;IAEvE,CAAA,GAAA,0BAAkB,EAAE,KAAK,IAAM,CAAC,OAAmB;YACjD,qFAAqF;YACrF,kGAAkG;YAClG,CAAA,GAAA,gBAAQ,EAAE;gBACR,YAAY,OAAO;YACrB;YAEA,+CAA+C;YAC/C,SAAS,OAAO,OAAO;YAEvB,kFAAkF;YAClF,IAAI,OAAO,GAAG,sBAAsB;gBAClC,YAAY;YACd;QACF,GAAG;QAAC;KAAO;IAEX,CAAA,GAAA,gBAAQ,EAAE;QACR,OAAO;YACL,IAAI,IAAI,OAAO,EACb,qBAAqB,IAAI,OAAO;QAEpC;IACF,GAAG,EAAE;IAEL,IAAI,CAAC,UACH,OAAO;IAGT,qBACE,gCAAC;QAAI,OAAO;YAAC,QAAQ;YAAM,UAAU;YAAY,KAAK;YAAG,MAAM;QAAO;QAAG,KAAK;OAC3E;AAGP","sources":["packages/@react-aria/dnd/src/DragPreview.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {DragItem, DragPreviewRenderer} from '@react-types/shared';\nimport {flushSync} from 'react-dom';\nimport React, {ForwardedRef, JSX, useEffect, useImperativeHandle, useRef, useState} from 'react';\n\nexport interface DragPreviewProps {\n children: (items: DragItem[]) => JSX.Element | null\n}\n\nexport const DragPreview = React.forwardRef(function DragPreview(props: DragPreviewProps, ref: ForwardedRef<DragPreviewRenderer | null>) {\n let render = props.children;\n let [children, setChildren] = useState<JSX.Element | null>(null);\n let domRef = useRef<HTMLDivElement | null>(null);\n let raf = useRef<ReturnType<typeof requestAnimationFrame> | undefined>(undefined);\n\n useImperativeHandle(ref, () => (items: DragItem[], callback: (node: HTMLElement | null) => void) => {\n // This will be called during the onDragStart event by useDrag. We need to render the\n // preview synchronously before this event returns so we can call event.dataTransfer.setDragImage.\n flushSync(() => {\n setChildren(render(items));\n });\n\n // Yield back to useDrag to set the drag image.\n callback(domRef.current);\n\n // Remove the preview from the DOM after a frame so the browser has time to paint.\n raf.current = requestAnimationFrame(() => {\n setChildren(null);\n });\n }, [render]);\n\n useEffect(() => {\n return () => {\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n }\n };\n }, []);\n\n if (!children) {\n return null;\n }\n\n return (\n <div style={{zIndex: -100, position: 'absolute', top: 0, left: -100000}} ref={domRef}>\n {children}\n </div>\n );\n});\n"],"names":[],"version":3,"file":"DragPreview.module.js.map"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAeM,MAAM,0DAEb,CAAA,GAAA,YAAI,EAAE,UAAU,CAAC,SAAS,YAAY,KAAuB,EAAE,GAA6C;IAC1G,IAAI,SAAS,MAAM,QAAQ;IAC3B,IAAI,CAAC,UAAU,YAAY,GAAG,CAAA,GAAA,eAAO,EAAsB;IAC3D,IAAI,SAAS,CAAA,GAAA,aAAK,EAAyB;IAC3C,IAAI,MAAM,CAAA,GAAA,aAAK,EAAwD;IAEvE,CAAA,GAAA,0BAAkB,EAAE,KAAK,IAAM,CAAC,OAAmB;YACjD,qFAAqF;YACrF,kGAAkG;YAElG,IAAI,SAAS,OAAO;YACpB,IAAI;YACJ,IAAI;YACJ,IAAI;YAEJ,IAAI,UAAU,OAAO,WAAW,YAAY,aAAa,QAAQ;gBAC/D,UAAU,OAAO,OAAO;gBACxB,UAAU,OAAO,CAAC;gBAClB,UAAU,OAAO,CAAC;YACpB,OACE,UAAU;YAGZ,CAAA,GAAA,gBAAQ,EAAE;gBACR,YAAY;YACd;YAEA,+CAA+C;YAC/C,SAAS,OAAO,OAAO,EAAE,SAAS;YAElC,kFAAkF;YAClF,IAAI,OAAO,GAAG,sBAAsB;gBAClC,YAAY;YACd;QACF,GAAG;QAAC;KAAO;IAEX,CAAA,GAAA,gBAAQ,EAAE;QACR,OAAO;YACL,IAAI,IAAI,OAAO,EACb,qBAAqB,IAAI,OAAO;QAEpC;IACF,GAAG,EAAE;IAEL,IAAI,CAAC,UACH,OAAO;IAGT,qBACE,gCAAC;QAAI,OAAO;YAAC,QAAQ;YAAM,UAAU;YAAY,KAAK;YAAG,MAAM;QAAO;QAAG,KAAK;OAC3E;AAGP","sources":["packages/@react-aria/dnd/src/DragPreview.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {DragItem, DragPreviewRenderer} from '@react-types/shared';\nimport {flushSync} from 'react-dom';\nimport React, {ForwardedRef, JSX, useEffect, useImperativeHandle, useRef, useState} from 'react';\n\nexport interface DragPreviewProps {\n /**\n * A render function which returns a preview element, or an object containing the element\n * and a custom offset. If an object is returned, the provided `x` and `y` values will be\n * used as the drag preview offset instead of the default calculation.\n */\n children: (items: DragItem[]) => JSX.Element | {element: JSX.Element, x: number, y: number} | null\n}\n\nexport const DragPreview:\n React.ForwardRefExoticComponent<DragPreviewProps & React.RefAttributes<DragPreviewRenderer | null>> =\nReact.forwardRef(function DragPreview(props: DragPreviewProps, ref: ForwardedRef<DragPreviewRenderer | null>) {\n let render = props.children;\n let [children, setChildren] = useState<JSX.Element | null>(null);\n let domRef = useRef<HTMLDivElement | null>(null);\n let raf = useRef<ReturnType<typeof requestAnimationFrame> | undefined>(undefined);\n\n useImperativeHandle(ref, () => (items: DragItem[], callback: (node: HTMLElement | null, x?: number, y?: number) => void) => {\n // This will be called during the onDragStart event by useDrag. We need to render the\n // preview synchronously before this event returns so we can call event.dataTransfer.setDragImage.\n\n let result = render(items);\n let element: JSX.Element | null;\n let offsetX: number | undefined;\n let offsetY: number | undefined;\n\n if (result && typeof result === 'object' && 'element' in result) {\n element = result.element;\n offsetX = result.x;\n offsetY = result.y;\n } else {\n element = result as JSX.Element | null;\n }\n\n flushSync(() => {\n setChildren(element);\n });\n\n // Yield back to useDrag to set the drag image.\n callback(domRef.current, offsetX, offsetY);\n\n // Remove the preview from the DOM after a frame so the browser has time to paint.\n raf.current = requestAnimationFrame(() => {\n setChildren(null);\n });\n }, [render]);\n\n useEffect(() => {\n return () => {\n if (raf.current) {\n cancelAnimationFrame(raf.current);\n }\n };\n }, []);\n\n if (!children) {\n return null;\n }\n\n return (\n <div style={{zIndex: -100, position: 'absolute', top: 0, left: -100000}} ref={domRef}>\n {children}\n </div>\n );\n});\n"],"names":[],"version":3,"file":"DragPreview.module.js.map"}
@@ -40,7 +40,6 @@ const $76b1e110a27b1ccd$export$9bbdfc78cf083e16 = {
40
40
  };
41
41
  const $76b1e110a27b1ccd$export$dd0165308d8bff45 = $76b1e110a27b1ccd$var$invert($76b1e110a27b1ccd$export$9bbdfc78cf083e16);
42
42
  $76b1e110a27b1ccd$export$dd0165308d8bff45[7] = 'all'; // ensure we don't map to 'uninitialized'.
43
- const $76b1e110a27b1ccd$export$d7ebf00f36b7a95e = $76b1e110a27b1ccd$var$invert($76b1e110a27b1ccd$export$60b7b4bcf3903d8e);
44
43
  const $76b1e110a27b1ccd$export$608ecc6f1b23c35d = {
45
44
  none: 'cancel',
46
45
  link: 'link',
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC,GAIM,IAAA,AAAK,mEAAA;;;;;;;WAAA;;AAUL,MAAM,4CAAyB;IACpC,GAAG,yCAAc;IACjB,UAAU;IACV,UAAU;IACV,UAAU;IACV,GAAG;IACH,aAAa;AACf;AAEO,MAAM,4CAAiB,6BAAO;AACrC,yCAAc,GAAoB,GAAG,OAAO,0CAA0C;AAE/E,MAAM,4CAAc,6BAAO;AAC3B,MAAM,4CAAiE;IAC5E,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;AACR;AAEO,MAAM,4CAAgC,6BAAO;AAEpD,SAAS,6BAAO,MAAM;IACpB,IAAI,MAAM,CAAC;IACX,IAAK,IAAI,OAAO,OACd,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG;IAGrB,OAAO;AACT;AAEO,MAAM,4CAAoB,IAAI,IAAI;IAAC;IAAc;IAAiB;CAAY;AAC9E,MAAM,4CAAmB;AACzB,MAAM,4CAAe","sources":["packages/@react-aria/dnd/src/constants.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {DropOperation} from '@react-types/shared';\n\nexport enum DROP_OPERATION {\n none = 0,\n cancel = 0,\n move = 1 << 0,\n copy = 1 << 1,\n link = 1 << 2,\n all = move | copy | link\n}\n\n// See https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/effectAllowed\nexport const DROP_OPERATION_ALLOWED = {\n ...DROP_OPERATION,\n copyMove: DROP_OPERATION.copy | DROP_OPERATION.move,\n copyLink: DROP_OPERATION.copy | DROP_OPERATION.link,\n linkMove: DROP_OPERATION.link | DROP_OPERATION.move,\n all: DROP_OPERATION.all,\n uninitialized: DROP_OPERATION.all\n};\n\nexport const EFFECT_ALLOWED = invert(DROP_OPERATION_ALLOWED);\nEFFECT_ALLOWED[DROP_OPERATION.all] = 'all'; // ensure we don't map to 'uninitialized'.\n\nexport const DROP_EFFECT = invert(DROP_OPERATION);\nexport const DROP_EFFECT_TO_DROP_OPERATION: {[name: string]: DropOperation} = {\n none: 'cancel',\n link: 'link',\n copy: 'copy',\n move: 'move'\n};\n\nexport const DROP_OPERATION_TO_DROP_EFFECT = invert(DROP_EFFECT_TO_DROP_OPERATION);\n\nfunction invert(object) {\n let res = {};\n for (let key in object) {\n res[object[key]] = key;\n }\n\n return res;\n}\n\nexport const NATIVE_DRAG_TYPES = new Set(['text/plain', 'text/uri-list', 'text/html']);\nexport const CUSTOM_DRAG_TYPE = 'application/vnd.react-aria.items+json';\nexport const GENERIC_TYPE = 'application/octet-stream';\n"],"names":[],"version":3,"file":"constants.main.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC,GAaM,IAAA,AAAK,mEAAA;;;;;;;WAAA;;AAgBL,MAAM,4CAA+C;IAC1D,GAAG,yCAAc;IACjB,UAAU;IACV,UAAU;IACV,UAAU;IACV,GAAG;IACH,aAAa;AACf;AAaO,MAAM,4CAAgC,6BAAO;AACpD,yCAAc,GAAoB,GAAG,OAAO,0CAA0C;AAI/E,MAAM,4CAAoE;IAC/E,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;AACR;AAEO,MAAM,4CAAoE,6BAAO;AAExF,SAAS,6BAA6D,MAAoB;IACxF,IAAI,MAAoB,CAAC;IACzB,IAAK,IAAI,OAAO,OACd,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG;IAGrB,OAAO;AACT;AAEO,MAAM,4CAAiC,IAAI,IAAI;IAAC;IAAc;IAAiB;CAAY;AAC3F,MAAM,4CAAmB;AACzB,MAAM,4CAAe","sources":["packages/@react-aria/dnd/src/constants.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {DropOperation} from '@react-types/shared';\n\nexport interface IDropOperation {\n readonly none: 0,\n readonly cancel: 0,\n readonly move: number,\n readonly copy: number,\n readonly link: number,\n readonly all: number\n}\n\nexport enum DROP_OPERATION {\n none = 0,\n cancel = 0,\n move = 1 << 0,\n copy = 1 << 1,\n link = 1 << 2,\n all = move | copy | link\n}\ninterface DropOperationAllowed extends IDropOperation {\n readonly copyMove: number,\n readonly copyLink: number,\n readonly linkMove: number,\n readonly all: number,\n readonly uninitialized: number\n}\n// See https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/effectAllowed\nexport const DROP_OPERATION_ALLOWED: DropOperationAllowed = {\n ...DROP_OPERATION,\n copyMove: DROP_OPERATION.copy | DROP_OPERATION.move,\n copyLink: DROP_OPERATION.copy | DROP_OPERATION.link,\n linkMove: DROP_OPERATION.link | DROP_OPERATION.move,\n all: DROP_OPERATION.all,\n uninitialized: DROP_OPERATION.all\n};\n\ninterface EffectAllowed {\n 0: 'none' | 'cancel',\n 1: 'move',\n 2: 'copy',\n 3: 'copyMove',\n 4: 'link',\n 5: 'linkMove',\n 6: 'copyLink',\n 7: 'all'\n}\n\nexport const EFFECT_ALLOWED: EffectAllowed = invert(DROP_OPERATION_ALLOWED) as unknown as EffectAllowed;\nEFFECT_ALLOWED[DROP_OPERATION.all] = 'all'; // ensure we don't map to 'uninitialized'.\n\ntype DropEffect = 'none' | 'link' | 'copy' | 'move';\n\nexport const DROP_EFFECT_TO_DROP_OPERATION: {[K in DropEffect]: DropOperation} = {\n none: 'cancel',\n link: 'link',\n copy: 'copy',\n move: 'move'\n};\n\nexport const DROP_OPERATION_TO_DROP_EFFECT: {[K in DropOperation]: DropEffect} = invert(DROP_EFFECT_TO_DROP_OPERATION);\n\nfunction invert<T extends string | number, C extends string | number>(object: Record<T, C>): Record<C, T> {\n let res: Record<C, T> = {} as Record<C, T>;\n for (let key in object) {\n res[object[key]] = key as T;\n }\n\n return res;\n}\n\nexport const NATIVE_DRAG_TYPES: Set<string> = new Set(['text/plain', 'text/uri-list', 'text/html']);\nexport const CUSTOM_DRAG_TYPE = 'application/vnd.react-aria.items+json';\nexport const GENERIC_TYPE = 'application/octet-stream';\n"],"names":[],"version":3,"file":"constants.main.js.map"}
@@ -27,7 +27,6 @@ const $103790afe9474d1c$export$9bbdfc78cf083e16 = {
27
27
  };
28
28
  const $103790afe9474d1c$export$dd0165308d8bff45 = $103790afe9474d1c$var$invert($103790afe9474d1c$export$9bbdfc78cf083e16);
29
29
  $103790afe9474d1c$export$dd0165308d8bff45[7] = 'all'; // ensure we don't map to 'uninitialized'.
30
- const $103790afe9474d1c$export$d7ebf00f36b7a95e = $103790afe9474d1c$var$invert($103790afe9474d1c$export$60b7b4bcf3903d8e);
31
30
  const $103790afe9474d1c$export$608ecc6f1b23c35d = {
32
31
  none: 'cancel',
33
32
  link: 'link',
@@ -49,5 +48,5 @@ const $103790afe9474d1c$export$fd9f9fc120c5402d = 'application/vnd.react-aria.it
49
48
  const $103790afe9474d1c$export$f8fc6581787339b3 = 'application/octet-stream';
50
49
 
51
50
 
52
- export {$103790afe9474d1c$export$60b7b4bcf3903d8e as DROP_OPERATION, $103790afe9474d1c$export$9bbdfc78cf083e16 as DROP_OPERATION_ALLOWED, $103790afe9474d1c$export$dd0165308d8bff45 as EFFECT_ALLOWED, $103790afe9474d1c$export$d7ebf00f36b7a95e as DROP_EFFECT, $103790afe9474d1c$export$608ecc6f1b23c35d as DROP_EFFECT_TO_DROP_OPERATION, $103790afe9474d1c$export$5eacb0769d26d3b2 as DROP_OPERATION_TO_DROP_EFFECT, $103790afe9474d1c$export$4a7729b856e9a690 as NATIVE_DRAG_TYPES, $103790afe9474d1c$export$fd9f9fc120c5402d as CUSTOM_DRAG_TYPE, $103790afe9474d1c$export$f8fc6581787339b3 as GENERIC_TYPE};
51
+ export {$103790afe9474d1c$export$60b7b4bcf3903d8e as DROP_OPERATION, $103790afe9474d1c$export$9bbdfc78cf083e16 as DROP_OPERATION_ALLOWED, $103790afe9474d1c$export$dd0165308d8bff45 as EFFECT_ALLOWED, $103790afe9474d1c$export$608ecc6f1b23c35d as DROP_EFFECT_TO_DROP_OPERATION, $103790afe9474d1c$export$5eacb0769d26d3b2 as DROP_OPERATION_TO_DROP_EFFECT, $103790afe9474d1c$export$4a7729b856e9a690 as NATIVE_DRAG_TYPES, $103790afe9474d1c$export$fd9f9fc120c5402d as CUSTOM_DRAG_TYPE, $103790afe9474d1c$export$f8fc6581787339b3 as GENERIC_TYPE};
53
52
  //# sourceMappingURL=constants.module.js.map
@@ -27,7 +27,6 @@ const $103790afe9474d1c$export$9bbdfc78cf083e16 = {
27
27
  };
28
28
  const $103790afe9474d1c$export$dd0165308d8bff45 = $103790afe9474d1c$var$invert($103790afe9474d1c$export$9bbdfc78cf083e16);
29
29
  $103790afe9474d1c$export$dd0165308d8bff45[7] = 'all'; // ensure we don't map to 'uninitialized'.
30
- const $103790afe9474d1c$export$d7ebf00f36b7a95e = $103790afe9474d1c$var$invert($103790afe9474d1c$export$60b7b4bcf3903d8e);
31
30
  const $103790afe9474d1c$export$608ecc6f1b23c35d = {
32
31
  none: 'cancel',
33
32
  link: 'link',
@@ -49,5 +48,5 @@ const $103790afe9474d1c$export$fd9f9fc120c5402d = 'application/vnd.react-aria.it
49
48
  const $103790afe9474d1c$export$f8fc6581787339b3 = 'application/octet-stream';
50
49
 
51
50
 
52
- export {$103790afe9474d1c$export$60b7b4bcf3903d8e as DROP_OPERATION, $103790afe9474d1c$export$9bbdfc78cf083e16 as DROP_OPERATION_ALLOWED, $103790afe9474d1c$export$dd0165308d8bff45 as EFFECT_ALLOWED, $103790afe9474d1c$export$d7ebf00f36b7a95e as DROP_EFFECT, $103790afe9474d1c$export$608ecc6f1b23c35d as DROP_EFFECT_TO_DROP_OPERATION, $103790afe9474d1c$export$5eacb0769d26d3b2 as DROP_OPERATION_TO_DROP_EFFECT, $103790afe9474d1c$export$4a7729b856e9a690 as NATIVE_DRAG_TYPES, $103790afe9474d1c$export$fd9f9fc120c5402d as CUSTOM_DRAG_TYPE, $103790afe9474d1c$export$f8fc6581787339b3 as GENERIC_TYPE};
51
+ export {$103790afe9474d1c$export$60b7b4bcf3903d8e as DROP_OPERATION, $103790afe9474d1c$export$9bbdfc78cf083e16 as DROP_OPERATION_ALLOWED, $103790afe9474d1c$export$dd0165308d8bff45 as EFFECT_ALLOWED, $103790afe9474d1c$export$608ecc6f1b23c35d as DROP_EFFECT_TO_DROP_OPERATION, $103790afe9474d1c$export$5eacb0769d26d3b2 as DROP_OPERATION_TO_DROP_EFFECT, $103790afe9474d1c$export$4a7729b856e9a690 as NATIVE_DRAG_TYPES, $103790afe9474d1c$export$fd9f9fc120c5402d as CUSTOM_DRAG_TYPE, $103790afe9474d1c$export$f8fc6581787339b3 as GENERIC_TYPE};
53
52
  //# sourceMappingURL=constants.module.js.map
@@ -1 +1 @@
1
- {"mappings":"AAAA;;;;;;;;;;CAUC,GAIM,IAAA,AAAK,mEAAA;;;;;;;WAAA;;AAUL,MAAM,4CAAyB;IACpC,GAAG,yCAAc;IACjB,UAAU;IACV,UAAU;IACV,UAAU;IACV,GAAG;IACH,aAAa;AACf;AAEO,MAAM,4CAAiB,6BAAO;AACrC,yCAAc,GAAoB,GAAG,OAAO,0CAA0C;AAE/E,MAAM,4CAAc,6BAAO;AAC3B,MAAM,4CAAiE;IAC5E,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;AACR;AAEO,MAAM,4CAAgC,6BAAO;AAEpD,SAAS,6BAAO,MAAM;IACpB,IAAI,MAAM,CAAC;IACX,IAAK,IAAI,OAAO,OACd,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG;IAGrB,OAAO;AACT;AAEO,MAAM,4CAAoB,IAAI,IAAI;IAAC;IAAc;IAAiB;CAAY;AAC9E,MAAM,4CAAmB;AACzB,MAAM,4CAAe","sources":["packages/@react-aria/dnd/src/constants.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {DropOperation} from '@react-types/shared';\n\nexport enum DROP_OPERATION {\n none = 0,\n cancel = 0,\n move = 1 << 0,\n copy = 1 << 1,\n link = 1 << 2,\n all = move | copy | link\n}\n\n// See https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/effectAllowed\nexport const DROP_OPERATION_ALLOWED = {\n ...DROP_OPERATION,\n copyMove: DROP_OPERATION.copy | DROP_OPERATION.move,\n copyLink: DROP_OPERATION.copy | DROP_OPERATION.link,\n linkMove: DROP_OPERATION.link | DROP_OPERATION.move,\n all: DROP_OPERATION.all,\n uninitialized: DROP_OPERATION.all\n};\n\nexport const EFFECT_ALLOWED = invert(DROP_OPERATION_ALLOWED);\nEFFECT_ALLOWED[DROP_OPERATION.all] = 'all'; // ensure we don't map to 'uninitialized'.\n\nexport const DROP_EFFECT = invert(DROP_OPERATION);\nexport const DROP_EFFECT_TO_DROP_OPERATION: {[name: string]: DropOperation} = {\n none: 'cancel',\n link: 'link',\n copy: 'copy',\n move: 'move'\n};\n\nexport const DROP_OPERATION_TO_DROP_EFFECT = invert(DROP_EFFECT_TO_DROP_OPERATION);\n\nfunction invert(object) {\n let res = {};\n for (let key in object) {\n res[object[key]] = key;\n }\n\n return res;\n}\n\nexport const NATIVE_DRAG_TYPES = new Set(['text/plain', 'text/uri-list', 'text/html']);\nexport const CUSTOM_DRAG_TYPE = 'application/vnd.react-aria.items+json';\nexport const GENERIC_TYPE = 'application/octet-stream';\n"],"names":[],"version":3,"file":"constants.module.js.map"}
1
+ {"mappings":"AAAA;;;;;;;;;;CAUC,GAaM,IAAA,AAAK,mEAAA;;;;;;;WAAA;;AAgBL,MAAM,4CAA+C;IAC1D,GAAG,yCAAc;IACjB,UAAU;IACV,UAAU;IACV,UAAU;IACV,GAAG;IACH,aAAa;AACf;AAaO,MAAM,4CAAgC,6BAAO;AACpD,yCAAc,GAAoB,GAAG,OAAO,0CAA0C;AAI/E,MAAM,4CAAoE;IAC/E,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;AACR;AAEO,MAAM,4CAAoE,6BAAO;AAExF,SAAS,6BAA6D,MAAoB;IACxF,IAAI,MAAoB,CAAC;IACzB,IAAK,IAAI,OAAO,OACd,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG;IAGrB,OAAO;AACT;AAEO,MAAM,4CAAiC,IAAI,IAAI;IAAC;IAAc;IAAiB;CAAY;AAC3F,MAAM,4CAAmB;AACzB,MAAM,4CAAe","sources":["packages/@react-aria/dnd/src/constants.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {DropOperation} from '@react-types/shared';\n\nexport interface IDropOperation {\n readonly none: 0,\n readonly cancel: 0,\n readonly move: number,\n readonly copy: number,\n readonly link: number,\n readonly all: number\n}\n\nexport enum DROP_OPERATION {\n none = 0,\n cancel = 0,\n move = 1 << 0,\n copy = 1 << 1,\n link = 1 << 2,\n all = move | copy | link\n}\ninterface DropOperationAllowed extends IDropOperation {\n readonly copyMove: number,\n readonly copyLink: number,\n readonly linkMove: number,\n readonly all: number,\n readonly uninitialized: number\n}\n// See https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/effectAllowed\nexport const DROP_OPERATION_ALLOWED: DropOperationAllowed = {\n ...DROP_OPERATION,\n copyMove: DROP_OPERATION.copy | DROP_OPERATION.move,\n copyLink: DROP_OPERATION.copy | DROP_OPERATION.link,\n linkMove: DROP_OPERATION.link | DROP_OPERATION.move,\n all: DROP_OPERATION.all,\n uninitialized: DROP_OPERATION.all\n};\n\ninterface EffectAllowed {\n 0: 'none' | 'cancel',\n 1: 'move',\n 2: 'copy',\n 3: 'copyMove',\n 4: 'link',\n 5: 'linkMove',\n 6: 'copyLink',\n 7: 'all'\n}\n\nexport const EFFECT_ALLOWED: EffectAllowed = invert(DROP_OPERATION_ALLOWED) as unknown as EffectAllowed;\nEFFECT_ALLOWED[DROP_OPERATION.all] = 'all'; // ensure we don't map to 'uninitialized'.\n\ntype DropEffect = 'none' | 'link' | 'copy' | 'move';\n\nexport const DROP_EFFECT_TO_DROP_OPERATION: {[K in DropEffect]: DropOperation} = {\n none: 'cancel',\n link: 'link',\n copy: 'copy',\n move: 'move'\n};\n\nexport const DROP_OPERATION_TO_DROP_EFFECT: {[K in DropOperation]: DropEffect} = invert(DROP_EFFECT_TO_DROP_OPERATION);\n\nfunction invert<T extends string | number, C extends string | number>(object: Record<T, C>): Record<C, T> {\n let res: Record<C, T> = {} as Record<C, T>;\n for (let key in object) {\n res[object[key]] = key as T;\n }\n\n return res;\n}\n\nexport const NATIVE_DRAG_TYPES: Set<string> = new Set(['text/plain', 'text/uri-list', 'text/html']);\nexport const CUSTOM_DRAG_TYPE = 'application/vnd.react-aria.items+json';\nexport const GENERIC_TYPE = 'application/octet-stream';\n"],"names":[],"version":3,"file":"constants.module.js.map"}
package/dist/types.d.ts CHANGED
@@ -2,7 +2,7 @@ import { DirectoryDropItem, DropItem, FileDropItem, TextDropItem, DOMAttributes,
2
2
  import { AriaButtonProps } from "@react-types/button";
3
3
  import { DroppableCollectionState, DraggableCollectionState } from "@react-stately/dnd";
4
4
  import React, { HTMLAttributes, JSX } from "react";
5
- export const DIRECTORY_DRAG_TYPE: unique symbol;
5
+ export const DIRECTORY_DRAG_TYPE: symbol;
6
6
  /** Returns whether a drop item contains text data. */
7
7
  export function isTextDropItem(dropItem: DropItem): dropItem is TextDropItem;
8
8
  /** Returns whether a drop item is a file. */
@@ -181,7 +181,16 @@ export interface DraggableCollectionOptions {
181
181
  */
182
182
  export function useDraggableCollection(props: DraggableCollectionOptions, state: DraggableCollectionState, ref: RefObject<HTMLElement | null>): void;
183
183
  export interface DragPreviewProps {
184
- children: (items: DragItem[]) => JSX.Element | null;
184
+ /**
185
+ * A render function which returns a preview element, or an object containing the element
186
+ * and a custom offset. If an object is returned, the provided `x` and `y` values will be
187
+ * used as the drag preview offset instead of the default calculation.
188
+ */
189
+ children: (items: DragItem[]) => JSX.Element | {
190
+ element: JSX.Element;
191
+ x: number;
192
+ y: number;
193
+ } | null;
185
194
  }
186
195
  export const DragPreview: React.ForwardRefExoticComponent<DragPreviewProps & React.RefAttributes<DragPreviewRenderer | null>>;
187
196
  export interface ClipboardProps {
@@ -1 +1 @@
1
- {"mappings":";;;;ACu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C,EAAE,GAAG,EAAE,UAAU,WAAW,GAAG,IAAI,CAAC,EAAE,OAAO,CAAC,EAAE,6BAA6B;IAoC5H,sBAAsB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,iBAAiB,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,OAAO,GAAG,UAAU;CAuG7G;AC3JD,YAAY,EACV,iBAAiB,EACjB,YAAY,EACZ,2BAA2B,EAC3B,4BAA4B,EAC5B,6BAA6B,EAC7B,QAAQ,EACR,aAAa,EACb,mBAAmB,EACnB,cAAc,EACd,SAAS,EACT,cAAc,EACd,SAAS,EACT,aAAa,EACb,QAAQ,EACR,aAAa,EACb,aAAa,EACb,4BAA4B,EAC5B,6BAA6B,EAC7B,4BAA4B,EAC5B,kCAAkC,EAClC,4BAA4B,EAC5B,kCAAkC,EAClC,+BAA+B,EAC/B,gCAAgC,EAChC,YAAY,EACZ,UAAU,EACV,kBAAkB,EAClB,YAAY,EACZ,cAAc,EACd,cAAc,EACd,YAAY,EACb,MAAM,qBAAqB,CAAC","sources":["packages/@react-aria/dnd/src/packages/@react-aria/dnd/src/constants.ts","packages/@react-aria/dnd/src/packages/@react-aria/dnd/src/utils.ts","packages/@react-aria/dnd/src/packages/@react-aria/dnd/src/DragManager.ts","packages/@react-aria/dnd/src/packages/@react-aria/dnd/src/DropTargetKeyboardNavigation.ts","packages/@react-aria/dnd/src/packages/@react-aria/dnd/src/useAutoScroll.ts","packages/@react-aria/dnd/src/packages/@react-aria/dnd/src/useVirtualDrop.ts","packages/@react-aria/dnd/src/packages/@react-aria/dnd/src/useDrop.ts","packages/@react-aria/dnd/src/packages/@react-aria/dnd/src/useDroppableCollection.ts","packages/@react-aria/dnd/src/packages/@react-aria/dnd/src/useDroppableItem.ts","packages/@react-aria/dnd/src/packages/@react-aria/dnd/src/useDropIndicator.ts","packages/@react-aria/dnd/src/packages/@react-aria/dnd/src/useDrag.ts","packages/@react-aria/dnd/src/packages/@react-aria/dnd/src/useDraggableItem.ts","packages/@react-aria/dnd/src/packages/@react-aria/dnd/src/useDraggableCollection.ts","packages/@react-aria/dnd/src/packages/@react-aria/dnd/src/DragPreview.tsx","packages/@react-aria/dnd/src/packages/@react-aria/dnd/src/useClipboard.ts","packages/@react-aria/dnd/src/packages/@react-aria/dnd/src/ListDropTargetDelegate.ts","packages/@react-aria/dnd/src/packages/@react-aria/dnd/src/index.ts","packages/@react-aria/dnd/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {DroppableCollectionOptions, DroppableCollectionResult} from './useDroppableCollection';\nexport type {DroppableItemOptions, DroppableItemResult} from './useDroppableItem';\nexport type {DropIndicatorProps, DropIndicatorAria} from './useDropIndicator';\nexport type {DraggableItemProps, DraggableItemResult} from './useDraggableItem';\nexport type {DraggableCollectionOptions} from './useDraggableCollection';\nexport type {DragPreviewProps} from './DragPreview';\nexport type {DragOptions, DragResult} from './useDrag';\nexport type {DropOptions, DropResult} from './useDrop';\nexport type {ClipboardProps, ClipboardResult} from './useClipboard';\nexport type {\n DirectoryDropItem,\n DragEndEvent,\n DraggableCollectionEndEvent,\n DraggableCollectionMoveEvent,\n DraggableCollectionStartEvent,\n DragItem,\n DragMoveEvent,\n DragPreviewRenderer,\n DragStartEvent,\n DragTypes,\n DropEnterEvent,\n DropEvent,\n DropExitEvent,\n DropItem,\n DropMoveEvent,\n DropOperation,\n DroppableCollectionDropEvent,\n DroppableCollectionEnterEvent,\n DroppableCollectionExitEvent,\n DroppableCollectionInsertDropEvent,\n DroppableCollectionMoveEvent,\n DroppableCollectionOnItemDropEvent,\n DroppableCollectionReorderEvent,\n DroppableCollectionRootDropEvent,\n DropPosition,\n DropTarget,\n DropTargetDelegate,\n FileDropItem,\n ItemDropTarget,\n RootDropTarget,\n TextDropItem\n} from '@react-types/shared';\n\nexport {DIRECTORY_DRAG_TYPE} from './utils';\nexport {useDrag} from './useDrag';\nexport {useDrop} from './useDrop';\nexport {useDroppableCollection} from './useDroppableCollection';\nexport {useDroppableItem} from './useDroppableItem';\nexport {useDropIndicator} from './useDropIndicator';\nexport {useDraggableItem} from './useDraggableItem';\nexport {useDraggableCollection} from './useDraggableCollection';\nexport {useClipboard} from './useClipboard';\nexport {DragPreview} from './DragPreview';\nexport {ListDropTargetDelegate} from './ListDropTargetDelegate';\nexport {isVirtualDragging} from './DragManager';\nexport {isDirectoryDropItem, isFileDropItem, isTextDropItem} from './utils';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
1
+ {"mappings":";;;;ACuBA,OAAO,MAAM,qBAAqB,MAAiB,CAAC;AA0SpD,sDAAsD;AACtD,+BAA+B,QAAQ,EAAE,QAAQ,GAAG,QAAQ,IAAI,YAAY,CAE3E;AAED,6CAA6C;AAC7C,+BAA+B,QAAQ,EAAE,QAAQ,GAAG,QAAQ,IAAI,YAAY,CAE3E;AAED,kDAAkD;AAClD,oCAAoC,QAAQ,EAAE,QAAQ,GAAG,QAAQ,IAAI,iBAAiB,CAErF;ACxOD,eAAe;AACf,qCAAqC,OAAO,CAE3C;AIpFD;IACE,uCAAuC;IACvC,GAAG,EAAE,UAAU,gBAAgB,GAAG,IAAI,CAAC,CAAC;IACxC;;;OAGG;IACH,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,SAAU,EAAE,iBAAiB,EAAE,aAAa,EAAE,KAAK,aAAa,CAAC;IAC5F,yFAAyF;IACzF,wBAAwB,CAAC,EAAE,CAAC,KAAK,EAAE,SAAU,EAAE,iBAAiB,EAA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SAAS,EACT,aAAa,EACb,QAAQ,EACR,aAAa,EACb,aAAa,EACb,4BAA4B,EAC5B,6BAA6B,EAC7B,4BAA4B,EAC5B,kCAAkC,EAClC,4BAA4B,EAC5B,kCAAkC,EAClC,+BAA+B,EAC/B,gCAAgC,EAChC,YAAY,EACZ,UAAU,EACV,kBAAkB,EAClB,YAAY,EACZ,cAAc,EACd,cAAc,EACd,YAAY,EACb,MAAM,qBAAqB,CAAC","sources":["packages/@react-aria/dnd/src/packages/@react-aria/dnd/src/constants.ts","packages/@react-aria/dnd/src/packages/@react-aria/dnd/src/utils.ts","packages/@react-aria/dnd/src/packages/@react-aria/dnd/src/DragManager.ts","packages/@react-aria/dnd/src/packages/@react-aria/dnd/src/DropTargetKeyboardNavigation.ts","packages/@react-aria/dnd/src/packages/@react-aria/dnd/src/useAutoScroll.ts","packages/@react-aria/dnd/src/packages/@react-aria/dnd/src/useVirtualDrop.ts","packages/@react-aria/dnd/src/packages/@react-aria/dnd/src/useDrop.ts","packages/@react-aria/dnd/src/packages/@react-aria/dnd/src/useDroppableCollection.ts","packages/@react-aria/dnd/src/packages/@react-aria/dnd/src/useDroppableItem.ts","packages/@react-aria/dnd/src/packages/@react-aria/dnd/src/useDropIndicator.ts","packages/@react-aria/dnd/src/packages/@react-aria/dnd/src/useDrag.ts","packages/@react-aria/dnd/src/packages/@react-aria/dnd/src/useDraggableItem.ts","packages/@react-aria/dnd/src/packages/@react-aria/dnd/src/useDraggableCollection.ts","packages/@react-aria/dnd/src/packages/@react-aria/dnd/src/DragPreview.tsx","packages/@react-aria/dnd/src/packages/@react-aria/dnd/src/useClipboard.ts","packages/@react-aria/dnd/src/packages/@react-aria/dnd/src/ListDropTargetDelegate.ts","packages/@react-aria/dnd/src/packages/@react-aria/dnd/src/index.ts","packages/@react-aria/dnd/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {DroppableCollectionOptions, DroppableCollectionResult} from './useDroppableCollection';\nexport type {DroppableItemOptions, DroppableItemResult} from './useDroppableItem';\nexport type {DropIndicatorProps, DropIndicatorAria} from './useDropIndicator';\nexport type {DraggableItemProps, DraggableItemResult} from './useDraggableItem';\nexport type {DraggableCollectionOptions} from './useDraggableCollection';\nexport type {DragPreviewProps} from './DragPreview';\nexport type {DragOptions, DragResult} from './useDrag';\nexport type {DropOptions, DropResult} from './useDrop';\nexport type {ClipboardProps, ClipboardResult} from './useClipboard';\nexport type {\n DirectoryDropItem,\n DragEndEvent,\n DraggableCollectionEndEvent,\n DraggableCollectionMoveEvent,\n DraggableCollectionStartEvent,\n DragItem,\n DragMoveEvent,\n DragPreviewRenderer,\n DragStartEvent,\n DragTypes,\n DropEnterEvent,\n DropEvent,\n DropExitEvent,\n DropItem,\n DropMoveEvent,\n DropOperation,\n DroppableCollectionDropEvent,\n DroppableCollectionEnterEvent,\n DroppableCollectionExitEvent,\n DroppableCollectionInsertDropEvent,\n DroppableCollectionMoveEvent,\n DroppableCollectionOnItemDropEvent,\n DroppableCollectionReorderEvent,\n DroppableCollectionRootDropEvent,\n DropPosition,\n DropTarget,\n DropTargetDelegate,\n FileDropItem,\n ItemDropTarget,\n RootDropTarget,\n TextDropItem\n} from '@react-types/shared';\n\nexport {DIRECTORY_DRAG_TYPE} from './utils';\nexport {useDrag} from './useDrag';\nexport {useDrop} from './useDrop';\nexport {useDroppableCollection} from './useDroppableCollection';\nexport {useDroppableItem} from './useDroppableItem';\nexport {useDropIndicator} from './useDropIndicator';\nexport {useDraggableItem} from './useDraggableItem';\nexport {useDraggableCollection} from './useDraggableCollection';\nexport {useClipboard} from './useClipboard';\nexport {DragPreview} from './DragPreview';\nexport {ListDropTargetDelegate} from './ListDropTargetDelegate';\nexport {isVirtualDragging} from './DragManager';\nexport {isDirectoryDropItem, isFileDropItem, isTextDropItem} from './utils';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
@@ -56,16 +56,17 @@ function $dc204e8ec58447a6$export$7941f8aafa4b6021(options) {
56
56
  y: 0
57
57
  }).current;
58
58
  state.options = options;
59
- let isDraggingRef = (0, $3w36N$react.useRef)(false);
59
+ let isDraggingRef = (0, $3w36N$react.useRef)(null);
60
60
  let [isDragging, setDraggingState] = (0, $3w36N$react.useState)(false);
61
- let setDragging = (isDragging)=>{
62
- isDraggingRef.current = isDragging;
63
- setDraggingState(isDragging);
61
+ let setDragging = (element)=>{
62
+ isDraggingRef.current = element;
63
+ setDraggingState(!!element);
64
64
  };
65
65
  let { addGlobalListener: addGlobalListener, removeAllGlobalListeners: removeAllGlobalListeners } = (0, $3w36N$reactariautils.useGlobalListeners)();
66
66
  let modalityOnPointerDown = (0, $3w36N$react.useRef)(null);
67
67
  let onDragStart = (e)=>{
68
- var _options_preview;
68
+ var // Clear existing data (e.g. selected text on the page would be included in some browsers)
69
+ _e_dataTransfer_clearData, _e_dataTransfer, _options_preview;
69
70
  if (e.defaultPrevented) return;
70
71
  // Prevent the drag event from propagating to any parent draggables
71
72
  e.stopPropagation();
@@ -82,6 +83,7 @@ function $dc204e8ec58447a6$export$7941f8aafa4b6021(options) {
82
83
  y: e.clientY
83
84
  });
84
85
  let items = options.getItems();
86
+ (_e_dataTransfer_clearData = (_e_dataTransfer = e.dataTransfer).clearData) === null || _e_dataTransfer_clearData === void 0 ? void 0 : _e_dataTransfer_clearData.call(_e_dataTransfer);
85
87
  (0, $4620ae0dc40f0031$exports.writeToDataTransfer)(e.dataTransfer, items);
86
88
  let allowed = (0, $76b1e110a27b1ccd$exports.DROP_OPERATION).all;
87
89
  if (typeof options.getAllowedDropOperations === 'function') {
@@ -90,26 +92,41 @@ function $dc204e8ec58447a6$export$7941f8aafa4b6021(options) {
90
92
  for (let operation of allowedOperations)allowed |= (0, $76b1e110a27b1ccd$exports.DROP_OPERATION)[operation] || (0, $76b1e110a27b1ccd$exports.DROP_OPERATION).none;
91
93
  }
92
94
  (0, $4620ae0dc40f0031$exports.setGlobalAllowedDropOperations)(allowed);
93
- e.dataTransfer.effectAllowed = (0, $76b1e110a27b1ccd$exports.EFFECT_ALLOWED)[allowed] || 'none';
95
+ let effectAllowed = (0, $76b1e110a27b1ccd$exports.EFFECT_ALLOWED)[allowed] || 'none';
96
+ e.dataTransfer.effectAllowed = effectAllowed === 'cancel' ? 'none' : effectAllowed;
94
97
  // If there is a preview option, use it to render a custom preview image that will
95
98
  // appear under the pointer while dragging. If not, the element itself is dragged by the browser.
96
- if (typeof ((_options_preview = options.preview) === null || _options_preview === void 0 ? void 0 : _options_preview.current) === 'function') options.preview.current(items, (node)=>{
99
+ if (typeof ((_options_preview = options.preview) === null || _options_preview === void 0 ? void 0 : _options_preview.current) === 'function') options.preview.current(items, (node, userX, userY)=>{
97
100
  if (!node) return;
98
101
  // Compute the offset that the preview will appear under the mouse.
99
102
  // If possible, this is based on the point the user clicked on the target.
100
103
  // If the preview is much smaller, then just use the center point of the preview.
101
104
  let size = node.getBoundingClientRect();
102
105
  let rect = e.currentTarget.getBoundingClientRect();
103
- let x = e.clientX - rect.x;
104
- let y = e.clientY - rect.y;
105
- if (x > size.width || y > size.height) {
106
- x = size.width / 2;
107
- y = size.height / 2;
106
+ let defaultX = e.clientX - rect.x;
107
+ let defaultY = e.clientY - rect.y;
108
+ if (defaultX > size.width || defaultY > size.height) {
109
+ defaultX = size.width / 2;
110
+ defaultY = size.height / 2;
108
111
  }
112
+ // Start with default offsets.
113
+ let offsetX = defaultX;
114
+ let offsetY = defaultY;
115
+ // If the preview renderer supplied explicit offsets, use those.
116
+ if (typeof userX === 'number' && typeof userY === 'number') {
117
+ offsetX = userX;
118
+ offsetY = userY;
119
+ }
120
+ // Clamp the offset so it stays within the preview bounds. Browsers
121
+ // automatically clamp out-of-range values, but doing it ourselves
122
+ // prevents the visible "snap" that can occur when the browser adjusts
123
+ // them after the first drag update.
124
+ offsetX = Math.max(0, Math.min(offsetX, size.width));
125
+ offsetY = Math.max(0, Math.min(offsetY, size.height));
109
126
  // Rounding height to an even number prevents blurry preview seen on some screens
110
127
  let height = 2 * Math.round(size.height / 2);
111
128
  node.style.height = `${height}px`;
112
- e.dataTransfer.setDragImage(node, x, y);
129
+ e.dataTransfer.setDragImage(node, offsetX, offsetY);
113
130
  });
114
131
  // Enforce that drops are handled by useDrop.
115
132
  addGlobalListener(window, 'drop', (e)=>{
@@ -123,8 +140,9 @@ function $dc204e8ec58447a6$export$7941f8aafa4b6021(options) {
123
140
  state.y = e.clientY;
124
141
  // Wait a frame before we set dragging to true so that the browser has time to
125
142
  // render the preview image before we update the element that has been dragged.
143
+ let target = e.target;
126
144
  requestAnimationFrame(()=>{
127
- setDragging(true);
145
+ setDragging(target);
128
146
  });
129
147
  };
130
148
  let onDrag = (e)=>{
@@ -154,16 +172,19 @@ function $dc204e8ec58447a6$export$7941f8aafa4b6021(options) {
154
172
  if (0, $4620ae0dc40f0031$exports.globalDropEffect) event.dropOperation = (0, $76b1e110a27b1ccd$exports.DROP_EFFECT_TO_DROP_OPERATION)[0, $4620ae0dc40f0031$exports.globalDropEffect];
155
173
  options.onDragEnd(event);
156
174
  }
157
- setDragging(false);
175
+ setDragging(null);
158
176
  removeAllGlobalListeners();
159
177
  (0, $4620ae0dc40f0031$exports.setGlobalAllowedDropOperations)((0, $76b1e110a27b1ccd$exports.DROP_OPERATION).none);
160
178
  (0, $4620ae0dc40f0031$exports.setGlobalDropEffect)(undefined);
161
179
  };
162
180
  // If the dragged element is removed from the DOM via onDrop, onDragEnd won't fire: https://bugzilla.mozilla.org/show_bug.cgi?id=460801
163
181
  // In this case, we need to manually call onDragEnd on cleanup
164
- (0, $3w36N$reactariautils.useLayoutEffect)(()=>{
182
+ (0, $3w36N$react.useEffect)(()=>{
165
183
  return ()=>{
166
- if (isDraggingRef.current) {
184
+ // Check that the dragged element has actually unmounted from the DOM and not a React Strict Mode false positive.
185
+ // https://github.com/facebook/react/issues/29585
186
+ // React 16 ran effect cleanups before removing elements from the DOM but did not have this issue.
187
+ if (isDraggingRef.current && (!isDraggingRef.current.isConnected || parseInt((0, $3w36N$react.version), 10) < 17)) {
167
188
  if (typeof state.options.onDragEnd === 'function') {
168
189
  let event = {
169
190
  type: 'dragend',
@@ -173,7 +194,7 @@ function $dc204e8ec58447a6$export$7941f8aafa4b6021(options) {
173
194
  };
174
195
  state.options.onDragEnd(event);
175
196
  }
176
- setDragging(false);
197
+ setDragging(null);
177
198
  (0, $4620ae0dc40f0031$exports.setGlobalAllowedDropOperations)((0, $76b1e110a27b1ccd$exports.DROP_OPERATION).none);
178
199
  (0, $4620ae0dc40f0031$exports.setGlobalDropEffect)(undefined);
179
200
  }
@@ -203,11 +224,11 @@ function $dc204e8ec58447a6$export$7941f8aafa4b6021(options) {
203
224
  'link'
204
225
  ],
205
226
  onDragEnd (e) {
206
- setDragging(false);
227
+ setDragging(null);
207
228
  if (typeof state.options.onDragEnd === 'function') state.options.onDragEnd(e);
208
229
  }
209
230
  }, stringFormatter);
210
- setDragging(true);
231
+ setDragging(target);
211
232
  };
212
233
  let modality = (0, $4620ae0dc40f0031$exports.useDragModality)();
213
234
  let message = !isDragging ? $dc204e8ec58447a6$var$MESSAGES[modality].start : $dc204e8ec58447a6$var$MESSAGES[modality].end;
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AA8CD,MAAM,iCAAW;IACf,UAAU;QACR,OAAO;QACP,KAAK;IACP;IACA,OAAO;QACL,OAAO;QACP,KAAK;IACP;IACA,SAAS;QACP,OAAO;QACP,KAAK;IACP;AACF;AAMO,SAAS,0CAAQ,OAAoB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AgB;qBACnB;QACF;oBACA;IACF;AACF","sources":["packages/@react-aria/dnd/src/useDrag.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaButtonProps} from '@react-types/button';\nimport {DragEndEvent, DragItem, DragMoveEvent, DragPreviewRenderer, DragStartEvent, DropOperation, PressEvent, RefObject} from '@react-types/shared';\nimport {DragEvent, HTMLAttributes, useRef, useState} from 'react';\nimport * as DragManager from './DragManager';\nimport {DROP_EFFECT_TO_DROP_OPERATION, DROP_OPERATION, EFFECT_ALLOWED} from './constants';\nimport {globalDropEffect, setGlobalAllowedDropOperations, setGlobalDropEffect, useDragModality, writeToDataTransfer} from './utils';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {isVirtualClick, isVirtualPointerEvent, useDescription, useGlobalListeners, useLayoutEffect} from '@react-aria/utils';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\n\nexport interface DragOptions {\n /** Handler that is called when a drag operation is started. */\n onDragStart?: (e: DragStartEvent) => void,\n /** Handler that is called when the drag is moved. */\n onDragMove?: (e: DragMoveEvent) => void,\n /** Handler that is called when the drag operation is ended, either as a result of a drop or a cancellation. */\n onDragEnd?: (e: DragEndEvent) => void,\n /** A function that returns the items being dragged. */\n getItems: () => DragItem[],\n /** The ref of the element that will be rendered as the drag preview while dragging. */\n preview?: RefObject<DragPreviewRenderer | null>,\n /** Function that returns the drop operations that are allowed for the dragged items. If not provided, all drop operations are allowed. */\n getAllowedDropOperations?: () => DropOperation[],\n /**\n * Whether the item has an explicit focusable drag affordance to initiate accessible drag and drop mode.\n * If true, the dragProps will omit these event handlers, and they will be applied to dragButtonProps instead.\n */\n hasDragButton?: boolean,\n /**\n * Whether the drag operation is disabled. If true, the element will not be draggable.\n */\n isDisabled?: boolean\n}\n\nexport interface DragResult {\n /** Props for the draggable element. */\n dragProps: HTMLAttributes<HTMLElement>,\n /** Props for the explicit drag button affordance, if any. */\n dragButtonProps: AriaButtonProps,\n /** Whether the element is currently being dragged. */\n isDragging: boolean\n}\n\nconst MESSAGES = {\n keyboard: {\n start: 'dragDescriptionKeyboard',\n end: 'endDragKeyboard'\n },\n touch: {\n start: 'dragDescriptionTouch',\n end: 'endDragTouch'\n },\n virtual: {\n start: 'dragDescriptionVirtual',\n end: 'endDragVirtual'\n }\n};\n\n/**\n * Handles drag interactions for an element, with support for traditional mouse and touch\n * based drag and drop, in addition to full parity for keyboard and screen reader users.\n */\nexport function useDrag(options: DragOptions): DragResult {\n let {hasDragButton, isDisabled} = options;\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/dnd');\n let state = useRef({\n options,\n x: 0,\n y: 0\n }).current;\n state.options = options;\n let isDraggingRef = useRef(false);\n let [isDragging, setDraggingState] = useState(false);\n let setDragging = (isDragging) => {\n isDraggingRef.current = isDragging;\n setDraggingState(isDragging);\n };\n let {addGlobalListener, removeAllGlobalListeners} = useGlobalListeners();\n let modalityOnPointerDown = useRef<string>(null);\n\n let onDragStart = (e: DragEvent) => {\n if (e.defaultPrevented) {\n return;\n }\n\n // Prevent the drag event from propagating to any parent draggables\n e.stopPropagation();\n\n // If this drag was initiated by a mobile screen reader (e.g. VoiceOver or TalkBack), enter virtual dragging mode.\n if (modalityOnPointerDown.current === 'virtual') {\n e.preventDefault();\n startDragging(e.target as HTMLElement);\n modalityOnPointerDown.current = null;\n return;\n }\n\n if (typeof options.onDragStart === 'function') {\n options.onDragStart({\n type: 'dragstart',\n x: e.clientX,\n y: e.clientY\n });\n }\n\n let items = options.getItems();\n writeToDataTransfer(e.dataTransfer, items);\n\n let allowed = DROP_OPERATION.all;\n if (typeof options.getAllowedDropOperations === 'function') {\n let allowedOperations = options.getAllowedDropOperations();\n allowed = DROP_OPERATION.none;\n for (let operation of allowedOperations) {\n allowed |= DROP_OPERATION[operation] || DROP_OPERATION.none;\n }\n }\n\n setGlobalAllowedDropOperations(allowed);\n e.dataTransfer.effectAllowed = EFFECT_ALLOWED[allowed] || 'none';\n\n // If there is a preview option, use it to render a custom preview image that will\n // appear under the pointer while dragging. If not, the element itself is dragged by the browser.\n if (typeof options.preview?.current === 'function') {\n options.preview.current(items, node => {\n if (!node) {\n return;\n }\n // Compute the offset that the preview will appear under the mouse.\n // If possible, this is based on the point the user clicked on the target.\n // If the preview is much smaller, then just use the center point of the preview.\n let size = node.getBoundingClientRect();\n let rect = e.currentTarget.getBoundingClientRect();\n let x = e.clientX - rect.x;\n let y = e.clientY - rect.y;\n if (x > size.width || y > size.height) {\n x = size.width / 2;\n y = size.height / 2;\n }\n\n // Rounding height to an even number prevents blurry preview seen on some screens\n let height = 2 * Math.round(size.height / 2);\n node.style.height = `${height}px`;\n\n e.dataTransfer.setDragImage(node, x, y);\n });\n }\n\n // Enforce that drops are handled by useDrop.\n addGlobalListener(window, 'drop', e => {\n e.preventDefault();\n e.stopPropagation();\n console.warn('Drags initiated from the React Aria useDrag hook may only be dropped on a target created with useDrop. This ensures that a keyboard and screen reader accessible alternative is available.');\n }, {once: true});\n state.x = e.clientX;\n state.y = e.clientY;\n\n // Wait a frame before we set dragging to true so that the browser has time to\n // render the preview image before we update the element that has been dragged.\n requestAnimationFrame(() => {\n setDragging(true);\n });\n };\n\n let onDrag = (e: DragEvent) => {\n // Prevent the drag event from propagating to any parent draggables\n e.stopPropagation();\n\n if (e.clientX === state.x && e.clientY === state.y) {\n return;\n }\n\n if (typeof options.onDragMove === 'function') {\n options.onDragMove({\n type: 'dragmove',\n x: e.clientX,\n y: e.clientY\n });\n }\n\n state.x = e.clientX;\n state.y = e.clientY;\n };\n\n let onDragEnd = (e: DragEvent) => {\n // Prevent the drag event from propagating to any parent draggables\n e.stopPropagation();\n\n if (typeof options.onDragEnd === 'function') {\n let event: DragEndEvent = {\n type: 'dragend',\n x: e.clientX,\n y: e.clientY,\n dropOperation: DROP_EFFECT_TO_DROP_OPERATION[e.dataTransfer.dropEffect]\n };\n\n // Chrome Android always returns none as its dropEffect so we use the drop effect set in useDrop via\n // onDragEnter/onDragOver instead. https://bugs.chromium.org/p/chromium/issues/detail?id=1353951\n if (globalDropEffect) {\n event.dropOperation = DROP_EFFECT_TO_DROP_OPERATION[globalDropEffect];\n }\n options.onDragEnd(event);\n }\n\n setDragging(false);\n removeAllGlobalListeners();\n setGlobalAllowedDropOperations(DROP_OPERATION.none);\n setGlobalDropEffect(undefined);\n };\n\n // If the dragged element is removed from the DOM via onDrop, onDragEnd won't fire: https://bugzilla.mozilla.org/show_bug.cgi?id=460801\n // In this case, we need to manually call onDragEnd on cleanup\n \n useLayoutEffect(() => {\n return () => {\n if (isDraggingRef.current) {\n if (typeof state.options.onDragEnd === 'function') {\n let event: DragEndEvent = {\n type: 'dragend',\n x: 0,\n y: 0,\n dropOperation: DROP_EFFECT_TO_DROP_OPERATION[globalDropEffect || 'none']\n };\n state.options.onDragEnd(event);\n }\n\n setDragging(false);\n setGlobalAllowedDropOperations(DROP_OPERATION.none);\n setGlobalDropEffect(undefined);\n }\n };\n }, [state]);\n\n let onPress = (e: PressEvent) => {\n if (e.pointerType !== 'keyboard' && e.pointerType !== 'virtual') {\n return;\n }\n\n startDragging(e.target as HTMLElement);\n };\n\n let startDragging = (target: HTMLElement) => {\n if (typeof state.options.onDragStart === 'function') {\n let rect = target.getBoundingClientRect();\n state.options.onDragStart({\n type: 'dragstart',\n x: rect.x + (rect.width / 2),\n y: rect.y + (rect.height / 2)\n });\n }\n\n DragManager.beginDragging({\n element: target,\n items: state.options.getItems(),\n allowedDropOperations: typeof state.options.getAllowedDropOperations === 'function'\n ? state.options.getAllowedDropOperations()\n : ['move', 'copy', 'link'],\n onDragEnd(e) {\n setDragging(false);\n if (typeof state.options.onDragEnd === 'function') {\n state.options.onDragEnd(e);\n }\n }\n }, stringFormatter);\n\n setDragging(true);\n };\n\n let modality = useDragModality();\n let message = !isDragging ? MESSAGES[modality].start : MESSAGES[modality].end;\n\n let descriptionProps = useDescription(stringFormatter.format(message));\n\n let interactions: HTMLAttributes<HTMLElement> = {};\n if (!hasDragButton) {\n // If there's no separate button to trigger accessible drag and drop mode,\n // then add event handlers to the draggable element itself to start dragging.\n // For keyboard, we use the Enter key in a capturing listener to prevent other\n // events such as selection from also occurring. We attempt to infer whether a\n // pointer event (e.g. long press) came from a touch screen reader, and then initiate\n // dragging in the native onDragStart listener above.\n\n interactions = {\n ...descriptionProps,\n onPointerDown(e) {\n modalityOnPointerDown.current = isVirtualPointerEvent(e.nativeEvent) ? 'virtual' : e.pointerType;\n\n // Try to detect virtual drag passthrough gestures.\n if (e.width < 1 && e.height < 1) {\n // iOS VoiceOver.\n modalityOnPointerDown.current = 'virtual';\n } else {\n let rect = e.currentTarget.getBoundingClientRect();\n let offsetX = e.clientX - rect.x;\n let offsetY = e.clientY - rect.y;\n let centerX = rect.width / 2;\n let centerY = rect.height / 2;\n\n if (Math.abs(offsetX - centerX) <= 0.5 && Math.abs(offsetY - centerY) <= 0.5) {\n // Android TalkBack.\n modalityOnPointerDown.current = 'virtual';\n } else {\n modalityOnPointerDown.current = e.pointerType;\n }\n }\n },\n onKeyDownCapture(e) {\n if (e.target === e.currentTarget && e.key === 'Enter') {\n e.preventDefault();\n e.stopPropagation();\n }\n },\n onKeyUpCapture(e) {\n if (e.target === e.currentTarget && e.key === 'Enter') {\n e.preventDefault();\n e.stopPropagation();\n startDragging(e.target as HTMLElement);\n }\n },\n onClick(e) {\n // Handle NVDA/JAWS in browse mode, and touch screen readers. In this case, no keyboard events are fired.\n if (isVirtualClick(e.nativeEvent) || modalityOnPointerDown.current === 'virtual') {\n e.preventDefault();\n e.stopPropagation();\n startDragging(e.target as HTMLElement);\n }\n }\n };\n }\n\n if (isDisabled) {\n return {\n dragProps: {\n draggable: 'false'\n },\n dragButtonProps: {},\n isDragging: false\n };\n }\n\n return {\n dragProps: {\n ...interactions,\n draggable: 'true',\n onDragStart,\n onDrag,\n onDragEnd\n },\n dragButtonProps: {\n ...descriptionProps,\n onPress\n },\n isDragging\n };\n}\n"],"names":[],"version":3,"file":"useDrag.main.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AA8CD,MAAM,iCAAW;IACf,UAAU;QACR,OAAO;QACP,KAAK;IACP;IACA,OAAO;QACL,OAAO;QACP,KAAK;IACP;IACA,SAAS;QACP,OAAO;QACP,KAAK;IACP;AACF;AAMO,SAAS,0CAAQ,OAAoB;IAC1C,IAAI,iBAAC,aAAa,cAAE,UAAU,EAAC,GAAG;IAClC,IAAI,kBAAkB,CAAA,GAAA,gDAA0B,EAAE,CAAA,GAAA,mDAAW,GAAG;IAChE,IAAI,QAAQ,CAAA,GAAA,mBAAK,EAAE;iBACjB;QACA,GAAG;QACH,GAAG;IACL,GAAG,OAAO;IACV,MAAM,OAAO,GAAG;IAChB,IAAI,gBAAgB,CAAA,GAAA,mBAAK,EAAkB;IAC3C,IAAI,CAAC,YAAY,iBAAiB,GAAG,CAAA,GAAA,qBAAO,EAAE;IAC9C,IAAI,cAAc,CAAC;QACjB,cAAc,OAAO,GAAG;QACxB,iBAAiB,CAAC,CAAC;IACrB;IACA,IAAI,qBAAC,iBAAiB,4BAAE,wBAAwB,EAAC,GAAG,CAAA,GAAA,wCAAiB;IACrE,IAAI,wBAAwB,CAAA,GAAA,mBAAK,EAAU;IAE3C,IAAI,cAAc,CAAC;YAyBjB,0FAA0F;QAC1F,2BAAA,iBAkBW;QA3CX,IAAI,EAAE,gBAAgB,EACpB;QAGF,mEAAmE;QACnE,EAAE,eAAe;QAEjB,kHAAkH;QAClH,IAAI,sBAAsB,OAAO,KAAK,WAAW;YAC/C,EAAE,cAAc;YACh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":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaButtonProps} from '@react-types/button';\nimport {DragEndEvent, DragItem, DragMoveEvent, DragPreviewRenderer, DragStartEvent, DropOperation, PressEvent, RefObject} from '@react-types/shared';\nimport {DragEvent, HTMLAttributes, version as ReactVersion, useEffect, useRef, useState} from 'react';\nimport * as DragManager from './DragManager';\nimport {DROP_EFFECT_TO_DROP_OPERATION, DROP_OPERATION, EFFECT_ALLOWED} from './constants';\nimport {globalDropEffect, setGlobalAllowedDropOperations, setGlobalDropEffect, useDragModality, writeToDataTransfer} from './utils';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {isVirtualClick, isVirtualPointerEvent, useDescription, useGlobalListeners} from '@react-aria/utils';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\n\nexport interface DragOptions {\n /** Handler that is called when a drag operation is started. */\n onDragStart?: (e: DragStartEvent) => void,\n /** Handler that is called when the drag is moved. */\n onDragMove?: (e: DragMoveEvent) => void,\n /** Handler that is called when the drag operation is ended, either as a result of a drop or a cancellation. */\n onDragEnd?: (e: DragEndEvent) => void,\n /** A function that returns the items being dragged. */\n getItems: () => DragItem[],\n /** The ref of the element that will be rendered as the drag preview while dragging. */\n preview?: RefObject<DragPreviewRenderer | null>,\n /** Function that returns the drop operations that are allowed for the dragged items. If not provided, all drop operations are allowed. */\n getAllowedDropOperations?: () => DropOperation[],\n /**\n * Whether the item has an explicit focusable drag affordance to initiate accessible drag and drop mode.\n * If true, the dragProps will omit these event handlers, and they will be applied to dragButtonProps instead.\n */\n hasDragButton?: boolean,\n /**\n * Whether the drag operation is disabled. If true, the element will not be draggable.\n */\n isDisabled?: boolean\n}\n\nexport interface DragResult {\n /** Props for the draggable element. */\n dragProps: HTMLAttributes<HTMLElement>,\n /** Props for the explicit drag button affordance, if any. */\n dragButtonProps: AriaButtonProps,\n /** Whether the element is currently being dragged. */\n isDragging: boolean\n}\n\nconst MESSAGES = {\n keyboard: {\n start: 'dragDescriptionKeyboard',\n end: 'endDragKeyboard'\n },\n touch: {\n start: 'dragDescriptionTouch',\n end: 'endDragTouch'\n },\n virtual: {\n start: 'dragDescriptionVirtual',\n end: 'endDragVirtual'\n }\n};\n\n/**\n * Handles drag interactions for an element, with support for traditional mouse and touch\n * based drag and drop, in addition to full parity for keyboard and screen reader users.\n */\nexport function useDrag(options: DragOptions): DragResult {\n let {hasDragButton, isDisabled} = options;\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/dnd');\n let state = useRef({\n options,\n x: 0,\n y: 0\n }).current;\n state.options = options;\n let isDraggingRef = useRef<Element | null>(null);\n let [isDragging, setDraggingState] = useState(false);\n let setDragging = (element: Element | null) => {\n isDraggingRef.current = element;\n setDraggingState(!!element);\n };\n let {addGlobalListener, removeAllGlobalListeners} = useGlobalListeners();\n let modalityOnPointerDown = useRef<string>(null);\n\n let onDragStart = (e: DragEvent) => {\n if (e.defaultPrevented) {\n return;\n }\n\n // Prevent the drag event from propagating to any parent draggables\n e.stopPropagation();\n\n // If this drag was initiated by a mobile screen reader (e.g. VoiceOver or TalkBack), enter virtual dragging mode.\n if (modalityOnPointerDown.current === 'virtual') {\n e.preventDefault();\n startDragging(e.target as HTMLElement);\n modalityOnPointerDown.current = null;\n return;\n }\n\n if (typeof options.onDragStart === 'function') {\n options.onDragStart({\n type: 'dragstart',\n x: e.clientX,\n y: e.clientY\n });\n }\n\n let items = options.getItems();\n // Clear existing data (e.g. selected text on the page would be included in some browsers)\n e.dataTransfer.clearData?.();\n writeToDataTransfer(e.dataTransfer, items);\n\n let allowed = DROP_OPERATION.all;\n if (typeof options.getAllowedDropOperations === 'function') {\n let allowedOperations = options.getAllowedDropOperations();\n allowed = DROP_OPERATION.none;\n for (let operation of allowedOperations) {\n allowed |= DROP_OPERATION[operation] || DROP_OPERATION.none;\n }\n }\n\n setGlobalAllowedDropOperations(allowed);\n let effectAllowed = EFFECT_ALLOWED[allowed] || 'none';\n e.dataTransfer.effectAllowed = effectAllowed === 'cancel' ? 'none' : effectAllowed;\n\n // If there is a preview option, use it to render a custom preview image that will\n // appear under the pointer while dragging. If not, the element itself is dragged by the browser.\n if (typeof options.preview?.current === 'function') {\n options.preview.current(items, (node, userX, userY) => {\n if (!node) {\n return;\n }\n // Compute the offset that the preview will appear under the mouse.\n // If possible, this is based on the point the user clicked on the target.\n // If the preview is much smaller, then just use the center point of the preview.\n let size = node.getBoundingClientRect();\n let rect = e.currentTarget.getBoundingClientRect();\n let defaultX = e.clientX - rect.x;\n let defaultY = e.clientY - rect.y;\n if (defaultX > size.width || defaultY > size.height) {\n defaultX = size.width / 2;\n defaultY = size.height / 2;\n }\n\n // Start with default offsets.\n let offsetX = defaultX;\n let offsetY = defaultY;\n\n // If the preview renderer supplied explicit offsets, use those.\n if (typeof userX === 'number' && typeof userY === 'number') {\n offsetX = userX;\n offsetY = userY;\n }\n\n // Clamp the offset so it stays within the preview bounds. Browsers\n // automatically clamp out-of-range values, but doing it ourselves\n // prevents the visible \"snap\" that can occur when the browser adjusts\n // them after the first drag update.\n offsetX = Math.max(0, Math.min(offsetX, size.width));\n offsetY = Math.max(0, Math.min(offsetY, size.height));\n\n // Rounding height to an even number prevents blurry preview seen on some screens\n let height = 2 * Math.round(size.height / 2);\n node.style.height = `${height}px`;\n\n e.dataTransfer.setDragImage(node, offsetX, offsetY);\n });\n }\n\n // Enforce that drops are handled by useDrop.\n addGlobalListener(window, 'drop', e => {\n e.preventDefault();\n e.stopPropagation();\n console.warn('Drags initiated from the React Aria useDrag hook may only be dropped on a target created with useDrop. This ensures that a keyboard and screen reader accessible alternative is available.');\n }, {once: true});\n state.x = e.clientX;\n state.y = e.clientY;\n\n // Wait a frame before we set dragging to true so that the browser has time to\n // render the preview image before we update the element that has been dragged.\n let target = e.target;\n requestAnimationFrame(() => {\n setDragging(target as Element);\n });\n };\n\n let onDrag = (e: DragEvent) => {\n // Prevent the drag event from propagating to any parent draggables\n e.stopPropagation();\n\n if (e.clientX === state.x && e.clientY === state.y) {\n return;\n }\n\n if (typeof options.onDragMove === 'function') {\n options.onDragMove({\n type: 'dragmove',\n x: e.clientX,\n y: e.clientY\n });\n }\n\n state.x = e.clientX;\n state.y = e.clientY;\n };\n\n let onDragEnd = (e: DragEvent) => {\n // Prevent the drag event from propagating to any parent draggables\n e.stopPropagation();\n\n if (typeof options.onDragEnd === 'function') {\n let event: DragEndEvent = {\n type: 'dragend',\n x: e.clientX,\n y: e.clientY,\n dropOperation: DROP_EFFECT_TO_DROP_OPERATION[e.dataTransfer.dropEffect]\n };\n\n // Chrome Android always returns none as its dropEffect so we use the drop effect set in useDrop via\n // onDragEnter/onDragOver instead. https://bugs.chromium.org/p/chromium/issues/detail?id=1353951\n if (globalDropEffect) {\n event.dropOperation = DROP_EFFECT_TO_DROP_OPERATION[globalDropEffect];\n }\n options.onDragEnd(event);\n }\n\n setDragging(null);\n removeAllGlobalListeners();\n setGlobalAllowedDropOperations(DROP_OPERATION.none);\n setGlobalDropEffect(undefined);\n };\n\n // If the dragged element is removed from the DOM via onDrop, onDragEnd won't fire: https://bugzilla.mozilla.org/show_bug.cgi?id=460801\n // In this case, we need to manually call onDragEnd on cleanup\n\n useEffect(() => {\n return () => {\n // Check that the dragged element has actually unmounted from the DOM and not a React Strict Mode false positive.\n // https://github.com/facebook/react/issues/29585\n // React 16 ran effect cleanups before removing elements from the DOM but did not have this issue.\n if (isDraggingRef.current && (!isDraggingRef.current.isConnected || parseInt(ReactVersion, 10) < 17)) {\n if (typeof state.options.onDragEnd === 'function') {\n let event: DragEndEvent = {\n type: 'dragend',\n x: 0,\n y: 0,\n dropOperation: DROP_EFFECT_TO_DROP_OPERATION[globalDropEffect || 'none']\n };\n state.options.onDragEnd(event);\n }\n\n setDragging(null);\n setGlobalAllowedDropOperations(DROP_OPERATION.none);\n setGlobalDropEffect(undefined);\n }\n };\n }, [state]);\n\n let onPress = (e: PressEvent) => {\n if (e.pointerType !== 'keyboard' && e.pointerType !== 'virtual') {\n return;\n }\n\n startDragging(e.target as HTMLElement);\n };\n\n let startDragging = (target: HTMLElement) => {\n if (typeof state.options.onDragStart === 'function') {\n let rect = target.getBoundingClientRect();\n state.options.onDragStart({\n type: 'dragstart',\n x: rect.x + (rect.width / 2),\n y: rect.y + (rect.height / 2)\n });\n }\n\n DragManager.beginDragging({\n element: target,\n items: state.options.getItems(),\n allowedDropOperations: typeof state.options.getAllowedDropOperations === 'function'\n ? state.options.getAllowedDropOperations()\n : ['move', 'copy', 'link'],\n onDragEnd(e) {\n setDragging(null);\n if (typeof state.options.onDragEnd === 'function') {\n state.options.onDragEnd(e);\n }\n }\n }, stringFormatter);\n\n setDragging(target);\n };\n\n let modality = useDragModality();\n let message = !isDragging ? MESSAGES[modality].start : MESSAGES[modality].end;\n\n let descriptionProps = useDescription(stringFormatter.format(message));\n\n let interactions: HTMLAttributes<HTMLElement> = {};\n if (!hasDragButton) {\n // If there's no separate button to trigger accessible drag and drop mode,\n // then add event handlers to the draggable element itself to start dragging.\n // For keyboard, we use the Enter key in a capturing listener to prevent other\n // events such as selection from also occurring. We attempt to infer whether a\n // pointer event (e.g. long press) came from a touch screen reader, and then initiate\n // dragging in the native onDragStart listener above.\n\n interactions = {\n ...descriptionProps,\n onPointerDown(e) {\n modalityOnPointerDown.current = isVirtualPointerEvent(e.nativeEvent) ? 'virtual' : e.pointerType;\n\n // Try to detect virtual drag passthrough gestures.\n if (e.width < 1 && e.height < 1) {\n // iOS VoiceOver.\n modalityOnPointerDown.current = 'virtual';\n } else {\n let rect = e.currentTarget.getBoundingClientRect();\n let offsetX = e.clientX - rect.x;\n let offsetY = e.clientY - rect.y;\n let centerX = rect.width / 2;\n let centerY = rect.height / 2;\n\n if (Math.abs(offsetX - centerX) <= 0.5 && Math.abs(offsetY - centerY) <= 0.5) {\n // Android TalkBack.\n modalityOnPointerDown.current = 'virtual';\n } else {\n modalityOnPointerDown.current = e.pointerType;\n }\n }\n },\n onKeyDownCapture(e) {\n if (e.target === e.currentTarget && e.key === 'Enter') {\n e.preventDefault();\n e.stopPropagation();\n }\n },\n onKeyUpCapture(e) {\n if (e.target === e.currentTarget && e.key === 'Enter') {\n e.preventDefault();\n e.stopPropagation();\n startDragging(e.target as HTMLElement);\n }\n },\n onClick(e) {\n // Handle NVDA/JAWS in browse mode, and touch screen readers. In this case, no keyboard events are fired.\n if (isVirtualClick(e.nativeEvent) || modalityOnPointerDown.current === 'virtual') {\n e.preventDefault();\n e.stopPropagation();\n startDragging(e.target as HTMLElement);\n }\n }\n };\n }\n\n if (isDisabled) {\n return {\n dragProps: {\n draggable: 'false'\n },\n dragButtonProps: {},\n isDragging: false\n };\n }\n\n return {\n dragProps: {\n ...interactions,\n draggable: 'true',\n onDragStart,\n onDrag,\n onDragEnd\n },\n dragButtonProps: {\n ...descriptionProps,\n onPress\n },\n isDragging\n };\n}\n"],"names":[],"version":3,"file":"useDrag.main.js.map"}
package/dist/useDrag.mjs CHANGED
@@ -2,8 +2,8 @@ import {beginDragging as $67560de7c78cb232$export$549dbcf8649bf3b2} from "./Drag
2
2
  import {DROP_EFFECT_TO_DROP_OPERATION as $103790afe9474d1c$export$608ecc6f1b23c35d, DROP_OPERATION as $103790afe9474d1c$export$60b7b4bcf3903d8e, EFFECT_ALLOWED as $103790afe9474d1c$export$dd0165308d8bff45} from "./constants.mjs";
3
3
  import {globalDropEffect as $7252cd45fc48c07c$export$8e6636520ac15722, setGlobalAllowedDropOperations as $7252cd45fc48c07c$export$6539bc8c3a0a2d67, setGlobalDropEffect as $7252cd45fc48c07c$export$64f52ed7349ddb84, useDragModality as $7252cd45fc48c07c$export$49bac5d6d4b352ea, writeToDataTransfer as $7252cd45fc48c07c$export$f9c1490890ddd063} from "./utils.mjs";
4
4
  import $72Evg$intlStringsmodulejs from "./intlStrings.mjs";
5
- import {useRef as $72Evg$useRef, useState as $72Evg$useState} from "react";
6
- import {useGlobalListeners as $72Evg$useGlobalListeners, useLayoutEffect as $72Evg$useLayoutEffect, useDescription as $72Evg$useDescription, isVirtualPointerEvent as $72Evg$isVirtualPointerEvent, isVirtualClick as $72Evg$isVirtualClick} from "@react-aria/utils";
5
+ import {useRef as $72Evg$useRef, useState as $72Evg$useState, useEffect as $72Evg$useEffect, version as $72Evg$version} from "react";
6
+ import {useGlobalListeners as $72Evg$useGlobalListeners, useDescription as $72Evg$useDescription, isVirtualPointerEvent as $72Evg$isVirtualPointerEvent, isVirtualClick as $72Evg$isVirtualClick} from "@react-aria/utils";
7
7
  import {useLocalizedStringFormatter as $72Evg$useLocalizedStringFormatter} from "@react-aria/i18n";
8
8
 
9
9
 
@@ -50,16 +50,17 @@ function $8253ed7ece74b463$export$7941f8aafa4b6021(options) {
50
50
  y: 0
51
51
  }).current;
52
52
  state.options = options;
53
- let isDraggingRef = (0, $72Evg$useRef)(false);
53
+ let isDraggingRef = (0, $72Evg$useRef)(null);
54
54
  let [isDragging, setDraggingState] = (0, $72Evg$useState)(false);
55
- let setDragging = (isDragging)=>{
56
- isDraggingRef.current = isDragging;
57
- setDraggingState(isDragging);
55
+ let setDragging = (element)=>{
56
+ isDraggingRef.current = element;
57
+ setDraggingState(!!element);
58
58
  };
59
59
  let { addGlobalListener: addGlobalListener, removeAllGlobalListeners: removeAllGlobalListeners } = (0, $72Evg$useGlobalListeners)();
60
60
  let modalityOnPointerDown = (0, $72Evg$useRef)(null);
61
61
  let onDragStart = (e)=>{
62
- var _options_preview;
62
+ var // Clear existing data (e.g. selected text on the page would be included in some browsers)
63
+ _e_dataTransfer_clearData, _e_dataTransfer, _options_preview;
63
64
  if (e.defaultPrevented) return;
64
65
  // Prevent the drag event from propagating to any parent draggables
65
66
  e.stopPropagation();
@@ -76,6 +77,7 @@ function $8253ed7ece74b463$export$7941f8aafa4b6021(options) {
76
77
  y: e.clientY
77
78
  });
78
79
  let items = options.getItems();
80
+ (_e_dataTransfer_clearData = (_e_dataTransfer = e.dataTransfer).clearData) === null || _e_dataTransfer_clearData === void 0 ? void 0 : _e_dataTransfer_clearData.call(_e_dataTransfer);
79
81
  (0, $7252cd45fc48c07c$export$f9c1490890ddd063)(e.dataTransfer, items);
80
82
  let allowed = (0, $103790afe9474d1c$export$60b7b4bcf3903d8e).all;
81
83
  if (typeof options.getAllowedDropOperations === 'function') {
@@ -84,26 +86,41 @@ function $8253ed7ece74b463$export$7941f8aafa4b6021(options) {
84
86
  for (let operation of allowedOperations)allowed |= (0, $103790afe9474d1c$export$60b7b4bcf3903d8e)[operation] || (0, $103790afe9474d1c$export$60b7b4bcf3903d8e).none;
85
87
  }
86
88
  (0, $7252cd45fc48c07c$export$6539bc8c3a0a2d67)(allowed);
87
- e.dataTransfer.effectAllowed = (0, $103790afe9474d1c$export$dd0165308d8bff45)[allowed] || 'none';
89
+ let effectAllowed = (0, $103790afe9474d1c$export$dd0165308d8bff45)[allowed] || 'none';
90
+ e.dataTransfer.effectAllowed = effectAllowed === 'cancel' ? 'none' : effectAllowed;
88
91
  // If there is a preview option, use it to render a custom preview image that will
89
92
  // appear under the pointer while dragging. If not, the element itself is dragged by the browser.
90
- if (typeof ((_options_preview = options.preview) === null || _options_preview === void 0 ? void 0 : _options_preview.current) === 'function') options.preview.current(items, (node)=>{
93
+ if (typeof ((_options_preview = options.preview) === null || _options_preview === void 0 ? void 0 : _options_preview.current) === 'function') options.preview.current(items, (node, userX, userY)=>{
91
94
  if (!node) return;
92
95
  // Compute the offset that the preview will appear under the mouse.
93
96
  // If possible, this is based on the point the user clicked on the target.
94
97
  // If the preview is much smaller, then just use the center point of the preview.
95
98
  let size = node.getBoundingClientRect();
96
99
  let rect = e.currentTarget.getBoundingClientRect();
97
- let x = e.clientX - rect.x;
98
- let y = e.clientY - rect.y;
99
- if (x > size.width || y > size.height) {
100
- x = size.width / 2;
101
- y = size.height / 2;
100
+ let defaultX = e.clientX - rect.x;
101
+ let defaultY = e.clientY - rect.y;
102
+ if (defaultX > size.width || defaultY > size.height) {
103
+ defaultX = size.width / 2;
104
+ defaultY = size.height / 2;
102
105
  }
106
+ // Start with default offsets.
107
+ let offsetX = defaultX;
108
+ let offsetY = defaultY;
109
+ // If the preview renderer supplied explicit offsets, use those.
110
+ if (typeof userX === 'number' && typeof userY === 'number') {
111
+ offsetX = userX;
112
+ offsetY = userY;
113
+ }
114
+ // Clamp the offset so it stays within the preview bounds. Browsers
115
+ // automatically clamp out-of-range values, but doing it ourselves
116
+ // prevents the visible "snap" that can occur when the browser adjusts
117
+ // them after the first drag update.
118
+ offsetX = Math.max(0, Math.min(offsetX, size.width));
119
+ offsetY = Math.max(0, Math.min(offsetY, size.height));
103
120
  // Rounding height to an even number prevents blurry preview seen on some screens
104
121
  let height = 2 * Math.round(size.height / 2);
105
122
  node.style.height = `${height}px`;
106
- e.dataTransfer.setDragImage(node, x, y);
123
+ e.dataTransfer.setDragImage(node, offsetX, offsetY);
107
124
  });
108
125
  // Enforce that drops are handled by useDrop.
109
126
  addGlobalListener(window, 'drop', (e)=>{
@@ -117,8 +134,9 @@ function $8253ed7ece74b463$export$7941f8aafa4b6021(options) {
117
134
  state.y = e.clientY;
118
135
  // Wait a frame before we set dragging to true so that the browser has time to
119
136
  // render the preview image before we update the element that has been dragged.
137
+ let target = e.target;
120
138
  requestAnimationFrame(()=>{
121
- setDragging(true);
139
+ setDragging(target);
122
140
  });
123
141
  };
124
142
  let onDrag = (e)=>{
@@ -148,16 +166,19 @@ function $8253ed7ece74b463$export$7941f8aafa4b6021(options) {
148
166
  if (0, $7252cd45fc48c07c$export$8e6636520ac15722) event.dropOperation = (0, $103790afe9474d1c$export$608ecc6f1b23c35d)[0, $7252cd45fc48c07c$export$8e6636520ac15722];
149
167
  options.onDragEnd(event);
150
168
  }
151
- setDragging(false);
169
+ setDragging(null);
152
170
  removeAllGlobalListeners();
153
171
  (0, $7252cd45fc48c07c$export$6539bc8c3a0a2d67)((0, $103790afe9474d1c$export$60b7b4bcf3903d8e).none);
154
172
  (0, $7252cd45fc48c07c$export$64f52ed7349ddb84)(undefined);
155
173
  };
156
174
  // If the dragged element is removed from the DOM via onDrop, onDragEnd won't fire: https://bugzilla.mozilla.org/show_bug.cgi?id=460801
157
175
  // In this case, we need to manually call onDragEnd on cleanup
158
- (0, $72Evg$useLayoutEffect)(()=>{
176
+ (0, $72Evg$useEffect)(()=>{
159
177
  return ()=>{
160
- if (isDraggingRef.current) {
178
+ // Check that the dragged element has actually unmounted from the DOM and not a React Strict Mode false positive.
179
+ // https://github.com/facebook/react/issues/29585
180
+ // React 16 ran effect cleanups before removing elements from the DOM but did not have this issue.
181
+ if (isDraggingRef.current && (!isDraggingRef.current.isConnected || parseInt((0, $72Evg$version), 10) < 17)) {
161
182
  if (typeof state.options.onDragEnd === 'function') {
162
183
  let event = {
163
184
  type: 'dragend',
@@ -167,7 +188,7 @@ function $8253ed7ece74b463$export$7941f8aafa4b6021(options) {
167
188
  };
168
189
  state.options.onDragEnd(event);
169
190
  }
170
- setDragging(false);
191
+ setDragging(null);
171
192
  (0, $7252cd45fc48c07c$export$6539bc8c3a0a2d67)((0, $103790afe9474d1c$export$60b7b4bcf3903d8e).none);
172
193
  (0, $7252cd45fc48c07c$export$64f52ed7349ddb84)(undefined);
173
194
  }
@@ -197,11 +218,11 @@ function $8253ed7ece74b463$export$7941f8aafa4b6021(options) {
197
218
  'link'
198
219
  ],
199
220
  onDragEnd (e) {
200
- setDragging(false);
221
+ setDragging(null);
201
222
  if (typeof state.options.onDragEnd === 'function') state.options.onDragEnd(e);
202
223
  }
203
224
  }, stringFormatter);
204
- setDragging(true);
225
+ setDragging(target);
205
226
  };
206
227
  let modality = (0, $7252cd45fc48c07c$export$49bac5d6d4b352ea)();
207
228
  let message = !isDragging ? $8253ed7ece74b463$var$MESSAGES[modality].start : $8253ed7ece74b463$var$MESSAGES[modality].end;