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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (262) hide show
  1. package/lib/browser/commonjs/blocks/text/text.js +1 -1
  2. package/lib/browser/commonjs/constants/sdk-version.js +1 -1
  3. package/lib/browser/commonjs/functions/evaluate/node-runtime/safeDynamicRequire.js +4 -18
  4. package/lib/browser/commonjs/functions/evaluate/node-runtime/safeDynamicRequire.js.map +1 -1
  5. package/lib/browser/commonjs/helpers/cookie.js +12 -2
  6. package/lib/browser/commonjs/helpers/cookie.js.map +1 -1
  7. package/lib/browser/module/blocks/text/text.js +1 -1
  8. package/lib/browser/module/blocks/text/text.js.map +1 -1
  9. package/lib/browser/module/constants/sdk-version.js +1 -1
  10. package/lib/browser/module/functions/evaluate/node-runtime/safeDynamicRequire.js +5 -18
  11. package/lib/browser/module/functions/evaluate/node-runtime/safeDynamicRequire.js.map +1 -1
  12. package/lib/browser/module/helpers/cookie.js +11 -2
  13. package/lib/browser/module/helpers/cookie.js.map +1 -1
  14. package/lib/browser/typescript/constants/sdk-version.d.ts +1 -1
  15. package/lib/browser/typescript/helpers/cookie.d.ts +1 -0
  16. package/lib/browser/typescript/helpers/cookie.d.ts.map +1 -1
  17. package/lib/edge/commonjs/blocks/text/text.js +1 -1
  18. package/lib/edge/commonjs/constants/sdk-version.js +1 -1
  19. package/lib/edge/commonjs/functions/evaluate/node-runtime/safeDynamicRequire.js +4 -18
  20. package/lib/edge/commonjs/functions/evaluate/node-runtime/safeDynamicRequire.js.map +1 -1
  21. package/lib/edge/commonjs/helpers/cookie.js +12 -2
  22. package/lib/edge/commonjs/helpers/cookie.js.map +1 -1
  23. package/lib/edge/module/blocks/text/text.js +1 -1
  24. package/lib/edge/module/blocks/text/text.js.map +1 -1
  25. package/lib/edge/module/constants/sdk-version.js +1 -1
  26. package/lib/edge/module/functions/evaluate/node-runtime/safeDynamicRequire.js +5 -18
  27. package/lib/edge/module/functions/evaluate/node-runtime/safeDynamicRequire.js.map +1 -1
  28. package/lib/edge/module/helpers/cookie.js +11 -2
  29. package/lib/edge/module/helpers/cookie.js.map +1 -1
  30. package/lib/edge/typescript/constants/sdk-version.d.ts +1 -1
  31. package/lib/edge/typescript/helpers/cookie.d.ts +1 -0
  32. package/lib/edge/typescript/helpers/cookie.d.ts.map +1 -1
  33. package/lib/node/commonjs/blocks/text/text.js +1 -1
  34. package/lib/node/commonjs/constants/sdk-version.js +1 -1
  35. package/lib/node/commonjs/functions/evaluate/node-runtime/safeDynamicRequire.js +4 -18
  36. package/lib/node/commonjs/functions/evaluate/node-runtime/safeDynamicRequire.js.map +1 -1
  37. package/lib/node/commonjs/helpers/cookie.js +12 -2
  38. package/lib/node/commonjs/helpers/cookie.js.map +1 -1
  39. package/lib/node/module/blocks/text/text.js +1 -1
  40. package/lib/node/module/blocks/text/text.js.map +1 -1
  41. package/lib/node/module/constants/sdk-version.js +1 -1
  42. package/lib/node/module/functions/evaluate/node-runtime/safeDynamicRequire.js +5 -18
  43. package/lib/node/module/functions/evaluate/node-runtime/safeDynamicRequire.js.map +1 -1
  44. package/lib/node/module/helpers/cookie.js +11 -2
  45. package/lib/node/module/helpers/cookie.js.map +1 -1
  46. package/lib/node/typescript/constants/sdk-version.d.ts +1 -1
  47. package/lib/node/typescript/helpers/cookie.d.ts +1 -0
  48. package/lib/node/typescript/helpers/cookie.d.ts.map +1 -1
  49. package/package.json +10 -7
  50. package/src/blocks/BaseText.tsx +17 -0
  51. package/src/blocks/accordion/accordion.tsx +181 -0
  52. package/src/blocks/accordion/accordion.types.ts +12 -0
  53. package/src/blocks/accordion/component-info.ts +124 -0
  54. package/src/blocks/accordion/helpers.ts +3 -0
  55. package/src/blocks/accordion/index.ts +1 -0
  56. package/src/blocks/button/button.tsx +56 -0
  57. package/src/blocks/button/button.types.ts +7 -0
  58. package/src/blocks/button/component-info.ts +35 -0
  59. package/src/blocks/button/index.ts +1 -0
  60. package/src/blocks/columns/columns.tsx +199 -0
  61. package/src/blocks/columns/columns.types.ts +14 -0
  62. package/src/blocks/columns/component-info.ts +219 -0
  63. package/src/blocks/columns/helpers.ts +3 -0
  64. package/src/blocks/columns/index.ts +1 -0
  65. package/src/blocks/custom-code/component-info.ts +24 -0
  66. package/src/blocks/custom-code/custom-code.tsx +71 -0
  67. package/src/blocks/custom-code/index.ts +1 -0
  68. package/src/blocks/embed/component-info.ts +38 -0
  69. package/src/blocks/embed/embed.tsx +62 -0
  70. package/src/blocks/embed/helpers.ts +2 -0
  71. package/src/blocks/embed/index.ts +1 -0
  72. package/src/blocks/form/form/component-info.ts +233 -0
  73. package/src/blocks/form/form/form.tsx +324 -0
  74. package/src/blocks/form/form/index.ts +1 -0
  75. package/src/blocks/form/input/component-info.ts +47 -0
  76. package/src/blocks/form/input/index.ts +1 -0
  77. package/src/blocks/form/input/input.tsx +49 -0
  78. package/src/blocks/form/select/component-info.ts +44 -0
  79. package/src/blocks/form/select/index.ts +1 -0
  80. package/src/blocks/form/select/select.tsx +54 -0
  81. package/src/blocks/form/submit-button/component-info.ts +27 -0
  82. package/src/blocks/form/submit-button/index.ts +1 -0
  83. package/src/blocks/form/submit-button/submit-button.tsx +34 -0
  84. package/src/blocks/fragment/component-info.ts +8 -0
  85. package/src/blocks/fragment/fragment.tsx +18 -0
  86. package/src/blocks/fragment/fragment.types.ts +5 -0
  87. package/src/blocks/fragment/index.ts +1 -0
  88. package/src/blocks/helpers.ts +43 -0
  89. package/src/blocks/image/component-info.ts +129 -0
  90. package/src/blocks/image/image.helpers.ts +47 -0
  91. package/src/blocks/image/image.tsx +65 -0
  92. package/src/blocks/image/image.types.ts +20 -0
  93. package/src/blocks/image/index.ts +1 -0
  94. package/src/blocks/img/component-info.ts +16 -0
  95. package/src/blocks/img/img.tsx +55 -0
  96. package/src/blocks/img/index.ts +1 -0
  97. package/src/blocks/raw-text/component-info.ts +11 -0
  98. package/src/blocks/raw-text/index.ts +1 -0
  99. package/src/blocks/raw-text/raw-text.tsx +1 -0
  100. package/src/blocks/section/component-info.ts +41 -0
  101. package/src/blocks/section/index.ts +1 -0
  102. package/src/blocks/section/section.tsx +39 -0
  103. package/src/blocks/section/section.types.ts +6 -0
  104. package/src/blocks/slot/component-info.ts +15 -0
  105. package/src/blocks/slot/index.ts +1 -0
  106. package/src/blocks/slot/slot.tsx +42 -0
  107. package/src/blocks/symbol/component-info.ts +35 -0
  108. package/src/blocks/symbol/index.ts +1 -0
  109. package/src/blocks/symbol/symbol.helpers.ts +47 -0
  110. package/src/blocks/symbol/symbol.tsx +100 -0
  111. package/src/blocks/symbol/symbol.types.ts +17 -0
  112. package/src/blocks/tabs/component-info.ts +139 -0
  113. package/src/blocks/tabs/index.ts +1 -0
  114. package/src/blocks/tabs/tabs.tsx +79 -0
  115. package/src/blocks/tabs/tabs.types.ts +13 -0
  116. package/src/blocks/text/component-info.ts +20 -0
  117. package/src/blocks/text/index.ts +1 -0
  118. package/src/blocks/text/text.tsx +105 -0
  119. package/src/blocks/text/text.types.ts +4 -0
  120. package/src/blocks/textarea/component-info.ts +38 -0
  121. package/src/blocks/textarea/index.ts +1 -0
  122. package/src/blocks/textarea/textarea.tsx +41 -0
  123. package/src/blocks/video/component-info.ts +83 -0
  124. package/src/blocks/video/index.ts +1 -0
  125. package/src/blocks/video/video.tsx +70 -0
  126. package/src/blocks/video/video.types.ts +21 -0
  127. package/src/components/block/animator.ts +220 -0
  128. package/src/components/block/block.helpers.ts +124 -0
  129. package/src/components/block/block.tsx +232 -0
  130. package/src/components/block/components/block-styles.tsx +136 -0
  131. package/src/components/block/components/block-wrapper.tsx +52 -0
  132. package/src/components/block/components/component-ref/component-ref.helpers.ts +55 -0
  133. package/src/components/block/components/component-ref/component-ref.tsx +66 -0
  134. package/src/components/block/components/interactive-element.tsx +53 -0
  135. package/src/components/block/components/repeated-block.tsx +37 -0
  136. package/src/components/block/types.ts +6 -0
  137. package/src/components/blocks/blocks-wrapper.tsx +93 -0
  138. package/src/components/blocks/blocks.tsx +57 -0
  139. package/src/components/blocks/blocks.types.ts +7 -0
  140. package/src/components/blocks/index.ts +1 -0
  141. package/src/components/content/components/enable-editor.tsx +472 -0
  142. package/src/components/content/components/styles.helpers.ts +101 -0
  143. package/src/components/content/components/styles.tsx +42 -0
  144. package/src/components/content/content.helpers.ts +40 -0
  145. package/src/components/content/content.tsx +150 -0
  146. package/src/components/content/content.types.ts +13 -0
  147. package/src/components/content/contentProps.types.ts +17 -0
  148. package/src/components/content/index.ts +1 -0
  149. package/src/components/content/wrap-component-ref.ts +6 -0
  150. package/src/components/content-variants/content-variants.tsx +146 -0
  151. package/src/components/content-variants/content-variants.types.ts +84 -0
  152. package/src/components/content-variants/helpers.ts +72 -0
  153. package/src/components/content-variants/index.ts +1 -0
  154. package/src/components/content-variants/inlined-fns.ts +22 -0
  155. package/src/components/dynamic-div.tsx +30 -0
  156. package/src/components/dynamic-renderer/dynamic-renderer.helpers.ts +7 -0
  157. package/src/components/dynamic-renderer/dynamic-renderer.tsx +47 -0
  158. package/src/components/error-boundary.tsx +38 -0
  159. package/src/components/inlined-script.tsx +10 -0
  160. package/src/components/inlined-styles.tsx +10 -0
  161. package/src/constants/builder-registered-components.ts +59 -0
  162. package/src/constants/device-sizes.ts +59 -0
  163. package/src/constants/extra-components.ts +1 -0
  164. package/src/constants/sdk-version.ts +1 -0
  165. package/src/constants/target.ts +3 -0
  166. package/src/context/builder.context.ts +15 -0
  167. package/src/context/components.context.ts +3 -0
  168. package/src/context/index.ts +1 -0
  169. package/src/context/types.ts +38 -0
  170. package/src/functions/apply-patch-with-mutation.ts +61 -0
  171. package/src/functions/camel-to-kebab-case.ts +1 -0
  172. package/src/functions/deopt.ts +6 -0
  173. package/src/functions/evaluate/browser-runtime/browser.ts +61 -0
  174. package/src/functions/evaluate/browser-runtime/index.ts +1 -0
  175. package/src/functions/evaluate/choose-eval.ts +23 -0
  176. package/src/functions/evaluate/edge-runtime/acorn-interpreter.ts +2891 -0
  177. package/src/functions/evaluate/edge-runtime/edge-runtime.ts +89 -0
  178. package/src/functions/evaluate/edge-runtime/index.ts +1 -0
  179. package/src/functions/evaluate/evaluate.ts +76 -0
  180. package/src/functions/evaluate/helpers.ts +56 -0
  181. package/src/functions/evaluate/index.ts +1 -0
  182. package/src/functions/evaluate/node-runtime/index.ts +1 -0
  183. package/src/functions/evaluate/node-runtime/init.ts +33 -0
  184. package/src/functions/evaluate/node-runtime/node-runtime.ts +176 -0
  185. package/src/functions/evaluate/node-runtime/safeDynamicRequire.ts +14 -0
  186. package/src/functions/evaluate/placeholder-runtime.ts +4 -0
  187. package/src/functions/evaluate/should-force-browser-runtime-in-node.ts +16 -0
  188. package/src/functions/event-handler-name.ts +4 -0
  189. package/src/functions/extract-text-styles.ts +24 -0
  190. package/src/functions/fast-clone.ts +4 -0
  191. package/src/functions/fetch-builder-props.ts +75 -0
  192. package/src/functions/get-block-actions-handler.ts +17 -0
  193. package/src/functions/get-block-actions.ts +35 -0
  194. package/src/functions/get-block-component-options.ts +7 -0
  195. package/src/functions/get-block-properties.ts +62 -0
  196. package/src/functions/get-builder-search-params/index.ts +33 -0
  197. package/src/functions/get-class-prop-name.ts +15 -0
  198. package/src/functions/get-content/generate-content-url.ts +88 -0
  199. package/src/functions/get-content/index.ts +99 -0
  200. package/src/functions/get-content/types.ts +157 -0
  201. package/src/functions/get-env.ts +5 -0
  202. package/src/functions/get-fetch.ts +11 -0
  203. package/src/functions/get-global-this.ts +16 -0
  204. package/src/functions/get-processed-block.ts +70 -0
  205. package/src/functions/get-style.ts +38 -0
  206. package/src/functions/get.ts +4 -0
  207. package/src/functions/is-browser.ts +3 -0
  208. package/src/functions/is-edge-runtime.ts +9 -0
  209. package/src/functions/is-editing.ts +8 -0
  210. package/src/functions/is-from-trusted-host.ts +11 -0
  211. package/src/functions/is-iframe.ts +4 -0
  212. package/src/functions/is-node-runtime.ts +8 -0
  213. package/src/functions/is-previewing.ts +16 -0
  214. package/src/functions/on-change.ts +29 -0
  215. package/src/functions/register-component.ts +30 -0
  216. package/src/functions/register.ts +44 -0
  217. package/src/functions/set-editor-settings.ts +15 -0
  218. package/src/functions/set.ts +14 -0
  219. package/src/functions/track/helpers.ts +51 -0
  220. package/src/functions/track/index.ts +131 -0
  221. package/src/functions/track/interaction.ts +63 -0
  222. package/src/functions/transform-block-properties.ts +33 -0
  223. package/src/functions/transform-block.ts +30 -0
  224. package/src/functions/transform-style-property.ts +296 -0
  225. package/src/helpers/ab-tests.ts +166 -0
  226. package/src/helpers/canTrack.ts +2 -0
  227. package/src/helpers/cookie.ts +109 -0
  228. package/src/helpers/css.ts +33 -0
  229. package/src/helpers/flatten.ts +41 -0
  230. package/src/helpers/localStorage.ts +36 -0
  231. package/src/helpers/logger.ts +7 -0
  232. package/src/helpers/nullable.ts +2 -0
  233. package/src/helpers/omit.ts +7 -0
  234. package/src/helpers/preview-lru-cache/get.ts +4 -0
  235. package/src/helpers/preview-lru-cache/helpers.ts +1 -0
  236. package/src/helpers/preview-lru-cache/init.ts +7 -0
  237. package/src/helpers/preview-lru-cache/set.ts +12 -0
  238. package/src/helpers/preview-lru-cache/types.ts +1 -0
  239. package/src/helpers/search/search.ts +18 -0
  240. package/src/helpers/sessionId.ts +37 -0
  241. package/src/helpers/subscribe-to-editor.ts +95 -0
  242. package/src/helpers/time.ts +2 -0
  243. package/src/helpers/url.ts +15 -0
  244. package/src/helpers/uuid.ts +17 -0
  245. package/src/helpers/visitorId.ts +37 -0
  246. package/src/index-helpers/blocks-exports.ts +16 -0
  247. package/src/index-helpers/top-of-file.ts +2 -0
  248. package/src/index.ts +15 -0
  249. package/src/scripts/init-editing.ts +119 -0
  250. package/src/server-index.ts +43 -0
  251. package/src/types/api-version.ts +2 -0
  252. package/src/types/builder-block.ts +89 -0
  253. package/src/types/builder-content.ts +47 -0
  254. package/src/types/builder-props.ts +12 -0
  255. package/src/types/can-track.ts +3 -0
  256. package/src/types/components.ts +119 -0
  257. package/src/types/deep-partial.ts +1 -0
  258. package/src/types/element.ts +57 -0
  259. package/src/types/enforced-partials.ts +19 -0
  260. package/src/types/input.ts +123 -0
  261. package/src/types/targets.ts +1 -0
  262. package/src/types/typescript.ts +9 -0
