{"version":3,"sources":["../src/modal-focus.tsx"],"sourcesContent":["import { FocusLock } from \"@chakra-ui/focus-lock\"\nimport { usePresence } from \"framer-motion\"\nimport { useEffect } from \"react\"\nimport { RemoveScroll } from \"react-remove-scroll\"\n\nimport { useModalContext } from \"./modal\"\nimport { useModalManager } from \"./modal-manager\"\n\ninterface ModalFocusScopeProps {\n  /**\n   * @type React.ReactElement\n   */\n  children: React.ReactElement\n}\n\nexport function ModalFocusScope(props: ModalFocusScopeProps) {\n  const {\n    autoFocus,\n    trapFocus,\n    dialogRef,\n    initialFocusRef,\n    blockScrollOnMount,\n    allowPinchZoom,\n    finalFocusRef,\n    returnFocusOnClose,\n    preserveScrollBarGap,\n    lockFocusAcrossFrames,\n    isOpen,\n  } = useModalContext()\n\n  const [isPresent, safeToRemove] = usePresence()\n\n  useEffect(() => {\n    if (!isPresent && safeToRemove) {\n      setTimeout(safeToRemove)\n    }\n  }, [isPresent, safeToRemove])\n\n  const index = useModalManager(dialogRef, isOpen)\n\n  return (\n    <FocusLock\n      autoFocus={autoFocus}\n      isDisabled={!trapFocus}\n      initialFocusRef={initialFocusRef}\n      finalFocusRef={finalFocusRef}\n      restoreFocus={returnFocusOnClose}\n      contentRef={dialogRef}\n      lockFocusAcrossFrames={lockFocusAcrossFrames}\n    >\n      <RemoveScroll\n        removeScrollBar={!preserveScrollBarGap}\n        allowPinchZoom={allowPinchZoom}\n        // only block scroll for first dialog\n        enabled={index === 1 && blockScrollOnMount}\n        forwardProps\n      >\n        {props.children}\n      </RemoveScroll>\n    </FocusLock>\n  )\n}\n"],"mappings":";;;;;;;;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB;AAC5B,SAAS,iBAAiB;AAC1B,SAAS,oBAAoB;AA+CvB;AAnCC,SAAS,gBAAgB,OAA6B;AAC3D,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,gBAAgB;AAEpB,QAAM,CAAC,WAAW,YAAY,IAAI,YAAY;AAE9C,YAAU,MAAM;AACd,QAAI,CAAC,aAAa,cAAc;AAC9B,iBAAW,YAAY;AAAA,IACzB;AAAA,EACF,GAAG,CAAC,WAAW,YAAY,CAAC;AAE5B,QAAM,QAAQ,gBAAgB,WAAW,MAAM;AAE/C,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,YAAY,CAAC;AAAA,MACb;AAAA,MACA;AAAA,MACA,cAAc;AAAA,MACd,YAAY;AAAA,MACZ;AAAA,MAEA;AAAA,QAAC;AAAA;AAAA,UACC,iBAAiB,CAAC;AAAA,UAClB;AAAA,UAEA,SAAS,UAAU,KAAK;AAAA,UACxB,cAAY;AAAA,UAEX,gBAAM;AAAA;AAAA,MACT;AAAA;AAAA,EACF;AAEJ;","names":[]}