@builder.io/sdk-solid 0.0.5 → 0.0.8-0

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 (128) hide show
  1. package/package.json +9 -2
  2. package/src/blocks/button/button.jsx +13 -0
  3. package/src/blocks/button/button.lite.tsx +20 -0
  4. package/src/blocks/button/component-info.js +41 -0
  5. package/src/blocks/button/index.js +7 -0
  6. package/src/blocks/columns/columns.jsx +91 -0
  7. package/src/blocks/{columns.lite.tsx → columns/columns.lite.tsx} +32 -26
  8. package/src/blocks/columns/component-info.js +217 -0
  9. package/src/blocks/columns/index.js +7 -0
  10. package/src/blocks/custom-code/component-info.js +31 -0
  11. package/src/blocks/{custom-code.js → custom-code/custom-code.jsx} +5 -26
  12. package/src/blocks/{custom-code.lite.tsx → custom-code/custom-code.lite.tsx} +3 -1
  13. package/src/blocks/custom-code/index.js +7 -0
  14. package/src/blocks/embed/component-info.js +24 -0
  15. package/src/blocks/embed/embed.jsx +51 -0
  16. package/src/blocks/{embed.lite.tsx → embed/embed.lite.tsx} +3 -1
  17. package/src/blocks/embed/index.js +7 -0
  18. package/src/blocks/form/component-info.js +262 -0
  19. package/src/blocks/form/form.jsx +253 -0
  20. package/src/blocks/{form.lite.tsx → form/form.lite.tsx} +14 -8
  21. package/src/blocks/form/index.js +7 -0
  22. package/src/blocks/fragment/component-info.js +11 -0
  23. package/src/blocks/fragment/fragment.jsx +5 -0
  24. package/src/blocks/fragment/fragment.lite.tsx +5 -0
  25. package/src/blocks/fragment/index.js +7 -0
  26. package/src/blocks/image/component-info.js +104 -0
  27. package/src/blocks/image/image.jsx +54 -0
  28. package/src/blocks/image/image.lite.tsx +83 -0
  29. package/src/blocks/image/index.js +7 -0
  30. package/src/blocks/img/component-info.js +20 -0
  31. package/src/blocks/img/img.jsx +10 -0
  32. package/src/blocks/{img.lite.tsx → img/img.lite.tsx} +4 -2
  33. package/src/blocks/img/index.js +7 -0
  34. package/src/blocks/input/component-info.js +74 -0
  35. package/src/blocks/input/index.js +7 -0
  36. package/src/blocks/input/input.jsx +7 -0
  37. package/src/blocks/{input.lite.tsx → input/input.lite.tsx} +4 -2
  38. package/src/blocks/raw-text/component-info.js +16 -0
  39. package/src/blocks/raw-text/index.js +7 -0
  40. package/src/blocks/raw-text/raw-text.jsx +5 -0
  41. package/src/blocks/{raw-text.lite.tsx → raw-text/raw-text.lite.tsx} +3 -1
  42. package/src/blocks/section/component-info.js +49 -0
  43. package/src/blocks/section/index.js +7 -0
  44. package/src/blocks/section/section.jsx +9 -0
  45. package/src/blocks/{section.lite.tsx → section/section.lite.tsx} +3 -1
  46. package/src/blocks/select/component-info.js +59 -0
  47. package/src/blocks/select/index.js +7 -0
  48. package/src/blocks/select/select.jsx +16 -0
  49. package/src/blocks/{select.lite.tsx → select/select.lite.tsx} +10 -5
  50. package/src/blocks/submit-button/component-info.js +28 -0
  51. package/src/blocks/submit-button/index.js +7 -0
  52. package/src/blocks/submit-button/submit-button.jsx +7 -0
  53. package/src/blocks/{submit-button.lite.tsx → submit-button/submit-button.lite.tsx} +3 -1
  54. package/src/blocks/symbol/component-info.js +42 -0
  55. package/src/blocks/symbol/index.js +7 -0
  56. package/src/blocks/symbol/symbol.jsx +24 -0
  57. package/src/blocks/{symbol.lite.tsx → symbol/symbol.lite.tsx} +6 -4
  58. package/src/blocks/text/component-info.js +24 -0
  59. package/src/blocks/text/index.js +7 -0
  60. package/src/blocks/{text.lite.tsx → text/text.jsx} +3 -1
  61. package/src/blocks/text/text.lite.tsx +5 -0
  62. package/src/blocks/textarea/component-info.js +47 -0
  63. package/src/blocks/textarea/index.js +7 -0
  64. package/src/blocks/textarea/textarea.jsx +5 -0
  65. package/src/blocks/{textarea.lite.tsx → textarea/textarea.lite.tsx} +3 -1
  66. package/src/blocks/video/component-info.js +106 -0
  67. package/src/blocks/video/index.js +7 -0
  68. package/src/blocks/video/video.jsx +14 -0
  69. package/src/blocks/{video.lite.tsx → video/video.lite.tsx} +3 -1
  70. package/src/components/error-boundary.jsx +5 -0
  71. package/src/components/error-boundary.lite.tsx +3 -1
  72. package/src/components/render-block/block-styles.jsx +36 -0
  73. package/src/components/render-block/block-styles.lite.tsx +38 -0
  74. package/src/components/render-block/render-block.jsx +117 -0
  75. package/src/components/{render-block.lite.tsx → render-block/render-block.lite.tsx} +24 -13
  76. package/src/components/render-blocks.jsx +57 -0
  77. package/src/components/render-blocks.lite.tsx +9 -6
  78. package/src/components/render-content/components/{render-styles.js → render-styles.jsx} +8 -15
  79. package/src/components/render-content/components/render-styles.lite.tsx +10 -4
  80. package/src/components/render-content/{render-content.js → render-content.jsx} +42 -94
  81. package/src/components/render-content/render-content.lite.tsx +23 -20
  82. package/src/components/render-inlined-styles.jsx +23 -0
  83. package/src/components/render-inlined-styles.lite.tsx +26 -0
  84. package/src/functions/evaluate.js +2 -2
  85. package/src/functions/get-block-actions.js +2 -2
  86. package/src/functions/get-builder-search-params/fn.test.js +1 -1
  87. package/src/functions/get-content/index.js +3 -2
  88. package/src/functions/get-fetch.js +29 -7
  89. package/src/functions/get-processed-block.js +3 -3
  90. package/src/functions/get-processed-block.test.js +1 -1
  91. package/src/functions/if-target.js +1 -1
  92. package/src/functions/is-editing.js +1 -1
  93. package/src/functions/is-iframe.js +1 -1
  94. package/src/functions/is-previewing.js +2 -2
  95. package/src/functions/on-change.test.js +1 -1
  96. package/src/functions/previewing-model-name.js +1 -1
  97. package/src/functions/register-component.js +1 -1
  98. package/src/functions/register.js +1 -1
  99. package/src/functions/set-editor-settings.js +1 -1
  100. package/src/functions/set.test.js +1 -1
  101. package/src/functions/track.js +3 -3
  102. package/src/index-helpers/blocks-exports.js +8 -8
  103. package/src/index.js +10 -13
  104. package/src/scripts/init-editing.js +72 -63
  105. package/src/blocks/button.js +0 -32
  106. package/src/blocks/button.lite.tsx +0 -12
  107. package/src/blocks/columns.js +0 -133
  108. package/src/blocks/embed.js +0 -62
  109. package/src/blocks/form.js +0 -355
  110. package/src/blocks/fragment.js +0 -15
  111. package/src/blocks/fragment.lite.tsx +0 -3
  112. package/src/blocks/image.js +0 -211
  113. package/src/blocks/image.lite.tsx +0 -169
  114. package/src/blocks/img.js +0 -39
  115. package/src/blocks/input.js +0 -45
  116. package/src/blocks/raw-text.js +0 -25
  117. package/src/blocks/section.js +0 -24
  118. package/src/blocks/select.js +0 -57
  119. package/src/blocks/submit-button.js +0 -18
  120. package/src/blocks/symbol.js +0 -69
  121. package/src/blocks/text.js +0 -15
  122. package/src/blocks/textarea.js +0 -34
  123. package/src/blocks/video.js +0 -54
  124. package/src/components/block-styles.js +0 -3
  125. package/src/components/block-styles.lite.tsx +0 -3
  126. package/src/components/error-boundary.js +0 -3
  127. package/src/components/render-block.js +0 -154
  128. package/src/components/render-blocks.js +0 -104
