@builder.io/sdk-react-native 0.0.1-25 → 0.0.1-26

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.
Files changed (77) hide show
  1. package/package.json +3 -2
  2. package/src/blocks/button.js +66 -22
  3. package/src/blocks/button.lite.tsx +4 -4
  4. package/src/blocks/columns.js +247 -36
  5. package/src/blocks/columns.lite.tsx +7 -7
  6. package/src/blocks/custom-code.js +73 -47
  7. package/src/blocks/custom-code.lite.tsx +12 -16
  8. package/src/blocks/embed.js +66 -47
  9. package/src/blocks/embed.lite.tsx +11 -13
  10. package/src/blocks/form.js +436 -195
  11. package/src/blocks/form.lite.tsx +65 -72
  12. package/src/blocks/fragment.js +16 -8
  13. package/src/blocks/fragment.lite.tsx +3 -3
  14. package/src/blocks/image.js +88 -80
  15. package/src/blocks/image.lite.tsx +14 -15
  16. package/src/blocks/img.js +45 -28
  17. package/src/blocks/img.lite.tsx +7 -7
  18. package/src/blocks/input.js +93 -28
  19. package/src/blocks/input.lite.tsx +5 -7
  20. package/src/blocks/raw-text.js +16 -12
  21. package/src/blocks/raw-text.lite.tsx +3 -3
  22. package/src/blocks/section.js +66 -23
  23. package/src/blocks/section.lite.tsx +4 -4
  24. package/src/blocks/select.js +67 -28
  25. package/src/blocks/select.lite.tsx +6 -8
  26. package/src/blocks/submit-button.js +41 -21
  27. package/src/blocks/submit-button.lite.tsx +3 -3
  28. package/src/blocks/symbol.js +18 -16
  29. package/src/blocks/symbol.lite.tsx +5 -5
  30. package/src/blocks/text.js +29 -27
  31. package/src/blocks/text.lite.tsx +4 -9
  32. package/src/blocks/textarea.js +53 -24
  33. package/src/blocks/textarea.lite.tsx +3 -3
  34. package/src/blocks/video.js +112 -46
  35. package/src/blocks/video.lite.tsx +6 -6
  36. package/src/components/block-styles.js +2 -4
  37. package/src/components/block-styles.lite.tsx +3 -3
  38. package/src/components/error-boundary.js +11 -9
  39. package/src/components/error-boundary.lite.tsx +3 -3
  40. package/src/components/render-block.js +85 -40
  41. package/src/components/render-block.lite.tsx +17 -25
  42. package/src/components/render-blocks.js +56 -32
  43. package/src/components/render-blocks.lite.tsx +14 -14
  44. package/src/components/render-content.js +100 -52
  45. package/src/components/render-content.lite.tsx +32 -41
  46. package/src/constants/device-sizes.js +8 -11
  47. package/src/context/builder.context.js +2 -4
  48. package/src/functions/evaluate.js +17 -9
  49. package/src/functions/get-block-actions.js +9 -10
  50. package/src/functions/get-block-component-options.js +11 -10
  51. package/src/functions/get-block-properties.js +15 -17
  52. package/src/functions/get-block-styles.js +19 -16
  53. package/src/functions/get-block-tag.js +2 -4
  54. package/src/functions/get-content.js +40 -29
  55. package/src/functions/get-fetch.js +5 -7
  56. package/src/functions/get-global-this.js +5 -7
  57. package/src/functions/get-processed-block.js +11 -13
  58. package/src/functions/get-processed-block.test.js +14 -14
  59. package/src/functions/get-target.js +2 -4
  60. package/src/functions/if-target.js +1 -3
  61. package/src/functions/is-browser.js +3 -5
  62. package/src/functions/is-editing.js +3 -5
  63. package/src/functions/is-iframe.js +2 -4
  64. package/src/functions/is-previewing.js +4 -6
  65. package/src/functions/is-react-native.js +2 -4
  66. package/src/functions/macro-eval.js +2 -5
  67. package/src/functions/on-change.js +4 -7
  68. package/src/functions/on-change.test.js +10 -10
  69. package/src/functions/previewing-model-name.js +3 -5
  70. package/src/functions/register-component.js +33 -28
  71. package/src/functions/register.js +8 -10
  72. package/src/functions/set-editor-settings.js +5 -7
  73. package/src/functions/set.js +10 -4
  74. package/src/functions/set.test.js +14 -14
  75. package/src/functions/track.js +6 -8
  76. package/src/index.js +20 -18
  77. package/src/scripts/init-editing.js +64 -40
