@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,29 @@
1
+ import * as React from "react";
2
+ import ContentVariants from "../../components/content-variants/content-variants.js";
3
+ import { fetchContent } from "./symbol.helpers.js";
4
+ async function Symbol(props) {
5
+ const className = function className() {
6
+ return [
7
+ ...[props.attributes.className],
8
+ "builder-symbol",
9
+ props.symbol?.inline ? "builder-inline-symbol" : undefined,
10
+ props.symbol?.dynamic || props.dynamic
11
+ ? "builder-dynamic-symbol"
12
+ : undefined,
13
+ ]
14
+ .filter(Boolean)
15
+ .join(" ");
16
+ };
17
+ const contentToUse = props.symbol?.content ||
18
+ (await fetchContent({
19
+ symbol: props.symbol,
20
+ builderContextValue: props.builderContext,
21
+ }));
22
+ return (React.createElement("div", { ...props.attributes, className: className() },
23
+ React.createElement(ContentVariants, { __isNestedRender: true, apiVersion: props.builderContext.apiVersion, apiKey: props.builderContext.apiKey, context: props.builderContext.context, customComponents: Object.values(props.builderComponents), data: {
24
+ ...props.symbol?.data,
25
+ ...props.builderContext.localState,
26
+ ...contentToUse?.data?.state,
27
+ }, model: props.symbol?.model, content: contentToUse })));
28
+ }
29
+ export default Symbol;
@@ -0,0 +1,2 @@
1
+ import type { ComponentInfo } from '../../types/components.js';
2
+ export declare const componentInfo: ComponentInfo;
@@ -0,0 +1,19 @@
1
+ export const componentInfo = {
2
+ name: 'Text',
3
+ static: true,
4
+ isRSC: true,
5
+ image: 'https://firebasestorage.googleapis.com/v0/b/builder-3b0a2.appspot.com/o/images%2Fbaseline-text_fields-24px%20(1).svg?alt=media&token=12177b73-0ee3-42ca-98c6-0dd003de1929',
6
+ inputs: [{
7
+ name: 'text',
8
+ type: 'html',
9
+ required: true,
10
+ autoFocus: true,
11
+ bubble: true,
12
+ defaultValue: 'Enter some text...'
13
+ }],
14
+ defaultStyles: {
15
+ lineHeight: 'normal',
16
+ height: 'auto',
17
+ textAlign: 'center'
18
+ }
19
+ };
@@ -0,0 +1,5 @@
1
+ export interface TextProps {
2
+ text?: string;
3
+ }
4
+ declare function Text(props: TextProps): JSX.Element;
5
+ export default Text;
@@ -0,0 +1,7 @@
1
+ import * as React from "react";
2
+ function Text(props) {
3
+ return (React.createElement("span", { className: "builder-text", dangerouslySetInnerHTML: { __html: props.text?.toString() || "" }, style: {
4
+ outline: "none",
5
+ } }));
6
+ }
7
+ export default Text;
@@ -0,0 +1,2 @@
1
+ import type { ComponentInfo } from '../../types/components.js';
2
+ export declare const componentInfo: ComponentInfo;
@@ -0,0 +1,82 @@
1
+ export const componentInfo = {
2
+ name: 'Video',
3
+ canHaveChildren: true,
4
+ defaultStyles: {
5
+ minHeight: '20px',
6
+ minWidth: '20px'
7
+ },
8
+ image: 'https://firebasestorage.googleapis.com/v0/b/builder-3b0a2.appspot.com/o/images%2Fbaseline-videocam-24px%20(1).svg?alt=media&token=49a84e4a-b20e-4977-a650-047f986874bb',
9
+ inputs: [{
10
+ name: 'video',
11
+ type: 'file',
12
+ allowedFileTypes: ['mp4'],
13
+ bubble: true,
14
+ defaultValue: 'https://firebasestorage.googleapis.com/v0/b/builder-3b0a2.appspot.com/o/assets%2FKQlEmWDxA0coC3PK6UvkrjwkIGI2%2F28cb070609f546cdbe5efa20e931aa4b?alt=media&token=912e9551-7a7c-4dfb-86b6-3da1537d1a7f',
15
+ required: true
16
+ }, {
17
+ name: 'posterImage',
18
+ type: 'file',
19
+ allowedFileTypes: ['jpeg', 'png'],
20
+ helperText: 'Image to show before the video plays'
21
+ }, {
22
+ name: 'autoPlay',
23
+ type: 'boolean',
24
+ defaultValue: true
25
+ }, {
26
+ name: 'controls',
27
+ type: 'boolean',
28
+ defaultValue: false
29
+ }, {
30
+ name: 'muted',
31
+ type: 'boolean',
32
+ defaultValue: true
33
+ }, {
34
+ name: 'loop',
35
+ type: 'boolean',
36
+ defaultValue: true
37
+ }, {
38
+ name: 'playsInline',
39
+ type: 'boolean',
40
+ defaultValue: true
41
+ }, {
42
+ name: 'fit',
43
+ type: 'text',
44
+ defaultValue: 'cover',
45
+ enum: ['contain', 'cover', 'fill', 'auto']
46
+ }, {
47
+ name: 'preload',
48
+ type: 'text',
49
+ defaultValue: 'metadata',
50
+ enum: ['auto', 'metadata', 'none']
51
+ }, {
52
+ name: 'fitContent',
53
+ type: 'boolean',
54
+ helperText: 'When child blocks are provided, fit to them instead of using the aspect ratio',
55
+ defaultValue: true,
56
+ advanced: true
57
+ }, {
58
+ name: 'position',
59
+ type: 'text',
60
+ defaultValue: 'center',
61
+ enum: ['center', 'top', 'left', 'right', 'bottom', 'top left', 'top right', 'bottom left', 'bottom right']
62
+ }, {
63
+ name: 'height',
64
+ type: 'number',
65
+ advanced: true
66
+ }, {
67
+ name: 'width',
68
+ type: 'number',
69
+ advanced: true
70
+ }, {
71
+ name: 'aspectRatio',
72
+ type: 'number',
73
+ advanced: true,
74
+ defaultValue: 0.7004048582995948
75
+ }, {
76
+ name: 'lazyLoad',
77
+ type: 'boolean',
78
+ helperText: 'Load this video "lazily" - as in only when a user scrolls near the video. Recommended for optmized performance and bandwidth consumption',
79
+ defaultValue: true,
80
+ advanced: true
81
+ }]
82
+ };
@@ -0,0 +1,19 @@
1
+ export interface VideoProps {
2
+ attributes?: any;
3
+ video?: string;
4
+ autoPlay?: boolean;
5
+ controls?: boolean;
6
+ muted?: boolean;
7
+ loop?: boolean;
8
+ playsInline?: boolean;
9
+ aspectRatio?: number;
10
+ width?: number;
11
+ height?: number;
12
+ fit?: "contain" | "cover" | "fill";
13
+ preload?: "auto" | "metadata" | "none";
14
+ position?: "center" | "top" | "left" | "right" | "bottom" | "top left" | "top right" | "bottom left" | "bottom right";
15
+ posterImage?: string;
16
+ lazyLoad?: boolean;
17
+ }
18
+ declare function Video(props: VideoProps): JSX.Element;
19
+ export default Video;
@@ -0,0 +1,47 @@
1
+ "use client";
2
+ import * as React from "react";
3
+ function Video(props) {
4
+ function videoProps() {
5
+ return {
6
+ ...(props.autoPlay === true
7
+ ? {
8
+ autoPlay: true,
9
+ }
10
+ : {}),
11
+ ...(props.muted === true
12
+ ? {
13
+ muted: true,
14
+ }
15
+ : {}),
16
+ ...(props.controls === true
17
+ ? {
18
+ controls: true,
19
+ }
20
+ : {}),
21
+ ...(props.loop === true
22
+ ? {
23
+ loop: true,
24
+ }
25
+ : {}),
26
+ ...(props.playsInline === true
27
+ ? {
28
+ playsInline: true,
29
+ }
30
+ : {}),
31
+ };
32
+ }
33
+ function spreadProps() {
34
+ return { ...props.attributes, ...videoProps() };
35
+ }
36
+ return (React.createElement("video", { ...spreadProps(), preload: props.preload || "metadata", style: {
37
+ width: "100%",
38
+ height: "100%",
39
+ ...props.attributes?.style,
40
+ objectFit: props.fit,
41
+ objectPosition: props.position,
42
+ // Hack to get object fit to work as expected and
43
+ // not have the video overflow
44
+ borderRadius: 1,
45
+ }, src: props.video || "no-src", poster: props.posterImage }));
46
+ }
47
+ export default Video;
@@ -0,0 +1,9 @@
1
+ export type BlockProps = {
2
+ block: BuilderBlock;
3
+ context: 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 Block(props: BlockProps): JSX.Element;
9
+ export default Block;
@@ -0,0 +1,13 @@
1
+ import type { BuilderContextInterface, RegisteredComponents } from '../../context/types.js';
2
+ import type { BuilderBlock } from '../../types/builder-block.js';
3
+ import type { RepeatData } from './types.js';
4
+ export declare const isEmptyHtmlElement: (tagName: unknown) => boolean;
5
+ export declare const getComponent: ({ block, context, registeredComponents }: {
6
+ block: BuilderBlock;
7
+ context: BuilderContextInterface;
8
+ registeredComponents: RegisteredComponents;
9
+ }) => import("../../context/types.js").RegisteredComponent;
10
+ export declare const getRepeatItemData: ({ block, context }: {
11
+ block: BuilderBlock;
12
+ context: BuilderContextInterface;
13
+ }) => RepeatData[] | undefined;
@@ -0,0 +1,67 @@
1
+ import { evaluate } from '../../functions/evaluate.js';
2
+ import { getProcessedBlock } from '../../functions/get-processed-block.js';
3
+ /**
4
+ * https://developer.mozilla.org/en-US/docs/Glossary/Empty_element
5
+ */
6
+ const EMPTY_HTML_ELEMENTS = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
7
+ export const isEmptyHtmlElement = (tagName) => {
8
+ return typeof tagName === 'string' && EMPTY_HTML_ELEMENTS.includes(tagName.toLowerCase());
9
+ };
10
+ export const getComponent = ({ block, context, registeredComponents }) => {
11
+ const componentName = getProcessedBlock({
12
+ block,
13
+ localState: context.localState,
14
+ rootState: context.rootState,
15
+ rootSetState: context.rootSetState,
16
+ context: context.context,
17
+ shouldEvaluateBindings: false
18
+ }).component?.name;
19
+ if (!componentName) {
20
+ return null;
21
+ }
22
+ const ref = registeredComponents[componentName];
23
+ if (!ref) {
24
+ // TODO: Public doc page with more info about this message
25
+ console.warn(`
26
+ Could not find a registered component named "${componentName}".
27
+ If you registered it, is the file that registered it imported by the file that needs to render it?`);
28
+ return undefined;
29
+ }
30
+ else {
31
+ return ref;
32
+ }
33
+ };
34
+ export const getRepeatItemData = ({ block, context }) => {
35
+ /**
36
+ * we don't use `state.processedBlock` here because the processing done within its logic includes evaluating the block's bindings,
37
+ * which will not work if there is a repeat.
38
+ */
39
+ const { repeat, ...blockWithoutRepeat } = block;
40
+ if (!repeat?.collection) {
41
+ return undefined;
42
+ }
43
+ const itemsArray = evaluate({
44
+ code: repeat.collection,
45
+ localState: context.localState,
46
+ rootState: context.rootState,
47
+ rootSetState: context.rootSetState,
48
+ context: context.context
49
+ });
50
+ if (!Array.isArray(itemsArray)) {
51
+ return undefined;
52
+ }
53
+ const collectionName = repeat.collection.split('.').pop();
54
+ const itemNameToUse = repeat.itemName || (collectionName ? collectionName + 'Item' : 'item');
55
+ const repeatArray = itemsArray.map((item, index) => ({
56
+ context: { ...context,
57
+ localState: { ...context.localState,
58
+ $index: index,
59
+ $item: item,
60
+ [itemNameToUse]: item,
61
+ [`$${itemNameToUse}Index`]: index
62
+ }
63
+ },
64
+ block: blockWithoutRepeat
65
+ }));
66
+ return repeatArray;
67
+ };
@@ -0,0 +1,92 @@
1
+ import * as React from "react";
2
+ import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
3
+ import { getProcessedBlock } from "../../functions/get-processed-block.js";
4
+ import BlockStyles from "./components/block-styles.js";
5
+ import { getComponent, getRepeatItemData, isEmptyHtmlElement, } from "./block.helpers.js";
6
+ import RepeatedBlock from "./components/repeated-block.js";
7
+ import ComponentRef from "./components/component-ref/component-ref.js";
8
+ import BlockWrapper from "./components/block-wrapper.js";
9
+ function Block(props) {
10
+ const blockComponent = function blockComponent() {
11
+ return getComponent({
12
+ block: props.block,
13
+ context: props.context,
14
+ registeredComponents: props.registeredComponents,
15
+ });
16
+ };
17
+ const repeatItem = function repeatItem() {
18
+ return getRepeatItemData({
19
+ block: props.block,
20
+ context: props.context,
21
+ });
22
+ };
23
+ const processedBlock = function processedBlock() {
24
+ return repeatItem()
25
+ ? props.block
26
+ : getProcessedBlock({
27
+ block: props.block,
28
+ localState: props.context.localState,
29
+ rootState: props.context.rootState,
30
+ rootSetState: props.context.rootSetState,
31
+ context: props.context.context,
32
+ shouldEvaluateBindings: true,
33
+ });
34
+ };
35
+ const Tag = function Tag() {
36
+ return props.block.tagName || "div";
37
+ };
38
+ const canShowBlock = function canShowBlock() {
39
+ if ("hide" in processedBlock()) {
40
+ return !processedBlock().hide;
41
+ }
42
+ if ("show" in processedBlock()) {
43
+ return processedBlock().show;
44
+ }
45
+ return true;
46
+ };
47
+ const childrenWithoutParentComponent = function childrenWithoutParentComponent() {
48
+ /**
49
+ * When there is no `componentRef`, there might still be children that need to be rendered. In this case,
50
+ * we render them outside of `componentRef`.
51
+ * NOTE: We make sure not to render this if `repeatItemData` is non-null, because that means we are rendering an array of
52
+ * blocks, and the children will be repeated within those blocks.
53
+ */
54
+ const shouldRenderChildrenOutsideRef = !blockComponent()?.component && !repeatItem();
55
+ return shouldRenderChildrenOutsideRef
56
+ ? processedBlock().children ?? []
57
+ : [];
58
+ };
59
+ const componentRefProps = function componentRefProps() {
60
+ return {
61
+ blockChildren: processedBlock().children ?? [],
62
+ componentRef: blockComponent()?.component,
63
+ componentOptions: {
64
+ ...getBlockComponentOptions(processedBlock()),
65
+ builderContext: props.context,
66
+ ...(blockComponent()?.name === "Symbol" ||
67
+ blockComponent()?.name === "Columns"
68
+ ? {
69
+ builderComponents: props.registeredComponents,
70
+ }
71
+ : {}),
72
+ },
73
+ context: childrenContext,
74
+ registeredComponents: props.registeredComponents,
75
+ builderBlock: processedBlock(),
76
+ includeBlockProps: blockComponent()?.noWrap === true,
77
+ isInteractive: !blockComponent()?.isRSC,
78
+ };
79
+ };
80
+ const childrenContext = props.context;
81
+ return (React.createElement(React.Fragment, null, canShowBlock() ? (React.createElement(React.Fragment, null, !blockComponent()?.noWrap ? (React.createElement(React.Fragment, null,
82
+ isEmptyHtmlElement(Tag()) ? (React.createElement(React.Fragment, null,
83
+ React.createElement(BlockWrapper, { Wrapper: Tag(), block: processedBlock(), context: props.context, hasChildren: false }))) : null,
84
+ !isEmptyHtmlElement(Tag()) && repeatItem() ? (React.createElement(React.Fragment, null, repeatItem()?.map((data, index) => (React.createElement(RepeatedBlock, { key: index, repeatContext: data.context, block: data.block, registeredComponents: props.registeredComponents }))))) : null,
85
+ !isEmptyHtmlElement(Tag()) && !repeatItem() ? (React.createElement(React.Fragment, null,
86
+ React.createElement(BlockWrapper, { Wrapper: Tag(), block: processedBlock(), context: props.context, hasChildren: true },
87
+ React.createElement(ComponentRef, { ...componentRefProps() }),
88
+ childrenWithoutParentComponent()?.map((child) => (React.createElement(Block, { key: "block-" + child.id, block: child, context: childrenContext, registeredComponents: props.registeredComponents }))),
89
+ childrenWithoutParentComponent()?.map((child) => (React.createElement(BlockStyles, { key: "block-style-" + child.id, block: child, context: childrenContext })))))) : null)) : (React.createElement(React.Fragment, null,
90
+ React.createElement(ComponentRef, { ...componentRefProps() }))))) : null));
91
+ }
92
+ export default Block;
@@ -0,0 +1,8 @@
1
+ export type BlockStylesProps = {
2
+ block: BuilderBlock;
3
+ context: BuilderContextInterface;
4
+ };
5
+ import type { BuilderContextInterface } from "../../../context/types.js";
6
+ import type { BuilderBlock } from "../../../types/builder-block.js";
7
+ declare function BlockStyles(props: BlockStylesProps): JSX.Element;
8
+ export default BlockStyles;
@@ -0,0 +1,65 @@
1
+ "use client";
2
+ import * as React from "react";
3
+ import { useState } from "react";
4
+ import { getMaxWidthQueryForSize, getSizesForBreakpoints, } from "../../../constants/device-sizes.js";
5
+ import { TARGET } from "../../../constants/target.js";
6
+ import { getProcessedBlock } from "../../../functions/get-processed-block.js";
7
+ import { createCssClass } from "../../../helpers/css.js";
8
+ import { checkIsDefined } from "../../../helpers/nullable.js";
9
+ import InlinedStyles from "../../inlined-styles.js";
10
+ function BlockStyles(props) {
11
+ const [processedBlock, setProcessedBlock] = useState(() => getProcessedBlock({
12
+ block: props.block,
13
+ localState: props.context.localState,
14
+ rootState: props.context.rootState,
15
+ rootSetState: props.context.rootSetState,
16
+ context: props.context.context,
17
+ shouldEvaluateBindings: true,
18
+ }));
19
+ function canShowBlock() {
20
+ // only render styles for blocks that are visible
21
+ if (checkIsDefined(processedBlock.hide)) {
22
+ return !processedBlock.hide;
23
+ }
24
+ if (checkIsDefined(processedBlock.show)) {
25
+ return processedBlock.show;
26
+ }
27
+ return true;
28
+ }
29
+ function css() {
30
+ const styles = processedBlock.responsiveStyles;
31
+ const content = props.context.content;
32
+ const sizesWithUpdatedBreakpoints = getSizesForBreakpoints(content?.meta?.breakpoints || {});
33
+ const largeStyles = styles?.large;
34
+ const mediumStyles = styles?.medium;
35
+ const smallStyles = styles?.small;
36
+ const className = processedBlock.id;
37
+ if (!className) {
38
+ return "";
39
+ }
40
+ const largeStylesClass = largeStyles
41
+ ? createCssClass({
42
+ className,
43
+ styles: largeStyles,
44
+ })
45
+ : "";
46
+ const mediumStylesClass = mediumStyles
47
+ ? createCssClass({
48
+ className,
49
+ styles: mediumStyles,
50
+ mediaQuery: getMaxWidthQueryForSize("medium", sizesWithUpdatedBreakpoints),
51
+ })
52
+ : "";
53
+ const smallStylesClass = smallStyles
54
+ ? createCssClass({
55
+ className,
56
+ styles: smallStyles,
57
+ mediaQuery: getMaxWidthQueryForSize("small", sizesWithUpdatedBreakpoints),
58
+ })
59
+ : "";
60
+ return [largeStylesClass, mediumStylesClass, smallStylesClass].join(" ");
61
+ }
62
+ return (React.createElement(React.Fragment, null, TARGET !== "reactNative" && css() && canShowBlock() ? (React.createElement(React.Fragment, null,
63
+ React.createElement(InlinedStyles, { styles: css() }))) : null));
64
+ }
65
+ export default BlockStyles;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * This import is used by the Svelte SDK. Do not remove.
3
+ */
4
+ type BlockWrapperProps = {
5
+ Wrapper: string;
6
+ block: BuilderBlock;
7
+ context: BuilderContextInterface;
8
+ hasChildren: boolean;
9
+ };
10
+ /**
11
+ * This component renders a block's wrapper HTML element (from the block's `tagName` property).
12
+ * It reuses the exact same logic as the `InteractiveElement` component, but we need to have 2 separate components for
13
+ * Svelte's sake, as it needs to know at compile-time whether to use: * - `<svelte:element>` (for HTML element) or * - `<svelte:component>` (for custom components) */ import type { PropsWithChildren } from "../../../types/typescript.js";
14
+ import type { BuilderBlock } from "../../../types/builder-block.js";
15
+ import type { BuilderContextInterface } from "../../../context/types.js";
16
+ declare function BlockWrapper(props: PropsWithChildren<BlockWrapperProps>): JSX.Element;
17
+ export default BlockWrapper;
@@ -0,0 +1,36 @@
1
+ "use client";
2
+ import * as React from "react";
3
+ import { getBlockActions } from "../../../functions/get-block-actions.js";
4
+ import { getBlockProperties } from "../../../functions/get-block-properties.js";
5
+ function BlockWrapper(props) {
6
+ return (React.createElement(React.Fragment, null,
7
+ " ",
8
+ props.hasChildren ? (React.createElement(React.Fragment, null,
9
+ React.createElement(props.Wrapper, { ...getBlockProperties({
10
+ block: props.block,
11
+ context: props.context,
12
+ }), ...getBlockActions({
13
+ block: props.block,
14
+ rootState: props.context.rootState,
15
+ rootSetState: props.context.rootSetState,
16
+ localState: props.context.localState,
17
+ context: props.context.context,
18
+ stripPrefix: true,
19
+ }) },
20
+ " ",
21
+ props.children,
22
+ " "))) : (React.createElement(React.Fragment, null,
23
+ React.createElement(props.Wrapper, { ...getBlockProperties({
24
+ block: props.block,
25
+ context: props.context,
26
+ }), ...getBlockActions({
27
+ block: props.block,
28
+ rootState: props.context.rootState,
29
+ rootSetState: props.context.rootSetState,
30
+ localState: props.context.localState,
31
+ context: props.context.context,
32
+ stripPrefix: true,
33
+ }) }))),
34
+ " "));
35
+ }
36
+ export default BlockWrapper;
@@ -0,0 +1,3 @@
1
+ import type { ComponentProps } from "./component-ref.helpers.js";
2
+ declare function ComponentRef(props: ComponentProps): JSX.Element;
3
+ export default ComponentRef;
@@ -0,0 +1,28 @@
1
+ import type { BuilderContextInterface, RegisteredComponents } from '../../../../context/types.js';
2
+ import type { BuilderBlock } from '../../../../types/builder-block.js';
3
+ import type { PropsWithBuilderData } from '../../../../types/builder-props.js';
4
+ import type { InteractiveElementProps } from '../interactive-element.js';
5
+ type ComponentOptions = PropsWithBuilderData<{
6
+ [index: string]: any;
7
+ attributes?: {
8
+ [index: string]: any;
9
+ };
10
+ }>;
11
+ export interface ComponentProps {
12
+ componentRef: any;
13
+ componentOptions: ComponentOptions;
14
+ blockChildren: BuilderBlock[];
15
+ context: BuilderContextInterface;
16
+ registeredComponents: RegisteredComponents;
17
+ builderBlock: BuilderBlock;
18
+ includeBlockProps: boolean;
19
+ isInteractive: boolean | undefined;
20
+ }
21
+ export declare const getWrapperProps: ({ componentOptions, builderBlock, context, componentRef, includeBlockProps, isInteractive, contextValue }: Omit<ComponentProps, "registeredComponents" | "blockChildren"> & {
22
+ contextValue: BuilderContextInterface;
23
+ }) => InteractiveElementProps | {
24
+ attributes?: any;
25
+ builderBlock: BuilderBlock;
26
+ builderContext: BuilderContextInterface;
27
+ };
28
+ export {};
@@ -0,0 +1,21 @@
1
+ import { getBlockProperties } from '../../../../functions/get-block-properties.js';
2
+ export const getWrapperProps = ({ componentOptions, builderBlock, context, componentRef, includeBlockProps, isInteractive, contextValue }) => {
3
+ const interactiveElementProps = {
4
+ Wrapper: componentRef,
5
+ block: builderBlock,
6
+ context,
7
+ wrapperProps: componentOptions
8
+ };
9
+ return isInteractive ? interactiveElementProps : { ...componentOptions,
10
+ /**
11
+ * If `noWrap` is set to `true`, then the block's props/attributes are provided to the
12
+ * component itself directly. Otherwise, they are provided to the wrapper element.
13
+ */
14
+ ...(includeBlockProps ? {
15
+ attributes: getBlockProperties({
16
+ block: builderBlock,
17
+ context: contextValue
18
+ })
19
+ } : {})
20
+ };
21
+ };
@@ -0,0 +1,21 @@
1
+ import * as React from "react";
2
+ import BlockStyles from "../block-styles.js";
3
+ import Block from "../../block.js";
4
+ import InteractiveElement from "../interactive-element.js";
5
+ import { getWrapperProps } from "./component-ref.helpers.js";
6
+ function ComponentRef(props) {
7
+ const Wrapper = props.isInteractive ? InteractiveElement : props.componentRef;
8
+ return (React.createElement(React.Fragment, null, props.componentRef ? (React.createElement(React.Fragment, null,
9
+ React.createElement(Wrapper, { ...getWrapperProps({
10
+ componentOptions: props.componentOptions,
11
+ builderBlock: props.builderBlock,
12
+ context: props.context,
13
+ componentRef: props.componentRef,
14
+ includeBlockProps: props.includeBlockProps,
15
+ isInteractive: props.isInteractive,
16
+ contextValue: props.context,
17
+ }) },
18
+ props.blockChildren?.map((child) => (React.createElement(Block, { key: "block-" + child.id, block: child, context: props.context, registeredComponents: props.registeredComponents }))),
19
+ props.blockChildren?.map((child) => (React.createElement(BlockStyles, { key: "block-style-" + child.id, block: child, context: props.context })))))) : null));
20
+ }
21
+ export default ComponentRef;
@@ -0,0 +1,11 @@
1
+ export type InteractiveElementProps = {
2
+ Wrapper: any;
3
+ block: BuilderBlock;
4
+ context: BuilderContextInterface;
5
+ wrapperProps: object;
6
+ };
7
+ import type { BuilderContextInterface } from "../../../context/types.js";
8
+ import type { BuilderBlock } from "../../../types/builder-block.js";
9
+ import type { PropsWithChildren } from "../../../types/typescript.js";
10
+ declare function InteractiveElement(props: PropsWithChildren<InteractiveElementProps>): JSX.Element;
11
+ export default InteractiveElement;
@@ -0,0 +1,20 @@
1
+ "use client";
2
+ import * as React from "react";
3
+ import { getBlockActions } from "../../../functions/get-block-actions.js";
4
+ import { getBlockProperties } from "../../../functions/get-block-properties.js";
5
+ function InteractiveElement(props) {
6
+ return (React.createElement(props.Wrapper, { ...props.wrapperProps, attributes: {
7
+ ...getBlockProperties({
8
+ block: props.block,
9
+ context: props.context,
10
+ }),
11
+ ...getBlockActions({
12
+ block: props.block,
13
+ rootState: props.context.rootState,
14
+ rootSetState: props.context.rootSetState,
15
+ localState: props.context.localState,
16
+ context: props.context.context,
17
+ }),
18
+ } }, props.children));
19
+ }
20
+ export default InteractiveElement;