@builder.io/sdk-react-native 0.4.4 → 0.5.0
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/dist/blocks/button/button.js +6 -2
- package/dist/blocks/button/component-info.js +4 -8
- package/dist/blocks/columns/columns.js +19 -23
- package/dist/blocks/columns/component-info.js +27 -48
- package/dist/blocks/custom-code/component-info.js +4 -8
- package/dist/blocks/custom-code/custom-code.js +1 -1
- package/dist/blocks/embed/component-info.js +7 -11
- package/dist/blocks/embed/embed.js +1 -1
- package/dist/blocks/embed/helpers.js +2 -6
- package/dist/blocks/form/component-info.js +33 -69
- package/dist/blocks/form/form.js +2 -203
- package/dist/blocks/fragment/fragment.js +1 -1
- package/dist/blocks/helpers.js +33 -0
- package/dist/blocks/image/component-info.js +21 -47
- package/dist/blocks/image/image.helpers.js +2 -2
- package/dist/blocks/img/component-info.js +2 -4
- package/dist/blocks/img/img.js +2 -1
- package/dist/blocks/input/component-info.js +8 -34
- package/dist/blocks/input/input.js +2 -1
- package/dist/blocks/raw-text/component-info.js +2 -4
- package/dist/blocks/raw-text/raw-text.js +3 -2
- package/dist/blocks/section/component-info.js +5 -10
- package/dist/blocks/section/section.js +2 -1
- package/dist/blocks/select/component-info.js +12 -24
- package/dist/blocks/select/select.js +2 -1
- package/dist/blocks/submit-button/component-info.js +2 -4
- package/dist/blocks/submit-button/submit-button.js +2 -1
- package/dist/blocks/symbol/component-info.js +7 -12
- package/dist/blocks/symbol/symbol.helpers.js +66 -0
- package/dist/blocks/symbol/symbol.js +23 -50
- package/dist/blocks/text/component-info.js +3 -4
- package/dist/blocks/textarea/component-info.js +6 -12
- package/dist/blocks/textarea/textarea.js +2 -1
- package/dist/blocks/video/component-info.js +21 -41
- package/dist/components/block/block.helpers.js +102 -0
- package/dist/components/block/block.js +141 -0
- package/dist/components/block/components/block-styles.js +95 -0
- package/dist/components/block/components/block-wrapper/block-wrapper.js +41 -0
- package/dist/components/block/components/block-wrapper.js +56 -0
- package/dist/components/block/components/component-ref/component-ref.helpers.js +40 -0
- package/dist/components/block/components/component-ref/component-ref.js +63 -0
- package/dist/components/block/components/component-ref.js +81 -0
- package/dist/components/block/components/component.js +41 -0
- package/dist/components/block/components/interactive-element/interactive-element.helpers.js +35 -0
- package/dist/components/block/components/interactive-element/interactive-element.js +36 -0
- package/dist/components/block/components/interactive-element.js +46 -0
- package/dist/components/block/components/repeated-block.js +40 -0
- package/dist/components/block/types.js +1 -0
- package/dist/components/blocks/blocks-wrapper.js +69 -0
- package/dist/components/blocks/blocks.js +41 -0
- package/dist/components/content/builder-editing.js +32 -0
- package/dist/components/content/components/content-styles.helpers.js +55 -0
- package/dist/components/content/components/content-styles.js +61 -0
- package/dist/components/content/components/enable-editor.js +310 -0
- package/dist/components/content/components/styles.helpers.js +55 -0
- package/dist/components/content/components/styles.js +61 -0
- package/dist/components/content/content.helpers.js +49 -0
- package/dist/components/content/content.js +110 -0
- package/dist/components/content/content.types.js +1 -0
- package/dist/components/content/index.js +8 -0
- package/dist/components/content/wrap-component-ref.js +5 -0
- package/dist/components/content-variants/content-variants.js +77 -0
- package/dist/components/content-variants/content-variants.types.js +1 -0
- package/dist/components/content-variants/helpers.js +175 -0
- package/dist/components/inlined-script.js +32 -0
- package/dist/components/{render-inlined-styles.js → inlined-styles.js} +3 -3
- package/dist/components/render-block/block-styles.js +2 -2
- package/dist/components/render-content/components/render-styles.js +2 -2
- package/dist/components/render-content/render-content.js +10 -8
- package/dist/components/render-content-variants/helpers.js +49 -20
- package/dist/components/render-content-variants/render-content-variants.js +29 -24
- package/dist/components/render-content-variants/render-content-variants.types.js +1 -0
- package/dist/constants/device-sizes.js +2 -2
- package/dist/constants/sdk-version.js +1 -1
- package/dist/context/builder.context.js +1 -1
- package/dist/functions/apply-patch-with-mutation.js +75 -0
- package/dist/functions/apply-patch-with-mutation.test.js +55 -0
- package/dist/functions/camel-to-kebab-case.js +1 -1
- package/dist/functions/evaluate/acorn.js +1691 -0
- package/dist/functions/evaluate/evaluate.js +72 -0
- package/dist/functions/evaluate/index.js +5 -0
- package/dist/functions/evaluate/interpreter.js +2903 -0
- package/dist/functions/evaluate/non-node-runtime.js +97 -0
- package/dist/functions/evaluate/types.js +1 -0
- package/dist/functions/evaluate.test.js +12 -6
- package/dist/functions/event-handler-name.js +1 -1
- package/dist/functions/extract-text-styles.js +3 -9
- package/dist/functions/fast-clone.js +1 -1
- package/dist/functions/get-block-actions-handler.js +2 -2
- package/dist/functions/get-block-actions.js +14 -1
- package/dist/functions/get-block-component-options.js +6 -1
- package/dist/functions/get-block-properties.js +21 -8
- package/dist/functions/get-builder-search-params/fn.test.js +3 -3
- package/dist/functions/get-builder-search-params/index.js +4 -4
- package/dist/functions/get-content/generate-content-url.js +12 -5
- package/dist/functions/get-content/generate-content-url.test.js +31 -17
- package/dist/functions/get-content/index.js +36 -12
- package/dist/functions/get-content/processCookies.js +7 -0
- package/dist/functions/get-processed-block.js +8 -3
- package/dist/functions/get-processed-block.test.js +3 -1
- package/dist/functions/get-react-native-block-styles.js +6 -1
- package/dist/functions/is-non-node-server.js +12 -0
- package/dist/functions/on-change.test.js +13 -3
- package/dist/functions/register-component.js +24 -19
- package/dist/functions/sanitize-react-native-block-styles.js +17 -6
- package/dist/functions/set.test.js +9 -3
- package/dist/functions/track/helpers.js +5 -5
- package/dist/functions/track/index.js +29 -18
- package/dist/functions/track/interaction.js +10 -4
- package/dist/functions/transform-block-properties.js +2 -0
- package/dist/helpers/ab-tests.js +38 -14
- package/dist/helpers/canTrack.js +2 -2
- package/dist/helpers/css.js +2 -2
- package/dist/helpers/flatten.js +10 -7
- package/dist/helpers/nullable.js +1 -1
- package/dist/helpers/preview-lru-cache/get.js +11 -0
- package/dist/helpers/preview-lru-cache/helpers.js +13 -0
- package/dist/helpers/preview-lru-cache/init.js +13 -0
- package/dist/helpers/preview-lru-cache/set.js +37 -0
- package/dist/helpers/preview-lru-cache/types.js +1 -0
- package/dist/helpers/sessionId.js +13 -6
- package/dist/helpers/url.js +1 -1
- package/dist/helpers/visitorId.js +4 -1
- package/dist/index-helpers/blocks-exports.js +2 -2
- package/dist/scripts/init-editing.js +61 -46
- package/dist/types/builder-props.js +1 -0
- package/dist/types/enforced-partials.js +1 -0
- package/package.json +2 -2
- package/src/blocks/button/button.jsx +11 -2
- package/src/blocks/button/component-info.js +16 -22
- package/src/blocks/columns/columns.jsx +29 -28
- package/src/blocks/columns/component-info.js +203 -226
- package/src/blocks/custom-code/component-info.js +19 -25
- package/src/blocks/custom-code/custom-code.jsx +1 -1
- package/src/blocks/embed/component-info.js +31 -37
- package/src/blocks/embed/embed.jsx +1 -1
- package/src/blocks/embed/helpers.js +3 -9
- package/src/blocks/form/component-info.js +174 -212
- package/src/blocks/form/form.jsx +3 -247
- package/src/blocks/fragment/component-info.js +1 -3
- package/src/blocks/fragment/fragment.jsx +1 -1
- package/src/blocks/helpers.js +27 -0
- package/src/blocks/image/component-info.js +105 -133
- package/src/blocks/image/image.helpers.js +3 -5
- package/src/blocks/img/component-info.js +8 -12
- package/src/blocks/img/img.jsx +3 -1
- package/src/blocks/input/component-info.js +29 -57
- package/src/blocks/input/input.jsx +3 -1
- package/src/blocks/raw-text/component-info.js +7 -11
- package/src/blocks/raw-text/raw-text.jsx +4 -2
- package/src/blocks/section/component-info.js +24 -31
- package/src/blocks/section/section.jsx +3 -1
- package/src/blocks/select/component-info.js +34 -48
- package/src/blocks/select/select.jsx +3 -1
- package/src/blocks/submit-button/component-info.js +6 -10
- package/src/blocks/submit-button/submit-button.jsx +3 -2
- package/src/blocks/symbol/component-info.js +30 -37
- package/src/blocks/symbol/symbol.helpers.js +60 -0
- package/src/blocks/symbol/symbol.jsx +34 -59
- package/src/blocks/text/component-info.js +10 -13
- package/src/blocks/textarea/component-info.js +22 -30
- package/src/blocks/textarea/textarea.jsx +3 -1
- package/src/blocks/video/component-info.js +74 -96
- package/src/components/{render-block/render-block.helpers.js → block/block.helpers.js} +26 -44
- package/src/components/{render-block/render-block.jsx → block/block.jsx} +68 -81
- package/src/components/{render-block → block/components}/block-styles.jsx +19 -18
- package/src/components/block/components/block-wrapper.jsx +58 -0
- package/src/components/block/components/component-ref/component-ref.helpers.js +41 -0
- package/src/components/block/components/component-ref/component-ref.jsx +72 -0
- package/src/components/block/components/interactive-element.jsx +37 -0
- package/src/components/{render-block/render-repeated-block.jsx → block/components/repeated-block.jsx} +10 -6
- package/src/components/blocks/blocks-wrapper.jsx +74 -0
- package/src/components/blocks/blocks.jsx +51 -0
- package/src/components/{render-content/render-content.jsx → content/components/enable-editor.jsx} +81 -165
- package/src/components/{render-content/components/render-styles.helpers.js → content/components/styles.helpers.js} +6 -7
- package/src/components/{render-content/components/render-styles.jsx → content/components/styles.jsx} +7 -7
- package/src/components/{render-content/render-content.helpers.js → content/content.helpers.js} +15 -15
- package/src/components/content/content.jsx +141 -0
- package/src/components/content/content.types.js +0 -0
- package/src/components/content/index.js +2 -0
- package/src/components/content/wrap-component-ref.js +2 -0
- package/src/components/content-variants/content-variants.jsx +120 -0
- package/src/components/{render-content-variants → content-variants}/helpers.js +58 -41
- package/src/components/inlined-script.jsx +18 -0
- package/src/components/{render-inlined-styles.jsx → inlined-styles.jsx} +3 -3
- package/src/constants/device-sizes.js +6 -6
- package/src/constants/sdk-version.js +1 -1
- package/src/context/builder.context.js +1 -1
- package/src/functions/apply-patch-with-mutation.js +66 -0
- package/src/functions/camel-to-kebab-case.js +2 -4
- package/src/functions/evaluate/acorn.js +1595 -0
- package/src/functions/{evaluate.js → evaluate/evaluate.js} +36 -10
- package/src/functions/evaluate/index.js +2 -0
- package/src/functions/evaluate/interpreter.js +2801 -0
- package/src/functions/evaluate/non-node-runtime.js +92 -0
- package/src/functions/evaluate/types.js +0 -0
- package/src/functions/event-handler-name.js +2 -4
- package/src/functions/extract-text-styles.js +4 -12
- package/src/functions/fast-clone.js +2 -4
- package/src/functions/get-block-actions-handler.js +3 -5
- package/src/functions/get-block-actions.js +15 -4
- package/src/functions/get-block-component-options.js +11 -12
- package/src/functions/get-block-properties.js +29 -19
- package/src/functions/get-builder-search-params/index.js +5 -10
- package/src/functions/get-content/generate-content-url.js +17 -19
- package/src/functions/get-content/index.js +43 -29
- package/src/functions/get-fetch.js +1 -3
- package/src/functions/get-global-this.js +1 -3
- package/src/functions/get-processed-block.js +12 -13
- package/src/functions/get-react-native-block-styles.js +11 -12
- package/src/functions/if-target.js +1 -3
- package/src/functions/is-browser.js +1 -3
- package/src/functions/is-editing.js +1 -3
- package/src/functions/is-iframe.js +1 -3
- package/src/functions/is-non-node-server.js +9 -0
- package/src/functions/is-previewing.js +1 -3
- package/src/functions/on-change.js +1 -4
- package/src/functions/register-component.js +34 -42
- package/src/functions/register.js +1 -3
- package/src/functions/sanitize-react-native-block-styles.js +22 -17
- package/src/functions/set-editor-settings.js +1 -3
- package/src/functions/set.js +1 -3
- package/src/functions/track/helpers.js +3 -5
- package/src/functions/track/index.js +45 -43
- package/src/functions/track/interaction.js +11 -7
- package/src/functions/transform-block-properties.js +2 -0
- package/src/helpers/ab-tests.js +46 -26
- package/src/helpers/canTrack.js +3 -5
- package/src/helpers/css.js +3 -7
- package/src/helpers/flatten.js +15 -18
- package/src/helpers/localStorage.js +1 -4
- package/src/helpers/logger.js +1 -3
- package/src/helpers/nullable.js +2 -4
- package/src/helpers/preview-lru-cache/get.js +8 -0
- package/src/helpers/preview-lru-cache/helpers.js +10 -0
- package/src/helpers/preview-lru-cache/init.js +10 -0
- package/src/helpers/preview-lru-cache/set.js +35 -0
- package/src/helpers/preview-lru-cache/types.js +0 -0
- package/src/helpers/sessionId.js +14 -11
- package/src/helpers/time.js +1 -3
- package/src/helpers/url.js +2 -4
- package/src/helpers/uuid.js +4 -6
- package/src/helpers/visitorId.js +8 -7
- package/src/index-helpers/blocks-exports.js +1 -1
- package/src/index.js +2 -17
- package/src/scripts/init-editing.js +62 -48
- package/src/types/api-version.js +1 -3
- package/src/types/builder-props.js +0 -0
- package/src/types/enforced-partials.js +0 -0
- package/dist/blocks/BaseText.d.ts +0 -6
- package/dist/blocks/button/button.d.ts +0 -9
- package/dist/blocks/button/component-info.d.ts +0 -2
- package/dist/blocks/columns/columns.d.ts +0 -16
- package/dist/blocks/columns/component-info.d.ts +0 -2
- package/dist/blocks/custom-code/component-info.d.ts +0 -2
- package/dist/blocks/custom-code/custom-code.d.ts +0 -5
- package/dist/blocks/embed/component-info.d.ts +0 -2
- package/dist/blocks/embed/embed.d.ts +0 -5
- package/dist/blocks/embed/helpers.d.ts +0 -1
- package/dist/blocks/form/component-info.d.ts +0 -2
- package/dist/blocks/form/form.d.ts +0 -28
- package/dist/blocks/fragment/component-info.d.ts +0 -2
- package/dist/blocks/fragment/fragment.d.ts +0 -8
- package/dist/blocks/image/component-info.d.ts +0 -2
- package/dist/blocks/image/image.d.ts +0 -17
- package/dist/blocks/image/image.helpers.d.ts +0 -1
- package/dist/blocks/img/component-info.d.ts +0 -2
- package/dist/blocks/img/img.d.ts +0 -11
- package/dist/blocks/input/component-info.d.ts +0 -2
- package/dist/blocks/input/input.d.ts +0 -12
- package/dist/blocks/raw-text/component-info.d.ts +0 -2
- package/dist/blocks/raw-text/raw-text.d.ts +0 -5
- package/dist/blocks/section/component-info.d.ts +0 -2
- package/dist/blocks/section/section.d.ts +0 -9
- package/dist/blocks/select/component-info.d.ts +0 -2
- package/dist/blocks/select/select.d.ts +0 -13
- package/dist/blocks/submit-button/component-info.d.ts +0 -2
- package/dist/blocks/submit-button/submit-button.d.ts +0 -7
- package/dist/blocks/symbol/component-info.d.ts +0 -2
- package/dist/blocks/symbol/symbol.d.ts +0 -21
- package/dist/blocks/text/component-info.d.ts +0 -2
- package/dist/blocks/text/text.d.ts +0 -7
- package/dist/blocks/textarea/component-info.d.ts +0 -2
- package/dist/blocks/textarea/textarea.d.ts +0 -10
- package/dist/blocks/util.d.ts +0 -4
- package/dist/blocks/video/component-info.d.ts +0 -2
- package/dist/blocks/video/video.d.ts +0 -31
- package/dist/components/render-block/block-styles.d.ts +0 -9
- package/dist/components/render-block/render-block.d.ts +0 -9
- package/dist/components/render-block/render-block.helpers.d.ts +0 -12
- package/dist/components/render-block/render-component.d.ts +0 -17
- package/dist/components/render-block/render-repeated-block.d.ts +0 -9
- package/dist/components/render-block/types.d.ts +0 -6
- package/dist/components/render-blocks.d.ts +0 -10
- package/dist/components/render-content/builder-editing.d.ts +0 -3
- package/dist/components/render-content/components/render-styles.d.ts +0 -9
- package/dist/components/render-content/components/render-styles.helpers.d.ts +0 -15
- package/dist/components/render-content/index.d.ts +0 -1
- package/dist/components/render-content/render-content.d.ts +0 -4
- package/dist/components/render-content/render-content.helpers.d.ts +0 -7
- package/dist/components/render-content/render-content.types.d.ts +0 -38
- package/dist/components/render-content/wrap-component-ref.d.ts +0 -6
- package/dist/components/render-content-variants/helpers.d.ts +0 -17
- package/dist/components/render-content-variants/render-content-variants.d.ts +0 -5
- package/dist/components/render-inlined-styles.d.ts +0 -7
- package/dist/constants/builder-registered-components.d.ts +0 -6
- package/dist/constants/device-sizes.d.ts +0 -13
- package/dist/constants/sdk-version.d.ts +0 -1
- package/dist/constants/target.d.ts +0 -3
- package/dist/context/builder.context.d.ts +0 -3
- package/dist/context/types.d.ts +0 -35
- package/dist/functions/camel-to-kebab-case.d.ts +0 -1
- package/dist/functions/evaluate.d.ts +0 -7
- package/dist/functions/evaluate.test.d.ts +0 -1
- package/dist/functions/event-handler-name.d.ts +0 -1
- package/dist/functions/extract-text-styles.d.ts +0 -4
- package/dist/functions/fast-clone.d.ts +0 -4
- package/dist/functions/get-block-actions-handler.d.ts +0 -8
- package/dist/functions/get-block-actions.d.ts +0 -9
- package/dist/functions/get-block-component-options.d.ts +0 -2
- package/dist/functions/get-block-properties.d.ts +0 -2
- package/dist/functions/get-builder-search-params/fn.test.d.ts +0 -1
- package/dist/functions/get-builder-search-params/index.d.ts +0 -12
- package/dist/functions/get-content/generate-content-url.d.ts +0 -2
- package/dist/functions/get-content/generate-content-url.test.d.ts +0 -1
- package/dist/functions/get-content/index.d.ts +0 -16
- package/dist/functions/get-content/types.d.ts +0 -51
- package/dist/functions/get-fetch.d.ts +0 -1
- package/dist/functions/get-processed-block.d.ts +0 -10
- package/dist/functions/get-processed-block.test.d.ts +0 -1
- package/dist/functions/get-react-native-block-styles.d.ts +0 -7
- package/dist/functions/if-target.d.ts +0 -7
- package/dist/functions/is-browser.d.ts +0 -1
- package/dist/functions/is-editing.d.ts +0 -1
- package/dist/functions/is-iframe.d.ts +0 -1
- package/dist/functions/is-previewing.d.ts +0 -1
- package/dist/functions/on-change.d.ts +0 -7
- package/dist/functions/on-change.test.d.ts +0 -1
- package/dist/functions/register-component.d.ts +0 -14
- package/dist/functions/register.d.ts +0 -16
- package/dist/functions/sanitize-react-native-block-styles.d.ts +0 -3
- package/dist/functions/set-editor-settings.d.ts +0 -4
- package/dist/functions/set.d.ts +0 -7
- package/dist/functions/set.test.d.ts +0 -1
- package/dist/functions/track/helpers.d.ts +0 -5
- package/dist/functions/track/index.d.ts +0 -51
- package/dist/functions/track/interaction.d.ts +0 -13
- package/dist/functions/transform-block-properties.d.ts +0 -3
- package/dist/functions/transform-block.d.ts +0 -2
- package/dist/helpers/ab-tests.d.ts +0 -9
- package/dist/helpers/canTrack.d.ts +0 -1
- package/dist/helpers/cookie.d.ts +0 -9
- package/dist/helpers/css.d.ts +0 -7
- package/dist/helpers/flatten.d.ts +0 -6
- package/dist/helpers/localStorage.d.ts +0 -9
- package/dist/helpers/logger.d.ts +0 -6
- package/dist/helpers/nullable.d.ts +0 -2
- package/dist/helpers/sessionId.d.ts +0 -6
- package/dist/helpers/time.d.ts +0 -1
- package/dist/helpers/url.d.ts +0 -6
- package/dist/helpers/url.test.d.ts +0 -1
- package/dist/helpers/uuid.d.ts +0 -8
- package/dist/helpers/visitorId.d.ts +0 -6
- package/dist/index-helpers/blocks-exports.d.ts +0 -8
- package/dist/index-helpers/top-of-file.d.ts +0 -1
- package/dist/index.d.ts +0 -15
- package/dist/scripts/init-editing.d.ts +0 -6
- package/dist/types/api-version.d.ts +0 -2
- package/dist/types/builder-block.d.ts +0 -66
- package/dist/types/builder-content.d.ts +0 -44
- package/dist/types/can-track.d.ts +0 -3
- package/dist/types/components.d.ts +0 -105
- package/dist/types/deep-partial.d.ts +0 -3
- package/dist/types/element.d.ts +0 -59
- package/dist/types/input.d.ts +0 -121
- package/dist/types/targets.d.ts +0 -3
- package/dist/types/typescript.d.ts +0 -5
- package/src/blocks/util.js +0 -8
- package/src/components/render-block/render-component.jsx +0 -55
- package/src/components/render-blocks.jsx +0 -101
- package/src/components/render-content/builder-editing.jsx +0 -16
- package/src/components/render-content/index.js +0 -4
- package/src/components/render-content/wrap-component-ref.js +0 -4
- package/src/components/render-content-variants/render-content-variants.jsx +0 -101
- package/src/functions/evaluate.test.js +0 -17
- package/src/functions/get-builder-search-params/fn.test.js +0 -13
- package/src/functions/get-content/generate-content-url.test.js +0 -97
- package/src/functions/get-processed-block.test.js +0 -34
- package/src/functions/on-change.test.js +0 -19
- package/src/functions/set.test.js +0 -16
- package/src/helpers/url.test.js +0 -21
- /package/src/components/{render-block → block}/types.js +0 -0
- /package/src/components/{render-content/render-content.types.js → content-variants/content-variants.types.js} +0 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import {
|
|
4
|
+
FlatList,
|
|
5
|
+
ScrollView,
|
|
6
|
+
View,
|
|
7
|
+
StyleSheet,
|
|
8
|
+
Image,
|
|
9
|
+
Text,
|
|
10
|
+
} from "react-native";
|
|
11
|
+
import { useState, useEffect } from "react";
|
|
12
|
+
import {
|
|
13
|
+
checkShouldRunVariants,
|
|
14
|
+
getScriptString,
|
|
15
|
+
getVariants,
|
|
16
|
+
getVariantsScriptString,
|
|
17
|
+
} from "./helpers.js";
|
|
18
|
+
import ContentComponent from "../content/content";
|
|
19
|
+
import { getDefaultCanTrack } from "../../helpers/canTrack.js";
|
|
20
|
+
import InlinedStyles from "../inlined-styles";
|
|
21
|
+
import { handleABTestingSync } from "../../helpers/ab-tests.js";
|
|
22
|
+
import InlinedScript from "../inlined-script";
|
|
23
|
+
import { TARGET } from "../../constants/target.js";
|
|
24
|
+
|
|
25
|
+
function ContentVariants(props) {
|
|
26
|
+
const [shouldRenderVariants, setShouldRenderVariants] = useState(() =>
|
|
27
|
+
checkShouldRunVariants({
|
|
28
|
+
canTrack: getDefaultCanTrack(props.canTrack),
|
|
29
|
+
content: props.content,
|
|
30
|
+
})
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
function variantScriptStr() {
|
|
34
|
+
return getVariantsScriptString(
|
|
35
|
+
getVariants(props.content).map((value) => ({
|
|
36
|
+
id: value.testVariationId,
|
|
37
|
+
testRatio: value.testRatio,
|
|
38
|
+
})),
|
|
39
|
+
props.content?.id || ""
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function hideVariantsStyleString() {
|
|
44
|
+
return getVariants(props.content)
|
|
45
|
+
.map((value) => `.variant-${value.testVariationId} { display: none; } `)
|
|
46
|
+
.join("");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
/**
|
|
51
|
+
* We unmount the non-winning variants post-hydration in Vue.
|
|
52
|
+
*/
|
|
53
|
+
}, []);
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<>
|
|
57
|
+
{!props.__isNestedRender && TARGET !== "reactNative" ? (
|
|
58
|
+
<>
|
|
59
|
+
<InlinedScript scriptStr={getScriptString()} />
|
|
60
|
+
</>
|
|
61
|
+
) : null}
|
|
62
|
+
|
|
63
|
+
{shouldRenderVariants ? (
|
|
64
|
+
<>
|
|
65
|
+
<InlinedStyles
|
|
66
|
+
id={`variants-styles-${props.content?.id}`}
|
|
67
|
+
styles={hideVariantsStyleString()}
|
|
68
|
+
/>
|
|
69
|
+
<InlinedScript scriptStr={variantScriptStr()} />
|
|
70
|
+
{getVariants(props.content)?.map((variant) => (
|
|
71
|
+
<ContentComponent
|
|
72
|
+
key={variant.testVariationId}
|
|
73
|
+
content={variant}
|
|
74
|
+
showContent={false}
|
|
75
|
+
classNameProp={undefined}
|
|
76
|
+
model={props.model}
|
|
77
|
+
data={props.data}
|
|
78
|
+
context={props.context}
|
|
79
|
+
apiKey={props.apiKey}
|
|
80
|
+
apiVersion={props.apiVersion}
|
|
81
|
+
customComponents={props.customComponents}
|
|
82
|
+
canTrack={props.canTrack}
|
|
83
|
+
locale={props.locale}
|
|
84
|
+
includeRefs={props.includeRefs}
|
|
85
|
+
enrich={props.enrich}
|
|
86
|
+
isSsrAbTest={shouldRenderVariants}
|
|
87
|
+
/>
|
|
88
|
+
))}
|
|
89
|
+
</>
|
|
90
|
+
) : null}
|
|
91
|
+
|
|
92
|
+
<ContentComponent
|
|
93
|
+
{...{}}
|
|
94
|
+
content={
|
|
95
|
+
shouldRenderVariants
|
|
96
|
+
? props.content
|
|
97
|
+
: handleABTestingSync({
|
|
98
|
+
item: props.content,
|
|
99
|
+
canTrack: getDefaultCanTrack(props.canTrack),
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
classNameProp={`variant-${props.content?.id}`}
|
|
103
|
+
showContent={true}
|
|
104
|
+
model={props.model}
|
|
105
|
+
data={props.data}
|
|
106
|
+
context={props.context}
|
|
107
|
+
apiKey={props.apiKey}
|
|
108
|
+
apiVersion={props.apiVersion}
|
|
109
|
+
customComponents={props.customComponents}
|
|
110
|
+
canTrack={props.canTrack}
|
|
111
|
+
locale={props.locale}
|
|
112
|
+
includeRefs={props.includeRefs}
|
|
113
|
+
enrich={props.enrich}
|
|
114
|
+
isSsrAbTest={shouldRenderVariants}
|
|
115
|
+
/>
|
|
116
|
+
</>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export default ContentVariants;
|
|
@@ -1,23 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true,
|
|
11
|
+
value
|
|
12
|
+
}) : obj[key] = value;
|
|
13
|
+
var __spreadValues = (a, b) => {
|
|
14
|
+
for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
15
|
+
if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
18
|
+
return a;
|
|
19
|
+
};
|
|
20
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
|
+
import { TARGET } from "../../constants/target.js";
|
|
22
|
+
import { isBrowser } from "../../functions/is-browser.js";
|
|
23
|
+
const getVariants = content => Object.values((content == null ? void 0 : content.variations) || {}).map(variant => __spreadProps(__spreadValues({}, variant), {
|
|
24
|
+
testVariationId: variant.id,
|
|
25
|
+
id: content == null ? void 0 : content.id
|
|
26
|
+
}));
|
|
4
27
|
const checkShouldRunVariants = ({
|
|
5
28
|
canTrack,
|
|
6
29
|
content
|
|
7
30
|
}) => {
|
|
8
31
|
const hasVariants = getVariants(content).length > 0;
|
|
9
|
-
if (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
if (isBrowser()) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
32
|
+
if (TARGET === "reactNative") return false;
|
|
33
|
+
if (!hasVariants) return false;
|
|
34
|
+
if (!canTrack) return false;
|
|
35
|
+
if (TARGET === "vue2" || TARGET === "vue3") return true;
|
|
36
|
+
if (isBrowser()) return false;
|
|
18
37
|
return true;
|
|
19
38
|
};
|
|
20
39
|
function bldrAbTest(contentId, variants, isHydrationTarget2) {
|
|
40
|
+
var _a;
|
|
21
41
|
function getAndSetVariantId() {
|
|
22
42
|
function setCookie(name, value, days) {
|
|
23
43
|
let expires = "";
|
|
@@ -33,16 +53,14 @@ function bldrAbTest(contentId, variants, isHydrationTarget2) {
|
|
|
33
53
|
const ca = document.cookie.split(";");
|
|
34
54
|
for (let i = 0; i < ca.length; i++) {
|
|
35
55
|
let c = ca[i];
|
|
36
|
-
while (c.charAt(0) === " ")
|
|
37
|
-
|
|
38
|
-
if (c.indexOf(nameEQ) === 0)
|
|
39
|
-
return c.substring(nameEQ.length, c.length);
|
|
56
|
+
while (c.charAt(0) === " ") c = c.substring(1, c.length);
|
|
57
|
+
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
|
|
40
58
|
}
|
|
41
59
|
return null;
|
|
42
60
|
}
|
|
43
61
|
const cookieName = `builder.tests.${contentId}`;
|
|
44
62
|
const variantInCookie = getCookie(cookieName);
|
|
45
|
-
const availableIDs = variants.map(
|
|
63
|
+
const availableIDs = variants.map(vr => vr.id).concat(contentId);
|
|
46
64
|
if (variantInCookie && availableIDs.includes(variantInCookie)) {
|
|
47
65
|
return variantInCookie;
|
|
48
66
|
}
|
|
@@ -61,13 +79,15 @@ function bldrAbTest(contentId, variants, isHydrationTarget2) {
|
|
|
61
79
|
return contentId;
|
|
62
80
|
}
|
|
63
81
|
const winningVariantId = getAndSetVariantId();
|
|
64
|
-
const styleEl = document.
|
|
82
|
+
const styleEl = (_a = document.currentScript) == null ? void 0 : _a.previousElementSibling;
|
|
65
83
|
if (isHydrationTarget2) {
|
|
66
84
|
styleEl.remove();
|
|
67
|
-
const thisScriptEl = document.
|
|
85
|
+
const thisScriptEl = document.currentScript;
|
|
68
86
|
thisScriptEl == null ? void 0 : thisScriptEl.remove();
|
|
69
87
|
} else {
|
|
70
|
-
const newStyleStr = variants.concat({
|
|
88
|
+
const newStyleStr = variants.concat({
|
|
89
|
+
id: contentId
|
|
90
|
+
}).filter(variant => variant.id !== winningVariantId).map(value => {
|
|
71
91
|
return `.variant-${value.id} { display: none; }
|
|
72
92
|
`;
|
|
73
93
|
}).join("");
|
|
@@ -75,6 +95,7 @@ function bldrAbTest(contentId, variants, isHydrationTarget2) {
|
|
|
75
95
|
}
|
|
76
96
|
}
|
|
77
97
|
function bldrCntntScrpt(variantContentId, defaultContentId, isHydrationTarget2) {
|
|
98
|
+
var _a;
|
|
78
99
|
if (!navigator.cookieEnabled) {
|
|
79
100
|
return;
|
|
80
101
|
}
|
|
@@ -83,16 +104,14 @@ function bldrCntntScrpt(variantContentId, defaultContentId, isHydrationTarget2)
|
|
|
83
104
|
const ca = document.cookie.split(";");
|
|
84
105
|
for (let i = 0; i < ca.length; i++) {
|
|
85
106
|
let c = ca[i];
|
|
86
|
-
while (c.charAt(0) === " ")
|
|
87
|
-
|
|
88
|
-
if (c.indexOf(nameEQ) === 0)
|
|
89
|
-
return c.substring(nameEQ.length, c.length);
|
|
107
|
+
while (c.charAt(0) === " ") c = c.substring(1, c.length);
|
|
108
|
+
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
|
|
90
109
|
}
|
|
91
110
|
return null;
|
|
92
111
|
}
|
|
93
112
|
const cookieName = `builder.tests.${defaultContentId}`;
|
|
94
113
|
const variantId = getCookie(cookieName);
|
|
95
|
-
const parentDiv = document.
|
|
114
|
+
const parentDiv = (_a = document.currentScript) == null ? void 0 : _a.parentElement;
|
|
96
115
|
const variantIsDefaultContent = variantContentId === defaultContentId;
|
|
97
116
|
if (variantId === variantContentId) {
|
|
98
117
|
if (variantIsDefaultContent) {
|
|
@@ -113,29 +132,27 @@ function bldrCntntScrpt(variantContentId, defaultContentId, isHydrationTarget2)
|
|
|
113
132
|
}
|
|
114
133
|
return;
|
|
115
134
|
}
|
|
116
|
-
const getIsHydrationTarget =
|
|
135
|
+
const getIsHydrationTarget = target => target === "react" || target === "reactNative";
|
|
117
136
|
const isHydrationTarget = getIsHydrationTarget(TARGET);
|
|
118
|
-
const AB_TEST_FN_NAME = "
|
|
119
|
-
const CONTENT_FN_NAME = "
|
|
120
|
-
const
|
|
137
|
+
const AB_TEST_FN_NAME = "builderIoAbTest";
|
|
138
|
+
const CONTENT_FN_NAME = "builderIoRenderContent";
|
|
139
|
+
const getScriptString = () => {
|
|
121
140
|
const fnStr = bldrAbTest.toString().replace(/\s+/g, " ");
|
|
122
141
|
const fnStr2 = bldrCntntScrpt.toString().replace(/\s+/g, " ");
|
|
123
142
|
return `
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
${AB_TEST_FN_NAME}("${contentId}", ${JSON.stringify(variants)}, ${isHydrationTarget})
|
|
143
|
+
window.${AB_TEST_FN_NAME} = ${fnStr}
|
|
144
|
+
window.${CONTENT_FN_NAME} = ${fnStr2}
|
|
127
145
|
`;
|
|
128
146
|
};
|
|
147
|
+
const getVariantsScriptString = (variants, contentId) => {
|
|
148
|
+
return `
|
|
149
|
+
window.${AB_TEST_FN_NAME}("${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget})`;
|
|
150
|
+
};
|
|
129
151
|
const getRenderContentScriptString = ({
|
|
130
|
-
|
|
131
|
-
|
|
152
|
+
contentId,
|
|
153
|
+
variationId
|
|
132
154
|
}) => {
|
|
133
155
|
return `
|
|
134
|
-
|
|
135
|
-
};
|
|
136
|
-
export {
|
|
137
|
-
checkShouldRunVariants,
|
|
138
|
-
getRenderContentScriptString,
|
|
139
|
-
getVariants,
|
|
140
|
-
getVariantsScriptString
|
|
156
|
+
window.${CONTENT_FN_NAME}("${variationId}", "${contentId}", ${isHydrationTarget})`;
|
|
141
157
|
};
|
|
158
|
+
export { checkShouldRunVariants, getRenderContentScriptString, getScriptString, getVariants, getVariantsScriptString }
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import {
|
|
4
|
+
FlatList,
|
|
5
|
+
ScrollView,
|
|
6
|
+
View,
|
|
7
|
+
StyleSheet,
|
|
8
|
+
Image,
|
|
9
|
+
Text,
|
|
10
|
+
} from "react-native";
|
|
11
|
+
|
|
12
|
+
function InlinedScript(props) {
|
|
13
|
+
return (
|
|
14
|
+
<View dangerouslySetInnerHTML={{ __html: props.scriptStr }} id={props.id} />
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default InlinedScript;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
"use client";
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import {
|
|
4
4
|
FlatList,
|
|
@@ -9,10 +9,10 @@ import {
|
|
|
9
9
|
Text,
|
|
10
10
|
} from "react-native";
|
|
11
11
|
|
|
12
|
-
function
|
|
12
|
+
function InlinedStyles(props) {
|
|
13
13
|
return (
|
|
14
14
|
<View dangerouslySetInnerHTML={{ __html: props.styles }} id={props.id} />
|
|
15
15
|
);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export default
|
|
18
|
+
export default InlinedStyles;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { fastClone } from "../functions/fast-clone";
|
|
1
|
+
import { fastClone } from "../functions/fast-clone.js";
|
|
2
2
|
const SIZES = {
|
|
3
3
|
small: {
|
|
4
4
|
min: 320,
|
|
@@ -17,7 +17,10 @@ const SIZES = {
|
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
19
|
const getMaxWidthQueryForSize = (size, sizeValues = SIZES) => `@media (max-width: ${sizeValues[size].max}px)`;
|
|
20
|
-
const getSizesForBreakpoints = ({
|
|
20
|
+
const getSizesForBreakpoints = ({
|
|
21
|
+
small,
|
|
22
|
+
medium
|
|
23
|
+
}) => {
|
|
21
24
|
const newSizes = fastClone(SIZES);
|
|
22
25
|
if (!small || !medium) {
|
|
23
26
|
return newSizes;
|
|
@@ -42,7 +45,4 @@ const getSizesForBreakpoints = ({ small, medium }) => {
|
|
|
42
45
|
};
|
|
43
46
|
return newSizes;
|
|
44
47
|
};
|
|
45
|
-
export {
|
|
46
|
-
getMaxWidthQueryForSize,
|
|
47
|
-
getSizesForBreakpoints
|
|
48
|
-
};
|
|
48
|
+
export { getMaxWidthQueryForSize, getSizesForBreakpoints }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "0.
|
|
1
|
+
export const SDK_VERSION = "0.5.0"
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
configurable: true,
|
|
8
|
+
writable: true,
|
|
9
|
+
value
|
|
10
|
+
}) : obj[key] = value;
|
|
11
|
+
var __spreadValues = (a, b) => {
|
|
12
|
+
for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
13
|
+
if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
|
|
15
|
+
}
|
|
16
|
+
return a;
|
|
17
|
+
};
|
|
18
|
+
const applyPatchWithMinimalMutationChain = (obj, patch, preserveRoot = false) => {
|
|
19
|
+
if (Object(obj) !== obj) {
|
|
20
|
+
return obj;
|
|
21
|
+
}
|
|
22
|
+
const {
|
|
23
|
+
path,
|
|
24
|
+
op,
|
|
25
|
+
value
|
|
26
|
+
} = patch;
|
|
27
|
+
const pathArr = path.split(/\//);
|
|
28
|
+
if (pathArr[0] === "") {
|
|
29
|
+
pathArr.shift();
|
|
30
|
+
}
|
|
31
|
+
const newObj = preserveRoot ? obj : __spreadValues({}, obj);
|
|
32
|
+
let objPart = newObj;
|
|
33
|
+
for (let i = 0; i < pathArr.length; i++) {
|
|
34
|
+
const isLast = i === pathArr.length - 1;
|
|
35
|
+
const property = pathArr[i];
|
|
36
|
+
if (isLast) {
|
|
37
|
+
if (op === "replace") {
|
|
38
|
+
objPart[property] = value;
|
|
39
|
+
} else if (op === "add") {
|
|
40
|
+
const index = Number(property);
|
|
41
|
+
if (Array.isArray(objPart)) {
|
|
42
|
+
if (property === "-") {
|
|
43
|
+
objPart.push(value);
|
|
44
|
+
} else {
|
|
45
|
+
objPart.splice(index, 0, value);
|
|
46
|
+
}
|
|
47
|
+
} else {
|
|
48
|
+
objPart[property] = value;
|
|
49
|
+
}
|
|
50
|
+
} else if (op === "remove") {
|
|
51
|
+
const index = Number(property);
|
|
52
|
+
if (Array.isArray(objPart)) {
|
|
53
|
+
objPart.splice(index, 1);
|
|
54
|
+
} else {
|
|
55
|
+
delete objPart[property];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
const nextProperty = pathArr[i + 1];
|
|
60
|
+
const newPart = Object(objPart[property]) === objPart[property] ? objPart[property] : String(Number(nextProperty)) === nextProperty ? [] : {};
|
|
61
|
+
objPart = objPart[property] = Array.isArray(newPart) ? [...newPart] : __spreadValues({}, newPart);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return newObj;
|
|
65
|
+
};
|
|
66
|
+
export { applyPatchWithMinimalMutationChain }
|
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
const camelToKebabCase =
|
|
2
|
-
export {
|
|
3
|
-
camelToKebabCase
|
|
4
|
-
};
|
|
1
|
+
const camelToKebabCase = string => string.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
|
|
2
|
+
export { camelToKebabCase }
|