@builder.io/sdk-solid 0.5.9 → 0.6.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 (166) hide show
  1. package/README.md +0 -4
  2. package/dist/index.d.ts +51 -0
  3. package/lib/browser/dev.js +4790 -0
  4. package/lib/browser/dev.jsx +4392 -0
  5. package/lib/browser/index.js +4767 -0
  6. package/lib/browser/index.jsx +4374 -0
  7. package/lib/edge/dev.js +7921 -0
  8. package/lib/edge/dev.jsx +7525 -0
  9. package/lib/edge/index.js +7898 -0
  10. package/lib/edge/index.jsx +7507 -0
  11. package/lib/node/dev.js +4790 -0
  12. package/lib/node/dev.jsx +4392 -0
  13. package/lib/node/index.js +4767 -0
  14. package/lib/node/index.jsx +4374 -0
  15. package/package.json +86 -14
  16. package/CHANGELOG.md +0 -102
  17. package/solid-index.jsx +0 -5
  18. package/src/blocks/BaseText.jsx +0 -11
  19. package/src/blocks/button/button.jsx +0 -41
  20. package/src/blocks/button/component-info.js +0 -34
  21. package/src/blocks/columns/columns.jsx +0 -174
  22. package/src/blocks/columns/component-info.js +0 -218
  23. package/src/blocks/custom-code/component-info.js +0 -24
  24. package/src/blocks/custom-code/custom-code.jsx +0 -62
  25. package/src/blocks/embed/component-info.js +0 -37
  26. package/src/blocks/embed/embed.jsx +0 -50
  27. package/src/blocks/embed/helpers.js +0 -3
  28. package/src/blocks/form/component-info.js +0 -223
  29. package/src/blocks/form/form.jsx +0 -5
  30. package/src/blocks/fragment/component-info.js +0 -8
  31. package/src/blocks/fragment/fragment.jsx +0 -5
  32. package/src/blocks/helpers.js +0 -27
  33. package/src/blocks/image/component-info.js +0 -122
  34. package/src/blocks/image/image.helpers.js +0 -46
  35. package/src/blocks/image/image.jsx +0 -122
  36. package/src/blocks/img/component-info.js +0 -15
  37. package/src/blocks/img/img.jsx +0 -20
  38. package/src/blocks/input/component-info.js +0 -45
  39. package/src/blocks/input/input.jsx +0 -22
  40. package/src/blocks/raw-text/component-info.js +0 -11
  41. package/src/blocks/raw-text/raw-text.jsx +0 -10
  42. package/src/blocks/section/component-info.js +0 -41
  43. package/src/blocks/section/section.jsx +0 -26
  44. package/src/blocks/select/component-info.js +0 -44
  45. package/src/blocks/select/select.jsx +0 -30
  46. package/src/blocks/submit-button/component-info.js +0 -23
  47. package/src/blocks/submit-button/submit-button.jsx +0 -11
  48. package/src/blocks/symbol/component-info.js +0 -35
  49. package/src/blocks/symbol/symbol.helpers.js +0 -60
  50. package/src/blocks/symbol/symbol.jsx +0 -64
  51. package/src/blocks/text/component-info.js +0 -20
  52. package/src/blocks/text/text.jsx +0 -14
  53. package/src/blocks/textarea/component-info.js +0 -38
  54. package/src/blocks/textarea/textarea.jsx +0 -16
  55. package/src/blocks/video/component-info.js +0 -83
  56. package/src/blocks/video/video.jsx +0 -61
  57. package/src/components/block/block.helpers.js +0 -99
  58. package/src/components/block/block.jsx +0 -167
  59. package/src/components/block/components/block-styles.jsx +0 -85
  60. package/src/components/block/components/block-wrapper.jsx +0 -50
  61. package/src/components/block/components/component-ref/component-ref.helpers.js +0 -41
  62. package/src/components/block/components/component-ref/component-ref.jsx +0 -59
  63. package/src/components/block/components/interactive-element.jsx +0 -30
  64. package/src/components/block/components/repeated-block.jsx +0 -20
  65. package/src/components/block/types.js +0 -0
  66. package/src/components/blocks/blocks-wrapper.jsx +0 -66
  67. package/src/components/blocks/blocks.jsx +0 -57
  68. package/src/components/content/components/enable-editor.jsx +0 -347
  69. package/src/components/content/components/styles.helpers.js +0 -56
  70. package/src/components/content/components/styles.jsx +0 -36
  71. package/src/components/content/content.helpers.js +0 -48
  72. package/src/components/content/content.jsx +0 -136
  73. package/src/components/content/content.types.js +0 -0
  74. package/src/components/content/index.js +0 -2
  75. package/src/components/content/wrap-component-ref.js +0 -2
  76. package/src/components/content-variants/content-variants.jsx +0 -115
  77. package/src/components/content-variants/content-variants.types.js +0 -0
  78. package/src/components/content-variants/helpers.js +0 -158
  79. package/src/components/inlined-script.jsx +0 -5
  80. package/src/components/inlined-styles.jsx +0 -5
  81. package/src/constants/builder-registered-components.js +0 -63
  82. package/src/constants/device-sizes.js +0 -48
  83. package/src/constants/sdk-version.js +0 -1
  84. package/src/constants/target.js +0 -4
  85. package/src/context/builder.context.js +0 -16
  86. package/src/context/components.context.js +0 -5
  87. package/src/context/types.js +0 -0
  88. package/src/functions/apply-patch-with-mutation.js +0 -66
  89. package/src/functions/camel-to-kebab-case.js +0 -2
  90. package/src/functions/evaluate/browser-runtime/browser.js +0 -40
  91. package/src/functions/evaluate/browser-runtime/index.js +0 -2
  92. package/src/functions/evaluate/evaluate.js +0 -49
  93. package/src/functions/evaluate/helpers.js +0 -15
  94. package/src/functions/evaluate/index.js +0 -2
  95. package/src/functions/evaluate/node-runtime/index.js +0 -2
  96. package/src/functions/evaluate/non-node-runtime/acorn-interpreter.js +0 -2876
  97. package/src/functions/evaluate/non-node-runtime/index.js +0 -18
  98. package/src/functions/evaluate/non-node-runtime/non-node-runtime.js +0 -91
  99. package/src/functions/event-handler-name.js +0 -5
  100. package/src/functions/extract-text-styles.js +0 -14
  101. package/src/functions/fast-clone.js +0 -2
  102. package/src/functions/fetch-builder-props.js +0 -60
  103. package/src/functions/get-block-actions-handler.js +0 -11
  104. package/src/functions/get-block-actions.js +0 -29
  105. package/src/functions/get-block-component-options.js +0 -27
  106. package/src/functions/get-block-properties.js +0 -63
  107. package/src/functions/get-builder-search-params/index.js +0 -33
  108. package/src/functions/get-content/generate-content-url.js +0 -59
  109. package/src/functions/get-content/index.js +0 -116
  110. package/src/functions/get-content/types.js +0 -0
  111. package/src/functions/get-fetch.js +0 -12
  112. package/src/functions/get-global-this.js +0 -16
  113. package/src/functions/get-processed-block.js +0 -74
  114. package/src/functions/get-react-native-block-styles.js +0 -32
  115. package/src/functions/is-browser.js +0 -4
  116. package/src/functions/is-editing.js +0 -6
  117. package/src/functions/is-iframe.js +0 -5
  118. package/src/functions/is-non-node-server.js +0 -9
  119. package/src/functions/is-previewing.js +0 -12
  120. package/src/functions/on-change.js +0 -24
  121. package/src/functions/register-component.js +0 -60
  122. package/src/functions/register.js +0 -27
  123. package/src/functions/sanitize-react-native-block-styles.js +0 -71
  124. package/src/functions/set-editor-settings.js +0 -13
  125. package/src/functions/set.js +0 -9
  126. package/src/functions/track/helpers.js +0 -48
  127. package/src/functions/track/index.js +0 -131
  128. package/src/functions/track/interaction.js +0 -57
  129. package/src/functions/transform-block-properties.js +0 -4
  130. package/src/functions/transform-block.js +0 -4
  131. package/src/helpers/ab-tests.js +0 -158
  132. package/src/helpers/canTrack.js +0 -3
  133. package/src/helpers/cookie.js +0 -77
  134. package/src/helpers/css.js +0 -30
  135. package/src/helpers/flatten.js +0 -31
  136. package/src/helpers/localStorage.js +0 -32
  137. package/src/helpers/logger.js +0 -8
  138. package/src/helpers/nullable.js +0 -2
  139. package/src/helpers/preview-lru-cache/get.js +0 -4
  140. package/src/helpers/preview-lru-cache/helpers.js +0 -0
  141. package/src/helpers/preview-lru-cache/init.js +0 -2
  142. package/src/helpers/preview-lru-cache/set.js +0 -31
  143. package/src/helpers/preview-lru-cache/types.js +0 -0
  144. package/src/helpers/sessionId.js +0 -55
  145. package/src/helpers/time.js +0 -3
  146. package/src/helpers/url.js +0 -11
  147. package/src/helpers/uuid.js +0 -11
  148. package/src/helpers/visitorId.js +0 -35
  149. package/src/index-helpers/blocks-exports.js +0 -13
  150. package/src/index-helpers/top-of-file.js +0 -2
  151. package/src/index.js +0 -3
  152. package/src/scripts/init-editing.js +0 -109
  153. package/src/server-index.js +0 -11
  154. package/src/types/api-version.js +0 -2
  155. package/src/types/builder-block.js +0 -0
  156. package/src/types/builder-content.js +0 -0
  157. package/src/types/builder-props.js +0 -0
  158. package/src/types/can-track.js +0 -0
  159. package/src/types/components.js +0 -0
  160. package/src/types/deep-partial.js +0 -0
  161. package/src/types/element.js +0 -0
  162. package/src/types/enforced-partials.js +0 -0
  163. package/src/types/input.js +0 -0
  164. package/src/types/targets.js +0 -0
  165. package/src/types/typescript.js +0 -0
  166. package/vite.config.ts +0 -18
