@builder.io/sdk-react-native 0.0.1-5 → 0.0.1-52
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/CHANGELOG.md +28 -0
- package/README.md +15 -0
- package/package.json +6 -4
- package/src/blocks/button/button.js +31 -0
- package/src/blocks/{button.lite.tsx → button/button.lite.tsx} +7 -11
- package/src/blocks/button/component-info.js +42 -0
- package/src/blocks/columns/columns.js +59 -0
- package/src/blocks/columns/columns.lite.tsx +70 -0
- package/src/blocks/columns/component-info.js +218 -0
- package/src/blocks/custom-code/component-info.js +32 -0
- package/src/blocks/custom-code/custom-code.js +50 -0
- package/src/blocks/{custom-code.lite.tsx → custom-code/custom-code.lite.tsx} +2 -10
- package/src/blocks/embed/component-info.js +25 -0
- package/src/blocks/embed/embed.js +50 -0
- package/src/blocks/{embed.lite.tsx → embed/embed.lite.tsx} +2 -6
- package/src/blocks/form/component-info.js +263 -0
- package/src/blocks/form/form.js +221 -0
- package/src/blocks/{form.lite.tsx → form/form.lite.tsx} +24 -27
- package/src/blocks/fragment/component-info.js +12 -0
- package/src/blocks/fragment/fragment.js +8 -0
- package/src/blocks/fragment/fragment.lite.tsx +10 -0
- package/src/blocks/{image.js → image/component-info.js} +5 -23
- package/src/blocks/image/image.js +41 -0
- package/src/blocks/image/image.lite.tsx +67 -0
- package/src/blocks/img/component-info.js +21 -0
- package/src/blocks/img/img.js +36 -0
- package/src/blocks/{img.lite.tsx → img/img.lite.tsx} +2 -3
- package/src/blocks/input/component-info.js +75 -0
- package/src/blocks/input/input.js +36 -0
- package/src/blocks/{input.lite.tsx → input/input.lite.tsx} +2 -5
- package/src/blocks/raw-text/component-info.js +17 -0
- package/src/blocks/raw-text/raw-text.js +10 -0
- package/src/blocks/raw-text/raw-text.lite.tsx +6 -0
- package/src/blocks/section/component-info.js +50 -0
- package/src/blocks/section/section.js +31 -0
- package/src/blocks/{section.lite.tsx → section/section.lite.tsx} +1 -2
- package/src/blocks/select/component-info.js +60 -0
- package/src/blocks/select/select.js +36 -0
- package/src/blocks/{select.lite.tsx → select/select.lite.tsx} +6 -7
- package/src/blocks/submit-button/component-info.js +29 -0
- package/src/blocks/submit-button/submit-button.js +29 -0
- package/src/blocks/{submit-button.lite.tsx → submit-button/submit-button.lite.tsx} +1 -2
- package/src/blocks/symbol/component-info.js +43 -0
- package/src/blocks/symbol/symbol.js +68 -0
- package/src/blocks/symbol/symbol.lite.tsx +60 -0
- package/src/blocks/{text.js → text/component-info.js} +4 -10
- package/src/blocks/text/text.js +65 -0
- package/src/blocks/text/text.lite.tsx +6 -0
- package/src/blocks/textarea/component-info.js +48 -0
- package/src/blocks/textarea/textarea.js +32 -0
- package/src/blocks/{textarea.lite.tsx → textarea/textarea.lite.tsx} +0 -1
- package/src/blocks/video/component-info.js +107 -0
- package/src/blocks/video/video.js +33 -0
- package/src/blocks/{video.lite.tsx → video/video.lite.tsx} +0 -1
- package/src/components/error-boundary.js +25 -0
- package/src/components/error-boundary.lite.tsx +6 -0
- package/src/components/render-block/block-styles.js +29 -0
- package/src/components/render-block/block-styles.lite.tsx +35 -0
- package/src/components/render-block/render-block.helpers.js +24 -0
- package/src/components/render-block/render-block.js +116 -0
- package/src/components/render-block/render-block.lite.tsx +139 -0
- package/src/components/render-blocks.js +14 -7
- package/src/components/render-blocks.lite.tsx +18 -9
- package/src/components/render-content/components/render-styles.js +58 -0
- package/src/components/render-content/components/render-styles.lite.tsx +70 -0
- package/src/components/render-content/index.js +5 -0
- package/src/components/render-content/render-content.js +254 -0
- package/src/components/render-content/render-content.lite.tsx +283 -0
- package/src/components/render-inlined-styles.js +18 -0
- package/src/components/render-inlined-styles.lite.tsx +31 -0
- package/src/constants/builder-registered-components.js +27 -0
- package/src/constants/target.js +5 -0
- package/src/context/builder.context.js +7 -1
- package/src/functions/evaluate.js +17 -8
- package/src/functions/event-handler-name.js +8 -0
- package/src/functions/fast-clone.js +5 -0
- package/src/functions/get-block-actions.js +14 -13
- package/src/functions/get-block-component-options.js +17 -1
- package/src/functions/get-block-properties.js +7 -4
- package/src/functions/get-block-styles.js +31 -1
- package/src/functions/get-builder-search-params/fn.test.js +14 -0
- package/src/functions/get-builder-search-params/index.js +23 -0
- package/src/functions/get-content/fn.test.js +32 -0
- package/src/functions/get-content/index.js +139 -0
- package/src/functions/get-fetch.js +35 -0
- package/src/functions/get-global-this.js +19 -0
- package/src/functions/get-processed-block.js +5 -3
- package/src/functions/get-processed-block.test.js +13 -8
- package/src/functions/if-target.js +11 -2
- package/src/functions/is-browser.js +1 -2
- package/src/functions/is-editing.js +1 -1
- package/src/functions/is-iframe.js +1 -1
- package/src/functions/is-previewing.js +15 -0
- package/src/functions/is-react-native.js +1 -1
- package/src/functions/on-change.test.js +1 -2
- package/src/functions/previewing-model-name.js +12 -0
- package/src/functions/register-component.js +31 -13
- package/src/functions/register.js +30 -0
- package/src/functions/set-editor-settings.js +16 -0
- package/src/functions/set.test.js +1 -2
- package/src/functions/track.js +7 -3
- package/src/functions/transform-block.js +38 -0
- package/src/index-helpers/blocks-exports.js +19 -0
- package/src/index-helpers/top-of-file.js +2 -0
- package/src/index.js +10 -23
- package/src/scripts/init-editing.js +73 -47
- package/src/types/components.js +1 -0
- package/src/types/deep-partial.js +1 -0
- package/src/types/element.js +1 -0
- package/src/types/targets.js +1 -0
- package/src/types/typescript.js +1 -0
- package/index.js +0 -11
- package/src/blocks/button.js +0 -37
- package/src/blocks/columns.js +0 -47
- package/src/blocks/columns.lite.tsx +0 -46
- package/src/blocks/custom-code.js +0 -56
- package/src/blocks/embed.js +0 -56
- package/src/blocks/form.js +0 -229
- package/src/blocks/image.lite.tsx +0 -35
- package/src/blocks/img.js +0 -41
- package/src/blocks/input.js +0 -41
- package/src/blocks/raw-text.js +0 -17
- package/src/blocks/raw-text.lite.tsx +0 -12
- package/src/blocks/section.js +0 -36
- package/src/blocks/select.js +0 -40
- package/src/blocks/submit-button.js +0 -34
- package/src/blocks/symbol.js +0 -20
- package/src/blocks/symbol.lite.tsx +0 -20
- package/src/blocks/text.lite.tsx +0 -12
- package/src/blocks/textarea.js +0 -37
- package/src/blocks/video.js +0 -49
- package/src/components/render-block.js +0 -84
- package/src/components/render-block.lite.tsx +0 -92
- package/src/components/render-content.js +0 -66
- package/src/components/render-content.lite.tsx +0 -95
- package/src/functions/get-content.js +0 -103
- package/src/functions/get-target.js +0 -7
- package/src/package.json +0 -18
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { evaluate } from "./evaluate";
|
|
3
|
-
|
|
4
|
-
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
5
|
-
}
|
|
2
|
+
import { evaluate } from "./evaluate.js";
|
|
3
|
+
import { getEventHandlerName } from "./event-handler-name.js";
|
|
6
4
|
function getBlockActions(options) {
|
|
5
|
+
var _a;
|
|
7
6
|
const obj = {};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
code: value,
|
|
13
|
-
context: options.context,
|
|
14
|
-
state: options.state,
|
|
15
|
-
event
|
|
16
|
-
});
|
|
7
|
+
const optionActions = (_a = options.block.actions) != null ? _a : {};
|
|
8
|
+
for (const key in optionActions) {
|
|
9
|
+
if (!optionActions.hasOwnProperty(key)) {
|
|
10
|
+
continue;
|
|
17
11
|
}
|
|
12
|
+
const value = optionActions[key];
|
|
13
|
+
obj[getEventHandlerName(key)] = (event) => evaluate({
|
|
14
|
+
code: value,
|
|
15
|
+
context: options.context,
|
|
16
|
+
state: options.state,
|
|
17
|
+
event
|
|
18
|
+
});
|
|
18
19
|
}
|
|
19
20
|
return obj;
|
|
20
21
|
}
|
|
@@ -1,7 +1,23 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __spreadValues = (a, b) => {
|
|
8
|
+
for (var prop in b || (b = {}))
|
|
9
|
+
if (__hasOwnProp.call(b, prop))
|
|
10
|
+
__defNormalProp(a, prop, b[prop]);
|
|
11
|
+
if (__getOwnPropSymbols)
|
|
12
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
13
|
+
if (__propIsEnum.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
15
|
+
}
|
|
16
|
+
return a;
|
|
17
|
+
};
|
|
2
18
|
function getBlockComponentOptions(block) {
|
|
3
19
|
var _a;
|
|
4
|
-
return (_a = block.component) == null ? void 0 : _a.options;
|
|
20
|
+
return __spreadValues(__spreadValues({}, (_a = block.component) == null ? void 0 : _a.options), block.options);
|
|
5
21
|
}
|
|
6
22
|
export {
|
|
7
23
|
getBlockComponentOptions
|
|
@@ -18,14 +18,17 @@ var __spreadValues = (a, b) => {
|
|
|
18
18
|
return a;
|
|
19
19
|
};
|
|
20
20
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
|
+
import { isEditing } from "./is-editing";
|
|
21
22
|
import { findDOMNode } from "react-dom";
|
|
22
23
|
function getBlockProperties(block) {
|
|
23
24
|
return __spreadProps(__spreadValues({}, block.properties), {
|
|
24
25
|
ref: (ref) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
el
|
|
28
|
-
|
|
26
|
+
if (isEditing()) {
|
|
27
|
+
const el = findDOMNode(ref);
|
|
28
|
+
if (el) {
|
|
29
|
+
el.setAttribute("builder-id", block.id);
|
|
30
|
+
el.classList.add(block.id);
|
|
31
|
+
}
|
|
29
32
|
}
|
|
30
33
|
},
|
|
31
34
|
dataSet: {
|
|
@@ -15,15 +15,45 @@ var __spreadValues = (a, b) => {
|
|
|
15
15
|
}
|
|
16
16
|
return a;
|
|
17
17
|
};
|
|
18
|
+
const propertiesThatMustBeNumber = new Set(["lineHeight"]);
|
|
19
|
+
const displayValues = new Set(["flex", "none"]);
|
|
20
|
+
const SHOW_WARNINGS = false;
|
|
21
|
+
function validateReactNativeStyles(styles) {
|
|
22
|
+
for (const key in styles) {
|
|
23
|
+
const propertyValue = styles[key];
|
|
24
|
+
if (key === "display" && !displayValues.has(propertyValue)) {
|
|
25
|
+
if (SHOW_WARNINGS) {
|
|
26
|
+
console.warn(`Style value for key "display" must be "flex" or "none" but had ${propertyValue}`);
|
|
27
|
+
}
|
|
28
|
+
delete styles[key];
|
|
29
|
+
}
|
|
30
|
+
if (typeof propertyValue === "string" && propertyValue.match(/^\-?\d/)) {
|
|
31
|
+
const newValue = parseFloat(propertyValue);
|
|
32
|
+
if (!isNaN(newValue)) {
|
|
33
|
+
styles[key] = newValue;
|
|
34
|
+
}
|
|
35
|
+
if (typeof newValue === "number" && newValue < 0) {
|
|
36
|
+
styles[key] = 0;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (propertiesThatMustBeNumber.has(key) && typeof styles[key] !== "number") {
|
|
40
|
+
if (SHOW_WARNINGS) {
|
|
41
|
+
console.warn(`Style key ${key} must be a number, but had value \`${styles[key]}\``);
|
|
42
|
+
}
|
|
43
|
+
delete styles[key];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
18
47
|
function getBlockStyles(block) {
|
|
19
48
|
var _a, _b, _c;
|
|
20
|
-
const styles = __spreadValues({}, (_a = block.responsiveStyles) == null ? void 0 : _a.large);
|
|
49
|
+
const styles = __spreadValues(__spreadValues({}, (_a = block.responsiveStyles) == null ? void 0 : _a.large), block.styles);
|
|
21
50
|
if ((_b = block.responsiveStyles) == null ? void 0 : _b.medium) {
|
|
22
51
|
Object.assign(styles, block.responsiveStyles.medium);
|
|
23
52
|
}
|
|
24
53
|
if ((_c = block.responsiveStyles) == null ? void 0 : _c.small) {
|
|
25
54
|
Object.assign(styles, block.responsiveStyles.small);
|
|
26
55
|
}
|
|
56
|
+
validateReactNativeStyles(styles);
|
|
27
57
|
return styles;
|
|
28
58
|
}
|
|
29
59
|
export {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { convertSearchParamsToQueryObject, getBuilderSearchParams } from ".";
|
|
3
|
+
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";
|
|
4
|
+
const url = new URL(`localhost:3000/about-us?${querystring}`);
|
|
5
|
+
describe("Get Builder SearchParams", () => {
|
|
6
|
+
test("correctly converts URLSearchParams to object", () => {
|
|
7
|
+
const output = convertSearchParamsToQueryObject(url.searchParams);
|
|
8
|
+
expect(output).toMatchSnapshot();
|
|
9
|
+
});
|
|
10
|
+
test("correctly extracts all builder params from a query object", () => {
|
|
11
|
+
const output = getBuilderSearchParams(convertSearchParamsToQueryObject(url.searchParams));
|
|
12
|
+
expect(output).toMatchSnapshot();
|
|
13
|
+
});
|
|
14
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
const BUILDER_SEARCHPARAMS_PREFIX = "builder.";
|
|
3
|
+
const convertSearchParamsToQueryObject = (searchParams) => {
|
|
4
|
+
const options = {};
|
|
5
|
+
searchParams.forEach((value, key) => {
|
|
6
|
+
options[key] = value;
|
|
7
|
+
});
|
|
8
|
+
return options;
|
|
9
|
+
};
|
|
10
|
+
const getBuilderSearchParams = (options) => {
|
|
11
|
+
const newOptions = {};
|
|
12
|
+
Object.keys(options).forEach((key) => {
|
|
13
|
+
if (key.startsWith(BUILDER_SEARCHPARAMS_PREFIX)) {
|
|
14
|
+
const trimmedKey = key.replace(BUILDER_SEARCHPARAMS_PREFIX, "");
|
|
15
|
+
newOptions[trimmedKey] = options[key];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return newOptions;
|
|
19
|
+
};
|
|
20
|
+
export {
|
|
21
|
+
convertSearchParamsToQueryObject,
|
|
22
|
+
getBuilderSearchParams
|
|
23
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { generateContentUrl } from ".";
|
|
3
|
+
const testKey = "YJIGb4i01jvw0SRdL5Bt";
|
|
4
|
+
const testModel = "page";
|
|
5
|
+
const testId = "c1b81bab59704599b997574eb0736def";
|
|
6
|
+
const options = {
|
|
7
|
+
cachebust: "true",
|
|
8
|
+
noCache: "true",
|
|
9
|
+
"overrides.037948e52eaf4743afed464f02c70da4": "037948e52eaf4743afed464f02c70da4",
|
|
10
|
+
"overrides.page": "037948e52eaf4743afed464f02c70da4",
|
|
11
|
+
"overrides.page:/": "037948e52eaf4743afed464f02c70da4",
|
|
12
|
+
preview: "page"
|
|
13
|
+
};
|
|
14
|
+
describe("Generate Content URL", () => {
|
|
15
|
+
test("generates the proper value for a simple query", () => {
|
|
16
|
+
const output = generateContentUrl({
|
|
17
|
+
apiKey: testKey,
|
|
18
|
+
model: testModel,
|
|
19
|
+
query: { id: testId }
|
|
20
|
+
});
|
|
21
|
+
expect(output).toMatchSnapshot();
|
|
22
|
+
});
|
|
23
|
+
test("Handles overrides correctly", () => {
|
|
24
|
+
const output = generateContentUrl({
|
|
25
|
+
apiKey: testKey,
|
|
26
|
+
model: testModel,
|
|
27
|
+
query: { id: testId },
|
|
28
|
+
options
|
|
29
|
+
});
|
|
30
|
+
expect(output).toMatchSnapshot();
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
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 __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
|
+
var __async = (__this, __arguments, generator) => {
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
var fulfilled = (value) => {
|
|
24
|
+
try {
|
|
25
|
+
step(generator.next(value));
|
|
26
|
+
} catch (e) {
|
|
27
|
+
reject(e);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var rejected = (value) => {
|
|
31
|
+
try {
|
|
32
|
+
step(generator.throw(value));
|
|
33
|
+
} catch (e) {
|
|
34
|
+
reject(e);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
38
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
import { getFetch } from "../get-fetch.js";
|
|
42
|
+
const fetch$ = getFetch();
|
|
43
|
+
function flatten(object, path = null, separator = ".") {
|
|
44
|
+
return Object.keys(object).reduce((acc, key) => {
|
|
45
|
+
const value = object[key];
|
|
46
|
+
const newPath = [path, key].filter(Boolean).join(separator);
|
|
47
|
+
const isObject = [
|
|
48
|
+
typeof value === "object",
|
|
49
|
+
value !== null,
|
|
50
|
+
!(Array.isArray(value) && value.length === 0)
|
|
51
|
+
].every(Boolean);
|
|
52
|
+
return isObject ? __spreadValues(__spreadValues({}, acc), flatten(value, newPath, separator)) : __spreadProps(__spreadValues({}, acc), { [newPath]: value });
|
|
53
|
+
}, {});
|
|
54
|
+
}
|
|
55
|
+
function getContent(options) {
|
|
56
|
+
return __async(this, null, function* () {
|
|
57
|
+
return (yield getAllContent(__spreadProps(__spreadValues({}, options), { limit: 1 }))).results[0] || null;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
const generateContentUrl = (options) => {
|
|
61
|
+
const {
|
|
62
|
+
limit = 1,
|
|
63
|
+
userAttributes,
|
|
64
|
+
query,
|
|
65
|
+
noTraverse = false,
|
|
66
|
+
model,
|
|
67
|
+
apiKey
|
|
68
|
+
} = options;
|
|
69
|
+
const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}`);
|
|
70
|
+
if (options.options) {
|
|
71
|
+
const flattened = flatten(options.options);
|
|
72
|
+
for (const key in flattened) {
|
|
73
|
+
url.searchParams.set(key, String(flattened[key]));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (userAttributes) {
|
|
77
|
+
url.searchParams.set("userAttributes", JSON.stringify(userAttributes));
|
|
78
|
+
}
|
|
79
|
+
if (query) {
|
|
80
|
+
const flattened = flatten({ query });
|
|
81
|
+
for (const key in flattened) {
|
|
82
|
+
url.searchParams.set(key, JSON.stringify(flattened[key]));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return url;
|
|
86
|
+
};
|
|
87
|
+
const handleABTesting = (content, testGroups) => {
|
|
88
|
+
for (const item of content.results) {
|
|
89
|
+
if (item.variations && Object.keys(item.variations).length) {
|
|
90
|
+
const testGroup = testGroups[item.id];
|
|
91
|
+
const variationValue = item.variations[testGroup];
|
|
92
|
+
if (testGroup && variationValue) {
|
|
93
|
+
item.data = variationValue.data;
|
|
94
|
+
item.testVariationId = variationValue.id;
|
|
95
|
+
item.testVariationName = variationValue.name;
|
|
96
|
+
} else {
|
|
97
|
+
let n = 0;
|
|
98
|
+
const random = Math.random();
|
|
99
|
+
let set = false;
|
|
100
|
+
for (const id in item.variations) {
|
|
101
|
+
const variation = item.variations[id];
|
|
102
|
+
const testRatio = variation.testRatio;
|
|
103
|
+
n += testRatio;
|
|
104
|
+
if (random < n) {
|
|
105
|
+
const variationName = variation.name || (variation.id === item.id ? "Default variation" : "");
|
|
106
|
+
set = true;
|
|
107
|
+
Object.assign(item, {
|
|
108
|
+
data: variation.data,
|
|
109
|
+
testVariationId: variation.id,
|
|
110
|
+
testVariationName: variationName
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (!set) {
|
|
115
|
+
Object.assign(item, {
|
|
116
|
+
testVariationId: item.id,
|
|
117
|
+
testVariationName: "Default"
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
function getAllContent(options) {
|
|
125
|
+
return __async(this, null, function* () {
|
|
126
|
+
const url = generateContentUrl(options);
|
|
127
|
+
const fetch = yield fetch$;
|
|
128
|
+
const content = yield fetch(url.href).then((res) => res.json());
|
|
129
|
+
if (options.testGroups) {
|
|
130
|
+
handleABTesting(content, options.testGroups);
|
|
131
|
+
}
|
|
132
|
+
return content;
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
export {
|
|
136
|
+
generateContentUrl,
|
|
137
|
+
getAllContent,
|
|
138
|
+
getContent
|
|
139
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
var __async = (__this, __arguments, generator) => {
|
|
3
|
+
return new Promise((resolve, reject) => {
|
|
4
|
+
var fulfilled = (value) => {
|
|
5
|
+
try {
|
|
6
|
+
step(generator.next(value));
|
|
7
|
+
} catch (e) {
|
|
8
|
+
reject(e);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
var rejected = (value) => {
|
|
12
|
+
try {
|
|
13
|
+
step(generator.throw(value));
|
|
14
|
+
} catch (e) {
|
|
15
|
+
reject(e);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
19
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
import { getGlobalThis } from "./get-global-this.js";
|
|
23
|
+
function getFetch() {
|
|
24
|
+
return __async(this, null, function* () {
|
|
25
|
+
const globalFetch = getGlobalThis().fetch;
|
|
26
|
+
if (typeof globalFetch === "undefined" && typeof global !== "undefined") {
|
|
27
|
+
const nodeFetch = import("node-fetch").then((d) => d.default);
|
|
28
|
+
return nodeFetch;
|
|
29
|
+
}
|
|
30
|
+
return globalFetch;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
getFetch
|
|
35
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
function getGlobalThis() {
|
|
3
|
+
if (typeof globalThis !== "undefined") {
|
|
4
|
+
return globalThis;
|
|
5
|
+
}
|
|
6
|
+
if (typeof window !== "undefined") {
|
|
7
|
+
return window;
|
|
8
|
+
}
|
|
9
|
+
if (typeof global !== "undefined") {
|
|
10
|
+
return global;
|
|
11
|
+
}
|
|
12
|
+
if (typeof self !== "undefined") {
|
|
13
|
+
return self;
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
getGlobalThis
|
|
19
|
+
};
|
|
@@ -18,10 +18,12 @@ var __spreadValues = (a, b) => {
|
|
|
18
18
|
return a;
|
|
19
19
|
};
|
|
20
20
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
|
-
import { evaluate } from "./evaluate";
|
|
22
|
-
import { set } from "./set";
|
|
21
|
+
import { evaluate } from "./evaluate.js";
|
|
22
|
+
import { set } from "./set.js";
|
|
23
|
+
import { transformBlock } from "./transform-block.js";
|
|
23
24
|
function getProcessedBlock(options) {
|
|
24
|
-
const {
|
|
25
|
+
const { state, context } = options;
|
|
26
|
+
const block = transformBlock(options.block);
|
|
25
27
|
if (!block.bindings) {
|
|
26
28
|
return block;
|
|
27
29
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import { getProcessedBlock } from "./get-processed-block";
|
|
2
|
+
import { getProcessedBlock } from "./get-processed-block.js";
|
|
4
3
|
test("Can process bindings", () => {
|
|
4
|
+
var _a, _b, _c, _d, _e, _f;
|
|
5
5
|
const block = {
|
|
6
|
+
"@type": "@builder.io/sdk:Element",
|
|
6
7
|
properties: {
|
|
7
8
|
foo: "bar"
|
|
8
9
|
},
|
|
@@ -17,11 +18,15 @@ test("Can process bindings", () => {
|
|
|
17
18
|
"properties.isEditing": "builder.isEditing"
|
|
18
19
|
}
|
|
19
20
|
};
|
|
20
|
-
const processed = getProcessedBlock({
|
|
21
|
+
const processed = getProcessedBlock({
|
|
22
|
+
block,
|
|
23
|
+
context: {},
|
|
24
|
+
state: { test: "hello" }
|
|
25
|
+
});
|
|
21
26
|
expect(processed).not.toEqual(block);
|
|
22
|
-
expect(processed.properties.foo).toEqual("baz");
|
|
23
|
-
expect(processed.properties.test).toEqual("hello");
|
|
24
|
-
expect(processed.properties.block).toEqual("bar");
|
|
25
|
-
expect(processed.properties.isEditing).toEqual(false);
|
|
26
|
-
expect(processed.responsiveStyles.large.zIndex).toEqual(2);
|
|
27
|
+
expect((_a = processed.properties) == null ? void 0 : _a.foo).toEqual("baz");
|
|
28
|
+
expect((_b = processed.properties) == null ? void 0 : _b.test).toEqual("hello");
|
|
29
|
+
expect((_c = processed.properties) == null ? void 0 : _c.block).toEqual("bar");
|
|
30
|
+
expect((_d = processed.properties) == null ? void 0 : _d.isEditing).toEqual(false);
|
|
31
|
+
expect((_f = (_e = processed.responsiveStyles) == null ? void 0 : _e.large) == null ? void 0 : _f.zIndex).toEqual(2);
|
|
27
32
|
});
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { TARGET } from "../constants/target.js";
|
|
3
|
+
function ifTarget({
|
|
4
|
+
targets,
|
|
5
|
+
doThing,
|
|
6
|
+
elseThing
|
|
7
|
+
}) {
|
|
8
|
+
if (TARGET && targets.includes(TARGET)) {
|
|
9
|
+
return doThing();
|
|
10
|
+
} else {
|
|
11
|
+
return elseThing == null ? void 0 : elseThing();
|
|
12
|
+
}
|
|
4
13
|
}
|
|
5
14
|
export {
|
|
6
15
|
ifTarget
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { isReactNative } from "./is-react-native";
|
|
3
2
|
function isBrowser() {
|
|
4
|
-
return typeof window !== "undefined" && typeof document !== "undefined"
|
|
3
|
+
return typeof window !== "undefined" && typeof document !== "undefined";
|
|
5
4
|
}
|
|
6
5
|
export {
|
|
7
6
|
isBrowser
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { isBrowser } from "./is-browser.js";
|
|
3
|
+
import { isEditing } from "./is-editing.js";
|
|
4
|
+
function isPreviewing() {
|
|
5
|
+
if (!isBrowser()) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
if (isEditing()) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
return Boolean(location.search.indexOf("builder.preview=") !== -1);
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
isPreviewing
|
|
15
|
+
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import { onChange } from "./on-change";
|
|
2
|
+
import { onChange } from "./on-change.js";
|
|
4
3
|
test("onChange can observe a shallow change", () => {
|
|
5
4
|
let changeHappend = false;
|
|
6
5
|
const obj = onChange({ foo: "hi" }, () => changeHappend = true);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { isPreviewing } from "./is-previewing.js";
|
|
3
|
+
function previewingModelName() {
|
|
4
|
+
if (!isPreviewing()) {
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
7
|
+
const url = new URL(location.href);
|
|
8
|
+
return url.searchParams.get("builder.preview");
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
previewingModelName
|
|
12
|
+
};
|
|
@@ -18,26 +18,43 @@ var __spreadValues = (a, b) => {
|
|
|
18
18
|
return a;
|
|
19
19
|
};
|
|
20
20
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
var __objRest = (source, exclude) => {
|
|
22
|
+
var target = {};
|
|
23
|
+
for (var prop in source)
|
|
24
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
25
|
+
target[prop] = source[prop];
|
|
26
|
+
if (source != null && __getOwnPropSymbols)
|
|
27
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
28
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
}
|
|
31
|
+
return target;
|
|
32
|
+
};
|
|
33
|
+
import { fastClone } from "./fast-clone.js";
|
|
34
|
+
const components = [];
|
|
23
35
|
function registerComponent(component, info) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const sendInfo = prepareComponentInfoToSend(info);
|
|
28
|
-
(_a = window.parent) == null ? void 0 : _a.postMessage({
|
|
29
|
-
type: "builder.registerComponent",
|
|
30
|
-
data: sendInfo
|
|
31
|
-
}, "*");
|
|
32
|
-
}
|
|
36
|
+
components.push(__spreadValues({ component }, info));
|
|
37
|
+
console.warn("registerComponent is deprecated. Use the `customComponents` prop in RenderContent instead to provide your custom components to the builder SDK.");
|
|
38
|
+
return component;
|
|
33
39
|
}
|
|
40
|
+
const createRegisterComponentMessage = (_a) => {
|
|
41
|
+
var _b = _a, {
|
|
42
|
+
component
|
|
43
|
+
} = _b, info = __objRest(_b, [
|
|
44
|
+
"component"
|
|
45
|
+
]);
|
|
46
|
+
return {
|
|
47
|
+
type: "builder.registerComponent",
|
|
48
|
+
data: prepareComponentInfoToSend(fastClone(info))
|
|
49
|
+
};
|
|
50
|
+
};
|
|
34
51
|
function prepareComponentInfoToSend(info) {
|
|
35
52
|
return __spreadValues(__spreadValues({}, info), info.inputs && {
|
|
36
53
|
inputs: info.inputs.map((input) => {
|
|
37
54
|
const keysToConvertFnToString = ["onChange", "showIf"];
|
|
38
55
|
for (const key of keysToConvertFnToString) {
|
|
39
|
-
|
|
40
|
-
|
|
56
|
+
const fn = input[key];
|
|
57
|
+
if (fn && typeof fn === "function") {
|
|
41
58
|
input = __spreadProps(__spreadValues({}, input), {
|
|
42
59
|
[key]: `return (${fn.toString()}).apply(this, arguments)`
|
|
43
60
|
});
|
|
@@ -49,5 +66,6 @@ function prepareComponentInfoToSend(info) {
|
|
|
49
66
|
}
|
|
50
67
|
export {
|
|
51
68
|
components,
|
|
69
|
+
createRegisterComponentMessage,
|
|
52
70
|
registerComponent
|
|
53
71
|
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { isBrowser } from "./is-browser.js";
|
|
3
|
+
const registry = {};
|
|
4
|
+
function register(type, info) {
|
|
5
|
+
let typeList = registry[type];
|
|
6
|
+
if (!typeList) {
|
|
7
|
+
typeList = registry[type] = [];
|
|
8
|
+
}
|
|
9
|
+
typeList.push(info);
|
|
10
|
+
if (isBrowser()) {
|
|
11
|
+
const message = {
|
|
12
|
+
type: "builder.register",
|
|
13
|
+
data: {
|
|
14
|
+
type,
|
|
15
|
+
info
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
try {
|
|
19
|
+
parent.postMessage(message, "*");
|
|
20
|
+
if (parent !== window) {
|
|
21
|
+
window.postMessage(message, "*");
|
|
22
|
+
}
|
|
23
|
+
} catch (err) {
|
|
24
|
+
console.debug("Could not postmessage", err);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
register
|
|
30
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { isBrowser } from "./is-browser.js";
|
|
3
|
+
const settings = {};
|
|
4
|
+
function setEditorSettings(newSettings) {
|
|
5
|
+
if (isBrowser()) {
|
|
6
|
+
Object.assign(settings, newSettings);
|
|
7
|
+
const message = {
|
|
8
|
+
type: "builder.settingsChange",
|
|
9
|
+
data: settings
|
|
10
|
+
};
|
|
11
|
+
parent.postMessage(message, "*");
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
setEditorSettings
|
|
16
|
+
};
|