@builder.io/sdk-react 2.0.8 → 2.0.12

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.
Files changed (73) hide show
  1. package/lib/browser/blocks-exports.cjs +28 -28
  2. package/lib/browser/blocks-exports.mjs +991 -966
  3. package/lib/browser/index.cjs +1 -1
  4. package/lib/browser/index.mjs +1 -1
  5. package/lib/browser/init.cjs +3 -3
  6. package/lib/browser/init.mjs +3 -3
  7. package/lib/browser/server-entry-acf08871.cjs +2 -0
  8. package/lib/{node/server-entry-f6ee5d92.js → browser/server-entry-dc66de59.js} +346 -342
  9. package/lib/browser/server-entry.cjs +1 -1
  10. package/lib/browser/server-entry.mjs +1 -1
  11. package/lib/edge/{accordion-ef5e6161.js → accordion-37ff8319.js} +1 -1
  12. package/lib/edge/{accordion-88007399.cjs → accordion-b3b8c262.cjs} +1 -1
  13. package/lib/edge/blocks-793430a0.cjs +12 -0
  14. package/lib/edge/blocks-e0e60319.js +833 -0
  15. package/lib/edge/blocks-exports.cjs +1 -1
  16. package/lib/edge/blocks-exports.mjs +2 -2
  17. package/lib/edge/{button-8d307faf.js → button-15992755.js} +2 -2
  18. package/lib/edge/{button-228f448d.cjs → button-875ac10b.cjs} +1 -1
  19. package/lib/edge/{columns-3547be8c.cjs → columns-11ead988.cjs} +1 -1
  20. package/lib/edge/{columns-77b7011a.js → columns-cfe663b2.js} +4 -4
  21. package/lib/edge/{content-variants-4f7cad1a.js → content-variants-e780597b.js} +11 -11
  22. package/lib/edge/{content-variants-f0edf280.cjs → content-variants-f8ef104d.cjs} +4 -4
  23. package/lib/edge/{evaluate-384a03ed.js → evaluate-6408d64d.js} +87 -87
  24. package/lib/edge/{evaluate-39c2c786.cjs → evaluate-938a955e.cjs} +6 -6
  25. package/lib/edge/{form-c6da17f5.cjs → form-75a774bc.cjs} +1 -1
  26. package/lib/edge/{form-d40e9eca.js → form-7735178f.js} +4 -4
  27. package/lib/edge/{get-class-prop-name-767dbeb0.js → get-class-prop-name-d005a2bb.js} +1 -1
  28. package/lib/edge/{get-class-prop-name-4f8743e9.cjs → get-class-prop-name-e596650d.cjs} +1 -1
  29. package/lib/edge/{img-d650b796.js → img-045bb860.js} +1 -1
  30. package/lib/edge/{img-c50b3839.cjs → img-dd79e34b.cjs} +1 -1
  31. package/lib/edge/index.cjs +1 -1
  32. package/lib/edge/index.mjs +1 -1
  33. package/lib/edge/init.cjs +3 -3
  34. package/lib/edge/init.mjs +3 -3
  35. package/lib/edge/{input-aaba7df0.cjs → input-3bd0ac03.cjs} +1 -1
  36. package/lib/edge/{input-5646dcb2.js → input-adf80016.js} +1 -1
  37. package/lib/edge/{select-2e7bf7d0.cjs → select-882193d4.cjs} +1 -1
  38. package/lib/edge/{select-d3905dcd.js → select-90b076db.js} +1 -1
  39. package/lib/edge/{server-entry-29a170e3.js → server-entry-84c3cdd6.js} +59 -58
  40. package/lib/edge/server-entry-d5ae6221.cjs +2 -0
  41. package/lib/edge/server-entry.cjs +1 -1
  42. package/lib/edge/server-entry.mjs +1 -1
  43. package/lib/edge/{slot-82c0b340.js → slot-293114eb.js} +4 -4
  44. package/lib/edge/{slot-695259cf.cjs → slot-42b9b358.cjs} +1 -1
  45. package/lib/edge/{symbol-5a6a783f.cjs → symbol-3e0799b8.cjs} +1 -1
  46. package/lib/edge/{symbol-91897bd4.js → symbol-aed9cd2b.js} +2 -2
  47. package/lib/edge/{tabs-a191e7b1.js → tabs-0cf37bf4.js} +4 -4
  48. package/lib/edge/{tabs-4c4a6b19.cjs → tabs-f5c4f350.cjs} +1 -1
  49. package/lib/edge/{text-ca974245.js → text-9e2166c7.js} +2 -2
  50. package/lib/edge/{text-7a00e2f8.cjs → text-abb84188.cjs} +1 -1
  51. package/lib/node/blocks-exports.cjs +29 -29
  52. package/lib/node/blocks-exports.mjs +983 -958
  53. package/lib/node/index.cjs +1 -1
  54. package/lib/node/index.mjs +2 -2
  55. package/lib/node/init.cjs +1 -1
  56. package/lib/node/init.mjs +2 -2
  57. package/lib/node/{node-runtime-a6fb6ac7.cjs → node-runtime-11912803.cjs} +4 -4
  58. package/lib/node/{node-runtime-d8e6d827.js → node-runtime-49e4c6cb.js} +3 -3
  59. package/lib/node/server-entry-acf08871.cjs +2 -0
  60. package/lib/{browser/server-entry-f6ee5d92.js → node/server-entry-dc66de59.js} +346 -342
  61. package/lib/node/server-entry.cjs +1 -1
  62. package/lib/node/server-entry.mjs +1 -1
  63. package/package.json +3 -3
  64. package/types/components/block/block.helpers.d.ts +1 -2
  65. package/types/constants/sdk-version.d.ts +1 -1
  66. package/types/functions/evaluate/node-runtime/init.d.ts +1 -0
  67. package/types/functions/get-processed-block.d.ts +1 -0
  68. package/types/functions/register-component.d.ts +1 -1
  69. package/lib/browser/server-entry-ba3e0524.cjs +0 -2
  70. package/lib/edge/blocks-90fd2fd8.js +0 -808
  71. package/lib/edge/blocks-dc478c97.cjs +0 -12
  72. package/lib/edge/server-entry-b0e7430b.cjs +0 -2
  73. package/lib/node/server-entry-ba3e0524.cjs +0 -2
