@builder.io/sdk-react-nextjs 0.5.9 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (286) hide show
  1. package/lib/browser/USE_CLIENT_BUNDLE-29f9ac5c.js +23 -0
  2. package/lib/browser/USE_CLIENT_BUNDLE-dfa97c43.mjs +664 -0
  3. package/lib/browser/USE_SERVER_BUNDLE-25e181fa.js +1 -0
  4. package/lib/browser/USE_SERVER_BUNDLE-fcd44ecb.mjs +11 -0
  5. package/lib/browser/bundle-5cab6113.js +76 -0
  6. package/lib/browser/bundle-babbd573.mjs +2419 -0
  7. package/lib/browser/index.cjs +1 -0
  8. package/lib/browser/index.mjs +34 -0
  9. package/lib/edge/USE_CLIENT_BUNDLE-3cbb02d5.mjs +664 -0
  10. package/lib/edge/USE_CLIENT_BUNDLE-d0b99f60.js +23 -0
  11. package/lib/edge/USE_SERVER_BUNDLE-4eeb4634.mjs +11 -0
  12. package/lib/edge/USE_SERVER_BUNDLE-bbd89085.js +1 -0
  13. package/lib/edge/bundle-9ed99f98.mjs +4863 -0
  14. package/lib/edge/bundle-e4764e2a.js +96 -0
  15. package/lib/edge/index.cjs +1 -0
  16. package/lib/edge/index.mjs +34 -0
  17. package/lib/node/USE_CLIENT_BUNDLE-29f9ac5c.js +23 -0
  18. package/lib/node/USE_CLIENT_BUNDLE-dfa97c43.mjs +664 -0
  19. package/lib/node/USE_SERVER_BUNDLE-25e181fa.js +1 -0
  20. package/lib/node/USE_SERVER_BUNDLE-fcd44ecb.mjs +11 -0
  21. package/lib/node/bundle-5cab6113.js +76 -0
  22. package/lib/node/bundle-babbd573.mjs +2419 -0
  23. package/lib/node/index.cjs +1 -0
  24. package/lib/node/index.mjs +34 -0
  25. package/package.json +96 -13
  26. package/types/constants/sdk-version.d.ts +1 -0
  27. package/types/functions/deopt.d.ts +4 -0
  28. package/types/functions/evaluate/browser-runtime/index.d.ts +1 -0
  29. package/{dist → types}/functions/fetch-builder-props.d.ts +2 -1
  30. package/{dist → types}/functions/get-content/index.d.ts +4 -5
  31. package/{dist → types}/index-helpers/blocks-exports.d.ts +2 -2
  32. package/dist/blocks/button/button.js +0 -12
  33. package/dist/blocks/button/component-info.js +0 -34
  34. package/dist/blocks/columns/columns.js +0 -119
  35. package/dist/blocks/columns/component-info.js +0 -219
  36. package/dist/blocks/custom-code/component-info.js +0 -23
  37. package/dist/blocks/custom-code/custom-code.js +0 -51
  38. package/dist/blocks/embed/component-info.js +0 -39
  39. package/dist/blocks/embed/embed.js +0 -42
  40. package/dist/blocks/embed/helpers.js +0 -2
  41. package/dist/blocks/fragment/component-info.js +0 -7
  42. package/dist/blocks/fragment/fragment.js +0 -6
  43. package/dist/blocks/helpers.js +0 -40
  44. package/dist/blocks/image/component-info.js +0 -122
  45. package/dist/blocks/image/image.helpers.js +0 -47
  46. package/dist/blocks/image/image.js +0 -82
  47. package/dist/blocks/img/component-info.js +0 -15
  48. package/dist/blocks/img/img.js +0 -10
  49. package/dist/blocks/section/component-info.js +0 -40
  50. package/dist/blocks/section/section.js +0 -17
  51. package/dist/blocks/symbol/component-info.js +0 -34
  52. package/dist/blocks/symbol/symbol.helpers.js +0 -31
  53. package/dist/blocks/symbol/symbol.js +0 -29
  54. package/dist/blocks/text/component-info.js +0 -19
  55. package/dist/blocks/text/text.js +0 -7
  56. package/dist/blocks/video/component-info.js +0 -82
  57. package/dist/blocks/video/video.js +0 -50
  58. package/dist/components/block/block.helpers.js +0 -69
  59. package/dist/components/block/block.js +0 -92
  60. package/dist/components/block/components/block-styles.js +0 -65
  61. package/dist/components/block/components/block-wrapper.js +0 -36
  62. package/dist/components/block/components/component-ref/component-ref.helpers.js +0 -22
  63. package/dist/components/block/components/component-ref/component-ref.js +0 -21
  64. package/dist/components/block/components/interactive-element.js +0 -20
  65. package/dist/components/block/components/repeated-block.js +0 -7
  66. package/dist/components/block/types.js +0 -1
  67. package/dist/components/blocks/blocks-wrapper.js +0 -38
  68. package/dist/components/blocks/blocks.js +0 -10
  69. package/dist/components/content/components/enable-editor.js +0 -250
  70. package/dist/components/content/components/styles.helpers.js +0 -58
  71. package/dist/components/content/components/styles.js +0 -30
  72. package/dist/components/content/content.helpers.js +0 -30
  73. package/dist/components/content/content.js +0 -74
  74. package/dist/components/content/content.types.js +0 -1
  75. package/dist/components/content/wrap-component-ref.js +0 -6
  76. package/dist/components/content-variants/content-variants.js +0 -45
  77. package/dist/components/content-variants/content-variants.types.js +0 -1
  78. package/dist/components/content-variants/helpers.js +0 -189
  79. package/dist/components/inlined-script.js +0 -5
  80. package/dist/components/inlined-styles.js +0 -5
  81. package/dist/constants/builder-registered-components.js +0 -60
  82. package/dist/constants/device-sizes.js +0 -45
  83. package/dist/constants/sdk-version.d.ts +0 -1
  84. package/dist/constants/sdk-version.js +0 -1
  85. package/dist/constants/target.js +0 -2
  86. package/dist/context/builder.context.js +0 -12
  87. package/dist/context/components.context.js +0 -2
  88. package/dist/context/types.js +0 -1
  89. package/dist/functions/camel-to-kebab-case.js +0 -1
  90. package/dist/functions/evaluate/browser-runtime/browser.js +0 -31
  91. package/dist/functions/evaluate/evaluate.js +0 -47
  92. package/dist/functions/evaluate/helpers.js +0 -10
  93. package/dist/functions/evaluate/index.js +0 -1
  94. package/dist/functions/evaluate/non-node-runtime/acorn-interpreter.d.ts +0 -2
  95. package/dist/functions/evaluate/non-node-runtime/acorn-interpreter.js +0 -3111
  96. package/dist/functions/evaluate/non-node-runtime/index.d.ts +0 -1
  97. package/dist/functions/evaluate/non-node-runtime/index.js +0 -2
  98. package/dist/functions/evaluate/non-node-runtime/non-node-runtime.d.ts +0 -2
  99. package/dist/functions/evaluate/non-node-runtime/non-node-runtime.js +0 -83
  100. package/dist/functions/event-handler-name.js +0 -4
  101. package/dist/functions/extract-text-styles.js +0 -22
  102. package/dist/functions/fast-clone.js +0 -4
  103. package/dist/functions/fetch-builder-props.js +0 -25
  104. package/dist/functions/get-block-actions-handler.js +0 -10
  105. package/dist/functions/get-block-actions.js +0 -28
  106. package/dist/functions/get-block-component-options.js +0 -10
  107. package/dist/functions/get-block-properties.js +0 -72
  108. package/dist/functions/get-builder-search-params/index.js +0 -38
  109. package/dist/functions/get-content/generate-content-url.js +0 -33
  110. package/dist/functions/get-content/index.js +0 -100
  111. package/dist/functions/get-content/types.js +0 -1
  112. package/dist/functions/get-fetch.js +0 -11
  113. package/dist/functions/get-global-this.js +0 -15
  114. package/dist/functions/get-processed-block.js +0 -46
  115. package/dist/functions/get-react-native-block-styles.js +0 -17
  116. package/dist/functions/is-browser.js +0 -3
  117. package/dist/functions/is-editing.js +0 -5
  118. package/dist/functions/is-iframe.js +0 -4
  119. package/dist/functions/is-non-node-server.d.ts +0 -4
  120. package/dist/functions/is-non-node-server.js +0 -8
  121. package/dist/functions/is-previewing.js +0 -11
  122. package/dist/functions/register-component.js +0 -38
  123. package/dist/functions/register.js +0 -27
  124. package/dist/functions/sanitize-react-native-block-styles.js +0 -61
  125. package/dist/functions/set-editor-settings.js +0 -12
  126. package/dist/functions/set.js +0 -14
  127. package/dist/functions/track/helpers.js +0 -51
  128. package/dist/functions/track/index.js +0 -71
  129. package/dist/functions/track/interaction.js +0 -53
  130. package/dist/functions/transform-block-properties.js +0 -5
  131. package/dist/functions/transform-block.js +0 -4
  132. package/dist/helpers/ab-tests.js +0 -122
  133. package/dist/helpers/canTrack.js +0 -2
  134. package/dist/helpers/cookie.js +0 -55
  135. package/dist/helpers/css.js +0 -27
  136. package/dist/helpers/flatten.js +0 -19
  137. package/dist/helpers/localStorage.js +0 -24
  138. package/dist/helpers/logger.js +0 -7
  139. package/dist/helpers/nullable.js +0 -1
  140. package/dist/helpers/preview-lru-cache/get.js +0 -9
  141. package/dist/helpers/preview-lru-cache/helpers.js +0 -9
  142. package/dist/helpers/preview-lru-cache/init.js +0 -15
  143. package/dist/helpers/preview-lru-cache/set.js +0 -7
  144. package/dist/helpers/preview-lru-cache/types.js +0 -6
  145. package/dist/helpers/sessionId.js +0 -30
  146. package/dist/helpers/url.js +0 -15
  147. package/dist/helpers/uuid.js +0 -15
  148. package/dist/helpers/visitorId.js +0 -30
  149. package/dist/index-helpers/blocks-exports.js +0 -19
  150. package/dist/index-helpers/top-of-file.js +0 -4
  151. package/dist/index.js +0 -7
  152. package/dist/scripts/init-editing.js +0 -110
  153. package/dist/server-index.js +0 -10
  154. package/dist/types/api-version.js +0 -1
  155. package/dist/types/builder-block.js +0 -1
  156. package/dist/types/builder-content.js +0 -1
  157. package/dist/types/builder-props.js +0 -1
  158. package/dist/types/can-track.js +0 -1
  159. package/dist/types/components.js +0 -1
  160. package/dist/types/deep-partial.js +0 -1
  161. package/dist/types/element.js +0 -1
  162. package/dist/types/enforced-partials.js +0 -1
  163. package/dist/types/input.js +0 -1
  164. package/dist/types/targets.js +0 -1
  165. package/dist/types/typescript.js +0 -1
  166. /package/{dist → types}/blocks/button/button.d.ts +0 -0
  167. /package/{dist → types}/blocks/button/component-info.d.ts +0 -0
  168. /package/{dist → types}/blocks/columns/columns.d.ts +0 -0
  169. /package/{dist → types}/blocks/columns/component-info.d.ts +0 -0
  170. /package/{dist → types}/blocks/custom-code/component-info.d.ts +0 -0
  171. /package/{dist → types}/blocks/custom-code/custom-code.d.ts +0 -0
  172. /package/{dist → types}/blocks/embed/component-info.d.ts +0 -0
  173. /package/{dist → types}/blocks/embed/embed.d.ts +0 -0
  174. /package/{dist → types}/blocks/embed/helpers.d.ts +0 -0
  175. /package/{dist → types}/blocks/fragment/component-info.d.ts +0 -0
  176. /package/{dist → types}/blocks/fragment/fragment.d.ts +0 -0
  177. /package/{dist → types}/blocks/helpers.d.ts +0 -0
  178. /package/{dist → types}/blocks/image/component-info.d.ts +0 -0
  179. /package/{dist → types}/blocks/image/image.d.ts +0 -0
  180. /package/{dist → types}/blocks/image/image.helpers.d.ts +0 -0
  181. /package/{dist → types}/blocks/img/component-info.d.ts +0 -0
  182. /package/{dist → types}/blocks/img/img.d.ts +0 -0
  183. /package/{dist → types}/blocks/section/component-info.d.ts +0 -0
  184. /package/{dist → types}/blocks/section/section.d.ts +0 -0
  185. /package/{dist → types}/blocks/symbol/component-info.d.ts +0 -0
  186. /package/{dist → types}/blocks/symbol/symbol.d.ts +0 -0
  187. /package/{dist → types}/blocks/symbol/symbol.helpers.d.ts +0 -0
  188. /package/{dist → types}/blocks/text/component-info.d.ts +0 -0
  189. /package/{dist → types}/blocks/text/text.d.ts +0 -0
  190. /package/{dist → types}/blocks/video/component-info.d.ts +0 -0
  191. /package/{dist → types}/blocks/video/video.d.ts +0 -0
  192. /package/{dist → types}/components/block/block.d.ts +0 -0
  193. /package/{dist → types}/components/block/block.helpers.d.ts +0 -0
  194. /package/{dist → types}/components/block/components/block-styles.d.ts +0 -0
  195. /package/{dist → types}/components/block/components/block-wrapper.d.ts +0 -0
  196. /package/{dist → types}/components/block/components/component-ref/component-ref.d.ts +0 -0
  197. /package/{dist → types}/components/block/components/component-ref/component-ref.helpers.d.ts +0 -0
  198. /package/{dist → types}/components/block/components/interactive-element.d.ts +0 -0
  199. /package/{dist → types}/components/block/components/repeated-block.d.ts +0 -0
  200. /package/{dist → types}/components/block/types.d.ts +0 -0
  201. /package/{dist → types}/components/blocks/blocks-wrapper.d.ts +0 -0
  202. /package/{dist → types}/components/blocks/blocks.d.ts +0 -0
  203. /package/{dist → types}/components/content/components/enable-editor.d.ts +0 -0
  204. /package/{dist → types}/components/content/components/styles.d.ts +0 -0
  205. /package/{dist → types}/components/content/components/styles.helpers.d.ts +0 -0
  206. /package/{dist → types}/components/content/content.d.ts +0 -0
  207. /package/{dist → types}/components/content/content.helpers.d.ts +0 -0
  208. /package/{dist → types}/components/content/content.types.d.ts +0 -0
  209. /package/{dist → types}/components/content/wrap-component-ref.d.ts +0 -0
  210. /package/{dist → types}/components/content-variants/content-variants.d.ts +0 -0
  211. /package/{dist → types}/components/content-variants/content-variants.types.d.ts +0 -0
  212. /package/{dist → types}/components/content-variants/helpers.d.ts +0 -0
  213. /package/{dist → types}/components/inlined-script.d.ts +0 -0
  214. /package/{dist → types}/components/inlined-styles.d.ts +0 -0
  215. /package/{dist → types}/constants/builder-registered-components.d.ts +0 -0
  216. /package/{dist → types}/constants/device-sizes.d.ts +0 -0
  217. /package/{dist → types}/constants/target.d.ts +0 -0
  218. /package/{dist → types}/context/builder.context.d.ts +0 -0
  219. /package/{dist → types}/context/components.context.d.ts +0 -0
  220. /package/{dist → types}/context/types.d.ts +0 -0
  221. /package/{dist → types}/functions/camel-to-kebab-case.d.ts +0 -0
  222. /package/{dist → types}/functions/evaluate/browser-runtime/browser.d.ts +0 -0
  223. /package/{dist → types}/functions/evaluate/evaluate.d.ts +0 -0
  224. /package/{dist → types}/functions/evaluate/helpers.d.ts +0 -0
  225. /package/{dist → types}/functions/evaluate/index.d.ts +0 -0
  226. /package/{dist → types}/functions/event-handler-name.d.ts +0 -0
  227. /package/{dist → types}/functions/extract-text-styles.d.ts +0 -0
  228. /package/{dist → types}/functions/fast-clone.d.ts +0 -0
  229. /package/{dist → types}/functions/get-block-actions-handler.d.ts +0 -0
  230. /package/{dist → types}/functions/get-block-actions.d.ts +0 -0
  231. /package/{dist → types}/functions/get-block-component-options.d.ts +0 -0
  232. /package/{dist → types}/functions/get-block-properties.d.ts +0 -0
  233. /package/{dist → types}/functions/get-builder-search-params/index.d.ts +0 -0
  234. /package/{dist → types}/functions/get-content/generate-content-url.d.ts +0 -0
  235. /package/{dist → types}/functions/get-content/types.d.ts +0 -0
  236. /package/{dist → types}/functions/get-fetch.d.ts +0 -0
  237. /package/{dist → types}/functions/get-global-this.d.ts +0 -0
  238. /package/{dist → types}/functions/get-processed-block.d.ts +0 -0
  239. /package/{dist → types}/functions/get-react-native-block-styles.d.ts +0 -0
  240. /package/{dist → types}/functions/is-browser.d.ts +0 -0
  241. /package/{dist → types}/functions/is-editing.d.ts +0 -0
  242. /package/{dist → types}/functions/is-iframe.d.ts +0 -0
  243. /package/{dist → types}/functions/is-previewing.d.ts +0 -0
  244. /package/{dist → types}/functions/register-component.d.ts +0 -0
  245. /package/{dist → types}/functions/register.d.ts +0 -0
  246. /package/{dist → types}/functions/sanitize-react-native-block-styles.d.ts +0 -0
  247. /package/{dist → types}/functions/set-editor-settings.d.ts +0 -0
  248. /package/{dist → types}/functions/set.d.ts +0 -0
  249. /package/{dist → types}/functions/track/helpers.d.ts +0 -0
  250. /package/{dist → types}/functions/track/index.d.ts +0 -0
  251. /package/{dist → types}/functions/track/interaction.d.ts +0 -0
  252. /package/{dist → types}/functions/transform-block-properties.d.ts +0 -0
  253. /package/{dist → types}/functions/transform-block.d.ts +0 -0
  254. /package/{dist → types}/helpers/ab-tests.d.ts +0 -0
  255. /package/{dist → types}/helpers/canTrack.d.ts +0 -0
  256. /package/{dist → types}/helpers/cookie.d.ts +0 -0
  257. /package/{dist → types}/helpers/css.d.ts +0 -0
  258. /package/{dist → types}/helpers/flatten.d.ts +0 -0
  259. /package/{dist → types}/helpers/localStorage.d.ts +0 -0
  260. /package/{dist → types}/helpers/logger.d.ts +0 -0
  261. /package/{dist → types}/helpers/nullable.d.ts +0 -0
  262. /package/{dist → types}/helpers/preview-lru-cache/get.d.ts +0 -0
  263. /package/{dist → types}/helpers/preview-lru-cache/helpers.d.ts +0 -0
  264. /package/{dist → types}/helpers/preview-lru-cache/init.d.ts +0 -0
  265. /package/{dist → types}/helpers/preview-lru-cache/set.d.ts +0 -0
  266. /package/{dist → types}/helpers/preview-lru-cache/types.d.ts +0 -0
  267. /package/{dist → types}/helpers/sessionId.d.ts +0 -0
  268. /package/{dist → types}/helpers/url.d.ts +0 -0
  269. /package/{dist → types}/helpers/uuid.d.ts +0 -0
  270. /package/{dist → types}/helpers/visitorId.d.ts +0 -0
  271. /package/{dist → types}/index-helpers/top-of-file.d.ts +0 -0
  272. /package/{dist → types}/index.d.ts +0 -0
  273. /package/{dist → types}/scripts/init-editing.d.ts +0 -0
  274. /package/{dist → types}/server-index.d.ts +0 -0
  275. /package/{dist → types}/types/api-version.d.ts +0 -0
  276. /package/{dist → types}/types/builder-block.d.ts +0 -0
  277. /package/{dist → types}/types/builder-content.d.ts +0 -0
  278. /package/{dist → types}/types/builder-props.d.ts +0 -0
  279. /package/{dist → types}/types/can-track.d.ts +0 -0
  280. /package/{dist → types}/types/components.d.ts +0 -0
  281. /package/{dist → types}/types/deep-partial.d.ts +0 -0
  282. /package/{dist → types}/types/element.d.ts +0 -0
  283. /package/{dist → types}/types/enforced-partials.d.ts +0 -0
  284. /package/{dist → types}/types/input.d.ts +0 -0
  285. /package/{dist → types}/types/targets.d.ts +0 -0
  286. /package/{dist → types}/types/typescript.d.ts +0 -0
