@builder.io/sdk-react 0.2.3-4 → 0.3.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 (288) hide show
  1. package/README.md +72 -3
  2. package/dist/sdk/blocks/columns/columns.js +5 -5
  3. package/dist/sdk/blocks/image/image.js +8 -7
  4. package/dist/sdk/blocks/symbol/symbol.js +3 -2
  5. package/dist/sdk/blocks/video/video.js +4 -1
  6. package/dist/sdk/components/render-block/block-styles.js +3 -1
  7. package/dist/sdk/components/render-block/render-block.helpers.d.ts +0 -1
  8. package/dist/sdk/components/render-block/render-block.helpers.js +8 -20
  9. package/dist/sdk/components/render-block/render-block.js +24 -15
  10. package/dist/sdk/components/render-block/render-repeated-block.js +3 -2
  11. package/dist/sdk/components/render-content/render-content.js +31 -12
  12. package/dist/sdk/components/render-content-variants/helpers.d.ts +12 -0
  13. package/dist/sdk/components/render-content-variants/helpers.js +154 -0
  14. package/dist/sdk/components/render-content-variants/render-content-variants.d.ts +5 -0
  15. package/dist/sdk/components/render-content-variants/render-content-variants.js +29 -0
  16. package/dist/sdk/components/render-inlined-styles.js +2 -2
  17. package/dist/sdk/constants/sdk-version.d.ts +1 -0
  18. package/dist/sdk/constants/sdk-version.js +1 -0
  19. package/dist/sdk/context/builder.context.js +3 -2
  20. package/dist/sdk/context/types.d.ts +17 -2
  21. package/dist/sdk/functions/evaluate.d.ts +4 -3
  22. package/dist/sdk/functions/evaluate.js +23 -2
  23. package/dist/sdk/functions/evaluate.test.d.ts +1 -0
  24. package/dist/sdk/functions/evaluate.test.js +17 -0
  25. package/dist/sdk/functions/get-block-actions-handler.d.ts +1 -1
  26. package/dist/sdk/functions/get-block-actions-handler.js +3 -1
  27. package/dist/sdk/functions/get-block-actions.d.ts +1 -1
  28. package/dist/sdk/functions/get-processed-block.d.ts +2 -2
  29. package/dist/sdk/functions/get-processed-block.js +16 -4
  30. package/dist/sdk/functions/get-processed-block.test.js +3 -1
  31. package/dist/sdk/helpers/canTrack.d.ts +1 -0
  32. package/dist/sdk/helpers/canTrack.js +2 -0
  33. package/dist/sdk/index.d.ts +1 -0
  34. package/dist/sdk/scripts/init-editing.js +2 -0
  35. package/package.json +5 -5
  36. package/CHANGELOG.md +0 -25
  37. package/packages/react/src/blocks/BaseText.tsx +0 -19
  38. package/packages/react/src/blocks/button/button.tsx +0 -45
  39. package/packages/react/src/blocks/button/component-info.ts +0 -42
  40. package/packages/react/src/blocks/columns/columns.tsx +0 -211
  41. package/packages/react/src/blocks/columns/component-info.ts +0 -254
  42. package/packages/react/src/blocks/custom-code/component-info.ts +0 -31
  43. package/packages/react/src/blocks/custom-code/custom-code.tsx +0 -76
  44. package/packages/react/src/blocks/embed/component-info.ts +0 -55
  45. package/packages/react/src/blocks/embed/embed.tsx +0 -59
  46. package/packages/react/src/blocks/embed/helpers.ts +0 -8
  47. package/packages/react/src/blocks/form/component-info.ts +0 -282
  48. package/packages/react/src/blocks/form/form.tsx +0 -320
  49. package/packages/react/src/blocks/fragment/component-info.ts +0 -10
  50. package/packages/react/src/blocks/fragment/fragment.tsx +0 -14
  51. package/packages/react/src/blocks/image/component-info.ts +0 -172
  52. package/packages/react/src/blocks/image/image.helpers.ts +0 -75
  53. package/packages/react/src/blocks/image/image.tsx +0 -144
  54. package/packages/react/src/blocks/img/component-info.ts +0 -21
  55. package/packages/react/src/blocks/img/img.tsx +0 -40
  56. package/packages/react/src/blocks/input/component-info.ts +0 -78
  57. package/packages/react/src/blocks/input/input.tsx +0 -33
  58. package/packages/react/src/blocks/raw-text/component-info.ts +0 -15
  59. package/packages/react/src/blocks/raw-text/raw-text.tsx +0 -18
  60. package/packages/react/src/blocks/section/component-info.ts +0 -50
  61. package/packages/react/src/blocks/section/section.tsx +0 -33
  62. package/packages/react/src/blocks/select/component-info.ts +0 -61
  63. package/packages/react/src/blocks/select/select.tsx +0 -35
  64. package/packages/react/src/blocks/submit-button/component-info.ts +0 -32
  65. package/packages/react/src/blocks/submit-button/submit-button.tsx +0 -17
  66. package/packages/react/src/blocks/symbol/component-info.ts +0 -43
  67. package/packages/react/src/blocks/symbol/symbol.tsx +0 -111
  68. package/packages/react/src/blocks/text/component-info.ts +0 -24
  69. package/packages/react/src/blocks/text/text.tsx +0 -20
  70. package/packages/react/src/blocks/textarea/component-info.ts +0 -48
  71. package/packages/react/src/blocks/textarea/textarea.tsx +0 -24
  72. package/packages/react/src/blocks/util.ts +0 -18
  73. package/packages/react/src/blocks/video/component-info.ts +0 -109
  74. package/packages/react/src/blocks/video/video.tsx +0 -84
  75. package/packages/react/src/components/render-block/block-styles.tsx +0 -98
  76. package/packages/react/src/components/render-block/render-block.helpers.ts +0 -138
  77. package/packages/react/src/components/render-block/render-block.tsx +0 -216
  78. package/packages/react/src/components/render-block/render-component.tsx +0 -52
  79. package/packages/react/src/components/render-block/render-repeated-block.tsx +0 -43
  80. package/packages/react/src/components/render-block/types.ts +0 -7
  81. package/packages/react/src/components/render-blocks.tsx +0 -97
  82. package/packages/react/src/components/render-content/builder-editing.tsx +0 -8
  83. package/packages/react/src/components/render-content/components/render-styles.helpers.ts +0 -79
  84. package/packages/react/src/components/render-content/components/render-styles.tsx +0 -45
  85. package/packages/react/src/components/render-content/index.ts +0 -1
  86. package/packages/react/src/components/render-content/render-content.helpers.ts +0 -48
  87. package/packages/react/src/components/render-content/render-content.tsx +0 -410
  88. package/packages/react/src/components/render-content/render-content.types.ts +0 -33
  89. package/packages/react/src/components/render-inlined-styles.tsx +0 -36
  90. package/packages/react/src/constants/builder-registered-components.ts +0 -42
  91. package/packages/react/src/constants/device-sizes.ts +0 -65
  92. package/packages/react/src/constants/target.ts +0 -2
  93. package/packages/react/src/context/builder.context.ts +0 -12
  94. package/packages/react/src/context/types.ts +0 -26
  95. package/packages/react/src/functions/camel-to-kebab-case.ts +0 -2
  96. package/packages/react/src/functions/evaluate.ts +0 -57
  97. package/packages/react/src/functions/event-handler-name.ts +0 -6
  98. package/packages/react/src/functions/extract-text-styles.ts +0 -39
  99. package/packages/react/src/functions/fast-clone.ts +0 -5
  100. package/packages/react/src/functions/get-block-actions-handler.ts +0 -20
  101. package/packages/react/src/functions/get-block-actions.ts +0 -25
  102. package/packages/react/src/functions/get-block-component-options.ts +0 -12
  103. package/packages/react/src/functions/get-block-properties.ts +0 -75
  104. package/packages/react/src/functions/get-builder-search-params/fn.test.ts +0 -19
  105. package/packages/react/src/functions/get-builder-search-params/index.ts +0 -50
  106. package/packages/react/src/functions/get-content/ab-testing.ts +0 -132
  107. package/packages/react/src/functions/get-content/generate-content-url.test.ts +0 -95
  108. package/packages/react/src/functions/get-content/generate-content-url.ts +0 -59
  109. package/packages/react/src/functions/get-content/index.ts +0 -62
  110. package/packages/react/src/functions/get-content/types.ts +0 -53
  111. package/packages/react/src/functions/get-fetch.ts +0 -18
  112. package/packages/react/src/functions/get-global-this.ts +0 -17
  113. package/packages/react/src/functions/get-processed-block.test.ts +0 -33
  114. package/packages/react/src/functions/get-processed-block.ts +0 -54
  115. package/packages/react/src/functions/get-react-native-block-styles.ts +0 -33
  116. package/packages/react/src/functions/if-target.ts +0 -20
  117. package/packages/react/src/functions/is-browser.ts +0 -3
  118. package/packages/react/src/functions/is-editing.ts +0 -10
  119. package/packages/react/src/functions/is-iframe.ts +0 -5
  120. package/packages/react/src/functions/is-previewing.ts +0 -14
  121. package/packages/react/src/functions/on-change.test.ts +0 -23
  122. package/packages/react/src/functions/on-change.ts +0 -29
  123. package/packages/react/src/functions/register-component.ts +0 -50
  124. package/packages/react/src/functions/register.ts +0 -46
  125. package/packages/react/src/functions/sanitize-react-native-block-styles.ts +0 -65
  126. package/packages/react/src/functions/set-editor-settings.ts +0 -16
  127. package/packages/react/src/functions/set.test.ts +0 -19
  128. package/packages/react/src/functions/set.ts +0 -26
  129. package/packages/react/src/functions/track/helpers.ts +0 -67
  130. package/packages/react/src/functions/track/index.ts +0 -136
  131. package/packages/react/src/functions/track/interaction.ts +0 -80
  132. package/packages/react/src/functions/transform-block-properties.ts +0 -3
  133. package/packages/react/src/functions/transform-block.ts +0 -6
  134. package/packages/react/src/helpers/ab-tests.ts +0 -22
  135. package/packages/react/src/helpers/cookie.ts +0 -107
  136. package/packages/react/src/helpers/css.ts +0 -42
  137. package/packages/react/src/helpers/flatten.ts +0 -24
  138. package/packages/react/src/helpers/localStorage.ts +0 -40
  139. package/packages/react/src/helpers/logger.ts +0 -6
  140. package/packages/react/src/helpers/nullable.ts +0 -4
  141. package/packages/react/src/helpers/sessionId.ts +0 -38
  142. package/packages/react/src/helpers/time.ts +0 -4
  143. package/packages/react/src/helpers/url.test.ts +0 -23
  144. package/packages/react/src/helpers/url.ts +0 -16
  145. package/packages/react/src/helpers/uuid.ts +0 -17
  146. package/packages/react/src/helpers/visitorId.ts +0 -40
  147. package/packages/react/src/index-helpers/blocks-exports.ts +0 -10
  148. package/packages/react/src/index-helpers/top-of-file.ts +0 -4
  149. package/packages/react/src/index.ts +0 -14
  150. package/packages/react/src/scripts/init-editing.ts +0 -123
  151. package/packages/react/src/types/api-version.ts +0 -2
  152. package/packages/react/src/types/builder-block.ts +0 -69
  153. package/packages/react/src/types/builder-content.ts +0 -46
  154. package/packages/react/src/types/can-track.ts +0 -3
  155. package/packages/react/src/types/components.ts +0 -117
  156. package/packages/react/src/types/deep-partial.ts +0 -7
  157. package/packages/react/src/types/element.ts +0 -60
  158. package/packages/react/src/types/input.ts +0 -125
  159. package/packages/react/src/types/targets.ts +0 -6
  160. package/packages/react/src/types/typescript.ts +0 -7
  161. package/packages/rsc/src/blocks/BaseText.jsx +0 -12
  162. package/packages/rsc/src/blocks/button/button.jsx +0 -37
  163. package/packages/rsc/src/blocks/button/component-info.js +0 -40
  164. package/packages/rsc/src/blocks/columns/columns.jsx +0 -172
  165. package/packages/rsc/src/blocks/columns/component-info.js +0 -241
  166. package/packages/rsc/src/blocks/custom-code/component-info.js +0 -30
  167. package/packages/rsc/src/blocks/custom-code/custom-code.jsx +0 -57
  168. package/packages/rsc/src/blocks/embed/component-info.js +0 -43
  169. package/packages/rsc/src/blocks/embed/embed.jsx +0 -45
  170. package/packages/rsc/src/blocks/embed/helpers.js +0 -9
  171. package/packages/rsc/src/blocks/form/component-info.js +0 -261
  172. package/packages/rsc/src/blocks/form/form.jsx +0 -260
  173. package/packages/rsc/src/blocks/fragment/component-info.js +0 -10
  174. package/packages/rsc/src/blocks/fragment/fragment.jsx +0 -9
  175. package/packages/rsc/src/blocks/image/component-info.js +0 -150
  176. package/packages/rsc/src/blocks/image/image.helpers.js +0 -48
  177. package/packages/rsc/src/blocks/image/image.jsx +0 -122
  178. package/packages/rsc/src/blocks/img/component-info.js +0 -19
  179. package/packages/rsc/src/blocks/img/img.jsx +0 -21
  180. package/packages/rsc/src/blocks/input/component-info.js +0 -73
  181. package/packages/rsc/src/blocks/input/input.jsx +0 -23
  182. package/packages/rsc/src/blocks/raw-text/component-info.js +0 -15
  183. package/packages/rsc/src/blocks/raw-text/raw-text.jsx +0 -14
  184. package/packages/rsc/src/blocks/section/component-info.js +0 -48
  185. package/packages/rsc/src/blocks/section/section.jsx +0 -27
  186. package/packages/rsc/src/blocks/select/component-info.js +0 -58
  187. package/packages/rsc/src/blocks/select/select.jsx +0 -24
  188. package/packages/rsc/src/blocks/submit-button/component-info.js +0 -27
  189. package/packages/rsc/src/blocks/submit-button/submit-button.jsx +0 -13
  190. package/packages/rsc/src/blocks/symbol/component-info.js +0 -42
  191. package/packages/rsc/src/blocks/symbol/symbol.jsx +0 -89
  192. package/packages/rsc/src/blocks/text/component-info.js +0 -23
  193. package/packages/rsc/src/blocks/text/text.jsx +0 -17
  194. package/packages/rsc/src/blocks/textarea/component-info.js +0 -46
  195. package/packages/rsc/src/blocks/textarea/textarea.jsx +0 -17
  196. package/packages/rsc/src/blocks/util.js +0 -8
  197. package/packages/rsc/src/blocks/video/component-info.js +0 -105
  198. package/packages/rsc/src/blocks/video/video.jsx +0 -63
  199. package/packages/rsc/src/components/render-block/block-styles.jsx +0 -88
  200. package/packages/rsc/src/components/render-block/render-block.helpers.js +0 -129
  201. package/packages/rsc/src/components/render-block/render-block.jsx +0 -201
  202. package/packages/rsc/src/components/render-block/render-component.jsx +0 -39
  203. package/packages/rsc/src/components/render-block/render-repeated-block.jsx +0 -27
  204. package/packages/rsc/src/components/render-block/types.js +0 -0
  205. package/packages/rsc/src/components/render-blocks.jsx +0 -92
  206. package/packages/rsc/src/components/render-content/builder-editing.jsx +0 -64
  207. package/packages/rsc/src/components/render-content/components/render-styles.helpers.js +0 -57
  208. package/packages/rsc/src/components/render-content/components/render-styles.jsx +0 -39
  209. package/packages/rsc/src/components/render-content/index.js +0 -4
  210. package/packages/rsc/src/components/render-content/render-content.helpers.js +0 -48
  211. package/packages/rsc/src/components/render-content/render-content.jsx +0 -253
  212. package/packages/rsc/src/components/render-content/render-content.types.js +0 -0
  213. package/packages/rsc/src/components/render-inlined-styles.jsx +0 -33
  214. package/packages/rsc/src/constants/builder-registered-components.js +0 -54
  215. package/packages/rsc/src/constants/device-sizes.js +0 -48
  216. package/packages/rsc/src/constants/target.js +0 -4
  217. package/packages/rsc/src/context/builder.context.js +0 -14
  218. package/packages/rsc/src/context/types.js +0 -0
  219. package/packages/rsc/src/functions/camel-to-kebab-case.js +0 -4
  220. package/packages/rsc/src/functions/evaluate.js +0 -6
  221. package/packages/rsc/src/functions/event-handler-name.js +0 -7
  222. package/packages/rsc/src/functions/extract-text-styles.js +0 -22
  223. package/packages/rsc/src/functions/fast-clone.js +0 -4
  224. package/packages/rsc/src/functions/get-block-actions-handler.js +0 -11
  225. package/packages/rsc/src/functions/get-block-actions.js +0 -18
  226. package/packages/rsc/src/functions/get-block-component-options.js +0 -28
  227. package/packages/rsc/src/functions/get-block-properties.js +0 -53
  228. package/packages/rsc/src/functions/get-builder-search-params/fn.test.js +0 -13
  229. package/packages/rsc/src/functions/get-builder-search-params/index.js +0 -38
  230. package/packages/rsc/src/functions/get-content/ab-testing.js +0 -99
  231. package/packages/rsc/src/functions/get-content/generate-content-url.js +0 -60
  232. package/packages/rsc/src/functions/get-content/generate-content-url.test.js +0 -82
  233. package/packages/rsc/src/functions/get-content/index.js +0 -83
  234. package/packages/rsc/src/functions/get-content/types.js +0 -0
  235. package/packages/rsc/src/functions/get-fetch.js +0 -14
  236. package/packages/rsc/src/functions/get-global-this.js +0 -18
  237. package/packages/rsc/src/functions/get-processed-block.js +0 -59
  238. package/packages/rsc/src/functions/get-processed-block.test.js +0 -32
  239. package/packages/rsc/src/functions/get-react-native-block-styles.js +0 -33
  240. package/packages/rsc/src/functions/if-target.js +0 -15
  241. package/packages/rsc/src/functions/is-browser.js +0 -6
  242. package/packages/rsc/src/functions/is-editing.js +0 -8
  243. package/packages/rsc/src/functions/is-iframe.js +0 -7
  244. package/packages/rsc/src/functions/is-previewing.js +0 -14
  245. package/packages/rsc/src/functions/on-change.js +0 -27
  246. package/packages/rsc/src/functions/on-change.test.js +0 -19
  247. package/packages/rsc/src/functions/register-component.js +0 -68
  248. package/packages/rsc/src/functions/register.js +0 -29
  249. package/packages/rsc/src/functions/sanitize-react-native-block-styles.js +0 -66
  250. package/packages/rsc/src/functions/set-editor-settings.js +0 -15
  251. package/packages/rsc/src/functions/set.js +0 -11
  252. package/packages/rsc/src/functions/set.test.js +0 -16
  253. package/packages/rsc/src/functions/track/helpers.js +0 -50
  254. package/packages/rsc/src/functions/track/index.js +0 -129
  255. package/packages/rsc/src/functions/track/interaction.js +0 -53
  256. package/packages/rsc/src/functions/transform-block-properties.js +0 -6
  257. package/packages/rsc/src/functions/transform-block.js +0 -6
  258. package/packages/rsc/src/helpers/ab-tests.js +0 -16
  259. package/packages/rsc/src/helpers/cookie.js +0 -81
  260. package/packages/rsc/src/helpers/css.js +0 -34
  261. package/packages/rsc/src/helpers/flatten.js +0 -34
  262. package/packages/rsc/src/helpers/localStorage.js +0 -35
  263. package/packages/rsc/src/helpers/logger.js +0 -9
  264. package/packages/rsc/src/helpers/nullable.js +0 -4
  265. package/packages/rsc/src/helpers/sessionId.js +0 -52
  266. package/packages/rsc/src/helpers/time.js +0 -5
  267. package/packages/rsc/src/helpers/url.js +0 -13
  268. package/packages/rsc/src/helpers/url.test.js +0 -21
  269. package/packages/rsc/src/helpers/uuid.js +0 -13
  270. package/packages/rsc/src/helpers/visitorId.js +0 -34
  271. package/packages/rsc/src/index-helpers/blocks-exports.js +0 -22
  272. package/packages/rsc/src/index-helpers/top-of-file.js +0 -2
  273. package/packages/rsc/src/index.js +0 -13
  274. package/packages/rsc/src/scripts/init-editing.js +0 -93
  275. package/packages/rsc/src/types/api-version.js +0 -4
  276. package/packages/rsc/src/types/builder-block.js +0 -0
  277. package/packages/rsc/src/types/builder-content.js +0 -0
  278. package/packages/rsc/src/types/can-track.js +0 -0
  279. package/packages/rsc/src/types/components.js +0 -0
  280. package/packages/rsc/src/types/deep-partial.js +0 -0
  281. package/packages/rsc/src/types/element.js +0 -0
  282. package/packages/rsc/src/types/input.js +0 -0
  283. package/packages/rsc/src/types/targets.js +0 -0
  284. package/packages/rsc/src/types/typescript.js +0 -0
  285. package/tsconfig.json +0 -28
  286. package/tsconfig.sdk.json +0 -10
  287. package/tsconfig.server.json +0 -10
  288. package/vite.config.ts +0 -91
