@builder.io/sdk-react-native 0.0.1-56 → 0.0.1-59
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 +5 -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 -18
- package/src/constants/device-sizes.js +3 -21
- package/src/functions/camel-to-kebab-case.js +5 -0
- package/src/helpers/css.js +13 -0
- 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.js +0 -25
- package/src/components/error-boundary.lite.tsx +0 -6
- package/src/components/render-block/block-styles.lite.tsx +0 -57
- package/src/components/render-block/render-block.lite.tsx +0 -148
- package/src/components/render-block/render-component.lite.tsx +0 -26
- package/src/components/render-blocks.lite.tsx +0 -74
- 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,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
|
-
}
|