@builder.io/sdk-react-native 0.0.1-34 → 0.0.1-38
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/package.json +1 -1
- package/src/blocks/button.js +86 -0
- package/src/blocks/button.lite.tsx +25 -0
- package/src/blocks/columns.js +265 -0
- package/src/blocks/columns.lite.tsx +40 -0
- package/src/blocks/custom-code.js +85 -0
- package/src/blocks/custom-code.lite.tsx +67 -0
- package/src/blocks/embed.js +78 -0
- package/src/blocks/embed.lite.tsx +65 -0
- package/src/blocks/form.js +522 -0
- package/src/blocks/form.lite.tsx +253 -0
- package/src/blocks/fragment.js +21 -0
- package/src/blocks/fragment.lite.tsx +10 -0
- package/src/blocks/image.js +129 -0
- package/src/blocks/image.lite.tsx +68 -0
- package/src/blocks/img.js +64 -0
- package/src/blocks/img.lite.tsx +18 -0
- package/src/blocks/input.js +113 -0
- package/src/blocks/input.lite.tsx +20 -0
- package/src/blocks/raw-text.js +21 -0
- package/src/blocks/raw-text.lite.tsx +11 -0
- package/src/blocks/section.js +84 -0
- package/src/blocks/section.lite.tsx +19 -0
- package/src/blocks/select.js +91 -0
- package/src/blocks/select.lite.tsx +23 -0
- package/src/blocks/submit-button.js +60 -0
- package/src/blocks/submit-button.lite.tsx +10 -0
- package/src/blocks/symbol.js +22 -0
- package/src/blocks/symbol.lite.tsx +20 -0
- package/src/blocks/text.js +100 -0
- package/src/blocks/text.lite.tsx +11 -0
- package/src/blocks/textarea.js +73 -0
- package/src/blocks/textarea.lite.tsx +14 -0
- package/src/blocks/video.js +100 -0
- package/src/blocks/video.lite.tsx +27 -0
- package/src/components/block-styles.js +5 -0
- package/src/components/block-styles.lite.tsx +6 -0
- package/src/components/error-boundary.js +27 -0
- package/src/components/error-boundary.lite.tsx +6 -0
- package/src/components/render-block.js +169 -0
- package/src/components/render-block.lite.tsx +129 -0
- package/src/components/render-blocks.js +73 -0
- package/src/components/render-blocks.lite.tsx +59 -0
- package/src/components/render-content.js +215 -0
- package/src/components/render-content.lite.tsx +207 -0
- package/src/constants/device-sizes.js +37 -0
- package/src/context/builder.context.js +3 -0
- package/src/functions/evaluate.js +29 -0
- package/src/functions/event-handler-name.js +6 -0
- package/src/functions/get-block-actions.js +23 -0
- package/src/functions/get-block-component-options.js +31 -0
- package/src/functions/get-block-properties.js +47 -0
- package/src/functions/get-block-styles.js +78 -0
- package/src/functions/get-block-tag.js +6 -0
- package/src/functions/get-content.js +150 -0
- package/src/functions/get-content.test.js +58 -0
- package/src/functions/get-fetch.js +11 -0
- package/src/functions/get-global-this.js +17 -0
- package/src/functions/get-processed-block.js +51 -0
- package/src/functions/get-processed-block.test.js +31 -0
- package/src/functions/get-target.js +5 -0
- package/src/functions/if-target.js +5 -0
- package/src/functions/is-browser.js +10 -0
- package/src/functions/is-editing.js +8 -0
- package/src/functions/is-iframe.js +6 -0
- package/src/functions/is-previewing.js +13 -0
- package/src/functions/is-react-native.js +5 -0
- package/src/functions/macro-eval.js +3 -0
- package/src/functions/on-change.js +25 -0
- package/src/functions/on-change.test.js +21 -0
- package/src/functions/previewing-model-name.js +10 -0
- package/src/functions/register-component.js +65 -0
- package/src/functions/register.js +28 -0
- package/src/functions/set-editor-settings.js +14 -0
- package/src/functions/set.js +21 -0
- package/src/functions/set.test.js +18 -0
- package/src/functions/track.js +17 -0
- package/src/functions/transform-block.js +40 -0
- package/src/index.js +30 -0
- package/src/scripts/init-editing.js +95 -0
- package/src/types/builder-block.js +1 -0
- package/src/types/builder-content.js +1 -0
- package/src/types/deep-partial.js +1 -0
|
@@ -0,0 +1,150 @@
|
|
|
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) =>
|
|
9
|
+
key in obj
|
|
10
|
+
? __defProp(obj, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
writable: true,
|
|
14
|
+
value,
|
|
15
|
+
})
|
|
16
|
+
: (obj[key] = value);
|
|
17
|
+
var __spreadValues = (a, b) => {
|
|
18
|
+
for (var prop in b || (b = {}))
|
|
19
|
+
if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
20
|
+
if (__getOwnPropSymbols)
|
|
21
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
22
|
+
if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
23
|
+
}
|
|
24
|
+
return a;
|
|
25
|
+
};
|
|
26
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
27
|
+
var __async = (__this, __arguments, generator) => {
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
var fulfilled = (value) => {
|
|
30
|
+
try {
|
|
31
|
+
step(generator.next(value));
|
|
32
|
+
} catch (e) {
|
|
33
|
+
reject(e);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var rejected = (value) => {
|
|
37
|
+
try {
|
|
38
|
+
step(generator.throw(value));
|
|
39
|
+
} catch (e) {
|
|
40
|
+
reject(e);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
var step = (x) =>
|
|
44
|
+
x.done
|
|
45
|
+
? resolve(x.value)
|
|
46
|
+
: Promise.resolve(x.value).then(fulfilled, rejected);
|
|
47
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
import { getFetch } from './get-fetch';
|
|
51
|
+
const fetch = getFetch();
|
|
52
|
+
function flatten(object, path = null, separator = '.') {
|
|
53
|
+
return Object.keys(object).reduce((acc, key) => {
|
|
54
|
+
const value = object[key];
|
|
55
|
+
const newPath = [path, key].filter(Boolean).join(separator);
|
|
56
|
+
const isObject = [
|
|
57
|
+
typeof value === 'object',
|
|
58
|
+
value !== null,
|
|
59
|
+
!(Array.isArray(value) && value.length === 0),
|
|
60
|
+
].every(Boolean);
|
|
61
|
+
return isObject
|
|
62
|
+
? __spreadValues(
|
|
63
|
+
__spreadValues({}, acc),
|
|
64
|
+
flatten(value, newPath, separator)
|
|
65
|
+
)
|
|
66
|
+
: __spreadProps(__spreadValues({}, acc), { [newPath]: value });
|
|
67
|
+
}, {});
|
|
68
|
+
}
|
|
69
|
+
function getContent(options) {
|
|
70
|
+
return __async(this, null, function* () {
|
|
71
|
+
return (
|
|
72
|
+
(yield getAllContent(
|
|
73
|
+
__spreadProps(__spreadValues({}, options), { limit: 1 })
|
|
74
|
+
)).results[0] || null
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
function getAllContent(options) {
|
|
79
|
+
return __async(this, null, function* () {
|
|
80
|
+
const { model, apiKey } = options;
|
|
81
|
+
const { limit, testGroups, userAttributes, query } = __spreadValues(
|
|
82
|
+
{
|
|
83
|
+
limit: 1,
|
|
84
|
+
userAttributes: null,
|
|
85
|
+
testGroups: null,
|
|
86
|
+
},
|
|
87
|
+
options
|
|
88
|
+
);
|
|
89
|
+
const url = new URL(
|
|
90
|
+
`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}`
|
|
91
|
+
);
|
|
92
|
+
if (options.options) {
|
|
93
|
+
const flattened = flatten(options.options);
|
|
94
|
+
for (const key in flattened) {
|
|
95
|
+
url.searchParams.set(key, String(flattened[key]));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (userAttributes) {
|
|
99
|
+
url.searchParams.set('userAttributes', JSON.stringify(userAttributes));
|
|
100
|
+
}
|
|
101
|
+
if (query) {
|
|
102
|
+
const flattened = flatten({ query });
|
|
103
|
+
for (const key in flattened) {
|
|
104
|
+
url.searchParams.set(key, JSON.stringify(flattened[key]));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const content = yield fetch(url.href).then((res) => res.json());
|
|
108
|
+
if (testGroups) {
|
|
109
|
+
for (const item of content.results) {
|
|
110
|
+
if (item.variations && Object.keys(item.variations).length) {
|
|
111
|
+
const testGroup = testGroups[item.id];
|
|
112
|
+
const variationValue = item.variations[testGroup];
|
|
113
|
+
if (testGroup && variationValue) {
|
|
114
|
+
item.data = variationValue.data;
|
|
115
|
+
item.testVariationId = variationValue.id;
|
|
116
|
+
item.testVariationName = variationValue.name;
|
|
117
|
+
} else {
|
|
118
|
+
let n = 0;
|
|
119
|
+
const random = Math.random();
|
|
120
|
+
let set = false;
|
|
121
|
+
for (const id in item.variations) {
|
|
122
|
+
const variation = item.variations[id];
|
|
123
|
+
const testRatio = variation.testRatio;
|
|
124
|
+
n += testRatio;
|
|
125
|
+
if (random < n) {
|
|
126
|
+
const variationName =
|
|
127
|
+
variation.name ||
|
|
128
|
+
(variation.id === item.id ? 'Default variation' : '');
|
|
129
|
+
set = true;
|
|
130
|
+
Object.assign(item, {
|
|
131
|
+
data: variation.data,
|
|
132
|
+
testVariationId: variation.id,
|
|
133
|
+
testVariationName: variationName,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (!set) {
|
|
138
|
+
Object.assign(item, {
|
|
139
|
+
testVariationId: item.id,
|
|
140
|
+
testVariationName: 'Default',
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return content;
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
export { getAllContent, getContent };
|
|
@@ -0,0 +1,58 @@
|
|
|
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) =>
|
|
19
|
+
x.done
|
|
20
|
+
? resolve(x.value)
|
|
21
|
+
: Promise.resolve(x.value).then(fulfilled, rejected);
|
|
22
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
import fetchMock from 'jest-fetch-mock';
|
|
26
|
+
fetchMock.enableMocks();
|
|
27
|
+
import { test, beforeEach, expect } from '@jest/globals';
|
|
28
|
+
import { getContent } from './get-content';
|
|
29
|
+
const testKey = 'YJIGb4i01jvw0SRdL5Bt';
|
|
30
|
+
const testModel = 'page';
|
|
31
|
+
const testId = 'c1b81bab59704599b997574eb0736def';
|
|
32
|
+
beforeEach(() => {});
|
|
33
|
+
test.skip('Get content', () =>
|
|
34
|
+
__async(void 0, null, function* () {
|
|
35
|
+
var _a, _b;
|
|
36
|
+
expect(
|
|
37
|
+
(_a = yield getContent({
|
|
38
|
+
apiKey: testKey,
|
|
39
|
+
model: testModel,
|
|
40
|
+
query: {
|
|
41
|
+
id: testId,
|
|
42
|
+
},
|
|
43
|
+
})) == null
|
|
44
|
+
? void 0
|
|
45
|
+
: _a.id
|
|
46
|
+
).toEqual(testId);
|
|
47
|
+
expect(
|
|
48
|
+
(_b = yield getContent({
|
|
49
|
+
apiKey: testKey,
|
|
50
|
+
model: testModel,
|
|
51
|
+
userAttributes: {
|
|
52
|
+
urlPath: '/test-page',
|
|
53
|
+
},
|
|
54
|
+
})) == null
|
|
55
|
+
? void 0
|
|
56
|
+
: _b.id
|
|
57
|
+
).toEqual(testId);
|
|
58
|
+
}));
|
|
@@ -0,0 +1,11 @@
|
|
|
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 { getFetch };
|
|
@@ -0,0 +1,17 @@
|
|
|
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 { getGlobalThis };
|
|
@@ -0,0 +1,51 @@
|
|
|
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) =>
|
|
9
|
+
key in obj
|
|
10
|
+
? __defProp(obj, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
writable: true,
|
|
14
|
+
value,
|
|
15
|
+
})
|
|
16
|
+
: (obj[key] = value);
|
|
17
|
+
var __spreadValues = (a, b) => {
|
|
18
|
+
for (var prop in b || (b = {}))
|
|
19
|
+
if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
20
|
+
if (__getOwnPropSymbols)
|
|
21
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
22
|
+
if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
23
|
+
}
|
|
24
|
+
return a;
|
|
25
|
+
};
|
|
26
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
27
|
+
import { evaluate } from './evaluate';
|
|
28
|
+
import { set } from './set';
|
|
29
|
+
import { transformBlock } from './transform-block';
|
|
30
|
+
function getProcessedBlock(options) {
|
|
31
|
+
const { state, context } = options;
|
|
32
|
+
const block = transformBlock(options.block);
|
|
33
|
+
if (!block.bindings) {
|
|
34
|
+
return block;
|
|
35
|
+
}
|
|
36
|
+
const copied = __spreadProps(__spreadValues({}, block), {
|
|
37
|
+
properties: __spreadValues({}, block.properties),
|
|
38
|
+
actions: __spreadValues({}, block.actions),
|
|
39
|
+
});
|
|
40
|
+
for (const binding in block.bindings) {
|
|
41
|
+
const expression = block.bindings[binding];
|
|
42
|
+
const value = evaluate({
|
|
43
|
+
code: expression,
|
|
44
|
+
state,
|
|
45
|
+
context,
|
|
46
|
+
});
|
|
47
|
+
set(copied, binding, value);
|
|
48
|
+
}
|
|
49
|
+
return copied;
|
|
50
|
+
}
|
|
51
|
+
export { getProcessedBlock };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { expect, test } from '@jest/globals';
|
|
3
|
+
import { getProcessedBlock } from './get-processed-block';
|
|
4
|
+
test('Can process bindings', () => {
|
|
5
|
+
const block = {
|
|
6
|
+
properties: {
|
|
7
|
+
foo: 'bar',
|
|
8
|
+
},
|
|
9
|
+
bindings: {
|
|
10
|
+
'properties.foo': '"baz"',
|
|
11
|
+
'responsiveStyles.large.zIndex': '1 + 1',
|
|
12
|
+
'properties.test': 'state.test',
|
|
13
|
+
'properties.block': `
|
|
14
|
+
const foo = 'bar';
|
|
15
|
+
return foo;
|
|
16
|
+
`,
|
|
17
|
+
'properties.isEditing': 'builder.isEditing',
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
const processed = getProcessedBlock({
|
|
21
|
+
block,
|
|
22
|
+
context: {},
|
|
23
|
+
state: { test: 'hello' },
|
|
24
|
+
});
|
|
25
|
+
expect(processed).not.toEqual(block);
|
|
26
|
+
expect(processed.properties.foo).toEqual('baz');
|
|
27
|
+
expect(processed.properties.test).toEqual('hello');
|
|
28
|
+
expect(processed.properties.block).toEqual('bar');
|
|
29
|
+
expect(processed.properties.isEditing).toEqual(false);
|
|
30
|
+
expect(processed.responsiveStyles.large.zIndex).toEqual(2);
|
|
31
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
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 { isPreviewing };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
const onChangeProxySymbol = Symbol('onChangeProxySymbol');
|
|
3
|
+
function onChange(obj, cb) {
|
|
4
|
+
return new Proxy(obj, {
|
|
5
|
+
get(target, key) {
|
|
6
|
+
if (key === onChangeProxySymbol) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
const value = Reflect.get(target, key);
|
|
10
|
+
if (value && typeof value === 'object') {
|
|
11
|
+
if (value[onChangeProxySymbol]) {
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
return onChange(value, cb);
|
|
15
|
+
}
|
|
16
|
+
return value;
|
|
17
|
+
},
|
|
18
|
+
set(target, key, value) {
|
|
19
|
+
const returnValue = Reflect.set(target, key, value);
|
|
20
|
+
cb();
|
|
21
|
+
return returnValue;
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
export { onChange, onChangeProxySymbol };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { expect, test } from '@jest/globals';
|
|
3
|
+
import { onChange } from './on-change';
|
|
4
|
+
test('onChange can observe a shallow change', () => {
|
|
5
|
+
let changeHappend = false;
|
|
6
|
+
const obj = onChange({ foo: 'hi' }, () => (changeHappend = true));
|
|
7
|
+
obj.foo = 'yo';
|
|
8
|
+
expect(changeHappend).toBe(true);
|
|
9
|
+
});
|
|
10
|
+
test('onChange can observe a deep change', () => {
|
|
11
|
+
let changeHappend = false;
|
|
12
|
+
const obj = onChange({ foo: { bar: 'hi' } }, () => (changeHappend = true));
|
|
13
|
+
obj.foo.bar = 'yo';
|
|
14
|
+
expect(changeHappend).toBe(true);
|
|
15
|
+
});
|
|
16
|
+
test('Smoke test: callback is not fired if no properties updated', () => {
|
|
17
|
+
let changeHappend = false;
|
|
18
|
+
const obj = onChange({ foo: { bar: 'hi' } }, () => (changeHappend = true));
|
|
19
|
+
obj.foo.bar;
|
|
20
|
+
expect(changeHappend).toBe(false);
|
|
21
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
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 { previewingModelName };
|
|
@@ -0,0 +1,65 @@
|
|
|
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) =>
|
|
9
|
+
key in obj
|
|
10
|
+
? __defProp(obj, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
writable: true,
|
|
14
|
+
value,
|
|
15
|
+
})
|
|
16
|
+
: (obj[key] = value);
|
|
17
|
+
var __spreadValues = (a, b) => {
|
|
18
|
+
for (var prop in b || (b = {}))
|
|
19
|
+
if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
20
|
+
if (__getOwnPropSymbols)
|
|
21
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
22
|
+
if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
23
|
+
}
|
|
24
|
+
return a;
|
|
25
|
+
};
|
|
26
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
27
|
+
import { isBrowser } from './is-browser';
|
|
28
|
+
const components = {};
|
|
29
|
+
function registerComponent(component, info) {
|
|
30
|
+
var _a;
|
|
31
|
+
components[info.name] = { component, info };
|
|
32
|
+
if (isBrowser()) {
|
|
33
|
+
const sendInfo = prepareComponentInfoToSend(info);
|
|
34
|
+
(_a = window.parent) == null
|
|
35
|
+
? void 0
|
|
36
|
+
: _a.postMessage(
|
|
37
|
+
{
|
|
38
|
+
type: 'builder.registerComponent',
|
|
39
|
+
data: sendInfo,
|
|
40
|
+
},
|
|
41
|
+
'*'
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
return component;
|
|
45
|
+
}
|
|
46
|
+
function prepareComponentInfoToSend(info) {
|
|
47
|
+
return __spreadValues(
|
|
48
|
+
__spreadValues({}, info),
|
|
49
|
+
info.inputs && {
|
|
50
|
+
inputs: info.inputs.map((input) => {
|
|
51
|
+
const keysToConvertFnToString = ['onChange', 'showIf'];
|
|
52
|
+
for (const key of keysToConvertFnToString) {
|
|
53
|
+
if (input[key] && typeof input[key] === 'function') {
|
|
54
|
+
const fn = input[key];
|
|
55
|
+
input = __spreadProps(__spreadValues({}, input), {
|
|
56
|
+
[key]: `return (${fn.toString()}).apply(this, arguments)`,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return input;
|
|
61
|
+
}),
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
export { components, registerComponent };
|
|
@@ -0,0 +1,28 @@
|
|
|
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 { register };
|
|
@@ -0,0 +1,14 @@
|
|
|
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 { setEditorSettings };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
const set = (obj, _path, value) => {
|
|
3
|
+
if (Object(obj) !== obj) {
|
|
4
|
+
return obj;
|
|
5
|
+
}
|
|
6
|
+
const path = Array.isArray(_path)
|
|
7
|
+
? _path
|
|
8
|
+
: _path.toString().match(/[^.[\]]+/g);
|
|
9
|
+
path
|
|
10
|
+
.slice(0, -1)
|
|
11
|
+
.reduce(
|
|
12
|
+
(a, c, i) =>
|
|
13
|
+
Object(a[c]) === a[c]
|
|
14
|
+
? a[c]
|
|
15
|
+
: (a[c] =
|
|
16
|
+
Math.abs(Number(path[i + 1])) >> 0 === +path[i + 1] ? [] : {}),
|
|
17
|
+
obj
|
|
18
|
+
)[path[path.length - 1]] = value;
|
|
19
|
+
return obj;
|
|
20
|
+
};
|
|
21
|
+
export { set };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { expect, test } from '@jest/globals';
|
|
3
|
+
import { set } from './set';
|
|
4
|
+
test('can shallow set a property', () => {
|
|
5
|
+
const obj = { foo: 'bar' };
|
|
6
|
+
set(obj, 'foo', 'baz');
|
|
7
|
+
expect(obj.foo).toBe('baz');
|
|
8
|
+
});
|
|
9
|
+
test('can deeply set a property', () => {
|
|
10
|
+
const obj = { foo: 'bar' };
|
|
11
|
+
set(obj, 'foo.bar', 'baz');
|
|
12
|
+
expect(obj.foo.bar).toBe('baz');
|
|
13
|
+
});
|
|
14
|
+
test('can deeply create arrays', () => {
|
|
15
|
+
const obj = { foo: 'bar' };
|
|
16
|
+
set(obj, 'foo.bar.0', 'hi');
|
|
17
|
+
expect(obj.foo.bar).toEqual(['hi']);
|
|
18
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { isBrowser } from './is-browser';
|
|
3
|
+
import { isReactNative } from './is-react-native';
|
|
4
|
+
function track(event, properties) {
|
|
5
|
+
if (!isBrowser() || isReactNative()) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
return fetch(`https://builder.io/api/v1/track`, {
|
|
9
|
+
method: 'POST',
|
|
10
|
+
body: JSON.stringify({ events: [{ type: event, data: properties }] }),
|
|
11
|
+
headers: {
|
|
12
|
+
'content-type': 'application/json',
|
|
13
|
+
},
|
|
14
|
+
mode: 'cors',
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
export { track };
|
|
@@ -0,0 +1,40 @@
|
|
|
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) =>
|
|
9
|
+
key in obj
|
|
10
|
+
? __defProp(obj, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
writable: true,
|
|
14
|
+
value,
|
|
15
|
+
})
|
|
16
|
+
: (obj[key] = value);
|
|
17
|
+
var __spreadValues = (a, b) => {
|
|
18
|
+
for (var prop in b || (b = {}))
|
|
19
|
+
if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
20
|
+
if (__getOwnPropSymbols)
|
|
21
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
22
|
+
if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
23
|
+
}
|
|
24
|
+
return a;
|
|
25
|
+
};
|
|
26
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
27
|
+
function transformBlock(block) {
|
|
28
|
+
if (block.id.startsWith('builder-pixel-')) {
|
|
29
|
+
return __spreadProps(__spreadValues({}, block), {
|
|
30
|
+
component: {
|
|
31
|
+
name: 'Image',
|
|
32
|
+
options: {
|
|
33
|
+
image: block.properties.src,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return block;
|
|
39
|
+
}
|
|
40
|
+
export { transformBlock };
|