@react-aria/dnd 3.10.0 → 3.11.0

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.
@@ -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.module.js";
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.module.js";
4
4
  import $72Evg$intlStringsmodulejs from "./intlStrings.module.js";
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,11 +50,11 @@ 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);
@@ -84,26 +84,41 @@ function $8253ed7ece74b463$export$7941f8aafa4b6021(options) {
84
84
  for (let operation of allowedOperations)allowed |= (0, $103790afe9474d1c$export$60b7b4bcf3903d8e)[operation] || (0, $103790afe9474d1c$export$60b7b4bcf3903d8e).none;
85
85
  }
86
86
  (0, $7252cd45fc48c07c$export$6539bc8c3a0a2d67)(allowed);
87
- e.dataTransfer.effectAllowed = (0, $103790afe9474d1c$export$dd0165308d8bff45)[allowed] || 'none';
87
+ let effectAllowed = (0, $103790afe9474d1c$export$dd0165308d8bff45)[allowed] || 'none';
88
+ e.dataTransfer.effectAllowed = effectAllowed === 'cancel' ? 'none' : effectAllowed;
88
89
  // If there is a preview option, use it to render a custom preview image that will
89
90
  // 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)=>{
91
+ 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
92
  if (!node) return;
92
93
  // Compute the offset that the preview will appear under the mouse.
93
94
  // If possible, this is based on the point the user clicked on the target.
94
95
  // If the preview is much smaller, then just use the center point of the preview.
95
96
  let size = node.getBoundingClientRect();
96
97
  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;
98
+ let defaultX = e.clientX - rect.x;
99
+ let defaultY = e.clientY - rect.y;
100
+ if (defaultX > size.width || defaultY > size.height) {
101
+ defaultX = size.width / 2;
102
+ defaultY = size.height / 2;
102
103
  }
104
+ // Start with default offsets.
105
+ let offsetX = defaultX;
106
+ let offsetY = defaultY;
107
+ // If the preview renderer supplied explicit offsets, use those.
108
+ if (typeof userX === 'number' && typeof userY === 'number') {
109
+ offsetX = userX;
110
+ offsetY = userY;
111
+ }
112
+ // Clamp the offset so it stays within the preview bounds. Browsers
113
+ // automatically clamp out-of-range values, but doing it ourselves
114
+ // prevents the visible "snap" that can occur when the browser adjusts
115
+ // them after the first drag update.
116
+ offsetX = Math.max(0, Math.min(offsetX, size.width));
117
+ offsetY = Math.max(0, Math.min(offsetY, size.height));
103
118
  // Rounding height to an even number prevents blurry preview seen on some screens
104
119
  let height = 2 * Math.round(size.height / 2);
105
120
  node.style.height = `${height}px`;
106
- e.dataTransfer.setDragImage(node, x, y);
121
+ e.dataTransfer.setDragImage(node, offsetX, offsetY);
107
122
  });
108
123
  // Enforce that drops are handled by useDrop.
