@react-aria/dnd 3.9.2 → 3.10.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.
Files changed (40) hide show
  1. package/dist/DragManager.main.js +79 -12
  2. package/dist/DragManager.main.js.map +1 -1
  3. package/dist/DragManager.mjs +79 -12
  4. package/dist/DragManager.module.js +79 -12
  5. package/dist/DragManager.module.js.map +1 -1
  6. package/dist/DropTargetKeyboardNavigation.main.js +201 -0
  7. package/dist/DropTargetKeyboardNavigation.main.js.map +1 -0
  8. package/dist/DropTargetKeyboardNavigation.mjs +196 -0
  9. package/dist/DropTargetKeyboardNavigation.module.js +196 -0
  10. package/dist/DropTargetKeyboardNavigation.module.js.map +1 -0
  11. package/dist/ListDropTargetDelegate.main.js.map +1 -1
  12. package/dist/ListDropTargetDelegate.module.js.map +1 -1
  13. package/dist/types.d.ts +7 -1
  14. package/dist/types.d.ts.map +1 -1
  15. package/dist/useDrop.main.js.map +1 -1
  16. package/dist/useDrop.module.js.map +1 -1
  17. package/dist/useDropIndicator.main.js +15 -7
  18. package/dist/useDropIndicator.main.js.map +1 -1
  19. package/dist/useDropIndicator.mjs +15 -7
  20. package/dist/useDropIndicator.module.js +15 -7
  21. package/dist/useDropIndicator.module.js.map +1 -1
  22. package/dist/useDroppableCollection.main.js +33 -103
  23. package/dist/useDroppableCollection.main.js.map +1 -1
  24. package/dist/useDroppableCollection.mjs +33 -103
  25. package/dist/useDroppableCollection.module.js +33 -103
  26. package/dist/useDroppableCollection.module.js.map +1 -1
  27. package/dist/useDroppableItem.main.js +4 -2
  28. package/dist/useDroppableItem.main.js.map +1 -1
  29. package/dist/useDroppableItem.mjs +4 -2
  30. package/dist/useDroppableItem.module.js +4 -2
  31. package/dist/useDroppableItem.module.js.map +1 -1
  32. package/package.json +17 -12
  33. package/src/.DS_Store +0 -0
  34. package/src/DragManager.ts +66 -17
  35. package/src/DropTargetKeyboardNavigation.ts +273 -0
  36. package/src/ListDropTargetDelegate.ts +1 -1
  37. package/src/useDrop.ts +0 -1
  38. package/src/useDropIndicator.ts +17 -11
  39. package/src/useDroppableCollection.ts +41 -134
  40. package/src/useDroppableItem.ts +7 -4
@@ -1,5 +1,6 @@
1
1
  import {clearGlobalDnDState as $7252cd45fc48c07c$export$70936501603e6c57, DIRECTORY_DRAG_TYPE as $7252cd45fc48c07c$export$990fced5dfac2637, droppableCollectionMap as $7252cd45fc48c07c$export$dfdf5deeaf27473f, getTypes as $7252cd45fc48c07c$export$e1d41611756c6326, globalDndState as $7252cd45fc48c07c$export$6ca6700462636d0b, isInternalDropOperation as $7252cd45fc48c07c$export$78bf638634500fa5, setDropCollectionRef as $7252cd45fc48c07c$export$dac8db29d42db9a1} from "./utils.mjs";
2
2
  import {registerDropTarget as $67560de7c78cb232$export$c28d9fb4a54e471a} from "./DragManager.mjs";
3
+ import {navigate as $e154566cef11553b$export$ff7962acd6052c28} from "./DropTargetKeyboardNavigation.mjs";
3
4
  import {useAutoScroll as $80d9daea3067eff3$export$6323452ca4533ed8} from "./useAutoScroll.mjs";
4
5
  import {useDrop as $5c06e4929e123553$export$ccdee5eaf73cf661} from "./useDrop.mjs";
5
6
  import {useRef as $4ZR0C$useRef, useCallback as $4ZR0C$useCallback, useEffect as $4ZR0C$useEffect} from "react";
@@ -25,16 +26,7 @@ import {useLocale as $4ZR0C$useLocale} from "@react-aria/i18n";
25
26
 
26
27
 
27
28
 
