@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
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-react",
3
3
  "description": "Builder.io SDK for React",
4
- "version": "0.0.3",
4
+ "version": "0.0.5",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
7
7
  "exports": {
@@ -15,6 +15,7 @@
15
15
  }
16
16
  },
17
17
  "scripts": {
18
+ "build": "echo 'no need to build react SDK'",
18
19
  "release:patch": "npm version patch --no-git-tag-version && npm publish --access public",
19
20
  "release:dev": "npm version prerelease --no-git-tag-version && npm publish --tag dev --access public"
20
21
  },
@@ -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.js";
19
+ import { getSizesForBreakpoints } from "../../constants/device-sizes";
20
+ import RenderInlinedStyles from "../../components/render-inlined-styles.js";
21
+ import { TARGET } from "../../constants/target.js";
22
+ import { convertStyleMapToCSS } from "../../helpers/css";
19
23
  function Columns(props) {
20
24
  var _a;
21
25
  const _context = __spreadValues({}, props["_context"]);
@@ -57,17 +61,77 @@ function Columns(props) {
57
61
  "--column-width-tablet": state.maybeApplyForTablet(width),
58
62
  "--column-margin-left-tablet": state.maybeApplyForTablet(marginLeft)
59
63
  };
64
+ },
65
+ getWidthForBreakpointSize(size) {
66
+ const breakpointSizes = getSizesForBreakpoints(props.customBreakpoints || {});
67
+ return breakpointSizes[size].max;
68
+ },
69
+ get columnStyleObjects() {
70
+ return {
71
+ columns: {
72
+ small: {
73
+ flexDirection: "var(--flex-dir)",
74
+ alignItems: "stretch"
75
+ },
76
+ medium: {
77
+ flexDirection: "var(--flex-dir-tablet)",
78
+ alignItems: "stretch"
79
+ }
80
+ },
81
+ column: {
82
+ small: {
83
+ width: "var(--column-width) !important",
84
+ marginLeft: "var(--column-margin-left) !important"
85
+ },
86
+ medium: {
87
+ width: "var(--column-width-tablet) !important",
88
+ marginLeft: "var(--column-margin-left-tablet) !important"
89
+ }
90
+ }
91
+ };
92
+ },
93
+ get columnsStyles() {
94
+ return `
95
+ @media (max-width: ${state.getWidthForBreakpointSize("medium")}px) {
96
+ .${props.builderBlock.id}-breakpoints {
97
+ ${convertStyleMapToCSS(state.columnStyleObjects.columns.medium)}
98
+ }
99
+
100
+ .${props.builderBlock.id}-breakpoints > .builder-column {
101
+ ${convertStyleMapToCSS(state.columnStyleObjects.column.medium)}
102
+ }
103
+ }
104
+
105
+ @media (max-width: ${state.getWidthForBreakpointSize("small")}px) {
106
+ .${props.builderBlock.id}-breakpoints {
107
+ ${convertStyleMapToCSS(state.columnStyleObjects.columns.small)}
108
+ }
109
+
110
+ .${props.builderBlock.id}-breakpoints > .builder-column {
111
+ ${convertStyleMapToCSS(state.columnStyleObjects.column.small)}
112
+ }
113
+ },
114
+ `;
115
+ },
116
+ get reactNativeColumnsStyles() {
117
+ return this.columnStyleObjects.columns.small;
118
+ },
119
+ get reactNativeColumnStyles() {
120
+ return this.columnStyleObjects.column.small;
60
121
  }
61
122
  };
62
123
  return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
