@builder.io/sdk-react-nextjs 0.4.5

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 (244) hide show
  1. package/README.md +80 -0
  2. package/dist/blocks/button/button.d.ts +11 -0
  3. package/dist/blocks/button/button.js +12 -0
  4. package/dist/blocks/button/component-info.d.ts +2 -0
  5. package/dist/blocks/button/component-info.js +34 -0
  6. package/dist/blocks/columns/columns.d.ts +16 -0
  7. package/dist/blocks/columns/columns.js +119 -0
  8. package/dist/blocks/columns/component-info.d.ts +2 -0
  9. package/dist/blocks/columns/component-info.js +219 -0
  10. package/dist/blocks/custom-code/component-info.d.ts +2 -0
  11. package/dist/blocks/custom-code/component-info.js +23 -0
  12. package/dist/blocks/custom-code/custom-code.d.ts +6 -0
  13. package/dist/blocks/custom-code/custom-code.js +51 -0
  14. package/dist/blocks/embed/component-info.d.ts +2 -0
  15. package/dist/blocks/embed/component-info.js +38 -0
  16. package/dist/blocks/embed/embed.d.ts +5 -0
  17. package/dist/blocks/embed/embed.js +42 -0
  18. package/dist/blocks/embed/helpers.d.ts +1 -0
  19. package/dist/blocks/embed/helpers.js +2 -0
  20. package/dist/blocks/fragment/component-info.d.ts +2 -0
  21. package/dist/blocks/fragment/component-info.js +7 -0
  22. package/dist/blocks/fragment/fragment.d.ts +7 -0
  23. package/dist/blocks/fragment/fragment.js +6 -0
  24. package/dist/blocks/helpers.d.ts +13 -0
  25. package/dist/blocks/helpers.js +40 -0
  26. package/dist/blocks/image/component-info.d.ts +2 -0
  27. package/dist/blocks/image/component-info.js +121 -0
  28. package/dist/blocks/image/image.d.ts +21 -0
  29. package/dist/blocks/image/image.helpers.d.ts +1 -0
  30. package/dist/blocks/image/image.helpers.js +47 -0
  31. package/dist/blocks/image/image.js +81 -0
  32. package/dist/blocks/img/component-info.d.ts +2 -0
  33. package/dist/blocks/img/component-info.js +15 -0
  34. package/dist/blocks/img/img.d.ts +13 -0
  35. package/dist/blocks/img/img.js +10 -0
  36. package/dist/blocks/section/component-info.d.ts +2 -0
  37. package/dist/blocks/section/component-info.js +40 -0
  38. package/dist/blocks/section/section.d.ts +11 -0
  39. package/dist/blocks/section/section.js +17 -0
  40. package/dist/blocks/symbol/component-info.d.ts +2 -0
  41. package/dist/blocks/symbol/component-info.js +34 -0
  42. package/dist/blocks/symbol/symbol.d.ts +25 -0
  43. package/dist/blocks/symbol/symbol.helpers.d.ts +14 -0
  44. package/dist/blocks/symbol/symbol.helpers.js +30 -0
  45. package/dist/blocks/symbol/symbol.js +29 -0
  46. package/dist/blocks/text/component-info.d.ts +2 -0
  47. package/dist/blocks/text/component-info.js +19 -0
  48. package/dist/blocks/text/text.d.ts +5 -0
  49. package/dist/blocks/text/text.js +7 -0
  50. package/dist/blocks/video/component-info.d.ts +2 -0
  51. package/dist/blocks/video/component-info.js +82 -0
  52. package/dist/blocks/video/video.d.ts +19 -0
  53. package/dist/blocks/video/video.js +47 -0
  54. package/dist/components/block/block.d.ts +9 -0
  55. package/dist/components/block/block.helpers.d.ts +13 -0
  56. package/dist/components/block/block.helpers.js +67 -0
  57. package/dist/components/block/block.js +92 -0
  58. package/dist/components/block/components/block-styles.d.ts +8 -0
  59. package/dist/components/block/components/block-styles.js +65 -0
  60. package/dist/components/block/components/block-wrapper.d.ts +17 -0
  61. package/dist/components/block/components/block-wrapper.js +36 -0
  62. package/dist/components/block/components/component-ref/component-ref.d.ts +3 -0
  63. package/dist/components/block/components/component-ref/component-ref.helpers.d.ts +28 -0
  64. package/dist/components/block/components/component-ref/component-ref.helpers.js +21 -0
  65. package/dist/components/block/components/component-ref/component-ref.js +21 -0
  66. package/dist/components/block/components/interactive-element.d.ts +11 -0
  67. package/dist/components/block/components/interactive-element.js +20 -0
  68. package/dist/components/block/components/repeated-block.d.ts +9 -0
  69. package/dist/components/block/components/repeated-block.js +7 -0
  70. package/dist/components/block/types.d.ts +6 -0
  71. package/dist/components/block/types.js +1 -0
  72. package/dist/components/blocks/blocks-wrapper.d.ts +10 -0
  73. package/dist/components/blocks/blocks-wrapper.js +38 -0
  74. package/dist/components/blocks/blocks.d.ts +8 -0
  75. package/dist/components/blocks/blocks.js +10 -0
  76. package/dist/components/content/components/enable-editor.d.ts +9 -0
  77. package/dist/components/content/components/enable-editor.js +249 -0
  78. package/dist/components/content/components/styles.d.ts +8 -0
  79. package/dist/components/content/components/styles.helpers.d.ts +15 -0
  80. package/dist/components/content/components/styles.helpers.js +56 -0
  81. package/dist/components/content/components/styles.js +30 -0
  82. package/dist/components/content/content.d.ts +3 -0
  83. package/dist/components/content/content.helpers.d.ts +7 -0
  84. package/dist/components/content/content.helpers.js +25 -0
  85. package/dist/components/content/content.js +72 -0
  86. package/dist/components/content/content.types.d.ts +24 -0
  87. package/dist/components/content/content.types.js +1 -0
  88. package/dist/components/content/wrap-component-ref.d.ts +6 -0
  89. package/dist/components/content/wrap-component-ref.js +6 -0
  90. package/dist/components/content-variants/content-variants.d.ts +9 -0
  91. package/dist/components/content-variants/content-variants.js +39 -0
  92. package/dist/components/content-variants/content-variants.types.d.ts +20 -0
  93. package/dist/components/content-variants/content-variants.types.js +1 -0
  94. package/dist/components/content-variants/helpers.d.ts +41 -0
  95. package/dist/components/content-variants/helpers.js +188 -0
  96. package/dist/components/inlined-script.d.ts +6 -0
  97. package/dist/components/inlined-script.js +5 -0
  98. package/dist/components/inlined-styles.d.ts +6 -0
  99. package/dist/components/inlined-styles.js +5 -0
  100. package/dist/constants/builder-registered-components.d.ts +6 -0
  101. package/dist/constants/builder-registered-components.js +60 -0
  102. package/dist/constants/device-sizes.d.ts +13 -0
  103. package/dist/constants/device-sizes.js +45 -0
  104. package/dist/constants/sdk-version.d.ts +1 -0
  105. package/dist/constants/sdk-version.js +1 -0
  106. package/dist/constants/target.d.ts +2 -0
  107. package/dist/constants/target.js +2 -0
  108. package/dist/context/builder.context.d.ts +3 -0
  109. package/dist/context/builder.context.js +12 -0
  110. package/dist/context/types.d.ts +35 -0
  111. package/dist/context/types.js +1 -0
  112. package/dist/functions/apply-patch-with-mutation.d.ts +10 -0
  113. package/dist/functions/apply-patch-with-mutation.js +54 -0
  114. package/dist/functions/camel-to-kebab-case.d.ts +1 -0
  115. package/dist/functions/camel-to-kebab-case.js +1 -0
  116. package/dist/functions/evaluate.d.ts +7 -0
  117. package/dist/functions/evaluate.js +46 -0
  118. package/dist/functions/event-handler-name.d.ts +1 -0
  119. package/dist/functions/event-handler-name.js +4 -0
  120. package/dist/functions/extract-text-styles.d.ts +4 -0
  121. package/dist/functions/extract-text-styles.js +21 -0
  122. package/dist/functions/fast-clone.d.ts +4 -0
  123. package/dist/functions/fast-clone.js +4 -0
  124. package/dist/functions/get-block-actions-handler.d.ts +8 -0
  125. package/dist/functions/get-block-actions-handler.js +10 -0
  126. package/dist/functions/get-block-actions.d.ts +10 -0
  127. package/dist/functions/get-block-actions.js +28 -0
  128. package/dist/functions/get-block-component-options.d.ts +2 -0
  129. package/dist/functions/get-block-component-options.js +8 -0
  130. package/dist/functions/get-block-properties.d.ts +6 -0
  131. package/dist/functions/get-block-properties.js +71 -0
  132. package/dist/functions/get-builder-search-params/index.d.ts +12 -0
  133. package/dist/functions/get-builder-search-params/index.js +38 -0
  134. package/dist/functions/get-content/generate-content-url.d.ts +2 -0
  135. package/dist/functions/get-content/generate-content-url.js +32 -0
  136. package/dist/functions/get-content/index.d.ts +16 -0
  137. package/dist/functions/get-content/index.js +82 -0
  138. package/dist/functions/get-content/processCookies.d.ts +2 -0
  139. package/dist/functions/get-content/processCookies.js +35 -0
  140. package/dist/functions/get-content/types.d.ts +51 -0
  141. package/dist/functions/get-content/types.js +1 -0
  142. package/dist/functions/get-fetch.d.ts +1 -0
  143. package/dist/functions/get-fetch.js +11 -0
  144. package/dist/functions/get-global-this.d.ts +4 -0
  145. package/dist/functions/get-global-this.js +15 -0
  146. package/dist/functions/get-processed-block.d.ts +10 -0
  147. package/dist/functions/get-processed-block.js +43 -0
  148. package/dist/functions/get-react-native-block-styles.d.ts +7 -0
  149. package/dist/functions/get-react-native-block-styles.js +16 -0
  150. package/dist/functions/is-browser.d.ts +1 -0
  151. package/dist/functions/is-browser.js +3 -0
  152. package/dist/functions/is-editing.d.ts +1 -0
  153. package/dist/functions/is-editing.js +5 -0
  154. package/dist/functions/is-iframe.d.ts +1 -0
  155. package/dist/functions/is-iframe.js +4 -0
  156. package/dist/functions/is-previewing.d.ts +1 -0
  157. package/dist/functions/is-previewing.js +11 -0
  158. package/dist/functions/register-component.d.ts +15 -0
  159. package/dist/functions/register-component.js +34 -0
  160. package/dist/functions/register.d.ts +16 -0
  161. package/dist/functions/register.js +27 -0
  162. package/dist/functions/sanitize-react-native-block-styles.d.ts +3 -0
  163. package/dist/functions/sanitize-react-native-block-styles.js +58 -0
  164. package/dist/functions/set-editor-settings.d.ts +4 -0
  165. package/dist/functions/set-editor-settings.js +12 -0
  166. package/dist/functions/set.d.ts +7 -0
  167. package/dist/functions/set.js +14 -0
  168. package/dist/functions/track/helpers.d.ts +5 -0
  169. package/dist/functions/track/helpers.js +50 -0
  170. package/dist/functions/track/index.d.ts +51 -0
  171. package/dist/functions/track/index.js +69 -0
  172. package/dist/functions/track/interaction.d.ts +13 -0
  173. package/dist/functions/track/interaction.js +53 -0
  174. package/dist/functions/transform-block-properties.d.ts +1 -0
  175. package/dist/functions/transform-block-properties.js +5 -0
  176. package/dist/functions/transform-block.d.ts +2 -0
  177. package/dist/functions/transform-block.js +3 -0
  178. package/dist/helpers/ab-tests.d.ts +9 -0
  179. package/dist/helpers/ab-tests.js +116 -0
  180. package/dist/helpers/canTrack.d.ts +1 -0
  181. package/dist/helpers/canTrack.js +2 -0
  182. package/dist/helpers/cookie.d.ts +19 -0
  183. package/dist/helpers/cookie.js +54 -0
  184. package/dist/helpers/css.d.ts +7 -0
  185. package/dist/helpers/css.js +27 -0
  186. package/dist/helpers/flatten.d.ts +6 -0
  187. package/dist/helpers/flatten.js +17 -0
  188. package/dist/helpers/localStorage.d.ts +9 -0
  189. package/dist/helpers/localStorage.js +24 -0
  190. package/dist/helpers/logger.d.ts +6 -0
  191. package/dist/helpers/logger.js +7 -0
  192. package/dist/helpers/nullable.d.ts +2 -0
  193. package/dist/helpers/nullable.js +1 -0
  194. package/dist/helpers/preview-lru-cache/get.d.ts +1 -0
  195. package/dist/helpers/preview-lru-cache/get.js +7 -0
  196. package/dist/helpers/preview-lru-cache/helpers.d.ts +1 -0
  197. package/dist/helpers/preview-lru-cache/helpers.js +9 -0
  198. package/dist/helpers/preview-lru-cache/init.d.ts +1 -0
  199. package/dist/helpers/preview-lru-cache/init.js +15 -0
  200. package/dist/helpers/preview-lru-cache/set.d.ts +7 -0
  201. package/dist/helpers/preview-lru-cache/set.js +9 -0
  202. package/dist/helpers/preview-lru-cache/types.d.ts +12 -0
  203. package/dist/helpers/preview-lru-cache/types.js +1 -0
  204. package/dist/helpers/sessionId.d.ts +6 -0
  205. package/dist/helpers/sessionId.js +30 -0
  206. package/dist/helpers/url.d.ts +6 -0
  207. package/dist/helpers/url.js +15 -0
  208. package/dist/helpers/uuid.d.ts +8 -0
  209. package/dist/helpers/uuid.js +15 -0
  210. package/dist/helpers/visitorId.d.ts +6 -0
  211. package/dist/helpers/visitorId.js +30 -0
  212. package/dist/index-helpers/blocks-exports.d.ts +10 -0
  213. package/dist/index-helpers/blocks-exports.js +10 -0
  214. package/dist/index-helpers/top-of-file.d.ts +1 -0
  215. package/dist/index-helpers/top-of-file.js +4 -0
  216. package/dist/index.d.ts +15 -0
  217. package/dist/index.js +10 -0
  218. package/dist/scripts/init-editing.d.ts +6 -0
  219. package/dist/scripts/init-editing.js +109 -0
  220. package/dist/types/api-version.d.ts +2 -0
  221. package/dist/types/api-version.js +1 -0
  222. package/dist/types/builder-block.d.ts +66 -0
  223. package/dist/types/builder-block.js +1 -0
  224. package/dist/types/builder-content.d.ts +44 -0
  225. package/dist/types/builder-content.js +1 -0
  226. package/dist/types/builder-props.d.ts +9 -0
  227. package/dist/types/builder-props.js +1 -0
  228. package/dist/types/can-track.d.ts +3 -0
  229. package/dist/types/can-track.js +1 -0
  230. package/dist/types/components.d.ts +111 -0
  231. package/dist/types/components.js +1 -0
  232. package/dist/types/deep-partial.d.ts +3 -0
  233. package/dist/types/deep-partial.js +1 -0
  234. package/dist/types/element.d.ts +59 -0
  235. package/dist/types/element.js +1 -0
  236. package/dist/types/enforced-partials.d.ts +21 -0
  237. package/dist/types/enforced-partials.js +1 -0
  238. package/dist/types/input.d.ts +121 -0
  239. package/dist/types/input.js +1 -0
  240. package/dist/types/targets.d.ts +1 -0
  241. package/dist/types/targets.js +1 -0
  242. package/dist/types/typescript.d.ts +11 -0
  243. package/dist/types/typescript.js +1 -0
  244. package/package.json +27 -0
