@rtstic.dev/pulse 0.0.35 → 0.0.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/form/book-a-demo.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";(()=>{var
|
|
2
|
-
e.g. <script src="https://cdn.jsdelivr.net/npm/intl-tel-input@25/build/js/intlTelInput.min.js"><\/script>`);return}document.querySelectorAll('[pulse-form-block="phone"] input[type="tel"]').forEach(r=>{try{let n=e(r,{initialCountry:"us",separateDialCode:!0,strictMode:!1,loadUtils:()=>import("https://cdn.jsdelivr.net/npm/intl-tel-input@25/build/js/utils.js")});_.set(r,n),v(n),r.addEventListener("countrychange",()=>{v(n)}),console.log(`[PulseForm] intl-tel-input initialized for "${r.closest("[pulse-form-block]")?.getAttribute("pulse-field-name")||"unknown"}"`)}catch(n){console.warn("[PulseForm] Failed to init intl-tel-input:",n)}})}var G={0:l.INVALID_PHONE,1:l.PHONE_INVALID_COUNTRY,2:l.PHONE_TOO_SHORT,3:l.PHONE_TOO_LONG,4:l.INVALID_PHONE};function $(e){return e?/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)?null:{code:l.INVALID_EMAIL,message:c[l.INVALID_EMAIL]}:null}function j(e){let t=e.value.trim();if(!t)return null;let r=_.get(e);if(r)try{if(r.isValidNumber())return null;let o=r.getValidationError?.()??0,s=G[o]||l.INVALID_PHONE;return{code:s,message:c[s]}}catch{return{code:l.INVALID_PHONE,message:c[l.INVALID_PHONE]}}let n=t.replace(/\D/g,"");return n.length<7?{code:l.PHONE_TOO_SHORT,message:c[l.PHONE_TOO_SHORT]}:n.length>15?{code:l.PHONE_TOO_LONG,message:c[l.PHONE_TOO_LONG]}:null}function W(e){let t=e.querySelector("input, textarea");return t?t.value.trim():null}function X(e){let t=e.querySelector('input[type="email"]');return t?t.value.trim():null}function z(e){let t=e.querySelector('input[type="tel"]');return t?t.value.trim():null}function J(e){let t=e.querySelectorAll('input[type="checkbox"]'),r=[];return t.forEach(n=>{if(n.checked){let o=n.getAttribute("data-name")?.trim();r.push(o||n.value||"on")}}),r}function K(e){let t=e.querySelectorAll('input[type="radio"]');for(let r of t)if(r.checked)return r.closest("label")?.textContent?.trim()||r.value||"on";return null}function Z(e){let t=e.querySelector("select");if(!t)return null;let r=t.value.trim();return!r||t.selectedIndex===0?null:r}function ee(e){let t=e.querySelector('input[type="checkbox"]');return t?t.checked:!1}function M(e,t){switch(e){case"text":return W(t);case"email":return X(t);case"phone":return z(t);case"checkbox":return J(t);case"radio":return K(t);case"select":return Z(t);case"legal":return ee(t);default:return null}}function S(e){let t=e.getAttribute("required-selection")?.trim().toLowerCase();return!t||!Y.includes(t)?null:t}function te(e){return e.getAttribute("mirror-value")?.trim().toLowerCase()==="true"}function I(e,t,r,n){if(t)switch(t){case"true":{if(e==="legal"&&r!==!0)return{code:l.REQUIRED_LEGAL,message:c[l.REQUIRED_LEGAL]};if(e==="select"&&!r)return{code:l.REQUIRED_SELECT,message:c[l.REQUIRED_SELECT]};if((e==="text"||e==="email"||e==="phone")&&(!r||typeof r=="string"&&r===""))return{code:l.REQUIRED_INPUT,message:c[l.REQUIRED_INPUT]};break}case"atleast-one":{if(Array.isArray(r)?r.length===0:!r)return{code:l.ATLEAST_ONE,message:c[l.ATLEAST_ONE]};break}case"only-one":{if(Array.isArray(r)){if(r.length===0)return{code:l.ONLY_ONE_NONE,message:c[l.ONLY_ONE_NONE]};if(r.length>1)return{code:l.ONLY_ONE_EXCEEDED,message:c[l.ONLY_ONE_EXCEEDED]}}else if(!r)return{code:l.ONLY_ONE_NONE,message:c[l.ONLY_ONE_NONE]};break}}if(e==="email"&&typeof r=="string"&&r){let o=$(r);if(o)return o}if(e==="phone"&&typeof r=="string"&&r){let o=n.querySelector('input[type="tel"]');if(o){let s=j(o);if(s)return s}}return null}function N(e){let t=document.querySelectorAll("[pulse-form-block]"),r=[];return t.forEach(n=>{let o=n.getAttribute("pulse-form-block")?.trim().toLowerCase();if(!o||!P.includes(o))return;let s=o,a=n.getAttribute("pulse-field-name")?.trim();if(!a)return;let u=S(n),d=te(n),f=M(s,n),m=e?I(s,u,f,n):null;r.push({"form-block":s,"field-name":a,value:f,required:u,"mirror-value":d,error:m})}),r}function F(){document.querySelectorAll(`.${y}`).forEach(e=>e.remove()),document.querySelectorAll("[pulse-form-block]").forEach(e=>e.classList.remove("has-error"))}function ne(e){let t=e.querySelector(`.${y}`);t&&t.remove(),e.classList.remove("has-error")}function k(e,t){let r=e.querySelector(`.${y}`);r&&r.remove();let n=document.createElement("span");n.className=y,n.textContent=t.message,n.setAttribute("data-error-code",t.code),n.setAttribute("data-field-name",e.getAttribute("pulse-field-name")?.trim()||""),e.classList.add("has-error"),e.appendChild(n)}function re(e){F(),document.querySelectorAll("[pulse-form-block]").forEach(r=>{let n=r.getAttribute("pulse-field-name")?.trim();if(!n)return;let o=e.find(s=>s["field-name"]===n);!o||!o.error||k(r,o.error)})}function oe(){let e=document.querySelector("[pulse-form-block].has-error");if(!e)return;e.scrollIntoView({behavior:"smooth",block:"center"});let t=e.querySelector("input, textarea, select");t&&setTimeout(()=>t.focus(),400)}function L(){let e=i.filter(r=>r["mirror-value"]===!0);if(e.length===0)return;let t=document.querySelectorAll("[pulse-form-block-mirror]");e.forEach(r=>{let n=r["field-name"],o=!1;t.forEach(s=>{if(s.getAttribute("pulse-form-block-mirror")?.trim()!==n)return;o=!0;let u=s.querySelector("input, textarea, select");if(!u){console.warn(`[PulseForm] Mirror target for "${n}" found, but no input element inside it.`);return}let d=r.value;typeof d=="string"?u.value=d:typeof d=="boolean"?u instanceof HTMLInputElement&&u.type==="checkbox"?u.checked=d:u.value=String(d):Array.isArray(d)?u.value=d.join(", "):u.value=""}),o||console.warn(`[PulseForm] No mirror target found for field "${n}". Add an element with attribute pulse-form-block-mirror="${n}" to mirror this value.`)})}var le={"Financial Services":"david",Sports:"steven",Beauty:"albany",Music:"steven","Customer Packaged Goods":"david",Other:"david"};function ie(){let e=i.find(n=>n["field-name"]==="industry");if(!e||typeof e.value!="string"||!e.value)return;let t=le[e.value];document.querySelectorAll("[hs-calender]").forEach(n=>{let o=n.getAttribute("hs-calender")?.trim();t&&o===t?n.setAttribute("hs-calender-active","true"):n.setAttribute("hs-calender-active","false")})}function p(){let e=i.find(n=>n["field-name"]==="flow-type");if(!e)return;let t=e.value;document.querySelectorAll("[form-flow]").forEach(n=>{n.getAttribute("form-flow")?.trim()===t?n.setAttribute("form-flow-active","true"):n.setAttribute("form-flow-active","false")}),t==="White Glove services"&&ie()}function h(){let e=i.find(o=>o["field-name"]==="flow-type");if(!e)return;let t=e.value,r=i.findIndex(o=>o["field-name"]==="industry"),n=i.findIndex(o=>o["field-name"]==="what-are-you-looking-for");r!==-1&&(i[r]={...i[r],required:null}),n!==-1&&(i[n]={...i[n],required:null}),t==="White Glove services"&&r!==-1?i[r]={...i[r],required:"true"}:t==="Pulse demo"&&n!==-1&&(i[n]={...i[n],required:"atleast-one"}),window.PulseFormData=i}var i=[];function O(e,t,r){let n=i.findIndex(o=>o["field-name"]===e);n!==-1&&(i[n]={...i[n],value:t,error:r},window.PulseFormData=i,h(),L(),p())}function se(e){let t=e.getAttribute("pulse-form-block")?.trim().toLowerCase(),r=e.getAttribute("pulse-field-name")?.trim();if(!r)return;let n=S(e),o=M(t,e);if(e.classList.contains("has-error")){let a=I(t,n,o,e);a?(k(e,a),O(r,o,a)):(ne(e),O(r,o,null))}else O(r,o,null)}function ue(){document.querySelectorAll("[pulse-form-block]").forEach(t=>{let r=t.getAttribute("pulse-form-block")?.trim().toLowerCase();if(!r||!P.includes(r))return;let n=()=>se(t);switch(r){case"text":case"email":{let o=t.querySelector("input, textarea");o&&(o.addEventListener("input",n),o.addEventListener("change",n));break}case"phone":{let o=t.querySelector('input[type="tel"]');o&&(o.addEventListener("input",n),o.addEventListener("change",n),o.addEventListener("keyup",n),o.addEventListener("countrychange",n));break}case"checkbox":case"legal":{t.querySelectorAll('input[type="checkbox"]').forEach(o=>o.addEventListener("change",n));break}case"radio":{t.querySelectorAll('input[type="radio"]').forEach(o=>o.addEventListener("change",n));break}case"select":{let o=t.querySelector("select");o&&o.addEventListener("change",n);break}}})}var H={get fields(){return i},refresh(){return i=N(!1),window.PulseFormData=i,h(),L(),p(),i},validate(){i=N(!0),window.PulseFormData=i,h();let t=document.querySelectorAll("[pulse-form-block]");i.forEach((n,o)=>{let s=Array.from(t).find(u=>u.getAttribute("pulse-field-name")?.trim()===n["field-name"]);if(!s)return;let a=I(n["form-block"],n.required,n.value,s);i[o]={...i[o],error:a}}),window.PulseFormData=i;let r=i.every(n=>n.error===null);return L(),p(),re(i),r||oe(),{fields:i,isValid:r}},clearErrors(){F(),i=i.map(e=>({...e,error:null})),window.PulseFormData=i,h(),L(),p()},ERROR_CODES:l,ERROR_MESSAGES:c};document.addEventListener("DOMContentLoaded",()=>{let e=document.querySelectorAll("[pulse-form-block]").length;console.log(`[PulseForm] Initialized \u2014 found ${e} form blocks.`),Q(),i=N(!1),window.PulseFormData=i,h(),L(),p(),ue();let t=document.getElementById("trigger-webflow-form-submit");t&&t.addEventListener("click",r=>{r.preventDefault();let{isValid:n}=H.validate();if(!n)return;let o=document.getElementById("webflow-form-submit");o?o.click():console.warn('[PulseForm] Button with id "webflow-form-submit" not found.');let s=document.getElementById("hubspot-form-submit");s?s.click():console.warn('[PulseForm] Button with id "hubspot-form-submit" not found.')}),window.PulseForm=H});function ce(){let e=["Jordan","Morgan","Riley","Avery","Quinn","Casey","Blake","Harper","Sage","Rowan"],t=["Nakamura","Lindqvist","Okafor","Brennan","Castellano","Pham","Eriksen","Moreira","Ashworth","Dubois"],r=["inbox.co","mailbox.org","zipmail.net","postly.io","demobox.dev"],n=m=>m[Math.floor(Math.random()*m.length)],o=()=>Math.random().toString(36).substring(2,8),s=n(e),a=n(t),u=`${s.toLowerCase()}.${o()}@${n(r)}`,d=`${2e9+Math.floor(Math.random()*8e9)}`,f={"first-name":s,"last-name":a,email:u,phone:d,"anything-else":"Ignore this is a test form submission"};Object.entries(f).forEach(([m,b])=>{let T=document.querySelector(`[pulse-field-name="${m}"]`);if(!T)return;if(m==="phone"){let E=T.querySelector('input[type="tel"]');if(!E)return;let A=_.get(E);A?A.setNumber(`+1${b}`):E.value=b,E.dispatchEvent(new Event("input",{bubbles:!0})),E.dispatchEvent(new Event("change",{bubbles:!0})),E.dispatchEvent(new Event("keyup",{bubbles:!0}));return}let g=m==="anything-else"?T.querySelector("textarea"):T.querySelector("input");g&&(g.value=b,g.dispatchEvent(new Event("input",{bubbles:!0})),g.dispatchEvent(new Event("change",{bubbles:!0})))}),console.log("[PulseForm][DEV] Auto-filled:",f)}setTimeout(ce,500);})();
|
|
1
|
+
"use strict";(()=>{var P=Object.create;var y=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var F=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var D=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof require<"u"?require:t)[r]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var w=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of S(t))!k.call(e,o)&&o!==r&&y(e,o,{get:()=>t[o],enumerable:!(n=M(t,o))||n.enumerable});return e};var q=(e,t,r)=>(r=e!=null?P(F(e)):{},w(t||!e||!e.__esModule?y(r,"default",{value:e,enumerable:!0}):r,e));console.log("Book a demo form script loaded");var N=["text","email","phone","checkbox","radio","select","legal"],x=["true","atleast-one","only-one"],l={REQUIRED_INPUT:"ERR_REQUIRED",REQUIRED_LEGAL:"ERR_LEGAL_REQUIRED",REQUIRED_SELECT:"ERR_SELECT_REQUIRED",ATLEAST_ONE:"ERR_ATLEAST_ONE",ONLY_ONE_NONE:"ERR_ONLY_ONE_NONE",ONLY_ONE_EXCEEDED:"ERR_ONLY_ONE_EXCEEDED",INVALID_EMAIL:"ERR_INVALID_EMAIL",INVALID_PHONE:"ERR_INVALID_PHONE",PHONE_TOO_SHORT:"ERR_PHONE_TOO_SHORT",PHONE_TOO_LONG:"ERR_PHONE_TOO_LONG",PHONE_INVALID_COUNTRY:"ERR_PHONE_INVALID_COUNTRY"},c={[l.REQUIRED_INPUT]:"This field is required.",[l.REQUIRED_LEGAL]:"You must accept this to continue.",[l.REQUIRED_SELECT]:"Please select an option.",[l.ATLEAST_ONE]:"Please select at least one option.",[l.ONLY_ONE_NONE]:"Please select one option.",[l.ONLY_ONE_EXCEEDED]:"Only one option can be selected.",[l.INVALID_EMAIL]:"Please enter a valid email address.",[l.INVALID_PHONE]:"Please enter a valid phone number.",[l.PHONE_TOO_SHORT]:"Phone number is too short.",[l.PHONE_TOO_LONG]:"Phone number is too long.",[l.PHONE_INVALID_COUNTRY]:"Invalid country code."},L="pulse-form-error",_=new Map;function b(e){try{let t=e.getSelectedCountryData?.();if(!t?.dialCode)return;document.querySelectorAll('input[pulse-form-field="country-code"]').forEach(n=>{n.value=`+${t.dialCode}`})}catch(t){console.warn("[PulseForm] Error filling country code:",t)}}function C(){let e=window.intlTelInput;if(!e){console.warn(`[PulseForm] intlTelInput not found on window. Make sure you include the intl-tel-input script before this script.
|
|
2
|
+
e.g. <script src="https://cdn.jsdelivr.net/npm/intl-tel-input@25/build/js/intlTelInput.min.js"><\/script>`);return}document.querySelectorAll('[pulse-form-block="phone"] input[type="tel"]').forEach(r=>{try{let n=e(r,{initialCountry:"us",separateDialCode:!0,strictMode:!1,loadUtils:()=>import("https://cdn.jsdelivr.net/npm/intl-tel-input@25/build/js/utils.js")});_.set(r,n),b(n),r.addEventListener("countrychange",()=>{b(n)}),console.log(`[PulseForm] intl-tel-input initialized for "${r.closest("[pulse-form-block]")?.getAttribute("pulse-field-name")||"unknown"}"`)}catch(n){console.warn("[PulseForm] Failed to init intl-tel-input:",n)}})}var V={0:l.INVALID_PHONE,1:l.PHONE_INVALID_COUNTRY,2:l.PHONE_TOO_SHORT,3:l.PHONE_TOO_LONG,4:l.INVALID_PHONE};function U(e){return e?/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)?null:{code:l.INVALID_EMAIL,message:c[l.INVALID_EMAIL]}:null}function B(e){let t=e.value.trim();if(!t)return null;let r=_.get(e);if(r)try{if(r.isValidNumber())return null;let o=r.getValidationError?.()??0,s=V[o]||l.INVALID_PHONE;return{code:s,message:c[s]}}catch{return{code:l.INVALID_PHONE,message:c[l.INVALID_PHONE]}}let n=t.replace(/\D/g,"");return n.length<7?{code:l.PHONE_TOO_SHORT,message:c[l.PHONE_TOO_SHORT]}:n.length>15?{code:l.PHONE_TOO_LONG,message:c[l.PHONE_TOO_LONG]}:null}function Y(e){let t=e.querySelector("input, textarea");return t?t.value.trim():null}function Q(e){let t=e.querySelector('input[type="email"]');return t?t.value.trim():null}function G(e){let t=e.querySelector('input[type="tel"]');return t?t.value.trim():null}function $(e){let t=e.querySelectorAll('input[type="checkbox"]'),r=[];return t.forEach(n=>{if(n.checked){let o=n.getAttribute("data-name")?.trim();r.push(o||n.value||"on")}}),r}function j(e){let t=e.querySelectorAll('input[type="radio"]');for(let r of t)if(r.checked)return r.closest("label")?.textContent?.trim()||r.value||"on";return null}function W(e){let t=e.querySelector("select");if(!t)return null;let r=t.value.trim();return!r||t.selectedIndex===0?null:r}function X(e){let t=e.querySelector('input[type="checkbox"]');return t?t.checked:!1}function I(e,t){switch(e){case"text":return Y(t);case"email":return Q(t);case"phone":return G(t);case"checkbox":return $(t);case"radio":return j(t);case"select":return W(t);case"legal":return X(t);default:return null}}function A(e){let t=e.getAttribute("required-selection")?.trim().toLowerCase();return!t||!x.includes(t)?null:t}function z(e){return e.getAttribute("mirror-value")?.trim().toLowerCase()==="true"}function g(e,t,r,n){if(t)switch(t){case"true":{if(e==="legal"&&r!==!0)return{code:l.REQUIRED_LEGAL,message:c[l.REQUIRED_LEGAL]};if(e==="select"&&!r)return{code:l.REQUIRED_SELECT,message:c[l.REQUIRED_SELECT]};if((e==="text"||e==="email"||e==="phone")&&(!r||typeof r=="string"&&r===""))return{code:l.REQUIRED_INPUT,message:c[l.REQUIRED_INPUT]};break}case"atleast-one":{if(Array.isArray(r)?r.length===0:!r)return{code:l.ATLEAST_ONE,message:c[l.ATLEAST_ONE]};break}case"only-one":{if(Array.isArray(r)){if(r.length===0)return{code:l.ONLY_ONE_NONE,message:c[l.ONLY_ONE_NONE]};if(r.length>1)return{code:l.ONLY_ONE_EXCEEDED,message:c[l.ONLY_ONE_EXCEEDED]}}else if(!r)return{code:l.ONLY_ONE_NONE,message:c[l.ONLY_ONE_NONE]};break}}if(e==="email"&&typeof r=="string"&&r){let o=U(r);if(o)return o}if(e==="phone"&&typeof r=="string"&&r){let o=n.querySelector('input[type="tel"]');if(o){let s=B(o);if(s)return s}}return null}function h(e){let t=document.querySelectorAll("[pulse-form-block]"),r=[];return t.forEach(n=>{let o=n.getAttribute("pulse-form-block")?.trim().toLowerCase();if(!o||!N.includes(o))return;let s=o,a=n.getAttribute("pulse-field-name")?.trim();if(!a)return;let u=A(n),d=z(n),T=I(s,n),H=e?g(s,u,T,n):null;r.push({"form-block":s,"field-name":a,value:T,required:u,"mirror-value":d,error:H})}),r}function R(){document.querySelectorAll(`.${L}`).forEach(e=>e.remove()),document.querySelectorAll("[pulse-form-block]").forEach(e=>e.classList.remove("has-error"))}function J(e){let t=e.querySelector(`.${L}`);t&&t.remove(),e.classList.remove("has-error")}function v(e,t){let r=e.querySelector(`.${L}`);r&&r.remove();let n=document.createElement("span");n.className=L,n.textContent=t.message,n.setAttribute("data-error-code",t.code),n.setAttribute("data-field-name",e.getAttribute("pulse-field-name")?.trim()||""),e.classList.add("has-error"),e.appendChild(n)}function K(e){R(),document.querySelectorAll("[pulse-form-block]").forEach(r=>{let n=r.getAttribute("pulse-field-name")?.trim();if(!n)return;let o=e.find(s=>s["field-name"]===n);!o||!o.error||v(r,o.error)})}function Z(){let e=document.querySelector("[pulse-form-block].has-error");if(!e)return;e.scrollIntoView({behavior:"smooth",block:"center"});let t=e.querySelector("input, textarea, select");t&&setTimeout(()=>t.focus(),400)}function m(){let e=i.filter(r=>r["mirror-value"]===!0);if(e.length===0)return;let t=document.querySelectorAll("[pulse-form-block-mirror]");e.forEach(r=>{let n=r["field-name"],o=!1;t.forEach(s=>{if(s.getAttribute("pulse-form-block-mirror")?.trim()!==n)return;o=!0;let u=s.querySelector("input, textarea, select");if(!u){console.warn(`[PulseForm] Mirror target for "${n}" found, but no input element inside it.`);return}let d=r.value;typeof d=="string"?u.value=d:typeof d=="boolean"?u instanceof HTMLInputElement&&u.type==="checkbox"?u.checked=d:u.value=String(d):Array.isArray(d)?u.value=d.join(", "):u.value=""}),o||console.warn(`[PulseForm] No mirror target found for field "${n}". Add an element with attribute pulse-form-block-mirror="${n}" to mirror this value.`)})}var ee={"Financial Services":"david",Sports:"steven",Beauty:"albany",Music:"steven","Customer Packaged Goods":"david",Other:"david"};function te(){let e=i.find(n=>n["field-name"]==="industry");if(!e||typeof e.value!="string"||!e.value)return;let t=ee[e.value];document.querySelectorAll("[hs-calender]").forEach(n=>{let o=n.getAttribute("hs-calender")?.trim();t&&o===t?n.setAttribute("hs-calender-active","true"):n.setAttribute("hs-calender-active","false")})}function E(){let e=i.find(n=>n["field-name"]==="flow-type");if(!e)return;let t=e.value;document.querySelectorAll("[form-flow]").forEach(n=>{n.getAttribute("form-flow")?.trim()===t?n.setAttribute("form-flow-active","true"):n.setAttribute("form-flow-active","false")}),t==="White Glove services"&&te()}function f(){let e=i.find(o=>o["field-name"]==="flow-type");if(!e)return;let t=e.value,r=i.findIndex(o=>o["field-name"]==="industry"),n=i.findIndex(o=>o["field-name"]==="what-are-you-looking-for");r!==-1&&(i[r]={...i[r],required:null}),n!==-1&&(i[n]={...i[n],required:null}),t==="White Glove services"&&r!==-1?i[r]={...i[r],required:"true"}:t==="Pulse demo"&&n!==-1&&(i[n]={...i[n],required:"atleast-one"}),window.PulseFormData=i}var i=[];function p(e,t,r){let n=i.findIndex(o=>o["field-name"]===e);n!==-1&&(i[n]={...i[n],value:t,error:r},window.PulseFormData=i,f(),m(),E())}function ne(e){let t=e.getAttribute("pulse-form-block")?.trim().toLowerCase(),r=e.getAttribute("pulse-field-name")?.trim();if(!r)return;let n=A(e),o=I(t,e);if(e.classList.contains("has-error")){let a=g(t,n,o,e);a?(v(e,a),p(r,o,a)):(J(e),p(r,o,null))}else p(r,o,null)}function re(){document.querySelectorAll("[pulse-form-block]").forEach(t=>{let r=t.getAttribute("pulse-form-block")?.trim().toLowerCase();if(!r||!N.includes(r))return;let n=()=>ne(t);switch(r){case"text":case"email":{let o=t.querySelector("input, textarea");o&&(o.addEventListener("input",n),o.addEventListener("change",n));break}case"phone":{let o=t.querySelector('input[type="tel"]');o&&(o.addEventListener("input",n),o.addEventListener("change",n),o.addEventListener("keyup",n),o.addEventListener("countrychange",n));break}case"checkbox":case"legal":{t.querySelectorAll('input[type="checkbox"]').forEach(o=>o.addEventListener("change",n));break}case"radio":{t.querySelectorAll('input[type="radio"]').forEach(o=>o.addEventListener("change",n));break}case"select":{let o=t.querySelector("select");o&&o.addEventListener("change",n);break}}})}var O={get fields(){return i},refresh(){return i=h(!1),window.PulseFormData=i,f(),m(),E(),i},validate(){i=h(!0),window.PulseFormData=i,f();let t=document.querySelectorAll("[pulse-form-block]");i.forEach((n,o)=>{let s=Array.from(t).find(u=>u.getAttribute("pulse-field-name")?.trim()===n["field-name"]);if(!s)return;let a=g(n["form-block"],n.required,n.value,s);i[o]={...i[o],error:a}}),window.PulseFormData=i;let r=i.every(n=>n.error===null);return m(),E(),K(i),r||Z(),{fields:i,isValid:r}},clearErrors(){R(),i=i.map(e=>({...e,error:null})),window.PulseFormData=i,f(),m(),E()},ERROR_CODES:l,ERROR_MESSAGES:c};document.addEventListener("DOMContentLoaded",()=>{let e=document.querySelectorAll("[pulse-form-block]").length;console.log(`[PulseForm] Initialized \u2014 found ${e} form blocks.`),C(),i=h(!1),window.PulseFormData=i,f(),m(),E(),re();let t=document.getElementById("trigger-webflow-form-submit");t&&t.addEventListener("click",r=>{r.preventDefault();let{isValid:n}=O.validate();if(!n)return;let o=document.getElementById("webflow-form-submit");o?o.click():console.warn('[PulseForm] Button with id "webflow-form-submit" not found.');let s=document.getElementById("hubspot-form-submit");s?s.click():console.warn('[PulseForm] Button with id "hubspot-form-submit" not found.')}),window.PulseForm=O});})();
|
package/dist/marquee/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";(()=>{var
|
|
2
|
-
e.g. <script src="https://cdn.jsdelivr.net/npm/intl-tel-input@25/build/js/intlTelInput.min.js"><\/script>`);return}document.querySelectorAll('[pulse-form-block="phone"] input[type="tel"]').forEach(n=>{try{let r=e(n,{initialCountry:"us",separateDialCode:!0,strictMode:!1,loadUtils:()=>import("https://cdn.jsdelivr.net/npm/intl-tel-input@25/build/js/utils.js")});
|
|
1
|
+
"use strict";(()=>{var H=Object.create;var O=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var v=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty;var M=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,n)=>(typeof require<"u"?require:t)[n]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var D=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of S(t))!F.call(e,o)&&o!==n&&O(e,o,{get:()=>t[o],enumerable:!(r=P(t,o))||r.enumerable});return e};var k=(e,t,n)=>(n=e!=null?H(v(e)):{},D(t||!e||!e.__esModule?O(n,"default",{value:e,enumerable:!0}):n,e));console.log("Book a demo form script loaded");var p=["text","email","phone","checkbox","radio","select","legal"],C=["true","atleast-one","only-one"],l={REQUIRED_INPUT:"ERR_REQUIRED",REQUIRED_LEGAL:"ERR_LEGAL_REQUIRED",REQUIRED_SELECT:"ERR_SELECT_REQUIRED",ATLEAST_ONE:"ERR_ATLEAST_ONE",ONLY_ONE_NONE:"ERR_ONLY_ONE_NONE",ONLY_ONE_EXCEEDED:"ERR_ONLY_ONE_EXCEEDED",INVALID_EMAIL:"ERR_INVALID_EMAIL",INVALID_PHONE:"ERR_INVALID_PHONE",PHONE_TOO_SHORT:"ERR_PHONE_TOO_SHORT",PHONE_TOO_LONG:"ERR_PHONE_TOO_LONG",PHONE_INVALID_COUNTRY:"ERR_PHONE_INVALID_COUNTRY"},u={[l.REQUIRED_INPUT]:"This field is required.",[l.REQUIRED_LEGAL]:"You must accept this to continue.",[l.REQUIRED_SELECT]:"Please select an option.",[l.ATLEAST_ONE]:"Please select at least one option.",[l.ONLY_ONE_NONE]:"Please select one option.",[l.ONLY_ONE_EXCEEDED]:"Only one option can be selected.",[l.INVALID_EMAIL]:"Please enter a valid email address.",[l.INVALID_PHONE]:"Please enter a valid phone number.",[l.PHONE_TOO_SHORT]:"Phone number is too short.",[l.PHONE_TOO_LONG]:"Phone number is too long.",[l.PHONE_INVALID_COUNTRY]:"Invalid country code."},f="pulse-form-error",h=new Map;function N(e){try{let t=e.getSelectedCountryData?.();if(!t?.dialCode)return;document.querySelectorAll('input[pulse-form-field="country-code"]').forEach(r=>{r.value=`+${t.dialCode}`})}catch(t){console.warn("[PulseForm] Error filling country code:",t)}}function q(){let e=window.intlTelInput;if(!e){console.warn(`[PulseForm] intlTelInput not found on window. Make sure you include the intl-tel-input script before this script.
|
|
2
|
+
e.g. <script src="https://cdn.jsdelivr.net/npm/intl-tel-input@25/build/js/intlTelInput.min.js"><\/script>`);return}document.querySelectorAll('[pulse-form-block="phone"] input[type="tel"]').forEach(n=>{try{let r=e(n,{initialCountry:"us",separateDialCode:!0,strictMode:!1,loadUtils:()=>import("https://cdn.jsdelivr.net/npm/intl-tel-input@25/build/js/utils.js")});h.set(n,r),N(r),n.addEventListener("countrychange",()=>{N(r)}),console.log(`[PulseForm] intl-tel-input initialized for "${n.closest("[pulse-form-block]")?.getAttribute("pulse-field-name")||"unknown"}"`)}catch(r){console.warn("[PulseForm] Failed to init intl-tel-input:",r)}})}var x={0:l.INVALID_PHONE,1:l.PHONE_INVALID_COUNTRY,2:l.PHONE_TOO_SHORT,3:l.PHONE_TOO_LONG,4:l.INVALID_PHONE};function V(e){return e?/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)?null:{code:l.INVALID_EMAIL,message:u[l.INVALID_EMAIL]}:null}function U(e){let t=e.value.trim();if(!t)return null;let n=h.get(e);if(n)try{if(n.isValidNumber())return null;let o=n.getValidationError?.()??0,s=x[o]||l.INVALID_PHONE;return{code:s,message:u[s]}}catch{return{code:l.INVALID_PHONE,message:u[l.INVALID_PHONE]}}let r=t.replace(/\D/g,"");return r.length<7?{code:l.PHONE_TOO_SHORT,message:u[l.PHONE_TOO_SHORT]}:r.length>15?{code:l.PHONE_TOO_LONG,message:u[l.PHONE_TOO_LONG]}:null}function w(e){let t=e.querySelector("input, textarea");return t?t.value.trim():null}function Y(e){let t=e.querySelector('input[type="email"]');return t?t.value.trim():null}function Q(e){let t=e.querySelector('input[type="tel"]');return t?t.value.trim():null}function G(e){let t=e.querySelectorAll('input[type="checkbox"]'),n=[];return t.forEach(r=>{if(r.checked){let o=r.getAttribute("data-name")?.trim();n.push(o||r.value||"on")}}),n}function B(e){let t=e.querySelectorAll('input[type="radio"]');for(let n of t)if(n.checked)return n.closest("label")?.textContent?.trim()||n.value||"on";return null}function $(e){let t=e.querySelector("select");if(!t)return null;let n=t.value.trim();return!n||t.selectedIndex===0?null:n}function X(e){let t=e.querySelector('input[type="checkbox"]');return t?t.checked:!1}function I(e,t){switch(e){case"text":return w(t);case"email":return Y(t);case"phone":return Q(t);case"checkbox":return G(t);case"radio":return B(t);case"select":return $(t);case"legal":return X(t);default:return null}}function g(e){let t=e.getAttribute("required-selection")?.trim().toLowerCase();return!t||!C.includes(t)?null:t}function j(e){return e.getAttribute("mirror-value")?.trim().toLowerCase()==="true"}function y(e,t,n,r){if(t)switch(t){case"true":{if(e==="legal"&&n!==!0)return{code:l.REQUIRED_LEGAL,message:u[l.REQUIRED_LEGAL]};if(e==="select"&&!n)return{code:l.REQUIRED_SELECT,message:u[l.REQUIRED_SELECT]};if((e==="text"||e==="email"||e==="phone")&&(!n||typeof n=="string"&&n===""))return{code:l.REQUIRED_INPUT,message:u[l.REQUIRED_INPUT]};break}case"atleast-one":{if(Array.isArray(n)?n.length===0:!n)return{code:l.ATLEAST_ONE,message:u[l.ATLEAST_ONE]};break}case"only-one":{if(Array.isArray(n)){if(n.length===0)return{code:l.ONLY_ONE_NONE,message:u[l.ONLY_ONE_NONE]};if(n.length>1)return{code:l.ONLY_ONE_EXCEEDED,message:u[l.ONLY_ONE_EXCEEDED]}}else if(!n)return{code:l.ONLY_ONE_NONE,message:u[l.ONLY_ONE_NONE]};break}}if(e==="email"&&typeof n=="string"&&n){let o=V(n);if(o)return o}if(e==="phone"&&typeof n=="string"&&n){let o=r.querySelector('input[type="tel"]');if(o){let s=U(o);if(s)return s}}return null}function T(e){let t=document.querySelectorAll("[pulse-form-block]"),n=[];return t.forEach(r=>{let o=r.getAttribute("pulse-form-block")?.trim().toLowerCase();if(!o||!p.includes(o))return;let s=o,d=r.getAttribute("pulse-field-name")?.trim();if(!d)return;let c=g(r),a=j(r),_=I(s,r),b=e?y(s,c,_,r):null;n.push({"form-block":s,"field-name":d,value:_,required:c,"mirror-value":a,error:b})}),n}function A(){document.querySelectorAll(`.${f}`).forEach(e=>e.remove()),document.querySelectorAll("[pulse-form-block]").forEach(e=>e.classList.remove("has-error"))}function W(e){let t=e.querySelector(`.${f}`);t&&t.remove(),e.classList.remove("has-error")}function R(e,t){let n=e.querySelector(`.${f}`);n&&n.remove();let r=document.createElement("span");r.className=f,r.textContent=t.message,r.setAttribute("data-error-code",t.code),r.setAttribute("data-field-name",e.getAttribute("pulse-field-name")?.trim()||""),e.classList.add("has-error"),e.appendChild(r)}function z(e){A(),document.querySelectorAll("[pulse-form-block]").forEach(n=>{let r=n.getAttribute("pulse-field-name")?.trim();if(!r)return;let o=e.find(s=>s["field-name"]===r);!o||!o.error||R(n,o.error)})}function K(){let e=document.querySelector("[pulse-form-block].has-error");if(!e)return;e.scrollIntoView({behavior:"smooth",block:"center"});let t=e.querySelector("input, textarea, select");t&&setTimeout(()=>t.focus(),400)}function E(){let e=i.filter(n=>n["mirror-value"]===!0);if(e.length===0)return;let t=document.querySelectorAll("[pulse-form-block-mirror]");e.forEach(n=>{let r=n["field-name"],o=!1;t.forEach(s=>{if(s.getAttribute("pulse-form-block-mirror")?.trim()!==r)return;o=!0;let c=s.querySelector("input, textarea, select");if(!c){console.warn(`[PulseForm] Mirror target for "${r}" found, but no input element inside it.`);return}let a=n.value;typeof a=="string"?c.value=a:typeof a=="boolean"?c instanceof HTMLInputElement&&c.type==="checkbox"?c.checked=a:c.value=String(a):Array.isArray(a)?c.value=a.join(", "):c.value=""}),o||console.warn(`[PulseForm] No mirror target found for field "${r}". Add an element with attribute pulse-form-block-mirror="${r}" to mirror this value.`)})}var J={"Financial Services":"david",Sports:"steven",Beauty:"albany",Music:"steven","Customer Packaged Goods":"david",Other:"david"};function Z(){let e=i.find(r=>r["field-name"]==="industry");if(!e||typeof e.value!="string"||!e.value)return;let t=J[e.value];document.querySelectorAll("[hs-calender]").forEach(r=>{let o=r.getAttribute("hs-calender")?.trim();t&&o===t?r.setAttribute("hs-calender-active","true"):r.setAttribute("hs-calender-active","false")})}function m(){let e=i.find(r=>r["field-name"]==="flow-type");if(!e)return;let t=e.value;document.querySelectorAll("[form-flow]").forEach(r=>{r.getAttribute("form-flow")?.trim()===t?r.setAttribute("form-flow-active","true"):r.setAttribute("form-flow-active","false")}),t==="White Glove services"&&Z()}var i=[];function L(e,t,n){let r=i.findIndex(o=>o["field-name"]===e);r!==-1&&(i[r]={...i[r],value:t,error:n},window.PulseFormData=i,E(),m())}function ee(e){let t=e.getAttribute("pulse-form-block")?.trim().toLowerCase(),n=e.getAttribute("pulse-field-name")?.trim();if(!n)return;let r=g(e),o=I(t,e);if(e.classList.contains("has-error")){let d=y(t,r,o,e);d?(R(e,d),L(n,o,d)):(W(e),L(n,o,null))}else L(n,o,null)}function te(){document.querySelectorAll("[pulse-form-block]").forEach(t=>{let n=t.getAttribute("pulse-form-block")?.trim().toLowerCase();if(!n||!p.includes(n))return;let r=()=>ee(t);switch(n){case"text":case"email":{let o=t.querySelector("input, textarea");o&&(o.addEventListener("input",r),o.addEventListener("change",r));break}case"phone":{let o=t.querySelector('input[type="tel"]');o&&(o.addEventListener("input",r),o.addEventListener("change",r),o.addEventListener("keyup",r),o.addEventListener("countrychange",r));break}case"checkbox":case"legal":{t.querySelectorAll('input[type="checkbox"]').forEach(o=>o.addEventListener("change",r));break}case"radio":{t.querySelectorAll('input[type="radio"]').forEach(o=>o.addEventListener("change",r));break}case"select":{let o=t.querySelector("select");o&&o.addEventListener("change",r);break}}})}var ne={get fields(){return i},refresh(){return i=T(!1),window.PulseFormData=i,E(),m(),i},validate(){let e=T(!0),t=e.every(n=>n.error===null);return i=e,window.PulseFormData=i,E(),m(),z(e),t||K(),{fields:e,isValid:t}},clearErrors(){A(),i=i.map(e=>({...e,error:null})),window.PulseFormData=i,E(),m()},ERROR_CODES:l,ERROR_MESSAGES:u};document.addEventListener("DOMContentLoaded",()=>{let e=document.querySelectorAll("[pulse-form-block]").length;console.log(`[PulseForm] Initialized \u2014 found ${e} form blocks.`),q(),i=T(!1),window.PulseFormData=i,E(),m(),te(),window.PulseForm=ne});})();
|