@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.
@@ -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 s, useEffect as l } from "react";
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 f } from "../../../functions/is-editing.mjs";
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 z } from "../../../functions/register-component.mjs";
12
+ import { createRegisterComponentMessage as $ } from "../../../functions/register-component.mjs";
13
13
  import { _track as H } from "../../../functions/track/index.mjs";
14
- import { getInteractionPropertiesForEvent as $ } from "../../../functions/track/interaction.mjs";
14
+ import { getInteractionPropertiesForEvent as z } from "../../../functions/track/interaction.mjs";
15
15
  import { getDefaultCanTrack as K } from "../../../helpers/canTrack.mjs";
16
- import { postPreviewContent as G } from "../../../helpers/preview-lru-cache/set.mjs";
17
- import { createEditorListener as J } from "../../../helpers/subscribe-to-editor.mjs";
18
- import { registerInsertMenu as Q, setupBrowserForEditing as X } from "../../../scripts/init-editing.mjs";
19
- import { triggerAnimation as Y } from "../../block/animator.mjs";
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 Z } from "./styles.helpers.mjs";
22
- import { useRouter as p } from "next/navigation";
23
- function Re(e) {
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 c = P(null);
26
- function g(n) {
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
- G({
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 [D, ee] = s(
64
+ const [U, te] = m(
63
65
  () => e.contentWrapper || "div"
64
66
  );
65
67
  function v(n) {
66
- return J({
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
- Y(t);
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, te] = s(() => ({})), [S, ne] = s(() => ({})), [x, U] = s(() => !1);
89
- function N(n) {
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
- ...$(n),
105
+ ...z(n),
101
106
  unique: !x
102
107
  });
103
108
  }
104
- x || U(!0);
109
+ x || D(!0);
105
110
  }
106
- function V() {
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] && !f())
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
- (u, M) => String(
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((u) => u.json()).then((u) => {
126
- g({
127
- [a]: u
130
+ F(d), fetch(d).then((l) => l.json()).then((l) => {
131
+ s({
132
+ [a]: l
128
133
  }), h[a] = !0;
129
- }).catch((u) => {
130
- console.error("error fetching dynamic data", o, u);
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 m() {
137
- f() && window.dispatchEvent(
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), Q(), X({
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 = z(i);
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
- m
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 _ = p(), I = P(!1);
197
- return I.current || (V(), m(), I.current = !0), l(() => {
201
+ const _ = ee(), I = P(!1);
202
+ return I.current || (N(), f(), I.current = !0), c(() => {
198
203
  var n;
199
- return (n = c.current) == null || n.addEventListener(
204
+ return (n = u.current) == null || n.addEventListener(
200
205
  "initeditingbldr",
201
206
  C
202
207
  ), () => {
203
208
  var t;
204
- return (t = c.current) == null ? void 0 : t.removeEventListener(
209
+ return (t = u.current) == null ? void 0 : t.removeEventListener(
205
210
  "initeditingbldr",
206
211
  C
207
212
  );
208
213
  };
209
- }, []), l(() => {
214
+ }, []), c(() => {
210
215
  var n;
211
- return (n = c.current) == null || n.addEventListener(
216
+ return (n = u.current) == null || n.addEventListener(
212
217
  "initpreviewingbldr",
213
218
  E
214
219
  ), () => {
215
220
  var t;
216
- return (t = c.current) == null ? void 0 : t.removeEventListener(
221
+ return (t = u.current) == null ? void 0 : t.removeEventListener(
217
222
  "initpreviewingbldr",
218
223
  E
219
224
  );
220
225
  };
221
- }, []), l(() => {
222
- var n, t;
226
+ }, []), c(() => {
227
+ var n, t, i;
223
228
  if (L()) {
224
- if (f() && !e.isNestedRender && c.current && c.current.dispatchEvent(new CustomEvent("initeditingbldr")), e.builderContextSignal.content && K(e.canTrack)) {
225
- const r = (n = e.builderContextSignal.content) == null ? void 0 : n.testVariationId, a = (t = e.builderContextSignal.content) == null ? void 0 : t.id, o = e.apiKey;
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: a,
231
- apiKey: o,
232
- variationId: r !== a ? r : void 0
240
+ contentId: d,
241
+ apiKey: l,
242
+ variationId: a !== d ? a : void 0
233
243
  });
234
244
  }
235
- B() && f();
245
+ B() && g();
236
246
  }
237
- }, []), l(() => {
238
- }, [e.content]), l(() => {
239
- m();
240
- }, [e.builderContextSignal.rootState]), l(() => {
241
- e.data && g(e.data);
242
- }, [e.data]), l(() => {
243
- e.locale && g({
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]), l(() => () => {
256
+ }, [e.locale]), c(() => () => {
247
257
  L() && (window.removeEventListener("message", v), window.removeEventListener(
248
258
  "builder:component:stateChangeListenerActivated",
249
- m
259
+ f
250
260
  ));
251
261
  }, []), /* @__PURE__ */ k(O.Provider, { value: e.builderContextSignal, children: e.builderContextSignal.content || q() ? /* @__PURE__ */ k(
252
- D,
262
+ U,
253
263
  {
254
- ref: c,
255
- onClick: (n) => N(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: Z(
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
- Re as default
281
+ ke as default
272
282
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e="0.18.0";exports.SDK_VERSION=e;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e="0.18.2";exports.SDK_VERSION=e;
@@ -1,4 +1,4 @@
1
- const o = "0.18.0";
1
+ const o = "0.18.2";
2
2
  export {
3
3
  o as SDK_VERSION
4
4
  };
@@ -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"),g=require("../scripts/init-editing.cjs"),b=require("./logger.cjs"),s=({model:n,trustedHosts:o,callbacks:t})=>i=>{if(!u.isFromTrustedHost(o,i))return;const{data:e}=i;if(e)switch(e.type){case"builder.configureSdk":{t.configureSdk(e.data);break}case"builder.triggerAnimation":{t.animation(e.data);break}case"builder.contentUpdate":{const r=e.data,a=r.key||r.alias||r.entry||r.modelName,d=r.data;a===n&&t.contentUpdate(d);break}}},m=({model:n,apiKey:o,callback:t,trustedHosts:i})=>{if(!c.isBrowser)return b.logger.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server."),()=>{};g.setupBrowserForEditing({modelName:n,apiKey:o});const e=s({callbacks:{contentUpdate:t,animation:()=>{},configureSdk:()=>{}},model:n,trustedHosts:i});return window.addEventListener("message",e),()=>{window.removeEventListener("message",e)}};exports.createEditorListener=s;exports.subscribeToEditor=m;
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 g = ({
6
- model: n,
5
+ const b = ({
6
+ model: o,
7
7
  trustedHosts: i,
8
- callbacks: t
9
- }) => (o) => {
10
- if (!c(i, o))
8
+ callbacks: r
9
+ }) => (n) => {
10
+ if (!c(i, n))
11
11
  return;
12
12
  const {
13
- data: e
14
- } = o;
15
- if (e)
16
- switch (e.type) {
13
+ data: t
14
+ } = n;
15
+ if (t)
16
+ switch (t.type) {
17
17
  case "builder.configureSdk": {
18
- t.configureSdk(e.data);
18
+ r.configureSdk(t.data);
19
19
  break;
20
20
  }
21
21
  case "builder.triggerAnimation": {
22
- t.animation(e.data);
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 r = e.data, s = r.key || r.alias || r.entry || r.modelName, a = r.data;
27
- s === n && t.contentUpdate(a);
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: n,
37
+ model: o,
33
38
  apiKey: i,
34
- callback: t,
35
- trustedHosts: o
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: n,
46
+ modelName: o,
42
47
  apiKey: i
43
48
  });
44
- const e = g({
49
+ const t = b({
45
50
  callbacks: {
46
- contentUpdate: t,
51
+ contentUpdate: r,
47
52
  animation: () => {
48
53
  },
49
54
  configureSdk: () => {
55
+ },
56
+ stateUpdate: () => {
50
57
  }
51
58
  },
52
- model: n,
53
- trustedHosts: o
59
+ model: o,
60
+ trustedHosts: n
54
61
  });
55
- return window.addEventListener("message", e), () => {
56
- window.removeEventListener("message", e);
62
+ return window.addEventListener("message", t), () => {
63
+ window.removeEventListener("message", t);
57
64
  };
58
65
  };
59
66
  export {
60
- g as createEditorListener,
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.0",
4
+ "version": "0.18.2",
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.0";
1
+ export declare const SDK_VERSION = "0.18.2";
@@ -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.0";
1
+ export declare const SDK_VERSION = "0.18.2";
@@ -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
  };