@builder.io/sdk-react-native 0.0.1-50 → 0.0.1-51

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 (113) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/package.json +1 -1
  3. package/src/blocks/button/button.js +31 -0
  4. package/src/blocks/{button.lite.tsx → button/button.lite.tsx} +0 -0
  5. package/src/blocks/button/component-info.js +42 -0
  6. package/src/blocks/columns/columns.js +59 -0
  7. package/src/blocks/{columns.lite.tsx → columns/columns.lite.tsx} +5 -4
  8. package/src/blocks/columns/component-info.js +218 -0
  9. package/src/blocks/custom-code/component-info.js +32 -0
  10. package/src/blocks/custom-code/custom-code.js +50 -0
  11. package/src/blocks/{custom-code.lite.tsx → custom-code/custom-code.lite.tsx} +1 -1
  12. package/src/blocks/embed/component-info.js +25 -0
  13. package/src/blocks/embed/embed.js +50 -0
  14. package/src/blocks/{embed.lite.tsx → embed/embed.lite.tsx} +1 -1
  15. package/src/blocks/form/component-info.js +263 -0
  16. package/src/blocks/form/form.js +221 -0
  17. package/src/blocks/{form.lite.tsx → form/form.lite.tsx} +8 -7
  18. package/src/blocks/fragment/component-info.js +12 -0
  19. package/src/blocks/fragment/fragment.js +8 -0
  20. package/src/blocks/{fragment.lite.tsx → fragment/fragment.lite.tsx} +0 -0
  21. package/src/blocks/{image.js → image/component-info.js} +4 -42
  22. package/src/blocks/image/image.js +41 -0
  23. package/src/blocks/{image.lite.tsx → image/image.lite.tsx} +1 -1
  24. package/src/blocks/img/component-info.js +21 -0
  25. package/src/blocks/img/img.js +36 -0
  26. package/src/blocks/{img.lite.tsx → img/img.lite.tsx} +1 -1
  27. package/src/blocks/input/component-info.js +75 -0
  28. package/src/blocks/input/input.js +36 -0
  29. package/src/blocks/{input.lite.tsx → input/input.lite.tsx} +1 -1
  30. package/src/blocks/raw-text/component-info.js +17 -0
  31. package/src/blocks/raw-text/raw-text.js +10 -0
  32. package/src/blocks/{raw-text.lite.tsx → raw-text/raw-text.lite.tsx} +1 -1
  33. package/src/blocks/section/component-info.js +50 -0
  34. package/src/blocks/section/section.js +31 -0
  35. package/src/blocks/{section.lite.tsx → section/section.lite.tsx} +0 -0
  36. package/src/blocks/select/component-info.js +60 -0
  37. package/src/blocks/select/select.js +36 -0
  38. package/src/blocks/{select.lite.tsx → select/select.lite.tsx} +2 -2
  39. package/src/blocks/submit-button/component-info.js +29 -0
  40. package/src/blocks/submit-button/submit-button.js +29 -0
  41. package/src/blocks/{submit-button.lite.tsx → submit-button/submit-button.lite.tsx} +0 -0
  42. package/src/blocks/symbol/component-info.js +43 -0
  43. package/src/blocks/symbol/symbol.js +68 -0
  44. package/src/blocks/{symbol.lite.tsx → symbol/symbol.lite.tsx} +7 -7
  45. package/src/blocks/text/component-info.js +25 -0
  46. package/src/blocks/{text.js → text/text.js} +0 -22
  47. package/src/blocks/{text.lite.tsx → text/text.lite.tsx} +1 -1
  48. package/src/blocks/textarea/component-info.js +48 -0
  49. package/src/blocks/textarea/textarea.js +32 -0
  50. package/src/blocks/{textarea.lite.tsx → textarea/textarea.lite.tsx} +0 -0
  51. package/src/blocks/{video.js → video/component-info.js} +52 -40
  52. package/src/blocks/video/video.js +33 -0
  53. package/src/blocks/{video.lite.tsx → video/video.lite.tsx} +0 -0
  54. package/src/components/render-block/block-styles.js +29 -0
  55. package/src/components/render-block/block-styles.lite.tsx +35 -0
  56. package/src/components/render-block/render-block.helpers.js +24 -0
  57. package/src/components/{render-block.js → render-block/render-block.js} +28 -20
  58. package/src/components/{render-block.lite.tsx → render-block/render-block.lite.tsx} +43 -31
  59. package/src/components/render-blocks.js +3 -3
  60. package/src/components/render-blocks.lite.tsx +3 -3
  61. package/src/components/render-content/components/render-styles.js +58 -0
  62. package/src/components/render-content/components/render-styles.lite.tsx +70 -0
  63. package/src/components/render-content/index.js +5 -0
  64. package/src/components/{render-content.js → render-content/render-content.js} +57 -69
  65. package/src/components/{render-content.lite.tsx → render-content/render-content.lite.tsx} +67 -92
  66. package/src/components/render-inlined-styles.js +18 -0
  67. package/src/components/render-inlined-styles.lite.tsx +31 -0
  68. package/src/constants/builder-registered-components.js +27 -0
  69. package/src/constants/target.js +5 -0
  70. package/src/context/builder.context.js +2 -1
  71. package/src/functions/evaluate.js +2 -2
  72. package/src/functions/fast-clone.js +5 -0
  73. package/src/functions/get-block-actions.js +2 -2
  74. package/src/functions/get-block-properties.js +1 -1
  75. package/src/functions/get-builder-search-params/fn.test.js +1 -1
  76. package/src/functions/get-content/index.js +3 -2
  77. package/src/functions/get-fetch.js +29 -7
  78. package/src/functions/get-processed-block.js +3 -3
  79. package/src/functions/get-processed-block.test.js +1 -1
  80. package/src/functions/if-target.js +11 -2
  81. package/src/functions/is-editing.js +1 -1
  82. package/src/functions/is-iframe.js +1 -1
  83. package/src/functions/is-previewing.js +2 -2
  84. package/src/functions/on-change.test.js +1 -1
  85. package/src/functions/previewing-model-name.js +1 -1
  86. package/src/functions/register-component.js +13 -13
  87. package/src/functions/register.js +1 -1
  88. package/src/functions/set-editor-settings.js +1 -1
  89. package/src/functions/set.test.js +1 -1
  90. package/src/functions/track.js +4 -4
  91. package/src/index-helpers/blocks-exports.js +8 -8
  92. package/src/index.js +10 -13
  93. package/src/scripts/init-editing.js +72 -62
  94. package/src/types/components.js +1 -0
  95. package/src/types/element.js +1 -0
  96. package/src/types/targets.js +1 -0
  97. package/src/blocks/button.js +0 -36
  98. package/src/blocks/columns.js +0 -63
  99. package/src/blocks/custom-code.js +0 -55
  100. package/src/blocks/embed.js +0 -55
  101. package/src/blocks/form.js +0 -225
  102. package/src/blocks/fragment.js +0 -13
  103. package/src/blocks/img.js +0 -41
  104. package/src/blocks/input.js +0 -41
  105. package/src/blocks/raw-text.js +0 -15
  106. package/src/blocks/section.js +0 -36
  107. package/src/blocks/select.js +0 -41
  108. package/src/blocks/submit-button.js +0 -34
  109. package/src/blocks/symbol.js +0 -73
  110. package/src/blocks/textarea.js +0 -37
  111. package/src/components/block-styles.js +0 -7
  112. package/src/components/block-styles.lite.tsx +0 -6
  113. package/src/functions/get-target.js +0 -7
