@builder.io/sdk-react 0.0.3 → 0.0.5

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.
Files changed (36) hide show
  1. package/package.json +2 -1
  2. package/packages/_rsc/src/blocks/columns/columns.js +73 -16
  3. package/packages/_rsc/src/blocks/image/image.js +20 -14
  4. package/packages/_rsc/src/blocks/section/section.js +12 -3
  5. package/packages/_rsc/src/blocks/symbol/symbol.js +10 -1
  6. package/packages/_rsc/src/components/render-block/render-block.js +18 -10
  7. package/packages/_rsc/src/components/render-content/render-content.js +21 -4
  8. package/packages/_rsc/src/functions/get-block-actions-handler.js +8 -9
  9. package/packages/_rsc/src/functions/get-block-actions.js +2 -2
  10. package/packages/_rsc/src/functions/get-block-properties.js +22 -1
  11. package/packages/_rsc/src/functions/get-builder-search-params/index.js +2 -1
  12. package/packages/_rsc/src/functions/get-content/index.js +4 -3
  13. package/packages/_rsc/src/functions/get-react-native-block-styles.js +3 -2
  14. package/packages/_rsc/src/functions/track.js +4 -0
  15. package/packages/_rsc/src/functions/transform-block-properties.js +6 -0
  16. package/packages/_rsc/src/helpers/css.js +9 -3
  17. package/packages/_rsc/src/scripts/init-editing.js +10 -4
  18. package/src/blocks/columns/columns.jsx +72 -16
  19. package/src/blocks/image/image.jsx +36 -14
  20. package/src/blocks/section/section.jsx +12 -3
  21. package/src/blocks/symbol/symbol.jsx +12 -3
  22. package/src/components/render-block/render-block.jsx +18 -10
  23. package/src/components/render-content/render-content.jsx +31 -7
  24. package/src/functions/evaluate.js +4 -3
  25. package/src/functions/get-block-actions-handler.js +8 -9
  26. package/src/functions/get-block-actions.js +2 -2
  27. package/src/functions/get-block-properties.js +22 -1
  28. package/src/functions/get-builder-search-params/index.js +2 -1
  29. package/src/functions/get-content/index.js +4 -3
  30. package/src/functions/get-react-native-block-styles.js +3 -2
  31. package/src/functions/track.js +4 -0
  32. package/src/functions/transform-block-properties.js +6 -0
  33. package/src/helpers/css.js +9 -3
  34. package/src/scripts/init-editing.js +10 -4
  35. package/packages/_rsc/src/functions/mark-mutable.js +0 -10
  36. package/src/functions/mark-mutable.js +0 -10
@@ -16,6 +16,10 @@ var __spreadValues = (a, b) => {
16
16
  };
17
17
  import * as React from "react";
18
18
  import RenderBlocks from "../../components/render-blocks.jsx";
