@builder.io/sdk-react 0.0.1-6 → 0.0.1
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 +2 -1
- package/src/blocks/BaseText.jsx +12 -0
- package/src/blocks/button/{button.js → button.jsx} +3 -3
- package/src/blocks/columns/{columns.js → columns.jsx} +17 -11
- package/src/blocks/custom-code/{custom-code.js → custom-code.jsx} +1 -1
- package/src/blocks/embed/{embed.js → embed.jsx} +2 -0
- package/src/blocks/form/{form.js → form.jsx} +4 -4
- package/src/blocks/fragment/{fragment.js → fragment.jsx} +0 -0
- package/src/blocks/image/{image.js → image.jsx} +12 -15
- package/src/blocks/img/{img.js → img.jsx} +0 -0
- package/src/blocks/input/{input.js → input.jsx} +0 -0
- package/src/blocks/raw-text/{raw-text.js → raw-text.jsx} +0 -0
- package/src/blocks/section/{section.js → section.jsx} +0 -0
- package/src/blocks/select/{select.js → select.jsx} +0 -0
- package/src/blocks/submit-button/{submit-button.js → submit-button.jsx} +0 -0
- package/src/blocks/symbol/{symbol.js → symbol.jsx} +15 -19
- package/src/blocks/text/{text.js → text.jsx} +1 -1
- package/src/blocks/textarea/{textarea.js → textarea.jsx} +0 -0
- package/src/blocks/video/{video.js → video.jsx} +4 -1
- package/src/components/render-block/{block-styles.js → block-styles.jsx} +19 -12
- package/src/components/render-block/{render-block.js → render-block.jsx} +60 -37
- package/src/components/render-block/render-component-with-context.jsx +35 -0
- package/src/components/render-block/{render-component.js → render-component.jsx} +4 -3
- package/src/components/render-block/{render-repeated-block.js → render-repeated-block.jsx} +4 -1
- package/src/components/{render-blocks.js → render-blocks.jsx} +5 -4
- package/src/components/render-content/components/{render-styles.js → render-styles.jsx} +1 -1
- package/src/components/render-content/index.js +1 -1
- package/src/components/render-content/{render-content.js → render-content.jsx} +25 -35
- package/src/components/{render-inlined-styles.js → render-inlined-styles.jsx} +0 -0
- package/src/constants/builder-registered-components.js +14 -11
- package/src/context/builder.context.js +2 -1
- package/src/context/types.js +0 -0
- package/src/functions/evaluate.js +1 -1
- package/src/functions/extract-text-styles.js +22 -0
- package/src/functions/fast-clone.js +4 -0
- package/src/functions/get-block-actions-handler.js +12 -0
- package/src/functions/get-block-actions.js +2 -7
- package/src/functions/get-builder-search-params/index.js +6 -2
- package/src/functions/get-content/ab-testing.js +91 -30
- package/src/functions/get-content/index.js +5 -5
- package/src/functions/get-processed-block.js +5 -3
- package/src/functions/get-react-native-block-styles.js +32 -0
- package/src/functions/mark-mutable.js +10 -0
- package/src/functions/register-component.js +1 -1
- package/src/functions/sanitize-react-native-block-styles.js +66 -0
- package/src/functions/track.js +9 -7
- package/src/helpers/ab-tests.js +16 -0
- package/src/helpers/cookie.js +26 -6
- package/src/helpers/css.js +17 -1
- package/src/helpers/sessionId.js +26 -3
- package/src/index-helpers/blocks-exports.js +10 -10
- package/src/scripts/init-editing.js +36 -34
- package/src/functions/convert-style-object.js +0 -6
- package/src/functions/get-block-styles.js +0 -34
- package/src/functions/sanitize-styles.js +0 -5
package/src/functions/track.js
CHANGED
|
@@ -54,18 +54,20 @@ import { getSessionId } from "../helpers/sessionId.js";
|
|
|
54
54
|
import { getVisitorId } from "../helpers/visitorId.js";
|
|
55
55
|
import { isBrowser } from "./is-browser.js";
|
|
56
56
|
import { isEditing } from "./is-editing.js";
|
|
57
|
-
const getTrackingEventData = (
|
|
57
|
+
const getTrackingEventData = (_0) => __async(void 0, [_0], function* ({
|
|
58
|
+
canTrack
|
|
59
|
+
}) {
|
|
58
60
|
if (!canTrack) {
|
|
59
61
|
return { visitorId: void 0, sessionId: void 0 };
|
|
60
62
|
}
|
|
61
|
-
const sessionId = getSessionId({ canTrack });
|
|
63
|
+
const sessionId = yield getSessionId({ canTrack });
|
|
62
64
|
const visitorId = getVisitorId({ canTrack });
|
|
63
65
|
return {
|
|
64
66
|
sessionId,
|
|
65
67
|
visitorId
|
|
66
68
|
};
|
|
67
|
-
};
|
|
68
|
-
const createEvent = (_a) => {
|
|
69
|
+
});
|
|
70
|
+
const createEvent = (_a) => __async(void 0, null, function* () {
|
|
69
71
|
var _b = _a, {
|
|
70
72
|
type: eventType,
|
|
71
73
|
canTrack,
|
|
@@ -79,12 +81,12 @@ const createEvent = (_a) => {
|
|
|
79
81
|
]);
|
|
80
82
|
return {
|
|
81
83
|
type: eventType,
|
|
82
|
-
data: __spreadProps(__spreadValues(__spreadValues({}, properties), getTrackingEventData({ canTrack })), {
|
|
84
|
+
data: __spreadProps(__spreadValues(__spreadValues({}, properties), yield getTrackingEventData({ canTrack })), {
|
|
83
85
|
ownerId: orgId,
|
|
84
86
|
contentId
|
|
85
87
|
})
|
|
86
88
|
};
|
|
87
|
-
};
|
|
89
|
+
});
|
|
88
90
|
function track(eventProps) {
|
|
89
91
|
return __async(this, null, function* () {
|
|
90
92
|
if (!eventProps.canTrack) {
|
|
@@ -99,7 +101,7 @@ function track(eventProps) {
|
|
|
99
101
|
return fetch(`https://builder.io/api/v1/track`, {
|
|
100
102
|
method: "POST",
|
|
101
103
|
body: JSON.stringify({
|
|
102
|
-
events: [createEvent(eventProps)]
|
|
104
|
+
events: [yield createEvent(eventProps)]
|
|
103
105
|
}),
|
|
104
106
|
headers: {
|
|
105
107
|
"content-type": "application/json"
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { getCookie, setCookie } from "./cookie.js";
|
|
2
|
+
const BUILDER_STORE_PREFIX = "builderio.variations";
|
|
3
|
+
const getContentTestKey = (id) => `${BUILDER_STORE_PREFIX}.${id}`;
|
|
4
|
+
const getContentVariationCookie = ({
|
|
5
|
+
contentId,
|
|
6
|
+
canTrack
|
|
7
|
+
}) => getCookie({ name: getContentTestKey(contentId), canTrack });
|
|
8
|
+
const setContentVariationCookie = ({
|
|
9
|
+
contentId,
|
|
10
|
+
canTrack,
|
|
11
|
+
value
|
|
12
|
+
}) => setCookie({ name: getContentTestKey(contentId), value, canTrack });
|
|
13
|
+
export {
|
|
14
|
+
getContentVariationCookie,
|
|
15
|
+
setContentVariationCookie
|
|
16
|
+
};
|
package/src/helpers/cookie.js
CHANGED
|
@@ -1,9 +1,29 @@
|
|
|
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
|
+
};
|
|
1
21
|
import { isBrowser } from "../functions/is-browser.js";
|
|
2
22
|
import { getTopLevelDomain } from "./url.js";
|
|
3
|
-
const getCookie = ({
|
|
23
|
+
const getCookie = (_0) => __async(void 0, [_0], function* ({
|
|
4
24
|
name,
|
|
5
25
|
canTrack
|
|
6
|
-
})
|
|
26
|
+
}) {
|
|
7
27
|
var _a;
|
|
8
28
|
try {
|
|
9
29
|
if (!canTrack) {
|
|
@@ -13,7 +33,7 @@ const getCookie = ({
|
|
|
13
33
|
} catch (err) {
|
|
14
34
|
console.debug("[COOKIE] GET error: ", err);
|
|
15
35
|
}
|
|
16
|
-
};
|
|
36
|
+
});
|
|
17
37
|
const stringifyCookie = (cookie) => cookie.map(([key, value]) => value ? `${key}=${value}` : key).join("; ");
|
|
18
38
|
const SECURE_CONFIG = [
|
|
19
39
|
["secure", ""],
|
|
@@ -37,12 +57,12 @@ const createCookieString = ({
|
|
|
37
57
|
const cookie = stringifyCookie(cookieValue);
|
|
38
58
|
return cookie;
|
|
39
59
|
};
|
|
40
|
-
const setCookie = ({
|
|
60
|
+
const setCookie = (_0) => __async(void 0, [_0], function* ({
|
|
41
61
|
name,
|
|
42
62
|
value,
|
|
43
63
|
expires,
|
|
44
64
|
canTrack
|
|
45
|
-
})
|
|
65
|
+
}) {
|
|
46
66
|
try {
|
|
47
67
|
if (!canTrack) {
|
|
48
68
|
return void 0;
|
|
@@ -52,7 +72,7 @@ const setCookie = ({
|
|
|
52
72
|
} catch (err) {
|
|
53
73
|
console.warn("[COOKIE] SET error: ", err);
|
|
54
74
|
}
|
|
55
|
-
};
|
|
75
|
+
});
|
|
56
76
|
export {
|
|
57
77
|
getCookie,
|
|
58
78
|
setCookie
|
package/src/helpers/css.js
CHANGED
|
@@ -7,6 +7,22 @@ const convertStyleMaptoCSS = (style) => {
|
|
|
7
7
|
});
|
|
8
8
|
return cssProps.join("\n");
|
|
9
9
|
};
|
|
10
|
+
const createCssClass = ({
|
|
11
|
+
mediaQuery,
|
|
12
|
+
className,
|
|
13
|
+
styles
|
|
14
|
+
}) => {
|
|
15
|
+
const cssClass = `.${className} {
|
|
16
|
+
${convertStyleMaptoCSS(styles)}
|
|
17
|
+
}`;
|
|
18
|
+
if (mediaQuery) {
|
|
19
|
+
return `${mediaQuery} {
|
|
20
|
+
${cssClass}
|
|
21
|
+
}`;
|
|
22
|
+
} else {
|
|
23
|
+
return cssClass;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
10
26
|
export {
|
|
11
|
-
|
|
27
|
+
createCssClass
|
|
12
28
|
};
|
package/src/helpers/sessionId.js
CHANGED
|
@@ -1,19 +1,42 @@
|
|
|
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
|
+
};
|
|
1
21
|
import { getCookie, setCookie } from "./cookie.js";
|
|
2
22
|
import { checkIsDefined } from "./nullable.js";
|
|
3
23
|
import { uuid } from "./uuid.js";
|
|
4
24
|
const SESSION_LOCAL_STORAGE_KEY = "builderSessionId";
|
|
5
|
-
const getSessionId = ({ canTrack })
|
|
25
|
+
const getSessionId = (_0) => __async(void 0, [_0], function* ({ canTrack }) {
|
|
6
26
|
if (!canTrack) {
|
|
7
27
|
return void 0;
|
|
8
28
|
}
|
|
9
|
-
const sessionId = getCookie({
|
|
29
|
+
const sessionId = yield getCookie({
|
|
30
|
+
name: SESSION_LOCAL_STORAGE_KEY,
|
|
31
|
+
canTrack
|
|
32
|
+
});
|
|
10
33
|
if (checkIsDefined(sessionId)) {
|
|
11
34
|
return sessionId;
|
|
12
35
|
} else {
|
|
13
36
|
const newSessionId = createSessionId();
|
|
14
37
|
setSessionId({ id: newSessionId, canTrack });
|
|
15
38
|
}
|
|
16
|
-
};
|
|
39
|
+
});
|
|
17
40
|
const createSessionId = () => uuid();
|
|
18
41
|
const setSessionId = ({
|
|
19
42
|
id,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { default as default2 } from "../blocks/columns/columns.
|
|
2
|
-
import { default as default3 } from "../blocks/image/image.
|
|
3
|
-
import { default as default4 } from "../blocks/text/text.
|
|
4
|
-
import { default as default5 } from "../blocks/video/video.
|
|
5
|
-
import { default as default6 } from "../blocks/symbol/symbol.
|
|
6
|
-
import { default as default7 } from "../blocks/button/button.
|
|
7
|
-
import { default as default8 } from "../blocks/section/section.
|
|
8
|
-
import { default as default9 } from "../blocks/fragment/fragment.
|
|
9
|
-
import { default as default10 } from "../components/render-content/render-content.
|
|
10
|
-
import { default as default11 } from "../components/render-blocks.
|
|
1
|
+
import { default as default2 } from "../blocks/columns/columns.jsx";
|
|
2
|
+
import { default as default3 } from "../blocks/image/image.jsx";
|
|
3
|
+
import { default as default4 } from "../blocks/text/text.jsx";
|
|
4
|
+
import { default as default5 } from "../blocks/video/video.jsx";
|
|
5
|
+
import { default as default6 } from "../blocks/symbol/symbol.jsx";
|
|
6
|
+
import { default as default7 } from "../blocks/button/button.jsx";
|
|
7
|
+
import { default as default8 } from "../blocks/section/section.jsx";
|
|
8
|
+
import { default as default9 } from "../blocks/fragment/fragment.jsx";
|
|
9
|
+
import { default as default10 } from "../components/render-content/render-content.jsx";
|
|
10
|
+
import { default as default11 } from "../components/render-blocks.jsx";
|
|
11
11
|
export {
|
|
12
12
|
default7 as Button,
|
|
13
13
|
default2 as Columns,
|
|
@@ -26,48 +26,50 @@ const setupBrowserForEditing = () => {
|
|
|
26
26
|
type: "builder.sdkInfo",
|
|
27
27
|
data: {
|
|
28
28
|
target: TARGET,
|
|
29
|
-
supportsPatchUpdates: false
|
|
29
|
+
supportsPatchUpdates: false,
|
|
30
|
+
supportsAddBlockScoping: true
|
|
30
31
|
}
|
|
31
32
|
}, "*");
|
|
32
33
|
window.addEventListener("message", ({ data }) => {
|
|
33
34
|
var _a2, _b;
|
|
34
|
-
if (data) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}, "*");
|
|
61
|
-
}).catch(console.error);
|
|
62
|
-
} else {
|
|
63
|
-
(_b = window.parent) == null ? void 0 : _b.postMessage({
|
|
35
|
+
if (!(data == null ? void 0 : data.type)) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
switch (data.type) {
|
|
39
|
+
case "builder.evaluate": {
|
|
40
|
+
const text = data.data.text;
|
|
41
|
+
const args = data.data.arguments || [];
|
|
42
|
+
const id = data.data.id;
|
|
43
|
+
const fn = new Function(text);
|
|
44
|
+
let result;
|
|
45
|
+
let error = null;
|
|
46
|
+
try {
|
|
47
|
+
result = fn.apply(null, args);
|
|
48
|
+
} catch (err) {
|
|
49
|
+
error = err;
|
|
50
|
+
}
|
|
51
|
+
if (error) {
|
|
52
|
+
(_a2 = window.parent) == null ? void 0 : _a2.postMessage({
|
|
53
|
+
type: "builder.evaluateError",
|
|
54
|
+
data: { id, error: error.message }
|
|
55
|
+
}, "*");
|
|
56
|
+
} else {
|
|
57
|
+
if (result && typeof result.then === "function") {
|
|
58
|
+
result.then((finalResult) => {
|
|
59
|
+
var _a3;
|
|
60
|
+
(_a3 = window.parent) == null ? void 0 : _a3.postMessage({
|
|
64
61
|
type: "builder.evaluateResult",
|
|
65
|
-
data: {
|
|
62
|
+
data: { id, result: finalResult }
|
|
66
63
|
}, "*");
|
|
67
|
-
}
|
|
64
|
+
}).catch(console.error);
|
|
65
|
+
} else {
|
|
66
|
+
(_b = window.parent) == null ? void 0 : _b.postMessage({
|
|
67
|
+
type: "builder.evaluateResult",
|
|
68
|
+
data: { result, id }
|
|
69
|
+
}, "*");
|
|
68
70
|
}
|
|
69
|
-
break;
|
|
70
71
|
}
|
|
72
|
+
break;
|
|
71
73
|
}
|
|
72
74
|
}
|
|
73
75
|
});
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
-
var __spreadValues = (a, b) => {
|
|
7
|
-
for (var prop in b || (b = {}))
|
|
8
|
-
if (__hasOwnProp.call(b, prop))
|
|
9
|
-
__defNormalProp(a, prop, b[prop]);
|
|
10
|
-
if (__getOwnPropSymbols)
|
|
11
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
-
if (__propIsEnum.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
}
|
|
15
|
-
return a;
|
|
16
|
-
};
|
|
17
|
-
import { getMaxWidthQueryForSize } from "../constants/device-sizes.js";
|
|
18
|
-
import { convertStyleObject } from "./convert-style-object.js";
|
|
19
|
-
import { sanitizeBlockStyles } from "./sanitize-styles.js";
|
|
20
|
-
function getBlockStyles(block) {
|
|
21
|
-
var _a, _b, _c, _d, _e;
|
|
22
|
-
const styles = __spreadValues(__spreadValues({}, convertStyleObject((_a = block.responsiveStyles) == null ? void 0 : _a.large)), block.styles);
|
|
23
|
-
if ((_b = block.responsiveStyles) == null ? void 0 : _b.medium) {
|
|
24
|
-
styles[getMaxWidthQueryForSize("medium")] = convertStyleObject((_c = block.responsiveStyles) == null ? void 0 : _c.medium);
|
|
25
|
-
}
|
|
26
|
-
if ((_d = block.responsiveStyles) == null ? void 0 : _d.small) {
|
|
27
|
-
styles[getMaxWidthQueryForSize("small")] = convertStyleObject((_e = block.responsiveStyles) == null ? void 0 : _e.small);
|
|
28
|
-
}
|
|
29
|
-
sanitizeBlockStyles(styles);
|
|
30
|
-
return styles;
|
|
31
|
-
}
|
|
32
|
-
export {
|
|
33
|
-
getBlockStyles
|
|
34
|
-
};
|