109
124
  addGlobalListener(window, 'drop', (e)=>{
@@ -117,8 +132,9 @@ function $8253ed7ece74b463$export$7941f8aafa4b6021(options) {
117
132
  state.y = e.clientY;
118
133
  // Wait a frame before we set dragging to true so that the browser has time to
119
134
  // render the preview image before we update the element that has been dragged.
135
+ let target = e.target;
120
136
  requestAnimationFrame(()=>{
121
- setDragging(true);
137
+ setDragging(target);
122
138
  });
123
139
  };
124
140
  let onDrag = (e)=>{
@@ -148,16 +164,19 @@ function $8253ed7ece74b463$export$7941f8aafa4b6021(options) {
148
164
  if (0, $7252cd45fc48c07c$export$8e6636520ac15722) event.dropOperation = (0, $103790afe9474d1c$export$608ecc6f1b23c35d)[0, $7252cd45fc48c07c$export$8e6636520ac15722];
149
165
  options.onDragEnd(event);
150
166
  }
151
- setDragging(false);
167
+ setDragging(null);
152
168
  removeAllGlobalListeners();
153
169
  (0, $7252cd45fc48c07c$export$6539bc8c3a0a2d67)((0, $103790afe9474d1c$export$60b7b4bcf3903d8e).none);
154
170
  (0, $7252cd45fc48c07c$export$64f52ed7349ddb84)(undefined);
155
171
  };
156
172
  // 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
173
  // In this case, we need to manually call onDragEnd on cleanup
158
- (0, $72Evg$useLayoutEffect)(()=>{
174
+ (0, $72Evg$useEffect)(()=>{
159
175
  return ()=>{
160
- if (isDraggingRef.current) {
176
+ // Check that the dragged element has actually unmounted from the DOM and not a React Strict Mode false positive.
177
+ // https://github.com/facebook/react/issues/29585
178
+ // React 16 ran effect cleanups before removing elements from the DOM but did not have this issue.
179
+ if (isDraggingRef.current && (!isDraggingRef.current.isConnected || parseInt((0, $72Evg$version), 10) < 17)) {
161
180
  if (typeof state.options.onDragEnd === 'function') {
162
181
  let event = {
163
182
  type: 'dragend',
@@ -167,7 +186,7 @@ function $8253ed7ece74b463$export$7941f8aafa4b6021(options) {
167
186
  };
168
187
  state.options.onDragEnd(event);
169
188
  }
170
- setDragging(false);
189
+ setDragging(null);
171
190
  (0, $7252cd45fc48c07c$export$6539bc8c3a0a2d67)((0, $103790afe9474d1c$export$60b7b4bcf3903d8e).none);
172
191
  (0, $7252cd45fc48c07c$export$64f52ed7349ddb84)(undefined);
173
192
  }
@@ -197,11 +216,11 @@ function $8253ed7ece74b463$export$7941f8aafa4b6021(options) {
197
216
  'link'
198
217
  ],
199
218
  onDragEnd (e) {
200
- setDragging(false);
219
+ setDragging(null);
201
220
  if (typeof state.options.onDragEnd === 'function') state.options.onDragEnd(e);
202
221
  }
203
222
  }, stringFormatter);
204
- setDragging(true);
223
+ setDragging(target);
205
224
  };
206
225
  let modality = (0, $7252cd45fc48c07c$export$49bac5d6d4b352ea)();
207
226
  let message = !isDragging ? $8253ed7ece74b463$var$MESSAG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AW;gBAChF,EAAE,cAAc;gBAChB,EAAE,eAAe;gBACjB,cAAc,EAAE,MAAM;YACxB;QACF;IACF;IAGF,IAAI,YACF,OAAO;QACL,WAAW;YACT,WAAW;QACb;QACA,iBAAiB,CAAC;QAClB,YAAY;IACd;IAGF,OAAO;QACL,WAAW;YACT,GAAG,YAAY;YACf,WAAW;yBACX;oBACA;uBACA;QACF;QACA,iBAAiB;YACf,GAAG,gBAAgB;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.module.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,kCAA0B,EAAE,CAAA,GAAA,oDAAW,GAAG;IAChE,IAAI,QAAQ,CAAA,GAAA,aAAK,EAAE;iBACjB;QACA,GAAG;QACH,GAAG;IACL,GAAG,OAAO;IACV,MAAM,OAAO,GAAG;IAChB,IAAI,gBAAgB,CAAA,GAAA,aAAK,EAAkB;IAC3C,IAAI,CAAC,YAAY,iBAAiB,GAAG,CAAA,GAAA,eAAO,EAAE;IAC9C,IAAI,cAAc,CAAC;QACjB,cAAc,OAAO,GAAG;QACxB,iBAAiB,CAAC,CAAC;IACrB;IACA,IAAI,qBAAC,iBAAiB,4BAAE,wBAAwB,EAAC,GAAG,CAAA,GAAA,yBA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YACT,GAAG,YAAY;YACf,WAAW;yBACX;oBACA;uBACA;QACF;QACA,iBAAiB;YACf,GAAG,gBAAgB;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, 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 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.module.js.map"}
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAYM,MAAM,4CAAyB,IAAI;AACnC,MAAM,4CAAsB;AAE5B,SAAS,0CAAyB,KAA+B;IACtE,IAAI,MAAC,EAAE,EAAC,GAAG,0CAAuB,GAAG,CAAC,UAAU,CAAC;IACjD,IAAI,CAAC,IACH,MAAM,IAAI,MAAM;IAGlB,OAAO;AACT;AAEO,SAAS,0CAA0B,KAA+B;IACvE,IAAI,OAAC,GAA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AS,QAAQ,MAAM,GAAG,GAAG;AAC/B;AAEA,SAAS,mCAAa,KAA0B;IAC9C,OAAO,IAAI,QAAQ,CAAC,SAAS,SAAW,MAAM,IAAI,CAAC,SAAS;AAC9D;AAGO,SAAS,0CAAe,QAAkB;IAC/C,OAAO,SAAS,IAAI,KAAK;AAC3B;AAGO,SAAS,yCAAe,QAAkB;IAC/C,OAAO,SAAS,IAAI,KAAK;AAC3B;AAGO,SAAS,0CAAoB,QAAkB;IACpD,OAAO,SAAS,IAAI,KAAK;AAC3B;AAYO,IAAI,4CAA2B;IAAC,cAAc,IAAI;AAAK;AAEvD,SAAS,0CAAyB,GAAkC;IACzE,0CAAe,qBAAqB,GAAG;AACzC;AAEO,SAAS,0CAAgB,IAAc;IAC5C,0CAAe,YAAY,GAAG;AAChC;AAEO,SAAS,0CAAqB,GAAmC;IACtE,0CAAe,iBAAiB,GAAG;AACrC;AAEO,SAAS;IACd,4CAAiB;QAAC,cAAc,IAAI;IAAK;AAC3C;AAEO,SAAS,0CAAkB,KAAe;IAC/C,4CAAiB;AACnB;AAIO,SAAS,0CAAwB,GAAmC;IACzE,IAAI,yBAAC,qBAAqB,qBAAE,iBAAiB,EAAC,GAAG;IACjD,OAAO,CAAA,kCAAA,4CAAA,sBAAuB,OAAO,KAAI,QAAQ,sBAAsB,OAAO,KAAM,CAAA,CAAA,gBAAA,0BAAA,IAAK,OAAO,MAAI,8BAAA,wCAAA,kBAAmB,OAAO,CAAD;AAC/H;AAGO,IAAI;AACJ,SAAS,0CAAoB,UAAkC;IACpE,4CAAmB;AACrB;AAEO,IAAI,4CAA8B,CAAA,GAAA,wCAAa,EAAE,IAAI;AACrD,SAAS,0CAA+B,CAAiB;IAC9D,4CAA8B;AAChC","sources":["packages/@react-aria/dnd/src/utils.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 {CUSTOM_DRAG_TYPE, DROP_OPERATION, GENERIC_TYPE, NATIVE_DRAG_TYPES} from './constants';\nimport {DirectoryDropItem, DragItem, DropItem, FileDropItem, DragTypes as IDragTypes, Key, RefObject, TextDropItem} from '@react-types/shared';\nimport {DroppableCollectionState} from '@react-stately/dnd';\nimport {getInteractionModality, useInteractionModality} from '@react-aria/interactions';\n\ninterface DroppableCollectionMap {\n id: string,\n ref: RefObject<HTMLElement | null>\n}\n\nexport const droppableCollectionMap = new WeakMap<DroppableCollectionState, DroppableCollectionMap>();\nexport const DIRECTORY_DRAG_TYPE = Symbol();\n\nexport function getDroppableCollectionId(state: DroppableCollectionState): string {\n let {id} = droppableCollectionMap.get(state) || {};\n if (!id) {\n throw new Error('Droppable item outside a droppable collection');\n }\n\n return id;\n}\n\nexport function getDroppableCollectionRef(state: DroppableCollectionState): RefObject<HTMLElement | null> {\n let {ref} = droppableCollectionMap.get(state) || {};\n if (!ref) {\n throw new Error('Droppable item outside a droppable collection');\n }\n\n return ref;\n}\n\nexport function getTypes(items: DragItem[]): Set<string> {\n let types = new Set<string>();\n for (let item of items) {\n for (let type of Object.keys(item)) {\n types.add(type);\n }\n }\n\n return types;\n}\n\nfunction mapModality(modality: string | null) {\n if (!modality) {\n modality = 'virtual';\n }\n\n if (modality === 'pointer') {\n modality = 'virtual';\n }\n\n if (modality === 'virtual' && (typeof window !== 'undefined' && 'ontouchstart' in window)) {\n modality = 'touch';\n }\n\n return modality;\n}\n\nexport function useDragModality(): string {\n return mapModality(useInteractionModality());\n}\n\nexport function getDragModality(): string {\n return mapModality(getInteractionModality());\n}\n\nexport function writeToDataTransfer(dataTransfer: DataTransfer, items: DragItem[]): void {\n // The data transfer API doesn't support more than one item of a given type at once.\n // In addition, only a small set of types are supported natively for transfer between applications.\n // We allow for both multiple items, as well as multiple representations of a single item.\n // In order to make our API work with the native API, we serialize all items to JSON and\n // store as a single native item. We only need to do this if there is more than one item\n // of the same type, or if an item has more than one representation. Otherwise the native\n // API is sufficient.\n //\n // The DataTransferItemList API also theoretically supports adding files, which would enable\n // dragging binary data out of the browser onto the user's desktop for example. Unfortunately,\n // this does not currently work in any browser, so it is not currently supported by our API.\n // See e.g. https://bugs.chromium.org/p/chromium/issues/detail?id=438479.\n let groupedByType = new Map<string, string[]>();\n let needsCustomData = false;\n let customData: Array<{}> = [];\n for (let item of items) {\n let types = Object.keys(item);\n if (types.length > 1) {\n needsCustomData = true;\n }\n\n let dataByType = {};\n for (let type of types) {\n let typeItems = groupedByType.get(type);\n if (!typeItems) {\n typeItems = [];\n groupedByType.set(type, typeItems);\n } else {\n needsCustomData = true;\n }\n\n let data = item[type];\n dataByType[type] = data;\n typeItems.push(data);\n }\n\n customData.push(dataByType);\n }\n\n for (let [type, items] of groupedByType) {\n if (NATIVE_DRAG_TYPES.has(type)) {\n // Only one item of a given type can be set on a data transfer.\n // Join all of the items together separated by newlines.\n let data = items.join('\\n');\n dataTransfer.items.add(data, type);\n } else {\n // Set data to the first item so we have access to the list of types.\n dataTransfer.items.add(items[0], type);\n }\n }\n\n if (needsCustomData) {\n let data = JSON.stringify(customData);\n dataTransfer.items.add(data, CUSTOM_DRAG_TYPE);\n }\n}\n\nexport class DragTypes implements IDragTypes {\n private types: Set<string>;\n private includesUnknownTypes: boolean;\n\n constructor(dataTransfer: DataTransfer) {\n this.types = new Set<string>();\n\n let hasFiles = false;\n for (let item of dataTransfer.items) {\n if (item.type !== CUSTOM_DRAG_TYPE) {\n if (item.kind === 'file') {\n hasFiles = true;\n }\n\n if (item.type) {\n this.types.add(item.type);\n } else {\n // Files with unknown types or extensions that don't map to a known mime type\n // are sometimes exposed as an empty string by the browser. Map to a generic\n // mime type instead. Note that this could also be a directory as there's no\n // way to determine if something is a file or directory until drop.\n this.types.add(GENERIC_TYPE);\n }\n }\n }\n\n // In Safari, when dragging files, the dataTransfer.items list is empty, but dataTransfer.types contains \"Files\".\n // Unfortunately, this doesn't tell us what types of files the user is dragging, so we need to assume that any\n // type the user checks for is included. See https://bugs.webkit.org/show_bug.cgi?id=223517.\n this.includesUnknownTypes = !hasFiles && dataTransfer.types.includes('Files');\n }\n\n has(type: string | symbol): boolean {\n if (this.includesUnknownTypes || (type === DIRECTORY_DRAG_TYPE && this.types.has(GENERIC_TYPE))) {\n return true;\n }\n\n return typeof type === 'string' && this.types.has(type);\n }\n}\n\nexport function readFromDataTransfer(dataTransfer: DataTransfer): DropItem[] {\n let items: DropItem[] = [];\n if (!dataTransfer) {\n return items;\n }\n\n // If our custom drag type is available, use that. This is a JSON serialized\n // representation of all items in the drag, set when there are multiple items\n // of the same type, or an individual item has multiple representations.\n let hasCustomType = false;\n if (dataTransfer.types.includes(CUSTOM_DRAG_TYPE)) {\n try {\n let data = dataTransfer.getData(CUSTOM_DRAG_TYPE);\n let parsed = JSON.parse(data);\n for (let item of parsed) {\n items.push({\n kind: 'text',\n types: new Set(Object.keys(item)),\n getText: (type) => Promise.resolve(item[type])\n });\n }\n\n hasCustomType = true;\n } catch {\n // ignore\n }\n }\n\n // Otherwise, map native drag items to items of a single representation.\n if (!hasCustomType) {\n let stringItems = new Map();\n for (let item of dataTransfer.items) {\n if (item.kind === 'string') {\n // The data for all formats must be read here because the data transfer gets\n // cleared out after the event handler finishes. If the item has an empty string\n // as a type, the mime type is unknown. Map to a generic mime type instead.\n stringItems.set(item.type || GENERIC_TYPE, dataTransfer.getData(item.type));\n } else if (item.kind === 'file') {\n // Despite the name, webkitGetAsEntry is also implemented in Firefox and Edge.\n // In the future, we may use getAsFileSystemHandle instead, but that's currently\n // only implemented in Chrome.\n if (typeof item.webkitGetAsEntry === 'function') {\n let entry: FileSystemEntry | null = item.webkitGetAsEntry();\n // eslint-disable-next-line max-depth\n if (!entry) {\n // For some reason, Firefox includes an item with type image/png when copy\n // and pasting any file or directory (no matter the type), but returns `null` for both\n // item.getAsFile() and item.webkitGetAsEntry(). Safari works as expected. Ignore this\n // item if this happens. See https://bugzilla.mozilla.org/show_bug.cgi?id=1699743.\n // This was recently fixed in Chrome Canary: https://bugs.chromium.org/p/chromium/issues/detail?id=1175483.\n continue;\n }\n\n // eslint-disable-next-line max-depth\n if (entry.isFile) {\n items.push(createFileItem(item.getAsFile()));\n } else if (entry.isDirectory) {\n items.push(createDirectoryItem(entry));\n }\n } else {\n // Assume it's a file.\n items.push(createFileItem(item.getAsFile()));\n }\n }\n }\n\n // All string items are different representations of the same item. There's no way to have\n // multiple string items at once in the current DataTransfer API.\n if (stringItems.size > 0) {\n items.push({\n kind: 'text',\n types: new Set(stringItems.keys()),\n getText: (type) => Promise.resolve(stringItems.get(type))\n });\n }\n }\n\n return items;\n}\n\nfunction blobToString(blob: Blob): Promise<string> {\n if (typeof blob.text === 'function') {\n return blob.text();\n }\n\n // Safari doesn't have the Blob#text() method yet...\n return new Promise((resolve, reject) => {\n let reader = new FileReader;\n reader.onload = () => {\n resolve(reader.result as string);\n };\n\n reader.onerror = reject;\n reader.readAsText(blob);\n });\n}\n\nfunction createFileItem(file: File | null): FileDropItem {\n if (!file) {\n throw new Error('No file provided');\n }\n return {\n kind: 'file',\n type: file.type || GENERIC_TYPE,\n name: file.name,\n getText: () => blobToString(file),\n getFile: () => Promise.resolve(file)\n };\n}\n\nfunction createDirectoryItem(entry: any): DirectoryDropItem {\n return {\n kind: 'directory',\n name: entry.name,\n getEntries: () => getEntries(entry)\n };\n}\n\nasync function *getEntries(item: FileSystemDirectoryEntry): AsyncIterable<FileDropItem | DirectoryDropItem> {\n let reader = item.createReader();\n\n // We must call readEntries repeatedly because there may be a limit to the\n // number of entries that are returned at once.\n let entries: FileSystemEntry[];\n do {\n entries = await new Promise((resolve, reject) => {\n reader.readEntries(resolve, reject);\n });\n\n for (let entry of entries) {\n if (entry.isFile) {\n let file = await getEntryFile(entry as FileSystemFileEntry);\n yield createFileItem(file);\n } else if (entry.isDirectory) {\n yield createDirectoryItem(entry);\n }\n }\n } while (entries.length > 0);\n}\n\nfunction getEntryFile(entry: FileSystemFileEntry): Promise<File> {\n return new Promise((resolve, reject) => entry.file(resolve, reject));\n}\n\n/** Returns whether a drop item contains text data. */\nexport function isTextDropItem(dropItem: DropItem): dropItem is TextDropItem {\n return dropItem.kind === 'text';\n}\n\n/** Returns whether a drop item is a file. */\nexport function isFileDropItem(dropItem: DropItem): dropItem is FileDropItem {\n return dropItem.kind === 'file';\n}\n\n/** Returns whether a drop item is a directory. */\nexport function isDirectoryDropItem(dropItem: DropItem): dropItem is DirectoryDropItem {\n return dropItem.kind === 'directory';\n}\n\n// Global DnD collection state tracker.\nexport interface DnDState {\n /** A ref for the of the drag items in the current drag session if any. */\n draggingCollectionRef?: RefObject<HTMLElement | null>,\n /** The set of currently dragged keys. */\n draggingKeys: Set<Key>,\n /** A ref for the collection that is targeted for a drop operation, if any. */\n dropCollectionRef?: RefObject<HTMLElement | null>\n}\n\nexport let globalDndState: DnDState = {draggingKeys: new Set()};\n\nexport function setDraggingCollectionRef(ref: RefObject<HTMLElement | null>): void {\n globalDndState.draggingCollectionRef = ref;\n}\n\nexport function setDraggingKeys(keys: Set<Key>): void {\n globalDndState.draggingKeys = keys;\n}\n\nexport function setDropCollectionRef(ref?: RefObject<HTMLElement | null>): void {\n globalDndState.dropCollectionRef = ref;\n}\n\nexport function clearGlobalDnDState(): void {\n globalDndState = {draggingKeys: new Set()};\n}\n\nexport function setGlobalDnDState(state: DnDState): void {\n globalDndState = state;\n}\n\n// Util function to check if the current dragging collection ref is the same as the current targeted droppable collection ref.\n// Allows a droppable ref arg in case the global drop collection ref hasn't been set\nexport function isInternalDropOperation(ref?: RefObject<HTMLElement | null>): boolean {\n let {draggingCollectionRef, dropCollectionRef} = globalDndState;\n return draggingCollectionRef?.current != null && draggingCollectionRef.current === (ref?.current || dropCollectionRef?.current);\n}\n\ntype DropEffect = 'none' | 'copy' | 'link' | 'move';\nexport let globalDropEffect: DropEffect | undefined;\nexport function setGlobalDropEffect(dropEffect: DropEffect | undefined): void {\n globalDropEffect = dropEffect;\n}\n\nexport let globalAllowedDropOperations = DROP_OPERATION.none;\nexport function setGlobalAllowedDropOperations(o: DROP_OPERATION): void {\n globalAllowedDropOperations = o;\n}\n"],"names":[],"version":3,"file":"utils.main.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAYM,MAAM,4CAAoF,IAAI;AAC9F,MAAM,4CAA8B;AAEpC,SAAS,0CAAyB,KAA+B;IACtE,IAAI,MAAC,EAAE,EAAC,GAAG,0CAAuB,GAAG,CAAC,UAAU,CAAC;IACjD,IAAI,CAAC,IACH,MAAM,IAAI,MAAM;IAGlB,OAAO;AACT;AAEO,SAAS,0CAA0B,KAA+B;IACvE,IAAI,OAAC,GAAG,EAAC,GAAG,0CAAuB,GAAG,CAAC,UAAU,CAAC;IAClD,IAAI,CAAC,KACH,MAAM,IAAI,MAAM;IAGlB,OAAO;AACT;AAEO,SAAS,0CAAS,KAAiB;IACxC,IAAI,QAAQ,IAAI;IAChB,KAAK,IAAI,QAAQ,MACf,KAAK,IAAI,QAAQ,OAAO,IAAI,CAAC,MAC3B,MAAM,GAAG,CAAC;IAId,OAAO;AACT;AAEA,SAAS,kCAAY,QAAuB;IAC1C,IAAI,CAAC,UACH,WAAW;IAGb,IAAI,aAAa,WACf,WAAW;IAGb,IAAI,aAAa,aAAe,OAAO,WAAW,eAAe,kBAAkB,QACjF,WAAW;IAGb,OAAO;AACT;AAEO,SAAS;IACd,OAAO,kCAAY,CAAA,GAAA,mDAAqB;AAC1C;AAEO,SAAS;IACd,OAAO,kCAAY,CAAA,GAAA,mDAAqB;AAC1C;AAEO,SAAS,0CAAoB,YAA0B,EAAE,KAAiB;IAC/E,oFAAoF;IACpF,mGAAmG;IACnG,0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AAS,0CAAkB,KAAe;IAC/C,4CAAiB;AACnB;AAIO,SAAS,0CAAwB,GAAmC;IACzE,IAAI,yBAAC,qBAAqB,qBAAE,iBAAiB,EAAC,GAAG;IACjD,OAAO,CAAA,kCAAA,4CAAA,sBAAuB,OAAO,KAAI,QAAQ,sBAAsB,OAAO,KAAM,CAAA,CAAA,gBAAA,0BAAA,IAAK,OAAO,MAAI,8BAAA,wCAAA,kBAAmB,OAAO,CAAD;AAC/H;AAGO,IAAI;AACJ,SAAS,0CAAoB,UAAkC;IACpE,4CAAmB;AACrB;AAEO,IAAI,4CAA8C,CAAA,GAAA,wCAAa,EAAE,IAAI;AACrE,SAAS,0CAA+B,CAAiB;IAC9D,4CAA8B;AAChC","sources":["packages/@react-aria/dnd/src/utils.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 {CUSTOM_DRAG_TYPE, DROP_OPERATION, GENERIC_TYPE, NATIVE_DRAG_TYPES} from './constants';\nimport {DirectoryDropItem, DragItem, DropItem, FileDropItem, DragTypes as IDragTypes, Key, RefObject, TextDropItem} from '@react-types/shared';\nimport {DroppableCollectionState} from '@react-stately/dnd';\nimport {getInteractionModality, useInteractionModality} from '@react-aria/interactions';\n\ninterface DroppableCollectionMap {\n id: string,\n ref: RefObject<HTMLElement | null>\n}\n\nexport const droppableCollectionMap: WeakMap<DroppableCollectionState, DroppableCollectionMap> = new WeakMap<DroppableCollectionState, DroppableCollectionMap>();\nexport const DIRECTORY_DRAG_TYPE: symbol = Symbol();\n\nexport function getDroppableCollectionId(state: DroppableCollectionState): string {\n let {id} = droppableCollectionMap.get(state) || {};\n if (!id) {\n throw new Error('Droppable item outside a droppable collection');\n }\n\n return id;\n}\n\nexport function getDroppableCollectionRef(state: DroppableCollectionState): RefObject<HTMLElement | null> {\n let {ref} = droppableCollectionMap.get(state) || {};\n if (!ref) {\n throw new Error('Droppable item outside a droppable collection');\n }\n\n return ref;\n}\n\nexport function getTypes(items: DragItem[]): Set<string> {\n let types = new Set<string>();\n for (let item of items) {\n for (let type of Object.keys(item)) {\n types.add(type);\n }\n }\n\n return types;\n}\n\nfunction mapModality(modality: string | null) {\n if (!modality) {\n modality = 'virtual';\n }\n\n if (modality === 'pointer') {\n modality = 'virtual';\n }\n\n if (modality === 'virtual' && (typeof window !== 'undefined' && 'ontouchstart' in window)) {\n modality = 'touch';\n }\n\n return modality;\n}\n\nexport function useDragModality(): string {\n return mapModality(useInteractionModality());\n}\n\nexport function getDragModality(): string {\n return mapModality(getInteractionModality());\n}\n\nexport function writeToDataTransfer(dataTransfer: DataTransfer, items: DragItem[]): void {\n // The data transfer API doesn't support more than one item of a given type at once.\n // In addition, only a small set of types are supported natively for transfer between applications.\n // We allow for both multiple items, as well as multiple representations of a single item.\n // In order to make our API work with the native API, we serialize all items to JSON and\n // store as a single native item. We only need to do this if there is more than one item\n // of the same type, or if an item has more than one representation. Otherwise the native\n // API is sufficient.\n //\n // The DataTransferItemList API also theoretically supports adding files, which would enable\n // dragging binary data out of the browser onto the user's desktop for example. Unfortunately,\n // this does not currently work in any browser, so it is not currently supported by our API.\n // See e.g. https://bugs.chromium.org/p/chromium/issues/detail?id=438479.\n let groupedByType = new Map<string, string[]>();\n let needsCustomData = false;\n let customData: Array<{}> = [];\n for (let item of items) {\n let types = Object.keys(item);\n if (types.length > 1) {\n needsCustomData = true;\n }\n\n let dataByType = {};\n for (let type of types) {\n let typeItems = groupedByType.get(type);\n if (!typeItems) {\n typeItems = [];\n groupedByType.set(type, typeItems);\n } else {\n needsCustomData = true;\n }\n\n let data = item[type];\n dataByType[type] = data;\n typeItems.push(data);\n }\n\n customData.push(dataByType);\n }\n\n for (let [type, items] of groupedByType) {\n if (NATIVE_DRAG_TYPES.has(type)) {\n // Only one item of a given type can be set on a data transfer.\n // Join all of the items together separated by newlines.\n let data = items.join('\\n');\n dataTransfer.items.add(data, type);\n } else {\n // Set data to the first item so we have access to the list of types.\n dataTransfer.items.add(items[0], type);\n }\n }\n\n if (needsCustomData) {\n let data = JSON.stringify(customData);\n dataTransfer.items.add(data, CUSTOM_DRAG_TYPE);\n }\n}\n\nexport class DragTypes implements IDragTypes {\n private types: Set<string>;\n private includesUnknownTypes: boolean;\n\n constructor(dataTransfer: DataTransfer) {\n this.types = new Set<string>();\n\n let hasFiles = false;\n for (let item of dataTransfer.items) {\n if (item.type !== CUSTOM_DRAG_TYPE) {\n if (item.kind === 'file') {\n hasFiles = true;\n }\n\n if (item.type) {\n this.types.add(item.type);\n } else {\n // Files with unknown types or extensions that don't map to a known mime type\n // are sometimes exposed as an empty string by the browser. Map to a generic\n // mime type instead. Note that this could also be a directory as there's no\n // way to determine if something is a file or directory until drop.\n this.types.add(GENERIC_TYPE);\n }\n }\n }\n\n // In Safari, when dragging files, the dataTransfer.items list is empty, but dataTransfer.types contains \"Files\".\n // Unfortunately, this doesn't tell us what types of files the user is dragging, so we need to assume that any\n // type the user checks for is included. See https://bugs.webkit.org/show_bug.cgi?id=223517.\n this.includesUnknownTypes = !hasFiles && dataTransfer.types.includes('Files');\n }\n\n has(type: string | symbol): boolean {\n if (this.includesUnknownTypes || (type === DIRECTORY_DRAG_TYPE && this.types.has(GENERIC_TYPE))) {\n return true;\n }\n\n return typeof type === 'string' && this.types.has(type);\n }\n}\n\nexport function readFromDataTransfer(dataTransfer: DataTransfer): DropItem[] {\n let items: DropItem[] = [];\n if (!dataTransfer) {\n return items;\n }\n\n // If our custom drag type is available, use that. This is a JSON serialized\n // representation of all items in the drag, set when there are multiple items\n // of the same type, or an individual item has multiple representations.\n let hasCustomType = false;\n if (dataTransfer.types.includes(CUSTOM_DRAG_TYPE)) {\n try {\n let data = dataTransfer.getData(CUSTOM_DRAG_TYPE);\n let parsed = JSON.parse(data);\n for (let item of parsed) {\n items.push({\n kind: 'text',\n types: new Set(Object.keys(item)),\n getText: (type) => Promise.resolve(item[type])\n });\n }\n\n hasCustomType = true;\n } catch {\n // ignore\n }\n }\n\n // Otherwise, map native drag items to items of a single representation.\n if (!hasCustomType) {\n let stringItems = new Map();\n for (let item of dataTransfer.items) {\n if (item.kind === 'string') {\n // The data for all formats must be read here because the data transfer gets\n // cleared out after the event handler finishes. If the item has an empty string\n // as a type, the mime type is unknown. Map to a generic mime type instead.\n stringItems.set(item.type || GENERIC_TYPE, dataTransfer.getData(item.type));\n } else if (item.kind === 'file') {\n // Despite the name, webkitGetAsEntry is also implemented in Firefox and Edge.\n // In the future, we may use getAsFileSystemHandle instead, but that's currently\n // only implemented in Chrome.\n if (typeof item.webkitGetAsEntry === 'function') {\n let entry: FileSystemEntry | null = item.webkitGetAsEntry();\n // eslint-disable-next-line max-depth\n if (!entry) {\n // For some reason, Firefox includes an item with type image/png when copy\n // and pasting any file or directory (no matter the type), but returns `null` for both\n // item.getAsFile() and item.webkitGetAsEntry(). Safari works as expected. Ignore this\n // item if this happens. See https://bugzilla.mozilla.org/show_bug.cgi?id=1699743.\n // This was recently fixed in Chrome Canary: https://bugs.chromium.org/p/chromium/issues/detail?id=1175483.\n continue;\n }\n\n // eslint-disable-next-line max-depth\n if (entry.isFile) {\n items.push(createFileItem(item.getAsFile()));\n } else if (entry.isDirectory) {\n items.push(createDirectoryItem(entry));\n }\n } else {\n // Assume it's a file.\n items.push(createFileItem(item.getAsFile()));\n }\n }\n }\n\n // All string items are different representations of the same item. There's no way to have\n // multiple string items at once in the current DataTransfer API.\n if (stringItems.size > 0) {\n items.push({\n kind: 'text',\n types: new Set(stringItems.keys()),\n getText: (type) => Promise.resolve(stringItems.get(type))\n });\n }\n }\n\n return items;\n}\n\nfunction blobToString(blob: Blob): Promise<string> {\n if (typeof blob.text === 'function') {\n return blob.text();\n }\n\n // Safari doesn't have the Blob#text() method yet...\n return new Promise((resolve, reject) => {\n let reader = new FileReader;\n reader.onload = () => {\n resolve(reader.result as string);\n };\n\n reader.onerror = reject;\n reader.readAsText(blob);\n });\n}\n\nfunction createFileItem(file: File | null): FileDropItem {\n if (!file) {\n throw new Error('No file provided');\n }\n return {\n kind: 'file',\n type: file.type || GENERIC_TYPE,\n name: file.name,\n getText: () => blobToString(file),\n getFile: () => Promise.resolve(file)\n };\n}\n\nfunction createDirectoryItem(entry: any): DirectoryDropItem {\n return {\n kind: 'directory',\n name: entry.name,\n getEntries: () => getEntries(entry)\n };\n}\n\nasync function *getEntries(item: FileSystemDirectoryEntry): AsyncIterable<FileDropItem | DirectoryDropItem> {\n let reader = item.createReader();\n\n // We must call readEntries repeatedly because there may be a limit to the\n // number of entries that are returned at once.\n let entries: FileSystemEntry[];\n do {\n entries = await new Promise((resolve, reject) => {\n reader.readEntries(resolve, reject);\n });\n\n for (let entry of entries) {\n if (entry.isFile) {\n let file = await getEntryFile(entry as FileSystemFileEntry);\n yield createFileItem(file);\n } else if (entry.isDirectory) {\n yield createDirectoryItem(entry);\n }\n }\n } while (entries.length > 0);\n}\n\nfunction getEntryFile(entry: FileSystemFileEntry): Promise<File> {\n return new Promise((resolve, reject) => entry.file(resolve, reject));\n}\n\n/** Returns whether a drop item contains text data. */\nexport function isTextDropItem(dropItem: DropItem): dropItem is TextDropItem {\n return dropItem.kind === 'text';\n}\n\n/** Returns whether a drop item is a file. */\nexport function isFileDropItem(dropItem: DropItem): dropItem is FileDropItem {\n return dropItem.kind === 'file';\n}\n\n/** Returns whether a drop item is a directory. */\nexport function isDirectoryDropItem(dropItem: DropItem): dropItem is DirectoryDropItem {\n return dropItem.kind === 'directory';\n}\n\n// Global DnD collection state tracker.\nexport interface DnDState {\n /** A ref for the of the drag items in the current drag session if any. */\n draggingCollectionRef?: RefObject<HTMLElement | null>,\n /** The set of currently dragged keys. */\n draggingKeys: Set<Key>,\n /** A ref for the collection that is targeted for a drop operation, if any. */\n dropCollectionRef?: RefObject<HTMLElement | null>\n}\n\nexport let globalDndState: DnDState = {draggingKeys: new Set()};\n\nexport function setDraggingCollectionRef(ref: RefObject<HTMLElement | null>): void {\n globalDndState.draggingCollectionRef = ref;\n}\n\nexport function setDraggingKeys(keys: Set<Key>): void {\n globalDndState.draggingKeys = keys;\n}\n\nexport function setDropCollectionRef(ref?: RefObject<HTMLElement | null>): void {\n globalDndState.dropCollectionRef = ref;\n}\n\nexport function clearGlobalDnDState(): void {\n globalDndState = {draggingKeys: new Set()};\n}\n\nexport function setGlobalDnDState(state: DnDState): void {\n globalDndState = state;\n}\n\n// Util function to check if the current dragging collection ref is the same as the current targeted droppable collection ref.\n// Allows a droppable ref arg in case the global drop collection ref hasn't been set\nexport function isInternalDropOperation(ref?: RefObject<HTMLElement | null>): boolean {\n let {draggingCollectionRef, dropCollectionRef} = globalDndState;\n return draggingCollectionRef?.current != null && draggingCollectionRef.current === (ref?.current || dropCollectionRef?.current);\n}\n\ntype DropEffect = 'none' | 'copy' | 'link' | 'move';\nexport let globalDropEffect: DropEffect | undefined;\nexport function setGlobalDropEffect(dropEffect: DropEffect | undefined): void {\n globalDropEffect = dropEffect;\n}\n\nexport let globalAllowedDropOperations: DROP_OPERATION = DROP_OPERATION.none;\nexport function setGlobalAllowedDropOperations(o: DROP_OPERATION): void {\n globalAllowedDropOperations = o;\n}\n"],"names":[],"version":3,"file":"utils.main.js.map"}
@@ -1 +1 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAYM,MAAM,4CAAyB,IAAI;AACnC,MAAM,4CAAsB;AAE5B,SAAS,0CAAyB,KAA+B;IACtE,IAAI,MAAC,EAAE,EAAC,GAAG,0CAAuB,GAAG,CAAC,UAAU,CAAC;IACjD,IAAI,CAAC,IACH,MAAM,IAAI,MAAM;IAGlB,OAAO;AACT;AAEO,SAAS,0CAA0B,KAA+B;IACvE,IAAI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9B;IACF,QAAS,QAAQ,MAAM,GAAG,GAAG;AAC/B;AAEA,SAAS,mCAAa,KAA0B;IAC9C,OAAO,IAAI,QAAQ,CAAC,SAAS,SAAW,MAAM,IAAI,CAAC,SAAS;AAC9D;AAGO,SAAS,0CAAe,QAAkB;IAC/C,OAAO,SAAS,IAAI,KAAK;AAC3B;AAGO,SAAS,yCAAe,QAAkB;IAC/C,OAAO,SAAS,IAAI,KAAK;AAC3B;AAGO,SAAS,0CAAoB,QAAkB;IACpD,OAAO,SAAS,IAAI,KAAK;AAC3B;AAYO,IAAI,4CAA2B;IAAC,cAAc,IAAI;AAAK;AAEvD,SAAS,0CAAyB,GAAkC;IACzE,0CAAe,qBAAqB,GAAG;AACzC;AAEO,SAAS,0CAAgB,IAAc;IAC5C,0CAAe,YAAY,GAAG;AAChC;AAEO,SAAS,0CAAqB,GAAmC;IACtE,0CAAe,iBAAiB,GAAG;AACrC;AAEO,SAAS;IACd,4CAAiB;QAAC,cAAc,IAAI;IAAK;AAC3C;AAEO,SAAS,0CAAkB,KAAe;IAC/C,4CAAiB;AACnB;AAIO,SAAS,0CAAwB,GAAmC;IACzE,IAAI,yBAAC,qBAAqB,qBAAE,iBAAiB,EAAC,GAAG;IACjD,OAAO,CAAA,kCAAA,4CAAA,sBAAuB,OAAO,KAAI,QAAQ,sBAAsB,OAAO,KAAM,CAAA,CAAA,gBAAA,0BAAA,IAAK,OAAO,MAAI,8BAAA,wCAAA,kBAAmB,OAAO,CAAD;AAC/H;AAGO,IAAI;AACJ,SAAS,0CAAoB,UAAkC;IACpE,4CAAmB;AACrB;AAEO,IAAI,4CAA8B,CAAA,GAAA,yCAAa,EAAE,IAAI;AACrD,SAAS,0CAA+B,CAAiB;IAC9D,4CAA8B;AAChC","sources":["packages/@react-aria/dnd/src/utils.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 {CUSTOM_DRAG_TYPE, DROP_OPERATION, GENERIC_TYPE, NATIVE_DRAG_TYPES} from './constants';\nimport {DirectoryDropItem, DragItem, DropItem, FileDropItem, DragTypes as IDragTypes, Key, RefObject, TextDropItem} from '@react-types/shared';\nimport {DroppableCollectionState} from '@react-stately/dnd';\nimport {getInteractionModality, useInteractionModality} from '@react-aria/interactions';\n\ninterface DroppableCollectionMap {\n id: string,\n ref: RefObject<HTMLElement | null>\n}\n\nexport const droppableCollectionMap = new WeakMap<DroppableCollectionState, DroppableCollectionMap>();\nexport const DIRECTORY_DRAG_TYPE = Symbol();\n\nexport function getDroppableCollectionId(state: DroppableCollectionState): string {\n let {id} = droppableCollectionMap.get(state) || {};\n if (!id) {\n throw new Error('Droppable item outside a droppable collection');\n }\n\n return id;\n}\n\nexport function getDroppableCollectionRef(state: DroppableCollectionState): RefObject<HTMLElement | null> {\n let {ref} = droppableCollectionMap.get(state) || {};\n if (!ref) {\n throw new Error('Droppable item outside a droppable collection');\n }\n\n return ref;\n}\n\nexport function getTypes(items: DragItem[]): Set<string> {\n let types = new Set<string>();\n for (let item of items) {\n for (let type of Object.keys(item)) {\n types.add(type);\n }\n }\n\n return types;\n}\n\nfunction mapModality(modality: string | null) {\n if (!modality) {\n modality = 'virtual';\n }\n\n if (modality === 'pointer') {\n modality = 'virtual';\n }\n\n if (modality === 'virtual' && (typeof window !== 'undefined' && 'ontouchstart' in window)) {\n modality = 'touch';\n }\n\n return modality;\n}\n\nexport function useDragModality(): string {\n return mapModality(useInteractionModality());\n}\n\nexport function getDragModality(): string {\n return mapModality(getInteractionModality());\n}\n\nexport function writeToDataTransfer(dataTransfer: DataTransfer, items: DragItem[]): void {\n // The data transfer API doesn't support more than one item of a given type at once.\n // In addition, only a small set of types are supported natively for transfer between applications.\n // We allow for both multiple items, as well as multiple representations of a single item.\n // In order to make our API work with the native API, we serialize all items to JSON and\n // store as a single native item. We only need to do this if there is more than one item\n // of the same type, or if an item has more than one representation. Otherwise the native\n // API is sufficient.\n //\n // The DataTransferItemList API also theoretically supports adding files, which would enable\n // dragging binary data out of the browser onto the user's desktop for example. Unfortunately,\n // this does not currently work in any browser, so it is not currently supported by our API.\n // See e.g. https://bugs.chromium.org/p/chromium/issues/detail?id=438479.\n let groupedByType = new Map<string, string[]>();\n let needsCustomData = false;\n let customData: Array<{}> = [];\n for (let item of items) {\n let types = Object.keys(item);\n if (types.length > 1) {\n needsCustomData = true;\n }\n\n let dataByType = {};\n for (let type of types) {\n let typeItems = groupedByType.get(type);\n if (!typeItems) {\n typeItems = [];\n groupedByType.set(type, typeItems);\n } else {\n needsCustomData = true;\n }\n\n let data = item[type];\n dataByType[type] = data;\n typeItems.push(data);\n }\n\n customData.push(dataByType);\n }\n\n for (let [type, items] of groupedByType) {\n if (NATIVE_DRAG_TYPES.has(type)) {\n // Only one item of a given type can be set on a data transfer.\n // Join all of the items together separated by newlines.\n let data = items.join('\\n');\n dataTransfer.items.add(data, type);\n } else {\n // Set data to the first item so we have access to the list of types.\n dataTransfer.items.add(items[0], type);\n }\n }\n\n if (needsCustomData) {\n let data = JSON.stringify(customData);\n dataTransfer.items.add(data, CUSTOM_DRAG_TYPE);\n }\n}\n\nexport class DragTypes implements IDragTypes {\n private types: Set<string>;\n private includesUnknownTypes: boolean;\n\n constructor(dataTransfer: DataTransfer) {\n this.types = new Set<string>();\n\n let hasFiles = false;\n for (let item of dataTransfer.items) {\n if (item.type !== CUSTOM_DRAG_TYPE) {\n if (item.kind === 'file') {\n hasFiles = true;\n }\n\n if (item.type) {\n this.types.add(item.type);\n } else {\n // Files with unknown types or extensions that don't map to a known mime type\n // are sometimes exposed as an empty string by the browser. Map to a generic\n // mime type instead. Note that this could also be a directory as there's no\n // way to determine if something is a file or directory until drop.\n this.types.add(GENERIC_TYPE);\n }\n }\n }\n\n // In Safari, when dragging files, the dataTransfer.items list is empty, but dataTransfer.types contains \"Files\".\n // Unfortunately, this doesn't tell us what types of files the user is dragging, so we need to assume that any\n // type the user checks for is included. See https://bugs.webkit.org/show_bug.cgi?id=223517.\n this.includesUnknownTypes = !hasFiles && dataTransfer.types.includes('Files');\n }\n\n has(type: string | symbol): boolean {\n if (this.includesUnknownTypes || (type === DIRECTORY_DRAG_TYPE && this.types.has(GENERIC_TYPE))) {\n return true;\n }\n\n return typeof type === 'string' && this.types.has(type);\n }\n}\n\nexport function readFromDataTransfer(dataTransfer: DataTransfer): DropItem[] {\n let items: DropItem[] = [];\n if (!dataTransfer) {\n return items;\n }\n\n // If our custom drag type is available, use that. This is a JSON serialized\n // representation of all items in the drag, set when there are multiple items\n // of the same type, or an individual item has multiple representations.\n let hasCustomType = false;\n if (dataTransfer.types.includes(CUSTOM_DRAG_TYPE)) {\n try {\n let data = dataTransfer.getData(CUSTOM_DRAG_TYPE);\n let parsed = JSON.parse(data);\n for (let item of parsed) {\n items.push({\n kind: 'text',\n types: new Set(Object.keys(item)),\n getText: (type) => Promise.resolve(item[type])\n });\n }\n\n hasCustomType = true;\n } catch {\n // ignore\n }\n }\n\n // Otherwise, map native drag items to items of a single representation.\n if (!hasCustomType) {\n let stringItems = new Map();\n for (let item of dataTransfer.items) {\n if (item.kind === 'string') {\n // The data for all formats must be read here because the data transfer gets\n // cleared out after the event handler finishes. If the item has an empty string\n // as a type, the mime type is unknown. Map to a generic mime type instead.\n stringItems.set(item.type || GENERIC_TYPE, dataTransfer.getData(item.type));\n } else if (item.kind === 'file') {\n // Despite the name, webkitGetAsEntry is also implemented in Firefox and Edge.\n // In the future, we may use getAsFileSystemHandle instead, but that's currently\n // only implemented in Chrome.\n if (typeof item.webkitGetAsEntry === 'function') {\n let entry: FileSystemEntry | null = item.webkitGetAsEntry();\n // eslint-disable-next-line max-depth\n if (!entry) {\n // For some reason, Firefox includes an item with type image/png when copy\n // and pasting any file or directory (no matter the type), but returns `null` for both\n // item.getAsFile() and item.webkitGetAsEntry(). Safari works as expected. Ignore this\n // item if this happens. See https://bugzilla.mozilla.org/show_bug.cgi?id=1699743.\n // This was recently fixed in Chrome Canary: https://bugs.chromium.org/p/chromium/issues/detail?id=1175483.\n continue;\n }\n\n // eslint-disable-next-line max-depth\n if (entry.isFile) {\n items.push(createFileItem(item.getAsFile()));\n } else if (entry.isDirectory) {\n items.push(createDirectoryItem(entry));\n }\n } else {\n // Assume it's a file.\n items.push(createFileItem(item.getAsFile()));\n }\n }\n }\n\n // All string items are different representations of the same item. There's no way to have\n // multiple string items at once in the current DataTransfer API.\n if (stringItems.size > 0) {\n items.push({\n kind: 'text',\n types: new Set(stringItems.keys()),\n getText: (type) => Promise.resolve(stringItems.get(type))\n });\n }\n }\n\n return items;\n}\n\nfunction blobToString(blob: Blob): Promise<string> {\n if (typeof blob.text === 'function') {\n return blob.text();\n }\n\n // Safari doesn't have the Blob#text() method yet...\n return new Promise((resolve, reject) => {\n let reader = new FileReader;\n reader.onload = () => {\n resolve(reader.result as string);\n };\n\n reader.onerror = reject;\n reader.readAsText(blob);\n });\n}\n\nfunction createFileItem(file: File | null): FileDropItem {\n if (!file) {\n throw new Error('No file provided');\n }\n return {\n kind: 'file',\n type: file.type || GENERIC_TYPE,\n name: file.name,\n getText: () => blobToString(file),\n getFile: () => Promise.resolve(file)\n };\n}\n\nfunction createDirectoryItem(entry: any): DirectoryDropItem {\n return {\n kind: 'directory',\n name: entry.name,\n getEntries: () => getEntries(entry)\n };\n}\n\nasync function *getEntries(item: FileSystemDirectoryEntry): AsyncIterable<FileDropItem | DirectoryDropItem> {\n let reader = item.createReader();\n\n // We must call readEntries repeatedly because there may be a limit to the\n // number of entries that are returned at once.\n let entries: FileSystemEntry[];\n do {\n entries = await new Promise((resolve, reject) => {\n reader.readEntries(resolve, reject);\n });\n\n for (let entry of entries) {\n if (entry.isFile) {\n let file = await getEntryFile(entry as FileSystemFileEntry);\n yield createFileItem(file);\n } else if (entry.isDirectory) {\n yield createDirectoryItem(entry);\n }\n }\n } while (entries.length > 0);\n}\n\nfunction getEntryFile(entry: FileSystemFileEntry): Promise<File> {\n return new Promise((resolve, reject) => entry.file(resolve, reject));\n}\n\n/** Returns whether a drop item contains text data. */\nexport function isTextDropItem(dropItem: DropItem): dropItem is TextDropItem {\n return dropItem.kind === 'text';\n}\n\n/** Returns whether a drop item is a file. */\nexport function isFileDropItem(dropItem: DropItem): dropItem is FileDropItem {\n return dropItem.kind === 'file';\n}\n\n/** Returns whether a drop item is a directory. */\nexport function isDirectoryDropItem(dropItem: DropItem): dropItem is DirectoryDropItem {\n return dropItem.kind === 'directory';\n}\n\n// Global DnD collection state tracker.\nexport interface DnDState {\n /** A ref for the of the drag items in the current drag session if any. */\n draggingCollectionRef?: RefObject<HTMLElement | null>,\n /** The set of currently dragged keys. */\n draggingKeys: Set<Key>,\n /** A ref for the collection that is targeted for a drop operation, if any. */\n dropCollectionRef?: RefObject<HTMLElement | null>\n}\n\nexport let globalDndState: DnDState = {draggingKeys: new Set()};\n\nexport function setDraggingCollectionRef(ref: RefObject<HTMLElement | null>): void {\n globalDndState.draggingCollectionRef = ref;\n}\n\nexport function setDraggingKeys(keys: Set<Key>): void {\n globalDndState.draggingKeys = keys;\n}\n\nexport function setDropCollectionRef(ref?: RefObject<HTMLElement | null>): void {\n globalDndState.dropCollectionRef = ref;\n}\n\nexport function clearGlobalDnDState(): void {\n globalDndState = {draggingKeys: new Set()};\n}\n\nexport function setGlobalDnDState(state: DnDState): void {\n globalDndState = state;\n}\n\n// Util function to check if the current dragging collection ref is the same as the current targeted droppable collection ref.\n// Allows a droppable ref arg in case the global drop collection ref hasn't been set\nexport function isInternalDropOperation(ref?: RefObject<HTMLElement | null>): boolean {\n let {draggingCollectionRef, dropCollectionRef} = globalDndState;\n return draggingCollectionRef?.current != null && draggingCollectionRef.current === (ref?.current || dropCollectionRef?.current);\n}\n\ntype DropEffect = 'none' | 'copy' | 'link' | 'move';\nexport let globalDropEffect: DropEffect | undefined;\nexport function setGlobalDropEffect(dropEffect: DropEffect | undefined): void {\n globalDropEffect = dropEffect;\n}\n\nexport let globalAllowedDropOperations = DROP_OPERATION.none;\nexport function setGlobalAllowedDropOperations(o: DROP_OPERATION): void {\n globalAllowedDropOperations = o;\n}\n"],"names":[],"version":3,"file":"utils.module.js.map"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAYM,MAAM,4CAAoF,IAAI;AAC9F,MAAM,4CAA8B;AAEpC,SAAS,0CAAyB,KAA+B;IACtE,IAAI,MAAC,EAAE,EAAC,GAAG,0CAAuB,GAAG,CAAC,UAAU,CAAC;IACjD,IAAI,CAAC,IACH,MAAM,IAAI,MAAM;IAGlB,OAAO;AACT;AAEO,SAAS,0CAA0B,KAA+B;IACvE,IAAI,OAAC,GAAG,EAAC,GAAG,0CAAuB,GAAG,CAAC,UAAU,CAAC;IAClD,IAAI,CAAC,KACH,MAAM,IAAI,MAAM;IAGlB,OAAO;AACT;AAEO,SAAS,0CAAS,KAAiB;IACxC,IAAI,QAAQ,IAAI;IAChB,KAAK,IAAI,QAAQ,MACf,KAAK,IAAI,QAAQ,OAAO,IAAI,CAAC,MAC3B,MAAM,GAAG,CAAC;IAId,OAAO;AACT;AAEA,SAAS,kCAAY,QAAuB;IAC1C,IAAI,CAAC,UACH,WAAW;IAGb,IAAI,aAAa,WACf,WAAW;IAGb,IAAI,aAAa,aAAe,OAAO,WAAW,eAAe,kBAAkB,QACjF,WAAW;IAGb,OAAO;AACT;AAEO,SAAS;IACd,OAAO,kCAAY,CAAA,GAAA,6BAAqB;AAC1C;AAEO,SAAS;IACd,OAAO,kCAAY,CAAA,GAAA,6BAAqB;AAC1C;AAEO,SAAS,0CAAoB,YAA0B,EAAE,KAAiB;IAC/E,oFAAoF;IACpF,mGAAmG;IACnG,0FAA0F;IAC1F,wFAAwF;I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C,4CAAiB;AACnB;AAIO,SAAS,0CAAwB,GAAmC;IACzE,IAAI,yBAAC,qBAAqB,qBAAE,iBAAiB,EAAC,GAAG;IACjD,OAAO,CAAA,kCAAA,4CAAA,sBAAuB,OAAO,KAAI,QAAQ,sBAAsB,OAAO,KAAM,CAAA,CAAA,gBAAA,0BAAA,IAAK,OAAO,MAAI,8BAAA,wCAAA,kBAAmB,OAAO,CAAD;AAC/H;AAGO,IAAI;AACJ,SAAS,0CAAoB,UAAkC;IACpE,4CAAmB;AACrB;AAEO,IAAI,4CAA8C,CAAA,GAAA,yCAAa,EAAE,IAAI;AACrE,SAAS,0CAA+B,CAAiB;IAC9D,4CAA8B;AAChC","sources":["packages/@react-aria/dnd/src/utils.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 {CUSTOM_DRAG_TYPE, DROP_OPERATION, GENERIC_TYPE, NATIVE_DRAG_TYPES} from './constants';\nimport {DirectoryDropItem, DragItem, DropItem, FileDropItem, DragTypes as IDragTypes, Key, RefObject, TextDropItem} from '@react-types/shared';\nimport {DroppableCollectionState} from '@react-stately/dnd';\nimport {getInteractionModality, useInteractionModality} from '@react-aria/interactions';\n\ninterface DroppableCollectionMap {\n id: string,\n ref: RefObject<HTMLElement | null>\n}\n\nexport const droppableCollectionMap: WeakMap<DroppableCollectionState, DroppableCollectionMap> = new WeakMap<DroppableCollectionState, DroppableCollectionMap>();\nexport const DIRECTORY_DRAG_TYPE: symbol = Symbol();\n\nexport function getDroppableCollectionId(state: DroppableCollectionState): string {\n let {id} = droppableCollectionMap.get(state) || {};\n if (!id) {\n throw new Error('Droppable item outside a droppable collection');\n }\n\n return id;\n}\n\nexport function getDroppableCollectionRef(state: DroppableCollectionState): RefObject<HTMLElement | null> {\n let {ref} = droppableCollectionMap.get(state) || {};\n if (!ref) {\n throw new Error('Droppable item outside a droppable collection');\n }\n\n return ref;\n}\n\nexport function getTypes(items: DragItem[]): Set<string> {\n let types = new Set<string>();\n for (let item of items) {\n for (let type of Object.keys(item)) {\n types.add(type);\n }\n }\n\n return types;\n}\n\nfunction mapModality(modality: string | null) {\n if (!modality) {\n modality = 'virtual';\n }\n\n if (modality === 'pointer') {\n modality = 'virtual';\n }\n\n if (modality === 'virtual' && (typeof window !== 'undefined' && 'ontouchstart' in window)) {\n modality = 'touch';\n }\n\n return modality;\n}\n\nexport function useDragModality(): string {\n return mapModality(useInteractionModality());\n}\n\nexport function getDragModality(): string {\n return mapModality(getInteractionModality());\n}\n\nexport function writeToDataTransfer(dataTransfer: DataTransfer, items: DragItem[]): void {\n // The data transfer API doesn't support more than one item of a given type at once.\n // In addition, only a small set of types are supported natively for transfer between applications.\n // We allow for both multiple items, as well as multiple representations of a single item.\n // In order to make our API work with the native API, we serialize all items to JSON and\n // store as a single native item. We only need to do this if there is more than one item\n // of the same type, or if an item has more than one representation. Otherwise the native\n // API is sufficient.\n //\n // The DataTransferItemList API also theoretically supports adding files, which would enable\n // dragging binary data out of the browser onto the user's desktop for example. Unfortunately,\n // this does not currently work in any browser, so it is not currently supported by our API.\n // See e.g. https://bugs.chromium.org/p/chromium/issues/detail?id=438479.\n let groupedByType = new Map<string, string[]>();\n let needsCustomData = false;\n let customData: Array<{}> = [];\n for (let item of items) {\n let types = Object.keys(item);\n if (types.length > 1) {\n needsCustomData = true;\n }\n\n let dataByType = {};\n for (let type of types) {\n let typeItems = groupedByType.get(type);\n if (!typeItems) {\n typeItems = [];\n groupedByType.set(type, typeItems);\n } else {\n needsCustomData = true;\n }\n\n let data = item[type];\n dataByType[type] = data;\n typeItems.push(data);\n }\n\n customData.push(dataByType);\n }\n\n for (let [type, items] of groupedByType) {\n if (NATIVE_DRAG_TYPES.has(type)) {\n // Only one item of a given type can be set on a data transfer.\n // Join all of the items together separated by newlines.\n let data = items.join('\\n');\n dataTransfer.items.add(data, type);\n } else {\n // Set data to the first item so we have access to the list of types.\n dataTransfer.items.add(items[0], type);\n }\n }\n\n if (needsCustomData) {\n let data = JSON.stringify(customData);\n dataTransfer.items.add(data, CUSTOM_DRAG_TYPE);\n }\n}\n\nexport class DragTypes implements IDragTypes {\n private types: Set<string>;\n private includesUnknownTypes: boolean;\n\n constructor(dataTransfer: DataTransfer) {\n this.types = new Set<string>();\n\n let hasFiles = false;\n for (let item of dataTransfer.items) {\n if (item.type !== CUSTOM_DRAG_TYPE) {\n if (item.kind === 'file') {\n hasFiles = true;\n }\n\n if (item.type) {\n this.types.add(item.type);\n } else {\n // Files with unknown types or extensions that don't map to a known mime type\n // are sometimes exposed as an empty string by the browser. Map to a generic\n // mime type instead. Note that this could also be a directory as there's no\n // way to determine if something is a file or directory until drop.\n this.types.add(GENERIC_TYPE);\n }\n }\n }\n\n // In Safari, when dragging files, the dataTransfer.items list is empty, but dataTransfer.types contains \"Files\".\n // Unfortunately, this doesn't tell us what types of files the user is dragging, so we need to assume that any\n // type the user checks for is included. See https://bugs.webkit.org/show_bug.cgi?id=223517.\n this.includesUnknownTypes = !hasFiles && dataTransfer.types.includes('Files');\n }\n\n has(type: string | symbol): boolean {\n if (this.includesUnknownTypes || (type === DIRECTORY_DRAG_TYPE && this.types.has(GENERIC_TYPE))) {\n return true;\n }\n\n return typeof type === 'string' && this.types.has(type);\n }\n}\n\nexport function readFromDataTransfer(dataTransfer: DataTransfer): DropItem[] {\n let items: DropItem[] = [];\n if (!dataTransfer) {\n return items;\n }\n\n // If our custom drag type is available, use that. This is a JSON serialized\n // representation of all items in the drag, set when there are multiple items\n // of the same type, or an individual item has multiple representations.\n let hasCustomType = false;\n if (dataTransfer.types.includes(CUSTOM_DRAG_TYPE)) {\n try {\n let data = dataTransfer.getData(CUSTOM_DRAG_TYPE);\n let parsed = JSON.parse(data);\n for (let item of parsed) {\n items.push({\n kind: 'text',\n types: new Set(Object.keys(item)),\n getText: (type) => Promise.resolve(item[type])\n });\n }\n\n hasCustomType = true;\n } catch {\n // ignore\n }\n }\n\n // Otherwise, map native drag items to items of a single representation.\n if (!hasCustomType) {\n let stringItems = new Map();\n for (let item of dataTransfer.items) {\n if (item.kind === 'string') {\n // The data for all formats must be read here because the data transfer gets\n // cleared out after the event handler finishes. If the item has an empty string\n // as a type, the mime type is unknown. Map to a generic mime type instead.\n stringItems.set(item.type || GENERIC_TYPE, dataTransfer.getData(item.type));\n } else if (item.kind === 'file') {\n // Despite the name, webkitGetAsEntry is also implemented in Firefox and Edge.\n // In the future, we may use getAsFileSystemHandle instead, but that's currently\n // only implemented in Chrome.\n if (typeof item.webkitGetAsEntry === 'function') {\n let entry: FileSystemEntry | null = item.webkitGetAsEntry();\n // eslint-disable-next-line max-depth\n if (!entry) {\n // For some reason, Firefox includes an item with type image/png when copy\n // and pasting any file or directory (no matter the type), but returns `null` for both\n // item.getAsFile() and item.webkitGetAsEntry(). Safari works as expected. Ignore this\n // item if this happens. See https://bugzilla.mozilla.org/show_bug.cgi?id=1699743.\n // This was recently fixed in Chrome Canary: https://bugs.chromium.org/p/chromium/issues/detail?id=1175483.\n continue;\n }\n\n // eslint-disable-next-line max-depth\n if (entry.isFile) {\n items.push(createFileItem(item.getAsFile()));\n } else if (entry.isDirectory) {\n items.push(createDirectoryItem(entry));\n }\n } else {\n // Assume it's a file.\n items.push(createFileItem(item.getAsFile()));\n }\n }\n }\n\n // All string items are different representations of the same item. There's no way to have\n // multiple string items at once in the current DataTransfer API.\n if (stringItems.size > 0) {\n items.push({\n kind: 'text',\n types: new Set(stringItems.keys()),\n getText: (type) => Promise.resolve(stringItems.get(type))\n });\n }\n }\n\n return items;\n}\n\nfunction blobToString(blob: Blob): Promise<string> {\n if (typeof blob.text === 'function') {\n return blob.text();\n }\n\n // Safari doesn't have the Blob#text() method yet...\n return new Promise((resolve, reject) => {\n let reader = new FileReader;\n reader.onload = () => {\n resolve(reader.result as string);\n };\n\n reader.onerror = reject;\n reader.readAsText(blob);\n });\n}\n\nfunction createFileItem(file: File | null): FileDropItem {\n if (!file) {\n throw new Error('No file provided');\n }\n return {\n kind: 'file',\n type: file.type || GENERIC_TYPE,\n name: file.name,\n getText: () => blobToString(file),\n getFile: () => Promise.resolve(file)\n };\n}\n\nfunction createDirectoryItem(entry: any): DirectoryDropItem {\n return {\n kind: 'directory',\n name: entry.name,\n getEntries: () => getEntries(entry)\n };\n}\n\nasync function *getEntries(item: FileSystemDirectoryEntry): AsyncIterable<FileDropItem | DirectoryDropItem> {\n let reader = item.createReader();\n\n // We must call readEntries repeatedly because there may be a limit to the\n // number of entries that are returned at once.\n let entries: FileSystemEntry[];\n do {\n entries = await new Promise((resolve, reject) => {\n reader.readEntries(resolve, reject);\n });\n\n for (let entry of entries) {\n if (entry.isFile) {\n let file = await getEntryFile(entry as FileSystemFileEntry);\n yield createFileItem(file);\n } else if (entry.isDirectory) {\n yield createDirectoryItem(entry);\n }\n }\n } while (entries.length > 0);\n}\n\nfunction getEntryFile(entry: FileSystemFileEntry): Promise<File> {\n return new Promise((resolve, reject) => entry.file(resolve, reject));\n}\n\n/** Returns whether a drop item contains text data. */\nexport function isTextDropItem(dropItem: DropItem): dropItem is TextDropItem {\n return dropItem.kind === 'text';\n}\n\n/** Returns whether a drop item is a file. */\nexport function isFileDropItem(dropItem: DropItem): dropItem is FileDropItem {\n return dropItem.kind === 'file';\n}\n\n/** Returns whether a drop item is a directory. */\nexport function isDirectoryDropItem(dropItem: DropItem): dropItem is DirectoryDropItem {\n return dropItem.kind === 'directory';\n}\n\n// Global DnD collection state tracker.\nexport interface DnDState {\n /** A ref for the of the drag items in the current drag session if any. */\n draggingCollectionRef?: RefObject<HTMLElement | null>,\n /** The set of currently dragged keys. */\n draggingKeys: Set<Key>,\n /** A ref for the collection that is targeted for a drop operation, if any. */\n dropCollectionRef?: RefObject<HTMLElement | null>\n}\n\nexport let globalDndState: DnDState = {draggingKeys: new Set()};\n\nexport function setDraggingCollectionRef(ref: RefObject<HTMLElement | null>): void {\n globalDndState.draggingCollectionRef = ref;\n}\n\nexport function setDraggingKeys(keys: Set<Key>): void {\n globalDndState.draggingKeys = keys;\n}\n\nexport function setDropCollectionRef(ref?: RefObject<HTMLElement | null>): void {\n globalDndState.dropCollectionRef = ref;\n}\n\nexport function clearGlobalDnDState(): void {\n globalDndState = {draggingKeys: new Set()};\n}\n\nexport function setGlobalDnDState(state: DnDState): void {\n globalDndState = state;\n}\n\n// Util function to check if the current dragging collection ref is the same as the current targeted droppable collection ref.\n// Allows a droppable ref arg in case the global drop collection ref hasn't been set\nexport function isInternalDropOperation(ref?: RefObject<HTMLElement | null>): boolean {\n let {draggingCollectionRef, dropCollectionRef} = globalDndState;\n return draggingCollectionRef?.current != null && draggingCollectionRef.current === (ref?.current || dropCollectionRef?.current);\n}\n\ntype DropEffect = 'none' | 'copy' | 'link' | 'move';\nexport let globalDropEffect: DropEffect | undefined;\nexport function setGlobalDropEffect(dropEffect: DropEffect | undefined): void {\n globalDropEffect = dropEffect;\n}\n\nexport let globalAllowedDropOperations: DROP_OPERATION = DROP_OPERATION.none;\nexport function setGlobalAllowedDropOperations(o: DROP_OPERATION): void {\n globalAllowedDropOperations = o;\n}\n"],"names":[],"version":3,"file":"utils.module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-aria/dnd",
3
- "version": "3.10.0",
3
+ "version": "3.11.0",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -27,15 +27,15 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@internationalized/string": "^3.2.7",
30
- "@react-aria/i18n": "^3.12.10",
31
- "@react-aria/interactions": "^3.25.2",
32
- "@react-aria/live-announcer": "^3.4.3",
33
- "@react-aria/overlays": "^3.27.2",
34
- "@react-aria/utils": "^3.29.1",
35
- "@react-stately/collections": "^3.12.5",
36
- "@react-stately/dnd": "^3.6.0",
37
- "@react-types/button": "^3.12.2",
38
- "@react-types/shared": "^3.30.0",
30
+ "@react-aria/i18n": "^3.12.11",
31
+ "@react-aria/interactions": "^3.25.4",
32
+ "@react-aria/live-announcer": "^3.4.4",
33
+ "@react-aria/overlays": "^3.28.0",
34
+ "@react-aria/utils": "^3.30.0",
35
+ "@react-stately/collections": "^3.12.6",
36
+ "@react-stately/dnd": "^3.6.1",
37
+ "@react-types/button": "^3.13.0",
38
+ "@react-types/shared": "^3.31.0",
39
39
  "@swc/helpers": "^0.5.0"
40
40
  },
41
41
  "peerDependencies": {
@@ -45,5 +45,5 @@
45
45
  "publishConfig": {
46
46
  "access": "public"
47
47
  },
48
- "gitHead": "265b4d7f107905ee1c6e87a8af1613ab440a6849"
48
+ "gitHead": "8b9348ff255e018b2dd9b27e2a45507cadfa1d35"
49
49
  }