@builder.io/sdk-react 0.0.1-0

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 (110) hide show
  1. package/README.md +19 -0
  2. package/package.json +15 -0
  3. package/src/blocks/button/button.js +38 -0
  4. package/src/blocks/button/component-info.js +41 -0
  5. package/src/blocks/columns/columns.js +110 -0
  6. package/src/blocks/columns/component-info.js +241 -0
  7. package/src/blocks/custom-code/component-info.js +31 -0
  8. package/src/blocks/custom-code/custom-code.js +50 -0
  9. package/src/blocks/embed/component-info.js +43 -0
  10. package/src/blocks/embed/embed.js +43 -0
  11. package/src/blocks/embed/helpers.js +9 -0
  12. package/src/blocks/form/component-info.js +262 -0
  13. package/src/blocks/form/form.js +225 -0
  14. package/src/blocks/fragment/component-info.js +11 -0
  15. package/src/blocks/fragment/fragment.js +7 -0
  16. package/src/blocks/image/component-info.js +150 -0
  17. package/src/blocks/image/image.helpers.js +48 -0
  18. package/src/blocks/image/image.js +90 -0
  19. package/src/blocks/img/component-info.js +20 -0
  20. package/src/blocks/img/img.js +35 -0
  21. package/src/blocks/input/component-info.js +74 -0
  22. package/src/blocks/input/input.js +35 -0
  23. package/src/blocks/raw-text/component-info.js +16 -0
  24. package/src/blocks/raw-text/raw-text.js +11 -0
  25. package/src/blocks/section/component-info.js +49 -0
  26. package/src/blocks/section/section.js +30 -0
  27. package/src/blocks/select/component-info.js +59 -0
  28. package/src/blocks/select/select.js +35 -0
  29. package/src/blocks/submit-button/component-info.js +28 -0
  30. package/src/blocks/submit-button/submit-button.js +28 -0
  31. package/src/blocks/symbol/component-info.js +43 -0
  32. package/src/blocks/symbol/symbol.js +69 -0
  33. package/src/blocks/text/component-info.js +24 -0
  34. package/src/blocks/text/text.js +10 -0
  35. package/src/blocks/textarea/component-info.js +47 -0
  36. package/src/blocks/textarea/textarea.js +31 -0
  37. package/src/blocks/video/component-info.js +106 -0
  38. package/src/blocks/video/video.js +51 -0
  39. package/src/components/render-block/block-styles.js +40 -0
  40. package/src/components/render-block/render-block.helpers.js +23 -0
  41. package/src/components/render-block/render-block.js +169 -0
  42. package/src/components/render-block/render-component.js +33 -0
  43. package/src/components/render-block/render-repeated-block.js +29 -0
  44. package/src/components/render-block/types.js +0 -0
  45. package/src/components/render-blocks.js +62 -0
  46. package/src/components/render-content/components/render-styles.js +58 -0
  47. package/src/components/render-content/index.js +4 -0
  48. package/src/components/render-content/render-content.js +265 -0
  49. package/src/components/render-inlined-styles.js +17 -0
  50. package/src/constants/builder-registered-components.js +48 -0
  51. package/src/constants/device-sizes.js +21 -0
  52. package/src/constants/target.js +4 -0
  53. package/src/context/builder.context.js +11 -0
  54. package/src/functions/camel-to-kebab-case.js +4 -0
  55. package/src/functions/convert-style-object.js +6 -0
  56. package/src/functions/evaluate.js +28 -0
  57. package/src/functions/event-handler-name.js +7 -0
  58. package/src/functions/get-block-actions.js +23 -0
  59. package/src/functions/get-block-component-options.js +28 -0
  60. package/src/functions/get-block-properties.js +29 -0
  61. package/src/functions/get-block-styles.js +34 -0
  62. package/src/functions/get-block-tag.js +6 -0
  63. package/src/functions/get-builder-search-params/fn.test.js +13 -0
  64. package/src/functions/get-builder-search-params/index.js +33 -0
  65. package/src/functions/get-content/ab-testing.js +38 -0
  66. package/src/functions/get-content/fn.test.js +31 -0
  67. package/src/functions/get-content/index.js +96 -0
  68. package/src/functions/get-content/types.js +0 -0
  69. package/src/functions/get-fetch.js +34 -0
  70. package/src/functions/get-global-this.js +18 -0
  71. package/src/functions/get-processed-block.js +53 -0
  72. package/src/functions/get-processed-block.test.js +32 -0
  73. package/src/functions/if-target.js +15 -0
  74. package/src/functions/is-browser.js +6 -0
  75. package/src/functions/is-editing.js +7 -0
  76. package/src/functions/is-iframe.js +7 -0
  77. package/src/functions/is-previewing.js +14 -0
  78. package/src/functions/on-change.js +27 -0
  79. package/src/functions/on-change.test.js +19 -0
  80. package/src/functions/register-component.js +72 -0
  81. package/src/functions/register.js +29 -0
  82. package/src/functions/sanitize-styles.js +5 -0
  83. package/src/functions/set-editor-settings.js +15 -0
  84. package/src/functions/set.js +11 -0
  85. package/src/functions/set.test.js +16 -0
  86. package/src/functions/track.js +91 -0
  87. package/src/functions/transform-block.js +6 -0
  88. package/src/helpers/cookie.js +59 -0
  89. package/src/helpers/css.js +12 -0
  90. package/src/helpers/flatten.js +34 -0
  91. package/src/helpers/localStorage.js +34 -0
  92. package/src/helpers/nullable.js +4 -0
  93. package/src/helpers/sessionId.js +26 -0
  94. package/src/helpers/time.js +5 -0
  95. package/src/helpers/url.js +10 -0
  96. package/src/helpers/url.test.js +15 -0
  97. package/src/helpers/uuid.js +13 -0
  98. package/src/helpers/visitorId.js +33 -0
  99. package/src/index-helpers/blocks-exports.js +22 -0
  100. package/src/index-helpers/top-of-file.js +4 -0
  101. package/src/index.js +10 -0
  102. package/src/scripts/init-editing.js +80 -0
  103. package/src/types/builder-block.js +0 -0
  104. package/src/types/builder-content.js +0 -0
  105. package/src/types/can-track.js +0 -0
  106. package/src/types/components.js +0 -0
  107. package/src/types/deep-partial.js +0 -0
  108. package/src/types/element.js +0 -0
  109. package/src/types/targets.js +0 -0
  110. package/src/types/typescript.js +0 -0
