@builder.io/sdk-react-native 0.0.1-55 โ†’ 0.0.1-58

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 (35) hide show
  1. package/CHANGELOG.md +10 -1
  2. package/README.md +4 -0
  3. package/package.json +1 -1
  4. package/src/blocks/custom-code/custom-code.js +1 -1
  5. package/src/blocks/embed/embed.js +1 -1
  6. package/src/blocks/form/form.js +1 -1
  7. package/src/components/render-block/block-styles.js +16 -4
  8. package/src/components/render-block/render-block.js +26 -29
  9. package/src/components/render-block/render-component.js +33 -0
  10. package/src/components/render-blocks.js +10 -6
  11. package/src/functions/get-block-component-options.js +6 -1
  12. package/src/blocks/button/button.lite.tsx +0 -25
  13. package/src/blocks/columns/columns.lite.tsx +0 -70
  14. package/src/blocks/custom-code/custom-code.lite.tsx +0 -59
  15. package/src/blocks/embed/embed.lite.tsx +0 -61
  16. package/src/blocks/form/form.lite.tsx +0 -254
  17. package/src/blocks/fragment/fragment.lite.tsx +0 -10
  18. package/src/blocks/image/image.lite.tsx +0 -67
  19. package/src/blocks/img/img.lite.tsx +0 -18
  20. package/src/blocks/input/input.lite.tsx +0 -20
  21. package/src/blocks/raw-text/raw-text.lite.tsx +0 -6
  22. package/src/blocks/section/section.lite.tsx +0 -19
  23. package/src/blocks/select/select.lite.tsx +0 -23
  24. package/src/blocks/submit-button/submit-button.lite.tsx +0 -10
  25. package/src/blocks/symbol/symbol.lite.tsx +0 -60
  26. package/src/blocks/text/text.lite.tsx +0 -6
  27. package/src/blocks/textarea/textarea.lite.tsx +0 -14
  28. package/src/blocks/video/video.lite.tsx +0 -27
  29. package/src/components/error-boundary.lite.tsx +0 -6
  30. package/src/components/render-block/block-styles.lite.tsx +0 -35
  31. package/src/components/render-block/render-block.lite.tsx +0 -144
  32. package/src/components/render-blocks.lite.tsx +0 -65
  33. package/src/components/render-content/components/render-styles.lite.tsx +0 -70
  34. package/src/components/render-content/render-content.lite.tsx +0 -283
  35. package/src/components/render-inlined-styles.lite.tsx +0 -31
package/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ### 0.0.1-56
2
+
3
+ ๐Ÿ› Fix: image block `srcSet` was incorrectly set as `srcset`
4
+
5
+ ### 0.0.1-55
6
+
7
+ ๐Ÿ› Fix: custom components were not rendering correctly
8
+ ๐Ÿ› Fix: Image component's `srcSet` was not being set correctly
9
+
1
10
  ### 0.0.1-52
2
11
 
3
12
  ๐Ÿงจ Breaking change: the format of the `customComponents` prop has changed from `[{ component, info }]` to `[{ component, ...info }]`.