package/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ### 0.0.1-50
2
+
3
+ - feat: 🎸 export `isPreviewing()` (https://github.com/BuilderIO/builder/pull/951)
4
+ - feat: 🎸 Add support for Symbols (https://github.com/BuilderIO/builder/pull/951)
5
+ - feat: 🎸 Add support for Data Bindings https://github.com/BuilderIO/builder/pull/970
6
+
7
+ - BREAKING CHANGE: 🧨 RenderContent must now be provided the `apiKey` as a prop (https://github.com/BuilderIO/builder/pull/951)
8
+
1
9
  ### 0.0.1-49
2
10
 
3
11
  - Fix: show the "+ add block" button on empty pages https://github.com/BuilderIO/builder/pull/934
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-50",
4
+ "version": "0.0.1-51",
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"
@@ -0,0 +1,31 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ import * as React from "react";
21
+ import { View, Text } from "react-native";
22
+ function Button(props) {
23
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, props.link ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(View, __spreadProps(__spreadValues({}, props.attributes), {
24
+ role: "button",
25
+ href: props.link,
26
+ target: props.openLinkInNewTab ? "_blank" : void 0
27
+ }), /* @__PURE__ */ React.createElement(Text, null, props.text))) : /* @__PURE__ */ React.createElement(View, __spreadValues({}, props.attributes), /* @__PURE__ */ React.createElement(Text, null, props.text)));
28
+ }
29
+ export {
30
+ Button as default
31
+ };
@@ -0,0 +1,42 @@
1
+ import * as React from 'react';
2
+ const componentInfo = {
3
+ name: "Core:Button",
4
+ builtIn: true,
5
+ image: "https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2F81a15681c3e74df09677dfc57a615b13",
6
+ defaultStyles: {
7
+ appearance: "none",
8
+ paddingTop: "15px",
9
+ paddingBottom: "15px",
10
+ paddingLeft: "25px",
11
+ paddingRight: "25px",
12
+ backgroundColor: "#000000",
13
+ color: "white",
14
+ borderRadius: "4px",
15
+ textAlign: "center",
16
+ cursor: "pointer"
17
+ },
18
+ inputs: [
19
+ {
20
+ name: "text",
21
+ type: "text",
22
+ defaultValue: "Click me!",
23
+ bubble: true
24
+ },
25
+ {
26
+ name: "link",
27
+ type: "url",
28
+ bubble: true
29
+ },
30
+ {
31
+ name: "openLinkInNewTab",
32
+ type: "boolean",
33
+ defaultValue: false,
34
+ friendlyName: "Open link in new tab"
35
+ }
36
+ ],
37
+ static: true,
38
+ noWrap: true
39
+ };
40
+ export {
41
+ componentInfo
42
+ };
@@ -0,0 +1,59 @@
1
+ import * as React from "react";
2
+ import { View, StyleSheet } from "react-native";
3
+ import RenderBlocks from "../../components/render-blocks.js";
4
+ function Columns(props) {
5
+ var _a;
6
+ function getGutterSize() {
7
+ return typeof props.space === "number" ? props.space || 0 : 20;
8
+ }
9
+ function getColumns() {
10
+ return props.columns || [];
11
+ }
12
+ function getWidth(index) {
13
+ var _a2;
14
+ const columns = getColumns();
15
+ return ((_a2 = columns[index]) == null ? void 0 : _a2.width) || 100 / columns.length;
16
+ }
17
+ function getColumnCssWidth(index) {
18
+ const columns = getColumns();
19
+ const gutterSize = getGutterSize();
20
+ const subtractWidth = gutterSize * (columns.length - 1) / columns.length;
21
+ return `calc(${getWidth(index)}% - ${subtractWidth}px)`;
22
+ }
23
+ function maybeApplyForTablet(prop) {
24
+ const _stackColumnsAt = props.stackColumnsAt || "tablet";
25
+ return _stackColumnsAt === "tablet" ? prop : "inherit";
26
+ }
27
+ function columnsCssVars() {
28
+ const flexDir = props.stackColumnsAt === "never" ? "inherit" : props.reverseColumnsWhenStacked ? "column-reverse" : "column";
29
+ return {
30
+ "--flex-dir": flexDir,
31
+ "--flex-dir-tablet": maybeApplyForTablet(flexDir)
32
+ };
33
+ }
34
+ function columnCssVars() {
35
+ const width = "100%";
36
+ const marginLeft = "0";
37
+ return {
38
+ "--column-width": width,
39
+ "--column-margin-left": marginLeft,
40
+ "--column-width-tablet": maybeApplyForTablet(width),
41
+ "--column-margin-left-tablet": maybeApplyForTablet(marginLeft)
42
+ };
43
+ }
44
+ return /* @__PURE__ */ React.createElement(View, {
45
+ style: styles.view1
46
+ }, (_a = props.columns) == null ? void 0 : _a.map((column, index) => /* @__PURE__ */ React.createElement(View, {
47
+ style: styles.view2,
48
+ key: index
49
+ }, /* @__PURE__ */ React.createElement(RenderBlocks, {
50
+ blocks: column.blocks
51
+ }))));
52
+ }
53
+ const styles = StyleSheet.create({
54
+ view1: { display: "flex", alignItems: "stretch" },
55
+ view2: { flexGrow: 1 }
56
+ });
57
+ export {
58
+ Columns as default
59
+ };
@@ -1,6 +1,6 @@
1
1
  import * as React from "react";
2
2
  import { View, StyleSheet, Image, Text } from "react-native";
3
- import RenderBlocks from "../components/render-blocks.lite";
3
+ import RenderBlocks from "../../components/render-blocks.lite";
4
4
 
5
5
  export default function Columns(props) {
6
6
  function getGutterSize() {
@@ -24,8 +24,9 @@ export default function Columns(props) {
24
24
  }
25
25
 
26
26
  function maybeApplyForTablet(prop) {
27
- const stackColumnsAt = props.stackColumnsAt || "tablet";
28
- return stackColumnsAt === "tablet" ? prop : "inherit";
27
+ const _stackColumnsAt = props.stackColumnsAt || "tablet";
28
+
29
+ return _stackColumnsAt === "tablet" ? prop : "inherit";
29
30
  }
30
31
 
31
32
  function columnsCssVars() {
@@ -55,7 +56,7 @@ export default function Columns(props) {
55
56
  return (
56
57
  <View style={styles.view1}>
57
58
  {props.columns?.map((column, index) => (
58
- <View style={styles.view2}>
59
+ <View style={styles.view2} key={index}>
59
60
  <RenderBlocks blocks={column.blocks} />
60
61
  </View>
61
62
  ))}
@@ -0,0 +1,218 @@
1
+ import * as React from 'react';
2
+ const componentInfo = {
3
+ name: "Columns",
4
+ builtIn: true,
5
+ inputs: [
6
+ {
7
+ name: "columns",
8
+ type: "array",
9
+ broadcast: true,
10
+ subFields: [
11
+ {
12
+ name: "blocks",
13
+ type: "array",
14
+ hideFromUI: true,
15
+ defaultValue: [
16
+ {
17
+ "@type": "@builder.io/sdk:Element",
18
+ responsiveStyles: {
19
+ large: {
20
+ display: "flex",
21
+ flexDirection: "column",
22
+ alignItems: "stretch",
23
+ flexShrink: "0",
24
+ position: "relative",
25
+ marginTop: "30px",
26
+ textAlign: "center",
27
+ lineHeight: "normal",
28
+ height: "auto",
29
+ minHeight: "20px",
30
+ minWidth: "20px",
31
+ overflow: "hidden"
32
+ }
33
+ },
34
+ component: {
35
+ name: "Image",
36
+ options: {
37
+ image: "https://builder.io/api/v1/image/assets%2Fpwgjf0RoYWbdnJSbpBAjXNRMe9F2%2Ffb27a7c790324294af8be1c35fe30f4d",
38
+ backgroundPosition: "center",
39
+ backgroundSize: "cover",
40
+ aspectRatio: 0.7004048582995948
41
+ }
42
+ }
43
+ },
44
+ {
45
+ "@type": "@builder.io/sdk:Element",
46
+ responsiveStyles: {
47
+ large: {
48
+ display: "flex",
49
+ flexDirection: "column",
50
+ alignItems: "stretch",
51
+ flexShrink: "0",
52
+ position: "relative",
53
+ marginTop: "30px",
54
+ textAlign: "center",
55
+ lineHeight: "normal",
56
+ height: "auto"
57
+ }
58
+ },
59
+ component: {
60
+ name: "Text",
61
+ options: {
62
+ text: "<p>Enter some text...</p>"
63
+ }
64
+ }
65
+ }
66
+ ]
67
+ },
68
+ {
69
+ name: "width",
70
+ type: "number",
71
+ hideFromUI: true,
72
+ helperText: "Width %, e.g. set to 50 to fill half of the space"
73
+ },
74
+ {
75
+ name: "link",
76
+ type: "url",
77
+ helperText: "Optionally set a url that clicking this column will link to"
78
+ }
79
+ ],
80
+ defaultValue: [
81
+ {
82
+ blocks: [
83
+ {
84
+ "@type": "@builder.io/sdk:Element",
85
+ responsiveStyles: {
86
+ large: {
87
+ display: "flex",
88
+ flexDirection: "column",
89
+ alignItems: "stretch",
90
+ flexShrink: "0",
91
+ position: "relative",
92
+ marginTop: "30px",
93
+ textAlign: "center",
94
+ lineHeight: "normal",
95
+ height: "auto",
96
+ minHeight: "20px",
97
+ minWidth: "20px",
98
+ overflow: "hidden"
99
+ }
100
+ },
101
+ component: {
102
+ name: "Image",
103
+ options: {
104
+ image: "https://builder.io/api/v1/image/assets%2Fpwgjf0RoYWbdnJSbpBAjXNRMe9F2%2Ffb27a7c790324294af8be1c35fe30f4d",
105
+ backgroundPosition: "center",
106
+ backgroundSize: "cover",
107
+ aspectRatio: 0.7004048582995948
108
+ }
109
+ }
110
+ },
111
+ {
112
+ "@type": "@builder.io/sdk:Element",
113
+ responsiveStyles: {
114
+ large: {
115
+ display: "flex",
116
+ flexDirection: "column",
117
+ alignItems: "stretch",
118
+ flexShrink: "0",
119
+ position: "relative",
120
+ marginTop: "30px",
121
+ textAlign: "center",
122
+ lineHeight: "normal",
123
+ height: "auto"
124
+ }
125
+ },
126
+ component: {
127
+ name: "Text",
128
+ options: {
129
+ text: "<p>Enter some text...</p>"
130
+ }
131
+ }
132
+ }
133
+ ]
134
+ },
135
+ {
136
+ blocks: [
137
+ {
138
+ "@type": "@builder.io/sdk:Element",
139
+ responsiveStyles: {
140
+ large: {
141
+ display: "flex",
142
+ flexDirection: "column",
143
+ alignItems: "stretch",
144
+ flexShrink: "0",
145
+ position: "relative",
146
+ marginTop: "30px",
147
+ textAlign: "center",
148
+ lineHeight: "normal",
149
+ height: "auto",
150
+ minHeight: "20px",
151
+ minWidth: "20px",
152
+ overflow: "hidden"
153
+ }
154
+ },
155
+ component: {
156
+ name: "Image",
157
+ options: {
158
+ image: "https://builder.io/api/v1/image/assets%2Fpwgjf0RoYWbdnJSbpBAjXNRMe9F2%2Ffb27a7c790324294af8be1c35fe30f4d",
159
+ backgroundPosition: "center",
160
+ backgroundSize: "cover",
161
+ aspectRatio: 0.7004048582995948
162
+ }
163
+ }
164
+ },
165
+ {
166
+ "@type": "@builder.io/sdk:Element",
167
+ responsiveStyles: {
168
+ large: {
169
+ display: "flex",
170
+ flexDirection: "column",
171
+ alignItems: "stretch",
172
+ flexShrink: "0",
173
+ position: "relative",
174
+ marginTop: "30px",
175
+ textAlign: "center",
176
+ lineHeight: "normal",
177
+ height: "auto"
178
+ }
179
+ },
180
+ component: {
181
+ name: "Text",
182
+ options: {
183
+ text: "<p>Enter some text...</p>"
184
+ }
185
+ }
186
+ }
187
+ ]
188
+ }
189
+ ],
190
+ 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(); } } } } "
191
+ },
192
+ {
193
+ name: "space",
194
+ type: "number",
195
+ defaultValue: 20,
196
+ helperText: "Size of gap between columns",
197
+ advanced: true
198
+ },
199
+ {
200
+ name: "stackColumnsAt",
201
+ type: "string",
202
+ defaultValue: "tablet",
203
+ helperText: "Convert horizontal columns to vertical at what device size",
204
+ enum: ["tablet", "mobile", "never"],
205
+ advanced: true
206
+ },
207
+ {
208
+ name: "reverseColumnsWhenStacked",
209
+ type: "boolean",
210
+ defaultValue: false,
211
+ helperText: "When stacking columns for mobile devices, reverse the ordering",
212
+ advanced: true
213
+ }
214
+ ]
215
+ };
216
+ export {
217
+ componentInfo
218
+ };
@@ -0,0 +1,32 @@
1
+ import * as React from 'react';
2
+ const componentInfo = {
3
+ name: "Custom Code",
4
+ static: true,
5
+ builtIn: true,
6
+ requiredPermissions: ["editCode"],
7
+ inputs: [
8
+ {
9
+ name: "code",
10
+ type: "html",
11
+ required: true,
12
+ defaultValue: "<p>Hello there, I am custom HTML code!</p>",
13
+ code: true
14
+ },
15
+ {
16
+ name: "replaceNodes",
17
+ type: "boolean",
18
+ helperText: "Preserve server rendered dom nodes",
19
+ advanced: true
20
+ },
21
+ {
22
+ name: "scriptsClientOnly",
23
+ type: "boolean",
24
+ defaultValue: false,
25
+ helperText: "Only print and run scripts on the client. Important when scripts influence DOM that could be replaced when client loads",
26
+ advanced: true
27
+ }
28
+ ]
29
+ };
30
+ export {
31
+ componentInfo
32
+ };
@@ -0,0 +1,50 @@
1
+ import * as React from "react";
2
+ import { View } from "react-native";
3
+ import { useState, useRef, useEffect } from "react";
4
+ function CustomCode(props) {
5
+ const [scriptsInserted, setScriptsInserted] = useState(() => []);
6
+ const [scriptsRun, setScriptsRun] = useState(() => []);
7
+ function findAndRunScripts() {
8
+ if (elem.current && typeof window !== "undefined") {
9
+ const scripts = elem.current.getElementsByTagName("script");
10
+ for (let i = 0; i < scripts.length; i++) {
11
+ const script = scripts[i];
12
+ if (script.src) {
13
+ if (scriptsInserted.includes(script.src)) {
14
+ continue;
15
+ }
16
+ scriptsInserted.push(script.src);
17
+ const newScript = document.createElement("script");
18
+ newScript.async = true;
19
+ newScript.src = script.src;
20
+ document.head.appendChild(newScript);
21
+ } else if (!script.type || [
22
+ "text/javascript",
23
+ "application/javascript",
24
+ "application/ecmascript"
25
+ ].includes(script.type)) {
26
+ if (scriptsRun.includes(script.innerText)) {
27
+ continue;
28
+ }
29
+ try {
30
+ scriptsRun.push(script.innerText);
31
+ new Function(script.innerText)();
32
+ } catch (error) {
33
+ console.warn("`CustomCode`: Error running script:", error);
34
+ }
35
+ }
36
+ }
37
+ }
38
+ }
39
+ const elem = useRef();
40
+ useEffect(() => {
41
+ findAndRunScripts();
42
+ }, []);
43
+ return /* @__PURE__ */ React.createElement(View, {
44
+ ref: elem,
45
+ dangerouslySetInnerHTML: { __html: props.code }
46
+ });
47
+ }
48
+ export {
49
+ CustomCode as default
50
+ };
@@ -55,5 +55,5 @@ export default function CustomCode(props) {
55
55
  findAndRunScripts();
56
56
  }, []);
57
57
 
58
- return <View ref={elem} dangerouslySetInnerHTML={{ __html: "props.code" }} />;
58
+ return <View ref={elem} dangerouslySetInnerHTML={{ __html: props.code }} />;
59
59
  }
