@builder.io/sdk-solid 0.0.15 → 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.
Files changed (119) hide show
  1. package/README.md +5 -1
  2. package/package.json +17 -5
  3. package/solid-index.jsx +5 -0
  4. package/src/blocks/BaseText.jsx +9 -0
  5. package/src/blocks/button/button.jsx +9 -6
  6. package/src/blocks/columns/columns.jsx +54 -52
  7. package/src/blocks/columns/component-info.js +26 -1
  8. package/src/blocks/custom-code/custom-code.jsx +35 -38
  9. package/src/blocks/embed/component-info.js +21 -1
  10. package/src/blocks/embed/embed.jsx +37 -42
  11. package/src/blocks/embed/helpers.js +9 -0
  12. package/src/blocks/form/form.jsx +175 -176
  13. package/src/blocks/image/component-info.js +48 -1
  14. package/src/blocks/image/image.helpers.js +48 -0
  15. package/src/blocks/image/image.jsx +44 -13
  16. package/src/blocks/img/img.jsx +1 -1
  17. package/src/blocks/symbol/component-info.js +1 -0
  18. package/src/blocks/symbol/symbol.jsx +40 -13
  19. package/src/blocks/text/text.jsx +1 -1
  20. package/src/blocks/util.js +7 -0
  21. package/src/blocks/video/video.jsx +21 -2
  22. package/src/components/render-block/block-styles.jsx +41 -31
  23. package/src/components/render-block/render-block.helpers.js +23 -0
  24. package/src/components/render-block/render-block.jsx +205 -90
  25. package/src/components/render-block/render-component-with-context.jsx +36 -0
  26. package/src/components/render-block/render-component.jsx +28 -0
  27. package/src/components/render-block/render-repeated-block.jsx +36 -0
  28. package/src/components/render-block/types.js +0 -0
  29. package/src/components/render-blocks.jsx +42 -33
  30. package/src/components/render-content/components/render-styles.jsx +39 -42
  31. package/src/components/render-content/index.js +4 -0
  32. package/src/components/render-content/render-content.jsx +200 -129
  33. package/src/components/render-inlined-styles.jsx +21 -5
  34. package/src/constants/builder-registered-components.js +54 -0
  35. package/src/constants/device-sizes.js +3 -21
  36. package/src/context/builder.context.js +3 -1
  37. package/src/context/types.js +0 -0
  38. package/src/functions/camel-to-kebab-case.js +4 -0
  39. package/src/functions/convert-style-object.js +14 -0
  40. package/src/functions/evaluate.js +1 -1
  41. package/src/functions/extract-text-styles.js +22 -0
  42. package/src/functions/fast-clone.js +4 -0
  43. package/src/functions/get-block-actions-handler.js +12 -0
  44. package/src/functions/get-block-actions.js +2 -7
  45. package/src/functions/get-block-component-options.js +6 -1
  46. package/src/functions/get-block-styles.js +27 -19
  47. package/src/functions/get-builder-search-params/index.js +17 -2
  48. package/src/functions/get-content/ab-testing.js +99 -0
  49. package/src/functions/get-content/fn.test.js +1 -1
  50. package/src/functions/get-content/index.js +20 -62
  51. package/src/functions/get-content/types.js +0 -0
  52. package/src/functions/get-fetch.js +2 -2
  53. package/src/functions/get-processed-block.js +24 -11
  54. package/src/functions/get-processed-block.test.js +2 -1
  55. package/src/functions/mark-mutable.js +10 -0
  56. package/src/functions/register-component.js +45 -26
  57. package/src/functions/sanitize-styles.js +4 -0
  58. package/src/functions/track.js +108 -13
  59. package/src/helpers/ab-tests.js +16 -0
  60. package/src/helpers/cookie.js +79 -0
  61. package/src/helpers/css.js +28 -0
  62. package/src/helpers/flatten.js +34 -0
  63. package/src/helpers/localStorage.js +34 -0
  64. package/src/helpers/nullable.js +4 -0
  65. package/src/helpers/sessionId.js +49 -0
  66. package/src/helpers/time.js +5 -0
  67. package/src/helpers/url.js +10 -0
  68. package/src/helpers/url.test.js +15 -0
  69. package/src/helpers/uuid.js +13 -0
  70. package/src/helpers/visitorId.js +33 -0
  71. package/src/index-helpers/blocks-exports.js +11 -9
  72. package/src/scripts/init-editing.js +4 -5
  73. package/src/types/can-track.js +0 -0
  74. package/src/types/components.js +0 -0
  75. package/src/types/element.js +0 -0
  76. package/src/blocks/button/button.lite.tsx +0 -20
  77. package/src/blocks/button/index.js +0 -7
  78. package/src/blocks/columns/columns.lite.tsx +0 -102
  79. package/src/blocks/columns/index.js +0 -7
  80. package/src/blocks/custom-code/custom-code.lite.tsx +0 -67
  81. package/src/blocks/custom-code/index.js +0 -7
  82. package/src/blocks/embed/embed.lite.tsx +0 -59
  83. package/src/blocks/embed/index.js +0 -7
  84. package/src/blocks/form/form.lite.tsx +0 -293
  85. package/src/blocks/form/index.js +0 -7
  86. package/src/blocks/fragment/fragment.lite.tsx +0 -5
  87. package/src/blocks/fragment/index.js +0 -7
  88. package/src/blocks/image/image.lite.tsx +0 -83
  89. package/src/blocks/image/index.js +0 -7
  90. package/src/blocks/img/img.lite.tsx +0 -18
  91. package/src/blocks/img/index.js +0 -7
  92. package/src/blocks/input/index.js +0 -7
  93. package/src/blocks/input/input.lite.tsx +0 -20
  94. package/src/blocks/raw-text/index.js +0 -7
  95. package/src/blocks/raw-text/raw-text.lite.tsx +0 -10
  96. package/src/blocks/section/index.js +0 -7
  97. package/src/blocks/section/section.lite.tsx +0 -18
  98. package/src/blocks/select/index.js +0 -7
  99. package/src/blocks/select/select.lite.tsx +0 -28
  100. package/src/blocks/submit-button/index.js +0 -7
  101. package/src/blocks/submit-button/submit-button.lite.tsx +0 -9
  102. package/src/blocks/symbol/index.js +0 -7
  103. package/src/blocks/symbol/symbol.lite.tsx +0 -39
  104. package/src/blocks/text/index.js +0 -7
  105. package/src/blocks/text/text.lite.tsx +0 -5
  106. package/src/blocks/textarea/index.js +0 -7
  107. package/src/blocks/textarea/textarea.lite.tsx +0 -13
  108. package/src/blocks/video/index.js +0 -7
  109. package/src/blocks/video/video.lite.tsx +0 -26
  110. package/src/components/error-boundary.jsx +0 -5
  111. package/src/components/error-boundary.lite.tsx +0 -5
  112. package/src/components/render-block/block-styles.lite.tsx +0 -38
  113. package/src/components/render-block/render-block.lite.tsx +0 -119
  114. package/src/components/render-blocks.lite.tsx +0 -75
  115. package/src/components/render-content/components/render-styles.lite.tsx +0 -76
  116. package/src/components/render-content/render-content.lite.tsx +0 -232
  117. package/src/components/render-inlined-styles.lite.tsx +0 -5
  118. package/src/functions/macro-eval.js +0 -5
  119. package/src/functions/previewing-model-name.js +0 -11
