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,CAAC;oBACxC,qCAAqC;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,oBAAM,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, {\n  createContext,\n  ForwardedRef,\n  forwardRef,\n  JSX,\n  ReactNode,\n  useCallback,\n  useContext,\n  useMemo\n} 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   *\n   * @selector [data-drop-target]\n   */\n  isDropTarget: boolean;\n}\n\nexport interface DropIndicatorProps\n  extends Omit<AriaDropIndicatorProps, 'activateButtonRef'>, RenderProps<DropIndicatorRenderProps> {\n  /**\n   * The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the\n   * element. A function may be provided to compute the class based on component state.\n   *\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\n * inserted.\n */\nexport const DropIndicator = forwardRef(function DropIndicator(\n  props: DropIndicatorProps,\n  ref: ForwardedRef<HTMLElement>\n): 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(\n  dragAndDropHooks?: DragAndDropHooks,\n  dropState?: DroppableCollectionState\n): RenderDropIndicatorRetValue {\n  let renderDropIndicator = dragAndDropHooks?.renderDropIndicator;\n  let isVirtualDragging = dragAndDropHooks?.isVirtualDragging?.();\n  let fn = useCallback(\n    (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 ? (\n          renderDropIndicator(target)\n        ) : (\n          <DropIndicator target={target} />\n        );\n      }\n    },\n    // We invalidate whenever the target changes.\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n    [dropState?.target, isVirtualDragging, renderDropIndicator]\n  );\n  return dragAndDropHooks?.useDropIndicator ? fn : undefined;\n}\n\nexport function useDndPersistedKeys(\n  selectionManager: MultipleSelectionManager,\n  dragAndDropHooks?: DragAndDropHooks,\n  dropState?: DroppableCollectionState\n): 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 != null) {\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.cjs.map"}