@builder.io/sdk-react-nextjs 0.7.2 → 0.7.4

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 (42) hide show
  1. package/lib/browser/USE_CLIENT_BUNDLE-6b3887b7.js +711 -0
  2. package/lib/browser/USE_CLIENT_BUNDLE-f95a196a.cjs +23 -0
  3. package/lib/{edge/USE_SERVER_BUNDLE-e0effb0f.js → browser/USE_SERVER_BUNDLE-b314d0f7.js} +1 -1
  4. package/lib/{edge/USE_SERVER_BUNDLE-ea7c665e.cjs → browser/USE_SERVER_BUNDLE-eed7792a.cjs} +1 -1
  5. package/lib/browser/{bundle-fc27d227.cjs → bundle-df55c296.cjs} +111 -19
  6. package/lib/browser/{bundle-6f6b7d63.js → bundle-fc3e7377.js} +528 -514
  7. package/lib/browser/index.cjs +1 -1
  8. package/lib/browser/index.mjs +3 -3
  9. package/lib/edge/USE_CLIENT_BUNDLE-44225d7a.cjs +23 -0
  10. package/lib/edge/USE_CLIENT_BUNDLE-a32e462e.js +711 -0
  11. package/lib/{node/USE_SERVER_BUNDLE-787d0ec8.js → edge/USE_SERVER_BUNDLE-2c9d1a5d.js} +1 -1
  12. package/lib/{node/USE_SERVER_BUNDLE-842e66c9.cjs → edge/USE_SERVER_BUNDLE-e5ab43ec.cjs} +1 -1
  13. package/lib/edge/bundle-38f08fa1.cjs +188 -0
  14. package/lib/edge/{bundle-213a8bf7.js → bundle-bef73246.js} +1516 -1502
  15. package/lib/edge/index.cjs +1 -1
  16. package/lib/edge/index.mjs +3 -3
  17. package/lib/node/USE_CLIENT_BUNDLE-539be307.cjs +23 -0
  18. package/lib/node/USE_CLIENT_BUNDLE-a5c6399c.js +711 -0
  19. package/lib/{browser/USE_SERVER_BUNDLE-ea1618f4.js → node/USE_SERVER_BUNDLE-21bf3ffc.js} +1 -1
  20. package/lib/{browser/USE_SERVER_BUNDLE-4341bf5c.cjs → node/USE_SERVER_BUNDLE-7f4ba7e9.cjs} +1 -1
  21. package/lib/node/{bundle-fb3490a6.js → bundle-74479d5d.js} +297 -283
  22. package/lib/node/{bundle-df78531d.cjs → bundle-f7863fb3.cjs} +110 -18
  23. package/lib/node/index.cjs +1 -1
  24. package/lib/node/index.mjs +3 -3
  25. package/package.json +8 -1
  26. package/types/cjs/blocks/video/video.d.ts +4 -0
  27. package/types/cjs/components/content/content.types.d.ts +0 -4
  28. package/types/cjs/components/content-variants/helpers.d.ts +3 -3
  29. package/types/cjs/components/content-variants/inlined-fns.d.ts +14 -0
  30. package/types/cjs/constants/sdk-version.d.ts +1 -1
  31. package/types/esm/blocks/video/video.d.ts +4 -0
  32. package/types/esm/components/content/content.types.d.ts +0 -4
  33. package/types/esm/components/content-variants/helpers.d.ts +3 -3
  34. package/types/esm/components/content-variants/inlined-fns.d.ts +14 -0
  35. package/types/esm/constants/sdk-version.d.ts +1 -1
  36. package/lib/browser/USE_CLIENT_BUNDLE-0e3e24e7.js +0 -657
  37. package/lib/browser/USE_CLIENT_BUNDLE-727780ee.cjs +0 -23
  38. package/lib/edge/USE_CLIENT_BUNDLE-372b4c60.js +0 -657
  39. package/lib/edge/USE_CLIENT_BUNDLE-f1bfb292.cjs +0 -23
  40. package/lib/edge/bundle-0fb39c43.cjs +0 -96
  41. package/lib/node/USE_CLIENT_BUNDLE-bdbc178a.cjs +0 -23
  42. package/lib/node/USE_CLIENT_BUNDLE-c6d9e08c.js +0 -657
