@builder.io/sdk-react-native 0.0.1-6 → 0.0.1-60
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.
- package/CHANGELOG.md +42 -0
- package/README.md +19 -0
- package/package.json +6 -4
- package/src/blocks/button/button.js +31 -0
- package/src/blocks/button/component-info.js +42 -0
- package/src/blocks/columns/columns.js +59 -0
- package/src/blocks/columns/component-info.js +218 -0
- package/src/blocks/custom-code/component-info.js +32 -0
- package/src/blocks/{custom-code.lite.tsx → custom-code/custom-code.js} +16 -33
- package/src/blocks/embed/component-info.js +25 -0
- package/src/blocks/{embed.lite.tsx → embed/embed.js} +16 -31
- package/src/blocks/form/component-info.js +263 -0
- package/src/blocks/form/form.js +221 -0
- package/src/blocks/fragment/component-info.js +12 -0
- package/src/blocks/fragment/fragment.js +8 -0
- package/src/blocks/{image.js → image/component-info.js} +5 -23
- package/src/blocks/image/image.js +41 -0
- package/src/blocks/img/component-info.js +21 -0
- package/src/blocks/img/img.js +36 -0
- package/src/blocks/input/component-info.js +75 -0
- package/src/blocks/input/input.js +36 -0
- package/src/blocks/raw-text/component-info.js +17 -0
- package/src/blocks/raw-text/raw-text.js +10 -0
- package/src/blocks/section/component-info.js +50 -0
- package/src/blocks/section/section.js +31 -0
- package/src/blocks/select/component-info.js +60 -0
- package/src/blocks/select/select.js +36 -0
- package/src/blocks/submit-button/component-info.js +29 -0
- package/src/blocks/submit-button/submit-button.js +29 -0
- package/src/blocks/symbol/component-info.js +44 -0
- package/src/blocks/symbol/symbol.js +68 -0
- package/src/blocks/{text.js → text/component-info.js} +4 -10
- package/src/blocks/text/text.js +65 -0
- package/src/blocks/textarea/component-info.js +48 -0
- package/src/blocks/textarea/textarea.js +32 -0
- package/src/blocks/video/component-info.js +107 -0
- package/src/blocks/video/video.js +33 -0
- package/src/components/render-block/block-styles.js +40 -0
- package/src/components/render-block/render-block.helpers.js +24 -0
- package/src/components/render-block/render-block.js +171 -0
- package/src/components/render-block/render-component.js +33 -0
- package/src/components/render-block/render-repeated-block.js +29 -0
- package/src/components/render-blocks.js +23 -12
- package/src/components/render-content/components/render-styles.js +58 -0
- package/src/components/render-content/index.js +5 -0
- package/src/components/render-content/render-content.js +254 -0
- package/src/components/render-inlined-styles.js +18 -0
- package/src/constants/builder-registered-components.js +43 -0
- package/src/constants/device-sizes.js +3 -21
- package/src/constants/target.js +5 -0
- package/src/context/builder.context.js +7 -1
- package/src/functions/camel-to-kebab-case.js +5 -0
- package/src/functions/convert-style-object.js +7 -0
- package/src/functions/evaluate.js +17 -8
- package/src/functions/event-handler-name.js +8 -0
- package/src/functions/fast-clone.js +5 -0
- package/src/functions/get-block-actions.js +14 -13
- package/src/functions/get-block-component-options.js +22 -1
- package/src/functions/get-block-properties.js +2 -3
- package/src/functions/get-block-styles.js +9 -19
- package/src/functions/get-builder-search-params/fn.test.js +14 -0
- package/src/functions/get-builder-search-params/index.js +23 -0
- package/src/functions/get-content/fn.test.js +32 -0
- package/src/functions/get-content/index.js +139 -0
- package/src/functions/get-fetch.js +35 -0
- package/src/functions/get-global-this.js +19 -0
- package/src/functions/get-processed-block.js +18 -9
- package/src/functions/get-processed-block.test.js +14 -8
- package/src/functions/if-target.js +11 -2
- package/src/functions/is-browser.js +1 -2
- package/src/functions/is-editing.js +1 -1
- package/src/functions/is-iframe.js +1 -1
- package/src/functions/is-previewing.js +15 -0
- package/src/functions/is-react-native.js +1 -1
- package/src/functions/on-change.test.js +1 -2
- package/src/functions/previewing-model-name.js +12 -0
- package/src/functions/register-component.js +31 -13
- package/src/functions/register.js +30 -0
- package/src/functions/sanitize-styles.js +33 -0
- package/src/functions/set-editor-settings.js +16 -0
- package/src/functions/set.test.js +1 -2
- package/src/functions/track.js +7 -3
- package/src/functions/transform-block.js +38 -0
- package/src/helpers/css.js +13 -0
- package/src/index-helpers/blocks-exports.js +19 -0
- package/src/index-helpers/top-of-file.js +2 -0
- package/src/index.js +10 -23
- package/src/scripts/init-editing.js +73 -49
- package/src/types/components.js +1 -0
- package/src/types/deep-partial.js +1 -0
- package/src/types/element.js +1 -0
- package/src/types/targets.js +1 -0
- package/src/types/typescript.js +1 -0
- package/index.js +0 -11
- package/src/blocks/button.js +0 -37
- package/src/blocks/button.lite.tsx +0 -29
- package/src/blocks/columns.js +0 -42
- package/src/blocks/columns.lite.tsx +0 -41
- package/src/blocks/custom-code.js +0 -56
- package/src/blocks/embed.js +0 -56
- package/src/blocks/form.js +0 -229
- package/src/blocks/form.lite.tsx +0 -257
- package/src/blocks/image.lite.tsx +0 -35
- package/src/blocks/img.js +0 -41
- package/src/blocks/img.lite.tsx +0 -19
- package/src/blocks/input.js +0 -41
- package/src/blocks/input.lite.tsx +0 -23
- package/src/blocks/raw-text.js +0 -17
- package/src/blocks/raw-text.lite.tsx +0 -12
- package/src/blocks/section.js +0 -36
- package/src/blocks/section.lite.tsx +0 -20
- package/src/blocks/select.js +0 -40
- package/src/blocks/select.lite.tsx +0 -24
- package/src/blocks/submit-button.js +0 -34
- package/src/blocks/submit-button.lite.tsx +0 -11
- package/src/blocks/symbol.js +0 -20
- package/src/blocks/symbol.lite.tsx +0 -20
- package/src/blocks/text.lite.tsx +0 -12
- package/src/blocks/textarea.js +0 -37
- package/src/blocks/textarea.lite.tsx +0 -15
- package/src/blocks/video.js +0 -49
- package/src/blocks/video.lite.tsx +0 -28
- package/src/components/render-block.js +0 -84
- package/src/components/render-block.lite.tsx +0 -92
- package/src/components/render-blocks.lite.tsx +0 -56
- package/src/components/render-content.js +0 -66
- package/src/components/render-content.lite.tsx +0 -95
- package/src/functions/get-content.js +0 -103
- package/src/functions/get-target.js +0 -7
- package/src/functions/macro-eval.js +0 -6
- package/src/package.json +0 -18
|
@@ -1,57 +1,81 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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: {
|
|
67
|
+
data: { result, id }
|
|
43
68
|
}, "*");
|
|
44
|
-
}
|
|
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';
|
package/src/blocks/button.js
DELETED
|
@@ -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
|
-
}
|
package/src/blocks/columns.js
DELETED
|
@@ -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}]});
|
package/src/blocks/embed.js
DELETED
|
@@ -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}]});
|