@builder.io/sdk-react-native 0.2.1 → 0.2.3

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.
@@ -32,8 +32,9 @@ const react_native_1 = require("react-native");
32
32
  function Button(props) {
33
33
  return (React.createElement(React.Fragment, null, props.link ? (React.createElement(React.Fragment, null,
34
34
  React.createElement(react_native_1.View, { role: "button", ...props.attributes, href: props.link, target: props.openLinkInNewTab ? "_blank" : undefined },
35
- React.createElement(BaseText_1.default, null, props.text)))) : (React.createElement(react_native_1.View, { ...props.attributes, style: styles.view1 },
36
- React.createElement(BaseText_1.default, null, props.text)))));
35
+ React.createElement(BaseText_1.default, null, props.text)))) : (React.createElement(React.Fragment, null,
36
+ React.createElement(react_native_1.View, { ...props.attributes, style: styles.view1 },
37
+ React.createElement(BaseText_1.default, null, props.text))))));
37
38
  }
38
39
  const styles = react_native_1.StyleSheet.create({ view1: { all: "unset" } });
39
40
  exports.default = Button;
@@ -111,30 +111,30 @@ function Columns(props) {
111
111
  }
112
112
  function columnsStyles() {
113
113
  return `
114
- @media (max-width: ${getWidthForBreakpointSize("medium")}px) {
115
- .${props.builderBlock.id}-breakpoints {
116
- flex-direction: var(--flex-dir-tablet);
117
- align-items: stretch;
118
- }
114
+ @media (max-width: ${getWidthForBreakpointSize("medium")}px) {
115
+ .${props.builderBlock.id}-breakpoints {
116
+ flex-direction: var(--flex-dir-tablet);
117
+ align-items: stretch;
118
+ }
119
119
 
120
- .${props.builderBlock.id}-breakpoints > .builder-column {
121
- width: var(--column-width-tablet) !important;
122
- margin-left: var(--column-margin-left-tablet) !important;
123
- }
124
- }
120
+ .${props.builderBlock.id}-breakpoints > .builder-column {
121
+ width: var(--column-width-tablet) !important;
122
+ margin-left: var(--column-margin-left-tablet) !important;
123
+ }
124
+ }
125
125
 
126
- @media (max-width: ${getWidthForBreakpointSize("small")}px) {
127
- .${props.builderBlock.id}-breakpoints {
128
- flex-direction: var(--flex-dir);
129
- align-items: stretch;
130
- }
126
+ @media (max-width: ${getWidthForBreakpointSize("small")}px) {
127
+ .${props.builderBlock.id}-breakpoints {
128
+ flex-direction: var(--flex-dir);
129
+ align-items: stretch;
130
+ }
131
131
 
132
- .${props.builderBlock.id}-breakpoints > .builder-column {
133
- width: var(--column-width-mobile) !important;
134
- margin-left: var(--column-margin-left-mobile) !important;
135
- }
136
- },
137
- `;
132
+ .${props.builderBlock.id}-breakpoints > .builder-column {
133
+ width: var(--column-width-mobile) !important;
134
+ margin-left: var(--column-margin-left-mobile) !important;
135
+ }
136
+ },
137
+ `;
138
138
  }
139
139
  const builderContext = (0, react_1.useContext)(builder_context_js_1.default);
140
140
  return (React.createElement(react_native_1.View, { style: columnsCssVars(), dataSet: {
@@ -33,6 +33,7 @@ const render_content_1 = __importDefault(require("../../components/render-conten
33
33
  const builder_context_js_1 = __importDefault(require("../../context/builder.context.js"));
34
34
  const index_js_1 = require("../../functions/get-content/index.js");
35
35
  const target_1 = require("../../constants/target");
36
+ const logger_1 = require("../../helpers/logger");
36
37
  function Symbol(props) {
37
38
  var _a, _b, _c;
38
39
  const [className, setClassName] = (0, react_1.useState)(() => {
@@ -81,7 +82,7 @@ function Symbol(props) {
81
82
  }
82
83
  })
83
84
  .catch((err) => {
84
- console.error("[Builder.io]: Could not fetch symbol content: ", err);
85
+ logger_1.logger.error("Could not fetch symbol content: ", err);
85
86
  });
86
87
  }
87
88
  }
@@ -40,7 +40,6 @@ const target_js_1 = require("../../constants/target.js");
40
40
  const extract_text_styles_js_1 = require("../../functions/extract-text-styles.js");
41
41
  const render_component_1 = __importDefault(require("./render-component"));
42
42
  const get_react_native_block_styles_js_1 = require("../../functions/get-react-native-block-styles.js");
43
- const nullable_js_1 = require("../../helpers/nullable.js");
44
43
  function RenderBlock(props) {
45
44
  var _a, _b;
46
45
  const [component, setComponent] = (0, react_1.useState)(() => (0, render_block_helpers_js_1.getComponent)({
@@ -63,10 +62,10 @@ function RenderBlock(props) {
63
62
  }
64
63
  const [tag, setTag] = (0, react_1.useState)(() => props.block.tagName || "div");
65
64
  function canShowBlock() {
66
- if ((0, nullable_js_1.checkIsDefined)(useBlock().hide)) {
65
+ if ("hide" in useBlock()) {
67
66
  return !useBlock().hide;
68
67
  }
69
- if ((0, nullable_js_1.checkIsDefined)(useBlock().show)) {
68
+ if ("show" in useBlock()) {
70
69
  return useBlock().show;
71
70
  }
72
71
  return true;
@@ -158,6 +157,7 @@ function RenderBlock(props) {
158
157
  React.createElement(react_native_1.View, { ...attributes(), ...actions() },
159
158
  React.createElement(render_component_1.default, { ...renderComponentProps() }), (_a = childrenWithoutParentComponent()) === null || _a === void 0 ? void 0 :
160
159
  _a.map((child) => (React.createElement(RenderBlock, { key: "render-block-" + child.id, block: child, context: childrenContext() }))), (_b = childrenWithoutParentComponent()) === null || _b === void 0 ? void 0 :
161
- _b.map((child) => (React.createElement(block_styles_1.default, { key: "block-style-" + child.id, block: child, context: childrenContext() })))))) : null)) : (React.createElement(render_component_1.default, { ...renderComponentProps() })))) : null));
160
+ _b.map((child) => (React.createElement(block_styles_1.default, { key: "block-style-" + child.id, block: child, context: childrenContext() })))))) : null)) : (React.createElement(React.Fragment, null,
161
+ React.createElement(render_component_1.default, { ...renderComponentProps() }))))) : null));
162
162
  }
163
163
  exports.default = RenderBlock;
@@ -40,6 +40,7 @@ function RenderRepeatedBlock(props) {
40
40
  apiKey: props.repeatContext.apiKey,
41
41
  registeredComponents: props.repeatContext.registeredComponents,
42
42
  inheritedStyles: props.repeatContext.inheritedStyles,
43
+ apiVersion: props.repeatContext.apiVersion,
43
44
  } },
44
45
  React.createElement(render_block_1.default, { block: props.block, context: props.repeatContext })));
45
46
  }
@@ -43,16 +43,16 @@ ${(0, render_styles_helpers_2.getFontCss)({
43
43
  })}
44
44
 
45
45
  .builder-text > p:first-of-type, .builder-text > .builder-paragraph:first-of-type {
46
- margin: 0;
46
+ margin: 0;
47
47
  }
48
48
  .builder-text > p, .builder-text > .builder-paragraph {
49
- color: inherit;
50
- line-height: inherit;
51
- letter-spacing: inherit;
52
- font-weight: inherit;
53
- font-size: inherit;
54
- text-align: inherit;
55
- font-family: inherit;
49
+ color: inherit;
50
+ line-height: inherit;
51
+ letter-spacing: inherit;
52
+ font-weight: inherit;
53
+ font-size: inherit;
54
+ text-align: inherit;
55
+ font-family: inherit;
56
56
  }
57
57
  `);
