@builder.io/sdk-solid 0.0.20 → 0.0.22

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 (44) hide show
  1. package/package.json +2 -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 +19 -17
  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 +28 -45
  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 +32 -54
  33. package/src/components/render-inlined-styles.jsx +3 -7
  34. package/src/constants/device-sizes.js +29 -2
  35. package/src/functions/evaluate.js +4 -3
  36. package/src/functions/get-block-actions-handler.js +8 -9
  37. package/src/functions/get-block-actions.js +2 -2
  38. package/src/functions/get-builder-search-params/index.js +2 -1
  39. package/src/functions/get-content/index.js +8 -3
  40. package/src/functions/register-component.js +1 -5
  41. package/src/functions/track.js +4 -0
  42. package/src/index.js +1 -1
  43. package/src/scripts/init-editing.js +17 -5
  44. package/src/functions/mark-mutable.js +0 -10
@@ -1,5 +1,4 @@
1
1
  function Textarea(props) {
2
2
  return <textarea {...props.attributes} placeholder={props.placeholder} name={props.name} value={props.value} defaultValue={props.defaultValue}></textarea>;
3
3
  }
4
-
5
4
  export default Textarea;
@@ -1,7 +1,8 @@
1
- function markSerializable(fn) {
2
- fn.__qwik_serializable__ = true;
3
- return fn;
4
- }
1
+ const serializeFn = (fnValue) => {
2
+ const fnStr = fnValue.toString().trim();
3
+ const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("(");
4
+ return `return (${appendFunction ? "function " : ""}${fnStr}).apply(this, arguments)`;
5
+ };
5
6
  export {
6
- markSerializable
7
+ serializeFn
7
8
  };
@@ -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,14 +47,16 @@ function RenderBlock(props) {
53
47
  shouldEvaluateBindings: true
54
48
  });
55
49
  }
