@builder.io/sdk-svelte 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (233) hide show
  1. package/package/--package.json +160 -0
  2. package/package/blocks/BaseText.svelte +19 -0
  3. package/package/blocks/BaseText.svelte.d.ts +19 -0
  4. package/package/blocks/columns/columns.svelte +13 -4
  5. package/package/blocks/columns/columns.svelte.d.ts +1 -1
  6. package/package/blocks/custom-code/custom-code.svelte +1 -1
  7. package/package/blocks/embed/embed.svelte +2 -0
  8. package/package/blocks/form/form.svelte +7 -5
  9. package/package/blocks/image/image.svelte +48 -46
  10. package/package/blocks/image/image.svelte.d.ts +1 -1
  11. package/package/blocks/img/img.svelte +7 -2
  12. package/package/blocks/section/section.svelte +7 -2
  13. package/package/blocks/symbol/symbol.svelte +13 -13
  14. package/package/blocks/symbol/symbol.svelte.d.ts +3 -3
  15. package/package/blocks/video/video.svelte +14 -3
  16. package/package/components/render-block/block-styles.svelte +24 -19
  17. package/package/components/render-block/block-styles.svelte.d.ts +2 -2
  18. package/package/components/render-block/render-block.svelte +81 -58
  19. package/package/components/render-block/render-block.svelte.d.ts +2 -2
  20. package/package/components/render-block/render-component-with-context.svelte +32 -0
  21. package/package/components/render-block/render-component-with-context.svelte.d.ts +19 -0
  22. package/package/components/render-block/render-component.svelte +1 -3
  23. package/package/components/render-block/render-component.svelte.d.ts +2 -2
  24. package/package/components/render-block/render-repeated-block.svelte +3 -0
  25. package/package/components/render-block/types.d.ts +2 -2
  26. package/package/components/render-block/types.js +1 -2
  27. package/package/components/render-blocks.svelte +12 -1
  28. package/package/components/render-blocks.svelte.d.ts +3 -1
  29. package/package/components/render-content/components/render-styles.svelte +2 -1
  30. package/package/components/render-content/render-content.svelte +24 -8
  31. package/package/components/render-content/render-content.svelte.d.ts +2 -2
  32. package/package/constants/builder-registered-components.js +3 -0
  33. package/package/context/builder.context.d.ts +1 -0
  34. package/package/context/builder.context.js +1 -0
  35. package/package/context/types.d.ts +4 -3
  36. package/package/context/types.js +1 -3
  37. package/package/functions/extract-text-styles.d.ts +4 -0
  38. package/package/functions/extract-text-styles.js +34 -0
  39. package/package/functions/fast-clone.d.ts +4 -0
  40. package/package/functions/fast-clone.js +4 -0
  41. package/package/functions/get-block-actions-handler.d.ts +5 -0
  42. package/package/functions/get-block-actions-handler.js +9 -0
  43. package/package/functions/get-block-actions.d.ts +1 -1
  44. package/package/functions/get-block-actions.js +2 -8
  45. package/package/functions/get-block-component-options.d.ts +1 -1
  46. package/package/functions/get-block-component-options.js +0 -1
  47. package/package/functions/get-block-properties.d.ts +1 -1
  48. package/package/functions/get-block-properties.js +0 -1
  49. package/package/functions/get-block-tag.d.ts +1 -1
  50. package/package/functions/get-block-tag.js +0 -1
  51. package/package/functions/get-content/ab-testing.d.ts +5 -3
  52. package/package/functions/get-content/ab-testing.js +75 -37
  53. package/package/functions/get-content/index.d.ts +1 -1
  54. package/package/functions/get-content/index.js +4 -5
  55. package/package/functions/get-content/types.d.ts +7 -2
  56. package/package/functions/get-processed-block.d.ts +1 -1
  57. package/package/functions/get-processed-block.js +5 -4
  58. package/package/functions/get-processed-block.test.js +0 -1
  59. package/package/functions/get-react-native-block-styles.d.ts +6 -0
  60. package/package/functions/get-react-native-block-styles.js +16 -0
  61. package/package/functions/register-component.d.ts +2 -2
  62. package/package/functions/register-component.js +1 -5
  63. package/package/functions/register.d.ts +2 -2
  64. package/package/functions/register.js +0 -2
  65. package/package/functions/sanitize-react-native-block-styles.d.ts +3 -0
  66. package/package/functions/sanitize-react-native-block-styles.js +53 -0
  67. package/package/functions/track.d.ts +1 -1
  68. package/package/functions/track.js +5 -6
  69. package/package/functions/transform-block.d.ts +1 -1
  70. package/package/functions/transform-block.js +0 -1
  71. package/package/helpers/ab-tests.d.ts +8 -0
  72. package/package/helpers/ab-tests.js +5 -0
  73. package/package/helpers/cookie.d.ts +9 -3
  74. package/package/helpers/cookie.js +8 -3
  75. package/package/helpers/css.d.ts +5 -1
  76. package/package/helpers/css.js +14 -1
  77. package/package/helpers/localStorage.d.ts +3 -4
  78. package/package/helpers/sessionId.d.ts +3 -4
  79. package/package/helpers/sessionId.js +5 -3
  80. package/package/helpers/visitorId.d.ts +3 -5
  81. package/package/scripts/init-editing.js +42 -38
  82. package/package/types/builder-content.d.ts +1 -1
  83. package/package/types/builder-content.js +1 -1
  84. package/package/types/targets.d.ts +1 -1
  85. package/package/types/typescript.d.ts +1 -0
  86. package/package.json +10 -4
  87. package/src/blocks/BaseText.svelte +27 -0
  88. package/{package/blocks/button/button.lite.tsx → src/blocks/button/button.svelte} +0 -0
  89. package/src/blocks/button/component-info.ts +42 -0
  90. package/{package/blocks/columns/columns.lite.tsx → src/blocks/columns/columns.svelte} +26 -17
  91. package/src/blocks/columns/component-info.ts +254 -0
  92. package/src/blocks/custom-code/component-info.ts +31 -0
  93. package/{package/blocks/custom-code/custom-code.lite.tsx → src/blocks/custom-code/custom-code.svelte} +1 -5
  94. package/src/blocks/embed/component-info.ts +53 -0
  95. package/{package/blocks/embed/embed.lite.tsx → src/blocks/embed/embed.svelte} +1 -2
  96. package/src/blocks/embed/helpers.ts +8 -0
  97. package/src/blocks/form/component-info.ts +282 -0
  98. package/{package/blocks/form/form.lite.tsx → src/blocks/form/form.svelte} +12 -31
  99. package/src/blocks/fragment/component-info.ts +10 -0
  100. package/{package/blocks/fragment/fragment.lite.tsx → src/blocks/fragment/fragment.svelte} +0 -0
  101. package/src/blocks/image/component-info.ts +170 -0
  102. package/src/blocks/image/image.helpers.ts +75 -0
  103. package/{package/blocks/image/image.lite.tsx → src/blocks/image/image.svelte} +47 -50
  104. package/src/blocks/img/component-info.ts +21 -0
  105. package/{package/blocks/img/img.lite.tsx → src/blocks/img/img.svelte} +6 -3
  106. package/src/blocks/input/component-info.ts +78 -0
  107. package/{package/blocks/input/input.lite.tsx → src/blocks/input/input.svelte} +0 -0
  108. package/src/blocks/raw-text/component-info.ts +15 -0
  109. package/{package/blocks/raw-text/raw-text.lite.tsx → src/blocks/raw-text/raw-text.svelte} +2 -1
  110. package/src/blocks/section/component-info.ts +50 -0
  111. package/{package/blocks/section/section.lite.tsx → src/blocks/section/section.svelte} +6 -2
  112. package/src/blocks/select/component-info.ts +61 -0
  113. package/{package/blocks/select/select.lite.tsx → src/blocks/select/select.svelte} +0 -0
  114. package/src/blocks/submit-button/component-info.ts +32 -0
  115. package/{package/blocks/submit-button/submit-button.lite.tsx → src/blocks/submit-button/submit-button.svelte} +0 -0
  116. package/src/blocks/symbol/component-info.ts +43 -0
  117. package/{package/blocks/symbol/symbol.lite.tsx → src/blocks/symbol/symbol.svelte} +23 -15
  118. package/src/blocks/text/component-info.ts +24 -0
  119. package/{package/blocks/text/text.lite.tsx → src/blocks/text/text.svelte} +0 -0
  120. package/src/blocks/textarea/component-info.ts +48 -0
  121. package/{package/blocks/textarea/textarea.lite.tsx → src/blocks/textarea/textarea.svelte} +0 -0
  122. package/src/blocks/util.ts +6 -0
  123. package/src/blocks/video/component-info.ts +109 -0
  124. package/{package/blocks/video/video.lite.tsx → src/blocks/video/video.svelte} +13 -3
  125. package/{package/components/render-block/block-styles.lite.tsx → src/components/render-block/block-styles.svelte} +28 -26
  126. package/src/components/render-block/render-block.helpers.ts +27 -0
  127. package/{package/components/render-block/render-block.lite.tsx → src/components/render-block/render-block.svelte} +93 -81
  128. package/src/components/render-block/render-component-with-context.svelte +38 -0
  129. package/{package/components/render-block/render-component.lite.tsx → src/components/render-block/render-component.svelte} +5 -3
  130. package/{package/components/render-block/render-repeated-block.lite.tsx → src/components/render-block/render-repeated-block.svelte} +4 -0
  131. package/src/components/render-block/types.ts +7 -0
  132. package/{package/components/render-blocks.lite.tsx → src/components/render-blocks.svelte} +15 -2
  133. package/{package/components/render-content/components/render-styles.lite.tsx → src/components/render-content/components/render-styles.svelte} +2 -8
  134. package/src/components/render-content/index.ts +1 -0
  135. package/{package/components/render-content/render-content.lite.tsx → src/components/render-content/render-content.svelte} +34 -36
  136. package/{package/components/render-inlined-styles.lite.tsx → src/components/render-inlined-styles.svelte} +0 -1
  137. package/src/constants/builder-registered-components.ts +42 -0
  138. package/src/constants/device-sizes.ts +28 -0
  139. package/src/constants/target.ts +2 -0
  140. package/src/context/builder.context.ts +13 -0
  141. package/src/context/types.ts +23 -0
  142. package/src/functions/camel-to-kebab-case.ts +2 -0
  143. package/src/functions/evaluate.ts +52 -0
  144. package/src/functions/event-handler-name.ts +6 -0
  145. package/src/functions/extract-text-styles.ts +39 -0
  146. package/src/functions/fast-clone.ts +5 -0
  147. package/src/functions/get-block-actions-handler.ts +19 -0
  148. package/src/functions/get-block-actions.ts +25 -0
  149. package/src/functions/get-block-component-options.ts +12 -0
  150. package/src/functions/get-block-properties.ts +11 -0
  151. package/src/functions/get-block-tag.ts +7 -0
  152. package/src/functions/get-builder-search-params/fn.test.ts +19 -0
  153. package/src/functions/get-builder-search-params/index.ts +48 -0
  154. package/src/functions/get-content/ab-testing.ts +132 -0
  155. package/src/functions/get-content/fn.test.ts +35 -0
  156. package/src/functions/get-content/index.ts +77 -0
  157. package/src/functions/get-content/types.ts +36 -0
  158. package/src/functions/get-fetch.ts +14 -0
  159. package/src/functions/get-global-this.ts +15 -0
  160. package/src/functions/get-processed-block.test.ts +33 -0
  161. package/src/functions/get-processed-block.ts +54 -0
  162. package/src/functions/get-react-native-block-styles.ts +30 -0
  163. package/src/functions/if-target.ts +20 -0
  164. package/src/functions/is-browser.ts +3 -0
  165. package/src/functions/is-editing.ts +7 -0
  166. package/src/functions/is-iframe.ts +5 -0
  167. package/src/functions/is-previewing.ts +14 -0
  168. package/src/functions/mark-mutable.ts +7 -0
  169. package/src/functions/on-change.test.ts +23 -0
  170. package/src/functions/on-change.ts +29 -0
  171. package/src/functions/register-component.ts +67 -0
  172. package/src/functions/register.ts +46 -0
  173. package/src/functions/sanitize-react-native-block-styles.ts +65 -0
  174. package/src/functions/set-editor-settings.ts +16 -0
  175. package/src/functions/set.test.ts +19 -0
  176. package/src/functions/set.ts +26 -0
  177. package/src/functions/track.ts +90 -0
  178. package/src/functions/transform-block.ts +6 -0
  179. package/src/helpers/ab-tests.ts +22 -0
  180. package/src/helpers/cookie.ts +102 -0
  181. package/src/helpers/css.ts +33 -0
  182. package/src/helpers/flatten.ts +24 -0
  183. package/src/helpers/localStorage.ts +38 -0
  184. package/src/helpers/nullable.ts +4 -0
  185. package/src/helpers/sessionId.ts +34 -0
  186. package/src/helpers/time.ts +4 -0
  187. package/src/helpers/url.test.ts +16 -0
  188. package/src/helpers/url.ts +12 -0
  189. package/src/helpers/uuid.ts +17 -0
  190. package/src/helpers/visitorId.ts +38 -0
  191. package/src/index-helpers/blocks-exports.ts +10 -0
  192. package/src/index-helpers/top-of-file.ts +4 -0
  193. package/src/index.ts +12 -0
  194. package/src/scripts/init-editing.ts +102 -0
  195. package/src/types/builder-block.ts +58 -0
  196. package/src/types/builder-content.ts +39 -0
  197. package/src/types/can-track.ts +3 -0
  198. package/src/types/components.ts +188 -0
  199. package/src/types/deep-partial.ts +7 -0
  200. package/src/types/element.ts +60 -0
  201. package/src/types/targets.ts +6 -0
  202. package/src/types/typescript.ts +7 -0
  203. package/package/blocks/button/button.lite.d.ts +0 -0
  204. package/package/blocks/columns/columns.lite.d.ts +0 -0
  205. package/package/blocks/custom-code/custom-code.lite.d.ts +0 -0
  206. package/package/blocks/embed/embed.lite.d.ts +0 -0
  207. package/package/blocks/form/form.lite.d.ts +0 -0
  208. package/package/blocks/fragment/fragment.lite.d.ts +0 -0
  209. package/package/blocks/image/image.lite.d.ts +0 -0
  210. package/package/blocks/img/img.lite.d.ts +0 -0
  211. package/package/blocks/input/input.lite.d.ts +0 -0
  212. package/package/blocks/raw-text/raw-text.lite.d.ts +0 -0
  213. package/package/blocks/section/section.lite.d.ts +0 -0
  214. package/package/blocks/select/select.lite.d.ts +0 -0
  215. package/package/blocks/submit-button/submit-button.lite.d.ts +0 -0
  216. package/package/blocks/symbol/symbol.lite.d.ts +0 -0
  217. package/package/blocks/text/text.lite.d.ts +0 -0
  218. package/package/blocks/textarea/textarea.lite.d.ts +0 -0
  219. package/package/blocks/video/video.lite.d.ts +0 -0
  220. package/package/components/render-block/block-styles.lite.d.ts +0 -0
  221. package/package/components/render-block/render-block.lite.d.ts +0 -0
  222. package/package/components/render-block/render-component.lite.d.ts +0 -0
  223. package/package/components/render-block/render-repeated-block.lite.d.ts +0 -0
  224. package/package/components/render-blocks.lite.d.ts +0 -0
  225. package/package/components/render-content/components/render-styles.lite.d.ts +0 -0
  226. package/package/components/render-content/render-content.lite.d.ts +0 -0
  227. package/package/components/render-inlined-styles.lite.d.ts +0 -0
  228. package/package/functions/convert-style-object.d.ts +0 -1
  229. package/package/functions/convert-style-object.js +0 -3
  230. package/package/functions/get-block-styles.d.ts +0 -2
  231. package/package/functions/get-block-styles.js +0 -21
  232. package/package/functions/sanitize-styles.d.ts +0 -4
  233. package/package/functions/sanitize-styles.js +0 -6
