@react-aria/dnd 3.9.1 → 3.9.3

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/utils.ts CHANGED
@@ -23,7 +23,7 @@ interface DroppableCollectionMap {
23
23
  export const droppableCollectionMap = new WeakMap<DroppableCollectionState, DroppableCollectionMap>();
24
24
  export const DIRECTORY_DRAG_TYPE = Symbol();
25
25
 
26
- export function getDroppableCollectionId(state: DroppableCollectionState) {
26
+ export function getDroppableCollectionId(state: DroppableCollectionState): string {
27
27
  let {id} = droppableCollectionMap.get(state) || {};
28
28
  if (!id) {
29
29
  throw new Error('Droppable item outside a droppable collection');
@@ -32,7 +32,7 @@ export function getDroppableCollectionId(state: DroppableCollectionState) {
32
32
  return id;
33
33
  }
34
34
 
35
- export function getDroppableCollectionRef(state: DroppableCollectionState) {
35
+ export function getDroppableCollectionRef(state: DroppableCollectionState): RefObject<HTMLElement | null> {
36
36
  let {ref} = droppableCollectionMap.get(state) || {};
37
37
  if (!ref) {
38
38
  throw new Error('Droppable item outside a droppable collection');
@@ -68,15 +68,15 @@ function mapModality(modality: string | null) {
68
68
  return modality;
69
69
  }
70
70
 
71
- export function useDragModality() {
71
+ export function useDragModality(): string {
72
72
  return mapModality(useInteractionModality());
73
73
  }
74
74
 
75
- export function getDragModality() {
75
+ export function getDragModality(): string {
76
76
  return mapModality(getInteractionModality());
77
77
  }
78
78
 
79
- export function writeToDataTransfer(dataTransfer: DataTransfer, items: DragItem[]) {
79
+ export function writeToDataTransfer(dataTransfer: DataTransfer, items: DragItem[]): void {
80
80
  // The data transfer API doesn't support more than one item of a given type at once.
81
81
  // In addition, only a small set of types are supported natively for transfer between applications.
82
82
  // We allow for both multiple items, as well as multiple representations of a single item.
@@ -166,7 +166,7 @@ export class DragTypes implements IDragTypes {
166
166
  this.includesUnknownTypes = !hasFiles && dataTransfer.types.includes('Files');
167
167
  }
168
168
 
169
- has(type: string | symbol) {
169
+ has(type: string | symbol): boolean {
170
170
  if (this.includesUnknownTypes || (type === DIRECTORY_DRAG_TYPE && this.types.has(GENERIC_TYPE))) {
171
171
  return true;
172
172
  }
@@ -175,7 +175,7 @@ export class DragTypes implements IDragTypes {
175
175
  }
176
176
  }
177
177
 
178
- export function readFromDataTransfer(dataTransfer: DataTransfer) {
178
+ export function readFromDataTransfer(dataTransfer: DataTransfer): DropItem[] {
179
179
  let items: DropItem[] = [];
180
180
  if (!dataTransfer) {
181
181
  return items;
@@ -346,40 +346,40 @@ export interface DnDState {
346
346
 
347
347
  export let globalDndState: DnDState = {draggingKeys: new Set()};
348
348
 
349
- export function setDraggingCollectionRef(ref: RefObject<HTMLElement | null>) {
349
+ export function setDraggingCollectionRef(ref: RefObject<HTMLElement | null>): void {
350
350
  globalDndState.draggingCollectionRef = ref;
351
351
  }
352
352
 
353
- export function setDraggingKeys(keys: Set<Key>) {
353
+ export function setDraggingKeys(keys: Set<Key>): void {
354
354
  globalDndState.draggingKeys = keys;
355
355
  }
356
356
 
357
- export function setDropCollectionRef(ref?: RefObject<HTMLElement | null>) {
357
+ export function setDropCollectionRef(ref?: RefObject<HTMLElement | null>): void {
358
358
  globalDndState.dropCollectionRef = ref;
359
359
  }
360
360
 
361
- export function clearGlobalDnDState() {
361
+ export function clearGlobalDnDState(): void {
362
362
  globalDndState = {draggingKeys: new Set()};
363
363
  }
364
364
 
365
- export function setGlobalDnDState(state: DnDState) {
365
+ export function setGlobalDnDState(state: DnDState): void {
366
366
  globalDndState = state;
367
367
  }
368
368
 
369
369
  // Util function to check if the current dragging collection ref is the same as the current targeted droppable collection ref.
370
370
  // Allows a droppable ref arg in case the global drop collection ref hasn't been set
371
- export function isInternalDropOperation(ref?: RefObject<HTMLElement | null>) {
371
+ export function isInternalDropOperation(ref?: RefObject<HTMLElement | null>): boolean {
372
372
  let {draggingCollectionRef, dropCollectionRef} = globalDndState;
373
373
  return draggingCollectionRef?.current != null && draggingCollectionRef.current === (ref?.current || dropCollectionRef?.current);
374
374
  }
375
375
 
376
376
  type DropEffect = 'none' | 'copy' | 'link' | 'move';
377
377
  export let globalDropEffect: DropEffect | undefined;
378
- export function setGlobalDropEffect(dropEffect: DropEffect | undefined) {
378
+ export function setGlobalDropEffect(dropEffect: DropEffect | undefined): void {
379
379
  globalDropEffect = dropEffect;
380
380
  }
381
381
 
382
382
  export let globalAllowedDropOperations = DROP_OPERATION.none;
383
- export function setGlobalAllowedDropOperations(o: DROP_OPERATION) {
383
+ export function setGlobalAllowedDropOperations(o: DROP_OPERATION): void {
384
384
  globalAllowedDropOperations = o;
385
385
  }