@@ -1,4 +0,0 @@
1
- function isBrowser() {
2
- return typeof window !== "undefined" && typeof document !== "undefined";
3
- }
4
- export { isBrowser }
@@ -1,6 +0,0 @@
1
- import { TARGET } from "../constants/target.js";
2
- import { isIframe } from "./is-iframe.js";
3
- function isEditing() {
4
- return isIframe() && (TARGET === "reactNative" || window.location.search.indexOf("builder.frameEditing=") !== -1);
5
- }
6
- export { isEditing }
@@ -1,5 +0,0 @@
1
- import { isBrowser } from "./is-browser.js";
2
- function isIframe() {
3
- return isBrowser() && window.self !== window.top;
4
- }
5
- export { isIframe }
@@ -1,9 +0,0 @@
1
- import { isBrowser } from "./is-browser.js";
2
- function isNonNodeServer() {
3
- const hasNode = () => {
4
- var _a;
5
- return typeof process !== "undefined" && ((_a = process == null ? void 0 : process.versions) == null ? void 0 : _a.node);
6
- };
7
- return !isBrowser() && !hasNode();
8
- }
9
- export { isNonNodeServer }
@@ -1,12 +0,0 @@
1
- import { isBrowser } from "./is-browser.js";
2
- import { isEditing } from "./is-editing.js";
3
- function isPreviewing() {
4
- if (!isBrowser()) {
5
- return false;
6
- }
7
- if (isEditing()) {
8
- return false;
9
- }
10
- return Boolean(location.search.indexOf("builder.preview=") !== -1);
11
- }
12
- export { isPreviewing }
@@ -1,24 +0,0 @@
1
- const onChangeProxySymbol = Symbol("onChangeProxySymbol");
2
- function onChange(obj, cb) {
3
- return new Proxy(obj, {
4
- get(target, key) {
5
- if (key === onChangeProxySymbol) {
6
- return true;
7
- }
8
- const value = Reflect.get(target, key);
9
- if (value && typeof value === "object") {
10
- if (value[onChangeProxySymbol]) {
11
- return value;
12
- }
13
- return onChange(value, cb);
14
- }
15
- return value;
16
- },
17
- set(target, key, value) {
18
- const returnValue = Reflect.set(target, key, value);
19
- cb();
20
- return returnValue;
21
- }
22
- });
23
- }
24
- export { onChange, onChangeProxySymbol }
@@ -1,60 +0,0 @@
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, {
8
- enumerable: true,
9
- configurable: true,
10
- writable: true,
11
- value
12
- }) : obj[key] = value;
13
- var __spreadValues = (a, b) => {
14
- for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
15
- if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) {
16
- if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
17
- }
18
- return a;
19
- };
20
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
- var __objRest = (source, exclude) => {
22
- var target = {};
23
- for (var prop in source) if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0) target[prop] = source[prop];
24
- if (source != null && __getOwnPropSymbols) for (var prop of __getOwnPropSymbols(source)) {
25
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop)) target[prop] = source[prop];
26
- }
27
- return target;
28
- };
29
- import { fastClone } from "./fast-clone.js";
30
- const components = [];
31
- function registerComponent(component, info) {
32
- components.push(__spreadValues({
33
- component
34
- }, info));
35
- console.warn("registerComponent is deprecated. Use the `customComponents` prop in RenderContent instead to provide your custom components to the builder SDK.");
36
- return component;
37
- }
38
- const createRegisterComponentMessage = info => ({
39
- type: "builder.registerComponent",
40
- data: serializeComponentInfo(info)
41
- });
42
- const serializeFn = fnValue => {
43
- const fnStr = fnValue.toString().trim();
44
- const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("(");
45
- return `return (${appendFunction ? "function " : ""}${fnStr}).apply(this, arguments)`;
46
- };
47
- const serializeValue = value => typeof value === "function" ? serializeFn(value) : fastClone(value);
48
- const serializeComponentInfo = _a => {
49
- var _b = _a,
50
- {
51
- inputs
52
- } = _b,
53
- info = __objRest(_b, ["inputs"]);
54
- return __spreadProps(__spreadValues({}, fastClone(info)), {
55
- inputs: inputs == null ? void 0 : inputs.map(input => Object.entries(input).reduce((acc, [key, value]) => __spreadProps(__spreadValues({}, acc), {
56
- [key]: serializeValue(value)
57
- }), {}))
58
- });
59
- };
60
- export { components, createRegisterComponentMessage, registerComponent, serializeComponentInfo }
@@ -1,27 +0,0 @@
1
- import { isBrowser } from "./is-browser.js";
2
- const registry = {};
3
- function register(type, info) {
4
- let typeList = registry[type];
5
- if (!typeList) {
6
- typeList = registry[type] = [];
7
- }
8
- typeList.push(info);
9
- if (isBrowser()) {
10
- const message = {
11
- type: "builder.register",
12
- data: {
13
- type,
14
- info
15
- }
16
- };
17
- try {
18
- parent.postMessage(message, "*");
19
- if (parent !== window) {
20
- window.postMessage(message, "*");
21
- }
22
- } catch (err) {
23
- console.debug("Could not postmessage", err);
24
- }
25
- }
26
- }
27
- export { register }
@@ -1,71 +0,0 @@
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, {
8
- enumerable: true,
9
- configurable: true,
10
- writable: true,
11
- value
12
- }) : obj[key] = value;
13
- var __spreadValues = (a, b) => {
14
- for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
15
- if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) {
16
- if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
17
- }
18
- return a;
19
- };
20
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
- const propertiesThatMustBeNumber = new Set(["lineHeight"]);
22
- const displayValues = new Set(["flex", "none"]);
23
- const SHOW_WARNINGS = false;
24
- const normalizeNumber = value => {
25
- if (Number.isNaN(value)) {
26
- return void 0;
27
- } else if (value < 0) {
28
- return 0;
29
- } else {
30
- return value;
31
- }
32
- };
33
- const sanitizeReactNativeBlockStyles = styles => {
34
- return Object.keys(styles).reduce((acc, key) => {
35
- const propertyValue = styles[key];
36
- if (key === "display" && !displayValues.has(propertyValue)) {
37
- if (SHOW_WARNINGS) {
38
- console.warn(`Style value for key "display" must be "flex" or "none" but had ${propertyValue}`);
39
- }
40
- return acc;
41
- }
42
- if (propertiesThatMustBeNumber.has(key) && typeof propertyValue !== "number") {
43
- if (SHOW_WARNINGS) {
44
- console.warn(`Style key ${key} must be a number, but had value \`${styles[key]}\``);
45
- }
46
- return acc;
47
- }
48
- if (typeof propertyValue === "string") {
49
- const isPixelUnit = propertyValue.match(/^-?(\d*)(\.?)(\d*)*px$/);
50
- if (isPixelUnit) {
51
- const newValue = parseFloat(propertyValue);
52
- const normalizedValue = normalizeNumber(newValue);
53
- if (normalizedValue) {
54
- return __spreadProps(__spreadValues({}, acc), {
55
- [key]: normalizedValue
56
- });
57
- } else {
58
- return acc;
59
- }
60
- } else if (propertyValue === "0") {
61
- return __spreadProps(__spreadValues({}, acc), {
62
- [key]: 0
63
- });
64
- }
65
- }
66
- return __spreadProps(__spreadValues({}, acc), {
67
- [key]: propertyValue
68
- });
69
- }, {});
70
- };
71
- export { sanitizeReactNativeBlockStyles }
@@ -1,13 +0,0 @@
1
- import { isBrowser } from "./is-browser.js";
2
- const settings = {};
3
- function setEditorSettings(newSettings) {
4
- if (isBrowser()) {
5
- Object.assign(settings, newSettings);
6
- const message = {
7
- type: "builder.settingsChange",
8
- data: settings
9
- };
10
- parent.postMessage(message, "*");
11
- }
12
- }
13
- export { setEditorSettings }
@@ -1,9 +0,0 @@
1
- const set = (obj, _path, value) => {
2
- if (Object(obj) !== obj) {
3
- return obj;
4
- }
5
- const path = Array.isArray(_path) ? _path : _path.toString().match(/[^.[\]]+/g);
6
- path.slice(0, -1).reduce((a, c, i) => Object(a[c]) === a[c] ? a[c] : a[c] = Math.abs(Number(path[i + 1])) >> 0 === +path[i + 1] ? [] : {}, obj)[path[path.length - 1]] = value;
7
- return obj;
8
- };
9
- export { set }
@@ -1,48 +0,0 @@
1
- import { TARGET } from "../../constants/target.js";
2
- import { isBrowser } from "../is-browser.js";
3
- const getLocation = () => {
4
- if (TARGET === "reactNative") {
5
- return null;
6
- } else if (isBrowser()) {
7
- const parsedLocation = new URL(location.href);
8
- if (parsedLocation.pathname === "") {
9
- parsedLocation.pathname = "/";
10
- }
11
- return parsedLocation;
12
- } else {
13
- console.warn("Cannot get location for tracking in non-browser environment");
14
- return null;
15
- }
16
- };
17
- const getUserAgent = () => typeof navigator === "object" && navigator.userAgent || "";
18
- const getUserAttributes = () => {
19
- const userAgent = getUserAgent();
20
- const isMobile = {
21
- Android() {
22
- return userAgent.match(/Android/i);
23
- },
24
- BlackBerry() {
25
- return userAgent.match(/BlackBerry/i);
26
- },
27
- iOS() {
28
- return userAgent.match(/iPhone|iPod/i);
29
- },
30
- Opera() {
31
- return userAgent.match(/Opera Mini/i);
32
- },
33
- Windows() {
34
- return userAgent.match(/IEMobile/i) || userAgent.match(/WPDesktop/i);
35
- },
36
- any() {
37
- return isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows() || TARGET === "reactNative";
38
- }
39
- };
40
- const isTablet = userAgent.match(/Tablet|iPad/i);
41
- const url = getLocation();
42
- return {
43
- urlPath: url == null ? void 0 : url.pathname,
44
- host: (url == null ? void 0 : url.host) || (url == null ? void 0 : url.hostname),
45
- device: isTablet ? "tablet" : isMobile.any() ? "mobile" : "desktop"
46
- };
47
- };
48
- export { getUserAttributes }
@@ -1,131 +0,0 @@
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, {
8
- enumerable: true,
9
- configurable: true,
10
- writable: true,
11
- value
12
- }) : obj[key] = value;
13
- var __spreadValues = (a, b) => {
14
- for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
15
- if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) {
16
- if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
17
- }
18
- return a;
19
- };
20
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
- var __objRest = (source, exclude) => {
22
- var target = {};
23
- for (var prop in source) if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0) target[prop] = source[prop];
24
- if (source != null && __getOwnPropSymbols) for (var prop of __getOwnPropSymbols(source)) {
25
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop)) target[prop] = source[prop];
26
- }
27
- return target;
28
- };
29
- var __async = (__this, __arguments, generator) => {
30
- return new Promise((resolve, reject) => {
31
- var fulfilled = value => {
32
- try {
33
- step(generator.next(value));
34
- } catch (e) {
35
- reject(e);
36
- }
37
- };
38
- var rejected = value => {
39
- try {
40
- step(generator.throw(value));
41
- } catch (e) {
42
- reject(e);
43
- }
44
- };
45
- var step = x => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
46
- step((generator = generator.apply(__this, __arguments)).next());
47
- });
48
- };
49
- import { TARGET } from "../../constants/target.js";
50
- import { logger } from "../../helpers/logger.js";
51
- import { getSessionId } from "../../helpers/sessionId.js";
52
- import { getVisitorId } from "../../helpers/visitorId.js";
53
- import { isBrowser } from "../is-browser.js";
54
- import { isEditing } from "../is-editing.js";
55
- import { getUserAttributes } from "./helpers.js";
56
- const getTrackingEventData = _0 => __async(void 0, [_0], function* ({
57
- canTrack
58
- }) {
59
- if (!canTrack) {
60
- return {
61
- visitorId: void 0,
62
- sessionId: void 0
63
- };
64
- }
65
- const sessionId = yield getSessionId({
66
- canTrack
67
- });
68
- const visitorId = getVisitorId({
69
- canTrack
70
- });
71
- return {
72
- sessionId,
73
- visitorId
74
- };
75
- });
76
- const createEvent = _a => __async(void 0, null, function* () {
77
- var _b = _a,
78
- {
79
- type: eventType,
80
- canTrack,
81
- apiKey,
82
- metadata
83
- } = _b,
84
- properties = __objRest(_b, ["type", "canTrack", "apiKey", "metadata"]);
85
- return {
86
- type: eventType,
87
- data: __spreadProps(__spreadValues(__spreadProps(__spreadValues({}, properties), {
88
- metadata: __spreadValues({
89
- url: location.href
90
- }, metadata)
91
- }), yield getTrackingEventData({
92
- canTrack
93
- })), {
94
- userAttributes: getUserAttributes(),
95
- ownerId: apiKey
96
- })
97
- };
98
- });
99
- function _track(eventProps) {
100
- return __async(this, null, function* () {
101
- if (!eventProps.apiKey) {
102
- logger.error("Missing API key for track call. Please provide your API key.");
103
- return;
104
- }
105
- if (!eventProps.canTrack) {
106
- return;
107
- }
108
- if (isEditing()) {
109
- return;
110
- }
111
- if (!(isBrowser() || TARGET === "reactNative")) {
112
- return;
113
- }
114
- return fetch(`https://cdn.builder.io/api/v1/track`, {
115
- method: "POST",
116
- body: JSON.stringify({
117
- events: [yield createEvent(eventProps)]
118
- }),
119
- headers: {
120
- "content-type": "application/json"
121
- },
122
- mode: "cors"
123
- }).catch(err => {
124
- console.error("Failed to track: ", err);
125
- });
126
- });
127
- }
128
- const track = args => _track(__spreadProps(__spreadValues({}, args), {
129
- canTrack: true
130
- }));
131
- export { _track, track }
@@ -1,57 +0,0 @@
1
- function round(num) {
2
- return Math.round(num * 1e3) / 1e3;
3
- }
4
- const findParentElement = (target, callback, checkElement = true) => {
5
- if (!(target instanceof HTMLElement)) {
6
- return null;
7
- }
8
- let parent = checkElement ? target : target.parentElement;
9
- do {
10
- if (!parent) {
11
- return null;
12
- }
13
- const matches = callback(parent);
14
- if (matches) {
15
- return parent;
16
- }
17
- } while (parent = parent.parentElement);
18
- return null;
19
- };
20
- const findBuilderParent = target => findParentElement(target, el => {
21
- const id = el.getAttribute("builder-id") || el.id;
22
- return Boolean((id == null ? void 0 : id.indexOf("builder-")) === 0);
23
- });
24
- const computeOffset = ({
25
- event,
26
- target
27
- }) => {
28
- const targetRect = target.getBoundingClientRect();
29
- const xOffset = event.clientX - targetRect.left;
30
- const yOffset = event.clientY - targetRect.top;
31
- const xRatio = round(xOffset / targetRect.width);
32
- const yRatio = round(yOffset / targetRect.height);
33
- return {
34
- x: xRatio,
35
- y: yRatio
36
- };
37
- };
38
- const getInteractionPropertiesForEvent = event => {
39
- const target = event.target;
40
- const targetBuilderElement = target && findBuilderParent(target);
41
- const builderId = (targetBuilderElement == null ? void 0 : targetBuilderElement.getAttribute("builder-id")) || (targetBuilderElement == null ? void 0 : targetBuilderElement.id);
42
- return {
43
- targetBuilderElement: builderId || void 0,
44
- metadata: {
45
- targetOffset: target ? computeOffset({
46
- event,
47
- target
48
- }) : void 0,
49
- builderTargetOffset: targetBuilderElement ? computeOffset({
50
- event,
51
- target: targetBuilderElement
52
- }) : void 0,
53
- builderElementIndex: targetBuilderElement && builderId ? [].slice.call(document.getElementsByClassName(builderId)).indexOf(targetBuilderElement) : void 0
54
- }
55
- };
56
- };
57
- export { getInteractionPropertiesForEvent }
@@ -1,4 +0,0 @@
1
- function transformBlockProperties(properties) {
2
- return properties;
3
- }
4
- export { transformBlockProperties }
@@ -1,4 +0,0 @@
1
- function transformBlock(block) {
2
- return block;
3
- }
4
- export { transformBlock }
@@ -1,158 +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, {
6
- enumerable: true,
7
- configurable: true,
8
- writable: true,
9
- value
10
- }) : obj[key] = value;
11
- var __spreadValues = (a, b) => {
12
- for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
13
- if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
15
- }
16
- return a;
17
- };
18
- var __async = (__this, __arguments, generator) => {
19
- return new Promise((resolve, reject) => {
20
- var fulfilled = value => {
21
- try {
22
- step(generator.next(value));
23
- } catch (e) {
24
- reject(e);
25
- }
26
- };
27
- var rejected = value => {
28
- try {
29
- step(generator.throw(value));
30
- } catch (e) {
31
- reject(e);
32
- }
33
- };
34
- var step = x => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
35
- step((generator = generator.apply(__this, __arguments)).next());
36
- });
37
- };
38
- import { getCookie, getCookieSync, setCookie } from "./cookie.js";
39
- import { checkIsDefined } from "../helpers/nullable.js";
40
- import { logger } from "./logger.js";
41
- import { TARGET } from "../constants/target.js";
42
- const BUILDER_STORE_PREFIX = "builder.tests";
43
- const getContentTestKey = id => `${BUILDER_STORE_PREFIX}.${id}`;
44
- const getContentVariationCookie = ({
45
- contentId
46
- }) => getCookie({
47
- name: getContentTestKey(contentId),
48
- canTrack: true
49
- });
50
- const getContentVariationCookieSync = ({
51
- contentId
52
- }) => getCookieSync({
53
- name: getContentTestKey(contentId),
54
- canTrack: true
55
- });
56
- const setContentVariationCookie = ({
57
- contentId,
58
- value
59
- }) => setCookie({
60
- name: getContentTestKey(contentId),
61
- value,
62
- canTrack: true
63
- });
64
- const checkIsBuilderContentWithVariations = item => checkIsDefined(item.id) && checkIsDefined(item.variations) && Object.keys(item.variations).length > 0;
65
- const getRandomVariationId = ({
66
- id,
67
- variations
68
- }) => {
69
- var _a;
70
- let n = 0;
71
- const random = Math.random();
72
- for (const id2 in variations) {
73
- const testRatio = (_a = variations[id2]) == null ? void 0 : _a.testRatio;
74
- n += testRatio;
75
- if (random < n) {
76
- return id2;
77
- }
78
- }
79
- return id;
80
- };
81
- const getAndSetVariantId = args => {
82
- const randomVariationId = getRandomVariationId(args);
83
- setContentVariationCookie({
84
- contentId: args.id,
85
- value: randomVariationId
86
- }).catch(err => {
87
- logger.error("could not store A/B test variation: ", err);
88
- });
89
- return randomVariationId;
90
- };
91
- const getTestFields = ({
92
- item,
93
- testGroupId
94
- }) => {
95
- const variationValue = item.variations[testGroupId];
96
- if (testGroupId === item.id || !variationValue) {
97
- return {
98
- testVariationId: item.id,
99
- testVariationName: "Default"
100
- };
101
- } else {
102
- return {
103
- data: variationValue.data,
104
- testVariationId: variationValue.id,
105
- testVariationName: variationValue.name || (variationValue.id === item.id ? "Default" : "")
106
- };
107
- }
108
- };
109
- const handleABTestingSync = ({
110
- item,
111
- canTrack
112
- }) => {
113
- if (TARGET === "reactNative") return item;
114
- if (!canTrack) {
115
- return item;
116
- }
117
- if (!item) {
118
- return void 0;
119
- }
120
- if (!checkIsBuilderContentWithVariations(item)) {
121
- return item;
122
- }
123
- const testGroupId = getContentVariationCookieSync({
124
- contentId: item.id
125
- }) || getAndSetVariantId({
126
- variations: item.variations,
127
- id: item.id
128
- });
129
- const variationValue = getTestFields({
130
- item,
131
- testGroupId
132
- });
133
- return __spreadValues(__spreadValues({}, item), variationValue);
134
- };
135
- const handleABTesting = _0 => __async(void 0, [_0], function* ({
136
- item,
137
- canTrack
138
- }) {
139
- if (!canTrack) {
140
- return item;
141
- }
142
- if (!checkIsBuilderContentWithVariations(item)) {
143
- return item;
144
- }
145
- const cookieValue = yield getContentVariationCookie({
146
- contentId: item.id
147
- });
148
- const testGroupId = cookieValue || getAndSetVariantId({
149
- variations: item.variations,
150
- id: item.id
151
- });
152
- const variationValue = getTestFields({
153
- item,
154
- testGroupId
155
- });
156
- return __spreadValues(__spreadValues({}, item), variationValue);
157
- });
158
- export { handleABTesting, handleABTestingSync }
@@ -1,3 +0,0 @@
1
- import { checkIsDefined } from "./nullable.js";
2
- const getDefaultCanTrack = canTrack => checkIsDefined(canTrack) ? canTrack : true;
3
- export { getDefaultCanTrack }