@builder.io/sdk-react 3.0.6 → 4.0.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 +32 -32
- package/lib/browser/blocks-exports.mjs +923 -860
- package/lib/browser/index.cjs +1 -1
- package/lib/browser/index.mjs +1 -1
- package/lib/browser/{server-entry-df5e89e5.js → server-entry-422fad84.js} +51 -40
- package/lib/browser/server-entry-916191b4.cjs +2 -0
- package/lib/browser/server-entry.cjs +1 -1
- package/lib/browser/server-entry.mjs +1 -1
- package/lib/edge/{accordion-fbfb71f4.cjs → accordion-2f83fc75.cjs} +1 -1
- package/lib/edge/{accordion-289f3464.js → accordion-e1b77652.js} +1 -1
- package/lib/edge/{blocks-582a7fd7.js → blocks-0885e182.js} +1305 -1280
- package/lib/edge/blocks-5165c164.cjs +30 -0
- package/lib/edge/blocks-exports.cjs +1 -1
- package/lib/edge/blocks-exports.mjs +2 -2
- package/lib/edge/{button-da357144.cjs → button-d7197e96.cjs} +1 -1
- package/lib/edge/{button-9b112da6.js → button-d878f35c.js} +2 -2
- package/lib/edge/{columns-a211113f.cjs → columns-46729516.cjs} +1 -1
- package/lib/edge/{columns-aba58dda.js → columns-b365c86a.js} +3 -3
- package/lib/edge/{content-variants-08f4371c.js → content-variants-1594c868.js} +281 -279
- package/lib/edge/content-variants-c6cab1c3.cjs +134 -0
- package/lib/edge/{form-e3a3afd4.cjs → form-9844766c.cjs} +1 -1
- package/lib/edge/{form-4d4553c2.js → form-b66c20a3.js} +3 -3
- package/lib/edge/{get-class-prop-name-fbe244e3.cjs → get-class-prop-name-0b992cfb.cjs} +1 -1
- package/lib/edge/{get-class-prop-name-38c2baca.js → get-class-prop-name-dac81472.js} +1 -1
- package/lib/edge/{img-c49066fa.js → img-c4a772a8.js} +1 -1
- package/lib/edge/{img-8d549af8.cjs → img-fb35350a.cjs} +1 -1
- package/lib/edge/index.cjs +1 -1
- package/lib/edge/index.mjs +1 -1
- package/lib/edge/{input-1ae3842f.cjs → input-122768ac.cjs} +1 -1
- package/lib/edge/{input-e7301f4e.js → input-57c5b097.js} +1 -1
- package/lib/edge/{personalization-container-035be6ba.js → personalization-container-7e63edce.js} +4 -4
- package/lib/edge/{personalization-container-25cd8b5e.cjs → personalization-container-a17ae615.cjs} +1 -1
- package/lib/edge/{select-4187b229.js → select-3d4324ef.js} +1 -1
- package/lib/edge/{select-64fdaa79.cjs → select-7f750b70.cjs} +1 -1
- package/lib/edge/server-entry-77166102.cjs +2 -0
- package/lib/edge/{server-entry-61fca4f7.js → server-entry-c1673af2.js} +55 -44
- package/lib/edge/server-entry.cjs +1 -1
- package/lib/edge/server-entry.mjs +1 -1
- package/lib/edge/{slot-d6c46a42.js → slot-05ef18a0.js} +3 -3
- package/lib/edge/{slot-995f63c2.cjs → slot-123c0993.cjs} +1 -1
- package/lib/edge/symbol-ee314d5a.cjs +1 -0
- package/lib/edge/{symbol-623dc717.js → symbol-f488bea0.js} +25 -25
- package/lib/edge/{tabs-12ba41b1.js → tabs-244d53fa.js} +3 -3
- package/lib/edge/{tabs-d39499cd.cjs → tabs-edb82022.cjs} +1 -1
- package/lib/edge/{video-a3f10439.js → video-52df64e2.js} +54 -17
- package/lib/edge/video-cc58dd83.cjs +1 -0
- package/lib/node/blocks-exports.cjs +32 -32
- package/lib/node/blocks-exports.mjs +912 -849
- 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/node/{server-entry-27d9d31e.js → server-entry-4df60fc5.js} +51 -40
- package/lib/node/server-entry-8ab8c78b.cjs +2 -0
- package/lib/node/server-entry.cjs +1 -1
- package/lib/node/server-entry.mjs +1 -1
- package/lib/node/{setIvm-2dde9074.js → setIvm-0edfc727.js} +1 -1
- package/lib/node/{setIvm-784fe19f.cjs → setIvm-6405aa63.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-cd6baa94.cjs → should-force-browser-runtime-in-node-6d4dbff9.cjs} +1 -1
- package/lib/node/{should-force-browser-runtime-in-node-80f081c8.js → should-force-browser-runtime-in-node-7a39b073.js} +1 -1
- package/package.json +1 -1
- package/types/components/content-variants/content-variants.types.d.ts +2 -2
- package/types/constants/device-sizes.d.ts +3 -2
- package/types/constants/sdk-version.d.ts +1 -1
- package/types/helpers/subscribe-to-editor.d.ts +13 -13
- package/types/scripts/init-editing.d.ts +3 -1
- package/types/types/builder-block.d.ts +0 -1
- package/types/types/builder-content.d.ts +1 -0
- package/lib/browser/server-entry-a1c64831.cjs +0 -2
- package/lib/edge/blocks-459a090b.cjs +0 -30
- package/lib/edge/content-variants-4b5899b5.cjs +0 -134
- package/lib/edge/server-entry-2ef4e66a.cjs +0 -2
- package/lib/edge/symbol-498daa97.cjs +0 -1
- package/lib/edge/video-4ecfd08b.cjs +0 -1
- package/lib/node/server-entry-98ebff74.cjs +0 -2
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";const y="react",E="[Builder.io]: ",d={log:(...t)=>console.log(E,...t),error:(...t)=>console.error(E,...t),warn:(...t)=>console.warn(E,...t),debug:(...t)=>console.debug(E,...t)};function c(){return typeof window!="undefined"&&typeof document!="undefined"}const mt=t=>{const e={};return t.forEach((n,r)=>{e[r]=n}),e},j=t=>t instanceof URLSearchParams?mt(t):t,W=t=>typeof t=="string"?t:t instanceof URLSearchParams?t.toString():new URLSearchParams(t).toString();function bt(){return c()&&window.self!==window.top}function G(t){return bt()&&W(t||window.location.search).indexOf("builder.frameEditing=")!==-1}const yt=()=>{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},St=()=>typeof navigator=="object"&&navigator.userAgent||"",$=()=>{const t=St(),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()||y==="reactNative"}},n=t.match(/Tablet|iPad/i),r=yt();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?W(e).indexOf("builder.preview=")!==-1:!1}const vt=t=>({type:"builder.registerComponent",data:O(t)}),Et=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"?Et(n):n))}const V={};function J(t,e){t==="plugin"&&(e=O(e));let n=V[t];if(n||(n=V[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 M={};function It(t){if(c()){Object.assign(M,t);const e={type:"builder.settingsChange",data:M};parent.postMessage(e,"*")}}const N="builder.",kt="options.",P=t=>{if(!t)return{};const e=j(t),n={};return Object.keys(e).forEach(r=>{if(r.startsWith(N)){const s=r.replace(N,"").replace(kt,"");n[s]=e[r]}}),n},At=()=>{if(!c())return{};const t=new URLSearchParams(window.location.search);return P(t)},z="3.0.6",X=()=>({"X-Builder-SDK":y,"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},C=({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}},H=async t=>C(t),Pt=t=>t.map(([e,n])=>n?`${e}=${n}`:e).filter(p).join("; "),Ct=[["secure",""],["SameSite","None"]],Tt=({name:t,value:e,expires:n})=>{const s=(c()?location.protocol==="https:":!0)?Ct:[[]],o=n?[["expires",n.toUTCString()]]:[[]],i=[[t,e],...o,["path","/"],["domain",Ot(window.location.hostname)],...s];return Pt(i)},T=async({name:t,value:e,expires:n,canTrack:r})=>{try{if(!r)return;const s=Tt({name:t,value:e,expires:n});document.cookie=s}catch(s){d.warn("[COOKIE] SET error: ",(s==null?void 0:s.message)||s)}};function Ut(){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 Ut().replace(/-/g,"")}const Y="builderSessionId",Bt=async({canTrack:t})=>{if(!t)return;const e=await H({name:Y,canTrack:t});if(p(e))return e;{const n=Rt();return xt({id:n,canTrack:t}),n}},Rt=()=>Q(),xt=({id:t,canTrack:e})=>T({name:Y,value:t,canTrack:e}),Z=()=>c()&&typeof localStorage!="undefined"?localStorage:void 0,Lt=({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}},Ft=({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",Vt=({canTrack:t})=>{if(!t)return;const e=Lt({key:q,canTrack:t});if(p(e))return e;{const n=Mt();return Nt({id:n,canTrack:t}),n}},Mt=()=>Q(),Nt=({id:t,canTrack:e})=>Ft({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 Dt=async({canTrack:t})=>{if(!t)return{visitorId:void 0,sessionId:void 0};const e=await Bt({canTrack:t}),n=Vt({canTrack:t});return{sessionId:e,visitorId:n}},Kt=async({type:t,canTrack:e,apiKey:n,metadata:r,...s})=>({type:t,data:{...s,metadata:{url:location.href,...r},...await Dt({canTrack:e}),userAttributes:$(),ownerId:n}});async function et({apiHost:t,...e}){if(!e.apiKey){d.error("Missing API key for track call. Please provide your API key.");return}if(!e.canTrack||G()||!(c()||y==="reactNative"))return;const r=`${t||"https://cdn.builder.io"}/api/v1/track`;return tt(r),fetch(r,{method:"POST",body:JSON.stringify({events:[await Kt(e)]}),headers:{"content-type":"application/json",...X()},mode:"cors"}).catch(s=>{console.error("Failed to track: ",s)})}const _t=t=>et({...t,canTrack:!0}),jt=["*.beta.builder.io","beta.builder.io","builder.io","localhost","qa.builder.io"];function nt(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}const Wt=()=>{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 D=!1;const rt=(t={})=>{var e,n;D||(D=!0,c()&&((e=window.parent)==null||e.postMessage({type:"builder.sdkInfo",data:{target:y,version:z,supportsPatchUpdates:!1,supportsAddBlockScoping:!0,supportsCustomBreakpoints:!0,blockLevelPersonalization:!0}},"*"),(n=window.parent)==null||n.postMessage({type:"builder.updateContent",data:{options:t}},"*"),window.addEventListener("message",r=>{var o,i;if(!nt(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,I=new Function(u);let l,g=null;try{l=I.apply(null,S)}catch(h){g=h}g?(o=window.parent)==null||o.postMessage({type:"builder.evaluateError",data:{id:m,error:g.message}},"*"):l&&typeof l.then=="function"?l.then(h=>{var w;(w=window.parent)==null||w.postMessage({type:"builder.evaluateResult",data:{id:m,result:h}},"*")}).catch(console.error):(i=window.parent)==null||i.postMessage({type:"builder.evaluateResult",data:{result:l,id:m}},"*");break}}})))},st=({model:t,trustedHosts:e,callbacks:n})=>r=>{if(!nt(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}}},Gt=(t,e,n)=>{if(!c)return d.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server."),()=>{};rt();const r=st({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",U=t=>`${$t}.${t}`,Jt=({contentId:t})=>H({name:U(t),canTrack:!0}),zt=({contentId:t})=>C({name:U(t),canTrack:!0}),Xt=({contentId:t,value:e})=>T({name:U(t),value:e,canTrack:!0}),ot=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},it=t=>{const e=Ht(t);return Xt({contentId:t.id,value:e}).catch(n=>{d.error("could not store A/B test variation: ",n)}),e},at=({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(!ot(t))return t;const n=zt({contentId:t.id})||it({variations:t.variations,id:t.id}),r=at({item:t,testGroupId:n});return{...t,...r}},Yt=async({item:t,canTrack:e})=>{if(!e||!ot(t))return t;const r=await Jt({contentId:t.id})||it({variations:t.variations,id:t.id}),s=at({item:t,testGroupId:r});return{...t,...s}},K="builder.userAttributes";function Zt(){let t=!0;const e=new Set;return{setUserAttributes(n){if(!c())return;const r={...this.getUserAttributes(),...n};T({name:K,value:JSON.stringify(r),canTrack:t}),e.forEach(s=>s(r))},getUserAttributes(){return c()?JSON.parse(C({name:K,canTrack:t})||"{}"):{}},subscribeOnUserAttributesChange(n){return e.add(n),()=>{e.delete(n)}},setCanTrack(n){t=n}}}const B=Zt(),qt=t=>{B.setUserAttributes(t)},ct=t=>{const e=p(t)?t:!0;return B.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 ne=ee();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 ut(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("$"))?ut(s,o,n):n[o]=s}return n}function re(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 se="v3",_=t=>typeof t=="number"&&!isNaN(t)&&t>=0,R=t=>{const{limit:e=30,userAttributes:n,query:r,model:s,apiKey:o,enrich:i,locale:u,apiVersion:S=se,fields:m,omit:I,offset:l,cacheSeconds:g,staleCacheSeconds:h,sort:w,includeUnpublished:x,apiHost:gt}=t;if(!o)throw new Error("Missing API key");if(!["v3"].includes(S))throw new Error(`Invalid apiVersion: expected 'v3', received '${S}'`);const ht=e!==1,pt=gt||"https://cdn.builder.io",a=new URL(`${pt}/api/${S}/content/${s}`);a.searchParams.set("apiKey",o),a.searchParams.set("limit",String(e)),a.searchParams.set("noTraverse",String(ht)),a.searchParams.set("includeRefs",String(!0));const k=u||(n==null?void 0:n.locale);let b=n||{};if(k&&(a.searchParams.set("locale",k),b={locale:k,...b}),i&&a.searchParams.set("enrich",String(i)),a.searchParams.set("omit",I||"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)),g&&_(g)&&a.searchParams.set("cacheSeconds",String(g)),h&&_(h)&&a.searchParams.set("staleCacheSeconds",String(h)),w){const f=A({sort:w});for(const v in f)a.searchParams.set(v,JSON.stringify(f[v]))}const L={...At(),...j(t.options||{})};b={...b,...ie(L)};const F=A(L);for(const f in F)a.searchParams.set(f,String(F[f]));if(Object.keys(b).length>0&&a.searchParams.set("userAttributes",JSON.stringify(b)),r){const f=ut({query:r});for(const v in f)a.searchParams.set(v,JSON.stringify(f[v]))}return a},oe=t=>{const e={};for(const n in t)n.startsWith("userAttributes.")&&(e[n]=t[n],delete t[n]);return e},ie=t=>{if(c()&&t.preview==="BUILDER_STUDIO"){t["userAttributes.urlPath"]=window.location.pathname,t["userAttributes.host"]=window.location.host;const e=oe(t),{userAttributes:n}=re(e);return n}return{}},ae=t=>"results"in t;async function lt(t){const e=await ft({...t,limit:1});return e&&e[0]||null}const ce=async t=>{var i,u;const e=R(t),n=(i=t.fetch)!=null?i:ne,r={...t.fetchOptions,headers:{...(u=t.fetchOptions)==null?void 0:u.headers,...X()}};return await(await n(e.href,r)).json()},dt=async(t,e,n=R(t))=>{const r=ct(t.canTrack);if(n.search.includes("preview="),!r||!(c()||y==="reactNative"))return e.results;try{const s=[];for(const o of e.results)s.push(await Yt({item:o,canTrack:r}));e.results=s}catch(s){d.error("Could not process A/B tests. ",s)}return e.results};async function ft(t){const e=R(t),n=await ce(t);if(!ae(n))throw d.error("Error fetching data. ",{url:e,content:n,options:t}),n;return dt(t,n)}const ue=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 lt(n)}};exports.MSG_PREFIX=E;exports.TARGET=y;exports._processContentResult=dt;exports._track=et;exports.checkIsDefined=p;exports.createEditorListener=st;exports.createRegisterComponentMessage=vt;exports.fetchBuilderProps=ue;exports.fetchEntries=ft;exports.fetchOneEntry=lt;exports.getBuilderSearchParams=P;exports.getDefaultCanTrack=ct;exports.getUserAttributes=$;exports.handleABTestingSync=Qt;exports.isBrowser=c;exports.isEditing=G;exports.isPreviewing=wt;exports.logFetch=tt;exports.logger=d;exports.register=J;exports.registerInsertMenu=Wt;exports.serializeIncludingFunctions=O;exports.setClientUserAttributes=qt;exports.setEditorSettings=It;exports.setupBrowserForEditing=rt;exports.subscribeToEditor=Gt;exports.track=_t;exports.userAttributesService=B;
|