@builder.io/sdk-react 2.0.2 → 2.0.3
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 +25 -25
- package/lib/browser/blocks-exports.mjs +120 -119
- package/lib/browser/index.cjs +1 -1
- package/lib/browser/index.mjs +1 -1
- package/lib/browser/init.cjs +1 -1
- package/lib/browser/init.mjs +1 -1
- package/lib/browser/server-entry-02cecfb7.cjs +2 -0
- package/lib/browser/server-entry-0687830a.js +688 -0
- package/lib/browser/server-entry.cjs +1 -1
- package/lib/browser/server-entry.mjs +1 -1
- package/lib/edge/{accordion-ca081054.js → accordion-0eca9b08.js} +1 -1
- package/lib/edge/{accordion-4f96554c.cjs → accordion-368a2cf8.cjs} +1 -1
- package/lib/edge/{blocks-f55c7d3e.js → blocks-db3cfcac.js} +130 -129
- package/lib/edge/blocks-exports.cjs +1 -1
- package/lib/edge/blocks-exports.mjs +2 -2
- package/lib/edge/{blocks-078044bc.cjs → blocks-f524a758.cjs} +13 -13
- package/lib/edge/{button-5d140f8e.cjs → button-3ed29654.cjs} +1 -1
- package/lib/edge/{button-41169061.js → button-e852700f.js} +2 -2
- package/lib/edge/columns-1f84e26e.cjs +28 -0
- package/lib/edge/{columns-f8916a18.js → columns-ee464f6c.js} +49 -48
- package/lib/edge/{content-variants-89a9389a.cjs → content-variants-42f2495b.cjs} +4 -4
- package/lib/edge/{content-variants-71ee0c76.js → content-variants-c0257a99.js} +23 -23
- package/lib/edge/{form-f2d2c2bf.cjs → form-4444faf2.cjs} +1 -1
- package/lib/edge/{form-ac2f2a0e.js → form-8191004e.js} +3 -3
- package/lib/edge/{get-class-prop-name-a9b4959e.cjs → get-class-prop-name-5fc98fcc.cjs} +1 -1
- package/lib/edge/{get-class-prop-name-a677d7a5.js → get-class-prop-name-d18337d2.js} +1 -1
- package/lib/edge/{img-b91cb4fd.cjs → img-10ef20a5.cjs} +1 -1
- package/lib/edge/{img-8fc26395.js → img-a24ed75f.js} +1 -1
- package/lib/edge/index.cjs +1 -1
- package/lib/edge/index.mjs +1 -1
- package/lib/edge/init.cjs +1 -1
- package/lib/edge/init.mjs +1 -1
- package/lib/edge/{input-549f090e.js → input-3876429d.js} +1 -1
- package/lib/edge/{input-ec7c695a.cjs → input-6325bfc0.cjs} +1 -1
- package/lib/edge/{select-3ffa9294.cjs → select-3f0f00f3.cjs} +1 -1
- package/lib/edge/{select-6a5a28ac.js → select-5dc1c7d1.js} +1 -1
- package/lib/edge/server-entry-805b9266.cjs +2 -0
- package/lib/edge/server-entry-ff728468.js +689 -0
- package/lib/edge/server-entry.cjs +1 -1
- package/lib/edge/server-entry.mjs +1 -1
- package/lib/edge/{slot-40de071b.js → slot-20fe5e4f.js} +3 -3
- package/lib/edge/{slot-8b27e15e.cjs → slot-a64b535f.cjs} +1 -1
- package/lib/edge/{symbol-76e76298.cjs → symbol-5012ed02.cjs} +1 -1
- package/lib/edge/{symbol-e6515a5f.js → symbol-e95082e1.js} +2 -2
- package/lib/edge/{tabs-b75be82d.js → tabs-261e8cd4.js} +3 -3
- package/lib/edge/{tabs-9c5af0ec.cjs → tabs-d672f816.cjs} +1 -1
- package/lib/node/blocks-exports.cjs +11 -11
- package/lib/node/blocks-exports.mjs +74 -73
- 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/{node-runtime-0e37d6f7.cjs → node-runtime-160b6846.cjs} +2 -2
- package/lib/node/{node-runtime-0f3a5df1.js → node-runtime-405effc5.js} +3 -2
- package/lib/node/server-entry-02cecfb7.cjs +2 -0
- package/lib/node/server-entry-0687830a.js +688 -0
- package/lib/node/server-entry.cjs +1 -1
- package/lib/node/server-entry.mjs +1 -1
- package/package.json +1 -1
- package/types/constants/sdk-version.d.ts +1 -1
- package/types/functions/register-component.d.ts +2 -2
- package/lib/browser/server-entry-419c051e.cjs +0 -2
- package/lib/browser/server-entry-825b4408.js +0 -695
- package/lib/edge/columns-354bf349.cjs +0 -28
- package/lib/edge/server-entry-966ac144.cjs +0 -2
- package/lib/edge/server-entry-d2020acf.js +0 -695
- package/lib/node/server-entry-5ebd1c9b.js +0 -695
- package/lib/node/server-entry-8002325b.cjs +0 -2
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";const I="react",ue=e=>{const t={};return e.forEach((n,r)=>{t[r]=n}),t},M=e=>e instanceof URLSearchParams?ue(e):e,U=e=>typeof e=="string"?e:e instanceof URLSearchParams?e.toString():new URLSearchParams(e).toString();function c(){return typeof window!="undefined"&&typeof document!="undefined"}function de(){return c()&&window.self!==window.top}function F(e){return de()&&U(e||window.location.search).indexOf("builder.frameEditing=")!==-1}function le(e){const t=e||(c()?window.location.search:void 0);return t?U(t).indexOf("builder.preview=")!==-1:!1}const k=e=>JSON.parse(JSON.stringify(e)),fe=e=>({type:"builder.registerComponent",data:N(e)}),ge=e=>{const t=e.toString().trim();return`return (${!t.startsWith("function")&&!t.startsWith("(")?"function ":""}${t}).apply(this, arguments)`},he=e=>typeof e=="function"?ge(e):k(e),N=({inputs:e,...t})=>({...k(t),inputs:e==null?void 0:e.map(n=>Object.entries(n).reduce((r,[o,s])=>({...r,[o]:he(s)}),{}))}),x={};function D(e,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 R={};function pe(e){if(c()){Object.assign(R,e);const t={type:"builder.settingsChange",data:R};parent.postMessage(t,"*")}}const B="builder.",me="options.",C=e=>{if(!e)return{};const t=M(e),n={};return Object.keys(t).forEach(r=>{if(r.startsWith(B)){const o=r.replace(B,"").replace(me,"");n[o]=t[r]}}),n},ye=()=>{if(!c())return{};const e=new URLSearchParams(window.location.search);return C(e)},b="[Builder.io]: ",d={log:(...e)=>console.log(b,...e),error:(...e)=>console.error(b,...e),warn:(...e)=>console.warn(b,...e),debug:(...e)=>console.debug(b,...e)},p=e=>e!=null,Se=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){d.warn("[COOKIE] GET error: ",(r==null?void 0:r.message)||r);return}},K=async e=>j(e),we=e=>e.map(([t,n])=>n?`${t}=${n}`:t).filter(p).join("; "),be=[["secure",""],["SameSite","None"]],Ie=({name:e,value:t,expires:n})=>{const o=(c()?location.protocol==="https:":!0)?be:[[]],s=n?[["expires",n.toUTCString()]]:[[]],a=[[e,t],...s,["path","/"],["domain",Se(window.location.hostname)],...o];return we(a)},_=async({name:e,value:t,expires:n,canTrack:r})=>{try{if(!r)return;const o=Ie({name:e,value:t,expires:n});document.cookie=o}catch(o){d.warn("[COOKIE] SET error: ",(o==null?void 0:o.message)||o)}};function ve(){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 W(){return ve().replace(/-/g,"")}const $="builderSessionId",Ee=async({canTrack:e})=>{if(!e)return;const t=await K({name:$,canTrack:e});if(p(t))return t;{const n=ke();return Ce({id:n,canTrack:e}),n}},ke=()=>W(),Ce=({id:e,canTrack:t})=>_({name:$,value:e,canTrack:t}),G=()=>c()&&typeof localStorage!="undefined"?localStorage:void 0,Pe=({key:e,canTrack:t})=>{var n;try{return t?(n=G())==null?void 0:n.getItem(e):void 0}catch(r){console.debug("[LocalStorage] GET error: ",r);return}},Oe=({key:e,canTrack:t,value:n})=>{var r;try{t&&((r=G())==null||r.setItem(e,n))}catch(o){console.debug("[LocalStorage] SET error: ",o)}},z="builderVisitorId",Ae=({canTrack:e})=>{if(!e)return;const t=Pe({key:z,canTrack:e});if(p(t))return t;{const n=Te();return xe({id:n,canTrack:e}),n}},Te=()=>W(),xe=({id:e,canTrack:t})=>Oe({key:z,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},Be=()=>typeof navigator=="object"&&navigator.userAgent||"",J=()=>{const e=Be(),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()||I==="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"}},Le=async({canTrack:e})=>{if(!e)return{visitorId:void 0,sessionId:void 0};const t=await Ee({canTrack:e}),n=Ae({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 Le({canTrack:t}),userAttributes:J(),ownerId:n}});async function H(e){if(!e.apiKey){d.error("Missing API key for track call. Please provide your API key.");return}if(e.canTrack&&!F()&&(c()||I==="reactNative"))return fetch("https://cdn.builder.io/api/v1/track",{method:"POST",body:JSON.stringify({events:[await Ve(e)]}),headers:{"content-type":"application/json"},mode:"cors"}).catch(t=>{console.error("Failed to track: ",t)})}const Me=e=>H({...e,canTrack:!0}),Ue=["*.beta.builder.io","beta.builder.io","builder.io","localhost","qa.builder.io"];function X(e,t){if(!t.origin.startsWith("http")&&!t.origin.startsWith("https"))return!1;const n=new URL(t.origin),r=n.hostname;return(e||Ue).findIndex(o=>o.startsWith("*.")?r.endsWith(o.slice(1)):o===r)>-1}const Fe="2.0.2",Ne=()=>{D("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:I,version:Fe,supportsPatchUpdates:!1,supportsAddBlockScoping:!0,supportsCustomBreakpoints:!0}},"*"),(n=window.parent)==null||n.postMessage({type:"builder.updateContent",data:{options:e}},"*"),window.addEventListener("message",r=>{var s,a;if(!X(e.trustedHosts,r))return;const{data:o}=r;if(o!=null&&o.type)switch(o.type){case"builder.evaluate":{const l=o.data.text,y=o.data.arguments||[],m=o.data.id,v=new Function(l);let u,g=null;try{u=v.apply(null,y)}catch(h){g=h}g?(s=window.parent)==null||s.postMessage({type:"builder.evaluateError",data:{id:m,error:g.message}},"*"):u&&typeof u.then=="function"?u.then(h=>{var S;(S=window.parent)==null||S.postMessage({type:"builder.evaluateResult",data:{id:m,result:h}},"*")}).catch(console.error):(a=window.parent)==null||a.postMessage({type:"builder.evaluateResult",data:{result:u,id:m}},"*");break}}})))},Q=({model:e,trustedHosts:t,callbacks:n})=>r=>{if(!X(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,a=s.key||s.alias||s.entry||s.modelName,l=s.data;a===e&&n.contentUpdate(l);break}}},De=(e,t,n)=>{if(!c)return d.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server."),()=>{};q();const r=Q({callbacks:{contentUpdate:t,animation:()=>{},configureSdk:()=>{}},model:e,trustedHosts:n==null?void 0:n.trustedHosts});return window.addEventListener("message",r),()=>{window.removeEventListener("message",r)}},je="builder.tests",P=e=>`${je}.${e}`,Ke=({contentId:e})=>K({name:P(e),canTrack:!0}),_e=({contentId:e})=>j({name:P(e),canTrack:!0}),We=({contentId:e,value:t})=>_({name:P(e),value:t,canTrack:!0}),Y=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 a=(o=t[s])==null?void 0:o.testRatio;if(n+=a,r<n)return s}return e},Z=e=>{const t=$e(e);return We({contentId:e.id,value:t}).catch(n=>{d.error("could not store A/B test variation: ",n)}),t},ee=({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(!Y(e))return e;const n=_e({contentId:e.id})||Z({variations:e.variations,id:e.id}),r=ee({item:e,testGroupId:n});return{...e,...r}},ze=async({item:e,canTrack:t})=>{if(!t||!Y(e))return e;const r=await Ke({contentId:e.id})||Z({variations:e.variations,id:e.id}),o=ee({item:e,testGroupId:r});return{...e,...o}},te=e=>p(e)?e:!0;function Je(){return typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:globalThis}function He(){const e=Je().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 ne=He();function E(e,t=null,n="."){return Object.keys(e).reduce((r,o)=>{const s=e[o],a=[t,o].filter(Boolean).join(n);return[typeof s=="object",s!==null,!(Array.isArray(s)&&s.length===0)].every(Boolean)?{...r,...E(s,a,n)}:{...r,[a]: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(a=>a.startsWith("$"))?re(o,s,n):n[s]=o}return n}const Xe="v3",V=e=>typeof e=="number"&&!isNaN(e)&&e>=0,O=e=>{const{limit:t=30,userAttributes:n,query:r,model:o,apiKey:s,enrich:a,locale:l,apiVersion:y=Xe,fields:m,omit:v,offset:u,cacheSeconds:g,staleCacheSeconds:h,sort:S,includeUnpublished:A}=e;if(!s)throw new Error("Missing API key");if(!["v3"].includes(y))throw new Error(`Invalid apiVersion: expected 'v3', received '${y}'`);const ae=t!==1,i=new URL(`https://cdn.builder.io/api/${y}/content/${o}`);if(i.searchParams.set("apiKey",s),i.searchParams.set("limit",String(t)),i.searchParams.set("noTraverse",String(ae)),i.searchParams.set("includeRefs",String(!0)),l&&i.searchParams.set("locale",l),a&&i.searchParams.set("enrich",String(a)),i.searchParams.set("omit",v||"meta.componentsUsed"),m&&i.searchParams.set("fields",m),Number.isFinite(u)&&u>-1&&i.searchParams.set("offset",String(Math.floor(u))),typeof A=="boolean"&&i.searchParams.set("includeUnpublished",String(A)),g&&V(g)&&i.searchParams.set("cacheSeconds",String(g)),h&&V(h)&&i.searchParams.set("staleCacheSeconds",String(h)),S){const f=E({sort:S});for(const w in f)i.searchParams.set(w,JSON.stringify(f[w]))}const ce={...ye(),...M(e.options||{})},T=E(ce);for(const f in T)i.searchParams.set(f,String(T[f]));if(n&&i.searchParams.set("userAttributes",JSON.stringify(n)),r){const f=re({query:r});for(const w in f)i.searchParams.set(w,JSON.stringify(f[w]))}return i},qe=e=>"results"in e;async function oe(e){const t=await ie({...e,limit:1});return t&&t[0]||null}const Qe=async e=>{var s;const t=O(e);return await(await((s=e.fetch)!=null?s:ne)(t.href,e.fetchOptions)).json()},se=async(e,t,n=O(e))=>{const r=te(e.canTrack);if(n.search.includes("preview="),!r||!(c()||I==="reactNative"))return t.results;try{const o=[];for(const s of t.results)o.push(await ze({item:s,canTrack:r}));t.results=o}catch(o){d.error("Could not process A/B tests. ",o)}return t.results};async function ie(e){try{const t=O(e),n=await Qe(e);return qe(n)?se(e,n):(d.error("Error fetching data. ",{url:t,content:n,options:e}),null)}catch(t){return d.error("Error fetching data. ",t),null}}const Ye=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:C(e.searchParams||((s=e.url)==null?void 0:s.searchParams)||e.options)};return{apiKey:n.apiKey,model:n.model,content:await oe(n)}};exports.MSG_PREFIX=b;exports.TARGET=I;exports._processContentResult=se;exports._track=H;exports.checkIsDefined=p;exports.createEditorListener=Q;exports.createRegisterComponentMessage=fe;exports.fastClone=k;exports.fetch=ne;exports.fetchBuilderProps=Ye;exports.fetchEntries=ie;exports.fetchOneEntry=oe;exports.getBuilderSearchParams=C;exports.getDefaultCanTrack=te;exports.getUserAttributes=J;exports.handleABTestingSync=Ge;exports.isBrowser=c;exports.isEditing=F;exports.isPreviewing=le;exports.logger=d;exports.register=D;exports.registerInsertMenu=Ne;exports.serializeComponentInfo=N;exports.setEditorSettings=pe;exports.setupBrowserForEditing=q;exports.subscribeToEditor=De;exports.track=Me;
|