@@ -1,61 +0,0 @@
1
- const propertiesThatMustBeNumber = new Set(['lineHeight']);
2
- const displayValues = new Set(['flex', 'none']);
3
- const SHOW_WARNINGS = false;
4
- const normalizeNumber = (value) => {
5
- if (Number.isNaN(value)) {
6
- return undefined;
7
- }
8
- else if (value < 0) {
9
- // TODO: why are negative values not allowed?
10
- return 0;
11
- }
12
- else {
13
- return value;
14
- }
15
- };
16
- export const sanitizeReactNativeBlockStyles = (styles) => {
17
- return Object.keys(styles).reduce((acc, key) => {
18
- const propertyValue = styles[key];
19
- if (key === 'display' && !displayValues.has(propertyValue)) {
20
- if (SHOW_WARNINGS) {
21
- console.warn(`Style value for key "display" must be "flex" or "none" but had ${propertyValue}`);
22
- }
23
- return acc;
24
- }
25
- if (propertiesThatMustBeNumber.has(key) && typeof propertyValue !== 'number') {
26
- if (SHOW_WARNINGS) {
27
- console.warn(`Style key ${key} must be a number, but had value \`${styles[key]}\``);
28
- }
29
- return acc;
30
- }
31
- if (typeof propertyValue === 'string') {
32
- // `px` units need to be stripped and replaced with numbers
33
- // https://regexr.com/6ualn
34
- const isPixelUnit = propertyValue.match(/^-?(\d*)(\.?)(\d*)*px$/);
35
- if (isPixelUnit) {
36
- const newValue = parseFloat(propertyValue);
37
- const normalizedValue = normalizeNumber(newValue);
38
- if (normalizedValue) {
39
- return {
40
- ...acc,
41
- [key]: normalizedValue
42
- };
43
- }
44
- else {
45
- return acc;
46
- }
47
- }
48
- else if (propertyValue === '0') {
49
- // 0 edge case needs to be handled
50
- return {
51
- ...acc,
52
- [key]: 0
53
- };
54
- }
55
- }
56
- return {
57
- ...acc,
58
- [key]: propertyValue
59
- };
60
- }, {});
61
- };
@@ -1,12 +0,0 @@
1
- import { isBrowser } from './is-browser.js';
2
- const settings = {};
3
- export 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
- }
@@ -1,14 +0,0 @@
1
- /**
2
- * Minimal implementation of lodash's _.set
3
- * https://lodash.com/docs/4.17.15#set
4
- *
5
- * See ./set.test.ts for usage examples
6
- */
7
- export const set = (obj, _path, value) => {
8
- if (Object(obj) !== obj) {
9
- return obj;
10
- }
11
- const path = Array.isArray(_path) ? _path : _path.toString().match(/[^.[\]]+/g);
12
- 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;
13
- return obj;
14
- };
@@ -1,51 +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
- }
7
- else if (isBrowser()) {
8
- const parsedLocation = new URL(location.href);
9
- // IE11 bug with parsed path being empty string
10
- // causes issues with our user targeting
11
- if (parsedLocation.pathname === '') {
12
- parsedLocation.pathname = '/';
13
- }
14
- return parsedLocation;
15
- }
16
- else {
17
- console.warn('Cannot get location for tracking in non-browser environment');
18
- return null;
19
- }
20
- };
21
- const getUserAgent = () => typeof navigator === 'object' && navigator.userAgent || '';
22
- export const getUserAttributes = () => {
23
- const userAgent = getUserAgent();
24
- const isMobile = {
25
- Android() {
26
- return userAgent.match(/Android/i);
27
- },
28
- BlackBerry() {
29
- return userAgent.match(/BlackBerry/i);
30
- },
31
- iOS() {
32
- return userAgent.match(/iPhone|iPod/i);
33
- },
34
- Opera() {
35
- return userAgent.match(/Opera Mini/i);
36
- },
37
- Windows() {
38
- return userAgent.match(/IEMobile/i) || userAgent.match(/WPDesktop/i);
39
- },
40
- any() {
41
- return isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows() || TARGET === 'reactNative';
42
- }
43
- };
44
- const isTablet = userAgent.match(/Tablet|iPad/i);
45
- const url = getLocation();
46
- return {
47
- urlPath: url?.pathname,
48
- host: url?.host || url?.hostname,
49
- device: isTablet ? 'tablet' : isMobile.any() ? 'mobile' : 'desktop'
50
- };
51
- };
@@ -1,71 +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 { isBrowser } from '../is-browser.js';
6
- import { isEditing } from '../is-editing.js';
7
- import { getUserAttributes } from './helpers.js';
8
- const getTrackingEventData = async ({ canTrack }) => {
9
- if (!canTrack) {
10
- return {
11
- visitorId: undefined,
12
- sessionId: undefined
13
- };
14
- }
15
- const sessionId = await getSessionId({
16
- canTrack
17
- });
18
- const visitorId = getVisitorId({
19
- canTrack
20
- });
21
- return {
22
- sessionId,
23
- visitorId
24
- };
25
- };
26
- const createEvent = async ({ type: eventType, canTrack, apiKey, metadata, ...properties }) => ({
27
- type: eventType,
28
- data: {
29
- ...properties,
30
- metadata: {
31
- url: location.href,
32
- ...metadata
33
- },
34
- ...(await getTrackingEventData({
35
- canTrack
36
- })),
37
- userAttributes: getUserAttributes(),
38
- ownerId: apiKey
39
- }
40
- });
41
- export async function _track(eventProps) {
42
- if (!eventProps.apiKey) {
43
- logger.error('Missing API key for track call. Please provide your API key.');
44
- return;
45
- }
46
- if (!eventProps.canTrack) {
47
- return;
48
- }
49
- if (isEditing()) {
50
- return;
51
- }
52
- if (!(isBrowser() || TARGET === 'reactNative')) {
53
- return;
54
- }
55
- return fetch(`https://cdn.builder.io/api/v1/track`, {
56
- method: 'POST',
57
- body: JSON.stringify({
58
- events: [await createEvent(eventProps)]
59
- }),
60
- headers: {
61
- 'content-type': 'application/json'
62
- },
63
- mode: 'cors'
64
- }).catch(err => {
65
- console.error('Failed to track: ', err);
66
- });
67
- }
68
- export const track = (args) => _track({
69
- ...args,
70
- canTrack: true
71
- });
@@ -1,53 +0,0 @@
1
- function round(num) {
2
- return Math.round(num * 1000) / 1000;
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?.indexOf('builder-') === 0);
23
- });
24
- const computeOffset = ({ event, target }) => {
25
- const targetRect = target.getBoundingClientRect();
26
- const xOffset = event.clientX - targetRect.left;
27
- const yOffset = event.clientY - targetRect.top;
28
- const xRatio = round(xOffset / targetRect.width);
29
- const yRatio = round(yOffset / targetRect.height);
30
- return {
31
- x: xRatio,
32
- y: yRatio
33
- };
34
- };
35
- export const getInteractionPropertiesForEvent = (event) => {
36
- const target = event.target;
37
- const targetBuilderElement = target && findBuilderParent(target);
38
- const builderId = targetBuilderElement?.getAttribute('builder-id') || targetBuilderElement?.id;
39
- return {
40
- targetBuilderElement: builderId || undefined,
41
- metadata: {
42
- targetOffset: target ? computeOffset({
43
- event,
44
- target
45
- }) : undefined,
46
- builderTargetOffset: targetBuilderElement ? computeOffset({
47
- event,
48
- target: targetBuilderElement
49
- }) : undefined,
50
- builderElementIndex: targetBuilderElement && builderId ? [].slice.call(document.getElementsByClassName(builderId)).indexOf(targetBuilderElement) : undefined
51
- }
52
- };
53
- };
@@ -1,5 +0,0 @@
1
- export function transformBlockProperties(properties) {
2
- properties.className = properties.class;
3
- delete properties.class;
4
- return properties;
5
- }
@@ -1,4 +0,0 @@
1
- // Noope way for targets to make modifications to the block object if/as needed
2
- export function transformBlock(block) {
3
- return block;
4
- }
@@ -1,122 +0,0 @@
1
- import { getCookie, getCookieSync, setCookie } from './cookie.js';
2
- import { checkIsDefined } from '../helpers/nullable.js';
3
- import { logger } from './logger.js';
4
- import { TARGET } from '../constants/target.js';
5
- const BUILDER_STORE_PREFIX = 'builder.tests';
6
- const getContentTestKey = (id) => `${BUILDER_STORE_PREFIX}.${id}`;
7
- const getContentVariationCookie = ({ contentId }) => getCookie({
8
- name: getContentTestKey(contentId),
9
- canTrack: true
10
- });
11
- const getContentVariationCookieSync = ({ contentId }) => getCookieSync({
12
- name: getContentTestKey(contentId),
13
- canTrack: true
14
- });
15
- const setContentVariationCookie = ({ contentId, value }) => setCookie({
16
- name: getContentTestKey(contentId),
17
- value,
18
- canTrack: true
19
- });
20
- const checkIsBuilderContentWithVariations = (item) => checkIsDefined(item.id) && checkIsDefined(item.variations) && Object.keys(item.variations).length > 0;
21
- /**
22
- * Randomly assign a variation to a user
23
- */
24
- const getRandomVariationId = ({ id, variations }) => {
25
- let n = 0;
26
- const random = Math.random();
27
- // loop over variations test ratios, incrementing a counter,
28
- // until we find the variation that this user should be assigned to
29
- for (const id in variations) {
30
- const testRatio = variations[id]?.testRatio;
31
- n += testRatio;
32
- if (random < n) {
33
- return id;
34
- }
35
- }
36
- // the variations array does not include the default variation.
37
- // if we arrive here, then it means that the random number fits in the default variation bucket.
38
- return id;
39
- };
40
- const getAndSetVariantId = (args) => {
41
- // if variation not found in storage, assign a random variation to this user
42
- const randomVariationId = getRandomVariationId(args);
43
- // store variation in cookies/storage
44
- setContentVariationCookie({
45
- contentId: args.id,
46
- value: randomVariationId
47
- }).catch(err => {
48
- logger.error('could not store A/B test variation: ', err);
49
- });
50
- return randomVariationId;
51
- };
52
- const getTestFields = ({ item, testGroupId }) => {
53
- const variationValue = item.variations[testGroupId];
54
- if (testGroupId === item.id ||
55
- // handle edge-case where `testGroupId` points to non-existing variation
56
- !variationValue) {
57
- return {
58
- testVariationId: item.id,
59
- testVariationName: 'Default'
60
- };
61
- }
62
- else {
63
- return {
64
- data: variationValue.data,
65
- testVariationId: variationValue.id,
66
- testVariationName: variationValue.name || (variationValue.id === item.id ? 'Default' : '')
67
- };
68
- }
69
- };
70
- export const handleABTestingSync = ({ item, canTrack }) => {
71
- /**
72
- * We cannot SSR in React-Native.
73
- */
74
- if (TARGET === 'reactNative')
75
- return item;
76
- if (!canTrack) {
77
- return item;
78
- }
79
- if (!item) {
80
- return undefined;
81
- }
82
- if (!checkIsBuilderContentWithVariations(item)) {
83
- return item;
84
- }
85
- const testGroupId = getContentVariationCookieSync({
86
- contentId: item.id
87
- }) || getAndSetVariantId({
88
- variations: item.variations,
89
- id: item.id
90
- });
91
- const variationValue = getTestFields({
92
- item,
93
- testGroupId
94
- });
95
- return {
96
- ...item,
97
- ...variationValue
98
- };
99
- };
100
- export const handleABTesting = async ({ item, canTrack }) => {
101
- if (!canTrack) {
102
- return item;
103
- }
104
- if (!checkIsBuilderContentWithVariations(item)) {
105
- return item;
106
- }
107
- const cookieValue = await getContentVariationCookie({
108
- contentId: item.id
109
- });
110
- const testGroupId = cookieValue || getAndSetVariantId({
111
- variations: item.variations,
112
- id: item.id
113
- });
114
- const variationValue = getTestFields({
115
- item,
116
- testGroupId
117
- });
118
- return {
119
- ...item,
120
- ...variationValue
121
- };
122
- };
@@ -1,2 +0,0 @@
1
- import { checkIsDefined } from './nullable.js';
2
- export const getDefaultCanTrack = (canTrack) => checkIsDefined(canTrack) ? canTrack : true;
@@ -1,55 +0,0 @@
1
- import { isBrowser } from '../functions/is-browser.js';
2
- import { logger } from './logger.js';
3
- import { checkIsDefined } from './nullable.js';
4
- import { getTopLevelDomain } from './url.js';
5
- export const getCookieSync = ({ name, canTrack }) => {
6
- try {
7
- if (!canTrack) {
8
- return undefined;
9
- }
10
- /**
11
- * Extracted from MDN docs
12
- * https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie#example_2_get_a_sample_cookie_named_test2
13
- */
14
- return document.cookie.split('; ').find(row => row.startsWith(`${name}=`))?.split('=')[1];
15
- }
16
- catch (err) {
17
- logger.warn('[COOKIE] GET error: ', err?.message || err);
18
- return undefined;
19
- }
20
- };
21
- /**
22
- * NOTE: This function is `async` because its react-native override is async. Do not remove the `async` keyword!
23
- * The sync version is only safe to use in code blocks that `react-native` is guaranteed not to not run.
24
- */
25
- export const getCookie = async (args) => getCookieSync(args);
26
- const stringifyCookie = (cookie) => cookie.map(([key, value]) => value ? `${key}=${value}` : key).filter(checkIsDefined).join('; ');
27
- const SECURE_CONFIG = [['secure', ''], ['SameSite', 'None']];
28
- const createCookieString = ({ name, value, expires }) => {
29
- const secure = isBrowser() ? location.protocol === 'https:' : true;
30
- const secureObj = secure ? SECURE_CONFIG : [[]];
31
- // TODO: need to know if secure server side
32
- const expiresObj = expires ? [['expires', expires.toUTCString()]] : [[]];
33
- const cookieValue = [[name, value], ...expiresObj, ['path', '/'], ['domain', getTopLevelDomain(window.location.hostname)], ...secureObj];
34
- const cookie = stringifyCookie(cookieValue);
35
- return cookie;
36
- };
37
- /**
38
- * NOTE: This function is `async` because its react-native override is async. Do not remove the `async` keyword!
39
- */
40
- export const setCookie = async ({ name, value, expires, canTrack }) => {
41
- try {
42
- if (!canTrack) {
43
- return;
44
- }
45
- const cookie = createCookieString({
46
- name,
47
- value,
48
- expires
49
- });
50
- document.cookie = cookie;
51
- }
52
- catch (err) {
53
- logger.warn('[COOKIE] SET error: ', err?.message || err);
54
- }
55
- };
@@ -1,27 +0,0 @@
1
- import { camelToKebabCase } from '../functions/camel-to-kebab-case.js';
2
- import { checkIsDefined } from './nullable.js';
3
- export const convertStyleMapToCSSArray = (style) => {
4
- const cssProps = Object.entries(style).map(([key, value]) => {
5
- if (typeof value === 'string') {
6
- return `${camelToKebabCase(key)}: ${value};`;
7
- }
8
- else {
9
- return undefined;
10
- }
11
- });
12
- return cssProps.filter(checkIsDefined);
13
- };
14
- export const convertStyleMapToCSS = (style) => convertStyleMapToCSSArray(style).join('\n');
15
- export const createCssClass = ({ mediaQuery, className, styles }) => {
16
- const cssClass = `.${className} {
17
- ${convertStyleMapToCSS(styles)}
18
- }`;
19
- if (mediaQuery) {
20
- return `${mediaQuery} {
21
- ${cssClass}
22
- }`;
23
- }
24
- else {
25
- return cssClass;
26
- }
27
- };
@@ -1,19 +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(object, path = null, separator = '.') {
7
- return Object.keys(object).reduce((acc, key) => {
8
- const value = object[key];
9
- const newPath = [path, key].filter(Boolean).join(separator);
10
- const isObject = [typeof value === 'object', value !== null, !(Array.isArray(value) && value.length === 0)].every(Boolean);
11
- return isObject ? {
12
- ...acc,
13
- ...flatten(value, newPath, separator)
14
- } : {
15
- ...acc,
16
- [newPath]: value
17
- };
18
- }, {});
19
- }
@@ -1,24 +0,0 @@
1
- import { isBrowser } from '../functions/is-browser.js';
2
- const getLocalStorage = () => isBrowser() && typeof localStorage !== 'undefined' ? localStorage : undefined;
3
- export const getLocalStorageItem = ({ key, canTrack }) => {
4
- try {
5
- if (canTrack) {
6
- return getLocalStorage()?.getItem(key);
7
- }
8
- return undefined;
9
- }
10
- catch (err) {
11
- console.debug('[LocalStorage] GET error: ', err);
12
- return undefined;
13
- }
14
- };
15
- export const setLocalStorageItem = ({ key, canTrack, value }) => {
16
- try {
17
- if (canTrack) {
18
- getLocalStorage()?.setItem(key, value);
19
- }
20
- }
21
- catch (err) {
22
- console.debug('[LocalStorage] SET error: ', err);
23
- }
24
- };
@@ -1,7 +0,0 @@
1
- const MSG_PREFIX = '[Builder.io]: ';
2
- export const logger = {
3
- log: (...message) => console.log(MSG_PREFIX, ...message),
4
- error: (...message) => console.error(MSG_PREFIX, ...message),
5
- warn: (...message) => console.warn(MSG_PREFIX, ...message),
6
- debug: (...message) => console.debug(MSG_PREFIX, ...message)
7
- };
@@ -1 +0,0 @@
1
- export const checkIsDefined = (maybeT) => maybeT !== null && maybeT !== undefined;
@@ -1,9 +0,0 @@
1
- import { getIdFromSearchParams } from './helpers';
2
- import { init } from './init';
3
- export function getPreviewContent(searchParams) {
4
- init();
5
- const id = getIdFromSearchParams(searchParams);
6
- return typeof id === 'string'
7
- ? globalThis._BUILDER_PREVIEW_LRU_CACHE.get(id)
8
- : undefined;
9
- }
@@ -1,9 +0,0 @@
1
- import { logger } from '../logger';
2
- export const getIdFromSearchParams = (searchParams) => {
3
- const previewedModel = searchParams.get('preview');
4
- const previewedId = searchParams.get('overrides.' + previewedModel);
5
- if (!previewedId) {
6
- logger.warn('No previewed ID found in search params.');
7
- }
8
- return previewedId;
9
- };
@@ -1,15 +0,0 @@
1
- /**
2
- * This is an LRU cache to hold preview content on the server-side.
3
- *
4
- * Note: This logic is only used by the NextJS SDK.
5
- */
6
- import { LRUCache } from 'lru-cache';
7
- export function init() {
8
- if (!globalThis._BUILDER_PREVIEW_LRU_CACHE) {
9
- globalThis._BUILDER_PREVIEW_LRU_CACHE = new LRUCache({
10
- max: 500,
11
- // how long to live in ms
12
- ttl: 1000 * 60 * 5,
13
- });
14
- }
15
- }
@@ -1,7 +0,0 @@
1
- 'use server';
2
- import { init } from './init';
3
- export async function postPreviewContent({ key, value, }) {
4
- init();
5
- globalThis._BUILDER_PREVIEW_LRU_CACHE.set(key, value);
6
- return { [key]: value };
7
- }
@@ -1,6 +0,0 @@
1
- /**
2
- * This is an LRU cache to hold preview content on the server-side.
3
- *
4
- * Note: This logic is only used by the NextJS SDK.
5
- */
6
- export {};
@@ -1,30 +0,0 @@
1
- import { getCookie, setCookie } from './cookie.js';
2
- import { checkIsDefined } from './nullable.js';
3
- import { uuid } from './uuid.js';
4
- const SESSION_LOCAL_STORAGE_KEY = 'builderSessionId';
5
- export const getSessionId = async ({ canTrack }) => {
6
- if (!canTrack) {
7
- return undefined;
8
- }
9
- const sessionId = await getCookie({
10
- name: SESSION_LOCAL_STORAGE_KEY,
11
- canTrack
12
- });
13
- if (checkIsDefined(sessionId)) {
14
- return sessionId;
15
- }
16
- else {
17
- const newSessionId = createSessionId();
18
- setSessionId({
19
- id: newSessionId,
20
- canTrack
21
- });
22
- return newSessionId;
23
- }
24
- };
25
- export const createSessionId = () => uuid();
26
- export const setSessionId = ({ id, canTrack }) => setCookie({
27
- name: SESSION_LOCAL_STORAGE_KEY,
28
- value: id,
29
- canTrack
30
- });
@@ -1,15 +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) => {
7
- if (host === 'localhost' || host === '127.0.0.1') {
8
- return host;
9
- }
10
- const parts = host.split('.');
11
- if (parts.length > 2) {
12
- return parts.slice(1).join('.');
13
- }
14
- return host;
15
- };
@@ -1,15 +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, v = c == 'x' ? r : r & 0x3 | 0x8;
7
- return v.toString(16);
8
- });
9
- }
10
- /**
11
- * Slightly cleaner and smaller UUIDs
12
- */
13
- export function uuid() {
14
- return uuidv4().replace(/-/g, '');
15
- }