56
-
50
+ function actions() {
51
+ return getBlockActions({
52
+ block: useBlock(),
53
+ state: props.context.state,
54
+ context: props.context.context
55
+ });
56
+ }
57
57
  function attributes() {
58
- return { ...getBlockProperties(useBlock()),
59
- ...getBlockActions({
60
- block: useBlock(),
61
- state: props.context.state,
62
- context: props.context.context
63
- }),
58
+ return {
59
+ ...getBlockProperties(useBlock()),
64
60
  ...(TARGET === "reactNative" ? {
65
61
  style: getReactNativeBlockStyles({
66
62
  block: useBlock(),
@@ -69,37 +65,36 @@ function RenderBlock(props) {
69
65
  } : {})
70
66
  };
71
67
  }
72
-
73
68
  function shouldWrap() {
74
69
  return !component()?.noWrap;
75
70
  }
76
-
77
71
  function renderComponentProps() {
78
72
  return {
79
- blockChildren: children(),
73
+ blockChildren: useChildren(),
80
74
  componentRef: component()?.component,
81
- componentOptions: { ...getBlockComponentOptions(useBlock()),
82
-
75
+ componentOptions: {
76
+ ...getBlockComponentOptions(useBlock()),
83
77
  /**
84
78
  * These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
85
79
  * they are provided to the component itself directly.
86
80
  */
87
81
  ...(shouldWrap() ? {} : {
88
- attributes: attributes()
82
+ attributes: {
83
+ ...attributes(),
84
+ ...actions()
85
+ }
89
86
  })
90
87
  },
91
88
  context: childrenContext()
92
89
  };
93
90
  }
94
-
95
- function children() {
91
+ function useChildren() {
96
92
  // TO-DO: When should `canHaveChildren` dictate rendering?
97
93
  // This is currently commented out because some Builder components (e.g. Box) do not have `canHaveChildren: true`,
98
94
  // but still receive and need to render children.
99
95
  // return componentInfo?.canHaveChildren ? useBlock().children : [];
100
96
  return useBlock().children ?? [];
101
97
  }
102
-
103
98
  function childrenWithoutParentComponent() {
104
99
  /**
105
100
  * When there is no `componentRef`, there might still be children that need to be rendered. In this case,
@@ -108,9 +103,8 @@ function RenderBlock(props) {
108
103
  * blocks, and the children will be repeated within those blocks.
109
104
  */
110
105
  const shouldRenderChildrenOutsideRef = !component()?.component && !repeatItemData();
111
- return shouldRenderChildrenOutsideRef ? children() : [];
106
+ return shouldRenderChildrenOutsideRef ? useChildren() : [];
112
107
  }
113
-
114
108
  function repeatItemData() {
115
109
  /**
116
110
  * we don't use `useBlock()` here because the processing done within its logic includes evaluating the block's bindings,
@@ -120,26 +114,24 @@ function RenderBlock(props) {
120
114
  repeat,
121
115
  ...blockWithoutRepeat
122
116
  } = props.block;
123
-
124
117
  if (!repeat?.collection) {
125
118
  return undefined;
126
119
  }
127
-
128
120
  const itemsArray = evaluate({
129
121
  code: repeat.collection,
130
122
  state: props.context.state,
131
123
  context: props.context.context
132
124
  });
133
-
134
125
  if (!Array.isArray(itemsArray)) {
135
126
  return undefined;
136
127
  }
137
-
138
128
  const collectionName = repeat.collection.split(".").pop();
139
129
  const itemNameToUse = repeat.itemName || (collectionName ? collectionName + "Item" : "item");
140
130
  const repeatArray = itemsArray.map((item, index) => ({
141
- context: { ...props.context,
142
- state: { ...props.context.state,
131
+ context: {
132
+ ...props.context,
133
+ state: {
134
+ ...props.context.state,
143
135
  $index: index,
144
136
  $item: item,
145
137
  [itemNameToUse]: item,
@@ -150,19 +142,16 @@ function RenderBlock(props) {
150
142
  }));
151
143
  return repeatArray;
152
144
  }
153
-
154
145
  function inheritedTextStyles() {
155
146
  if (TARGET !== "reactNative") {
156
147
  return {};
157
148
  }
158
-
159
149
  const styles = getReactNativeBlockStyles({
160
150
  block: useBlock(),
161
151
  context: props.context
162
152
  });
163
153
  return extractTextStyles(styles);
164
154
  }
165
-
166
155
  function childrenContext() {
167
156
  return {
168
157
  apiKey: props.context.apiKey,
@@ -173,7 +162,6 @@ function RenderBlock(props) {
173
162
  inheritedStyles: inheritedTextStyles()
174
163
  };
175
164
  }
176
-
177
165
  function renderComponentTag() {
178
166
  if (TARGET === "reactNative") {
179
167
  return RenderComponentWithContext;
@@ -184,34 +172,30 @@ function RenderBlock(props) {
184
172
  return RenderComponent;
185
173
  }
186
174
  }
187
-
188
175
  return <Show fallback={<Dynamic {...renderComponentProps()} component={renderComponentTag()}></Dynamic>} when={shouldWrap()}>
189
- <Show when={isEmptyHtmlElement(tagName())}>
190
- <Dynamic {...attributes()} component={tagName()}></Dynamic>
176
+ <Show when={isEmptyHtmlElement(tag())}>
177
+ <Dynamic {...attributes()} {...actions()} component={tag()}></Dynamic>
191
178
  </Show>
192
- <Show when={!isEmptyHtmlElement(tagName()) && repeatItemData()}>
179
+ <Show when={!isEmptyHtmlElement(tag()) && repeatItemData()}>
193
180
  <For each={repeatItemData()}>
194
181
  {(data, _index) => {
195
182
  const index = _index();
196
-
197
183
  return <RenderRepeatedBlock key={index} repeatContext={data.context} block={data.block}></RenderRepeatedBlock>;
198
184
  }}
199
185
  </For>
200
186
  </Show>
201
- <Show when={!isEmptyHtmlElement(tagName()) && !repeatItemData()}>
202
- <Dynamic {...attributes()} component={tagName()}>
187
+ <Show when={!isEmptyHtmlElement(tag()) && !repeatItemData()}>
188
+ <Dynamic {...attributes()} {...actions()} component={tag()}>
203
189
  <Dynamic {...renderComponentProps()} component={renderComponentTag()}></Dynamic>
204
190
  <For each={childrenWithoutParentComponent()}>
205
191
  {(child, _index) => {
206
192
  const index = _index();
207
-
208
193
  return <RenderBlock key={"render-block-" + child.id} block={child} context={childrenContext()}></RenderBlock>;
209
194
  }}
210
195
  </For>
211
196
  <For each={childrenWithoutParentComponent()}>
212
197
  {(child, _index) => {
213
198
  const index = _index();
214
-
215
199
  return <BlockStyles key={"block-style-" + child.id} block={child} context={childrenContext()}></BlockStyles>;
216
200
  }}
217
201
  </For>
@@ -219,5 +203,4 @@ function RenderBlock(props) {
219
203
  </Show>
220
204
  </Show>;
221
205
  }
222
-
223
206
  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;