@builder.io/sdk-react 0.2.3-4 → 0.2.3

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 (261) hide show
  1. package/dist/sdk/blocks/columns/columns.js +4 -4
  2. package/dist/sdk/blocks/image/image.js +8 -7
  3. package/dist/sdk/blocks/symbol/symbol.js +2 -1
  4. package/dist/sdk/blocks/video/video.js +4 -1
  5. package/dist/sdk/components/render-block/render-block.js +4 -1
  6. package/dist/sdk/components/render-content/render-content.js +19 -5
  7. package/dist/sdk/index.d.ts +1 -0
  8. package/package.json +4 -1
  9. package/CHANGELOG.md +0 -25
  10. package/packages/react/src/blocks/BaseText.tsx +0 -19
  11. package/packages/react/src/blocks/button/button.tsx +0 -45
  12. package/packages/react/src/blocks/button/component-info.ts +0 -42
  13. package/packages/react/src/blocks/columns/columns.tsx +0 -211
  14. package/packages/react/src/blocks/columns/component-info.ts +0 -254
  15. package/packages/react/src/blocks/custom-code/component-info.ts +0 -31
  16. package/packages/react/src/blocks/custom-code/custom-code.tsx +0 -76
  17. package/packages/react/src/blocks/embed/component-info.ts +0 -55
  18. package/packages/react/src/blocks/embed/embed.tsx +0 -59
  19. package/packages/react/src/blocks/embed/helpers.ts +0 -8
  20. package/packages/react/src/blocks/form/component-info.ts +0 -282
  21. package/packages/react/src/blocks/form/form.tsx +0 -320
  22. package/packages/react/src/blocks/fragment/component-info.ts +0 -10
  23. package/packages/react/src/blocks/fragment/fragment.tsx +0 -14
  24. package/packages/react/src/blocks/image/component-info.ts +0 -172
  25. package/packages/react/src/blocks/image/image.helpers.ts +0 -75
  26. package/packages/react/src/blocks/image/image.tsx +0 -144
  27. package/packages/react/src/blocks/img/component-info.ts +0 -21
  28. package/packages/react/src/blocks/img/img.tsx +0 -40
  29. package/packages/react/src/blocks/input/component-info.ts +0 -78
  30. package/packages/react/src/blocks/input/input.tsx +0 -33
  31. package/packages/react/src/blocks/raw-text/component-info.ts +0 -15
  32. package/packages/react/src/blocks/raw-text/raw-text.tsx +0 -18
  33. package/packages/react/src/blocks/section/component-info.ts +0 -50
  34. package/packages/react/src/blocks/section/section.tsx +0 -33
  35. package/packages/react/src/blocks/select/component-info.ts +0 -61
  36. package/packages/react/src/blocks/select/select.tsx +0 -35
  37. package/packages/react/src/blocks/submit-button/component-info.ts +0 -32
  38. package/packages/react/src/blocks/submit-button/submit-button.tsx +0 -17
  39. package/packages/react/src/blocks/symbol/component-info.ts +0 -43
  40. package/packages/react/src/blocks/symbol/symbol.tsx +0 -111
  41. package/packages/react/src/blocks/text/component-info.ts +0 -24
  42. package/packages/react/src/blocks/text/text.tsx +0 -20
  43. package/packages/react/src/blocks/textarea/component-info.ts +0 -48
  44. package/packages/react/src/blocks/textarea/textarea.tsx +0 -24
  45. package/packages/react/src/blocks/util.ts +0 -18
  46. package/packages/react/src/blocks/video/component-info.ts +0 -109
  47. package/packages/react/src/blocks/video/video.tsx +0 -84
  48. package/packages/react/src/components/render-block/block-styles.tsx +0 -98
  49. package/packages/react/src/components/render-block/render-block.helpers.ts +0 -138
  50. package/packages/react/src/components/render-block/render-block.tsx +0 -216
  51. package/packages/react/src/components/render-block/render-component.tsx +0 -52
  52. package/packages/react/src/components/render-block/render-repeated-block.tsx +0 -43
  53. package/packages/react/src/components/render-block/types.ts +0 -7
  54. package/packages/react/src/components/render-blocks.tsx +0 -97
  55. package/packages/react/src/components/render-content/builder-editing.tsx +0 -8
  56. package/packages/react/src/components/render-content/components/render-styles.helpers.ts +0 -79
  57. package/packages/react/src/components/render-content/components/render-styles.tsx +0 -45
  58. package/packages/react/src/components/render-content/index.ts +0 -1
  59. package/packages/react/src/components/render-content/render-content.helpers.ts +0 -48
  60. package/packages/react/src/components/render-content/render-content.tsx +0 -410
  61. package/packages/react/src/components/render-content/render-content.types.ts +0 -33
  62. package/packages/react/src/components/render-inlined-styles.tsx +0 -36
  63. package/packages/react/src/constants/builder-registered-components.ts +0 -42
  64. package/packages/react/src/constants/device-sizes.ts +0 -65
  65. package/packages/react/src/constants/target.ts +0 -2
  66. package/packages/react/src/context/builder.context.ts +0 -12
  67. package/packages/react/src/context/types.ts +0 -26
  68. package/packages/react/src/functions/camel-to-kebab-case.ts +0 -2
  69. package/packages/react/src/functions/evaluate.ts +0 -57
  70. package/packages/react/src/functions/event-handler-name.ts +0 -6
  71. package/packages/react/src/functions/extract-text-styles.ts +0 -39
  72. package/packages/react/src/functions/fast-clone.ts +0 -5
  73. package/packages/react/src/functions/get-block-actions-handler.ts +0 -20
  74. package/packages/react/src/functions/get-block-actions.ts +0 -25
  75. package/packages/react/src/functions/get-block-component-options.ts +0 -12
  76. package/packages/react/src/functions/get-block-properties.ts +0 -75
  77. package/packages/react/src/functions/get-builder-search-params/fn.test.ts +0 -19
  78. package/packages/react/src/functions/get-builder-search-params/index.ts +0 -50
  79. package/packages/react/src/functions/get-content/ab-testing.ts +0 -132
  80. package/packages/react/src/functions/get-content/generate-content-url.test.ts +0 -95
  81. package/packages/react/src/functions/get-content/generate-content-url.ts +0 -59
  82. package/packages/react/src/functions/get-content/index.ts +0 -62
  83. package/packages/react/src/functions/get-content/types.ts +0 -53
  84. package/packages/react/src/functions/get-fetch.ts +0 -18
  85. package/packages/react/src/functions/get-global-this.ts +0 -17
  86. package/packages/react/src/functions/get-processed-block.test.ts +0 -33
  87. package/packages/react/src/functions/get-processed-block.ts +0 -54
  88. package/packages/react/src/functions/get-react-native-block-styles.ts +0 -33
  89. package/packages/react/src/functions/if-target.ts +0 -20
  90. package/packages/react/src/functions/is-browser.ts +0 -3
  91. package/packages/react/src/functions/is-editing.ts +0 -10
  92. package/packages/react/src/functions/is-iframe.ts +0 -5
  93. package/packages/react/src/functions/is-previewing.ts +0 -14
  94. package/packages/react/src/functions/on-change.test.ts +0 -23
  95. package/packages/react/src/functions/on-change.ts +0 -29
  96. package/packages/react/src/functions/register-component.ts +0 -50
  97. package/packages/react/src/functions/register.ts +0 -46
  98. package/packages/react/src/functions/sanitize-react-native-block-styles.ts +0 -65
  99. package/packages/react/src/functions/set-editor-settings.ts +0 -16
  100. package/packages/react/src/functions/set.test.ts +0 -19
  101. package/packages/react/src/functions/set.ts +0 -26
  102. package/packages/react/src/functions/track/helpers.ts +0 -67
  103. package/packages/react/src/functions/track/index.ts +0 -136
  104. package/packages/react/src/functions/track/interaction.ts +0 -80
  105. package/packages/react/src/functions/transform-block-properties.ts +0 -3
  106. package/packages/react/src/functions/transform-block.ts +0 -6
  107. package/packages/react/src/helpers/ab-tests.ts +0 -22
  108. package/packages/react/src/helpers/cookie.ts +0 -107
  109. package/packages/react/src/helpers/css.ts +0 -42
  110. package/packages/react/src/helpers/flatten.ts +0 -24
  111. package/packages/react/src/helpers/localStorage.ts +0 -40
  112. package/packages/react/src/helpers/logger.ts +0 -6
  113. package/packages/react/src/helpers/nullable.ts +0 -4
  114. package/packages/react/src/helpers/sessionId.ts +0 -38
  115. package/packages/react/src/helpers/time.ts +0 -4
  116. package/packages/react/src/helpers/url.test.ts +0 -23
  117. package/packages/react/src/helpers/url.ts +0 -16
  118. package/packages/react/src/helpers/uuid.ts +0 -17
  119. package/packages/react/src/helpers/visitorId.ts +0 -40
  120. package/packages/react/src/index-helpers/blocks-exports.ts +0 -10
  121. package/packages/react/src/index-helpers/top-of-file.ts +0 -4
  122. package/packages/react/src/index.ts +0 -14
  123. package/packages/react/src/scripts/init-editing.ts +0 -123
  124. package/packages/react/src/types/api-version.ts +0 -2
  125. package/packages/react/src/types/builder-block.ts +0 -69
  126. package/packages/react/src/types/builder-content.ts +0 -46
  127. package/packages/react/src/types/can-track.ts +0 -3
  128. package/packages/react/src/types/components.ts +0 -117
  129. package/packages/react/src/types/deep-partial.ts +0 -7
  130. package/packages/react/src/types/element.ts +0 -60
  131. package/packages/react/src/types/input.ts +0 -125
  132. package/packages/react/src/types/targets.ts +0 -6
  133. package/packages/react/src/types/typescript.ts +0 -7
  134. package/packages/rsc/src/blocks/BaseText.jsx +0 -12
  135. package/packages/rsc/src/blocks/button/button.jsx +0 -37
  136. package/packages/rsc/src/blocks/button/component-info.js +0 -40
  137. package/packages/rsc/src/blocks/columns/columns.jsx +0 -172
  138. package/packages/rsc/src/blocks/columns/component-info.js +0 -241
  139. package/packages/rsc/src/blocks/custom-code/component-info.js +0 -30
  140. package/packages/rsc/src/blocks/custom-code/custom-code.jsx +0 -57
  141. package/packages/rsc/src/blocks/embed/component-info.js +0 -43
  142. package/packages/rsc/src/blocks/embed/embed.jsx +0 -45
  143. package/packages/rsc/src/blocks/embed/helpers.js +0 -9
  144. package/packages/rsc/src/blocks/form/component-info.js +0 -261
  145. package/packages/rsc/src/blocks/form/form.jsx +0 -260
  146. package/packages/rsc/src/blocks/fragment/component-info.js +0 -10
  147. package/packages/rsc/src/blocks/fragment/fragment.jsx +0 -9
  148. package/packages/rsc/src/blocks/image/component-info.js +0 -150
  149. package/packages/rsc/src/blocks/image/image.helpers.js +0 -48
  150. package/packages/rsc/src/blocks/image/image.jsx +0 -122
  151. package/packages/rsc/src/blocks/img/component-info.js +0 -19
  152. package/packages/rsc/src/blocks/img/img.jsx +0 -21
  153. package/packages/rsc/src/blocks/input/component-info.js +0 -73
  154. package/packages/rsc/src/blocks/input/input.jsx +0 -23
  155. package/packages/rsc/src/blocks/raw-text/component-info.js +0 -15
  156. package/packages/rsc/src/blocks/raw-text/raw-text.jsx +0 -14
  157. package/packages/rsc/src/blocks/section/component-info.js +0 -48
  158. package/packages/rsc/src/blocks/section/section.jsx +0 -27
  159. package/packages/rsc/src/blocks/select/component-info.js +0 -58
  160. package/packages/rsc/src/blocks/select/select.jsx +0 -24
  161. package/packages/rsc/src/blocks/submit-button/component-info.js +0 -27
  162. package/packages/rsc/src/blocks/submit-button/submit-button.jsx +0 -13
  163. package/packages/rsc/src/blocks/symbol/component-info.js +0 -42
  164. package/packages/rsc/src/blocks/symbol/symbol.jsx +0 -89
  165. package/packages/rsc/src/blocks/text/component-info.js +0 -23
  166. package/packages/rsc/src/blocks/text/text.jsx +0 -17
  167. package/packages/rsc/src/blocks/textarea/component-info.js +0 -46
  168. package/packages/rsc/src/blocks/textarea/textarea.jsx +0 -17
  169. package/packages/rsc/src/blocks/util.js +0 -8
  170. package/packages/rsc/src/blocks/video/component-info.js +0 -105
  171. package/packages/rsc/src/blocks/video/video.jsx +0 -63
  172. package/packages/rsc/src/components/render-block/block-styles.jsx +0 -88
  173. package/packages/rsc/src/components/render-block/render-block.helpers.js +0 -129
  174. package/packages/rsc/src/components/render-block/render-block.jsx +0 -201
  175. package/packages/rsc/src/components/render-block/render-component.jsx +0 -39
  176. package/packages/rsc/src/components/render-block/render-repeated-block.jsx +0 -27
  177. package/packages/rsc/src/components/render-block/types.js +0 -0
  178. package/packages/rsc/src/components/render-blocks.jsx +0 -92
  179. package/packages/rsc/src/components/render-content/builder-editing.jsx +0 -64
  180. package/packages/rsc/src/components/render-content/components/render-styles.helpers.js +0 -57
  181. package/packages/rsc/src/components/render-content/components/render-styles.jsx +0 -39
  182. package/packages/rsc/src/components/render-content/index.js +0 -4
  183. package/packages/rsc/src/components/render-content/render-content.helpers.js +0 -48
  184. package/packages/rsc/src/components/render-content/render-content.jsx +0 -253
  185. package/packages/rsc/src/components/render-content/render-content.types.js +0 -0
  186. package/packages/rsc/src/components/render-inlined-styles.jsx +0 -33
  187. package/packages/rsc/src/constants/builder-registered-components.js +0 -54
  188. package/packages/rsc/src/constants/device-sizes.js +0 -48
  189. package/packages/rsc/src/constants/target.js +0 -4
  190. package/packages/rsc/src/context/builder.context.js +0 -14
  191. package/packages/rsc/src/context/types.js +0 -0
  192. package/packages/rsc/src/functions/camel-to-kebab-case.js +0 -4
  193. package/packages/rsc/src/functions/evaluate.js +0 -6
  194. package/packages/rsc/src/functions/event-handler-name.js +0 -7
  195. package/packages/rsc/src/functions/extract-text-styles.js +0 -22
  196. package/packages/rsc/src/functions/fast-clone.js +0 -4
  197. package/packages/rsc/src/functions/get-block-actions-handler.js +0 -11
  198. package/packages/rsc/src/functions/get-block-actions.js +0 -18
  199. package/packages/rsc/src/functions/get-block-component-options.js +0 -28
  200. package/packages/rsc/src/functions/get-block-properties.js +0 -53
  201. package/packages/rsc/src/functions/get-builder-search-params/fn.test.js +0 -13
  202. package/packages/rsc/src/functions/get-builder-search-params/index.js +0 -38
  203. package/packages/rsc/src/functions/get-content/ab-testing.js +0 -99
  204. package/packages/rsc/src/functions/get-content/generate-content-url.js +0 -60
  205. package/packages/rsc/src/functions/get-content/generate-content-url.test.js +0 -82
  206. package/packages/rsc/src/functions/get-content/index.js +0 -83
  207. package/packages/rsc/src/functions/get-content/types.js +0 -0
  208. package/packages/rsc/src/functions/get-fetch.js +0 -14
  209. package/packages/rsc/src/functions/get-global-this.js +0 -18
  210. package/packages/rsc/src/functions/get-processed-block.js +0 -59
  211. package/packages/rsc/src/functions/get-processed-block.test.js +0 -32
  212. package/packages/rsc/src/functions/get-react-native-block-styles.js +0 -33
  213. package/packages/rsc/src/functions/if-target.js +0 -15
  214. package/packages/rsc/src/functions/is-browser.js +0 -6
  215. package/packages/rsc/src/functions/is-editing.js +0 -8
  216. package/packages/rsc/src/functions/is-iframe.js +0 -7
  217. package/packages/rsc/src/functions/is-previewing.js +0 -14
  218. package/packages/rsc/src/functions/on-change.js +0 -27
  219. package/packages/rsc/src/functions/on-change.test.js +0 -19
  220. package/packages/rsc/src/functions/register-component.js +0 -68
  221. package/packages/rsc/src/functions/register.js +0 -29
  222. package/packages/rsc/src/functions/sanitize-react-native-block-styles.js +0 -66
  223. package/packages/rsc/src/functions/set-editor-settings.js +0 -15
  224. package/packages/rsc/src/functions/set.js +0 -11
  225. package/packages/rsc/src/functions/set.test.js +0 -16
  226. package/packages/rsc/src/functions/track/helpers.js +0 -50
  227. package/packages/rsc/src/functions/track/index.js +0 -129
  228. package/packages/rsc/src/functions/track/interaction.js +0 -53
  229. package/packages/rsc/src/functions/transform-block-properties.js +0 -6
  230. package/packages/rsc/src/functions/transform-block.js +0 -6
  231. package/packages/rsc/src/helpers/ab-tests.js +0 -16
  232. package/packages/rsc/src/helpers/cookie.js +0 -81
  233. package/packages/rsc/src/helpers/css.js +0 -34
  234. package/packages/rsc/src/helpers/flatten.js +0 -34
  235. package/packages/rsc/src/helpers/localStorage.js +0 -35
  236. package/packages/rsc/src/helpers/logger.js +0 -9
  237. package/packages/rsc/src/helpers/nullable.js +0 -4
  238. package/packages/rsc/src/helpers/sessionId.js +0 -52
  239. package/packages/rsc/src/helpers/time.js +0 -5
  240. package/packages/rsc/src/helpers/url.js +0 -13
  241. package/packages/rsc/src/helpers/url.test.js +0 -21
  242. package/packages/rsc/src/helpers/uuid.js +0 -13
  243. package/packages/rsc/src/helpers/visitorId.js +0 -34
  244. package/packages/rsc/src/index-helpers/blocks-exports.js +0 -22
  245. package/packages/rsc/src/index-helpers/top-of-file.js +0 -2
  246. package/packages/rsc/src/index.js +0 -13
  247. package/packages/rsc/src/scripts/init-editing.js +0 -93
  248. package/packages/rsc/src/types/api-version.js +0 -4
  249. package/packages/rsc/src/types/builder-block.js +0 -0
  250. package/packages/rsc/src/types/builder-content.js +0 -0
  251. package/packages/rsc/src/types/can-track.js +0 -0
  252. package/packages/rsc/src/types/components.js +0 -0
  253. package/packages/rsc/src/types/deep-partial.js +0 -0
  254. package/packages/rsc/src/types/element.js +0 -0
  255. package/packages/rsc/src/types/input.js +0 -0
  256. package/packages/rsc/src/types/targets.js +0 -0
  257. package/packages/rsc/src/types/typescript.js +0 -0
  258. package/tsconfig.json +0 -28
  259. package/tsconfig.sdk.json +0 -10
  260. package/tsconfig.server.json +0 -10
  261. package/vite.config.ts +0 -91
