@builder.io/sdk-react-native 0.0.1-6 → 0.0.1-62

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 (138) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.md +19 -0
  3. package/package.json +6 -4
  4. package/src/blocks/button/button.js +31 -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/component-info.js +242 -0
  8. package/src/blocks/custom-code/component-info.js +32 -0
  9. package/src/blocks/{custom-code.lite.tsx → custom-code/custom-code.js} +16 -33
  10. package/src/blocks/embed/component-info.js +44 -0
  11. package/src/blocks/embed/embed.js +43 -0
  12. package/src/blocks/embed/helpers.js +10 -0
  13. package/src/blocks/form/component-info.js +263 -0
  14. package/src/blocks/form/form.js +221 -0
  15. package/src/blocks/fragment/component-info.js +12 -0
  16. package/src/blocks/fragment/fragment.js +8 -0
  17. package/src/blocks/image/component-info.js +151 -0
  18. package/src/blocks/image/image.helpers.js +49 -0
  19. package/src/blocks/image/image.js +41 -0
  20. package/src/blocks/img/component-info.js +21 -0
  21. package/src/blocks/img/img.js +36 -0
  22. package/src/blocks/input/component-info.js +75 -0
  23. package/src/blocks/input/input.js +36 -0
  24. package/src/blocks/raw-text/component-info.js +17 -0
  25. package/src/blocks/raw-text/raw-text.js +10 -0
  26. package/src/blocks/section/component-info.js +50 -0
  27. package/src/blocks/section/section.js +31 -0
  28. package/src/blocks/select/component-info.js +60 -0
  29. package/src/blocks/select/select.js +36 -0
  30. package/src/blocks/submit-button/component-info.js +29 -0
  31. package/src/blocks/submit-button/submit-button.js +29 -0
  32. package/src/blocks/symbol/component-info.js +44 -0
  33. package/src/blocks/symbol/symbol.js +69 -0
  34. package/src/blocks/{text.js → text/component-info.js} +4 -10
  35. package/src/blocks/text/text.js +65 -0
  36. package/src/blocks/textarea/component-info.js +48 -0
  37. package/src/blocks/textarea/textarea.js +32 -0
  38. package/src/blocks/video/component-info.js +107 -0
  39. package/src/blocks/video/video.js +33 -0
  40. package/src/components/render-block/block-styles.js +40 -0
  41. package/src/components/render-block/render-block.helpers.js +24 -0
  42. package/src/components/render-block/render-block.js +169 -0
  43. package/src/components/render-block/render-component.js +33 -0
  44. package/src/components/render-block/render-repeated-block.js +29 -0
  45. package/src/components/render-blocks.js +23 -12
  46. package/src/components/render-content/components/render-styles.js +58 -0
  47. package/src/components/render-content/index.js +5 -0
  48. package/src/components/render-content/render-content.js +254 -0
  49. package/src/components/render-inlined-styles.js +18 -0
  50. package/src/constants/builder-registered-components.js +43 -0
  51. package/src/constants/device-sizes.js +3 -21
  52. package/src/constants/target.js +5 -0
  53. package/src/context/builder.context.js +7 -1
  54. package/src/functions/camel-to-kebab-case.js +5 -0
  55. package/src/functions/convert-style-object.js +7 -0
  56. package/src/functions/evaluate.js +17 -8
  57. package/src/functions/event-handler-name.js +8 -0
  58. package/src/functions/get-block-actions.js +14 -13
  59. package/src/functions/get-block-component-options.js +22 -1
  60. package/src/functions/get-block-properties.js +2 -3
  61. package/src/functions/get-block-styles.js +9 -19
  62. package/src/functions/get-block-tag.js +1 -1
  63. package/src/functions/get-builder-search-params/fn.test.js +14 -0
  64. package/src/functions/get-builder-search-params/index.js +23 -0
  65. package/src/functions/get-content/ab-testing.js +39 -0
  66. package/src/functions/get-content/fn.test.js +32 -0
  67. package/src/functions/get-content/index.js +94 -0
  68. package/src/functions/get-content/types.js +1 -0
  69. package/src/functions/get-fetch.js +35 -0
  70. package/src/functions/get-global-this.js +19 -0
  71. package/src/functions/get-processed-block.js +18 -9
  72. package/src/functions/get-processed-block.test.js +14 -8
  73. package/src/functions/if-target.js +11 -2
  74. package/src/functions/is-browser.js +1 -2
  75. package/src/functions/is-editing.js +1 -1
  76. package/src/functions/is-iframe.js +1 -1
  77. package/src/functions/is-previewing.js +15 -0
  78. package/src/functions/is-react-native.js +1 -1
  79. package/src/functions/on-change.test.js +1 -2
  80. package/src/functions/previewing-model-name.js +12 -0
  81. package/src/functions/register-component.js +46 -26
  82. package/src/functions/register.js +30 -0
  83. package/src/functions/sanitize-styles.js +33 -0
  84. package/src/functions/set-editor-settings.js +16 -0
  85. package/src/functions/set.test.js +1 -2
  86. package/src/functions/track.js +7 -3
  87. package/src/functions/transform-block.js +38 -0
  88. package/src/helpers/css.js +13 -0
  89. package/src/helpers/flatten.js +35 -0
  90. package/src/index-helpers/blocks-exports.js +19 -0
  91. package/src/index-helpers/top-of-file.js +2 -0
  92. package/src/index.js +10 -23
  93. package/src/scripts/init-editing.js +73 -49
  94. package/src/types/components.js +1 -0
  95. package/src/types/deep-partial.js +1 -0
  96. package/src/types/element.js +1 -0
  97. package/src/types/targets.js +1 -0
  98. package/src/types/typescript.js +1 -0
  99. package/index.js +0 -11
  100. package/src/blocks/button.js +0 -37
  101. package/src/blocks/button.lite.tsx +0 -29
  102. package/src/blocks/columns.js +0 -42
  103. package/src/blocks/columns.lite.tsx +0 -41
  104. package/src/blocks/custom-code.js +0 -56
  105. package/src/blocks/embed.js +0 -56
  106. package/src/blocks/embed.lite.tsx +0 -65
  107. package/src/blocks/form.js +0 -229
  108. package/src/blocks/form.lite.tsx +0 -257
  109. package/src/blocks/image.js +0 -123
  110. package/src/blocks/image.lite.tsx +0 -35
  111. package/src/blocks/img.js +0 -41
  112. package/src/blocks/img.lite.tsx +0 -19
  113. package/src/blocks/input.js +0 -41
  114. package/src/blocks/input.lite.tsx +0 -23
  115. package/src/blocks/raw-text.js +0 -17
  116. package/src/blocks/raw-text.lite.tsx +0 -12
  117. package/src/blocks/section.js +0 -36
  118. package/src/blocks/section.lite.tsx +0 -20
  119. package/src/blocks/select.js +0 -40
  120. package/src/blocks/select.lite.tsx +0 -24
  121. package/src/blocks/submit-button.js +0 -34
  122. package/src/blocks/submit-button.lite.tsx +0 -11
  123. package/src/blocks/symbol.js +0 -20
  124. package/src/blocks/symbol.lite.tsx +0 -20
  125. package/src/blocks/text.lite.tsx +0 -12
  126. package/src/blocks/textarea.js +0 -37
  127. package/src/blocks/textarea.lite.tsx +0 -15
  128. package/src/blocks/video.js +0 -49
  129. package/src/blocks/video.lite.tsx +0 -28
  130. package/src/components/render-block.js +0 -84
  131. package/src/components/render-block.lite.tsx +0 -92
  132. package/src/components/render-blocks.lite.tsx +0 -56
  133. package/src/components/render-content.js +0 -66
  134. package/src/components/render-content.lite.tsx +0 -95
  135. package/src/functions/get-content.js +0 -103
  136. package/src/functions/get-target.js +0 -7
  137. package/src/functions/macro-eval.js +0 -6
  138. package/src/package.json +0 -18
