@builder.io/sdk-react-native 0.1.1 → 0.1.3
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/dist/blocks/BaseText.js +40 -0
- package/dist/blocks/button/button.js +39 -0
- package/dist/blocks/button/component-info.js +42 -0
- package/dist/blocks/columns/columns.js +149 -0
- package/dist/blocks/columns/component-info.js +244 -0
- package/dist/blocks/custom-code/component-info.js +32 -0
- package/dist/blocks/custom-code/custom-code.js +76 -0
- package/dist/blocks/embed/component-info.js +47 -0
- package/dist/blocks/embed/embed.js +67 -0
- package/dist/blocks/embed/helpers.js +10 -0
- package/dist/blocks/form/component-info.js +263 -0
- package/dist/blocks/form/form.js +232 -0
- package/dist/blocks/fragment/component-info.js +12 -0
- package/dist/blocks/fragment/fragment.js +36 -0
- package/dist/blocks/image/component-info.js +152 -0
- package/dist/blocks/image/image.helpers.js +49 -0
- package/dist/blocks/image/image.js +81 -0
- package/dist/blocks/img/component-info.js +21 -0
- package/dist/blocks/img/img.js +35 -0
- package/dist/blocks/input/component-info.js +75 -0
- package/dist/blocks/input/input.js +32 -0
- package/dist/blocks/raw-text/component-info.js +17 -0
- package/dist/blocks/raw-text/raw-text.js +31 -0
- package/dist/blocks/section/component-info.js +50 -0
- package/dist/blocks/section/section.js +49 -0
- package/dist/blocks/select/component-info.js +60 -0
- package/dist/blocks/select/select.js +38 -0
- package/dist/blocks/submit-button/component-info.js +29 -0
- package/dist/blocks/submit-button/submit-button.js +36 -0
- package/dist/blocks/symbol/component-info.js +44 -0
- package/dist/blocks/symbol/symbol.js +97 -0
- package/dist/blocks/text/component-info.js +25 -0
- package/dist/blocks/text/text.js +112 -0
- package/dist/blocks/textarea/component-info.js +48 -0
- package/dist/blocks/textarea/textarea.js +31 -0
- package/dist/blocks/util.js +9 -0
- package/dist/blocks/video/component-info.js +107 -0
- package/dist/blocks/video/video.js +81 -0
- package/dist/components/render-block/block-styles.js +79 -0
- package/dist/components/render-block/render-block.helpers.js +109 -0
- package/dist/components/render-block/render-block.js +154 -0
- package/dist/components/render-block/render-component-with-context.js +45 -0
- package/dist/components/render-block/render-component.js +50 -0
- package/dist/components/render-block/render-repeated-block.js +45 -0
- package/dist/components/render-block/types.js +1 -0
- package/dist/components/render-blocks.js +76 -0
- package/dist/components/render-content/builder-editing.js +31 -0
- package/dist/components/render-content/components/render-styles.js +91 -0
- package/dist/components/render-content/index.js +8 -0
- package/dist/components/render-content/render-content.js +325 -0
- package/dist/components/render-inlined-styles.js +42 -0
- package/dist/constants/builder-registered-components.js +46 -0
- package/dist/constants/device-sizes.js +49 -0
- package/dist/constants/target.js +5 -0
- package/dist/context/builder.context.js +13 -0
- package/dist/context/types.js +1 -0
- package/dist/functions/camel-to-kebab-case.js +5 -0
- package/dist/functions/evaluate.js +25 -0
- package/dist/functions/event-handler-name.js +8 -0
- package/dist/functions/extract-text-styles.js +23 -0
- package/dist/functions/fast-clone.js +5 -0
- package/dist/functions/get-block-actions-handler.js +12 -0
- package/dist/functions/get-block-actions.js +19 -0
- package/dist/functions/get-block-component-options.js +29 -0
- package/dist/functions/get-block-properties.js +51 -0
- package/dist/functions/get-block-tag.js +8 -0
- package/dist/functions/get-builder-search-params/fn.test.js +15 -0
- package/dist/functions/get-builder-search-params/index.js +39 -0
- package/dist/functions/get-content/ab-testing.js +89 -0
- package/dist/functions/get-content/generate-content-url.js +44 -0
- package/dist/functions/get-content/generate-content-url.test.js +33 -0
- package/dist/functions/get-content/index.js +68 -0
- package/dist/functions/get-content/types.js +1 -0
- package/dist/functions/get-fetch.js +15 -0
- package/dist/functions/get-global-this.js +19 -0
- package/dist/functions/get-processed-block.js +52 -0
- package/dist/functions/get-processed-block.test.js +34 -0
- package/dist/functions/get-react-native-block-styles.js +30 -0
- package/dist/functions/if-target.js +13 -0
- package/dist/functions/is-browser.js +7 -0
- package/dist/functions/is-editing.js +8 -0
- package/dist/functions/is-iframe.js +8 -0
- package/dist/functions/is-previewing.js +15 -0
- package/dist/functions/on-change.js +28 -0
- package/dist/functions/on-change.test.js +21 -0
- package/dist/functions/register-component.js +65 -0
- package/dist/functions/register.js +31 -0
- package/dist/functions/sanitize-react-native-block-styles.js +71 -0
- package/dist/functions/set-editor-settings.js +16 -0
- package/dist/functions/set.js +12 -0
- package/dist/functions/set.test.js +18 -0
- package/dist/functions/track/helpers.js +53 -0
- package/dist/functions/track/index.js +124 -0
- package/dist/functions/track/interaction.js +51 -0
- package/dist/functions/track.js +120 -0
- package/dist/functions/transform-block-properties.js +18 -0
- package/dist/functions/transform-block.js +38 -0
- package/dist/helpers/ab-tests.js +10 -0
- package/dist/helpers/cookie.js +70 -0
- package/dist/helpers/css.js +33 -0
- package/dist/helpers/flatten.js +35 -0
- package/dist/helpers/localStorage.js +31 -0
- package/dist/helpers/nullable.js +5 -0
- package/dist/helpers/sessionId.js +51 -0
- package/dist/helpers/time.js +6 -0
- package/dist/helpers/url.js +14 -0
- package/dist/helpers/url.test.js +23 -0
- package/dist/helpers/uuid.js +14 -0
- package/dist/helpers/visitorId.js +33 -0
- package/dist/index-helpers/blocks-exports.js +22 -0
- package/dist/index-helpers/top-of-file.js +3 -0
- package/dist/index.js +29 -0
- package/dist/scripts/init-editing.js +97 -0
- package/dist/types/builder-block.js +1 -0
- package/dist/types/builder-content.js +1 -0
- package/dist/types/can-track.js +1 -0
- package/dist/types/components.js +1 -0
- package/dist/types/deep-partial.js +1 -0
- package/dist/types/element.js +1 -0
- package/dist/types/targets.js +1 -0
- package/dist/types/typescript.js +1 -0
- package/package.json +13 -5
- package/src/blocks/BaseText.jsx +17 -0
- package/src/blocks/button/button.jsx +28 -0
- package/src/blocks/columns/{columns.js → columns.jsx} +59 -36
- package/src/blocks/custom-code/{custom-code.js → custom-code.jsx} +22 -15
- package/src/blocks/embed/{embed.js → embed.jsx} +12 -11
- package/src/blocks/form/form.jsx +251 -0
- package/src/blocks/fragment/fragment.jsx +11 -0
- package/src/blocks/image/image.jsx +78 -0
- package/src/blocks/img/img.jsx +18 -0
- package/src/blocks/input/input.jsx +20 -0
- package/src/blocks/raw-text/raw-text.jsx +6 -0
- package/src/blocks/section/section.jsx +29 -0
- package/src/blocks/select/select.jsx +24 -0
- package/src/blocks/submit-button/submit-button.jsx +11 -0
- package/src/blocks/symbol/symbol.jsx +86 -0
- package/src/blocks/text/text.jsx +100 -0
- package/src/blocks/textarea/textarea.jsx +14 -0
- package/src/blocks/video/video.jsx +70 -0
- package/src/components/render-block/block-styles.jsx +70 -0
- package/src/components/render-block/render-block.helpers.js +90 -0
- package/src/components/render-block/render-block.jsx +183 -0
- package/src/components/render-block/render-component.jsx +45 -0
- package/src/components/render-block/render-repeated-block.jsx +22 -0
- package/src/components/render-blocks.jsx +86 -0
- package/src/components/render-content/builder-editing.jsx +6 -0
- package/src/components/render-content/components/{render-styles.js → render-styles.jsx} +21 -14
- package/src/components/render-content/render-content.jsx +373 -0
- package/src/components/render-inlined-styles.jsx +29 -0
- package/src/functions/track/helpers.js +50 -0
- package/src/functions/{track.js → track/index.js} +10 -6
- package/src/functions/track/interaction.js +53 -0
- package/src/helpers/localStorage.js +1 -0
- package/src/helpers/sessionId.js +4 -1
- package/src/helpers/url.js +3 -0
- package/src/helpers/url.test.js +6 -0
- package/src/helpers/visitorId.js +1 -0
- package/src/index.js +1 -1
- package/src/blocks/BaseText.js +0 -31
- package/src/blocks/button/button.js +0 -36
- package/src/blocks/form/form.js +0 -222
- package/src/blocks/fragment/fragment.js +0 -9
- package/src/blocks/image/image.js +0 -55
- package/src/blocks/img/img.js +0 -33
- package/src/blocks/input/input.js +0 -36
- package/src/blocks/raw-text/raw-text.js +0 -10
- package/src/blocks/section/section.js +0 -41
- package/src/blocks/select/select.js +0 -37
- package/src/blocks/submit-button/submit-button.js +0 -27
- package/src/blocks/symbol/symbol.js +0 -73
- package/src/blocks/text/text.js +0 -67
- package/src/blocks/textarea/textarea.js +0 -32
- package/src/blocks/video/video.js +0 -55
- package/src/components/render-block/block-styles.js +0 -50
- package/src/components/render-block/render-block.js +0 -202
- package/src/components/render-block/render-component-with-context.js +0 -35
- package/src/components/render-block/render-component.js +0 -35
- package/src/components/render-block/render-repeated-block.js +0 -33
- package/src/components/render-blocks.js +0 -63
- package/src/components/render-content/builder-editing.js +0 -8
- package/src/components/render-content/render-content.js +0 -296
- package/src/components/render-inlined-styles.js +0 -17
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import BaseText from "../BaseText";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { View, StyleSheet, Image, Text } from "react-native";
|
|
4
|
+
|
|
5
|
+
export default function SectionComponent(props) {
|
|
6
|
+
return (
|
|
7
|
+
<View
|
|
8
|
+
{...props.attributes}
|
|
9
|
+
style={{
|
|
10
|
+
width: "100%",
|
|
11
|
+
alignSelf: "stretch",
|
|
12
|
+
flexGrow: "1",
|
|
13
|
+
boxSizing: "border-box",
|
|
14
|
+
maxWidth: `${
|
|
15
|
+
props.maxWidth && typeof props.maxWidth === "number"
|
|
16
|
+
? props.maxWidth
|
|
17
|
+
: 1200
|
|
18
|
+
}px`,
|
|
19
|
+
display: "flex",
|
|
20
|
+
flexDirection: "column",
|
|
21
|
+
alignItems: "stretch",
|
|
22
|
+
marginLeft: "auto",
|
|
23
|
+
marginRight: "auto",
|
|
24
|
+
}}
|
|
25
|
+
>
|
|
26
|
+
<BaseText>{props.children}</BaseText>
|
|
27
|
+
</View>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import BaseText from "../BaseText";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { View, StyleSheet, Image, Text } from "react-native";
|
|
4
|
+
import { isEditing } from "../../functions/is-editing.js";
|
|
5
|
+
|
|
6
|
+
export default function SelectComponent(props) {
|
|
7
|
+
return (
|
|
8
|
+
<View
|
|
9
|
+
{...props.attributes}
|
|
10
|
+
value={props.value}
|
|
11
|
+
key={
|
|
12
|
+
isEditing() && props.defaultValue ? props.defaultValue : "default-key"
|
|
13
|
+
}
|
|
14
|
+
defaultValue={props.defaultValue}
|
|
15
|
+
name={props.name}
|
|
16
|
+
>
|
|
17
|
+
{props.options?.map((option) => (
|
|
18
|
+
<View value={option.value}>
|
|
19
|
+
<BaseText>{option.name || option.value}</BaseText>
|
|
20
|
+
</View>
|
|
21
|
+
))}
|
|
22
|
+
</View>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import BaseText from "../BaseText";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { View, StyleSheet, Image, Text } from "react-native";
|
|
4
|
+
|
|
5
|
+
export default function SubmitButton(props) {
|
|
6
|
+
return (
|
|
7
|
+
<View type="submit" {...props.attributes}>
|
|
8
|
+
<BaseText>{props.text}</BaseText>
|
|
9
|
+
</View>
|
|
10
|
+
);
|
|
11
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { View, StyleSheet, Image, Text } from "react-native";
|
|
3
|
+
import { useState, useContext, useEffect } from "react";
|
|
4
|
+
import RenderContent from "../../components/render-content/render-content.js";
|
|
5
|
+
import BuilderContext from "../../context/builder.context.js";
|
|
6
|
+
import { getContent } from "../../functions/get-content/index.js";
|
|
7
|
+
import { TARGET } from "../../constants/target";
|
|
8
|
+
|
|
9
|
+
export default function Symbol(props) {
|
|
10
|
+
function className() {
|
|
11
|
+
return [
|
|
12
|
+
...(TARGET === "vue2" || TARGET === "vue3"
|
|
13
|
+
? Object.keys(props.attributes.class)
|
|
14
|
+
: [props.attributes.class]),
|
|
15
|
+
"builder-symbol",
|
|
16
|
+
props.symbol?.inline ? "builder-inline-symbol" : undefined,
|
|
17
|
+
props.symbol?.dynamic || props.dynamic
|
|
18
|
+
? "builder-dynamic-symbol"
|
|
19
|
+
: undefined,
|
|
20
|
+
]
|
|
21
|
+
.filter(Boolean)
|
|
22
|
+
.join(" ");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const [fetchedContent, setFetchedContent] = useState(() => null);
|
|
26
|
+
|
|
27
|
+
function contentToUse() {
|
|
28
|
+
return props.symbol?.content || fetchedContent;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const builderContext = useContext(BuilderContext);
|
|
32
|
+
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
const symbolToUse = props.symbol;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* If:
|
|
38
|
+
* - we have a symbol prop
|
|
39
|
+
* - yet it does not have any content
|
|
40
|
+
* - and we have not already stored content from before
|
|
41
|
+
* - and it has a model name
|
|
42
|
+
*
|
|
43
|
+
* then we want to re-fetch the symbol content.
|
|
44
|
+
*/
|
|
45
|
+
if (
|
|
46
|
+
symbolToUse &&
|
|
47
|
+
!symbolToUse.content &&
|
|
48
|
+
!fetchedContent &&
|
|
49
|
+
symbolToUse.model &&
|
|
50
|
+
// This is a hack, we should not need to check for this, but it is needed for Svelte.
|
|
51
|
+
builderContext?.apiKey
|
|
52
|
+
) {
|
|
53
|
+
getContent({
|
|
54
|
+
model: symbolToUse.model,
|
|
55
|
+
apiKey: builderContext.apiKey,
|
|
56
|
+
query: {
|
|
57
|
+
id: symbolToUse.entry,
|
|
58
|
+
},
|
|
59
|
+
}).then((response) => {
|
|
60
|
+
setFetchedContent(response);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}, [props.symbol, fetchedContent]);
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<View
|
|
67
|
+
{...props.attributes}
|
|
68
|
+
dataSet={{
|
|
69
|
+
class: className(),
|
|
70
|
+
}}
|
|
71
|
+
>
|
|
72
|
+
<RenderContent
|
|
73
|
+
apiKey={builderContext.apiKey}
|
|
74
|
+
context={builderContext.context}
|
|
75
|
+
customComponents={Object.values(builderContext.registeredComponents)}
|
|
76
|
+
data={{
|
|
77
|
+
...props.symbol?.data,
|
|
78
|
+
...builderContext.state,
|
|
79
|
+
...props.symbol?.content?.data?.state,
|
|
80
|
+
}}
|
|
81
|
+
model={props.symbol?.model}
|
|
82
|
+
content={contentToUse()}
|
|
83
|
+
/>
|
|
84
|
+
</View>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import HTML from 'react-native-render-html';
|
|
3
|
+
import BuilderContext from '../../context/builder.context';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {{}} BuilderBlock
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @param {string} string
|
|
12
|
+
* @returns {string}
|
|
13
|
+
*/
|
|
14
|
+
function camelToKebabCase(string) {
|
|
15
|
+
return string.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2').toLowerCase();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @param {object} object
|
|
21
|
+
* @param {string[]} keys
|
|
22
|
+
* @returns {object}
|
|
23
|
+
*/
|
|
24
|
+
function pick(object, keys) {
|
|
25
|
+
return keys.reduce((obj, key) => {
|
|
26
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
27
|
+
if (object && object.hasOwnProperty(key)) {
|
|
28
|
+
obj[key] = object[key];
|
|
29
|
+
}
|
|
30
|
+
return obj;
|
|
31
|
+
}, {});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const PICK_STYLES = ['textAlign'];
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param {BuilderBlock} block
|
|
38
|
+
* @returns
|
|
39
|
+
*/
|
|
40
|
+
function getBlockStyles(block) {
|
|
41
|
+
// TODO: responsive CSS using react native viewport width hooks
|
|
42
|
+
const styles = {
|
|
43
|
+
...block.responsiveStyles?.large,
|
|
44
|
+
...(block).styles,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
if (block.responsiveStyles?.medium) {
|
|
48
|
+
Object.assign(styles, block.responsiveStyles.medium);
|
|
49
|
+
}
|
|
50
|
+
if (block.responsiveStyles?.small) {
|
|
51
|
+
Object.assign(styles, block.responsiveStyles.small);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return styles;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
*
|
|
59
|
+
* @param {BuilderBlock} block
|
|
60
|
+
* @param {any} inheritedStyles
|
|
61
|
+
* @returns
|
|
62
|
+
*/
|
|
63
|
+
function getCss(block, inheritedStyles) {
|
|
64
|
+
const styleObject = {
|
|
65
|
+
...inheritedStyles,
|
|
66
|
+
...pick(getBlockStyles(block), PICK_STYLES)
|
|
67
|
+
};
|
|
68
|
+
if (!styleObject) {
|
|
69
|
+
return '';
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
let str = ``;
|
|
73
|
+
|
|
74
|
+
for (const key in styleObject) {
|
|
75
|
+
const value = styleObject[key];
|
|
76
|
+
if (typeof value === 'string') {
|
|
77
|
+
str += `${camelToKebabCase(key)}: ${value};`;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return str;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
*
|
|
86
|
+
* @param {{ text: string; builderBlock: BuilderBlock}} props
|
|
87
|
+
* @returns
|
|
88
|
+
*/
|
|
89
|
+
export default function Text(props) {
|
|
90
|
+
const builderContext = React.useContext(BuilderContext);
|
|
91
|
+
return (
|
|
92
|
+
<HTML
|
|
93
|
+
source={{
|
|
94
|
+
html: `<div style="${getCss(props.builderBlock, builderContext.inheritedStyles)}">${
|
|
95
|
+
props.text || ''
|
|
96
|
+
}</div>`,
|
|
97
|
+
}}
|
|
98
|
+
/>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { View, StyleSheet, Image, Text } from "react-native";
|
|
3
|
+
|
|
4
|
+
export default function Textarea(props) {
|
|
5
|
+
return (
|
|
6
|
+
<View
|
|
7
|
+
{...props.attributes}
|
|
8
|
+
placeholder={props.placeholder}
|
|
9
|
+
name={props.name}
|
|
10
|
+
value={props.value}
|
|
11
|
+
defaultValue={props.defaultValue}
|
|
12
|
+
/>
|
|
13
|
+
);
|
|
14
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// TO-DO: This file breaks due to this issue:
|
|
2
|
+
// https://github.com/expo/web-examples/issues/73
|
|
3
|
+
// For now, we do not import it elsewhere to avoid crashing Expo servers on web when importing the SDK.
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { View } from 'react-native';
|
|
6
|
+
import ReactVideo from 'react-native-video';
|
|
7
|
+
|
|
8
|
+
// Subset of Image props, many are irrelevant for native (such as altText, etc)
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @typedef {{
|
|
12
|
+
* attributes?: any;
|
|
13
|
+
* video?: string;
|
|
14
|
+
* autoPlay?: boolean;
|
|
15
|
+
* controls?: boolean;
|
|
16
|
+
* muted?: boolean;
|
|
17
|
+
* loop?: boolean;
|
|
18
|
+
* playsInline?: boolean;
|
|
19
|
+
* aspectRatio?: number;
|
|
20
|
+
* fit?: 'contain' | 'cover' | 'stretch';
|
|
21
|
+
* position?:
|
|
22
|
+
* | 'center'
|
|
23
|
+
* | 'top'
|
|
24
|
+
* | 'left'
|
|
25
|
+
* | 'right'
|
|
26
|
+
* | 'bottom'
|
|
27
|
+
* | 'top left'
|
|
28
|
+
* | 'top right'
|
|
29
|
+
* | 'bottom left'
|
|
30
|
+
* | 'bottom right';
|
|
31
|
+
* posterImage?: string;
|
|
32
|
+
* children?: any;
|
|
33
|
+
* }} VideoProps
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
// TODO: support children by wrapping in a View
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @param {VideoProps} props
|
|
40
|
+
*/
|
|
41
|
+
export default function Video(props) {
|
|
42
|
+
return (
|
|
43
|
+
<View style={{ position: 'relative' }}>
|
|
44
|
+
<ReactVideo
|
|
45
|
+
paused={!props.autoPlay}
|
|
46
|
+
controls={props.controls}
|
|
47
|
+
muted={props.muted}
|
|
48
|
+
repeat={props.loop}
|
|
49
|
+
poster={props.posterImage}
|
|
50
|
+
posterResizeMode={props.fit || 'contain'}
|
|
51
|
+
resizeMode={props.fit || ('contain')}
|
|
52
|
+
style={{
|
|
53
|
+
position: 'absolute',
|
|
54
|
+
top: 0,
|
|
55
|
+
bottom: 0,
|
|
56
|
+
left: 0,
|
|
57
|
+
right: 0,
|
|
58
|
+
zIndex: 1,
|
|
59
|
+
}}
|
|
60
|
+
source={{ uri: props.video }}
|
|
61
|
+
/>
|
|
62
|
+
<View
|
|
63
|
+
style={{
|
|
64
|
+
width: '100%',
|
|
65
|
+
paddingTop: `${props.aspectRatio * 100}%`,
|
|
66
|
+
}}
|
|
67
|
+
/>
|
|
68
|
+
</View>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { View, StyleSheet, Image, Text } from "react-native";
|
|
3
|
+
import {
|
|
4
|
+
getMaxWidthQueryForSize,
|
|
5
|
+
getSizesForBreakpoints,
|
|
6
|
+
} from "../../constants/device-sizes.js";
|
|
7
|
+
import { TARGET } from "../../constants/target.js";
|
|
8
|
+
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
9
|
+
import { createCssClass } from "../../helpers/css.js";
|
|
10
|
+
import RenderInlinedStyles from "../render-inlined-styles.js";
|
|
11
|
+
|
|
12
|
+
export default function BlockStyles(props) {
|
|
13
|
+
function useBlock() {
|
|
14
|
+
return getProcessedBlock({
|
|
15
|
+
block: props.block,
|
|
16
|
+
state: props.context.state,
|
|
17
|
+
context: props.context.context,
|
|
18
|
+
shouldEvaluateBindings: true,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function css() {
|
|
23
|
+
const styles = useBlock().responsiveStyles;
|
|
24
|
+
const content = props.context.content;
|
|
25
|
+
const sizesWithUpdatedBreakpoints = getSizesForBreakpoints(
|
|
26
|
+
content?.meta?.breakpoints || {}
|
|
27
|
+
);
|
|
28
|
+
const largeStyles = styles?.large;
|
|
29
|
+
const mediumStyles = styles?.medium;
|
|
30
|
+
const smallStyles = styles?.small;
|
|
31
|
+
const className = useBlock().id;
|
|
32
|
+
const largeStylesClass = largeStyles
|
|
33
|
+
? createCssClass({
|
|
34
|
+
className,
|
|
35
|
+
styles: largeStyles,
|
|
36
|
+
})
|
|
37
|
+
: "";
|
|
38
|
+
const mediumStylesClass = mediumStyles
|
|
39
|
+
? createCssClass({
|
|
40
|
+
className,
|
|
41
|
+
styles: mediumStyles,
|
|
42
|
+
mediaQuery: getMaxWidthQueryForSize(
|
|
43
|
+
"medium",
|
|
44
|
+
sizesWithUpdatedBreakpoints
|
|
45
|
+
),
|
|
46
|
+
})
|
|
47
|
+
: "";
|
|
48
|
+
const smallStylesClass = smallStyles
|
|
49
|
+
? createCssClass({
|
|
50
|
+
className,
|
|
51
|
+
styles: smallStyles,
|
|
52
|
+
mediaQuery: getMaxWidthQueryForSize(
|
|
53
|
+
"small",
|
|
54
|
+
sizesWithUpdatedBreakpoints
|
|
55
|
+
),
|
|
56
|
+
})
|
|
57
|
+
: "";
|
|
58
|
+
return [largeStylesClass, mediumStylesClass, smallStylesClass].join(" ");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<>
|
|
63
|
+
{TARGET !== "reactNative" && css() ? (
|
|
64
|
+
<>
|
|
65
|
+
<RenderInlinedStyles styles={css()} />
|
|
66
|
+
</>
|
|
67
|
+
) : null}
|
|
68
|
+
</>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
@@ -1,3 +1,36 @@
|
|
|
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
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
32
|
+
import { evaluate } from "../../functions/evaluate";
|
|
33
|
+
import { getProcessedBlock } from "../../functions/get-processed-block";
|
|
1
34
|
const EMPTY_HTML_ELEMENTS = [
|
|
2
35
|
"area",
|
|
3
36
|
"base",
|
|
@@ -18,6 +51,63 @@ const EMPTY_HTML_ELEMENTS = [
|
|
|
18
51
|
const isEmptyHtmlElement = (tagName) => {
|
|
19
52
|
return typeof tagName === "string" && EMPTY_HTML_ELEMENTS.includes(tagName.toLowerCase());
|
|
20
53
|
};
|
|
54
|
+
const getComponent = ({
|
|
55
|
+
block,
|
|
56
|
+
context
|
|
57
|
+
}) => {
|
|
58
|
+
var _a;
|
|
59
|
+
const componentName = (_a = getProcessedBlock({
|
|
60
|
+
block,
|
|
61
|
+
state: context.state,
|
|
62
|
+
context: context.context,
|
|
63
|
+
shouldEvaluateBindings: false
|
|
64
|
+
}).component) == null ? void 0 : _a.name;
|
|
65
|
+
if (!componentName) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
const ref = context.registeredComponents[componentName];
|
|
69
|
+
if (!ref) {
|
|
70
|
+
console.warn(`
|
|
71
|
+
Could not find a registered component named "${componentName}".
|
|
72
|
+
If you registered it, is the file that registered it imported by the file that needs to render it?`);
|
|
73
|
+
return void 0;
|
|
74
|
+
} else {
|
|
75
|
+
return ref;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const getRepeatItemData = ({
|
|
79
|
+
block,
|
|
80
|
+
context
|
|
81
|
+
}) => {
|
|
82
|
+
const _a = block, { repeat } = _a, blockWithoutRepeat = __objRest(_a, ["repeat"]);
|
|
83
|
+
if (!(repeat == null ? void 0 : repeat.collection)) {
|
|
84
|
+
return void 0;
|
|
85
|
+
}
|
|
86
|
+
const itemsArray = evaluate({
|
|
87
|
+
code: repeat.collection,
|
|
88
|
+
state: context.state,
|
|
89
|
+
context: context.context
|
|
90
|
+
});
|
|
91
|
+
if (!Array.isArray(itemsArray)) {
|
|
92
|
+
return void 0;
|
|
93
|
+
}
|
|
94
|
+
const collectionName = repeat.collection.split(".").pop();
|
|
95
|
+
const itemNameToUse = repeat.itemName || (collectionName ? collectionName + "Item" : "item");
|
|
96
|
+
const repeatArray = itemsArray.map((item, index) => ({
|
|
97
|
+
context: __spreadProps(__spreadValues({}, context), {
|
|
98
|
+
state: __spreadProps(__spreadValues({}, context.state), {
|
|
99
|
+
$index: index,
|
|
100
|
+
$item: item,
|
|
101
|
+
[itemNameToUse]: item,
|
|
102
|
+
[`$${itemNameToUse}Index`]: index
|
|
103
|
+
})
|
|
104
|
+
}),
|
|
105
|
+
block: blockWithoutRepeat
|
|
106
|
+
}));
|
|
107
|
+
return repeatArray;
|
|
108
|
+
};
|
|
21
109
|
export {
|
|
110
|
+
getComponent,
|
|
111
|
+
getRepeatItemData,
|
|
22
112
|
isEmptyHtmlElement
|
|
23
113
|
};
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { View, StyleSheet, Image, Text } from "react-native";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { getBlockActions } from "../../functions/get-block-actions.js";
|
|
5
|
+
import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
|
|
6
|
+
import { getBlockProperties } from "../../functions/get-block-properties.js";
|
|
7
|
+
import { getBlockTag } from "../../functions/get-block-tag.js";
|
|
8
|
+
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
9
|
+
import BlockStyles from "./block-styles.js";
|
|
10
|
+
import {
|
|
11
|
+
getComponent,
|
|
12
|
+
getRepeatItemData,
|
|
13
|
+
isEmptyHtmlElement,
|
|
14
|
+
} from "./render-block.helpers.js";
|
|
15
|
+
import RenderRepeatedBlock from "./render-repeated-block.js";
|
|
16
|
+
import { TARGET } from "../../constants/target.js";
|
|
17
|
+
import { extractTextStyles } from "../../functions/extract-text-styles.js";
|
|
18
|
+
import RenderComponent from "./render-component.js";
|
|
19
|
+
import { getReactNativeBlockStyles } from "../../functions/get-react-native-block-styles.js";
|
|
20
|
+
|
|
21
|
+
export default function RenderBlock(props) {
|
|
22
|
+
const [component, setComponent] = useState(() =>
|
|
23
|
+
getComponent({
|
|
24
|
+
block: props.block,
|
|
25
|
+
context: props.context,
|
|
26
|
+
})
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
function tag() {
|
|
30
|
+
return getBlockTag(useBlock());
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function useBlock() {
|
|
34
|
+
return repeatItemData
|
|
35
|
+
? props.block
|
|
36
|
+
: getProcessedBlock({
|
|
37
|
+
block: props.block,
|
|
38
|
+
state: props.context.state,
|
|
39
|
+
context: props.context.context,
|
|
40
|
+
shouldEvaluateBindings: true,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function actions() {
|
|
45
|
+
return getBlockActions({
|
|
46
|
+
block: useBlock(),
|
|
47
|
+
state: props.context.state,
|
|
48
|
+
context: props.context.context,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function attributes() {
|
|
53
|
+
const blockProperties = getBlockProperties(useBlock());
|
|
54
|
+
return {
|
|
55
|
+
...blockProperties,
|
|
56
|
+
...(TARGET === "reactNative"
|
|
57
|
+
? {
|
|
58
|
+
style: getReactNativeBlockStyles({
|
|
59
|
+
block: useBlock(),
|
|
60
|
+
context: props.context,
|
|
61
|
+
blockStyles: blockProperties.style,
|
|
62
|
+
}),
|
|
63
|
+
}
|
|
64
|
+
: {}),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function renderComponentProps() {
|
|
69
|
+
return {
|
|
70
|
+
blockChildren: useBlock().children ?? [],
|
|
71
|
+
componentRef: component?.component,
|
|
72
|
+
componentOptions: {
|
|
73
|
+
...getBlockComponentOptions(useBlock()),
|
|
74
|
+
/**
|
|
75
|
+
* These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
|
|
76
|
+
* they are provided to the component itself directly.
|
|
77
|
+
*/
|
|
78
|
+
...(!component?.noWrap
|
|
79
|
+
? {}
|
|
80
|
+
: {
|
|
81
|
+
attributes: {
|
|
82
|
+
...attributes(),
|
|
83
|
+
...actions(),
|
|
84
|
+
},
|
|
85
|
+
}),
|
|
86
|
+
customBreakpoints: childrenContext?.()?.content?.meta?.breakpoints,
|
|
87
|
+
},
|
|
88
|
+
context: childrenContext(),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function childrenWithoutParentComponent() {
|
|
93
|
+
/**
|
|
94
|
+
* When there is no `componentRef`, there might still be children that need to be rendered. In this case,
|
|
95
|
+
* we render them outside of `componentRef`.
|
|
96
|
+
* NOTE: We make sure not to render this if `repeatItemData` is non-null, because that means we are rendering an array of
|
|
97
|
+
* blocks, and the children will be repeated within those blocks.
|
|
98
|
+
*/
|
|
99
|
+
const shouldRenderChildrenOutsideRef =
|
|
100
|
+
!component?.component && !repeatItemData;
|
|
101
|
+
return shouldRenderChildrenOutsideRef ? useBlock().children ?? [] : [];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const [repeatItemData, setRepeatItemData] = useState(() =>
|
|
105
|
+
getRepeatItemData({
|
|
106
|
+
block: props.block,
|
|
107
|
+
context: props.context,
|
|
108
|
+
})
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
function childrenContext() {
|
|
112
|
+
const getInheritedTextStyles = () => {
|
|
113
|
+
if (TARGET !== "reactNative") {
|
|
114
|
+
return {};
|
|
115
|
+
}
|
|
116
|
+
return extractTextStyles(
|
|
117
|
+
getReactNativeBlockStyles({
|
|
118
|
+
block: useBlock(),
|
|
119
|
+
context: props.context,
|
|
120
|
+
blockStyles: attributes().style,
|
|
121
|
+
})
|
|
122
|
+
);
|
|
123
|
+
};
|
|
124
|
+
return {
|
|
125
|
+
apiKey: props.context.apiKey,
|
|
126
|
+
state: props.context.state,
|
|
127
|
+
content: props.context.content,
|
|
128
|
+
context: props.context.context,
|
|
129
|
+
registeredComponents: props.context.registeredComponents,
|
|
130
|
+
inheritedStyles: getInheritedTextStyles(),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return (
|
|
135
|
+
<>
|
|
136
|
+
{!component?.noWrap ? (
|
|
137
|
+
<>
|
|
138
|
+
{isEmptyHtmlElement(tag()) ? (
|
|
139
|
+
<>
|
|
140
|
+
<View {...attributes()} {...actions()} />
|
|
141
|
+
</>
|
|
142
|
+
) : null}
|
|
143
|
+
{!isEmptyHtmlElement(tag()) && repeatItemData ? (
|
|
144
|
+
<>
|
|
145
|
+
{repeatItemData?.map((data, index) => (
|
|
146
|
+
<RenderRepeatedBlock
|
|
147
|
+
key={index}
|
|
148
|
+
repeatContext={data.context}
|
|
149
|
+
block={data.block}
|
|
150
|
+
/>
|
|
151
|
+
))}
|
|
152
|
+
</>
|
|
153
|
+
) : null}
|
|
154
|
+
{!isEmptyHtmlElement(tag()) && !repeatItemData ? (
|
|
155
|
+
<>
|
|
156
|
+
<View {...attributes()} {...actions()}>
|
|
157
|
+
<RenderComponent {...renderComponentProps()} />
|
|
158
|
+
|
|
159
|
+
{childrenWithoutParentComponent()?.map((child) => (
|
|
160
|
+
<RenderBlock
|
|
161
|
+
key={"render-block-" + child.id}
|
|
162
|
+
block={child}
|
|
163
|
+
context={childrenContext()}
|
|
164
|
+
/>
|
|
165
|
+
))}
|
|
166
|
+
|
|
167
|
+
{childrenWithoutParentComponent()?.map((child) => (
|
|
168
|
+
<BlockStyles
|
|
169
|
+
key={"block-style-" + child.id}
|
|
170
|
+
block={child}
|
|
171
|
+
context={childrenContext()}
|
|
172
|
+
/>
|
|
173
|
+
))}
|
|
174
|
+
</View>
|
|
175
|
+
</>
|
|
176
|
+
) : null}
|
|
177
|
+
</>
|
|
178
|
+
) : (
|
|
179
|
+
<RenderComponent {...renderComponentProps()} />
|
|
180
|
+
)}
|
|
181
|
+
</>
|
|
182
|
+
);
|
|
183
|
+
}
|