{"mappings":";;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAeM,MAAM,0DAEb,CAAA,GAAA,sCAAI,EAAE,UAAU,CAAC,SAAS,YAAY,KAAuB,EAAE,GAA6C;IAC1G,IAAI,SAAS,MAAM,QAAQ;IAC3B,IAAI,CAAC,UAAU,YAAY,GAAG,CAAA,GAAA,qBAAO,EAAsB;IAC3D,IAAI,SAAS,CAAA,GAAA,mBAAK,EAAyB;IAC3C,IAAI,MAAM,CAAA,GAAA,mBAAK,EAAwD;IAEvE,CAAA,GAAA,gCAAkB,EAAE,KAAK,IAAM,CAAC,OAAmB;YACjD,qFAAqF;YACrF,kGAAkG;YAElG,IAAI,SAAS,OAAO;YACpB,IAAI;YACJ,IAAI;YACJ,IAAI;YAEJ,IAAI,UAAU,OAAO,WAAW,YAAY,aAAa,QAAQ;gBAC/D,UAAU,OAAO,OAAO;gBACxB,UAAU,OAAO,CAAC;gBAClB,UAAU,OAAO,CAAC;YACpB,OACE,UAAU;YAGZ,CAAA,GAAA,yBAAQ,EAAE;gBACR,YAAY;YACd;YAEA,+CAA+C;YAC/C,SAAS,OAAO,OAAO,EAAE,SAAS;YAElC,kFAAkF;YAClF,IAAI,OAAO,GAAG,sBAAsB;gBAClC,YAAY;YACd;QACF,GAAG;QAAC;KAAO;IAEX,CAAA,GAAA,sBAAQ,EAAE;QACR,OAAO;YACL,IAAI,IAAI,OAAO,EACb,qBAAqB,IAAI,OAAO;QAEpC;IACF,GAAG,EAAE;IAEL,IAAI,CAAC,UACH,OAAO;IAGT,qBACE,0DAAC;QAAI,OAAO;YAAC,QAAQ;YAAM,UAAU;YAAS,KAAK;YAAG,MAAM;QAAO;QAAG,KAAK;OACxE;AAGP","sources":["packages/react-aria/src/dnd/DragPreview.tsx"],"sourcesContent":["/*\n * Copyright 2020 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 */\n\nimport {DragItem, DragPreviewRenderer} from '@react-types/shared';\nimport {flushSync} from 'react-dom';\nimport React, {ForwardedRef, JSX, useEffect, useImperativeHandle, useRef, useState} from 'react';\n\nexport interface DragPreviewProps {\n  /**\n   * A render function which returns a preview element, or an object containing the element\n   * and a custom offset. If an object is returned, the provided `x` and `y` values will be\n   * used as the drag preview offset instead of the default calculation.\n   */\n  children: (items: DragItem[]) => JSX.Element | {element: JSX.Element, x: number, y: number} | null\n}\n\nexport const DragPreview:\n  React.ForwardRefExoticComponent<DragPreviewProps & React.RefAttributes<DragPreviewRenderer | null>> =\nReact.forwardRef(function DragPreview(props: DragPreviewProps, ref: ForwardedRef<DragPreviewRenderer | null>) {\n  let render = props.children;\n  let [children, setChildren] = useState<JSX.Element | null>(null);\n  let domRef = useRef<HTMLDivElement | null>(null);\n  let raf = useRef<ReturnType<typeof requestAnimationFrame> | undefined>(undefined);\n\n  useImperativeHandle(ref, () => (items: DragItem[], callback: (node: HTMLElement | null, x?: number, y?: number) => void) => {\n    // This will be called during the onDragStart event by useDrag. We need to render the\n    // preview synchronously before this event returns so we can call event.dataTransfer.setDragImage.\n\n    let result = render(items);\n    let element: JSX.Element | null;\n    let offsetX: number | undefined;\n    let offsetY: number | undefined;\n\n    if (result && typeof result === 'object' && 'element' in result) {\n      element = result.element;\n      offsetX = result.x;\n      offsetY = result.y;\n    } else {\n      element = result as JSX.Element | null;\n    }\n\n    flushSync(() => {\n      setChildren(element);\n    });\n\n    // Yield back to useDrag to set the drag image.\n    callback(domRef.current, offsetX, offsetY);\n\n    // Remove the preview from the DOM after a frame so the browser has time to paint.\n    raf.current = requestAnimationFrame(() => {\n      setChildren(null);\n    });\n  }, [render]);\n\n  useEffect(() => {\n    return () => {\n      if (raf.current) {\n        cancelAnimationFrame(raf.current);\n      }\n    };\n  }, []);\n\n  if (!children) {\n    return null;\n  }\n\n  return (\n    <div style={{zIndex: -100, position: 'fixed', top: 0, left: -100000}} ref={domRef}>\n      {children}\n    </div>\n  );\n});\n"],"names":[],"version":3,"file":"DragPreview.cjs.map"}