1 | /*
|
2 | * Copyright 2020 Ladifire. All rights reserved.
|
3 | * This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
4 | * you may not use this file except in compliance with the License. You may obtain a copy
|
5 | * of the License at http://www.apache.org/licenses/LICENSE-2.0
|
6 | *
|
7 | * Unless required by applicable law or agreed to in writing, software distributed under
|
8 | * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
9 | * OF ANY KIND, either express or implied. See the License for the specific language
|
10 | * governing permissions and limitations under the License.
|
11 | */
|
12 |
|
13 | import {Key, ReactNode} from 'react';
|
14 |
|
15 | export interface DndBase {
|
16 | dragDelegate?: DragDelegate,
|
17 | dropDelegate?: DropDelegate
|
18 | }
|
19 |
|
20 | // TODO: move this somewhere - enums in .d.ts files don't work well
|
21 | export enum DropOperation {
|
22 | /** The drop is not allowed. */
|
23 | NONE = 0,
|
24 |
|
25 | /** The dropped data can be moved between the source and destination. */
|
26 | MOVE = 1 << 0,
|
27 |
|
28 | /** The dropped data can be copied between the source and destination. */
|
29 | COPY = 1 << 1,
|
30 |
|
31 | /** The dropped data can be shared between the source and destination. */
|
32 | LINK = 1 << 2,
|
33 |
|
34 | /** All types of drops are allowed. */
|
35 | ALL = MOVE | COPY | LINK
|
36 | }
|
37 |
|
38 | export enum DropPosition {
|
39 | ON = 1 << 0,
|
40 | BETWEEN = 1 << 1,
|
41 | ANY = ON | BETWEEN
|
42 | }
|
43 |
|
44 | export interface DragTarget {
|
45 | /** The type of view being dragged. */
|
46 | type: string,
|
47 |
|
48 | /** The key of the view being dragged. */
|
49 | key: Key
|
50 | }
|
51 |
|
52 | export interface DropTarget {
|
53 | /** The type of view being dropped on or between. */
|
54 | type: string,
|
55 |
|
56 | /**
|
57 | * The key of the view being dropped on or between.
|
58 | * If null, it represents the entire collection view.
|
59 | */
|
60 | key: Key | null,
|
61 |
|
62 | dropPosition: DropPosition
|
63 | }
|
64 |
|
65 | export interface DragDelegate {
|
66 | shouldAllowDrag(target: DragTarget): boolean,
|
67 | prepareDragData(target: DragTarget, dataTransfer: DataTransfer): void,
|
68 | getAllowedDropOperations(target: DropTarget): DropOperation,
|
69 | renderDragView(items: Array<any>): ReactNode,
|
70 | onDragEnd(target: DropTarget, dropOperation: DropOperation): void
|
71 | }
|
72 |
|
73 | export interface DropDelegate {
|
74 | shouldAcceptDrop(target: DropTarget, types: Set<string>): boolean,
|
75 | getAllowedDropPositions(target: DropTarget): DropPosition,
|
76 | overrideDropTarget(target: DropTarget): DropTarget,
|
77 | getDropOperation(target: DropTarget, allowedOperations: DropOperation): DropOperation,
|
78 | onDrop(target: DropTarget, dataTransfer: DataTransfer, dropOperation: DropOperation): void
|
79 | }
|