@@ -24,7 +24,7 @@ export declare const getVariants: (content: Nullable<BuilderContent>) => {
24
24
  breakpoints?: import("../../types/builder-content.js").Breakpoints;
25
25
  };
26
26
  }[];
27
- export declare const checkShouldRunVariants: ({ canTrack, content }: {
27
+ export declare const checkShouldRenderVariants: ({ canTrack, content }: {
28
28
  canTrack: Nullable<boolean>;
29
29
  content: Nullable<BuilderContent>;
30
30
  }) => boolean;
@@ -33,8 +33,8 @@ type VariantData = {
33
33
  testRatio?: number;
34
34
  };
35
35
  export declare const getScriptString: () => string;
36
- export declare const getVariantsScriptString: (variants: VariantData[], contentId: string) => string;
37
- export declare const getRenderContentScriptString: ({ contentId, variationId }: {
36
+ export declare const getUpdateCookieAndStylesScript: (variants: VariantData[], contentId: string) => string;
37
+ export declare const getUpdateVariantVisibilityScript: ({ contentId, variationId }: {
38
38
  variationId: string;
39
39
  contentId: string;
40
40
  }) => string;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * WARNING: This file contains functions that get stringified and inlined into the HTML at build-time.
3
+ * They cannot import anything.
4
+ */
5
+ /**
6
+ * For more information on how this works,
7
+ * see our [SSR A/B Test Docs](https://github.com/BuilderIO/builder/tree/main/packages/sdks/src/SSR_AB_TEST.md)
8
+ */
9
+ /**
10
+ * For more information on how this works,
11
+ * see our [SSR A/B Test Docs](https://github.com/BuilderIO/builder/tree/main/packages/sdks/src/SSR_AB_TEST.md)
12
+ */
13
+ export declare const UPDATE_COOKIES_AND_STYLES_SCRIPT = "function updateCookiesAndStyles(contentId, variants, isHydrationTarget) {\n function getAndSetVariantId() {\n function setCookie(name, value, days) {\n let expires = '';\n if (days) {\n const date = new Date();\n date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);\n expires = '; expires=' + date.toUTCString();\n }\n document.cookie = name + '=' + (value || '') + expires + '; path=/' + '; Secure; SameSite=None';\n }\n function getCookie(name) {\n const nameEQ = name + '=';\n const ca = document.cookie.split(';');\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i];\n while (c.charAt(0) === ' ') c = c.substring(1, c.length);\n if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);\n }\n return null;\n }\n const cookieName = `builder.tests.${contentId}`;\n const variantInCookie = getCookie(cookieName);\n const availableIDs = variants.map(vr => vr.id).concat(contentId);\n if (variantInCookie && availableIDs.includes(variantInCookie)) {\n return variantInCookie;\n }\n let n = 0;\n const random = Math.random();\n for (let i = 0; i < variants.length; i++) {\n const variant = variants[i];\n const testRatio = variant.testRatio;\n n += testRatio;\n if (random < n) {\n setCookie(cookieName, variant.id);\n return variant.id;\n }\n }\n setCookie(cookieName, contentId);\n return contentId;\n }\n const winningVariantId = getAndSetVariantId();\n const styleEl = document.currentScript?.previousElementSibling;\n if (isHydrationTarget) {\n styleEl.remove();\n const thisScriptEl = document.currentScript;\n thisScriptEl?.remove();\n } else {\n const newStyleStr = variants.concat({\n id: contentId\n }).filter(variant => variant.id !== winningVariantId).map(value => {\n return `.variant-${value.id} { display: none; }\n `;\n }).join('');\n styleEl.innerHTML = newStyleStr;\n }\n}";
14
+ export declare const UPDATE_VARIANT_VISIBILITY_SCRIPT = "function updateVariantVisibility(variantContentId, defaultContentId, isHydrationTarget) {\n if (!navigator.cookieEnabled) {\n return;\n }\n function getCookie(name) {\n const nameEQ = name + '=';\n const ca = document.cookie.split(';');\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i];\n while (c.charAt(0) === ' ') c = c.substring(1, c.length);\n if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);\n }\n return null;\n }\n const cookieName = `builder.tests.${defaultContentId}`;\n const winningVariant = getCookie(cookieName);\n const parentDiv = document.currentScript?.parentElement;\n const isDefaultContent = variantContentId === defaultContentId;\n const isWinningVariant = winningVariant === variantContentId;\n if (isWinningVariant && !isDefaultContent) {\n parentDiv?.removeAttribute('hidden');\n parentDiv?.removeAttribute('aria-hidden');\n } else if (!isWinningVariant && isDefaultContent) {\n parentDiv?.setAttribute('hidden', 'true');\n parentDiv?.setAttribute('aria-hidden', 'true');\n }\n if (isHydrationTarget) {\n if (!isWinningVariant) {\n parentDiv?.remove();\n }\n const thisScriptEl = document.currentScript;\n thisScriptEl?.remove();\n }\n return;\n}";
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.7.2";
1
+ export declare const SDK_VERSION = "0.7.4";
@@ -1,657 +0,0 @@
1
- "use client";
2
- import { jsxs as w, Fragment as b, jsx as c } from "react/jsx-runtime";
3
- import { g as T, a as N, i as E, b as R, c as G, d as P, e as W, _ as A, f as $, l as Q, h as D, j as X, k as Y, r as Z, s as p, m as ee, n as te, o as ne } from "./bundle-6f6b7d63.js";
4
- import { useRef as j, useState as y, useEffect as x, createContext as ie, createElement as ae } from "react";
5
- import { p as ce } from "./USE_SERVER_BUNDLE-ea1618f4.js";
6
- import { useRouter as re } from "next/navigation";
7
- function be(e) {
8
- return /* @__PURE__ */ w(b, { children: [
9
- e.link ? /* @__PURE__ */ c(b, { children: /* @__PURE__ */ c(
10
- "a",
11
- {
12
- ...e.attributes,
13
- href: e.link,
14
- target: e.openLinkInNewTab ? "_blank" : void 0,
15
- role: "button",
16
- children: e.text
17
- }
18
- ) }) : /* @__PURE__ */ c(b, { children: /* @__PURE__ */ c(
19
- "button",
20
- {
21
- ...e.attributes,
22
- style: e.attributes.style,
23
- className: e.attributes.className + " button-5294b10c",
24
- children: e.text
25
- }
26
- ) }),
27
- /* @__PURE__ */ c("style", { children: `.button-5294b10c {
28
- all: unset;
29
- }` })
30
- ] });
31
- }
32
- function ge(e) {
33
- return /* @__PURE__ */ w(b, { children: [
34
- " ",
35
- e.hasChildren ? /* @__PURE__ */ c(b, { children: /* @__PURE__ */ w(
36
- e.Wrapper,
37
- {
38
- ...T({
39
- block: e.block,
40
- context: e.context
41
- }),
42
- ...N({
43
- block: e.block,
44
- rootState: e.context.rootState,
45
- rootSetState: e.context.rootSetState,
46
- localState: e.context.localState,
47
- context: e.context.context,
48
- stripPrefix: !0
49
- }),
50
- children: [
51
- " ",
52
- e.children,
53
- " "
54
- ]
55
- }
56
- ) }) : /* @__PURE__ */ c(b, { children: /* @__PURE__ */ c(
57
- e.Wrapper,
58
- {
59
- ...T({
60
- block: e.block,
61
- context: e.context
62
- }),
63
- ...N({
64
- block: e.block,
65
- rootState: e.context.rootState,
66
- rootSetState: e.context.rootSetState,
67
- localState: e.context.localState,
68
- context: e.context.context,
69
- stripPrefix: !0
70
- })
71
- }
72
- ) }),
73
- " "
74
- ] });
75
- }
76
- function he(e) {
77
- return /* @__PURE__ */ c(
78
- e.Wrapper,
79
- {
80
- ...e.wrapperProps,
81
- attributes: {
82
- ...T({
83
- block: e.block,
84
- context: e.context
85
- }),
86
- ...N({
87
- block: e.block,
88
- rootState: e.context.rootState,
89
- rootSetState: e.context.rootSetState,
90
- localState: e.context.localState,
91
- context: e.context.context
92
- })
93
- },
94
- children: e.children
95
- }
96
- );
97
- }
98
- function fe(e) {
99
- function i() {
100
- var o;
101
- return "builder-blocks" + ((o = e.blocks) != null && o.length ? "" : " no-blocks");
102
- }
103
- function s() {
104
- var o, f;
105
- E() && !((o = e.blocks) != null && o.length) && ((f = window.parent) == null || f.postMessage(
106
- {
107
- type: "builder.clickEmptyBlocks",
108
- data: {
109
- parentElementId: e.parent,
110
- dataPath: e.path
111
- }
112
- },
113
- "*"
114
- ));
115
- }
116
- function h() {
117
- var o, f;
118
- E() && !((o = e.blocks) != null && o.length) && ((f = window.parent) == null || f.postMessage(
119
- {
120
- type: "builder.hoverEmptyBlocks",
121
- data: {
122
- parentElementId: e.parent,
123
- dataPath: e.path
124
- }
125
- },
126
- "*"
127
- ));
128
- }
129
- return /* @__PURE__ */ w(b, { children: [
130
- /* @__PURE__ */ c(
131
- "div",
132
- {
133
- className: i() + " div-02c7a115",
134
- "builder-path": e.path,
135
- "builder-parent-id": e.parent,
136
- style: e.styleProp,
137
- onClick: (o) => s(),
138
- onMouseEnter: (o) => h(),
139
- onKeyPress: (o) => s(),
140
- children: e.children
141
- }
142
- ),
143
- /* @__PURE__ */ c("style", { children: `.div-02c7a115 {
144
- display: flex;
145
- flex-direction: column;
146
- align-items: stretch;
147
- }` })
148
- ] });
149
- }
150
- function Se(e) {
151
- return /* @__PURE__ */ c("span", { children: e.children });
152
- }
153
- function xe(e) {
154
- var o, f, k, S;
155
- function i() {
156
- var g;
157
- const l = e.image || e.src;
158
- if (!l || // We can auto add srcset for cdn.builder.io and shopify
159
- // images, otherwise you can supply this prop manually
160
- !(l.match(/builder\.io/) || l.match(/cdn\.shopify\.com/)))
161
- return e.srcset;
162
- if (e.srcset && ((g = e.image) != null && g.includes("builder.io/api/v1/image"))) {
163
- if (!e.srcset.includes(e.image.split("?")[0]))
164
- return console.debug("Removed given srcset"), R(l);
165
- } else if (e.image && !e.srcset)
166
- return R(l);
167
- return R(l);
168
- }
169
- function s() {
170
- var m;
171
- return (m = i == null ? void 0 : i()) != null && m.match(/builder\.io/) && !e.noWebp ? i().replace(/\?/g, "?format=webp&") : "";
172
- }
173
- function h() {
174
- const m = {
175
- position: "absolute",
176
- height: "100%",
177
- width: "100%",
178
- left: "0px",
179
- top: "0px"
180
- };
181
- return e.aspectRatio ? m : void 0;
182
- }
183
- return /* @__PURE__ */ w(b, { children: [
184
- /* @__PURE__ */ w(b, { children: [
185
- /* @__PURE__ */ w("picture", { children: [
186
- s() ? /* @__PURE__ */ c(b, { children: /* @__PURE__ */ c("source", { type: "image/webp", srcSet: s() }) }) : null,
187
- /* @__PURE__ */ c(
188
- "img",
189
- {
190
- loading: "lazy",
191
- alt: e.altText,
192
- role: e.altText ? "presentation" : void 0,
193
- style: {
194
- objectPosition: e.backgroundPosition || "center",
195
- objectFit: e.backgroundSize || "cover",
196
- ...h()
197
- },
198
- className: "builder-image" + (e.className ? " " + e.className : "") + " img-dbab4030",
199
- src: e.image,
200
- srcSet: i(),
201
- sizes: e.sizes
202
- }
203
- )
204
- ] }),
205
- e.aspectRatio && !((f = (o = e.builderBlock) == null ? void 0 : o.children) != null && f.length && e.fitContent) ? /* @__PURE__ */ c(b, { children: /* @__PURE__ */ c(
206
- "div",
207
- {
208
- className: "builder-image-sizer div-dbab4030",
209
- style: {
210
- paddingTop: e.aspectRatio * 100 + "%"
211
- }
212
- }
213
- ) }) : null,
214
- (S = (k = e.builderBlock) == null ? void 0 : k.children) != null && S.length && e.fitContent ? /* @__PURE__ */ c(b, { children: e.children }) : null,
215
- !e.fitContent && e.children ? /* @__PURE__ */ c(b, { children: /* @__PURE__ */ c("div", { className: "div-dbab4030-2", children: e.children }) }) : null
216
- ] }),
217
- /* @__PURE__ */ c("style", { children: `.img-dbab4030 {
218
- opacity: 1;
219
- transition: opacity 0.2s ease-in-out;
220
- }.div-dbab4030 {
221
- width: 100%;
222
- pointer-events: none;
223
- font-size: 0;
224
- }.div-dbab4030-2 {
225
- display: flex;
226
- flex-direction: column;
227
- align-items: stretch;
228
- position: absolute;
229
- top: 0;
230
- left: 0;
231
- width: 100%;
232
- height: 100%;
233
- }` })
234
- ] });
235
- }
236
- function ve(e) {
237
- return /* @__PURE__ */ c(
238
- "section",
239
- {
240
- ...e.attributes,
241
- style: {
242
- width: "100%",
243
- alignSelf: "stretch",
244
- flexGrow: 1,
245
- boxSizing: "border-box",
246
- maxWidth: e.maxWidth || 1200,
247
- display: "flex",
248
- flexDirection: "column",
249
- alignItems: "stretch",
250
- marginLeft: "auto",
251
- marginRight: "auto"
252
- },
253
- children: e.children
254
- }
255
- );
256
- }
257
- function ye(e) {
258
- const i = j(null), [s, h] = y(() => []), [o, f] = y(() => []);
259
- return x(() => {
260
- var S;
261
- if (!((S = i.current) != null && S.getElementsByTagName) || typeof window > "u")
262
- return;
263
- const k = i.current.getElementsByTagName("script");
264
- for (let m = 0; m < k.length; m++) {
265
- const l = k[m];
266
- if (l.src) {
267
- if (s.includes(l.src))
268
- continue;
269
- s.push(l.src);
270
- const g = document.createElement("script");
271
- g.async = !0, g.src = l.src, document.head.appendChild(g);
272
- } else if (!l.type || [
273
- "text/javascript",
274
- "application/javascript",
275
- "application/ecmascript"
276
- ].includes(l.type)) {
277
- if (o.includes(l.innerText))
278
- continue;
279
- try {
280
- o.push(l.innerText), new Function(l.innerText)();
281
- } catch (g) {
282
- console.warn("`CustomCode`: Error running script:", g);
283
- }
284
- }
285
- }
286
- }, []), /* @__PURE__ */ c(
287
- "div",
288
- {
289
- ref: i,
290
- className: "builder-custom-code" + (e.replaceNodes ? " replace-nodes" : ""),
291
- dangerouslySetInnerHTML: { __html: e.code }
292
- }
293
- );
294
- }
295
- function ke(e) {
296
- const i = j(null), [s, h] = y(() => []), [o, f] = y(() => []), [k, S] = y(() => !1);
297
- function m() {
298
- if (!i.current || !i.current.getElementsByTagName)
299
- return;
300
- const l = i.current.getElementsByTagName("script");
301
- for (let g = 0; g < l.length; g++) {
302
- const v = l[g];
303
- if (v.src && !s.includes(v.src)) {
304
- s.push(v.src);
305
- const C = document.createElement("script");
306
- C.async = !0, C.src = v.src, document.head.appendChild(C);
307
- } else if (G(v) && !o.includes(v.innerText))
308
- try {
309
- o.push(v.innerText), new Function(v.innerText)();
310
- } catch (C) {
311
- console.warn("`Embed`: Error running script:", C);
312
- }
313
- }
314
- }
315
- return x(() => {
316
- i.current && !k && (S(!0), m());
317
- }, [i.current, k]), /* @__PURE__ */ c(
318
- "div",
319
- {
320
- className: "builder-embed",
321
- ref: i,
322
- dangerouslySetInnerHTML: { __html: e.content }
323
- }
324
- );
325
- }
326
- function Ce(e) {
327
- return /* @__PURE__ */ c(
328
- "img",
329
- {
330
- style: {
331
- objectFit: e.backgroundSize || "cover",
332
- objectPosition: e.backgroundPosition || "center"
333
- },
334
- alt: e.altText,
335
- src: e.imgSrc || e.image,
336
- ...e.attributes
337
- },
338
- E() && e.imgSrc || "default-key"
339
- );
340
- }
341
- function we(e) {
342
- var h;
343
- function i() {
344
- return {
345
- ...e.autoPlay === !0 ? {
346
- autoPlay: !0
347
- } : {},
348
- ...e.muted === !0 ? {
349
- muted: !0
350
- } : {},
351
- ...e.controls === !0 ? {
352
- controls: !0
353
- } : {},
354
- ...e.loop === !0 ? {
355
- loop: !0
356
- } : {},
357
- ...e.playsInline === !0 ? {
358
- playsInline: !0
359
- } : {}
360
- };
361
- }
362
- function s() {
363
- return {
364
- ...e.attributes,
365
- ...i()
366
- };
367
- }
368
- return /* @__PURE__ */ c(
369
- "video",
370
- {
371
- ...s(),
372
- preload: e.preload || "metadata",
373
- style: {
374
- width: "100%",
375
- height: "100%",
376
- ...(h = e.attributes) == null ? void 0 : h.style,
377
- objectFit: e.fit,
378
- objectPosition: e.position,
379
- // Hack to get object fit to work as expected and
380
- // not have the video overflow
381
- borderRadius: 1
382
- },
383
- src: e.video || "no-src",
384
- poster: e.posterImage
385
- }
386
- );
387
- }
388
- const oe = ie({
389
- content: null,
390
- context: {},
391
- localState: void 0,
392
- rootSetState() {
393
- },
394
- rootState: {},
395
- apiKey: null,
396
- apiVersion: void 0,
397
- componentInfos: {},
398
- inheritedStyles: {}
399
- });
400
- function Ee(e) {
401
- var F, M, _, q, z;
402
- const i = j(null), [s, h] = y(() => 0);
403
- function o(t) {
404
- var a, r, d, u, V;
405
- const n = {
406
- ...e.builderContextSignal.content,
407
- ...t,
408
- data: {
409
- ...(a = e.builderContextSignal.content) == null ? void 0 : a.data,
410
- ...t == null ? void 0 : t.data
411
- },
412
- meta: {
413
- ...(r = e.builderContextSignal.content) == null ? void 0 : r.meta,
414
- ...t == null ? void 0 : t.meta,
415
- breakpoints: ((d = t == null ? void 0 : t.meta) == null ? void 0 : d.breakpoints) || ((V = (u = e.builderContextSignal.content) == null ? void 0 : u.meta) == null ? void 0 : V.breakpoints)
416
- }
417
- };
418
- ce({
419
- value: n,
420
- key: n.id
421
- }).then(() => {
422
- J.refresh();
423
- });
424
- }
425
- y(() => 0);
426
- const [f, k] = y(
427
- () => !1
428
- );
429
- function S(t) {
430
- var a;
431
- const { data: n } = t;
432
- if (n)
433
- switch (n.type) {
434
- case "builder.configureSdk": {
435
- const r = n.data, { breakpoints: d, contentId: u } = r;
436
- if (!u || u !== ((a = e.builderContextSignal.content) == null ? void 0 : a.id))
437
- return;
438
- d && o({
439
- meta: {
440
- breakpoints: d
441
- }
442
- }), h(s + 1);
443
- break;
444
- }
445
- case "builder.contentUpdate": {
446
- const r = n.data, d = r.key || r.alias || r.entry || r.modelName, u = r.data;
447
- d === e.model && (o(u), h(s + 1));
448
- break;
449
- }
450
- }
451
- }
452
- function m() {
453
- var n, a;
454
- const t = (a = (n = e.builderContextSignal.content) == null ? void 0 : n.data) == null ? void 0 : a.jsCode;
455
- t && D({
456
- code: t,
457
- context: e.context || {},
458
- localState: void 0,
459
- rootState: e.builderContextSignal.rootState,
460
- rootSetState: e.builderContextSignal.rootSetState
461
- });
462
- }
463
- const [l, g] = y(() => ({})), [v, C] = y(() => !1);
464
- function U(t) {
465
- var n, a;
466
- if (e.builderContextSignal.content) {
467
- const r = (n = e.builderContextSignal.content) == null ? void 0 : n.testVariationId, d = (a = e.builderContextSignal.content) == null ? void 0 : a.id;
468
- A({
469
- type: "click",
470
- canTrack: W(e.canTrack),
471
- contentId: d,
472
- apiKey: e.apiKey,
473
- variationId: r !== d ? r : void 0,
474
- ...X(t),
475
- unique: !v
476
- });
477
- }
478
- v || C(!0);
479
- }
480
- function H(t) {
481
- return t.replace(
482
- /{{([^}]+)}}/g,
483
- (n, a) => D({
484
- code: a,
485
- context: e.context || {},
486
- localState: void 0,
487
- rootState: e.builderContextSignal.rootState,
488
- rootSetState: e.builderContextSignal.rootSetState
489
- })
490
- );
491
- }
492
- function O({ url: t, key: n }) {
493
- ne(t).then((a) => a.json()).then((a) => {
494
- var d, u;
495
- const r = {
496
- ...e.builderContextSignal.rootState,
497
- [n]: a
498
- };
499
- (u = (d = e.builderContextSignal).rootSetState) == null || u.call(d, r), l[n] = !0;
500
- }).catch((a) => {
501
- console.error("error fetching dynamic data", t, a);
502
- });
503
- }
504
- function L() {
505
- var n, a;
506
- const t = ((a = (n = e.builderContextSignal.content) == null ? void 0 : n.data) == null ? void 0 : a.httpRequests) ?? {};
507
- Object.entries(t).forEach(([r, d]) => {
508
- if (d && (!l[r] || E())) {
509
- const u = H(d);
510
- O({
511
- url: u,
512
- key: r
513
- });
514
- }
515
- });
516
- }
517
- function I() {
518
- E() && window.dispatchEvent(
519
- new CustomEvent(
520
- "builder:component:stateChange",
521
- {
522
- detail: {
523
- state: Y(e.builderContextSignal.rootState),
524
- ref: {
525
- name: e.model
526
- }
527
- }
528
- }
529
- )
530
- );
531
- }
532
- function B(t) {
533
- h(s + 1), window.addEventListener("message", S), Z(), p({
534
- ...e.locale ? {
535
- locale: e.locale
536
- } : {},
537
- ...e.includeRefs ? {
538
- includeRefs: e.includeRefs
539
- } : {},
540
- ...e.enrich ? {
541
- enrich: e.enrich
542
- } : {}
543
- }), Object.values(
544
- e.builderContextSignal.componentInfos
545
- ).forEach((n) => {
546
- var r;
547
- const a = ee(n);
548
- (r = window.parent) == null || r.postMessage(a, "*");
549
- }), window.addEventListener(
550
- "builder:component:stateChangeListenerActivated",
551
- I
552
- );
553
- }
554
- function K(t) {
555
- const n = new URL(location.href).searchParams, a = n.get("builder.preview"), r = n.get(
556
- `builder.preview.${a}`
557
- ), d = n.get("apiKey") || n.get("builder.space");
558
- a === e.model && d === e.apiKey && (!e.content || r === e.content.id) && te({
559
- model: e.model,
560
- apiKey: e.apiKey,
561
- apiVersion: e.builderContextSignal.apiVersion
562
- }).then((u) => {
563
- u && o(u);
564
- });
565
- }
566
- const J = re();
567
- return x(() => {
568
- var t;
569
- return (t = i.current) == null || t.addEventListener(
570
- "initeditingbldr",
571
- B
572
- ), () => {
573
- var n;
574
- return (n = i.current) == null ? void 0 : n.removeEventListener(
575
- "initeditingbldr",
576
- B
577
- );
578
- };
579
- }, []), x(() => {
580
- var t;
581
- return (t = i.current) == null || t.addEventListener(
582
- "initpreviewingbldr",
583
- K
584
- ), () => {
585
- var n;
586
- return (n = i.current) == null ? void 0 : n.removeEventListener(
587
- "initpreviewingbldr",
588
- K
589
- );
590
- };
591
- }, []), x(() => {
592
- var t, n;
593
- if (P()) {
594
- if (E() && i.current && i.current.dispatchEvent(new CustomEvent("initeditingbldr")), e.builderContextSignal.content && W(e.canTrack)) {
595
- const r = (t = e.builderContextSignal.content) == null ? void 0 : t.testVariationId, d = (n = e.builderContextSignal.content) == null ? void 0 : n.id, u = e.apiKey;
596
- A({
597
- type: "impression",
598
- canTrack: !0,
599
- contentId: d,
600
- apiKey: u,
601
- variationId: r !== d ? r : void 0
602
- });
603
- }
604
- $() && i.current;
605
- }
606
- }, []), x(() => {
607
- e.apiKey || Q.error(
608
- "No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop."
609
- ), m(), L(), I();
610
- }, []), x(() => {
611
- }, [e.content]), x(() => {
612
- P() && (window.removeEventListener("message", S), window.addEventListener("message", S));
613
- }, [f]), x(() => {
614
- m();
615
- }, [
616
- (M = (F = e.builderContextSignal.content) == null ? void 0 : F.data) == null ? void 0 : M.jsCode,
617
- e.builderContextSignal.rootState
618
- ]), x(() => {
619
- L();
620
- }, [(q = (_ = e.builderContextSignal.content) == null ? void 0 : _.data) == null ? void 0 : q.httpRequests]), x(() => {
621
- I();
622
- }, [e.builderContextSignal.rootState]), x(() => () => {
623
- P() && (window.removeEventListener("message", S), window.removeEventListener(
624
- "builder:component:stateChangeListenerActivated",
625
- I
626
- ));
627
- }, []), /* @__PURE__ */ c(oe.Provider, { value: e.builderContextSignal, children: e.builderContextSignal.content ? /* @__PURE__ */ c(b, { children: /* @__PURE__ */ ae(
628
- "div",
629
- {
630
- key: s,
631
- ref: i,
632
- onClick: (t) => U(t),
633
- "builder-content-id": (z = e.builderContextSignal.content) == null ? void 0 : z.id,
634
- "builder-model": e.model,
635
- ...e.showContent ? {} : {
636
- hidden: !0,
637
- "aria-hidden": !0
638
- },
639
- className: e.classNameProp
640
- },
641
- e.children
642
- ) }) : null });
643
- }
644
- export {
645
- ge as B,
646
- ye as C,
647
- ke as E,
648
- Se as F,
649
- he as I,
650
- ve as S,
651
- we as V,
652
- fe as a,
653
- be as b,
654
- xe as c,
655
- Ce as d,
656
- Ee as e
657
- };