@builder.io/sdk-react-native 0.1.4 → 0.1.6
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/button/component-info.js +0 -1
- package/dist/blocks/columns/component-info.js +0 -1
- package/dist/blocks/custom-code/component-info.js +0 -1
- package/dist/blocks/embed/component-info.js +0 -1
- package/dist/blocks/form/component-info.js +0 -1
- package/dist/blocks/fragment/component-info.js +0 -1
- package/dist/blocks/image/component-info.js +0 -1
- package/dist/blocks/img/component-info.js +0 -1
- package/dist/blocks/input/component-info.js +0 -1
- package/dist/blocks/raw-text/component-info.js +0 -1
- package/dist/blocks/section/component-info.js +0 -1
- package/dist/blocks/select/component-info.js +0 -1
- package/dist/blocks/submit-button/component-info.js +0 -1
- package/dist/blocks/symbol/component-info.js +0 -1
- package/dist/blocks/text/component-info.js +0 -1
- package/dist/blocks/textarea/component-info.js +0 -1
- package/dist/blocks/video/component-info.js +0 -1
- package/dist/components/render-block/render-block.js +19 -1
- package/dist/components/render-block/render-repeated-block.js +1 -0
- package/dist/components/render-content/components/render-styles.helpers.js +55 -0
- package/dist/components/render-content/components/render-styles.js +13 -57
- package/dist/components/render-content/render-content.helpers.js +42 -0
- package/dist/components/render-content/render-content.js +70 -71
- package/dist/components/render-content/render-content.types.js +1 -0
- package/dist/context/builder.context.js +2 -0
- package/dist/types/input.js +1 -0
- package/package.json +1 -1
- package/src/blocks/button/component-info.js +0 -1
- package/src/blocks/columns/component-info.js +0 -1
- package/src/blocks/custom-code/component-info.js +0 -1
- package/src/blocks/embed/component-info.js +0 -1
- package/src/blocks/form/component-info.js +0 -1
- package/src/blocks/fragment/component-info.js +0 -1
- package/src/blocks/image/component-info.js +0 -1
- package/src/blocks/img/component-info.js +0 -1
- package/src/blocks/input/component-info.js +0 -1
- package/src/blocks/raw-text/component-info.js +0 -1
- package/src/blocks/section/component-info.js +0 -1
- package/src/blocks/select/component-info.js +0 -1
- package/src/blocks/submit-button/component-info.js +0 -1
- package/src/blocks/symbol/component-info.js +0 -1
- package/src/blocks/text/component-info.js +0 -1
- package/src/blocks/textarea/component-info.js +0 -1
- package/src/blocks/video/component-info.js +0 -1
- package/src/components/render-block/render-block.jsx +22 -1
- package/src/components/render-block/render-repeated-block.jsx +1 -0
- package/src/components/render-content/components/render-styles.helpers.js +57 -0
- package/src/components/render-content/components/render-styles.jsx +13 -56
- package/src/components/render-content/render-content.helpers.js +48 -0
- package/src/components/render-content/render-content.jsx +76 -67
- package/src/components/render-content/render-content.types.js +0 -0
- package/src/context/builder.context.js +2 -0
- package/src/types/input.js +0 -0
|
@@ -23,6 +23,10 @@ import {
|
|
|
23
23
|
} from "../../scripts/init-editing.js";
|
|
24
24
|
import { checkIsDefined } from "../../helpers/nullable.js";
|
|
25
25
|
import { getInteractionPropertiesForEvent } from "../../functions/track/interaction.js";
|
|
26
|
+
import {
|
|
27
|
+
getContentInitialValue,
|
|
28
|
+
getContextStateInitialValue,
|
|
29
|
+
} from "./render-content.helpers.js";
|
|
26
30
|
|
|
27
31
|
export default function RenderContent(props) {
|
|
28
32
|
const elementRef = useRef(null);
|
|
@@ -30,56 +34,58 @@ export default function RenderContent(props) {
|
|
|
30
34
|
|
|
31
35
|
const [overrideContent, setOverrideContent] = useState(() => null);
|
|
32
36
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
const [useContent, setUseContent] = useState(() =>
|
|
38
|
+
getContentInitialValue({
|
|
39
|
+
content: props.content,
|
|
40
|
+
data: props.data,
|
|
41
|
+
})
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
function mergeNewContent(newContent) {
|
|
45
|
+
setUseContent({
|
|
46
|
+
...useContent,
|
|
47
|
+
...newContent,
|
|
40
48
|
data: {
|
|
41
|
-
...
|
|
42
|
-
...
|
|
43
|
-
...overrideContent?.data,
|
|
49
|
+
...useContent?.data,
|
|
50
|
+
...newContent?.data,
|
|
44
51
|
},
|
|
45
52
|
meta: {
|
|
46
|
-
...
|
|
47
|
-
...
|
|
53
|
+
...useContent?.meta,
|
|
54
|
+
...newContent?.meta,
|
|
48
55
|
breakpoints:
|
|
49
|
-
|
|
50
|
-
overrideContent?.meta?.breakpoints ||
|
|
51
|
-
props.content?.meta?.breakpoints,
|
|
56
|
+
newContent?.meta?.breakpoints || useContent?.meta?.breakpoints,
|
|
52
57
|
},
|
|
53
|
-
};
|
|
58
|
+
});
|
|
54
59
|
}
|
|
55
60
|
|
|
56
|
-
|
|
61
|
+
function setBreakpoints(breakpoints) {
|
|
62
|
+
setUseContent({
|
|
63
|
+
...useContent,
|
|
64
|
+
meta: {
|
|
65
|
+
...useContent?.meta,
|
|
66
|
+
breakpoints,
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
}
|
|
57
70
|
|
|
58
|
-
const [
|
|
71
|
+
const [update, setUpdate] = useState(() => 0);
|
|
59
72
|
|
|
60
73
|
const [canTrackToUse, setCanTrackToUse] = useState(() =>
|
|
61
74
|
checkIsDefined(props.canTrack) ? props.canTrack : true
|
|
62
75
|
);
|
|
63
76
|
|
|
64
|
-
const [
|
|
77
|
+
const [contentState, setContentState] = useState(() =>
|
|
78
|
+
getContextStateInitialValue({
|
|
79
|
+
content: props.content,
|
|
80
|
+
data: props.data,
|
|
81
|
+
locale: props.locale,
|
|
82
|
+
})
|
|
83
|
+
);
|
|
65
84
|
|
|
66
|
-
function
|
|
67
|
-
|
|
68
|
-
...props.content?.data?.state,
|
|
69
|
-
...props.data,
|
|
70
|
-
...(props.locale
|
|
71
|
-
? {
|
|
72
|
-
locale: props.locale,
|
|
73
|
-
}
|
|
74
|
-
: {}),
|
|
75
|
-
...overrideState,
|
|
76
|
-
};
|
|
85
|
+
function setContextState(newState) {
|
|
86
|
+
setContentState(newState);
|
|
77
87
|
}
|
|
78
88
|
|
|
79
|
-
const [contextContext, setContextContext] = useState(
|
|
80
|
-
() => props.context || {}
|
|
81
|
-
);
|
|
82
|
-
|
|
83
89
|
const [allRegisteredComponents, setAllRegisteredComponents] = useState(() =>
|
|
84
90
|
[
|
|
85
91
|
...getDefaultRegisteredComponents(),
|
|
@@ -106,10 +112,12 @@ export default function RenderContent(props) {
|
|
|
106
112
|
case "builder.configureSdk": {
|
|
107
113
|
const messageContent = data.data;
|
|
108
114
|
const { breakpoints, contentId } = messageContent;
|
|
109
|
-
if (!contentId || contentId !== useContent?.
|
|
115
|
+
if (!contentId || contentId !== useContent?.id) {
|
|
110
116
|
return;
|
|
111
117
|
}
|
|
112
|
-
|
|
118
|
+
if (breakpoints) {
|
|
119
|
+
setBreakpoints(breakpoints);
|
|
120
|
+
}
|
|
113
121
|
setForceReRenderCount(forceReRenderCount + 1); // This is a hack to force Qwik to re-render.
|
|
114
122
|
break;
|
|
115
123
|
}
|
|
@@ -122,7 +130,7 @@ export default function RenderContent(props) {
|
|
|
122
130
|
messageContent.modelName;
|
|
123
131
|
const contentData = messageContent.data;
|
|
124
132
|
if (key === props.model) {
|
|
125
|
-
|
|
133
|
+
mergeNewContent(contentData);
|
|
126
134
|
setForceReRenderCount(forceReRenderCount + 1); // This is a hack to force Qwik to re-render.
|
|
127
135
|
}
|
|
128
136
|
|
|
@@ -138,12 +146,12 @@ export default function RenderContent(props) {
|
|
|
138
146
|
|
|
139
147
|
function evaluateJsCode() {
|
|
140
148
|
// run any dynamic JS code attached to content
|
|
141
|
-
const jsCode = useContent?.
|
|
149
|
+
const jsCode = useContent?.data?.jsCode;
|
|
142
150
|
if (jsCode) {
|
|
143
151
|
evaluate({
|
|
144
152
|
code: jsCode,
|
|
145
|
-
context:
|
|
146
|
-
state: contentState
|
|
153
|
+
context: props.context || {},
|
|
154
|
+
state: contentState,
|
|
147
155
|
});
|
|
148
156
|
}
|
|
149
157
|
}
|
|
@@ -153,9 +161,9 @@ export default function RenderContent(props) {
|
|
|
153
161
|
const [clicked, setClicked] = useState(() => false);
|
|
154
162
|
|
|
155
163
|
function onClick(event) {
|
|
156
|
-
if (useContent
|
|
157
|
-
const variationId = useContent?.
|
|
158
|
-
const contentId = useContent?.
|
|
164
|
+
if (useContent) {
|
|
165
|
+
const variationId = useContent?.testVariationId;
|
|
166
|
+
const contentId = useContent?.id;
|
|
159
167
|
_track({
|
|
160
168
|
type: "click",
|
|
161
169
|
canTrack: canTrackToUse,
|
|
@@ -175,8 +183,8 @@ export default function RenderContent(props) {
|
|
|
175
183
|
return expression.replace(/{{([^}]+)}}/g, (_match, group) =>
|
|
176
184
|
evaluate({
|
|
177
185
|
code: group,
|
|
178
|
-
context:
|
|
179
|
-
state: contentState
|
|
186
|
+
context: props.context || {},
|
|
187
|
+
state: contentState,
|
|
180
188
|
})
|
|
181
189
|
);
|
|
182
190
|
}
|
|
@@ -185,11 +193,11 @@ export default function RenderContent(props) {
|
|
|
185
193
|
fetch(url)
|
|
186
194
|
.then((response) => response.json())
|
|
187
195
|
.then((json) => {
|
|
188
|
-
const
|
|
189
|
-
...
|
|
196
|
+
const newState = {
|
|
197
|
+
...contentState,
|
|
190
198
|
[key]: json,
|
|
191
199
|
};
|
|
192
|
-
|
|
200
|
+
setContextState(newState);
|
|
193
201
|
})
|
|
194
202
|
.catch((err) => {
|
|
195
203
|
console.log("error fetching dynamic data", url, err);
|
|
@@ -197,7 +205,7 @@ export default function RenderContent(props) {
|
|
|
197
205
|
}
|
|
198
206
|
|
|
199
207
|
function runHttpRequests() {
|
|
200
|
-
const requests = useContent?.
|
|
208
|
+
const requests = useContent?.data?.httpRequests ?? {};
|
|
201
209
|
Object.entries(requests).forEach(([key, url]) => {
|
|
202
210
|
if (url && (!httpReqsData[key] || isEditing())) {
|
|
203
211
|
const evaluatedUrl = evalExpression(url);
|
|
@@ -214,7 +222,7 @@ export default function RenderContent(props) {
|
|
|
214
222
|
window.dispatchEvent(
|
|
215
223
|
new CustomEvent("builder:component:stateChange", {
|
|
216
224
|
detail: {
|
|
217
|
-
state: contentState
|
|
225
|
+
state: contentState,
|
|
218
226
|
ref: {
|
|
219
227
|
name: props.model,
|
|
220
228
|
},
|
|
@@ -226,8 +234,7 @@ export default function RenderContent(props) {
|
|
|
226
234
|
|
|
227
235
|
function shouldRenderContentStyles() {
|
|
228
236
|
return Boolean(
|
|
229
|
-
(useContent?.
|
|
230
|
-
useContent?.()?.data?.customFonts?.length) &&
|
|
237
|
+
(useContent?.data?.cssCode || useContent?.data?.customFonts?.length) &&
|
|
231
238
|
TARGET !== "reactNative"
|
|
232
239
|
);
|
|
233
240
|
}
|
|
@@ -266,9 +273,9 @@ export default function RenderContent(props) {
|
|
|
266
273
|
emitStateUpdate
|
|
267
274
|
);
|
|
268
275
|
}
|
|
269
|
-
if (useContent
|
|
270
|
-
const variationId = useContent?.
|
|
271
|
-
const contentId = useContent?.
|
|
276
|
+
if (useContent) {
|
|
277
|
+
const variationId = useContent?.testVariationId;
|
|
278
|
+
const contentId = useContent?.id;
|
|
272
279
|
_track({
|
|
273
280
|
type: "impression",
|
|
274
281
|
canTrack: canTrackToUse,
|
|
@@ -303,7 +310,7 @@ export default function RenderContent(props) {
|
|
|
303
310
|
apiKey: props.apiKey,
|
|
304
311
|
}).then((content) => {
|
|
305
312
|
if (content) {
|
|
306
|
-
|
|
313
|
+
mergeNewContent(content);
|
|
307
314
|
}
|
|
308
315
|
});
|
|
309
316
|
}
|
|
@@ -316,13 +323,13 @@ export default function RenderContent(props) {
|
|
|
316
323
|
|
|
317
324
|
useEffect(() => {
|
|
318
325
|
evaluateJsCode();
|
|
319
|
-
}, [useContent?.
|
|
326
|
+
}, [useContent?.data?.jsCode, contentState]);
|
|
320
327
|
useEffect(() => {
|
|
321
328
|
runHttpRequests();
|
|
322
|
-
}, [useContent?.
|
|
329
|
+
}, [useContent?.data?.httpRequests]);
|
|
323
330
|
useEffect(() => {
|
|
324
331
|
emitStateUpdate();
|
|
325
|
-
}, [contentState
|
|
332
|
+
}, [contentState]);
|
|
326
333
|
|
|
327
334
|
useEffect(() => {
|
|
328
335
|
return () => {
|
|
@@ -339,30 +346,32 @@ export default function RenderContent(props) {
|
|
|
339
346
|
return (
|
|
340
347
|
<builderContext.Provider
|
|
341
348
|
value={{
|
|
342
|
-
content: useContent
|
|
343
|
-
state: contentState
|
|
344
|
-
|
|
349
|
+
content: useContent,
|
|
350
|
+
state: contentState,
|
|
351
|
+
setState: setContextState,
|
|
352
|
+
context: props.context || {},
|
|
345
353
|
apiKey: props.apiKey,
|
|
346
354
|
registeredComponents: allRegisteredComponents,
|
|
347
355
|
}}
|
|
348
356
|
>
|
|
349
|
-
{useContent
|
|
357
|
+
{useContent ? (
|
|
350
358
|
<>
|
|
351
359
|
<View
|
|
352
360
|
ref={elementRef}
|
|
353
361
|
onClick={(event) => onClick(event)}
|
|
354
|
-
builder-content-id={useContent?.
|
|
362
|
+
builder-content-id={useContent?.id}
|
|
355
363
|
builder-model={props.model}
|
|
356
364
|
>
|
|
357
365
|
{shouldRenderContentStyles() ? (
|
|
358
366
|
<RenderContentStyles
|
|
359
|
-
|
|
360
|
-
|
|
367
|
+
contentId={useContent?.id}
|
|
368
|
+
cssCode={useContent?.data?.cssCode}
|
|
369
|
+
customFonts={useContent?.data?.customFonts}
|
|
361
370
|
/>
|
|
362
371
|
) : null}
|
|
363
372
|
|
|
364
373
|
<RenderBlocks
|
|
365
|
-
blocks={useContent?.
|
|
374
|
+
blocks={useContent?.data?.blocks}
|
|
366
375
|
key={forceReRenderCount}
|
|
367
376
|
/>
|
|
368
377
|
</View>
|
|
File without changes
|
|
File without changes
|