@builder.io/sdk-react-native 0.0.1-4 → 0.0.1-49

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 (90) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +15 -0
  3. package/package.json +6 -4
  4. package/src/blocks/button.js +73 -24
  5. package/src/blocks/button.lite.tsx +10 -14
  6. package/src/blocks/columns.js +286 -40
  7. package/src/blocks/columns.lite.tsx +43 -20
  8. package/src/blocks/custom-code.js +74 -47
  9. package/src/blocks/custom-code.lite.tsx +11 -19
  10. package/src/blocks/embed.js +68 -47
  11. package/src/blocks/embed.lite.tsx +11 -15
  12. package/src/blocks/form.js +490 -198
  13. package/src/blocks/form.lite.tsx +54 -58
  14. package/src/blocks/fragment.js +21 -0
  15. package/src/blocks/fragment.lite.tsx +10 -0
  16. package/src/blocks/image.js +125 -83
  17. package/src/blocks/image.lite.tsx +46 -14
  18. package/src/blocks/img.js +51 -28
  19. package/src/blocks/img.lite.tsx +6 -7
  20. package/src/blocks/input.js +100 -28
  21. package/src/blocks/input.lite.tsx +4 -7
  22. package/src/blocks/raw-text.js +12 -12
  23. package/src/blocks/raw-text.lite.tsx +3 -9
  24. package/src/blocks/section.js +71 -23
  25. package/src/blocks/section.lite.tsx +4 -5
  26. package/src/blocks/select.js +78 -27
  27. package/src/blocks/select.lite.tsx +8 -9
  28. package/src/blocks/submit-button.js +47 -21
  29. package/src/blocks/submit-button.lite.tsx +3 -4
  30. package/src/blocks/symbol.js +16 -16
  31. package/src/blocks/symbol.lite.tsx +6 -6
  32. package/src/blocks/text.js +85 -16
  33. package/src/blocks/text.lite.tsx +3 -9
  34. package/src/blocks/textarea.js +60 -24
  35. package/src/blocks/textarea.lite.tsx +2 -3
  36. package/src/blocks/video.js +97 -46
  37. package/src/blocks/video.lite.tsx +5 -6
  38. package/src/components/block-styles.js +5 -0
  39. package/src/components/block-styles.lite.tsx +6 -0
  40. package/src/components/error-boundary.js +27 -0
  41. package/src/components/error-boundary.lite.tsx +6 -0
  42. package/src/components/render-block.js +119 -39
  43. package/src/components/render-block.lite.tsx +76 -36
  44. package/src/components/render-blocks.js +65 -32
  45. package/src/components/render-blocks.lite.tsx +25 -16
  46. package/src/components/render-content.js +190 -36
  47. package/src/components/render-content.lite.tsx +143 -32
  48. package/src/constants/device-sizes.js +8 -11
  49. package/src/context/builder.context.js +2 -4
  50. package/src/functions/evaluate.js +18 -9
  51. package/src/functions/event-handler-name.js +6 -0
  52. package/src/functions/get-block-actions.js +13 -13
  53. package/src/functions/get-block-component-options.js +27 -4
  54. package/src/functions/get-block-properties.js +23 -16
  55. package/src/functions/get-block-styles.js +56 -9
  56. package/src/functions/get-block-tag.js +2 -4
  57. package/src/functions/get-builder-search-params/fn.test.js +18 -0
  58. package/src/functions/get-builder-search-params/index.js +20 -0
  59. package/src/functions/get-content/fn.test.js +34 -0
  60. package/src/functions/get-content/index.js +156 -0
  61. package/src/functions/get-fetch.js +11 -0
  62. package/src/functions/get-global-this.js +17 -0
  63. package/src/functions/get-processed-block.js +19 -13
  64. package/src/functions/get-processed-block.test.js +32 -16
  65. package/src/functions/get-target.js +3 -5
  66. package/src/functions/if-target.js +1 -3
  67. package/src/functions/is-browser.js +2 -5
  68. package/src/functions/is-editing.js +5 -5
  69. package/src/functions/is-iframe.js +2 -4
  70. package/src/functions/is-previewing.js +13 -0
  71. package/src/functions/is-react-native.js +2 -4
  72. package/src/functions/macro-eval.js +2 -5
  73. package/src/functions/on-change.js +4 -7
  74. package/src/functions/on-change.test.js +10 -10
  75. package/src/functions/previewing-model-name.js +10 -0
  76. package/src/functions/register-component.js +39 -27
  77. package/src/functions/register.js +28 -0
  78. package/src/functions/set-editor-settings.js +14 -0
  79. package/src/functions/set.js +14 -5
  80. package/src/functions/set.test.js +14 -14
  81. package/src/functions/track.js +7 -9
  82. package/src/functions/transform-block.js +42 -0
  83. package/src/index-helpers/blocks-exports.js +19 -0
  84. package/src/index-helpers/top-of-file.js +2 -0
  85. package/src/index.js +10 -21
  86. package/src/scripts/init-editing.js +67 -29
  87. package/src/types/deep-partial.js +1 -0
  88. package/index.js +0 -11
  89. package/src/functions/get-content.js +0 -103
  90. package/src/package.json +0 -18
