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