@builder.io/sdk-svelte 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/package/--package.json +43 -29
- package/package/CHANGELOG.md +13 -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 +14 -20
- 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 +38 -85
- 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/text/text.svelte.d.ts +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 +21 -23
- 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} +51 -169
- 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} +4 -4
- 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/content/content.types.d.ts +24 -0
- package/package/components/content/index.d.ts +1 -0
- package/package/components/content/index.js +1 -0
- package/package/components/content-variants/content-variants.svelte +98 -0
- package/package/components/content-variants/content-variants.svelte.d.ts +34 -0
- package/package/components/content-variants/content-variants.types.d.ts +20 -0
- package/package/components/content-variants/helpers.d.ts +41 -0
- package/package/components/{render-content-variants → content-variants}/helpers.js +46 -41
- package/package/components/inlined-script.svelte +7 -0
- package/package/components/inlined-script.svelte.d.ts +21 -0
- package/package/components/inlined-styles.svelte.d.ts +21 -0
- 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 +48 -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 +21 -0
- package/package/types/targets.d.ts +1 -3
- package/package/types/typescript.d.ts +6 -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 +28 -32
- 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 +51 -95
- package/src/blocks/text/component-info.ts +14 -18
- package/src/blocks/text/text.svelte +2 -2
- 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 +24 -25
- 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} +75 -202
- 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} +5 -5
- package/src/components/content/content.helpers.ts +42 -0
- package/src/components/content/content.svelte +138 -0
- package/src/components/content/content.types.ts +23 -0
- package/src/components/content/index.ts +1 -0
- package/src/components/{render-content → content}/wrap-component-ref.ts +1 -1
- package/src/components/content-variants/content-variants.svelte +120 -0
- package/src/components/content-variants/content-variants.types.ts +20 -0
- package/src/components/{render-content-variants → content-variants}/helpers.ts +53 -94
- package/src/components/inlined-script.svelte +13 -0
- 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 +69 -78
- 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 +13 -0
- package/src/types/input.ts +6 -9
- package/src/types/targets.ts +1 -6
- package/src/types/typescript.ts +10 -5
- 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 -31
- package/package/components/render-content/render-content.types.d.ts +0 -38
- package/package/components/render-content-variants/helpers.d.ts +0 -17
- package/package/components/render-content-variants/render-content-variants.svelte +0 -70
- package/package/components/render-content-variants/render-content-variants.svelte.d.ts +0 -23
- package/package/components/render-inlined-styles.svelte.d.ts +0 -21
- 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.js +0 -97
- 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/components/render-content/render-content.types.ts +0 -42
- package/src/components/render-content-variants/render-content-variants.svelte +0 -83
- 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/{functions/evaluate.test.d.ts → components/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/render-content.types.js → content-variants/content-variants.types.js} +0 -0
- /package/package/components/{render-inlined-styles.svelte → inlined-styles.svelte} +0 -0
- /package/package/functions/{get-builder-search-params/fn.test.d.ts → evaluate/types.js} +0 -0
- /package/package/{functions/get-content/generate-content-url.test.d.ts → types/builder-props.js} +0 -0
- /package/package/{functions/get-processed-block.test.d.ts → types/enforced-partials.js} +0 -0
- /package/src/components/{render-inlined-styles.svelte → inlined-styles.svelte} +0 -0
|
@@ -1,32 +1,31 @@
|
|
|
1
1
|
import type { BuilderContextInterface } from '../context/types.js';
|
|
2
2
|
import type { BuilderBlock } from '../types/builder-block.js';
|
|
3
|
-
import { evaluate } from './evaluate
|
|
3
|
+
import { evaluate } from './evaluate';
|
|
4
4
|
import { fastClone } from './fast-clone.js';
|
|
5
5
|
import { set } from './set.js';
|
|
6
6
|
import { transformBlock } from './transform-block.js';
|
|
7
|
-
|
|
8
7
|
const evaluateBindings = ({
|
|
9
8
|
block,
|
|
10
9
|
context,
|
|
11
10
|
localState,
|
|
12
11
|
rootState,
|
|
13
|
-
rootSetState
|
|
12
|
+
rootSetState
|
|
14
13
|
}: {
|
|
15
14
|
block: BuilderBlock;
|
|
16
|
-
} & Pick<
|
|
17
|
-
BuilderContextInterface,
|
|
18
|
-
'localState' | 'context' | 'rootState' | 'rootSetState'
|
|
19
|
-
>): BuilderBlock => {
|
|
15
|
+
} & Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>): BuilderBlock => {
|
|
20
16
|
if (!block.bindings) {
|
|
21
17
|
return block;
|
|
22
18
|
}
|
|
23
19
|
const copy = fastClone(block);
|
|
24
20
|
const copied = {
|
|
25
21
|
...copy,
|
|
26
|
-
properties: {
|
|
27
|
-
|
|
22
|
+
properties: {
|
|
23
|
+
...copy.properties
|
|
24
|
+
},
|
|
25
|
+
actions: {
|
|
26
|
+
...copy.actions
|
|
27
|
+
}
|
|
28
28
|
};
|
|
29
|
-
|
|
30
29
|
for (const binding in block.bindings) {
|
|
31
30
|
const expression = block.bindings[binding];
|
|
32
31
|
const value = evaluate({
|
|
@@ -34,21 +33,19 @@ const evaluateBindings = ({
|
|
|
34
33
|
localState,
|
|
35
34
|
rootState,
|
|
36
35
|
rootSetState,
|
|
37
|
-
context
|
|
36
|
+
context
|
|
38
37
|
});
|
|
39
38
|
set(copied, binding, value);
|
|
40
39
|
}
|
|
41
|
-
|
|
42
40
|
return copied;
|
|
43
41
|
};
|
|
44
|
-
|
|
45
42
|
export function getProcessedBlock({
|
|
46
43
|
block,
|
|
47
44
|
context,
|
|
48
45
|
shouldEvaluateBindings,
|
|
49
46
|
localState,
|
|
50
47
|
rootState,
|
|
51
|
-
rootSetState
|
|
48
|
+
rootSetState
|
|
52
49
|
}: {
|
|
53
50
|
block: BuilderBlock;
|
|
54
51
|
/**
|
|
@@ -56,21 +53,17 @@ export function getProcessedBlock({
|
|
|
56
53
|
* also sometimes too early to consider bindings, e.g. when we might be looking at a repeated block.
|
|
57
54
|
*/
|
|
58
55
|
shouldEvaluateBindings: boolean;
|
|
59
|
-
} & Pick<
|
|
60
|
-
BuilderContextInterface,
|
|
61
|
-
'localState' | 'context' | 'rootState' | 'rootSetState'
|
|
62
|
-
>): BuilderBlock {
|
|
56
|
+
} & Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>): BuilderBlock {
|
|
63
57
|
const transformedBlock = transformBlock(block);
|
|
64
|
-
|
|
65
58
|
if (shouldEvaluateBindings) {
|
|
66
59
|
return evaluateBindings({
|
|
67
60
|
block: transformedBlock,
|
|
68
61
|
localState,
|
|
69
62
|
rootState,
|
|
70
63
|
rootSetState,
|
|
71
|
-
context
|
|
64
|
+
context
|
|
72
65
|
});
|
|
73
66
|
} else {
|
|
74
67
|
return transformedBlock;
|
|
75
68
|
}
|
|
76
|
-
}
|
|
69
|
+
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type { BuilderContextInterface } from '../context/types.js';
|
|
2
2
|
import type { BuilderBlock } from '../types/builder-block.js';
|
|
3
3
|
import { sanitizeReactNativeBlockStyles } from './sanitize-react-native-block-styles.js';
|
|
4
|
-
|
|
5
4
|
export function getReactNativeBlockStyles({
|
|
6
5
|
block,
|
|
7
6
|
context,
|
|
8
|
-
blockStyles
|
|
7
|
+
blockStyles
|
|
9
8
|
}: {
|
|
10
9
|
block: BuilderBlock;
|
|
11
10
|
context: BuilderContextInterface;
|
|
@@ -15,19 +14,14 @@ export function getReactNativeBlockStyles({
|
|
|
15
14
|
if (!responsiveStyles) {
|
|
16
15
|
return {};
|
|
17
16
|
}
|
|
18
|
-
|
|
19
|
-
const styles = {
|
|
17
|
+
const styles = ({
|
|
20
18
|
// recursively apply inherited styles so that they can be passed down to children `Text` blocks
|
|
21
19
|
...context.inheritedStyles,
|
|
22
20
|
...(responsiveStyles.large || {}),
|
|
23
21
|
...(responsiveStyles.medium || {}),
|
|
24
22
|
...(responsiveStyles.small || {}),
|
|
25
|
-
...blockStyles
|
|
26
|
-
} as Record<string, string | number
|
|
27
|
-
|
|
28
|
-
const newStyles = sanitizeReactNativeBlockStyles(
|
|
29
|
-
styles
|
|
30
|
-
) as any as CSSStyleDeclaration;
|
|
31
|
-
|
|
23
|
+
...blockStyles
|
|
24
|
+
} as Record<string, string | number>);
|
|
25
|
+
const newStyles = ((sanitizeReactNativeBlockStyles(styles) as any) as CSSStyleDeclaration);
|
|
32
26
|
return newStyles;
|
|
33
|
-
}
|
|
27
|
+
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { TARGET } from '../constants/target.js';
|
|
2
|
-
|
|
3
2
|
type Target = import('../types/targets').Target;
|
|
4
3
|
|
|
5
4
|
// TODO: babel compile to include certain code only if the target matches
|
|
6
5
|
export function ifTarget<A, B>({
|
|
7
6
|
targets,
|
|
8
7
|
doThing,
|
|
9
|
-
elseThing
|
|
8
|
+
elseThing
|
|
10
9
|
}: {
|
|
11
10
|
targets: Target[];
|
|
12
11
|
doThing: () => A;
|
|
@@ -17,4 +16,4 @@ export function ifTarget<A, B>({
|
|
|
17
16
|
} else {
|
|
18
17
|
return elseThing?.();
|
|
19
18
|
}
|
|
20
|
-
}
|
|
19
|
+
}
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { TARGET } from '../constants/target.js';
|
|
2
2
|
import { isIframe } from './is-iframe.js';
|
|
3
|
-
|
|
4
3
|
export function isEditing(): boolean {
|
|
5
|
-
return (
|
|
6
|
-
|
|
7
|
-
(TARGET === 'reactNative' ||
|
|
8
|
-
window.location.search.indexOf('builder.frameEditing=') !== -1)
|
|
9
|
-
);
|
|
10
|
-
}
|
|
4
|
+
return isIframe() && (TARGET === 'reactNative' || window.location.search.indexOf('builder.frameEditing=') !== -1);
|
|
5
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { isBrowser } from './is-browser';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Identifies non-node server runtimes (edge, workers, serverless, etc.)
|
|
5
|
+
*/
|
|
6
|
+
export function isNonNodeServer(): boolean {
|
|
7
|
+
const hasNode = () => typeof process !== 'undefined' && process?.versions?.node;
|
|
8
|
+
return !isBrowser() && !hasNode();
|
|
9
|
+
}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { isBrowser } from './is-browser.js';
|
|
2
2
|
import { isEditing } from './is-editing.js';
|
|
3
|
-
|
|
4
3
|
export function isPreviewing() {
|
|
5
4
|
if (!isBrowser()) {
|
|
6
5
|
return false;
|
|
7
6
|
}
|
|
8
|
-
|
|
9
7
|
if (isEditing()) {
|
|
10
8
|
return false;
|
|
11
9
|
}
|
|
12
|
-
|
|
13
10
|
return Boolean(location.search.indexOf('builder.preview=') !== -1);
|
|
14
|
-
}
|
|
11
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { serializeFn } from '../blocks/util.js';
|
|
2
1
|
import type { RegisteredComponent } from '../context/types.js';
|
|
3
2
|
import type { ComponentInfo } from '../types/components.js';
|
|
4
3
|
import type { Input } from '../types/input.js';
|
|
@@ -13,38 +12,37 @@ export const components: RegisteredComponent[] = [];
|
|
|
13
12
|
* @deprecated. Use the `customComponents` prop in RenderContent instead to provide your custom components to the builder SDK.
|
|
14
13
|
*/
|
|
15
14
|
export function registerComponent(component: any, info: ComponentInfo): void {
|
|
16
|
-
components.push({
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
);
|
|
21
|
-
|
|
15
|
+
components.push({
|
|
16
|
+
component,
|
|
17
|
+
...info
|
|
18
|
+
});
|
|
19
|
+
console.warn('registerComponent is deprecated. Use the `customComponents` prop in RenderContent instead to provide your custom components to the builder SDK.');
|
|
22
20
|
return component;
|
|
23
21
|
}
|
|
24
|
-
|
|
25
|
-
export const createRegisterComponentMessage = ({
|
|
26
|
-
component: _,
|
|
27
|
-
...info
|
|
28
|
-
}: RegisteredComponent) => ({
|
|
22
|
+
export const createRegisterComponentMessage = (info: ComponentInfo) => ({
|
|
29
23
|
type: 'builder.registerComponent',
|
|
30
|
-
data:
|
|
24
|
+
data: info
|
|
31
25
|
});
|
|
32
26
|
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
28
|
+
const serializeFn = (fnValue: Function) => {
|
|
29
|
+
const fnStr = fnValue.toString().trim();
|
|
35
30
|
|
|
36
|
-
|
|
31
|
+
// we need to account for a few different fn syntaxes:
|
|
32
|
+
// 1. `function name(args) => {code}`
|
|
33
|
+
// 2. `name(args) => {code}`
|
|
34
|
+
// 3. `(args) => {}`
|
|
35
|
+
const appendFunction = !fnStr.startsWith('function') && !fnStr.startsWith('(');
|
|
36
|
+
return `return (${appendFunction ? 'function ' : ''}${fnStr}).apply(this, arguments)`;
|
|
37
|
+
};
|
|
38
|
+
const serializeValue = (value: object): any => typeof value === 'function' ? serializeFn(value) : fastClone(value);
|
|
39
|
+
export const serializeComponentInfo = ({
|
|
37
40
|
inputs,
|
|
38
41
|
...info
|
|
39
42
|
}: ComponentInfo): ComponentInfo => ({
|
|
40
43
|
...fastClone(info),
|
|
41
|
-
inputs: inputs?.map((input) =>
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}),
|
|
47
|
-
{} as Input
|
|
48
|
-
)
|
|
49
|
-
),
|
|
50
|
-
});
|
|
44
|
+
inputs: inputs?.map(input => Object.entries(input).reduce((acc, [key, value]) => ({
|
|
45
|
+
...acc,
|
|
46
|
+
[key]: serializeValue(value)
|
|
47
|
+
}), ({} as Input)))
|
|
48
|
+
})
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import type { BuilderBlock } from '../types/builder-block.js';
|
|
2
2
|
import type { DeepPartial } from '../types/deep-partial.js';
|
|
3
3
|
import { isBrowser } from './is-browser.js';
|
|
4
|
-
|
|
5
4
|
export interface InsertMenuItem {
|
|
6
5
|
name: string;
|
|
7
6
|
icon?: string;
|
|
8
7
|
item: DeepPartial<BuilderBlock>;
|
|
9
8
|
}
|
|
10
|
-
|
|
11
9
|
export interface InsertMenuConfig {
|
|
12
10
|
name: string;
|
|
13
11
|
priority?: number;
|
|
@@ -15,9 +13,9 @@ export interface InsertMenuConfig {
|
|
|
15
13
|
advanced?: boolean;
|
|
16
14
|
items: InsertMenuItem[];
|
|
17
15
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
const registry: {
|
|
17
|
+
[key: string]: any[];
|
|
18
|
+
} = {};
|
|
21
19
|
export function register(type: 'insertMenu', info: InsertMenuConfig): void;
|
|
22
20
|
export function register(type: string, info: any): void;
|
|
23
21
|
export function register(type: string, info: any) {
|
|
@@ -31,8 +29,8 @@ export function register(type: string, info: any) {
|
|
|
31
29
|
type: 'builder.register',
|
|
32
30
|
data: {
|
|
33
31
|
type,
|
|
34
|
-
info
|
|
35
|
-
}
|
|
32
|
+
info
|
|
33
|
+
}
|
|
36
34
|
};
|
|
37
35
|
try {
|
|
38
36
|
parent.postMessage(message, '*');
|
|
@@ -43,4 +41,4 @@ export function register(type: string, info: any) {
|
|
|
43
41
|
console.debug('Could not postmessage', err);
|
|
44
42
|
}
|
|
45
43
|
}
|
|
46
|
-
}
|
|
44
|
+
}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
const propertiesThatMustBeNumber = new Set(['lineHeight']);
|
|
2
2
|
const displayValues = new Set(['flex', 'none']);
|
|
3
|
-
|
|
4
3
|
const SHOW_WARNINGS = false;
|
|
5
|
-
|
|
6
4
|
type Styles = Record<string, string | number>;
|
|
7
|
-
|
|
8
5
|
const normalizeNumber = (value: number): number | undefined => {
|
|
9
6
|
if (Number.isNaN(value)) {
|
|
10
7
|
return undefined;
|
|
@@ -15,51 +12,47 @@ const normalizeNumber = (value: number): number | undefined => {
|
|
|
15
12
|
return value;
|
|
16
13
|
}
|
|
17
14
|
};
|
|
18
|
-
|
|
19
15
|
export const sanitizeReactNativeBlockStyles = (styles: Styles): Styles => {
|
|
20
16
|
return Object.keys(styles).reduce<Styles>((acc, key): Styles => {
|
|
21
17
|
const propertyValue = styles[key];
|
|
22
|
-
|
|
23
|
-
if (key === 'display' && !displayValues.has(propertyValue as string)) {
|
|
18
|
+
if (key === 'display' && !displayValues.has((propertyValue as string))) {
|
|
24
19
|
if (SHOW_WARNINGS) {
|
|
25
|
-
console.warn(
|
|
26
|
-
`Style value for key "display" must be "flex" or "none" but had ${propertyValue}`
|
|
27
|
-
);
|
|
20
|
+
console.warn(`Style value for key "display" must be "flex" or "none" but had ${propertyValue}`);
|
|
28
21
|
}
|
|
29
22
|
return acc;
|
|
30
23
|
}
|
|
31
|
-
|
|
32
|
-
if (
|
|
33
|
-
propertiesThatMustBeNumber.has(key) &&
|
|
34
|
-
typeof propertyValue !== 'number'
|
|
35
|
-
) {
|
|
24
|
+
if (propertiesThatMustBeNumber.has(key) && typeof propertyValue !== 'number') {
|
|
36
25
|
if (SHOW_WARNINGS) {
|
|
37
|
-
console.warn(
|
|
38
|
-
`Style key ${key} must be a number, but had value \`${styles[key]}\``
|
|
39
|
-
);
|
|
26
|
+
console.warn(`Style key ${key} must be a number, but had value \`${styles[key]}\``);
|
|
40
27
|
}
|
|
41
28
|
return acc;
|
|
42
29
|
}
|
|
43
|
-
|
|
44
30
|
if (typeof propertyValue === 'string') {
|
|
45
31
|
// `px` units need to be stripped and replaced with numbers
|
|
46
32
|
// https://regexr.com/6ualn
|
|
47
33
|
const isPixelUnit = propertyValue.match(/^-?(\d*)(\.?)(\d*)*px$/);
|
|
48
|
-
|
|
49
34
|
if (isPixelUnit) {
|
|
50
35
|
const newValue = parseFloat(propertyValue);
|
|
51
36
|
const normalizedValue = normalizeNumber(newValue);
|
|
52
37
|
if (normalizedValue) {
|
|
53
|
-
return {
|
|
38
|
+
return {
|
|
39
|
+
...acc,
|
|
40
|
+
[key]: normalizedValue
|
|
41
|
+
};
|
|
54
42
|
} else {
|
|
55
43
|
return acc;
|
|
56
44
|
}
|
|
57
45
|
} else if (propertyValue === '0') {
|
|
58
46
|
// 0 edge case needs to be handled
|
|
59
|
-
return {
|
|
47
|
+
return {
|
|
48
|
+
...acc,
|
|
49
|
+
[key]: 0
|
|
50
|
+
};
|
|
60
51
|
}
|
|
61
52
|
}
|
|
62
|
-
|
|
63
|
-
|
|
53
|
+
return {
|
|
54
|
+
...acc,
|
|
55
|
+
[key]: propertyValue
|
|
56
|
+
};
|
|
64
57
|
}, {});
|
|
65
|
-
}
|
|
58
|
+
}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { isBrowser } from './is-browser.js';
|
|
2
|
-
|
|
3
2
|
const settings: Settings = {};
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
export type Settings = {
|
|
4
|
+
customInsertMenu?: boolean;
|
|
5
|
+
};
|
|
7
6
|
export function setEditorSettings(newSettings: Settings) {
|
|
8
7
|
if (isBrowser()) {
|
|
9
8
|
Object.assign(settings, newSettings);
|
|
10
9
|
const message = {
|
|
11
10
|
type: 'builder.settingsChange',
|
|
12
|
-
data: settings
|
|
11
|
+
data: settings
|
|
13
12
|
};
|
|
14
13
|
parent.postMessage(message, '*');
|
|
15
14
|
}
|
|
16
|
-
}
|
|
15
|
+
}
|
package/src/functions/set.ts
CHANGED
|
@@ -8,19 +8,7 @@ export const set = (obj: any, _path: string | string[], value: any) => {
|
|
|
8
8
|
if (Object(obj) !== obj) {
|
|
9
9
|
return obj;
|
|
10
10
|
}
|
|
11
|
-
const path: string[] = Array.isArray(_path)
|
|
12
|
-
|
|
13
|
-
: (_path.toString().match(/[^.[\]]+/g) as string[]);
|
|
14
|
-
|
|
15
|
-
path
|
|
16
|
-
.slice(0, -1)
|
|
17
|
-
.reduce(
|
|
18
|
-
(a, c, i) =>
|
|
19
|
-
Object(a[c]) === a[c]
|
|
20
|
-
? a[c]
|
|
21
|
-
: (a[c] =
|
|
22
|
-
Math.abs(Number(path[i + 1])) >> 0 === +path[i + 1] ? [] : {}),
|
|
23
|
-
obj
|
|
24
|
-
)[path[path.length - 1]] = value;
|
|
11
|
+
const path: string[] = Array.isArray(_path) ? _path : (_path.toString().match(/[^.[\]]+/g) as string[]);
|
|
12
|
+
path.slice(0, -1).reduce((a, c, i) => Object(a[c]) === a[c] ? a[c] : a[c] = Math.abs(Number(path[i + 1])) >> 0 === +path[i + 1] ? [] : {}, obj)[path[path.length - 1]] = value;
|
|
25
13
|
return obj;
|
|
26
|
-
}
|
|
14
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { TARGET } from '../../constants/target';
|
|
2
|
-
import type { Nullable } from '../../helpers/nullable';
|
|
3
|
-
import { isBrowser } from '../is-browser';
|
|
4
|
-
|
|
1
|
+
import { TARGET } from '../../constants/target.js';
|
|
2
|
+
import type { Nullable } from '../../helpers/nullable.js';
|
|
3
|
+
import { isBrowser } from '../is-browser.js';
|
|
5
4
|
const getLocation = (): Nullable<URL> => {
|
|
6
5
|
if (TARGET === 'reactNative') {
|
|
7
6
|
return null;
|
|
@@ -13,20 +12,15 @@ const getLocation = (): Nullable<URL> => {
|
|
|
13
12
|
if (parsedLocation.pathname === '') {
|
|
14
13
|
parsedLocation.pathname = '/';
|
|
15
14
|
}
|
|
16
|
-
|
|
17
15
|
return parsedLocation;
|
|
18
16
|
} else {
|
|
19
17
|
console.warn('Cannot get location for tracking in non-browser environment');
|
|
20
18
|
return null;
|
|
21
19
|
}
|
|
22
20
|
};
|
|
23
|
-
|
|
24
|
-
const getUserAgent = () =>
|
|
25
|
-
(typeof navigator === 'object' && navigator.userAgent) || '';
|
|
26
|
-
|
|
21
|
+
const getUserAgent = () => typeof navigator === 'object' && navigator.userAgent || '';
|
|
27
22
|
export const getUserAttributes = () => {
|
|
28
23
|
const userAgent = getUserAgent();
|
|
29
|
-
|
|
30
24
|
const isMobile = {
|
|
31
25
|
Android() {
|
|
32
26
|
return userAgent.match(/Android/i);
|
|
@@ -44,24 +38,14 @@ export const getUserAttributes = () => {
|
|
|
44
38
|
return userAgent.match(/IEMobile/i) || userAgent.match(/WPDesktop/i);
|
|
45
39
|
},
|
|
46
40
|
any() {
|
|
47
|
-
return (
|
|
48
|
-
|
|
49
|
-
isMobile.BlackBerry() ||
|
|
50
|
-
isMobile.iOS() ||
|
|
51
|
-
isMobile.Opera() ||
|
|
52
|
-
isMobile.Windows() ||
|
|
53
|
-
TARGET === 'reactNative'
|
|
54
|
-
);
|
|
55
|
-
},
|
|
41
|
+
return isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows() || TARGET === 'reactNative';
|
|
42
|
+
}
|
|
56
43
|
};
|
|
57
|
-
|
|
58
44
|
const isTablet = userAgent.match(/Tablet|iPad/i);
|
|
59
|
-
|
|
60
45
|
const url = getLocation();
|
|
61
|
-
|
|
62
46
|
return {
|
|
63
47
|
urlPath: url?.pathname,
|
|
64
48
|
host: url?.host || url?.hostname,
|
|
65
|
-
device: isTablet ? 'tablet' : isMobile.any() ? 'mobile' : 'desktop'
|
|
49
|
+
device: isTablet ? 'tablet' : isMobile.any() ? 'mobile' : 'desktop'
|
|
66
50
|
};
|
|
67
|
-
}
|
|
51
|
+
}
|
|
@@ -7,7 +7,6 @@ import type { Dictionary } from '../../types/typescript.js';
|
|
|
7
7
|
import { isBrowser } from '../is-browser.js';
|
|
8
8
|
import { isEditing } from '../is-editing.js';
|
|
9
9
|
import { getUserAttributes } from './helpers.js';
|
|
10
|
-
|
|
11
10
|
interface Event {
|
|
12
11
|
/**
|
|
13
12
|
* The type of your event.
|
|
@@ -43,42 +42,41 @@ interface Event {
|
|
|
43
42
|
[index: string]: any;
|
|
44
43
|
};
|
|
45
44
|
}
|
|
46
|
-
|
|
47
45
|
type TrackingData = {
|
|
48
46
|
visitorId: string | undefined;
|
|
49
47
|
sessionId: string | undefined;
|
|
50
48
|
};
|
|
51
|
-
|
|
52
49
|
const getTrackingEventData = async ({
|
|
53
|
-
canTrack
|
|
50
|
+
canTrack
|
|
54
51
|
}: CanTrack): Promise<TrackingData> => {
|
|
55
52
|
if (!canTrack) {
|
|
56
|
-
return {
|
|
53
|
+
return {
|
|
54
|
+
visitorId: undefined,
|
|
55
|
+
sessionId: undefined
|
|
56
|
+
};
|
|
57
57
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
const sessionId = await getSessionId({
|
|
59
|
+
canTrack
|
|
60
|
+
});
|
|
61
|
+
const visitorId = getVisitorId({
|
|
62
|
+
canTrack
|
|
63
|
+
});
|
|
62
64
|
return {
|
|
63
65
|
sessionId,
|
|
64
|
-
visitorId
|
|
66
|
+
visitorId
|
|
65
67
|
};
|
|
66
68
|
};
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
[index: string]: any;
|
|
78
|
-
};
|
|
79
|
-
|
|
69
|
+
type EventProperties = Pick<Event, 'type'> & Pick<Event['data'], 'contentId' | 'variationId' | 'metadata'> & {
|
|
70
|
+
/**
|
|
71
|
+
* Your organization's API key.
|
|
72
|
+
*/
|
|
73
|
+
apiKey: Event['data']['ownerId'];
|
|
74
|
+
/**
|
|
75
|
+
* (Optional) Any additional (non-metadata) properties to add to the event.
|
|
76
|
+
*/
|
|
77
|
+
[index: string]: any;
|
|
78
|
+
};
|
|
80
79
|
export type EventProps = EventProperties & CanTrack;
|
|
81
|
-
|
|
82
80
|
const createEvent = async ({
|
|
83
81
|
type: eventType,
|
|
84
82
|
canTrack,
|
|
@@ -91,46 +89,43 @@ const createEvent = async ({
|
|
|
91
89
|
...properties,
|
|
92
90
|
metadata: {
|
|
93
91
|
url: location.href,
|
|
94
|
-
...metadata
|
|
92
|
+
...metadata
|
|
95
93
|
},
|
|
96
|
-
...(await getTrackingEventData({
|
|
94
|
+
...(await getTrackingEventData({
|
|
95
|
+
canTrack
|
|
96
|
+
})),
|
|
97
97
|
userAttributes: getUserAttributes(),
|
|
98
|
-
ownerId: apiKey
|
|
99
|
-
}
|
|
98
|
+
ownerId: apiKey
|
|
99
|
+
}
|
|
100
100
|
});
|
|
101
|
-
|
|
102
101
|
export async function _track(eventProps: EventProps) {
|
|
103
102
|
if (!eventProps.apiKey) {
|
|
104
|
-
logger.error(
|
|
105
|
-
'Missing API key for track call. Please provide your API key.'
|
|
106
|
-
);
|
|
103
|
+
logger.error('Missing API key for track call. Please provide your API key.');
|
|
107
104
|
return;
|
|
108
105
|
}
|
|
109
|
-
|
|
110
106
|
if (!eventProps.canTrack) {
|
|
111
107
|
return;
|
|
112
108
|
}
|
|
113
|
-
|
|
114
109
|
if (isEditing()) {
|
|
115
110
|
return;
|
|
116
111
|
}
|
|
117
112
|
if (!(isBrowser() || TARGET === 'reactNative')) {
|
|
118
113
|
return;
|
|
119
114
|
}
|
|
120
|
-
|
|
121
115
|
return fetch(`https://cdn.builder.io/api/v1/track`, {
|
|
122
116
|
method: 'POST',
|
|
123
117
|
body: JSON.stringify({
|
|
124
|
-
events: [await createEvent(eventProps)]
|
|
118
|
+
events: [await createEvent(eventProps)]
|
|
125
119
|
}),
|
|
126
120
|
headers: {
|
|
127
|
-
'content-type': 'application/json'
|
|
121
|
+
'content-type': 'application/json'
|
|
128
122
|
},
|
|
129
|
-
mode: 'cors'
|
|
130
|
-
}).catch(
|
|
123
|
+
mode: 'cors'
|
|
124
|
+
}).catch(err => {
|
|
131
125
|
console.error('Failed to track: ', err);
|
|
132
126
|
});
|
|
133
127
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
128
|
+
export const track = (args: EventProperties) => _track({
|
|
129
|
+
...args,
|
|
130
|
+
canTrack: true
|
|
131
|
+
})
|