@@ -0,0 +1,35 @@
1
+ import * as React from 'react';
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __spreadValues = (a, b) => {
10
+ for (var prop in b || (b = {}))
11
+ if (__hasOwnProp.call(b, prop))
12
+ __defNormalProp(a, prop, b[prop]);
13
+ if (__getOwnPropSymbols)
14
+ for (var prop of __getOwnPropSymbols(b)) {
15
+ if (__propIsEnum.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ }
18
+ return a;
19
+ };
20
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
+ function flatten(object, path = null, separator = ".") {
22
+ return Object.keys(object).reduce((acc, key) => {
23
+ const value = object[key];
24
+ const newPath = [path, key].filter(Boolean).join(separator);
25
+ const isObject = [
26
+ typeof value === "object",
27
+ value !== null,
28
+ !(Array.isArray(value) && value.length === 0)
29
+ ].every(Boolean);
30
+ return isObject ? __spreadValues(__spreadValues({}, acc), flatten(value, newPath, separator)) : __spreadProps(__spreadValues({}, acc), { [newPath]: value });
31
+ }, {});
32
+ }
33
+ export {
34
+ flatten
35
+ };
@@ -0,0 +1,19 @@
1
+ import * as React from 'react';
2
+ import { default as default2 } from "../blocks/columns/columns.js";
3
+ import { default as default3 } from "../blocks/image/image.js";
4
+ import { default as default4 } from "../blocks/text/text.js";
5
+ import { default as default5 } from "../blocks/symbol/symbol.js";
6
+ import { default as default6 } from "../blocks/button/button.js";
7
+ import { default as default7 } from "../blocks/section/section.js";
8
+ import { default as default8 } from "../blocks/fragment/fragment.js";
9
+ import { default as default9 } from "../components/render-content/render-content.js";
10
+ export {
11
+ default6 as Button,
12
+ default2 as Columns,
13
+ default8 as Fragment,
14
+ default3 as Image,
15
+ default9 as RenderContent,
16
+ default7 as Section,
17
+ default5 as Symbol,
18
+ default4 as Text
19
+ };
@@ -0,0 +1,2 @@
1
+ import * as React from 'react';
2
+ import "react-native-url-polyfill/auto";
package/src/index.js CHANGED
@@ -1,24 +1,11 @@
1
1
  import * as React from 'react';
2
- import { isEditing } from "./functions/is-editing";
3
- if (isEditing()) {
4
- import("./scripts/init-editing");
5
- }
6
- import { default as default2 } from "./blocks/columns";
7
- import { default as default3 } from "./blocks/image";
8
- import { default as default4 } from "./blocks/text";
9
- import { default as default5 } from "./blocks/video";
10
- import { default as default6 } from "./blocks/symbol";
11
- import { default as default7 } from "./blocks/button";
12
- import { default as default8 } from "./blocks/section";
13
- import { default as default9 } from "./components/render-content";
14
- export * from "./functions/register-component";
15
- export {
16
- default7 as Button,
17
- default2 as Columns,
18
- default3 as Image,
19
- default9 as RenderContent,
20
- default8 as Section,
21
- default6 as Symbol,
22
- default4 as Text,
23
- default5 as Video
24
- };
2
+ import "./index-helpers/top-of-file.js";
3
+ import "./scripts/init-editing.js";
4
+ export * from "./index-helpers/blocks-exports.js";
5
+ export * from "./functions/is-editing.js";
6
+ export * from "./functions/is-previewing.js";
7
+ export * from "./functions/register-component.js";
8
+ export * from "./functions/register.js";
9
+ export * from "./functions/set-editor-settings.js";
10
+ export * from "./functions/get-content/index.js";
11
+ export * from "./functions/get-builder-search-params/index.js";
@@ -1,57 +1,81 @@
1
1
  import * as React from 'react';
2
- var _a;
3
- import { getTarget } from "../functions/get-target";
4
- import { isBrowser } from "../functions/is-browser";
5
- if (isBrowser()) {
6
- (_a = window.parent) == null ? void 0 : _a.postMessage({
7
- type: "builder.sdkInfo",
8
- data: {
9
- target: getTarget(),
10
- type: process.env.SDK_TYPE,
11
- version: process.env.SDK_VERSION,
12
- supportsPatchUpdates: false
13
- }
14
- }, "*");
15
- window.addEventListener("message", ({ data }) => {
16
- var _a2, _b;
17
- if (data) {
18
- switch (data.type) {
19
- case "builder.evaluate": {
20
- const text = data.data.text;
21
- const args = data.data.arguments || [];
22
- const id = data.data.id;
23
- const fn = new Function(text);
24
- let result;
25
- let error = null;
26
- try {
27
- result = fn.apply(null, args);
28
- } catch (err) {
29
- error = err;
30
- }
31
- if (error) {
32
- (_a2 = window.parent) == null ? void 0 : _a2.postMessage({
33
- type: "builder.evaluateError",
34
- data: { id, error: error.message }
35
- }, "*");
36
- } else {
37
- if (result && typeof result.then === "function") {
38
- result.then((finalResult) => {
39
- var _a3;
40
- (_a3 = window.parent) == null ? void 0 : _a3.postMessage({
2
+ import { TARGET } from "../constants/target.js";
3
+ import { isBrowser } from "../functions/is-browser.js";
4
+ import { isEditing } from "../functions/is-editing.js";
5
+ import { register } from "../functions/register.js";
6
+ const registerInsertMenu = () => {
7
+ register("insertMenu", {
8
+ name: "_default",
9
+ default: true,
10
+ items: [
11
+ { name: "Box" },
12
+ { name: "Text" },
13
+ { name: "Image" },
14
+ { name: "Columns" },
15
+ ...TARGET === "reactNative" ? [] : [
16
+ { name: "Core:Section" },
17
+ { name: "Core:Button" },
18
+ { name: "Embed" },
19
+ { name: "Custom Code" }
20
+ ]
21
+ ]
22
+ });
23
+ };
24
+ const setupBrowserForEditing = () => {
25
+ var _a;
26
+ if (isBrowser()) {
27
+ (_a = window.parent) == null ? void 0 : _a.postMessage({
28
+ type: "builder.sdkInfo",
29
+ data: {
30
+ target: TARGET,
31
+ supportsPatchUpdates: false
32
+ }
33
+ }, "*");
34
+ window.addEventListener("message", ({ data }) => {
35
+ var _a2, _b;
36
+ if (data) {
37
+ switch (data.type) {
38
+ case "builder.evaluate": {
39
+ const text = data.data.text;
40
+ const args = data.data.arguments || [];
41
+ const id = data.data.id;
42
+ const fn = new Function(text);
43
+ let result;
44
+ let error = null;
45
+ try {
46
+ result = fn.apply(null, args);
47
+ } catch (err) {
48
+ error = err;
49
+ }
50
+ if (error) {
51
+ (_a2 = window.parent) == null ? void 0 : _a2.postMessage({
52
+ type: "builder.evaluateError",
53
+ data: { id, error: error.message }
54
+ }, "*");
55
+ } else {
56
+ if (result && typeof result.then === "function") {
57
+ result.then((finalResult) => {
58
+ var _a3;
59
+ (_a3 = window.parent) == null ? void 0 : _a3.postMessage({
60
+ type: "builder.evaluateResult",
61
+ data: { id, result: finalResult }
62
+ }, "*");
63
+ }).catch(console.error);
64
+ } else {
65
+ (_b = window.parent) == null ? void 0 : _b.postMessage({
41
66
  type: "builder.evaluateResult",
42
- data: { id, result: finalResult }
67
+ data: { result, id }
43
68
  }, "*");
44
- }).catch(console.error);
45
- } else {
46
- (_b = window.parent) == null ? void 0 : _b.postMessage({
47
- type: "builder.evaluateResult",
48
- data: { result, id }
49
- }, "*");
69
+ }
50
70
  }
71
+ break;
51
72
  }
52
- break;
53
73
  }
54
74
  }
55
- }
56
- });
75
+ });
76
+ }
77
+ };
78
+ if (isEditing()) {
79
+ registerInsertMenu();
80
+ setupBrowserForEditing();
57
81
  }
@@ -0,0 +1 @@
1
+ import * as React from 'react';
@@ -0,0 +1 @@
1
+ import * as React from 'react';
@@ -0,0 +1 @@
1
+ import * as React from 'react';
@@ -0,0 +1 @@
1
+ import * as React from 'react';
@@ -0,0 +1 @@
1
+ import * as React from 'react';
package/index.js DELETED
@@ -1,11 +0,0 @@
1
- import { isEditing } from './src/functions/is-editing';
2
-
3
- if (isEditing()) {
4
- import('./src/scripts/init-editing');
5
- }
6
-
7
- // TODO: lazy option
8
- export { default as Columns } from './src/blocks/columns';
9
- export { default as Image } from './src/blocks/image';
10
- export { default as Text } from './src/blocks/text';
11
- export { default as RenderContent } from './src/components/render-content';
@@ -1,37 +0,0 @@
1
- import { registerComponent } from '../functions/register-component';
2
-
3
- var __defProp = Object.defineProperty;
4
- var __defProps = Object.defineProperties;
5
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
- var __spreadValues = (a, b) => {
11
- for (var prop in b || (b = {}))
12
- if (__hasOwnProp.call(b, prop))
13
- __defNormalProp(a, prop, b[prop]);
14
- if (__getOwnPropSymbols)
15
- for (var prop of __getOwnPropSymbols(b)) {
16
- if (__propIsEnum.call(b, prop))
17
- __defNormalProp(a, prop, b[prop]);
18
- }
19
- return a;
20
- };
21
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
22
- import * as React from "react";
23
- import { View } from "react-native";
24
- function Button(props) {
25
- return /* @__PURE__ */ React.createElement(React.Fragment, null, props.link && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(View, __spreadProps(__spreadValues({}, props.attributes), {
26
- href: props.link,
27
- target: props.openLinkInNewTab ? "_blank" : void 0
28
- }), props.text)), !props.link && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(View, __spreadProps(__spreadValues({}, props.attributes), {
29
- type: "button"
30
- }), props.text)));
31
- }
32
- export {
33
- Button as default
34
- };
35
-
36
-
37
- registerComponent(Button, {name:'Core:Button',image:'https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2F81a15681c3e74df09677dfc57a615b13',defaultStyles:{appearance:'none',paddingTop:'15px',paddingBottom:'15px',paddingLeft:'25px',paddingRight:'25px',backgroundColor:'#3898EC',color:'white',borderRadius:'4px',textAlign:'center',cursor:'pointer'},inputs:[{name:'text',type:'text',defaultValue:'Click me!',bubble:true},{name:'link',type:'url',bubble:true},{name:'openLinkInNewTab',type:'boolean',defaultValue:false,friendlyName:'Open link in new tab'}],static:true,noWrap:true});
@@ -1,29 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
- import { useContext } from "react";
4
-
5
- export default function Button(props) {
6
- return (
7
- <>
8
- {props.link && (
9
- <>
10
- <View
11
- {...props.attributes}
12
- href={props.link}
13
- target={props.openLinkInNewTab ? "_blank" : undefined}
14
- >
15
- {props.text}
16
- </View>
17
- </>
18
- )}
19
-
20
- {!props.link && (
21
- <>
22
- <View {...props.attributes} type="button">
23
- {props.text}
24
- </View>
25
- </>
26
- )}
27
- </>
28
- );
29
- }
@@ -1,42 +0,0 @@
1
- import { registerComponent } from '../functions/register-component';
2
-
3
- import * as React from "react";
4
- import { View, StyleSheet } from "react-native";
5
- import RenderBlocks from "../components/render-blocks";
6
- function Columns(props) {
7
- function getGutterSize() {
8
- return typeof props.space === "number" ? props.space || 0 : 20;
9
- }
10
- function getColumns() {
11
- return props.columns || [];
12
- }
13
- function getWidth(index) {
14
- const columns = this.getColumns();
15
- return columns[index] && columns[index].width || 100 / columns.length;
16
- }
17
- function getColumnCssWidth(index) {
18
- const columns = this.getColumns();
19
- const gutterSize = this.getGutterSize();
20
- const subtractWidth = gutterSize * (columns.length - 1) / columns.length;
21
- return `calc(${this.getWidth(index)}% - ${subtractWidth}px)`;
22
- }
23
- return /* @__PURE__ */ React.createElement(View, {
24
- className: "builder-columns",
25
- style: styles.view1
26
- }, props.columns.map((column) => /* @__PURE__ */ React.createElement(View, {
27
- className: "builder-column",
28
- style: styles.view2
29
- }, /* @__PURE__ */ React.createElement(RenderBlocks, {
30
- blocks: column.blocks
31
- }))));
32
- }
33
- const styles = StyleSheet.create({
34
- view1: { display: "flex", flexDirection: "column", alignItems: "stretch" },
35
- view2: { flexGrow: 1 }
36
- });
37
- export {
38
- Columns as default
39
- };
40
-
41
-
42
- registerComponent(Columns, {name:'Columns',inputs:[{name:'columns',type:'array',broadcast:true,subFields:[{name:'blocks',type:'array',hideFromUI:true,defaultValue:[{'@type':'@builder.io/sdk:Element',responsiveStyles:{large:{display:'flex',flexDirection:'column',alignItems:'stretch',flexShrink:'0',position:'relative',marginTop:'30px',textAlign:'center',lineHeight:'normal',height:'auto',minHeight:'20px',minWidth:'20px',overflow:'hidden'}},component:{name:'Image',options:{image:'https://builder.io/api/v1/image/assets%2Fpwgjf0RoYWbdnJSbpBAjXNRMe9F2%2Ffb27a7c790324294af8be1c35fe30f4d',backgroundPosition:'center',backgroundSize:'cover',aspectRatio:0.7004048582995948}}},{'@type':'@builder.io/sdk:Element',responsiveStyles:{large:{display:'flex',flexDirection:'column',alignItems:'stretch',flexShrink:'0',position:'relative',marginTop:'30px',textAlign:'center',lineHeight:'normal',height:'auto'}},component:{name:'Text',options:{text:'<p>Enter some text...</p>'}}}]},{name:'width',type:'number',hideFromUI:true,helperText:'Width %, e.g. set to 50 to fill half of the space'},{name:'link',type:'url',helperText:'Optionally set a url that clicking this column will link to'}],defaultValue:[{blocks:[{'@type':'@builder.io/sdk:Element',responsiveStyles:{large:{display:'flex',flexDirection:'column',alignItems:'stretch',flexShrink:'0',position:'relative',marginTop:'30px',textAlign:'center',lineHeight:'normal',height:'auto',minHeight:'20px',minWidth:'20px',overflow:'hidden'}},component:{name:'Image',options:{image:'https://builder.io/api/v1/image/assets%2Fpwgjf0RoYWbdnJSbpBAjXNRMe9F2%2Ffb27a7c790324294af8be1c35fe30f4d',backgroundPosition:'center',backgroundSize:'cover',aspectRatio:0.7004048582995948}}},{'@type':'@builder.io/sdk:Element',responsiveStyles:{large:{display:'flex',flexDirection:'column',alignItems:'stretch',flexShrink:'0',position:'relative',marginTop:'30px',textAlign:'center',lineHeight:'normal',height:'auto'}},component:{name:'Text',options:{text:'<p>Enter some text...</p>'}}}]},{blocks:[{'@type':'@builder.io/sdk:Element',responsiveStyles:{large:{display:'flex',flexDirection:'column',alignItems:'stretch',flexShrink:'0',position:'relative',marginTop:'30px',textAlign:'center',lineHeight:'normal',height:'auto',minHeight:'20px',minWidth:'20px',overflow:'hidden'}},component:{name:'Image',options:{image:'https://builder.io/api/v1/image/assets%2Fpwgjf0RoYWbdnJSbpBAjXNRMe9F2%2Ffb27a7c790324294af8be1c35fe30f4d',backgroundPosition:'center',backgroundSize:'cover',aspectRatio:0.7004048582995948}}},{'@type':'@builder.io/sdk:Element',responsiveStyles:{large:{display:'flex',flexDirection:'column',alignItems:'stretch',flexShrink:'0',position:'relative',marginTop:'30px',textAlign:'center',lineHeight:'normal',height:'auto'}},component:{name:'Text',options:{text:'<p>Enter some text...</p>'}}}]}],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(); } } } } "},{name:'space',type:'number',defaultValue:20,helperText:'Size of gap between columns',advanced:true},{name:'stackColumnsAt',type:'string',defaultValue:'tablet',helperText:'Convert horizontal columns to vertical at what device size',enum:['tablet','mobile','never'],advanced:true},{name:'reverseColumnsWhenStacked',type:'boolean',defaultValue:false,helperText:'When stacking columns for mobile devices, reverse the ordering',advanced:true}]});
@@ -1,41 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
- import { useState, useContext } from "react";
4
- import RenderBlocks from "../components/render-blocks.lite";
5
-
6
- export default function Columns(props) {
7
- function getGutterSize() {
8
- return typeof props.space === "number" ? props.space || 0 : 20;
9
- }
10
-
11
- function getColumns() {
12
- return props.columns || [];
13
- }
14
-
15
- function getWidth(index) {
16
- const columns = this.getColumns();
17
- return (columns[index] && columns[index].width) || 100 / columns.length;
18
- }
19
-
20
- function getColumnCssWidth(index) {
21
- const columns = this.getColumns();
22
- const gutterSize = this.getGutterSize();
23
- const subtractWidth = (gutterSize * (columns.length - 1)) / columns.length;
24
- return `calc(${this.getWidth(index)}% - ${subtractWidth}px)`;
25
- }
26
-
27
- return (
28
- <View className="builder-columns" style={styles.view1}>
29
- {props.columns.map((column) => (
30
- <View className="builder-column" style={styles.view2}>
31
- <RenderBlocks blocks={column.blocks} />
32
- </View>
33
- ))}
34
- </View>
35
- );
36
- }
37
-
38
- const styles = StyleSheet.create({
39
- view1: { display: "flex", flexDirection: "column", alignItems: "stretch" },
40
- view2: { flexGrow: 1 },
41
- });
@@ -1,56 +0,0 @@
1
- import { registerComponent } from '../functions/register-component';
2
-
3
- import * as React from "react";
4
- import { View } from "react-native";
5
- import { useState, useRef, useEffect } from "react";
6
- function CustomCode(props) {
7
- const [scriptsInserted, setScriptsInserted] = useState(() => []);
8
- const [scriptsRun, setScriptsRun] = useState(() => []);
9
- function findAndRunScripts() {
10
- if (elem.current && typeof window !== "undefined") {
11
- const scripts = elem.current.getElementsByTagName("script");
12
- for (let i = 0; i < scripts.length; i++) {
13
- const script = scripts[i];
14
- if (script.src) {
15
- if (scriptsInserted.includes(script.src)) {
16
- continue;
17
- }
18
- scriptsInserted.push(script.src);
19
- const newScript = document.createElement("script");
20
- newScript.async = true;
21
- newScript.src = script.src;
22
- document.head.appendChild(newScript);
23
- } else if (!script.type || [
24
- "text/javascript",
25
- "application/javascript",
26
- "application/ecmascript"
27
- ].includes(script.type)) {
28
- if (scriptsRun.includes(script.innerText)) {
29
- continue;
30
- }
31
- try {
32
- scriptsRun.push(script.innerText);
33
- new Function(script.innerText)();
34
- } catch (error) {
35
- console.warn("`CustomCode`: Error running script:", error);
36
- }
37
- }
38
- }
39
- }
40
- }
41
- const elem = useRef();
42
- useEffect(() => {
43
- findAndRunScripts();
44
- }, []);
45
- return /* @__PURE__ */ React.createElement(View, {
46
- ref: elem,
47
- className: "builder-custom-code" + (props.replaceNodes ? " replace-nodes" : ""),
48
- dangerouslySetInnerHTML: { __html: "props.code" }
49
- });
50
- }
51
- export {
52
- CustomCode as default
53
- };
54
-
55
-
56
- registerComponent(CustomCode, {name:'Custom Code',static:true,requiredPermissions:['editCode'],inputs:[{name:'code',type:'html',required:true,defaultValue:'<p>Hello there, I am custom HTML code!</p>',code:true},{name:'replaceNodes',type:'boolean',helperText:'Preserve server rendered dom nodes',advanced:true},{name:'scriptsClientOnly',type:'boolean',defaultValue:false,helperText:'Only print and run scripts on the client. Important when scripts influence DOM that could be replaced when client loads',advanced:true}]});
@@ -1,56 +0,0 @@
1
- import { registerComponent } from '../functions/register-component';
2
-
3
- import * as React from "react";
4
- import { View } from "react-native";
5
- import { useState, useRef, useEffect } from "react";
6
- function Embed(props) {
7
- const [scriptsInserted, setScriptsInserted] = useState(() => []);
8
- const [scriptsRun, setScriptsRun] = useState(() => []);
9
- function findAndRunScripts() {
10
- if (elem.current && typeof window !== "undefined") {
11
- const scripts = elem.current.getElementsByTagName("script");
12
- for (let i = 0; i < scripts.length; i++) {
13
- const script = scripts[i];
14
- if (script.src) {
15
- if (scriptsInserted.includes(script.src)) {
16
- continue;
17
- }
18
- scriptsInserted.push(script.src);
19
- const newScript = document.createElement("script");
20
- newScript.async = true;
21
- newScript.src = script.src;
22
- document.head.appendChild(newScript);
23
- } else if (!script.type || [
24
- "text/javascript",
25
- "application/javascript",
26
- "application/ecmascript"
27
- ].includes(script.type)) {
28
- if (scriptsRun.includes(script.innerText)) {
29
- continue;
30
- }
31
- try {
32
- scriptsRun.push(script.innerText);
33
- new Function(script.innerText)();
34
- } catch (error) {
35
- console.warn("`Embed`: Error running script:", error);
36
- }
37
- }
38
- }
39
- }
40
- }
41
- const elem = useRef();
42
- useEffect(() => {
43
- findAndRunScripts();
44
- }, []);
45
- return /* @__PURE__ */ React.createElement(View, {
46
- className: "builder-embed",
47
- ref: elem,
48
- dangerouslySetInnerHTML: { __html: "props.content" }
49
- });
50
- }
51
- export {
52
- Embed as default
53
- };
54
-
55
-
56
- registerComponent(Embed, {name:'Embed',static:true,inputs:[{name:'url',type:'url',required:true,defaultValue:'',helperText:'e.g. enter a youtube url, google map, etc',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'); } "},{name:'content',type:'html',defaultValue:'<div style="padding: 20px; text-align: center">(Choose an embed URL)<div>',hideFromUI:true}]});
@@ -1,65 +0,0 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
- import { useState, useContext, 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
60
- className="builder-embed"
61
- ref={elem}
62
- dangerouslySetInnerHTML={{ __html: "props.content" }}
63
- />
64
- );
65
- }