@builder.io/sdk-react 0.1.11 → 0.1.13
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/react/blocks/columns/columns.js +68 -73
- package/dist/react/blocks/symbol/symbol.js +40 -35
- package/dist/react/components/render-content/render-content.js +7 -0
- package/dist/react/context/builder.context.js +1 -0
- package/dist/react/functions/get-content/generate-content-url.js +5 -2
- package/dist/react/functions/get-content/generate-content-url.test.js +42 -0
- package/dist/react/types/api-version.js +1 -0
- package/dist/rsc/blocks/columns/columns.js +68 -75
- package/dist/rsc/blocks/symbol/symbol.js +46 -19
- package/dist/rsc/components/render-content/render-content.js +1 -0
- package/dist/rsc/context/builder.context.js +1 -0
- package/dist/rsc/functions/get-content/generate-content-url.js +5 -2
- package/dist/rsc/functions/get-content/generate-content-url.test.js +42 -0
- package/dist/rsc/types/api-version.js +1 -0
- package/package.json +1 -1
- package/packages/react/src/blocks/columns/columns.jsx +81 -79
- package/packages/react/src/blocks/symbol/symbol.jsx +36 -28
- package/packages/react/src/components/render-content/render-content.jsx +7 -0
- package/packages/react/src/context/builder.context.js +1 -0
- package/packages/react/src/functions/get-content/generate-content-url.js +6 -2
- package/packages/react/src/functions/get-content/generate-content-url.test.js +42 -0
- package/packages/react/src/types/api-version.js +0 -0
- package/packages/rsc/src/blocks/columns/columns.jsx +73 -78
- package/packages/rsc/src/blocks/symbol/symbol.jsx +51 -18
- package/packages/rsc/src/components/render-content/render-content.jsx +1 -0
- package/packages/rsc/src/context/builder.context.js +1 -0
- package/packages/rsc/src/functions/get-content/generate-content-url.js +6 -2
- package/packages/rsc/src/functions/get-content/generate-content-url.test.js +42 -0
- package/packages/rsc/src/types/api-version.js +0 -0
|
@@ -1,132 +1,127 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { useContext } from "react";
|
|
2
|
+
import { useState, useContext } from "react";
|
|
3
3
|
import RenderBlocks from "../../components/render-blocks";
|
|
4
4
|
import { getSizesForBreakpoints } from "../../constants/device-sizes";
|
|
5
5
|
import RenderInlinedStyles from "../../components/render-inlined-styles";
|
|
6
6
|
import { TARGET } from "../../constants/target.js";
|
|
7
|
-
import { convertStyleMapToCSS } from "../../helpers/css";
|
|
8
7
|
import BuilderContext from "../../context/builder.context.js";
|
|
9
8
|
function Columns(props) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
function getColumns() {
|
|
14
|
-
return props.columns || [];
|
|
15
|
-
}
|
|
9
|
+
const [gutterSize, setGutterSize] = useState(() => typeof props.space === "number" ? props.space || 0 : 20);
|
|
10
|
+
const [cols, setCols] = useState(() => props.columns || []);
|
|
11
|
+
const [stackAt, setStackAt] = useState(() => props.stackColumnsAt || "tablet");
|
|
16
12
|
function getWidth(index) {
|
|
17
|
-
|
|
18
|
-
return columns[index]?.width || 100 / columns.length;
|
|
13
|
+
return cols[index]?.width || 100 / cols.length;
|
|
19
14
|
}
|
|
20
15
|
function getColumnCssWidth(index) {
|
|
21
|
-
const
|
|
22
|
-
const gutterSize = getGutterSize();
|
|
23
|
-
const subtractWidth = (gutterSize * (columns.length - 1)) / columns.length;
|
|
16
|
+
const subtractWidth = (gutterSize * (cols.length - 1)) / cols.length;
|
|
24
17
|
return `calc(${getWidth(index)}% - ${subtractWidth}px)`;
|
|
25
18
|
}
|
|
26
|
-
function
|
|
27
|
-
|
|
28
|
-
return _stackColumnsAt === "tablet" ? prop : "inherit";
|
|
19
|
+
function getTabletStyle({ stackedStyle, desktopStyle }) {
|
|
20
|
+
return stackAt === "tablet" ? stackedStyle : desktopStyle;
|
|
29
21
|
}
|
|
22
|
+
function getMobileStyle({ stackedStyle, desktopStyle }) {
|
|
23
|
+
return stackAt === "never" ? desktopStyle : stackedStyle;
|
|
24
|
+
}
|
|
25
|
+
const [flexDir, setFlexDir] = useState(() => props.stackColumnsAt === "never"
|
|
26
|
+
? "row"
|
|
27
|
+
: props.reverseColumnsWhenStacked
|
|
28
|
+
? "column-reverse"
|
|
29
|
+
: "column");
|
|
30
30
|
function columnsCssVars() {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
if (TARGET === "reactNative") {
|
|
32
|
+
return {
|
|
33
|
+
flexDirection: flexDir,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
36
|
return {
|
|
37
37
|
"--flex-dir": flexDir,
|
|
38
|
-
"--flex-dir-tablet":
|
|
38
|
+
"--flex-dir-tablet": getTabletStyle({
|
|
39
|
+
stackedStyle: flexDir,
|
|
40
|
+
desktopStyle: "row",
|
|
41
|
+
}),
|
|
39
42
|
};
|
|
40
43
|
}
|
|
41
|
-
function columnCssVars() {
|
|
42
|
-
const width =
|
|
43
|
-
const
|
|
44
|
+
function columnCssVars(index) {
|
|
45
|
+
const width = getColumnCssWidth(index);
|
|
46
|
+
const gutter = `${index === 0 ? 0 : gutterSize}px`;
|
|
47
|
+
if (TARGET === "reactNative") {
|
|
48
|
+
return {
|
|
49
|
+
width,
|
|
50
|
+
marginLeft: props.stackColumnsAt === "never" ? gutter : "0",
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
const mobileWidth = "100%";
|
|
54
|
+
const mobileMarginLeft = "0";
|
|
44
55
|
return {
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
"--column-width-
|
|
48
|
-
|
|
56
|
+
width,
|
|
57
|
+
"margin-left": gutter,
|
|
58
|
+
"--column-width-mobile": getMobileStyle({
|
|
59
|
+
stackedStyle: mobileWidth,
|
|
60
|
+
desktopStyle: width,
|
|
61
|
+
}),
|
|
62
|
+
"--column-margin-left-mobile": getMobileStyle({
|
|
63
|
+
stackedStyle: mobileMarginLeft,
|
|
64
|
+
desktopStyle: gutter,
|
|
65
|
+
}),
|
|
66
|
+
"--column-width-tablet": getTabletStyle({
|
|
67
|
+
stackedStyle: mobileWidth,
|
|
68
|
+
desktopStyle: width,
|
|
69
|
+
}),
|
|
70
|
+
"--column-margin-left-tablet": getTabletStyle({
|
|
71
|
+
stackedStyle: mobileMarginLeft,
|
|
72
|
+
desktopStyle: gutter,
|
|
73
|
+
}),
|
|
49
74
|
};
|
|
50
75
|
}
|
|
51
76
|
function getWidthForBreakpointSize(size) {
|
|
52
77
|
const breakpointSizes = getSizesForBreakpoints(builderContext.content?.meta?.breakpoints || {});
|
|
53
78
|
return breakpointSizes[size].max;
|
|
54
79
|
}
|
|
55
|
-
function columnStyleObjects() {
|
|
56
|
-
return {
|
|
57
|
-
columns: {
|
|
58
|
-
small: {
|
|
59
|
-
flexDirection: "var(--flex-dir)",
|
|
60
|
-
alignItems: "stretch",
|
|
61
|
-
},
|
|
62
|
-
medium: {
|
|
63
|
-
flexDirection: "var(--flex-dir-tablet)",
|
|
64
|
-
alignItems: "stretch",
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
column: {
|
|
68
|
-
small: {
|
|
69
|
-
width: "var(--column-width) !important",
|
|
70
|
-
marginLeft: "var(--column-margin-left) !important",
|
|
71
|
-
},
|
|
72
|
-
medium: {
|
|
73
|
-
width: "var(--column-width-tablet) !important",
|
|
74
|
-
marginLeft: "var(--column-margin-left-tablet) !important",
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
80
|
function columnsStyles() {
|
|
80
81
|
return `
|
|
81
82
|
@media (max-width: ${getWidthForBreakpointSize("medium")}px) {
|
|
82
83
|
.${props.builderBlock.id}-breakpoints {
|
|
83
|
-
|
|
84
|
+
flex-direction: var(--flex-dir-tablet);
|
|
85
|
+
align-items: stretch;
|
|
84
86
|
}
|
|
85
87
|
|
|
86
88
|
.${props.builderBlock.id}-breakpoints > .builder-column {
|
|
87
|
-
|
|
89
|
+
width: var(--column-width-tablet) !important;
|
|
90
|
+
margin-left: var(--column-margin-left-tablet) !important;
|
|
88
91
|
}
|
|
89
92
|
}
|
|
90
93
|
|
|
91
94
|
@media (max-width: ${getWidthForBreakpointSize("small")}px) {
|
|
92
95
|
.${props.builderBlock.id}-breakpoints {
|
|
93
|
-
|
|
96
|
+
flex-direction: var(--flex-dir);
|
|
97
|
+
align-items: stretch;
|
|
94
98
|
}
|
|
95
99
|
|
|
96
100
|
.${props.builderBlock.id}-breakpoints > .builder-column {
|
|
97
|
-
|
|
101
|
+
width: var(--column-width-mobile) !important;
|
|
102
|
+
margin-left: var(--column-margin-left-mobile) !important;
|
|
98
103
|
}
|
|
99
104
|
},
|
|
100
105
|
`;
|
|
101
106
|
}
|
|
102
|
-
function reactNativeColumnsStyles() {
|
|
103
|
-
return columnStyleObjects.columns.small;
|
|
104
|
-
}
|
|
105
|
-
function reactNativeColumnStyles() {
|
|
106
|
-
return columnStyleObjects.column.small;
|
|
107
|
-
}
|
|
108
107
|
const builderContext = useContext(BuilderContext);
|
|
109
108
|
return (React.createElement(React.Fragment, null,
|
|
110
109
|
React.createElement("div", { className: `builder-columns ${props.builderBlock.id}-breakpoints` +
|
|
111
|
-
" div-
|
|
112
|
-
|
|
113
|
-
...columnsCssVars(),
|
|
110
|
+
" div-568386c4", style: columnsCssVars(), dataSet: {
|
|
111
|
+
"builder-block-name": "builder-columns",
|
|
114
112
|
} },
|
|
115
113
|
TARGET !== "reactNative" ? (React.createElement(React.Fragment, null,
|
|
116
114
|
React.createElement(RenderInlinedStyles, { styles: columnsStyles() }))) : null,
|
|
117
|
-
props.columns?.map((column, index) => (React.createElement("div", { className: "builder-column div-
|
|
118
|
-
|
|
119
|
-
marginLeft: `${index === 0 ? 0 : getGutterSize()}px`,
|
|
120
|
-
...(TARGET === "reactNative" ? reactNativeColumnStyles() : {}),
|
|
121
|
-
...columnCssVars(),
|
|
115
|
+
props.columns?.map((column, index) => (React.createElement("div", { className: "builder-column div-568386c4-2", style: columnCssVars(index), dataSet: {
|
|
116
|
+
"builder-block-name": "builder-column",
|
|
122
117
|
}, key: index },
|
|
123
118
|
React.createElement(RenderBlocks, { blocks: column.blocks, path: `component.options.columns.${index}.blocks`, parent: props.builderBlock.id, styleProp: {
|
|
124
119
|
flexGrow: "1",
|
|
125
120
|
} }))))),
|
|
126
|
-
React.createElement("style", null, `.div-
|
|
121
|
+
React.createElement("style", null, `.div-568386c4 {
|
|
127
122
|
display: flex;
|
|
128
123
|
line-height: normal;
|
|
129
|
-
}.div-
|
|
124
|
+
}.div-568386c4-2 {
|
|
130
125
|
display: flex;
|
|
131
126
|
flex-direction: column;
|
|
132
127
|
align-items: stretch;
|
|
@@ -5,27 +5,20 @@ import BuilderContext from "../../context/builder.context.js";
|
|
|
5
5
|
import { getContent } from "../../functions/get-content/index.js";
|
|
6
6
|
import { TARGET } from "../../constants/target";
|
|
7
7
|
function Symbol(props) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const [fetchedContent, setFetchedContent] = useState(() => null);
|
|
23
|
-
function contentToUse() {
|
|
24
|
-
return props.symbol?.content || fetchedContent;
|
|
25
|
-
}
|
|
26
|
-
const builderContext = useContext(BuilderContext);
|
|
27
|
-
useEffect(() => {
|
|
28
|
-
const symbolToUse = props.symbol;
|
|
8
|
+
const [className, setClassName] = useState(() => [
|
|
9
|
+
...(TARGET === "vue2" || TARGET === "vue3"
|
|
10
|
+
? Object.keys(props.attributes.class)
|
|
11
|
+
: [props.attributes.class]),
|
|
12
|
+
"builder-symbol",
|
|
13
|
+
props.symbol?.inline ? "builder-inline-symbol" : undefined,
|
|
14
|
+
props.symbol?.dynamic || props.dynamic
|
|
15
|
+
? "builder-dynamic-symbol"
|
|
16
|
+
: undefined,
|
|
17
|
+
]
|
|
18
|
+
.filter(Boolean)
|
|
19
|
+
.join(" "));
|
|
20
|
+
const [contentToUse, setContentToUse] = useState(() => props.symbol?.content);
|
|
21
|
+
function fetchContent() {
|
|
29
22
|
/**
|
|
30
23
|
* If:
|
|
31
24
|
* - we have a symbol prop
|
|
@@ -35,30 +28,42 @@ function Symbol(props) {
|
|
|
35
28
|
*
|
|
36
29
|
* then we want to re-fetch the symbol content.
|
|
37
30
|
*/
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
!fetchedContent &&
|
|
41
|
-
symbolToUse.model &&
|
|
31
|
+
if (!contentToUse &&
|
|
32
|
+
props.symbol?.model &&
|
|
42
33
|
// This is a hack, we should not need to check for this, but it is needed for Svelte.
|
|
43
34
|
builderContext?.apiKey) {
|
|
44
35
|
getContent({
|
|
45
|
-
model:
|
|
36
|
+
model: props.symbol.model,
|
|
46
37
|
apiKey: builderContext.apiKey,
|
|
38
|
+
apiVersion: builderContext.apiVersion,
|
|
47
39
|
query: {
|
|
48
|
-
id:
|
|
40
|
+
id: props.symbol.entry,
|
|
49
41
|
},
|
|
50
|
-
})
|
|
51
|
-
|
|
42
|
+
})
|
|
43
|
+
.then((response) => {
|
|
44
|
+
if (response) {
|
|
45
|
+
setContentToUse(response);
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
.catch((err) => {
|
|
49
|
+
console.error("[Builder.io]: Could not fetch symbol content: ", err);
|
|
52
50
|
});
|
|
53
51
|
}
|
|
54
|
-
}
|
|
52
|
+
}
|
|
53
|
+
const builderContext = useContext(BuilderContext);
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
fetchContent();
|
|
56
|
+
}, []);
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
fetchContent();
|
|
59
|
+
}, [props.symbol]);
|
|
55
60
|
return (React.createElement("div", { ...props.attributes, dataSet: {
|
|
56
|
-
class: className
|
|
57
|
-
}, className: className
|
|
58
|
-
React.createElement(RenderContent, { apiKey: builderContext.apiKey, context: builderContext.context, customComponents: Object.values(builderContext.registeredComponents), data: {
|
|
61
|
+
class: className,
|
|
62
|
+
}, className: className },
|
|
63
|
+
React.createElement(RenderContent, { apiVersion: builderContext.apiVersion, apiKey: builderContext.apiKey, context: builderContext.context, customComponents: Object.values(builderContext.registeredComponents), data: {
|
|
59
64
|
...props.symbol?.data,
|
|
60
65
|
...builderContext.state,
|
|
61
|
-
...
|
|
62
|
-
}, model: props.symbol?.model, content: contentToUse
|
|
66
|
+
...contentToUse?.data?.state,
|
|
67
|
+
}, model: props.symbol?.model, content: contentToUse })));
|
|
63
68
|
}
|
|
64
69
|
export default Symbol;
|
|
@@ -241,6 +241,7 @@ function RenderContent(props) {
|
|
|
241
241
|
getContent({
|
|
242
242
|
model: props.model,
|
|
243
243
|
apiKey: props.apiKey,
|
|
244
|
+
apiVersion: props.apiVersion,
|
|
244
245
|
}).then((content) => {
|
|
245
246
|
if (content) {
|
|
246
247
|
mergeNewContent(content);
|
|
@@ -253,6 +254,11 @@ function RenderContent(props) {
|
|
|
253
254
|
emitStateUpdate();
|
|
254
255
|
}
|
|
255
256
|
}, []);
|
|
257
|
+
useEffect(() => {
|
|
258
|
+
if (props.content) {
|
|
259
|
+
mergeNewContent(props.content);
|
|
260
|
+
}
|
|
261
|
+
}, [props.content]);
|
|
256
262
|
useEffect(() => {
|
|
257
263
|
evaluateJsCode();
|
|
258
264
|
}, [useContent?.data?.jsCode, contentState]);
|
|
@@ -276,6 +282,7 @@ function RenderContent(props) {
|
|
|
276
282
|
setState: setContextState,
|
|
277
283
|
context: props.context || {},
|
|
278
284
|
apiKey: props.apiKey,
|
|
285
|
+
apiVersion: props.apiVersion,
|
|
279
286
|
registeredComponents: allRegisteredComponents,
|
|
280
287
|
} }, useContent ? (React.createElement(React.Fragment, null,
|
|
281
288
|
React.createElement("div", { ref: elementRef, onClick: (event) => onClick(event), "builder-content-id": useContent?.id, "builder-model": props.model },
|
|
@@ -17,11 +17,14 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
import { flatten } from "../../helpers/flatten.js";
|
|
18
18
|
import { getBuilderSearchParamsFromWindow, normalizeSearchParams } from "../get-builder-search-params/index.js";
|
|
19
19
|
const generateContentUrl = (options) => {
|
|
20
|
-
const { limit = 30, userAttributes, query, noTraverse = false, model, apiKey, includeRefs = true, locale } = options;
|
|
20
|
+
const { limit = 30, userAttributes, query, noTraverse = false, model, apiKey, includeRefs = true, locale, apiVersion = "v2" } = options;
|
|
21
21
|
if (!apiKey) {
|
|
22
22
|
throw new Error("Missing API key");
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
if (!["v2", "v3"].includes(apiVersion)) {
|
|
25
|
+
throw new Error(`Invalid apiVersion: expected 'v2' or 'v3', received '${apiVersion}'`);
|
|
26
|
+
}
|
|
27
|
+
const url = new URL(`https://cdn.builder.io/api/${apiVersion}/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}${locale ? `&locale=${locale}` : ""}`);
|
|
25
28
|
const queryOptions = __spreadValues(__spreadValues({}, getBuilderSearchParamsFromWindow()), normalizeSearchParams(options.options || {}));
|
|
26
29
|
const flattened = flatten(queryOptions);
|
|
27
30
|
for (const key in flattened) {
|
|
@@ -28,4 +28,46 @@ describe("Generate Content URL", () => {
|
|
|
28
28
|
});
|
|
29
29
|
expect(output).toMatchSnapshot();
|
|
30
30
|
});
|
|
31
|
+
test("generate content url with apiVersion as v2", () => {
|
|
32
|
+
const output = generateContentUrl({
|
|
33
|
+
apiKey: testKey,
|
|
34
|
+
model: testModel,
|
|
35
|
+
query: { id: testId },
|
|
36
|
+
options,
|
|
37
|
+
apiVersion: "v2"
|
|
38
|
+
});
|
|
39
|
+
expect(output).toMatchSnapshot();
|
|
40
|
+
});
|
|
41
|
+
test("generate content url with apiVersion as v3", () => {
|
|
42
|
+
const output = generateContentUrl({
|
|
43
|
+
apiKey: testKey,
|
|
44
|
+
model: testModel,
|
|
45
|
+
query: { id: testId },
|
|
46
|
+
options,
|
|
47
|
+
apiVersion: "v3"
|
|
48
|
+
});
|
|
49
|
+
expect(output).toMatchSnapshot();
|
|
50
|
+
});
|
|
51
|
+
test("throw error when trying to generate content url with apiVersion as v1", () => {
|
|
52
|
+
expect(() => {
|
|
53
|
+
generateContentUrl({
|
|
54
|
+
apiKey: testKey,
|
|
55
|
+
model: testModel,
|
|
56
|
+
query: { id: testId },
|
|
57
|
+
options,
|
|
58
|
+
apiVersion: "v1"
|
|
59
|
+
});
|
|
60
|
+
}).toThrow(`Invalid apiVersion: expected 'v2' or 'v3', received 'v1'`);
|
|
61
|
+
});
|
|
62
|
+
test("throw error when trying to generate content url with an invalid apiVersion value", () => {
|
|
63
|
+
expect(() => {
|
|
64
|
+
generateContentUrl({
|
|
65
|
+
apiKey: testKey,
|
|
66
|
+
model: testModel,
|
|
67
|
+
query: { id: testId },
|
|
68
|
+
options,
|
|
69
|
+
apiVersion: "INVALID_API_VERSION"
|
|
70
|
+
});
|
|
71
|
+
}).toThrow(`Invalid apiVersion: expected 'v2' or 'v3', received 'INVALID_API_VERSION'`);
|
|
72
|
+
});
|
|
31
73
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -3,134 +3,127 @@ import RenderBlocks from "../../components/render-blocks";
|
|
|
3
3
|
import { getSizesForBreakpoints } from "../../constants/device-sizes";
|
|
4
4
|
import RenderInlinedStyles from "../../components/render-inlined-styles";
|
|
5
5
|
import { TARGET } from "../../constants/target.js";
|
|
6
|
-
import { convertStyleMapToCSS } from "../../helpers/css";
|
|
7
6
|
import BuilderContext from "../../context/builder.context.js";
|
|
8
7
|
function Columns(props) {
|
|
9
8
|
const _context = { ...props["_context"] };
|
|
10
9
|
const state = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
getColumns() {
|
|
15
|
-
return props.columns || [];
|
|
16
|
-
},
|
|
10
|
+
gutterSize: typeof props.space === "number" ? props.space || 0 : 20,
|
|
11
|
+
cols: props.columns || [],
|
|
12
|
+
stackAt: props.stackColumnsAt || "tablet",
|
|
17
13
|
getWidth(index) {
|
|
18
|
-
|
|
19
|
-
return columns[index]?.width || 100 / columns.length;
|
|
14
|
+
return state.cols[index]?.width || 100 / state.cols.length;
|
|
20
15
|
},
|
|
21
16
|
getColumnCssWidth(index) {
|
|
22
|
-
const
|
|
23
|
-
const gutterSize = state.getGutterSize();
|
|
24
|
-
const subtractWidth = (gutterSize * (columns.length - 1)) / columns.length;
|
|
17
|
+
const subtractWidth = (state.gutterSize * (state.cols.length - 1)) / state.cols.length;
|
|
25
18
|
return `calc(${state.getWidth(index)}% - ${subtractWidth}px)`;
|
|
26
19
|
},
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return _stackColumnsAt === "tablet" ? prop : "inherit";
|
|
20
|
+
getTabletStyle({ stackedStyle, desktopStyle }) {
|
|
21
|
+
return state.stackAt === "tablet" ? stackedStyle : desktopStyle;
|
|
30
22
|
},
|
|
23
|
+
getMobileStyle({ stackedStyle, desktopStyle }) {
|
|
24
|
+
return state.stackAt === "never" ? desktopStyle : stackedStyle;
|
|
25
|
+
},
|
|
26
|
+
flexDir: props.stackColumnsAt === "never"
|
|
27
|
+
? "row"
|
|
28
|
+
: props.reverseColumnsWhenStacked
|
|
29
|
+
? "column-reverse"
|
|
30
|
+
: "column",
|
|
31
31
|
get columnsCssVars() {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
if (TARGET === "reactNative") {
|
|
33
|
+
return {
|
|
34
|
+
flexDirection: state.flexDir,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
37
|
return {
|
|
38
|
-
"--flex-dir": flexDir,
|
|
39
|
-
"--flex-dir-tablet": state.
|
|
38
|
+
"--flex-dir": state.flexDir,
|
|
39
|
+
"--flex-dir-tablet": state.getTabletStyle({
|
|
40
|
+
stackedStyle: state.flexDir,
|
|
41
|
+
desktopStyle: "row",
|
|
42
|
+
}),
|
|
40
43
|
};
|
|
41
44
|
},
|
|
42
|
-
|
|
43
|
-
const width =
|
|
44
|
-
const
|
|
45
|
+
columnCssVars(index) {
|
|
46
|
+
const width = state.getColumnCssWidth(index);
|
|
47
|
+
const gutter = `${index === 0 ? 0 : state.gutterSize}px`;
|
|
48
|
+
if (TARGET === "reactNative") {
|
|
49
|
+
return {
|
|
50
|
+
width,
|
|
51
|
+
marginLeft: props.stackColumnsAt === "never" ? gutter : "0",
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const mobileWidth = "100%";
|
|
55
|
+
const mobileMarginLeft = "0";
|
|
45
56
|
return {
|
|
46
|
-
|
|
47
|
-
"
|
|
48
|
-
"--column-width-
|
|
49
|
-
|
|
57
|
+
width,
|
|
58
|
+
"margin-left": gutter,
|
|
59
|
+
"--column-width-mobile": state.getMobileStyle({
|
|
60
|
+
stackedStyle: mobileWidth,
|
|
61
|
+
desktopStyle: width,
|
|
62
|
+
}),
|
|
63
|
+
"--column-margin-left-mobile": state.getMobileStyle({
|
|
64
|
+
stackedStyle: mobileMarginLeft,
|
|
65
|
+
desktopStyle: gutter,
|
|
66
|
+
}),
|
|
67
|
+
"--column-width-tablet": state.getTabletStyle({
|
|
68
|
+
stackedStyle: mobileWidth,
|
|
69
|
+
desktopStyle: width,
|
|
70
|
+
}),
|
|
71
|
+
"--column-margin-left-tablet": state.getTabletStyle({
|
|
72
|
+
stackedStyle: mobileMarginLeft,
|
|
73
|
+
desktopStyle: gutter,
|
|
74
|
+
}),
|
|
50
75
|
};
|
|
51
76
|
},
|
|
52
77
|
getWidthForBreakpointSize(size) {
|
|
53
78
|
const breakpointSizes = getSizesForBreakpoints(builderContext.content?.meta?.breakpoints || {});
|
|
54
79
|
return breakpointSizes[size].max;
|
|
55
80
|
},
|
|
56
|
-
get columnStyleObjects() {
|
|
57
|
-
return {
|
|
58
|
-
columns: {
|
|
59
|
-
small: {
|
|
60
|
-
flexDirection: "var(--flex-dir)",
|
|
61
|
-
alignItems: "stretch",
|
|
62
|
-
},
|
|
63
|
-
medium: {
|
|
64
|
-
flexDirection: "var(--flex-dir-tablet)",
|
|
65
|
-
alignItems: "stretch",
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
column: {
|
|
69
|
-
small: {
|
|
70
|
-
width: "var(--column-width) !important",
|
|
71
|
-
marginLeft: "var(--column-margin-left) !important",
|
|
72
|
-
},
|
|
73
|
-
medium: {
|
|
74
|
-
width: "var(--column-width-tablet) !important",
|
|
75
|
-
marginLeft: "var(--column-margin-left-tablet) !important",
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
},
|
|
80
81
|
get columnsStyles() {
|
|
81
82
|
return `
|
|
82
83
|
@media (max-width: ${state.getWidthForBreakpointSize("medium")}px) {
|
|
83
84
|
.${props.builderBlock.id}-breakpoints {
|
|
84
|
-
|
|
85
|
+
flex-direction: var(--flex-dir-tablet);
|
|
86
|
+
align-items: stretch;
|
|
85
87
|
}
|
|
86
88
|
|
|
87
89
|
.${props.builderBlock.id}-breakpoints > .builder-column {
|
|
88
|
-
|
|
90
|
+
width: var(--column-width-tablet) !important;
|
|
91
|
+
margin-left: var(--column-margin-left-tablet) !important;
|
|
89
92
|
}
|
|
90
93
|
}
|
|
91
94
|
|
|
92
95
|
@media (max-width: ${state.getWidthForBreakpointSize("small")}px) {
|
|
93
96
|
.${props.builderBlock.id}-breakpoints {
|
|
94
|
-
|
|
97
|
+
flex-direction: var(--flex-dir);
|
|
98
|
+
align-items: stretch;
|
|
95
99
|
}
|
|
96
100
|
|
|
97
101
|
.${props.builderBlock.id}-breakpoints > .builder-column {
|
|
98
|
-
|
|
102
|
+
width: var(--column-width-mobile) !important;
|
|
103
|
+
margin-left: var(--column-margin-left-mobile) !important;
|
|
99
104
|
}
|
|
100
105
|
},
|
|
101
106
|
`;
|
|
102
107
|
},
|
|
103
|
-
get reactNativeColumnsStyles() {
|
|
104
|
-
return this.columnStyleObjects.columns.small;
|
|
105
|
-
},
|
|
106
|
-
get reactNativeColumnStyles() {
|
|
107
|
-
return this.columnStyleObjects.column.small;
|
|
108
|
-
},
|
|
109
108
|
};
|
|
110
109
|
const builderContext = _context["BuilderContext"];
|
|
111
110
|
return (React.createElement(React.Fragment, null,
|
|
112
111
|
React.createElement("div", { className: `builder-columns ${props.builderBlock.id}-breakpoints` +
|
|
113
|
-
" div-
|
|
114
|
-
|
|
115
|
-
...state.columnsCssVars,
|
|
112
|
+
" div-263839f0", style: state.columnsCssVars, dataSet: {
|
|
113
|
+
"builder-block-name": "builder-columns",
|
|
116
114
|
} },
|
|
117
115
|
TARGET !== "reactNative" ? (React.createElement(React.Fragment, null,
|
|
118
116
|
React.createElement(RenderInlinedStyles, { styles: state.columnsStyles, _context: _context }))) : null,
|
|
119
|
-
props.columns?.map((column, index) => (React.createElement("div", { className: "builder-column div-
|
|
120
|
-
|
|
121
|
-
marginLeft: `${index === 0 ? 0 : state.getGutterSize()}px`,
|
|
122
|
-
...(TARGET === "reactNative"
|
|
123
|
-
? state.reactNativeColumnStyles
|
|
124
|
-
: {}),
|
|
125
|
-
...state.columnCssVars,
|
|
117
|
+
props.columns?.map((column, index) => (React.createElement("div", { className: "builder-column div-263839f0-2", style: state.columnCssVars(index), dataSet: {
|
|
118
|
+
"builder-block-name": "builder-column",
|
|
126
119
|
}, key: index },
|
|
127
120
|
React.createElement(RenderBlocks, { blocks: column.blocks, path: `component.options.columns.${index}.blocks`, parent: props.builderBlock.id, styleProp: {
|
|
128
121
|
flexGrow: "1",
|
|
129
122
|
}, _context: _context }))))),
|
|
130
|
-
React.createElement("style", null, `.div-
|
|
123
|
+
React.createElement("style", null, `.div-263839f0 {
|
|
131
124
|
display: flex;
|
|
132
125
|
line-height: normal;
|
|
133
|
-
}.div-
|
|
126
|
+
}.div-263839f0-2 {
|
|
134
127
|
display: flex;
|
|
135
128
|
flex-direction: column;
|
|
136
129
|
align-items: stretch;
|