19
+ import { getSizesForBreakpoints } from "../../constants/device-sizes";
20
+ import RenderInlinedStyles from "../../components/render-inlined-styles.jsx";
21
+ import { TARGET } from "../../constants/target.js";
22
+ import { convertStyleMapToCSS } from "../../helpers/css";
19
23
  function Columns(props) {
20
24
  var _a;
21
25
  function getGutterSize() {
@@ -56,15 +60,74 @@ function Columns(props) {
56
60
  "--column-margin-left-tablet": maybeApplyForTablet(marginLeft)
57
61
  };
58
62
  }
63
+ function getWidthForBreakpointSize(size) {
64
+ const breakpointSizes = getSizesForBreakpoints(props.customBreakpoints || {});
65
+ return breakpointSizes[size].max;
66
+ }
67
+ function columnStyleObjects() {
68
+ return {
69
+ columns: {
70
+ small: {
71
+ flexDirection: "var(--flex-dir)",
72
+ alignItems: "stretch"
73
+ },
74
+ medium: {
75
+ flexDirection: "var(--flex-dir-tablet)",
76
+ alignItems: "stretch"
77
+ }
78
+ },
79
+ column: {
80
+ small: {
81
+ width: "var(--column-width) !important",
82
+ marginLeft: "var(--column-margin-left) !important"
83
+ },
84
+ medium: {
85
+ width: "var(--column-width-tablet) !important",
86
+ marginLeft: "var(--column-margin-left-tablet) !important"
87
+ }
88
+ }
89
+ };
90
+ }
91
+ function columnsStyles() {
92
+ return `
93
+ @media (max-width: ${getWidthForBreakpointSize("medium")}px) {
94
+ .${props.builderBlock.id}-breakpoints {
95
+ ${convertStyleMapToCSS(columnStyleObjects().columns.medium)}
96
+ }
97
+
98
+ .${props.builderBlock.id}-breakpoints > .builder-column {
99
+ ${convertStyleMapToCSS(columnStyleObjects().column.medium)}
100
+ }
101
+ }
102
+
103
+ @media (max-width: ${getWidthForBreakpointSize("small")}px) {
104
+ .${props.builderBlock.id}-breakpoints {
105
+ ${convertStyleMapToCSS(columnStyleObjects().columns.small)}
106
+ }
107
+
108
+ .${props.builderBlock.id}-breakpoints > .builder-column {
109
+ ${convertStyleMapToCSS(columnStyleObjects().column.small)}
110
+ }
111
+ },
112
+ `;
113
+ }
114
+ function reactNativeColumnsStyles() {
115
+ return columnStyleObjects.columns.small;
116
+ }
117
+ function reactNativeColumnStyles() {
118
+ return columnStyleObjects.column.small;
119
+ }
59
120
  return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
60
- className: "builder-columns div-48253552",
61
- style: columnsCssVars()
62
- }, (_a = props.columns) == null ? void 0 : _a.map((column, index) => /* @__PURE__ */ React.createElement("div", {
63
- className: "builder-column div-48253552-2",
64
- style: __spreadValues({
121
+ className: `builder-columns ${props.builderBlock.id}-breakpoints div-bda7d4e0`,
122
+ style: __spreadValues(__spreadValues({}, TARGET === "reactNative" ? reactNativeColumnsStyles() : {}), columnsCssVars())
123
+ }, TARGET !== "reactNative" ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(RenderInlinedStyles, {
124
+ styles: columnsStyles()
125
+ })) : null, (_a = props.columns) == null ? void 0 : _a.map((column, index) => /* @__PURE__ */ React.createElement("div", {
126
+ className: "builder-column div-bda7d4e0-2",
127
+ style: __spreadValues(__spreadValues({
65
128
  width: getColumnCssWidth(index),
66
129
  marginLeft: `${index === 0 ? 0 : getGutterSize()}px`
67
- }, columnCssVars()),
130
+ }, TARGET === "reactNative" ? reactNativeColumnStyles() : {}), columnCssVars()),
68
131
  key: index
69
132
  }, /* @__PURE__ */ React.createElement(RenderBlocks, {
70
133
  blocks: column.blocks,
@@ -73,19 +136,12 @@ function Columns(props) {
73
136
  styleProp: {
74
137
  flexGrow: "1"
75
138
  }
76
- })))), /* @__PURE__ */ React.createElement("style", null, `.div-48253552 {
139
+ })))), /* @__PURE__ */ React.createElement("style", null, `.div-bda7d4e0 {
77
140
  display: flex;
78
- align-items: stretch;
79
- line-height: normal; }@media (max-width: 991px) { .div-48253552 {
80
- flex-direction: var(--flex-dir-tablet); } }@media (max-width: 639px) { .div-48253552 {
81
- flex-direction: var(--flex-dir); } }.div-48253552-2 {
141
+ line-height: normal; }.div-bda7d4e0-2 {
82
142
  display: flex;
83
143
  flex-direction: column;
84
- align-items: stretch; }@media (max-width: 991px) { .div-48253552-2 {
85
- width: var(--column-width-tablet) !important;
86
- margin-left: var(--column-margin-left-tablet) !important; } }@media (max-width: 639px) { .div-48253552-2 {
87
- width: var(--column-width) !important;
88
- margin-left: var(--column-margin-left) !important; } }`));
144
+ align-items: stretch; }`));
89
145
  }
