@builder.io/sdk-react 0.2.3-4 → 0.3.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/README.md +72 -3
- package/dist/sdk/blocks/columns/columns.js +5 -5
- package/dist/sdk/blocks/image/image.js +8 -7
- package/dist/sdk/blocks/symbol/symbol.js +3 -2
- package/dist/sdk/blocks/video/video.js +4 -1
- package/dist/sdk/components/render-block/block-styles.js +3 -1
- package/dist/sdk/components/render-block/render-block.helpers.d.ts +0 -1
- package/dist/sdk/components/render-block/render-block.helpers.js +8 -20
- package/dist/sdk/components/render-block/render-block.js +24 -15
- package/dist/sdk/components/render-block/render-repeated-block.js +3 -2
- package/dist/sdk/components/render-content/render-content.js +31 -12
- package/dist/sdk/components/render-content-variants/helpers.d.ts +12 -0
- package/dist/sdk/components/render-content-variants/helpers.js +154 -0
- package/dist/sdk/components/render-content-variants/render-content-variants.d.ts +5 -0
- package/dist/sdk/components/render-content-variants/render-content-variants.js +29 -0
- package/dist/sdk/components/render-inlined-styles.js +2 -2
- package/dist/sdk/constants/sdk-version.d.ts +1 -0
- package/dist/sdk/constants/sdk-version.js +1 -0
- package/dist/sdk/context/builder.context.js +3 -2
- package/dist/sdk/context/types.d.ts +17 -2
- package/dist/sdk/functions/evaluate.d.ts +4 -3
- package/dist/sdk/functions/evaluate.js +23 -2
- package/dist/sdk/functions/evaluate.test.d.ts +1 -0
- package/dist/sdk/functions/evaluate.test.js +17 -0
- package/dist/sdk/functions/get-block-actions-handler.d.ts +1 -1
- package/dist/sdk/functions/get-block-actions-handler.js +3 -1
- package/dist/sdk/functions/get-block-actions.d.ts +1 -1
- package/dist/sdk/functions/get-processed-block.d.ts +2 -2
- package/dist/sdk/functions/get-processed-block.js +16 -4
- package/dist/sdk/functions/get-processed-block.test.js +3 -1
- package/dist/sdk/helpers/canTrack.d.ts +1 -0
- package/dist/sdk/helpers/canTrack.js +2 -0
- package/dist/sdk/index.d.ts +1 -0
- package/dist/sdk/scripts/init-editing.js +2 -0
- package/package.json +5 -5
- package/CHANGELOG.md +0 -25
- package/packages/react/src/blocks/BaseText.tsx +0 -19
- package/packages/react/src/blocks/button/button.tsx +0 -45
- package/packages/react/src/blocks/button/component-info.ts +0 -42
- package/packages/react/src/blocks/columns/columns.tsx +0 -211
- package/packages/react/src/blocks/columns/component-info.ts +0 -254
- package/packages/react/src/blocks/custom-code/component-info.ts +0 -31
- package/packages/react/src/blocks/custom-code/custom-code.tsx +0 -76
- package/packages/react/src/blocks/embed/component-info.ts +0 -55
- package/packages/react/src/blocks/embed/embed.tsx +0 -59
- package/packages/react/src/blocks/embed/helpers.ts +0 -8
- package/packages/react/src/blocks/form/component-info.ts +0 -282
- package/packages/react/src/blocks/form/form.tsx +0 -320
- package/packages/react/src/blocks/fragment/component-info.ts +0 -10
- package/packages/react/src/blocks/fragment/fragment.tsx +0 -14
- package/packages/react/src/blocks/image/component-info.ts +0 -172
- package/packages/react/src/blocks/image/image.helpers.ts +0 -75
- package/packages/react/src/blocks/image/image.tsx +0 -144
- package/packages/react/src/blocks/img/component-info.ts +0 -21
- package/packages/react/src/blocks/img/img.tsx +0 -40
- package/packages/react/src/blocks/input/component-info.ts +0 -78
- package/packages/react/src/blocks/input/input.tsx +0 -33
- package/packages/react/src/blocks/raw-text/component-info.ts +0 -15
- package/packages/react/src/blocks/raw-text/raw-text.tsx +0 -18
- package/packages/react/src/blocks/section/component-info.ts +0 -50
- package/packages/react/src/blocks/section/section.tsx +0 -33
- package/packages/react/src/blocks/select/component-info.ts +0 -61
- package/packages/react/src/blocks/select/select.tsx +0 -35
- package/packages/react/src/blocks/submit-button/component-info.ts +0 -32
- package/packages/react/src/blocks/submit-button/submit-button.tsx +0 -17
- package/packages/react/src/blocks/symbol/component-info.ts +0 -43
- package/packages/react/src/blocks/symbol/symbol.tsx +0 -111
- package/packages/react/src/blocks/text/component-info.ts +0 -24
- package/packages/react/src/blocks/text/text.tsx +0 -20
- package/packages/react/src/blocks/textarea/component-info.ts +0 -48
- package/packages/react/src/blocks/textarea/textarea.tsx +0 -24
- package/packages/react/src/blocks/util.ts +0 -18
- package/packages/react/src/blocks/video/component-info.ts +0 -109
- package/packages/react/src/blocks/video/video.tsx +0 -84
- package/packages/react/src/components/render-block/block-styles.tsx +0 -98
- package/packages/react/src/components/render-block/render-block.helpers.ts +0 -138
- package/packages/react/src/components/render-block/render-block.tsx +0 -216
- package/packages/react/src/components/render-block/render-component.tsx +0 -52
- package/packages/react/src/components/render-block/render-repeated-block.tsx +0 -43
- package/packages/react/src/components/render-block/types.ts +0 -7
- package/packages/react/src/components/render-blocks.tsx +0 -97
- package/packages/react/src/components/render-content/builder-editing.tsx +0 -8
- package/packages/react/src/components/render-content/components/render-styles.helpers.ts +0 -79
- package/packages/react/src/components/render-content/components/render-styles.tsx +0 -45
- package/packages/react/src/components/render-content/index.ts +0 -1
- package/packages/react/src/components/render-content/render-content.helpers.ts +0 -48
- package/packages/react/src/components/render-content/render-content.tsx +0 -410
- package/packages/react/src/components/render-content/render-content.types.ts +0 -33
- package/packages/react/src/components/render-inlined-styles.tsx +0 -36
- package/packages/react/src/constants/builder-registered-components.ts +0 -42
- package/packages/react/src/constants/device-sizes.ts +0 -65
- package/packages/react/src/constants/target.ts +0 -2
- package/packages/react/src/context/builder.context.ts +0 -12
- package/packages/react/src/context/types.ts +0 -26
- package/packages/react/src/functions/camel-to-kebab-case.ts +0 -2
- package/packages/react/src/functions/evaluate.ts +0 -57
- package/packages/react/src/functions/event-handler-name.ts +0 -6
- package/packages/react/src/functions/extract-text-styles.ts +0 -39
- package/packages/react/src/functions/fast-clone.ts +0 -5
- package/packages/react/src/functions/get-block-actions-handler.ts +0 -20
- package/packages/react/src/functions/get-block-actions.ts +0 -25
- package/packages/react/src/functions/get-block-component-options.ts +0 -12
- package/packages/react/src/functions/get-block-properties.ts +0 -75
- package/packages/react/src/functions/get-builder-search-params/fn.test.ts +0 -19
- package/packages/react/src/functions/get-builder-search-params/index.ts +0 -50
- package/packages/react/src/functions/get-content/ab-testing.ts +0 -132
- package/packages/react/src/functions/get-content/generate-content-url.test.ts +0 -95
- package/packages/react/src/functions/get-content/generate-content-url.ts +0 -59
- package/packages/react/src/functions/get-content/index.ts +0 -62
- package/packages/react/src/functions/get-content/types.ts +0 -53
- package/packages/react/src/functions/get-fetch.ts +0 -18
- package/packages/react/src/functions/get-global-this.ts +0 -17
- package/packages/react/src/functions/get-processed-block.test.ts +0 -33
- package/packages/react/src/functions/get-processed-block.ts +0 -54
- package/packages/react/src/functions/get-react-native-block-styles.ts +0 -33
- package/packages/react/src/functions/if-target.ts +0 -20
- package/packages/react/src/functions/is-browser.ts +0 -3
- package/packages/react/src/functions/is-editing.ts +0 -10
- package/packages/react/src/functions/is-iframe.ts +0 -5
- package/packages/react/src/functions/is-previewing.ts +0 -14
- package/packages/react/src/functions/on-change.test.ts +0 -23
- package/packages/react/src/functions/on-change.ts +0 -29
- package/packages/react/src/functions/register-component.ts +0 -50
- package/packages/react/src/functions/register.ts +0 -46
- package/packages/react/src/functions/sanitize-react-native-block-styles.ts +0 -65
- package/packages/react/src/functions/set-editor-settings.ts +0 -16
- package/packages/react/src/functions/set.test.ts +0 -19
- package/packages/react/src/functions/set.ts +0 -26
- package/packages/react/src/functions/track/helpers.ts +0 -67
- package/packages/react/src/functions/track/index.ts +0 -136
- package/packages/react/src/functions/track/interaction.ts +0 -80
- package/packages/react/src/functions/transform-block-properties.ts +0 -3
- package/packages/react/src/functions/transform-block.ts +0 -6
- package/packages/react/src/helpers/ab-tests.ts +0 -22
- package/packages/react/src/helpers/cookie.ts +0 -107
- package/packages/react/src/helpers/css.ts +0 -42
- package/packages/react/src/helpers/flatten.ts +0 -24
- package/packages/react/src/helpers/localStorage.ts +0 -40
- package/packages/react/src/helpers/logger.ts +0 -6
- package/packages/react/src/helpers/nullable.ts +0 -4
- package/packages/react/src/helpers/sessionId.ts +0 -38
- package/packages/react/src/helpers/time.ts +0 -4
- package/packages/react/src/helpers/url.test.ts +0 -23
- package/packages/react/src/helpers/url.ts +0 -16
- package/packages/react/src/helpers/uuid.ts +0 -17
- package/packages/react/src/helpers/visitorId.ts +0 -40
- package/packages/react/src/index-helpers/blocks-exports.ts +0 -10
- package/packages/react/src/index-helpers/top-of-file.ts +0 -4
- package/packages/react/src/index.ts +0 -14
- package/packages/react/src/scripts/init-editing.ts +0 -123
- package/packages/react/src/types/api-version.ts +0 -2
- package/packages/react/src/types/builder-block.ts +0 -69
- package/packages/react/src/types/builder-content.ts +0 -46
- package/packages/react/src/types/can-track.ts +0 -3
- package/packages/react/src/types/components.ts +0 -117
- package/packages/react/src/types/deep-partial.ts +0 -7
- package/packages/react/src/types/element.ts +0 -60
- package/packages/react/src/types/input.ts +0 -125
- package/packages/react/src/types/targets.ts +0 -6
- package/packages/react/src/types/typescript.ts +0 -7
- package/packages/rsc/src/blocks/BaseText.jsx +0 -12
- package/packages/rsc/src/blocks/button/button.jsx +0 -37
- package/packages/rsc/src/blocks/button/component-info.js +0 -40
- package/packages/rsc/src/blocks/columns/columns.jsx +0 -172
- package/packages/rsc/src/blocks/columns/component-info.js +0 -241
- package/packages/rsc/src/blocks/custom-code/component-info.js +0 -30
- package/packages/rsc/src/blocks/custom-code/custom-code.jsx +0 -57
- package/packages/rsc/src/blocks/embed/component-info.js +0 -43
- package/packages/rsc/src/blocks/embed/embed.jsx +0 -45
- package/packages/rsc/src/blocks/embed/helpers.js +0 -9
- package/packages/rsc/src/blocks/form/component-info.js +0 -261
- package/packages/rsc/src/blocks/form/form.jsx +0 -260
- package/packages/rsc/src/blocks/fragment/component-info.js +0 -10
- package/packages/rsc/src/blocks/fragment/fragment.jsx +0 -9
- package/packages/rsc/src/blocks/image/component-info.js +0 -150
- package/packages/rsc/src/blocks/image/image.helpers.js +0 -48
- package/packages/rsc/src/blocks/image/image.jsx +0 -122
- package/packages/rsc/src/blocks/img/component-info.js +0 -19
- package/packages/rsc/src/blocks/img/img.jsx +0 -21
- package/packages/rsc/src/blocks/input/component-info.js +0 -73
- package/packages/rsc/src/blocks/input/input.jsx +0 -23
- package/packages/rsc/src/blocks/raw-text/component-info.js +0 -15
- package/packages/rsc/src/blocks/raw-text/raw-text.jsx +0 -14
- package/packages/rsc/src/blocks/section/component-info.js +0 -48
- package/packages/rsc/src/blocks/section/section.jsx +0 -27
- package/packages/rsc/src/blocks/select/component-info.js +0 -58
- package/packages/rsc/src/blocks/select/select.jsx +0 -24
- package/packages/rsc/src/blocks/submit-button/component-info.js +0 -27
- package/packages/rsc/src/blocks/submit-button/submit-button.jsx +0 -13
- package/packages/rsc/src/blocks/symbol/component-info.js +0 -42
- package/packages/rsc/src/blocks/symbol/symbol.jsx +0 -89
- package/packages/rsc/src/blocks/text/component-info.js +0 -23
- package/packages/rsc/src/blocks/text/text.jsx +0 -17
- package/packages/rsc/src/blocks/textarea/component-info.js +0 -46
- package/packages/rsc/src/blocks/textarea/textarea.jsx +0 -17
- package/packages/rsc/src/blocks/util.js +0 -8
- package/packages/rsc/src/blocks/video/component-info.js +0 -105
- package/packages/rsc/src/blocks/video/video.jsx +0 -63
- package/packages/rsc/src/components/render-block/block-styles.jsx +0 -88
- package/packages/rsc/src/components/render-block/render-block.helpers.js +0 -129
- package/packages/rsc/src/components/render-block/render-block.jsx +0 -201
- package/packages/rsc/src/components/render-block/render-component.jsx +0 -39
- package/packages/rsc/src/components/render-block/render-repeated-block.jsx +0 -27
- package/packages/rsc/src/components/render-block/types.js +0 -0
- package/packages/rsc/src/components/render-blocks.jsx +0 -92
- package/packages/rsc/src/components/render-content/builder-editing.jsx +0 -64
- package/packages/rsc/src/components/render-content/components/render-styles.helpers.js +0 -57
- package/packages/rsc/src/components/render-content/components/render-styles.jsx +0 -39
- package/packages/rsc/src/components/render-content/index.js +0 -4
- package/packages/rsc/src/components/render-content/render-content.helpers.js +0 -48
- package/packages/rsc/src/components/render-content/render-content.jsx +0 -253
- package/packages/rsc/src/components/render-content/render-content.types.js +0 -0
- package/packages/rsc/src/components/render-inlined-styles.jsx +0 -33
- package/packages/rsc/src/constants/builder-registered-components.js +0 -54
- package/packages/rsc/src/constants/device-sizes.js +0 -48
- package/packages/rsc/src/constants/target.js +0 -4
- package/packages/rsc/src/context/builder.context.js +0 -14
- package/packages/rsc/src/context/types.js +0 -0
- package/packages/rsc/src/functions/camel-to-kebab-case.js +0 -4
- package/packages/rsc/src/functions/evaluate.js +0 -6
- package/packages/rsc/src/functions/event-handler-name.js +0 -7
- package/packages/rsc/src/functions/extract-text-styles.js +0 -22
- package/packages/rsc/src/functions/fast-clone.js +0 -4
- package/packages/rsc/src/functions/get-block-actions-handler.js +0 -11
- package/packages/rsc/src/functions/get-block-actions.js +0 -18
- package/packages/rsc/src/functions/get-block-component-options.js +0 -28
- package/packages/rsc/src/functions/get-block-properties.js +0 -53
- package/packages/rsc/src/functions/get-builder-search-params/fn.test.js +0 -13
- package/packages/rsc/src/functions/get-builder-search-params/index.js +0 -38
- package/packages/rsc/src/functions/get-content/ab-testing.js +0 -99
- package/packages/rsc/src/functions/get-content/generate-content-url.js +0 -60
- package/packages/rsc/src/functions/get-content/generate-content-url.test.js +0 -82
- package/packages/rsc/src/functions/get-content/index.js +0 -83
- package/packages/rsc/src/functions/get-content/types.js +0 -0
- package/packages/rsc/src/functions/get-fetch.js +0 -14
- package/packages/rsc/src/functions/get-global-this.js +0 -18
- package/packages/rsc/src/functions/get-processed-block.js +0 -59
- package/packages/rsc/src/functions/get-processed-block.test.js +0 -32
- package/packages/rsc/src/functions/get-react-native-block-styles.js +0 -33
- package/packages/rsc/src/functions/if-target.js +0 -15
- package/packages/rsc/src/functions/is-browser.js +0 -6
- package/packages/rsc/src/functions/is-editing.js +0 -8
- package/packages/rsc/src/functions/is-iframe.js +0 -7
- package/packages/rsc/src/functions/is-previewing.js +0 -14
- package/packages/rsc/src/functions/on-change.js +0 -27
- package/packages/rsc/src/functions/on-change.test.js +0 -19
- package/packages/rsc/src/functions/register-component.js +0 -68
- package/packages/rsc/src/functions/register.js +0 -29
- package/packages/rsc/src/functions/sanitize-react-native-block-styles.js +0 -66
- package/packages/rsc/src/functions/set-editor-settings.js +0 -15
- package/packages/rsc/src/functions/set.js +0 -11
- package/packages/rsc/src/functions/set.test.js +0 -16
- package/packages/rsc/src/functions/track/helpers.js +0 -50
- package/packages/rsc/src/functions/track/index.js +0 -129
- package/packages/rsc/src/functions/track/interaction.js +0 -53
- package/packages/rsc/src/functions/transform-block-properties.js +0 -6
- package/packages/rsc/src/functions/transform-block.js +0 -6
- package/packages/rsc/src/helpers/ab-tests.js +0 -16
- package/packages/rsc/src/helpers/cookie.js +0 -81
- package/packages/rsc/src/helpers/css.js +0 -34
- package/packages/rsc/src/helpers/flatten.js +0 -34
- package/packages/rsc/src/helpers/localStorage.js +0 -35
- package/packages/rsc/src/helpers/logger.js +0 -9
- package/packages/rsc/src/helpers/nullable.js +0 -4
- package/packages/rsc/src/helpers/sessionId.js +0 -52
- package/packages/rsc/src/helpers/time.js +0 -5
- package/packages/rsc/src/helpers/url.js +0 -13
- package/packages/rsc/src/helpers/url.test.js +0 -21
- package/packages/rsc/src/helpers/uuid.js +0 -13
- package/packages/rsc/src/helpers/visitorId.js +0 -34
- package/packages/rsc/src/index-helpers/blocks-exports.js +0 -22
- package/packages/rsc/src/index-helpers/top-of-file.js +0 -2
- package/packages/rsc/src/index.js +0 -13
- package/packages/rsc/src/scripts/init-editing.js +0 -93
- package/packages/rsc/src/types/api-version.js +0 -4
- package/packages/rsc/src/types/builder-block.js +0 -0
- package/packages/rsc/src/types/builder-content.js +0 -0
- package/packages/rsc/src/types/can-track.js +0 -0
- package/packages/rsc/src/types/components.js +0 -0
- package/packages/rsc/src/types/deep-partial.js +0 -0
- package/packages/rsc/src/types/element.js +0 -0
- package/packages/rsc/src/types/input.js +0 -0
- package/packages/rsc/src/types/targets.js +0 -0
- package/packages/rsc/src/types/typescript.js +0 -0
- package/tsconfig.json +0 -28
- package/tsconfig.sdk.json +0 -10
- package/tsconfig.server.json +0 -10
- package/vite.config.ts +0 -91
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { checkShouldRunVariants, getVariantsScriptString } from "./helpers";
|
|
5
|
+
import RenderContent from "../render-content/render-content";
|
|
6
|
+
import { handleABTestingSync } from "../../helpers/ab-tests";
|
|
7
|
+
import { getDefaultCanTrack } from "../../helpers/canTrack";
|
|
8
|
+
function RenderContentVariants(props) {
|
|
9
|
+
const [variantScriptStr, setVariantScriptStr] = useState(() => getVariantsScriptString(Object.values(props.content?.variations || {}).map((value) => ({
|
|
10
|
+
id: value.id,
|
|
11
|
+
testRatio: value.testRatio,
|
|
12
|
+
})), props.content?.id || ""));
|
|
13
|
+
const [shouldRenderVariants, setShouldRenderVariants] = useState(() => checkShouldRunVariants({
|
|
14
|
+
canTrack: getDefaultCanTrack(props.canTrack),
|
|
15
|
+
content: props.content,
|
|
16
|
+
}));
|
|
17
|
+
const [ScriptTag, setScriptTag] = useState(() => "script");
|
|
18
|
+
const [TemplateTag, setTemplateTag] = useState(() => "template");
|
|
19
|
+
return (React.createElement(React.Fragment, null, shouldRenderVariants ? (React.createElement(React.Fragment, null,
|
|
20
|
+
Object.values(props.content.variations)?.map((variant) => (React.createElement(state.TemplateTag, { key: variant?.id, "data-template-variant-id": variant?.id },
|
|
21
|
+
React.createElement(RenderContent, { content: variant, apiKey: props.apiKey, apiVersion: props.apiVersion, canTrack: props.canTrack, customComponents: props.customComponents })))),
|
|
22
|
+
React.createElement(state.ScriptTag, { id: `variants-script-${props.content?.id}`, dangerouslySetInnerHTML: { __html: variantScriptStr } }),
|
|
23
|
+
React.createElement(RenderContent, { content: props.content, apiKey: props.apiKey, apiVersion: props.apiVersion, canTrack: props.canTrack, customComponents: props.customComponents }))) : (React.createElement(React.Fragment, null,
|
|
24
|
+
React.createElement(RenderContent, { content: handleABTestingSync({
|
|
25
|
+
item: props.content,
|
|
26
|
+
canTrack: getDefaultCanTrack(props.canTrack),
|
|
27
|
+
}), apiKey: props.apiKey, apiVersion: props.apiVersion, canTrack: props.canTrack, customComponents: props.customComponents })))));
|
|
28
|
+
}
|
|
29
|
+
export default RenderContentVariants;
|
|
@@ -3,9 +3,9 @@ import * as React from "react";
|
|
|
3
3
|
import { TARGET } from "../constants/target.js";
|
|
4
4
|
function RenderInlinedStyles(props) {
|
|
5
5
|
function tag() {
|
|
6
|
-
// NOTE: we have to
|
|
6
|
+
// NOTE: we have to obfuscate the name of the tag due to a limitation in the svelte-preprocessor plugin.
|
|
7
7
|
// https://github.com/sveltejs/vite-plugin-svelte/issues/315#issuecomment-1109000027
|
|
8
|
-
return "
|
|
8
|
+
return ("sty" + "le");
|
|
9
9
|
}
|
|
10
10
|
function injectedStyleScript() {
|
|
11
11
|
return `<${tag()}>${props.styles}</${tag()}>`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SDK_VERSION = "0.3.1";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const SDK_VERSION = "0.3.1";
|
|
@@ -2,8 +2,9 @@ import { createContext } from "react";
|
|
|
2
2
|
export default createContext({
|
|
3
3
|
content: null,
|
|
4
4
|
context: {},
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
localState: undefined,
|
|
6
|
+
rootSetState() { },
|
|
7
|
+
rootState: {},
|
|
7
8
|
apiKey: null,
|
|
8
9
|
apiVersion: undefined,
|
|
9
10
|
registeredComponents: {},
|
|
@@ -11,8 +11,23 @@ export type BuilderRenderContext = Record<string, unknown>;
|
|
|
11
11
|
export interface BuilderContextInterface {
|
|
12
12
|
content: Nullable<BuilderContent>;
|
|
13
13
|
context: BuilderRenderContext;
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
/**
|
|
15
|
+
* The state of the application.
|
|
16
|
+
*
|
|
17
|
+
* NOTE: see `localState` below to understand how it is different from `rootState`.
|
|
18
|
+
*/
|
|
19
|
+
rootState: BuilderRenderState;
|
|
20
|
+
/**
|
|
21
|
+
* Some frameworks have a `setState` function which needs to be invoked to notify
|
|
22
|
+
* the framework of state change. (other frameworks don't in which case it is `undefined')
|
|
23
|
+
*/
|
|
24
|
+
rootSetState: ((rootState: BuilderRenderState) => void) | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* The local state of the current component. This is different from `rootState` in that
|
|
27
|
+
* it can be a child state created by a repeater containing local state.
|
|
28
|
+
* The `rootState` is where all of the state mutations are actually stored.
|
|
29
|
+
*/
|
|
30
|
+
localState: BuilderRenderState | undefined;
|
|
16
31
|
apiKey: string | null;
|
|
17
32
|
apiVersion: ApiVersion | undefined;
|
|
18
33
|
registeredComponents: RegisteredComponents;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { BuilderContextInterface } from '../context/types.js';
|
|
2
|
-
export declare function evaluate({ code, context,
|
|
1
|
+
import type { BuilderContextInterface, BuilderRenderState } from '../context/types.js';
|
|
2
|
+
export declare function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression, }: {
|
|
3
3
|
code: string;
|
|
4
4
|
event?: Event;
|
|
5
5
|
isExpression?: boolean;
|
|
6
|
-
} & Pick<BuilderContextInterface, '
|
|
6
|
+
} & Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>): any;
|
|
7
|
+
export declare function flattenState(rootState: Record<string | symbol, any>, localState: Record<string | symbol, any> | undefined, rootSetState: ((rootState: BuilderRenderState) => void) | undefined): BuilderRenderState;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isBrowser } from './is-browser.js';
|
|
2
2
|
import { isEditing } from './is-editing.js';
|
|
3
|
-
export function evaluate({ code, context,
|
|
3
|
+
export function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true, }) {
|
|
4
4
|
if (code === '') {
|
|
5
5
|
console.warn('Skipping evaluation of empty code block.');
|
|
6
6
|
return;
|
|
@@ -20,9 +20,30 @@ export function evaluate({ code, context, state, event, isExpression = true, })
|
|
|
20
20
|
code.trim().startsWith('return '));
|
|
21
21
|
const useCode = useReturn ? `return (${code});` : code;
|
|
22
22
|
try {
|
|
23
|
-
return new Function('builder', 'Builder' /* <- legacy */, 'state', 'context', 'event', useCode)(builder, builder,
|
|
23
|
+
return new Function('builder', 'Builder' /* <- legacy */, 'state', 'context', 'event', useCode)(builder, builder, flattenState(rootState, localState, rootSetState), context, event);
|
|
24
24
|
}
|
|
25
25
|
catch (e) {
|
|
26
26
|
console.warn('Builder custom code error: \n While Evaluating: \n ', useCode, '\n', e);
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
+
export function flattenState(rootState, localState, rootSetState) {
|
|
30
|
+
if (rootState === localState) {
|
|
31
|
+
throw new Error('rootState === localState');
|
|
32
|
+
}
|
|
33
|
+
return new Proxy(rootState, {
|
|
34
|
+
get: (_, prop) => {
|
|
35
|
+
if (localState && prop in localState) {
|
|
36
|
+
return localState[prop];
|
|
37
|
+
}
|
|
38
|
+
return rootState[prop];
|
|
39
|
+
},
|
|
40
|
+
set: (_, prop, value) => {
|
|
41
|
+
if (localState && prop in localState) {
|
|
42
|
+
throw new Error('Writing to local state is not allowed as it is read-only.');
|
|
43
|
+
}
|
|
44
|
+
rootState[prop] = value;
|
|
45
|
+
rootSetState?.(rootState);
|
|
46
|
+
return true;
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { flattenState } from './evaluate';
|
|
2
|
+
describe('flatten state', () => {
|
|
3
|
+
it('should behave normally when no PROTO_STATE', () => {
|
|
4
|
+
const localState = {};
|
|
5
|
+
const rootState = { foo: 'bar' };
|
|
6
|
+
const flattened = flattenState(rootState, localState, undefined);
|
|
7
|
+
expect(flattened.foo).toEqual('bar');
|
|
8
|
+
flattened.foo = 'baz';
|
|
9
|
+
expect(rootState.foo).toEqual('baz');
|
|
10
|
+
});
|
|
11
|
+
it('should shadow write ', () => {
|
|
12
|
+
const rootState = { foo: 'foo' };
|
|
13
|
+
const localState = { foo: 'baz' };
|
|
14
|
+
const flattened = flattenState(rootState, localState, undefined);
|
|
15
|
+
expect(() => (flattened.foo = 'bar')).toThrow('Writing to local state is not allowed as it is read-only.');
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -2,7 +2,7 @@ import type { BuilderContextInterface } from '../context/types.js';
|
|
|
2
2
|
import type { BuilderBlock } from '../types/builder-block.js';
|
|
3
3
|
type Options = {
|
|
4
4
|
block: BuilderBlock;
|
|
5
|
-
} & Pick<BuilderContextInterface, '
|
|
5
|
+
} & Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>;
|
|
6
6
|
type EventHandler = (event: Event) => any;
|
|
7
7
|
export declare const createEventHandler: (value: string, options: Options) => EventHandler;
|
|
8
8
|
export {};
|
|
@@ -2,7 +2,9 @@ import { evaluate } from './evaluate.js';
|
|
|
2
2
|
export const createEventHandler = (value, options) => (event) => evaluate({
|
|
3
3
|
code: value,
|
|
4
4
|
context: options.context,
|
|
5
|
-
|
|
5
|
+
localState: options.localState,
|
|
6
|
+
rootState: options.rootState,
|
|
7
|
+
rootSetState: options.rootSetState,
|
|
6
8
|
event,
|
|
7
9
|
isExpression: false,
|
|
8
10
|
});
|
|
@@ -5,5 +5,5 @@ type Actions = {
|
|
|
5
5
|
};
|
|
6
6
|
export declare function getBlockActions(options: {
|
|
7
7
|
block: BuilderBlock;
|
|
8
|
-
} & Pick<BuilderContextInterface, '
|
|
8
|
+
} & Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>): Actions;
|
|
9
9
|
export {};
|
|
@@ -1,10 +1,10 @@
|
|
|
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,
|
|
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
|
|
7
7
|
* also sometimes too early to consider bindings, e.g. when we might be looking at a repeated block.
|
|
8
8
|
*/
|
|
9
9
|
shouldEvaluateBindings: boolean;
|
|
10
|
-
} & Pick<BuilderContextInterface, '
|
|
10
|
+
} & Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>): BuilderBlock;
|
|
@@ -2,7 +2,7 @@ import { evaluate } from './evaluate.js';
|
|
|
2
2
|
import { fastClone } from './fast-clone.js';
|
|
3
3
|
import { set } from './set.js';
|
|
4
4
|
import { transformBlock } from './transform-block.js';
|
|
5
|
-
const evaluateBindings = ({ block, context,
|
|
5
|
+
const evaluateBindings = ({ block, context, localState, rootState, rootSetState, }) => {
|
|
6
6
|
if (!block.bindings) {
|
|
7
7
|
return block;
|
|
8
8
|
}
|
|
@@ -14,15 +14,27 @@ const evaluateBindings = ({ block, context, state, }) => {
|
|
|
14
14
|
};
|
|
15
15
|
for (const binding in block.bindings) {
|
|
16
16
|
const expression = block.bindings[binding];
|
|
17
|
-
const value = evaluate({
|
|
17
|
+
const value = evaluate({
|
|
18
|
+
code: expression,
|
|
19
|
+
localState,
|
|
20
|
+
rootState,
|
|
21
|
+
rootSetState,
|
|
22
|
+
context,
|
|
23
|
+
});
|
|
18
24
|
set(copied, binding, value);
|
|
19
25
|
}
|
|
20
26
|
return copied;
|
|
21
27
|
};
|
|
22
|
-
export function getProcessedBlock({ block, context, shouldEvaluateBindings,
|
|
28
|
+
export function getProcessedBlock({ block, context, shouldEvaluateBindings, localState, rootState, rootSetState, }) {
|
|
23
29
|
const transformedBlock = transformBlock(block);
|
|
24
30
|
if (shouldEvaluateBindings) {
|
|
25
|
-
return evaluateBindings({
|
|
31
|
+
return evaluateBindings({
|
|
32
|
+
block: transformedBlock,
|
|
33
|
+
localState,
|
|
34
|
+
rootState,
|
|
35
|
+
rootSetState,
|
|
36
|
+
context,
|
|
37
|
+
});
|
|
26
38
|
}
|
|
27
39
|
else {
|
|
28
40
|
return transformedBlock;
|
|
@@ -19,7 +19,9 @@ test('Can process bindings', () => {
|
|
|
19
19
|
const processed = getProcessedBlock({
|
|
20
20
|
block,
|
|
21
21
|
context: {},
|
|
22
|
-
|
|
22
|
+
rootState: { test: 'hello' },
|
|
23
|
+
rootSetState: undefined,
|
|
24
|
+
localState: undefined,
|
|
23
25
|
shouldEvaluateBindings: true,
|
|
24
26
|
});
|
|
25
27
|
expect(processed).not.toEqual(block);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getDefaultCanTrack: (canTrack?: boolean) => boolean;
|
package/dist/sdk/index.d.ts
CHANGED
|
@@ -10,3 +10,4 @@ export * from './functions/get-builder-search-params/index.js';
|
|
|
10
10
|
export { track } from './functions/track/index.js';
|
|
11
11
|
export type { RegisteredComponent } from './context/types';
|
|
12
12
|
export type { ComponentInfo } from './types/components';
|
|
13
|
+
export type { RenderContentProps } from './components/render-content/render-content.types.js';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SDK_VERSION } from '../constants/sdk-version.js';
|
|
1
2
|
import { TARGET } from '../constants/target.js';
|
|
2
3
|
import { isBrowser } from '../functions/is-browser.js';
|
|
3
4
|
import { register } from '../functions/register.js';
|
|
@@ -32,6 +33,7 @@ export const setupBrowserForEditing = (options = {}) => {
|
|
|
32
33
|
type: 'builder.sdkInfo',
|
|
33
34
|
data: {
|
|
34
35
|
target: TARGET,
|
|
36
|
+
version: SDK_VERSION,
|
|
35
37
|
// TODO: compile these in
|
|
36
38
|
// type: process.env.SDK_TYPE,
|
|
37
39
|
// version: process.env.SDK_VERSION,
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@builder.io/sdk-react",
|
|
3
3
|
"description": "Builder.io SDK for React",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.1",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
6
9
|
"exports": {
|
|
7
10
|
".": "./dist/sdk/index.js",
|
|
8
11
|
"./server": "./dist/sdk/functions/get-content/index.js"
|
|
@@ -11,10 +14,7 @@
|
|
|
11
14
|
"build:types:server": "tsc -p ./tsconfig.server.json",
|
|
12
15
|
"build:types:sdk": "tsc -p ./tsconfig.sdk.json",
|
|
13
16
|
"build:types": "yarn build:types:sdk",
|
|
14
|
-
"build": "yarn build:types"
|
|
15
|
-
"release:patch": "yarn run build && npm version patch && npm publish",
|
|
16
|
-
"release:minor": "yarn run build && npm version minor && npm publish",
|
|
17
|
-
"release:dev": "yarn run build && npm version prerelease && npm publish --tag dev"
|
|
17
|
+
"build": "yarn build:types"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
20
|
"react": "^18.2.0"
|
package/CHANGELOG.md
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
### 0.2.2
|
|
2
|
-
|
|
3
|
-
- Fix: dynamic bindings for Link URLs.
|
|
4
|
-
- Fix: previewing content that includes a symbol whose `model` property is a `page`.
|
|
5
|
-
- Fix: "Show If"/"Hide If" bindings when the initial value is `undefined`.
|
|
6
|
-
|
|
7
|
-
### 0.2.1
|
|
8
|
-
|
|
9
|
-
- No Changes.
|
|
10
|
-
|
|
11
|
-
### 0.2.0
|
|
12
|
-
|
|
13
|
-
- Sets the default `apiVersion` to `v3`.
|
|
14
|
-
|
|
15
|
-
In case you feel the need to use our older API Version `v2`, reach out to us at support@builder.io first. But you can override the default by setting `apiVersion` explicitly to `v2` as follows:
|
|
16
|
-
|
|
17
|
-
```jsx
|
|
18
|
-
<RenderContent apiVersion="v2" />
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
```js
|
|
22
|
-
getContent({ apiVersion: 'v2' });
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
More details on the Builder API Versions visit [this link](https://www.builder.io/c/docs/content-api-versions).
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import * as React from "react";
|
|
3
|
-
import { useContext } from "react";
|
|
4
|
-
|
|
5
|
-
export interface BaseTextProps {
|
|
6
|
-
text: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
import BuilderContext from "../context/builder.context.js";
|
|
10
|
-
|
|
11
|
-
function BaseText(props: BaseTextProps) {
|
|
12
|
-
const builderContext = useContext(BuilderContext);
|
|
13
|
-
|
|
14
|
-
return (
|
|
15
|
-
<span style={builderContext.inheritedStyles as any}>{props.text}</span>
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export default BaseText;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import * as React from "react";
|
|
3
|
-
|
|
4
|
-
export interface ButtonProps {
|
|
5
|
-
attributes?: any;
|
|
6
|
-
text?: string;
|
|
7
|
-
link?: string;
|
|
8
|
-
openLinkInNewTab?: boolean;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function Button(props: ButtonProps) {
|
|
12
|
-
return (
|
|
13
|
-
<>
|
|
14
|
-
{props.link ? (
|
|
15
|
-
<>
|
|
16
|
-
<a
|
|
17
|
-
role="button"
|
|
18
|
-
{...props.attributes}
|
|
19
|
-
href={props.link}
|
|
20
|
-
target={props.openLinkInNewTab ? "_blank" : undefined}
|
|
21
|
-
>
|
|
22
|
-
{props.text}
|
|
23
|
-
</a>
|
|
24
|
-
</>
|
|
25
|
-
) : (
|
|
26
|
-
<>
|
|
27
|
-
<button
|
|
28
|
-
className={
|
|
29
|
-
/** * We have to explicitly provide `class` so that Mitosis knows to merge it with `css`. */
|
|
30
|
-
props.attributes.class + " button-2b50f164"
|
|
31
|
-
}
|
|
32
|
-
{...props.attributes}
|
|
33
|
-
>
|
|
34
|
-
{props.text}
|
|
35
|
-
</button>
|
|
36
|
-
</>
|
|
37
|
-
)}
|
|
38
|
-
<style>{`.button-2b50f164 {
|
|
39
|
-
all: unset;
|
|
40
|
-
}`}</style>
|
|
41
|
-
</>
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export default Button;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { ComponentInfo } from '../../types/components';
|
|
2
|
-
|
|
3
|
-
export const componentInfo: ComponentInfo = {
|
|
4
|
-
name: 'Core:Button',
|
|
5
|
-
|
|
6
|
-
image:
|
|
7
|
-
'https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2F81a15681c3e74df09677dfc57a615b13',
|
|
8
|
-
defaultStyles: {
|
|
9
|
-
// TODO: make min width more intuitive and set one
|
|
10
|
-
appearance: 'none',
|
|
11
|
-
paddingTop: '15px',
|
|
12
|
-
paddingBottom: '15px',
|
|
13
|
-
paddingLeft: '25px',
|
|
14
|
-
paddingRight: '25px',
|
|
15
|
-
backgroundColor: '#000000',
|
|
16
|
-
color: 'white',
|
|
17
|
-
borderRadius: '4px',
|
|
18
|
-
textAlign: 'center',
|
|
19
|
-
cursor: 'pointer',
|
|
20
|
-
},
|
|
21
|
-
inputs: [
|
|
22
|
-
{
|
|
23
|
-
name: 'text',
|
|
24
|
-
type: 'text',
|
|
25
|
-
defaultValue: 'Click me!',
|
|
26
|
-
bubble: true,
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
name: 'link',
|
|
30
|
-
type: 'url',
|
|
31
|
-
bubble: true,
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
name: 'openLinkInNewTab',
|
|
35
|
-
type: 'boolean',
|
|
36
|
-
defaultValue: false,
|
|
37
|
-
friendlyName: 'Open link in new tab',
|
|
38
|
-
},
|
|
39
|
-
],
|
|
40
|
-
static: true,
|
|
41
|
-
noWrap: true,
|
|
42
|
-
};
|
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import * as React from "react";
|
|
3
|
-
import { useState, useContext } from "react";
|
|
4
|
-
|
|
5
|
-
type Column = {
|
|
6
|
-
blocks: BuilderBlock[];
|
|
7
|
-
width?: number;
|
|
8
|
-
};
|
|
9
|
-
type CSSVal = string | number;
|
|
10
|
-
type StackColumnsAt = "tablet" | "mobile" | "never";
|
|
11
|
-
export interface ColumnProps {
|
|
12
|
-
columns?: Column[];
|
|
13
|
-
builderBlock: BuilderBlock; // TODO: Implement this when support for dynamic CSS lands
|
|
14
|
-
|
|
15
|
-
space?: number; // TODO: Implement this when support for dynamic CSS lands
|
|
16
|
-
|
|
17
|
-
stackColumnsAt?: StackColumnsAt; // TODO: Implement this when support for dynamic CSS lands
|
|
18
|
-
|
|
19
|
-
reverseColumnsWhenStacked?: boolean;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
import RenderBlocks from "../../components/render-blocks";
|
|
23
|
-
import type { BuilderBlock } from "../../types/builder-block";
|
|
24
|
-
import { getSizesForBreakpoints } from "../../constants/device-sizes";
|
|
25
|
-
import type { SizeName } from "../../constants/device-sizes";
|
|
26
|
-
import RenderInlinedStyles from "../../components/render-inlined-styles";
|
|
27
|
-
import { TARGET } from "../../constants/target.js";
|
|
28
|
-
import BuilderContext from "../../context/builder.context.js";
|
|
29
|
-
import type { Dictionary } from "../../types/typescript";
|
|
30
|
-
|
|
31
|
-
function Columns(props: ColumnProps) {
|
|
32
|
-
const [gutterSize, setGutterSize] = useState(() =>
|
|
33
|
-
typeof props.space === "number" ? props.space || 0 : 20
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
const [cols, setCols] = useState(() => props.columns || []);
|
|
37
|
-
|
|
38
|
-
const [stackAt, setStackAt] = useState(
|
|
39
|
-
() => props.stackColumnsAt || "tablet"
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
function getWidth(index: number) {
|
|
43
|
-
return cols[index]?.width || 100 / cols.length;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function getColumnCssWidth(index: number) {
|
|
47
|
-
const subtractWidth = (gutterSize * (cols.length - 1)) / cols.length;
|
|
48
|
-
return `calc(${getWidth(index)}% - ${subtractWidth}px)`;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function getTabletStyle({
|
|
52
|
-
stackedStyle,
|
|
53
|
-
desktopStyle,
|
|
54
|
-
}: {
|
|
55
|
-
stackedStyle: CSSVal;
|
|
56
|
-
desktopStyle: CSSVal;
|
|
57
|
-
}) {
|
|
58
|
-
return stackAt === "tablet" ? stackedStyle : desktopStyle;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function getMobileStyle({
|
|
62
|
-
stackedStyle,
|
|
63
|
-
desktopStyle,
|
|
64
|
-
}: {
|
|
65
|
-
stackedStyle: CSSVal;
|
|
66
|
-
desktopStyle: CSSVal;
|
|
67
|
-
}) {
|
|
68
|
-
return stackAt === "never" ? desktopStyle : stackedStyle;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const [flexDir, setFlexDir] = useState(() =>
|
|
72
|
-
props.stackColumnsAt === "never"
|
|
73
|
-
? "row"
|
|
74
|
-
: props.reverseColumnsWhenStacked
|
|
75
|
-
? "column-reverse"
|
|
76
|
-
: "column"
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
function columnsCssVars() {
|
|
80
|
-
if (TARGET === "reactNative") {
|
|
81
|
-
return {
|
|
82
|
-
flexDirection: flexDir,
|
|
83
|
-
} as Dictionary<string>;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return {
|
|
87
|
-
"--flex-dir": flexDir,
|
|
88
|
-
"--flex-dir-tablet": getTabletStyle({
|
|
89
|
-
stackedStyle: flexDir,
|
|
90
|
-
desktopStyle: "row",
|
|
91
|
-
}),
|
|
92
|
-
} as Dictionary<string>;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function columnCssVars(index: number) {
|
|
96
|
-
const gutter = index === 0 ? 0 : gutterSize;
|
|
97
|
-
|
|
98
|
-
if (TARGET === "reactNative") {
|
|
99
|
-
return {
|
|
100
|
-
marginLeft: props.stackColumnsAt === "never" ? gutter : 0,
|
|
101
|
-
} as any as Dictionary<string>;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const width = getColumnCssWidth(index);
|
|
105
|
-
const gutterPixels = `${gutterSize}px`;
|
|
106
|
-
const mobileWidth = "100%";
|
|
107
|
-
const mobileMarginLeft = 0;
|
|
108
|
-
return {
|
|
109
|
-
width,
|
|
110
|
-
"margin-left": gutterPixels,
|
|
111
|
-
"--column-width-mobile": getMobileStyle({
|
|
112
|
-
stackedStyle: mobileWidth,
|
|
113
|
-
desktopStyle: width,
|
|
114
|
-
}),
|
|
115
|
-
"--column-margin-left-mobile": getMobileStyle({
|
|
116
|
-
stackedStyle: mobileMarginLeft,
|
|
117
|
-
desktopStyle: gutterPixels,
|
|
118
|
-
}),
|
|
119
|
-
"--column-width-tablet": getTabletStyle({
|
|
120
|
-
stackedStyle: mobileWidth,
|
|
121
|
-
desktopStyle: width,
|
|
122
|
-
}),
|
|
123
|
-
"--column-margin-left-tablet": getTabletStyle({
|
|
124
|
-
stackedStyle: mobileMarginLeft,
|
|
125
|
-
desktopStyle: gutterPixels,
|
|
126
|
-
}),
|
|
127
|
-
} as any as Dictionary<string>;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function getWidthForBreakpointSize(size: SizeName) {
|
|
131
|
-
const breakpointSizes = getSizesForBreakpoints(
|
|
132
|
-
builderContext.content?.meta?.breakpoints || {}
|
|
133
|
-
);
|
|
134
|
-
return breakpointSizes[size].max;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function columnsStyles() {
|
|
138
|
-
return `
|
|
139
|
-
@media (max-width: ${getWidthForBreakpointSize("medium")}px) {
|
|
140
|
-
.${props.builderBlock.id}-breakpoints {
|
|
141
|
-
flex-direction: var(--flex-dir-tablet);
|
|
142
|
-
align-items: stretch;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
.${props.builderBlock.id}-breakpoints > .builder-column {
|
|
146
|
-
width: var(--column-width-tablet) !important;
|
|
147
|
-
margin-left: var(--column-margin-left-tablet) !important;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
@media (max-width: ${getWidthForBreakpointSize("small")}px) {
|
|
152
|
-
.${props.builderBlock.id}-breakpoints {
|
|
153
|
-
flex-direction: var(--flex-dir);
|
|
154
|
-
align-items: stretch;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
.${props.builderBlock.id}-breakpoints > .builder-column {
|
|
158
|
-
width: var(--column-width-mobile) !important;
|
|
159
|
-
margin-left: var(--column-margin-left-mobile) !important;
|
|
160
|
-
}
|
|
161
|
-
},
|
|
162
|
-
`;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const builderContext = useContext(BuilderContext);
|
|
166
|
-
|
|
167
|
-
return (
|
|
168
|
-
<>
|
|
169
|
-
<div
|
|
170
|
-
className={
|
|
171
|
-
`builder-columns ${props.builderBlock.id}-breakpoints` +
|
|
172
|
-
" div-66c71955"
|
|
173
|
-
}
|
|
174
|
-
style={columnsCssVars()}
|
|
175
|
-
>
|
|
176
|
-
{TARGET !== "reactNative" ? (
|
|
177
|
-
<>
|
|
178
|
-
<RenderInlinedStyles styles={columnsStyles()} />
|
|
179
|
-
</>
|
|
180
|
-
) : null}
|
|
181
|
-
|
|
182
|
-
{props.columns?.map((column, index) => (
|
|
183
|
-
<div
|
|
184
|
-
className="builder-column div-66c71955-2"
|
|
185
|
-
style={columnCssVars(index)}
|
|
186
|
-
key={index}
|
|
187
|
-
>
|
|
188
|
-
<RenderBlocks
|
|
189
|
-
blocks={column.blocks}
|
|
190
|
-
path={`component.options.columns.${index}.blocks`}
|
|
191
|
-
parent={props.builderBlock.id}
|
|
192
|
-
styleProp={{
|
|
193
|
-
flexGrow: "1",
|
|
194
|
-
}}
|
|
195
|
-
/>
|
|
196
|
-
</div>
|
|
197
|
-
))}
|
|
198
|
-
</div>
|
|
199
|
-
<style>{`.div-66c71955 {
|
|
200
|
-
display: flex;
|
|
201
|
-
line-height: normal;
|
|
202
|
-
}.div-66c71955-2 {
|
|
203
|
-
display: flex;
|
|
204
|
-
flex-direction: column;
|
|
205
|
-
align-items: stretch;
|
|
206
|
-
}`}</style>
|
|
207
|
-
</>
|
|
208
|
-
);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
export default Columns;
|