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

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.3",
4
+ "version": "0.0.5",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
7
7
  "release:patch": "npm version patch --no-git-tag-version && npm publish --access public",
@@ -36,9 +36,8 @@ function getBlockStyles(block) {
36
36
  return {};
37
37
  }
38
38
  const styles = getStyleForTarget(block.responsiveStyles);
39
- console.log("rn styles", styles);
40
- sanitizeBlockStyles(styles);
41
- return styles;
39
+ const newStyles = sanitizeBlockStyles(styles);
40
+ return newStyles;
42
41
  }
43
42
  export {
44
43
  getBlockStyles
@@ -1,31 +1,61 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
1
20
  const propertiesThatMustBeNumber = new Set(["lineHeight"]);
2
21
  const displayValues = new Set(["flex", "none"]);
3
22
  const SHOW_WARNINGS = false;
23
+ const normalizeNumber = (value) => {
24
+ if (Number.isNaN(value)) {
25
+ return void 0;
26
+ } else if (value < 0) {
27
+ return 0;
28
+ } else {
29
+ return value;
30
+ }
31
+ };
4
32
  const sanitizeBlockStyles = (styles) => {
5
- for (const key in styles) {
33
+ return Object.keys(styles).reduce((acc, key) => {
6
34
  const propertyValue = styles[key];
7
35
  if (key === "display" && !displayValues.has(propertyValue)) {
8
36
  if (SHOW_WARNINGS) {
9
37
  console.warn(`Style value for key "display" must be "flex" or "none" but had ${propertyValue}`);
10
38
  }
11
- delete styles[key];
12
- }
13
- if (typeof propertyValue === "string" && propertyValue.match(/^-?\d/)) {
14
- const newValue = parseFloat(propertyValue);
15
- if (!isNaN(newValue)) {
16
- styles[key] = newValue;
17
- }
18
- if (typeof newValue === "number" && newValue < 0) {
19
- styles[key] = 0;
20
- }
39
+ return acc;
21
40
  }
22
- if (propertiesThatMustBeNumber.has(key) && typeof styles[key] !== "number") {
41
+ if (propertiesThatMustBeNumber.has(key) && typeof propertyValue !== "number") {
23
42
  if (SHOW_WARNINGS) {
24
43
  console.warn(`Style key ${key} must be a number, but had value \`${styles[key]}\``);
25
44
  }
26
- delete styles[key];
45
+ return acc;
27
46
  }
28
- }
47
+ if (typeof propertyValue === "string" && propertyValue.match(/^-?(\d*)(\.?)(\d*)*px/)) {
48
+ const newValue = parseFloat(propertyValue);
49
+ const normalizedValue = normalizeNumber(newValue);
50
+ if (normalizedValue) {
51
+ const valueWithUnits = propertyValue.endsWith("%") ? `${normalizedValue}%` : "";
52
+ return __spreadProps(__spreadValues({}, acc), { [key]: valueWithUnits });
53
+ } else {
54
+ return acc;
55
+ }
56
+ }
57
+ return __spreadProps(__spreadValues({}, acc), { [key]: propertyValue });
58
+ }, {});
29
59
  };
30
60
  export {
31
61
  sanitizeBlockStyles