90
146
  export {
91
147
  Columns as default
@@ -1,3 +1,19 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
1
17
  import * as React from "react";
2
18
  import { getSrcSet } from "./image.helpers.js";
3
19
  function Image(props) {
@@ -27,6 +43,17 @@ function Image(props) {
27
43
  return "";
28
44
  }
29
45
  }
46
+ function aspectRatioCss() {
47
+ const aspectRatioStyles = {
48
+ position: "absolute",
49
+ height: "100%",
50
+ width: "100%",
51
+ left: "0px",
52
+ top: "0px"
53
+ };
54
+ const out = props.aspectRatio ? aspectRatioStyles : void 0;
55
+ return out;
56
+ }
30
57
  return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("picture", null, webpSrcSet() ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("source", {
31
58
  type: "image/webp",
32
59
  srcSet: webpSrcSet()
@@ -34,34 +61,29 @@ function Image(props) {
34
61
  loading: "lazy",
35
62
  alt: props.altText,
36
63
  role: props.altText ? "presentation" : void 0,
37
- style: {
38
- objectPosition: props.backgroundSize || "center",
64
+ style: __spreadValues({
65
+ objectPosition: props.backgroundPosition || "center",
39
66
  objectFit: props.backgroundSize || "cover"
40
- },
41
- className: "builder-image" + (props.className ? " " + props.className : "") + " img-6cfc0cdc",
67
+ }, aspectRatioCss()),
68
+ className: "builder-image" + (props.className ? " " + props.className : "") + " img-35d6dc22",
42
69
  src: props.image,
43
70
  srcSet: srcSetToUse(),
44
71
  sizes: props.sizes
45
72
  }), /* @__PURE__ */ React.createElement("source", {
46
73
  srcSet: srcSetToUse()
47
74
  })), props.aspectRatio && !(((_b = (_a = props.builderBlock) == null ? void 0 : _a.children) == null ? void 0 : _b.length) && props.fitContent) ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
48
- className: "builder-image-sizer div-6cfc0cdc",
75
+ className: "builder-image-sizer div-35d6dc22",
49
76
  style: {
50
77
  paddingTop: props.aspectRatio * 100 + "%"
51
78
  }
52
79
  })) : null, ((_d = (_c = props.builderBlock) == null ? void 0 : _c.children) == null ? void 0 : _d.length) && props.fitContent ? /* @__PURE__ */ React.createElement(React.Fragment, null, props.children) : null, !props.fitContent && props.children ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
