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. 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 {\n  CollectionBase,\n  DropTargetDelegate,\n  GlobalDOMAttributes,\n  ItemDropTarget,\n  Key,\n  LayoutDelegate,\n  RefObject\n} from '@react-types/shared';\nimport {createBranchComponent} from 'react-aria/CollectionBuilder';\nimport {\n  Collection as ICollection,\n  Node,\n  SelectionBehavior,\n  SelectionMode,\n  SectionProps as SharedSectionProps\n} from '@react-types/shared';\n\nimport React, {\n  cloneElement,\n  createContext,\n  ForwardedRef,\n  HTMLAttributes,\n  isValidElement,\n  JSX,\n  ReactElement,\n  ReactNode,\n  useContext,\n  useMemo\n} from 'react';\n\nimport {StyleProps} from './utils';\nimport {useCachedChildren} from 'react-aria/private/collections/useCachedChildren';\n\nexport interface CollectionProps<T> extends Omit<CollectionBase<T>, 'children'> {\n  /** The contents of the collection. */\n  children?: ReactNode | ((item: T) => ReactNode);\n  /** Values that should invalidate the item cache when using dynamic collections. */\n  dependencies?: ReadonlyArray<any>;\n}\n\nexport interface ItemRenderProps {\n  /**\n   * Whether the item is currently hovered with a mouse.\n   *\n   * @selector [data-hovered]\n   */\n  isHovered: boolean;\n  /**\n   * Whether the item is currently in a pressed state.\n   *\n   * @selector [data-pressed]\n   */\n  isPressed: boolean;\n  /**\n   * Whether the item is currently selected.\n   *\n   * @selector [data-selected]\n   */\n  isSelected: boolean;\n  /**\n   * Whether the item is currently focused.\n   *\n   * @selector [data-focused]\n   */\n  isFocused: boolean;\n  /**\n   * Whether the item is currently keyboard focused.\n   *\n   * @selector [data-focus-visible]\n   */\n  isFocusVisible: boolean;\n  /**\n   * Whether the item is non-interactive, i.e. both selection and actions are disabled and the item\n   * may not be focused. Dependent on `disabledKeys` and `disabledBehavior`.\n   *\n   * @selector [data-disabled]\n   */\n  isDisabled: boolean;\n  /**\n   * The type of selection that is allowed in the collection.\n   *\n   * @selector [data-selection-mode=\"single | multiple\"]\n   */\n  selectionMode: SelectionMode;\n  /** The selection behavior for the collection. */\n  selectionBehavior: SelectionBehavior;\n  /**\n   * Whether the item allows dragging.\n   *\n   * @note This property is only available in collection components that support drag and drop.\n   * @selector [data-allows-dragging]\n   */\n  allowsDragging?: boolean;\n  /**\n   * Whether the item is currently being dragged.\n   *\n   * @note This property is only available in collection components that support drag and drop.\n   * @selector [data-dragging]\n   */\n  isDragging?: boolean;\n  /**\n   * Whether the item is currently an active drop target.\n   *\n   * @note This property is only available in collection components that support drag and drop.\n   * @selector [data-drop-target]\n   */\n  isDropTarget?: boolean;\n}\n\nexport interface SectionProps<T>\n  extends\n    Omit<SharedSectionProps<T>, 'children' | 'title'>,\n    StyleProps,\n    GlobalDOMAttributes<HTMLElement> {\n  /** The unique id of the section. */\n  id?: Key;\n  /**\n   * The object value that this section represents. When using dynamic collections, this is set\n   * automatically.\n   */\n  value?: T;\n  /** Static child items or a function to render children. */\n  children?: ReactNode | ((item: T) => ReactElement);\n  /** Values that should invalidate the item cache when using dynamic collections. */\n  dependencies?: ReadonlyArray<any>;\n}\n\ninterface SectionContextValue {\n  name: string;\n  render: (\n    props: SectionProps<any>,\n    ref: ForwardedRef<HTMLElement>,\n    section: Node<any>,\n    className?: string\n  ) => ReactElement;\n}\n\nexport const SectionContext = createContext<SectionContextValue | null>(null);\n\n/** @deprecated */\nexport const Section = /*#__PURE__*/ createBranchComponent(\n  'section',\n  <T extends any>(\n    props: SectionProps<T>,\n    ref: ForwardedRef<HTMLElement>,\n    section: Node<T>\n  ): JSX.Element => {\n    let {name, render} = useContext(SectionContext)!;\n    if (process.env.NODE_ENV !== 'production') {\n      console.warn(`<Section> is deprecated. Please use <${name}> instead.`);\n    }\n    return render(props, ref, section, 'react-aria-Section');\n  }\n);\n\nexport interface CollectionBranchProps {\n  /** The collection of items to render. */\n  collection: ICollection<Node<unknown>>;\n  /** The parent node of the items to render. */\n  parent: Node<unknown>;\n  /** A function that renders a drop indicator between items. */\n  renderDropIndicator?: (target: ItemDropTarget) => ReactNode;\n}\n\nexport interface CollectionRootProps extends HTMLAttributes<HTMLElement> {\n  /** The collection of items to render. */\n  collection: ICollection<Node<unknown>>;\n  /** A set of keys for items that should always be persisted in the DOM. */\n  persistedKeys?: Set<Key> | null;\n  /** A ref to the scroll container for the collection. */\n  scrollRef?: RefObject<HTMLElement | null>;\n  /** A function that renders a drop indicator between items. */\n  renderDropIndicator?: (target: ItemDropTarget) => ReactNode;\n}\n\nexport interface CollectionRenderer {\n  /** Whether this is a virtualized collection. */\n  isVirtualized?: boolean;\n  /** A delegate object that provides layout information for items in the collection. */\n  layoutDelegate?: LayoutDelegate;\n  /** A delegate object that provides drop targets for pointer coordinates within the collection. */\n  dropTargetDelegate?: DropTargetDelegate;\n  /** A component that renders the root collection items. */\n  CollectionRoot: React.ComponentType<CollectionRootProps>;\n  /** A component that renders the child collection items. */\n  CollectionBranch: React.ComponentType<CollectionBranchProps>;\n}\n\nexport const DefaultCollectionRenderer: CollectionRenderer = {\n  CollectionRoot({collection, renderDropIndicator}) {\n    return useCollectionRender(collection, null, renderDropIndicator);\n  },\n  CollectionBranch({collection, parent, renderDropIndicator}) {\n    return useCollectionRender(collection, parent, renderDropIndicator);\n  }\n};\n\nfunction useCollectionRender(\n  collection: ICollection<Node<unknown>>,\n  parent: Node<unknown> | null,\n  renderDropIndicator?: (target: ItemDropTarget) => ReactNode\n) {\n  return useCachedChildren({\n    items: parent ? collection.getChildren!(parent.key) : collection,\n    dependencies: [renderDropIndicator],\n    children(node) {\n      // Return a empty fragment since we don't want to render the content twice\n      // If we don't skip the content node here, we end up rendering them twice in a Tree since we also render the content node in TreeItem\n      if (node.type === 'content') {\n        return <></>;\n      }\n\n      let rendered = node.render!(node);\n      if (!renderDropIndicator || node.type !== 'item') {\n        return rendered;\n      }\n\n      return (\n        <>\n          {renderDropIndicator({type: 'item', key: node.key, dropPosition: 'before'})}\n          {rendered}\n          {renderAfterDropIndicators(collection, node, renderDropIndicator)}\n        </>\n      );\n    }\n  });\n}\n\nexport function renderAfterDropIndicators(\n  collection: ICollection<Node<unknown>>,\n  node: Node<unknown>,\n  renderDropIndicator: (target: ItemDropTarget) => ReactNode\n): ReactNode {\n  let key = node.key;\n  let keyAfter = collection.getKeyAfter(key);\n  let nextItemInFlattenedCollection = keyAfter != null ? collection.getItem(keyAfter) : null;\n  while (nextItemInFlattenedCollection != null && nextItemInFlattenedCollection.type !== 'item') {\n    keyAfter = collection.getKeyAfter(nextItemInFlattenedCollection.key);\n    nextItemInFlattenedCollection = keyAfter != null ? collection.getItem(keyAfter) : null;\n  }\n\n  let nextItemInSameLevel = node.nextKey != null ? collection.getItem(node.nextKey) : null;\n  while (nextItemInSameLevel != null && nextItemInSameLevel.type !== 'item') {\n    nextItemInSameLevel =\n      nextItemInSameLevel.nextKey != null ? collection.getItem(nextItemInSameLevel.nextKey) : null;\n  }\n\n  // Render one or more \"after\" drop indicators when the next item in the flattened collection\n  // has a smaller level, is not an item, or there are no more items in the collection.\n  // Otherwise, the \"after\" position is equivalent to the next item's \"before\" position.\n  let afterIndicators: ReactNode[] = [];\n  if (nextItemInSameLevel == null) {\n    let current: Node<unknown> | null = node;\n    while (\n      current?.type === 'item' &&\n      (!nextItemInFlattenedCollection ||\n        (current.parentKey !== nextItemInFlattenedCollection.parentKey &&\n          nextItemInFlattenedCollection.level < current.level))\n    ) {\n      let indicator = renderDropIndicator({\n        type: 'item',\n        key: current.key,\n        dropPosition: 'after'\n      });\n      if (isValidElement(indicator)) {\n        afterIndicators.push(cloneElement(indicator, {key: `${current.key}-after`}));\n      }\n      current = current.parentKey != null ? collection.getItem(current.parentKey) : null;\n    }\n  }\n\n  return afterIndicators;\n}\n\nexport const CollectionRendererContext =\n  createContext<CollectionRenderer>(DefaultCollectionRenderer);\n\ntype PersistedKeysReturnValue = Set<Key> | null;\nexport function usePersistedKeys(focusedKey: Key | null): PersistedKeysReturnValue {\n  return useMemo(() => (focusedKey != null ? new Set([focusedKey]) : null), [focusedKey]);\n}\n"],"names":[],"version":3,"file":"Collection.mjs.map"}