@builder.io/sdk-solid 0.0.21 → 0.0.22

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-solid",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./solid-index.jsx",
@@ -9,6 +9,7 @@
9
9
  ".": "./solid-index.jsx"
10
10
  },
11
11
  "scripts": {
12
+ "build": "echo 'no need to build solid SDK'",
12
13
  "release:patch": "npm version patch --no-git-tag-version && npm publish --access public",
13
14
  "release:dev": "npm version prerelease --no-git-tag-version && npm publish --tag dev --access public"
14
15
  },
@@ -28,6 +28,17 @@ function Image(props) {
28
28
  return "";
29
29
  }
30
30
  }
31
+ function aspectRatioCss() {
32
+ const aspectRatioStyles = {
33
+ position: "absolute",
34
+ height: "100%",
35
+ width: "100%",
36
+ left: "0px",
37
+ top: "0px"
38
+ };
39
+ const out = props.aspectRatio ? aspectRatioStyles : undefined;
40
+ return out;
41
+ }
31
42
  return <>
32
43
  <picture>
33
44
  <Show when={webpSrcSet()}>
@@ -35,15 +46,11 @@ function Image(props) {
35
46
  </Show>
36
47
  <img class={"builder-image" + (props.className ? " " + props.className : "") + " " + css({
37
48
  opacity: "1",
38
- transition: "opacity 0.2s ease-in-out",
39
- position: "absolute",
40
- height: "100%",
41
- width: "100%",
42
- top: "0px",
43
- left: "0px"
49
+ transition: "opacity 0.2s ease-in-out"
44
50
  })} loading="lazy" alt={props.altText} role={props.altText ? "presentation" : undefined} style={{
45
- "object-position": props.backgroundSize || "center",
46
- "object-fit": props.backgroundSize || "cover"
51
+ "object-position": props.backgroundPosition || "center",
52
+ "object-fit": props.backgroundSize || "cover",
53
+ ...aspectRatioCss()
47
54
  }} src={props.image} srcset={srcSetToUse()} sizes={props.sizes} />
48
55
  <source srcset={srcSetToUse()} />
49
56
  </picture>
@@ -47,14 +47,16 @@ function RenderBlock(props) {
47
47
  shouldEvaluateBindings: true
48
48
  });
49
49
  }
