@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
package/src/blocks/util.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Input attributes that are functions must be converted to strings before being serialized to JSON.
|
|
3
|
-
*/
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
5
|
-
export const serializeFn = (fnValue: Function) => {
|
|
6
|
-
const fnStr = fnValue.toString().trim();
|
|
7
|
-
|
|
8
|
-
// we need to account for a few different fn syntaxes:
|
|
9
|
-
// 1. `function name(args) => {code}`
|
|
10
|
-
// 2. `name(args) => {code}`
|
|
11
|
-
// 3. `(args) => {}`
|
|
12
|
-
const appendFunction =
|
|
13
|
-
!fnStr.startsWith('function') && !fnStr.startsWith('(');
|
|
14
|
-
|
|
15
|
-
return `return (${
|
|
16
|
-
appendFunction ? 'function ' : ''
|
|
17
|
-
}${fnStr}).apply(this, arguments)`;
|
|
18
|
-
};
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
<script context="module" lang="ts">
|
|
2
|
-
export type RenderBlockProps = {
|
|
3
|
-
block: BuilderBlock;
|
|
4
|
-
context: Writable<BuilderContextInterface>;
|
|
5
|
-
};
|
|
6
|
-
</script>
|
|
7
|
-
|
|
8
|
-
<script lang="ts">
|
|
9
|
-
import { writable } from "svelte/store";
|
|
10
|
-
|
|
11
|
-
import type { BuilderContextInterface } from "../../context/types.js";
|
|
12
|
-
import { getBlockActions } from "../../functions/get-block-actions.js";
|
|
13
|
-
import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
|
|
14
|
-
import { getBlockProperties } from "../../functions/get-block-properties.js";
|
|
15
|
-
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
16
|
-
import type { BuilderBlock } from "../../types/builder-block.js";
|
|
17
|
-
import BlockStyles from "./block-styles.svelte";
|
|
18
|
-
import {
|
|
19
|
-
getComponent,
|
|
20
|
-
getRepeatItemData,
|
|
21
|
-
isEmptyHtmlElement,
|
|
22
|
-
} from "./render-block.helpers.js";
|
|
23
|
-
import type { RenderComponentProps } from "./render-component.svelte";
|
|
24
|
-
import RenderRepeatedBlock from "./render-repeated-block.svelte";
|
|
25
|
-
import { TARGET } from "../../constants/target.js";
|
|
26
|
-
import { extractTextStyles } from "../../functions/extract-text-styles.js";
|
|
27
|
-
import RenderComponent from "./render-component.svelte";
|
|
28
|
-
import { getReactNativeBlockStyles } from "../../functions/get-react-native-block-styles.js";
|
|
29
|
-
import type { Writable } from "svelte/store";
|
|
30
|
-
|
|
31
|
-
const setAttrs = (node, attrs = {}) => {
|
|
32
|
-
const attrKeys = Object.keys(attrs);
|
|
33
|
-
const setup = (attr) => node.addEventListener(attr.substr(3), attrs[attr]);
|
|
34
|
-
const teardown = (attr) =>
|
|
35
|
-
node.removeEventListener(attr.substr(3), attrs[attr]);
|
|
36
|
-
attrKeys.map(setup);
|
|
37
|
-
return {
|
|
38
|
-
update(attrs = {}) {
|
|
39
|
-
const attrKeys = Object.keys(attrs);
|
|
40
|
-
attrKeys.map(teardown);
|
|
41
|
-
attrKeys.map(setup);
|
|
42
|
-
},
|
|
43
|
-
destroy() {
|
|
44
|
-
attrKeys.map(teardown);
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export let block: RenderBlockProps["block"];
|
|
50
|
-
export let context: RenderBlockProps["context"];
|
|
51
|
-
|
|
52
|
-
$: repeatItem = () => {
|
|
53
|
-
return getRepeatItemData({
|
|
54
|
-
block: block,
|
|
55
|
-
context: $context,
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
|
-
$: useBlock = () => {
|
|
59
|
-
return repeatItem()
|
|
60
|
-
? block
|
|
61
|
-
: getProcessedBlock({
|
|
62
|
-
block: block,
|
|
63
|
-
localState: $context.localState,
|
|
64
|
-
rootState: $context.rootState,
|
|
65
|
-
rootSetState: $context.rootSetState,
|
|
66
|
-
context: $context.context,
|
|
67
|
-
shouldEvaluateBindings: true,
|
|
68
|
-
});
|
|
69
|
-
};
|
|
70
|
-
$: canShowBlock = () => {
|
|
71
|
-
if ("hide" in useBlock()) {
|
|
72
|
-
return !useBlock().hide;
|
|
73
|
-
}
|
|
74
|
-
if ("show" in useBlock()) {
|
|
75
|
-
return useBlock().show;
|
|
76
|
-
}
|
|
77
|
-
return true;
|
|
78
|
-
};
|
|
79
|
-
$: actions = () => {
|
|
80
|
-
return getBlockActions({
|
|
81
|
-
block: useBlock(),
|
|
82
|
-
rootState: $context.rootState,
|
|
83
|
-
rootSetState: $context.rootSetState,
|
|
84
|
-
localState: $context.localState,
|
|
85
|
-
context: $context.context,
|
|
86
|
-
});
|
|
87
|
-
};
|
|
88
|
-
$: attributes = () => {
|
|
89
|
-
const blockProperties = getBlockProperties(useBlock());
|
|
90
|
-
return {
|
|
91
|
-
...blockProperties,
|
|
92
|
-
...(TARGET === "reactNative"
|
|
93
|
-
? {
|
|
94
|
-
style: getReactNativeBlockStyles({
|
|
95
|
-
block: useBlock(),
|
|
96
|
-
context: $context,
|
|
97
|
-
blockStyles: blockProperties.style,
|
|
98
|
-
}),
|
|
99
|
-
}
|
|
100
|
-
: {}),
|
|
101
|
-
};
|
|
102
|
-
};
|
|
103
|
-
$: childrenWithoutParentComponent = () => {
|
|
104
|
-
/**
|
|
105
|
-
* When there is no `componentRef`, there might still be children that need to be rendered. In this case,
|
|
106
|
-
* we render them outside of `componentRef`.
|
|
107
|
-
* NOTE: We make sure not to render this if `repeatItemData` is non-null, because that means we are rendering an array of
|
|
108
|
-
* blocks, and the children will be repeated within those blocks.
|
|
109
|
-
*/
|
|
110
|
-
const shouldRenderChildrenOutsideRef =
|
|
111
|
-
!component?.component && !repeatItem();
|
|
112
|
-
return shouldRenderChildrenOutsideRef ? useBlock().children ?? [] : [];
|
|
113
|
-
};
|
|
114
|
-
$: renderComponentProps = () => {
|
|
115
|
-
return {
|
|
116
|
-
blockChildren: useBlock().children ?? [],
|
|
117
|
-
componentRef: component?.component,
|
|
118
|
-
componentOptions: {
|
|
119
|
-
...getBlockComponentOptions(useBlock()),
|
|
120
|
-
/**
|
|
121
|
-
* These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
|
|
122
|
-
* they are provided to the component itself directly.
|
|
123
|
-
*/
|
|
124
|
-
...(!component?.noWrap
|
|
125
|
-
? {}
|
|
126
|
-
: {
|
|
127
|
-
attributes: {
|
|
128
|
-
...attributes(),
|
|
129
|
-
...actions(),
|
|
130
|
-
},
|
|
131
|
-
}),
|
|
132
|
-
},
|
|
133
|
-
context: childrenContext,
|
|
134
|
-
};
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
let component = getComponent({
|
|
138
|
-
block: block,
|
|
139
|
-
context: $context,
|
|
140
|
-
});
|
|
141
|
-
let Tag = block.tagName || "div";
|
|
142
|
-
let childrenContext = writable($context);
|
|
143
|
-
</script>
|
|
144
|
-
|
|
145
|
-
{#if canShowBlock()}
|
|
146
|
-
{#if !component?.noWrap}
|
|
147
|
-
{#if isEmptyHtmlElement(Tag)}
|
|
148
|
-
<svelte:element this={Tag} {...attributes()} use:setAttrs={actions()} />
|
|
149
|
-
{/if}
|
|
150
|
-
|
|
151
|
-
{#if !isEmptyHtmlElement(Tag) && repeatItem()}
|
|
152
|
-
{#each repeatItem() as data, index (index)}
|
|
153
|
-
<RenderRepeatedBlock repeatContext={data.context} block={data.block} />
|
|
154
|
-
{/each}
|
|
155
|
-
{/if}
|
|
156
|
-
|
|
157
|
-
{#if !isEmptyHtmlElement(Tag) && !repeatItem()}
|
|
158
|
-
<svelte:element this={Tag} {...attributes()} use:setAttrs={actions()}>
|
|
159
|
-
<RenderComponent {...renderComponentProps()} />
|
|
160
|
-
|
|
161
|
-
{#each childrenWithoutParentComponent() as child ("render-block-" + child.id)}
|
|
162
|
-
<svelte:self block={child} context={childrenContext} />
|
|
163
|
-
{/each}
|
|
164
|
-
|
|
165
|
-
{#each childrenWithoutParentComponent() as child ("block-style-" + child.id)}
|
|
166
|
-
<BlockStyles block={child} context={$childrenContext} />
|
|
167
|
-
{/each}
|
|
168
|
-
</svelte:element>
|
|
169
|
-
{/if}
|
|
170
|
-
{:else}
|
|
171
|
-
<RenderComponent {...renderComponentProps()} />
|
|
172
|
-
{/if}
|
|
173
|
-
{/if}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
<script context="module" lang="ts">
|
|
2
|
-
type ComponentOptions = {
|
|
3
|
-
[index: string]: any;
|
|
4
|
-
attributes?: {
|
|
5
|
-
[index: string]: any;
|
|
6
|
-
};
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export interface RenderComponentProps {
|
|
10
|
-
componentRef: any;
|
|
11
|
-
componentOptions: ComponentOptions;
|
|
12
|
-
blockChildren: BuilderBlock[];
|
|
13
|
-
context: Writable<BuilderContextInterface>;
|
|
14
|
-
}
|
|
15
|
-
</script>
|
|
16
|
-
|
|
17
|
-
<script lang="ts">
|
|
18
|
-
import type { BuilderBlock } from "../../types/builder-block.js";
|
|
19
|
-
import BlockStyles from "./block-styles.svelte";
|
|
20
|
-
import RenderBlock from "./render-block.svelte";
|
|
21
|
-
import type { BuilderContextInterface } from "../../context/types.js";
|
|
22
|
-
import type { Writable } from "svelte/store";
|
|
23
|
-
|
|
24
|
-
export let componentRef: RenderComponentProps["componentRef"];
|
|
25
|
-
export let componentOptions: RenderComponentProps["componentOptions"];
|
|
26
|
-
export let blockChildren: RenderComponentProps["blockChildren"];
|
|
27
|
-
export let context: RenderComponentProps["context"];
|
|
28
|
-
</script>
|
|
29
|
-
|
|
30
|
-
{#if componentRef}
|
|
31
|
-
<svelte:component this={componentRef} {...componentOptions}>
|
|
32
|
-
{#each blockChildren as child ("render-block-" + child.id)}
|
|
33
|
-
<RenderBlock block={child} {context} />
|
|
34
|
-
{/each}
|
|
35
|
-
|
|
36
|
-
{#each blockChildren as child ("block-style-" + child.id)}
|
|
37
|
-
<BlockStyles block={child} context={$context} />
|
|
38
|
-
{/each}
|
|
39
|
-
</svelte:component>
|
|
40
|
-
{/if}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
<script context="module" lang="ts">
|
|
2
|
-
type Props = {
|
|
3
|
-
block: BuilderBlock;
|
|
4
|
-
repeatContext: BuilderContextInterface;
|
|
5
|
-
};
|
|
6
|
-
</script>
|
|
7
|
-
|
|
8
|
-
<script lang="ts">
|
|
9
|
-
import { setContext } from "svelte";
|
|
10
|
-
import { writable } from "svelte/store";
|
|
11
|
-
|
|
12
|
-
import BuilderContext from "../../context/builder.context.js";
|
|
13
|
-
import type { BuilderContextInterface } from "../../context/types.js";
|
|
14
|
-
import type { BuilderBlock } from "../../types/builder-block";
|
|
15
|
-
import RenderBlock from "./render-block.svelte";
|
|
16
|
-
|
|
17
|
-
export let repeatContext: Props["repeatContext"];
|
|
18
|
-
export let block: Props["block"];
|
|
19
|
-
|
|
20
|
-
let store = writable(repeatContext);
|
|
21
|
-
|
|
22
|
-
setContext(BuilderContext.key, store);
|
|
23
|
-
</script>
|
|
24
|
-
|
|
25
|
-
<RenderBlock {block} context={store} />
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from './render-content.svelte';
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type { BuilderRenderState } from '../../context/types';
|
|
2
|
-
import type { BuilderContent } from '../../types/builder-content';
|
|
3
|
-
import type { Nullable } from '../../types/typescript';
|
|
4
|
-
import type { RenderContentProps } from './render-content.types';
|
|
5
|
-
|
|
6
|
-
export const getContextStateInitialValue = ({
|
|
7
|
-
content,
|
|
8
|
-
data,
|
|
9
|
-
locale,
|
|
10
|
-
}: Pick<RenderContentProps, 'content' | 'data' | 'locale'>) => {
|
|
11
|
-
const defaultValues: BuilderRenderState = {};
|
|
12
|
-
|
|
13
|
-
// set default values for content state inputs
|
|
14
|
-
content?.data?.inputs?.forEach((input) => {
|
|
15
|
-
if (
|
|
16
|
-
input.name &&
|
|
17
|
-
input.defaultValue !== undefined &&
|
|
18
|
-
content?.data?.state &&
|
|
19
|
-
content.data.state[input.name] === undefined
|
|
20
|
-
) {
|
|
21
|
-
defaultValues[input.name] = input.defaultValue;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const stateToUse: BuilderRenderState = {
|
|
26
|
-
...content?.data?.state,
|
|
27
|
-
...data,
|
|
28
|
-
...(locale ? { locale } : {}),
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
return { ...defaultValues, ...stateToUse };
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const getContentInitialValue = ({
|
|
35
|
-
content,
|
|
36
|
-
data,
|
|
37
|
-
}: Pick<RenderContentProps, 'content' | 'data'>): Nullable<BuilderContent> => {
|
|
38
|
-
return !content
|
|
39
|
-
? undefined
|
|
40
|
-
: {
|
|
41
|
-
...content,
|
|
42
|
-
data: {
|
|
43
|
-
...content?.data,
|
|
44
|
-
...data,
|
|
45
|
-
},
|
|
46
|
-
meta: content?.meta,
|
|
47
|
-
};
|
|
48
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { flattenState } from './evaluate';
|
|
2
|
-
|
|
3
|
-
describe('flatten state', () => {
|
|
4
|
-
it('should behave normally when no PROTO_STATE', () => {
|
|
5
|
-
const localState = {};
|
|
6
|
-
const rootState = { foo: 'bar' };
|
|
7
|
-
const flattened = flattenState(rootState, localState, undefined);
|
|
8
|
-
expect(flattened.foo).toEqual('bar');
|
|
9
|
-
flattened.foo = 'baz';
|
|
10
|
-
expect(rootState.foo).toEqual('baz');
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it('should shadow write ', () => {
|
|
14
|
-
const rootState = { foo: 'foo' };
|
|
15
|
-
const localState = { foo: 'baz' };
|
|
16
|
-
const flattened = flattenState(rootState, localState, undefined);
|
|
17
|
-
expect(() => (flattened.foo = 'bar')).toThrow(
|
|
18
|
-
'Writing to local state is not allowed as it is read-only.'
|
|
19
|
-
);
|
|
20
|
-
});
|
|
21
|
-
});
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
BuilderContextInterface,
|
|
3
|
-
BuilderRenderState,
|
|
4
|
-
} from '../context/types.js';
|
|
5
|
-
import { isBrowser } from './is-browser.js';
|
|
6
|
-
import { isEditing } from './is-editing.js';
|
|
7
|
-
|
|
8
|
-
export function evaluate({
|
|
9
|
-
code,
|
|
10
|
-
context,
|
|
11
|
-
localState,
|
|
12
|
-
rootState,
|
|
13
|
-
rootSetState,
|
|
14
|
-
event,
|
|
15
|
-
isExpression = true,
|
|
16
|
-
}: {
|
|
17
|
-
code: string;
|
|
18
|
-
event?: Event;
|
|
19
|
-
isExpression?: boolean;
|
|
20
|
-
} & Pick<
|
|
21
|
-
BuilderContextInterface,
|
|
22
|
-
'localState' | 'context' | 'rootState' | 'rootSetState'
|
|
23
|
-
>): any {
|
|
24
|
-
if (code === '') {
|
|
25
|
-
console.warn('Skipping evaluation of empty code block.');
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const builder = {
|
|
30
|
-
isEditing: isEditing(),
|
|
31
|
-
isBrowser: isBrowser(),
|
|
32
|
-
isServer: !isBrowser(),
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
// Be able to handle simple expressions like "state.foo" or "1 + 1"
|
|
36
|
-
// as well as full blocks like "var foo = "bar"; return foo"
|
|
37
|
-
const useReturn =
|
|
38
|
-
// we disable this for cases where we definitely don't want a return
|
|
39
|
-
isExpression &&
|
|
40
|
-
!(
|
|
41
|
-
code.includes(';') ||
|
|
42
|
-
code.includes(' return ') ||
|
|
43
|
-
code.trim().startsWith('return ')
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
const useCode = useReturn ? `return (${code});` : code;
|
|
47
|
-
|
|
48
|
-
try {
|
|
49
|
-
return new Function(
|
|
50
|
-
'builder',
|
|
51
|
-
'Builder' /* <- legacy */,
|
|
52
|
-
'state',
|
|
53
|
-
'context',
|
|
54
|
-
'event',
|
|
55
|
-
useCode
|
|
56
|
-
)(
|
|
57
|
-
builder,
|
|
58
|
-
builder,
|
|
59
|
-
flattenState(rootState, localState, rootSetState),
|
|
60
|
-
context,
|
|
61
|
-
event
|
|
62
|
-
);
|
|
63
|
-
} catch (e) {
|
|
64
|
-
console.warn(
|
|
65
|
-
'Builder custom code error: \n While Evaluating: \n ',
|
|
66
|
-
useCode,
|
|
67
|
-
'\n',
|
|
68
|
-
e
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function flattenState(
|
|
74
|
-
rootState: Record<string | symbol, any>,
|
|
75
|
-
localState: Record<string | symbol, any> | undefined,
|
|
76
|
-
rootSetState: ((rootState: BuilderRenderState) => void) | undefined
|
|
77
|
-
): BuilderRenderState {
|
|
78
|
-
if (rootState === localState) {
|
|
79
|
-
throw new Error('rootState === localState');
|
|
80
|
-
}
|
|
81
|
-
return new Proxy(rootState, {
|
|
82
|
-
get: (_, prop) => {
|
|
83
|
-
if (localState && prop in localState) {
|
|
84
|
-
return localState[prop];
|
|
85
|
-
}
|
|
86
|
-
return rootState[prop as string];
|
|
87
|
-
},
|
|
88
|
-
set: (_, prop, value) => {
|
|
89
|
-
if (localState && prop in localState) {
|
|
90
|
-
throw new Error(
|
|
91
|
-
'Writing to local state is not allowed as it is read-only.'
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
rootState[prop as string] = value;
|
|
95
|
-
rootSetState?.(rootState);
|
|
96
|
-
return true;
|
|
97
|
-
},
|
|
98
|
-
});
|
|
99
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { convertSearchParamsToQueryObject, getBuilderSearchParams } from '.';
|
|
2
|
-
|
|
3
|
-
const querystring =
|
|
4
|
-
'someotherValue=jklsjfdal&abc=klfdjklgfds&builder.cachebust=true&builder.preview=page&builder.noCache=true&__builder_editing__=true&builder.overrides.page=037948e52eaf4743afed464f02c70da4&builder.overrides.037948e52eaf4743afed464f02c70da4=037948e52eaf4743afed464f02c70da4&builder.overrides.page%3A%2F=037948e52eaf4743afed464f02c70da4&preview_theme_id=128854393017';
|
|
5
|
-
|
|
6
|
-
const url = new URL(`localhost:3000/about-us?${querystring}`);
|
|
7
|
-
|
|
8
|
-
describe('Get Builder SearchParams', () => {
|
|
9
|
-
test('correctly converts URLSearchParams to object', () => {
|
|
10
|
-
const output = convertSearchParamsToQueryObject(url.searchParams);
|
|
11
|
-
expect(output).toMatchSnapshot();
|
|
12
|
-
});
|
|
13
|
-
test('correctly extracts all builder params from a query object', () => {
|
|
14
|
-
const output = getBuilderSearchParams(
|
|
15
|
-
convertSearchParamsToQueryObject(url.searchParams)
|
|
16
|
-
);
|
|
17
|
-
expect(output).toMatchSnapshot();
|
|
18
|
-
});
|
|
19
|
-
});
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { generateContentUrl } from './generate-content-url';
|
|
2
|
-
import type { GetContentOptions } from './types';
|
|
3
|
-
|
|
4
|
-
const testKey = 'YJIGb4i01jvw0SRdL5Bt';
|
|
5
|
-
const testModel = 'page';
|
|
6
|
-
const testId = 'c1b81bab59704599b997574eb0736def';
|
|
7
|
-
|
|
8
|
-
const options = {
|
|
9
|
-
cachebust: 'true',
|
|
10
|
-
noCache: 'true',
|
|
11
|
-
'overrides.037948e52eaf4743afed464f02c70da4':
|
|
12
|
-
'037948e52eaf4743afed464f02c70da4',
|
|
13
|
-
'overrides.page': '037948e52eaf4743afed464f02c70da4',
|
|
14
|
-
'overrides.page:/': '037948e52eaf4743afed464f02c70da4',
|
|
15
|
-
preview: 'page',
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
describe('Generate Content URL', () => {
|
|
19
|
-
test('generates the proper value for a simple query', () => {
|
|
20
|
-
const output = generateContentUrl({
|
|
21
|
-
apiKey: testKey,
|
|
22
|
-
model: testModel,
|
|
23
|
-
query: { id: testId },
|
|
24
|
-
});
|
|
25
|
-
expect(output).toMatchSnapshot();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test('Handles overrides correctly', () => {
|
|
29
|
-
const output = generateContentUrl({
|
|
30
|
-
apiKey: testKey,
|
|
31
|
-
model: testModel,
|
|
32
|
-
query: { id: testId },
|
|
33
|
-
options,
|
|
34
|
-
});
|
|
35
|
-
expect(output).toMatchSnapshot();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test('generate content url with apiVersion as default', () => {
|
|
39
|
-
const output = generateContentUrl({
|
|
40
|
-
apiKey: testKey,
|
|
41
|
-
model: testModel,
|
|
42
|
-
query: { id: testId },
|
|
43
|
-
options,
|
|
44
|
-
});
|
|
45
|
-
expect(output).toMatchSnapshot();
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test('generate content url with apiVersion as v2', () => {
|
|
49
|
-
const output = generateContentUrl({
|
|
50
|
-
apiKey: testKey,
|
|
51
|
-
model: testModel,
|
|
52
|
-
query: { id: testId },
|
|
53
|
-
options,
|
|
54
|
-
apiVersion: 'v2',
|
|
55
|
-
});
|
|
56
|
-
expect(output).toMatchSnapshot();
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
test('generate content url with apiVersion as v3', () => {
|
|
60
|
-
const output = generateContentUrl({
|
|
61
|
-
apiKey: testKey,
|
|
62
|
-
model: testModel,
|
|
63
|
-
query: { id: testId },
|
|
64
|
-
options,
|
|
65
|
-
apiVersion: 'v3',
|
|
66
|
-
});
|
|
67
|
-
expect(output).toMatchSnapshot();
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
test('throw error when trying to generate content url with apiVersion as v1', () => {
|
|
71
|
-
expect(() => {
|
|
72
|
-
generateContentUrl({
|
|
73
|
-
apiKey: testKey,
|
|
74
|
-
model: testModel,
|
|
75
|
-
query: { id: testId },
|
|
76
|
-
options,
|
|
77
|
-
apiVersion: 'v1' as GetContentOptions['apiVersion'],
|
|
78
|
-
});
|
|
79
|
-
}).toThrow(`Invalid apiVersion: expected 'v2' or 'v3', received 'v1'`);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test('throw error when trying to generate content url with an invalid apiVersion value', () => {
|
|
83
|
-
expect(() => {
|
|
84
|
-
generateContentUrl({
|
|
85
|
-
apiKey: testKey,
|
|
86
|
-
model: testModel,
|
|
87
|
-
query: { id: testId },
|
|
88
|
-
options,
|
|
89
|
-
apiVersion: 'INVALID_API_VERSION' as GetContentOptions['apiVersion'],
|
|
90
|
-
});
|
|
91
|
-
}).toThrow(
|
|
92
|
-
`Invalid apiVersion: expected 'v2' or 'v3', received 'INVALID_API_VERSION'`
|
|
93
|
-
);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
test('generate content url with enrich option true', () => {
|
|
97
|
-
const output = generateContentUrl({
|
|
98
|
-
apiKey: testKey,
|
|
99
|
-
model: testModel,
|
|
100
|
-
enrich: true,
|
|
101
|
-
});
|
|
102
|
-
expect(output).toMatchSnapshot();
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
test('generate content url with enrich option not present', () => {
|
|
106
|
-
const output = generateContentUrl({
|
|
107
|
-
apiKey: testKey,
|
|
108
|
-
model: testModel,
|
|
109
|
-
});
|
|
110
|
-
expect(output).toMatchSnapshot();
|
|
111
|
-
});
|
|
112
|
-
});
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { BuilderBlock } from '../types/builder-block.js';
|
|
2
|
-
import { getProcessedBlock } from './get-processed-block.js';
|
|
3
|
-
|
|
4
|
-
test('Can process bindings', () => {
|
|
5
|
-
const block: BuilderBlock = {
|
|
6
|
-
'@type': '@builder.io/sdk:Element',
|
|
7
|
-
properties: {
|
|
8
|
-
foo: 'bar',
|
|
9
|
-
},
|
|
10
|
-
bindings: {
|
|
11
|
-
'properties.foo': '"baz"',
|
|
12
|
-
'responsiveStyles.large.zIndex': '1 + 1',
|
|
13
|
-
'properties.test': 'state.test',
|
|
14
|
-
'properties.block': `
|
|
15
|
-
const foo = 'bar';
|
|
16
|
-
return foo;
|
|
17
|
-
`,
|
|
18
|
-
'properties.isEditing': 'builder.isEditing',
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
const processed = getProcessedBlock({
|
|
22
|
-
block,
|
|
23
|
-
context: {},
|
|
24
|
-
rootState: { test: 'hello' },
|
|
25
|
-
rootSetState: undefined,
|
|
26
|
-
localState: undefined,
|
|
27
|
-
shouldEvaluateBindings: true,
|
|
28
|
-
});
|
|
29
|
-
expect(processed).not.toEqual(block);
|
|
30
|
-
expect(processed.properties?.foo).toEqual('baz');
|
|
31
|
-
expect(processed.properties?.test).toEqual('hello');
|
|
32
|
-
expect(processed.properties?.block).toEqual('bar');
|
|
33
|
-
expect(processed.properties?.isEditing).toEqual(false);
|
|
34
|
-
expect(processed.responsiveStyles?.large?.zIndex).toEqual(2);
|
|
35
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { onChange } from './on-change.js';
|
|
2
|
-
|
|
3
|
-
test('onChange can observe a shallow change', () => {
|
|
4
|
-
let changeHappend = false;
|
|
5
|
-
const obj = onChange({ foo: 'hi' }, () => (changeHappend = true));
|
|
6
|
-
obj.foo = 'yo';
|
|
7
|
-
expect(changeHappend).toBe(true);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
test('onChange can observe a deep change', () => {
|
|
11
|
-
let changeHappend = false;
|
|
12
|
-
const obj = onChange({ foo: { bar: 'hi' } }, () => (changeHappend = true));
|
|
13
|
-
obj.foo.bar = 'yo';
|
|
14
|
-
expect(changeHappend).toBe(true);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
test('Smoke test: callback is not fired if no properties updated', () => {
|
|
18
|
-
let changeHappend = false;
|
|
19
|
-
const obj = onChange({ foo: { bar: 'hi' } }, () => (changeHappend = true));
|
|
20
|
-
// Access some properties
|
|
21
|
-
obj.foo.bar;
|
|
22
|
-
expect(changeHappend).toBe(false);
|
|
23
|
-
});
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { set } from './set.js';
|
|
2
|
-
|
|
3
|
-
test('can shallow set a property', () => {
|
|
4
|
-
const obj = { foo: 'bar' };
|
|
5
|
-
set(obj, 'foo', 'baz');
|
|
6
|
-
expect(obj.foo).toBe('baz');
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
test('can deeply set a property', () => {
|
|
10
|
-
const obj = { foo: 'bar' };
|
|
11
|
-
set(obj, 'foo.bar', 'baz');
|
|
12
|
-
expect((obj.foo as any).bar).toBe('baz');
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
test('can deeply create arrays', () => {
|
|
16
|
-
const obj = { foo: 'bar' };
|
|
17
|
-
set(obj, 'foo.bar.0', 'hi');
|
|
18
|
-
expect((obj.foo as any).bar).toEqual(['hi']);
|
|
19
|
-
});
|
package/src/helpers/url.test.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { getTopLevelDomain } from './url.js';
|
|
2
|
-
|
|
3
|
-
describe('getTopLevelDomain', () => {
|
|
4
|
-
test('handles root domain', () => {
|
|
5
|
-
const output = getTopLevelDomain('example.com');
|
|
6
|
-
expect(output).toBe('example.com');
|
|
7
|
-
});
|
|
8
|
-
test('handles subdomain', () => {
|
|
9
|
-
const output = getTopLevelDomain('wwww.example.com');
|
|
10
|
-
expect(output).toBe('example.com');
|
|
11
|
-
});
|
|
12
|
-
test('handles subdomain with long suffix', () => {
|
|
13
|
-
const output = getTopLevelDomain('www.example.co.uk');
|
|
14
|
-
expect(output).toBe('example.co.uk');
|
|
15
|
-
});
|
|
16
|
-
test('handles localhost', () => {
|
|
17
|
-
const output = getTopLevelDomain('localhost');
|
|
18
|
-
expect(output).toBe('localhost');
|
|
19
|
-
|
|
20
|
-
const output2 = getTopLevelDomain('127.0.0.1');
|
|
21
|
-
expect(output2).toBe('127.0.0.1');
|
|
22
|
-
});
|
|
23
|
-
});
|
|
File without changes
|
|
File without changes
|
/package/package/components/{render-content/render-content.types.js → content/content.types.js}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|