@@ -7,27 +7,27 @@ const v = "react", b = "[Builder.io]: ", f = {
7
7
  function c() {
8
8
  return typeof window != "undefined" && typeof document != "undefined";
9
9
  }
10
- const q = (t) => {
10
+ const Q = (t) => {
11
11
  const e = {};
12
12
  return t.forEach((n, r) => {
13
13
  e[r] = n;
14
14
  }), e;
15
- }, L = (t) => t instanceof URLSearchParams ? q(t) : t, V = (t) => typeof t == "string" ? t : t instanceof URLSearchParams ? t.toString() : new URLSearchParams(t).toString();
16
- function Q() {
15
+ }, L = (t) => t instanceof URLSearchParams ? Q(t) : t, V = (t) => typeof t == "string" ? t : t instanceof URLSearchParams ? t.toString() : new URLSearchParams(t).toString();
16
+ function Y() {
17
17
  return c() && window.self !== window.top;
18
18
  }
19
- function Y(t) {
20
- return Q() && // accessing window.location.search is safe here because `isIframe()` is only `true` if we're in a browser.
19
+ function Z(t) {
20
+ return Y() && // accessing window.location.search is safe here because `isIframe()` is only `true` if we're in a browser.
21
21
  V(t || window.location.search).indexOf("builder.frameEditing=") !== -1;
22
22
  }
23
- const Z = () => {
23
+ const tt = () => {
24
24
  if (c()) {
25
25
  const t = new URL(location.href);
26
26
  return t.pathname === "" && (t.pathname = "/"), t;
27
27
  } else
28
28
  return console.warn("Cannot get location for tracking in non-browser environment"), null;
29
- }, tt = () => typeof navigator == "object" && navigator.userAgent || "", et = () => {
30
- const t = tt(), e = {
29
+ }, et = () => typeof navigator == "object" && navigator.userAgent || "", nt = () => {
30
+ const t = et(), e = {
31
31
  Android() {
32
32
  return t.match(/Android/i);
33
33
  },
@@ -46,18 +46,78 @@ const Z = () => {
46
46
  any() {
47
47
  return e.Android() || e.BlackBerry() || e.iOS() || e.Opera() || e.Windows() || v === "reactNative";
48
48
  }
49
- }, n = t.match(/Tablet|iPad/i), r = Z();
49
+ }, n = t.match(/Tablet|iPad/i), r = tt();
50
50
  return {
51
51
  urlPath: r == null ? void 0 : r.pathname,
52
52
  host: (r == null ? void 0 : r.host) || (r == null ? void 0 : r.hostname),
53
53
  device: n ? "tablet" : e.any() ? "mobile" : "desktop"
54
54
  };
55
- }, m = (t) => t != null, nt = (t) => {
55
+ }, m = (t) => t != null;
56
+ function _t(t) {
57
+ const e = t || (c() ? window.location.search : void 0);
58
+ return e ? V(e).indexOf("builder.preview=") !== -1 : !1;
59
+ }
60
+ const $t = (t) => ({
61
+ type: "builder.registerComponent",
62
+ data: U(t)
63
+ }), rt = (t) => {
64
+ const e = t.toString().trim();
65
+ return `return (${!e.startsWith("function") && !e.startsWith("(") ? "function " : ""}${e}).apply(this, arguments)`;
66
+ };
67
+ function U(t) {
68
+ return JSON.parse(JSON.stringify(t, (e, n) => typeof n == "function" ? rt(n) : n));
69
+ }
70
+ const x = {};
71
+ function ot(t, e) {
72
+ t === "plugin" && (e = U(e));
73
+ let n = x[t];
74
+ if (n || (n = x[t] = []), n.push(e), c()) {
75
+ const r = {
76
+ type: "builder.register",
77
+ data: {
78
+ type: t,
79
+ info: e
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 Gt(t) {
91
+ if (c()) {
92
+ Object.assign(A, t);
93
+ const e = {
94
+ type: "builder.settingsChange",
95
+ data: A
96
+ };
97
+ parent.postMessage(e, "*");
98
+ }
99
+ }
100
+ const T = "builder.", st = "options.", M = (t) => {
101
+ if (!t)
102
+ return {};
103
+ const e = L(t), n = {};
104
+ return Object.keys(e).forEach((r) => {
105
+ if (r.startsWith(T)) {
106
+ const o = r.replace(T, "").replace(st, "");
107
+ n[o] = e[r];
108
+ }
109
+ }), n;
110
+ }, it = () => {
111
+ if (!c())
112
+ return {};
113
+ const t = new URLSearchParams(window.location.search);
114
+ return M(t);
115
+ }, at = (t) => {
56
116
  if (t === "localhost" || t === "127.0.0.1")
57
117
  return t;
58
118
  const e = t.split(".");
59
119
  return e.length > 2 ? e.slice(1).join(".") : t;
60
- }, U = ({
120
+ }, F = ({
61
121
  name: t,
62
122
  canTrack: e
63
123
  }) => {
@@ -68,14 +128,14 @@ const Z = () => {
68
128
  f.warn("[COOKIE] GET error: ", (r == null ? void 0 : r.message) || r);
69
129
  return;
70
130
  }
71
- }, M = async (t) => U(t), rt = (t) => t.map(([e, n]) => n ? `${e}=${n}` : e).filter(m).join("; "), ot = [["secure", ""], ["SameSite", "None"]], st = ({
131
+ }, N = async (t) => F(t), ct = (t) => t.map(([e, n]) => n ? `${e}=${n}` : e).filter(m).join("; "), ut = [["secure", ""], ["SameSite", "None"]], dt = ({
72
132
  name: t,
73
133
  value: e,
74
134
  expires: n
75
135
  }) => {
76
- const o = (c() ? location.protocol === "https:" : !0) ? ot : [[]], s = n ? [["expires", n.toUTCString()]] : [[]], a = [[t, e], ...s, ["path", "/"], ["domain", nt(window.location.hostname)], ...o];
77
- return rt(a);
78
- }, N = async ({
136
+ const o = (c() ? location.protocol === "https:" : !0) ? ut : [[]], s = n ? [["expires", n.toUTCString()]] : [[]], a = [[t, e], ...s, ["path", "/"], ["domain", at(window.location.hostname)], ...o];
137
+ return ct(a);
138
+ }, j = async ({
79
139
  name: t,
80
140
  value: e,
81
141
  expires: n,
@@ -84,7 +144,7 @@ const Z = () => {
84
144
  try {
85
145
  if (!r)
86
146
  return;
87
- const o = st({
147
+ const o = dt({
88
148
  name: t,
89
149
  value: e,
90
150
  expires: n
@@ -93,326 +153,89 @@ const Z = () => {
93
153
  } catch (o) {
94
154
  f.warn("[COOKIE] SET error: ", (o == null ? void 0 : o.message) || o);
95
155
  }
96
- }, it = "builder.tests", E = (t) => `${it}.${t}`, at = ({
97
- contentId: t
98
- }) => M({
99
- name: E(t),
100
- canTrack: !0
101
- }), ct = ({
102
- contentId: t
103
- }) => U({
104
- name: E(t),
105
- canTrack: !0
106
- }), ut = ({
107
- contentId: t,
108
- value: e
109
- }) => N({
110
- name: E(t),
111
- value: e,
112
- canTrack: !0
113
- }), F = (t) => m(t.id) && m(t.variations) && Object.keys(t.variations).length > 0, dt = ({
114
- id: t,
115
- variations: e
116
- }) => {
117
- var o;
118
- let n = 0;
119
- const r = Math.random();
120
- for (const s in e) {
121
- const a = (o = e[s]) == null ? void 0 : o.testRatio;
122
- if (n += a, r < n)
123
- return s;
124
- }
125
- return t;
126
- }, j = (t) => {
127
- const e = dt(t);
128
- return ut({
129
- contentId: t.id,
130
- value: e
131
- }).catch((n) => {
132
- f.error("could not store A/B test variation: ", n);
133
- }), e;
134
- }, D = ({
135
- item: t,
136
- testGroupId: e
137
- }) => {
138
- const n = t.variations[e];
139
- return e === t.id || // handle edge-case where `testGroupId` points to non-existing variation
140
- !n ? {
141
- testVariationId: t.id,
142
- testVariationName: "Default"
143
- } : {
144
- data: n.data,
145
- testVariationId: n.id,
146
- testVariationName: n.name || (n.id === t.id ? "Default" : "")
147
- };
148
- }, _t = ({
149
- item: t,
150
- canTrack: e
151
- }) => {
152
- if (!e)
153
- return t;
154
- if (!t)
155
- return;
156
- if (!F(t))
157
- return t;
158
- const n = ct({
159
- contentId: t.id
160
- }) || j({
161
- variations: t.variations,
162
- id: t.id
163
- }), r = D({
164
- item: t,
165
- testGroupId: n
166
- });
167
- return {
168
- ...t,
169
- ...r
170
- };
171
- }, lt = async ({
172
- item: t,
173
- canTrack: e
174
- }) => {
175
- if (!e || !F(t))
176
- return t;
177
- const r = await at({
178
- contentId: t.id
179
- }) || j({
180
- variations: t.variations,
181
- id: t.id
182
- }), o = D({
183
- item: t,
184
- testGroupId: r
185
- });
186
- return {
187
- ...t,
188
- ...o
189
- };
190
- }, ft = (t) => m(t) ? t : !0, $t = (t) => ({
191
- type: "builder.registerComponent",
192
- data: gt(t)
193
- }), ht = (t) => {
194
- const e = t.toString().trim();
195
- return `return (${!e.startsWith("function") && !e.startsWith("(") ? "function " : ""}${e}).apply(this, arguments)`;
196
- };
197
- function gt(t) {
198
- return JSON.parse(JSON.stringify(t, (e, n) => typeof n == "function" ? ht(n) : n));
199
- }
200
- function pt() {
201
- return typeof globalThis != "undefined" ? globalThis : typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : globalThis;
202
- }
203
- function mt() {
204
- const t = pt().fetch;
205
- if (typeof t == "undefined")
206
- throw console.warn(`Builder SDK could not find a global fetch function. Make sure you have a polyfill for fetch in your project.
207
- For more information, read https://github.com/BuilderIO/this-package-uses-fetch`), new Error("Builder SDK could not find a global `fetch` function");
208
- return t;
209
- }
210
- const yt = mt();
211
- function k(t, e = null, n = ".") {
212
- return Object.keys(t).reduce((r, o) => {
213
- const s = t[o], a = [e, o].filter(Boolean).join(n);
214
- return [typeof s == "object", s !== null, !(Array.isArray(s) && s.length === 0)].every(Boolean) ? {
215
- ...r,
216
- ...k(s, a, n)
217
- } : {
218
- ...r,
219
- [a]: s
220
- };
221
- }, {});
222
- }
223
- function K(t, e, n = {}) {
224
- for (const r in t) {
225
- const o = t[r], s = e ? e + "." + r : r;
226
- o && typeof o == "object" && !Array.isArray(o) && !Object.keys(o).find((a) => a.startsWith("$")) ? K(o, s, n) : n[s] = o;
227
- }
228
- return n;
229
- }
230
- const wt = "v3", x = "builder.", St = "options.", W = (t) => {
231
- if (!t)
232
- return {};
233
- const e = L(t), n = {};
234
- return Object.keys(e).forEach((r) => {
235
- if (r.startsWith(x)) {
236
- const o = r.replace(x, "").replace(St, "");
237
- n[o] = e[r];
238
- }
239
- }), n;
240
- }, bt = () => {
241
- if (!c())
242
- return {};
243
- const t = new URLSearchParams(window.location.search);
244
- return W(t);
245
- }, A = (t) => typeof t == "number" && !isNaN(t) && t >= 0, P = (t) => {
246
- const {
247
- limit: e = 30,
248
- userAttributes: n,
249
- query: r,
250
- model: o,
251
- apiKey: s,
252
- enrich: a,
253
- locale: d,
254
- apiVersion: y = wt,
255
- fields: p,
256
- omit: I,
257
- offset: u,
258
- cacheSeconds: h,
259
- staleCacheSeconds: g,
260
- sort: w,
261
- includeUnpublished: O
262
- } = t;
263
- if (!s)
264
- throw new Error("Missing API key");
265
- if (!["v3"].includes(y))
266
- throw new Error(`Invalid apiVersion: expected 'v3', received '${y}'`);
267
- const H = e !== 1, i = new URL(`https://cdn.builder.io/api/${y}/content/${o}`);
268
- if (i.searchParams.set("apiKey", s), i.searchParams.set("limit", String(e)), i.searchParams.set("noTraverse", String(H)), i.searchParams.set("includeRefs", String(!0)), d && i.searchParams.set("locale", d), a && i.searchParams.set("enrich", String(a)), i.searchParams.set("omit", I || "meta.componentsUsed"), p && i.searchParams.set("fields", p), Number.isFinite(u) && u > -1 && i.searchParams.set("offset", String(Math.floor(u))), typeof O == "boolean" && i.searchParams.set("includeUnpublished", String(O)), h && A(h) && i.searchParams.set("cacheSeconds", String(h)), g && A(g) && i.searchParams.set("staleCacheSeconds", String(g)), w) {
269
- const l = k({
270
- sort: w
271
- });
272
- for (const S in l)
273
- i.searchParams.set(S, JSON.stringify(l[S]));
274
- }
275
- const X = {
276
- ...bt(),
277
- ...L(t.options || {})
278
- }, C = k(X);
279
- for (const l in C)
280
- i.searchParams.set(l, String(C[l]));
281
- if (n && i.searchParams.set("userAttributes", JSON.stringify(n)), r) {
282
- const l = K({
283
- query: r
284
- });
285
- for (const S in l)
286
- i.searchParams.set(S, JSON.stringify(l[S]));
287
- }
288
- return i;
289
- }, vt = (t) => "results" in t;
290
- async function It(t) {
291
- const e = await Pt({
292
- ...t,
293
- limit: 1
294
- });
295
- return e && e[0] || null;
296
- }
297
- const kt = async (t) => {
298
- var s;
299
- const e = P(t);
300
- return await (await ((s = t.fetch) != null ? s : yt)(e.href, t.fetchOptions)).json();
301
- }, Et = async (t, e, n = P(t)) => {
302
- const r = ft(t.canTrack);
303
- if (n.search.includes("preview="), !r || !(c() || v === "reactNative"))
304
- return e.results;
305
- try {
306
- const o = [];
307
- for (const s of e.results)
308
- o.push(await lt({
309
- item: s,
310
- canTrack: r
311
- }));
312
- e.results = o;
313
- } catch (o) {
314
- f.error("Could not process A/B tests. ", o);
315
- }
316
- return e.results;
317
156
  };
318
- async function Pt(t) {
319
- try {
320
- const e = P(t), n = await kt(t);
321
- return vt(n) ? Et(t, n) : (f.error("Error fetching data. ", {
322
- url: e,
323
- content: n,
324
- options: t
325
- }), null);
326
- } catch (e) {
327
- return f.error("Error fetching data. ", e), null;
328
- }
329
- }
330
- function Gt(t) {
331
- const e = t || (c() ? window.location.search : void 0);
332
- return e ? V(e).indexOf("builder.preview=") !== -1 : !1;
333
- }
334
- function Ot() {
157
+ function lt() {
335
158
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(t) {
336
159
  const e = Math.random() * 16 | 0;
337
160
  return (t == "x" ? e : e & 3 | 8).toString(16);
338
161
  });
339
162
  }
340
- function _() {
341
- return Ot().replace(/-/g, "");
163
+ function D() {
164
+ return lt().replace(/-/g, "");
342
165
  }
343
- const $ = "builderSessionId", Ct = async ({
166
+ const K = "builderSessionId", ft = async ({
344
167
  canTrack: t
345
168
  }) => {
346
169
  if (!t)
347
170
  return;
348
- const e = await M({
349
- name: $,
171
+ const e = await N({
172
+ name: K,
350
173
  canTrack: t
351
174
  });
352
175
  if (m(e))
353
176
  return e;
354
177
  {
355
- const n = xt();
356
- return At({
178
+ const n = ht();
179
+ return gt({
357
180
  id: n,
358
181
  canTrack: t
359
182
  }), n;
360
183
  }
361
- }, xt = () => _(), At = ({
184
+ }, ht = () => D(), gt = ({
362
185
  id: t,
363
186
  canTrack: e
364
- }) => N({
365
- name: $,
187
+ }) => j({
188
+ name: K,
366
189
  value: t,
367
190
  canTrack: e
368
- }), G = () => c() && typeof localStorage != "undefined" ? localStorage : void 0, Tt = ({
191
+ }), W = () => c() && typeof localStorage != "undefined" ? localStorage : void 0, pt = ({
369
192
  key: t,
370
193
  canTrack: e
371
194
  }) => {
372
195
  var n;
373
196
  try {
374
- return e ? (n = G()) == null ? void 0 : n.getItem(t) : void 0;
197
+ return e ? (n = W()) == null ? void 0 : n.getItem(t) : void 0;
375
198
  } catch (r) {
376
199
  console.debug("[LocalStorage] GET error: ", r);
377
200
  return;
378
201
  }
379
- }, Rt = ({
202
+ }, mt = ({
380
203
  key: t,
381
204
  canTrack: e,
382
205
  value: n
383
206
  }) => {
384
207
  var r;
385
208
  try {
386
- e && ((r = G()) == null || r.setItem(t, n));
209
+ e && ((r = W()) == null || r.setItem(t, n));
387
210
  } catch (o) {
388
211
  console.debug("[LocalStorage] SET error: ", o);
389
212
  }
390
- }, J = "builderVisitorId", Bt = ({
213
+ }, _ = "builderVisitorId", yt = ({
391
214
  canTrack: t
392
215
  }) => {
393
216
  if (!t)
394
217
  return;
395
- const e = Tt({
396
- key: J,
218
+ const e = pt({
219
+ key: _,
397
220
  canTrack: t
398
221
  });
399
222
  if (m(e))
400
223
  return e;
401
224
  {
402
- const n = Lt();
403
- return Vt({
225
+ const n = wt();
226
+ return St({
404
227
  id: n,
405
228
  canTrack: t
406
229
  }), n;
407
230
  }
408
- }, Lt = () => _(), Vt = ({
231
+ }, wt = () => D(), St = ({
409
232
  id: t,
410
233
  canTrack: e
411
- }) => Rt({
412
- key: J,
234
+ }) => mt({
235
+ key: _,
413
236
  value: t,
414
237
  canTrack: e
415
- }), Ut = async ({
238
+ }), bt = async ({
416
239
  canTrack: t
417
240
  }) => {
418
241
  if (!t)
@@ -420,16 +243,16 @@ const $ = "builderSessionId", Ct = async ({
420
243
  visitorId: void 0,
421
244
  sessionId: void 0
422
245
  };
423
- const e = await Ct({
246
+ const e = await ft({
424
247
  canTrack: t
425
- }), n = Bt({
248
+ }), n = yt({
426
249
  canTrack: t
427
250
  });
428
251
  return {
429
252
  sessionId: e,
430
253
  visitorId: n
431
254
  };
432
- }, Mt = async ({
255
+ }, vt = async ({
433
256
  type: t,
434
257
  canTrack: e,
435
258
  apiKey: n,
@@ -443,23 +266,23 @@ const $ = "builderSessionId", Ct = async ({
443
266
  url: location.href,
444
267
  ...r
445
268
  },
446
- ...await Ut({
269
+ ...await bt({
447
270
  canTrack: e
448
271
  }),
449
- userAttributes: et(),
272
+ userAttributes: nt(),
450
273
  ownerId: n
451
274
  }
452
275
  });
453
- async function Nt(t) {
276
+ async function It(t) {
454
277
  if (!t.apiKey) {
455
278
  f.error("Missing API key for track call. Please provide your API key.");
456
279
  return;
457
280
  }
458
- if (t.canTrack && !Y() && (c() || v === "reactNative"))
281
+ if (t.canTrack && !Z() && (c() || v === "reactNative"))
459
282
  return fetch("https://cdn.builder.io/api/v1/track", {
460
283
  method: "POST",
461
284
  body: JSON.stringify({
462
- events: [await Mt(t)]
285
+ events: [await vt(t)]
463
286
  }),
464
287
  headers: {
465
288
  "content-type": "application/json"
@@ -469,36 +292,18 @@ async function Nt(t) {
469
292
  console.error("Failed to track: ", e);
470
293
  });
471
294
  }
472
- const Jt = (t) => Nt({
295
+ const Jt = (t) => It({
473
296
  ...t,
474
297
  canTrack: !0
475
- }), Ft = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
476
- function z(t, e) {
298
+ }), kt = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
299
+ function $(t, e) {
477
300
  if (!e.origin.startsWith("http") && !e.origin.startsWith("https"))
478
301
  return !1;
479
302
  const n = new URL(e.origin), r = n.hostname;
480
- return (t || Ft).findIndex((o) => o.startsWith("*.") ? r.endsWith(o.slice(1)) : o === r) > -1;
303
+ return (t || kt).findIndex((o) => o.startsWith("*.") ? r.endsWith(o.slice(1)) : o === r) > -1;
481
304
  }
482
- const jt = "2.0.8", T = {};
483
- function Dt(t, e) {
484
- let n = T[t];
485
- if (n || (n = T[t] = []), n.push(e), c()) {
486
- const r = {
487
- type: "builder.register",
488
- data: {
489
- type: t,
490
- info: e
491
- }
492
- };
493
- try {
494
- parent.postMessage(r, "*"), parent !== window && window.postMessage(r, "*");
495
- } catch (o) {
496
- console.debug("Could not postmessage", o);
497
- }
498
- }
499
- }
500
- const zt = () => {
501
- Dt("insertMenu", {
305
+ const Et = "2.0.12", zt = () => {
306
+ ot("insertMenu", {
502
307
  name: "_default",
503
308
  default: !0,
504
309
  items: [{
@@ -521,13 +326,13 @@ const zt = () => {
521
326
  });
522
327
  };
523
328
  let R = !1;
524
- const Kt = (t = {}) => {
329
+ const Pt = (t = {}) => {
525
330
  var e, n;
526
331
  R || (R = !0, c() && ((e = window.parent) == null || e.postMessage({
527
332
  type: "builder.sdkInfo",
528
333
  data: {
529
334
  target: v,
530
- version: jt,
335
+ version: Et,
531
336
  supportsPatchUpdates: !1,
532
337
  // Supports builder-model="..." attribute which is needed to
533
338
  // scope our '+ add block' button styling
@@ -541,7 +346,7 @@ const Kt = (t = {}) => {
541
346
  }
542
347
  }, "*"), window.addEventListener("message", (r) => {
543
348
  var s, a;
544
- if (!z(t.trustedHosts, r))
349
+ if (!$(t.trustedHosts, r))
545
350
  return;
546
351
  const {
547
352
  data: o
@@ -582,12 +387,12 @@ const Kt = (t = {}) => {
582
387
  }
583
388
  }
584
389
  })));
585
- }, Wt = ({
390
+ }, Ot = ({
586
391
  model: t,
587
392
  trustedHosts: e,
588
393
  callbacks: n
589
394
  }) => (r) => {
590
- if (!z(e, r))
395
+ if (!$(e, r))
591
396
  return;
592
397
  const {
593
398
  data: o
@@ -612,8 +417,8 @@ const Kt = (t = {}) => {
612
417
  if (!c)
613
418
  return f.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server."), () => {
614
419
  };
615
- Kt();
616
- const r = Wt({
420
+ Pt();
421
+ const r = Ot({
617
422
  callbacks: {
618
423
  contentUpdate: e,
619
424
  animation: () => {
@@ -627,15 +432,214 @@ const Kt = (t = {}) => {
627
432
  return window.addEventListener("message", r), () => {
628
433
  window.removeEventListener("message", r);
629
434
  };
630
- }, B = {};
631
- function Xt(t) {
632
- if (c()) {
633
- Object.assign(B, t);
634
- const e = {
635
- type: "builder.settingsChange",
636
- data: B
435
+ }, Ct = "builder.tests", E = (t) => `${Ct}.${t}`, xt = ({
436
+ contentId: t
437
+ }) => N({
438
+ name: E(t),
439
+ canTrack: !0
440
+ }), At = ({
441
+ contentId: t
442
+ }) => F({
443
+ name: E(t),
444
+ canTrack: !0
445
+ }), Tt = ({
446
+ contentId: t,
447
+ value: e
448
+ }) => j({
449
+ name: E(t),
450
+ value: e,
451
+ canTrack: !0
452
+ }), G = (t) => m(t.id) && m(t.variations) && Object.keys(t.variations).length > 0, Rt = ({
453
+ id: t,
454
+ variations: e
455
+ }) => {
456
+ var o;
457
+ let n = 0;
458
+ const r = Math.random();
459
+ for (const s in e) {
460
+ const a = (o = e[s]) == null ? void 0 : o.testRatio;
461
+ if (n += a, r < n)
462
+ return s;
463
+ }
464
+ return t;
465
+ }, J = (t) => {
466
+ const e = Rt(t);
467
+ return Tt({
468
+ contentId: t.id,
469
+ value: e
470
+ }).catch((n) => {
471
+ f.error("could not store A/B test variation: ", n);
472
+ }), e;
473
+ }, z = ({
474
+ item: t,
475
+ testGroupId: e
476
+ }) => {
477
+ const n = t.variations[e];
478
+ return e === t.id || // handle edge-case where `testGroupId` points to non-existing variation
479
+ !n ? {
480
+ testVariationId: t.id,
481
+ testVariationName: "Default"
482
+ } : {
483
+ data: n.data,
484
+ testVariationId: n.id,
485
+ testVariationName: n.name || (n.id === t.id ? "Default" : "")
486
+ };
487
+ }, Xt = ({
488
+ item: t,
489
+ canTrack: e
490
+ }) => {
491
+ if (!e)
492
+ return t;
493
+ if (!t)
494
+ return;
495
+ if (!G(t))
496
+ return t;
497
+ const n = At({
498
+ contentId: t.id
499
+ }) || J({
500
+ variations: t.variations,
501
+ id: t.id
502
+ }), r = z({
503
+ item: t,
504
+ testGroupId: n
505
+ });
506
+ return {
507
+ ...t,
508
+ ...r
509
+ };
510
+ }, Bt = async ({
511
+ item: t,
512
+ canTrack: e
513
+ }) => {
514
+ if (!e || !G(t))
515
+ return t;
516
+ const r = await xt({
517
+ contentId: t.id
518
+ }) || J({
519
+ variations: t.variations,
520
+ id: t.id
521
+ }), o = z({
522
+ item: t,
523
+ testGroupId: r
524
+ });
525
+ return {
526
+ ...t,
527
+ ...o
528
+ };
529
+ }, Lt = (t) => m(t) ? t : !0;
530
+ function Vt() {
531
+ return typeof globalThis != "undefined" ? globalThis : typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : globalThis;
532
+ }
533
+ function Ut() {
534
+ const t = Vt().fetch;
535
+ if (typeof t == "undefined")
536
+ throw console.warn(`Builder SDK could not find a global fetch function. Make sure you have a polyfill for fetch in your project.
537
+ For more information, read https://github.com/BuilderIO/this-package-uses-fetch`), new Error("Builder SDK could not find a global `fetch` function");
538
+ return t;
539
+ }
540
+ const Mt = Ut();
541
+ function k(t, e = null, n = ".") {
542
+ return Object.keys(t).reduce((r, o) => {
543
+ const s = t[o], a = [e, o].filter(Boolean).join(n);
544
+ return [typeof s == "object", s !== null, !(Array.isArray(s) && s.length === 0)].every(Boolean) ? {
545
+ ...r,
546
+ ...k(s, a, n)
547
+ } : {
548
+ ...r,
549
+ [a]: s
637
550
  };
638
- parent.postMessage(e, "*");
551
+ }, {});
552
+ }
553
+ function H(t, e, n = {}) {
554
+ for (const r in t) {
555
+ const o = t[r], s = e ? e + "." + r : r;
556
+ o && typeof o == "object" && !Array.isArray(o) && !Object.keys(o).find((a) => a.startsWith("$")) ? H(o, s, n) : n[s] = o;
557
+ }
558
+ return n;
559
+ }
560
+ const Ft = "v3", B = (t) => typeof t == "number" && !isNaN(t) && t >= 0, P = (t) => {
561
+ const {
562
+ limit: e = 30,
563
+ userAttributes: n,
564
+ query: r,
565
+ model: o,
566
+ apiKey: s,
567
+ enrich: a,
568
+ locale: d,
569
+ apiVersion: y = Ft,
570
+ fields: p,
571
+ omit: I,
572
+ offset: u,
573
+ cacheSeconds: h,
574
+ staleCacheSeconds: g,
575
+ sort: w,
576
+ includeUnpublished: O
577
+ } = t;
578
+ if (!s)
579
+ throw new Error("Missing API key");
580
+ if (!["v3"].includes(y))
581
+ throw new Error(`Invalid apiVersion: expected 'v3', received '${y}'`);
582
+ const X = e !== 1, i = new URL(`https://cdn.builder.io/api/${y}/content/${o}`);
583
+ if (i.searchParams.set("apiKey", s), i.searchParams.set("limit", String(e)), 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", I || "meta.componentsUsed"), p && i.searchParams.set("fields", p), Number.isFinite(u) && u > -1 && i.searchParams.set("offset", String(Math.floor(u))), typeof O == "boolean" && i.searchParams.set("includeUnpublished", String(O)), h && B(h) && i.searchParams.set("cacheSeconds", String(h)), g && B(g) && i.searchParams.set("staleCacheSeconds", String(g)), w) {
584
+ const l = k({
585
+ sort: w
586
+ });
587
+ for (const S in l)
588
+ i.searchParams.set(S, JSON.stringify(l[S]));
589
+ }
590
+ const q = {
591
+ ...it(),
592
+ ...L(t.options || {})
593
+ }, C = k(q);
594
+ for (const l in C)
595
+ i.searchParams.set(l, String(C[l]));
596
+ if (n && i.searchParams.set("userAttributes", JSON.stringify(n)), r) {
597
+ const l = H({
598
+ query: r
599
+ });
600
+ for (const S in l)
601
+ i.searchParams.set(S, JSON.stringify(l[S]));
602
+ }
603
+ return i;
604
+ }, Nt = (t) => "results" in t;
605
+ async function jt(t) {
606
+ const e = await Wt({
607
+ ...t,
608
+ limit: 1
609
+ });
610
+ return e && e[0] || null;
611
+ }
612
+ const Dt = async (t) => {
613
+ var s;
614
+ const e = P(t);
615
+ return await (await ((s = t.fetch) != null ? s : Mt)(e.href, t.fetchOptions)).json();
616
+ }, Kt = async (t, e, n = P(t)) => {
617
+ const r = Lt(t.canTrack);
618
+ if (n.search.includes("preview="), !r || !(c() || v === "reactNative"))
619
+ return e.results;
620
+ try {
621
+ const o = [];
622
+ for (const s of e.results)
623
+ o.push(await Bt({
624
+ item: s,
625
+ canTrack: r
626
+ }));
627
+ e.results = o;
628
+ } catch (o) {
629
+ f.error("Could not process A/B tests. ", o);
630
+ }
631
+ return e.results;
632
+ };
633
+ async function Wt(t) {
634
+ try {
635
+ const e = P(t), n = await Dt(t);
636
+ return Nt(n) ? Kt(t, n) : (f.error("Error fetching data. ", {
637
+ url: e,
638
+ content: n,
639
+ options: t
640
+ }), null);
641
+ } catch (e) {
642
+ return f.error("Error fetching data. ", e), null;
639
643
  }
640
644
  }
641
645
  const qt = async (t) => {
@@ -650,39 +654,39 @@ const qt = async (t) => {
650
654
  urlPath: e
651
655
  } : {}
652
656
  },
653
- options: W(t.searchParams || ((s = t.url) == null ? void 0 : s.searchParams) || t.options)
657
+ options: M(t.searchParams || ((s = t.url) == null ? void 0 : s.searchParams) || t.options)
654
658
  };
655
659
  return {
656
660
  apiKey: n.apiKey,
657
661
  model: n.model,
658
- content: await It(n)
662
+ content: await jt(n)
659
663
  };
660
664
  };
661
665
  export {
662
666
  b as MSG_PREFIX,
663
667
  v as TARGET,
664
- Et as _processContentResult,
665
- Nt as _track,
668
+ Kt as _processContentResult,
669
+ It as _track,
666
670
  m as checkIsDefined,
667
- Wt as createEditorListener,
671
+ Ot as createEditorListener,
668
672
  $t as createRegisterComponentMessage,
669
- yt as fetch,
673
+ Mt as fetch,
670
674
  qt as fetchBuilderProps,
671
- Pt as fetchEntries,
672
- It as fetchOneEntry,
673
- W as getBuilderSearchParams,
674
- ft as getDefaultCanTrack,
675
- et as getUserAttributes,
676
- _t as handleABTestingSync,
675
+ Wt as fetchEntries,
676
+ jt as fetchOneEntry,
677
+ M as getBuilderSearchParams,
678
+ Lt as getDefaultCanTrack,
679
+ nt as getUserAttributes,
680
+ Xt as handleABTestingSync,
677
681
  c as isBrowser,
678
- Y as isEditing,
679
- Gt as isPreviewing,
682
+ Z as isEditing,
683
+ _t as isPreviewing,
680
684
  f as logger,
681
- Dt as register,
685
+ ot as register,
682
686
  zt as registerInsertMenu,
683
- gt as serializeComponentInfo,
684
- Xt as setEditorSettings,
685
- Kt as setupBrowserForEditing,
687
+ U as serializeIncludingFunctions,
688
+ Gt as setEditorSettings,
689
+ Pt as setupBrowserForEditing,
686
690
  Ht as subscribeToEditor,
687
691
  Jt as track
688
692
  };