@builder.io/sdk-react 0.0.1-0

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 (110) hide show
  1. package/README.md +19 -0
  2. package/package.json +15 -0
  3. package/src/blocks/button/button.js +38 -0
  4. package/src/blocks/button/component-info.js +41 -0
  5. package/src/blocks/columns/columns.js +110 -0
  6. package/src/blocks/columns/component-info.js +241 -0
  7. package/src/blocks/custom-code/component-info.js +31 -0
  8. package/src/blocks/custom-code/custom-code.js +50 -0
  9. package/src/blocks/embed/component-info.js +43 -0
  10. package/src/blocks/embed/embed.js +43 -0
  11. package/src/blocks/embed/helpers.js +9 -0
  12. package/src/blocks/form/component-info.js +262 -0
  13. package/src/blocks/form/form.js +225 -0
  14. package/src/blocks/fragment/component-info.js +11 -0
  15. package/src/blocks/fragment/fragment.js +7 -0
  16. package/src/blocks/image/component-info.js +150 -0
  17. package/src/blocks/image/image.helpers.js +48 -0
  18. package/src/blocks/image/image.js +90 -0
  19. package/src/blocks/img/component-info.js +20 -0
  20. package/src/blocks/img/img.js +35 -0
  21. package/src/blocks/input/component-info.js +74 -0
  22. package/src/blocks/input/input.js +35 -0
  23. package/src/blocks/raw-text/component-info.js +16 -0
  24. package/src/blocks/raw-text/raw-text.js +11 -0
  25. package/src/blocks/section/component-info.js +49 -0
  26. package/src/blocks/section/section.js +30 -0
  27. package/src/blocks/select/component-info.js +59 -0
  28. package/src/blocks/select/select.js +35 -0
  29. package/src/blocks/submit-button/component-info.js +28 -0
  30. package/src/blocks/submit-button/submit-button.js +28 -0
  31. package/src/blocks/symbol/component-info.js +43 -0
  32. package/src/blocks/symbol/symbol.js +69 -0
  33. package/src/blocks/text/component-info.js +24 -0
  34. package/src/blocks/text/text.js +10 -0
  35. package/src/blocks/textarea/component-info.js +47 -0
  36. package/src/blocks/textarea/textarea.js +31 -0
  37. package/src/blocks/video/component-info.js +106 -0
  38. package/src/blocks/video/video.js +51 -0
  39. package/src/components/render-block/block-styles.js +40 -0
  40. package/src/components/render-block/render-block.helpers.js +23 -0
  41. package/src/components/render-block/render-block.js +169 -0
  42. package/src/components/render-block/render-component.js +33 -0
  43. package/src/components/render-block/render-repeated-block.js +29 -0
  44. package/src/components/render-block/types.js +0 -0
  45. package/src/components/render-blocks.js +62 -0
  46. package/src/components/render-content/components/render-styles.js +58 -0
  47. package/src/components/render-content/index.js +4 -0
  48. package/src/components/render-content/render-content.js +265 -0
  49. package/src/components/render-inlined-styles.js +17 -0
  50. package/src/constants/builder-registered-components.js +48 -0
  51. package/src/constants/device-sizes.js +21 -0
  52. package/src/constants/target.js +4 -0
  53. package/src/context/builder.context.js +11 -0
  54. package/src/functions/camel-to-kebab-case.js +4 -0
  55. package/src/functions/convert-style-object.js +6 -0
  56. package/src/functions/evaluate.js +28 -0
  57. package/src/functions/event-handler-name.js +7 -0
  58. package/src/functions/get-block-actions.js +23 -0
  59. package/src/functions/get-block-component-options.js +28 -0
  60. package/src/functions/get-block-properties.js +29 -0
  61. package/src/functions/get-block-styles.js +34 -0
  62. package/src/functions/get-block-tag.js +6 -0
  63. package/src/functions/get-builder-search-params/fn.test.js +13 -0
  64. package/src/functions/get-builder-search-params/index.js +33 -0
  65. package/src/functions/get-content/ab-testing.js +38 -0
  66. package/src/functions/get-content/fn.test.js +31 -0
  67. package/src/functions/get-content/index.js +96 -0
  68. package/src/functions/get-content/types.js +0 -0
  69. package/src/functions/get-fetch.js +34 -0
  70. package/src/functions/get-global-this.js +18 -0
  71. package/src/functions/get-processed-block.js +53 -0
  72. package/src/functions/get-processed-block.test.js +32 -0
  73. package/src/functions/if-target.js +15 -0
  74. package/src/functions/is-browser.js +6 -0
  75. package/src/functions/is-editing.js +7 -0
  76. package/src/functions/is-iframe.js +7 -0
  77. package/src/functions/is-previewing.js +14 -0
  78. package/src/functions/on-change.js +27 -0
  79. package/src/functions/on-change.test.js +19 -0
  80. package/src/functions/register-component.js +72 -0
  81. package/src/functions/register.js +29 -0
  82. package/src/functions/sanitize-styles.js +5 -0
  83. package/src/functions/set-editor-settings.js +15 -0
  84. package/src/functions/set.js +11 -0
  85. package/src/functions/set.test.js +16 -0
  86. package/src/functions/track.js +91 -0
  87. package/src/functions/transform-block.js +6 -0
  88. package/src/helpers/cookie.js +59 -0
  89. package/src/helpers/css.js +12 -0
  90. package/src/helpers/flatten.js +34 -0
  91. package/src/helpers/localStorage.js +34 -0
  92. package/src/helpers/nullable.js +4 -0
  93. package/src/helpers/sessionId.js +26 -0
  94. package/src/helpers/time.js +5 -0
  95. package/src/helpers/url.js +10 -0
  96. package/src/helpers/url.test.js +15 -0
  97. package/src/helpers/uuid.js +13 -0
  98. package/src/helpers/visitorId.js +33 -0
  99. package/src/index-helpers/blocks-exports.js +22 -0
  100. package/src/index-helpers/top-of-file.js +4 -0
  101. package/src/index.js +10 -0
  102. package/src/scripts/init-editing.js +80 -0
  103. package/src/types/builder-block.js +0 -0
  104. package/src/types/builder-content.js +0 -0
  105. package/src/types/can-track.js +0 -0
  106. package/src/types/components.js +0 -0
  107. package/src/types/deep-partial.js +0 -0
  108. package/src/types/element.js +0 -0
  109. package/src/types/targets.js +0 -0
  110. package/src/types/typescript.js +0 -0