@@ -0,0 +1,41 @@
1
+ import * as React from "react";
2
+ import {
3
+ FlatList,
4
+ ScrollView,
5
+ View,
6
+ StyleSheet,
7
+ Image,
8
+ Text,
9
+ Pressable,
10
+ TextInput,
11
+ } from "react-native";
12
+
13
+ /**
14
+ * This import is used by the Svelte SDK. Do not remove.
15
+ */
16
+
17
+ export interface TextareaProps {
18
+ attributes?: any;
19
+ name?: string;
20
+ value?: string;
21
+ defaultValue?: string;
22
+ placeholder?: string;
23
+ }
24
+
25
+ import { filterAttrs } from "../helpers";
26
+ import { setAttrs } from "../helpers";
27
+
28
+ function Textarea(props: TextareaProps) {
29
+ return (
30
+ <View
31
+ {...{}}
32
+ {...props.attributes}
33
+ placeholder={props.placeholder}
34
+ name={props.name}
35
+ value={props.value}
36
+ defaultValue={props.defaultValue}
37
+ />
38
+ );
39
+ }
40
+
41
+ export default Textarea;
@@ -0,0 +1,83 @@
1
+ import type { ComponentInfo } from '../../types/components';
2
+ export const componentInfo: ComponentInfo = {
3
+ name: 'Video',
4
+ canHaveChildren: true,
5
+ defaultStyles: {
6
+ minHeight: '20px',
7
+ minWidth: '20px'
8
+ },
9
+ 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',
10
+ inputs: [{
11
+ name: 'video',
12
+ type: 'file',
13
+ allowedFileTypes: ['mp4'],
14
+ bubble: true,
15
+ defaultValue: 'https://cdn.builder.io/o/assets%2FYJIGb4i01jvw0SRdL5Bt%2Fd27731a526464deba0016216f5f9e570%2Fcompressed?apiKey=YJIGb4i01jvw0SRdL5Bt&token=d27731a526464deba0016216f5f9e570&alt=media&optimized=true',
16
+ required: true
17
+ }, {
18
+ name: 'posterImage',
19
+ type: 'file',
20
+ allowedFileTypes: ['jpeg', 'png'],
21
+ helperText: 'Image to show before the video plays'
22
+ }, {
23
+ name: 'autoPlay',
24
+ type: 'boolean',
25
+ defaultValue: true
26
+ }, {
27
+ name: 'controls',
28
+ type: 'boolean',
29
+ defaultValue: false
30
+ }, {
31
+ name: 'muted',
32
+ type: 'boolean',
33
+ defaultValue: true
34
+ }, {
35
+ name: 'loop',
36
+ type: 'boolean',
37
+ defaultValue: true
38
+ }, {
39
+ name: 'playsInline',
40
+ type: 'boolean',
41
+ defaultValue: true
42
+ }, {
43
+ name: 'fit',
44
+ type: 'text',
45
+ defaultValue: 'cover',
46
+ enum: ['contain', 'cover', 'fill', 'auto']
47
+ }, {
48
+ name: 'preload',
49
+ type: 'text',
50
+ defaultValue: 'metadata',
51
+ enum: ['auto', 'metadata', 'none']
52
+ }, {
53
+ name: 'fitContent',
54
+ type: 'boolean',
55
+ helperText: 'When child blocks are provided, fit to them instead of using the aspect ratio',
56
+ defaultValue: true,
57
+ advanced: true
58
+ }, {
59
+ name: 'position',
60
+ type: 'text',
61
+ defaultValue: 'center',
62
+ enum: ['center', 'top', 'left', 'right', 'bottom', 'top left', 'top right', 'bottom left', 'bottom right']
63
+ }, {
64
+ name: 'height',
65
+ type: 'number',
66
+ advanced: true
67
+ }, {
68
+ name: 'width',
69
+ type: 'number',
70
+ advanced: true
71
+ }, {
72
+ name: 'aspectRatio',
73
+ type: 'number',
74
+ advanced: true,
75
+ defaultValue: 0.7004048582995948
76
+ }, {
77
+ name: 'lazyLoad',
78
+ type: 'boolean',
79
+ helperText: 'Load this video "lazily" - as in only when a user scrolls near the video. Recommended for optmized performance and bandwidth consumption',
80
+ defaultValue: true,
81
+ advanced: true
82
+ }]
83
+ }
@@ -0,0 +1 @@
1
+ export { default } from './video'
@@ -0,0 +1,70 @@
1
+ // TO-DO: This file breaks due to this issue:
2
+ // https://github.com/expo/web-examples/issues/73
3
+ // For now, we do not import it elsewhere to avoid crashing Expo servers on web when importing the SDK.
4
+ import * as React from 'react';
5
+ import { View } from 'react-native';
6
+ import ReactVideo from 'react-native-video';
7
+
8
+ // Subset of Image props, many are irrelevant for native (such as altText, etc)
9
+ /**
10
+ *
11
+ * @typedef {{
12
+ * attributes?: any;
13
+ * video?: string;
14
+ * autoPlay?: boolean;
15
+ * controls?: boolean;
16
+ * muted?: boolean;
17
+ * loop?: boolean;
18
+ * playsInline?: boolean;
19
+ * aspectRatio?: number;
20
+ * fit?: 'contain' | 'cover' | 'stretch';
21
+ * position?:
22
+ * | 'center'
23
+ * | 'top'
24
+ * | 'left'
25
+ * | 'right'
26
+ * | 'bottom'
27
+ * | 'top left'
28
+ * | 'top right'
29
+ * | 'bottom left'
30
+ * | 'bottom right';
31
+ * posterImage?: string;
32
+ * children?: any;
33
+ * }} VideoProps
34
+ */
35
+
36
+ // TODO: support children by wrapping in a View
37
+
38
+ /**
39
+ * @param {VideoProps} props
40
+ */
41
+ export default function Video(props) {
42
+ return (
43
+ <View style={{ position: 'relative' }}>
44
+ <ReactVideo
45
+ paused={!props.autoPlay}
46
+ controls={props.controls}
47
+ muted={props.muted}
48
+ repeat={props.loop}
49
+ poster={props.posterImage}
50
+ posterResizeMode={props.fit || 'contain'}
51
+ resizeMode={props.fit || ('contain')}
52
+ style={{
53
+ position: 'absolute',
54
+ top: 0,
55
+ bottom: 0,
56
+ left: 0,
57
+ right: 0,
58
+ zIndex: 1,
59
+ }}
60
+ source={{ uri: props.video }}
61
+ />
62
+ <View
63
+ style={{
64
+ width: '100%',
65
+ paddingTop: `${props.aspectRatio * 100}%`,
66
+ }}
67
+ />
68
+ </View>
69
+ );
70
+ }
@@ -0,0 +1,21 @@
1
+ import type { BuilderBlock } from '../../types/builder-block';
2
+ export interface VideoProps {
3
+ attributes?: any;
4
+ video?: string;
5
+ autoPlay?: boolean;
6
+ controls?: boolean;
7
+ muted?: boolean;
8
+ loop?: boolean;
9
+ playsInline?: boolean;
10
+ aspectRatio?: number;
11
+ width?: number;
12
+ height?: number;
13
+ fit?: 'contain' | 'cover' | 'fill';
14
+ preload?: 'auto' | 'metadata' | 'none';
15
+ position?: 'center' | 'top' | 'left' | 'right' | 'bottom' | 'top left' | 'top right' | 'bottom left' | 'bottom right';
16
+ posterImage?: string;
17
+ lazyLoad?: boolean;
18
+ children?: any;
19
+ fitContent?: boolean;
20
+ builderBlock?: BuilderBlock;
21
+ }
@@ -0,0 +1,220 @@
1
+ import { camelToKebabCase } from '../../functions/camel-to-kebab-case';
2
+ import type { BuilderAnimation } from '../../types/builder-block';
3
+
4
+ // eslint-disable-next-line @typescript-eslint/ban-types
5
+ function throttle(func: Function, wait: number, options: any = {}) {
6
+ let context: any;
7
+ let args: any;
8
+ let result: any;
9
+ let timeout = (null as any);
10
+ let previous = 0;
11
+ const later = function () {
12
+ previous = options.leading === false ? 0 : Date.now();
13
+ timeout = null;
14
+ result = func.apply(context, args);
15
+ if (!timeout) context = args = null;
16
+ };
17
+ return function (this: any) {
18
+ const now = Date.now();
19
+ if (!previous && options.leading === false) previous = now;
20
+ const remaining = wait - (now - previous);
21
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
22
+ context = this;
23
+ // eslint-disable-next-line prefer-rest-params
24
+ args = arguments;
25
+ if (remaining <= 0 || remaining > wait) {
26
+ if (timeout) {
27
+ clearTimeout(timeout);
28
+ timeout = null;
29
+ }
30
+ previous = now;
31
+ result = func.apply(context, args);
32
+ if (!timeout) context = args = null;
33
+ } else if (!timeout && options.trailing !== false) {
34
+ timeout = setTimeout(later, remaining);
35
+ }
36
+ return result;
37
+ };
38
+ }
39
+ function assign(target: object, ..._args: any[]) {
40
+ const to = Object(target);
41
+ for (let index = 1; index < arguments.length; index++) {
42
+ // eslint-disable-next-line prefer-rest-params
43
+ const nextSource = arguments[index];
44
+ if (nextSource != null) {
45
+ // Skip over if undefined or null
46
+ for (const nextKey in nextSource) {
47
+ // Avoid bugs when hasOwnProperty is shadowed
48
+ if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
49
+ to[nextKey] = nextSource[nextKey];
50
+ }
51
+ }
52
+ }
53
+ }
54
+ return to;
55
+ }
56
+ export function bindAnimations(animations: BuilderAnimation[]) {
57
+ for (const animation of animations) {
58
+ switch (animation.trigger) {
59
+ case 'pageLoad':
60
+ triggerAnimation(animation);
61
+ break;
62
+ case 'scrollInView':
63
+ bindScrollInViewAnimation(animation);
64
+ break;
65
+ }
66
+ }
67
+ }
68
+ function warnElementNotPresent(id: string) {
69
+ console.warn(`Cannot animate element: element with ID ${id} not found!`);
70
+ }
71
+ function augmentAnimation(animation: BuilderAnimation, element: HTMLElement) {
72
+ const stylesUsed = getAllStylesUsed(animation);
73
+ const computedStyle: any = getComputedStyle(element);
74
+ // const computedStyle = getComputedStyle(element);
75
+ // // FIXME: this will break if original load is in one reponsive size then resize to another hmmm
76
+ // Need to use transform instead of left since left can change on screen sizes
77
+ const firstStyles = animation.steps[0].styles;
78
+ const lastStyles = animation.steps[animation.steps.length - 1]!.styles;
79
+ const bothStyles = [firstStyles, lastStyles];
80
+
81
+ // FIXME: this won't work as expected for augmented animations - may need the editor itself to manage this
82
+ for (const styles of bothStyles) {
83
+ for (const style of stylesUsed) {
84
+ if (!(style in styles)) {
85
+ styles[(style as any)] = computedStyle[style];
86
+ }
87
+ }
88
+ }
89
+ }
90
+ function getAllStylesUsed(animation: BuilderAnimation) {
91
+ const properties: (keyof CSSStyleDeclaration)[] = [];
92
+ for (const step of animation.steps) {
93
+ for (const key in step.styles) {
94
+ if (properties.indexOf((key as any)) === -1) {
95
+ properties.push((key as any));
96
+ }
97
+ }
98
+ }
99
+ return properties;
100
+ }
101
+ export function triggerAnimation(animation: BuilderAnimation) {
102
+ // TODO: do for ALL elements
103
+ const elements = (Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || '')) as HTMLElement[]);
104
+ if (!elements.length) {
105
+ warnElementNotPresent(animation.elementId || animation.id || '');
106
+ return;
107
+ }
108
+ Array.from(elements).forEach(element => {
109
+ augmentAnimation(animation, element);
110
+ // TODO: do this properly, may have other animations of different properties
111
+
112
+ // TODO: only override the properties
113
+ // TODO: if there is an entrance and hover animation, the transition duration will get effed
114
+ // element.setAttribute('style', '');
115
+
116
+ // const styledUsed = this.getAllStylesUsed(animation);
117
+ element.style.transition = 'none';
118
+ element.style.transitionDelay = '0';
119
+ assign(element.style, animation.steps[0].styles);
120
+ // TODO: queue/batch these timeouts
121
+ // TODO: only include properties explicitly set in the animation
122
+ // using Object.keys(styles)
123
+ setTimeout(() => {
124
+ element.style.transition = `all ${animation.duration}s ${camelToKebabCase(animation.easing)}`;
125
+ if (animation.delay) {
126
+ element.style.transitionDelay = animation.delay + 's';
127
+ }
128
+ assign(element.style, animation.steps[1].styles);
129
+ // TODO: maybe remove/reset transitoin property after animation duration
130
+
131
+ // TODO: queue timers
132
+ setTimeout(() => {
133
+ // TODO: what if has other transition (reset back to what it was)
134
+ element.style.transition = '';
135
+ element.style.transitionDelay = '';
136
+ }, (animation.delay || 0) * 1000 + animation.duration * 1000 + 100);
137
+ });
138
+ });
139
+ }
140
+
141
+ // TODO: unbind on element remove
142
+ export function bindScrollInViewAnimation(animation: BuilderAnimation) {
143
+ // TODO: apply to ALL matching elements
144
+ const elements = (Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || '')) as HTMLElement[]);
145
+ if (!elements.length) {
146
+ warnElementNotPresent(animation.elementId || animation.id || '');
147
+ return;
148
+ }
149
+
150
+ // TODO: if server side rendered and scrolled into view don't animate...
151
+ Array.from(elements).forEach(element => {
152
+ augmentAnimation(animation, element);
153
+ let triggered = false;
154
+ let pendingAnimation = false;
155
+ function immediateOnScroll() {
156
+ if (!triggered && isScrolledIntoView(element)) {
157
+ triggered = true;
158
+ pendingAnimation = true;
159
+ setTimeout(() => {
160
+ assign(element!.style, animation.steps[1].styles);
161
+ if (!animation.repeat) {
162
+ document.removeEventListener('scroll', onScroll);
163
+ }
164
+ setTimeout(() => {
165
+ pendingAnimation = false;
166
+ if (!animation.repeat) {
167
+ element.style.transition = '';
168
+ element.style.transitionDelay = '';
169
+ }
170
+ }, (animation.duration + (animation.delay || 0)) * 1000 + 100);
171
+ });
172
+ } else if (animation.repeat && triggered && !pendingAnimation && !isScrolledIntoView(element)) {
173
+ // we want to repeat the animation every time the the element is out of view and back again
174
+ triggered = false;
175
+ assign(element!.style, animation.steps[0].styles);
176
+ }
177
+ }
178
+
179
+ // TODO: roll all of these in one for more efficiency of checking all the rects
180
+ const onScroll = throttle(immediateOnScroll, 200, {
181
+ leading: false
182
+ });
183
+
184
+ // TODO: fully in view or partially
185
+ function isScrolledIntoView(elem: HTMLElement) {
186
+ const rect = elem.getBoundingClientRect();
187
+ const windowHeight = window.innerHeight;
188
+ const thresholdPercent = (animation.thresholdPercent || 0) / 100;
189
+ const threshold = thresholdPercent * windowHeight;
190
+
191
+ // TODO: partial in view? or what if element is larger than screen itself
192
+ return rect.bottom > threshold && rect.top < windowHeight - threshold // Element is peeking top or bottom
193
+ // (rect.top > 0 && rect.bottom < window.innerHeight) || // element fits within the screen and is fully on screen (not hanging off at all)
194
+ // (rect.top < 0 && rect.bottom > window.innerHeight) // element is larger than the screen and hangs over the top and bottom
195
+ ;
196
+ }
197
+ const defaultState = animation.steps[0].styles;
198
+ function attachDefaultState() {
199
+ assign(element!.style, defaultState);
200
+ }
201
+ attachDefaultState();
202
+
203
+ // TODO: queue/batch these timeouts!
204
+ setTimeout(() => {
205
+ element.style.transition = `all ${animation.duration}s ${camelToKebabCase(animation.easing)}`;
206
+ if (animation.delay) {
207
+ element.style.transitionDelay = animation.delay + 's';
208
+ }
209
+ });
210
+
211
+ // TODO: one listener for everything
212
+ document.addEventListener('scroll', onScroll, ({
213
+ capture: true,
214
+ passive: true
215
+ } as any));
216
+
217
+ // Do an initial check
218
+ immediateOnScroll();
219
+ });
220
+ }
@@ -0,0 +1,124 @@
1
+ import { TARGET } from '../../constants/target';
2
+ import type { BuilderContextInterface, RegisteredComponent, RegisteredComponents } from '../../context/types';
3
+ import { evaluate } from '../../functions/evaluate/index';
4
+ import { extractTextStyles } from '../../functions/extract-text-styles';
5
+ import { getProcessedBlock } from '../../functions/get-processed-block';
6
+ import { getStyle } from '../../functions/get-style';
7
+ import type { BuilderBlock } from '../../types/builder-block';
8
+ import type { RepeatData } from './types';
9
+ export const getComponent = ({
10
+ block,
11
+ context,
12
+ registeredComponents
13
+ }: {
14
+ block: BuilderBlock;
15
+ context: BuilderContextInterface;
16
+ registeredComponents: RegisteredComponents;
17
+ }) => {
18
+ const componentName = getProcessedBlock({
19
+ block,
20
+ localState: context.localState,
21
+ rootState: context.rootState,
22
+ rootSetState: context.rootSetState,
23
+ context: context.context,
24
+ shouldEvaluateBindings: false
25
+ }).component?.name;
26
+ if (!componentName) {
27
+ return null;
28
+ }
29
+ const ref = registeredComponents[componentName];
30
+ if (!ref) {
31
+ // TODO: Public doc page with more info about this message
32
+ console.warn(`
33
+ Could not find a registered component named "${componentName}".
34
+ If you registered it, is the file that registered it imported by the file that needs to render it?`);
35
+ return undefined;
36
+ } else {
37
+ return ref;
38
+ }
39
+ };
40
+ export const getRepeatItemData = ({
41
+ block,
42
+ context
43
+ }: {
44
+ block: BuilderBlock;
45
+ context: BuilderContextInterface;
46
+ }): RepeatData[] | undefined => {
47
+ /**
48
+ * we don't use `state.processedBlock` here because the processing done within its logic includes evaluating the block's bindings,
49
+ * which will not work if there is a repeat.
50
+ */
51
+ const {
52
+ repeat,
53
+ ...blockWithoutRepeat
54
+ } = block;
55
+ if (!repeat?.collection) {
56
+ return undefined;
57
+ }
58
+ const itemsArray = evaluate({
59
+ code: repeat.collection,
60
+ localState: context.localState,
61
+ rootState: context.rootState,
62
+ rootSetState: context.rootSetState,
63
+ context: context.context,
64
+ enableCache: true
65
+ });
66
+ if (!Array.isArray(itemsArray)) {
67
+ return undefined;
68
+ }
69
+ const collectionName = repeat.collection.split('.').pop();
70
+ const itemNameToUse = repeat.itemName || (collectionName ? collectionName + 'Item' : 'item');
71
+ const repeatArray = itemsArray.map<RepeatData>((item, index) => ({
72
+ context: {
73
+ ...context,
74
+ localState: {
75
+ ...context.localState,
76
+ $index: index,
77
+ $item: item,
78
+ [itemNameToUse]: item,
79
+ [`$${itemNameToUse}Index`]: index
80
+ }
81
+ },
82
+ block: blockWithoutRepeat
83
+ }));
84
+ return repeatArray;
85
+ };
86
+ export const getInheritedStyles = ({
87
+ block,
88
+ context
89
+ }: {
90
+ block: BuilderBlock;
91
+ context: BuilderContextInterface;
92
+ }) => {
93
+ const style = getStyle({
94
+ block,
95
+ context
96
+ });
97
+ if (!style) {
98
+ return {};
99
+ }
100
+ return extractTextStyles(style);
101
+ };
102
+ export const provideLinkComponent = (block: RegisteredComponent | null | undefined, linkComponent: any) => {
103
+ return block && (block.isRSC && TARGET === 'rsc' || ['Core:Button', 'Symbol', 'Columns', 'Form:Form', 'Builder: Tabs', 'Builder:Accordion'].includes(block.name)) ? {
104
+ builderLinkComponent: linkComponent
105
+ } : {};
106
+ };
107
+ export const provideRegisteredComponents = (block: RegisteredComponent | null | undefined, registeredComponents: RegisteredComponents) => {
108
+ return block && (block.isRSC && TARGET === 'rsc' || ['Symbol', 'Columns', 'Form:Form', 'Builder: Tabs', 'Builder:Accordion'].includes(block.name)) ? {
109
+ builderComponents: registeredComponents
110
+ } : {};
111
+ };
112
+ export const provideBuilderBlock = (block: RegisteredComponent | null | undefined, builderBlock: BuilderBlock) => {
113
+ /**
114
+ * Our built-in components frequently make use of the block, so we provide all of it under `builderBlock`
115
+ */
116
+ return block && (block.isRSC && TARGET === 'rsc' || TARGET === 'reactNative' && block.name === 'Text' || ['Builder:Accordion', 'Columns', 'Form:Form', 'Builder: Tabs', 'Symbol', 'Image', 'Video'].includes(block.name)) ? {
117
+ builderBlock
118
+ } : {};
119
+ };
120
+ export const provideBuilderContext = (block: RegisteredComponent | null | undefined, context: BuilderContextInterface) => {
121
+ return block && (block.isRSC && TARGET === 'rsc' || ['Builder:Accordion', 'Columns', 'Form:Form', 'Builder: Tabs', 'Symbol', 'Slot'].includes(block.name)) ? {
122
+ builderContext: context
123
+ } : {};
124
+ }