@@ -0,0 +1,39 @@
1
+ import * as React from "react";
2
+ import { checkShouldRunVariants, getScriptString, getVariants, getVariantsScriptString, } from "./helpers.js";
3
+ import ContentComponent from "../content/content.js";
4
+ import { getDefaultCanTrack } from "../../helpers/canTrack.js";
5
+ import InlinedStyles from "../inlined-styles.js";
6
+ import { handleABTestingSync } from "../../helpers/ab-tests.js";
7
+ import InlinedScript from "../inlined-script.js";
8
+ import { TARGET } from "../../constants/target.js";
9
+ function ContentVariants(props) {
10
+ const shouldRenderVariants = checkShouldRunVariants({
11
+ canTrack: getDefaultCanTrack(props.canTrack),
12
+ content: props.content,
13
+ });
14
+ const variantScriptStr = function variantScriptStr() {
15
+ return getVariantsScriptString(getVariants(props.content).map((value) => ({
16
+ id: value.testVariationId,
17
+ testRatio: value.testRatio,
18
+ })), props.content?.id || "");
19
+ };
20
+ const hideVariantsStyleString = function hideVariantsStyleString() {
21
+ return getVariants(props.content)
22
+ .map((value) => `.variant-${value.testVariationId} { display: none; } `)
23
+ .join("");
24
+ };
25
+ return (React.createElement(React.Fragment, null,
26
+ !props.__isNestedRender && TARGET !== "reactNative" ? (React.createElement(React.Fragment, null,
27
+ React.createElement(InlinedScript, { scriptStr: getScriptString() }))) : null,
28
+ shouldRenderVariants ? (React.createElement(React.Fragment, null,
29
+ React.createElement(InlinedStyles, { id: `variants-styles-${props.content?.id}`, styles: hideVariantsStyleString() }),
30
+ React.createElement(InlinedScript, { scriptStr: variantScriptStr() }),
31
+ getVariants(props.content)?.map((variant) => (React.createElement(ContentComponent, { key: variant.testVariationId, content: variant, showContent: false, classNameProp: undefined, model: props.model, data: props.data, context: props.context, apiKey: props.apiKey, apiVersion: props.apiVersion, customComponents: props.customComponents, canTrack: props.canTrack, locale: props.locale, includeRefs: props.includeRefs, enrich: props.enrich, isSsrAbTest: shouldRenderVariants }))))) : null,
32
+ React.createElement(ContentComponent, { content: shouldRenderVariants
33
+ ? props.content
34
+ : handleABTestingSync({
35
+ item: props.content,
36
+ canTrack: getDefaultCanTrack(props.canTrack),
37
+ }), classNameProp: `variant-${props.content?.id}`, showContent: true, model: props.model, data: props.data, context: props.context, apiKey: props.apiKey, apiVersion: props.apiVersion, customComponents: props.customComponents, canTrack: props.canTrack, locale: props.locale, includeRefs: props.includeRefs, enrich: props.enrich, isSsrAbTest: shouldRenderVariants })));
38
+ }
39
+ export default ContentVariants;
@@ -0,0 +1,20 @@
1
+ import type { BuilderRenderContext, RegisteredComponent } from '../../context/types.js';
2
+ import type { ApiVersion } from '../../types/api-version.js';
3
+ import type { BuilderContent } from '../../types/builder-content.js';
4
+ import type { Nullable } from '../../types/typescript.js';
5
+ export interface ContentVariantsProps {
6
+ content?: Nullable<BuilderContent>;
7
+ model?: string;
8
+ data?: {
9
+ [key: string]: any;
10
+ };
11
+ context?: BuilderRenderContext;
12
+ apiKey: string;
13
+ apiVersion?: ApiVersion;
14
+ customComponents?: RegisteredComponent[];
15
+ canTrack?: boolean;
16
+ locale?: string;
17
+ /** @deprecated use `enrich` instead **/
18
+ includeRefs?: boolean;
19
+ enrich?: boolean;
20
+ }
@@ -0,0 +1,41 @@
1
+ import type { Nullable } from '../../helpers/nullable.js';
2
+ import type { BuilderContent } from '../../types/builder-content.js';
3
+ export declare const getVariants: (content: Nullable<BuilderContent>) => {
4
+ testVariationId: string;
5
+ id: string;
6
+ data?: {
7
+ [key: string]: any;
8
+ title?: string;
9
+ blocks?: import("../../types/builder-block.js").BuilderBlock[];
10
+ inputs?: import("../../types/input.js").Input[];
11
+ state?: {
12
+ [key: string]: any;
13
+ };
14
+ jsCode?: string;
15
+ tsCode?: string;
16
+ httpRequests?: {
17
+ [key: string]: string;
18
+ };
19
+ };
20
+ name?: string;
21
+ testRatio?: number;
22
+ meta?: {
23
+ [key: string]: any;
24
+ breakpoints?: import("../../types/builder-content.js").Breakpoints;
25
+ };
26
+ }[];
27
+ export declare const checkShouldRunVariants: ({ canTrack, content }: {
28
+ canTrack: Nullable<boolean>;
29
+ content: Nullable<BuilderContent>;
30
+ }) => boolean;
31
+ type VariantData = {
32
+ id: string;
33
+ testRatio?: number;
34
+ };
35
+ export declare const getScriptString: () => string;
36
+ export declare const getVariantsScriptString: (variants: VariantData[], contentId: string) => string;
37
+ export declare const getRenderContentScriptString: ({ contentId, variationId }: {
38
+ variationId: string;
39
+ contentId: string;
40
+ }) => string;
41
+ export {};
@@ -0,0 +1,188 @@
1
+ import { TARGET } from '../../constants/target.js';
2
+ import { isBrowser } from '../../functions/is-browser.js';
3
+ export const getVariants = (content) => Object.values(content?.variations || {}).map(variant => ({ ...variant,
4
+ testVariationId: variant.id,
5
+ id: content?.id
6
+ }));
7
+ export const checkShouldRunVariants = ({ canTrack, content }) => {
8
+ const hasVariants = getVariants(content).length > 0;
9
+ /**
10
+ * We cannot SSR in React-Native.
11
+ */
12
+ if (TARGET === 'reactNative')
13
+ return false;
14
+ if (!hasVariants)
15
+ return false;
16
+ if (!canTrack)
17
+ return false;
18
+ /**
19
+ * For Vue 2 and Vue 3, we need to (initially) render the variants. This is to avoid hydration mismatch errors.
20
+ * Unlike React, Vue's hydration checks are shallow and do not check the attributes/contents of each element, so we
21
+ * are able to modify the `hidden` HTML attributes and `display` CSS properties without causing a hydration mismatch error.
22
+ *
23
+ * NOTE: after the app is hydrated, we strip the variants from the DOM (on mount) to reduce the amount of HTML in the DOM.
24
+ */
25
+ if (TARGET === 'vue2' || TARGET === 'vue3')
26
+ return true;
27
+ if (isBrowser())
28
+ return false;
29
+ return true;
30
+ };
31
+ /**
32
+ * NOTE: when this function is stringified, single-line comments can cause weird issues when compiled by Sveltekit.
33
+ * Make sure to write multi-line comments only.
34
+ */
35
+ function bldrAbTest(contentId, variants, isHydrationTarget) {
36
+ function getAndSetVariantId() {
37
+ function setCookie(name, value, days) {
38
+ let expires = '';
39
+ if (days) {
40
+ const date = new Date();
41
+ date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
42
+ expires = '; expires=' + date.toUTCString();
43
+ }
44
+ document.cookie = name + '=' + (value || '') + expires + '; path=/' + '; Secure; SameSite=None';
45
+ }
46
+ function getCookie(name) {
47
+ const nameEQ = name + '=';
48
+ const ca = document.cookie.split(';');
49
+ for (let i = 0; i < ca.length; i++) {
50
+ let c = ca[i];
51
+ while (c.charAt(0) === ' ')
52
+ c = c.substring(1, c.length);
53
+ if (c.indexOf(nameEQ) === 0)
54
+ return c.substring(nameEQ.length, c.length);
55
+ }
56
+ return null;
57
+ }
58
+ const cookieName = `builder.tests.${contentId}`;
59
+ const variantInCookie = getCookie(cookieName);
60
+ const availableIDs = variants.map(vr => vr.id).concat(contentId);
61
+ /**
62
+ * cookie already exists
63
+ */
64
+ if (variantInCookie && availableIDs.includes(variantInCookie)) {
65
+ return variantInCookie;
66
+ }
67
+ /**
68
+ * no cookie exists, find variant
69
+ */
70
+ let n = 0;
71
+ const random = Math.random();
72
+ for (let i = 0; i < variants.length; i++) {
73
+ const variant = variants[i];
74
+ const testRatio = variant.testRatio;
75
+ n += testRatio;
76
+ if (random < n) {
77
+ setCookie(cookieName, variant.id);
78
+ return variant.id;
79
+ }
80
+ }
81
+ /**
82
+ * no variant found, assign default content
83
+ */
84
+ setCookie(cookieName, contentId);
85
+ return contentId;
86
+ }
87
+ const winningVariantId = getAndSetVariantId();
88
+ const styleEl = document.currentScript?.previousElementSibling;
89
+ /**
90
+ * For React to work, we need hydration to match SSR, so we completely remove this node and the styles tag.
91
+ */
92
+ if (isHydrationTarget) {
93
+ styleEl.remove();
94
+ const thisScriptEl = document.currentScript;
95
+ thisScriptEl?.remove();
96
+ }
97
+ else {
98
+ /* update styles to hide all variants except the winning variant */
99
+ const newStyleStr = variants.concat({
100
+ id: contentId
101
+ }).filter(variant => variant.id !== winningVariantId).map(value => {
102
+ return `.variant-${value.id} { display: none; }
103
+ `;
104
+ }).join('');
105
+ styleEl.innerHTML = newStyleStr;
106
+ }
107
+ }
108
+ /**
109
+ * NOTE: when this function is stringified, single-line comments can cause weird issues when compiled by Sveltekit.
110
+ * Make sure to write multi-line comments only.
111
+ */
112
+ function bldrCntntScrpt(variantContentId, defaultContentId, isHydrationTarget) {
113
+ if (!navigator.cookieEnabled) {
114
+ return;
115
+ }
116
+ function getCookie(name) {
117
+ const nameEQ = name + '=';
118
+ const ca = document.cookie.split(';');
119
+ for (let i = 0; i < ca.length; i++) {
120
+ let c = ca[i];
121
+ while (c.charAt(0) === ' ')
122
+ c = c.substring(1, c.length);
123
+ if (c.indexOf(nameEQ) === 0)
124
+ return c.substring(nameEQ.length, c.length);
125
+ }
126
+ return null;
127
+ }
128
+ const cookieName = `builder.tests.${defaultContentId}`;
129
+ const variantId = getCookie(cookieName);
130
+ const parentDiv = document.currentScript?.parentElement;
131
+ const variantIsDefaultContent = variantContentId === defaultContentId;
132
+ if (variantId === variantContentId) {
133
+ if (variantIsDefaultContent) {
134
+ /** the default content is already visible, no need to do anything */
135
+ return;
136
+ }
137
+ /** this is the winning variant and not already visible: remove `hidden` and `aria-hidden` attr */
138
+ parentDiv?.removeAttribute('hidden');
139
+ parentDiv?.removeAttribute('aria-hidden');
140
+ }
141
+ else {
142
+ if (variantIsDefaultContent) {
143
+ if (isHydrationTarget) {
144
+ /**
145
+ * For React to work, we need to support hydration, in which case the first CSR will have none of the hidden variants.
146
+ * So we completely remove that node.
147
+ */
148
+ parentDiv?.remove();
149
+ }
150
+ else {
151
+ /** this is not the winning variant, add `hidden` attr */
152
+ parentDiv?.setAttribute('hidden', 'true');
153
+ parentDiv?.setAttribute('aria-hidden', 'true');
154
+ }
155
+ }
156
+ /** This is not the winning variant, and it's not the default content.
157
+ * There's no need to hide it, because it's already hidden.
158
+ */
159
+ return;
160
+ }
161
+ return;
162
+ }
163
+ const getIsHydrationTarget = (target) => target === 'react' || target === 'reactNative';
164
+ const isHydrationTarget = getIsHydrationTarget(TARGET);
165
+ /**
166
+ * We hardcode explicit function names here, because the `.toString()` of a function can change depending on the bundler.
167
+ * Some bundlers will minify the fn name, etc.
168
+ *
169
+ * So we hardcode the function names here, and then use those names in the script string to make sure the function names are consistent.
170
+ */
171
+ const AB_TEST_FN_NAME = 'builderIoAbTest';
172
+ const CONTENT_FN_NAME = 'builderIoRenderContent';
173
+ export const getScriptString = () => {
174
+ const fnStr = bldrAbTest.toString().replace(/\s+/g, ' ');
175
+ const fnStr2 = bldrCntntScrpt.toString().replace(/\s+/g, ' ');
176
+ return `
177
+ window.${AB_TEST_FN_NAME} = ${fnStr}
178
+ window.${CONTENT_FN_NAME} = ${fnStr2}
179
+ `;
180
+ };
181
+ export const getVariantsScriptString = (variants, contentId) => {
182
+ return `
183
+ window.${AB_TEST_FN_NAME}("${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget})`;
184
+ };
185
+ export const getRenderContentScriptString = ({ contentId, variationId }) => {
186
+ return `
187
+ window.${CONTENT_FN_NAME}("${variationId}", "${contentId}", ${isHydrationTarget})`;
188
+ };
@@ -0,0 +1,6 @@
1
+ interface Props {
2
+ scriptStr: string;
3
+ id?: string;
4
+ }
5
+ declare function InlinedScript(props: Props): JSX.Element;
6
+ export default InlinedScript;
@@ -0,0 +1,5 @@
1
+ import * as React from "react";
2
+ function InlinedScript(props) {
3
+ return (React.createElement("script", { dangerouslySetInnerHTML: { __html: props.scriptStr }, id: props.id }));
4
+ }
5
+ export default InlinedScript;
@@ -0,0 +1,6 @@
1
+ interface Props {
2
+ styles: string;
3
+ id?: string;
4
+ }
5
+ declare function InlinedStyles(props: Props): JSX.Element;
6
+ export default InlinedStyles;
@@ -0,0 +1,5 @@
1
+ import * as React from "react";
2
+ function InlinedStyles(props) {
3
+ return (React.createElement("style", { dangerouslySetInnerHTML: { __html: props.styles }, id: props.id }));
4
+ }
5
+ export default InlinedStyles;
@@ -0,0 +1,6 @@
1
+ import type { RegisteredComponent } from '../context/types.js';
2
+ /**
3
+ * Returns a list of all registered components.
4
+ * NOTE: This needs to be a function to work around ESM circular dependencies.
5
+ */
6
+ export declare const getDefaultRegisteredComponents: () => RegisteredComponent[];
@@ -0,0 +1,60 @@
1
+ import { default as Button } from '../blocks/button/button.js';
2
+ import { componentInfo as buttonComponentInfo } from '../blocks/button/component-info.js';
3
+ import { default as Columns } from '../blocks/columns/columns.js';
4
+ import { componentInfo as columnsComponentInfo } from '../blocks/columns/component-info.js';
5
+ import { componentInfo as fragmentComponentInfo } from '../blocks/fragment/component-info.js';
6
+ import { default as Fragment } from '../blocks/fragment/fragment.js';
7
+ import { componentInfo as imageComponentInfo } from '../blocks/image/component-info.js';
8
+ import { default as Image } from '../blocks/image/image.js';
9
+ import { componentInfo as sectionComponentInfo } from '../blocks/section/component-info.js';
10
+ import { default as Section } from '../blocks/section/section.js';
11
+ import { componentInfo as symbolComponentInfo } from '../blocks/symbol/component-info.js';
12
+ import { default as Symbol } from '../blocks/symbol/symbol.js';
13
+ import { componentInfo as textComponentInfo } from '../blocks/text/component-info.js';
14
+ import { default as Text } from '../blocks/text/text.js';
15
+ import { componentInfo as videoComponentInfo } from '../blocks/video/component-info.js';
16
+ import { default as Video } from '../blocks/video/video.js';
17
+ import { componentInfo as embedComponentInfo } from '../blocks/embed/component-info.js';
18
+ import { default as embed } from '../blocks/embed/embed.js';
19
+ import { default as Img } from '../blocks/img/img.js';
20
+ import { componentInfo as imgComponentInfo } from '../blocks/img/component-info.js';
21
+ import { default as customCode } from '../blocks/custom-code/custom-code.js';
22
+ import { componentInfo as customCodeInfo } from '../blocks/custom-code/component-info.js';
23
+ /**
24
+ * Returns a list of all registered components.
25
+ * NOTE: This needs to be a function to work around ESM circular dependencies.
26
+ */
27
+ export const getDefaultRegisteredComponents = () => [{
28
+ component: Button,
29
+ ...buttonComponentInfo
30
+ }, {
31
+ component: Columns,
32
+ ...columnsComponentInfo
33
+ }, {
34
+ component: customCode,
35
+ ...customCodeInfo
36
+ }, {
37
+ component: embed,
38
+ ...embedComponentInfo
39
+ }, {
40
+ component: Fragment,
41
+ ...fragmentComponentInfo
42
+ }, {
43
+ component: Image,
44
+ ...imageComponentInfo
45
+ }, {
46
+ component: Img,
47
+ ...imgComponentInfo
48
+ }, {
49
+ component: Section,
50
+ ...sectionComponentInfo
51
+ }, {
52
+ component: Symbol,
53
+ ...symbolComponentInfo
54
+ }, {
55
+ component: Text,
56
+ ...textComponentInfo
57
+ }, {
58
+ component: Video,
59
+ ...videoComponentInfo
60
+ }];
@@ -0,0 +1,13 @@
1
+ export type SizeName = 'large' | 'medium' | 'small';
2
+ interface Size {
3
+ min: number;
4
+ default: number;
5
+ max: number;
6
+ }
7
+ export declare const getMaxWidthQueryForSize: (size: SizeName, sizeValues?: Record<SizeName, Size>) => string;
8
+ interface Breakpoints {
9
+ small?: number;
10
+ medium?: number;
11
+ }
12
+ export declare const getSizesForBreakpoints: ({ small, medium }: Breakpoints) => Record<SizeName, Size>;
13
+ export {};
@@ -0,0 +1,45 @@
1
+ import { fastClone } from '../functions/fast-clone.js';
2
+ const SIZES = {
3
+ small: {
4
+ min: 320,
5
+ default: 321,
6
+ max: 640
7
+ },
8
+ medium: {
9
+ min: 641,
10
+ default: 642,
11
+ max: 991
12
+ },
13
+ large: {
14
+ min: 990,
15
+ default: 991,
16
+ max: 1200
17
+ }
18
+ };
19
+ export const getMaxWidthQueryForSize = (size, sizeValues = SIZES) => `@media (max-width: ${sizeValues[size].max}px)`;
20
+ export const getSizesForBreakpoints = ({ small, medium }) => {
21
+ const newSizes = fastClone(SIZES); // Note: this helps to get a deep clone of fields like small, medium etc
22
+ if (!small || !medium) {
23
+ return newSizes;
24
+ }
25
+ const smallMin = Math.floor(small / 2);
26
+ newSizes.small = {
27
+ max: small,
28
+ min: smallMin,
29
+ default: smallMin + 1
30
+ };
31
+ const mediumMin = newSizes.small.max + 1;
32
+ newSizes.medium = {
33
+ max: medium,
34
+ min: mediumMin,
35
+ default: mediumMin + 1
36
+ };
37
+ const largeMin = newSizes.medium.max + 1;
38
+ newSizes.large = {
39
+ max: 2000,
40
+ // TODO: decide upper limit
41
+ min: largeMin,
42
+ default: largeMin + 1
43
+ };
44
+ return newSizes;
45
+ };
@@ -0,0 +1 @@
1
+ export declare const SDK_VERSION = "0.4.5";
@@ -0,0 +1 @@
1
+ export const SDK_VERSION = "0.4.5";
@@ -0,0 +1,2 @@
1
+ /** This file should be overriden for each framework. Ideally this would be implemented in Mitosis. */
2
+ export declare const TARGET: any;
@@ -0,0 +1,2 @@
1
+ /** This file should be overriden for each framework. Ideally this would be implemented in Mitosis. */
2
+ export const TARGET = 'rsc';
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ declare const _default: import("react").Context<any>;
3
+ export default _default;
@@ -0,0 +1,12 @@
1
+ import { createContext } from "react";
2
+ export default createContext({
3
+ content: null,
4
+ context: {},
5
+ localState: undefined,
6
+ rootSetState() { },
7
+ rootState: {},
8
+ apiKey: null,
9
+ apiVersion: undefined,
10
+ componentInfos: {},
11
+ inheritedStyles: {},
12
+ });
@@ -0,0 +1,35 @@
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
+ export type RegisteredComponent = ComponentInfo & {
6
+ component: any;
7
+ };
8
+ export type RegisteredComponents = Dictionary<RegisteredComponent>;
9
+ export type BuilderRenderState = Record<string, unknown>;
10
+ export type BuilderRenderContext = Record<string, unknown>;
11
+ export interface BuilderContextInterface {
12
+ content: Nullable<BuilderContent>;
13
+ context: BuilderRenderContext;
14
+ /**
15
+ * The state of the application.
16
+ *
17
+ * NOTE: see `localState` below to understand how it is different from `rootState`.
18
+ */
19
+ rootState: BuilderRenderState;
20
+ /**
21
+ * Some frameworks have a `setState` function which needs to be invoked to notify
22
+ * the framework of state change. (other frameworks don't in which case it is `undefined')
23
+ */
24
+ rootSetState: ((rootState: BuilderRenderState) => void) | undefined;
25
+ /**
26
+ * The local state of the current component. This is different from `rootState` in that
27
+ * it can be a child state created by a repeater containing local state.
28
+ * The `rootState` is where all of the state mutations are actually stored.
29
+ */
30
+ localState: BuilderRenderState | undefined;
31
+ apiKey: string | null;
32
+ apiVersion: ApiVersion | undefined;
33
+ componentInfos: Dictionary<ComponentInfo>;
34
+ inheritedStyles: Record<string, unknown>;
35
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ export type Patch = {
2
+ path: string;
3
+ op: 'add' | 'remove' | 'replace';
4
+ value: any;
5
+ };
6
+ export declare const applyPatchWithMinimalMutationChain: <T extends object>(obj: T, patch: {
7
+ path: string;
8
+ op: 'add' | 'remove' | 'replace';
9
+ value: any;
10
+ }, preserveRoot?: boolean) => T;
@@ -0,0 +1,54 @@
1
+ export const applyPatchWithMinimalMutationChain = (obj, patch, preserveRoot = false) => {
2
+ if (Object(obj) !== obj) {
3
+ return obj;
4
+ }
5
+ const { path, op, value } = patch;
6
+ const pathArr = path.split(/\//);
7
+ if (pathArr[0] === '') {
8
+ pathArr.shift();
9
+ }
10
+ const newObj = preserveRoot ? obj : {
11
+ ...obj
12
+ };
13
+ let objPart = newObj;
14
+ for (let i = 0; i < pathArr.length; i++) {
15
+ const isLast = i === pathArr.length - 1;
16
+ const property = pathArr[i];
17
+ if (isLast) {
18
+ if (op === 'replace') {
19
+ objPart[property] = value;
20
+ }
21
+ else if (op === 'add') {
22
+ const index = Number(property);
23
+ if (Array.isArray(objPart)) {
24
+ if (property === '-') {
25
+ objPart.push(value);
26
+ }
27
+ else {
28
+ objPart.splice(index, 0, value);
29
+ }
30
+ }
31
+ else {
32
+ objPart[property] = value;
33
+ }
34
+ }
35
+ else if (op === 'remove') {
36
+ const index = Number(property);
37
+ if (Array.isArray(objPart)) {
38
+ objPart.splice(index, 1);
39
+ }
40
+ else {
41
+ delete objPart[property];
42
+ }
43
+ }
44
+ }
45
+ else {
46
+ const nextProperty = pathArr[i + 1];
47
+ const newPart = Object(objPart[property]) === objPart[property] ? objPart[property] : String(Number(nextProperty)) === nextProperty ? [] : {};
48
+ objPart = objPart[property] = Array.isArray(newPart) ? [...newPart] : {
49
+ ...newPart
50
+ };
51
+ }
52
+ }
53
+ return newObj;
54
+ };
@@ -0,0 +1 @@
1
+ export declare const camelToKebabCase: (string: string) => string;
@@ -0,0 +1 @@
1
+ export const camelToKebabCase = (string) => string.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2').toLowerCase();
@@ -0,0 +1,7 @@
1
+ import type { BuilderContextInterface, BuilderRenderState } from '../context/types.js';
2
+ export declare function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression }: {
3
+ code: string;
4
+ event?: Event;
5
+ isExpression?: boolean;
6
+ } & Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>): any;
7
+ export declare function flattenState(rootState: Record<string | symbol, any>, localState: Record<string | symbol, any> | undefined, rootSetState: ((rootState: BuilderRenderState) => void) | undefined): BuilderRenderState;
@@ -0,0 +1,46 @@
1
+ import { isBrowser } from './is-browser.js';
2
+ import { isEditing } from './is-editing.js';
3
+ export function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true }) {
4
+ if (code === '') {
5
+ console.warn('Skipping evaluation of empty code block.');
6
+ return;
7
+ }
8
+ const builder = {
9
+ isEditing: isEditing(),
10
+ isBrowser: isBrowser(),
11
+ isServer: !isBrowser()
12
+ }; // Be able to handle simple expressions like "state.foo" or "1 + 1"
13
+ // as well as full blocks like "var foo = "bar"; return foo"
14
+ const useReturn = // we disable this for cases where we definitely don't want a return
15
+ isExpression && !(code.includes(';') || code.includes(' return ') || code.trim().startsWith('return '));
16
+ const useCode = useReturn ? `return (${code});` : code;
17
+ try {
18
+ return new Function('builder', 'Builder'
19
+ /* <- legacy */
20
+ , 'state', 'context', 'event', useCode)(builder, builder, flattenState(rootState, localState, rootSetState), context, event);
21
+ }
22
+ catch (e) {
23
+ console.warn('Builder custom code error: \n While Evaluating: \n ', useCode, '\n', e);
24
+ }
25
+ }
26
+ export function flattenState(rootState, localState, rootSetState) {
27
+ if (rootState === localState) {
28
+ throw new Error('rootState === localState');
29
+ }
30
+ return new Proxy(rootState, {
31
+ get: (_, prop) => {
32
+ if (localState && prop in localState) {
33
+ return localState[prop];
34
+ }
35
+ return rootState[prop];
36
+ },
37
+ set: (_, prop, value) => {
38
+ if (localState && prop in localState) {
39
+ throw new Error('Writing to local state is not allowed as it is read-only.');
40
+ }
41
+ rootState[prop] = value;
42
+ rootSetState?.(rootState);
43
+ return true;
44
+ }
45
+ });
46
+ }
@@ -0,0 +1 @@
1
+ export declare const getEventHandlerName: (key: string) => string;
@@ -0,0 +1,4 @@
1
+ function capitalizeFirstLetter(string) {
2
+ return string.charAt(0).toUpperCase() + string.slice(1);
3
+ }
4
+ export const getEventHandlerName = (key) => `on${capitalizeFirstLetter(key)}`;