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sBAAsB,mBAAmB,IAAI,KAAK,OAAQ;QAC/D,oBAAoB,WAAW,mBAAmB,GAAG;QACrD,qBAAqB,qBAAqB,OAAO,WAAW,OAAO,CAAC,qBAAqB;IAC3F;IACA,OAAO;AACT","sources":["packages/react-aria/src/dnd/DropTargetKeyboardNavigation.ts"],"sourcesContent":["import {Collection, DropTarget, Key, KeyboardDelegate, Node} from '@react-types/shared';\n\nexport function navigate(\n  keyboardDelegate: KeyboardDelegate,\n  collection: Collection<Node<unknown>>,\n  target: DropTarget | null | undefined,\n  direction: 'left' | 'right' | 'up' | 'down',\n  rtl = false,\n  wrap = false\n): DropTarget | null {\n  switch (direction) {\n    case 'left':\n      return rtl\n        ? nextDropTarget(keyboardDelegate, collection, target, wrap, 'left')\n        : previousDropTarget(keyboardDelegate, collection, target, wrap, 'left');\n    case 'right':\n      return rtl\n        ? previousDropTarget(keyboardDelegate, collection, target, wrap, 'right')\n        : nextDropTarget(keyboardDelegate, collection, target, wrap, 'right');\n    case 'up':\n      return previousDropTarget(keyboardDelegate, collection, target, wrap);\n    case 'down':\n      return nextDropTarget(keyboardDelegate, collection, target, wrap);\n  }\n}\n\nfunction nextDropTarget(\n  keyboardDelegate: KeyboardDelegate,\n  collection: Collection<Node<unknown>>,\n  target: DropTarget | null | undefined,\n  wrap = false,\n  horizontal: 'left' | 'right' | null = null\n): DropTarget | null {\n  if (!target) {\n    return {\n      type: 'root'\n    };\n  }\n\n  if (target.type === 'root') {\n    let nextKey = keyboardDelegate.getFirstKey?.() ?? null;\n    if (nextKey != null) {\n      return {\n        type: 'item',\n        key: nextKey,\n        dropPosition: 'before'\n      };\n    }\n\n    return null;\n  }\n\n  if (target.type === 'item') {\n    let nextKey: Key | null | undefined = null;\n    if (horizontal) {\n      nextKey = horizontal === 'right' ? keyboardDelegate.getKeyRightOf?.(target.key) : keyboardDelegate.getKeyLeftOf?.(target.key);\n    } else {\n      nextKey = keyboardDelegate.getKeyBelow?.(target.key);\n    }\n    let nextCollectionKey = getNextItem(collection, target.key, key => collection.getKeyAfter(key));\n\n    // If the keyboard delegate did not move to the next key in the collection,\n    // jump to that key with the same drop position. Otherwise, try the other\n    // drop positions on the current key first.\n    if (nextKey != null && nextKey !== nextCollectionKey) {\n      return {\n        type: 'item',\n        key: nextKey,\n        dropPosition: target.dropPosition\n      };\n    }\n\n    switch (target.dropPosition) {\n      case 'before': {\n        return {\n          type: 'item',\n          key: target.key,\n          dropPosition: 'on'\n        };\n      }\n      case 'on': {\n        // If there are nested items, traverse to them prior to the \"after\" position of this target.\n        // If the next key is on the same level, then its \"before\" position is equivalent to this item's \"after\" position.\n        let targetNode = collection.getItem(target.key);\n        let nextNode = nextKey != null ? collection.getItem(nextKey) : null;\n        if (targetNode && nextNode && nextNode.level >= targetNode.level) {\n          return {\n            type: 'item',\n            key: nextNode.key,\n            dropPosition: 'before'\n          };\n        }\n\n        return {\n          type: 'item',\n          key: target.key,\n          dropPosition: 'after'\n        };\n      }\n      case 'after': {\n        // If this is the last sibling in a level, traverse to the parent.\n        let targetNode = collection.getItem(target.key);\n        let nextItemInSameLevel = targetNode?.nextKey != null ? collection.getItem(targetNode.nextKey) : null;\n        while (nextItemInSameLevel != null && nextItemInSameLevel.type !== 'item') {\n          nextItemInSameLevel = nextItemInSameLevel.nextKey != null ? collection.getItem(nextItemInSameLevel.nextKey) : null;\n        }\n\n        if (targetNode && nextItemInSameLevel == null && targetNode.parentKey != null) {\n          // If the parent item has an item after it, use the \"before\" position.\n          let parentNode = collection.getItem(targetNode.parentKey);\n          const nextNode = parentNode?.nextKey != null ? collection.getItem(parentNode.nextKey) : null;\n          if (nextNode?.type === 'item') {\n            return {\n              type: 'item',\n              key: nextNode.key,\n              dropPosition: 'before'\n            };\n          }\n\n          if (parentNode?.type === 'item') {\n            return {\n              type: 'item',\n              key: parentNode.key,\n              dropPosition: 'after'\n            };\n          }\n        }\n\n        if (nextItemInSameLevel) {\n          return {\n            type: 'item',\n            key: nextItemInSameLevel.key,\n            dropPosition: 'on'\n          };\n        }\n      }\n    }\n  }\n\n  if (wrap) {\n    return {\n      type: 'root'\n    };\n  }\n\n  return null;\n}\n\nfunction previousDropTarget(\n  keyboardDelegate: KeyboardDelegate,\n  collection: Collection<Node<unknown>>,\n  target: DropTarget | null | undefined,\n  wrap = false,\n  horizontal: 'left' | 'right' | null = null\n): DropTarget | null {\n  // Start after the last root-level item.\n  if (!target || (wrap && target.type === 'root')) {\n    // Keyboard delegate gets the deepest item but we want the shallowest.\n    let prevKey: Key | null = null;\n    let lastKey = keyboardDelegate.getLastKey?.();\n    while (lastKey != null) {\n      let node = collection.getItem(lastKey);\n      if (node?.type !== 'item') {\n        break;\n      }\n      prevKey = lastKey;\n      lastKey = node?.parentKey;\n    }\n\n    if (prevKey != null) {\n      return {\n        type: 'item',\n        key: prevKey,\n        dropPosition: 'after'\n      };\n    }\n\n    return null;\n  }\n\n  if (target.type === 'item') {\n    let prevKey: Key | null | undefined = null;\n    if (horizontal) {\n      prevKey = horizontal === 'left' ? keyboardDelegate.getKeyLeftOf?.(target.key) : keyboardDelegate.getKeyRightOf?.(target.key);\n    } else {\n      prevKey = keyboardDelegate.getKeyAbove?.(target.key);\n    }\n    let prevCollectionKey = getNextItem(collection, target.key, key => collection.getKeyBefore(key));\n\n    // If the keyboard delegate did not move to the next key in the collection,\n    // jump to that key with the same drop position. Otherwise, try the other\n    // drop positions on the current key first.\n    if (prevKey != null && prevKey !== prevCollectionKey) {\n      return {\n        type: 'item',\n        key: prevKey,\n        dropPosition: target.dropPosition\n      };\n    }\n\n    switch (target.dropPosition) {\n      case 'before': {\n        // Move after the last child of the previous item.\n        let targetNode = collection.getItem(target.key);\n        if (targetNode && targetNode.prevKey != null) {\n          let lastChild = getLastChild(collection, targetNode.prevKey);\n          if (lastChild) {\n            return lastChild;\n          }\n        }\n\n        if (prevKey != null) {\n          return {\n            type: 'item',\n            key: prevKey,\n            dropPosition: 'on'\n          };\n        }\n\n        return {\n          type: 'root'\n        };\n      }\n      case 'on': {\n        return {\n          type: 'item',\n          key: target.key,\n          dropPosition: 'before'\n        };\n      }\n      case 'after': {\n        // Move after the last child of this item.\n        let lastChild = getLastChild(collection, target.key);\n        if (lastChild) {\n          return lastChild;\n        }\n\n        return {\n          type: 'item',\n          key: target.key,\n          dropPosition: 'on'\n        };\n      }\n    }\n  }\n\n  if (target.type !== 'root') {\n    return {\n      type: 'root'\n    };\n  }\n\n  return null;\n}\n\nfunction getLastChild(collection: Collection<Node<unknown>>, key: Key): DropTarget | null {\n  // getChildNodes still returns child tree items even when the item is collapsed.\n  // Checking if the next item has a greater level is a silly way to determine if the item is expanded.\n  let targetNode = collection.getItem(key);\n  let nextKey = getNextItem(collection, key, key => collection.getKeyAfter(key));\n  let nextNode = nextKey != null ? collection.getItem(nextKey) : null;\n  if (targetNode && nextNode && nextNode.level > targetNode.level) {\n    let lastChild: Node<unknown> | null = null;\n    if ('lastChildKey' in targetNode) {\n      lastChild = targetNode.lastChildKey != null ? collection.getItem(targetNode.lastChildKey) : null;\n      while (lastChild && lastChild.type !== 'item' && lastChild.prevKey != null) {\n        lastChild = collection.getItem(lastChild.prevKey)!;\n      }\n    } else {\n      lastChild = Array.from(targetNode.childNodes).findLast(item => item.type === 'item') || null;\n    }\n\n    if (lastChild) {\n      return {\n        type: 'item',\n        key: lastChild.key,\n        dropPosition: 'after'\n      };\n    }\n  }\n\n  return null;\n}\n\n// Find the next or previous item in a collection, skipping over other types of nodes (e.g. content).\nfunction getNextItem(collection: Collection<Node<unknown>>, key: Key, getNextKey: (key: Key) => Key | null): Key | null {\n  let nextCollectionKey = getNextKey(key);\n  let nextCollectionNode = nextCollectionKey != null ? collection.getItem(nextCollectionKey) : null;\n  while (nextCollectionNode && nextCollectionNode.type !== 'item') {\n    nextCollectionKey = getNextKey(nextCollectionNode.key);\n    nextCollectionNode = nextCollectionKey != null ? collection.getItem(nextCollectionKey) : null;\n  }\n  return nextCollectionKey;\n}\n"],"names":[],"version":3,"file":"DropTargetKeyboardNavigation.mjs.map"}