@builder.io/sdk-react 2.0.24 → 2.0.25
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 +1 -1
- package/lib/browser/blocks-exports.mjs +1 -1
- package/lib/browser/index.cjs +1 -1
- package/lib/browser/index.mjs +1 -1
- package/lib/browser/server-entry-350f7ecc.js +701 -0
- package/lib/browser/server-entry-f8b08c1e.cjs +2 -0
- package/lib/browser/server-entry.cjs +1 -1
- package/lib/browser/server-entry.mjs +1 -1
- package/lib/edge/{accordion-bb9fa8d9.cjs → accordion-d14d05aa.cjs} +1 -1
- package/lib/edge/{accordion-5b929fba.js → accordion-e2aeca0a.js} +1 -1
- package/lib/edge/{blocks-cff95ab8.cjs → blocks-5a60a8fa.cjs} +1 -1
- package/lib/edge/{blocks-e8701f70.js → blocks-9a763eda.js} +3 -3
- package/lib/edge/blocks-exports.cjs +1 -1
- package/lib/edge/blocks-exports.mjs +2 -2
- package/lib/edge/{button-dd9c397c.js → button-265653d5.js} +2 -2
- package/lib/edge/{button-89adbac2.cjs → button-6ab0c490.cjs} +1 -1
- package/lib/edge/{columns-acd49f06.js → columns-346d4ab7.js} +4 -4
- package/lib/edge/{columns-b0cfdce7.cjs → columns-449335a4.cjs} +1 -1
- package/lib/edge/{content-variants-56c457f6.cjs → content-variants-71459280.cjs} +1 -1
- package/lib/edge/{content-variants-2cbf3c83.js → content-variants-bdb3d738.js} +11 -11
- package/lib/edge/{evaluate-68711886.js → evaluate-be86a5d8.js} +1 -1
- package/lib/edge/{evaluate-efa88e4b.cjs → evaluate-db1f9237.cjs} +1 -1
- package/lib/edge/{form-060579d1.js → form-41305e00.js} +4 -4
- package/lib/edge/{form-85e86f80.cjs → form-90310cab.cjs} +1 -1
- package/lib/edge/{get-class-prop-name-d6d04e54.cjs → get-class-prop-name-711d58eb.cjs} +1 -1
- package/lib/edge/{get-class-prop-name-bb0664a1.js → get-class-prop-name-b49b7684.js} +1 -1
- package/lib/edge/{img-7267e34a.cjs → img-1ab7ba48.cjs} +1 -1
- package/lib/edge/{img-cb9a2e73.js → img-a75bf17b.js} +1 -1
- package/lib/edge/index.cjs +1 -1
- package/lib/edge/index.mjs +1 -1
- package/lib/edge/{input-0a7941d1.cjs → input-137d07aa.cjs} +1 -1
- package/lib/edge/{input-99f775bd.js → input-6c50146c.js} +1 -1
- package/lib/edge/{select-9791ad44.cjs → select-55d2c8fa.cjs} +1 -1
- package/lib/edge/{select-88a74342.js → select-b6c2fdd5.js} +1 -1
- package/lib/edge/server-entry-ae44ef40.cjs +2 -0
- package/lib/edge/server-entry-e914f16e.js +699 -0
- package/lib/edge/server-entry.cjs +1 -1
- package/lib/edge/server-entry.mjs +1 -1
- package/lib/edge/{slot-28b25c84.js → slot-84e40920.js} +4 -4
- package/lib/edge/{slot-d3b5cdb8.cjs → slot-8d3b7707.cjs} +1 -1
- package/lib/edge/{symbol-f0ba82bf.cjs → symbol-468348d8.cjs} +1 -1
- package/lib/edge/{symbol-1ab0fb76.js → symbol-7436ff06.js} +2 -2
- package/lib/edge/{tabs-a04af934.js → tabs-65d455da.js} +4 -4
- package/lib/edge/{tabs-fad92db1.cjs → tabs-802a32f0.cjs} +1 -1
- package/lib/edge/{text-3c4c2e24.js → text-423e3303.js} +2 -2
- package/lib/edge/{text-ee3d6be2.cjs → text-450bf7e4.cjs} +1 -1
- package/lib/node/blocks-exports.cjs +1 -1
- package/lib/node/blocks-exports.mjs +2 -2
- package/lib/node/index.cjs +1 -1
- package/lib/node/index.mjs +2 -2
- package/lib/node/init.cjs +1 -1
- package/lib/node/init.mjs +2 -2
- package/lib/node/server-entry-569f32b2.js +702 -0
- package/lib/node/server-entry-781dde88.cjs +2 -0
- package/lib/node/server-entry.cjs +1 -1
- package/lib/node/server-entry.mjs +1 -1
- package/lib/node/{should-force-browser-runtime-in-node-411c24f8.cjs → should-force-browser-runtime-in-node-13070d3a.cjs} +1 -1
- package/lib/node/{should-force-browser-runtime-in-node-2251f2e6.js → should-force-browser-runtime-in-node-3f610831.js} +1 -1
- package/package.json +1 -1
- package/types/constants/sdk-version.d.ts +1 -1
- package/types/helpers/sdk-headers.d.ts +5 -0
- package/lib/browser/server-entry-0dfca5e0.cjs +0 -2
- package/lib/browser/server-entry-578cd6e2.js +0 -690
- package/lib/edge/server-entry-a7db0ef9.js +0 -688
- package/lib/edge/server-entry-cb6fb618.cjs +0 -2
- package/lib/node/server-entry-2ce603a9.cjs +0 -2
- package/lib/node/server-entry-bf8bf121.js +0 -691
|
@@ -0,0 +1,701 @@
|
|
|
1
|
+
const b = "react", v = "[Builder.io]: ", f = {
|
|
2
|
+
log: (...e) => console.log(v, ...e),
|
|
3
|
+
error: (...e) => console.error(v, ...e),
|
|
4
|
+
warn: (...e) => console.warn(v, ...e),
|
|
5
|
+
debug: (...e) => console.debug(v, ...e)
|
|
6
|
+
};
|
|
7
|
+
function c() {
|
|
8
|
+
return typeof window != "undefined" && typeof document != "undefined";
|
|
9
|
+
}
|
|
10
|
+
const Z = (e) => {
|
|
11
|
+
const t = {};
|
|
12
|
+
return e.forEach((n, r) => {
|
|
13
|
+
t[r] = n;
|
|
14
|
+
}), t;
|
|
15
|
+
}, L = (e) => e instanceof URLSearchParams ? Z(e) : e, V = (e) => typeof e == "string" ? e : e instanceof URLSearchParams ? e.toString() : new URLSearchParams(e).toString();
|
|
16
|
+
function ee() {
|
|
17
|
+
return c() && window.self !== window.top;
|
|
18
|
+
}
|
|
19
|
+
function te(e) {
|
|
20
|
+
return ee() && // accessing window.location.search is safe here because `isIframe()` is only `true` if we're in a browser.
|
|
21
|
+
V(e || window.location.search).indexOf("builder.frameEditing=") !== -1;
|
|
22
|
+
}
|
|
23
|
+
const ne = () => {
|
|
24
|
+
if (c()) {
|
|
25
|
+
const e = new URL(location.href);
|
|
26
|
+
return e.pathname === "" && (e.pathname = "/"), e;
|
|
27
|
+
} else
|
|
28
|
+
return console.warn("Cannot get location for tracking in non-browser environment"), null;
|
|
29
|
+
}, re = () => typeof navigator == "object" && navigator.userAgent || "", oe = () => {
|
|
30
|
+
const e = re(), t = {
|
|
31
|
+
Android() {
|
|
32
|
+
return e.match(/Android/i);
|
|
33
|
+
},
|
|
34
|
+
BlackBerry() {
|
|
35
|
+
return e.match(/BlackBerry/i);
|
|
36
|
+
},
|
|
37
|
+
iOS() {
|
|
38
|
+
return e.match(/iPhone|iPod/i);
|
|
39
|
+
},
|
|
40
|
+
Opera() {
|
|
41
|
+
return e.match(/Opera Mini/i);
|
|
42
|
+
},
|
|
43
|
+
Windows() {
|
|
44
|
+
return e.match(/IEMobile/i) || e.match(/WPDesktop/i);
|
|
45
|
+
},
|
|
46
|
+
any() {
|
|
47
|
+
return t.Android() || t.BlackBerry() || t.iOS() || t.Opera() || t.Windows() || b === "reactNative";
|
|
48
|
+
}
|
|
49
|
+
}, n = e.match(/Tablet|iPad/i), r = ne();
|
|
50
|
+
return {
|
|
51
|
+
urlPath: r == null ? void 0 : r.pathname,
|
|
52
|
+
host: (r == null ? void 0 : r.host) || (r == null ? void 0 : r.hostname),
|
|
53
|
+
device: n ? "tablet" : t.any() ? "mobile" : "desktop"
|
|
54
|
+
};
|
|
55
|
+
}, m = (e) => e != null;
|
|
56
|
+
function _e(e) {
|
|
57
|
+
const t = e || (c() ? window.location.search : void 0);
|
|
58
|
+
return t ? V(t).indexOf("builder.preview=") !== -1 : !1;
|
|
59
|
+
}
|
|
60
|
+
const Ge = (e) => ({
|
|
61
|
+
type: "builder.registerComponent",
|
|
62
|
+
data: U(e)
|
|
63
|
+
}), se = (e) => {
|
|
64
|
+
const t = e.toString().trim();
|
|
65
|
+
return `return (${!t.startsWith("function") && !t.startsWith("(") ? "function " : ""}${t}).apply(this, arguments)`;
|
|
66
|
+
};
|
|
67
|
+
function U(e) {
|
|
68
|
+
return JSON.parse(JSON.stringify(e, (t, n) => typeof n == "function" ? se(n) : n));
|
|
69
|
+
}
|
|
70
|
+
const x = {};
|
|
71
|
+
function ie(e, t) {
|
|
72
|
+
e === "plugin" && (t = U(t));
|
|
73
|
+
let n = x[e];
|
|
74
|
+
if (n || (n = x[e] = []), n.push(t), c()) {
|
|
75
|
+
const r = {
|
|
76
|
+
type: "builder.register",
|
|
77
|
+
data: {
|
|
78
|
+
type: e,
|
|
79
|
+
info: t
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
try {
|
|
83
|
+
parent.postMessage(r, "*"), parent !== window && window.postMessage(r, "*");
|
|
84
|
+
} catch (o) {
|
|
85
|
+
console.debug("Could not postmessage", o);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const A = {};
|
|
90
|
+
function Xe(e) {
|
|
91
|
+
if (c()) {
|
|
92
|
+
Object.assign(A, e);
|
|
93
|
+
const t = {
|
|
94
|
+
type: "builder.settingsChange",
|
|
95
|
+
data: A
|
|
96
|
+
};
|
|
97
|
+
parent.postMessage(t, "*");
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const T = "builder.", ae = "options.", M = (e) => {
|
|
101
|
+
if (!e)
|
|
102
|
+
return {};
|
|
103
|
+
const t = L(e), n = {};
|
|
104
|
+
return Object.keys(t).forEach((r) => {
|
|
105
|
+
if (r.startsWith(T)) {
|
|
106
|
+
const o = r.replace(T, "").replace(ae, "");
|
|
107
|
+
n[o] = t[r];
|
|
108
|
+
}
|
|
109
|
+
}), n;
|
|
110
|
+
}, ce = () => {
|
|
111
|
+
if (!c())
|
|
112
|
+
return {};
|
|
113
|
+
const e = new URLSearchParams(window.location.search);
|
|
114
|
+
return M(e);
|
|
115
|
+
}, N = "2.0.25", F = () => ({
|
|
116
|
+
"X-Builder-SDK": b,
|
|
117
|
+
"X-Builder-SDK-GEN": "2",
|
|
118
|
+
"X-Builder-SDK-Version": N
|
|
119
|
+
}), ue = (e) => {
|
|
120
|
+
if (e === "localhost" || e === "127.0.0.1")
|
|
121
|
+
return e;
|
|
122
|
+
const t = e.split(".");
|
|
123
|
+
return t.length > 2 ? t.slice(1).join(".") : e;
|
|
124
|
+
}, D = ({
|
|
125
|
+
name: e,
|
|
126
|
+
canTrack: t
|
|
127
|
+
}) => {
|
|
128
|
+
var n;
|
|
129
|
+
try {
|
|
130
|
+
return t ? (n = document.cookie.split("; ").find((r) => r.startsWith(`${e}=`))) == null ? void 0 : n.split("=")[1] : void 0;
|
|
131
|
+
} catch (r) {
|
|
132
|
+
f.warn("[COOKIE] GET error: ", (r == null ? void 0 : r.message) || r);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
}, K = async (e) => D(e), de = (e) => e.map(([t, n]) => n ? `${t}=${n}` : t).filter(m).join("; "), le = [["secure", ""], ["SameSite", "None"]], fe = ({
|
|
136
|
+
name: e,
|
|
137
|
+
value: t,
|
|
138
|
+
expires: n
|
|
139
|
+
}) => {
|
|
140
|
+
const o = (c() ? location.protocol === "https:" : !0) ? le : [[]], s = n ? [["expires", n.toUTCString()]] : [[]], i = [[e, t], ...s, ["path", "/"], ["domain", ue(window.location.hostname)], ...o];
|
|
141
|
+
return de(i);
|
|
142
|
+
}, j = async ({
|
|
143
|
+
name: e,
|
|
144
|
+
value: t,
|
|
145
|
+
expires: n,
|
|
146
|
+
canTrack: r
|
|
147
|
+
}) => {
|
|
148
|
+
try {
|
|
149
|
+
if (!r)
|
|
150
|
+
return;
|
|
151
|
+
const o = fe({
|
|
152
|
+
name: e,
|
|
153
|
+
value: t,
|
|
154
|
+
expires: n
|
|
155
|
+
});
|
|
156
|
+
document.cookie = o;
|
|
157
|
+
} catch (o) {
|
|
158
|
+
f.warn("[COOKIE] SET error: ", (o == null ? void 0 : o.message) || o);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
function he() {
|
|
162
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(e) {
|
|
163
|
+
const t = Math.random() * 16 | 0;
|
|
164
|
+
return (e == "x" ? t : t & 3 | 8).toString(16);
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
function W() {
|
|
168
|
+
return he().replace(/-/g, "");
|
|
169
|
+
}
|
|
170
|
+
const $ = "builderSessionId", ge = async ({
|
|
171
|
+
canTrack: e
|
|
172
|
+
}) => {
|
|
173
|
+
if (!e)
|
|
174
|
+
return;
|
|
175
|
+
const t = await K({
|
|
176
|
+
name: $,
|
|
177
|
+
canTrack: e
|
|
178
|
+
});
|
|
179
|
+
if (m(t))
|
|
180
|
+
return t;
|
|
181
|
+
{
|
|
182
|
+
const n = pe();
|
|
183
|
+
return me({
|
|
184
|
+
id: n,
|
|
185
|
+
canTrack: e
|
|
186
|
+
}), n;
|
|
187
|
+
}
|
|
188
|
+
}, pe = () => W(), me = ({
|
|
189
|
+
id: e,
|
|
190
|
+
canTrack: t
|
|
191
|
+
}) => j({
|
|
192
|
+
name: $,
|
|
193
|
+
value: e,
|
|
194
|
+
canTrack: t
|
|
195
|
+
}), _ = () => c() && typeof localStorage != "undefined" ? localStorage : void 0, ye = ({
|
|
196
|
+
key: e,
|
|
197
|
+
canTrack: t
|
|
198
|
+
}) => {
|
|
199
|
+
var n;
|
|
200
|
+
try {
|
|
201
|
+
return t ? (n = _()) == null ? void 0 : n.getItem(e) : void 0;
|
|
202
|
+
} catch (r) {
|
|
203
|
+
console.debug("[LocalStorage] GET error: ", r);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
}, Se = ({
|
|
207
|
+
key: e,
|
|
208
|
+
canTrack: t,
|
|
209
|
+
value: n
|
|
210
|
+
}) => {
|
|
211
|
+
var r;
|
|
212
|
+
try {
|
|
213
|
+
t && ((r = _()) == null || r.setItem(e, n));
|
|
214
|
+
} catch (o) {
|
|
215
|
+
console.debug("[LocalStorage] SET error: ", o);
|
|
216
|
+
}
|
|
217
|
+
}, G = "builderVisitorId", we = ({
|
|
218
|
+
canTrack: e
|
|
219
|
+
}) => {
|
|
220
|
+
if (!e)
|
|
221
|
+
return;
|
|
222
|
+
const t = ye({
|
|
223
|
+
key: G,
|
|
224
|
+
canTrack: e
|
|
225
|
+
});
|
|
226
|
+
if (m(t))
|
|
227
|
+
return t;
|
|
228
|
+
{
|
|
229
|
+
const n = be();
|
|
230
|
+
return ve({
|
|
231
|
+
id: n,
|
|
232
|
+
canTrack: e
|
|
233
|
+
}), n;
|
|
234
|
+
}
|
|
235
|
+
}, be = () => W(), ve = ({
|
|
236
|
+
id: e,
|
|
237
|
+
canTrack: t
|
|
238
|
+
}) => Se({
|
|
239
|
+
key: G,
|
|
240
|
+
value: e,
|
|
241
|
+
canTrack: t
|
|
242
|
+
}), Ie = async ({
|
|
243
|
+
canTrack: e
|
|
244
|
+
}) => {
|
|
245
|
+
if (!e)
|
|
246
|
+
return {
|
|
247
|
+
visitorId: void 0,
|
|
248
|
+
sessionId: void 0
|
|
249
|
+
};
|
|
250
|
+
const t = await ge({
|
|
251
|
+
canTrack: e
|
|
252
|
+
}), n = we({
|
|
253
|
+
canTrack: e
|
|
254
|
+
});
|
|
255
|
+
return {
|
|
256
|
+
sessionId: t,
|
|
257
|
+
visitorId: n
|
|
258
|
+
};
|
|
259
|
+
}, ke = async ({
|
|
260
|
+
type: e,
|
|
261
|
+
canTrack: t,
|
|
262
|
+
apiKey: n,
|
|
263
|
+
metadata: r,
|
|
264
|
+
...o
|
|
265
|
+
}) => ({
|
|
266
|
+
type: e,
|
|
267
|
+
data: {
|
|
268
|
+
...o,
|
|
269
|
+
metadata: {
|
|
270
|
+
url: location.href,
|
|
271
|
+
...r
|
|
272
|
+
},
|
|
273
|
+
...await Ie({
|
|
274
|
+
canTrack: t
|
|
275
|
+
}),
|
|
276
|
+
userAttributes: oe(),
|
|
277
|
+
ownerId: n
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
async function Ee(e) {
|
|
281
|
+
if (!e.apiKey) {
|
|
282
|
+
f.error("Missing API key for track call. Please provide your API key.");
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
if (e.canTrack && !te() && (c() || b === "reactNative"))
|
|
286
|
+
return fetch("https://cdn.builder.io/api/v1/track", {
|
|
287
|
+
method: "POST",
|
|
288
|
+
body: JSON.stringify({
|
|
289
|
+
events: [await ke(e)]
|
|
290
|
+
}),
|
|
291
|
+
headers: {
|
|
292
|
+
"content-type": "application/json",
|
|
293
|
+
...F()
|
|
294
|
+
},
|
|
295
|
+
mode: "cors"
|
|
296
|
+
}).catch((t) => {
|
|
297
|
+
console.error("Failed to track: ", t);
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
const He = (e) => Ee({
|
|
301
|
+
...e,
|
|
302
|
+
canTrack: !0
|
|
303
|
+
}), Oe = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
|
|
304
|
+
function X(e, t) {
|
|
305
|
+
if (!t.origin.startsWith("http") && !t.origin.startsWith("https"))
|
|
306
|
+
return !1;
|
|
307
|
+
const n = new URL(t.origin), r = n.hostname;
|
|
308
|
+
return (e || Oe).findIndex((o) => o.startsWith("*.") ? r.endsWith(o.slice(1)) : o === r) > -1;
|
|
309
|
+
}
|
|
310
|
+
const Je = () => {
|
|
311
|
+
ie("insertMenu", {
|
|
312
|
+
name: "_default",
|
|
313
|
+
default: !0,
|
|
314
|
+
items: [{
|
|
315
|
+
name: "Box"
|
|
316
|
+
}, {
|
|
317
|
+
name: "Text"
|
|
318
|
+
}, {
|
|
319
|
+
name: "Image"
|
|
320
|
+
}, {
|
|
321
|
+
name: "Columns"
|
|
322
|
+
}, {
|
|
323
|
+
name: "Core:Section"
|
|
324
|
+
}, {
|
|
325
|
+
name: "Core:Button"
|
|
326
|
+
}, {
|
|
327
|
+
name: "Embed"
|
|
328
|
+
}, {
|
|
329
|
+
name: "Custom Code"
|
|
330
|
+
}]
|
|
331
|
+
});
|
|
332
|
+
};
|
|
333
|
+
let R = !1;
|
|
334
|
+
const Pe = (e = {}) => {
|
|
335
|
+
var t, n;
|
|
336
|
+
R || (R = !0, c() && ((t = window.parent) == null || t.postMessage({
|
|
337
|
+
type: "builder.sdkInfo",
|
|
338
|
+
data: {
|
|
339
|
+
target: b,
|
|
340
|
+
version: N,
|
|
341
|
+
supportsPatchUpdates: !1,
|
|
342
|
+
// Supports builder-model="..." attribute which is needed to
|
|
343
|
+
// scope our '+ add block' button styling
|
|
344
|
+
supportsAddBlockScoping: !0,
|
|
345
|
+
supportsCustomBreakpoints: !0
|
|
346
|
+
}
|
|
347
|
+
}, "*"), (n = window.parent) == null || n.postMessage({
|
|
348
|
+
type: "builder.updateContent",
|
|
349
|
+
data: {
|
|
350
|
+
options: e
|
|
351
|
+
}
|
|
352
|
+
}, "*"), window.addEventListener("message", (r) => {
|
|
353
|
+
var s, i;
|
|
354
|
+
if (!X(e.trustedHosts, r))
|
|
355
|
+
return;
|
|
356
|
+
const {
|
|
357
|
+
data: o
|
|
358
|
+
} = r;
|
|
359
|
+
if (o != null && o.type)
|
|
360
|
+
switch (o.type) {
|
|
361
|
+
case "builder.evaluate": {
|
|
362
|
+
const u = o.data.text, y = o.data.arguments || [], p = o.data.id, I = new Function(u);
|
|
363
|
+
let d, h = null;
|
|
364
|
+
try {
|
|
365
|
+
d = I.apply(null, y);
|
|
366
|
+
} catch (g) {
|
|
367
|
+
h = g;
|
|
368
|
+
}
|
|
369
|
+
h ? (s = window.parent) == null || s.postMessage({
|
|
370
|
+
type: "builder.evaluateError",
|
|
371
|
+
data: {
|
|
372
|
+
id: p,
|
|
373
|
+
error: h.message
|
|
374
|
+
}
|
|
375
|
+
}, "*") : d && typeof d.then == "function" ? d.then((g) => {
|
|
376
|
+
var S;
|
|
377
|
+
(S = window.parent) == null || S.postMessage({
|
|
378
|
+
type: "builder.evaluateResult",
|
|
379
|
+
data: {
|
|
380
|
+
id: p,
|
|
381
|
+
result: g
|
|
382
|
+
}
|
|
383
|
+
}, "*");
|
|
384
|
+
}).catch(console.error) : (i = window.parent) == null || i.postMessage({
|
|
385
|
+
type: "builder.evaluateResult",
|
|
386
|
+
data: {
|
|
387
|
+
result: d,
|
|
388
|
+
id: p
|
|
389
|
+
}
|
|
390
|
+
}, "*");
|
|
391
|
+
break;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
})));
|
|
395
|
+
}, Ce = ({
|
|
396
|
+
model: e,
|
|
397
|
+
trustedHosts: t,
|
|
398
|
+
callbacks: n
|
|
399
|
+
}) => (r) => {
|
|
400
|
+
if (!X(t, r))
|
|
401
|
+
return;
|
|
402
|
+
const {
|
|
403
|
+
data: o
|
|
404
|
+
} = r;
|
|
405
|
+
if (o)
|
|
406
|
+
switch (o.type) {
|
|
407
|
+
case "builder.configureSdk": {
|
|
408
|
+
n.configureSdk(o.data);
|
|
409
|
+
break;
|
|
410
|
+
}
|
|
411
|
+
case "builder.triggerAnimation": {
|
|
412
|
+
n.animation(o.data);
|
|
413
|
+
break;
|
|
414
|
+
}
|
|
415
|
+
case "builder.contentUpdate": {
|
|
416
|
+
const s = o.data, i = s.key || s.alias || s.entry || s.modelName, u = s.data;
|
|
417
|
+
i === e && n.contentUpdate(u);
|
|
418
|
+
break;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}, ze = (e, t, n) => {
|
|
422
|
+
if (!c)
|
|
423
|
+
return f.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server."), () => {
|
|
424
|
+
};
|
|
425
|
+
Pe();
|
|
426
|
+
const r = Ce({
|
|
427
|
+
callbacks: {
|
|
428
|
+
contentUpdate: t,
|
|
429
|
+
animation: () => {
|
|
430
|
+
},
|
|
431
|
+
configureSdk: () => {
|
|
432
|
+
}
|
|
433
|
+
},
|
|
434
|
+
model: e,
|
|
435
|
+
trustedHosts: n == null ? void 0 : n.trustedHosts
|
|
436
|
+
});
|
|
437
|
+
return window.addEventListener("message", r), () => {
|
|
438
|
+
window.removeEventListener("message", r);
|
|
439
|
+
};
|
|
440
|
+
}, xe = "builder.tests", E = (e) => `${xe}.${e}`, Ae = ({
|
|
441
|
+
contentId: e
|
|
442
|
+
}) => K({
|
|
443
|
+
name: E(e),
|
|
444
|
+
canTrack: !0
|
|
445
|
+
}), Te = ({
|
|
446
|
+
contentId: e
|
|
447
|
+
}) => D({
|
|
448
|
+
name: E(e),
|
|
449
|
+
canTrack: !0
|
|
450
|
+
}), Re = ({
|
|
451
|
+
contentId: e,
|
|
452
|
+
value: t
|
|
453
|
+
}) => j({
|
|
454
|
+
name: E(e),
|
|
455
|
+
value: t,
|
|
456
|
+
canTrack: !0
|
|
457
|
+
}), H = (e) => m(e.id) && m(e.variations) && Object.keys(e.variations).length > 0, Be = ({
|
|
458
|
+
id: e,
|
|
459
|
+
variations: t
|
|
460
|
+
}) => {
|
|
461
|
+
var o;
|
|
462
|
+
let n = 0;
|
|
463
|
+
const r = Math.random();
|
|
464
|
+
for (const s in t) {
|
|
465
|
+
const i = (o = t[s]) == null ? void 0 : o.testRatio;
|
|
466
|
+
if (n += i, r < n)
|
|
467
|
+
return s;
|
|
468
|
+
}
|
|
469
|
+
return e;
|
|
470
|
+
}, J = (e) => {
|
|
471
|
+
const t = Be(e);
|
|
472
|
+
return Re({
|
|
473
|
+
contentId: e.id,
|
|
474
|
+
value: t
|
|
475
|
+
}).catch((n) => {
|
|
476
|
+
f.error("could not store A/B test variation: ", n);
|
|
477
|
+
}), t;
|
|
478
|
+
}, z = ({
|
|
479
|
+
item: e,
|
|
480
|
+
testGroupId: t
|
|
481
|
+
}) => {
|
|
482
|
+
const n = e.variations[t];
|
|
483
|
+
return t === e.id || // handle edge-case where `testGroupId` points to non-existing variation
|
|
484
|
+
!n ? {
|
|
485
|
+
testVariationId: e.id,
|
|
486
|
+
testVariationName: "Default"
|
|
487
|
+
} : {
|
|
488
|
+
data: n.data,
|
|
489
|
+
testVariationId: n.id,
|
|
490
|
+
testVariationName: n.name || (n.id === e.id ? "Default" : "")
|
|
491
|
+
};
|
|
492
|
+
}, qe = ({
|
|
493
|
+
item: e,
|
|
494
|
+
canTrack: t
|
|
495
|
+
}) => {
|
|
496
|
+
if (!t)
|
|
497
|
+
return e;
|
|
498
|
+
if (!e)
|
|
499
|
+
return;
|
|
500
|
+
if (!H(e))
|
|
501
|
+
return e;
|
|
502
|
+
const n = Te({
|
|
503
|
+
contentId: e.id
|
|
504
|
+
}) || J({
|
|
505
|
+
variations: e.variations,
|
|
506
|
+
id: e.id
|
|
507
|
+
}), r = z({
|
|
508
|
+
item: e,
|
|
509
|
+
testGroupId: n
|
|
510
|
+
});
|
|
511
|
+
return {
|
|
512
|
+
...e,
|
|
513
|
+
...r
|
|
514
|
+
};
|
|
515
|
+
}, Le = async ({
|
|
516
|
+
item: e,
|
|
517
|
+
canTrack: t
|
|
518
|
+
}) => {
|
|
519
|
+
if (!t || !H(e))
|
|
520
|
+
return e;
|
|
521
|
+
const r = await Ae({
|
|
522
|
+
contentId: e.id
|
|
523
|
+
}) || J({
|
|
524
|
+
variations: e.variations,
|
|
525
|
+
id: e.id
|
|
526
|
+
}), o = z({
|
|
527
|
+
item: e,
|
|
528
|
+
testGroupId: r
|
|
529
|
+
});
|
|
530
|
+
return {
|
|
531
|
+
...e,
|
|
532
|
+
...o
|
|
533
|
+
};
|
|
534
|
+
}, Ve = (e) => m(e) ? e : !0;
|
|
535
|
+
function Ue() {
|
|
536
|
+
return typeof globalThis != "undefined" ? globalThis : typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : globalThis;
|
|
537
|
+
}
|
|
538
|
+
function Me() {
|
|
539
|
+
const e = Ue().fetch;
|
|
540
|
+
if (typeof e == "undefined")
|
|
541
|
+
throw console.warn(`Builder SDK could not find a global fetch function. Make sure you have a polyfill for fetch in your project.
|
|
542
|
+
For more information, read https://github.com/BuilderIO/this-package-uses-fetch`), new Error("Builder SDK could not find a global `fetch` function");
|
|
543
|
+
return e;
|
|
544
|
+
}
|
|
545
|
+
const Ne = Me();
|
|
546
|
+
function k(e, t = null, n = ".") {
|
|
547
|
+
return Object.keys(e).reduce((r, o) => {
|
|
548
|
+
const s = e[o], i = [t, o].filter(Boolean).join(n);
|
|
549
|
+
return [typeof s == "object", s !== null, !(Array.isArray(s) && s.length === 0)].every(Boolean) ? {
|
|
550
|
+
...r,
|
|
551
|
+
...k(s, i, n)
|
|
552
|
+
} : {
|
|
553
|
+
...r,
|
|
554
|
+
[i]: s
|
|
555
|
+
};
|
|
556
|
+
}, {});
|
|
557
|
+
}
|
|
558
|
+
function q(e, t, n = {}) {
|
|
559
|
+
for (const r in e) {
|
|
560
|
+
const o = e[r], s = t ? t + "." + r : r;
|
|
561
|
+
o && typeof o == "object" && !Array.isArray(o) && !Object.keys(o).find((i) => i.startsWith("$")) ? q(o, s, n) : n[s] = o;
|
|
562
|
+
}
|
|
563
|
+
return n;
|
|
564
|
+
}
|
|
565
|
+
const Fe = "v3", B = (e) => typeof e == "number" && !isNaN(e) && e >= 0, O = (e) => {
|
|
566
|
+
const {
|
|
567
|
+
limit: t = 30,
|
|
568
|
+
userAttributes: n,
|
|
569
|
+
query: r,
|
|
570
|
+
model: o,
|
|
571
|
+
apiKey: s,
|
|
572
|
+
enrich: i,
|
|
573
|
+
locale: u,
|
|
574
|
+
apiVersion: y = Fe,
|
|
575
|
+
fields: p,
|
|
576
|
+
omit: I,
|
|
577
|
+
offset: d,
|
|
578
|
+
cacheSeconds: h,
|
|
579
|
+
staleCacheSeconds: g,
|
|
580
|
+
sort: S,
|
|
581
|
+
includeUnpublished: P
|
|
582
|
+
} = e;
|
|
583
|
+
if (!s)
|
|
584
|
+
throw new Error("Missing API key");
|
|
585
|
+
if (!["v3"].includes(y))
|
|
586
|
+
throw new Error(`Invalid apiVersion: expected 'v3', received '${y}'`);
|
|
587
|
+
const Q = t !== 1, a = new URL(`https://cdn.builder.io/api/${y}/content/${o}`);
|
|
588
|
+
if (a.searchParams.set("apiKey", s), a.searchParams.set("limit", String(t)), a.searchParams.set("noTraverse", String(Q)), a.searchParams.set("includeRefs", String(!0)), u && a.searchParams.set("locale", u), i && a.searchParams.set("enrich", String(i)), a.searchParams.set("omit", I || "meta.componentsUsed"), p && a.searchParams.set("fields", p), Number.isFinite(d) && d > -1 && a.searchParams.set("offset", String(Math.floor(d))), typeof P == "boolean" && a.searchParams.set("includeUnpublished", String(P)), h && B(h) && a.searchParams.set("cacheSeconds", String(h)), g && B(g) && a.searchParams.set("staleCacheSeconds", String(g)), S) {
|
|
589
|
+
const l = k({
|
|
590
|
+
sort: S
|
|
591
|
+
});
|
|
592
|
+
for (const w in l)
|
|
593
|
+
a.searchParams.set(w, JSON.stringify(l[w]));
|
|
594
|
+
}
|
|
595
|
+
const Y = {
|
|
596
|
+
...ce(),
|
|
597
|
+
...L(e.options || {})
|
|
598
|
+
}, C = k(Y);
|
|
599
|
+
for (const l in C)
|
|
600
|
+
a.searchParams.set(l, String(C[l]));
|
|
601
|
+
if (n && a.searchParams.set("userAttributes", JSON.stringify(n)), r) {
|
|
602
|
+
const l = q({
|
|
603
|
+
query: r
|
|
604
|
+
});
|
|
605
|
+
for (const w in l)
|
|
606
|
+
a.searchParams.set(w, JSON.stringify(l[w]));
|
|
607
|
+
}
|
|
608
|
+
return a;
|
|
609
|
+
}, De = (e) => "results" in e;
|
|
610
|
+
async function Ke(e) {
|
|
611
|
+
const t = await $e({
|
|
612
|
+
...e,
|
|
613
|
+
limit: 1
|
|
614
|
+
});
|
|
615
|
+
return t && t[0] || null;
|
|
616
|
+
}
|
|
617
|
+
const je = async (e) => {
|
|
618
|
+
var i, u;
|
|
619
|
+
const t = O(e), n = (i = e.fetch) != null ? i : Ne, r = {
|
|
620
|
+
...e.fetchOptions,
|
|
621
|
+
headers: {
|
|
622
|
+
...(u = e.fetchOptions) == null ? void 0 : u.headers,
|
|
623
|
+
...F()
|
|
624
|
+
}
|
|
625
|
+
};
|
|
626
|
+
return await (await n(t.href, r)).json();
|
|
627
|
+
}, We = async (e, t, n = O(e)) => {
|
|
628
|
+
const r = Ve(e.canTrack);
|
|
629
|
+
if (n.search.includes("preview="), !r || !(c() || b === "reactNative"))
|
|
630
|
+
return t.results;
|
|
631
|
+
try {
|
|
632
|
+
const o = [];
|
|
633
|
+
for (const s of t.results)
|
|
634
|
+
o.push(await Le({
|
|
635
|
+
item: s,
|
|
636
|
+
canTrack: r
|
|
637
|
+
}));
|
|
638
|
+
t.results = o;
|
|
639
|
+
} catch (o) {
|
|
640
|
+
f.error("Could not process A/B tests. ", o);
|
|
641
|
+
}
|
|
642
|
+
return t.results;
|
|
643
|
+
};
|
|
644
|
+
async function $e(e) {
|
|
645
|
+
try {
|
|
646
|
+
const t = O(e), n = await je(e);
|
|
647
|
+
return De(n) ? We(e, n) : (f.error("Error fetching data. ", {
|
|
648
|
+
url: t,
|
|
649
|
+
content: n,
|
|
650
|
+
options: e
|
|
651
|
+
}), null);
|
|
652
|
+
} catch (t) {
|
|
653
|
+
return f.error("Error fetching data. ", t), null;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
const Qe = async (e) => {
|
|
657
|
+
var r, o, s;
|
|
658
|
+
const t = e.path || ((r = e.url) == null ? void 0 : r.pathname) || ((o = e.userAttributes) == null ? void 0 : o.urlPath), n = {
|
|
659
|
+
...e,
|
|
660
|
+
apiKey: e.apiKey,
|
|
661
|
+
model: e.model || "page",
|
|
662
|
+
userAttributes: {
|
|
663
|
+
...e.userAttributes,
|
|
664
|
+
...t ? {
|
|
665
|
+
urlPath: t
|
|
666
|
+
} : {}
|
|
667
|
+
},
|
|
668
|
+
options: M(e.searchParams || ((s = e.url) == null ? void 0 : s.searchParams) || e.options)
|
|
669
|
+
};
|
|
670
|
+
return {
|
|
671
|
+
apiKey: n.apiKey,
|
|
672
|
+
model: n.model,
|
|
673
|
+
content: await Ke(n)
|
|
674
|
+
};
|
|
675
|
+
};
|
|
676
|
+
export {
|
|
677
|
+
b as TARGET,
|
|
678
|
+
We as _processContentResult,
|
|
679
|
+
Ee as _track,
|
|
680
|
+
m as checkIsDefined,
|
|
681
|
+
Ce as createEditorListener,
|
|
682
|
+
Ge as createRegisterComponentMessage,
|
|
683
|
+
Qe as fetchBuilderProps,
|
|
684
|
+
$e as fetchEntries,
|
|
685
|
+
Ke as fetchOneEntry,
|
|
686
|
+
M as getBuilderSearchParams,
|
|
687
|
+
Ve as getDefaultCanTrack,
|
|
688
|
+
oe as getUserAttributes,
|
|
689
|
+
qe as handleABTestingSync,
|
|
690
|
+
c as isBrowser,
|
|
691
|
+
te as isEditing,
|
|
692
|
+
_e as isPreviewing,
|
|
693
|
+
f as logger,
|
|
694
|
+
ie as register,
|
|
695
|
+
Je as registerInsertMenu,
|
|
696
|
+
U as serializeIncludingFunctions,
|
|
697
|
+
Xe as setEditorSettings,
|
|
698
|
+
Pe as setupBrowserForEditing,
|
|
699
|
+
ze as subscribeToEditor,
|
|
700
|
+
He as track
|
|
701
|
+
};
|