@builder.io/sdk-solid 0.0.19 → 0.0.21

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 (39) hide show
  1. package/package.json +1 -1
  2. package/src/blocks/BaseText.jsx +0 -2
  3. package/src/blocks/button/button.jsx +1 -3
  4. package/src/blocks/columns/columns.jsx +1 -13
  5. package/src/blocks/columns/component-info.js +2 -2
  6. package/src/blocks/custom-code/custom-code.jsx +0 -8
  7. package/src/blocks/embed/component-info.js +2 -2
  8. package/src/blocks/embed/embed.jsx +0 -8
  9. package/src/blocks/form/form.jsx +9 -43
  10. package/src/blocks/fragment/fragment.jsx +0 -1
  11. package/src/blocks/image/component-info.js +2 -2
  12. package/src/blocks/image/image.jsx +4 -9
  13. package/src/blocks/img/img.jsx +2 -4
  14. package/src/blocks/input/input.jsx +0 -2
  15. package/src/blocks/raw-text/raw-text.jsx +0 -1
  16. package/src/blocks/section/section.jsx +0 -1
  17. package/src/blocks/select/select.jsx +0 -3
  18. package/src/blocks/submit-button/submit-button.jsx +1 -2
  19. package/src/blocks/symbol/symbol.jsx +4 -10
  20. package/src/blocks/text/text.jsx +0 -1
  21. package/src/blocks/textarea/textarea.jsx +0 -1
  22. package/src/blocks/util.js +6 -5
  23. package/src/blocks/video/video.jsx +4 -5
  24. package/src/components/render-block/block-styles.jsx +5 -7
  25. package/src/components/render-block/render-block.jsx +17 -39
  26. package/src/components/render-block/render-component-with-context.jsx +0 -8
  27. package/src/components/render-block/render-component.jsx +1 -6
  28. package/src/components/render-block/render-repeated-block.jsx +0 -8
  29. package/src/components/render-blocks.jsx +0 -7
  30. package/src/components/render-content/builder-editing.jsx +4 -0
  31. package/src/components/render-content/components/render-styles.jsx +2 -13
  32. package/src/components/render-content/render-content.jsx +29 -56
  33. package/src/components/render-inlined-styles.jsx +3 -7
  34. package/src/constants/device-sizes.js +29 -2
  35. package/src/functions/get-content/index.js +6 -2
  36. package/src/functions/register-component.js +1 -5
  37. package/src/functions/track.js +11 -8
  38. package/src/index.js +5 -1
  39. package/src/scripts/init-editing.js +7 -1
