@builder.io/sdk-react 3.0.1 → 3.0.3-0

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