@react-types/shared 3.0.0-nightly.1786 → 3.0.0-nightly.1802

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/dnd.d.ts +82 -29
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-types/shared",
3
- "version": "3.0.0-nightly.1786+892d41e82",
3
+ "version": "3.0.0-nightly.1802+1d21d12cc",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "types": "src/index.d.ts",
@@ -14,5 +14,5 @@
14
14
  "publishConfig": {
15
15
  "access": "public"
16
16
  },
17
- "gitHead": "892d41e82dc781fb4651455d0e29c324376659ed"
17
+ "gitHead": "1d21d12cc7d2f8f36dc38a67d6cd8ea579cdc182"
18
18
  }
package/src/dnd.d.ts CHANGED
@@ -13,8 +13,9 @@
13
13
  import {Key, RefObject} from 'react';
14
14
 
15
15
  export interface DragDropEvent {
16
- // Relative to the target element's position
16
+ /** The x coordinate of the event, relative to the target element. */
17
17
  x: number,
18
+ /** The y coordinate of the event, relative to the target element. */
18
19
  y: number
19
20
  }
20
21
 
@@ -25,120 +26,167 @@ export interface DragItem {
25
26
  }
26
27
 
27
28
  export interface DragStartEvent extends DragDropEvent {
29
+ /** The event type. */
28
30
  type: 'dragstart'
29
31
  }
30
32
 
31
33
  export interface DragMoveEvent extends DragDropEvent {
34
+ /** The event type. */
32
35
  type: 'dragmove'
33
36
  }
34
37
 
35
38
  export interface DragEndEvent extends DragDropEvent {
39
+ /** The event type. */
36
40
  type: 'dragend',
41
+ /** The drop operation that occurred. */
37
42
  dropOperation: DropOperation
38
43
  }
39
44
 
40
45
  export interface DropEnterEvent extends DragDropEvent {
46
+ /** The event type. */
41
47
  type: 'dropenter'
42
48
  }
43
49
 
44
50
  export interface DropMoveEvent extends DragDropEvent {
51
+ /** The event type. */
45
52
  type: 'dropmove'
46
53
  }
47
54
 
48
55
  export interface DropActivateEvent extends DragDropEvent {
56
+ /** The event type. */
49
57
  type: 'dropactivate'
50
58
  }
51
59
 
52
60
  export interface DropExitEvent extends DragDropEvent {
61
+ /** The event type. */
53
62
  type: 'dropexit'
54
63
  }
55
64
 
56
65
  export interface TextItem {
66
+ /** The item kind. */
57
67
  kind: 'text',
68
+ /**
69
+ * The drag types available for this item.
70
+ * These are often mime types, but may be custom app-specific types.
71
+ */
58
72
  types: Set<string>,
73
+ /** Returns the data for the given type as a string. */
59
74
  getText(type: string): Promise<string>
60
75
  }
61
76
 
62
77
  export interface FileItem {
78
+ /** The item kind. */
63
79
  kind: 'file',
80
+ /** The file type (usually a mime type). */
64
81
  type: string,
82
+ /** The file name. */
65
83
  name: string,
84
+ /** Returns the contents of the file as a blob. */
66
85
  getFile(): Promise<File>,
86
+ /** Returns the contents of the file as a string. */
67
87
  getText(): Promise<string>
68
88
  }
69
89
 
70
90
  export interface DirectoryItem {
91
+ /** The item kind. */
71
92
  kind: 'directory',
93
+ /** The directory name. */
72
94
  name: string,
95
+ /** Returns the entries contained within the directory. */
73
96
  getEntries(): AsyncIterable<FileItem | DirectoryItem>
74
97
  }
75
98
 
76
99
  export type DropItem = TextItem | FileItem | DirectoryItem;
77
100
 
78
101
  export interface DropEvent extends DragDropEvent {
102
+ /** The event type. */
79
103
  type: 'drop',
104
+ /** The drop operation that should occur. */
80
105
  dropOperation: DropOperation,
106
+ /** The dropped items. */
81
107
  items: DropItem[]
82
108
  }
83
109
 
84
110
  export type DropPosition = 'on' | 'before' | 'after';
