@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,59 +0,0 @@
1
- import { flatten } from '../../helpers/flatten.js';
2
- import {
3
- getBuilderSearchParamsFromWindow,
4
- normalizeSearchParams,
5
- } from '../get-builder-search-params/index.js';
6
- import type { GetContentOptions } from './types.js';
7
- import { DEFAULT_API_VERSION } from '../../types/api-version';
8
-
9
- export const generateContentUrl = (options: GetContentOptions): URL => {
10
- const {
11
- limit = 30,
12
- userAttributes,
13
- query,
14
- noTraverse = false,
15
- model,
16
- apiKey,
17
- includeRefs = true,
18
- locale,
19
- apiVersion = DEFAULT_API_VERSION,
20
- } = options;
21
-
22
- if (!apiKey) {
23
- throw new Error('Missing API key');
24
- }
25
-
26
- if (!['v2', 'v3'].includes(apiVersion)) {
27
- throw new Error(
28
- `Invalid apiVersion: expected 'v2' or 'v3', received '${apiVersion}'`
29
- );
30
- }
31
-
32
- const url = new URL(
33
- `https://cdn.builder.io/api/${apiVersion}/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}${
34
- locale ? `&locale=${locale}` : ''
35
- }`
36
- );
37
-
38
- const queryOptions = {
39
- ...getBuilderSearchParamsFromWindow(),
40
- ...normalizeSearchParams(options.options || {}),
41
- };
42
-
43
- const flattened = flatten(queryOptions);
44
- for (const key in flattened) {
45
- url.searchParams.set(key, String(flattened[key]));
46
- }
47
-
48
- if (userAttributes) {
49
- url.searchParams.set('userAttributes', JSON.stringify(userAttributes));
50
- }
51
- if (query) {
52
- const flattened = flatten({ query });
53
- for (const key in flattened) {
54
- url.searchParams.set(key, JSON.stringify((flattened as any)[key]));
55
- }
56
- }
57
-
58
- return url;
59
- };
@@ -1,62 +0,0 @@
1
- import { logger } from '../../helpers/logger.js';
2
- import type { BuilderContent } from '../../types/builder-content.js';
3
- import { fetch } from '../get-fetch.js';
4
- import { handleABTesting } from './ab-testing.js';
5
- import { generateContentUrl } from './generate-content-url.js';
6
- import type { GetContentOptions } from './types.js';
7
-
8
- export async function getContent(
9
- options: GetContentOptions
10
- ): Promise<BuilderContent | null> {
11
- const allContent = await getAllContent({ ...options, limit: 1 });
12
- if (allContent && 'results' in allContent) {
13
- return allContent?.results[0] || null;
14
- }
15
-
16
- return null;
17
- }
18
-
19
- type ContentResponse =
20
- | {
21
- results: BuilderContent[];
22
- }
23
- | {
24
- status: number;
25
- message: string;
26
- };
27
-
28
- export async function getAllContent(
29
- options: GetContentOptions
30
- ): Promise<ContentResponse | null> {
31
- try {
32
- const url = generateContentUrl(options);
33
-
34
- const res = await fetch(url.href);
35
- const content = await (res.json() as Promise<ContentResponse>);
36
-
37
- if ('status' in content && !('results' in content)) {
38
- logger.error('Error fetching data. ', { url, content, options });
39
- return content;
40
- }
41
-
42
- const canTrack = options.canTrack !== false;
43
- try {
44
- if (
45
- canTrack &&
46
- // This makes sure we have a non-error response with the results array.
47
- Array.isArray(content.results)
48
- ) {
49
- for (const item of content.results) {
50
- await handleABTesting({ item, canTrack });
51
- }
52
- }
53
- } catch (e) {
54
- logger.error('Could not setup A/B testing. ', e);
55
- }
56
-
57
- return content;
58
- } catch (error) {
59
- logger.error('Error fetching data. ', error);
60
- return null;
61
- }
62
- }
@@ -1,53 +0,0 @@
1
- export interface GetContentOptions {
2
- /** The model to get content for */
3
- model: string;
4
-
5
- /** Your public API key */
6
- apiKey: string;
7
-
8
- /** Number of items to fetch. Default is 1 */
9
- limit?: number;
10
-
11
- /** User attributes to target on, such as { urlPath: '/foo', device: 'mobile', ...etc } */
12
- userAttributes?: (Record<string, string> & { urlPath?: string }) | null;
13
-
14
- /** Custom query */
15
- query?: Record<string, any>;
16
-
17
- /**
18
- * Any other API options.
19
- * Accepts both a key/value object or a `URLSearchParams` instance
20
- * */
21
- options?: Record<string, any> | URLSearchParams;
22
-
23
- /**
24
- * If set to `true`, it will lazy load symbols/references.
25
- * If set to `false`, it will render the entire content tree eagerly.
26
- */
27
- noTraverse?: boolean;
28
-
29
- /**
30
- * If set to `false`, it will not use cookies to target content. Therefore, A/B Testing will be disabled and
31
- * only the default variation will be returned to every user.
32
- *
33
- * Defaults to `true`.
34
- */
35
- canTrack?: boolean;
36
-
37
- /**
38
- * Include references in the response. Defaults to `true`.
39
- */
40
- includeRefs?: boolean;
41
-
42
- /**
43
- * If provided, the API will auto-resolve localized objects to the value of this `locale` key.
44
- */
45
- locale?: string;
46
-
47
- /**
48
- * If provided, sets the Builder API version used to fetch content.
49
- *
50
- * Defaults to `v3`.
51
- */
52
- apiVersion?: 'v2' | 'v3';
53
- }
@@ -1,18 +0,0 @@
1
- import { getGlobalThis } from './get-global-this.js';
2
-
3
- function getFetch(): typeof global.fetch {
4
- const globalFetch: typeof global.fetch = getGlobalThis().fetch;
5
-
6
- if (typeof globalFetch === 'undefined') {
7
- console.warn(
8
- `Builder SDK could not find a global fetch function. Make sure you have a polyfill for fetch in your project.
9
- For more information, read https://github.com/BuilderIO/this-package-uses-fetch`
10
- );
11
-
12
- throw new Error('Builder SDK could not find a global `fetch` function');
13
- }
14
-
15
- return globalFetch;
16
- }
17
-
18
- export const fetch = getFetch();
@@ -1,17 +0,0 @@
1
- type Global = typeof global | typeof window | typeof self | typeof globalThis;
2
-
3
- export function getGlobalThis(): Global {
4
- if (typeof globalThis !== 'undefined') {
5
- return globalThis;
6
- }
7
- if (typeof window !== 'undefined') {
8
- return window;
9
- }
10
- if (typeof global !== 'undefined') {
11
- return global;
12
- }
13
- if (typeof self !== 'undefined') {
14
- return self;
15
- }
16
- return globalThis;
17
- }
@@ -1,33 +0,0 @@
1
- import type { BuilderBlock } from '../types/builder-block.js';
2
- import { getProcessedBlock } from './get-processed-block.js';
3
-
4
- test('Can process bindings', () => {
5
- const block: BuilderBlock = {
6
- '@type': '@builder.io/sdk:Element',
7
- properties: {
8
- foo: 'bar',
9
- },
10
- bindings: {
11
- 'properties.foo': '"baz"',
12
- 'responsiveStyles.large.zIndex': '1 + 1',
13
- 'properties.test': 'state.test',
14
- 'properties.block': `
15
- const foo = 'bar';
16
- return foo;
17
- `,
18
- 'properties.isEditing': 'builder.isEditing',
19
- },
20
- };
21
- const processed = getProcessedBlock({
22
- block,
23
- context: {},
24
- state: { test: 'hello' },
25
- shouldEvaluateBindings: true,
26
- });
27
- expect(processed).not.toEqual(block);
28
- expect(processed.properties?.foo).toEqual('baz');
29
- expect(processed.properties?.test).toEqual('hello');
30
- expect(processed.properties?.block).toEqual('bar');
31
- expect(processed.properties?.isEditing).toEqual(false);
32
- expect(processed.responsiveStyles?.large?.zIndex).toEqual(2);
33
- });
@@ -1,54 +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
- import { fastClone } from './fast-clone.js';
5
- import { set } from './set.js';
6
- import { transformBlock } from './transform-block.js';
7
-
8
- const evaluateBindings = ({
9
- block,
10
- context,
11
- state,
12
- }: {
13
- block: BuilderBlock;
14
- } & Pick<BuilderContextInterface, 'state' | 'context'>): BuilderBlock => {
15
- if (!block.bindings) {
16
- return block;
17
- }
18
- const copy = fastClone(block);
19
- const copied = {
20
- ...copy,
21
- properties: { ...copy.properties },
22
- actions: { ...copy.actions },
23
- };
24
-
25
- for (const binding in block.bindings) {
26
- const expression = block.bindings[binding];
27
- const value = evaluate({ code: expression, state, context });
28
- set(copied, binding, value);
29
- }
30
-
31
- return copied;
32
- };
33
-
34
- export function getProcessedBlock({
35
- block,
36
- context,
37
- shouldEvaluateBindings,
38
- state,
39
- }: {
40
- block: BuilderBlock;
41
- /**
42
- * In some cases, we want to avoid evaluating bindings and only want framework-specific block transformation. It is
43
- * also sometimes too early to consider bindings, e.g. when we might be looking at a repeated block.
44
- */
45
- shouldEvaluateBindings: boolean;
46
- } & Pick<BuilderContextInterface, 'state' | 'context'>): BuilderBlock {
47
- const transformedBlock = transformBlock(block);
48
-
49
- if (shouldEvaluateBindings) {
50
- return evaluateBindings({ block: transformedBlock, state, context });
51
- } else {
52
- return transformedBlock;
53
- }
54
- }
@@ -1,33 +0,0 @@
1
- import type { BuilderContextInterface } from '../context/types.js';
2
- import type { BuilderBlock } from '../types/builder-block.js';
3
- import { sanitizeReactNativeBlockStyles } from './sanitize-react-native-block-styles.js';
4
-
5
- export function getReactNativeBlockStyles({
6
- block,
7
- context,
8
- blockStyles,
9
- }: {
10
- block: BuilderBlock;
11
- context: BuilderContextInterface;
12
- blockStyles: any;
13
- }): CSSStyleDeclaration | Record<string, string | undefined> {
14
- const responsiveStyles = block.responsiveStyles;
15
- if (!responsiveStyles) {
16
- return {};
17
- }
18
-
19
- const styles = {
20
- // recursively apply inherited styles so that they can be passed down to children `Text` blocks
21
- ...context.inheritedStyles,
22
- ...(responsiveStyles.large || {}),
23
- ...(responsiveStyles.medium || {}),
24
- ...(responsiveStyles.small || {}),
25
- ...blockStyles,
26
- } as Record<string, string | number>;
27
-
28
- const newStyles = sanitizeReactNativeBlockStyles(
29
- styles
30
- ) as any as CSSStyleDeclaration;
31
-
32
- return newStyles;
33
- }
@@ -1,20 +0,0 @@
1
- import { TARGET } from '../constants/target.js';
2
-
3
- type Target = import('../types/targets').Target;
4
-
5
- // TODO: babel compile to include certain code only if the target matches
6
- export function ifTarget<A, B>({
7
- targets,
8
- doThing,
9
- elseThing,
10
- }: {
11
- targets: Target[];
12
- doThing: () => A;
13
- elseThing?: () => B;
14
- }) {
15
- if (TARGET && targets.includes(TARGET)) {
16
- return doThing();
17
- } else {
18
- return elseThing?.();
19
- }
20
- }
@@ -1,3 +0,0 @@
1
- export function isBrowser(): boolean {
2
- return typeof window !== 'undefined' && typeof document !== 'undefined';
3
- }
@@ -1,10 +0,0 @@
1
- import { TARGET } from '../constants/target.js';
2
- import { isIframe } from './is-iframe.js';
3
-
4
- export function isEditing(): boolean {
5
- return (
6
- isIframe() &&
7
- (TARGET === 'reactNative' ||
8
- window.location.search.indexOf('builder.frameEditing=') !== -1)
9
- );
10
- }
@@ -1,5 +0,0 @@
1
- import { isBrowser } from './is-browser.js';
2
-
3
- export function isIframe(): boolean {
4
- return isBrowser() && window.self !== window.top;
5
- }
@@ -1,14 +0,0 @@
1
- import { isBrowser } from './is-browser.js';
2
- import { isEditing } from './is-editing.js';
3
-
4
- export function isPreviewing() {
5
- if (!isBrowser()) {
6
- return false;
7
- }
8
-
9
- if (isEditing()) {
10
- return false;
11
- }
12
-
13
- return Boolean(location.search.indexOf('builder.preview=') !== -1);
14
- }
@@ -1,23 +0,0 @@
1
- import { onChange } from './on-change.js';
2
-
3
- test('onChange can observe a shallow change', () => {
4
- let changeHappend = false;
5
- const obj = onChange({ foo: 'hi' }, () => (changeHappend = true));
6
- obj.foo = 'yo';
7
- expect(changeHappend).toBe(true);
8
- });
9
-
10
- test('onChange can observe a deep change', () => {
11
- let changeHappend = false;
12
- const obj = onChange({ foo: { bar: 'hi' } }, () => (changeHappend = true));
13
- obj.foo.bar = 'yo';
14
- expect(changeHappend).toBe(true);
15
- });
16
-
17
- test('Smoke test: callback is not fired if no properties updated', () => {
18
- let changeHappend = false;
19
- const obj = onChange({ foo: { bar: 'hi' } }, () => (changeHappend = true));
20
- // Access some properties
21
- obj.foo.bar;
22
- expect(changeHappend).toBe(false);
23
- });
@@ -1,29 +0,0 @@
1
- export const onChangeProxySymbol = Symbol('onChangeProxySymbol');
2
-
3
- /**
4
- * Deeply observe an object and run a callback when it changes
5
- *
6
- * See ./on-change.test.ts for more info
7
- */
8
- export function onChange<T extends object = any>(obj: T, cb: () => void): T {
9
- return new Proxy(obj, {
10
- get(target, key) {
11
- if (key === onChangeProxySymbol) {
12
- return true;
13
- }
14
- const value = Reflect.get(target, key);
15
- if (value && typeof value === 'object') {
16
- if ((value as any)[onChangeProxySymbol]) {
17
- return value;
18
- }
19
- return onChange(value, cb);
20
- }
21
- return value;
22
- },
23
- set(target, key, value) {
24
- const returnValue = Reflect.set(target, key, value);
25
- cb();
26
- return returnValue;
27
- },
28
- });
29
- }
@@ -1,50 +0,0 @@
1
- import { serializeFn } from '../blocks/util.js';
2
- import type { RegisteredComponent } from '../context/types.js';
3
- import type { ComponentInfo } from '../types/components.js';
4
- import type { Input } from '../types/input.js';
5
- import { fastClone } from './fast-clone.js';
6
-
7
- /**
8
- * @deprecated. Use the `customComponents` prop in RenderContent instead to provide your custom components to the builder SDK.
9
- */
10
- export const components: RegisteredComponent[] = [];
11
-
12
- /**
13
- * @deprecated. Use the `customComponents` prop in RenderContent instead to provide your custom components to the builder SDK.
14
- */
15
- export function registerComponent(component: any, info: ComponentInfo): void {
16
- components.push({ component, ...info });
17
-
18
- console.warn(
19
- 'registerComponent is deprecated. Use the `customComponents` prop in RenderContent instead to provide your custom components to the builder SDK.'
20
- );
21
-
22
- return component;
23
- }
24
-
25
- export const createRegisterComponentMessage = ({
26
- component: _,
27
- ...info
28
- }: RegisteredComponent) => ({
29
- type: 'builder.registerComponent',
30
- data: prepareComponentInfoToSend(info),
31
- });
32
-
33
- const serializeValue = (value: object): any =>
34
- typeof value === 'function' ? serializeFn(value) : fastClone(value);
35
-
36
- const prepareComponentInfoToSend = ({
37
- inputs,
38
- ...info
39
- }: ComponentInfo): ComponentInfo => ({
40
- ...fastClone(info),
41
- inputs: inputs?.map((input) =>
42
- Object.entries(input).reduce(
43
- (acc, [key, value]) => ({
44
- ...acc,
45
- [key]: serializeValue(value),
46
- }),
47
- {} as Input
48
- )
49
- ),
50
- });
@@ -1,46 +0,0 @@
1
- import type { BuilderBlock } from '../types/builder-block.js';
2
- import type { DeepPartial } from '../types/deep-partial.js';
3
- import { isBrowser } from './is-browser.js';
4
-
5
- export interface InsertMenuItem {
6
- name: string;
7
- icon?: string;
8
- item: DeepPartial<BuilderBlock>;
9
- }
10
-
11
- export interface InsertMenuConfig {
12
- name: string;
13
- priority?: number;
14
- persist?: boolean;
15
- advanced?: boolean;
16
- items: InsertMenuItem[];
17
- }
18
-
19
- const registry: { [key: string]: any[] } = {};
20
-
21
- export function register(type: 'insertMenu', info: InsertMenuConfig): void;
22
- export function register(type: string, info: any): void;
23
- export function register(type: string, info: any) {
24
- let typeList = registry[type];
25
- if (!typeList) {
26
- typeList = registry[type] = [];
27
- }
28
- typeList.push(info);
29
- if (isBrowser()) {
30
- const message = {
31
- type: 'builder.register',
32
- data: {
33
- type,
34
- info,
35
- },
36
- };
37
- try {
38
- parent.postMessage(message, '*');
39
- if (parent !== window) {
40
- window.postMessage(message, '*');
41
- }
42
- } catch (err) {
43
- console.debug('Could not postmessage', err);
44
- }
45
- }
46
- }
@@ -1,65 +0,0 @@
1
- const propertiesThatMustBeNumber = new Set(['lineHeight']);
2
- const displayValues = new Set(['flex', 'none']);
3
-
4
- const SHOW_WARNINGS = false;
5
-
6
- type Styles = Record<string, string | number>;
7
-
8
- const normalizeNumber = (value: number): number | undefined => {
9
- if (Number.isNaN(value)) {
10
- return undefined;
11
- } else if (value < 0) {
12
- // TODO: why are negative values not allowed?
13
- return 0;
14
- } else {
15
- return value;
16
- }
17
- };
18
-
19
- export const sanitizeReactNativeBlockStyles = (styles: Styles): Styles => {
20
- return Object.keys(styles).reduce<Styles>((acc, key): Styles => {
21
- const propertyValue = styles[key];
22
-
23
- if (key === 'display' && !displayValues.has(propertyValue as string)) {
24
- if (SHOW_WARNINGS) {
25
- console.warn(
26
- `Style value for key "display" must be "flex" or "none" but had ${propertyValue}`
27
- );
28
- }
29
- return acc;
30
- }
31
-
32
- if (
33
- propertiesThatMustBeNumber.has(key) &&
34
- typeof propertyValue !== 'number'
35
- ) {
36
- if (SHOW_WARNINGS) {
37
- console.warn(
38
- `Style key ${key} must be a number, but had value \`${styles[key]}\``
39
- );
40
- }
41
- return acc;
42
- }
43
-
44
- if (typeof propertyValue === 'string') {
45
- // `px` units need to be stripped and replaced with numbers
46
- // https://regexr.com/6ualn
47
- const isPixelUnit = propertyValue.match(/^-?(\d*)(\.?)(\d*)*px$/);
48
-
49
- if (isPixelUnit) {
50
- const newValue = parseFloat(propertyValue);
51
- const normalizedValue = normalizeNumber(newValue);
52
- if (normalizedValue) {
53
- return { ...acc, [key]: normalizedValue };
54
- } else {
55
- return acc;
56
- }
57
- } else if (propertyValue === '0') {
58
- // 0 edge case needs to be handled
59
- return { ...acc, [key]: 0 };
60
- }
61
- }
62
-
63
- return { ...acc, [key]: propertyValue };
64
- }, {});
65
- };
@@ -1,16 +0,0 @@
1
- import { isBrowser } from './is-browser.js';
2
-
3
- const settings: Settings = {};
4
-
5
- export type Settings = { customInsertMenu?: boolean };
6
-
7
- export function setEditorSettings(newSettings: Settings) {
8
- if (isBrowser()) {
9
- Object.assign(settings, newSettings);
10
- const message = {
11
- type: 'builder.settingsChange',
12
- data: settings,
13
- };
14
- parent.postMessage(message, '*');
15
- }
16
- }
@@ -1,19 +0,0 @@
1
- import { set } from './set.js';
2
-
3
- test('can shallow set a property', () => {
4
- const obj = { foo: 'bar' };
5
- set(obj, 'foo', 'baz');
6
- expect(obj.foo).toBe('baz');
7
- });
8
-
9
- test('can deeply set a property', () => {
10
- const obj = { foo: 'bar' };
11
- set(obj, 'foo.bar', 'baz');
12
- expect((obj.foo as any).bar).toBe('baz');
13
- });
14
-
15
- test('can deeply create arrays', () => {
16
- const obj = { foo: 'bar' };
17
- set(obj, 'foo.bar.0', 'hi');
18
- expect((obj.foo as any).bar).toEqual(['hi']);
19
- });
@@ -1,26 +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: any, _path: string | string[], value: any) => {
8
- if (Object(obj) !== obj) {
9
- return obj;
10
- }
11
- const path: string[] = Array.isArray(_path)
12
- ? _path
13
- : (_path.toString().match(/[^.[\]]+/g) as string[]);
14
-
15
- path
16
- .slice(0, -1)
17
- .reduce(
18
- (a, c, i) =>
19
- Object(a[c]) === a[c]
20
- ? a[c]
21
- : (a[c] =
22
- Math.abs(Number(path[i + 1])) >> 0 === +path[i + 1] ? [] : {}),
23
- obj
24
- )[path[path.length - 1]] = value;
25
- return obj;
26
- };