@builder.io/sdk-react 4.2.2 → 4.2.4
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 +30 -30
- package/lib/browser/blocks-exports.mjs +676 -623
- package/lib/browser/index.cjs +1 -1
- package/lib/browser/index.mjs +1 -1
- package/lib/browser/{server-entry-074665de.js → server-entry-1c122812.js} +248 -246
- package/lib/browser/server-entry-4452b993.cjs +2 -0
- package/lib/browser/server-entry.cjs +1 -1
- package/lib/browser/server-entry.mjs +1 -1
- package/lib/edge/{accordion-0768e15a.cjs → accordion-3f30d417.cjs} +1 -1
- package/lib/edge/{accordion-d3831f48.js → accordion-48a5b362.js} +1 -1
- package/lib/edge/{blocks-2af1d7c9.cjs → blocks-3024bb2c.cjs} +14 -14
- package/lib/edge/{blocks-0269007e.js → blocks-729e6331.js} +735 -721
- package/lib/edge/blocks-exports.cjs +1 -1
- package/lib/edge/blocks-exports.mjs +2 -2
- package/lib/edge/{button-a478ff1a.js → button-36cacb47.js} +2 -2
- package/lib/edge/{button-050f4fef.cjs → button-8ab624e2.cjs} +1 -1
- package/lib/edge/{columns-25375990.cjs → columns-0d6d8b29.cjs} +1 -1
- package/lib/edge/{columns-0b3181f1.js → columns-597b4a0e.js} +3 -3
- package/lib/edge/{content-variants-0dd65b50.js → content-variants-78e04173.js} +142 -108
- package/lib/edge/{content-variants-4cab7215.cjs → content-variants-b2c99976.cjs} +3 -3
- package/lib/edge/{custom-code-f7a0f1c1.js → custom-code-0a11f81d.js} +1 -1
- package/lib/edge/{custom-code-eb5aedd2.cjs → custom-code-1d8040fe.cjs} +1 -1
- package/lib/edge/{embed-e4979560.js → embed-5b2461a4.js} +1 -1
- package/lib/edge/{embed-69114c35.cjs → embed-89e540df.cjs} +1 -1
- package/lib/edge/{form-7b4bd399.cjs → form-46264810.cjs} +1 -1
- package/lib/edge/{form-30fba682.js → form-4f5ea678.js} +3 -3
- package/lib/edge/{get-class-prop-name-f470d5ce.cjs → get-class-prop-name-a8c4e896.cjs} +1 -1
- package/lib/edge/{get-class-prop-name-770bdff2.js → get-class-prop-name-e31571bf.js} +1 -1
- package/lib/edge/image-cce92f6c.cjs +17 -0
- package/lib/edge/image-d87761af.js +123 -0
- package/lib/edge/img-194b08ce.js +33 -0
- package/lib/edge/img-821534bf.cjs +1 -0
- package/lib/edge/index.cjs +1 -1
- package/lib/edge/index.mjs +1 -1
- package/lib/edge/{input-a6caf021.cjs → input-6d65470b.cjs} +1 -1
- package/lib/edge/{input-e4a9fe0b.js → input-cfd5294a.js} +1 -1
- package/lib/edge/{personalization-container-64f3cd71.js → personalization-container-0d92ab21.js} +4 -4
- package/lib/edge/{personalization-container-f7030f08.cjs → personalization-container-74138dc4.cjs} +1 -1
- package/lib/edge/{select-c217566c.cjs → select-cec6b7d9.cjs} +1 -1
- package/lib/edge/{select-c59c9ac6.js → select-d665e4e4.js} +1 -1
- package/lib/edge/server-entry-d79ba493.cjs +2 -0
- package/lib/{node/server-entry-83d3751d.js → edge/server-entry-fec7344c.js} +307 -307
- package/lib/edge/server-entry.cjs +1 -1
- package/lib/edge/server-entry.mjs +1 -1
- package/lib/edge/{slot-ccd946e2.cjs → slot-4ad8e165.cjs} +1 -1
- package/lib/edge/{slot-26ec2911.js → slot-f2279693.js} +3 -3
- package/lib/edge/{symbol-4548e942.cjs → symbol-064c9433.cjs} +1 -1
- package/lib/edge/{symbol-10cb2f77.js → symbol-93b85799.js} +2 -2
- package/lib/edge/{tabs-f9110171.js → tabs-d87f99ab.js} +3 -3
- package/lib/edge/{tabs-82a9170c.cjs → tabs-f81e3a59.cjs} +1 -1
- package/lib/node/blocks-exports.cjs +32 -32
- package/lib/node/blocks-exports.mjs +821 -768
- package/lib/node/index.cjs +1 -1
- package/lib/node/index.mjs +3 -3
- package/lib/node/init.cjs +1 -1
- package/lib/node/init.mjs +3 -3
- package/lib/{edge/server-entry-fb5f2b80.js → node/server-entry-b75016aa.js} +346 -342
- package/lib/node/server-entry-fec6b9d9.cjs +2 -0
- package/lib/node/server-entry.cjs +1 -1
- package/lib/node/server-entry.mjs +1 -1
- package/lib/node/{setIvm-596668c3.js → setIvm-6290921a.js} +1 -1
- package/lib/node/{setIvm-0a5b2ba2.cjs → setIvm-9ebbab5f.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-5b9e373d.cjs → should-force-browser-runtime-in-node-209c023a.cjs} +1 -1
- package/lib/node/{should-force-browser-runtime-in-node-180c3315.js → should-force-browser-runtime-in-node-4ca1840a.js} +1 -1
- package/package.json +1 -1
- package/types/blocks/img/img.d.ts +2 -0
- package/types/components/block/components/live-edit-block-styles.d.ts +8 -0
- package/types/components/block/components/style-wrapper.d.ts +9 -0
- package/types/components/live-edit.d.ts +9 -0
- package/types/constants/sdk-version.d.ts +1 -1
- package/types/functions/get-builder-search-params/index.d.ts +8 -2
- package/types/functions/is-previewing.d.ts +11 -1
- package/types/helpers/find-block.d.ts +18 -0
- package/types/helpers/subscribe-to-editor.d.ts +3 -2
- package/lib/browser/server-entry-06504dba.cjs +0 -2
- package/lib/edge/image-209835f4.js +0 -94
- package/lib/edge/image-87a4e006.cjs +0 -17
- package/lib/edge/image.helpers-3e926d47.js +0 -33
- package/lib/edge/image.helpers-dba8a869.cjs +0 -1
- package/lib/edge/img-3bb375bf.js +0 -28
- package/lib/edge/img-ddf74e12.cjs +0 -1
- package/lib/edge/server-entry-67200cf1.cjs +0 -2
- package/lib/node/server-entry-d40e4b66.cjs +0 -2
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";const b="react",A="[Builder.io]: ",f={log:(...t)=>console.log(A,...t),error:(...t)=>console.error(A,...t),warn:(...t)=>console.warn(A,...t),debug:(...t)=>console.debug(A,...t)};function a(){return typeof window!="undefined"&&typeof document!="undefined"}const St=t=>{const e={};return t.forEach((r,n)=>{e[n]=r}),e},j=t=>t instanceof URLSearchParams?St(t):t,G=t=>typeof t=="string"?t:t instanceof URLSearchParams?t.toString():new URLSearchParams(t).toString();function bt(){return a()&&window.self!==window.top}function $(t){return bt()&&G(t||window.location.search).indexOf("builder.frameEditing=")!==-1}const yt=()=>{if(a()){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},mt=()=>typeof navigator=="object"&&navigator.userAgent||"",J=()=>{const t=mt(),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()||b==="reactNative"}},r=t.match(/Tablet|iPad/i),n=yt();return{urlPath:n==null?void 0:n.pathname,host:(n==null?void 0:n.host)||(n==null?void 0:n.hostname),device:r?"tablet":e.any()?"mobile":"desktop"}},S=t=>t!=null;function wt(t){const e=t||(a()?window.location.search:void 0);return e?G(e).indexOf("builder.preview=")!==-1:!1}const Et=t=>({type:"builder.registerComponent",data:U(t)}),At=t=>{const e=t.toString().trim(),r=/^[a-zA-Z0-9_]+\s*=>/i.test(e);return`return (${!e.startsWith("function")&&!e.startsWith("async")&&!e.startsWith("(")&&!r?"function ":""}${e}).apply(this, arguments)`};function U(t){return JSON.parse(JSON.stringify(t,(e,r)=>typeof r=="function"?At(r):r))}const N={};function It(t,e){t==="plugin"&&(e=U(e));let r=N[t];if(r||(r=N[t]=[]),r.push(e),a()){const n={type:"builder.register",data:{type:t,info:e}};try{parent.postMessage(n,"*"),parent!==window&&window.postMessage(n,"*")}catch(s){console.debug("Could not postmessage",s)}}}function vt(t){var e;if(a()){const r=JSON.parse(JSON.stringify(t));t.action&&(r.action=t.action.toString()),(e=window.parent)==null||e.postMessage({type:"builder.registerAction",data:r},"*")}}const V={};function kt(t){if(a()){Object.assign(V,t);const e={type:"builder.settingsChange",data:V};parent.postMessage(e,"*")}}const D="builder.",Tt="options.",O=t=>{if(!t)return{};const e=j(t),r={};return Object.keys(e).forEach(n=>{if(n.startsWith(D)){const s=n.replace(D,"").replace(Tt,"");r[s]=e[n]}}),r},Ut=()=>{if(!a())return{};const t=new URLSearchParams(window.location.search);return O(t)},z="4.2.4",X=()=>({"X-Builder-SDK":b,"X-Builder-SDK-GEN":"2","X-Builder-SDK-Version":z}),Ot=t=>{if(t==="localhost"||t==="127.0.0.1")return t;const e=t.split(".");return e.length>2?e.slice(1).join("."):t},v=({name:t,canTrack:e})=>{var r;try{return e?(r=document.cookie.split("; ").find(n=>n.startsWith(`${t}=`)))==null?void 0:r.split("=")[1]:void 0}catch(n){f.warn("[COOKIE] GET error: ",(n==null?void 0:n.message)||n);return}},H=async t=>v(t),Pt=t=>t.map(([e,r])=>r?`${e}=${r}`:e).filter(S).join("; "),Rt=[["secure",""],["SameSite","None"]],Ct=({name:t,value:e,expires:r})=>{const s=(a()?location.protocol==="https:":!0)?Rt:[[]],o=r?[["expires",r.toUTCString()]]:[[]],i=[[t,e],...o,["path","/"],["domain",Ot(window.location.hostname)],...s];return Pt(i)},P=async({name:t,value:e,expires:r,canTrack:n})=>{try{if(!n)return;const s=Ct({name:t,value:e,expires:r});document.cookie=s}catch(s){f.warn("[COOKIE] SET error: ",(s==null?void 0:s.message)||s)}};function Bt(){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 Q(){return Bt().replace(/-/g,"")}const Y="builderSessionId",_t=async({canTrack:t})=>{if(!t)return;const e=await H({name:Y,canTrack:t});if(S(e))return e;{const r=xt();return Lt({id:r,canTrack:t}),r}},xt=()=>Q(),Lt=({id:t,canTrack:e})=>P({name:Y,value:t,canTrack:e}),Z=()=>a()&&typeof localStorage!="undefined"?localStorage:void 0,Nt=({key:t,canTrack:e})=>{var r;try{return e?(r=Z())==null?void 0:r.getItem(t):void 0}catch(n){console.debug("[LocalStorage] GET error: ",n);return}},Vt=({key:t,canTrack:e,value:r})=>{var n;try{e&&((n=Z())==null||n.setItem(t,r))}catch(s){console.debug("[LocalStorage] SET error: ",s)}},q="builderVisitorId",Dt=({canTrack:t})=>{if(!t)return;const e=Nt({key:q,canTrack:t});if(S(e))return e;{const r=Ft();return Mt({id:r,canTrack:t}),r}},Ft=()=>Q(),Mt=({id:t,canTrack:e})=>Vt({key:q,value:t,canTrack:e});function tt(t){var e;typeof process!="undefined"&&((e=process.env)!=null&&e.DEBUG)&&String(process.env.DEBUG)=="true"&&f.log(t)}const Kt=async({canTrack:t})=>{if(!t)return{visitorId:void 0,sessionId:void 0};const e=await _t({canTrack:t}),r=Dt({canTrack:t});return{sessionId:e,visitorId:r}},Wt=async({type:t,canTrack:e,apiKey:r,metadata:n,...s})=>({type:t,data:{...s,metadata:{url:location.href,...n},...await Kt({canTrack:e}),userAttributes:J(),ownerId:r}});async function et({apiHost:t,...e}){if(!e.apiKey){f.error("Missing API key for track call. Please provide your API key.");return}if(!e.canTrack||$()||!(a()||b==="reactNative"))return;const n=`${t||"https://cdn.builder.io"}/api/v1/track`;return tt(n),fetch(n,{method:"POST",body:JSON.stringify({events:[await Wt(e)]}),headers:{"content-type":"application/json",...X()},mode:"cors"}).catch(s=>{console.error("Failed to track: ",s)})}const jt=t=>et({...t,canTrack:!0}),Gt=["*.beta.builder.io","beta.builder.io","builder.io","localhost","qa.builder.io"];function rt(t,e){if(!e.origin.startsWith("http")&&!e.origin.startsWith("https"))return!1;const r=new URL(e.origin),n=r.hostname;return(t||Gt).findIndex(s=>s.startsWith("*.")?n.endsWith(s.slice(1)):s===n)>-1}let F=!1;const nt=t=>{var e,r;F||(F=!0,a()&&((e=window.parent)==null||e.postMessage({type:"builder.sdkInfo",data:{target:b,version:z,supportsPatchUpdates:!1,supportsAddBlockScoping:!0,supportsCustomBreakpoints:!0,modelName:t.modelName,apiKey:t.apiKey,supportsXSmallBreakpoint:!0,blockLevelPersonalization:!0}},"*"),(r=window.parent)==null||r.postMessage({type:"builder.updateContent",data:{options:t}},"*"),window.addEventListener("message",n=>{var o,i;if(!rt(t.trustedHosts,n))return;const{data:s}=n;if(s!=null&&s.type)switch(s.type){case"builder.evaluate":{const u=s.data.text,l=s.data.arguments||[],y=s.data.id,m=new Function(u);let d,h=null;try{d=m.apply(null,l)}catch(p){h=p}h?(o=window.parent)==null||o.postMessage({type:"builder.evaluateError",data:{id:y,error:h.message}},"*"):d&&typeof d.then=="function"?d.then(p=>{var w;(w=window.parent)==null||w.postMessage({type:"builder.evaluateResult",data:{id:y,result:p}},"*")}).catch(console.error):(i=window.parent)==null||i.postMessage({type:"builder.evaluateResult",data:{result:d,id:y}},"*");break}}})))},st=({model:t,trustedHosts:e,callbacks:r})=>n=>{if(!rt(e,n))return;const{data:s}=n;if(s)switch(s.type){case"builder.configureSdk":{r.configureSdk(s.data);break}case"builder.triggerAnimation":{r.animation(s.data);break}case"builder.resetState":{const o=s.data,i=o.model,u=o==null?void 0:o.state,l=o.editType;i===t&&u&&r.stateUpdate(u,l);break}case"builder.contentUpdate":{const o=s.data,i=o.key||o.alias||o.entry||o.modelName,u=o.data,l=o.editType;i===t&&r.contentUpdate(u,l);break}}},$t=({model:t,apiKey:e,callback:r,trustedHosts:n})=>{if(!a)return f.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server."),()=>{};nt({modelName:t,apiKey:e});const s=st({callbacks:{contentUpdate:r,animation:()=>{},configureSdk:()=>{},stateUpdate:()=>{}},model:t,trustedHosts:n});return window.addEventListener("message",s),()=>{window.removeEventListener("message",s)}},Jt="builder.tests",R=t=>`${Jt}.${t}`,zt=({contentId:t})=>H({name:R(t),canTrack:!0}),Xt=({contentId:t})=>v({name:R(t),canTrack:!0}),Ht=({contentId:t,value:e})=>P({name:R(t),value:e,canTrack:!0}),ot=t=>S(t.id)&&S(t.variations)&&Object.keys(t.variations).length>0,Qt=({id:t,variations:e})=>{var s;let r=0;const n=Math.random();for(const o in e){const i=(s=e[o])==null?void 0:s.testRatio;if(r+=i,n<r)return o}return t},it=t=>{const e=Qt(t);return Ht({contentId:t.id,value:e}).catch(r=>{f.error("could not store A/B test variation: ",r)}),e},at=({item:t,testGroupId:e})=>{const r=t.variations[e];return e===t.id||!r?{testVariationId:t.id,testVariationName:"Default"}:{data:r.data,testVariationId:r.id,testVariationName:r.name||(r.id===t.id?"Default":"")}},Yt=({item:t,canTrack:e})=>{if(!e)return t;if(!t)return;if(!ot(t))return t;const r=Xt({contentId:t.id})||it({variations:t.variations,id:t.id}),n=at({item:t,testGroupId:r});return{...t,...n}},Zt=async({item:t,canTrack:e})=>{if(!e||!ot(t))return t;const n=await zt({contentId:t.id})||it({variations:t.variations,id:t.id}),s=at({item:t,testGroupId:n});return{...t,...s}};const M="builder.userAttributes";function K(){let t=!0;const e=new Set;return{setUserAttributes(r){if(!a())return;const n={...this.getUserAttributes(),...r};P({name:M,value:JSON.stringify(n),canTrack:t}),e.forEach(s=>s(n))},getUserAttributes(){return a()?JSON.parse(v({name:M,canTrack:t})||"{}"):{}},subscribeOnUserAttributesChange(r,{fireImmediately:n}={}){return e.add(r),n&&r(this.getUserAttributes()),function(){e.delete(r)}},setCanTrack(r){t=r}}}let k;a()&&b==="qwik"?(window.__BUILDER_USER_ATTRIBUTES_SERVICE__||(window.__BUILDER_USER_ATTRIBUTES_SERVICE__=K()),k=window.__BUILDER_USER_ATTRIBUTES_SERVICE__):k=K();const C=k,qt=t=>{C.setUserAttributes(t)},ct=t=>{const e=S(t)?t:!0;return C.setCanTrack(e),e};function te(){return typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:globalThis}function ee(){const t=te().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 re=ee();function T(t,e=null,r="."){return Object.keys(t).reduce((n,s)=>{const o=t[s],i=[e,s].filter(Boolean).join(r);return[typeof o=="object",o!==null,!(Array.isArray(o)&&o.length===0)].every(Boolean)?{...n,...T(o,i,r)}:{...n,[i]:o}},{})}function ut(t,e,r={}){for(const n in t){const s=t[n],o=e?e+"."+n:n;s&&typeof s=="object"&&!Array.isArray(s)&&!Object.keys(s).find(i=>i.startsWith("$"))?ut(s,o,r):r[o]=s}return r}function ne(t){const e={};for(const r in t){const n=r.split(".");let s=e;for(let o=0;o<n.length;o++){const i=n[o];o===n.length-1?s[i]=t[r]:(s[i]=s[i]||{},s=s[i])}}return e}const se="v3",W=t=>typeof t=="number"&&!isNaN(t)&&t>=0,B=t=>{const{limit:e=30,userAttributes:r,query:n,model:s,apiKey:o,enrich:i,locale:u,apiVersion:l=se,fields:y,omit:m,offset:d,cacheSeconds:h,staleCacheSeconds:p,sort:w,includeUnpublished:_,apiHost:gt}=t;if(!o)throw new Error("Missing API key");if(!["v3"].includes(l))throw new Error(`Invalid apiVersion: expected 'v3', received '${l}'`);const ht=e!==1,pt=gt||"https://cdn.builder.io",c=new URL(`${pt}/api/${l}/content/${s}`);c.searchParams.set("apiKey",o),c.searchParams.set("limit",String(e)),c.searchParams.set("noTraverse",String(ht)),c.searchParams.set("includeRefs",String(!0)),u&&c.searchParams.set("locale",u);let I=r||{};if(i&&c.searchParams.set("enrich",String(i)),c.searchParams.set("omit",m!=null?m:"meta.componentsUsed"),y&&c.searchParams.set("fields",y),Number.isFinite(d)&&d>-1&&c.searchParams.set("offset",String(Math.floor(d))),typeof _=="boolean"&&c.searchParams.set("includeUnpublished",String(_)),h&&W(h)&&c.searchParams.set("cacheSeconds",String(h)),p&&W(p)&&c.searchParams.set("staleCacheSeconds",String(p)),w){const g=T({sort:w});for(const E in g)c.searchParams.set(E,JSON.stringify(g[E]))}const x={...Ut(),...j(t.options||{})};I={...I,...ie(x)};const L=T(x);for(const g in L)c.searchParams.set(g,String(L[g]));if(Object.keys(I).length>0&&c.searchParams.set("userAttributes",JSON.stringify(I)),n){const g=ut({query:n});for(const E in g)c.searchParams.set(E,JSON.stringify(g[E]))}return c},oe=t=>{const e={};for(const r in t)r.startsWith("userAttributes.")&&(e[r]=t[r],delete t[r]);return e},ie=t=>{if(a()&&t.preview==="BUILDER_STUDIO"){t["userAttributes.urlPath"]=window.location.pathname,t["userAttributes.host"]=window.location.host;const e=oe(t),{userAttributes:r}=ne(e);return r}return{}},ae=t=>"results"in t;async function lt(t){var n;const e=t.locale||((n=t.userAttributes)==null?void 0:n.locale);e&&(t.locale=e,t.userAttributes={locale:e,...t.userAttributes});const r=await ft({...t,limit:1});return r&&r[0]||null}const ce=async t=>{var i,u;const e=B(t),r=(i=t.fetch)!=null?i:re,n={...t.fetchOptions,headers:{...(u=t.fetchOptions)==null?void 0:u.headers,...X()}};return await(await r(e.href,n)).json()},dt=async(t,e,r=B(t))=>{const n=ct(t.canTrack);if(r.search.includes("preview="),!n||!(a()||b==="reactNative"))return e.results;try{const s=[];for(const o of e.results)s.push(await Zt({item:o,canTrack:n}));e.results=s}catch(s){f.error("Could not process A/B tests. ",s)}return e.results};async function ft(t){const e=B(t),r=await ce(t);if(!ae(r))throw f.error("Error fetching data. ",{url:e,content:r,options:t}),r;return dt(t,r)}const ue=async t=>{var n,s,o;const e=t.path||((n=t.url)==null?void 0:n.pathname)||((s=t.userAttributes)==null?void 0:s.urlPath),r={...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:r.apiKey,model:r.model,content:await lt(r)}};exports.MSG_PREFIX=A;exports.TARGET=b;exports._processContentResult=dt;exports._track=et;exports.checkIsDefined=S;exports.createEditorListener=st;exports.createRegisterComponentMessage=Et;exports.fetchBuilderProps=ue;exports.fetchEntries=ft;exports.fetchOneEntry=lt;exports.getBuilderSearchParams=O;exports.getCookieSync=v;exports.getDefaultCanTrack=ct;exports.getUserAttributes=J;exports.handleABTestingSync=Yt;exports.isBrowser=a;exports.isEditing=$;exports.isPreviewing=wt;exports.logFetch=tt;exports.logger=f;exports.register=It;exports.registerAction=vt;exports.serializeIncludingFunctions=U;exports.setClientUserAttributes=qt;exports.setEditorSettings=kt;exports.setupBrowserForEditing=nt;exports.subscribeToEditor=$t;exports.track=jt;exports.userAttributesService=C;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./server-entry-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./server-entry-fec6b9d9.cjs");exports._processContentResult=e._processContentResult;exports.createRegisterComponentMessage=e.createRegisterComponentMessage;exports.fetchBuilderProps=e.fetchBuilderProps;exports.fetchEntries=e.fetchEntries;exports.fetchOneEntry=e.fetchOneEntry;exports.getBuilderSearchParams=e.getBuilderSearchParams;exports.isEditing=e.isEditing;exports.isPreviewing=e.isPreviewing;exports.register=e.register;exports.registerAction=e.registerAction;exports.setEditorSettings=e.setEditorSettings;exports.subscribeToEditor=e.subscribeToEditor;exports.track=e.track;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _processContentResult as r, createRegisterComponentMessage as i, fetchBuilderProps as s, fetchEntries as n, fetchOneEntry as o, getBuilderSearchParams as c, isEditing as g, isPreviewing as a, register as d, registerAction as E, setEditorSettings as f, subscribeToEditor as h, track as p } from "./server-entry-
|
|
1
|
+
import { _processContentResult as r, createRegisterComponentMessage as i, fetchBuilderProps as s, fetchEntries as n, fetchOneEntry as o, getBuilderSearchParams as c, isEditing as g, isPreviewing as a, register as d, registerAction as E, setEditorSettings as f, subscribeToEditor as h, track as p } from "./server-entry-b75016aa.js";
|
|
2
2
|
export {
|
|
3
3
|
r as _processContentResult,
|
|
4
4
|
i as createRegisterComponentMessage,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isEditing, isBrowser, getUserAttributes, TARGET, logger, MSG_PREFIX } from "./server-entry-
|
|
1
|
+
import { isEditing, isBrowser, getUserAttributes, TARGET, logger, MSG_PREFIX } from "./server-entry-b75016aa.js";
|
|
2
2
|
const getFunctionArguments = ({
|
|
3
3
|
builder: e,
|
|
4
4
|
context: t,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";const serverEntry=require("./server-entry-
|
|
1
|
+
"use strict";const serverEntry=require("./server-entry-fec6b9d9.cjs"),getFunctionArguments=({builder:e,context:t,event:s,state:r})=>Object.entries({state:r,Builder:e,builder:e,context:t,event:s}),getBuilderGlobals=()=>({isEditing:serverEntry.isEditing(),isBrowser:serverEntry.isBrowser(),isServer:!serverEntry.isBrowser(),getUserAttributes:()=>serverEntry.getUserAttributes()}),parseCode=(e,{isExpression:t=!0})=>t&&!(e.includes(";")||e.includes(" return ")||e.trim().startsWith("return "))?`return (${e});`:e;function flattenState({rootState:e,localState:t,rootSetState:s}){return new Proxy(e,{get:(r,n)=>{if(t&&n in t)return t[n];const o=r[n];return typeof o=="object"&&o!==null?flattenState({rootState:o,localState:void 0,rootSetState:s?i=>{r[n]=i,s(r)}:void 0}):o},set:(r,n,o)=>{if(t&&n in t)throw new Error("Writing to local state is not allowed as it is read-only.");return r[n]=o,s==null||s(r),!0}})}const SDK_NAME_FOR_TARGET=(()=>{switch(serverEntry.TARGET){case"rsc":return"react-nextjs";case"reactNative":return"react-native";default:return serverEntry.TARGET}})(),SDK_NAME=`@builder.io/sdk-${SDK_NAME_FOR_TARGET}`,fastClone=e=>JSON.parse(JSON.stringify(e)),set=(e,t,s)=>{if(Object(e)!==e)return e;const r=Array.isArray(t)?t:t.toString().match(/[^.[\]]+/g);return r.slice(0,-1).reduce((n,o,i)=>Object(n[o])===n[o]?n[o]:n[o]=Math.abs(Number(r[i+1]))>>0===+r[i+1]?[]:{},e)[r[r.length-1]]=s,e},noop=()=>{};let safeDynamicRequire=noop;try{safeDynamicRequire=eval("require")}catch(e){}const getSyncValName=e=>`bldr_${e}_sync`,BUILDER_SET_STATE_NAME="BUILDER_SET_STATE",INJECTED_IVM_GLOBAL="BUILDER_IVM",REF_TO_PROXY_FN=`
|
|
2
2
|
var refToProxy = (obj) => {
|
|
3
3
|
if (typeof obj !== 'object' || obj === null) {
|
|
4
4
|
return obj;
|
package/lib/node/setIvm.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./setIvm-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./setIvm-9ebbab5f.cjs");require("./server-entry-fec6b9d9.cjs");exports.setIvm=e.setIvm;
|
package/lib/node/setIvm.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const s=require("./server-entry-
|
|
1
|
+
"use strict";const s=require("./server-entry-fec6b9d9.cjs");function t(){var e;return typeof process!="undefined"&&s.checkIsDefined((e=process==null?void 0:process.versions)==null?void 0:e.node)}const c=({shouldLogWarning:e})=>{var o;if(!t())return!1;const n=process.arch==="arm64",r=process.version.startsWith("v20"),i=(o=process.env.NODE_OPTIONS)==null?void 0:o.includes("--no-node-snapshot");return n&&r&&!i?(e&&s.logger.log("Skipping usage of `isolated-vm` to avoid crashes in Node v20 on an arm64 machine.\n If you would like to use the `isolated-vm` package on this machine, please provide the `NODE_OPTIONS=--no-node-snapshot` config to your Node process.\n See https://github.com/BuilderIO/builder/blob/main/packages/sdks/README.md#node-v20--m1-macs-apple-silicon-support for more information.\n "),!0):!1};exports.shouldForceBrowserRuntimeInNode=c;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { checkIsDefined as i, logger as t } from "./server-entry-
|
|
1
|
+
import { checkIsDefined as i, logger as t } from "./server-entry-b75016aa.js";
|
|
2
2
|
function a() {
|
|
3
3
|
var o;
|
|
4
4
|
return typeof process != "undefined" && i((o = process == null ? void 0 : process.versions) == null ? void 0 : o.node);
|
package/package.json
CHANGED
|
@@ -9,6 +9,8 @@ export interface ImgProps {
|
|
|
9
9
|
altText?: string;
|
|
10
10
|
backgroundSize?: "cover" | "contain";
|
|
11
11
|
backgroundPosition?: "center" | "top" | "left" | "right" | "bottom" | "top left" | "top right" | "bottom left" | "bottom right";
|
|
12
|
+
aspectRatio?: number;
|
|
13
|
+
title?: string;
|
|
12
14
|
}
|
|
13
15
|
declare function ImgComponent(props: ImgProps): React.JSX.Element;
|
|
14
16
|
export default ImgComponent;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
type LiveEditBlockStylesProps = {
|
|
3
|
+
id?: any;
|
|
4
|
+
contextProvider: BuilderContextInterface;
|
|
5
|
+
};
|
|
6
|
+
import type { BuilderContextInterface } from "../../../server-index";
|
|
7
|
+
declare function LiveEditBlockStyles(props: LiveEditBlockStylesProps): React.JSX.Element;
|
|
8
|
+
export default LiveEditBlockStyles;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
type StyleWrapperProps = {
|
|
3
|
+
block: BuilderBlock;
|
|
4
|
+
context: BuilderContextInterface;
|
|
5
|
+
id?: string;
|
|
6
|
+
};
|
|
7
|
+
import { BuilderBlock, BuilderContextInterface } from "../../../server-index";
|
|
8
|
+
declare function StyleWrapper(props: StyleWrapperProps): React.JSX.Element;
|
|
9
|
+
export default StyleWrapper;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "4.2.
|
|
1
|
+
export declare const SDK_VERSION = "4.2.4";
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import type { QueryObject } from '../../helpers/search/search';
|
|
2
2
|
/**
|
|
3
|
-
* Receives a `URLSearchParams` object or a regular query object, and returns
|
|
4
|
-
* relevant to the Builder SDK.
|
|
3
|
+
* Receives a `URLSearchParams` object or a regular query object, and returns
|
|
4
|
+
* the subset of query params that are relevant to the Builder SDK.
|
|
5
|
+
*
|
|
6
|
+
* Outputs a key-value object to be passed to `fetchOneEntry` or `fetchEntries`
|
|
7
|
+
* functions as the `options` argument.
|
|
8
|
+
*
|
|
9
|
+
* NOTE: This function is generally not needed. Instead, it is recommended to use `isPreviewing()`
|
|
10
|
+
* to check if the current page requires previewed content.
|
|
5
11
|
*
|
|
6
12
|
* @returns
|
|
7
13
|
*/
|
|
@@ -1,2 +1,12 @@
|
|
|
1
1
|
import type { Search } from '../helpers/search/search';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Checks the current URL's search parameters to see if it is attempting to
|
|
4
|
+
* preview Builder Content.
|
|
5
|
+
*
|
|
6
|
+
* When called on the client, it uses `window.location.search`.
|
|
7
|
+
* When called on the server (SSR), it requires a `search` argument.
|
|
8
|
+
*
|
|
9
|
+
* @param search - The search parameters to check. Can be a URL string (containing the search parameters), `URLSearchParams`, or a key-value object containing the search parameters.
|
|
10
|
+
* @returns `true` if the current page is being previewed, `false` otherwise.
|
|
11
|
+
*/
|
|
12
|
+
export declare function isPreviewing(search?: Search): boolean;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { BuilderBlock, BuilderContent } from '../server-index';
|
|
2
|
+
/**
|
|
3
|
+
* Recursively searches for a block by ID.
|
|
4
|
+
*
|
|
5
|
+
* @param content The Builder content to search through.
|
|
6
|
+
* @param id The ID of the block to search for.
|
|
7
|
+
* @returns The block if found, otherwise null.
|
|
8
|
+
*/
|
|
9
|
+
export declare const findBlockById: (content: BuilderContent, id: string) => BuilderBlock | null;
|
|
10
|
+
/**
|
|
11
|
+
* Helper function to recursively search through block tree.
|
|
12
|
+
*
|
|
13
|
+
* @param blocks The blocks to search through.
|
|
14
|
+
* @param id The ID of the block to search for.
|
|
15
|
+
* @returns The block if found, otherwise null.
|
|
16
|
+
* @private This is an internal implementation detail.
|
|
17
|
+
*/
|
|
18
|
+
export declare const findBlockInTree: (blocks: BuilderBlock[] | undefined, id: string) => BuilderBlock | null;
|
|
@@ -2,10 +2,11 @@ import type { ContentProps } from '../components/content/content.types';
|
|
|
2
2
|
import type { BuilderAnimation } from '../types/builder-block';
|
|
3
3
|
import type { BuilderContent } from '../types/builder-content';
|
|
4
4
|
import type { Dictionary } from '../types/typescript';
|
|
5
|
+
export type EditType = 'client' | 'server' | undefined;
|
|
5
6
|
type ContentListener = Required<Pick<ContentProps, 'model' | 'trustedHosts'>> & {
|
|
6
7
|
callbacks: {
|
|
7
|
-
contentUpdate: (updatedContent: BuilderContent) => void;
|
|
8
|
-
stateUpdate: (newState: Dictionary<string
|
|
8
|
+
contentUpdate: (updatedContent: BuilderContent, editType?: EditType) => void;
|
|
9
|
+
stateUpdate: (newState: Dictionary<string>, editType?: EditType) => void;
|
|
9
10
|
animation: (updatedContent: BuilderAnimation) => void;
|
|
10
11
|
configureSdk: (updatedContent: any) => void;
|
|
11
12
|
};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";const S="react",A="[Builder.io]: ",d={log:(...t)=>console.log(A,...t),error:(...t)=>console.error(A,...t),warn:(...t)=>console.warn(A,...t),debug:(...t)=>console.debug(A,...t)};function a(){return typeof window!="undefined"&&typeof document!="undefined"}const yt=t=>{const e={};return t.forEach((n,r)=>{e[r]=n}),e},$=t=>t instanceof URLSearchParams?yt(t):t,G=t=>typeof t=="string"?t:t instanceof URLSearchParams?t.toString():new URLSearchParams(t).toString();function bt(){return a()&&window.self!==window.top}function J(t){return bt()&&G(t||window.location.search).indexOf("builder.frameEditing=")!==-1}const mt=()=>{if(a()){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},wt=()=>typeof navigator=="object"&&navigator.userAgent||"",z=()=>{const t=wt(),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()||S==="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 Et(t){const e=t||(a()?window.location.search:void 0);return e?G(e).indexOf("builder.preview=")!==-1:!1}const It=t=>({type:"builder.registerComponent",data:O(t)}),At=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 O(t){return JSON.parse(JSON.stringify(t,(e,n)=>typeof n=="function"?At(n):n))}const V={};function vt(t,e){t==="plugin"&&(e=O(e));let n=V[t];if(n||(n=V[t]=[]),n.push(e),a()){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)}}}function kt(t){var e;if(a()){const n=JSON.parse(JSON.stringify(t));t.action&&(n.action=t.action.toString()),(e=window.parent)==null||e.postMessage({type:"builder.registerAction",data:n},"*")}}const D={};function Ut(t){if(a()){Object.assign(D,t);const e={type:"builder.settingsChange",data:D};parent.postMessage(e,"*")}}const F="builder.",Tt="options.",P=t=>{if(!t)return{};const e=$(t),n={};return Object.keys(e).forEach(r=>{if(r.startsWith(F)){const s=r.replace(F,"").replace(Tt,"");n[s]=e[r]}}),n},Ot=()=>{if(!a())return{};const t=new URLSearchParams(window.location.search);return P(t)},X="4.2.2",H=()=>({"X-Builder-SDK":S,"X-Builder-SDK-GEN":"2","X-Builder-SDK-Version":X}),Pt=t=>{if(t==="localhost"||t==="127.0.0.1")return t;const e=t.split(".");return e.length>2?e.slice(1).join("."):t},v=({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}},Q=async t=>v(t),Rt=t=>t.map(([e,n])=>n?`${e}=${n}`:e).filter(p).join("; "),Ct=[["secure",""],["SameSite","None"]],Bt=({name:t,value:e,expires:n})=>{const s=(a()?location.protocol==="https:":!0)?Ct:[[]],o=n?[["expires",n.toUTCString()]]:[[]],i=[[t,e],...o,["path","/"],["domain",Pt(window.location.hostname)],...s];return Rt(i)},R=async({name:t,value:e,expires:n,canTrack:r})=>{try{if(!r)return;const s=Bt({name:t,value:e,expires:n});document.cookie=s}catch(s){d.warn("[COOKIE] SET error: ",(s==null?void 0:s.message)||s)}};function xt(){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 Y(){return xt().replace(/-/g,"")}const Z="builderSessionId",_t=async({canTrack:t})=>{if(!t)return;const e=await Q({name:Z,canTrack:t});if(p(e))return e;{const n=Lt();return Nt({id:n,canTrack:t}),n}},Lt=()=>Y(),Nt=({id:t,canTrack:e})=>R({name:Z,value:t,canTrack:e}),q=()=>a()&&typeof localStorage!="undefined"?localStorage:void 0,Vt=({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}},Dt=({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)}},tt="builderVisitorId",Ft=({canTrack:t})=>{if(!t)return;const e=Vt({key:tt,canTrack:t});if(p(e))return e;{const n=Mt();return Kt({id:n,canTrack:t}),n}},Mt=()=>Y(),Kt=({id:t,canTrack:e})=>Dt({key:tt,value:t,canTrack:e});function et(t){var e;typeof process!="undefined"&&((e=process.env)!=null&&e.DEBUG)&&String(process.env.DEBUG)=="true"&&d.log(t)}const Wt=async({canTrack:t})=>{if(!t)return{visitorId:void 0,sessionId:void 0};const e=await _t({canTrack:t}),n=Ft({canTrack:t});return{sessionId:e,visitorId:n}},jt=async({type:t,canTrack:e,apiKey:n,metadata:r,...s})=>({type:t,data:{...s,metadata:{url:location.href,...r},...await Wt({canTrack:e}),userAttributes:z(),ownerId:n}});async function nt({apiHost:t,...e}){if(!e.apiKey){d.error("Missing API key for track call. Please provide your API key.");return}if(!e.canTrack||J()||!(a()||S==="reactNative"))return;const r=`${t||"https://cdn.builder.io"}/api/v1/track`;return et(r),fetch(r,{method:"POST",body:JSON.stringify({events:[await jt(e)]}),headers:{"content-type":"application/json",...H()},mode:"cors"}).catch(s=>{console.error("Failed to track: ",s)})}const $t=t=>nt({...t,canTrack:!0}),Gt=["*.beta.builder.io","beta.builder.io","builder.io","localhost","qa.builder.io"];function rt(t,e){if(!e.origin.startsWith("http")&&!e.origin.startsWith("https"))return!1;const n=new URL(e.origin),r=n.hostname;return(t||Gt).findIndex(s=>s.startsWith("*.")?r.endsWith(s.slice(1)):s===r)>-1}let M=!1;const st=t=>{var e,n;M||(M=!0,a()&&((e=window.parent)==null||e.postMessage({type:"builder.sdkInfo",data:{target:S,version:X,supportsPatchUpdates:!1,supportsAddBlockScoping:!0,supportsCustomBreakpoints:!0,modelName:t.modelName,apiKey:t.apiKey,supportsXSmallBreakpoint:!0,blockLevelPersonalization:!0}},"*"),(n=window.parent)==null||n.postMessage({type:"builder.updateContent",data:{options:t}},"*"),window.addEventListener("message",r=>{var o,i;if(!rt(t.trustedHosts,r))return;const{data:s}=r;if(s!=null&&s.type)switch(s.type){case"builder.evaluate":{const u=s.data.text,m=s.data.arguments||[],y=s.data.id,w=new Function(u);let l,g=null;try{l=w.apply(null,m)}catch(h){g=h}g?(o=window.parent)==null||o.postMessage({type:"builder.evaluateError",data:{id:y,error:g.message}},"*"):l&&typeof l.then=="function"?l.then(h=>{var E;(E=window.parent)==null||E.postMessage({type:"builder.evaluateResult",data:{id:y,result:h}},"*")}).catch(console.error):(i=window.parent)==null||i.postMessage({type:"builder.evaluateResult",data:{result:l,id:y}},"*");break}}})))},ot=({model:t,trustedHosts:e,callbacks:n})=>r=>{if(!rt(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.resetState":{const o=s.data,i=o.model,u=o==null?void 0:o.state;i===t&&u&&n.stateUpdate(u);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}}},Jt=({model:t,apiKey:e,callback:n,trustedHosts:r})=>{if(!a)return d.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server."),()=>{};st({modelName:t,apiKey:e});const s=ot({callbacks:{contentUpdate:n,animation:()=>{},configureSdk:()=>{},stateUpdate:()=>{}},model:t,trustedHosts:r});return window.addEventListener("message",s),()=>{window.removeEventListener("message",s)}},zt="builder.tests",C=t=>`${zt}.${t}`,Xt=({contentId:t})=>Q({name:C(t),canTrack:!0}),Ht=({contentId:t})=>v({name:C(t),canTrack:!0}),Qt=({contentId:t,value:e})=>R({name:C(t),value:e,canTrack:!0}),it=t=>p(t.id)&&p(t.variations)&&Object.keys(t.variations).length>0,Yt=({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},at=t=>{const e=Yt(t);return Qt({contentId:t.id,value:e}).catch(n=>{d.error("could not store A/B test variation: ",n)}),e},ct=({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":"")}},Zt=({item:t,canTrack:e})=>{if(!e)return t;if(!t)return;if(!it(t))return t;const n=Ht({contentId:t.id})||at({variations:t.variations,id:t.id}),r=ct({item:t,testGroupId:n});return{...t,...r}},qt=async({item:t,canTrack:e})=>{if(!e||!it(t))return t;const r=await Xt({contentId:t.id})||at({variations:t.variations,id:t.id}),s=ct({item:t,testGroupId:r});return{...t,...s}};const K="builder.userAttributes";function W(){let t=!0;const e=new Set;return{setUserAttributes(n){if(!a())return;const r={...this.getUserAttributes(),...n};R({name:K,value:JSON.stringify(r),canTrack:t}),e.forEach(s=>s(r))},getUserAttributes(){return a()?JSON.parse(v({name:K,canTrack:t})||"{}"):{}},subscribeOnUserAttributesChange(n,{fireImmediately:r}={}){return e.add(n),r&&n(this.getUserAttributes()),function(){e.delete(n)}},setCanTrack(n){t=n}}}let U;a()&&S==="qwik"?(window.__BUILDER_USER_ATTRIBUTES_SERVICE__||(window.__BUILDER_USER_ATTRIBUTES_SERVICE__=W()),U=window.__BUILDER_USER_ATTRIBUTES_SERVICE__):U=W();const B=U,te=t=>{B.setUserAttributes(t)},ut=t=>{const e=p(t)?t:!0;return B.setCanTrack(e),e};function ee(){return typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:globalThis}function ne(){const t=ee().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 re=ne();function T(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,...T(o,i,n)}:{...r,[i]:o}},{})}function lt(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("$"))?lt(s,o,n):n[o]=s}return n}function se(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 oe="v3",j=t=>typeof t=="number"&&!isNaN(t)&&t>=0,x=t=>{const{limit:e=30,userAttributes:n,query:r,model:s,apiKey:o,enrich:i,locale:u,apiVersion:m=oe,fields:y,omit:w,offset:l,cacheSeconds:g,staleCacheSeconds:h,sort:E,includeUnpublished:_,apiHost:ht}=t;if(!o)throw new Error("Missing API key");if(!["v3"].includes(m))throw new Error(`Invalid apiVersion: expected 'v3', received '${m}'`);const pt=e!==1,St=ht||"https://cdn.builder.io",c=new URL(`${St}/api/${m}/content/${s}`);c.searchParams.set("apiKey",o),c.searchParams.set("limit",String(e)),c.searchParams.set("noTraverse",String(pt)),c.searchParams.set("includeRefs",String(!0));const k=u||(n==null?void 0:n.locale);let b=n||{};if(k&&(c.searchParams.set("locale",k),b={locale:k,...b}),i&&c.searchParams.set("enrich",String(i)),c.searchParams.set("omit",w!=null?w:"meta.componentsUsed"),y&&c.searchParams.set("fields",y),Number.isFinite(l)&&l>-1&&c.searchParams.set("offset",String(Math.floor(l))),typeof _=="boolean"&&c.searchParams.set("includeUnpublished",String(_)),g&&j(g)&&c.searchParams.set("cacheSeconds",String(g)),h&&j(h)&&c.searchParams.set("staleCacheSeconds",String(h)),E){const f=T({sort:E});for(const I in f)c.searchParams.set(I,JSON.stringify(f[I]))}const L={...Ot(),...$(t.options||{})};b={...b,...ae(L)};const N=T(L);for(const f in N)c.searchParams.set(f,String(N[f]));if(Object.keys(b).length>0&&c.searchParams.set("userAttributes",JSON.stringify(b)),r){const f=lt({query:r});for(const I in f)c.searchParams.set(I,JSON.stringify(f[I]))}return c},ie=t=>{const e={};for(const n in t)n.startsWith("userAttributes.")&&(e[n]=t[n],delete t[n]);return e},ae=t=>{if(a()&&t.preview==="BUILDER_STUDIO"){t["userAttributes.urlPath"]=window.location.pathname,t["userAttributes.host"]=window.location.host;const e=ie(t),{userAttributes:n}=se(e);return n}return{}},ce=t=>"results"in t;async function dt(t){const e=await gt({...t,limit:1});return e&&e[0]||null}const ue=async t=>{var i,u;const e=x(t),n=(i=t.fetch)!=null?i:re,r={...t.fetchOptions,headers:{...(u=t.fetchOptions)==null?void 0:u.headers,...H()}};return await(await n(e.href,r)).json()},ft=async(t,e,n=x(t))=>{const r=ut(t.canTrack);if(n.search.includes("preview="),!r||!(a()||S==="reactNative"))return e.results;try{const s=[];for(const o of e.results)s.push(await qt({item:o,canTrack:r}));e.results=s}catch(s){d.error("Could not process A/B tests. ",s)}return e.results};async function gt(t){const e=x(t),n=await ue(t);if(!ce(n))throw d.error("Error fetching data. ",{url:e,content:n,options:t}),n;return ft(t,n)}const le=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:P(t.searchParams||((o=t.url)==null?void 0:o.searchParams)||t.options)};return{apiKey:n.apiKey,model:n.model,content:await dt(n)}};exports.TARGET=S;exports._processContentResult=ft;exports._track=nt;exports.checkIsDefined=p;exports.createEditorListener=ot;exports.createRegisterComponentMessage=It;exports.fetchBuilderProps=le;exports.fetchEntries=gt;exports.fetchOneEntry=dt;exports.getBuilderSearchParams=P;exports.getCookieSync=v;exports.getDefaultCanTrack=ut;exports.getUserAttributes=z;exports.handleABTestingSync=Zt;exports.isBrowser=a;exports.isEditing=J;exports.isPreviewing=Et;exports.logFetch=et;exports.logger=d;exports.register=vt;exports.registerAction=kt;exports.serializeIncludingFunctions=O;exports.setClientUserAttributes=te;exports.setEditorSettings=Ut;exports.setupBrowserForEditing=st;exports.subscribeToEditor=Jt;exports.track=$t;exports.userAttributesService=B;
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { jsxs as l, Fragment as a, jsx as t } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect as v } from "react";
|
|
3
|
-
import { getSrcSet as d } from "./image.helpers-3e926d47.js";
|
|
4
|
-
function w(e) {
|
|
5
|
-
var r, u, s, g, m, h;
|
|
6
|
-
function c() {
|
|
7
|
-
var f;
|
|
8
|
-
const i = e.image || e.src;
|
|
9
|
-
if (!i || // We can auto add srcset for cdn.builder.io and shopify
|
|
10
|
-
// images, otherwise you can supply this prop manually
|
|
11
|
-
!(typeof i == "string" && (i.match(/builder\.io/) || i.match(/cdn\.shopify\.com/))))
|
|
12
|
-
return e.srcset;
|
|
13
|
-
if (!e.noWebp) {
|
|
14
|
-
if (e.srcset && ((f = e.image) != null && f.includes("builder.io/api/v1/image"))) {
|
|
15
|
-
if (!e.srcset.includes(e.image.split("?")[0]))
|
|
16
|
-
return console.debug("Removed given srcset"), d(i);
|
|
17
|
-
} else if (e.image && !e.srcset)
|
|
18
|
-
return d(i);
|
|
19
|
-
return d(i);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
function o() {
|
|
23
|
-
var n;
|
|
24
|
-
return (n = c == null ? void 0 : c()) != null && n.match(/builder\.io/) && !e.noWebp ? c().replace(/\?/g, "?format=webp&") : "";
|
|
25
|
-
}
|
|
26
|
-
function b() {
|
|
27
|
-
const n = {
|
|
28
|
-
position: "absolute",
|
|
29
|
-
height: "100%",
|
|
30
|
-
width: "100%",
|
|
31
|
-
left: "0px",
|
|
32
|
-
top: "0px"
|
|
33
|
-
};
|
|
34
|
-
return e.aspectRatio ? n : void 0;
|
|
35
|
-
}
|
|
36
|
-
return v(() => {
|
|
37
|
-
}, []), /* @__PURE__ */ l(a, { children: [
|
|
38
|
-
/* @__PURE__ */ t("style", { children: `.img-3cc22d08 {
|
|
39
|
-
opacity: 1;
|
|
40
|
-
transition: opacity 0.2s ease-in-out;
|
|
41
|
-
}.div-3cc22d08 {
|
|
42
|
-
width: 100%;
|
|
43
|
-
pointer-events: none;
|
|
44
|
-
font-size: 0;
|
|
45
|
-
}.div-3cc22d08-2 {
|
|
46
|
-
display: flex;
|
|
47
|
-
flex-direction: column;
|
|
48
|
-
align-items: stretch;
|
|
49
|
-
position: absolute;
|
|
50
|
-
top: 0;
|
|
51
|
-
left: 0;
|
|
52
|
-
width: 100%;
|
|
53
|
-
height: 100%;
|
|
54
|
-
}` }),
|
|
55
|
-
/* @__PURE__ */ l(a, { children: [
|
|
56
|
-
/* @__PURE__ */ l("picture", { children: [
|
|
57
|
-
o() ? /* @__PURE__ */ t("source", { type: "image/webp", srcSet: o() }) : null,
|
|
58
|
-
/* @__PURE__ */ t(
|
|
59
|
-
"img",
|
|
60
|
-
{
|
|
61
|
-
loading: e.highPriority ? "eager" : "lazy",
|
|
62
|
-
fetchPriority: e.highPriority ? "high" : "auto",
|
|
63
|
-
alt: e.altText,
|
|
64
|
-
title: e.title,
|
|
65
|
-
role: e.altText ? void 0 : "presentation",
|
|
66
|
-
style: {
|
|
67
|
-
objectPosition: e.backgroundPosition || "center",
|
|
68
|
-
objectFit: e.backgroundSize || "cover",
|
|
69
|
-
...b()
|
|
70
|
-
},
|
|
71
|
-
className: "builder-image" + (e.className ? " " + e.className : "") + " img-3cc22d08",
|
|
72
|
-
src: e.image,
|
|
73
|
-
srcSet: c(),
|
|
74
|
-
sizes: e.sizes
|
|
75
|
-
}
|
|
76
|
-
)
|
|
77
|
-
] }),
|
|
78
|
-
e.aspectRatio && !((u = (r = e.builderBlock) == null ? void 0 : r.children) != null && u.length && e.fitContent) ? /* @__PURE__ */ t(
|
|
79
|
-
"div",
|
|
80
|
-
{
|
|
81
|
-
className: "builder-image-sizer div-3cc22d08",
|
|
82
|
-
style: {
|
|
83
|
-
paddingTop: e.aspectRatio * 100 + "%"
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
) : null,
|
|
87
|
-
(g = (s = e.builderBlock) == null ? void 0 : s.children) != null && g.length && e.fitContent ? /* @__PURE__ */ t(a, { children: e.children }) : null,
|
|
88
|
-
!e.fitContent && ((h = (m = e.builderBlock) == null ? void 0 : m.children) != null && h.length) ? /* @__PURE__ */ t("div", { className: "div-3cc22d08-2", children: e.children }) : null
|
|
89
|
-
] })
|
|
90
|
-
] });
|
|
91
|
-
}
|
|
92
|
-
export {
|
|
93
|
-
w as default
|
|
94
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),f=require("react"),l=require("./image.helpers-dba8a869.cjs");function b(e){var s,r,d,u,o,g;function c(){var h;const i=e.image||e.src;if(!i||!(typeof i=="string"&&(i.match(/builder\.io/)||i.match(/cdn\.shopify\.com/))))return e.srcset;if(!e.noWebp){if(e.srcset&&((h=e.image)!=null&&h.includes("builder.io/api/v1/image"))){if(!e.srcset.includes(e.image.split("?")[0]))return console.debug("Removed given srcset"),l.getSrcSet(i)}else if(e.image&&!e.srcset)return l.getSrcSet(i);return l.getSrcSet(i)}}function a(){var n;return(n=c==null?void 0:c())!=null&&n.match(/builder\.io/)&&!e.noWebp?c().replace(/\?/g,"?format=webp&"):""}function m(){const n={position:"absolute",height:"100%",width:"100%",left:"0px",top:"0px"};return e.aspectRatio?n:void 0}return f.useEffect(()=>{},[]),t.jsxs(t.Fragment,{children:[t.jsx("style",{children:`.img-3cc22d08 {
|
|
2
|
-
opacity: 1;
|
|
3
|
-
transition: opacity 0.2s ease-in-out;
|
|
4
|
-
}.div-3cc22d08 {
|
|
5
|
-
width: 100%;
|
|
6
|
-
pointer-events: none;
|
|
7
|
-
font-size: 0;
|
|
8
|
-
}.div-3cc22d08-2 {
|
|
9
|
-
display: flex;
|
|
10
|
-
flex-direction: column;
|
|
11
|
-
align-items: stretch;
|
|
12
|
-
position: absolute;
|
|
13
|
-
top: 0;
|
|
14
|
-
left: 0;
|
|
15
|
-
width: 100%;
|
|
16
|
-
height: 100%;
|
|
17
|
-
}`}),t.jsxs(t.Fragment,{children:[t.jsxs("picture",{children:[a()?t.jsx("source",{type:"image/webp",srcSet:a()}):null,t.jsx("img",{loading:e.highPriority?"eager":"lazy",fetchPriority:e.highPriority?"high":"auto",alt:e.altText,title:e.title,role:e.altText?void 0:"presentation",style:{objectPosition:e.backgroundPosition||"center",objectFit:e.backgroundSize||"cover",...m()},className:"builder-image"+(e.className?" "+e.className:"")+" img-3cc22d08",src:e.image,srcSet:c(),sizes:e.sizes})]}),e.aspectRatio&&!((r=(s=e.builderBlock)==null?void 0:s.children)!=null&&r.length&&e.fitContent)?t.jsx("div",{className:"builder-image-sizer div-3cc22d08",style:{paddingTop:e.aspectRatio*100+"%"}}):null,(u=(d=e.builderBlock)==null?void 0:d.children)!=null&&u.length&&e.fitContent?t.jsx(t.Fragment,{children:e.children}):null,!e.fitContent&&((g=(o=e.builderBlock)==null?void 0:o.children)!=null&&g.length)?t.jsx("div",{className:"div-3cc22d08-2",children:e.children}):null]})]})}exports.default=b;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
function c(t) {
|
|
2
|
-
return t.replace(/http(s)?:/, "");
|
|
3
|
-
}
|
|
4
|
-
function p(t = "", e, n) {
|
|
5
|
-
const o = new RegExp("([?&])" + e + "=.*?(&|$)", "i"), i = t.indexOf("?") !== -1 ? "&" : "?";
|
|
6
|
-
return t.match(o) ? t.replace(o, "$1" + e + "=" + encodeURIComponent(n) + "$2") : t + i + e + "=" + encodeURIComponent(n);
|
|
7
|
-
}
|
|
8
|
-
function a(t, e) {
|
|
9
|
-
if (!t || !(t != null && t.match(/cdn\.shopify\.com/)) || !e)
|
|
10
|
-
return t;
|
|
11
|
-
if (e === "master")
|
|
12
|
-
return c(t);
|
|
13
|
-
const n = t.match(/(_\d+x(\d+)?)?(\.(jpg|jpeg|gif|png|bmp|bitmap|tiff|tif)(\?v=\d+)?)/i);
|
|
14
|
-
if (n) {
|
|
15
|
-
const o = t.split(n[0]), i = n[3], f = e.match("x") ? e : `${e}x`;
|
|
16
|
-
return c(`${o[0]}_${f}${i}`);
|
|
17
|
-
}
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
function r(t) {
|
|
21
|
-
if (!t)
|
|
22
|
-
return t;
|
|
23
|
-
const e = [100, 200, 400, 800, 1200, 1600, 2e3];
|
|
24
|
-
if (t.match(/builder\.io/)) {
|
|
25
|
-
let n = t;
|
|
26
|
-
const o = Number(t.split("?width=")[1]);
|
|
27
|
-
return isNaN(o) || (n = `${n} ${o}w`), e.filter((i) => i !== o).map((i) => `${p(t, "width", i)} ${i}w`).concat([n]).join(", ");
|
|
28
|
-
}
|
|
29
|
-
return t.match(/cdn\.shopify\.com/) ? e.map((n) => [a(t, `${n}x${n}`), n]).filter(([n]) => !!n).map(([n, o]) => `${n} ${o}w`).concat([t]).join(", ") : t;
|
|
30
|
-
}
|
|
31
|
-
export {
|
|
32
|
-
r as getSrcSet
|
|
33
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";function c(t){return t.replace(/http(s)?:/,"")}function r(t="",e,n){const o=new RegExp("([?&])"+e+"=.*?(&|$)","i"),i=t.indexOf("?")!==-1?"&":"?";return t.match(o)?t.replace(o,"$1"+e+"="+encodeURIComponent(n)+"$2"):t+i+e+"="+encodeURIComponent(n)}function a(t,e){if(!t||!(t!=null&&t.match(/cdn\.shopify\.com/))||!e)return t;if(e==="master")return c(t);const n=t.match(/(_\d+x(\d+)?)?(\.(jpg|jpeg|gif|png|bmp|bitmap|tiff|tif)(\?v=\d+)?)/i);if(n){const o=t.split(n[0]),i=n[3],f=e.match("x")?e:`${e}x`;return c(`${o[0]}_${f}${i}`)}return null}function p(t){if(!t)return t;const e=[100,200,400,800,1200,1600,2e3];if(t.match(/builder\.io/)){let n=t;const o=Number(t.split("?width=")[1]);return isNaN(o)||(n=`${n} ${o}w`),e.filter(i=>i!==o).map(i=>`${r(t,"width",i)} ${i}w`).concat([n]).join(", ")}return t.match(/cdn\.shopify\.com/)?e.map(n=>[a(t,`${n}x${n}`),n]).filter(([n])=>!!n).map(([n,o])=>`${n} ${o}w`).concat([t]).join(", "):t}exports.getSrcSet=p;
|
package/lib/edge/img-3bb375bf.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { jsx as r } from "react/jsx-runtime";
|
|
2
|
-
import { isEditing as n } from "./server-entry-fb5f2b80.js";
|
|
3
|
-
import { getSrcSet as o } from "./image.helpers-3e926d47.js";
|
|
4
|
-
function g(t) {
|
|
5
|
-
function e() {
|
|
6
|
-
const i = t.imgSrc || t.image;
|
|
7
|
-
if (!(!i || typeof i != "string") && i.match(/builder\.io/))
|
|
8
|
-
return o(i);
|
|
9
|
-
}
|
|
10
|
-
return /* @__PURE__ */ r(
|
|
11
|
-
"img",
|
|
12
|
-
{
|
|
13
|
-
loading: "lazy",
|
|
14
|
-
style: {
|
|
15
|
-
objectFit: t.backgroundSize || "cover",
|
|
16
|
-
objectPosition: t.backgroundPosition || "center"
|
|
17
|
-
},
|
|
18
|
-
alt: t.altText,
|
|
19
|
-
src: t.imgSrc || t.image,
|
|
20
|
-
srcSet: e(),
|
|
21
|
-
...t.attributes
|
|
22
|
-
},
|
|
23
|
-
n() && t.imgSrc || "default-key"
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
export {
|
|
27
|
-
g as default
|
|
28
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),n=require("./server-entry-67200cf1.cjs"),c=require("./image.helpers-dba8a869.cjs");function u(e){function i(){const t=e.imgSrc||e.image;if(!(!t||typeof t!="string")&&t.match(/builder\.io/))return c.getSrcSet(t)}return r.jsx("img",{loading:"lazy",style:{objectFit:e.backgroundSize||"cover",objectPosition:e.backgroundPosition||"center"},alt:e.altText,src:e.imgSrc||e.image,srcSet:i(),...e.attributes},n.isEditing()&&e.imgSrc||"default-key")}exports.default=u;
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";const S="react";function a(){return typeof window!="undefined"&&typeof document!="undefined"}const A="[Builder.io]: ",d={log:(...t)=>console.log(A,...t),error:(...t)=>console.error(A,...t),warn:(...t)=>console.warn(A,...t),debug:(...t)=>console.debug(A,...t)},p=t=>t!=null,yt=t=>{if(t==="localhost"||t==="127.0.0.1")return t;const e=t.split(".");return e.length>2?e.slice(1).join("."):t},v=({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}},$=async t=>v(t),bt=t=>t.map(([e,n])=>n?`${e}=${n}`:e).filter(p).join("; "),mt=[["secure",""],["SameSite","None"]],wt=({name:t,value:e,expires:n})=>{const s=(a()?location.protocol==="https:":!0)?mt:[[]],o=n?[["expires",n.toUTCString()]]:[[]],i=[[t,e],...o,["path","/"],["domain",yt(window.location.hostname)],...s];return bt(i)},O=async({name:t,value:e,expires:n,canTrack:r})=>{try{if(!r)return;const s=wt({name:t,value:e,expires:n});document.cookie=s}catch(s){d.warn("[COOKIE] SET error: ",(s==null?void 0:s.message)||s)}};const V="builder.userAttributes";function D(){let t=!0;const e=new Set;return{setUserAttributes(n){if(!a())return;const r={...this.getUserAttributes(),...n};O({name:V,value:JSON.stringify(r),canTrack:t}),e.forEach(s=>s(r))},getUserAttributes(){return a()?JSON.parse(v({name:V,canTrack:t})||"{}"):{}},subscribeOnUserAttributesChange(n,{fireImmediately:r}={}){return e.add(n),r&&n(this.getUserAttributes()),function(){e.delete(n)}},setCanTrack(n){t=n}}}let U;a()&&S==="qwik"?(window.__BUILDER_USER_ATTRIBUTES_SERVICE__||(window.__BUILDER_USER_ATTRIBUTES_SERVICE__=D()),U=window.__BUILDER_USER_ATTRIBUTES_SERVICE__):U=D();const P=U,Et=t=>{P.setUserAttributes(t)},It=t=>{const e={};return t.forEach((n,r)=>{e[r]=n}),e},G=t=>t instanceof URLSearchParams?It(t):t,J=t=>typeof t=="string"?t:t instanceof URLSearchParams?t.toString():new URLSearchParams(t).toString();function At(){return a()&&window.self!==window.top}function z(t){return At()&&J(t||window.location.search).indexOf("builder.frameEditing=")!==-1}function vt(t){const e=t||(a()?window.location.search:void 0);return e?J(e).indexOf("builder.preview=")!==-1:!1}const kt=t=>({type:"builder.registerComponent",data:R(t)}),Ut=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 R(t){return JSON.parse(JSON.stringify(t,(e,n)=>typeof n=="function"?Ut(n):n))}const F={};function Tt(t,e){t==="plugin"&&(e=R(e));let n=F[t];if(n||(n=F[t]=[]),n.push(e),a()){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)}}}function Ot(t){var e;if(a()){const n=JSON.parse(JSON.stringify(t));t.action&&(n.action=t.action.toString()),(e=window.parent)==null||e.postMessage({type:"builder.registerAction",data:n},"*")}}const M={};function Pt(t){if(a()){Object.assign(M,t);const e={type:"builder.settingsChange",data:M};parent.postMessage(e,"*")}}const K="builder.",Rt="options.",C=t=>{if(!t)return{};const e=G(t),n={};return Object.keys(e).forEach(r=>{if(r.startsWith(K)){const s=r.replace(K,"").replace(Rt,"");n[s]=e[r]}}),n},Ct=()=>{if(!a())return{};const t=new URLSearchParams(window.location.search);return C(t)},X="4.2.2",H=()=>({"X-Builder-SDK":S,"X-Builder-SDK-GEN":"2","X-Builder-SDK-Version":X});function Bt(){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 Q(){return Bt().replace(/-/g,"")}const Y="builderSessionId",xt=async({canTrack:t})=>{if(!t)return;const e=await $({name:Y,canTrack:t});if(p(e))return e;{const n=_t();return Lt({id:n,canTrack:t}),n}},_t=()=>Q(),Lt=({id:t,canTrack:e})=>O({name:Y,value:t,canTrack:e}),Z=()=>a()&&typeof localStorage!="undefined"?localStorage:void 0,Nt=({key:t,canTrack:e})=>{var n;try{return e?(n=Z())==null?void 0:n.getItem(t):void 0}catch(r){console.debug("[LocalStorage] GET error: ",r);return}},Vt=({key:t,canTrack:e,value:n})=>{var r;try{e&&((r=Z())==null||r.setItem(t,n))}catch(s){console.debug("[LocalStorage] SET error: ",s)}},q="builderVisitorId",Dt=({canTrack:t})=>{if(!t)return;const e=Nt({key:q,canTrack:t});if(p(e))return e;{const n=Ft();return Mt({id:n,canTrack:t}),n}},Ft=()=>Q(),Mt=({id:t,canTrack:e})=>Vt({key:q,value:t,canTrack:e});function tt(t){var e;typeof process!="undefined"&&((e=process.env)!=null&&e.DEBUG)&&String(process.env.DEBUG)=="true"&&d.log(t)}const Kt=()=>{if(a()){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},Wt=()=>typeof navigator=="object"&&navigator.userAgent||"",et=()=>{const t=Wt(),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()||S==="reactNative"}},n=t.match(/Tablet|iPad/i),r=Kt();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"}},jt=async({canTrack:t})=>{if(!t)return{visitorId:void 0,sessionId:void 0};const e=await xt({canTrack:t}),n=Dt({canTrack:t});return{sessionId:e,visitorId:n}},$t=async({type:t,canTrack:e,apiKey:n,metadata:r,...s})=>({type:t,data:{...s,metadata:{url:location.href,...r},...await jt({canTrack:e}),userAttributes:et(),ownerId:n}});async function nt({apiHost:t,...e}){if(!e.apiKey){d.error("Missing API key for track call. Please provide your API key.");return}if(!e.canTrack||z()||!(a()||S==="reactNative"))return;const r=`${t||"https://cdn.builder.io"}/api/v1/track`;return tt(r),fetch(r,{method:"POST",body:JSON.stringify({events:[await $t(e)]}),headers:{"content-type":"application/json",...H()},mode:"cors"}).catch(s=>{console.error("Failed to track: ",s)})}const Gt=t=>nt({...t,canTrack:!0}),Jt=["*.beta.builder.io","beta.builder.io","builder.io","localhost","qa.builder.io"];function rt(t,e){if(!e.origin.startsWith("http")&&!e.origin.startsWith("https"))return!1;const n=new URL(e.origin),r=n.hostname;return(t||Jt).findIndex(s=>s.startsWith("*.")?r.endsWith(s.slice(1)):s===r)>-1}let W=!1;const st=t=>{var e,n;W||(W=!0,a()&&((e=window.parent)==null||e.postMessage({type:"builder.sdkInfo",data:{target:S,version:X,supportsPatchUpdates:!1,supportsAddBlockScoping:!0,supportsCustomBreakpoints:!0,modelName:t.modelName,apiKey:t.apiKey,supportsXSmallBreakpoint:!0,blockLevelPersonalization:!0}},"*"),(n=window.parent)==null||n.postMessage({type:"builder.updateContent",data:{options:t}},"*"),window.addEventListener("message",r=>{var o,i;if(!rt(t.trustedHosts,r))return;const{data:s}=r;if(s!=null&&s.type)switch(s.type){case"builder.evaluate":{const u=s.data.text,m=s.data.arguments||[],y=s.data.id,w=new Function(u);let l,g=null;try{l=w.apply(null,m)}catch(h){g=h}g?(o=window.parent)==null||o.postMessage({type:"builder.evaluateError",data:{id:y,error:g.message}},"*"):l&&typeof l.then=="function"?l.then(h=>{var E;(E=window.parent)==null||E.postMessage({type:"builder.evaluateResult",data:{id:y,result:h}},"*")}).catch(console.error):(i=window.parent)==null||i.postMessage({type:"builder.evaluateResult",data:{result:l,id:y}},"*");break}}})))},ot=({model:t,trustedHosts:e,callbacks:n})=>r=>{if(!rt(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.resetState":{const o=s.data,i=o.model,u=o==null?void 0:o.state;i===t&&u&&n.stateUpdate(u);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}}},zt=({model:t,apiKey:e,callback:n,trustedHosts:r})=>{if(!a)return d.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server."),()=>{};st({modelName:t,apiKey:e});const s=ot({callbacks:{contentUpdate:n,animation:()=>{},configureSdk:()=>{},stateUpdate:()=>{}},model:t,trustedHosts:r});return window.addEventListener("message",s),()=>{window.removeEventListener("message",s)}},Xt="builder.tests",B=t=>`${Xt}.${t}`,Ht=({contentId:t})=>$({name:B(t),canTrack:!0}),Qt=({contentId:t})=>v({name:B(t),canTrack:!0}),Yt=({contentId:t,value:e})=>O({name:B(t),value:e,canTrack:!0}),it=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},at=t=>{const e=Zt(t);return Yt({contentId:t.id,value:e}).catch(n=>{d.error("could not store A/B test variation: ",n)}),e},ct=({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":"")}},qt=({item:t,canTrack:e})=>{if(!e)return t;if(!t)return;if(!it(t))return t;const n=Qt({contentId:t.id})||at({variations:t.variations,id:t.id}),r=ct({item:t,testGroupId:n});return{...t,...r}},te=async({item:t,canTrack:e})=>{if(!e||!it(t))return t;const r=await Ht({contentId:t.id})||at({variations:t.variations,id:t.id}),s=ct({item:t,testGroupId:r});return{...t,...s}},ut=t=>{const e=p(t)?t:!0;return P.setCanTrack(e),e};function ee(){return typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:globalThis}function ne(){const t=ee().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 re=ne();function T(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,...T(o,i,n)}:{...r,[i]:o}},{})}function lt(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("$"))?lt(s,o,n):n[o]=s}return n}function se(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 oe="v3",j=t=>typeof t=="number"&&!isNaN(t)&&t>=0,x=t=>{const{limit:e=30,userAttributes:n,query:r,model:s,apiKey:o,enrich:i,locale:u,apiVersion:m=oe,fields:y,omit:w,offset:l,cacheSeconds:g,staleCacheSeconds:h,sort:E,includeUnpublished:_,apiHost:ht}=t;if(!o)throw new Error("Missing API key");if(!["v3"].includes(m))throw new Error(`Invalid apiVersion: expected 'v3', received '${m}'`);const pt=e!==1,St=ht||"https://cdn.builder.io",c=new URL(`${St}/api/${m}/content/${s}`);c.searchParams.set("apiKey",o),c.searchParams.set("limit",String(e)),c.searchParams.set("noTraverse",String(pt)),c.searchParams.set("includeRefs",String(!0));const k=u||(n==null?void 0:n.locale);let b=n||{};if(k&&(c.searchParams.set("locale",k),b={locale:k,...b}),i&&c.searchParams.set("enrich",String(i)),c.searchParams.set("omit",w!=null?w:"meta.componentsUsed"),y&&c.searchParams.set("fields",y),Number.isFinite(l)&&l>-1&&c.searchParams.set("offset",String(Math.floor(l))),typeof _=="boolean"&&c.searchParams.set("includeUnpublished",String(_)),g&&j(g)&&c.searchParams.set("cacheSeconds",String(g)),h&&j(h)&&c.searchParams.set("staleCacheSeconds",String(h)),E){const f=T({sort:E});for(const I in f)c.searchParams.set(I,JSON.stringify(f[I]))}const L={...Ct(),...G(t.options||{})};b={...b,...ae(L)};const N=T(L);for(const f in N)c.searchParams.set(f,String(N[f]));if(Object.keys(b).length>0&&c.searchParams.set("userAttributes",JSON.stringify(b)),r){const f=lt({query:r});for(const I in f)c.searchParams.set(I,JSON.stringify(f[I]))}return c},ie=t=>{const e={};for(const n in t)n.startsWith("userAttributes.")&&(e[n]=t[n],delete t[n]);return e},ae=t=>{if(a()&&t.preview==="BUILDER_STUDIO"){t["userAttributes.urlPath"]=window.location.pathname,t["userAttributes.host"]=window.location.host;const e=ie(t),{userAttributes:n}=se(e);return n}return{}},ce=t=>"results"in t;async function dt(t){const e=await gt({...t,limit:1});return e&&e[0]||null}const ue=async t=>{var i,u;const e=x(t),n=(i=t.fetch)!=null?i:re,r={...t.fetchOptions,headers:{...(u=t.fetchOptions)==null?void 0:u.headers,...H()}};return await(await n(e.href,r)).json()},ft=async(t,e,n=x(t))=>{const r=ut(t.canTrack);if(n.search.includes("preview="),!r||!(a()||S==="reactNative"))return e.results;try{const s=[];for(const o of e.results)s.push(await te({item:o,canTrack:r}));e.results=s}catch(s){d.error("Could not process A/B tests. ",s)}return e.results};async function gt(t){const e=x(t),n=await ue(t);if(!ce(n))throw d.error("Error fetching data. ",{url:e,content:n,options:t}),n;return ft(t,n)}const le=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:C(t.searchParams||((o=t.url)==null?void 0:o.searchParams)||t.options)};return{apiKey:n.apiKey,model:n.model,content:await dt(n)}};exports.TARGET=S;exports._processContentResult=ft;exports._track=nt;exports.checkIsDefined=p;exports.createEditorListener=ot;exports.createRegisterComponentMessage=kt;exports.fetchBuilderProps=le;exports.fetchEntries=gt;exports.fetchOneEntry=dt;exports.getBuilderSearchParams=C;exports.getCookieSync=v;exports.getDefaultCanTrack=ut;exports.getUserAttributes=et;exports.handleABTestingSync=qt;exports.isBrowser=a;exports.isEditing=z;exports.isPreviewing=vt;exports.logFetch=tt;exports.logger=d;exports.register=Tt;exports.registerAction=Ot;exports.serializeIncludingFunctions=R;exports.setClientUserAttributes=Et;exports.setEditorSettings=Pt;exports.setupBrowserForEditing=st;exports.subscribeToEditor=zt;exports.track=Gt;exports.userAttributesService=P;
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";const S="react",A="[Builder.io]: ",d={log:(...t)=>console.log(A,...t),error:(...t)=>console.error(A,...t),warn:(...t)=>console.warn(A,...t),debug:(...t)=>console.debug(A,...t)};function a(){return typeof window!="undefined"&&typeof document!="undefined"}const yt=t=>{const e={};return t.forEach((n,r)=>{e[r]=n}),e},G=t=>t instanceof URLSearchParams?yt(t):t,$=t=>typeof t=="string"?t:t instanceof URLSearchParams?t.toString():new URLSearchParams(t).toString();function bt(){return a()&&window.self!==window.top}function J(t){return bt()&&$(t||window.location.search).indexOf("builder.frameEditing=")!==-1}const mt=()=>{if(a()){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},wt=()=>typeof navigator=="object"&&navigator.userAgent||"",z=()=>{const t=wt(),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()||S==="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 Et(t){const e=t||(a()?window.location.search:void 0);return e?$(e).indexOf("builder.preview=")!==-1:!1}const It=t=>({type:"builder.registerComponent",data:O(t)}),At=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 O(t){return JSON.parse(JSON.stringify(t,(e,n)=>typeof n=="function"?At(n):n))}const V={};function vt(t,e){t==="plugin"&&(e=O(e));let n=V[t];if(n||(n=V[t]=[]),n.push(e),a()){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)}}}function kt(t){var e;if(a()){const n=JSON.parse(JSON.stringify(t));t.action&&(n.action=t.action.toString()),(e=window.parent)==null||e.postMessage({type:"builder.registerAction",data:n},"*")}}const D={};function Ut(t){if(a()){Object.assign(D,t);const e={type:"builder.settingsChange",data:D};parent.postMessage(e,"*")}}const F="builder.",Tt="options.",P=t=>{if(!t)return{};const e=G(t),n={};return Object.keys(e).forEach(r=>{if(r.startsWith(F)){const s=r.replace(F,"").replace(Tt,"");n[s]=e[r]}}),n},Ot=()=>{if(!a())return{};const t=new URLSearchParams(window.location.search);return P(t)},X="4.2.2",H=()=>({"X-Builder-SDK":S,"X-Builder-SDK-GEN":"2","X-Builder-SDK-Version":X}),Pt=t=>{if(t==="localhost"||t==="127.0.0.1")return t;const e=t.split(".");return e.length>2?e.slice(1).join("."):t},v=({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}},Q=async t=>v(t),Rt=t=>t.map(([e,n])=>n?`${e}=${n}`:e).filter(p).join("; "),Ct=[["secure",""],["SameSite","None"]],Bt=({name:t,value:e,expires:n})=>{const s=(a()?location.protocol==="https:":!0)?Ct:[[]],o=n?[["expires",n.toUTCString()]]:[[]],i=[[t,e],...o,["path","/"],["domain",Pt(window.location.hostname)],...s];return Rt(i)},R=async({name:t,value:e,expires:n,canTrack:r})=>{try{if(!r)return;const s=Bt({name:t,value:e,expires:n});document.cookie=s}catch(s){d.warn("[COOKIE] SET error: ",(s==null?void 0:s.message)||s)}};function _t(){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 Y(){return _t().replace(/-/g,"")}const Z="builderSessionId",xt=async({canTrack:t})=>{if(!t)return;const e=await Q({name:Z,canTrack:t});if(p(e))return e;{const n=Lt();return Nt({id:n,canTrack:t}),n}},Lt=()=>Y(),Nt=({id:t,canTrack:e})=>R({name:Z,value:t,canTrack:e}),q=()=>a()&&typeof localStorage!="undefined"?localStorage:void 0,Vt=({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}},Dt=({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)}},tt="builderVisitorId",Ft=({canTrack:t})=>{if(!t)return;const e=Vt({key:tt,canTrack:t});if(p(e))return e;{const n=Mt();return Kt({id:n,canTrack:t}),n}},Mt=()=>Y(),Kt=({id:t,canTrack:e})=>Dt({key:tt,value:t,canTrack:e});function et(t){var e;typeof process!="undefined"&&((e=process.env)!=null&&e.DEBUG)&&String(process.env.DEBUG)=="true"&&d.log(t)}const Wt=async({canTrack:t})=>{if(!t)return{visitorId:void 0,sessionId:void 0};const e=await xt({canTrack:t}),n=Ft({canTrack:t});return{sessionId:e,visitorId:n}},jt=async({type:t,canTrack:e,apiKey:n,metadata:r,...s})=>({type:t,data:{...s,metadata:{url:location.href,...r},...await Wt({canTrack:e}),userAttributes:z(),ownerId:n}});async function nt({apiHost:t,...e}){if(!e.apiKey){d.error("Missing API key for track call. Please provide your API key.");return}if(!e.canTrack||J()||!(a()||S==="reactNative"))return;const r=`${t||"https://cdn.builder.io"}/api/v1/track`;return et(r),fetch(r,{method:"POST",body:JSON.stringify({events:[await jt(e)]}),headers:{"content-type":"application/json",...H()},mode:"cors"}).catch(s=>{console.error("Failed to track: ",s)})}const Gt=t=>nt({...t,canTrack:!0}),$t=["*.beta.builder.io","beta.builder.io","builder.io","localhost","qa.builder.io"];function rt(t,e){if(!e.origin.startsWith("http")&&!e.origin.startsWith("https"))return!1;const n=new URL(e.origin),r=n.hostname;return(t||$t).findIndex(s=>s.startsWith("*.")?r.endsWith(s.slice(1)):s===r)>-1}let M=!1;const st=t=>{var e,n;M||(M=!0,a()&&((e=window.parent)==null||e.postMessage({type:"builder.sdkInfo",data:{target:S,version:X,supportsPatchUpdates:!1,supportsAddBlockScoping:!0,supportsCustomBreakpoints:!0,modelName:t.modelName,apiKey:t.apiKey,supportsXSmallBreakpoint:!0,blockLevelPersonalization:!0}},"*"),(n=window.parent)==null||n.postMessage({type:"builder.updateContent",data:{options:t}},"*"),window.addEventListener("message",r=>{var o,i;if(!rt(t.trustedHosts,r))return;const{data:s}=r;if(s!=null&&s.type)switch(s.type){case"builder.evaluate":{const u=s.data.text,m=s.data.arguments||[],y=s.data.id,w=new Function(u);let l,g=null;try{l=w.apply(null,m)}catch(h){g=h}g?(o=window.parent)==null||o.postMessage({type:"builder.evaluateError",data:{id:y,error:g.message}},"*"):l&&typeof l.then=="function"?l.then(h=>{var E;(E=window.parent)==null||E.postMessage({type:"builder.evaluateResult",data:{id:y,result:h}},"*")}).catch(console.error):(i=window.parent)==null||i.postMessage({type:"builder.evaluateResult",data:{result:l,id:y}},"*");break}}})))},ot=({model:t,trustedHosts:e,callbacks:n})=>r=>{if(!rt(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.resetState":{const o=s.data,i=o.model,u=o==null?void 0:o.state;i===t&&u&&n.stateUpdate(u);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}}},Jt=({model:t,apiKey:e,callback:n,trustedHosts:r})=>{if(!a)return d.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server."),()=>{};st({modelName:t,apiKey:e});const s=ot({callbacks:{contentUpdate:n,animation:()=>{},configureSdk:()=>{},stateUpdate:()=>{}},model:t,trustedHosts:r});return window.addEventListener("message",s),()=>{window.removeEventListener("message",s)}},zt="builder.tests",C=t=>`${zt}.${t}`,Xt=({contentId:t})=>Q({name:C(t),canTrack:!0}),Ht=({contentId:t})=>v({name:C(t),canTrack:!0}),Qt=({contentId:t,value:e})=>R({name:C(t),value:e,canTrack:!0}),it=t=>p(t.id)&&p(t.variations)&&Object.keys(t.variations).length>0,Yt=({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},at=t=>{const e=Yt(t);return Qt({contentId:t.id,value:e}).catch(n=>{d.error("could not store A/B test variation: ",n)}),e},ct=({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":"")}},Zt=({item:t,canTrack:e})=>{if(!e)return t;if(!t)return;if(!it(t))return t;const n=Ht({contentId:t.id})||at({variations:t.variations,id:t.id}),r=ct({item:t,testGroupId:n});return{...t,...r}},qt=async({item:t,canTrack:e})=>{if(!e||!it(t))return t;const r=await Xt({contentId:t.id})||at({variations:t.variations,id:t.id}),s=ct({item:t,testGroupId:r});return{...t,...s}};const K="builder.userAttributes";function W(){let t=!0;const e=new Set;return{setUserAttributes(n){if(!a())return;const r={...this.getUserAttributes(),...n};R({name:K,value:JSON.stringify(r),canTrack:t}),e.forEach(s=>s(r))},getUserAttributes(){return a()?JSON.parse(v({name:K,canTrack:t})||"{}"):{}},subscribeOnUserAttributesChange(n,{fireImmediately:r}={}){return e.add(n),r&&n(this.getUserAttributes()),function(){e.delete(n)}},setCanTrack(n){t=n}}}let U;a()&&S==="qwik"?(window.__BUILDER_USER_ATTRIBUTES_SERVICE__||(window.__BUILDER_USER_ATTRIBUTES_SERVICE__=W()),U=window.__BUILDER_USER_ATTRIBUTES_SERVICE__):U=W();const B=U,te=t=>{B.setUserAttributes(t)},ut=t=>{const e=p(t)?t:!0;return B.setCanTrack(e),e};function ee(){return typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:globalThis}function ne(){const t=ee().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 re=ne();function T(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,...T(o,i,n)}:{...r,[i]:o}},{})}function lt(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("$"))?lt(s,o,n):n[o]=s}return n}function se(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 oe="v3",j=t=>typeof t=="number"&&!isNaN(t)&&t>=0,_=t=>{const{limit:e=30,userAttributes:n,query:r,model:s,apiKey:o,enrich:i,locale:u,apiVersion:m=oe,fields:y,omit:w,offset:l,cacheSeconds:g,staleCacheSeconds:h,sort:E,includeUnpublished:x,apiHost:ht}=t;if(!o)throw new Error("Missing API key");if(!["v3"].includes(m))throw new Error(`Invalid apiVersion: expected 'v3', received '${m}'`);const pt=e!==1,St=ht||"https://cdn.builder.io",c=new URL(`${St}/api/${m}/content/${s}`);c.searchParams.set("apiKey",o),c.searchParams.set("limit",String(e)),c.searchParams.set("noTraverse",String(pt)),c.searchParams.set("includeRefs",String(!0));const k=u||(n==null?void 0:n.locale);let b=n||{};if(k&&(c.searchParams.set("locale",k),b={locale:k,...b}),i&&c.searchParams.set("enrich",String(i)),c.searchParams.set("omit",w!=null?w:"meta.componentsUsed"),y&&c.searchParams.set("fields",y),Number.isFinite(l)&&l>-1&&c.searchParams.set("offset",String(Math.floor(l))),typeof x=="boolean"&&c.searchParams.set("includeUnpublished",String(x)),g&&j(g)&&c.searchParams.set("cacheSeconds",String(g)),h&&j(h)&&c.searchParams.set("staleCacheSeconds",String(h)),E){const f=T({sort:E});for(const I in f)c.searchParams.set(I,JSON.stringify(f[I]))}const L={...Ot(),...G(t.options||{})};b={...b,...ae(L)};const N=T(L);for(const f in N)c.searchParams.set(f,String(N[f]));if(Object.keys(b).length>0&&c.searchParams.set("userAttributes",JSON.stringify(b)),r){const f=lt({query:r});for(const I in f)c.searchParams.set(I,JSON.stringify(f[I]))}return c},ie=t=>{const e={};for(const n in t)n.startsWith("userAttributes.")&&(e[n]=t[n],delete t[n]);return e},ae=t=>{if(a()&&t.preview==="BUILDER_STUDIO"){t["userAttributes.urlPath"]=window.location.pathname,t["userAttributes.host"]=window.location.host;const e=ie(t),{userAttributes:n}=se(e);return n}return{}},ce=t=>"results"in t;async function dt(t){const e=await gt({...t,limit:1});return e&&e[0]||null}const ue=async t=>{var i,u;const e=_(t),n=(i=t.fetch)!=null?i:re,r={...t.fetchOptions,headers:{...(u=t.fetchOptions)==null?void 0:u.headers,...H()}};return await(await n(e.href,r)).json()},ft=async(t,e,n=_(t))=>{const r=ut(t.canTrack);if(n.search.includes("preview="),!r||!(a()||S==="reactNative"))return e.results;try{const s=[];for(const o of e.results)s.push(await qt({item:o,canTrack:r}));e.results=s}catch(s){d.error("Could not process A/B tests. ",s)}return e.results};async function gt(t){const e=_(t),n=await ue(t);if(!ce(n))throw d.error("Error fetching data. ",{url:e,content:n,options:t}),n;return ft(t,n)}const le=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:P(t.searchParams||((o=t.url)==null?void 0:o.searchParams)||t.options)};return{apiKey:n.apiKey,model:n.model,content:await dt(n)}};exports.MSG_PREFIX=A;exports.TARGET=S;exports._processContentResult=ft;exports._track=nt;exports.checkIsDefined=p;exports.createEditorListener=ot;exports.createRegisterComponentMessage=It;exports.fetchBuilderProps=le;exports.fetchEntries=gt;exports.fetchOneEntry=dt;exports.getBuilderSearchParams=P;exports.getCookieSync=v;exports.getDefaultCanTrack=ut;exports.getUserAttributes=z;exports.handleABTestingSync=Zt;exports.isBrowser=a;exports.isEditing=J;exports.isPreviewing=Et;exports.logFetch=et;exports.logger=d;exports.register=vt;exports.registerAction=kt;exports.serializeIncludingFunctions=O;exports.setClientUserAttributes=te;exports.setEditorSettings=Ut;exports.setupBrowserForEditing=st;exports.subscribeToEditor=Jt;exports.track=Gt;exports.userAttributesService=B;
|