package/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ ### UPCOMING
2
+
3
+ - Add `getBuilderSearchParams` helper export to easily view current drafts on your production site.
4
+
5
+ ### 0.0.1-44
6
+
7
+ Changes:
8
+
9
+ - Fixes `getAllContent` to traverse all nested data from symbols/references https://github.com/BuilderIO/builder/pull/718
10
+ - Fixes `getContent` (broken due to missing URL polyfill) https://github.com/BuilderIO/builder/pull/880
11
+ - Strips invalid `this.` left from Mitosis compilation https://github.com/BuilderIO/builder/pull/717/commits/b1947c86db769f74a7408965dac70f22dfcc538d
12
+ - Fix identification of react-native environment https://github.com/BuilderIO/builder/pull/717/commits/9d2a207ceca39bf83d5bbdc4bd67351e86105d78
13
+ - Fix Aspect Ratio handling (this adds support for Pixel Tracking) https://github.com/BuilderIO/builder/pull/749, preceeded by https://github.com/BuilderIO/builder/pull/687
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # Builder.io React-native SDK (BETA)
2
+
3
+ This is the React-Native SDK. It is currently in beta.
4
+
5
+ ## Feature Support
6
+
7
+ To check the status of the SDK, look at [these tables](../../README.md#feature-implementation).
8
+
9
+ ## Getting Started
10
+
11
+ ```
12
+ npm install @builder.io/sdk-react-native@dev
13
+ ```
14
+
15
+ Take a look at [our example repo](/examples/react-native) for how to use this SDK.
package/package.json CHANGED
@@ -1,18 +1,20 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-react-native",
3
3
  "description": "Builder.io SDK for React Native",
4
- "version": "0.0.1-4",
4
+ "version": "0.0.1-49",
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"
8
8
  },
9
9
  "dependencies": {
10
- "react-native-render-html": "^5.1.1"
10
+ "react-native-render-html": "^6.3.4",
11
+ "react-native-video": "^5.1.1"
11
12
  },
12
13
  "peerDependencies": {
13
- "react-native": "^0.64.2"
14
+ "react-native": "^0.64.3"
14
15
  },
15
16
  "devDependencies": {
16
- "react-native": "^0.64.2"
17
+ "@types/react-native-video": "^5.0.9",
18
+ "react-native": "^0.64.3"
17
19
  }
18
20
  }
@@ -1,37 +1,86 @@
1
1
  import { registerComponent } from '../functions/register-component';
2
2
 
3
- var __defProp = Object.defineProperty;
3
+ var __defProp = Object.defineProperty;
4
4
  var __defProps = Object.defineProperties;
5
5
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
6
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
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;
9
+ var __defNormalProp = (obj, key, value) =>
10
+ key in obj
11
+ ? __defProp(obj, key, {
12
+ enumerable: true,
13
+ configurable: true,
14
+ writable: true,
15
+ value,
16
+ })
17
+ : (obj[key] = value);
10
18
  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;
19
+ for (var prop in b || (b = {}))
20
+ if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
21
+ if (__getOwnPropSymbols)
22
+ for (var prop of __getOwnPropSymbols(b)) {
23
+ if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
24
+ }
25
+ return a;
20
26
  };