63
- className: "builder-columns div-6bcd11d2",
64
- style: state.columnsCssVars
65
- }, (_a = props.columns) == null ? void 0 : _a.map((column, index) => /* @__PURE__ */ React.createElement("div", {
66
- className: "builder-column div-6bcd11d2-2",
67
- style: __spreadValues({
124
+ className: `builder-columns ${props.builderBlock.id}-breakpoints div-540739f0`,
125
+ style: __spreadValues(__spreadValues({}, TARGET === "reactNative" ? state.reactNativeColumnsStyles : {}), state.columnsCssVars)
126
+ }, TARGET !== "reactNative" ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(RenderInlinedStyles, {
127
+ styles: state.columnsStyles,
128
+ _context
129
+ })) : null, (_a = props.columns) == null ? void 0 : _a.map((column, index) => /* @__PURE__ */ React.createElement("div", {
130
+ className: "builder-column div-540739f0-2",
131
+ style: __spreadValues(__spreadValues({
68
132
  width: state.getColumnCssWidth(index),
69
133
  marginLeft: `${index === 0 ? 0 : state.getGutterSize()}px`
70
- }, state.columnCssVars),
134
+ }, TARGET === "reactNative" ? state.reactNativeColumnStyles : {}), state.columnCssVars),
71
135
  key: index
72
136
  }, /* @__PURE__ */ React.createElement(RenderBlocks, {
73
137
  blocks: column.blocks,
@@ -77,19 +141,12 @@ function Columns(props) {
77
141
  flexGrow: "1"
78
142
  },
79
143
  _context
80
- })))), /* @__PURE__ */ React.createElement("style", null, `.div-6bcd11d2 {
144
+ })))), /* @__PURE__ */ React.createElement("style", null, `.div-540739f0 {
81
145
  display: flex;
82
- align-items: stretch;
83
- line-height: normal; }@media (max-width: 991px) { .div-6bcd11d2 {
84
- flex-direction: var(--flex-dir-tablet); } }@media (max-width: 639px) { .div-6bcd11d2 {
85
- flex-direction: var(--flex-dir); } }.div-6bcd11d2-2 {
146
+ line-height: normal; }.div-540739f0-2 {
86
147
  display: flex;
87
148
  flex-direction: column;
88
- align-items: stretch; }@media (max-width: 991px) { .div-6bcd11d2-2 {
89
- width: var(--column-width-tablet) !important;
90
- margin-left: var(--column-margin-left-tablet) !important; } }@media (max-width: 639px) { .div-6bcd11d2-2 {
91
- width: var(--column-width) !important;
92
- margin-left: var(--column-margin-left) !important; } }`));
149
+ align-items: stretch; }`));
93
150
  }
94
151
  export {
95
152
  Columns as default
@@ -44,6 +44,17 @@ function Image(props) {
44
44
  } else {
45
45
  return "";
46
46
  }
47
+ },
48
+ get aspectRatioCss() {
49
+ const aspectRatioStyles = {
50
+ position: "absolute",
51
+ height: "100%",
52
+ width: "100%",
53
+ left: "0px",
54
+ top: "0px"
55
+ };
56
+ const out = props.aspectRatio ? aspectRatioStyles : void 0;
57
+ return out;
47
58
  }
48
59
  };
49
60
  return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("picture", null, state.webpSrcSet ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("source", {
@@ -53,34 +64,29 @@ function Image(props) {
53
64
  loading: "lazy",
54
65
  alt: props.altText,
55
66
  role: props.altText ? "presentation" : void 0,
56
- style: {
57
- objectPosition: props.backgroundSize || "center",
67
+ style: __spreadValues({
68
+ objectPosition: props.backgroundPosition || "center",
58
69
  objectFit: props.backgroundSize || "cover"
59
- },
60
- className: "builder-image" + (props.className ? " " + props.className : "") + " img-af05e244",
70
+ }, state.aspectRatioCss),
71
+ className: "builder-image" + (props.className ? " " + props.className : "") + " img-03c4fd62",
61
72
  src: props.image,
62
73
  srcSet: state.srcSetToUse,
63
74
  sizes: props.sizes
64
75
  }), /* @__PURE__ */ React.createElement("source", {
65
76
  srcSet: state.srcSetToUse
66
77
  })), 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", {
67
- className: "builder-image-sizer div-af05e244",
78
+ className: "builder-image-sizer div-03c4fd62",
68
79
  style: {
69
80
  paddingTop: props.aspectRatio * 100 + "%"
70
81
  }
71
82
  })) : 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", {
