@react-aria/dnd 3.0.0-alpha.8 → 3.0.0-nightly-641446f65-240905
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/DragManager.main.js +432 -0
- package/dist/DragManager.main.js.map +1 -0
- package/dist/DragManager.mjs +423 -0
- package/dist/DragManager.module.js +423 -0
- package/dist/DragManager.module.js.map +1 -0
- package/dist/DragPreview.main.js +59 -0
- package/dist/DragPreview.main.js.map +1 -0
- package/dist/DragPreview.mjs +50 -0
- package/dist/DragPreview.module.js +50 -0
- package/dist/DragPreview.module.js.map +1 -0
- package/dist/ListDropTargetDelegate.main.js +123 -0
- package/dist/ListDropTargetDelegate.main.js.map +1 -0
- package/dist/ListDropTargetDelegate.mjs +118 -0
- package/dist/ListDropTargetDelegate.module.js +118 -0
- package/dist/ListDropTargetDelegate.module.js.map +1 -0
- package/dist/ar-AE.main.js +44 -0
- package/dist/ar-AE.main.js.map +1 -0
- package/dist/ar-AE.mjs +46 -0
- package/dist/ar-AE.module.js +46 -0
- package/dist/ar-AE.module.js.map +1 -0
- package/dist/bg-BG.main.js +44 -0
- package/dist/bg-BG.main.js.map +1 -0
- package/dist/bg-BG.mjs +46 -0
- package/dist/bg-BG.module.js +46 -0
- package/dist/bg-BG.module.js.map +1 -0
- package/dist/constants.main.js +65 -0
- package/dist/constants.main.js.map +1 -0
- package/dist/constants.mjs +53 -0
- package/dist/constants.module.js +53 -0
- package/dist/constants.module.js.map +1 -0
- package/dist/cs-CZ.main.js +45 -0
- package/dist/cs-CZ.main.js.map +1 -0
- package/dist/cs-CZ.mjs +47 -0
- package/dist/cs-CZ.module.js +47 -0
- package/dist/cs-CZ.module.js.map +1 -0
- package/dist/da-DK.main.js +44 -0
- package/dist/da-DK.main.js.map +1 -0
- package/dist/da-DK.mjs +46 -0
- package/dist/da-DK.module.js +46 -0
- package/dist/da-DK.module.js.map +1 -0
- package/dist/de-DE.main.js +44 -0
- package/dist/de-DE.main.js.map +1 -0
- package/dist/de-DE.mjs +46 -0
- package/dist/de-DE.module.js +46 -0
- package/dist/de-DE.module.js.map +1 -0
- package/dist/el-GR.main.js +44 -0
- package/dist/el-GR.main.js.map +1 -0
- package/dist/el-GR.mjs +46 -0
- package/dist/el-GR.module.js +46 -0
- package/dist/el-GR.module.js.map +1 -0
- package/dist/en-US.main.js +44 -0
- package/dist/en-US.main.js.map +1 -0
- package/dist/en-US.mjs +46 -0
- package/dist/en-US.module.js +46 -0
- package/dist/en-US.module.js.map +1 -0
- package/dist/es-ES.main.js +44 -0
- package/dist/es-ES.main.js.map +1 -0
- package/dist/es-ES.mjs +46 -0
- package/dist/es-ES.module.js +46 -0
- package/dist/es-ES.module.js.map +1 -0
- package/dist/et-EE.main.js +44 -0
- package/dist/et-EE.main.js.map +1 -0
- package/dist/et-EE.mjs +46 -0
- package/dist/et-EE.module.js +46 -0
- package/dist/et-EE.module.js.map +1 -0
- package/dist/fi-FI.main.js +44 -0
- package/dist/fi-FI.main.js.map +1 -0
- package/dist/fi-FI.mjs +46 -0
- package/dist/fi-FI.module.js +46 -0
- package/dist/fi-FI.module.js.map +1 -0
- package/dist/fr-FR.main.js +44 -0
- package/dist/fr-FR.main.js.map +1 -0
- package/dist/fr-FR.mjs +46 -0
- package/dist/fr-FR.module.js +46 -0
- package/dist/fr-FR.module.js.map +1 -0
- package/dist/he-IL.main.js +44 -0
- package/dist/he-IL.main.js.map +1 -0
- package/dist/he-IL.mjs +46 -0
- package/dist/he-IL.module.js +46 -0
- package/dist/he-IL.module.js.map +1 -0
- package/dist/hr-HR.main.js +44 -0
- package/dist/hr-HR.main.js.map +1 -0
- package/dist/hr-HR.mjs +46 -0
- package/dist/hr-HR.module.js +46 -0
- package/dist/hr-HR.module.js.map +1 -0
- package/dist/hu-HU.main.js +44 -0
- package/dist/hu-HU.main.js.map +1 -0
- package/dist/hu-HU.mjs +46 -0
- package/dist/hu-HU.module.js +46 -0
- package/dist/hu-HU.module.js.map +1 -0
- package/dist/import.mjs +39 -0
- package/dist/intlStrings.main.js +108 -0
- package/dist/intlStrings.main.js.map +1 -0
- package/dist/intlStrings.mjs +110 -0
- package/dist/intlStrings.module.js +110 -0
- package/dist/intlStrings.module.js.map +1 -0
- package/dist/it-IT.main.js +44 -0
- package/dist/it-IT.main.js.map +1 -0
- package/dist/it-IT.mjs +46 -0
- package/dist/it-IT.module.js +46 -0
- package/dist/it-IT.module.js.map +1 -0
- package/dist/ja-JP.main.js +44 -0
- package/dist/ja-JP.main.js.map +1 -0
- package/dist/ja-JP.mjs +46 -0
- package/dist/ja-JP.module.js +46 -0
- package/dist/ja-JP.module.js.map +1 -0
- package/dist/ko-KR.main.js +44 -0
- package/dist/ko-KR.main.js.map +1 -0
- package/dist/ko-KR.mjs +46 -0
- package/dist/ko-KR.module.js +46 -0
- package/dist/ko-KR.module.js.map +1 -0
- package/dist/lt-LT.main.js +44 -0
- package/dist/lt-LT.main.js.map +1 -0
- package/dist/lt-LT.mjs +46 -0
- package/dist/lt-LT.module.js +46 -0
- package/dist/lt-LT.module.js.map +1 -0
- package/dist/lv-LV.main.js +44 -0
- package/dist/lv-LV.main.js.map +1 -0
- package/dist/lv-LV.mjs +46 -0
- package/dist/lv-LV.module.js +46 -0
- package/dist/lv-LV.module.js.map +1 -0
- package/dist/main.js +38 -1855
- package/dist/main.js.map +1 -1
- package/dist/module.js +24 -1838
- package/dist/module.js.map +1 -1
- package/dist/nb-NO.main.js +44 -0
- package/dist/nb-NO.main.js.map +1 -0
- package/dist/nb-NO.mjs +46 -0
- package/dist/nb-NO.module.js +46 -0
- package/dist/nb-NO.module.js.map +1 -0
- package/dist/nl-NL.main.js +44 -0
- package/dist/nl-NL.main.js.map +1 -0
- package/dist/nl-NL.mjs +46 -0
- package/dist/nl-NL.module.js +46 -0
- package/dist/nl-NL.module.js.map +1 -0
- package/dist/pl-PL.main.js +44 -0
- package/dist/pl-PL.main.js.map +1 -0
- package/dist/pl-PL.mjs +46 -0
- package/dist/pl-PL.module.js +46 -0
- package/dist/pl-PL.module.js.map +1 -0
- package/dist/pt-BR.main.js +44 -0
- package/dist/pt-BR.main.js.map +1 -0
- package/dist/pt-BR.mjs +46 -0
- package/dist/pt-BR.module.js +46 -0
- package/dist/pt-BR.module.js.map +1 -0
- package/dist/pt-PT.main.js +44 -0
- package/dist/pt-PT.main.js.map +1 -0
- package/dist/pt-PT.mjs +46 -0
- package/dist/pt-PT.module.js +46 -0
- package/dist/pt-PT.module.js.map +1 -0
- package/dist/ro-RO.main.js +44 -0
- package/dist/ro-RO.main.js.map +1 -0
- package/dist/ro-RO.mjs +46 -0
- package/dist/ro-RO.module.js +46 -0
- package/dist/ro-RO.module.js.map +1 -0
- package/dist/ru-RU.main.js +44 -0
- package/dist/ru-RU.main.js.map +1 -0
- package/dist/ru-RU.mjs +46 -0
- package/dist/ru-RU.module.js +46 -0
- package/dist/ru-RU.module.js.map +1 -0
- package/dist/sk-SK.main.js +44 -0
- package/dist/sk-SK.main.js.map +1 -0
- package/dist/sk-SK.mjs +46 -0
- package/dist/sk-SK.module.js +46 -0
- package/dist/sk-SK.module.js.map +1 -0
- package/dist/sl-SI.main.js +44 -0
- package/dist/sl-SI.main.js.map +1 -0
- package/dist/sl-SI.mjs +46 -0
- package/dist/sl-SI.module.js +46 -0
- package/dist/sl-SI.module.js.map +1 -0
- package/dist/sr-SP.main.js +44 -0
- package/dist/sr-SP.main.js.map +1 -0
- package/dist/sr-SP.mjs +46 -0
- package/dist/sr-SP.module.js +46 -0
- package/dist/sr-SP.module.js.map +1 -0
- package/dist/sv-SE.main.js +44 -0
- package/dist/sv-SE.main.js.map +1 -0
- package/dist/sv-SE.mjs +46 -0
- package/dist/sv-SE.module.js +46 -0
- package/dist/sv-SE.module.js.map +1 -0
- package/dist/tr-TR.main.js +44 -0
- package/dist/tr-TR.main.js.map +1 -0
- package/dist/tr-TR.mjs +46 -0
- package/dist/tr-TR.module.js +46 -0
- package/dist/tr-TR.module.js.map +1 -0
- package/dist/types.d.ts +184 -32
- package/dist/types.d.ts.map +1 -1
- package/dist/uk-UA.main.js +44 -0
- package/dist/uk-UA.main.js.map +1 -0
- package/dist/uk-UA.mjs +46 -0
- package/dist/uk-UA.module.js +46 -0
- package/dist/uk-UA.module.js.map +1 -0
- package/dist/useAutoScroll.main.js +89 -0
- package/dist/useAutoScroll.main.js.map +1 -0
- package/dist/useAutoScroll.mjs +84 -0
- package/dist/useAutoScroll.module.js +84 -0
- package/dist/useAutoScroll.module.js.map +1 -0
- package/dist/useClipboard.main.js +107 -0
- package/dist/useClipboard.main.js.map +1 -0
- package/dist/useClipboard.mjs +102 -0
- package/dist/useClipboard.module.js +102 -0
- package/dist/useClipboard.module.js.map +1 -0
- package/dist/useDrag.main.js +286 -0
- package/dist/useDrag.main.js.map +1 -0
- package/dist/useDrag.mjs +281 -0
- package/dist/useDrag.module.js +281 -0
- package/dist/useDrag.module.js.map +1 -0
- package/dist/useDraggableCollection.main.js +27 -0
- package/dist/useDraggableCollection.main.js.map +1 -0
- package/dist/useDraggableCollection.mjs +22 -0
- package/dist/useDraggableCollection.module.js +22 -0
- package/dist/useDraggableCollection.module.js.map +1 -0
- package/dist/useDraggableItem.main.js +128 -0
- package/dist/useDraggableItem.main.js.map +1 -0
- package/dist/useDraggableItem.mjs +123 -0
- package/dist/useDraggableItem.module.js +123 -0
- package/dist/useDraggableItem.module.js.map +1 -0
- package/dist/useDrop.main.js +299 -0
- package/dist/useDrop.main.js.map +1 -0
- package/dist/useDrop.mjs +294 -0
- package/dist/useDrop.module.js +294 -0
- package/dist/useDrop.module.js.map +1 -0
- package/dist/useDropIndicator.main.js +93 -0
- package/dist/useDropIndicator.main.js.map +1 -0
- package/dist/useDropIndicator.mjs +88 -0
- package/dist/useDropIndicator.module.js +88 -0
- package/dist/useDropIndicator.module.js.map +1 -0
- package/dist/useDroppableCollection.main.js +592 -0
- package/dist/useDroppableCollection.main.js.map +1 -0
- package/dist/useDroppableCollection.mjs +587 -0
- package/dist/useDroppableCollection.module.js +587 -0
- package/dist/useDroppableCollection.module.js.map +1 -0
- package/dist/useDroppableItem.main.js +79 -0
- package/dist/useDroppableItem.main.js.map +1 -0
- package/dist/useDroppableItem.mjs +74 -0
- package/dist/useDroppableItem.module.js +74 -0
- package/dist/useDroppableItem.module.js.map +1 -0
- package/dist/useVirtualDrop.main.js +56 -0
- package/dist/useVirtualDrop.main.js.map +1 -0
- package/dist/useVirtualDrop.mjs +51 -0
- package/dist/useVirtualDrop.module.js +51 -0
- package/dist/useVirtualDrop.module.js.map +1 -0
- package/dist/utils.main.js +283 -0
- package/dist/utils.main.js.map +1 -0
- package/dist/utils.mjs +255 -0
- package/dist/utils.module.js +255 -0
- package/dist/utils.module.js.map +1 -0
- package/dist/zh-CN.main.js +44 -0
- package/dist/zh-CN.main.js.map +1 -0
- package/dist/zh-CN.mjs +46 -0
- package/dist/zh-CN.module.js +46 -0
- package/dist/zh-CN.module.js.map +1 -0
- package/dist/zh-TW.main.js +44 -0
- package/dist/zh-TW.main.js.map +1 -0
- package/dist/zh-TW.mjs +46 -0
- package/dist/zh-TW.module.js +46 -0
- package/dist/zh-TW.module.js.map +1 -0
- package/package.json +20 -16
- package/src/DragManager.ts +87 -52
- package/src/DragPreview.tsx +54 -0
- package/src/ListDropTargetDelegate.ts +173 -0
- package/src/constants.ts +2 -0
- package/src/index.ts +56 -7
- package/src/useAutoScroll.ts +26 -6
- package/src/useClipboard.ts +65 -59
- package/src/useDrag.ts +195 -61
- package/src/useDraggableCollection.ts +29 -0
- package/src/useDraggableItem.ts +106 -15
- package/src/useDrop.ts +273 -93
- package/src/useDropIndicator.ts +49 -23
- package/src/useDroppableCollection.ts +317 -122
- package/src/useDroppableItem.ts +35 -19
- package/src/useVirtualDrop.ts +5 -5
- package/src/utils.ts +92 -17
- package/LICENSE +0 -201
package/src/useDroppableItem.ts
CHANGED
|
@@ -12,44 +12,59 @@
|
|
|
12
12
|
|
|
13
13
|
import * as DragManager from './DragManager';
|
|
14
14
|
import {DroppableCollectionState} from '@react-stately/dnd';
|
|
15
|
-
import {DropTarget} from '@react-types/shared';
|
|
16
|
-
import {getTypes} from './utils';
|
|
17
|
-
import {HTMLAttributes,
|
|
15
|
+
import {DropTarget, RefObject} from '@react-types/shared';
|
|
16
|
+
import {getDroppableCollectionRef, getTypes, globalDndState, isInternalDropOperation} from './utils';
|
|
17
|
+
import {HTMLAttributes, useEffect} from 'react';
|
|
18
18
|
import {useVirtualDrop} from './useVirtualDrop';
|
|
19
19
|
|
|
20
|
-
interface DroppableItemOptions {
|
|
20
|
+
export interface DroppableItemOptions {
|
|
21
|
+
/** The drop target represented by the item. */
|
|
21
22
|
target: DropTarget
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
interface DroppableItemResult {
|
|
25
|
-
|
|
25
|
+
export interface DroppableItemResult {
|
|
26
|
+
/** Props for the droppable element. */
|
|
27
|
+
dropProps: HTMLAttributes<HTMLElement>,
|
|
28
|
+
/** Whether the item is currently the active drop target. */
|
|
29
|
+
isDropTarget: boolean
|
|
26
30
|
}
|
|
27
31
|
|
|
28
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Handles drop interactions for an item within a collection component.
|
|
34
|
+
*/
|
|
35
|
+
export function useDroppableItem(options: DroppableItemOptions, state: DroppableCollectionState, ref: RefObject<HTMLElement | null>): DroppableItemResult {
|
|
29
36
|
let {dropProps} = useVirtualDrop();
|
|
30
|
-
|
|
37
|
+
let droppableCollectionRef = getDroppableCollectionRef(state);
|
|
31
38
|
useEffect(() => {
|
|
32
39
|
if (ref.current) {
|
|
33
40
|
return DragManager.registerDropItem({
|
|
34
41
|
element: ref.current,
|
|
35
42
|
target: options.target,
|
|
36
43
|
getDropOperation(types, allowedOperations) {
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
let {draggingKeys} = globalDndState;
|
|
45
|
+
let isInternal = isInternalDropOperation(droppableCollectionRef);
|
|
46
|
+
return state.getDropOperation({
|
|
47
|
+
target: options.target,
|
|
39
48
|
types,
|
|
40
|
-
allowedOperations
|
|
41
|
-
|
|
49
|
+
allowedOperations,
|
|
50
|
+
isInternal,
|
|
51
|
+
draggingKeys
|
|
52
|
+
});
|
|
42
53
|
}
|
|
43
54
|
});
|
|
44
55
|
}
|
|
45
|
-
}, [ref, options.target, state]);
|
|
56
|
+
}, [ref, options.target, state, droppableCollectionRef]);
|
|
46
57
|
|
|
47
58
|
let dragSession = DragManager.useDragSession();
|
|
48
|
-
let
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
59
|
+
let {draggingKeys} = globalDndState;
|
|
60
|
+
let isInternal = isInternalDropOperation(droppableCollectionRef);
|
|
61
|
+
let isValidDropTarget = dragSession && state.getDropOperation({
|
|
62
|
+
target: options.target,
|
|
63
|
+
types: getTypes(dragSession.dragTarget.items),
|
|
64
|
+
allowedOperations: dragSession.dragTarget.allowedDropOperations,
|
|
65
|
+
isInternal,
|
|
66
|
+
draggingKeys
|
|
67
|
+
}) !== 'cancel';
|
|
53
68
|
|
|
54
69
|
let isDropTarget = state.isDropTarget(options.target);
|
|
55
70
|
useEffect(() => {
|
|
@@ -62,6 +77,7 @@ export function useDroppableItem(options: DroppableItemOptions, state: Droppable
|
|
|
62
77
|
dropProps: {
|
|
63
78
|
...dropProps,
|
|
64
79
|
'aria-hidden': !dragSession || isValidDropTarget ? undefined : 'true'
|
|
65
|
-
}
|
|
80
|
+
},
|
|
81
|
+
isDropTarget
|
|
66
82
|
};
|
|
67
83
|
}
|
package/src/useVirtualDrop.ts
CHANGED
|
@@ -10,16 +10,16 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
import {DOMAttributes} from '@react-types/shared';
|
|
13
14
|
import * as DragManager from './DragManager';
|
|
14
|
-
import {HTMLAttributes} from 'react';
|
|
15
15
|
// @ts-ignore
|
|
16
16
|
import intlMessages from '../intl/*.json';
|
|
17
17
|
import {useDescription} from '@react-aria/utils';
|
|
18
18
|
import {useDragModality} from './utils';
|
|
19
|
-
import {
|
|
19
|
+
import {useLocalizedStringFormatter} from '@react-aria/i18n';
|
|
20
20
|
|
|
21
21
|
interface VirtualDropResult {
|
|
22
|
-
dropProps:
|
|
22
|
+
dropProps: DOMAttributes
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
const MESSAGES = {
|
|
@@ -29,10 +29,10 @@ const MESSAGES = {
|
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
export function useVirtualDrop(): VirtualDropResult {
|
|
32
|
-
let
|
|
32
|
+
let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/dnd');
|
|
33
33
|
let modality = useDragModality();
|
|
34
34
|
let dragSession = DragManager.useDragSession();
|
|
35
|
-
let descriptionProps = useDescription(dragSession ?
|
|
35
|
+
let descriptionProps = useDescription(dragSession ? stringFormatter.format(MESSAGES[modality]) : '');
|
|
36
36
|
|
|
37
37
|
return {
|
|
38
38
|
dropProps: {
|
package/src/utils.ts
CHANGED
|
@@ -10,22 +10,21 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {CUSTOM_DRAG_TYPE, GENERIC_TYPE, NATIVE_DRAG_TYPES} from './constants';
|
|
14
|
-
import {
|
|
13
|
+
import {CUSTOM_DRAG_TYPE, DROP_OPERATION, GENERIC_TYPE, NATIVE_DRAG_TYPES} from './constants';
|
|
14
|
+
import {DirectoryDropItem, DragItem, DropItem, FileDropItem, DragTypes as IDragTypes, Key, RefObject, TextDropItem} from '@react-types/shared';
|
|
15
15
|
import {DroppableCollectionState} from '@react-stately/dnd';
|
|
16
16
|
import {getInteractionModality, useInteractionModality} from '@react-aria/interactions';
|
|
17
|
-
import {useId} from '@react-aria/utils';
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
let id = useId();
|
|
23
|
-
droppableCollectionIds.set(state, id);
|
|
24
|
-
return id;
|
|
18
|
+
interface DroppableCollectionMap {
|
|
19
|
+
id: string,
|
|
20
|
+
ref: RefObject<HTMLElement | null>
|
|
25
21
|
}
|
|
26
22
|
|
|
23
|
+
export const droppableCollectionMap = new WeakMap<DroppableCollectionState, DroppableCollectionMap>();
|
|
24
|
+
export const DIRECTORY_DRAG_TYPE = Symbol();
|
|
25
|
+
|
|
27
26
|
export function getDroppableCollectionId(state: DroppableCollectionState) {
|
|
28
|
-
let id =
|
|
27
|
+
let {id} = droppableCollectionMap.get(state);
|
|
29
28
|
if (!id) {
|
|
30
29
|
throw new Error('Droppable item outside a droppable collection');
|
|
31
30
|
}
|
|
@@ -33,6 +32,15 @@ export function getDroppableCollectionId(state: DroppableCollectionState) {
|
|
|
33
32
|
return id;
|
|
34
33
|
}
|
|
35
34
|
|
|
35
|
+
export function getDroppableCollectionRef(state: DroppableCollectionState) {
|
|
36
|
+
let {ref} = droppableCollectionMap.get(state);
|
|
37
|
+
if (!ref) {
|
|
38
|
+
throw new Error('Droppable item outside a droppable collection');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return ref;
|
|
42
|
+
}
|
|
43
|
+
|
|
36
44
|
export function getTypes(items: DragItem[]): Set<string> {
|
|
37
45
|
let types = new Set<string>();
|
|
38
46
|
for (let item of items) {
|
|
@@ -53,7 +61,7 @@ function mapModality(modality: string) {
|
|
|
53
61
|
modality = 'virtual';
|
|
54
62
|
}
|
|
55
63
|
|
|
56
|
-
if (modality === 'virtual' && 'ontouchstart' in window) {
|
|
64
|
+
if (modality === 'virtual' && (typeof window !== 'undefined' && 'ontouchstart' in window)) {
|
|
57
65
|
modality = 'touch';
|
|
58
66
|
}
|
|
59
67
|
|
|
@@ -158,12 +166,12 @@ export class DragTypes implements IDragTypes {
|
|
|
158
166
|
this.includesUnknownTypes = !hasFiles && dataTransfer.types.includes('Files');
|
|
159
167
|
}
|
|
160
168
|
|
|
161
|
-
has(type: string) {
|
|
162
|
-
if (this.includesUnknownTypes) {
|
|
169
|
+
has(type: string | symbol) {
|
|
170
|
+
if (this.includesUnknownTypes || (type === DIRECTORY_DRAG_TYPE && this.types.has(GENERIC_TYPE))) {
|
|
163
171
|
return true;
|
|
164
172
|
}
|
|
165
173
|
|
|
166
|
-
return this.types.has(type);
|
|
174
|
+
return typeof type === 'string' && this.types.has(type);
|
|
167
175
|
}
|
|
168
176
|
}
|
|
169
177
|
|
|
@@ -207,6 +215,7 @@ export function readFromDataTransfer(dataTransfer: DataTransfer) {
|
|
|
207
215
|
// only implemented in Chrome.
|
|
208
216
|
if (typeof item.webkitGetAsEntry === 'function') {
|
|
209
217
|
let entry: FileSystemEntry = item.webkitGetAsEntry();
|
|
218
|
+
// eslint-disable-next-line max-depth
|
|
210
219
|
if (!entry) {
|
|
211
220
|
// For some reason, Firefox includes an item with type image/png when copy
|
|
212
221
|
// and pasting any file or directory (no matter the type), but returns `null` for both
|
|
@@ -216,6 +225,7 @@ export function readFromDataTransfer(dataTransfer: DataTransfer) {
|
|
|
216
225
|
continue;
|
|
217
226
|
}
|
|
218
227
|
|
|
228
|
+
// eslint-disable-next-line max-depth
|
|
219
229
|
if (entry.isFile) {
|
|
220
230
|
items.push(createFileItem(item.getAsFile()));
|
|
221
231
|
} else if (entry.isDirectory) {
|
|
@@ -259,7 +269,7 @@ function blobToString(blob: Blob): Promise<string> {
|
|
|
259
269
|
});
|
|
260
270
|
}
|
|
261
271
|
|
|
262
|
-
function createFileItem(file: File):
|
|
272
|
+
function createFileItem(file: File): FileDropItem {
|
|
263
273
|
return {
|
|
264
274
|
kind: 'file',
|
|
265
275
|
type: file.type || GENERIC_TYPE,
|
|
@@ -269,7 +279,7 @@ function createFileItem(file: File): FileItem {
|
|
|
269
279
|
};
|
|
270
280
|
}
|
|
271
281
|
|
|
272
|
-
function createDirectoryItem(entry: any):
|
|
282
|
+
function createDirectoryItem(entry: any): DirectoryDropItem {
|
|
273
283
|
return {
|
|
274
284
|
kind: 'directory',
|
|
275
285
|
name: entry.name,
|
|
@@ -277,7 +287,7 @@ function createDirectoryItem(entry: any): DirectoryItem {
|
|
|
277
287
|
};
|
|
278
288
|
}
|
|
279
289
|
|
|
280
|
-
async function *getEntries(item: FileSystemDirectoryEntry): AsyncIterable<
|
|
290
|
+
async function *getEntries(item: FileSystemDirectoryEntry): AsyncIterable<FileDropItem | DirectoryDropItem> {
|
|
281
291
|
let reader = item.createReader();
|
|
282
292
|
|
|
283
293
|
// We must call readEntries repeatedly because there may be a limit to the
|
|
@@ -302,3 +312,68 @@ async function *getEntries(item: FileSystemDirectoryEntry): AsyncIterable<FileIt
|
|
|
302
312
|
function getEntryFile(entry: FileSystemFileEntry): Promise<File> {
|
|
303
313
|
return new Promise((resolve, reject) => entry.file(resolve, reject));
|
|
304
314
|
}
|
|
315
|
+
|
|
316
|
+
/** Returns whether a drop item contains text data. */
|
|
317
|
+
export function isTextDropItem(dropItem: DropItem): dropItem is TextDropItem {
|
|
318
|
+
return dropItem.kind === 'text';
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/** Returns whether a drop item is a file. */
|
|
322
|
+
export function isFileDropItem(dropItem: DropItem): dropItem is FileDropItem {
|
|
323
|
+
return dropItem.kind === 'file';
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** Returns whether a drop item is a directory. */
|
|
327
|
+
export function isDirectoryDropItem(dropItem: DropItem): dropItem is DirectoryDropItem {
|
|
328
|
+
return dropItem.kind === 'directory';
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// Global DnD collection state tracker.
|
|
332
|
+
export interface DnDState {
|
|
333
|
+
/** A ref for the of the drag items in the current drag session if any. */
|
|
334
|
+
draggingCollectionRef?: RefObject<HTMLElement | null>,
|
|
335
|
+
/** The set of currently dragged keys. */
|
|
336
|
+
draggingKeys: Set<Key>,
|
|
337
|
+
/** A ref for the collection that is targeted for a drop operation, if any. */
|
|
338
|
+
dropCollectionRef?: RefObject<HTMLElement | null>
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export let globalDndState: DnDState = {draggingKeys: new Set()};
|
|
342
|
+
|
|
343
|
+
export function setDraggingCollectionRef(ref: RefObject<HTMLElement | null>) {
|
|
344
|
+
globalDndState.draggingCollectionRef = ref;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
export function setDraggingKeys(keys: Set<Key>) {
|
|
348
|
+
globalDndState.draggingKeys = keys;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
export function setDropCollectionRef(ref: RefObject<HTMLElement | null>) {
|
|
352
|
+
globalDndState.dropCollectionRef = ref;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export function clearGlobalDnDState() {
|
|
356
|
+
globalDndState = {draggingKeys: new Set()};
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
export function setGlobalDnDState(state: DnDState) {
|
|
360
|
+
globalDndState = state;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// Util function to check if the current dragging collection ref is the same as the current targeted droppable collection ref.
|
|
364
|
+
// Allows a droppable ref arg in case the global drop collection ref hasn't been set
|
|
365
|
+
export function isInternalDropOperation(ref?: RefObject<HTMLElement | null>) {
|
|
366
|
+
let {draggingCollectionRef, dropCollectionRef} = globalDndState;
|
|
367
|
+
return draggingCollectionRef?.current != null && draggingCollectionRef.current === (ref?.current || dropCollectionRef?.current);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
type DropEffect = 'none' | 'copy' | 'link' | 'move';
|
|
371
|
+
export let globalDropEffect: DropEffect;
|
|
372
|
+
export function setGlobalDropEffect(dropEffect: DropEffect) {
|
|
373
|
+
globalDropEffect = dropEffect;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
export let globalAllowedDropOperations = DROP_OPERATION.none;
|
|
377
|
+
export function setGlobalAllowedDropOperations(o: DROP_OPERATION) {
|
|
378
|
+
globalAllowedDropOperations = o;
|
|
379
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|
|
177
|
-
|
|
178
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
-
|
|
180
|
-
To apply the Apache License to your work, attach the following
|
|
181
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
-
replaced with your own identifying information. (Don't include
|
|
183
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
-
comment syntax for the file format. We also recommend that a
|
|
185
|
-
file or class name and description of purpose be included on the
|
|
186
|
-
same "printed page" as the copyright notice for easier
|
|
187
|
-
identification within third-party archives.
|
|
188
|
-
|
|
189
|
-
Copyright 2019 Adobe
|
|
190
|
-
|
|
191
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
-
you may not use this file except in compliance with the License.
|
|
193
|
-
You may obtain a copy of the License at
|
|
194
|
-
|
|
195
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
-
|
|
197
|
-
Unless required by applicable law or agreed to in writing, software
|
|
198
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
-
See the License for the specific language governing permissions and
|
|
201
|
-
limitations under the License.
|