@builder.io/sdk-react-native 0.5.1 → 0.5.3
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/README.md +4 -0
- package/dist/blocks/button/button.js +2 -2
- package/dist/blocks/columns/columns.js +8 -4
- package/dist/blocks/img/img.js +1 -1
- package/dist/blocks/input/input.js +1 -1
- package/dist/blocks/section/section.js +1 -1
- package/dist/blocks/select/select.js +1 -1
- package/dist/blocks/submit-button/submit-button.js +1 -1
- package/dist/blocks/symbol/symbol.js +4 -2
- package/dist/blocks/textarea/textarea.js +1 -1
- package/dist/components/blocks/blocks-wrapper.js +4 -2
- package/dist/components/content/components/enable-editor.js +5 -4
- package/dist/components/content/content.js +3 -1
- package/dist/components/content-variants/content-variants.js +13 -6
- package/dist/constants/sdk-version.js +2 -1
- package/dist/functions/evaluate/evaluate.js +39 -2
- package/dist/functions/evaluate/interpreter.js +1 -1
- package/package.json +15 -4
- package/src/components/content-variants/content-variants.jsx +13 -8
- package/src/constants/sdk-version.js +2 -1
- package/src/functions/evaluate/evaluate.js +15 -1
- package/src/functions/evaluate/interpreter.js +1 -1
- package/dist/blocks/util.js +0 -9
- package/dist/components/block/components/block-wrapper/block-wrapper.js +0 -41
- package/dist/components/block/components/component-ref.js +0 -81
- package/dist/components/block/components/component.js +0 -41
- package/dist/components/block/components/interactive-element/interactive-element.helpers.js +0 -35
- package/dist/components/block/components/interactive-element/interactive-element.js +0 -36
- package/dist/components/content/builder-editing.js +0 -32
- package/dist/components/content/components/content-styles.helpers.js +0 -55
- package/dist/components/content/components/content-styles.js +0 -61
- package/dist/components/render-block/block-styles.js +0 -96
- package/dist/components/render-block/render-block.helpers.js +0 -113
- package/dist/components/render-block/render-block.js +0 -162
- package/dist/components/render-block/render-component.js +0 -52
- package/dist/components/render-block/render-repeated-block.js +0 -40
- package/dist/components/render-block/types.js +0 -1
- package/dist/components/render-blocks.js +0 -81
- package/dist/components/render-content/builder-editing.js +0 -32
- package/dist/components/render-content/components/render-styles.helpers.js +0 -55
- package/dist/components/render-content/components/render-styles.js +0 -61
- package/dist/components/render-content/index.js +0 -8
- package/dist/components/render-content/render-content.helpers.js +0 -42
- package/dist/components/render-content/render-content.js +0 -375
- package/dist/components/render-content/render-content.types.js +0 -1
- package/dist/components/render-content/wrap-component-ref.js +0 -5
- package/dist/components/render-content-variants/helpers.js +0 -168
- package/dist/components/render-content-variants/render-content-variants.js +0 -78
- package/dist/components/render-content-variants/render-content-variants.types.js +0 -1
- package/dist/functions/apply-patch-with-mutation.test.js +0 -55
- package/dist/functions/evaluate.js +0 -47
- package/dist/functions/evaluate.test.js +0 -25
- package/dist/functions/get-builder-search-params/fn.test.js +0 -15
- package/dist/functions/get-content/generate-content-url.test.js +0 -113
- package/dist/functions/get-content/processCookies.js +0 -7
- package/dist/functions/get-processed-block.test.js +0 -38
- package/dist/functions/on-change.test.js +0 -31
- package/dist/functions/set.test.js +0 -24
- package/dist/helpers/url.test.js +0 -23
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getVariantsScriptString = exports.getVariants = exports.getScriptString = exports.getRenderContentScriptString = exports.checkShouldRunVariants = void 0;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __defProps = Object.defineProperties;
|
|
6
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
-
var __spreadValues = (a, b) => {
|
|
12
|
-
for (var prop in b || (b = {}))
|
|
13
|
-
if (__hasOwnProp.call(b, prop))
|
|
14
|
-
__defNormalProp(a, prop, b[prop]);
|
|
15
|
-
if (__getOwnPropSymbols)
|
|
16
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
-
if (__propIsEnum.call(b, prop))
|
|
18
|
-
__defNormalProp(a, prop, b[prop]);
|
|
19
|
-
}
|
|
20
|
-
return a;
|
|
21
|
-
};
|
|
22
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
|
-
const target_1 = require("../../constants/target");
|
|
24
|
-
const is_browser_1 = require("../../functions/is-browser");
|
|
25
|
-
const getVariants = (content) => Object.values((content == null ? void 0 : content.variations) || {}).map((variant) => __spreadProps(__spreadValues({}, variant), {
|
|
26
|
-
testVariationId: variant.id,
|
|
27
|
-
id: content == null ? void 0 : content.id
|
|
28
|
-
}));
|
|
29
|
-
exports.getVariants = getVariants;
|
|
30
|
-
const checkShouldRunVariants = ({ canTrack, content }) => {
|
|
31
|
-
const hasVariants = getVariants(content).length > 0;
|
|
32
|
-
if (target_1.TARGET === "reactNative")
|
|
33
|
-
return false;
|
|
34
|
-
if (!hasVariants)
|
|
35
|
-
return false;
|
|
36
|
-
if (!canTrack)
|
|
37
|
-
return false;
|
|
38
|
-
if (target_1.TARGET === "vue2" || target_1.TARGET === "vue3")
|
|
39
|
-
return true;
|
|
40
|
-
if ((0, is_browser_1.isBrowser)())
|
|
41
|
-
return false;
|
|
42
|
-
return true;
|
|
43
|
-
};
|
|
44
|
-
exports.checkShouldRunVariants = checkShouldRunVariants;
|
|
45
|
-
function bldrAbTest(contentId, variants, isHydrationTarget2) {
|
|
46
|
-
var _a;
|
|
47
|
-
function getAndSetVariantId() {
|
|
48
|
-
function setCookie(name, value, days) {
|
|
49
|
-
let expires = "";
|
|
50
|
-
if (days) {
|
|
51
|
-
const date = new Date();
|
|
52
|
-
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1e3);
|
|
53
|
-
expires = "; expires=" + date.toUTCString();
|
|
54
|
-
}
|
|
55
|
-
document.cookie = name + "=" + (value || "") + expires + "; path=/; Secure; SameSite=None";
|
|
56
|
-
}
|
|
57
|
-
function getCookie(name) {
|
|
58
|
-
const nameEQ = name + "=";
|
|
59
|
-
const ca = document.cookie.split(";");
|
|
60
|
-
for (let i = 0; i < ca.length; i++) {
|
|
61
|
-
let c = ca[i];
|
|
62
|
-
while (c.charAt(0) === " ")
|
|
63
|
-
c = c.substring(1, c.length);
|
|
64
|
-
if (c.indexOf(nameEQ) === 0)
|
|
65
|
-
return c.substring(nameEQ.length, c.length);
|
|
66
|
-
}
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
const cookieName = `builder.tests.${contentId}`;
|
|
70
|
-
const variantInCookie = getCookie(cookieName);
|
|
71
|
-
const availableIDs = variants.map((vr) => vr.id).concat(contentId);
|
|
72
|
-
if (variantInCookie && availableIDs.includes(variantInCookie)) {
|
|
73
|
-
return variantInCookie;
|
|
74
|
-
}
|
|
75
|
-
let n = 0;
|
|
76
|
-
const random = Math.random();
|
|
77
|
-
for (let i = 0; i < variants.length; i++) {
|
|
78
|
-
const variant = variants[i];
|
|
79
|
-
const testRatio = variant.testRatio;
|
|
80
|
-
n += testRatio;
|
|
81
|
-
if (random < n) {
|
|
82
|
-
setCookie(cookieName, variant.id);
|
|
83
|
-
return variant.id;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
setCookie(cookieName, contentId);
|
|
87
|
-
return contentId;
|
|
88
|
-
}
|
|
89
|
-
const winningVariantId = getAndSetVariantId();
|
|
90
|
-
const styleEl = (_a = document.currentScript) == null ? void 0 : _a.previousElementSibling;
|
|
91
|
-
if (isHydrationTarget2) {
|
|
92
|
-
styleEl.remove();
|
|
93
|
-
const thisScriptEl = document.currentScript;
|
|
94
|
-
thisScriptEl == null ? void 0 : thisScriptEl.remove();
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
const newStyleStr = variants.concat({ id: contentId }).filter((variant) => variant.id !== winningVariantId).map((value) => {
|
|
98
|
-
return `.variant-${value.id} { display: none; }
|
|
99
|
-
`;
|
|
100
|
-
}).join("");
|
|
101
|
-
styleEl.innerHTML = newStyleStr;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
function bldrCntntScrpt(variantContentId, defaultContentId, isHydrationTarget2) {
|
|
105
|
-
var _a;
|
|
106
|
-
if (!navigator.cookieEnabled) {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
function getCookie(name) {
|
|
110
|
-
const nameEQ = name + "=";
|
|
111
|
-
const ca = document.cookie.split(";");
|
|
112
|
-
for (let i = 0; i < ca.length; i++) {
|
|
113
|
-
let c = ca[i];
|
|
114
|
-
while (c.charAt(0) === " ")
|
|
115
|
-
c = c.substring(1, c.length);
|
|
116
|
-
if (c.indexOf(nameEQ) === 0)
|
|
117
|
-
return c.substring(nameEQ.length, c.length);
|
|
118
|
-
}
|
|
119
|
-
return null;
|
|
120
|
-
}
|
|
121
|
-
const cookieName = `builder.tests.${defaultContentId}`;
|
|
122
|
-
const variantId = getCookie(cookieName);
|
|
123
|
-
const parentDiv = (_a = document.currentScript) == null ? void 0 : _a.parentElement;
|
|
124
|
-
const variantIsDefaultContent = variantContentId === defaultContentId;
|
|
125
|
-
if (variantId === variantContentId) {
|
|
126
|
-
if (variantIsDefaultContent) {
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
parentDiv == null ? void 0 : parentDiv.removeAttribute("hidden");
|
|
130
|
-
parentDiv == null ? void 0 : parentDiv.removeAttribute("aria-hidden");
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
if (variantIsDefaultContent) {
|
|
134
|
-
if (isHydrationTarget2) {
|
|
135
|
-
parentDiv == null ? void 0 : parentDiv.remove();
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
parentDiv == null ? void 0 : parentDiv.setAttribute("hidden", "true");
|
|
139
|
-
parentDiv == null ? void 0 : parentDiv.setAttribute("aria-hidden", "true");
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
const getIsHydrationTarget = (target) => target === "react" || target === "reactNative";
|
|
147
|
-
const isHydrationTarget = getIsHydrationTarget(target_1.TARGET);
|
|
148
|
-
const AB_TEST_FN_NAME = "builderIoAbTest";
|
|
149
|
-
const CONTENT_FN_NAME = "builderIoRenderContent";
|
|
150
|
-
const getScriptString = () => {
|
|
151
|
-
const fnStr = bldrAbTest.toString().replace(/\s+/g, " ");
|
|
152
|
-
const fnStr2 = bldrCntntScrpt.toString().replace(/\s+/g, " ");
|
|
153
|
-
return `
|
|
154
|
-
window.${AB_TEST_FN_NAME} = ${fnStr}
|
|
155
|
-
window.${CONTENT_FN_NAME} = ${fnStr2}
|
|
156
|
-
`;
|
|
157
|
-
};
|
|
158
|
-
exports.getScriptString = getScriptString;
|
|
159
|
-
const getVariantsScriptString = (variants, contentId) => {
|
|
160
|
-
return `
|
|
161
|
-
window.${AB_TEST_FN_NAME}("${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget})`;
|
|
162
|
-
};
|
|
163
|
-
exports.getVariantsScriptString = getVariantsScriptString;
|
|
164
|
-
const getRenderContentScriptString = ({ contentId, variationId }) => {
|
|
165
|
-
return `
|
|
166
|
-
window.${CONTENT_FN_NAME}("${variationId}", "${contentId}", ${isHydrationTarget})`;
|
|
167
|
-
};
|
|
168
|
-
exports.getRenderContentScriptString = getRenderContentScriptString;
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
'use client';
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
-
}) : function(o, v) {
|
|
17
|
-
o["default"] = v;
|
|
18
|
-
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
-
if (mod && mod.__esModule) return mod;
|
|
21
|
-
var result = {};
|
|
22
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
-
__setModuleDefault(result, mod);
|
|
24
|
-
return result;
|
|
25
|
-
};
|
|
26
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
27
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
28
|
-
};
|
|
29
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
const React = __importStar(require("react"));
|
|
31
|
-
const react_native_1 = require("react-native");
|
|
32
|
-
const react_1 = require("react");
|
|
33
|
-
const helpers_1 = require("./helpers");
|
|
34
|
-
const render_content_1 = __importDefault(require("../render-content/render-content"));
|
|
35
|
-
const canTrack_1 = require("../../helpers/canTrack");
|
|
36
|
-
const inlined_styles_1 = __importDefault(require("../inlined-styles"));
|
|
37
|
-
const ab_tests_1 = require("../../helpers/ab-tests");
|
|
38
|
-
const inlined_script_1 = __importDefault(require("../inlined-script"));
|
|
39
|
-
const target_1 = require("../../constants/target");
|
|
40
|
-
function RenderContentVariants(props) {
|
|
41
|
-
var _a, _b, _c;
|
|
42
|
-
const [shouldRenderVariants, setShouldRenderVariants] = (0, react_1.useState)(() => (0, helpers_1.checkShouldRunVariants)({
|
|
43
|
-
canTrack: (0, canTrack_1.getDefaultCanTrack)(props.canTrack),
|
|
44
|
-
content: props.content,
|
|
45
|
-
}));
|
|
46
|
-
const [variantScriptStr, setVariantScriptStr] = (0, react_1.useState)(() => {
|
|
47
|
-
var _a;
|
|
48
|
-
return (0, helpers_1.getVariantsScriptString)((0, helpers_1.getVariants)(props.content).map((value) => ({
|
|
49
|
-
id: value.testVariationId,
|
|
50
|
-
testRatio: value.testRatio,
|
|
51
|
-
})), ((_a = props.content) === null || _a === void 0 ? void 0 : _a.id) || "");
|
|
52
|
-
});
|
|
53
|
-
const [hideVariantsStyleString, setHideVariantsStyleString] = (0, react_1.useState)(() => (0, helpers_1.getVariants)(props.content)
|
|
54
|
-
.map((value) => `.variant-${value.testVariationId} { display: none; } `)
|
|
55
|
-
.join(""));
|
|
56
|
-
(0, react_1.useEffect)(() => {
|
|
57
|
-
/**
|
|
58
|
-
* We unmount the non-winning variants post-hydration in Vue.
|
|
59
|
-
*/
|
|
60
|
-
if (target_1.TARGET === "vue2" || target_1.TARGET === "vue3") {
|
|
61
|
-
setShouldRenderVariants(false);
|
|
62
|
-
}
|
|
63
|
-
}, []);
|
|
64
|
-
return (React.createElement(React.Fragment, null,
|
|
65
|
-
!props.__isNestedRender && target_1.TARGET !== "reactNative" ? (React.createElement(React.Fragment, null,
|
|
66
|
-
React.createElement(inlined_script_1.default, { scriptStr: (0, helpers_1.getScriptString)() }))) : null,
|
|
67
|
-
shouldRenderVariants ? (React.createElement(React.Fragment, null,
|
|
68
|
-
React.createElement(inlined_styles_1.default, { id: `variants-styles-${(_a = props.content) === null || _a === void 0 ? void 0 : _a.id}`, styles: hideVariantsStyleString }),
|
|
69
|
-
React.createElement(inlined_script_1.default, { scriptStr: variantScriptStr }), (_b = (0, helpers_1.getVariants)(props.content)) === null || _b === void 0 ? void 0 :
|
|
70
|
-
_b.map((variant) => (React.createElement(render_content_1.default, { key: variant.testVariationId, content: variant, showContent: false, classNameProp: undefined, model: props.model, data: props.data, context: props.context, apiKey: props.apiKey, apiVersion: props.apiVersion, customComponents: props.customComponents, canTrack: props.canTrack, locale: props.locale, includeRefs: props.includeRefs, enrich: props.enrich, isSsrAbTest: shouldRenderVariants }))))) : null,
|
|
71
|
-
React.createElement(render_content_1.default, { ...{}, content: shouldRenderVariants
|
|
72
|
-
? props.content
|
|
73
|
-
: (0, ab_tests_1.handleABTestingSync)({
|
|
74
|
-
item: props.content,
|
|
75
|
-
canTrack: (0, canTrack_1.getDefaultCanTrack)(props.canTrack),
|
|
76
|
-
}), classNameProp: `variant-${(_c = props.content) === null || _c === void 0 ? void 0 : _c.id}`, showContent: true, model: props.model, data: props.data, context: props.context, apiKey: props.apiKey, apiVersion: props.apiVersion, customComponents: props.customComponents, canTrack: props.canTrack, locale: props.locale, includeRefs: props.includeRefs, enrich: props.enrich, isSsrAbTest: shouldRenderVariants })));
|
|
77
|
-
}
|
|
78
|
-
exports.default = RenderContentVariants;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const apply_patch_with_mutation_js_1 = require("./apply-patch-with-mutation.js");
|
|
4
|
-
describe("applyPatchWithMinimalMutationChain", () => {
|
|
5
|
-
test("Basic shallow update", () => {
|
|
6
|
-
const obj = {
|
|
7
|
-
foo: "bar"
|
|
8
|
-
};
|
|
9
|
-
const patch = {
|
|
10
|
-
op: "replace",
|
|
11
|
-
path: "/foo",
|
|
12
|
-
value: "60px"
|
|
13
|
-
};
|
|
14
|
-
const applied = (0, apply_patch_with_mutation_js_1.applyPatchWithMinimalMutationChain)(obj, patch);
|
|
15
|
-
expect(applied.foo).toBe("60px");
|
|
16
|
-
expect(applied).not.toBe(obj);
|
|
17
|
-
});
|
|
18
|
-
test("Deep object updates", () => {
|
|
19
|
-
const obj = {
|
|
20
|
-
foo: {
|
|
21
|
-
bar: true
|
|
22
|
-
},
|
|
23
|
-
baz: {}
|
|
24
|
-
};
|
|
25
|
-
const patch = {
|
|
26
|
-
op: "replace",
|
|
27
|
-
path: "/foo/bar",
|
|
28
|
-
value: "60px"
|
|
29
|
-
};
|
|
30
|
-
const applied = (0, apply_patch_with_mutation_js_1.applyPatchWithMinimalMutationChain)(obj, patch);
|
|
31
|
-
expect(applied.foo.bar).toBe("60px");
|
|
32
|
-
expect(applied).not.toBe(obj);
|
|
33
|
-
expect(applied.foo).not.toBe(obj.foo);
|
|
34
|
-
expect(applied.baz).toBe(obj.baz);
|
|
35
|
-
});
|
|
36
|
-
test("Deep array updates", () => {
|
|
37
|
-
const obj = {
|
|
38
|
-
foo: [{
|
|
39
|
-
bar: true
|
|
40
|
-
}],
|
|
41
|
-
baz: {}
|
|
42
|
-
};
|
|
43
|
-
const patch = {
|
|
44
|
-
op: "replace",
|
|
45
|
-
path: "/foo/0/bar",
|
|
46
|
-
value: "60px"
|
|
47
|
-
};
|
|
48
|
-
const applied = (0, apply_patch_with_mutation_js_1.applyPatchWithMinimalMutationChain)(obj, patch);
|
|
49
|
-
expect(applied.foo[0].bar).toBe("60px");
|
|
50
|
-
expect(applied).not.toBe(obj);
|
|
51
|
-
expect(applied.foo).not.toBe(obj.foo);
|
|
52
|
-
expect(applied.foo[0]).not.toBe(obj.foo[0]);
|
|
53
|
-
expect(applied.baz).toBe(obj.baz);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.flattenState = exports.evaluate = void 0;
|
|
4
|
-
const is_browser_js_1 = require("./is-browser.js");
|
|
5
|
-
const is_editing_js_1 = require("./is-editing.js");
|
|
6
|
-
function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true }) {
|
|
7
|
-
if (code === "") {
|
|
8
|
-
console.warn("Skipping evaluation of empty code block.");
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
const builder = {
|
|
12
|
-
isEditing: (0, is_editing_js_1.isEditing)(),
|
|
13
|
-
isBrowser: (0, is_browser_js_1.isBrowser)(),
|
|
14
|
-
isServer: !(0, is_browser_js_1.isBrowser)()
|
|
15
|
-
};
|
|
16
|
-
const useReturn = isExpression && !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "));
|
|
17
|
-
const useCode = useReturn ? `return (${code});` : code;
|
|
18
|
-
try {
|
|
19
|
-
return new Function("builder", "Builder", "state", "context", "event", useCode)(builder, builder, flattenState(rootState, localState, rootSetState), context, event);
|
|
20
|
-
}
|
|
21
|
-
catch (e) {
|
|
22
|
-
console.warn("Builder custom code error: \n While Evaluating: \n ", useCode, "\n", e);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.evaluate = evaluate;
|
|
26
|
-
function flattenState(rootState, localState, rootSetState) {
|
|
27
|
-
if (rootState === localState) {
|
|
28
|
-
throw new Error("rootState === localState");
|
|
29
|
-
}
|
|
30
|
-
return new Proxy(rootState, {
|
|
31
|
-
get: (_, prop) => {
|
|
32
|
-
if (localState && prop in localState) {
|
|
33
|
-
return localState[prop];
|
|
34
|
-
}
|
|
35
|
-
return rootState[prop];
|
|
36
|
-
},
|
|
37
|
-
set: (_, prop, value) => {
|
|
38
|
-
if (localState && prop in localState) {
|
|
39
|
-
throw new Error("Writing to local state is not allowed as it is read-only.");
|
|
40
|
-
}
|
|
41
|
-
rootState[prop] = value;
|
|
42
|
-
rootSetState == null ? void 0 : rootSetState(rootState);
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
exports.flattenState = flattenState;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const evaluate_js_1 = require("./evaluate.js");
|
|
4
|
-
describe("flatten state", () => {
|
|
5
|
-
it("should behave normally when no PROTO_STATE", () => {
|
|
6
|
-
const localState = {};
|
|
7
|
-
const rootState = {
|
|
8
|
-
foo: "bar"
|
|
9
|
-
};
|
|
10
|
-
const flattened = (0, evaluate_js_1.flattenState)(rootState, localState, void 0);
|
|
11
|
-
expect(flattened.foo).toEqual("bar");
|
|
12
|
-
flattened.foo = "baz";
|
|
13
|
-
expect(rootState.foo).toEqual("baz");
|
|
14
|
-
});
|
|
15
|
-
it("should shadow write ", () => {
|
|
16
|
-
const rootState = {
|
|
17
|
-
foo: "foo"
|
|
18
|
-
};
|
|
19
|
-
const localState = {
|
|
20
|
-
foo: "baz"
|
|
21
|
-
};
|
|
22
|
-
const flattened = (0, evaluate_js_1.flattenState)(rootState, localState, void 0);
|
|
23
|
-
expect(() => flattened.foo = "bar").toThrow("Writing to local state is not allowed as it is read-only.");
|
|
24
|
-
});
|
|
25
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const index_js_1 = require("./index.js");
|
|
4
|
-
const querystring = "someotherValue=jklsjfdal&abc=klfdjklgfds&builder.cachebust=true&builder.preview=page&builder.noCache=true&__builder_editing__=true&builder.overrides.page=037948e52eaf4743afed464f02c70da4&builder.overrides.037948e52eaf4743afed464f02c70da4=037948e52eaf4743afed464f02c70da4&builder.overrides.page%3A%2F=037948e52eaf4743afed464f02c70da4&preview_theme_id=128854393017";
|
|
5
|
-
const url = new URL(`localhost:3000/about-us?${querystring}`);
|
|
6
|
-
describe("Get Builder SearchParams", () => {
|
|
7
|
-
test("correctly converts URLSearchParams to object", () => {
|
|
8
|
-
const output = (0, index_js_1.convertSearchParamsToQueryObject)(url.searchParams);
|
|
9
|
-
expect(output).toMatchSnapshot();
|
|
10
|
-
});
|
|
11
|
-
test("correctly extracts all builder params from a query object", () => {
|
|
12
|
-
const output = (0, index_js_1.getBuilderSearchParams)((0, index_js_1.convertSearchParamsToQueryObject)(url.searchParams));
|
|
13
|
-
expect(output).toMatchSnapshot();
|
|
14
|
-
});
|
|
15
|
-
});
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const generate_content_url_js_1 = require("./generate-content-url.js");
|
|
4
|
-
const testKey = "YJIGb4i01jvw0SRdL5Bt";
|
|
5
|
-
const testModel = "page";
|
|
6
|
-
const testId = "c1b81bab59704599b997574eb0736def";
|
|
7
|
-
const options = {
|
|
8
|
-
cachebust: "true",
|
|
9
|
-
noCache: "true",
|
|
10
|
-
"overrides.037948e52eaf4743afed464f02c70da4": "037948e52eaf4743afed464f02c70da4",
|
|
11
|
-
"overrides.page": "037948e52eaf4743afed464f02c70da4",
|
|
12
|
-
"overrides.page:/": "037948e52eaf4743afed464f02c70da4",
|
|
13
|
-
preview: "page"
|
|
14
|
-
};
|
|
15
|
-
describe("Generate Content URL", () => {
|
|
16
|
-
test("generates the proper value for a simple query", () => {
|
|
17
|
-
const output = (0, generate_content_url_js_1.generateContentUrl)({
|
|
18
|
-
apiKey: testKey,
|
|
19
|
-
model: testModel,
|
|
20
|
-
query: {
|
|
21
|
-
id: testId
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
expect(output).toMatchSnapshot();
|
|
25
|
-
});
|
|
26
|
-
test("Handles overrides correctly", () => {
|
|
27
|
-
const output = (0, generate_content_url_js_1.generateContentUrl)({
|
|
28
|
-
apiKey: testKey,
|
|
29
|
-
model: testModel,
|
|
30
|
-
query: {
|
|
31
|
-
id: testId
|
|
32
|
-
},
|
|
33
|
-
options
|
|
34
|
-
});
|
|
35
|
-
expect(output).toMatchSnapshot();
|
|
36
|
-
});
|
|
37
|
-
test("generate content url with apiVersion as default", () => {
|
|
38
|
-
const output = (0, generate_content_url_js_1.generateContentUrl)({
|
|
39
|
-
apiKey: testKey,
|
|
40
|
-
model: testModel,
|
|
41
|
-
query: {
|
|
42
|
-
id: testId
|
|
43
|
-
},
|
|
44
|
-
options
|
|
45
|
-
});
|
|
46
|
-
expect(output).toMatchSnapshot();
|
|
47
|
-
});
|
|
48
|
-
test("generate content url with apiVersion as v2", () => {
|
|
49
|
-
const output = (0, generate_content_url_js_1.generateContentUrl)({
|
|
50
|
-
apiKey: testKey,
|
|
51
|
-
model: testModel,
|
|
52
|
-
query: {
|
|
53
|
-
id: testId
|
|
54
|
-
},
|
|
55
|
-
options,
|
|
56
|
-
apiVersion: "v2"
|
|
57
|
-
});
|
|
58
|
-
expect(output).toMatchSnapshot();
|
|
59
|
-
});
|
|
60
|
-
test("generate content url with apiVersion as v3", () => {
|
|
61
|
-
const output = (0, generate_content_url_js_1.generateContentUrl)({
|
|
62
|
-
apiKey: testKey,
|
|
63
|
-
model: testModel,
|
|
64
|
-
query: {
|
|
65
|
-
id: testId
|
|
66
|
-
},
|
|
67
|
-
options,
|
|
68
|
-
apiVersion: "v3"
|
|
69
|
-
});
|
|
70
|
-
expect(output).toMatchSnapshot();
|
|
71
|
-
});
|
|
72
|
-
test("throw error when trying to generate content url with apiVersion as v1", () => {
|
|
73
|
-
expect(() => {
|
|
74
|
-
(0, generate_content_url_js_1.generateContentUrl)({
|
|
75
|
-
apiKey: testKey,
|
|
76
|
-
model: testModel,
|
|
77
|
-
query: {
|
|
78
|
-
id: testId
|
|
79
|
-
},
|
|
80
|
-
options,
|
|
81
|
-
apiVersion: "v1"
|
|
82
|
-
});
|
|
83
|
-
}).toThrow(`Invalid apiVersion: expected 'v2' or 'v3', received 'v1'`);
|
|
84
|
-
});
|
|
85
|
-
test("throw error when trying to generate content url with an invalid apiVersion value", () => {
|
|
86
|
-
expect(() => {
|
|
87
|
-
(0, generate_content_url_js_1.generateContentUrl)({
|
|
88
|
-
apiKey: testKey,
|
|
89
|
-
model: testModel,
|
|
90
|
-
query: {
|
|
91
|
-
id: testId
|
|
92
|
-
},
|
|
93
|
-
options,
|
|
94
|
-
apiVersion: "INVALID_API_VERSION"
|
|
95
|
-
});
|
|
96
|
-
}).toThrow(`Invalid apiVersion: expected 'v2' or 'v3', received 'INVALID_API_VERSION'`);
|
|
97
|
-
});
|
|
98
|
-
test("generate content url with enrich option true", () => {
|
|
99
|
-
const output = (0, generate_content_url_js_1.generateContentUrl)({
|
|
100
|
-
apiKey: testKey,
|
|
101
|
-
model: testModel,
|
|
102
|
-
enrich: true
|
|
103
|
-
});
|
|
104
|
-
expect(output).toMatchSnapshot();
|
|
105
|
-
});
|
|
106
|
-
test("generate content url with enrich option not present", () => {
|
|
107
|
-
const output = (0, generate_content_url_js_1.generateContentUrl)({
|
|
108
|
-
apiKey: testKey,
|
|
109
|
-
model: testModel
|
|
110
|
-
});
|
|
111
|
-
expect(output).toMatchSnapshot();
|
|
112
|
-
});
|
|
113
|
-
});
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const get_processed_block_js_1 = require("./get-processed-block.js");
|
|
4
|
-
test("Can process bindings", () => {
|
|
5
|
-
var _a, _b, _c, _d, _e, _f;
|
|
6
|
-
const block = {
|
|
7
|
-
"@type": "@builder.io/sdk:Element",
|
|
8
|
-
properties: {
|
|
9
|
-
foo: "bar"
|
|
10
|
-
},
|
|
11
|
-
bindings: {
|
|
12
|
-
"properties.foo": '"baz"',
|
|
13
|
-
"responsiveStyles.large.zIndex": "1 + 1",
|
|
14
|
-
"properties.test": "state.test",
|
|
15
|
-
"properties.block": `
|
|
16
|
-
const foo = 'bar';
|
|
17
|
-
return foo;
|
|
18
|
-
`,
|
|
19
|
-
"properties.isEditing": "builder.isEditing"
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
const processed = (0, get_processed_block_js_1.getProcessedBlock)({
|
|
23
|
-
block,
|
|
24
|
-
context: {},
|
|
25
|
-
rootState: {
|
|
26
|
-
test: "hello"
|
|
27
|
-
},
|
|
28
|
-
rootSetState: void 0,
|
|
29
|
-
localState: void 0,
|
|
30
|
-
shouldEvaluateBindings: true
|
|
31
|
-
});
|
|
32
|
-
expect(processed).not.toEqual(block);
|
|
33
|
-
expect((_a = processed.properties) == null ? void 0 : _a.foo).toEqual("baz");
|
|
34
|
-
expect((_b = processed.properties) == null ? void 0 : _b.test).toEqual("hello");
|
|
35
|
-
expect((_c = processed.properties) == null ? void 0 : _c.block).toEqual("bar");
|
|
36
|
-
expect((_d = processed.properties) == null ? void 0 : _d.isEditing).toEqual(false);
|
|
37
|
-
expect((_f = (_e = processed.responsiveStyles) == null ? void 0 : _e.large) == null ? void 0 : _f.zIndex).toEqual(2);
|
|
38
|
-
});
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const on_change_js_1 = require("./on-change.js");
|
|
4
|
-
test("onChange can observe a shallow change", () => {
|
|
5
|
-
let changeHappend = false;
|
|
6
|
-
const obj = (0, on_change_js_1.onChange)({
|
|
7
|
-
foo: "hi"
|
|
8
|
-
}, () => changeHappend = true);
|
|
9
|
-
obj.foo = "yo";
|
|
10
|
-
expect(changeHappend).toBe(true);
|
|
11
|
-
});
|
|
12
|
-
test("onChange can observe a deep change", () => {
|
|
13
|
-
let changeHappend = false;
|
|
14
|
-
const obj = (0, on_change_js_1.onChange)({
|
|
15
|
-
foo: {
|
|
16
|
-
bar: "hi"
|
|
17
|
-
}
|
|
18
|
-
}, () => changeHappend = true);
|
|
19
|
-
obj.foo.bar = "yo";
|
|
20
|
-
expect(changeHappend).toBe(true);
|
|
21
|
-
});
|
|
22
|
-
test("Smoke test: callback is not fired if no properties updated", () => {
|
|
23
|
-
let changeHappend = false;
|
|
24
|
-
const obj = (0, on_change_js_1.onChange)({
|
|
25
|
-
foo: {
|
|
26
|
-
bar: "hi"
|
|
27
|
-
}
|
|
28
|
-
}, () => changeHappend = true);
|
|
29
|
-
obj.foo.bar;
|
|
30
|
-
expect(changeHappend).toBe(false);
|
|
31
|
-
});
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const set_js_1 = require("./set.js");
|
|
4
|
-
test("can shallow set a property", () => {
|
|
5
|
-
const obj = {
|
|
6
|
-
foo: "bar"
|
|
7
|
-
};
|
|
8
|
-
(0, set_js_1.set)(obj, "foo", "baz");
|
|
9
|
-
expect(obj.foo).toBe("baz");
|
|
10
|
-
});
|
|
11
|
-
test("can deeply set a property", () => {
|
|
12
|
-
const obj = {
|
|
13
|
-
foo: "bar"
|
|
14
|
-
};
|
|
15
|
-
(0, set_js_1.set)(obj, "foo.bar", "baz");
|
|
16
|
-
expect(obj.foo.bar).toBe("baz");
|
|
17
|
-
});
|
|
18
|
-
test("can deeply create arrays", () => {
|
|
19
|
-
const obj = {
|
|
20
|
-
foo: "bar"
|
|
21
|
-
};
|
|
22
|
-
(0, set_js_1.set)(obj, "foo.bar.0", "hi");
|
|
23
|
-
expect(obj.foo.bar).toEqual(["hi"]);
|
|
24
|
-
});
|
package/dist/helpers/url.test.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const url_js_1 = require("./url.js");
|
|
4
|
-
describe("getTopLevelDomain", () => {
|
|
5
|
-
test("handles root domain", () => {
|
|
6
|
-
const output = (0, url_js_1.getTopLevelDomain)("example.com");
|
|
7
|
-
expect(output).toBe("example.com");
|
|
8
|
-
});
|
|
9
|
-
test("handles subdomain", () => {
|
|
10
|
-
const output = (0, url_js_1.getTopLevelDomain)("wwww.example.com");
|
|
11
|
-
expect(output).toBe("example.com");
|
|
12
|
-
});
|
|
13
|
-
test("handles subdomain with long suffix", () => {
|
|
14
|
-
const output = (0, url_js_1.getTopLevelDomain)("www.example.co.uk");
|
|
15
|
-
expect(output).toBe("example.co.uk");
|
|
16
|
-
});
|
|
17
|
-
test("handles localhost", () => {
|
|
18
|
-
const output = (0, url_js_1.getTopLevelDomain)("localhost");
|
|
19
|
-
expect(output).toBe("localhost");
|
|
20
|
-
const output2 = (0, url_js_1.getTopLevelDomain)("127.0.0.1");
|
|
21
|
-
expect(output2).toBe("127.0.0.1");
|
|
22
|
-
});
|
|
23
|
-
});
|