@builder.io/sdk-react 0.0.1-5 → 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.
Files changed (55) hide show
  1. package/package.json +2 -1
  2. package/src/blocks/BaseText.jsx +12 -0
  3. package/src/blocks/button/{button.js → button.jsx} +3 -3
  4. package/src/blocks/columns/{columns.js → columns.jsx} +17 -11
  5. package/src/blocks/custom-code/{custom-code.js → custom-code.jsx} +1 -1
  6. package/src/blocks/embed/{embed.js → embed.jsx} +2 -0
  7. package/src/blocks/form/{form.js → form.jsx} +4 -4
  8. package/src/blocks/fragment/{fragment.js → fragment.jsx} +0 -0
  9. package/src/blocks/image/{image.js → image.jsx} +12 -15
  10. package/src/blocks/img/{img.js → img.jsx} +0 -0
  11. package/src/blocks/input/{input.js → input.jsx} +0 -0
  12. package/src/blocks/raw-text/{raw-text.js → raw-text.jsx} +0 -0
  13. package/src/blocks/section/{section.js → section.jsx} +0 -0
  14. package/src/blocks/select/{select.js → select.jsx} +0 -0
  15. package/src/blocks/submit-button/{submit-button.js → submit-button.jsx} +0 -0
  16. package/src/blocks/symbol/{symbol.js → symbol.jsx} +15 -19
  17. package/src/blocks/text/{text.js → text.jsx} +1 -1
  18. package/src/blocks/textarea/{textarea.js → textarea.jsx} +0 -0
  19. package/src/blocks/video/{video.js → video.jsx} +4 -1
  20. package/src/components/render-block/{block-styles.js → block-styles.jsx} +19 -12
  21. package/src/components/render-block/{render-block.js → render-block.jsx} +60 -37
  22. package/src/components/render-block/render-component-with-context.jsx +35 -0
  23. package/src/components/render-block/{render-component.js → render-component.jsx} +4 -3
  24. package/src/components/render-block/{render-repeated-block.js → render-repeated-block.jsx} +4 -1
  25. package/src/components/{render-blocks.js → render-blocks.jsx} +5 -4
  26. package/src/components/render-content/components/{render-styles.js → render-styles.jsx} +1 -1
  27. package/src/components/render-content/index.js +1 -1
  28. package/src/components/render-content/{render-content.js → render-content.jsx} +25 -35
  29. package/src/components/{render-inlined-styles.js → render-inlined-styles.jsx} +0 -0
  30. package/src/constants/builder-registered-components.js +14 -11
  31. package/src/context/builder.context.js +2 -1
  32. package/src/context/types.js +0 -0
  33. package/src/functions/evaluate.js +1 -1
  34. package/src/functions/extract-text-styles.js +22 -0
  35. package/src/functions/fast-clone.js +4 -0
  36. package/src/functions/get-block-actions-handler.js +12 -0
  37. package/src/functions/get-block-actions.js +2 -7
  38. package/src/functions/get-builder-search-params/index.js +6 -2
  39. package/src/functions/get-content/ab-testing.js +91 -30
  40. package/src/functions/get-content/index.js +5 -5
  41. package/src/functions/get-processed-block.js +5 -3
  42. package/src/functions/get-react-native-block-styles.js +32 -0
  43. package/src/functions/mark-mutable.js +10 -0
  44. package/src/functions/register-component.js +1 -1
  45. package/src/functions/sanitize-react-native-block-styles.js +66 -0
  46. package/src/functions/track.js +50 -24
  47. package/src/helpers/ab-tests.js +16 -0
  48. package/src/helpers/cookie.js +26 -6
  49. package/src/helpers/css.js +17 -1
  50. package/src/helpers/sessionId.js +26 -3
  51. package/src/index-helpers/blocks-exports.js +10 -10
  52. package/src/scripts/init-editing.js +36 -34
  53. package/src/functions/convert-style-object.js +0 -6
  54. package/src/functions/get-block-styles.js +0 -34
  55. package/src/functions/sanitize-styles.js +0 -5
@@ -29,23 +29,45 @@ var __objRest = (source, exclude) => {
29
29
  }
30
30
  return target;
31
31
  };
32
+ var __async = (__this, __arguments, generator) => {
33
+ return new Promise((resolve, reject) => {
34
+ var fulfilled = (value) => {
35
+ try {
36
+ step(generator.next(value));
37
+ } catch (e) {
38
+ reject(e);
39
+ }
40
+ };
41
+ var rejected = (value) => {
42
+ try {
43
+ step(generator.throw(value));
44
+ } catch (e) {
45
+ reject(e);
46
+ }
47
+ };
48
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
49
+ step((generator = generator.apply(__this, __arguments)).next());
50
+ });
51
+ };
32
52
  import { TARGET } from "../constants/target.js";
33
53
  import { getSessionId } from "../helpers/sessionId.js";
