@builder.io/sdk-react-native 0.1.2 → 0.1.4

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 (181) hide show
  1. package/dist/blocks/BaseText.js +40 -0
  2. package/dist/blocks/button/button.js +39 -0
  3. package/dist/blocks/button/component-info.js +42 -0
  4. package/dist/blocks/columns/columns.js +149 -0
  5. package/dist/blocks/columns/component-info.js +244 -0
  6. package/dist/blocks/custom-code/component-info.js +32 -0
  7. package/dist/blocks/custom-code/custom-code.js +76 -0
  8. package/dist/blocks/embed/component-info.js +47 -0
  9. package/dist/blocks/embed/embed.js +67 -0
  10. package/dist/blocks/embed/helpers.js +10 -0
  11. package/dist/blocks/form/component-info.js +263 -0
  12. package/dist/blocks/form/form.js +232 -0
  13. package/dist/blocks/fragment/component-info.js +12 -0
  14. package/dist/blocks/fragment/fragment.js +36 -0
  15. package/dist/blocks/image/component-info.js +152 -0
  16. package/dist/blocks/image/image.helpers.js +49 -0
  17. package/dist/blocks/image/image.js +81 -0
  18. package/dist/blocks/img/component-info.js +21 -0
  19. package/dist/blocks/img/img.js +35 -0
  20. package/dist/blocks/input/component-info.js +75 -0
  21. package/dist/blocks/input/input.js +32 -0
  22. package/dist/blocks/raw-text/component-info.js +17 -0
  23. package/dist/blocks/raw-text/raw-text.js +31 -0
  24. package/dist/blocks/section/component-info.js +50 -0
  25. package/dist/blocks/section/section.js +49 -0
  26. package/dist/blocks/select/component-info.js +60 -0
  27. package/dist/blocks/select/select.js +38 -0
  28. package/dist/blocks/submit-button/component-info.js +29 -0
  29. package/dist/blocks/submit-button/submit-button.js +36 -0
  30. package/dist/blocks/symbol/component-info.js +44 -0
  31. package/dist/blocks/symbol/symbol.js +97 -0
  32. package/dist/blocks/text/component-info.js +25 -0
  33. package/dist/blocks/text/text.js +112 -0
  34. package/dist/blocks/textarea/component-info.js +48 -0
  35. package/dist/blocks/textarea/textarea.js +31 -0
  36. package/dist/blocks/util.js +9 -0
  37. package/dist/blocks/video/component-info.js +107 -0
  38. package/dist/blocks/video/video.js +81 -0
  39. package/dist/components/render-block/block-styles.js +79 -0
  40. package/dist/components/render-block/render-block.helpers.js +109 -0
  41. package/dist/components/render-block/render-block.js +154 -0
  42. package/dist/components/render-block/render-component-with-context.js +45 -0
  43. package/dist/components/render-block/render-component.js +50 -0
  44. package/dist/components/render-block/render-repeated-block.js +45 -0
  45. package/dist/components/render-block/types.js +1 -0
  46. package/dist/components/render-blocks.js +76 -0
  47. package/dist/components/render-content/builder-editing.js +31 -0
  48. package/dist/components/render-content/components/render-styles.js +91 -0
  49. package/dist/components/render-content/index.js +8 -0
  50. package/dist/components/render-content/render-content.js +325 -0
  51. package/dist/components/render-inlined-styles.js +42 -0
  52. package/dist/constants/builder-registered-components.js +46 -0
  53. package/dist/constants/device-sizes.js +49 -0
  54. package/dist/constants/target.js +5 -0
  55. package/dist/context/builder.context.js +13 -0
  56. package/dist/context/types.js +1 -0
  57. package/dist/functions/camel-to-kebab-case.js +5 -0
  58. package/dist/functions/evaluate.js +25 -0
  59. package/dist/functions/event-handler-name.js +8 -0
  60. package/dist/functions/extract-text-styles.js +23 -0
  61. package/dist/functions/fast-clone.js +5 -0
  62. package/dist/functions/get-block-actions-handler.js +12 -0
  63. package/dist/functions/get-block-actions.js +19 -0
  64. package/dist/functions/get-block-component-options.js +29 -0
  65. package/dist/functions/get-block-properties.js +51 -0
  66. package/dist/functions/get-block-tag.js +8 -0
  67. package/dist/functions/get-builder-search-params/fn.test.js +15 -0
  68. package/dist/functions/get-builder-search-params/index.js +39 -0
  69. package/dist/functions/get-content/ab-testing.js +89 -0
  70. package/dist/functions/get-content/generate-content-url.js +44 -0
  71. package/dist/functions/get-content/generate-content-url.test.js +33 -0
  72. package/dist/functions/get-content/index.js +68 -0
  73. package/dist/functions/get-content/types.js +1 -0
  74. package/dist/functions/get-fetch.js +15 -0
  75. package/dist/functions/get-global-this.js +19 -0
  76. package/dist/functions/get-processed-block.js +52 -0
  77. package/dist/functions/get-processed-block.test.js +34 -0
  78. package/dist/functions/get-react-native-block-styles.js +30 -0
  79. package/dist/functions/if-target.js +13 -0
  80. package/dist/functions/is-browser.js +7 -0
  81. package/dist/functions/is-editing.js +8 -0
  82. package/dist/functions/is-iframe.js +8 -0
  83. package/dist/functions/is-previewing.js +15 -0
  84. package/dist/functions/on-change.js +28 -0
  85. package/dist/functions/on-change.test.js +21 -0
  86. package/dist/functions/register-component.js +65 -0
  87. package/dist/functions/register.js +31 -0
  88. package/dist/functions/sanitize-react-native-block-styles.js +71 -0
  89. package/dist/functions/set-editor-settings.js +16 -0
  90. package/dist/functions/set.js +12 -0
  91. package/dist/functions/set.test.js +18 -0
  92. package/dist/functions/track/helpers.js +53 -0
  93. package/dist/functions/track/index.js +124 -0
  94. package/dist/functions/track/interaction.js +51 -0
  95. package/dist/functions/track.js +120 -0
  96. package/dist/functions/transform-block-properties.js +18 -0
  97. package/dist/functions/transform-block.js +38 -0
  98. package/dist/helpers/ab-tests.js +10 -0
  99. package/dist/helpers/cookie.js +70 -0
  100. package/dist/helpers/css.js +33 -0
  101. package/dist/helpers/flatten.js +35 -0
  102. package/dist/helpers/localStorage.js +31 -0
  103. package/dist/helpers/nullable.js +5 -0
  104. package/dist/helpers/sessionId.js +51 -0
  105. package/dist/helpers/time.js +6 -0
  106. package/dist/helpers/url.js +14 -0
  107. package/dist/helpers/url.test.js +23 -0
  108. package/dist/helpers/uuid.js +14 -0
  109. package/dist/helpers/visitorId.js +33 -0
  110. package/dist/index-helpers/blocks-exports.js +22 -0
  111. package/dist/index-helpers/top-of-file.js +3 -0
  112. package/dist/index.js +29 -0
  113. package/dist/scripts/init-editing.js +97 -0
  114. package/dist/types/builder-block.js +1 -0
  115. package/dist/types/builder-content.js +1 -0
  116. package/dist/types/can-track.js +1 -0
  117. package/dist/types/components.js +1 -0
  118. package/dist/types/deep-partial.js +1 -0
  119. package/dist/types/element.js +1 -0
  120. package/dist/types/targets.js +1 -0
  121. package/dist/types/typescript.js +1 -0
  122. package/package.json +13 -5
  123. package/src/blocks/BaseText.jsx +17 -0
  124. package/src/blocks/button/button.jsx +28 -0
  125. package/src/blocks/columns/{columns.js → columns.jsx} +61 -38
  126. package/src/blocks/custom-code/{custom-code.js → custom-code.jsx} +22 -15
  127. package/src/blocks/embed/{embed.js → embed.jsx} +12 -11
  128. package/src/blocks/form/form.jsx +251 -0
  129. package/src/blocks/fragment/fragment.jsx +11 -0
  130. package/src/blocks/image/image.jsx +78 -0
  131. package/src/blocks/img/img.jsx +18 -0
  132. package/src/blocks/input/input.jsx +20 -0
  133. package/src/blocks/raw-text/raw-text.jsx +6 -0
  134. package/src/blocks/section/section.jsx +29 -0
  135. package/src/blocks/select/select.jsx +24 -0
  136. package/src/blocks/submit-button/submit-button.jsx +11 -0
  137. package/src/blocks/symbol/symbol.jsx +86 -0
  138. package/src/blocks/text/text.jsx +100 -0
  139. package/src/blocks/textarea/textarea.jsx +14 -0
  140. package/src/blocks/video/video.jsx +70 -0
  141. package/src/components/render-block/block-styles.jsx +70 -0
  142. package/src/components/render-block/render-block.helpers.js +90 -0
  143. package/src/components/render-block/render-block.jsx +183 -0
  144. package/src/components/render-block/render-component.jsx +45 -0
  145. package/src/components/render-block/render-repeated-block.jsx +22 -0
  146. package/src/components/render-blocks.jsx +86 -0
  147. package/src/components/render-content/builder-editing.jsx +6 -0
  148. package/src/components/render-content/components/{render-styles.js → render-styles.jsx} +22 -15
  149. package/src/components/render-content/index.js +1 -1
  150. package/src/components/render-content/render-content.jsx +373 -0
  151. package/src/components/render-inlined-styles.jsx +29 -0
  152. package/src/constants/builder-registered-components.js +7 -7
  153. package/src/functions/track/helpers.js +50 -0
  154. package/src/functions/{track.js → track/index.js} +10 -6
  155. package/src/functions/track/interaction.js +53 -0
  156. package/src/index-helpers/blocks-exports.js +8 -8
  157. package/src/index.js +1 -1
  158. package/src/blocks/BaseText.js +0 -31
  159. package/src/blocks/button/button.js +0 -36
  160. package/src/blocks/form/form.js +0 -222
  161. package/src/blocks/fragment/fragment.js +0 -9
  162. package/src/blocks/image/image.js +0 -55
  163. package/src/blocks/img/img.js +0 -33
  164. package/src/blocks/input/input.js +0 -36
  165. package/src/blocks/raw-text/raw-text.js +0 -10
  166. package/src/blocks/section/section.js +0 -41
  167. package/src/blocks/select/select.js +0 -37
  168. package/src/blocks/submit-button/submit-button.js +0 -27
  169. package/src/blocks/symbol/symbol.js +0 -73
  170. package/src/blocks/text/text.js +0 -67
  171. package/src/blocks/textarea/textarea.js +0 -32
  172. package/src/blocks/video/video.js +0 -55
  173. package/src/components/render-block/block-styles.js +0 -50
  174. package/src/components/render-block/render-block.js +0 -202
  175. package/src/components/render-block/render-component-with-context.js +0 -35
  176. package/src/components/render-block/render-component.js +0 -35
  177. package/src/components/render-block/render-repeated-block.js +0 -33
  178. package/src/components/render-blocks.js +0 -63
  179. package/src/components/render-content/builder-editing.js +0 -8
  180. package/src/components/render-content/render-content.js +0 -297
  181. package/src/components/render-inlined-styles.js +0 -17
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.setCookie = exports.getCookie = void 0;
7
+ var __async = (__this, __arguments, generator) => {
8
+ return new Promise((resolve, reject) => {
9
+ var fulfilled = (value) => {
10
+ try {
11
+ step(generator.next(value));
12
+ }
13
+ catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var rejected = (value) => {
18
+ try {
19
+ step(generator.throw(value));
20
+ }
21
+ catch (e) {
22
+ reject(e);
23
+ }
24
+ };
25
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
26
+ step((generator = generator.apply(__this, __arguments)).next());
27
+ });
28
+ };
29
+ const react_native_storage_1 = __importDefault(require("react-native-storage"));
30
+ const is_browser_js_1 = require("../functions/is-browser.js");
31
+ const async_storage_1 = __importDefault(require("@react-native-async-storage/async-storage"));
32
+ const ONE_DAY = 1e3 * 60 * 60 * 24;
33
+ const initStorage = () => {
34
+ const backend = (0, is_browser_js_1.isBrowser)() ? window.localStorage : async_storage_1.default;
35
+ const storage2 = new react_native_storage_1.default({
36
+ size: 1e3,
37
+ storageBackend: backend,
38
+ defaultExpires: ONE_DAY * 30,
39
+ enableCache: true
40
+ });
41
+ return storage2;
42
+ };
43
+ const storage = initStorage();
44
+ const getStorageName = (name) => `builderio.${name}`;
45
+ const getCookie = (_0) => __async(void 0, [_0], function* ({ name, canTrack }) {
46
+ try {
47
+ if (!canTrack) {
48
+ return void 0;
49
+ }
50
+ const parsedName = name.replace(/_/g, ".");
51
+ const data = yield storage.load({ key: getStorageName(parsedName) });
52
+ return data.value;
53
+ }
54
+ catch (err) {
55
+ console.debug("[COOKIE] GET error: ", err);
56
+ }
57
+ });
58
+ exports.getCookie = getCookie;
59
+ const setCookie = (_0) => __async(void 0, [_0], function* ({ name, value, expires, canTrack }) {
60
+ try {
61
+ if (!canTrack) {
62
+ return void 0;
63
+ }
64
+ yield storage.save({ key: getStorageName(name), data: { value }, expires });
65
+ }
66
+ catch (err) {
67
+ console.warn("[COOKIE] SET error: ", err);
68
+ }
69
+ });
70
+ exports.setCookie = setCookie;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createCssClass = exports.convertStyleMapToCSSArray = exports.convertStyleMapToCSS = void 0;
4
+ const camel_to_kebab_case_js_1 = require("../functions/camel-to-kebab-case.js");
5
+ const nullable_js_1 = require("./nullable.js");
6
+ const convertStyleMapToCSSArray = (style) => {
7
+ const cssProps = Object.entries(style).map(([key, value]) => {
8
+ if (typeof value === "string") {
9
+ return `${(0, camel_to_kebab_case_js_1.camelToKebabCase)(key)}: ${value};`;
10
+ }
11
+ else {
12
+ return void 0;
13
+ }
14
+ });
15
+ return cssProps.filter(nullable_js_1.checkIsDefined);
16
+ };
17
+ exports.convertStyleMapToCSSArray = convertStyleMapToCSSArray;
18
+ const convertStyleMapToCSS = (style) => convertStyleMapToCSSArray(style).join("\n");
19
+ exports.convertStyleMapToCSS = convertStyleMapToCSS;
20
+ const createCssClass = ({ mediaQuery, className, styles }) => {
21
+ const cssClass = `.${className} {
22
+ ${convertStyleMapToCSS(styles)}
23
+ }`;
24
+ if (mediaQuery) {
25
+ return `${mediaQuery} {
26
+ ${cssClass}
27
+ }`;
28
+ }
29
+ else {
30
+ return cssClass;
31
+ }
32
+ };
33
+ exports.createCssClass = createCssClass;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.flatten = void 0;
4
+ var __defProp = Object.defineProperty;
5
+ var __defProps = Object.defineProperties;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
+ var __spreadValues = (a, b) => {
12
+ for (var prop in b || (b = {}))
13
+ if (__hasOwnProp.call(b, prop))
14
+ __defNormalProp(a, prop, b[prop]);
15
+ if (__getOwnPropSymbols)
16
+ for (var prop of __getOwnPropSymbols(b)) {
17
+ if (__propIsEnum.call(b, prop))
18
+ __defNormalProp(a, prop, b[prop]);
19
+ }
20
+ return a;
21
+ };
22
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
+ function flatten(object, path = null, separator = ".") {
24
+ return Object.keys(object).reduce((acc, key) => {
25
+ const value = object[key];
26
+ const newPath = [path, key].filter(Boolean).join(separator);
27
+ const isObject = [
28
+ typeof value === "object",
29
+ value !== null,
30
+ !(Array.isArray(value) && value.length === 0)
31
+ ].every(Boolean);
32
+ return isObject ? __spreadValues(__spreadValues({}, acc), flatten(value, newPath, separator)) : __spreadProps(__spreadValues({}, acc), { [newPath]: value });
33
+ }, {});
34
+ }
35
+ exports.flatten = flatten;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setLocalStorageItem = exports.getLocalStorageItem = void 0;
4
+ const is_browser_js_1 = require("../functions/is-browser.js");
5
+ const getLocalStorage = () => (0, is_browser_js_1.isBrowser)() && typeof localStorage !== "undefined" ? localStorage : void 0;
6
+ const getLocalStorageItem = ({ key, canTrack }) => {
7
+ var _a;
8
+ try {
9
+ if (canTrack) {
10
+ return (_a = getLocalStorage()) == null ? void 0 : _a.getItem(key);
11
+ }
12
+ return void 0;
13
+ }
14
+ catch (err) {
15
+ console.debug("[LocalStorage] GET error: ", err);
16
+ return void 0;
17
+ }
18
+ };
19
+ exports.getLocalStorageItem = getLocalStorageItem;
20
+ const setLocalStorageItem = ({ key, canTrack, value }) => {
21
+ var _a;
22
+ try {
23
+ if (canTrack) {
24
+ (_a = getLocalStorage()) == null ? void 0 : _a.setItem(key, value);
25
+ }
26
+ }
27
+ catch (err) {
28
+ console.debug("[LocalStorage] SET error: ", err);
29
+ }
30
+ };
31
+ exports.setLocalStorageItem = setLocalStorageItem;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkIsDefined = void 0;
4
+ const checkIsDefined = (maybeT) => maybeT !== null && maybeT !== void 0;
5
+ exports.checkIsDefined = checkIsDefined;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setSessionId = exports.getSessionId = exports.createSessionId = void 0;
4
+ var __async = (__this, __arguments, generator) => {
5
+ return new Promise((resolve, reject) => {
6
+ var fulfilled = (value) => {
7
+ try {
8
+ step(generator.next(value));
9
+ }
10
+ catch (e) {
11
+ reject(e);
12
+ }
13
+ };
14
+ var rejected = (value) => {
15
+ try {
16
+ step(generator.throw(value));
17
+ }
18
+ catch (e) {
19
+ reject(e);
20
+ }
21
+ };
22
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
23
+ step((generator = generator.apply(__this, __arguments)).next());
24
+ });
25
+ };
26
+ const cookie_js_1 = require("./cookie.js");
27
+ const nullable_js_1 = require("./nullable.js");
28
+ const uuid_js_1 = require("./uuid.js");
29
+ const SESSION_LOCAL_STORAGE_KEY = "builderSessionId";
30
+ const getSessionId = (_0) => __async(void 0, [_0], function* ({ canTrack }) {
31
+ if (!canTrack) {
32
+ return void 0;
33
+ }
34
+ const sessionId = yield (0, cookie_js_1.getCookie)({
35
+ name: SESSION_LOCAL_STORAGE_KEY,
36
+ canTrack
37
+ });
38
+ if ((0, nullable_js_1.checkIsDefined)(sessionId)) {
39
+ return sessionId;
40
+ }
41
+ else {
42
+ const newSessionId = createSessionId();
43
+ setSessionId({ id: newSessionId, canTrack });
44
+ return newSessionId;
45
+ }
46
+ });
47
+ exports.getSessionId = getSessionId;
48
+ const createSessionId = () => (0, uuid_js_1.uuid)();
49
+ exports.createSessionId = createSessionId;
50
+ const setSessionId = ({ id, canTrack }) => (0, cookie_js_1.setCookie)({ name: SESSION_LOCAL_STORAGE_KEY, value: id, canTrack });
51
+ exports.setSessionId = setSessionId;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCurrentDatePlusMinutes = void 0;
4
+ const MINUTE_TO_MILLESECONDS_MULTIPLIER = 6e4;
5
+ const getCurrentDatePlusMinutes = (minutes = 30) => new Date(Date.now() + minutes * MINUTE_TO_MILLESECONDS_MULTIPLIER);
6
+ exports.getCurrentDatePlusMinutes = getCurrentDatePlusMinutes;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTopLevelDomain = void 0;
4
+ const getTopLevelDomain = (host) => {
5
+ if (host === "localhost" || host === "127.0.0.1") {
6
+ return host;
7
+ }
8
+ const parts = host.split(".");
9
+ if (parts.length > 2) {
10
+ return parts.slice(1).join(".");
11
+ }
12
+ return host;
13
+ };
14
+ exports.getTopLevelDomain = getTopLevelDomain;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const url_js_1 = require("./url.js");
4
+ describe("getTopLevelDomain", () => {
5
+ test("handles root domain", () => {
6
+ const output = (0, url_js_1.getTopLevelDomain)("example.com");
7
+ expect(output).toBe("example.com");
8
+ });
9
+ test("handles subdomain", () => {
10
+ const output = (0, url_js_1.getTopLevelDomain)("wwww.example.com");
11
+ expect(output).toBe("example.com");
12
+ });
13
+ test("handles subdomain with long suffix", () => {
14
+ const output = (0, url_js_1.getTopLevelDomain)("www.example.co.uk");
15
+ expect(output).toBe("example.co.uk");
16
+ });
17
+ test("handles localhost", () => {
18
+ const output = (0, url_js_1.getTopLevelDomain)("localhost");
19
+ expect(output).toBe("localhost");
20
+ const output2 = (0, url_js_1.getTopLevelDomain)("127.0.0.1");
21
+ expect(output2).toBe("127.0.0.1");
22
+ });
23
+ });
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.uuidv4 = exports.uuid = void 0;
4
+ function uuidv4() {
5
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
6
+ const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
7
+ return v.toString(16);
8
+ });
9
+ }
10
+ exports.uuidv4 = uuidv4;
11
+ function uuid() {
12
+ return uuidv4().replace(/-/g, "");
13
+ }
14
+ exports.uuid = uuid;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setVisitorId = exports.getVisitorId = exports.createVisitorId = void 0;
4
+ const localStorage_js_1 = require("./localStorage.js");
5
+ const nullable_js_1 = require("./nullable.js");
6
+ const uuid_js_1 = require("./uuid.js");
7
+ const VISITOR_LOCAL_STORAGE_KEY = "builderVisitorId";
8
+ const getVisitorId = ({ canTrack }) => {
9
+ if (!canTrack) {
10
+ return void 0;
11
+ }
12
+ const visitorId = (0, localStorage_js_1.getLocalStorageItem)({
13
+ key: VISITOR_LOCAL_STORAGE_KEY,
14
+ canTrack
15
+ });
16
+ if ((0, nullable_js_1.checkIsDefined)(visitorId)) {
17
+ return visitorId;
18
+ }
19
+ else {
20
+ const newVisitorId = createVisitorId();
21
+ setVisitorId({ id: newVisitorId, canTrack });
22
+ return newVisitorId;
23
+ }
24
+ };
25
+ exports.getVisitorId = getVisitorId;
26
+ const createVisitorId = () => (0, uuid_js_1.uuid)();
27
+ exports.createVisitorId = createVisitorId;
28
+ const setVisitorId = ({ id, canTrack }) => (0, localStorage_js_1.setLocalStorageItem)({
29
+ key: VISITOR_LOCAL_STORAGE_KEY,
30
+ value: id,
31
+ canTrack
32
+ });
33
+ exports.setVisitorId = setVisitorId;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Text = exports.Symbol = exports.Section = exports.RenderContent = exports.Image = exports.Fragment = exports.Columns = exports.Button = void 0;
7
+ const columns_1 = __importDefault(require("../blocks/columns/columns"));
8
+ Object.defineProperty(exports, "Columns", { enumerable: true, get: function () { return columns_1.default; } });
9
+ const image_1 = __importDefault(require("../blocks/image/image"));
10
+ Object.defineProperty(exports, "Image", { enumerable: true, get: function () { return image_1.default; } });
11
+ const text_1 = __importDefault(require("../blocks/text/text"));
12
+ Object.defineProperty(exports, "Text", { enumerable: true, get: function () { return text_1.default; } });
13
+ const symbol_1 = __importDefault(require("../blocks/symbol/symbol"));
14
+ Object.defineProperty(exports, "Symbol", { enumerable: true, get: function () { return symbol_1.default; } });
15
+ const button_1 = __importDefault(require("../blocks/button/button"));
16
+ Object.defineProperty(exports, "Button", { enumerable: true, get: function () { return button_1.default; } });
17
+ const section_1 = __importDefault(require("../blocks/section/section"));
18
+ Object.defineProperty(exports, "Section", { enumerable: true, get: function () { return section_1.default; } });
19
+ const fragment_1 = __importDefault(require("../blocks/fragment/fragment"));
20
+ Object.defineProperty(exports, "Fragment", { enumerable: true, get: function () { return fragment_1.default; } });
21
+ const render_content_1 = __importDefault(require("../components/render-content/render-content"));
22
+ Object.defineProperty(exports, "RenderContent", { enumerable: true, get: function () { return render_content_1.default; } });
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("react-native-url-polyfill/auto");
package/dist/index.js ADDED
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.track = void 0;
18
+ __exportStar(require("./index-helpers/top-of-file.js"), exports);
19
+ require("./scripts/init-editing.js");
20
+ __exportStar(require("./index-helpers/blocks-exports.js"), exports);
21
+ __exportStar(require("./functions/is-editing.js"), exports);
22
+ __exportStar(require("./functions/is-previewing.js"), exports);
23
+ __exportStar(require("./functions/register-component.js"), exports);
24
+ __exportStar(require("./functions/register.js"), exports);
25
+ __exportStar(require("./functions/set-editor-settings.js"), exports);
26
+ __exportStar(require("./functions/get-content/index.js"), exports);
27
+ __exportStar(require("./functions/get-builder-search-params/index.js"), exports);
28
+ const index_js_1 = require("./functions/track/index.js");
29
+ Object.defineProperty(exports, "track", { enumerable: true, get: function () { return index_js_1.track; } });
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setupBrowserForEditing = exports.registerInsertMenu = void 0;
4
+ const target_js_1 = require("../constants/target.js");
5
+ const is_browser_js_1 = require("../functions/is-browser.js");
6
+ const register_js_1 = require("../functions/register.js");
7
+ const registerInsertMenu = () => {
8
+ (0, register_js_1.register)("insertMenu", {
9
+ name: "_default",
10
+ default: true,
11
+ items: [
12
+ { name: "Box" },
13
+ { name: "Text" },
14
+ { name: "Image" },
15
+ { name: "Columns" },
16
+ ...target_js_1.TARGET === "reactNative" ? [] : [
17
+ { name: "Core:Section" },
18
+ { name: "Core:Button" },
19
+ { name: "Embed" },
20
+ { name: "Custom Code" }
21
+ ]
22
+ ]
23
+ });
24
+ };
25
+ exports.registerInsertMenu = registerInsertMenu;
26
+ let isSetupForEditing = false;
27
+ const setupBrowserForEditing = (options = {}) => {
28
+ var _a, _b;
29
+ if (isSetupForEditing) {
30
+ return;
31
+ }
32
+ isSetupForEditing = true;
33
+ if ((0, is_browser_js_1.isBrowser)()) {
34
+ (_a = window.parent) == null ? void 0 : _a.postMessage({
35
+ type: "builder.sdkInfo",
36
+ data: {
37
+ target: target_js_1.TARGET,
38
+ supportsPatchUpdates: false,
39
+ supportsAddBlockScoping: true,
40
+ supportsCustomBreakpoints: true
41
+ }
42
+ }, "*");
43
+ (_b = window.parent) == null ? void 0 : _b.postMessage({
44
+ type: "builder.updateContent",
45
+ data: {
46
+ options
47
+ }
48
+ }, "*");
49
+ window.addEventListener("message", ({ data }) => {
50
+ var _a2, _b2;
51
+ if (!(data == null ? void 0 : data.type)) {
52
+ return;
53
+ }
54
+ switch (data.type) {
55
+ case "builder.evaluate": {
56
+ const text = data.data.text;
57
+ const args = data.data.arguments || [];
58
+ const id = data.data.id;
59
+ const fn = new Function(text);
60
+ let result;
61
+ let error = null;
62
+ try {
63
+ result = fn.apply(null, args);
64
+ }
65
+ catch (err) {
66
+ error = err;
67
+ }
68
+ if (error) {
69
+ (_a2 = window.parent) == null ? void 0 : _a2.postMessage({
70
+ type: "builder.evaluateError",
71
+ data: { id, error: error.message }
72
+ }, "*");
73
+ }
74
+ else {
75
+ if (result && typeof result.then === "function") {
76
+ result.then((finalResult) => {
77
+ var _a3;
78
+ (_a3 = window.parent) == null ? void 0 : _a3.postMessage({
79
+ type: "builder.evaluateResult",
80
+ data: { id, result: finalResult }
81
+ }, "*");
82
+ }).catch(console.error);
83
+ }
84
+ else {
85
+ (_b2 = window.parent) == null ? void 0 : _b2.postMessage({
86
+ type: "builder.evaluateResult",
87
+ data: { result, id }
88
+ }, "*");
89
+ }
90
+ }
91
+ break;
92
+ }
93
+ }
94
+ });
95
+ }
96
+ };
97
+ exports.setupBrowserForEditing = setupBrowserForEditing;
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1 @@
1
+ "use strict";
package/package.json CHANGED
@@ -1,13 +1,19 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-react-native",
3
3
  "description": "Builder.io SDK for React Native",
4
- "version": "0.1.2",
5
- "main": "src/index.js",
4
+ "version": "0.1.4",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "exports": {
9
+ ".": "./dist/index.js"
10
+ },
6
11
  "files": [
7
- "src"
12
+ "src",
13
+ "dist"
8
14
  ],
9
15
  "scripts": {
10
- "build": "echo 'no need to build react-native SDK'",
16
+ "build": "tsc",
11
17
  "release:patch": "yarn run build && npm version patch && npm publish",
12
18
  "release:minor": "yarn run build && npm version minor && npm publish",
13
19
  "release:dev": "yarn run build && npm version prerelease && npm publish --tag dev"
@@ -23,8 +29,10 @@
23
29
  "react-native-url-polyfill": "^1.3.0"
24
30
  },
25
31
  "devDependencies": {
32
+ "@tsconfig/react-native": "^2.0.3",
26
33
  "@types/react-native-video": "^5.0.9",
27
34
  "react-native": "^0.64.3",
28
- "react-native-url-polyfill": "^1.3.0"
35
+ "react-native-url-polyfill": "^1.3.0",
36
+ "typescript": "^4.9.4"
29
37
  }
30
38
  }
@@ -0,0 +1,17 @@
1
+ import * as React from 'react';
2
+ import { Text } from 'react-native';
3
+ import BuilderContext from '../context/builder.context';
4
+
5
+ /**
6
+ * Implements CSS-like inheritance for `Text` by replacing all calls to `Text` with a custom `BaseText` component that
7
+ * applies the `inheritedStyles` context styles, which contain all styles from all parents that might apply to a `Text`.
8
+ */
9
+ export default function BaseText(props) {
10
+ const builderContext = React.useContext(BuilderContext);
11
+ return (
12
+ <Text
13
+ {...props}
14
+ style={{ ...builderContext.inheritedStyles, ...props.style }}
15
+ />
16
+ );
17
+ }
@@ -0,0 +1,28 @@
1
+ import BaseText from "../BaseText";
2
+ import * as React from "react";
3
+ import { View, StyleSheet, Image, Text } from "react-native";
4
+
5
+ export default function Button(props) {
6
+ return (
7
+ <>
8
+ {props.link ? (
9
+ <>
10
+ <View
11
+ role="button"
12
+ {...props.attributes}
13
+ href={props.link}
14
+ target={props.openLinkInNewTab ? "_blank" : undefined}
15
+ >
16
+ <BaseText>{props.text}</BaseText>
17
+ </View>
18
+ </>
19
+ ) : (
20
+ <View {...props.attributes} style={styles.view1}>
21
+ <BaseText>{props.text}</BaseText>
22
+ </View>
23
+ )}
24
+ </>
25
+ );
26
+ }
27
+
28
+ const styles = StyleSheet.create({ view1: { all: "unset" } });