@builder.io/sdk-react 0.1.4 → 0.1.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 (181) hide show
  1. package/dist/react/blocks/button/button.js +2 -2
  2. package/dist/react/blocks/columns/columns.js +4 -4
  3. package/dist/react/blocks/form/form.js +2 -2
  4. package/dist/react/blocks/image/image.js +6 -6
  5. package/dist/react/components/render-block/render-block.js +18 -1
  6. package/dist/react/components/render-block/render-repeated-block.js +1 -0
  7. package/dist/react/components/render-blocks.js +2 -2
  8. package/dist/react/components/render-content/components/render-styles.helpers.js +51 -0
  9. package/dist/react/components/render-content/components/render-styles.js +12 -54
  10. package/dist/react/components/render-content/render-content.helpers.js +38 -0
  11. package/dist/react/components/render-content/render-content.js +65 -62
  12. package/dist/react/components/render-content/render-content.types.js +1 -0
  13. package/dist/react/constants/builder-registered-components.js +7 -7
  14. package/dist/react/context/builder.context.js +2 -0
  15. package/dist/react/index-helpers/blocks-exports.js +10 -10
  16. package/dist/react/types/input.js +1 -0
  17. package/dist/rsc/blocks/button/button.js +2 -2
  18. package/dist/rsc/blocks/columns/columns.js +4 -4
  19. package/dist/rsc/blocks/form/form.js +2 -2
  20. package/dist/rsc/blocks/image/image.js +6 -6
  21. package/dist/rsc/components/render-block/render-block.js +18 -1
  22. package/dist/rsc/components/render-block/render-repeated-block.js +1 -0
  23. package/dist/rsc/components/render-blocks.js +2 -2
  24. package/dist/rsc/components/render-content/builder-editing.js +47 -4
  25. package/dist/rsc/components/render-content/components/render-styles.helpers.js +51 -0
  26. package/dist/rsc/components/render-content/components/render-styles.js +11 -54
  27. package/dist/rsc/components/render-content/render-content.helpers.js +38 -0
  28. package/dist/rsc/components/render-content/render-content.js +43 -38
  29. package/dist/rsc/components/render-content/render-content.types.js +1 -0
  30. package/dist/rsc/constants/builder-registered-components.js +7 -7
  31. package/dist/rsc/context/builder.context.js +2 -0
  32. package/dist/rsc/index-helpers/blocks-exports.js +10 -10
  33. package/dist/rsc/types/input.js +1 -0
  34. package/package.json +1 -1
  35. package/packages/react/src/blocks/button/button.jsx +2 -2
  36. package/packages/react/src/blocks/columns/columns.jsx +4 -4
  37. package/packages/react/src/blocks/form/form.jsx +2 -2
  38. package/packages/react/src/blocks/image/image.jsx +6 -6
  39. package/packages/react/src/components/render-block/render-block.jsx +22 -1
  40. package/packages/react/src/components/render-block/render-repeated-block.jsx +1 -0
  41. package/packages/react/src/components/render-blocks.jsx +2 -2
  42. package/packages/react/src/components/render-content/components/render-styles.helpers.js +57 -0
  43. package/packages/react/src/components/render-content/components/render-styles.jsx +13 -56
  44. package/packages/react/src/components/render-content/render-content.helpers.js +48 -0
  45. package/packages/react/src/components/render-content/render-content.jsx +76 -67
  46. package/packages/{_rsc/src/components/render-block/types.js → react/src/components/render-content/render-content.types.js} +0 -0
  47. package/packages/react/src/constants/builder-registered-components.js +7 -7
  48. package/packages/react/src/context/builder.context.js +2 -0
  49. package/packages/react/src/index-helpers/blocks-exports.js +18 -18
  50. package/packages/{_rsc/src/context/types.js → react/src/types/input.js} +0 -0
  51. package/packages/rsc/src/blocks/button/button.jsx +2 -2
  52. package/packages/rsc/src/blocks/columns/columns.jsx +4 -4
  53. package/packages/rsc/src/blocks/form/form.jsx +2 -2
  54. package/packages/rsc/src/blocks/image/image.jsx +6 -6
  55. package/packages/rsc/src/components/render-block/render-block.jsx +21 -1
  56. package/packages/rsc/src/components/render-block/render-repeated-block.jsx +1 -0
  57. package/packages/rsc/src/components/render-blocks.jsx +2 -2
  58. package/packages/rsc/src/components/render-content/builder-editing.jsx +61 -4
  59. package/packages/rsc/src/components/render-content/components/render-styles.helpers.js +57 -0
  60. package/packages/rsc/src/components/render-content/components/render-styles.jsx +10 -56
  61. package/packages/rsc/src/components/render-content/render-content.helpers.js +48 -0
  62. package/packages/rsc/src/components/render-content/render-content.jsx +46 -37
  63. package/packages/{_rsc/src/functions/get-content/types.js → rsc/src/components/render-content/render-content.types.js} +0 -0
  64. package/packages/rsc/src/constants/builder-registered-components.js +7 -7
  65. package/packages/rsc/src/context/builder.context.js +2 -0
  66. package/packages/rsc/src/index-helpers/blocks-exports.js +18 -18
  67. package/packages/{_rsc/src/types/builder-block.js → rsc/src/types/input.js} +0 -0
  68. package/packages/_rsc/src/blocks/BaseText.jsx +0 -10
  69. package/packages/_rsc/src/blocks/button/button.jsx +0 -29
  70. package/packages/_rsc/src/blocks/button/component-info.js +0 -41
  71. package/packages/_rsc/src/blocks/columns/columns.jsx +0 -172
  72. package/packages/_rsc/src/blocks/columns/component-info.js +0 -242
  73. package/packages/_rsc/src/blocks/custom-code/component-info.js +0 -31
  74. package/packages/_rsc/src/blocks/custom-code/custom-code.jsx +0 -55
  75. package/packages/_rsc/src/blocks/embed/component-info.js +0 -44
  76. package/packages/_rsc/src/blocks/embed/embed.jsx +0 -43
  77. package/packages/_rsc/src/blocks/embed/helpers.js +0 -9
  78. package/packages/_rsc/src/blocks/form/component-info.js +0 -262
  79. package/packages/_rsc/src/blocks/form/form.jsx +0 -259
  80. package/packages/_rsc/src/blocks/fragment/component-info.js +0 -11
  81. package/packages/_rsc/src/blocks/fragment/fragment.jsx +0 -7
  82. package/packages/_rsc/src/blocks/image/component-info.js +0 -151
  83. package/packages/_rsc/src/blocks/image/image.helpers.js +0 -48
  84. package/packages/_rsc/src/blocks/image/image.jsx +0 -124
  85. package/packages/_rsc/src/blocks/img/component-info.js +0 -20
  86. package/packages/_rsc/src/blocks/img/img.jsx +0 -19
  87. package/packages/_rsc/src/blocks/input/component-info.js +0 -74
  88. package/packages/_rsc/src/blocks/input/input.jsx +0 -21
  89. package/packages/_rsc/src/blocks/raw-text/component-info.js +0 -16
  90. package/packages/_rsc/src/blocks/raw-text/raw-text.jsx +0 -12
  91. package/packages/_rsc/src/blocks/section/component-info.js +0 -49
  92. package/packages/_rsc/src/blocks/section/section.jsx +0 -29
  93. package/packages/_rsc/src/blocks/select/component-info.js +0 -59
  94. package/packages/_rsc/src/blocks/select/select.jsx +0 -22
  95. package/packages/_rsc/src/blocks/submit-button/component-info.js +0 -28
  96. package/packages/_rsc/src/blocks/submit-button/submit-button.jsx +0 -11
  97. package/packages/_rsc/src/blocks/symbol/component-info.js +0 -43
  98. package/packages/_rsc/src/blocks/symbol/symbol.jsx +0 -56
  99. package/packages/_rsc/src/blocks/text/component-info.js +0 -24
  100. package/packages/_rsc/src/blocks/text/text.jsx +0 -12
  101. package/packages/_rsc/src/blocks/textarea/component-info.js +0 -47
  102. package/packages/_rsc/src/blocks/textarea/textarea.jsx +0 -15
  103. package/packages/_rsc/src/blocks/util.js +0 -8
  104. package/packages/_rsc/src/blocks/video/component-info.js +0 -106
  105. package/packages/_rsc/src/blocks/video/video.jsx +0 -61
  106. package/packages/_rsc/src/components/render-block/block-styles.jsx +0 -72
  107. package/packages/_rsc/src/components/render-block/render-block.helpers.js +0 -23
  108. package/packages/_rsc/src/components/render-block/render-block.jsx +0 -251
  109. package/packages/_rsc/src/components/render-block/render-component-with-context.jsx +0 -38
  110. package/packages/_rsc/src/components/render-block/render-component.jsx +0 -37
  111. package/packages/_rsc/src/components/render-block/render-repeated-block.jsx +0 -36
  112. package/packages/_rsc/src/components/render-blocks.jsx +0 -90
  113. package/packages/_rsc/src/components/render-content/builder-editing.jsx +0 -7
  114. package/packages/_rsc/src/components/render-content/components/render-styles.jsx +0 -70
  115. package/packages/_rsc/src/components/render-content/index.js +0 -4
  116. package/packages/_rsc/src/components/render-content/render-content.jsx +0 -259
  117. package/packages/_rsc/src/components/render-inlined-styles.jsx +0 -33
  118. package/packages/_rsc/src/constants/builder-registered-components.js +0 -54
  119. package/packages/_rsc/src/constants/device-sizes.js +0 -48
  120. package/packages/_rsc/src/constants/target.js +0 -4
  121. package/packages/_rsc/src/context/builder.context.js +0 -11
  122. package/packages/_rsc/src/functions/camel-to-kebab-case.js +0 -4
  123. package/packages/_rsc/src/functions/evaluate.js +0 -6
  124. package/packages/_rsc/src/functions/event-handler-name.js +0 -7
  125. package/packages/_rsc/src/functions/extract-text-styles.js +0 -22
  126. package/packages/_rsc/src/functions/fast-clone.js +0 -4
  127. package/packages/_rsc/src/functions/get-block-actions-handler.js +0 -11
  128. package/packages/_rsc/src/functions/get-block-actions.js +0 -18
  129. package/packages/_rsc/src/functions/get-block-component-options.js +0 -28
  130. package/packages/_rsc/src/functions/get-block-properties.js +0 -50
  131. package/packages/_rsc/src/functions/get-block-tag.js +0 -6
  132. package/packages/_rsc/src/functions/get-builder-search-params/fn.test.js +0 -13
  133. package/packages/_rsc/src/functions/get-builder-search-params/index.js +0 -38
  134. package/packages/_rsc/src/functions/get-content/ab-testing.js +0 -99
  135. package/packages/_rsc/src/functions/get-content/generate-content-url.js +0 -55
  136. package/packages/_rsc/src/functions/get-content/generate-content-url.test.js +0 -31
  137. package/packages/_rsc/src/functions/get-content/index.js +0 -65
  138. package/packages/_rsc/src/functions/get-fetch.js +0 -14
  139. package/packages/_rsc/src/functions/get-global-this.js +0 -18
  140. package/packages/_rsc/src/functions/get-processed-block.js +0 -59
  141. package/packages/_rsc/src/functions/get-processed-block.test.js +0 -32
  142. package/packages/_rsc/src/functions/get-react-native-block-styles.js +0 -33
  143. package/packages/_rsc/src/functions/if-target.js +0 -15
  144. package/packages/_rsc/src/functions/is-browser.js +0 -6
  145. package/packages/_rsc/src/functions/is-editing.js +0 -7
  146. package/packages/_rsc/src/functions/is-iframe.js +0 -7
  147. package/packages/_rsc/src/functions/is-previewing.js +0 -14
  148. package/packages/_rsc/src/functions/on-change.js +0 -27
  149. package/packages/_rsc/src/functions/on-change.test.js +0 -19
  150. package/packages/_rsc/src/functions/register-component.js +0 -68
  151. package/packages/_rsc/src/functions/register.js +0 -29
  152. package/packages/_rsc/src/functions/sanitize-react-native-block-styles.js +0 -66
  153. package/packages/_rsc/src/functions/set-editor-settings.js +0 -15
  154. package/packages/_rsc/src/functions/set.js +0 -11
  155. package/packages/_rsc/src/functions/set.test.js +0 -16
  156. package/packages/_rsc/src/functions/track.js +0 -124
  157. package/packages/_rsc/src/functions/transform-block-properties.js +0 -6
  158. package/packages/_rsc/src/functions/transform-block.js +0 -6
  159. package/packages/_rsc/src/helpers/ab-tests.js +0 -16
  160. package/packages/_rsc/src/helpers/cookie.js +0 -81
  161. package/packages/_rsc/src/helpers/css.js +0 -34
  162. package/packages/_rsc/src/helpers/flatten.js +0 -34
  163. package/packages/_rsc/src/helpers/localStorage.js +0 -35
  164. package/packages/_rsc/src/helpers/nullable.js +0 -4
  165. package/packages/_rsc/src/helpers/sessionId.js +0 -52
  166. package/packages/_rsc/src/helpers/time.js +0 -5
  167. package/packages/_rsc/src/helpers/url.js +0 -13
  168. package/packages/_rsc/src/helpers/url.test.js +0 -21
  169. package/packages/_rsc/src/helpers/uuid.js +0 -13
  170. package/packages/_rsc/src/helpers/visitorId.js +0 -34
  171. package/packages/_rsc/src/index-helpers/blocks-exports.js +0 -22
  172. package/packages/_rsc/src/index-helpers/top-of-file.js +0 -2
  173. package/packages/_rsc/src/index.js +0 -14
  174. package/packages/_rsc/src/scripts/init-editing.js +0 -93
  175. package/packages/_rsc/src/types/builder-content.js +0 -0
  176. package/packages/_rsc/src/types/can-track.js +0 -0
  177. package/packages/_rsc/src/types/components.js +0 -0
  178. package/packages/_rsc/src/types/deep-partial.js +0 -0
  179. package/packages/_rsc/src/types/element.js +0 -0
  180. package/packages/_rsc/src/types/targets.js +0 -0
  181. package/packages/_rsc/src/types/typescript.js +0 -0
