1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | import {Key, RefObject} from 'react';
|
14 |
|
15 | export interface DragDropEvent {
|
16 |
|
17 | x: number,
|
18 |
|
19 | y: number
|
20 | }
|
21 |
|
22 | export type DropOperation = 'copy' | 'link' | 'move' | 'cancel';
|
23 |
|
24 | export interface DragItem {
|
25 | [type: string]: string
|
26 | }
|
27 |
|
28 | export interface DragStartEvent extends DragDropEvent {
|
29 |
|
30 | type: 'dragstart'
|
31 | }
|
32 |
|
33 | export interface DragMoveEvent extends DragDropEvent {
|
34 |
|
35 | type: 'dragmove'
|
36 | }
|
37 |
|
38 | export interface DragEndEvent extends DragDropEvent {
|
39 |
|
40 | type: 'dragend',
|
41 |
|
42 | dropOperation: DropOperation
|
43 | }
|
44 |
|
45 | export interface DropEnterEvent extends DragDropEvent {
|
46 |
|
47 | type: 'dropenter'
|
48 | }
|
49 |
|
50 | export interface DropMoveEvent extends DragDropEvent {
|
51 |
|
52 | type: 'dropmove'
|
53 | }
|
54 |
|
55 | export interface DropActivateEvent extends DragDropEvent {
|
56 |
|
57 | type: 'dropactivate'
|
58 | }
|
59 |
|
60 | export interface DropExitEvent extends DragDropEvent {
|
61 |
|
62 | type: 'dropexit'
|
63 | }
|
64 |
|
65 | export interface TextDropItem {
|
66 |
|
67 | kind: 'text',
|
68 | |
69 |
|
70 |
|
71 |
|
72 | types: Set<string>,
|
73 |
|
74 | getText(type: string): Promise<string>
|
75 | }
|
76 |
|
77 | export interface FileDropItem {
|
78 |
|
79 | kind: 'file',
|
80 |
|
81 | type: string,
|
82 |
|
83 | name: string,
|
84 |
|
85 | getFile(): Promise<File>,
|
86 |
|
87 | getText(): Promise<string>
|
88 | }
|
89 |
|
90 | export interface DirectoryDropItem {
|
91 |
|
92 | kind: 'directory',
|
93 |
|
94 | name: string,
|
95 |
|
96 | getEntries(): AsyncIterable<FileDropItem | DirectoryDropItem>
|
97 | }
|
98 |
|
99 | export type DropItem = TextDropItem | FileDropItem | DirectoryDropItem;
|
100 |
|
101 | export interface DropEvent extends DragDropEvent {
|
102 |
|
103 | type: 'drop',
|
104 |
|
105 | dropOperation: DropOperation,
|
106 |
|
107 | items: DropItem[]
|
108 | }
|
109 |
|
110 | export type DropPosition = 'on' | 'before' | 'after';
|
111 | export interface RootDropTarget {
|
112 |
|
113 | type: 'root'
|
114 | }
|
115 |
|
116 | export interface ItemDropTarget {
|
117 |
|
118 | type: 'item',
|
119 |
|
120 | key: Key,
|
121 |
|
122 | dropPosition: DropPosition
|
123 | }
|
124 |
|
125 | export type DropTarget = RootDropTarget | ItemDropTarget;
|
126 |
|
127 | export interface DroppableCollectionEnterEvent extends DropEnterEvent {
|
128 |
|
129 | target: DropTarget
|
130 | }
|
131 |
|
132 | export interface DroppableCollectionMoveEvent extends DropMoveEvent {
|
133 |
|
134 | target: DropTarget
|
135 | }
|
136 |
|
137 | export interface DroppableCollectionActivateEvent extends DropActivateEvent {
|
138 |
|
139 | target: DropTarget
|
140 | }
|
141 |
|
142 | export interface DroppableCollectionExitEvent extends DropExitEvent {
|
143 |
|
144 | target: DropTarget
|
145 | }
|
146 |
|
147 | export interface DroppableCollectionDropEvent extends DropEvent {
|
148 |
|
149 | target: DropTarget
|
150 | }
|
151 |
|
152 | export interface DroppableCollectionInsertDropEvent {
|
153 |
|
154 | items: DropItem[],
|
155 |
|
156 | dropOperation: DropOperation,
|
157 |
|
158 | target: ItemDropTarget
|
159 | }
|
160 |
|
161 | export interface DroppableCollectionRootDropEvent {
|
162 |
|
163 | items: DropItem[],
|
164 |
|
165 | dropOperation: DropOperation
|
166 | }
|
167 |
|
168 | export interface DroppableCollectionOnItemDropEvent {
|
169 |
|
170 | items: DropItem[],
|
171 |
|
172 | dropOperation: DropOperation,
|
173 |
|
174 | isInternal: boolean,
|
175 |
|
176 | target: ItemDropTarget
|
177 | }
|
178 |
|
179 | export interface DroppableCollectionReorderEvent {
|
180 |
|
181 | keys: Set<Key>,
|
182 |
|
183 | dropOperation: DropOperation,
|
184 |
|
185 | target: ItemDropTarget
|
186 | }
|
187 |
|
188 | export interface DragTypes {
|
189 |
|
190 | has(type: string | symbol): boolean
|
191 | }
|
192 |
|
193 | export interface DropTargetDelegate {
|
194 | |
195 |
|
196 |
|
197 |
|
198 |
|
199 | getDropTargetFromPoint(x: number, y: number, isValidDropTarget: (target: DropTarget) => boolean): DropTarget | null
|
200 | }
|
201 |
|
202 | export interface DroppableCollectionUtilityOptions {
|
203 | |
204 |
|
205 |
|
206 |
|
207 | acceptedDragTypes?: 'all' | Array<string | symbol>,
|
208 | |
209 |
|
210 |
|
211 | onInsert?: (e: DroppableCollectionInsertDropEvent) => void,
|
212 | |
213 |
|
214 |
|
215 | onRootDrop?: (e: DroppableCollectionRootDropEvent) => void,
|
216 | |
217 |
|
218 |
|
219 | onItemDrop?: (e: DroppableCollectionOnItemDropEvent) => void,
|
220 | |
221 |
|
222 |
|
223 | onReorder?: (e: DroppableCollectionReorderEvent) => void,
|
224 | |
225 |
|
226 |
|
227 | shouldAcceptItemDrop?: (target: ItemDropTarget, types: DragTypes) => boolean
|
228 | }
|
229 |
|
230 | export interface DroppableCollectionBaseProps {
|
231 |
|
232 | onDropEnter?: (e: DroppableCollectionEnterEvent) => void,
|
233 | |
234 |
|
235 |
|
236 |
|
237 | onDropActivate?: (e: DroppableCollectionActivateEvent) => void,
|
238 |
|
239 | onDropExit?: (e: DroppableCollectionExitEvent) => void,
|
240 | |
241 |
|
242 |
|
243 |
|
244 | onDrop?: (e: DroppableCollectionDropEvent) => void,
|
245 | |
246 |
|
247 |
|
248 |
|
249 | getDropOperation?: (target: DropTarget, types: DragTypes, allowedOperations: DropOperation[]) => DropOperation
|
250 | }
|
251 |
|
252 | export interface DroppableCollectionProps extends DroppableCollectionUtilityOptions, DroppableCollectionBaseProps {}
|
253 |
|
254 | export interface DraggableCollectionStartEvent extends DragStartEvent {
|
255 |
|
256 | keys: Set<Key>
|
257 | }
|
258 |
|
259 | export interface DraggableCollectionMoveEvent extends DragMoveEvent {
|
260 |
|
261 | keys: Set<Key>
|
262 | }
|
263 |
|
264 | export interface DraggableCollectionEndEvent extends DragEndEvent {
|
265 |
|
266 | keys: Set<Key>,
|
267 |
|
268 | isInternal: boolean
|
269 | }
|
270 |
|
271 | export type DragPreviewRenderer = (items: DragItem[], callback: (node: HTMLElement) => void) => void;
|
272 |
|
273 | export interface DraggableCollectionProps {
|
274 |
|
275 | onDragStart?: (e: DraggableCollectionStartEvent) => void,
|
276 |
|
277 | onDragMove?: (e: DraggableCollectionMoveEvent) => void,
|
278 |
|
279 | onDragEnd?: (e: DraggableCollectionEndEvent) => void,
|
280 |
|
281 | getItems: (keys: Set<Key>) => DragItem[],
|
282 |
|
283 | preview?: RefObject<DragPreviewRenderer>,
|
284 |
|
285 | getAllowedDropOperations?: () => DropOperation[]
|
286 | }
|