@builder.io/sdk-react 0.1.2 → 0.1.4

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 (564) hide show
  1. package/dist/react/blocks/BaseText.js +7 -0
  2. package/dist/react/blocks/button/button.js +9 -0
  3. package/dist/react/blocks/button/component-info.js +39 -0
  4. package/dist/react/blocks/columns/columns.js +131 -0
  5. package/dist/react/blocks/columns/component-info.js +241 -0
  6. package/dist/react/blocks/custom-code/component-info.js +29 -0
  7. package/dist/react/blocks/custom-code/custom-code.js +49 -0
  8. package/dist/react/blocks/embed/component-info.js +44 -0
  9. package/dist/react/blocks/embed/embed.js +40 -0
  10. package/dist/react/blocks/embed/helpers.js +7 -0
  11. package/dist/react/blocks/form/component-info.js +260 -0
  12. package/dist/react/blocks/form/form.js +201 -0
  13. package/dist/react/blocks/fragment/component-info.js +9 -0
  14. package/dist/react/blocks/fragment/fragment.js +4 -0
  15. package/dist/react/blocks/image/component-info.js +149 -0
  16. package/dist/react/blocks/image/image.helpers.js +46 -0
  17. package/dist/react/blocks/image/image.js +82 -0
  18. package/dist/react/blocks/img/component-info.js +18 -0
  19. package/dist/react/blocks/img/img.js +8 -0
  20. package/dist/react/blocks/input/component-info.js +72 -0
  21. package/dist/react/blocks/input/input.js +5 -0
  22. package/dist/react/blocks/raw-text/component-info.js +14 -0
  23. package/dist/react/blocks/raw-text/raw-text.js +4 -0
  24. package/dist/react/blocks/section/component-info.js +47 -0
  25. package/dist/react/blocks/section/section.js +17 -0
  26. package/dist/react/blocks/select/component-info.js +57 -0
  27. package/dist/react/blocks/select/select.js +5 -0
  28. package/dist/react/blocks/submit-button/component-info.js +26 -0
  29. package/dist/react/blocks/submit-button/submit-button.js +4 -0
  30. package/dist/react/blocks/symbol/component-info.js +41 -0
  31. package/dist/react/blocks/symbol/symbol.js +63 -0
  32. package/dist/react/blocks/text/component-info.js +22 -0
  33. package/dist/react/blocks/text/text.js +4 -0
  34. package/dist/react/blocks/textarea/component-info.js +45 -0
  35. package/dist/react/blocks/textarea/textarea.js +4 -0
  36. package/dist/react/blocks/util.js +6 -0
  37. package/dist/react/blocks/video/component-info.js +104 -0
  38. package/dist/react/blocks/video/video.js +48 -0
  39. package/dist/react/components/render-block/block-styles.js +48 -0
  40. package/dist/react/components/render-block/render-block.helpers.js +104 -0
  41. package/dist/react/components/render-block/render-block.js +122 -0
  42. package/dist/react/components/render-block/render-component-with-context.js +27 -0
  43. package/dist/react/components/render-block/render-component.js +10 -0
  44. package/dist/react/components/render-block/render-repeated-block.js +15 -0
  45. package/dist/react/components/render-block/types.js +1 -0
  46. package/dist/react/components/render-blocks.js +45 -0
  47. package/dist/react/components/render-content/builder-editing.js +4 -0
  48. package/dist/react/components/render-content/components/render-styles.js +59 -0
  49. package/dist/react/components/render-content/index.js +2 -0
  50. package/dist/react/components/render-content/render-content.js +285 -0
  51. package/dist/react/components/render-inlined-styles.js +15 -0
  52. package/dist/react/constants/builder-registered-components.js +52 -0
  53. package/dist/react/constants/device-sizes.js +45 -0
  54. package/dist/react/constants/target.js +2 -0
  55. package/dist/react/context/builder.context.js +10 -0
  56. package/dist/react/context/types.js +1 -0
  57. package/dist/react/functions/camel-to-kebab-case.js +2 -0
  58. package/dist/react/functions/evaluate.js +22 -0
  59. package/dist/react/functions/event-handler-name.js +5 -0
  60. package/dist/react/functions/extract-text-styles.js +20 -0
  61. package/dist/react/functions/fast-clone.js +2 -0
  62. package/dist/react/functions/get-block-actions-handler.js +9 -0
  63. package/dist/react/functions/get-block-actions.js +16 -0
  64. package/dist/react/functions/get-block-component-options.js +26 -0
  65. package/dist/react/functions/get-block-properties.js +48 -0
  66. package/dist/react/functions/get-block-tag.js +4 -0
  67. package/dist/react/functions/get-builder-search-params/fn.test.js +13 -0
  68. package/dist/react/functions/get-builder-search-params/index.js +33 -0
  69. package/dist/react/functions/get-content/ab-testing.js +86 -0
  70. package/dist/react/functions/get-content/generate-content-url.js +41 -0
  71. package/dist/react/functions/get-content/generate-content-url.test.js +31 -0
  72. package/dist/react/functions/get-content/index.js +64 -0
  73. package/dist/react/functions/get-content/types.js +1 -0
  74. package/dist/react/functions/get-fetch.js +12 -0
  75. package/dist/react/functions/get-global-this.js +16 -0
  76. package/dist/react/functions/get-processed-block.js +49 -0
  77. package/dist/react/functions/get-processed-block.test.js +32 -0
  78. package/dist/react/functions/get-react-native-block-styles.js +27 -0
  79. package/dist/react/functions/if-target.js +10 -0
  80. package/dist/react/functions/is-browser.js +4 -0
  81. package/dist/react/functions/is-editing.js +5 -0
  82. package/dist/react/functions/is-iframe.js +5 -0
  83. package/dist/react/functions/is-previewing.js +12 -0
  84. package/dist/react/functions/on-change.js +24 -0
  85. package/dist/react/functions/on-change.test.js +19 -0
  86. package/dist/react/functions/register-component.js +60 -0
  87. package/dist/react/functions/register.js +28 -0
  88. package/dist/react/functions/sanitize-react-native-block-styles.js +68 -0
  89. package/dist/react/functions/set-editor-settings.js +13 -0
  90. package/dist/react/functions/set.js +9 -0
  91. package/dist/react/functions/set.test.js +16 -0
  92. package/dist/react/functions/track/helpers.js +50 -0
  93. package/dist/react/functions/track/index.js +120 -0
  94. package/dist/react/functions/track/interaction.js +48 -0
  95. package/dist/react/functions/track.js +116 -0
  96. package/dist/react/functions/transform-block-properties.js +4 -0
  97. package/dist/react/functions/transform-block.js +4 -0
  98. package/dist/react/helpers/ab-tests.js +6 -0
  99. package/dist/react/helpers/cookie.js +70 -0
  100. package/dist/react/helpers/css.js +28 -0
  101. package/dist/react/helpers/flatten.js +32 -0
  102. package/dist/react/helpers/localStorage.js +27 -0
  103. package/dist/react/helpers/nullable.js +2 -0
  104. package/dist/react/helpers/sessionId.js +46 -0
  105. package/dist/react/helpers/time.js +3 -0
  106. package/dist/react/helpers/url.js +11 -0
  107. package/dist/react/helpers/url.test.js +21 -0
  108. package/dist/react/helpers/uuid.js +10 -0
  109. package/dist/react/helpers/visitorId.js +28 -0
  110. package/dist/react/index-helpers/blocks-exports.js +11 -0
  111. package/dist/react/index-helpers/top-of-file.js +2 -0
  112. package/dist/react/index.js +12 -0
  113. package/dist/react/scripts/init-editing.js +93 -0
  114. package/dist/react/types/builder-block.js +1 -0
  115. package/dist/react/types/builder-content.js +1 -0
  116. package/dist/react/types/can-track.js +1 -0
  117. package/dist/react/types/components.js +1 -0
  118. package/dist/react/types/deep-partial.js +1 -0
  119. package/dist/react/types/element.js +1 -0
  120. package/dist/react/types/targets.js +1 -0
  121. package/dist/react/types/typescript.js +1 -0
  122. package/dist/rsc/blocks/BaseText.js +7 -0
  123. package/dist/rsc/blocks/button/button.js +10 -0
  124. package/dist/rsc/blocks/button/component-info.js +39 -0
  125. package/dist/rsc/blocks/columns/columns.js +136 -0
  126. package/dist/rsc/blocks/columns/component-info.js +241 -0
  127. package/dist/rsc/blocks/custom-code/component-info.js +29 -0
  128. package/dist/rsc/blocks/custom-code/custom-code.js +45 -0
  129. package/dist/rsc/blocks/embed/component-info.js +44 -0
  130. package/dist/rsc/blocks/embed/embed.js +36 -0
  131. package/dist/rsc/blocks/embed/helpers.js +7 -0
  132. package/dist/rsc/blocks/form/component-info.js +260 -0
  133. package/dist/rsc/blocks/form/form.js +204 -0
  134. package/dist/rsc/blocks/fragment/component-info.js +9 -0
  135. package/dist/rsc/blocks/fragment/fragment.js +5 -0
  136. package/dist/rsc/blocks/image/component-info.js +149 -0
  137. package/dist/rsc/blocks/image/image.helpers.js +46 -0
  138. package/dist/rsc/blocks/image/image.js +85 -0
  139. package/dist/rsc/blocks/img/component-info.js +18 -0
  140. package/dist/rsc/blocks/img/img.js +9 -0
  141. package/dist/rsc/blocks/input/component-info.js +72 -0
  142. package/dist/rsc/blocks/input/input.js +6 -0
  143. package/dist/rsc/blocks/raw-text/component-info.js +14 -0
  144. package/dist/rsc/blocks/raw-text/raw-text.js +5 -0
  145. package/dist/rsc/blocks/section/component-info.js +47 -0
  146. package/dist/rsc/blocks/section/section.js +18 -0
  147. package/dist/rsc/blocks/select/component-info.js +57 -0
  148. package/dist/rsc/blocks/select/select.js +6 -0
  149. package/dist/rsc/blocks/submit-button/component-info.js +26 -0
  150. package/dist/rsc/blocks/submit-button/submit-button.js +5 -0
  151. package/dist/rsc/blocks/symbol/component-info.js +41 -0
  152. package/dist/rsc/blocks/symbol/symbol.js +37 -0
  153. package/dist/rsc/blocks/text/component-info.js +22 -0
  154. package/dist/rsc/blocks/text/text.js +5 -0
  155. package/dist/rsc/blocks/textarea/component-info.js +45 -0
  156. package/dist/rsc/blocks/textarea/textarea.js +5 -0
  157. package/dist/rsc/blocks/util.js +6 -0
  158. package/dist/rsc/blocks/video/component-info.js +104 -0
  159. package/dist/rsc/blocks/video/video.js +51 -0
  160. package/dist/rsc/components/render-block/block-styles.js +51 -0
  161. package/dist/rsc/components/render-block/render-block.helpers.js +104 -0
  162. package/dist/rsc/components/render-block/render-block.js +126 -0
  163. package/dist/rsc/components/render-block/render-component-with-context.js +27 -0
  164. package/dist/rsc/components/render-block/render-component.js +11 -0
  165. package/dist/rsc/components/render-block/render-repeated-block.js +15 -0
  166. package/dist/rsc/components/render-block/types.js +1 -0
  167. package/dist/rsc/components/render-blocks.js +47 -0
  168. package/dist/rsc/components/render-content/builder-editing.js +5 -0
  169. package/dist/rsc/components/render-content/components/render-styles.js +62 -0
  170. package/dist/rsc/components/render-content/index.js +2 -0
  171. package/dist/rsc/components/render-content/render-content.js +201 -0
  172. package/dist/rsc/components/render-inlined-styles.js +18 -0
  173. package/dist/rsc/constants/builder-registered-components.js +52 -0
  174. package/dist/rsc/constants/device-sizes.js +45 -0
  175. package/dist/rsc/constants/target.js +2 -0
  176. package/dist/rsc/context/builder.context.js +9 -0
  177. package/dist/rsc/context/types.js +1 -0
  178. package/dist/rsc/functions/camel-to-kebab-case.js +2 -0
  179. package/dist/rsc/functions/evaluate.js +4 -0
  180. package/dist/rsc/functions/event-handler-name.js +5 -0
  181. package/dist/rsc/functions/extract-text-styles.js +20 -0
  182. package/dist/rsc/functions/fast-clone.js +2 -0
  183. package/dist/rsc/functions/get-block-actions-handler.js +9 -0
  184. package/dist/rsc/functions/get-block-actions.js +16 -0
  185. package/dist/rsc/functions/get-block-component-options.js +26 -0
  186. package/dist/rsc/functions/get-block-properties.js +48 -0
  187. package/dist/rsc/functions/get-block-tag.js +4 -0
  188. package/dist/rsc/functions/get-builder-search-params/fn.test.js +13 -0
  189. package/dist/rsc/functions/get-builder-search-params/index.js +33 -0
  190. package/dist/rsc/functions/get-content/ab-testing.js +86 -0
  191. package/dist/rsc/functions/get-content/generate-content-url.js +41 -0
  192. package/dist/rsc/functions/get-content/generate-content-url.test.js +31 -0
  193. package/dist/rsc/functions/get-content/index.js +64 -0
  194. package/dist/rsc/functions/get-content/types.js +1 -0
  195. package/dist/rsc/functions/get-fetch.js +12 -0
  196. package/dist/rsc/functions/get-global-this.js +16 -0
  197. package/dist/rsc/functions/get-processed-block.js +49 -0
  198. package/dist/rsc/functions/get-processed-block.test.js +32 -0
  199. package/dist/rsc/functions/get-react-native-block-styles.js +27 -0
  200. package/dist/rsc/functions/if-target.js +10 -0
  201. package/dist/rsc/functions/is-browser.js +4 -0
  202. package/dist/rsc/functions/is-editing.js +5 -0
  203. package/dist/rsc/functions/is-iframe.js +5 -0
  204. package/dist/rsc/functions/is-previewing.js +12 -0
  205. package/dist/rsc/functions/on-change.js +24 -0
  206. package/dist/rsc/functions/on-change.test.js +19 -0
  207. package/dist/rsc/functions/register-component.js +60 -0
  208. package/dist/rsc/functions/register.js +28 -0
  209. package/dist/rsc/functions/sanitize-react-native-block-styles.js +68 -0
  210. package/dist/rsc/functions/set-editor-settings.js +13 -0
  211. package/dist/rsc/functions/set.js +9 -0
  212. package/dist/rsc/functions/set.test.js +16 -0
  213. package/dist/rsc/functions/track/helpers.js +50 -0
  214. package/dist/rsc/functions/track/index.js +120 -0
  215. package/dist/rsc/functions/track/interaction.js +48 -0
  216. package/dist/rsc/functions/track.js +116 -0
  217. package/dist/rsc/functions/transform-block-properties.js +4 -0
  218. package/dist/rsc/functions/transform-block.js +4 -0
  219. package/dist/rsc/helpers/ab-tests.js +6 -0
  220. package/dist/rsc/helpers/cookie.js +70 -0
  221. package/dist/rsc/helpers/css.js +28 -0
  222. package/dist/rsc/helpers/flatten.js +32 -0
  223. package/dist/rsc/helpers/localStorage.js +27 -0
  224. package/dist/rsc/helpers/nullable.js +2 -0
  225. package/dist/rsc/helpers/sessionId.js +46 -0
  226. package/dist/rsc/helpers/time.js +3 -0
  227. package/dist/rsc/helpers/url.js +11 -0
  228. package/dist/rsc/helpers/url.test.js +21 -0
  229. package/dist/rsc/helpers/uuid.js +10 -0
  230. package/dist/rsc/helpers/visitorId.js +28 -0
  231. package/dist/rsc/index-helpers/blocks-exports.js +11 -0
  232. package/dist/rsc/index-helpers/top-of-file.js +2 -0
  233. package/dist/rsc/index.js +12 -0
  234. package/dist/rsc/scripts/init-editing.js +93 -0
  235. package/dist/rsc/types/builder-block.js +1 -0
  236. package/dist/rsc/types/builder-content.js +1 -0
  237. package/dist/rsc/types/can-track.js +1 -0
  238. package/dist/rsc/types/components.js +1 -0
  239. package/dist/rsc/types/deep-partial.js +1 -0
  240. package/dist/rsc/types/element.js +1 -0
  241. package/dist/rsc/types/targets.js +1 -0
  242. package/dist/rsc/types/typescript.js +1 -0
  243. package/package.json +11 -6
  244. package/packages/_rsc/src/blocks/BaseText.jsx +10 -0
  245. package/packages/_rsc/src/blocks/button/button.jsx +29 -0
  246. package/packages/_rsc/src/blocks/columns/{columns.js → columns.jsx} +80 -61
  247. package/packages/_rsc/src/blocks/custom-code/custom-code.jsx +55 -0
  248. package/packages/_rsc/src/blocks/embed/embed.jsx +43 -0
  249. package/packages/_rsc/src/blocks/form/form.jsx +259 -0
  250. package/packages/_rsc/src/blocks/fragment/fragment.jsx +7 -0
  251. package/packages/_rsc/src/blocks/image/image.jsx +124 -0
  252. package/packages/_rsc/src/blocks/img/img.jsx +19 -0
  253. package/packages/_rsc/src/blocks/input/input.jsx +21 -0
  254. package/packages/_rsc/src/blocks/raw-text/raw-text.jsx +12 -0
  255. package/packages/_rsc/src/blocks/section/section.jsx +29 -0
  256. package/packages/_rsc/src/blocks/select/select.jsx +22 -0
  257. package/packages/_rsc/src/blocks/submit-button/submit-button.jsx +11 -0
  258. package/packages/_rsc/src/blocks/symbol/symbol.jsx +56 -0
  259. package/packages/_rsc/src/blocks/text/text.jsx +12 -0
  260. package/packages/_rsc/src/blocks/textarea/textarea.jsx +15 -0
  261. package/packages/_rsc/src/blocks/video/video.jsx +61 -0
  262. package/packages/_rsc/src/components/render-block/block-styles.jsx +72 -0
  263. package/packages/_rsc/src/components/render-block/render-block.jsx +251 -0
  264. package/packages/_rsc/src/components/render-block/render-component-with-context.jsx +38 -0
  265. package/packages/_rsc/src/components/render-block/render-component.jsx +37 -0
  266. package/packages/_rsc/src/components/render-block/render-repeated-block.jsx +36 -0
  267. package/packages/_rsc/src/components/render-blocks.jsx +90 -0
  268. package/packages/_rsc/src/components/render-content/builder-editing.jsx +7 -0
  269. package/packages/_rsc/src/components/render-content/components/render-styles.jsx +70 -0
  270. package/packages/_rsc/src/components/render-content/render-content.jsx +259 -0
  271. package/packages/_rsc/src/components/render-inlined-styles.jsx +33 -0
  272. package/packages/react/src/blocks/BaseText.jsx +9 -0
  273. package/packages/react/src/blocks/button/button.jsx +27 -0
  274. package/packages/react/src/blocks/button/component-info.js +41 -0
  275. package/packages/react/src/blocks/columns/columns.jsx +172 -0
  276. package/packages/react/src/blocks/columns/component-info.js +242 -0
  277. package/packages/react/src/blocks/custom-code/component-info.js +31 -0
  278. package/packages/react/src/blocks/custom-code/custom-code.jsx +64 -0
  279. package/packages/react/src/blocks/embed/component-info.js +44 -0
  280. package/packages/react/src/blocks/embed/embed.jsx +49 -0
  281. package/packages/react/src/blocks/embed/helpers.js +9 -0
  282. package/packages/react/src/blocks/form/component-info.js +262 -0
  283. package/packages/react/src/blocks/form/form.jsx +253 -0
  284. package/packages/react/src/blocks/fragment/component-info.js +11 -0
  285. package/packages/react/src/blocks/fragment/fragment.jsx +5 -0
  286. package/packages/react/src/blocks/image/component-info.js +151 -0
  287. package/packages/react/src/blocks/image/image.helpers.js +48 -0
  288. package/packages/react/src/blocks/image/image.jsx +120 -0
  289. package/packages/react/src/blocks/img/component-info.js +20 -0
  290. package/packages/react/src/blocks/img/img.jsx +17 -0
  291. package/packages/react/src/blocks/input/component-info.js +74 -0
  292. package/packages/react/src/blocks/input/input.jsx +19 -0
  293. package/packages/react/src/blocks/raw-text/component-info.js +16 -0
  294. package/packages/react/src/blocks/raw-text/raw-text.jsx +10 -0
  295. package/packages/react/src/blocks/section/component-info.js +49 -0
  296. package/packages/react/src/blocks/section/section.jsx +27 -0
  297. package/packages/react/src/blocks/select/component-info.js +59 -0
  298. package/packages/react/src/blocks/select/select.jsx +20 -0
  299. package/packages/react/src/blocks/submit-button/component-info.js +28 -0
  300. package/packages/react/src/blocks/submit-button/submit-button.jsx +9 -0
  301. package/packages/react/src/blocks/symbol/component-info.js +43 -0
  302. package/packages/react/src/blocks/symbol/symbol.jsx +86 -0
  303. package/packages/react/src/blocks/text/component-info.js +24 -0
  304. package/packages/react/src/blocks/text/text.jsx +10 -0
  305. package/packages/react/src/blocks/textarea/component-info.js +47 -0
  306. package/packages/react/src/blocks/textarea/textarea.jsx +13 -0
  307. package/packages/react/src/blocks/util.js +8 -0
  308. package/packages/react/src/blocks/video/component-info.js +106 -0
  309. package/packages/react/src/blocks/video/video.jsx +58 -0
  310. package/packages/react/src/components/render-block/block-styles.jsx +69 -0
  311. package/packages/react/src/components/render-block/render-block.helpers.js +113 -0
  312. package/packages/react/src/components/render-block/render-block.jsx +184 -0
  313. package/packages/react/src/components/render-block/render-component.jsx +33 -0
  314. package/packages/react/src/components/render-block/render-repeated-block.jsx +21 -0
  315. package/packages/react/src/components/render-block/types.js +0 -0
  316. package/packages/react/src/components/render-blocks.jsx +89 -0
  317. package/packages/react/src/components/render-content/builder-editing.jsx +5 -0
  318. package/packages/react/src/components/render-content/components/render-styles.jsx +64 -0
  319. package/packages/react/src/components/render-content/index.js +4 -0
  320. package/packages/react/src/components/render-content/render-content.jsx +372 -0
  321. package/packages/react/src/components/render-inlined-styles.jsx +28 -0
  322. package/packages/react/src/constants/builder-registered-components.js +54 -0
  323. package/packages/react/src/constants/device-sizes.js +48 -0
  324. package/packages/react/src/constants/target.js +4 -0
  325. package/packages/react/src/context/builder.context.js +12 -0
  326. package/packages/react/src/context/types.js +0 -0
  327. package/packages/react/src/functions/camel-to-kebab-case.js +4 -0
  328. package/packages/react/src/functions/evaluate.js +29 -0
  329. package/packages/react/src/functions/event-handler-name.js +7 -0
  330. package/packages/react/src/functions/extract-text-styles.js +22 -0
  331. package/packages/react/src/functions/fast-clone.js +4 -0
  332. package/packages/react/src/functions/get-block-actions-handler.js +11 -0
  333. package/packages/react/src/functions/get-block-actions.js +18 -0
  334. package/packages/{_rsc/src/blocks/textarea/textarea.js → react/src/functions/get-block-component-options.js} +6 -10
  335. package/packages/react/src/functions/get-block-properties.js +50 -0
  336. package/packages/react/src/functions/get-block-tag.js +6 -0
  337. package/packages/react/src/functions/get-builder-search-params/fn.test.js +13 -0
  338. package/packages/react/src/functions/get-builder-search-params/index.js +38 -0
  339. package/packages/react/src/functions/get-content/ab-testing.js +99 -0
  340. package/packages/react/src/functions/get-content/generate-content-url.js +55 -0
  341. package/packages/react/src/functions/get-content/generate-content-url.test.js +31 -0
  342. package/packages/react/src/functions/get-content/index.js +65 -0
  343. package/packages/react/src/functions/get-content/types.js +0 -0
  344. package/packages/react/src/functions/get-fetch.js +14 -0
  345. package/packages/react/src/functions/get-global-this.js +18 -0
  346. package/packages/react/src/functions/get-processed-block.js +59 -0
  347. package/packages/react/src/functions/get-processed-block.test.js +32 -0
  348. package/packages/{_rsc/src/blocks/BaseText.js → react/src/functions/get-react-native-block-styles.js} +14 -8
  349. package/packages/react/src/functions/if-target.js +15 -0
  350. package/packages/react/src/functions/is-browser.js +6 -0
  351. package/packages/react/src/functions/is-editing.js +7 -0
  352. package/packages/react/src/functions/is-iframe.js +7 -0
  353. package/packages/react/src/functions/is-previewing.js +14 -0
  354. package/packages/react/src/functions/on-change.js +27 -0
  355. package/packages/react/src/functions/on-change.test.js +19 -0
  356. package/packages/react/src/functions/register-component.js +68 -0
  357. package/packages/react/src/functions/register.js +29 -0
  358. package/packages/react/src/functions/sanitize-react-native-block-styles.js +66 -0
  359. package/packages/react/src/functions/set-editor-settings.js +15 -0
  360. package/packages/react/src/functions/set.js +11 -0
  361. package/packages/react/src/functions/set.test.js +16 -0
  362. package/packages/react/src/functions/track/helpers.js +50 -0
  363. package/packages/react/src/functions/track/index.js +128 -0
  364. package/packages/react/src/functions/track/interaction.js +53 -0
  365. package/packages/react/src/functions/transform-block-properties.js +6 -0
  366. package/packages/react/src/functions/transform-block.js +6 -0
  367. package/packages/react/src/helpers/ab-tests.js +16 -0
  368. package/packages/react/src/helpers/cookie.js +81 -0
  369. package/packages/react/src/helpers/css.js +34 -0
  370. package/packages/{_rsc/src/blocks/input/input.js → react/src/helpers/flatten.js} +12 -14
  371. package/packages/react/src/helpers/localStorage.js +35 -0
  372. package/packages/react/src/helpers/nullable.js +4 -0
  373. package/packages/react/src/helpers/sessionId.js +52 -0
  374. package/packages/react/src/helpers/time.js +5 -0
  375. package/packages/react/src/helpers/url.js +13 -0
  376. package/packages/react/src/helpers/url.test.js +21 -0
  377. package/packages/react/src/helpers/uuid.js +13 -0
  378. package/packages/react/src/helpers/visitorId.js +34 -0
  379. package/packages/react/src/index-helpers/blocks-exports.js +22 -0
  380. package/packages/react/src/index-helpers/top-of-file.js +4 -0
  381. package/packages/react/src/index.js +14 -0
  382. package/packages/react/src/scripts/init-editing.js +93 -0
  383. package/packages/react/src/types/builder-block.js +0 -0
  384. package/packages/react/src/types/builder-content.js +0 -0
  385. package/packages/react/src/types/can-track.js +0 -0
  386. package/packages/react/src/types/components.js +0 -0
  387. package/packages/react/src/types/deep-partial.js +0 -0
  388. package/packages/react/src/types/element.js +0 -0
  389. package/packages/react/src/types/targets.js +0 -0
  390. package/packages/react/src/types/typescript.js +0 -0
  391. package/packages/rsc/src/blocks/BaseText.jsx +10 -0
  392. package/packages/rsc/src/blocks/button/button.jsx +29 -0
  393. package/packages/rsc/src/blocks/button/component-info.js +41 -0
  394. package/packages/rsc/src/blocks/columns/columns.jsx +172 -0
  395. package/packages/rsc/src/blocks/columns/component-info.js +242 -0
  396. package/packages/rsc/src/blocks/custom-code/component-info.js +31 -0
  397. package/packages/rsc/src/blocks/custom-code/custom-code.jsx +55 -0
  398. package/packages/rsc/src/blocks/embed/component-info.js +44 -0
  399. package/packages/rsc/src/blocks/embed/embed.jsx +43 -0
  400. package/packages/rsc/src/blocks/embed/helpers.js +9 -0
  401. package/packages/rsc/src/blocks/form/component-info.js +262 -0
  402. package/packages/rsc/src/blocks/form/form.jsx +259 -0
  403. package/packages/rsc/src/blocks/fragment/component-info.js +11 -0
  404. package/packages/rsc/src/blocks/fragment/fragment.jsx +7 -0
  405. package/packages/rsc/src/blocks/image/component-info.js +151 -0
  406. package/packages/rsc/src/blocks/image/image.helpers.js +48 -0
  407. package/packages/rsc/src/blocks/image/image.jsx +122 -0
  408. package/packages/rsc/src/blocks/img/component-info.js +20 -0
  409. package/packages/rsc/src/blocks/img/img.jsx +19 -0
  410. package/packages/rsc/src/blocks/input/component-info.js +74 -0
  411. package/packages/rsc/src/blocks/input/input.jsx +21 -0
  412. package/packages/rsc/src/blocks/raw-text/component-info.js +16 -0
  413. package/packages/rsc/src/blocks/raw-text/raw-text.jsx +12 -0
  414. package/packages/rsc/src/blocks/section/component-info.js +49 -0
  415. package/packages/rsc/src/blocks/section/section.jsx +29 -0
  416. package/packages/rsc/src/blocks/select/component-info.js +59 -0
  417. package/packages/rsc/src/blocks/select/select.jsx +22 -0
  418. package/packages/rsc/src/blocks/submit-button/component-info.js +28 -0
  419. package/packages/rsc/src/blocks/submit-button/submit-button.jsx +11 -0
  420. package/packages/rsc/src/blocks/symbol/component-info.js +43 -0
  421. package/packages/rsc/src/blocks/symbol/symbol.jsx +56 -0
  422. package/packages/rsc/src/blocks/text/component-info.js +24 -0
  423. package/packages/rsc/src/blocks/text/text.jsx +12 -0
  424. package/packages/rsc/src/blocks/textarea/component-info.js +47 -0
  425. package/packages/rsc/src/blocks/textarea/textarea.jsx +15 -0
  426. package/packages/rsc/src/blocks/util.js +8 -0
  427. package/packages/rsc/src/blocks/video/component-info.js +106 -0
  428. package/packages/rsc/src/blocks/video/video.jsx +61 -0
  429. package/packages/rsc/src/components/render-block/block-styles.jsx +72 -0
  430. package/packages/rsc/src/components/render-block/render-block.helpers.js +113 -0
  431. package/packages/rsc/src/components/render-block/render-block.jsx +183 -0
  432. package/packages/rsc/src/components/render-block/render-component.jsx +37 -0
  433. package/packages/rsc/src/components/render-block/render-repeated-block.jsx +24 -0
  434. package/packages/rsc/src/components/render-block/types.js +0 -0
  435. package/packages/rsc/src/components/render-blocks.jsx +90 -0
  436. package/packages/rsc/src/components/render-content/builder-editing.jsx +7 -0
  437. package/packages/rsc/src/components/render-content/components/render-styles.jsx +70 -0
  438. package/packages/rsc/src/components/render-content/index.js +4 -0
  439. package/packages/rsc/src/components/render-content/render-content.jsx +245 -0
  440. package/packages/rsc/src/components/render-inlined-styles.jsx +31 -0
  441. package/packages/rsc/src/constants/builder-registered-components.js +54 -0
  442. package/packages/rsc/src/constants/device-sizes.js +48 -0
  443. package/packages/rsc/src/constants/target.js +4 -0
  444. package/packages/rsc/src/context/builder.context.js +11 -0
  445. package/packages/rsc/src/context/types.js +0 -0
  446. package/packages/rsc/src/functions/camel-to-kebab-case.js +4 -0
  447. package/packages/rsc/src/functions/evaluate.js +6 -0
  448. package/packages/rsc/src/functions/event-handler-name.js +7 -0
  449. package/packages/rsc/src/functions/extract-text-styles.js +22 -0
  450. package/packages/rsc/src/functions/fast-clone.js +4 -0
  451. package/packages/rsc/src/functions/get-block-actions-handler.js +11 -0
  452. package/packages/rsc/src/functions/get-block-actions.js +18 -0
  453. package/packages/{_rsc/src/blocks/text/text.js → rsc/src/functions/get-block-component-options.js} +8 -7
  454. package/packages/rsc/src/functions/get-block-properties.js +50 -0
  455. package/packages/rsc/src/functions/get-block-tag.js +6 -0
  456. package/packages/rsc/src/functions/get-builder-search-params/fn.test.js +13 -0
  457. package/packages/rsc/src/functions/get-builder-search-params/index.js +38 -0
  458. package/packages/rsc/src/functions/get-content/ab-testing.js +99 -0
  459. package/packages/rsc/src/functions/get-content/generate-content-url.js +55 -0
  460. package/packages/rsc/src/functions/get-content/generate-content-url.test.js +31 -0
  461. package/packages/rsc/src/functions/get-content/index.js +65 -0
  462. package/packages/rsc/src/functions/get-content/types.js +0 -0
  463. package/packages/rsc/src/functions/get-fetch.js +14 -0
  464. package/packages/rsc/src/functions/get-global-this.js +18 -0
  465. package/packages/rsc/src/functions/get-processed-block.js +59 -0
  466. package/packages/rsc/src/functions/get-processed-block.test.js +32 -0
  467. package/packages/{_rsc/src/blocks/raw-text/raw-text.js → rsc/src/functions/get-react-native-block-styles.js} +14 -9
  468. package/packages/rsc/src/functions/if-target.js +15 -0
  469. package/packages/rsc/src/functions/is-browser.js +6 -0
  470. package/packages/rsc/src/functions/is-editing.js +7 -0
  471. package/packages/rsc/src/functions/is-iframe.js +7 -0
  472. package/packages/rsc/src/functions/is-previewing.js +14 -0
  473. package/packages/rsc/src/functions/on-change.js +27 -0
  474. package/packages/rsc/src/functions/on-change.test.js +19 -0
  475. package/packages/rsc/src/functions/register-component.js +68 -0
  476. package/packages/rsc/src/functions/register.js +29 -0
  477. package/packages/rsc/src/functions/sanitize-react-native-block-styles.js +66 -0
  478. package/packages/rsc/src/functions/set-editor-settings.js +15 -0
  479. package/packages/rsc/src/functions/set.js +11 -0
  480. package/packages/rsc/src/functions/set.test.js +16 -0
  481. package/packages/rsc/src/functions/track/helpers.js +50 -0
  482. package/packages/rsc/src/functions/track/index.js +128 -0
  483. package/packages/rsc/src/functions/track/interaction.js +53 -0
  484. package/packages/rsc/src/functions/transform-block-properties.js +6 -0
  485. package/packages/rsc/src/functions/transform-block.js +6 -0
  486. package/packages/rsc/src/helpers/ab-tests.js +16 -0
  487. package/packages/rsc/src/helpers/cookie.js +81 -0
  488. package/packages/rsc/src/helpers/css.js +34 -0
  489. package/packages/{_rsc/src/blocks/section/section.js → rsc/src/helpers/flatten.js} +12 -18
  490. package/packages/rsc/src/helpers/localStorage.js +35 -0
  491. package/packages/rsc/src/helpers/nullable.js +4 -0
  492. package/packages/rsc/src/helpers/sessionId.js +52 -0
  493. package/packages/rsc/src/helpers/time.js +5 -0
  494. package/packages/rsc/src/helpers/url.js +13 -0
  495. package/packages/rsc/src/helpers/url.test.js +21 -0
  496. package/packages/rsc/src/helpers/uuid.js +13 -0
  497. package/packages/rsc/src/helpers/visitorId.js +34 -0
  498. package/packages/rsc/src/index-helpers/blocks-exports.js +22 -0
  499. package/packages/rsc/src/index-helpers/top-of-file.js +2 -0
  500. package/packages/rsc/src/index.js +14 -0
  501. package/packages/rsc/src/scripts/init-editing.js +93 -0
  502. package/packages/rsc/src/types/builder-block.js +0 -0
  503. package/packages/rsc/src/types/builder-content.js +0 -0
  504. package/packages/rsc/src/types/can-track.js +0 -0
  505. package/packages/rsc/src/types/components.js +0 -0
  506. package/packages/rsc/src/types/deep-partial.js +0 -0
  507. package/packages/rsc/src/types/element.js +0 -0
  508. package/packages/rsc/src/types/targets.js +0 -0
  509. package/packages/rsc/src/types/typescript.js +0 -0
  510. package/src/blocks/BaseText.jsx +4 -7
  511. package/src/blocks/button/button.jsx +25 -32
  512. package/src/blocks/columns/columns.jsx +83 -59
  513. package/src/blocks/custom-code/custom-code.jsx +29 -15
  514. package/src/blocks/embed/embed.jsx +15 -11
  515. package/src/blocks/form/form.jsx +184 -148
  516. package/src/blocks/fragment/fragment.jsx +3 -5
  517. package/src/blocks/image/image.jsx +80 -56
  518. package/src/blocks/img/img.jsx +14 -29
  519. package/src/blocks/input/input.jsx +16 -32
  520. package/src/blocks/raw-text/raw-text.jsx +8 -9
  521. package/src/blocks/section/section.jsx +25 -37
  522. package/src/blocks/select/select.jsx +17 -32
  523. package/src/blocks/submit-button/submit-button.jsx +7 -23
  524. package/src/blocks/symbol/symbol.jsx +59 -48
  525. package/src/blocks/text/text.jsx +8 -8
  526. package/src/blocks/textarea/textarea.jsx +11 -29
  527. package/src/blocks/video/video.jsx +52 -48
  528. package/src/components/render-block/block-styles.jsx +48 -29
  529. package/src/components/render-block/render-block.jsx +150 -100
  530. package/src/components/render-block/render-component-with-context.jsx +35 -32
  531. package/src/components/render-block/render-component.jsx +30 -32
  532. package/src/components/render-block/render-repeated-block.jsx +30 -30
  533. package/src/components/render-blocks.jsx +73 -47
  534. package/src/components/render-content/builder-editing.jsx +3 -5
  535. package/src/components/render-content/components/render-styles.jsx +21 -15
  536. package/src/components/render-content/index.js +1 -1
  537. package/src/components/render-content/render-content.jsx +207 -133
  538. package/src/components/render-inlined-styles.jsx +19 -8
  539. package/src/constants/builder-registered-components.js +11 -11
  540. package/src/index-helpers/blocks-exports.js +10 -10
  541. package/tsconfig.base.json +18 -0
  542. package/tsconfig.react.json +7 -0
  543. package/tsconfig.rsc.json +7 -0
  544. package/packages/_rsc/src/blocks/button/button.js +0 -35
  545. package/packages/_rsc/src/blocks/custom-code/custom-code.js +0 -63
  546. package/packages/_rsc/src/blocks/embed/embed.js +0 -55
  547. package/packages/_rsc/src/blocks/form/form.js +0 -222
  548. package/packages/_rsc/src/blocks/fragment/fragment.js +0 -24
  549. package/packages/_rsc/src/blocks/image/image.js +0 -101
  550. package/packages/_rsc/src/blocks/img/img.js +0 -33
  551. package/packages/_rsc/src/blocks/select/select.js +0 -36
  552. package/packages/_rsc/src/blocks/submit-button/submit-button.js +0 -26
  553. package/packages/_rsc/src/blocks/symbol/symbol.js +0 -60
  554. package/packages/_rsc/src/blocks/video/video.js +0 -57
  555. package/packages/_rsc/src/components/render-block/block-styles.js +0 -70
  556. package/packages/_rsc/src/components/render-block/render-block.js +0 -211
  557. package/packages/_rsc/src/components/render-block/render-component-with-context.js +0 -51
  558. package/packages/_rsc/src/components/render-block/render-component.js +0 -43
  559. package/packages/_rsc/src/components/render-block/render-repeated-block.js +0 -49
  560. package/packages/_rsc/src/components/render-blocks.js +0 -80
  561. package/packages/_rsc/src/components/render-content/builder-editing.js +0 -35
  562. package/packages/_rsc/src/components/render-content/components/render-styles.js +0 -78
  563. package/packages/_rsc/src/components/render-content/render-content.js +0 -216
  564. package/packages/_rsc/src/components/render-inlined-styles.js +0 -36
