{"version":3,"file":"SubstackSignup.BAAxztqq.mjs","names":["React.useRef","React.useCallback","React.useState","_Fragment","__esmMin","init_npm_react_18_3_1","ne","init_ssg_sandbox_shims","window","l","_e","Ha","c","J","init_jsx_runtime","ce","de","sendToSubstack","data","form","email","EMAIL_FIELD","topic","TOPIC_FIELD","key","SECTIONS","k","section","ALL","body","SUBSTACK","withSubstackSignup","own","setRef","el","ref","confirm","setConfirm","slot","setSlot","onSubmit","pageKey","CONFIRM_PAGES","href","label","cs","holder","anchor","Component","props","CONFIRM_LINE_1","CONFIRM_LINE_2","init_SubstackSignup","init_npm_react_dom_18_3_1"],"sources":["https:/framerusercontent.com/modules/NJMQW1Yki9yqR7PLFeUi/yJA95JsH4hpnhTayDFfo/SubstackSignup.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from\"react/jsx-runtime\";import*as React from\"react\";import{createPortal}from\"react-dom\";// Substack publication and the section each newsletter choice subscribes to.\n// Section IDs come from navisalma.substack.com (public page data).\nconst SUBSTACK=\"https://navisalma.substack.com\";// \"All\" subscribes to the main publication with no section picked, so Substack applies its defaults:\n// the main newsletter plus every section set to \"subscribe new subscribers automatically\".\nconst ALL=\"All\";const SECTIONS={General:\"516385\",\"House of Navisalma\":\"516380\",\"Investor News\":\"516386\"};// Where someone who already has a Substack account confirms their subscription.\nconst CONFIRM_PAGES={All:SUBSTACK,General:SUBSTACK+\"/s/navisalma-general\",\"House of Navisalma\":SUBSTACK+\"/s/house-of-navisalma\",\"Investor News\":SUBSTACK+\"/s/navisalma-investor-news\"};const CONFIRM_LINE_1=\"Already on Substack?\";const CONFIRM_LINE_2=\"Confirm your subscription here →\";const EMAIL_FIELD=\"Email\";const TOPIC_FIELD=\"Topics\";function sendToSubstack(form){const data=new FormData(form);const email=String(data.get(EMAIL_FIELD)||\"\").trim();const topic=String(data.get(TOPIC_FIELD)||\"\");const key=Object.keys(SECTIONS).find(k=>k.toLowerCase()===topic.toLowerCase());const section=key?SECTIONS[key]:undefined;if(!email||!section&&topic.toLowerCase()!==ALL.toLowerCase())return;const body=new URLSearchParams({email,source:\"embed\",first_url:window.location.href,current_url:window.location.href});if(section)body.set(\"specific_section_ids\",section);// Sent from the visitor's browser, as Substack's own embed form does. The response can't be read cross-origin,\n// so this never blocks or breaks the Framer form, which still emails its copy of the sign-up.\nfetch(SUBSTACK+\"/api/v1/free\",{method:\"POST\",mode:\"no-cors\",credentials:\"omit\",headers:{\"Content-Type\":\"application/x-www-form-urlencoded\"},body,keepalive:true}).catch(()=>{});}// Apply to the newsletter form (the frame set to Form). Also signs the visitor up on Substack, in the chosen section.\nexport function withSubstackSignup(Component){return /*#__PURE__*/React.forwardRef(function SubstackSignup(props,ref){const own=React.useRef(null);const setRef=React.useCallback(el=>{own.current=el;if(typeof ref===\"function\")ref(el);else if(ref)ref.current=el;},[ref]);const[confirm,setConfirm]=React.useState(null);// the line is placed inside the form, right after the Submit / Thank you button\nconst[slot,setSlot]=React.useState(null);React.useEffect(()=>{const el=own.current;const form=el?el.tagName===\"FORM\"?el:el.querySelector(\"form\")||el.closest(\"form\"):null;if(!form)return;const onSubmit=()=>{if(!form.checkValidity())return;sendToSubstack(form);const topic=String(new FormData(form).get(TOPIC_FIELD)||\"\");const pageKey=Object.keys(CONFIRM_PAGES).find(k=>k.toLowerCase()===topic.toLowerCase());const href=pageKey?CONFIRM_PAGES[pageKey]:undefined;if(!href)return;// match the form's own label text (font, size, colour)\nconst label=form.querySelector(\"label p, label span, p\");const cs=label?window.getComputedStyle(label):null;setConfirm({href,style:cs?{fontFamily:cs.fontFamily,fontSize:cs.fontSize,fontWeight:cs.fontWeight,letterSpacing:cs.letterSpacing,textTransform:cs.textTransform,color:cs.color}:{}});};const holder=document.createElement(\"div\");holder.style.width=\"100%\";// right after the submit button (or the group holding it), before anything below it such as a privacy notice\nlet anchor=form.querySelector('[type=\"submit\"], button');while(anchor&&anchor.parentElement&&anchor.parentElement!==form)anchor=anchor.parentElement;if(anchor&&anchor.parentElement===form)form.insertBefore(holder,anchor.nextSibling);else form.appendChild(holder);setSlot(holder);form.addEventListener(\"submit\",onSubmit,true);return()=>{form.removeEventListener(\"submit\",onSubmit,true);holder.remove();};},[]);return /*#__PURE__*/_jsxs(_Fragment,{children:[/*#__PURE__*/_jsx(Component,{...props,ref:setRef}),confirm&&slot&&/*#__PURE__*/createPortal(/*#__PURE__*/_jsxs(\"a\",{href:confirm.href,target:\"_blank\",rel:\"noopener\",style:{...confirm.style,display:\"block\",width:\"100%\",marginTop:12,marginBottom:12,textDecoration:\"underline\",textUnderlineOffset:3,lineHeight:1.3},children:[CONFIRM_LINE_1,/*#__PURE__*/_jsx(\"br\",{}),CONFIRM_LINE_2]}),slot)]});});}\nexport const __FramerMetadata__ = {\"exports\":{\"withSubstackSignup\":{\"type\":\"reactHoc\",\"name\":\"withSubstackSignup\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./SubstackSignup.map"],"mappings":"A,8KAKgV,SAASiB,EAAe,EAAK,CAAC,IAAMC,EAAK,IAAI,SAASC,CAAI,EAAQC,EAAM,OAAOF,EAAK,IAAIG,CAAW,GAAG,EAAE,CAAC,CAAC,KAAK,EAAQC,EAAM,OAAOJ,EAAK,IAAIK,CAAW,GAAG,EAAE,EAAQC,EAAI,OAAO,KAAKC,CAAQ,CAAC,CAAC,KAAK,GAAGC,EAAE,YAAY,IAAIJ,EAAM,YAAY,CAAC,EAAQK,EAAQH,EAAIC,EAASD,GAAK,IAAA,GAAU,GAAG,CAACJ,GAAO,CAACO,GAASL,EAAM,YAAY,IAAIM,EAAI,YAAY,EAAE,OAAO,IAAMC,EAAK,IAAI,gBAAgB,CAAC,QAAM,OAAO,QAAQ,UAAUrB,EAAO,SAAS,KAAK,YAAYA,EAAO,SAAS,IAAI,CAAC,EAAKmB,GAAQE,EAAK,IAAI,uBAAuBF,CAAO,EAEr1B,MAAMG,EAAS,eAAe,CAAC,OAA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