@builder.io/sdk-react-native 1.0.32 → 1.0.34

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 (277) hide show
  1. package/lib/browser/commonjs/blocks/text/text.js +1 -1
  2. package/lib/browser/commonjs/constants/sdk-version.js +1 -1
  3. package/lib/browser/commonjs/functions/evaluate/node-runtime/safeDynamicRequire.js +4 -18
  4. package/lib/browser/commonjs/functions/evaluate/node-runtime/safeDynamicRequire.js.map +1 -1
  5. package/lib/browser/commonjs/functions/is-from-trusted-host.js +3 -0
  6. package/lib/browser/commonjs/functions/is-from-trusted-host.js.map +1 -1
  7. package/lib/browser/commonjs/helpers/cookie.js +12 -2
  8. package/lib/browser/commonjs/helpers/cookie.js.map +1 -1
  9. package/lib/browser/module/blocks/text/text.js +1 -1
  10. package/lib/browser/module/blocks/text/text.js.map +1 -1
  11. package/lib/browser/module/constants/sdk-version.js +1 -1
  12. package/lib/browser/module/functions/evaluate/node-runtime/safeDynamicRequire.js +5 -18
  13. package/lib/browser/module/functions/evaluate/node-runtime/safeDynamicRequire.js.map +1 -1
  14. package/lib/browser/module/functions/is-from-trusted-host.js +3 -0
  15. package/lib/browser/module/functions/is-from-trusted-host.js.map +1 -1
  16. package/lib/browser/module/helpers/cookie.js +11 -2
  17. package/lib/browser/module/helpers/cookie.js.map +1 -1
  18. package/lib/browser/typescript/constants/sdk-version.d.ts +1 -1
  19. package/lib/browser/typescript/functions/is-from-trusted-host.d.ts.map +1 -1
  20. package/lib/browser/typescript/helpers/cookie.d.ts +1 -0
  21. package/lib/browser/typescript/helpers/cookie.d.ts.map +1 -1
  22. package/lib/edge/commonjs/blocks/text/text.js +1 -1
  23. package/lib/edge/commonjs/constants/sdk-version.js +1 -1
  24. package/lib/edge/commonjs/functions/evaluate/node-runtime/safeDynamicRequire.js +4 -18
  25. package/lib/edge/commonjs/functions/evaluate/node-runtime/safeDynamicRequire.js.map +1 -1
  26. package/lib/edge/commonjs/functions/is-from-trusted-host.js +3 -0
  27. package/lib/edge/commonjs/functions/is-from-trusted-host.js.map +1 -1
  28. package/lib/edge/commonjs/helpers/cookie.js +12 -2
  29. package/lib/edge/commonjs/helpers/cookie.js.map +1 -1
  30. package/lib/edge/module/blocks/text/text.js +1 -1
  31. package/lib/edge/module/blocks/text/text.js.map +1 -1
  32. package/lib/edge/module/constants/sdk-version.js +1 -1
  33. package/lib/edge/module/functions/evaluate/node-runtime/safeDynamicRequire.js +5 -18
  34. package/lib/edge/module/functions/evaluate/node-runtime/safeDynamicRequire.js.map +1 -1
  35. package/lib/edge/module/functions/is-from-trusted-host.js +3 -0
  36. package/lib/edge/module/functions/is-from-trusted-host.js.map +1 -1
  37. package/lib/edge/module/helpers/cookie.js +11 -2
  38. package/lib/edge/module/helpers/cookie.js.map +1 -1
  39. package/lib/edge/typescript/constants/sdk-version.d.ts +1 -1
  40. package/lib/edge/typescript/functions/is-from-trusted-host.d.ts.map +1 -1
  41. package/lib/edge/typescript/helpers/cookie.d.ts +1 -0
  42. package/lib/edge/typescript/helpers/cookie.d.ts.map +1 -1
  43. package/lib/node/commonjs/blocks/text/text.js +1 -1
  44. package/lib/node/commonjs/constants/sdk-version.js +1 -1
  45. package/lib/node/commonjs/functions/evaluate/node-runtime/safeDynamicRequire.js +4 -18
  46. package/lib/node/commonjs/functions/evaluate/node-runtime/safeDynamicRequire.js.map +1 -1
  47. package/lib/node/commonjs/functions/is-from-trusted-host.js +3 -0
  48. package/lib/node/commonjs/functions/is-from-trusted-host.js.map +1 -1
  49. package/lib/node/commonjs/helpers/cookie.js +12 -2
  50. package/lib/node/commonjs/helpers/cookie.js.map +1 -1
  51. package/lib/node/module/blocks/text/text.js +1 -1
  52. package/lib/node/module/blocks/text/text.js.map +1 -1
  53. package/lib/node/module/constants/sdk-version.js +1 -1
  54. package/lib/node/module/functions/evaluate/node-runtime/safeDynamicRequire.js +5 -18
  55. package/lib/node/module/functions/evaluate/node-runtime/safeDynamicRequire.js.map +1 -1
  56. package/lib/node/module/functions/is-from-trusted-host.js +3 -0
  57. package/lib/node/module/functions/is-from-trusted-host.js.map +1 -1
  58. package/lib/node/module/helpers/cookie.js +11 -2
  59. package/lib/node/module/helpers/cookie.js.map +1 -1
  60. package/lib/node/typescript/constants/sdk-version.d.ts +1 -1
  61. package/lib/node/typescript/functions/is-from-trusted-host.d.ts.map +1 -1
  62. package/lib/node/typescript/helpers/cookie.d.ts +1 -0
  63. package/lib/node/typescript/helpers/cookie.d.ts.map +1 -1
  64. package/package.json +10 -7
  65. package/src/blocks/BaseText.tsx +17 -0
  66. package/src/blocks/accordion/accordion.tsx +181 -0
  67. package/src/blocks/accordion/accordion.types.ts +12 -0
  68. package/src/blocks/accordion/component-info.ts +124 -0
  69. package/src/blocks/accordion/helpers.ts +3 -0
  70. package/src/blocks/accordion/index.ts +1 -0
  71. package/src/blocks/button/button.tsx +56 -0
  72. package/src/blocks/button/button.types.ts +7 -0
  73. package/src/blocks/button/component-info.ts +35 -0
  74. package/src/blocks/button/index.ts +1 -0
  75. package/src/blocks/columns/columns.tsx +199 -0
  76. package/src/blocks/columns/columns.types.ts +14 -0
  77. package/src/blocks/columns/component-info.ts +219 -0
  78. package/src/blocks/columns/helpers.ts +3 -0
  79. package/src/blocks/columns/index.ts +1 -0
  80. package/src/blocks/custom-code/component-info.ts +24 -0
  81. package/src/blocks/custom-code/custom-code.tsx +71 -0
  82. package/src/blocks/custom-code/index.ts +1 -0
  83. package/src/blocks/embed/component-info.ts +38 -0
  84. package/src/blocks/embed/embed.tsx +62 -0
  85. package/src/blocks/embed/helpers.ts +2 -0
  86. package/src/blocks/embed/index.ts +1 -0
  87. package/src/blocks/form/form/component-info.ts +233 -0
  88. package/src/blocks/form/form/form.tsx +324 -0
  89. package/src/blocks/form/form/index.ts +1 -0
  90. package/src/blocks/form/input/component-info.ts +47 -0
  91. package/src/blocks/form/input/index.ts +1 -0
  92. package/src/blocks/form/input/input.tsx +49 -0
  93. package/src/blocks/form/select/component-info.ts +44 -0
  94. package/src/blocks/form/select/index.ts +1 -0
  95. package/src/blocks/form/select/select.tsx +54 -0
  96. package/src/blocks/form/submit-button/component-info.ts +27 -0
  97. package/src/blocks/form/submit-button/index.ts +1 -0
  98. package/src/blocks/form/submit-button/submit-button.tsx +34 -0
  99. package/src/blocks/fragment/component-info.ts +8 -0
  100. package/src/blocks/fragment/fragment.tsx +18 -0
  101. package/src/blocks/fragment/fragment.types.ts +5 -0
  102. package/src/blocks/fragment/index.ts +1 -0
  103. package/src/blocks/helpers.ts +43 -0
  104. package/src/blocks/image/component-info.ts +129 -0
  105. package/src/blocks/image/image.helpers.ts +47 -0
  106. package/src/blocks/image/image.tsx +65 -0
  107. package/src/blocks/image/image.types.ts +20 -0
  108. package/src/blocks/image/index.ts +1 -0
  109. package/src/blocks/img/component-info.ts +16 -0
  110. package/src/blocks/img/img.tsx +55 -0
  111. package/src/blocks/img/index.ts +1 -0
  112. package/src/blocks/raw-text/component-info.ts +11 -0
  113. package/src/blocks/raw-text/index.ts +1 -0
  114. package/src/blocks/raw-text/raw-text.tsx +1 -0
  115. package/src/blocks/section/component-info.ts +41 -0
  116. package/src/blocks/section/index.ts +1 -0
  117. package/src/blocks/section/section.tsx +39 -0
  118. package/src/blocks/section/section.types.ts +6 -0
  119. package/src/blocks/slot/component-info.ts +15 -0
  120. package/src/blocks/slot/index.ts +1 -0
  121. package/src/blocks/slot/slot.tsx +42 -0
  122. package/src/blocks/symbol/component-info.ts +35 -0
  123. package/src/blocks/symbol/index.ts +1 -0
  124. package/src/blocks/symbol/symbol.helpers.ts +47 -0
  125. package/src/blocks/symbol/symbol.tsx +100 -0
  126. package/src/blocks/symbol/symbol.types.ts +17 -0
  127. package/src/blocks/tabs/component-info.ts +139 -0
  128. package/src/blocks/tabs/index.ts +1 -0
  129. package/src/blocks/tabs/tabs.tsx +79 -0
  130. package/src/blocks/tabs/tabs.types.ts +13 -0
  131. package/src/blocks/text/component-info.ts +20 -0
  132. package/src/blocks/text/index.ts +1 -0
  133. package/src/blocks/text/text.tsx +105 -0
  134. package/src/blocks/text/text.types.ts +4 -0
  135. package/src/blocks/textarea/component-info.ts +38 -0
  136. package/src/blocks/textarea/index.ts +1 -0
  137. package/src/blocks/textarea/textarea.tsx +41 -0
  138. package/src/blocks/video/component-info.ts +83 -0
  139. package/src/blocks/video/index.ts +1 -0
  140. package/src/blocks/video/video.tsx +70 -0
  141. package/src/blocks/video/video.types.ts +21 -0
  142. package/src/components/block/animator.ts +220 -0
  143. package/src/components/block/block.helpers.ts +124 -0
  144. package/src/components/block/block.tsx +232 -0
  145. package/src/components/block/components/block-styles.tsx +136 -0
  146. package/src/components/block/components/block-wrapper.tsx +52 -0
  147. package/src/components/block/components/component-ref/component-ref.helpers.ts +55 -0
  148. package/src/components/block/components/component-ref/component-ref.tsx +66 -0
  149. package/src/components/block/components/interactive-element.tsx +53 -0
  150. package/src/components/block/components/repeated-block.tsx +37 -0
  151. package/src/components/block/types.ts +6 -0
  152. package/src/components/blocks/blocks-wrapper.tsx +93 -0
  153. package/src/components/blocks/blocks.tsx +57 -0
  154. package/src/components/blocks/blocks.types.ts +7 -0
  155. package/src/components/blocks/index.ts +1 -0
  156. package/src/components/content/components/enable-editor.tsx +472 -0
  157. package/src/components/content/components/styles.helpers.ts +101 -0
  158. package/src/components/content/components/styles.tsx +42 -0
  159. package/src/components/content/content.helpers.ts +40 -0
  160. package/src/components/content/content.tsx +150 -0
  161. package/src/components/content/content.types.ts +13 -0
  162. package/src/components/content/contentProps.types.ts +17 -0
  163. package/src/components/content/index.ts +1 -0
  164. package/src/components/content/wrap-component-ref.ts +6 -0
  165. package/src/components/content-variants/content-variants.tsx +146 -0
  166. package/src/components/content-variants/content-variants.types.ts +84 -0
  167. package/src/components/content-variants/helpers.ts +72 -0
  168. package/src/components/content-variants/index.ts +1 -0
  169. package/src/components/content-variants/inlined-fns.ts +22 -0
  170. package/src/components/dynamic-div.tsx +30 -0
  171. package/src/components/dynamic-renderer/dynamic-renderer.helpers.ts +7 -0
  172. package/src/components/dynamic-renderer/dynamic-renderer.tsx +47 -0
  173. package/src/components/error-boundary.tsx +38 -0
  174. package/src/components/inlined-script.tsx +10 -0
  175. package/src/components/inlined-styles.tsx +10 -0
  176. package/src/constants/builder-registered-components.ts +59 -0
  177. package/src/constants/device-sizes.ts +59 -0
  178. package/src/constants/extra-components.ts +1 -0
  179. package/src/constants/sdk-version.ts +1 -0
  180. package/src/constants/target.ts +3 -0
  181. package/src/context/builder.context.ts +15 -0
  182. package/src/context/components.context.ts +3 -0
  183. package/src/context/index.ts +1 -0
  184. package/src/context/types.ts +38 -0
  185. package/src/functions/apply-patch-with-mutation.ts +61 -0
  186. package/src/functions/camel-to-kebab-case.ts +1 -0
  187. package/src/functions/deopt.ts +6 -0
  188. package/src/functions/evaluate/browser-runtime/browser.ts +61 -0
  189. package/src/functions/evaluate/browser-runtime/index.ts +1 -0
  190. package/src/functions/evaluate/choose-eval.ts +23 -0
  191. package/src/functions/evaluate/edge-runtime/acorn-interpreter.ts +2891 -0
  192. package/src/functions/evaluate/edge-runtime/edge-runtime.ts +89 -0
  193. package/src/functions/evaluate/edge-runtime/index.ts +1 -0
  194. package/src/functions/evaluate/evaluate.ts +76 -0
  195. package/src/functions/evaluate/helpers.ts +56 -0
  196. package/src/functions/evaluate/index.ts +1 -0
  197. package/src/functions/evaluate/node-runtime/index.ts +1 -0
  198. package/src/functions/evaluate/node-runtime/init.ts +33 -0
  199. package/src/functions/evaluate/node-runtime/node-runtime.ts +176 -0
  200. package/src/functions/evaluate/node-runtime/safeDynamicRequire.ts +14 -0
  201. package/src/functions/evaluate/placeholder-runtime.ts +4 -0
  202. package/src/functions/evaluate/should-force-browser-runtime-in-node.ts +16 -0
  203. package/src/functions/event-handler-name.ts +4 -0
  204. package/src/functions/extract-text-styles.ts +24 -0
  205. package/src/functions/fast-clone.ts +4 -0
  206. package/src/functions/fetch-builder-props.ts +75 -0
  207. package/src/functions/get-block-actions-handler.ts +17 -0
  208. package/src/functions/get-block-actions.ts +35 -0
  209. package/src/functions/get-block-component-options.ts +7 -0
  210. package/src/functions/get-block-properties.ts +62 -0
  211. package/src/functions/get-builder-search-params/index.ts +33 -0
  212. package/src/functions/get-class-prop-name.ts +15 -0
  213. package/src/functions/get-content/generate-content-url.ts +88 -0
  214. package/src/functions/get-content/index.ts +99 -0
  215. package/src/functions/get-content/types.ts +157 -0
  216. package/src/functions/get-env.ts +5 -0
  217. package/src/functions/get-fetch.ts +11 -0
  218. package/src/functions/get-global-this.ts +16 -0
  219. package/src/functions/get-processed-block.ts +70 -0
  220. package/src/functions/get-style.ts +38 -0
  221. package/src/functions/get.ts +4 -0
  222. package/src/functions/is-browser.ts +3 -0
  223. package/src/functions/is-edge-runtime.ts +9 -0
  224. package/src/functions/is-editing.ts +8 -0
  225. package/src/functions/is-from-trusted-host.ts +11 -0
  226. package/src/functions/is-iframe.ts +4 -0
  227. package/src/functions/is-node-runtime.ts +8 -0
  228. package/src/functions/is-previewing.ts +16 -0
  229. package/src/functions/on-change.ts +29 -0
  230. package/src/functions/register-component.ts +30 -0
  231. package/src/functions/register.ts +44 -0
  232. package/src/functions/set-editor-settings.ts +15 -0
  233. package/src/functions/set.ts +14 -0
  234. package/src/functions/track/helpers.ts +51 -0
  235. package/src/functions/track/index.ts +131 -0
  236. package/src/functions/track/interaction.ts +63 -0
  237. package/src/functions/transform-block-properties.ts +33 -0
  238. package/src/functions/transform-block.ts +30 -0
  239. package/src/functions/transform-style-property.ts +296 -0
  240. package/src/helpers/ab-tests.ts +166 -0
  241. package/src/helpers/canTrack.ts +2 -0
  242. package/src/helpers/cookie.ts +109 -0
  243. package/src/helpers/css.ts +33 -0
  244. package/src/helpers/flatten.ts +41 -0
  245. package/src/helpers/localStorage.ts +36 -0
  246. package/src/helpers/logger.ts +7 -0
  247. package/src/helpers/nullable.ts +2 -0
  248. package/src/helpers/omit.ts +7 -0
  249. package/src/helpers/preview-lru-cache/get.ts +4 -0
  250. package/src/helpers/preview-lru-cache/helpers.ts +1 -0
  251. package/src/helpers/preview-lru-cache/init.ts +7 -0
  252. package/src/helpers/preview-lru-cache/set.ts +12 -0
  253. package/src/helpers/preview-lru-cache/types.ts +1 -0
  254. package/src/helpers/search/search.ts +18 -0
  255. package/src/helpers/sessionId.ts +37 -0
  256. package/src/helpers/subscribe-to-editor.ts +95 -0
  257. package/src/helpers/time.ts +2 -0
  258. package/src/helpers/url.ts +15 -0
  259. package/src/helpers/uuid.ts +17 -0
  260. package/src/helpers/visitorId.ts +37 -0
  261. package/src/index-helpers/blocks-exports.ts +16 -0
  262. package/src/index-helpers/top-of-file.ts +2 -0
  263. package/src/index.ts +15 -0
  264. package/src/scripts/init-editing.ts +119 -0
  265. package/src/server-index.ts +43 -0
  266. package/src/types/api-version.ts +2 -0
  267. package/src/types/builder-block.ts +89 -0
  268. package/src/types/builder-content.ts +47 -0
  269. package/src/types/builder-props.ts +12 -0
  270. package/src/types/can-track.ts +3 -0
  271. package/src/types/components.ts +119 -0
  272. package/src/types/deep-partial.ts +1 -0
  273. package/src/types/element.ts +57 -0
  274. package/src/types/enforced-partials.ts +19 -0
  275. package/src/types/input.ts +123 -0
  276. package/src/types/targets.ts +1 -0
  277. package/src/types/typescript.ts +9 -0