@@ -0,0 +1,259 @@
1
+ import * as React from "react";
2
+ import RenderBlock from "../../components/render-block/render-block";
3
+ import BuilderBlocks from "../../components/render-blocks";
4
+ import { isEditing } from "../../functions/is-editing.js";
5
+
6
+ export default function FormComponent(props) {
7
+ const _context = { ...props["_context"] };
8
+
9
+ const state = {
10
+ formState: "unsubmitted",
11
+ responseData: null,
12
+ formErrorMessage: "",
13
+ get submissionState() {
14
+ return (isEditing() && props.previewState) || state.formState;
15
+ },
16
+ onSubmit(event) {
17
+ const sendWithJs =
18
+ props.sendWithJs || props.sendSubmissionsTo === "email";
19
+ if (props.sendSubmissionsTo === "zapier") {
20
+ event.preventDefault();
21
+ } else if (sendWithJs) {
22
+ if (!(props.action || props.sendSubmissionsTo === "email")) {
23
+ event.preventDefault();
24
+ return;
25
+ }
26
+ event.preventDefault();
27
+ const el = event.currentTarget;
28
+ const headers = props.customHeaders || {};
29
+ let body;
30
+ const formData = new FormData(el);
31
+
32
+ // TODO: maybe support null
33
+ const formPairs = Array.from(
34
+ event.currentTarget.querySelectorAll("input,select,textarea")
35
+ )
36
+ .filter((el) => !!el.name)
37
+ .map((el) => {
38
+ let value;
39
+ const key = el.name;
40
+ if (el instanceof HTMLInputElement) {
41
+ if (el.type === "radio") {
42
+ if (el.checked) {
43
+ value = el.name;
44
+ return {
45
+ key,
46
+ value,
47
+ };
48
+ }
49
+ } else if (el.type === "checkbox") {
50
+ value = el.checked;
51
+ } else if (el.type === "number" || el.type === "range") {
52
+ const num = el.valueAsNumber;
53
+ if (!isNaN(num)) {
54
+ value = num;
55
+ }
56
+ } else if (el.type === "file") {
57
+ // TODO: one vs multiple files
58
+ value = el.files;
59
+ } else {
60
+ value = el.value;
61
+ }
62
+ } else {
63
+ value = el.value;
64
+ }
65
+ return {
66
+ key,
67
+ value,
68
+ };
69
+ });
70
+ let contentType = props.contentType;
71
+ if (props.sendSubmissionsTo === "email") {
72
+ contentType = "multipart/form-data";
73
+ }
74
+ Array.from(formPairs).forEach(({ value }) => {
75
+ if (
76
+ value instanceof File ||
77
+ (Array.isArray(value) && value[0] instanceof File) ||
78
+ value instanceof FileList
79
+ ) {
80
+ contentType = "multipart/form-data";
81
+ }
82
+ });
83
+
84
+ // TODO: send as urlEncoded or multipart by default
85
+ // because of ease of use and reliability in browser API
86
+ // for encoding the form?
87
+ if (contentType !== "application/json") {
88
+ body = formData;
89
+ } else {
90
+ // Json
91
+ const json = {};
92
+ Array.from(formPairs).forEach(({ value, key }) => {
93
+ set(json, key, value);
94
+ });
95
+ body = JSON.stringify(json);
96
+ }
97
+ if (contentType && contentType !== "multipart/form-data") {
98
+ if (
99
+ /* Zapier doesn't allow content-type header to be sent from browsers */ !(
100
+ sendWithJs && props.action?.includes("zapier.com")
101
+ )
102
+ ) {
103
+ headers["content-type"] = contentType;
104
+ }
105
+ }
106
+ const presubmitEvent = new CustomEvent("presubmit", {
107
+ detail: { body },
108
+ });
109
+ if (formRef) {
110
+ formRef.dispatchEvent(presubmitEvent);
111
+ if (presubmitEvent.defaultPrevented) {
112
+ return;
113
+ }
114
+ }
115
+ state.formState = "sending";
116
+ const formUrl = `${
117
+ builder.env === "dev" ? "http://localhost:5000" : "https://builder.io"
118
+ }/api/v1/form-submit?apiKey=${builder.apiKey}&to=${btoa(
119
+ props.sendSubmissionsToEmail || ""
120
+ )}&name=${encodeURIComponent(props.name || "")}`;
121
+ fetch(
122
+ props.sendSubmissionsTo === "email"
123
+ ? formUrl
124
+ : props.action /* TODO: throw error if no action URL */,
125
+ { body, headers, method: props.method || "post" }
126
+ ).then(
127
+ async (res) => {
128
+ let body;
129
+ const contentType = res.headers.get("content-type");
130
+ if (contentType && contentType.indexOf("application/json") !== -1) {
131
+ body = await res.json();
132
+ } else {
133
+ body = await res.text();
134
+ }
135
+ if (!res.ok && props.errorMessagePath) {
136
+ /* TODO: allow supplying an error formatter function */ let message =
137
+ get(body, props.errorMessagePath);
138
+ if (message) {
139
+ if (typeof message !== "string") {
140
+ /* TODO: ideally convert json to yaml so it woul dbe like error: - email has been taken */ message =
141
+ JSON.stringify(message);
142
+ }
143
+ state.formErrorMessage = message;
144
+ }
145
+ }
146
+ state.responseData = body;
147
+ state.formState = res.ok ? "success" : "error";
148
+ if (res.ok) {
149
+ const submitSuccessEvent = new CustomEvent("submit:success", {
150
+ detail: { res, body },
151
+ });
152
+ if (formRef) {
153
+ formRef.dispatchEvent(submitSuccessEvent);
154
+ if (submitSuccessEvent.defaultPrevented) {
155
+ return;
156
+ }
157
+ /* TODO: option to turn this on/off? */ if (
158
+ props.resetFormOnSubmit !== false
159
+ ) {
160
+ formRef.reset();
161
+ }
162
+ }
163
+ /* TODO: client side route event first that can be preventDefaulted */ if (
164
+ props.successUrl
165
+ ) {
166
+ if (formRef) {
167
+ const event = new CustomEvent("route", {
168
+ detail: { url: props.successUrl },
169
+ });
170
+ formRef.dispatchEvent(event);
171
+ if (!event.defaultPrevented) {
172
+ location.href = props.successUrl;
173
+ }
174
+ } else {
175
+ location.href = props.successUrl;
176
+ }
177
+ }
178
+ }
179
+ },
180
+ (err) => {
181
+ const submitErrorEvent = new CustomEvent("submit:error", {
182
+ detail: { error: err },
183
+ });
184
+ if (formRef) {
185
+ formRef.dispatchEvent(submitErrorEvent);
186
+ if (submitErrorEvent.defaultPrevented) {
187
+ return;
188
+ }
189
+ }
190
+ state.responseData = err;
191
+ state.formState = "error";
192
+ }
193
+ );
194
+ }
195
+ },
196
+ };
197
+ const builderContext = _context["BuilderContext"];
198
+ return (
199
+ <>
200
+ {" "}
201
+ <form
202
+ validate={props.validate}
203
+ action={!props.sendWithJs && props.action}
204
+ method={props.method}
205
+ name={props.name}
206
+ {...props.attributes}
207
+ >
208
+ {" "}
209
+ {props.builderBlock && props.builderBlock.children ? (
210
+ <>
211
+ {props.builderBlock?.children?.map((block) => (
212
+ <RenderBlock
213
+ block={block}
214
+ context={builderContext}
215
+ _context={_context}
216
+ />
217
+ ))}
218
+ </>
219
+ ) : null}{" "}
220
+ {state.submissionState === "error" ? (
221
+ <>
222
+ <BuilderBlocks
223
+ dataPath="errorMessage"
224
+ blocks={props.errorMessage}
225
+ _context={_context}
226
+ />
227
+ </>
228
+ ) : null}{" "}
229
+ {state.submissionState === "sending" ? (
230
+ <>
231
+ <BuilderBlocks
232
+ dataPath="sendingMessage"
233
+ blocks={props.sendingMessage}
234
+ _context={_context}
235
+ />
236
+ </>
237
+ ) : null}{" "}
238
+ {state.submissionState === "error" && state.responseData ? (
239
+ <>
240
+ <pre className="builder-form-error-text pre-105231da">
241
+ {" "}
242
+ {JSON.stringify(state.responseData, null, 2)}{" "}
243
+ </pre>
244
+ </>
245
+ ) : null}{" "}
246
+ {state.submissionState === "success" ? (
247
+ <>
248
+ <BuilderBlocks
249
+ dataPath="successMessage"
250
+ blocks={props.successMessage}
251
+ _context={_context}
252
+ />
253
+ </>
254
+ ) : null}{" "}
255
+ </form>{" "}
256
+ <style>{`.pre-105231da { padding: 10px; color: red; text-align: center; }`}</style>{" "}
257
+ </>
258
+ );
259
+ }
@@ -0,0 +1,11 @@
1
+ const componentInfo = {
2
+ name: "Fragment",
3
+ static: true,
4
+ hidden: true,
5
+ builtIn: true,
6
+ canHaveChildren: true,
7
+ noWrap: true
8
+ };
9
+ export {
10
+ componentInfo
11
+ };
@@ -0,0 +1,7 @@
1
+ import * as React from "react";
2
+
3
+ export default function FragmentComponent(props) {
4
+ const _context = { ...props["_context"] };
5
+
6
+ return <span>{props.children}</span>;
7
+ }
@@ -0,0 +1,151 @@
1
+ import { serializeFn } from "../util.js";
2
+ const componentInfo = {
3
+ name: "Image",
4
+ static: true,
5
+ builtIn: true,
6
+ 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",
7
+ defaultStyles: {
8
+ position: "relative",
9
+ minHeight: "20px",
10
+ minWidth: "20px",
11
+ overflow: "hidden"
12
+ },
13
+ canHaveChildren: true,
14
+ inputs: [
15
+ {
16
+ name: "image",
17
+ type: "file",
18
+ bubble: true,
19
+ allowedFileTypes: ["jpeg", "jpg", "png", "svg"],
20
+ required: true,
21
+ defaultValue: "https://cdn.builder.io/api/v1/image/assets%2Fpwgjf0RoYWbdnJSbpBAjXNRMe9F2%2Ffb27a7c790324294af8be1c35fe30f4d",
22
+ onChange: serializeFn((options) => {
23
+ const DEFAULT_ASPECT_RATIO = 0.7041;
24
+ options.delete("srcset");
25
+ options.delete("noWebp");
26
+ function loadImage(url, timeout = 6e4) {
27
+ return new Promise((resolve, reject) => {
28
+ const img = document.createElement("img");
29
+ let loaded = false;
30
+ img.onload = () => {
31
+ loaded = true;
32
+ resolve(img);
33
+ };
34
+ img.addEventListener("error", (event) => {
35
+ console.warn("Image load failed", event.error);
36
+ reject(event.error);
37
+ });
38
+ img.src = url;
39
+ setTimeout(() => {
40
+ if (!loaded) {
41
+ reject(new Error("Image load timed out"));
42
+ }
43
+ }, timeout);
44
+ });
45
+ }
46
+ function round(num) {
47
+ return Math.round(num * 1e3) / 1e3;
48
+ }
49
+ const value = options.get("image");
50
+ const aspectRatio = options.get("aspectRatio");
51
+ fetch(value).then((res) => res.blob()).then((blob) => {
52
+ if (blob.type.includes("svg")) {
53
+ options.set("noWebp", true);
54
+ }
55
+ });
56
+ if (value && (!aspectRatio || aspectRatio === DEFAULT_ASPECT_RATIO)) {
57
+ return loadImage(value).then((img) => {
58
+ const possiblyUpdatedAspectRatio = options.get("aspectRatio");
59
+ if (options.get("image") === value && (!possiblyUpdatedAspectRatio || possiblyUpdatedAspectRatio === DEFAULT_ASPECT_RATIO)) {
60
+ if (img.width && img.height) {
61
+ options.set("aspectRatio", round(img.height / img.width));
62
+ options.set("height", img.height);
63
+ options.set("width", img.width);
64
+ }
65
+ }
66
+ });
67
+ }
68
+ })
69
+ },
70
+ {
71
+ name: "backgroundSize",
72
+ type: "text",
73
+ defaultValue: "cover",
74
+ enum: [
75
+ {
76
+ label: "contain",
77
+ value: "contain",
78
+ helperText: "The image should never get cropped"
79
+ },
80
+ {
81
+ label: "cover",
82
+ value: "cover",
83
+ helperText: "The image should fill it's box, cropping when needed"
84
+ }
85
+ ]
86
+ },
87
+ {
88
+ name: "backgroundPosition",
89
+ type: "text",
90
+ defaultValue: "center",
91
+ enum: [
92
+ "center",
93
+ "top",
94
+ "left",
95
+ "right",
96
+ "bottom",
97
+ "top left",
98
+ "top right",
99
+ "bottom left",
100
+ "bottom right"
101
+ ]
102
+ },
103
+ {
104
+ name: "altText",
105
+ type: "string",
106
+ helperText: "Text to display when the user has images off"
107
+ },
108
+ {
109
+ name: "height",
110
+ type: "number",
111
+ hideFromUI: true
112
+ },
113
+ {
114
+ name: "width",
115
+ type: "number",
116
+ hideFromUI: true
117
+ },
118
+ {
119
+ name: "sizes",
120
+ type: "string",
121
+ hideFromUI: true
122
+ },
123
+ {
124
+ name: "srcset",
125
+ type: "string",
126
+ hideFromUI: true
127
+ },
128
+ {
129
+ name: "lazy",
130
+ type: "boolean",
131
+ defaultValue: true,
132
+ hideFromUI: true
133
+ },
134
+ {
135
+ name: "fitContent",
136
+ type: "boolean",
137
+ helperText: "When child blocks are provided, fit to them instead of using the image's aspect ratio",
138
+ defaultValue: true
139
+ },
140
+ {
141
+ name: "aspectRatio",
142
+ type: "number",
143
+ helperText: "This is the ratio of height/width, e.g. set to 1.5 for a 300px wide and 200px tall photo. Set to 0 to not force the image to maintain it's aspect ratio",
144
+ advanced: true,
145
+ defaultValue: 0.7041
146
+ }
147
+ ]
148
+ };
149
+ export {
150
+ componentInfo
151
+ };
@@ -0,0 +1,48 @@
1
+ function removeProtocol(path) {
2
+ return path.replace(/http(s)?:/, "");
3
+ }
4
+ function updateQueryParam(uri = "", key, value) {
5
+ const re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
6
+ const separator = uri.indexOf("?") !== -1 ? "&" : "?";
7
+ if (uri.match(re)) {
8
+ return uri.replace(re, "$1" + key + "=" + encodeURIComponent(value) + "$2");
9
+ }
10
+ return uri + separator + key + "=" + encodeURIComponent(value);
11
+ }
12
+ function getShopifyImageUrl(src, size) {
13
+ if (!src || !(src == null ? void 0 : src.match(/cdn\.shopify\.com/)) || !size) {
14
+ return src;
15
+ }
16
+ if (size === "master") {
17
+ return removeProtocol(src);
18
+ }
19
+ const match = src.match(/(_\d+x(\d+)?)?(\.(jpg|jpeg|gif|png|bmp|bitmap|tiff|tif)(\?v=\d+)?)/i);
20
+ if (match) {
21
+ const prefix = src.split(match[0]);
22
+ const suffix = match[3];
23
+ const useSize = size.match("x") ? size : `${size}x`;
24
+ return removeProtocol(`${prefix[0]}_${useSize}${suffix}`);
25
+ }
26
+ return null;
27
+ }
28
+ function getSrcSet(url) {
29
+ if (!url) {
30
+ return url;
31
+ }
32
+ const sizes = [100, 200, 400, 800, 1200, 1600, 2e3];
33
+ if (url.match(/builder\.io/)) {
34
+ let srcUrl = url;
35
+ const widthInSrc = Number(url.split("?width=")[1]);
36
+ if (!isNaN(widthInSrc)) {
37
+ srcUrl = `${srcUrl} ${widthInSrc}w`;
38
+ }
39
+ return sizes.filter((size) => size !== widthInSrc).map((size) => `${updateQueryParam(url, "width", size)} ${size}w`).concat([srcUrl]).join(", ");
40
+ }
41
+ if (url.match(/cdn\.shopify\.com/)) {
42
+ return sizes.map((size) => [getShopifyImageUrl(url, `${size}x${size}`), size]).filter(([sizeUrl]) => !!sizeUrl).map(([sizeUrl, size]) => `${sizeUrl} ${size}w`).concat([url]).join(", ");
43
+ }
44
+ return url;
45
+ }
46
+ export {
47
+ getSrcSet
48
+ };
@@ -0,0 +1,122 @@
1
+ import * as React from "react";
2
+ import { getSrcSet } from "./image.helpers.js";
3
+
4
+ export default function Image(props) {
5
+ const _context = { ...props["_context"] };
6
+
7
+ const state = {
8
+ get srcSetToUse() {
9
+ const imageToUse = props.image || props.src;
10
+ const url = imageToUse;
11
+ if (
12
+ !url ||
13
+ // We can auto add srcset for cdn.builder.io and shopify
14
+ // images, otherwise you can supply this prop manually
15
+ !(url.match(/builder\.io/) || url.match(/cdn\.shopify\.com/))
16
+ ) {
17
+ return props.srcset;
18
+ }
19
+ if (props.srcset && props.image?.includes("builder.io/api/v1/image")) {
20
+ if (!props.srcset.includes(props.image.split("?")[0])) {
21
+ console.debug("Removed given srcset");
22
+ return getSrcSet(url);
23
+ }
24
+ } else if (props.image && !props.srcset) {
25
+ return getSrcSet(url);
26
+ }
27
+ return getSrcSet(url);
28
+ },
29
+ get webpSrcSet() {
30
+ if (state.srcSetToUse?.match(/builder\.io/) && !props.noWebp) {
31
+ return state.srcSetToUse.replace(/\?/g, "?format=webp&");
32
+ } else {
33
+ return "";
34
+ }
35
+ },
36
+ get aspectRatioCss() {
37
+ const aspectRatioStyles = {
38
+ position: "absolute",
39
+ height: "100%",
40
+ width: "100%",
41
+ left: "0px",
42
+ top: "0px",
43
+ };
44
+ const out = props.aspectRatio ? aspectRatioStyles : undefined;
45
+ return out;
46
+ },
47
+ };
48
+
49
+ return (
50
+ <>
51
+ <>
52
+ <picture>
53
+ {state.webpSrcSet ? (
54
+ <>
55
+ <source type="image/webp" srcSet={state.webpSrcSet} />
56
+ </>
57
+ ) : null}
58
+
59
+ <img
60
+ loading="lazy"
61
+ alt={props.altText}
62
+ role={props.altText ? "presentation" : undefined}
63
+ style={{
64
+ objectPosition: props.backgroundPosition || "center",
65
+ objectFit: props.backgroundSize || "cover",
66
+ ...state.aspectRatioCss,
67
+ }}
68
+ className={
69
+ "builder-image" +
70
+ (props.className ? " " + props.className : "") +
71
+ " img-d6cf1f9c"
72
+ }
73
+ src={props.image}
74
+ srcSet={state.srcSetToUse}
75
+ sizes={props.sizes}
76
+ />
77
+ </picture>
78
+
79
+ {props.aspectRatio &&
80
+ !(props.builderBlock?.children?.length && props.fitContent) ? (
81
+ <>
82
+ <div
83
+ className="builder-image-sizer div-d6cf1f9c"
84
+ style={{
85
+ paddingTop:
86
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
87
+ props.aspectRatio * 100 + "%",
88
+ }}
89
+ />
90
+ </>
91
+ ) : null}
92
+
93
+ {props.builderBlock?.children?.length && props.fitContent ? (
94
+ <>{props.children}</>
95
+ ) : null}
96
+
97
+ {!props.fitContent && props.children ? (
98
+ <>
99
+ <div className="div-d6cf1f9c-2">{props.children}</div>
100
+ </>
101
+ ) : null}
102
+ </>
103
+ <style>{`.img-d6cf1f9c {
104
+ opacity: 1;
105
+ transition: opacity 0.2s ease-in-out;
106
+ }.div-d6cf1f9c {
107
+ width: 100%;
108
+ pointer-events: none;
109
+ font-size: 0;
110
+ }.div-d6cf1f9c-2 {
111
+ display: flex;
112
+ flex-direction: column;
113
+ align-items: stretch;
114
+ position: absolute;
115
+ top: 0;
116
+ left: 0;
117
+ width: 100%;
118
+ height: 100%;
119
+ }`}</style>
120
+ </>
121
+ );
122
+ }
@@ -0,0 +1,20 @@
1
+ const componentInfo = {
2
+ name: "Raw:Img",
3
+ hideFromInsertMenu: true,
4
+ builtIn: true,
5
+ 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",
6
+ inputs: [
7
+ {
8
+ name: "image",
9
+ bubble: true,
10
+ type: "file",
11
+ allowedFileTypes: ["jpeg", "jpg", "png", "svg"],
12
+ required: true
13
+ }
14
+ ],
15
+ noWrap: true,
16
+ static: true
17
+ };
18
+ export {
19
+ componentInfo
20
+ };
@@ -0,0 +1,19 @@
1
+ import * as React from "react";
2
+ import { isEditing } from "../../functions/is-editing.js";
3
+
4
+ export default function ImgComponent(props) {
5
+ const _context = { ...props["_context"] };
6
+
7
+ return (
8
+ <img
9
+ style={{
10
+ objectFit: props.backgroundSize || "cover",
11
+ objectPosition: props.backgroundPosition || "center",
12
+ }}
13
+ key={(isEditing() && props.imgSrc) || "default-key"}
14
+ alt={props.altText}
15
+ src={props.imgSrc || props.image}
16
+ {...props.attributes}
17
+ />
18
+ );
19
+ }