@@ -1,67 +0,0 @@
1
- import { TARGET } from '../../constants/target';
2
- import type { Nullable } from '../../helpers/nullable';
3
- import { isBrowser } from '../is-browser';
4
-
5
- const getLocation = (): Nullable<URL> => {
6
- if (TARGET === 'reactNative') {
7
- return null;
8
- } else if (isBrowser()) {
9
- const parsedLocation = new URL(location.href);
10
-
11
- // IE11 bug with parsed path being empty string
12
- // causes issues with our user targeting
13
- if (parsedLocation.pathname === '') {
14
- parsedLocation.pathname = '/';
15
- }
16
-
17
- return parsedLocation;
18
- } else {
19
- console.warn('Cannot get location for tracking in non-browser environment');
20
- return null;
21
- }
22
- };
23
-
24
- const getUserAgent = () =>
25
- (typeof navigator === 'object' && navigator.userAgent) || '';
26
-
27
- export const getUserAttributes = () => {
28
- const userAgent = getUserAgent();
29
-
30
- const isMobile = {
31
- Android() {
32
- return userAgent.match(/Android/i);
33
- },
34
- BlackBerry() {
35
- return userAgent.match(/BlackBerry/i);
36
- },
37
- iOS() {
38
- return userAgent.match(/iPhone|iPod/i);
39
- },
40
- Opera() {
41
- return userAgent.match(/Opera Mini/i);
42
- },
43
- Windows() {
44
- return userAgent.match(/IEMobile/i) || userAgent.match(/WPDesktop/i);
45
- },
46
- any() {
47
- return (
48
- isMobile.Android() ||
49
- isMobile.BlackBerry() ||
50
- isMobile.iOS() ||
51
- isMobile.Opera() ||
52
- isMobile.Windows() ||
53
- TARGET === 'reactNative'
54
- );
55
- },
56
- };
57
-
58
- const isTablet = userAgent.match(/Tablet|iPad/i);
59
-
60
- const url = getLocation();
61
-
62
- return {
63
- urlPath: url?.pathname,
64
- host: url?.host || url?.hostname,
65
- device: isTablet ? 'tablet' : isMobile.any() ? 'mobile' : 'desktop',
66
- };
67
- };
@@ -1,136 +0,0 @@
1
- import { TARGET } from '../../constants/target.js';
2
- import { logger } from '../../helpers/logger.js';
3
- import { getSessionId } from '../../helpers/sessionId.js';
4
- import { getVisitorId } from '../../helpers/visitorId.js';
5
- import type { CanTrack } from '../../types/can-track.js';
6
- import type { Dictionary } from '../../types/typescript.js';
7
- import { isBrowser } from '../is-browser.js';
8
- import { isEditing } from '../is-editing.js';
9
- import { getUserAttributes } from './helpers.js';
10
-
11
- interface Event {
12
- /**
13
- * The type of your event.
14
- *
15
- * Examples: `click`, `conversion`, `pageview`, `impression`
16
- */
17
- type: string;
18
- data: {
19
- /**
20
- * (Optional) The content's ID. Useful if this event pertains to a specific piece of content.
21
- */
22
- contentId?: string;
23
- /**
24
- * This is the ID of the space that the content belongs to.
25
- */
26
- ownerId: string;
27
- /**
28
- * (Optional) metadata that you want to provide with your event.
29
- */
30
- metadata?: Dictionary<any>;
31
- /**
32
- * Session ID of the user. This is provided by the SDK by checking session storage.
33
- */
34
- sessionId: string | undefined;
35
- /**
36
- * Visitor ID of the user. This is provided by the SDK by checking cookies.
37
- */
38
- visitorId: string | undefined;
39
- /**
40
- * (Optional) If running an A/B test, the ID of the variation that the user is in.
41
- */
42
- variationId?: string;
43
- [index: string]: any;
44
- };
45
- }
46
-
47
- type TrackingData = {
48
- visitorId: string | undefined;
49
- sessionId: string | undefined;
50
- };
51
-
52
- const getTrackingEventData = async ({
53
- canTrack,
54
- }: CanTrack): Promise<TrackingData> => {
55
- if (!canTrack) {
56
- return { visitorId: undefined, sessionId: undefined };
57
- }
58
-
59
- const sessionId = await getSessionId({ canTrack });
60
- const visitorId = getVisitorId({ canTrack });
61
-
62
- return {
63
- sessionId,
64
- visitorId,
65
- };
66
- };
67
-
68
- type EventProperties = Pick<Event, 'type'> &
69
- Pick<Event['data'], 'contentId' | 'variationId' | 'metadata'> & {
70
- /**
71
- * Your organization's API key.
72
- */
73
- apiKey: Event['data']['ownerId'];
74
- /**
75
- * (Optional) Any additional (non-metadata) properties to add to the event.
76
- */
77
- [index: string]: any;
78
- };
79
-
80
- export type EventProps = EventProperties & CanTrack;
81
-
82
- const createEvent = async ({
83
- type: eventType,
84
- canTrack,
85
- apiKey,
86
- metadata,
87
- ...properties
88
- }: EventProps): Promise<Event> => ({
89
- type: eventType,
90
- data: {
91
- ...properties,
92
- metadata: {
93
- url: location.href,
94
- ...metadata,
95
- },
96
- ...(await getTrackingEventData({ canTrack })),
97
- userAttributes: getUserAttributes(),
98
- ownerId: apiKey,
99
- },
100
- });
101
-
102
- export async function _track(eventProps: EventProps) {
103
- if (!eventProps.apiKey) {
104
- logger.error(
105
- 'Missing API key for track call. Please provide your API key.'
106
- );
107
- return;
108
- }
109
-
110
- if (!eventProps.canTrack) {
111
- return;
112
- }
113
-
114
- if (isEditing()) {
115
- return;
116
- }
117
- if (!(isBrowser() || TARGET === 'reactNative')) {
118
- return;
119
- }
120
-
121
- return fetch(`https://builder.io/api/v1/track`, {
122
- method: 'POST',
123
- body: JSON.stringify({
124
- events: [await createEvent(eventProps)],
125
- }),
126
- headers: {
127
- 'content-type': 'application/json',
128
- },
129
- mode: 'cors',
130
- }).catch((err) => {
131
- console.error('Failed to track: ', err);
132
- });
133
- }
134
-
135
- export const track = (args: EventProperties) =>
136
- _track({ ...args, canTrack: true });
@@ -1,80 +0,0 @@
1
- function round(num: number) {
2
- return Math.round(num * 1000) / 1000;
3
- }
4
- const findParentElement = (
5
- target: HTMLElement,
6
- callback: (element: HTMLElement) => boolean,
7
- checkElement = true
8
- ): HTMLElement | null => {
9
- if (!(target instanceof HTMLElement)) {
10
- return null;
11
- }
12
- let parent: HTMLElement | null = checkElement ? target : target.parentElement;
13
- do {
14
- if (!parent) {
15
- return null;
16
- }
17
-
18
- const matches = callback(parent);
19
- if (matches) {
20
- return parent;
21
- }
22
- } while ((parent = parent.parentElement));
23
-
24
- return null;
25
- };
26
-
27
- const findBuilderParent = (target: HTMLElement) =>
28
- findParentElement(target, (el) => {
29
- const id = el.getAttribute('builder-id') || el.id;
30
- return Boolean(id?.indexOf('builder-') === 0);
31
- });
32
-
33
- type Offset = {
34
- x: number;
35
- y: number;
36
- };
37
-
38
- const computeOffset = ({
39
- event,
40
- target,
41
- }: {
42
- event: MouseEvent;
43
- target: HTMLElement;
44
- }): Offset => {
45
- const targetRect = target.getBoundingClientRect();
46
- const xOffset = event.clientX - targetRect.left;
47
- const yOffset = event.clientY - targetRect.top;
48
-
49
- const xRatio = round(xOffset / targetRect.width);
50
- const yRatio = round(yOffset / targetRect.height);
51
-
52
- return {
53
- x: xRatio,
54
- y: yRatio,
55
- };
56
- };
57
-
58
- export const getInteractionPropertiesForEvent = (event: MouseEvent) => {
59
- const target = event.target as HTMLElement | null;
60
- const targetBuilderElement = target && findBuilderParent(target);
61
- const builderId =
62
- targetBuilderElement?.getAttribute('builder-id') ||
63
- targetBuilderElement?.id;
64
-
65
- return {
66
- targetBuilderElement: builderId || undefined,
67
- metadata: {
68
- targetOffset: target ? computeOffset({ event, target }) : undefined,
69
- builderTargetOffset: targetBuilderElement
70
- ? computeOffset({ event, target: targetBuilderElement })
71
- : undefined,
72
- builderElementIndex:
73
- targetBuilderElement && builderId
74
- ? ([] as Element[]).slice
75
- .call(document.getElementsByClassName(builderId))
76
- .indexOf(targetBuilderElement)
77
- : undefined,
78
- },
79
- };
80
- };
@@ -1,3 +0,0 @@
1
- export function transformBlockProperties<T>(properties: T) {
2
- return properties;
3
- }
@@ -1,6 +0,0 @@
1
- import type { BuilderBlock } from '../types/builder-block.js';
2
-
3
- // Noope way for targets to make modifications to the block object if/as needed
4
- export function transformBlock(block: BuilderBlock): BuilderBlock {
5
- return block;
6
- }
@@ -1,22 +0,0 @@
1
- import type { CanTrack } from '../types/can-track.js';
2
- import { getCookie, setCookie } from './cookie.js';
3
-
4
- const BUILDER_STORE_PREFIX = 'builderio.variations';
5
-
6
- const getContentTestKey = (id: string) => `${BUILDER_STORE_PREFIX}.${id}`;
7
-
8
- export const getContentVariationCookie = ({
9
- contentId,
10
- canTrack,
11
- }: { contentId: string } & CanTrack) =>
12
- getCookie({ name: getContentTestKey(contentId), canTrack });
13
-
14
- export const setContentVariationCookie = ({
15
- contentId,
16
- canTrack,
17
- value,
18
- }: {
19
- contentId: string;
20
- value: string;
21
- } & CanTrack) =>
22
- setCookie({ name: getContentTestKey(contentId), value, canTrack });
@@ -1,107 +0,0 @@
1
- import { isBrowser } from '../functions/is-browser.js';
2
- import type { CanTrack } from '../types/can-track.js';
3
- import { checkIsDefined } from './nullable.js';
4
- import { getTopLevelDomain } from './url.js';
5
-
6
- /**
7
- * NOTE: This function is `async` because its react-native override is async. Do not remove the `async` keyword!
8
- */
9
- export const getCookie = async ({
10
- name,
11
- canTrack,
12
- }: {
13
- name: string;
14
- } & CanTrack): Promise<string | undefined> => {
15
- try {
16
- if (!canTrack) {
17
- return undefined;
18
- }
19
-
20
- /**
21
- * Extracted from MDN docs
22
- * https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie#example_2_get_a_sample_cookie_named_test2
23
- */
24
- return document.cookie
25
- .split('; ')
26
- .find((row) => row.startsWith(`${name}=`))
27
- ?.split('=')[1];
28
- } catch (err) {
29
- console.debug('[COOKIE] GET error: ', err);
30
- return undefined;
31
- }
32
- };
33
-
34
- type CookieConfiguration = Array<
35
- | ['expires', string]
36
- | ['path', '/']
37
- | ['domain', string]
38
- | ['secure', '']
39
- | ['SameSite', 'None']
40
- | [string, string]
41
- | []
42
- >;
43
-
44
- const stringifyCookie = (cookie: CookieConfiguration): string =>
45
- cookie
46
- .map(([key, value]) => (value ? `${key}=${value}` : key))
47
- .filter(checkIsDefined)
48
- .join('; ');
49
-
50
- const SECURE_CONFIG: CookieConfiguration = [
51
- ['secure', ''],
52
- ['SameSite', 'None'],
53
- ];
54
-
55
- const createCookieString = ({
56
- name,
57
- value,
58
- expires,
59
- }: {
60
- name: string;
61
- value: string;
62
- expires?: Date;
63
- }) => {
64
- const secure = isBrowser() ? location.protocol === 'https:' : true;
65
-
66
- const secureObj: CookieConfiguration = secure ? SECURE_CONFIG : [[]];
67
-
68
- // TODO: need to know if secure server side
69
- const expiresObj: CookieConfiguration = expires
70
- ? [['expires', expires.toUTCString()]]
71
- : [[]];
72
-
73
- const cookieValue: CookieConfiguration = [
74
- [name, value],
75
- ...expiresObj,
76
- ['path', '/'],
77
- ['domain', getTopLevelDomain(window.location.hostname)],
78
- ...secureObj,
79
- ];
80
- const cookie = stringifyCookie(cookieValue);
81
-
82
- return cookie;
83
- };
84
-
85
- /**
86
- * NOTE: This function is `async` because its react-native override is async. Do not remove the `async` keyword!
87
- */
88
- export const setCookie = async ({
89
- name,
90
- value,
91
- expires,
92
- canTrack,
93
- }: {
94
- name: string;
95
- value: string;
96
- expires?: Date;
97
- } & CanTrack): Promise<void> => {
98
- try {
99
- if (!canTrack) {
100
- return;
101
- }
102
- const cookie = createCookieString({ name, value, expires });
103
- document.cookie = cookie;
104
- } catch (err) {
105
- console.warn('[COOKIE] SET error: ', err);
106
- }
107
- };
@@ -1,42 +0,0 @@
1
- import { camelToKebabCase } from '../functions/camel-to-kebab-case.js';
2
- import { checkIsDefined } from './nullable.js';
3
-
4
- export const convertStyleMapToCSSArray = (
5
- style: Partial<CSSStyleDeclaration>
6
- ): string[] => {
7
- const cssProps = Object.entries(style).map(([key, value]) => {
8
- if (typeof value === 'string') {
9
- return `${camelToKebabCase(key)}: ${value};`;
10
- } else {
11
- return undefined;
12
- }
13
- });
14
-
15
- return cssProps.filter(checkIsDefined);
16
- };
17
-
18
- export const convertStyleMapToCSS = (
19
- style: Partial<CSSStyleDeclaration>
20
- ): string => convertStyleMapToCSSArray(style).join('\n');
21
-
22
- export const createCssClass = ({
23
- mediaQuery,
24
- className,
25
- styles,
26
- }: {
27
- mediaQuery?: string;
28
- className: string;
29
- styles: Partial<CSSStyleDeclaration>;
30
- }) => {
31
- const cssClass = `.${className} {
32
- ${convertStyleMapToCSS(styles)}
33
- }`;
34
-
35
- if (mediaQuery) {
36
- return `${mediaQuery} {
37
- ${cssClass}
38
- }`;
39
- } else {
40
- return cssClass;
41
- }
42
- };
@@ -1,24 +0,0 @@
1
- /**
2
- * Convert deep object to a flat object with dots
3
- *
4
- * { foo: { bar: 'baz' }} -> { 'foo.bar': 'baz' }
5
- */
6
- export function flatten<T extends Record<string, any>>(
7
- object: T,
8
- path: string | null = null,
9
- separator = '.'
10
- ): T {
11
- return Object.keys(object).reduce((acc: T, key: string): T => {
12
- const value = object[key];
13
- const newPath = [path, key].filter(Boolean).join(separator);
14
- const isObject = [
15
- typeof value === 'object',
16
- value !== null,
17
- !(Array.isArray(value) && value.length === 0),
18
- ].every(Boolean);
19
-
20
- return isObject
21
- ? { ...acc, ...flatten(value, newPath, separator) }
22
- : { ...acc, [newPath]: value };
23
- }, {} as T);
24
- }
@@ -1,40 +0,0 @@
1
- import { isBrowser } from '../functions/is-browser.js';
2
- import type { CanTrack } from '../types/can-track.js';
3
- import type { Nullable } from './nullable.js';
4
-
5
- const getLocalStorage = () =>
6
- isBrowser() && typeof localStorage !== 'undefined' ? localStorage : undefined;
7
-
8
- export const getLocalStorageItem = ({
9
- key,
10
- canTrack,
11
- }: {
12
- key: string;
13
- } & CanTrack): Nullable<string> => {
14
- try {
15
- if (canTrack) {
16
- return getLocalStorage()?.getItem(key);
17
- }
18
- return undefined;
19
- } catch (err) {
20
- console.debug('[LocalStorage] GET error: ', err);
21
- return undefined;
22
- }
23
- };
24
-
25
- export const setLocalStorageItem = ({
26
- key,
27
- canTrack,
28
- value,
29
- }: {
30
- key: string;
31
- value: string;
32
- } & CanTrack) => {
33
- try {
34
- if (canTrack) {
35
- getLocalStorage()?.setItem(key, value);
36
- }
37
- } catch (err) {
38
- console.debug('[LocalStorage] SET error: ', err);
39
- }
40
- };
@@ -1,6 +0,0 @@
1
- const MSG_PREFIX = '[Builder.io]: ';
2
- export const logger = {
3
- log: (...message: any[]) => console.log(MSG_PREFIX, ...message),
4
- error: (...message: any[]) => console.error(MSG_PREFIX, ...message),
5
- warn: (...message: any[]) => console.warn(MSG_PREFIX, ...message),
6
- };
@@ -1,4 +0,0 @@
1
- export type Nullable<T> = T | null | undefined;
2
-
3
- export const checkIsDefined = <T>(maybeT: Nullable<T>): maybeT is T =>
4
- maybeT !== null && maybeT !== undefined;
@@ -1,38 +0,0 @@
1
- import type { CanTrack } from '../types/can-track.js';
2
- import { getCookie, setCookie } from './cookie.js';
3
- import { checkIsDefined } from './nullable.js';
4
- import { uuid } from './uuid.js';
5
-
6
- const SESSION_LOCAL_STORAGE_KEY = 'builderSessionId';
7
-
8
- export const getSessionId = async ({
9
- canTrack,
10
- }: CanTrack): Promise<string | undefined> => {
11
- if (!canTrack) {
12
- return undefined;
13
- }
14
-
15
- const sessionId = await getCookie({
16
- name: SESSION_LOCAL_STORAGE_KEY,
17
- canTrack,
18
- });
19
-
20
- if (checkIsDefined(sessionId)) {
21
- return sessionId;
22
- } else {
23
- const newSessionId = createSessionId();
24
- setSessionId({ id: newSessionId, canTrack });
25
-
26
- return newSessionId;
27
- }
28
- };
29
-
30
- export const createSessionId = () => uuid();
31
-
32
- export const setSessionId = ({
33
- id,
34
- canTrack,
35
- }: {
36
- id: string;
37
- } & CanTrack) =>
38
- setCookie({ name: SESSION_LOCAL_STORAGE_KEY, value: id, canTrack });
@@ -1,4 +0,0 @@
1
- const MINUTE_TO_MILLESECONDS_MULTIPLIER = 60000;
2
-
3
- export const getCurrentDatePlusMinutes = (minutes = 30) =>
4
- new Date(Date.now() + minutes * MINUTE_TO_MILLESECONDS_MULTIPLIER);
@@ -1,23 +0,0 @@
1
- import { getTopLevelDomain } from './url.js';
2
-
3
- describe('getTopLevelDomain', () => {
4
- test('handles root domain', () => {
5
- const output = getTopLevelDomain('example.com');
6
- expect(output).toBe('example.com');
7
- });
8
- test('handles subdomain', () => {
9
- const output = getTopLevelDomain('wwww.example.com');
10
- expect(output).toBe('example.com');
11
- });
12
- test('handles subdomain with long suffix', () => {
13
- const output = getTopLevelDomain('www.example.co.uk');
14
- expect(output).toBe('example.co.uk');
15
- });
16
- test('handles localhost', () => {
17
- const output = getTopLevelDomain('localhost');
18
- expect(output).toBe('localhost');
19
-
20
- const output2 = getTopLevelDomain('127.0.0.1');
21
- expect(output2).toBe('127.0.0.1');
22
- });
23
- });
@@ -1,16 +0,0 @@
1
- /**
2
- * Only gets one level up from hostname
3
- * wwww.example.com -> example.com
4
- * www.example.co.uk -> example.co.uk
5
- */
6
- export const getTopLevelDomain = (host: string) => {
7
- if (host === 'localhost' || host === '127.0.0.1') {
8
- return host;
9
- }
10
-
11
- const parts = host.split('.');
12
- if (parts.length > 2) {
13
- return parts.slice(1).join('.');
14
- }
15
- return host;
16
- };
@@ -1,17 +0,0 @@
1
- /**
2
- * @credit https://stackoverflow.com/a/2117523
3
- */
4
- export function uuidv4() {
5
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
6
- const r = (Math.random() * 16) | 0,
7
- v = c == 'x' ? r : (r & 0x3) | 0x8;
8
- return v.toString(16);
9
- });
10
- }
11
-
12
- /**
13
- * Slightly cleaner and smaller UUIDs
14
- */
15
- export function uuid() {
16
- return uuidv4().replace(/-/g, '');
17
- }
@@ -1,40 +0,0 @@
1
- import type { CanTrack } from '../types/can-track.js';
2
- import { getLocalStorageItem, setLocalStorageItem } from './localStorage.js';
3
- import { checkIsDefined } from './nullable.js';
4
- import { uuid } from './uuid.js';
5
-
6
- const VISITOR_LOCAL_STORAGE_KEY = 'builderVisitorId';
7
-
8
- export const getVisitorId = ({ canTrack }: CanTrack): string | undefined => {
9
- if (!canTrack) {
10
- return undefined;
11
- }
12
-
13
- const visitorId = getLocalStorageItem({
14
- key: VISITOR_LOCAL_STORAGE_KEY,
15
- canTrack,
16
- });
17
-
18
- if (checkIsDefined(visitorId)) {
19
- return visitorId;
20
- } else {
21
- const newVisitorId = createVisitorId();
22
- setVisitorId({ id: newVisitorId, canTrack });
23
-
24
- return newVisitorId;
25
- }
26
- };
27
-
28
- export const createVisitorId = () => uuid();
29
-
30
- export const setVisitorId = ({
31
- id,
32
- canTrack,
33
- }: {
34
- id: string;
35
- } & CanTrack) =>
36
- setLocalStorageItem({
37
- key: VISITOR_LOCAL_STORAGE_KEY,
38
- value: id,
39
- canTrack,
40
- });