package/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # Builder.io React SDK v2 (BETA)
2
+
3
+ This is the React v2 SDK.
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
+
9
+ ## Feature Support
10
+
11
+ To check the status of the SDK, look at [these tables](../../README.md#feature-implementation).
12
+
13
+ ## Getting Started
14
+
15
+ ```
16
+ npm install @builder.io/sdk-react@dev
17
+ ```
18
+
19
+ Take a look at [our example repo](/examples/react-native) for how to use this SDK.
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@builder.io/sdk-react",
3
+ "description": "Builder.io SDK for React'",
4
+ "version": "0.0.1-0",
5
+ "main": "src/index.js",
6
+ "scripts": {
7
+ "release:dev": "npm version prerelease --no-git-tag-version && npm publish --tag dev --access public"
8
+ },
9
+ "peerDependencies": {
10
+ "react": "^18.2.0"
11
+ },
12
+ "devDependencies": {
13
+ "react": "^18.2.0"
14
+ }
15
+ }
@@ -0,0 +1,38 @@
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
+ function Button(props) {
22
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(React.Fragment, null, props.link ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("a", __spreadProps(__spreadValues({}, props.attributes), {
23
+ role: "button",
24
+ href: props.link,
25
+ target: props.openLinkInNewTab ? "_blank" : void 0
26
+ }), props.text)) : /* @__PURE__ */ React.createElement("button", __spreadProps(__spreadValues({}, props.attributes), {
27
+ className: "button"
28
+ }), props.text)), /* @__PURE__ */ React.createElement("style", {
29
+ jsx: true
30
+ }, `
31
+ .button {
32
+ all: unset;
33
+ }
34
+ `));
35
+ }
36
+ export {
37
+ Button as default
38
+ };
@@ -0,0 +1,41 @@
1
+ const componentInfo = {
2
+ name: "Core:Button",
3
+ builtIn: true,
4
+ image: "https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2F81a15681c3e74df09677dfc57a615b13",
5
+ defaultStyles: {
6
+ appearance: "none",
7
+ paddingTop: "15px",
8
+ paddingBottom: "15px",
9
+ paddingLeft: "25px",
10
+ paddingRight: "25px",
11
+ backgroundColor: "#000000",
12
+ color: "white",
13
+ borderRadius: "4px",
14
+ textAlign: "center",
15
+ cursor: "pointer"
16
+ },
17
+ inputs: [
18
+ {
19
+ name: "text",
20
+ type: "text",
21
+ defaultValue: "Click me!",
22
+ bubble: true
23
+ },
24
+ {
25
+ name: "link",
26
+ type: "url",
27
+ bubble: true
28
+ },
29
+ {
30
+ name: "openLinkInNewTab",
31
+ type: "boolean",
32
+ defaultValue: false,
33
+ friendlyName: "Open link in new tab"
34
+ }
35
+ ],
36
+ static: true,
37
+ noWrap: true
38
+ };
39
+ export {
40
+ componentInfo
41
+ };
@@ -0,0 +1,110 @@
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 RenderBlocks from "../../components/render-blocks.js";
19
+ function Columns(props) {
20
+ var _a;
21
+ function getGutterSize() {
22
+ return typeof props.space === "number" ? props.space || 0 : 20;
23
+ }
24
+ function getColumns() {
25
+ return props.columns || [];
26
+ }
27
+ function getWidth(index) {
28
+ var _a2;
29
+ const columns = getColumns();
30
+ return ((_a2 = columns[index]) == null ? void 0 : _a2.width) || 100 / columns.length;
31
+ }
32
+ function getColumnCssWidth(index) {
33
+ const columns = getColumns();
34
+ const gutterSize = getGutterSize();
35
+ const subtractWidth = gutterSize * (columns.length - 1) / columns.length;
36
+ return `calc(${getWidth(index)}% - ${subtractWidth}px)`;
37
+ }
38
+ function maybeApplyForTablet(prop) {
39
+ const _stackColumnsAt = props.stackColumnsAt || "tablet";
40
+ return _stackColumnsAt === "tablet" ? prop : "inherit";
41
+ }
42
+ function columnsCssVars() {
43
+ const flexDir = props.stackColumnsAt === "never" ? "inherit" : props.reverseColumnsWhenStacked ? "column-reverse" : "column";
44
+ return {
45
+ "--flex-dir": flexDir,
46
+ "--flex-dir-tablet": maybeApplyForTablet(flexDir)
47
+ };
48
+ }
49
+ function columnCssVars() {
50
+ const width = "100%";
51
+ const marginLeft = "0";
52
+ return {
53
+ "--column-width": width,
54
+ "--column-margin-left": marginLeft,
55
+ "--column-width-tablet": maybeApplyForTablet(width),
56
+ "--column-margin-left-tablet": maybeApplyForTablet(marginLeft)
57
+ };
58
+ }
59
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
60
+ className: "builder-columns div",
61
+ style: columnsCssVars()
62
+ }, (_a = props.columns) == null ? void 0 : _a.map((column, index) => /* @__PURE__ */ React.createElement("div", {
63
+ className: "builder-column div-2",
64
+ style: __spreadValues({
65
+ width: getColumnCssWidth(index),
66
+ marginLeft: `${index === 0 ? 0 : getGutterSize()}px`
67
+ }, columnCssVars()),
68
+ key: index
69
+ }, /* @__PURE__ */ React.createElement(RenderBlocks, {
70
+ blocks: column.blocks,
71
+ path: `component.options.columns.${index}.blocks`,
72
+ parent: props.builderBlock.id
73
+ })))), /* @__PURE__ */ React.createElement("style", {
74
+ jsx: true
75
+ }, `
76
+ .div {
77
+ display: flex;
78
+ align-items: stretch;
79
+ line-height: normal;
80
+ }
81
+ @media (max-width: 991px) {
82
+ .div {
83
+ flex-direction: var(--flex-dir-tablet);
84
+ }
85
+ }
86
+ @media (max-width: 639px) {
87
+ .div {
88
+ flex-direction: var(--flex-dir);
89
+ }
90
+ }
91
+ .div-2 {
92
+ flex-grow: 1;
93
+ }
94
+ @media (max-width: 991px) {
95
+ .div-2 {
96
+ width: var(--column-width-tablet) !important;
97
+ margin-left: var(--column-margin-left-tablet) !important;
98
+ }
99
+ }
100
+ @media (max-width: 639px) {
101
+ .div-2 {
102
+ width: var(--column-width) !important;
103
+ margin-left: var(--column-margin-left) !important;
104
+ }
105
+ }
106
+ `));
107
+ }
108
+ export {
109
+ Columns as default
110
+ };
@@ -0,0 +1,241 @@
1
+ const componentInfo = {
2
+ name: "Columns",
3
+ builtIn: true,
4
+ inputs: [
5
+ {
6
+ name: "columns",
7
+ type: "array",
8
+ broadcast: true,
9
+ subFields: [
10
+ {
11
+ name: "blocks",
12
+ type: "array",
13
+ hideFromUI: true,
14
+ defaultValue: [
15
+ {
16
+ "@type": "@builder.io/sdk:Element",
17
+ responsiveStyles: {
18
+ large: {
19
+ display: "flex",
20
+ flexDirection: "column",
21
+ alignItems: "stretch",
22
+ flexShrink: "0",
23
+ position: "relative",
24
+ marginTop: "30px",
25
+ textAlign: "center",
26
+ lineHeight: "normal",
27
+ height: "auto",
28
+ minHeight: "20px",
29
+ minWidth: "20px",
30
+ overflow: "hidden"
31
+ }
32
+ },
33
+ component: {
34
+ name: "Image",
35
+ options: {
36
+ image: "https://builder.io/api/v1/image/assets%2Fpwgjf0RoYWbdnJSbpBAjXNRMe9F2%2Ffb27a7c790324294af8be1c35fe30f4d",
37
+ backgroundPosition: "center",
38
+ backgroundSize: "cover",
39
+ aspectRatio: 0.7004048582995948
40
+ }
41
+ }
42
+ },
43
+ {
44
+ "@type": "@builder.io/sdk:Element",
45
+ responsiveStyles: {
46
+ large: {
47
+ display: "flex",
48
+ flexDirection: "column",
49
+ alignItems: "stretch",
50
+ flexShrink: "0",
51
+ position: "relative",
52
+ marginTop: "30px",
53
+ textAlign: "center",
54
+ lineHeight: "normal",
55
+ height: "auto"
56
+ }
57
+ },
58
+ component: {
59
+ name: "Text",
60
+ options: {
61
+ text: "<p>Enter some text...</p>"
62
+ }
63
+ }
64
+ }
65
+ ]
66
+ },
67
+ {
68
+ name: "width",
69
+ type: "number",
70
+ hideFromUI: true,
71
+ helperText: "Width %, e.g. set to 50 to fill half of the space"
72
+ },
73
+ {
74
+ name: "link",
75
+ type: "url",
76
+ helperText: "Optionally set a url that clicking this column will link to"
77
+ }
78
+ ],
79
+ defaultValue: [
80
+ {
81
+ blocks: [
82
+ {
83
+ "@type": "@builder.io/sdk:Element",
84
+ responsiveStyles: {
85
+ large: {
86
+ display: "flex",
87
+ flexDirection: "column",
88
+ alignItems: "stretch",
89
+ flexShrink: "0",
90
+ position: "relative",
91
+ marginTop: "30px",
92
+ textAlign: "center",
93
+ lineHeight: "normal",
94
+ height: "auto",
95
+ minHeight: "20px",
96
+ minWidth: "20px",
97
+ overflow: "hidden"
98
+ }
99
+ },
100
+ component: {
101
+ name: "Image",
102
+ options: {
103
+ image: "https://builder.io/api/v1/image/assets%2Fpwgjf0RoYWbdnJSbpBAjXNRMe9F2%2Ffb27a7c790324294af8be1c35fe30f4d",
104
+ backgroundPosition: "center",
105
+ backgroundSize: "cover",
106
+ aspectRatio: 0.7004048582995948
107
+ }
108
+ }
109
+ },
110
+ {
111
+ "@type": "@builder.io/sdk:Element",
112
+ responsiveStyles: {
113
+ large: {
114
+ display: "flex",
115
+ flexDirection: "column",
116
+ alignItems: "stretch",
117
+ flexShrink: "0",
118
+ position: "relative",
119
+ marginTop: "30px",
120
+ textAlign: "center",
121
+ lineHeight: "normal",
122
+ height: "auto"
123
+ }
124
+ },
125
+ component: {
126
+ name: "Text",
127
+ options: {
128
+ text: "<p>Enter some text...</p>"
129
+ }
130
+ }
131
+ }
132
+ ]
133
+ },
134
+ {
135
+ blocks: [
136
+ {
137
+ "@type": "@builder.io/sdk:Element",
138
+ responsiveStyles: {
139
+ large: {
140
+ display: "flex",
141
+ flexDirection: "column",
142
+ alignItems: "stretch",
143
+ flexShrink: "0",
144
+ position: "relative",
145
+ marginTop: "30px",
146
+ textAlign: "center",
147
+ lineHeight: "normal",
148
+ height: "auto",
149
+ minHeight: "20px",
150
+ minWidth: "20px",
151
+ overflow: "hidden"
152
+ }
153
+ },
154
+ component: {
155
+ name: "Image",
156
+ options: {
157
+ image: "https://builder.io/api/v1/image/assets%2Fpwgjf0RoYWbdnJSbpBAjXNRMe9F2%2Ffb27a7c790324294af8be1c35fe30f4d",
158
+ backgroundPosition: "center",
159
+ backgroundSize: "cover",
160
+ aspectRatio: 0.7004048582995948
161
+ }
162
+ }
163
+ },
164
+ {
165
+ "@type": "@builder.io/sdk:Element",
166
+ responsiveStyles: {
167
+ large: {
168
+ display: "flex",
169
+ flexDirection: "column",
170
+ alignItems: "stretch",
171
+ flexShrink: "0",
172
+ position: "relative",
173
+ marginTop: "30px",
174
+ textAlign: "center",
175
+ lineHeight: "normal",
176
+ height: "auto"
177
+ }
178
+ },
179
+ component: {
180
+ name: "Text",
181
+ options: {
182
+ text: "<p>Enter some text...</p>"
183
+ }
184
+ }
185
+ }
186
+ ]
187
+ }
188
+ ],
189
+ onChange(options) {
190
+ function clearWidths() {
191
+ columns.forEach((col) => {
192
+ col.delete("width");
193
+ });
194
+ }
195
+ const columns = options.get("columns");
196
+ if (Array.isArray(columns)) {
197
+ const containsColumnWithWidth = !!columns.find((col) => col.get("width"));
198
+ if (containsColumnWithWidth) {
199
+ const containsColumnWithoutWidth = !!columns.find((col) => !col.get("width"));
200
+ if (containsColumnWithoutWidth) {
201
+ clearWidths();
202
+ } else {
203
+ const sumWidths = columns.reduce((memo, col) => {
204
+ return memo + col.get("width");
205
+ }, 0);
206
+ const widthsDontAddUp = sumWidths !== 100;
207
+ if (widthsDontAddUp) {
208
+ clearWidths();
209
+ }
210
+ }
211
+ }
212
+ }
213
+ }
214
+ },
215
+ {
216
+ name: "space",
217
+ type: "number",
218
+ defaultValue: 20,
219
+ helperText: "Size of gap between columns",
220
+ advanced: true
221
+ },
222
+ {
223
+ name: "stackColumnsAt",
224
+ type: "string",
225
+ defaultValue: "tablet",
226
+ helperText: "Convert horizontal columns to vertical at what device size",
227
+ enum: ["tablet", "mobile", "never"],
228
+ advanced: true
229
+ },
230
+ {
231
+ name: "reverseColumnsWhenStacked",
232
+ type: "boolean",
233
+ defaultValue: false,
234
+ helperText: "When stacking columns for mobile devices, reverse the ordering",
235
+ advanced: true
236
+ }
237
+ ]
238
+ };
239
+ export {
240
+ componentInfo
241
+ };
@@ -0,0 +1,31 @@
1
+ const componentInfo = {
2
+ name: "Custom Code",
3
+ static: true,
4
+ builtIn: true,
5
+ requiredPermissions: ["editCode"],
6
+ inputs: [
7
+ {
8
+ name: "code",
9
+ type: "html",
10
+ required: true,
11
+ defaultValue: "<p>Hello there, I am custom HTML code!</p>",
12
+ code: true
13
+ },
14
+ {
15
+ name: "replaceNodes",
16
+ type: "boolean",
17
+ helperText: "Preserve server rendered dom nodes",
18
+ advanced: true
19
+ },
20
+ {
21
+ name: "scriptsClientOnly",
22
+ type: "boolean",
23
+ defaultValue: false,
24
+ helperText: "Only print and run scripts on the client. Important when scripts influence DOM that could be replaced when client loads",
25
+ advanced: true
26
+ }
27
+ ]
28
+ };
29
+ export {
30
+ componentInfo
31
+ };
@@ -0,0 +1,50 @@
1
+ import * as React from "react";
2
+ import { useState, useRef, useEffect } from "react";
3
+ function CustomCode(props) {
4
+ const elem = useRef(null);
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
+ useEffect(() => {
40
+ findAndRunScripts();
41
+ }, []);
42
+ return /* @__PURE__ */ React.createElement("div", {
43
+ ref: elem,
44
+ className: "builder-custom-code" + (props.replaceNodes ? " replace-nodes" : ""),
45
+ dangerouslySetInnerHTML: { __html: props.code }
46
+ });
47
+ }
48
+ export {
49
+ CustomCode as default
50
+ };
@@ -0,0 +1,43 @@
1
+ const componentInfo = {
2
+ name: "Embed",
3
+ static: true,
4
+ builtIn: true,
5
+ inputs: [
6
+ {
7
+ name: "url",
8
+ type: "url",
9
+ required: true,
10
+ defaultValue: "",
11
+ helperText: "e.g. enter a youtube url, google map, etc",
12
+ onChange(options) {
13
+ const url = options.get("url");
14
+ if (url) {
15
+ options.set("content", "Loading...");
16
+ const apiKey = "ae0e60e78201a3f2b0de4b";
17
+ return fetch(`https://iframe.ly/api/iframely?url=${url}&api_key=${apiKey}`).then((res) => res.json()).then((data) => {
18
+ if (options.get("url") === url) {
19
+ if (data.html) {
20
+ options.set("content", data.html);
21
+ } else {
22
+ options.set("content", "Invalid url, please try another");
23
+ }
24
+ }
25
+ }).catch((_err) => {
26
+ options.set("content", "There was an error embedding this URL, please try again or another URL");
27
+ });
28
+ } else {
29
+ options.delete("content");
30
+ }
31
+ }
32
+ },
33
+ {
34
+ name: "content",
35
+ type: "html",
36
+ defaultValue: '<div style="padding: 20px; text-align: center">(Choose an embed URL)<div>',
37
+ hideFromUI: true
38
+ }
39
+ ]
40
+ };
41
+ export {
42
+ componentInfo
43
+ };
@@ -0,0 +1,43 @@
1
+ import * as React from "react";
2
+ import { useState, useRef, useEffect } from "react";
3
+ import { isJsScript } from "./helpers";
4
+ function Embed(props) {
5
+ const elem = useRef(null);
6
+ const [scriptsInserted, setScriptsInserted] = useState(() => []);
7
+ const [scriptsRun, setScriptsRun] = useState(() => []);
8
+ const [ranInitFn, setRanInitFn] = useState(() => false);
9
+ function findAndRunScripts() {
10
+ const scripts = elem.current.getElementsByTagName("script");
11
+ for (let i = 0; i < scripts.length; i++) {
12
+ const script = scripts[i];
13
+ if (script.src && !scriptsInserted.includes(script.src)) {
14
+ scriptsInserted.push(script.src);
15
+ const newScript = document.createElement("script");
16
+ newScript.async = true;
17
+ newScript.src = script.src;
18
+ document.head.appendChild(newScript);
19
+ } else if (isJsScript(script) && !scriptsRun.includes(script.innerText)) {
20
+ try {
21
+ scriptsRun.push(script.innerText);
22
+ new Function(script.innerText)();
23
+ } catch (error) {
24
+ console.warn("`Embed`: Error running script:", error);
25
+ }
26
+ }
27
+ }
28
+ }
29
+ useEffect(() => {
30
+ if (elem.current && !ranInitFn) {
31
+ setRanInitFn(true);
32
+ findAndRunScripts();
33
+ }
34
+ }, [elem.current, ranInitFn]);
35
+ return /* @__PURE__ */ React.createElement("div", {
36
+ className: "builder-embed",
37
+ ref: elem,
38
+ dangerouslySetInnerHTML: { __html: props.content }
39
+ });
40
+ }
41
+ export {
42
+ Embed as default
43
+ };
@@ -0,0 +1,9 @@
1
+ const SCRIPT_MIME_TYPES = [
2
+ "text/javascript",
3
+ "application/javascript",
4
+ "application/ecmascript"
5
+ ];
6
+ const isJsScript = (script) => SCRIPT_MIME_TYPES.includes(script.type);
7
+ export {
8
+ isJsScript
9
+ };