@builder.io/sdk-react 3.0.1 → 3.0.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.
Files changed (83) hide show
  1. package/lib/browser/blocks-exports.cjs +21 -21
  2. package/lib/browser/blocks-exports.mjs +657 -658
  3. package/lib/browser/index.cjs +1 -1
  4. package/lib/browser/index.mjs +1 -1
  5. package/lib/browser/server-entry-75ce8600.cjs +2 -0
  6. package/lib/browser/server-entry-a2495a20.js +748 -0
  7. package/lib/browser/server-entry.cjs +1 -1
  8. package/lib/browser/server-entry.mjs +1 -1
  9. package/lib/edge/{accordion-decb24cf.cjs → accordion-1c16f65e.cjs} +1 -1
  10. package/lib/edge/{accordion-1572cb0d.js → accordion-c020e15b.js} +1 -1
  11. package/lib/edge/blocks-27ac5b23.js +3534 -0
  12. package/lib/edge/blocks-cd946d16.cjs +30 -0
  13. package/lib/edge/blocks-exports.cjs +1 -1
  14. package/lib/edge/blocks-exports.mjs +2 -2
  15. package/lib/edge/{button-0709893d.js → button-5cdb4f26.js} +2 -2
  16. package/lib/edge/{button-cf66cf8d.cjs → button-8572fca5.cjs} +1 -1
  17. package/lib/edge/{columns-e234acc6.js → columns-3ac1fa96.js} +5 -6
  18. package/lib/edge/columns-c8a9cb89.cjs +28 -0
  19. package/lib/edge/{content-variants-3ab9230f.js → content-variants-23c8eec6.js} +209 -205
  20. package/lib/edge/content-variants-caa23bf7.cjs +134 -0
  21. package/lib/edge/form-3d9bf265.cjs +1 -0
  22. package/lib/edge/{form-27bcc23a.js → form-7fc5691b.js} +14 -15
  23. package/lib/edge/{get-class-prop-name-0b3d48a4.cjs → get-class-prop-name-29fd576a.cjs} +1 -1
  24. package/lib/edge/{get-class-prop-name-a3bd113c.js → get-class-prop-name-a4845b04.js} +1 -1
  25. package/lib/edge/{img-e0c8f7f9.cjs → img-102acaa2.cjs} +1 -1
  26. package/lib/edge/{img-80be6914.js → img-388698cb.js} +1 -1
  27. package/lib/edge/index.cjs +1 -1
  28. package/lib/edge/index.mjs +1 -1
  29. package/lib/edge/{input-f5ba6b1e.cjs → input-10e350a9.cjs} +1 -1
  30. package/lib/edge/{input-920922d5.js → input-5484e9e7.js} +1 -1
  31. package/lib/edge/{select-673864b7.js → select-b8406bcf.js} +1 -1
  32. package/lib/edge/{select-2ced1aca.cjs → select-f11be7a7.cjs} +1 -1
  33. package/lib/edge/server-entry-1879cbc4.cjs +2 -0
  34. package/lib/edge/server-entry-7ce03a4e.js +746 -0
  35. package/lib/edge/server-entry.cjs +1 -1
  36. package/lib/edge/server-entry.mjs +1 -1
  37. package/lib/edge/{slot-68f2b177.js → slot-23f75377.js} +5 -6
  38. package/lib/edge/slot-4ab390ec.cjs +1 -0
  39. package/lib/edge/{symbol-7e260a70.js → symbol-2eafb4e0.js} +2 -2
  40. package/lib/edge/{symbol-ded9dba9.cjs → symbol-fa343d77.cjs} +1 -1
  41. package/lib/edge/{tabs-5156494d.js → tabs-4c9c64f6.js} +15 -16
  42. package/lib/edge/tabs-7d258d82.cjs +1 -0
  43. package/lib/edge/text-5915f038.js +17 -0
  44. package/lib/edge/text-e6dbb721.cjs +1 -0
  45. package/lib/node/blocks-exports.cjs +22 -22
  46. package/lib/node/blocks-exports.mjs +542 -543
  47. package/lib/node/index.cjs +1 -1
  48. package/lib/node/index.mjs +3 -3
  49. package/lib/node/init.cjs +1 -1
  50. package/lib/node/init.mjs +3 -3
  51. package/lib/node/server-entry-2b263dde.js +749 -0
  52. package/lib/node/server-entry-ec330556.cjs +2 -0
  53. package/lib/node/server-entry.cjs +1 -1
  54. package/lib/node/server-entry.mjs +1 -1
  55. package/lib/node/{setIvm-aba1bed8.cjs → setIvm-1e6f0b60.cjs} +1 -1
  56. package/lib/node/{setIvm-8b303d4e.js → setIvm-7eb67cd6.js} +1 -1
  57. package/lib/node/setIvm.cjs +1 -1
  58. package/lib/node/setIvm.mjs +2 -2
  59. package/lib/node/{should-force-browser-runtime-in-node-491a9b55.cjs → should-force-browser-runtime-in-node-23218b19.cjs} +1 -1
  60. package/lib/node/{should-force-browser-runtime-in-node-0a037bde.js → should-force-browser-runtime-in-node-cdae9360.js} +1 -1
  61. package/package.json +1 -1
  62. package/types/constants/sdk-version.d.ts +1 -1
  63. package/types/functions/get-block-component-options.d.ts +2 -1
  64. package/types/functions/get-processed-block.d.ts +1 -6
  65. package/types/helpers/flatten.d.ts +6 -0
  66. package/types/server-index.d.ts +1 -1
  67. package/lib/browser/server-entry-017b8439.js +0 -717
  68. package/lib/browser/server-entry-9f80066e.cjs +0 -2
  69. package/lib/edge/blocks-9c35be74.js +0 -916
  70. package/lib/edge/blocks-d3823063.cjs +0 -12
  71. package/lib/edge/columns-2fdf0656.cjs +0 -28
  72. package/lib/edge/content-variants-616a6c0f.cjs +0 -134
  73. package/lib/edge/evaluate-ccf1ad96.cjs +0 -19
  74. package/lib/edge/evaluate-f0b82ede.js +0 -2612
  75. package/lib/edge/form-7c61693d.cjs +0 -1
  76. package/lib/edge/server-entry-6c0047ea.js +0 -715
  77. package/lib/edge/server-entry-de142ee8.cjs +0 -2
  78. package/lib/edge/slot-cc8b4e5b.cjs +0 -1
  79. package/lib/edge/tabs-d422921f.cjs +0 -1
  80. package/lib/edge/text-27a917c0.js +0 -37
  81. package/lib/edge/text-5796f488.cjs +0 -1
  82. package/lib/node/server-entry-e91e06a3.cjs +0 -2
  83. package/lib/node/server-entry-fdedc1aa.js +0 -718
