@builder.io/sdk-react-nextjs 0.18.0 → 0.18.1
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 +22 -19
- 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 +22 -19
- 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 +22 -19
- 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 w=require("react/jsx-runtime"),o=require("react"),F=require("../../../context/builder.context.cjs"),N=require("../../../functions/evaluate/evaluate.cjs"),V=require("../../../functions/fast-clone.cjs"),M=require("../../../functions/get-content/index.cjs"),y=require("../../../functions/is-browser.cjs"),
|
|
1
|
+
"use client";"use strict";const w=require("react/jsx-runtime"),o=require("react"),F=require("../../../context/builder.context.cjs"),N=require("../../../functions/evaluate/evaluate.cjs"),V=require("../../../functions/fast-clone.cjs"),M=require("../../../functions/get-content/index.cjs"),y=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"),k=require("../../../functions/track/index.cjs"),$=require("../../../functions/track/interaction.cjs"),P=require("../../../helpers/canTrack.cjs"),z=require("../../../helpers/preview-lru-cache/set.cjs"),G=require("../../../helpers/subscribe-to-editor.cjs"),L=require("../../../scripts/init-editing.cjs"),J=require("../../block/animator.cjs"),H=require("./enable-editor.helpers.cjs"),Q=require("./styles.helpers.cjs"),X=require("next/navigation");function Y(e){var q,I,R;const l=o.useRef(null);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)}};z.postPreviewContent({value:t,key:t.id}).then(()=>{j.refresh()})}function K(){return e.showContent?{}:{hidden:!0,"aria-hidden":!0}}const[T,Z]=o.useState(()=>e.contentWrapper||"div");function S(n){return G.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(()=>({})),[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;k._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,(s,B)=>String(N.evaluate({code:B,context:e.context||{},localState:void 0,rootState:e.builderContextSignal.rootState,rootSetState:e.builderContextSignal.rootSetState})));W.logFetch(d),fetch(d).then(s=>s.json()).then(s=>{u({[a]:s}),v[a]=!0}).catch(s=>{console.error("error fetching dynamic data",c,s)}).finally(()=>{b[a]=!1})})}function g(){f.isEditing()&&window.dispatchEvent(new CustomEvent("builder:component:stateChange",{detail:{state:V.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 j=X.useRouter(),C=o.useRef(!1);return C.current||(U(),g(),C.current=!0),o.useEffect(()=>{var n;return(n=l.current)==null||n.addEventListener("initeditingbldr",E),()=>{var t;return(t=l.current)==null?void 0:t.removeEventListener("initeditingbldr",E)}},[]),o.useEffect(()=>{var n;return(n=l.current)==null||n.addEventListener("initpreviewingbldr",x),()=>{var t;return(t=l.current)==null?void 0:t.removeEventListener("initpreviewingbldr",x)}},[]),o.useEffect(()=>{var n,t;if(y.isBrowser()){if(f.isEditing()&&!e.isNestedRender&&l.current&&l.current.dispatchEvent(new CustomEvent("initeditingbldr")),e.builderContextSignal.content&&P.getDefaultCanTrack(e.canTrack)){const r=(n=e.builderContextSignal.content)==null?void 0:n.testVariationId,a=(t=e.builderContextSignal.content)==null?void 0:t.id,c=e.apiKey;k._track({apiHost:e.apiHost,type:"impression",canTrack:!0,contentId:a,apiKey:c,variationId:r!==a?r: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(()=>()=>{y.isBrowser()&&(window.removeEventListener("message",S),window.removeEventListener("builder:component:stateChangeListenerActivated",g))},[]),w.jsx(F.Provider,{value:e.builderContextSignal,children:e.builderContextSignal.content||H.needsElementRefDivForEditing()?w.jsx(T,{ref:l,onClick:n=>_(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)||((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=Y;
|
|
@@ -1,12 +1,12 @@
|
|
|
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 f, useEffect as l } 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
12
|
import { createRegisterComponentMessage as z } from "../../../functions/register-component.mjs";
|
|
@@ -23,7 +23,7 @@ import { useRouter as p } from "next/navigation";
|
|
|
23
23
|
function Re(e) {
|
|
24
24
|
var y, R, w;
|
|
25
25
|
const c = P(null);
|
|
26
|
-
function
|
|
26
|
+
function m(n) {
|
|
27
27
|
var i, r;
|
|
28
28
|
const t = {
|
|
29
29
|
...e.builderContextSignal.rootState,
|
|
@@ -59,7 +59,7 @@ function Re(e) {
|
|
|
59
59
|
"aria-hidden": !0
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
|
-
const [
|
|
62
|
+
const [U, ee] = f(
|
|
63
63
|
() => e.contentWrapper || "div"
|
|
64
64
|
);
|
|
65
65
|
function v(n) {
|
|
@@ -81,11 +81,14 @@ function Re(e) {
|
|
|
81
81
|
},
|
|
82
82
|
contentUpdate: (t) => {
|
|
83
83
|
b(t);
|
|
84
|
+
},
|
|
85
|
+
stateUpdate: (t) => {
|
|
86
|
+
m(t);
|
|
84
87
|
}
|
|
85
88
|
}
|
|
86
89
|
})(n);
|
|
87
90
|
}
|
|
88
|
-
const [h, te] =
|
|
91
|
+
const [h, te] = f(() => ({})), [S, ne] = f(() => ({})), [x, D] = f(() => !1);
|
|
89
92
|
function N(n) {
|
|
90
93
|
var t, i;
|
|
91
94
|
if (e.builderContextSignal.content) {
|
|
@@ -101,13 +104,13 @@ function Re(e) {
|
|
|
101
104
|
unique: !x
|
|
102
105
|
});
|
|
103
106
|
}
|
|
104
|
-
x ||
|
|
107
|
+
x || D(!0);
|
|
105
108
|
}
|
|
106
109
|
function V() {
|
|
107
110
|
var t, i, r;
|
|
108
111
|
const n = (r = (i = (t = e.builderContextSignal.content) == null ? void 0 : t.data) == null ? void 0 : i.httpRequests) != null ? r : {};
|
|
109
112
|
Object.entries(n).forEach(([a, o]) => {
|
|
110
|
-
if (!o || S[a] || h[a] && !
|
|
113
|
+
if (!o || S[a] || h[a] && !g())
|
|
111
114
|
return;
|
|
112
115
|
S[a] = !0;
|
|
113
116
|
const d = o.replace(
|
|
@@ -123,7 +126,7 @@ function Re(e) {
|
|
|
123
126
|
)
|
|
124
127
|
);
|
|
125
128
|
F(d), fetch(d).then((u) => u.json()).then((u) => {
|
|
126
|
-
|
|
129
|
+
m({
|
|
127
130
|
[a]: u
|
|
128
131
|
}), h[a] = !0;
|
|
129
132
|
}).catch((u) => {
|
|
@@ -133,8 +136,8 @@ function Re(e) {
|
|
|
133
136
|
});
|
|
134
137
|
});
|
|
135
138
|
}
|
|
136
|
-
function
|
|
137
|
-
|
|
139
|
+
function s() {
|
|
140
|
+
g() && window.dispatchEvent(
|
|
138
141
|
new CustomEvent(
|
|
139
142
|
"builder:component:stateChange",
|
|
140
143
|
{
|
|
@@ -172,7 +175,7 @@ function Re(e) {
|
|
|
172
175
|
}
|
|
173
176
|
}), window.addEventListener(
|
|
174
177
|
"builder:component:stateChangeListenerActivated",
|
|
175
|
-
|
|
178
|
+
s
|
|
176
179
|
);
|
|
177
180
|
}
|
|
178
181
|
function E(n) {
|
|
@@ -194,7 +197,7 @@ function Re(e) {
|
|
|
194
197
|
});
|
|
195
198
|
}
|
|
196
199
|
const _ = p(), I = P(!1);
|
|
197
|
-
return I.current || (V(),
|
|
200
|
+
return I.current || (V(), s(), I.current = !0), l(() => {
|
|
198
201
|
var n;
|
|
199
202
|
return (n = c.current) == null || n.addEventListener(
|
|
200
203
|
"initeditingbldr",
|
|
@@ -221,7 +224,7 @@ function Re(e) {
|
|
|
221
224
|
}, []), l(() => {
|
|
222
225
|
var n, t;
|
|
223
226
|
if (L()) {
|
|
224
|
-
if (
|
|
227
|
+
if (g() && !e.isNestedRender && c.current && c.current.dispatchEvent(new CustomEvent("initeditingbldr")), e.builderContextSignal.content && K(e.canTrack)) {
|
|
225
228
|
const r = (n = e.builderContextSignal.content) == null ? void 0 : n.testVariationId, a = (t = e.builderContextSignal.content) == null ? void 0 : t.id, o = e.apiKey;
|
|
226
229
|
H({
|
|
227
230
|
apiHost: e.apiHost,
|
|
@@ -232,24 +235,24 @@ function Re(e) {
|
|
|
232
235
|
variationId: r !== a ? r : void 0
|
|
233
236
|
});
|
|
234
237
|
}
|
|
235
|
-
B() &&
|
|
238
|
+
B() && g();
|
|
236
239
|
}
|
|
237
240
|
}, []), l(() => {
|
|
238
241
|
}, [e.content]), l(() => {
|
|
239
|
-
|
|
242
|
+
s();
|
|
240
243
|
}, [e.builderContextSignal.rootState]), l(() => {
|
|
241
|
-
e.data &&
|
|
244
|
+
e.data && m(e.data);
|
|
242
245
|
}, [e.data]), l(() => {
|
|
243
|
-
e.locale &&
|
|
246
|
+
e.locale && m({
|
|
244
247
|
locale: e.locale
|
|
245
248
|
});
|
|
246
249
|
}, [e.locale]), l(() => () => {
|
|
247
250
|
L() && (window.removeEventListener("message", v), window.removeEventListener(
|
|
248
251
|
"builder:component:stateChangeListenerActivated",
|
|
249
|
-
|
|
252
|
+
s
|
|
250
253
|
));
|
|
251
254
|
}, []), /* @__PURE__ */ k(O.Provider, { value: e.builderContextSignal, children: e.builderContextSignal.content || q() ? /* @__PURE__ */ k(
|
|
252
|
-
|
|
255
|
+
U,
|
|
253
256
|
{
|
|
254
257
|
ref: c,
|
|
255
258
|
onClick: (n) => N(n),
|
|
@@ -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.1";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 w=require("react/jsx-runtime"),o=require("react"),F=require("../../../context/builder.context.cjs"),N=require("../../../functions/evaluate/evaluate.cjs"),V=require("../../../functions/fast-clone.cjs"),M=require("../../../functions/get-content/index.cjs"),y=require("../../../functions/is-browser.cjs"),
|
|
1
|
+
"use client";"use strict";const w=require("react/jsx-runtime"),o=require("react"),F=require("../../../context/builder.context.cjs"),N=require("../../../functions/evaluate/evaluate.cjs"),V=require("../../../functions/fast-clone.cjs"),M=require("../../../functions/get-content/index.cjs"),y=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"),k=require("../../../functions/track/index.cjs"),$=require("../../../functions/track/interaction.cjs"),P=require("../../../helpers/canTrack.cjs"),z=require("../../../helpers/preview-lru-cache/set.cjs"),G=require("../../../helpers/subscribe-to-editor.cjs"),L=require("../../../scripts/init-editing.cjs"),J=require("../../block/animator.cjs"),H=require("./enable-editor.helpers.cjs"),Q=require("./styles.helpers.cjs"),X=require("next/navigation");function Y(e){var q,I,R;const l=o.useRef(null);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)}};z.postPreviewContent({value:t,key:t.id}).then(()=>{j.refresh()})}function K(){return e.showContent?{}:{hidden:!0,"aria-hidden":!0}}const[T,Z]=o.useState(()=>e.contentWrapper||"div");function S(n){return G.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(()=>({})),[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;k._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,(s,B)=>String(N.evaluate({code:B,context:e.context||{},localState:void 0,rootState:e.builderContextSignal.rootState,rootSetState:e.builderContextSignal.rootSetState})));W.logFetch(d),fetch(d).then(s=>s.json()).then(s=>{u({[a]:s}),v[a]=!0}).catch(s=>{console.error("error fetching dynamic data",c,s)}).finally(()=>{b[a]=!1})})}function g(){f.isEditing()&&window.dispatchEvent(new CustomEvent("builder:component:stateChange",{detail:{state:V.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 j=X.useRouter(),C=o.useRef(!1);return C.current||(U(),g(),C.current=!0),o.useEffect(()=>{var n;return(n=l.current)==null||n.addEventListener("initeditingbldr",E),()=>{var t;return(t=l.current)==null?void 0:t.removeEventListener("initeditingbldr",E)}},[]),o.useEffect(()=>{var n;return(n=l.current)==null||n.addEventListener("initpreviewingbldr",x),()=>{var t;return(t=l.current)==null?void 0:t.removeEventListener("initpreviewingbldr",x)}},[]),o.useEffect(()=>{var n,t;if(y.isBrowser()){if(f.isEditing()&&!e.isNestedRender&&l.current&&l.current.dispatchEvent(new CustomEvent("initeditingbldr")),e.builderContextSignal.content&&P.getDefaultCanTrack(e.canTrack)){const r=(n=e.builderContextSignal.content)==null?void 0:n.testVariationId,a=(t=e.builderContextSignal.content)==null?void 0:t.id,c=e.apiKey;k._track({apiHost:e.apiHost,type:"impression",canTrack:!0,contentId:a,apiKey:c,variationId:r!==a?r: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(()=>()=>{y.isBrowser()&&(window.removeEventListener("message",S),window.removeEventListener("builder:component:stateChangeListenerActivated",g))},[]),w.jsx(F.Provider,{value:e.builderContextSignal,children:e.builderContextSignal.content||H.needsElementRefDivForEditing()?w.jsx(T,{ref:l,onClick:n=>_(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)||((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=Y;
|
|
@@ -1,12 +1,12 @@
|
|
|
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 f, useEffect as l } 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
12
|
import { createRegisterComponentMessage as z } from "../../../functions/register-component.mjs";
|
|
@@ -23,7 +23,7 @@ import { useRouter as p } from "next/navigation";
|
|
|
23
23
|
function Re(e) {
|
|
24
24
|
var y, R, w;
|
|
25
25
|
const c = P(null);
|
|
26
|
-
function
|
|
26
|
+
function m(n) {
|
|
27
27
|
var i, r;
|
|
28
28
|
const t = {
|
|
29
29
|
...e.builderContextSignal.rootState,
|
|
@@ -59,7 +59,7 @@ function Re(e) {
|
|
|
59
59
|
"aria-hidden": !0
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
|
-
const [
|
|
62
|
+
const [U, ee] = f(
|
|
63
63
|
() => e.contentWrapper || "div"
|
|
64
64
|
);
|
|
65
65
|
function v(n) {
|
|
@@ -81,11 +81,14 @@ function Re(e) {
|
|
|
81
81
|
},
|
|
82
82
|
contentUpdate: (t) => {
|
|
83
83
|
b(t);
|
|
84
|
+
},
|
|
85
|
+
stateUpdate: (t) => {
|
|
86
|
+
m(t);
|
|
84
87
|
}
|
|
85
88
|
}
|
|
86
89
|
})(n);
|
|
87
90
|
}
|
|
88
|
-
const [h, te] =
|
|
91
|
+
const [h, te] = f(() => ({})), [S, ne] = f(() => ({})), [x, D] = f(() => !1);
|
|
89
92
|
function N(n) {
|
|
90
93
|
var t, i;
|
|
91
94
|
if (e.builderContextSignal.content) {
|
|
@@ -101,13 +104,13 @@ function Re(e) {
|
|
|
101
104
|
unique: !x
|
|
102
105
|
});
|
|
103
106
|
}
|
|
104
|
-
x ||
|
|
107
|
+
x || D(!0);
|
|
105
108
|
}
|
|
106
109
|
function V() {
|
|
107
110
|
var t, i, r;
|
|
108
111
|
const n = (r = (i = (t = e.builderContextSignal.content) == null ? void 0 : t.data) == null ? void 0 : i.httpRequests) != null ? r : {};
|
|
109
112
|
Object.entries(n).forEach(([a, o]) => {
|
|
110
|
-
if (!o || S[a] || h[a] && !
|
|
113
|
+
if (!o || S[a] || h[a] && !g())
|
|
111
114
|
return;
|
|
112
115
|
S[a] = !0;
|
|
113
116
|
const d = o.replace(
|
|
@@ -123,7 +126,7 @@ function Re(e) {
|
|
|
123
126
|
)
|
|
124
127
|
);
|
|
125
128
|
F(d), fetch(d).then((u) => u.json()).then((u) => {
|
|
126
|
-
|
|
129
|
+
m({
|
|
127
130
|
[a]: u
|
|
128
131
|
}), h[a] = !0;
|
|
129
132
|
}).catch((u) => {
|
|
@@ -133,8 +136,8 @@ function Re(e) {
|
|
|
133
136
|
});
|
|
134
137
|
});
|
|
135
138
|
}
|
|
136
|
-
function
|
|
137
|
-
|
|
139
|
+
function s() {
|
|
140
|
+
g() && window.dispatchEvent(
|
|
138
141
|
new CustomEvent(
|
|
139
142
|
"builder:component:stateChange",
|
|
140
143
|
{
|
|
@@ -172,7 +175,7 @@ function Re(e) {
|
|
|
172
175
|
}
|
|
173
176
|
}), window.addEventListener(
|
|
174
177
|
"builder:component:stateChangeListenerActivated",
|
|
175
|
-
|
|
178
|
+
s
|
|
176
179
|
);
|
|
177
180
|
}
|
|
178
181
|
function E(n) {
|
|
@@ -194,7 +197,7 @@ function Re(e) {
|
|
|
194
197
|
});
|
|
195
198
|
}
|
|
196
199
|
const _ = p(), I = P(!1);
|
|
197
|
-
return I.current || (V(),
|
|
200
|
+
return I.current || (V(), s(), I.current = !0), l(() => {
|
|
198
201
|
var n;
|
|
199
202
|
return (n = c.current) == null || n.addEventListener(
|
|
200
203
|
"initeditingbldr",
|
|
@@ -221,7 +224,7 @@ function Re(e) {
|
|
|
221
224
|
}, []), l(() => {
|
|
222
225
|
var n, t;
|
|
223
226
|
if (L()) {
|
|
224
|
-
if (
|
|
227
|
+
if (g() && !e.isNestedRender && c.current && c.current.dispatchEvent(new CustomEvent("initeditingbldr")), e.builderContextSignal.content && K(e.canTrack)) {
|
|
225
228
|
const r = (n = e.builderContextSignal.content) == null ? void 0 : n.testVariationId, a = (t = e.builderContextSignal.content) == null ? void 0 : t.id, o = e.apiKey;
|
|
226
229
|
H({
|
|
227
230
|
apiHost: e.apiHost,
|
|
@@ -232,24 +235,24 @@ function Re(e) {
|
|
|
232
235
|
variationId: r !== a ? r : void 0
|
|
233
236
|
});
|
|
234
237
|
}
|
|
235
|
-
B() &&
|
|
238
|
+
B() && g();
|
|
236
239
|
}
|
|
237
240
|
}, []), l(() => {
|
|
238
241
|
}, [e.content]), l(() => {
|
|
239
|
-
|
|
242
|
+
s();
|
|
240
243
|
}, [e.builderContextSignal.rootState]), l(() => {
|
|
241
|
-
e.data &&
|
|
244
|
+
e.data && m(e.data);
|
|
242
245
|
}, [e.data]), l(() => {
|
|
243
|
-
e.locale &&
|
|
246
|
+
e.locale && m({
|
|
244
247
|
locale: e.locale
|
|
245
248
|
});
|
|
246
249
|
}, [e.locale]), l(() => () => {
|
|
247
250
|
L() && (window.removeEventListener("message", v), window.removeEventListener(
|
|
248
251
|
"builder:component:stateChangeListenerActivated",
|
|
249
|
-
|
|
252
|
+
s
|
|
250
253
|
));
|
|
251
254
|
}, []), /* @__PURE__ */ k(O.Provider, { value: e.builderContextSignal, children: e.builderContextSignal.content || q() ? /* @__PURE__ */ k(
|
|
252
|
-
|
|
255
|
+
U,
|
|
253
256
|
{
|
|
254
257
|
ref: c,
|
|
255
258
|
onClick: (n) => N(n),
|
|
@@ -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.1";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 w=require("react/jsx-runtime"),o=require("react"),F=require("../../../context/builder.context.cjs"),N=require("../../../functions/evaluate/evaluate.cjs"),V=require("../../../functions/fast-clone.cjs"),M=require("../../../functions/get-content/index.cjs"),y=require("../../../functions/is-browser.cjs"),
|
|
1
|
+
"use client";"use strict";const w=require("react/jsx-runtime"),o=require("react"),F=require("../../../context/builder.context.cjs"),N=require("../../../functions/evaluate/evaluate.cjs"),V=require("../../../functions/fast-clone.cjs"),M=require("../../../functions/get-content/index.cjs"),y=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"),k=require("../../../functions/track/index.cjs"),$=require("../../../functions/track/interaction.cjs"),P=require("../../../helpers/canTrack.cjs"),z=require("../../../helpers/preview-lru-cache/set.cjs"),G=require("../../../helpers/subscribe-to-editor.cjs"),L=require("../../../scripts/init-editing.cjs"),J=require("../../block/animator.cjs"),H=require("./enable-editor.helpers.cjs"),Q=require("./styles.helpers.cjs"),X=require("next/navigation");function Y(e){var q,I,R;const l=o.useRef(null);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)}};z.postPreviewContent({value:t,key:t.id}).then(()=>{j.refresh()})}function K(){return e.showContent?{}:{hidden:!0,"aria-hidden":!0}}const[T,Z]=o.useState(()=>e.contentWrapper||"div");function S(n){return G.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(()=>({})),[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;k._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,(s,B)=>String(N.evaluate({code:B,context:e.context||{},localState:void 0,rootState:e.builderContextSignal.rootState,rootSetState:e.builderContextSignal.rootSetState})));W.logFetch(d),fetch(d).then(s=>s.json()).then(s=>{u({[a]:s}),v[a]=!0}).catch(s=>{console.error("error fetching dynamic data",c,s)}).finally(()=>{b[a]=!1})})}function g(){f.isEditing()&&window.dispatchEvent(new CustomEvent("builder:component:stateChange",{detail:{state:V.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 j=X.useRouter(),C=o.useRef(!1);return C.current||(U(),g(),C.current=!0),o.useEffect(()=>{var n;return(n=l.current)==null||n.addEventListener("initeditingbldr",E),()=>{var t;return(t=l.current)==null?void 0:t.removeEventListener("initeditingbldr",E)}},[]),o.useEffect(()=>{var n;return(n=l.current)==null||n.addEventListener("initpreviewingbldr",x),()=>{var t;return(t=l.current)==null?void 0:t.removeEventListener("initpreviewingbldr",x)}},[]),o.useEffect(()=>{var n,t;if(y.isBrowser()){if(f.isEditing()&&!e.isNestedRender&&l.current&&l.current.dispatchEvent(new CustomEvent("initeditingbldr")),e.builderContextSignal.content&&P.getDefaultCanTrack(e.canTrack)){const r=(n=e.builderContextSignal.content)==null?void 0:n.testVariationId,a=(t=e.builderContextSignal.content)==null?void 0:t.id,c=e.apiKey;k._track({apiHost:e.apiHost,type:"impression",canTrack:!0,contentId:a,apiKey:c,variationId:r!==a?r: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(()=>()=>{y.isBrowser()&&(window.removeEventListener("message",S),window.removeEventListener("builder:component:stateChangeListenerActivated",g))},[]),w.jsx(F.Provider,{value:e.builderContextSignal,children:e.builderContextSignal.content||H.needsElementRefDivForEditing()?w.jsx(T,{ref:l,onClick:n=>_(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)||((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=Y;
|
|
@@ -1,12 +1,12 @@
|
|
|
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 f, useEffect as l } 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
12
|
import { createRegisterComponentMessage as z } from "../../../functions/register-component.mjs";
|
|
@@ -23,7 +23,7 @@ import { useRouter as p } from "next/navigation";
|
|
|
23
23
|
function Re(e) {
|
|
24
24
|
var y, R, w;
|
|
25
25
|
const c = P(null);
|
|
26
|
-
function
|
|
26
|
+
function m(n) {
|
|
27
27
|
var i, r;
|
|
28
28
|
const t = {
|
|
29
29
|
...e.builderContextSignal.rootState,
|
|
@@ -59,7 +59,7 @@ function Re(e) {
|
|
|
59
59
|
"aria-hidden": !0
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
|
-
const [
|
|
62
|
+
const [U, ee] = f(
|
|
63
63
|
() => e.contentWrapper || "div"
|
|
64
64
|
);
|
|
65
65
|
function v(n) {
|
|
@@ -81,11 +81,14 @@ function Re(e) {
|
|
|
81
81
|
},
|
|
82
82
|
contentUpdate: (t) => {
|
|
83
83
|
b(t);
|
|
84
|
+
},
|
|
85
|
+
stateUpdate: (t) => {
|
|
86
|
+
m(t);
|
|
84
87
|
}
|
|
85
88
|
}
|
|
86
89
|
})(n);
|
|
87
90
|
}
|
|
88
|
-
const [h, te] =
|
|
91
|
+
const [h, te] = f(() => ({})), [S, ne] = f(() => ({})), [x, D] = f(() => !1);
|
|
89
92
|
function N(n) {
|
|
90
93
|
var t, i;
|
|
91
94
|
if (e.builderContextSignal.content) {
|
|
@@ -101,13 +104,13 @@ function Re(e) {
|
|
|
101
104
|
unique: !x
|
|
102
105
|
});
|
|
103
106
|
}
|
|
104
|
-
x ||
|
|
107
|
+
x || D(!0);
|
|
105
108
|
}
|
|
106
109
|
function V() {
|
|
107
110
|
var t, i, r;
|
|
108
111
|
const n = (r = (i = (t = e.builderContextSignal.content) == null ? void 0 : t.data) == null ? void 0 : i.httpRequests) != null ? r : {};
|
|
109
112
|
Object.entries(n).forEach(([a, o]) => {
|
|
110
|
-
if (!o || S[a] || h[a] && !
|
|
113
|
+
if (!o || S[a] || h[a] && !g())
|
|
111
114
|
return;
|
|
112
115
|
S[a] = !0;
|
|
113
116
|
const d = o.replace(
|
|
@@ -123,7 +126,7 @@ function Re(e) {
|
|
|
123
126
|
)
|
|
124
127
|
);
|
|
125
128
|
F(d), fetch(d).then((u) => u.json()).then((u) => {
|
|
126
|
-
|
|
129
|
+
m({
|
|
127
130
|
[a]: u
|
|
128
131
|
}), h[a] = !0;
|
|
129
132
|
}).catch((u) => {
|
|
@@ -133,8 +136,8 @@ function Re(e) {
|
|
|
133
136
|
});
|
|
134
137
|
});
|
|
135
138
|
}
|
|
136
|
-
function
|
|
137
|
-
|
|
139
|
+
function s() {
|
|
140
|
+
g() && window.dispatchEvent(
|
|
138
141
|
new CustomEvent(
|
|
139
142
|
"builder:component:stateChange",
|
|
140
143
|
{
|
|
@@ -172,7 +175,7 @@ function Re(e) {
|
|
|
172
175
|
}
|
|
173
176
|
}), window.addEventListener(
|
|
174
177
|
"builder:component:stateChangeListenerActivated",
|
|
175
|
-
|
|
178
|
+
s
|
|
176
179
|
);
|
|
177
180
|
}
|
|
178
181
|
function E(n) {
|
|
@@ -194,7 +197,7 @@ function Re(e) {
|
|
|
194
197
|
});
|
|
195
198
|
}
|
|
196
199
|
const _ = p(), I = P(!1);
|
|
197
|
-
return I.current || (V(),
|
|
200
|
+
return I.current || (V(), s(), I.current = !0), l(() => {
|
|
198
201
|
var n;
|
|
199
202
|
return (n = c.current) == null || n.addEventListener(
|
|
200
203
|
"initeditingbldr",
|
|
@@ -221,7 +224,7 @@ function Re(e) {
|
|
|
221
224
|
}, []), l(() => {
|
|
222
225
|
var n, t;
|
|
223
226
|
if (L()) {
|
|
224
|
-
if (
|
|
227
|
+
if (g() && !e.isNestedRender && c.current && c.current.dispatchEvent(new CustomEvent("initeditingbldr")), e.builderContextSignal.content && K(e.canTrack)) {
|
|
225
228
|
const r = (n = e.builderContextSignal.content) == null ? void 0 : n.testVariationId, a = (t = e.builderContextSignal.content) == null ? void 0 : t.id, o = e.apiKey;
|
|
226
229
|
H({
|
|
227
230
|
apiHost: e.apiHost,
|
|
@@ -232,24 +235,24 @@ function Re(e) {
|
|
|
232
235
|
variationId: r !== a ? r : void 0
|
|
233
236
|
});
|
|
234
237
|
}
|
|
235
|
-
B() &&
|
|
238
|
+
B() && g();
|
|
236
239
|
}
|
|
237
240
|
}, []), l(() => {
|
|
238
241
|
}, [e.content]), l(() => {
|
|
239
|
-
|
|
242
|
+
s();
|
|
240
243
|
}, [e.builderContextSignal.rootState]), l(() => {
|
|
241
|
-
e.data &&
|
|
244
|
+
e.data && m(e.data);
|
|
242
245
|
}, [e.data]), l(() => {
|
|
243
|
-
e.locale &&
|
|
246
|
+
e.locale && m({
|
|
244
247
|
locale: e.locale
|
|
245
248
|
});
|
|
246
249
|
}, [e.locale]), l(() => () => {
|
|
247
250
|
L() && (window.removeEventListener("message", v), window.removeEventListener(
|
|
248
251
|
"builder:component:stateChangeListenerActivated",
|
|
249
|
-
|
|
252
|
+
s
|
|
250
253
|
));
|
|
251
254
|
}, []), /* @__PURE__ */ k(O.Provider, { value: e.builderContextSignal, children: e.builderContextSignal.content || q() ? /* @__PURE__ */ k(
|
|
252
|
-
|
|
255
|
+
U,
|
|
253
256
|
{
|
|
254
257
|
ref: c,
|
|
255
258
|
onClick: (n) => N(n),
|
|
@@ -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.1";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
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@builder.io/sdk-react-nextjs",
|
|
3
3
|
"description": "Builder.io RSC SDK for NextJS App Directory",
|
|
4
|
-
"version": "0.18.
|
|
4
|
+
"version": "0.18.1",
|
|
5
5
|
"homepage": "https://github.com/BuilderIO/builder/tree/main/packages/sdks/output/nextjs",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.18.
|
|
1
|
+
export declare const SDK_VERSION = "0.18.1";
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { ContentProps } from '../components/content/content.types.js';
|
|
2
2
|
import type { BuilderAnimation } from '../types/builder-block.js';
|
|
3
3
|
import type { BuilderContent } from '../types/builder-content.js';
|
|
4
|
+
import type { Dictionary } from '../types/typescript.js';
|
|
4
5
|
type ContentListener = Required<Pick<ContentProps, 'model' | 'trustedHosts'>> & {
|
|
5
6
|
callbacks: {
|
|
6
7
|
contentUpdate: (updatedContent: BuilderContent) => void;
|
|
8
|
+
stateUpdate: (newState: Dictionary<string>) => void;
|
|
7
9
|
animation: (updatedContent: BuilderAnimation) => void;
|
|
8
10
|
configureSdk: (updatedContent: any) => void;
|
|
9
11
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.18.
|
|
1
|
+
export declare const SDK_VERSION = "0.18.1";
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { ContentProps } from '../components/content/content.types.js';
|
|
2
2
|
import type { BuilderAnimation } from '../types/builder-block.js';
|
|
3
3
|
import type { BuilderContent } from '../types/builder-content.js';
|
|
4
|
+
import type { Dictionary } from '../types/typescript.js';
|
|
4
5
|
type ContentListener = Required<Pick<ContentProps, 'model' | 'trustedHosts'>> & {
|
|
5
6
|
callbacks: {
|
|
6
7
|
contentUpdate: (updatedContent: BuilderContent) => void;
|
|
8
|
+
stateUpdate: (newState: Dictionary<string>) => void;
|
|
7
9
|
animation: (updatedContent: BuilderAnimation) => void;
|
|
8
10
|
configureSdk: (updatedContent: any) => void;
|
|
9
11
|
};
|