@builder.io/sdk-react-native 0.0.1 → 0.0.2
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.
|
|
4
|
+
"version": "0.0.2",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"release:patch": "npm version patch --no-git-tag-version && npm publish --access public",
|
|
@@ -1,77 +1,41 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
1
17
|
import * as React from "react";
|
|
2
|
-
import {
|
|
3
|
-
import { getSrcSet } from "./image.helpers.js";
|
|
18
|
+
import { Image as ReactImage, View } from "react-native";
|
|
4
19
|
function Image(props) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return props.srcset;
|
|
12
|
-
}
|
|
13
|
-
if (props.srcset && ((_a2 = props.image) == null ? void 0 : _a2.includes("builder.io/api/v1/image"))) {
|
|
14
|
-
if (!props.srcset.includes(props.image.split("?")[0])) {
|
|
15
|
-
console.debug("Removed given srcset");
|
|
16
|
-
return getSrcSet(url);
|
|
17
|
-
}
|
|
18
|
-
} else if (props.image && !props.srcset) {
|
|
19
|
-
return getSrcSet(url);
|
|
20
|
-
}
|
|
21
|
-
return getSrcSet(url);
|
|
22
|
-
}
|
|
23
|
-
function webpSrcSet() {
|
|
24
|
-
var _a2;
|
|
25
|
-
if (((_a2 = srcSetToUse == null ? void 0 : srcSetToUse()) == null ? void 0 : _a2.match(/builder\.io/)) && !props.noWebp) {
|
|
26
|
-
return srcSetToUse().replace(/\?/g, "?format=webp&");
|
|
27
|
-
} else {
|
|
28
|
-
return "";
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return /* @__PURE__ */ React.createElement(View, {
|
|
32
|
-
style: styles.view1
|
|
33
|
-
}, /* @__PURE__ */ React.createElement(View, null, webpSrcSet() ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(View, {
|
|
34
|
-
type: "image/webp",
|
|
35
|
-
srcset: webpSrcSet()
|
|
36
|
-
})) : null, /* @__PURE__ */ React.createElement(View, {
|
|
37
|
-
loading: "lazy",
|
|
38
|
-
alt: props.altText,
|
|
39
|
-
role: props.altText ? "presentation" : void 0,
|
|
40
|
-
style: styles.view2,
|
|
41
|
-
src: props.image,
|
|
42
|
-
srcset: srcSetToUse(),
|
|
43
|
-
sizes: props.sizes
|
|
20
|
+
return props.aspectRatio ? /* @__PURE__ */ React.createElement(View, {
|
|
21
|
+
style: { position: "relative" }
|
|
22
|
+
}, /* @__PURE__ */ React.createElement(ReactImage, {
|
|
23
|
+
resizeMode: props.backgroundSize || "contain",
|
|
24
|
+
style: { position: "absolute", top: 0, bottom: 0, left: 0, right: 0 },
|
|
25
|
+
source: { uri: props.image }
|
|
44
26
|
}), /* @__PURE__ */ React.createElement(View, {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
27
|
+
style: {
|
|
28
|
+
width: "100%",
|
|
29
|
+
paddingTop: props.aspectRatio * 100 + "%"
|
|
30
|
+
}
|
|
31
|
+
})) : /* @__PURE__ */ React.createElement(ReactImage, {
|
|
32
|
+
resizeMode: props.backgroundSize || "contain",
|
|
33
|
+
style: __spreadValues(__spreadValues({
|
|
34
|
+
position: "relative"
|
|
35
|
+
}, props.width ? { width: props.width } : {}), props.height ? { height: props.height } : {}),
|
|
36
|
+
source: { uri: props.image }
|
|
37
|
+
});
|
|
51
38
|
}
|
|
52
|
-
const styles = StyleSheet.create({
|
|
53
|
-
view1: { position: "relative" },
|
|
54
|
-
view2: {
|
|
55
|
-
opacity: 1,
|
|
56
|
-
transition: "opacity 0.2s ease-in-out",
|
|
57
|
-
position: "absolute",
|
|
58
|
-
height: 100,
|
|
59
|
-
width: 100,
|
|
60
|
-
top: 0,
|
|
61
|
-
left: 0
|
|
62
|
-
},
|
|
63
|
-
view3: { width: 100, pointerEvents: "none", fontSize: 0 },
|
|
64
|
-
view4: {
|
|
65
|
-
display: "flex",
|
|
66
|
-
flexDirection: "column",
|
|
67
|
-
alignItems: "stretch",
|
|
68
|
-
position: "absolute",
|
|
69
|
-
top: 0,
|
|
70
|
-
left: 0,
|
|
71
|
-
width: 100,
|
|
72
|
-
height: 100
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
39
|
export {
|
|
76
40
|
Image as default
|
|
77
41
|
};
|
package/src/blocks/text/text.js
CHANGED
|
@@ -1,8 +1,63 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
1
17
|
import * as React from "react";
|
|
2
|
-
import
|
|
18
|
+
import HTML from "react-native-render-html";
|
|
19
|
+
function camelToKebabCase(string) {
|
|
20
|
+
return string.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
|
|
21
|
+
}
|
|
22
|
+
function pick(object, keys) {
|
|
23
|
+
return keys.reduce((obj, key) => {
|
|
24
|
+
if (object && object.hasOwnProperty(key)) {
|
|
25
|
+
obj[key] = object[key];
|
|
26
|
+
}
|
|
27
|
+
return obj;
|
|
28
|
+
}, {});
|
|
29
|
+
}
|
|
30
|
+
const PICK_STYLES = ["textAlign"];
|
|
31
|
+
function getBlockStyles(block) {
|
|
32
|
+
var _a, _b, _c;
|
|
33
|
+
const styles = __spreadValues(__spreadValues({}, (_a = block.responsiveStyles) == null ? void 0 : _a.large), block.styles);
|
|
34
|
+
if ((_b = block.responsiveStyles) == null ? void 0 : _b.medium) {
|
|
35
|
+
Object.assign(styles, block.responsiveStyles.medium);
|
|
36
|
+
}
|
|
37
|
+
if ((_c = block.responsiveStyles) == null ? void 0 : _c.small) {
|
|
38
|
+
Object.assign(styles, block.responsiveStyles.small);
|
|
39
|
+
}
|
|
40
|
+
return styles;
|
|
41
|
+
}
|
|
42
|
+
function getCss(block) {
|
|
43
|
+
const styleObject = pick(getBlockStyles(block), PICK_STYLES);
|
|
44
|
+
if (!styleObject) {
|
|
45
|
+
return "";
|
|
46
|
+
}
|
|
47
|
+
let str = ``;
|
|
48
|
+
for (const key in styleObject) {
|
|
49
|
+
const value = styleObject[key];
|
|
50
|
+
if (typeof value === "string") {
|
|
51
|
+
str += `${camelToKebabCase(key)}: ${value};`;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return str;
|
|
55
|
+
}
|
|
3
56
|
function Text(props) {
|
|
4
|
-
return /* @__PURE__ */ React.createElement(
|
|
5
|
-
|
|
57
|
+
return /* @__PURE__ */ React.createElement(HTML, {
|
|
58
|
+
source: {
|
|
59
|
+
html: `<div style="${getCss(props.builderBlock)}">${props.text || ""}</div>`
|
|
60
|
+
}
|
|
6
61
|
});
|
|
7
62
|
}
|
|
8
63
|
export {
|
|
@@ -18,13 +18,13 @@ import { getMaxWidthQueryForSize } from "../constants/device-sizes.js";
|
|
|
18
18
|
import { convertStyleObject } from "./convert-style-object.js";
|
|
19
19
|
import { sanitizeBlockStyles } from "./sanitize-styles.js";
|
|
20
20
|
function getBlockStyles(block) {
|
|
21
|
-
|
|
22
|
-
const styles = __spreadValues(__spreadValues({}, convertStyleObject(
|
|
23
|
-
if (
|
|
24
|
-
styles[getMaxWidthQueryForSize("medium")] = convertStyleObject(
|
|
21
|
+
const responsiveStyles = block.responsiveStyles;
|
|
22
|
+
const styles = __spreadValues(__spreadValues({}, convertStyleObject(responsiveStyles == null ? void 0 : responsiveStyles.large)), block.styles);
|
|
23
|
+
if (responsiveStyles == null ? void 0 : responsiveStyles.medium) {
|
|
24
|
+
styles[getMaxWidthQueryForSize("medium")] = convertStyleObject(responsiveStyles.medium);
|
|
25
25
|
}
|
|
26
|
-
if (
|
|
27
|
-
styles[getMaxWidthQueryForSize("small")] = convertStyleObject(
|
|
26
|
+
if (responsiveStyles == null ? void 0 : responsiveStyles.small) {
|
|
27
|
+
styles[getMaxWidthQueryForSize("small")] = convertStyleObject(responsiveStyles.small);
|
|
28
28
|
}
|
|
29
29
|
sanitizeBlockStyles(styles);
|
|
30
30
|
return styles;
|