85
- interface RootDropTarget {
111
+ export interface RootDropTarget {
112
+ /** The event type. */
86
113
  type: 'root'
87
114
  }
88
115
 
89
116
  export interface ItemDropTarget {
117
+ /** The drop target type. */
90
118
  type: 'item',
119
+ /** The item key. */
91
120
  key: Key,
121
+ /** The drop position relative to the item. */
92
122
  dropPosition: DropPosition
93
123
  }
94
124
 
95
125
  export type DropTarget = RootDropTarget | ItemDropTarget;
96
126
 
97
- interface DroppableCollectionEnterEvent extends DropEnterEvent {
127
+ export interface DroppableCollectionEnterEvent extends DropEnterEvent {
128
+ /** The drop target. */
98
129
  target: DropTarget
99
130
  }
100
131
 
101
- interface DroppableCollectionMoveEvent extends DropMoveEvent {
132
+ export interface DroppableCollectionMoveEvent extends DropMoveEvent {
133
+ /** The drop target. */
102
134
  target: DropTarget
103
135
  }
104
136
 
105
- interface DroppableCollectionActivateEvent extends DropActivateEvent {
137
+ export interface DroppableCollectionActivateEvent extends DropActivateEvent {
138
+ /** The drop target. */
106
139
  target: DropTarget
107
140
  }
108
141
 
109
- interface DroppableCollectionExitEvent extends DropExitEvent {
142
+ export interface DroppableCollectionExitEvent extends DropExitEvent {
143
+ /** The drop target. */
110
144
  target: DropTarget
111
145
  }
112
146
 
113
- interface DroppableCollectionDropEvent extends DropEvent {
147
+ export interface DroppableCollectionDropEvent extends DropEvent {
148
+ /** The drop target. */
114
149
  target: DropTarget
115
150
  }
116
151
 
117
152
  interface DroppableCollectionInsertDropEvent {
153
+ /** The dropped items. */
118
154
  items: DropItem[],
155
+ /** The drop operation that should occur. */
119
156
  dropOperation: DropOperation,
157
+ /** The drop target. */
120
158
  target: ItemDropTarget
121
159
  }
122
160
 
123
161
  interface DroppableCollectionRootDropEvent {
162
+ /** The dropped items. */
124
163
  items: DropItem[],
164
+ /** The drop operation that should occur. */
125
165
  dropOperation: DropOperation
126
166
  }
127
167
 
128
168
  interface DroppableCollectionOnItemDropEvent {
169
+ /** The dropped items. */
129
170
  items: DropItem[],
171
+ /** The drop operation that should occur. */
130
172
  dropOperation: DropOperation,
173
+ /** Whether the drag originated within the same collection as the drop. */
131
174
  isInternal: boolean,
175
+ /** The drop target. */
132
176
  target: ItemDropTarget
133
177
  }
134
178
 
135
179
  interface DroppableCollectionReorderEvent {
180
+ /** The keys of the items that were reordered. */
136
181
  keys: Set<Key>,
182
+ /** The drop operation that should occur. */
137
183
  dropOperation: DropOperation,
184
+ /** The drop target. */
138
185
  target: ItemDropTarget
139
186
  }
140
187
 
141
188
  export interface DragTypes {
189
+ /** Returns whether the drag contains data of the given type. */
142
190
  has(type: string | symbol): boolean
143
191
  }
144
192
 
@@ -153,57 +201,62 @@ export interface DropTargetDelegate {
153
201
 
154
202
  export interface DroppableCollectionProps {
155
203
  /**
156
- * A function returning the drop operation to be performed when items matching the given types are dropped
157
- * on the drop target.
204
+ * The drag types that the droppable collection accepts. If the collection accepts directories, include `DIRECTORY_DRAG_TYPE` in your array of allowed types.
205
+ * @default 'all'
158
206
  */
159
- getDropOperation?: (target: DropTarget, types: DragTypes, allowedOperations: DropOperation[]) => DropOperation,
160
- /** Handler that is called when a valid drag enters the drop target. */
161
- onDropEnter?: (e: DroppableCollectionEnterEvent) => void,
162
- /** Handler that is called when a valid drag is moved within the drop target. */
163
- onDropMove?: (e: DroppableCollectionMoveEvent) => void,
164
- /** Handler that is called after a valid drag is held over the drop target for a period of time. */
165
- onDropActivate?: (e: DroppableCollectionActivateEvent) => void,
166
- /** Handler that is called when a valid drag exits the drop target. */
167
- onDropExit?: (e: DroppableCollectionExitEvent) => void,
168
- /** Handler that is called when a valid drag is dropped on the drop target. */
169
- onDrop?: (e: DroppableCollectionDropEvent) => void,
207
+ acceptedDragTypes?: 'all' | Array<string | symbol>,
170
208
  /**
171
- * Handler called when external items are dropped "between" the droppable collection's items.
209
+ * Handler that is called when external items are dropped "between" items.
172
210
  */
173
211
  onInsert?: (e: DroppableCollectionInsertDropEvent) => void,
174
212
  /**
175
- * Handler called when external items are dropped on the droppable collection's root.
213
+ * Handler that is called when external items are dropped on the droppable collection's root.
176
214
  */
177
215
  onRootDrop?: (e: DroppableCollectionRootDropEvent) => void,
178
216
  /**
179
- * Handler called when items are dropped "on" a droppable collection's item.
217
+ * Handler that is called when items are dropped "on" an item.
180
218
  */
181
219
  onItemDrop?: (e: DroppableCollectionOnItemDropEvent) => void,
182
220
  /**
183
- * Handler called when items are reordered via drag in the source collection.
221
+ * Handler that is called when items are reordered via drag in the source collection.
184
222
  */
185
223
  onReorder?: (e: DroppableCollectionReorderEvent) => void,
224
+ /** Handler that is called when a valid drag enters a drop target. */
225
+ onDropEnter?: (e: DroppableCollectionEnterEvent) => void,
226
+ /** Handler that is called after a valid drag is held over a drop target for a period of time. */
227
+ onDropActivate?: (e: DroppableCollectionActivateEvent) => void,
228
+ /** Handler that is called when a valid drag exits a drop target. */
229
+ onDropExit?: (e: DroppableCollectionExitEvent) => void,
186
230
  /**
187
- * The drag types that the droppable collection accepts. If directories are accepted, include the DIRECTORY_DRAG_TYPE from @react-aria/dnd in the array of allowed types.
188
- * @default 'all'
231
+ * Handler that is called when a valid drag is dropped on a drop target. When defined, this overrides other
232
+ * drop handlers such as `onInsert`, and `onItemDrop`.
189
233
  */
190
- acceptedDragTypes?: 'all' | Array<string | symbol>,
234
+ onDrop?: (e: DroppableCollectionDropEvent) => void,
191
235
  /**
192
236
  * A function returning whether a given target in the droppable collection is a valid "on" drop target for the current drag types.
193
237
  */
194
- shouldAcceptItemDrop?: (target: ItemDropTarget, types: DragTypes) => boolean
238
+ shouldAcceptItemDrop?: (target: ItemDropTarget, types: DragTypes) => boolean,
239
+ /**
240
+ * A function returning the drop operation to be performed when items matching the given types are dropped
241
+ * on the drop target.
242
+ */
243
+ getDropOperation?: (target: DropTarget, types: DragTypes, allowedOperations: DropOperation[]) => DropOperation
195
244
  }
196
245
 
197
246
  interface DraggableCollectionStartEvent extends DragStartEvent {
247
+ /** The keys of the items that were dragged. */
198
248
  keys: Set<Key>
199
249
  }
200
250
 
201
251
  interface DraggableCollectionMoveEvent extends DragMoveEvent {
252
+ /** The keys of the items that were dragged. */
202
253
  keys: Set<Key>
203
254
  }
204
255
 
205
256
  interface DraggableCollectionEndEvent extends DragEndEvent {
257
+ /** The keys of the items that were dragged. */
206
258
  keys: Set<Key>,
259
+ /** Whether the drop ended within the same collection as it originated. */
207
260
  isInternal: boolean
208
261
  }
209
262
 
@@ -212,7 +265,7 @@ export type DragPreviewRenderer = (items: DragItem[], callback: (node: HTMLEleme
212
265
  export interface DraggableCollectionProps {
213
266
  /** Handler that is called when a drag operation is started. */
214
267
  onDragStart?: (e: DraggableCollectionStartEvent) => void,
215
- /** Handler that is called when the dragged element is moved. */
268
+ /** Handler that is called when the drag is moved. */
216
269
  onDragMove?: (e: DraggableCollectionMoveEvent) => void,
217
270
  /** Handler that is called when the drag operation is ended, either as a result of a drop or a cancellation. */
218
271
  onDragEnd?: (e: DraggableCollectionEndEvent) => void,