@@ -1,25 +1,25 @@
1
1
  import * as React from 'react';
2
- const sizeNames = ["xsmall", "small", "medium", "large"];
2
+ const sizeNames = ['xsmall', 'small', 'medium', 'large'];
3
3
  const sizes = {
4
4
  xsmall: {
5
5
  min: 0,
6
6
  default: 0,
7
- max: 0
7
+ max: 0,
8
8
  },
9
9
  small: {
10
10
  min: 320,
11
11
  default: 321,
12
- max: 640
12
+ max: 640,
13
13
  },
14
14
  medium: {
15
15
  min: 641,
16
16
  default: 642,
17
- max: 991
17
+ max: 991,
18
18
  },
19
19
  large: {
20
20
  min: 990,
21
21
  default: 991,
22
- max: 1200
22
+ max: 1200,
23
23
  },
24
24
  getWidthForSize(size) {
25
25
  return this[size].default;
@@ -31,10 +31,7 @@ const sizes = {
31
31
  return size;
32
32
  }
33
33
  }
34
- return "large";
35
- }
36
- };
37
- export {
38
- sizeNames,
39
- sizes
34
+ return 'large';
35
+ },
40
36
  };
37
+ export { sizeNames, sizes };
@@ -1,5 +1,3 @@
1
- import { createContext } from "react";
1
+ import { createContext } from 'react';
2
2
  var stdin_default = createContext({ content: null, context: {}, state: {} });
3
- export {
4
- stdin_default as default
5
- };
3
+ export { stdin_default as default };
@@ -1,20 +1,28 @@
1
1
  import * as React from 'react';
2
- import { isBrowser } from "./is-browser";
3
- import { isEditing } from "./is-editing";
2
+ import { isBrowser } from './is-browser';
3
+ import { isEditing } from './is-editing';
4
4
  function evaluate(options) {
5
5
  const { code } = options;
6
6
  const builder = {
7
7
  isEditing: isEditing(),
8
- isBrowser: isBrowser()
8
+ isBrowser: isBrowser(),
9
9
  };
10
- const useReturn = !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "));
10
+ const useReturn = !(
11
+ code.includes(';') ||
12
+ code.includes(' return ') ||
13
+ code.trim().startsWith('return ')
14
+ );
11
15
  const useCode = `${useReturn ? `return (${code});` : code}`;
12
16
  try {
13
- return new Function("builder", "Builder", "state", "context", "event", useCode)(builder, builder, options.state, options.context, options.event);
17
+ return new Function('builder', 'Builder', 'state', 'context', 'event', useCode)(
18
+ builder,
19
+ builder,
20
+ options.state,
21
+ options.context,
22
+ options.event
23
+ );
14
24
  } catch (e) {
15
- console.warn("Builder custom code error", e);
25
+ console.warn('Builder custom code error', e);
16
26
  }
17
27
  }
18
- export {
19
- evaluate
20
- };
28
+ export { evaluate };
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { evaluate } from "./evaluate";
2
+ import { evaluate } from './evaluate';
3
3
  function capitalizeFirstLetter(string) {
4
4
  return string.charAt(0).toUpperCase() + string.slice(1);
5
5
  }
@@ -8,16 +8,15 @@ function getBlockActions(options) {
8
8
  if (options.block.actions) {
9
9
  for (const key in options.block.actions) {
10
10
  const value = options.block.actions[key];
11
- obj["on" + capitalizeFirstLetter(key)] = (event) => evaluate({
12
- code: value,
13
- context: options.context,
14
- state: options.state,
15
- event
16
- });
11
+ obj['on' + capitalizeFirstLetter(key)] = event =>
12
+ evaluate({
13
+ code: value,
14
+ context: options.context,
15
+ state: options.state,
16
+ event,
17
+ });
17
18
  }
18
19
  }
19
20
  return obj;
20
21
  }
