@builder.io/sdk-react-native 0.3.1 → 0.4.0
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/button.js +1 -0
- package/dist/blocks/columns/columns.js +1 -0
- package/dist/blocks/custom-code/custom-code.js +1 -0
- package/dist/blocks/embed/embed.js +1 -0
- package/dist/blocks/form/form.js +1 -0
- package/dist/blocks/fragment/fragment.js +1 -0
- package/dist/blocks/img/img.js +1 -0
- package/dist/blocks/input/input.js +1 -0
- package/dist/blocks/raw-text/raw-text.js +1 -0
- package/dist/blocks/section/section.js +1 -0
- package/dist/blocks/select/select.js +1 -0
- package/dist/blocks/submit-button/submit-button.js +1 -0
- package/dist/blocks/symbol/symbol.js +1 -0
- package/dist/blocks/textarea/textarea.js +1 -0
- package/dist/components/render-block/block-styles.js +1 -0
- package/dist/components/render-block/render-block.js +7 -6
- package/dist/components/render-block/render-component.js +2 -2
- package/dist/components/render-block/render-repeated-block.js +1 -0
- package/dist/components/render-blocks.js +1 -0
- package/dist/components/render-content/builder-editing.js +1 -0
- package/dist/components/render-content/components/render-styles.js +2 -1
- package/dist/components/render-content/render-content.js +36 -3
- package/dist/components/render-content/wrap-component-ref.js +5 -0
- package/dist/components/render-content-variants/helpers.js +137 -0
- package/dist/components/render-content-variants/render-content-variants.js +73 -0
- package/dist/components/render-inlined-styles.js +2 -12
- package/dist/constants/sdk-version.js +1 -1
- package/dist/functions/get-content/generate-content-url.js +2 -2
- package/dist/functions/get-content/generate-content-url.test.js +15 -0
- package/dist/functions/get-content/index.js +36 -19
- package/dist/helpers/ab-tests.js +123 -6
- package/dist/helpers/canTrack.js +6 -0
- package/dist/helpers/cookie.js +9 -2
- package/dist/helpers/logger.js +2 -1
- package/dist/index.js +17 -10
- package/package.json +1 -1
- package/src/blocks/button/button.jsx +1 -0
- package/src/blocks/columns/columns.jsx +1 -0
- package/src/blocks/custom-code/custom-code.jsx +1 -0
- package/src/blocks/embed/embed.jsx +1 -0
- package/src/blocks/form/form.jsx +1 -0
- package/src/blocks/fragment/fragment.jsx +1 -0
- package/src/blocks/img/img.jsx +1 -0
- package/src/blocks/input/input.jsx +1 -0
- package/src/blocks/raw-text/raw-text.jsx +1 -0
- package/src/blocks/section/section.jsx +1 -0
- package/src/blocks/select/select.jsx +1 -0
- package/src/blocks/submit-button/submit-button.jsx +1 -0
- package/src/blocks/symbol/symbol.jsx +1 -0
- package/src/blocks/textarea/textarea.jsx +1 -0
- package/src/components/render-block/block-styles.jsx +1 -0
- package/src/components/render-block/render-block.jsx +8 -7
- package/src/components/render-block/render-component.jsx +3 -4
- package/src/components/render-block/render-repeated-block.jsx +1 -0
- package/src/components/render-blocks.jsx +1 -0
- package/src/components/render-content/builder-editing.jsx +1 -0
- package/src/components/render-content/components/render-styles.jsx +4 -3
- package/src/components/render-content/render-content.jsx +42 -2
- package/src/components/render-content/wrap-component-ref.js +4 -0
- package/src/components/render-content-variants/helpers.js +139 -0
- package/src/components/render-content-variants/render-content-variants.jsx +101 -0
- package/src/components/render-inlined-styles.jsx +2 -22
- package/src/constants/sdk-version.js +1 -1
- package/src/functions/get-content/generate-content-url.js +2 -1
- package/src/functions/get-content/generate-content-url.test.js +15 -0
- package/src/functions/get-content/index.js +35 -18
- package/src/helpers/ab-tests.js +132 -10
- package/src/helpers/canTrack.js +5 -0
- package/src/helpers/cookie.js +9 -2
- package/src/helpers/logger.js +2 -1
- package/src/index.js +18 -7
- package/src/functions/get-content/ab-testing.js +0 -99
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getContent = exports.getAllContent = void 0;
|
|
3
|
+
exports.processContentResult = exports.getContent = exports.getAllContent = void 0;
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __defProps = Object.defineProperties;
|
|
6
6
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
@@ -42,42 +42,59 @@ var __async = (__this, __arguments, generator) => {
|
|
|
42
42
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
43
43
|
});
|
|
44
44
|
};
|
|
45
|
+
const target_js_1 = require("../../constants/target.js");
|
|
46
|
+
const ab_tests_js_1 = require("../../helpers/ab-tests.js");
|
|
47
|
+
const canTrack_js_1 = require("../../helpers/canTrack.js");
|
|
45
48
|
const logger_js_1 = require("../../helpers/logger.js");
|
|
46
49
|
const get_fetch_js_1 = require("../get-fetch.js");
|
|
47
|
-
const
|
|
50
|
+
const is_browser_js_1 = require("../is-browser.js");
|
|
48
51
|
const generate_content_url_js_1 = require("./generate-content-url.js");
|
|
52
|
+
const checkContentHasResults = (content) => "results" in content;
|
|
49
53
|
function getContent(options) {
|
|
50
54
|
return __async(this, null, function* () {
|
|
51
55
|
const allContent = yield getAllContent(__spreadProps(__spreadValues({}, options), { limit: 1 }));
|
|
52
|
-
if (allContent &&
|
|
53
|
-
return
|
|
56
|
+
if (allContent && checkContentHasResults(allContent)) {
|
|
57
|
+
return allContent.results[0] || null;
|
|
54
58
|
}
|
|
55
59
|
return null;
|
|
56
60
|
});
|
|
57
61
|
}
|
|
58
62
|
exports.getContent = getContent;
|
|
63
|
+
const fetchContent = (options) => __async(void 0, null, function* () {
|
|
64
|
+
const url = (0, generate_content_url_js_1.generateContentUrl)(options);
|
|
65
|
+
const res = yield (0, get_fetch_js_1.fetch)(url.href);
|
|
66
|
+
const content = yield res.json();
|
|
67
|
+
return content;
|
|
68
|
+
});
|
|
69
|
+
const processContentResult = (options, content) => __async(void 0, null, function* () {
|
|
70
|
+
const canTrack = (0, canTrack_js_1.getDefaultCanTrack)(options.canTrack);
|
|
71
|
+
if (!canTrack)
|
|
72
|
+
return content;
|
|
73
|
+
if (!((0, is_browser_js_1.isBrowser)() || target_js_1.TARGET === "reactNative"))
|
|
74
|
+
return content;
|
|
75
|
+
try {
|
|
76
|
+
const newResults = [];
|
|
77
|
+
for (const item of content.results) {
|
|
78
|
+
newResults.push(yield (0, ab_tests_js_1.handleABTesting)({ item, canTrack }));
|
|
79
|
+
}
|
|
80
|
+
content.results = newResults;
|
|
81
|
+
}
|
|
82
|
+
catch (e) {
|
|
83
|
+
logger_js_1.logger.error("Could not process A/B tests. ", e);
|
|
84
|
+
}
|
|
85
|
+
return content;
|
|
86
|
+
});
|
|
87
|
+
exports.processContentResult = processContentResult;
|
|
59
88
|
function getAllContent(options) {
|
|
60
89
|
return __async(this, null, function* () {
|
|
61
90
|
try {
|
|
62
91
|
const url = (0, generate_content_url_js_1.generateContentUrl)(options);
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
if ("status" in content && !("results" in content)) {
|
|
92
|
+
const content = yield fetchContent(options);
|
|
93
|
+
if (!checkContentHasResults(content)) {
|
|
66
94
|
logger_js_1.logger.error("Error fetching data. ", { url, content, options });
|
|
67
95
|
return content;
|
|
68
96
|
}
|
|
69
|
-
|
|
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
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
catch (e) {
|
|
78
|
-
logger_js_1.logger.error("Could not setup A/B testing. ", e);
|
|
79
|
-
}
|
|
80
|
-
return content;
|
|
97
|
+
return processContentResult(options, content);
|
|
81
98
|
}
|
|
82
99
|
catch (error) {
|
|
83
100
|
logger_js_1.logger.error("Error fetching data. ", error);
|
package/dist/helpers/ab-tests.js
CHANGED
|
@@ -1,10 +1,127 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.handleABTestingSync = exports.handleABTesting = void 0;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __spreadValues = (a, b) => {
|
|
10
|
+
for (var prop in b || (b = {}))
|
|
11
|
+
if (__hasOwnProp.call(b, prop))
|
|
12
|
+
__defNormalProp(a, prop, b[prop]);
|
|
13
|
+
if (__getOwnPropSymbols)
|
|
14
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
+
if (__propIsEnum.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
18
|
+
return a;
|
|
19
|
+
};
|
|
20
|
+
var __async = (__this, __arguments, generator) => {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
var fulfilled = (value) => {
|
|
23
|
+
try {
|
|
24
|
+
step(generator.next(value));
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
reject(e);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var rejected = (value) => {
|
|
31
|
+
try {
|
|
32
|
+
step(generator.throw(value));
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
reject(e);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
39
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
40
|
+
});
|
|
41
|
+
};
|
|
4
42
|
const cookie_js_1 = require("./cookie.js");
|
|
5
|
-
const
|
|
43
|
+
const nullable_js_1 = require("../helpers/nullable.js");
|
|
44
|
+
const logger_js_1 = require("./logger.js");
|
|
45
|
+
const BUILDER_STORE_PREFIX = "builder.tests";
|
|
6
46
|
const getContentTestKey = (id) => `${BUILDER_STORE_PREFIX}.${id}`;
|
|
7
|
-
const getContentVariationCookie = ({ contentId
|
|
8
|
-
|
|
9
|
-
const setContentVariationCookie = ({ contentId,
|
|
10
|
-
|
|
47
|
+
const getContentVariationCookie = ({ contentId }) => (0, cookie_js_1.getCookie)({ name: getContentTestKey(contentId), canTrack: true });
|
|
48
|
+
const getContentVariationCookieSync = ({ contentId }) => (0, cookie_js_1.getCookieSync)({ name: getContentTestKey(contentId), canTrack: true });
|
|
49
|
+
const setContentVariationCookie = ({ contentId, value }) => (0, cookie_js_1.setCookie)({ name: getContentTestKey(contentId), value, canTrack: true });
|
|
50
|
+
const checkIsBuilderContentWithVariations = (item) => (0, nullable_js_1.checkIsDefined)(item.id) && (0, nullable_js_1.checkIsDefined)(item.variations) && Object.keys(item.variations).length > 0;
|
|
51
|
+
const getRandomVariationId = ({ id, variations }) => {
|
|
52
|
+
var _a;
|
|
53
|
+
let n = 0;
|
|
54
|
+
const random = Math.random();
|
|
55
|
+
for (const id2 in variations) {
|
|
56
|
+
const testRatio = (_a = variations[id2]) == null ? void 0 : _a.testRatio;
|
|
57
|
+
n += testRatio;
|
|
58
|
+
if (random < n) {
|
|
59
|
+
return id2;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return id;
|
|
63
|
+
};
|
|
64
|
+
const getAndSetVariantId = (args) => {
|
|
65
|
+
const randomVariationId = getRandomVariationId(args);
|
|
66
|
+
setContentVariationCookie({
|
|
67
|
+
contentId: args.id,
|
|
68
|
+
value: randomVariationId
|
|
69
|
+
}).catch((err) => {
|
|
70
|
+
logger_js_1.logger.error("could not store A/B test variation: ", err);
|
|
71
|
+
});
|
|
72
|
+
return randomVariationId;
|
|
73
|
+
};
|
|
74
|
+
const getTestFields = ({ item, testGroupId }) => {
|
|
75
|
+
const variationValue = item.variations[testGroupId];
|
|
76
|
+
if (testGroupId === item.id || !variationValue) {
|
|
77
|
+
return {
|
|
78
|
+
testVariationId: item.id,
|
|
79
|
+
testVariationName: "Default"
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
return {
|
|
84
|
+
data: variationValue.data,
|
|
85
|
+
testVariationId: variationValue.id,
|
|
86
|
+
testVariationName: variationValue.name || (variationValue.id === item.id ? "Default" : "")
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
const handleABTestingSync = ({ item, canTrack }) => {
|
|
91
|
+
if (!canTrack) {
|
|
92
|
+
return item;
|
|
93
|
+
}
|
|
94
|
+
if (!item) {
|
|
95
|
+
return void 0;
|
|
96
|
+
}
|
|
97
|
+
if (!checkIsBuilderContentWithVariations(item)) {
|
|
98
|
+
return item;
|
|
99
|
+
}
|
|
100
|
+
const testGroupId = getContentVariationCookieSync({
|
|
101
|
+
contentId: item.id
|
|
102
|
+
}) || getAndSetVariantId({
|
|
103
|
+
variations: item.variations,
|
|
104
|
+
id: item.id
|
|
105
|
+
});
|
|
106
|
+
const variationValue = getTestFields({ item, testGroupId });
|
|
107
|
+
return __spreadValues(__spreadValues({}, item), variationValue);
|
|
108
|
+
};
|
|
109
|
+
exports.handleABTestingSync = handleABTestingSync;
|
|
110
|
+
const handleABTesting = (_0) => __async(void 0, [_0], function* ({ item, canTrack }) {
|
|
111
|
+
if (!canTrack) {
|
|
112
|
+
return item;
|
|
113
|
+
}
|
|
114
|
+
if (!checkIsBuilderContentWithVariations(item)) {
|
|
115
|
+
return item;
|
|
116
|
+
}
|
|
117
|
+
const cookieValue = yield getContentVariationCookie({
|
|
118
|
+
contentId: item.id
|
|
119
|
+
});
|
|
120
|
+
const testGroupId = cookieValue || getAndSetVariantId({
|
|
121
|
+
variations: item.variations,
|
|
122
|
+
id: item.id
|
|
123
|
+
});
|
|
124
|
+
const variationValue = getTestFields({ item, testGroupId });
|
|
125
|
+
return __spreadValues(__spreadValues({}, item), variationValue);
|
|
126
|
+
});
|
|
127
|
+
exports.handleABTesting = handleABTesting;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDefaultCanTrack = void 0;
|
|
4
|
+
const nullable_1 = require("./nullable");
|
|
5
|
+
const getDefaultCanTrack = (canTrack) => (0, nullable_1.checkIsDefined)(canTrack) ? canTrack : true;
|
|
6
|
+
exports.getDefaultCanTrack = getDefaultCanTrack;
|
package/dist/helpers/cookie.js
CHANGED
|
@@ -26,6 +26,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
26
26
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
27
27
|
});
|
|
28
28
|
};
|
|
29
|
+
const logger_js_1 = require("./logger.js");
|
|
29
30
|
const react_native_storage_1 = __importDefault(require("react-native-storage"));
|
|
30
31
|
const is_browser_js_1 = require("../functions/is-browser.js");
|
|
31
32
|
const async_storage_1 = __importDefault(require("@react-native-async-storage/async-storage"));
|
|
@@ -52,7 +53,10 @@ const getCookie = (_0) => __async(void 0, [_0], function* ({ name, canTrack }) {
|
|
|
52
53
|
return data.value;
|
|
53
54
|
}
|
|
54
55
|
catch (err) {
|
|
55
|
-
|
|
56
|
+
if ((err == null ? void 0 : err.name) !== "NotFoundError") {
|
|
57
|
+
logger_js_1.logger.warn("[COOKIE] GET error: ", (err == null ? void 0 : err.message) || err);
|
|
58
|
+
}
|
|
59
|
+
return void 0;
|
|
56
60
|
}
|
|
57
61
|
});
|
|
58
62
|
exports.getCookie = getCookie;
|
|
@@ -64,7 +68,10 @@ const setCookie = (_0) => __async(void 0, [_0], function* ({ name, value, expire
|
|
|
64
68
|
yield storage.save({ key: getStorageName(name), data: { value }, expires });
|
|
65
69
|
}
|
|
66
70
|
catch (err) {
|
|
67
|
-
|
|
71
|
+
if ((err == null ? void 0 : err.name) !== "NotFoundError") {
|
|
72
|
+
logger_js_1.logger.warn("[COOKIE] SET error: ", (err == null ? void 0 : err.message) || err);
|
|
73
|
+
}
|
|
74
|
+
return void 0;
|
|
68
75
|
}
|
|
69
76
|
});
|
|
70
77
|
exports.setCookie = setCookie;
|
package/dist/helpers/logger.js
CHANGED
|
@@ -5,6 +5,7 @@ const MSG_PREFIX = "[Builder.io]: ";
|
|
|
5
5
|
const logger = {
|
|
6
6
|
log: (...message) => console.log(MSG_PREFIX, ...message),
|
|
7
7
|
error: (...message) => console.error(MSG_PREFIX, ...message),
|
|
8
|
-
warn: (...message) => console.warn(MSG_PREFIX, ...message)
|
|
8
|
+
warn: (...message) => console.warn(MSG_PREFIX, ...message),
|
|
9
|
+
debug: (...message) => console.debug(MSG_PREFIX, ...message)
|
|
9
10
|
};
|
|
10
11
|
exports.logger = logger;
|
package/dist/index.js
CHANGED
|
@@ -14,15 +14,22 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.track = void 0;
|
|
17
|
+
exports.track = exports.setEditorSettings = exports.register = exports.processContentResult = exports.isPreviewing = exports.isEditing = exports.getContent = exports.getAllContent = exports.createRegisterComponentMessage = void 0;
|
|
18
18
|
__exportStar(require("./index-helpers/top-of-file.js"), exports);
|
|
19
19
|
__exportStar(require("./index-helpers/blocks-exports.js"), exports);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
const is_editing_js_1 = require("./functions/is-editing.js");
|
|
21
|
+
Object.defineProperty(exports, "isEditing", { enumerable: true, get: function () { return is_editing_js_1.isEditing; } });
|
|
22
|
+
const is_previewing_js_1 = require("./functions/is-previewing.js");
|
|
23
|
+
Object.defineProperty(exports, "isPreviewing", { enumerable: true, get: function () { return is_previewing_js_1.isPreviewing; } });
|
|
24
|
+
const register_component_js_1 = require("./functions/register-component.js");
|
|
25
|
+
Object.defineProperty(exports, "createRegisterComponentMessage", { enumerable: true, get: function () { return register_component_js_1.createRegisterComponentMessage; } });
|
|
26
|
+
const register_js_1 = require("./functions/register.js");
|
|
27
|
+
Object.defineProperty(exports, "register", { enumerable: true, get: function () { return register_js_1.register; } });
|
|
28
|
+
const set_editor_settings_js_1 = require("./functions/set-editor-settings.js");
|
|
29
|
+
Object.defineProperty(exports, "setEditorSettings", { enumerable: true, get: function () { return set_editor_settings_js_1.setEditorSettings; } });
|
|
30
|
+
const index_js_1 = require("./functions/get-content/index.js");
|
|
31
|
+
Object.defineProperty(exports, "getAllContent", { enumerable: true, get: function () { return index_js_1.getAllContent; } });
|
|
32
|
+
Object.defineProperty(exports, "getContent", { enumerable: true, get: function () { return index_js_1.getContent; } });
|
|
33
|
+
Object.defineProperty(exports, "processContentResult", { enumerable: true, get: function () { return index_js_1.processContentResult; } });
|
|
34
|
+
const index_js_2 = require("./functions/track/index.js");
|
|
35
|
+
Object.defineProperty(exports, "track", { enumerable: true, get: function () { return index_js_2.track; } });
|
package/package.json
CHANGED
package/src/blocks/form/form.jsx
CHANGED
package/src/blocks/img/img.jsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
'use client';
|
|
1
2
|
import * as React from "react";
|
|
2
3
|
import {
|
|
3
4
|
FlatList,
|
|
@@ -52,7 +53,7 @@ function RenderBlock(props) {
|
|
|
52
53
|
});
|
|
53
54
|
}
|
|
54
55
|
|
|
55
|
-
const [
|
|
56
|
+
const [Tag, setTag] = useState(() => props.block.tagName || "div");
|
|
56
57
|
|
|
57
58
|
function canShowBlock() {
|
|
58
59
|
if ("hide" in useBlock()) {
|
|
@@ -157,12 +158,12 @@ function RenderBlock(props) {
|
|
|
157
158
|
<>
|
|
158
159
|
{!component?.noWrap ? (
|
|
159
160
|
<>
|
|
160
|
-
{isEmptyHtmlElement(
|
|
161
|
+
{isEmptyHtmlElement(Tag) ? (
|
|
161
162
|
<>
|
|
162
|
-
<
|
|
163
|
+
<Tag {...attributes()} {...actions()} />
|
|
163
164
|
</>
|
|
164
165
|
) : null}
|
|
165
|
-
{!isEmptyHtmlElement(
|
|
166
|
+
{!isEmptyHtmlElement(Tag) && repeatItem() ? (
|
|
166
167
|
<>
|
|
167
168
|
{repeatItem()?.map((data, index) => (
|
|
168
169
|
<RenderRepeatedBlock
|
|
@@ -173,9 +174,9 @@ function RenderBlock(props) {
|
|
|
173
174
|
))}
|
|
174
175
|
</>
|
|
175
176
|
) : null}
|
|
176
|
-
{!isEmptyHtmlElement(
|
|
177
|
+
{!isEmptyHtmlElement(Tag) && !repeatItem() ? (
|
|
177
178
|
<>
|
|
178
|
-
<
|
|
179
|
+
<Tag {...attributes()} {...actions()}>
|
|
179
180
|
<RenderComponent {...renderComponentProps()} />
|
|
180
181
|
|
|
181
182
|
{childrenWithoutParentComponent()?.map((child) => (
|
|
@@ -193,7 +194,7 @@ function RenderBlock(props) {
|
|
|
193
194
|
context={childrenContext()}
|
|
194
195
|
/>
|
|
195
196
|
))}
|
|
196
|
-
</
|
|
197
|
+
</Tag>
|
|
197
198
|
</>
|
|
198
199
|
) : null}
|
|
199
200
|
</>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
'use client';
|
|
1
2
|
import * as React from "react";
|
|
2
3
|
import {
|
|
3
4
|
FlatList,
|
|
@@ -13,8 +14,6 @@ import RenderBlock from "./render-block";
|
|
|
13
14
|
import BuilderContext from "../../context/builder.context.js";
|
|
14
15
|
|
|
15
16
|
function RenderComponent(props) {
|
|
16
|
-
const ComponentRefRef = props.componentRef;
|
|
17
|
-
|
|
18
17
|
return (
|
|
19
18
|
<BuilderContext.Provider
|
|
20
19
|
value={{
|
|
@@ -30,7 +29,7 @@ function RenderComponent(props) {
|
|
|
30
29
|
>
|
|
31
30
|
{props.componentRef ? (
|
|
32
31
|
<>
|
|
33
|
-
<
|
|
32
|
+
<props.componentRef {...props.componentOptions}>
|
|
34
33
|
{props.blockChildren?.map((child) => (
|
|
35
34
|
<RenderBlock
|
|
36
35
|
key={"render-block-" + child.id}
|
|
@@ -46,7 +45,7 @@ function RenderComponent(props) {
|
|
|
46
45
|
context={props.context}
|
|
47
46
|
/>
|
|
48
47
|
))}
|
|
49
|
-
</
|
|
48
|
+
</props.componentRef>
|
|
50
49
|
</>
|
|
51
50
|
) : null}
|
|
52
51
|
</BuilderContext.Provider>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
'use client';
|
|
1
2
|
import * as React from "react";
|
|
2
3
|
import {
|
|
3
4
|
FlatList,
|
|
@@ -13,8 +14,8 @@ import { getCss } from "./render-styles.helpers";
|
|
|
13
14
|
import { getFontCss } from "./render-styles.helpers";
|
|
14
15
|
|
|
15
16
|
function RenderContentStyles(props) {
|
|
16
|
-
const [injectedStyles, setInjectedStyles] = useState(
|
|
17
|
-
|
|
17
|
+
const [injectedStyles, setInjectedStyles] = useState(() =>
|
|
18
|
+
`
|
|
18
19
|
${getCss({
|
|
19
20
|
cssCode: props.cssCode,
|
|
20
21
|
contentId: props.contentId,
|
|
@@ -35,7 +36,7 @@ ${getFontCss({
|
|
|
35
36
|
text-align: inherit;
|
|
36
37
|
font-family: inherit;
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
+
`.trim()
|
|
39
40
|
);
|
|
40
41
|
|
|
41
42
|
return <RenderInlinedStyles styles={injectedStyles} />;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
'use client';
|
|
1
2
|
import * as React from "react";
|
|
2
3
|
import {
|
|
3
4
|
FlatList,
|
|
@@ -35,6 +36,8 @@ import {
|
|
|
35
36
|
} from "./render-content.helpers.js";
|
|
36
37
|
import { TARGET } from "../../constants/target.js";
|
|
37
38
|
import { logger } from "../../helpers/logger.js";
|
|
39
|
+
import { getRenderContentScriptString } from "../render-content-variants/helpers.js";
|
|
40
|
+
import { wrapComponentRef } from "./wrap-component-ref.js";
|
|
38
41
|
|
|
39
42
|
function RenderContent(props) {
|
|
40
43
|
const elementRef = useRef(null);
|
|
@@ -105,9 +108,13 @@ function RenderContent(props) {
|
|
|
105
108
|
...components,
|
|
106
109
|
...(props.customComponents || []),
|
|
107
110
|
].reduce(
|
|
108
|
-
(acc, curr) => ({
|
|
111
|
+
(acc, { component, ...curr }) => ({
|
|
109
112
|
...acc,
|
|
110
|
-
[curr.name]:
|
|
113
|
+
[curr.name]: {
|
|
114
|
+
component:
|
|
115
|
+
TARGET === "vue3" ? wrapComponentRef(component) : component,
|
|
116
|
+
...curr,
|
|
117
|
+
},
|
|
111
118
|
}),
|
|
112
119
|
{}
|
|
113
120
|
)
|
|
@@ -244,6 +251,14 @@ function RenderContent(props) {
|
|
|
244
251
|
}
|
|
245
252
|
}
|
|
246
253
|
|
|
254
|
+
const [scriptStr, setScriptStr] = useState(() =>
|
|
255
|
+
getRenderContentScriptString({
|
|
256
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
|
|
257
|
+
contentId: props.content?.id,
|
|
258
|
+
parentContentId: props.parentContentId,
|
|
259
|
+
})
|
|
260
|
+
);
|
|
261
|
+
|
|
247
262
|
useEffect(() => {
|
|
248
263
|
if (!props.apiKey) {
|
|
249
264
|
logger.error(
|
|
@@ -265,6 +280,11 @@ function RenderContent(props) {
|
|
|
265
280
|
includeRefs: props.includeRefs,
|
|
266
281
|
}
|
|
267
282
|
: {}),
|
|
283
|
+
...(props.enrich
|
|
284
|
+
? {
|
|
285
|
+
enrich: props.enrich,
|
|
286
|
+
}
|
|
287
|
+
: {}),
|
|
268
288
|
});
|
|
269
289
|
Object.values(allRegisteredComponents).forEach(
|
|
270
290
|
(registeredComponent) => {
|
|
@@ -377,7 +397,27 @@ function RenderContent(props) {
|
|
|
377
397
|
onClick={(event) => onClick(event)}
|
|
378
398
|
builder-content-id={useContent?.id}
|
|
379
399
|
builder-model={props.model}
|
|
400
|
+
{...(TARGET === "reactNative"
|
|
401
|
+
? {
|
|
402
|
+
dataSet: {
|
|
403
|
+
// currently, we can't set the actual ID here. // we don't need it right now, we just need to identify content divs for testing.
|
|
404
|
+
"builder-content-id": "",
|
|
405
|
+
},
|
|
406
|
+
}
|
|
407
|
+
: {})}
|
|
408
|
+
{...(props.hideContent
|
|
409
|
+
? {
|
|
410
|
+
hidden: true,
|
|
411
|
+
"aria-hidden": true,
|
|
412
|
+
}
|
|
413
|
+
: {})}
|
|
380
414
|
>
|
|
415
|
+
{props.isSsrAbTest ? (
|
|
416
|
+
<>
|
|
417
|
+
<ScrollView dangerouslySetInnerHTML={{ __html: scriptStr }} />
|
|
418
|
+
</>
|
|
419
|
+
) : null}
|
|
420
|
+
|
|
381
421
|
{TARGET !== "reactNative" ? (
|
|
382
422
|
<>
|
|
383
423
|
<RenderContentStyles
|