@react-aria/dnd 3.0.0-alpha.1 → 3.0.0-alpha.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js +2853 -1965
- package/dist/main.js.map +1 -1
- package/dist/module.js +2844 -1908
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +55 -31
- package/dist/types.d.ts.map +1 -1
- package/package.json +15 -14
- package/src/DragManager.ts +109 -43
- package/src/DragPreview.tsx +54 -0
- package/src/ListDropTargetDelegate.ts +90 -0
- package/src/constants.ts +3 -1
- package/src/index.ts +19 -7
- package/src/useClipboard.ts +5 -5
- package/src/useDrag.ts +40 -39
- package/src/useDraggableItem.ts +10 -11
- package/src/useDrop.ts +116 -49
- package/src/useDropIndicator.ts +22 -13
- package/src/useDroppableCollection.ts +11 -16
- package/src/useDroppableItem.ts +6 -4
- package/src/useVirtualDrop.ts +5 -5
- package/src/utils.ts +1 -20
|
@@ -10,23 +10,23 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {Collection, DropEvent, DropOperation, DroppableCollectionProps, DropPosition, DropTarget, KeyboardDelegate, Node} from '@react-types/shared';
|
|
13
|
+
import {Collection, DropEvent, DropOperation, DroppableCollectionProps, DropPosition, DropTarget, DropTargetDelegate, KeyboardDelegate, Node} from '@react-types/shared';
|
|
14
14
|
import * as DragManager from './DragManager';
|
|
15
15
|
import {DroppableCollectionState} from '@react-stately/dnd';
|
|
16
16
|
import {getTypes} from './utils';
|
|
17
|
-
import {HTMLAttributes, Key, RefObject, useCallback, useEffect,
|
|
18
|
-
import {mergeProps} from '@react-aria/utils';
|
|
17
|
+
import {HTMLAttributes, Key, RefObject, useCallback, useEffect, useRef} from 'react';
|
|
18
|
+
import {mergeProps, useLayoutEffect} from '@react-aria/utils';
|
|
19
19
|
import {setInteractionModality} from '@react-aria/interactions';
|
|
20
20
|
import {useAutoScroll} from './useAutoScroll';
|
|
21
21
|
import {useDrop} from './useDrop';
|
|
22
22
|
import {useDroppableCollectionId} from './utils';
|
|
23
23
|
|
|
24
|
-
interface DroppableCollectionOptions extends DroppableCollectionProps {
|
|
24
|
+
export interface DroppableCollectionOptions extends DroppableCollectionProps {
|
|
25
25
|
keyboardDelegate: KeyboardDelegate,
|
|
26
|
-
|
|
26
|
+
dropTargetDelegate: DropTargetDelegate
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
interface DroppableCollectionResult {
|
|
29
|
+
export interface DroppableCollectionResult {
|
|
30
30
|
collectionProps: HTMLAttributes<HTMLElement>
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -34,7 +34,7 @@ interface DroppingState {
|
|
|
34
34
|
collection: Collection<Node<unknown>>,
|
|
35
35
|
focusedKey: Key,
|
|
36
36
|
selectedKeys: Set<Key>,
|
|
37
|
-
timeout:
|
|
37
|
+
timeout: ReturnType<typeof setTimeout>
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
const DROP_POSITIONS: DropPosition[] = ['before', 'on', 'after'];
|
|
@@ -52,27 +52,22 @@ export function useDroppableCollection(props: DroppableCollectionOptions, state:
|
|
|
52
52
|
let autoScroll = useAutoScroll(ref);
|
|
53
53
|
let {dropProps} = useDrop({
|
|
54
54
|
ref,
|
|
55
|
-
onDropEnter(
|
|
56
|
-
|
|
57
|
-
state.setTarget(target);
|
|
55
|
+
onDropEnter() {
|
|
56
|
+
state.setTarget(localState.nextTarget);
|
|
58
57
|
},
|
|
59
58
|
onDropMove(e) {
|
|
60
59
|
state.setTarget(localState.nextTarget);
|
|
61
60
|
autoScroll.move(e.x, e.y);
|
|
62
61
|
},
|
|
63
62
|
getDropOperationForPoint(types, allowedOperations, x, y) {
|
|
64
|
-
let
|
|
63
|
+
let isValidDropTarget = (target) => state.getDropOperation(target, types, allowedOperations) !== 'cancel';
|
|
64
|
+
let target = props.dropTargetDelegate.getDropTargetFromPoint(x, y, isValidDropTarget);
|
|
65
65
|
if (!target) {
|
|
66
66
|
localState.dropOperation = 'cancel';
|
|
67
67
|
localState.nextTarget = null;
|
|
68
68
|
return 'cancel';
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
if (state.isDropTarget(target)) {
|
|
72
|
-
localState.nextTarget = target;
|
|
73
|
-
return localState.dropOperation;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
71
|
localState.dropOperation = state.getDropOperation(target, types, allowedOperations);
|
|
77
72
|
|
|
78
73
|
// If the target doesn't accept the drop, see if the root accepts it instead.
|
package/src/useDroppableItem.ts
CHANGED
|
@@ -17,12 +17,13 @@ import {getTypes} from './utils';
|
|
|
17
17
|
import {HTMLAttributes, RefObject, useEffect} from 'react';
|
|
18
18
|
import {useVirtualDrop} from './useVirtualDrop';
|
|
19
19
|
|
|
20
|
-
interface DroppableItemOptions {
|
|
20
|
+
export interface DroppableItemOptions {
|
|
21
21
|
target: DropTarget
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
interface DroppableItemResult {
|
|
25
|
-
dropProps: HTMLAttributes<HTMLElement
|
|
24
|
+
export interface DroppableItemResult {
|
|
25
|
+
dropProps: HTMLAttributes<HTMLElement>,
|
|
26
|
+
isDropTarget: boolean
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
export function useDroppableItem(options: DroppableItemOptions, state: DroppableCollectionState, ref: RefObject<HTMLElement>): DroppableItemResult {
|
|
@@ -62,6 +63,7 @@ export function useDroppableItem(options: DroppableItemOptions, state: Droppable
|
|
|
62
63
|
dropProps: {
|
|
63
64
|
...dropProps,
|
|
64
65
|
'aria-hidden': !dragSession || isValidDropTarget ? undefined : 'true'
|
|
65
|
-
}
|
|
66
|
+
},
|
|
67
|
+
isDropTarget
|
|
66
68
|
};
|
|
67
69
|
}
|
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);
|
|
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
|
@@ -277,25 +277,6 @@ function createDirectoryItem(entry: any): DirectoryItem {
|
|
|
277
277
|
};
|
|
278
278
|
}
|
|
279
279
|
|
|
280
|
-
interface FileSystemFileEntry {
|
|
281
|
-
isFile: true,
|
|
282
|
-
isDirectory: false,
|
|
283
|
-
name: string,
|
|
284
|
-
file(successCallback: (file: File) => void, errorCallback?: (error: Error) => void): void
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
interface FileSystemDirectoryEntry {
|
|
288
|
-
isDirectory: true,
|
|
289
|
-
isFile: false,
|
|
290
|
-
name: string,
|
|
291
|
-
createReader(): FileSystemDirectoryReader
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
type FileSystemEntry = FileSystemFileEntry | FileSystemDirectoryEntry;
|
|
295
|
-
interface FileSystemDirectoryReader {
|
|
296
|
-
readEntries(successCallback: (entries: FileSystemEntry[]) => void, errorCallback?: (error: Error) => void): void
|
|
297
|
-
}
|
|
298
|
-
|
|
299
280
|
async function *getEntries(item: FileSystemDirectoryEntry): AsyncIterable<FileItem | DirectoryItem> {
|
|
300
281
|
let reader = item.createReader();
|
|
301
282
|
|
|
@@ -309,7 +290,7 @@ async function *getEntries(item: FileSystemDirectoryEntry): AsyncIterable<FileIt
|
|
|
309
290
|
|
|
310
291
|
for (let entry of entries) {
|
|
311
292
|
if (entry.isFile) {
|
|
312
|
-
let file = await getEntryFile(entry);
|
|
293
|
+
let file = await getEntryFile(entry as FileSystemFileEntry);
|
|
313
294
|
yield createFileItem(file);
|
|
314
295
|
} else if (entry.isDirectory) {
|
|
315
296
|
yield createDirectoryItem(entry);
|