21
- export {
22
- getBlockActions
23
- };
22
+ export { getBlockActions };
@@ -3,22 +3,23 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
5
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
6
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __defNormalProp = (obj, key, value) =>
7
+ key in obj
8
+ ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value })
9
+ : (obj[key] = value);
7
10
  var __spreadValues = (a, b) => {
8
- for (var prop in b || (b = {}))
9
- if (__hasOwnProp.call(b, prop))
10
- __defNormalProp(a, prop, b[prop]);
11
+ for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
11
12
  if (__getOwnPropSymbols)
12
13
  for (var prop of __getOwnPropSymbols(b)) {
13
- if (__propIsEnum.call(b, prop))
14
- __defNormalProp(a, prop, b[prop]);
14
+ if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
15
15
  }
16
16
  return a;
17
17
  };
18
18
  function getBlockComponentOptions(block) {
19
19
  var _a;
20
- return __spreadValues(__spreadValues({}, (_a = block.component) == null ? void 0 : _a.options), block.options);
20
+ return __spreadValues(
21
+ __spreadValues({}, (_a = block.component) == null ? void 0 : _a.options),
22
+ block.options
23
+ );
21
24
  }
22
- export {
23
- getBlockComponentOptions
24
- };
25
+ export { getBlockComponentOptions };
@@ -5,39 +5,37 @@ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
5
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __defNormalProp = (obj, key, value) =>
9
+ key in obj
10
+ ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value })
11
+ : (obj[key] = value);
9
12
  var __spreadValues = (a, b) => {
10
- for (var prop in b || (b = {}))
11
- if (__hasOwnProp.call(b, prop))
12
- __defNormalProp(a, prop, b[prop]);
13
+ for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
13
14
  if (__getOwnPropSymbols)
14
15
  for (var prop of __getOwnPropSymbols(b)) {
15
- if (__propIsEnum.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
16
+ if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
17
17
  }
18
18
  return a;
19
19
  };
20
20
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
- import { findDOMNode } from "react-dom";
22
- import { isBrowser } from "./is-browser";
23
- import { isReactNative } from "./is-react-native";
21
+ import { findDOMNode } from 'react-dom';
22
+ import { isBrowser } from './is-browser';
23
+ import { isReactNative } from './is-react-native';
24
24
  function getBlockProperties(block) {
25
25
  return __spreadProps(__spreadValues({}, block.properties), {
26
- ref: (ref) => {
26
+ ref: ref => {
27
27
  if (isBrowser() && !isReactNative()) {
28
28
  const el = findDOMNode(ref);
29
29
  if (el) {
30
- el.setAttribute("builder-id", block.id);
30
+ el.setAttribute('builder-id', block.id);
31
31
  el.classList.add(block.id);
32
32
  }
33
33
  }
34
34
  },
35
35
  dataSet: {
36
- "builder-id": block.id,
37
- class: [block.id, "builder-block", block.class].filter(Boolean).join(" ")
38
- }
36
+ 'builder-id': block.id,
37
+ class: [block.id, 'builder-block', block.class].filter(Boolean).join(' '),
38
+ },
39
39
  });
40
40
  }
41
- export {
42
- getBlockProperties
43
- };
41
+ export { getBlockProperties };
@@ -3,37 +3,39 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
5
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
6
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __defNormalProp = (obj, key, value) =>
7
+ key in obj
8
+ ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value })
9
+ : (obj[key] = value);
7
10
  var __spreadValues = (a, b) => {
8
- for (var prop in b || (b = {}))
9
- if (__hasOwnProp.call(b, prop))
10
- __defNormalProp(a, prop, b[prop]);
11
+ for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
11
12
  if (__getOwnPropSymbols)
12
13
  for (var prop of __getOwnPropSymbols(b)) {
13
- if (__propIsEnum.call(b, prop))
14
- __defNormalProp(a, prop, b[prop]);
14
+ if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
15
15
  }
16
16
  return a;
17
17
  };
18
- const propertiesThatMustBeNumber = new Set(["lineHeight"]);
19
- const displayValues = new Set(["flex", "none"]);
18
+ const propertiesThatMustBeNumber = new Set(['lineHeight']);
19
+ const displayValues = new Set(['flex', 'none']);
20
20
  const SHOW_WARNINGS = false;
