@builder.io/sdk-react-native 0.0.1-55 → 0.0.1-58
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 +10 -1
- package/README.md +4 -0
- package/package.json +1 -1
- package/src/blocks/custom-code/custom-code.js +1 -1
- package/src/blocks/embed/embed.js +1 -1
- package/src/blocks/form/form.js +1 -1
- package/src/components/render-block/block-styles.js +16 -4
- package/src/components/render-block/render-block.js +26 -29
- package/src/components/render-block/render-component.js +33 -0
- package/src/components/render-blocks.js +10 -6
- package/src/functions/get-block-component-options.js +6 -1
- package/src/blocks/button/button.lite.tsx +0 -25
- package/src/blocks/columns/columns.lite.tsx +0 -70
- package/src/blocks/custom-code/custom-code.lite.tsx +0 -59
- package/src/blocks/embed/embed.lite.tsx +0 -61
- package/src/blocks/form/form.lite.tsx +0 -254
- package/src/blocks/fragment/fragment.lite.tsx +0 -10
- package/src/blocks/image/image.lite.tsx +0 -67
- package/src/blocks/img/img.lite.tsx +0 -18
- package/src/blocks/input/input.lite.tsx +0 -20
- package/src/blocks/raw-text/raw-text.lite.tsx +0 -6
- package/src/blocks/section/section.lite.tsx +0 -19
- package/src/blocks/select/select.lite.tsx +0 -23
- package/src/blocks/submit-button/submit-button.lite.tsx +0 -10
- package/src/blocks/symbol/symbol.lite.tsx +0 -60
- package/src/blocks/text/text.lite.tsx +0 -6
- package/src/blocks/textarea/textarea.lite.tsx +0 -14
- package/src/blocks/video/video.lite.tsx +0 -27
- package/src/components/error-boundary.lite.tsx +0 -6
- package/src/components/render-block/block-styles.lite.tsx +0 -35
- package/src/components/render-block/render-block.lite.tsx +0 -144
- package/src/components/render-blocks.lite.tsx +0 -65
- package/src/components/render-content/components/render-styles.lite.tsx +0 -70
- package/src/components/render-content/render-content.lite.tsx +0 -283
- package/src/components/render-inlined-styles.lite.tsx +0 -31
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { View, StyleSheet, Image, Text } from "react-native";
|
|
3
|
-
import { useContext } from "react";
|
|
4
|
-
import { TARGET } from "../../constants/target.js";
|
|
5
|
-
import BuilderContext from "../../context/builder.context";
|
|
6
|
-
import { getBlockActions } from "../../functions/get-block-actions.js";
|
|
7
|
-
import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
|
|
8
|
-
import { getBlockProperties } from "../../functions/get-block-properties.js";
|
|
9
|
-
import { getBlockStyles } from "../../functions/get-block-styles.js";
|
|
10
|
-
import { getBlockTag } from "../../functions/get-block-tag.js";
|
|
11
|
-
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
12
|
-
import BlockStyles from "./block-styles.lite";
|
|
13
|
-
import { isEmptyHtmlElement } from "./render-block.helpers.js";
|
|
14
|
-
|
|
15
|
-
export default function RenderBlock(props) {
|
|
16
|
-
function component() {
|
|
17
|
-
const componentName = useBlock().component?.name;
|
|
18
|
-
|
|
19
|
-
if (!componentName) {
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const ref = builderContext.registeredComponents[componentName];
|
|
24
|
-
|
|
25
|
-
if (!ref) {
|
|
26
|
-
// TODO: Public doc page with more info about this message
|
|
27
|
-
console.warn(`
|
|
28
|
-
Could not find a registered component named "${componentName}".
|
|
29
|
-
If you registered it, is the file that registered it imported by the file that needs to render it?`);
|
|
30
|
-
return undefined;
|
|
31
|
-
} else {
|
|
32
|
-
return ref;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function componentInfo() {
|
|
37
|
-
if (component()) {
|
|
38
|
-
const { component: _, ...info } = component();
|
|
39
|
-
return info;
|
|
40
|
-
} else {
|
|
41
|
-
return undefined;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function componentRef() {
|
|
46
|
-
return component?.()?.component;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function tagName() {
|
|
50
|
-
return getBlockTag(useBlock());
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function useBlock() {
|
|
54
|
-
return getProcessedBlock({
|
|
55
|
-
block: props.block,
|
|
56
|
-
state: builderContext.state,
|
|
57
|
-
context: builderContext.context,
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function propertiesAndActions() {
|
|
62
|
-
return {
|
|
63
|
-
...getBlockProperties(useBlock()),
|
|
64
|
-
...getBlockActions({
|
|
65
|
-
block: useBlock(),
|
|
66
|
-
state: builderContext.state,
|
|
67
|
-
context: builderContext.context,
|
|
68
|
-
}),
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function css() {
|
|
73
|
-
return getBlockStyles(useBlock());
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function componentOptions() {
|
|
77
|
-
return getBlockComponentOptions(useBlock());
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function children() {
|
|
81
|
-
// TO-DO: When should `canHaveChildren` dictate rendering?
|
|
82
|
-
// This is currently commented out because some Builder components (e.g. Box) do not have `canHaveChildren: true`,
|
|
83
|
-
// but still receive and need to render children.
|
|
84
|
-
// return componentInfo?.()?.canHaveChildren ? useBlock().children : [];
|
|
85
|
-
return useBlock().children ?? [];
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function noCompRefChildren() {
|
|
89
|
-
return componentRef() ? [] : children();
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const builderContext = useContext(BuilderContext);
|
|
93
|
-
|
|
94
|
-
const ComponentRefRef = componentRef();
|
|
95
|
-
const TagNameRef = tagName();
|
|
96
|
-
|
|
97
|
-
return (
|
|
98
|
-
<>
|
|
99
|
-
{!componentInfo?.()?.noWrap ? (
|
|
100
|
-
<>
|
|
101
|
-
{!isEmptyHtmlElement(tagName()) ? (
|
|
102
|
-
<>
|
|
103
|
-
<TagNameRef {...propertiesAndActions()} style={css()}>
|
|
104
|
-
{TARGET === "vue" || TARGET === "svelte" ? (
|
|
105
|
-
<>
|
|
106
|
-
<BlockStyles block={useBlock()} />
|
|
107
|
-
</>
|
|
108
|
-
) : null}
|
|
109
|
-
|
|
110
|
-
{componentRef() ? (
|
|
111
|
-
<ComponentRefRef
|
|
112
|
-
{...componentOptions()}
|
|
113
|
-
builderBlock={useBlock()}
|
|
114
|
-
>
|
|
115
|
-
{children()?.map((child) => (
|
|
116
|
-
<RenderBlock key={child.id} block={child} />
|
|
117
|
-
))}
|
|
118
|
-
</ComponentRefRef>
|
|
119
|
-
) : null}
|
|
120
|
-
|
|
121
|
-
{noCompRefChildren()?.map((child) => (
|
|
122
|
-
<RenderBlock key={child.id} block={child} />
|
|
123
|
-
))}
|
|
124
|
-
</TagNameRef>
|
|
125
|
-
</>
|
|
126
|
-
) : (
|
|
127
|
-
<TagNameRef {...propertiesAndActions()} style={css()} />
|
|
128
|
-
)}
|
|
129
|
-
</>
|
|
130
|
-
) : (
|
|
131
|
-
<ComponentRefRef
|
|
132
|
-
{...componentOptions()}
|
|
133
|
-
attributes={propertiesAndActions()}
|
|
134
|
-
builderBlock={useBlock()}
|
|
135
|
-
style={css()}
|
|
136
|
-
>
|
|
137
|
-
{children()?.map((child) => (
|
|
138
|
-
<RenderBlock key={child.id} block={child} />
|
|
139
|
-
))}
|
|
140
|
-
</ComponentRefRef>
|
|
141
|
-
)}
|
|
142
|
-
</>
|
|
143
|
-
);
|
|
144
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
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
|
-
|
|
6
|
-
export default function RenderBlocks(props) {
|
|
7
|
-
function className() {
|
|
8
|
-
return "builder-blocks" + (!props.blocks?.length ? " no-blocks" : "");
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function onClick() {
|
|
12
|
-
if (isEditing() && !props.blocks?.length) {
|
|
13
|
-
window.parent?.postMessage(
|
|
14
|
-
{
|
|
15
|
-
type: "builder.clickEmptyBlocks",
|
|
16
|
-
data: {
|
|
17
|
-
parentElementId: props.parent,
|
|
18
|
-
dataPath: props.path,
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
"*"
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function onMouseEnter() {
|
|
27
|
-
if (isEditing() && !props.blocks?.length) {
|
|
28
|
-
window.parent?.postMessage(
|
|
29
|
-
{
|
|
30
|
-
type: "builder.hoverEmptyBlocks",
|
|
31
|
-
data: {
|
|
32
|
-
parentElementId: props.parent,
|
|
33
|
-
dataPath: props.path,
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
"*"
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return (
|
|
42
|
-
<View
|
|
43
|
-
builder-path={props.path}
|
|
44
|
-
builder-parent-id={props.parent}
|
|
45
|
-
dataSet={{
|
|
46
|
-
class: className(),
|
|
47
|
-
}}
|
|
48
|
-
onClick={(event) => onClick()}
|
|
49
|
-
onMouseEnter={(event) => onMouseEnter()}
|
|
50
|
-
style={styles.view1}
|
|
51
|
-
>
|
|
52
|
-
{props.blocks ? (
|
|
53
|
-
<>
|
|
54
|
-
{props.blocks?.map((block) => (
|
|
55
|
-
<RenderBlock key={block.id} block={block} />
|
|
56
|
-
))}
|
|
57
|
-
</>
|
|
58
|
-
) : null}
|
|
59
|
-
</View>
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const styles = StyleSheet.create({
|
|
64
|
-
view1: { display: "flex", flexDirection: "column", alignItems: "stretch" },
|
|
65
|
-
});
|
|
@@ -1,70 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,283 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { View, StyleSheet, Image, Text } from "react-native";
|
|
3
|
-
import { useState, useContext, useEffect } from "react";
|
|
4
|
-
import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
|
|
5
|
-
import { TARGET } from "../../constants/target.js";
|
|
6
|
-
import BuilderContext from "../../context/builder.context";
|
|
7
|
-
import { evaluate } from "../../functions/evaluate.js";
|
|
8
|
-
import {
|
|
9
|
-
convertSearchParamsToQueryObject,
|
|
10
|
-
getBuilderSearchParams,
|
|
11
|
-
} from "../../functions/get-builder-search-params/index.js";
|
|
12
|
-
import { getContent } from "../../functions/get-content/index.js";
|
|
13
|
-
import { getFetch } from "../../functions/get-fetch.js";
|
|
14
|
-
import { isBrowser } from "../../functions/is-browser.js";
|
|
15
|
-
import { isEditing } from "../../functions/is-editing.js";
|
|
16
|
-
import { isPreviewing } from "../../functions/is-previewing.js";
|
|
17
|
-
import { previewingModelName } from "../../functions/previewing-model-name.js";
|
|
18
|
-
import {
|
|
19
|
-
components,
|
|
20
|
-
createRegisterComponentMessage,
|
|
21
|
-
} from "../../functions/register-component.js";
|
|
22
|
-
import { track } from "../../functions/track.js";
|
|
23
|
-
import RenderBlocks from "../render-blocks.lite";
|
|
24
|
-
import RenderContentStyles from "./components/render-styles.lite";
|
|
25
|
-
|
|
26
|
-
export default function RenderContent(props) {
|
|
27
|
-
function useContent() {
|
|
28
|
-
const mergedContent = {
|
|
29
|
-
...props.content,
|
|
30
|
-
...overrideContent,
|
|
31
|
-
data: { ...props.content?.data, ...props.data, ...overrideContent?.data },
|
|
32
|
-
};
|
|
33
|
-
return mergedContent;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const [overrideContent, setOverrideContent] = useState(() => null);
|
|
37
|
-
|
|
38
|
-
const [update, setUpdate] = useState(() => 0);
|
|
39
|
-
|
|
40
|
-
const [overrideState, setOverrideState] = useState(() => ({}));
|
|
41
|
-
|
|
42
|
-
function contentState() {
|
|
43
|
-
return { ...props.content?.data?.state, ...props.data, ...overrideState };
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function context() {
|
|
47
|
-
return {};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function allRegisteredComponents() {
|
|
51
|
-
const allComponentsArray = [
|
|
52
|
-
...getDefaultRegisteredComponents(), // While this `components` object is deprecated, we must maintain support for it.
|
|
53
|
-
// Since users are able to override our default components, we need to make sure that we do not break such
|
|
54
|
-
// existing usage.
|
|
55
|
-
// This is why we spread `components` after the default Builder.io components, but before the `props.customComponents`,
|
|
56
|
-
// which is the new standard way of providing custom components, and must therefore take precedence.
|
|
57
|
-
...components,
|
|
58
|
-
...(props.customComponents || []),
|
|
59
|
-
];
|
|
60
|
-
const allComponents = allComponentsArray.reduce(
|
|
61
|
-
(acc, curr) => ({ ...acc, [curr.name]: curr }),
|
|
62
|
-
{}
|
|
63
|
-
);
|
|
64
|
-
return allComponents;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function processMessage(event) {
|
|
68
|
-
const { data } = event;
|
|
69
|
-
|
|
70
|
-
if (data) {
|
|
71
|
-
switch (data.type) {
|
|
72
|
-
case "builder.contentUpdate": {
|
|
73
|
-
const messageContent = data.data;
|
|
74
|
-
const key =
|
|
75
|
-
messageContent.key ||
|
|
76
|
-
messageContent.alias ||
|
|
77
|
-
messageContent.entry ||
|
|
78
|
-
messageContent.modelName;
|
|
79
|
-
const contentData = messageContent.data;
|
|
80
|
-
|
|
81
|
-
if (key === props.model) {
|
|
82
|
-
setOverrideContent(contentData);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
case "builder.patchUpdates": {
|
|
89
|
-
// TODO
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function evaluateJsCode() {
|
|
97
|
-
// run any dynamic JS code attached to content
|
|
98
|
-
const jsCode = useContent?.()?.data?.jsCode;
|
|
99
|
-
|
|
100
|
-
if (jsCode) {
|
|
101
|
-
evaluate({
|
|
102
|
-
code: jsCode,
|
|
103
|
-
context: context(),
|
|
104
|
-
state: contentState(),
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function httpReqsData() {
|
|
110
|
-
return {};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function evalExpression(expression) {
|
|
114
|
-
return expression.replace(/{{([^}]+)}}/g, (_match, group) =>
|
|
115
|
-
evaluate({
|
|
116
|
-
code: group,
|
|
117
|
-
context: context(),
|
|
118
|
-
state: contentState(),
|
|
119
|
-
})
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function handleRequest({ url, key }) {
|
|
124
|
-
const fetchAndSetState = async () => {
|
|
125
|
-
const fetch = await getFetch();
|
|
126
|
-
const response = await fetch(url);
|
|
127
|
-
const json = await response.json();
|
|
128
|
-
const newOverrideState = { ...overrideState, [key]: json };
|
|
129
|
-
setOverrideState(newOverrideState);
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
fetchAndSetState();
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function runHttpRequests() {
|
|
136
|
-
const requests = useContent?.()?.data?.httpRequests ?? {};
|
|
137
|
-
Object.entries(requests).forEach(([key, url]) => {
|
|
138
|
-
if (url && (!httpReqsData()[key] || isEditing())) {
|
|
139
|
-
const evaluatedUrl = evalExpression(url);
|
|
140
|
-
handleRequest({
|
|
141
|
-
url: evaluatedUrl,
|
|
142
|
-
key,
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function emitStateUpdate() {
|
|
149
|
-
if (isEditing()) {
|
|
150
|
-
window.dispatchEvent(
|
|
151
|
-
new CustomEvent("builder:component:stateChange", {
|
|
152
|
-
detail: {
|
|
153
|
-
state: contentState(),
|
|
154
|
-
ref: {
|
|
155
|
-
name: props.model,
|
|
156
|
-
},
|
|
157
|
-
},
|
|
158
|
-
})
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
useEffect(() => {
|
|
164
|
-
if (isBrowser()) {
|
|
165
|
-
if (isEditing()) {
|
|
166
|
-
Object.values(allRegisteredComponents()).forEach(
|
|
167
|
-
(registeredComponent) => {
|
|
168
|
-
const message = createRegisterComponentMessage(registeredComponent);
|
|
169
|
-
window.parent?.postMessage(message, "*");
|
|
170
|
-
}
|
|
171
|
-
);
|
|
172
|
-
window.addEventListener("message", processMessage);
|
|
173
|
-
window.addEventListener(
|
|
174
|
-
"builder:component:stateChangeListenerActivated",
|
|
175
|
-
emitStateUpdate
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
if (useContent()) {
|
|
180
|
-
track("impression", {
|
|
181
|
-
contentId: useContent().id,
|
|
182
|
-
});
|
|
183
|
-
} // override normal content in preview mode
|
|
184
|
-
|
|
185
|
-
if (isPreviewing()) {
|
|
186
|
-
if (props.model && previewingModelName() === props.model) {
|
|
187
|
-
const currentUrl = new URL(location.href);
|
|
188
|
-
const previewApiKey = currentUrl.searchParams.get("apiKey");
|
|
189
|
-
|
|
190
|
-
if (previewApiKey) {
|
|
191
|
-
getContent({
|
|
192
|
-
model: props.model,
|
|
193
|
-
apiKey: previewApiKey,
|
|
194
|
-
options: getBuilderSearchParams(
|
|
195
|
-
convertSearchParamsToQueryObject(currentUrl.searchParams)
|
|
196
|
-
),
|
|
197
|
-
}).then((content) => {
|
|
198
|
-
if (content) {
|
|
199
|
-
setOverrideContent(content);
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
evaluateJsCode();
|
|
207
|
-
runHttpRequests();
|
|
208
|
-
emitStateUpdate();
|
|
209
|
-
}
|
|
210
|
-
}, []);
|
|
211
|
-
|
|
212
|
-
useEffect(() => {
|
|
213
|
-
evaluateJsCode();
|
|
214
|
-
}, [useContent?.()?.data?.jsCode]);
|
|
215
|
-
useEffect(() => {
|
|
216
|
-
runHttpRequests();
|
|
217
|
-
}, [useContent?.()?.data?.httpRequests]);
|
|
218
|
-
useEffect(() => {
|
|
219
|
-
emitStateUpdate();
|
|
220
|
-
}, [contentState()]);
|
|
221
|
-
|
|
222
|
-
useEffect(() => {
|
|
223
|
-
return () => {
|
|
224
|
-
if (isBrowser()) {
|
|
225
|
-
window.removeEventListener("message", processMessage);
|
|
226
|
-
window.removeEventListener(
|
|
227
|
-
"builder:component:stateChangeListenerActivated",
|
|
228
|
-
emitStateUpdate
|
|
229
|
-
);
|
|
230
|
-
}
|
|
231
|
-
};
|
|
232
|
-
}, []);
|
|
233
|
-
|
|
234
|
-
return (
|
|
235
|
-
<BuilderContext.Provider
|
|
236
|
-
value={{
|
|
237
|
-
get content() {
|
|
238
|
-
return useContent();
|
|
239
|
-
},
|
|
240
|
-
|
|
241
|
-
get state() {
|
|
242
|
-
return contentState();
|
|
243
|
-
},
|
|
244
|
-
|
|
245
|
-
get context() {
|
|
246
|
-
return context();
|
|
247
|
-
},
|
|
248
|
-
|
|
249
|
-
get apiKey() {
|
|
250
|
-
return props.apiKey;
|
|
251
|
-
},
|
|
252
|
-
|
|
253
|
-
get registeredComponents() {
|
|
254
|
-
return allRegisteredComponents();
|
|
255
|
-
},
|
|
256
|
-
}}
|
|
257
|
-
>
|
|
258
|
-
{useContent() ? (
|
|
259
|
-
<>
|
|
260
|
-
<View
|
|
261
|
-
onClick={(event) =>
|
|
262
|
-
track("click", {
|
|
263
|
-
contentId: useContent().id,
|
|
264
|
-
})
|
|
265
|
-
}
|
|
266
|
-
data-builder-content-id={useContent?.()?.id}
|
|
267
|
-
>
|
|
268
|
-
{(useContent?.()?.data?.cssCode ||
|
|
269
|
-
useContent?.()?.data?.customFonts?.length) &&
|
|
270
|
-
TARGET !== "reactNative" ? (
|
|
271
|
-
<RenderContentStyles
|
|
272
|
-
cssCode={useContent().data.cssCode}
|
|
273
|
-
customFonts={useContent().data.customFonts}
|
|
274
|
-
/>
|
|
275
|
-
) : null}
|
|
276
|
-
|
|
277
|
-
<RenderBlocks blocks={useContent?.()?.data?.blocks} />
|
|
278
|
-
</View>
|
|
279
|
-
</>
|
|
280
|
-
) : null}
|
|
281
|
-
</BuilderContext.Provider>
|
|
282
|
-
);
|
|
283
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { View, StyleSheet, Image, Text } from "react-native";
|
|
3
|
-
import { TARGET } from "../constants/target.js";
|
|
4
|
-
|
|
5
|
-
export default function RenderInlinedStyles(props) {
|
|
6
|
-
function injectedStyleScript() {
|
|
7
|
-
return `<${tagName()}>${props.styles}</${tagName()}>`;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function tagName() {
|
|
11
|
-
// NOTE: we have to obfusctate the name of the tag due to a limitation in the svelte-preprocessor plugin.
|
|
12
|
-
// https://github.com/sveltejs/vite-plugin-svelte/issues/315#issuecomment-1109000027
|
|
13
|
-
return "sty" + "le";
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const TagNameRef = tagName();
|
|
17
|
-
|
|
18
|
-
return (
|
|
19
|
-
<>
|
|
20
|
-
{TARGET === "svelte" ? (
|
|
21
|
-
<>
|
|
22
|
-
<View dangerouslySetInnerHTML={{ __html: injectedStyleScript() }} />
|
|
23
|
-
</>
|
|
24
|
-
) : (
|
|
25
|
-
<TagNameRef>
|
|
26
|
-
<Text>{props.styles}</Text>
|
|
27
|
-
</TagNameRef>
|
|
28
|
-
)}
|
|
29
|
-
</>
|
|
30
|
-
);
|
|
31
|
-
}
|