@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,9 @@
1
+ type Props = {
2
+ block: BuilderBlock;
3
+ repeatContext: BuilderContextInterface;
4
+ registeredComponents: RegisteredComponents;
5
+ };
6
+ import type { BuilderContextInterface, RegisteredComponents } from "../../../context/types.js";
7
+ import type { BuilderBlock } from "../../../types/builder-block.js";
8
+ declare function RepeatedBlock(props: Props): JSX.Element;
9
+ export default RepeatedBlock;
@@ -0,0 +1,7 @@
1
+ import * as React from "react";
2
+ import Block from "../block.js";
3
+ function RepeatedBlock(props) {
4
+ const store = props.repeatContext;
5
+ return (React.createElement(Block, { block: props.block, context: store, registeredComponents: props.registeredComponents }));
6
+ }
7
+ export default RepeatedBlock;
@@ -0,0 +1,6 @@
1
+ import type { BuilderContextInterface } from '../../context/types.js';
2
+ import type { BuilderBlock } from '../../types/builder-block.js';
3
+ export interface RepeatData {
4
+ block: BuilderBlock;
5
+ context: BuilderContextInterface;
6
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ export type BlocksWrapperProps = {
2
+ blocks: BuilderBlock[] | undefined;
3
+ parent: string | undefined;
4
+ path: string | undefined;
5
+ styleProp: Record<string, any> | undefined;
6
+ };
7
+ import type { BuilderBlock } from "../../types/builder-block.js";
8
+ import type { PropsWithChildren } from "../../types/typescript.js";
9
+ declare function BlocksWrapper(props: PropsWithChildren<BlocksWrapperProps>): JSX.Element;
10
+ export default BlocksWrapper;
@@ -0,0 +1,38 @@
1
+ "use client";
2
+ import * as React from "react";
3
+ import { isEditing } from "../../functions/is-editing.js";
4
+ function BlocksWrapper(props) {
5
+ function className() {
6
+ return "builder-blocks" + (!props.blocks?.length ? " no-blocks" : "");
7
+ }
8
+ function onClick() {
9
+ if (isEditing() && !props.blocks?.length) {
10
+ window.parent?.postMessage({
11
+ type: "builder.clickEmptyBlocks",
12
+ data: {
13
+ parentElementId: props.parent,
14
+ dataPath: props.path,
15
+ },
16
+ }, "*");
17
+ }
18
+ }
19
+ function onMouseEnter() {
20
+ if (isEditing() && !props.blocks?.length) {
21
+ window.parent?.postMessage({
22
+ type: "builder.hoverEmptyBlocks",
23
+ data: {
24
+ parentElementId: props.parent,
25
+ dataPath: props.path,
26
+ },
27
+ }, "*");
28
+ }
29
+ }
30
+ return (React.createElement(React.Fragment, null,
31
+ React.createElement("div", { className: className() + " div-b2473120", "builder-path": props.path, "builder-parent-id": props.parent, style: props.styleProp, onClick: (event) => onClick(), onMouseEnter: (event) => onMouseEnter(), onKeyPress: (event) => onClick() }, props.children),
32
+ React.createElement("style", null, `.div-b2473120 {
33
+ display: flex;
34
+ flex-direction: column;
35
+ align-items: stretch;
36
+ }`)));
37
+ }
38
+ export default BlocksWrapper;
@@ -0,0 +1,8 @@
1
+ export type BlocksProps = Partial<BlocksWrapperProps> & {
2
+ context: BuilderContextInterface;
3
+ registeredComponents: RegisteredComponents;
4
+ };
5
+ import type { BlocksWrapperProps } from "./blocks-wrapper.js";
6
+ import type { BuilderContextInterface, RegisteredComponents } from "../../context/types.js";
7
+ declare function Blocks(props: BlocksProps): JSX.Element;
8
+ export default Blocks;
@@ -0,0 +1,10 @@
1
+ import * as React from "react";
2
+ import BlockStyles from "../block/components/block-styles.js";
3
+ import Block from "../block/block.js";
4
+ import BlocksWrapper from "./blocks-wrapper.js";
5
+ function Blocks(props) {
6
+ return (React.createElement(BlocksWrapper, { blocks: props.blocks, parent: props.parent, path: props.path, styleProp: props.styleProp },
7
+ props.blocks ? (React.createElement(React.Fragment, null, props.blocks?.map((block) => (React.createElement(Block, { key: "render-block-" + block.id, block: block, context: props.context, registeredComponents: props.registeredComponents }))))) : null,
8
+ props.blocks ? (React.createElement(React.Fragment, null, props.blocks?.map((block) => (React.createElement(BlockStyles, { key: "block-style-" + block.id, block: block, context: props.context }))))) : null));
9
+ }
10
+ export default Blocks;
@@ -0,0 +1,9 @@
1
+ type BuilderEditorProps = Omit<ContentProps, "customComponents" | "data" | "apiVersion" | "isSsrAbTest"> & {
2
+ builderContextSignal: BuilderContextInterface;
3
+ setBuilderContextSignal?: (signal: any) => any;
4
+ children?: any;
5
+ };
6
+ import type { BuilderContextInterface } from "../../../context/types.js";
7
+ import type { ContentProps } from "../content.types.js";
8
+ declare function EnableEditor(props: BuilderEditorProps): JSX.Element;
9
+ export default EnableEditor;
@@ -0,0 +1,249 @@
1
+ "use client";
2
+ import * as React from "react";
3
+ import { useState, useRef, useEffect } from "react";
4
+ import { evaluate } from "../../../functions/evaluate.js";
5
+ import { fetch } from "../../../functions/get-fetch.js";
6
+ import { isBrowser } from "../../../functions/is-browser.js";
7
+ import { isEditing } from "../../../functions/is-editing.js";
8
+ import { createRegisterComponentMessage } from "../../../functions/register-component.js";
9
+ import { _track } from "../../../functions/track/index.js";
10
+ import builderContext from "../../../context/builder.context";
11
+ import { registerInsertMenu, setupBrowserForEditing, } from "../../../scripts/init-editing.js";
12
+ import { checkIsDefined } from "../../../helpers/nullable.js";
13
+ import { getInteractionPropertiesForEvent } from "../../../functions/track/interaction.js";
14
+ import { logger } from "../../../helpers/logger.js";
15
+ import { postPreviewContent } from "../../../helpers/preview-lru-cache/set.js";
16
+ import { useRouter } from "next/navigation";
17
+ function EnableEditor(props) {
18
+ const elementRef = useRef(null);
19
+ const [canTrackToUse, setCanTrackToUse] = useState(() => checkIsDefined(props.canTrack) ? props.canTrack : true);
20
+ const [forceReRenderCount, setForceReRenderCount] = useState(() => 0);
21
+ function mergeNewContent(newContent) {
22
+ const newContentValue = {
23
+ ...props.builderContextSignal.content,
24
+ ...newContent,
25
+ data: {
26
+ ...props.builderContextSignal.content?.data,
27
+ ...newContent?.data,
28
+ },
29
+ meta: {
30
+ ...props.builderContextSignal.content?.meta,
31
+ ...newContent?.meta,
32
+ breakpoints: newContent?.meta?.breakpoints ||
33
+ props.builderContextSignal.content?.meta?.breakpoints,
34
+ },
35
+ };
36
+ postPreviewContent({
37
+ value: newContentValue,
38
+ key: newContentValue.id,
39
+ }).then(() => {
40
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
41
+ // @ts-ignore
42
+ router.refresh();
43
+ });
44
+ }
45
+ const [lastUpdated, setLastUpdated] = useState(() => 0);
46
+ const [shouldSendResetCookie, setShouldSendResetCookie] = useState(() => false);
47
+ function processMessage(event) {
48
+ const { data } = event;
49
+ if (data) {
50
+ switch (data.type) {
51
+ case "builder.configureSdk": {
52
+ const messageContent = data.data;
53
+ const { breakpoints, contentId } = messageContent;
54
+ if (!contentId ||
55
+ contentId !== props.builderContextSignal.content?.id) {
56
+ return;
57
+ }
58
+ if (breakpoints) {
59
+ mergeNewContent({
60
+ meta: {
61
+ breakpoints,
62
+ },
63
+ });
64
+ }
65
+ setForceReRenderCount(forceReRenderCount + 1); // This is a hack to force Qwik to re-render.
66
+ break;
67
+ }
68
+ case "builder.contentUpdate": {
69
+ const messageContent = data.data;
70
+ const key = messageContent.key ||
71
+ messageContent.alias ||
72
+ messageContent.entry ||
73
+ messageContent.modelName;
74
+ const contentData = messageContent.data;
75
+ if (key === props.model) {
76
+ mergeNewContent(contentData);
77
+ setForceReRenderCount(forceReRenderCount + 1); // This is a hack to force Qwik to re-render.
78
+ }
79
+ break;
80
+ }
81
+ }
82
+ }
83
+ }
84
+ function evaluateJsCode() {
85
+ // run any dynamic JS code attached to content
86
+ const jsCode = props.builderContextSignal.content?.data?.jsCode;
87
+ if (jsCode) {
88
+ evaluate({
89
+ code: jsCode,
90
+ context: props.context || {},
91
+ localState: undefined,
92
+ rootState: props.builderContextSignal.rootState,
93
+ rootSetState: props.builderContextSignal.rootSetState,
94
+ });
95
+ }
96
+ }
97
+ const [httpReqsData, setHttpReqsData] = useState(() => ({}));
98
+ const [clicked, setClicked] = useState(() => false);
99
+ function onClick(event) {
100
+ if (props.builderContextSignal.content) {
101
+ const variationId = props.builderContextSignal.content?.testVariationId;
102
+ const contentId = props.builderContextSignal.content?.id;
103
+ _track({
104
+ type: "click",
105
+ canTrack: canTrackToUse,
106
+ contentId,
107
+ apiKey: props.apiKey,
108
+ variationId: variationId !== contentId ? variationId : undefined,
109
+ ...getInteractionPropertiesForEvent(event),
110
+ unique: !clicked,
111
+ });
112
+ }
113
+ if (!clicked) {
114
+ setClicked(true);
115
+ }
116
+ }
117
+ function evalExpression(expression) {
118
+ return expression.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({
119
+ code: group,
120
+ context: props.context || {},
121
+ localState: undefined,
122
+ rootState: props.builderContextSignal.rootState,
123
+ rootSetState: props.builderContextSignal.rootSetState,
124
+ }));
125
+ }
126
+ function handleRequest({ url, key }) {
127
+ fetch(url)
128
+ .then((response) => response.json())
129
+ .then((json) => {
130
+ const newState = {
131
+ ...props.builderContextSignal.rootState,
132
+ [key]: json,
133
+ };
134
+ props.builderContextSignal.rootSetState?.(newState);
135
+ httpReqsData[key] = true;
136
+ })
137
+ .catch((err) => {
138
+ console.error("error fetching dynamic data", url, err);
139
+ });
140
+ }
141
+ function runHttpRequests() {
142
+ const requests = props.builderContextSignal.content?.data?.httpRequests ?? {};
143
+ Object.entries(requests).forEach(([key, url]) => {
144
+ if (url && (!httpReqsData[key] || isEditing())) {
145
+ const evaluatedUrl = evalExpression(url);
146
+ handleRequest({
147
+ url: evaluatedUrl,
148
+ key,
149
+ });
150
+ }
151
+ });
152
+ }
153
+ function emitStateUpdate() {
154
+ if (isEditing()) {
155
+ window.dispatchEvent(new CustomEvent("builder:component:stateChange", {
156
+ detail: {
157
+ state: props.builderContextSignal.rootState,
158
+ ref: {
159
+ name: props.model,
160
+ },
161
+ },
162
+ }));
163
+ }
164
+ }
165
+ const router = useRouter();
166
+ useEffect(() => {
167
+ if (!props.apiKey) {
168
+ logger.error("No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
169
+ }
170
+ if (isBrowser()) {
171
+ if (isEditing()) {
172
+ setForceReRenderCount(forceReRenderCount + 1);
173
+ window.addEventListener("message", processMessage);
174
+ registerInsertMenu();
175
+ setupBrowserForEditing({
176
+ ...(props.locale
177
+ ? {
178
+ locale: props.locale,
179
+ }
180
+ : {}),
181
+ ...(props.includeRefs
182
+ ? {
183
+ includeRefs: props.includeRefs,
184
+ }
185
+ : {}),
186
+ ...(props.enrich
187
+ ? {
188
+ enrich: props.enrich,
189
+ }
190
+ : {}),
191
+ });
192
+ Object.values(props.builderContextSignal.componentInfos).forEach((registeredComponent) => {
193
+ const message = createRegisterComponentMessage(registeredComponent);
194
+ window.parent?.postMessage(message, "*");
195
+ });
196
+ window.addEventListener("builder:component:stateChangeListenerActivated", emitStateUpdate);
197
+ }
198
+ if (props.builderContextSignal.content) {
199
+ const variationId = props.builderContextSignal.content?.testVariationId;
200
+ const contentId = props.builderContextSignal.content?.id;
201
+ _track({
202
+ type: "impression",
203
+ canTrack: canTrackToUse,
204
+ contentId,
205
+ apiKey: props.apiKey,
206
+ variationId: variationId !== contentId ? variationId : undefined,
207
+ });
208
+ }
209
+ evaluateJsCode();
210
+ runHttpRequests();
211
+ emitStateUpdate();
212
+ }
213
+ }, []);
214
+ useEffect(() => { }, [props.content]);
215
+ useEffect(() => {
216
+ if (isBrowser()) {
217
+ window.removeEventListener("message", processMessage);
218
+ window.addEventListener("message", processMessage);
219
+ }
220
+ }, [shouldSendResetCookie]);
221
+ useEffect(() => {
222
+ evaluateJsCode();
223
+ }, [
224
+ props.builderContextSignal.content?.data?.jsCode,
225
+ props.builderContextSignal.rootState,
226
+ ]);
227
+ useEffect(() => {
228
+ runHttpRequests();
229
+ }, [props.builderContextSignal.content?.data?.httpRequests]);
230
+ useEffect(() => {
231
+ emitStateUpdate();
232
+ }, [props.builderContextSignal.rootState]);
233
+ useEffect(() => {
234
+ return () => {
235
+ if (isBrowser()) {
236
+ window.removeEventListener("message", processMessage);
237
+ window.removeEventListener("builder:component:stateChangeListenerActivated", emitStateUpdate);
238
+ }
239
+ };
240
+ }, []);
241
+ return (React.createElement(builderContext.Provider, { value: props.builderContextSignal }, props.builderContextSignal.content ? (React.createElement(React.Fragment, null,
242
+ React.createElement("div", { key: forceReRenderCount, ref: elementRef, onClick: (event) => onClick(event), "builder-content-id": props.builderContextSignal.content?.id, "builder-model": props.model, ...(props.showContent
243
+ ? {}
244
+ : {
245
+ hidden: true,
246
+ "aria-hidden": true,
247
+ }), className: props.classNameProp }, props.children))) : null));
248
+ }
249
+ export default EnableEditor;
@@ -0,0 +1,8 @@
1
+ interface Props {
2
+ cssCode?: string;
3
+ customFonts?: CustomFont[];
4
+ contentId?: string;
5
+ }
6
+ import type { CustomFont } from "./styles.helpers.js";
7
+ declare function ContentStyles(props: Props): JSX.Element;
8
+ export default ContentStyles;
@@ -0,0 +1,15 @@
1
+ export interface CustomFont {
2
+ family?: string;
3
+ kind?: string;
4
+ fileUrl?: string;
5
+ files?: {
6
+ [key: string]: string;
7
+ };
8
+ }
9
+ export declare const getFontCss: ({ customFonts }: {
10
+ customFonts?: CustomFont[];
11
+ }) => string;
12
+ export declare const getCss: ({ cssCode, contentId }: {
13
+ cssCode?: string;
14
+ contentId?: string;
15
+ }) => string;
@@ -0,0 +1,56 @@
1
+ const getCssFromFont = (font) => {
2
+ // TODO: compute what font sizes are used and only load those.......
3
+ const family = font.family + (font.kind && !font.kind.includes('#') ? ', ' + font.kind : '');
4
+ const name = family.split(',')[0];
5
+ const url = font.fileUrl ?? font?.files?.regular;
6
+ let str = '';
7
+ if (url && family && name) {
8
+ str += `
9
+ @font-face {
10
+ font-family: "${family}";
11
+ src: local("${name}"), url('${url}') format('woff2');
12
+ font-display: fallback;
13
+ font-weight: 400;
14
+ }
15
+ `.trim();
16
+ }
17
+ if (font.files) {
18
+ for (const weight in font.files) {
19
+ const isNumber = String(Number(weight)) === weight;
20
+ if (!isNumber) {
21
+ continue;
22
+ } // TODO: maybe limit number loaded
23
+ const weightUrl = font.files[weight];
24
+ if (weightUrl && weightUrl !== url) {
25
+ str += `
26
+ @font-face {
27
+ font-family: "${family}";
28
+ src: url('${weightUrl}') format('woff2');
29
+ font-display: fallback;
30
+ font-weight: ${weight};
31
+ }
32
+ `.trim();
33
+ }
34
+ }
35
+ }
36
+ return str;
37
+ };
38
+ export const getFontCss = ({ customFonts }) => {
39
+ // TODO: flag for this
40
+ // if (!this.builder.allowCustomFonts) {
41
+ // return '';
42
+ // }
43
+ // TODO: separate internal data from external
44
+ return customFonts?.map(font => getCssFromFont(font))?.join(' ') || '';
45
+ };
46
+ export const getCss = ({ cssCode, contentId }) => {
47
+ if (!cssCode) {
48
+ return '';
49
+ }
50
+ if (!contentId) {
51
+ return cssCode;
52
+ } // Allow using `&` in custom CSS code like @emotion
53
+ // E.g. `& .foobar { ... }` to scope CSS
54
+ // TODO: handle if '&' is within a string like `content: "&"`
55
+ return cssCode?.replace(/&/g, `div[builder-content-id="${contentId}"]`) || '';
56
+ };
@@ -0,0 +1,30 @@
1
+ import * as React from "react";
2
+ import InlinedStyles from "../../inlined-styles.js";
3
+ import { getCss } from "./styles.helpers.js";
4
+ import { getFontCss } from "./styles.helpers.js";
5
+ function ContentStyles(props) {
6
+ const injectedStyles = `
7
+ ${getCss({
8
+ cssCode: props.cssCode,
9
+ contentId: props.contentId,
10
+ })}
11
+ ${getFontCss({
12
+ customFonts: props.customFonts,
13
+ })}
14
+
15
+ .builder-text > p:first-of-type, .builder-text > .builder-paragraph:first-of-type {
16
+ margin: 0;
17
+ }
18
+ .builder-text > p, .builder-text > .builder-paragraph {
19
+ color: inherit;
20
+ line-height: inherit;
21
+ letter-spacing: inherit;
22
+ font-weight: inherit;
23
+ font-size: inherit;
24
+ text-align: inherit;
25
+ font-family: inherit;
26
+ }
27
+ `.trim();
28
+ return React.createElement(InlinedStyles, { styles: injectedStyles });
29
+ }
30
+ export default ContentStyles;
@@ -0,0 +1,3 @@
1
+ import type { ContentProps } from "./content.types.js";
2
+ declare function ContentComponent(props: ContentProps): JSX.Element;
3
+ export default ContentComponent;
@@ -0,0 +1,7 @@
1
+ import type { BuilderContent } from '../../types/builder-content.js';
2
+ import type { Nullable } from '../../types/typescript.js';
3
+ import type { ContentProps } from './content.types.js';
4
+ export declare const getContextStateInitialValue: ({ content, data, locale }: Pick<ContentProps, 'content' | 'data' | 'locale'>) => {
5
+ [x: string]: unknown;
6
+ };
7
+ export declare const getContentInitialValue: ({ content, data }: Pick<ContentProps, 'content' | 'data'>) => Nullable<BuilderContent>;
@@ -0,0 +1,25 @@
1
+ export const getContextStateInitialValue = ({ content, data, locale }) => {
2
+ const defaultValues = {}; // set default values for content state inputs
3
+ content?.data?.inputs?.forEach(input => {
4
+ if (input.name && input.defaultValue !== undefined && content?.data?.state && content.data.state[input.name] === undefined) {
5
+ defaultValues[input.name] = input.defaultValue;
6
+ }
7
+ });
8
+ const stateToUse = { ...content?.data?.state,
9
+ ...data,
10
+ ...(locale ? {
11
+ locale
12
+ } : {})
13
+ };
14
+ return { ...defaultValues,
15
+ ...stateToUse
16
+ };
17
+ };
18
+ export const getContentInitialValue = ({ content, data }) => {
19
+ return !content ? undefined : { ...content,
20
+ data: { ...content?.data,
21
+ ...data
22
+ },
23
+ meta: content?.meta
24
+ };
25
+ };
@@ -0,0 +1,72 @@
1
+ import * as React from "react";
2
+ import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
3
+ import { components, serializeComponentInfo, } from "../../functions/register-component.js";
4
+ import Blocks from "../blocks/blocks.js";
5
+ import ContentStyles from "./components/styles.js";
6
+ import { getContentInitialValue, getContextStateInitialValue, } from "./content.helpers.js";
7
+ import { TARGET } from "../../constants/target.js";
8
+ import { getRenderContentScriptString } from "../content-variants/helpers.js";
9
+ import EnableEditor from "./components/enable-editor.js";
10
+ import InlinedScript from "../inlined-script.js";
11
+ function ContentComponent(props) {
12
+ const scriptStr = getRenderContentScriptString({
13
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
14
+ variationId: props.content?.testVariationId,
15
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
16
+ contentId: props.content?.id,
17
+ });
18
+ const contentSetState = function contentSetState(newRootState) {
19
+ builderContextSignal.rootState = newRootState;
20
+ };
21
+ const registeredComponents = [
22
+ ...getDefaultRegisteredComponents(),
23
+ // Since users are able to override our default components, we need to make sure that we do not break such
24
+ // existing usage.
25
+ // This is why we spread `components` after the default Builder.io components, but before the `props.customComponents`,
26
+ // which is the new standard way of providing custom components, and must therefore take precedence.
27
+ ...components,
28
+ ...(props.customComponents || []),
29
+ ].reduce((acc, { component, ...info }) => ({
30
+ ...acc,
31
+ [info.name]: {
32
+ component: component,
33
+ ...serializeComponentInfo(info),
34
+ },
35
+ }), {});
36
+ const builderContextSignal = {
37
+ content: getContentInitialValue({
38
+ content: props.content,
39
+ data: props.data,
40
+ }),
41
+ localState: undefined,
42
+ rootState: getContextStateInitialValue({
43
+ content: props.content,
44
+ data: props.data,
45
+ locale: props.locale,
46
+ }),
47
+ rootSetState: undefined,
48
+ context: props.context || {},
49
+ apiKey: props.apiKey,
50
+ apiVersion: props.apiVersion,
51
+ componentInfos: [
52
+ ...getDefaultRegisteredComponents(),
53
+ // Since users are able to override our default components, we need to make sure that we do not break such
54
+ // existing usage.
55
+ // This is why we spread `components` after the default Builder.io components, but before the `props.customComponents`,
56
+ // which is the new standard way of providing custom components, and must therefore take precedence.
57
+ ...components,
58
+ ...(props.customComponents || []),
59
+ ].reduce((acc, { component: _, ...info }) => ({
60
+ ...acc,
61
+ [info.name]: serializeComponentInfo(info),
62
+ }), {}),
63
+ inheritedStyles: {},
64
+ };
65
+ return (React.createElement(EnableEditor, { content: props.content, model: props.model, context: props.context, apiKey: props.apiKey, canTrack: props.canTrack, locale: props.locale, includeRefs: props.includeRefs, enrich: props.enrich, classNameProp: props.classNameProp, showContent: props.showContent, builderContextSignal: builderContextSignal },
66
+ props.isSsrAbTest ? (React.createElement(React.Fragment, null,
67
+ React.createElement(InlinedScript, { scriptStr: scriptStr }))) : null,
68
+ TARGET !== "reactNative" ? (React.createElement(React.Fragment, null,
69
+ React.createElement(ContentStyles, { contentId: builderContextSignal.content?.id, cssCode: builderContextSignal.content?.data?.cssCode, customFonts: builderContextSignal.content?.data?.customFonts }))) : null,
70
+ React.createElement(Blocks, { blocks: builderContextSignal.content?.data?.blocks, context: builderContextSignal, registeredComponents: registeredComponents })));
71
+ }
72
+ export default ContentComponent;
@@ -0,0 +1,24 @@
1
+ import type { BuilderRenderState } from '../../context/types.js';
2
+ import type { EnforcePartials } from '../../types/enforced-partials.js';
3
+ import type { ContentVariantsProps } from '../content-variants/content-variants.types.js';
4
+ interface InternalRenderProps {
5
+ /**
6
+ * TO-DO: improve qwik generator to not remap this name for non-HTML tags, then name it `className`
7
+ */
8
+ classNameProp: string | undefined;
9
+ showContent: boolean;
10
+ isSsrAbTest: boolean;
11
+ }
12
+ export type ContentProps = InternalRenderProps & EnforcePartials<ContentVariantsProps>;
13
+ export interface BuilderComponentStateChange {
14
+ state: BuilderRenderState;
15
+ ref: {
16
+ name?: string;
17
+ props?: {
18
+ builderBlock?: {
19
+ id?: string;
20
+ };
21
+ };
22
+ };
23
+ }
24
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Apply target-specific transformations to the component reference.
3
+ *
4
+ * See overrides/* for examples.
5
+ */
6
+ export declare const wrapComponentRef: (component: any) => any;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Apply target-specific transformations to the component reference.
3
+ *
4
+ * See overrides/* for examples.
5
+ */
6
+ export const wrapComponentRef = (component) => component;
@@ -0,0 +1,9 @@
1
+ type VariantsProviderProps = ContentVariantsProps & {
2
+ /**
3
+ * For internal use only. Do not provide this prop.
4
+ */
5
+ __isNestedRender?: boolean;
6
+ };
7
+ import type { ContentVariantsProps } from "./content-variants.types.js";
8
+ declare function ContentVariants(props: VariantsProviderProps): JSX.Element;
9
+ export default ContentVariants;