@builder.io/sdk-svelte 0.0.1-9 → 0.0.1

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 (359) hide show
  1. package/README.md +4 -0
  2. package/package/CHANGELOG.md +19 -0
  3. package/package/README.md +19 -0
  4. package/{src/types/builder-block.js → package/blocks/button/button.lite.d.ts} +0 -0
  5. package/package/blocks/button/button.lite.tsx +36 -0
  6. package/package/blocks/button/button.svelte +28 -0
  7. package/package/blocks/button/button.svelte.d.ts +25 -0
  8. package/package/blocks/button/component-info.d.ts +2 -0
  9. package/package/blocks/button/component-info.js +39 -0
  10. package/{src/types/builder-content.js → package/blocks/columns/columns.lite.d.ts} +0 -0
  11. package/package/blocks/columns/columns.lite.tsx +139 -0
  12. package/package/blocks/columns/columns.svelte +109 -0
  13. package/package/blocks/columns/columns.svelte.d.ts +33 -0
  14. package/package/blocks/columns/component-info.d.ts +2 -0
  15. package/package/blocks/columns/component-info.js +241 -0
  16. package/package/blocks/custom-code/component-info.d.ts +2 -0
  17. package/package/blocks/custom-code/component-info.js +28 -0
  18. package/{src/types/components.js → package/blocks/custom-code/custom-code.lite.d.ts} +0 -0
  19. package/package/blocks/custom-code/custom-code.lite.tsx +70 -0
  20. package/package/blocks/custom-code/custom-code.svelte +55 -0
  21. package/package/blocks/custom-code/custom-code.svelte.d.ts +21 -0
  22. package/package/blocks/embed/component-info.d.ts +2 -0
  23. package/package/blocks/embed/component-info.js +47 -0
  24. package/{src/types/deep-partial.js → package/blocks/embed/embed.lite.d.ts} +0 -0
  25. package/package/blocks/embed/embed.lite.tsx +52 -0
  26. package/package/blocks/embed/embed.svelte +41 -0
  27. package/package/blocks/embed/embed.svelte.d.ts +19 -0
  28. package/package/blocks/embed/helpers.d.ts +1 -0
  29. package/package/blocks/embed/helpers.js +6 -0
  30. package/package/blocks/form/component-info.d.ts +2 -0
  31. package/package/blocks/form/component-info.js +268 -0
  32. package/{src/types/element.js → package/blocks/form/form.lite.d.ts} +0 -0
  33. package/package/blocks/form/form.lite.tsx +351 -0
  34. package/package/blocks/form/form.svelte +259 -0
  35. package/package/blocks/form/form.svelte.d.ts +70 -0
  36. package/package/blocks/fragment/component-info.d.ts +2 -0
  37. package/package/blocks/fragment/component-info.js +8 -0
  38. package/{src/types/targets.js → package/blocks/fragment/fragment.lite.d.ts} +0 -0
  39. package/package/blocks/fragment/fragment.lite.tsx +12 -0
  40. package/package/blocks/fragment/fragment.svelte +5 -0
  41. package/package/blocks/fragment/fragment.svelte.d.ts +21 -0
  42. package/package/blocks/image/component-info.d.ts +2 -0
  43. package/package/blocks/image/component-info.js +153 -0
  44. package/package/blocks/image/image.helpers.d.ts +1 -0
  45. package/package/blocks/image/image.helpers.js +56 -0
  46. package/{src/types/typescript.js → package/blocks/image/image.lite.d.ts} +0 -0
  47. package/package/blocks/image/image.lite.tsx +148 -0
  48. package/package/blocks/image/image.svelte +119 -0
  49. package/package/blocks/image/image.svelte.d.ts +48 -0
  50. package/package/blocks/img/component-info.d.ts +2 -0
  51. package/package/blocks/img/component-info.js +18 -0
  52. package/package/blocks/img/img.lite.d.ts +0 -0
  53. package/package/blocks/img/img.lite.tsx +48 -0
  54. package/package/blocks/img/img.svelte +26 -0
  55. package/package/blocks/img/img.svelte.d.ts +29 -0
  56. package/package/blocks/input/component-info.d.ts +2 -0
  57. package/package/blocks/input/component-info.js +72 -0
  58. package/package/blocks/input/input.lite.d.ts +0 -0
  59. package/package/blocks/input/input.lite.tsx +34 -0
  60. package/package/blocks/input/input.svelte +22 -0
  61. package/package/blocks/input/input.svelte.d.ts +31 -0
  62. package/package/blocks/raw-text/component-info.d.ts +2 -0
  63. package/package/blocks/raw-text/component-info.js +13 -0
  64. package/package/blocks/raw-text/raw-text.lite.d.ts +0 -0
  65. package/package/blocks/raw-text/raw-text.lite.tsx +15 -0
  66. package/package/blocks/raw-text/raw-text.svelte +9 -0
  67. package/package/blocks/raw-text/raw-text.svelte.d.ts +21 -0
  68. package/package/blocks/section/component-info.d.ts +2 -0
  69. package/package/blocks/section/component-info.js +46 -0
  70. package/package/blocks/section/section.lite.d.ts +0 -0
  71. package/package/blocks/section/section.lite.tsx +30 -0
  72. package/package/blocks/section/section.svelte +21 -0
  73. package/package/blocks/section/section.svelte.d.ts +25 -0
  74. package/package/blocks/select/component-info.d.ts +2 -0
  75. package/package/blocks/select/component-info.js +56 -0
  76. package/package/blocks/select/select.lite.d.ts +0 -0
  77. package/package/blocks/select/select.lite.tsx +34 -0
  78. package/package/blocks/select/select.svelte +21 -0
  79. package/package/blocks/select/select.svelte.d.ts +30 -0
  80. package/package/blocks/submit-button/component-info.d.ts +2 -0
  81. package/package/blocks/submit-button/component-info.js +29 -0
  82. package/package/blocks/submit-button/submit-button.lite.d.ts +0 -0
  83. package/package/blocks/submit-button/submit-button.lite.tsx +15 -0
  84. package/package/blocks/submit-button/submit-button.svelte +9 -0
  85. package/package/blocks/submit-button/submit-button.svelte.d.ts +21 -0
  86. package/package/blocks/symbol/component-info.d.ts +2 -0
  87. package/package/blocks/symbol/component-info.js +40 -0
  88. package/package/blocks/symbol/symbol.lite.d.ts +0 -0
  89. package/package/blocks/symbol/symbol.lite.tsx +92 -0
  90. package/package/blocks/symbol/symbol.svelte +66 -0
  91. package/package/blocks/symbol/symbol.svelte.d.ts +35 -0
  92. package/package/blocks/text/component-info.d.ts +2 -0
  93. package/package/blocks/text/component-info.js +21 -0
  94. package/package/blocks/text/text.lite.d.ts +0 -0
  95. package/package/blocks/text/text.lite.tsx +11 -0
  96. package/package/blocks/text/text.svelte +6 -0
  97. package/package/blocks/text/text.svelte.d.ts +19 -0
  98. package/package/blocks/textarea/component-info.d.ts +2 -0
  99. package/package/blocks/textarea/component-info.js +44 -0
  100. package/package/blocks/textarea/textarea.lite.d.ts +0 -0
  101. package/package/blocks/textarea/textarea.lite.tsx +19 -0
  102. package/package/blocks/textarea/textarea.svelte +10 -0
  103. package/package/blocks/textarea/textarea.svelte.d.ts +27 -0
  104. package/package/blocks/util.d.ts +1 -0
  105. package/package/blocks/util.js +4 -0
  106. package/package/blocks/video/component-info.d.ts +2 -0
  107. package/package/blocks/video/component-info.js +103 -0
  108. package/package/blocks/video/video.lite.d.ts +0 -0
  109. package/package/blocks/video/video.lite.tsx +92 -0
  110. package/package/blocks/video/video.svelte +63 -0
  111. package/package/blocks/video/video.svelte.d.ts +41 -0
  112. package/package/components/render-block/block-styles.lite.d.ts +0 -0
  113. package/package/components/render-block/block-styles.lite.tsx +60 -0
  114. package/package/components/render-block/block-styles.svelte +45 -0
  115. package/package/components/render-block/block-styles.svelte.d.ts +23 -0
  116. package/package/components/render-block/render-block.helpers.d.ts +1 -0
  117. package/package/components/render-block/render-block.helpers.js +24 -0
  118. package/package/components/render-block/render-block.lite.d.ts +0 -0
  119. package/package/components/render-block/render-block.lite.tsx +216 -0
  120. package/package/components/render-block/render-block.svelte +185 -0
  121. package/package/components/render-block/render-block.svelte.d.ts +23 -0
  122. package/package/components/render-block/render-component.lite.d.ts +0 -0
  123. package/package/components/render-block/render-component.lite.tsx +33 -0
  124. package/package/components/render-block/render-component.svelte +24 -0
  125. package/package/components/render-block/render-component.svelte.d.ts +27 -0
  126. package/package/components/render-block/render-repeated-block.lite.d.ts +0 -0
  127. package/package/components/render-block/render-repeated-block.lite.tsx +49 -0
  128. package/package/components/render-block/render-repeated-block.svelte +36 -0
  129. package/package/components/render-block/render-repeated-block.svelte.d.ts +23 -0
  130. package/package/components/render-block/types.d.ts +6 -0
  131. package/package/components/render-block/types.js +2 -0
  132. package/package/components/render-blocks.lite.d.ts +0 -0
  133. package/package/components/render-blocks.lite.tsx +91 -0
  134. package/package/components/render-blocks.svelte +73 -0
  135. package/package/components/render-blocks.svelte.d.ts +24 -0
  136. package/package/components/render-content/components/render-styles.lite.d.ts +0 -0
  137. package/package/components/render-content/components/render-styles.lite.tsx +86 -0
  138. package/package/components/render-content/components/render-styles.svelte +61 -0
  139. package/package/components/render-content/components/render-styles.svelte.d.ts +29 -0
  140. package/package/components/render-content/index.d.ts +1 -0
  141. package/package/components/render-content/index.js +1 -0
  142. package/package/components/render-content/render-content.lite.d.ts +0 -0
  143. package/package/components/render-content/render-content.lite.tsx +356 -0
  144. package/package/components/render-content/render-content.svelte +260 -0
  145. package/package/components/render-content/render-content.svelte.d.ts +36 -0
  146. package/package/components/render-inlined-styles.lite.d.ts +0 -0
  147. package/package/components/render-inlined-styles.lite.tsx +27 -0
  148. package/package/components/render-inlined-styles.svelte +19 -0
  149. package/package/components/render-inlined-styles.svelte.d.ts +19 -0
  150. package/package/constants/builder-registered-components.d.ts +6 -0
  151. package/package/constants/builder-registered-components.js +36 -0
  152. package/package/constants/device-sizes.d.ts +2 -0
  153. package/package/constants/device-sizes.js +18 -0
  154. package/package/constants/target.d.ts +2 -0
  155. package/package/constants/target.js +2 -0
  156. package/package/context/builder.context.d.ts +11 -0
  157. package/package/context/builder.context.js +11 -0
  158. package/package/context/types.d.ts +16 -0
  159. package/package/context/types.js +3 -0
  160. package/package/functions/camel-to-kebab-case.d.ts +1 -0
  161. package/package/functions/camel-to-kebab-case.js +1 -0
  162. package/package/functions/convert-style-object.d.ts +1 -0
  163. package/package/functions/convert-style-object.js +3 -0
  164. package/package/functions/evaluate.d.ts +5 -0
  165. package/package/functions/evaluate.js +25 -0
  166. package/package/functions/event-handler-name.d.ts +1 -0
  167. package/package/functions/event-handler-name.js +4 -0
  168. package/package/functions/get-block-actions.d.ts +9 -0
  169. package/package/functions/get-block-actions.js +21 -0
  170. package/package/functions/get-block-component-options.d.ts +2 -0
  171. package/package/functions/get-block-component-options.js +11 -0
  172. package/package/functions/get-block-properties.d.ts +5 -0
  173. package/package/functions/get-block-properties.js +10 -0
  174. package/package/functions/get-block-styles.d.ts +2 -0
  175. package/package/functions/get-block-styles.js +21 -0
  176. package/package/functions/get-block-tag.d.ts +10 -0
  177. package/package/functions/get-block-tag.js +9 -0
  178. package/package/functions/get-builder-search-params/fn.test.d.ts +1 -0
  179. package/package/functions/get-builder-search-params/fn.test.js +13 -0
  180. package/package/functions/get-builder-search-params/index.d.ts +6 -0
  181. package/package/functions/get-builder-search-params/index.js +29 -0
  182. package/package/functions/get-content/ab-testing.d.ts +3 -0
  183. package/package/functions/get-content/ab-testing.js +40 -0
  184. package/package/functions/get-content/fn.test.d.ts +1 -0
  185. package/package/functions/get-content/fn.test.js +31 -0
  186. package/package/functions/get-content/index.d.ts +9 -0
  187. package/package/functions/get-content/index.js +42 -0
  188. package/package/functions/get-content/types.d.ts +26 -0
  189. package/package/functions/get-content/types.js +1 -0
  190. package/package/functions/get-fetch.d.ts +1 -0
  191. package/package/functions/get-fetch.js +9 -0
  192. package/package/functions/get-global-this.d.ts +1 -0
  193. package/package/functions/get-global-this.js +15 -0
  194. package/package/functions/get-processed-block.d.ts +10 -0
  195. package/package/functions/get-processed-block.js +29 -0
  196. package/package/functions/get-processed-block.test.d.ts +1 -0
  197. package/package/functions/get-processed-block.test.js +32 -0
  198. package/package/functions/if-target.d.ts +7 -0
  199. package/package/functions/if-target.js +10 -0
  200. package/package/functions/is-browser.d.ts +1 -0
  201. package/package/functions/is-browser.js +3 -0
  202. package/package/functions/is-editing.d.ts +1 -0
  203. package/package/functions/is-editing.js +4 -0
  204. package/package/functions/is-iframe.d.ts +1 -0
  205. package/package/functions/is-iframe.js +4 -0
  206. package/package/functions/is-previewing.d.ts +1 -0
  207. package/package/functions/is-previewing.js +11 -0
  208. package/package/functions/mark-mutable.d.ts +2 -0
  209. package/package/functions/mark-mutable.js +6 -0
  210. package/package/functions/on-change.d.ts +7 -0
  211. package/package/functions/on-change.js +28 -0
  212. package/package/functions/on-change.test.d.ts +1 -0
  213. package/package/functions/on-change.test.js +20 -0
  214. package/package/functions/register-component.d.ts +14 -0
  215. package/package/functions/register-component.js +42 -0
  216. package/package/functions/register.d.ts +16 -0
  217. package/package/functions/register.js +29 -0
  218. package/package/functions/sanitize-styles.d.ts +4 -0
  219. package/package/functions/sanitize-styles.js +6 -0
  220. package/package/functions/set-editor-settings.d.ts +4 -0
  221. package/package/functions/set-editor-settings.js +12 -0
  222. package/package/functions/set.d.ts +7 -0
  223. package/package/functions/set.js +21 -0
  224. package/package/functions/set.test.d.ts +1 -0
  225. package/package/functions/set.test.js +16 -0
  226. package/package/functions/track.d.ts +21 -0
  227. package/package/functions/track.js +49 -0
  228. package/package/functions/transform-block.d.ts +2 -0
  229. package/package/functions/transform-block.js +5 -0
  230. package/package/helpers/cookie.d.ts +9 -0
  231. package/package/helpers/cookie.js +55 -0
  232. package/package/helpers/css.d.ts +1 -0
  233. package/package/helpers/css.js +9 -0
  234. package/package/helpers/flatten.d.ts +6 -0
  235. package/package/helpers/flatten.js +19 -0
  236. package/package/helpers/localStorage.d.ts +9 -0
  237. package/package/helpers/localStorage.js +23 -0
  238. package/package/helpers/nullable.d.ts +2 -0
  239. package/package/helpers/nullable.js +1 -0
  240. package/package/helpers/sessionId.d.ts +7 -0
  241. package/package/helpers/sessionId.js +20 -0
  242. package/package/helpers/time.d.ts +1 -0
  243. package/package/helpers/time.js +2 -0
  244. package/package/helpers/url.d.ts +6 -0
  245. package/package/helpers/url.js +12 -0
  246. package/package/helpers/url.test.d.ts +1 -0
  247. package/package/helpers/url.test.js +15 -0
  248. package/package/helpers/uuid.d.ts +8 -0
  249. package/package/helpers/uuid.js +15 -0
  250. package/package/helpers/visitorId.d.ts +8 -0
  251. package/package/helpers/visitorId.js +26 -0
  252. package/package/index-helpers/blocks-exports.d.ts +10 -0
  253. package/package/index-helpers/blocks-exports.js +10 -0
  254. package/package/index-helpers/top-of-file.d.ts +1 -0
  255. package/package/index-helpers/top-of-file.js +4 -0
  256. package/package/index.d.ts +10 -0
  257. package/package/index.js +10 -0
  258. package/package/scripts/init-editing.d.ts +2 -0
  259. package/package/scripts/init-editing.js +84 -0
  260. package/package/types/builder-block.d.ts +57 -0
  261. package/package/types/builder-block.js +1 -0
  262. package/package/types/builder-content.d.ts +38 -0
  263. package/package/types/builder-content.js +1 -0
  264. package/package/types/can-track.d.ts +3 -0
  265. package/package/types/can-track.js +1 -0
  266. package/package/types/components.d.ts +177 -0
  267. package/package/types/components.js +1 -0
  268. package/package/types/deep-partial.d.ts +3 -0
  269. package/package/types/deep-partial.js +1 -0
  270. package/package/types/element.d.ts +59 -0
  271. package/package/types/element.js +1 -0
  272. package/package/types/targets.d.ts +3 -0
  273. package/package/types/targets.js +1 -0
  274. package/package/types/typescript.d.ts +4 -0
  275. package/package/types/typescript.js +1 -0
  276. package/package.json +31 -8
  277. package/src/blocks/button/button.svelte +0 -49
  278. package/src/blocks/button/component-info.js +0 -41
  279. package/src/blocks/columns/columns.svelte +0 -103
  280. package/src/blocks/columns/component-info.js +0 -217
  281. package/src/blocks/custom-code/component-info.js +0 -31
  282. package/src/blocks/custom-code/custom-code.svelte +0 -64
  283. package/src/blocks/embed/component-info.js +0 -24
  284. package/src/blocks/embed/embed.svelte +0 -63
  285. package/src/blocks/form/component-info.js +0 -262
  286. package/src/blocks/form/form.svelte +0 -333
  287. package/src/blocks/fragment/component-info.js +0 -11
  288. package/src/blocks/fragment/fragment.svelte +0 -28
  289. package/src/blocks/image/component-info.js +0 -104
  290. package/src/blocks/image/image.svelte +0 -117
  291. package/src/blocks/img/component-info.js +0 -20
  292. package/src/blocks/img/img.svelte +0 -36
  293. package/src/blocks/input/component-info.js +0 -74
  294. package/src/blocks/input/input.svelte +0 -35
  295. package/src/blocks/raw-text/component-info.js +0 -16
  296. package/src/blocks/raw-text/raw-text.svelte +0 -29
  297. package/src/blocks/section/component-info.js +0 -49
  298. package/src/blocks/section/section.svelte +0 -36
  299. package/src/blocks/select/component-info.js +0 -59
  300. package/src/blocks/select/select.svelte +0 -41
  301. package/src/blocks/submit-button/component-info.js +0 -28
  302. package/src/blocks/submit-button/submit-button.svelte +0 -33
  303. package/src/blocks/symbol/component-info.js +0 -42
  304. package/src/blocks/symbol/symbol.svelte +0 -54
  305. package/src/blocks/text/component-info.js +0 -24
  306. package/src/blocks/text/text.svelte +0 -28
  307. package/src/blocks/textarea/component-info.js +0 -47
  308. package/src/blocks/textarea/textarea.svelte +0 -32
  309. package/src/blocks/video/component-info.js +0 -106
  310. package/src/blocks/video/video.svelte +0 -45
  311. package/src/components/error-boundary.svelte +0 -26
  312. package/src/components/render-block/block-styles.svelte +0 -51
  313. package/src/components/render-block/render-block.helpers.js +0 -23
  314. package/src/components/render-block/render-block.svelte +0 -174
  315. package/src/components/render-blocks.svelte +0 -82
  316. package/src/components/render-content/components/render-styles.svelte +0 -90
  317. package/src/components/render-content/index.js +0 -4
  318. package/src/components/render-content/render-content.svelte +0 -252
  319. package/src/components/render-inlined-styles.svelte +0 -51
  320. package/src/constants/builder-registered-components.js +0 -45
  321. package/src/constants/device-sizes.js +0 -39
  322. package/src/constants/target.js +0 -4
  323. package/src/context/builder.context.js +0 -8
  324. package/src/functions/evaluate.js +0 -28
  325. package/src/functions/event-handler-name.js +0 -7
  326. package/src/functions/fast-clone.js +0 -4
  327. package/src/functions/get-block-actions.js +0 -23
  328. package/src/functions/get-block-component-options.js +0 -23
  329. package/src/functions/get-block-properties.js +0 -29
  330. package/src/functions/get-block-styles.js +0 -31
  331. package/src/functions/get-block-tag.js +0 -6
  332. package/src/functions/get-builder-search-params/fn.test.js +0 -13
  333. package/src/functions/get-builder-search-params/index.js +0 -22
  334. package/src/functions/get-content/fn.test.js +0 -31
  335. package/src/functions/get-content/index.js +0 -138
  336. package/src/functions/get-fetch.js +0 -34
  337. package/src/functions/get-global-this.js +0 -18
  338. package/src/functions/get-processed-block.js +0 -46
  339. package/src/functions/get-processed-block.test.js +0 -31
  340. package/src/functions/if-target.js +0 -15
  341. package/src/functions/is-browser.js +0 -6
  342. package/src/functions/is-editing.js +0 -7
  343. package/src/functions/is-iframe.js +0 -7
  344. package/src/functions/is-previewing.js +0 -14
  345. package/src/functions/macro-eval.js +0 -5
  346. package/src/functions/on-change.js +0 -27
  347. package/src/functions/on-change.test.js +0 -19
  348. package/src/functions/previewing-model-name.js +0 -11
  349. package/src/functions/register-component.js +0 -70
  350. package/src/functions/register.js +0 -29
  351. package/src/functions/set-editor-settings.js +0 -15
  352. package/src/functions/set.js +0 -11
  353. package/src/functions/set.test.js +0 -16
  354. package/src/functions/track.js +0 -22
  355. package/src/functions/transform-block.js +0 -6
  356. package/src/index-helpers/blocks-exports.js +0 -20
  357. package/src/index-helpers/top-of-file.js +0 -4
  358. package/src/index.js +0 -10
  359. package/src/scripts/init-editing.js +0 -80
