@builder.io/sdk-solid 0.0.8-0 → 0.0.8-11
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.
- package/package.json +11 -6
- package/src/blocks/button/button.jsx +1 -1
- package/src/blocks/button/button.lite.tsx +4 -1
- package/src/blocks/columns/columns.jsx +3 -3
- package/src/blocks/columns/columns.lite.tsx +30 -23
- package/src/blocks/custom-code/custom-code.jsx +1 -0
- package/src/blocks/custom-code/custom-code.lite.tsx +2 -0
- package/src/blocks/embed/embed.jsx +2 -1
- package/src/blocks/embed/embed.lite.tsx +3 -1
- package/src/blocks/form/form.jsx +1 -1
- package/src/blocks/form/form.lite.tsx +8 -5
- package/src/blocks/image/image.jsx +3 -3
- package/src/blocks/image/image.lite.tsx +10 -7
- package/src/blocks/symbol/component-info.js +1 -0
- package/src/blocks/symbol/symbol.jsx +2 -1
- package/src/blocks/symbol/symbol.lite.tsx +3 -1
- package/src/blocks/text/text.jsx +1 -1
- package/src/blocks/text/text.lite.tsx +1 -1
- package/src/components/render-block/block-styles.jsx +18 -3
- package/src/components/render-block/block-styles.lite.tsx +21 -3
- package/src/components/render-block/render-block.helpers.js +23 -0
- package/src/components/render-block/render-block.jsx +48 -31
- package/src/components/render-block/render-block.lite.tsx +74 -37
- package/src/components/render-block/render-component.jsx +27 -0
- package/src/components/render-block/render-component.lite.tsx +38 -0
- package/src/components/render-blocks.jsx +11 -1
- package/src/components/render-blocks.lite.tsx +20 -1
- package/src/components/render-content/index.js +4 -0
- package/src/components/render-content/render-content.jsx +32 -7
- package/src/components/render-content/render-content.lite.tsx +45 -15
- package/src/components/render-inlined-styles.jsx +2 -1
- package/src/components/render-inlined-styles.lite.tsx +4 -1
- package/src/constants/builder-registered-components.js +45 -0
- package/src/context/builder.context.js +2 -1
- package/src/functions/fast-clone.js +4 -0
- package/src/functions/get-block-component-options.js +6 -1
- package/src/functions/get-block-styles.js +2 -2
- package/src/functions/register-component.js +30 -13
- package/src/index-helpers/blocks-exports.js +9 -9
- package/src/solid-index.jsx +5 -0
- package/src/types/components.js +0 -0
- package/src/types/element.js +0 -0
- package/src/blocks/button/index.js +0 -7
- package/src/blocks/columns/index.js +0 -7
- package/src/blocks/custom-code/index.js +0 -7
- package/src/blocks/embed/index.js +0 -7
- package/src/blocks/form/index.js +0 -7
- package/src/blocks/fragment/index.js +0 -7
- package/src/blocks/image/index.js +0 -7
- package/src/blocks/img/index.js +0 -7
- package/src/blocks/input/index.js +0 -7
- package/src/blocks/raw-text/index.js +0 -7
- package/src/blocks/section/index.js +0 -7
- package/src/blocks/select/index.js +0 -7
- package/src/blocks/submit-button/index.js +0 -7
- package/src/blocks/symbol/index.js +0 -7
- package/src/blocks/text/index.js +0 -7
- package/src/blocks/textarea/index.js +0 -7
- package/src/blocks/video/index.js +0 -7
- package/src/functions/macro-eval.js +0 -5
package/package.json
CHANGED
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@builder.io/sdk-solid",
|
|
3
|
-
"version": "0.0.8-
|
|
4
|
-
"type": "module",
|
|
3
|
+
"version": "0.0.8-11",
|
|
5
4
|
"description": "",
|
|
6
|
-
"
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/solid-index.jsx",
|
|
7
|
+
"module": "./src/solid-index.jsx",
|
|
7
8
|
"exports": {
|
|
8
|
-
".": "./src/index.
|
|
9
|
+
".": "./src/solid-index.jsx"
|
|
9
10
|
},
|
|
10
11
|
"scripts": {
|
|
11
12
|
"release:dev": "npm version prerelease --no-git-tag-version && npm publish --tag dev --access public"
|
|
12
13
|
},
|
|
13
14
|
"dependencies": {
|
|
15
|
+
"node-fetch": "^2.6.7",
|
|
14
16
|
"solid-styled-components": "^0.27.6"
|
|
15
17
|
},
|
|
16
18
|
"peerDependencies": {
|
|
17
|
-
"solid-js": "^1.3
|
|
19
|
+
"solid-js": "^1.4.3"
|
|
18
20
|
},
|
|
19
21
|
"devDependencies": {
|
|
20
|
-
"solid
|
|
22
|
+
"babel-preset-solid": "^1.3.17",
|
|
23
|
+
"solid-js": "^1.4.3",
|
|
24
|
+
"vite": "^2.9.8",
|
|
25
|
+
"vite-plugin-solid": "^2.2.6"
|
|
21
26
|
}
|
|
22
27
|
}
|
|
@@ -2,7 +2,7 @@ import { Show } from "solid-js";
|
|
|
2
2
|
|
|
3
3
|
function Button(props) {
|
|
4
4
|
return <>
|
|
5
|
-
<Show when={props.link}>
|
|
5
|
+
<Show fallback={<span {...props.attributes}>{props.text}</span>} when={props.link}>
|
|
6
6
|
<a {...props.attributes} role="button" href={props.link} target={props.openLinkInNewTab ? "_blank" : undefined}>
|
|
7
7
|
{props.text}
|
|
8
8
|
</a>
|
|
@@ -51,7 +51,7 @@ function Columns(props) {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
});
|
|
54
|
-
return <div class={css({
|
|
54
|
+
return <div class={"builder-columns " + css({
|
|
55
55
|
display: "flex",
|
|
56
56
|
alignItems: "stretch",
|
|
57
57
|
lineHeight: "normal",
|
|
@@ -66,7 +66,7 @@ function Columns(props) {
|
|
|
66
66
|
{(column, _index) => {
|
|
67
67
|
const index = _index();
|
|
68
68
|
|
|
69
|
-
return <div class={css({
|
|
69
|
+
return <div class={"builder-column " + css({
|
|
70
70
|
flexGrow: "1",
|
|
71
71
|
"@media (max-width: 999px)": {
|
|
72
72
|
width: "var(--column-width-tablet) !important",
|
|
@@ -80,7 +80,7 @@ function Columns(props) {
|
|
|
80
80
|
width: state.getColumnCssWidth(index),
|
|
81
81
|
"margin-left": `${index === 0 ? 0 : state.getGutterSize()}px`,
|
|
82
82
|
...state.columnCssVars
|
|
83
|
-
}}>
|
|
83
|
+
}} key={index}>
|
|
84
84
|
<RenderBlocks blocks={column.blocks}></RenderBlocks>
|
|
85
85
|
</div>;
|
|
86
86
|
}}
|
|
@@ -24,7 +24,7 @@ function Columns(props) {
|
|
|
24
24
|
(gutterSize * (columns.length - 1)) / columns.length;
|
|
25
25
|
return `calc(${this.getWidth(index)}% - ${subtractWidth}px)`;
|
|
26
26
|
},
|
|
27
|
-
maybeApplyForTablet(prop:
|
|
27
|
+
maybeApplyForTablet(prop: CSSProperties["flexDirection"]) {
|
|
28
28
|
const _stackColumnsAt = props.stackColumnsAt || "tablet";
|
|
29
29
|
|
|
30
30
|
return _stackColumnsAt === "tablet" ? prop : "inherit";
|
|
@@ -55,17 +55,20 @@ function Columns(props) {
|
|
|
55
55
|
|
|
56
56
|
return (
|
|
57
57
|
<div
|
|
58
|
-
class={
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
58
|
+
class={
|
|
59
|
+
"builder-columns " +
|
|
60
|
+
css({
|
|
61
|
+
display: "flex",
|
|
62
|
+
alignItems: "stretch",
|
|
63
|
+
lineHeight: "normal",
|
|
64
|
+
"@media (max-width: 999px)": {
|
|
65
|
+
flexDirection: "var(--flex-dir-tablet)",
|
|
66
|
+
},
|
|
67
|
+
"@media (max-width: 639px)": {
|
|
68
|
+
flexDirection: "var(--flex-dir)",
|
|
69
|
+
},
|
|
70
|
+
})
|
|
71
|
+
}
|
|
69
72
|
style={state.columnsCssVars}
|
|
70
73
|
>
|
|
71
74
|
<For each={props.columns}>
|
|
@@ -73,22 +76,26 @@ function Columns(props) {
|
|
|
73
76
|
const index = _index();
|
|
74
77
|
return (
|
|
75
78
|
<div
|
|
76
|
-
class={
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
79
|
+
class={
|
|
80
|
+
"builder-column " +
|
|
81
|
+
css({
|
|
82
|
+
flexGrow: "1",
|
|
83
|
+
"@media (max-width: 999px)": {
|
|
84
|
+
width: "var(--column-width-tablet) !important",
|
|
85
|
+
marginLeft: "var(--column-margin-left-tablet) !important",
|
|
86
|
+
},
|
|
87
|
+
"@media (max-width: 639px)": {
|
|
88
|
+
width: "var(--column-width) !important",
|
|
89
|
+
marginLeft: "var(--column-margin-left) !important",
|
|
90
|
+
},
|
|
91
|
+
})
|
|
92
|
+
}
|
|
87
93
|
style={{
|
|
88
94
|
width: state.getColumnCssWidth(index),
|
|
89
95
|
"margin-left": `${index === 0 ? 0 : state.getGutterSize()}px`,
|
|
90
96
|
...state.columnCssVars,
|
|
91
97
|
}}
|
|
98
|
+
key={index}
|
|
92
99
|
>
|
|
93
100
|
<RenderBlocks blocks={column.blocks}></RenderBlocks>
|
|
94
101
|
</div>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { onMount } from "solid-js";
|
|
1
2
|
import { createMutable } from "solid-js/store";
|
|
2
3
|
|
|
3
4
|
function Embed(props) {
|
|
@@ -45,7 +46,7 @@ function Embed(props) {
|
|
|
45
46
|
onMount(() => {
|
|
46
47
|
state.findAndRunScripts();
|
|
47
48
|
});
|
|
48
|
-
return <div ref={elem} innerHTML={props.content}></div>;
|
|
49
|
+
return <div class="builder-embed" ref={elem} innerHTML={props.content}></div>;
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
export default Embed;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { onMount } from "solid-js";
|
|
2
|
+
|
|
1
3
|
import { createMutable } from "solid-js/store";
|
|
2
4
|
|
|
3
5
|
function Embed(props) {
|
|
@@ -53,7 +55,7 @@ function Embed(props) {
|
|
|
53
55
|
state.findAndRunScripts();
|
|
54
56
|
});
|
|
55
57
|
|
|
56
|
-
return <div ref={elem} innerHTML={props.content}></div>;
|
|
58
|
+
return <div class="builder-embed" ref={elem} innerHTML={props.content}></div>;
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
export default Embed;
|
package/src/blocks/form/form.jsx
CHANGED
|
@@ -236,7 +236,7 @@ function FormComponent(props) {
|
|
|
236
236
|
<BuilderBlocks dataPath="sendingMessage" blocks={props.sendingMessage}></BuilderBlocks>
|
|
237
237
|
</Show>
|
|
238
238
|
<Show when={state.submissionState === "error" && state.responseData}>
|
|
239
|
-
<pre class={css({
|
|
239
|
+
<pre class={"builder-form-error-text " + css({
|
|
240
240
|
padding: "10px",
|
|
241
241
|
color: "red",
|
|
242
242
|
textAlign: "center"
|
|
@@ -271,11 +271,14 @@ function FormComponent(props) {
|
|
|
271
271
|
</Show>
|
|
272
272
|
<Show when={state.submissionState === "error" && state.responseData}>
|
|
273
273
|
<pre
|
|
274
|
-
class={
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
274
|
+
class={
|
|
275
|
+
"builder-form-error-text " +
|
|
276
|
+
css({
|
|
277
|
+
padding: "10px",
|
|
278
|
+
color: "red",
|
|
279
|
+
textAlign: "center",
|
|
280
|
+
})
|
|
281
|
+
}
|
|
279
282
|
>
|
|
280
283
|
{JSON.stringify(state.responseData, null, 2)}
|
|
281
284
|
</pre>
|
|
@@ -14,14 +14,14 @@ function Image(props) {
|
|
|
14
14
|
width: "100%",
|
|
15
15
|
top: "0px",
|
|
16
16
|
left: "0px"
|
|
17
|
-
})} loading="lazy" alt={props.altText}
|
|
17
|
+
})} loading="lazy" alt={props.altText} role={props.altText ? "presentation" : undefined} style={{
|
|
18
18
|
"object-position": props.backgroundSize || "center",
|
|
19
19
|
"object-fit": props.backgroundSize || "cover"
|
|
20
|
-
}} src={props.image}
|
|
20
|
+
}} src={props.image} srcSet={props.srcset} sizes={props.sizes} />
|
|
21
21
|
<source srcSet={props.srcset} />
|
|
22
22
|
</picture>
|
|
23
23
|
<Show when={props.aspectRatio && !(props.fitContent && props.builderBlock?.children?.length)}>
|
|
24
|
-
<div class={css({
|
|
24
|
+
<div class={"builder-image-sizer " + css({
|
|
25
25
|
width: "100%",
|
|
26
26
|
pointerEvents: "none",
|
|
27
27
|
fontSize: "0"
|
|
@@ -27,13 +27,13 @@ function Image(props) {
|
|
|
27
27
|
}
|
|
28
28
|
loading="lazy"
|
|
29
29
|
alt={props.altText}
|
|
30
|
-
|
|
30
|
+
role={props.altText ? "presentation" : undefined}
|
|
31
31
|
style={{
|
|
32
32
|
"object-position": props.backgroundSize || "center",
|
|
33
33
|
"object-fit": props.backgroundSize || "cover",
|
|
34
34
|
}}
|
|
35
35
|
src={props.image}
|
|
36
|
-
|
|
36
|
+
srcSet={props.srcset}
|
|
37
37
|
sizes={props.sizes}
|
|
38
38
|
/>
|
|
39
39
|
<source srcSet={props.srcset} />
|
|
@@ -45,11 +45,14 @@ function Image(props) {
|
|
|
45
45
|
}
|
|
46
46
|
>
|
|
47
47
|
<div
|
|
48
|
-
class={
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
class={
|
|
49
|
+
"builder-image-sizer " +
|
|
50
|
+
css({
|
|
51
|
+
width: "100%",
|
|
52
|
+
pointerEvents: "none",
|
|
53
|
+
fontSize: "0",
|
|
54
|
+
})
|
|
55
|
+
}
|
|
53
56
|
style={{
|
|
54
57
|
"padding-top": props.aspectRatio * 100 + "%",
|
|
55
58
|
}}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useContext, onMount } from "solid-js";
|
|
1
2
|
import { createMutable } from "solid-js/store";
|
|
2
3
|
import RenderContent from "../../components/render-content/render-content";
|
|
3
4
|
import BuilderContext from "../../context/builder.context";
|
|
@@ -16,7 +17,7 @@ function Symbol(props) {
|
|
|
16
17
|
}}>
|
|
17
18
|
<RenderContent apiKey={builderContext.apiKey} context={builderContext.context} data={{ ...props.symbol?.data,
|
|
18
19
|
...builderContext.state,
|
|
19
|
-
...props.symbol?.
|
|
20
|
+
...props.symbol?.content?.data?.state
|
|
20
21
|
}} model={props.symbol?.model} content={state.content}></RenderContent>
|
|
21
22
|
</div>;
|
|
22
23
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { useContext, onMount } from "solid-js";
|
|
2
|
+
|
|
1
3
|
import { createMutable } from "solid-js/store";
|
|
2
4
|
|
|
3
5
|
import RenderContent from "../../components/render-content/render-content.lite";
|
|
@@ -27,7 +29,7 @@ function Symbol(props) {
|
|
|
27
29
|
data={{
|
|
28
30
|
...props.symbol?.data,
|
|
29
31
|
...builderContext.state,
|
|
30
|
-
...props.symbol?.
|
|
32
|
+
...props.symbol?.content?.data?.state,
|
|
31
33
|
}}
|
|
32
34
|
model={props.symbol?.model}
|
|
33
35
|
content={state.content}
|
package/src/blocks/text/text.jsx
CHANGED
|
@@ -1,21 +1,33 @@
|
|
|
1
|
+
import { useContext, Show } from "solid-js";
|
|
1
2
|
import { createMutable } from "solid-js/store";
|
|
3
|
+
import { TARGET } from "../../constants/target.js";
|
|
4
|
+
import BuilderContext from "../../context/builder.context";
|
|
5
|
+
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
2
6
|
import RenderInlinedStyles from "../render-inlined-styles";
|
|
3
7
|
|
|
4
8
|
function BlockStyles(props) {
|
|
5
9
|
const state = createMutable({
|
|
10
|
+
get useBlock() {
|
|
11
|
+
return getProcessedBlock({
|
|
12
|
+
block: props.block,
|
|
13
|
+
state: builderContext.state,
|
|
14
|
+
context: builderContext.context
|
|
15
|
+
});
|
|
16
|
+
},
|
|
17
|
+
|
|
6
18
|
camelToKebabCase(string) {
|
|
7
19
|
return string.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
|
|
8
20
|
},
|
|
9
21
|
|
|
10
22
|
get css() {
|
|
11
23
|
// TODO: media queries
|
|
12
|
-
const styleObject =
|
|
24
|
+
const styleObject = state.useBlock.responsiveStyles?.large;
|
|
13
25
|
|
|
14
26
|
if (!styleObject) {
|
|
15
27
|
return "";
|
|
16
28
|
}
|
|
17
29
|
|
|
18
|
-
let str = `.${
|
|
30
|
+
let str = `.${state.useBlock.id} {`;
|
|
19
31
|
|
|
20
32
|
for (const key in styleObject) {
|
|
21
33
|
const value = styleObject[key];
|
|
@@ -30,7 +42,10 @@ function BlockStyles(props) {
|
|
|
30
42
|
}
|
|
31
43
|
|
|
32
44
|
});
|
|
33
|
-
|
|
45
|
+
const builderContext = useContext(BuilderContext);
|
|
46
|
+
return <Show when={TARGET === "vue" || TARGET === "svelte"}>
|
|
47
|
+
<RenderInlinedStyles styles={state.css}></RenderInlinedStyles>
|
|
48
|
+
</Show>;
|
|
34
49
|
}
|
|
35
50
|
|
|
36
51
|
export default BlockStyles;
|
|
@@ -1,9 +1,21 @@
|
|
|
1
|
+
import { useContext, Show } from "solid-js";
|
|
2
|
+
|
|
1
3
|
import { createMutable } from "solid-js/store";
|
|
2
4
|
|
|
5
|
+
import { TARGET } from "../../constants/target.js";
|
|
6
|
+
import BuilderContext from "../../context/builder.context";
|
|
7
|
+
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
3
8
|
import RenderInlinedStyles from "../render-inlined-styles.lite";
|
|
4
9
|
|
|
5
10
|
function BlockStyles(props) {
|
|
6
11
|
const state = createMutable({
|
|
12
|
+
get useBlock() {
|
|
13
|
+
return getProcessedBlock({
|
|
14
|
+
block: props.block,
|
|
15
|
+
state: builderContext.state,
|
|
16
|
+
context: builderContext.context,
|
|
17
|
+
});
|
|
18
|
+
},
|
|
7
19
|
camelToKebabCase(string: string) {
|
|
8
20
|
return string
|
|
9
21
|
.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2")
|
|
@@ -11,13 +23,13 @@ function BlockStyles(props) {
|
|
|
11
23
|
},
|
|
12
24
|
get css() {
|
|
13
25
|
// TODO: media queries
|
|
14
|
-
const styleObject =
|
|
26
|
+
const styleObject = state.useBlock.responsiveStyles?.large;
|
|
15
27
|
|
|
16
28
|
if (!styleObject) {
|
|
17
29
|
return "";
|
|
18
30
|
}
|
|
19
31
|
|
|
20
|
-
let str = `.${
|
|
32
|
+
let str = `.${state.useBlock.id} {`;
|
|
21
33
|
|
|
22
34
|
for (const key in styleObject) {
|
|
23
35
|
const value = styleObject[key];
|
|
@@ -32,7 +44,13 @@ function BlockStyles(props) {
|
|
|
32
44
|
},
|
|
33
45
|
});
|
|
34
46
|
|
|
35
|
-
|
|
47
|
+
const builderContext = useContext(BuilderContext);
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<Show when={TARGET === "vue" || TARGET === "svelte"}>
|
|
51
|
+
<RenderInlinedStyles styles={state.css}></RenderInlinedStyles>
|
|
52
|
+
</Show>
|
|
53
|
+
);
|
|
36
54
|
}
|
|
37
55
|
|
|
38
56
|
export default BlockStyles;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const EMPTY_HTML_ELEMENTS = [
|
|
2
|
+
"area",
|
|
3
|
+
"base",
|
|
4
|
+
"br",
|
|
5
|
+
"col",
|
|
6
|
+
"embed",
|
|
7
|
+
"hr",
|
|
8
|
+
"img",
|
|
9
|
+
"input",
|
|
10
|
+
"keygen",
|
|
11
|
+
"link",
|
|
12
|
+
"meta",
|
|
13
|
+
"param",
|
|
14
|
+
"source",
|
|
15
|
+
"track",
|
|
16
|
+
"wbr"
|
|
17
|
+
];
|
|
18
|
+
const isEmptyHtmlElement = (tagName) => {
|
|
19
|
+
return typeof tagName === "string" && EMPTY_HTML_ELEMENTS.includes(tagName.toLowerCase());
|
|
20
|
+
};
|
|
21
|
+
export {
|
|
22
|
+
isEmptyHtmlElement
|
|
23
|
+
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { useContext, Show, For } from "solid-js";
|
|
2
2
|
import { Dynamic } from "solid-js/web";
|
|
3
3
|
import { createMutable } from "solid-js/store";
|
|
4
|
-
import { TARGET } from "../../constants/target.js";
|
|
5
4
|
import BuilderContext from "../../context/builder.context";
|
|
6
5
|
import { getBlockActions } from "../../functions/get-block-actions.js";
|
|
7
6
|
import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
|
|
@@ -9,8 +8,9 @@ import { getBlockProperties } from "../../functions/get-block-properties.js";
|
|
|
9
8
|
import { getBlockStyles } from "../../functions/get-block-styles.js";
|
|
10
9
|
import { getBlockTag } from "../../functions/get-block-tag.js";
|
|
11
10
|
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
12
|
-
import { components } from "../../functions/register-component.js";
|
|
13
11
|
import BlockStyles from "./block-styles";
|
|
12
|
+
import { isEmptyHtmlElement } from "./render-block.helpers.js";
|
|
13
|
+
import RenderComponent from "./render-component";
|
|
14
14
|
|
|
15
15
|
function RenderBlock(props) {
|
|
16
16
|
const state = createMutable({
|
|
@@ -21,20 +21,29 @@ function RenderBlock(props) {
|
|
|
21
21
|
return null;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
const ref =
|
|
24
|
+
const ref = builderContext.registeredComponents[componentName];
|
|
25
25
|
|
|
26
|
-
if (
|
|
26
|
+
if (!ref) {
|
|
27
27
|
// TODO: Public doc page with more info about this message
|
|
28
28
|
console.warn(`
|
|
29
29
|
Could not find a registered component named "${componentName}".
|
|
30
30
|
If you registered it, is the file that registered it imported by the file that needs to render it?`);
|
|
31
|
+
return undefined;
|
|
32
|
+
} else {
|
|
33
|
+
return ref;
|
|
31
34
|
}
|
|
32
|
-
|
|
33
|
-
return ref;
|
|
34
35
|
},
|
|
35
36
|
|
|
36
37
|
get componentInfo() {
|
|
37
|
-
|
|
38
|
+
if (state.component) {
|
|
39
|
+
const {
|
|
40
|
+
component: _,
|
|
41
|
+
...info
|
|
42
|
+
} = state.component;
|
|
43
|
+
return info;
|
|
44
|
+
} else {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
38
47
|
},
|
|
39
48
|
|
|
40
49
|
get componentRef() {
|
|
@@ -53,22 +62,32 @@ function RenderBlock(props) {
|
|
|
53
62
|
});
|
|
54
63
|
},
|
|
55
64
|
|
|
56
|
-
get
|
|
65
|
+
get attributes() {
|
|
57
66
|
return { ...getBlockProperties(state.useBlock),
|
|
58
67
|
...getBlockActions({
|
|
59
68
|
block: state.useBlock,
|
|
60
69
|
state: builderContext.state,
|
|
61
70
|
context: builderContext.context
|
|
62
|
-
})
|
|
71
|
+
}),
|
|
72
|
+
style: getBlockStyles(state.useBlock)
|
|
63
73
|
};
|
|
64
74
|
},
|
|
65
75
|
|
|
66
|
-
get
|
|
67
|
-
return
|
|
76
|
+
get shouldWrap() {
|
|
77
|
+
return !state.componentInfo?.noWrap;
|
|
68
78
|
},
|
|
69
79
|
|
|
70
80
|
get componentOptions() {
|
|
71
|
-
return getBlockComponentOptions(state.useBlock)
|
|
81
|
+
return { ...getBlockComponentOptions(state.useBlock),
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
|
|
85
|
+
* they are provided to the component itself directly.
|
|
86
|
+
*/
|
|
87
|
+
...(state.shouldWrap ? {} : {
|
|
88
|
+
attributes: state.attributes
|
|
89
|
+
})
|
|
90
|
+
};
|
|
72
91
|
},
|
|
73
92
|
|
|
74
93
|
get children() {
|
|
@@ -80,38 +99,36 @@ function RenderBlock(props) {
|
|
|
80
99
|
},
|
|
81
100
|
|
|
82
101
|
get noCompRefChildren() {
|
|
102
|
+
/**
|
|
103
|
+
* When there is no `componentRef`, there might still be children that need to be rendered. In this case,
|
|
104
|
+
* we render them outside of `componentRef`
|
|
105
|
+
*/
|
|
83
106
|
return state.componentRef ? [] : state.children;
|
|
84
107
|
}
|
|
85
108
|
|
|
86
109
|
});
|
|
87
110
|
const builderContext = useContext(BuilderContext);
|
|
88
|
-
return
|
|
89
|
-
<Show when={!state.
|
|
90
|
-
<Dynamic {...state.
|
|
91
|
-
<
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return <RenderBlock block={child}></RenderBlock>;
|
|
101
|
-
}}
|
|
102
|
-
</For>
|
|
103
|
-
</Dynamic>
|
|
104
|
-
</Show>
|
|
111
|
+
return <Show fallback={<RenderComponent blockChildren={state.children} componentRef={state.componentRef} componentOptions={state.componentOptions}></RenderComponent>} when={state.shouldWrap}>
|
|
112
|
+
<Show fallback={<Dynamic {...state.attributes} component={state.tagName}></Dynamic>} when={!isEmptyHtmlElement(state.tagName)}>
|
|
113
|
+
<Dynamic {...state.attributes} component={state.tagName}>
|
|
114
|
+
<RenderComponent blockChildren={state.children} componentRef={state.componentRef} componentOptions={state.componentOptions}></RenderComponent>
|
|
115
|
+
<For each={state.noCompRefChildren}>
|
|
116
|
+
{(child, _index) => {
|
|
117
|
+
const index = _index();
|
|
118
|
+
|
|
119
|
+
return <RenderBlock key={"render-block-" + child.id} block={child}></RenderBlock>;
|
|
120
|
+
}}
|
|
121
|
+
</For>
|
|
105
122
|
<For each={state.noCompRefChildren}>
|
|
106
123
|
{(child, _index) => {
|
|
107
124
|
const index = _index();
|
|
108
125
|
|
|
109
|
-
return <
|
|
126
|
+
return <BlockStyles key={"block-style-" + child.id} block={child}></BlockStyles>;
|
|
110
127
|
}}
|
|
111
128
|
</For>
|
|
112
129
|
</Dynamic>
|
|
113
130
|
</Show>
|
|
114
|
-
|
|
131
|
+
</Show>;
|
|
115
132
|
}
|
|
116
133
|
|
|
117
134
|
export default RenderBlock;
|