21
27
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
22
- import * as React from "react";
23
- import { View } from "react-native";
28
+ import * as React from 'react';
29
+ import { View, Text } from 'react-native';
24
30
  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
+ return /* @__PURE__ */ React.createElement(
32
+ React.Fragment,
33
+ null,
34
+ props.link
35
+ ? /* @__PURE__ */ React.createElement(
36
+ React.Fragment,
37
+ null,
38
+ /* @__PURE__ */ React.createElement(
39
+ View,
40
+ __spreadProps(__spreadValues({}, props.attributes), {
41
+ role: 'button',
42
+ href: props.link,
43
+ target: props.openLinkInNewTab ? '_blank' : void 0,
44
+ }),
45
+ /* @__PURE__ */ React.createElement(Text, null, props.text)
46
+ )
47
+ )
48
+ : /* @__PURE__ */ React.createElement(
49
+ View,
50
+ __spreadValues({}, props.attributes),
51
+ /* @__PURE__ */ React.createElement(Text, null, props.text)
52
+ )
53
+ );
31
54
  }
32
- export {
33
- Button as default
34
- };
35
-
55
+ export { Button as default };
36
56
 
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});
57
+ registerComponent(Button, {
58
+ name: 'Core:Button',
59
+ builtIn: true,
60
+ image:
61
+ 'https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2F81a15681c3e74df09677dfc57a615b13',
62
+ defaultStyles: {
63
+ appearance: 'none',
64
+ paddingTop: '15px',
65
+ paddingBottom: '15px',
66
+ paddingLeft: '25px',
67
+ paddingRight: '25px',
68
+ backgroundColor: '#000000',
69
+ color: 'white',
70
+ borderRadius: '4px',
71
+ textAlign: 'center',
72
+ cursor: 'pointer',
73
+ },
74
+ inputs: [
75
+ { name: 'text', type: 'text', defaultValue: 'Click me!', bubble: true },
76
+ { name: 'link', type: 'url', bubble: true },
77
+ {
78
+ name: 'openLinkInNewTab',
79
+ type: 'boolean',
80
+ defaultValue: false,
81
+ friendlyName: 'Open link in new tab',
82
+ },
83
+ ],
84
+ static: true,
85
+ noWrap: true,
86
+ });
@@ -1,28 +1,24 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
- import { useContext } from "react";
1
+ import * as React from 'react';
2
+ import { View, StyleSheet, Image, Text } from 'react-native';
4
3
 
5
4
  export default function Button(props) {
6
5
  return (
7
6
  <>
8
- {props.link && (
7
+ {props.link ? (
9
8
  <>
10
9
  <View
11
10
  {...props.attributes}
11
+ role="button"
12
12
  href={props.link}
13
- target={props.openLinkInNewTab ? "_blank" : undefined}
13
+ target={props.openLinkInNewTab ? '_blank' : undefined}
14
14
  >
15
- {props.text}
16
- </View>
17
- </>
18
- )}
19
-
20
- {!props.link && (
21
- <>
22
- <View {...props.attributes} type="button">
23
- {props.text}
15
+ <Text>{props.text}</Text>
24
16
  </View>
25
17
  </>
18
+ ) : (
19
+ <View {...props.attributes}>
20
+ <Text>{props.text}</Text>
21
+ </View>
26
22
  )}
27
23
  </>
28
24
  );
@@ -1,47 +1,293 @@
1
1
  import { registerComponent } from '../functions/register-component';
2
2
 
3
- import * as React from "react";
4
- import { View, StyleSheet } from "react-native";
5
- import RenderBlocks from "../components/render-blocks";
3
+ import * as React from 'react';
4
+ import { View, StyleSheet } from 'react-native';
5
+ import RenderBlocks from '../components/render-blocks';
6
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
- }))));
7
+ var _a;
8
+ function getGutterSize() {
9
+ return typeof props.space === 'number' ? props.space || 0 : 20;
10
+ }
11
+ function getColumns() {
12
+ return props.columns || [];
13
+ }
14
+ function getWidth(index) {
15
+ var _a2;
16
+ const columns = getColumns();
17
+ return (
18
+ ((_a2 = columns[index]) == null ? void 0 : _a2.width) ||
19
+ 100 / columns.length
20
+ );
21
+ }
22
+ function getColumnCssWidth(index) {
23
+ const columns = getColumns();
24
+ const gutterSize = getGutterSize();
25
+ const subtractWidth = (gutterSize * (columns.length - 1)) / columns.length;
26
+ return `calc(${getWidth(index)}% - ${subtractWidth}px)`;
27
+ }
28
+ function maybeApplyForTablet(prop) {
29
+ const stackColumnsAt = props.stackColumnsAt || 'tablet';
30
+ return stackColumnsAt === 'tablet' ? prop : 'inherit';
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
+ function columnCssVars() {
45
+ const width = '100%';
46
+ const marginLeft = '0';
47
+ return {
48
+ '--column-width': width,
49
+ '--column-margin-left': marginLeft,
50
+ '--column-width-tablet': maybeApplyForTablet(width),
51
+ '--column-margin-left-tablet': maybeApplyForTablet(marginLeft),
52
+ };
53
+ }
54
+ return /* @__PURE__ */ React.createElement(
55
+ View,
56
+ {
57
+ style: styles.view1,
58
+ },
59
+ (_a = props.columns) == null
60
+ ? void 0
61
+ : _a.map((column) =>
62
+ /* @__PURE__ */ React.createElement(
63
+ View,
64
+ {
65
+ style: styles.view2,
66
+ },
67
+ /* @__PURE__ */ React.createElement(RenderBlocks, {
68
+ blocks: column.blocks,
69
+ })
70
+ )
71
+ )
72
+ );
32
73
  }
