@builder.io/sdk-react-native 0.0.1-49 → 0.0.1-51
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 +11 -2
- package/package.json +1 -1
- package/src/blocks/button/button.js +31 -0
- package/src/blocks/{button.lite.tsx → button/button.lite.tsx} +3 -3
- package/src/blocks/button/component-info.js +42 -0
- package/src/blocks/columns/columns.js +59 -0
- package/src/blocks/{columns.lite.tsx → columns/columns.lite.tsx} +22 -21
- package/src/blocks/columns/component-info.js +218 -0
- package/src/blocks/custom-code/component-info.js +32 -0
- package/src/blocks/custom-code/custom-code.js +50 -0
- package/src/blocks/{custom-code.lite.tsx → custom-code/custom-code.lite.tsx} +11 -11
- package/src/blocks/embed/component-info.js +25 -0
- package/src/blocks/embed/embed.js +50 -0
- package/src/blocks/{embed.lite.tsx → embed/embed.lite.tsx} +11 -11
- package/src/blocks/form/component-info.js +263 -0
- package/src/blocks/form/form.js +221 -0
- package/src/blocks/{form.lite.tsx → form/form.lite.tsx} +51 -50
- package/src/blocks/fragment/component-info.js +12 -0
- package/src/blocks/fragment/fragment.js +8 -0
- package/src/blocks/{fragment.lite.tsx → fragment/fragment.lite.tsx} +2 -2
- package/src/blocks/image/component-info.js +105 -0
- package/src/blocks/image/image.js +41 -0
- package/src/blocks/{image.lite.tsx → image/image.lite.tsx} +11 -11
- package/src/blocks/img/component-info.js +21 -0
- package/src/blocks/img/img.js +36 -0
- package/src/blocks/img/img.lite.tsx +18 -0
- package/src/blocks/input/component-info.js +75 -0
- package/src/blocks/input/input.js +36 -0
- package/src/blocks/{input.lite.tsx → input/input.lite.tsx} +4 -4
- package/src/blocks/raw-text/component-info.js +17 -0
- package/src/blocks/raw-text/raw-text.js +10 -0
- package/src/blocks/raw-text/raw-text.lite.tsx +6 -0
- package/src/blocks/section/component-info.js +50 -0
- package/src/blocks/section/section.js +31 -0
- package/src/blocks/{section.lite.tsx → section/section.lite.tsx} +3 -3
- package/src/blocks/select/component-info.js +60 -0
- package/src/blocks/select/select.js +36 -0
- package/src/blocks/{select.lite.tsx → select/select.lite.tsx} +4 -4
- package/src/blocks/submit-button/component-info.js +29 -0
- package/src/blocks/submit-button/submit-button.js +29 -0
- package/src/blocks/{submit-button.lite.tsx → submit-button/submit-button.lite.tsx} +2 -2
- package/src/blocks/symbol/component-info.js +43 -0
- package/src/blocks/symbol/symbol.js +68 -0
- package/src/blocks/symbol/symbol.lite.tsx +60 -0
- package/src/blocks/text/component-info.js +25 -0
- package/src/blocks/text/text.js +65 -0
- package/src/blocks/text/text.lite.tsx +6 -0
- package/src/blocks/textarea/component-info.js +48 -0
- package/src/blocks/textarea/textarea.js +32 -0
- package/src/blocks/{textarea.lite.tsx → textarea/textarea.lite.tsx} +2 -2
- package/src/blocks/video/component-info.js +107 -0
- package/src/blocks/video/video.js +33 -0
- package/src/blocks/{video.lite.tsx → video/video.lite.tsx} +5 -5
- package/src/components/error-boundary.js +9 -11
- package/src/components/error-boundary.lite.tsx +2 -2
- package/src/components/render-block/block-styles.js +29 -0
- package/src/components/render-block/block-styles.lite.tsx +35 -0
- package/src/components/render-block/render-block.helpers.js +24 -0
- package/src/components/render-block/render-block.js +116 -0
- package/src/components/render-block/render-block.lite.tsx +139 -0
- package/src/components/render-blocks.js +35 -61
- package/src/components/render-blocks.lite.tsx +11 -11
- package/src/components/render-content/components/render-styles.js +58 -0
- package/src/components/render-content/components/render-styles.lite.tsx +70 -0
- package/src/components/render-content/index.js +5 -0
- package/src/components/render-content/render-content.js +254 -0
- package/src/components/render-content/render-content.lite.tsx +283 -0
- package/src/components/render-inlined-styles.js +18 -0
- package/src/components/render-inlined-styles.lite.tsx +31 -0
- package/src/constants/builder-registered-components.js +27 -0
- package/src/constants/device-sizes.js +11 -8
- package/src/constants/target.js +5 -0
- package/src/context/builder.context.js +11 -3
- package/src/functions/evaluate.js +20 -20
- package/src/functions/event-handler-name.js +3 -1
- package/src/functions/fast-clone.js +5 -0
- package/src/functions/get-block-actions.js +17 -16
- package/src/functions/get-block-component-options.js +9 -16
- package/src/functions/get-block-properties.js +14 -18
- package/src/functions/get-block-styles.js +17 -34
- package/src/functions/get-block-tag.js +4 -2
- package/src/functions/get-builder-search-params/fn.test.js +6 -10
- package/src/functions/get-builder-search-params/index.js +6 -3
- package/src/functions/get-content/fn.test.js +15 -17
- package/src/functions/get-content/index.js +25 -42
- package/src/functions/get-fetch.js +32 -8
- package/src/functions/get-global-this.js +7 -5
- package/src/functions/get-processed-block.js +13 -17
- package/src/functions/get-processed-block.test.js +16 -27
- package/src/functions/if-target.js +14 -3
- package/src/functions/is-browser.js +4 -2
- package/src/functions/is-editing.js +5 -5
- package/src/functions/is-iframe.js +4 -2
- package/src/functions/is-previewing.js +6 -4
- package/src/functions/is-react-native.js +3 -1
- package/src/functions/macro-eval.js +5 -2
- package/src/functions/on-change.js +7 -4
- package/src/functions/on-change.test.js +9 -10
- package/src/functions/previewing-model-name.js +5 -3
- package/src/functions/register-component.js +33 -44
- package/src/functions/register.js +10 -8
- package/src/functions/set-editor-settings.js +7 -5
- package/src/functions/set.js +5 -14
- package/src/functions/set.test.js +13 -14
- package/src/functions/track.js +13 -7
- package/src/functions/transform-block.js +13 -17
- package/src/index-helpers/blocks-exports.js +9 -9
- package/src/index-helpers/top-of-file.js +1 -1
- package/src/index.js +10 -12
- package/src/scripts/init-editing.js +74 -88
- package/src/types/components.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/src/blocks/button.js +0 -86
- package/src/blocks/columns.js +0 -293
- package/src/blocks/custom-code.js +0 -83
- package/src/blocks/embed.js +0 -77
- package/src/blocks/form.js +0 -521
- package/src/blocks/fragment.js +0 -21
- package/src/blocks/image.js +0 -165
- package/src/blocks/img.js +0 -64
- package/src/blocks/img.lite.tsx +0 -18
- package/src/blocks/input.js +0 -113
- package/src/blocks/raw-text.js +0 -17
- package/src/blocks/raw-text.lite.tsx +0 -6
- package/src/blocks/section.js +0 -84
- package/src/blocks/select.js +0 -91
- package/src/blocks/submit-button.js +0 -60
- package/src/blocks/symbol.js +0 -20
- package/src/blocks/symbol.lite.tsx +0 -20
- package/src/blocks/text.js +0 -100
- package/src/blocks/text.lite.tsx +0 -6
- package/src/blocks/textarea.js +0 -73
- package/src/blocks/video.js +0 -100
- package/src/components/block-styles.js +0 -5
- package/src/components/block-styles.lite.tsx +0 -6
- package/src/components/render-block.js +0 -164
- package/src/components/render-block.lite.tsx +0 -132
- package/src/components/render-content.js +0 -220
- package/src/components/render-content.lite.tsx +0 -206
- package/src/functions/get-target.js +0 -5
|
@@ -1,80 +1,54 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import { View, StyleSheet } from
|
|
3
|
-
import { isEditing } from
|
|
4
|
-
import RenderBlock from
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { View, StyleSheet } from "react-native";
|
|
3
|
+
import { isEditing } from "../functions/is-editing.js";
|
|
4
|
+
import RenderBlock from "./render-block/render-block.js";
|
|
5
5
|
function RenderBlocks(props) {
|
|
6
6
|
var _a;
|
|
7
7
|
function className() {
|
|
8
8
|
var _a2;
|
|
9
|
-
return (
|
|
10
|
-
'builder-blocks' +
|
|
11
|
-
(!((_a2 = props.blocks) == null ? void 0 : _a2.length)
|
|
12
|
-
? ' no-blocks'
|
|
13
|
-
: '')
|
|
14
|
-
);
|
|
9
|
+
return "builder-blocks" + (!((_a2 = props.blocks) == null ? void 0 : _a2.length) ? " no-blocks" : "");
|
|
15
10
|
}
|
|
16
11
|
function onClick() {
|
|
17
12
|
var _a2, _b;
|
|
18
13
|
if (isEditing() && !((_a2 = props.blocks) == null ? void 0 : _a2.length)) {
|
|
19
|
-
(_b = window.parent) == null
|
|
20
|
-
|
|
21
|
-
:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
dataPath: props.path,
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
'*'
|
|
30
|
-
);
|
|
14
|
+
(_b = window.parent) == null ? void 0 : _b.postMessage({
|
|
15
|
+
type: "builder.clickEmptyBlocks",
|
|
16
|
+
data: {
|
|
17
|
+
parentElementId: props.parent,
|
|
18
|
+
dataPath: props.path
|
|
19
|
+
}
|
|
20
|
+
}, "*");
|
|
31
21
|
}
|
|
32
22
|
}
|
|
33
23
|
function onMouseEnter() {
|
|
34
24
|
var _a2, _b;
|
|
35
25
|
if (isEditing() && !((_a2 = props.blocks) == null ? void 0 : _a2.length)) {
|
|
36
|
-
(_b = window.parent) == null
|
|
37
|
-
|
|
38
|
-
:
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
dataPath: props.path,
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
'*'
|
|
47
|
-
);
|
|
26
|
+
(_b = window.parent) == null ? void 0 : _b.postMessage({
|
|
27
|
+
type: "builder.hoverEmptyBlocks",
|
|
28
|
+
data: {
|
|
29
|
+
parentElementId: props.parent,
|
|
30
|
+
dataPath: props.path
|
|
31
|
+
}
|
|
32
|
+
}, "*");
|
|
48
33
|
}
|
|
49
34
|
}
|
|
50
|
-
return /* @__PURE__ */ React.createElement(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
dataSet: {
|
|
56
|
-
class: className(),
|
|
57
|
-
},
|
|
58
|
-
onClick: (event) => onClick(),
|
|
59
|
-
onMouseEnter: (event) => onMouseEnter(),
|
|
60
|
-
style: styles.view1,
|
|
35
|
+
return /* @__PURE__ */ React.createElement(View, {
|
|
36
|
+
"builder-path": props.path,
|
|
37
|
+
"builder-parent-id": props.parent,
|
|
38
|
+
dataSet: {
|
|
39
|
+
class: className()
|
|
61
40
|
},
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
/* @__PURE__ */ React.createElement(RenderBlock, {
|
|
70
|
-
block,
|
|
71
|
-
})
|
|
72
|
-
)
|
|
73
|
-
)
|
|
74
|
-
: null
|
|
75
|
-
);
|
|
41
|
+
onClick: (event) => onClick(),
|
|
42
|
+
onMouseEnter: (event) => onMouseEnter(),
|
|
43
|
+
style: styles.view1
|
|
44
|
+
}, props.blocks ? /* @__PURE__ */ React.createElement(React.Fragment, null, (_a = props.blocks) == null ? void 0 : _a.map((block) => /* @__PURE__ */ React.createElement(RenderBlock, {
|
|
45
|
+
key: block.id,
|
|
46
|
+
block
|
|
47
|
+
}))) : null);
|
|
76
48
|
}
|
|
77
49
|
const styles = StyleSheet.create({
|
|
78
|
-
view1: { display:
|
|
50
|
+
view1: { display: "flex", flexDirection: "column", alignItems: "stretch" }
|
|
79
51
|
});
|
|
80
|
-
export {
|
|
52
|
+
export {
|
|
53
|
+
RenderBlocks as default
|
|
54
|
+
};
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import { View, StyleSheet, Image, Text } from
|
|
3
|
-
import { isEditing } from
|
|
4
|
-
import RenderBlock from
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { View, StyleSheet, Image, Text } from "react-native";
|
|
3
|
+
import { isEditing } from "../functions/is-editing.js";
|
|
4
|
+
import RenderBlock from "./render-block/render-block.lite";
|
|
5
5
|
|
|
6
6
|
export default function RenderBlocks(props) {
|
|
7
7
|
function className() {
|
|
8
|
-
return
|
|
8
|
+
return "builder-blocks" + (!props.blocks?.length ? " no-blocks" : "");
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
function onClick() {
|
|
12
12
|
if (isEditing() && !props.blocks?.length) {
|
|
13
13
|
window.parent?.postMessage(
|
|
14
14
|
{
|
|
15
|
-
type:
|
|
15
|
+
type: "builder.clickEmptyBlocks",
|
|
16
16
|
data: {
|
|
17
17
|
parentElementId: props.parent,
|
|
18
18
|
dataPath: props.path,
|
|
19
19
|
},
|
|
20
20
|
},
|
|
21
|
-
|
|
21
|
+
"*"
|
|
22
22
|
);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -27,13 +27,13 @@ export default function RenderBlocks(props) {
|
|
|
27
27
|
if (isEditing() && !props.blocks?.length) {
|
|
28
28
|
window.parent?.postMessage(
|
|
29
29
|
{
|
|
30
|
-
type:
|
|
30
|
+
type: "builder.hoverEmptyBlocks",
|
|
31
31
|
data: {
|
|
32
32
|
parentElementId: props.parent,
|
|
33
33
|
dataPath: props.path,
|
|
34
34
|
},
|
|
35
35
|
},
|
|
36
|
-
|
|
36
|
+
"*"
|
|
37
37
|
);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
@@ -52,7 +52,7 @@ export default function RenderBlocks(props) {
|
|
|
52
52
|
{props.blocks ? (
|
|
53
53
|
<>
|
|
54
54
|
{props.blocks?.map((block) => (
|
|
55
|
-
<RenderBlock block={block} />
|
|
55
|
+
<RenderBlock key={block.id} block={block} />
|
|
56
56
|
))}
|
|
57
57
|
</>
|
|
58
58
|
) : null}
|
|
@@ -61,5 +61,5 @@ export default function RenderBlocks(props) {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
const styles = StyleSheet.create({
|
|
64
|
-
view1: { display:
|
|
64
|
+
view1: { display: "flex", flexDirection: "column", alignItems: "stretch" },
|
|
65
65
|
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import RenderInlinedStyles from "../../render-inlined-styles.js";
|
|
3
|
+
function RenderContentStyles(props) {
|
|
4
|
+
function getCssFromFont(font) {
|
|
5
|
+
var _a, _b;
|
|
6
|
+
const family = font.family + (font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
|
|
7
|
+
const name = family.split(",")[0];
|
|
8
|
+
const url = (_b = font.fileUrl) != null ? _b : (_a = font == null ? void 0 : font.files) == null ? void 0 : _a.regular;
|
|
9
|
+
let str = "";
|
|
10
|
+
if (url && family && name) {
|
|
11
|
+
str += `
|
|
12
|
+
@font-face {
|
|
13
|
+
font-family: "${family}";
|
|
14
|
+
src: local("${name}"), url('${url}') format('woff2');
|
|
15
|
+
font-display: fallback;
|
|
16
|
+
font-weight: 400;
|
|
17
|
+
}
|
|
18
|
+
`.trim();
|
|
19
|
+
}
|
|
20
|
+
if (font.files) {
|
|
21
|
+
for (const weight in font.files) {
|
|
22
|
+
const isNumber = String(Number(weight)) === weight;
|
|
23
|
+
if (!isNumber) {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
const weightUrl = font.files[weight];
|
|
27
|
+
if (weightUrl && weightUrl !== url) {
|
|
28
|
+
str += `
|
|
29
|
+
@font-face {
|
|
30
|
+
font-family: "${family}";
|
|
31
|
+
src: url('${weightUrl}') format('woff2');
|
|
32
|
+
font-display: fallback;
|
|
33
|
+
font-weight: ${weight};
|
|
34
|
+
}
|
|
35
|
+
`.trim();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return str;
|
|
40
|
+
}
|
|
41
|
+
function getFontCss({ customFonts }) {
|
|
42
|
+
var _a;
|
|
43
|
+
return ((_a = customFonts == null ? void 0 : customFonts.map((font) => getCssFromFont(font))) == null ? void 0 : _a.join(" ")) || "";
|
|
44
|
+
}
|
|
45
|
+
function injectedStyles() {
|
|
46
|
+
return `
|
|
47
|
+
${props.cssCode || ""}
|
|
48
|
+
${getFontCss({
|
|
49
|
+
customFonts: props.customFonts
|
|
50
|
+
})}`;
|
|
51
|
+
}
|
|
52
|
+
return /* @__PURE__ */ React.createElement(RenderInlinedStyles, {
|
|
53
|
+
styles: injectedStyles()
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
export {
|
|
57
|
+
RenderContentStyles as default
|
|
58
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { View, StyleSheet, Image, Text } from "react-native";
|
|
3
|
+
import RenderInlinedStyles from "../../render-inlined-styles.lite";
|
|
4
|
+
|
|
5
|
+
export default function RenderContentStyles(props) {
|
|
6
|
+
function getCssFromFont(font) {
|
|
7
|
+
// TODO: compute what font sizes are used and only load those.......
|
|
8
|
+
const family =
|
|
9
|
+
font.family +
|
|
10
|
+
(font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
|
|
11
|
+
const name = family.split(",")[0];
|
|
12
|
+
const url = font.fileUrl ?? font?.files?.regular;
|
|
13
|
+
let str = "";
|
|
14
|
+
|
|
15
|
+
if (url && family && name) {
|
|
16
|
+
str += `
|
|
17
|
+
@font-face {
|
|
18
|
+
font-family: "${family}";
|
|
19
|
+
src: local("${name}"), url('${url}') format('woff2');
|
|
20
|
+
font-display: fallback;
|
|
21
|
+
font-weight: 400;
|
|
22
|
+
}
|
|
23
|
+
`.trim();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (font.files) {
|
|
27
|
+
for (const weight in font.files) {
|
|
28
|
+
const isNumber = String(Number(weight)) === weight;
|
|
29
|
+
|
|
30
|
+
if (!isNumber) {
|
|
31
|
+
continue;
|
|
32
|
+
} // TODO: maybe limit number loaded
|
|
33
|
+
|
|
34
|
+
const weightUrl = font.files[weight];
|
|
35
|
+
|
|
36
|
+
if (weightUrl && weightUrl !== url) {
|
|
37
|
+
str += `
|
|
38
|
+
@font-face {
|
|
39
|
+
font-family: "${family}";
|
|
40
|
+
src: url('${weightUrl}') format('woff2');
|
|
41
|
+
font-display: fallback;
|
|
42
|
+
font-weight: ${weight};
|
|
43
|
+
}
|
|
44
|
+
`.trim();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return str;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function getFontCss({ customFonts }) {
|
|
53
|
+
// TODO: flag for this
|
|
54
|
+
// if (!builder.allowCustomFonts) {
|
|
55
|
+
// return '';
|
|
56
|
+
// }
|
|
57
|
+
// TODO: separate internal data from external
|
|
58
|
+
return customFonts?.map((font) => getCssFromFont(font))?.join(" ") || "";
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function injectedStyles() {
|
|
62
|
+
return `
|
|
63
|
+
${props.cssCode || ""}
|
|
64
|
+
${getFontCss({
|
|
65
|
+
customFonts: props.customFonts,
|
|
66
|
+
})}`;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return <RenderInlinedStyles styles={injectedStyles()} />;
|
|
70
|
+
}
|
|
@@ -0,0 +1,254 @@
|
|
|
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 __async = (__this, __arguments, generator) => {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
var fulfilled = (value) => {
|
|
23
|
+
try {
|
|
24
|
+
step(generator.next(value));
|
|
25
|
+
} catch (e) {
|
|
26
|
+
reject(e);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var rejected = (value) => {
|
|
30
|
+
try {
|
|
31
|
+
step(generator.throw(value));
|
|
32
|
+
} catch (e) {
|
|
33
|
+
reject(e);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
import * as React from "react";
|
|
41
|
+
import { View } from "react-native";
|
|
42
|
+
import { useState, useEffect } from "react";
|
|
43
|
+
import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
|
|
44
|
+
import { TARGET } from "../../constants/target.js";
|
|
45
|
+
import BuilderContext from "../../context/builder.context";
|
|
46
|
+
import { evaluate } from "../../functions/evaluate.js";
|
|
47
|
+
import {
|
|
48
|
+
convertSearchParamsToQueryObject,
|
|
49
|
+
getBuilderSearchParams
|
|
50
|
+
} from "../../functions/get-builder-search-params/index.js";
|
|
51
|
+
import { getContent } from "../../functions/get-content/index.js";
|
|
52
|
+
import { getFetch } from "../../functions/get-fetch.js";
|
|
53
|
+
import { isBrowser } from "../../functions/is-browser.js";
|
|
54
|
+
import { isEditing } from "../../functions/is-editing.js";
|
|
55
|
+
import { isPreviewing } from "../../functions/is-previewing.js";
|
|
56
|
+
import { previewingModelName } from "../../functions/previewing-model-name.js";
|
|
57
|
+
import {
|
|
58
|
+
components,
|
|
59
|
+
createRegisterComponentMessage
|
|
60
|
+
} from "../../functions/register-component.js";
|
|
61
|
+
import { track } from "../../functions/track.js";
|
|
62
|
+
import RenderBlocks from "../render-blocks.js";
|
|
63
|
+
import RenderContentStyles from "./components/render-styles.js";
|
|
64
|
+
function RenderContent(props) {
|
|
65
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
66
|
+
function useContent() {
|
|
67
|
+
var _a2;
|
|
68
|
+
const mergedContent = __spreadProps(__spreadValues(__spreadValues({}, props.content), overrideContent), {
|
|
69
|
+
data: __spreadValues(__spreadValues(__spreadValues({}, (_a2 = props.content) == null ? void 0 : _a2.data), props.data), overrideContent == null ? void 0 : overrideContent.data)
|
|
70
|
+
});
|
|
71
|
+
return mergedContent;
|
|
72
|
+
}
|
|
73
|
+
const [overrideContent, setOverrideContent] = useState(() => null);
|
|
74
|
+
const [update, setUpdate] = useState(() => 0);
|
|
75
|
+
const [overrideState, setOverrideState] = useState(() => ({}));
|
|
76
|
+
function contentState() {
|
|
77
|
+
var _a2, _b2;
|
|
78
|
+
return __spreadValues(__spreadValues(__spreadValues({}, (_b2 = (_a2 = props.content) == null ? void 0 : _a2.data) == null ? void 0 : _b2.state), props.data), overrideState);
|
|
79
|
+
}
|
|
80
|
+
function context() {
|
|
81
|
+
return {};
|
|
82
|
+
}
|
|
83
|
+
function allRegisteredComponents() {
|
|
84
|
+
const allComponentsArray = [
|
|
85
|
+
...getDefaultRegisteredComponents(),
|
|
86
|
+
...components,
|
|
87
|
+
...props.customComponents || []
|
|
88
|
+
];
|
|
89
|
+
const allComponents = allComponentsArray.reduce((acc, curr) => __spreadProps(__spreadValues({}, acc), { [curr.info.name]: curr }), {});
|
|
90
|
+
return allComponents;
|
|
91
|
+
}
|
|
92
|
+
function processMessage(event) {
|
|
93
|
+
const { data } = event;
|
|
94
|
+
if (data) {
|
|
95
|
+
switch (data.type) {
|
|
96
|
+
case "builder.contentUpdate": {
|
|
97
|
+
const messageContent = data.data;
|
|
98
|
+
const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
|
|
99
|
+
const contentData = messageContent.data;
|
|
100
|
+
if (key === props.model) {
|
|
101
|
+
setOverrideContent(contentData);
|
|
102
|
+
}
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
case "builder.patchUpdates": {
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function evaluateJsCode() {
|
|
112
|
+
var _a2, _b2;
|
|
113
|
+
const jsCode = (_b2 = (_a2 = useContent == null ? void 0 : useContent()) == null ? void 0 : _a2.data) == null ? void 0 : _b2.jsCode;
|
|
114
|
+
if (jsCode) {
|
|
115
|
+
evaluate({
|
|
116
|
+
code: jsCode,
|
|
117
|
+
context: context(),
|
|
118
|
+
state: contentState()
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function httpReqsData() {
|
|
123
|
+
return {};
|
|
124
|
+
}
|
|
125
|
+
function evalExpression(expression) {
|
|
126
|
+
return expression.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({
|
|
127
|
+
code: group,
|
|
128
|
+
context: context(),
|
|
129
|
+
state: contentState()
|
|
130
|
+
}));
|
|
131
|
+
}
|
|
132
|
+
function handleRequest({ url, key }) {
|
|
133
|
+
const fetchAndSetState = () => __async(this, null, function* () {
|
|
134
|
+
const fetch = yield getFetch();
|
|
135
|
+
const response = yield fetch(url);
|
|
136
|
+
const json = yield response.json();
|
|
137
|
+
const newOverrideState = __spreadProps(__spreadValues({}, overrideState), { [key]: json });
|
|
138
|
+
setOverrideState(newOverrideState);
|
|
139
|
+
});
|
|
140
|
+
fetchAndSetState();
|
|
141
|
+
}
|
|
142
|
+
function runHttpRequests() {
|
|
143
|
+
var _a2, _b2, _c2;
|
|
144
|
+
const requests = (_c2 = (_b2 = (_a2 = useContent == null ? void 0 : useContent()) == null ? void 0 : _a2.data) == null ? void 0 : _b2.httpRequests) != null ? _c2 : {};
|
|
145
|
+
Object.entries(requests).forEach(([key, url]) => {
|
|
146
|
+
if (url && (!httpReqsData()[key] || isEditing())) {
|
|
147
|
+
const evaluatedUrl = evalExpression(url);
|
|
148
|
+
handleRequest({
|
|
149
|
+
url: evaluatedUrl,
|
|
150
|
+
key
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
function emitStateUpdate() {
|
|
156
|
+
if (isEditing()) {
|
|
157
|
+
window.dispatchEvent(new CustomEvent("builder:component:stateChange", {
|
|
158
|
+
detail: {
|
|
159
|
+
state: contentState(),
|
|
160
|
+
ref: {
|
|
161
|
+
name: props.model
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
useEffect(() => {
|
|
168
|
+
if (isBrowser()) {
|
|
169
|
+
if (isEditing()) {
|
|
170
|
+
Object.values(allRegisteredComponents()).forEach((registeredComponent) => {
|
|
171
|
+
var _a2;
|
|
172
|
+
const message = createRegisterComponentMessage(registeredComponent);
|
|
173
|
+
(_a2 = window.parent) == null ? void 0 : _a2.postMessage(message, "*");
|
|
174
|
+
});
|
|
175
|
+
window.addEventListener("message", processMessage);
|
|
176
|
+
window.addEventListener("builder:component:stateChangeListenerActivated", emitStateUpdate);
|
|
177
|
+
}
|
|
178
|
+
if (useContent()) {
|
|
179
|
+
track("impression", {
|
|
180
|
+
contentId: useContent().id
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
if (isPreviewing()) {
|
|
184
|
+
if (props.model && previewingModelName() === props.model) {
|
|
185
|
+
const currentUrl = new URL(location.href);
|
|
186
|
+
const previewApiKey = currentUrl.searchParams.get("apiKey");
|
|
187
|
+
if (previewApiKey) {
|
|
188
|
+
getContent({
|
|
189
|
+
model: props.model,
|
|
190
|
+
apiKey: previewApiKey,
|
|
191
|
+
options: getBuilderSearchParams(convertSearchParamsToQueryObject(currentUrl.searchParams))
|
|
192
|
+
}).then((content) => {
|
|
193
|
+
if (content) {
|
|
194
|
+
setOverrideContent(content);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
evaluateJsCode();
|
|
201
|
+
runHttpRequests();
|
|
202
|
+
emitStateUpdate();
|
|
203
|
+
}
|
|
204
|
+
}, []);
|
|
205
|
+
useEffect(() => {
|
|
206
|
+
evaluateJsCode();
|
|
207
|
+
}, [(_b = (_a = useContent == null ? void 0 : useContent()) == null ? void 0 : _a.data) == null ? void 0 : _b.jsCode]);
|
|
208
|
+
useEffect(() => {
|
|
209
|
+
runHttpRequests();
|
|
210
|
+
}, [(_d = (_c = useContent == null ? void 0 : useContent()) == null ? void 0 : _c.data) == null ? void 0 : _d.httpRequests]);
|
|
211
|
+
useEffect(() => {
|
|
212
|
+
emitStateUpdate();
|
|
213
|
+
}, [contentState()]);
|
|
214
|
+
useEffect(() => {
|
|
215
|
+
return () => {
|
|
216
|
+
if (isBrowser()) {
|
|
217
|
+
window.removeEventListener("message", processMessage);
|
|
218
|
+
window.removeEventListener("builder:component:stateChangeListenerActivated", emitStateUpdate);
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
}, []);
|
|
222
|
+
return /* @__PURE__ */ React.createElement(BuilderContext.Provider, {
|
|
223
|
+
value: {
|
|
224
|
+
get content() {
|
|
225
|
+
return useContent();
|
|
226
|
+
},
|
|
227
|
+
get state() {
|
|
228
|
+
return contentState();
|
|
229
|
+
},
|
|
230
|
+
get context() {
|
|
231
|
+
return context();
|
|
232
|
+
},
|
|
233
|
+
get apiKey() {
|
|
234
|
+
return props.apiKey;
|
|
235
|
+
},
|
|
236
|
+
get registeredComponents() {
|
|
237
|
+
return allRegisteredComponents();
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}, useContent() ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(View, {
|
|
241
|
+
onClick: (event) => track("click", {
|
|
242
|
+
contentId: useContent().id
|
|
243
|
+
}),
|
|
244
|
+
"data-builder-content-id": (_e = useContent == null ? void 0 : useContent()) == null ? void 0 : _e.id
|
|
245
|
+
}, (((_g = (_f = useContent == null ? void 0 : useContent()) == null ? void 0 : _f.data) == null ? void 0 : _g.cssCode) || ((_j = (_i = (_h = useContent == null ? void 0 : useContent()) == null ? void 0 : _h.data) == null ? void 0 : _i.customFonts) == null ? void 0 : _j.length)) && TARGET !== "reactNative" ? /* @__PURE__ */ React.createElement(RenderContentStyles, {
|
|
246
|
+
cssCode: useContent().data.cssCode,
|
|
247
|
+
customFonts: useContent().data.customFonts
|
|
248
|
+
}) : null, /* @__PURE__ */ React.createElement(RenderBlocks, {
|
|
249
|
+
blocks: (_l = (_k = useContent == null ? void 0 : useContent()) == null ? void 0 : _k.data) == null ? void 0 : _l.blocks
|
|
250
|
+
}))) : null);
|
|
251
|
+
}
|
|
252
|
+
export {
|
|
253
|
+
RenderContent as default
|
|
254
|
+
};
|