@builder.io/sdk-solid 0.0.7 → 0.0.8-10
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 +16 -5
- package/src/blocks/button/button.jsx +13 -0
- package/src/blocks/button/button.lite.tsx +23 -0
- package/src/blocks/button/component-info.js +41 -0
- package/src/blocks/columns/columns.jsx +91 -0
- package/src/blocks/{columns.lite.tsx → columns/columns.lite.tsx} +34 -26
- package/src/blocks/columns/component-info.js +217 -0
- package/src/blocks/custom-code/component-info.js +31 -0
- package/src/blocks/{custom-code.jsx → custom-code/custom-code.jsx} +2 -2
- package/src/blocks/{custom-code.lite.tsx → custom-code/custom-code.lite.tsx} +2 -0
- package/src/blocks/embed/component-info.js +24 -0
- package/src/blocks/{embed.jsx → embed/embed.jsx} +3 -3
- package/src/blocks/{embed.lite.tsx → embed/embed.lite.tsx} +3 -1
- package/src/blocks/form/component-info.js +262 -0
- package/src/blocks/{form.jsx → form/form.jsx} +9 -9
- package/src/blocks/{form.lite.tsx → form/form.lite.tsx} +15 -11
- package/src/blocks/fragment/component-info.js +11 -0
- package/src/blocks/fragment/fragment.jsx +5 -0
- package/src/blocks/{fragment.lite.tsx → fragment/fragment.lite.tsx} +0 -0
- package/src/blocks/image/component-info.js +104 -0
- package/src/blocks/image/image.jsx +54 -0
- package/src/blocks/image/image.lite.tsx +86 -0
- package/src/blocks/img/component-info.js +20 -0
- package/src/blocks/img/img.jsx +10 -0
- package/src/blocks/{img.lite.tsx → img/img.lite.tsx} +1 -1
- package/src/blocks/input/component-info.js +74 -0
- package/src/blocks/input/input.jsx +7 -0
- package/src/blocks/{input.lite.tsx → input/input.lite.tsx} +1 -1
- package/src/blocks/raw-text/component-info.js +16 -0
- package/src/blocks/raw-text/raw-text.jsx +5 -0
- package/src/blocks/{raw-text.lite.tsx → raw-text/raw-text.lite.tsx} +0 -0
- package/src/blocks/section/component-info.js +49 -0
- package/src/blocks/section/section.jsx +9 -0
- package/src/blocks/{section.lite.tsx → section/section.lite.tsx} +0 -0
- package/src/blocks/select/component-info.js +59 -0
- package/src/blocks/select/select.jsx +16 -0
- package/src/blocks/{select.lite.tsx → select/select.lite.tsx} +1 -1
- package/src/blocks/submit-button/component-info.js +28 -0
- package/src/blocks/submit-button/submit-button.jsx +7 -0
- package/src/blocks/{submit-button.lite.tsx → submit-button/submit-button.lite.tsx} +0 -0
- package/src/blocks/symbol/component-info.js +43 -0
- package/src/blocks/symbol/symbol.jsx +25 -0
- package/src/blocks/{symbol.lite.tsx → symbol/symbol.lite.tsx} +6 -4
- package/src/blocks/text/component-info.js +24 -0
- package/src/blocks/text/text.jsx +5 -0
- package/src/blocks/text/text.lite.tsx +5 -0
- package/src/blocks/textarea/component-info.js +47 -0
- package/src/blocks/textarea/textarea.jsx +5 -0
- package/src/blocks/{textarea.lite.tsx → textarea/textarea.lite.tsx} +0 -0
- package/src/blocks/video/component-info.js +106 -0
- package/src/blocks/video/video.jsx +14 -0
- package/src/blocks/{video.lite.tsx → video/video.lite.tsx} +0 -0
- package/src/components/render-block/block-styles.jsx +36 -0
- package/src/components/render-block/block-styles.lite.tsx +38 -0
- package/src/components/render-block/render-block.helpers.js +23 -0
- package/src/components/{render-block.jsx → render-block/render-block.jsx} +40 -22
- package/src/components/{render-block.lite.tsx → render-block/render-block.lite.tsx} +57 -19
- package/src/components/render-blocks.jsx +2 -2
- package/src/components/render-blocks.lite.tsx +2 -2
- package/src/components/render-content/components/render-styles.jsx +6 -5
- package/src/components/render-content/components/render-styles.lite.tsx +9 -5
- package/src/components/render-content/index.js +4 -0
- package/src/components/render-content/render-content.jsx +50 -24
- package/src/components/render-content/render-content.lite.tsx +64 -33
- package/src/components/render-inlined-styles.jsx +24 -0
- package/src/components/render-inlined-styles.lite.tsx +29 -0
- package/src/constants/builder-registered-components.js +45 -0
- package/src/context/builder.context.js +2 -1
- package/src/functions/evaluate.js +2 -2
- package/src/functions/fast-clone.js +4 -0
- package/src/functions/get-block-actions.js +2 -2
- package/src/functions/get-block-styles.js +2 -2
- package/src/functions/get-builder-search-params/fn.test.js +1 -1
- package/src/functions/get-content/index.js +3 -2
- package/src/functions/get-fetch.js +29 -7
- package/src/functions/get-processed-block.js +3 -3
- package/src/functions/get-processed-block.test.js +1 -1
- package/src/functions/if-target.js +1 -1
- package/src/functions/is-editing.js +1 -1
- package/src/functions/is-iframe.js +1 -1
- package/src/functions/is-previewing.js +2 -2
- package/src/functions/on-change.test.js +1 -1
- package/src/functions/previewing-model-name.js +1 -1
- package/src/functions/register-component.js +30 -13
- package/src/functions/register.js +1 -1
- package/src/functions/set-editor-settings.js +1 -1
- package/src/functions/set.test.js +1 -1
- package/src/functions/track.js +3 -3
- package/src/index-helpers/blocks-exports.js +9 -9
- package/src/index.js +10 -13
- package/src/scripts/init-editing.js +72 -63
- 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.jsx +0 -8
- package/src/blocks/button.lite.tsx +0 -14
- package/src/blocks/columns.jsx +0 -96
- package/src/blocks/fragment.jsx +0 -6
- package/src/blocks/image.jsx +0 -120
- package/src/blocks/image.lite.tsx +0 -171
- package/src/blocks/img.jsx +0 -11
- package/src/blocks/input.jsx +0 -8
- package/src/blocks/raw-text.jsx +0 -6
- package/src/blocks/section.jsx +0 -10
- package/src/blocks/select.jsx +0 -17
- package/src/blocks/submit-button.jsx +0 -8
- package/src/blocks/symbol.jsx +0 -25
- package/src/blocks/text.jsx +0 -6
- package/src/blocks/text.lite.tsx +0 -5
- package/src/blocks/textarea.jsx +0 -6
- package/src/blocks/video.jsx +0 -15
- package/src/components/block-styles.jsx +0 -5
- package/src/components/block-styles.lite.tsx +0 -5
- package/src/functions/macro-eval.js +0 -5
|
@@ -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,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,15 +1,16 @@
|
|
|
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 {
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
import { getProcessedBlock } from "
|
|
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
12
|
import BlockStyles from "./block-styles";
|
|
13
|
+
import { isEmptyHtmlElement } from "./render-block.helpers.js";
|
|
13
14
|
|
|
14
15
|
function RenderBlock(props) {
|
|
15
16
|
const state = createMutable({
|
|
@@ -20,20 +21,29 @@ function RenderBlock(props) {
|
|
|
20
21
|
return null;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
const ref =
|
|
24
|
+
const ref = builderContext.registeredComponents[componentName];
|
|
24
25
|
|
|
25
|
-
if (
|
|
26
|
+
if (!ref) {
|
|
26
27
|
// TODO: Public doc page with more info about this message
|
|
27
28
|
console.warn(`
|
|
28
29
|
Could not find a registered component named "${componentName}".
|
|
29
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;
|
|
30
34
|
}
|
|
31
|
-
|
|
32
|
-
return ref;
|
|
33
35
|
},
|
|
34
36
|
|
|
35
37
|
get componentInfo() {
|
|
36
|
-
|
|
38
|
+
if (state.component) {
|
|
39
|
+
const {
|
|
40
|
+
component: _,
|
|
41
|
+
...info
|
|
42
|
+
} = state.component;
|
|
43
|
+
return info;
|
|
44
|
+
} else {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
37
47
|
},
|
|
38
48
|
|
|
39
49
|
get componentRef() {
|
|
@@ -84,19 +94,27 @@ function RenderBlock(props) {
|
|
|
84
94
|
|
|
85
95
|
});
|
|
86
96
|
const builderContext = useContext(BuilderContext);
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
97
|
+
return <Show fallback={<Dynamic {...state.componentOptions} attributes={state.propertiesAndActions} builderBlock={state.useBlock} style={state.css} component={state.componentRef}>
|
|
98
|
+
<For each={state.children}>
|
|
99
|
+
{(child, _index) => {
|
|
100
|
+
const index = _index();
|
|
101
|
+
|
|
102
|
+
return <RenderBlock key={child.id} block={child}></RenderBlock>;
|
|
103
|
+
}}
|
|
104
|
+
</For>
|
|
105
|
+
</Dynamic>} when={!state.componentInfo?.noWrap}>
|
|
106
|
+
<Show fallback={<Dynamic {...state.propertiesAndActions} style={state.css} component={state.tagName}></Dynamic>} when={!isEmptyHtmlElement(state.tagName)}>
|
|
90
107
|
<Dynamic {...state.propertiesAndActions} style={state.css} component={state.tagName}>
|
|
91
|
-
<
|
|
108
|
+
<Show when={TARGET === "vue" || TARGET === "svelte"}>
|
|
109
|
+
<BlockStyles block={state.useBlock}></BlockStyles>
|
|
110
|
+
</Show>
|
|
92
111
|
<Show when={state.componentRef}>
|
|
93
|
-
<Dynamic {...
|
|
112
|
+
<Dynamic {...state.componentOptions} builderBlock={state.useBlock} component={state.componentRef}>
|
|
94
113
|
<For each={state.children}>
|
|
95
114
|
{(child, _index) => {
|
|
96
115
|
const index = _index();
|
|
97
|
-
console.log('render block?')
|
|
98
116
|
|
|
99
|
-
return <RenderBlock block={child}></RenderBlock>;
|
|
117
|
+
return <RenderBlock key={child.id} block={child}></RenderBlock>;
|
|
100
118
|
}}
|
|
101
119
|
</For>
|
|
102
120
|
</Dynamic>
|
|
@@ -105,12 +123,12 @@ function RenderBlock(props) {
|
|
|
105
123
|
{(child, _index) => {
|
|
106
124
|
const index = _index();
|
|
107
125
|
|
|
108
|
-
return <RenderBlock block={child}></RenderBlock>;
|
|
126
|
+
return <RenderBlock key={child.id} block={child}></RenderBlock>;
|
|
109
127
|
}}
|
|
110
128
|
</For>
|
|
111
129
|
</Dynamic>
|
|
112
130
|
</Show>
|
|
113
|
-
|
|
131
|
+
</Show>;
|
|
114
132
|
}
|
|
115
133
|
|
|
116
134
|
export default RenderBlock;
|
|
@@ -2,15 +2,16 @@ import { useContext, Show, For } from "solid-js";
|
|
|
2
2
|
import { Dynamic } from "solid-js/web";
|
|
3
3
|
import { createMutable } from "solid-js/store";
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
import {
|
|
12
|
-
import { getProcessedBlock } from "
|
|
5
|
+
import { TARGET } from "../../constants/target.js";
|
|
6
|
+
import BuilderContext from "../../context/builder.context";
|
|
7
|
+
import { getBlockActions } from "../../functions/get-block-actions.js";
|
|
8
|
+
import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
|
|
9
|
+
import { getBlockProperties } from "../../functions/get-block-properties.js";
|
|
10
|
+
import { getBlockStyles } from "../../functions/get-block-styles.js";
|
|
11
|
+
import { getBlockTag } from "../../functions/get-block-tag.js";
|
|
12
|
+
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
13
13
|
import BlockStyles from "./block-styles.lite";
|
|
14
|
+
import { isEmptyHtmlElement } from "./render-block.helpers.js";
|
|
14
15
|
|
|
15
16
|
function RenderBlock(props) {
|
|
16
17
|
const state = createMutable({
|
|
@@ -21,19 +22,25 @@ function RenderBlock(props) {
|
|
|
21
22
|
return null;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
const ref =
|
|
25
|
+
const ref = builderContext.registeredComponents[componentName];
|
|
25
26
|
|
|
26
|
-
if (
|
|
27
|
+
if (!ref) {
|
|
27
28
|
// TODO: Public doc page with more info about this message
|
|
28
29
|
console.warn(`
|
|
29
30
|
Could not find a registered component named "${componentName}".
|
|
30
31
|
If you registered it, is the file that registered it imported by the file that needs to render it?`);
|
|
32
|
+
return undefined;
|
|
33
|
+
} else {
|
|
34
|
+
return ref;
|
|
31
35
|
}
|
|
32
|
-
|
|
33
|
-
return ref;
|
|
34
36
|
},
|
|
35
37
|
get componentInfo() {
|
|
36
|
-
|
|
38
|
+
if (state.component) {
|
|
39
|
+
const { component: _, ...info } = state.component;
|
|
40
|
+
return info;
|
|
41
|
+
} else {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
37
44
|
},
|
|
38
45
|
get componentRef() {
|
|
39
46
|
return state.component?.component;
|
|
@@ -79,14 +86,43 @@ function RenderBlock(props) {
|
|
|
79
86
|
const builderContext = useContext(BuilderContext);
|
|
80
87
|
|
|
81
88
|
return (
|
|
82
|
-
|
|
83
|
-
|
|
89
|
+
<Show
|
|
90
|
+
fallback={
|
|
91
|
+
<Dynamic
|
|
92
|
+
{...state.componentOptions}
|
|
93
|
+
attributes={state.propertiesAndActions}
|
|
94
|
+
builderBlock={state.useBlock}
|
|
95
|
+
style={state.css}
|
|
96
|
+
component={state.componentRef}
|
|
97
|
+
>
|
|
98
|
+
<For each={state.children}>
|
|
99
|
+
{(child, _index) => {
|
|
100
|
+
const index = _index();
|
|
101
|
+
return <RenderBlock key={child.id} block={child}></RenderBlock>;
|
|
102
|
+
}}
|
|
103
|
+
</For>
|
|
104
|
+
</Dynamic>
|
|
105
|
+
}
|
|
106
|
+
when={!state.componentInfo?.noWrap}
|
|
107
|
+
>
|
|
108
|
+
<Show
|
|
109
|
+
fallback={
|
|
110
|
+
<Dynamic
|
|
111
|
+
{...state.propertiesAndActions}
|
|
112
|
+
style={state.css}
|
|
113
|
+
component={state.tagName}
|
|
114
|
+
></Dynamic>
|
|
115
|
+
}
|
|
116
|
+
when={!isEmptyHtmlElement(state.tagName)}
|
|
117
|
+
>
|
|
84
118
|
<Dynamic
|
|
85
119
|
{...state.propertiesAndActions}
|
|
86
120
|
style={state.css}
|
|
87
121
|
component={state.tagName}
|
|
88
122
|
>
|
|
89
|
-
<
|
|
123
|
+
<Show when={TARGET === "vue" || TARGET === "svelte"}>
|
|
124
|
+
<BlockStyles block={state.useBlock}></BlockStyles>
|
|
125
|
+
</Show>
|
|
90
126
|
<Show when={state.componentRef}>
|
|
91
127
|
<Dynamic
|
|
92
128
|
{...state.componentOptions}
|
|
@@ -96,7 +132,9 @@ function RenderBlock(props) {
|
|
|
96
132
|
<For each={state.children}>
|
|
97
133
|
{(child, _index) => {
|
|
98
134
|
const index = _index();
|
|
99
|
-
return
|
|
135
|
+
return (
|
|
136
|
+
<RenderBlock key={child.id} block={child}></RenderBlock>
|
|
137
|
+
);
|
|
100
138
|
}}
|
|
101
139
|
</For>
|
|
102
140
|
</Dynamic>
|
|
@@ -104,12 +142,12 @@ function RenderBlock(props) {
|
|
|
104
142
|
<For each={state.noCompRefChildren}>
|
|
105
143
|
{(child, _index) => {
|
|
106
144
|
const index = _index();
|
|
107
|
-
return <RenderBlock block={child}></RenderBlock>;
|
|
145
|
+
return <RenderBlock key={child.id} block={child}></RenderBlock>;
|
|
108
146
|
}}
|
|
109
147
|
</For>
|
|
110
148
|
</Dynamic>
|
|
111
149
|
</Show>
|
|
112
|
-
|
|
150
|
+
</Show>
|
|
113
151
|
);
|
|
114
152
|
}
|
|
115
153
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Show, For } from "solid-js";
|
|
2
2
|
import { createMutable } from "solid-js/store";
|
|
3
3
|
import { css } from "solid-styled-components";
|
|
4
|
-
import { isEditing } from "../functions/is-editing";
|
|
5
|
-
import RenderBlock from "./render-block";
|
|
4
|
+
import { isEditing } from "../functions/is-editing.js";
|
|
5
|
+
import RenderBlock from "./render-block/render-block";
|
|
6
6
|
|
|
7
7
|
function RenderBlocks(props) {
|
|
8
8
|
const state = createMutable({
|
|
@@ -3,8 +3,8 @@ import { Show, For } from "solid-js";
|
|
|
3
3
|
import { createMutable } from "solid-js/store";
|
|
4
4
|
import { css } from "solid-styled-components";
|
|
5
5
|
|
|
6
|
-
import { isEditing } from "../functions/is-editing";
|
|
7
|
-
import RenderBlock from "./render-block.lite";
|
|
6
|
+
import { isEditing } from "../functions/is-editing.js";
|
|
7
|
+
import RenderBlock from "./render-block/render-block.lite";
|
|
8
8
|
|
|
9
9
|
function RenderBlocks(props) {
|
|
10
10
|
const state = createMutable({
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createMutable } from "solid-js/store";
|
|
2
|
+
import RenderInlinedStyles from "../../render-inlined-styles";
|
|
2
3
|
|
|
3
|
-
function
|
|
4
|
+
function RenderContentStyles(props) {
|
|
4
5
|
const state = createMutable({
|
|
5
6
|
getCssFromFont(font) {
|
|
6
7
|
// TODO: compute what font sizes are used and only load those.......
|
|
@@ -58,16 +59,16 @@ function RenderStyles(props) {
|
|
|
58
59
|
return customFonts?.map(font => this.getCssFromFont(font))?.join(" ") || "";
|
|
59
60
|
},
|
|
60
61
|
|
|
61
|
-
|
|
62
|
+
get injectedStyles() {
|
|
62
63
|
return `
|
|
63
|
-
${props.cssCode}
|
|
64
|
+
${props.cssCode || ""}
|
|
64
65
|
${state.getFontCss({
|
|
65
66
|
customFonts: props.customFonts
|
|
66
67
|
})}`;
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
});
|
|
70
|
-
return <
|
|
71
|
+
return <RenderInlinedStyles styles={state.injectedStyles}></RenderInlinedStyles>;
|
|
71
72
|
}
|
|
72
73
|
|
|
73
|
-
export default
|
|
74
|
+
export default RenderContentStyles;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { createMutable } from "solid-js/store";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import RenderInlinedStyles from "../../render-inlined-styles.lite";
|
|
4
|
+
|
|
5
|
+
function RenderContentStyles(props) {
|
|
4
6
|
const state = createMutable({
|
|
5
7
|
getCssFromFont(font: CustomFont) {
|
|
6
8
|
// TODO: compute what font sizes are used and only load those.......
|
|
@@ -57,16 +59,18 @@ function RenderStyles(props) {
|
|
|
57
59
|
customFonts?.map((font) => this.getCssFromFont(font))?.join(" ") || ""
|
|
58
60
|
);
|
|
59
61
|
},
|
|
60
|
-
|
|
62
|
+
get injectedStyles() {
|
|
61
63
|
return `
|
|
62
|
-
${props.cssCode}
|
|
64
|
+
${props.cssCode || ""}
|
|
63
65
|
${state.getFontCss({
|
|
64
66
|
customFonts: props.customFonts,
|
|
65
67
|
})}`;
|
|
66
68
|
},
|
|
67
69
|
});
|
|
68
70
|
|
|
69
|
-
return
|
|
71
|
+
return (
|
|
72
|
+
<RenderInlinedStyles styles={state.injectedStyles}></RenderInlinedStyles>
|
|
73
|
+
);
|
|
70
74
|
}
|
|
71
75
|
|
|
72
|
-
export default
|
|
76
|
+
export default RenderContentStyles;
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import { Show, onMount } from "solid-js";
|
|
2
2
|
import { Dynamic } from "solid-js/web";
|
|
3
3
|
import { createMutable } from "solid-js/store";
|
|
4
|
-
import {
|
|
4
|
+
import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
|
|
5
|
+
import { TARGET } from "../../constants/target.js";
|
|
5
6
|
import BuilderContext from "../../context/builder.context";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
7
|
+
import { evaluate } from "../../functions/evaluate.js";
|
|
8
|
+
import { convertSearchParamsToQueryObject, getBuilderSearchParams } from "../../functions/get-builder-search-params/index.js";
|
|
9
|
+
import { getContent } from "../../functions/get-content/index.js";
|
|
10
|
+
import { getFetch } from "../../functions/get-fetch.js";
|
|
11
|
+
import { isBrowser } from "../../functions/is-browser.js";
|
|
12
|
+
import { isEditing } from "../../functions/is-editing.js";
|
|
13
|
+
import { isPreviewing } from "../../functions/is-previewing.js";
|
|
14
|
+
import { previewingModelName } from "../../functions/previewing-model-name.js";
|
|
15
|
+
import { components, createRegisterComponentMessage } from "../../functions/register-component.js";
|
|
16
|
+
import { track } from "../../functions/track.js";
|
|
12
17
|
import RenderBlocks from "../render-blocks";
|
|
13
|
-
import
|
|
14
|
-
import { getFetch } from "../../functions/get-fetch";
|
|
15
|
-
import { TARGET } from "../../constants/target";
|
|
16
|
-
import RenderStyles from "./components/render-styles";
|
|
18
|
+
import RenderContentStyles from "./components/render-styles";
|
|
17
19
|
|
|
18
20
|
function RenderContent(props) {
|
|
19
21
|
const state = createMutable({
|
|
@@ -32,7 +34,7 @@ function RenderContent(props) {
|
|
|
32
34
|
update: 0,
|
|
33
35
|
overrideState: {},
|
|
34
36
|
|
|
35
|
-
get
|
|
37
|
+
get contentState() {
|
|
36
38
|
return { ...props.content?.data?.state,
|
|
37
39
|
...props.data,
|
|
38
40
|
...state.overrideState
|
|
@@ -43,6 +45,19 @@ function RenderContent(props) {
|
|
|
43
45
|
return {};
|
|
44
46
|
},
|
|
45
47
|
|
|
48
|
+
get allRegisteredComponents() {
|
|
49
|
+
const allComponentsArray = [...getDefaultRegisteredComponents(), // While this `components` object is deprecated, we must maintain support for it.
|
|
50
|
+
// Since users are able to override our default components, we need to make sure that we do not break such
|
|
51
|
+
// existing usage.
|
|
52
|
+
// This is why we spread `components` after the default Builder.io components, but before the `props.customComponents`,
|
|
53
|
+
// which is the new standard way of providing custom components, and must therefore take precedence.
|
|
54
|
+
...components, ...(props.customComponents || [])];
|
|
55
|
+
const allComponents = allComponentsArray.reduce((acc, curr) => ({ ...acc,
|
|
56
|
+
[curr.name]: curr
|
|
57
|
+
}), {});
|
|
58
|
+
return allComponents;
|
|
59
|
+
},
|
|
60
|
+
|
|
46
61
|
processMessage(event) {
|
|
47
62
|
const {
|
|
48
63
|
data
|
|
@@ -80,7 +95,7 @@ function RenderContent(props) {
|
|
|
80
95
|
evaluate({
|
|
81
96
|
code: jsCode,
|
|
82
97
|
context: state.context,
|
|
83
|
-
state: state.
|
|
98
|
+
state: state.contentState
|
|
84
99
|
});
|
|
85
100
|
}
|
|
86
101
|
},
|
|
@@ -93,7 +108,7 @@ function RenderContent(props) {
|
|
|
93
108
|
return expression.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({
|
|
94
109
|
code: group,
|
|
95
110
|
context: state.context,
|
|
96
|
-
state: state.
|
|
111
|
+
state: state.contentState
|
|
97
112
|
}));
|
|
98
113
|
},
|
|
99
114
|
|
|
@@ -102,7 +117,8 @@ function RenderContent(props) {
|
|
|
102
117
|
key
|
|
103
118
|
}) {
|
|
104
119
|
const fetchAndSetState = async () => {
|
|
105
|
-
const
|
|
120
|
+
const fetch = await getFetch();
|
|
121
|
+
const response = await fetch(url);
|
|
106
122
|
const json = await response.json();
|
|
107
123
|
const newOverrideState = { ...state.overrideState,
|
|
108
124
|
[key]: json
|
|
@@ -127,20 +143,26 @@ function RenderContent(props) {
|
|
|
127
143
|
},
|
|
128
144
|
|
|
129
145
|
emitStateUpdate() {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
146
|
+
if (isEditing()) {
|
|
147
|
+
window.dispatchEvent(new CustomEvent("builder:component:stateChange", {
|
|
148
|
+
detail: {
|
|
149
|
+
state: state.contentState,
|
|
150
|
+
ref: {
|
|
151
|
+
name: props.model
|
|
152
|
+
}
|
|
135
153
|
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
154
|
+
}));
|
|
155
|
+
}
|
|
138
156
|
}
|
|
139
157
|
|
|
140
158
|
});
|
|
141
159
|
onMount(() => {
|
|
142
160
|
if (isBrowser()) {
|
|
143
161
|
if (isEditing()) {
|
|
162
|
+
Object.values(state.allRegisteredComponents).forEach(registeredComponent => {
|
|
163
|
+
const message = createRegisterComponentMessage(registeredComponent);
|
|
164
|
+
window.parent?.postMessage(message, "*");
|
|
165
|
+
});
|
|
144
166
|
window.addEventListener("message", state.processMessage);
|
|
145
167
|
window.addEventListener("builder:component:stateChangeListenerActivated", state.emitStateUpdate);
|
|
146
168
|
}
|
|
@@ -182,7 +204,7 @@ function RenderContent(props) {
|
|
|
182
204
|
},
|
|
183
205
|
|
|
184
206
|
get state() {
|
|
185
|
-
return state.
|
|
207
|
+
return state.contentState;
|
|
186
208
|
},
|
|
187
209
|
|
|
188
210
|
get context() {
|
|
@@ -191,6 +213,10 @@ function RenderContent(props) {
|
|
|
191
213
|
|
|
192
214
|
get apiKey() {
|
|
193
215
|
return props.apiKey;
|
|
216
|
+
},
|
|
217
|
+
|
|
218
|
+
get registeredComponents() {
|
|
219
|
+
return state.allRegisteredComponents;
|
|
194
220
|
}
|
|
195
221
|
|
|
196
222
|
}} component={BuilderContext.Provider}>
|
|
@@ -199,7 +225,7 @@ function RenderContent(props) {
|
|
|
199
225
|
contentId: state.useContent.id
|
|
200
226
|
})} data-builder-content-id={state.useContent?.id}>
|
|
201
227
|
<Show when={(state.useContent?.data?.cssCode || state.useContent?.data?.customFonts?.length) && TARGET !== "reactNative"}>
|
|
202
|
-
<
|
|
228
|
+
<RenderContentStyles cssCode={state.useContent.data.cssCode} customFonts={state.useContent.data.customFonts}></RenderContentStyles>
|
|
203
229
|
</Show>
|
|
204
230
|
<RenderBlocks blocks={state.useContent?.data?.blocks}></RenderBlocks>
|
|
205
231
|
</div>
|