@builder.io/sdk-solid 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ### 0.2.2
2
+
3
+ - Fix: dynamic bindings for Link URLs.
4
+ - Fix: previewing content that includes a symbol whose `model` property is a `page`.
5
+ - Fix: "Show If"/"Hide If" bindings when the initial value is `undefined`.
6
+
1
7
  ### 0.2.1
2
8
 
3
9
  - No Changes.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-solid",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./solid-index.jsx",
@@ -4,6 +4,7 @@ import RenderContent from "../../components/render-content/render-content.jsx";
4
4
  import BuilderContext from "../../context/builder.context.js";
5
5
  import { getContent } from "../../functions/get-content/index.js";
6
6
  import { TARGET } from "../../constants/target";
7
+ import { logger } from "../../helpers/logger";
7
8
 
8
9
  function Symbol(props) {
9
10
  const [className, setClassName] = createSignal(
@@ -53,7 +54,7 @@ function Symbol(props) {
53
54
  }
54
55
  })
55
56
  .catch((err) => {
56
- console.error("[Builder.io]: Could not fetch symbol content: ", err);
57
+ logger.error("Could not fetch symbol content: ", err);
57
58
  });
58
59
  }
59
60
  }
@@ -17,7 +17,6 @@ import { TARGET } from "../../constants/target.js";
17
17
  import { extractTextStyles } from "../../functions/extract-text-styles.js";
18
18
  import RenderComponent from "./render-component.jsx";
19
19
  import { getReactNativeBlockStyles } from "../../functions/get-react-native-block-styles.js";
20
- import { checkIsDefined } from "../../helpers/nullable.js";
21
20
 
22
21
  function RenderBlock(props) {
23
22
  const [component, setComponent] = createSignal(
@@ -52,10 +51,10 @@ function RenderBlock(props) {
52
51
  }
53
52
 
54
53
  function canShowBlock() {
55
- if (checkIsDefined(useBlock().hide)) {
54
+ if ("hide" in useBlock()) {
56
55
  return !useBlock().hide;
57
56
  }
58
- if (checkIsDefined(useBlock().show)) {
57
+ if ("show" in useBlock()) {
59
58
  return useBlock().show;
60
59
  }
61
60
  return true;
@@ -28,6 +28,7 @@ import {
28
28
  getContextStateInitialValue,
29
29
  } from "./render-content.helpers.js";
30
30
  import { TARGET } from "../../constants/target.js";
31
+ import { logger } from "../../helpers/logger.js";
31
32
 
32
33
  function RenderContent(props) {
33
34
  const [forceReRenderCount, setForceReRenderCount] = createSignal(0);
@@ -235,8 +236,8 @@ function RenderContent(props) {
235
236
 
236
237
  onMount(() => {
237
238
  if (!props.apiKey) {
238
- console.error(
239
- "[Builder.io]: No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop."
239
+ logger.error(
240
+ "No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop."
240
241
  );
241
242
  }
242
243
  if (isBrowser()) {
@@ -282,7 +283,10 @@ function RenderContent(props) {
282
283
  // override normal content in preview mode
283
284
  if (isPreviewing()) {
284
285
  const searchParams = new URL(location.href).searchParams;
285
- const searchParamPreview = searchParams.get("builder.preview");
286
+ const searchParamPreviewModel = searchParams.get("builder.preview");
287
+ const searchParamPreviewId = searchParams.get(
288
+ `builder.preview.${searchParamPreviewModel}`
289
+ );
286
290
  const previewApiKey =
287
291
  searchParams.get("apiKey") || searchParams.get("builder.space");
288
292
 
@@ -291,15 +295,14 @@ function RenderContent(props) {
291
295
  * - the preview model name is the same as the one we're rendering, since there can be multiple models rendered
292
296
  * at the same time, e.g. header/page/footer.
293
297
  * - the API key is the same, since we don't want to preview content from other organizations.
294
- *
295
- * TO-DO: should we check that the preview item ID is the same as the initial one being rendered? Or would
296
- * this break scenarios where the item is not published yet?
298
+ * - if there is content, that the preview ID is the same as that of the one we receive.
297
299
  *
298
300
  * TO-DO: should we only update the state when there is a change?
299
301
  **/
300
302
  if (
301
- searchParamPreview === props.model &&
302
- previewApiKey === props.apiKey
303
+ searchParamPreviewModel === props.model &&
304
+ previewApiKey === props.apiKey &&
305
+ (!props.content || searchParamPreviewId === props.content.id)
303
306
  ) {
304
307
  getContent({
305
308
  model: props.model,
@@ -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. ", 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
+ };