@@ -0,0 +1,746 @@
1
+ const v = "react", rt = (t) => {
2
+ const e = {};
3
+ return t.forEach((n, r) => {
4
+ e[r] = n;
5
+ }), e;
6
+ }, F = (t) => t instanceof URLSearchParams ? rt(t) : t, D = (t) => typeof t == "string" ? t : t instanceof URLSearchParams ? t.toString() : new URLSearchParams(t).toString();
7
+ function c() {
8
+ return typeof window != "undefined" && typeof document != "undefined";
9
+ }
10
+ function ot() {
11
+ return c() && window.self !== window.top;
12
+ }
13
+ function st(t) {
14
+ return ot() && // accessing window.location.search is safe here because `isIframe()` is only `true` if we're in a browser.
15
+ D(t || window.location.search).indexOf("builder.frameEditing=") !== -1;
16
+ }
17
+ function Zt(t) {
18
+ const e = t || (c() ? window.location.search : void 0);
19
+ return e ? D(e).indexOf("builder.preview=") !== -1 : !1;
20
+ }
21
+ const qt = (t) => ({
22
+ type: "builder.registerComponent",
23
+ data: N(t)
24
+ }), it = (t) => {
25
+ const e = t.toString().trim(), n = /^[a-zA-Z0-9_]+\s*=>/i.test(e);
26
+ return `return (${!e.startsWith("function") && !e.startsWith("async") && !e.startsWith("(") && !n ? "function " : ""}${e}).apply(this, arguments)`;
27
+ };
28
+ function N(t) {
29
+ return JSON.parse(JSON.stringify(t, (e, n) => typeof n == "function" ? it(n) : n));
30
+ }
31
+ const U = {};
32
+ function at(t, e) {
33
+ t === "plugin" && (e = N(e));
34
+ let n = U[t];
35
+ if (n || (n = U[t] = []), n.push(e), c()) {
36
+ const r = {
37
+ type: "builder.register",
38
+ data: {
39
+ type: t,
40
+ info: e
41
+ }
42
+ };
43
+ try {
44
+ parent.postMessage(r, "*"), parent !== window && window.postMessage(r, "*");
45
+ } catch (o) {
46
+ console.debug("Could not postmessage", o);
47
+ }
48
+ }
49
+ }
50
+ const B = {};
51
+ function te(t) {
52
+ if (c()) {
53
+ Object.assign(B, t);
54
+ const e = {
55
+ type: "builder.settingsChange",
56
+ data: B
57
+ };
58
+ parent.postMessage(e, "*");
59
+ }
60
+ }
61
+ const R = "builder.", ct = "options.", M = (t) => {
62
+ if (!t)
63
+ return {};
64
+ const e = F(t), n = {};
65
+ return Object.keys(e).forEach((r) => {
66
+ if (r.startsWith(R)) {
67
+ const o = r.replace(R, "").replace(ct, "");
68
+ n[o] = e[r];
69
+ }
70
+ }), n;
71
+ }, ut = () => {
72
+ if (!c())
73
+ return {};
74
+ const t = new URLSearchParams(window.location.search);
75
+ return M(t);
76
+ }, I = "[Builder.io]: ", f = {
77
+ log: (...t) => console.log(I, ...t),
78
+ error: (...t) => console.error(I, ...t),
79
+ warn: (...t) => console.warn(I, ...t),
80
+ debug: (...t) => console.debug(I, ...t)
81
+ }, K = "3.0.2", j = () => ({
82
+ "X-Builder-SDK": v,
83
+ "X-Builder-SDK-GEN": "2",
84
+ "X-Builder-SDK-Version": K
85
+ }), y = (t) => t != null, lt = (t) => {
86
+ if (t === "localhost" || t === "127.0.0.1")
87
+ return t;
88
+ const e = t.split(".");
89
+ return e.length > 2 ? e.slice(1).join(".") : t;
90
+ }, W = ({
91
+ name: t,
92
+ canTrack: e
93
+ }) => {
94
+ var n;
95
+ try {
96
+ return e ? (n = document.cookie.split("; ").find((r) => r.startsWith(`${t}=`))) == null ? void 0 : n.split("=")[1] : void 0;
97
+ } catch (r) {
98
+ f.warn("[COOKIE] GET error: ", (r == null ? void 0 : r.message) || r);
99
+ return;
100
+ }
101
+ }, $ = async (t) => W(t), dt = (t) => t.map(([e, n]) => n ? `${e}=${n}` : e).filter(y).join("; "), ft = [["secure", ""], ["SameSite", "None"]], ht = ({
102
+ name: t,
103
+ value: e,
104
+ expires: n
105
+ }) => {
106
+ const o = (c() ? location.protocol === "https:" : !0) ? ft : [[]], s = n ? [["expires", n.toUTCString()]] : [[]], i = [[t, e], ...s, ["path", "/"], ["domain", lt(window.location.hostname)], ...o];
107
+ return dt(i);
108
+ }, _ = async ({
109
+ name: t,
110
+ value: e,
111
+ expires: n,
112
+ canTrack: r
113
+ }) => {
114
+ try {
115
+ if (!r)
116
+ return;
117
+ const o = ht({
118
+ name: t,
119
+ value: e,
120
+ expires: n
121
+ });
122
+ document.cookie = o;
123
+ } catch (o) {
124
+ f.warn("[COOKIE] SET error: ", (o == null ? void 0 : o.message) || o);
125
+ }
126
+ };
127
+ function gt() {
128
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(t) {
129
+ const e = Math.random() * 16 | 0;
130
+ return (t == "x" ? e : e & 3 | 8).toString(16);
131
+ });
132
+ }
133
+ function G() {
134
+ return gt().replace(/-/g, "");
135
+ }
136
+ const H = "builderSessionId", pt = async ({
137
+ canTrack: t
138
+ }) => {
139
+ if (!t)
140
+ return;
141
+ const e = await $({
142
+ name: H,
143
+ canTrack: t
144
+ });
145
+ if (y(e))
146
+ return e;
147
+ {
148
+ const n = mt();
149
+ return yt({
150
+ id: n,
151
+ canTrack: t
152
+ }), n;
153
+ }
154
+ }, mt = () => G(), yt = ({
155
+ id: t,
156
+ canTrack: e
157
+ }) => _({
158
+ name: H,
159
+ value: t,
160
+ canTrack: e
161
+ }), J = () => c() && typeof localStorage != "undefined" ? localStorage : void 0, wt = ({
162
+ key: t,
163
+ canTrack: e
164
+ }) => {
165
+ var n;
166
+ try {
167
+ return e ? (n = J()) == null ? void 0 : n.getItem(t) : void 0;
168
+ } catch (r) {
169
+ console.debug("[LocalStorage] GET error: ", r);
170
+ return;
171
+ }
172
+ }, St = ({
173
+ key: t,
174
+ canTrack: e,
175
+ value: n
176
+ }) => {
177
+ var r;
178
+ try {
179
+ e && ((r = J()) == null || r.setItem(t, n));
180
+ } catch (o) {
181
+ console.debug("[LocalStorage] SET error: ", o);
182
+ }
183
+ }, X = "builderVisitorId", bt = ({
184
+ canTrack: t
185
+ }) => {
186
+ if (!t)
187
+ return;
188
+ const e = wt({
189
+ key: X,
190
+ canTrack: t
191
+ });
192
+ if (y(e))
193
+ return e;
194
+ {
195
+ const n = vt();
196
+ return It({
197
+ id: n,
198
+ canTrack: t
199
+ }), n;
200
+ }
201
+ }, vt = () => G(), It = ({
202
+ id: t,
203
+ canTrack: e
204
+ }) => St({
205
+ key: X,
206
+ value: t,
207
+ canTrack: e
208
+ });
209
+ function kt(t) {
210
+ var e;
211
+ typeof process != "undefined" && ((e = process.env) != null && e.DEBUG) && String(process.env.DEBUG) == "true" && f.log(t);
212
+ }
213
+ const Et = () => {
214
+ if (c()) {
215
+ const t = new URL(location.href);
216
+ return t.pathname === "" && (t.pathname = "/"), t;
217
+ } else
218
+ return console.warn("Cannot get location for tracking in non-browser environment"), null;
219
+ }, At = () => typeof navigator == "object" && navigator.userAgent || "", Pt = () => {
220
+ const t = At(), e = {
221
+ Android() {
222
+ return t.match(/Android/i);
223
+ },
224
+ BlackBerry() {
225
+ return t.match(/BlackBerry/i);
226
+ },
227
+ iOS() {
228
+ return t.match(/iPhone|iPod/i);
229
+ },
230
+ Opera() {
231
+ return t.match(/Opera Mini/i);
232
+ },
233
+ Windows() {
234
+ return t.match(/IEMobile/i) || t.match(/WPDesktop/i);
235
+ },
236
+ any() {
237
+ return e.Android() || e.BlackBerry() || e.iOS() || e.Opera() || e.Windows() || v === "reactNative";
238
+ }
239
+ }, n = t.match(/Tablet|iPad/i), r = Et();
240
+ return {
241
+ urlPath: r == null ? void 0 : r.pathname,
242
+ host: (r == null ? void 0 : r.host) || (r == null ? void 0 : r.hostname),
243
+ device: n ? "tablet" : e.any() ? "mobile" : "desktop"
244
+ };
245
+ }, Ot = async ({
246
+ canTrack: t
247
+ }) => {
248
+ if (!t)
249
+ return {
250
+ visitorId: void 0,
251
+ sessionId: void 0
252
+ };
253
+ const e = await pt({
254
+ canTrack: t
255
+ }), n = bt({
256
+ canTrack: t
257
+ });
258
+ return {
259
+ sessionId: e,
260
+ visitorId: n
261
+ };
262
+ }, Ct = async ({
263
+ type: t,
264
+ canTrack: e,
265
+ apiKey: n,
266
+ metadata: r,
267
+ ...o
268
+ }) => ({
269
+ type: t,
270
+ data: {
271
+ ...o,
272
+ metadata: {
273
+ url: location.href,
274
+ ...r
275
+ },
276
+ ...await Ot({
277
+ canTrack: e
278
+ }),
279
+ userAttributes: Pt(),
280
+ ownerId: n
281
+ }
282
+ });
283
+ async function xt({
284
+ apiHost: t,
285
+ ...e
286
+ }) {
287
+ if (!e.apiKey) {
288
+ f.error("Missing API key for track call. Please provide your API key.");
289
+ return;
290
+ }
291
+ if (!e.canTrack || st() || !(c() || v === "reactNative"))
292
+ return;
293
+ const r = `${t || "https://cdn.builder.io"}/api/v1/track`;
294
+ return kt(r), fetch(r, {
295
+ method: "POST",
296
+ body: JSON.stringify({
297
+ events: [await Ct(e)]
298
+ }),
299
+ headers: {
300
+ "content-type": "application/json",
301
+ ...j()
302
+ },
303
+ mode: "cors"
304
+ }).catch((o) => {
305
+ console.error("Failed to track: ", o);
306
+ });
307
+ }
308
+ const ee = (t) => xt({
309
+ ...t,
310
+ canTrack: !0
311
+ }), Tt = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
312
+ function z(t, e) {
313
+ if (!e.origin.startsWith("http") && !e.origin.startsWith("https"))
314
+ return !1;
315
+ const n = new URL(e.origin), r = n.hostname;
316
+ return (t || Tt).findIndex((o) => o.startsWith("*.") ? r.endsWith(o.slice(1)) : o === r) > -1;
317
+ }
318
+ const ne = () => {
319
+ at("insertMenu", {
320
+ name: "_default",
321
+ default: !0,
322
+ items: [{
323
+ name: "Box"
324
+ }, {
325
+ name: "Text"
326
+ }, {
327
+ name: "Image"
328
+ }, {
329
+ name: "Columns"
330
+ }, {
331
+ name: "Core:Section"
332
+ }, {
333
+ name: "Core:Button"
334
+ }, {
335
+ name: "Embed"
336
+ }, {
337
+ name: "Custom Code"
338
+ }]
339
+ });
340
+ };
341
+ let L = !1;
342
+ const Ut = (t = {}) => {
343
+ var e, n;
344
+ L || (L = !0, c() && ((e = window.parent) == null || e.postMessage({
345
+ type: "builder.sdkInfo",
346
+ data: {
347
+ target: v,
348
+ version: K,
349
+ supportsPatchUpdates: !1,
350
+ // Supports builder-model="..." attribute which is needed to
351
+ // scope our '+ add block' button styling
352
+ supportsAddBlockScoping: !0,
353
+ supportsCustomBreakpoints: !0
354
+ }
355
+ }, "*"), (n = window.parent) == null || n.postMessage({
356
+ type: "builder.updateContent",
357
+ data: {
358
+ options: t
359
+ }
360
+ }, "*"), window.addEventListener("message", (r) => {
361
+ var s, i;
362
+ if (!z(t.trustedHosts, r))
363
+ return;
364
+ const {
365
+ data: o
366
+ } = r;
367
+ if (o != null && o.type)
368
+ switch (o.type) {
369
+ case "builder.evaluate": {
370
+ const u = o.data.text, w = o.data.arguments || [], p = o.data.id, k = new Function(u);
371
+ let l, h = null;
372
+ try {
373
+ l = k.apply(null, w);
374
+ } catch (g) {
375
+ h = g;
376
+ }
377
+ h ? (s = window.parent) == null || s.postMessage({
378
+ type: "builder.evaluateError",
379
+ data: {
380
+ id: p,
381
+ error: h.message
382
+ }
383
+ }, "*") : l && typeof l.then == "function" ? l.then((g) => {
384
+ var S;
385
+ (S = window.parent) == null || S.postMessage({
386
+ type: "builder.evaluateResult",
387
+ data: {
388
+ id: p,
389
+ result: g
390
+ }
391
+ }, "*");
392
+ }).catch(console.error) : (i = window.parent) == null || i.postMessage({
393
+ type: "builder.evaluateResult",
394
+ data: {
395
+ result: l,
396
+ id: p
397
+ }
398
+ }, "*");
399
+ break;
400
+ }
401
+ }
402
+ })));
403
+ }, Bt = ({
404
+ model: t,
405
+ trustedHosts: e,
406
+ callbacks: n
407
+ }) => (r) => {
408
+ if (!z(e, r))
409
+ return;
410
+ const {
411
+ data: o
412
+ } = r;
413
+ if (o)
414
+ switch (o.type) {
415
+ case "builder.configureSdk": {
416
+ n.configureSdk(o.data);
417
+ break;
418
+ }
419
+ case "builder.triggerAnimation": {
420
+ n.animation(o.data);
421
+ break;
422
+ }
423
+ case "builder.contentUpdate": {
424
+ const s = o.data, i = s.key || s.alias || s.entry || s.modelName, u = s.data;
425
+ i === t && n.contentUpdate(u);
426
+ break;
427
+ }
428
+ }
429
+ }, re = (t, e, n) => {
430
+ if (!c)
431
+ return f.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server."), () => {
432
+ };
433
+ Ut();
434
+ const r = Bt({
435
+ callbacks: {
436
+ contentUpdate: e,
437
+ animation: () => {
438
+ },
439
+ configureSdk: () => {
440
+ }
441
+ },
442
+ model: t,
443
+ trustedHosts: n == null ? void 0 : n.trustedHosts
444
+ });
445
+ return window.addEventListener("message", r), () => {
446
+ window.removeEventListener("message", r);
447
+ };
448
+ }, Rt = "builder.tests", P = (t) => `${Rt}.${t}`, Lt = ({
449
+ contentId: t
450
+ }) => $({
451
+ name: P(t),
452
+ canTrack: !0
453
+ }), Vt = ({
454
+ contentId: t
455
+ }) => W({
456
+ name: P(t),
457
+ canTrack: !0
458
+ }), Ft = ({
459
+ contentId: t,
460
+ value: e
461
+ }) => _({
462
+ name: P(t),
463
+ value: e,
464
+ canTrack: !0
465
+ }), Q = (t) => y(t.id) && y(t.variations) && Object.keys(t.variations).length > 0, Dt = ({
466
+ id: t,
467
+ variations: e
468
+ }) => {
469
+ var o;
470
+ let n = 0;
471
+ const r = Math.random();
472
+ for (const s in e) {
473
+ const i = (o = e[s]) == null ? void 0 : o.testRatio;
474
+ if (n += i, r < n)
475
+ return s;
476
+ }
477
+ return t;
478
+ }, Y = (t) => {
479
+ const e = Dt(t);
480
+ return Ft({
481
+ contentId: t.id,
482
+ value: e
483
+ }).catch((n) => {
484
+ f.error("could not store A/B test variation: ", n);
485
+ }), e;
486
+ }, Z = ({
487
+ item: t,
488
+ testGroupId: e
489
+ }) => {
490
+ const n = t.variations[e];
491
+ return e === t.id || // handle edge-case where `testGroupId` points to non-existing variation
492
+ !n ? {
493
+ testVariationId: t.id,
494
+ testVariationName: "Default"
495
+ } : {
496
+ data: n.data,
497
+ testVariationId: n.id,
498
+ testVariationName: n.name || (n.id === t.id ? "Default" : "")
499
+ };
500
+ }, oe = ({
501
+ item: t,
502
+ canTrack: e
503
+ }) => {
504
+ if (!e)
505
+ return t;
506
+ if (!t)
507
+ return;
508
+ if (!Q(t))
509
+ return t;
510
+ const n = Vt({
511
+ contentId: t.id
512
+ }) || Y({
513
+ variations: t.variations,
514
+ id: t.id
515
+ }), r = Z({
516
+ item: t,
517
+ testGroupId: n
518
+ });
519
+ return {
520
+ ...t,
521
+ ...r
522
+ };
523
+ }, Nt = async ({
524
+ item: t,
525
+ canTrack: e
526
+ }) => {
527
+ if (!e || !Q(t))
528
+ return t;
529
+ const r = await Lt({
530
+ contentId: t.id
531
+ }) || Y({
532
+ variations: t.variations,
533
+ id: t.id
534
+ }), o = Z({
535
+ item: t,
536
+ testGroupId: r
537
+ });
538
+ return {
539
+ ...t,
540
+ ...o
541
+ };
542
+ }, Mt = (t) => y(t) ? t : !0;
543
+ function Kt() {
544
+ return typeof globalThis != "undefined" ? globalThis : typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : globalThis;
545
+ }
546
+ function jt() {
547
+ const t = Kt().fetch;
548
+ if (typeof t == "undefined")
549
+ throw console.warn(`Builder SDK could not find a global fetch function. Make sure you have a polyfill for fetch in your project.
550
+ For more information, read https://github.com/BuilderIO/this-package-uses-fetch`), new Error("Builder SDK could not find a global `fetch` function");
551
+ return t;
552
+ }
553
+ const Wt = jt();
554
+ function A(t, e = null, n = ".") {
555
+ return Object.keys(t).reduce((r, o) => {
556
+ const s = t[o], i = [e, o].filter(Boolean).join(n);
557
+ return [typeof s == "object", s !== null, !(Array.isArray(s) && s.length === 0)].every(Boolean) ? {
558
+ ...r,
559
+ ...A(s, i, n)
560
+ } : {
561
+ ...r,
562
+ [i]: s
563
+ };
564
+ }, {});
565
+ }
566
+ function q(t, e, n = {}) {
567
+ for (const r in t) {
568
+ const o = t[r], s = e ? e + "." + r : r;
569
+ o && typeof o == "object" && !Array.isArray(o) && !Object.keys(o).find((i) => i.startsWith("$")) ? q(o, s, n) : n[s] = o;
570
+ }
571
+ return n;
572
+ }
573
+ function $t(t) {
574
+ const e = {};
575
+ for (const n in t) {
576
+ const r = n.split(".");
577
+ let o = e;
578
+ for (let s = 0; s < r.length; s++) {
579
+ const i = r[s];
580
+ s === r.length - 1 ? o[i] = t[n] : (o[i] = o[i] || {}, o = o[i]);
581
+ }
582
+ }
583
+ return e;
584
+ }
585
+ const _t = "v3", V = (t) => typeof t == "number" && !isNaN(t) && t >= 0, O = (t) => {
586
+ const {
587
+ limit: e = 30,
588
+ userAttributes: n,
589
+ query: r,
590
+ model: o,
591
+ apiKey: s,
592
+ enrich: i,
593
+ locale: u,
594
+ apiVersion: w = _t,
595
+ fields: p,
596
+ omit: k,
597
+ offset: l,
598
+ cacheSeconds: h,
599
+ staleCacheSeconds: g,
600
+ sort: S,
601
+ includeUnpublished: C,
602
+ apiHost: tt
603
+ } = t;
604
+ if (!s)
605
+ throw new Error("Missing API key");
606
+ if (!["v3"].includes(w))
607
+ throw new Error(`Invalid apiVersion: expected 'v3', received '${w}'`);
608
+ const et = e !== 1, nt = tt || "https://cdn.builder.io", a = new URL(`${nt}/api/${w}/content/${o}`);
609
+ a.searchParams.set("apiKey", s), a.searchParams.set("limit", String(e)), a.searchParams.set("noTraverse", String(et)), a.searchParams.set("includeRefs", String(!0));
610
+ const E = u || (n == null ? void 0 : n.locale);
611
+ let m = n || {};
612
+ if (E && (a.searchParams.set("locale", E), m = {
613
+ locale: E,
614
+ ...m
615
+ }), i && a.searchParams.set("enrich", String(i)), a.searchParams.set("omit", k || "meta.componentsUsed"), p && a.searchParams.set("fields", p), Number.isFinite(l) && l > -1 && a.searchParams.set("offset", String(Math.floor(l))), typeof C == "boolean" && a.searchParams.set("includeUnpublished", String(C)), h && V(h) && a.searchParams.set("cacheSeconds", String(h)), g && V(g) && a.searchParams.set("staleCacheSeconds", String(g)), S) {
616
+ const d = A({
617
+ sort: S
618
+ });
619
+ for (const b in d)
620
+ a.searchParams.set(b, JSON.stringify(d[b]));
621
+ }
622
+ const x = {
623
+ ...ut(),
624
+ ...F(t.options || {})
625
+ };
626
+ m = {
627
+ ...m,
628
+ ...Ht(x)
629
+ };
630
+ const T = A(x);
631
+ for (const d in T)
632
+ a.searchParams.set(d, String(T[d]));
633
+ if (Object.keys(m).length > 0 && a.searchParams.set("userAttributes", JSON.stringify(m)), r) {
634
+ const d = q({
635
+ query: r
636
+ });
637
+ for (const b in d)
638
+ a.searchParams.set(b, JSON.stringify(d[b]));
639
+ }
640
+ return a;
641
+ }, Gt = (t) => {
642
+ const e = {};
643
+ for (const n in t)
644
+ n.startsWith("userAttributes.") && (e[n] = t[n], delete t[n]);
645
+ return e;
646
+ }, Ht = (t) => {
647
+ if (c() && t.preview === "BUILDER_STUDIO") {
648
+ t["userAttributes.urlPath"] = window.location.pathname, t["userAttributes.host"] = window.location.host;
649
+ const e = Gt(t), {
650
+ userAttributes: n
651
+ } = $t(e);
652
+ return n;
653
+ }
654
+ return {};
655
+ }, Jt = (t) => "results" in t;
656
+ async function Xt(t) {
657
+ const e = await Yt({
658
+ ...t,
659
+ limit: 1
660
+ });
661
+ return e && e[0] || null;
662
+ }
663
+ const zt = async (t) => {
664
+ var i, u;
665
+ const e = O(t), n = (i = t.fetch) != null ? i : Wt, r = {
666
+ ...t.fetchOptions,
667
+ headers: {
668
+ ...(u = t.fetchOptions) == null ? void 0 : u.headers,
669
+ ...j()
670
+ }
671
+ };
672
+ return await (await n(e.href, r)).json();
673
+ }, Qt = async (t, e, n = O(t)) => {
674
+ const r = Mt(t.canTrack);
675
+ if (n.search.includes("preview="), !r || !(c() || v === "reactNative"))
676
+ return e.results;
677
+ try {
678
+ const o = [];
679
+ for (const s of e.results)
680
+ o.push(await Nt({
681
+ item: s,
682
+ canTrack: r
683
+ }));
684
+ e.results = o;
685
+ } catch (o) {
686
+ f.error("Could not process A/B tests. ", o);
687
+ }
688
+ return e.results;
689
+ };
690
+ async function Yt(t) {
691
+ const e = O(t), n = await zt(t);
692
+ if (!Jt(n))
693
+ throw f.error("Error fetching data. ", {
694
+ url: e,
695
+ content: n,
696
+ options: t
697
+ }), n;
698
+ return Qt(t, n);
699
+ }
700
+ const se = async (t) => {
701
+ var r, o, s;
702
+ const e = t.path || ((r = t.url) == null ? void 0 : r.pathname) || ((o = t.userAttributes) == null ? void 0 : o.urlPath), n = {
703
+ ...t,
704
+ apiKey: t.apiKey,
705
+ model: t.model || "page",
706
+ userAttributes: {
707
+ ...t.userAttributes,
708
+ ...e ? {
709
+ urlPath: e
710
+ } : {}
711
+ },
712
+ options: M(t.searchParams || ((s = t.url) == null ? void 0 : s.searchParams) || t.options)
713
+ };
714
+ return {
715
+ apiKey: n.apiKey,
716
+ model: n.model,
717
+ content: await Xt(n)
718
+ };
719
+ };
720
+ export {
721
+ v as TARGET,
722
+ Qt as _processContentResult,
723
+ xt as _track,
724
+ y as checkIsDefined,
725
+ Bt as createEditorListener,
726
+ qt as createRegisterComponentMessage,
727
+ se as fetchBuilderProps,
728
+ Yt as fetchEntries,
729
+ Xt as fetchOneEntry,
730
+ M as getBuilderSearchParams,
731
+ Mt as getDefaultCanTrack,
732
+ Pt as getUserAttributes,
733
+ oe as handleABTestingSync,
734
+ c as isBrowser,
735
+ st as isEditing,
736
+ Zt as isPreviewing,
737
+ kt as logFetch,
738
+ f as logger,
739
+ at as register,
740
+ ne as registerInsertMenu,
741
+ N as serializeIncludingFunctions,
742
+ te as setEditorSettings,
743
+ Ut as setupBrowserForEditing,
744
+ re as subscribeToEditor,
745
+ ee as track
746
+ };