@@ -1,31 +1,38 @@
1
1
  <script context="module" lang="ts">
2
+ import type {
3
+ BuilderContextInterface,
4
+ RegisteredComponent,
5
+ } from "../../context/types.js";
6
+
7
+ import type { BuilderBlock } from "../../types/builder-block.js";
8
+
9
+ import type { Nullable } from "../../types/typescript.js";
10
+
11
+ import type { RenderComponentProps } from "./render-component";
12
+
13
+ import type { RepeatData } from "./types.js";
14
+
2
15
  export type RenderBlockProps = {
3
16
  block: BuilderBlock;
4
17
  context: BuilderContextInterface;
5
- }; // eslint-disable-next-line @builder.io/mitosis/only-default-function-and-imports
18
+ };
6
19
  </script>
7
20
 
8
21
  <script lang="ts">
9
- import {
10
- BuilderContextInterface,
11
- RegisteredComponent,
12
- } from "../../context/types.js";
13
22
  import { getBlockActions } from "../../functions/get-block-actions.js";
14
23
  import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
15
24
  import { getBlockProperties } from "../../functions/get-block-properties.js";
16
- import { getBlockStyles } from "../../functions/get-block-styles.js";
17
25
  import { getBlockTag } from "../../functions/get-block-tag.js";
18
26
  import { getProcessedBlock } from "../../functions/get-processed-block.js";