@@ -0,0 +1,28 @@
1
+ const componentInfo = {
2
+ name: "Form:SubmitButton",
3
+ builtIn: true,
4
+ image: "https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2Fdf2820ffed1f4349a94c40b3221f5b98",
5
+ defaultStyles: {
6
+ appearance: "none",
7
+ paddingTop: "15px",
8
+ paddingBottom: "15px",
9
+ paddingLeft: "25px",
10
+ paddingRight: "25px",
11
+ backgroundColor: "#3898EC",
12
+ color: "white",
13
+ borderRadius: "4px",
14
+ cursor: "pointer"
15
+ },
16
+ inputs: [
17
+ {
18
+ name: "text",
19
+ type: "text",
20
+ defaultValue: "Click me"
21
+ }
22
+ ],
23
+ static: true,
24
+ noWrap: true
25
+ };
26
+ export {
27
+ componentInfo
28
+ };
@@ -0,0 +1,7 @@
1
+ import { registerComponent } from "../../functions/register-component.js";
2
+ import { componentInfo } from "./component-info.js";
3
+ import component from "./submit-button";
4
+ var stdin_default = registerComponent(component, componentInfo);
5
+ export {
6
+ stdin_default as default
7
+ };
@@ -0,0 +1,7 @@
1
+ function SubmitButton(props) {
2
+ return <button {...props.attributes} type="submit">
3
+ {props.text}
4
+ </button>;
5
+ }
6
+
7
+ export default SubmitButton;
@@ -1,7 +1,9 @@
1
- export default function SubmitButton(props) {
1
+ function SubmitButton(props) {
2
2
  return (
3
3
  <button {...props.attributes} type="submit">
4
4
  {props.text}
5
5
  </button>
6
6
  );
7
7
  }
8
+
9
+ export default SubmitButton;
@@ -0,0 +1,42 @@
1
+ const componentInfo = {
2
+ name: "Symbol",
3
+ noWrap: true,
4
+ static: true,
5
+ inputs: [
6
+ {
7
+ name: "symbol",
8
+ type: "uiSymbol"
9
+ },
10
+ {
11
+ name: "dataOnly",
12
+ helperText: "Make this a data symbol that doesn't display any UI",
13
+ type: "boolean",
14
+ defaultValue: false,
15
+ advanced: true,
16
+ hideFromUI: true
17
+ },
18
+ {
19
+ name: "inheritState",
20
+ helperText: "Inherit the parent component state and data",
21
+ type: "boolean",
22
+ defaultValue: false,
23
+ advanced: true
24
+ },
25
+ {
26
+ name: "renderToLiquid",
27
+ helperText: "Render this symbols contents to liquid. Turn off to fetch with javascript and use custom targeting",
28
+ type: "boolean",
29
+ defaultValue: false,
30
+ advanced: true,
31
+ hideFromUI: true
32
+ },
33
+ {
34
+ name: "useChildren",
35
+ hideFromUI: true,
36
+ type: "boolean"
37
+ }
38
+ ]
39
+ };
40
+ export {
41
+ componentInfo
42
+ };
@@ -0,0 +1,7 @@
1
+ import { registerComponent } from "../../functions/register-component.js";
2
+ import { componentInfo } from "./component-info.js";
3
+ import component from "./symbol";
4
+ var stdin_default = registerComponent(component, componentInfo);
5
+ export {
6
+ stdin_default as default
7
+ };
@@ -0,0 +1,24 @@
1
+ import { createMutable } from "solid-js/store";
2
+ import RenderContent from "../../components/render-content/render-content";
3
+ import BuilderContext from "../../context/builder.context";
4
+
5
+ function Symbol(props) {
6
+ const state = createMutable({
7
+ className: "builder-symbol",
8
+ content: null
9
+ });
10
+ const builderContext = useContext(BuilderContext);
11
+ onMount(() => {
12
+ state.content = props.symbol?.content;
13
+ });
14
+ return <div class={state.className} {...props.attributes} dataSet={{
15
+ class: state.className
16
+ }}>
17
+ <RenderContent apiKey={builderContext.apiKey} context={builderContext.context} data={{ ...props.symbol?.data,
18
+ ...builderContext.state,
19
+ ...props.symbol?.state.content?.data?.state
20
+ }} model={props.symbol?.model} content={state.content}></RenderContent>
21
+ </div>;
22
+ }
23
+
24
+ export default Symbol;
@@ -1,10 +1,10 @@
1
1
  import { createMutable } from "solid-js/store";
2
2
 
3
- import RenderContent from "../components/render-content/render-content.lite";
4
- import BuilderContext from "../context/builder.context";
5
- import { getContent } from "../functions/get-content";
3
+ import RenderContent from "../../components/render-content/render-content.lite";
4
+ import BuilderContext from "../../context/builder.context";
5
+ import { getContent } from "../../functions/get-content/index.js";
6
6
 
7
- export default function Symbol(props) {
7
+ function Symbol(props) {
8
8
  const state = createMutable({ className: "builder-symbol", content: null });
9
9
 
10
10
  const builderContext = useContext(BuilderContext);
@@ -35,3 +35,5 @@ export default function Symbol(props) {
35
35
  </div>
36
36
  );
37
37
  }
38
+
39
+ export default Symbol;
@@ -0,0 +1,24 @@
1
+ const componentInfo = {
2
+ name: "Text",
3
+ static: true,
4
+ builtIn: true,
5
+ image: "https://firebasestorage.googleapis.com/v0/b/builder-3b0a2.appspot.com/o/images%2Fbaseline-text_fields-24px%20(1).svg?alt=media&token=12177b73-0ee3-42ca-98c6-0dd003de1929",
6
+ inputs: [
7
+ {
8
+ name: "text",
9
+ type: "html",
10
+ required: true,
11
+ autoFocus: true,
12
+ bubble: true,
13
+ defaultValue: "Enter some text..."
14
+ }
15
+ ],
16
+ defaultStyles: {
17
+ lineHeight: "normal",
18
+ height: "auto",
19
+ textAlign: "center"
20
+ }
21
+ };
22
+ export {
23
+ componentInfo
24
+ };
@@ -0,0 +1,7 @@
1
+ import { registerComponent } from "../../functions/register-component.js";
2
+ import { componentInfo } from "./component-info.js";
3
+ import component from "./text";
4
+ var stdin_default = registerComponent(component, componentInfo);
5
+ export {
6
+ stdin_default as default
7
+ };
@@ -1,3 +1,5 @@
1
- export default function Text(props) {
1
+ function Text(props) {
2
2
  return <div innerHTML={props.text}></div>;
3
3
  }
4
+
5
+ export default Text;
@@ -0,0 +1,5 @@
1
+ function Text(props) {
2
+ return <div innerHTML={props.text}></div>;
3
+ }
4
+
5
+ export default Text;
@@ -0,0 +1,47 @@
1
+ const componentInfo = {
2
+ name: "Form:TextArea",
3
+ builtIn: true,
4
+ image: "https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2Ff74a2f3de58c4c3e939204e5b6b8f6c3",
5
+ inputs: [
6
+ {
7
+ advanced: true,
8
+ name: "value",
9
+ type: "string"
10
+ },
11
+ {
12
+ name: "name",
13
+ type: "string",
14
+ required: true,
15
+ helperText: 'Every input in a form needs a unique name describing what it gets, e.g. "email"'
16
+ },
17
+ {
18
+ name: "defaultValue",
19
+ type: "string"
20
+ },
21
+ {
22
+ name: "placeholder",
23
+ type: "string",
24
+ defaultValue: "Hello there"
25
+ },
26
+ {
27
+ name: "required",
28
+ type: "boolean",
29
+ defaultValue: false
30
+ }
31
+ ],
32
+ defaultStyles: {
33
+ paddingTop: "10px",
34
+ paddingBottom: "10px",
35
+ paddingLeft: "10px",
36
+ paddingRight: "10px",
37
+ borderRadius: "3px",
38
+ borderWidth: "1px",
39
+ borderStyle: "solid",
40
+ borderColor: "#ccc"
41
+ },
42
+ static: true,
43
+ noWrap: true
44
+ };
45
+ export {
46
+ componentInfo
47
+ };
@@ -0,0 +1,7 @@
1
+ import { registerComponent } from "../../functions/register-component.js";
2
+ import { componentInfo } from "./component-info.js";
3
+ import component from "./textarea";
4
+ var stdin_default = registerComponent(component, componentInfo);
5
+ export {
6
+ stdin_default as default
7
+ };
@@ -0,0 +1,5 @@
1
+ function Textarea(props) {
2
+ return <textarea {...props.attributes} placeholder={props.placeholder} name={props.name} value={props.value} defaultValue={props.defaultValue}></textarea>;
3
+ }
4
+
5
+ export default Textarea;
@@ -1,4 +1,4 @@
1
- export default function Textarea(props) {
1
+ function Textarea(props) {
2
2
  return (
3
3
  <textarea
4
4
  {...props.attributes}
@@ -9,3 +9,5 @@ export default function Textarea(props) {
9
9
  ></textarea>
10
10
  );
11
11
  }
12
+
13
+ export default Textarea;
@@ -0,0 +1,106 @@
1
+ const componentInfo = {
2
+ name: "Video",
3
+ canHaveChildren: true,
4
+ builtIn: true,
5
+ defaultStyles: {
6
+ minHeight: "20px",
7
+ minWidth: "20px"
8
+ },
9
+ image: "https://firebasestorage.googleapis.com/v0/b/builder-3b0a2.appspot.com/o/images%2Fbaseline-videocam-24px%20(1).svg?alt=media&token=49a84e4a-b20e-4977-a650-047f986874bb",
10
+ inputs: [
11
+ {
12
+ name: "video",
13
+ type: "file",
14
+ allowedFileTypes: ["mp4"],
15
+ bubble: true,
16
+ defaultValue: "https://firebasestorage.googleapis.com/v0/b/builder-3b0a2.appspot.com/o/assets%2FKQlEmWDxA0coC3PK6UvkrjwkIGI2%2F28cb070609f546cdbe5efa20e931aa4b?alt=media&token=912e9551-7a7c-4dfb-86b6-3da1537d1a7f",
17
+ required: true
18
+ },
19
+ {
20
+ name: "posterImage",
21
+ type: "file",
22
+ allowedFileTypes: ["jpeg", "png"],
23
+ helperText: "Image to show before the video plays"
24
+ },
25
+ {
26
+ name: "autoPlay",
27
+ type: "boolean",
28
+ defaultValue: true
29
+ },
30
+ {
31
+ name: "controls",
32
+ type: "boolean",
33
+ defaultValue: false
34
+ },
35
+ {
36
+ name: "muted",
37
+ type: "boolean",
38
+ defaultValue: true
39
+ },
40
+ {
41
+ name: "loop",
42
+ type: "boolean",
43
+ defaultValue: true
44
+ },
45
+ {
46
+ name: "playsInline",
47
+ type: "boolean",
48
+ defaultValue: true
49
+ },
50
+ {
51
+ name: "fit",
52
+ type: "text",
53
+ defaultValue: "cover",
54
+ enum: ["contain", "cover", "fill", "auto"]
55
+ },
56
+ {
57
+ name: "fitContent",
58
+ type: "boolean",
59
+ helperText: "When child blocks are provided, fit to them instead of using the aspect ratio",
60
+ defaultValue: true,
61
+ advanced: true
62
+ },
63
+ {
64
+ name: "position",
65
+ type: "text",
66
+ defaultValue: "center",
67
+ enum: [
68
+ "center",
69
+ "top",
70
+ "left",
71
+ "right",
72
+ "bottom",
73
+ "top left",
74
+ "top right",
75
+ "bottom left",
76
+ "bottom right"
77
+ ]
78
+ },
79
+ {
80
+ name: "height",
81
+ type: "number",
82
+ advanced: true
83
+ },
84
+ {
85
+ name: "width",
86
+ type: "number",
87
+ advanced: true
88
+ },
89
+ {
90
+ name: "aspectRatio",
91
+ type: "number",
92
+ advanced: true,
93
+ defaultValue: 0.7004048582995948
94
+ },
95
+ {
96
+ name: "lazyLoad",
97
+ type: "boolean",
98
+ helperText: 'Load this video "lazily" - as in only when a user scrolls near the video. Recommended for optmized performance and bandwidth consumption',
99
+ defaultValue: true,
100
+ advanced: true
101
+ }
102
+ ]
103
+ };
104
+ export {
105
+ componentInfo
106
+ };
@@ -0,0 +1,7 @@
1
+ import { registerComponent } from "../../functions/register-component.js";
2
+ import { componentInfo } from "./component-info.js";
3
+ import component from "./video";
4
+ var stdin_default = registerComponent(component, componentInfo);
5
+ export {
6
+ stdin_default as default
7
+ };
@@ -0,0 +1,14 @@
1
+ function Video(props) {
2
+ return <video {...props.attributes} preload="none" style={{
3
+ width: "100%",
4
+ height: "100%",
5
+ ...props.attributes?.style,
6
+ "object-fit": props.fit,
7
+ "object-position": props.position,
8
+ // Hack to get object fit to work as expected and
9
+ // not have the video overflow
10
+ "border-radius": 1
11
+ }} key={props.video || "no-src"} poster={props.posterImage} autoPlay={props.autoPlay} muted={props.muted} controls={props.controls} loop={props.loop}></video>;
12
+ }
13
+
14
+ export default Video;
@@ -1,4 +1,4 @@
1
- export default function Video(props) {
1
+ function Video(props) {
2
2
  return (
3
3
  <video
4
4
  {...props.attributes}
@@ -22,3 +22,5 @@ export default function Video(props) {
22
22
  ></video>
23
23
  );
24
24
  }
25
+
26
+ export default Video;
@@ -0,0 +1,5 @@
1
+ function ErrorBoundary(props) {
2
+ return <></>;
3
+ }
4
+
5
+ export default ErrorBoundary;
@@ -1,3 +1,5 @@
1
- export default function ErrorBoundary(props) {
1
+ function ErrorBoundary(props) {
2
2
  return <></>;
3
3
  }
4
+
5
+ export default ErrorBoundary;
@@ -0,0 +1,36 @@
1
+ import { createMutable } from "solid-js/store";
2
+ import RenderInlinedStyles from "../render-inlined-styles";
3
+
4
+ function BlockStyles(props) {
5
+ const state = createMutable({
6
+ camelToKebabCase(string) {
7
+ return string.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
8
+ },
9
+
10
+ get css() {
11
+ // TODO: media queries
12
+ const styleObject = props.block.responsiveStyles?.large;
13
+
14
+ if (!styleObject) {
15
+ return "";
16
+ }
17
+
18
+ let str = `.${props.block.id} {`;
19
+
20
+ for (const key in styleObject) {
21
+ const value = styleObject[key];
22
+
23
+ if (typeof value === "string") {
24
+ str += `${state.camelToKebabCase(key)}: ${value};`;
25
+ }
26
+ }
27
+
28
+ str += "}";
29
+ return str;
30
+ }
31
+
32
+ });
33
+ return <RenderInlinedStyles styles={state.css}></RenderInlinedStyles>;
34
+ }
35
+
36
+ export default BlockStyles;
@@ -0,0 +1,38 @@
1
+ import { createMutable } from "solid-js/store";
2
+
3
+ import RenderInlinedStyles from "../render-inlined-styles.lite";
4
+
5
+ function BlockStyles(props) {
6
+ const state = createMutable({
7
+ camelToKebabCase(string: string) {
8
+ return string
9
+ .replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2")
10
+ .toLowerCase();
11
+ },
12
+ get css() {
13
+ // TODO: media queries
14
+ const styleObject = props.block.responsiveStyles?.large;
15
+
16
+ if (!styleObject) {
17
+ return "";
18
+ }
19
+
20
+ let str = `.${props.block.id} {`;
21
+
22
+ for (const key in styleObject) {
23
+ const value = styleObject[key];
24
+
25
+ if (typeof value === "string") {
26
+ str += `${state.camelToKebabCase(key)}: ${value};`;
27
+ }
28
+ }
29
+
30
+ str += "}";
31
+ return str;
32
+ },
33
+ });
34
+
35
+ return <RenderInlinedStyles styles={state.css}></RenderInlinedStyles>;
36
+ }
37
+
38
+ export default BlockStyles;
@@ -0,0 +1,117 @@
1
+ import { useContext, Show, For } from "solid-js";
2
+ import { Dynamic } from "solid-js/web";
3
+ import { createMutable } from "solid-js/store";
4
+ import { TARGET } from "../../constants/target.js";
5
+ import BuilderContext from "../../context/builder.context";
6
+ import { getBlockActions } from "../../functions/get-block-actions.js";
7
+ import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
8
+ import { getBlockProperties } from "../../functions/get-block-properties.js";
9
+ import { getBlockStyles } from "../../functions/get-block-styles.js";
10
+ import { getBlockTag } from "../../functions/get-block-tag.js";
11
+ import { getProcessedBlock } from "../../functions/get-processed-block.js";
12
+ import { components } from "../../functions/register-component.js";
13
+ import BlockStyles from "./block-styles";
14
+
15
+ function RenderBlock(props) {
16
+ const state = createMutable({
17
+ get component() {
18
+ const componentName = state.useBlock.component?.name;
19
+
20
+ if (!componentName) {
21
+ return null;
22
+ }
23
+
24
+ const ref = components[componentName];
25
+
26
+ if (componentName && !ref) {
27
+ // TODO: Public doc page with more info about this message
28
+ console.warn(`
29
+ Could not find a registered component named "${componentName}".
30
+ If you registered it, is the file that registered it imported by the file that needs to render it?`);
31
+ }
32
+
33
+ return ref;
34
+ },
35
+
36
+ get componentInfo() {
37
+ return state.component?.info;
38
+ },
39
+
40
+ get componentRef() {
41
+ return state.component?.component;
42
+ },
43
+
44
+ get tagName() {
45
+ return getBlockTag(state.useBlock);
46
+ },
47
+
48
+ get useBlock() {
49
+ return getProcessedBlock({
50
+ block: props.block,
51
+ state: builderContext.state,
52
+ context: builderContext.context
53
+ });
54
+ },
55
+
56
+ get propertiesAndActions() {
57
+ return { ...getBlockProperties(state.useBlock),
58
+ ...getBlockActions({
59
+ block: state.useBlock,
60
+ state: builderContext.state,
61
+ context: builderContext.context
62
+ })
63
+ };
64
+ },
65
+
66
+ get css() {
67
+ return getBlockStyles(state.useBlock);
68
+ },
69
+
70
+ get componentOptions() {
71
+ return getBlockComponentOptions(state.useBlock);
72
+ },
73
+
74
+ get children() {
75
+ // TO-DO: When should `canHaveChildren` dictate rendering?
76
+ // This is currently commented out because some Builder components (e.g. Box) do not have `canHaveChildren: true`,
77
+ // but still receive and need to render children.
78
+ // return state.componentInfo?.canHaveChildren ? state.useBlock.children : [];
79
+ return state.useBlock.children ?? [];
80
+ },
81
+
82
+ get noCompRefChildren() {
83
+ return state.componentRef ? [] : state.children;
84
+ }
85
+
86
+ });
87
+ const builderContext = useContext(BuilderContext);
88
+ return <>
89
+ <Show when={!state.componentInfo?.noWrap}>
90
+ <Dynamic {...state.propertiesAndActions} style={state.css} component={state.tagName}>
91
+ <Show when={TARGET === "vue" || TARGET === "svelte"}>
92
+ <BlockStyles block={state.useBlock}></BlockStyles>
93
+ </Show>
94
+ <Show when={state.componentRef}>
95
+ <Dynamic {...state.componentOptions} builderBlock={state.useBlock} component={state.componentRef}>
96
+ <For each={state.children}>
97
+ {(child, _index) => {
98
+ const index = _index();
99
+
100
+ return <RenderBlock block={child}></RenderBlock>;
101
+ }}
102
+ </For>
103
+ </Dynamic>
104
+ </Show>
105
+ <For each={state.noCompRefChildren}>
106
+ {(child, _index) => {
107
+ const index = _index();
108
+
109
+ return <RenderBlock block={child}></RenderBlock>;
110
+ }}
111
+ </For>
112
+ </Dynamic>
113
+ </Show>
114
+ </>;
115
+ }
116
+
117
+ export default RenderBlock;