33
74
  const styles = StyleSheet.create({
34
- view1: {
35
- display: "flex",
36
- flexDirection: "column",
37
- alignItems: "stretch",
38
- lineHeight: "normal"
39
- },
40
- view2: { flexGrow: "1" }
75
+ view1: { display: 'flex', alignItems: 'stretch' },
76
+ view2: { flexGrow: 1 },
41
77
  });
42
- export {
43
- Columns as default
44
- };
45
-
78
+ export { Columns as default };
46
79
 
47
- 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}]});
80
+ registerComponent(Columns, {
81
+ name: 'Columns',
82
+ builtIn: true,
83
+ inputs: [
84
+ {
85
+ name: 'columns',
86
+ type: 'array',
87
+ broadcast: true,
88
+ subFields: [
89
+ {
90
+ name: 'blocks',
91
+ type: 'array',
92
+ hideFromUI: true,
93
+ defaultValue: [
94
+ {
95
+ '@type': '@builder.io/sdk:Element',
96
+ responsiveStyles: {
97
+ large: {
98
+ display: 'flex',
99
+ flexDirection: 'column',
100
+ alignItems: 'stretch',
101
+ flexShrink: '0',
102
+ position: 'relative',
103
+ marginTop: '30px',
104
+ textAlign: 'center',
105
+ lineHeight: 'normal',
106
+ height: 'auto',
107
+ minHeight: '20px',
108
+ minWidth: '20px',
109
+ overflow: 'hidden',
110
+ },
111
+ },
112
+ component: {
113
+ name: 'Image',
114
+ options: {
115
+ image:
116
+ 'https://builder.io/api/v1/image/assets%2Fpwgjf0RoYWbdnJSbpBAjXNRMe9F2%2Ffb27a7c790324294af8be1c35fe30f4d',
117
+ backgroundPosition: 'center',
118
+ backgroundSize: 'cover',
119
+ aspectRatio: 0.7004048582995948,
120
+ },
121
+ },
122
+ },
123
+ {
124
+ '@type': '@builder.io/sdk:Element',
125
+ responsiveStyles: {
126
+ large: {
127
+ display: 'flex',
128
+ flexDirection: 'column',
129
+ alignItems: 'stretch',
130
+ flexShrink: '0',
131
+ position: 'relative',
132
+ marginTop: '30px',
133
+ textAlign: 'center',
134
+ lineHeight: 'normal',
135
+ height: 'auto',
136
+ },
137
+ },
138
+ component: {
139
+ name: 'Text',
140
+ options: { text: '<p>Enter some text...</p>' },
141
+ },
142
+ },
143
+ ],
144
+ },
145
+ {
146
+ name: 'width',
147
+ type: 'number',
148
+ hideFromUI: true,
149
+ helperText: 'Width %, e.g. set to 50 to fill half of the space',
150
+ },
151
+ {
152
+ name: 'link',
153
+ type: 'url',
154
+ helperText:
155
+ 'Optionally set a url that clicking this column will link to',
156
+ },
157
+ ],
158
+ defaultValue: [
159
+ {
160
+ blocks: [
161
+ {
162
+ '@type': '@builder.io/sdk:Element',
163
+ responsiveStyles: {
164
+ large: {
165
+ display: 'flex',
166
+ flexDirection: 'column',
167
+ alignItems: 'stretch',
168
+ flexShrink: '0',
169
+ position: 'relative',
170
+ marginTop: '30px',
171
+ textAlign: 'center',
172
+ lineHeight: 'normal',
173
+ height: 'auto',
174
+ minHeight: '20px',
175
+ minWidth: '20px',
176
+ overflow: 'hidden',
177
+ },
178
+ },
179
+ component: {
180
+ name: 'Image',
181
+ options: {
182
+ image:
183
+ 'https://builder.io/api/v1/image/assets%2Fpwgjf0RoYWbdnJSbpBAjXNRMe9F2%2Ffb27a7c790324294af8be1c35fe30f4d',
184
+ backgroundPosition: 'center',
185
+ backgroundSize: 'cover',
186
+ aspectRatio: 0.7004048582995948,
187
+ },
188
+ },
189
+ },
190
+ {
191
+ '@type': '@builder.io/sdk:Element',
192
+ responsiveStyles: {
193
+ large: {
194
+ display: 'flex',
195
+ flexDirection: 'column',
196
+ alignItems: 'stretch',
197
+ flexShrink: '0',
198
+ position: 'relative',
199
+ marginTop: '30px',
200
+ textAlign: 'center',
201
+ lineHeight: 'normal',
202
+ height: 'auto',
203
+ },
204
+ },
205
+ component: {
206
+ name: 'Text',
207
+ options: { text: '<p>Enter some text...</p>' },
208
+ },
209
+ },
210
+ ],
211
+ },
212
+ {
213
+ blocks: [
214
+ {
215
+ '@type': '@builder.io/sdk:Element',
216
+ responsiveStyles: {
217
+ large: {
218
+ display: 'flex',
219
+ flexDirection: 'column',
220
+ alignItems: 'stretch',
221
+ flexShrink: '0',
222
+ position: 'relative',
223
+ marginTop: '30px',
224
+ textAlign: 'center',
225
+ lineHeight: 'normal',
226
+ height: 'auto',
227
+ minHeight: '20px',
228
+ minWidth: '20px',
229
+ overflow: 'hidden',
230
+ },
231
+ },
232
+ component: {
233
+ name: 'Image',
234
+ options: {
235
+ image:
236
+ 'https://builder.io/api/v1/image/assets%2Fpwgjf0RoYWbdnJSbpBAjXNRMe9F2%2Ffb27a7c790324294af8be1c35fe30f4d',
237
+ backgroundPosition: 'center',
238
+ backgroundSize: 'cover',
239
+ aspectRatio: 0.7004048582995948,
240
+ },
241
+ },
242
+ },
243
+ {
244
+ '@type': '@builder.io/sdk:Element',
245
+ responsiveStyles: {
246
+ large: {
247
+ display: 'flex',
248
+ flexDirection: 'column',
249
+ alignItems: 'stretch',
250
+ flexShrink: '0',
251
+ position: 'relative',
252
+ marginTop: '30px',
253
+ textAlign: 'center',
254
+ lineHeight: 'normal',
255
+ height: 'auto',
256
+ },
257
+ },
258
+ component: {
259
+ name: 'Text',
260
+ options: { text: '<p>Enter some text...</p>' },
261
+ },
262
+ },
263
+ ],
264
+ },
265
+ ],
266
+ onChange:
267
+ " 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(); } } } } ",
268
+ },
269
+ {
270
+ name: 'space',
271
+ type: 'number',
272
+ defaultValue: 20,
273
+ helperText: 'Size of gap between columns',
274
+ advanced: true,
275
+ },
276
+ {
277
+ name: 'stackColumnsAt',
278
+ type: 'string',
279
+ defaultValue: 'tablet',
280
+ helperText: 'Convert horizontal columns to vertical at what device size',
281
+ enum: ['tablet', 'mobile', 'never'],
282
+ advanced: true,
283
+ },
284
+ {
285
+ name: 'reverseColumnsWhenStacked',
286
+ type: 'boolean',
287
+ defaultValue: false,
288
+ helperText:
289
+ 'When stacking columns for mobile devices, reverse the ordering',
290
+ advanced: true,
291
+ },
292
+ ],
293
+ });
@@ -1,11 +1,10 @@
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";
1
+ import * as React from 'react';
2
+ import { View, StyleSheet, Image, Text } from 'react-native';
3
+ import RenderBlocks from '../components/render-blocks.lite';
5
4
 
