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;oBAAO,IAC3E,OAAO,YAAY,GAAG,YAAY,WAAW;gBAEjD;gBAEA,OAAO;YACT;QACF;QAEA,IAAI,OAAO,KAAK,CAAC,KAAK,GAAG,CAAC,KAAK,MAAM,MAAM,GAAG,GAAG;QACjD,IAAI,UAAU,WAAW,GAAG,CAAC,OAAO,KAAK,GAAG;QAC5C,OAAO,SAAS;QAEhB,IAAI,QAAS,CAAA,UAAU,IAAI,CAAC,eAAe,CAAC,SAAS,KAAK,GAAG,CAAC,OAAO,IAAI,CAAC,YAAY,CAAC,SAAS,KAAK,GAAG,CAAC,OAAO,IAAI,CAAC,UAAU,CAAC,MAAK,GACnI,OAAO;YACL,MAAM;YACN,KAAK,KAAK,GAAG;YACb,cAAc,YAAY,UAAU;QACtC;QAGF,OAAO;YACL,MAAM;YACN,KAAK,KAAK,GAAG;YACb,cAAc,YAAY,WAAW;QACvC;IACF;AACF","sources":["packages/react-aria/src/dnd/ListDropTargetDelegate.ts"],"sourcesContent":["import {Direction, DropTarget, DropTargetDelegate, Node, Orientation, RefObject} from '@react-types/shared';\n\ninterface ListDropTargetDelegateOptions {\n  /**\n   * Whether the items are arranged in a stack or grid.\n   * @default 'stack'\n   */\n  layout?: 'stack' | 'grid',\n  /**\n   * The primary orientation of the items. Usually this is the\n   * direction that the collection scrolls.\n   * @default 'vertical'\n   */\n  orientation?: Orientation,\n  /**\n   * The horizontal layout direction.\n   * @default 'ltr'\n   */\n  direction?: Direction\n}\n\n// Terms used in the below code:\n//   * \"Primary\"   – The main layout direction. For stacks, this is the direction\n//                   that the stack is arranged in (e.g. horizontal or vertical).\n//                   For grids, this is the main scroll direction.\n//   * \"Secondary\" – The secondary layout direction. For stacks, there is no secondary\n//                   layout direction. For grids, this is the opposite of the primary direction.\n//   * \"Flow\"      – The flow direction of the items. For stacks, this is the the primary\n//                   direction. For grids, it is the secondary direction.\n\nexport class ListDropTargetDelegate implements DropTargetDelegate {\n  private collection: Iterable<Node<unknown>>;\n  private ref: RefObject<HTMLElement | null>;\n  private layout: 'stack' | 'grid';\n  private orientation: Orientation;\n  protected direction: Direction;\n\n  constructor(collection: Iterable<Node<unknown>>, ref: RefObject<HTMLElement | null>, options?: ListDropTargetDelegateOptions) {\n    this.collection = collection;\n    this.ref = ref;\n    this.layout = options?.layout || 'stack';\n    this.orientation = options?.orientation || 'vertical';\n    this.direction = options?.direction || 'ltr';\n  }\n\n  private getPrimaryStart(rect: DOMRect) {\n    return this.orientation === 'horizontal' ? rect.left : rect.top;\n  }\n\n  private getPrimaryEnd(rect: DOMRect) {\n    return this.orientation === 'horizontal' ? rect.right : rect.bottom;\n  }\n\n  private getSecondaryStart(rect: DOMRect) {\n    return this.orientation === 'horizontal' ? rect.top : rect.left;\n  }\n\n  private getSecondaryEnd(rect: DOMRect) {\n    return this.orientation === 'horizontal' ? rect.bottom : rect.right;\n  }\n\n  private getFlowStart(rect: DOMRect) {\n    return this.layout === 'stack' ? this.getPrimaryStart(rect) : this.getSecondaryStart(rect);\n  }\n\n  private getFlowEnd(rect: DOMRect) {\n    return this.layout === 'stack' ? this.getPrimaryEnd(rect) : this.getSecondaryEnd(rect);\n  }\n\n  private getFlowSize(rect: DOMRect) {\n    return this.getFlowEnd(rect) - this.getFlowStart(rect);\n  }\n\n  getDropTargetFromPoint(x: number, y: number, isValidDropTarget: (target: DropTarget) => boolean): DropTarget {\n    if (this.collection[Symbol.iterator]().next().done || !this.ref.current) {\n      return {type: 'root'};\n    }\n\n    let rect: DOMRect | undefined = this.ref.current.getBoundingClientRect();\n    let primary = this.orientation === 'horizontal' ? x : y;\n    let secondary = this.orientation === 'horizontal' ? y : x;\n    primary += this.getPrimaryStart(rect);\n    secondary += this.getSecondaryStart(rect);\n\n    let flow = this.layout === 'stack' ? primary : secondary;\n    let isPrimaryRTL = this.orientation === 'horizontal' && this.direction === 'rtl';\n    let isSecondaryRTL = this.layout === 'grid' && this.orientation === 'vertical' && this.direction === 'rtl';\n    let isFlowRTL = this.layout === 'stack' ? isPrimaryRTL : isSecondaryRTL;\n\n    let collection = this.ref.current?.dataset.collection;\n    let elements = this.ref.current.querySelectorAll(collection ? `[data-collection=\"${CSS.escape(collection)}\"]` : '[data-key]');\n    let elementMap = new Map<string, HTMLElement>();\n    for (let item of elements) {\n      if (item instanceof HTMLElement && item.dataset.key != null) {\n        elementMap.set(item.dataset.key, item);\n      }\n    }\n\n    // TODO: assume that only item type items are valid drop targets. This is to prevent a crash when dragging over the loader\n    // row since it doesn't have a data-key set on it. Will eventually need to handle the case with drag and drop and loaders located between rows aka tree.\n    // Can see https://github.com/adobe/react-spectrum/pull/4210/files#diff-21e555e0c597a28215e36137f5be076a65a1e1456c92cd0fdd60f866929aae2a for additional logic\n    // that may need to happen then\n    let items = [...this.collection].filter(item => item.type === 'item');\n\n    if (items.length < 1) {\n      return {type: 'root'};\n    }\n\n    let low = 0;\n    let high = items.length;\n    while (low < high) {\n      let mid = Math.floor((low + high) / 2);\n      let item = items[mid];\n      let element = elementMap.get(String(item.key));\n      if (!element) {\n        break;\n      }\n      let rect = element.getBoundingClientRect();\n      let update = (isGreater: boolean) => {\n        if (isGreater) {\n          low = mid + 1;\n        } else {\n          high = mid;\n        }\n      };\n\n      if (primary < this.getPrimaryStart(rect)) {\n        update(isPrimaryRTL);\n      } else if (primary > this.getPrimaryEnd(rect)) {\n        update(!isPrimaryRTL);\n      } else if (secondary < this.getSecondaryStart(rect)) {\n        update(isSecondaryRTL);\n      } else if (secondary > this.getSecondaryEnd(rect)) {\n        update(!isSecondaryRTL);\n      } else {\n        let target: DropTarget = {\n          type: 'item',\n          key: item.key,\n          dropPosition: 'on'\n        };\n\n        if (isValidDropTarget(target)) {\n          // Otherwise, if dropping on the item is accepted, try the before/after positions if within 5px\n          // of the start or end of the item.\n          if (flow <= this.getFlowStart(rect) + 5 && isValidDropTarget({...target, dropPosition: 'before'})) {\n            target.dropPosition = isFlowRTL ? 'after' : 'before';\n          } else if (flow >= this.getFlowEnd(rect) - 5 && isValidDropTarget({...target, dropPosition: 'after'})) {\n            target.dropPosition = isFlowRTL ? 'before' : 'after';\n          }\n        } else {\n          // If dropping on the item isn't accepted, try the target before or after depending on the position.\n          let mid = this.getFlowStart(rect) + this.getFlowSize(rect) / 2;\n          if (flow <= mid && isValidDropTarget({...target, dropPosition: 'before'})) {\n            target.dropPosition = isFlowRTL ? 'after' : 'before';\n          } else if (flow >= mid && isValidDropTarget({...target, dropPosition: 'after'})) {\n            target.dropPosition = isFlowRTL ? 'before' : 'after';\n          }\n        }\n\n        return target;\n      }\n    }\n\n    let item = items[Math.min(low, items.length - 1)];\n    let element = elementMap.get(String(item.key));\n    rect = element?.getBoundingClientRect();\n\n    if (rect && (primary < this.getPrimaryStart(rect) || Math.abs(flow - this.getFlowStart(rect)) < Math.abs(flow - this.getFlowEnd(rect)))) {\n      return {\n        type: 'item',\n        key: item.key,\n        dropPosition: isFlowRTL ? 'after' : 'before'\n      };\n    }\n\n    return {\n      type: 'item',\n      key: item.key,\n      dropPosition: isFlowRTL ? 'before' : 'after'\n    };\n  }\n}\n"],"names":[],"version":3,"file":"ListDropTargetDelegate.cjs.map"}