@noaignite/react-centra-checkout
Version:
React components and helpers for Centra checkout api
1 lines • 2.1 kB
Source Map (JSON)
{"version":3,"file":"HtmlEmbed.cjs","names":["useRef"],"sources":["../../src/internal/HtmlEmbed.tsx"],"sourcesContent":["import { useEffect, useRef } from 'react'\n\ninterface HtmlEmbedProps extends React.ComponentProps<'div'> {\n html: string\n}\n\nexport function HtmlEmbed(props: HtmlEmbedProps): React.ReactElement {\n const { html, ...other } = props\n\n const ref = useRef<HTMLDivElement>(null)\n\n // We need to reload scripts in the html in order for them to run\n useEffect(() => {\n const createdScripts: HTMLScriptElement[] = []\n const node = ref.current\n\n if (node && html) {\n const scripts = node.getElementsByTagName('script')\n\n Array.from(scripts).forEach((script) => {\n if (script.type === 'application/json') {\n return\n }\n\n const scriptEl = document.createElement('script')\n\n if (script.src) {\n scriptEl.src = script.src\n } else {\n const textNode = document.createTextNode(script.innerHTML)\n scriptEl.appendChild(textNode)\n }\n\n script.remove()\n createdScripts.push(scriptEl)\n node.appendChild(scriptEl)\n })\n }\n\n return () => {\n createdScripts.forEach((script) => {\n script.remove()\n })\n }\n }, [html])\n\n return <div dangerouslySetInnerHTML={{ __html: html }} ref={ref} {...other} />\n}\n"],"mappings":";;;;AAMA,SAAgB,UAAU,OAA2C;CACnE,MAAM,EAAE,MAAM,GAAG,UAAU;CAE3B,MAAM,OAAA,GAAMA,MAAAA,OAAAA,CAAuB,IAAI;CAGvC,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd,MAAM,iBAAsC,CAAC;EAC7C,MAAM,OAAO,IAAI;EAEjB,IAAI,QAAQ,MAAM;GAChB,MAAM,UAAU,KAAK,qBAAqB,QAAQ;GAElD,MAAM,KAAK,OAAO,CAAC,CAAC,SAAS,WAAW;IACtC,IAAI,OAAO,SAAS,oBAClB;IAGF,MAAM,WAAW,SAAS,cAAc,QAAQ;IAEhD,IAAI,OAAO,KACT,SAAS,MAAM,OAAO;SACjB;KACL,MAAM,WAAW,SAAS,eAAe,OAAO,SAAS;KACzD,SAAS,YAAY,QAAQ;IAC/B;IAEA,OAAO,OAAO;IACd,eAAe,KAAK,QAAQ;IAC5B,KAAK,YAAY,QAAQ;GAC3B,CAAC;EACH;EAEA,aAAa;GACX,eAAe,SAAS,WAAW;IACjC,OAAO,OAAO;GAChB,CAAC;EACH;CACF,GAAG,CAAC,IAAI,CAAC;CAET,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;EAAK,yBAAyB,EAAE,QAAQ,KAAK;EAAQ;EAAK,GAAI;CAAQ,CAAA;AAC/E"}