@builder.io/sdk-solid 0.0.16 → 0.0.17
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 +17 -5
- package/solid-index.jsx +5 -0
- package/src/blocks/BaseText.jsx +9 -0
- package/src/blocks/button/button.jsx +9 -6
- package/src/blocks/columns/columns.jsx +54 -52
- package/src/blocks/columns/component-info.js +26 -1
- package/src/blocks/custom-code/custom-code.jsx +35 -38
- package/src/blocks/embed/component-info.js +21 -1
- package/src/blocks/embed/embed.jsx +37 -42
- package/src/blocks/embed/helpers.js +9 -0
- package/src/blocks/form/form.jsx +175 -176
- package/src/blocks/image/component-info.js +48 -1
- package/src/blocks/image/image.helpers.js +48 -0
- package/src/blocks/image/image.jsx +44 -13
- package/src/blocks/img/img.jsx +1 -1
- package/src/blocks/symbol/component-info.js +1 -0
- package/src/blocks/symbol/symbol.jsx +39 -12
- package/src/blocks/text/text.jsx +1 -1
- package/src/blocks/util.js +7 -0
- package/src/blocks/video/video.jsx +21 -2
- package/src/components/render-block/block-styles.jsx +41 -31
- package/src/components/render-block/render-block.helpers.js +23 -0
- package/src/components/render-block/render-block.jsx +205 -90
- package/src/components/render-block/render-component-with-context.jsx +36 -0
- package/src/components/render-block/render-component.jsx +28 -0
- package/src/components/render-block/render-repeated-block.jsx +36 -0
- package/src/components/render-block/types.js +0 -0
- package/src/components/render-blocks.jsx +42 -33
- package/src/components/render-content/components/render-styles.jsx +39 -42
- package/src/components/render-content/index.js +4 -0
- package/src/components/render-content/render-content.jsx +199 -128
- package/src/components/render-inlined-styles.jsx +21 -5
- package/src/constants/builder-registered-components.js +54 -0
- package/src/constants/device-sizes.js +3 -21
- package/src/context/builder.context.js +3 -1
- package/src/context/types.js +0 -0
- package/src/functions/camel-to-kebab-case.js +4 -0
- package/src/functions/convert-style-object.js +14 -0
- package/src/functions/evaluate.js +1 -1
- package/src/functions/extract-text-styles.js +22 -0
- package/src/functions/fast-clone.js +4 -0
- package/src/functions/get-block-actions-handler.js +12 -0
- package/src/functions/get-block-actions.js +2 -7
- package/src/functions/get-block-component-options.js +6 -1
- package/src/functions/get-block-styles.js +27 -19
- package/src/functions/get-builder-search-params/index.js +17 -2
- package/src/functions/get-content/ab-testing.js +99 -0
- package/src/functions/get-content/fn.test.js +1 -1
- package/src/functions/get-content/index.js +20 -62
- package/src/functions/get-content/types.js +0 -0
- package/src/functions/get-fetch.js +2 -2
- package/src/functions/get-processed-block.js +24 -11
- package/src/functions/get-processed-block.test.js +2 -1
- package/src/functions/mark-mutable.js +10 -0
- package/src/functions/register-component.js +45 -26
- package/src/functions/sanitize-styles.js +4 -0
- package/src/functions/track.js +108 -13
- package/src/helpers/ab-tests.js +16 -0
- package/src/helpers/cookie.js +79 -0
- package/src/helpers/css.js +28 -0
- package/src/helpers/flatten.js +34 -0
- package/src/helpers/localStorage.js +34 -0
- package/src/helpers/nullable.js +4 -0
- package/src/helpers/sessionId.js +49 -0
- package/src/helpers/time.js +5 -0
- package/src/helpers/url.js +10 -0
- package/src/helpers/url.test.js +15 -0
- package/src/helpers/uuid.js +13 -0
- package/src/helpers/visitorId.js +33 -0
- package/src/index-helpers/blocks-exports.js +11 -9
- package/src/scripts/init-editing.js +4 -5
- package/src/types/can-track.js +0 -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 -5
- package/src/functions/macro-eval.js +0 -5
- package/src/functions/previewing-model-name.js +0 -11
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@builder.io/sdk-solid",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"type": "module",
|
|
3
|
+
"version": "0.0.17",
|
|
5
4
|
"description": "",
|
|
6
|
-
"
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./solid-index.jsx",
|
|
7
|
+
"module": "./solid-index.jsx",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./solid-index.jsx"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"release:patch": "npm version patch --no-git-tag-version && npm publish --access public",
|
|
13
|
+
"release:dev": "npm version prerelease --no-git-tag-version && npm publish --tag dev --access public"
|
|
14
|
+
},
|
|
7
15
|
"dependencies": {
|
|
16
|
+
"node-fetch": "^2.6.7",
|
|
8
17
|
"solid-styled-components": "^0.27.6"
|
|
9
18
|
},
|
|
10
19
|
"peerDependencies": {
|
|
11
|
-
"solid-js": "^1.3
|
|
20
|
+
"solid-js": "^1.4.3"
|
|
12
21
|
},
|
|
13
22
|
"devDependencies": {
|
|
14
|
-
"solid
|
|
23
|
+
"babel-preset-solid": "^1.3.17",
|
|
24
|
+
"solid-js": "^1.4.3",
|
|
25
|
+
"vite": "^3.0.4",
|
|
26
|
+
"vite-plugin-solid": "^2.2.6"
|
|
15
27
|
}
|
|
16
28
|
}
|
package/solid-index.jsx
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useContext } from "solid-js";
|
|
2
|
+
import BuilderContext from "../context/builder.context.js";
|
|
3
|
+
|
|
4
|
+
function BaseText(props) {
|
|
5
|
+
const builderContext = useContext(BuilderContext);
|
|
6
|
+
return <span style={builderContext.inheritedStyles}>{props.text}</span>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export default BaseText;
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { Show } from "solid-js";
|
|
2
|
+
import { css } from "solid-styled-components";
|
|
2
3
|
|
|
3
4
|
function Button(props) {
|
|
4
|
-
return
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
return <Show fallback={<button class={css({
|
|
6
|
+
all: "unset"
|
|
7
|
+
})} {...props.attributes}>
|
|
7
8
|
{props.text}
|
|
8
|
-
</
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
</button>} when={props.link}>
|
|
10
|
+
<a {...props.attributes} role="button" href={props.link} target={props.openLinkInNewTab ? "_blank" : undefined}>
|
|
11
|
+
{props.text}
|
|
12
|
+
</a>
|
|
13
|
+
</Show>;
|
|
11
14
|
}
|
|
12
15
|
|
|
13
16
|
export default Button;
|
|
@@ -1,74 +1,74 @@
|
|
|
1
1
|
import { For } from "solid-js";
|
|
2
|
-
import { createMutable } from "solid-js/store";
|
|
3
2
|
import { css } from "solid-styled-components";
|
|
4
|
-
import RenderBlocks from "../../components/render-blocks.
|
|
3
|
+
import RenderBlocks from "../../components/render-blocks.jsx";
|
|
4
|
+
import { markMutable } from "../../functions/mark-mutable";
|
|
5
5
|
|
|
6
6
|
function Columns(props) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
},
|
|
7
|
+
function getGutterSize() {
|
|
8
|
+
return typeof props.space === "number" ? props.space || 0 : 20;
|
|
9
|
+
}
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
function getColumns() {
|
|
12
|
+
return props.columns || [];
|
|
13
|
+
}
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
function getWidth(index) {
|
|
16
|
+
const columns = getColumns();
|
|
17
|
+
return columns[index]?.width || 100 / columns.length;
|
|
18
|
+
}
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
function getColumnCssWidth(index) {
|
|
21
|
+
const columns = getColumns();
|
|
22
|
+
const gutterSize = getGutterSize();
|
|
23
|
+
const subtractWidth = gutterSize * (columns.length - 1) / columns.length;
|
|
24
|
+
return `calc(${getWidth(index)}% - ${subtractWidth}px)`;
|
|
25
|
+
}
|
|
27
26
|
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
function maybeApplyForTablet(prop) {
|
|
28
|
+
const _stackColumnsAt = props.stackColumnsAt || "tablet";
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
return _stackColumnsAt === "tablet" ? prop : "inherit";
|
|
31
|
+
}
|
|
33
32
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
function columnsCssVars() {
|
|
34
|
+
const flexDir = props.stackColumnsAt === "never" ? "inherit" : props.reverseColumnsWhenStacked ? "column-reverse" : "column";
|
|
35
|
+
return {
|
|
36
|
+
"--flex-dir": flexDir,
|
|
37
|
+
"--flex-dir-tablet": maybeApplyForTablet(flexDir)
|
|
38
|
+
};
|
|
39
|
+
}
|
|
41
40
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
41
|
+
function columnCssVars() {
|
|
42
|
+
const width = "100%";
|
|
43
|
+
const marginLeft = "0";
|
|
44
|
+
return {
|
|
45
|
+
"--column-width": width,
|
|
46
|
+
"--column-margin-left": marginLeft,
|
|
47
|
+
"--column-width-tablet": maybeApplyForTablet(width),
|
|
48
|
+
"--column-margin-left-tablet": maybeApplyForTablet(marginLeft)
|
|
49
|
+
};
|
|
50
|
+
}
|
|
52
51
|
|
|
53
|
-
|
|
54
|
-
return <div class={css({
|
|
52
|
+
return <div class={"builder-columns " + css({
|
|
55
53
|
display: "flex",
|
|
56
54
|
alignItems: "stretch",
|
|
57
55
|
lineHeight: "normal",
|
|
58
|
-
"@media (max-width:
|
|
56
|
+
"@media (max-width: 991px)": {
|
|
59
57
|
flexDirection: "var(--flex-dir-tablet)"
|
|
60
58
|
},
|
|
61
59
|
"@media (max-width: 639px)": {
|
|
62
60
|
flexDirection: "var(--flex-dir)"
|
|
63
61
|
}
|
|
64
|
-
})} style={
|
|
62
|
+
})} style={columnsCssVars()}>
|
|
65
63
|
<For each={props.columns}>
|
|
66
64
|
{(column, _index) => {
|
|
67
65
|
const index = _index();
|
|
68
66
|
|
|
69
|
-
return <div class={css({
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
return <div class={"builder-column " + css({
|
|
68
|
+
display: "flex",
|
|
69
|
+
flexDirection: "column",
|
|
70
|
+
alignItems: "stretch",
|
|
71
|
+
"@media (max-width: 991px)": {
|
|
72
72
|
width: "var(--column-width-tablet) !important",
|
|
73
73
|
marginLeft: "var(--column-margin-left-tablet) !important"
|
|
74
74
|
},
|
|
@@ -77,11 +77,13 @@ function Columns(props) {
|
|
|
77
77
|
marginLeft: "var(--column-margin-left) !important"
|
|
78
78
|
}
|
|
79
79
|
})} style={{
|
|
80
|
-
width:
|
|
81
|
-
"margin-left": `${index === 0 ? 0 :
|
|
82
|
-
...
|
|
83
|
-
}}>
|
|
84
|
-
<RenderBlocks blocks={column.blocks}
|
|
80
|
+
width: getColumnCssWidth(index),
|
|
81
|
+
"margin-left": `${index === 0 ? 0 : getGutterSize()}px`,
|
|
82
|
+
...columnCssVars()
|
|
83
|
+
}} key={index}>
|
|
84
|
+
<RenderBlocks blocks={markMutable(column.blocks)} path={`component.options.columns.${index}.blocks`} parent={props.builderBlock.id} style={{
|
|
85
|
+
"flex-grow": "1"
|
|
86
|
+
}}></RenderBlocks>
|
|
85
87
|
</div>;
|
|
86
88
|
}}
|
|
87
89
|
</For>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { markSerializable } from "../util.js";
|
|
1
2
|
const componentInfo = {
|
|
2
3
|
name: "Columns",
|
|
3
4
|
builtIn: true,
|
|
@@ -186,7 +187,31 @@ const componentInfo = {
|
|
|
186
187
|
]
|
|
187
188
|
}
|
|
188
189
|
],
|
|
189
|
-
onChange:
|
|
190
|
+
onChange: markSerializable((options) => {
|
|
191
|
+
function clearWidths() {
|
|
192
|
+
columns.forEach((col) => {
|
|
193
|
+
col.delete("width");
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
const columns = options.get("columns");
|
|
197
|
+
if (Array.isArray(columns)) {
|
|
198
|
+
const containsColumnWithWidth = !!columns.find((col) => col.get("width"));
|
|
199
|
+
if (containsColumnWithWidth) {
|
|
200
|
+
const containsColumnWithoutWidth = !!columns.find((col) => !col.get("width"));
|
|
201
|
+
if (containsColumnWithoutWidth) {
|
|
202
|
+
clearWidths();
|
|
203
|
+
} else {
|
|
204
|
+
const sumWidths = columns.reduce((memo, col) => {
|
|
205
|
+
return memo + col.get("width");
|
|
206
|
+
}, 0);
|
|
207
|
+
const widthsDontAddUp = sumWidths !== 100;
|
|
208
|
+
if (widthsDontAddUp) {
|
|
209
|
+
clearWidths();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
})
|
|
190
215
|
},
|
|
191
216
|
{
|
|
192
217
|
name: "space",
|
|
@@ -1,49 +1,46 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { onMount, createSignal } from "solid-js";
|
|
2
2
|
|
|
3
3
|
function CustomCode(props) {
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
} catch (error) {
|
|
36
|
-
console.warn("`CustomCode`: Error running script:", error);
|
|
37
|
-
}
|
|
4
|
+
const [scriptsInserted, setScriptsInserted] = createSignal([]);
|
|
5
|
+
const [scriptsRun, setScriptsRun] = createSignal([]);
|
|
6
|
+
|
|
7
|
+
function findAndRunScripts() {
|
|
8
|
+
// TODO: Move this function to standalone one in '@builder.io/utils'
|
|
9
|
+
if (elem && elem.getElementsByTagName && typeof window !== "undefined") {
|
|
10
|
+
const scripts = elem.getElementsByTagName("script");
|
|
11
|
+
|
|
12
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
13
|
+
const script = scripts[i];
|
|
14
|
+
|
|
15
|
+
if (script.src) {
|
|
16
|
+
if (scriptsInserted().includes(script.src)) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
scriptsInserted().push(script.src);
|
|
21
|
+
const newScript = document.createElement("script");
|
|
22
|
+
newScript.async = true;
|
|
23
|
+
newScript.src = script.src;
|
|
24
|
+
document.head.appendChild(newScript);
|
|
25
|
+
} else if (!script.type || ["text/javascript", "application/javascript", "application/ecmascript"].includes(script.type)) {
|
|
26
|
+
if (scriptsRun().includes(script.innerText)) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
scriptsRun().push(script.innerText);
|
|
32
|
+
new Function(script.innerText)();
|
|
33
|
+
} catch (error) {
|
|
34
|
+
console.warn("`CustomCode`: Error running script:", error);
|
|
38
35
|
}
|
|
39
36
|
}
|
|
40
37
|
}
|
|
41
38
|
}
|
|
39
|
+
}
|
|
42
40
|
|
|
43
|
-
|
|
44
|
-
const elem = useRef();
|
|
41
|
+
let elem;
|
|
45
42
|
onMount(() => {
|
|
46
|
-
|
|
43
|
+
findAndRunScripts();
|
|
47
44
|
});
|
|
48
45
|
return <div class={"builder-custom-code" + (props.replaceNodes ? " replace-nodes" : "")} ref={elem} innerHTML={props.code}></div>;
|
|
49
46
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { markSerializable } from "../util.js";
|
|
1
2
|
const componentInfo = {
|
|
2
3
|
name: "Embed",
|
|
3
4
|
static: true,
|
|
@@ -9,7 +10,26 @@ const componentInfo = {
|
|
|
9
10
|
required: true,
|
|
10
11
|
defaultValue: "",
|
|
11
12
|
helperText: "e.g. enter a youtube url, google map, etc",
|
|
12
|
-
onChange:
|
|
13
|
+
onChange: markSerializable((options) => {
|
|
14
|
+
const url = options.get("url");
|
|
15
|
+
if (url) {
|
|
16
|
+
options.set("content", "Loading...");
|
|
17
|
+
const apiKey = "ae0e60e78201a3f2b0de4b";
|
|
18
|
+
return fetch(`https://iframe.ly/api/iframely?url=${url}&api_key=${apiKey}`).then((res) => res.json()).then((data) => {
|
|
19
|
+
if (options.get("url") === url) {
|
|
20
|
+
if (data.html) {
|
|
21
|
+
options.set("content", data.html);
|
|
22
|
+
} else {
|
|
23
|
+
options.set("content", "Invalid url, please try another");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}).catch((_err) => {
|
|
27
|
+
options.set("content", "There was an error embedding this URL, please try again or another URL");
|
|
28
|
+
});
|
|
29
|
+
} else {
|
|
30
|
+
options.delete("content");
|
|
31
|
+
}
|
|
32
|
+
})
|
|
13
33
|
},
|
|
14
34
|
{
|
|
15
35
|
name: "content",
|
|
@@ -1,51 +1,46 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { on, createEffect, createSignal } from "solid-js";
|
|
2
|
+
import { isJsScript } from "./helpers.js";
|
|
2
3
|
|
|
3
4
|
function Embed(props) {
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
} else if (!script.type || ["text/javascript", "application/javascript", "application/ecmascript"].includes(script.type)) {
|
|
28
|
-
if (state.scriptsRun.includes(script.innerText)) {
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
try {
|
|
33
|
-
state.scriptsRun.push(script.innerText);
|
|
34
|
-
new Function(script.innerText)();
|
|
35
|
-
} catch (error) {
|
|
36
|
-
console.warn("`Embed`: Error running script:", error);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
5
|
+
const [scriptsInserted, setScriptsInserted] = createSignal([]);
|
|
6
|
+
const [scriptsRun, setScriptsRun] = createSignal([]);
|
|
7
|
+
const [ranInitFn, setRanInitFn] = createSignal(false);
|
|
8
|
+
|
|
9
|
+
function findAndRunScripts() {
|
|
10
|
+
if (!elem || !elem.getElementsByTagName) return;
|
|
11
|
+
const scripts = elem.getElementsByTagName("script");
|
|
12
|
+
|
|
13
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
14
|
+
const script = scripts[i];
|
|
15
|
+
|
|
16
|
+
if (script.src && !scriptsInserted().includes(script.src)) {
|
|
17
|
+
scriptsInserted().push(script.src);
|
|
18
|
+
const newScript = document.createElement("script");
|
|
19
|
+
newScript.async = true;
|
|
20
|
+
newScript.src = script.src;
|
|
21
|
+
document.head.appendChild(newScript);
|
|
22
|
+
} else if (isJsScript(script) && !scriptsRun().includes(script.innerText)) {
|
|
23
|
+
try {
|
|
24
|
+
scriptsRun().push(script.innerText);
|
|
25
|
+
new Function(script.innerText)();
|
|
26
|
+
} catch (error) {
|
|
27
|
+
console.warn("`Embed`: Error running script:", error);
|
|
39
28
|
}
|
|
40
29
|
}
|
|
41
30
|
}
|
|
31
|
+
}
|
|
42
32
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
33
|
+
let elem;
|
|
34
|
+
|
|
35
|
+
function onUpdateFn_0() {
|
|
36
|
+
if (elem && !ranInitFn()) {
|
|
37
|
+
setRanInitFn(true);
|
|
38
|
+
findAndRunScripts();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
createEffect(on(() => [elem, ranInitFn()], onUpdateFn_0));
|
|
43
|
+
return <div class="builder-embed" ref={elem} innerHTML={props.content}></div>;
|
|
49
44
|
}
|
|
50
45
|
|
|
51
46
|
export default Embed;
|