@builder.io/sdk-react 2.0.2 → 2.0.5

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 (85) hide show
  1. package/lib/browser/blocks-exports.cjs +29 -29
  2. package/lib/browser/blocks-exports.mjs +300 -278
  3. package/lib/browser/index.cjs +1 -1
  4. package/lib/browser/index.mjs +1 -1
  5. package/lib/browser/init.cjs +1 -1
  6. package/lib/browser/init.mjs +1 -1
  7. package/lib/browser/server-entry-0c6c220c.js +688 -0
  8. package/lib/browser/server-entry-7e145817.cjs +2 -0
  9. package/lib/browser/server-entry.cjs +1 -1
  10. package/lib/browser/server-entry.mjs +1 -1
  11. package/lib/edge/{accordion-4f96554c.cjs → accordion-72dab8ce.cjs} +1 -1
  12. package/lib/edge/{accordion-ca081054.js → accordion-99129d68.js} +1 -1
  13. package/lib/edge/blocks-426e0c44.js +808 -0
  14. package/lib/edge/blocks-53ae1b87.cjs +12 -0
  15. package/lib/edge/blocks-exports.cjs +1 -1
  16. package/lib/edge/blocks-exports.mjs +2 -2
  17. package/lib/edge/{button-41169061.js → button-778062cd.js} +2 -2
  18. package/lib/edge/{button-5d140f8e.cjs → button-967d0268.cjs} +1 -1
  19. package/lib/edge/{columns-f8916a18.js → columns-3a8c4d3f.js} +53 -51
  20. package/lib/edge/columns-3b921658.cjs +28 -0
  21. package/lib/edge/{content-variants-71ee0c76.js → content-variants-15d191de.js} +28 -26
  22. package/lib/edge/content-variants-4b8718f8.cjs +134 -0
  23. package/lib/edge/evaluate-26c0fdb7.js +2615 -0
  24. package/lib/edge/evaluate-c0eeb4f8.cjs +21 -0
  25. package/lib/edge/form-9d9dce5d.cjs +1 -0
  26. package/lib/edge/{form-ac2f2a0e.js → form-ccb0b912.js} +8 -7
  27. package/lib/edge/{get-class-prop-name-a677d7a5.js → get-class-prop-name-0a91c3bd.js} +1 -1
  28. package/lib/edge/{get-class-prop-name-a9b4959e.cjs → get-class-prop-name-eae60eae.cjs} +1 -1
  29. package/lib/edge/{image-e3fcd611.js → image-6a074aab.js} +27 -25
  30. package/lib/edge/image-eebfcbac.cjs +17 -0
  31. package/lib/edge/{img-b91cb4fd.cjs → img-183de27d.cjs} +1 -1
  32. package/lib/edge/{img-8fc26395.js → img-75751c89.js} +1 -1
  33. package/lib/edge/index.cjs +1 -1
  34. package/lib/edge/index.mjs +1 -1
  35. package/lib/edge/init.cjs +1 -1
  36. package/lib/edge/init.mjs +1 -1
  37. package/lib/edge/{input-549f090e.js → input-27972020.js} +1 -1
  38. package/lib/edge/{input-ec7c695a.cjs → input-fd18a67d.cjs} +1 -1
  39. package/lib/edge/{select-6a5a28ac.js → select-60ff549c.js} +1 -1
  40. package/lib/edge/{select-3ffa9294.cjs → select-6ea0d59f.cjs} +1 -1
  41. package/lib/edge/server-entry-4133a544.cjs +2 -0
  42. package/lib/edge/server-entry-feff6177.js +689 -0
  43. package/lib/edge/server-entry.cjs +1 -1
  44. package/lib/edge/server-entry.mjs +1 -1
  45. package/lib/edge/{slot-40de071b.js → slot-2347377e.js} +12 -11
  46. package/lib/edge/slot-a4509cae.cjs +1 -0
  47. package/lib/edge/{symbol-76e76298.cjs → symbol-98650b06.cjs} +1 -1
  48. package/lib/edge/{symbol-e6515a5f.js → symbol-dcef0d8e.js} +2 -2
  49. package/lib/edge/{tabs-b75be82d.js → tabs-0784574b.js} +10 -9
  50. package/lib/edge/tabs-4c131e17.cjs +1 -0
  51. package/lib/edge/text-1c1986aa.cjs +1 -0
  52. package/lib/edge/text-6f7cbc35.js +38 -0
  53. package/lib/node/blocks-exports.cjs +16 -16
  54. package/lib/node/blocks-exports.mjs +255 -233
  55. package/lib/node/index.cjs +1 -1
  56. package/lib/node/index.mjs +2 -2
  57. package/lib/node/init.cjs +1 -1
  58. package/lib/node/init.mjs +2 -2
  59. package/lib/node/{node-runtime-0e37d6f7.cjs → node-runtime-4978bc21.cjs} +2 -2
  60. package/lib/node/{node-runtime-0f3a5df1.js → node-runtime-ce5c71e5.js} +3 -2
  61. package/lib/node/server-entry-0c6c220c.js +688 -0
  62. package/lib/node/server-entry-7e145817.cjs +2 -0
  63. package/lib/node/server-entry.cjs +1 -1
  64. package/lib/node/server-entry.mjs +1 -1
  65. package/package.json +1 -1
  66. package/types/blocks/image/image.types.d.ts +2 -0
  67. package/types/blocks/symbol/symbol.types.d.ts +1 -0
  68. package/types/constants/sdk-version.d.ts +1 -1
  69. package/types/functions/register-component.d.ts +2 -2
  70. package/lib/browser/server-entry-419c051e.cjs +0 -2
  71. package/lib/browser/server-entry-825b4408.js +0 -695
  72. package/lib/edge/blocks-078044bc.cjs +0 -32
  73. package/lib/edge/blocks-f55c7d3e.js +0 -3418
  74. package/lib/edge/columns-354bf349.cjs +0 -28
  75. package/lib/edge/content-variants-89a9389a.cjs +0 -134
  76. package/lib/edge/form-f2d2c2bf.cjs +0 -1
  77. package/lib/edge/image-344ddbb0.cjs +0 -17
  78. package/lib/edge/server-entry-966ac144.cjs +0 -2
  79. package/lib/edge/server-entry-d2020acf.js +0 -695
  80. package/lib/edge/slot-8b27e15e.cjs +0 -1
  81. package/lib/edge/tabs-9c5af0ec.cjs +0 -1
  82. package/lib/edge/text-5915f038.js +0 -17
  83. package/lib/edge/text-e6dbb721.cjs +0 -1
  84. package/lib/node/server-entry-5ebd1c9b.js +0 -695
  85. package/lib/node/server-entry-8002325b.cjs +0 -2
