@builder.io/sdk-solid 0.0.8-2 → 0.0.8-20
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/README.md +5 -1
- package/package.json +11 -7
- package/src/blocks/button/button.jsx +1 -1
- package/src/blocks/columns/columns.jsx +4 -4
- package/src/blocks/columns/component-info.js +25 -1
- package/src/blocks/custom-code/custom-code.jsx +2 -2
- package/src/blocks/embed/component-info.js +20 -1
- package/src/blocks/embed/embed.jsx +31 -34
- package/src/blocks/embed/helpers.js +9 -0
- package/src/blocks/form/form.jsx +3 -3
- package/src/blocks/image/component-info.js +47 -1
- package/src/blocks/image/image.helpers.js +48 -0
- package/src/blocks/image/image.jsx +43 -7
- package/src/blocks/symbol/component-info.js +1 -0
- package/src/blocks/symbol/symbol.jsx +32 -3
- package/src/blocks/text/text.jsx +1 -1
- package/src/blocks/video/video.jsx +25 -2
- package/src/components/render-block/block-styles.jsx +31 -23
- package/src/components/render-block/render-block.helpers.js +23 -0
- package/src/components/render-block/render-block.jsx +123 -36
- package/src/components/render-block/render-component.jsx +27 -0
- package/src/components/render-block/render-repeated-block.jsx +32 -0
- package/src/components/render-block/types.js +0 -0
- package/src/components/render-blocks.jsx +12 -2
- package/src/components/render-content/components/render-styles.jsx +1 -1
- package/src/components/render-content/index.js +4 -0
- package/src/components/render-content/render-content.jsx +70 -25
- package/src/components/render-inlined-styles.jsx +2 -1
- package/src/constants/builder-registered-components.js +48 -0
- package/src/constants/device-sizes.js +3 -21
- package/src/context/builder.context.js +2 -1
- package/src/functions/camel-to-kebab-case.js +4 -0
- package/src/functions/convert-style-object.js +14 -0
- package/src/functions/get-block-component-options.js +6 -1
- package/src/functions/get-block-styles.js +7 -15
- package/src/functions/get-builder-search-params/index.js +12 -1
- package/src/functions/get-content/ab-testing.js +38 -0
- package/src/functions/get-content/index.js +16 -58
- package/src/functions/get-content/types.js +0 -0
- package/src/functions/get-processed-block.js +15 -8
- package/src/functions/get-processed-block.test.js +2 -1
- package/src/functions/register-component.js +45 -26
- package/src/functions/sanitize-styles.js +5 -0
- package/src/helpers/css.js +12 -0
- package/src/helpers/flatten.js +34 -0
- package/src/index-helpers/blocks-exports.js +11 -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/button.lite.tsx +0 -20
- package/src/blocks/button/index.js +0 -7
- package/src/blocks/columns/columns.lite.tsx +0 -102
- package/src/blocks/columns/index.js +0 -7
- package/src/blocks/custom-code/custom-code.lite.tsx +0 -67
- package/src/blocks/custom-code/index.js +0 -7
- package/src/blocks/embed/embed.lite.tsx +0 -59
- package/src/blocks/embed/index.js +0 -7
- package/src/blocks/form/form.lite.tsx +0 -293
- package/src/blocks/form/index.js +0 -7
- package/src/blocks/fragment/fragment.lite.tsx +0 -5
- package/src/blocks/fragment/index.js +0 -7
- package/src/blocks/image/image.lite.tsx +0 -83
- package/src/blocks/image/index.js +0 -7
- package/src/blocks/img/img.lite.tsx +0 -18
- package/src/blocks/img/index.js +0 -7
- package/src/blocks/input/index.js +0 -7
- package/src/blocks/input/input.lite.tsx +0 -20
- package/src/blocks/raw-text/index.js +0 -7
- package/src/blocks/raw-text/raw-text.lite.tsx +0 -10
- package/src/blocks/section/index.js +0 -7
- package/src/blocks/section/section.lite.tsx +0 -18
- package/src/blocks/select/index.js +0 -7
- package/src/blocks/select/select.lite.tsx +0 -28
- package/src/blocks/submit-button/index.js +0 -7
- package/src/blocks/submit-button/submit-button.lite.tsx +0 -9
- package/src/blocks/symbol/index.js +0 -7
- package/src/blocks/symbol/symbol.lite.tsx +0 -39
- package/src/blocks/text/index.js +0 -7
- package/src/blocks/text/text.lite.tsx +0 -5
- package/src/blocks/textarea/index.js +0 -7
- package/src/blocks/textarea/textarea.lite.tsx +0 -13
- package/src/blocks/video/index.js +0 -7
- package/src/blocks/video/video.lite.tsx +0 -26
- package/src/components/error-boundary.jsx +0 -5
- package/src/components/error-boundary.lite.tsx +0 -5
- package/src/components/render-block/block-styles.lite.tsx +0 -38
- package/src/components/render-block/render-block.lite.tsx +0 -119
- package/src/components/render-blocks.lite.tsx +0 -75
- package/src/components/render-content/components/render-styles.lite.tsx +0 -76
- package/src/components/render-content/render-content.lite.tsx +0 -232
- package/src/components/render-inlined-styles.lite.tsx +0 -26
- package/src/functions/macro-eval.js +0 -5
- package/src/functions/previewing-model-name.js +0 -11
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { createMutable } from "solid-js/store";
|
|
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/index.js";
|
|
6
|
-
|
|
7
|
-
function Symbol(props) {
|
|
8
|
-
const state = createMutable({ className: "builder-symbol", content: null });
|
|
9
|
-
|
|
10
|
-
const builderContext = useContext(BuilderContext);
|
|
11
|
-
|
|
12
|
-
onMount(() => {
|
|
13
|
-
state.content = props.symbol?.content;
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
return (
|
|
17
|
-
<div
|
|
18
|
-
class={state.className}
|
|
19
|
-
{...props.attributes}
|
|
20
|
-
dataSet={{
|
|
21
|
-
class: state.className,
|
|
22
|
-
}}
|
|
23
|
-
>
|
|
24
|
-
<RenderContent
|
|
25
|
-
apiKey={builderContext.apiKey}
|
|
26
|
-
context={builderContext.context}
|
|
27
|
-
data={{
|
|
28
|
-
...props.symbol?.data,
|
|
29
|
-
...builderContext.state,
|
|
30
|
-
...props.symbol?.state.content?.data?.state,
|
|
31
|
-
}}
|
|
32
|
-
model={props.symbol?.model}
|
|
33
|
-
content={state.content}
|
|
34
|
-
></RenderContent>
|
|
35
|
-
</div>
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export default Symbol;
|
package/src/blocks/text/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
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,7 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
function Video(props) {
|
|
2
|
-
return (
|
|
3
|
-
<video
|
|
4
|
-
{...props.attributes}
|
|
5
|
-
preload="none"
|
|
6
|
-
style={{
|
|
7
|
-
width: "100%",
|
|
8
|
-
height: "100%",
|
|
9
|
-
...props.attributes?.style,
|
|
10
|
-
"object-fit": props.fit,
|
|
11
|
-
"object-position": props.position,
|
|
12
|
-
// Hack to get object fit to work as expected and
|
|
13
|
-
// not have the video overflow
|
|
14
|
-
"border-radius": 1,
|
|
15
|
-
}}
|
|
16
|
-
key={props.video || "no-src"}
|
|
17
|
-
poster={props.posterImage}
|
|
18
|
-
autoPlay={props.autoPlay}
|
|
19
|
-
muted={props.muted}
|
|
20
|
-
controls={props.controls}
|
|
21
|
-
loop={props.loop}
|
|
22
|
-
></video>
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export default Video;
|
|
@@ -1,38 +0,0 @@
|
|
|
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;
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { useContext, Show, For } from "solid-js";
|
|
2
|
-
import { Dynamic } from "solid-js/web";
|
|
3
|
-
import { createMutable } from "solid-js/store";
|
|
4
|
-
|
|
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
|
-
import { components } from "../../functions/register-component.js";
|
|
14
|
-
import BlockStyles from "./block-styles.lite";
|
|
15
|
-
|
|
16
|
-
function RenderBlock(props) {
|
|
17
|
-
const state = createMutable({
|
|
18
|
-
get component() {
|
|
19
|
-
const componentName = state.useBlock.component?.name;
|
|
20
|
-
|
|
21
|
-
if (!componentName) {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const ref = components[componentName];
|
|
26
|
-
|
|
27
|
-
if (componentName && !ref) {
|
|
28
|
-
// TODO: Public doc page with more info about this message
|
|
29
|
-
console.warn(`
|
|
30
|
-
Could not find a registered component named "${componentName}".
|
|
31
|
-
If you registered it, is the file that registered it imported by the file that needs to render it?`);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return ref;
|
|
35
|
-
},
|
|
36
|
-
get componentInfo() {
|
|
37
|
-
return state.component?.info;
|
|
38
|
-
},
|
|
39
|
-
get componentRef() {
|
|
40
|
-
return state.component?.component;
|
|
41
|
-
},
|
|
42
|
-
get tagName() {
|
|
43
|
-
return getBlockTag(state.useBlock);
|
|
44
|
-
},
|
|
45
|
-
get useBlock() {
|
|
46
|
-
return getProcessedBlock({
|
|
47
|
-
block: props.block,
|
|
48
|
-
state: builderContext.state,
|
|
49
|
-
context: builderContext.context,
|
|
50
|
-
});
|
|
51
|
-
},
|
|
52
|
-
get propertiesAndActions() {
|
|
53
|
-
return {
|
|
54
|
-
...getBlockProperties(state.useBlock),
|
|
55
|
-
...getBlockActions({
|
|
56
|
-
block: state.useBlock,
|
|
57
|
-
state: builderContext.state,
|
|
58
|
-
context: builderContext.context,
|
|
59
|
-
}),
|
|
60
|
-
};
|
|
61
|
-
},
|
|
62
|
-
get css() {
|
|
63
|
-
return getBlockStyles(state.useBlock);
|
|
64
|
-
},
|
|
65
|
-
get componentOptions() {
|
|
66
|
-
return getBlockComponentOptions(state.useBlock);
|
|
67
|
-
},
|
|
68
|
-
get children() {
|
|
69
|
-
// TO-DO: When should `canHaveChildren` dictate rendering?
|
|
70
|
-
// This is currently commented out because some Builder components (e.g. Box) do not have `canHaveChildren: true`,
|
|
71
|
-
// but still receive and need to render children.
|
|
72
|
-
// return state.componentInfo?.canHaveChildren ? state.useBlock.children : [];
|
|
73
|
-
return state.useBlock.children ?? [];
|
|
74
|
-
},
|
|
75
|
-
get noCompRefChildren() {
|
|
76
|
-
return state.componentRef ? [] : state.children;
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
const builderContext = useContext(BuilderContext);
|
|
81
|
-
|
|
82
|
-
return (
|
|
83
|
-
<>
|
|
84
|
-
<Show when={!state.componentInfo?.noWrap}>
|
|
85
|
-
<Dynamic
|
|
86
|
-
{...state.propertiesAndActions}
|
|
87
|
-
style={state.css}
|
|
88
|
-
component={state.tagName}
|
|
89
|
-
>
|
|
90
|
-
<Show when={TARGET === "vue" || TARGET === "svelte"}>
|
|
91
|
-
<BlockStyles block={state.useBlock}></BlockStyles>
|
|
92
|
-
</Show>
|
|
93
|
-
<Show when={state.componentRef}>
|
|
94
|
-
<Dynamic
|
|
95
|
-
{...state.componentOptions}
|
|
96
|
-
builderBlock={state.useBlock}
|
|
97
|
-
component={state.componentRef}
|
|
98
|
-
>
|
|
99
|
-
<For each={state.children}>
|
|
100
|
-
{(child, _index) => {
|
|
101
|
-
const index = _index();
|
|
102
|
-
return <RenderBlock block={child}></RenderBlock>;
|
|
103
|
-
}}
|
|
104
|
-
</For>
|
|
105
|
-
</Dynamic>
|
|
106
|
-
</Show>
|
|
107
|
-
<For each={state.noCompRefChildren}>
|
|
108
|
-
{(child, _index) => {
|
|
109
|
-
const index = _index();
|
|
110
|
-
return <RenderBlock block={child}></RenderBlock>;
|
|
111
|
-
}}
|
|
112
|
-
</For>
|
|
113
|
-
</Dynamic>
|
|
114
|
-
</Show>
|
|
115
|
-
</>
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export default RenderBlock;
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { Show, For } from "solid-js";
|
|
2
|
-
|
|
3
|
-
import { createMutable } from "solid-js/store";
|
|
4
|
-
import { css } from "solid-styled-components";
|
|
5
|
-
|
|
6
|
-
import { isEditing } from "../functions/is-editing.js";
|
|
7
|
-
import RenderBlock from "./render-block/render-block.lite";
|
|
8
|
-
|
|
9
|
-
function RenderBlocks(props) {
|
|
10
|
-
const state = createMutable({
|
|
11
|
-
get className() {
|
|
12
|
-
return "builder-blocks" + (!props.blocks?.length ? " no-blocks" : "");
|
|
13
|
-
},
|
|
14
|
-
onClick() {
|
|
15
|
-
if (isEditing() && !props.blocks?.length) {
|
|
16
|
-
window.parent?.postMessage(
|
|
17
|
-
{
|
|
18
|
-
type: "builder.clickEmptyBlocks",
|
|
19
|
-
data: {
|
|
20
|
-
parentElementId: props.parent,
|
|
21
|
-
dataPath: props.path,
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
"*"
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
onMouseEnter() {
|
|
29
|
-
if (isEditing() && !props.blocks?.length) {
|
|
30
|
-
window.parent?.postMessage(
|
|
31
|
-
{
|
|
32
|
-
type: "builder.hoverEmptyBlocks",
|
|
33
|
-
data: {
|
|
34
|
-
parentElementId: props.parent,
|
|
35
|
-
dataPath: props.path,
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
"*"
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
return (
|
|
45
|
-
<div
|
|
46
|
-
class={
|
|
47
|
-
state.className +
|
|
48
|
-
" " +
|
|
49
|
-
css({
|
|
50
|
-
display: "flex",
|
|
51
|
-
flexDirection: "column",
|
|
52
|
-
alignItems: "stretch",
|
|
53
|
-
})
|
|
54
|
-
}
|
|
55
|
-
builder-path={props.path}
|
|
56
|
-
builder-parent-id={props.parent}
|
|
57
|
-
dataSet={{
|
|
58
|
-
class: state.className,
|
|
59
|
-
}}
|
|
60
|
-
onClick={(event) => state.onClick()}
|
|
61
|
-
onMouseEnter={(event) => state.onMouseEnter()}
|
|
62
|
-
>
|
|
63
|
-
<Show when={props.blocks}>
|
|
64
|
-
<For each={props.blocks}>
|
|
65
|
-
{(block, _index) => {
|
|
66
|
-
const index = _index();
|
|
67
|
-
return <RenderBlock key={block.id} block={block}></RenderBlock>;
|
|
68
|
-
}}
|
|
69
|
-
</For>
|
|
70
|
-
</Show>
|
|
71
|
-
</div>
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export default RenderBlocks;
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { createMutable } from "solid-js/store";
|
|
2
|
-
|
|
3
|
-
import RenderInlinedStyles from "../../render-inlined-styles.lite";
|
|
4
|
-
|
|
5
|
-
function RenderContentStyles(props) {
|
|
6
|
-
const state = createMutable({
|
|
7
|
-
getCssFromFont(font: CustomFont) {
|
|
8
|
-
// TODO: compute what font sizes are used and only load those.......
|
|
9
|
-
const family =
|
|
10
|
-
font.family +
|
|
11
|
-
(font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
|
|
12
|
-
const name = family.split(",")[0];
|
|
13
|
-
const url = font.fileUrl ?? font?.files?.regular;
|
|
14
|
-
let str = "";
|
|
15
|
-
|
|
16
|
-
if (url && family && name) {
|
|
17
|
-
str += `
|
|
18
|
-
@font-face {
|
|
19
|
-
font-family: "${family}";
|
|
20
|
-
src: local("${name}"), url('${url}') format('woff2');
|
|
21
|
-
font-display: fallback;
|
|
22
|
-
font-weight: 400;
|
|
23
|
-
}
|
|
24
|
-
`.trim();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (font.files) {
|
|
28
|
-
for (const weight in font.files) {
|
|
29
|
-
const isNumber = String(Number(weight)) === weight;
|
|
30
|
-
|
|
31
|
-
if (!isNumber) {
|
|
32
|
-
continue;
|
|
33
|
-
} // TODO: maybe limit number loaded
|
|
34
|
-
|
|
35
|
-
const weightUrl = font.files[weight];
|
|
36
|
-
|
|
37
|
-
if (weightUrl && weightUrl !== url) {
|
|
38
|
-
str += `
|
|
39
|
-
@font-face {
|
|
40
|
-
font-family: "${family}";
|
|
41
|
-
src: url('${weightUrl}') format('woff2');
|
|
42
|
-
font-display: fallback;
|
|
43
|
-
font-weight: ${weight};
|
|
44
|
-
}
|
|
45
|
-
`.trim();
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return str;
|
|
51
|
-
},
|
|
52
|
-
getFontCss({ customFonts }: { customFonts?: CustomFont[] }) {
|
|
53
|
-
// TODO: flag for this
|
|
54
|
-
// if (!this.builder.allowCustomFonts) {
|
|
55
|
-
// return '';
|
|
56
|
-
// }
|
|
57
|
-
// TODO: separate internal data from external
|
|
58
|
-
return (
|
|
59
|
-
customFonts?.map((font) => this.getCssFromFont(font))?.join(" ") || ""
|
|
60
|
-
);
|
|
61
|
-
},
|
|
62
|
-
get injectedStyles() {
|
|
63
|
-
return `
|
|
64
|
-
${props.cssCode || ""}
|
|
65
|
-
${state.getFontCss({
|
|
66
|
-
customFonts: props.customFonts,
|
|
67
|
-
})}`;
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
return (
|
|
72
|
-
<RenderInlinedStyles styles={state.injectedStyles}></RenderInlinedStyles>
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export default RenderContentStyles;
|
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
import { useContext, Show, onMount } from "solid-js";
|
|
2
|
-
import { Dynamic } from "solid-js/web";
|
|
3
|
-
import { createMutable } from "solid-js/store";
|
|
4
|
-
|
|
5
|
-
import { TARGET } from "../../constants/target.js";
|
|
6
|
-
import BuilderContext from "../../context/builder.context";
|
|
7
|
-
import { evaluate } from "../../functions/evaluate.js";
|
|
8
|
-
import {
|
|
9
|
-
convertSearchParamsToQueryObject,
|
|
10
|
-
getBuilderSearchParams,
|
|
11
|
-
} from "../../functions/get-builder-search-params/index.js";
|
|
12
|
-
import { getContent } from "../../functions/get-content/index.js";
|
|
13
|
-
import { getFetch } from "../../functions/get-fetch.js";
|
|
14
|
-
import { isBrowser } from "../../functions/is-browser.js";
|
|
15
|
-
import { isEditing } from "../../functions/is-editing.js";
|
|
16
|
-
import { isPreviewing } from "../../functions/is-previewing.js";
|
|
17
|
-
import { previewingModelName } from "../../functions/previewing-model-name.js";
|
|
18
|
-
import { track } from "../../functions/track.js";
|
|
19
|
-
import RenderBlocks from "../render-blocks.lite";
|
|
20
|
-
import RenderContentStyles from "./components/render-styles.lite";
|
|
21
|
-
|
|
22
|
-
function RenderContent(props) {
|
|
23
|
-
const state = createMutable({
|
|
24
|
-
get useContent() {
|
|
25
|
-
const mergedContent: BuilderContent = {
|
|
26
|
-
...props.content,
|
|
27
|
-
...state.overrideContent,
|
|
28
|
-
data: {
|
|
29
|
-
...props.content?.data,
|
|
30
|
-
...props.data,
|
|
31
|
-
...state.overrideContent?.data,
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
return mergedContent;
|
|
35
|
-
},
|
|
36
|
-
overrideContent: null,
|
|
37
|
-
update: 0,
|
|
38
|
-
overrideState: {},
|
|
39
|
-
get contentState() {
|
|
40
|
-
return {
|
|
41
|
-
...props.content?.data?.state,
|
|
42
|
-
...props.data,
|
|
43
|
-
...state.overrideState,
|
|
44
|
-
};
|
|
45
|
-
},
|
|
46
|
-
get context() {
|
|
47
|
-
return {} as {
|
|
48
|
-
[index: string]: any;
|
|
49
|
-
};
|
|
50
|
-
},
|
|
51
|
-
processMessage(event: MessageEvent) {
|
|
52
|
-
const { data } = event;
|
|
53
|
-
|
|
54
|
-
if (data) {
|
|
55
|
-
switch (data.type) {
|
|
56
|
-
case "builder.contentUpdate": {
|
|
57
|
-
const messageContent = data.data;
|
|
58
|
-
const key =
|
|
59
|
-
messageContent.key ||
|
|
60
|
-
messageContent.alias ||
|
|
61
|
-
messageContent.entry ||
|
|
62
|
-
messageContent.modelName;
|
|
63
|
-
const contentData = messageContent.data;
|
|
64
|
-
|
|
65
|
-
if (key === props.model) {
|
|
66
|
-
state.overrideContent = contentData;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
case "builder.patchUpdates": {
|
|
73
|
-
// TODO
|
|
74
|
-
break;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
evaluateJsCode() {
|
|
80
|
-
// run any dynamic JS code attached to content
|
|
81
|
-
const jsCode = state.useContent?.data?.jsCode;
|
|
82
|
-
|
|
83
|
-
if (jsCode) {
|
|
84
|
-
evaluate({
|
|
85
|
-
code: jsCode,
|
|
86
|
-
context: state.context,
|
|
87
|
-
state: state.contentState,
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
get httpReqsData() {
|
|
92
|
-
return {};
|
|
93
|
-
},
|
|
94
|
-
evalExpression(expression: string) {
|
|
95
|
-
return expression.replace(/{{([^}]+)}}/g, (_match, group) =>
|
|
96
|
-
evaluate({
|
|
97
|
-
code: group,
|
|
98
|
-
context: state.context,
|
|
99
|
-
state: state.contentState,
|
|
100
|
-
})
|
|
101
|
-
);
|
|
102
|
-
},
|
|
103
|
-
handleRequest({ url, key }: { key: string; url: string }) {
|
|
104
|
-
const fetchAndSetState = async () => {
|
|
105
|
-
const fetch = await getFetch();
|
|
106
|
-
const response = await fetch(url);
|
|
107
|
-
const json = await response.json();
|
|
108
|
-
const newOverrideState = { ...state.overrideState, [key]: json };
|
|
109
|
-
state.overrideState = newOverrideState;
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
fetchAndSetState();
|
|
113
|
-
},
|
|
114
|
-
runHttpRequests() {
|
|
115
|
-
const requests = state.useContent?.data?.httpRequests ?? {};
|
|
116
|
-
Object.entries(requests).forEach(([key, url]) => {
|
|
117
|
-
if (url && (!state.httpReqsData[key] || isEditing())) {
|
|
118
|
-
const evaluatedUrl = state.evalExpression(url);
|
|
119
|
-
state.handleRequest({
|
|
120
|
-
url: evaluatedUrl,
|
|
121
|
-
key,
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
},
|
|
126
|
-
emitStateUpdate() {
|
|
127
|
-
window.dispatchEvent(
|
|
128
|
-
new CustomEvent<BuilderComponentStateChange>(
|
|
129
|
-
"builder:component:stateChange",
|
|
130
|
-
{
|
|
131
|
-
detail: {
|
|
132
|
-
state: state.contentState,
|
|
133
|
-
ref: {
|
|
134
|
-
name: props.model,
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
}
|
|
138
|
-
)
|
|
139
|
-
);
|
|
140
|
-
},
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
onMount(() => {
|
|
144
|
-
if (isBrowser()) {
|
|
145
|
-
if (isEditing()) {
|
|
146
|
-
window.addEventListener("message", state.processMessage);
|
|
147
|
-
window.addEventListener(
|
|
148
|
-
"builder:component:stateChangeListenerActivated",
|
|
149
|
-
state.emitStateUpdate
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (state.useContent) {
|
|
154
|
-
track("impression", {
|
|
155
|
-
contentId: state.useContent.id,
|
|
156
|
-
});
|
|
157
|
-
} // override normal content in preview mode
|
|
158
|
-
|
|
159
|
-
if (isPreviewing()) {
|
|
160
|
-
if (props.model && previewingModelName() === props.model) {
|
|
161
|
-
const currentUrl = new URL(location.href);
|
|
162
|
-
const previewApiKey = currentUrl.searchParams.get("apiKey");
|
|
163
|
-
|
|
164
|
-
if (previewApiKey) {
|
|
165
|
-
getContent({
|
|
166
|
-
model: props.model,
|
|
167
|
-
apiKey: previewApiKey,
|
|
168
|
-
options: getBuilderSearchParams(
|
|
169
|
-
convertSearchParamsToQueryObject(currentUrl.searchParams)
|
|
170
|
-
),
|
|
171
|
-
}).then((content) => {
|
|
172
|
-
if (content) {
|
|
173
|
-
state.overrideContent = content;
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
state.evaluateJsCode();
|
|
181
|
-
state.runHttpRequests();
|
|
182
|
-
state.emitStateUpdate();
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
return (
|
|
187
|
-
<Dynamic
|
|
188
|
-
value={{
|
|
189
|
-
get content() {
|
|
190
|
-
return state.useContent;
|
|
191
|
-
},
|
|
192
|
-
get state() {
|
|
193
|
-
return state.contentState;
|
|
194
|
-
},
|
|
195
|
-
get context() {
|
|
196
|
-
return state.context;
|
|
197
|
-
},
|
|
198
|
-
get apiKey() {
|
|
199
|
-
return props.apiKey;
|
|
200
|
-
},
|
|
201
|
-
}}
|
|
202
|
-
component={BuilderContext.Provider}
|
|
203
|
-
>
|
|
204
|
-
<Show when={state.useContent}>
|
|
205
|
-
<div
|
|
206
|
-
onClick={(event) =>
|
|
207
|
-
track("click", {
|
|
208
|
-
contentId: state.useContent.id,
|
|
209
|
-
})
|
|
210
|
-
}
|
|
211
|
-
data-builder-content-id={state.useContent?.id}
|
|
212
|
-
>
|
|
213
|
-
<Show
|
|
214
|
-
when={
|
|
215
|
-
(state.useContent?.data?.cssCode ||
|
|
216
|
-
state.useContent?.data?.customFonts?.length) &&
|
|
217
|
-
TARGET !== "reactNative"
|
|
218
|
-
}
|
|
219
|
-
>
|
|
220
|
-
<RenderContentStyles
|
|
221
|
-
cssCode={state.useContent.data.cssCode}
|
|
222
|
-
customFonts={state.useContent.data.customFonts}
|
|
223
|
-
></RenderContentStyles>
|
|
224
|
-
</Show>
|
|
225
|
-
<RenderBlocks blocks={state.useContent?.data?.blocks}></RenderBlocks>
|
|
226
|
-
</div>
|
|
227
|
-
</Show>
|
|
228
|
-
</Dynamic>
|
|
229
|
-
);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
export default RenderContent;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Show } from "solid-js";
|
|
2
|
-
import { Dynamic } from "solid-js/web";
|
|
3
|
-
import { createMutable } from "solid-js/store";
|
|
4
|
-
|
|
5
|
-
import { TARGET } from "../constants/target.js";
|
|
6
|
-
|
|
7
|
-
function RenderInlinedStyles(props) {
|
|
8
|
-
const state = createMutable({
|
|
9
|
-
get injectedStyleScript() {
|
|
10
|
-
return `<${state.tagName}>${props.styles}</${state.tagName}>`;
|
|
11
|
-
},
|
|
12
|
-
get tagName() {
|
|
13
|
-
// NOTE: we have to obfusctate the name of the tag due to a limitation in the svelte-preprocessor plugin.
|
|
14
|
-
// https://github.com/sveltejs/vite-plugin-svelte/issues/315#issuecomment-1109000027
|
|
15
|
-
return "sty" + "le";
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
return (
|
|
20
|
-
<Show when={TARGET === "svelte"}>
|
|
21
|
-
<div innerHTML={state.injectedStyleScript}></div>
|
|
22
|
-
</Show>
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export default RenderInlinedStyles;
|