19
- import { BuilderBlock } from "../../types/builder-block.js";
20
- import { Nullable } from "../../types/typescript.js";
21
27
  import { evaluate } from "../../functions/evaluate.js";
22
28
  import BlockStyles from "./block-styles.svelte";
23
29
  import { isEmptyHtmlElement } from "./render-block.helpers.js";
24
- import RenderComponent, {
25
- RenderComponentProps,
26
- } from "./render-component.svelte";
27
- import { RepeatData } from "./types.js";
28
30
  import RenderRepeatedBlock from "./render-repeated-block.svelte";
31
+ import { TARGET } from "../../constants/target.js";
32
+ import { extractTextStyles } from "../../functions/extract-text-styles.js";
33
+ import RenderComponentWithContext from "./render-component-with-context.svelte";
34
+ import RenderComponent from "./render-component.svelte";
35
+ import { getReactNativeBlockStyles } from "../../functions/get-react-native-block-styles.js";
29
36
 
30
37
  export let block: RenderBlockProps["block"];
31
38
  export let context: RenderBlockProps["context"];
@@ -37,13 +44,10 @@
37
44
  context: context.context,
38
45
  shouldEvaluateBindings: false,
39
46
  }).component?.name;
40
-
41
47
  if (!componentName) {
42
48
  return null;
43
49
  }