@@ -0,0 +1,25 @@
1
+ import * as React from 'react';
2
+ const componentInfo = {
3
+ name: "Embed",
4
+ static: true,
5
+ builtIn: true,
6
+ inputs: [
7
+ {
8
+ name: "url",
9
+ type: "url",
10
+ required: true,
11
+ defaultValue: "",
12
+ helperText: "e.g. enter a youtube url, google map, etc",
13
+ 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'); } "
14
+ },
15
+ {
16
+ name: "content",
17
+ type: "html",
18
+ defaultValue: '<div style="padding: 20px; text-align: center">(Choose an embed URL)<div>',
19
+ hideFromUI: true
20
+ }
21
+ ]
22
+ };
23
+ export {
24
+ componentInfo
25
+ };
@@ -0,0 +1,50 @@
1
+ import * as React from "react";
2
+ import { View } from "react-native";
3
+ import { useState, useRef, useEffect } from "react";
4
+ function Embed(props) {
5
+ const [scriptsInserted, setScriptsInserted] = useState(() => []);
6
+ const [scriptsRun, setScriptsRun] = useState(() => []);
7
+ function findAndRunScripts() {
8
+ if (elem.current && typeof window !== "undefined") {
9
+ const scripts = elem.current.getElementsByTagName("script");
10
+ for (let i = 0; i < scripts.length; i++) {
11
+ const script = scripts[i];
12
+ if (script.src) {
13
+ if (scriptsInserted.includes(script.src)) {
14
+ continue;
15
+ }
16
+ scriptsInserted.push(script.src);
17
+ const newScript = document.createElement("script");
18
+ newScript.async = true;
19
+ newScript.src = script.src;
20
+ document.head.appendChild(newScript);
21
+ } else if (!script.type || [
22
+ "text/javascript",
23
+ "application/javascript",
24
+ "application/ecmascript"
25
+ ].includes(script.type)) {
26
+ if (scriptsRun.includes(script.innerText)) {
27
+ continue;
28
+ }
29
+ try {
30
+ scriptsRun.push(script.innerText);
31
+ new Function(script.innerText)();
32
+ } catch (error) {
33
+ console.warn("`Embed`: Error running script:", error);
34
+ }
35
+ }
36
+ }
37
+ }
38
+ }
39
+ const elem = useRef();
40
+ useEffect(() => {
41
+ findAndRunScripts();
42
+ }, []);
43
+ return /* @__PURE__ */ React.createElement(View, {
44
+ ref: elem,
45
+ dangerouslySetInnerHTML: { __html: props.content }
46
+ });
47
+ }
48
+ export {
49
+ Embed as default
50
+ };
@@ -56,6 +56,6 @@ export default function Embed(props) {
56
56
  }, []);
57
57
 
58
58
  return (
59
- <View ref={elem} dangerouslySetInnerHTML={{ __html: "props.content" }} />
59
+ <View ref={elem} dangerouslySetInnerHTML={{ __html: props.content }} />
60
60
  );
61
61
  }