@builder.io/sdk-svelte 0.4.5 → 0.5.1
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 +41 -29
- package/package/CHANGELOG.md +8 -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 +36 -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 +118 -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/components.context.d.ts +7 -0
- package/package/context/components.context.js +5 -0
- 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 +51 -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 +144 -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/components.context.ts +6 -0
- 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,84 @@
|
|
|
1
|
+
import { logger } from '../../helpers/logger';
|
|
2
|
+
import { set } from '../set';
|
|
3
|
+
import Interpreter from './interpreter.js';
|
|
4
|
+
const processCode = (code) => {
|
|
5
|
+
return code.split('\n').map(line => {
|
|
6
|
+
const trimmed = line.trim();
|
|
7
|
+
// this async wrapper doesn't work in JS-interpreter, so we drop it.
|
|
8
|
+
if (line.includes('__awaiter'))
|
|
9
|
+
return undefined;
|
|
10
|
+
// we find all state setter expressions and append a call to setRootState afterwards
|
|
11
|
+
const isStateSetter = trimmed.startsWith('state.');
|
|
12
|
+
if (!isStateSetter)
|
|
13
|
+
return line;
|
|
14
|
+
const [lhs, rhs] = trimmed.split('=');
|
|
15
|
+
const setStr = lhs.replace('state.', '').trim();
|
|
16
|
+
const setExpr = `setRootState('${setStr}', ${rhs.trim()})`;
|
|
17
|
+
return `
|
|
18
|
+
${line}
|
|
19
|
+
${setExpr}
|
|
20
|
+
`;
|
|
21
|
+
}).filter(Boolean).join('\n');
|
|
22
|
+
};
|
|
23
|
+
const getJSONValName = (val) => val + 'JSON';
|
|
24
|
+
export const runInNonNode = ({ builder, context, event, rootState, localState, rootSetState, useCode }) => {
|
|
25
|
+
const state = {
|
|
26
|
+
...rootState,
|
|
27
|
+
...localState
|
|
28
|
+
};
|
|
29
|
+
const properties = {
|
|
30
|
+
state,
|
|
31
|
+
Builder: builder,
|
|
32
|
+
builder,
|
|
33
|
+
context,
|
|
34
|
+
event
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Deserialize all properties from JSON strings to JS objects
|
|
38
|
+
*/
|
|
39
|
+
const prependedCode = Object.keys(properties).map(key => `var ${key} = JSON.parse(${getJSONValName(key)});`).join('\n');
|
|
40
|
+
const cleanedCode = processCode(useCode);
|
|
41
|
+
if (cleanedCode === '') {
|
|
42
|
+
logger.warn('Skipping evaluation of empty code block.');
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const transformed = `
|
|
46
|
+
function theFunction() {
|
|
47
|
+
${prependedCode}
|
|
48
|
+
|
|
49
|
+
${cleanedCode}
|
|
50
|
+
}
|
|
51
|
+
theFunction();
|
|
52
|
+
`;
|
|
53
|
+
const setRootState = (prop, value) => {
|
|
54
|
+
const newState = set(state, prop, value);
|
|
55
|
+
rootSetState?.(newState);
|
|
56
|
+
};
|
|
57
|
+
const initFunc = function (interpreter, globalObject) {
|
|
58
|
+
/**
|
|
59
|
+
* serialize all function args to JSON strings
|
|
60
|
+
*/
|
|
61
|
+
Object.keys(properties).forEach(key => {
|
|
62
|
+
const val = properties[key] || {};
|
|
63
|
+
const jsonVal = JSON.stringify(val);
|
|
64
|
+
interpreter.setProperty(globalObject, getJSONValName(key), jsonVal);
|
|
65
|
+
});
|
|
66
|
+
/**
|
|
67
|
+
* Add a JavaScript function "setRootState" to the interpreter's global object, that will be called whenever a
|
|
68
|
+
* state property is set. This function will update the state object.
|
|
69
|
+
*/
|
|
70
|
+
interpreter.setProperty(globalObject, 'setRootState', interpreter.createNativeFunction(setRootState));
|
|
71
|
+
};
|
|
72
|
+
try {
|
|
73
|
+
const myInterpreter = new Interpreter(transformed, initFunc);
|
|
74
|
+
myInterpreter.run();
|
|
75
|
+
const output = myInterpreter.pseudoToNative(myInterpreter.value);
|
|
76
|
+
return output;
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
logger.warn('Custom code error in non-node runtime. SDK can only execute ES5 JavaScript.', {
|
|
80
|
+
e
|
|
81
|
+
});
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { BuilderContextInterface } from '../../context/types';
|
|
2
|
+
export type ExecutorArgs = Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'> & {
|
|
3
|
+
useCode: string;
|
|
4
|
+
builder: {
|
|
5
|
+
isEditing: boolean | undefined;
|
|
6
|
+
isBrowser: boolean | undefined;
|
|
7
|
+
isServer: boolean | undefined;
|
|
8
|
+
};
|
|
9
|
+
event: Event | undefined;
|
|
10
|
+
};
|
|
@@ -1,23 +1,11 @@
|
|
|
1
|
-
const TEXT_STYLE_KEYS = [
|
|
2
|
-
'color',
|
|
3
|
-
'whiteSpace',
|
|
4
|
-
'direction',
|
|
5
|
-
'hyphens',
|
|
6
|
-
'overflowWrap',
|
|
7
|
-
];
|
|
1
|
+
const TEXT_STYLE_KEYS = ['color', 'whiteSpace', 'direction', 'hyphens', 'overflowWrap'];
|
|
8
2
|
/**
|
|
9
3
|
* Check if the key represent a CSS style property that applies to text
|
|
10
4
|
* See MDN docs for refrence of what properties apply to text.
|
|
11
5
|
* https://developer.mozilla.org/en-US/docs/Learn/CSS/Styling_text/Fundamentals#summary
|
|
12
6
|
*/
|
|
13
7
|
const isTextStyle = (key) => {
|
|
14
|
-
return
|
|
15
|
-
key.startsWith('font') ||
|
|
16
|
-
key.startsWith('text') ||
|
|
17
|
-
key.startsWith('letter') ||
|
|
18
|
-
key.startsWith('line') ||
|
|
19
|
-
key.startsWith('word') ||
|
|
20
|
-
key.startsWith('writing'));
|
|
8
|
+
return TEXT_STYLE_KEYS.includes(key) || key.startsWith('font') || key.startsWith('text') || key.startsWith('letter') || key.startsWith('line') || key.startsWith('word') || key.startsWith('writing');
|
|
21
9
|
};
|
|
22
10
|
/**
|
|
23
11
|
* Extract styles that apply to text from a style object.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { evaluate } from './evaluate
|
|
2
|
-
export const createEventHandler = (value, options) =>
|
|
1
|
+
import { evaluate } from './evaluate';
|
|
2
|
+
export const createEventHandler = (value, options) => event => evaluate({
|
|
3
3
|
code: value,
|
|
4
4
|
context: options.context,
|
|
5
5
|
localState: options.localState,
|
|
6
6
|
rootState: options.rootState,
|
|
7
7
|
rootSetState: options.rootSetState,
|
|
8
8
|
event,
|
|
9
|
-
isExpression: false
|
|
9
|
+
isExpression: false
|
|
10
10
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TARGET } from '../constants/target.js';
|
|
1
2
|
import { getEventHandlerName } from './event-handler-name.js';
|
|
2
3
|
import { createEventHandler } from './get-block-actions-handler.js';
|
|
3
4
|
export function getBlockActions(options) {
|
|
@@ -9,7 +10,19 @@ export function getBlockActions(options) {
|
|
|
9
10
|
continue;
|
|
10
11
|
}
|
|
11
12
|
const value = optionActions[key];
|
|
12
|
-
|
|
13
|
+
let eventHandlerName = getEventHandlerName(key);
|
|
14
|
+
if (options.stripPrefix) {
|
|
15
|
+
switch (TARGET) {
|
|
16
|
+
case 'vue2':
|
|
17
|
+
case 'vue3':
|
|
18
|
+
eventHandlerName = eventHandlerName.replace('v-on:', '');
|
|
19
|
+
break;
|
|
20
|
+
case 'svelte':
|
|
21
|
+
eventHandlerName = eventHandlerName.replace('on:', '');
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
obj[eventHandlerName] = createEventHandler(value, options);
|
|
13
26
|
}
|
|
14
27
|
return obj;
|
|
15
28
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import type { BuilderContextInterface } from '../context/types.js';
|
|
1
2
|
import type { BuilderBlock } from '../types/builder-block.js';
|
|
2
|
-
export declare function getBlockProperties(block
|
|
3
|
+
export declare function getBlockProperties({ block, context }: {
|
|
4
|
+
block: BuilderBlock;
|
|
5
|
+
context: BuilderContextInterface;
|
|
6
|
+
}): {
|
|
3
7
|
'builder-id': string | undefined;
|
|
4
8
|
style: string | Partial<CSSStyleDeclaration> | undefined;
|
|
5
9
|
class: string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TARGET } from '../constants/target.js';
|
|
2
2
|
import { convertStyleMapToCSSArray } from '../helpers/css.js';
|
|
3
|
+
import { getReactNativeBlockStyles } from './get-react-native-block-styles.js';
|
|
3
4
|
import { transformBlockProperties } from './transform-block-properties.js';
|
|
4
5
|
const extractRelevantRootBlockProperties = (block) => {
|
|
5
6
|
// currently we are only spreading the `href` property
|
|
@@ -29,18 +30,25 @@ const extractRelevantRootBlockProperties = (block) => {
|
|
|
29
30
|
// // anything set by dynamic bindings outside of predefined `BuilderBlock` properties
|
|
30
31
|
// ...remainingBlockProperties
|
|
31
32
|
// } = block;
|
|
32
|
-
return {
|
|
33
|
+
return {
|
|
34
|
+
href: block.href
|
|
35
|
+
};
|
|
33
36
|
};
|
|
34
|
-
export function getBlockProperties(block) {
|
|
37
|
+
export function getBlockProperties({ block, context }) {
|
|
35
38
|
const properties = {
|
|
36
39
|
...extractRelevantRootBlockProperties(block),
|
|
37
40
|
...block.properties,
|
|
38
41
|
'builder-id': block.id,
|
|
39
|
-
style: getStyleAttribute(block.style),
|
|
40
|
-
class: [block.id, 'builder-block', block.class, block.properties?.class]
|
|
41
|
-
.filter(Boolean)
|
|
42
|
-
.join(' '),
|
|
42
|
+
style: block.style ? getStyleAttribute(block.style) : undefined,
|
|
43
|
+
class: [block.id, 'builder-block', block.class, block.properties?.class].filter(Boolean).join(' ')
|
|
43
44
|
};
|
|
45
|
+
if (TARGET === 'reactNative') {
|
|
46
|
+
properties.style = getReactNativeBlockStyles({
|
|
47
|
+
block,
|
|
48
|
+
context,
|
|
49
|
+
blockStyles: properties.style
|
|
50
|
+
});
|
|
51
|
+
}
|
|
44
52
|
return transformBlockProperties(properties);
|
|
45
53
|
}
|
|
46
54
|
/**
|
|
@@ -49,9 +57,6 @@ export function getBlockProperties(block) {
|
|
|
49
57
|
* Additionally, Svelte, Vue and other frameworks use kebab-case styles, so we need to convert them.
|
|
50
58
|
*/
|
|
51
59
|
function getStyleAttribute(style) {
|
|
52
|
-
if (!style) {
|
|
53
|
-
return undefined;
|
|
54
|
-
}
|
|
55
60
|
switch (TARGET) {
|
|
56
61
|
case 'svelte':
|
|
57
62
|
case 'vue2':
|
|
@@ -61,6 +66,7 @@ function getStyleAttribute(style) {
|
|
|
61
66
|
case 'qwik':
|
|
62
67
|
case 'reactNative':
|
|
63
68
|
case 'react':
|
|
69
|
+
case 'rsc':
|
|
64
70
|
return style;
|
|
65
71
|
}
|
|
66
72
|
}
|
|
@@ -20,11 +20,9 @@ export const getBuilderSearchParams = (_options) => {
|
|
|
20
20
|
}
|
|
21
21
|
const options = normalizeSearchParams(_options);
|
|
22
22
|
const newOptions = {};
|
|
23
|
-
Object.keys(options).forEach(
|
|
23
|
+
Object.keys(options).forEach(key => {
|
|
24
24
|
if (key.startsWith(BUILDER_SEARCHPARAMS_PREFIX)) {
|
|
25
|
-
const trimmedKey = key
|
|
26
|
-
.replace(BUILDER_SEARCHPARAMS_PREFIX, '')
|
|
27
|
-
.replace(BUILDER_OPTIONS_PREFIX, '');
|
|
25
|
+
const trimmedKey = key.replace(BUILDER_SEARCHPARAMS_PREFIX, '').replace(BUILDER_OPTIONS_PREFIX, '');
|
|
28
26
|
newOptions[trimmedKey] = options[key];
|
|
29
27
|
}
|
|
30
28
|
});
|
|
@@ -37,6 +35,4 @@ export const getBuilderSearchParamsFromWindow = () => {
|
|
|
37
35
|
const searchParams = new URLSearchParams(window.location.search);
|
|
38
36
|
return getBuilderSearchParams(searchParams);
|
|
39
37
|
};
|
|
40
|
-
export const normalizeSearchParams = (searchParams) => searchParams instanceof URLSearchParams
|
|
41
|
-
? convertSearchParamsToQueryObject(searchParams)
|
|
42
|
-
: searchParams;
|
|
38
|
+
export const normalizeSearchParams = (searchParams) => searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { flatten } from '../../helpers/flatten.js';
|
|
2
|
-
import { getBuilderSearchParamsFromWindow, normalizeSearchParams
|
|
3
|
-
import { DEFAULT_API_VERSION } from '../../types/api-version';
|
|
2
|
+
import { getBuilderSearchParamsFromWindow, normalizeSearchParams } from '../get-builder-search-params/index.js';
|
|
3
|
+
import { DEFAULT_API_VERSION } from '../../types/api-version.js';
|
|
4
4
|
export const generateContentUrl = (options) => {
|
|
5
|
-
const { limit = 30, userAttributes, query, noTraverse = false, model, apiKey, includeRefs = true, enrich, locale, apiVersion = DEFAULT_API_VERSION
|
|
5
|
+
const { limit = 30, userAttributes, query, noTraverse = false, model, apiKey, includeRefs = true, enrich, locale, apiVersion = DEFAULT_API_VERSION } = options;
|
|
6
6
|
if (!apiKey) {
|
|
7
7
|
throw new Error('Missing API key');
|
|
8
8
|
}
|
|
@@ -12,7 +12,7 @@ export const generateContentUrl = (options) => {
|
|
|
12
12
|
const url = new URL(`https://cdn.builder.io/api/${apiVersion}/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}${locale ? `&locale=${locale}` : ''}${enrich ? `&enrich=${enrich}` : ''}`);
|
|
13
13
|
const queryOptions = {
|
|
14
14
|
...getBuilderSearchParamsFromWindow(),
|
|
15
|
-
...normalizeSearchParams(options.options || {})
|
|
15
|
+
...normalizeSearchParams(options.options || {})
|
|
16
16
|
};
|
|
17
17
|
const flattened = flatten(queryOptions);
|
|
18
18
|
for (const key in flattened) {
|
|
@@ -22,7 +22,9 @@ export const generateContentUrl = (options) => {
|
|
|
22
22
|
url.searchParams.set('userAttributes', JSON.stringify(userAttributes));
|
|
23
23
|
}
|
|
24
24
|
if (query) {
|
|
25
|
-
const flattened = flatten({
|
|
25
|
+
const flattened = flatten({
|
|
26
|
+
query
|
|
27
|
+
});
|
|
26
28
|
for (const key in flattened) {
|
|
27
29
|
url.searchParams.set(key, JSON.stringify(flattened[key]));
|
|
28
30
|
}
|
|
@@ -4,13 +4,9 @@ export declare function getContent(options: GetContentOptions): Promise<BuilderC
|
|
|
4
4
|
type ContentResults = {
|
|
5
5
|
results: BuilderContent[];
|
|
6
6
|
};
|
|
7
|
-
type ContentResponse = ContentResults | {
|
|
8
|
-
status: number;
|
|
9
|
-
message: string;
|
|
10
|
-
};
|
|
11
7
|
/**
|
|
12
8
|
* Exported only for testing purposes. Should not be used directly.
|
|
13
9
|
*/
|
|
14
|
-
export declare const processContentResult: (options: GetContentOptions, content: ContentResults) => Promise<ContentResults>;
|
|
15
|
-
export declare function getAllContent(options: GetContentOptions): Promise<
|
|
10
|
+
export declare const processContentResult: (options: GetContentOptions, content: ContentResults, url?: URL) => Promise<ContentResults>;
|
|
11
|
+
export declare function getAllContent(options: GetContentOptions): Promise<ContentResults | null>;
|
|
16
12
|
export {};
|
|
@@ -2,13 +2,17 @@ import { TARGET } from '../../constants/target.js';
|
|
|
2
2
|
import { handleABTesting } from '../../helpers/ab-tests.js';
|
|
3
3
|
import { getDefaultCanTrack } from '../../helpers/canTrack.js';
|
|
4
4
|
import { logger } from '../../helpers/logger.js';
|
|
5
|
+
import { getPreviewContent } from '../../helpers/preview-lru-cache/get.js';
|
|
5
6
|
import { fetch } from '../get-fetch.js';
|
|
6
7
|
import { isBrowser } from '../is-browser.js';
|
|
7
8
|
import { generateContentUrl } from './generate-content-url.js';
|
|
8
9
|
const checkContentHasResults = (content) => 'results' in content;
|
|
9
10
|
export async function getContent(options) {
|
|
10
|
-
const allContent = await getAllContent({
|
|
11
|
-
|
|
11
|
+
const allContent = await getAllContent({
|
|
12
|
+
...options,
|
|
13
|
+
limit: 1
|
|
14
|
+
});
|
|
15
|
+
if (allContent) {
|
|
12
16
|
return allContent.results[0] || null;
|
|
13
17
|
}
|
|
14
18
|
return null;
|
|
@@ -22,8 +26,17 @@ const fetchContent = async (options) => {
|
|
|
22
26
|
/**
|
|
23
27
|
* Exported only for testing purposes. Should not be used directly.
|
|
24
28
|
*/
|
|
25
|
-
export const processContentResult = async (options, content) => {
|
|
29
|
+
export const processContentResult = async (options, content, url = generateContentUrl(options)) => {
|
|
26
30
|
const canTrack = getDefaultCanTrack(options.canTrack);
|
|
31
|
+
const isPreviewing = url.search.includes(`preview=`);
|
|
32
|
+
if (TARGET === 'rsc' && isPreviewing) {
|
|
33
|
+
const newResults = [];
|
|
34
|
+
for (const item of content.results) {
|
|
35
|
+
const previewContent = getPreviewContent(url.searchParams);
|
|
36
|
+
newResults.push(previewContent || item);
|
|
37
|
+
}
|
|
38
|
+
content.results = newResults;
|
|
39
|
+
}
|
|
27
40
|
if (!canTrack)
|
|
28
41
|
return content;
|
|
29
42
|
if (!(isBrowser() || TARGET === 'reactNative'))
|
|
@@ -37,7 +50,10 @@ export const processContentResult = async (options, content) => {
|
|
|
37
50
|
try {
|
|
38
51
|
const newResults = [];
|
|
39
52
|
for (const item of content.results) {
|
|
40
|
-
newResults.push(await handleABTesting({
|
|
53
|
+
newResults.push(await handleABTesting({
|
|
54
|
+
item,
|
|
55
|
+
canTrack
|
|
56
|
+
}));
|
|
41
57
|
}
|
|
42
58
|
content.results = newResults;
|
|
43
59
|
}
|
|
@@ -51,8 +67,12 @@ export async function getAllContent(options) {
|
|
|
51
67
|
const url = generateContentUrl(options);
|
|
52
68
|
const content = await fetchContent(options);
|
|
53
69
|
if (!checkContentHasResults(content)) {
|
|
54
|
-
logger.error('Error fetching data. ', {
|
|
55
|
-
|
|
70
|
+
logger.error('Error fetching data. ', {
|
|
71
|
+
url,
|
|
72
|
+
content,
|
|
73
|
+
options
|
|
74
|
+
});
|
|
75
|
+
return null;
|
|
56
76
|
}
|
|
57
77
|
return processContentResult(options, content);
|
|
58
78
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BuilderContextInterface } from '../context/types.js';
|
|
2
2
|
import type { BuilderBlock } from '../types/builder-block.js';
|
|
3
|
-
export declare function getProcessedBlock({ block, context, shouldEvaluateBindings, localState, rootState, rootSetState
|
|
3
|
+
export declare function getProcessedBlock({ block, context, shouldEvaluateBindings, localState, rootState, rootSetState }: {
|
|
4
4
|
block: BuilderBlock;
|
|
5
5
|
/**
|
|
6
6
|
* In some cases, we want to avoid evaluating bindings and only want framework-specific block transformation. It is
|
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import { evaluate } from './evaluate
|
|
1
|
+
import { evaluate } from './evaluate';
|
|
2
2
|
import { fastClone } from './fast-clone.js';
|
|
3
3
|
import { set } from './set.js';
|
|
4
4
|
import { transformBlock } from './transform-block.js';
|
|
5
|
-
const evaluateBindings = ({ block, context, localState, rootState, rootSetState
|
|
5
|
+
const evaluateBindings = ({ block, context, localState, rootState, rootSetState }) => {
|
|
6
6
|
if (!block.bindings) {
|
|
7
7
|
return block;
|
|
8
8
|
}
|
|
9
9
|
const copy = fastClone(block);
|
|
10
10
|
const copied = {
|
|
11
11
|
...copy,
|
|
12
|
-
properties: {
|
|
13
|
-
|
|
12
|
+
properties: {
|
|
13
|
+
...copy.properties
|
|
14
|
+
},
|
|
15
|
+
actions: {
|
|
16
|
+
...copy.actions
|
|
17
|
+
}
|
|
14
18
|
};
|
|
15
19
|
for (const binding in block.bindings) {
|
|
16
20
|
const expression = block.bindings[binding];
|
|
@@ -19,13 +23,13 @@ const evaluateBindings = ({ block, context, localState, rootState, rootSetState,
|
|
|
19
23
|
localState,
|
|
20
24
|
rootState,
|
|
21
25
|
rootSetState,
|
|
22
|
-
context
|
|
26
|
+
context
|
|
23
27
|
});
|
|
24
28
|
set(copied, binding, value);
|
|
25
29
|
}
|
|
26
30
|
return copied;
|
|
27
31
|
};
|
|
28
|
-
export function getProcessedBlock({ block, context, shouldEvaluateBindings, localState, rootState, rootSetState
|
|
32
|
+
export function getProcessedBlock({ block, context, shouldEvaluateBindings, localState, rootState, rootSetState }) {
|
|
29
33
|
const transformedBlock = transformBlock(block);
|
|
30
34
|
if (shouldEvaluateBindings) {
|
|
31
35
|
return evaluateBindings({
|
|
@@ -33,7 +37,7 @@ export function getProcessedBlock({ block, context, shouldEvaluateBindings, loca
|
|
|
33
37
|
localState,
|
|
34
38
|
rootState,
|
|
35
39
|
rootSetState,
|
|
36
|
-
context
|
|
40
|
+
context
|
|
37
41
|
});
|
|
38
42
|
}
|
|
39
43
|
else {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BuilderContextInterface } from '../context/types.js';
|
|
2
2
|
import type { BuilderBlock } from '../types/builder-block.js';
|
|
3
|
-
export declare function getReactNativeBlockStyles({ block, context, blockStyles
|
|
3
|
+
export declare function getReactNativeBlockStyles({ block, context, blockStyles }: {
|
|
4
4
|
block: BuilderBlock;
|
|
5
5
|
context: BuilderContextInterface;
|
|
6
6
|
blockStyles: any;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { sanitizeReactNativeBlockStyles } from './sanitize-react-native-block-styles.js';
|
|
2
|
-
export function getReactNativeBlockStyles({ block, context, blockStyles
|
|
2
|
+
export function getReactNativeBlockStyles({ block, context, blockStyles }) {
|
|
3
3
|
const responsiveStyles = block.responsiveStyles;
|
|
4
4
|
if (!responsiveStyles) {
|
|
5
5
|
return {};
|
|
@@ -10,7 +10,7 @@ export function getReactNativeBlockStyles({ block, context, blockStyles, }) {
|
|
|
10
10
|
...(responsiveStyles.large || {}),
|
|
11
11
|
...(responsiveStyles.medium || {}),
|
|
12
12
|
...(responsiveStyles.small || {}),
|
|
13
|
-
...blockStyles
|
|
13
|
+
...blockStyles
|
|
14
14
|
};
|
|
15
15
|
const newStyles = sanitizeReactNativeBlockStyles(styles);
|
|
16
16
|
return newStyles;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TARGET } from '../constants/target.js';
|
|
2
2
|
// TODO: babel compile to include certain code only if the target matches
|
|
3
|
-
export function ifTarget({ targets, doThing, elseThing
|
|
3
|
+
export function ifTarget({ targets, doThing, elseThing }) {
|
|
4
4
|
if (TARGET && targets.includes(TARGET)) {
|
|
5
5
|
return doThing();
|
|
6
6
|
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { TARGET } from '../constants/target.js';
|
|
2
2
|
import { isIframe } from './is-iframe.js';
|
|
3
3
|
export function isEditing() {
|
|
4
|
-
return
|
|
5
|
-
(TARGET === 'reactNative' ||
|
|
6
|
-
window.location.search.indexOf('builder.frameEditing=') !== -1));
|
|
4
|
+
return isIframe() && (TARGET === 'reactNative' || window.location.search.indexOf('builder.frameEditing=') !== -1);
|
|
7
5
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { isBrowser } from './is-browser';
|
|
2
|
+
/**
|
|
3
|
+
* Identifies non-node server runtimes (edge, workers, serverless, etc.)
|
|
4
|
+
*/
|
|
5
|
+
export function isNonNodeServer() {
|
|
6
|
+
const hasNode = () => typeof process !== 'undefined' && process?.versions?.node;
|
|
7
|
+
return !isBrowser() && !hasNode();
|
|
8
|
+
}
|
|
@@ -8,7 +8,8 @@ export declare const components: RegisteredComponent[];
|
|
|
8
8
|
* @deprecated. Use the `customComponents` prop in RenderContent instead to provide your custom components to the builder SDK.
|
|
9
9
|
*/
|
|
10
10
|
export declare function registerComponent(component: any, info: ComponentInfo): void;
|
|
11
|
-
export declare const createRegisterComponentMessage: (
|
|
11
|
+
export declare const createRegisterComponentMessage: (info: ComponentInfo) => {
|
|
12
12
|
type: string;
|
|
13
13
|
data: ComponentInfo;
|
|
14
14
|
};
|
|
15
|
+
export declare const serializeComponentInfo: ({ inputs, ...info }: ComponentInfo) => ComponentInfo;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { serializeFn } from '../blocks/util.js';
|
|
2
1
|
import { fastClone } from './fast-clone.js';
|
|
3
2
|
/**
|
|
4
3
|
* @deprecated. Use the `customComponents` prop in RenderContent instead to provide your custom components to the builder SDK.
|
|
@@ -8,19 +7,32 @@ export const components = [];
|
|
|
8
7
|
* @deprecated. Use the `customComponents` prop in RenderContent instead to provide your custom components to the builder SDK.
|
|
9
8
|
*/
|
|
10
9
|
export function registerComponent(component, info) {
|
|
11
|
-
components.push({
|
|
10
|
+
components.push({
|
|
11
|
+
component,
|
|
12
|
+
...info
|
|
13
|
+
});
|
|
12
14
|
console.warn('registerComponent is deprecated. Use the `customComponents` prop in RenderContent instead to provide your custom components to the builder SDK.');
|
|
13
15
|
return component;
|
|
14
16
|
}
|
|
15
|
-
export const createRegisterComponentMessage = (
|
|
17
|
+
export const createRegisterComponentMessage = (info) => ({
|
|
16
18
|
type: 'builder.registerComponent',
|
|
17
|
-
data:
|
|
19
|
+
data: info
|
|
18
20
|
});
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
22
|
+
const serializeFn = (fnValue) => {
|
|
23
|
+
const fnStr = fnValue.toString().trim();
|
|
24
|
+
// we need to account for a few different fn syntaxes:
|
|
25
|
+
// 1. `function name(args) => {code}`
|
|
26
|
+
// 2. `name(args) => {code}`
|
|
27
|
+
// 3. `(args) => {}`
|
|
28
|
+
const appendFunction = !fnStr.startsWith('function') && !fnStr.startsWith('(');
|
|
29
|
+
return `return (${appendFunction ? 'function ' : ''}${fnStr}).apply(this, arguments)`;
|
|
30
|
+
};
|
|
19
31
|
const serializeValue = (value) => typeof value === 'function' ? serializeFn(value) : fastClone(value);
|
|
20
|
-
const
|
|
32
|
+
export const serializeComponentInfo = ({ inputs, ...info }) => ({
|
|
21
33
|
...fastClone(info),
|
|
22
|
-
inputs: inputs?.map(
|
|
34
|
+
inputs: inputs?.map(input => Object.entries(input).reduce((acc, [key, value]) => ({
|
|
23
35
|
...acc,
|
|
24
|
-
[key]: serializeValue(value)
|
|
25
|
-
}), {}))
|
|
36
|
+
[key]: serializeValue(value)
|
|
37
|
+
}), {}))
|
|
26
38
|
});
|
|
@@ -22,8 +22,7 @@ export const sanitizeReactNativeBlockStyles = (styles) => {
|
|
|
22
22
|
}
|
|
23
23
|
return acc;
|
|
24
24
|
}
|
|
25
|
-
if (propertiesThatMustBeNumber.has(key) &&
|
|
26
|
-
typeof propertyValue !== 'number') {
|
|
25
|
+
if (propertiesThatMustBeNumber.has(key) && typeof propertyValue !== 'number') {
|
|
27
26
|
if (SHOW_WARNINGS) {
|
|
28
27
|
console.warn(`Style key ${key} must be a number, but had value \`${styles[key]}\``);
|
|
29
28
|
}
|
|
@@ -37,7 +36,10 @@ export const sanitizeReactNativeBlockStyles = (styles) => {
|
|
|
37
36
|
const newValue = parseFloat(propertyValue);
|
|
38
37
|
const normalizedValue = normalizeNumber(newValue);
|
|
39
38
|
if (normalizedValue) {
|
|
40
|
-
return {
|
|
39
|
+
return {
|
|
40
|
+
...acc,
|
|
41
|
+
[key]: normalizedValue
|
|
42
|
+
};
|
|
41
43
|
}
|
|
42
44
|
else {
|
|
43
45
|
return acc;
|
|
@@ -45,9 +47,15 @@ export const sanitizeReactNativeBlockStyles = (styles) => {
|
|
|
45
47
|
}
|
|
46
48
|
else if (propertyValue === '0') {
|
|
47
49
|
// 0 edge case needs to be handled
|
|
48
|
-
return {
|
|
50
|
+
return {
|
|
51
|
+
...acc,
|
|
52
|
+
[key]: 0
|
|
53
|
+
};
|
|
49
54
|
}
|
|
50
55
|
}
|
|
51
|
-
return {
|
|
56
|
+
return {
|
|
57
|
+
...acc,
|
|
58
|
+
[key]: propertyValue
|
|
59
|
+
};
|
|
52
60
|
}, {});
|
|
53
61
|
};
|