@builder.io/sdk-react 2.0.24 → 2.0.26
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 +5 -5
- package/lib/browser/blocks-exports.mjs +47 -41
- package/lib/browser/index.cjs +1 -1
- package/lib/browser/index.mjs +1 -1
- package/lib/browser/server-entry-720336f2.js +704 -0
- package/lib/browser/server-entry-f2c8ba91.cjs +2 -0
- package/lib/browser/server-entry.cjs +1 -1
- package/lib/browser/server-entry.mjs +1 -1
- package/lib/edge/{accordion-5b929fba.js → accordion-0a97d42c.js} +1 -1
- package/lib/edge/{accordion-bb9fa8d9.cjs → accordion-e8975004.cjs} +1 -1
- package/lib/edge/{blocks-cff95ab8.cjs → blocks-13ac260d.cjs} +1 -1
- package/lib/edge/{blocks-e8701f70.js → blocks-79d4ca8d.js} +3 -3
- package/lib/edge/blocks-exports.cjs +1 -1
- package/lib/edge/blocks-exports.mjs +2 -2
- package/lib/edge/{button-dd9c397c.js → button-17d873fa.js} +2 -2
- package/lib/edge/{button-89adbac2.cjs → button-a01a8a04.cjs} +1 -1
- package/lib/edge/{columns-acd49f06.js → columns-b8bb106c.js} +4 -4
- package/lib/edge/{columns-b0cfdce7.cjs → columns-c4c26bf0.cjs} +1 -1
- package/lib/edge/{content-variants-56c457f6.cjs → content-variants-32296e48.cjs} +8 -8
- package/lib/edge/{content-variants-2cbf3c83.js → content-variants-6560c3c8.js} +51 -45
- package/lib/edge/{evaluate-68711886.js → evaluate-1c58cb0f.js} +1 -1
- package/lib/edge/{evaluate-efa88e4b.cjs → evaluate-92fb6615.cjs} +1 -1
- package/lib/edge/{form-85e86f80.cjs → form-11832191.cjs} +1 -1
- package/lib/edge/{form-060579d1.js → form-d8609725.js} +4 -4
- package/lib/edge/{get-class-prop-name-bb0664a1.js → get-class-prop-name-1dd91564.js} +1 -1
- package/lib/edge/{get-class-prop-name-d6d04e54.cjs → get-class-prop-name-e5b5610b.cjs} +1 -1
- package/lib/edge/{img-cb9a2e73.js → img-bf66df07.js} +1 -1
- package/lib/edge/{img-7267e34a.cjs → img-d044ae25.cjs} +1 -1
- package/lib/edge/index.cjs +1 -1
- package/lib/edge/index.mjs +1 -1
- package/lib/edge/{input-0a7941d1.cjs → input-9340f0ba.cjs} +1 -1
- package/lib/edge/{input-99f775bd.js → input-ab613ef1.js} +1 -1
- package/lib/edge/{select-88a74342.js → select-c9f8f72d.js} +1 -1
- package/lib/edge/{select-9791ad44.cjs → select-cda5352c.cjs} +1 -1
- package/lib/edge/server-entry-4d4f2c4b.cjs +2 -0
- package/lib/edge/server-entry-c809a8ff.js +702 -0
- package/lib/edge/server-entry.cjs +1 -1
- package/lib/edge/server-entry.mjs +1 -1
- package/lib/edge/{slot-28b25c84.js → slot-69765c02.js} +4 -4
- package/lib/edge/{slot-d3b5cdb8.cjs → slot-b66c52dc.cjs} +1 -1
- package/lib/edge/{symbol-f0ba82bf.cjs → symbol-1b3f8d1f.cjs} +1 -1
- package/lib/edge/{symbol-1ab0fb76.js → symbol-335cfb65.js} +2 -2
- package/lib/edge/{tabs-a04af934.js → tabs-629e6a1f.js} +4 -4
- package/lib/edge/{tabs-fad92db1.cjs → tabs-bf6cc6f2.cjs} +1 -1
- package/lib/edge/{text-3c4c2e24.js → text-2d218073.js} +2 -2
- package/lib/edge/{text-ee3d6be2.cjs → text-ff5a8f9b.cjs} +1 -1
- package/lib/node/blocks-exports.cjs +7 -7
- package/lib/node/blocks-exports.mjs +49 -43
- package/lib/node/index.cjs +1 -1
- package/lib/node/index.mjs +2 -2
- package/lib/node/init.cjs +1 -1
- package/lib/node/init.mjs +2 -2
- package/lib/node/server-entry-12c82a21.js +705 -0
- package/lib/node/server-entry-ac34c1ae.cjs +2 -0
- package/lib/node/server-entry.cjs +1 -1
- package/lib/node/server-entry.mjs +1 -1
- package/lib/node/{should-force-browser-runtime-in-node-411c24f8.cjs → should-force-browser-runtime-in-node-1e38f5d9.cjs} +1 -1
- package/lib/node/{should-force-browser-runtime-in-node-2251f2e6.js → should-force-browser-runtime-in-node-94a10439.js} +1 -1
- package/package.json +1 -1
- package/types/components/content/components/enable-editor.d.ts +1 -1
- package/types/components/content-variants/content-variants.types.d.ts +4 -0
- package/types/constants/sdk-version.d.ts +1 -1
- package/types/functions/get-content/types.d.ts +4 -0
- package/types/functions/track/index.d.ts +3 -1
- package/types/helpers/sdk-headers.d.ts +5 -0
- package/lib/browser/server-entry-0dfca5e0.cjs +0 -2
- package/lib/browser/server-entry-578cd6e2.js +0 -690
- package/lib/edge/server-entry-a7db0ef9.js +0 -688
- package/lib/edge/server-entry-cb6fb618.cjs +0 -2
- package/lib/node/server-entry-2ce603a9.cjs +0 -2
- package/lib/node/server-entry-bf8bf121.js +0 -691
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";const y="react",le=e=>{const t={};return e.forEach((n,r)=>{t[r]=n}),t},V=e=>e instanceof URLSearchParams?le(e):e,M=e=>typeof e=="string"?e:e instanceof URLSearchParams?e.toString():new URLSearchParams(e).toString();function c(){return typeof window!="undefined"&&typeof document!="undefined"}function fe(){return c()&&window.self!==window.top}function F(e){return fe()&&M(e||window.location.search).indexOf("builder.frameEditing=")!==-1}function ge(e){const t=e||(c()?window.location.search:void 0);return t?M(t).indexOf("builder.preview=")!==-1:!1}const he=e=>({type:"builder.registerComponent",data:k(e)}),pe=e=>{const t=e.toString().trim();return`return (${!t.startsWith("function")&&!t.startsWith("(")?"function ":""}${t}).apply(this, arguments)`};function k(e){return JSON.parse(JSON.stringify(e,(t,n)=>typeof n=="function"?pe(n):n))}const x={};function N(e,t){e==="plugin"&&(t=k(t));let n=x[e];if(n||(n=x[e]=[]),n.push(t),c()){const r={type:"builder.register",data:{type:e,info:t}};try{parent.postMessage(r,"*"),parent!==window&&window.postMessage(r,"*")}catch(o){console.debug("Could not postmessage",o)}}}const B={};function me(e){if(c()){Object.assign(B,e);const t={type:"builder.settingsChange",data:B};parent.postMessage(t,"*")}}const R="builder.",ye="options.",P=e=>{if(!e)return{};const t=V(e),n={};return Object.keys(t).forEach(r=>{if(r.startsWith(R)){const o=r.replace(R,"").replace(ye,"");n[o]=t[r]}}),n},Se=()=>{if(!c())return{};const e=new URLSearchParams(window.location.search);return P(e)},I="[Builder.io]: ",l={log:(...e)=>console.log(I,...e),error:(...e)=>console.error(I,...e),warn:(...e)=>console.warn(I,...e),debug:(...e)=>console.debug(I,...e)},D="2.0.26",K=()=>({"X-Builder-SDK":y,"X-Builder-SDK-GEN":"2","X-Builder-SDK-Version":D}),p=e=>e!=null,we=e=>{if(e==="localhost"||e==="127.0.0.1")return e;const t=e.split(".");return t.length>2?t.slice(1).join("."):e},j=({name:e,canTrack:t})=>{var n;try{return t?(n=document.cookie.split("; ").find(r=>r.startsWith(`${e}=`)))==null?void 0:n.split("=")[1]:void 0}catch(r){l.warn("[COOKIE] GET error: ",(r==null?void 0:r.message)||r);return}},W=async e=>j(e),be=e=>e.map(([t,n])=>n?`${t}=${n}`:t).filter(p).join("; "),Ie=[["secure",""],["SameSite","None"]],ve=({name:e,value:t,expires:n})=>{const o=(c()?location.protocol==="https:":!0)?Ie:[[]],s=n?[["expires",n.toUTCString()]]:[[]],i=[[e,t],...s,["path","/"],["domain",we(window.location.hostname)],...o];return be(i)},$=async({name:e,value:t,expires:n,canTrack:r})=>{try{if(!r)return;const o=ve({name:e,value:t,expires:n});document.cookie=o}catch(o){l.warn("[COOKIE] SET error: ",(o==null?void 0:o.message)||o)}};function Ee(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){const t=Math.random()*16|0;return(e=="x"?t:t&3|8).toString(16)})}function _(){return Ee().replace(/-/g,"")}const G="builderSessionId",ke=async({canTrack:e})=>{if(!e)return;const t=await W({name:G,canTrack:e});if(p(t))return t;{const n=Pe();return Oe({id:n,canTrack:e}),n}},Pe=()=>_(),Oe=({id:e,canTrack:t})=>$({name:G,value:e,canTrack:t}),H=()=>c()&&typeof localStorage!="undefined"?localStorage:void 0,Ce=({key:e,canTrack:t})=>{var n;try{return t?(n=H())==null?void 0:n.getItem(e):void 0}catch(r){console.debug("[LocalStorage] GET error: ",r);return}},Ae=({key:e,canTrack:t,value:n})=>{var r;try{t&&((r=H())==null||r.setItem(e,n))}catch(o){console.debug("[LocalStorage] SET error: ",o)}},X="builderVisitorId",Te=({canTrack:e})=>{if(!e)return;const t=Ce({key:X,canTrack:e});if(p(t))return t;{const n=xe();return Be({id:n,canTrack:e}),n}},xe=()=>_(),Be=({id:e,canTrack:t})=>Ae({key:X,value:e,canTrack:t}),Re=()=>{if(c()){const e=new URL(location.href);return e.pathname===""&&(e.pathname="/"),e}else return console.warn("Cannot get location for tracking in non-browser environment"),null},Le=()=>typeof navigator=="object"&&navigator.userAgent||"",z=()=>{const e=Le(),t={Android(){return e.match(/Android/i)},BlackBerry(){return e.match(/BlackBerry/i)},iOS(){return e.match(/iPhone|iPod/i)},Opera(){return e.match(/Opera Mini/i)},Windows(){return e.match(/IEMobile/i)||e.match(/WPDesktop/i)},any(){return t.Android()||t.BlackBerry()||t.iOS()||t.Opera()||t.Windows()||y==="reactNative"}},n=e.match(/Tablet|iPad/i),r=Re();return{urlPath:r==null?void 0:r.pathname,host:(r==null?void 0:r.host)||(r==null?void 0:r.hostname),device:n?"tablet":t.any()?"mobile":"desktop"}},Ue=async({canTrack:e})=>{if(!e)return{visitorId:void 0,sessionId:void 0};const t=await ke({canTrack:e}),n=Te({canTrack:e});return{sessionId:t,visitorId:n}},Ve=async({type:e,canTrack:t,apiKey:n,metadata:r,...o})=>({type:e,data:{...o,metadata:{url:location.href,...r},...await Ue({canTrack:t}),userAttributes:z(),ownerId:n}});async function J({apiHost:e,...t}){if(!t.apiKey){l.error("Missing API key for track call. Please provide your API key.");return}return!t.canTrack||F()||!(c()||y==="reactNative")?void 0:fetch(`${e||"https://cdn.builder.io"}/api/v1/track`,{method:"POST",body:JSON.stringify({events:[await Ve(t)]}),headers:{"content-type":"application/json",...K()},mode:"cors"}).catch(r=>{console.error("Failed to track: ",r)})}const Me=e=>J({...e,canTrack:!0}),Fe=["*.beta.builder.io","beta.builder.io","builder.io","localhost","qa.builder.io"];function q(e,t){if(!t.origin.startsWith("http")&&!t.origin.startsWith("https"))return!1;const n=new URL(t.origin),r=n.hostname;return(e||Fe).findIndex(o=>o.startsWith("*.")?r.endsWith(o.slice(1)):o===r)>-1}const Ne=()=>{N("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 L=!1;const Q=(e={})=>{var t,n;L||(L=!0,c()&&((t=window.parent)==null||t.postMessage({type:"builder.sdkInfo",data:{target:y,version:D,supportsPatchUpdates:!1,supportsAddBlockScoping:!0,supportsCustomBreakpoints:!0}},"*"),(n=window.parent)==null||n.postMessage({type:"builder.updateContent",data:{options:e}},"*"),window.addEventListener("message",r=>{var s,i;if(!q(e.trustedHosts,r))return;const{data:o}=r;if(o!=null&&o.type)switch(o.type){case"builder.evaluate":{const u=o.data.text,S=o.data.arguments||[],m=o.data.id,v=new Function(u);let d,g=null;try{d=v.apply(null,S)}catch(h){g=h}g?(s=window.parent)==null||s.postMessage({type:"builder.evaluateError",data:{id:m,error:g.message}},"*"):d&&typeof d.then=="function"?d.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:d,id:m}},"*");break}}})))},Y=({model:e,trustedHosts:t,callbacks:n})=>r=>{if(!q(t,r))return;const{data:o}=r;if(o)switch(o.type){case"builder.configureSdk":{n.configureSdk(o.data);break}case"builder.triggerAnimation":{n.animation(o.data);break}case"builder.contentUpdate":{const s=o.data,i=s.key||s.alias||s.entry||s.modelName,u=s.data;i===e&&n.contentUpdate(u);break}}},De=(e,t,n)=>{if(!c)return l.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server."),()=>{};Q();const r=Y({callbacks:{contentUpdate:t,animation:()=>{},configureSdk:()=>{}},model:e,trustedHosts:n==null?void 0:n.trustedHosts});return window.addEventListener("message",r),()=>{window.removeEventListener("message",r)}},Ke="builder.tests",O=e=>`${Ke}.${e}`,je=({contentId:e})=>W({name:O(e),canTrack:!0}),We=({contentId:e})=>j({name:O(e),canTrack:!0}),$e=({contentId:e,value:t})=>$({name:O(e),value:t,canTrack:!0}),Z=e=>p(e.id)&&p(e.variations)&&Object.keys(e.variations).length>0,_e=({id:e,variations:t})=>{var o;let n=0;const r=Math.random();for(const s in t){const i=(o=t[s])==null?void 0:o.testRatio;if(n+=i,r<n)return s}return e},ee=e=>{const t=_e(e);return $e({contentId:e.id,value:t}).catch(n=>{l.error("could not store A/B test variation: ",n)}),t},te=({item:e,testGroupId:t})=>{const n=e.variations[t];return t===e.id||!n?{testVariationId:e.id,testVariationName:"Default"}:{data:n.data,testVariationId:n.id,testVariationName:n.name||(n.id===e.id?"Default":"")}},Ge=({item:e,canTrack:t})=>{if(!t)return e;if(!e)return;if(!Z(e))return e;const n=We({contentId:e.id})||ee({variations:e.variations,id:e.id}),r=te({item:e,testGroupId:n});return{...e,...r}},He=async({item:e,canTrack:t})=>{if(!t||!Z(e))return e;const r=await je({contentId:e.id})||ee({variations:e.variations,id:e.id}),o=te({item:e,testGroupId:r});return{...e,...o}},ne=e=>p(e)?e:!0;function Xe(){return typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:globalThis}function ze(){const e=Xe().fetch;if(typeof e=="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 e}const Je=ze();function E(e,t=null,n="."){return Object.keys(e).reduce((r,o)=>{const s=e[o],i=[t,o].filter(Boolean).join(n);return[typeof s=="object",s!==null,!(Array.isArray(s)&&s.length===0)].every(Boolean)?{...r,...E(s,i,n)}:{...r,[i]:s}},{})}function re(e,t,n={}){for(const r in e){const o=e[r],s=t?t+"."+r:r;o&&typeof o=="object"&&!Array.isArray(o)&&!Object.keys(o).find(i=>i.startsWith("$"))?re(o,s,n):n[s]=o}return n}const qe="v3",U=e=>typeof e=="number"&&!isNaN(e)&&e>=0,C=e=>{const{limit:t=30,userAttributes:n,query:r,model:o,apiKey:s,enrich:i,locale:u,apiVersion:S=qe,fields:m,omit:v,offset:d,cacheSeconds:g,staleCacheSeconds:h,sort:w,includeUnpublished:A,apiHost:ae}=e;if(!s)throw new Error("Missing API key");if(!["v3"].includes(S))throw new Error(`Invalid apiVersion: expected 'v3', received '${S}'`);const ce=t!==1,ue=ae||"https://cdn.builder.io",a=new URL(`${ue}/api/${S}/content/${o}`);if(a.searchParams.set("apiKey",s),a.searchParams.set("limit",String(t)),a.searchParams.set("noTraverse",String(ce)),a.searchParams.set("includeRefs",String(!0)),u&&a.searchParams.set("locale",u),i&&a.searchParams.set("enrich",String(i)),a.searchParams.set("omit",v||"meta.componentsUsed"),m&&a.searchParams.set("fields",m),Number.isFinite(d)&&d>-1&&a.searchParams.set("offset",String(Math.floor(d))),typeof A=="boolean"&&a.searchParams.set("includeUnpublished",String(A)),g&&U(g)&&a.searchParams.set("cacheSeconds",String(g)),h&&U(h)&&a.searchParams.set("staleCacheSeconds",String(h)),w){const f=E({sort:w});for(const b in f)a.searchParams.set(b,JSON.stringify(f[b]))}const de={...Se(),...V(e.options||{})},T=E(de);for(const f in T)a.searchParams.set(f,String(T[f]));if(n&&a.searchParams.set("userAttributes",JSON.stringify(n)),r){const f=re({query:r});for(const b in f)a.searchParams.set(b,JSON.stringify(f[b]))}return a},Qe=e=>"results"in e;async function oe(e){const t=await ie({...e,limit:1});return t&&t[0]||null}const Ye=async e=>{var i,u;const t=C(e),n=(i=e.fetch)!=null?i:Je,r={...e.fetchOptions,headers:{...(u=e.fetchOptions)==null?void 0:u.headers,...K()}};return await(await n(t.href,r)).json()},se=async(e,t,n=C(e))=>{const r=ne(e.canTrack);if(n.search.includes("preview="),!r||!(c()||y==="reactNative"))return t.results;try{const o=[];for(const s of t.results)o.push(await He({item:s,canTrack:r}));t.results=o}catch(o){l.error("Could not process A/B tests. ",o)}return t.results};async function ie(e){try{const t=C(e),n=await Ye(e);return Qe(n)?se(e,n):(l.error("Error fetching data. ",{url:t,content:n,options:e}),null)}catch(t){return l.error("Error fetching data. ",t),null}}const Ze=async e=>{var r,o,s;const t=e.path||((r=e.url)==null?void 0:r.pathname)||((o=e.userAttributes)==null?void 0:o.urlPath),n={...e,apiKey:e.apiKey,model:e.model||"page",userAttributes:{...e.userAttributes,...t?{urlPath:t}:{}},options:P(e.searchParams||((s=e.url)==null?void 0:s.searchParams)||e.options)};return{apiKey:n.apiKey,model:n.model,content:await oe(n)}};exports.TARGET=y;exports._processContentResult=se;exports._track=J;exports.checkIsDefined=p;exports.createEditorListener=Y;exports.createRegisterComponentMessage=he;exports.fetchBuilderProps=Ze;exports.fetchEntries=ie;exports.fetchOneEntry=oe;exports.getBuilderSearchParams=P;exports.getDefaultCanTrack=ne;exports.getUserAttributes=z;exports.handleABTestingSync=Ge;exports.isBrowser=c;exports.isEditing=F;exports.isPreviewing=ge;exports.logger=l;exports.register=N;exports.registerInsertMenu=Ne;exports.serializeIncludingFunctions=k;exports.setEditorSettings=me;exports.setupBrowserForEditing=Q;exports.subscribeToEditor=De;exports.track=Me;
|