@react-types/shared 3.34.0 → 3.36.0

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/src/dnd.d.ts CHANGED
@@ -14,280 +14,302 @@ import {Key, RefObject} from '@react-types/shared';
14
14
 
15
15
  export interface DragDropEvent {
16
16
  /** The x coordinate of the event, relative to the target element. */
17
- x: number,
17
+ x: number;
18
18
  /** The y coordinate of the event, relative to the target element. */
19
- y: number
19
+ y: number;
20
20
  }
21
21
 
22
22
  export type DropOperation = 'copy' | 'link' | 'move' | 'cancel';
23
23
 
24
24
  export interface DragItem {
25
- [type: string]: string
25
+ [type: string]: string;
26
26
  }
27
27
 
28
28
  export interface DragStartEvent extends DragDropEvent {
29
29
  /** The event type. */
30
- type: 'dragstart'
30
+ type: 'dragstart';
31
31
  }
32
32
 
33
33
  export interface DragMoveEvent extends DragDropEvent {
34
34
  /** The event type. */
35
- type: 'dragmove'
35
+ type: 'dragmove';
36
36
  }
37
37
 
38
38
  export interface DragEndEvent extends DragDropEvent {
39
39
  /** The event type. */
40
- type: 'dragend',
40
+ type: 'dragend';
41
41
  /** The drop operation that occurred. */
42
- dropOperation: DropOperation
42
+ dropOperation: DropOperation;
43
43
  }
44
44
 
45
45
  export interface DropEnterEvent extends DragDropEvent {
46
46
  /** The event type. */
47
- type: 'dropenter'
47
+ type: 'dropenter';
48
48
  }
49
49
 
50
50
  export interface DropMoveEvent extends DragDropEvent {
51
51
  /** The event type. */
52
- type: 'dropmove'
52
+ type: 'dropmove';
53
53
  }
54
54
 
55
55
  export interface DropActivateEvent extends DragDropEvent {
56
56
  /** The event type. */
57
- type: 'dropactivate'
57
+ type: 'dropactivate';
58
58
  }
59
59
 
60
60
  export interface DropExitEvent extends DragDropEvent {
61
61
  /** The event type. */
62
- type: 'dropexit'
62
+ type: 'dropexit';
63
63
  }
64
64
 
65
65
  export interface TextDropItem {
66
66
  /** The item kind. */
67
- kind: 'text',
67
+ kind: 'text';
68
68
  /**
69
69
  * The drag types available for this item.
70
70
  * These are often mime types, but may be custom app-specific types.
71
71
  */
72
- types: Set<string>,
72
+ types: Set<string>;
73
73
  /** Returns the data for the given type as a string. */
74
- getText(type: string): Promise<string>
74
+ getText(type: string): Promise<string>;
75
75
  }
76
76
 
77
77
  export interface FileDropItem {
78
78
  /** The item kind. */
79
- kind: 'file',
79
+ kind: 'file';
80
80
  /** The file type (usually a mime type). */
81
- type: string,
81
+ type: string;
82
82
  /** The file name. */
83
- name: string,
83
+ name: string;
84
84
  /** Returns the contents of the file as a blob. */
85
- getFile(): Promise<File>,
85
+ getFile(): Promise<File>;
86
86
  /** Returns the contents of the file as a string. */
87
- getText(): Promise<string>
87
+ getText(): Promise<string>;
88
88
  }
89
89
 
90
90
  export interface DirectoryDropItem {
91
91
  /** The item kind. */
92
- kind: 'directory',
92
+ kind: 'directory';
93
93
  /** The directory name. */
94
- name: string,
94
+ name: string;
95
95
  /** Returns the entries contained within the directory. */
96
- getEntries(): AsyncIterable<FileDropItem | DirectoryDropItem>
96
+ getEntries(): AsyncIterable<FileDropItem | DirectoryDropItem>;
97
97
  }
98
98
 
99
99
  export type DropItem = TextDropItem | FileDropItem | DirectoryDropItem;
100
100
 
101
101
  export interface DropEvent extends DragDropEvent {
102
102
  /** The event type. */
103
- type: 'drop',
103
+ type: 'drop';
104
104
  /** The drop operation that should occur. */
105
- dropOperation: DropOperation,
105
+ dropOperation: DropOperation;
106
106
  /** The dropped items. */
107
- items: DropItem[]
107
+ items: DropItem[];
108
108
  }