@@ -0,0 +1,688 @@
1
+ const v = "react", b = "[Builder.io]: ", f = {
2
+ log: (...t) => console.log(b, ...t),
3
+ error: (...t) => console.error(b, ...t),
4
+ warn: (...t) => console.warn(b, ...t),
5
+ debug: (...t) => console.debug(b, ...t)
6
+ };
7
+ function c() {
8
+ return typeof window != "undefined" && typeof document != "undefined";
9
+ }
10
+ const q = (t) => {
11
+ const e = {};
12
+ return t.forEach((n, r) => {
13
+ e[r] = n;
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() {
17
+ return c() && window.self !== window.top;
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.
21
+ V(t || window.location.search).indexOf("builder.frameEditing=") !== -1;
22
+ }
23
+ const Z = () => {
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
+ }, tt = () => typeof navigator == "object" && navigator.userAgent || "", et = () => {
30
+ const t = tt(), 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 = Z();
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
+ }, m = (t) => t != null, nt = (t) => {
56
+ if (t === "localhost" || t === "127.0.0.1")
57
+ return t;
58
+ const e = t.split(".");
59
+ return e.length > 2 ? e.slice(1).join(".") : t;
60
+ }, U = ({
61
+ name: t,
62
+ canTrack: e
63
+ }) => {
64
+ var n;
65
+ try {
66
+ return e ? (n = document.cookie.split("; ").find((r) => r.startsWith(`${t}=`))) == null ? void 0 : n.split("=")[1] : void 0;
67
+ } catch (r) {
68
+ f.warn("[COOKIE] GET error: ", (r == null ? void 0 : r.message) || r);
69
+ return;
70
+ }
71
+ }, M = async (t) => U(t), rt = (t) => t.map(([e, n]) => n ? `${e}=${n}` : e).filter(m).join("; "), ot = [["secure", ""], ["SameSite", "None"]], st = ({
72
+ name: t,
73
+ value: e,
74
+ expires: n
75
+ }) => {
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 ({
79
+ name: t,
80
+ value: e,
81
+ expires: n,
82
+ canTrack: r
83
+ }) => {
84
+ try {
85
+ if (!r)
86
+ return;
87
+ const o = st({
88
+ name: t,
89
+ value: e,
90
+ expires: n
91
+ });
92
+ document.cookie = o;
93
+ } catch (o) {
94
+ f.warn("[COOKIE] SET error: ", (o == null ? void 0 : o.message) || o);
95
+ }
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
+ };
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() {
335
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(t) {
336
+ const e = Math.random() * 16 | 0;
337
+ return (t == "x" ? e : e & 3 | 8).toString(16);
338
+ });
339
+ }
340
+ function _() {
341
+ return Ot().replace(/-/g, "");
342
+ }
343
+ const $ = "builderSessionId", Ct = async ({
344
+ canTrack: t
345
+ }) => {
346
+ if (!t)
347
+ return;
348
+ const e = await M({
349
+ name: $,
350
+ canTrack: t
351
+ });
352
+ if (m(e))
353
+ return e;
354
+ {
355
+ const n = xt();
356
+ return At({
357
+ id: n,
358
+ canTrack: t
359
+ }), n;
360
+ }
361
+ }, xt = () => _(), At = ({
362
+ id: t,
363
+ canTrack: e
364
+ }) => N({
365
+ name: $,
366
+ value: t,
367
+ canTrack: e
368
+ }), G = () => c() && typeof localStorage != "undefined" ? localStorage : void 0, Tt = ({
369
+ key: t,
370
+ canTrack: e
371
+ }) => {
372
+ var n;
373
+ try {
374
+ return e ? (n = G()) == null ? void 0 : n.getItem(t) : void 0;
375
+ } catch (r) {
376
+ console.debug("[LocalStorage] GET error: ", r);
377
+ return;
378
+ }
379
+ }, Rt = ({
380
+ key: t,
381
+ canTrack: e,
382
+ value: n
383
+ }) => {
384
+ var r;
385
+ try {
386
+ e && ((r = G()) == null || r.setItem(t, n));
387
+ } catch (o) {
388
+ console.debug("[LocalStorage] SET error: ", o);
389
+ }
390
+ }, J = "builderVisitorId", Bt = ({
391
+ canTrack: t
392
+ }) => {
393
+ if (!t)
394
+ return;
395
+ const e = Tt({
396
+ key: J,
397
+ canTrack: t
398
+ });
399
+ if (m(e))
400
+ return e;
401
+ {
402
+ const n = Lt();
403
+ return Vt({
404
+ id: n,
405
+ canTrack: t
406
+ }), n;
407
+ }
408
+ }, Lt = () => _(), Vt = ({
409
+ id: t,
410
+ canTrack: e
411
+ }) => Rt({
412
+ key: J,
413
+ value: t,
414
+ canTrack: e
415
+ }), Ut = async ({
416
+ canTrack: t
417
+ }) => {
418
+ if (!t)
419
+ return {
420
+ visitorId: void 0,
421
+ sessionId: void 0
422
+ };
423
+ const e = await Ct({
424
+ canTrack: t
425
+ }), n = Bt({
426
+ canTrack: t
427
+ });
428
+ return {
429
+ sessionId: e,
430
+ visitorId: n
431
+ };
432
+ }, Mt = async ({
433
+ type: t,
434
+ canTrack: e,
435
+ apiKey: n,
436
+ metadata: r,
437
+ ...o
438
+ }) => ({
439
+ type: t,
440
+ data: {
441
+ ...o,
442
+ metadata: {
443
+ url: location.href,
444
+ ...r
445
+ },
446
+ ...await Ut({
447
+ canTrack: e
448
+ }),
449
+ userAttributes: et(),
450
+ ownerId: n
451
+ }
452
+ });
453
+ async function Nt(t) {
454
+ if (!t.apiKey) {
455
+ f.error("Missing API key for track call. Please provide your API key.");
456
+ return;
457
+ }
458
+ if (t.canTrack && !Y() && (c() || v === "reactNative"))
459
+ return fetch("https://cdn.builder.io/api/v1/track", {
460
+ method: "POST",
461
+ body: JSON.stringify({
462
+ events: [await Mt(t)]
463
+ }),
464
+ headers: {
465
+ "content-type": "application/json"
466
+ },
467
+ mode: "cors"
468
+ }).catch((e) => {
469
+ console.error("Failed to track: ", e);
470
+ });
471
+ }
472
+ const Jt = (t) => Nt({
473
+ ...t,
474
+ canTrack: !0
475
+ }), Ft = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
476
+ function z(t, e) {
477
+ if (!e.origin.startsWith("http") && !e.origin.startsWith("https"))
478
+ return !1;
479
+ 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;
481
+ }
482
+ const jt = "2.0.5", 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", {
502
+ name: "_default",
503
+ default: !0,
504
+ items: [{
505
+ name: "Box"
506
+ }, {
507
+ name: "Text"
508
+ }, {
509
+ name: "Image"
510
+ }, {
511
+ name: "Columns"
512
+ }, {
513
+ name: "Core:Section"
514
+ }, {
515
+ name: "Core:Button"
516
+ }, {
517
+ name: "Embed"
518
+ }, {
519
+ name: "Custom Code"
520
+ }]
521
+ });
522
+ };
523
+ let R = !1;
524
+ const Kt = (t = {}) => {
525
+ var e, n;
526
+ R || (R = !0, c() && ((e = window.parent) == null || e.postMessage({
527
+ type: "builder.sdkInfo",
528
+ data: {
529
+ target: v,
530
+ version: jt,
531
+ supportsPatchUpdates: !1,
532
+ // Supports builder-model="..." attribute which is needed to
533
+ // scope our '+ add block' button styling
534
+ supportsAddBlockScoping: !0,
535
+ supportsCustomBreakpoints: !0
536
+ }
537
+ }, "*"), (n = window.parent) == null || n.postMessage({
538
+ type: "builder.updateContent",
539
+ data: {
540
+ options: t
541
+ }
542
+ }, "*"), window.addEventListener("message", (r) => {
543
+ var s, a;
544
+ if (!z(t.trustedHosts, r))
545
+ return;
546
+ const {
547
+ data: o
548
+ } = r;
549
+ if (o != null && o.type)
550
+ switch (o.type) {
551
+ case "builder.evaluate": {
552
+ const d = o.data.text, y = o.data.arguments || [], p = o.data.id, I = new Function(d);
553
+ let u, h = null;
554
+ try {
555
+ u = I.apply(null, y);
556
+ } catch (g) {
557
+ h = g;
558
+ }
559
+ h ? (s = window.parent) == null || s.postMessage({
560
+ type: "builder.evaluateError",
561
+ data: {
562
+ id: p,
563
+ error: h.message
564
+ }
565
+ }, "*") : u && typeof u.then == "function" ? u.then((g) => {
566
+ var w;
567
+ (w = window.parent) == null || w.postMessage({
568
+ type: "builder.evaluateResult",
569
+ data: {
570
+ id: p,
571
+ result: g
572
+ }
573
+ }, "*");
574
+ }).catch(console.error) : (a = window.parent) == null || a.postMessage({
575
+ type: "builder.evaluateResult",
576
+ data: {
577
+ result: u,
578
+ id: p
579
+ }
580
+ }, "*");
581
+ break;
582
+ }
583
+ }
584
+ })));
585
+ }, Wt = ({
586
+ model: t,
587
+ trustedHosts: e,
588
+ callbacks: n
589
+ }) => (r) => {
590
+ if (!z(e, r))
591
+ return;
592
+ const {
593
+ data: o
594
+ } = r;
595
+ if (o)
596
+ switch (o.type) {
597
+ case "builder.configureSdk": {
598
+ n.configureSdk(o.data);
599
+ break;
600
+ }
601
+ case "builder.triggerAnimation": {
602
+ n.animation(o.data);
603
+ break;
604
+ }
605
+ case "builder.contentUpdate": {
606
+ const s = o.data, a = s.key || s.alias || s.entry || s.modelName, d = s.data;
607
+ a === t && n.contentUpdate(d);
608
+ break;
609
+ }
610
+ }
611
+ }, Ht = (t, e, n) => {
612
+ if (!c)
613
+ return f.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server."), () => {
614
+ };
615
+ Kt();
616
+ const r = Wt({
617
+ callbacks: {
618
+ contentUpdate: e,
619
+ animation: () => {
620
+ },
621
+ configureSdk: () => {
622
+ }
623
+ },
624
+ model: t,
625
+ trustedHosts: n == null ? void 0 : n.trustedHosts
626
+ });
627
+ return window.addEventListener("message", r), () => {
628
+ window.removeEventListener("message", r);
629
+ };
630
+ }, B = {};
631
+ function Xt(t) {
632
+ if (c()) {
633
+ Object.assign(B, t);
634
+ const e = {
635
+ type: "builder.settingsChange",
636
+ data: B
637
+ };
638
+ parent.postMessage(e, "*");
639
+ }
640
+ }
641
+ const qt = async (t) => {
642
+ var r, o, s;
643
+ const e = t.path || ((r = t.url) == null ? void 0 : r.pathname) || ((o = t.userAttributes) == null ? void 0 : o.urlPath), n = {
644
+ ...t,
645
+ apiKey: t.apiKey,
646
+ model: t.model || "page",
647
+ userAttributes: {
648
+ ...t.userAttributes,
649
+ ...e ? {
650
+ urlPath: e
651
+ } : {}
652
+ },
653
+ options: W(t.searchParams || ((s = t.url) == null ? void 0 : s.searchParams) || t.options)
654
+ };
655
+ return {
656
+ apiKey: n.apiKey,
657
+ model: n.model,
658
+ content: await It(n)
659
+ };
660
+ };
661
+ export {
662
+ b as MSG_PREFIX,
663
+ v as TARGET,
664
+ Et as _processContentResult,
665
+ Nt as _track,
666
+ m as checkIsDefined,
667
+ Wt as createEditorListener,
668
+ $t as createRegisterComponentMessage,
669
+ yt as fetch,
670
+ 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,
677
+ c as isBrowser,
678
+ Y as isEditing,
679
+ Gt as isPreviewing,
680
+ f as logger,
681
+ Dt as register,
682
+ zt as registerInsertMenu,
683
+ gt as serializeComponentInfo,
684
+ Xt as setEditorSettings,
685
+ Kt as setupBrowserForEditing,
686
+ Ht as subscribeToEditor,
687
+ Jt as track
688
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";const I="react",b="[Builder.io]: ",d={log:(...e)=>console.log(b,...e),error:(...e)=>console.error(b,...e),warn:(...e)=>console.warn(b,...e),debug:(...e)=>console.debug(b,...e)};function c(){return typeof window!="undefined"&&typeof document!="undefined"}const ce=e=>{const t={};return e.forEach((n,r)=>{t[r]=n}),t},V=e=>e instanceof URLSearchParams?ce(e):e,M=e=>typeof e=="string"?e:e instanceof URLSearchParams?e.toString():new URLSearchParams(e).toString();function ue(){return c()&&window.self!==window.top}function U(e){return ue()&&M(e||window.location.search).indexOf("builder.frameEditing=")!==-1}const de=()=>{if(c()){const e=new URL(location.href);return e.pathname===""&&(e.pathname="/"),e}else return console.warn("Cannot get location for tracking in non-browser environment"),null},le=()=>typeof navigator=="object"&&navigator.userAgent||"",F=()=>{const e=le(),t={Android(){return e.match(/Android/i)},BlackBerry(){return e.match(/BlackBerry/i)},iOS(){return e.match(/iPhone|iPod/i)},Opera(){return e.match(/Opera Mini/i)},Windows(){return e.match(/IEMobile/i)||e.match(/WPDesktop/i)},any(){return t.Android()||t.BlackBerry()||t.iOS()||t.Opera()||t.Windows()||I==="reactNative"}},n=e.match(/Tablet|iPad/i),r=de();return{urlPath:r==null?void 0:r.pathname,host:(r==null?void 0:r.host)||(r==null?void 0:r.hostname),device:n?"tablet":t.any()?"mobile":"desktop"}},p=e=>e!=null,fe=e=>{if(e==="localhost"||e==="127.0.0.1")return e;const t=e.split(".");return t.length>2?t.slice(1).join("."):e},N=({name:e,canTrack:t})=>{var n;try{return t?(n=document.cookie.split("; ").find(r=>r.startsWith(`${e}=`)))==null?void 0:n.split("=")[1]:void 0}catch(r){d.warn("[COOKIE] GET error: ",(r==null?void 0:r.message)||r);return}},D=async e=>N(e),ge=e=>e.map(([t,n])=>n?`${t}=${n}`:t).filter(p).join("; "),he=[["secure",""],["SameSite","None"]],pe=({name:e,value:t,expires:n})=>{const o=(c()?location.protocol==="https:":!0)?he:[[]],s=n?[["expires",n.toUTCString()]]:[[]],a=[[e,t],...s,["path","/"],["domain",fe(window.location.hostname)],...o];return ge(a)},j=async({name:e,value:t,expires:n,canTrack:r})=>{try{if(!r)return;const o=pe({name:e,value:t,expires:n});document.cookie=o}catch(o){d.warn("[COOKIE] SET error: ",(o==null?void 0:o.message)||o)}},me="builder.tests",k=e=>`${me}.${e}`,ye=({contentId:e})=>D({name:k(e),canTrack:!0}),Se=({contentId:e})=>N({name:k(e),canTrack:!0}),we=({contentId:e,value:t})=>j({name:k(e),value:t,canTrack:!0}),K=e=>p(e.id)&&p(e.variations)&&Object.keys(e.variations).length>0,be=({id:e,variations:t})=>{var o;let n=0;const r=Math.random();for(const s in t){const a=(o=t[s])==null?void 0:o.testRatio;if(n+=a,r<n)return s}return e},_=e=>{const t=be(e);return we({contentId:e.id,value:t}).catch(n=>{d.error("could not store A/B test variation: ",n)}),t},W=({item:e,testGroupId:t})=>{const n=e.variations[t];return t===e.id||!n?{testVariationId:e.id,testVariationName:"Default"}:{data:n.data,testVariationId:n.id,testVariationName:n.name||(n.id===e.id?"Default":"")}},Ie=({item:e,canTrack:t})=>{if(!t)return e;if(!e)return;if(!K(e))return e;const n=Se({contentId:e.id})||_({variations:e.variations,id:e.id}),r=W({item:e,testGroupId:n});return{...e,...r}},ve=async({item:e,canTrack:t})=>{if(!t||!K(e))return e;const r=await ye({contentId:e.id})||_({variations:e.variations,id:e.id}),o=W({item:e,testGroupId:r});return{...e,...o}},$=e=>p(e)?e:!0,Ee=e=>({type:"builder.registerComponent",data:G(e)}),ke=e=>{const t=e.toString().trim();return`return (${!t.startsWith("function")&&!t.startsWith("(")?"function ":""}${t}).apply(this, arguments)`};function G(e){return JSON.parse(JSON.stringify(e,(t,n)=>typeof n=="function"?ke(n):n))}function Pe(){return typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:globalThis}function Ce(){const e=Pe().fetch;if(typeof e=="undefined")throw console.warn(`Builder SDK could not find a global fetch function. Make sure you have a polyfill for fetch in your project.
2
+ For more information, read https://github.com/BuilderIO/this-package-uses-fetch`),new Error("Builder SDK could not find a global `fetch` function");return e}const z=Ce();function E(e,t=null,n="."){return Object.keys(e).reduce((r,o)=>{const s=e[o],a=[t,o].filter(Boolean).join(n);return[typeof s=="object",s!==null,!(Array.isArray(s)&&s.length===0)].every(Boolean)?{...r,...E(s,a,n)}:{...r,[a]:s}},{})}function J(e,t,n={}){for(const r in e){const o=e[r],s=t?t+"."+r:r;o&&typeof o=="object"&&!Array.isArray(o)&&!Object.keys(o).find(a=>a.startsWith("$"))?J(o,s,n):n[s]=o}return n}const Oe="v3",T="builder.",Ae="options.",P=e=>{if(!e)return{};const t=V(e),n={};return Object.keys(t).forEach(r=>{if(r.startsWith(T)){const o=r.replace(T,"").replace(Ae,"");n[o]=t[r]}}),n},Te=()=>{if(!c())return{};const e=new URLSearchParams(window.location.search);return P(e)},x=e=>typeof e=="number"&&!isNaN(e)&&e>=0,C=e=>{const{limit:t=30,userAttributes:n,query:r,model:o,apiKey:s,enrich:a,locale:l,apiVersion:y=Oe,fields:m,omit:v,offset:u,cacheSeconds:g,staleCacheSeconds:h,sort:S,includeUnpublished:O}=e;if(!s)throw new Error("Missing API key");if(!["v3"].includes(y))throw new Error(`Invalid apiVersion: expected 'v3', received '${y}'`);const ie=t!==1,i=new URL(`https://cdn.builder.io/api/${y}/content/${o}`);if(i.searchParams.set("apiKey",s),i.searchParams.set("limit",String(t)),i.searchParams.set("noTraverse",String(ie)),i.searchParams.set("includeRefs",String(!0)),l&&i.searchParams.set("locale",l),a&&i.searchParams.set("enrich",String(a)),i.searchParams.set("omit",v||"meta.componentsUsed"),m&&i.searchParams.set("fields",m),Number.isFinite(u)&&u>-1&&i.searchParams.set("offset",String(Math.floor(u))),typeof O=="boolean"&&i.searchParams.set("includeUnpublished",String(O)),g&&x(g)&&i.searchParams.set("cacheSeconds",String(g)),h&&x(h)&&i.searchParams.set("staleCacheSeconds",String(h)),S){const f=E({sort:S});for(const w in f)i.searchParams.set(w,JSON.stringify(f[w]))}const ae={...Te(),...V(e.options||{})},A=E(ae);for(const f in A)i.searchParams.set(f,String(A[f]));if(n&&i.searchParams.set("userAttributes",JSON.stringify(n)),r){const f=J({query:r});for(const w in f)i.searchParams.set(w,JSON.stringify(f[w]))}return i},xe=e=>"results"in e;async function H(e){const t=await q({...e,limit:1});return t&&t[0]||null}const Re=async e=>{var s;const t=C(e);return await(await((s=e.fetch)!=null?s:z)(t.href,e.fetchOptions)).json()},X=async(e,t,n=C(e))=>{const r=$(e.canTrack);if(n.search.includes("preview="),!r||!(c()||I==="reactNative"))return t.results;try{const o=[];for(const s of t.results)o.push(await ve({item:s,canTrack:r}));t.results=o}catch(o){d.error("Could not process A/B tests. ",o)}return t.results};async function q(e){try{const t=C(e),n=await Re(e);return xe(n)?X(e,n):(d.error("Error fetching data. ",{url:t,content:n,options:e}),null)}catch(t){return d.error("Error fetching data. ",t),null}}function Be(e){const t=e||(c()?window.location.search:void 0);return t?M(t).indexOf("builder.preview=")!==-1:!1}function Le(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){const t=Math.random()*16|0;return(e=="x"?t:t&3|8).toString(16)})}function Q(){return Le().replace(/-/g,"")}const Y="builderSessionId",Ve=async({canTrack:e})=>{if(!e)return;const t=await D({name:Y,canTrack:e});if(p(t))return t;{const n=Me();return Ue({id:n,canTrack:e}),n}},Me=()=>Q(),Ue=({id:e,canTrack:t})=>j({name:Y,value:e,canTrack:t}),Z=()=>c()&&typeof localStorage!="undefined"?localStorage:void 0,Fe=({key:e,canTrack:t})=>{var n;try{return t?(n=Z())==null?void 0:n.getItem(e):void 0}catch(r){console.debug("[LocalStorage] GET error: ",r);return}},Ne=({key:e,canTrack:t,value:n})=>{var r;try{t&&((r=Z())==null||r.setItem(e,n))}catch(o){console.debug("[LocalStorage] SET error: ",o)}},ee="builderVisitorId",De=({canTrack:e})=>{if(!e)return;const t=Fe({key:ee,canTrack:e});if(p(t))return t;{const n=je();return Ke({id:n,canTrack:e}),n}},je=()=>Q(),Ke=({id:e,canTrack:t})=>Ne({key:ee,value:e,canTrack:t}),_e=async({canTrack:e})=>{if(!e)return{visitorId:void 0,sessionId:void 0};const t=await Ve({canTrack:e}),n=De({canTrack:e});return{sessionId:t,visitorId:n}},We=async({type:e,canTrack:t,apiKey:n,metadata:r,...o})=>({type:e,data:{...o,metadata:{url:location.href,...r},...await _e({canTrack:t}),userAttributes:F(),ownerId:n}});async function te(e){if(!e.apiKey){d.error("Missing API key for track call. Please provide your API key.");return}if(e.canTrack&&!U()&&(c()||I==="reactNative"))return fetch("https://cdn.builder.io/api/v1/track",{method:"POST",body:JSON.stringify({events:[await We(e)]}),headers:{"content-type":"application/json"},mode:"cors"}).catch(t=>{console.error("Failed to track: ",t)})}const $e=e=>te({...e,canTrack:!0}),Ge=["*.beta.builder.io","beta.builder.io","builder.io","localhost","qa.builder.io"];function ne(e,t){if(!t.origin.startsWith("http")&&!t.origin.startsWith("https"))return!1;const n=new URL(t.origin),r=n.hostname;return(e||Ge).findIndex(o=>o.startsWith("*.")?r.endsWith(o.slice(1)):o===r)>-1}const ze="2.0.5",R={};function re(e,t){let n=R[e];if(n||(n=R[e]=[]),n.push(t),c()){const r={type:"builder.register",data:{type:e,info:t}};try{parent.postMessage(r,"*"),parent!==window&&window.postMessage(r,"*")}catch(o){console.debug("Could not postmessage",o)}}}const Je=()=>{re("insertMenu",{name:"_default",default:!0,items:[{name:"Box"},{name:"Text"},{name:"Image"},{name:"Columns"},{name:"Core:Section"},{name:"Core:Button"},{name:"Embed"},{name:"Custom Code"}]})};let B=!1;const oe=(e={})=>{var t,n;B||(B=!0,c()&&((t=window.parent)==null||t.postMessage({type:"builder.sdkInfo",data:{target:I,version:ze,supportsPatchUpdates:!1,supportsAddBlockScoping:!0,supportsCustomBreakpoints:!0}},"*"),(n=window.parent)==null||n.postMessage({type:"builder.updateContent",data:{options:e}},"*"),window.addEventListener("message",r=>{var s,a;if(!ne(e.trustedHosts,r))return;const{data:o}=r;if(o!=null&&o.type)switch(o.type){case"builder.evaluate":{const l=o.data.text,y=o.data.arguments||[],m=o.data.id,v=new Function(l);let u,g=null;try{u=v.apply(null,y)}catch(h){g=h}g?(s=window.parent)==null||s.postMessage({type:"builder.evaluateError",data:{id:m,error:g.message}},"*"):u&&typeof u.then=="function"?u.then(h=>{var S;(S=window.parent)==null||S.postMessage({type:"builder.evaluateResult",data:{id:m,result:h}},"*")}).catch(console.error):(a=window.parent)==null||a.postMessage({type:"builder.evaluateResult",data:{result:u,id:m}},"*");break}}})))},se=({model:e,trustedHosts:t,callbacks:n})=>r=>{if(!ne(t,r))return;const{data:o}=r;if(o)switch(o.type){case"builder.configureSdk":{n.configureSdk(o.data);break}case"builder.triggerAnimation":{n.animation(o.data);break}case"builder.contentUpdate":{const s=o.data,a=s.key||s.alias||s.entry||s.modelName,l=s.data;a===e&&n.contentUpdate(l);break}}},He=(e,t,n)=>{if(!c)return d.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server."),()=>{};oe();const r=se({callbacks:{contentUpdate:t,animation:()=>{},configureSdk:()=>{}},model:e,trustedHosts:n==null?void 0:n.trustedHosts});return window.addEventListener("message",r),()=>{window.removeEventListener("message",r)}},L={};function Xe(e){if(c()){Object.assign(L,e);const t={type:"builder.settingsChange",data:L};parent.postMessage(t,"*")}}const qe=async e=>{var r,o,s;const t=e.path||((r=e.url)==null?void 0:r.pathname)||((o=e.userAttributes)==null?void 0:o.urlPath),n={...e,apiKey:e.apiKey,model:e.model||"page",userAttributes:{...e.userAttributes,...t?{urlPath:t}:{}},options:P(e.searchParams||((s=e.url)==null?void 0:s.searchParams)||e.options)};return{apiKey:n.apiKey,model:n.model,content:await H(n)}};exports.MSG_PREFIX=b;exports.TARGET=I;exports._processContentResult=X;exports._track=te;exports.checkIsDefined=p;exports.createEditorListener=se;exports.createRegisterComponentMessage=Ee;exports.fetch=z;exports.fetchBuilderProps=qe;exports.fetchEntries=q;exports.fetchOneEntry=H;exports.getBuilderSearchParams=P;exports.getDefaultCanTrack=$;exports.getUserAttributes=F;exports.handleABTestingSync=Ie;exports.isBrowser=c;exports.isEditing=U;exports.isPreviewing=Be;exports.logger=d;exports.register=re;exports.registerInsertMenu=Je;exports.serializeComponentInfo=G;exports.setEditorSettings=Xe;exports.setupBrowserForEditing=oe;exports.subscribeToEditor=He;exports.track=$e;