@builder.io/sdk-react-nextjs 0.19.3 → 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.
- package/lib/browser/components/content/components/enable-editor.cjs +1 -1
- package/lib/browser/components/content/components/enable-editor.mjs +198 -176
- package/lib/browser/constants/sdk-version.cjs +1 -1
- package/lib/browser/constants/sdk-version.mjs +1 -1
- package/lib/edge/components/content/components/enable-editor.cjs +1 -1
- package/lib/edge/components/content/components/enable-editor.mjs +198 -176
- package/lib/edge/constants/sdk-version.cjs +1 -1
- package/lib/edge/constants/sdk-version.mjs +1 -1
- package/lib/node/components/content/components/enable-editor.cjs +1 -1
- package/lib/node/components/content/components/enable-editor.mjs +198 -176
- package/lib/node/constants/sdk-version.cjs +1 -1
- package/lib/node/constants/sdk-version.mjs +1 -1
- package/package.json +1 -1
- package/types/cjs/constants/sdk-version.d.ts +1 -1
- package/types/esm/constants/sdk-version.d.ts +1 -1
|
@@ -1,282 +1,304 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { useRef as
|
|
4
|
-
import
|
|
5
|
-
import { evaluate as
|
|
6
|
-
import { fastClone as
|
|
7
|
-
import { fetchOneEntry as
|
|
8
|
-
import { isBrowser as
|
|
9
|
-
import { isEditing as
|
|
10
|
-
import { isPreviewing as
|
|
11
|
-
import { logFetch as
|
|
12
|
-
import { createRegisterComponentMessage as
|
|
13
|
-
import { _track as
|
|
14
|
-
import { getInteractionPropertiesForEvent as
|
|
15
|
-
import { getDefaultCanTrack as
|
|
16
|
-
import { getCookieSync as
|
|
17
|
-
import { postPreviewContent as
|
|
18
|
-
import { createEditorListener as
|
|
19
|
-
import { setupBrowserForEditing as
|
|
20
|
-
import { triggerAnimation as
|
|
21
|
-
import { needsElementRefDivForEditing as
|
|
22
|
-
import { getWrapperClassName as
|
|
23
|
-
import { useRouter as
|
|
24
|
-
function
|
|
25
|
-
var
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
function
|
|
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
|
|
31
|
-
...
|
|
30
|
+
const t = {
|
|
31
|
+
...e.builderContextSignal.rootState,
|
|
32
32
|
...n
|
|
33
33
|
};
|
|
34
|
-
|
|
34
|
+
e.builderContextSignal.rootSetState ? (o = (i = e.builderContextSignal).rootSetState) == null || o.call(i, t) : e.builderContextSignal.rootState = t;
|
|
35
35
|
}
|
|
36
|
-
function
|
|
36
|
+
function S(n) {
|
|
37
37
|
var i, o, a, r, d;
|
|
38
|
-
const
|
|
39
|
-
...
|
|
38
|
+
const t = {
|
|
39
|
+
...e.builderContextSignal.content,
|
|
40
40
|
...n,
|
|
41
41
|
data: {
|
|
42
|
-
...(i =
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
52
|
-
value:
|
|
53
|
-
key:
|
|
51
|
+
X({
|
|
52
|
+
value: t,
|
|
53
|
+
key: t.id,
|
|
54
54
|
url: window.location.pathname
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
|
-
function
|
|
58
|
-
return
|
|
57
|
+
function N() {
|
|
58
|
+
return e.showContent ? {} : {
|
|
59
59
|
hidden: !0,
|
|
60
60
|
"aria-hidden": !0
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
|
-
const [
|
|
64
|
-
() =>
|
|
63
|
+
const [O, ne] = s(
|
|
64
|
+
() => e.contentWrapper || "div"
|
|
65
65
|
);
|
|
66
|
-
function
|
|
67
|
-
return
|
|
68
|
-
model:
|
|
69
|
-
trustedHosts:
|
|
66
|
+
function x(n) {
|
|
67
|
+
return Y({
|
|
68
|
+
model: e.model,
|
|
69
|
+
trustedHosts: e.trustedHosts,
|
|
70
70
|
callbacks: {
|
|
71
|
-
configureSdk: (
|
|
71
|
+
configureSdk: (t) => {
|
|
72
72
|
var a;
|
|
73
|
-
const { breakpoints: i, contentId: o } =
|
|
74
|
-
!o || o !== ((a =
|
|
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: (
|
|
81
|
-
|
|
80
|
+
animation: (t) => {
|
|
81
|
+
p(t);
|
|
82
82
|
},
|
|
83
|
-
contentUpdate: (
|
|
84
|
-
|
|
83
|
+
contentUpdate: (t) => {
|
|
84
|
+
S(t);
|
|
85
85
|
},
|
|
86
|
-
stateUpdate: (
|
|
87
|
-
|
|
86
|
+
stateUpdate: (t) => {
|
|
87
|
+
f(t);
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
})(n);
|
|
91
91
|
}
|
|
92
|
-
const [
|
|
93
|
-
function
|
|
94
|
-
var
|
|
95
|
-
if (
|
|
96
|
-
const o = (
|
|
97
|
-
|
|
98
|
-
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:
|
|
100
|
+
canTrack: q(e.canTrack),
|
|
101
101
|
contentId: a,
|
|
102
|
-
apiKey:
|
|
102
|
+
apiKey: e.apiKey,
|
|
103
103
|
variationId: o !== a ? o : void 0,
|
|
104
|
-
|
|
105
|
-
unique: !
|
|
104
|
+
...G(n),
|
|
105
|
+
unique: !y
|
|
106
106
|
});
|
|
107
107
|
}
|
|
108
|
-
|
|
108
|
+
y || V(!0);
|
|
109
109
|
}
|
|
110
|
-
function
|
|
111
|
-
var
|
|
112
|
-
const n = (o = (i = (
|
|
113
|
-
Object.entries(n).forEach(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
|
141
|
-
|
|
162
|
+
function g() {
|
|
163
|
+
b() && window.dispatchEvent(
|
|
142
164
|
new CustomEvent(
|
|
143
165
|
"builder:component:stateChange",
|
|
144
166
|
{
|
|
145
167
|
detail: {
|
|
146
|
-
state:
|
|
168
|
+
state: F(e.builderContextSignal.rootState),
|
|
147
169
|
ref: {
|
|
148
|
-
name:
|
|
170
|
+
name: e.model
|
|
149
171
|
}
|
|
150
172
|
}
|
|
151
173
|
}
|
|
152
174
|
)
|
|
153
175
|
);
|
|
154
176
|
}
|
|
155
|
-
function
|
|
156
|
-
var
|
|
157
|
-
window.addEventListener("message",
|
|
158
|
-
...
|
|
159
|
-
locale:
|
|
177
|
+
function E(n) {
|
|
178
|
+
var t;
|
|
179
|
+
window.addEventListener("message", x), Z({
|
|
180
|
+
...e.locale ? {
|
|
181
|
+
locale: e.locale
|
|
160
182
|
} : {},
|
|
161
|
-
...
|
|
162
|
-
enrich:
|
|
183
|
+
...e.enrich ? {
|
|
184
|
+
enrich: e.enrich
|
|
163
185
|
} : {},
|
|
164
|
-
...
|
|
165
|
-
trustedHosts:
|
|
186
|
+
...e.trustedHosts ? {
|
|
187
|
+
trustedHosts: e.trustedHosts
|
|
166
188
|
} : {},
|
|
167
|
-
modelName: (
|
|
168
|
-
apiKey:
|
|
189
|
+
modelName: (t = e.model) != null ? t : "",
|
|
190
|
+
apiKey: e.apiKey
|
|
169
191
|
}), Object.values(
|
|
170
|
-
|
|
192
|
+
e.builderContextSignal.componentInfos
|
|
171
193
|
).forEach((i) => {
|
|
172
194
|
var o, a;
|
|
173
|
-
if (!((o = i.models) != null && o.length) || i.models.includes(
|
|
174
|
-
const r =
|
|
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
|
-
|
|
201
|
+
g
|
|
180
202
|
);
|
|
181
203
|
}
|
|
182
|
-
function
|
|
204
|
+
function I(n) {
|
|
183
205
|
var r;
|
|
184
|
-
const
|
|
206
|
+
const t = new URL(location.href).searchParams, i = t.get("builder.preview"), o = t.get(
|
|
185
207
|
`builder.overrides.${i}`
|
|
186
|
-
), a =
|
|
187
|
-
(i === "BUILDER_STUDIO" || i ===
|
|
188
|
-
model:
|
|
189
|
-
apiKey:
|
|
190
|
-
apiVersion:
|
|
191
|
-
...i === "BUILDER_STUDIO" && ((r =
|
|
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:
|
|
215
|
+
id: e.context.symbolId
|
|
194
216
|
}
|
|
195
217
|
} : {}
|
|
196
218
|
}).then((d) => {
|
|
197
|
-
d &&
|
|
219
|
+
d && S(d);
|
|
198
220
|
});
|
|
199
221
|
}
|
|
200
|
-
|
|
201
|
-
const
|
|
202
|
-
return
|
|
222
|
+
te();
|
|
223
|
+
const w = K(!1);
|
|
224
|
+
return w.current || (_(), g(), w.current = !0), l(() => {
|
|
203
225
|
var n;
|
|
204
|
-
return (n =
|
|
226
|
+
return (n = c.current) == null || n.addEventListener(
|
|
205
227
|
"initeditingbldr",
|
|
206
|
-
|
|
228
|
+
E
|
|
207
229
|
), () => {
|
|
208
|
-
var
|
|
209
|
-
return (
|
|
230
|
+
var t;
|
|
231
|
+
return (t = c.current) == null ? void 0 : t.removeEventListener(
|
|
210
232
|
"initeditingbldr",
|
|
211
|
-
|
|
233
|
+
E
|
|
212
234
|
);
|
|
213
235
|
};
|
|
214
|
-
}, []),
|
|
236
|
+
}, []), l(() => {
|
|
215
237
|
var n;
|
|
216
|
-
return (n =
|
|
238
|
+
return (n = c.current) == null || n.addEventListener(
|
|
217
239
|
"initpreviewingbldr",
|
|
218
|
-
|
|
240
|
+
I
|
|
219
241
|
), () => {
|
|
220
|
-
var
|
|
221
|
-
return (
|
|
242
|
+
var t;
|
|
243
|
+
return (t = c.current) == null ? void 0 : t.removeEventListener(
|
|
222
244
|
"initpreviewingbldr",
|
|
223
|
-
|
|
245
|
+
I
|
|
224
246
|
);
|
|
225
247
|
};
|
|
226
|
-
}, []),
|
|
227
|
-
var n,
|
|
228
|
-
if (
|
|
229
|
-
|
|
230
|
-
const o =
|
|
231
|
-
name: `builder.tests.${(n =
|
|
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 = (
|
|
255
|
+
}), r = (t = e.builderContextSignal.content) == null ? void 0 : t.testVariationId;
|
|
234
256
|
if (o && r === a) {
|
|
235
|
-
const d = (i =
|
|
236
|
-
|
|
237
|
-
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:
|
|
263
|
+
apiKey: h,
|
|
242
264
|
variationId: a !== d ? a : void 0
|
|
243
265
|
});
|
|
244
266
|
}
|
|
245
|
-
|
|
267
|
+
J() && b();
|
|
246
268
|
}
|
|
247
|
-
}, []),
|
|
248
|
-
}, [
|
|
249
|
-
|
|
250
|
-
}, [
|
|
251
|
-
|
|
252
|
-
}, [
|
|
253
|
-
|
|
254
|
-
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
|
-
}, [
|
|
257
|
-
|
|
278
|
+
}, [e.locale]), l(() => () => {
|
|
279
|
+
T() && (window.removeEventListener("message", x), window.removeEventListener(
|
|
258
280
|
"builder:component:stateChangeListenerActivated",
|
|
259
|
-
|
|
281
|
+
g
|
|
260
282
|
));
|
|
261
|
-
}, []), /* @__PURE__ */
|
|
262
|
-
|
|
283
|
+
}, []), /* @__PURE__ */ H(A.Provider, { value: e.builderContextSignal, children: e.builderContextSignal.content || D() ? /* @__PURE__ */ H(
|
|
284
|
+
O,
|
|
263
285
|
{
|
|
264
|
-
ref:
|
|
265
|
-
onClick: (n) =>
|
|
266
|
-
"builder-content-id": (
|
|
267
|
-
"builder-model":
|
|
268
|
-
className:
|
|
269
|
-
((
|
|
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: !
|
|
294
|
+
display: !e.builderContextSignal.content && D() ? "none" : void 0
|
|
273
295
|
},
|
|
274
|
-
...
|
|
275
|
-
...
|
|
276
|
-
children:
|
|
296
|
+
...N(),
|
|
297
|
+
...e.contentWrapperProps,
|
|
298
|
+
children: e.children
|
|
277
299
|
}
|
|
278
300
|
) : null });
|
|
279
301
|
}
|
|
280
302
|
export {
|
|
281
|
-
|
|
303
|
+
Le as default
|
|
282
304
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e="0.
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e="0.20.0";exports.SDK_VERSION=e;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";const
|
|
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;
|