@builder.io/sdk-react 4.2.0 → 4.2.2
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 +17 -17
- package/lib/browser/blocks-exports.mjs +759 -740
- package/lib/browser/index.cjs +1 -1
- package/lib/browser/index.mjs +6 -5
- package/lib/browser/server-entry-06504dba.cjs +2 -0
- package/lib/browser/{server-entry-065ec411.js → server-entry-074665de.js} +24 -13
- package/lib/browser/server-entry.cjs +1 -1
- package/lib/browser/server-entry.mjs +7 -6
- package/lib/edge/{accordion-c239771d.cjs → accordion-0768e15a.cjs} +1 -1
- package/lib/edge/{accordion-79f6d62c.js → accordion-d3831f48.js} +1 -1
- package/lib/edge/{blocks-3cb3a9cd.js → blocks-0269007e.js} +105 -106
- package/lib/edge/{blocks-56f79850.cjs → blocks-2af1d7c9.cjs} +10 -10
- package/lib/edge/blocks-exports.cjs +1 -1
- package/lib/edge/blocks-exports.mjs +2 -2
- package/lib/edge/{button-759b43fb.cjs → button-050f4fef.cjs} +1 -1
- package/lib/edge/{button-6dee05c9.js → button-a478ff1a.js} +2 -2
- package/lib/edge/{columns-2743498a.js → columns-0b3181f1.js} +3 -3
- package/lib/edge/{columns-a29ec0ac.cjs → columns-25375990.cjs} +1 -1
- package/lib/edge/{content-variants-4d5a1e3c.js → content-variants-0dd65b50.js} +426 -415
- package/lib/edge/content-variants-4cab7215.cjs +302 -0
- package/lib/edge/{custom-code-6129bd8c.cjs → custom-code-eb5aedd2.cjs} +1 -1
- package/lib/edge/{custom-code-8034fac0.js → custom-code-f7a0f1c1.js} +1 -1
- package/lib/edge/{embed-b2ea5150.cjs → embed-69114c35.cjs} +1 -1
- package/lib/edge/{embed-f5b10eeb.js → embed-e4979560.js} +1 -1
- package/lib/edge/{form-14942d4f.js → form-30fba682.js} +27 -22
- package/lib/edge/form-7b4bd399.cjs +1 -0
- package/lib/edge/{get-class-prop-name-f6a63f4a.js → get-class-prop-name-770bdff2.js} +1 -1
- package/lib/edge/{get-class-prop-name-7e739c9f.cjs → get-class-prop-name-f470d5ce.cjs} +1 -1
- package/lib/edge/{img-ba2ef9ee.js → img-3bb375bf.js} +1 -1
- package/lib/edge/{img-f33a2e42.cjs → img-ddf74e12.cjs} +1 -1
- package/lib/edge/index.cjs +1 -1
- package/lib/edge/index.mjs +4 -3
- package/lib/edge/{input-c2f95825.cjs → input-a6caf021.cjs} +1 -1
- package/lib/edge/{input-7089e95f.js → input-e4a9fe0b.js} +1 -1
- package/lib/edge/{personalization-container-eb1ecef2.js → personalization-container-64f3cd71.js} +4 -4
- package/lib/edge/{personalization-container-794b3939.cjs → personalization-container-f7030f08.cjs} +1 -1
- package/lib/edge/{select-af0bb9fe.cjs → select-c217566c.cjs} +1 -1
- package/lib/edge/{select-8f01592a.js → select-c59c9ac6.js} +1 -1
- package/lib/edge/server-entry-67200cf1.cjs +2 -0
- package/lib/edge/{server-entry-7c65c9a8.js → server-entry-fb5f2b80.js} +22 -11
- package/lib/edge/server-entry.cjs +1 -1
- package/lib/edge/server-entry.mjs +7 -6
- package/lib/edge/{slot-2638fd6d.js → slot-26ec2911.js} +3 -3
- package/lib/edge/{slot-db37860e.cjs → slot-ccd946e2.cjs} +1 -1
- package/lib/edge/{symbol-7faca118.js → symbol-10cb2f77.js} +26 -23
- package/lib/edge/symbol-4548e942.cjs +1 -0
- package/lib/edge/tabs-82a9170c.cjs +1 -0
- package/lib/edge/{tabs-2eee6422.js → tabs-f9110171.js} +24 -23
- package/lib/node/blocks-exports.cjs +20 -20
- package/lib/node/blocks-exports.mjs +919 -900
- package/lib/node/index.cjs +1 -1
- package/lib/node/index.mjs +6 -5
- package/lib/node/init.cjs +1 -1
- package/lib/node/init.mjs +3 -3
- package/lib/node/{server-entry-581dd491.js → server-entry-83d3751d.js} +24 -13
- package/lib/node/server-entry-d40e4b66.cjs +2 -0
- package/lib/node/server-entry.cjs +1 -1
- package/lib/node/server-entry.mjs +7 -6
- package/lib/node/{setIvm-2eb44b9d.cjs → setIvm-0a5b2ba2.cjs} +1 -1
- package/lib/node/{setIvm-8d02dc72.js → setIvm-596668c3.js} +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-f461467e.js → should-force-browser-runtime-in-node-180c3315.js} +1 -1
- package/lib/node/{should-force-browser-runtime-in-node-ed3fa1f9.cjs → should-force-browser-runtime-in-node-5b9e373d.cjs} +1 -1
- package/package.json +1 -1
- package/types/blocks/symbol/symbol.types.d.ts +1 -2
- package/types/components/awaiter.d.ts +1 -11
- package/types/components/awaiter.types.d.ts +7 -0
- package/types/constants/sdk-version.d.ts +1 -1
- package/types/functions/register.d.ts +18 -0
- package/types/server-index.d.ts +1 -1
- package/lib/browser/server-entry-09953757.cjs +0 -2
- package/lib/edge/content-variants-bdf1748b.cjs +0 -302
- package/lib/edge/form-26c3a03e.cjs +0 -1
- package/lib/edge/server-entry-142a50e9.cjs +0 -2
- package/lib/edge/symbol-630b9a57.cjs +0 -1
- package/lib/edge/tabs-502123df.cjs +0 -1
- package/lib/node/server-entry-375d06e8.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-d40e4b66.cjs");require("react/jsx-runtime");require("react");require("./setIvm-0a5b2ba2.cjs");require("./should-force-browser-runtime-in-node-5b9e373d.cjs");exports.Blocks=t.Blocks;exports.BuilderContext=t.BuilderContext;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.registerAction=e.registerAction;exports.setClientUserAttributes=e.setClientUserAttributes;exports.setEditorSettings=e.setEditorSettings;exports.subscribeToEditor=e.subscribeToEditor;exports.track=e.track;
|
package/lib/node/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Blocks as n, BuilderContext as m, Button as c, Columns as g, Content as p, Fragment as a, Image as l, Section as u, Symbol as d, Text as C, Video as f } from "./blocks-exports.mjs";
|
|
2
|
-
import { _processContentResult as E, createRegisterComponentMessage as b, fetchBuilderProps as h, fetchEntries as x, fetchOneEntry as S, getBuilderSearchParams as P, isEditing as k, isPreviewing as y, register as R, setClientUserAttributes as T, setEditorSettings as v, subscribeToEditor as w, track as
|
|
2
|
+
import { _processContentResult as E, createRegisterComponentMessage as b, fetchBuilderProps as h, fetchEntries as x, fetchOneEntry as S, getBuilderSearchParams as P, isEditing as k, isPreviewing as y, register as A, registerAction as R, setClientUserAttributes as T, setEditorSettings as v, subscribeToEditor as w, track as F } from "./server-entry-83d3751d.js";
|
|
3
3
|
import "react/jsx-runtime";
|
|
4
4
|
import "react";
|
|
5
|
-
import "./setIvm-
|
|
6
|
-
import "./should-force-browser-runtime-in-node-
|
|
5
|
+
import "./setIvm-596668c3.js";
|
|
6
|
+
import "./should-force-browser-runtime-in-node-180c3315.js";
|
|
7
7
|
export {
|
|
8
8
|
n as Blocks,
|
|
9
9
|
m as BuilderContext,
|
|
@@ -24,9 +24,10 @@ export {
|
|
|
24
24
|
P as getBuilderSearchParams,
|
|
25
25
|
k as isEditing,
|
|
26
26
|
y as isPreviewing,
|
|
27
|
-
|
|
27
|
+
A as register,
|
|
28
|
+
R as registerAction,
|
|
28
29
|
T as setClientUserAttributes,
|
|
29
30
|
v as setEditorSettings,
|
|
30
31
|
w as subscribeToEditor,
|
|
31
|
-
|
|
32
|
+
F as track
|
|
32
33
|
};
|
package/lib/node/init.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./should-force-browser-runtime-in-node-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./should-force-browser-runtime-in-node-5b9e373d.cjs"),t=require("isolated-vm"),r=require("./setIvm-0a5b2ba2.cjs");require("./server-entry-d40e4b66.cjs");const n=e=>{if(o.shouldForceBrowserRuntimeInNode({shouldLogWarning:!0}))return;const{ivmIsolateOptions:i}=e||{};r.setIvm(t,i)};exports.initializeNodeRuntime=n;
|
package/lib/node/init.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { shouldForceBrowserRuntimeInNode as r } from "./should-force-browser-runtime-in-node-
|
|
1
|
+
import { shouldForceBrowserRuntimeInNode as r } from "./should-force-browser-runtime-in-node-180c3315.js";
|
|
2
2
|
import t from "isolated-vm";
|
|
3
|
-
import { setIvm as e } from "./setIvm-
|
|
4
|
-
import "./server-entry-
|
|
3
|
+
import { setIvm as e } from "./setIvm-596668c3.js";
|
|
4
|
+
import "./server-entry-83d3751d.js";
|
|
5
5
|
const u = (o) => {
|
|
6
6
|
if (r({
|
|
7
7
|
shouldLogWarning: !0
|
|
@@ -86,8 +86,18 @@ function re(t, e) {
|
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
-
const L = {};
|
|
90
89
|
function se(t) {
|
|
90
|
+
var e;
|
|
91
|
+
if (c()) {
|
|
92
|
+
const n = JSON.parse(JSON.stringify(t));
|
|
93
|
+
t.action && (n.action = t.action.toString()), (e = window.parent) == null || e.postMessage({
|
|
94
|
+
type: "builder.registerAction",
|
|
95
|
+
data: n
|
|
96
|
+
}, "*");
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const L = {};
|
|
100
|
+
function oe(t) {
|
|
91
101
|
if (c()) {
|
|
92
102
|
Object.assign(L, t);
|
|
93
103
|
const e = {
|
|
@@ -112,7 +122,7 @@ const N = "builder.", gt = "options.", $ = (t) => {
|
|
|
112
122
|
return {};
|
|
113
123
|
const t = new URLSearchParams(window.location.search);
|
|
114
124
|
return $(t);
|
|
115
|
-
}, G = "4.2.
|
|
125
|
+
}, G = "4.2.2", J = () => ({
|
|
116
126
|
"X-Builder-SDK": b,
|
|
117
127
|
"X-Builder-SDK-GEN": "2",
|
|
118
128
|
"X-Builder-SDK-Version": G
|
|
@@ -307,7 +317,7 @@ async function Bt({
|
|
|
307
317
|
console.error("Failed to track: ", s);
|
|
308
318
|
});
|
|
309
319
|
}
|
|
310
|
-
const
|
|
320
|
+
const ie = (t) => Bt({
|
|
311
321
|
...t,
|
|
312
322
|
canTrack: !0
|
|
313
323
|
}), xt = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
|
|
@@ -414,7 +424,7 @@ const _t = (t) => {
|
|
|
414
424
|
break;
|
|
415
425
|
}
|
|
416
426
|
}
|
|
417
|
-
},
|
|
427
|
+
}, ae = ({
|
|
418
428
|
model: t,
|
|
419
429
|
apiKey: e,
|
|
420
430
|
callback: n,
|
|
@@ -495,7 +505,7 @@ const _t = (t) => {
|
|
|
495
505
|
testVariationId: n.id,
|
|
496
506
|
testVariationName: n.name || (n.id === t.id ? "Default" : "")
|
|
497
507
|
};
|
|
498
|
-
},
|
|
508
|
+
}, ce = ({
|
|
499
509
|
item: t,
|
|
500
510
|
canTrack: e
|
|
501
511
|
}) => {
|
|
@@ -576,7 +586,7 @@ function F() {
|
|
|
576
586
|
}
|
|
577
587
|
let k;
|
|
578
588
|
c() && b === "qwik" ? (window.__BUILDER_USER_ATTRIBUTES_SERVICE__ || (window.__BUILDER_USER_ATTRIBUTES_SERVICE__ = F()), k = window.__BUILDER_USER_ATTRIBUTES_SERVICE__) : k = F();
|
|
579
|
-
const nt = k,
|
|
589
|
+
const nt = k, ue = (t) => {
|
|
580
590
|
nt.setUserAttributes(t);
|
|
581
591
|
}, Wt = (t) => {
|
|
582
592
|
const e = y(t) ? t : !0;
|
|
@@ -739,7 +749,7 @@ async function te(t) {
|
|
|
739
749
|
}), n;
|
|
740
750
|
return qt(t, n);
|
|
741
751
|
}
|
|
742
|
-
const
|
|
752
|
+
const le = async (t) => {
|
|
743
753
|
var r, s, o;
|
|
744
754
|
const e = t.path || ((r = t.url) == null ? void 0 : r.pathname) || ((s = t.userAttributes) == null ? void 0 : s.urlPath), n = {
|
|
745
755
|
...t,
|
|
@@ -767,25 +777,26 @@ export {
|
|
|
767
777
|
y as checkIsDefined,
|
|
768
778
|
Lt as createEditorListener,
|
|
769
779
|
ne as createRegisterComponentMessage,
|
|
770
|
-
|
|
780
|
+
le as fetchBuilderProps,
|
|
771
781
|
te as fetchEntries,
|
|
772
782
|
Yt as fetchOneEntry,
|
|
773
783
|
$ as getBuilderSearchParams,
|
|
774
784
|
O as getCookieSync,
|
|
775
785
|
Wt as getDefaultCanTrack,
|
|
776
786
|
ft as getUserAttributes,
|
|
777
|
-
|
|
787
|
+
ce as handleABTestingSync,
|
|
778
788
|
c as isBrowser,
|
|
779
789
|
ut as isEditing,
|
|
780
790
|
ee as isPreviewing,
|
|
781
791
|
Pt as logFetch,
|
|
782
792
|
f as logger,
|
|
783
793
|
re as register,
|
|
794
|
+
se as registerAction,
|
|
784
795
|
j as serializeIncludingFunctions,
|
|
785
|
-
|
|
786
|
-
|
|
796
|
+
ue as setClientUserAttributes,
|
|
797
|
+
oe as setEditorSettings,
|
|
787
798
|
_t as setupBrowserForEditing,
|
|
788
|
-
|
|
789
|
-
|
|
799
|
+
ae as subscribeToEditor,
|
|
800
|
+
ie as track,
|
|
790
801
|
nt as userAttributesService
|
|
791
802
|
};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";const S="react",A="[Builder.io]: ",d={log:(...t)=>console.log(A,...t),error:(...t)=>console.error(A,...t),warn:(...t)=>console.warn(A,...t),debug:(...t)=>console.debug(A,...t)};function a(){return typeof window!="undefined"&&typeof document!="undefined"}const yt=t=>{const e={};return t.forEach((n,r)=>{e[r]=n}),e},G=t=>t instanceof URLSearchParams?yt(t):t,$=t=>typeof t=="string"?t:t instanceof URLSearchParams?t.toString():new URLSearchParams(t).toString();function bt(){return a()&&window.self!==window.top}function J(t){return bt()&&$(t||window.location.search).indexOf("builder.frameEditing=")!==-1}const mt=()=>{if(a()){const t=new URL(location.href);return t.pathname===""&&(t.pathname="/"),t}else return console.warn("Cannot get location for tracking in non-browser environment"),null},wt=()=>typeof navigator=="object"&&navigator.userAgent||"",z=()=>{const t=wt(),e={Android(){return t.match(/Android/i)},BlackBerry(){return t.match(/BlackBerry/i)},iOS(){return t.match(/iPhone|iPod/i)},Opera(){return t.match(/Opera Mini/i)},Windows(){return t.match(/IEMobile/i)||t.match(/WPDesktop/i)},any(){return e.Android()||e.BlackBerry()||e.iOS()||e.Opera()||e.Windows()||S==="reactNative"}},n=t.match(/Tablet|iPad/i),r=mt();return{urlPath:r==null?void 0:r.pathname,host:(r==null?void 0:r.host)||(r==null?void 0:r.hostname),device:n?"tablet":e.any()?"mobile":"desktop"}},p=t=>t!=null;function Et(t){const e=t||(a()?window.location.search:void 0);return e?$(e).indexOf("builder.preview=")!==-1:!1}const It=t=>({type:"builder.registerComponent",data:O(t)}),At=t=>{const e=t.toString().trim(),n=/^[a-zA-Z0-9_]+\s*=>/i.test(e);return`return (${!e.startsWith("function")&&!e.startsWith("async")&&!e.startsWith("(")&&!n?"function ":""}${e}).apply(this, arguments)`};function O(t){return JSON.parse(JSON.stringify(t,(e,n)=>typeof n=="function"?At(n):n))}const V={};function vt(t,e){t==="plugin"&&(e=O(e));let n=V[t];if(n||(n=V[t]=[]),n.push(e),a()){const r={type:"builder.register",data:{type:t,info:e}};try{parent.postMessage(r,"*"),parent!==window&&window.postMessage(r,"*")}catch(s){console.debug("Could not postmessage",s)}}}function kt(t){var e;if(a()){const n=JSON.parse(JSON.stringify(t));t.action&&(n.action=t.action.toString()),(e=window.parent)==null||e.postMessage({type:"builder.registerAction",data:n},"*")}}const D={};function Ut(t){if(a()){Object.assign(D,t);const e={type:"builder.settingsChange",data:D};parent.postMessage(e,"*")}}const F="builder.",Tt="options.",P=t=>{if(!t)return{};const e=G(t),n={};return Object.keys(e).forEach(r=>{if(r.startsWith(F)){const s=r.replace(F,"").replace(Tt,"");n[s]=e[r]}}),n},Ot=()=>{if(!a())return{};const t=new URLSearchParams(window.location.search);return P(t)},X="4.2.2",H=()=>({"X-Builder-SDK":S,"X-Builder-SDK-GEN":"2","X-Builder-SDK-Version":X}),Pt=t=>{if(t==="localhost"||t==="127.0.0.1")return t;const e=t.split(".");return e.length>2?e.slice(1).join("."):t},v=({name:t,canTrack:e})=>{var n;try{return e?(n=document.cookie.split("; ").find(r=>r.startsWith(`${t}=`)))==null?void 0:n.split("=")[1]:void 0}catch(r){d.warn("[COOKIE] GET error: ",(r==null?void 0:r.message)||r);return}},Q=async t=>v(t),Rt=t=>t.map(([e,n])=>n?`${e}=${n}`:e).filter(p).join("; "),Ct=[["secure",""],["SameSite","None"]],Bt=({name:t,value:e,expires:n})=>{const s=(a()?location.protocol==="https:":!0)?Ct:[[]],o=n?[["expires",n.toUTCString()]]:[[]],i=[[t,e],...o,["path","/"],["domain",Pt(window.location.hostname)],...s];return Rt(i)},R=async({name:t,value:e,expires:n,canTrack:r})=>{try{if(!r)return;const s=Bt({name:t,value:e,expires:n});document.cookie=s}catch(s){d.warn("[COOKIE] SET error: ",(s==null?void 0:s.message)||s)}};function _t(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){const e=Math.random()*16|0;return(t=="x"?e:e&3|8).toString(16)})}function Y(){return _t().replace(/-/g,"")}const Z="builderSessionId",xt=async({canTrack:t})=>{if(!t)return;const e=await Q({name:Z,canTrack:t});if(p(e))return e;{const n=Lt();return Nt({id:n,canTrack:t}),n}},Lt=()=>Y(),Nt=({id:t,canTrack:e})=>R({name:Z,value:t,canTrack:e}),q=()=>a()&&typeof localStorage!="undefined"?localStorage:void 0,Vt=({key:t,canTrack:e})=>{var n;try{return e?(n=q())==null?void 0:n.getItem(t):void 0}catch(r){console.debug("[LocalStorage] GET error: ",r);return}},Dt=({key:t,canTrack:e,value:n})=>{var r;try{e&&((r=q())==null||r.setItem(t,n))}catch(s){console.debug("[LocalStorage] SET error: ",s)}},tt="builderVisitorId",Ft=({canTrack:t})=>{if(!t)return;const e=Vt({key:tt,canTrack:t});if(p(e))return e;{const n=Mt();return Kt({id:n,canTrack:t}),n}},Mt=()=>Y(),Kt=({id:t,canTrack:e})=>Dt({key:tt,value:t,canTrack:e});function et(t){var e;typeof process!="undefined"&&((e=process.env)!=null&&e.DEBUG)&&String(process.env.DEBUG)=="true"&&d.log(t)}const Wt=async({canTrack:t})=>{if(!t)return{visitorId:void 0,sessionId:void 0};const e=await xt({canTrack:t}),n=Ft({canTrack:t});return{sessionId:e,visitorId:n}},jt=async({type:t,canTrack:e,apiKey:n,metadata:r,...s})=>({type:t,data:{...s,metadata:{url:location.href,...r},...await Wt({canTrack:e}),userAttributes:z(),ownerId:n}});async function nt({apiHost:t,...e}){if(!e.apiKey){d.error("Missing API key for track call. Please provide your API key.");return}if(!e.canTrack||J()||!(a()||S==="reactNative"))return;const r=`${t||"https://cdn.builder.io"}/api/v1/track`;return et(r),fetch(r,{method:"POST",body:JSON.stringify({events:[await jt(e)]}),headers:{"content-type":"application/json",...H()},mode:"cors"}).catch(s=>{console.error("Failed to track: ",s)})}const Gt=t=>nt({...t,canTrack:!0}),$t=["*.beta.builder.io","beta.builder.io","builder.io","localhost","qa.builder.io"];function rt(t,e){if(!e.origin.startsWith("http")&&!e.origin.startsWith("https"))return!1;const n=new URL(e.origin),r=n.hostname;return(t||$t).findIndex(s=>s.startsWith("*.")?r.endsWith(s.slice(1)):s===r)>-1}let M=!1;const st=t=>{var e,n;M||(M=!0,a()&&((e=window.parent)==null||e.postMessage({type:"builder.sdkInfo",data:{target:S,version:X,supportsPatchUpdates:!1,supportsAddBlockScoping:!0,supportsCustomBreakpoints:!0,modelName:t.modelName,apiKey:t.apiKey,supportsXSmallBreakpoint:!0,blockLevelPersonalization:!0}},"*"),(n=window.parent)==null||n.postMessage({type:"builder.updateContent",data:{options:t}},"*"),window.addEventListener("message",r=>{var o,i;if(!rt(t.trustedHosts,r))return;const{data:s}=r;if(s!=null&&s.type)switch(s.type){case"builder.evaluate":{const u=s.data.text,m=s.data.arguments||[],y=s.data.id,w=new Function(u);let l,g=null;try{l=w.apply(null,m)}catch(h){g=h}g?(o=window.parent)==null||o.postMessage({type:"builder.evaluateError",data:{id:y,error:g.message}},"*"):l&&typeof l.then=="function"?l.then(h=>{var E;(E=window.parent)==null||E.postMessage({type:"builder.evaluateResult",data:{id:y,result:h}},"*")}).catch(console.error):(i=window.parent)==null||i.postMessage({type:"builder.evaluateResult",data:{result:l,id:y}},"*");break}}})))},ot=({model:t,trustedHosts:e,callbacks:n})=>r=>{if(!rt(e,r))return;const{data:s}=r;if(s)switch(s.type){case"builder.configureSdk":{n.configureSdk(s.data);break}case"builder.triggerAnimation":{n.animation(s.data);break}case"builder.resetState":{const o=s.data,i=o.model,u=o==null?void 0:o.state;i===t&&u&&n.stateUpdate(u);break}case"builder.contentUpdate":{const o=s.data,i=o.key||o.alias||o.entry||o.modelName,u=o.data;i===t&&n.contentUpdate(u);break}}},Jt=({model:t,apiKey:e,callback:n,trustedHosts:r})=>{if(!a)return d.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server."),()=>{};st({modelName:t,apiKey:e});const s=ot({callbacks:{contentUpdate:n,animation:()=>{},configureSdk:()=>{},stateUpdate:()=>{}},model:t,trustedHosts:r});return window.addEventListener("message",s),()=>{window.removeEventListener("message",s)}},zt="builder.tests",C=t=>`${zt}.${t}`,Xt=({contentId:t})=>Q({name:C(t),canTrack:!0}),Ht=({contentId:t})=>v({name:C(t),canTrack:!0}),Qt=({contentId:t,value:e})=>R({name:C(t),value:e,canTrack:!0}),it=t=>p(t.id)&&p(t.variations)&&Object.keys(t.variations).length>0,Yt=({id:t,variations:e})=>{var s;let n=0;const r=Math.random();for(const o in e){const i=(s=e[o])==null?void 0:s.testRatio;if(n+=i,r<n)return o}return t},at=t=>{const e=Yt(t);return Qt({contentId:t.id,value:e}).catch(n=>{d.error("could not store A/B test variation: ",n)}),e},ct=({item:t,testGroupId:e})=>{const n=t.variations[e];return e===t.id||!n?{testVariationId:t.id,testVariationName:"Default"}:{data:n.data,testVariationId:n.id,testVariationName:n.name||(n.id===t.id?"Default":"")}},Zt=({item:t,canTrack:e})=>{if(!e)return t;if(!t)return;if(!it(t))return t;const n=Ht({contentId:t.id})||at({variations:t.variations,id:t.id}),r=ct({item:t,testGroupId:n});return{...t,...r}},qt=async({item:t,canTrack:e})=>{if(!e||!it(t))return t;const r=await Xt({contentId:t.id})||at({variations:t.variations,id:t.id}),s=ct({item:t,testGroupId:r});return{...t,...s}};const K="builder.userAttributes";function W(){let t=!0;const e=new Set;return{setUserAttributes(n){if(!a())return;const r={...this.getUserAttributes(),...n};R({name:K,value:JSON.stringify(r),canTrack:t}),e.forEach(s=>s(r))},getUserAttributes(){return a()?JSON.parse(v({name:K,canTrack:t})||"{}"):{}},subscribeOnUserAttributesChange(n,{fireImmediately:r}={}){return e.add(n),r&&n(this.getUserAttributes()),function(){e.delete(n)}},setCanTrack(n){t=n}}}let U;a()&&S==="qwik"?(window.__BUILDER_USER_ATTRIBUTES_SERVICE__||(window.__BUILDER_USER_ATTRIBUTES_SERVICE__=W()),U=window.__BUILDER_USER_ATTRIBUTES_SERVICE__):U=W();const B=U,te=t=>{B.setUserAttributes(t)},ut=t=>{const e=p(t)?t:!0;return B.setCanTrack(e),e};function ee(){return typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:globalThis}function ne(){const t=ee().fetch;if(typeof t=="undefined")throw console.warn(`Builder SDK could not find a global fetch function. Make sure you have a polyfill for fetch in your project.
|
|
2
|
+
For more information, read https://github.com/BuilderIO/this-package-uses-fetch`),new Error("Builder SDK could not find a global `fetch` function");return t}const re=ne();function T(t,e=null,n="."){return Object.keys(t).reduce((r,s)=>{const o=t[s],i=[e,s].filter(Boolean).join(n);return[typeof o=="object",o!==null,!(Array.isArray(o)&&o.length===0)].every(Boolean)?{...r,...T(o,i,n)}:{...r,[i]:o}},{})}function lt(t,e,n={}){for(const r in t){const s=t[r],o=e?e+"."+r:r;s&&typeof s=="object"&&!Array.isArray(s)&&!Object.keys(s).find(i=>i.startsWith("$"))?lt(s,o,n):n[o]=s}return n}function se(t){const e={};for(const n in t){const r=n.split(".");let s=e;for(let o=0;o<r.length;o++){const i=r[o];o===r.length-1?s[i]=t[n]:(s[i]=s[i]||{},s=s[i])}}return e}const oe="v3",j=t=>typeof t=="number"&&!isNaN(t)&&t>=0,_=t=>{const{limit:e=30,userAttributes:n,query:r,model:s,apiKey:o,enrich:i,locale:u,apiVersion:m=oe,fields:y,omit:w,offset:l,cacheSeconds:g,staleCacheSeconds:h,sort:E,includeUnpublished:x,apiHost:ht}=t;if(!o)throw new Error("Missing API key");if(!["v3"].includes(m))throw new Error(`Invalid apiVersion: expected 'v3', received '${m}'`);const pt=e!==1,St=ht||"https://cdn.builder.io",c=new URL(`${St}/api/${m}/content/${s}`);c.searchParams.set("apiKey",o),c.searchParams.set("limit",String(e)),c.searchParams.set("noTraverse",String(pt)),c.searchParams.set("includeRefs",String(!0));const k=u||(n==null?void 0:n.locale);let b=n||{};if(k&&(c.searchParams.set("locale",k),b={locale:k,...b}),i&&c.searchParams.set("enrich",String(i)),c.searchParams.set("omit",w!=null?w:"meta.componentsUsed"),y&&c.searchParams.set("fields",y),Number.isFinite(l)&&l>-1&&c.searchParams.set("offset",String(Math.floor(l))),typeof x=="boolean"&&c.searchParams.set("includeUnpublished",String(x)),g&&j(g)&&c.searchParams.set("cacheSeconds",String(g)),h&&j(h)&&c.searchParams.set("staleCacheSeconds",String(h)),E){const f=T({sort:E});for(const I in f)c.searchParams.set(I,JSON.stringify(f[I]))}const L={...Ot(),...G(t.options||{})};b={...b,...ae(L)};const N=T(L);for(const f in N)c.searchParams.set(f,String(N[f]));if(Object.keys(b).length>0&&c.searchParams.set("userAttributes",JSON.stringify(b)),r){const f=lt({query:r});for(const I in f)c.searchParams.set(I,JSON.stringify(f[I]))}return c},ie=t=>{const e={};for(const n in t)n.startsWith("userAttributes.")&&(e[n]=t[n],delete t[n]);return e},ae=t=>{if(a()&&t.preview==="BUILDER_STUDIO"){t["userAttributes.urlPath"]=window.location.pathname,t["userAttributes.host"]=window.location.host;const e=ie(t),{userAttributes:n}=se(e);return n}return{}},ce=t=>"results"in t;async function dt(t){const e=await gt({...t,limit:1});return e&&e[0]||null}const ue=async t=>{var i,u;const e=_(t),n=(i=t.fetch)!=null?i:re,r={...t.fetchOptions,headers:{...(u=t.fetchOptions)==null?void 0:u.headers,...H()}};return await(await n(e.href,r)).json()},ft=async(t,e,n=_(t))=>{const r=ut(t.canTrack);if(n.search.includes("preview="),!r||!(a()||S==="reactNative"))return e.results;try{const s=[];for(const o of e.results)s.push(await qt({item:o,canTrack:r}));e.results=s}catch(s){d.error("Could not process A/B tests. ",s)}return e.results};async function gt(t){const e=_(t),n=await ue(t);if(!ce(n))throw d.error("Error fetching data. ",{url:e,content:n,options:t}),n;return ft(t,n)}const le=async t=>{var r,s,o;const e=t.path||((r=t.url)==null?void 0:r.pathname)||((s=t.userAttributes)==null?void 0:s.urlPath),n={...t,apiKey:t.apiKey,model:t.model||"page",userAttributes:{...t.userAttributes,...e?{urlPath:e}:{}},options:P(t.searchParams||((o=t.url)==null?void 0:o.searchParams)||t.options)};return{apiKey:n.apiKey,model:n.model,content:await dt(n)}};exports.MSG_PREFIX=A;exports.TARGET=S;exports._processContentResult=ft;exports._track=nt;exports.checkIsDefined=p;exports.createEditorListener=ot;exports.createRegisterComponentMessage=It;exports.fetchBuilderProps=le;exports.fetchEntries=gt;exports.fetchOneEntry=dt;exports.getBuilderSearchParams=P;exports.getCookieSync=v;exports.getDefaultCanTrack=ut;exports.getUserAttributes=z;exports.handleABTestingSync=Zt;exports.isBrowser=a;exports.isEditing=J;exports.isPreviewing=Et;exports.logFetch=et;exports.logger=d;exports.register=vt;exports.registerAction=kt;exports.serializeIncludingFunctions=O;exports.setClientUserAttributes=te;exports.setEditorSettings=Ut;exports.setupBrowserForEditing=st;exports.subscribeToEditor=Jt;exports.track=Gt;exports.userAttributesService=B;
|
|
@@ -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-d40e4b66.cjs");exports._processContentResult=e._processContentResult;exports.createRegisterComponentMessage=e.createRegisterComponentMessage;exports.fetchBuilderProps=e.fetchBuilderProps;exports.fetchEntries=e.fetchEntries;exports.fetchOneEntry=e.fetchOneEntry;exports.getBuilderSearchParams=e.getBuilderSearchParams;exports.isEditing=e.isEditing;exports.isPreviewing=e.isPreviewing;exports.register=e.register;exports.registerAction=e.registerAction;exports.setEditorSettings=e.setEditorSettings;exports.subscribeToEditor=e.subscribeToEditor;exports.track=e.track;
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { _processContentResult as r, createRegisterComponentMessage as
|
|
1
|
+
import { _processContentResult as r, createRegisterComponentMessage as i, fetchBuilderProps as s, fetchEntries as n, fetchOneEntry as o, getBuilderSearchParams as c, isEditing as g, isPreviewing as a, register as d, registerAction as E, setEditorSettings as f, subscribeToEditor as h, track as p } from "./server-entry-83d3751d.js";
|
|
2
2
|
export {
|
|
3
3
|
r as _processContentResult,
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
i as createRegisterComponentMessage,
|
|
5
|
+
s as fetchBuilderProps,
|
|
6
6
|
n as fetchEntries,
|
|
7
7
|
o as fetchOneEntry,
|
|
8
8
|
c as getBuilderSearchParams,
|
|
9
9
|
g as isEditing,
|
|
10
10
|
a as isPreviewing,
|
|
11
11
|
d as register,
|
|
12
|
-
E as
|
|
13
|
-
f as
|
|
14
|
-
h as
|
|
12
|
+
E as registerAction,
|
|
13
|
+
f as setEditorSettings,
|
|
14
|
+
h as subscribeToEditor,
|
|
15
|
+
p as track
|
|
15
16
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";const serverEntry=require("./server-entry-
|
|
1
|
+
"use strict";const serverEntry=require("./server-entry-d40e4b66.cjs"),getFunctionArguments=({builder:e,context:t,event:s,state:r})=>Object.entries({state:r,Builder:e,builder:e,context:t,event:s}),getBuilderGlobals=()=>({isEditing:serverEntry.isEditing(),isBrowser:serverEntry.isBrowser(),isServer:!serverEntry.isBrowser(),getUserAttributes:()=>serverEntry.getUserAttributes()}),parseCode=(e,{isExpression:t=!0})=>t&&!(e.includes(";")||e.includes(" return ")||e.trim().startsWith("return "))?`return (${e});`:e;function flattenState({rootState:e,localState:t,rootSetState:s}){return new Proxy(e,{get:(r,n)=>{if(t&&n in t)return t[n];const o=r[n];return typeof o=="object"&&o!==null?flattenState({rootState:o,localState:void 0,rootSetState:s?i=>{r[n]=i,s(r)}:void 0}):o},set:(r,n,o)=>{if(t&&n in t)throw new Error("Writing to local state is not allowed as it is read-only.");return r[n]=o,s==null||s(r),!0}})}const SDK_NAME_FOR_TARGET=(()=>{switch(serverEntry.TARGET){case"rsc":return"react-nextjs";case"reactNative":return"react-native";default:return serverEntry.TARGET}})(),SDK_NAME=`@builder.io/sdk-${SDK_NAME_FOR_TARGET}`,fastClone=e=>JSON.parse(JSON.stringify(e)),set=(e,t,s)=>{if(Object(e)!==e)return e;const r=Array.isArray(t)?t:t.toString().match(/[^.[\]]+/g);return r.slice(0,-1).reduce((n,o,i)=>Object(n[o])===n[o]?n[o]:n[o]=Math.abs(Number(r[i+1]))>>0===+r[i+1]?[]:{},e)[r[r.length-1]]=s,e},noop=()=>{};let safeDynamicRequire=noop;try{safeDynamicRequire=eval("require")}catch(e){}const getSyncValName=e=>`bldr_${e}_sync`,BUILDER_SET_STATE_NAME="BUILDER_SET_STATE",INJECTED_IVM_GLOBAL="BUILDER_IVM",REF_TO_PROXY_FN=`
|
|
2
2
|
var refToProxy = (obj) => {
|
|
3
3
|
if (typeof obj !== 'object' || obj === null) {
|
|
4
4
|
return obj;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isEditing, isBrowser, getUserAttributes, TARGET, logger, MSG_PREFIX } from "./server-entry-
|
|
1
|
+
import { isEditing, isBrowser, getUserAttributes, TARGET, logger, MSG_PREFIX } from "./server-entry-83d3751d.js";
|
|
2
2
|
const getFunctionArguments = ({
|
|
3
3
|
builder: e,
|
|
4
4
|
context: t,
|
package/lib/node/setIvm.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./setIvm-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./setIvm-0a5b2ba2.cjs");require("./server-entry-d40e4b66.cjs");exports.setIvm=e.setIvm;
|
package/lib/node/setIvm.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { checkIsDefined as i, logger as t } from "./server-entry-
|
|
1
|
+
import { checkIsDefined as i, logger as t } from "./server-entry-83d3751d.js";
|
|
2
2
|
function a() {
|
|
3
3
|
var o;
|
|
4
4
|
return typeof process != "undefined" && i((o = process == null ? void 0 : process.versions) == null ? void 0 : o.node);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const s=require("./server-entry-
|
|
1
|
+
"use strict";const s=require("./server-entry-d40e4b66.cjs");function t(){var e;return typeof process!="undefined"&&s.checkIsDefined((e=process==null?void 0:process.versions)==null?void 0:e.node)}const c=({shouldLogWarning:e})=>{var o;if(!t())return!1;const n=process.arch==="arm64",r=process.version.startsWith("v20"),i=(o=process.env.NODE_OPTIONS)==null?void 0:o.includes("--no-node-snapshot");return n&&r&&!i?(e&&s.logger.log("Skipping usage of `isolated-vm` to avoid crashes in Node v20 on an arm64 machine.\n If you would like to use the `isolated-vm` package on this machine, please provide the `NODE_OPTIONS=--no-node-snapshot` config to your Node process.\n See https://github.com/BuilderIO/builder/blob/main/packages/sdks/README.md#node-v20--m1-macs-apple-silicon-support for more information.\n "),!0):!1};exports.shouldForceBrowserRuntimeInNode=c;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BuilderContent } from '../../types/builder-content';
|
|
2
2
|
import type { BuilderComponentsProp, BuilderDataProps, BuilderLinkComponentProp } from '../../types/builder-props';
|
|
3
|
-
interface SymbolInfo {
|
|
3
|
+
export interface SymbolInfo {
|
|
4
4
|
model?: string;
|
|
5
5
|
entry?: string;
|
|
6
6
|
data?: any;
|
|
@@ -16,4 +16,3 @@ export interface SymbolProps extends BuilderComponentsProp, BuilderDataProps, Bu
|
|
|
16
16
|
inheritState?: boolean;
|
|
17
17
|
renderToLiquid?: boolean;
|
|
18
18
|
}
|
|
19
|
-
export {};
|
|
@@ -1,14 +1,4 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
|
|
3
|
-
* Placeholder component to be overridden by specific SDKs.
|
|
4
|
-
* Allows to dynamically import components.
|
|
5
|
-
*/
|
|
6
|
-
type AwaiterProps = {
|
|
7
|
-
load: () => Promise<any>;
|
|
8
|
-
props?: any;
|
|
9
|
-
attributes?: any;
|
|
10
|
-
fallback?: any;
|
|
11
|
-
children?: any;
|
|
12
|
-
};
|
|
2
|
+
import type { AwaiterProps } from "./awaiter.types";
|
|
13
3
|
declare function Awaiter(props: AwaiterProps): React.JSX.Element;
|
|
14
4
|
export default Awaiter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "4.2.
|
|
1
|
+
export declare const SDK_VERSION = "4.2.2";
|
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
import type { BuilderBlock } from '../types/builder-block';
|
|
2
2
|
import type { DeepPartial } from '../types/deep-partial';
|
|
3
|
+
import type { Input } from '../types/input';
|
|
4
|
+
export interface Action {
|
|
5
|
+
name: string;
|
|
6
|
+
inputs?: readonly Input[];
|
|
7
|
+
returnType?: Input;
|
|
8
|
+
action: (options: Record<string, any>) => string;
|
|
9
|
+
/**
|
|
10
|
+
* Is an action for expression (e.g. calculating a binding like a formula
|
|
11
|
+
* to fill a value based on locale) or a function (e.g. something to trigger
|
|
12
|
+
* on an event like add to cart) or either (e.g. a custom code block)
|
|
13
|
+
*/
|
|
14
|
+
kind: 'expression' | 'function' | 'any';
|
|
15
|
+
/**
|
|
16
|
+
* Globally unique ID for an action, e.g. "@builder.io:setState"
|
|
17
|
+
*/
|
|
18
|
+
id: string;
|
|
19
|
+
}
|
|
3
20
|
export interface InsertMenuItem {
|
|
4
21
|
name: string;
|
|
5
22
|
icon?: string;
|
|
@@ -14,3 +31,4 @@ export interface InsertMenuConfig {
|
|
|
14
31
|
}
|
|
15
32
|
export declare function register(type: 'insertMenu', info: InsertMenuConfig): void;
|
|
16
33
|
export declare function register(type: string, info: any): void;
|
|
34
|
+
export declare function registerAction(action: Action): void;
|
package/types/server-index.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export type { ComponentInfo } from './types/components';
|
|
|
25
25
|
export { isEditing } from './functions/is-editing';
|
|
26
26
|
export { isPreviewing } from './functions/is-previewing';
|
|
27
27
|
export { createRegisterComponentMessage } from './functions/register-component';
|
|
28
|
-
export { register } from './functions/register';
|
|
28
|
+
export { register, registerAction } from './functions/register';
|
|
29
29
|
export type { InsertMenuConfig, InsertMenuItem } from './functions/register';
|
|
30
30
|
export { setEditorSettings } from './functions/set-editor-settings';
|
|
31
31
|
export type { Settings } from './functions/set-editor-settings';
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";const S="react",v="[Builder.io]: ",d={log:(...t)=>console.log(v,...t),error:(...t)=>console.error(v,...t),warn:(...t)=>console.warn(v,...t),debug:(...t)=>console.debug(v,...t)};function c(){return typeof window!="undefined"&&typeof document!="undefined"}const bt=t=>{const e={};return t.forEach((r,n)=>{e[n]=r}),e},$=t=>t instanceof URLSearchParams?bt(t):t,G=t=>typeof t=="string"?t:t instanceof URLSearchParams?t.toString():new URLSearchParams(t).toString();function yt(){return c()&&window.self!==window.top}function z(t){return yt()&&G(t||window.location.search).indexOf("builder.frameEditing=")!==-1}const mt=()=>{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},wt=()=>typeof navigator=="object"&&navigator.userAgent||"",J=()=>{const t=wt(),e={Android(){return t.match(/Android/i)},BlackBerry(){return t.match(/BlackBerry/i)},iOS(){return t.match(/iPhone|iPod/i)},Opera(){return t.match(/Opera Mini/i)},Windows(){return t.match(/IEMobile/i)||t.match(/WPDesktop/i)},any(){return e.Android()||e.BlackBerry()||e.iOS()||e.Opera()||e.Windows()||S==="reactNative"}},r=t.match(/Tablet|iPad/i),n=mt();return{urlPath:n==null?void 0:n.pathname,host:(n==null?void 0:n.host)||(n==null?void 0:n.hostname),device:r?"tablet":e.any()?"mobile":"desktop"}},p=t=>t!=null;function Et(t){const e=t||(c()?window.location.search:void 0);return e?G(e).indexOf("builder.preview=")!==-1:!1}const It=t=>({type:"builder.registerComponent",data:O(t)}),vt=t=>{const e=t.toString().trim(),r=/^[a-zA-Z0-9_]+\s*=>/i.test(e);return`return (${!e.startsWith("function")&&!e.startsWith("async")&&!e.startsWith("(")&&!r?"function ":""}${e}).apply(this, arguments)`};function O(t){return JSON.parse(JSON.stringify(t,(e,r)=>typeof r=="function"?vt(r):r))}const V={};function At(t,e){t==="plugin"&&(e=O(e));let r=V[t];if(r||(r=V[t]=[]),r.push(e),c()){const n={type:"builder.register",data:{type:t,info:e}};try{parent.postMessage(n,"*"),parent!==window&&window.postMessage(n,"*")}catch(s){console.debug("Could not postmessage",s)}}}const D={};function kt(t){if(c()){Object.assign(D,t);const e={type:"builder.settingsChange",data:D};parent.postMessage(e,"*")}}const F="builder.",Ut="options.",P=t=>{if(!t)return{};const e=$(t),r={};return Object.keys(e).forEach(n=>{if(n.startsWith(F)){const s=n.replace(F,"").replace(Ut,"");r[s]=e[n]}}),r},Tt=()=>{if(!c())return{};const t=new URLSearchParams(window.location.search);return P(t)},X="4.2.0",H=()=>({"X-Builder-SDK":S,"X-Builder-SDK-GEN":"2","X-Builder-SDK-Version":X}),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},A=({name:t,canTrack:e})=>{var r;try{return e?(r=document.cookie.split("; ").find(n=>n.startsWith(`${t}=`)))==null?void 0:r.split("=")[1]:void 0}catch(n){d.warn("[COOKIE] GET error: ",(n==null?void 0:n.message)||n);return}},Q=async t=>A(t),Pt=t=>t.map(([e,r])=>r?`${e}=${r}`:e).filter(p).join("; "),Rt=[["secure",""],["SameSite","None"]],Ct=({name:t,value:e,expires:r})=>{const s=(c()?location.protocol==="https:":!0)?Rt:[[]],o=r?[["expires",r.toUTCString()]]:[[]],i=[[t,e],...o,["path","/"],["domain",Ot(window.location.hostname)],...s];return Pt(i)},R=async({name:t,value:e,expires:r,canTrack:n})=>{try{if(!n)return;const s=Ct({name:t,value:e,expires:r});document.cookie=s}catch(s){d.warn("[COOKIE] SET error: ",(s==null?void 0:s.message)||s)}};function Bt(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){const e=Math.random()*16|0;return(t=="x"?e:e&3|8).toString(16)})}function Y(){return Bt().replace(/-/g,"")}const Z="builderSessionId",xt=async({canTrack:t})=>{if(!t)return;const e=await Q({name:Z,canTrack:t});if(p(e))return e;{const r=_t();return Lt({id:r,canTrack:t}),r}},_t=()=>Y(),Lt=({id:t,canTrack:e})=>R({name:Z,value:t,canTrack:e}),q=()=>c()&&typeof localStorage!="undefined"?localStorage:void 0,Nt=({key:t,canTrack:e})=>{var r;try{return e?(r=q())==null?void 0:r.getItem(t):void 0}catch(n){console.debug("[LocalStorage] GET error: ",n);return}},Vt=({key:t,canTrack:e,value:r})=>{var n;try{e&&((n=q())==null||n.setItem(t,r))}catch(s){console.debug("[LocalStorage] SET error: ",s)}},tt="builderVisitorId",Dt=({canTrack:t})=>{if(!t)return;const e=Nt({key:tt,canTrack:t});if(p(e))return e;{const r=Ft();return Kt({id:r,canTrack:t}),r}},Ft=()=>Y(),Kt=({id:t,canTrack:e})=>Vt({key:tt,value:t,canTrack:e});function et(t){var e;typeof process!="undefined"&&((e=process.env)!=null&&e.DEBUG)&&String(process.env.DEBUG)=="true"&&d.log(t)}const Mt=async({canTrack:t})=>{if(!t)return{visitorId:void 0,sessionId:void 0};const e=await xt({canTrack:t}),r=Dt({canTrack:t});return{sessionId:e,visitorId:r}},Wt=async({type:t,canTrack:e,apiKey:r,metadata:n,...s})=>({type:t,data:{...s,metadata:{url:location.href,...n},...await Mt({canTrack:e}),userAttributes:J(),ownerId:r}});async function rt({apiHost:t,...e}){if(!e.apiKey){d.error("Missing API key for track call. Please provide your API key.");return}if(!e.canTrack||z()||!(c()||S==="reactNative"))return;const n=`${t||"https://cdn.builder.io"}/api/v1/track`;return et(n),fetch(n,{method:"POST",body:JSON.stringify({events:[await Wt(e)]}),headers:{"content-type":"application/json",...H()},mode:"cors"}).catch(s=>{console.error("Failed to track: ",s)})}const jt=t=>rt({...t,canTrack:!0}),$t=["*.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 r=new URL(e.origin),n=r.hostname;return(t||$t).findIndex(s=>s.startsWith("*.")?n.endsWith(s.slice(1)):s===n)>-1}let K=!1;const st=t=>{var e,r;K||(K=!0,c()&&((e=window.parent)==null||e.postMessage({type:"builder.sdkInfo",data:{target:S,version:X,supportsPatchUpdates:!1,supportsAddBlockScoping:!0,supportsCustomBreakpoints:!0,modelName:t.modelName,apiKey:t.apiKey,supportsXSmallBreakpoint:!0,blockLevelPersonalization:!0}},"*"),(r=window.parent)==null||r.postMessage({type:"builder.updateContent",data:{options:t}},"*"),window.addEventListener("message",n=>{var o,i;if(!nt(t.trustedHosts,n))return;const{data:s}=n;if(s!=null&&s.type)switch(s.type){case"builder.evaluate":{const u=s.data.text,m=s.data.arguments||[],b=s.data.id,w=new Function(u);let l,h=null;try{l=w.apply(null,m)}catch(g){h=g}h?(o=window.parent)==null||o.postMessage({type:"builder.evaluateError",data:{id:b,error:h.message}},"*"):l&&typeof l.then=="function"?l.then(g=>{var E;(E=window.parent)==null||E.postMessage({type:"builder.evaluateResult",data:{id:b,result:g}},"*")}).catch(console.error):(i=window.parent)==null||i.postMessage({type:"builder.evaluateResult",data:{result:l,id:b}},"*");break}}})))},ot=({model:t,trustedHosts:e,callbacks:r})=>n=>{if(!nt(e,n))return;const{data:s}=n;if(s)switch(s.type){case"builder.configureSdk":{r.configureSdk(s.data);break}case"builder.triggerAnimation":{r.animation(s.data);break}case"builder.resetState":{const o=s.data,i=o.model,u=o==null?void 0:o.state;i===t&&u&&r.stateUpdate(u);break}case"builder.contentUpdate":{const o=s.data,i=o.key||o.alias||o.entry||o.modelName,u=o.data;i===t&&r.contentUpdate(u);break}}},Gt=({model:t,apiKey:e,callback:r,trustedHosts:n})=>{if(!c)return d.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server."),()=>{};st({modelName:t,apiKey:e});const s=ot({callbacks:{contentUpdate:r,animation:()=>{},configureSdk:()=>{},stateUpdate:()=>{}},model:t,trustedHosts:n});return window.addEventListener("message",s),()=>{window.removeEventListener("message",s)}},zt="builder.tests",C=t=>`${zt}.${t}`,Jt=({contentId:t})=>Q({name:C(t),canTrack:!0}),Xt=({contentId:t})=>A({name:C(t),canTrack:!0}),Ht=({contentId:t,value:e})=>R({name:C(t),value:e,canTrack:!0}),it=t=>p(t.id)&&p(t.variations)&&Object.keys(t.variations).length>0,Qt=({id:t,variations:e})=>{var s;let r=0;const n=Math.random();for(const o in e){const i=(s=e[o])==null?void 0:s.testRatio;if(r+=i,n<r)return o}return t},at=t=>{const e=Qt(t);return Ht({contentId:t.id,value:e}).catch(r=>{d.error("could not store A/B test variation: ",r)}),e},ct=({item:t,testGroupId:e})=>{const r=t.variations[e];return e===t.id||!r?{testVariationId:t.id,testVariationName:"Default"}:{data:r.data,testVariationId:r.id,testVariationName:r.name||(r.id===t.id?"Default":"")}},Yt=({item:t,canTrack:e})=>{if(!e)return t;if(!t)return;if(!it(t))return t;const r=Xt({contentId:t.id})||at({variations:t.variations,id:t.id}),n=ct({item:t,testGroupId:r});return{...t,...n}},Zt=async({item:t,canTrack:e})=>{if(!e||!it(t))return t;const n=await Jt({contentId:t.id})||at({variations:t.variations,id:t.id}),s=ct({item:t,testGroupId:n});return{...t,...s}};const M="builder.userAttributes";function W(){let t=!0;const e=new Set;return{setUserAttributes(r){if(!c())return;const n={...this.getUserAttributes(),...r};R({name:M,value:JSON.stringify(n),canTrack:t}),e.forEach(s=>s(n))},getUserAttributes(){return c()?JSON.parse(A({name:M,canTrack:t})||"{}"):{}},subscribeOnUserAttributesChange(r,{fireImmediately:n}={}){return e.add(r),n&&r(this.getUserAttributes()),function(){e.delete(r)}},setCanTrack(r){t=r}}}let U;c()&&S==="qwik"?(window.__BUILDER_USER_ATTRIBUTES_SERVICE__||(window.__BUILDER_USER_ATTRIBUTES_SERVICE__=W()),U=window.__BUILDER_USER_ATTRIBUTES_SERVICE__):U=W();const B=U,qt=t=>{B.setUserAttributes(t)},ut=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 re=ee();function T(t,e=null,r="."){return Object.keys(t).reduce((n,s)=>{const o=t[s],i=[e,s].filter(Boolean).join(r);return[typeof o=="object",o!==null,!(Array.isArray(o)&&o.length===0)].every(Boolean)?{...n,...T(o,i,r)}:{...n,[i]:o}},{})}function lt(t,e,r={}){for(const n in t){const s=t[n],o=e?e+"."+n:n;s&&typeof s=="object"&&!Array.isArray(s)&&!Object.keys(s).find(i=>i.startsWith("$"))?lt(s,o,r):r[o]=s}return r}function ne(t){const e={};for(const r in t){const n=r.split(".");let s=e;for(let o=0;o<n.length;o++){const i=n[o];o===n.length-1?s[i]=t[r]:(s[i]=s[i]||{},s=s[i])}}return e}const se="v3",j=t=>typeof t=="number"&&!isNaN(t)&&t>=0,x=t=>{const{limit:e=30,userAttributes:r,query:n,model:s,apiKey:o,enrich:i,locale:u,apiVersion:m=se,fields:b,omit:w,offset:l,cacheSeconds:h,staleCacheSeconds:g,sort:E,includeUnpublished:_,apiHost:gt}=t;if(!o)throw new Error("Missing API key");if(!["v3"].includes(m))throw new Error(`Invalid apiVersion: expected 'v3', received '${m}'`);const pt=e!==1,St=gt||"https://cdn.builder.io",a=new URL(`${St}/api/${m}/content/${s}`);a.searchParams.set("apiKey",o),a.searchParams.set("limit",String(e)),a.searchParams.set("noTraverse",String(pt)),a.searchParams.set("includeRefs",String(!0));const k=u||(r==null?void 0:r.locale);let y=r||{};if(k&&(a.searchParams.set("locale",k),y={locale:k,...y}),i&&a.searchParams.set("enrich",String(i)),a.searchParams.set("omit",w!=null?w:"meta.componentsUsed"),b&&a.searchParams.set("fields",b),Number.isFinite(l)&&l>-1&&a.searchParams.set("offset",String(Math.floor(l))),typeof _=="boolean"&&a.searchParams.set("includeUnpublished",String(_)),h&&j(h)&&a.searchParams.set("cacheSeconds",String(h)),g&&j(g)&&a.searchParams.set("staleCacheSeconds",String(g)),E){const f=T({sort:E});for(const I in f)a.searchParams.set(I,JSON.stringify(f[I]))}const L={...Tt(),...$(t.options||{})};y={...y,...ie(L)};const N=T(L);for(const f in N)a.searchParams.set(f,String(N[f]));if(Object.keys(y).length>0&&a.searchParams.set("userAttributes",JSON.stringify(y)),n){const f=lt({query:n});for(const I in f)a.searchParams.set(I,JSON.stringify(f[I]))}return a},oe=t=>{const e={};for(const r in t)r.startsWith("userAttributes.")&&(e[r]=t[r],delete t[r]);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:r}=ne(e);return r}return{}},ae=t=>"results"in t;async function dt(t){const e=await ht({...t,limit:1});return e&&e[0]||null}const ce=async t=>{var i,u;const e=x(t),r=(i=t.fetch)!=null?i:re,n={...t.fetchOptions,headers:{...(u=t.fetchOptions)==null?void 0:u.headers,...H()}};return await(await r(e.href,n)).json()},ft=async(t,e,r=x(t))=>{const n=ut(t.canTrack);if(r.search.includes("preview="),!n||!(c()||S==="reactNative"))return e.results;try{const s=[];for(const o of e.results)s.push(await Zt({item:o,canTrack:n}));e.results=s}catch(s){d.error("Could not process A/B tests. ",s)}return e.results};async function ht(t){const e=x(t),r=await ce(t);if(!ae(r))throw d.error("Error fetching data. ",{url:e,content:r,options:t}),r;return ft(t,r)}const ue=async t=>{var n,s,o;const e=t.path||((n=t.url)==null?void 0:n.pathname)||((s=t.userAttributes)==null?void 0:s.urlPath),r={...t,apiKey:t.apiKey,model:t.model||"page",userAttributes:{...t.userAttributes,...e?{urlPath:e}:{}},options:P(t.searchParams||((o=t.url)==null?void 0:o.searchParams)||t.options)};return{apiKey:r.apiKey,model:r.model,content:await dt(r)}};exports.TARGET=S;exports._processContentResult=ft;exports._track=rt;exports.checkIsDefined=p;exports.createEditorListener=ot;exports.createRegisterComponentMessage=It;exports.fetchBuilderProps=ue;exports.fetchEntries=ht;exports.fetchOneEntry=dt;exports.getBuilderSearchParams=P;exports.getCookieSync=A;exports.getDefaultCanTrack=ut;exports.getUserAttributes=J;exports.handleABTestingSync=Yt;exports.isBrowser=c;exports.isEditing=z;exports.isPreviewing=Et;exports.logFetch=et;exports.logger=d;exports.register=At;exports.serializeIncludingFunctions=O;exports.setClientUserAttributes=qt;exports.setEditorSettings=kt;exports.setupBrowserForEditing=st;exports.subscribeToEditor=Gt;exports.track=jt;exports.userAttributesService=B;
|