@builder.io/sdk-react 1.0.14 → 1.0.16
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 +48 -24
- package/lib/browser/index.cjs +1 -1
- package/lib/browser/index.mjs +1 -1
- package/lib/browser/server-entry-11e01841.cjs +2 -0
- package/lib/browser/{server-entry-df552d27.js → server-entry-afeff3cb.js} +16 -15
- package/lib/browser/server-entry.cjs +1 -1
- package/lib/browser/server-entry.mjs +1 -1
- package/lib/edge/{blocks-dbf6f051.js → blocks-8e5cc463.js} +10 -4
- package/lib/edge/{blocks-75e914c4.cjs → blocks-a0a9d452.cjs} +2 -2
- package/lib/edge/blocks-exports.cjs +1 -1
- package/lib/edge/blocks-exports.mjs +2 -2
- package/lib/edge/{button-4e7f9eff.cjs → button-66c46316.cjs} +1 -1
- package/lib/edge/{button-db8d78a4.js → button-764707c4.js} +2 -2
- package/lib/edge/{columns-8399aa74.cjs → columns-0a14db0e.cjs} +2 -2
- package/lib/edge/{columns-9765610b.js → columns-0bdc7586.js} +27 -27
- package/lib/edge/{content-variants-ed22bfec.cjs → content-variants-c03ec7a1.cjs} +8 -8
- package/lib/edge/{content-variants-9a129944.js → content-variants-db1e0281.js} +140 -122
- package/lib/edge/{form-7a73e99c.js → form-7a6f998f.js} +3 -3
- package/lib/edge/{form-bc7b5558.cjs → form-a5d18c89.cjs} +1 -1
- package/lib/edge/{get-class-prop-name-83fffba1.js → get-class-prop-name-49cbb2c6.js} +1 -1
- package/lib/edge/{get-class-prop-name-3c370466.cjs → get-class-prop-name-bbc4d2f3.cjs} +1 -1
- package/lib/edge/{img-7d93925c.cjs → img-058cb6f0.cjs} +1 -1
- package/lib/edge/{img-c944597b.js → img-c9630f56.js} +1 -1
- package/lib/edge/index.cjs +1 -1
- package/lib/edge/index.mjs +1 -1
- package/lib/edge/{input-d735cf41.js → input-3de90790.js} +1 -1
- package/lib/edge/{input-72be594b.cjs → input-ceacd029.cjs} +1 -1
- package/lib/edge/{select-3411462e.cjs → select-df72f987.cjs} +1 -1
- package/lib/edge/{select-5e67472b.js → select-ee266e60.js} +1 -1
- package/lib/edge/{server-entry-5e5c1898.js → server-entry-2b1068fd.js} +17 -16
- package/lib/edge/{server-entry-62fc8a1d.cjs → server-entry-ef266884.cjs} +2 -2
- package/lib/edge/server-entry.cjs +1 -1
- package/lib/edge/server-entry.mjs +1 -1
- package/lib/edge/{slot-04d29096.cjs → slot-83d735d6.cjs} +1 -1
- package/lib/edge/{slot-495693a8.js → slot-f246e67e.js} +3 -3
- package/lib/edge/{symbol-ad121694.cjs → symbol-991f09b3.cjs} +1 -1
- package/lib/edge/{symbol-c29e2a25.js → symbol-f68a7357.js} +2 -2
- package/lib/node/blocks-exports.cjs +9 -9
- package/lib/node/blocks-exports.mjs +257 -233
- package/lib/node/index.cjs +1 -1
- package/lib/node/index.mjs +1 -1
- package/lib/node/server-entry-4ba58cf3.cjs +2 -0
- package/lib/node/{server-entry-3a79d01e.js → server-entry-a221fe66.js} +16 -15
- package/lib/node/server-entry.cjs +1 -1
- package/lib/node/server-entry.mjs +1 -1
- package/package.json +1 -1
- package/types/components/content-variants/helpers.d.ts +1 -1
- package/types/components/inlined-script.d.ts +1 -1
- package/types/components/inlined-styles.d.ts +1 -1
- package/types/constants/sdk-version.d.ts +1 -1
- package/types/functions/get-content/types.d.ts +8 -0
- package/lib/browser/server-entry-742c121c.cjs +0 -2
- package/lib/node/server-entry-f5a4cdfa.cjs +0 -2
package/lib/node/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./blocks-exports.cjs"),e=require("./server-entry-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./blocks-exports.cjs"),e=require("./server-entry-4ba58cf3.cjs");require("react/jsx-runtime");require("react");exports.Blocks=t.Blocks;exports.Button=t.Button;exports.Columns=t.Columns;exports.Content=t.Content;exports.Fragment=t.Fragment;exports.Image=t.Image;exports.Section=t.Section;exports.Symbol=t.Symbol;exports.Text=t.Text;exports.Video=t.Video;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.setEditorSettings=e.setEditorSettings;exports.subscribeToEditor=e.subscribeToEditor;exports.track=e.track;
|
package/lib/node/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Blocks as i, Button as s, Columns as n, Content as c, Fragment as m, Image as g, Section as a, Symbol as p, Text as d, Video as l } from "./blocks-exports.mjs";
|
|
2
|
-
import { _processContentResult as f, createRegisterComponentMessage as E, fetchBuilderProps as h, fetchEntries as B, fetchOneEntry as C, getBuilderSearchParams as S, isEditing as b, isPreviewing as x, register as P, setEditorSettings as k, subscribeToEditor as y, track as R } from "./server-entry-
|
|
2
|
+
import { _processContentResult as f, createRegisterComponentMessage as E, fetchBuilderProps as h, fetchEntries as B, fetchOneEntry as C, getBuilderSearchParams as S, isEditing as b, isPreviewing as x, register as P, setEditorSettings as k, subscribeToEditor as y, track as R } from "./server-entry-a221fe66.js";
|
|
3
3
|
import "react/jsx-runtime";
|
|
4
4
|
import "react";
|
|
5
5
|
export {
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";const b="react",I="[Builder.io]: ",d={log:(...e)=>console.log(I,...e),error:(...e)=>console.error(I,...e),warn:(...e)=>console.warn(I,...e),debug:(...e)=>console.debug(I,...e)};function c(){return typeof window!="undefined"&&typeof document!="undefined"}const ce=e=>{const t={};return e.forEach((n,r)=>{t[r]=n}),t},M=e=>e instanceof URLSearchParams?ce(e):e,F=e=>typeof e=="string"?e:e instanceof URLSearchParams?e.toString():new URLSearchParams(e).toString();function ue(){return c()&&window.self!==window.top}function k(e){return ue()&&F(e||window.location.search).indexOf("builder.frameEditing=")!==-1}const de=()=>{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||"",N=()=>{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()||b==="reactNative"}},n=e.match(/Tablet|iPad/i),r=de();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"}},C=e=>JSON.parse(JSON.stringify(e)),p=e=>e!=null,fe=e=>{if(e==="localhost"||e==="127.0.0.1")return e;const t=e.split(".");return t.length>2?t.slice(1).join("."):e},D=({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}},j=async e=>D(e),ge=e=>e.map(([t,n])=>n?`${t}=${n}`:t).filter(p).join("; "),he=[["secure",""],["SameSite","None"]],pe=({name:e,value:t,expires:n})=>{const o=(c()?location.protocol==="https:":!0)?he:[[]],s=n?[["expires",n.toUTCString()]]:[[]],a=[[e,t],...s,["path","/"],["domain",fe(window.location.hostname)],...o];return ge(a)},_=async({name:e,value:t,expires:n,canTrack:r})=>{try{if(!r)return;const o=pe({name:e,value:t,expires:n});document.cookie=o}catch(o){d.warn("[COOKIE] SET error: ",(o==null?void 0:o.message)||o)}},me="builder.tests",P=e=>`${me}.${e}`,ye=({contentId:e})=>j({name:P(e),canTrack:!0}),we=({contentId:e})=>D({name:P(e),canTrack:!0}),Se=({contentId:e,value:t})=>_({name:P(e),value:t,canTrack:!0}),K=e=>p(e.id)&&p(e.variations)&&Object.keys(e.variations).length>0,be=({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},W=e=>{const t=be(e);return Se({contentId:e.id,value:t}).catch(n=>{d.error("could not store A/B test variation: ",n)}),t},$=({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":"")}},Ie=({item:e,canTrack:t})=>{if(!t)return e;if(!e)return;if(!K(e))return e;const n=we({contentId:e.id})||W({variations:e.variations,id:e.id}),r=$({item:e,testGroupId:n});return{...e,...r}},ve=async({item:e,canTrack:t})=>{if(!t||!K(e))return e;const r=await ye({contentId:e.id})||W({variations:e.variations,id:e.id}),o=$({item:e,testGroupId:r});return{...e,...o}},G=e=>p(e)?e:!0,Ee=e=>({type:"builder.registerComponent",data:z(e)}),ke=e=>{const t=e.toString().trim();return`return (${!t.startsWith("function")&&!t.startsWith("(")?"function ":""}${t}).apply(this, arguments)`},Ce=e=>typeof e=="function"?ke(e):C(e),z=({inputs:e,...t})=>({...C(t),inputs:e==null?void 0:e.map(n=>Object.entries(n).reduce((r,[o,s])=>({...r,[o]:Ce(s)}),{}))});function Pe(){return typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:globalThis}function Oe(){const e=Pe().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 J=Oe();function v(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,...v(s,a,n)}:{...r,[a]:s}},{})}const Te="v3",R="builder.",xe="options.",O=e=>{if(!e)return{};const t=M(e),n={};return Object.keys(t).forEach(r=>{if(r.startsWith(R)){const o=r.replace(R,"").replace(xe,"");n[o]=t[r]}}),n},Ae=()=>{if(!c())return{};const e=new URLSearchParams(window.location.search);return O(e)},B=e=>typeof e=="number"&&!isNaN(e)&&e>=0,T=e=>{const{limit:t=30,userAttributes:n,query:r,model:o,apiKey:s,enrich:a,locale:l,apiVersion:y=Te,fields:m,omit:E,offset:u,cacheSeconds:g,staleCacheSeconds:h,sort:w,includeUnpublished:x}=e;if(!s)throw new Error("Missing API key");if(!["v3"].includes(y))throw new Error(`Invalid apiVersion: expected 'v3', received '${y}'`);const ie=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(ie)),i.searchParams.set("includeRefs",String(!0)),l&&i.searchParams.set("locale",l),a&&i.searchParams.set("enrich",String(a)),i.searchParams.set("omit",E||"meta.componentsUsed"),m&&i.searchParams.set("fields",m),Number.isFinite(u)&&u>-1&&i.searchParams.set("offset",String(Math.floor(u))),typeof x=="boolean"&&i.searchParams.set("includeUnpublished",String(x)),g&&B(g)&&i.searchParams.set("cacheSeconds",String(g)),h&&B(h)&&i.searchParams.set("staleCacheSeconds",String(h)),w){const f=v({sort:w});for(const S in f)i.searchParams.set(S,JSON.stringify(f[S]))}const ae={...Ae(),...M(e.options||{})},A=v(ae);for(const f in A)i.searchParams.set(f,String(A[f]));if(n&&i.searchParams.set("userAttributes",JSON.stringify(n)),r){const f=v({query:r});for(const S in f)i.searchParams.set(S,JSON.stringify(f[S]))}return i},Re=e=>"results"in e;async function H(e){const t=await q({...e,limit:1});return t&&t[0]||null}const Be=async e=>{var s;const t=T(e);return await(await((s=e.fetch)!=null?s:J)(t.href,e.fetchOptions)).json()},X=async(e,t,n=T(e))=>{const r=G(e.canTrack);if(n.search.includes("preview="),!r||!(c()||b==="reactNative"))return t.results;try{const o=[];for(const s of t.results)o.push(await ve({item:s,canTrack:r}));t.results=o}catch(o){d.error("Could not process A/B tests. ",o)}return t.results};async function q(e){try{const t=T(e),n=await Be(e);return Re(n)?X(e,n):(d.error("Error fetching data. ",{url:t,content:n,options:e}),null)}catch(t){return d.error("Error fetching data. ",t),null}}function Le(e){if(!c())return!1;const t=F(e||window.location.search);return k(t)?!1:t.indexOf("builder.preview=")!==-1}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 Y(){return Ve().replace(/-/g,"")}const Q="builderSessionId",Ue=async({canTrack:e})=>{if(!e)return;const t=await j({name:Q,canTrack:e});if(p(t))return t;{const n=Me();return Fe({id:n,canTrack:e}),n}},Me=()=>Y(),Fe=({id:e,canTrack:t})=>_({name:Q,value:e,canTrack:t}),Z=()=>c()&&typeof localStorage!="undefined"?localStorage:void 0,Ne=({key:e,canTrack:t})=>{var n;try{return t?(n=Z())==null?void 0:n.getItem(e):void 0}catch(r){console.debug("[LocalStorage] GET error: ",r);return}},De=({key:e,canTrack:t,value:n})=>{var r;try{t&&((r=Z())==null||r.setItem(e,n))}catch(o){console.debug("[LocalStorage] SET error: ",o)}},ee="builderVisitorId",je=({canTrack:e})=>{if(!e)return;const t=Ne({key:ee,canTrack:e});if(p(t))return t;{const n=_e();return Ke({id:n,canTrack:e}),n}},_e=()=>Y(),Ke=({id:e,canTrack:t})=>De({key:ee,value:e,canTrack:t}),We=async({canTrack:e})=>{if(!e)return{visitorId:void 0,sessionId:void 0};const t=await Ue({canTrack:e}),n=je({canTrack:e});return{sessionId:t,visitorId:n}},$e=async({type:e,canTrack:t,apiKey:n,metadata:r,...o})=>({type:e,data:{...o,metadata:{url:location.href,...r},...await We({canTrack:t}),userAttributes:N(),ownerId:n}});async function te(e){if(!e.apiKey){d.error("Missing API key for track call. Please provide your API key.");return}if(e.canTrack&&!k()&&(c()||b==="reactNative"))return fetch("https://cdn.builder.io/api/v1/track",{method:"POST",body:JSON.stringify({events:[await $e(e)]}),headers:{"content-type":"application/json"},mode:"cors"}).catch(t=>{console.error("Failed to track: ",t)})}const Ge=e=>te({...e,canTrack:!0}),ze=["*.beta.builder.io","beta.builder.io","builder.io","localhost","qa.builder.io"];function ne(e,t){const n=new URL(t.origin),r=n.hostname;return(e||ze).findIndex(o=>o.startsWith("*.")?r.endsWith(o.slice(1)):o===r)>-1}const Je="1.0.16",L={};function re(e,t){let n=L[e];if(n||(n=L[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 He=()=>{re("insertMenu",{name:"_default",default:!0,items:[{name:"Box"},{name:"Text"},{name:"Image"},{name:"Columns"},{name:"Core:Section"},{name:"Core:Button"},{name:"Embed"},{name:"Custom Code"}]})};let V=!1;const oe=(e={})=>{var t,n;V||(V=!0,c()&&((t=window.parent)==null||t.postMessage({type:"builder.sdkInfo",data:{target:b,version:Je,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(!ne(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,E=new Function(l);let u,g=null;try{u=E.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 w;(w=window.parent)==null||w.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}}})))},se=({model:e,trustedHosts:t,callbacks:n})=>r=>{if(!ne(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}}},Xe=(e,t,n)=>{if(!c)return d.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server."),()=>{};oe();const r=se({callbacks:{contentUpdate:t,animation:()=>{},configureSdk:()=>{}},model:e,trustedHosts:n==null?void 0:n.trustedHosts});return window.addEventListener("message",r),()=>{window.removeEventListener("message",r)}},U={};function qe(e){if(c()){Object.assign(U,e);const t={type:"builder.settingsChange",data:U};parent.postMessage(t,"*")}}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:O(e.searchParams||((s=e.url)==null?void 0:s.searchParams)||e.options)};return{apiKey:n.apiKey,model:n.model,content:await H(n)}};exports.TARGET=b;exports._processContentResult=X;exports._track=te;exports.checkIsDefined=p;exports.createEditorListener=se;exports.createRegisterComponentMessage=Ee;exports.fastClone=C;exports.fetch=J;exports.fetchBuilderProps=Ye;exports.fetchEntries=q;exports.fetchOneEntry=H;exports.getBuilderSearchParams=O;exports.getDefaultCanTrack=G;exports.getUserAttributes=N;exports.handleABTestingSync=Ie;exports.isBrowser=c;exports.isEditing=k;exports.isPreviewing=Le;exports.logger=d;exports.register=re;exports.registerInsertMenu=He;exports.serializeComponentInfo=z;exports.setEditorSettings=qe;exports.setupBrowserForEditing=oe;exports.subscribeToEditor=Xe;exports.track=Ge;
|
|
@@ -189,17 +189,17 @@ const Z = () => {
|
|
|
189
189
|
}, fe = (e) => m(e) ? e : !0, Ge = (e) => ({
|
|
190
190
|
type: "builder.registerComponent",
|
|
191
191
|
data: pe(e)
|
|
192
|
-
}),
|
|
192
|
+
}), he = (e) => {
|
|
193
193
|
const t = e.toString().trim();
|
|
194
194
|
return `return (${!t.startsWith("function") && !t.startsWith("(") ? "function " : ""}${t}).apply(this, arguments)`;
|
|
195
|
-
},
|
|
195
|
+
}, ge = (e) => typeof e == "function" ? he(e) : M(e), pe = ({
|
|
196
196
|
inputs: e,
|
|
197
197
|
...t
|
|
198
198
|
}) => ({
|
|
199
199
|
...M(t),
|
|
200
200
|
inputs: e == null ? void 0 : e.map((n) => Object.entries(n).reduce((r, [o, s]) => ({
|
|
201
201
|
...r,
|
|
202
|
-
[o]:
|
|
202
|
+
[o]: ge(s)
|
|
203
203
|
}), {}))
|
|
204
204
|
});
|
|
205
205
|
function me() {
|
|
@@ -253,8 +253,8 @@ const Se = "v3", x = "builder.", be = "options.", W = (e) => {
|
|
|
253
253
|
fields: p,
|
|
254
254
|
omit: k,
|
|
255
255
|
offset: u,
|
|
256
|
-
cacheSeconds:
|
|
257
|
-
staleCacheSeconds:
|
|
256
|
+
cacheSeconds: h,
|
|
257
|
+
staleCacheSeconds: g,
|
|
258
258
|
sort: w,
|
|
259
259
|
includeUnpublished: C
|
|
260
260
|
} = e;
|
|
@@ -263,7 +263,7 @@ const Se = "v3", x = "builder.", be = "options.", W = (e) => {
|
|
|
263
263
|
if (!["v3"].includes(y))
|
|
264
264
|
throw new Error(`Invalid apiVersion: expected 'v3', received '${y}'`);
|
|
265
265
|
const X = t !== 1, i = new URL(`https://cdn.builder.io/api/${y}/content/${o}`);
|
|
266
|
-
if (i.searchParams.set("apiKey", s), i.searchParams.set("limit", String(t)), i.searchParams.set("noTraverse", String(X)), i.searchParams.set("includeRefs", String(!0)), d && i.searchParams.set("locale", d), a && i.searchParams.set("enrich", String(a)), i.searchParams.set("omit", k || "meta.componentsUsed"), p && i.searchParams.set("fields", p), Number.isFinite(u) && u > -1 && i.searchParams.set("offset", String(Math.floor(u))), typeof C == "boolean" && i.searchParams.set("includeUnpublished", String(C)),
|
|
266
|
+
if (i.searchParams.set("apiKey", s), i.searchParams.set("limit", String(t)), i.searchParams.set("noTraverse", String(X)), i.searchParams.set("includeRefs", String(!0)), d && i.searchParams.set("locale", d), a && i.searchParams.set("enrich", String(a)), i.searchParams.set("omit", k || "meta.componentsUsed"), p && i.searchParams.set("fields", p), Number.isFinite(u) && u > -1 && i.searchParams.set("offset", String(Math.floor(u))), typeof C == "boolean" && i.searchParams.set("includeUnpublished", String(C)), h && A(h) && i.searchParams.set("cacheSeconds", String(h)), g && A(g) && i.searchParams.set("staleCacheSeconds", String(g)), w) {
|
|
267
267
|
const l = I({
|
|
268
268
|
sort: w
|
|
269
269
|
});
|
|
@@ -293,8 +293,9 @@ async function ke(e) {
|
|
|
293
293
|
return t && t[0] || null;
|
|
294
294
|
}
|
|
295
295
|
const Ee = async (e) => {
|
|
296
|
+
var s;
|
|
296
297
|
const t = P(e);
|
|
297
|
-
return await (await we(t.href)).json();
|
|
298
|
+
return await (await ((s = e.fetch) != null ? s : we)(t.href, e.fetchOptions)).json();
|
|
298
299
|
}, Pe = async (e, t, n = P(e)) => {
|
|
299
300
|
const r = fe(e.canTrack);
|
|
300
301
|
if (n.search.includes("preview="), !r || !(c() || v === "reactNative"))
|
|
@@ -476,7 +477,7 @@ function H(e, t) {
|
|
|
476
477
|
const n = new URL(t.origin), r = n.hostname;
|
|
477
478
|
return (e || je).findIndex((o) => o.startsWith("*.") ? r.endsWith(o.slice(1)) : o === r) > -1;
|
|
478
479
|
}
|
|
479
|
-
const De = "1.0.
|
|
480
|
+
const De = "1.0.16", T = {};
|
|
480
481
|
function Ke(e, t) {
|
|
481
482
|
let n = T[e];
|
|
482
483
|
if (n || (n = T[e] = []), n.push(t), c()) {
|
|
@@ -547,25 +548,25 @@ const _e = (e = {}) => {
|
|
|
547
548
|
switch (o.type) {
|
|
548
549
|
case "builder.evaluate": {
|
|
549
550
|
const d = o.data.text, y = o.data.arguments || [], p = o.data.id, k = new Function(d);
|
|
550
|
-
let u,
|
|
551
|
+
let u, h = null;
|
|
551
552
|
try {
|
|
552
553
|
u = k.apply(null, y);
|
|
553
|
-
} catch (
|
|
554
|
-
|
|
554
|
+
} catch (g) {
|
|
555
|
+
h = g;
|
|
555
556
|
}
|
|
556
|
-
|
|
557
|
+
h ? (s = window.parent) == null || s.postMessage({
|
|
557
558
|
type: "builder.evaluateError",
|
|
558
559
|
data: {
|
|
559
560
|
id: p,
|
|
560
|
-
error:
|
|
561
|
+
error: h.message
|
|
561
562
|
}
|
|
562
|
-
}, "*") : u && typeof u.then == "function" ? u.then((
|
|
563
|
+
}, "*") : u && typeof u.then == "function" ? u.then((g) => {
|
|
563
564
|
var w;
|
|
564
565
|
(w = window.parent) == null || w.postMessage({
|
|
565
566
|
type: "builder.evaluateResult",
|
|
566
567
|
data: {
|
|
567
568
|
id: p,
|
|
568
|
-
result:
|
|
569
|
+
result: g
|
|
569
570
|
}
|
|
570
571
|
}, "*");
|
|
571
572
|
}).catch(console.error) : (a = window.parent) == null || a.postMessage({
|
|
@@ -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-4ba58cf3.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.setEditorSettings=e.setEditorSettings;exports.subscribeToEditor=e.subscribeToEditor;exports.track=e.track;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _processContentResult as r, createRegisterComponentMessage as s, fetchBuilderProps as i, fetchEntries as n, fetchOneEntry as o, getBuilderSearchParams as c, isEditing as g, isPreviewing as a, register as d, setEditorSettings as E, subscribeToEditor as f, track as h } from "./server-entry-
|
|
1
|
+
import { _processContentResult as r, createRegisterComponentMessage as s, fetchBuilderProps as i, fetchEntries as n, fetchOneEntry as o, getBuilderSearchParams as c, isEditing as g, isPreviewing as a, register as d, setEditorSettings as E, subscribeToEditor as f, track as h } from "./server-entry-a221fe66.js";
|
|
2
2
|
export {
|
|
3
3
|
r as _processContentResult,
|
|
4
4
|
s as createRegisterComponentMessage,
|
package/package.json
CHANGED
|
@@ -32,7 +32,7 @@ type VariantData = {
|
|
|
32
32
|
id: string;
|
|
33
33
|
testRatio?: number;
|
|
34
34
|
};
|
|
35
|
-
export declare const
|
|
35
|
+
export declare const getInitVariantsFnsScriptString: () => string;
|
|
36
36
|
export declare const getUpdateCookieAndStylesScript: (variants: VariantData[], contentId: string) => string;
|
|
37
37
|
export declare const getUpdateVariantVisibilityScript: ({ contentId, variationId }: {
|
|
38
38
|
variationId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.0.
|
|
1
|
+
export declare const SDK_VERSION = "1.0.16";
|
|
@@ -128,4 +128,12 @@ export interface GetContentOptions {
|
|
|
128
128
|
* draft mode and un-archived. Default is false.
|
|
129
129
|
*/
|
|
130
130
|
includeUnpublished?: boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Optional override of the `fetch` function. (Defaults to global `fetch`)
|
|
133
|
+
*/
|
|
134
|
+
fetch?: typeof global.fetch;
|
|
135
|
+
/**
|
|
136
|
+
* Optional fetch options to be passed to the `fetch` function.
|
|
137
|
+
*/
|
|
138
|
+
fetchOptions?: RequestInit;
|
|
131
139
|
}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";const b="react",I="[Builder.io]: ",d={log:(...e)=>console.log(I,...e),error:(...e)=>console.error(I,...e),warn:(...e)=>console.warn(I,...e),debug:(...e)=>console.debug(I,...e)};function c(){return typeof window!="undefined"&&typeof document!="undefined"}const ce=e=>{const t={};return e.forEach((n,r)=>{t[r]=n}),t},M=e=>e instanceof URLSearchParams?ce(e):e,F=e=>typeof e=="string"?e:e instanceof URLSearchParams?e.toString():new URLSearchParams(e).toString();function ue(){return c()&&window.self!==window.top}function k(e){return ue()&&F(e||window.location.search).indexOf("builder.frameEditing=")!==-1}const de=()=>{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||"",N=()=>{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()||b==="reactNative"}},n=e.match(/Tablet|iPad/i),r=de();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"}},p=e=>e!=null,C=e=>JSON.parse(JSON.stringify(e)),fe=e=>{if(e==="localhost"||e==="127.0.0.1")return e;const t=e.split(".");return t.length>2?t.slice(1).join("."):e},D=({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}},j=async e=>D(e),ge=e=>e.map(([t,n])=>n?`${t}=${n}`:t).filter(p).join("; "),he=[["secure",""],["SameSite","None"]],pe=({name:e,value:t,expires:n})=>{const o=(c()?location.protocol==="https:":!0)?he:[[]],s=n?[["expires",n.toUTCString()]]:[[]],a=[[e,t],...s,["path","/"],["domain",fe(window.location.hostname)],...o];return ge(a)},K=async({name:e,value:t,expires:n,canTrack:r})=>{try{if(!r)return;const o=pe({name:e,value:t,expires:n});document.cookie=o}catch(o){d.warn("[COOKIE] SET error: ",(o==null?void 0:o.message)||o)}},me="builder.tests",P=e=>`${me}.${e}`,ye=({contentId:e})=>j({name:P(e),canTrack:!0}),we=({contentId:e})=>D({name:P(e),canTrack:!0}),Se=({contentId:e,value:t})=>K({name:P(e),value:t,canTrack:!0}),_=e=>p(e.id)&&p(e.variations)&&Object.keys(e.variations).length>0,be=({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},W=e=>{const t=be(e);return Se({contentId:e.id,value:t}).catch(n=>{d.error("could not store A/B test variation: ",n)}),t},$=({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":"")}},Ie=({item:e,canTrack:t})=>{if(!t)return e;if(!e)return;if(!_(e))return e;const n=we({contentId:e.id})||W({variations:e.variations,id:e.id}),r=$({item:e,testGroupId:n});return{...e,...r}},ve=async({item:e,canTrack:t})=>{if(!t||!_(e))return e;const r=await ye({contentId:e.id})||W({variations:e.variations,id:e.id}),o=$({item:e,testGroupId:r});return{...e,...o}},G=e=>p(e)?e:!0,Ee=e=>({type:"builder.registerComponent",data:z(e)}),ke=e=>{const t=e.toString().trim();return`return (${!t.startsWith("function")&&!t.startsWith("(")?"function ":""}${t}).apply(this, arguments)`},Ce=e=>typeof e=="function"?ke(e):C(e),z=({inputs:e,...t})=>({...C(t),inputs:e==null?void 0:e.map(n=>Object.entries(n).reduce((r,[o,s])=>({...r,[o]:Ce(s)}),{}))});function Pe(){return typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:globalThis}function Oe(){const e=Pe().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 J=Oe();function v(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,...v(s,a,n)}:{...r,[a]:s}},{})}const Te="v3",R="builder.",xe="options.",O=e=>{if(!e)return{};const t=M(e),n={};return Object.keys(t).forEach(r=>{if(r.startsWith(R)){const o=r.replace(R,"").replace(xe,"");n[o]=t[r]}}),n},Ae=()=>{if(!c())return{};const e=new URLSearchParams(window.location.search);return O(e)},B=e=>typeof e=="number"&&!isNaN(e)&&e>=0,T=e=>{const{limit:t=30,userAttributes:n,query:r,model:o,apiKey:s,enrich:a,locale:l,apiVersion:y=Te,fields:m,omit:E,offset:u,cacheSeconds:g,staleCacheSeconds:h,sort:w,includeUnpublished:x}=e;if(!s)throw new Error("Missing API key");if(!["v3"].includes(y))throw new Error(`Invalid apiVersion: expected 'v3', received '${y}'`);const ie=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(ie)),i.searchParams.set("includeRefs",String(!0)),l&&i.searchParams.set("locale",l),a&&i.searchParams.set("enrich",String(a)),i.searchParams.set("omit",E||"meta.componentsUsed"),m&&i.searchParams.set("fields",m),Number.isFinite(u)&&u>-1&&i.searchParams.set("offset",String(Math.floor(u))),typeof x=="boolean"&&i.searchParams.set("includeUnpublished",String(x)),g&&B(g)&&i.searchParams.set("cacheSeconds",String(g)),h&&B(h)&&i.searchParams.set("staleCacheSeconds",String(h)),w){const f=v({sort:w});for(const S in f)i.searchParams.set(S,JSON.stringify(f[S]))}const ae={...Ae(),...M(e.options||{})},A=v(ae);for(const f in A)i.searchParams.set(f,String(A[f]));if(n&&i.searchParams.set("userAttributes",JSON.stringify(n)),r){const f=v({query:r});for(const S in f)i.searchParams.set(S,JSON.stringify(f[S]))}return i},Re=e=>"results"in e;async function H(e){const t=await q({...e,limit:1});return t&&t[0]||null}const Be=async e=>{const t=T(e);return await(await J(t.href)).json()},X=async(e,t,n=T(e))=>{const r=G(e.canTrack);if(n.search.includes("preview="),!r||!(c()||b==="reactNative"))return t.results;try{const o=[];for(const s of t.results)o.push(await ve({item:s,canTrack:r}));t.results=o}catch(o){d.error("Could not process A/B tests. ",o)}return t.results};async function q(e){try{const t=T(e),n=await Be(e);return Re(n)?X(e,n):(d.error("Error fetching data. ",{url:t,content:n,options:e}),null)}catch(t){return d.error("Error fetching data. ",t),null}}function Le(e){if(!c())return!1;const t=F(e||window.location.search);return k(t)?!1:t.indexOf("builder.preview=")!==-1}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 Y(){return Ve().replace(/-/g,"")}const Q="builderSessionId",Ue=async({canTrack:e})=>{if(!e)return;const t=await j({name:Q,canTrack:e});if(p(t))return t;{const n=Me();return Fe({id:n,canTrack:e}),n}},Me=()=>Y(),Fe=({id:e,canTrack:t})=>K({name:Q,value:e,canTrack:t}),Z=()=>c()&&typeof localStorage!="undefined"?localStorage:void 0,Ne=({key:e,canTrack:t})=>{var n;try{return t?(n=Z())==null?void 0:n.getItem(e):void 0}catch(r){console.debug("[LocalStorage] GET error: ",r);return}},De=({key:e,canTrack:t,value:n})=>{var r;try{t&&((r=Z())==null||r.setItem(e,n))}catch(o){console.debug("[LocalStorage] SET error: ",o)}},ee="builderVisitorId",je=({canTrack:e})=>{if(!e)return;const t=Ne({key:ee,canTrack:e});if(p(t))return t;{const n=Ke();return _e({id:n,canTrack:e}),n}},Ke=()=>Y(),_e=({id:e,canTrack:t})=>De({key:ee,value:e,canTrack:t}),We=async({canTrack:e})=>{if(!e)return{visitorId:void 0,sessionId:void 0};const t=await Ue({canTrack:e}),n=je({canTrack:e});return{sessionId:t,visitorId:n}},$e=async({type:e,canTrack:t,apiKey:n,metadata:r,...o})=>({type:e,data:{...o,metadata:{url:location.href,...r},...await We({canTrack:t}),userAttributes:N(),ownerId:n}});async function te(e){if(!e.apiKey){d.error("Missing API key for track call. Please provide your API key.");return}if(e.canTrack&&!k()&&(c()||b==="reactNative"))return fetch("https://cdn.builder.io/api/v1/track",{method:"POST",body:JSON.stringify({events:[await $e(e)]}),headers:{"content-type":"application/json"},mode:"cors"}).catch(t=>{console.error("Failed to track: ",t)})}const Ge=e=>te({...e,canTrack:!0}),ze=["*.beta.builder.io","beta.builder.io","builder.io","localhost","qa.builder.io"];function ne(e,t){const n=new URL(t.origin),r=n.hostname;return(e||ze).findIndex(o=>o.startsWith("*.")?r.endsWith(o.slice(1)):o===r)>-1}const Je="1.0.14",L={};function re(e,t){let n=L[e];if(n||(n=L[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 He=()=>{re("insertMenu",{name:"_default",default:!0,items:[{name:"Box"},{name:"Text"},{name:"Image"},{name:"Columns"},{name:"Core:Section"},{name:"Core:Button"},{name:"Embed"},{name:"Custom Code"}]})};let V=!1;const oe=(e={})=>{var t,n;V||(V=!0,c()&&((t=window.parent)==null||t.postMessage({type:"builder.sdkInfo",data:{target:b,version:Je,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(!ne(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,E=new Function(l);let u,g=null;try{u=E.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 w;(w=window.parent)==null||w.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}}})))},se=({model:e,trustedHosts:t,callbacks:n})=>r=>{if(!ne(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}}},Xe=(e,t,n)=>{if(!c)return d.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server."),()=>{};oe();const r=se({callbacks:{contentUpdate:t,animation:()=>{},configureSdk:()=>{}},model:e,trustedHosts:n==null?void 0:n.trustedHosts});return window.addEventListener("message",r),()=>{window.removeEventListener("message",r)}},U={};function qe(e){if(c()){Object.assign(U,e);const t={type:"builder.settingsChange",data:U};parent.postMessage(t,"*")}}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:O(e.searchParams||((s=e.url)==null?void 0:s.searchParams)||e.options)};return{apiKey:n.apiKey,model:n.model,content:await H(n)}};exports.TARGET=b;exports._processContentResult=X;exports._track=te;exports.checkIsDefined=p;exports.createEditorListener=se;exports.createRegisterComponentMessage=Ee;exports.fastClone=C;exports.fetch=J;exports.fetchBuilderProps=Ye;exports.fetchEntries=q;exports.fetchOneEntry=H;exports.getBuilderSearchParams=O;exports.getDefaultCanTrack=G;exports.getUserAttributes=N;exports.handleABTestingSync=Ie;exports.isBrowser=c;exports.isEditing=k;exports.isPreviewing=Le;exports.logger=d;exports.register=re;exports.registerInsertMenu=He;exports.serializeComponentInfo=z;exports.setEditorSettings=qe;exports.setupBrowserForEditing=oe;exports.subscribeToEditor=Xe;exports.track=Ge;
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";const b="react",I="[Builder.io]: ",d={log:(...e)=>console.log(I,...e),error:(...e)=>console.error(I,...e),warn:(...e)=>console.warn(I,...e),debug:(...e)=>console.debug(I,...e)};function c(){return typeof window!="undefined"&&typeof document!="undefined"}const ce=e=>{const t={};return e.forEach((n,r)=>{t[r]=n}),t},M=e=>e instanceof URLSearchParams?ce(e):e,F=e=>typeof e=="string"?e:e instanceof URLSearchParams?e.toString():new URLSearchParams(e).toString();function ue(){return c()&&window.self!==window.top}function k(e){return ue()&&F(e||window.location.search).indexOf("builder.frameEditing=")!==-1}const de=()=>{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||"",N=()=>{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()||b==="reactNative"}},n=e.match(/Tablet|iPad/i),r=de();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"}},C=e=>JSON.parse(JSON.stringify(e)),p=e=>e!=null,fe=e=>{if(e==="localhost"||e==="127.0.0.1")return e;const t=e.split(".");return t.length>2?t.slice(1).join("."):e},D=({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}},j=async e=>D(e),ge=e=>e.map(([t,n])=>n?`${t}=${n}`:t).filter(p).join("; "),he=[["secure",""],["SameSite","None"]],pe=({name:e,value:t,expires:n})=>{const o=(c()?location.protocol==="https:":!0)?he:[[]],s=n?[["expires",n.toUTCString()]]:[[]],a=[[e,t],...s,["path","/"],["domain",fe(window.location.hostname)],...o];return ge(a)},K=async({name:e,value:t,expires:n,canTrack:r})=>{try{if(!r)return;const o=pe({name:e,value:t,expires:n});document.cookie=o}catch(o){d.warn("[COOKIE] SET error: ",(o==null?void 0:o.message)||o)}},me="builder.tests",P=e=>`${me}.${e}`,ye=({contentId:e})=>j({name:P(e),canTrack:!0}),we=({contentId:e})=>D({name:P(e),canTrack:!0}),Se=({contentId:e,value:t})=>K({name:P(e),value:t,canTrack:!0}),_=e=>p(e.id)&&p(e.variations)&&Object.keys(e.variations).length>0,be=({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},W=e=>{const t=be(e);return Se({contentId:e.id,value:t}).catch(n=>{d.error("could not store A/B test variation: ",n)}),t},$=({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":"")}},Ie=({item:e,canTrack:t})=>{if(!t)return e;if(!e)return;if(!_(e))return e;const n=we({contentId:e.id})||W({variations:e.variations,id:e.id}),r=$({item:e,testGroupId:n});return{...e,...r}},ve=async({item:e,canTrack:t})=>{if(!t||!_(e))return e;const r=await ye({contentId:e.id})||W({variations:e.variations,id:e.id}),o=$({item:e,testGroupId:r});return{...e,...o}},G=e=>p(e)?e:!0,Ee=e=>({type:"builder.registerComponent",data:z(e)}),ke=e=>{const t=e.toString().trim();return`return (${!t.startsWith("function")&&!t.startsWith("(")?"function ":""}${t}).apply(this, arguments)`},Ce=e=>typeof e=="function"?ke(e):C(e),z=({inputs:e,...t})=>({...C(t),inputs:e==null?void 0:e.map(n=>Object.entries(n).reduce((r,[o,s])=>({...r,[o]:Ce(s)}),{}))});function Pe(){return typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:globalThis}function Oe(){const e=Pe().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 J=Oe();function v(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,...v(s,a,n)}:{...r,[a]:s}},{})}const Te="v3",R="builder.",xe="options.",O=e=>{if(!e)return{};const t=M(e),n={};return Object.keys(t).forEach(r=>{if(r.startsWith(R)){const o=r.replace(R,"").replace(xe,"");n[o]=t[r]}}),n},Ae=()=>{if(!c())return{};const e=new URLSearchParams(window.location.search);return O(e)},B=e=>typeof e=="number"&&!isNaN(e)&&e>=0,T=e=>{const{limit:t=30,userAttributes:n,query:r,model:o,apiKey:s,enrich:a,locale:l,apiVersion:y=Te,fields:m,omit:E,offset:u,cacheSeconds:g,staleCacheSeconds:h,sort:w,includeUnpublished:x}=e;if(!s)throw new Error("Missing API key");if(!["v3"].includes(y))throw new Error(`Invalid apiVersion: expected 'v3', received '${y}'`);const ie=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(ie)),i.searchParams.set("includeRefs",String(!0)),l&&i.searchParams.set("locale",l),a&&i.searchParams.set("enrich",String(a)),i.searchParams.set("omit",E||"meta.componentsUsed"),m&&i.searchParams.set("fields",m),Number.isFinite(u)&&u>-1&&i.searchParams.set("offset",String(Math.floor(u))),typeof x=="boolean"&&i.searchParams.set("includeUnpublished",String(x)),g&&B(g)&&i.searchParams.set("cacheSeconds",String(g)),h&&B(h)&&i.searchParams.set("staleCacheSeconds",String(h)),w){const f=v({sort:w});for(const S in f)i.searchParams.set(S,JSON.stringify(f[S]))}const ae={...Ae(),...M(e.options||{})},A=v(ae);for(const f in A)i.searchParams.set(f,String(A[f]));if(n&&i.searchParams.set("userAttributes",JSON.stringify(n)),r){const f=v({query:r});for(const S in f)i.searchParams.set(S,JSON.stringify(f[S]))}return i},Re=e=>"results"in e;async function H(e){const t=await q({...e,limit:1});return t&&t[0]||null}const Be=async e=>{const t=T(e);return await(await J(t.href)).json()},X=async(e,t,n=T(e))=>{const r=G(e.canTrack);if(n.search.includes("preview="),!r||!(c()||b==="reactNative"))return t.results;try{const o=[];for(const s of t.results)o.push(await ve({item:s,canTrack:r}));t.results=o}catch(o){d.error("Could not process A/B tests. ",o)}return t.results};async function q(e){try{const t=T(e),n=await Be(e);return Re(n)?X(e,n):(d.error("Error fetching data. ",{url:t,content:n,options:e}),null)}catch(t){return d.error("Error fetching data. ",t),null}}function Le(e){if(!c())return!1;const t=F(e||window.location.search);return k(t)?!1:t.indexOf("builder.preview=")!==-1}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 Y(){return Ve().replace(/-/g,"")}const Q="builderSessionId",Ue=async({canTrack:e})=>{if(!e)return;const t=await j({name:Q,canTrack:e});if(p(t))return t;{const n=Me();return Fe({id:n,canTrack:e}),n}},Me=()=>Y(),Fe=({id:e,canTrack:t})=>K({name:Q,value:e,canTrack:t}),Z=()=>c()&&typeof localStorage!="undefined"?localStorage:void 0,Ne=({key:e,canTrack:t})=>{var n;try{return t?(n=Z())==null?void 0:n.getItem(e):void 0}catch(r){console.debug("[LocalStorage] GET error: ",r);return}},De=({key:e,canTrack:t,value:n})=>{var r;try{t&&((r=Z())==null||r.setItem(e,n))}catch(o){console.debug("[LocalStorage] SET error: ",o)}},ee="builderVisitorId",je=({canTrack:e})=>{if(!e)return;const t=Ne({key:ee,canTrack:e});if(p(t))return t;{const n=Ke();return _e({id:n,canTrack:e}),n}},Ke=()=>Y(),_e=({id:e,canTrack:t})=>De({key:ee,value:e,canTrack:t}),We=async({canTrack:e})=>{if(!e)return{visitorId:void 0,sessionId:void 0};const t=await Ue({canTrack:e}),n=je({canTrack:e});return{sessionId:t,visitorId:n}},$e=async({type:e,canTrack:t,apiKey:n,metadata:r,...o})=>({type:e,data:{...o,metadata:{url:location.href,...r},...await We({canTrack:t}),userAttributes:N(),ownerId:n}});async function te(e){if(!e.apiKey){d.error("Missing API key for track call. Please provide your API key.");return}if(e.canTrack&&!k()&&(c()||b==="reactNative"))return fetch("https://cdn.builder.io/api/v1/track",{method:"POST",body:JSON.stringify({events:[await $e(e)]}),headers:{"content-type":"application/json"},mode:"cors"}).catch(t=>{console.error("Failed to track: ",t)})}const Ge=e=>te({...e,canTrack:!0}),ze=["*.beta.builder.io","beta.builder.io","builder.io","localhost","qa.builder.io"];function ne(e,t){const n=new URL(t.origin),r=n.hostname;return(e||ze).findIndex(o=>o.startsWith("*.")?r.endsWith(o.slice(1)):o===r)>-1}const Je="1.0.14",L={};function re(e,t){let n=L[e];if(n||(n=L[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 He=()=>{re("insertMenu",{name:"_default",default:!0,items:[{name:"Box"},{name:"Text"},{name:"Image"},{name:"Columns"},{name:"Core:Section"},{name:"Core:Button"},{name:"Embed"},{name:"Custom Code"}]})};let V=!1;const oe=(e={})=>{var t,n;V||(V=!0,c()&&((t=window.parent)==null||t.postMessage({type:"builder.sdkInfo",data:{target:b,version:Je,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(!ne(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,E=new Function(l);let u,g=null;try{u=E.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 w;(w=window.parent)==null||w.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}}})))},se=({model:e,trustedHosts:t,callbacks:n})=>r=>{if(!ne(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}}},Xe=(e,t,n)=>{if(!c)return d.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server."),()=>{};oe();const r=se({callbacks:{contentUpdate:t,animation:()=>{},configureSdk:()=>{}},model:e,trustedHosts:n==null?void 0:n.trustedHosts});return window.addEventListener("message",r),()=>{window.removeEventListener("message",r)}},U={};function qe(e){if(c()){Object.assign(U,e);const t={type:"builder.settingsChange",data:U};parent.postMessage(t,"*")}}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:O(e.searchParams||((s=e.url)==null?void 0:s.searchParams)||e.options)};return{apiKey:n.apiKey,model:n.model,content:await H(n)}};exports.TARGET=b;exports._processContentResult=X;exports._track=te;exports.checkIsDefined=p;exports.createEditorListener=se;exports.createRegisterComponentMessage=Ee;exports.fastClone=C;exports.fetch=J;exports.fetchBuilderProps=Ye;exports.fetchEntries=q;exports.fetchOneEntry=H;exports.getBuilderSearchParams=O;exports.getDefaultCanTrack=G;exports.getUserAttributes=N;exports.handleABTestingSync=Ie;exports.isBrowser=c;exports.isEditing=k;exports.isPreviewing=Le;exports.logger=d;exports.register=re;exports.registerInsertMenu=He;exports.serializeComponentInfo=z;exports.setEditorSettings=qe;exports.setupBrowserForEditing=oe;exports.subscribeToEditor=Xe;exports.track=Ge;
|