109
109
 
110
110
  export type DropPosition = 'on' | 'before' | 'after';
111
111
  export interface RootDropTarget {
112
112
  /** The event type. */
113
- type: 'root'
113
+ type: 'root';
114
114
  }
115
115
 
116
116
  export interface ItemDropTarget {
117
117
  /** The drop target type. */
118
- type: 'item',
118
+ type: 'item';
119
119
  /** The item key. */
120
- key: Key,
120
+ key: Key;
121
121
  /** The drop position relative to the item. */
122
- dropPosition: DropPosition
122
+ dropPosition: DropPosition;
123
123
  }
124
124
 
125
125
  export type DropTarget = RootDropTarget | ItemDropTarget;
126
126
 
127
127
  export interface DroppableCollectionEnterEvent extends DropEnterEvent {
128
128
  /** The drop target. */
129
- target: DropTarget
129
+ target: DropTarget;
130
130
  }
131
131
 
132
132
  export interface DroppableCollectionMoveEvent extends DropMoveEvent {
133
133
  /** The drop target. */
134
- target: DropTarget
134
+ target: DropTarget;
135
135
  }
136
136
 
137
137
  export interface DroppableCollectionActivateEvent extends DropActivateEvent {
138
138
  /** The drop target. */
139
- target: DropTarget
139
+ target: DropTarget;
140
140
  }
141
141
 
142
142
  export interface DroppableCollectionExitEvent extends DropExitEvent {
143
143
  /** The drop target. */
144
- target: DropTarget
144
+ target: DropTarget;
145
145
  }
146
146
 
147
147
  export interface DroppableCollectionDropEvent extends DropEvent {
148
148
  /** The drop target. */
149
- target: DropTarget
149
+ target: DropTarget;
150
150
  }
151
151
 
152
152
  export interface DroppableCollectionInsertDropEvent {
153
153
  /** The dropped items. */
154
- items: DropItem[],
154
+ items: DropItem[];
155
155
  /** The drop operation that should occur. */
156
- dropOperation: DropOperation,
157
- /** The drop target. */
158
- target: ItemDropTarget
156
+ dropOperation: DropOperation;
157
+ /** The drop target. */
158
+ target: ItemDropTarget;
159
159
  }
160
160
 
161
161
  export interface DroppableCollectionRootDropEvent {
162
162
  /** The dropped items. */
163
- items: DropItem[],
163
+ items: DropItem[];
164
164
  /** The drop operation that should occur. */
165
- dropOperation: DropOperation
165
+ dropOperation: DropOperation;
166
166
  }
167
167
 
168
168
  export interface DroppableCollectionOnItemDropEvent {
169
169
  /** The dropped items. */
170
- items: DropItem[],
170
+ items: DropItem[];
171
171
  /** The drop operation that should occur. */
172
- dropOperation: DropOperation,
172
+ dropOperation: DropOperation;
173
173
  /** Whether the drag originated within the same collection as the drop. */
174
- isInternal: boolean,
174
+ isInternal: boolean;
175
175
  /** The drop target. */
176
- target: ItemDropTarget
176
+ target: ItemDropTarget;
177
177
  }
178
178
 
179
179
  export interface DroppableCollectionReorderEvent {
180
180
  /** The keys of the items that were reordered. */
181
- keys: Set<Key>,
181
+ keys: Set<Key>;
182
182
  /** The drop operation that should occur. */
183
- dropOperation: DropOperation,
183
+ dropOperation: DropOperation;
184
184
  /** The drop target. */
185
- target: ItemDropTarget
185
+ target: ItemDropTarget;
186
186
  }
187
187
 
188
+ export type DragType = string | symbol;
188
189
  export interface DragTypes {
189
190
  /** Returns whether the drag contains data of the given type. */
190
- has(type: string | symbol): boolean
191
+ has(type: DragType | DragType[]): boolean;
191
192
  }
192
193
 
