@builder.io/sdk-solid 0.0.16 → 0.0.17
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 +5 -1
- package/package.json +17 -5
- package/solid-index.jsx +5 -0
- package/src/blocks/BaseText.jsx +9 -0
- package/src/blocks/button/button.jsx +9 -6
- package/src/blocks/columns/columns.jsx +54 -52
- package/src/blocks/columns/component-info.js +26 -1
- package/src/blocks/custom-code/custom-code.jsx +35 -38
- package/src/blocks/embed/component-info.js +21 -1
- package/src/blocks/embed/embed.jsx +37 -42
- package/src/blocks/embed/helpers.js +9 -0
- package/src/blocks/form/form.jsx +175 -176
- package/src/blocks/image/component-info.js +48 -1
- package/src/blocks/image/image.helpers.js +48 -0
- package/src/blocks/image/image.jsx +44 -13
- package/src/blocks/img/img.jsx +1 -1
- package/src/blocks/symbol/component-info.js +1 -0
- package/src/blocks/symbol/symbol.jsx +39 -12
- package/src/blocks/text/text.jsx +1 -1
- package/src/blocks/util.js +7 -0
- package/src/blocks/video/video.jsx +21 -2
- package/src/components/render-block/block-styles.jsx +41 -31
- package/src/components/render-block/render-block.helpers.js +23 -0
- package/src/components/render-block/render-block.jsx +205 -90
- package/src/components/render-block/render-component-with-context.jsx +36 -0
- package/src/components/render-block/render-component.jsx +28 -0
- package/src/components/render-block/render-repeated-block.jsx +36 -0
- package/src/components/render-block/types.js +0 -0
- package/src/components/render-blocks.jsx +42 -33
- package/src/components/render-content/components/render-styles.jsx +39 -42
- package/src/components/render-content/index.js +4 -0
- package/src/components/render-content/render-content.jsx +199 -128
- package/src/components/render-inlined-styles.jsx +21 -5
- package/src/constants/builder-registered-components.js +54 -0
- package/src/constants/device-sizes.js +3 -21
- package/src/context/builder.context.js +3 -1
- package/src/context/types.js +0 -0
- package/src/functions/camel-to-kebab-case.js +4 -0
- package/src/functions/convert-style-object.js +14 -0
- package/src/functions/evaluate.js +1 -1
- package/src/functions/extract-text-styles.js +22 -0
- package/src/functions/fast-clone.js +4 -0
- package/src/functions/get-block-actions-handler.js +12 -0
- package/src/functions/get-block-actions.js +2 -7
- package/src/functions/get-block-component-options.js +6 -1
- package/src/functions/get-block-styles.js +27 -19
- package/src/functions/get-builder-search-params/index.js +17 -2
- package/src/functions/get-content/ab-testing.js +99 -0
- package/src/functions/get-content/fn.test.js +1 -1
- package/src/functions/get-content/index.js +20 -62
- package/src/functions/get-content/types.js +0 -0
- package/src/functions/get-fetch.js +2 -2
- package/src/functions/get-processed-block.js +24 -11
- package/src/functions/get-processed-block.test.js +2 -1
- package/src/functions/mark-mutable.js +10 -0
- package/src/functions/register-component.js +45 -26
- package/src/functions/sanitize-styles.js +4 -0
- package/src/functions/track.js +108 -13
- package/src/helpers/ab-tests.js +16 -0
- package/src/helpers/cookie.js +79 -0
- package/src/helpers/css.js +28 -0
- package/src/helpers/flatten.js +34 -0
- package/src/helpers/localStorage.js +34 -0
- package/src/helpers/nullable.js +4 -0
- package/src/helpers/sessionId.js +49 -0
- package/src/helpers/time.js +5 -0
- package/src/helpers/url.js +10 -0
- package/src/helpers/url.test.js +15 -0
- package/src/helpers/uuid.js +13 -0
- package/src/helpers/visitorId.js +33 -0
- package/src/index-helpers/blocks-exports.js +11 -9
- package/src/scripts/init-editing.js +4 -5
- package/src/types/can-track.js +0 -0
- package/src/types/components.js +0 -0
- package/src/types/element.js +0 -0
- package/src/blocks/button/button.lite.tsx +0 -20
- package/src/blocks/button/index.js +0 -7
- package/src/blocks/columns/columns.lite.tsx +0 -102
- package/src/blocks/columns/index.js +0 -7
- package/src/blocks/custom-code/custom-code.lite.tsx +0 -67
- package/src/blocks/custom-code/index.js +0 -7
- package/src/blocks/embed/embed.lite.tsx +0 -59
- package/src/blocks/embed/index.js +0 -7
- package/src/blocks/form/form.lite.tsx +0 -293
- package/src/blocks/form/index.js +0 -7
- package/src/blocks/fragment/fragment.lite.tsx +0 -5
- package/src/blocks/fragment/index.js +0 -7
- package/src/blocks/image/image.lite.tsx +0 -83
- package/src/blocks/image/index.js +0 -7
- package/src/blocks/img/img.lite.tsx +0 -18
- package/src/blocks/img/index.js +0 -7
- package/src/blocks/input/index.js +0 -7
- package/src/blocks/input/input.lite.tsx +0 -20
- package/src/blocks/raw-text/index.js +0 -7
- package/src/blocks/raw-text/raw-text.lite.tsx +0 -10
- package/src/blocks/section/index.js +0 -7
- package/src/blocks/section/section.lite.tsx +0 -18
- package/src/blocks/select/index.js +0 -7
- package/src/blocks/select/select.lite.tsx +0 -28
- package/src/blocks/submit-button/index.js +0 -7
- package/src/blocks/submit-button/submit-button.lite.tsx +0 -9
- package/src/blocks/symbol/index.js +0 -7
- package/src/blocks/symbol/symbol.lite.tsx +0 -39
- package/src/blocks/text/index.js +0 -7
- package/src/blocks/text/text.lite.tsx +0 -5
- package/src/blocks/textarea/index.js +0 -7
- package/src/blocks/textarea/textarea.lite.tsx +0 -13
- package/src/blocks/video/index.js +0 -7
- package/src/blocks/video/video.lite.tsx +0 -26
- package/src/components/error-boundary.jsx +0 -5
- package/src/components/error-boundary.lite.tsx +0 -5
- package/src/components/render-block/block-styles.lite.tsx +0 -38
- package/src/components/render-block/render-block.lite.tsx +0 -119
- package/src/components/render-blocks.lite.tsx +0 -75
- package/src/components/render-content/components/render-styles.lite.tsx +0 -76
- package/src/components/render-content/render-content.lite.tsx +0 -232
- package/src/components/render-inlined-styles.lite.tsx +0 -5
- package/src/functions/macro-eval.js +0 -5
- package/src/functions/previewing-model-name.js +0 -11
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
import { default as Button } from "../blocks/button/button.jsx";
|
|
18
|
+
import { componentInfo as buttonComponentInfo } from "../blocks/button/component-info.js";
|
|
19
|
+
import { default as Columns } from "../blocks/columns/columns.jsx";
|
|
20
|
+
import { componentInfo as columnsComponentInfo } from "../blocks/columns/component-info.js";
|
|
21
|
+
import { componentInfo as fragmentComponentInfo } from "../blocks/fragment/component-info.js";
|
|
22
|
+
import { default as Fragment } from "../blocks/fragment/fragment.jsx";
|
|
23
|
+
import { componentInfo as imageComponentInfo } from "../blocks/image/component-info.js";
|
|
24
|
+
import { default as Image } from "../blocks/image/image.jsx";
|
|
25
|
+
import { componentInfo as sectionComponentInfo } from "../blocks/section/component-info.js";
|
|
26
|
+
import { default as Section } from "../blocks/section/section.jsx";
|
|
27
|
+
import { componentInfo as symbolComponentInfo } from "../blocks/symbol/component-info.js";
|
|
28
|
+
import { default as Symbol } from "../blocks/symbol/symbol.jsx";
|
|
29
|
+
import { componentInfo as textComponentInfo } from "../blocks/text/component-info.js";
|
|
30
|
+
import { default as Text } from "../blocks/text/text.jsx";
|
|
31
|
+
import { componentInfo as videoComponentInfo } from "../blocks/video/component-info.js";
|
|
32
|
+
import { default as Video } from "../blocks/video/video.jsx";
|
|
33
|
+
import { componentInfo as embedComponentInfo } from "../blocks/embed/component-info.js";
|
|
34
|
+
import { default as embed } from "../blocks/embed/embed.jsx";
|
|
35
|
+
import { default as Img } from "../blocks/img/img.jsx";
|
|
36
|
+
import { componentInfo as imgComponentInfo } from "../blocks/img/component-info.js";
|
|
37
|
+
import { default as customCode } from "../blocks/custom-code/custom-code.jsx";
|
|
38
|
+
import { componentInfo as customCodeInfo } from "../blocks/custom-code/component-info.js";
|
|
39
|
+
const getDefaultRegisteredComponents = () => [
|
|
40
|
+
__spreadValues({ component: Columns }, columnsComponentInfo),
|
|
41
|
+
__spreadValues({ component: Image }, imageComponentInfo),
|
|
42
|
+
__spreadValues({ component: Img }, imgComponentInfo),
|
|
43
|
+
__spreadValues({ component: Text }, textComponentInfo),
|
|
44
|
+
__spreadValues({ component: Video }, videoComponentInfo),
|
|
45
|
+
__spreadValues({ component: Symbol }, symbolComponentInfo),
|
|
46
|
+
__spreadValues({ component: Button }, buttonComponentInfo),
|
|
47
|
+
__spreadValues({ component: Section }, sectionComponentInfo),
|
|
48
|
+
__spreadValues({ component: Fragment }, fragmentComponentInfo),
|
|
49
|
+
__spreadValues({ component: embed }, embedComponentInfo),
|
|
50
|
+
__spreadValues({ component: customCode }, customCodeInfo)
|
|
51
|
+
];
|
|
52
|
+
export {
|
|
53
|
+
getDefaultRegisteredComponents
|
|
54
|
+
};
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
const
|
|
2
|
-
const sizes = {
|
|
3
|
-
xsmall: {
|
|
4
|
-
min: 0,
|
|
5
|
-
default: 0,
|
|
6
|
-
max: 0
|
|
7
|
-
},
|
|
1
|
+
const SIZES = {
|
|
8
2
|
small: {
|
|
9
3
|
min: 320,
|
|
10
4
|
default: 321,
|
|
@@ -19,21 +13,9 @@ const sizes = {
|
|
|
19
13
|
min: 990,
|
|
20
14
|
default: 991,
|
|
21
15
|
max: 1200
|
|
22
|
-
},
|
|
23
|
-
getWidthForSize(size) {
|
|
24
|
-
return this[size].default;
|
|
25
|
-
},
|
|
26
|
-
getSizeForWidth(width) {
|
|
27
|
-
for (const size of sizeNames) {
|
|
28
|
-
const value = this[size];
|
|
29
|
-
if (width <= value.max) {
|
|
30
|
-
return size;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return "large";
|
|
34
16
|
}
|
|
35
17
|
};
|
|
18
|
+
const getMaxWidthQueryForSize = (size) => `@media (max-width: ${SIZES[size].max}px)`;
|
|
36
19
|
export {
|
|
37
|
-
|
|
38
|
-
sizes
|
|
20
|
+
getMaxWidthQueryForSize
|
|
39
21
|
};
|
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const camelCaseToDashCase = (str = "") => str.replace(/[A-Z]/g, (match) => "-" + match.toLowerCase());
|
|
2
|
+
const convertStyleObject = (obj) => {
|
|
3
|
+
if (!obj) {
|
|
4
|
+
return obj;
|
|
5
|
+
}
|
|
6
|
+
const newObj = {};
|
|
7
|
+
for (const key in obj) {
|
|
8
|
+
newObj[camelCaseToDashCase(key)] = obj[key];
|
|
9
|
+
}
|
|
10
|
+
return newObj;
|
|
11
|
+
};
|
|
12
|
+
export {
|
|
13
|
+
convertStyleObject
|
|
14
|
+
};
|
|
@@ -20,7 +20,7 @@ function evaluate({
|
|
|
20
20
|
try {
|
|
21
21
|
return new Function("builder", "Builder", "state", "context", "event", useCode)(builder, builder, state, context, event);
|
|
22
22
|
} catch (e) {
|
|
23
|
-
console.warn("Builder custom code error: ", e);
|
|
23
|
+
console.warn("Builder custom code error: \n While Evaluating: \n ", useCode, "\n", e.message || e);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
export {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const TEXT_STYLE_KEYS = [
|
|
2
|
+
"color",
|
|
3
|
+
"whiteSpace",
|
|
4
|
+
"direction",
|
|
5
|
+
"hyphens",
|
|
6
|
+
"overflowWrap"
|
|
7
|
+
];
|
|
8
|
+
const isTextStyle = (key) => {
|
|
9
|
+
return TEXT_STYLE_KEYS.includes(key) || key.startsWith("font") || key.startsWith("text") || key.startsWith("letter") || key.startsWith("line") || key.startsWith("word") || key.startsWith("writing");
|
|
10
|
+
};
|
|
11
|
+
const extractTextStyles = (styles) => {
|
|
12
|
+
const textStyles = {};
|
|
13
|
+
Object.entries(styles).forEach(([key, value]) => {
|
|
14
|
+
if (isTextStyle(key)) {
|
|
15
|
+
textStyles[key] = value;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return textStyles;
|
|
19
|
+
};
|
|
20
|
+
export {
|
|
21
|
+
extractTextStyles
|
|
22
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { evaluate } from "./evaluate.js";
|
|
2
1
|
import { getEventHandlerName } from "./event-handler-name.js";
|
|
2
|
+
import { crateEventHandler } from "./get-block-actions-handler.js";
|
|
3
3
|
function getBlockActions(options) {
|
|
4
4
|
var _a;
|
|
5
5
|
const obj = {};
|
|
@@ -9,12 +9,7 @@ function getBlockActions(options) {
|
|
|
9
9
|
continue;
|
|
10
10
|
}
|
|
11
11
|
const value = optionActions[key];
|
|
12
|
-
obj[getEventHandlerName(key)] = (
|
|
13
|
-
code: value,
|
|
14
|
-
context: options.context,
|
|
15
|
-
state: options.state,
|
|
16
|
-
event
|
|
17
|
-
});
|
|
12
|
+
obj[getEventHandlerName(key)] = crateEventHandler(value, options);
|
|
18
13
|
}
|
|
19
14
|
return obj;
|
|
20
15
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
2
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
6
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
@@ -14,9 +16,12 @@ var __spreadValues = (a, b) => {
|
|
|
14
16
|
}
|
|
15
17
|
return a;
|
|
16
18
|
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
17
20
|
function getBlockComponentOptions(block) {
|
|
18
21
|
var _a;
|
|
19
|
-
return __spreadValues(__spreadValues({}, (_a = block.component) == null ? void 0 : _a.options), block.options)
|
|
22
|
+
return __spreadProps(__spreadValues(__spreadValues({}, (_a = block.component) == null ? void 0 : _a.options), block.options), {
|
|
23
|
+
builderBlock: block
|
|
24
|
+
});
|
|
20
25
|
}
|
|
21
26
|
export {
|
|
22
27
|
getBlockComponentOptions
|
|
@@ -14,28 +14,36 @@ var __spreadValues = (a, b) => {
|
|
|
14
14
|
}
|
|
15
15
|
return a;
|
|
16
16
|
};
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
import { getMaxWidthQueryForSize } from "../constants/device-sizes.js";
|
|
18
|
+
import { TARGET } from "../constants/target.js";
|
|
19
|
+
import { convertStyleObject } from "./convert-style-object.js";
|
|
20
|
+
import { sanitizeBlockStyles } from "./sanitize-styles.js";
|
|
21
|
+
const getStyleForTarget = ({
|
|
22
|
+
styles,
|
|
23
|
+
context
|
|
24
|
+
}) => {
|
|
25
|
+
switch (TARGET) {
|
|
26
|
+
case "reactNative": {
|
|
27
|
+
return __spreadValues(__spreadValues(__spreadValues(__spreadValues({}, context.inheritedStyles), styles.large ? convertStyleObject(styles.large) : {}), styles.medium ? convertStyleObject(styles.medium) : {}), styles.small ? convertStyleObject(styles.small) : {});
|
|
28
|
+
}
|
|
29
|
+
default:
|
|
30
|
+
return __spreadValues(__spreadValues(__spreadValues({}, styles.large ? convertStyleObject(styles.large) : {}), styles.medium ? {
|
|
31
|
+
[getMaxWidthQueryForSize("medium")]: convertStyleObject(styles.medium)
|
|
32
|
+
} : {}), styles.small ? {
|
|
33
|
+
[getMaxWidthQueryForSize("small")]: convertStyleObject(styles.small)
|
|
34
|
+
} : {});
|
|
26
35
|
}
|
|
27
|
-
return newObj;
|
|
28
36
|
};
|
|
29
|
-
function getBlockStyles(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if ((_d = block.responsiveStyles) == null ? void 0 : _d.small) {
|
|
36
|
-
styles[`@media (max-width: ${sizes.small})`] = convertStyleObject((_e = block.responsiveStyles) == null ? void 0 : _e.small);
|
|
37
|
+
function getBlockStyles({
|
|
38
|
+
block,
|
|
39
|
+
context
|
|
40
|
+
}) {
|
|
41
|
+
if (!block.responsiveStyles) {
|
|
42
|
+
return {};
|
|
37
43
|
}
|
|
38
|
-
|
|
44
|
+
const styles = getStyleForTarget({ styles: block.responsiveStyles, context });
|
|
45
|
+
const newStyles = sanitizeBlockStyles(styles);
|
|
46
|
+
return newStyles;
|
|
39
47
|
}
|
|
40
48
|
export {
|
|
41
49
|
getBlockStyles
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isBrowser } from "../is-browser.js";
|
|
1
2
|
const BUILDER_SEARCHPARAMS_PREFIX = "builder.";
|
|
2
3
|
const convertSearchParamsToQueryObject = (searchParams) => {
|
|
3
4
|
const options = {};
|
|
@@ -6,7 +7,11 @@ const convertSearchParamsToQueryObject = (searchParams) => {
|
|
|
6
7
|
});
|
|
7
8
|
return options;
|
|
8
9
|
};
|
|
9
|
-
const getBuilderSearchParams = (
|
|
10
|
+
const getBuilderSearchParams = (_options) => {
|
|
11
|
+
if (!_options) {
|
|
12
|
+
return {};
|
|
13
|
+
}
|
|
14
|
+
const options = normalizeSearchParams(_options);
|
|
10
15
|
const newOptions = {};
|
|
11
16
|
Object.keys(options).forEach((key) => {
|
|
12
17
|
if (key.startsWith(BUILDER_SEARCHPARAMS_PREFIX)) {
|
|
@@ -16,7 +21,17 @@ const getBuilderSearchParams = (options) => {
|
|
|
16
21
|
});
|
|
17
22
|
return newOptions;
|
|
18
23
|
};
|
|
24
|
+
const getBuilderSearchParamsFromWindow = () => {
|
|
25
|
+
if (!isBrowser()) {
|
|
26
|
+
return {};
|
|
27
|
+
}
|
|
28
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
29
|
+
return getBuilderSearchParams(searchParams);
|
|
30
|
+
};
|
|
31
|
+
const normalizeSearchParams = (searchParams) => searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams;
|
|
19
32
|
export {
|
|
20
33
|
convertSearchParamsToQueryObject,
|
|
21
|
-
getBuilderSearchParams
|
|
34
|
+
getBuilderSearchParams,
|
|
35
|
+
getBuilderSearchParamsFromWindow,
|
|
36
|
+
normalizeSearchParams
|
|
22
37
|
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
import {
|
|
22
|
+
getContentVariationCookie,
|
|
23
|
+
setContentVariationCookie
|
|
24
|
+
} from "../../helpers/ab-tests.js";
|
|
25
|
+
import { checkIsDefined } from "../../helpers/nullable.js";
|
|
26
|
+
const checkIsBuilderContentWithVariations = (item) => checkIsDefined(item.id) && checkIsDefined(item.variations) && Object.keys(item.variations).length > 0;
|
|
27
|
+
const getRandomVariationId = ({
|
|
28
|
+
id,
|
|
29
|
+
variations
|
|
30
|
+
}) => {
|
|
31
|
+
var _a;
|
|
32
|
+
let n = 0;
|
|
33
|
+
const random = Math.random();
|
|
34
|
+
for (const id2 in variations) {
|
|
35
|
+
const testRatio = (_a = variations[id2]) == null ? void 0 : _a.testRatio;
|
|
36
|
+
n += testRatio;
|
|
37
|
+
if (random < n) {
|
|
38
|
+
return id2;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return id;
|
|
42
|
+
};
|
|
43
|
+
const getTestFields = ({
|
|
44
|
+
item,
|
|
45
|
+
testGroupId
|
|
46
|
+
}) => {
|
|
47
|
+
const variationValue = item.variations[testGroupId];
|
|
48
|
+
if (testGroupId === item.id || !variationValue) {
|
|
49
|
+
return {
|
|
50
|
+
testVariationId: item.id,
|
|
51
|
+
testVariationName: "Default"
|
|
52
|
+
};
|
|
53
|
+
} else {
|
|
54
|
+
return {
|
|
55
|
+
data: variationValue.data,
|
|
56
|
+
testVariationId: variationValue.id,
|
|
57
|
+
testVariationName: variationValue.name || (variationValue.id === item.id ? "Default" : "")
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const getContentVariation = (_0) => __async(void 0, [_0], function* ({
|
|
62
|
+
item,
|
|
63
|
+
canTrack
|
|
64
|
+
}) {
|
|
65
|
+
const testGroupId = yield getContentVariationCookie({
|
|
66
|
+
canTrack,
|
|
67
|
+
contentId: item.id
|
|
68
|
+
});
|
|
69
|
+
const testFields = testGroupId ? getTestFields({ item, testGroupId }) : void 0;
|
|
70
|
+
if (testFields) {
|
|
71
|
+
return testFields;
|
|
72
|
+
} else {
|
|
73
|
+
const randomVariationId = getRandomVariationId({
|
|
74
|
+
variations: item.variations,
|
|
75
|
+
id: item.id
|
|
76
|
+
});
|
|
77
|
+
setContentVariationCookie({
|
|
78
|
+
contentId: item.id,
|
|
79
|
+
value: randomVariationId,
|
|
80
|
+
canTrack
|
|
81
|
+
}).catch((err) => {
|
|
82
|
+
console.error("could not store A/B test variation: ", err);
|
|
83
|
+
});
|
|
84
|
+
return getTestFields({ item, testGroupId: randomVariationId });
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
const handleABTesting = (_0) => __async(void 0, [_0], function* ({
|
|
88
|
+
item,
|
|
89
|
+
canTrack
|
|
90
|
+
}) {
|
|
91
|
+
if (!checkIsBuilderContentWithVariations(item)) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const variationValue = yield getContentVariation({ item, canTrack });
|
|
95
|
+
Object.assign(item, variationValue);
|
|
96
|
+
});
|
|
97
|
+
export {
|
|
98
|
+
handleABTesting
|
|
99
|
+
};
|
|
@@ -37,20 +37,13 @@ var __async = (__this, __arguments, generator) => {
|
|
|
37
37
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
38
|
});
|
|
39
39
|
};
|
|
40
|
+
import { flatten } from "../../helpers/flatten.js";
|
|
41
|
+
import {
|
|
42
|
+
getBuilderSearchParamsFromWindow,
|
|
43
|
+
normalizeSearchParams
|
|
44
|
+
} from "../get-builder-search-params/index.js";
|
|
40
45
|
import { getFetch } from "../get-fetch.js";
|
|
41
|
-
|
|
42
|
-
function flatten(object, path = null, separator = ".") {
|
|
43
|
-
return Object.keys(object).reduce((acc, key) => {
|
|
44
|
-
const value = object[key];
|
|
45
|
-
const newPath = [path, key].filter(Boolean).join(separator);
|
|
46
|
-
const isObject = [
|
|
47
|
-
typeof value === "object",
|
|
48
|
-
value !== null,
|
|
49
|
-
!(Array.isArray(value) && value.length === 0)
|
|
50
|
-
].every(Boolean);
|
|
51
|
-
return isObject ? __spreadValues(__spreadValues({}, acc), flatten(value, newPath, separator)) : __spreadProps(__spreadValues({}, acc), { [newPath]: value });
|
|
52
|
-
}, {});
|
|
53
|
-
}
|
|
46
|
+
import { handleABTesting } from "./ab-testing.js";
|
|
54
47
|
function getContent(options) {
|
|
55
48
|
return __async(this, null, function* () {
|
|
56
49
|
return (yield getAllContent(__spreadProps(__spreadValues({}, options), { limit: 1 }))).results[0] || null;
|
|
@@ -58,7 +51,7 @@ function getContent(options) {
|
|
|
58
51
|
}
|
|
59
52
|
const generateContentUrl = (options) => {
|
|
60
53
|
const {
|
|
61
|
-
limit =
|
|
54
|
+
limit = 30,
|
|
62
55
|
userAttributes,
|
|
63
56
|
query,
|
|
64
57
|
noTraverse = false,
|
|
@@ -66,67 +59,32 @@ const generateContentUrl = (options) => {
|
|
|
66
59
|
apiKey
|
|
67
60
|
} = options;
|
|
68
61
|
const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}`);
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
62
|
+
const queryOptions = __spreadValues(__spreadValues({}, getBuilderSearchParamsFromWindow()), normalizeSearchParams(options.options || {}));
|
|
63
|
+
const flattened = flatten(queryOptions);
|
|
64
|
+
for (const key in flattened) {
|
|
65
|
+
url.searchParams.set(key, String(flattened[key]));
|
|
74
66
|
}
|
|
75
67
|
if (userAttributes) {
|
|
76
68
|
url.searchParams.set("userAttributes", JSON.stringify(userAttributes));
|
|
77
69
|
}
|
|
78
70
|
if (query) {
|
|
79
|
-
const
|
|
80
|
-
for (const key in
|
|
81
|
-
url.searchParams.set(key, JSON.stringify(
|
|
71
|
+
const flattened2 = flatten({ query });
|
|
72
|
+
for (const key in flattened2) {
|
|
73
|
+
url.searchParams.set(key, JSON.stringify(flattened2[key]));
|
|
82
74
|
}
|
|
83
75
|
}
|
|
84
76
|
return url;
|
|
85
77
|
};
|
|
86
|
-
const handleABTesting = (content, testGroups) => {
|
|
87
|
-
for (const item of content.results) {
|
|
88
|
-
if (item.variations && Object.keys(item.variations).length) {
|
|
89
|
-
const testGroup = testGroups[item.id];
|
|
90
|
-
const variationValue = item.variations[testGroup];
|
|
91
|
-
if (testGroup && variationValue) {
|
|
92
|
-
item.data = variationValue.data;
|
|
93
|
-
item.testVariationId = variationValue.id;
|
|
94
|
-
item.testVariationName = variationValue.name;
|
|
95
|
-
} else {
|
|
96
|
-
let n = 0;
|
|
97
|
-
const random = Math.random();
|
|
98
|
-
let set = false;
|
|
99
|
-
for (const id in item.variations) {
|
|
100
|
-
const variation = item.variations[id];
|
|
101
|
-
const testRatio = variation.testRatio;
|
|
102
|
-
n += testRatio;
|
|
103
|
-
if (random < n) {
|
|
104
|
-
const variationName = variation.name || (variation.id === item.id ? "Default variation" : "");
|
|
105
|
-
set = true;
|
|
106
|
-
Object.assign(item, {
|
|
107
|
-
data: variation.data,
|
|
108
|
-
testVariationId: variation.id,
|
|
109
|
-
testVariationName: variationName
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
if (!set) {
|
|
114
|
-
Object.assign(item, {
|
|
115
|
-
testVariationId: item.id,
|
|
116
|
-
testVariationName: "Default"
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
78
|
function getAllContent(options) {
|
|
124
79
|
return __async(this, null, function* () {
|
|
125
80
|
const url = generateContentUrl(options);
|
|
126
|
-
const fetch = yield
|
|
81
|
+
const fetch = yield getFetch();
|
|
127
82
|
const content = yield fetch(url.href).then((res) => res.json());
|
|
128
|
-
|
|
129
|
-
|
|
83
|
+
const canTrack = options.canTrack !== false;
|
|
84
|
+
if (canTrack) {
|
|
85
|
+
for (const item of content.results) {
|
|
86
|
+
yield handleABTesting({ item, canTrack });
|
|
87
|
+
}
|
|
130
88
|
}
|
|
131
89
|
return content;
|
|
132
90
|
});
|
|
File without changes
|
|
@@ -24,9 +24,9 @@ function getFetch() {
|
|
|
24
24
|
const globalFetch = getGlobalThis().fetch;
|
|
25
25
|
if (typeof globalFetch === "undefined" && typeof global !== "undefined") {
|
|
26
26
|
const nodeFetch = import("node-fetch").then((d) => d.default);
|
|
27
|
-
return nodeFetch;
|
|
27
|
+
return nodeFetch.default || nodeFetch;
|
|
28
28
|
}
|
|
29
|
-
return globalFetch;
|
|
29
|
+
return globalFetch.default || globalFetch;
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
export {
|
|
@@ -18,28 +18,41 @@ var __spreadValues = (a, b) => {
|
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
20
|
import { evaluate } from "./evaluate.js";
|
|
21
|
+
import { fastClone } from "./fast-clone.js";
|
|
21
22
|
import { set } from "./set.js";
|
|
22
23
|
import { transformBlock } from "./transform-block.js";
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
const evaluateBindings = ({
|
|
25
|
+
block,
|
|
26
|
+
context,
|
|
27
|
+
state
|
|
28
|
+
}) => {
|
|
26
29
|
if (!block.bindings) {
|
|
27
30
|
return block;
|
|
28
31
|
}
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
const copy = fastClone(block);
|
|
33
|
+
const copied = __spreadProps(__spreadValues({}, copy), {
|
|
34
|
+
properties: __spreadValues({}, copy.properties),
|
|
35
|
+
actions: __spreadValues({}, copy.actions)
|
|
32
36
|
});
|
|
33
37
|
for (const binding in block.bindings) {
|
|
34
38
|
const expression = block.bindings[binding];
|
|
35
|
-
const value = evaluate({
|
|
36
|
-
code: expression,
|
|
37
|
-
state,
|
|
38
|
-
context
|
|
39
|
-
});
|
|
39
|
+
const value = evaluate({ code: expression, state, context });
|
|
40
40
|
set(copied, binding, value);
|
|
41
41
|
}
|
|
42
42
|
return copied;
|
|
43
|
+
};
|
|
44
|
+
function getProcessedBlock({
|
|
45
|
+
block,
|
|
46
|
+
context,
|
|
47
|
+
shouldEvaluateBindings,
|
|
48
|
+
state
|
|
49
|
+
}) {
|
|
50
|
+
const transformedBlock = transformBlock(block);
|
|
51
|
+
if (shouldEvaluateBindings) {
|
|
52
|
+
return evaluateBindings({ block: transformedBlock, state, context });
|
|
53
|
+
} else {
|
|
54
|
+
return transformedBlock;
|
|
55
|
+
}
|
|
43
56
|
}
|
|
44
57
|
export {
|
|
45
58
|
getProcessedBlock
|
|
@@ -20,7 +20,8 @@ test("Can process bindings", () => {
|
|
|
20
20
|
const processed = getProcessedBlock({
|
|
21
21
|
block,
|
|
22
22
|
context: {},
|
|
23
|
-
state: { test: "hello" }
|
|
23
|
+
state: { test: "hello" },
|
|
24
|
+
shouldEvaluateBindings: true
|
|
24
25
|
});
|
|
25
26
|
expect(processed).not.toEqual(block);
|
|
26
27
|
expect((_a = processed.properties) == null ? void 0 : _a.foo).toEqual("baz");
|