50
+ function actions() {
51
+ return getBlockActions({
52
+ block: useBlock(),
53
+ state: props.context.state,
54
+ context: props.context.context
55
+ });
56
+ }
50
57
  function attributes() {
51
58
  return {
52
59
  ...getBlockProperties(useBlock()),
53
- ...getBlockActions({
54
- block: useBlock(),
55
- state: props.context.state,
56
- context: props.context.context
57
- }),
58
60
  ...(TARGET === "reactNative" ? {
59
61
  style: getReactNativeBlockStyles({
60
62
  block: useBlock(),
@@ -77,7 +79,10 @@ function RenderBlock(props) {
77
79
  * they are provided to the component itself directly.
78
80
  */
79
81
  ...(shouldWrap() ? {} : {
80
- attributes: attributes()
82
+ attributes: {
83
+ ...attributes(),
84
+ ...actions()
85
+ }
81
86
  })
82
87
  },
83
88
  context: childrenContext()
@@ -169,7 +174,7 @@ function RenderBlock(props) {
169
174
  }
170
175
  return <Show fallback={<Dynamic {...renderComponentProps()} component={renderComponentTag()}></Dynamic>} when={shouldWrap()}>
171
176
  <Show when={isEmptyHtmlElement(tag())}>
172
- <Dynamic {...attributes()} component={tag()}></Dynamic>
177
+ <Dynamic {...attributes()} {...actions()} component={tag()}></Dynamic>
173
178
  </Show>
174
179
  <Show when={!isEmptyHtmlElement(tag()) && repeatItemData()}>
175
180
  <For each={repeatItemData()}>
@@ -180,7 +185,7 @@ function RenderBlock(props) {
180
185
  </For>
181
186
  </Show>
182
187
  <Show when={!isEmptyHtmlElement(tag()) && !repeatItemData()}>
183
- <Dynamic {...attributes()} component={tag()}>
188
+ <Dynamic {...attributes()} {...actions()} component={tag()}>
184
189
  <Dynamic {...renderComponentProps()} component={renderComponentTag()}></Dynamic>
185
190
  <For each={childrenWithoutParentComponent()}>
186
191
  {(child, _index) => {
@@ -3,7 +3,6 @@ import { Dynamic } from "solid-js/web";
3
3
  import { createStore, reconcile } from "solid-js/store";
4
4
  import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
5
5
  import { TARGET } from "../../constants/target.js";
6
- import BuilderContext from "../../context/builder.context.js";
7
6
  import { evaluate } from "../../functions/evaluate.js";
8
7
  import { getContent } from "../../functions/get-content/index.js";
9
8
  import { getFetch } from "../../functions/get-fetch.js";
@@ -14,6 +13,7 @@ import { components, createRegisterComponentMessage } from "../../functions/regi
14
13
  import { _track } from "../../functions/track.js";
15
14
  import RenderBlocks from "../render-blocks.jsx";
16
15
  import RenderContentStyles from "./components/render-styles.jsx";
16
+ import BuilderContext from "../../context/builder.context.js";
17
17
  import { registerInsertMenu, setupBrowserForEditing } from "../../scripts/init-editing.js";
18
18
  function RenderContent(props) {
19
19
  const [forceReRenderCount, setForceReRenderCount] = createSignal(0);
@@ -27,6 +27,9 @@ function RenderContent(props) {
27
27
  return {
28
28
  ...props.content?.data?.state,
29
29
  ...props.data,
30
+ ...(props.locale ? {
31
+ locale: props.locale
32
+ } : {}),
30
33
  ...overrideState()
31
34
  };
32
35
  }
@@ -167,11 +170,21 @@ function RenderContent(props) {
167
170
  createEffect(on(() => [overrideContent(), props.content, props.data], () => setUseContent(reconcile(updateUseContent()))));
168
171
  let elementRef;
169
172
  onMount(() => {
173
+ if (!props.apiKey) {
174
+ console.error("[Builder.io]: No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
175
+ }
170
176
  if (isBrowser()) {
171
177
  if (isEditing()) {
172
178
  setForceReRenderCount(forceReRenderCount() + 1);
173
179
  registerInsertMenu();
174
- setupBrowserForEditing();
180
+ setupBrowserForEditing({
181
+ ...(props.locale ? {
182
+ locale: props.locale
183
+ } : {}),
184
+ ...(props.includeRefs ? {
185
+ includeRefs: props.includeRefs
186
+ } : {})
187
+ });
175
188
  Object.values(allRegisteredComponents()).forEach(registeredComponent => {
176
189
  const message = createRegisterComponentMessage(registeredComponent);
177
190
  window.parent?.postMessage(message, "*");
@@ -216,7 +229,7 @@ function RenderContent(props) {
216
229
  function onUpdateFn_0() {
217
230
  evaluateJsCode();
218
231
  }
219
- createEffect(on(() => [useContent?.data?.jsCode], onUpdateFn_0));
232
+ createEffect(on(() => [useContent?.data?.jsCode, contentState()], onUpdateFn_0));
220
233
  function onUpdateFn_1() {
221
234
  runHttpRequests();
222
235
  }
@@ -4,7 +4,8 @@ function evaluate({
4
4
  code,
5
5
  context,
6
6
  state,
7
- event
7
+ event,
8
+ isExpression = true
8
9
  }) {
9
10
  if (code === "") {
10
11
  console.warn("Skipping evaluation of empty code block.");
@@ -15,12 +16,12 @@ function evaluate({
15
16
  isBrowser: isBrowser(),
16
17
  isServer: !isBrowser()
17
18
  };
18
- const useReturn = !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "));
19
+ const useReturn = isExpression && !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "));
19
20
  const useCode = useReturn ? `return (${code});` : code;
20
21
  try {
21
22
  return new Function("builder", "Builder", "state", "context", "event", useCode)(builder, builder, state, context, event);
22
23
  } catch (e) {
23
- console.warn("Builder custom code error: \n While Evaluating: \n ", useCode, "\n", e.message || e);
24
+ console.warn("Builder custom code error: \n While Evaluating: \n ", useCode, "\n", e);
24
25
  }
25
26
  }
26
27
  export {
@@ -1,12 +1,11 @@
1
1
  import { evaluate } from "./evaluate.js";
2
- function crateEventHandler(value, options) {
3
- return (event) => evaluate({
4
- code: value,
5
- context: options.context,
6
- state: options.state,
7
- event
8
- });
9
- }
2
+ const createEventHandler = (value, options) => (event) => evaluate({
3
+ code: value,
4
+ context: options.context,
5
+ state: options.state,
6
+ event,
7
+ isExpression: false
8
+ });
10
9
  export {
11
- crateEventHandler
10
+ createEventHandler
12
11
  };
@@ -1,5 +1,5 @@
1
1
  import { getEventHandlerName } from "./event-handler-name.js";
2
- import { crateEventHandler } from "./get-block-actions-handler.js";
2
+ import { createEventHandler } from "./get-block-actions-handler.js";
3
3
  function getBlockActions(options) {
4
4
  var _a;
5
5
  const obj = {};
@@ -9,7 +9,7 @@ function getBlockActions(options) {
9
9
  continue;
10
10
  }
11
11
  const value = optionActions[key];
12
- obj[getEventHandlerName(key)] = crateEventHandler(value, options);
12
+ obj[getEventHandlerName(key)] = createEventHandler(value, options);
13
13
  }
14
14
  return obj;
15
15
  }
@@ -1,5 +1,6 @@
1
1
  import { isBrowser } from "../is-browser.js";
2
2
  const BUILDER_SEARCHPARAMS_PREFIX = "builder.";
3
+ const BUILDER_OPTIONS_PREFIX = "options.";
3
4
  const convertSearchParamsToQueryObject = (searchParams) => {
4
5
  const options = {};
5
6
  searchParams.forEach((value, key) => {
@@ -15,7 +16,7 @@ const getBuilderSearchParams = (_options) => {
15
16
  const newOptions = {};
16
17
  Object.keys(options).forEach((key) => {
17
18
  if (key.startsWith(BUILDER_SEARCHPARAMS_PREFIX)) {
18
- const trimmedKey = key.replace(BUILDER_SEARCHPARAMS_PREFIX, "");
19
+ const trimmedKey = key.replace(BUILDER_SEARCHPARAMS_PREFIX, "").replace(BUILDER_OPTIONS_PREFIX, "");
19
20
  newOptions[trimmedKey] = options[key];
20
21
  }
21
22
  });
@@ -57,12 +57,13 @@ const generateContentUrl = (options) => {
57
57
  noTraverse = false,
58
58
  model,
59
59
  apiKey,
60
- includeRefs = true
60
+ includeRefs = true,
61
+ locale
61
62
  } = options;
62
63
  if (!apiKey) {
63
64
  throw new Error("Missing API key");
64
65
  }
65
- const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}`);
66
+ const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}${locale ? `&locale=${locale}` : ""}`);
66
67
  const queryOptions = __spreadValues(__spreadValues({}, getBuilderSearchParamsFromWindow()), normalizeSearchParams(options.options || {}));
67
68
  const flattened = flatten(queryOptions);
68
69
  for (const key in flattened) {
@@ -85,7 +86,7 @@ function getAllContent(options) {
85
86
  const fetch = yield getFetch();
86
87
  const content = yield fetch(url.href).then((res) => res.json());
87
88
  const canTrack = options.canTrack !== false;
88
- if (canTrack) {
89
+ if (canTrack && Array.isArray(content.results)) {
89
90
  for (const item of content.results) {
90
91
  yield handleABTesting({ item, canTrack });
91
92
  }
@@ -90,6 +90,10 @@ const createEvent = (_a) => __async(void 0, null, function* () {
90
90
  });
91
91
  function _track(eventProps) {
92
92
  return __async(this, null, function* () {
93
+ if (!eventProps.apiKey) {
94
+ console.error("[Builder.io]: Missing API key for track call. Please provide your API key.");
95
+ return;
96
+ }
93
97
  if (!eventProps.canTrack) {
94
98
  return;
95
99
  }
@@ -20,8 +20,8 @@ const registerInsertMenu = () => {
20
20
  });
21
21
  };
22
22
  let isSetupForEditing = false;
23
- const setupBrowserForEditing = () => {
24
- var _a;
23
+ const setupBrowserForEditing = (options = {}) => {
24
+ var _a, _b;
25
25
  if (isSetupForEditing) {
26
26
  return;
27
27
  }
@@ -36,8 +36,14 @@ const setupBrowserForEditing = () => {
36
36
  supportsCustomBreakpoints: true
37
37
  }
38
38
  }, "*");
39
+ (_b = window.parent) == null ? void 0 : _b.postMessage({
40
+ type: "builder.updateContent",
41
+ data: {
42
+ options
43
+ }
44
+ }, "*");
39
45
  window.addEventListener("message", ({ data }) => {
40
- var _a2, _b;
46
+ var _a2, _b2;
41
47
  if (!(data == null ? void 0 : data.type)) {
42
48
  return;
43
49
  }
@@ -69,7 +75,7 @@ const setupBrowserForEditing = () => {
69
75
  }, "*");
70
76
  }).catch(console.error);
71
77
  } else {
72
- (_b = window.parent) == null ? void 0 : _b.postMessage({
78
+ (_b2 = window.parent) == null ? void 0 : _b2.postMessage({
73
79
  type: "builder.evaluateResult",
74
80
  data: { result, id }
75
81
  }, "*");
@@ -1,10 +0,0 @@
1
- function markMutable(value) {
2
- return value;
3
- }
4
- function markPropsMutable(props) {
5
- return props;
6
- }
7
- export {
8
- markMutable,
9
- markPropsMutable
10
- };