@builder.io/sdk-svelte 0.4.5 → 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/package/--package.json +40 -29
- package/package/CHANGELOG.md +4 -0
- package/package/blocks/BaseText.svelte +1 -1
- package/package/blocks/button/button.svelte +18 -33
- package/package/blocks/button/button.svelte.d.ts +3 -1
- package/package/blocks/button/component-info.d.ts +1 -1
- package/package/blocks/button/component-info.js +9 -13
- package/package/blocks/columns/columns.svelte +12 -18
- package/package/blocks/columns/columns.svelte.d.ts +11 -7
- package/package/blocks/columns/component-info.d.ts +1 -1
- package/package/blocks/columns/component-info.js +62 -83
- package/package/blocks/custom-code/component-info.d.ts +1 -1
- package/package/blocks/custom-code/component-info.js +7 -11
- package/package/blocks/embed/component-info.d.ts +1 -1
- package/package/blocks/embed/component-info.js +8 -15
- package/package/blocks/embed/helpers.js +1 -5
- package/package/blocks/form/component-info.d.ts +1 -1
- package/package/blocks/form/component-info.js +94 -129
- package/package/blocks/form/form.svelte +2 -289
- package/package/blocks/form/form.svelte.d.ts +1 -57
- package/package/blocks/fragment/component-info.d.ts +1 -1
- package/package/blocks/fragment/component-info.js +1 -1
- package/package/blocks/helpers.d.ts +13 -0
- package/package/blocks/helpers.js +40 -0
- package/package/blocks/image/component-info.d.ts +1 -1
- package/package/blocks/image/component-info.js +33 -63
- package/package/blocks/image/image.helpers.js +2 -11
- package/package/blocks/image/image.svelte.d.ts +0 -1
- package/package/blocks/img/component-info.d.ts +1 -1
- package/package/blocks/img/component-info.js +4 -6
- package/package/blocks/img/img.svelte +4 -29
- package/package/blocks/img/img.svelte.d.ts +3 -1
- package/package/blocks/input/component-info.d.ts +1 -1
- package/package/blocks/input/component-info.js +15 -40
- package/package/blocks/input/input.svelte +4 -29
- package/package/blocks/input/input.svelte.d.ts +3 -1
- package/package/blocks/raw-text/component-info.d.ts +1 -1
- package/package/blocks/raw-text/component-info.js +3 -5
- package/package/blocks/raw-text/raw-text.svelte +3 -5
- package/package/blocks/raw-text/raw-text.svelte.d.ts +1 -1
- package/package/blocks/section/component-info.d.ts +1 -1
- package/package/blocks/section/component-info.js +13 -18
- package/package/blocks/section/section.svelte +4 -29
- package/package/blocks/section/section.svelte.d.ts +3 -1
- package/package/blocks/select/component-info.d.ts +1 -1
- package/package/blocks/select/component-info.js +22 -34
- package/package/blocks/select/select.svelte +4 -29
- package/package/blocks/select/select.svelte.d.ts +3 -1
- package/package/blocks/submit-button/component-info.d.ts +1 -1
- package/package/blocks/submit-button/component-info.js +5 -7
- package/package/blocks/submit-button/submit-button.svelte +4 -29
- package/package/blocks/submit-button/submit-button.svelte.d.ts +3 -1
- package/package/blocks/symbol/component-info.d.ts +1 -1
- package/package/blocks/symbol/component-info.js +12 -17
- package/package/blocks/symbol/symbol.helpers.d.ts +14 -0
- package/package/blocks/symbol/symbol.helpers.js +31 -0
- package/package/blocks/symbol/symbol.svelte +37 -87
- package/package/blocks/symbol/symbol.svelte.d.ts +13 -7
- package/package/blocks/text/component-info.d.ts +1 -1
- package/package/blocks/text/component-info.js +6 -7
- package/package/blocks/text/text.svelte +1 -1
- package/package/blocks/textarea/component-info.d.ts +1 -1
- package/package/blocks/textarea/component-info.js +13 -19
- package/package/blocks/textarea/textarea.svelte +4 -29
- package/package/blocks/textarea/textarea.svelte.d.ts +3 -1
- package/package/blocks/video/component-info.d.ts +1 -1
- package/package/blocks/video/component-info.js +35 -55
- package/package/blocks/video/video.svelte +4 -30
- package/package/blocks/video/video.svelte.d.ts +2 -0
- package/package/components/block/block.helpers.d.ts +13 -0
- package/package/components/{render-block/render-block.helpers.js → block/block.helpers.js} +12 -29
- package/package/components/block/block.svelte +135 -0
- package/package/components/block/block.svelte.d.ts +26 -0
- package/package/components/{render-block → block/components}/block-styles.svelte +20 -22
- package/package/components/{render-block → block/components}/block-styles.svelte.d.ts +2 -2
- package/package/components/block/components/block-wrapper.svelte +53 -0
- package/package/components/block/components/block-wrapper.svelte.d.ts +33 -0
- package/package/components/block/components/component-ref/component-ref.helpers.d.ts +36 -0
- package/package/components/block/components/component-ref/component-ref.helpers.js +22 -0
- package/package/components/block/components/component-ref/component-ref.svelte +37 -0
- package/package/components/block/components/component-ref/component-ref.svelte.d.ts +24 -0
- package/package/components/block/components/interactive-element.svelte +29 -0
- package/package/components/block/components/interactive-element.svelte.d.ts +31 -0
- package/package/components/{render-block/render-repeated-block.svelte → block/components/repeated-block.svelte} +4 -3
- package/package/components/block/components/repeated-block.svelte.d.ts +25 -0
- package/package/components/{render-blocks.svelte → blocks/blocks-wrapper.svelte} +3 -20
- package/package/components/blocks/blocks-wrapper.svelte.d.ts +29 -0
- package/package/components/blocks/blocks.svelte +26 -0
- package/package/components/blocks/blocks.svelte.d.ts +28 -0
- package/package/components/{render-content/render-content.svelte → content/components/enable-editor.svelte} +47 -166
- package/package/components/content/components/enable-editor.svelte.d.ts +36 -0
- package/package/components/{render-content/components/render-styles.helpers.d.ts → content/components/styles.helpers.d.ts} +1 -1
- package/package/components/{render-content/components/render-styles.helpers.js → content/components/styles.helpers.js} +3 -4
- package/package/components/{render-content/components/render-styles.svelte → content/components/styles.svelte} +2 -2
- package/package/components/{render-content/components/render-styles.svelte.d.ts → content/components/styles.svelte.d.ts} +5 -5
- package/package/components/content/content.helpers.d.ts +7 -0
- package/package/components/content/content.helpers.js +30 -0
- package/package/components/content/content.svelte +113 -0
- package/package/components/content/content.svelte.d.ts +30 -0
- package/package/components/{render-content/render-content.types.d.ts → content/content.types.d.ts} +4 -4
- package/package/components/content/index.d.ts +1 -0
- package/package/components/content/index.js +1 -0
- package/package/components/{render-content-variants/render-content-variants.svelte → content-variants/content-variants.svelte} +20 -19
- package/package/components/{render-content-variants/render-content-variants.svelte.d.ts → content-variants/content-variants.svelte.d.ts} +6 -6
- package/package/components/{render-content-variants/render-content-variants.types.d.ts → content-variants/content-variants.types.d.ts} +5 -5
- package/package/components/{render-content-variants → content-variants}/helpers.d.ts +7 -7
- package/package/components/{render-content-variants → content-variants}/helpers.js +13 -22
- package/package/constants/builder-registered-components.js +34 -13
- package/package/constants/device-sizes.js +9 -8
- package/package/constants/sdk-version.d.ts +1 -1
- package/package/constants/sdk-version.js +1 -1
- package/package/constants/target.d.ts +1 -1
- package/package/context/builder.context.d.ts +1 -1
- package/package/context/builder.context.js +1 -1
- package/package/context/types.d.ts +1 -1
- package/package/functions/apply-patch-with-mutation.d.ts +10 -0
- package/package/functions/apply-patch-with-mutation.js +54 -0
- package/package/functions/evaluate/acorn.d.ts +0 -0
- package/package/functions/evaluate/acorn.js +2433 -0
- package/package/functions/{evaluate.d.ts → evaluate/evaluate.d.ts} +5 -2
- package/package/functions/{evaluate.js → evaluate/evaluate.js} +34 -13
- package/package/functions/evaluate/index.d.ts +1 -0
- package/package/functions/evaluate/index.js +1 -0
- package/package/functions/evaluate/interpreter.d.ts +2 -0
- package/package/functions/evaluate/interpreter.js +3853 -0
- package/package/functions/evaluate/non-node-runtime.d.ts +2 -0
- package/package/functions/evaluate/non-node-runtime.js +84 -0
- package/package/functions/evaluate/types.d.ts +10 -0
- package/package/functions/extract-text-styles.js +2 -14
- package/package/functions/get-block-actions-handler.js +3 -3
- package/package/functions/get-block-actions.d.ts +1 -0
- package/package/functions/get-block-actions.js +14 -1
- package/package/functions/get-block-component-options.js +1 -1
- package/package/functions/get-block-properties.d.ts +5 -1
- package/package/functions/get-block-properties.js +15 -9
- package/package/functions/get-builder-search-params/index.js +3 -7
- package/package/functions/get-content/generate-content-url.js +7 -5
- package/package/functions/get-content/index.d.ts +2 -6
- package/package/functions/get-content/index.js +26 -6
- package/package/functions/get-processed-block.d.ts +1 -1
- package/package/functions/get-processed-block.js +11 -7
- package/package/functions/get-react-native-block-styles.d.ts +1 -1
- package/package/functions/get-react-native-block-styles.js +2 -2
- package/package/functions/if-target.d.ts +1 -1
- package/package/functions/if-target.js +1 -1
- package/package/functions/is-editing.js +1 -3
- package/package/functions/is-non-node-server.d.ts +4 -0
- package/package/functions/is-non-node-server.js +8 -0
- package/package/functions/on-change.js +1 -1
- package/package/functions/register-component.d.ts +2 -1
- package/package/functions/register-component.js +20 -8
- package/package/functions/register.js +2 -2
- package/package/functions/sanitize-react-native-block-styles.js +13 -5
- package/package/functions/set-editor-settings.js +1 -1
- package/package/functions/set.js +2 -9
- package/package/functions/track/helpers.js +6 -11
- package/package/functions/track/index.js +26 -14
- package/package/functions/track/interaction.js +15 -16
- package/package/helpers/ab-tests.d.ts +2 -2
- package/package/helpers/ab-tests.js +42 -30
- package/package/helpers/canTrack.js +1 -1
- package/package/helpers/cookie.d.ts +2 -2
- package/package/helpers/cookie.js +13 -26
- package/package/helpers/css.d.ts +1 -1
- package/package/helpers/css.js +1 -1
- package/package/helpers/flatten.js +8 -8
- package/package/helpers/localStorage.d.ts +2 -2
- package/package/helpers/localStorage.js +2 -2
- package/package/helpers/logger.js +1 -1
- package/package/helpers/preview-lru-cache/get.d.ts +1 -0
- package/package/helpers/preview-lru-cache/get.js +7 -0
- package/package/helpers/preview-lru-cache/helpers.d.ts +1 -0
- package/package/helpers/preview-lru-cache/helpers.js +9 -0
- package/package/helpers/preview-lru-cache/init.d.ts +6 -0
- package/package/helpers/preview-lru-cache/init.js +15 -0
- package/package/helpers/preview-lru-cache/set.d.ts +7 -0
- package/package/helpers/preview-lru-cache/set.js +9 -0
- package/package/helpers/preview-lru-cache/types.d.ts +12 -0
- package/package/helpers/preview-lru-cache/types.js +6 -0
- package/package/helpers/sessionId.d.ts +2 -2
- package/package/helpers/sessionId.js +11 -4
- package/package/helpers/uuid.js +1 -1
- package/package/helpers/visitorId.d.ts +1 -1
- package/package/helpers/visitorId.js +7 -4
- package/package/index-helpers/blocks-exports.d.ts +2 -2
- package/package/index-helpers/blocks-exports.js +2 -2
- package/package/index.d.ts +2 -2
- package/package/index.js +1 -1
- package/package/scripts/init-editing.js +65 -57
- package/package/types/builder-props.d.ts +10 -0
- package/package/types/components.d.ts +8 -2
- package/package/types/enforced-partials.d.ts +1 -1
- package/package/types/targets.d.ts +1 -3
- package/package/types/typescript.d.ts +3 -0
- package/package.json +2 -2
- package/src/blocks/BaseText.svelte +1 -1
- package/src/blocks/button/button.svelte +21 -34
- package/src/blocks/button/component-info.ts +20 -27
- package/src/blocks/columns/columns.svelte +26 -30
- package/src/blocks/columns/component-info.ts +205 -240
- package/src/blocks/custom-code/component-info.ts +20 -27
- package/src/blocks/embed/component-info.ts +34 -51
- package/src/blocks/embed/helpers.ts +2 -8
- package/src/blocks/form/component-info.ts +204 -253
- package/src/blocks/form/form.svelte +1 -368
- package/src/blocks/fragment/component-info.ts +3 -5
- package/src/blocks/helpers.ts +43 -0
- package/src/blocks/image/component-info.ts +113 -161
- package/src/blocks/image/image.helpers.ts +5 -33
- package/src/blocks/img/component-info.ts +11 -16
- package/src/blocks/img/img.svelte +7 -31
- package/src/blocks/input/component-info.ts +35 -66
- package/src/blocks/input/input.svelte +7 -31
- package/src/blocks/raw-text/component-info.ts +8 -12
- package/src/blocks/raw-text/raw-text.svelte +2 -5
- package/src/blocks/section/component-info.ts +28 -37
- package/src/blocks/section/section.svelte +7 -30
- package/src/blocks/select/component-info.ts +38 -55
- package/src/blocks/select/select.svelte +7 -31
- package/src/blocks/submit-button/component-info.ts +10 -15
- package/src/blocks/submit-button/submit-button.svelte +7 -30
- package/src/blocks/symbol/component-info.ts +31 -39
- package/src/blocks/symbol/symbol.helpers.ts +47 -0
- package/src/blocks/symbol/symbol.svelte +50 -97
- package/src/blocks/text/component-info.ts +14 -18
- package/src/blocks/text/text.svelte +1 -1
- package/src/blocks/textarea/component-info.ts +26 -36
- package/src/blocks/textarea/textarea.svelte +7 -30
- package/src/blocks/video/component-info.ts +77 -103
- package/src/blocks/video/video.svelte +4 -31
- package/src/components/{render-block/render-block.helpers.ts → block/block.helpers.ts} +22 -49
- package/src/components/block/block.svelte +158 -0
- package/src/components/{render-block → block/components}/block-styles.svelte +23 -24
- package/src/components/block/components/block-wrapper.svelte +70 -0
- package/src/components/block/components/component-ref/component-ref.helpers.ts +53 -0
- package/src/components/block/components/component-ref/component-ref.svelte +41 -0
- package/src/components/block/components/interactive-element.svelte +42 -0
- package/src/components/block/components/repeated-block.svelte +30 -0
- package/src/components/{render-block → block}/types.ts +1 -2
- package/src/components/{render-blocks.svelte → blocks/blocks-wrapper.svelte} +14 -32
- package/src/components/blocks/blocks.svelte +39 -0
- package/src/components/{render-content/render-content.svelte → content/components/enable-editor.svelte} +71 -199
- package/src/components/{render-content/components/render-styles.helpers.ts → content/components/styles.helpers.ts} +9 -11
- package/src/components/{render-content/components/render-styles.svelte → content/components/styles.svelte} +3 -3
- package/src/components/content/content.helpers.ts +42 -0
- package/src/components/content/content.svelte +138 -0
- package/src/components/{render-content/render-content.types.ts → content/content.types.ts} +5 -9
- package/src/components/content/index.ts +1 -0
- package/src/components/{render-content → content}/wrap-component-ref.ts +1 -1
- package/src/components/{render-content-variants/render-content-variants.svelte → content-variants/content-variants.svelte} +26 -24
- package/src/components/{render-content-variants/render-content-variants.types.ts → content-variants/content-variants.types.ts} +9 -11
- package/src/components/{render-content-variants → content-variants}/helpers.ts +27 -73
- package/src/constants/builder-registered-components.ts +34 -14
- package/src/constants/device-sizes.ts +16 -22
- package/src/constants/sdk-version.ts +1 -1
- package/src/constants/target.ts +3 -1
- package/src/context/builder.context.ts +1 -1
- package/src/context/types.ts +2 -7
- package/src/functions/apply-patch-with-mutation.ts +61 -0
- package/src/functions/camel-to-kebab-case.ts +1 -2
- package/src/functions/evaluate/acorn.ts +2501 -0
- package/src/functions/evaluate/evaluate.ts +90 -0
- package/src/functions/evaluate/index.ts +1 -0
- package/src/functions/evaluate/interpreter.ts +3887 -0
- package/src/functions/evaluate/non-node-runtime.ts +94 -0
- package/src/functions/evaluate/types.ts +10 -0
- package/src/functions/extract-text-styles.ts +3 -18
- package/src/functions/fast-clone.ts +1 -2
- package/src/functions/get-block-actions-handler.ts +11 -20
- package/src/functions/get-block-actions.ts +22 -14
- package/src/functions/get-block-component-options.ts +2 -3
- package/src/functions/get-block-properties.ts +24 -17
- package/src/functions/get-builder-search-params/index.ts +5 -21
- package/src/functions/get-content/generate-content-url.ts +10 -25
- package/src/functions/get-content/index.ts +34 -37
- package/src/functions/get-content/types.ts +4 -2
- package/src/functions/get-fetch.ts +3 -10
- package/src/functions/get-global-this.ts +1 -2
- package/src/functions/get-processed-block.ts +14 -21
- package/src/functions/get-react-native-block-styles.ts +6 -12
- package/src/functions/if-target.ts +2 -3
- package/src/functions/is-browser.ts +1 -1
- package/src/functions/is-editing.ts +2 -7
- package/src/functions/is-iframe.ts +1 -2
- package/src/functions/is-non-node-server.ts +9 -0
- package/src/functions/is-previewing.ts +1 -4
- package/src/functions/on-change.ts +2 -2
- package/src/functions/register-component.ts +24 -26
- package/src/functions/register.ts +6 -8
- package/src/functions/sanitize-react-native-block-styles.ts +17 -24
- package/src/functions/set-editor-settings.ts +5 -6
- package/src/functions/set.ts +3 -15
- package/src/functions/track/helpers.ts +8 -24
- package/src/functions/track/index.ts +37 -42
- package/src/functions/track/interaction.ts +21 -38
- package/src/functions/transform-block-properties.ts +1 -1
- package/src/functions/transform-block.ts +1 -1
- package/src/helpers/ab-tests.ts +64 -79
- package/src/helpers/canTrack.ts +2 -4
- package/src/helpers/cookie.ts +15 -46
- package/src/helpers/css.ts +4 -13
- package/src/helpers/flatten.ts +11 -16
- package/src/helpers/localStorage.ts +4 -8
- package/src/helpers/logger.ts +2 -2
- package/src/helpers/nullable.ts +1 -3
- package/src/helpers/preview-lru-cache/get.ts +8 -0
- package/src/helpers/preview-lru-cache/helpers.ts +9 -0
- package/src/helpers/preview-lru-cache/init.ts +17 -0
- package/src/helpers/preview-lru-cache/set.ts +18 -0
- package/src/helpers/preview-lru-cache/types.ts +12 -0
- package/src/helpers/sessionId.ts +12 -13
- package/src/helpers/time.ts +1 -3
- package/src/helpers/url.ts +1 -2
- package/src/helpers/uuid.ts +3 -3
- package/src/helpers/visitorId.ts +14 -17
- package/src/index-helpers/blocks-exports.ts +2 -2
- package/src/index-helpers/top-of-file.ts +1 -1
- package/src/index.ts +2 -13
- package/src/scripts/init-editing.ts +85 -98
- package/src/types/api-version.ts +1 -1
- package/src/types/builder-block.ts +1 -3
- package/src/types/builder-content.ts +7 -4
- package/src/types/builder-props.ts +10 -0
- package/src/types/can-track.ts +1 -1
- package/src/types/components.ts +17 -13
- package/src/types/deep-partial.ts +1 -7
- package/src/types/element.ts +1 -3
- package/src/types/enforced-partials.ts +6 -20
- package/src/types/input.ts +6 -9
- package/src/types/targets.ts +1 -6
- package/src/types/typescript.ts +9 -9
- package/package/blocks/util.d.ts +0 -4
- package/package/blocks/util.js +0 -13
- package/package/components/render-block/render-block.helpers.d.ts +0 -12
- package/package/components/render-block/render-block.svelte +0 -152
- package/package/components/render-block/render-block.svelte.d.ts +0 -24
- package/package/components/render-block/render-component.svelte +0 -21
- package/package/components/render-block/render-component.svelte.d.ts +0 -34
- package/package/components/render-block/render-repeated-block.svelte.d.ts +0 -23
- package/package/components/render-blocks.svelte.d.ts +0 -26
- package/package/components/render-content/builder-editing.svelte +0 -4
- package/package/components/render-content/builder-editing.svelte.d.ts +0 -14
- package/package/components/render-content/index.d.ts +0 -1
- package/package/components/render-content/index.js +0 -1
- package/package/components/render-content/render-content.helpers.d.ts +0 -7
- package/package/components/render-content/render-content.helpers.js +0 -30
- package/package/components/render-content/render-content.svelte.d.ts +0 -30
- package/package/functions/evaluate.test.js +0 -17
- package/package/functions/get-builder-search-params/fn.test.js +0 -13
- package/package/functions/get-content/generate-content-url.test.d.ts +0 -1
- package/package/functions/get-content/generate-content-url.test.js +0 -97
- package/package/functions/get-processed-block.test.d.ts +0 -1
- package/package/functions/get-processed-block.test.js +0 -33
- package/package/functions/on-change.test.d.ts +0 -1
- package/package/functions/on-change.test.js +0 -20
- package/package/functions/set.test.d.ts +0 -1
- package/package/functions/set.test.js +0 -16
- package/package/helpers/url.test.d.ts +0 -1
- package/package/helpers/url.test.js +0 -21
- package/src/blocks/util.ts +0 -18
- package/src/components/render-block/render-block.svelte +0 -173
- package/src/components/render-block/render-component.svelte +0 -40
- package/src/components/render-block/render-repeated-block.svelte +0 -25
- package/src/components/render-content/builder-editing.svelte +0 -4
- package/src/components/render-content/index.ts +0 -1
- package/src/components/render-content/render-content.helpers.ts +0 -48
- package/src/functions/evaluate.test.ts +0 -21
- package/src/functions/evaluate.ts +0 -99
- package/src/functions/get-builder-search-params/fn.test.ts +0 -19
- package/src/functions/get-content/generate-content-url.test.ts +0 -112
- package/src/functions/get-processed-block.test.ts +0 -35
- package/src/functions/on-change.test.ts +0 -23
- package/src/functions/set.test.ts +0 -19
- package/src/helpers/url.test.ts +0 -23
- /package/package/components/{render-block → block}/types.d.ts +0 -0
- /package/package/components/{render-block → block}/types.js +0 -0
- /package/package/components/{render-content/render-content.types.js → content/content.types.js} +0 -0
- /package/package/components/{render-content → content}/wrap-component-ref.d.ts +0 -0
- /package/package/components/{render-content → content}/wrap-component-ref.js +0 -0
- /package/package/components/{render-content-variants/render-content-variants.types.js → content-variants/content-variants.types.js} +0 -0
- /package/package/functions/{evaluate.test.d.ts → evaluate/types.js} +0 -0
- /package/package/{functions/get-builder-search-params/fn.test.d.ts → types/builder-props.js} +0 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { writable } from "svelte/store";
|
|
3
|
+
|
|
4
|
+
import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
|
|
5
|
+
import type {
|
|
6
|
+
BuilderContextInterface,
|
|
7
|
+
BuilderRenderState,
|
|
8
|
+
RegisteredComponents,
|
|
9
|
+
} from "../../context/types.js";
|
|
10
|
+
import {
|
|
11
|
+
components,
|
|
12
|
+
serializeComponentInfo,
|
|
13
|
+
} from "../../functions/register-component.js";
|
|
14
|
+
import Blocks from "../blocks/blocks.svelte";
|
|
15
|
+
import ContentStyles from "./components/styles.svelte";
|
|
16
|
+
import type { ContentProps } from "./content.types.js";
|
|
17
|
+
import {
|
|
18
|
+
getContentInitialValue,
|
|
19
|
+
getContextStateInitialValue,
|
|
20
|
+
} from "./content.helpers.js";
|
|
21
|
+
import { TARGET } from "../../constants/target.js";
|
|
22
|
+
import { getRenderContentScriptString } from "../content-variants/helpers.js";
|
|
23
|
+
import EnableEditor from "./components/enable-editor.svelte";
|
|
24
|
+
import InlinedScript from "../inlined-script.svelte";
|
|
25
|
+
import { wrapComponentRef } from "./wrap-component-ref.js";
|
|
26
|
+
import type { ComponentInfo } from "../../types/components.js";
|
|
27
|
+
import type { Dictionary } from "../../types/typescript.js";
|
|
28
|
+
|
|
29
|
+
export let content: ContentProps["content"];
|
|
30
|
+
export let customComponents: ContentProps["customComponents"];
|
|
31
|
+
export let data: ContentProps["data"];
|
|
32
|
+
export let locale: ContentProps["locale"];
|
|
33
|
+
export let context: ContentProps["context"];
|
|
34
|
+
export let apiKey: ContentProps["apiKey"];
|
|
35
|
+
export let apiVersion: ContentProps["apiVersion"];
|
|
36
|
+
export let model: ContentProps["model"];
|
|
37
|
+
export let canTrack: ContentProps["canTrack"];
|
|
38
|
+
export let includeRefs: ContentProps["includeRefs"];
|
|
39
|
+
export let enrich: ContentProps["enrich"];
|
|
40
|
+
export let classNameProp: ContentProps["classNameProp"];
|
|
41
|
+
export let showContent: ContentProps["showContent"];
|
|
42
|
+
export let isSsrAbTest: ContentProps["isSsrAbTest"];
|
|
43
|
+
|
|
44
|
+
function contentSetState(newRootState: BuilderRenderState) {
|
|
45
|
+
$builderContextSignal.rootState = newRootState;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
let scriptStr = getRenderContentScriptString({
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
|
|
50
|
+
variationId: content?.testVariationId!,
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
|
|
52
|
+
contentId: content?.id!,
|
|
53
|
+
});
|
|
54
|
+
let registeredComponents = [
|
|
55
|
+
...getDefaultRegisteredComponents(),
|
|
56
|
+
// While this `components` object is deprecated, we must maintain support for it.
|
|
57
|
+
// Since users are able to override our default components, we need to make sure that we do not break such
|
|
58
|
+
// existing usage.
|
|
59
|
+
// This is why we spread `components` after the default Builder.io components, but before the `props.customComponents`,
|
|
60
|
+
// which is the new standard way of providing custom components, and must therefore take precedence.
|
|
61
|
+
...components,
|
|
62
|
+
...(customComponents || []),
|
|
63
|
+
].reduce<RegisteredComponents>(
|
|
64
|
+
(acc, { component, ...info }) => ({
|
|
65
|
+
...acc,
|
|
66
|
+
[info.name]: {
|
|
67
|
+
component: component,
|
|
68
|
+
...serializeComponentInfo(info),
|
|
69
|
+
},
|
|
70
|
+
}),
|
|
71
|
+
{}
|
|
72
|
+
);
|
|
73
|
+
let builderContextSignal = writable({
|
|
74
|
+
content: getContentInitialValue({
|
|
75
|
+
content: content,
|
|
76
|
+
data: data,
|
|
77
|
+
}),
|
|
78
|
+
localState: undefined,
|
|
79
|
+
rootState: getContextStateInitialValue({
|
|
80
|
+
content: content,
|
|
81
|
+
data: data,
|
|
82
|
+
locale: locale,
|
|
83
|
+
}),
|
|
84
|
+
rootSetState: contentSetState,
|
|
85
|
+
context: context || {},
|
|
86
|
+
apiKey: apiKey,
|
|
87
|
+
apiVersion: apiVersion,
|
|
88
|
+
componentInfos: [
|
|
89
|
+
...getDefaultRegisteredComponents(),
|
|
90
|
+
// While this `components` object is deprecated, we must maintain support for it.
|
|
91
|
+
// Since users are able to override our default components, we need to make sure that we do not break such
|
|
92
|
+
// existing usage.
|
|
93
|
+
// This is why we spread `components` after the default Builder.io components, but before the `props.customComponents`,
|
|
94
|
+
// which is the new standard way of providing custom components, and must therefore take precedence.
|
|
95
|
+
...components,
|
|
96
|
+
...(customComponents || []),
|
|
97
|
+
].reduce<Dictionary<ComponentInfo>>(
|
|
98
|
+
(acc, { component: _, ...info }) => ({
|
|
99
|
+
...acc,
|
|
100
|
+
[info.name]: serializeComponentInfo(info),
|
|
101
|
+
}),
|
|
102
|
+
{}
|
|
103
|
+
),
|
|
104
|
+
inheritedStyles: {},
|
|
105
|
+
});
|
|
106
|
+
</script>
|
|
107
|
+
|
|
108
|
+
<EnableEditor
|
|
109
|
+
{content}
|
|
110
|
+
{model}
|
|
111
|
+
{context}
|
|
112
|
+
{apiKey}
|
|
113
|
+
{canTrack}
|
|
114
|
+
{locale}
|
|
115
|
+
{includeRefs}
|
|
116
|
+
{enrich}
|
|
117
|
+
{classNameProp}
|
|
118
|
+
{showContent}
|
|
119
|
+
{builderContextSignal}
|
|
120
|
+
{...{}}
|
|
121
|
+
>
|
|
122
|
+
{#if isSsrAbTest}
|
|
123
|
+
<InlinedScript {scriptStr} />
|
|
124
|
+
{/if}
|
|
125
|
+
|
|
126
|
+
{#if TARGET !== "reactNative"}
|
|
127
|
+
<ContentStyles
|
|
128
|
+
contentId={$builderContextSignal.content?.id}
|
|
129
|
+
cssCode={$builderContextSignal.content?.data?.cssCode}
|
|
130
|
+
customFonts={$builderContextSignal.content?.data?.customFonts}
|
|
131
|
+
/>
|
|
132
|
+
{/if}
|
|
133
|
+
<Blocks
|
|
134
|
+
blocks={$builderContextSignal.content?.data?.blocks}
|
|
135
|
+
context={builderContextSignal}
|
|
136
|
+
{registeredComponents}
|
|
137
|
+
/>
|
|
138
|
+
</EnableEditor>
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { BuilderRenderState } from '../../context/types';
|
|
2
|
-
import type { EnforcePartials } from '../../types/enforced-partials';
|
|
3
|
-
import type {
|
|
4
|
-
|
|
1
|
+
import type { BuilderRenderState } from '../../context/types.js';
|
|
2
|
+
import type { EnforcePartials } from '../../types/enforced-partials.js';
|
|
3
|
+
import type { ContentVariantsProps } from '../content-variants/content-variants.types.js';
|
|
5
4
|
interface InternalRenderProps {
|
|
6
5
|
/**
|
|
7
6
|
* TO-DO: improve qwik generator to not remap this name for non-HTML tags, then name it `className`
|
|
@@ -10,10 +9,7 @@ interface InternalRenderProps {
|
|
|
10
9
|
showContent: boolean;
|
|
11
10
|
isSsrAbTest: boolean;
|
|
12
11
|
}
|
|
13
|
-
|
|
14
|
-
export type RenderContentProps = InternalRenderProps &
|
|
15
|
-
EnforcePartials<RenderContentVariantsProps>;
|
|
16
|
-
|
|
12
|
+
export type ContentProps = InternalRenderProps & EnforcePartials<ContentVariantsProps>;
|
|
17
13
|
export interface BuilderComponentStateChange {
|
|
18
14
|
state: BuilderRenderState;
|
|
19
15
|
ref: {
|
|
@@ -24,4 +20,4 @@ export interface BuilderComponentStateChange {
|
|
|
24
20
|
};
|
|
25
21
|
};
|
|
26
22
|
};
|
|
27
|
-
}
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './content.svelte'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script context="module" lang="ts">
|
|
2
|
-
type VariantsProviderProps =
|
|
2
|
+
type VariantsProviderProps = ContentVariantsProps & {
|
|
3
3
|
/**
|
|
4
4
|
* For internal use only. Do not provide this prop.
|
|
5
5
|
*/
|
|
@@ -15,14 +15,14 @@
|
|
|
15
15
|
getScriptString,
|
|
16
16
|
getVariants,
|
|
17
17
|
getVariantsScriptString,
|
|
18
|
-
} from "./helpers";
|
|
19
|
-
import
|
|
20
|
-
import { getDefaultCanTrack } from "../../helpers/canTrack";
|
|
18
|
+
} from "./helpers.js";
|
|
19
|
+
import ContentComponent from "../content/content.svelte";
|
|
20
|
+
import { getDefaultCanTrack } from "../../helpers/canTrack.js";
|
|
21
21
|
import InlinedStyles from "../inlined-styles.svelte";
|
|
22
|
-
import { handleABTestingSync } from "../../helpers/ab-tests";
|
|
22
|
+
import { handleABTestingSync } from "../../helpers/ab-tests.js";
|
|
23
23
|
import InlinedScript from "../inlined-script.svelte";
|
|
24
|
-
import { TARGET } from "../../constants/target";
|
|
25
|
-
import type {
|
|
24
|
+
import { TARGET } from "../../constants/target.js";
|
|
25
|
+
import type { ContentVariantsProps } from "./content-variants.types.js";
|
|
26
26
|
|
|
27
27
|
export let canTrack: VariantsProviderProps["canTrack"];
|
|
28
28
|
export let content: VariantsProviderProps["content"];
|
|
@@ -37,28 +37,30 @@
|
|
|
37
37
|
export let includeRefs: VariantsProviderProps["includeRefs"];
|
|
38
38
|
export let enrich: VariantsProviderProps["enrich"];
|
|
39
39
|
|
|
40
|
+
$: variantScriptStr = () => {
|
|
41
|
+
return getVariantsScriptString(
|
|
42
|
+
getVariants(content).map((value) => ({
|
|
43
|
+
id: value.testVariationId!,
|
|
44
|
+
testRatio: value.testRatio,
|
|
45
|
+
})),
|
|
46
|
+
content?.id || ""
|
|
47
|
+
);
|
|
48
|
+
};
|
|
49
|
+
$: hideVariantsStyleString = () => {
|
|
50
|
+
return getVariants(content)
|
|
51
|
+
.map((value) => `.variant-${value.testVariationId} { display: none; } `)
|
|
52
|
+
.join("");
|
|
53
|
+
};
|
|
54
|
+
|
|
40
55
|
let shouldRenderVariants = checkShouldRunVariants({
|
|
41
56
|
canTrack: getDefaultCanTrack(canTrack),
|
|
42
57
|
content: content,
|
|
43
58
|
});
|
|
44
|
-
let variantScriptStr = getVariantsScriptString(
|
|
45
|
-
getVariants(content).map((value) => ({
|
|
46
|
-
id: value.testVariationId!,
|
|
47
|
-
testRatio: value.testRatio,
|
|
48
|
-
})),
|
|
49
|
-
content?.id || ""
|
|
50
|
-
);
|
|
51
|
-
let hideVariantsStyleString = getVariants(content)
|
|
52
|
-
.map((value) => `.variant-${value.testVariationId} { display: none; } `)
|
|
53
|
-
.join("");
|
|
54
59
|
|
|
55
60
|
onMount(() => {
|
|
56
61
|
/**
|
|
57
62
|
* We unmount the non-winning variants post-hydration in Vue.
|
|
58
63
|
*/
|
|
59
|
-
if (TARGET === "vue2" || TARGET === "vue3") {
|
|
60
|
-
shouldRenderVariants = false;
|
|
61
|
-
}
|
|
62
64
|
});
|
|
63
65
|
</script>
|
|
64
66
|
|
|
@@ -69,13 +71,13 @@
|
|
|
69
71
|
{#if shouldRenderVariants}
|
|
70
72
|
<InlinedStyles
|
|
71
73
|
id={`variants-styles-${content?.id}`}
|
|
72
|
-
styles={hideVariantsStyleString}
|
|
74
|
+
styles={hideVariantsStyleString()}
|
|
73
75
|
/>
|
|
74
76
|
|
|
75
|
-
<InlinedScript scriptStr={variantScriptStr} />
|
|
77
|
+
<InlinedScript scriptStr={variantScriptStr()} />
|
|
76
78
|
|
|
77
79
|
{#each getVariants(content) as variant (variant.testVariationId)}
|
|
78
|
-
<
|
|
80
|
+
<ContentComponent
|
|
79
81
|
content={variant}
|
|
80
82
|
showContent={false}
|
|
81
83
|
classNameProp={undefined}
|
|
@@ -94,7 +96,7 @@
|
|
|
94
96
|
{/each}
|
|
95
97
|
{/if}
|
|
96
98
|
|
|
97
|
-
<
|
|
99
|
+
<ContentComponent
|
|
98
100
|
{...{}}
|
|
99
101
|
content={shouldRenderVariants
|
|
100
102
|
? content
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from '../../
|
|
5
|
-
|
|
6
|
-
import type { BuilderContent } from '../../types/builder-content';
|
|
7
|
-
import type { Nullable } from '../../types/typescript';
|
|
8
|
-
|
|
9
|
-
export interface RenderContentVariantsProps {
|
|
1
|
+
import type { BuilderRenderContext, RegisteredComponent } from '../../context/types.js';
|
|
2
|
+
import type { ApiVersion } from '../../types/api-version.js';
|
|
3
|
+
import type { BuilderContent } from '../../types/builder-content.js';
|
|
4
|
+
import type { Nullable } from '../../types/typescript.js';
|
|
5
|
+
export interface ContentVariantsProps {
|
|
10
6
|
content?: Nullable<BuilderContent>;
|
|
11
7
|
model?: string;
|
|
12
|
-
data?: {
|
|
8
|
+
data?: {
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
};
|
|
13
11
|
context?: BuilderRenderContext;
|
|
14
12
|
apiKey: string;
|
|
15
13
|
apiVersion?: ApiVersion;
|
|
@@ -19,4 +17,4 @@ export interface RenderContentVariantsProps {
|
|
|
19
17
|
/** @deprecated use `enrich` instead **/
|
|
20
18
|
includeRefs?: boolean;
|
|
21
19
|
enrich?: boolean;
|
|
22
|
-
}
|
|
20
|
+
}
|
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
import { TARGET } from '../../constants/target';
|
|
2
|
-
import { isBrowser } from '../../functions/is-browser';
|
|
3
|
-
import type { Nullable } from '../../helpers/nullable';
|
|
4
|
-
import type { BuilderContent } from '../../types/builder-content';
|
|
5
|
-
import type { Target } from '../../types/targets';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
id: content?.id,
|
|
12
|
-
}));
|
|
13
|
-
|
|
1
|
+
import { TARGET } from '../../constants/target.js';
|
|
2
|
+
import { isBrowser } from '../../functions/is-browser.js';
|
|
3
|
+
import type { Nullable } from '../../helpers/nullable.js';
|
|
4
|
+
import type { BuilderContent } from '../../types/builder-content.js';
|
|
5
|
+
import type { Target } from '../../types/targets.js';
|
|
6
|
+
export const getVariants = (content: Nullable<BuilderContent>) => Object.values(content?.variations || {}).map(variant => ({
|
|
7
|
+
...variant,
|
|
8
|
+
testVariationId: variant.id,
|
|
9
|
+
id: content?.id
|
|
10
|
+
}));
|
|
14
11
|
export const checkShouldRunVariants = ({
|
|
15
12
|
canTrack,
|
|
16
|
-
content
|
|
13
|
+
content
|
|
17
14
|
}: {
|
|
18
15
|
canTrack: Nullable<boolean>;
|
|
19
16
|
content: Nullable<BuilderContent>;
|
|
@@ -24,7 +21,6 @@ export const checkShouldRunVariants = ({
|
|
|
24
21
|
* We cannot SSR in React-Native.
|
|
25
22
|
*/
|
|
26
23
|
if (TARGET === 'reactNative') return false;
|
|
27
|
-
|
|
28
24
|
if (!hasVariants) return false;
|
|
29
25
|
if (!canTrack) return false;
|
|
30
26
|
|
|
@@ -36,12 +32,9 @@ export const checkShouldRunVariants = ({
|
|
|
36
32
|
* NOTE: after the app is hydrated, we strip the variants from the DOM (on mount) to reduce the amount of HTML in the DOM.
|
|
37
33
|
*/
|
|
38
34
|
if (TARGET === 'vue2' || TARGET === 'vue3') return true;
|
|
39
|
-
|
|
40
35
|
if (isBrowser()) return false;
|
|
41
|
-
|
|
42
36
|
return true;
|
|
43
37
|
};
|
|
44
|
-
|
|
45
38
|
type VariantData = {
|
|
46
39
|
id: string;
|
|
47
40
|
testRatio?: number;
|
|
@@ -51,11 +44,7 @@ type VariantData = {
|
|
|
51
44
|
* NOTE: when this function is stringified, single-line comments can cause weird issues when compiled by Sveltekit.
|
|
52
45
|
* Make sure to write multi-line comments only.
|
|
53
46
|
*/
|
|
54
|
-
function bldrAbTest(
|
|
55
|
-
contentId: string,
|
|
56
|
-
variants: VariantData[],
|
|
57
|
-
isHydrationTarget: boolean
|
|
58
|
-
) {
|
|
47
|
+
function bldrAbTest(contentId: string, variants: VariantData[], isHydrationTarget: boolean) {
|
|
59
48
|
function getAndSetVariantId(): string {
|
|
60
49
|
function setCookie(name: string, value: string, days?: number) {
|
|
61
50
|
let expires = '';
|
|
@@ -64,13 +53,7 @@ function bldrAbTest(
|
|
|
64
53
|
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
|
|
65
54
|
expires = '; expires=' + date.toUTCString();
|
|
66
55
|
}
|
|
67
|
-
document.cookie =
|
|
68
|
-
name +
|
|
69
|
-
'=' +
|
|
70
|
-
(value || '') +
|
|
71
|
-
expires +
|
|
72
|
-
'; path=/' +
|
|
73
|
-
'; Secure; SameSite=None';
|
|
56
|
+
document.cookie = name + '=' + (value || '') + expires + '; path=/' + '; Secure; SameSite=None';
|
|
74
57
|
}
|
|
75
58
|
function getCookie(name: string) {
|
|
76
59
|
const nameEQ = name + '=';
|
|
@@ -78,14 +61,13 @@ function bldrAbTest(
|
|
|
78
61
|
for (let i = 0; i < ca.length; i++) {
|
|
79
62
|
let c = ca[i];
|
|
80
63
|
while (c.charAt(0) === ' ') c = c.substring(1, c.length);
|
|
81
|
-
if (c.indexOf(nameEQ) === 0)
|
|
82
|
-
return c.substring(nameEQ.length, c.length);
|
|
64
|
+
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
|
|
83
65
|
}
|
|
84
66
|
return null;
|
|
85
67
|
}
|
|
86
68
|
const cookieName = `builder.tests.${contentId}`;
|
|
87
69
|
const variantInCookie = getCookie(cookieName);
|
|
88
|
-
const availableIDs = variants.map(
|
|
70
|
+
const availableIDs = variants.map(vr => vr.id).concat(contentId);
|
|
89
71
|
/**
|
|
90
72
|
* cookie already exists
|
|
91
73
|
*/
|
|
@@ -112,14 +94,10 @@ function bldrAbTest(
|
|
|
112
94
|
* no variant found, assign default content
|
|
113
95
|
*/
|
|
114
96
|
setCookie(cookieName, contentId);
|
|
115
|
-
|
|
116
97
|
return contentId;
|
|
117
98
|
}
|
|
118
|
-
|
|
119
99
|
const winningVariantId = getAndSetVariantId();
|
|
120
|
-
|
|
121
|
-
const styleEl = document.currentScript
|
|
122
|
-
?.previousElementSibling as HTMLStyleElement;
|
|
100
|
+
const styleEl = (document.currentScript?.previousElementSibling as HTMLStyleElement);
|
|
123
101
|
|
|
124
102
|
/**
|
|
125
103
|
* For React to work, we need hydration to match SSR, so we completely remove this node and the styles tag.
|
|
@@ -130,15 +108,12 @@ function bldrAbTest(
|
|
|
130
108
|
thisScriptEl?.remove();
|
|
131
109
|
} else {
|
|
132
110
|
/* update styles to hide all variants except the winning variant */
|
|
133
|
-
const newStyleStr = variants
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
.
|
|
137
|
-
return `.variant-${value.id} { display: none; }
|
|
111
|
+
const newStyleStr = variants.concat({
|
|
112
|
+
id: contentId
|
|
113
|
+
}).filter(variant => variant.id !== winningVariantId).map(value => {
|
|
114
|
+
return `.variant-${value.id} { display: none; }
|
|
138
115
|
`;
|
|
139
|
-
|
|
140
|
-
.join('');
|
|
141
|
-
|
|
116
|
+
}).join('');
|
|
142
117
|
styleEl.innerHTML = newStyleStr;
|
|
143
118
|
}
|
|
144
119
|
}
|
|
@@ -147,15 +122,10 @@ function bldrAbTest(
|
|
|
147
122
|
* NOTE: when this function is stringified, single-line comments can cause weird issues when compiled by Sveltekit.
|
|
148
123
|
* Make sure to write multi-line comments only.
|
|
149
124
|
*/
|
|
150
|
-
function bldrCntntScrpt(
|
|
151
|
-
variantContentId: string,
|
|
152
|
-
defaultContentId: string,
|
|
153
|
-
isHydrationTarget: boolean
|
|
154
|
-
) {
|
|
125
|
+
function bldrCntntScrpt(variantContentId: string, defaultContentId: string, isHydrationTarget: boolean) {
|
|
155
126
|
if (!navigator.cookieEnabled) {
|
|
156
127
|
return;
|
|
157
128
|
}
|
|
158
|
-
|
|
159
129
|
function getCookie(name: string) {
|
|
160
130
|
const nameEQ = name + '=';
|
|
161
131
|
const ca = document.cookie.split(';');
|
|
@@ -168,11 +138,8 @@ function bldrCntntScrpt(
|
|
|
168
138
|
}
|
|
169
139
|
const cookieName = `builder.tests.${defaultContentId}`;
|
|
170
140
|
const variantId = getCookie(cookieName);
|
|
171
|
-
|
|
172
141
|
const parentDiv = document.currentScript?.parentElement;
|
|
173
|
-
|
|
174
142
|
const variantIsDefaultContent = variantContentId === defaultContentId;
|
|
175
|
-
|
|
176
143
|
if (variantId === variantContentId) {
|
|
177
144
|
if (variantIsDefaultContent) {
|
|
178
145
|
/** the default content is already visible, no need to do anything */
|
|
@@ -203,13 +170,9 @@ function bldrCntntScrpt(
|
|
|
203
170
|
*/
|
|
204
171
|
return;
|
|
205
172
|
}
|
|
206
|
-
|
|
207
173
|
return;
|
|
208
174
|
}
|
|
209
|
-
|
|
210
|
-
const getIsHydrationTarget = (target: Target) =>
|
|
211
|
-
target === 'react' || target === 'reactNative';
|
|
212
|
-
|
|
175
|
+
const getIsHydrationTarget = (target: Target) => target === 'react' || target === 'reactNative';
|
|
213
176
|
const isHydrationTarget = getIsHydrationTarget(TARGET);
|
|
214
177
|
|
|
215
178
|
/**
|
|
@@ -220,34 +183,25 @@ const isHydrationTarget = getIsHydrationTarget(TARGET);
|
|
|
220
183
|
*/
|
|
221
184
|
const AB_TEST_FN_NAME = 'builderIoAbTest';
|
|
222
185
|
const CONTENT_FN_NAME = 'builderIoRenderContent';
|
|
223
|
-
|
|
224
186
|
export const getScriptString = () => {
|
|
225
187
|
const fnStr = bldrAbTest.toString().replace(/\s+/g, ' ');
|
|
226
188
|
const fnStr2 = bldrCntntScrpt.toString().replace(/\s+/g, ' ');
|
|
227
|
-
|
|
228
189
|
return `
|
|
229
190
|
window.${AB_TEST_FN_NAME} = ${fnStr}
|
|
230
191
|
window.${CONTENT_FN_NAME} = ${fnStr2}
|
|
231
192
|
`;
|
|
232
193
|
};
|
|
233
|
-
|
|
234
|
-
export const getVariantsScriptString = (
|
|
235
|
-
variants: VariantData[],
|
|
236
|
-
contentId: string
|
|
237
|
-
) => {
|
|
194
|
+
export const getVariantsScriptString = (variants: VariantData[], contentId: string) => {
|
|
238
195
|
return `
|
|
239
|
-
window.${AB_TEST_FN_NAME}("${contentId}",${JSON.stringify(
|
|
240
|
-
variants
|
|
241
|
-
)}, ${isHydrationTarget})`;
|
|
196
|
+
window.${AB_TEST_FN_NAME}("${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget})`;
|
|
242
197
|
};
|
|
243
|
-
|
|
244
198
|
export const getRenderContentScriptString = ({
|
|
245
199
|
contentId,
|
|
246
|
-
variationId
|
|
200
|
+
variationId
|
|
247
201
|
}: {
|
|
248
202
|
variationId: string;
|
|
249
203
|
contentId: string;
|
|
250
204
|
}) => {
|
|
251
205
|
return `
|
|
252
206
|
window.${CONTENT_FN_NAME}("${variationId}", "${contentId}", ${isHydrationTarget})`;
|
|
253
|
-
}
|
|
207
|
+
}
|
|
@@ -26,17 +26,37 @@ import { componentInfo as customCodeInfo } from '../blocks/custom-code/component
|
|
|
26
26
|
* Returns a list of all registered components.
|
|
27
27
|
* NOTE: This needs to be a function to work around ESM circular dependencies.
|
|
28
28
|
*/
|
|
29
|
-
export const getDefaultRegisteredComponents: () => RegisteredComponent[] =
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
29
|
+
export const getDefaultRegisteredComponents: () => RegisteredComponent[] = () => [{
|
|
30
|
+
component: Button,
|
|
31
|
+
...buttonComponentInfo
|
|
32
|
+
}, {
|
|
33
|
+
component: Columns,
|
|
34
|
+
...columnsComponentInfo
|
|
35
|
+
}, {
|
|
36
|
+
component: customCode,
|
|
37
|
+
...customCodeInfo
|
|
38
|
+
}, {
|
|
39
|
+
component: embed,
|
|
40
|
+
...embedComponentInfo
|
|
41
|
+
}, {
|
|
42
|
+
component: Fragment,
|
|
43
|
+
...fragmentComponentInfo
|
|
44
|
+
}, {
|
|
45
|
+
component: Image,
|
|
46
|
+
...imageComponentInfo
|
|
47
|
+
}, {
|
|
48
|
+
component: Img,
|
|
49
|
+
...imgComponentInfo
|
|
50
|
+
}, {
|
|
51
|
+
component: Section,
|
|
52
|
+
...sectionComponentInfo
|
|
53
|
+
}, {
|
|
54
|
+
component: Symbol,
|
|
55
|
+
...symbolComponentInfo
|
|
56
|
+
}, {
|
|
57
|
+
component: Text,
|
|
58
|
+
...textComponentInfo
|
|
59
|
+
}, {
|
|
60
|
+
component: Video,
|
|
61
|
+
...videoComponentInfo
|
|
62
|
+
}]
|
|
@@ -1,65 +1,59 @@
|
|
|
1
|
-
import { fastClone } from '../functions/fast-clone';
|
|
1
|
+
import { fastClone } from '../functions/fast-clone.js';
|
|
2
2
|
export type SizeName = 'large' | 'medium' | 'small';
|
|
3
|
-
|
|
4
3
|
interface Size {
|
|
5
4
|
min: number;
|
|
6
5
|
default: number;
|
|
7
6
|
max: number;
|
|
8
7
|
}
|
|
9
|
-
|
|
10
8
|
const SIZES: Record<SizeName, Size> = {
|
|
11
9
|
small: {
|
|
12
10
|
min: 320,
|
|
13
11
|
default: 321,
|
|
14
|
-
max: 640
|
|
12
|
+
max: 640
|
|
15
13
|
},
|
|
16
14
|
medium: {
|
|
17
15
|
min: 641,
|
|
18
16
|
default: 642,
|
|
19
|
-
max: 991
|
|
17
|
+
max: 991
|
|
20
18
|
},
|
|
21
19
|
large: {
|
|
22
20
|
min: 990,
|
|
23
21
|
default: 991,
|
|
24
|
-
max: 1200
|
|
25
|
-
}
|
|
22
|
+
max: 1200
|
|
23
|
+
}
|
|
26
24
|
};
|
|
27
|
-
|
|
28
|
-
export const getMaxWidthQueryForSize = (size: SizeName, sizeValues = SIZES) =>
|
|
29
|
-
`@media (max-width: ${sizeValues[size].max}px)`;
|
|
30
|
-
|
|
25
|
+
export const getMaxWidthQueryForSize = (size: SizeName, sizeValues = SIZES) => `@media (max-width: ${sizeValues[size].max}px)`;
|
|
31
26
|
interface Breakpoints {
|
|
32
27
|
small?: number;
|
|
33
28
|
medium?: number;
|
|
34
29
|
}
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
export const getSizesForBreakpoints = ({
|
|
31
|
+
small,
|
|
32
|
+
medium
|
|
33
|
+
}: Breakpoints) => {
|
|
37
34
|
const newSizes = fastClone(SIZES); // Note: this helps to get a deep clone of fields like small, medium etc
|
|
38
35
|
|
|
39
36
|
if (!small || !medium) {
|
|
40
37
|
return newSizes;
|
|
41
38
|
}
|
|
42
|
-
|
|
43
39
|
const smallMin = Math.floor(small / 2);
|
|
44
40
|
newSizes.small = {
|
|
45
41
|
max: small,
|
|
46
42
|
min: smallMin,
|
|
47
|
-
default: smallMin + 1
|
|
43
|
+
default: smallMin + 1
|
|
48
44
|
};
|
|
49
|
-
|
|
50
45
|
const mediumMin = newSizes.small.max + 1;
|
|
51
46
|
newSizes.medium = {
|
|
52
47
|
max: medium,
|
|
53
48
|
min: mediumMin,
|
|
54
|
-
default: mediumMin + 1
|
|
49
|
+
default: mediumMin + 1
|
|
55
50
|
};
|
|
56
|
-
|
|
57
51
|
const largeMin = newSizes.medium.max + 1;
|
|
58
52
|
newSizes.large = {
|
|
59
|
-
max: 2000,
|
|
53
|
+
max: 2000,
|
|
54
|
+
// TODO: decide upper limit
|
|
60
55
|
min: largeMin,
|
|
61
|
-
default: largeMin + 1
|
|
56
|
+
default: largeMin + 1
|
|
62
57
|
};
|
|
63
|
-
|
|
64
58
|
return newSizes;
|
|
65
|
-
}
|
|
59
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "0.
|
|
1
|
+
export const SDK_VERSION = "0.5.0"
|
package/src/constants/target.ts
CHANGED