193
194
  export interface DropTargetDelegate {
194
195
  /**
195
- * Returns a drop target within a collection for the given x and y coordinates.
196
- * The point is provided relative to the top left corner of the collection container.
197
- * A drop target can be checked to see if it is valid using the provided `isValidDropTarget` function.
196
+ * Returns a drop target within a collection for the given x and y coordinates. The point is
197
+ * provided relative to the top left corner of the collection container. A drop target can be
198
+ * checked to see if it is valid using the provided `isValidDropTarget` function.
198
199
  */
199
- getDropTargetFromPoint(x: number, y: number, isValidDropTarget: (target: DropTarget) => boolean): DropTarget | null
200
+ getDropTargetFromPoint(
201
+ x: number,
202
+ y: number,
203
+ isValidDropTarget: (target: DropTarget) => boolean
204
+ ): DropTarget | null;
200
205
  }
201
206
 
202
207
  export interface DroppableCollectionUtilityOptions {
203
208
  /**
204
- * The drag types that the droppable collection accepts. If the collection accepts directories, include `DIRECTORY_DRAG_TYPE` in your array of allowed types.
209
+ * The drag types that the droppable collection accepts. If the collection accepts directories,
210
+ * include `DIRECTORY_DRAG_TYPE` in your array of allowed types.
211
+ *
205
212
  * @default 'all'
206
213
  */
207
- acceptedDragTypes?: 'all' | Array<string | symbol>,
214
+ acceptedDragTypes?: 'all' | Array<string | symbol>;
208
215
  /**
209
216
  * Handler that is called when external items are dropped "between" items.
210
217
  */
211
- onInsert?: (e: DroppableCollectionInsertDropEvent) => void,
218
+ onInsert?: (e: DroppableCollectionInsertDropEvent) => void;
212
219
  /**
213
220
  * Handler that is called when external items are dropped on the droppable collection's root.
214
221
  */
215
- onRootDrop?: (e: DroppableCollectionRootDropEvent) => void,
222
+ onRootDrop?: (e: DroppableCollectionRootDropEvent) => void;
216
223
  /**
217
224
  * Handler that is called when items are dropped "on" an item.
218
225
  */
219
- onItemDrop?: (e: DroppableCollectionOnItemDropEvent) => void,
226
+ onItemDrop?: (e: DroppableCollectionOnItemDropEvent) => void;
220
227
  /**
221
228
  * Handler that is called when items are reordered within the collection.
222
229
  * This handler only allows dropping between items, not on items.
223
230
  * It does not allow moving items to a different parent item within a tree.
224
231
  */
225
- onReorder?: (e: DroppableCollectionReorderEvent) => void,
232
+ onReorder?: (e: DroppableCollectionReorderEvent) => void;
226
233
  /**
227
234
  * Handler that is called when items are moved within the source collection.
228
235
  * This handler allows dropping both on or between items, and items may be
229
236
  * moved to a different parent item within a tree.
230
237
  */
231
- onMove?: (e: DroppableCollectionReorderEvent) => void,
238
+ onMove?: (e: DroppableCollectionReorderEvent) => void;
232
239
  /**
233
- * A function returning whether a given target in the droppable collection is a valid "on" drop target for the current drag types.
240
+ * A function returning whether a given target in the droppable collection is a valid "on" drop
241
+ * target for the current drag types.
234
242
  */
235
- shouldAcceptItemDrop?: (target: ItemDropTarget, types: DragTypes) => boolean
243
+ shouldAcceptItemDrop?: (target: ItemDropTarget, types: DragTypes) => boolean;
236
244
  }
237
245
 
