@builder.io/sdk-react-native 0.0.1-5 → 0.0.1-50
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 +14 -0
- package/README.md +15 -0
- package/package.json +6 -4
- package/src/blocks/button.js +5 -6
- package/src/blocks/button.lite.tsx +7 -11
- package/src/blocks/columns.js +32 -16
- package/src/blocks/columns.lite.tsx +39 -16
- package/src/blocks/custom-code.js +1 -2
- package/src/blocks/custom-code.lite.tsx +2 -10
- package/src/blocks/embed.js +1 -2
- package/src/blocks/embed.lite.tsx +2 -6
- package/src/blocks/form.js +11 -15
- package/src/blocks/form.lite.tsx +18 -22
- package/src/blocks/fragment.js +13 -0
- package/src/blocks/fragment.lite.tsx +10 -0
- package/src/blocks/image.js +27 -7
- package/src/blocks/image.lite.tsx +42 -10
- package/src/blocks/img.js +3 -3
- package/src/blocks/img.lite.tsx +2 -3
- package/src/blocks/input.js +3 -3
- package/src/blocks/input.lite.tsx +2 -5
- package/src/blocks/raw-text.js +1 -3
- package/src/blocks/raw-text.lite.tsx +1 -7
- package/src/blocks/section.js +3 -3
- package/src/blocks/section.lite.tsx +1 -2
- package/src/blocks/select.js +7 -6
- package/src/blocks/select.lite.tsx +6 -7
- package/src/blocks/submit-button.js +3 -3
- package/src/blocks/submit-button.lite.tsx +1 -2
- package/src/blocks/symbol.js +65 -12
- package/src/blocks/symbol.lite.tsx +44 -4
- package/src/blocks/text.js +57 -1
- package/src/blocks/text.lite.tsx +1 -7
- package/src/blocks/textarea.js +1 -1
- package/src/blocks/textarea.lite.tsx +0 -1
- package/src/blocks/video.js +90 -44
- package/src/blocks/video.lite.tsx +0 -1
- package/src/components/block-styles.js +7 -0
- package/src/components/block-styles.lite.tsx +6 -0
- package/src/components/error-boundary.js +25 -0
- package/src/components/error-boundary.lite.tsx +6 -0
- package/src/components/render-block.js +43 -19
- package/src/components/render-block.lite.tsx +69 -34
- package/src/components/render-blocks.js +12 -5
- package/src/components/render-blocks.lite.tsx +16 -7
- package/src/components/render-content.js +224 -24
- package/src/components/render-content.lite.tsx +247 -34
- package/src/context/builder.context.js +6 -1
- package/src/functions/evaluate.js +15 -6
- package/src/functions/event-handler-name.js +8 -0
- package/src/functions/get-block-actions.js +13 -12
- 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 +138 -0
- package/src/functions/get-fetch.js +13 -0
- package/src/functions/get-global-this.js +19 -0
- package/src/functions/get-processed-block.js +3 -1
- package/src/functions/get-processed-block.test.js +12 -7
- package/src/functions/get-target.js +1 -1
- package/src/functions/is-browser.js +1 -2
- package/src/functions/is-previewing.js +15 -0
- package/src/functions/is-react-native.js +1 -1
- package/src/functions/on-change.test.js +0 -1
- package/src/functions/previewing-model-name.js +12 -0
- package/src/functions/register-component.js +1 -0
- package/src/functions/register.js +30 -0
- package/src/functions/set-editor-settings.js +16 -0
- package/src/functions/set.test.js +0 -1
- package/src/functions/track.js +5 -1
- 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 +8 -18
- package/src/scripts/init-editing.js +18 -2
- package/src/types/deep-partial.js +1 -0
- package/src/types/typescript.js +1 -0
- package/index.js +0 -11
- package/src/functions/get-content.js +0 -103
- package/src/package.json +0 -18
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { evaluate } from "./evaluate";
|
|
3
|
-
|
|
4
|
-
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
5
|
-
}
|
|
3
|
+
import { getEventHandlerName } from "./event-handler-name";
|
|
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
|
|
@@ -19,13 +19,16 @@ var __spreadValues = (a, b) => {
|
|
|
19
19
|
};
|
|
20
20
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
21
|
import { findDOMNode } from "react-dom";
|
|
22
|
+
import { isEditing } from "./is-editing";
|
|
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 { getBuilderSearchParams, convertSearchParamsToQueryObject } 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,138 @@
|
|
|
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";
|
|
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 content = yield fetch(url.href).then((res) => res.json());
|
|
128
|
+
if (options.testGroups) {
|
|
129
|
+
handleABTesting(content, options.testGroups);
|
|
130
|
+
}
|
|
131
|
+
return content;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
export {
|
|
135
|
+
generateContentUrl,
|
|
136
|
+
getAllContent,
|
|
137
|
+
getContent
|
|
138
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { getGlobalThis } from "./get-global-this";
|
|
3
|
+
function getFetch() {
|
|
4
|
+
let fetch = getGlobalThis().fetch;
|
|
5
|
+
if (typeof fetch === "undefined" && typeof global !== "undefined") {
|
|
6
|
+
const _require = eval("require");
|
|
7
|
+
fetch = _require("node-fetch");
|
|
8
|
+
}
|
|
9
|
+
return fetch;
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
getFetch
|
|
13
|
+
};
|
|
@@ -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
|
+
};
|
|
@@ -20,8 +20,10 @@ var __spreadValues = (a, b) => {
|
|
|
20
20
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
21
|
import { evaluate } from "./evaluate";
|
|
22
22
|
import { set } from "./set";
|
|
23
|
+
import { transformBlock } from "./transform-block";
|
|
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 { expect, test } from "@jest/globals";
|
|
3
2
|
import { getProcessedBlock } from "./get-processed-block";
|
|
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,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";
|
|
3
|
+
import { isEditing } from "./is-editing";
|
|
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
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { isPreviewing } from "./is-previewing";
|
|
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
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { isBrowser } from "./is-browser";
|
|
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";
|
|
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
|
+
};
|
package/src/functions/track.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { isBrowser } from "./is-browser";
|
|
3
|
+
import { isEditing } from "./is-editing";
|
|
3
4
|
import { isReactNative } from "./is-react-native";
|
|
4
5
|
function track(event, properties) {
|
|
5
|
-
if (
|
|
6
|
+
if (isEditing()) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (!(isBrowser() || isReactNative())) {
|
|
6
10
|
return;
|
|
7
11
|
}
|
|
8
12
|
return fetch(`https://builder.io/api/v1/track`, {
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
function transformBlock(block) {
|
|
22
|
+
if (block.id.startsWith("builder-pixel-") && !block.component) {
|
|
23
|
+
return __spreadProps(__spreadValues({}, block), {
|
|
24
|
+
component: {
|
|
25
|
+
name: "Image",
|
|
26
|
+
options: {
|
|
27
|
+
image: block.properties.src,
|
|
28
|
+
width: 1,
|
|
29
|
+
height: 1
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return block;
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
transformBlock
|
|
38
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { default as default2 } from "../blocks/columns";
|
|
3
|
+
import { default as default3 } from "../blocks/image";
|
|
4
|
+
import { default as default4 } from "../blocks/text";
|
|
5
|
+
import { default as default5 } from "../blocks/symbol";
|
|
6
|
+
import { default as default6 } from "../blocks/button";
|
|
7
|
+
import { default as default7 } from "../blocks/section";
|
|
8
|
+
import { default as default8 } from "../blocks/fragment";
|
|
9
|
+
import { default as default9 } from "../components/render-content";
|
|
10
|
+
export {
|
|
11
|
+
default6 as Button,
|
|
12
|
+
default2 as Columns,
|
|
13
|
+
default8 as Fragment,
|
|
14
|
+
default3 as Image,
|
|
15
|
+
default9 as RenderContent,
|
|
16
|
+
default7 as Section,
|
|
17
|
+
default5 as Symbol,
|
|
18
|
+
default4 as Text
|
|
19
|
+
};
|
package/src/index.js
CHANGED
|
@@ -1,24 +1,14 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import("./index-helpers/top-of-file");
|
|
2
3
|
import { isEditing } from "./functions/is-editing";
|
|
3
4
|
if (isEditing()) {
|
|
4
5
|
import("./scripts/init-editing");
|
|
5
6
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import { default as default5 } from "./blocks/video";
|
|
10
|
-
import { default as default6 } from "./blocks/symbol";
|
|
11
|
-
import { default as default7 } from "./blocks/button";
|
|
12
|
-
import { default as default8 } from "./blocks/section";
|
|
13
|
-
import { default as default9 } from "./components/render-content";
|
|
7
|
+
export * from "./index-helpers/blocks-exports";
|
|
8
|
+
export * from "./functions/is-editing";
|
|
9
|
+
export * from "./functions/is-previewing";
|
|
14
10
|
export * from "./functions/register-component";
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
default9 as RenderContent,
|
|
20
|
-
default8 as Section,
|
|
21
|
-
default6 as Symbol,
|
|
22
|
-
default4 as Text,
|
|
23
|
-
default5 as Video
|
|
24
|
-
};
|
|
11
|
+
export * from "./functions/register";
|
|
12
|
+
export * from "./functions/set-editor-settings";
|
|
13
|
+
export * from "./functions/get-content";
|
|
14
|
+
export * from "./functions/get-builder-search-params";
|