{"version":3,"file":"Hubspot.CmoNN545.mjs","names":["React.useState","React.useRef"],"sources":["https:/framerusercontent.com/modules/uGQZtcsxBzvxqsgxQ0Tz/x1uX2pQ17kYOWs5UPyT3/Hubspot.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import*as React from\"react\";import{addPropertyControls,ControlType,useTracking}from\"framer\";import{emptyStateStyle,stateParagraphStyle,stateTitleStyle}from\"https://framer.com/m/framer/integrations-styles.js@0.2.0\";// Poll for 5 minutes ...\nfunction poll(f,delay=200,count=5*60*5,i=0){if(i>count){console.error(\"poll max attempts\",f);return;}if(!f()){console.log(\"poll\",delay,count,i);setTimeout(()=>{poll(f,delay,count,i+1);},delay);}}function EmptyState({title,description}){return /*#__PURE__*/_jsxs(\"div\",{style:{...emptyStateStyle,width:\"100%\",height:\"100%\"},children:[/*#__PURE__*/_jsx(\"h1\",{style:stateTitleStyle,children:title}),/*#__PURE__*/_jsx(\"p\",{style:stateParagraphStyle,children:description})]});}/**\n * Return the actual instance id of the HubSpot form.\n *\n * window.hbspt.forms.create returns a totally different instanceId\n * from the one in the success event. This ugly code below grabs the\n * actual instance id from the iframe src. Hopefully this doesn’t break.\n */function getActualInstanceId(div){const url=div.querySelector(\"iframe\")?.getAttribute(\"src\");return url?new URL(url).searchParams.get(\"_hsInstanceId\"):null;}/**\n * HUBSPOT\n *\n * @framerIntrinsicWidth 480\n * @framerIntrinsicHeight 300\n *\n * @framerSupportedLayoutWidth fixed\n * @framerSupportedLayoutHeight auto\n */export default function HubSpotForm({portalId,formId,advanced,region,trackingId}){const[isScriptLoaded,setIsScriptLoaded]=React.useState(()=>Boolean(typeof window!==\"undefined\"&&window.hbspt));const ref=React.useRef(null);const track=useTracking();// Tracking setup\nReact.useEffect(()=>{if(!portalId||!formId||!trackingId)return;function onFormSubmissionSuccess(event){if(!ref.current)return;// Because the events are global, we need to compare\n// instanceId to know which instance it is comes from.\nif(getActualInstanceId(ref.current)!==event.detail.instanceId)return;if(trackingId)track(trackingId);}// https://developers.hubspot.com/docs/guides/api/marketing/forms/global-form-events#form-events$0\ndocument.addEventListener(\"hs-form-event:on-submission:success\",onFormSubmissionSuccess);return()=>document.removeEventListener(\"hs-form-event:on-submission:success\",onFormSubmissionSuccess);},[trackingId,formId,portalId]);// Load the hubspot script\nReact.useEffect(()=>{if(!region)return;if(isScriptLoaded||typeof window===\"undefined\")return;if(window.hbspt)return setIsScriptLoaded(true);const script=document.createElement(\"script\");script.src=`https://js-${region}.hsforms.net/forms/shell.js`;script.async=true;script.onload=()=>poll(()=>{if(window.hbspt){setIsScriptLoaded(true);return true;}});document.body.appendChild(script);},[isScriptLoaded,region]);React.useEffect(()=>{if(!portalId||!formId)return;if(!isScriptLoaded||!ref.current||typeof window===\"undefined\")return;const element=document.createElement(\"div\");const randomId=Math.random().toString(36).substr(2,8);const elementId=`hubspot_form_${randomId}`;element.setAttribute(\"id\",elementId);element.style.width=\"100%\";element.style.height=\"100%\";ref.current.appendChild(element);window.hbspt.forms.create({region,portalId,formId,target:`#${elementId}`});return()=>{if(ref.current)ref.current.removeChild(element);};},[isScriptLoaded,portalId,formId]);if(!portalId||!formId||!region){return /*#__PURE__*/_jsx(EmptyState,{title:\"Hubspot\",description:\"Set a portal ID and form in the Properties.\"});}return /*#__PURE__*/_jsx(\"div\",{style:{display:\"contents\"},ref:ref});}addPropertyControls(HubSpotForm,{portalId:{title:\"Portal\",type:ControlType.String,placeholder:\"25276298\",// defaultValue: \"25276298\",\ndescription:\"Create a [Hubspot](https://www.hubspot.com/) account, add a new form and copy your portal ID. [Learn more…](https://www.framer.com/plugins/hubspot/)\"},formId:{title:\"Form\",type:ControlType.String,placeholder:\"e7167571-4bc4-4c2c-bfdc-a0a8dbfd22f1\"},trackingId:{title:\"Tracking\",type:ControlType.TrackingId,placeholder:\"ID\"},advanced:{title:\"Advanced\",type:ControlType.Boolean,enabledTitle:\"Show\",disabledTitle:\"Hide\",defaultValue:false},region:{title:\"Region\",type:ControlType.String,placeholder:\"eu1\",defaultValue:\"eu1\",hidden:({advanced})=>!advanced}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"HubSpotForm\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\",\"framerIntrinsicHeight\":\"300\",\"framerSupportedLayoutWidth\":\"fixed\",\"framerSupportedLayoutHeight\":\"auto\",\"framerIntrinsicWidth\":\"480\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Hubspot.map"],"mappings":"ySACA,SAAS,EAAK,EAAE,EAAM,IAAI,EAAM,IAAK,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,EAAM,CAAC,QAAQ,MAAM,oBAAoB,CAAC,EAAE,MAAO,CAAK,EAAE,IAAG,QAAQ,IAAI,OAAO,EAAM,EAAM,CAAC,EAAE,eAAe,CAAC,EAAK,EAAE,EAAM,EAAM,EAAE,CAAC,CAAE,EAAE,CAAK,EAAG,CAAC,SAAS,EAAW,CAAC,QAAM,eAAa,CAAC,OAAoB,EAAM,MAAM,CAAC,MAAM,CAAC,GAAG,EAAgB,MAAM,OAAO,OAAO,MAAM,EAAE,SAAS,CAAc,EAAK,KAAK,CAAC,MAAM,EAAgB,SAAS,CAAK,CAAC,EAAe,EAAK,IAAI,CAAC,MAAM,EAAoB,SAAS,CAAW,CAAC,CAAC,CAAC,CAAC,CAAE,CAMpd,SAAS,EAAoB,EAAI,CAAC,IAAM,EAAI,EAAI,cAAc,QAAQ,CAAC,EAAE,aAAa,KAAK,EAAE,OAAO,EAAI,IAAI,IAAI,CAAG,CAAC,CAAC,aAAa,IAAI,eAAe,EAAE,IAAK,CAQ5J,SAAwB,EAAY,CAAC,WAAS,SAAO,WAAS,SAAO,cAAY,CAAC,GAAK,CAAC,EAAe,GAAmBA,MAAmB,GAAe,IAAS,QAAa,EAAO,MAAM,EAAQ,EAAIC,EAAa,IAAI,EAAQ,EAAM,EAAY,EAKi2B,OAJ1l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