@builder.io/sdk-react-nextjs 0.19.2 → 0.20.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.
@@ -1 +1 @@
1
- "use client";"use strict";const R=require("react/jsx-runtime"),o=require("react"),V=require("../../../context/builder.context.cjs"),j=require("../../../functions/evaluate/evaluate.cjs"),B=require("../../../functions/fast-clone.cjs"),F=require("../../../functions/get-content/index.cjs"),k=require("../../../functions/is-browser.cjs"),f=require("../../../functions/is-editing.cjs"),N=require("../../../functions/is-previewing.cjs"),O=require("../../../functions/log-fetch.cjs"),W=require("../../../functions/register-component.cjs"),y=require("../../../functions/track/index.cjs"),A=require("../../../functions/track/interaction.cjs"),P=require("../../../helpers/canTrack.cjs"),M=require("../../../helpers/cookie.cjs"),$=require("../../../helpers/preview-lru-cache/set.cjs"),z=require("../../../helpers/subscribe-to-editor.cjs"),G=require("../../../scripts/init-editing.cjs"),J=require("../../block/animator.cjs"),L=require("./enable-editor.helpers.cjs"),Q=require("./styles.helpers.cjs"),X=require("next/navigation");function Y(e){var q,I,w;const s=o.useRef(null);o.useState(()=>!1);function u(n){var i,r;const t={...e.builderContextSignal.rootState,...n};e.builderContextSignal.rootSetState?(r=(i=e.builderContextSignal).rootSetState)==null||r.call(i,t):e.builderContextSignal.rootState=t}function m(n){var i,r,a,c,d;const t={...e.builderContextSignal.content,...n,data:{...(i=e.builderContextSignal.content)==null?void 0:i.data,...n==null?void 0:n.data},meta:{...(r=e.builderContextSignal.content)==null?void 0:r.meta,...n==null?void 0:n.meta,breakpoints:((a=n==null?void 0:n.meta)==null?void 0:a.breakpoints)||((d=(c=e.builderContextSignal.content)==null?void 0:c.meta)==null?void 0:d.breakpoints)}};$.postPreviewContent({value:t,key:t.id,url:window.location.pathname})}function H(){return e.showContent?{}:{hidden:!0,"aria-hidden":!0}}const[K,Z]=o.useState(()=>e.contentWrapper||"div");function S(n){return z.createEditorListener({model:e.model,trustedHosts:e.trustedHosts,callbacks:{configureSdk:t=>{var a;const{breakpoints:i,contentId:r}=t;!r||r!==((a=e.builderContextSignal.content)==null?void 0:a.id)||i&&m({meta:{breakpoints:i}})},animation:t=>{J.triggerAnimation(t)},contentUpdate:t=>{m(t)},stateUpdate:t=>{u(t)}}})(n)}const[v,p]=o.useState(()=>({})),[b,ee]=o.useState(()=>({})),[E,T]=o.useState(()=>!1);function D(n){var t,i;if(e.builderContextSignal.content){const r=(t=e.builderContextSignal.content)==null?void 0:t.testVariationId,a=(i=e.builderContextSignal.content)==null?void 0:i.id;y._track({apiHost:e.apiHost,type:"click",canTrack:P.getDefaultCanTrack(e.canTrack),contentId:a,apiKey:e.apiKey,variationId:r!==a?r:void 0,...A.getInteractionPropertiesForEvent(n),unique:!E})}E||T(!0)}function _(){var t,i,r;const n=(r=(i=(t=e.builderContextSignal.content)==null?void 0:t.data)==null?void 0:i.httpRequests)!=null?r:{};Object.entries(n).forEach(([a,c])=>{if(!c||b[a]||v[a]&&!f.isEditing())return;b[a]=!0;const d=c.replace(/{{([^}]+)}}/g,(l,U)=>String(j.evaluate({code:U,context:e.context||{},localState:void 0,rootState:e.builderContextSignal.rootState,rootSetState:e.builderContextSignal.rootSetState})));O.logFetch(d),fetch(d).then(l=>l.json()).then(l=>{u({[a]:l}),v[a]=!0}).catch(l=>{console.error("error fetching dynamic data",c,l)}).finally(()=>{b[a]=!1})})}function g(){f.isEditing()&&window.dispatchEvent(new CustomEvent("builder:component:stateChange",{detail:{state:B.fastClone(e.builderContextSignal.rootState),ref:{name:e.model}}}))}function h(n){var t;window.addEventListener("message",S),G.setupBrowserForEditing({...e.locale?{locale:e.locale}:{},...e.enrich?{enrich:e.enrich}:{},...e.trustedHosts?{trustedHosts:e.trustedHosts}:{},modelName:(t=e.model)!=null?t:"",apiKey:e.apiKey}),Object.values(e.builderContextSignal.componentInfos).forEach(i=>{var r,a;if(!((r=i.models)!=null&&r.length)||i.models.includes(e.model)){const c=W.createRegisterComponentMessage(i);(a=window.parent)==null||a.postMessage(c,"*")}}),window.addEventListener("builder:component:stateChangeListenerActivated",g)}function x(n){var c;const t=new URL(location.href).searchParams,i=t.get("builder.preview"),r=t.get(`builder.overrides.${i}`),a=t.get("apiKey")||t.get("builder.space");(i==="BUILDER_STUDIO"||i===e.model&&a===e.apiKey&&(!e.content||r===e.content.id))&&F.fetchOneEntry({model:e.model,apiKey:e.apiKey,apiVersion:e.builderContextSignal.apiVersion,...i==="BUILDER_STUDIO"&&((c=e.context)!=null&&c.symbolId)?{query:{id:e.context.symbolId}}:{}}).then(d=>{d&&m(d)})}X.useRouter();const C=o.useRef(!1);return C.current||(_(),g(),C.current=!0),o.useEffect(()=>{var n;return(n=s.current)==null||n.addEventListener("initeditingbldr",h),()=>{var t;return(t=s.current)==null?void 0:t.removeEventListener("initeditingbldr",h)}},[]),o.useEffect(()=>{var n;return(n=s.current)==null||n.addEventListener("initpreviewingbldr",x),()=>{var t;return(t=s.current)==null?void 0:t.removeEventListener("initpreviewingbldr",x)}},[]),o.useEffect(()=>{var n,t,i;if(k.isBrowser()){f.isEditing()&&!e.isNestedRender&&s.current&&s.current.dispatchEvent(new CustomEvent("initeditingbldr"));const r=e.builderContextSignal.content&&P.getDefaultCanTrack(e.canTrack),a=M.getCookieSync({name:`builder.tests.${(n=e.builderContextSignal.content)==null?void 0:n.id}`,canTrack:!0}),c=(t=e.builderContextSignal.content)==null?void 0:t.testVariationId;if(r&&c===a){const d=(i=e.builderContextSignal.content)==null?void 0:i.id,l=e.apiKey;y._track({apiHost:e.apiHost,type:"impression",canTrack:!0,contentId:d,apiKey:l,variationId:a!==d?a:void 0})}N.isPreviewing()&&f.isEditing()}},[]),o.useEffect(()=>{},[e.content]),o.useEffect(()=>{g()},[e.builderContextSignal.rootState]),o.useEffect(()=>{e.data&&u(e.data)},[e.data]),o.useEffect(()=>{e.locale&&u({locale:e.locale})},[e.locale]),o.useEffect(()=>()=>{k.isBrowser()&&(window.removeEventListener("message",S),window.removeEventListener("builder:component:stateChangeListenerActivated",g))},[]),R.jsx(V.Provider,{value:e.builderContextSignal,children:e.builderContextSignal.content||L.needsElementRefDivForEditing()?R.jsx(K,{ref:s,onClick:n=>D(n),"builder-content-id":(q=e.builderContextSignal.content)==null?void 0:q.id,"builder-model":e.model,className:Q.getWrapperClassName(((I=e.content)==null?void 0:I.testVariationId)||((w=e.content)==null?void 0:w.id)),style:{display:!e.builderContextSignal.content&&L.needsElementRefDivForEditing()?"none":void 0},...H(),...e.contentWrapperProps,children:e.children}):null})}module.exports=Y;
1
+ "use client";"use strict";const P=require("react/jsx-runtime"),c=require("react"),V=require("../../../context/builder.context.cjs"),B=require("../../../functions/evaluate/evaluate.cjs"),F=require("../../../functions/fast-clone.cjs"),W=require("../../../functions/get-content/index.cjs"),L=require("../../../functions/is-browser.cjs"),m=require("../../../functions/is-editing.cjs"),A=require("../../../functions/is-previewing.cjs"),M=require("../../../functions/log-fetch.cjs"),$=require("../../../functions/register-component.cjs"),T=require("../../../functions/track/index.cjs"),J=require("../../../functions/track/interaction.cjs"),H=require("../../../helpers/canTrack.cjs"),z=require("../../../helpers/cookie.cjs"),G=require("../../../helpers/preview-lru-cache/set.cjs"),Q=require("../../../helpers/subscribe-to-editor.cjs"),X=require("../../../scripts/init-editing.cjs"),Y=require("../../block/animator.cjs"),K=require("./enable-editor.helpers.cjs"),Z=require("./styles.helpers.cjs"),p=require("next/navigation");function ee(e){var I,w,k;const l=c.useRef(null);c.useState(()=>!1);function g(n){var i,r;const t={...e.builderContextSignal.rootState,...n};e.builderContextSignal.rootSetState?(r=(i=e.builderContextSignal).rootSetState)==null||r.call(i,t):e.builderContextSignal.rootState=t}function b(n){var i,r,a,o,d;const t={...e.builderContextSignal.content,...n,data:{...(i=e.builderContextSignal.content)==null?void 0:i.data,...n==null?void 0:n.data},meta:{...(r=e.builderContextSignal.content)==null?void 0:r.meta,...n==null?void 0:n.meta,breakpoints:((a=n==null?void 0:n.meta)==null?void 0:a.breakpoints)||((d=(o=e.builderContextSignal.content)==null?void 0:o.meta)==null?void 0:d.breakpoints)}};G.postPreviewContent({value:t,key:t.id,url:window.location.pathname})}function D(){return e.showContent?{}:{hidden:!0,"aria-hidden":!0}}const[_,te]=c.useState(()=>e.contentWrapper||"div");function h(n){return Q.createEditorListener({model:e.model,trustedHosts:e.trustedHosts,callbacks:{configureSdk:t=>{var a;const{breakpoints:i,contentId:r}=t;!r||r!==((a=e.builderContextSignal.content)==null?void 0:a.id)||i&&b({meta:{breakpoints:i}})},animation:t=>{Y.triggerAnimation(t)},contentUpdate:t=>{b(t)},stateUpdate:t=>{g(t)}}})(n)}const[E,ne]=c.useState(()=>({})),[S,ie]=c.useState(()=>({})),[x,U]=c.useState(()=>!1);function j(n){var t,i;if(e.builderContextSignal.content){const r=(t=e.builderContextSignal.content)==null?void 0:t.testVariationId,a=(i=e.builderContextSignal.content)==null?void 0:i.id;T._track({apiHost:e.apiHost,type:"click",canTrack:H.getDefaultCanTrack(e.canTrack),contentId:a,apiKey:e.apiKey,variationId:r!==a?r:void 0,...J.getInteractionPropertiesForEvent(n),unique:!x})}x||U(!0)}function N(){var t,i,r;const n=(r=(i=(t=e.builderContextSignal.content)==null?void 0:t.data)==null?void 0:i.httpRequests)!=null?r:{};Object.entries(n).forEach(([a,o])=>{if(!o)return;const d=typeof o=="object"&&o["@type"]==="@builder.io/core:Request";if(S[a]||E[a]&&!m.isEditing())return;const v=d?o.request.url:o;S[a]=!0;const R=v.replace(/{{([^}]+)}}/g,(s,O)=>String(B.evaluate({code:O,context:e.context||{},localState:void 0,rootState:e.builderContextSignal.rootState,rootSetState:e.builderContextSignal.rootSetState}))),u=d?{url:R,method:o.request.method,headers:o.request.headers,body:o.request.body}:{url:R,method:"GET"};M.logFetch(JSON.stringify(u)),fetch(u.url,{method:u.method,headers:u.headers,body:u.body}).then(s=>s.json()).then(s=>{g({[a]:s}),E[a]=!0}).catch(s=>{console.error("error fetching dynamic data",JSON.stringify(o),s)}).finally(()=>{S[a]=!1})})}function f(){m.isEditing()&&window.dispatchEvent(new CustomEvent("builder:component:stateChange",{detail:{state:F.fastClone(e.builderContextSignal.rootState),ref:{name:e.model}}}))}function C(n){var t;window.addEventListener("message",h),X.setupBrowserForEditing({...e.locale?{locale:e.locale}:{},...e.enrich?{enrich:e.enrich}:{},...e.trustedHosts?{trustedHosts:e.trustedHosts}:{},modelName:(t=e.model)!=null?t:"",apiKey:e.apiKey}),Object.values(e.builderContextSignal.componentInfos).forEach(i=>{var r,a;if(!((r=i.models)!=null&&r.length)||i.models.includes(e.model)){const o=$.createRegisterComponentMessage(i);(a=window.parent)==null||a.postMessage(o,"*")}}),window.addEventListener("builder:component:stateChangeListenerActivated",f)}function q(n){var o;const t=new URL(location.href).searchParams,i=t.get("builder.preview"),r=t.get(`builder.overrides.${i}`),a=t.get("apiKey")||t.get("builder.space");(i==="BUILDER_STUDIO"||i===e.model&&a===e.apiKey&&(!e.content||r===e.content.id))&&W.fetchOneEntry({model:e.model,apiKey:e.apiKey,apiVersion:e.builderContextSignal.apiVersion,...i==="BUILDER_STUDIO"&&((o=e.context)!=null&&o.symbolId)?{query:{id:e.context.symbolId}}:{}}).then(d=>{d&&b(d)})}p.useRouter();const y=c.useRef(!1);return y.current||(N(),f(),y.current=!0),c.useEffect(()=>{var n;return(n=l.current)==null||n.addEventListener("initeditingbldr",C),()=>{var t;return(t=l.current)==null?void 0:t.removeEventListener("initeditingbldr",C)}},[]),c.useEffect(()=>{var n;return(n=l.current)==null||n.addEventListener("initpreviewingbldr",q),()=>{var t;return(t=l.current)==null?void 0:t.removeEventListener("initpreviewingbldr",q)}},[]),c.useEffect(()=>{var n,t,i;if(L.isBrowser()){m.isEditing()&&!e.isNestedRender&&l.current&&l.current.dispatchEvent(new CustomEvent("initeditingbldr"));const r=e.builderContextSignal.content&&H.getDefaultCanTrack(e.canTrack),a=z.getCookieSync({name:`builder.tests.${(n=e.builderContextSignal.content)==null?void 0:n.id}`,canTrack:!0}),o=(t=e.builderContextSignal.content)==null?void 0:t.testVariationId;if(r&&o===a){const d=(i=e.builderContextSignal.content)==null?void 0:i.id,v=e.apiKey;T._track({apiHost:e.apiHost,type:"impression",canTrack:!0,contentId:d,apiKey:v,variationId:a!==d?a:void 0})}A.isPreviewing()&&m.isEditing()}},[]),c.useEffect(()=>{},[e.content]),c.useEffect(()=>{f()},[e.builderContextSignal.rootState]),c.useEffect(()=>{e.data&&g(e.data)},[e.data]),c.useEffect(()=>{e.locale&&g({locale:e.locale})},[e.locale]),c.useEffect(()=>()=>{L.isBrowser()&&(window.removeEventListener("message",h),window.removeEventListener("builder:component:stateChangeListenerActivated",f))},[]),P.jsx(V.Provider,{value:e.builderContextSignal,children:e.builderContextSignal.content||K.needsElementRefDivForEditing()?P.jsx(_,{ref:l,onClick:n=>j(n),"builder-content-id":(I=e.builderContextSignal.content)==null?void 0:I.id,"builder-model":e.model,className:Z.getWrapperClassName(((w=e.content)==null?void 0:w.testVariationId)||((k=e.content)==null?void 0:k.id)),style:{display:!e.builderContextSignal.content&&K.needsElementRefDivForEditing()?"none":void 0},...D(),...e.contentWrapperProps,children:e.children}):null})}module.exports=ee;
@@ -1,282 +1,304 @@
1
1
  "use client";
