@react-types/shared 3.14.1 → 3.15.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-types/shared",
3
- "version": "3.14.1",
3
+ "version": "3.15.0",
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": "b03ef51e6317547dd0a840f151e59d039b1e1fd3"
17
+ "gitHead": "9202ef59e8c104dd06ffe33148445ef7932a5d1b"
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,97 +26,168 @@ 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
 
152
+ interface DroppableCollectionInsertDropEvent {
153
+ /** The dropped items. */
154
+ items: DropItem[],
155
+ /** The drop operation that should occur. */
156
+ dropOperation: DropOperation,
157
+ /** The drop target. */
158
+ target: ItemDropTarget
159
+ }
160
+
161
+ interface DroppableCollectionRootDropEvent {
162
+ /** The dropped items. */
163
+ items: DropItem[],
164
+ /** The drop operation that should occur. */
165
+ dropOperation: DropOperation
166
+ }
167
+
168
+ interface DroppableCollectionOnItemDropEvent {
169
+ /** The dropped items. */
170
+ items: DropItem[],
171
+ /** The drop operation that should occur. */
172
+ dropOperation: DropOperation,
173
+ /** Whether the drag originated within the same collection as the drop. */
174
+ isInternal: boolean,
175
+ /** The drop target. */
176
+ target: ItemDropTarget
177
+ }
178
+
179
+ interface DroppableCollectionReorderEvent {
180
+ /** The keys of the items that were reordered. */
181
+ keys: Set<Key>,
182
+ /** The drop operation that should occur. */
183
+ dropOperation: DropOperation,
184
+ /** The drop target. */
185
+ target: ItemDropTarget
186
+ }
187
+
117
188
  export interface DragTypes {
118
- has(type: string): boolean
189
+ /** Returns whether the drag contains data of the given type. */
190
+ has(type: string | symbol): boolean
119
191
  }
120
192
 
121
193
  export interface DropTargetDelegate {
@@ -127,34 +199,73 @@ export interface DropTargetDelegate {
127
199
  getDropTargetFromPoint(x: number, y: number, isValidDropTarget: (target: DropTarget) => boolean): DropTarget | null
128
200
  }
129
201
 
130
- export interface DroppableCollectionProps {
202
+ export interface DroppableCollectionUtilityOptions {
131
203
  /**
132
- * A function returning the drop operation to be performed when items matching the given types are dropped
133
- * 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'
206
+ */
207
+ acceptedDragTypes?: 'all' | Array<string | symbol>,
208
+ /**
209
+ * Handler that is called when external items are dropped "between" items.
210
+ */
211
+ onInsert?: (e: DroppableCollectionInsertDropEvent) => void,
212
+ /**
213
+ * Handler that is called when external items are dropped on the droppable collection's root.
214
+ */
215
+ onRootDrop?: (e: DroppableCollectionRootDropEvent) => void,
216
+ /**
217
+ * Handler that is called when items are dropped "on" an item.
218
+ */
219
+ onItemDrop?: (e: DroppableCollectionOnItemDropEvent) => void,
220
+ /**
221
+ * Handler that is called when items are reordered via drag in the source collection.
134
222
  */
135
- getDropOperation?: (target: DropTarget, types: DragTypes, allowedOperations: DropOperation[]) => DropOperation,
136
- /** Handler that is called when a valid drag enters the drop target. */
223
+ onReorder?: (e: DroppableCollectionReorderEvent) => void,
224
+ /**
225
+ * A function returning whether a given target in the droppable collection is a valid "on" drop target for the current drag types.
226
+ */
227
+ shouldAcceptItemDrop?: (target: ItemDropTarget, types: DragTypes) => boolean
228
+ }
229
+
230
+ export interface DroppableCollectionBaseProps {
231
+ /** Handler that is called when a valid drag enters a drop target. */
137
232
  onDropEnter?: (e: DroppableCollectionEnterEvent) => void,
138
- /** Handler that is called when a valid drag is moved within the drop target. */
139
- onDropMove?: (e: DroppableCollectionMoveEvent) => void,
140
- /** Handler that is called after a valid drag is held over the drop target for a period of time. */
233
+ /**
234
+ * Handler that is called after a valid drag is held over a drop target for a period of time.
235
+ * @private
236
+ */
141
237
  onDropActivate?: (e: DroppableCollectionActivateEvent) => void,
142
- /** Handler that is called when a valid drag exits the drop target. */
238
+ /** Handler that is called when a valid drag exits a drop target. */
143
239
  onDropExit?: (e: DroppableCollectionExitEvent) => void,
144
- /** Handler that is called when a valid drag is dropped on the drop target. */
145
- onDrop?: (e: DroppableCollectionDropEvent) => void
240
+ /**
241
+ * Handler that is called when a valid drag is dropped on a drop target. When defined, this overrides other
242
+ * drop handlers such as `onInsert`, and `onItemDrop`.
243
+ */
244
+ onDrop?: (e: DroppableCollectionDropEvent) => void,
245
+ /**
246
+ * A function returning the drop operation to be performed when items matching the given types are dropped
247
+ * on the drop target.
248
+ */
249
+ getDropOperation?: (target: DropTarget, types: DragTypes, allowedOperations: DropOperation[]) => DropOperation
146
250
  }
147
251
 
252
+ export interface DroppableCollectionProps extends DroppableCollectionUtilityOptions, DroppableCollectionBaseProps {}
253
+
148
254
  interface DraggableCollectionStartEvent extends DragStartEvent {
255
+ /** The keys of the items that were dragged. */
149
256
  keys: Set<Key>
150
257
  }
151
258
 
152
259
  interface DraggableCollectionMoveEvent extends DragMoveEvent {
260
+ /** The keys of the items that were dragged. */
153
261
  keys: Set<Key>
154
262
  }
155
263
 
156
264
  interface DraggableCollectionEndEvent extends DragEndEvent {
157
- keys: Set<Key>
265
+ /** The keys of the items that were dragged. */
266
+ keys: Set<Key>,
267
+ /** Whether the drop ended within the same collection as it originated. */
268
+ isInternal: boolean
158
269
  }
159
270
 
160
271
  export type DragPreviewRenderer = (items: DragItem[], callback: (node: HTMLElement) => void) => void;
@@ -162,7 +273,7 @@ export type DragPreviewRenderer = (items: DragItem[], callback: (node: HTMLEleme
162
273
  export interface DraggableCollectionProps {
163
274
  /** Handler that is called when a drag operation is started. */
164
275
  onDragStart?: (e: DraggableCollectionStartEvent) => void,
165
- /** Handler that is called when the dragged element is moved. */
276
+ /** Handler that is called when the drag is moved. */
166
277
  onDragMove?: (e: DraggableCollectionMoveEvent) => void,
167
278
  /** Handler that is called when the drag operation is ended, either as a result of a drop or a cancellation. */
168
279
  onDragEnd?: (e: DraggableCollectionEndEvent) => void,
@@ -40,5 +40,9 @@ export interface SpectrumLabelableProps extends LabelableProps {
40
40
  /**
41
41
  * Whether the label is labeling a required field or group.
42
42
  */
43
- isRequired?: boolean
43
+ isRequired?: boolean,
44
+ /**
45
+ * A ContextualHelp element to place next to the label.
46
+ */
47
+ contextualHelp?: ReactNode
44
48
  }