@@ -0,0 +1,34 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ function flatten(object, path = null, separator = ".") {
21
+ return Object.keys(object).reduce((acc, key) => {
22
+ const value = object[key];
23
+ const newPath = [path, key].filter(Boolean).join(separator);
24
+ const isObject = [
25
+ typeof value === "object",
26
+ value !== null,
27
+ !(Array.isArray(value) && value.length === 0)
28
+ ].every(Boolean);
29
+ return isObject ? __spreadValues(__spreadValues({}, acc), flatten(value, newPath, separator)) : __spreadProps(__spreadValues({}, acc), { [newPath]: value });
30
+ }, {});
31
+ }
32
+ export {
33
+ flatten
34
+ };
@@ -0,0 +1,34 @@
1
+ import { isBrowser } from "../functions/is-browser";
2
+ const getLocalStorage = () => isBrowser() && typeof localStorage !== "undefined" ? localStorage : void 0;
3
+ const getLocalStorageItem = ({
4
+ key,
5
+ canTrack
6
+ }) => {
7
+ var _a;
8
+ try {
9
+ if (canTrack) {
10
+ return (_a = getLocalStorage()) == null ? void 0 : _a.getItem(key);
11
+ }
12
+ return void 0;
13
+ } catch (err) {
14
+ console.debug("[LocalStorage] GET error: ", err);
15
+ }
16
+ };
17
+ const setLocalStorageItem = ({
18
+ key,
19
+ canTrack,
20
+ value
21
+ }) => {
22
+ var _a;
23
+ try {
24
+ if (canTrack) {
25
+ (_a = getLocalStorage()) == null ? void 0 : _a.setItem(key, value);
26
+ }
27
+ } catch (err) {
28
+ console.debug("[LocalStorage] SET error: ", err);
29
+ }
30
+ };
31
+ export {
32
+ getLocalStorageItem,
33
+ setLocalStorageItem
34
+ };
@@ -0,0 +1,4 @@
1
+ const checkIsDefined = (maybeT) => maybeT !== null && maybeT !== void 0;
2
+ export {
3
+ checkIsDefined
4
+ };
@@ -0,0 +1,26 @@
1
+ import { getCookie, setCookie } from "./cookie";
2
+ import { checkIsDefined } from "./nullable";
3
+ import { uuid } from "./uuid";
4
+ const SESSION_LOCAL_STORAGE_KEY = "builderSessionId";
5
+ const getSessionId = ({ canTrack }) => {
6
+ if (!canTrack) {
7
+ return void 0;
8
+ }
9
+ const sessionId = getCookie({ name: SESSION_LOCAL_STORAGE_KEY, canTrack });
10
+ if (checkIsDefined(sessionId)) {
11
+ return sessionId;
12
+ } else {
13
+ const newSessionId = createSessionId();
14
+ setSessionId({ id: newSessionId, canTrack });
15
+ }
16
+ };
17
+ const createSessionId = () => uuid();
18
+ const setSessionId = ({
19
+ id,
20
+ canTrack
21
+ }) => setCookie({ name: SESSION_LOCAL_STORAGE_KEY, value: id, canTrack });
22
+ export {
23
+ createSessionId,
24
+ getSessionId,
25
+ setSessionId
26
+ };
@@ -0,0 +1,5 @@
1
+ const MINUTE_TO_MILLESECONDS_MULTIPLIER = 6e4;
2
+ const getCurrentDatePlusMinutes = (minutes = 30) => new Date(Date.now() + minutes * MINUTE_TO_MILLESECONDS_MULTIPLIER);
3
+ export {
4
+ getCurrentDatePlusMinutes
5
+ };
@@ -0,0 +1,10 @@
1
+ const getTopLevelDomain = (host) => {
2
+ const parts = host.split(".");
3
+ if (parts.length > 2) {
4
+ return parts.slice(1).join(".");
5
+ }
6
+ return host;
7
+ };
8
+ export {
9
+ getTopLevelDomain
10
+ };
@@ -0,0 +1,15 @@
1
+ import { getTopLevelDomain } from "./url.js";
2
+ describe("getTopLevelDomain", () => {
3
+ test("handles root domain", () => {
4
+ const output = getTopLevelDomain("example.com");
5
+ expect(output).toBe("example.com");
6
+ });
7
+ test("handles subdomain", () => {
8
+ const output = getTopLevelDomain("wwww.example.com");
9
+ expect(output).toBe("example.com");
10
+ });
11
+ test("handles subdomain with long suffix", () => {
12
+ const output = getTopLevelDomain("www.example.co.uk");
13
+ expect(output).toBe("example.co.uk");
14
+ });
15
+ });
@@ -0,0 +1,13 @@
1
+ function uuidv4() {
2
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
3
+ const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
4
+ return v.toString(16);
5
+ });
6
+ }
7
+ function uuid() {
8
+ return uuidv4().replace(/-/g, "");
9
+ }
10
+ export {
11
+ uuid,
12
+ uuidv4
13
+ };
@@ -0,0 +1,33 @@
1
+ import { getLocalStorageItem, setLocalStorageItem } from "./localStorage";
2
+ import { checkIsDefined } from "./nullable";
3
+ import { uuid } from "./uuid";
4
+ const VISITOR_LOCAL_STORAGE_KEY = "builderVisitorId";
5
+ const getVisitorId = ({ canTrack }) => {
6
+ if (!canTrack) {
7
+ return void 0;
8
+ }
9
+ const visitorId = getLocalStorageItem({
10
+ key: VISITOR_LOCAL_STORAGE_KEY,
11
+ canTrack
12
+ });
13
+ if (checkIsDefined(visitorId)) {
14
+ return visitorId;
15
+ } else {
16
+ const newVisitorId = createVisitorId();
17
+ setVisitorId({ id: newVisitorId, canTrack });
18
+ }
19
+ };
20
+ const createVisitorId = () => uuid();
21
+ const setVisitorId = ({
22
+ id,
23
+ canTrack
24
+ }) => setLocalStorageItem({
25
+ key: VISITOR_LOCAL_STORAGE_KEY,
26
+ value: id,
27
+ canTrack
28
+ });
29
+ export {
30
+ createVisitorId,
31
+ getVisitorId,
32
+ setVisitorId
33
+ };
@@ -0,0 +1,22 @@
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";
11
+ export {
12
+ default7 as Button,
13
+ default2 as Columns,
14
+ default9 as Fragment,
15
+ default3 as Image,
16
+ default11 as RenderBlocks,
17
+ default10 as RenderContent,
18
+ default8 as Section,
19
+ default6 as Symbol,
20
+ default4 as Text,
21
+ default5 as Video
22
+ };
@@ -0,0 +1,4 @@
1
+ var stdin_default = void 0;
2
+ export {
3
+ stdin_default as default
4
+ };
package/src/index.js ADDED
@@ -0,0 +1,10 @@
1
+ import "./index-helpers/top-of-file.js";
2
+ import "./scripts/init-editing.js";
3
+ export * from "./index-helpers/blocks-exports.js";
4
+ export * from "./functions/is-editing.js";
5
+ export * from "./functions/is-previewing.js";
6
+ export * from "./functions/register-component.js";
7
+ export * from "./functions/register.js";
8
+ export * from "./functions/set-editor-settings.js";
9
+ export * from "./functions/get-content/index.js";
10
+ export * from "./functions/get-builder-search-params/index.js";
@@ -0,0 +1,80 @@
1
+ import { TARGET } from "../constants/target.js";
2
+ import { isBrowser } from "../functions/is-browser.js";
3
+ import { isEditing } from "../functions/is-editing.js";
4
+ import { register } from "../functions/register.js";
5
+ const registerInsertMenu = () => {
6
+ register("insertMenu", {
7
+ name: "_default",
8
+ default: true,
9
+ items: [
10
+ { name: "Box" },
11
+ { name: "Text" },
12
+ { name: "Image" },
13
+ { name: "Columns" },
14
+ ...TARGET === "reactNative" ? [] : [
15
+ { name: "Core:Section" },
16
+ { name: "Core:Button" },
17
+ { name: "Embed" },
18
+ { name: "Custom Code" }
19
+ ]
20
+ ]
21
+ });
22
+ };
23
+ const setupBrowserForEditing = () => {
24
+ var _a;
25
+ if (isBrowser()) {
26
+ (_a = window.parent) == null ? void 0 : _a.postMessage({
27
+ type: "builder.sdkInfo",
28
+ data: {
29
+ target: TARGET,
30
+ supportsPatchUpdates: false
31
+ }
32
+ }, "*");
33
+ window.addEventListener("message", ({ data }) => {
34
+ var _a2, _b;
35
+ if (data) {
36
+ switch (data.type) {
37
+ case "builder.evaluate": {
38
+ const text = data.data.text;
39
+ const args = data.data.arguments || [];
40
+ const id = data.data.id;
41
+ const fn = new Function(text);
42
+ let result;
43
+ let error = null;
44
+ try {
45
+ result = fn.apply(null, args);
46
+ } catch (err) {
47
+ error = err;
48
+ }
49
+ if (error) {
50
+ (_a2 = window.parent) == null ? void 0 : _a2.postMessage({
51
+ type: "builder.evaluateError",
52
+ data: { id, error: error.message }
53
+ }, "*");
54
+ } else {
55
+ if (result && typeof result.then === "function") {
56
+ result.then((finalResult) => {
57
+ var _a3;
58
+ (_a3 = window.parent) == null ? void 0 : _a3.postMessage({
59
+ type: "builder.evaluateResult",
60
+ data: { id, result: finalResult }
61
+ }, "*");
62
+ }).catch(console.error);
63
+ } else {
64
+ (_b = window.parent) == null ? void 0 : _b.postMessage({
65
+ type: "builder.evaluateResult",
66
+ data: { result, id }
67
+ }, "*");
68
+ }
69
+ }
70
+ break;
71
+ }
72
+ }
73
+ }
74
+ });
75
+ }
76
+ };
77
+ if (isEditing()) {
78
+ registerInsertMenu();
79
+ setupBrowserForEditing();
80
+ }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes