@builder.io/sdk-solid 0.0.8-13 → 0.0.8-14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/blocks/image/image.jsx +1 -3
- package/src/components/render-block/block-styles.jsx +16 -24
- package/src/constants/device-sizes.js +3 -21
- package/src/functions/camel-to-kebab-case.js +4 -0
- package/src/helpers/css.js +12 -0
- package/src/components/error-boundary.jsx +0 -5
package/package.json
CHANGED
|
@@ -4,6 +4,8 @@ import { TARGET } from "../../constants/target.js";
|
|
|
4
4
|
import BuilderContext from "../../context/builder.context";
|
|
5
5
|
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
6
6
|
import RenderInlinedStyles from "../render-inlined-styles.jsx";
|
|
7
|
+
import { convertStyleMaptoCSS } from "../../helpers/css.js";
|
|
8
|
+
import { getMaxWidthQueryForSize } from "../../constants/device-sizes.js";
|
|
7
9
|
|
|
8
10
|
function BlockStyles(props) {
|
|
9
11
|
const state = createMutable({
|
|
@@ -15,35 +17,25 @@ function BlockStyles(props) {
|
|
|
15
17
|
});
|
|
16
18
|
},
|
|
17
19
|
|
|
18
|
-
camelToKebabCase(string) {
|
|
19
|
-
return string.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
|
|
20
|
-
},
|
|
21
|
-
|
|
22
20
|
get css() {
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
str += `${state.camelToKebabCase(key)}: ${value};`;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
str += "}";
|
|
41
|
-
return str;
|
|
21
|
+
const styles = state.useBlock.responsiveStyles;
|
|
22
|
+
const largeStyles = styles?.large;
|
|
23
|
+
const mediumStyles = styles?.medium;
|
|
24
|
+
const smallStyles = styles?.small;
|
|
25
|
+
return `
|
|
26
|
+
${largeStyles ? `.${state.useBlock.id} {${convertStyleMaptoCSS(largeStyles)}}` : ""}
|
|
27
|
+
${mediumStyles ? `${getMaxWidthQueryForSize("medium")} {
|
|
28
|
+
.${state.useBlock.id} {${convertStyleMaptoCSS(mediumStyles)}}
|
|
29
|
+
}` : ""}
|
|
30
|
+
${smallStyles ? `${getMaxWidthQueryForSize("small")} {
|
|
31
|
+
.${state.useBlock.id} {${convertStyleMaptoCSS(smallStyles)}}
|
|
32
|
+
}` : ""}
|
|
33
|
+
}`;
|
|
42
34
|
}
|
|
43
35
|
|
|
44
36
|
});
|
|
45
37
|
const builderContext = useContext(BuilderContext);
|
|
46
|
-
return <Show when={TARGET === "
|
|
38
|
+
return <Show when={TARGET === "vue2" || TARGET === "vue3" || TARGET === "svelte"}>
|
|
47
39
|
<RenderInlinedStyles styles={state.css}></RenderInlinedStyles>
|
|
48
40
|
</Show>;
|
|
49
41
|
}
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
const
|
|
2
|
-
const sizes = {
|
|
3
|
-
xsmall: {
|
|
4
|
-
min: 0,
|
|
5
|
-
default: 0,
|
|
6
|
-
max: 0
|
|
7
|
-
},
|
|
1
|
+
const SIZES = {
|
|
8
2
|
small: {
|
|
9
3
|
min: 320,
|
|
10
4
|
default: 321,
|
|
@@ -19,21 +13,9 @@ const sizes = {
|
|
|
19
13
|
min: 990,
|
|
20
14
|
default: 991,
|
|
21
15
|
max: 1200
|
|
22
|
-
},
|
|
23
|
-
getWidthForSize(size) {
|
|
24
|
-
return this[size].default;
|
|
25
|
-
},
|
|
26
|
-
getSizeForWidth(width) {
|
|
27
|
-
for (const size of sizeNames) {
|
|
28
|
-
const value = this[size];
|
|
29
|
-
if (width <= value.max) {
|
|
30
|
-
return size;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return "large";
|
|
34
16
|
}
|
|
35
17
|
};
|
|
18
|
+
const getMaxWidthQueryForSize = (size) => `@media (max-width: ${SIZES[size].max}px)`;
|
|
36
19
|
export {
|
|
37
|
-
|
|
38
|
-
sizes
|
|
20
|
+
getMaxWidthQueryForSize
|
|
39
21
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { camelToKebabCase } from "../functions/camel-to-kebab-case";
|
|
2
|
+
const convertStyleMaptoCSS = (style) => {
|
|
3
|
+
const cssProps = Object.entries(style).map(([key, value]) => {
|
|
4
|
+
if (typeof value === "string") {
|
|
5
|
+
return `${camelToKebabCase(key)}: ${value};`;
|
|
6
|
+
}
|
|
7
|
+
});
|
|
8
|
+
return cssProps.join("\n");
|
|
9
|
+
};
|
|
10
|
+
export {
|
|
11
|
+
convertStyleMaptoCSS
|
|
12
|
+
};
|