{"version":3,"file":"usePortals.cjs","names":["PORTALS_REACT_CONTEXT","getContext","PORTALS_CONTEXT_KEY"],"sources":["../../../src/portals/usePortals/usePortals.ts"],"sourcesContent":["import { useContext } from 'react';\nimport { PORTALS_CONTEXT_KEY } from '@pastweb/tools';\nimport { getContext } from '../../GlobalContext';\nimport { PORTALS_REACT_CONTEXT } from '../constants';\n\n/**\n * Reads the portal descriptor installed by {@link installPortals}.\n *\n * @typeParam T - Expected portal descriptor shape.\n *\n * @returns The current portals context cast to `T`.\n *\n * @example\n * ```tsx\n * type AppPortals = {\n *   modal: PortalFunction;\n * };\n *\n * const portals = usePortals<AppPortals>();\n * const entryId = portals.modal(<Dialog />).open();\n * ```\n */\nexport function usePortals<T>(): T {\n  const providerPortals = useContext(PORTALS_REACT_CONTEXT);\n  const globalPortals = getContext<T>(PORTALS_CONTEXT_KEY);\n\n  return (providerPortals ?? globalPortals) as T;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,aAAmB;CACjC,MAAM,mBAAA,GAAA,MAAA,WAAA,CAA6BA,0BAAAA,qBAAqB;CACxD,MAAM,gBAAgBC,iCAAAA,WAAcC,eAAAA,mBAAmB;CAEvD,OAAQ,mBAAmB;AAC7B"}