@builder.io/sdk-react 3.0.2 → 3.0.3-0
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/lib/browser/blocks-exports.cjs +169 -32
- package/lib/browser/blocks-exports.mjs +1297 -887
- package/lib/browser/index.cjs +1 -1
- package/lib/browser/index.mjs +17 -16
- package/lib/browser/server-entry-c7bda8b5.cjs +2 -0
- package/lib/browser/{server-entry-a2495a20.js → server-entry-da1754bd.js} +279 -237
- package/lib/browser/server-entry.cjs +1 -1
- package/lib/browser/server-entry.mjs +1 -1
- package/lib/edge/accordion-388f5e60.cjs +1 -0
- package/lib/edge/{accordion-c020e15b.js → accordion-50de133c.js} +17 -16
- package/lib/edge/{blocks-27ac5b23.js → blocks-5e476ddc.js} +4 -4
- package/lib/edge/{blocks-cd946d16.cjs → blocks-a5193d52.cjs} +8 -8
- package/lib/edge/blocks-exports.cjs +1 -1
- package/lib/edge/blocks-exports.mjs +13 -12
- package/lib/edge/{button-5cdb4f26.js → button-4261ae64.js} +2 -2
- package/lib/edge/{button-8572fca5.cjs → button-c6ec3aea.cjs} +1 -1
- package/lib/edge/{columns-3ac1fa96.js → columns-28e9fb0a.js} +12 -12
- package/lib/edge/{columns-c8a9cb89.cjs → columns-8c831c02.cjs} +2 -2
- package/lib/edge/{content-variants-23c8eec6.js → content-variants-36ca4fe5.js} +165 -124
- package/lib/edge/content-variants-81713434.cjs +134 -0
- package/lib/edge/{custom-code-6d9730ff.cjs → custom-code-8119ea3f.cjs} +1 -1
- package/lib/edge/dynamic-blocks-exports.cjs +3 -1
- package/lib/edge/dynamic-blocks-exports.mjs +5 -2
- package/lib/edge/{form-7fc5691b.js → form-039fb5ff.js} +13 -13
- package/lib/edge/{form-3d9bf265.cjs → form-e7a1dec9.cjs} +1 -1
- package/lib/edge/{get-class-prop-name-a4845b04.js → get-class-prop-name-65d6824c.js} +1 -1
- package/lib/edge/{get-class-prop-name-29fd576a.cjs → get-class-prop-name-a86a3e60.cjs} +1 -1
- package/lib/edge/{image-5c9e156f.js → image-2a2b26d2.js} +6 -6
- package/lib/edge/{image-94922c87.cjs → image-4db81d72.cjs} +3 -3
- package/lib/edge/{img-388698cb.js → img-61d29fb3.js} +1 -1
- package/lib/edge/{img-102acaa2.cjs → img-7de3a3de.cjs} +1 -1
- package/lib/edge/index.cjs +1 -1
- package/lib/edge/index.mjs +18 -17
- package/lib/edge/{input-10e350a9.cjs → input-bd5387a6.cjs} +1 -1
- package/lib/edge/{input-5484e9e7.js → input-c8539054.js} +1 -1
- package/lib/edge/personalization-container-3fda6014.cjs +138 -0
- package/lib/edge/personalization-container-c76e4fef.js +379 -0
- package/lib/edge/{select-b8406bcf.js → select-6b5cda00.js} +1 -1
- package/lib/edge/{select-f11be7a7.cjs → select-73accaf4.cjs} +1 -1
- package/lib/edge/{server-entry-7ce03a4e.js → server-entry-838c1f06.js} +322 -280
- package/lib/edge/server-entry-ea2a8b0e.cjs +2 -0
- package/lib/edge/server-entry.cjs +1 -1
- package/lib/edge/server-entry.mjs +1 -1
- package/lib/edge/{slot-4ab390ec.cjs → slot-099112f1.cjs} +1 -1
- package/lib/edge/{slot-23f75377.js → slot-403c77da.js} +3 -3
- package/lib/edge/{symbol-2eafb4e0.js → symbol-97f456f4.js} +2 -2
- package/lib/edge/{symbol-fa343d77.cjs → symbol-ffa6e6cd.cjs} +1 -1
- package/lib/edge/{tabs-4c9c64f6.js → tabs-a7c94ead.js} +3 -3
- package/lib/edge/{tabs-7d258d82.cjs → tabs-ad55c6a7.cjs} +1 -1
- package/lib/node/blocks-exports.cjs +168 -31
- package/lib/node/blocks-exports.mjs +1403 -993
- package/lib/node/index.cjs +1 -1
- package/lib/node/index.mjs +17 -16
- package/lib/node/init.cjs +1 -1
- package/lib/node/init.mjs +3 -3
- package/lib/node/{server-entry-2b263dde.js → server-entry-51bc0b1d.js} +279 -237
- package/lib/node/server-entry-d7316893.cjs +2 -0
- package/lib/node/server-entry.cjs +1 -1
- package/lib/node/server-entry.mjs +1 -1
- package/lib/node/{setIvm-7eb67cd6.js → setIvm-575cf1f1.js} +1 -1
- package/lib/node/{setIvm-1e6f0b60.cjs → setIvm-d912cf4d.cjs} +1 -1
- package/lib/node/setIvm.cjs +1 -1
- package/lib/node/setIvm.mjs +2 -2
- package/lib/node/{should-force-browser-runtime-in-node-23218b19.cjs → should-force-browser-runtime-in-node-23225980.cjs} +1 -1
- package/lib/node/{should-force-browser-runtime-in-node-cdae9360.js → should-force-browser-runtime-in-node-66df4856.js} +1 -1
- package/package.json +1 -1
- package/types/blocks/index.d.ts +4 -0
- package/types/blocks/personalization-container/component-info.d.ts +2 -0
- package/types/blocks/personalization-container/helpers/index.d.ts +15 -0
- package/types/blocks/personalization-container/helpers/inlined-fns.d.ts +8 -0
- package/types/blocks/personalization-container/helpers.d.ts +27 -0
- package/types/blocks/personalization-container/index.d.ts +1 -0
- package/types/blocks/personalization-container/personalization-container.d.ts +4 -0
- package/types/blocks/personalization-container/personalization-container.types.d.ts +14 -0
- package/types/blocks/textarea/component-info.d.ts +2 -0
- package/types/blocks/textarea/index.d.ts +1 -0
- package/types/blocks/textarea/textarea.d.ts +14 -0
- package/types/constants/sdk-version.d.ts +1 -1
- package/types/functions/filter-with-custom-targeting.d.ts +15 -0
- package/types/helpers/user-attributes.d.ts +17 -0
- package/types/index-helpers/blocks-exports.d.ts +1 -0
- package/types/types/builder-content.d.ts +1 -0
- package/types/types/input.d.ts +11 -0
- package/lib/browser/server-entry-75ce8600.cjs +0 -2
- package/lib/edge/accordion-1c16f65e.cjs +0 -1
- package/lib/edge/content-variants-caa23bf7.cjs +0 -134
- package/lib/edge/server-entry-1879cbc4.cjs +0 -2
- package/lib/node/server-entry-ec330556.cjs +0 -2
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";const w="react",gt=t=>{const e={};return t.forEach((n,r)=>{e[r]=n}),e},M=t=>t instanceof URLSearchParams?gt(t):t,N=t=>typeof t=="string"?t:t instanceof URLSearchParams?t.toString():new URLSearchParams(t).toString();function c(){return typeof window!="undefined"&&typeof document!="undefined"}function pt(){return c()&&window.self!==window.top}function K(t){return pt()&&N(t||window.location.search).indexOf("builder.frameEditing=")!==-1}function mt(t){const e=t||(c()?window.location.search:void 0);return e?N(e).indexOf("builder.preview=")!==-1:!1}const yt=t=>({type:"builder.registerComponent",data:P(t)}),wt=t=>{const e=t.toString().trim(),n=/^[a-zA-Z0-9_]+\s*=>/i.test(e);return`return (${!e.startsWith("function")&&!e.startsWith("async")&&!e.startsWith("(")&&!n?"function ":""}${e}).apply(this, arguments)`};function P(t){return JSON.parse(JSON.stringify(t,(e,n)=>typeof n=="function"?wt(n):n))}const U={};function j(t,e){t==="plugin"&&(e=P(e));let n=U[t];if(n||(n=U[t]=[]),n.push(e),c()){const r={type:"builder.register",data:{type:t,info:e}};try{parent.postMessage(r,"*"),parent!==window&&window.postMessage(r,"*")}catch(s){console.debug("Could not postmessage",s)}}}const L={};function St(t){if(c()){Object.assign(L,t);const e={type:"builder.settingsChange",data:L};parent.postMessage(e,"*")}}const F="builder.",bt="options.",O=t=>{if(!t)return{};const e=M(t),n={};return Object.keys(e).forEach(r=>{if(r.startsWith(F)){const s=r.replace(F,"").replace(bt,"");n[s]=e[r]}}),n},vt=()=>{if(!c())return{};const t=new URLSearchParams(window.location.search);return O(t)},I="[Builder.io]: ",d={log:(...t)=>console.log(I,...t),error:(...t)=>console.error(I,...t),warn:(...t)=>console.warn(I,...t),debug:(...t)=>console.debug(I,...t)},W="3.0.2",_=()=>({"X-Builder-SDK":w,"X-Builder-SDK-GEN":"2","X-Builder-SDK-Version":W}),p=t=>t!=null,It=t=>{if(t==="localhost"||t==="127.0.0.1")return t;const e=t.split(".");return e.length>2?e.slice(1).join("."):t},$=({name:t,canTrack:e})=>{var n;try{return e?(n=document.cookie.split("; ").find(r=>r.startsWith(`${t}=`)))==null?void 0:n.split("=")[1]:void 0}catch(r){d.warn("[COOKIE] GET error: ",(r==null?void 0:r.message)||r);return}},G=async t=>$(t),kt=t=>t.map(([e,n])=>n?`${e}=${n}`:e).filter(p).join("; "),Et=[["secure",""],["SameSite","None"]],At=({name:t,value:e,expires:n})=>{const s=(c()?location.protocol==="https:":!0)?Et:[[]],o=n?[["expires",n.toUTCString()]]:[[]],i=[[t,e],...o,["path","/"],["domain",It(window.location.hostname)],...s];return kt(i)},z=async({name:t,value:e,expires:n,canTrack:r})=>{try{if(!r)return;const s=At({name:t,value:e,expires:n});document.cookie=s}catch(s){d.warn("[COOKIE] SET error: ",(s==null?void 0:s.message)||s)}};function Pt(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){const e=Math.random()*16|0;return(t=="x"?e:e&3|8).toString(16)})}function H(){return Pt().replace(/-/g,"")}const J="builderSessionId",Ot=async({canTrack:t})=>{if(!t)return;const e=await G({name:J,canTrack:t});if(p(e))return e;{const n=Ct();return Tt({id:n,canTrack:t}),n}},Ct=()=>H(),Tt=({id:t,canTrack:e})=>z({name:J,value:t,canTrack:e}),X=()=>c()&&typeof localStorage!="undefined"?localStorage:void 0,xt=({key:t,canTrack:e})=>{var n;try{return e?(n=X())==null?void 0:n.getItem(t):void 0}catch(r){console.debug("[LocalStorage] GET error: ",r);return}},Bt=({key:t,canTrack:e,value:n})=>{var r;try{e&&((r=X())==null||r.setItem(t,n))}catch(s){console.debug("[LocalStorage] SET error: ",s)}},Q="builderVisitorId",Rt=({canTrack:t})=>{if(!t)return;const e=xt({key:Q,canTrack:t});if(p(e))return e;{const n=Ut();return Lt({id:n,canTrack:t}),n}},Ut=()=>H(),Lt=({id:t,canTrack:e})=>Bt({key:Q,value:t,canTrack:e});function Y(t){var e;typeof process!="undefined"&&((e=process.env)!=null&&e.DEBUG)&&String(process.env.DEBUG)=="true"&&d.log(t)}const Ft=()=>{if(c()){const t=new URL(location.href);return t.pathname===""&&(t.pathname="/"),t}else return console.warn("Cannot get location for tracking in non-browser environment"),null},Vt=()=>typeof navigator=="object"&&navigator.userAgent||"",Z=()=>{const t=Vt(),e={Android(){return t.match(/Android/i)},BlackBerry(){return t.match(/BlackBerry/i)},iOS(){return t.match(/iPhone|iPod/i)},Opera(){return t.match(/Opera Mini/i)},Windows(){return t.match(/IEMobile/i)||t.match(/WPDesktop/i)},any(){return e.Android()||e.BlackBerry()||e.iOS()||e.Opera()||e.Windows()||w==="reactNative"}},n=t.match(/Tablet|iPad/i),r=Ft();return{urlPath:r==null?void 0:r.pathname,host:(r==null?void 0:r.host)||(r==null?void 0:r.hostname),device:n?"tablet":e.any()?"mobile":"desktop"}},Dt=async({canTrack:t})=>{if(!t)return{visitorId:void 0,sessionId:void 0};const e=await Ot({canTrack:t}),n=Rt({canTrack:t});return{sessionId:e,visitorId:n}},Mt=async({type:t,canTrack:e,apiKey:n,metadata:r,...s})=>({type:t,data:{...s,metadata:{url:location.href,...r},...await Dt({canTrack:e}),userAttributes:Z(),ownerId:n}});async function q({apiHost:t,...e}){if(!e.apiKey){d.error("Missing API key for track call. Please provide your API key.");return}if(!e.canTrack||K()||!(c()||w==="reactNative"))return;const r=`${t||"https://cdn.builder.io"}/api/v1/track`;return Y(r),fetch(r,{method:"POST",body:JSON.stringify({events:[await Mt(e)]}),headers:{"content-type":"application/json",..._()},mode:"cors"}).catch(s=>{console.error("Failed to track: ",s)})}const Nt=t=>q({...t,canTrack:!0}),Kt=["*.beta.builder.io","beta.builder.io","builder.io","localhost","qa.builder.io"];function tt(t,e){if(!e.origin.startsWith("http")&&!e.origin.startsWith("https"))return!1;const n=new URL(e.origin),r=n.hostname;return(t||Kt).findIndex(s=>s.startsWith("*.")?r.endsWith(s.slice(1)):s===r)>-1}const jt=()=>{j("insertMenu",{name:"_default",default:!0,items:[{name:"Box"},{name:"Text"},{name:"Image"},{name:"Columns"},{name:"Core:Section"},{name:"Core:Button"},{name:"Embed"},{name:"Custom Code"}]})};let V=!1;const et=(t={})=>{var e,n;V||(V=!0,c()&&((e=window.parent)==null||e.postMessage({type:"builder.sdkInfo",data:{target:w,version:W,supportsPatchUpdates:!1,supportsAddBlockScoping:!0,supportsCustomBreakpoints:!0}},"*"),(n=window.parent)==null||n.postMessage({type:"builder.updateContent",data:{options:t}},"*"),window.addEventListener("message",r=>{var o,i;if(!tt(t.trustedHosts,r))return;const{data:s}=r;if(s!=null&&s.type)switch(s.type){case"builder.evaluate":{const u=s.data.text,S=s.data.arguments||[],m=s.data.id,k=new Function(u);let l,h=null;try{l=k.apply(null,S)}catch(g){h=g}h?(o=window.parent)==null||o.postMessage({type:"builder.evaluateError",data:{id:m,error:h.message}},"*"):l&&typeof l.then=="function"?l.then(g=>{var b;(b=window.parent)==null||b.postMessage({type:"builder.evaluateResult",data:{id:m,result:g}},"*")}).catch(console.error):(i=window.parent)==null||i.postMessage({type:"builder.evaluateResult",data:{result:l,id:m}},"*");break}}})))},nt=({model:t,trustedHosts:e,callbacks:n})=>r=>{if(!tt(e,r))return;const{data:s}=r;if(s)switch(s.type){case"builder.configureSdk":{n.configureSdk(s.data);break}case"builder.triggerAnimation":{n.animation(s.data);break}case"builder.contentUpdate":{const o=s.data,i=o.key||o.alias||o.entry||o.modelName,u=o.data;i===t&&n.contentUpdate(u);break}}},Wt=(t,e,n)=>{if(!c)return d.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server."),()=>{};et();const r=nt({callbacks:{contentUpdate:e,animation:()=>{},configureSdk:()=>{}},model:t,trustedHosts:n==null?void 0:n.trustedHosts});return window.addEventListener("message",r),()=>{window.removeEventListener("message",r)}},_t="builder.tests",C=t=>`${_t}.${t}`,$t=({contentId:t})=>G({name:C(t),canTrack:!0}),Gt=({contentId:t})=>$({name:C(t),canTrack:!0}),zt=({contentId:t,value:e})=>z({name:C(t),value:e,canTrack:!0}),rt=t=>p(t.id)&&p(t.variations)&&Object.keys(t.variations).length>0,Ht=({id:t,variations:e})=>{var s;let n=0;const r=Math.random();for(const o in e){const i=(s=e[o])==null?void 0:s.testRatio;if(n+=i,r<n)return o}return t},st=t=>{const e=Ht(t);return zt({contentId:t.id,value:e}).catch(n=>{d.error("could not store A/B test variation: ",n)}),e},ot=({item:t,testGroupId:e})=>{const n=t.variations[e];return e===t.id||!n?{testVariationId:t.id,testVariationName:"Default"}:{data:n.data,testVariationId:n.id,testVariationName:n.name||(n.id===t.id?"Default":"")}},Jt=({item:t,canTrack:e})=>{if(!e)return t;if(!t)return;if(!rt(t))return t;const n=Gt({contentId:t.id})||st({variations:t.variations,id:t.id}),r=ot({item:t,testGroupId:n});return{...t,...r}},Xt=async({item:t,canTrack:e})=>{if(!e||!rt(t))return t;const r=await $t({contentId:t.id})||st({variations:t.variations,id:t.id}),s=ot({item:t,testGroupId:r});return{...t,...s}},it=t=>p(t)?t:!0;function Qt(){return typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:globalThis}function Yt(){const t=Qt().fetch;if(typeof t=="undefined")throw console.warn(`Builder SDK could not find a global fetch function. Make sure you have a polyfill for fetch in your project.
|
|
2
|
-
For more information, read https://github.com/BuilderIO/this-package-uses-fetch`),new Error("Builder SDK could not find a global `fetch` function");return t}const Zt=Yt();function A(t,e=null,n="."){return Object.keys(t).reduce((r,s)=>{const o=t[s],i=[e,s].filter(Boolean).join(n);return[typeof o=="object",o!==null,!(Array.isArray(o)&&o.length===0)].every(Boolean)?{...r,...A(o,i,n)}:{...r,[i]:o}},{})}function at(t,e,n={}){for(const r in t){const s=t[r],o=e?e+"."+r:r;s&&typeof s=="object"&&!Array.isArray(s)&&!Object.keys(s).find(i=>i.startsWith("$"))?at(s,o,n):n[o]=s}return n}function qt(t){const e={};for(const n in t){const r=n.split(".");let s=e;for(let o=0;o<r.length;o++){const i=r[o];o===r.length-1?s[i]=t[n]:(s[i]=s[i]||{},s=s[i])}}return e}const te="v3",D=t=>typeof t=="number"&&!isNaN(t)&&t>=0,T=t=>{const{limit:e=30,userAttributes:n,query:r,model:s,apiKey:o,enrich:i,locale:u,apiVersion:S=te,fields:m,omit:k,offset:l,cacheSeconds:h,staleCacheSeconds:g,sort:b,includeUnpublished:x,apiHost:dt}=t;if(!o)throw new Error("Missing API key");if(!["v3"].includes(S))throw new Error(`Invalid apiVersion: expected 'v3', received '${S}'`);const ft=e!==1,ht=dt||"https://cdn.builder.io",a=new URL(`${ht}/api/${S}/content/${s}`);a.searchParams.set("apiKey",o),a.searchParams.set("limit",String(e)),a.searchParams.set("noTraverse",String(ft)),a.searchParams.set("includeRefs",String(!0));const E=u||(n==null?void 0:n.locale);let y=n||{};if(E&&(a.searchParams.set("locale",E),y={locale:E,...y}),i&&a.searchParams.set("enrich",String(i)),a.searchParams.set("omit",k||"meta.componentsUsed"),m&&a.searchParams.set("fields",m),Number.isFinite(l)&&l>-1&&a.searchParams.set("offset",String(Math.floor(l))),typeof x=="boolean"&&a.searchParams.set("includeUnpublished",String(x)),h&&D(h)&&a.searchParams.set("cacheSeconds",String(h)),g&&D(g)&&a.searchParams.set("staleCacheSeconds",String(g)),b){const f=A({sort:b});for(const v in f)a.searchParams.set(v,JSON.stringify(f[v]))}const B={...vt(),...M(t.options||{})};y={...y,...ne(B)};const R=A(B);for(const f in R)a.searchParams.set(f,String(R[f]));if(Object.keys(y).length>0&&a.searchParams.set("userAttributes",JSON.stringify(y)),r){const f=at({query:r});for(const v in f)a.searchParams.set(v,JSON.stringify(f[v]))}return a},ee=t=>{const e={};for(const n in t)n.startsWith("userAttributes.")&&(e[n]=t[n],delete t[n]);return e},ne=t=>{if(c()&&t.preview==="BUILDER_STUDIO"){t["userAttributes.urlPath"]=window.location.pathname,t["userAttributes.host"]=window.location.host;const e=ee(t),{userAttributes:n}=qt(e);return n}return{}},re=t=>"results"in t;async function ct(t){const e=await lt({...t,limit:1});return e&&e[0]||null}const se=async t=>{var i,u;const e=T(t),n=(i=t.fetch)!=null?i:Zt,r={...t.fetchOptions,headers:{...(u=t.fetchOptions)==null?void 0:u.headers,..._()}};return await(await n(e.href,r)).json()},ut=async(t,e,n=T(t))=>{const r=it(t.canTrack);if(n.search.includes("preview="),!r||!(c()||w==="reactNative"))return e.results;try{const s=[];for(const o of e.results)s.push(await Xt({item:o,canTrack:r}));e.results=s}catch(s){d.error("Could not process A/B tests. ",s)}return e.results};async function lt(t){const e=T(t),n=await se(t);if(!re(n))throw d.error("Error fetching data. ",{url:e,content:n,options:t}),n;return ut(t,n)}const oe=async t=>{var r,s,o;const e=t.path||((r=t.url)==null?void 0:r.pathname)||((s=t.userAttributes)==null?void 0:s.urlPath),n={...t,apiKey:t.apiKey,model:t.model||"page",userAttributes:{...t.userAttributes,...e?{urlPath:e}:{}},options:O(t.searchParams||((o=t.url)==null?void 0:o.searchParams)||t.options)};return{apiKey:n.apiKey,model:n.model,content:await ct(n)}};exports.TARGET=w;exports._processContentResult=ut;exports._track=q;exports.checkIsDefined=p;exports.createEditorListener=nt;exports.createRegisterComponentMessage=yt;exports.fetchBuilderProps=oe;exports.fetchEntries=lt;exports.fetchOneEntry=ct;exports.getBuilderSearchParams=O;exports.getDefaultCanTrack=it;exports.getUserAttributes=Z;exports.handleABTestingSync=Jt;exports.isBrowser=c;exports.isEditing=K;exports.isPreviewing=mt;exports.logFetch=Y;exports.logger=d;exports.register=j;exports.registerInsertMenu=jt;exports.serializeIncludingFunctions=P;exports.setEditorSettings=St;exports.setupBrowserForEditing=et;exports.subscribeToEditor=Wt;exports.track=Nt;
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";const w="react",v="[Builder.io]: ",d={log:(...t)=>console.log(v,...t),error:(...t)=>console.error(v,...t),warn:(...t)=>console.warn(v,...t),debug:(...t)=>console.debug(v,...t)};function c(){return typeof window!="undefined"&&typeof document!="undefined"}const gt=t=>{const e={};return t.forEach((n,r)=>{e[r]=n}),e},M=t=>t instanceof URLSearchParams?gt(t):t,N=t=>typeof t=="string"?t:t instanceof URLSearchParams?t.toString():new URLSearchParams(t).toString();function pt(){return c()&&window.self!==window.top}function K(t){return pt()&&N(t||window.location.search).indexOf("builder.frameEditing=")!==-1}const mt=()=>{if(c()){const t=new URL(location.href);return t.pathname===""&&(t.pathname="/"),t}else return console.warn("Cannot get location for tracking in non-browser environment"),null},yt=()=>typeof navigator=="object"&&navigator.userAgent||"",j=()=>{const t=yt(),e={Android(){return t.match(/Android/i)},BlackBerry(){return t.match(/BlackBerry/i)},iOS(){return t.match(/iPhone|iPod/i)},Opera(){return t.match(/Opera Mini/i)},Windows(){return t.match(/IEMobile/i)||t.match(/WPDesktop/i)},any(){return e.Android()||e.BlackBerry()||e.iOS()||e.Opera()||e.Windows()||w==="reactNative"}},n=t.match(/Tablet|iPad/i),r=mt();return{urlPath:r==null?void 0:r.pathname,host:(r==null?void 0:r.host)||(r==null?void 0:r.hostname),device:n?"tablet":e.any()?"mobile":"desktop"}},p=t=>t!=null;function wt(t){const e=t||(c()?window.location.search:void 0);return e?N(e).indexOf("builder.preview=")!==-1:!1}const St=t=>({type:"builder.registerComponent",data:A(t)}),bt=t=>{const e=t.toString().trim(),n=/^[a-zA-Z0-9_]+\s*=>/i.test(e);return`return (${!e.startsWith("function")&&!e.startsWith("async")&&!e.startsWith("(")&&!n?"function ":""}${e}).apply(this, arguments)`};function A(t){return JSON.parse(JSON.stringify(t,(e,n)=>typeof n=="function"?bt(n):n))}const U={};function W(t,e){t==="plugin"&&(e=A(e));let n=U[t];if(n||(n=U[t]=[]),n.push(e),c()){const r={type:"builder.register",data:{type:t,info:e}};try{parent.postMessage(r,"*"),parent!==window&&window.postMessage(r,"*")}catch(s){console.debug("Could not postmessage",s)}}}const L={};function It(t){if(c()){Object.assign(L,t);const e={type:"builder.settingsChange",data:L};parent.postMessage(e,"*")}}const F="builder.",vt="options.",O=t=>{if(!t)return{};const e=M(t),n={};return Object.keys(e).forEach(r=>{if(r.startsWith(F)){const s=r.replace(F,"").replace(vt,"");n[s]=e[r]}}),n},Et=()=>{if(!c())return{};const t=new URLSearchParams(window.location.search);return O(t)},_="3.0.2",G=()=>({"X-Builder-SDK":w,"X-Builder-SDK-GEN":"2","X-Builder-SDK-Version":_}),kt=t=>{if(t==="localhost"||t==="127.0.0.1")return t;const e=t.split(".");return e.length>2?e.slice(1).join("."):t},$=({name:t,canTrack:e})=>{var n;try{return e?(n=document.cookie.split("; ").find(r=>r.startsWith(`${t}=`)))==null?void 0:n.split("=")[1]:void 0}catch(r){d.warn("[COOKIE] GET error: ",(r==null?void 0:r.message)||r);return}},X=async t=>$(t),Pt=t=>t.map(([e,n])=>n?`${e}=${n}`:e).filter(p).join("; "),At=[["secure",""],["SameSite","None"]],Ot=({name:t,value:e,expires:n})=>{const s=(c()?location.protocol==="https:":!0)?At:[[]],o=n?[["expires",n.toUTCString()]]:[[]],i=[[t,e],...o,["path","/"],["domain",kt(window.location.hostname)],...s];return Pt(i)},z=async({name:t,value:e,expires:n,canTrack:r})=>{try{if(!r)return;const s=Ot({name:t,value:e,expires:n});document.cookie=s}catch(s){d.warn("[COOKIE] SET error: ",(s==null?void 0:s.message)||s)}};function Ct(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){const e=Math.random()*16|0;return(t=="x"?e:e&3|8).toString(16)})}function H(){return Ct().replace(/-/g,"")}const J="builderSessionId",Tt=async({canTrack:t})=>{if(!t)return;const e=await X({name:J,canTrack:t});if(p(e))return e;{const n=xt();return Bt({id:n,canTrack:t}),n}},xt=()=>H(),Bt=({id:t,canTrack:e})=>z({name:J,value:t,canTrack:e}),Q=()=>c()&&typeof localStorage!="undefined"?localStorage:void 0,Rt=({key:t,canTrack:e})=>{var n;try{return e?(n=Q())==null?void 0:n.getItem(t):void 0}catch(r){console.debug("[LocalStorage] GET error: ",r);return}},Ut=({key:t,canTrack:e,value:n})=>{var r;try{e&&((r=Q())==null||r.setItem(t,n))}catch(s){console.debug("[LocalStorage] SET error: ",s)}},Y="builderVisitorId",Lt=({canTrack:t})=>{if(!t)return;const e=Rt({key:Y,canTrack:t});if(p(e))return e;{const n=Ft();return Vt({id:n,canTrack:t}),n}},Ft=()=>H(),Vt=({id:t,canTrack:e})=>Ut({key:Y,value:t,canTrack:e});function Z(t){var e;typeof process!="undefined"&&((e=process.env)!=null&&e.DEBUG)&&String(process.env.DEBUG)=="true"&&d.log(t)}const Dt=async({canTrack:t})=>{if(!t)return{visitorId:void 0,sessionId:void 0};const e=await Tt({canTrack:t}),n=Lt({canTrack:t});return{sessionId:e,visitorId:n}},Mt=async({type:t,canTrack:e,apiKey:n,metadata:r,...s})=>({type:t,data:{...s,metadata:{url:location.href,...r},...await Dt({canTrack:e}),userAttributes:j(),ownerId:n}});async function q({apiHost:t,...e}){if(!e.apiKey){d.error("Missing API key for track call. Please provide your API key.");return}if(!e.canTrack||K()||!(c()||w==="reactNative"))return;const r=`${t||"https://cdn.builder.io"}/api/v1/track`;return Z(r),fetch(r,{method:"POST",body:JSON.stringify({events:[await Mt(e)]}),headers:{"content-type":"application/json",...G()},mode:"cors"}).catch(s=>{console.error("Failed to track: ",s)})}const Nt=t=>q({...t,canTrack:!0}),Kt=["*.beta.builder.io","beta.builder.io","builder.io","localhost","qa.builder.io"];function tt(t,e){if(!e.origin.startsWith("http")&&!e.origin.startsWith("https"))return!1;const n=new URL(e.origin),r=n.hostname;return(t||Kt).findIndex(s=>s.startsWith("*.")?r.endsWith(s.slice(1)):s===r)>-1}const jt=()=>{W("insertMenu",{name:"_default",default:!0,items:[{name:"Box"},{name:"Text"},{name:"Image"},{name:"Columns"},{name:"Core:Section"},{name:"Core:Button"},{name:"Embed"},{name:"Custom Code"}]})};let V=!1;const et=(t={})=>{var e,n;V||(V=!0,c()&&((e=window.parent)==null||e.postMessage({type:"builder.sdkInfo",data:{target:w,version:_,supportsPatchUpdates:!1,supportsAddBlockScoping:!0,supportsCustomBreakpoints:!0}},"*"),(n=window.parent)==null||n.postMessage({type:"builder.updateContent",data:{options:t}},"*"),window.addEventListener("message",r=>{var o,i;if(!tt(t.trustedHosts,r))return;const{data:s}=r;if(s!=null&&s.type)switch(s.type){case"builder.evaluate":{const u=s.data.text,S=s.data.arguments||[],m=s.data.id,E=new Function(u);let l,h=null;try{l=E.apply(null,S)}catch(g){h=g}h?(o=window.parent)==null||o.postMessage({type:"builder.evaluateError",data:{id:m,error:h.message}},"*"):l&&typeof l.then=="function"?l.then(g=>{var b;(b=window.parent)==null||b.postMessage({type:"builder.evaluateResult",data:{id:m,result:g}},"*")}).catch(console.error):(i=window.parent)==null||i.postMessage({type:"builder.evaluateResult",data:{result:l,id:m}},"*");break}}})))},nt=({model:t,trustedHosts:e,callbacks:n})=>r=>{if(!tt(e,r))return;const{data:s}=r;if(s)switch(s.type){case"builder.configureSdk":{n.configureSdk(s.data);break}case"builder.triggerAnimation":{n.animation(s.data);break}case"builder.contentUpdate":{const o=s.data,i=o.key||o.alias||o.entry||o.modelName,u=o.data;i===t&&n.contentUpdate(u);break}}},Wt=(t,e,n)=>{if(!c)return d.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server."),()=>{};et();const r=nt({callbacks:{contentUpdate:e,animation:()=>{},configureSdk:()=>{}},model:t,trustedHosts:n==null?void 0:n.trustedHosts});return window.addEventListener("message",r),()=>{window.removeEventListener("message",r)}},_t="builder.tests",C=t=>`${_t}.${t}`,Gt=({contentId:t})=>X({name:C(t),canTrack:!0}),$t=({contentId:t})=>$({name:C(t),canTrack:!0}),Xt=({contentId:t,value:e})=>z({name:C(t),value:e,canTrack:!0}),rt=t=>p(t.id)&&p(t.variations)&&Object.keys(t.variations).length>0,zt=({id:t,variations:e})=>{var s;let n=0;const r=Math.random();for(const o in e){const i=(s=e[o])==null?void 0:s.testRatio;if(n+=i,r<n)return o}return t},st=t=>{const e=zt(t);return Xt({contentId:t.id,value:e}).catch(n=>{d.error("could not store A/B test variation: ",n)}),e},ot=({item:t,testGroupId:e})=>{const n=t.variations[e];return e===t.id||!n?{testVariationId:t.id,testVariationName:"Default"}:{data:n.data,testVariationId:n.id,testVariationName:n.name||(n.id===t.id?"Default":"")}},Ht=({item:t,canTrack:e})=>{if(!e)return t;if(!t)return;if(!rt(t))return t;const n=$t({contentId:t.id})||st({variations:t.variations,id:t.id}),r=ot({item:t,testGroupId:n});return{...t,...r}},Jt=async({item:t,canTrack:e})=>{if(!e||!rt(t))return t;const r=await Gt({contentId:t.id})||st({variations:t.variations,id:t.id}),s=ot({item:t,testGroupId:r});return{...t,...s}},it=t=>p(t)?t:!0;function Qt(){return typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:globalThis}function Yt(){const t=Qt().fetch;if(typeof t=="undefined")throw console.warn(`Builder SDK could not find a global fetch function. Make sure you have a polyfill for fetch in your project.
|
|
2
|
-
For more information, read https://github.com/BuilderIO/this-package-uses-fetch`),new Error("Builder SDK could not find a global `fetch` function");return t}const Zt=Yt();function P(t,e=null,n="."){return Object.keys(t).reduce((r,s)=>{const o=t[s],i=[e,s].filter(Boolean).join(n);return[typeof o=="object",o!==null,!(Array.isArray(o)&&o.length===0)].every(Boolean)?{...r,...P(o,i,n)}:{...r,[i]:o}},{})}function at(t,e,n={}){for(const r in t){const s=t[r],o=e?e+"."+r:r;s&&typeof s=="object"&&!Array.isArray(s)&&!Object.keys(s).find(i=>i.startsWith("$"))?at(s,o,n):n[o]=s}return n}function qt(t){const e={};for(const n in t){const r=n.split(".");let s=e;for(let o=0;o<r.length;o++){const i=r[o];o===r.length-1?s[i]=t[n]:(s[i]=s[i]||{},s=s[i])}}return e}const te="v3",D=t=>typeof t=="number"&&!isNaN(t)&&t>=0,T=t=>{const{limit:e=30,userAttributes:n,query:r,model:s,apiKey:o,enrich:i,locale:u,apiVersion:S=te,fields:m,omit:E,offset:l,cacheSeconds:h,staleCacheSeconds:g,sort:b,includeUnpublished:x,apiHost:dt}=t;if(!o)throw new Error("Missing API key");if(!["v3"].includes(S))throw new Error(`Invalid apiVersion: expected 'v3', received '${S}'`);const ft=e!==1,ht=dt||"https://cdn.builder.io",a=new URL(`${ht}/api/${S}/content/${s}`);a.searchParams.set("apiKey",o),a.searchParams.set("limit",String(e)),a.searchParams.set("noTraverse",String(ft)),a.searchParams.set("includeRefs",String(!0));const k=u||(n==null?void 0:n.locale);let y=n||{};if(k&&(a.searchParams.set("locale",k),y={locale:k,...y}),i&&a.searchParams.set("enrich",String(i)),a.searchParams.set("omit",E||"meta.componentsUsed"),m&&a.searchParams.set("fields",m),Number.isFinite(l)&&l>-1&&a.searchParams.set("offset",String(Math.floor(l))),typeof x=="boolean"&&a.searchParams.set("includeUnpublished",String(x)),h&&D(h)&&a.searchParams.set("cacheSeconds",String(h)),g&&D(g)&&a.searchParams.set("staleCacheSeconds",String(g)),b){const f=P({sort:b});for(const I in f)a.searchParams.set(I,JSON.stringify(f[I]))}const B={...Et(),...M(t.options||{})};y={...y,...ne(B)};const R=P(B);for(const f in R)a.searchParams.set(f,String(R[f]));if(Object.keys(y).length>0&&a.searchParams.set("userAttributes",JSON.stringify(y)),r){const f=at({query:r});for(const I in f)a.searchParams.set(I,JSON.stringify(f[I]))}return a},ee=t=>{const e={};for(const n in t)n.startsWith("userAttributes.")&&(e[n]=t[n],delete t[n]);return e},ne=t=>{if(c()&&t.preview==="BUILDER_STUDIO"){t["userAttributes.urlPath"]=window.location.pathname,t["userAttributes.host"]=window.location.host;const e=ee(t),{userAttributes:n}=qt(e);return n}return{}},re=t=>"results"in t;async function ct(t){const e=await lt({...t,limit:1});return e&&e[0]||null}const se=async t=>{var i,u;const e=T(t),n=(i=t.fetch)!=null?i:Zt,r={...t.fetchOptions,headers:{...(u=t.fetchOptions)==null?void 0:u.headers,...G()}};return await(await n(e.href,r)).json()},ut=async(t,e,n=T(t))=>{const r=it(t.canTrack);if(n.search.includes("preview="),!r||!(c()||w==="reactNative"))return e.results;try{const s=[];for(const o of e.results)s.push(await Jt({item:o,canTrack:r}));e.results=s}catch(s){d.error("Could not process A/B tests. ",s)}return e.results};async function lt(t){const e=T(t),n=await se(t);if(!re(n))throw d.error("Error fetching data. ",{url:e,content:n,options:t}),n;return ut(t,n)}const oe=async t=>{var r,s,o;const e=t.path||((r=t.url)==null?void 0:r.pathname)||((s=t.userAttributes)==null?void 0:s.urlPath),n={...t,apiKey:t.apiKey,model:t.model||"page",userAttributes:{...t.userAttributes,...e?{urlPath:e}:{}},options:O(t.searchParams||((o=t.url)==null?void 0:o.searchParams)||t.options)};return{apiKey:n.apiKey,model:n.model,content:await ct(n)}};exports.MSG_PREFIX=v;exports.TARGET=w;exports._processContentResult=ut;exports._track=q;exports.checkIsDefined=p;exports.createEditorListener=nt;exports.createRegisterComponentMessage=St;exports.fetchBuilderProps=oe;exports.fetchEntries=lt;exports.fetchOneEntry=ct;exports.getBuilderSearchParams=O;exports.getDefaultCanTrack=it;exports.getUserAttributes=j;exports.handleABTestingSync=Ht;exports.isBrowser=c;exports.isEditing=K;exports.isPreviewing=wt;exports.logFetch=Z;exports.logger=d;exports.register=W;exports.registerInsertMenu=jt;exports.serializeIncludingFunctions=A;exports.setEditorSettings=It;exports.setupBrowserForEditing=et;exports.subscribeToEditor=Wt;exports.track=Nt;
|