28
- const $4b52e4eff84e5217$var$DROP_POSITIONS = [
29
- 'before',
30
- 'on',
31
- 'after'
32
- ];
33
- const $4b52e4eff84e5217$var$DROP_POSITIONS_RTL = [
34
- 'after',
35
- 'on',
36
- 'before'
37
- ];
29
+
38
30
  function $4b52e4eff84e5217$export$f4e2f423c21f7b04(props, state, ref) {
39
31
  let localState = (0, $4ZR0C$useRef)({
40
32
  props: props,
@@ -45,7 +37,7 @@ function $4b52e4eff84e5217$export$f4e2f423c21f7b04(props, state, ref) {
45
37
  localState.props = props;
46
38
  localState.state = state;
47
39
  let defaultOnDrop = (0, $4ZR0C$useCallback)(async (e)=>{
48
- let { onInsert: onInsert, onRootDrop: onRootDrop, onItemDrop: onItemDrop, onReorder: onReorder, acceptedDragTypes: acceptedDragTypes = 'all', shouldAcceptItemDrop: shouldAcceptItemDrop } = localState.props;
40
+ let { onInsert: onInsert, onRootDrop: onRootDrop, onItemDrop: onItemDrop, onReorder: onReorder, onMove: onMove, acceptedDragTypes: acceptedDragTypes = 'all', shouldAcceptItemDrop: shouldAcceptItemDrop } = localState.props;
49
41
  let { draggingKeys: draggingKeys } = (0, $7252cd45fc48c07c$export$6ca6700462636d0b);
50
42
  let isInternal = (0, $7252cd45fc48c07c$export$78bf638634500fa5)(ref);
51
43
  let { target: target, dropOperation: dropOperation, items: items } = e;
@@ -78,6 +70,11 @@ function $4b52e4eff84e5217$export$f4e2f423c21f7b04(props, state, ref) {
78
70
  isInternal: isInternal,
79
71
  target: target
80
72
  });
73
+ if (onMove && isInternal) await onMove({
74
+ keys: draggingKeys,
75
+ dropOperation: dropOperation,
76
+ target: target
77
+ });
81
78
  if (target.dropPosition !== 'on') {
82
79
  if (!isInternal && onInsert) await onInsert({
83
80
  items: filteredItems,
@@ -158,8 +155,8 @@ function $4b52e4eff84e5217$export$f4e2f423c21f7b04(props, state, ref) {
158
155
  autoScroll.stop();
159
156
  },
160
157
  onDropActivate (e) {
161
- var _state_target, _state_target1;
162
- if (((_state_target = state.target) === null || _state_target === void 0 ? void 0 : _state_target.type) === 'item' && ((_state_target1 = state.target) === null || _state_target1 === void 0 ? void 0 : _state_target1.dropPosition) === 'on' && typeof props.onDropActivate === 'function') props.onDropActivate({
158
+ var _state_target;
159
+ if (((_state_target = state.target) === null || _state_target === void 0 ? void 0 : _state_target.type) === 'item' && typeof props.onDropActivate === 'function') props.onDropActivate({
163
160
  type: 'dropactivate',
164
161
  x: e.x,
165
162
  y: e.y,
@@ -193,11 +190,16 @@ function $4b52e4eff84e5217$export$f4e2f423c21f7b04(props, state, ref) {
193
190
  // is some indication that items were added.
194
191
  if (state.selectionManager.focusedKey === prevFocusedKey) {
195
192
  let first = newKeys.keys().next().value;
196
- let item = state.collection.getItem(first);
197
- // If this is a cell, focus the parent row.
198
- if ((item === null || item === void 0 ? void 0 : item.type) === 'cell') first = item.parentKey;
199
- state.selectionManager.setFocusedKey(first);
200
- if (state.selectionManager.selectionMode === 'none') (0, $4ZR0C$setInteractionModality)('keyboard');
193
+ if (first != null) {
194
+ let item = state.collection.getItem(first);
195
+ // If this is a cell, focus the parent row.
196
+ // eslint-disable-next-line max-depth
197
+ if ((item === null || item === void 0 ? void 0 : item.type) === 'cell') first = item.parentKey;
198
+ // eslint-disable-next-line max-depth
199
+ if (first != null) state.selectionManager.setFocusedKey(first);
200
+ // eslint-disable-next-line max-depth
201
+ if (state.selectionManager.selectionMode === 'none') (0, $4ZR0C$setInteractionModality)('keyboard');
202
+ }
201
203
  }
202
204
  } else if (prevFocusedKey != null && state.selectionManager.focusedKey === prevFocusedKey && isInternal && target.type === 'item' && target.dropPosition !== 'on' && draggingKeys.has((_state_collection_getItem = state.collection.getItem(prevFocusedKey)) === null || _state_collection_getItem === void 0 ? void 0 : _state_collection_getItem.parentKey)) {
203
205
  var _state_collection_getItem1;
@@ -263,84 +265,11 @@ function $4b52e4eff84e5217$export$f4e2f423c21f7b04(props, state, ref) {
263
265
  let { direction: direction } = (0, $4ZR0C$useLocale)();
264
266
  (0, $4ZR0C$useEffect)(()=>{
265
267
  if (!ref.current) return;
266
- let getNextTarget = (target, wrap = true, horizontal = false)=>{
267
- var _keyboardDelegate_getKeyRightOf, _keyboardDelegate_getKeyBelow, _keyboardDelegate_getLastKey, _keyboardDelegate_getFirstKey;
268
- if (!target) return {
269
- type: 'root'
270
- };
271
- let { keyboardDelegate: keyboardDelegate } = localState.props;
272
- let nextKey;
273
- if ((target === null || target === void 0 ? void 0 : target.type) === 'item') nextKey = horizontal ? (_keyboardDelegate_getKeyRightOf = keyboardDelegate.getKeyRightOf) === null || _keyboardDelegate_getKeyRightOf === void 0 ? void 0 : _keyboardDelegate_getKeyRightOf.call(keyboardDelegate, target.key) : (_keyboardDelegate_getKeyBelow = keyboardDelegate.getKeyBelow) === null || _keyboardDelegate_getKeyBelow === void 0 ? void 0 : _keyboardDelegate_getKeyBelow.call(keyboardDelegate, target.key);
274
- else nextKey = horizontal && direction === 'rtl' ? (_keyboardDelegate_getLastKey = keyboardDelegate.getLastKey) === null || _keyboardDelegate_getLastKey === void 0 ? void 0 : _keyboardDelegate_getLastKey.call(keyboardDelegate) : (_keyboardDelegate_getFirstKey = keyboardDelegate.getFirstKey) === null || _keyboardDelegate_getFirstKey === void 0 ? void 0 : _keyboardDelegate_getFirstKey.call(keyboardDelegate);
275
- let dropPositions = horizontal && direction === 'rtl' ? $4b52e4eff84e5217$var$DROP_POSITIONS_RTL : $4b52e4eff84e5217$var$DROP_POSITIONS;
276
- let dropPosition = dropPositions[0];
277
- if (target.type === 'item') {
278
- // If the the keyboard delegate returned the next key in the collection,
279
- // first try the other positions in the current key. Otherwise (e.g. in a grid layout),
280
- // jump to the same drop position in the new key.
281
- let nextCollectionKey = horizontal && direction === 'rtl' ? localState.state.collection.getKeyBefore(target.key) : localState.state.collection.getKeyAfter(target.key);
282
- if (nextKey == null || nextKey === nextCollectionKey) {
283
- let positionIndex = dropPositions.indexOf(target.dropPosition);
284
- let nextDropPosition = dropPositions[positionIndex + 1];
285
- if (positionIndex < dropPositions.length - 1 && !(nextDropPosition === dropPositions[2] && nextKey != null)) return {
286
- type: 'item',
287
- key: target.key,
288
- dropPosition: nextDropPosition
289
- };
290
- // If the last drop position was 'after', then 'before' on the next key is equivalent.
291
- // Switch to 'on' instead.
292
- if (target.dropPosition === dropPositions[2]) dropPosition = 'on';
293
- } else dropPosition = target.dropPosition;
294
- }
295
- if (nextKey == null) {
296
- if (wrap) return {
297
- type: 'root'
298
- };
299
- return null;
300
- }
301
- return {
302
- type: 'item',
303
- key: nextKey,
304
- dropPosition: dropPosition
305
- };
268
+ let getNextTarget = (target, wrap = true, key = 'down')=>{
269
+ return (0, $e154566cef11553b$export$ff7962acd6052c28)(localState.props.keyboardDelegate, localState.state.collection, target, key, direction === 'rtl', wrap);
306
270
  };
307
- let getPreviousTarget = (target, wrap = true, horizontal = false)=>{
308
- var _keyboardDelegate_getKeyLeftOf, _keyboardDelegate_getKeyAbove, _keyboardDelegate_getFirstKey, _keyboardDelegate_getLastKey;
309
- let { keyboardDelegate: keyboardDelegate } = localState.props;
310
- let nextKey;
311
- if ((target === null || target === void 0 ? void 0 : target.type) === 'item') nextKey = horizontal ? (_keyboardDelegate_getKeyLeftOf = keyboardDelegate.getKeyLeftOf) === null || _keyboardDelegate_getKeyLeftOf === void 0 ? void 0 : _keyboardDelegate_getKeyLeftOf.call(keyboardDelegate, target.key) : (_keyboardDelegate_getKeyAbove = keyboardDelegate.getKeyAbove) === null || _keyboardDelegate_getKeyAbove === void 0 ? void 0 : _keyboardDelegate_getKeyAbove.call(keyboardDelegate, target.key);
312
- else nextKey = horizontal && direction === 'rtl' ? (_keyboardDelegate_getFirstKey = keyboardDelegate.getFirstKey) === null || _keyboardDelegate_getFirstKey === void 0 ? void 0 : _keyboardDelegate_getFirstKey.call(keyboardDelegate) : (_keyboardDelegate_getLastKey = keyboardDelegate.getLastKey) === null || _keyboardDelegate_getLastKey === void 0 ? void 0 : _keyboardDelegate_getLastKey.call(keyboardDelegate);
313
- let dropPositions = horizontal && direction === 'rtl' ? $4b52e4eff84e5217$var$DROP_POSITIONS_RTL : $4b52e4eff84e5217$var$DROP_POSITIONS;
314
- let dropPosition = !target || target.type === 'root' ? dropPositions[2] : 'on';
315
- if ((target === null || target === void 0 ? void 0 : target.type) === 'item') {
316
- // If the the keyboard delegate returned the previous key in the collection,
317
- // first try the other positions in the current key. Otherwise (e.g. in a grid layout),
318
- // jump to the same drop position in the new key.
319
- let prevCollectionKey = horizontal && direction === 'rtl' ? localState.state.collection.getKeyAfter(target.key) : localState.state.collection.getKeyBefore(target.key);
320
- if (nextKey == null || nextKey === prevCollectionKey) {
321
- let positionIndex = dropPositions.indexOf(target.dropPosition);
322
- let nextDropPosition = dropPositions[positionIndex - 1];
323
- if (positionIndex > 0 && nextDropPosition !== dropPositions[2]) return {
324
- type: 'item',
325
- key: target.key,
326
- dropPosition: nextDropPosition
327
- };
328
- // If the last drop position was 'before', then 'after' on the previous key is equivalent.
329
- // Switch to 'on' instead.
330
- if (target.dropPosition === dropPositions[0]) dropPosition = 'on';
331
- } else dropPosition = target.dropPosition;
332
- }
333
- if (nextKey == null) {
334
- if (wrap) return {
335
- type: 'root'
336
- };
337
- return null;
338
- }
339
- return {
340
- type: 'item',
341
- key: nextKey,
342
- dropPosition: dropPosition
343
- };
271
+ let getPreviousTarget = (target, wrap = true)=>{
272
+ return getNextTarget(target, wrap, 'up');
344
273
  };
345
274
  let nextValidTarget = (target, types, allowedDropOperations, getNextTarget, wrap = true)=>{
346
275
  let seenRoot = 0;
@@ -434,13 +363,12 @@ function $4b52e4eff84e5217$export$f4e2f423c21f7b04(props, state, ref) {
434
363
  onDropTargetEnter (target) {
435
364
  localState.state.setTarget(target);
436
365
  },
437
- onDropActivate (e) {
438
- var _localState_state_target, _localState_state_target1;
439
- if (((_localState_state_target = localState.state.target) === null || _localState_state_target === void 0 ? void 0 : _localState_state_target.type) === 'item' && ((_localState_state_target1 = localState.state.target) === null || _localState_state_target1 === void 0 ? void 0 : _localState_state_target1.dropPosition) === 'on' && typeof localState.props.onDropActivate === 'function') localState.props.onDropActivate({
366
+ onDropActivate (e, target) {
367
+ if ((target === null || target === void 0 ? void 0 : target.type) === 'item' && (target === null || target === void 0 ? void 0 : target.dropPosition) === 'on' && typeof localState.props.onDropActivate === 'function') localState.props.onDropActivate({
440
368
  type: 'dropactivate',
441
369
  x: e.x,
442
370
  y: e.y,
443
- target: localState.state.target
371
+ target: target
444
372
  });
445
373
  },
446
374
  onDrop (e, target) {
@@ -448,30 +376,31 @@ function $4b52e4eff84e5217$export$f4e2f423c21f7b04(props, state, ref) {
448
376
  if (localState.state.target) onDrop(e, target || localState.state.target);
449
377
  },
450
378
  onKeyDown (e, drag) {
379
+ var _localState_props_onKeyDown, _localState_props;
451
380
  let { keyboardDelegate: keyboardDelegate } = localState.props;
452
381
  let types = (0, $7252cd45fc48c07c$export$e1d41611756c6326)(drag.items);
453
382
  switch(e.key){
454
383
  case 'ArrowDown':
455
384
  if (keyboardDelegate.getKeyBelow) {
456
- let target = nextValidTarget(localState.state.target, types, drag.allowedDropOperations, getNextTarget);
385
+ let target = nextValidTarget(localState.state.target, types, drag.allowedDropOperations, (target, wrap)=>getNextTarget(target, wrap, 'down'));
457
386
  localState.state.setTarget(target);
458
387
  }
459
388
  break;
460
389
  case 'ArrowUp':
461
390
  if (keyboardDelegate.getKeyAbove) {
462
- let target = nextValidTarget(localState.state.target, types, drag.allowedDropOperations, getPreviousTarget);
391
+ let target = nextValidTarget(localState.state.target, types, drag.allowedDropOperations, (target, wrap)=>getNextTarget(target, wrap, 'up'));
463
392
  localState.state.setTarget(target);
464
393
  }
465
394
  break;
466
395
  case 'ArrowLeft':
467
396
  if (keyboardDelegate.getKeyLeftOf) {
468
- let target = nextValidTarget(localState.state.target, types, drag.allowedDropOperations, (target, wrap)=>getPreviousTarget(target, wrap, true));
397
+ let target = nextValidTarget(localState.state.target, types, drag.allowedDropOperations, (target, wrap)=>getNextTarget(target, wrap, 'left'));
469
398
  localState.state.setTarget(target);
470
399
  }
471
400
  break;
472
401
  case 'ArrowRight':
473
402
  if (keyboardDelegate.getKeyRightOf) {
474
- let target = nextValidTarget(localState.state.target, types, drag.allowedDropOperations, (target, wrap)=>getNextTarget(target, wrap, true));
403
+ let target = nextValidTarget(localState.state.target, types, drag.allowedDropOperations, (target, wrap)=>getNextTarget(target, wrap, 'right'));
475
404
  localState.state.setTarget(target);
476
405
  }
477
406
  break;
@@ -573,6 +502,7 @@ function $4b52e4eff84e5217$export$f4e2f423c21f7b04(props, state, ref) {
573
502
  break;
574
503
  }
575
504
  }
505
+ (_localState_props_onKeyDown = (_localState_props = localState.props).onKeyDown) === null || _localState_props_onKeyDown === void 0 ? void 0 : _localState_props_onKeyDown.call(_localState_props, e);
576
506
  }
577
507
  });
578
508
  }, [
@@ -1,5 +1,6 @@
1
1
  import {clearGlobalDnDState as $7252cd45fc48c07c$export$70936501603e6c57, DIRECTORY_DRAG_TYPE as $7252cd45fc48c07c$export$990fced5dfac2637, droppableCollectionMap as $7252cd45fc48c07c$export$dfdf5deeaf27473f, getTypes as $7252cd45fc48c07c$export$e1d41611756c6326, globalDndState as $7252cd45fc48c07c$export$6ca6700462636d0b, isInternalDropOperation as $7252cd45fc48c07c$export$78bf638634500fa5, setDropCollectionRef as $7252cd45fc48c07c$export$dac8db29d42db9a1} from "./utils.module.js";
2
2
  import {registerDropTarget as $67560de7c78cb232$export$c28d9fb4a54e471a} from "./DragManager.module.js";
3
+ import {navigate as $e154566cef11553b$export$ff7962acd6052c28} from "./DropTargetKeyboardNavigation.module.js";
3
4
  import {useAutoScroll as $80d9daea3067eff3$export$6323452ca4533ed8} from "./useAutoScroll.module.js";
4
5
  import {useDrop as $5c06e4929e123553$export$ccdee5eaf73cf661} from "./useDrop.module.js";
5
6
  import {useRef as $4ZR0C$useRef, useCallback as $4ZR0C$useCallback, useEffect as $4ZR0C$useEffect} from "react";
@@ -25,16 +26,7 @@ import {useLocale as $4ZR0C$useLocale} from "@react-aria/i18n";
25
26
 
26
27
 
27
28
 
28
- const $4b52e4eff84e5217$var$DROP_POSITIONS = [
29
- 'before',
30
- 'on',
31
- 'after'
32
- ];
33
- const $4b52e4eff84e5217$var$DROP_POSITIONS_RTL = [
34
- 'after',
35
- 'on',
36
- 'before'
37
- ];
29
+
38
30
  function $4b52e4eff84e5217$export$f4e2f423c21f7b04(props, state, ref) {
39
31
  let localState = (0, $4ZR0C$useRef)({
40
32
  props: props,
@@ -45,7 +37,7 @@ function $4b52e4eff84e5217$export$f4e2f423c21f7b04(props, state, ref) {
45
37
  localState.props = props;
46
38
  localState.state = state;
47
39
  let defaultOnDrop = (0, $4ZR0C$useCallback)(async (e)=>{
48
- let { onInsert: onInsert, onRootDrop: onRootDrop, onItemDrop: onItemDrop, onReorder: onReorder, acceptedDragTypes: acceptedDragTypes = 'all', shouldAcceptItemDrop: shouldAcceptItemDrop } = localState.props;
40
+ let { onInsert: onInsert, onRootDrop: onRootDrop, onItemDrop: onItemDrop, onReorder: onReorder, onMove: onMove, acceptedDragTypes: acceptedDragTypes = 'all', shouldAcceptItemDrop: shouldAcceptItemDrop } = localState.props;
49
41
  let { draggingKeys: draggingKeys } = (0, $7252cd45fc48c07c$export$6ca6700462636d0b);
50
42
  let isInternal = (0, $7252cd45fc48c07c$export$78bf638634500fa5)(ref);
51
43
  let { target: target, dropOperation: dropOperation, items: items } = e;
@@ -78,6 +70,11 @@ function $4b52e4eff84e5217$export$f4e2f423c21f7b04(props, state, ref) {
78
70
  isInternal: isInternal,
79
71
  target: target
80
72
  });
73
+ if (onMove && isInternal) await onMove({
74
+ keys: draggingKeys,
75
+ dropOperation: dropOperation,
76
+ target: target
77
+ });
81
78
  if (target.dropPosition !== 'on') {
82
79
  if (!isInternal && onInsert) await onInsert({
83
80
  items: filteredItems,
@@ -158,8 +155,8 @@ function $4b52e4eff84e5217$export$f4e2f423c21f7b04(props, state, ref) {
158
155
  autoScroll.stop();
159
156
  },
160
157
  onDropActivate (e) {
161
- var _state_target, _state_target1;
162
- if (((_state_target = state.target) === null || _state_target === void 0 ? void 0 : _state_target.type) === 'item' && ((_state_target1 = state.target) === null || _state_target1 === void 0 ? void 0 : _state_target1.dropPosition) === 'on' && typeof props.onDropActivate === 'function') props.onDropActivate({
158
+ var _state_target;
159
+ if (((_state_target = state.target) === null || _state_target === void 0 ? void 0 : _state_target.type) === 'item' && typeof props.onDropActivate === 'function') props.onDropActivate({
163
160
  type: 'dropactivate',
164
161
  x: e.x,
165
162
  y: e.y,
@@ -193,11 +190,16 @@ function $4b52e4eff84e5217$export$f4e2f423c21f7b04(props, state, ref) {
193
190
  // is some indication that items were added.
194
191
  if (state.selectionManager.focusedKey === prevFocusedKey) {
195
192
  let first = newKeys.keys().next().value;
196
- let item = state.collection.getItem(first);
197
- // If this is a cell, focus the parent row.
198
- if ((item === null || item === void 0 ? void 0 : item.type) === 'cell') first = item.parentKey;
199
- state.selectionManager.setFocusedKey(first);
200
- if (state.selectionManager.selectionMode === 'none') (0, $4ZR0C$setInteractionModality)('keyboard');
193
+ if (first != null) {
194
+ let item = state.collection.getItem(first);
195
+ // If this is a cell, focus the parent row.
196
+ // eslint-disable-next-line max-depth
197
+ if ((item === null || item === void 0 ? void 0 : item.type) === 'cell') first = item.parentKey;
198
+ // eslint-disable-next-line max-depth
199
+ if (first != null) state.selectionManager.setFocusedKey(first);
200
+ // eslint-disable-next-line max-depth
201
+ if (state.selectionManager.selectionMode === 'none') (0, $4ZR0C$setInteractionModality)('keyboard');
202
+ }
201
203
  }
202
204
  } else if (prevFocusedKey != null && state.selectionManager.focusedKey === prevFocusedKey && isInternal && target.type === 'item' && target.dropPosition !== 'on' && draggingKeys.has((_state_collection_getItem = state.collection.getItem(prevFocusedKey)) === null || _state_collection_getItem === void 0 ? void 0 : _state_collection_getItem.parentKey)) {
203
205
  var _state_collection_getItem1;
@@ -263,84 +265,11 @@ function $4b52e4eff84e5217$export$f4e2f423c21f7b04(props, state, ref) {
263
265
  let { direction: direction } = (0, $4ZR0C$useLocale)();
264
266
  (0, $4ZR0C$useEffect)(()=>{
265
267
  if (!ref.current) return;
266
- let getNextTarget = (target, wrap = true, horizontal = false)=>{
267
- var _keyboardDelegate_getKeyRightOf, _keyboardDelegate_getKeyBelow, _keyboardDelegate_getLastKey, _keyboardDelegate_getFirstKey;
268
- if (!target) return {
269
- type: 'root'
270
- };
271
- let { keyboardDelegate: keyboardDelegate } = localState.props;
272
- let nextKey;
273
- if ((target === null || target === void 0 ? void 0 : target.type) === 'item') nextKey = horizontal ? (_keyboardDelegate_getKeyRightOf = keyboardDelegate.getKeyRightOf) === null || _keyboardDelegate_getKeyRightOf === void 0 ? void 0 : _keyboardDelegate_getKeyRightOf.call(keyboardDelegate, target.key) : (_keyboardDelegate_getKeyBelow = keyboardDelegate.getKeyBelow) === null || _keyboardDelegate_getKeyBelow === void 0 ? void 0 : _keyboardDelegate_getKeyBelow.call(keyboardDelegate, target.key);
274
- else nextKey = horizontal && direction === 'rtl' ? (_keyboardDelegate_getLastKey = keyboardDelegate.getLastKey) === null || _keyboardDelegate_getLastKey === void 0 ? void 0 : _keyboardDelegate_getLastKey.call(keyboardDelegate) : (_keyboardDelegate_getFirstKey = keyboardDelegate.getFirstKey) === null || _keyboardDelegate_getFirstKey === void 0 ? void 0 : _keyboardDelegate_getFirstKey.call(keyboardDelegate);
275
- let dropPositions = horizontal && direction === 'rtl' ? $4b52e4eff84e5217$var$DROP_POSITIONS_RTL : $4b52e4eff84e5217$var$DROP_POSITIONS;
276
- let dropPosition = dropPositions[0];
277
- if (target.type === 'item') {
278
- // If the the keyboard delegate returned the next key in the collection,
279
- // first try the other positions in the current key. Otherwise (e.g. in a grid layout),
280
- // jump to the same drop position in the new key.
281
- let nextCollectionKey = horizontal && direction === 'rtl' ? localState.state.collection.getKeyBefore(target.key) : localState.state.collection.getKeyAfter(target.key);
282
- if (nextKey == null || nextKey === nextCollectionKey) {
283
- let positionIndex = dropPositions.indexOf(target.dropPosition);
284
- let nextDropPosition = dropPositions[positionIndex + 1];
285
- if (positionIndex < dropPositions.length - 1 && !(nextDropPosition === dropPositions[2] && nextKey != null)) return {
286
- type: 'item',
287
- key: target.key,
288
- dropPosition: nextDropPosition
289
- };
290
- // If the last drop position was 'after', then 'before' on the next key is equivalent.
291
- // Switch to 'on' instead.
292
- if (target.dropPosition === dropPositions[2]) dropPosition = 'on';
293
- } else dropPosition = target.dropPosition;
294
- }
295
- if (nextKey == null) {
296
- if (wrap) return {
297
- type: 'root'
298
- };
299
- return null;
300
- }
301
- return {
302
- type: 'item',
303
- key: nextKey,
304
- dropPosition: dropPosition
305
- };
268
+ let getNextTarget = (target, wrap = true, key = 'down')=>{
269
+ return (0, $e154566cef11553b$export$ff7962acd6052c28)(localState.props.keyboardDelegate, localState.state.collection, target, key, direction === 'rtl', wrap);
306
270
  };
307
- let getPreviousTarget = (target, wrap = true, horizontal = false)=>{
308
- var _keyboardDelegate_getKeyLeftOf, _keyboardDelegate_getKeyAbove, _keyboardDelegate_getFirstKey, _keyboardDelegate_getLastKey;
309
- let { keyboardDelegate: keyboardDelegate } = localState.props;
310
- let nextKey;
311
- if ((target === null || target === void 0 ? void 0 : target.type) === 'item') nextKey = horizontal ? (_keyboardDelegate_getKeyLeftOf = keyboardDelegate.getKeyLeftOf) === null || _keyboardDelegate_getKeyLeftOf === void 0 ? void 0 : _keyboardDelegate_getKeyLeftOf.call(keyboardDelegate, target.key) : (_keyboardDelegate_getKeyAbove = keyboardDelegate.getKeyAbove) === null || _keyboardDelegate_getKeyAbove === void 0 ? void 0 : _keyboardDelegate_getKeyAbove.call(keyboardDelegate, target.key);
312
- else nextKey = horizontal && direction === 'rtl' ? (_keyboardDelegate_getFirstKey = keyboardDelegate.getFirstKey) === null || _keyboardDelegate_getFirstKey === void 0 ? void 0 : _keyboardDelegate_getFirstKey.call(keyboardDelegate) : (_keyboardDelegate_getLastKey = keyboardDelegate.getLastKey) === null || _keyboardDelegate_getLastKey === void 0 ? void 0 : _keyboardDelegate_getLastKey.call(keyboardDelegate);
313
- let dropPositions = horizontal && direction === 'rtl' ? $4b52e4eff84e5217$var$DROP_POSITIONS_RTL : $4b52e4eff84e5217$var$DROP_POSITIONS;
314
- let dropPosition = !target || target.type === 'root' ? dropPositions[2] : 'on';
315
- if ((target === null || target === void 0 ? void 0 : target.type) === 'item') {
316
- // If the the keyboard delegate returned the previous key in the collection,
317
- // first try the other positions in the current key. Otherwise (e.g. in a grid layout),
318
- // jump to the same drop position in the new key.
319
- let prevCollectionKey = horizontal && direction === 'rtl' ? localState.state.collection.getKeyAfter(target.key) : localState.state.collection.getKeyBefore(target.key);
320
- if (nextKey == null || nextKey === prevCollectionKey) {
321
- let positionIndex = dropPositions.indexOf(target.dropPosition);
322
- let nextDropPosition = dropPositions[positionIndex - 1];
323
- if (positionIndex > 0 && nextDropPosition !== dropPositions[2]) return {
324
- type: 'item',
325
- key: target.key,
326
- dropPosition: nextDropPosition
327
- };
328
- // If the last drop position was 'before', then 'after' on the previous key is equivalent.
329
- // Switch to 'on' instead.
330
- if (target.dropPosition === dropPositions[0]) dropPosition = 'on';
331
- } else dropPosition = target.dropPosition;
332
- }
333
- if (nextKey == null) {
334
- if (wrap) return {
335
- type: 'root'
336
- };
337
- return null;
338
- }
339
- return {
340
- type: 'item',
341
- key: nextKey,
342
- dropPosition: dropPosition
343
- };
271
+ let getPreviousTarget = (target, wrap = true)=>{
272
+ return getNextTarget(target, wrap, 'up');
344
273
  };
345
274
  let nextValidTarget = (target, types, allowedDropOperations, getNextTarget, wrap = true)=>{
346
275
  let seenRoot = 0;
@@ -434,13 +363,12 @@ function $4b52e4eff84e5217$export$f4e2f423c21f7b04(props, state, ref) {
434
363
  onDropTargetEnter (target) {
435
364
  localState.state.setTarget(target);
436
365
  },
437
- onDropActivate (e) {
438
- var _localState_state_target, _localState_state_target1;
439
- if (((_localState_state_target = localState.state.target) === null || _localState_state_target === void 0 ? void 0 : _localState_state_target.type) === 'item' && ((_localState_state_target1 = localState.state.target) === null || _localState_state_target1 === void 0 ? void 0 : _localState_state_target1.dropPosition) === 'on' && typeof localState.props.onDropActivate === 'function') localState.props.onDropActivate({
366
+ onDropActivate (e, target) {
367
+ if ((target === null || target === void 0 ? void 0 : target.type) === 'item' && (target === null || target === void 0 ? void 0 : target.dropPosition) === 'on' && typeof localState.props.onDropActivate === 'function') localState.props.onDropActivate({
440
368
  type: 'dropactivate',
441
369
  x: e.x,
442
370
  y: e.y,
443
- target: localState.state.target
371
+ target: target
444
372
  });
445
373
  },
446
374
  onDrop (e, target) {
@@ -448,30 +376,31 @@ function $4b52e4eff84e5217$export$f4e2f423c21f7b04(props, state, ref) {
448
376
  if (localState.state.target) onDrop(e, target || localState.state.target);
449
377
  },
450
378
  onKeyDown (e, drag) {
379
+ var _localState_props_onKeyDown, _localState_props;
451
380
  let { keyboardDelegate: keyboardDelegate } = localState.props;
452
381
  let types = (0, $7252cd45fc48c07c$export$e1d41611756c6326)(drag.items);
453
382
  switch(e.key){
454
383
  case 'ArrowDown':
455
384
  if (keyboardDelegate.getKeyBelow) {
456
- let target = nextValidTarget(localState.state.target, types, drag.allowedDropOperations, getNextTarget);
385
+ let target = nextValidTarget(localState.state.target, types, drag.allowedDropOperations, (target, wrap)=>getNextTarget(target, wrap, 'down'));
457
386
  localState.state.setTarget(target);
458
387
  }
459
388
  break;
460
389
  case 'ArrowUp':
461
390
  if (keyboardDelegate.getKeyAbove) {
462
- let target = nextValidTarget(localState.state.target, types, drag.allowedDropOperations, getPreviousTarget);
391
+ let target = nextValidTarget(localState.state.target, types, drag.allowedDropOperations, (target, wrap)=>getNextTarget(target, wrap, 'up'));
463
392
  localState.state.setTarget(target);
464
393
  }
465
394
  break;
466
395
  case 'ArrowLeft':
467
396
  if (keyboardDelegate.getKeyLeftOf) {
468
- let target = nextValidTarget(localState.state.target, types, drag.allowedDropOperations, (target, wrap)=>getPreviousTarget(target, wrap, true));
397
+ let target = nextValidTarget(localState.state.target, types, drag.allowedDropOperations, (target, wrap)=>getNextTarget(target, wrap, 'left'));
469
398
  localState.state.setTarget(target);
470
399
  }
471
400
  break;
472
401
  case 'ArrowRight':
473
402
  if (keyboardDelegate.getKeyRightOf) {
474
- let target = nextValidTarget(localState.state.target, types, drag.allowedDropOperations, (target, wrap)=>getNextTarget(target, wrap, true));
403
+ let target = nextValidTarget(localState.state.target, types, drag.allowedDropOperations, (target, wrap)=>getNextTarget(target, wrap, 'right'));
475
404
  localState.state.setTarget(target);
476
405
  }
477
406
  break;
@@ -573,6 +502,7 @@ function $4b52e4eff84e5217$export$f4e2f423c21f7b04(props, state, ref) {
573
502
  break;
574
503
  }
575
504
  }
505
+ (_localState_props_onKeyDown = (_localState_props = localState.props).onKeyDown) === null || _localState_props_onKeyDown === void 0 ? void 0 : _localState_props_onKeyDown.call(_localState_props, e);
576
506
  }
577
507
  });
578
508
  }, [