@@ -0,0 +1,216 @@
1
+ <script context="module" lang="ts">
2
+ export type RenderBlockProps = {
3
+ block: BuilderBlock;
4
+ context: BuilderContextInterface;
5
+ }; // eslint-disable-next-line @builder.io/mitosis/only-default-function-and-imports
6
+ </script>
7
+
8
+ <script lang="ts">
9
+ import {
10
+ BuilderContextInterface,
11
+ RegisteredComponent,
12
+ } from "../../context/types.js";
13
+ import { getBlockActions } from "../../functions/get-block-actions.js";
14
+ import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
15
+ import { getBlockProperties } from "../../functions/get-block-properties.js";
16
+ import { getBlockStyles } from "../../functions/get-block-styles.js";
17
+ import { getBlockTag } from "../../functions/get-block-tag.js";
18
+ import { getProcessedBlock } from "../../functions/get-processed-block.js";
19
+ import { BuilderBlock } from "../../types/builder-block.js";
20
+ import { Nullable } from "../../types/typescript.js";
21
+ import { evaluate } from "../../functions/evaluate.js";
22
+ import BlockStyles from "./block-styles.svelte";
23
+ import { isEmptyHtmlElement } from "./render-block.helpers.js";
24
+ import RenderComponent, {
25
+ RenderComponentProps,
26
+ } from "./render-component.svelte";
27
+ import { RepeatData } from "./types.js";
28
+ import RenderRepeatedBlock from "./render-repeated-block.svelte";
29
+
30
+ export let block: RenderBlockProps["block"];
31
+ export let context: RenderBlockProps["context"];
32
+
33
+ $: component = () => {
34
+ const componentName = getProcessedBlock({
35
+ block: block,
36
+ state: context.state,
37
+ context: context.context,
38
+ shouldEvaluateBindings: false,
39
+ }).component?.name;
40
+
41
+ if (!componentName) {
42
+ return null;
43
+ }
44
+
45
+ const ref = context.registeredComponents[componentName];
46
+
47
+ if (!ref) {
48
+ // TODO: Public doc page with more info about this message
49
+ console.warn(`
50
+ Could not find a registered component named "${componentName}".
51
+ If you registered it, is the file that registered it imported by the file that needs to render it?`);
52
+ return undefined;
53
+ } else {
54
+ return ref;
55
+ }
56
+ };
57
+
58
+ $: componentInfo = () => {
59
+ if (component()) {
60
+ const { component: _, ...info } = component();
61
+ return info;
62
+ } else {
63
+ return undefined;
64
+ }
65
+ };
66
+
67
+ $: componentRef = () => {
68
+ return component?.()?.component;
69
+ };
70
+
71
+ $: tagName = () => {
72
+ return getBlockTag(useBlock());
73
+ };
74
+
75
+ $: useBlock = () => {
76
+ return repeatItemData()
77
+ ? block
78
+ : getProcessedBlock({
79
+ block: block,
80
+ state: context.state,
81
+ context: context.context,
82
+ shouldEvaluateBindings: true,
83
+ });
84
+ };
85
+
86
+ $: attributes = () => {
87
+ return {
88
+ ...getBlockProperties(useBlock()),
89
+ ...getBlockActions({
90
+ block: useBlock(),
91
+ state: context.state,
92
+ context: context.context,
93
+ }),
94
+ style: getBlockStyles(useBlock()),
95
+ };
96
+ };
97
+
98
+ $: shouldWrap = () => {
99
+ return !componentInfo?.()?.noWrap;
100
+ };
101
+
102
+ $: componentOptions = () => {
103
+ return {
104
+ ...getBlockComponentOptions(useBlock()),
105
+
106
+ /**
107
+ * These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
108
+ * they are provided to the component itself directly.
109
+ */
110
+ ...(shouldWrap()
111
+ ? {}
112
+ : {
113
+ attributes: attributes(),
114
+ }),
115
+ };
116
+ };
117
+
118
+ $: renderComponentProps = () => {
119
+ return {
120
+ blockChildren: children(),
121
+ componentRef: componentRef(),
122
+ componentOptions: componentOptions(),
123
+ context: context,
124
+ };
125
+ };
126
+
127
+ $: children = () => {
128
+ // TO-DO: When should `canHaveChildren` dictate rendering?
129
+ // This is currently commented out because some Builder components (e.g. Box) do not have `canHaveChildren: true`,
130
+ // but still receive and need to render children.
131
+ // return componentInfo?.()?.canHaveChildren ? useBlock().children : [];
132
+ return useBlock().children ?? [];
133
+ };
134
+
135
+ $: childrenWithoutParentComponent = () => {
136
+ /**
137
+ * When there is no `componentRef`, there might still be children that need to be rendered. In this case,
138
+ * we render them outside of `componentRef`.
139
+ * NOTE: We make sure not to render this if `repeatItemData` is non-null, because that means we are rendering an array of
140
+ * blocks, and the children will be repeated within those blocks.
141
+ */
142
+ const shouldRenderChildrenOutsideRef = !componentRef() && !repeatItemData();
143
+ return shouldRenderChildrenOutsideRef ? children() : [];
144
+ };
145
+
146
+ $: repeatItemData = () => {
147
+ /**
148
+ * we don't use `useBlock()` here because the processing done within its logic includes evaluating the block's bindings,
149
+ * which will not work if there is a repeat.
150
+ */
151
+ const { repeat, ...blockWithoutRepeat } = block;
152
+
153
+ if (!repeat?.collection) {
154
+ return undefined;
155
+ }
156
+
157
+ const itemsArray = evaluate({
158
+ code: repeat.collection,
159
+ state: context.state,
160
+ context: context.context,
161
+ });
162
+
163
+ if (!Array.isArray(itemsArray)) {
164
+ return undefined;
165
+ }
166
+
167
+ const collectionName = repeat.collection.split(".").pop();
168
+ const itemNameToUse =
169
+ repeat.itemName || (collectionName ? collectionName + "Item" : "item");
170
+ const repeatArray = itemsArray.map((item, index) => ({
171
+ context: {
172
+ ...context,
173
+ state: {
174
+ ...context.state,
175
+ $index: index,
176
+ $item: item,
177
+ [itemNameToUse]: item,
178
+ [`$${itemNameToUse}Index`]: index,
179
+ },
180
+ },
181
+ block: blockWithoutRepeat,
182
+ }));
183
+ return repeatArray;
184
+ };
185
+ </script>
186
+
187
+ {#if shouldWrap()}
188
+ {#if !isEmptyHtmlElement(tagName())}
189
+ <svelte:element this={tagName()} {...attributes()}>
190
+ {#if repeatItemData()}
191
+ {#each repeatItemData() as data, index (index)}
192
+ <RenderRepeatedBlock
193
+ repeatContext={data.context}
194
+ block={data.block}
195
+ />
196
+ {/each}
197
+ {/if}
198
+
199
+ {#if !repeatItemData()}
200
+ <RenderComponent {...renderComponentProps()} />
201
+ {/if}
202
+
203
+ {#each childrenWithoutParentComponent() as child ("render-block-" + child.id)}
204
+ <svelte:self block={child} {context} />
205
+ {/each}
206
+
207
+ {#each childrenWithoutParentComponent() as child ("block-style-" + child.id)}
208
+ <BlockStyles block={child} {context} />
209
+ {/each}
210
+ </svelte:element>
211
+ {:else}
212
+ <svelte:element this={tagName()} {...attributes()} />
213
+ {/if}
214
+ {:else}
215
+ <RenderComponent {...renderComponentProps()} {context} />
216
+ {/if}
@@ -0,0 +1,185 @@
1
+ <script context="module"></script>
2
+
3
+ <script>import "../../context/types.js";
4
+ import { getBlockActions } from "../../functions/get-block-actions.js";
5
+ import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
6
+ import { getBlockProperties } from "../../functions/get-block-properties.js";
7
+ import { getBlockStyles } from "../../functions/get-block-styles.js";
8
+ import { getBlockTag } from "../../functions/get-block-tag.js";
9
+ import { getProcessedBlock } from "../../functions/get-processed-block.js";
10
+ import "../../types/builder-block.js";
11
+ import "../../types/typescript.js";
12
+ import { evaluate } from "../../functions/evaluate.js";
13
+ import BlockStyles from "./block-styles.svelte";
14
+ import { isEmptyHtmlElement } from "./render-block.helpers.js";
15
+ import RenderComponent from "./render-component.svelte";
16
+ import "./types.js";
17
+ import RenderRepeatedBlock from "./render-repeated-block.svelte";
18
+ export let block;
19
+ export let context;
20
+ $: component = () => {
21
+ const componentName = getProcessedBlock({
22
+ block: block,
23
+ state: context.state,
24
+ context: context.context,
25
+ shouldEvaluateBindings: false,
26
+ }).component?.name;
27
+ if (!componentName) {
28
+ return null;
29
+ }
30
+ const ref = context.registeredComponents[componentName];
31
+ if (!ref) {
32
+ // TODO: Public doc page with more info about this message
33
+ console.warn(`
34
+ Could not find a registered component named "${componentName}".
35
+ If you registered it, is the file that registered it imported by the file that needs to render it?`);
36
+ return undefined;
37
+ }
38
+ else {
39
+ return ref;
40
+ }
41
+ };
42
+ $: componentInfo = () => {
43
+ if (component()) {
44
+ const { component: _, ...info } = component();
45
+ return info;
46
+ }
47
+ else {
48
+ return undefined;
49
+ }
50
+ };
51
+ $: componentRef = () => {
52
+ return component?.()?.component;
53
+ };
54
+ $: tagName = () => {
55
+ return getBlockTag(useBlock());
56
+ };
57
+ $: useBlock = () => {
58
+ return repeatItemData()
59
+ ? block
60
+ : getProcessedBlock({
61
+ block: block,
62
+ state: context.state,
63
+ context: context.context,
64
+ shouldEvaluateBindings: true,
65
+ });
66
+ };
67
+ $: attributes = () => {
68
+ return {
69
+ ...getBlockProperties(useBlock()),
70
+ ...getBlockActions({
71
+ block: useBlock(),
72
+ state: context.state,
73
+ context: context.context,
74
+ }),
75
+ style: getBlockStyles(useBlock()),
76
+ };
77
+ };
78
+ $: shouldWrap = () => {
79
+ return !componentInfo?.()?.noWrap;
80
+ };
81
+ $: componentOptions = () => {
82
+ return {
83
+ ...getBlockComponentOptions(useBlock()),
84
+ /**
85
+ * These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
86
+ * they are provided to the component itself directly.
87
+ */
88
+ ...(shouldWrap()
89
+ ? {}
90
+ : {
91
+ attributes: attributes(),
92
+ }),
93
+ };
94
+ };
95
+ $: renderComponentProps = () => {
96
+ return {
97
+ blockChildren: children(),
98
+ componentRef: componentRef(),
99
+ componentOptions: componentOptions(),
100
+ context: context,
101
+ };
102
+ };
103
+ $: children = () => {
104
+ // TO-DO: When should `canHaveChildren` dictate rendering?
105
+ // This is currently commented out because some Builder components (e.g. Box) do not have `canHaveChildren: true`,
106
+ // but still receive and need to render children.
107
+ // return componentInfo?.()?.canHaveChildren ? useBlock().children : [];
108
+ return useBlock().children ?? [];
109
+ };
110
+ $: childrenWithoutParentComponent = () => {
111
+ /**
112
+ * When there is no `componentRef`, there might still be children that need to be rendered. In this case,
113
+ * we render them outside of `componentRef`.
114
+ * NOTE: We make sure not to render this if `repeatItemData` is non-null, because that means we are rendering an array of
115
+ * blocks, and the children will be repeated within those blocks.
116
+ */
117
+ const shouldRenderChildrenOutsideRef = !componentRef() && !repeatItemData();
118
+ return shouldRenderChildrenOutsideRef ? children() : [];
119
+ };
120
+ $: repeatItemData = () => {
121
+ /**
122
+ * we don't use `useBlock()` here because the processing done within its logic includes evaluating the block's bindings,
123
+ * which will not work if there is a repeat.
124
+ */
125
+ const { repeat, ...blockWithoutRepeat } = block;
126
+ if (!repeat?.collection) {
127
+ return undefined;
128
+ }
129
+ const itemsArray = evaluate({
130
+ code: repeat.collection,
131
+ state: context.state,
132
+ context: context.context,
133
+ });
134
+ if (!Array.isArray(itemsArray)) {
135
+ return undefined;
136
+ }
137
+ const collectionName = repeat.collection.split(".").pop();
138
+ const itemNameToUse = repeat.itemName || (collectionName ? collectionName + "Item" : "item");
139
+ const repeatArray = itemsArray.map((item, index) => ({
140
+ context: {
141
+ ...context,
142
+ state: {
143
+ ...context.state,
144
+ $index: index,
145
+ $item: item,
146
+ [itemNameToUse]: item,
147
+ [`$${itemNameToUse}Index`]: index,
148
+ },
149
+ },
150
+ block: blockWithoutRepeat,
151
+ }));
152
+ return repeatArray;
153
+ };
154
+ </script>
155
+
156
+ {#if shouldWrap()}
157
+ {#if !isEmptyHtmlElement(tagName())}
158
+ <svelte:element this={tagName()} {...attributes()}>
159
+ {#if repeatItemData()}
160
+ {#each repeatItemData() as data, index (index)}
161
+ <RenderRepeatedBlock
162
+ repeatContext={data.context}
163
+ block={data.block}
164
+ />
165
+ {/each}
166
+ {/if}
167
+
168
+ {#if !repeatItemData()}
169
+ <RenderComponent {...renderComponentProps()} />
170
+ {/if}
171
+
172
+ {#each childrenWithoutParentComponent() as child ("render-block-" + child.id)}
173
+ <svelte:self block={child} {context} />
174
+ {/each}
175
+
176
+ {#each childrenWithoutParentComponent() as child ("block-style-" + child.id)}
177
+ <BlockStyles block={child} {context} />
178
+ {/each}
179
+ </svelte:element>
180
+ {:else}
181
+ <svelte:element this={tagName()} {...attributes()} />
182
+ {/if}
183
+ {:else}
184
+ <RenderComponent {...renderComponentProps()} {context} />
185
+ {/if}
@@ -0,0 +1,23 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ export declare type RenderBlockProps = {
3
+ block: BuilderBlock;
4
+ context: BuilderContextInterface;
5
+ };
6
+ import { BuilderContextInterface } from "../../context/types.js";
7
+ import { BuilderBlock } from "../../types/builder-block.js";
8
+ declare const __propDef: {
9
+ props: {
10
+ block: RenderBlockProps["block"];
11
+ context: RenderBlockProps["context"];
12
+ };
13
+ events: {
14
+ [evt: string]: CustomEvent<any>;
15
+ };
16
+ slots: {};
17
+ };
18
+ export declare type RenderBlockProps = typeof __propDef.props;
19
+ export declare type RenderBlockEvents = typeof __propDef.events;
20
+ export declare type RenderBlockSlots = typeof __propDef.slots;
21
+ export default class RenderBlock extends SvelteComponentTyped<RenderBlockProps, RenderBlockEvents, RenderBlockSlots> {
22
+ }
23
+ export {};
@@ -0,0 +1,33 @@
1
+ <script context="module" lang="ts">
2
+ export interface RenderComponentProps {
3
+ componentRef: any;
4
+ componentOptions: any;
5
+ blockChildren: BuilderBlock[];
6
+ context: BuilderContextInterface;
7
+ } // eslint-disable-next-line @builder.io/mitosis/only-default-function-and-imports
8
+ </script>
9
+
10
+ <script lang="ts">
11
+ import { BuilderBlock } from "../../types/builder-block.js";
12
+ import BlockStyles from "./block-styles.svelte";
13
+ import RenderBlock from "./render-block.svelte";
14
+ import { BuilderContextInterface } from "../../context/types.js";
15
+ import { markPropsMutable } from "../../functions/mark-mutable.js";
16
+
17
+ export let componentRef: RenderComponentProps["componentRef"];
18
+ export let componentOptions: RenderComponentProps["componentOptions"];
19
+ export let blockChildren: RenderComponentProps["blockChildren"];
20
+ export let context: RenderComponentProps["context"];
21
+ </script>
22
+
23
+ {#if componentRef}
24
+ <svelte:component this={componentRef} {...markPropsMutable(componentOptions)}>
25
+ {#each blockChildren as child ("render-block-" + child.id)}
26
+ <RenderBlock block={child} {context} />
27
+ {/each}
28
+
29
+ {#each blockChildren as child ("block-style-" + child.id)}
30
+ <BlockStyles block={child} {context} />
31
+ {/each}
32
+ </svelte:component>
33
+ {/if}
@@ -0,0 +1,24 @@
1
+ <script context="module"></script>
2
+
3
+ <script>import "../../types/builder-block.js";
4
+ import BlockStyles from "./block-styles.svelte";
5
+ import RenderBlock from "./render-block.svelte";
6
+ import "../../context/types.js";
7
+ import { markPropsMutable } from "../../functions/mark-mutable.js";
8
+ export let componentRef;
9
+ export let componentOptions;
10
+ export let blockChildren;
11
+ export let context;
12
+ </script>
13
+
14
+ {#if componentRef}
15
+ <svelte:component this={componentRef} {...markPropsMutable(componentOptions)}>
16
+ {#each blockChildren as child ("render-block-" + child.id)}
17
+ <RenderBlock block={child} {context} />
18
+ {/each}
19
+
20
+ {#each blockChildren as child ("block-style-" + child.id)}
21
+ <BlockStyles block={child} {context} />
22
+ {/each}
23
+ </svelte:component>
24
+ {/if}
@@ -0,0 +1,27 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ export interface RenderComponentProps {
3
+ componentRef: any;
4
+ componentOptions: any;
5
+ blockChildren: BuilderBlock[];
6
+ context: BuilderContextInterface;
7
+ }
8
+ import { BuilderBlock } from "../../types/builder-block.js";
9
+ import { BuilderContextInterface } from "../../context/types.js";
10
+ declare const __propDef: {
11
+ props: {
12
+ componentRef: RenderComponentProps["componentRef"];
13
+ componentOptions: RenderComponentProps["componentOptions"];
14
+ blockChildren: RenderComponentProps["blockChildren"];
15
+ context: RenderComponentProps["context"];
16
+ };
17
+ events: {
18
+ [evt: string]: CustomEvent<any>;
19
+ };
20
+ slots: {};
21
+ };
22
+ export declare type RenderComponentProps = typeof __propDef.props;
23
+ export declare type RenderComponentEvents = typeof __propDef.events;
24
+ export declare type RenderComponentSlots = typeof __propDef.slots;
25
+ export default class RenderComponent extends SvelteComponentTyped<RenderComponentProps, RenderComponentEvents, RenderComponentSlots> {
26
+ }
27
+ export {};
@@ -0,0 +1,49 @@
1
+ <script context="module" lang="ts">
2
+ import type { BuilderContextInterface } from "../../context/types.js";
3
+
4
+ import type { BuilderBlock } from "../../types/builder-block";
5
+
6
+ type Props = {
7
+ block: BuilderBlock;
8
+ repeatContext: BuilderContextInterface;
9
+ };
10
+ /**
11
+ * We can't make this a generic `ProvideContext` function because Vue 2 won't support root slots, e.g.
12
+ *
13
+ * ```vue
14
+ * <template>
15
+ * <slot></slot>
16
+ * </template>
17
+ * ```
18
+ */
19
+ </script>
20
+
21
+ <script lang="ts">
22
+ import { getContext, setContext } from "svelte";
23
+
24
+ import BuilderContext from "../../context/builder.context.js";
25
+ import RenderBlock from "./render-block.svelte";
26
+
27
+ export let block: Props["block"];
28
+ export let repeatContext: Props["repeatContext"];
29
+
30
+ setContext(BuilderContext.key, {
31
+ get content() {
32
+ return repeatContext.content;
33
+ },
34
+ get state() {
35
+ return repeatContext.state;
36
+ },
37
+ get context() {
38
+ return repeatContext.context;
39
+ },
40
+ get apiKey() {
41
+ return repeatContext.apiKey;
42
+ },
43
+ get registeredComponents() {
44
+ return repeatContext.registeredComponents;
45
+ },
46
+ });
47
+ </script>
48
+
49
+ <RenderBlock {block} context={repeatContext} />
@@ -0,0 +1,36 @@
1
+ <script context="module">/**
2
+ * We can't make this a generic `ProvideContext` function because Vue 2 won't support root slots, e.g.
3
+ *
4
+ * ```vue
5
+ *
6
+ * <slot></slot>
7
+ *
8
+ * ```
9
+ */
10
+ </script>
11
+
12
+ <script>import { setContext } from "svelte";
13
+ import BuilderContext from "../../context/builder.context.js";
14
+ import RenderBlock from "./render-block.svelte";
15
+ export let block;
16
+ export let repeatContext;
17
+ setContext(BuilderContext.key, {
18
+ get content() {
19
+ return repeatContext.content;
20
+ },
21
+ get state() {
22
+ return repeatContext.state;
23
+ },
24
+ get context() {
25
+ return repeatContext.context;
26
+ },
27
+ get apiKey() {
28
+ return repeatContext.apiKey;
29
+ },
30
+ get registeredComponents() {
31
+ return repeatContext.registeredComponents;
32
+ },
33
+ });
34
+ </script>
35
+
36
+ <RenderBlock {block} context={repeatContext} />
@@ -0,0 +1,23 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { BuilderContextInterface } from "../../context/types.js";
3
+ import type { BuilderBlock } from "../../types/builder-block";
4
+ declare type Props = {
5
+ block: BuilderBlock;
6
+ repeatContext: BuilderContextInterface;
7
+ };
8
+ declare const __propDef: {
9
+ props: {
10
+ block: Props["block"];
11
+ repeatContext: Props["repeatContext"];
12
+ };
13
+ events: {
14
+ [evt: string]: CustomEvent<any>;
15
+ };
16
+ slots: {};
17
+ };
18
+ export declare type RenderRepeatedBlockProps = typeof __propDef.props;
19
+ export declare type RenderRepeatedBlockEvents = typeof __propDef.events;
20
+ export declare type RenderRepeatedBlockSlots = typeof __propDef.slots;
21
+ export default class RenderRepeatedBlock extends SvelteComponentTyped<RenderRepeatedBlockProps, RenderRepeatedBlockEvents, RenderRepeatedBlockSlots> {
22
+ }
23
+ export {};
@@ -0,0 +1,6 @@
1
+ import { BuilderContextInterface } from '../../context/types.js';
2
+ import { BuilderBlock } from '../../types/builder-block.js';
3
+ export interface RepeatData {
4
+ block: BuilderBlock;
5
+ context: BuilderContextInterface;
6
+ }
@@ -0,0 +1,2 @@
1
+ import '../../context/types.js';
2
+ import '../../types/builder-block.js';
File without changes