@@ -108,13 +108,13 @@ export default function Columns(props) {
108
108
  };
109
109
  return (React.createElement(React.Fragment, null,
110
110
  React.createElement("div", { className: `builder-columns ${props.builderBlock.id}-breakpoints` +
111
- " div-540739f0", style: {
111
+ " div-ca644030", style: {
112
112
  ...(TARGET === "reactNative" ? state.reactNativeColumnsStyles : {}),
113
113
  ...state.columnsCssVars,
114
114
  } },
115
115
  TARGET !== "reactNative" ? (React.createElement(React.Fragment, null,
116
116
  React.createElement(RenderInlinedStyles, { styles: state.columnsStyles, _context: _context }))) : null,
117
- props.columns?.map((column, index) => (React.createElement("div", { className: "builder-column div-540739f0-2", style: {
117
+ props.columns?.map((column, index) => (React.createElement("div", { className: "builder-column div-ca644030-2", style: {
118
118
  width: state.getColumnCssWidth(index),
119
119
  marginLeft: `${index === 0 ? 0 : state.getGutterSize()}px`,
120
120
  ...(TARGET === "reactNative"
@@ -125,10 +125,10 @@ export default function Columns(props) {
125
125
  React.createElement(RenderBlocks, { blocks: column.blocks, path: `component.options.columns.${index}.blocks`, parent: props.builderBlock.id, styleProp: {
126
126
  flexGrow: "1",
127
127
  }, _context: _context }))))),
128
- React.createElement("style", null, `.div-540739f0 {
128
+ React.createElement("style", null, `.div-ca644030 {
129
129
  display: flex;
130
130
  line-height: normal;
131
- }.div-540739f0-2 {
131
+ }.div-ca644030-2 {
132
132
  display: flex;
133
133
  flex-direction: column;
134
134
  align-items: stretch;
@@ -190,7 +190,7 @@ export default function FormComponent(props) {
190
190
  React.createElement(BuilderBlocks, { dataPath: "sendingMessage", blocks: props.sendingMessage, _context: _context }))) : null,
191
191
  " ",
192
192
  state.submissionState === "error" && state.responseData ? (React.createElement(React.Fragment, null,
193
- React.createElement("pre", { className: "builder-form-error-text pre-105231da" },
193
+ React.createElement("pre", { className: "builder-form-error-text pre-41e7c77e" },
194
194
  " ",
195
195
  JSON.stringify(state.responseData, null, 2),
196
196
  " "))) : null,
@@ -199,6 +199,6 @@ export default function FormComponent(props) {
199
199
  React.createElement(BuilderBlocks, { dataPath: "successMessage", blocks: props.successMessage, _context: _context }))) : null,
200
200
  " "),
201
201
  " ",
202
- React.createElement("style", null, `.pre-105231da { padding: 10px; color: red; text-align: center; }`),
202
+ React.createElement("style", null, `.pre-41e7c77e { padding: 10px; color: red; text-align: center; }`),
203
203
  " "));
204
204
  }
@@ -54,25 +54,25 @@ export default function Image(props) {
54
54
  ...state.aspectRatioCss,
55
55
  }, className: "builder-image" +
56
56
  (props.className ? " " + props.className : "") +
57
- " img-d6cf1f9c", src: props.image, srcSet: state.srcSetToUse, sizes: props.sizes })),
57
+ " img-5aa89e3a", src: props.image, srcSet: state.srcSetToUse, sizes: props.sizes })),
58
58
  props.aspectRatio &&
59
59
  !(props.builderBlock?.children?.length && props.fitContent) ? (React.createElement(React.Fragment, null,
60
- React.createElement("div", { className: "builder-image-sizer div-d6cf1f9c", style: {
60
+ React.createElement("div", { className: "builder-image-sizer div-5aa89e3a", style: {
61
61
  paddingTop:
62
62
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
63
63
  props.aspectRatio * 100 + "%",
64
64
  } }))) : null,
65
65
  props.builderBlock?.children?.length && props.fitContent ? (React.createElement(React.Fragment, null, props.children)) : null,
66
66
  !props.fitContent && props.children ? (React.createElement(React.Fragment, null,
67
- React.createElement("div", { className: "div-d6cf1f9c-2" }, props.children))) : null),
68
- React.createElement("style", null, `.img-d6cf1f9c {
67
+ React.createElement("div", { className: "div-5aa89e3a-2" }, props.children))) : null),
68
+ React.createElement("style", null, `.img-5aa89e3a {
69
69
  opacity: 1;
70
70
  transition: opacity 0.2s ease-in-out;
71
- }.div-d6cf1f9c {
71
+ }.div-5aa89e3a {
72
72
  width: 100%;
73
73
  pointer-events: none;
74
74
  font-size: 0;
75
- }.div-d6cf1f9c-2 {
75
+ }.div-5aa89e3a-2 {
76
76
  display: flex;
77
77
  flex-direction: column;
78
78
  align-items: stretch;
@@ -31,10 +31,26 @@ export default function RenderBlock(props) {
31
31
  shouldEvaluateBindings: true,
32
32
  });
33
33
  },
34
+ get proxyState() {
35
+ if (typeof Proxy === "undefined") {
36
+ console.error("no Proxy available in this environment, cannot proxy state.");
37
+ return props.context.state;
38
+ }
39
+ const useState = new Proxy(props.context.state, {
40
+ set: (obj, prop, value) => {
41
+ // set the value on the state object, so that the event handler instantly gets the update.
42
+ obj[prop] = value;
43
+ // set the value in the context, so that the rest of the app gets the update.
44
+ props.context.setState?.(obj);
45
+ return true;
46
+ },
47
+ });
48
+ return useState;
49
+ },
34
50
  get actions() {
35
51
  return getBlockActions({
36
52
  block: state.useBlock,
37
- state: props.context.state,
53
+ state: state.proxyState,
38
54
  context: props.context.context,
39
55
  });
40
56
  },
@@ -108,6 +124,7 @@ export default function RenderBlock(props) {
108
124
  state: props.context.state,
109
125
  content: props.context.content,
110
126
  context: props.context.context,
127
+ setState: props.context.setState,
111
128
  registeredComponents: props.context.registeredComponents,
112
129
  inheritedStyles: getInheritedTextStyles(),
113
130
  };
@@ -6,6 +6,7 @@ export default function RenderRepeatedBlock(props) {
6
6
  _context.BuilderContext = {
7
7
  content: props.repeatContext.content,
8
8
  state: props.repeatContext.state,
9
+ setState: props.repeatContext.setState,
9
10
  context: props.repeatContext.context,
10
11
  apiKey: props.repeatContext.apiKey,
11
12
  registeredComponents: props.repeatContext.registeredComponents,
@@ -34,12 +34,12 @@ export default function RenderBlocks(props) {
34
34
  };
35
35
  const builderContext = _context["BuilderContext"];
36
36
  return (React.createElement(React.Fragment, null,
37
- React.createElement("div", { className: state.className + " div-4f307ff9", "builder-path": props.path, "builder-parent-id": props.parent, dataSet: {
37
+ React.createElement("div", { className: state.className + " div-d19f7a9a", "builder-path": props.path, "builder-parent-id": props.parent, dataSet: {
38
38
  class: state.className,
39
39
  }, style: props.styleProp },
40
40
  props.blocks ? (React.createElement(React.Fragment, null, props.blocks?.map((block) => (React.createElement(RenderBlock, { key: "render-block-" + block.id, block: block, context: builderContext, _context: _context }))))) : null,
41
41
  props.blocks ? (React.createElement(React.Fragment, null, props.blocks?.map((block) => (React.createElement(BlockStyles, { key: "block-style-" + block.id, block: block, context: builderContext, _context: _context }))))) : null),
42
- React.createElement("style", null, `.div-4f307ff9 {
42
+ React.createElement("style", null, `.div-d19f7a9a {
43
43
  display: flex;
44
44
  flex-direction: column;
45
45
  align-items: stretch;
@@ -1,5 +1,48 @@
1
- import * as React from "react";
2
- export default function BuilderEditing(props) {
3
- const _context = { ...props["_context"] };
4
- return React.createElement("div", null);
1
+ import React, { useEffect } from 'react';
2
+ import { setupBrowserForEditing } from '../../scripts/init-editing.js';
3
+ // import type { RegisteredComponent } from '../../context/types.js';
4
+ // import type { BuilderContent } from '../../types/builder-content.js';
5
+ /**
6
+ * @typedef {object} RegisteredComponent
7
+ * @typedef {object} BuilderContent
8
+ * @typedef {(data: {data: object, key: string }) => void} OnUpdateCallback
9
+ * @typedef {{
10
+ * model: string,
11
+ * components?: RegisteredComponent[],
12
+ * children: any,
13
+ * onUpdate?: OnUpdateCallback,
14
+ * }} BuilderEditingProps
15
+ */
16
+ /**
17
+ * @param {BuilderEditingProps} props
18
+ */
19
+ export function BuilderEditingWrapper(props) {
20
+ useEffect(() => {
21
+ setupBrowserForEditing();
22
+ if (props.components) {
23
+ for (const component of props.components) {
24
+ window.parent.postMessage({
25
+ type: 'builder.registerComponent',
26
+ data: component,
27
+ }, '*');
28
+ }
29
+ }
30
+ /**
31
+ *
32
+ * @param {MessageEvent} e
33
+ */
34
+ function onMessage(e) {
35
+ switch (e.data?.type) {
36
+ case 'builder.contentUpdate': {
37
+ props.onUpdate?.(e.data.data);
38
+ }
39
+ }
40
+ }
41
+ addEventListener('message', onMessage);
42
+ return () => window.removeEventListener('message', onMessage);
43
+ }, [props.model]);
44
+ return (React.createElement("div", { onMouseDown: (e) => e.preventDefault(), onClickCapture: (e) => {
45
+ e.stopPropagation();
46
+ e.preventDefault();
47
+ } }, props.children));
5
48
  }
@@ -0,0 +1,51 @@
1
+ const getCssFromFont = (font) => {
2
+ var _a, _b;
3
+ const family = font.family + (font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
4
+ const name = family.split(",")[0];
5
+ const url = (_b = font.fileUrl) != null ? _b : (_a = font == null ? void 0 : font.files) == null ? void 0 : _a.regular;
6
+ let str = "";
7
+ if (url && family && name) {
8
+ str += `
9
+ @font-face {
10
+ font-family: "${family}";
11
+ src: local("${name}"), url('${url}') format('woff2');
12
+ font-display: fallback;
13
+ font-weight: 400;
14
+ }
15
+ `.trim();
16
+ }
17
+ if (font.files) {
18
+ for (const weight in font.files) {
19
+ const isNumber = String(Number(weight)) === weight;
20
+ if (!isNumber) {
21
+ continue;
22
+ }
23
+ const weightUrl = font.files[weight];
24
+ if (weightUrl && weightUrl !== url) {
25
+ str += `
26
+ @font-face {
27
+ font-family: "${family}";
28
+ src: url('${weightUrl}') format('woff2');
29
+ font-display: fallback;
30
+ font-weight: ${weight};
31
+ }
32
+ `.trim();
33
+ }
34
+ }
35
+ }
36
+ return str;
37
+ };
38
+ const getFontCss = ({ customFonts }) => {
39
+ var _a;
40
+ return ((_a = customFonts == null ? void 0 : customFonts.map((font) => getCssFromFont(font))) == null ? void 0 : _a.join(" ")) || "";
41
+ };
42
+ const getCss = ({ cssCode, contentId }) => {
43
+ if (!cssCode) {
44
+ return "";
45
+ }
46
+ if (!contentId) {
47
+ return cssCode;
48
+ }
49
+ return (cssCode == null ? void 0 : cssCode.replace(/&/g, `div[builder-content-id="${contentId}"]`)) || "";
50
+ };
51
+ export { getCss, getFontCss };
@@ -1,62 +1,19 @@
1
1
  import * as React from "react";
2
2
  import RenderInlinedStyles from "../../render-inlined-styles";
3
+ import { getCss } from "./render-styles.helpers";
4
+ import { getFontCss } from "./render-styles.helpers";
3
5
  export default function RenderContentStyles(props) {
4
6
  const _context = { ...props["_context"] };
5
7
  const state = {
6
- getCssFromFont(font) {
7
- // TODO: compute what font sizes are used and only load those.......
8
- const family = font.family +
9
- (font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
10
- const name = family.split(",")[0];
11
- const url = font.fileUrl ?? font?.files?.regular;
12
- let str = "";
13
- if (url && family && name) {
14
- str += `
15
- @font-face {
16
- font-family: "${family}";
17
- src: local("${name}"), url('${url}') format('woff2');
18
- font-display: fallback;
19
- font-weight: 400;
20
- }
21
- `.trim();
22
- }
23
- if (font.files) {
24
- for (const weight in font.files) {
25
- const isNumber = String(Number(weight)) === weight;
26
- if (!isNumber) {
27
- continue;
28
- }
29
- // TODO: maybe limit number loaded
30
- const weightUrl = font.files[weight];
31
- if (weightUrl && weightUrl !== url) {
32
- str += `
33
- @font-face {
34
- font-family: "${family}";
35
- src: url('${weightUrl}') format('woff2');
36
- font-display: fallback;
37
- font-weight: ${weight};
38
- }
39
- `.trim();
40
- }
41
- }
42
- }
43
- return str;
44
- },
45
- getFontCss({ customFonts }) {
46
- // TODO: flag for this
47
- // if (!this.builder.allowCustomFonts) {
48
- // return '';
49
- // }
50
- // TODO: separate internal data from external
51
- return (customFonts?.map((font) => this.getCssFromFont(font))?.join(" ") || "");
52
- },
53
- get injectedStyles() {
54
- return `
55
- ${props.cssCode || ""}
56
- ${state.getFontCss({
57
- customFonts: props.customFonts,
58
- })}`;
59
- },
8
+ injectedStyles: `
9
+ ${getCss({
10
+ cssCode: props.cssCode,
11
+ contentId: props.contentId,
12
+ })}
13
+ ${getFontCss({
14
+ customFonts: props.customFonts,
15
+ })}
16
+ `,
60
17
  };
61
18
  return (React.createElement(RenderInlinedStyles, { styles: state.injectedStyles, _context: _context }));
62
19
  }
@@ -0,0 +1,38 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ const getContextStateInitialValue = ({ content, data, locale }) => {
21
+ var _a, _b, _c;
22
+ const defaultValues = {};
23
+ (_b = (_a = content == null ? void 0 : content.data) == null ? void 0 : _a.inputs) == null ? void 0 : _b.forEach((input) => {
24
+ var _a2;
25
+ 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) {
26
+ defaultValues[input.name] = input.defaultValue;
27
+ }
28
+ });
29
+ const stateToUse = __spreadValues(__spreadValues(__spreadValues({}, (_c = content == null ? void 0 : content.data) == null ? void 0 : _c.state), data), locale ? { locale } : {});
30
+ return __spreadValues(__spreadValues({}, defaultValues), stateToUse);
31
+ };
32
+ const getContentInitialValue = ({ content, data }) => {
33
+ return !content ? void 0 : __spreadProps(__spreadValues({}, content), {
34
+ data: __spreadValues(__spreadValues({}, content == null ? void 0 : content.data), data),
35
+ meta: content == null ? void 0 : content.meta
36
+ });
37
+ };
38
+ export { getContentInitialValue, getContextStateInitialValue };
@@ -15,49 +15,51 @@ import builderContext from "../../context/builder.context.js";
15
15
  import { registerInsertMenu, setupBrowserForEditing, } from "../../scripts/init-editing.js";
16
16
  import { checkIsDefined } from "../../helpers/nullable.js";
17
17
  import { getInteractionPropertiesForEvent } from "../../functions/track/interaction.js";
18
+ import { getContentInitialValue, getContextStateInitialValue, } from "./render-content.helpers.js";
18
19
  export default function RenderContent(props) {
19
20
  const _context = { ...props["_context"] };
20
21
  const state = {
21
22
  forceReRenderCount: 0,
22
23
  overrideContent: null,
23
- get useContent() {
24
- if (!props.content && !state.overrideContent) {
25
- return undefined;
26
- }
27
- return {
28
- ...props.content,
29
- ...state.overrideContent,
24
+ useContent: getContentInitialValue({
25
+ content: props.content,
26
+ data: props.data,
27
+ }),
28
+ mergeNewContent(newContent) {
29
+ state.useContent = {
30
+ ...state.useContent,
31
+ ...newContent,
30
32
  data: {
31
- ...props.content?.data,
32
- ...props.data,
33
- ...state.overrideContent?.data,
33
+ ...state.useContent?.data,
34
+ ...newContent?.data,
35
+ },
36
+ meta: {
37
+ ...state.useContent?.meta,
38
+ ...newContent?.meta,
39
+ breakpoints: newContent?.meta?.breakpoints ||
40
+ state.useContent?.meta?.breakpoints,
34
41
  },
42
+ };
43
+ },
44
+ setBreakpoints(breakpoints) {
45
+ state.useContent = {
46
+ ...state.useContent,
35
47
  meta: {
36
- ...props.content?.meta,
37
- ...state.overrideContent?.meta,
38
- breakpoints: state.useBreakpoints ||
39
- state.overrideContent?.meta?.breakpoints ||
40
- props.content?.meta?.breakpoints,
48
+ ...state.useContent?.meta,
49
+ breakpoints,
41
50
  },
42
51
  };
43
52
  },
44
53
  update: 0,
45
- useBreakpoints: null,
46
54
  canTrackToUse: checkIsDefined(props.canTrack) ? props.canTrack : true,
47
- overrideState: {},
48
- get contentState() {
49
- return {
50
- ...props.content?.data?.state,
51
- ...props.data,
52
- ...(props.locale
53
- ? {
54
- locale: props.locale,
55
- }
56
- : {}),
57
- ...state.overrideState,
58
- };
55
+ contentState: getContextStateInitialValue({
56
+ content: props.content,
57
+ data: props.data,
58
+ locale: props.locale,
59
+ }),
60
+ setContextState(newState) {
61
+ state.contentState = newState;
59
62
  },
60
- contextContext: props.context || {},
61
63
  allRegisteredComponents: [
62
64
  ...getDefaultRegisteredComponents(),
63
65
  // While this `components` object is deprecated, we must maintain support for it.
@@ -81,7 +83,9 @@ export default function RenderContent(props) {
81
83
  if (!contentId || contentId !== state.useContent?.id) {
82
84
  return;
83
85
  }
84
- state.useBreakpoints = breakpoints;
86
+ if (breakpoints) {
87
+ state.setBreakpoints(breakpoints);
88
+ }
85
89
  state.forceReRenderCount = state.forceReRenderCount + 1; // This is a hack to force Qwik to re-render.
86
90
  break;
87
91
  }
@@ -93,7 +97,7 @@ export default function RenderContent(props) {
93
97
  messageContent.modelName;
94
98
  const contentData = messageContent.data;
95
99
  if (key === props.model) {
96
- state.overrideContent = contentData;
100
+ state.mergeNewContent(contentData);
97
101
  state.forceReRenderCount = state.forceReRenderCount + 1; // This is a hack to force Qwik to re-render.
98
102
  }
99
103
  break;
@@ -111,7 +115,7 @@ export default function RenderContent(props) {
111
115
  if (jsCode) {
112
116
  evaluate({
113
117
  code: jsCode,
114
- context: state.contextContext,
118
+ context: props.context || {},
115
119
  state: state.contentState,
116
120
  });
117
121
  }
@@ -139,7 +143,7 @@ export default function RenderContent(props) {
139
143
  evalExpression(expression) {
140
144
  return expression.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({
141
145
  code: group,
142
- context: state.contextContext,
146
+ context: props.context || {},
143
147
  state: state.contentState,
144
148
  }));
145
149
  },
@@ -147,11 +151,11 @@ export default function RenderContent(props) {
147
151
  fetch(url)
148
152
  .then((response) => response.json())
149
153
  .then((json) => {
150
- const newOverrideState = {
151
- ...state.overrideState,
154
+ const newState = {
155
+ ...state.contentState,
152
156
  [key]: json,
153
157
  };
154
- state.overrideState = newOverrideState;
158
+ state.setContextState(newState);
155
159
  })
156
160
  .catch((err) => {
157
161
  console.log("error fetching dynamic data", url, err);
@@ -190,12 +194,13 @@ export default function RenderContent(props) {
190
194
  _context.builderContext = {
191
195
  content: state.useContent,
192
196
  state: state.contentState,
193
- context: state.contextContext,
197
+ setState: state.setContextState,
198
+ context: props.context || {},
194
199
  apiKey: props.apiKey,
195
200
  registeredComponents: state.allRegisteredComponents,
196
201
  };
197
202
  return (React.createElement(React.Fragment, null, state.useContent ? (React.createElement(React.Fragment, null,
198
203
  React.createElement("div", { "builder-content-id": state.useContent?.id, "builder-model": props.model },
199
- state.shouldRenderContentStyles ? (React.createElement(RenderContentStyles, { cssCode: state.useContent?.data?.cssCode, customFonts: state.useContent?.data?.customFonts, _context: _context })) : null,
204
+ state.shouldRenderContentStyles ? (React.createElement(RenderContentStyles, { contentId: state.useContent?.id, cssCode: state.useContent?.data?.cssCode, customFonts: state.useContent?.data?.customFonts, _context: _context })) : null,
200
205
  React.createElement(RenderBlocks, { blocks: state.useContent?.data?.blocks, key: state.forceReRenderCount, _context: _context })))) : null));
201
206
  }
@@ -37,16 +37,16 @@ import { componentInfo as imgComponentInfo } from "../blocks/img/component-info.
37
37
  import { default as customCode } from "../blocks/custom-code/custom-code";
38
38
  import { componentInfo as customCodeInfo } from "../blocks/custom-code/component-info.js";
39
39
  const getDefaultRegisteredComponents = () => [
40
+ __spreadValues({ component: Button }, buttonComponentInfo),
40
41
  __spreadValues({ component: Columns }, columnsComponentInfo),
42
+ __spreadValues({ component: customCode }, customCodeInfo),
43
+ __spreadValues({ component: embed }, embedComponentInfo),
44
+ __spreadValues({ component: Fragment }, fragmentComponentInfo),
41
45
  __spreadValues({ component: Image }, imageComponentInfo),
42
46
  __spreadValues({ component: Img }, imgComponentInfo),
43
- __spreadValues({ component: Text }, textComponentInfo),
44
- __spreadValues({ component: Video }, videoComponentInfo),
45
- __spreadValues({ component: Symbol }, symbolComponentInfo),
46
- __spreadValues({ component: Button }, buttonComponentInfo),
47
47
  __spreadValues({ component: Section }, sectionComponentInfo),
48
- __spreadValues({ component: Fragment }, fragmentComponentInfo),
49
- __spreadValues({ component: embed }, embedComponentInfo),
50
- __spreadValues({ component: customCode }, customCodeInfo)
48
+ __spreadValues({ component: Symbol }, symbolComponentInfo),
49
+ __spreadValues({ component: Text }, textComponentInfo),
50
+ __spreadValues({ component: Video }, videoComponentInfo)
51
51
  ];
52
52
  export { getDefaultRegisteredComponents };
@@ -2,6 +2,8 @@ var stdin_default = {
2
2
  content: null,
3
3
  context: {},
4
4
  state: {},
5
+ setState() {
6
+ },
5
7
  apiKey: null,
6
8
  registeredComponents: {},
7
9
  inheritedStyles: {}
@@ -1,11 +1,11 @@
1
- import { default as default2 } from "../blocks/columns/columns";
2
- import { default as default3 } from "../blocks/image/image";
3
- import { default as default4 } from "../blocks/text/text";
4
- import { default as default5 } from "../blocks/video/video";
5
- import { default as default6 } from "../blocks/symbol/symbol";
6
- import { default as default7 } from "../blocks/button/button";
1
+ import { default as default2 } from "../blocks/button/button";
2
+ import { default as default3 } from "../blocks/columns/columns";
3
+ import { default as default4 } from "../blocks/fragment/fragment";
4
+ import { default as default5 } from "../blocks/image/image";
5
+ import { default as default6 } from "../components/render-blocks";
6
+ import { default as default7 } from "../components/render-content/render-content";
7
7
  import { default as default8 } from "../blocks/section/section";
8
- import { default as default9 } from "../blocks/fragment/fragment";
9
- import { default as default10 } from "../components/render-content/render-content";
10
- import { default as default11 } from "../components/render-blocks";
11
- export { default7 as Button, default2 as Columns, default9 as Fragment, default3 as Image, default11 as RenderBlocks, default10 as RenderContent, default8 as Section, default6 as Symbol, default4 as Text, default5 as Video };
8
+ import { default as default9 } from "../blocks/symbol/symbol";
9
+ import { default as default10 } from "../blocks/text/text";
10
+ import { default as default11 } from "../blocks/video/video";
11
+ export { default2 as Button, default3 as Columns, default4 as Fragment, default5 as Image, default6 as RenderBlocks, default7 as RenderContent, default8 as Section, default9 as Symbol, default10 as Text, default11 as Video };
@@ -0,0 +1 @@
1
+ "use strict";
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.1.4",
4
+ "version": "0.1.5",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
7
7
  "exports": {
@@ -15,11 +15,11 @@ export default function Button(props) {
15
15
  </a>
16
16
  </>
17
17
  ) : (
18
- <button className="button-7028b0a4" {...props.attributes}>
18
+ <button className="button-66d34b93" {...props.attributes}>
19
19
  {props.text}
20
20
  </button>
21
21
  )}
22
- <style>{`.button-7028b0a4 {
22
+ <style>{`.button-66d34b93 {
23
23
  all: unset;
24
24
  }`}</style>
25
25
  </>
@@ -124,7 +124,7 @@ export default function Columns(props) {
124
124
  <div
125
125
  className={
126
126
  `builder-columns ${props.builderBlock.id}-breakpoints` +
127
- " div-bda7d4e0"
127
+ " div-46a0fd84"
128
128
  }
129
129
  style={{
130
130
  ...(TARGET === "reactNative" ? reactNativeColumnsStyles() : {}),
@@ -139,7 +139,7 @@ export default function Columns(props) {
139
139
 
140
140
  {props.columns?.map((column, index) => (
141
141
  <div
142
- className="builder-column div-bda7d4e0-2"
142
+ className="builder-column div-46a0fd84-2"
143
143
  style={{
144
144
  width: getColumnCssWidth(index),
145
145
  marginLeft: `${index === 0 ? 0 : getGutterSize()}px`,
@@ -159,10 +159,10 @@ export default function Columns(props) {
159
159
  </div>
160
160
  ))}
161
161
  </div>
162
- <style>{`.div-bda7d4e0 {
162
+ <style>{`.div-46a0fd84 {
163
163
  display: flex;
164
164
  line-height: normal;
165
- }.div-bda7d4e0-2 {
165
+ }.div-46a0fd84-2 {
166
166
  display: flex;
167
167
  flex-direction: column;
168
168
  align-items: stretch;
@@ -232,7 +232,7 @@ export default function FormComponent(props) {
232
232
  ) : null}{" "}
233
233
  {submissionState() === "error" && responseData ? (
234
234
  <>
235
- <pre className="builder-form-error-text pre-4bdc7532">
235
+ <pre className="builder-form-error-text pre-0d1abaf2">
236
236
  {" "}
237
237
  {JSON.stringify(responseData, null, 2)}{" "}
238
238
  </pre>
@@ -247,7 +247,7 @@ export default function FormComponent(props) {
247
247
  </>
248
248
  ) : null}{" "}
249
249
  </form>{" "}
250
- <style>{`.pre-4bdc7532 { padding: 10px; color: red; text-align: center; }`}</style>{" "}
250
+ <style>{`.pre-0d1abaf2 { padding: 10px; color: red; text-align: center; }`}</style>{" "}
251
251
  </>
252
252
  );
253
253
  }