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qC;oBACrC,IAAI,CAAC,MACH;oBAEF,6EAA6E;oBAC7E,qCAAqC;oBACrC,IAAI,KAAK,IAAI,KAAK,QAAQ;wBACxB,UAAU,UAAU,UAAU,CAAC,WAAW,CAAC;wBAC3C;oBACF;oBAEA,wDAAwD;oBACxD,qCAAqC;oBACrC,IAAI,AAAC,CAAA,KAAK,KAAK,IAAI,CAAA,KAAM,aACvB;oBAGF,oBAAoB;oBACpB,UAAU,UAAU,UAAU,CAAC,WAAW,CAAC;gBAC7C;YACF;YAEA,kEAAkE;YAClE,gBAAgB,WAAW,qBAAqB;QAClD;IACF;IAEA,OAAO,CAAA,GAAA,cAAM,EAAE;QACb,OAAO,IAAI,IAAI;YAAC;YAAY;SAAc,CAAC,MAAM,CAAC,CAAA,IAAK,KAAK;IAC9D,GAAG;QAAC;QAAY;KAAc;AAChC","sources":["packages/react-aria-components/src/DragAndDrop.tsx"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nimport type {DropIndicatorProps as AriaDropIndicatorProps} from 'react-aria/useDroppableCollection';\n\nimport type {ClassNameOrFunction, RenderProps} from './utils';\nimport type {DragAndDropHooks} from './useDragAndDrop';\nimport type {DraggableCollectionState} from 'react-stately/useDraggableCollectionState';\nimport type {DroppableCollectionState} from 'react-stately/useDroppableCollectionState';\nimport type {ItemDropTarget, Key} from '@react-types/shared';\nimport type {MultipleSelectionManager} from 'react-stately/useMultipleSelectionState';\nimport React, {createContext, ForwardedRef, forwardRef, JSX, ReactNode, useCallback, useContext, useMemo} from 'react';\n\nexport interface DragAndDropContextValue {\n  dragAndDropHooks?: DragAndDropHooks,\n  dragState?: DraggableCollectionState,\n  dropState?: DroppableCollectionState\n}\n\nexport const DragAndDropContext = createContext<DragAndDropContextValue>({});\nexport const DropIndicatorContext = createContext<DropIndicatorContextValue | null>(null);\n\nexport interface DropIndicatorRenderProps {\n  /**\n   * Whether the drop indicator is currently the active drop target.\n   * @selector [data-drop-target]\n   */\n  isDropTarget: boolean\n}\n\nexport interface DropIndicatorProps extends Omit<AriaDropIndicatorProps, 'activateButtonRef'>, RenderProps<DropIndicatorRenderProps> {\n  /**\n   * The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. A function may be provided to compute the class based on component state.\n   * @default 'react-aria-DropIndicator'\n   */\n  className?: ClassNameOrFunction<DropIndicatorRenderProps>\n}\ninterface DropIndicatorContextValue {\n  render: (props: DropIndicatorProps, ref: ForwardedRef<HTMLElement>) => ReactNode\n}\n\n/**\n * A DropIndicator is rendered between items in a collection to indicate where dropped data will be inserted.\n */\nexport const DropIndicator = forwardRef(function DropIndicator(props: DropIndicatorProps, ref: ForwardedRef<HTMLElement>): JSX.Element {\n  let {render} = useContext(DropIndicatorContext)!;\n  return <>{render(props, ref)}</>;\n});\n\ntype RenderDropIndicatorRetValue = ((target: ItemDropTarget) => ReactNode | undefined) | undefined\n\nexport function useRenderDropIndicator(dragAndDropHooks?: DragAndDropHooks, dropState?: DroppableCollectionState): RenderDropIndicatorRetValue {\n  let renderDropIndicator = dragAndDropHooks?.renderDropIndicator;\n  let isVirtualDragging = dragAndDropHooks?.isVirtualDragging?.();\n  let fn = useCallback((target: ItemDropTarget) => {\n    // Only show drop indicators when virtual dragging or this is the current drop target.\n    if (isVirtualDragging || dropState?.isDropTarget(target)) {\n      return renderDropIndicator ? renderDropIndicator(target) : <DropIndicator target={target} />;\n    }\n    // We invalidate whenever the target changes.\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [dropState?.target, isVirtualDragging, renderDropIndicator]);\n  return dragAndDropHooks?.useDropIndicator ? fn : undefined;\n}\n\nexport function useDndPersistedKeys(selectionManager: MultipleSelectionManager, dragAndDropHooks?: DragAndDropHooks, dropState?: DroppableCollectionState): Set<Key> {\n  // Persist the focused key and the drop target key.\n  let focusedKey = selectionManager.focusedKey;\n  let dropTargetKey: Key | null | undefined = null;\n  if (dragAndDropHooks?.isVirtualDragging?.() && dropState?.target?.type === 'item') {\n    dropTargetKey = dropState.target.key;\n    if (dropState.target.dropPosition === 'after') {\n      // Normalize to the \"before\" drop position since we only render those to the DOM.\n      let nextKey = dropState.collection.getKeyAfter(dropTargetKey);\n      let lastDescendantKey: Key | null = null;\n      if (nextKey != null) {\n        let targetLevel = dropState.collection.getItem(dropTargetKey)?.level ?? 0;\n        // Skip over any rows that are descendants of the target (\"after\" position should be after all children)\n        while (nextKey) {\n          let node = dropState.collection.getItem(nextKey);\n          // eslint-disable-next-line max-depth\n          if (!node) {\n            break;\n          }\n          // Skip over non-item nodes (e.g., loaders) since they can't be drop targets.\n          // eslint-disable-next-line max-depth\n          if (node.type !== 'item') {\n            nextKey = dropState.collection.getKeyAfter(nextKey);\n            continue;\n          }\n\n          // Stop once we find an item at the same level or higher\n          // eslint-disable-next-line max-depth\n          if ((node.level ?? 0) <= targetLevel) {\n            break;\n          }\n          \n          lastDescendantKey = nextKey;\n          nextKey = dropState.collection.getKeyAfter(nextKey);\n        }\n      }\n\n      // If nextKey is null (end of collection), use the last descendant\n      dropTargetKey = nextKey ?? lastDescendantKey ?? dropTargetKey;\n    }\n  }\n\n  return useMemo(() => {\n    return new Set([focusedKey, dropTargetKey].filter(k => k != null));\n  }, [focusedKey, dropTargetKey]);\n}\n"],"names":[],"version":3,"file":"DragAndDrop.mjs.map"}