@builder.io/sdk-react 3.0.1 → 3.0.3

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