34
54
  import { getVisitorId } from "../helpers/visitorId.js";
35
55
  import { isBrowser } from "./is-browser.js";
36
56
  import { isEditing } from "./is-editing.js";
37
- const getTrackingEventData = ({ canTrack }) => {
57
+ const getTrackingEventData = (_0) => __async(void 0, [_0], function* ({
58
+ canTrack
59
+ }) {
38
60
  if (!canTrack) {
39
61
  return { visitorId: void 0, sessionId: void 0 };
40
62
  }
41
- const sessionId = getSessionId({ canTrack });
63
+ const sessionId = yield getSessionId({ canTrack });
42
64
  const visitorId = getVisitorId({ canTrack });
43
65
  return {
44
66
  sessionId,
45
67
  visitorId
46
68
  };
47
- };
48
- const createEvent = (_a) => {
69
+ });
70
+ const createEvent = (_a) => __async(void 0, null, function* () {
49
71
  var _b = _a, {
50
72
  type: eventType,
51
73
  canTrack,
@@ -59,31 +81,35 @@ const createEvent = (_a) => {
59
81
  ]);
60
82
  return {
61
83
  type: eventType,
62
- data: __spreadProps(__spreadValues(__spreadValues({}, properties), getTrackingEventData({ canTrack })), {
84
+ data: __spreadProps(__spreadValues(__spreadValues({}, properties), yield getTrackingEventData({ canTrack })), {
63
85
  ownerId: orgId,
64
86
  contentId
65
87
  })
66
88
  };
67
- };
89
+ });
68
90
  function track(eventProps) {
69
- if (!eventProps.canTrack) {
70
- return;
71
- }
72
- if (isEditing()) {
73
- return;
74
- }
75
- if (!(isBrowser() || TARGET === "reactNative")) {
76
- return;
77
- }
78
- return fetch(`https://builder.io/api/v1/track`, {
79
- method: "POST",
80
- body: JSON.stringify({
81
- events: [createEvent(eventProps)]
82
- }),
83
- headers: {
84
- "content-type": "application/json"
85
- },
86
- mode: "cors"
91
+ return __async(this, null, function* () {
92
+ if (!eventProps.canTrack) {
93
+ return;
94
+ }
95
+ if (isEditing()) {
96
+ return;
97
+ }
98
+ if (!(isBrowser() || TARGET === "reactNative")) {
99
+ return;
100
+ }
101
+ return fetch(`https://builder.io/api/v1/track`, {
102
+ method: "POST",
103
+ body: JSON.stringify({
104
+ events: [yield createEvent(eventProps)]
105
+ }),
106
+ headers: {
107
+ "content-type": "application/json"
108
+ },
109
+ mode: "cors"
110
+ }).catch((err) => {
111
+ console.error("Failed to track: ", err);
112
+ });
87
113
  });
88
114
  }
89
115
  export {
@@ -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
+ };
@@ -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
@@ -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
- convertStyleMaptoCSS
27
+ createCssClass
12
28
  };
@@ -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({ name: SESSION_LOCAL_STORAGE_KEY, canTrack });
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.js";
2
- import { default as default3 } from "../blocks/image/image.js";
3
- import { default as default4 } from "../blocks/text/text.js";
4
- import { default as default5 } from "../blocks/video/video.js";
5
- import { default as default6 } from "../blocks/symbol/symbol.js";
6
- import { default as default7 } from "../blocks/button/button.js";
7
- import { default as default8 } from "../blocks/section/section.js";
8
- import { default as default9 } from "../blocks/fragment/fragment.js";
9
- import { default as default10 } from "../components/render-content/render-content.js";
10
- import { default as default11 } from "../components/render-blocks.js";
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
- switch (data.type) {
36
- case "builder.evaluate": {
37
- const text = data.data.text;
38
- const args = data.data.arguments || [];
39
- const id = data.data.id;
40
- const fn = new Function(text);
41
- let result;
42
- let error = null;
43
- try {
44
- result = fn.apply(null, args);
45
- } catch (err) {
46
- error = err;
47
- }
48
- if (error) {
49
- (_a2 = window.parent) == null ? void 0 : _a2.postMessage({
50
- type: "builder.evaluateError",
51
- data: { id, error: error.message }
52
- }, "*");
53
- } else {
54
- if (result && typeof result.then === "function") {
55
- result.then((finalResult) => {
56
- var _a3;
57
- (_a3 = window.parent) == null ? void 0 : _a3.postMessage({
58
- type: "builder.evaluateResult",
59
- data: { id, result: finalResult }
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: { result, id }
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,6 +0,0 @@
1
- const convertStyleObject = (obj) => {
2
- return obj;
3
- };
4
- export {
5
- convertStyleObject
6
- };
@@ -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
- };
@@ -1,5 +0,0 @@
1
- const sanitizeBlockStyles = (_styles) => {
2
- };
3
- export {
4
- sanitizeBlockStyles
5
- };