package/README.md CHANGED
@@ -1,3 +1,7 @@
1
1
  # Builder.io SDK for Solid
2
2
 
3
- More info comign soon
3
+ More info coming soon.
4
+
5
+ ## Mitosis
6
+
7
+ This SDK is generated by [Mitosis](https://github.com/BuilderIO/mitosis). To see the Mitosis source-code, go [here](../../).
package/package.json CHANGED
@@ -1,16 +1,28 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-solid",
3
- "version": "0.0.15",
4
- "type": "module",
3
+ "version": "0.0.17",
5
4
  "description": "",
6
- "module": "src/index.js",
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.15"
20
+ "solid-js": "^1.4.3"
12
21
  },
13
22
  "devDependencies": {
14
- "solid-js": "^1.3.15"
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
  }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * We need to have a `.jsx` entry point for our SolidJS SDK. To avoid enforcing this to all other frameworks,
3
+ * we add this file and use it to re-export the index.js file from the Mitosis-generated code.
4
+ */
5
+ export * from './src/index.js';
@@ -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
- <Show when={props.link}>
6
- <a {...props.attributes} role="button" href={props.link} target={props.openLinkInNewTab ? "_blank" : undefined}>
5
+ return <Show fallback={<button class={css({
6
+ all: "unset"
7
+ })} {...props.attributes}>
7
8
  {props.text}
8
- </a>
9
- </Show>
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..js";
3
+ import RenderBlocks from "../../components/render-blocks.jsx";
4
+ import { markMutable } from "../../functions/mark-mutable";
5
5
 
6
6
  function Columns(props) {
7
- const state = createMutable({
8
- getGutterSize() {
9
- return typeof props.space === "number" ? props.space || 0 : 20;
10
- },
7
+ function getGutterSize() {
8
+ return typeof props.space === "number" ? props.space || 0 : 20;
9
+ }
11
10
 
12
- getColumns() {
13
- return props.columns || [];
14
- },
11
+ function getColumns() {
12
+ return props.columns || [];
13
+ }
15
14
 
16
- getWidth(index) {
17
- const columns = this.getColumns();
18
- return columns[index]?.width || 100 / columns.length;
19
- },
15
+ function getWidth(index) {
16
+ const columns = getColumns();
17
+ return columns[index]?.width || 100 / columns.length;
18
+ }
20
19
 
21
- getColumnCssWidth(index) {
22
- const columns = this.getColumns();
23
- const gutterSize = this.getGutterSize();
24
- const subtractWidth = gutterSize * (columns.length - 1) / columns.length;
25
- return `calc(${this.getWidth(index)}% - ${subtractWidth}px)`;
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
- maybeApplyForTablet(prop) {
29
- const _stackColumnsAt = props.stackColumnsAt || "tablet";
27
+ function maybeApplyForTablet(prop) {
28
+ const _stackColumnsAt = props.stackColumnsAt || "tablet";
30
29
 
31
- return _stackColumnsAt === "tablet" ? prop : "inherit";
32
- },
30
+ return _stackColumnsAt === "tablet" ? prop : "inherit";
31
+ }
33
32
 
34
- get columnsCssVars() {
35
- const flexDir = props.stackColumnsAt === "never" ? "inherit" : props.reverseColumnsWhenStacked ? "column-reverse" : "column";
36
- return {
37
- "--flex-dir": flexDir,
38
- "--flex-dir-tablet": this.maybeApplyForTablet(flexDir)
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
- get columnCssVars() {
43
- const width = "100%";
44
- const marginLeft = "0";
45
- return {
46
- "--column-width": width,
47
- "--column-margin-left": marginLeft,
48
- "--column-width-tablet": this.maybeApplyForTablet(width),
49
- "--column-margin-left-tablet": this.maybeApplyForTablet(marginLeft)
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: 999px)": {
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={state.columnsCssVars}>
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
- flexGrow: "1",
71
- "@media (max-width: 999px)": {
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: state.getColumnCssWidth(index),
81
- "margin-left": `${index === 0 ? 0 : state.getGutterSize()}px`,
82
- ...state.columnCssVars
83
- }}>
84
- <RenderBlocks blocks={column.blocks}></RenderBlocks>
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: " function clearWidths() { columns.forEach(col => { col.delete('width'); }); } const columns = options.get('columns') as Array<Map<String, any>>; if (Array.isArray(columns)) { const containsColumnWithWidth = !!columns.find(col => col.get('width')); if (containsColumnWithWidth) { const containsColumnWithoutWidth = !!columns.find(col => !col.get('width')); if (containsColumnWithoutWidth) { clearWidths(); } else { const sumWidths = columns.reduce((memo, col) => { return memo + col.get('width'); }, 0); const widthsDontAddUp = sumWidths !== 100; if (widthsDontAddUp) { clearWidths(); } } } } "
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 { createMutable } from "solid-js/store";
1
+ import { onMount, createSignal } from "solid-js";
2
2
 
3
3
  function CustomCode(props) {
4
- const state = createMutable({
5
- scriptsInserted: [],
6
- scriptsRun: [],
7
-
8
- findAndRunScripts() {
9
- // TODO: Move this function to standalone one in '@builder.io/utils'
10
- if (elem && typeof window !== "undefined") {
11
- /** @type {HTMLScriptElement[]} */
12
- const scripts = elem.getElementsByTagName("script");
13
-
14
- for (let i = 0; i < scripts.length; i++) {
15
- const script = scripts[i];
16
-
17
- if (script.src) {
18
- if (state.scriptsInserted.includes(script.src)) {
19
- continue;
20
- }
21
-
22
- state.scriptsInserted.push(script.src);
23
- const newScript = document.createElement("script");
24
- newScript.async = true;
25
- newScript.src = script.src;
26
- document.head.appendChild(newScript);
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("`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
- state.findAndRunScripts();
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: " const url = options.get('url'); if (url) { options.set('content', 'Loading...'); // TODO: get this out of here! const apiKey = 'ae0e60e78201a3f2b0de4b'; return fetch(`https://iframe.ly/api/iframely?url=${url}&api_key=${apiKey}`) .then(res => res.json()) .then(data => { if (options.get('url') === url) { if (data.html) { options.set('content', data.html); } else { options.set('content', 'Invalid url, please try another'); } } }) .catch(err => { options.set( 'content', 'There was an error embedding this URL, please try again or another URL' ); }); } else { options.delete('content'); } "
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 { createMutable } from "solid-js/store";
1
+ import { on, createEffect, createSignal } from "solid-js";
2
+ import { isJsScript } from "./helpers.js";
2
3
 
3
4
  function Embed(props) {
4
- const state = createMutable({
5
- scriptsInserted: [],
6
- scriptsRun: [],
7
-
8
- findAndRunScripts() {
9
- // TODO: Move this function to standalone one in '@builder.io/utils'
10
- if (elem && typeof window !== "undefined") {
11
- /** @type {HTMLScriptElement[]} */
12
- const scripts = elem.getElementsByTagName("script");
13
-
14
- for (let i = 0; i < scripts.length; i++) {
15
- const script = scripts[i];
16
-
17
- if (script.src) {
18
- if (state.scriptsInserted.includes(script.src)) {
19
- continue;
20
- }
21
-
22
- state.scriptsInserted.push(script.src);
23
- const newScript = document.createElement("script");
24
- newScript.async = true;
25
- newScript.src = script.src;
26
- document.head.appendChild(newScript);
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
- const elem = useRef();
45
- onMount(() => {
46
- state.findAndRunScripts();
47
- });
48
- return <div ref={elem} innerHTML={props.content}></div>;
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;
@@ -0,0 +1,9 @@
1
+ const SCRIPT_MIME_TYPES = [
2
+ "text/javascript",
3
+ "application/javascript",
4
+ "application/ecmascript"
5
+ ];
6
+ const isJsScript = (script) => SCRIPT_MIME_TYPES.includes(script.type);
7
+ export {
8
+ isJsScript
9
+ };