58
58
  return React.createElement(render_inlined_styles_1.default, { styles: injectedStyles });
@@ -46,6 +46,7 @@ const nullable_js_1 = require("../../helpers/nullable.js");
46
46
  const interaction_js_1 = require("../../functions/track/interaction.js");
47
47
  const render_content_helpers_js_1 = require("./render-content.helpers.js");
48
48
  const target_js_1 = require("../../constants/target.js");
49
+ const logger_js_1 = require("../../helpers/logger.js");
49
50
  function RenderContent(props) {
50
51
  var _a, _b, _c, _d, _e;
51
52
  const elementRef = (0, react_1.useRef)(null);
@@ -219,7 +220,7 @@ function RenderContent(props) {
219
220
  }
220
221
  (0, react_1.useEffect)(() => {
221
222
  if (!props.apiKey) {
222
- console.error("[Builder.io]: No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
223
+ logger_js_1.logger.error("No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
223
224
  }
224
225
  if ((0, is_browser_js_1.isBrowser)()) {
225
226
  if ((0, is_editing_js_1.isEditing)()) {
@@ -259,19 +260,19 @@ function RenderContent(props) {
259
260
  // override normal content in preview mode
260
261
  if ((0, is_previewing_js_1.isPreviewing)()) {
261
262
  const searchParams = new URL(location.href).searchParams;
262
- const searchParamPreview = searchParams.get("builder.preview");
263
+ const searchParamPreviewModel = searchParams.get("builder.preview");
264
+ const searchParamPreviewId = searchParams.get(`builder.preview.${searchParamPreviewModel}`);
263
265
  const previewApiKey = searchParams.get("apiKey") || searchParams.get("builder.space");
264
266
  /**
265
267
  * Make sure that:
266
268
  * - the preview model name is the same as the one we're rendering, since there can be multiple models rendered * at the same time, e.g. header/page/footer. * - the API key is the same, since we don't want to preview content from other organizations.
267
- *
268
- * TO-DO: should we check that the preview item ID is the same as the initial one being rendered? Or would
269
- * this break scenarios where the item is not published yet?
269
+ * - if there is content, that the preview ID is the same as that of the one we receive.
270
270
  *
271
271
  * TO-DO: should we only update the state when there is a change?
272
272
  **/
273
- if (searchParamPreview === props.model &&
274
- previewApiKey === props.apiKey) {
273
+ if (searchParamPreviewModel === props.model &&
274
+ previewApiKey === props.apiKey &&
275
+ (!props.content || searchParamPreviewId === props.content.id)) {
275
276
  (0, index_js_1.getContent)({
276
277
  model: props.model,
277
278
  apiKey: props.apiKey,
@@ -318,6 +319,7 @@ function RenderContent(props) {
318
319
  apiKey: props.apiKey,
319
320
  apiVersion: props.apiVersion,
320
321
  registeredComponents: allRegisteredComponents,
322
+ inheritedStyles: {},
321
323
  } }, useContent ? (React.createElement(React.Fragment, null,
322
324
  React.createElement(react_native_1.ScrollView, { ref: elementRef, onClick: (event) => onClick(event), "builder-content-id": useContent === null || useContent === void 0 ? void 0 : useContent.id, "builder-model": props.model },
323
325
  target_js_1.TARGET !== "reactNative" ? (React.createElement(React.Fragment, null,
@@ -23,9 +23,12 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
23
  const target_js_1 = require("../constants/target.js");
24
24
  const css_js_1 = require("../helpers/css.js");
25
25
  const transform_block_properties_js_1 = require("./transform-block-properties.js");
26
+ const extractRelevantRootBlockProperties = (block) => {
27
+ return { href: block.href };
28
+ };
26
29
  function getBlockProperties(block) {
27
30
  var _a;
28
- const properties = __spreadProps(__spreadValues({}, block.properties), {
31
+ const properties = __spreadProps(__spreadValues(__spreadValues({}, extractRelevantRootBlockProperties(block)), block.properties), {
29
32
  "builder-id": block.id,
30
33
  style: getStyleAttribute(block.style),
31
34
  class: [block.id, "builder-block", block.class, (_a = block.properties) == null ? void 0 : _a.class].filter(Boolean).join(" ")
@@ -42,13 +42,14 @@ var __async = (__this, __arguments, generator) => {
42
42
  step((generator = generator.apply(__this, __arguments)).next());
43
43
  });
44
44
  };
45
+ const logger_js_1 = require("../../helpers/logger.js");
45
46
  const get_fetch_js_1 = require("../get-fetch.js");
46
47
  const ab_testing_js_1 = require("./ab-testing.js");
47
48
  const generate_content_url_js_1 = require("./generate-content-url.js");
48
49
  function getContent(options) {
49
50
  return __async(this, null, function* () {
50
51
  const allContent = yield getAllContent(__spreadProps(__spreadValues({}, options), { limit: 1 }));
51
- if ("results" in allContent) {
52
+ if (allContent && "results" in allContent) {
52
53
  return (allContent == null ? void 0 : allContent.results[0]) || null;
53
54
  }
54
55
  return null;
@@ -57,25 +58,31 @@ function getContent(options) {
57
58
  exports.getContent = getContent;
58
59
  function getAllContent(options) {
59
60
  return __async(this, null, function* () {
60
- const url = (0, generate_content_url_js_1.generateContentUrl)(options);
61
- const res = yield (0, get_fetch_js_1.fetch)(url.href);
62
- const content = yield res.json();
63
- if ("status" in content && !("results" in content)) {
64
- console.error("[Builder.io]: Error fetching data. ", content, options);
65
- return content;
66
- }
67
- const canTrack = options.canTrack !== false;
68
61
  try {
69
- if (canTrack && Array.isArray(content.results)) {
70
- for (const item of content.results) {
71
- yield (0, ab_testing_js_1.handleABTesting)({ item, canTrack });
62
+ const url = (0, generate_content_url_js_1.generateContentUrl)(options);
63
+ const res = yield (0, get_fetch_js_1.fetch)(url.href);
64
+ const content = yield res.json();
65
+ if ("status" in content && !("results" in content)) {
66
+ logger_js_1.logger.error("Error fetching data. ", { url, content, options });
67
+ return content;
68
+ }
69
+ const canTrack = options.canTrack !== false;
70
+ try {
71
+ if (canTrack && Array.isArray(content.results)) {
72
+ for (const item of content.results) {
73
+ yield (0, ab_testing_js_1.handleABTesting)({ item, canTrack });
74
+ }
72
75
  }
73
76
  }
77
+ catch (e) {
78
+ logger_js_1.logger.error("Could not setup A/B testing. ", e);
79
+ }
80
+ return content;
74
81
  }
75
- catch (e) {
76
- console.error("[Builder.io]: Could not setup A/B testing. ", e);
82
+ catch (error) {
83
+ logger_js_1.logger.error("Error fetching data. ", error);
84
+ return null;
77
85
  }
78
- return content;
79
86
  });
80
87
  }
81
88
  exports.getAllContent = getAllContent;
@@ -55,6 +55,7 @@ var __async = (__this, __arguments, generator) => {
55
55
  });
56
56
  };
57
57
  const target_js_1 = require("../../constants/target.js");
58
+ const logger_js_1 = require("../../helpers/logger.js");
58
59
  const sessionId_js_1 = require("../../helpers/sessionId.js");
59
60
  const visitorId_js_1 = require("../../helpers/visitorId.js");
60
61
  const is_browser_js_1 = require("../is-browser.js");
@@ -93,7 +94,7 @@ const createEvent = (_a) => __async(void 0, null, function* () {
93
94
  function _track(eventProps) {
94
95
  return __async(this, null, function* () {
95
96
  if (!eventProps.apiKey) {
96
- console.error("[Builder.io]: Missing API key for track call. Please provide your API key.");
97
+ logger_js_1.logger.error("Missing API key for track call. Please provide your API key.");
97
98
  return;
98
99
  }
99
100
  if (!eventProps.canTrack) {
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.logger = void 0;
4
+ const MSG_PREFIX = "[Builder.io]: ";
5
+ const logger = {
6
+ log: (...message) => console.log(MSG_PREFIX, ...message),
7
+ error: (...message) => console.error(MSG_PREFIX, ...message),
8
+ warn: (...message) => console.warn(MSG_PREFIX, ...message)
9
+ };
10
+ exports.logger = logger;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-react-native",
3
3
  "description": "Builder.io SDK for React Native",
4
- "version": "0.2.1",
4
+ "version": "0.2.3",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",
@@ -24,9 +24,11 @@ function Button(props) {
24
24
  </View>
25
25
  </>
26
26
  ) : (
27
- <View {...props.attributes} style={styles.view1}>
28
- <BaseText>{props.text}</BaseText>
29
- </View>
27
+ <>
28
+ <View {...props.attributes} style={styles.view1}>
29
+ <BaseText>{props.text}</BaseText>
30
+ </View>
31
+ </>
30
32
  )}
31
33
  </>
32
34
  );
@@ -107,30 +107,30 @@ function Columns(props) {
107
107
 
108
108
  function columnsStyles() {
109
109
  return `
110
- @media (max-width: ${getWidthForBreakpointSize("medium")}px) {
111
- .${props.builderBlock.id}-breakpoints {
112
- flex-direction: var(--flex-dir-tablet);
113
- align-items: stretch;
114
- }
115
-
116
- .${props.builderBlock.id}-breakpoints > .builder-column {
117
- width: var(--column-width-tablet) !important;
118
- margin-left: var(--column-margin-left-tablet) !important;
119
- }
120
- }
121
-
122
- @media (max-width: ${getWidthForBreakpointSize("small")}px) {
123
- .${props.builderBlock.id}-breakpoints {
124
- flex-direction: var(--flex-dir);
125
- align-items: stretch;
126
- }
127
-
128
- .${props.builderBlock.id}-breakpoints > .builder-column {
129
- width: var(--column-width-mobile) !important;
130
- margin-left: var(--column-margin-left-mobile) !important;
131
- }
132
- },
133
- `;
110
+ @media (max-width: ${getWidthForBreakpointSize("medium")}px) {
111
+ .${props.builderBlock.id}-breakpoints {
112
+ flex-direction: var(--flex-dir-tablet);
113
+ align-items: stretch;
114
+ }
115
+
116
+ .${props.builderBlock.id}-breakpoints > .builder-column {
117
+ width: var(--column-width-tablet) !important;
118
+ margin-left: var(--column-margin-left-tablet) !important;
119
+ }
120
+ }
121
+
122
+ @media (max-width: ${getWidthForBreakpointSize("small")}px) {
123
+ .${props.builderBlock.id}-breakpoints {
124
+ flex-direction: var(--flex-dir);
125
+ align-items: stretch;
126
+ }
127
+
128
+ .${props.builderBlock.id}-breakpoints > .builder-column {
129
+ width: var(--column-width-mobile) !important;
130
+ margin-left: var(--column-margin-left-mobile) !important;
131
+ }
132
+ },
133
+ `;
134
134
  }
135
135
 
136
136
  const builderContext = useContext(BuilderContext);
@@ -12,6 +12,7 @@ import RenderContent from "../../components/render-content/render-content";
12
12
  import BuilderContext from "../../context/builder.context.js";
13
13
  import { getContent } from "../../functions/get-content/index.js";
14
14
  import { TARGET } from "../../constants/target";
15
+ import { logger } from "../../helpers/logger";
15
16
 
16
17
  function Symbol(props) {
17
18
  const [className, setClassName] = useState(() =>
@@ -61,7 +62,7 @@ function Symbol(props) {
61
62
  }
62
63
  })
63
64
  .catch((err) => {
64
- console.error("[Builder.io]: Could not fetch symbol content: ", err);
65
+ logger.error("Could not fetch symbol content: ", err);
65
66
  });
66
67
  }
67
68
  }
@@ -24,7 +24,6 @@ import { TARGET } from "../../constants/target.js";
24
24
  import { extractTextStyles } from "../../functions/extract-text-styles.js";
25
25
  import RenderComponent from "./render-component";
26
26
  import { getReactNativeBlockStyles } from "../../functions/get-react-native-block-styles.js";
27
- import { checkIsDefined } from "../../helpers/nullable.js";
28
27
 
29
28
  function RenderBlock(props) {
30
29
  const [component, setComponent] = useState(() =>
@@ -55,10 +54,10 @@ function RenderBlock(props) {
55
54
  const [tag, setTag] = useState(() => props.block.tagName || "div");
56
55
 
57
56
  function canShowBlock() {
58
- if (checkIsDefined(useBlock().hide)) {
57
+ if ("hide" in useBlock()) {
59
58
  return !useBlock().hide;
60
59
  }
61
- if (checkIsDefined(useBlock().show)) {
60
+ if ("show" in useBlock()) {
62
61
  return useBlock().show;
63
62
  }
64
63
  return true;
@@ -199,7 +198,9 @@ function RenderBlock(props) {
199
198
  ) : null}
200
199
  </>
201
200
  ) : (
202
- <RenderComponent {...renderComponentProps()} />
201
+ <>
202
+ <RenderComponent {...renderComponentProps()} />
203
+ </>
203
204
  )}
204
205
  </>
205
206
  ) : null}
@@ -22,6 +22,7 @@ function RenderRepeatedBlock(props) {
22
22
  apiKey: props.repeatContext.apiKey,
23
23
  registeredComponents: props.repeatContext.registeredComponents,
24
24
  inheritedStyles: props.repeatContext.inheritedStyles,
25
+ apiVersion: props.repeatContext.apiVersion,
25
26
  }}
26
27
  >
27
28
  <RenderBlock block={props.block} context={props.repeatContext} />
@@ -24,16 +24,16 @@ ${getFontCss({
24
24
  })}
25
25
 
26
26
  .builder-text > p:first-of-type, .builder-text > .builder-paragraph:first-of-type {
27
- margin: 0;
27
+ margin: 0;
28
28
  }
29
29
  .builder-text > p, .builder-text > .builder-paragraph {
30
- color: inherit;
31
- line-height: inherit;
32
- letter-spacing: inherit;
33
- font-weight: inherit;
34
- font-size: inherit;
35
- text-align: inherit;
36
- font-family: inherit;
30
+ color: inherit;
31
+ line-height: inherit;
32
+ letter-spacing: inherit;
33
+ font-weight: inherit;
34
+ font-size: inherit;
35
+ text-align: inherit;
36
+ font-family: inherit;
37
37
  }
38
38
  `
39
39
  );
@@ -34,6 +34,7 @@ import {
34
34
  getContextStateInitialValue,
35
35
  } from "./render-content.helpers.js";
36
36
  import { TARGET } from "../../constants/target.js";
37
+ import { logger } from "../../helpers/logger.js";
37
38
 
38
39
  function RenderContent(props) {
39
40
  const elementRef = useRef(null);
@@ -241,8 +242,8 @@ function RenderContent(props) {
241
242
 
242
243
  useEffect(() => {
243
244
  if (!props.apiKey) {
244
- console.error(
245
- "[Builder.io]: No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop."
245
+ logger.error(
246
+ "No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop."
246
247
  );
247
248
  }
248
249
  if (isBrowser()) {
@@ -288,22 +289,24 @@ function RenderContent(props) {
288
289
  // override normal content in preview mode
289
290
  if (isPreviewing()) {
290
291
  const searchParams = new URL(location.href).searchParams;
291
- const searchParamPreview = searchParams.get("builder.preview");
292
+ const searchParamPreviewModel = searchParams.get("builder.preview");
293
+ const searchParamPreviewId = searchParams.get(
294
+ `builder.preview.${searchParamPreviewModel}`
295
+ );
292
296
  const previewApiKey =
293
297
  searchParams.get("apiKey") || searchParams.get("builder.space");
294
298
 
295
299
  /**
296
300
  * Make sure that:
297
301
  * - the preview model name is the same as the one we're rendering, since there can be multiple models rendered * at the same time, e.g. header/page/footer. * - the API key is the same, since we don't want to preview content from other organizations.
298
- *
299
- * TO-DO: should we check that the preview item ID is the same as the initial one being rendered? Or would
300
- * this break scenarios where the item is not published yet?
302
+ * - if there is content, that the preview ID is the same as that of the one we receive.
301
303
  *
302
304
  * TO-DO: should we only update the state when there is a change?
303
305
  **/
304
306
  if (
305
- searchParamPreview === props.model &&
306
- previewApiKey === props.apiKey
307
+ searchParamPreviewModel === props.model &&
308
+ previewApiKey === props.apiKey &&
309
+ (!props.content || searchParamPreviewId === props.content.id)
307
310
  ) {
308
311
  getContent({
309
312
  model: props.model,
@@ -359,6 +362,7 @@ function RenderContent(props) {
359
362
  apiKey: props.apiKey,
360
363
  apiVersion: props.apiVersion,
361
364
  registeredComponents: allRegisteredComponents,
365
+ inheritedStyles: {},
362
366
  }}
363
367
  >
364
368
  {useContent ? (
@@ -20,9 +20,12 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
20
  import { TARGET } from "../constants/target.js";
21
21
  import { convertStyleMapToCSSArray } from "../helpers/css.js";
22
22
  import { transformBlockProperties } from "./transform-block-properties.js";
23
+ const extractRelevantRootBlockProperties = (block) => {
24
+ return { href: block.href };
25
+ };
23
26
  function getBlockProperties(block) {
24
27
  var _a;
25
- const properties = __spreadProps(__spreadValues({}, block.properties), {
28
+ const properties = __spreadProps(__spreadValues(__spreadValues({}, extractRelevantRootBlockProperties(block)), block.properties), {
26
29
  "builder-id": block.id,
27
30
  style: getStyleAttribute(block.style),
28
31
  class: [block.id, "builder-block", block.class, (_a = block.properties) == null ? void 0 : _a.class].filter(Boolean).join(" ")
@@ -37,13 +37,14 @@ var __async = (__this, __arguments, generator) => {
37
37
  step((generator = generator.apply(__this, __arguments)).next());
38
38
  });
39
39
  };
40
+ import { logger } from "../../helpers/logger.js";
40
41
  import { fetch } from "../get-fetch.js";
41
42
  import { handleABTesting } from "./ab-testing.js";
42
43
  import { generateContentUrl } from "./generate-content-url.js";
43
44
  function getContent(options) {
44
45
  return __async(this, null, function* () {
45
46
  const allContent = yield getAllContent(__spreadProps(__spreadValues({}, options), { limit: 1 }));
46
- if ("results" in allContent) {
47
+ if (allContent && "results" in allContent) {
47
48
  return (allContent == null ? void 0 : allContent.results[0]) || null;
48
49
  }
49
50
  return null;
@@ -51,24 +52,29 @@ function getContent(options) {
51
52
  }
52
53
  function getAllContent(options) {
53
54
  return __async(this, null, function* () {
54
- const url = generateContentUrl(options);
55
- const res = yield fetch(url.href);
56
- const content = yield res.json();
57
- if ("status" in content && !("results" in content)) {
58
- console.error("[Builder.io]: Error fetching data. ", content, options);
59
- return content;
60
- }
61
- const canTrack = options.canTrack !== false;
62
55
  try {
63
- if (canTrack && Array.isArray(content.results)) {
64
- for (const item of content.results) {
65
- yield handleABTesting({ item, canTrack });
56
+ const url = generateContentUrl(options);
57
+ const res = yield fetch(url.href);
58
+ const content = yield res.json();
59
+ if ("status" in content && !("results" in content)) {
60
+ logger.error("Error fetching data. ", { url, content, options });
61
+ return content;
62
+ }
63
+ const canTrack = options.canTrack !== false;
64
+ try {
65
+ if (canTrack && Array.isArray(content.results)) {
66
+ for (const item of content.results) {
67
+ yield handleABTesting({ item, canTrack });
68
+ }
66
69
  }
70
+ } catch (e) {
71
+ logger.error("Could not setup A/B testing. ", e);
67
72
  }
68
- } catch (e) {
69
- console.error("[Builder.io]: Could not setup A/B testing. ", e);
73
+ return content;
74
+ } catch (error) {
75
+ logger.error("Error fetching data. ", error);
76
+ return null;
70
77
  }
71
- return content;
72
78
  });
73
79
  }
74
80
  export {
@@ -50,6 +50,7 @@ var __async = (__this, __arguments, generator) => {
50
50
  });
51
51
  };
52
52
  import { TARGET } from "../../constants/target.js";
53
+ import { logger } from "../../helpers/logger.js";
53
54
  import { getSessionId } from "../../helpers/sessionId.js";
54
55
  import { getVisitorId } from "../../helpers/visitorId.js";
55
56
  import { isBrowser } from "../is-browser.js";
@@ -95,7 +96,7 @@ const createEvent = (_a) => __async(void 0, null, function* () {
95
96
  function _track(eventProps) {
96
97
  return __async(this, null, function* () {
97
98
  if (!eventProps.apiKey) {
98
- console.error("[Builder.io]: Missing API key for track call. Please provide your API key.");
99
+ logger.error("Missing API key for track call. Please provide your API key.");
99
100
  return;
100
101
  }
101
102
  if (!eventProps.canTrack) {
@@ -0,0 +1,9 @@
1
+ const MSG_PREFIX = "[Builder.io]: ";
2
+ const logger = {
3
+ log: (...message) => console.log(MSG_PREFIX, ...message),
4
+ error: (...message) => console.error(MSG_PREFIX, ...message),
5
+ warn: (...message) => console.warn(MSG_PREFIX, ...message)
6
+ };
7
+ export {
8
+ logger
9
+ };