{"version":3,"sources":["../../../src/components/Mounter.tsx"],"sourcesContent":["import type { MountHandle, NovuUI } from '@novu/js/ui';\nimport { useRef } from 'react';\nimport { registerMountPoint } from '../context/mountPointScopes';\nimport { useNovuUI, useOutletScope } from '../context/NovuUIContext';\nimport { useIsomorphicLayoutEffect } from '../hooks/internal/useIsomorphicLayoutEffect';\n\ntype MountComponentParams = Parameters<NovuUI['mountComponent']>[0];\n\nexport type MounterProps = {\n  name: MountComponentParams['name'];\n  props?: MountComponentParams['props'];\n  /** Mount as an island: no `Root` wrapper, no layout box. For mount points inside DOM that already sits under an engine root. */\n  bare?: boolean;\n};\n\n/**\n * A mount point: a DOM node the host hands to the engine so the engine can render a component into it.\n *\n * Mounts before the browser paints, pushes later prop changes through the engine's handle instead of mounting\n * again, and unmounts when React removes it.\n */\nexport function Mounter({ name, props, bare }: MounterProps) {\n  const { novuUI } = useNovuUI();\n  const scope = useOutletScope();\n  const ref = useRef<HTMLDivElement>(null);\n  const handleRef = useRef<MountHandle<MountComponentParams['props']> | null>(null);\n  const latestProps = useRef(props);\n  latestProps.current = props;\n\n  // Before the mount below: the engine opens outlets synchronously while mounting, and those look the scope up.\n  useIsomorphicLayoutEffect(() => {\n    const element = ref.current;\n    if (!element || !scope) {\n      return;\n    }\n\n    return registerMountPoint(element, scope);\n  }, [scope]);\n\n  useIsomorphicLayoutEffect(() => {\n    const element = ref.current;\n    if (!element) {\n      return;\n    }\n\n    handleRef.current = novuUI.mountComponent({ name, element, props: latestProps.current, bare });\n\n    return () => {\n      handleRef.current?.unmount();\n      handleRef.current = null;\n    };\n  }, [novuUI, name, bare]);\n\n  useIsomorphicLayoutEffect(() => {\n    handleRef.current?.update(props);\n  }, [props]);\n\n  return <div ref={ref} style={bare ? { display: 'contents' } : undefined} />;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAuB;AACvB,8BAAmC;AACnC,2BAA0C;AAC1C,uCAA0C;AAqDjC;AApCF,SAAS,QAAQ,EAAE,MAAM,OAAO,KAAK,GAAiB;AAC3D,QAAM,EAAE,OAAO,QAAI,gCAAU;AAC7B,QAAM,YAAQ,qCAAe;AAC7B,QAAM,UAAM,qBAAuB,IAAI;AACvC,QAAM,gBAAY,qBAA0D,IAAI;AAChF,QAAM,kBAAc,qBAAO,KAAK;AAChC,cAAY,UAAU;AAGtB,kEAA0B,MAAM;AAC9B,UAAM,UAAU,IAAI;AACpB,QAAI,CAAC,WAAW,CAAC,OAAO;AACtB;AAAA,IACF;AAEA,eAAO,4CAAmB,SAAS,KAAK;AAAA,EAC1C,GAAG,CAAC,KAAK,CAAC;AAEV,kEAA0B,MAAM;AAC9B,UAAM,UAAU,IAAI;AACpB,QAAI,CAAC,SAAS;AACZ;AAAA,IACF;AAEA,cAAU,UAAU,OAAO,eAAe,EAAE,MAAM,SAAS,OAAO,YAAY,SAAS,KAAK,CAAC;AAE7F,WAAO,MAAM;AA/CjB;AAgDM,sBAAU,YAAV,mBAAmB;AACnB,gBAAU,UAAU;AAAA,IACtB;AAAA,EACF,GAAG,CAAC,QAAQ,MAAM,IAAI,CAAC;AAEvB,kEAA0B,MAAM;AArDlC;AAsDI,oBAAU,YAAV,mBAAmB,OAAO;AAAA,EAC5B,GAAG,CAAC,KAAK,CAAC;AAEV,SAAO,4CAAC,SAAI,KAAU,OAAO,OAAO,EAAE,SAAS,WAAW,IAAI,QAAW;AAC3E;","names":[]}