@@ -1,6 +1,7 @@
1
1
  function Video(props) {
2
2
  function videoProps() {
3
- return { ...(props.autoPlay === true ? {
3
+ return {
4
+ ...(props.autoPlay === true ? {
4
5
  autoPlay: true
5
6
  } : {}),
6
7
  ...(props.muted === true ? {
@@ -17,13 +18,12 @@ function Video(props) {
17
18
  } : {})
18
19
  };
19
20
  }
20
-
21
21
  function spreadProps() {
22
- return { ...props.attributes,
22
+ return {
23
+ ...props.attributes,
23
24
  ...videoProps()
24
25
  };
25
26
  }
26
-
27
27
  return <video {...spreadProps()} style={{
28
28
  width: "100%",
29
29
  height: "100%",
@@ -35,5 +35,4 @@ function Video(props) {
35
35
  "border-radius": 1
36
36
  }} src={props.video || "no-src"} poster={props.posterImage}></video>;
37
37
  }
38
-
39
38
  export default Video;
@@ -1,10 +1,9 @@
1
1
  import { Show } from "solid-js";
2
- import { getMaxWidthQueryForSize } from "../../constants/device-sizes.js";
2
+ import { getMaxWidthQueryForSize, getSizesForBreakpoints } from "../../constants/device-sizes.js";
3
3
  import { TARGET } from "../../constants/target.js";
4
4
  import { getProcessedBlock } from "../../functions/get-processed-block.js";
5
5
  import { createCssClass } from "../../helpers/css.js";
6
6
  import RenderInlinedStyles from "../render-inlined-styles.jsx";
7
-
8
7
  function BlockStyles(props) {
9
8
  function useBlock() {
10
9
  return getProcessedBlock({
@@ -14,9 +13,10 @@ function BlockStyles(props) {
14
13
  shouldEvaluateBindings: true
15
14
  });
16
15
  }
17
-
18
16
  function css() {
19
17
  const styles = useBlock().responsiveStyles;
18
+ const content = props.context.content;
19
+ const sizesWithUpdatedBreakpoints = getSizesForBreakpoints(content?.meta?.breakpoints || {});
20
20
  const largeStyles = styles?.large;
21
21
  const mediumStyles = styles?.medium;
22
22
  const smallStyles = styles?.small;
@@ -28,19 +28,17 @@ function BlockStyles(props) {
28
28
  const mediumStylesClass = mediumStyles ? createCssClass({
29
29
  className,
30
30
  styles: mediumStyles,
31
- mediaQuery: getMaxWidthQueryForSize("medium")
31
+ mediaQuery: getMaxWidthQueryForSize("medium", sizesWithUpdatedBreakpoints)
32
32
  }) : "";
33
33
  const smallStylesClass = smallStyles ? createCssClass({
34
34
  className,
35
35
  styles: smallStyles,
36
- mediaQuery: getMaxWidthQueryForSize("small")
36
+ mediaQuery: getMaxWidthQueryForSize("small", sizesWithUpdatedBreakpoints)
37
37
  }) : "";
38
38
  return [largeStylesClass, mediumStylesClass, smallStylesClass].join(" ");
39
39
  }
40
-
41
40
  return <Show when={TARGET !== "reactNative" && css()}>
42
41
  <RenderInlinedStyles styles={css()}></RenderInlinedStyles>
43
42
  </Show>;
44
43
  }
45
-
46
44
  export default BlockStyles;
@@ -14,7 +14,6 @@ import { extractTextStyles } from "../../functions/extract-text-styles.js";
14
14
  import RenderComponentWithContext from "./render-component-with-context.jsx";
15
15
  import RenderComponent from "./render-component.jsx";
16
16
  import { getReactNativeBlockStyles } from "../../functions/get-react-native-block-styles.js";
17
-
18
17
  function RenderBlock(props) {
19
18
  function component() {
20
19
  const componentName = getProcessedBlock({
@@ -23,13 +22,10 @@ function RenderBlock(props) {
23
22
  context: props.context.context,
24
23
  shouldEvaluateBindings: false
25
24
  }).component?.name;
26
-
27
25
  if (!componentName) {
28
26
  return null;
29
27
  }
30
-
31
28
  const ref = props.context.registeredComponents[componentName];
32
-
33
29
  if (!ref) {
34
30
  // TODO: Public doc page with more info about this message
35
31
  console.warn(`
@@ -40,11 +36,9 @@ function RenderBlock(props) {
40
36
  return ref;
41
37
  }
42
38
  }
43
-
44
- function tagName() {
39
+ function tag() {
45
40
  return getBlockTag(useBlock());
46
41
  }
47
-
48
42
  function useBlock() {
49
43
  return repeatItemData() ? props.block : getProcessedBlock({
50
44
  block: props.block,
@@ -53,9 +47,9 @@ function RenderBlock(props) {
53
47
  shouldEvaluateBindings: true
54
48
  });
55
49
  }
56
-
57
50
  function attributes() {
58
- return { ...getBlockProperties(useBlock()),
51
+ return {
52
+ ...getBlockProperties(useBlock()),
59
53
  ...getBlockActions({
60
54
  block: useBlock(),
61
55
  state: props.context.state,
@@ -69,17 +63,15 @@ function RenderBlock(props) {
69
63
  } : {})
70
64
  };
71
65
  }
72
-
73
66
  function shouldWrap() {
74
67
  return !component()?.noWrap;
75
68
  }
76
-
77
69
  function renderComponentProps() {
78
70
  return {
79
- blockChildren: children(),
71
+ blockChildren: useChildren(),
80
72
  componentRef: component()?.component,
81
- componentOptions: { ...getBlockComponentOptions(useBlock()),
82
-
73
+ componentOptions: {
74
+ ...getBlockComponentOptions(useBlock()),
83
75
  /**
84
76
  * These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
85
77
  * they are provided to the component itself directly.
@@ -91,15 +83,13 @@ function RenderBlock(props) {
91
83
  context: childrenContext()
92
84
  };
93
85
  }
94
-
95
- function children() {
86
+ function useChildren() {
96
87
  // TO-DO: When should `canHaveChildren` dictate rendering?
97
88
  // This is currently commented out because some Builder components (e.g. Box) do not have `canHaveChildren: true`,
98
89
  // but still receive and need to render children.
99
90
  // return componentInfo?.canHaveChildren ? useBlock().children : [];
100
91
  return useBlock().children ?? [];
101
92
  }
102
-
103
93
  function childrenWithoutParentComponent() {
104
94
  /**
105
95
  * When there is no `componentRef`, there might still be children that need to be rendered. In this case,
@@ -108,9 +98,8 @@ function RenderBlock(props) {
108
98
  * blocks, and the children will be repeated within those blocks.
109
99
  */
110
100
  const shouldRenderChildrenOutsideRef = !component()?.component && !repeatItemData();
111
- return shouldRenderChildrenOutsideRef ? children() : [];
101
+ return shouldRenderChildrenOutsideRef ? useChildren() : [];
112
102
  }
113
-
114
103
  function repeatItemData() {
115
104
  /**
116
105
  * we don't use `useBlock()` here because the processing done within its logic includes evaluating the block's bindings,
@@ -120,26 +109,24 @@ function RenderBlock(props) {
120
109
  repeat,
121
110
  ...blockWithoutRepeat
122
111
  } = props.block;
123
-
124
112
  if (!repeat?.collection) {
125
113
  return undefined;
126
114
  }
127
-
128
115
  const itemsArray = evaluate({
129
116
  code: repeat.collection,
130
117
  state: props.context.state,
131
118
  context: props.context.context
132
119
  });
133
-
134
120
  if (!Array.isArray(itemsArray)) {
135
121
  return undefined;
136
122
  }
137
-
138
123
  const collectionName = repeat.collection.split(".").pop();
139
124
  const itemNameToUse = repeat.itemName || (collectionName ? collectionName + "Item" : "item");
140
125
  const repeatArray = itemsArray.map((item, index) => ({
141
- context: { ...props.context,
142
- state: { ...props.context.state,
126
+ context: {
127
+ ...props.context,
128
+ state: {
129
+ ...props.context.state,
143
130
  $index: index,
144
131
  $item: item,
145
132
  [itemNameToUse]: item,
@@ -150,19 +137,16 @@ function RenderBlock(props) {
150
137
  }));
151
138
  return repeatArray;
152
139
  }
153
-
154
140
  function inheritedTextStyles() {
155
141
  if (TARGET !== "reactNative") {
156
142
  return {};
157
143
  }
158
-
159
144
  const styles = getReactNativeBlockStyles({
160
145
  block: useBlock(),
161
146
  context: props.context
162
147
  });
163
148
  return extractTextStyles(styles);
164
149
  }
165
-
166
150
  function childrenContext() {
167
151
  return {
168
152
  apiKey: props.context.apiKey,
@@ -173,7 +157,6 @@ function RenderBlock(props) {
173
157
  inheritedStyles: inheritedTextStyles()
174
158
  };
175
159
  }
176
-
177
160
  function renderComponentTag() {
178
161
  if (TARGET === "reactNative") {
179
162
  return RenderComponentWithContext;
@@ -184,34 +167,30 @@ function RenderBlock(props) {
184
167
  return RenderComponent;
185
168
  }
186
169
  }
187
-
188
170
  return <Show fallback={<Dynamic {...renderComponentProps()} component={renderComponentTag()}></Dynamic>} when={shouldWrap()}>
189
- <Show when={isEmptyHtmlElement(tagName())}>
190
- <Dynamic {...attributes()} component={tagName()}></Dynamic>
171
+ <Show when={isEmptyHtmlElement(tag())}>
172
+ <Dynamic {...attributes()} component={tag()}></Dynamic>
191
173
  </Show>
192
- <Show when={!isEmptyHtmlElement(tagName()) && repeatItemData()}>
174
+ <Show when={!isEmptyHtmlElement(tag()) && repeatItemData()}>
193
175
  <For each={repeatItemData()}>
194
176
  {(data, _index) => {
195
177
  const index = _index();
196
-
197
178
  return <RenderRepeatedBlock key={index} repeatContext={data.context} block={data.block}></RenderRepeatedBlock>;
198
179
  }}
199
180
  </For>
200
181
  </Show>
201
- <Show when={!isEmptyHtmlElement(tagName()) && !repeatItemData()}>
202
- <Dynamic {...attributes()} component={tagName()}>
182
+ <Show when={!isEmptyHtmlElement(tag()) && !repeatItemData()}>
183
+ <Dynamic {...attributes()} component={tag()}>
203
184
  <Dynamic {...renderComponentProps()} component={renderComponentTag()}></Dynamic>
204
185
  <For each={childrenWithoutParentComponent()}>
205
186
  {(child, _index) => {
206
187
  const index = _index();
207
-
208
188
  return <RenderBlock key={"render-block-" + child.id} block={child} context={childrenContext()}></RenderBlock>;
209
189
  }}
210
190
  </For>
211
191
  <For each={childrenWithoutParentComponent()}>
212
192
  {(child, _index) => {
213
193
  const index = _index();
214
-
215
194
  return <BlockStyles key={"block-style-" + child.id} block={child} context={childrenContext()}></BlockStyles>;
216
195
  }}
217
196
  </For>
@@ -219,5 +198,4 @@ function RenderBlock(props) {
219
198
  </Show>
220
199
  </Show>;
221
200
  }
222
-
223
201
  export default RenderBlock;
@@ -1,36 +1,28 @@
1
1
  import { Dynamic } from "solid-js/web";
2
2
  import BuilderContext from "../../context/builder.context.js";
3
3
  import RenderComponent from "./render-component.jsx";
4
-
5
4
  function RenderComponentWithContext(props) {
6
5
  return <Dynamic value={{
7
6
  get content() {
8
7
  return props.context.content;
9
8
  },
10
-
11
9
  get state() {
12
10
  return props.context.state;
13
11
  },
14
-
15
12
  get context() {
16
13
  return props.context.context;
17
14
  },
18
-
19
15
  get apiKey() {
20
16
  return props.context.apiKey;
21
17
  },
22
-
23
18
  get registeredComponents() {
24
19
  return props.context.registeredComponents;
25
20
  },
26
-
27
21
  get inheritedStyles() {
28
22
  return props.context.inheritedStyles;
29
23
  }
30
-
31
24
  }} component={BuilderContext.Provider}>
32
25
  <RenderComponent componentRef={props.componentRef} componentOptions={props.componentOptions} blockChildren={props.blockChildren} context={props.context}></RenderComponent>
33
26
  </Dynamic>;
34
27
  }
35
-
36
28
  export default RenderComponentWithContext;
@@ -2,27 +2,22 @@ import { Show, For } from "solid-js";
2
2
  import { Dynamic } from "solid-js/web";
3
3
  import BlockStyles from "./block-styles.jsx";
4
4
  import RenderBlock from "./render-block.jsx";
5
- import { markPropsMutable } from "../../functions/mark-mutable.js";
6
-
7
5
  function RenderComponent(props) {
8
6
  return <Show when={props.componentRef}>
9
- <Dynamic {...markPropsMutable(props.componentOptions)} component={props.componentRef}>
7
+ <Dynamic {...props.componentOptions} component={props.componentRef}>
10
8
  <For each={props.blockChildren}>
11
9
  {(child, _index) => {
12
10
  const index = _index();
13
-
14
11
  return <RenderBlock key={"render-block-" + child.id} block={child} context={props.context}></RenderBlock>;
15
12
  }}
16
13
  </For>
17
14
  <For each={props.blockChildren}>
18
15
  {(child, _index) => {
19
16
  const index = _index();
20
-
21
17
  return <BlockStyles key={"block-style-" + child.id} block={child} context={props.context}></BlockStyles>;
22
18
  }}
23
19
  </For>
24
20
  </Dynamic>
25
21
  </Show>;
26
22
  }
27
-
28
23
  export default RenderComponent;
@@ -1,36 +1,28 @@
1
1
  import { Dynamic } from "solid-js/web";
2
2
  import BuilderContext from "../../context/builder.context.js";
3
3
  import RenderBlock from "./render-block.jsx";
4
-
5
4
  function RenderRepeatedBlock(props) {
6
5
  return <Dynamic value={{
7
6
  get content() {
8
7
  return props.repeatContext.content;
9
8
  },
10
-
11
9
  get state() {
12
10
  return props.repeatContext.state;
13
11
  },
14
-
15
12
  get context() {
16
13
  return props.repeatContext.context;
17
14
  },
18
-
19
15
  get apiKey() {
20
16
  return props.repeatContext.apiKey;
21
17
  },
22
-
23
18
  get registeredComponents() {
24
19
  return props.repeatContext.registeredComponents;
25
20
  },
26
-
27
21
  get inheritedStyles() {
28
22
  return props.repeatContext.inheritedStyles;
29
23
  }
30
-
31
24
  }} component={BuilderContext.Provider}>
32
25
  <RenderBlock block={props.block} context={props.repeatContext}></RenderBlock>
33
26
  </Dynamic>;
34
27
  }
35
-
36
28
  export default RenderRepeatedBlock;
@@ -4,12 +4,10 @@ import BuilderContext from "../context/builder.context.js";
4
4
  import { isEditing } from "../functions/is-editing.js";
5
5
  import BlockStyles from "./render-block/block-styles.jsx";
6
6
  import RenderBlock from "./render-block/render-block.jsx";
7
-
8
7
  function RenderBlocks(props) {
9
8
  function className() {
10
9
  return "builder-blocks" + (!props.blocks?.length ? " no-blocks" : "");
11
10
  }
12
-
13
11
  function onClick() {
14
12
  if (isEditing() && !props.blocks?.length) {
15
13
  window.parent?.postMessage({
@@ -21,7 +19,6 @@ function RenderBlocks(props) {
21
19
  }, "*");
22
20
  }
23
21
  }
24
-
25
22
  function onMouseEnter() {
26
23
  if (isEditing() && !props.blocks?.length) {
27
24
  window.parent?.postMessage({
@@ -33,7 +30,6 @@ function RenderBlocks(props) {
33
30
  }, "*");
34
31
  }
35
32
  }
36
-
37
33
  const builderContext = useContext(BuilderContext);
38
34
  return <div class={className() + " " + css({
39
35
  display: "flex",
@@ -46,7 +42,6 @@ function RenderBlocks(props) {
46
42
  <For each={props.blocks}>
47
43
  {(block, _index) => {
48
44
  const index = _index();
49
-
50
45
  return <RenderBlock key={"render-block-" + block.id} block={block} context={builderContext}></RenderBlock>;
51
46
  }}
52
47
  </For>
@@ -55,12 +50,10 @@ function RenderBlocks(props) {
55
50
  <For each={props.blocks}>
56
51
  {(block, _index) => {
57
52
  const index = _index();
58
-
59
53
  return <BlockStyles key={"block-style-" + block.id} block={block} context={builderContext}></BlockStyles>;
60
54
  }}
61
55
  </For>
62
56
  </Show>
63
57
  </div>;
64
58
  }
65
-
66
59
  export default RenderBlocks;
@@ -0,0 +1,4 @@
1
+ function BuilderEditing(props) {
2
+ return <div></div>;
3
+ }
4
+ export default BuilderEditing;
@@ -1,5 +1,4 @@
1
1
  import RenderInlinedStyles from "../../render-inlined-styles.jsx";
2
-
3
2
  function RenderContentStyles(props) {
4
3
  function getCssFromFont(font) {
5
4
  // TODO: compute what font sizes are used and only load those.......
@@ -7,7 +6,6 @@ function RenderContentStyles(props) {
7
6
  const name = family.split(",")[0];
8
7
  const url = font.fileUrl ?? font?.files?.regular;
9
8
  let str = "";
10
-
11
9
  if (url && family && name) {
12
10
  str += `
13
11
  @font-face {
@@ -18,18 +16,14 @@ function RenderContentStyles(props) {
18
16
  }
19
17
  `.trim();
20
18
  }
21
-
22
19
  if (font.files) {
23
20
  for (const weight in font.files) {
24
21
  const isNumber = String(Number(weight)) === weight;
25
-
26
22
  if (!isNumber) {
27
23
  continue;
28
- } // TODO: maybe limit number loaded
29
-
30
-
24
+ }
25
+ // TODO: maybe limit number loaded
31
26
  const weightUrl = font.files[weight];
32
-
33
27
  if (weightUrl && weightUrl !== url) {
34
28
  str += `
35
29
  @font-face {
@@ -42,10 +36,8 @@ function RenderContentStyles(props) {
42
36
  }
43
37
  }
44
38
  }
45
-
46
39
  return str;
47
40
  }
48
-
49
41
  function getFontCss({
50
42
  customFonts
51
43
  }) {
@@ -56,7 +48,6 @@ function RenderContentStyles(props) {
56
48
  // TODO: separate internal data from external
57
49
  return customFonts?.map(font => this.getCssFromFont(font))?.join(" ") || "";
58
50
  }
59
-
60
51
  function injectedStyles() {
61
52
  return `
62
53
  ${props.cssCode || ""}
@@ -64,8 +55,6 @@ ${getFontCss({
64
55
  customFonts: props.customFonts
65
56
  })}`;
66
57
  }
67
-
68
58
  return <RenderInlinedStyles styles={injectedStyles()}></RenderInlinedStyles>;
69
59
  }
70
-
71
60
  export default RenderContentStyles;