44
-
45
50
  const ref = context.registeredComponents[componentName];
46
-
47
51
  if (!ref) {
48
52
  // TODO: Public doc page with more info about this message
49
53
  console.warn(`
@@ -54,24 +58,9 @@
54
58
  return ref;
55
59
  }
56
60
  };
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
61
  $: tagName = () => {
72
62
  return getBlockTag(useBlock());
73
63
  };
74
-
75
64
  $: useBlock = () => {
76
65
  return repeatItemData()
77
66
  ? block
@@ -82,7 +71,6 @@
82
71
  shouldEvaluateBindings: true,
83
72
  });
84
73
  };
85
-
86
74
  $: attributes = () => {
87
75
  return {
88
76
  ...getBlockProperties(useBlock()),
@@ -91,47 +79,45 @@
91
79
  state: context.state,
92
80
  context: context.context,
93
81
  }),
94
- style: getBlockStyles(useBlock()),
82
+ ...(TARGET === "reactNative"
83
+ ? {
84
+ style: getReactNativeBlockStyles({
85
+ block: useBlock(),
86
+ context: context,
87
+ }),
88
+ }
89
+ : {}),
95
90
  };
96
91
  };
97
-
98
92
  $: 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
- };
93
+ return !component?.()?.noWrap;
116
94
  };
117
-
118
95
  $: renderComponentProps = () => {
119
96
  return {
120
97
  blockChildren: children(),
121
- componentRef: componentRef(),
122
- componentOptions: componentOptions(),
123
- context: context,
98
+ componentRef: component?.()?.component,
99
+ componentOptions: {
100
+ ...getBlockComponentOptions(useBlock()),
101
+ /**
102
+ * These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
103
+ * they are provided to the component itself directly.
104
+ */
105
+ ...(shouldWrap()
106
+ ? {}
107
+ : {
108
+ attributes: attributes(),
109
+ }),
110
+ },
111
+ context: childrenContext(),
124
112
  };
125
113
  };
126
-
127
114
  $: children = () => {
128
115
  // TO-DO: When should `canHaveChildren` dictate rendering?
129
116
  // This is currently commented out because some Builder components (e.g. Box) do not have `canHaveChildren: true`,
130
117
  // but still receive and need to render children.
131
- // return componentInfo?.()?.canHaveChildren ? useBlock().children : [];
118
+ // return componentInfo?.canHaveChildren ? useBlock().children : [];
132
119
  return useBlock().children ?? [];
133
120
  };
134
-
135
121
  $: childrenWithoutParentComponent = () => {
136
122
  /**
137
123
  * When there is no `componentRef`, there might still be children that need to be rendered. In this case,
@@ -139,31 +125,27 @@
139
125
  * NOTE: We make sure not to render this if `repeatItemData` is non-null, because that means we are rendering an array of
140
126
  * blocks, and the children will be repeated within those blocks.
141
127
  */
142
- const shouldRenderChildrenOutsideRef = !componentRef() && !repeatItemData();
128
+ const shouldRenderChildrenOutsideRef =
129
+ !component?.()?.component && !repeatItemData();
143
130
  return shouldRenderChildrenOutsideRef ? children() : [];
144
131
  };
145
-
146
132
  $: repeatItemData = () => {
147
133
  /**
148
134
  * we don't use `useBlock()` here because the processing done within its logic includes evaluating the block's bindings,
149
135
  * which will not work if there is a repeat.
150
136
  */
151
137
  const { repeat, ...blockWithoutRepeat } = block;
152
-
153
138
  if (!repeat?.collection) {
154
139
  return undefined;
155
140
  }
156
-
157
141
  const itemsArray = evaluate({
158
142
  code: repeat.collection,
159
143
  state: context.state,
160
144
  context: context.context,
161
145
  });
162
-
163
146
  if (!Array.isArray(itemsArray)) {
164
147
  return undefined;
165
148
  }
166
-
167
149
  const collectionName = repeat.collection.split(".").pop();
168
150
  const itemNameToUse =
169
151
  repeat.itemName || (collectionName ? collectionName + "Item" : "item");
@@ -182,35 +164,65 @@
182
164
  }));
183
165
  return repeatArray;
184
166
  };
167
+ $: inheritedTextStyles = () => {
168
+ if (TARGET !== "reactNative") {
169
+ return {};
170
+ }
171
+ const styles = getReactNativeBlockStyles({
172
+ block: useBlock(),
173
+ context: context,
174
+ });
175
+ return extractTextStyles(styles);
176
+ };
177
+ $: childrenContext = () => {
178
+ return {
179
+ apiKey: context.apiKey,
180
+ state: context.state,
181
+ content: context.content,
182
+ context: context.context,
183
+ registeredComponents: context.registeredComponents,
184
+ inheritedStyles: inheritedTextStyles(),
185
+ };
186
+ };
187
+ $: renderComponentTag = () => {
188
+ if (TARGET === "reactNative") {
189
+ return RenderComponentWithContext;
190
+ } else if (TARGET === "vue3") {
191
+ // vue3 expects a string for the component tag
192
+ return "RenderComponent";
193
+ } else {
194
+ return RenderComponent;
195
+ }
196
+ };
185
197
  </script>
186
198
 
187
199
  {#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}
200
+ {#if isEmptyHtmlElement(tagName())}
201
+ <svelte:element this={tagName()} {...attributes()} />
202
+ {/if}
198
203
 
199
- {#if !repeatItemData()}
200
- <RenderComponent {...renderComponentProps()} />
201
- {/if}
204
+ {#if !isEmptyHtmlElement(tagName()) && repeatItemData()}
205
+ {#each repeatItemData() as data, index (index)}
206
+ <RenderRepeatedBlock repeatContext={data.context} block={data.block} />
207
+ {/each}
208
+ {/if}
209
+
210
+ {#if !isEmptyHtmlElement(tagName()) && !repeatItemData()}
211
+ <svelte:element this={tagName()} {...attributes()}>
212
+ <svelte:component
213
+ this={renderComponentTag()}
214
+ {...renderComponentProps()}
215
+ />
202
216
 
203
217
  {#each childrenWithoutParentComponent() as child ("render-block-" + child.id)}
204
- <svelte:self block={child} {context} />
218
+ <svelte:self block={child} context={childrenContext()} />
205
219
  {/each}
206
220
 
207
221
  {#each childrenWithoutParentComponent() as child ("block-style-" + child.id)}
208
- <BlockStyles block={child} {context} />
222
+ <BlockStyles block={child} context={childrenContext()} />
209
223
  {/each}
210
224
  </svelte:element>
211
- {:else}
212
- <svelte:element this={tagName()} {...attributes()} />
213
225
  {/if}
214
226
  {:else}
215
- <RenderComponent {...renderComponentProps()} {context} />
227
+ <svelte:component this={renderComponentTag()} {...renderComponentProps()} />
216
228
  {/if}
@@ -0,0 +1,38 @@
1
+ <script context="module" lang="ts">
2
+ import type { RenderComponentProps } from "./render-component";
3
+ </script>
4
+
5
+ <script lang="ts">
6
+ import { getContext, setContext } from "svelte";
7
+
8
+ import BuilderContext from "../../context/builder.context.js";
9
+ import RenderComponent from "./render-component.svelte";
10
+
11
+ export let componentRef: RenderComponentProps["componentRef"];
12
+ export let componentOptions: RenderComponentProps["componentOptions"];
13
+ export let blockChildren: RenderComponentProps["blockChildren"];
14
+ export let context: RenderComponentProps["context"];
15
+
16
+ setContext(BuilderContext.key, {
17
+ get content() {
18
+ return context.content;
19
+ },
20
+ get state() {
21
+ return context.state;
22
+ },
23
+ get context() {
24
+ return context.context;
25
+ },
26
+ get apiKey() {
27
+ return context.apiKey;
28
+ },
29
+ get registeredComponents() {
30
+ return context.registeredComponents;
31
+ },
32
+ get inheritedStyles() {
33
+ return context.inheritedStyles;
34
+ },
35
+ });
36
+ </script>
37
+
38
+ <RenderComponent {componentRef} {componentOptions} {blockChildren} {context} />
@@ -1,17 +1,19 @@
1
1
  <script context="module" lang="ts">
2
+ import type { BuilderBlock } from "../../types/builder-block.js";
3
+
4
+ import type { BuilderContextInterface } from "../../context/types.js";
5
+
2
6
  export interface RenderComponentProps {
3
7
  componentRef: any;
4
8
  componentOptions: any;
5
9
  blockChildren: BuilderBlock[];
6
10
  context: BuilderContextInterface;
7
- } // eslint-disable-next-line @builder.io/mitosis/only-default-function-and-imports
11
+ }
8
12
  </script>
9
13
 
10
14
  <script lang="ts">
11
- import { BuilderBlock } from "../../types/builder-block.js";
12
15
  import BlockStyles from "./block-styles.svelte";
13
16
  import RenderBlock from "./render-block.svelte";
14
- import { BuilderContextInterface } from "../../context/types.js";
15
17
  import { markPropsMutable } from "../../functions/mark-mutable.js";
16
18
 
17
19
  export let componentRef: RenderComponentProps["componentRef"];
@@ -7,6 +7,7 @@
7
7
  block: BuilderBlock;
8
8
  repeatContext: BuilderContextInterface;
9
9
  };
10
+
10
11
  /**
11
12
  * We can't make this a generic `ProvideContext` function because Vue 2 won't support root slots, e.g.
12
13
  *
@@ -43,6 +44,9 @@
43
44
  get registeredComponents() {
44
45
  return repeatContext.registeredComponents;
45
46
  },
47
+ get inheritedStyles() {
48
+ return repeatContext.inheritedStyles;
49
+ },
46
50
  });
47
51
  </script>
48
52
 
@@ -0,0 +1,7 @@
1
+ import type { BuilderContextInterface } from '../../context/types.js';
2
+ import type { BuilderBlock } from '../../types/builder-block.js';
3
+
4
+ export interface RepeatData {
5
+ block: BuilderBlock;
6
+ context: BuilderContextInterface;
7
+ }
@@ -1,8 +1,11 @@
1
1
  <script context="module" lang="ts">
2
+ import type { BuilderBlock } from "../types/builder-block.js";
3
+
2
4
  export type RenderBlockProps = {
3
5
  blocks?: BuilderBlock[];
4
6
  parent?: string;
5
7
  path?: string;
8
+ styleProp?: Record<string, any>;
6
9
  };
7
10
  </script>
8
11
 
@@ -11,13 +14,23 @@
11
14
 
12
15
  import BuilderContext from "../context/builder.context.js";
13
16
  import { isEditing } from "../functions/is-editing.js";
14
- import { BuilderBlock } from "../types/builder-block.js";
15
17
  import BlockStyles from "./render-block/block-styles.svelte";
16
18
  import RenderBlock from "./render-block/render-block.svelte";
17
19
 
18
20
  export let blocks: RenderBlockProps["blocks"];
19
21
  export let parent: RenderBlockProps["parent"];
20
22
  export let path: RenderBlockProps["path"];
23
+ export let styleProp: RenderBlockProps["styleProp"];
24
+
25
+ function mitosis_styling(node, vars) {
26
+ Object.entries(vars || {}).forEach(([p, v]) => {
27
+ if (p.startsWith("--")) {
28
+ node.style.setProperty(p, v);
29
+ } else {
30
+ node.style[p] = v;
31
+ }
32
+ });
33
+ }
21
34
 
22
35
  let builderContext = getContext(BuilderContext.key);
23
36
 
@@ -35,7 +48,6 @@
35
48
  );
36
49
  }
37
50
  }
38
-
39
51
  function onMouseEnter() {
40
52
  if (isEditing() && !blocks?.length) {
41
53
  window.parent?.postMessage(
@@ -56,6 +68,7 @@
56
68
  </script>
57
69
 
58
70
  <div
71
+ use:mitosis_styling={styleProp}
59
72
  class={className() + " div"}
60
73
  builder-path={path}
61
74
  builder-parent-id={parent}
@@ -28,7 +28,6 @@
28
28
  const name = family.split(",")[0];
29
29
  const url = font.fileUrl ?? font?.files?.regular;
30
30
  let str = "";
31
-
32
31
  if (url && family && name) {
33
32
  str += `
34
33
  @font-face {
@@ -39,17 +38,14 @@
39
38
  }
40
39
  `.trim();
41
40
  }
42
-
43
41
  if (font.files) {
44
42
  for (const weight in font.files) {
45
43
  const isNumber = String(Number(weight)) === weight;
46
-
47
44
  if (!isNumber) {
48
45
  continue;
49
- } // TODO: maybe limit number loaded
50
-
46
+ }
47
+ // TODO: maybe limit number loaded
51
48
  const weightUrl = font.files[weight];
52
-
53
49
  if (weightUrl && weightUrl !== url) {
54
50
  str += `
55
51
  @font-face {
@@ -62,10 +58,8 @@
62
58
  }
63
59
  }
64
60
  }