238
246
  export interface DroppableCollectionBaseProps {
239
247
  /** Handler that is called when a valid drag enters a drop target. */
240
- onDropEnter?: (e: DroppableCollectionEnterEvent) => void,
248
+ onDropEnter?: (e: DroppableCollectionEnterEvent) => void;
241
249
  /**
242
250
  * Handler that is called after a valid drag is held over a drop target for a period of time.
243
251
  */
244
- onDropActivate?: (e: DroppableCollectionActivateEvent) => void,
252
+ onDropActivate?: (e: DroppableCollectionActivateEvent) => void;
245
253
  /** Handler that is called when a valid drag exits a drop target. */
246
- onDropExit?: (e: DroppableCollectionExitEvent) => void,
254
+ onDropExit?: (e: DroppableCollectionExitEvent) => void;
247
255
  /**
248
- * Handler that is called when a valid drag is dropped on a drop target. When defined, this overrides other
249
- * drop handlers such as `onInsert`, and `onItemDrop`.
256
+ * Handler that is called when a valid drag is dropped on a drop target. When defined, this
257
+ * overrides other drop handlers such as `onInsert`, and `onItemDrop`.
250
258
  */
251
- onDrop?: (e: DroppableCollectionDropEvent) => void,
259
+ onDrop?: (e: DroppableCollectionDropEvent) => void;
252
260
  /**
253
- * A function returning the drop operation to be performed when items matching the given types are dropped
254
- * on the drop target.
261
+ * A function returning the drop operation to be performed when items matching the given types are
262
+ * dropped on the drop target.
255
263
  */
256
- getDropOperation?: (target: DropTarget, types: DragTypes, allowedOperations: DropOperation[]) => DropOperation
264
+ getDropOperation?: (
265
+ target: DropTarget,
266
+ types: DragTypes,
267
+ allowedOperations: DropOperation[]
268
+ ) => DropOperation;
257
269
  }
258
270
 
259
- export interface DroppableCollectionProps extends DroppableCollectionUtilityOptions, DroppableCollectionBaseProps {}
271
+ export interface DroppableCollectionProps
272
+ extends DroppableCollectionUtilityOptions, DroppableCollectionBaseProps {}
260
273
 
261
274
  export interface DraggableCollectionStartEvent extends DragStartEvent {
262
275
  /** The keys of the items that were dragged. */
263
- keys: Set<Key>
276
+ keys: Set<Key>;
264
277
  }
265
278
 
266
279
  export interface DraggableCollectionMoveEvent extends DragMoveEvent {
267
280
  /** The keys of the items that were dragged. */
268
- keys: Set<Key>
281
+ keys: Set<Key>;
269
282
  }
270
283
 
271
284
  export interface DraggableCollectionEndEvent extends DragEndEvent {
272
285
  /** The keys of the items that were dragged. */
273
- keys: Set<Key>,
286
+ keys: Set<Key>;
274
287
  /** Whether the drop ended within the same collection as it originated. */
275
- isInternal: boolean
288
+ isInternal: boolean;
276
289
  }
277
290
 
278
- export type DragPreviewRenderer = (items: DragItem[], callback: (node: HTMLElement | null, x?: number, y?: number) => void) => void;
291
+ export type DragPreviewRenderer = (
292
+ items: DragItem[],
293
+ callback: (node: HTMLElement | null, x?: number, y?: number) => void
294
+ ) => void;
279
295
 
280
296
  export interface DraggableCollectionProps<T = object> {
281
297
  /** Handler that is called when a drag operation is started. */
282
- onDragStart?: (e: DraggableCollectionStartEvent) => void,
298
+ onDragStart?: (e: DraggableCollectionStartEvent) => void;
283
299
  /** Handler that is called when the drag is moved. */
284
- onDragMove?: (e: DraggableCollectionMoveEvent) => void,
285
- /** Handler that is called when the drag operation is ended, either as a result of a drop or a cancellation. */
286
- onDragEnd?: (e: DraggableCollectionEndEvent) => void,
300
+ onDragMove?: (e: DraggableCollectionMoveEvent) => void;
301
+ /**
302
+ * Handler that is called when the drag operation is ended, either as a result of a drop or a
303
+ * cancellation.
304
+ */
305
+ onDragEnd?: (e: DraggableCollectionEndEvent) => void;
287
306
  /** A function that returns the items being dragged. */
288
- getItems: (keys: Set<Key>, items: T[]) => DragItem[],
307
+ getItems: (keys: Set<Key>, items: T[]) => DragItem[];
289
308
  /** The ref of the element that will be rendered as the drag preview while dragging. */
290
- preview?: RefObject<DragPreviewRenderer | null>,
291
- /** Function that returns the drop operations that are allowed for the dragged items. If not provided, all drop operations are allowed. */
292
- getAllowedDropOperations?: () => DropOperation[]
309
+ preview?: RefObject<DragPreviewRenderer | null>;
310
+ /**
311
+ * Function that returns the drop operations that are allowed for the dragged items. If not
312
+ * provided, all drop operations are allowed.
313
+ */
314
+ getAllowedDropOperations?: () => DropOperation[];
293
315
  }