@@ -5,7 +14,7 @@ See [builder-registered-components.ts](/packages/sdks/src/constants/builder-regi
5
14
 
6
15
  ### 0.0.1-51
7
16
 
8
- โš ๏ธ Deprecation notice: Registering components via `registerComponent(component, info)` is now deprecated.
17
+ โš ๏ธ Deprecation notice: Registering components via `registerComponent(component, info)` is now deprecated.
9
18
  To register your custom components in Builder, you must now provide a `customComponents` array to the `RenderContent` component containing `[{ component, info }]`.
10
19
  See [builder-registered-components.ts](/packages/sdks/src/constants/builder-registered-components.ts) for examples of how to do so, or see the example provided for this SDK.
11
20
 
package/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  This is the React-Native SDK. It is currently in beta.
4
4
 
5
+ ## Mitosis
6
+
7
+ This SDK is generated by [Mitosis](https://github.com/BuilderIO/mitosis). To see the Mitosis source-code, go [here](../../).
8
+
5
9
  ## Feature Support
6
10
 
7
11
  To check the status of the SDK, look at [these tables](../../README.md#feature-implementation).
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-react-native",
3
3
  "description": "Builder.io SDK for React Native",
4
- "version": "0.0.1-55",
4
+ "version": "0.0.1-58",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
7
7
  "release:dev": "npm version prerelease --no-git-tag-version && npm publish --tag dev --access public"
@@ -2,6 +2,7 @@ import * as React from "react";
2
2
  import { View } from "react-native";
3
3
  import { useState, useRef, useEffect } from "react";
4
4
  function CustomCode(props) {
5
+ const elem = useRef(null);
5
6
  const [scriptsInserted, setScriptsInserted] = useState(() => []);
6
7
  const [scriptsRun, setScriptsRun] = useState(() => []);
7
8
  function findAndRunScripts() {
@@ -36,7 +37,6 @@ function CustomCode(props) {
36
37
  }
37
38
  }
38
39
  }
39
- const elem = useRef();
40
40
  useEffect(() => {
41
41
  findAndRunScripts();
42
42
  }, []);
@@ -2,6 +2,7 @@ import * as React from "react";
2
2
  import { View } from "react-native";
3
3
  import { useState, useRef, useEffect } from "react";
4
4
  function Embed(props) {
5
+ const elem = useRef(null);
5
6
  const [scriptsInserted, setScriptsInserted] = useState(() => []);
6
7
  const [scriptsRun, setScriptsRun] = useState(() => []);
7
8
  function findAndRunScripts() {
@@ -36,7 +37,6 @@ function Embed(props) {
36
37
  }
37
38
  }
38
39
  }
39
- const elem = useRef();
40
40
  useEffect(() => {
41
41
  findAndRunScripts();
42
42
  }, []);
@@ -44,6 +44,7 @@ import RenderBlock from "../../components/render-block/render-block.js";
44
44
  import { isEditing } from "../../functions/is-editing.js";
45
45
  function FormComponent(props) {
46
46
  var _a, _b;
47
+ const formRef = useRef(null);
47
48
  const [formState, setFormState] = useState(() => "unsubmitted");
48
49
  const [responseData, setResponseData] = useState(() => null);
49
50
  const [formErrorMessage, setFormErrorMessage] = useState(() => "");
@@ -190,7 +191,6 @@ function FormComponent(props) {
190
191
  });
191
192
  }
192
193
  }
193
- const formRef = useRef();
194
194
  return /* @__PURE__ */ React.createElement(View, __spreadProps(__spreadValues({}, props.attributes), {
195
195
  validate: props.validate,
196
196
  ref: formRef,
@@ -1,16 +1,27 @@
1
1
  import * as React from "react";
2
+ import { useContext } from "react";
3
+ import { TARGET } from "../../constants/target.js";
4
+ import BuilderContext from "../../context/builder.context";
5
+ import { getProcessedBlock } from "../../functions/get-processed-block.js";
2
6
  import RenderInlinedStyles from "../render-inlined-styles.js";
3
7
  function BlockStyles(props) {
8
+ function useBlock() {
9
+ return getProcessedBlock({
10
+ block: props.block,
11
+ state: builderContext.state,
12
+ context: builderContext.context
13
+ });
14
+ }
4
15
  function camelToKebabCase(string) {
5
16
  return string.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
6
17
  }
7
18
  function css() {
8
19
  var _a;
9
- const styleObject = (_a = props.block.responsiveStyles) == null ? void 0 : _a.large;
20
+ const styleObject = (_a = useBlock().responsiveStyles) == null ? void 0 : _a.large;
10
21
  if (!styleObject) {
11
22
  return "";
12
23
  }
13
- let str = `.${props.block.id} {`;
24
+ let str = `.${useBlock().id} {`;
14
25
  for (const key in styleObject) {
15
26
  const value = styleObject[key];
16
27
  if (typeof value === "string") {
@@ -20,9 +31,10 @@ function BlockStyles(props) {
20
31
  str += "}";
21
32
  return str;
22
33
  }
23
- return /* @__PURE__ */ React.createElement(RenderInlinedStyles, {
34
+ const builderContext = useContext(BuilderContext);
35
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, TARGET === "vue" || TARGET === "svelte" ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(RenderInlinedStyles, {
24
36
  styles: css()
25
- });
37
+ })) : null);
26
38
  }
27
39
  export {
28
40
  BlockStyles as default
@@ -31,7 +31,6 @@ var __objRest = (source, exclude) => {
31
31
  };
32
32
  import * as React from "react";
33
33
  import { useContext } from "react";
34
- import { TARGET } from "../../constants/target.js";
35
34
  import BuilderContext from "../../context/builder.context";
36
35
  import { getBlockActions } from "../../functions/get-block-actions.js";
37
36
  import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
@@ -41,8 +40,9 @@ import { getBlockTag } from "../../functions/get-block-tag.js";
41
40
  import { getProcessedBlock } from "../../functions/get-processed-block.js";
42
41
  import BlockStyles from "./block-styles.js";
43
42
  import { isEmptyHtmlElement } from "./render-block.helpers.js";
43
+ import RenderComponent from "./render-component.js";
44
44
  function RenderBlock(props) {
45
- var _a, _b, _c, _d;
45
+ var _a, _b;
46
46
  function component() {
47
47
  var _a2;
48
48
  const componentName = (_a2 = useBlock().component) == null ? void 0 : _a2.name;
@@ -81,18 +81,23 @@ function RenderBlock(props) {
81
81
  context: builderContext.context
82
82
  });
83
83
  }
84
- function propertiesAndActions() {
85
- return __spreadValues(__spreadValues({}, getBlockProperties(useBlock())), getBlockActions({
84
+ function attributes() {
85
+ return __spreadProps(__spreadValues(__spreadValues({}, getBlockProperties(useBlock())), getBlockActions({
86
86
  block: useBlock(),
87
87
  state: builderContext.state,
88
88
  context: builderContext.context
89
- }));
89
+ })), {
90
+ style: getBlockStyles(useBlock())
91
+ });
90
92
  }
91
- function css() {
92
- return getBlockStyles(useBlock());
93
+ function shouldWrap() {
94
+ var _a2;
95
+ return !((_a2 = componentInfo == null ? void 0 : componentInfo()) == null ? void 0 : _a2.noWrap);
93
96
  }
94
97
  function componentOptions() {
95
- return getBlockComponentOptions(useBlock());
98
+ return __spreadValues(__spreadValues({}, getBlockComponentOptions(useBlock())), shouldWrap() ? {} : {
99
+ attributes: attributes()
100
+ });
96
101
  }
97
102
  function children() {
98
103
  var _a2;
@@ -102,30 +107,22 @@ function RenderBlock(props) {
102
107
  return componentRef() ? [] : children();
103
108
  }
104
109
  const builderContext = useContext(BuilderContext);
105
- const ComponentRefRef = componentRef();
106
110
  const TagNameRef = tagName();
107
- return /* @__PURE__ */ React.createElement(React.Fragment, null, !((_a = componentInfo == null ? void 0 : componentInfo()) == null ? void 0 : _a.noWrap) ? /* @__PURE__ */ React.createElement(React.Fragment, null, !isEmptyHtmlElement(tagName()) ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(TagNameRef, __spreadProps(__spreadValues({}, propertiesAndActions()), {
108
- style: css()
109
- }), TARGET === "vue" || TARGET === "svelte" ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(BlockStyles, {
110
- block: useBlock()
111
- })) : null, componentRef() ? /* @__PURE__ */ React.createElement(ComponentRefRef, __spreadProps(__spreadValues({}, componentOptions()), {
112
- builderBlock: useBlock()
113
- }), (_b = children()) == null ? void 0 : _b.map((child) => /* @__PURE__ */ React.createElement(RenderBlock, {
114
- key: child.id,
115
- block: child
116
- }))) : null, (_c = noCompRefChildren()) == null ? void 0 : _c.map((child) => /* @__PURE__ */ React.createElement(RenderBlock, {
117
- key: child.id,
111
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, shouldWrap() ? /* @__PURE__ */ React.createElement(React.Fragment, null, !isEmptyHtmlElement(tagName()) ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(TagNameRef, __spreadValues({}, attributes()), /* @__PURE__ */ React.createElement(RenderComponent, {
112
+ blockChildren: children(),
113
+ componentRef: componentRef(),
114
+ componentOptions: componentOptions()
115
+ }), (_a = noCompRefChildren()) == null ? void 0 : _a.map((child) => /* @__PURE__ */ React.createElement(RenderBlock, {
116
+ key: "render-block-" + child.id,
118
117
  block: child
119
- })))) : /* @__PURE__ */ React.createElement(TagNameRef, __spreadProps(__spreadValues({}, propertiesAndActions()), {
120
- style: css()
121
- }))) : /* @__PURE__ */ React.createElement(ComponentRefRef, __spreadProps(__spreadValues({}, componentOptions()), {
122
- attributes: propertiesAndActions(),
123
- builderBlock: useBlock(),
124
- style: css()
125
- }), (_d = children()) == null ? void 0 : _d.map((child) => /* @__PURE__ */ React.createElement(RenderBlock, {
126
- key: child.id,
118
+ })), (_b = noCompRefChildren()) == null ? void 0 : _b.map((child) => /* @__PURE__ */ React.createElement(BlockStyles, {
119
+ key: "block-style-" + child.id,
127
120
  block: child
128
- }))));
121
+ })))) : /* @__PURE__ */ React.createElement(TagNameRef, __spreadValues({}, attributes()))) : /* @__PURE__ */ React.createElement(RenderComponent, {
122
+ blockChildren: children(),
123
+ componentRef: componentRef(),
124
+ componentOptions: componentOptions()
125
+ }));
129
126
  }
130
127
  export {
131
128
  RenderBlock as default
@@ -0,0 +1,33 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+ import * as React from "react";
18
+ import BlockStyles from "./block-styles.js";
19
+ import RenderBlock from "./render-block.js";
20
+ function RenderComponent(props) {
21
+ var _a, _b;
22
+ const ComponentRefRef = props.componentRef;
23
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, props.componentRef ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(ComponentRefRef, __spreadValues({}, props.componentOptions), (_a = props.blockChildren) == null ? void 0 : _a.map((child) => /* @__PURE__ */ React.createElement(RenderBlock, {
24
+ key: "render-block-" + child.id,
25
+ block: child
26
+ })), (_b = props.blockChildren) == null ? void 0 : _b.map((child) => /* @__PURE__ */ React.createElement(BlockStyles, {
27
+ key: "block-style-" + child.id,
28
+ block: child
29
+ })))) : null);
30
+ }
31
+ export {
32
+ RenderComponent as default
33
+ };
@@ -1,17 +1,18 @@
1
1
  import * as React from "react";
2
2
  import { View, StyleSheet } from "react-native";
3
3
  import { isEditing } from "../functions/is-editing.js";
4
+ import BlockStyles from "./render-block/block-styles.js";
4
5
  import RenderBlock from "./render-block/render-block.js";
5
6
  function RenderBlocks(props) {
6
- var _a;
7
+ var _a, _b;
7
8
  function className() {
8
9
  var _a2;
9
10
  return "builder-blocks" + (!((_a2 = props.blocks) == null ? void 0 : _a2.length) ? " no-blocks" : "");
10
11
  }
11
12
  function onClick() {
12
- var _a2, _b;
13
+ var _a2, _b2;
13
14
  if (isEditing() && !((_a2 = props.blocks) == null ? void 0 : _a2.length)) {
14
- (_b = window.parent) == null ? void 0 : _b.postMessage({
15
+ (_b2 = window.parent) == null ? void 0 : _b2.postMessage({
15
16
  type: "builder.clickEmptyBlocks",
16
17
  data: {
17
18
  parentElementId: props.parent,
@@ -21,9 +22,9 @@ function RenderBlocks(props) {
21
22
  }
22
23
  }
23
24
  function onMouseEnter() {
24
- var _a2, _b;
25
+ var _a2, _b2;
25
26
  if (isEditing() && !((_a2 = props.blocks) == null ? void 0 : _a2.length)) {
26
- (_b = window.parent) == null ? void 0 : _b.postMessage({
27
+ (_b2 = window.parent) == null ? void 0 : _b2.postMessage({
27
28
  type: "builder.hoverEmptyBlocks",
28
29
  data: {
29
30
  parentElementId: props.parent,
@@ -42,7 +43,10 @@ function RenderBlocks(props) {
42
43
  onMouseEnter: (event) => onMouseEnter(),
43
44
  style: styles.view1
44
45
  }, props.blocks ? /* @__PURE__ */ React.createElement(React.Fragment, null, (_a = props.blocks) == null ? void 0 : _a.map((block) => /* @__PURE__ */ React.createElement(RenderBlock, {
45
- key: block.id,
46
+ key: "render-block-" + block.id,
47
+ block
48
+ }))) : null, props.blocks ? /* @__PURE__ */ React.createElement(React.Fragment, null, (_b = props.blocks) == null ? void 0 : _b.map((block) => /* @__PURE__ */ React.createElement(BlockStyles, {
49
+ key: "block-style-" + block.id,
46
50
  block
47
51
  }))) : null);
48
52
  }
@@ -1,5 +1,7 @@
1
1
  import * as React from 'react';
2
2
  var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
3
5
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
@@ -15,9 +17,12 @@ var __spreadValues = (a, b) => {
15
17
  }
16
18
  return a;
17
19
  };
20
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
18
21
  function getBlockComponentOptions(block) {
19
22
  var _a;
20
- return __spreadValues(__spreadValues({}, (_a = block.component) == null ? void 0 : _a.options), block.options);
23
+ return __spreadProps(__spreadValues(__spreadValues({}, (_a = block.component) == null ? void 0 : _a.options), block.options), {
24
+ builderBlock: block
25
+ });
21
26
  }
22
27
  export {
23
28
  getBlockComponentOptions
@@ -1,25 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
-
4
- export default function Button(props) {
5
- return (
6
- <>
7
- {props.link ? (
8
- <>
9
- <View
10
- {...props.attributes}
11
- role="button"
12
- href={props.link}
13
- target={props.openLinkInNewTab ? "_blank" : undefined}
14
- >
15
- <Text>{props.text}</Text>
16
- </View>
17
- </>
18
- ) : (
19
- <View {...props.attributes}>
20
- <Text>{props.text}</Text>
21
- </View>
22
- )}
23
- </>
24
- );
25
- }
@@ -1,70 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
- import RenderBlocks from "../../components/render-blocks.lite";
4
-
5
- export default function Columns(props) {
6
- function getGutterSize() {
7
- return typeof props.space === "number" ? props.space || 0 : 20;
8
- }
9
-
10
- function getColumns() {
11
- return props.columns || [];
12
- }
13
-
14
- function getWidth(index) {
15
- const columns = getColumns();
16
- return columns[index]?.width || 100 / columns.length;
17
- }
18
-
19
- function getColumnCssWidth(index) {
20
- const columns = getColumns();
21
- const gutterSize = getGutterSize();
22
- const subtractWidth = (gutterSize * (columns.length - 1)) / columns.length;
23
- return `calc(${getWidth(index)}% - ${subtractWidth}px)`;
24
- }
25
-
26
- function maybeApplyForTablet(prop) {
27
- const _stackColumnsAt = props.stackColumnsAt || "tablet";
28
-
29
- return _stackColumnsAt === "tablet" ? prop : "inherit";
30
- }
31
-
32
- function 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": maybeApplyForTablet(flexDir),
42
- };
43
- }
44
-
45
- function columnCssVars() {
46
- const width = "100%";
47
- const marginLeft = "0";
48
- return {
49
- "--column-width": width,
50
- "--column-margin-left": marginLeft,
51
- "--column-width-tablet": maybeApplyForTablet(width),
52
- "--column-margin-left-tablet": maybeApplyForTablet(marginLeft),
53
- };
54
- }
55
-
56
- return (
57
- <View style={styles.view1}>
58
- {props.columns?.map((column, index) => (
59
- <View style={styles.view2} key={index}>
60
- <RenderBlocks blocks={column.blocks} />
61
- </View>
62
- ))}
63
- </View>
64
- );
65
- }
66
-
67
- const styles = StyleSheet.create({
68
- view1: { display: "flex", alignItems: "stretch" },
69
- view2: { flexGrow: 1 },
70
- });
@@ -1,59 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
- import { useState, useRef, useEffect } from "react";
4
-
5
- export default function CustomCode(props) {
6
- const [scriptsInserted, setScriptsInserted] = useState(() => []);
7
-
8
- const [scriptsRun, setScriptsRun] = useState(() => []);
9
-
10
- function findAndRunScripts() {
11
- // TODO: Move this function to standalone one in '@builder.io/utils'
12
- if (elem.current && typeof window !== "undefined") {
13
- /** @type {HTMLScriptElement[]} */
14
- const scripts = elem.current.getElementsByTagName("script");
15
-
16
- for (let i = 0; i < scripts.length; i++) {
17
- const script = scripts[i];
18
-
19
- if (script.src) {
20
- if (scriptsInserted.includes(script.src)) {
21
- continue;
22
- }
23
-
24
- scriptsInserted.push(script.src);
25
- const newScript = document.createElement("script");
26
- newScript.async = true;
27
- newScript.src = script.src;
28
- document.head.appendChild(newScript);
29
- } else if (
30
- !script.type ||
31
- [
32
- "text/javascript",
33
- "application/javascript",
34
- "application/ecmascript",
35
- ].includes(script.type)
36
- ) {
37
- if (scriptsRun.includes(script.innerText)) {
38
- continue;
39
- }
40
-
41
- try {
42
- scriptsRun.push(script.innerText);
43
- new Function(script.innerText)();
44
- } catch (error) {
45
- console.warn("`CustomCode`: Error running script:", error);
46
- }
47
- }
48
- }
49
- }
50
- }
51
-
52
- const elem = useRef();
53
-
54
- useEffect(() => {
55
- findAndRunScripts();
56
- }, []);
57
-
58
- return <View ref={elem} dangerouslySetInnerHTML={{ __html: props.code }} />;
59
- }
@@ -1,61 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
- import { useState, useRef, useEffect } from "react";
4
-
5
- export default function Embed(props) {
6
- const [scriptsInserted, setScriptsInserted] = useState(() => []);
7
-
8
- const [scriptsRun, setScriptsRun] = useState(() => []);
9
-
10
- function findAndRunScripts() {
11
- // TODO: Move this function to standalone one in '@builder.io/utils'
12
- if (elem.current && typeof window !== "undefined") {
13
- /** @type {HTMLScriptElement[]} */
14
- const scripts = elem.current.getElementsByTagName("script");
15
-
16
- for (let i = 0; i < scripts.length; i++) {
17
- const script = scripts[i];
18
-
19
- if (script.src) {
20
- if (scriptsInserted.includes(script.src)) {
21
- continue;
22
- }
23
-
24
- scriptsInserted.push(script.src);
25
- const newScript = document.createElement("script");
26
- newScript.async = true;
27
- newScript.src = script.src;
28
- document.head.appendChild(newScript);
29
- } else if (
30
- !script.type ||
31
- [
32
- "text/javascript",
33
- "application/javascript",
34
- "application/ecmascript",
35
- ].includes(script.type)
36
- ) {
37
- if (scriptsRun.includes(script.innerText)) {
38
- continue;
39
- }
40
-
41
- try {
42
- scriptsRun.push(script.innerText);
43
- new Function(script.innerText)();
44
- } catch (error) {
45
- console.warn("`Embed`: Error running script:", error);
46
- }
47
- }
48
- }
49
- }
50
- }
51
-
52
- const elem = useRef();
53
-
54
- useEffect(() => {
55
- findAndRunScripts();
56
- }, []);
57
-
58
- return (
59
- <View ref={elem} dangerouslySetInnerHTML={{ __html: props.content }} />
60
- );
61
- }