65
-
66
61
  return str;
67
62
  }
68
-
69
63
  function getFontCss({ customFonts }) {
70
64
  // TODO: flag for this
71
65
  // if (!builder.allowCustomFonts) {
@@ -0,0 +1 @@
1
+ export { default } from './render-content.svelte';
@@ -1,4 +1,13 @@
1
1
  <script context="module" lang="ts">
2
+ import type {
3
+ BuilderRenderContext,
4
+ BuilderRenderState,
5
+ RegisteredComponent,
6
+ RegisteredComponents,
7
+ } from "../../context/types.js";
8
+
9
+ import type { BuilderContent } from "../../types/builder-content.js";
10
+
2
11
  import type { Dictionary, Nullable } from "../../types/typescript.js";
3
12
 
4
13
  export type RenderContentProps = {
@@ -38,12 +47,6 @@
38
47
  import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
39
48
  import { TARGET } from "../../constants/target.js";
40
49
  import BuilderContext from "../../context/builder.context.js";
41
- import {
42
- BuilderRenderContext,
43
- BuilderRenderState,
44
- RegisteredComponent,
45
- RegisteredComponents,
46
- } from "../../context/types.js";
47
50
  import { evaluate } from "../../functions/evaluate.js";
48
51
  import { getContent } from "../../functions/get-content/index.js";
49
52
  import { getFetch } from "../../functions/get-fetch.js";
@@ -55,7 +58,6 @@
55
58
  createRegisterComponentMessage,
56
59
  } from "../../functions/register-component.js";
57
60
  import { track } from "../../functions/track.js";
58
- import { BuilderContent } from "../../types/builder-content.js";
59
61
  import RenderBlocks from "../render-blocks.svelte";
60
62
  import RenderContentStyles from "./components/render-styles.svelte";
61
63
  import {
@@ -92,7 +94,6 @@
92
94
 
93
95
  function processMessage(event) {
94
96
  const { data } = event;
95
-
96
97
  if (data) {
97
98
  switch (data.type) {
98
99
  case "builder.contentUpdate": {
@@ -103,7 +104,6 @@
103
104
  messageContent.entry ||
104
105
  messageContent.modelName;
105
106
  const contentData = messageContent.data;
106
-
107
107
  if (key === model) {
108
108
  overrideContent = contentData;
109
109
  forceReRenderCount = forceReRenderCount + 1; // This is a hack to force Qwik to re-render.
@@ -111,7 +111,6 @@
111
111
 
112
112
  break;
113
113
  }
114
-
115
114
  case "builder.patchUpdates": {
116
115
  // TODO
117
116
  break;
@@ -119,11 +118,9 @@
119
118
  }
120
119
  }
121
120
  }
122
-
123
121
  function evaluateJsCode() {
124
122
  // run any dynamic JS code attached to content
125
123
  const jsCode = useContent?.()?.data?.jsCode;
126
-
127
124
  if (jsCode) {
128
125
  evaluate({
129
126
  code: jsCode,
@@ -132,7 +129,6 @@
132
129
  });
133
130
  }
134
131
  }
135
-
136
132
  function onClick(_event) {
137
133
  if (useContent()) {
138
134
  track({
@@ -143,7 +139,6 @@
143
139
  });
144
140
  }
145
141
  }
146
-
147
142
  function evalExpression(expression) {
148
143
  return expression.replace(/{{([^}]+)}}/g, (_match, group) =>
149
144
  evaluate({
@@ -153,20 +148,21 @@
153
148
  })
154
149
  );
155
150
  }
156
-
157
151
  function handleRequest({ url, key }) {
158
152
  getFetch()
159
153
  .then((fetch) => fetch(url))
160
154
  .then((response) => response.json())
161
155
  .then((json) => {
162
- const newOverrideState = { ...overrideState, [key]: json };
156
+ const newOverrideState = {
157
+ ...overrideState,
158
+ [key]: json,
159
+ };
163
160
  overrideState = newOverrideState;
164
161
  })
165
162
  .catch((err) => {
166
163
  console.log("error fetching dynamic data", url, err);
167
164
  });
168
165
  }
169
-
170
166
  function runHttpRequests() {
171
167
  const requests = useContent?.()?.data?.httpRequests ?? {};
172
168
  Object.entries(requests).forEach(([key, url]) => {
@@ -179,7 +175,6 @@
179
175
  }
180
176
  });
181
177
  }
182
-
183
178
  function emitStateUpdate() {
184
179
  if (isEditing()) {
185
180
  window.dispatchEvent(
@@ -198,30 +193,34 @@
198
193
  if (!content && !overrideContent) {
199
194
  return undefined;
200
195
  }
201
-
202
196
  const mergedContent = {
203
197
  ...content,
204
198
  ...overrideContent,
205
- data: { ...content?.data, ...data, ...overrideContent?.data },
199
+ data: {
200
+ ...content?.data,
201
+ ...data,
202
+ ...overrideContent?.data,
203
+ },
206
204
  };
207
205
  return mergedContent;
208
206
  };
209
-
210
207
  $: canTrackToUse = () => {
211
208
  return canTrack || true;
212
209
  };
213
-
214
210
  $: contentState = () => {
215
- return { ...content?.data?.state, ...data, ...overrideState };
211
+ return {
212
+ ...content?.data?.state,
213
+ ...data,
214
+ ...overrideState,
215
+ };
216
216
  };
217
-
218
217
  $: contextContext = () => {
219
218
  return context || {};
220
219
  };
221
-
222
220
  $: allRegisteredComponents = () => {
223
221
  const allComponentsArray = [
224
- ...getDefaultRegisteredComponents(), // While this `components` object is deprecated, we must maintain support for it.
222
+ ...getDefaultRegisteredComponents(),
223
+ // While this `components` object is deprecated, we must maintain support for it.
225
224
  // Since users are able to override our default components, we need to make sure that we do not break such
226
225
  // existing usage.
227
226
  // This is why we spread `components` after the default Builder.io components, but before the `customComponents`,
@@ -230,16 +229,17 @@
230
229
  ...(customComponents || []),
231
230
  ];
232
231
  const allComponents = allComponentsArray.reduce(
233
- (acc, curr) => ({ ...acc, [curr.name]: curr }),
232
+ (acc, curr) => ({
233
+ ...acc,
234
+ [curr.name]: curr,
235
+ }),
234
236
  {}
235
237
  );
236
238
  return allComponents;
237
239
  };
238
-
239
240
  $: httpReqsData = () => {
240
241
  return {};
241
242
  };
242
-
243
243
  $: shouldRenderContentStyles = () => {
244
244
  return Boolean(
245
245
  (useContent?.()?.data?.cssCode ||
@@ -258,8 +258,8 @@
258
258
  onMount(() => {
259
259
  if (isBrowser()) {
260
260
  if (isEditing()) {
261
- forceReRenderCount = forceReRenderCount + 1; // QWIK-REPLACE: _useMutableProps
262
-
261
+ forceReRenderCount = forceReRenderCount + 1;
262
+ // QWIK-REPLACE: _useMutableProps
263
263
  registerInsertMenu();
264
264
  setupBrowserForEditing();
265
265
  Object.values(allRegisteredComponents()).forEach(
@@ -274,7 +274,6 @@
274
274
  emitStateUpdate
275
275
  );
276
276
  }
277
-
278
277
  if (useContent()) {
279
278
  track({
280
279
  type: "impression",
@@ -282,15 +281,14 @@
282
281
  contentId: useContent?.()?.id,
283
282
  orgId: apiKey,
284
283
  });
285
- } // override normal content in preview mode
284
+ }
286
285
 
286
+ // override normal content in preview mode
287
287
  if (isPreviewing()) {
288
288
  const searchParams = new URL(location.href).searchParams;
289
-
290
289
  if (model && searchParams.get("builder.preview") === model) {
291
290
  const previewApiKey =
292
291
  searchParams.get("apiKey") || searchParams.get("builder.space");
293
-
294
292
  if (previewApiKey) {
295
293
  getContent({
296
294
  model: model,
@@ -303,7 +301,6 @@
303
301
  }
304
302
  }
305
303
  }
306
-
307
304
  evaluateJsCode();
308
305
  runHttpRequests();
309
306
  emitStateUpdate();
@@ -341,6 +338,7 @@
341
338
  onClick(event);
342
339
  }}
343
340
  builder-content-id={useContent?.()?.id}
341
+ builder-model={model}
344
342
  >
345
343
  {#if shouldRenderContentStyles()}
346
344
  <RenderContentStyles