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collection.tsx"],"sourcesContent":["/*\n * Copyright 2022 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 {CollectionBase, DropTargetDelegate, GlobalDOMAttributes, ItemDropTarget, Key, LayoutDelegate, RefObject} 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, {cloneElement, createContext, ForwardedRef, HTMLAttributes, isValidElement, JSX, ReactElement, ReactNode, useContext, useMemo} 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   * @selector [data-hovered]\n   */\n  isHovered: boolean,\n  /**\n   * Whether the item is currently in a pressed state.\n   * @selector [data-pressed]\n   */\n  isPressed: boolean,\n  /**\n   * Whether the item is currently selected.\n   * @selector [data-selected]\n   */\n  isSelected: boolean,\n  /**\n   * Whether the item is currently focused.\n   * @selector [data-focused]\n   */\n  isFocused: boolean,\n  /**\n   * Whether the item is currently keyboard focused.\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 may\n   * not be focused. Dependent on `disabledKeys` and `disabledBehavior`.\n   * @selector [data-disabled]\n   */\n  isDisabled: boolean,\n  /**\n   * The type of selection that is allowed in the collection.\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   * @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   * @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   * @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> extends Omit<SharedSectionProps<T>, 'children' | 'title'>, StyleProps, GlobalDOMAttributes<HTMLElement> {\n  /** The unique id of the section. */\n  id?: Key,\n  /** The object value that this section represents. When using dynamic collections, this is set automatically. */\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: (props: SectionProps<any>, ref: ForwardedRef<HTMLElement>, section: Node<any>, className?: string) => ReactElement\n}\n\nexport const SectionContext = createContext<SectionContextValue | null>(null);\n\n/** @deprecated */\nexport const Section = /*#__PURE__*/ createBranchComponent('section', <T extends object>(props: SectionProps<T>, ref: ForwardedRef<HTMLElement>, section: Node<T>): 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\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(collection: ICollection<Node<unknown>>, node: Node<unknown>, renderDropIndicator: (target: ItemDropTarget) => ReactNode): 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 = 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 (current?.type === 'item' && (!nextItemInFlattenedCollection || (current.parentKey !== nextItemInFlattenedCollection.parentKey && nextItemInFlattenedCollection.level < current.level))) {\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 = 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.cjs.map"}