@builder.io/sdk-react 0.4.5 → 0.5.1-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{sdk/blocks → blocks}/BaseText.d.ts +0 -1
- package/dist/{sdk/blocks → blocks}/BaseText.js +2 -2
- package/dist/{sdk/blocks → blocks}/button/button.d.ts +3 -2
- package/dist/{sdk/blocks → blocks}/button/button.js +3 -5
- package/dist/blocks/button/component-info.d.ts +2 -0
- package/dist/{sdk/blocks → blocks}/button/component-info.js +9 -13
- package/dist/blocks/columns/columns.d.ts +16 -0
- package/dist/{sdk/blocks → blocks}/columns/columns.js +13 -19
- package/dist/blocks/columns/component-info.d.ts +2 -0
- package/dist/{sdk/blocks → blocks}/columns/component-info.js +62 -83
- package/dist/blocks/custom-code/component-info.d.ts +2 -0
- package/dist/{sdk/blocks → blocks}/custom-code/component-info.js +7 -11
- package/dist/{sdk/blocks → blocks}/custom-code/custom-code.d.ts +0 -1
- package/dist/{sdk/blocks → blocks}/custom-code/custom-code.js +1 -1
- package/dist/blocks/embed/component-info.d.ts +2 -0
- package/dist/{sdk/blocks → blocks}/embed/component-info.js +8 -15
- package/dist/{sdk/blocks → blocks}/embed/embed.d.ts +0 -1
- package/dist/{sdk/blocks → blocks}/embed/embed.js +1 -1
- package/dist/blocks/embed/helpers.js +2 -0
- package/dist/blocks/form/component-info.d.ts +2 -0
- package/dist/{sdk/blocks → blocks}/form/component-info.js +94 -129
- package/dist/blocks/form/form.d.ts +2 -0
- package/dist/blocks/form/form.js +6 -0
- package/dist/blocks/fragment/component-info.d.ts +2 -0
- package/dist/{sdk/blocks → blocks}/fragment/component-info.js +1 -1
- package/dist/{sdk/blocks → blocks}/fragment/fragment.d.ts +0 -1
- package/dist/{sdk/blocks → blocks}/fragment/fragment.js +1 -1
- package/dist/blocks/helpers.d.ts +13 -0
- package/dist/blocks/helpers.js +40 -0
- package/dist/blocks/image/component-info.d.ts +2 -0
- package/dist/{sdk/blocks → blocks}/image/component-info.js +33 -63
- package/dist/{sdk/blocks → blocks}/image/image.d.ts +0 -1
- package/dist/{sdk/blocks → blocks}/image/image.helpers.js +2 -11
- package/dist/{sdk/blocks → blocks}/image/image.js +7 -7
- package/dist/blocks/img/component-info.d.ts +2 -0
- package/dist/{sdk/blocks → blocks}/img/component-info.js +4 -6
- package/dist/{sdk/blocks → blocks}/img/img.d.ts +3 -2
- package/dist/{sdk/blocks → blocks}/img/img.js +1 -1
- package/dist/blocks/input/component-info.d.ts +2 -0
- package/dist/{sdk/blocks → blocks}/input/component-info.js +15 -40
- package/dist/{sdk/blocks → blocks}/input/input.d.ts +3 -2
- package/dist/{sdk/blocks → blocks}/input/input.js +1 -1
- package/dist/blocks/raw-text/component-info.d.ts +2 -0
- package/dist/{sdk/blocks → blocks}/raw-text/component-info.js +3 -5
- package/dist/{sdk/blocks → blocks}/raw-text/raw-text.d.ts +0 -1
- package/dist/blocks/raw-text/raw-text.js +6 -0
- package/dist/blocks/section/component-info.d.ts +2 -0
- package/dist/{sdk/blocks → blocks}/section/component-info.js +13 -18
- package/dist/{sdk/blocks → blocks}/section/section.d.ts +3 -2
- package/dist/{sdk/blocks → blocks}/section/section.js +1 -1
- package/dist/blocks/select/component-info.d.ts +2 -0
- package/dist/{sdk/blocks → blocks}/select/component-info.js +22 -34
- package/dist/{sdk/blocks → blocks}/select/select.d.ts +3 -2
- package/dist/{sdk/blocks → blocks}/select/select.js +1 -1
- package/dist/blocks/submit-button/component-info.d.ts +2 -0
- package/dist/{sdk/blocks → blocks}/submit-button/component-info.js +5 -7
- package/dist/{sdk/blocks → blocks}/submit-button/submit-button.d.ts +3 -2
- package/dist/{sdk/blocks → blocks}/submit-button/submit-button.js +1 -1
- package/dist/blocks/symbol/component-info.d.ts +2 -0
- package/dist/{sdk/blocks → blocks}/symbol/component-info.js +12 -17
- package/dist/blocks/symbol/symbol.d.ts +23 -0
- package/dist/blocks/symbol/symbol.helpers.d.ts +14 -0
- package/dist/blocks/symbol/symbol.helpers.js +31 -0
- package/dist/blocks/symbol/symbol.js +45 -0
- package/dist/blocks/text/component-info.d.ts +2 -0
- package/dist/{sdk/blocks → blocks}/text/component-info.js +6 -7
- package/dist/{sdk/blocks → blocks}/text/text.d.ts +0 -1
- package/dist/{sdk/blocks → blocks}/text/text.js +2 -2
- package/dist/blocks/textarea/component-info.d.ts +2 -0
- package/dist/{sdk/blocks → blocks}/textarea/component-info.js +13 -19
- package/dist/{sdk/blocks → blocks}/textarea/textarea.d.ts +3 -2
- package/dist/{sdk/blocks → blocks}/textarea/textarea.js +1 -1
- package/dist/blocks/video/component-info.d.ts +2 -0
- package/dist/{sdk/blocks → blocks}/video/component-info.js +35 -55
- package/dist/{sdk/blocks → blocks}/video/video.d.ts +1 -1
- package/dist/{sdk/blocks → blocks}/video/video.js +2 -2
- package/dist/{sdk/components → components}/block/block.d.ts +2 -4
- package/dist/components/block/block.helpers.d.ts +13 -0
- package/dist/{sdk/components → components}/block/block.helpers.js +12 -29
- package/dist/components/block/block.js +94 -0
- package/dist/{sdk/components → components}/block/components/block-styles.d.ts +0 -1
- package/dist/{sdk/components → components}/block/components/block-styles.js +1 -1
- package/dist/components/block/components/block-wrapper.d.ts +16 -0
- package/dist/components/block/components/block-wrapper.js +36 -0
- package/dist/components/block/components/component-ref/component-ref.d.ts +3 -0
- package/dist/components/block/components/component-ref/component-ref.helpers.d.ts +28 -0
- package/dist/components/block/components/component-ref/component-ref.helpers.js +22 -0
- package/dist/components/block/components/component-ref/component-ref.js +23 -0
- package/dist/components/block/components/interactive-element.d.ts +11 -0
- package/dist/components/block/components/interactive-element.js +20 -0
- package/dist/components/block/components/repeated-block.d.ts +9 -0
- package/dist/{sdk/components → components}/block/components/repeated-block.js +3 -3
- package/dist/{sdk/components → components}/blocks/blocks-wrapper.d.ts +2 -5
- package/dist/{sdk/components → components}/blocks/blocks-wrapper.js +3 -3
- package/dist/components/blocks/blocks.d.ts +8 -0
- package/dist/{sdk/components → components}/blocks/blocks.js +9 -3
- package/dist/components/content/components/enable-editor.d.ts +9 -0
- package/dist/{sdk/components → components}/content/components/enable-editor.js +31 -39
- package/dist/{sdk/components/content/components/content-styles.d.ts → components/content/components/styles.d.ts} +1 -2
- package/dist/{sdk/components/content/components/content-styles.helpers.d.ts → components/content/components/styles.helpers.d.ts} +1 -1
- package/dist/{sdk/components/content/components/content-styles.helpers.js → components/content/components/styles.helpers.js} +3 -4
- package/dist/{sdk/components/content/components/content-styles.js → components/content/components/styles.js} +3 -3
- package/dist/components/content/content.d.ts +3 -0
- package/dist/components/content/content.helpers.d.ts +7 -0
- package/dist/components/content/content.helpers.js +30 -0
- package/dist/{sdk/components → components}/content/content.js +26 -40
- package/dist/{sdk/components/render-content/render-content.types.d.ts → components/content/content.types.d.ts} +4 -4
- package/dist/components/content-variants/content-variants.d.ts +9 -0
- package/dist/{sdk/components/render-content-variants/render-content-variants.js → components/content-variants/content-variants.js} +23 -22
- package/dist/{sdk/components/render-content-variants/render-content-variants.types.d.ts → components/content-variants/content-variants.types.d.ts} +5 -5
- package/dist/{sdk/components/render-content-variants → components/content-variants}/helpers.d.ts +7 -7
- package/dist/{sdk/components/render-content-variants → components/content-variants}/helpers.js +13 -22
- package/dist/{sdk/components → components}/inlined-script.d.ts +0 -1
- package/dist/{sdk/components → components}/inlined-script.js +1 -1
- package/dist/{sdk/components → components}/inlined-styles.d.ts +0 -1
- package/dist/{sdk/components → components}/inlined-styles.js +1 -1
- package/dist/{sdk/constants → constants}/builder-registered-components.js +34 -13
- package/dist/{sdk/constants → constants}/device-sizes.js +9 -8
- package/dist/constants/sdk-version.d.ts +1 -0
- package/dist/constants/sdk-version.js +1 -0
- package/dist/{sdk/context → context}/builder.context.js +1 -1
- package/dist/context/components.context.d.ts +3 -0
- package/dist/context/components.context.js +2 -0
- package/dist/{sdk/context → context}/types.d.ts +1 -1
- package/dist/functions/acorn_interpreter.d.ts +1 -0
- package/dist/functions/acorn_interpreter.js +3027 -0
- package/dist/functions/apply-patch-with-mutation.d.ts +10 -0
- package/dist/functions/apply-patch-with-mutation.js +54 -0
- package/dist/functions/apply-patch-with-mutation.test.js +53 -0
- package/dist/functions/evaluate/acorn.d.ts +0 -0
- package/dist/functions/evaluate/acorn.js +2432 -0
- package/dist/{sdk/functions → functions/evaluate}/evaluate.d.ts +5 -2
- package/dist/functions/evaluate/evaluate.js +70 -0
- package/dist/functions/evaluate/evaluate.test.js +23 -0
- package/dist/functions/evaluate/index.d.ts +1 -0
- package/dist/functions/evaluate/index.js +1 -0
- package/dist/functions/evaluate/interpreter.d.ts +2 -0
- package/dist/functions/evaluate/interpreter.js +3853 -0
- package/dist/functions/evaluate/non-node-runtime.d.ts +2 -0
- package/dist/functions/evaluate/non-node-runtime.js +84 -0
- package/dist/functions/evaluate/types.d.ts +10 -0
- package/dist/functions/evaluate.d.ts +23 -0
- package/dist/{sdk/functions → functions}/evaluate.js +28 -9
- package/dist/{sdk/functions → functions}/evaluate.test.js +11 -5
- package/dist/{sdk/functions → functions}/extract-text-styles.js +2 -14
- package/dist/{sdk/functions → functions}/get-block-actions-handler.js +3 -3
- package/dist/{sdk/functions → functions}/get-block-actions.d.ts +1 -0
- package/dist/functions/get-block-actions.js +28 -0
- package/dist/{sdk/functions → functions}/get-block-component-options.js +1 -1
- package/dist/functions/get-block-properties.d.ts +6 -0
- package/dist/{sdk/functions → functions}/get-block-properties.js +15 -9
- package/dist/{sdk/functions → functions}/get-builder-search-params/fn.test.js +1 -1
- package/dist/{sdk/functions → functions}/get-builder-search-params/index.js +3 -7
- package/dist/{sdk/functions → functions}/get-content/generate-content-url.js +7 -5
- package/dist/{sdk/functions → functions}/get-content/generate-content-url.test.js +31 -17
- package/dist/{sdk/functions → functions}/get-content/index.d.ts +2 -6
- package/dist/{sdk/functions → functions}/get-content/index.js +26 -6
- package/dist/functions/get-content/processCookies.d.ts +2 -0
- package/dist/functions/get-content/processCookies.js +3 -0
- package/dist/{sdk/functions → functions}/get-processed-block.d.ts +1 -1
- package/dist/{sdk/functions → functions}/get-processed-block.js +11 -7
- package/dist/{sdk/functions → functions}/get-processed-block.test.js +8 -6
- package/dist/{sdk/functions → functions}/get-react-native-block-styles.d.ts +1 -1
- package/dist/{sdk/functions → functions}/get-react-native-block-styles.js +2 -2
- package/dist/{sdk/functions → functions}/if-target.d.ts +1 -1
- package/dist/{sdk/functions → functions}/if-target.js +1 -1
- package/dist/functions/is-editing.js +5 -0
- package/dist/functions/is-non-node-server.d.ts +4 -0
- package/dist/functions/is-non-node-server.js +8 -0
- package/dist/{sdk/functions → functions}/on-change.js +1 -1
- package/dist/{sdk/functions → functions}/on-change.test.js +13 -3
- package/dist/{sdk/functions → functions}/register-component.d.ts +2 -1
- package/dist/functions/register-component.js +38 -0
- package/dist/{sdk/functions → functions}/register.js +2 -2
- package/dist/{sdk/functions → functions}/sanitize-react-native-block-styles.js +13 -5
- package/dist/{sdk/functions → functions}/set-editor-settings.js +1 -1
- package/dist/functions/set.js +14 -0
- package/dist/{sdk/functions → functions}/set.test.js +9 -3
- package/dist/{sdk/functions → functions}/track/helpers.js +6 -11
- package/dist/{sdk/functions → functions}/track/index.js +26 -14
- package/dist/{sdk/functions → functions}/track/interaction.js +15 -16
- package/dist/functions/transform-block-properties.d.ts +1 -0
- package/dist/{sdk/functions → functions}/transform-block-properties.js +2 -0
- package/dist/{sdk/helpers → helpers}/ab-tests.d.ts +2 -2
- package/dist/{sdk/helpers → helpers}/ab-tests.js +42 -30
- package/dist/{sdk/helpers → helpers}/canTrack.js +1 -1
- package/dist/{sdk/helpers → helpers}/cookie.d.ts +2 -2
- package/dist/{sdk/helpers → helpers}/cookie.js +13 -26
- package/dist/{sdk/helpers → helpers}/css.d.ts +1 -1
- package/dist/{sdk/helpers → helpers}/css.js +1 -1
- package/dist/{sdk/helpers → helpers}/flatten.js +8 -8
- package/dist/{sdk/helpers → helpers}/localStorage.d.ts +2 -2
- package/dist/{sdk/helpers → helpers}/localStorage.js +2 -2
- package/dist/{sdk/helpers → helpers}/logger.js +1 -1
- package/dist/helpers/preview-lru-cache/get.d.ts +1 -0
- package/dist/helpers/preview-lru-cache/get.js +7 -0
- package/dist/helpers/preview-lru-cache/helpers.d.ts +1 -0
- package/dist/helpers/preview-lru-cache/helpers.js +9 -0
- package/dist/helpers/preview-lru-cache/init.d.ts +6 -0
- package/dist/helpers/preview-lru-cache/init.js +15 -0
- package/dist/helpers/preview-lru-cache/set.d.ts +7 -0
- package/dist/helpers/preview-lru-cache/set.js +9 -0
- package/dist/helpers/preview-lru-cache/types.d.ts +12 -0
- package/dist/helpers/preview-lru-cache/types.js +6 -0
- package/dist/{sdk/helpers → helpers}/sessionId.d.ts +2 -2
- package/dist/{sdk/helpers → helpers}/sessionId.js +11 -4
- package/dist/{sdk/helpers → helpers}/uuid.js +1 -1
- package/dist/{sdk/helpers → helpers}/visitorId.d.ts +1 -1
- package/dist/{sdk/helpers → helpers}/visitorId.js +7 -4
- package/dist/{sdk/index-helpers → index-helpers}/blocks-exports.d.ts +2 -2
- package/dist/{sdk/index-helpers → index-helpers}/blocks-exports.js +2 -2
- package/dist/{sdk/index.d.ts → index.d.ts} +2 -2
- package/dist/{sdk/index.js → index.js} +1 -1
- package/dist/scripts/init-editing.js +110 -0
- package/dist/types/builder-props.d.ts +9 -0
- package/dist/{sdk/types → types}/components.d.ts +8 -2
- package/dist/{sdk/types → types}/enforced-partials.d.ts +1 -1
- package/dist/types/targets.d.ts +1 -0
- package/dist/{sdk/types → types}/typescript.d.ts +3 -0
- package/package.json +8 -16
- package/server/package.json +5 -0
- package/dist/sdk/blocks/button/component-info.d.ts +0 -2
- package/dist/sdk/blocks/columns/columns.d.ts +0 -16
- package/dist/sdk/blocks/columns/component-info.d.ts +0 -2
- package/dist/sdk/blocks/custom-code/component-info.d.ts +0 -2
- package/dist/sdk/blocks/embed/component-info.d.ts +0 -2
- package/dist/sdk/blocks/embed/helpers.js +0 -6
- package/dist/sdk/blocks/form/component-info.d.ts +0 -2
- package/dist/sdk/blocks/form/form.d.ts +0 -40
- package/dist/sdk/blocks/form/form.js +0 -203
- package/dist/sdk/blocks/fragment/component-info.d.ts +0 -2
- package/dist/sdk/blocks/image/component-info.d.ts +0 -2
- package/dist/sdk/blocks/img/component-info.d.ts +0 -2
- package/dist/sdk/blocks/input/component-info.d.ts +0 -2
- package/dist/sdk/blocks/raw-text/component-info.d.ts +0 -2
- package/dist/sdk/blocks/raw-text/raw-text.js +0 -6
- package/dist/sdk/blocks/section/component-info.d.ts +0 -2
- package/dist/sdk/blocks/select/component-info.d.ts +0 -2
- package/dist/sdk/blocks/submit-button/component-info.d.ts +0 -2
- package/dist/sdk/blocks/symbol/component-info.d.ts +0 -2
- package/dist/sdk/blocks/symbol/symbol.d.ts +0 -21
- package/dist/sdk/blocks/symbol/symbol.js +0 -71
- package/dist/sdk/blocks/text/component-info.d.ts +0 -2
- package/dist/sdk/blocks/textarea/component-info.d.ts +0 -2
- package/dist/sdk/blocks/util.d.ts +0 -4
- package/dist/sdk/blocks/util.js +0 -13
- package/dist/sdk/blocks/video/component-info.d.ts +0 -2
- package/dist/sdk/components/block/block.helpers.d.ts +0 -12
- package/dist/sdk/components/block/block.js +0 -124
- package/dist/sdk/components/block/components/component.d.ts +0 -20
- package/dist/sdk/components/block/components/component.js +0 -11
- package/dist/sdk/components/block/components/repeated-block.d.ts +0 -11
- package/dist/sdk/components/blocks/blocks.d.ts +0 -10
- package/dist/sdk/components/content/components/enable-editor.d.ts +0 -13
- package/dist/sdk/components/content/content.d.ts +0 -4
- package/dist/sdk/components/content/content.helpers.d.ts +0 -7
- package/dist/sdk/components/content/content.helpers.js +0 -30
- package/dist/sdk/components/content/content.types.d.ts +0 -38
- package/dist/sdk/components/content-variants/content-variants.d.ts +0 -5
- package/dist/sdk/components/content-variants/content-variants.js +0 -37
- package/dist/sdk/components/content-variants/helpers.d.ts +0 -17
- package/dist/sdk/components/content-variants/helpers.js +0 -184
- package/dist/sdk/components/render-block/block-styles.d.ts +0 -9
- package/dist/sdk/components/render-block/block-styles.js +0 -66
- package/dist/sdk/components/render-block/render-block.d.ts +0 -9
- package/dist/sdk/components/render-block/render-block.helpers.d.ts +0 -12
- package/dist/sdk/components/render-block/render-block.helpers.js +0 -86
- package/dist/sdk/components/render-block/render-block.js +0 -115
- package/dist/sdk/components/render-block/render-component.d.ts +0 -17
- package/dist/sdk/components/render-block/render-component.js +0 -11
- package/dist/sdk/components/render-block/render-repeated-block.d.ts +0 -9
- package/dist/sdk/components/render-block/render-repeated-block.js +0 -11
- package/dist/sdk/components/render-block/types.d.ts +0 -6
- package/dist/sdk/components/render-blocks.d.ts +0 -10
- package/dist/sdk/components/render-blocks.js +0 -45
- package/dist/sdk/components/render-content/builder-editing.d.ts +0 -3
- package/dist/sdk/components/render-content/builder-editing.js +0 -6
- package/dist/sdk/components/render-content/components/render-styles.d.ts +0 -9
- package/dist/sdk/components/render-content/components/render-styles.helpers.d.ts +0 -15
- package/dist/sdk/components/render-content/components/render-styles.helpers.js +0 -59
- package/dist/sdk/components/render-content/components/render-styles.js +0 -32
- package/dist/sdk/components/render-content/index.d.ts +0 -1
- package/dist/sdk/components/render-content/index.js +0 -1
- package/dist/sdk/components/render-content/render-content.d.ts +0 -4
- package/dist/sdk/components/render-content/render-content.helpers.d.ts +0 -7
- package/dist/sdk/components/render-content/render-content.helpers.js +0 -30
- package/dist/sdk/components/render-content/render-content.js +0 -343
- package/dist/sdk/components/render-content/wrap-component-ref.d.ts +0 -6
- package/dist/sdk/components/render-content/wrap-component-ref.js +0 -6
- package/dist/sdk/components/render-content-variants/render-content-variants.d.ts +0 -10
- package/dist/sdk/components/render-inlined-styles.d.ts +0 -7
- package/dist/sdk/components/render-inlined-styles.js +0 -6
- package/dist/sdk/constants/sdk-version.d.ts +0 -1
- package/dist/sdk/constants/sdk-version.js +0 -1
- package/dist/sdk/functions/get-block-actions.js +0 -15
- package/dist/sdk/functions/get-block-properties.d.ts +0 -7
- package/dist/sdk/functions/get-content/ab-testing.d.ts +0 -5
- package/dist/sdk/functions/get-content/ab-testing.js +0 -78
- package/dist/sdk/functions/is-editing.js +0 -7
- package/dist/sdk/functions/register-component.js +0 -26
- package/dist/sdk/functions/set.js +0 -21
- package/dist/sdk/functions/transform-block-properties.d.ts +0 -1
- package/dist/sdk/scripts/init-editing.js +0 -102
- package/dist/sdk/types/builder-props.d.ts +0 -10
- package/dist/sdk/types/targets.d.ts +0 -3
- package/dist/server/functions/get-builder-search-params/index.d.ts +0 -6
- package/dist/server/functions/get-builder-search-params/index.js +0 -36
- package/dist/server/functions/get-content/ab-testing.d.ts +0 -5
- package/dist/server/functions/get-content/ab-testing.js +0 -78
- package/dist/server/functions/get-content/generate-content-url.d.ts +0 -2
- package/dist/server/functions/get-content/generate-content-url.js +0 -31
- package/dist/server/functions/get-content/generate-content-url.test.d.ts +0 -1
- package/dist/server/functions/get-content/generate-content-url.test.js +0 -82
- package/dist/server/functions/get-content/index.d.ts +0 -11
- package/dist/server/functions/get-content/index.js +0 -40
- package/dist/server/functions/get-content/types.d.ts +0 -45
- package/dist/server/functions/get-fetch.d.ts +0 -1
- package/dist/server/functions/get-fetch.js +0 -11
- package/dist/server/functions/get-global-this.d.ts +0 -4
- package/dist/server/functions/get-global-this.js +0 -15
- package/dist/server/functions/is-browser.d.ts +0 -1
- package/dist/server/functions/is-browser.js +0 -3
- package/dist/server/helpers/ab-tests.d.ts +0 -8
- package/dist/server/helpers/ab-tests.js +0 -5
- package/dist/server/helpers/cookie.d.ts +0 -15
- package/dist/server/helpers/cookie.js +0 -65
- package/dist/server/helpers/flatten.d.ts +0 -6
- package/dist/server/helpers/flatten.js +0 -19
- package/dist/server/helpers/logger.d.ts +0 -5
- package/dist/server/helpers/logger.js +0 -6
- package/dist/server/helpers/nullable.d.ts +0 -2
- package/dist/server/helpers/nullable.js +0 -1
- package/dist/server/helpers/url.d.ts +0 -6
- package/dist/server/helpers/url.js +0 -15
- package/dist/server/types/api-version.d.ts +0 -2
- package/dist/server/types/api-version.js +0 -1
- package/dist/server/types/builder-block.d.ts +0 -66
- package/dist/server/types/builder-block.js +0 -1
- package/dist/server/types/builder-content.d.ts +0 -46
- package/dist/server/types/builder-content.js +0 -1
- package/dist/server/types/can-track.d.ts +0 -3
- package/dist/server/types/can-track.js +0 -1
- package/dist/server/types/input.d.ts +0 -121
- package/dist/server/types/input.js +0 -1
- package/dist/server/types/typescript.d.ts +0 -5
- package/dist/server/types/typescript.js +0 -1
- /package/dist/{sdk/blocks → blocks}/embed/helpers.d.ts +0 -0
- /package/dist/{sdk/blocks → blocks}/image/image.helpers.d.ts +0 -0
- /package/dist/{sdk/components → components}/block/types.d.ts +0 -0
- /package/dist/{sdk/components → components}/block/types.js +0 -0
- /package/dist/{sdk/components/render-block/types.js → components/content/content.types.js} +0 -0
- /package/dist/{sdk/components → components}/content/index.d.ts +0 -0
- /package/dist/{sdk/components → components}/content/index.js +0 -0
- /package/dist/{sdk/components → components}/content/wrap-component-ref.d.ts +0 -0
- /package/dist/{sdk/components → components}/content/wrap-component-ref.js +0 -0
- /package/dist/{sdk/components/content/content.types.js → components/content-variants/content-variants.types.js} +0 -0
- /package/dist/{sdk/constants → constants}/builder-registered-components.d.ts +0 -0
- /package/dist/{sdk/constants → constants}/device-sizes.d.ts +0 -0
- /package/dist/{sdk/constants → constants}/target.d.ts +0 -0
- /package/dist/{sdk/constants → constants}/target.js +0 -0
- /package/dist/{sdk/context → context}/builder.context.d.ts +0 -0
- /package/dist/{sdk/context → context}/types.js +0 -0
- /package/dist/{sdk/components/render-content-variants/render-content-variants.types.js → functions/apply-patch-with-mutation.test.d.ts} +0 -0
- /package/dist/{sdk/functions → functions}/camel-to-kebab-case.d.ts +0 -0
- /package/dist/{sdk/functions → functions}/camel-to-kebab-case.js +0 -0
- /package/dist/{sdk/components/render-content/render-content.types.js → functions/evaluate/evaluate.test.d.ts} +0 -0
- /package/dist/{sdk/functions/get-content → functions/evaluate}/types.js +0 -0
- /package/dist/{sdk/functions → functions}/evaluate.test.d.ts +0 -0
- /package/dist/{sdk/functions → functions}/event-handler-name.d.ts +0 -0
- /package/dist/{sdk/functions → functions}/event-handler-name.js +0 -0
- /package/dist/{sdk/functions → functions}/extract-text-styles.d.ts +0 -0
- /package/dist/{sdk/functions → functions}/fast-clone.d.ts +0 -0
- /package/dist/{sdk/functions → functions}/fast-clone.js +0 -0
- /package/dist/{sdk/functions → functions}/get-block-actions-handler.d.ts +0 -0
- /package/dist/{sdk/functions → functions}/get-block-component-options.d.ts +0 -0
- /package/dist/{sdk/functions → functions}/get-builder-search-params/fn.test.d.ts +0 -0
- /package/dist/{sdk/functions → functions}/get-builder-search-params/index.d.ts +0 -0
- /package/dist/{sdk/functions → functions}/get-content/generate-content-url.d.ts +0 -0
- /package/dist/{sdk/functions → functions}/get-content/generate-content-url.test.d.ts +0 -0
- /package/dist/{sdk/functions → functions}/get-content/types.d.ts +0 -0
- /package/dist/{server/functions → functions}/get-content/types.js +0 -0
- /package/dist/{sdk/functions → functions}/get-fetch.d.ts +0 -0
- /package/dist/{sdk/functions → functions}/get-fetch.js +0 -0
- /package/dist/{sdk/functions → functions}/get-global-this.d.ts +0 -0
- /package/dist/{sdk/functions → functions}/get-global-this.js +0 -0
- /package/dist/{sdk/functions → functions}/get-processed-block.test.d.ts +0 -0
- /package/dist/{sdk/functions → functions}/is-browser.d.ts +0 -0
- /package/dist/{sdk/functions → functions}/is-browser.js +0 -0
- /package/dist/{sdk/functions → functions}/is-editing.d.ts +0 -0
- /package/dist/{sdk/functions → functions}/is-iframe.d.ts +0 -0
- /package/dist/{sdk/functions → functions}/is-iframe.js +0 -0
- /package/dist/{sdk/functions → functions}/is-previewing.d.ts +0 -0
- /package/dist/{sdk/functions → functions}/is-previewing.js +0 -0
- /package/dist/{sdk/functions → functions}/on-change.d.ts +0 -0
- /package/dist/{sdk/functions → functions}/on-change.test.d.ts +0 -0
- /package/dist/{sdk/functions → functions}/register.d.ts +0 -0
- /package/dist/{sdk/functions → functions}/sanitize-react-native-block-styles.d.ts +0 -0
- /package/dist/{sdk/functions → functions}/set-editor-settings.d.ts +0 -0
- /package/dist/{sdk/functions → functions}/set.d.ts +0 -0
- /package/dist/{sdk/functions → functions}/set.test.d.ts +0 -0
- /package/dist/{sdk/functions → functions}/track/helpers.d.ts +0 -0
- /package/dist/{sdk/functions → functions}/track/index.d.ts +0 -0
- /package/dist/{sdk/functions → functions}/track/interaction.d.ts +0 -0
- /package/dist/{sdk/functions → functions}/transform-block.d.ts +0 -0
- /package/dist/{sdk/functions → functions}/transform-block.js +0 -0
- /package/dist/{sdk/helpers → helpers}/canTrack.d.ts +0 -0
- /package/dist/{sdk/helpers → helpers}/flatten.d.ts +0 -0
- /package/dist/{sdk/helpers → helpers}/logger.d.ts +0 -0
- /package/dist/{sdk/helpers → helpers}/nullable.d.ts +0 -0
- /package/dist/{sdk/helpers → helpers}/nullable.js +0 -0
- /package/dist/{sdk/helpers → helpers}/time.d.ts +0 -0
- /package/dist/{sdk/helpers → helpers}/time.js +0 -0
- /package/dist/{sdk/helpers → helpers}/url.d.ts +0 -0
- /package/dist/{sdk/helpers → helpers}/url.js +0 -0
- /package/dist/{sdk/helpers → helpers}/url.test.d.ts +0 -0
- /package/dist/{sdk/helpers → helpers}/url.test.js +0 -0
- /package/dist/{sdk/helpers → helpers}/uuid.d.ts +0 -0
- /package/dist/{sdk/index-helpers → index-helpers}/top-of-file.d.ts +0 -0
- /package/dist/{sdk/index-helpers → index-helpers}/top-of-file.js +0 -0
- /package/dist/{sdk/scripts → scripts}/init-editing.d.ts +0 -0
- /package/dist/{sdk/types → types}/api-version.d.ts +0 -0
- /package/dist/{sdk/types → types}/api-version.js +0 -0
- /package/dist/{sdk/types → types}/builder-block.d.ts +0 -0
- /package/dist/{sdk/types → types}/builder-block.js +0 -0
- /package/dist/{sdk/types → types}/builder-content.d.ts +0 -0
- /package/dist/{sdk/types → types}/builder-content.js +0 -0
- /package/dist/{sdk/types → types}/builder-props.js +0 -0
- /package/dist/{sdk/types → types}/can-track.d.ts +0 -0
- /package/dist/{sdk/types → types}/can-track.js +0 -0
- /package/dist/{sdk/types → types}/components.js +0 -0
- /package/dist/{sdk/types → types}/deep-partial.d.ts +0 -0
- /package/dist/{sdk/types → types}/deep-partial.js +0 -0
- /package/dist/{sdk/types → types}/element.d.ts +0 -0
- /package/dist/{sdk/types → types}/element.js +0 -0
- /package/dist/{sdk/types → types}/enforced-partials.js +0 -0
- /package/dist/{sdk/types → types}/input.d.ts +0 -0
- /package/dist/{sdk/types → types}/input.js +0 -0
- /package/dist/{sdk/types → types}/targets.js +0 -0
- /package/dist/{sdk/types → types}/typescript.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
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { BuilderContextInterface, BuilderRenderContext, BuilderRenderState } from '../context/types.js';
|
|
2
|
+
export declare const isNode: () => boolean;
|
|
3
|
+
export declare function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression }: {
|
|
4
|
+
code: string;
|
|
5
|
+
event?: Event;
|
|
6
|
+
isExpression?: boolean;
|
|
7
|
+
} & Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>): any;
|
|
8
|
+
type ExecutorArgs = {
|
|
9
|
+
useCode: string;
|
|
10
|
+
builder: {
|
|
11
|
+
isEditing: boolean | undefined;
|
|
12
|
+
isBrowser: boolean | undefined;
|
|
13
|
+
isServer: boolean | undefined;
|
|
14
|
+
};
|
|
15
|
+
state: BuilderRenderState;
|
|
16
|
+
context: BuilderRenderContext;
|
|
17
|
+
event: Event | undefined;
|
|
18
|
+
};
|
|
19
|
+
export declare const runInBrowser: ({ useCode, builder, state, context, event }: ExecutorArgs) => any;
|
|
20
|
+
export declare const runInNonNode: ({ useCode, builder, state, context, event }: ExecutorArgs) => void;
|
|
21
|
+
export declare const runInNode: (args: ExecutorArgs) => any;
|
|
22
|
+
export declare function flattenState(rootState: Record<string | symbol, any>, localState: Record<string | symbol, any> | undefined, rootSetState: ((rootState: BuilderRenderState) => void) | undefined): BuilderRenderState;
|
|
23
|
+
export {};
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { isBrowser } from './is-browser.js';
|
|
2
2
|
import { isEditing } from './is-editing.js';
|
|
3
|
-
export
|
|
3
|
+
export const isNode = () => {
|
|
4
|
+
return typeof window === 'undefined';
|
|
5
|
+
};
|
|
6
|
+
export function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true }) {
|
|
4
7
|
if (code === '') {
|
|
5
8
|
console.warn('Skipping evaluation of empty code block.');
|
|
6
9
|
return;
|
|
@@ -8,24 +11,40 @@ export function evaluate({ code, context, localState, rootState, rootSetState, e
|
|
|
8
11
|
const builder = {
|
|
9
12
|
isEditing: isEditing(),
|
|
10
13
|
isBrowser: isBrowser(),
|
|
11
|
-
isServer: !isBrowser()
|
|
14
|
+
isServer: !isBrowser()
|
|
12
15
|
};
|
|
13
16
|
// Be able to handle simple expressions like "state.foo" or "1 + 1"
|
|
14
17
|
// as well as full blocks like "var foo = "bar"; return foo"
|
|
15
18
|
const useReturn =
|
|
16
19
|
// we disable this for cases where we definitely don't want a return
|
|
17
|
-
isExpression &&
|
|
18
|
-
!(code.includes(';') ||
|
|
19
|
-
code.includes(' return ') ||
|
|
20
|
-
code.trim().startsWith('return '));
|
|
20
|
+
isExpression && !(code.includes(';') || code.includes(' return ') || code.trim().startsWith('return '));
|
|
21
21
|
const useCode = useReturn ? `return (${code});` : code;
|
|
22
|
+
const state = flattenState(rootState, localState, rootSetState);
|
|
23
|
+
const args = {
|
|
24
|
+
useCode,
|
|
25
|
+
builder,
|
|
26
|
+
state,
|
|
27
|
+
context,
|
|
28
|
+
event
|
|
29
|
+
};
|
|
30
|
+
if (isBrowser())
|
|
31
|
+
return runInBrowser(args);
|
|
32
|
+
if (isNode())
|
|
33
|
+
return runInNode(args);
|
|
34
|
+
return runInBrowser(args);
|
|
35
|
+
}
|
|
36
|
+
export const runInBrowser = ({ useCode, builder, state, context, event }) => {
|
|
22
37
|
try {
|
|
23
|
-
return new Function('builder', 'Builder' /* <- legacy */, 'state', 'context', 'event', useCode)(builder, builder,
|
|
38
|
+
return new Function('builder', 'Builder' /* <- legacy */, 'state', 'context', 'event', useCode)(builder, builder, state, context, event);
|
|
24
39
|
}
|
|
25
40
|
catch (e) {
|
|
26
41
|
console.warn('Builder custom code error: \n While Evaluating: \n ', useCode, '\n', e);
|
|
27
42
|
}
|
|
28
|
-
}
|
|
43
|
+
};
|
|
44
|
+
export const runInNonNode = ({ useCode, builder, state, context, event }) => { };
|
|
45
|
+
export const runInNode = (args) => {
|
|
46
|
+
return runInBrowser(args);
|
|
47
|
+
};
|
|
29
48
|
export function flattenState(rootState, localState, rootSetState) {
|
|
30
49
|
if (rootState === localState) {
|
|
31
50
|
throw new Error('rootState === localState');
|
|
@@ -44,6 +63,6 @@ export function flattenState(rootState, localState, rootSetState) {
|
|
|
44
63
|
rootState[prop] = value;
|
|
45
64
|
rootSetState?.(rootState);
|
|
46
65
|
return true;
|
|
47
|
-
}
|
|
66
|
+
}
|
|
48
67
|
});
|
|
49
68
|
}
|
|
@@ -1,17 +1,23 @@
|
|
|
1
|
-
import { flattenState } from './evaluate';
|
|
1
|
+
import { flattenState } from './evaluate.js';
|
|
2
2
|
describe('flatten state', () => {
|
|
3
3
|
it('should behave normally when no PROTO_STATE', () => {
|
|
4
4
|
const localState = {};
|
|
5
|
-
const rootState = {
|
|
5
|
+
const rootState = {
|
|
6
|
+
foo: 'bar'
|
|
7
|
+
};
|
|
6
8
|
const flattened = flattenState(rootState, localState, undefined);
|
|
7
9
|
expect(flattened.foo).toEqual('bar');
|
|
8
10
|
flattened.foo = 'baz';
|
|
9
11
|
expect(rootState.foo).toEqual('baz');
|
|
10
12
|
});
|
|
11
13
|
it('should shadow write ', () => {
|
|
12
|
-
const rootState = {
|
|
13
|
-
|
|
14
|
+
const rootState = {
|
|
15
|
+
foo: 'foo'
|
|
16
|
+
};
|
|
17
|
+
const localState = {
|
|
18
|
+
foo: 'baz'
|
|
19
|
+
};
|
|
14
20
|
const flattened = flattenState(rootState, localState, undefined);
|
|
15
|
-
expect(() =>
|
|
21
|
+
expect(() => flattened.foo = 'bar').toThrow('Writing to local state is not allowed as it is read-only.');
|
|
16
22
|
});
|
|
17
23
|
});
|
|
@@ -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
|
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { TARGET } from '../constants/target.js';
|
|
2
|
+
import { getEventHandlerName } from './event-handler-name.js';
|
|
3
|
+
import { createEventHandler } from './get-block-actions-handler.js';
|
|
4
|
+
export function getBlockActions(options) {
|
|
5
|
+
const obj = {};
|
|
6
|
+
const optionActions = options.block.actions ?? {};
|
|
7
|
+
for (const key in optionActions) {
|
|
8
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
9
|
+
if (!optionActions.hasOwnProperty(key)) {
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
const value = optionActions[key];
|
|
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);
|
|
26
|
+
}
|
|
27
|
+
return obj;
|
|
28
|
+
}
|
|
@@ -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
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { convertSearchParamsToQueryObject, getBuilderSearchParams } from '.';
|
|
1
|
+
import { convertSearchParamsToQueryObject, getBuilderSearchParams } from './index.js';
|
|
2
2
|
const querystring = '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';
|
|
3
3
|
const url = new URL(`localhost:3000/about-us?${querystring}`);
|
|
4
4
|
describe('Get Builder SearchParams', () => {
|
|
@@ -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
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { generateContentUrl } from './generate-content-url';
|
|
1
|
+
import { generateContentUrl } from './generate-content-url.js';
|
|
2
2
|
const testKey = 'YJIGb4i01jvw0SRdL5Bt';
|
|
3
3
|
const testModel = 'page';
|
|
4
4
|
const testId = 'c1b81bab59704599b997574eb0736def';
|
|
@@ -8,14 +8,16 @@ const options = {
|
|
|
8
8
|
'overrides.037948e52eaf4743afed464f02c70da4': '037948e52eaf4743afed464f02c70da4',
|
|
9
9
|
'overrides.page': '037948e52eaf4743afed464f02c70da4',
|
|
10
10
|
'overrides.page:/': '037948e52eaf4743afed464f02c70da4',
|
|
11
|
-
preview: 'page'
|
|
11
|
+
preview: 'page'
|
|
12
12
|
};
|
|
13
13
|
describe('Generate Content URL', () => {
|
|
14
14
|
test('generates the proper value for a simple query', () => {
|
|
15
15
|
const output = generateContentUrl({
|
|
16
16
|
apiKey: testKey,
|
|
17
17
|
model: testModel,
|
|
18
|
-
query: {
|
|
18
|
+
query: {
|
|
19
|
+
id: testId
|
|
20
|
+
}
|
|
19
21
|
});
|
|
20
22
|
expect(output).toMatchSnapshot();
|
|
21
23
|
});
|
|
@@ -23,8 +25,10 @@ describe('Generate Content URL', () => {
|
|
|
23
25
|
const output = generateContentUrl({
|
|
24
26
|
apiKey: testKey,
|
|
25
27
|
model: testModel,
|
|
26
|
-
query: {
|
|
27
|
-
|
|
28
|
+
query: {
|
|
29
|
+
id: testId
|
|
30
|
+
},
|
|
31
|
+
options
|
|
28
32
|
});
|
|
29
33
|
expect(output).toMatchSnapshot();
|
|
30
34
|
});
|
|
@@ -32,8 +36,10 @@ describe('Generate Content URL', () => {
|
|
|
32
36
|
const output = generateContentUrl({
|
|
33
37
|
apiKey: testKey,
|
|
34
38
|
model: testModel,
|
|
35
|
-
query: {
|
|
36
|
-
|
|
39
|
+
query: {
|
|
40
|
+
id: testId
|
|
41
|
+
},
|
|
42
|
+
options
|
|
37
43
|
});
|
|
38
44
|
expect(output).toMatchSnapshot();
|
|
39
45
|
});
|
|
@@ -41,9 +47,11 @@ describe('Generate Content URL', () => {
|
|
|
41
47
|
const output = generateContentUrl({
|
|
42
48
|
apiKey: testKey,
|
|
43
49
|
model: testModel,
|
|
44
|
-
query: {
|
|
50
|
+
query: {
|
|
51
|
+
id: testId
|
|
52
|
+
},
|
|
45
53
|
options,
|
|
46
|
-
apiVersion: 'v2'
|
|
54
|
+
apiVersion: 'v2'
|
|
47
55
|
});
|
|
48
56
|
expect(output).toMatchSnapshot();
|
|
49
57
|
});
|
|
@@ -51,9 +59,11 @@ describe('Generate Content URL', () => {
|
|
|
51
59
|
const output = generateContentUrl({
|
|
52
60
|
apiKey: testKey,
|
|
53
61
|
model: testModel,
|
|
54
|
-
query: {
|
|
62
|
+
query: {
|
|
63
|
+
id: testId
|
|
64
|
+
},
|
|
55
65
|
options,
|
|
56
|
-
apiVersion: 'v3'
|
|
66
|
+
apiVersion: 'v3'
|
|
57
67
|
});
|
|
58
68
|
expect(output).toMatchSnapshot();
|
|
59
69
|
});
|
|
@@ -62,9 +72,11 @@ describe('Generate Content URL', () => {
|
|
|
62
72
|
generateContentUrl({
|
|
63
73
|
apiKey: testKey,
|
|
64
74
|
model: testModel,
|
|
65
|
-
query: {
|
|
75
|
+
query: {
|
|
76
|
+
id: testId
|
|
77
|
+
},
|
|
66
78
|
options,
|
|
67
|
-
apiVersion: 'v1'
|
|
79
|
+
apiVersion: 'v1'
|
|
68
80
|
});
|
|
69
81
|
}).toThrow(`Invalid apiVersion: expected 'v2' or 'v3', received 'v1'`);
|
|
70
82
|
});
|
|
@@ -73,9 +85,11 @@ describe('Generate Content URL', () => {
|
|
|
73
85
|
generateContentUrl({
|
|
74
86
|
apiKey: testKey,
|
|
75
87
|
model: testModel,
|
|
76
|
-
query: {
|
|
88
|
+
query: {
|
|
89
|
+
id: testId
|
|
90
|
+
},
|
|
77
91
|
options,
|
|
78
|
-
apiVersion: 'INVALID_API_VERSION'
|
|
92
|
+
apiVersion: 'INVALID_API_VERSION'
|
|
79
93
|
});
|
|
80
94
|
}).toThrow(`Invalid apiVersion: expected 'v2' or 'v3', received 'INVALID_API_VERSION'`);
|
|
81
95
|
});
|
|
@@ -83,14 +97,14 @@ describe('Generate Content URL', () => {
|
|
|
83
97
|
const output = generateContentUrl({
|
|
84
98
|
apiKey: testKey,
|
|
85
99
|
model: testModel,
|
|
86
|
-
enrich: true
|
|
100
|
+
enrich: true
|
|
87
101
|
});
|
|
88
102
|
expect(output).toMatchSnapshot();
|
|
89
103
|
});
|
|
90
104
|
test('generate content url with enrich option not present', () => {
|
|
91
105
|
const output = generateContentUrl({
|
|
92
106
|
apiKey: testKey,
|
|
93
|
-
model: testModel
|
|
107
|
+
model: testModel
|
|
94
108
|
});
|
|
95
109
|
expect(output).toMatchSnapshot();
|
|
96
110
|
});
|
|
@@ -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>;
|
|
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
|