@builder.io/sdk-react-nextjs 0.18.0 → 0.18.2
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 +73 -63
- package/lib/browser/constants/sdk-version.cjs +1 -1
- package/lib/browser/constants/sdk-version.mjs +1 -1
- package/lib/browser/helpers/subscribe-to-editor.cjs +1 -1
- package/lib/browser/helpers/subscribe-to-editor.mjs +31 -24
- package/lib/edge/components/content/components/enable-editor.cjs +1 -1
- package/lib/edge/components/content/components/enable-editor.mjs +73 -63
- package/lib/edge/constants/sdk-version.cjs +1 -1
- package/lib/edge/constants/sdk-version.mjs +1 -1
- package/lib/edge/helpers/subscribe-to-editor.cjs +1 -1
- package/lib/edge/helpers/subscribe-to-editor.mjs +31 -24
- package/lib/node/components/content/components/enable-editor.cjs +1 -1
- package/lib/node/components/content/components/enable-editor.mjs +73 -63
- package/lib/node/constants/sdk-version.cjs +1 -1
- package/lib/node/constants/sdk-version.mjs +1 -1
- package/lib/node/helpers/subscribe-to-editor.cjs +1 -1
- package/lib/node/helpers/subscribe-to-editor.mjs +31 -24
- package/package.json +1 -1
- package/types/cjs/constants/sdk-version.d.ts +1 -1
- package/types/cjs/helpers/subscribe-to-editor.d.ts +2 -0
- package/types/esm/constants/sdk-version.d.ts +1 -1
- package/types/esm/helpers/subscribe-to-editor.d.ts +2 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";const
|
|
1
|
+
"use client";"use strict";const k=require("react/jsx-runtime"),o=require("react"),B=require("../../../context/builder.context.cjs"),F=require("../../../functions/evaluate/evaluate.cjs"),N=require("../../../functions/fast-clone.cjs"),M=require("../../../functions/get-content/index.cjs"),w=require("../../../functions/is-browser.cjs"),f=require("../../../functions/is-editing.cjs"),O=require("../../../functions/is-previewing.cjs"),W=require("../../../functions/log-fetch.cjs"),A=require("../../../functions/register-component.cjs"),y=require("../../../functions/track/index.cjs"),$=require("../../../functions/track/interaction.cjs"),P=require("../../../helpers/canTrack.cjs"),z=require("../../../helpers/cookie.cjs"),G=require("../../../helpers/preview-lru-cache/set.cjs"),J=require("../../../helpers/subscribe-to-editor.cjs"),L=require("../../../scripts/init-editing.cjs"),Q=require("../../block/animator.cjs"),H=require("./enable-editor.helpers.cjs"),X=require("./styles.helpers.cjs"),Y=require("next/navigation");function Z(e){var q,I,R;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)}};G.postPreviewContent({value:t,key:t.id}).then(()=>{V.refresh()})}function K(){return e.showContent?{}:{hidden:!0,"aria-hidden":!0}}const[T,p]=o.useState(()=>e.contentWrapper||"div");function S(n){return J.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=>{Q.triggerAnimation(t)},contentUpdate:t=>{m(t)},stateUpdate:t=>{u(t)}}})(n)}const[v,ee]=o.useState(()=>({})),[b,te]=o.useState(()=>({})),[h,D]=o.useState(()=>!1);function _(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,...$.getInteractionPropertiesForEvent(n),unique:!h})}h||D(!0)}function U(){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,j)=>String(F.evaluate({code:j,context:e.context||{},localState:void 0,rootState:e.builderContextSignal.rootState,rootSetState:e.builderContextSignal.rootSetState})));W.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:N.fastClone(e.builderContextSignal.rootState),ref:{name:e.model}}}))}function E(n){var t;window.addEventListener("message",S),L.registerInsertMenu(),L.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=A.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))&&M.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)})}const V=Y.useRouter(),C=o.useRef(!1);return C.current||(U(),g(),C.current=!0),o.useEffect(()=>{var n;return(n=s.current)==null||n.addEventListener("initeditingbldr",E),()=>{var t;return(t=s.current)==null?void 0:t.removeEventListener("initeditingbldr",E)}},[]),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(w.isBrowser()){f.isEditing()&&!e.isNestedRender&&s.current&&s.current.dispatchEvent(new CustomEvent("initeditingbldr"));const r=e.builderContextSignal.content&&P.getDefaultCanTrack(e.canTrack),a=z.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})}O.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(()=>()=>{w.isBrowser()&&(window.removeEventListener("message",S),window.removeEventListener("builder:component:stateChangeListenerActivated",g))},[]),k.jsx(B.Provider,{value:e.builderContextSignal,children:e.builderContextSignal.content||H.needsElementRefDivForEditing()?k.jsx(T,{ref:s,onClick:n=>_(n),"builder-content-id":(q=e.builderContextSignal.content)==null?void 0:q.id,"builder-model":e.model,className:X.getWrapperClassName(((I=e.content)==null?void 0:I.testVariationId)||((R=e.content)==null?void 0:R.id)),style:{display:!e.builderContextSignal.content&&H.needsElementRefDivForEditing()?"none":void 0},...K(),...e.contentWrapperProps,children:e.children}):null})}module.exports=Z;
|
|
@@ -1,29 +1,31 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as k } from "react/jsx-runtime";
|
|
3
|
-
import { useRef as P, useState as
|
|
3
|
+
import { useRef as P, useState as m, useEffect as c } from "react";
|
|
4
4
|
import O from "../../../context/builder.context.mjs";
|
|
5
5
|
import { evaluate as W } from "../../../functions/evaluate/evaluate.mjs";
|
|
6
6
|
import { fastClone as j } from "../../../functions/fast-clone.mjs";
|
|
7
7
|
import { fetchOneEntry as A } from "../../../functions/get-content/index.mjs";
|
|
8
8
|
import { isBrowser as L } from "../../../functions/is-browser.mjs";
|
|
9
|
-
import { isEditing as
|
|
9
|
+
import { isEditing as g } from "../../../functions/is-editing.mjs";
|
|
10
10
|
import { isPreviewing as B } from "../../../functions/is-previewing.mjs";
|
|
11
11
|
import { logFetch as F } from "../../../functions/log-fetch.mjs";
|
|
12
|
-
import { createRegisterComponentMessage as
|
|
12
|
+
import { createRegisterComponentMessage as $ } from "../../../functions/register-component.mjs";
|
|
13
13
|
import { _track as H } from "../../../functions/track/index.mjs";
|
|
14
|
-
import { getInteractionPropertiesForEvent as
|
|
14
|
+
import { getInteractionPropertiesForEvent as z } from "../../../functions/track/interaction.mjs";
|
|
15
15
|
import { getDefaultCanTrack as K } from "../../../helpers/canTrack.mjs";
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
16
|
+
import { getCookieSync as G } from "../../../helpers/cookie.mjs";
|
|
17
|
+
import { postPreviewContent as J } from "../../../helpers/preview-lru-cache/set.mjs";
|
|
18
|
+
import { createEditorListener as Q } from "../../../helpers/subscribe-to-editor.mjs";
|
|
19
|
+
import { registerInsertMenu as X, setupBrowserForEditing as Y } from "../../../scripts/init-editing.mjs";
|
|
20
|
+
import { triggerAnimation as Z } from "../../block/animator.mjs";
|
|
20
21
|
import { needsElementRefDivForEditing as q } from "./enable-editor.helpers.mjs";
|
|
21
|
-
import { getWrapperClassName as
|
|
22
|
-
import { useRouter as
|
|
23
|
-
function
|
|
22
|
+
import { getWrapperClassName as p } from "./styles.helpers.mjs";
|
|
23
|
+
import { useRouter as ee } from "next/navigation";
|
|
24
|
+
function ke(e) {
|
|
24
25
|
var y, R, w;
|
|
25
|
-
const
|
|
26
|
-
|
|
26
|
+
const u = P(null);
|
|
27
|
+
m(() => !1);
|
|
28
|
+
function s(n) {
|
|
27
29
|
var i, r;
|
|
28
30
|
const t = {
|
|
29
31
|
...e.builderContextSignal.rootState,
|
|
@@ -46,7 +48,7 @@ function Re(e) {
|
|
|
46
48
|
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)
|
|
47
49
|
}
|
|
48
50
|
};
|
|
49
|
-
|
|
51
|
+
J({
|
|
50
52
|
value: t,
|
|
51
53
|
key: t.id
|
|
52
54
|
}).then(() => {
|
|
@@ -59,11 +61,11 @@ function Re(e) {
|
|
|
59
61
|
"aria-hidden": !0
|
|
60
62
|
};
|
|
61
63
|
}
|
|
62
|
-
const [
|
|
64
|
+
const [U, te] = m(
|
|
63
65
|
() => e.contentWrapper || "div"
|
|
64
66
|
);
|
|
65
67
|
function v(n) {
|
|
66
|
-
return
|
|
68
|
+
return Q({
|
|
67
69
|
model: e.model,
|
|
68
70
|
trustedHosts: e.trustedHosts,
|
|
69
71
|
callbacks: {
|
|
@@ -77,16 +79,19 @@ function Re(e) {
|
|
|
77
79
|
});
|
|
78
80
|
},
|
|
79
81
|
animation: (t) => {
|
|
80
|
-
|
|
82
|
+
Z(t);
|
|
81
83
|
},
|
|
82
84
|
contentUpdate: (t) => {
|
|
83
85
|
b(t);
|
|
86
|
+
},
|
|
87
|
+
stateUpdate: (t) => {
|
|
88
|
+
s(t);
|
|
84
89
|
}
|
|
85
90
|
}
|
|
86
91
|
})(n);
|
|
87
92
|
}
|
|
88
|
-
const [h,
|
|
89
|
-
function
|
|
93
|
+
const [h, ne] = m(() => ({})), [S, ie] = m(() => ({})), [x, D] = m(() => !1);
|
|
94
|
+
function V(n) {
|
|
90
95
|
var t, i;
|
|
91
96
|
if (e.builderContextSignal.content) {
|
|
92
97
|
const r = (t = e.builderContextSignal.content) == null ? void 0 : t.testVariationId, a = (i = e.builderContextSignal.content) == null ? void 0 : i.id;
|
|
@@ -97,22 +102,22 @@ function Re(e) {
|
|
|
97
102
|
contentId: a,
|
|
98
103
|
apiKey: e.apiKey,
|
|
99
104
|
variationId: r !== a ? r : void 0,
|
|
100
|
-
|
|
105
|
+
...z(n),
|
|
101
106
|
unique: !x
|
|
102
107
|
});
|
|
103
108
|
}
|
|
104
|
-
x ||
|
|
109
|
+
x || D(!0);
|
|
105
110
|
}
|
|
106
|
-
function
|
|
111
|
+
function N() {
|
|
107
112
|
var t, i, r;
|
|
108
113
|
const n = (r = (i = (t = e.builderContextSignal.content) == null ? void 0 : t.data) == null ? void 0 : i.httpRequests) != null ? r : {};
|
|
109
114
|
Object.entries(n).forEach(([a, o]) => {
|
|
110
|
-
if (!o || S[a] || h[a] && !
|
|
115
|
+
if (!o || S[a] || h[a] && !g())
|
|
111
116
|
return;
|
|
112
117
|
S[a] = !0;
|
|
113
118
|
const d = o.replace(
|
|
114
119
|
/{{([^}]+)}}/g,
|
|
115
|
-
(
|
|
120
|
+
(l, M) => String(
|
|
116
121
|
W({
|
|
117
122
|
code: M,
|
|
118
123
|
context: e.context || {},
|
|
@@ -122,19 +127,19 @@ function Re(e) {
|
|
|
122
127
|
})
|
|
123
128
|
)
|
|
124
129
|
);
|
|
125
|
-
F(d), fetch(d).then((
|
|
126
|
-
|
|
127
|
-
[a]:
|
|
130
|
+
F(d), fetch(d).then((l) => l.json()).then((l) => {
|
|
131
|
+
s({
|
|
132
|
+
[a]: l
|
|
128
133
|
}), h[a] = !0;
|
|
129
|
-
}).catch((
|
|
130
|
-
console.error("error fetching dynamic data", o,
|
|
134
|
+
}).catch((l) => {
|
|
135
|
+
console.error("error fetching dynamic data", o, l);
|
|
131
136
|
}).finally(() => {
|
|
132
137
|
S[a] = !1;
|
|
133
138
|
});
|
|
134
139
|
});
|
|
135
140
|
}
|
|
136
|
-
function
|
|
137
|
-
|
|
141
|
+
function f() {
|
|
142
|
+
g() && window.dispatchEvent(
|
|
138
143
|
new CustomEvent(
|
|
139
144
|
"builder:component:stateChange",
|
|
140
145
|
{
|
|
@@ -150,7 +155,7 @@ function Re(e) {
|
|
|
150
155
|
}
|
|
151
156
|
function C(n) {
|
|
152
157
|
var t;
|
|
153
|
-
window.addEventListener("message", v),
|
|
158
|
+
window.addEventListener("message", v), X(), Y({
|
|
154
159
|
...e.locale ? {
|
|
155
160
|
locale: e.locale
|
|
156
161
|
} : {},
|
|
@@ -167,12 +172,12 @@ function Re(e) {
|
|
|
167
172
|
).forEach((i) => {
|
|
168
173
|
var r, a;
|
|
169
174
|
if (!((r = i.models) != null && r.length) || i.models.includes(e.model)) {
|
|
170
|
-
const o =
|
|
175
|
+
const o = $(i);
|
|
171
176
|
(a = window.parent) == null || a.postMessage(o, "*");
|
|
172
177
|
}
|
|
173
178
|
}), window.addEventListener(
|
|
174
179
|
"builder:component:stateChangeListenerActivated",
|
|
175
|
-
|
|
180
|
+
f
|
|
176
181
|
);
|
|
177
182
|
}
|
|
178
183
|
function E(n) {
|
|
@@ -193,69 +198,74 @@ function Re(e) {
|
|
|
193
198
|
d && b(d);
|
|
194
199
|
});
|
|
195
200
|
}
|
|
196
|
-
const _ =
|
|
197
|
-
return I.current || (
|
|
201
|
+
const _ = ee(), I = P(!1);
|
|
202
|
+
return I.current || (N(), f(), I.current = !0), c(() => {
|
|
198
203
|
var n;
|
|
199
|
-
return (n =
|
|
204
|
+
return (n = u.current) == null || n.addEventListener(
|
|
200
205
|
"initeditingbldr",
|
|
201
206
|
C
|
|
202
207
|
), () => {
|
|
203
208
|
var t;
|
|
204
|
-
return (t =
|
|
209
|
+
return (t = u.current) == null ? void 0 : t.removeEventListener(
|
|
205
210
|
"initeditingbldr",
|
|
206
211
|
C
|
|
207
212
|
);
|
|
208
213
|
};
|
|
209
|
-
}, []),
|
|
214
|
+
}, []), c(() => {
|
|
210
215
|
var n;
|
|
211
|
-
return (n =
|
|
216
|
+
return (n = u.current) == null || n.addEventListener(
|
|
212
217
|
"initpreviewingbldr",
|
|
213
218
|
E
|
|
214
219
|
), () => {
|
|
215
220
|
var t;
|
|
216
|
-
return (t =
|
|
221
|
+
return (t = u.current) == null ? void 0 : t.removeEventListener(
|
|
217
222
|
"initpreviewingbldr",
|
|
218
223
|
E
|
|
219
224
|
);
|
|
220
225
|
};
|
|
221
|
-
}, []),
|
|
222
|
-
var n, t;
|
|
226
|
+
}, []), c(() => {
|
|
227
|
+
var n, t, i;
|
|
223
228
|
if (L()) {
|
|
224
|
-
|
|
225
|
-
|
|
229
|
+
g() && !e.isNestedRender && u.current && u.current.dispatchEvent(new CustomEvent("initeditingbldr"));
|
|
230
|
+
const r = e.builderContextSignal.content && K(e.canTrack), a = G({
|
|
231
|
+
name: `builder.tests.${(n = e.builderContextSignal.content) == null ? void 0 : n.id}`,
|
|
232
|
+
canTrack: !0
|
|
233
|
+
}), o = (t = e.builderContextSignal.content) == null ? void 0 : t.testVariationId;
|
|
234
|
+
if (r && o === a) {
|
|
235
|
+
const d = (i = e.builderContextSignal.content) == null ? void 0 : i.id, l = e.apiKey;
|
|
226
236
|
H({
|
|
227
237
|
apiHost: e.apiHost,
|
|
228
238
|
type: "impression",
|
|
229
239
|
canTrack: !0,
|
|
230
|
-
contentId:
|
|
231
|
-
apiKey:
|
|
232
|
-
variationId:
|
|
240
|
+
contentId: d,
|
|
241
|
+
apiKey: l,
|
|
242
|
+
variationId: a !== d ? a : void 0
|
|
233
243
|
});
|
|
234
244
|
}
|
|
235
|
-
B() &&
|
|
245
|
+
B() && g();
|
|
236
246
|
}
|
|
237
|
-
}, []),
|
|
238
|
-
}, [e.content]),
|
|
239
|
-
|
|
240
|
-
}, [e.builderContextSignal.rootState]),
|
|
241
|
-
e.data &&
|
|
242
|
-
}, [e.data]),
|
|
243
|
-
e.locale &&
|
|
247
|
+
}, []), c(() => {
|
|
248
|
+
}, [e.content]), c(() => {
|
|
249
|
+
f();
|
|
250
|
+
}, [e.builderContextSignal.rootState]), c(() => {
|
|
251
|
+
e.data && s(e.data);
|
|
252
|
+
}, [e.data]), c(() => {
|
|
253
|
+
e.locale && s({
|
|
244
254
|
locale: e.locale
|
|
245
255
|
});
|
|
246
|
-
}, [e.locale]),
|
|
256
|
+
}, [e.locale]), c(() => () => {
|
|
247
257
|
L() && (window.removeEventListener("message", v), window.removeEventListener(
|
|
248
258
|
"builder:component:stateChangeListenerActivated",
|
|
249
|
-
|
|
259
|
+
f
|
|
250
260
|
));
|
|
251
261
|
}, []), /* @__PURE__ */ k(O.Provider, { value: e.builderContextSignal, children: e.builderContextSignal.content || q() ? /* @__PURE__ */ k(
|
|
252
|
-
|
|
262
|
+
U,
|
|
253
263
|
{
|
|
254
|
-
ref:
|
|
255
|
-
onClick: (n) =>
|
|
264
|
+
ref: u,
|
|
265
|
+
onClick: (n) => V(n),
|
|
256
266
|
"builder-content-id": (y = e.builderContextSignal.content) == null ? void 0 : y.id,
|
|
257
267
|
"builder-model": e.model,
|
|
258
|
-
className:
|
|
268
|
+
className: p(
|
|
259
269
|
((R = e.content) == null ? void 0 : R.testVariationId) || ((w = e.content) == null ? void 0 : w.id)
|
|
260
270
|
),
|
|
261
271
|
style: {
|
|
@@ -268,5 +278,5 @@ function Re(e) {
|
|
|
268
278
|
) : null });
|
|
269
279
|
}
|
|
270
280
|
export {
|
|
271
|
-
|
|
281
|
+
ke as default
|
|
272
282
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e="0.18.
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e="0.18.2";exports.SDK_VERSION=e;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../functions/is-browser.cjs"),u=require("../functions/is-from-trusted-host.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../functions/is-browser.cjs"),u=require("../functions/is-from-trusted-host.cjs"),b=require("../scripts/init-editing.cjs"),g=require("./logger.cjs"),d=({model:n,trustedHosts:i,callbacks:r})=>o=>{if(!u.isFromTrustedHost(i,o))return;const{data:t}=o;if(t)switch(t.type){case"builder.configureSdk":{r.configureSdk(t.data);break}case"builder.triggerAnimation":{r.animation(t.data);break}case"builder.resetState":{const e=t.data,a=e.model,s=e==null?void 0:e.state;a===n&&s&&r.stateUpdate(s);break}case"builder.contentUpdate":{const e=t.data,a=e.key||e.alias||e.entry||e.modelName,s=e.data;a===n&&r.contentUpdate(s);break}}},m=({model:n,apiKey:i,callback:r,trustedHosts:o})=>{if(!c.isBrowser)return g.logger.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server."),()=>{};b.setupBrowserForEditing({modelName:n,apiKey:i});const t=d({callbacks:{contentUpdate:r,animation:()=>{},configureSdk:()=>{},stateUpdate:()=>{}},model:n,trustedHosts:o});return window.addEventListener("message",t),()=>{window.removeEventListener("message",t)}};exports.createEditorListener=d;exports.subscribeToEditor=m;
|
|
@@ -2,61 +2,68 @@ import { isBrowser as d } from "../functions/is-browser.mjs";
|
|
|
2
2
|
import { isFromTrustedHost as c } from "../functions/is-from-trusted-host.mjs";
|
|
3
3
|
import { setupBrowserForEditing as m } from "../scripts/init-editing.mjs";
|
|
4
4
|
import { logger as u } from "./logger.mjs";
|
|
5
|
-
const
|
|
6
|
-
model:
|
|
5
|
+
const b = ({
|
|
6
|
+
model: o,
|
|
7
7
|
trustedHosts: i,
|
|
8
|
-
callbacks:
|
|
9
|
-
}) => (
|
|
10
|
-
if (!c(i,
|
|
8
|
+
callbacks: r
|
|
9
|
+
}) => (n) => {
|
|
10
|
+
if (!c(i, n))
|
|
11
11
|
return;
|
|
12
12
|
const {
|
|
13
|
-
data:
|
|
14
|
-
} =
|
|
15
|
-
if (
|
|
16
|
-
switch (
|
|
13
|
+
data: t
|
|
14
|
+
} = n;
|
|
15
|
+
if (t)
|
|
16
|
+
switch (t.type) {
|
|
17
17
|
case "builder.configureSdk": {
|
|
18
|
-
|
|
18
|
+
r.configureSdk(t.data);
|
|
19
19
|
break;
|
|
20
20
|
}
|
|
21
21
|
case "builder.triggerAnimation": {
|
|
22
|
-
|
|
22
|
+
r.animation(t.data);
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
case "builder.resetState": {
|
|
26
|
+
const e = t.data, s = e.model, a = e == null ? void 0 : e.state;
|
|
27
|
+
s === o && a && r.stateUpdate(a);
|
|
23
28
|
break;
|
|
24
29
|
}
|
|
25
30
|
case "builder.contentUpdate": {
|
|
26
|
-
const
|
|
27
|
-
s ===
|
|
31
|
+
const e = t.data, s = e.key || e.alias || e.entry || e.modelName, a = e.data;
|
|
32
|
+
s === o && r.contentUpdate(a);
|
|
28
33
|
break;
|
|
29
34
|
}
|
|
30
35
|
}
|
|
31
36
|
}, k = ({
|
|
32
|
-
model:
|
|
37
|
+
model: o,
|
|
33
38
|
apiKey: i,
|
|
34
|
-
callback:
|
|
35
|
-
trustedHosts:
|
|
39
|
+
callback: r,
|
|
40
|
+
trustedHosts: n
|
|
36
41
|
}) => {
|
|
37
42
|
if (!d)
|
|
38
43
|
return u.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server."), () => {
|
|
39
44
|
};
|
|
40
45
|
m({
|
|
41
|
-
modelName:
|
|
46
|
+
modelName: o,
|
|
42
47
|
apiKey: i
|
|
43
48
|
});
|
|
44
|
-
const
|
|
49
|
+
const t = b({
|
|
45
50
|
callbacks: {
|
|
46
|
-
contentUpdate:
|
|
51
|
+
contentUpdate: r,
|
|
47
52
|
animation: () => {
|
|
48
53
|
},
|
|
49
54
|
configureSdk: () => {
|
|
55
|
+
},
|
|
56
|
+
stateUpdate: () => {
|
|
50
57
|
}
|
|
51
58
|
},
|
|
52
|
-
model:
|
|
53
|
-
trustedHosts:
|
|
59
|
+
model: o,
|
|
60
|
+
trustedHosts: n
|
|
54
61
|
});
|
|
55
|
-
return window.addEventListener("message",
|
|
56
|
-
window.removeEventListener("message",
|
|
62
|
+
return window.addEventListener("message", t), () => {
|
|
63
|
+
window.removeEventListener("message", t);
|
|
57
64
|
};
|
|
58
65
|
};
|
|
59
66
|
export {
|
|
60
|
-
|
|
67
|
+
b as createEditorListener,
|
|
61
68
|
k as subscribeToEditor
|
|
62
69
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";const
|
|
1
|
+
"use client";"use strict";const k=require("react/jsx-runtime"),o=require("react"),B=require("../../../context/builder.context.cjs"),F=require("../../../functions/evaluate/evaluate.cjs"),N=require("../../../functions/fast-clone.cjs"),M=require("../../../functions/get-content/index.cjs"),w=require("../../../functions/is-browser.cjs"),f=require("../../../functions/is-editing.cjs"),O=require("../../../functions/is-previewing.cjs"),W=require("../../../functions/log-fetch.cjs"),A=require("../../../functions/register-component.cjs"),y=require("../../../functions/track/index.cjs"),$=require("../../../functions/track/interaction.cjs"),P=require("../../../helpers/canTrack.cjs"),z=require("../../../helpers/cookie.cjs"),G=require("../../../helpers/preview-lru-cache/set.cjs"),J=require("../../../helpers/subscribe-to-editor.cjs"),L=require("../../../scripts/init-editing.cjs"),Q=require("../../block/animator.cjs"),H=require("./enable-editor.helpers.cjs"),X=require("./styles.helpers.cjs"),Y=require("next/navigation");function Z(e){var q,I,R;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)}};G.postPreviewContent({value:t,key:t.id}).then(()=>{V.refresh()})}function K(){return e.showContent?{}:{hidden:!0,"aria-hidden":!0}}const[T,p]=o.useState(()=>e.contentWrapper||"div");function S(n){return J.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=>{Q.triggerAnimation(t)},contentUpdate:t=>{m(t)},stateUpdate:t=>{u(t)}}})(n)}const[v,ee]=o.useState(()=>({})),[b,te]=o.useState(()=>({})),[h,D]=o.useState(()=>!1);function _(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,...$.getInteractionPropertiesForEvent(n),unique:!h})}h||D(!0)}function U(){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,j)=>String(F.evaluate({code:j,context:e.context||{},localState:void 0,rootState:e.builderContextSignal.rootState,rootSetState:e.builderContextSignal.rootSetState})));W.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:N.fastClone(e.builderContextSignal.rootState),ref:{name:e.model}}}))}function E(n){var t;window.addEventListener("message",S),L.registerInsertMenu(),L.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=A.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))&&M.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)})}const V=Y.useRouter(),C=o.useRef(!1);return C.current||(U(),g(),C.current=!0),o.useEffect(()=>{var n;return(n=s.current)==null||n.addEventListener("initeditingbldr",E),()=>{var t;return(t=s.current)==null?void 0:t.removeEventListener("initeditingbldr",E)}},[]),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(w.isBrowser()){f.isEditing()&&!e.isNestedRender&&s.current&&s.current.dispatchEvent(new CustomEvent("initeditingbldr"));const r=e.builderContextSignal.content&&P.getDefaultCanTrack(e.canTrack),a=z.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})}O.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(()=>()=>{w.isBrowser()&&(window.removeEventListener("message",S),window.removeEventListener("builder:component:stateChangeListenerActivated",g))},[]),k.jsx(B.Provider,{value:e.builderContextSignal,children:e.builderContextSignal.content||H.needsElementRefDivForEditing()?k.jsx(T,{ref:s,onClick:n=>_(n),"builder-content-id":(q=e.builderContextSignal.content)==null?void 0:q.id,"builder-model":e.model,className:X.getWrapperClassName(((I=e.content)==null?void 0:I.testVariationId)||((R=e.content)==null?void 0:R.id)),style:{display:!e.builderContextSignal.content&&H.needsElementRefDivForEditing()?"none":void 0},...K(),...e.contentWrapperProps,children:e.children}):null})}module.exports=Z;
|