@@ -0,0 +1,4 @@
1
+ import type { BuilderContent } from '../../types/builder-content';
2
+ export function getPreviewContent(_searchParams: URLSearchParams): BuilderContent | undefined {
3
+ return undefined;
4
+ }
@@ -0,0 +1 @@
1
+ export {}
@@ -0,0 +1,7 @@
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
+
7
+ export function init() {}
@@ -0,0 +1,12 @@
1
+ import type { BuilderContent } from '../../types/builder-content';
2
+ export async function postPreviewContent({
3
+ key,
4
+ value
5
+ }: {
6
+ key: string;
7
+ value: BuilderContent;
8
+ }) {
9
+ return {
10
+ [key]: value
11
+ };
12
+ }
@@ -0,0 +1 @@
1
+ export {}
@@ -0,0 +1,18 @@
1
+ export type QueryObject = Record<string, string | string[]>;
2
+ export const convertSearchParamsToQueryObject = (searchParams: URLSearchParams): QueryObject => {
3
+ const options: Record<string, string> = {};
4
+ searchParams.forEach((value, key) => {
5
+ options[key] = value;
6
+ });
7
+ return options;
8
+ };
9
+ export const normalizeSearchParams = (searchParams: QueryObject | URLSearchParams): QueryObject => searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams;
10
+ export type Search = URLSearchParams | string | QueryObject;
11
+ export const getSearchString = (search: Search): string => {
12
+ if (typeof search === 'string') {
13
+ return search;
14
+ } else if (search instanceof URLSearchParams) {
15
+ return search.toString();
16
+ }
17
+ return new URLSearchParams((search as any)).toString();
18
+ }
@@ -0,0 +1,37 @@
1
+ import type { CanTrack } from '../types/can-track';
2
+ import { getCookie, setCookie } from './cookie';
3
+ import { checkIsDefined } from './nullable';
4
+ import { uuid } from './uuid';
5
+ const SESSION_LOCAL_STORAGE_KEY = 'builderSessionId';
6
+ export const getSessionId = async ({
7
+ canTrack
8
+ }: CanTrack): Promise<string | undefined> => {
9
+ if (!canTrack) {
10
+ return undefined;
11
+ }
12
+ const sessionId = await getCookie({
13
+ name: SESSION_LOCAL_STORAGE_KEY,
14
+ canTrack
15
+ });
16
+ if (checkIsDefined(sessionId)) {
17
+ return sessionId;
18
+ } else {
19
+ const newSessionId = createSessionId();
20
+ setSessionId({
21
+ id: newSessionId,
22
+ canTrack
23
+ });
24
+ return newSessionId;
25
+ }
26
+ };
27
+ export const createSessionId = () => uuid();
28
+ export const setSessionId = ({
29
+ id,
30
+ canTrack
31
+ }: {
32
+ id: string;
33
+ } & CanTrack) => setCookie({
34
+ name: SESSION_LOCAL_STORAGE_KEY,
35
+ value: id,
36
+ canTrack
37
+ })
@@ -0,0 +1,95 @@
1
+ import type { ContentProps } from '../components/content/content.types';
2
+ import { isBrowser } from '../functions/is-browser';
3
+ import { isFromTrustedHost } from '../functions/is-from-trusted-host';
4
+ import { setupBrowserForEditing } from '../scripts/init-editing';
5
+ import type { BuilderAnimation } from '../types/builder-block';
6
+ import type { BuilderContent } from '../types/builder-content';
7
+ import { logger } from './logger';
8
+ type ContentListener = Required<Pick<ContentProps, 'model' | 'trustedHosts'>> & {
9
+ callbacks: {
10
+ contentUpdate: (updatedContent: BuilderContent) => void;
11
+ animation: (updatedContent: BuilderAnimation) => void;
12
+ configureSdk: (updatedContent: any) => void;
13
+ };
14
+ };
15
+ export const createEditorListener = ({
16
+ model,
17
+ trustedHosts,
18
+ callbacks
19
+ }: ContentListener) => {
20
+ return (event: MessageEvent<any>): void => {
21
+ if (!isFromTrustedHost(trustedHosts, event)) {
22
+ return;
23
+ }
24
+ const {
25
+ data
26
+ } = event;
27
+ if (data) {
28
+ switch (data.type) {
29
+ case 'builder.configureSdk':
30
+ {
31
+ callbacks.configureSdk(data.data);
32
+ break;
33
+ }
34
+ case 'builder.triggerAnimation':
35
+ {
36
+ callbacks.animation(data.data);
37
+ break;
38
+ }
39
+ case 'builder.contentUpdate':
40
+ {
41
+ const messageContent = data.data;
42
+ const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
43
+ const contentData = messageContent.data;
44
+ if (key === model) {
45
+ callbacks.contentUpdate(contentData);
46
+ }
47
+ break;
48
+ }
49
+ }
50
+ }
51
+ };
52
+ };
53
+ type SubscribeToEditor = (
54
+ /**
55
+ * The Builder `model` to subscribe to
56
+ */
57
+ model: string,
58
+ /**
59
+ * The callback function to call when the content is updated.
60
+ */
61
+ callback: (updatedContent: BuilderContent) => void,
62
+ /**
63
+ * Extra options for the listener.
64
+ */
65
+ options?: {
66
+ /**
67
+ * List of hosts to allow editing content from.
68
+ */
69
+ trustedHosts?: string[] | undefined;
70
+ }) => () => void;
71
+
72
+ /**
73
+ * Subscribes to the Builder editor and listens to `content` updates of a certain `model`.
74
+ * Sends the updated `content` to the `callback` function.
75
+ */
76
+ export const subscribeToEditor: SubscribeToEditor = (model, callback, options) => {
77
+ if (!isBrowser) {
78
+ logger.warn('`subscribeToEditor` only works in the browser. It currently seems to be running on the server.');
79
+ return () => {};
80
+ }
81
+ setupBrowserForEditing();
82
+ const listener = createEditorListener({
83
+ callbacks: {
84
+ contentUpdate: callback,
85
+ animation: () => {},
86
+ configureSdk: () => {}
87
+ },
88
+ model,
89
+ trustedHosts: options?.trustedHosts
90
+ });
91
+ window.addEventListener('message', listener);
92
+ return () => {
93
+ window.removeEventListener('message', listener);
94
+ };
95
+ }
@@ -0,0 +1,2 @@
1
+ const MINUTE_TO_MILLESECONDS_MULTIPLIER = 60000;
2
+ export const getCurrentDatePlusMinutes = (minutes = 30) => new Date(Date.now() + minutes * MINUTE_TO_MILLESECONDS_MULTIPLIER)
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Only gets one level up from hostname
3
+ * wwww.example.com -> example.com
4
+ * www.example.co.uk -> example.co.uk
5
+ */
6
+ export const getTopLevelDomain = (host: string) => {
7
+ if (host === 'localhost' || host === '127.0.0.1') {
8
+ return host;
9
+ }
10
+ const parts = host.split('.');
11
+ if (parts.length > 2) {
12
+ return parts.slice(1).join('.');
13
+ }
14
+ return host;
15
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @credit https://stackoverflow.com/a/2117523
3
+ */
4
+ export function uuidv4() {
5
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
6
+ const r = Math.random() * 16 | 0,
7
+ v = c == 'x' ? r : r & 0x3 | 0x8;
8
+ return v.toString(16);
9
+ });
10
+ }
11
+
12
+ /**
13
+ * Slightly cleaner and smaller UUIDs
14
+ */
15
+ export function uuid() {
16
+ return uuidv4().replace(/-/g, '');
17
+ }
@@ -0,0 +1,37 @@
1
+ import type { CanTrack } from '../types/can-track';
2
+ import { getLocalStorageItem, setLocalStorageItem } from './localStorage';
3
+ import { checkIsDefined } from './nullable';
4
+ import { uuid } from './uuid';
5
+ const VISITOR_LOCAL_STORAGE_KEY = 'builderVisitorId';
6
+ export const getVisitorId = ({
7
+ canTrack
8
+ }: CanTrack): string | undefined => {
9
+ if (!canTrack) {
10
+ return undefined;
11
+ }
12
+ const visitorId = getLocalStorageItem({
13
+ key: VISITOR_LOCAL_STORAGE_KEY,
14
+ canTrack
15
+ });
16
+ if (checkIsDefined(visitorId)) {
17
+ return visitorId;
18
+ } else {
19
+ const newVisitorId = createVisitorId();
20
+ setVisitorId({
21
+ id: newVisitorId,
22
+ canTrack
23
+ });
24
+ return newVisitorId;
25
+ }
26
+ };
27
+ export const createVisitorId = () => uuid();
28
+ export const setVisitorId = ({
29
+ id,
30
+ canTrack
31
+ }: {
32
+ id: string;
33
+ } & CanTrack) => setLocalStorageItem({
34
+ key: VISITOR_LOCAL_STORAGE_KEY,
35
+ value: id,
36
+ canTrack
37
+ })
@@ -0,0 +1,16 @@
1
+ export { default as Button } from '../blocks/button/index';
2
+ export { default as Columns } from '../blocks/columns/index';
3
+ export { default as Fragment } from '../blocks/fragment/index';
4
+ export { default as Image } from '../blocks/image/index';
5
+ export { default as Section } from '../blocks/section/index';
6
+ export { default as Symbol } from '../blocks/symbol/index';
7
+ export { default as Text } from '../blocks/text/index';
8
+ // TO-DO: This file breaks due to this issue:
9
+ // https://github.com/expo/web-examples/issues/73
10
+ // For now, we do not import it elsewhere to avoid crashing Expo servers on web when importing the SDK.
11
+ // export { default as Video } from '../blocks/video/video';
12
+
13
+ import { default as Blocks } from '../components/blocks/index';
14
+ import { default as Content } from '../components/content-variants/index';
15
+
16
+ export { Blocks, Content };
@@ -0,0 +1,2 @@
1
+ // this is needed because react-native's URL polyfill is lacking all features we use, such as `URLSearchParams.set()`.
2
+ import 'react-native-url-polyfill/auto';
package/src/index.ts ADDED
@@ -0,0 +1,15 @@
1
+ // ignore prettier formatting for this file because the order of exports is meaningful
2
+ // prettier-ignore
3
+ export * from './index-helpers/top-of-file';
4
+
5
+ /**
6
+ * In the React SDK, this file is marked with `use client`.
7
+ */
8
+ // prettier-ignore
9
+ export * from './index-helpers/blocks-exports';
10
+
11
+ /**
12
+ * In the React SDK, this file is not marked with `use client`, to allow
13
+ * NextJS App Directory to use the SDK helper functions without issues.
14
+ */
15
+ export * from './server-index'
@@ -0,0 +1,119 @@
1
+ import { SDK_VERSION } from '../constants/sdk-version';
2
+ import { TARGET } from '../constants/target';
3
+ import { isBrowser } from '../functions/is-browser';
4
+ import { isFromTrustedHost } from '../functions/is-from-trusted-host';
5
+ import { register } from '../functions/register';
6
+ export const registerInsertMenu = () => {
7
+ register('insertMenu', {
8
+ name: '_default',
9
+ default: true,
10
+ items: [{
11
+ name: 'Box'
12
+ }, {
13
+ name: 'Text'
14
+ }, {
15
+ name: 'Image'
16
+ }, {
17
+ name: 'Columns'
18
+ }, ...(TARGET === 'reactNative' ? [] : [{
19
+ name: 'Core:Section'
20
+ }, {
21
+ name: 'Core:Button'
22
+ }, {
23
+ name: 'Embed'
24
+ }, {
25
+ name: 'Custom Code'
26
+ }])]
27
+ });
28
+ };
29
+ let isSetupForEditing = false;
30
+ export const setupBrowserForEditing = (options: {
31
+ enrich?: boolean;
32
+ includeRefs?: boolean;
33
+ locale?: string;
34
+ trustedHosts?: string[];
35
+ } = {}) => {
36
+ if (isSetupForEditing) {
37
+ return;
38
+ }
39
+ isSetupForEditing = true;
40
+ if (isBrowser()) {
41
+ window.parent?.postMessage({
42
+ type: 'builder.sdkInfo',
43
+ data: {
44
+ target: TARGET,
45
+ version: SDK_VERSION,
46
+ supportsPatchUpdates: false,
47
+ // Supports builder-model="..." attribute which is needed to
48
+ // scope our '+ add block' button styling
49
+ supportsAddBlockScoping: true,
50
+ supportsCustomBreakpoints: true
51
+ }
52
+ }, '*');
53
+ window.parent?.postMessage({
54
+ type: 'builder.updateContent',
55
+ data: {
56
+ options
57
+ }
58
+ }, '*');
59
+ window.addEventListener('message', (event: MessageEvent) => {
60
+ if (!isFromTrustedHost(options.trustedHosts, event)) {
61
+ return;
62
+ }
63
+ const {
64
+ data
65
+ } = event;
66
+ if (!data?.type) {
67
+ return;
68
+ }
69
+ switch (data.type) {
70
+ case 'builder.evaluate':
71
+ {
72
+ const text = data.data.text;
73
+ const args = data.data.arguments || [];
74
+ const id = data.data.id;
75
+ // tslint:disable-next-line:no-function-constructor-with-string-args
76
+ const fn = new Function(text);
77
+ let result: any;
78
+ let error: Error | null = null;
79
+ try {
80
+ // eslint-disable-next-line prefer-spread
81
+ result = fn.apply(null, args);
82
+ } catch (err) {
83
+ error = (err as Error);
84
+ }
85
+ if (error) {
86
+ window.parent?.postMessage({
87
+ type: 'builder.evaluateError',
88
+ data: {
89
+ id,
90
+ error: error.message
91
+ }
92
+ }, '*');
93
+ } else {
94
+ if (result && typeof result.then === 'function') {
95
+ (result as Promise<any>).then(finalResult => {
96
+ window.parent?.postMessage({
97
+ type: 'builder.evaluateResult',
98
+ data: {
99
+ id,
100
+ result: finalResult
101
+ }
102
+ }, '*');
103
+ }).catch(console.error);
104
+ } else {
105
+ window.parent?.postMessage({
106
+ type: 'builder.evaluateResult',
107
+ data: {
108
+ result,
109
+ id
110
+ }
111
+ }, '*');
112
+ }
113
+ }
114
+ break;
115
+ }
116
+ }
117
+ });
118
+ }
119
+ }
@@ -0,0 +1,43 @@
1
+ export * from './index-helpers/top-of-file';
2
+
3
+ /**
4
+ * Component Prop types
5
+ */
6
+ export type { ButtonProps } from './blocks/button/button.types';
7
+ export type { ColumnProps } from './blocks/columns/columns.types';
8
+ export type { FragmentProps } from './blocks/fragment/fragment.types';
9
+ export type { ImageProps } from './blocks/image/image.types';
10
+ export type { SectionProps } from './blocks/section/section.types';
11
+ export type { SymbolProps } from './blocks/symbol/symbol.types';
12
+ export type { TextProps } from './blocks/text/text.types';
13
+ export type { VideoProps } from './blocks/video/video.types';
14
+ export type { BlocksProps } from './components/blocks/blocks.types';
15
+ export type { ContentVariantsPrps as ContentProps } from './components/content-variants/content-variants.types';
16
+
17
+ /**
18
+ * General Builder types
19
+ */
20
+ export type { RegisteredComponent } from './context/types';
21
+ export type { BuilderBlock } from './types/builder-block';
22
+ export type { BuilderContent } from './types/builder-content';
23
+ export type { ComponentInfo } from './types/components';
24
+
25
+ /**
26
+ * Helper functions
27
+ */
28
+ export { isEditing } from './functions/is-editing';
29
+ export { isPreviewing } from './functions/is-previewing';
30
+ export { createRegisterComponentMessage } from './functions/register-component';
31
+ export { register } from './functions/register';
32
+ export type { InsertMenuConfig, InsertMenuItem } from './functions/register';
33
+ export { setEditorSettings } from './functions/set-editor-settings';
34
+ export type { Settings } from './functions/set-editor-settings';
35
+ export { getBuilderSearchParams } from './functions/get-builder-search-params/index';
36
+ export { track } from './functions/track/index';
37
+ export { subscribeToEditor } from './helpers/subscribe-to-editor';
38
+
39
+ /**
40
+ * Content fetching
41
+ */
42
+ export { fetchBuilderProps } from './functions/fetch-builder-props';
43
+ export { _processContentResult, fetchEntries, fetchOneEntry } from './functions/get-content/index'
@@ -0,0 +1,2 @@
1
+ export type ApiVersion = 'v3';
2
+ export const DEFAULT_API_VERSION: ApiVersion = 'v3'
@@ -0,0 +1,89 @@
1
+ type JSONValue = string | number | boolean | JSONObject | JSONArray;
2
+ interface JSONObject {
3
+ [x: string]: JSONValue;
4
+ }
5
+ interface JSONArray extends Array<JSONValue> {}
6
+ export interface AnimationStep {
7
+ // First one is always start state
8
+ // isStartState?: boolean;
9
+ styles: {
10
+ [key: string]: string;
11
+ };
12
+ delay?: number;
13
+ }
14
+ export interface BuilderAnimation {
15
+ elementId: string;
16
+ trigger: string;
17
+ steps: AnimationStep[];
18
+ duration: number;
19
+ delay?: number;
20
+ easing?: string;
21
+ // TODO: deprecate - only here because of an API bug
22
+ id?: string;
23
+ // only apply in scrollInView
24
+ repeat?: boolean;
25
+ // only apply in scrollInView, number from -1 to 1
26
+ thresholdPercent?: number;
27
+ }
28
+ /** @todo typedoc this */
29
+ export interface BuilderBlock {
30
+ '@type': '@builder.io/sdk:Element';
31
+ '@version'?: number;
32
+ id?: string;
33
+ tagName?: string;
34
+ layerName?: string;
35
+ groupLocked?: boolean;
36
+ layerLocked?: boolean;
37
+ /** @todo make alias for properties.class */
38
+ class?: string;
39
+ children?: BuilderBlock[];
40
+ responsiveStyles?: {
41
+ large?: Partial<CSSStyleDeclaration>;
42
+ medium?: Partial<CSSStyleDeclaration>;
43
+ small?: Partial<CSSStyleDeclaration>;
44
+ /** @deprecated */
45
+ xsmall?: Partial<CSSStyleDeclaration>;
46
+ };
47
+ component?: {
48
+ name: string;
49
+ options?: any;
50
+ tag?: string;
51
+ };
52
+ bindings?: {
53
+ [key: string]: string;
54
+ };
55
+ meta?: {
56
+ [key: string]: JSONValue;
57
+ };
58
+ actions?: {
59
+ [key: string]: string;
60
+ };
61
+ properties?: {
62
+ [key: string]: string;
63
+ };
64
+ code?: {
65
+ bindings?: {
66
+ [key: string]: string;
67
+ };
68
+ actions?: {
69
+ [key: string]: string;
70
+ };
71
+ };
72
+ repeat?: {
73
+ collection: string;
74
+ itemName?: string;
75
+ } | null;
76
+ animations?: BuilderAnimation[];
77
+ style?: Partial<CSSStyleDeclaration>;
78
+ href?: string;
79
+
80
+ /**
81
+ * generated by the "Hide If" binding
82
+ */
83
+ hide?: boolean;
84
+
85
+ /**
86
+ * generated by the "Show If" binding
87
+ */
88
+ show?: boolean;
89
+ }
@@ -0,0 +1,47 @@
1
+ import type { BuilderBlock } from './builder-block';
2
+ import type { Input } from './input';
3
+ import type { Nullable } from './typescript';
4
+ export interface Breakpoints {
5
+ small: number;
6
+ medium: number;
7
+ }
8
+ export interface BuilderContentVariation {
9
+ data?: {
10
+ title?: string;
11
+ blocks?: BuilderBlock[];
12
+ inputs?: Input[];
13
+ state?: {
14
+ [key: string]: any;
15
+ };
16
+ jsCode?: string;
17
+ tsCode?: string;
18
+ httpRequests?: {
19
+ [key: string]: string;
20
+ };
21
+ [key: string]: any;
22
+ };
23
+ name?: string;
24
+ testRatio?: number;
25
+ id?: string;
26
+ meta?: {
27
+ breakpoints?: Nullable<Breakpoints>;
28
+ [key: string]: any;
29
+ };
30
+ }
31
+
32
+ // TODO: separate full and partial versions
33
+ export interface BuilderContent extends BuilderContentVariation {
34
+ // TODO: query
35
+ '@version'?: number;
36
+ published?: 'published' | 'draft' | 'archived';
37
+ modelId?: string;
38
+ priority?: number;
39
+ lastUpdated?: number;
40
+ startDate?: number;
41
+ endDate?: number;
42
+ variations?: {
43
+ [id: string]: BuilderContentVariation;
44
+ };
45
+ testVariationId?: string;
46
+ testVariationName?: string;
47
+ }
@@ -0,0 +1,12 @@
1
+ import type { BuilderContextInterface, RegisteredComponents } from '../context/types';
2
+ import type { BuilderBlock } from './builder-block';
3
+ export type BuilderDataProps = {
4
+ builderBlock: BuilderBlock;
5
+ builderContext: BuilderContextInterface;
6
+ };
7
+ export type BuilderComponentsProp = {
8
+ builderComponents: RegisteredComponents;
9
+ };
10
+ export type BuilderLinkComponentProp = {
11
+ builderLinkComponent?: any;
12
+ }
@@ -0,0 +1,3 @@
1
+ export type CanTrack = {
2
+ canTrack: boolean;
3
+ }