@builder.io/sdk-react-native 0.0.1-44 → 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/package.json +1 -1
- package/src/blocks/button.js +23 -73
- package/src/blocks/button.lite.tsx +3 -3
- package/src/blocks/columns.js +56 -288
- package/src/blocks/columns.lite.tsx +22 -22
- package/src/blocks/custom-code.js +46 -76
- package/src/blocks/custom-code.lite.tsx +11 -19
- package/src/blocks/embed.js +46 -69
- package/src/blocks/embed.lite.tsx +11 -15
- package/src/blocks/form.js +194 -491
- package/src/blocks/form.lite.tsx +51 -51
- package/src/blocks/fragment.js +8 -16
- package/src/blocks/fragment.lite.tsx +2 -2
- package/src/blocks/image.js +91 -113
- package/src/blocks/image.lite.tsx +12 -13
- package/src/blocks/img.js +28 -51
- package/src/blocks/img.lite.tsx +6 -6
- package/src/blocks/input.js +28 -100
- package/src/blocks/input.lite.tsx +4 -4
- package/src/blocks/raw-text.js +10 -16
- package/src/blocks/raw-text.lite.tsx +3 -8
- package/src/blocks/section.js +23 -71
- package/src/blocks/section.lite.tsx +3 -3
- package/src/blocks/select.js +28 -78
- package/src/blocks/select.lite.tsx +5 -5
- package/src/blocks/submit-button.js +21 -47
- package/src/blocks/submit-button.lite.tsx +2 -2
- package/src/blocks/symbol.js +71 -20
- package/src/blocks/symbol.lite.tsx +48 -8
- package/src/blocks/text.js +27 -40
- package/src/blocks/text.lite.tsx +3 -8
- package/src/blocks/textarea.js +24 -60
- package/src/blocks/textarea.lite.tsx +2 -2
- package/src/blocks/video.js +66 -71
- package/src/blocks/video.lite.tsx +5 -5
- package/src/components/block-styles.js +4 -2
- package/src/components/block-styles.lite.tsx +2 -2
- package/src/components/error-boundary.js +9 -11
- package/src/components/error-boundary.lite.tsx +2 -2
- package/src/components/render-block.js +44 -100
- package/src/components/render-block.lite.tsx +23 -28
- package/src/components/render-blocks.js +41 -60
- package/src/components/render-blocks.lite.tsx +20 -14
- package/src/components/render-content.js +189 -142
- package/src/components/render-content.lite.tsx +166 -60
- package/src/constants/device-sizes.js +11 -8
- package/src/context/builder.context.js +10 -3
- package/src/functions/evaluate.js +20 -20
- package/src/functions/event-handler-name.js +3 -1
- package/src/functions/get-block-actions.js +17 -16
- package/src/functions/get-block-component-options.js +9 -16
- package/src/functions/get-block-properties.js +14 -18
- package/src/functions/get-block-styles.js +17 -34
- package/src/functions/get-block-tag.js +4 -2
- 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 +7 -5
- package/src/functions/get-global-this.js +7 -5
- package/src/functions/get-processed-block.js +13 -17
- package/src/functions/get-processed-block.test.js +17 -16
- package/src/functions/get-target.js +4 -2
- package/src/functions/if-target.js +3 -1
- package/src/functions/is-browser.js +4 -2
- package/src/functions/is-editing.js +5 -5
- package/src/functions/is-iframe.js +4 -2
- package/src/functions/is-previewing.js +6 -4
- package/src/functions/is-react-native.js +3 -1
- package/src/functions/macro-eval.js +5 -2
- package/src/functions/on-change.js +7 -4
- package/src/functions/on-change.test.js +9 -10
- package/src/functions/previewing-model-name.js +5 -3
- package/src/functions/register-component.js +27 -38
- package/src/functions/register.js +10 -8
- package/src/functions/set-editor-settings.js +7 -5
- package/src/functions/set.js +5 -14
- package/src/functions/set.test.js +13 -14
- package/src/functions/track.js +12 -6
- package/src/functions/transform-block.js +13 -17
- package/src/index-helpers/blocks-exports.js +19 -0
- package/src/index-helpers/top-of-file.js +2 -0
- package/src/index.js +11 -26
- package/src/scripts/init-editing.js +40 -64
- package/src/types/typescript.js +1 -0
- package/src/functions/get-content.js +0 -152
- package/src/functions/get-content.test.js +0 -58
|
@@ -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
|
+
};
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { getGlobalThis } from
|
|
2
|
+
import { getGlobalThis } from "./get-global-this";
|
|
3
3
|
function getFetch() {
|
|
4
4
|
let fetch = getGlobalThis().fetch;
|
|
5
|
-
if (typeof fetch ===
|
|
6
|
-
const _require = eval(
|
|
7
|
-
fetch = _require(
|
|
5
|
+
if (typeof fetch === "undefined" && typeof global !== "undefined") {
|
|
6
|
+
const _require = eval("require");
|
|
7
|
+
fetch = _require("node-fetch");
|
|
8
8
|
}
|
|
9
9
|
return fetch;
|
|
10
10
|
}
|
|
11
|
-
export {
|
|
11
|
+
export {
|
|
12
|
+
getFetch
|
|
13
|
+
};
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
function getGlobalThis() {
|
|
3
|
-
if (typeof globalThis !==
|
|
3
|
+
if (typeof globalThis !== "undefined") {
|
|
4
4
|
return globalThis;
|
|
5
5
|
}
|
|
6
|
-
if (typeof window !==
|
|
6
|
+
if (typeof window !== "undefined") {
|
|
7
7
|
return window;
|
|
8
8
|
}
|
|
9
|
-
if (typeof global !==
|
|
9
|
+
if (typeof global !== "undefined") {
|
|
10
10
|
return global;
|
|
11
11
|
}
|
|
12
|
-
if (typeof self !==
|
|
12
|
+
if (typeof self !== "undefined") {
|
|
13
13
|
return self;
|
|
14
14
|
}
|
|
15
15
|
return null;
|
|
16
16
|
}
|
|
17
|
-
export {
|
|
17
|
+
export {
|
|
18
|
+
getGlobalThis
|
|
19
|
+
};
|
|
@@ -5,28 +5,22 @@ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
|
5
5
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
-
var __defNormalProp = (obj, key, value) =>
|
|
9
|
-
key in obj
|
|
10
|
-
? __defProp(obj, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
configurable: true,
|
|
13
|
-
writable: true,
|
|
14
|
-
value,
|
|
15
|
-
})
|
|
16
|
-
: (obj[key] = value);
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
17
9
|
var __spreadValues = (a, b) => {
|
|
18
10
|
for (var prop in b || (b = {}))
|
|
19
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
if (__hasOwnProp.call(b, prop))
|
|
12
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
13
|
if (__getOwnPropSymbols)
|
|
21
14
|
for (var prop of __getOwnPropSymbols(b)) {
|
|
22
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
+
if (__propIsEnum.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
23
17
|
}
|
|
24
18
|
return a;
|
|
25
19
|
};
|
|
26
20
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
27
|
-
import { evaluate } from
|
|
28
|
-
import { set } from
|
|
29
|
-
import { transformBlock } from
|
|
21
|
+
import { evaluate } from "./evaluate";
|
|
22
|
+
import { set } from "./set";
|
|
23
|
+
import { transformBlock } from "./transform-block";
|
|
30
24
|
function getProcessedBlock(options) {
|
|
31
25
|
const { state, context } = options;
|
|
32
26
|
const block = transformBlock(options.block);
|
|
@@ -35,17 +29,19 @@ function getProcessedBlock(options) {
|
|
|
35
29
|
}
|
|
36
30
|
const copied = __spreadProps(__spreadValues({}, block), {
|
|
37
31
|
properties: __spreadValues({}, block.properties),
|
|
38
|
-
actions: __spreadValues({}, block.actions)
|
|
32
|
+
actions: __spreadValues({}, block.actions)
|
|
39
33
|
});
|
|
40
34
|
for (const binding in block.bindings) {
|
|
41
35
|
const expression = block.bindings[binding];
|
|
42
36
|
const value = evaluate({
|
|
43
37
|
code: expression,
|
|
44
38
|
state,
|
|
45
|
-
context
|
|
39
|
+
context
|
|
46
40
|
});
|
|
47
41
|
set(copied, binding, value);
|
|
48
42
|
}
|
|
49
43
|
return copied;
|
|
50
44
|
}
|
|
51
|
-
export {
|
|
45
|
+
export {
|
|
46
|
+
getProcessedBlock
|
|
47
|
+
};
|
|
@@ -1,31 +1,32 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import { getProcessedBlock } from "./get-processed-block";
|
|
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
|
-
foo:
|
|
8
|
+
foo: "bar"
|
|
8
9
|
},
|
|
9
10
|
bindings: {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
"properties.foo": '"baz"',
|
|
12
|
+
"responsiveStyles.large.zIndex": "1 + 1",
|
|
13
|
+
"properties.test": "state.test",
|
|
14
|
+
"properties.block": `
|
|
14
15
|
const foo = 'bar';
|
|
15
16
|
return foo;
|
|
16
17
|
`,
|
|
17
|
-
|
|
18
|
-
}
|
|
18
|
+
"properties.isEditing": "builder.isEditing"
|
|
19
|
+
}
|
|
19
20
|
};
|
|
20
21
|
const processed = getProcessedBlock({
|
|
21
22
|
block,
|
|
22
23
|
context: {},
|
|
23
|
-
state: { test:
|
|
24
|
+
state: { test: "hello" }
|
|
24
25
|
});
|
|
25
26
|
expect(processed).not.toEqual(block);
|
|
26
|
-
expect(processed.properties.foo).toEqual(
|
|
27
|
-
expect(processed.properties.test).toEqual(
|
|
28
|
-
expect(processed.properties.block).toEqual(
|
|
29
|
-
expect(processed.properties.isEditing).toEqual(false);
|
|
30
|
-
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);
|
|
31
32
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { isIframe } from
|
|
2
|
+
import { isIframe } from "./is-iframe";
|
|
3
3
|
function isEditing() {
|
|
4
|
-
return (
|
|
5
|
-
isIframe() && window.location.search.indexOf('builder.frameEditing=') !== -1
|
|
6
|
-
);
|
|
4
|
+
return isIframe() && window.location.search.indexOf("builder.frameEditing=") !== -1;
|
|
7
5
|
}
|
|
8
|
-
export {
|
|
6
|
+
export {
|
|
7
|
+
isEditing
|
|
8
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { isBrowser } from
|
|
3
|
-
import { isEditing } from
|
|
2
|
+
import { isBrowser } from "./is-browser";
|
|
3
|
+
import { isEditing } from "./is-editing";
|
|
4
4
|
function isPreviewing() {
|
|
5
5
|
if (!isBrowser()) {
|
|
6
6
|
return false;
|
|
@@ -8,6 +8,8 @@ function isPreviewing() {
|
|
|
8
8
|
if (isEditing()) {
|
|
9
9
|
return false;
|
|
10
10
|
}
|
|
11
|
-
return Boolean(location.search.indexOf(
|
|
11
|
+
return Boolean(location.search.indexOf("builder.preview=") !== -1);
|
|
12
12
|
}
|
|
13
|
-
export {
|
|
13
|
+
export {
|
|
14
|
+
isPreviewing
|
|
15
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
const onChangeProxySymbol = Symbol(
|
|
2
|
+
const onChangeProxySymbol = Symbol("onChangeProxySymbol");
|
|
3
3
|
function onChange(obj, cb) {
|
|
4
4
|
return new Proxy(obj, {
|
|
5
5
|
get(target, key) {
|
|
@@ -7,7 +7,7 @@ function onChange(obj, cb) {
|
|
|
7
7
|
return true;
|
|
8
8
|
}
|
|
9
9
|
const value = Reflect.get(target, key);
|
|
10
|
-
if (value && typeof value ===
|
|
10
|
+
if (value && typeof value === "object") {
|
|
11
11
|
if (value[onChangeProxySymbol]) {
|
|
12
12
|
return value;
|
|
13
13
|
}
|
|
@@ -19,7 +19,10 @@ function onChange(obj, cb) {
|
|
|
19
19
|
const returnValue = Reflect.set(target, key, value);
|
|
20
20
|
cb();
|
|
21
21
|
return returnValue;
|
|
22
|
-
}
|
|
22
|
+
}
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
|
-
export {
|
|
25
|
+
export {
|
|
26
|
+
onChange,
|
|
27
|
+
onChangeProxySymbol
|
|
28
|
+
};
|
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
test('onChange can observe a shallow change', () => {
|
|
2
|
+
import { onChange } from "./on-change";
|
|
3
|
+
test("onChange can observe a shallow change", () => {
|
|
5
4
|
let changeHappend = false;
|
|
6
|
-
const obj = onChange({ foo:
|
|
7
|
-
obj.foo =
|
|
5
|
+
const obj = onChange({ foo: "hi" }, () => changeHappend = true);
|
|
6
|
+
obj.foo = "yo";
|
|
8
7
|
expect(changeHappend).toBe(true);
|
|
9
8
|
});
|
|
10
|
-
test(
|
|
9
|
+
test("onChange can observe a deep change", () => {
|
|
11
10
|
let changeHappend = false;
|
|
12
|
-
const obj = onChange({ foo: { bar:
|
|
13
|
-
obj.foo.bar =
|
|
11
|
+
const obj = onChange({ foo: { bar: "hi" } }, () => changeHappend = true);
|
|
12
|
+
obj.foo.bar = "yo";
|
|
14
13
|
expect(changeHappend).toBe(true);
|
|
15
14
|
});
|
|
16
|
-
test(
|
|
15
|
+
test("Smoke test: callback is not fired if no properties updated", () => {
|
|
17
16
|
let changeHappend = false;
|
|
18
|
-
const obj = onChange({ foo: { bar:
|
|
17
|
+
const obj = onChange({ foo: { bar: "hi" } }, () => changeHappend = true);
|
|
19
18
|
obj.foo.bar;
|
|
20
19
|
expect(changeHappend).toBe(false);
|
|
21
20
|
});
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { isPreviewing } from
|
|
2
|
+
import { isPreviewing } from "./is-previewing";
|
|
3
3
|
function previewingModelName() {
|
|
4
4
|
if (!isPreviewing()) {
|
|
5
5
|
return null;
|
|
6
6
|
}
|
|
7
7
|
const url = new URL(location.href);
|
|
8
|
-
return url.searchParams.get(
|
|
8
|
+
return url.searchParams.get("builder.preview");
|
|
9
9
|
}
|
|
10
|
-
export {
|
|
10
|
+
export {
|
|
11
|
+
previewingModelName
|
|
12
|
+
};
|
|
@@ -5,61 +5,50 @@ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
|
5
5
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
-
var __defNormalProp = (obj, key, value) =>
|
|
9
|
-
key in obj
|
|
10
|
-
? __defProp(obj, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
configurable: true,
|
|
13
|
-
writable: true,
|
|
14
|
-
value,
|
|
15
|
-
})
|
|
16
|
-
: (obj[key] = value);
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
17
9
|
var __spreadValues = (a, b) => {
|
|
18
10
|
for (var prop in b || (b = {}))
|
|
19
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
if (__hasOwnProp.call(b, prop))
|
|
12
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
13
|
if (__getOwnPropSymbols)
|
|
21
14
|
for (var prop of __getOwnPropSymbols(b)) {
|
|
22
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
+
if (__propIsEnum.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
23
17
|
}
|
|
24
18
|
return a;
|
|
25
19
|
};
|
|
26
20
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
27
|
-
import { isBrowser } from
|
|
21
|
+
import { isBrowser } from "./is-browser";
|
|
28
22
|
const components = {};
|
|
29
23
|
function registerComponent(component, info) {
|
|
30
24
|
var _a;
|
|
31
25
|
components[info.name] = { component, info };
|
|
32
26
|
if (isBrowser()) {
|
|
33
27
|
const sendInfo = prepareComponentInfoToSend(info);
|
|
34
|
-
(_a = window.parent) == null
|
|
35
|
-
|
|
36
|
-
:
|
|
37
|
-
|
|
38
|
-
type: 'builder.registerComponent',
|
|
39
|
-
data: sendInfo,
|
|
40
|
-
},
|
|
41
|
-
'*'
|
|
42
|
-
);
|
|
28
|
+
(_a = window.parent) == null ? void 0 : _a.postMessage({
|
|
29
|
+
type: "builder.registerComponent",
|
|
30
|
+
data: sendInfo
|
|
31
|
+
}, "*");
|
|
43
32
|
}
|
|
44
33
|
return component;
|
|
45
34
|
}
|
|
46
35
|
function prepareComponentInfoToSend(info) {
|
|
47
|
-
return __spreadValues(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
[key]: `return (${fn.toString()}).apply(this, arguments)`,
|
|
57
|
-
});
|
|
58
|
-
}
|
|
36
|
+
return __spreadValues(__spreadValues({}, info), info.inputs && {
|
|
37
|
+
inputs: info.inputs.map((input) => {
|
|
38
|
+
const keysToConvertFnToString = ["onChange", "showIf"];
|
|
39
|
+
for (const key of keysToConvertFnToString) {
|
|
40
|
+
if (input[key] && typeof input[key] === "function") {
|
|
41
|
+
const fn = input[key];
|
|
42
|
+
input = __spreadProps(__spreadValues({}, input), {
|
|
43
|
+
[key]: `return (${fn.toString()}).apply(this, arguments)`
|
|
44
|
+
});
|
|
59
45
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
);
|
|
46
|
+
}
|
|
47
|
+
return input;
|
|
48
|
+
})
|
|
49
|
+
});
|
|
64
50
|
}
|
|
65
|
-
export {
|
|
51
|
+
export {
|
|
52
|
+
components,
|
|
53
|
+
registerComponent
|
|
54
|
+
};
|