@builder.io/sdk-react-native 0.2.1 → 0.2.2
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/symbol/symbol.js +2 -1
- package/dist/components/render-block/render-block.js +2 -3
- package/dist/components/render-content/render-content.js +8 -7
- package/dist/functions/get-block-properties.js +4 -1
- package/dist/functions/get-content/index.js +22 -15
- package/dist/functions/track/index.js +2 -1
- package/dist/helpers/logger.js +10 -0
- package/package.json +1 -1
- package/src/blocks/symbol/symbol.jsx +2 -1
- package/src/components/render-block/render-block.jsx +2 -3
- package/src/components/render-content/render-content.jsx +11 -8
- package/src/functions/get-block-properties.js +4 -1
- package/src/functions/get-content/index.js +21 -15
- package/src/functions/track/index.js +2 -1
- package/src/helpers/logger.js +9 -0
|
@@ -33,6 +33,7 @@ const render_content_1 = __importDefault(require("../../components/render-conten
|
|
|
33
33
|
const builder_context_js_1 = __importDefault(require("../../context/builder.context.js"));
|
|
34
34
|
const index_js_1 = require("../../functions/get-content/index.js");
|
|
35
35
|
const target_1 = require("../../constants/target");
|
|
36
|
+
const logger_1 = require("../../helpers/logger");
|
|
36
37
|
function Symbol(props) {
|
|
37
38
|
var _a, _b, _c;
|
|
38
39
|
const [className, setClassName] = (0, react_1.useState)(() => {
|
|
@@ -81,7 +82,7 @@ function Symbol(props) {
|
|
|
81
82
|
}
|
|
82
83
|
})
|
|
83
84
|
.catch((err) => {
|
|
84
|
-
|
|
85
|
+
logger_1.logger.error("Could not fetch symbol content: ", err);
|
|
85
86
|
});
|
|
86
87
|
}
|
|
87
88
|
}
|
|
@@ -40,7 +40,6 @@ const target_js_1 = require("../../constants/target.js");
|
|
|
40
40
|
const extract_text_styles_js_1 = require("../../functions/extract-text-styles.js");
|
|
41
41
|
const render_component_1 = __importDefault(require("./render-component"));
|
|
42
42
|
const get_react_native_block_styles_js_1 = require("../../functions/get-react-native-block-styles.js");
|
|
43
|
-
const nullable_js_1 = require("../../helpers/nullable.js");
|
|
44
43
|
function RenderBlock(props) {
|
|
45
44
|
var _a, _b;
|
|
46
45
|
const [component, setComponent] = (0, react_1.useState)(() => (0, render_block_helpers_js_1.getComponent)({
|
|
@@ -63,10 +62,10 @@ function RenderBlock(props) {
|
|
|
63
62
|
}
|
|
64
63
|
const [tag, setTag] = (0, react_1.useState)(() => props.block.tagName || "div");
|
|
65
64
|
function canShowBlock() {
|
|
66
|
-
if (
|
|
65
|
+
if ("hide" in useBlock()) {
|
|
67
66
|
return !useBlock().hide;
|
|
68
67
|
}
|
|
69
|
-
if (
|
|
68
|
+
if ("show" in useBlock()) {
|
|
70
69
|
return useBlock().show;
|
|
71
70
|
}
|
|
72
71
|
return true;
|
|
@@ -46,6 +46,7 @@ const nullable_js_1 = require("../../helpers/nullable.js");
|
|
|
46
46
|
const interaction_js_1 = require("../../functions/track/interaction.js");
|
|
47
47
|
const render_content_helpers_js_1 = require("./render-content.helpers.js");
|
|
48
48
|
const target_js_1 = require("../../constants/target.js");
|
|
49
|
+
const logger_js_1 = require("../../helpers/logger.js");
|
|
49
50
|
function RenderContent(props) {
|
|
50
51
|
var _a, _b, _c, _d, _e;
|
|
51
52
|
const elementRef = (0, react_1.useRef)(null);
|
|
@@ -219,7 +220,7 @@ function RenderContent(props) {
|
|
|
219
220
|
}
|
|
220
221
|
(0, react_1.useEffect)(() => {
|
|
221
222
|
if (!props.apiKey) {
|
|
222
|
-
|
|
223
|
+
logger_js_1.logger.error("No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
|
|
223
224
|
}
|
|
224
225
|
if ((0, is_browser_js_1.isBrowser)()) {
|
|
225
226
|
if ((0, is_editing_js_1.isEditing)()) {
|
|
@@ -259,19 +260,19 @@ function RenderContent(props) {
|
|
|
259
260
|
// override normal content in preview mode
|
|
260
261
|
if ((0, is_previewing_js_1.isPreviewing)()) {
|
|
261
262
|
const searchParams = new URL(location.href).searchParams;
|
|
262
|
-
const
|
|
263
|
+
const searchParamPreviewModel = searchParams.get("builder.preview");
|
|
264
|
+
const searchParamPreviewId = searchParams.get(`builder.preview.${searchParamPreviewModel}`);
|
|
263
265
|
const previewApiKey = searchParams.get("apiKey") || searchParams.get("builder.space");
|
|
264
266
|
/**
|
|
265
267
|
* Make sure that:
|
|
266
268
|
* - the preview model name is the same as the one we're rendering, since there can be multiple models rendered * at the same time, e.g. header/page/footer. * - the API key is the same, since we don't want to preview content from other organizations.
|
|
267
|
-
*
|
|
268
|
-
* TO-DO: should we check that the preview item ID is the same as the initial one being rendered? Or would
|
|
269
|
-
* this break scenarios where the item is not published yet?
|
|
269
|
+
* - if there is content, that the preview ID is the same as that of the one we receive.
|
|
270
270
|
*
|
|
271
271
|
* TO-DO: should we only update the state when there is a change?
|
|
272
272
|
**/
|
|
273
|
-
if (
|
|
274
|
-
previewApiKey === props.apiKey
|
|
273
|
+
if (searchParamPreviewModel === props.model &&
|
|
274
|
+
previewApiKey === props.apiKey &&
|
|
275
|
+
(!props.content || searchParamPreviewId === props.content.id)) {
|
|
275
276
|
(0, index_js_1.getContent)({
|
|
276
277
|
model: props.model,
|
|
277
278
|
apiKey: props.apiKey,
|
|
@@ -23,9 +23,12 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
23
23
|
const target_js_1 = require("../constants/target.js");
|
|
24
24
|
const css_js_1 = require("../helpers/css.js");
|
|
25
25
|
const transform_block_properties_js_1 = require("./transform-block-properties.js");
|
|
26
|
+
const extractRelevantRootBlockProperties = (block) => {
|
|
27
|
+
return { href: block.href };
|
|
28
|
+
};
|
|
26
29
|
function getBlockProperties(block) {
|
|
27
30
|
var _a;
|
|
28
|
-
const properties = __spreadProps(__spreadValues({}, block.properties), {
|
|
31
|
+
const properties = __spreadProps(__spreadValues(__spreadValues({}, extractRelevantRootBlockProperties(block)), block.properties), {
|
|
29
32
|
"builder-id": block.id,
|
|
30
33
|
style: getStyleAttribute(block.style),
|
|
31
34
|
class: [block.id, "builder-block", block.class, (_a = block.properties) == null ? void 0 : _a.class].filter(Boolean).join(" ")
|
|
@@ -42,13 +42,14 @@ var __async = (__this, __arguments, generator) => {
|
|
|
42
42
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
43
43
|
});
|
|
44
44
|
};
|
|
45
|
+
const logger_js_1 = require("../../helpers/logger.js");
|
|
45
46
|
const get_fetch_js_1 = require("../get-fetch.js");
|
|
46
47
|
const ab_testing_js_1 = require("./ab-testing.js");
|
|
47
48
|
const generate_content_url_js_1 = require("./generate-content-url.js");
|
|
48
49
|
function getContent(options) {
|
|
49
50
|
return __async(this, null, function* () {
|
|
50
51
|
const allContent = yield getAllContent(__spreadProps(__spreadValues({}, options), { limit: 1 }));
|
|
51
|
-
if ("results" in allContent) {
|
|
52
|
+
if (allContent && "results" in allContent) {
|
|
52
53
|
return (allContent == null ? void 0 : allContent.results[0]) || null;
|
|
53
54
|
}
|
|
54
55
|
return null;
|
|
@@ -57,25 +58,31 @@ function getContent(options) {
|
|
|
57
58
|
exports.getContent = getContent;
|
|
58
59
|
function getAllContent(options) {
|
|
59
60
|
return __async(this, null, function* () {
|
|
60
|
-
const url = (0, generate_content_url_js_1.generateContentUrl)(options);
|
|
61
|
-
const res = yield (0, get_fetch_js_1.fetch)(url.href);
|
|
62
|
-
const content = yield res.json();
|
|
63
|
-
if ("status" in content && !("results" in content)) {
|
|
64
|
-
console.error("[Builder.io]: Error fetching data. ", content, options);
|
|
65
|
-
return content;
|
|
66
|
-
}
|
|
67
|
-
const canTrack = options.canTrack !== false;
|
|
68
61
|
try {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
62
|
+
const url = (0, generate_content_url_js_1.generateContentUrl)(options);
|
|
63
|
+
const res = yield (0, get_fetch_js_1.fetch)(url.href);
|
|
64
|
+
const content = yield res.json();
|
|
65
|
+
if ("status" in content && !("results" in content)) {
|
|
66
|
+
logger_js_1.logger.error("Error fetching data. ", content, options);
|
|
67
|
+
return content;
|
|
68
|
+
}
|
|
69
|
+
const canTrack = options.canTrack !== false;
|
|
70
|
+
try {
|
|
71
|
+
if (canTrack && Array.isArray(content.results)) {
|
|
72
|
+
for (const item of content.results) {
|
|
73
|
+
yield (0, ab_testing_js_1.handleABTesting)({ item, canTrack });
|
|
74
|
+
}
|
|
72
75
|
}
|
|
73
76
|
}
|
|
77
|
+
catch (e) {
|
|
78
|
+
logger_js_1.logger.error("Could not setup A/B testing. ", e);
|
|
79
|
+
}
|
|
80
|
+
return content;
|
|
74
81
|
}
|
|
75
|
-
catch (
|
|
76
|
-
|
|
82
|
+
catch (error) {
|
|
83
|
+
logger_js_1.logger.error("Error fetching data. ", error);
|
|
84
|
+
return null;
|
|
77
85
|
}
|
|
78
|
-
return content;
|
|
79
86
|
});
|
|
80
87
|
}
|
|
81
88
|
exports.getAllContent = getAllContent;
|
|
@@ -55,6 +55,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
55
55
|
});
|
|
56
56
|
};
|
|
57
57
|
const target_js_1 = require("../../constants/target.js");
|
|
58
|
+
const logger_js_1 = require("../../helpers/logger.js");
|
|
58
59
|
const sessionId_js_1 = require("../../helpers/sessionId.js");
|
|
59
60
|
const visitorId_js_1 = require("../../helpers/visitorId.js");
|
|
60
61
|
const is_browser_js_1 = require("../is-browser.js");
|
|
@@ -93,7 +94,7 @@ const createEvent = (_a) => __async(void 0, null, function* () {
|
|
|
93
94
|
function _track(eventProps) {
|
|
94
95
|
return __async(this, null, function* () {
|
|
95
96
|
if (!eventProps.apiKey) {
|
|
96
|
-
|
|
97
|
+
logger_js_1.logger.error("Missing API key for track call. Please provide your API key.");
|
|
97
98
|
return;
|
|
98
99
|
}
|
|
99
100
|
if (!eventProps.canTrack) {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logger = void 0;
|
|
4
|
+
const MSG_PREFIX = "[Builder.io]: ";
|
|
5
|
+
const logger = {
|
|
6
|
+
log: (...message) => console.log(MSG_PREFIX, ...message),
|
|
7
|
+
error: (...message) => console.error(MSG_PREFIX, ...message),
|
|
8
|
+
warn: (...message) => console.warn(MSG_PREFIX, ...message)
|
|
9
|
+
};
|
|
10
|
+
exports.logger = logger;
|
package/package.json
CHANGED
|
@@ -12,6 +12,7 @@ import RenderContent from "../../components/render-content/render-content";
|
|
|
12
12
|
import BuilderContext from "../../context/builder.context.js";
|
|
13
13
|
import { getContent } from "../../functions/get-content/index.js";
|
|
14
14
|
import { TARGET } from "../../constants/target";
|
|
15
|
+
import { logger } from "../../helpers/logger";
|
|
15
16
|
|
|
16
17
|
function Symbol(props) {
|
|
17
18
|
const [className, setClassName] = useState(() =>
|
|
@@ -61,7 +62,7 @@ function Symbol(props) {
|
|
|
61
62
|
}
|
|
62
63
|
})
|
|
63
64
|
.catch((err) => {
|
|
64
|
-
|
|
65
|
+
logger.error("Could not fetch symbol content: ", err);
|
|
65
66
|
});
|
|
66
67
|
}
|
|
67
68
|
}
|
|
@@ -24,7 +24,6 @@ import { TARGET } from "../../constants/target.js";
|
|
|
24
24
|
import { extractTextStyles } from "../../functions/extract-text-styles.js";
|
|
25
25
|
import RenderComponent from "./render-component";
|
|
26
26
|
import { getReactNativeBlockStyles } from "../../functions/get-react-native-block-styles.js";
|
|
27
|
-
import { checkIsDefined } from "../../helpers/nullable.js";
|
|
28
27
|
|
|
29
28
|
function RenderBlock(props) {
|
|
30
29
|
const [component, setComponent] = useState(() =>
|
|
@@ -55,10 +54,10 @@ function RenderBlock(props) {
|
|
|
55
54
|
const [tag, setTag] = useState(() => props.block.tagName || "div");
|
|
56
55
|
|
|
57
56
|
function canShowBlock() {
|
|
58
|
-
if (
|
|
57
|
+
if ("hide" in useBlock()) {
|
|
59
58
|
return !useBlock().hide;
|
|
60
59
|
}
|
|
61
|
-
if (
|
|
60
|
+
if ("show" in useBlock()) {
|
|
62
61
|
return useBlock().show;
|
|
63
62
|
}
|
|
64
63
|
return true;
|
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
getContextStateInitialValue,
|
|
35
35
|
} from "./render-content.helpers.js";
|
|
36
36
|
import { TARGET } from "../../constants/target.js";
|
|
37
|
+
import { logger } from "../../helpers/logger.js";
|
|
37
38
|
|
|
38
39
|
function RenderContent(props) {
|
|
39
40
|
const elementRef = useRef(null);
|
|
@@ -241,8 +242,8 @@ function RenderContent(props) {
|
|
|
241
242
|
|
|
242
243
|
useEffect(() => {
|
|
243
244
|
if (!props.apiKey) {
|
|
244
|
-
|
|
245
|
-
"
|
|
245
|
+
logger.error(
|
|
246
|
+
"No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop."
|
|
246
247
|
);
|
|
247
248
|
}
|
|
248
249
|
if (isBrowser()) {
|
|
@@ -288,22 +289,24 @@ function RenderContent(props) {
|
|
|
288
289
|
// override normal content in preview mode
|
|
289
290
|
if (isPreviewing()) {
|
|
290
291
|
const searchParams = new URL(location.href).searchParams;
|
|
291
|
-
const
|
|
292
|
+
const searchParamPreviewModel = searchParams.get("builder.preview");
|
|
293
|
+
const searchParamPreviewId = searchParams.get(
|
|
294
|
+
`builder.preview.${searchParamPreviewModel}`
|
|
295
|
+
);
|
|
292
296
|
const previewApiKey =
|
|
293
297
|
searchParams.get("apiKey") || searchParams.get("builder.space");
|
|
294
298
|
|
|
295
299
|
/**
|
|
296
300
|
* Make sure that:
|
|
297
301
|
* - the preview model name is the same as the one we're rendering, since there can be multiple models rendered * at the same time, e.g. header/page/footer. * - the API key is the same, since we don't want to preview content from other organizations.
|
|
298
|
-
*
|
|
299
|
-
* TO-DO: should we check that the preview item ID is the same as the initial one being rendered? Or would
|
|
300
|
-
* this break scenarios where the item is not published yet?
|
|
302
|
+
* - if there is content, that the preview ID is the same as that of the one we receive.
|
|
301
303
|
*
|
|
302
304
|
* TO-DO: should we only update the state when there is a change?
|
|
303
305
|
**/
|
|
304
306
|
if (
|
|
305
|
-
|
|
306
|
-
previewApiKey === props.apiKey
|
|
307
|
+
searchParamPreviewModel === props.model &&
|
|
308
|
+
previewApiKey === props.apiKey &&
|
|
309
|
+
(!props.content || searchParamPreviewId === props.content.id)
|
|
307
310
|
) {
|
|
308
311
|
getContent({
|
|
309
312
|
model: props.model,
|
|
@@ -20,9 +20,12 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
20
20
|
import { TARGET } from "../constants/target.js";
|
|
21
21
|
import { convertStyleMapToCSSArray } from "../helpers/css.js";
|
|
22
22
|
import { transformBlockProperties } from "./transform-block-properties.js";
|
|
23
|
+
const extractRelevantRootBlockProperties = (block) => {
|
|
24
|
+
return { href: block.href };
|
|
25
|
+
};
|
|
23
26
|
function getBlockProperties(block) {
|
|
24
27
|
var _a;
|
|
25
|
-
const properties = __spreadProps(__spreadValues({}, block.properties), {
|
|
28
|
+
const properties = __spreadProps(__spreadValues(__spreadValues({}, extractRelevantRootBlockProperties(block)), block.properties), {
|
|
26
29
|
"builder-id": block.id,
|
|
27
30
|
style: getStyleAttribute(block.style),
|
|
28
31
|
class: [block.id, "builder-block", block.class, (_a = block.properties) == null ? void 0 : _a.class].filter(Boolean).join(" ")
|
|
@@ -37,13 +37,14 @@ var __async = (__this, __arguments, generator) => {
|
|
|
37
37
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
38
|
});
|
|
39
39
|
};
|
|
40
|
+
import { logger } from "../../helpers/logger.js";
|
|
40
41
|
import { fetch } from "../get-fetch.js";
|
|
41
42
|
import { handleABTesting } from "./ab-testing.js";
|
|
42
43
|
import { generateContentUrl } from "./generate-content-url.js";
|
|
43
44
|
function getContent(options) {
|
|
44
45
|
return __async(this, null, function* () {
|
|
45
46
|
const allContent = yield getAllContent(__spreadProps(__spreadValues({}, options), { limit: 1 }));
|
|
46
|
-
if ("results" in allContent) {
|
|
47
|
+
if (allContent && "results" in allContent) {
|
|
47
48
|
return (allContent == null ? void 0 : allContent.results[0]) || null;
|
|
48
49
|
}
|
|
49
50
|
return null;
|
|
@@ -51,24 +52,29 @@ function getContent(options) {
|
|
|
51
52
|
}
|
|
52
53
|
function getAllContent(options) {
|
|
53
54
|
return __async(this, null, function* () {
|
|
54
|
-
const url = generateContentUrl(options);
|
|
55
|
-
const res = yield fetch(url.href);
|
|
56
|
-
const content = yield res.json();
|
|
57
|
-
if ("status" in content && !("results" in content)) {
|
|
58
|
-
console.error("[Builder.io]: Error fetching data. ", content, options);
|
|
59
|
-
return content;
|
|
60
|
-
}
|
|
61
|
-
const canTrack = options.canTrack !== false;
|
|
62
55
|
try {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
56
|
+
const url = generateContentUrl(options);
|
|
57
|
+
const res = yield fetch(url.href);
|
|
58
|
+
const content = yield res.json();
|
|
59
|
+
if ("status" in content && !("results" in content)) {
|
|
60
|
+
logger.error("Error fetching data. ", content, options);
|
|
61
|
+
return content;
|
|
62
|
+
}
|
|
63
|
+
const canTrack = options.canTrack !== false;
|
|
64
|
+
try {
|
|
65
|
+
if (canTrack && Array.isArray(content.results)) {
|
|
66
|
+
for (const item of content.results) {
|
|
67
|
+
yield handleABTesting({ item, canTrack });
|
|
68
|
+
}
|
|
66
69
|
}
|
|
70
|
+
} catch (e) {
|
|
71
|
+
logger.error("Could not setup A/B testing. ", e);
|
|
67
72
|
}
|
|
68
|
-
|
|
69
|
-
|
|
73
|
+
return content;
|
|
74
|
+
} catch (error) {
|
|
75
|
+
logger.error("Error fetching data. ", error);
|
|
76
|
+
return null;
|
|
70
77
|
}
|
|
71
|
-
return content;
|
|
72
78
|
});
|
|
73
79
|
}
|
|
74
80
|
export {
|
|
@@ -50,6 +50,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
50
50
|
});
|
|
51
51
|
};
|
|
52
52
|
import { TARGET } from "../../constants/target.js";
|
|
53
|
+
import { logger } from "../../helpers/logger.js";
|
|
53
54
|
import { getSessionId } from "../../helpers/sessionId.js";
|
|
54
55
|
import { getVisitorId } from "../../helpers/visitorId.js";
|
|
55
56
|
import { isBrowser } from "../is-browser.js";
|
|
@@ -95,7 +96,7 @@ const createEvent = (_a) => __async(void 0, null, function* () {
|
|
|
95
96
|
function _track(eventProps) {
|
|
96
97
|
return __async(this, null, function* () {
|
|
97
98
|
if (!eventProps.apiKey) {
|
|
98
|
-
|
|
99
|
+
logger.error("Missing API key for track call. Please provide your API key.");
|
|
99
100
|
return;
|
|
100
101
|
}
|
|
101
102
|
if (!eventProps.canTrack) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const MSG_PREFIX = "[Builder.io]: ";
|
|
2
|
+
const logger = {
|
|
3
|
+
log: (...message) => console.log(MSG_PREFIX, ...message),
|
|
4
|
+
error: (...message) => console.error(MSG_PREFIX, ...message),
|
|
5
|
+
warn: (...message) => console.warn(MSG_PREFIX, ...message)
|
|
6
|
+
};
|
|
7
|
+
export {
|
|
8
|
+
logger
|
|
9
|
+
};
|