2
- import { jsx as k } from "react/jsx-runtime";
3
- import { useRef as P, useState as m, useEffect as c } from "react";
4
- import O from "../../../context/builder.context.mjs";
5
- import { evaluate as W } from "../../../functions/evaluate/evaluate.mjs";
6
- import { fastClone as j } from "../../../functions/fast-clone.mjs";
7
- import { fetchOneEntry as A } from "../../../functions/get-content/index.mjs";
8
- import { isBrowser as L } from "../../../functions/is-browser.mjs";
9
- import { isEditing as g } from "../../../functions/is-editing.mjs";
10
- import { isPreviewing as B } from "../../../functions/is-previewing.mjs";
11
- import { logFetch as F } from "../../../functions/log-fetch.mjs";
12
- import { createRegisterComponentMessage as M } from "../../../functions/register-component.mjs";
13
- import { _track as H } from "../../../functions/track/index.mjs";
14
- import { getInteractionPropertiesForEvent as $ } from "../../../functions/track/interaction.mjs";
15
- import { getDefaultCanTrack as K } from "../../../helpers/canTrack.mjs";
16
- import { getCookieSync as z } from "../../../helpers/cookie.mjs";
17
- import { postPreviewContent as G } from "../../../helpers/preview-lru-cache/set.mjs";
18
- import { createEditorListener as J } from "../../../helpers/subscribe-to-editor.mjs";
19
- import { setupBrowserForEditing as Q } from "../../../scripts/init-editing.mjs";
20
- import { triggerAnimation as X } from "../../block/animator.mjs";
21
- import { needsElementRefDivForEditing as q } from "./enable-editor.helpers.mjs";
22
- import { getWrapperClassName as Y } from "./styles.helpers.mjs";
23
- import { useRouter as Z } from "next/navigation";
24
- function yt(t) {
25
- var w, y, R;
26
- const u = P(null);
27
- m(() => !1);
28
- function s(n) {
2
+ import { jsx as H } from "react/jsx-runtime";
3
+ import { useRef as K, useState as s, useEffect as l } from "react";
4
+ import A from "../../../context/builder.context.mjs";
5
+ import { evaluate as B } from "../../../functions/evaluate/evaluate.mjs";
6
+ import { fastClone as F } from "../../../functions/fast-clone.mjs";
7
+ import { fetchOneEntry as M } from "../../../functions/get-content/index.mjs";
8
+ import { isBrowser as T } from "../../../functions/is-browser.mjs";
9
+ import { isEditing as b } from "../../../functions/is-editing.mjs";
10
+ import { isPreviewing as J } from "../../../functions/is-previewing.mjs";
11
+ import { logFetch as $ } from "../../../functions/log-fetch.mjs";
12
+ import { createRegisterComponentMessage as z } from "../../../functions/register-component.mjs";
13
+ import { _track as U } from "../../../functions/track/index.mjs";
14
+ import { getInteractionPropertiesForEvent as G } from "../../../functions/track/interaction.mjs";
15
+ import { getDefaultCanTrack as q } from "../../../helpers/canTrack.mjs";
16
+ import { getCookieSync as Q } from "../../../helpers/cookie.mjs";
17
+ import { postPreviewContent as X } from "../../../helpers/preview-lru-cache/set.mjs";
18
+ import { createEditorListener as Y } from "../../../helpers/subscribe-to-editor.mjs";
19
+ import { setupBrowserForEditing as Z } from "../../../scripts/init-editing.mjs";
20
+ import { triggerAnimation as p } from "../../block/animator.mjs";
21
+ import { needsElementRefDivForEditing as D } from "./enable-editor.helpers.mjs";
22
+ import { getWrapperClassName as ee } from "./styles.helpers.mjs";
23
+ import { useRouter as te } from "next/navigation";
24
+ function Le(e) {
25
+ var k, P, L;
26
+ const c = K(null);
27
+ s(() => !1);
28
+ function f(n) {
29
29
  var i, o;
30
- const e = {
31
- ...t.builderContextSignal.rootState,
30
+ const t = {
31
+ ...e.builderContextSignal.rootState,
32
32
  ...n
33
33
  };
34
- t.builderContextSignal.rootSetState ? (o = (i = t.builderContextSignal).rootSetState) == null || o.call(i, e) : t.builderContextSignal.rootState = e;
34
+ e.builderContextSignal.rootSetState ? (o = (i = e.builderContextSignal).rootSetState) == null || o.call(i, t) : e.builderContextSignal.rootState = t;
35
35
  }
36
- function b(n) {
36
+ function S(n) {
37
37
  var i, o, a, r, d;
38
- const e = {
39
- ...t.builderContextSignal.content,
38
+ const t = {
39
+ ...e.builderContextSignal.content,
40
40
  ...n,
41
41
  data: {
42
- ...(i = t.builderContextSignal.content) == null ? void 0 : i.data,
42
+ ...(i = e.builderContextSignal.content) == null ? void 0 : i.data,
43
43
  ...n == null ? void 0 : n.data
44
44
  },
45
45
  meta: {
46
- ...(o = t.builderContextSignal.content) == null ? void 0 : o.meta,
46
+ ...(o = e.builderContextSignal.content) == null ? void 0 : o.meta,
47
47
  ...n == null ? void 0 : n.meta,
48
- breakpoints: ((a = n == null ? void 0 : n.meta) == null ? void 0 : a.breakpoints) || ((d = (r = t.builderContextSignal.content) == null ? void 0 : r.meta) == null ? void 0 : d.breakpoints)
48
+ breakpoints: ((a = n == null ? void 0 : n.meta) == null ? void 0 : a.breakpoints) || ((d = (r = e.builderContextSignal.content) == null ? void 0 : r.meta) == null ? void 0 : d.breakpoints)
49
49
  }
50
50
  };
51
- G({
52
- value: e,
53
- key: e.id,
51
+ X({
52
+ value: t,
53
+ key: t.id,
54
54
  url: window.location.pathname
55
55
  });
56
56
  }
57
- function T() {
58
- return t.showContent ? {} : {
57
+ function N() {
58
+ return e.showContent ? {} : {
59
59
  hidden: !0,
60
60
  "aria-hidden": !0
61
61
  };
62
62
  }
63
- const [U, p] = m(
64
- () => t.contentWrapper || "div"
63
+ const [O, ne] = s(
64
+ () => e.contentWrapper || "div"
65
65
  );
66
- function v(n) {
67
- return J({
68
- model: t.model,
69
- trustedHosts: t.trustedHosts,
66
+ function x(n) {
67
+ return Y({
68
+ model: e.model,
69
+ trustedHosts: e.trustedHosts,
70
70
  callbacks: {
71
- configureSdk: (e) => {
71
+ configureSdk: (t) => {
72
72
  var a;
73
- const { breakpoints: i, contentId: o } = e;
74
- !o || o !== ((a = t.builderContextSignal.content) == null ? void 0 : a.id) || i && b({
73
+ const { breakpoints: i, contentId: o } = t;
74
+ !o || o !== ((a = e.builderContextSignal.content) == null ? void 0 : a.id) || i && S({
75
75
  meta: {
76
76
  breakpoints: i
77
77
  }
78
78
  });
79
79
  },
80
- animation: (e) => {
81
- X(e);
80
+ animation: (t) => {
81
+ p(t);
82
82
  },
83
- contentUpdate: (e) => {
84
- b(e);
83
+ contentUpdate: (t) => {
84
+ S(t);
85
85
  },
86
- stateUpdate: (e) => {
87
- s(e);
86
+ stateUpdate: (t) => {
87
+ f(t);
88
88
  }
89
89
  }
90
90
  })(n);
91
91
  }
92
- const [h, tt] = m(() => ({})), [S, et] = m(() => ({})), [x, D] = m(() => !1);
93
- function V(n) {
94
- var e, i;
95
- if (t.builderContextSignal.content) {
96
- const o = (e = t.builderContextSignal.content) == null ? void 0 : e.testVariationId, a = (i = t.builderContextSignal.content) == null ? void 0 : i.id;
97
- H({
98
- apiHost: t.apiHost,
92
+ const [C, ie] = s(() => ({})), [v, ae] = s(() => ({})), [y, V] = s(() => !1);
93
+ function j(n) {
94
+ var t, i;
95
+ if (e.builderContextSignal.content) {
96
+ const o = (t = e.builderContextSignal.content) == null ? void 0 : t.testVariationId, a = (i = e.builderContextSignal.content) == null ? void 0 : i.id;
97
+ U({
98
+ apiHost: e.apiHost,
99
99
  type: "click",
100
- canTrack: K(t.canTrack),
100
+ canTrack: q(e.canTrack),
101
101
  contentId: a,
102
- apiKey: t.apiKey,
102
+ apiKey: e.apiKey,
103
103
  variationId: o !== a ? o : void 0,
104
- ...$(n),
105
- unique: !x
104
+ ...G(n),
105
+ unique: !y
106
106
  });
107
107
  }
108
- x || D(!0);
108
+ y || V(!0);
109
109
  }
110
- function N() {
111
- var e, i, o;
112
- const n = (o = (i = (e = t.builderContextSignal.content) == null ? void 0 : e.data) == null ? void 0 : i.httpRequests) != null ? o : {};
113
- Object.entries(n).forEach(([a, r]) => {
114
- if (!r || S[a] || h[a] && !g())
115
- return;
116
- S[a] = !0;
117
- const d = r.replace(
118
- /{{([^}]+)}}/g,
119
- (l, _) => String(
120
- W({
121
- code: _,
122
- context: t.context || {},
123
- localState: void 0,
124
- rootState: t.builderContextSignal.rootState,
125
- rootSetState: t.builderContextSignal.rootSetState
126
- })
127
- )
128
- );
129
- F(d), fetch(d).then((l) => l.json()).then((l) => {
130
- s({
131
- [a]: l
132
- }), h[a] = !0;
133
- }).catch((l) => {
134
- console.error("error fetching dynamic data", r, l);
135
- }).finally(() => {
136
- S[a] = !1;
137
- });
138
- });
110
+ function _() {
111
+ var t, i, o;
112
+ const n = (o = (i = (t = e.builderContextSignal.content) == null ? void 0 : t.data) == null ? void 0 : i.httpRequests) != null ? o : {};
113
+ Object.entries(n).forEach(
114
+ ([a, r]) => {
115
+ if (!r)
116
+ return;
117
+ const d = typeof r == "object" && r["@type"] === "@builder.io/core:Request";
118
+ if (v[a] || C[a] && !b())
119
+ return;
120
+ const h = d ? r.request.url : r;
121
+ v[a] = !0;
122
+ const R = h.replace(
123
+ /{{([^}]+)}}/g,
124
+ (u, W) => String(
125
+ B({
126
+ code: W,
127
+ context: e.context || {},
128
+ localState: void 0,
129
+ rootState: e.builderContextSignal.rootState,
130
+ rootSetState: e.builderContextSignal.rootSetState
131
+ })
132
+ )
133
+ ), m = d ? {
134
+ url: R,
135
+ method: r.request.method,
136
+ headers: r.request.headers,
137
+ body: r.request.body
138
+ } : {
139
+ url: R,
140
+ method: "GET"
141
+ };
142
+ $(JSON.stringify(m)), fetch(m.url, {
143
+ method: m.method,
144
+ headers: m.headers,
145
+ body: m.body
146
+ }).then((u) => u.json()).then((u) => {
147
+ f({
148
+ [a]: u
149
+ }), C[a] = !0;
150
+ }).catch((u) => {
151
+ console.error(
152
+ "error fetching dynamic data",
153
+ JSON.stringify(r),
154
+ u
155
+ );
156
+ }).finally(() => {
157
+ v[a] = !1;
158
+ });
159
+ }
160
+ );
139
161
  }
140
- function f() {
141
- g() && window.dispatchEvent(
162
+ function g() {
163
+ b() && window.dispatchEvent(
142
164
  new CustomEvent(
143
165
  "builder:component:stateChange",
144
166
  {
145
167
  detail: {
146
- state: j(t.builderContextSignal.rootState),
168
+ state: F(e.builderContextSignal.rootState),
147
169
  ref: {
148
- name: t.model
170
+ name: e.model
149
171
  }
150
172
  }
151
173
  }
152
174
  )
153
175
  );
154
176
  }
155
- function C(n) {
156
- var e;
157
- window.addEventListener("message", v), Q({
158
- ...t.locale ? {
159
- locale: t.locale
177
+ function E(n) {
178
+ var t;
179
+ window.addEventListener("message", x), Z({
180
+ ...e.locale ? {
181
+ locale: e.locale
160
182
  } : {},
161
- ...t.enrich ? {
162
- enrich: t.enrich
183
+ ...e.enrich ? {
184
+ enrich: e.enrich
163
185
  } : {},
164
- ...t.trustedHosts ? {
165
- trustedHosts: t.trustedHosts
186
+ ...e.trustedHosts ? {
187
+ trustedHosts: e.trustedHosts
166
188
  } : {},
167
- modelName: (e = t.model) != null ? e : "",
168
- apiKey: t.apiKey
189
+ modelName: (t = e.model) != null ? t : "",
190
+ apiKey: e.apiKey
169
191
  }), Object.values(
170
- t.builderContextSignal.componentInfos
192
+ e.builderContextSignal.componentInfos
171
193
  ).forEach((i) => {
172
194
  var o, a;
173
- if (!((o = i.models) != null && o.length) || i.models.includes(t.model)) {
174
- const r = M(i);
195
+ if (!((o = i.models) != null && o.length) || i.models.includes(e.model)) {
196
+ const r = z(i);
175
197
  (a = window.parent) == null || a.postMessage(r, "*");
176
198
  }
177
199
  }), window.addEventListener(
178
200
  "builder:component:stateChangeListenerActivated",
179
- f
201
+ g
180
202
  );
181
203
  }
182
- function E(n) {
204
+ function I(n) {
183
205
  var r;
184
- const e = new URL(location.href).searchParams, i = e.get("builder.preview"), o = e.get(
206
+ const t = new URL(location.href).searchParams, i = t.get("builder.preview"), o = t.get(
185
207
  `builder.overrides.${i}`
186
- ), a = e.get("apiKey") || e.get("builder.space");
187
- (i === "BUILDER_STUDIO" || i === t.model && a === t.apiKey && (!t.content || o === t.content.id)) && A({
188
- model: t.model,
189
- apiKey: t.apiKey,
190
- apiVersion: t.builderContextSignal.apiVersion,
191
- ...i === "BUILDER_STUDIO" && ((r = t.context) != null && r.symbolId) ? {
208
+ ), a = t.get("apiKey") || t.get("builder.space");
209
+ (i === "BUILDER_STUDIO" || i === e.model && a === e.apiKey && (!e.content || o === e.content.id)) && M({
210
+ model: e.model,
211
+ apiKey: e.apiKey,
212
+ apiVersion: e.builderContextSignal.apiVersion,
213
+ ...i === "BUILDER_STUDIO" && ((r = e.context) != null && r.symbolId) ? {
192
214
  query: {
193
- id: t.context.symbolId
215
+ id: e.context.symbolId
194
216
  }
195
217
  } : {}
196
218
  }).then((d) => {
197
- d && b(d);
219
+ d && S(d);
198
220
  });
199
221
  }
200
- Z();
201
- const I = P(!1);
202
- return I.current || (N(), f(), I.current = !0), c(() => {
222
+ te();
223
+ const w = K(!1);
224
+ return w.current || (_(), g(), w.current = !0), l(() => {
203
225
  var n;
204
- return (n = u.current) == null || n.addEventListener(
226
+ return (n = c.current) == null || n.addEventListener(
205
227
  "initeditingbldr",
206
- C
228
+ E
207
229
  ), () => {
208
- var e;
209
- return (e = u.current) == null ? void 0 : e.removeEventListener(
230
+ var t;
231
+ return (t = c.current) == null ? void 0 : t.removeEventListener(
210
232
  "initeditingbldr",
211
- C
233
+ E
212
234
  );
213
235
  };
214
- }, []), c(() => {
236
+ }, []), l(() => {
215
237
  var n;
216
- return (n = u.current) == null || n.addEventListener(
238
+ return (n = c.current) == null || n.addEventListener(
217
239
  "initpreviewingbldr",
218
- E
240
+ I
219
241
  ), () => {
220
- var e;
221
- return (e = u.current) == null ? void 0 : e.removeEventListener(
242
+ var t;
243
+ return (t = c.current) == null ? void 0 : t.removeEventListener(
222
244
  "initpreviewingbldr",
223
- E
245
+ I
224
246
  );
225
247
  };
226
- }, []), c(() => {
227
- var n, e, i;
228
- if (L()) {
229
- g() && !t.isNestedRender && u.current && u.current.dispatchEvent(new CustomEvent("initeditingbldr"));
230
- const o = t.builderContextSignal.content && K(t.canTrack), a = z({
231
- name: `builder.tests.${(n = t.builderContextSignal.content) == null ? void 0 : n.id}`,
248
+ }, []), l(() => {
249
+ var n, t, i;
250
+ if (T()) {
251
+ b() && !e.isNestedRender && c.current && c.current.dispatchEvent(new CustomEvent("initeditingbldr"));
252
+ const o = e.builderContextSignal.content && q(e.canTrack), a = Q({
253
+ name: `builder.tests.${(n = e.builderContextSignal.content) == null ? void 0 : n.id}`,
232
254
  canTrack: !0
233
- }), r = (e = t.builderContextSignal.content) == null ? void 0 : e.testVariationId;
255
+ }), r = (t = e.builderContextSignal.content) == null ? void 0 : t.testVariationId;
234
256
  if (o && r === a) {
235
- const d = (i = t.builderContextSignal.content) == null ? void 0 : i.id, l = t.apiKey;
236
- H({
237
- apiHost: t.apiHost,
257
+ const d = (i = e.builderContextSignal.content) == null ? void 0 : i.id, h = e.apiKey;
258
+ U({
259
+ apiHost: e.apiHost,
238
260
  type: "impression",
239
261
  canTrack: !0,
240
262
  contentId: d,
241
- apiKey: l,
263
+ apiKey: h,
242
264
  variationId: a !== d ? a : void 0
243
265
  });
244
266
  }
245
- B() && g();
267
+ J() && b();
246
268
  }
247
- }, []), c(() => {
248
- }, [t.content]), c(() => {
249
- f();
250
- }, [t.builderContextSignal.rootState]), c(() => {
251
- t.data && s(t.data);
252
- }, [t.data]), c(() => {
253
- t.locale && s({
254
- locale: t.locale
269
+ }, []), l(() => {
270
+ }, [e.content]), l(() => {
271
+ g();
272
+ }, [e.builderContextSignal.rootState]), l(() => {
273
+ e.data && f(e.data);
274
+ }, [e.data]), l(() => {
275
+ e.locale && f({
276
+ locale: e.locale
255
277
  });
256
- }, [t.locale]), c(() => () => {
257
- L() && (window.removeEventListener("message", v), window.removeEventListener(
278
+ }, [e.locale]), l(() => () => {
279
+ T() && (window.removeEventListener("message", x), window.removeEventListener(
258
280
  "builder:component:stateChangeListenerActivated",
259
- f
281
+ g
260
282
  ));
261
- }, []), /* @__PURE__ */ k(O.Provider, { value: t.builderContextSignal, children: t.builderContextSignal.content || q() ? /* @__PURE__ */ k(
262
- U,
283
+ }, []), /* @__PURE__ */ H(A.Provider, { value: e.builderContextSignal, children: e.builderContextSignal.content || D() ? /* @__PURE__ */ H(
284
+ O,
263
285
  {
264
- ref: u,
265
- onClick: (n) => V(n),
266
- "builder-content-id": (w = t.builderContextSignal.content) == null ? void 0 : w.id,
267
- "builder-model": t.model,
268
- className: Y(
269
- ((y = t.content) == null ? void 0 : y.testVariationId) || ((R = t.content) == null ? void 0 : R.id)
286
+ ref: c,
287
+ onClick: (n) => j(n),
288
+ "builder-content-id": (k = e.builderContextSignal.content) == null ? void 0 : k.id,
289
+ "builder-model": e.model,
290
+ className: ee(
291
+ ((P = e.content) == null ? void 0 : P.testVariationId) || ((L = e.content) == null ? void 0 : L.id)
270
292
  ),
271
293
  style: {
272
- display: !t.builderContextSignal.content && q() ? "none" : void 0
294
+ display: !e.builderContextSignal.content && D() ? "none" : void 0
273
295
  },
274
- ...T(),
275
- ...t.contentWrapperProps,
276
- children: t.children
296
+ ...N(),
297
+ ...e.contentWrapperProps,
298
+ children: e.children
277
299
  }
278
300
  ) : null });
279
301
  }
280
302
  export {
281
- yt as default
303
+ Le as default
282
304
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e="0.19.2";exports.SDK_VERSION=e;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e="0.20.0";exports.SDK_VERSION=e;
@@ -1,4 +1,4 @@
1
- const o = "0.19.2";
1
+ const o = "0.20.0";
2
2
  export {
3
3
  o as SDK_VERSION
4
4
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../constants/target.cjs"),d=require("../helpers/omit.cjs"),p=require("./evaluate/evaluate.cjs"),f=require("./extract-localized-values.cjs"),g=require("./fast-clone.cjs"),m=require("./set.cjs"),y=require("./transform-block.cjs");function o(e){if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(n=>o(n));if(e["@type"]==="@builder.io/sdk:Element")return e;const t={};for(const n in e)n!=="meta"&&Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=o(e[n]));return t}const C=["svelte","vue","angular","qwik","solid"].includes(u.TARGET),q=e=>{if(C){const t=g.fastClone(e);return{...t,properties:{...t.properties},actions:{...t.actions}}}else{const t=o(d.omit(e,"children","meta"));return{...t,properties:{...t.properties},actions:{...t.actions},children:e.children,meta:e.meta}}},v=({block:e,context:t,localState:n,rootState:i,rootSetState:s})=>{if(!e.bindings)return e;const r=q(e);for(const c in e.bindings){const a=e.bindings[c],l=p.evaluate({code:a,localState:n,rootState:i,rootSetState:s,context:t});m.set(r,c,l)}return r};function B({block:e,context:t,localState:n,rootState:i,rootSetState:s}){let r=f.resolveLocalizedValues(e,i.locale);return r=y.transformBlock(r),v({block:r,localState:n,rootState:i,rootSetState:s,context:t})}exports.deepCloneWithConditions=o;exports.getProcessedBlock=B;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../constants/target.cjs"),d=require("../helpers/omit.cjs"),p=require("./evaluate/evaluate.cjs"),f=require("./extract-localized-values.cjs"),g=require("./fast-clone.cjs"),m=require("./set.cjs"),y=require("./transform-block.cjs");function o(e){if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(n=>o(n));if(e["@type"]==="@builder.io/sdk:Element")return e;const t={};for(const n in e)n!=="meta"&&Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=o(e[n]));return t}const C=["svelte","vue","angular","qwik","solid"].includes(u.TARGET),q=e=>{if(C){const t=g.fastClone(e);return{...t,properties:{...t.properties},actions:{...t.actions}}}else{const t=o(d.omit(e,"children","meta"));return{...t,properties:{...t.properties},actions:{...t.actions},children:e.children,meta:e.meta}}},v=({block:e,context:t,localState:n,rootState:i,rootSetState:s})=>{if(!e.bindings)return e;const r=q(e);for(const c in e.bindings){const a=e.bindings[c],l=p.evaluate({code:a,localState:n,rootState:i,rootSetState:s,context:t});m.set(r,c,l)}return r};function B({block:e,context:t,localState:n,rootState:i,rootSetState:s}){let r=y.transformBlock(e);return r=v({block:r,localState:n,rootState:i,rootSetState:s,context:t}),r=f.resolveLocalizedValues(r,i.locale),r}exports.deepCloneWithConditions=o;exports.getProcessedBlock=B;
@@ -72,14 +72,14 @@ function P({
72
72
  rootState: i,
73
73
  rootSetState: o
74
74
  }) {
75
- let n = f(e, i.locale);
76
- return n = g(n), O({
75
+ let n = g(e);
76
+ return n = O({
77
77
  block: n,
78
78
  localState: t,
79
79
  rootState: i,
80
80
  rootSetState: o,
81
81
  context: r
82
- });
82
+ }), n = f(n, i.locale), n;
83
83
  }
84
84
  export {
85
85
  s as deepCloneWithConditions,
@@ -1 +1 @@
1
- "use client";"use strict";const R=require("react/jsx-runtime"),o=require("react"),V=require("../../../context/builder.context.cjs"),j=require("../../../functions/evaluate/evaluate.cjs"),B=require("../../../functions/fast-clone.cjs"),F=require("../../../functions/get-content/index.cjs"),k=require("../../../functions/is-browser.cjs"),f=require("../../../functions/is-editing.cjs"),N=require("../../../functions/is-previewing.cjs"),O=require("../../../functions/log-fetch.cjs"),W=require("../../../functions/register-component.cjs"),y=require("../../../functions/track/index.cjs"),A=require("../../../functions/track/interaction.cjs"),P=require("../../../helpers/canTrack.cjs"),M=require("../../../helpers/cookie.cjs"),$=require("../../../helpers/preview-lru-cache/set.cjs"),z=require("../../../helpers/subscribe-to-editor.cjs"),G=require("../../../scripts/init-editing.cjs"),J=require("../../block/animator.cjs"),L=require("./enable-editor.helpers.cjs"),Q=require("./styles.helpers.cjs"),X=require("next/navigation");function Y(e){var q,I,w;const s=o.useRef(null);o.useState(()=>!1);function u(n){var i,r;const t={...e.builderContextSignal.rootState,...n};e.builderContextSignal.rootSetState?(r=(i=e.builderContextSignal).rootSetState)==null||r.call(i,t):e.builderContextSignal.rootState=t}function m(n){var i,r,a,c,d;const t={...e.builderContextSignal.content,...n,data:{...(i=e.builderContextSignal.content)==null?void 0:i.data,...n==null?void 0:n.data},meta:{...(r=e.builderContextSignal.content)==null?void 0:r.meta,...n==null?void 0:n.meta,breakpoints:((a=n==null?void 0:n.meta)==null?void 0:a.breakpoints)||((d=(c=e.builderContextSignal.content)==null?void 0:c.meta)==null?void 0:d.breakpoints)}};$.postPreviewContent({value:t,key:t.id,url:window.location.pathname})}function H(){return e.showContent?{}:{hidden:!0,"aria-hidden":!0}}const[K,Z]=o.useState(()=>e.contentWrapper||"div");function S(n){return z.createEditorListener({model:e.model,trustedHosts:e.trustedHosts,callbacks:{configureSdk:t=>{var a;const{breakpoints:i,contentId:r}=t;!r||r!==((a=e.builderContextSignal.content)==null?void 0:a.id)||i&&m({meta:{breakpoints:i}})},animation:t=>{J.triggerAnimation(t)},contentUpdate:t=>{m(t)},stateUpdate:t=>{u(t)}}})(n)}const[v,p]=o.useState(()=>({})),[b,ee]=o.useState(()=>({})),[E,T]=o.useState(()=>!1);function D(n){var t,i;if(e.builderContextSignal.content){const r=(t=e.builderContextSignal.content)==null?void 0:t.testVariationId,a=(i=e.builderContextSignal.content)==null?void 0:i.id;y._track({apiHost:e.apiHost,type:"click",canTrack:P.getDefaultCanTrack(e.canTrack),contentId:a,apiKey:e.apiKey,variationId:r!==a?r:void 0,...A.getInteractionPropertiesForEvent(n),unique:!E})}E||T(!0)}function _(){var t,i,r;const n=(r=(i=(t=e.builderContextSignal.content)==null?void 0:t.data)==null?void 0:i.httpRequests)!=null?r:{};Object.entries(n).forEach(([a,c])=>{if(!c||b[a]||v[a]&&!f.isEditing())return;b[a]=!0;const d=c.replace(/{{([^}]+)}}/g,(l,U)=>String(j.evaluate({code:U,context:e.context||{},localState:void 0,rootState:e.builderContextSignal.rootState,rootSetState:e.builderContextSignal.rootSetState})));O.logFetch(d),fetch(d).then(l=>l.json()).then(l=>{u({[a]:l}),v[a]=!0}).catch(l=>{console.error("error fetching dynamic data",c,l)}).finally(()=>{b[a]=!1})})}function g(){f.isEditing()&&window.dispatchEvent(new CustomEvent("builder:component:stateChange",{detail:{state:B.fastClone(e.builderContextSignal.rootState),ref:{name:e.model}}}))}function h(n){var t;window.addEventListener("message",S),G.setupBrowserForEditing({...e.locale?{locale:e.locale}:{},...e.enrich?{enrich:e.enrich}:{},...e.trustedHosts?{trustedHosts:e.trustedHosts}:{},modelName:(t=e.model)!=null?t:"",apiKey:e.apiKey}),Object.values(e.builderContextSignal.componentInfos).forEach(i=>{var r,a;if(!((r=i.models)!=null&&r.length)||i.models.includes(e.model)){const c=W.createRegisterComponentMessage(i);(a=window.parent)==null||a.postMessage(c,"*")}}),window.addEventListener("builder:component:stateChangeListenerActivated",g)}function x(n){var c;const t=new URL(location.href).searchParams,i=t.get("builder.preview"),r=t.get(`builder.overrides.${i}`),a=t.get("apiKey")||t.get("builder.space");(i==="BUILDER_STUDIO"||i===e.model&&a===e.apiKey&&(!e.content||r===e.content.id))&&F.fetchOneEntry({model:e.model,apiKey:e.apiKey,apiVersion:e.builderContextSignal.apiVersion,...i==="BUILDER_STUDIO"&&((c=e.context)!=null&&c.symbolId)?{query:{id:e.context.symbolId}}:{}}).then(d=>{d&&m(d)})}X.useRouter();const C=o.useRef(!1);return C.current||(_(),g(),C.current=!0),o.useEffect(()=>{var n;return(n=s.current)==null||n.addEventListener("initeditingbldr",h),()=>{var t;return(t=s.current)==null?void 0:t.removeEventListener("initeditingbldr",h)}},[]),o.useEffect(()=>{var n;return(n=s.current)==null||n.addEventListener("initpreviewingbldr",x),()=>{var t;return(t=s.current)==null?void 0:t.removeEventListener("initpreviewingbldr",x)}},[]),o.useEffect(()=>{var n,t,i;if(k.isBrowser()){f.isEditing()&&!e.isNestedRender&&s.current&&s.current.dispatchEvent(new CustomEvent("initeditingbldr"));const r=e.builderContextSignal.content&&P.getDefaultCanTrack(e.canTrack),a=M.getCookieSync({name:`builder.tests.${(n=e.builderContextSignal.content)==null?void 0:n.id}`,canTrack:!0}),c=(t=e.builderContextSignal.content)==null?void 0:t.testVariationId;if(r&&c===a){const d=(i=e.builderContextSignal.content)==null?void 0:i.id,l=e.apiKey;y._track({apiHost:e.apiHost,type:"impression",canTrack:!0,contentId:d,apiKey:l,variationId:a!==d?a:void 0})}N.isPreviewing()&&f.isEditing()}},[]),o.useEffect(()=>{},[e.content]),o.useEffect(()=>{g()},[e.builderContextSignal.rootState]),o.useEffect(()=>{e.data&&u(e.data)},[e.data]),o.useEffect(()=>{e.locale&&u({locale:e.locale})},[e.locale]),o.useEffect(()=>()=>{k.isBrowser()&&(window.removeEventListener("message",S),window.removeEventListener("builder:component:stateChangeListenerActivated",g))},[]),R.jsx(V.Provider,{value:e.builderContextSignal,children:e.builderContextSignal.content||L.needsElementRefDivForEditing()?R.jsx(K,{ref:s,onClick:n=>D(n),"builder-content-id":(q=e.builderContextSignal.content)==null?void 0:q.id,"builder-model":e.model,className:Q.getWrapperClassName(((I=e.content)==null?void 0:I.testVariationId)||((w=e.content)==null?void 0:w.id)),style:{display:!e.builderContextSignal.content&&L.needsElementRefDivForEditing()?"none":void 0},...H(),...e.contentWrapperProps,children:e.children}):null})}module.exports=Y;
1
+ "use client";"use strict";const P=require("react/jsx-runtime"),c=require("react"),V=require("../../../context/builder.context.cjs"),B=require("../../../functions/evaluate/evaluate.cjs"),F=require("../../../functions/fast-clone.cjs"),W=require("../../../functions/get-content/index.cjs"),L=require("../../../functions/is-browser.cjs"),m=require("../../../functions/is-editing.cjs"),A=require("../../../functions/is-previewing.cjs"),M=require("../../../functions/log-fetch.cjs"),$=require("../../../functions/register-component.cjs"),T=require("../../../functions/track/index.cjs"),J=require("../../../functions/track/interaction.cjs"),H=require("../../../helpers/canTrack.cjs"),z=require("../../../helpers/cookie.cjs"),G=require("../../../helpers/preview-lru-cache/set.cjs"),Q=require("../../../helpers/subscribe-to-editor.cjs"),X=require("../../../scripts/init-editing.cjs"),Y=require("../../block/animator.cjs"),K=require("./enable-editor.helpers.cjs"),Z=require("./styles.helpers.cjs"),p=require("next/navigation");function ee(e){var I,w,k;const l=c.useRef(null);c.useState(()=>!1);function g(n){var i,r;const t={...e.builderContextSignal.rootState,...n};e.builderContextSignal.rootSetState?(r=(i=e.builderContextSignal).rootSetState)==null||r.call(i,t):e.builderContextSignal.rootState=t}function b(n){var i,r,a,o,d;const t={...e.builderContextSignal.content,...n,data:{...(i=e.builderContextSignal.content)==null?void 0:i.data,...n==null?void 0:n.data},meta:{...(r=e.builderContextSignal.content)==null?void 0:r.meta,...n==null?void 0:n.meta,breakpoints:((a=n==null?void 0:n.meta)==null?void 0:a.breakpoints)||((d=(o=e.builderContextSignal.content)==null?void 0:o.meta)==null?void 0:d.breakpoints)}};G.postPreviewContent({value:t,key:t.id,url:window.location.pathname})}function D(){return e.showContent?{}:{hidden:!0,"aria-hidden":!0}}const[_,te]=c.useState(()=>e.contentWrapper||"div");function h(n){return Q.createEditorListener({model:e.model,trustedHosts:e.trustedHosts,callbacks:{configureSdk:t=>{var a;const{breakpoints:i,contentId:r}=t;!r||r!==((a=e.builderContextSignal.content)==null?void 0:a.id)||i&&b({meta:{breakpoints:i}})},animation:t=>{Y.triggerAnimation(t)},contentUpdate:t=>{b(t)},stateUpdate:t=>{g(t)}}})(n)}const[E,ne]=c.useState(()=>({})),[S,ie]=c.useState(()=>({})),[x,U]=c.useState(()=>!1);function j(n){var t,i;if(e.builderContextSignal.content){const r=(t=e.builderContextSignal.content)==null?void 0:t.testVariationId,a=(i=e.builderContextSignal.content)==null?void 0:i.id;T._track({apiHost:e.apiHost,type:"click",canTrack:H.getDefaultCanTrack(e.canTrack),contentId:a,apiKey:e.apiKey,variationId:r!==a?r:void 0,...J.getInteractionPropertiesForEvent(n),unique:!x})}x||U(!0)}function N(){var t,i,r;const n=(r=(i=(t=e.builderContextSignal.content)==null?void 0:t.data)==null?void 0:i.httpRequests)!=null?r:{};Object.entries(n).forEach(([a,o])=>{if(!o)return;const d=typeof o=="object"&&o["@type"]==="@builder.io/core:Request";if(S[a]||E[a]&&!m.isEditing())return;const v=d?o.request.url:o;S[a]=!0;const R=v.replace(/{{([^}]+)}}/g,(s,O)=>String(B.evaluate({code:O,context:e.context||{},localState:void 0,rootState:e.builderContextSignal.rootState,rootSetState:e.builderContextSignal.rootSetState}))),u=d?{url:R,method:o.request.method,headers:o.request.headers,body:o.request.body}:{url:R,method:"GET"};M.logFetch(JSON.stringify(u)),fetch(u.url,{method:u.method,headers:u.headers,body:u.body}).then(s=>s.json()).then(s=>{g({[a]:s}),E[a]=!0}).catch(s=>{console.error("error fetching dynamic data",JSON.stringify(o),s)}).finally(()=>{S[a]=!1})})}function f(){m.isEditing()&&window.dispatchEvent(new CustomEvent("builder:component:stateChange",{detail:{state:F.fastClone(e.builderContextSignal.rootState),ref:{name:e.model}}}))}function C(n){var t;window.addEventListener("message",h),X.setupBrowserForEditing({...e.locale?{locale:e.locale}:{},...e.enrich?{enrich:e.enrich}:{},...e.trustedHosts?{trustedHosts:e.trustedHosts}:{},modelName:(t=e.model)!=null?t:"",apiKey:e.apiKey}),Object.values(e.builderContextSignal.componentInfos).forEach(i=>{var r,a;if(!((r=i.models)!=null&&r.length)||i.models.includes(e.model)){const o=$.createRegisterComponentMessage(i);(a=window.parent)==null||a.postMessage(o,"*")}}),window.addEventListener("builder:component:stateChangeListenerActivated",f)}function q(n){var o;const t=new URL(location.href).searchParams,i=t.get("builder.preview"),r=t.get(`builder.overrides.${i}`),a=t.get("apiKey")||t.get("builder.space");(i==="BUILDER_STUDIO"||i===e.model&&a===e.apiKey&&(!e.content||r===e.content.id))&&W.fetchOneEntry({model:e.model,apiKey:e.apiKey,apiVersion:e.builderContextSignal.apiVersion,...i==="BUILDER_STUDIO"&&((o=e.context)!=null&&o.symbolId)?{query:{id:e.context.symbolId}}:{}}).then(d=>{d&&b(d)})}p.useRouter();const y=c.useRef(!1);return y.current||(N(),f(),y.current=!0),c.useEffect(()=>{var n;return(n=l.current)==null||n.addEventListener("initeditingbldr",C),()=>{var t;return(t=l.current)==null?void 0:t.removeEventListener("initeditingbldr",C)}},[]),c.useEffect(()=>{var n;return(n=l.current)==null||n.addEventListener("initpreviewingbldr",q),()=>{var t;return(t=l.current)==null?void 0:t.removeEventListener("initpreviewingbldr",q)}},[]),c.useEffect(()=>{var n,t,i;if(L.isBrowser()){m.isEditing()&&!e.isNestedRender&&l.current&&l.current.dispatchEvent(new CustomEvent("initeditingbldr"));const r=e.builderContextSignal.content&&H.getDefaultCanTrack(e.canTrack),a=z.getCookieSync({name:`builder.tests.${(n=e.builderContextSignal.content)==null?void 0:n.id}`,canTrack:!0}),o=(t=e.builderContextSignal.content)==null?void 0:t.testVariationId;if(r&&o===a){const d=(i=e.builderContextSignal.content)==null?void 0:i.id,v=e.apiKey;T._track({apiHost:e.apiHost,type:"impression",canTrack:!0,contentId:d,apiKey:v,variationId:a!==d?a:void 0})}A.isPreviewing()&&m.isEditing()}},[]),c.useEffect(()=>{},[e.content]),c.useEffect(()=>{f()},[e.builderContextSignal.rootState]),c.useEffect(()=>{e.data&&g(e.data)},[e.data]),c.useEffect(()=>{e.locale&&g({locale:e.locale})},[e.locale]),c.useEffect(()=>()=>{L.isBrowser()&&(window.removeEventListener("message",h),window.removeEventListener("builder:component:stateChangeListenerActivated",f))},[]),P.jsx(V.Provider,{value:e.builderContextSignal,children:e.builderContextSignal.content||K.needsElementRefDivForEditing()?P.jsx(_,{ref:l,onClick:n=>j(n),"builder-content-id":(I=e.builderContextSignal.content)==null?void 0:I.id,"builder-model":e.model,className:Z.getWrapperClassName(((w=e.content)==null?void 0:w.testVariationId)||((k=e.content)==null?void 0:k.id)),style:{display:!e.builderContextSignal.content&&K.needsElementRefDivForEditing()?"none":void 0},...D(),...e.contentWrapperProps,children:e.children}):null})}module.exports=ee;