@builder.io/sdk-react-native 1.0.33 → 1.0.35
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.
- package/lib/browser/commonjs/blocks/embed/component-info.js +3 -2
- package/lib/browser/commonjs/blocks/embed/component-info.js.map +1 -1
- package/lib/browser/commonjs/blocks/image/component-info.js +1 -1
- package/lib/browser/commonjs/blocks/image/component-info.js.map +1 -1
- package/lib/browser/commonjs/blocks/text/text.js +1 -1
- package/lib/browser/commonjs/constants/sdk-version.js +1 -1
- package/lib/browser/commonjs/functions/evaluate/node-runtime/safeDynamicRequire.js +4 -18
- package/lib/browser/commonjs/functions/evaluate/node-runtime/safeDynamicRequire.js.map +1 -1
- package/lib/browser/commonjs/functions/extract-css-var-default-value.js +19 -0
- package/lib/browser/commonjs/functions/extract-css-var-default-value.js.map +1 -0
- package/lib/browser/commonjs/functions/transform-style-property.js +3 -1
- package/lib/browser/commonjs/functions/transform-style-property.js.map +1 -1
- package/lib/browser/commonjs/helpers/cookie.js +12 -2
- package/lib/browser/commonjs/helpers/cookie.js.map +1 -1
- package/lib/browser/module/blocks/embed/component-info.js +3 -2
- package/lib/browser/module/blocks/embed/component-info.js.map +1 -1
- package/lib/browser/module/blocks/image/component-info.js +1 -1
- package/lib/browser/module/blocks/image/component-info.js.map +1 -1
- package/lib/browser/module/blocks/text/text.js +1 -1
- package/lib/browser/module/blocks/text/text.js.map +1 -1
- package/lib/browser/module/constants/sdk-version.js +1 -1
- package/lib/browser/module/functions/evaluate/node-runtime/safeDynamicRequire.js +5 -18
- package/lib/browser/module/functions/evaluate/node-runtime/safeDynamicRequire.js.map +1 -1
- package/lib/browser/module/functions/extract-css-var-default-value.js +13 -0
- package/lib/browser/module/functions/extract-css-var-default-value.js.map +1 -0
- package/lib/browser/module/functions/transform-style-property.js +3 -1
- package/lib/browser/module/functions/transform-style-property.js.map +1 -1
- package/lib/browser/module/helpers/cookie.js +11 -2
- package/lib/browser/module/helpers/cookie.js.map +1 -1
- package/lib/browser/typescript/constants/sdk-version.d.ts +1 -1
- package/lib/browser/typescript/functions/extract-css-var-default-value.d.ts +2 -0
- package/lib/browser/typescript/functions/extract-css-var-default-value.d.ts.map +1 -0
- package/lib/browser/typescript/functions/transform-style-property.d.ts.map +1 -1
- package/lib/browser/typescript/helpers/cookie.d.ts +1 -0
- package/lib/browser/typescript/helpers/cookie.d.ts.map +1 -1
- package/lib/edge/commonjs/blocks/embed/component-info.js +3 -2
- package/lib/edge/commonjs/blocks/embed/component-info.js.map +1 -1
- package/lib/edge/commonjs/blocks/image/component-info.js +1 -1
- package/lib/edge/commonjs/blocks/image/component-info.js.map +1 -1
- package/lib/edge/commonjs/blocks/text/text.js +1 -1
- package/lib/edge/commonjs/constants/sdk-version.js +1 -1
- package/lib/edge/commonjs/functions/evaluate/node-runtime/safeDynamicRequire.js +4 -18
- package/lib/edge/commonjs/functions/evaluate/node-runtime/safeDynamicRequire.js.map +1 -1
- package/lib/edge/commonjs/functions/extract-css-var-default-value.js +19 -0
- package/lib/edge/commonjs/functions/extract-css-var-default-value.js.map +1 -0
- package/lib/edge/commonjs/functions/transform-style-property.js +3 -1
- package/lib/edge/commonjs/functions/transform-style-property.js.map +1 -1
- package/lib/edge/commonjs/helpers/cookie.js +12 -2
- package/lib/edge/commonjs/helpers/cookie.js.map +1 -1
- package/lib/edge/module/blocks/embed/component-info.js +3 -2
- package/lib/edge/module/blocks/embed/component-info.js.map +1 -1
- package/lib/edge/module/blocks/image/component-info.js +1 -1
- package/lib/edge/module/blocks/image/component-info.js.map +1 -1
- package/lib/edge/module/blocks/text/text.js +1 -1
- package/lib/edge/module/blocks/text/text.js.map +1 -1
- package/lib/edge/module/constants/sdk-version.js +1 -1
- package/lib/edge/module/functions/evaluate/node-runtime/safeDynamicRequire.js +5 -18
- package/lib/edge/module/functions/evaluate/node-runtime/safeDynamicRequire.js.map +1 -1
- package/lib/edge/module/functions/extract-css-var-default-value.js +13 -0
- package/lib/edge/module/functions/extract-css-var-default-value.js.map +1 -0
- package/lib/edge/module/functions/transform-style-property.js +3 -1
- package/lib/edge/module/functions/transform-style-property.js.map +1 -1
- package/lib/edge/module/helpers/cookie.js +11 -2
- package/lib/edge/module/helpers/cookie.js.map +1 -1
- package/lib/edge/typescript/constants/sdk-version.d.ts +1 -1
- package/lib/edge/typescript/functions/extract-css-var-default-value.d.ts +2 -0
- package/lib/edge/typescript/functions/extract-css-var-default-value.d.ts.map +1 -0
- package/lib/edge/typescript/functions/transform-style-property.d.ts.map +1 -1
- package/lib/edge/typescript/helpers/cookie.d.ts +1 -0
- package/lib/edge/typescript/helpers/cookie.d.ts.map +1 -1
- package/lib/node/commonjs/blocks/embed/component-info.js +3 -2
- package/lib/node/commonjs/blocks/embed/component-info.js.map +1 -1
- package/lib/node/commonjs/blocks/image/component-info.js +1 -1
- package/lib/node/commonjs/blocks/image/component-info.js.map +1 -1
- package/lib/node/commonjs/blocks/text/text.js +1 -1
- package/lib/node/commonjs/constants/sdk-version.js +1 -1
- package/lib/node/commonjs/functions/evaluate/node-runtime/safeDynamicRequire.js +4 -18
- package/lib/node/commonjs/functions/evaluate/node-runtime/safeDynamicRequire.js.map +1 -1
- package/lib/node/commonjs/functions/extract-css-var-default-value.js +19 -0
- package/lib/node/commonjs/functions/extract-css-var-default-value.js.map +1 -0
- package/lib/node/commonjs/functions/transform-style-property.js +3 -1
- package/lib/node/commonjs/functions/transform-style-property.js.map +1 -1
- package/lib/node/commonjs/helpers/cookie.js +12 -2
- package/lib/node/commonjs/helpers/cookie.js.map +1 -1
- package/lib/node/module/blocks/embed/component-info.js +3 -2
- package/lib/node/module/blocks/embed/component-info.js.map +1 -1
- package/lib/node/module/blocks/image/component-info.js +1 -1
- package/lib/node/module/blocks/image/component-info.js.map +1 -1
- package/lib/node/module/blocks/text/text.js +1 -1
- package/lib/node/module/blocks/text/text.js.map +1 -1
- package/lib/node/module/constants/sdk-version.js +1 -1
- package/lib/node/module/functions/evaluate/node-runtime/safeDynamicRequire.js +5 -18
- package/lib/node/module/functions/evaluate/node-runtime/safeDynamicRequire.js.map +1 -1
- package/lib/node/module/functions/extract-css-var-default-value.js +13 -0
- package/lib/node/module/functions/extract-css-var-default-value.js.map +1 -0
- package/lib/node/module/functions/transform-style-property.js +3 -1
- package/lib/node/module/functions/transform-style-property.js.map +1 -1
- package/lib/node/module/helpers/cookie.js +11 -2
- package/lib/node/module/helpers/cookie.js.map +1 -1
- package/lib/node/typescript/constants/sdk-version.d.ts +1 -1
- package/lib/node/typescript/functions/extract-css-var-default-value.d.ts +2 -0
- package/lib/node/typescript/functions/extract-css-var-default-value.d.ts.map +1 -0
- package/lib/node/typescript/functions/transform-style-property.d.ts.map +1 -1
- package/lib/node/typescript/helpers/cookie.d.ts +1 -0
- package/lib/node/typescript/helpers/cookie.d.ts.map +1 -1
- package/package.json +10 -7
- package/src/blocks/BaseText.tsx +17 -0
- package/src/blocks/accordion/accordion.tsx +181 -0
- package/src/blocks/accordion/accordion.types.ts +12 -0
- package/src/blocks/accordion/component-info.ts +124 -0
- package/src/blocks/accordion/helpers.ts +3 -0
- package/src/blocks/accordion/index.ts +1 -0
- package/src/blocks/button/button.tsx +56 -0
- package/src/blocks/button/button.types.ts +7 -0
- package/src/blocks/button/component-info.ts +35 -0
- package/src/blocks/button/index.ts +1 -0
- package/src/blocks/columns/columns.tsx +199 -0
- package/src/blocks/columns/columns.types.ts +14 -0
- package/src/blocks/columns/component-info.ts +219 -0
- package/src/blocks/columns/helpers.ts +3 -0
- package/src/blocks/columns/index.ts +1 -0
- package/src/blocks/custom-code/component-info.ts +24 -0
- package/src/blocks/custom-code/custom-code.tsx +71 -0
- package/src/blocks/custom-code/index.ts +1 -0
- package/src/blocks/embed/component-info.ts +40 -0
- package/src/blocks/embed/embed.tsx +62 -0
- package/src/blocks/embed/helpers.ts +2 -0
- package/src/blocks/embed/index.ts +1 -0
- package/src/blocks/form/form/component-info.ts +233 -0
- package/src/blocks/form/form/form.tsx +324 -0
- package/src/blocks/form/form/index.ts +1 -0
- package/src/blocks/form/input/component-info.ts +47 -0
- package/src/blocks/form/input/index.ts +1 -0
- package/src/blocks/form/input/input.tsx +49 -0
- package/src/blocks/form/select/component-info.ts +44 -0
- package/src/blocks/form/select/index.ts +1 -0
- package/src/blocks/form/select/select.tsx +54 -0
- package/src/blocks/form/submit-button/component-info.ts +27 -0
- package/src/blocks/form/submit-button/index.ts +1 -0
- package/src/blocks/form/submit-button/submit-button.tsx +34 -0
- package/src/blocks/fragment/component-info.ts +8 -0
- package/src/blocks/fragment/fragment.tsx +18 -0
- package/src/blocks/fragment/fragment.types.ts +5 -0
- package/src/blocks/fragment/index.ts +1 -0
- package/src/blocks/helpers.ts +43 -0
- package/src/blocks/image/component-info.ts +129 -0
- package/src/blocks/image/image.helpers.ts +47 -0
- package/src/blocks/image/image.tsx +65 -0
- package/src/blocks/image/image.types.ts +20 -0
- package/src/blocks/image/index.ts +1 -0
- package/src/blocks/img/component-info.ts +16 -0
- package/src/blocks/img/img.tsx +55 -0
- package/src/blocks/img/index.ts +1 -0
- package/src/blocks/raw-text/component-info.ts +11 -0
- package/src/blocks/raw-text/index.ts +1 -0
- package/src/blocks/raw-text/raw-text.tsx +1 -0
- package/src/blocks/section/component-info.ts +41 -0
- package/src/blocks/section/index.ts +1 -0
- package/src/blocks/section/section.tsx +39 -0
- package/src/blocks/section/section.types.ts +6 -0
- package/src/blocks/slot/component-info.ts +15 -0
- package/src/blocks/slot/index.ts +1 -0
- package/src/blocks/slot/slot.tsx +42 -0
- package/src/blocks/symbol/component-info.ts +35 -0
- package/src/blocks/symbol/index.ts +1 -0
- package/src/blocks/symbol/symbol.helpers.ts +47 -0
- package/src/blocks/symbol/symbol.tsx +100 -0
- package/src/blocks/symbol/symbol.types.ts +17 -0
- package/src/blocks/tabs/component-info.ts +139 -0
- package/src/blocks/tabs/index.ts +1 -0
- package/src/blocks/tabs/tabs.tsx +79 -0
- package/src/blocks/tabs/tabs.types.ts +13 -0
- package/src/blocks/text/component-info.ts +20 -0
- package/src/blocks/text/index.ts +1 -0
- package/src/blocks/text/text.tsx +105 -0
- package/src/blocks/text/text.types.ts +4 -0
- package/src/blocks/textarea/component-info.ts +38 -0
- package/src/blocks/textarea/index.ts +1 -0
- package/src/blocks/textarea/textarea.tsx +41 -0
- package/src/blocks/video/component-info.ts +83 -0
- package/src/blocks/video/index.ts +1 -0
- package/src/blocks/video/video.tsx +70 -0
- package/src/blocks/video/video.types.ts +21 -0
- package/src/components/block/animator.ts +220 -0
- package/src/components/block/block.helpers.ts +124 -0
- package/src/components/block/block.tsx +232 -0
- package/src/components/block/components/block-styles.tsx +136 -0
- package/src/components/block/components/block-wrapper.tsx +52 -0
- package/src/components/block/components/component-ref/component-ref.helpers.ts +55 -0
- package/src/components/block/components/component-ref/component-ref.tsx +66 -0
- package/src/components/block/components/interactive-element.tsx +53 -0
- package/src/components/block/components/repeated-block.tsx +37 -0
- package/src/components/block/types.ts +6 -0
- package/src/components/blocks/blocks-wrapper.tsx +93 -0
- package/src/components/blocks/blocks.tsx +57 -0
- package/src/components/blocks/blocks.types.ts +7 -0
- package/src/components/blocks/index.ts +1 -0
- package/src/components/content/components/enable-editor.tsx +472 -0
- package/src/components/content/components/styles.helpers.ts +101 -0
- package/src/components/content/components/styles.tsx +42 -0
- package/src/components/content/content.helpers.ts +40 -0
- package/src/components/content/content.tsx +150 -0
- package/src/components/content/content.types.ts +13 -0
- package/src/components/content/contentProps.types.ts +17 -0
- package/src/components/content/index.ts +1 -0
- package/src/components/content/wrap-component-ref.ts +6 -0
- package/src/components/content-variants/content-variants.tsx +146 -0
- package/src/components/content-variants/content-variants.types.ts +84 -0
- package/src/components/content-variants/helpers.ts +72 -0
- package/src/components/content-variants/index.ts +1 -0
- package/src/components/content-variants/inlined-fns.ts +22 -0
- package/src/components/dynamic-div.tsx +30 -0
- package/src/components/dynamic-renderer/dynamic-renderer.helpers.ts +7 -0
- package/src/components/dynamic-renderer/dynamic-renderer.tsx +47 -0
- package/src/components/error-boundary.tsx +38 -0
- package/src/components/inlined-script.tsx +10 -0
- package/src/components/inlined-styles.tsx +10 -0
- package/src/constants/builder-registered-components.ts +59 -0
- package/src/constants/device-sizes.ts +59 -0
- package/src/constants/extra-components.ts +1 -0
- package/src/constants/sdk-version.ts +1 -0
- package/src/constants/target.ts +3 -0
- package/src/context/builder.context.ts +15 -0
- package/src/context/components.context.ts +3 -0
- package/src/context/index.ts +1 -0
- package/src/context/types.ts +38 -0
- package/src/functions/apply-patch-with-mutation.ts +61 -0
- package/src/functions/camel-to-kebab-case.ts +1 -0
- package/src/functions/deopt.ts +6 -0
- package/src/functions/evaluate/browser-runtime/browser.ts +61 -0
- package/src/functions/evaluate/browser-runtime/index.ts +1 -0
- package/src/functions/evaluate/choose-eval.ts +23 -0
- package/src/functions/evaluate/edge-runtime/acorn-interpreter.ts +2891 -0
- package/src/functions/evaluate/edge-runtime/edge-runtime.ts +89 -0
- package/src/functions/evaluate/edge-runtime/index.ts +1 -0
- package/src/functions/evaluate/evaluate.ts +76 -0
- package/src/functions/evaluate/helpers.ts +56 -0
- package/src/functions/evaluate/index.ts +1 -0
- package/src/functions/evaluate/node-runtime/index.ts +1 -0
- package/src/functions/evaluate/node-runtime/init.ts +33 -0
- package/src/functions/evaluate/node-runtime/node-runtime.ts +176 -0
- package/src/functions/evaluate/node-runtime/safeDynamicRequire.ts +14 -0
- package/src/functions/evaluate/placeholder-runtime.ts +4 -0
- package/src/functions/evaluate/should-force-browser-runtime-in-node.ts +16 -0
- package/src/functions/event-handler-name.ts +4 -0
- package/src/functions/extract-css-var-default-value.ts +12 -0
- package/src/functions/extract-text-styles.ts +24 -0
- package/src/functions/fast-clone.ts +4 -0
- package/src/functions/fetch-builder-props.ts +75 -0
- package/src/functions/get-block-actions-handler.ts +17 -0
- package/src/functions/get-block-actions.ts +35 -0
- package/src/functions/get-block-component-options.ts +7 -0
- package/src/functions/get-block-properties.ts +62 -0
- package/src/functions/get-builder-search-params/index.ts +33 -0
- package/src/functions/get-class-prop-name.ts +15 -0
- package/src/functions/get-content/generate-content-url.ts +88 -0
- package/src/functions/get-content/index.ts +99 -0
- package/src/functions/get-content/types.ts +157 -0
- package/src/functions/get-env.ts +5 -0
- package/src/functions/get-fetch.ts +11 -0
- package/src/functions/get-global-this.ts +16 -0
- package/src/functions/get-processed-block.ts +70 -0
- package/src/functions/get-style.ts +38 -0
- package/src/functions/get.ts +4 -0
- package/src/functions/is-browser.ts +3 -0
- package/src/functions/is-edge-runtime.ts +9 -0
- package/src/functions/is-editing.ts +8 -0
- package/src/functions/is-from-trusted-host.ts +11 -0
- package/src/functions/is-iframe.ts +4 -0
- package/src/functions/is-node-runtime.ts +8 -0
- package/src/functions/is-previewing.ts +16 -0
- package/src/functions/on-change.ts +29 -0
- package/src/functions/register-component.ts +30 -0
- package/src/functions/register.ts +44 -0
- package/src/functions/set-editor-settings.ts +15 -0
- package/src/functions/set.ts +14 -0
- package/src/functions/track/helpers.ts +51 -0
- package/src/functions/track/index.ts +131 -0
- package/src/functions/track/interaction.ts +63 -0
- package/src/functions/transform-block-properties.ts +33 -0
- package/src/functions/transform-block.ts +30 -0
- package/src/functions/transform-style-property.ts +298 -0
- package/src/helpers/ab-tests.ts +166 -0
- package/src/helpers/canTrack.ts +2 -0
- package/src/helpers/cookie.ts +109 -0
- package/src/helpers/css.ts +33 -0
- package/src/helpers/flatten.ts +41 -0
- package/src/helpers/localStorage.ts +36 -0
- package/src/helpers/logger.ts +7 -0
- package/src/helpers/nullable.ts +2 -0
- package/src/helpers/omit.ts +7 -0
- package/src/helpers/preview-lru-cache/get.ts +4 -0
- package/src/helpers/preview-lru-cache/helpers.ts +1 -0
- package/src/helpers/preview-lru-cache/init.ts +7 -0
- package/src/helpers/preview-lru-cache/set.ts +12 -0
- package/src/helpers/preview-lru-cache/types.ts +1 -0
- package/src/helpers/search/search.ts +18 -0
- package/src/helpers/sessionId.ts +37 -0
- package/src/helpers/subscribe-to-editor.ts +95 -0
- package/src/helpers/time.ts +2 -0
- package/src/helpers/url.ts +15 -0
- package/src/helpers/uuid.ts +17 -0
- package/src/helpers/visitorId.ts +37 -0
- package/src/index-helpers/blocks-exports.ts +16 -0
- package/src/index-helpers/top-of-file.ts +2 -0
- package/src/index.ts +15 -0
- package/src/scripts/init-editing.ts +119 -0
- package/src/server-index.ts +43 -0
- package/src/types/api-version.ts +2 -0
- package/src/types/builder-block.ts +89 -0
- package/src/types/builder-content.ts +47 -0
- package/src/types/builder-props.ts +12 -0
- package/src/types/can-track.ts +3 -0
- package/src/types/components.ts +119 -0
- package/src/types/deep-partial.ts +1 -0
- package/src/types/element.ts +57 -0
- package/src/types/enforced-partials.ts +19 -0
- package/src/types/input.ts +123 -0
- package/src/types/targets.ts +1 -0
- package/src/types/typescript.ts +9 -0
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import BaseText from "../../blocks/BaseText";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import {
|
|
4
|
+
FlatList,
|
|
5
|
+
ScrollView,
|
|
6
|
+
View,
|
|
7
|
+
StyleSheet,
|
|
8
|
+
Image,
|
|
9
|
+
Text,
|
|
10
|
+
Pressable,
|
|
11
|
+
TextInput,
|
|
12
|
+
} from "react-native";
|
|
13
|
+
import { useEffect } from "react";
|
|
14
|
+
|
|
15
|
+
export type BlockProps = {
|
|
16
|
+
block: BuilderBlock;
|
|
17
|
+
context: BuilderContextInterface;
|
|
18
|
+
registeredComponents: RegisteredComponents;
|
|
19
|
+
linkComponent: any;
|
|
20
|
+
};
|
|
21
|
+
import type {
|
|
22
|
+
BuilderContextInterface,
|
|
23
|
+
RegisteredComponents,
|
|
24
|
+
} from "../../context/types";
|
|
25
|
+
import { getBlockComponentOptions } from "../../functions/get-block-component-options";
|
|
26
|
+
import { getProcessedBlock } from "../../functions/get-processed-block";
|
|
27
|
+
import type { BuilderBlock } from "../../types/builder-block";
|
|
28
|
+
import DynamicDiv from "../dynamic-div";
|
|
29
|
+
import { bindAnimations } from "./animator";
|
|
30
|
+
import {
|
|
31
|
+
getComponent,
|
|
32
|
+
getInheritedStyles,
|
|
33
|
+
getRepeatItemData,
|
|
34
|
+
provideBuilderBlock,
|
|
35
|
+
provideBuilderContext,
|
|
36
|
+
provideLinkComponent,
|
|
37
|
+
provideRegisteredComponents,
|
|
38
|
+
} from "./block.helpers";
|
|
39
|
+
import BlockStyles from "./components/block-styles";
|
|
40
|
+
import BlockWrapper from "./components/block-wrapper";
|
|
41
|
+
import type { ComponentProps } from "./components/component-ref/component-ref.helpers";
|
|
42
|
+
import ComponentRef from "./components/component-ref/component-ref";
|
|
43
|
+
import RepeatedBlock from "./components/repeated-block";
|
|
44
|
+
|
|
45
|
+
function Block(props: BlockProps) {
|
|
46
|
+
function blockComponent() {
|
|
47
|
+
return getComponent({
|
|
48
|
+
block: props.block,
|
|
49
|
+
context: props.context,
|
|
50
|
+
registeredComponents: props.registeredComponents,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function repeatItem() {
|
|
55
|
+
return getRepeatItemData({
|
|
56
|
+
block: props.block,
|
|
57
|
+
context: props.context,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function processedBlock() {
|
|
62
|
+
return props.block.repeat?.collection
|
|
63
|
+
? props.block
|
|
64
|
+
: getProcessedBlock({
|
|
65
|
+
block: props.block,
|
|
66
|
+
localState: props.context.localState,
|
|
67
|
+
rootState: props.context.rootState,
|
|
68
|
+
rootSetState: props.context.rootSetState,
|
|
69
|
+
context: props.context.context,
|
|
70
|
+
shouldEvaluateBindings: true,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function Tag() {
|
|
75
|
+
const shouldUseLink =
|
|
76
|
+
props.block.tagName === "a" ||
|
|
77
|
+
processedBlock().properties?.href ||
|
|
78
|
+
processedBlock().href;
|
|
79
|
+
if (shouldUseLink) {
|
|
80
|
+
return props.linkComponent || BaseText;
|
|
81
|
+
}
|
|
82
|
+
return View;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function canShowBlock() {
|
|
86
|
+
if (props.block.repeat?.collection) {
|
|
87
|
+
if (repeatItem?.()?.length) return true;
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
const shouldHide =
|
|
91
|
+
"hide" in processedBlock() ? processedBlock().hide : false;
|
|
92
|
+
const shouldShow =
|
|
93
|
+
"show" in processedBlock() ? processedBlock().show : true;
|
|
94
|
+
return shouldShow && !shouldHide;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function childrenWithoutParentComponent() {
|
|
98
|
+
/**
|
|
99
|
+
* When there is no `componentRef`, there might still be children that need to be rendered. In this case,
|
|
100
|
+
* we render them outside of `componentRef`.
|
|
101
|
+
* NOTE: We make sure not to render this if `repeatItemData` is non-null, because that means we are rendering an array of
|
|
102
|
+
* blocks, and the children will be repeated within those blocks.
|
|
103
|
+
*/
|
|
104
|
+
const shouldRenderChildrenOutsideRef =
|
|
105
|
+
!blockComponent?.()?.component && !repeatItem();
|
|
106
|
+
return shouldRenderChildrenOutsideRef
|
|
107
|
+
? processedBlock().children ?? []
|
|
108
|
+
: [];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function componentRefProps() {
|
|
112
|
+
return {
|
|
113
|
+
blockChildren: processedBlock().children ?? [],
|
|
114
|
+
componentRef: blockComponent?.()?.component,
|
|
115
|
+
componentOptions: {
|
|
116
|
+
...getBlockComponentOptions(processedBlock()),
|
|
117
|
+
...provideBuilderBlock(blockComponent(), processedBlock()),
|
|
118
|
+
...provideBuilderContext(blockComponent(), props.context),
|
|
119
|
+
...provideLinkComponent(blockComponent(), props.linkComponent),
|
|
120
|
+
...provideRegisteredComponents(
|
|
121
|
+
blockComponent(),
|
|
122
|
+
props.registeredComponents
|
|
123
|
+
),
|
|
124
|
+
},
|
|
125
|
+
context: {
|
|
126
|
+
...props.context,
|
|
127
|
+
inheritedStyles: getInheritedStyles({
|
|
128
|
+
block: processedBlock(),
|
|
129
|
+
context: props.context,
|
|
130
|
+
}),
|
|
131
|
+
} as any,
|
|
132
|
+
linkComponent: props.linkComponent,
|
|
133
|
+
registeredComponents: props.registeredComponents,
|
|
134
|
+
builderBlock: processedBlock(),
|
|
135
|
+
includeBlockProps: blockComponent?.()?.noWrap === true,
|
|
136
|
+
isInteractive: !blockComponent?.()?.isRSC,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
const blockId = processedBlock().id;
|
|
142
|
+
const animations = processedBlock().animations;
|
|
143
|
+
if (animations && blockId) {
|
|
144
|
+
bindAnimations(
|
|
145
|
+
animations.map((animation) => ({
|
|
146
|
+
...animation,
|
|
147
|
+
elementId: blockId,
|
|
148
|
+
}))
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
}, []);
|
|
152
|
+
|
|
153
|
+
return (
|
|
154
|
+
<>
|
|
155
|
+
{canShowBlock() ? (
|
|
156
|
+
<>
|
|
157
|
+
<BlockStyles block={props.block} context={props.context} />
|
|
158
|
+
{!blockComponent?.()?.noWrap ? (
|
|
159
|
+
<>
|
|
160
|
+
{!repeatItem() ? (
|
|
161
|
+
<BlockWrapper
|
|
162
|
+
Wrapper={Tag()}
|
|
163
|
+
block={processedBlock()}
|
|
164
|
+
context={props.context}
|
|
165
|
+
>
|
|
166
|
+
<ComponentRef
|
|
167
|
+
componentRef={componentRefProps().componentRef}
|
|
168
|
+
componentOptions={componentRefProps().componentOptions}
|
|
169
|
+
blockChildren={componentRefProps().blockChildren}
|
|
170
|
+
context={componentRefProps().context}
|
|
171
|
+
registeredComponents={
|
|
172
|
+
componentRefProps().registeredComponents
|
|
173
|
+
}
|
|
174
|
+
linkComponent={componentRefProps().linkComponent}
|
|
175
|
+
builderBlock={componentRefProps().builderBlock}
|
|
176
|
+
includeBlockProps={componentRefProps().includeBlockProps}
|
|
177
|
+
isInteractive={componentRefProps().isInteractive}
|
|
178
|
+
/>
|
|
179
|
+
{childrenWithoutParentComponent()?.map((child) => (
|
|
180
|
+
<Block
|
|
181
|
+
key={child.id}
|
|
182
|
+
block={child}
|
|
183
|
+
registeredComponents={props.registeredComponents}
|
|
184
|
+
linkComponent={props.linkComponent}
|
|
185
|
+
context={
|
|
186
|
+
{
|
|
187
|
+
...props.context,
|
|
188
|
+
inheritedStyles: getInheritedStyles({
|
|
189
|
+
block: processedBlock(),
|
|
190
|
+
context: props.context,
|
|
191
|
+
}),
|
|
192
|
+
} as any
|
|
193
|
+
}
|
|
194
|
+
/>
|
|
195
|
+
))}
|
|
196
|
+
</BlockWrapper>
|
|
197
|
+
) : (
|
|
198
|
+
<>
|
|
199
|
+
{repeatItem()?.map((data, index) => (
|
|
200
|
+
<RepeatedBlock
|
|
201
|
+
key={index}
|
|
202
|
+
repeatContext={data.context}
|
|
203
|
+
block={data.block}
|
|
204
|
+
registeredComponents={props.registeredComponents}
|
|
205
|
+
linkComponent={props.linkComponent}
|
|
206
|
+
/>
|
|
207
|
+
))}
|
|
208
|
+
</>
|
|
209
|
+
)}
|
|
210
|
+
</>
|
|
211
|
+
) : (
|
|
212
|
+
<>
|
|
213
|
+
<ComponentRef
|
|
214
|
+
componentRef={componentRefProps().componentRef}
|
|
215
|
+
componentOptions={componentRefProps().componentOptions}
|
|
216
|
+
blockChildren={componentRefProps().blockChildren}
|
|
217
|
+
context={componentRefProps().context}
|
|
218
|
+
registeredComponents={componentRefProps().registeredComponents}
|
|
219
|
+
linkComponent={componentRefProps().linkComponent}
|
|
220
|
+
builderBlock={componentRefProps().builderBlock}
|
|
221
|
+
includeBlockProps={componentRefProps().includeBlockProps}
|
|
222
|
+
isInteractive={componentRefProps().isInteractive}
|
|
223
|
+
/>
|
|
224
|
+
</>
|
|
225
|
+
)}
|
|
226
|
+
</>
|
|
227
|
+
) : null}
|
|
228
|
+
</>
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export default Block;
|