@builder.io/sdk-solid 0.0.8-12 → 0.0.8-15

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/package.json +1 -1
  2. package/src/blocks/image/image.jsx +1 -3
  3. package/src/components/render-block/block-styles.jsx +18 -25
  4. package/src/components/render-block/render-block.jsx +81 -10
  5. package/src/components/render-block/render-repeated-block.jsx +32 -0
  6. package/src/components/render-content/render-content.jsx +5 -5
  7. package/src/constants/device-sizes.js +3 -21
  8. package/src/functions/camel-to-kebab-case.js +4 -0
  9. package/src/functions/convert-style-object.js +14 -0
  10. package/src/functions/get-block-styles.js +7 -15
  11. package/src/functions/get-processed-block.js +15 -8
  12. package/src/functions/get-processed-block.test.js +2 -1
  13. package/src/functions/sanitize-styles.js +5 -0
  14. package/src/helpers/css.js +12 -0
  15. package/src/blocks/button/button.lite.tsx +0 -23
  16. package/src/blocks/columns/columns.lite.tsx +0 -109
  17. package/src/blocks/custom-code/custom-code.lite.tsx +0 -68
  18. package/src/blocks/embed/embed.lite.tsx +0 -60
  19. package/src/blocks/form/form.lite.tsx +0 -296
  20. package/src/blocks/fragment/fragment.lite.tsx +0 -5
  21. package/src/blocks/image/image.lite.tsx +0 -86
  22. package/src/blocks/img/img.lite.tsx +0 -18
  23. package/src/blocks/input/input.lite.tsx +0 -20
  24. package/src/blocks/raw-text/raw-text.lite.tsx +0 -10
  25. package/src/blocks/section/section.lite.tsx +0 -18
  26. package/src/blocks/select/select.lite.tsx +0 -28
  27. package/src/blocks/submit-button/submit-button.lite.tsx +0 -9
  28. package/src/blocks/symbol/symbol.lite.tsx +0 -41
  29. package/src/blocks/text/text.lite.tsx +0 -5
  30. package/src/blocks/textarea/textarea.lite.tsx +0 -13
  31. package/src/blocks/video/video.lite.tsx +0 -26
  32. package/src/components/error-boundary.jsx +0 -5
  33. package/src/components/error-boundary.lite.tsx +0 -5
  34. package/src/components/render-block/block-styles.lite.tsx +0 -56
  35. package/src/components/render-block/render-block.lite.tsx +0 -156
  36. package/src/components/render-block/render-component.lite.tsx +0 -38
  37. package/src/components/render-blocks.lite.tsx +0 -94
  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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-solid",
3
- "version": "0.0.8-12",
3
+ "version": "0.0.8-15",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./src/solid-index.jsx",
@@ -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}
@@ -4,6 +4,8 @@ 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
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({
@@ -11,39 +13,30 @@ function BlockStyles(props) {
11
13
  return getProcessedBlock({
12
14
  block: props.block,
13
15
  state: builderContext.state,
14
- context: builderContext.context
16
+ context: builderContext.context,
17
+ evaluateBindings: true
15
18
  });
16
19
  },
17
20
 
18
- camelToKebabCase(string) {
19
- return string.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
20
- },
21
-
22
21
  get css() {
23
- // TODO: media queries
24
- const styleObject = state.useBlock.responsiveStyles?.large;
25
-
26
- if (!styleObject) {
27
- return "";
28
- }
29
-
30
- let str = `.${state.useBlock.id} {`;
31
-
32
- for (const key in styleObject) {
33
- const value = styleObject[key];
34
-
35
- if (typeof value === "string") {
36
- str += `${state.camelToKebabCase(key)}: ${value};`;
37
- }
38
- }
39
-
40
- str += "}";
41
- return str;
22
+ const styles = state.useBlock.responsiveStyles;
23
+ const largeStyles = styles?.large;
24
+ const mediumStyles = styles?.medium;
25
+ const smallStyles = styles?.small;
26
+ return `
27
+ ${largeStyles ? `.${state.useBlock.id} {${convertStyleMaptoCSS(largeStyles)}}` : ""}
28
+ ${mediumStyles ? `${getMaxWidthQueryForSize("medium")} {
29
+ .${state.useBlock.id} {${convertStyleMaptoCSS(mediumStyles)}}
30
+ }` : ""}
31
+ ${smallStyles ? `${getMaxWidthQueryForSize("small")} {
32
+ .${state.useBlock.id} {${convertStyleMaptoCSS(smallStyles)}}
33
+ }` : ""}
34
+ }`;
42
35
  }
43
36
 
44
37
  });
45
38
  const builderContext = useContext(BuilderContext);
