@builder.io/sdk-solid 0.0.8-10 → 0.0.8-13

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 (40) hide show
  1. package/README.md +5 -1
  2. package/package.json +1 -1
  3. package/src/blocks/columns/columns.jsx +1 -1
  4. package/src/blocks/custom-code/custom-code.jsx +1 -2
  5. package/src/blocks/embed/embed.jsx +1 -2
  6. package/src/blocks/form/form.jsx +2 -2
  7. package/src/blocks/image/image.jsx +2 -2
  8. package/src/blocks/symbol/symbol.jsx +1 -1
  9. package/src/components/render-block/block-styles.jsx +19 -4
  10. package/src/components/render-block/render-block.jsx +30 -30
  11. package/src/components/render-block/render-component.jsx +27 -0
  12. package/src/components/render-blocks.jsx +12 -2
  13. package/src/components/render-content/components/render-styles.jsx +1 -1
  14. package/src/components/render-content/render-content.jsx +2 -2
  15. package/src/functions/get-block-component-options.js +6 -1
  16. package/src/index-helpers/blocks-exports.js +2 -0
  17. package/src/blocks/button/button.lite.tsx +0 -23
  18. package/src/blocks/columns/columns.lite.tsx +0 -109
  19. package/src/blocks/custom-code/custom-code.lite.tsx +0 -69
  20. package/src/blocks/embed/embed.lite.tsx +0 -61
  21. package/src/blocks/form/form.lite.tsx +0 -296
  22. package/src/blocks/fragment/fragment.lite.tsx +0 -5
  23. package/src/blocks/image/image.lite.tsx +0 -86
  24. package/src/blocks/img/img.lite.tsx +0 -18
  25. package/src/blocks/input/input.lite.tsx +0 -20
  26. package/src/blocks/raw-text/raw-text.lite.tsx +0 -10
  27. package/src/blocks/section/section.lite.tsx +0 -18
  28. package/src/blocks/select/select.lite.tsx +0 -28
  29. package/src/blocks/submit-button/submit-button.lite.tsx +0 -9
  30. package/src/blocks/symbol/symbol.lite.tsx +0 -41
  31. package/src/blocks/text/text.lite.tsx +0 -5
  32. package/src/blocks/textarea/textarea.lite.tsx +0 -13
  33. package/src/blocks/video/video.lite.tsx +0 -26
  34. package/src/components/error-boundary.lite.tsx +0 -5
  35. package/src/components/render-block/block-styles.lite.tsx +0 -38
  36. package/src/components/render-block/render-block.lite.tsx +0 -154
  37. package/src/components/render-blocks.lite.tsx +0 -75
  38. package/src/components/render-content/components/render-styles.lite.tsx +0 -76
  39. package/src/components/render-content/render-content.lite.tsx +0 -262
  40. package/src/components/render-inlined-styles.lite.tsx +0 -29
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-solid",
3
- "version": "0.0.8-10",
3
+ "version": "0.0.8-13",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./src/solid-index.jsx",
@@ -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++) {
@@ -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} srcSet={props.srcset} sizes={props.sizes} />
21
- <source srcSet={props.srcset} />
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({
@@ -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) {
@@ -1,21 +1,33 @@
1
+ import { useContext, Show } from "solid-js";
1
2
  import { createMutable } from "solid-js/store";
2
- import RenderInlinedStyles from "../render-inlined-styles";
3
+ import { TARGET } from "../../constants/target.js";
4
+ import BuilderContext from "../../context/builder.context";
5
+ import { getProcessedBlock } from "../../functions/get-processed-block.js";
6
+ import RenderInlinedStyles from "../render-inlined-styles.jsx";
3
7
 
4
8
  function BlockStyles(props) {
5
9
  const state = createMutable({
10
+ get useBlock() {
11
+ return getProcessedBlock({
12
+ block: props.block,
13
+ state: builderContext.state,
14
+ context: builderContext.context
15
+ });
16
+ },
17
+
6
18
  camelToKebabCase(string) {
7
19
  return string.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
8
20
  },
9
21
 
10
22
  get css() {
11
23
  // TODO: media queries
12
- const styleObject = props.block.responsiveStyles?.large;
24
+ const styleObject = state.useBlock.responsiveStyles?.large;
13
25
 
14
26
  if (!styleObject) {
15
27
  return "";
16
28
  }
17
29
 
18
- let str = `.${props.block.id} {`;
30
+ let str = `.${state.useBlock.id} {`;
19
31
 
20
32
  for (const key in styleObject) {
21
33
  const value = styleObject[key];
@@ -30,7 +42,10 @@ function BlockStyles(props) {
30
42
  }
31
43
 
32
44
  });
33
- return <RenderInlinedStyles styles={state.css}></RenderInlinedStyles>;
45
+ const builderContext = useContext(BuilderContext);
46
+ return <Show when={TARGET === "vue" || TARGET === "svelte"}>
47
+ <RenderInlinedStyles styles={state.css}></RenderInlinedStyles>
48
+ </Show>;
34
49
  }
35
50
 
36
51
  export default BlockStyles;
@@ -1,7 +1,6 @@
1
1
  import { useContext, Show, For } from "solid-js";
2
2
  import { Dynamic } from "solid-js/web";
3
3
  import { createMutable } from "solid-js/store";
4
- import { TARGET } from "../../constants/target.js";
5
4
  import BuilderContext from "../../context/builder.context";
6
5
  import { getBlockActions } from "../../functions/get-block-actions.js";
7
6
  import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
@@ -9,8 +8,9 @@ import { getBlockProperties } from "../../functions/get-block-properties.js";
9
8
  import { getBlockStyles } from "../../functions/get-block-styles.js";
10
9
  import { getBlockTag } from "../../functions/get-block-tag.js";
11
10
  import { getProcessedBlock } from "../../functions/get-processed-block.js";
12
- import BlockStyles from "./block-styles";
11
+ import BlockStyles from "./block-styles.jsx";
13
12
  import { isEmptyHtmlElement } from "./render-block.helpers.js";
13
+ import RenderComponent from "./render-component.jsx";
14
14
 
15
15
  function RenderBlock(props) {
16
16
  const state = createMutable({
@@ -62,22 +62,32 @@ function RenderBlock(props) {
62
62
  });
63
63
  },
64
64
 
65
- get propertiesAndActions() {
65
+ get attributes() {
66
66
  return { ...getBlockProperties(state.useBlock),
67
67
  ...getBlockActions({
68
68
  block: state.useBlock,
69
69
  state: builderContext.state,
70
70
  context: builderContext.context
71
- })
71
+ }),
72
+ style: getBlockStyles(state.useBlock)
72
73
  };
73
74
  },
74
75
 
75
- get css() {
76
- return getBlockStyles(state.useBlock);
76
+ get shouldWrap() {
77
+ return !state.componentInfo?.noWrap;
77
78
  },
78
79
 
79
80
  get componentOptions() {
80
- return getBlockComponentOptions(state.useBlock);
81
+ return { ...getBlockComponentOptions(state.useBlock),
82
+
83
+ /**
84
+ * These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
85
+ * they are provided to the component itself directly.
86
+ */
87
+ ...(state.shouldWrap ? {} : {
88
+ attributes: state.attributes
89
+ })
90
+ };
81
91
  },
82
92
 
83
93
  get children() {
@@ -89,41 +99,31 @@ function RenderBlock(props) {
89
99
  },
90
100
 
91
101
  get noCompRefChildren() {
102
+ /**
103
+ * When there is no `componentRef`, there might still be children that need to be rendered. In this case,
104
+ * we render them outside of `componentRef`
105
+ */
92
106
  return state.componentRef ? [] : state.children;
93
107
  }
94
108
 
95
109
  });
96
110
  const builderContext = useContext(BuilderContext);
97
- return <Show fallback={<Dynamic {...state.componentOptions} attributes={state.propertiesAndActions} builderBlock={state.useBlock} style={state.css} component={state.componentRef}>
98
- <For each={state.children}>
111
+ return <Show fallback={<RenderComponent blockChildren={state.children} componentRef={state.componentRef} componentOptions={state.componentOptions}></RenderComponent>} when={state.shouldWrap}>
112
+ <Show fallback={<Dynamic {...state.attributes} component={state.tagName}></Dynamic>} when={!isEmptyHtmlElement(state.tagName)}>
113
+ <Dynamic {...state.attributes} component={state.tagName}>
114
+ <RenderComponent blockChildren={state.children} componentRef={state.componentRef} componentOptions={state.componentOptions}></RenderComponent>
115
+ <For each={state.noCompRefChildren}>
99
116
  {(child, _index) => {
100
- const index = _index();
117
+ const index = _index();
101
118
 
102
- return <RenderBlock key={child.id} block={child}></RenderBlock>;
103
- }}
119
+ return <RenderBlock key={"render-block-" + child.id} block={child}></RenderBlock>;
120
+ }}
104
121
  </For>
105
- </Dynamic>} when={!state.componentInfo?.noWrap}>
106
- <Show fallback={<Dynamic {...state.propertiesAndActions} style={state.css} component={state.tagName}></Dynamic>} when={!isEmptyHtmlElement(state.tagName)}>
107
- <Dynamic {...state.propertiesAndActions} style={state.css} component={state.tagName}>
108
- <Show when={TARGET === "vue" || TARGET === "svelte"}>
109
- <BlockStyles block={state.useBlock}></BlockStyles>
110
- </Show>
111
- <Show when={state.componentRef}>
112
- <Dynamic {...state.componentOptions} builderBlock={state.useBlock} component={state.componentRef}>
113
- <For each={state.children}>
114
- {(child, _index) => {
115
- const index = _index();
116
-
117
- return <RenderBlock key={child.id} block={child}></RenderBlock>;
118
- }}
119
- </For>
120
- </Dynamic>
121
- </Show>
122
122
  <For each={state.noCompRefChildren}>
123
123
  {(child, _index) => {
124
124
  const index = _index();
125
125
 
126
- return <RenderBlock key={child.id} block={child}></RenderBlock>;
126
+ return <BlockStyles key={"block-style-" + child.id} block={child}></BlockStyles>;
127
127
  }}
128
128
  </For>
129
129
  </Dynamic>
@@ -0,0 +1,27 @@
1
+ import { Show, For } from "solid-js";
2
+ import { Dynamic } from "solid-js/web";
3
+ import BlockStyles from "./block-styles.jsx";
4
+ import RenderBlock from "./render-block.jsx";
5
+
6
+ function RenderComponent(props) {
7
+ return <Show when={props.componentRef}>
8
+ <Dynamic {...props.componentOptions} component={props.componentRef}>
9
+ <For each={props.blockChildren}>
10
+ {(child, _index) => {
11
+ const index = _index();
12
+
13
+ return <RenderBlock key={"render-block-" + child.id} block={child}></RenderBlock>;
14
+ }}
15
+ </For>
16
+ <For each={props.blockChildren}>
17
+ {(child, _index) => {
18
+ const index = _index();
19
+
20
+ return <BlockStyles key={"block-style-" + child.id} block={child}></BlockStyles>;
21
+ }}
22
+ </For>
23
+ </Dynamic>
24
+ </Show>;
25
+ }
26
+
27
+ export default RenderComponent;
@@ -2,7 +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 RenderBlock from "./render-block/render-block";
5
+ import BlockStyles from "./render-block/block-styles.jsx";
6
+ import RenderBlock from "./render-block/render-block.jsx";
6
7
 
7
8
  function RenderBlocks(props) {
8
9
  const state = createMutable({
@@ -47,7 +48,16 @@ function RenderBlocks(props) {
47
48
  {(block, _index) => {
48
49
  const index = _index();
49
50
 
50
- return <RenderBlock key={block.id} block={block}></RenderBlock>;
51
+ return <RenderBlock key={"render-block-" + block.id} block={block}></RenderBlock>;
52
+ }}
53
+ </For>
54
+ </Show>
55
+ <Show when={props.blocks}>
56
+ <For each={props.blocks}>
57
+ {(block, _index) => {
58
+ const index = _index();
59
+
60
+ return <BlockStyles key={"block-style-" + block.id} block={block}></BlockStyles>;
51
61
  }}
52
62
  </For>
53
63
  </Show>
@@ -1,5 +1,5 @@
1
1
  import { createMutable } from "solid-js/store";
2
- import RenderInlinedStyles from "../../render-inlined-styles";
2
+ import RenderInlinedStyles from "../../render-inlined-styles.jsx";
3
3
 
4
4
  function RenderContentStyles(props) {
5
5
  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,4 +1,6 @@
1
1
  var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
2
4
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
4
6
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
@@ -14,9 +16,12 @@ var __spreadValues = (a, b) => {
14
16
  }
15
17
  return a;
16
18
  };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
17
20
  function getBlockComponentOptions(block) {
18
21
  var _a;
19
- return __spreadValues(__spreadValues({}, (_a = block.component) == null ? void 0 : _a.options), block.options);
22
+ return __spreadProps(__spreadValues(__spreadValues({}, (_a = block.component) == null ? void 0 : _a.options), block.options), {
23
+ builderBlock: block
24
+ });
20
25
  }
21
26
  export {
22
27
  getBlockComponentOptions
@@ -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;