72
- className: "div-af05e244-2"
73
- }, props.children)) : null), /* @__PURE__ */ React.createElement("style", null, `.img-af05e244 {
83
+ className: "div-03c4fd62-2"
84
+ }, props.children)) : null), /* @__PURE__ */ React.createElement("style", null, `.img-03c4fd62 {
74
85
  opacity: 1;
75
- transition: opacity 0.2s ease-in-out;
76
- position: absolute;
77
- height: 100%;
78
- width: 100%;
79
- top: 0px;
80
- left: 0px; }.div-af05e244 {
86
+ transition: opacity 0.2s ease-in-out; }.div-03c4fd62 {
81
87
  width: 100%;
82
88
  pointer-events: none;
83
- font-size: 0; }.div-af05e244-2 {
89
+ font-size: 0; }.div-03c4fd62-2 {
84
90
  display: flex;
85
91
  flex-direction: column;
86
92
  align-items: stretch;
@@ -21,9 +21,18 @@ import * as React from "react";
21
21
  function SectionComponent(props) {
22
22
  const _context = __spreadValues({}, props["_context"]);
23
23
  return /* @__PURE__ */ React.createElement("section", __spreadProps(__spreadValues({}, props.attributes), {
24
- style: props.maxWidth && typeof props.maxWidth === "number" ? {
25
- maxWidth: props.maxWidth
26
- } : void 0
24
+ style: {
25
+ width: "100%",
26
+ alignSelf: "stretch",
27
+ flexGrow: "1",
28
+ boxSizing: "border-box",
29
+ maxWidth: `${props.maxWidth && typeof props.maxWidth === "number" ? props.maxWidth : 1200}px`,
30
+ display: "flex",
31
+ flexDirection: "column",
32
+ alignItems: "stretch",
33
+ marginLeft: "auto",
34
+ marginRight: "auto"
35
+ }
27
36
  }), props.children);
28
37
  }
29
38
  export {
@@ -19,11 +19,20 @@ var __spreadValues = (a, b) => {
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
20
  import * as React from "react";
21
21
  import RenderContent from "../../components/render-content/render-content.js";
22
+ import { TARGET } from "../../constants/target";
22
23
  function Symbol(props) {
23
24
  var _a, _b, _c, _d, _e;
24
25
  const _context = __spreadValues({}, props["_context"]);
25
26
  const state = {
26
- className: "builder-symbol",
27
+ get className() {
28
+ var _a2, _b2;
29
+ return [
30
+ ...TARGET === "vue2" || TARGET === "vue3" ? Object.keys(props.attributes.class) : [props.attributes.class],
31
+ "builder-symbol",
32
+ ((_a2 = props.symbol) == null ? void 0 : _a2.inline) ? "builder-inline-symbol" : void 0,
33
+ ((_b2 = props.symbol) == null ? void 0 : _b2.dynamic) || props.dynamic ? "builder-dynamic-symbol" : void 0
34
+ ].filter(Boolean).join(" ");
35
+ },
27
36
  fetchedContent: null,
28
37
  get contentToUse() {
29
38
  var _a2;
@@ -80,15 +80,20 @@ function RenderBlock(props) {
80
80
  shouldEvaluateBindings: true
81
81
  });
82
82
  },
83
- get attributes() {
84
- return __spreadValues(__spreadValues(__spreadValues({}, getBlockProperties(state.useBlock)), getBlockActions({
83
+ get actions() {
84
+ return getBlockActions({
85
85
  block: state.useBlock,
86
86
  state: props.context.state,
87
87
  context: props.context.context
88
- })), TARGET === "reactNative" ? {
88
+ });
89
+ },
90
+ get attributes() {
91
+ const blockProperties = getBlockProperties(state.useBlock);
92
+ return __spreadValues(__spreadValues({}, blockProperties), TARGET === "reactNative" ? {
89
93
  style: getReactNativeBlockStyles({
90
94
  block: state.useBlock,
91
- context: props.context
95
+ context: props.context,
96
+ blockStyles: blockProperties.style
92
97
  })
93
98
  } : {});
94
99
  },
@@ -97,12 +102,14 @@ function RenderBlock(props) {
97
102
  return !((_a2 = state.component) == null ? void 0 : _a2.noWrap);
98
103
  },
99
104
  get renderComponentProps() {
100
- var _a2;
105
+ var _a2, _b2, _c2, _d;
101
106
  return {
102
107
  blockChildren: state.useChildren,
103
108
  componentRef: (_a2 = state.component) == null ? void 0 : _a2.component,
104
- componentOptions: __spreadValues(__spreadValues({}, getBlockComponentOptions(state.useBlock)), state.shouldWrap ? {} : {
105
- attributes: state.attributes
109
+ componentOptions: __spreadProps(__spreadValues(__spreadValues({}, getBlockComponentOptions(state.useBlock)), state.shouldWrap ? {} : {
110
+ attributes: __spreadValues(__spreadValues({}, state.attributes), state.actions)
111
+ }), {
112
+ customBreakpoints: (_d = (_c2 = (_b2 = state.childrenContext) == null ? void 0 : _b2.content) == null ? void 0 : _c2.meta) == null ? void 0 : _d.breakpoints
106
113
  }),
107
114
  context: state.childrenContext
108
115
  };
@@ -150,7 +157,8 @@ function RenderBlock(props) {
150
157
  }
151
158
  const styles = getReactNativeBlockStyles({
152
159
  block: state.useBlock,
153
- context: props.context
160
+ context: props.context,
161
+ blockStyles: state.attributes.style
154
162
  });
155
163
  return extractTextStyles(styles);
156
164
  },
@@ -177,12 +185,12 @@ function RenderBlock(props) {
177
185
  };
178
186
  const RenderComponentTagRef = state.renderComponentTag;
179
187
  const TagRef = state.tag;
180
- return /* @__PURE__ */ React.createElement(React.Fragment, null, state.shouldWrap ? /* @__PURE__ */ React.createElement(React.Fragment, null, isEmptyHtmlElement(state.tag) ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(TagRef, __spreadValues({}, state.attributes))) : null, !isEmptyHtmlElement(state.tag) && state.repeatItemData ? /* @__PURE__ */ React.createElement(React.Fragment, null, (_a = state.repeatItemData) == null ? void 0 : _a.map((data, index) => /* @__PURE__ */ React.createElement(RenderRepeatedBlock, {
188
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, state.shouldWrap ? /* @__PURE__ */ React.createElement(React.Fragment, null, isEmptyHtmlElement(state.tag) ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(TagRef, __spreadValues(__spreadValues({}, state.attributes), state.actions))) : null, !isEmptyHtmlElement(state.tag) && state.repeatItemData ? /* @__PURE__ */ React.createElement(React.Fragment, null, (_a = state.repeatItemData) == null ? void 0 : _a.map((data, index) => /* @__PURE__ */ React.createElement(RenderRepeatedBlock, {
181
189
  key: index,
182
190
  repeatContext: data.context,
183
191
  block: data.block,
184
192
  _context
185
- }))) : null, !isEmptyHtmlElement(state.tag) && !state.repeatItemData ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(TagRef, __spreadValues({}, state.attributes), /* @__PURE__ */ React.createElement(RenderComponentTagRef, __spreadProps(__spreadValues({}, state.renderComponentProps), {
193
+ }))) : null, !isEmptyHtmlElement(state.tag) && !state.repeatItemData ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(TagRef, __spreadValues(__spreadValues({}, state.attributes), state.actions), /* @__PURE__ */ React.createElement(RenderComponentTagRef, __spreadProps(__spreadValues({}, state.renderComponentProps), {
186
194
  _context
187
195
  })), (_b = state.childrenWithoutParentComponent) == null ? void 0 : _b.map((child) => /* @__PURE__ */ React.createElement(RenderBlock, {
188
196
  key: "render-block-" + child.id,
@@ -34,25 +34,31 @@ function RenderContent(props) {
34
34
  const _context = __spreadValues({}, props["_context"]);
35
35
  const state = {
36
36
  forceReRenderCount: 0,
37
+ overrideContent: null,
37
38
  get useContent() {
38
- var _a2, _b2;
39
+ var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h;
39
40
  if (!props.content && !state.overrideContent) {
40
41
  return void 0;
41
42
  }
42
43
  const mergedContent = __spreadProps(__spreadValues(__spreadValues({}, props.content), state.overrideContent), {
43
- data: __spreadValues(__spreadValues(__spreadValues({}, (_a2 = props.content) == null ? void 0 : _a2.data), props.data), (_b2 = state.overrideContent) == null ? void 0 : _b2.data)
44
+ data: __spreadValues(__spreadValues(__spreadValues({}, (_a2 = props.content) == null ? void 0 : _a2.data), props.data), (_b2 = state.overrideContent) == null ? void 0 : _b2.data),
45
+ meta: __spreadProps(__spreadValues(__spreadValues({}, (_c2 = props.content) == null ? void 0 : _c2.meta), (_d2 = state.overrideContent) == null ? void 0 : _d2.meta), {
46
+ breakpoints: state.useBreakpoints || ((_f2 = (_e2 = state.overrideContent) == null ? void 0 : _e2.meta) == null ? void 0 : _f2.breakpoints) || ((_h = (_g2 = props.content) == null ? void 0 : _g2.meta) == null ? void 0 : _h.breakpoints)
47
+ })
44
48
  });
45
49
  return mergedContent;
46
50
  },
47
- overrideContent: null,
48
51
  update: 0,
52
+ useBreakpoints: null,
49
53
  get canTrackToUse() {
50
54
  return props.canTrack || true;
51
55
  },
52
56
  overrideState: {},
53
57
  get contentState() {
54
58
  var _a2, _b2;
55
- return __spreadValues(__spreadValues(__spreadValues({}, (_b2 = (_a2 = props.content) == null ? void 0 : _a2.data) == null ? void 0 : _b2.state), props.data), state.overrideState);
59
+ return __spreadValues(__spreadValues(__spreadValues(__spreadValues({}, (_b2 = (_a2 = props.content) == null ? void 0 : _a2.data) == null ? void 0 : _b2.state), props.data), props.locale ? {
60
+ locale: props.locale
61
+ } : {}), state.overrideState);
56
62
  },
57
63
  get contextContext() {
58
64
  return props.context || {};
@@ -69,9 +75,20 @@ function RenderContent(props) {
69
75
  return allComponents;
70
76
  },
71
77
  processMessage(event) {
78
+ var _a2;
72
79
  const { data } = event;
73
80
  if (data) {
74
81
  switch (data.type) {
82
+ case "builder.configureSdk": {
83
+ const messageContent = data.data;
84
+ const { breakpoints, contentId } = messageContent;
85
+ if (!contentId || contentId !== ((_a2 = state.useContent) == null ? void 0 : _a2.id)) {
86
+ return;
87
+ }
88
+ state.useBreakpoints = breakpoints;
89
+ state.forceReRenderCount = state.forceReRenderCount + 1;
90
+ break;
91
+ }
75
92
  case "builder.contentUpdate": {
76
93
  const messageContent = data.data;
77
94
  const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
@@ -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
  };
@@ -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
  }, "*");