53
- className: "div-6cfc0cdc-2"
54
- }, props.children)) : null), /* @__PURE__ */ React.createElement("style", null, `.img-6cfc0cdc {
80
+ className: "div-35d6dc22-2"
81
+ }, props.children)) : null), /* @__PURE__ */ React.createElement("style", null, `.img-35d6dc22 {
55
82
  opacity: 1;
56
- transition: opacity 0.2s ease-in-out;
57
- position: absolute;
58
- height: 100%;
59
- width: 100%;
60
- top: 0px;
61
- left: 0px; }.div-6cfc0cdc {
83
+ transition: opacity 0.2s ease-in-out; }.div-35d6dc22 {
62
84
  width: 100%;
63
85
  pointer-events: none;
64
- font-size: 0; }.div-6cfc0cdc-2 {
86
+ font-size: 0; }.div-35d6dc22-2 {
65
87
  display: flex;
66
88
  flex-direction: column;
67
89
  align-items: stretch;
@@ -20,9 +20,18 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
20
  import * as React from "react";
21
21
  function SectionComponent(props) {
22
22
  return /* @__PURE__ */ React.createElement("section", __spreadProps(__spreadValues({}, props.attributes), {
23
- style: props.maxWidth && typeof props.maxWidth === "number" ? {
24
- maxWidth: props.maxWidth
25
- } : void 0
23
+ style: {
24
+ width: "100%",
25
+ alignSelf: "stretch",
26
+ flexGrow: "1",
27
+ boxSizing: "border-box",
28
+ maxWidth: `${props.maxWidth && typeof props.maxWidth === "number" ? props.maxWidth : 1200}px`,
29
+ display: "flex",
30
+ flexDirection: "column",
31
+ alignItems: "stretch",
32
+ marginLeft: "auto",
33
+ marginRight: "auto"
34
+ }
26
35
  }), props.children);
27
36
  }
28
37
  export {
@@ -22,9 +22,18 @@ import { useState, useContext, useEffect } from "react";
22
22
  import RenderContent from "../../components/render-content/render-content.jsx";
23
23
  import BuilderContext from "../../context/builder.context.js";
24
24
  import { getContent } from "../../functions/get-content/index.js";
25
+ import { TARGET } from "../../constants/target";
25
26
  function Symbol(props) {
26
27
  var _a, _b, _c, _d, _e;
27
- const [className, setClassName] = useState(() => "builder-symbol");
28
+ function className() {
29
+ var _a2, _b2;
30
+ return [
31
+ ...TARGET === "vue2" || TARGET === "vue3" ? Object.keys(props.attributes.class) : [props.attributes.class],
32
+ "builder-symbol",
33
+ ((_a2 = props.symbol) == null ? void 0 : _a2.inline) ? "builder-inline-symbol" : void 0,
34
+ ((_b2 = props.symbol) == null ? void 0 : _b2.dynamic) || props.dynamic ? "builder-dynamic-symbol" : void 0
35
+ ].filter(Boolean).join(" ");
36
+ }
28
37
  const [fetchedContent, setFetchedContent] = useState(() => null);
29
38
  function contentToUse() {
30
39
  var _a2;
@@ -47,9 +56,9 @@ function Symbol(props) {
47
56
  }, [props.symbol, fetchedContent]);
48
57
  return /* @__PURE__ */ React.createElement("div", __spreadProps(__spreadValues({}, props.attributes), {
49
58
  dataSet: {
50
- class: className
59
+ class: className()
51
60
  },
52
- className
61
+ className: className()
53
62
  }), /* @__PURE__ */ React.createElement(RenderContent, {
54
63
  apiKey: builderContext.apiKey,
55
64
  context: builderContext.context,
@@ -79,15 +79,20 @@ function RenderBlock(props) {
79
79
  shouldEvaluateBindings: true
80
80
  });
81
81
  }
82
- function attributes() {
83
- return __spreadValues(__spreadValues(__spreadValues({}, getBlockProperties(useBlock())), getBlockActions({
82
+ function actions() {
83
+ return getBlockActions({
84
84
  block: useBlock(),
85
85
  state: props.context.state,
86
86
  context: props.context.context
87
- })), TARGET === "reactNative" ? {
87
+ });
88
+ }
89
+ function attributes() {
90
+ const blockProperties = getBlockProperties(useBlock());
91
+ return __spreadValues(__spreadValues({}, blockProperties), TARGET === "reactNative" ? {
88
92
  style: getReactNativeBlockStyles({
89
93
  block: useBlock(),
90
- context: props.context
94
+ context: props.context,
95
+ blockStyles: blockProperties.style
91
96
  })
92
97
  } : {});
93
98
  }
@@ -96,12 +101,14 @@ function RenderBlock(props) {
96
101
  return !((_a2 = component == null ? void 0 : component()) == null ? void 0 : _a2.noWrap);
97
102
  }
98
103
  function renderComponentProps() {
99
- var _a2;
104
+ var _a2, _b2, _c2, _d;
100
105
  return {
101
106
  blockChildren: useChildren(),
102
107
  componentRef: (_a2 = component == null ? void 0 : component()) == null ? void 0 : _a2.component,
103
- componentOptions: __spreadValues(__spreadValues({}, getBlockComponentOptions(useBlock())), shouldWrap() ? {} : {
104
- attributes: attributes()
108
+ componentOptions: __spreadProps(__spreadValues(__spreadValues({}, getBlockComponentOptions(useBlock())), shouldWrap() ? {} : {
109
+ attributes: __spreadValues(__spreadValues({}, attributes()), actions())
110
+ }), {
111
+ customBreakpoints: (_d = (_c2 = (_b2 = childrenContext == null ? void 0 : childrenContext()) == null ? void 0 : _b2.content) == null ? void 0 : _c2.meta) == null ? void 0 : _d.breakpoints
105
112
  }),
106
113
  context: childrenContext()
107
114
  };
@@ -149,7 +156,8 @@ function RenderBlock(props) {
149
156
  }
150
157
  const styles = getReactNativeBlockStyles({
151
158
  block: useBlock(),
152
- context: props.context
159
+ context: props.context,
160
+ blockStyles: attributes().style
153
161
  });
154
162
  return extractTextStyles(styles);
155
163
  }
@@ -175,11 +183,11 @@ function RenderBlock(props) {
175
183
  const [componentInfo, setComponentInfo] = useState(() => null);
176
184
  const RenderComponentTagRef = renderComponentTag();
177
185
  const TagRef = tag();
178
- return /* @__PURE__ */ React.createElement(React.Fragment, null, shouldWrap() ? /* @__PURE__ */ React.createElement(React.Fragment, null, isEmptyHtmlElement(tag()) ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(TagRef, __spreadValues({}, attributes()))) : null, !isEmptyHtmlElement(tag()) && repeatItemData() ? /* @__PURE__ */ React.createElement(React.Fragment, null, (_a = repeatItemData()) == null ? void 0 : _a.map((data, index) => /* @__PURE__ */ React.createElement(RenderRepeatedBlock, {
186
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, shouldWrap() ? /* @__PURE__ */ React.createElement(React.Fragment, null, isEmptyHtmlElement(tag()) ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(TagRef, __spreadValues(__spreadValues({}, attributes()), actions()))) : null, !isEmptyHtmlElement(tag()) && repeatItemData() ? /* @__PURE__ */ React.createElement(React.Fragment, null, (_a = repeatItemData()) == null ? void 0 : _a.map((data, index) => /* @__PURE__ */ React.createElement(RenderRepeatedBlock, {
179
187
  key: index,
180
188
  repeatContext: data.context,
181
189
  block: data.block
182
- }))) : null, !isEmptyHtmlElement(tag()) && !repeatItemData() ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(TagRef, __spreadValues({}, attributes()), /* @__PURE__ */ React.createElement(RenderComponentTagRef, __spreadValues({}, renderComponentProps())), (_b = childrenWithoutParentComponent()) == null ? void 0 : _b.map((child) => /* @__PURE__ */ React.createElement(RenderBlock, {
190
+ }))) : null, !isEmptyHtmlElement(tag()) && !repeatItemData() ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(TagRef, __spreadValues(__spreadValues({}, attributes()), actions()), /* @__PURE__ */ React.createElement(RenderComponentTagRef, __spreadValues({}, renderComponentProps())), (_b = childrenWithoutParentComponent()) == null ? void 0 : _b.map((child) => /* @__PURE__ */ React.createElement(RenderBlock, {
183
191
  key: "render-block-" + child.id,
184
192
  block: child,
185
193
  context: childrenContext()
@@ -21,7 +21,6 @@ import * as React from "react";
21
21
  import { useState, useRef, useEffect } from "react";
22
22
  import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
23
23
  import { TARGET } from "../../constants/target.js";
24
- import BuilderContext from "../../context/builder.context.js";
25
24
  import { evaluate } from "../../functions/evaluate.js";
26
25
  import { getContent } from "../../functions/get-content/index.js";
27
26
  import { getFetch } from "../../functions/get-fetch.js";
@@ -35,6 +34,7 @@ import {
35
34
  import { _track } from "../../functions/track.js";
36
35
  import RenderBlocks from "../render-blocks.jsx";
37
36
  import RenderContentStyles from "./components/render-styles.jsx";
37
+ import BuilderContext from "../../context/builder.context.js";
38
38
  import {
39
39
  registerInsertMenu,
40
40
  setupBrowserForEditing
@@ -43,25 +43,31 @@ function RenderContent(props) {
43
43
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
44
44
  const elementRef = useRef(null);
45
45
  const [forceReRenderCount, setForceReRenderCount] = useState(() => 0);
46
+ const [overrideContent, setOverrideContent] = useState(() => null);
46
47
  function useContent() {
47
- var _a2;
48
+ var _a2, _b2, _c2, _d2, _e2;
48
49
  if (!props.content && !overrideContent) {
49
50
  return void 0;
50
51
  }
51
52
  const mergedContent = __spreadProps(__spreadValues(__spreadValues({}, props.content), overrideContent), {
52
- data: __spreadValues(__spreadValues(__spreadValues({}, (_a2 = props.content) == null ? void 0 : _a2.data), props.data), overrideContent == null ? void 0 : overrideContent.data)
53
+ data: __spreadValues(__spreadValues(__spreadValues({}, (_a2 = props.content) == null ? void 0 : _a2.data), props.data), overrideContent == null ? void 0 : overrideContent.data),
54
+ meta: __spreadProps(__spreadValues(__spreadValues({}, (_b2 = props.content) == null ? void 0 : _b2.meta), overrideContent == null ? void 0 : overrideContent.meta), {
55
+ breakpoints: useBreakpoints || ((_c2 = overrideContent == null ? void 0 : overrideContent.meta) == null ? void 0 : _c2.breakpoints) || ((_e2 = (_d2 = props.content) == null ? void 0 : _d2.meta) == null ? void 0 : _e2.breakpoints)
56
+ })
53
57
  });
54
58
  return mergedContent;
55
59
  }
56
- const [overrideContent, setOverrideContent] = useState(() => null);
57
60
  const [update, setUpdate] = useState(() => 0);
61
+ const [useBreakpoints, setUseBreakpoints] = useState(() => null);
58
62
  function canTrackToUse() {
59
63
  return props.canTrack || true;
60
64
  }
61
65
  const [overrideState, setOverrideState] = useState(() => ({}));
62
66
  function contentState() {
63
67
  var _a2, _b2;
64
- return __spreadValues(__spreadValues(__spreadValues({}, (_b2 = (_a2 = props.content) == null ? void 0 : _a2.data) == null ? void 0 : _b2.state), props.data), overrideState);
68
+ return __spreadValues(__spreadValues(__spreadValues(__spreadValues({}, (_b2 = (_a2 = props.content) == null ? void 0 : _a2.data) == null ? void 0 : _b2.state), props.data), props.locale ? {
69
+ locale: props.locale
70
+ } : {}), overrideState);
65
71
  }
66
72
  function contextContext() {
67
73
  return props.context || {};
@@ -78,9 +84,20 @@ function RenderContent(props) {
78
84
  return allComponents;
79
85
  }
80
86
  function processMessage(event) {
87
+ var _a2;
81
88
  const { data } = event;
82
89
  if (data) {
83
90
  switch (data.type) {
91
+ case "builder.configureSdk": {
92
+ const messageContent = data.data;
93
+ const { breakpoints, contentId } = messageContent;
94
+ if (!contentId || contentId !== ((_a2 = useContent == null ? void 0 : useContent()) == null ? void 0 : _a2.id)) {
95
+ return;
96
+ }
97
+ setUseBreakpoints(breakpoints);
98
+ setForceReRenderCount(forceReRenderCount + 1);
99
+ break;
100
+ }
84
101
  case "builder.contentUpdate": {
85
102
  const messageContent = data.data;
86
103
  const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
@@ -173,11 +190,18 @@ function RenderContent(props) {
173
190
  }
174
191
  useEffect(() => {
175
192
  var _a2, _b2;
193
+ if (!props.apiKey) {
194
+ console.error("[Builder.io]: No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
195
+ }
176
196
  if (isBrowser()) {
177
197
  if (isEditing()) {
178
198
  setForceReRenderCount(forceReRenderCount + 1);
179
199
  registerInsertMenu();
180
- setupBrowserForEditing();
200
+ setupBrowserForEditing(__spreadValues(__spreadValues({}, props.locale ? {
201
+ locale: props.locale
202
+ } : {}), props.includeRefs ? {
203
+ includeRefs: props.includeRefs
204
+ } : {}));
181
205
  Object.values(allRegisteredComponents()).forEach((registeredComponent) => {
182
206
  var _a3;
183
207
  const message = createRegisterComponentMessage(registeredComponent);
@@ -220,7 +244,7 @@ function RenderContent(props) {
220
244
  }, []);
221
245
  useEffect(() => {
222
246
  evaluateJsCode();
223
- }, [(_b = (_a = useContent == null ? void 0 : useContent()) == null ? void 0 : _a.data) == null ? void 0 : _b.jsCode]);
247
+ }, [(_b = (_a = useContent == null ? void 0 : useContent()) == null ? void 0 : _a.data) == null ? void 0 : _b.jsCode, contentState()]);
224
248
  useEffect(() => {
225
249
  runHttpRequests();
226
250
  }, [(_d = (_c = useContent == null ? void 0 : useContent()) == null ? void 0 : _c.data) == null ? void 0 : _d.httpRequests]);
@@ -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
  }
@@ -17,12 +17,33 @@ var __spreadValues = (a, b) => {
17
17
  return a;
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ import { TARGET } from "../constants/target.js";
21
+ import { convertStyleMapToCSSArray } from "../helpers/css.js";
22
+ import { transformBlockProperties } from "./transform-block-properties.js";
20
23
  function getBlockProperties(block) {
21
24
  var _a;
22
- return __spreadProps(__spreadValues({}, block.properties), {
25
+ const properties = __spreadProps(__spreadValues({}, block.properties), {
23
26
  "builder-id": block.id,
27
+ style: getStyleAttribute(block.style),
24
28
  class: [block.id, "builder-block", block.class, (_a = block.properties) == null ? void 0 : _a.class].filter(Boolean).join(" ")
25
29
  });
30
+ return transformBlockProperties(properties);
31
+ }
32
+ function getStyleAttribute(style) {
33
+ if (!style) {
34
+ return void 0;
35
+ }
36
+ switch (TARGET) {
37
+ case "svelte":
38
+ case "vue2":
39
+ case "vue3":
40
+ case "solid":
41
+ return convertStyleMapToCSSArray(style).join(" ");
42
+ case "qwik":
43
+ case "reactNative":
44
+ case "react":
45
+ return style;
46
+ }
26
47
  }
27
48
  export {
28
49
  getBlockProperties
@@ -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
  }
@@ -17,13 +17,14 @@ var __spreadValues = (a, b) => {
17
17
  import { sanitizeReactNativeBlockStyles } from "./sanitize-react-native-block-styles.js";
18
18
  function getReactNativeBlockStyles({
19
19
  block,
20
- context
20
+ context,
21
+ blockStyles
21
22
  }) {
22
23
  const responsiveStyles = block.responsiveStyles;
23
24
  if (!responsiveStyles) {
24
25
  return {};
25
26
  }
26
- const styles = __spreadValues(__spreadValues(__spreadValues(__spreadValues({}, context.inheritedStyles), responsiveStyles.large || {}), responsiveStyles.medium || {}), responsiveStyles.small || {});
27
+ const styles = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, context.inheritedStyles), responsiveStyles.large || {}), responsiveStyles.medium || {}), responsiveStyles.small || {}), blockStyles);
27
28
  const newStyles = sanitizeReactNativeBlockStyles(styles);
28
29
  return newStyles;
29
30
  }
@@ -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
  }
@@ -0,0 +1,6 @@
1
+ function transformBlockProperties(properties) {
2
+ return properties;
3
+ }
4
+ export {
5
+ transformBlockProperties
6
+ };
@@ -1,19 +1,23 @@
1
1
  import { camelToKebabCase } from "../functions/camel-to-kebab-case.js";
2
- const convertStyleMaptoCSS = (style) => {
2
+ import { checkIsDefined } from "./nullable.js";
3
+ const convertStyleMapToCSSArray = (style) => {
3
4
  const cssProps = Object.entries(style).map(([key, value]) => {
4
5
  if (typeof value === "string") {
5
6
  return `${camelToKebabCase(key)}: ${value};`;
7
+ } else {
8
+ return void 0;
6
9
  }
7
10
  });
8
- return cssProps.join("\n");
11
+ return cssProps.filter(checkIsDefined);
9
12
  };
13
+ const convertStyleMapToCSS = (style) => convertStyleMapToCSSArray(style).join("\n");
10
14
  const createCssClass = ({
11
15
  mediaQuery,
12
16
  className,
13
17
  styles
14
18
  }) => {
15
19
  const cssClass = `.${className} {
16
- ${convertStyleMaptoCSS(styles)}
20
+ ${convertStyleMapToCSS(styles)}
17
21
  }`;
18
22
  if (mediaQuery) {
19
23
  return `${mediaQuery} {
@@ -24,5 +28,7 @@ const createCssClass = ({
24
28
  }
25
29
  };
26
30
  export {
31
+ convertStyleMapToCSS,
32
+ convertStyleMapToCSSArray,
27
33
  createCssClass
28
34
  };