{"ast":null,"code":"import _defineProperty from \"@babel/runtime/helpers/defineProperty\";\n\nfunction ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }\n\nfunction _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }\n\nimport { useEffect } from 'react';\nimport { useFocusWithin } from '@react-aria/interactions';\nvar visibleOverlays = [];\nexport function useOverlay(props, ref) {\n  var onClose = props.onClose,\n      shouldCloseOnBlur = props.shouldCloseOnBlur,\n      isOpen = props.isOpen,\n      _props$isKeyboardDism = props.isKeyboardDismissDisabled,\n      isKeyboardDismissDisabled = _props$isKeyboardDism === void 0 ? false : _props$isKeyboardDism;\n  useEffect(function () {\n    if (isOpen) {\n      visibleOverlays.push(ref);\n    }\n\n    return function () {\n      var index = visibleOverlays.indexOf(ref);\n\n      if (index >= 0) {\n        visibleOverlays.splice(index, 1);\n      }\n    };\n  }, [isOpen, ref]);\n\n  var onHide = function onHide() {\n    if (visibleOverlays[visibleOverlays.length - 1] === ref && onClose) {\n      onClose();\n    }\n  };\n\n  var onKeyDown = function onKeyDown(e) {\n    if (e.key === 'Escape' && !isKeyboardDismissDisabled) {\n      e.preventDefault();\n      onHide();\n    }\n  };\n\n  var _useFocusWithin = useFocusWithin({\n    isDisabled: !shouldCloseOnBlur,\n    onBlurWithin: function onBlurWithin() {\n      onClose && onClose();\n    }\n  }),\n      focusWithinProps = _useFocusWithin.focusWithinProps;\n\n  return {\n    overlayProps: _objectSpread({\n      onKeyDown: onKeyDown\n    }, focusWithinProps)\n  };\n}","map":{"version":3,"sources":["useOverlay.web.ts"],"names":["visibleOverlays","isKeyboardDismissDisabled","useEffect","index","onHide","onClose","onKeyDown","e","focusWithinProps","useFocusWithin","isDisabled","onBlurWithin","overlayProps"],"mappings":";;;;;;AAAA,SAAA,SAAA,QAAA,OAAA;AACA,SAAA,cAAA,QAAA,0BAAA;AAsCA,IAAMA,eAAyC,GAA/C,EAAA;AAOA,OAAO,SAAA,UAAA,CAAA,KAAA,EAAA,GAAA,EAGQ;AAAA,MACT,OADS,GAAA,KAAA,CACT,OADS;AAAA,MACT,iBADS,GAAA,KAAA,CACT,iBADS;AAAA,MACT,MADS,GAAA,KAAA,CACT,MADS;AAAA,8BAAA,KAAA,CAKXC,yBALW;AAAA,MAKXA,yBALW,sCAKiB,KALjB;AASbC,EAAAA,SAAS,CAAC,YAAM;AACd,QAAA,MAAA,EAAY;AACVF,MAAAA,eAAe,CAAfA,IAAAA,CAAAA,GAAAA;AACD;;AAED,WAAO,YAAM;AACX,UAAIG,KAAK,GAAGH,eAAe,CAAfA,OAAAA,CAAZ,GAAYA,CAAZ;;AACA,UAAIG,KAAK,IAAT,CAAA,EAAgB;AACdH,QAAAA,eAAe,CAAfA,MAAAA,CAAAA,KAAAA,EAAAA,CAAAA;AACD;AAJH,KAAA;AALO,GAAA,EAWN,CAAA,MAAA,EApBU,GAoBV,CAXM,CAATE;;AAcA,MAAIE,MAAM,GAAG,SAATA,MAAS,GAAM;AACjB,QAAIJ,eAAe,CAACA,eAAe,CAAfA,MAAAA,GAAhBA,CAAe,CAAfA,KAAAA,GAAAA,IAAJ,OAAA,EAAoE;AAClEK,MAAAA,OAAO;AACR;AA1BU,GAuBb;;AAOA,MAAIC,SAAS,GAAIC,SAAbD,SAAaC,CAAAA,CAAD,EAAY;AAC1B,QAAIA,CAAC,CAADA,GAAAA,KAAAA,QAAAA,IAAsB,CAA1B,yBAAA,EAAsD;AACpDA,MAAAA,CAAC,CAADA,cAAAA;AACAH,MAAAA,MAAM;AACP;AAlCU,GA8Bb;;AA9Ba,wBAuCcK,cAAc,CAAC;AACxCC,IAAAA,UAAU,EAAE,CAD4B,iBAAA;AAExCC,IAAAA,YAAY,EAAE,wBAAM;AAClBN,MAAAA,OAAO,IAAIA,OAAXA,EAAAA;AACD;AAJuC,GAAD,CAvC5B;AAAA,MAuCPG,gBAvCO,mBAuCPA,gBAvCO;;AA8Cb,SAAO;AACLI,IAAAA,YAAY;AACVN,MAAAA,SADY,EACZA;AADU,OAEPE,gBAFO;AADP,GAAP;AAMD","sourcesContent":["import { HTMLAttributes, RefObject, useEffect } from 'react';\nimport { useFocusWithin } from '@react-aria/interactions';\n\ninterface OverlayProps {\n  /** Whether the overlay is currently open. */\n  isOpen?: boolean;\n\n  /** Handler that is called when the overlay should close. */\n  onClose?: () => void;\n\n  /**\n   * Whether to close the overlay when the user interacts outside it.\n   * @default false\n   */\n  isDismissable?: boolean;\n\n  /** Whether the overlay should close when focus is lost or moves outside it. */\n  shouldCloseOnBlur?: boolean;\n\n  /**\n   * Whether pressing the escape key to close the overlay should be disabled.\n   * @default false\n   */\n  isKeyboardDismissDisabled?: boolean;\n\n  /**\n   * When user interacts with the argument element outside of the overlay ref,\n   * return true if onClose should be called.  This gives you a chance to filter\n   * out interaction with elements that should not dismiss the overlay.\n   * By default, onClose will always be called on interaction outside the overlay ref.\n   */\n  shouldCloseOnInteractOutside?: (element: HTMLElement) => boolean;\n}\n\ninterface OverlayAria {\n  /** Props to apply to the overlay container element. */\n  overlayProps: HTMLAttributes<HTMLElement>;\n}\n\nconst visibleOverlays: RefObject<HTMLElement>[] = [];\n\n/**\n * Provides the behavior for overlays such as dialogs, popovers, and menus.\n * Hides the overlay when the user interacts outside it, when the Escape key is pressed,\n * or optionally, on blur. Only the top-most overlay will close at once.\n */\nexport function useOverlay(\n  props: OverlayProps,\n  ref: RefObject<HTMLElement>\n): OverlayAria {\n  let {\n    onClose,\n    shouldCloseOnBlur,\n    isOpen,\n    isKeyboardDismissDisabled = false,\n  } = props;\n\n  // Add the overlay ref to the stack of visible overlays on mount, and remove on unmount.\n  useEffect(() => {\n    if (isOpen) {\n      visibleOverlays.push(ref);\n    }\n\n    return () => {\n      let index = visibleOverlays.indexOf(ref);\n      if (index >= 0) {\n        visibleOverlays.splice(index, 1);\n      }\n    };\n  }, [isOpen, ref]);\n\n  // Only hide the overlay when it is the topmost visible overlay in the stack.\n  let onHide = () => {\n    if (visibleOverlays[visibleOverlays.length - 1] === ref && onClose) {\n      onClose();\n    }\n  };\n\n  // Handle the escape key\n  let onKeyDown = (e: any) => {\n    if (e.key === 'Escape' && !isKeyboardDismissDisabled) {\n      e.preventDefault();\n      onHide();\n    }\n  };\n\n  // Handle clicking outside the overlay to close it\n\n  let { focusWithinProps } = useFocusWithin({\n    isDisabled: !shouldCloseOnBlur,\n    onBlurWithin: () => {\n      onClose && onClose();\n    },\n  });\n\n  return {\n    overlayProps: {\n      onKeyDown,\n      ...focusWithinProps,\n    },\n  };\n}\n"]},"metadata":{},"sourceType":"module"}