21
21
  function validateReactNativeStyles(styles) {
22
22
  for (const key in styles) {
23
23
  const propertyValue = styles[key];
24
- if (key === "display" && !displayValues.has(propertyValue)) {
24
+ if (key === 'display' && !displayValues.has(propertyValue)) {
25
25
  if (SHOW_WARNINGS) {
26
- console.warn(`Style value for key "display" must be "flex" or "none" but had ${propertyValue}`);
26
+ console.warn(
27
+ `Style value for key "display" must be "flex" or "none" but had ${propertyValue}`
28
+ );
27
29
  }
28
30
  delete styles[key];
29
31
  }
30
- if (typeof propertyValue === "string" && propertyValue.match(/^\d/)) {
32
+ if (typeof propertyValue === 'string' && propertyValue.match(/^\d/)) {
31
33
  const newValue = parseFloat(propertyValue);
32
34
  if (!isNaN(newValue)) {
33
35
  styles[key] = newValue;
34
36
  }
35
37
  }
36
- if (propertiesThatMustBeNumber.has(key) && typeof styles[key] !== "number") {
38
+ if (propertiesThatMustBeNumber.has(key) && typeof styles[key] !== 'number') {
37
39
  if (SHOW_WARNINGS) {
38
40
  console.warn(`Style key ${key} must be a number, but had value \`${styles[key]}\``);
39
41
  }
@@ -43,7 +45,10 @@ function validateReactNativeStyles(styles) {
43
45
  }
44
46
  function getBlockStyles(block) {
45
47
  var _a, _b, _c;
46
- const styles = __spreadValues(__spreadValues({}, (_a = block.responsiveStyles) == null ? void 0 : _a.large), block.styles);
48
+ const styles = __spreadValues(
49
+ __spreadValues({}, (_a = block.responsiveStyles) == null ? void 0 : _a.large),
50
+ block.styles
51
+ );
47
52
  if ((_b = block.responsiveStyles) == null ? void 0 : _b.medium) {
48
53
  Object.assign(styles, block.responsiveStyles.medium);
49
54
  }
@@ -53,6 +58,4 @@ function getBlockStyles(block) {
53
58
  validateReactNativeStyles(styles);
54
59
  return styles;
55
60
  }
56
- export {
57
- getBlockStyles
58
- };
61
+ export { getBlockStyles };
@@ -1,8 +1,6 @@
1
1
  import * as React from 'react';
2
- import { View } from "react-native";
2
+ import { View } from 'react-native';
3
3
  function getBlockTag(block) {
4
4
  return View;
5
5
  }
6
- export {
7
- getBlockTag
8
- };
6
+ export { getBlockTag };
@@ -5,74 +5,87 @@ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
5
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __defNormalProp = (obj, key, value) =>
9
+ key in obj
10
+ ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value })
11
+ : (obj[key] = value);
9
12
  var __spreadValues = (a, b) => {
10
- for (var prop in b || (b = {}))
11
- if (__hasOwnProp.call(b, prop))
12
- __defNormalProp(a, prop, b[prop]);
13
+ for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
13
14
  if (__getOwnPropSymbols)
14
15
  for (var prop of __getOwnPropSymbols(b)) {
15
- if (__propIsEnum.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
16
+ if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
17
17
  }
18
18
  return a;
19
19
  };
20
20
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
21
  var __async = (__this, __arguments, generator) => {
22
22
  return new Promise((resolve, reject) => {
23
- var fulfilled = (value) => {
23
+ var fulfilled = value => {
24
24
  try {
25
25
  step(generator.next(value));
26
26
  } catch (e) {
27
27
  reject(e);
28
28
  }
29
29
  };
30
- var rejected = (value) => {
30
+ var rejected = value => {
31
31
  try {
32
32
  step(generator.throw(value));
33
33
  } catch (e) {
34
34
  reject(e);
35
35
  }
36
36
  };
37
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
37
+ var step = x =>
38
+ x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
38
39
  step((generator = generator.apply(__this, __arguments)).next());
39
40
  });
40
41
  };
41
- import { getFetch } from "./get-fetch";
42
+ import { getFetch } from './get-fetch';
42
43
  const fetch = getFetch();
43
- function flatten(object, path = null, separator = ".") {
44
+ function flatten(object, path = null, separator = '.') {
44
45
  return Object.keys(object).reduce((acc, key) => {
45
46
  const value = object[key];
46
47
  const newPath = [path, key].filter(Boolean).join(separator);
47
48
  const isObject = [
48
- typeof value === "object",
49
+ typeof value === 'object',
49
50
  value !== null,
50
- !(Array.isArray(value) && value.length === 0)
51
+ !(Array.isArray(value) && value.length === 0),
51
52
  ].every(Boolean);
52
- return isObject ? __spreadValues(__spreadValues({}, acc), flatten(value, newPath, separator)) : __spreadProps(__spreadValues({}, acc), { [newPath]: value });
53
+ return isObject
54
+ ? __spreadValues(__spreadValues({}, acc), flatten(value, newPath, separator))
55
+ : __spreadProps(__spreadValues({}, acc), { [newPath]: value });
53
56
  }, {});
54
57
  }
55
58
  function getContent(options) {
56
59
  return __async(this, null, function* () {
57
- return (yield getAllContent(__spreadProps(__spreadValues({}, options), { limit: 1 }))).results[0] || null;
60
+ return (
61
+ (yield getAllContent(__spreadProps(__spreadValues({}, options), { limit: 1 }))).results[0] ||
62
+ null
63
+ );
58
64
  });
59
65
  }
60
66
  function getAllContent(options) {
61
67
  return __async(this, null, function* () {
62
68
  const { model, apiKey } = options;
63
- const { limit, testGroups, userAttributes } = __spreadValues({
64
- limit: 1,
65
- userAttributes: null,
66
- testGroups: null
67
- }, options);
68
- const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&userAttributes=${JSON.stringify(userAttributes)}`);
69
+ const { limit, testGroups, userAttributes } = __spreadValues(
70
+ {
71
+ limit: 1,
72
+ userAttributes: null,
73
+ testGroups: null,
74
+ },
75
+ options
76
+ );
77
+ const url = new URL(
78
+ `https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&userAttributes=${JSON.stringify(
79
+ userAttributes
80
+ )}`
81
+ );
69
82
  if (options.options) {
70
83
  const flattened = flatten(options.options);
71
84
  for (const key in flattened) {
72
85
  url.searchParams.set(key, String(flattened[key]));
73
86
  }
74
87
  }
75
- const content = yield fetch(url.href).then((res) => res.json());
88
+ const content = yield fetch(url.href).then(res => res.json());
76
89
  if (testGroups) {
77
90
  for (const item of content.results) {
78
91
  if (item.variations && Object.keys(item.variations).length) {
@@ -91,19 +104,20 @@ function getAllContent(options) {
91
104
  const testRatio = variation.testRatio;
92
105
  n += testRatio;
93
106
  if (random < n) {
94
- const variationName = variation.name || (variation.id === item.id ? "Default variation" : "");
107
+ const variationName =
108
+ variation.name || (variation.id === item.id ? 'Default variation' : '');
95
109
  set = true;
96
110
  Object.assign(item, {
97
111
  data: variation.data,
98
112
  testVariationId: variation.id,
99
- testVariationName: variationName
113
+ testVariationName: variationName,
100
114
  });
101
115
  }
102
116
  }
103
117
  if (!set) {
104
118
  Object.assign(item, {
105
119
  testVariationId: item.id,
106
- testVariationName: "Default"
120
+ testVariationName: 'Default',
107
121
  });
108
122
  }
109
123
  }
@@ -113,7 +127,4 @@ function getAllContent(options) {
113
127
  return content;
114
128
  });
115
129
  }
116
- export {
117
- getAllContent,
118
- getContent
119
- };
130
+ export { getAllContent, getContent };
@@ -1,13 +1,11 @@
1
1
  import * as React from 'react';
2
- import { getGlobalThis } from "./get-global-this";
2
+ import { getGlobalThis } from './get-global-this';
3
3
  function getFetch() {
4
4
  let fetch = getGlobalThis().fetch;
5
- if (typeof fetch === "undefined" && typeof global !== "undefined") {
6
- const _require = eval("require");
7
- fetch = _require("node-fetch");
5
+ if (typeof fetch === 'undefined' && typeof global !== 'undefined') {
6
+ const _require = eval('require');
7
+ fetch = _require('node-fetch');
8
8
  }
9
9
  return fetch;
10
10
  }
11
- export {
12
- getFetch
13
- };
11
+ export { getFetch };