@builder.io/sdk-react-native 0.0.1-58 → 0.0.1-59
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@builder.io/sdk-react-native",
|
|
3
3
|
"description": "Builder.io SDK for React Native",
|
|
4
|
-
"version": "0.0.1-
|
|
4
|
+
"version": "0.0.1-59",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"release:dev": "npm version prerelease --no-git-tag-version && npm publish --tag dev --access public"
|
|
@@ -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.js";
|
|
7
|
+
import { convertStyleMaptoCSS } from "../../helpers/css.js";
|
|
8
|
+
import { getMaxWidthQueryForSize } from "../../constants/device-sizes.js";
|
|
7
9
|
function BlockStyles(props) {
|
|
8
10
|
function useBlock() {
|
|
9
11
|
return getProcessedBlock({
|
|
@@ -12,27 +14,23 @@ function BlockStyles(props) {
|
|
|
12
14
|
context: builderContext.context
|
|
13
15
|
});
|
|
14
16
|
}
|
|
15
|
-
function camelToKebabCase(string) {
|
|
16
|
-
return string.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
|
|
17
|
-
}
|
|
18
17
|
function css() {
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return str;
|
|
18
|
+
const styles = useBlock().responsiveStyles;
|
|
19
|
+
const largeStyles = styles == null ? void 0 : styles.large;
|
|
20
|
+
const mediumStyles = styles == null ? void 0 : styles.medium;
|
|
21
|
+
const smallStyles = styles == null ? void 0 : styles.small;
|
|
22
|
+
return `
|
|
23
|
+
${largeStyles ? `.${useBlock().id} {${convertStyleMaptoCSS(largeStyles)}}` : ""}
|
|
24
|
+
${mediumStyles ? `${getMaxWidthQueryForSize("medium")} {
|
|
25
|
+
.${useBlock().id} {${convertStyleMaptoCSS(mediumStyles)}}
|
|
26
|
+
}` : ""}
|
|
27
|
+
${smallStyles ? `${getMaxWidthQueryForSize("small")} {
|
|
28
|
+
.${useBlock().id} {${convertStyleMaptoCSS(smallStyles)}}
|
|
29
|
+
}` : ""}
|
|
30
|
+
}`;
|
|
33
31
|
}
|
|
34
32
|
const builderContext = useContext(BuilderContext);
|
|
35
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, null, TARGET === "
|
|
33
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, TARGET === "vue2" || TARGET === "vue3" || TARGET === "svelte" ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(RenderInlinedStyles, {
|
|
36
34
|
styles: css()
|
|
37
35
|
})) : null);
|
|
38
36
|
}
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
const
|
|
3
|
-
const sizes = {
|
|
4
|
-
xsmall: {
|
|
5
|
-
min: 0,
|
|
6
|
-
default: 0,
|
|
7
|
-
max: 0
|
|
8
|
-
},
|
|
2
|
+
const SIZES = {
|
|
9
3
|
small: {
|
|
10
4
|
min: 320,
|
|
11
5
|
default: 321,
|
|
@@ -20,21 +14,9 @@ const sizes = {
|
|
|
20
14
|
min: 990,
|
|
21
15
|
default: 991,
|
|
22
16
|
max: 1200
|
|
23
|
-
},
|
|
24
|
-
getWidthForSize(size) {
|
|
25
|
-
return this[size].default;
|
|
26
|
-
},
|
|
27
|
-
getSizeForWidth(width) {
|
|
28
|
-
for (const size of sizeNames) {
|
|
29
|
-
const value = this[size];
|
|
30
|
-
if (width <= value.max) {
|
|
31
|
-
return size;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return "large";
|
|
35
17
|
}
|
|
36
18
|
};
|
|
19
|
+
const getMaxWidthQueryForSize = (size) => `@media (max-width: ${SIZES[size].max}px)`;
|
|
37
20
|
export {
|
|
38
|
-
|
|
39
|
-
sizes
|
|
21
|
+
getMaxWidthQueryForSize
|
|
40
22
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { camelToKebabCase } from "../functions/camel-to-kebab-case";
|
|
3
|
+
const convertStyleMaptoCSS = (style) => {
|
|
4
|
+
const cssProps = Object.entries(style).map(([key, value]) => {
|
|
5
|
+
if (typeof value === "string") {
|
|
6
|
+
return `${camelToKebabCase(key)}: ${value};`;
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
return cssProps.join("\n");
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
convertStyleMaptoCSS
|
|
13
|
+
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { Text } from "react-native";
|
|
3
|
-
class ErrorBoundary extends React.Component {
|
|
4
|
-
constructor(props) {
|
|
5
|
-
super(props);
|
|
6
|
-
this.state = { hasError: false };
|
|
7
|
-
}
|
|
8
|
-
static getDerivedStateFromError(error) {
|
|
9
|
-
return { hasError: true };
|
|
10
|
-
}
|
|
11
|
-
componentDidCatch(error, errorInfo) {
|
|
12
|
-
console.error("Error rendering Builder.io block", error, errorInfo);
|
|
13
|
-
}
|
|
14
|
-
render() {
|
|
15
|
-
if (this.state.hasError) {
|
|
16
|
-
return /* @__PURE__ */ React.createElement(Text, {
|
|
17
|
-
style: { color: "gray" }
|
|
18
|
-
}, "Error rendering Builder.io block");
|
|
19
|
-
}
|
|
20
|
-
return this.props.children;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
export {
|
|
24
|
-
ErrorBoundary as default
|
|
25
|
-
};
|