46
- return <Show when={TARGET === "vue" || TARGET === "svelte"}>
39
+ return <Show when={TARGET === "vue2" || TARGET === "vue3" || TARGET === "svelte"}>
47
40
  <RenderInlinedStyles styles={state.css}></RenderInlinedStyles>
48
41
  </Show>;
49
42
  }
@@ -8,14 +8,21 @@ 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 { evaluate } from "../../functions/evaluate.js";
11
12
  import BlockStyles from "./block-styles.jsx";
12
13
  import { isEmptyHtmlElement } from "./render-block.helpers.js";
13
14
  import RenderComponent from "./render-component.jsx";
15
+ import RenderRepeatedBlock from "./render-repeated-block.jsx";
14
16
 
15
17
  function RenderBlock(props) {
16
18
  const state = createMutable({
17
19
  get component() {
18
- const componentName = state.useBlock.component?.name;
20
+ const componentName = getProcessedBlock({
21
+ block: props.block,
22
+ state: builderContext.state,
23
+ context: builderContext.context,
24
+ evaluateBindings: false
25
+ }).component?.name;
19
26
 
20
27
  if (!componentName) {
21
28
  return null;
@@ -55,10 +62,11 @@ function RenderBlock(props) {
55
62
  },
56
63
 
57
64
  get useBlock() {
58
- return getProcessedBlock({
65
+ return state.repeatItemData ? props.block : getProcessedBlock({
59
66
  block: props.block,
60
67
  state: builderContext.state,
61
- context: builderContext.context
68
+ context: builderContext.context,
69
+ evaluateBindings: true
62
70
  });
63
71
  },
64
72
 
@@ -90,6 +98,14 @@ function RenderBlock(props) {
90
98
  };
91
99
  },
92
100
 
101
+ get renderComponentProps() {
102
+ return {
103
+ blockChildren: state.children,
104
+ componentRef: state.componentRef,
105
+ componentOptions: state.componentOptions
106
+ };
107
+ },
108
+
93
109
  get children() {
94
110
  // TO-DO: When should `canHaveChildren` dictate rendering?
95
111
  // This is currently commented out because some Builder components (e.g. Box) do not have `canHaveChildren: true`,
@@ -98,28 +114,83 @@ function RenderBlock(props) {
98
114
  return state.useBlock.children ?? [];
99
115
  },
100
116
 
101
- get noCompRefChildren() {
117
+ get childrenWithoutParentComponent() {
102
118
  /**
103
119
  * 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`
120
+ * we render them outside of `componentRef`.
121
+ * NOTE: We make sure not to render this if `repeatItemData` is non-null, because that means we are rendering an array of
122
+ * blocks, and the children will be repeated within those blocks.
105
123
  */
106
- return state.componentRef ? [] : state.children;
124
+ const shouldRenderChildrenOutsideRef = !state.componentRef && !state.repeatItemData;
125
+ return shouldRenderChildrenOutsideRef ? state.children : [];
126
+ },
127
+
128
+ get repeatItemData() {
129
+ /**
130
+ * we don't use `state.useBlock` here because the processing done within its logic includes evaluating the block's bindings,
131
+ * which will not work if there is a repeat.
132
+ */
133
+ const {
134
+ repeat,
135
+ ...blockWithoutRepeat
136
+ } = props.block;
137
+
138
+ if (!repeat?.collection) {
139
+ return undefined;
140
+ }
141
+
142
+ const {
143
+ collection,
144
+ itemName
145
+ } = repeat;
146
+ const itemsArray = evaluate({
147
+ code: collection,
148
+ state: builderContext.state,
149
+ context: builderContext.context
150
+ });
151
+
152
+ if (Array.isArray(itemsArray)) {
153
+ const collectionName = collection.split(".").pop();
154
+ const itemNameToUse = itemName || (collectionName ? collectionName + "Item" : "item");
155
+ const repeatArray = itemsArray.map((item, index) => ({
156
+ context: { ...builderContext,
157
+ state: { ...builderContext.state,
158
+ $index: index,
159
+ $item: item,
160
+ [itemNameToUse]: item,
161
+ [`$${itemNameToUse}Index`]: index
162
+ }
163
+ },
164
+ block: blockWithoutRepeat
165
+ }));
166
+ return repeatArray;
167
+ } else {
168
+ return undefined;
169
+ }
107
170
  }
108
171
 
109
172
  });
110
173
  const builderContext = useContext(BuilderContext);
111
- return <Show fallback={<RenderComponent blockChildren={state.children} componentRef={state.componentRef} componentOptions={state.componentOptions}></RenderComponent>} when={state.shouldWrap}>
174
+ return <Show fallback={<RenderComponent {...state.renderComponentProps}></RenderComponent>} when={state.shouldWrap}>
112
175
  <Show fallback={<Dynamic {...state.attributes} component={state.tagName}></Dynamic>} when={!isEmptyHtmlElement(state.tagName)}>
113
176
  <Dynamic {...state.attributes} component={state.tagName}>
114
- <RenderComponent blockChildren={state.children} componentRef={state.componentRef} componentOptions={state.componentOptions}></RenderComponent>
115
- <For each={state.noCompRefChildren}>
177
+ <Show fallback={<RenderComponent {...state.renderComponentProps}></RenderComponent>} when={state.repeatItemData}>
178
+ <For each={state.repeatItemData}>
179
+ {(data, _index) => {
180
+ const index = _index();
181
+
182
+ return <RenderRepeatedBlock key={index} repeatContext={data.context} block={data.block}></RenderRepeatedBlock>;
183
+ }}
184
+ </For>
185
+ </Show>
186
+ <For each={state.childrenWithoutParentComponent}>
116
187
  {(child, _index) => {
117
188
  const index = _index();
118
189
 
119
190
  return <RenderBlock key={"render-block-" + child.id} block={child}></RenderBlock>;
120
191
  }}
121
192
  </For>
122
- <For each={state.noCompRefChildren}>
193
+ <For each={state.childrenWithoutParentComponent}>
123
194
  {(child, _index) => {
124
195
  const index = _index();
125
196
 
@@ -0,0 +1,32 @@
1
+ import { Dynamic } from "solid-js/web";
2
+ import BuilderContext from "../../context/builder.context";
3
+ import RenderBlock from "./render-block.jsx";
4
+
5
+ function RenderRepeatedBlock(props) {
6
+ return <Dynamic value={{
7
+ get content() {
8
+ return props.repeatContext.content;
9
+ },
10
+
11
+ get state() {
12
+ return props.repeatContext.state;
13
+ },
14
+
15
+ get context() {
16
+ return props.repeatContext.context;
17
+ },
18
+
19
+ get apiKey() {
20
+ return props.repeatContext.apiKey;
21
+ },
22
+
23
+ get registeredComponents() {
24
+ return props.repeatContext.registeredComponents;
25
+ }
26
+
27
+ }} component={BuilderContext.Provider}>
28
+ <RenderBlock block={props.block}></RenderBlock>
29
+ </Dynamic>;
30
+ }
31
+
32
+ export default RenderRepeatedBlock;
@@ -41,8 +41,8 @@ function RenderContent(props) {
41
41
  };
42
42
  },
43
43
 
44
- get context() {
45
- return {};
44
+ get contextContext() {
45
+ return props.context || {};
46
46
  },
47
47
 
48
48
  get allRegisteredComponents() {
@@ -94,7 +94,7 @@ function RenderContent(props) {
94
94
  if (jsCode) {
95
95
  evaluate({
96
96
  code: jsCode,
97
- context: state.context,
97
+ context: state.contextContext,
98
98
  state: state.contentState
99
99
  });
100
100
  }
@@ -107,7 +107,7 @@ function RenderContent(props) {
107
107
  evalExpression(expression) {
108
108
  return expression.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({
109
109
  code: group,
110
- context: state.context,
110
+ context: state.contextContext,
111
111
  state: state.contentState
112
112
  }));
113
113
  },
@@ -208,7 +208,7 @@ function RenderContent(props) {
208
208
  },
209
209
 
210
210
  get context() {
211
- return state.context;
211
+ return state.contextContext;
212
212
  },
213
213
 
214
214
  get apiKey() {
@@ -1,10 +1,4 @@
1
- const sizeNames = ["xsmall", "small", "medium", "large"];
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
- sizeNames,
38
- sizes
20
+ getMaxWidthQueryForSize
39
21
  };
@@ -0,0 +1,4 @@
1
+ const camelToKebabCase = (string) => string.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
2
+ export {
3
+ camelToKebabCase
4
+ };
@@ -0,0 +1,14 @@
1
+ const camelCaseToDashCase = (str = "") => str.replace(/[A-Z]/g, (match) => "-" + match.toLowerCase());
2
+ const convertStyleObject = (obj) => {
3
+ if (!obj) {
4
+ return obj;
5
+ }
6
+ const newObj = {};
7
+ for (const key in obj) {
8
+ newObj[camelCaseToDashCase(key)] = obj[key];
9
+ }
10
+ return newObj;
11
+ };
12
+ export {
13
+ convertStyleObject
14
+ };
@@ -14,27 +14,19 @@ var __spreadValues = (a, b) => {
14
14
  }
15
15
  return a;
16
16
  };
17
- import { sizes } from "../constants/device-sizes";
18
- const camelCaseToDashCase = (str = "") => str.replace(/[A-Z]/g, (match) => "-" + match.toLowerCase());
19
- const convertStyleObject = (obj) => {
20
- if (!obj) {
21
- return obj;
22
- }
23
- const newObj = {};
24
- for (const key in obj) {
25
- newObj[camelCaseToDashCase(key)] = obj[key];
26
- }
27
- return newObj;
28
- };
17
+ import { getMaxWidthQueryForSize } from "../constants/device-sizes.js";
18
+ import { convertStyleObject } from "./convert-style-object.js";
19
+ import { sanitizeBlockStyles } from "./sanitize-styles.js";
29
20
  function getBlockStyles(block) {
30
21
  var _a, _b, _c, _d, _e;
31
- const styles = __spreadValues({}, convertStyleObject((_a = block.responsiveStyles) == null ? void 0 : _a.large));
22
+ const styles = __spreadValues(__spreadValues({}, convertStyleObject((_a = block.responsiveStyles) == null ? void 0 : _a.large)), block.styles);
32
23
  if ((_b = block.responsiveStyles) == null ? void 0 : _b.medium) {
33
- styles[`@media (max-width: ${sizes.medium.max})`] = convertStyleObject((_c = block.responsiveStyles) == null ? void 0 : _c.medium);
24
+ styles[getMaxWidthQueryForSize("medium")] = convertStyleObject((_c = block.responsiveStyles) == null ? void 0 : _c.medium);
34
25
  }
35
26
  if ((_d = block.responsiveStyles) == null ? void 0 : _d.small) {
36
- styles[`@media (max-width: ${sizes.small.max})`] = convertStyleObject((_e = block.responsiveStyles) == null ? void 0 : _e.small);
27
+ styles[getMaxWidthQueryForSize("small")] = convertStyleObject((_e = block.responsiveStyles) == null ? void 0 : _e.small);
37
28
  }
29
+ sanitizeBlockStyles(styles);
38
30
  return styles;
39
31
  }
40
32
  export {
@@ -20,9 +20,11 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
20
  import { evaluate } from "./evaluate.js";
21
21
  import { set } from "./set.js";
22
22
  import { transformBlock } from "./transform-block.js";
23
- function getProcessedBlock(options) {
24
- const { state, context } = options;
25
- const block = transformBlock(options.block);
23
+ const evaluateBindings = ({
24
+ block,
25
+ context,
26
+ state
27
+ }) => {
26
28
  if (!block.bindings) {
27
29
  return block;
28
30
  }
@@ -32,14 +34,19 @@ function getProcessedBlock(options) {
32
34
  });
33
35
  for (const binding in block.bindings) {
34
36
  const expression = block.bindings[binding];
35
- const value = evaluate({
36
- code: expression,
37
- state,
38
- context
39
- });
37
+ const value = evaluate({ code: expression, state, context });
40
38
  set(copied, binding, value);
41
39
  }
42
40
  return copied;
41
+ };
42
+ function getProcessedBlock(options) {
43
+ const { state, context } = options;
44
+ const block = transformBlock(options.block);
45
+ if (evaluateBindings) {
46
+ return evaluateBindings({ block, state, context });
47
+ } else {
48
+ return block;
49
+ }
43
50
  }
44
51
  export {
45
52
  getProcessedBlock
@@ -20,7 +20,8 @@ test("Can process bindings", () => {
20
20
  const processed = getProcessedBlock({
21
21
  block,
22
22
  context: {},
23
- state: { test: "hello" }
23
+ state: { test: "hello" },
24
+ evaluateBindings: true
24
25
  });
25
26
  expect(processed).not.toEqual(block);
26
27
  expect((_a = processed.properties) == null ? void 0 : _a.foo).toEqual("baz");
@@ -0,0 +1,5 @@
1
+ const sanitizeBlockStyles = (_styles) => {
2
+ };
3
+ export {
4
+ sanitizeBlockStyles
5
+ };
@@ -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
+ };
@@ -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.jsx";
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: JSX.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,68 +0,0 @@
1
- import { onMount, useRef } 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
- 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 (
28
- !script.type ||
29
- [
30
- "text/javascript",
31
- "application/javascript",
32
- "application/ecmascript",
33
- ].includes(script.type)
34
- ) {
35
- if (state.scriptsRun.includes(script.innerText)) {
36
- continue;
37
- }
38
-
39
- try {
40
- state.scriptsRun.push(script.innerText);
41
- new Function(script.innerText)();
42
- } catch (error) {
43
- console.warn("`CustomCode`: Error running script:", error);
44
- }
45
- }
46
- }
47
- }
48
- },
49
- });
50
-
51
- const elem = useRef();
52
-
53
- onMount(() => {
54
- state.findAndRunScripts();
55
- });
56
-
57
- return (
58
- <div
59
- class={
60
- "builder-custom-code" + (props.replaceNodes ? " replace-nodes" : "")
61
- }
62
- ref={elem}
63
- innerHTML={props.code}
64
- ></div>
65
- );
66
- }
67
-
68
- export default CustomCode;