@builder.io/sdk-react-native 0.0.1 → 0.0.3

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.3",
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 { View, StyleSheet, Text } from "react-native";
3
- import { getSrcSet } from "./image.helpers.js";
18
+ import { Image as ReactImage, View } from "react-native";
4
19
  function Image(props) {
5
- var _a, _b, _c, _d;
6
- function srcSetToUse() {
7
- var _a2;
8
- const imageToUse = props.image || props.src;
9
- const url = imageToUse;
10
- if (!url || !(url.match(/builder\.io/) || url.match(/cdn\.shopify\.com/))) {
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
- srcset: srcSetToUse()
46
- })), props.aspectRatio && !(props.fitContent && ((_b = (_a = props.builderBlock) == null ? void 0 : _a.children) == null ? void 0 : _b.length)) ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(View, {
47
- style: styles.view3
48
- })) : null, ((_d = (_c = props.builderBlock) == null ? void 0 : _c.children) == null ? void 0 : _d.length) && props.fitContent ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Text, null, props.children)) : null, !props.fitContent ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(View, {
49
- style: styles.view4
50
- }, /* @__PURE__ */ React.createElement(Text, null, props.children))) : null);
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
  };
@@ -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 { View } from "react-native";
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(View, {
5
- dangerouslySetInnerHTML: { __html: props.text }
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 {
@@ -15,17 +15,28 @@ var __spreadValues = (a, b) => {
15
15
  return a;
16
16
  };
17
17
  import { getMaxWidthQueryForSize } from "../constants/device-sizes.js";
18
+ import { TARGET } from "../constants/target.js";
18
19
  import { convertStyleObject } from "./convert-style-object.js";
19
20
  import { sanitizeBlockStyles } from "./sanitize-styles.js";
20
- function getBlockStyles(block) {
21
- var _a, _b, _c, _d, _e;
22
- const styles = __spreadValues(__spreadValues({}, convertStyleObject((_a = block.responsiveStyles) == null ? void 0 : _a.large)), block.styles);
23
- if ((_b = block.responsiveStyles) == null ? void 0 : _b.medium) {
24
- styles[getMaxWidthQueryForSize("medium")] = convertStyleObject((_c = block.responsiveStyles) == null ? void 0 : _c.medium);
21
+ const getStyleForTarget = (styles) => {
22
+ switch (TARGET) {
23
+ case "reactNative": {
24
+ return __spreadValues(__spreadValues(__spreadValues({}, styles.large ? convertStyleObject(styles.large) : {}), styles.medium ? convertStyleObject(styles.medium) : {}), styles.small ? convertStyleObject(styles.small) : {});
25
+ }
26
+ default:
27
+ return __spreadValues(__spreadValues(__spreadValues({}, styles.large ? convertStyleObject(styles.large) : {}), styles.medium ? {
28
+ [getMaxWidthQueryForSize("medium")]: convertStyleObject(styles.medium)
29
+ } : {}), styles.small ? {
30
+ [getMaxWidthQueryForSize("small")]: convertStyleObject(styles.small)
31
+ } : {});
25
32
  }
26
- if ((_d = block.responsiveStyles) == null ? void 0 : _d.small) {
27
- styles[getMaxWidthQueryForSize("small")] = convertStyleObject((_e = block.responsiveStyles) == null ? void 0 : _e.small);
33
+ };
34
+ function getBlockStyles(block) {
35
+ if (!block.responsiveStyles) {
36
+ return {};
28
37
  }
38
+ const styles = getStyleForTarget(block.responsiveStyles);
39
+ console.log("rn styles", styles);
29
40
  sanitizeBlockStyles(styles);
30
41
  return styles;
31
42
  }