@builder.io/sdk-solid 0.0.8-11 → 0.0.8-14
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 +1 -1
- package/src/blocks/columns/columns.jsx +1 -1
- package/src/blocks/custom-code/custom-code.jsx +1 -2
- package/src/blocks/embed/embed.jsx +1 -2
- package/src/blocks/form/form.jsx +2 -2
- package/src/blocks/image/image.jsx +3 -5
- package/src/blocks/symbol/symbol.jsx +1 -1
- package/src/components/render-block/block-styles.jsx +17 -25
- package/src/components/render-block/render-block.jsx +2 -2
- package/src/components/render-block/render-component.jsx +2 -2
- package/src/components/render-blocks.jsx +2 -2
- package/src/components/render-content/components/render-styles.jsx +1 -1
- package/src/components/render-content/render-content.jsx +2 -2
- package/src/constants/device-sizes.js +3 -21
- package/src/functions/camel-to-kebab-case.js +4 -0
- package/src/helpers/css.js +12 -0
- package/src/index-helpers/blocks-exports.js +2 -0
- package/src/blocks/button/button.lite.tsx +0 -23
- package/src/blocks/columns/columns.lite.tsx +0 -109
- package/src/blocks/custom-code/custom-code.lite.tsx +0 -69
- package/src/blocks/embed/embed.lite.tsx +0 -61
- package/src/blocks/form/form.lite.tsx +0 -296
- package/src/blocks/fragment/fragment.lite.tsx +0 -5
- package/src/blocks/image/image.lite.tsx +0 -86
- package/src/blocks/img/img.lite.tsx +0 -18
- package/src/blocks/input/input.lite.tsx +0 -20
- package/src/blocks/raw-text/raw-text.lite.tsx +0 -10
- package/src/blocks/section/section.lite.tsx +0 -18
- package/src/blocks/select/select.lite.tsx +0 -28
- package/src/blocks/submit-button/submit-button.lite.tsx +0 -9
- package/src/blocks/symbol/symbol.lite.tsx +0 -41
- package/src/blocks/text/text.lite.tsx +0 -5
- package/src/blocks/textarea/textarea.lite.tsx +0 -13
- 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 -56
- package/src/components/render-block/render-block.lite.tsx +0 -156
- package/src/components/render-block/render-component.lite.tsx +0 -38
- package/src/components/render-blocks.lite.tsx +0 -94
- package/src/components/render-content/components/render-styles.lite.tsx +0 -76
- package/src/components/render-content/render-content.lite.tsx +0 -262
- package/src/components/render-inlined-styles.lite.tsx +0 -29
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { For } from "solid-js";
|
|
2
2
|
import { createMutable } from "solid-js/store";
|
|
3
3
|
import { css } from "solid-styled-components";
|
|
4
|
-
import RenderBlocks from "../../components/render-blocks";
|
|
4
|
+
import RenderBlocks from "../../components/render-blocks.jsx";
|
|
5
5
|
|
|
6
6
|
function Columns(props) {
|
|
7
7
|
const state = createMutable({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { onMount } from "solid-js";
|
|
1
|
+
import { onMount, useRef } from "solid-js";
|
|
2
2
|
import { createMutable } from "solid-js/store";
|
|
3
3
|
|
|
4
4
|
function CustomCode(props) {
|
|
@@ -9,7 +9,6 @@ function CustomCode(props) {
|
|
|
9
9
|
findAndRunScripts() {
|
|
10
10
|
// TODO: Move this function to standalone one in '@builder.io/utils'
|
|
11
11
|
if (elem && typeof window !== "undefined") {
|
|
12
|
-
/** @type {HTMLScriptElement[]} */
|
|
13
12
|
const scripts = elem.getElementsByTagName("script");
|
|
14
13
|
|
|
15
14
|
for (let i = 0; i < scripts.length; i++) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { onMount } from "solid-js";
|
|
1
|
+
import { onMount, useRef } from "solid-js";
|
|
2
2
|
import { createMutable } from "solid-js/store";
|
|
3
3
|
|
|
4
4
|
function Embed(props) {
|
|
@@ -9,7 +9,6 @@ function Embed(props) {
|
|
|
9
9
|
findAndRunScripts() {
|
|
10
10
|
// TODO: Move this function to standalone one in '@builder.io/utils'
|
|
11
11
|
if (elem && typeof window !== "undefined") {
|
|
12
|
-
/** @type {HTMLScriptElement[]} */
|
|
13
12
|
const scripts = elem.getElementsByTagName("script");
|
|
14
13
|
|
|
15
14
|
for (let i = 0; i < scripts.length; i++) {
|
package/src/blocks/form/form.jsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Show, For } from "solid-js";
|
|
1
|
+
import { Show, For, useRef } from "solid-js";
|
|
2
2
|
import { createMutable } from "solid-js/store";
|
|
3
3
|
import { css } from "solid-styled-components";
|
|
4
|
-
import RenderBlock from "../../components/render-block/render-block";
|
|
4
|
+
import RenderBlock from "../../components/render-block/render-block.jsx";
|
|
5
5
|
import { isEditing } from "../../functions/is-editing.js";
|
|
6
6
|
|
|
7
7
|
function FormComponent(props) {
|
|
@@ -17,8 +17,8 @@ function Image(props) {
|
|
|
17
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}
|
|
21
|
-
<source
|
|
20
|
+
}} src={props.image} srcset={props.srcset} sizes={props.sizes} />
|
|
21
|
+
<source srcset={props.srcset} />
|
|
22
22
|
</picture>
|
|
23
23
|
<Show when={props.aspectRatio && !(props.fitContent && props.builderBlock?.children?.length)}>
|
|
24
24
|
<div class={"builder-image-sizer " + css({
|
|
@@ -27,9 +27,7 @@ function Image(props) {
|
|
|
27
27
|
fontSize: "0"
|
|
28
28
|
})} style={{
|
|
29
29
|
"padding-top": props.aspectRatio * 100 + "%"
|
|
30
|
-
}}>
|
|
31
|
-
{" "}
|
|
32
|
-
</div>
|
|
30
|
+
}}></div>
|
|
33
31
|
</Show>
|
|
34
32
|
<Show when={props.builderBlock?.children?.length && props.fitContent}>
|
|
35
33
|
{props.children}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useContext, onMount } from "solid-js";
|
|
2
2
|
import { createMutable } from "solid-js/store";
|
|
3
|
-
import RenderContent from "../../components/render-content/render-content";
|
|
3
|
+
import RenderContent from "../../components/render-content/render-content.jsx";
|
|
4
4
|
import BuilderContext from "../../context/builder.context";
|
|
5
5
|
|
|
6
6
|
function Symbol(props) {
|
|
@@ -3,7 +3,9 @@ import { createMutable } from "solid-js/store";
|
|
|
3
3
|
import { TARGET } from "../../constants/target.js";
|
|
4
4
|
import BuilderContext from "../../context/builder.context";
|
|
5
5
|
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
6
|
-
import RenderInlinedStyles from "../render-inlined-styles";
|
|
6
|
+
import RenderInlinedStyles from "../render-inlined-styles.jsx";
|
|
7
|
+
import { convertStyleMaptoCSS } from "../../helpers/css.js";
|
|
8
|
+
import { getMaxWidthQueryForSize } from "../../constants/device-sizes.js";
|
|
7
9
|
|
|
8
10
|
function BlockStyles(props) {
|
|
9
11
|
const state = createMutable({
|
|
@@ -15,35 +17,25 @@ function BlockStyles(props) {
|
|
|
15
17
|
});
|
|
16
18
|
},
|
|
17
19
|
|
|
18
|
-
camelToKebabCase(string) {
|
|
19
|
-
return string.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
|
|
20
|
-
},
|
|
21
|
-
|
|
22
20
|
get css() {
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
str += `${state.camelToKebabCase(key)}: ${value};`;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
str += "}";
|
|
41
|
-
return str;
|
|
21
|
+
const styles = state.useBlock.responsiveStyles;
|
|
22
|
+
const largeStyles = styles?.large;
|
|
23
|
+
const mediumStyles = styles?.medium;
|
|
24
|
+
const smallStyles = styles?.small;
|
|
25
|
+
return `
|
|
26
|
+
${largeStyles ? `.${state.useBlock.id} {${convertStyleMaptoCSS(largeStyles)}}` : ""}
|
|
27
|
+
${mediumStyles ? `${getMaxWidthQueryForSize("medium")} {
|
|
28
|
+
.${state.useBlock.id} {${convertStyleMaptoCSS(mediumStyles)}}
|
|
29
|
+
}` : ""}
|
|
30
|
+
${smallStyles ? `${getMaxWidthQueryForSize("small")} {
|
|
31
|
+
.${state.useBlock.id} {${convertStyleMaptoCSS(smallStyles)}}
|
|
32
|
+
}` : ""}
|
|
33
|
+
}`;
|
|
42
34
|
}
|
|
43
35
|
|
|
44
36
|
});
|
|
45
37
|
const builderContext = useContext(BuilderContext);
|
|
46
|
-
return <Show when={TARGET === "
|
|
38
|
+
return <Show when={TARGET === "vue2" || TARGET === "vue3" || TARGET === "svelte"}>
|
|
47
39
|
<RenderInlinedStyles styles={state.css}></RenderInlinedStyles>
|
|
48
40
|
</Show>;
|
|
49
41
|
}
|
|
@@ -8,9 +8,9 @@ import { getBlockProperties } from "../../functions/get-block-properties.js";
|
|
|
8
8
|
import { getBlockStyles } from "../../functions/get-block-styles.js";
|
|
9
9
|
import { getBlockTag } from "../../functions/get-block-tag.js";
|
|
10
10
|
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
11
|
-
import BlockStyles from "./block-styles";
|
|
11
|
+
import BlockStyles from "./block-styles.jsx";
|
|
12
12
|
import { isEmptyHtmlElement } from "./render-block.helpers.js";
|
|
13
|
-
import RenderComponent from "./render-component";
|
|
13
|
+
import RenderComponent from "./render-component.jsx";
|
|
14
14
|
|
|
15
15
|
function RenderBlock(props) {
|
|
16
16
|
const state = createMutable({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Show, For } from "solid-js";
|
|
2
2
|
import { Dynamic } from "solid-js/web";
|
|
3
|
-
import BlockStyles from "./block-styles";
|
|
4
|
-
import RenderBlock from "./render-block";
|
|
3
|
+
import BlockStyles from "./block-styles.jsx";
|
|
4
|
+
import RenderBlock from "./render-block.jsx";
|
|
5
5
|
|
|
6
6
|
function RenderComponent(props) {
|
|
7
7
|
return <Show when={props.componentRef}>
|
|
@@ -2,8 +2,8 @@ import { Show, For } from "solid-js";
|
|
|
2
2
|
import { createMutable } from "solid-js/store";
|
|
3
3
|
import { css } from "solid-styled-components";
|
|
4
4
|
import { isEditing } from "../functions/is-editing.js";
|
|
5
|
-
import BlockStyles from "./render-block/block-styles";
|
|
6
|
-
import RenderBlock from "./render-block/render-block";
|
|
5
|
+
import BlockStyles from "./render-block/block-styles.jsx";
|
|
6
|
+
import RenderBlock from "./render-block/render-block.jsx";
|
|
7
7
|
|
|
8
8
|
function RenderBlocks(props) {
|
|
9
9
|
const state = createMutable({
|
|
@@ -14,8 +14,8 @@ import { isPreviewing } from "../../functions/is-previewing.js";
|
|
|
14
14
|
import { previewingModelName } from "../../functions/previewing-model-name.js";
|
|
15
15
|
import { components, createRegisterComponentMessage } from "../../functions/register-component.js";
|
|
16
16
|
import { track } from "../../functions/track.js";
|
|
17
|
-
import RenderBlocks from "../render-blocks";
|
|
18
|
-
import RenderContentStyles from "./components/render-styles";
|
|
17
|
+
import RenderBlocks from "../render-blocks.jsx";
|
|
18
|
+
import RenderContentStyles from "./components/render-styles.jsx";
|
|
19
19
|
|
|
20
20
|
function RenderContent(props) {
|
|
21
21
|
const state = createMutable({
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
const
|
|
2
|
-
const sizes = {
|
|
3
|
-
xsmall: {
|
|
4
|
-
min: 0,
|
|
5
|
-
default: 0,
|
|
6
|
-
max: 0
|
|
7
|
-
},
|
|
1
|
+
const SIZES = {
|
|
8
2
|
small: {
|
|
9
3
|
min: 320,
|
|
10
4
|
default: 321,
|
|
@@ -19,21 +13,9 @@ const sizes = {
|
|
|
19
13
|
min: 990,
|
|
20
14
|
default: 991,
|
|
21
15
|
max: 1200
|
|
22
|
-
},
|
|
23
|
-
getWidthForSize(size) {
|
|
24
|
-
return this[size].default;
|
|
25
|
-
},
|
|
26
|
-
getSizeForWidth(width) {
|
|
27
|
-
for (const size of sizeNames) {
|
|
28
|
-
const value = this[size];
|
|
29
|
-
if (width <= value.max) {
|
|
30
|
-
return size;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return "large";
|
|
34
16
|
}
|
|
35
17
|
};
|
|
18
|
+
const getMaxWidthQueryForSize = (size) => `@media (max-width: ${SIZES[size].max}px)`;
|
|
36
19
|
export {
|
|
37
|
-
|
|
38
|
-
sizes
|
|
20
|
+
getMaxWidthQueryForSize
|
|
39
21
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { camelToKebabCase } from "../functions/camel-to-kebab-case";
|
|
2
|
+
const convertStyleMaptoCSS = (style) => {
|
|
3
|
+
const cssProps = Object.entries(style).map(([key, value]) => {
|
|
4
|
+
if (typeof value === "string") {
|
|
5
|
+
return `${camelToKebabCase(key)}: ${value};`;
|
|
6
|
+
}
|
|
7
|
+
});
|
|
8
|
+
return cssProps.join("\n");
|
|
9
|
+
};
|
|
10
|
+
export {
|
|
11
|
+
convertStyleMaptoCSS
|
|
12
|
+
};
|
|
@@ -7,11 +7,13 @@ import { default as default7 } from "../blocks/button/button.jsx";
|
|
|
7
7
|
import { default as default8 } from "../blocks/section/section.jsx";
|
|
8
8
|
import { default as default9 } from "../blocks/fragment/fragment.jsx";
|
|
9
9
|
import { default as default10 } from "../components/render-content/render-content.jsx";
|
|
10
|
+
import { default as default11 } from "../components/render-blocks.jsx";
|
|
10
11
|
export {
|
|
11
12
|
default7 as Button,
|
|
12
13
|
default2 as Columns,
|
|
13
14
|
default9 as Fragment,
|
|
14
15
|
default3 as Image,
|
|
16
|
+
default11 as RenderBlocks,
|
|
15
17
|
default10 as RenderContent,
|
|
16
18
|
default8 as Section,
|
|
17
19
|
default6 as Symbol,
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Show } from "solid-js";
|
|
2
|
-
|
|
3
|
-
function Button(props) {
|
|
4
|
-
return (
|
|
5
|
-
<>
|
|
6
|
-
<Show
|
|
7
|
-
fallback={<span {...props.attributes}>{props.text}</span>}
|
|
8
|
-
when={props.link}
|
|
9
|
-
>
|
|
10
|
-
<a
|
|
11
|
-
{...props.attributes}
|
|
12
|
-
role="button"
|
|
13
|
-
href={props.link}
|
|
14
|
-
target={props.openLinkInNewTab ? "_blank" : undefined}
|
|
15
|
-
>
|
|
16
|
-
{props.text}
|
|
17
|
-
</a>
|
|
18
|
-
</Show>
|
|
19
|
-
</>
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export default Button;
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { For } from "solid-js";
|
|
2
|
-
|
|
3
|
-
import { createMutable } from "solid-js/store";
|
|
4
|
-
import { css } from "solid-styled-components";
|
|
5
|
-
|
|
6
|
-
import RenderBlocks from "../../components/render-blocks.lite";
|
|
7
|
-
|
|
8
|
-
function Columns(props) {
|
|
9
|
-
const state = createMutable({
|
|
10
|
-
getGutterSize() {
|
|
11
|
-
return typeof props.space === "number" ? props.space || 0 : 20;
|
|
12
|
-
},
|
|
13
|
-
getColumns() {
|
|
14
|
-
return props.columns || [];
|
|
15
|
-
},
|
|
16
|
-
getWidth(index: number) {
|
|
17
|
-
const columns = this.getColumns();
|
|
18
|
-
return columns[index]?.width || 100 / columns.length;
|
|
19
|
-
},
|
|
20
|
-
getColumnCssWidth(index: number) {
|
|
21
|
-
const columns = this.getColumns();
|
|
22
|
-
const gutterSize = this.getGutterSize();
|
|
23
|
-
const subtractWidth =
|
|
24
|
-
(gutterSize * (columns.length - 1)) / columns.length;
|
|
25
|
-
return `calc(${this.getWidth(index)}% - ${subtractWidth}px)`;
|
|
26
|
-
},
|
|
27
|
-
maybeApplyForTablet(prop: CSSProperties["flexDirection"]) {
|
|
28
|
-
const _stackColumnsAt = props.stackColumnsAt || "tablet";
|
|
29
|
-
|
|
30
|
-
return _stackColumnsAt === "tablet" ? prop : "inherit";
|
|
31
|
-
},
|
|
32
|
-
get columnsCssVars() {
|
|
33
|
-
const flexDir =
|
|
34
|
-
props.stackColumnsAt === "never"
|
|
35
|
-
? "inherit"
|
|
36
|
-
: props.reverseColumnsWhenStacked
|
|
37
|
-
? "column-reverse"
|
|
38
|
-
: "column";
|
|
39
|
-
return {
|
|
40
|
-
"--flex-dir": flexDir,
|
|
41
|
-
"--flex-dir-tablet": this.maybeApplyForTablet(flexDir),
|
|
42
|
-
};
|
|
43
|
-
},
|
|
44
|
-
get columnCssVars() {
|
|
45
|
-
const width = "100%";
|
|
46
|
-
const marginLeft = "0";
|
|
47
|
-
return {
|
|
48
|
-
"--column-width": width,
|
|
49
|
-
"--column-margin-left": marginLeft,
|
|
50
|
-
"--column-width-tablet": this.maybeApplyForTablet(width),
|
|
51
|
-
"--column-margin-left-tablet": this.maybeApplyForTablet(marginLeft),
|
|
52
|
-
};
|
|
53
|
-
},
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
return (
|
|
57
|
-
<div
|
|
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
|
-
}
|
|
72
|
-
style={state.columnsCssVars}
|
|
73
|
-
>
|
|
74
|
-
<For each={props.columns}>
|
|
75
|
-
{(column, _index) => {
|
|
76
|
-
const index = _index();
|
|
77
|
-
return (
|
|
78
|
-
<div
|
|
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
|
-
}
|
|
93
|
-
style={{
|
|
94
|
-
width: state.getColumnCssWidth(index),
|
|
95
|
-
"margin-left": `${index === 0 ? 0 : state.getGutterSize()}px`,
|
|
96
|
-
...state.columnCssVars,
|
|
97
|
-
}}
|
|
98
|
-
key={index}
|
|
99
|
-
>
|
|
100
|
-
<RenderBlocks blocks={column.blocks}></RenderBlocks>
|
|
101
|
-
</div>
|
|
102
|
-
);
|
|
103
|
-
}}
|
|
104
|
-
</For>
|
|
105
|
-
</div>
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export default Columns;
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { onMount } from "solid-js";
|
|
2
|
-
|
|
3
|
-
import { createMutable } from "solid-js/store";
|
|
4
|
-
|
|
5
|
-
function CustomCode(props) {
|
|
6
|
-
const state = createMutable({
|
|
7
|
-
scriptsInserted: [],
|
|
8
|
-
scriptsRun: [],
|
|
9
|
-
findAndRunScripts() {
|
|
10
|
-
// TODO: Move this function to standalone one in '@builder.io/utils'
|
|
11
|
-
if (elem && typeof window !== "undefined") {
|
|
12
|
-
/** @type {HTMLScriptElement[]} */
|
|
13
|
-
const scripts = elem.getElementsByTagName("script");
|
|
14
|
-
|
|
15
|
-
for (let i = 0; i < scripts.length; i++) {
|
|
16
|
-
const script = scripts[i];
|
|
17
|
-
|
|
18
|
-
if (script.src) {
|
|
19
|
-
if (state.scriptsInserted.includes(script.src)) {
|
|
20
|
-
continue;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
state.scriptsInserted.push(script.src);
|
|
24
|
-
const newScript = document.createElement("script");
|
|
25
|
-
newScript.async = true;
|
|
26
|
-
newScript.src = script.src;
|
|
27
|
-
document.head.appendChild(newScript);
|
|
28
|
-
} else if (
|
|
29
|
-
!script.type ||
|
|
30
|
-
[
|
|
31
|
-
"text/javascript",
|
|
32
|
-
"application/javascript",
|
|
33
|
-
"application/ecmascript",
|
|
34
|
-
].includes(script.type)
|
|
35
|
-
) {
|
|
36
|
-
if (state.scriptsRun.includes(script.innerText)) {
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
try {
|
|
41
|
-
state.scriptsRun.push(script.innerText);
|
|
42
|
-
new Function(script.innerText)();
|
|
43
|
-
} catch (error) {
|
|
44
|
-
console.warn("`CustomCode`: Error running script:", error);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
const elem = useRef();
|
|
53
|
-
|
|
54
|
-
onMount(() => {
|
|
55
|
-
state.findAndRunScripts();
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
return (
|
|
59
|
-
<div
|
|
60
|
-
class={
|
|
61
|
-
"builder-custom-code" + (props.replaceNodes ? " replace-nodes" : "")
|
|
62
|
-
}
|
|
63
|
-
ref={elem}
|
|
64
|
-
innerHTML={props.code}
|
|
65
|
-
></div>
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export default CustomCode;
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { onMount } from "solid-js";
|
|
2
|
-
|
|
3
|
-
import { createMutable } from "solid-js/store";
|
|
4
|
-
|
|
5
|
-
function Embed(props) {
|
|
6
|
-
const state = createMutable({
|
|
7
|
-
scriptsInserted: [],
|
|
8
|
-
scriptsRun: [],
|
|
9
|
-
findAndRunScripts() {
|
|
10
|
-
// TODO: Move this function to standalone one in '@builder.io/utils'
|
|
11
|
-
if (elem && typeof window !== "undefined") {
|
|
12
|
-
/** @type {HTMLScriptElement[]} */
|
|
13
|
-
const scripts = elem.getElementsByTagName("script");
|
|
14
|
-
|
|
15
|
-
for (let i = 0; i < scripts.length; i++) {
|
|
16
|
-
const script = scripts[i];
|
|
17
|
-
|
|
18
|
-
if (script.src) {
|
|
19
|
-
if (state.scriptsInserted.includes(script.src)) {
|
|
20
|
-
continue;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
state.scriptsInserted.push(script.src);
|
|
24
|
-
const newScript = document.createElement("script");
|
|
25
|
-
newScript.async = true;
|
|
26
|
-
newScript.src = script.src;
|
|
27
|
-
document.head.appendChild(newScript);
|
|
28
|
-
} else if (
|
|
29
|
-
!script.type ||
|
|
30
|
-
[
|
|
31
|
-
"text/javascript",
|
|
32
|
-
"application/javascript",
|
|
33
|
-
"application/ecmascript",
|
|
34
|
-
].includes(script.type)
|
|
35
|
-
) {
|
|
36
|
-
if (state.scriptsRun.includes(script.innerText)) {
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
try {
|
|
41
|
-
state.scriptsRun.push(script.innerText);
|
|
42
|
-
new Function(script.innerText)();
|
|
43
|
-
} catch (error) {
|
|
44
|
-
console.warn("`Embed`: Error running script:", error);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
const elem = useRef();
|
|
53
|
-
|
|
54
|
-
onMount(() => {
|
|
55
|
-
state.findAndRunScripts();
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
return <div class="builder-embed" ref={elem} innerHTML={props.content}></div>;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export default Embed;
|