6
5
  export default function Columns(props) {
7
6
  function getGutterSize() {
8
- return typeof props.space === "number" ? props.space || 0 : 20;
7
+ return typeof props.space === 'number' ? props.space || 0 : 20;
9
8
  }
10
9
 
11
10
  function getColumns() {
@@ -13,21 +12,50 @@ export default function Columns(props) {
13
12
  }
14
13
 
15
14
  function getWidth(index) {
16
- const columns = this.getColumns();
17
- return (columns[index] && columns[index].width) || 100 / columns.length;
15
+ const columns = getColumns();
16
+ return columns[index]?.width || 100 / columns.length;
18
17
  }
19
18
 
20
19
  function getColumnCssWidth(index) {
21
- const columns = this.getColumns();
22
- const gutterSize = this.getGutterSize();
20
+ const columns = getColumns();
21
+ const gutterSize = getGutterSize();
23
22
  const subtractWidth = (gutterSize * (columns.length - 1)) / columns.length;
24
- return `calc(${this.getWidth(index)}% - ${subtractWidth}px)`;
23
+ return `calc(${getWidth(index)}% - ${subtractWidth}px)`;
24
+ }
25
+
26
+ function maybeApplyForTablet(prop) {
27
+ const stackColumnsAt = props.stackColumnsAt || 'tablet';
28
+ return stackColumnsAt === 'tablet' ? prop : 'inherit';
29
+ }
30
+
31
+ function columnsCssVars() {
32
+ const flexDir =
33
+ props.stackColumnsAt === 'never'
34
+ ? 'inherit'
35
+ : props.reverseColumnsWhenStacked
36
+ ? 'column-reverse'
37
+ : 'column';
38
+ return {
39
+ '--flex-dir': flexDir,
40
+ '--flex-dir-tablet': maybeApplyForTablet(flexDir),
41
+ };
42
+ }
43
+
44
+ function columnCssVars() {
45
+ const width = '100%';
46
+ const marginLeft = '0';
47
+ return {
48
+ '--column-width': width,
49
+ '--column-margin-left': marginLeft,
50
+ '--column-width-tablet': maybeApplyForTablet(width),
51
+ '--column-margin-left-tablet': maybeApplyForTablet(marginLeft),
52
+ };
25
53
  }
26
54
 
27
55
  return (
28
- <View className="builder-columns" style={styles.view1}>
29
- {props.columns.map((column) => (
30
- <View className="builder-column" style={styles.view2}>
56
+ <View style={styles.view1}>
57
+ {props.columns?.map((column) => (
58
+ <View style={styles.view2}>
31
59
  <RenderBlocks blocks={column.blocks} />
32
60
  </View>
33
61
  ))}
@@ -36,11 +64,6 @@ export default function Columns(props) {
36
64
  }
37
65
 
38
66
  const styles = StyleSheet.create({
39
- view1: {
40
- display: "flex",
41
- flexDirection: "column",
42
- alignItems: "stretch",
43
- lineHeight: "normal",
44
- },
45
- view2: { flexGrow: "1" },
67
+ view1: { display: 'flex', alignItems: 'stretch' },
68
+ view2: { flexGrow: 1 },
46
69
  });