@builder.io/sdk-react-native 0.1.4 → 0.1.6

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 (53) hide show
  1. package/dist/blocks/button/component-info.js +0 -1
  2. package/dist/blocks/columns/component-info.js +0 -1
  3. package/dist/blocks/custom-code/component-info.js +0 -1
  4. package/dist/blocks/embed/component-info.js +0 -1
  5. package/dist/blocks/form/component-info.js +0 -1
  6. package/dist/blocks/fragment/component-info.js +0 -1
  7. package/dist/blocks/image/component-info.js +0 -1
  8. package/dist/blocks/img/component-info.js +0 -1
  9. package/dist/blocks/input/component-info.js +0 -1
  10. package/dist/blocks/raw-text/component-info.js +0 -1
  11. package/dist/blocks/section/component-info.js +0 -1
  12. package/dist/blocks/select/component-info.js +0 -1
  13. package/dist/blocks/submit-button/component-info.js +0 -1
  14. package/dist/blocks/symbol/component-info.js +0 -1
  15. package/dist/blocks/text/component-info.js +0 -1
  16. package/dist/blocks/textarea/component-info.js +0 -1
  17. package/dist/blocks/video/component-info.js +0 -1
  18. package/dist/components/render-block/render-block.js +19 -1
  19. package/dist/components/render-block/render-repeated-block.js +1 -0
  20. package/dist/components/render-content/components/render-styles.helpers.js +55 -0
  21. package/dist/components/render-content/components/render-styles.js +13 -57
  22. package/dist/components/render-content/render-content.helpers.js +42 -0
  23. package/dist/components/render-content/render-content.js +70 -71
  24. package/dist/components/render-content/render-content.types.js +1 -0
  25. package/dist/context/builder.context.js +2 -0
  26. package/dist/types/input.js +1 -0
  27. package/package.json +1 -1
  28. package/src/blocks/button/component-info.js +0 -1
  29. package/src/blocks/columns/component-info.js +0 -1
  30. package/src/blocks/custom-code/component-info.js +0 -1
  31. package/src/blocks/embed/component-info.js +0 -1
  32. package/src/blocks/form/component-info.js +0 -1
  33. package/src/blocks/fragment/component-info.js +0 -1
  34. package/src/blocks/image/component-info.js +0 -1
  35. package/src/blocks/img/component-info.js +0 -1
  36. package/src/blocks/input/component-info.js +0 -1
  37. package/src/blocks/raw-text/component-info.js +0 -1
  38. package/src/blocks/section/component-info.js +0 -1
  39. package/src/blocks/select/component-info.js +0 -1
  40. package/src/blocks/submit-button/component-info.js +0 -1
  41. package/src/blocks/symbol/component-info.js +0 -1
  42. package/src/blocks/text/component-info.js +0 -1
  43. package/src/blocks/textarea/component-info.js +0 -1
  44. package/src/blocks/video/component-info.js +0 -1
  45. package/src/components/render-block/render-block.jsx +22 -1
  46. package/src/components/render-block/render-repeated-block.jsx +1 -0
  47. package/src/components/render-content/components/render-styles.helpers.js +57 -0
  48. package/src/components/render-content/components/render-styles.jsx +13 -56
  49. package/src/components/render-content/render-content.helpers.js +48 -0
  50. package/src/components/render-content/render-content.jsx +76 -67
  51. package/src/components/render-content/render-content.types.js +0 -0
  52. package/src/context/builder.context.js +2 -0
  53. package/src/types/input.js +0 -0
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.componentInfo = void 0;
4
4
  const componentInfo = {
5
5
  name: "Core:Button",
6
- builtIn: true,
7
6
  image: "https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2F81a15681c3e74df09677dfc57a615b13",
8
7
  defaultStyles: {
9
8
  appearance: "none",
@@ -4,7 +4,6 @@ exports.componentInfo = void 0;
4
4
  const util_js_1 = require("../util.js");
5
5
  const componentInfo = {
6
6
  name: "Columns",
7
- builtIn: true,
8
7
  inputs: [
9
8
  {
10
9
  name: "columns",
@@ -4,7 +4,6 @@ exports.componentInfo = void 0;
4
4
  const componentInfo = {
5
5
  name: "Custom Code",
6
6
  static: true,
7
- builtIn: true,
8
7
  requiredPermissions: ["editCode"],
9
8
  inputs: [
10
9
  {
@@ -5,7 +5,6 @@ const util_js_1 = require("../util.js");
5
5
  const componentInfo = {
6
6
  name: "Embed",
7
7
  static: true,
8
- builtIn: true,
9
8
  inputs: [
10
9
  {
11
10
  name: "url",
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.componentInfo = void 0;
4
4
  const componentInfo = {
5
5
  name: "Form:Form",
6
- builtIn: true,
7
6
  defaults: {
8
7
  responsiveStyles: {
9
8
  large: {
@@ -5,7 +5,6 @@ const componentInfo = {
5
5
  name: "Fragment",
6
6
  static: true,
7
7
  hidden: true,
8
- builtIn: true,
9
8
  canHaveChildren: true,
10
9
  noWrap: true
11
10
  };
@@ -5,7 +5,6 @@ const util_js_1 = require("../util.js");
5
5
  const componentInfo = {
6
6
  name: "Image",
7
7
  static: true,
8
- builtIn: true,
9
8
  image: "https://firebasestorage.googleapis.com/v0/b/builder-3b0a2.appspot.com/o/images%2Fbaseline-insert_photo-24px.svg?alt=media&token=4e5d0ef4-f5e8-4e57-b3a9-38d63a9b9dc4",
10
9
  defaultStyles: {
11
10
  position: "relative",
@@ -4,7 +4,6 @@ exports.componentInfo = void 0;
4
4
  const componentInfo = {
5
5
  name: "Raw:Img",
6
6
  hideFromInsertMenu: true,
7
- builtIn: true,
8
7
  image: "https://firebasestorage.googleapis.com/v0/b/builder-3b0a2.appspot.com/o/images%2Fbaseline-insert_photo-24px.svg?alt=media&token=4e5d0ef4-f5e8-4e57-b3a9-38d63a9b9dc4",
9
8
  inputs: [
10
9
  {
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.componentInfo = void 0;
4
4
  const componentInfo = {
5
5
  name: "Form:Input",
6
- builtIn: true,
7
6
  image: "https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2Fad6f37889d9e40bbbbc72cdb5875d6ca",
8
7
  inputs: [
9
8
  {
@@ -4,7 +4,6 @@ exports.componentInfo = void 0;
4
4
  const componentInfo = {
5
5
  name: "Builder:RawText",
6
6
  hideFromInsertMenu: true,
7
- builtIn: true,
8
7
  inputs: [
9
8
  {
10
9
  name: "text",
@@ -4,7 +4,6 @@ exports.componentInfo = void 0;
4
4
  const componentInfo = {
5
5
  name: "Core:Section",
6
6
  static: true,
7
- builtIn: true,
8
7
  image: "https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2F682efef23ace49afac61748dd305c70a",
9
8
  inputs: [
10
9
  {
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.componentInfo = void 0;
4
4
  const componentInfo = {
5
5
  name: "Form:Select",
6
- builtIn: true,
7
6
  image: "https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2F83acca093fb24aaf94dee136e9a4b045",
8
7
  defaultStyles: {
9
8
  alignSelf: "flex-start"
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.componentInfo = void 0;
4
4
  const componentInfo = {
5
5
  name: "Form:SubmitButton",
6
- builtIn: true,
7
6
  image: "https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2Fdf2820ffed1f4349a94c40b3221f5b98",
8
7
  defaultStyles: {
9
8
  appearance: "none",
@@ -5,7 +5,6 @@ const componentInfo = {
5
5
  name: "Symbol",
6
6
  noWrap: true,
7
7
  static: true,
8
- builtIn: true,
9
8
  inputs: [
10
9
  {
11
10
  name: "symbol",
@@ -4,7 +4,6 @@ exports.componentInfo = void 0;
4
4
  const componentInfo = {
5
5
  name: "Text",
6
6
  static: true,
7
- builtIn: true,
8
7
  image: "https://firebasestorage.googleapis.com/v0/b/builder-3b0a2.appspot.com/o/images%2Fbaseline-text_fields-24px%20(1).svg?alt=media&token=12177b73-0ee3-42ca-98c6-0dd003de1929",
9
8
  inputs: [
10
9
  {
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.componentInfo = void 0;
4
4
  const componentInfo = {
5
5
  name: "Form:TextArea",
6
- builtIn: true,
7
6
  image: "https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2Ff74a2f3de58c4c3e939204e5b6b8f6c3",
8
7
  inputs: [
9
8
  {
@@ -4,7 +4,6 @@ exports.componentInfo = void 0;
4
4
  const componentInfo = {
5
5
  name: "Video",
6
6
  canHaveChildren: true,
7
- builtIn: true,
8
7
  defaultStyles: {
9
8
  minHeight: "20px",
10
9
  minWidth: "20px"
@@ -60,10 +60,27 @@ function RenderBlock(props) {
60
60
  shouldEvaluateBindings: true,
61
61
  });
62
62
  }
63
+ function proxyState() {
64
+ if (typeof Proxy === "undefined") {
65
+ console.error("no Proxy available in this environment, cannot proxy state.");
66
+ return props.context.state;
67
+ }
68
+ const useState = new Proxy(props.context.state, {
69
+ set: (obj, prop, value) => {
70
+ var _a, _b;
71
+ // set the value on the state object, so that the event handler instantly gets the update.
72
+ obj[prop] = value;
73
+ // set the value in the context, so that the rest of the app gets the update.
74
+ (_b = (_a = props.context).setState) === null || _b === void 0 ? void 0 : _b.call(_a, obj);
75
+ return true;
76
+ },
77
+ });
78
+ return useState;
79
+ }
63
80
  function actions() {
64
81
  return (0, get_block_actions_js_1.getBlockActions)({
65
82
  block: useBlock(),
66
- state: props.context.state,
83
+ state: proxyState(),
67
84
  context: props.context.context,
68
85
  });
69
86
  }
@@ -137,6 +154,7 @@ function RenderBlock(props) {
137
154
  state: props.context.state,
138
155
  content: props.context.content,
139
156
  context: props.context.context,
157
+ setState: props.context.setState,
140
158
  registeredComponents: props.context.registeredComponents,
141
159
  inheritedStyles: getInheritedTextStyles(),
142
160
  };
@@ -35,6 +35,7 @@ function RenderRepeatedBlock(props) {
35
35
  return (React.createElement(builder_context_js_1.default.Provider, { value: {
36
36
  content: props.repeatContext.content,
37
37
  state: props.repeatContext.state,
38
+ setState: props.repeatContext.setState,
38
39
  context: props.repeatContext.context,
39
40
  apiKey: props.repeatContext.apiKey,
40
41
  registeredComponents: props.repeatContext.registeredComponents,
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getFontCss = exports.getCss = void 0;
4
+ const getCssFromFont = (font) => {
5
+ var _a, _b;
6
+ const family = font.family + (font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
7
+ const name = family.split(",")[0];
8
+ const url = (_b = font.fileUrl) != null ? _b : (_a = font == null ? void 0 : font.files) == null ? void 0 : _a.regular;
9
+ let str = "";
10
+ if (url && family && name) {
11
+ str += `
12
+ @font-face {
13
+ font-family: "${family}";
14
+ src: local("${name}"), url('${url}') format('woff2');
15
+ font-display: fallback;
16
+ font-weight: 400;
17
+ }
18
+ `.trim();
19
+ }
20
+ if (font.files) {
21
+ for (const weight in font.files) {
22
+ const isNumber = String(Number(weight)) === weight;
23
+ if (!isNumber) {
24
+ continue;
25
+ }
26
+ const weightUrl = font.files[weight];
27
+ if (weightUrl && weightUrl !== url) {
28
+ str += `
29
+ @font-face {
30
+ font-family: "${family}";
31
+ src: url('${weightUrl}') format('woff2');
32
+ font-display: fallback;
33
+ font-weight: ${weight};
34
+ }
35
+ `.trim();
36
+ }
37
+ }
38
+ }
39
+ return str;
40
+ };
41
+ const getFontCss = ({ customFonts }) => {
42
+ var _a;
43
+ return ((_a = customFonts == null ? void 0 : customFonts.map((font) => getCssFromFont(font))) == null ? void 0 : _a.join(" ")) || "";
44
+ };
45
+ exports.getFontCss = getFontCss;
46
+ const getCss = ({ cssCode, contentId }) => {
47
+ if (!cssCode) {
48
+ return "";
49
+ }
50
+ if (!contentId) {
51
+ return cssCode;
52
+ }
53
+ return (cssCode == null ? void 0 : cssCode.replace(/&/g, `div[builder-content-id="${contentId}"]`)) || "";
54
+ };
55
+ exports.getCss = getCss;
@@ -28,64 +28,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  const React = __importStar(require("react"));
30
30
  const react_native_1 = require("react-native");
31
+ const react_1 = require("react");
31
32
  const render_inlined_styles_1 = __importDefault(require("../../render-inlined-styles"));
33
+ const render_styles_helpers_1 = require("./render-styles.helpers");
34
+ const render_styles_helpers_2 = require("./render-styles.helpers");
32
35
  function RenderContentStyles(props) {
33
- function getCssFromFont(font) {
34
- var _a, _b;
35
- // TODO: compute what font sizes are used and only load those.......
36
- const family = font.family +
37
- (font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
38
- const name = family.split(",")[0];
39
- const url = (_a = font.fileUrl) !== null && _a !== void 0 ? _a : (_b = font === null || font === void 0 ? void 0 : font.files) === null || _b === void 0 ? void 0 : _b.regular;
40
- let str = "";
41
- if (url && family && name) {
42
- str += `
43
- @font-face {
44
- font-family: "${family}";
45
- src: local("${name}"), url('${url}') format('woff2');
46
- font-display: fallback;
47
- font-weight: 400;
48
- }
49
- `.trim();
50
- }
51
- if (font.files) {
52
- for (const weight in font.files) {
53
- const isNumber = String(Number(weight)) === weight;
54
- if (!isNumber) {
55
- continue;
56
- }
57
- // TODO: maybe limit number loaded
58
- const weightUrl = font.files[weight];
59
- if (weightUrl && weightUrl !== url) {
60
- str += `
61
- @font-face {
62
- font-family: "${family}";
63
- src: url('${weightUrl}') format('woff2');
64
- font-display: fallback;
65
- font-weight: ${weight};
66
- }
67
- `.trim();
68
- }
69
- }
70
- }
71
- return str;
72
- }
73
- function getFontCss({ customFonts }) {
74
- var _a;
75
- // TODO: flag for this
76
- // if (!builder.allowCustomFonts) {
77
- // return '';
78
- // }
79
- // TODO: separate internal data from external
80
- return ((_a = customFonts === null || customFonts === void 0 ? void 0 : customFonts.map((font) => getCssFromFont(font))) === null || _a === void 0 ? void 0 : _a.join(" ")) || "";
81
- }
82
- function injectedStyles() {
83
- return `
84
- ${props.cssCode || ""}
85
- ${getFontCss({
86
- customFonts: props.customFonts,
87
- })}`;
88
- }
89
- return React.createElement(render_inlined_styles_1.default, { styles: injectedStyles() });
36
+ const [injectedStyles, setInjectedStyles] = (0, react_1.useState)(() => `
37
+ ${(0, render_styles_helpers_1.getCss)({
38
+ cssCode: props.cssCode,
39
+ contentId: props.contentId,
40
+ })}
41
+ ${(0, render_styles_helpers_2.getFontCss)({
42
+ customFonts: props.customFonts,
43
+ })}
44
+ `);
45
+ return React.createElement(render_inlined_styles_1.default, { styles: injectedStyles });
90
46
  }
91
47
  exports.default = RenderContentStyles;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getContextStateInitialValue = exports.getContentInitialValue = void 0;
4
+ var __defProp = Object.defineProperty;
5
+ var __defProps = Object.defineProperties;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
+ var __spreadValues = (a, b) => {
12
+ for (var prop in b || (b = {}))
13
+ if (__hasOwnProp.call(b, prop))
14
+ __defNormalProp(a, prop, b[prop]);
15
+ if (__getOwnPropSymbols)
16
+ for (var prop of __getOwnPropSymbols(b)) {
17
+ if (__propIsEnum.call(b, prop))
18
+ __defNormalProp(a, prop, b[prop]);
19
+ }
20
+ return a;
21
+ };
22
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
+ const getContextStateInitialValue = ({ content, data, locale }) => {
24
+ var _a, _b, _c;
25
+ const defaultValues = {};
26
+ (_b = (_a = content == null ? void 0 : content.data) == null ? void 0 : _a.inputs) == null ? void 0 : _b.forEach((input) => {
27
+ var _a2;
28
+ if (input.name && input.defaultValue !== void 0 && ((_a2 = content == null ? void 0 : content.data) == null ? void 0 : _a2.state) && content.data.state[input.name] === void 0) {
29
+ defaultValues[input.name] = input.defaultValue;
30
+ }
31
+ });
32
+ const stateToUse = __spreadValues(__spreadValues(__spreadValues({}, (_c = content == null ? void 0 : content.data) == null ? void 0 : _c.state), data), locale ? { locale } : {});
33
+ return __spreadValues(__spreadValues({}, defaultValues), stateToUse);
34
+ };
35
+ exports.getContextStateInitialValue = getContextStateInitialValue;
36
+ const getContentInitialValue = ({ content, data }) => {
37
+ return !content ? void 0 : __spreadProps(__spreadValues({}, content), {
38
+ data: __spreadValues(__spreadValues({}, content == null ? void 0 : content.data), data),
39
+ meta: content == null ? void 0 : content.meta
40
+ });
41
+ };
42
+ exports.getContentInitialValue = getContentInitialValue;
@@ -45,51 +45,51 @@ const builder_context_js_1 = __importDefault(require("../../context/builder.cont
45
45
  const init_editing_js_1 = require("../../scripts/init-editing.js");
46
46
  const nullable_js_1 = require("../../helpers/nullable.js");
47
47
  const interaction_js_1 = require("../../functions/track/interaction.js");
48
+ const render_content_helpers_js_1 = require("./render-content.helpers.js");
48
49
  function RenderContent(props) {
49
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
50
+ var _a, _b, _c, _d, _e;
50
51
  const elementRef = (0, react_1.useRef)(null);
51
52
  const [forceReRenderCount, setForceReRenderCount] = (0, react_1.useState)(() => 0);
52
53
  const [overrideContent, setOverrideContent] = (0, react_1.useState)(() => null);
53
- function useContent() {
54
- var _a, _b, _c, _d, _e;
55
- if (!props.content && !overrideContent) {
56
- return undefined;
57
- }
58
- return {
59
- ...props.content,
60
- ...overrideContent,
54
+ const [useContent, setUseContent] = (0, react_1.useState)(() => (0, render_content_helpers_js_1.getContentInitialValue)({
55
+ content: props.content,
56
+ data: props.data,
57
+ }));
58
+ function mergeNewContent(newContent) {
59
+ var _a, _b;
60
+ setUseContent({
61
+ ...useContent,
62
+ ...newContent,
61
63
  data: {
62
- ...(_a = props.content) === null || _a === void 0 ? void 0 : _a.data,
63
- ...props.data,
64
- ...overrideContent === null || overrideContent === void 0 ? void 0 : overrideContent.data,
64
+ ...useContent === null || useContent === void 0 ? void 0 : useContent.data,
65
+ ...newContent === null || newContent === void 0 ? void 0 : newContent.data,
65
66
  },
66
67
  meta: {
67
- ...(_b = props.content) === null || _b === void 0 ? void 0 : _b.meta,
68
- ...overrideContent === null || overrideContent === void 0 ? void 0 : overrideContent.meta,
69
- breakpoints: useBreakpoints ||
70
- ((_c = overrideContent === null || overrideContent === void 0 ? void 0 : overrideContent.meta) === null || _c === void 0 ? void 0 : _c.breakpoints) ||
71
- ((_e = (_d = props.content) === null || _d === void 0 ? void 0 : _d.meta) === null || _e === void 0 ? void 0 : _e.breakpoints),
68
+ ...useContent === null || useContent === void 0 ? void 0 : useContent.meta,
69
+ ...newContent === null || newContent === void 0 ? void 0 : newContent.meta,
70
+ breakpoints: ((_a = newContent === null || newContent === void 0 ? void 0 : newContent.meta) === null || _a === void 0 ? void 0 : _a.breakpoints) || ((_b = useContent === null || useContent === void 0 ? void 0 : useContent.meta) === null || _b === void 0 ? void 0 : _b.breakpoints),
72
71
  },
73
- };
72
+ });
73
+ }
74
+ function setBreakpoints(breakpoints) {
75
+ setUseContent({
76
+ ...useContent,
77
+ meta: {
78
+ ...useContent === null || useContent === void 0 ? void 0 : useContent.meta,
79
+ breakpoints,
80
+ },
81
+ });
74
82
  }
75
83
  const [update, setUpdate] = (0, react_1.useState)(() => 0);
76
- const [useBreakpoints, setUseBreakpoints] = (0, react_1.useState)(() => null);
77
84
  const [canTrackToUse, setCanTrackToUse] = (0, react_1.useState)(() => (0, nullable_js_1.checkIsDefined)(props.canTrack) ? props.canTrack : true);
78
- const [overrideState, setOverrideState] = (0, react_1.useState)(() => ({}));
79
- function contentState() {
80
- var _a, _b;
81
- return {
82
- ...(_b = (_a = props.content) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.state,
83
- ...props.data,
84
- ...(props.locale
85
- ? {
86
- locale: props.locale,
87
- }
88
- : {}),
89
- ...overrideState,
90
- };
85
+ const [contentState, setContentState] = (0, react_1.useState)(() => (0, render_content_helpers_js_1.getContextStateInitialValue)({
86
+ content: props.content,
87
+ data: props.data,
88
+ locale: props.locale,
89
+ }));
90
+ function setContextState(newState) {
91
+ setContentState(newState);
91
92
  }
92
- const [contextContext, setContextContext] = (0, react_1.useState)(() => props.context || {});
93
93
  const [allRegisteredComponents, setAllRegisteredComponents] = (0, react_1.useState)(() => [
94
94
  ...(0, builder_registered_components_js_1.getDefaultRegisteredComponents)(),
95
95
  // While this `components` object is deprecated, we must maintain support for it.
@@ -104,17 +104,18 @@ function RenderContent(props) {
104
104
  [curr.name]: curr,
105
105
  }), {}));
106
106
  function processMessage(event) {
107
- var _a;
108
107
  const { data } = event;
109
108
  if (data) {
110
109
  switch (data.type) {
111
110
  case "builder.configureSdk": {
112
111
  const messageContent = data.data;
113
112
  const { breakpoints, contentId } = messageContent;
114
- if (!contentId || contentId !== ((_a = useContent === null || useContent === void 0 ? void 0 : useContent()) === null || _a === void 0 ? void 0 : _a.id)) {
113
+ if (!contentId || contentId !== (useContent === null || useContent === void 0 ? void 0 : useContent.id)) {
115
114
  return;
116
115
  }
117
- setUseBreakpoints(breakpoints);
116
+ if (breakpoints) {
117
+ setBreakpoints(breakpoints);
118
+ }
118
119
  setForceReRenderCount(forceReRenderCount + 1); // This is a hack to force Qwik to re-render.
119
120
  break;
120
121
  }
@@ -126,7 +127,7 @@ function RenderContent(props) {
126
127
  messageContent.modelName;
127
128
  const contentData = messageContent.data;
128
129
  if (key === props.model) {
129
- setOverrideContent(contentData);
130
+ mergeNewContent(contentData);
130
131
  setForceReRenderCount(forceReRenderCount + 1); // This is a hack to force Qwik to re-render.
131
132
  }
132
133
  break;
@@ -139,24 +140,23 @@ function RenderContent(props) {
139
140
  }
140
141
  }
141
142
  function evaluateJsCode() {
142
- var _a, _b;
143
+ var _a;
143
144
  // run any dynamic JS code attached to content
144
- const jsCode = (_b = (_a = useContent === null || useContent === void 0 ? void 0 : useContent()) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.jsCode;
145
+ const jsCode = (_a = useContent === null || useContent === void 0 ? void 0 : useContent.data) === null || _a === void 0 ? void 0 : _a.jsCode;
145
146
  if (jsCode) {
146
147
  (0, evaluate_js_1.evaluate)({
147
148
  code: jsCode,
148
- context: contextContext,
149
- state: contentState(),
149
+ context: props.context || {},
150
+ state: contentState,
150
151
  });
151
152
  }
152
153
  }
153
154
  const [httpReqsData, setHttpReqsData] = (0, react_1.useState)(() => ({}));
154
155
  const [clicked, setClicked] = (0, react_1.useState)(() => false);
155
156
  function onClick(event) {
156
- var _a, _b;
157
- if (useContent()) {
158
- const variationId = (_a = useContent === null || useContent === void 0 ? void 0 : useContent()) === null || _a === void 0 ? void 0 : _a.testVariationId;
159
- const contentId = (_b = useContent === null || useContent === void 0 ? void 0 : useContent()) === null || _b === void 0 ? void 0 : _b.id;
157
+ if (useContent) {
158
+ const variationId = useContent === null || useContent === void 0 ? void 0 : useContent.testVariationId;
159
+ const contentId = useContent === null || useContent === void 0 ? void 0 : useContent.id;
160
160
  (0, index_js_2._track)({
161
161
  type: "click",
162
162
  canTrack: canTrackToUse,
@@ -174,27 +174,27 @@ function RenderContent(props) {
174
174
  function evalExpression(expression) {
175
175
  return expression.replace(/{{([^}]+)}}/g, (_match, group) => (0, evaluate_js_1.evaluate)({
176
176
  code: group,
177
- context: contextContext,
178
- state: contentState(),
177
+ context: props.context || {},
178
+ state: contentState,
179
179
  }));
180
180
  }
181
181
  function handleRequest({ url, key }) {
182
182
  (0, get_fetch_js_1.fetch)(url)
183
183
  .then((response) => response.json())
184
184
  .then((json) => {
185
- const newOverrideState = {
186
- ...overrideState,
185
+ const newState = {
186
+ ...contentState,
187
187
  [key]: json,
188
188
  };
189
- setOverrideState(newOverrideState);
189
+ setContextState(newState);
190
190
  })
191
191
  .catch((err) => {
192
192
  console.log("error fetching dynamic data", url, err);
193
193
  });
194
194
  }
195
195
  function runHttpRequests() {
196
- var _a, _b, _c;
197
- const requests = (_c = (_b = (_a = useContent === null || useContent === void 0 ? void 0 : useContent()) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.httpRequests) !== null && _c !== void 0 ? _c : {};
196
+ var _a, _b;
197
+ const requests = (_b = (_a = useContent === null || useContent === void 0 ? void 0 : useContent.data) === null || _a === void 0 ? void 0 : _a.httpRequests) !== null && _b !== void 0 ? _b : {};
198
198
  Object.entries(requests).forEach(([key, url]) => {
199
199
  if (url && (!httpReqsData[key] || (0, is_editing_js_1.isEditing)())) {
200
200
  const evaluatedUrl = evalExpression(url);
@@ -209,7 +209,7 @@ function RenderContent(props) {
209
209
  if ((0, is_editing_js_1.isEditing)()) {
210
210
  window.dispatchEvent(new CustomEvent("builder:component:stateChange", {
211
211
  detail: {
212
- state: contentState(),
212
+ state: contentState,
213
213
  ref: {
214
214
  name: props.model,
215
215
  },
@@ -218,13 +218,11 @@ function RenderContent(props) {
218
218
  }
219
219
  }
220
220
  function shouldRenderContentStyles() {
221
- var _a, _b, _c, _d, _e;
222
- return Boolean((((_b = (_a = useContent === null || useContent === void 0 ? void 0 : useContent()) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.cssCode) ||
223
- ((_e = (_d = (_c = useContent === null || useContent === void 0 ? void 0 : useContent()) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.customFonts) === null || _e === void 0 ? void 0 : _e.length)) &&
221
+ var _a, _b, _c;
222
+ return Boolean((((_a = useContent === null || useContent === void 0 ? void 0 : useContent.data) === null || _a === void 0 ? void 0 : _a.cssCode) || ((_c = (_b = useContent === null || useContent === void 0 ? void 0 : useContent.data) === null || _b === void 0 ? void 0 : _b.customFonts) === null || _c === void 0 ? void 0 : _c.length)) &&
224
223
  target_js_1.TARGET !== "reactNative");
225
224
  }
226
225
  (0, react_1.useEffect)(() => {
227
- var _a, _b;
228
226
  if (!props.apiKey) {
229
227
  console.error("[Builder.io]: No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
230
228
  }
@@ -252,9 +250,9 @@ function RenderContent(props) {
252
250
  window.addEventListener("message", processMessage);
253
251
  window.addEventListener("builder:component:stateChangeListenerActivated", emitStateUpdate);
254
252
  }
255
- if (useContent()) {
256
- const variationId = (_a = useContent === null || useContent === void 0 ? void 0 : useContent()) === null || _a === void 0 ? void 0 : _a.testVariationId;
257
- const contentId = (_b = useContent === null || useContent === void 0 ? void 0 : useContent()) === null || _b === void 0 ? void 0 : _b.id;
253
+ if (useContent) {
254
+ const variationId = useContent === null || useContent === void 0 ? void 0 : useContent.testVariationId;
255
+ const contentId = useContent === null || useContent === void 0 ? void 0 : useContent.id;
258
256
  (0, index_js_2._track)({
259
257
  type: "impression",
260
258
  canTrack: canTrackToUse,
@@ -284,7 +282,7 @@ function RenderContent(props) {
284
282
  apiKey: props.apiKey,
285
283
  }).then((content) => {
286
284
  if (content) {
287
- setOverrideContent(content);
285
+ mergeNewContent(content);
288
286
  }
289
287
  });
290
288
  }
@@ -296,13 +294,13 @@ function RenderContent(props) {
296
294
  }, []);
297
295
  (0, react_1.useEffect)(() => {
298
296
  evaluateJsCode();
299
- }, [(_b = (_a = useContent === null || useContent === void 0 ? void 0 : useContent()) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.jsCode, contentState()]);
297
+ }, [(_a = useContent === null || useContent === void 0 ? void 0 : useContent.data) === null || _a === void 0 ? void 0 : _a.jsCode, contentState]);
300
298
  (0, react_1.useEffect)(() => {
301
299
  runHttpRequests();
302
- }, [(_d = (_c = useContent === null || useContent === void 0 ? void 0 : useContent()) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.httpRequests]);
300
+ }, [(_b = useContent === null || useContent === void 0 ? void 0 : useContent.data) === null || _b === void 0 ? void 0 : _b.httpRequests]);
303
301
  (0, react_1.useEffect)(() => {
304
302
  emitStateUpdate();
305
- }, [contentState()]);
303
+ }, [contentState]);
306
304
  (0, react_1.useEffect)(() => {
307
305
  return () => {
308
306
  if ((0, is_browser_js_1.isBrowser)()) {
@@ -312,14 +310,15 @@ function RenderContent(props) {
312
310
  };
313
311
  }, []);
314
312
  return (React.createElement(builder_context_js_1.default.Provider, { value: {
315
- content: useContent(),
316
- state: contentState(),
317
- context: contextContext,
313
+ content: useContent,
314
+ state: contentState,
315
+ setState: setContextState,
316
+ context: props.context || {},
318
317
  apiKey: props.apiKey,
319
318
  registeredComponents: allRegisteredComponents,
320
- } }, useContent() ? (React.createElement(React.Fragment, null,
321
- React.createElement(react_native_1.View, { ref: elementRef, onClick: (event) => onClick(event), "builder-content-id": (_e = useContent === null || useContent === void 0 ? void 0 : useContent()) === null || _e === void 0 ? void 0 : _e.id, "builder-model": props.model },
322
- shouldRenderContentStyles() ? (React.createElement(render_styles_1.default, { cssCode: (_g = (_f = useContent === null || useContent === void 0 ? void 0 : useContent()) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.cssCode, customFonts: (_j = (_h = useContent === null || useContent === void 0 ? void 0 : useContent()) === null || _h === void 0 ? void 0 : _h.data) === null || _j === void 0 ? void 0 : _j.customFonts })) : null,
323
- React.createElement(render_blocks_1.default, { blocks: (_l = (_k = useContent === null || useContent === void 0 ? void 0 : useContent()) === null || _k === void 0 ? void 0 : _k.data) === null || _l === void 0 ? void 0 : _l.blocks, key: forceReRenderCount })))) : null));
319
+ } }, useContent ? (React.createElement(React.Fragment, null,
320
+ React.createElement(react_native_1.View, { ref: elementRef, onClick: (event) => onClick(event), "builder-content-id": useContent === null || useContent === void 0 ? void 0 : useContent.id, "builder-model": props.model },
321
+ shouldRenderContentStyles() ? (React.createElement(render_styles_1.default, { contentId: useContent === null || useContent === void 0 ? void 0 : useContent.id, cssCode: (_c = useContent === null || useContent === void 0 ? void 0 : useContent.data) === null || _c === void 0 ? void 0 : _c.cssCode, customFonts: (_d = useContent === null || useContent === void 0 ? void 0 : useContent.data) === null || _d === void 0 ? void 0 : _d.customFonts })) : null,
322
+ React.createElement(render_blocks_1.default, { blocks: (_e = useContent === null || useContent === void 0 ? void 0 : useContent.data) === null || _e === void 0 ? void 0 : _e.blocks, key: forceReRenderCount })))) : null));
324
323
  }
325
324
  exports.default = RenderContent;