@@ -1,65 +0,0 @@
1
- import { fastClone } from '../functions/fast-clone';
2
- export type SizeName = 'large' | 'medium' | 'small';
3
-
4
- interface Size {
5
- min: number;
6
- default: number;
7
- max: number;
8
- }
9
-
10
- const SIZES: Record<SizeName, Size> = {
11
- small: {
12
- min: 320,
13
- default: 321,
14
- max: 640,
15
- },
16
- medium: {
17
- min: 641,
18
- default: 642,
19
- max: 991,
20
- },
21
- large: {
22
- min: 990,
23
- default: 991,
24
- max: 1200,
25
- },
26
- };
27
-
28
- export const getMaxWidthQueryForSize = (size: SizeName, sizeValues = SIZES) =>
29
- `@media (max-width: ${sizeValues[size].max}px)`;
30
-
31
- interface Breakpoints {
32
- small?: number;
33
- medium?: number;
34
- }
35
-
36
- export const getSizesForBreakpoints = ({ small, medium }: Breakpoints) => {
37
- const newSizes = fastClone(SIZES); // Note: this helps to get a deep clone of fields like small, medium etc
38
-
39
- if (!small || !medium) {
40
- return newSizes;
41
- }
42
-
43
- const smallMin = Math.floor(small / 2);
44
- newSizes.small = {
45
- max: small,
46
- min: smallMin,
47
- default: smallMin + 1,
48
- };
49
-
50
- const mediumMin = newSizes.small.max + 1;
51
- newSizes.medium = {
52
- max: medium,
53
- min: mediumMin,
54
- default: mediumMin + 1,
55
- };
56
-
57
- const largeMin = newSizes.medium.max + 1;
58
- newSizes.large = {
59
- max: 2000, // TODO: decide upper limit
60
- min: largeMin,
61
- default: largeMin + 1,
62
- };
63
-
64
- return newSizes;
65
- };
@@ -1,2 +0,0 @@
1
- /** This file should be overriden for each framework. Ideally this would be implemented in Mitosis. */
2
- export const TARGET = 'react' as any;
@@ -1,12 +0,0 @@
1
- import { createContext } from "react";
2
-
3
- export default createContext<any>({
4
- content: null,
5
- context: {},
6
- state: {},
7
- setState() {},
8
- apiKey: null,
9
- apiVersion: undefined,
10
- registeredComponents: {},
11
- inheritedStyles: {},
12
- });
@@ -1,26 +0,0 @@
1
- import type { BuilderContent } from '../types/builder-content.js';
2
- import type { ComponentInfo } from '../types/components.js';
3
- import type { Dictionary, Nullable } from '../types/typescript.js';
4
- import type { ApiVersion } from '../types/api-version.js';
5
-
6
- export type RegisteredComponent = ComponentInfo & {
7
- component: any;
8
- };
9
-
10
- export type RegisteredComponents = Dictionary<RegisteredComponent>;
11
-
12
- export type BuilderRenderState = Record<string, unknown>;
13
-
14
- export type BuilderRenderContext = Record<string, unknown>;
15
-
16
- export interface BuilderContextInterface {
17
- content: Nullable<BuilderContent>;
18
- context: BuilderRenderContext;
19
- state: BuilderRenderState;
20
- setState?: (state: BuilderRenderState) => void;
21
- apiKey: string | null;
22
- apiVersion: ApiVersion | undefined;
23
- registeredComponents: RegisteredComponents;
24
- // Used to recursively store all CSS coming from a parent that would apply to a Text block
25
- inheritedStyles: Record<string, unknown>;
26
- }
@@ -1,2 +0,0 @@
1
- export const camelToKebabCase = (string: string) =>
2
- string.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2').toLowerCase();
@@ -1,57 +0,0 @@
1
- import type { BuilderContextInterface } from '../context/types.js';
2
- import { isBrowser } from './is-browser.js';
3
- import { isEditing } from './is-editing.js';
4
-
5
- export function evaluate({
6
- code,
7
- context,
8
- state,
9
- event,
10
- isExpression = true,
11
- }: {
12
- code: string;
13
- event?: Event;
14
- isExpression?: boolean;
15
- } & Pick<BuilderContextInterface, 'state' | 'context'>): any {
16
- if (code === '') {
17
- console.warn('Skipping evaluation of empty code block.');
18
- return;
19
- }
20
-
21
- const builder = {
22
- isEditing: isEditing(),
23
- isBrowser: isBrowser(),
24
- isServer: !isBrowser(),
25
- };
26
-
27
- // Be able to handle simple expressions like "state.foo" or "1 + 1"
28
- // as well as full blocks like "var foo = "bar"; return foo"
29
- const useReturn =
30
- // we disable this for cases where we definitely don't want a return
31
- isExpression &&
32
- !(
33
- code.includes(';') ||
34
- code.includes(' return ') ||
35
- code.trim().startsWith('return ')
36
- );
37
-
38
- const useCode = useReturn ? `return (${code});` : code;
39
-
40
- try {
41
- return new Function(
42
- 'builder',
43
- 'Builder' /* <- legacy */,
44
- 'state',
45
- 'context',
46
- 'event',
47
- useCode
48
- )(builder, builder, state, context, event);
49
- } catch (e) {
50
- console.warn(
51
- 'Builder custom code error: \n While Evaluating: \n ',
52
- useCode,
53
- '\n',
54
- e
55
- );
56
- }
57
- }
@@ -1,6 +0,0 @@
1
- function capitalizeFirstLetter(string: string) {
2
- return string.charAt(0).toUpperCase() + string.slice(1);
3
- }
4
-
5
- export const getEventHandlerName = (key: string) =>
6
- `on${capitalizeFirstLetter(key)}`;
@@ -1,39 +0,0 @@
1
- const TEXT_STYLE_KEYS = [
2
- 'color',
3
- 'whiteSpace',
4
- 'direction',
5
- 'hyphens',
6
- 'overflowWrap',
7
- ];
8
-
9
- /**
10
- * Check if the key represent a CSS style property that applies to text
11
- * See MDN docs for refrence of what properties apply to text.
12
- * https://developer.mozilla.org/en-US/docs/Learn/CSS/Styling_text/Fundamentals#summary
13
- */
14
- const isTextStyle = (key: string) => {
15
- return (
16
- TEXT_STYLE_KEYS.includes(key) ||
17
- key.startsWith('font') ||
18
- key.startsWith('text') ||
19
- key.startsWith('letter') ||
20
- key.startsWith('line') ||
21
- key.startsWith('word') ||
22
- key.startsWith('writing')
23
- );
24
- };
25
-
26
- /**
27
- * Extract styles that apply to text from a style object.
28
- */
29
- export const extractTextStyles = (styles: Partial<CSSStyleDeclaration>) => {
30
- const textStyles: Partial<CSSStyleDeclaration> = {};
31
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
- Object.entries(styles).forEach(([key, value]: [any, any]) => {
33
- if (isTextStyle(key)) {
34
- textStyles[key] = value;
35
- }
36
- });
37
-
38
- return textStyles;
39
- };
@@ -1,5 +0,0 @@
1
- /**
2
- * We need to serialize values to a string in case there are Proxy values, as is the case with SolidJS etc.
3
- */
4
- export const fastClone = <T extends object>(obj: T): T =>
5
- JSON.parse(JSON.stringify(obj));
@@ -1,20 +0,0 @@
1
- import type { BuilderContextInterface } from '../context/types.js';
2
- import type { BuilderBlock } from '../types/builder-block.js';
3
- import { evaluate } from './evaluate.js';
4
-
5
- type Options = {
6
- block: BuilderBlock;
7
- } & Pick<BuilderContextInterface, 'state' | 'context'>;
8
-
9
- type EventHandler = (event: Event) => any;
10
-
11
- export const createEventHandler =
12
- (value: string, options: Options): EventHandler =>
13
- (event) =>
14
- evaluate({
15
- code: value,
16
- context: options.context,
17
- state: options.state,
18
- event,
19
- isExpression: false,
20
- });
@@ -1,25 +0,0 @@
1
- import type { BuilderContextInterface } from '../context/types.js';
2
- import type { BuilderBlock } from '../types/builder-block.js';
3
- import { getEventHandlerName } from './event-handler-name.js';
4
- import { createEventHandler } from './get-block-actions-handler.js';
5
-
6
- type Actions = { [index: string]: (event: Event) => any };
7
-
8
- export function getBlockActions(
9
- options: {
10
- block: BuilderBlock;
11
- } & Pick<BuilderContextInterface, 'state' | 'context'>
12
- ): Actions {
13
- const obj: Actions = {};
14
- const optionActions = options.block.actions ?? {};
15
-
16
- for (const key in optionActions) {
17
- // eslint-disable-next-line no-prototype-builtins
18
- if (!optionActions.hasOwnProperty(key)) {
19
- continue;
20
- }
21
- const value = optionActions[key];
22
- obj[getEventHandlerName(key)] = createEventHandler(value, options);
23
- }
24
- return obj;
25
- }
@@ -1,12 +0,0 @@
1
- import type { BuilderBlock } from '../types/builder-block.js';
2
-
3
- export function getBlockComponentOptions(block: BuilderBlock) {
4
- return {
5
- ...block.component?.options,
6
- ...(block as any).options,
7
- /**
8
- * Our built-in components frequently make use of the block, so we provide all of it under `builderBlock`
9
- */
10
- builderBlock: block,
11
- };
12
- }
@@ -1,75 +0,0 @@
1
- import { TARGET } from '../constants/target.js';
2
- import { convertStyleMapToCSSArray } from '../helpers/css.js';
3
- import type { BuilderBlock } from '../types/builder-block.js';
4
- import { transformBlockProperties } from './transform-block-properties.js';
5
-
6
- const extractRelevantRootBlockProperties = (block: BuilderBlock) => {
7
- // currently we are only spreading the `href` property
8
- // TO-DO: potentially spread all properties from block, but only if they are not already defined by BuilderBlock
9
-
10
- // const {
11
- // '@type': _type,
12
- // '@version': _version,
13
- // id: _id,
14
- // tagName: _tagName,
15
- // layerName: _layerName,
16
- // groupLocked: _groupLocked,
17
- // layerLocked: _layerLocked,
18
- // class: _class,
19
- // children: _children,
20
- // responsiveStyles: _responsiveStyles,
21
- // component: _component,
22
- // bindings: _bindings,
23
- // meta: _meta,
24
- // actions: _actions,
25
- // properties: _properties,
26
- // code: _code,
27
- // repeat: _repeat,
28
- // animations: _animations,
29
- // style: _style,
30
- // hide: _hide,
31
- // show: _show,
32
- // // anything set by dynamic bindings outside of predefined `BuilderBlock` properties
33
- // ...remainingBlockProperties
34
- // } = block;
35
-
36
- return { href: (block as any).href };
37
- };
38
-
39
- export function getBlockProperties(block: BuilderBlock) {
40
- const properties = {
41
- ...extractRelevantRootBlockProperties(block),
42
- ...block.properties,
43
- 'builder-id': block.id,
44
- style: getStyleAttribute(block.style),
45
- class: [block.id, 'builder-block', block.class, block.properties?.class]
46
- .filter(Boolean)
47
- .join(' '),
48
- };
49
-
50
- return transformBlockProperties(properties);
51
- }
52
- /**
53
- * Svelte does not support style attribute as an object so we need to flatten it.
54
- *
55
- * Additionally, Svelte, Vue and other frameworks use kebab-case styles, so we need to convert them.
56
- */
57
- function getStyleAttribute(
58
- style: Partial<CSSStyleDeclaration> | undefined
59
- ): string | Partial<CSSStyleDeclaration> | undefined {
60
- if (!style) {
61
- return undefined;
62
- }
63
-
64
- switch (TARGET) {
65
- case 'svelte':
66
- case 'vue2':
67
- case 'vue3':
68
- case 'solid':
69
- return convertStyleMapToCSSArray(style).join(' ');
70
- case 'qwik':
71
- case 'reactNative':
72
- case 'react':
73
- return style;
74
- }
75
- }
@@ -1,19 +0,0 @@
1
- import { convertSearchParamsToQueryObject, getBuilderSearchParams } from '.';
2
-
3
- const querystring =
4
- 'someotherValue=jklsjfdal&abc=klfdjklgfds&builder.cachebust=true&builder.preview=page&builder.noCache=true&__builder_editing__=true&builder.overrides.page=037948e52eaf4743afed464f02c70da4&builder.overrides.037948e52eaf4743afed464f02c70da4=037948e52eaf4743afed464f02c70da4&builder.overrides.page%3A%2F=037948e52eaf4743afed464f02c70da4&preview_theme_id=128854393017';
5
-
6
- const url = new URL(`localhost:3000/about-us?${querystring}`);
7
-
8
- describe('Get Builder SearchParams', () => {
9
- test('correctly converts URLSearchParams to object', () => {
10
- const output = convertSearchParamsToQueryObject(url.searchParams);
11
- expect(output).toMatchSnapshot();
12
- });
13
- test('correctly extracts all builder params from a query object', () => {
14
- const output = getBuilderSearchParams(
15
- convertSearchParamsToQueryObject(url.searchParams)
16
- );
17
- expect(output).toMatchSnapshot();
18
- });
19
- });
@@ -1,50 +0,0 @@
1
- import { isBrowser } from '../is-browser.js';
2
-
3
- const BUILDER_SEARCHPARAMS_PREFIX = 'builder.';
4
- const BUILDER_OPTIONS_PREFIX = 'options.';
5
- type QueryObject = Record<string, string | string[]>;
6
-
7
- export const convertSearchParamsToQueryObject = (
8
- searchParams: URLSearchParams
9
- ): QueryObject => {
10
- const options: Record<string, string> = {};
11
- searchParams.forEach((value, key) => {
12
- options[key] = value;
13
- });
14
- return options;
15
- };
16
-
17
- export const getBuilderSearchParams = (
18
- _options: QueryObject | URLSearchParams | undefined
19
- ) => {
20
- if (!_options) {
21
- return {};
22
- }
23
- const options = normalizeSearchParams(_options);
24
-
25
- const newOptions: QueryObject = {};
26
- Object.keys(options).forEach((key) => {
27
- if (key.startsWith(BUILDER_SEARCHPARAMS_PREFIX)) {
28
- const trimmedKey = key
29
- .replace(BUILDER_SEARCHPARAMS_PREFIX, '')
30
- .replace(BUILDER_OPTIONS_PREFIX, '');
31
- newOptions[trimmedKey] = options[key];
32
- }
33
- });
34
- return newOptions;
35
- };
36
-
37
- export const getBuilderSearchParamsFromWindow = () => {
38
- if (!isBrowser()) {
39
- return {};
40
- }
41
- const searchParams = new URLSearchParams(window.location.search);
42
- return getBuilderSearchParams(searchParams);
43
- };
44
-
45
- export const normalizeSearchParams = (
46
- searchParams: QueryObject | URLSearchParams
47
- ): QueryObject =>
48
- searchParams instanceof URLSearchParams
49
- ? convertSearchParamsToQueryObject(searchParams)
50
- : searchParams;
@@ -1,132 +0,0 @@
1
- import type {
2
- BuilderContent,
3
- BuilderContentVariation,
4
- } from '../../types/builder-content.js';
5
- import {
6
- getContentVariationCookie,
7
- setContentVariationCookie,
8
- } from '../../helpers/ab-tests.js';
9
- import type { Overwrite } from '../../types/typescript.js';
10
- import type { CanTrack } from '../../types/can-track.js';
11
- import { checkIsDefined } from '../../helpers/nullable.js';
12
-
13
- type BuilderContentWithVariations = Overwrite<
14
- BuilderContent,
15
- Required<Pick<BuilderContent, 'variations' | 'id'>>
16
- >;
17
-
18
- const checkIsBuilderContentWithVariations = (
19
- item: BuilderContent
20
- ): item is BuilderContentWithVariations =>
21
- checkIsDefined(item.id) &&
22
- checkIsDefined(item.variations) &&
23
- Object.keys(item.variations).length > 0;
24
-
25
- /**
26
- * Randomly assign a variation to this user and store it in cookies/storage
27
- */
28
- const getRandomVariationId = ({
29
- id,
30
- variations,
31
- }: BuilderContentWithVariations) => {
32
- let n = 0;
33
- const random = Math.random();
34
-
35
- // loop over variations test ratios, incrementing a counter,
36
- // until we find the variation that this user should be assigned to
37
- for (const id in variations) {
38
- const testRatio = variations[id]?.testRatio;
39
- n += testRatio!;
40
-
41
- if (random < n) {
42
- return id;
43
- }
44
- }
45
-
46
- // `item.variations` does not include the default variation
47
- // if we arrive here, then it means that the random number fits in the default variation bucket
48
- return id;
49
- };
50
-
51
- const getTestFields = ({
52
- item,
53
- testGroupId,
54
- }: {
55
- item: BuilderContentWithVariations;
56
- testGroupId: string;
57
- }): TestFields => {
58
- const variationValue = item.variations[testGroupId];
59
- if (
60
- testGroupId === item.id ||
61
- // handle edge-case where `testGroupId` points to non-existing variation
62
- !variationValue
63
- ) {
64
- return {
65
- testVariationId: item.id,
66
- testVariationName: 'Default',
67
- };
68
- } else {
69
- return {
70
- data: variationValue.data,
71
- testVariationId: variationValue.id,
72
- testVariationName:
73
- variationValue.name || (variationValue.id === item.id ? 'Default' : ''),
74
- };
75
- }
76
- };
77
-
78
- type TestFields = {
79
- data?: BuilderContentVariation['data'];
80
- testVariationId?: string;
81
- testVariationName: string;
82
- };
83
-
84
- const getContentVariation = async ({
85
- item,
86
- canTrack,
87
- }: {
88
- item: BuilderContentWithVariations;
89
- } & CanTrack): Promise<TestFields> => {
90
- // try to find test variation in cookies/storage
91
- const testGroupId = await getContentVariationCookie({
92
- canTrack,
93
- contentId: item.id,
94
- });
95
-
96
- const testFields = testGroupId
97
- ? getTestFields({ item, testGroupId })
98
- : undefined;
99
-
100
- if (testFields) {
101
- return testFields;
102
- } else {
103
- // if variation not found in storage, assign a random variation to this user
104
- const randomVariationId = getRandomVariationId({
105
- variations: item.variations,
106
- id: item.id,
107
- });
108
-
109
- // store variation in cookies/storage
110
- setContentVariationCookie({
111
- contentId: item.id,
112
- value: randomVariationId,
113
- canTrack,
114
- }).catch((err) => {
115
- console.error('could not store A/B test variation: ', err);
116
- });
117
-
118
- return getTestFields({ item, testGroupId: randomVariationId });
119
- }
120
- };
121
-
122
- export const handleABTesting = async ({
123
- item,
124
- canTrack,
125
- }: { item: BuilderContent } & CanTrack) => {
126
- if (!checkIsBuilderContentWithVariations(item)) {
127
- return;
128
- }
129
-
130
- const variationValue = await getContentVariation({ item, canTrack });
131
- Object.assign(item, variationValue);
132
- };
@@ -1,95 +0,0 @@
1
- import { generateContentUrl } from './generate-content-url';
2
- import type { GetContentOptions } from './types';
3
-
4
- const testKey = 'YJIGb4i01jvw0SRdL5Bt';
5
- const testModel = 'page';
6
- const testId = 'c1b81bab59704599b997574eb0736def';
7
-
8
- const options = {
9
- cachebust: 'true',
10
- noCache: 'true',
11
- 'overrides.037948e52eaf4743afed464f02c70da4':
12
- '037948e52eaf4743afed464f02c70da4',
13
- 'overrides.page': '037948e52eaf4743afed464f02c70da4',
14
- 'overrides.page:/': '037948e52eaf4743afed464f02c70da4',
15
- preview: 'page',
16
- };
17
-
18
- describe('Generate Content URL', () => {
19
- test('generates the proper value for a simple query', () => {
20
- const output = generateContentUrl({
21
- apiKey: testKey,
22
- model: testModel,
23
- query: { id: testId },
24
- });
25
- expect(output).toMatchSnapshot();
26
- });
27
-
28
- test('Handles overrides correctly', () => {
29
- const output = generateContentUrl({
30
- apiKey: testKey,
31
- model: testModel,
32
- query: { id: testId },
33
- options,
34
- });
35
- expect(output).toMatchSnapshot();
36
- });
37
-
38
- test('generate content url with apiVersion as default', () => {
39
- const output = generateContentUrl({
40
- apiKey: testKey,
41
- model: testModel,
42
- query: { id: testId },
43
- options,
44
- });
45
- expect(output).toMatchSnapshot();
46
- });
47
-
48
- test('generate content url with apiVersion as v2', () => {
49
- const output = generateContentUrl({
50
- apiKey: testKey,
51
- model: testModel,
52
- query: { id: testId },
53
- options,
54
- apiVersion: 'v2',
55
- });
56
- expect(output).toMatchSnapshot();
57
- });
58
-
59
- test('generate content url with apiVersion as v3', () => {
60
- const output = generateContentUrl({
61
- apiKey: testKey,
62
- model: testModel,
63
- query: { id: testId },
64
- options,
65
- apiVersion: 'v3',
66
- });
67
- expect(output).toMatchSnapshot();
68
- });
69
-
70
- test('throw error when trying to generate content url with apiVersion as v1', () => {
71
- expect(() => {
72
- generateContentUrl({
73
- apiKey: testKey,
74
- model: testModel,
75
- query: { id: testId },
76
- options,
77
- apiVersion: 'v1' as GetContentOptions['apiVersion'],
78
- });
79
- }).toThrow(`Invalid apiVersion: expected 'v2' or 'v3', received 'v1'`);
80
- });
81
-
82
- test('throw error when trying to generate content url with an invalid apiVersion value', () => {
83
- expect(() => {
84
- generateContentUrl({
85
- apiKey: testKey,
86
- model: testModel,
87
- query: { id: testId },
88
- options,
89
- apiVersion: 'INVALID_API_VERSION' as GetContentOptions['apiVersion'],
90
- });
91
- }).toThrow(
92
- `Invalid apiVersion: expected 'v2' or 'v3', received 'INVALID_API_VERSION'`
93
- );
94
- });
95
- });