@builder.io/sdk-react-native 0.0.1-7 → 0.0.1-70
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 +42 -0
- package/README.md +19 -0
- package/package.json +6 -4
- package/src/blocks/button/button.js +34 -0
- package/src/blocks/button/component-info.js +41 -0
- package/src/blocks/columns/columns.js +61 -0
- package/src/blocks/columns/component-info.js +242 -0
- package/src/blocks/custom-code/component-info.js +31 -0
- package/src/blocks/{custom-code.lite.tsx → custom-code/custom-code.js} +16 -33
- package/src/blocks/embed/component-info.js +44 -0
- package/src/blocks/embed/embed.js +43 -0
- package/src/blocks/embed/helpers.js +9 -0
- package/src/blocks/form/component-info.js +262 -0
- package/src/blocks/form/form.js +224 -0
- package/src/blocks/fragment/component-info.js +11 -0
- package/src/blocks/fragment/fragment.js +8 -0
- package/src/blocks/image/component-info.js +151 -0
- package/src/blocks/image/image.helpers.js +48 -0
- package/src/blocks/image/image.js +40 -0
- package/src/blocks/img/component-info.js +20 -0
- package/src/blocks/img/img.js +36 -0
- package/src/blocks/input/component-info.js +74 -0
- package/src/blocks/input/input.js +36 -0
- package/src/blocks/raw-text/component-info.js +16 -0
- package/src/blocks/raw-text/raw-text.js +10 -0
- package/src/blocks/section/component-info.js +49 -0
- package/src/blocks/section/section.js +31 -0
- package/src/blocks/select/component-info.js +59 -0
- package/src/blocks/select/select.js +36 -0
- package/src/blocks/submit-button/component-info.js +28 -0
- package/src/blocks/submit-button/submit-button.js +29 -0
- package/src/blocks/symbol/component-info.js +43 -0
- package/src/blocks/symbol/symbol.js +69 -0
- package/src/blocks/{text.js → text/component-info.js} +4 -11
- package/src/blocks/text/text.js +64 -0
- package/src/blocks/textarea/component-info.js +47 -0
- package/src/blocks/textarea/textarea.js +32 -0
- package/src/blocks/util.js +7 -0
- package/src/blocks/video/component-info.js +106 -0
- package/src/blocks/video/video.js +32 -0
- package/src/components/render-block/block-styles.js +37 -0
- package/src/components/render-block/render-block.helpers.js +23 -0
- package/src/components/render-block/render-block.js +171 -0
- package/src/components/render-block/render-component.js +35 -0
- package/src/components/render-block/render-repeated-block.js +30 -0
- package/src/components/render-block/types.js +0 -0
- package/src/components/render-blocks.js +29 -13
- package/src/components/render-content/components/render-styles.js +58 -0
- package/src/components/render-content/index.js +4 -0
- package/src/components/render-content/render-content.js +277 -0
- package/src/components/render-inlined-styles.js +18 -0
- package/src/constants/builder-registered-components.js +42 -0
- package/src/constants/device-sizes.js +3 -22
- package/src/constants/target.js +4 -0
- package/src/context/builder.context.js +7 -1
- package/src/functions/camel-to-kebab-case.js +4 -0
- package/src/functions/convert-style-object.js +6 -0
- package/src/functions/evaluate.js +17 -9
- package/src/functions/event-handler-name.js +7 -0
- package/src/functions/get-block-actions.js +14 -14
- package/src/functions/get-block-component-options.js +22 -2
- package/src/functions/get-block-properties.js +2 -4
- package/src/functions/get-block-styles.js +9 -28
- package/src/functions/get-block-tag.js +1 -2
- package/src/functions/get-builder-search-params/fn.test.js +13 -0
- package/src/functions/get-builder-search-params/index.js +33 -0
- package/src/functions/get-content/ab-testing.js +38 -0
- package/src/functions/get-content/fn.test.js +31 -0
- package/src/functions/get-content/index.js +96 -0
- package/src/functions/get-content/types.js +0 -0
- package/src/functions/get-fetch.js +34 -0
- package/src/functions/get-global-this.js +18 -0
- package/src/functions/get-processed-block.js +22 -10
- package/src/functions/get-processed-block.test.js +14 -9
- package/src/functions/if-target.js +11 -3
- package/src/functions/is-browser.js +1 -3
- package/src/functions/is-editing.js +1 -2
- package/src/functions/is-iframe.js +1 -2
- package/src/functions/is-previewing.js +14 -0
- package/src/functions/is-react-native.js +1 -2
- package/src/functions/on-change.js +0 -1
- package/src/functions/on-change.test.js +1 -3
- package/src/functions/register-component.js +46 -27
- package/src/functions/register.js +29 -0
- package/src/functions/sanitize-styles.js +32 -0
- package/src/functions/set-editor-settings.js +15 -0
- package/src/functions/set.js +0 -1
- package/src/functions/set.test.js +1 -3
- package/src/functions/track.js +109 -13
- package/src/functions/transform-block.js +37 -0
- package/src/helpers/cookie.js +59 -0
- package/src/helpers/css.js +12 -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 +26 -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 +18 -0
- package/src/index-helpers/top-of-file.js +1 -0
- package/src/index.js +10 -24
- package/src/scripts/init-editing.js +73 -51
- package/src/types/builder-block.js +0 -1
- package/src/types/builder-content.js +0 -1
- package/src/types/can-track.js +0 -0
- package/src/types/components.js +0 -0
- package/src/types/deep-partial.js +0 -0
- package/src/types/element.js +0 -0
- package/src/types/targets.js +0 -0
- package/src/types/typescript.js +0 -0
- package/index.js +0 -11
- package/src/blocks/button.js +0 -37
- package/src/blocks/button.lite.tsx +0 -29
- package/src/blocks/columns.js +0 -42
- package/src/blocks/columns.lite.tsx +0 -41
- package/src/blocks/custom-code.js +0 -56
- package/src/blocks/embed.js +0 -56
- package/src/blocks/embed.lite.tsx +0 -65
- package/src/blocks/form.js +0 -229
- package/src/blocks/form.lite.tsx +0 -257
- package/src/blocks/image.js +0 -123
- package/src/blocks/image.lite.tsx +0 -35
- package/src/blocks/img.js +0 -41
- package/src/blocks/img.lite.tsx +0 -19
- package/src/blocks/input.js +0 -41
- package/src/blocks/input.lite.tsx +0 -23
- 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/section.lite.tsx +0 -20
- package/src/blocks/select.js +0 -40
- package/src/blocks/select.lite.tsx +0 -24
- package/src/blocks/submit-button.js +0 -34
- package/src/blocks/submit-button.lite.tsx +0 -11
- 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/textarea.lite.tsx +0 -15
- package/src/blocks/video.js +0 -49
- package/src/blocks/video.lite.tsx +0 -28
- package/src/components/render-block.js +0 -84
- package/src/components/render-block.lite.tsx +0 -92
- package/src/components/render-blocks.lite.tsx +0 -56
- 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/functions/macro-eval.js +0 -6
- package/src/package.json +0 -18
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { convertSearchParamsToQueryObject, getBuilderSearchParams } from ".";
|
|
2
|
+
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";
|
|
3
|
+
const url = new URL(`localhost:3000/about-us?${querystring}`);
|
|
4
|
+
describe("Get Builder SearchParams", () => {
|
|
5
|
+
test("correctly converts URLSearchParams to object", () => {
|
|
6
|
+
const output = convertSearchParamsToQueryObject(url.searchParams);
|
|
7
|
+
expect(output).toMatchSnapshot();
|
|
8
|
+
});
|
|
9
|
+
test("correctly extracts all builder params from a query object", () => {
|
|
10
|
+
const output = getBuilderSearchParams(convertSearchParamsToQueryObject(url.searchParams));
|
|
11
|
+
expect(output).toMatchSnapshot();
|
|
12
|
+
});
|
|
13
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { isBrowser } from "../is-browser.js";
|
|
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
|
+
const getBuilderSearchParamsFromWindow = () => {
|
|
21
|
+
if (!isBrowser()) {
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
25
|
+
return getBuilderSearchParams(convertSearchParamsToQueryObject(searchParams));
|
|
26
|
+
};
|
|
27
|
+
const normalizeSearchParams = (searchParams) => searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams;
|
|
28
|
+
export {
|
|
29
|
+
convertSearchParamsToQueryObject,
|
|
30
|
+
getBuilderSearchParams,
|
|
31
|
+
getBuilderSearchParamsFromWindow,
|
|
32
|
+
normalizeSearchParams
|
|
33
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const handleABTesting = (item, testGroups) => {
|
|
2
|
+
if (item.variations && Object.keys(item.variations).length) {
|
|
3
|
+
const testGroup = item.id ? testGroups[item.id] : void 0;
|
|
4
|
+
const variationValue = testGroup ? item.variations[testGroup] : void 0;
|
|
5
|
+
if (testGroup && variationValue) {
|
|
6
|
+
item.data = variationValue.data;
|
|
7
|
+
item.testVariationId = variationValue.id;
|
|
8
|
+
item.testVariationName = variationValue.name;
|
|
9
|
+
} else {
|
|
10
|
+
let n = 0;
|
|
11
|
+
const random = Math.random();
|
|
12
|
+
let set = false;
|
|
13
|
+
for (const id in item.variations) {
|
|
14
|
+
const variation = item.variations[id];
|
|
15
|
+
const testRatio = variation.testRatio;
|
|
16
|
+
n += testRatio;
|
|
17
|
+
if (random < n) {
|
|
18
|
+
const variationName = variation.name || (variation.id === item.id ? "Default variation" : "");
|
|
19
|
+
set = true;
|
|
20
|
+
Object.assign(item, {
|
|
21
|
+
data: variation.data,
|
|
22
|
+
testVariationId: variation.id,
|
|
23
|
+
testVariationName: variationName
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (!set) {
|
|
28
|
+
Object.assign(item, {
|
|
29
|
+
testVariationId: item.id,
|
|
30
|
+
testVariationName: "Default"
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
export {
|
|
37
|
+
handleABTesting
|
|
38
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { generateContentUrl } from ".";
|
|
2
|
+
const testKey = "YJIGb4i01jvw0SRdL5Bt";
|
|
3
|
+
const testModel = "page";
|
|
4
|
+
const testId = "c1b81bab59704599b997574eb0736def";
|
|
5
|
+
const options = {
|
|
6
|
+
cachebust: "true",
|
|
7
|
+
noCache: "true",
|
|
8
|
+
"overrides.037948e52eaf4743afed464f02c70da4": "037948e52eaf4743afed464f02c70da4",
|
|
9
|
+
"overrides.page": "037948e52eaf4743afed464f02c70da4",
|
|
10
|
+
"overrides.page:/": "037948e52eaf4743afed464f02c70da4",
|
|
11
|
+
preview: "page"
|
|
12
|
+
};
|
|
13
|
+
describe("Generate Content URL", () => {
|
|
14
|
+
test("generates the proper value for a simple query", () => {
|
|
15
|
+
const output = generateContentUrl({
|
|
16
|
+
apiKey: testKey,
|
|
17
|
+
model: testModel,
|
|
18
|
+
query: { id: testId }
|
|
19
|
+
});
|
|
20
|
+
expect(output).toMatchSnapshot();
|
|
21
|
+
});
|
|
22
|
+
test("Handles overrides correctly", () => {
|
|
23
|
+
const output = generateContentUrl({
|
|
24
|
+
apiKey: testKey,
|
|
25
|
+
model: testModel,
|
|
26
|
+
query: { id: testId },
|
|
27
|
+
options
|
|
28
|
+
});
|
|
29
|
+
expect(output).toMatchSnapshot();
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __async = (__this, __arguments, generator) => {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
var fulfilled = (value) => {
|
|
23
|
+
try {
|
|
24
|
+
step(generator.next(value));
|
|
25
|
+
} catch (e) {
|
|
26
|
+
reject(e);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var rejected = (value) => {
|
|
30
|
+
try {
|
|
31
|
+
step(generator.throw(value));
|
|
32
|
+
} catch (e) {
|
|
33
|
+
reject(e);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
import { flatten } from "../../helpers/flatten.js";
|
|
41
|
+
import {
|
|
42
|
+
getBuilderSearchParamsFromWindow,
|
|
43
|
+
normalizeSearchParams
|
|
44
|
+
} from "../get-builder-search-params/index.js";
|
|
45
|
+
import { getFetch } from "../get-fetch.js";
|
|
46
|
+
import { handleABTesting } from "./ab-testing.js";
|
|
47
|
+
const fetch$ = getFetch();
|
|
48
|
+
function getContent(options) {
|
|
49
|
+
return __async(this, null, function* () {
|
|
50
|
+
return (yield getAllContent(__spreadProps(__spreadValues({}, options), { limit: 1 }))).results[0] || null;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
const generateContentUrl = (options) => {
|
|
54
|
+
const {
|
|
55
|
+
limit = 30,
|
|
56
|
+
userAttributes,
|
|
57
|
+
query,
|
|
58
|
+
noTraverse = false,
|
|
59
|
+
model,
|
|
60
|
+
apiKey
|
|
61
|
+
} = options;
|
|
62
|
+
const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}`);
|
|
63
|
+
const queryOptions = __spreadValues(__spreadValues({}, getBuilderSearchParamsFromWindow()), normalizeSearchParams(options.options || {}));
|
|
64
|
+
const flattened = flatten(queryOptions);
|
|
65
|
+
for (const key in flattened) {
|
|
66
|
+
url.searchParams.set(key, String(flattened[key]));
|
|
67
|
+
}
|
|
68
|
+
if (userAttributes) {
|
|
69
|
+
url.searchParams.set("userAttributes", JSON.stringify(userAttributes));
|
|
70
|
+
}
|
|
71
|
+
if (query) {
|
|
72
|
+
const flattened2 = flatten({ query });
|
|
73
|
+
for (const key in flattened2) {
|
|
74
|
+
url.searchParams.set(key, JSON.stringify(flattened2[key]));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return url;
|
|
78
|
+
};
|
|
79
|
+
function getAllContent(options) {
|
|
80
|
+
return __async(this, null, function* () {
|
|
81
|
+
const url = generateContentUrl(options);
|
|
82
|
+
const fetch = yield fetch$;
|
|
83
|
+
const content = yield fetch(url.href).then((res) => res.json());
|
|
84
|
+
if (options.testGroups) {
|
|
85
|
+
for (const item of content.results) {
|
|
86
|
+
handleABTesting(item, options.testGroups);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return content;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
export {
|
|
93
|
+
generateContentUrl,
|
|
94
|
+
getAllContent,
|
|
95
|
+
getContent
|
|
96
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,34 @@
|
|
|
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 { getGlobalThis } from "./get-global-this.js";
|
|
22
|
+
function getFetch() {
|
|
23
|
+
return __async(this, null, function* () {
|
|
24
|
+
const globalFetch = getGlobalThis().fetch;
|
|
25
|
+
if (typeof globalFetch === "undefined" && typeof global !== "undefined") {
|
|
26
|
+
const nodeFetch = import("node-fetch").then((d) => d.default);
|
|
27
|
+
return nodeFetch.default || nodeFetch;
|
|
28
|
+
}
|
|
29
|
+
return globalFetch.default || globalFetch;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
getFetch
|
|
34
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
function getGlobalThis() {
|
|
2
|
+
if (typeof globalThis !== "undefined") {
|
|
3
|
+
return globalThis;
|
|
4
|
+
}
|
|
5
|
+
if (typeof window !== "undefined") {
|
|
6
|
+
return window;
|
|
7
|
+
}
|
|
8
|
+
if (typeof global !== "undefined") {
|
|
9
|
+
return global;
|
|
10
|
+
}
|
|
11
|
+
if (typeof self !== "undefined") {
|
|
12
|
+
return self;
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
getGlobalThis
|
|
18
|
+
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
2
|
var __defProps = Object.defineProperties;
|
|
4
3
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
@@ -18,10 +17,14 @@ var __spreadValues = (a, b) => {
|
|
|
18
17
|
return a;
|
|
19
18
|
};
|
|
20
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
|
-
import { evaluate } from "./evaluate";
|
|
22
|
-
import { set } from "./set";
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
import { evaluate } from "./evaluate.js";
|
|
21
|
+
import { set } from "./set.js";
|
|
22
|
+
import { transformBlock } from "./transform-block.js";
|
|
23
|
+
const evaluateBindings = ({
|
|
24
|
+
block,
|
|
25
|
+
context,
|
|
26
|
+
state
|
|
27
|
+
}) => {
|
|
25
28
|
if (!block.bindings) {
|
|
26
29
|
return block;
|
|
27
30
|
}
|
|
@@ -31,14 +34,23 @@ function getProcessedBlock(options) {
|
|
|
31
34
|
});
|
|
32
35
|
for (const binding in block.bindings) {
|
|
33
36
|
const expression = block.bindings[binding];
|
|
34
|
-
const value = evaluate({
|
|
35
|
-
code: expression,
|
|
36
|
-
state,
|
|
37
|
-
context
|
|
38
|
-
});
|
|
37
|
+
const value = evaluate({ code: expression, state, context });
|
|
39
38
|
set(copied, binding, value);
|
|
40
39
|
}
|
|
41
40
|
return copied;
|
|
41
|
+
};
|
|
42
|
+
function getProcessedBlock({
|
|
43
|
+
block,
|
|
44
|
+
context,
|
|
45
|
+
shouldEvaluateBindings,
|
|
46
|
+
state
|
|
47
|
+
}) {
|
|
48
|
+
const transformedBlock = transformBlock(block);
|
|
49
|
+
if (shouldEvaluateBindings) {
|
|
50
|
+
return evaluateBindings({ block: transformedBlock, state, context });
|
|
51
|
+
} else {
|
|
52
|
+
return transformedBlock;
|
|
53
|
+
}
|
|
42
54
|
}
|
|
43
55
|
export {
|
|
44
56
|
getProcessedBlock
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { expect, test } from "@jest/globals";
|
|
3
|
-
import { getProcessedBlock } from "./get-processed-block";
|
|
1
|
+
import { getProcessedBlock } from "./get-processed-block.js";
|
|
4
2
|
test("Can process bindings", () => {
|
|
3
|
+
var _a, _b, _c, _d, _e, _f;
|
|
5
4
|
const block = {
|
|
5
|
+
"@type": "@builder.io/sdk:Element",
|
|
6
6
|
properties: {
|
|
7
7
|
foo: "bar"
|
|
8
8
|
},
|
|
@@ -17,11 +17,16 @@ test("Can process bindings", () => {
|
|
|
17
17
|
"properties.isEditing": "builder.isEditing"
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
|
-
const processed = getProcessedBlock({
|
|
20
|
+
const processed = getProcessedBlock({
|
|
21
|
+
block,
|
|
22
|
+
context: {},
|
|
23
|
+
state: { test: "hello" },
|
|
24
|
+
shouldEvaluateBindings: true
|
|
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,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
function ifTarget(
|
|
3
|
-
|
|
1
|
+
import { TARGET } from "../constants/target.js";
|
|
2
|
+
function ifTarget({
|
|
3
|
+
targets,
|
|
4
|
+
doThing,
|
|
5
|
+
elseThing
|
|
6
|
+
}) {
|
|
7
|
+
if (TARGET && targets.includes(TARGET)) {
|
|
8
|
+
return doThing();
|
|
9
|
+
} else {
|
|
10
|
+
return elseThing == null ? void 0 : elseThing();
|
|
11
|
+
}
|
|
4
12
|
}
|
|
5
13
|
export {
|
|
6
14
|
ifTarget
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { isReactNative } from "./is-react-native";
|
|
3
1
|
function isBrowser() {
|
|
4
|
-
return typeof window !== "undefined" && typeof document !== "undefined"
|
|
2
|
+
return typeof window !== "undefined" && typeof document !== "undefined";
|
|
5
3
|
}
|
|
6
4
|
export {
|
|
7
5
|
isBrowser
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { isBrowser } from "./is-browser.js";
|
|
2
|
+
import { isEditing } from "./is-editing.js";
|
|
3
|
+
function isPreviewing() {
|
|
4
|
+
if (!isBrowser()) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
if (isEditing()) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
return Boolean(location.search.indexOf("builder.preview=") !== -1);
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
isPreviewing
|
|
14
|
+
};
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { expect, test } from "@jest/globals";
|
|
3
|
-
import { onChange } from "./on-change";
|
|
1
|
+
import { onChange } from "./on-change.js";
|
|
4
2
|
test("onChange can observe a shallow change", () => {
|
|
5
3
|
let changeHappend = false;
|
|
6
4
|
const obj = onChange({ foo: "hi" }, () => changeHappend = true);
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
2
|
var __defProps = Object.defineProperties;
|
|
4
3
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
@@ -18,36 +17,56 @@ var __spreadValues = (a, b) => {
|
|
|
18
17
|
return a;
|
|
19
18
|
};
|
|
20
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
32
|
+
const components = [];
|
|
23
33
|
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
|
-
}
|
|
34
|
+
components.push(__spreadValues({ component }, info));
|
|
35
|
+
console.warn("registerComponent is deprecated. Use the `customComponents` prop in RenderContent instead to provide your custom components to the builder SDK.");
|
|
36
|
+
return component;
|
|
33
37
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
38
|
+
const createRegisterComponentMessage = (_a) => {
|
|
39
|
+
var _b = _a, {
|
|
40
|
+
component: _
|
|
41
|
+
} = _b, info = __objRest(_b, [
|
|
42
|
+
"component"
|
|
43
|
+
]);
|
|
44
|
+
return {
|
|
45
|
+
type: "builder.registerComponent",
|
|
46
|
+
data: prepareComponentInfoToSend(info)
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
const fastClone = (obj) => JSON.parse(JSON.stringify(obj));
|
|
50
|
+
const serializeValue = (value) => typeof value === "function" ? serializeFn(value) : fastClone(value);
|
|
51
|
+
const serializeFn = (fnValue) => {
|
|
52
|
+
const fnStr = fnValue.toString().trim();
|
|
53
|
+
const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("(");
|
|
54
|
+
return `return (${appendFunction ? "function " : ""}${fnStr}).apply(this, arguments)`;
|
|
55
|
+
};
|
|
56
|
+
const prepareComponentInfoToSend = (_c) => {
|
|
57
|
+
var _d = _c, {
|
|
58
|
+
inputs
|
|
59
|
+
} = _d, info = __objRest(_d, [
|
|
60
|
+
"inputs"
|
|
61
|
+
]);
|
|
62
|
+
return __spreadProps(__spreadValues({}, fastClone(info)), {
|
|
63
|
+
inputs: inputs == null ? void 0 : inputs.map((input) => Object.entries(input).reduce((acc, [key, value]) => __spreadProps(__spreadValues({}, acc), {
|
|
64
|
+
[key]: serializeValue(value)
|
|
65
|
+
}), {}))
|
|
48
66
|
});
|
|
49
|
-
}
|
|
67
|
+
};
|
|
50
68
|
export {
|
|
51
69
|
components,
|
|
70
|
+
createRegisterComponentMessage,
|
|
52
71
|
registerComponent
|
|
53
72
|
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { isBrowser } from "./is-browser.js";
|
|
2
|
+
const registry = {};
|
|
3
|
+
function register(type, info) {
|
|
4
|
+
let typeList = registry[type];
|
|
5
|
+
if (!typeList) {
|
|
6
|
+
typeList = registry[type] = [];
|
|
7
|
+
}
|
|
8
|
+
typeList.push(info);
|
|
9
|
+
if (isBrowser()) {
|
|
10
|
+
const message = {
|
|
11
|
+
type: "builder.register",
|
|
12
|
+
data: {
|
|
13
|
+
type,
|
|
14
|
+
info
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
try {
|
|
18
|
+
parent.postMessage(message, "*");
|
|
19
|
+
if (parent !== window) {
|
|
20
|
+
window.postMessage(message, "*");
|
|
21
|
+
}
|
|
22
|
+
} catch (err) {
|
|
23
|
+
console.debug("Could not postmessage", err);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
register
|
|
29
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const propertiesThatMustBeNumber = new Set(["lineHeight"]);
|
|
2
|
+
const displayValues = new Set(["flex", "none"]);
|
|
3
|
+
const SHOW_WARNINGS = false;
|
|
4
|
+
const sanitizeBlockStyles = (styles) => {
|
|
5
|
+
for (const key in styles) {
|
|
6
|
+
const propertyValue = styles[key];
|
|
7
|
+
if (key === "display" && !displayValues.has(propertyValue)) {
|
|
8
|
+
if (SHOW_WARNINGS) {
|
|
9
|
+
console.warn(`Style value for key "display" must be "flex" or "none" but had ${propertyValue}`);
|
|
10
|
+
}
|
|
11
|
+
delete styles[key];
|
|
12
|
+
}
|
|
13
|
+
if (typeof propertyValue === "string" && propertyValue.match(/^-?\d/)) {
|
|
14
|
+
const newValue = parseFloat(propertyValue);
|
|
15
|
+
if (!isNaN(newValue)) {
|
|
16
|
+
styles[key] = newValue;
|
|
17
|
+
}
|
|
18
|
+
if (typeof newValue === "number" && newValue < 0) {
|
|
19
|
+
styles[key] = 0;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (propertiesThatMustBeNumber.has(key) && typeof styles[key] !== "number") {
|
|
23
|
+
if (SHOW_WARNINGS) {
|
|
24
|
+
console.warn(`Style key ${key} must be a number, but had value \`${styles[key]}\``);
|
|
25
|
+
}
|
|
26
|
+
delete styles[key];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
export {
|
|
31
|
+
sanitizeBlockStyles
|
|
32
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { isBrowser } from "./is-browser.js";
|
|
2
|
+
const settings = {};
|
|
3
|
+
function setEditorSettings(newSettings) {
|
|
4
|
+
if (isBrowser()) {
|
|
5
|
+
Object.assign(settings, newSettings);
|
|
6
|
+
const message = {
|
|
7
|
+
type: "builder.settingsChange",
|
|
8
|
+
data: settings
|
|
9
|
+
};
|
|
10
|
+
parent.postMessage(message, "*");
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
setEditorSettings
|
|
15
|
+
};
|
package/src/functions/set.js
CHANGED