@builder.io/sdk-react-native 0.0.1-35 → 0.0.1-39

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 (81) hide show
  1. package/package.json +1 -1
  2. package/src/blocks/button.js +73 -22
  3. package/src/blocks/button.lite.tsx +4 -4
  4. package/src/blocks/columns.js +258 -36
  5. package/src/blocks/columns.lite.tsx +5 -6
  6. package/src/blocks/custom-code.js +76 -47
  7. package/src/blocks/custom-code.lite.tsx +12 -12
  8. package/src/blocks/embed.js +69 -47
  9. package/src/blocks/embed.lite.tsx +11 -11
  10. package/src/blocks/form.js +491 -195
  11. package/src/blocks/form.lite.tsx +49 -49
  12. package/src/blocks/fragment.js +16 -8
  13. package/src/blocks/fragment.lite.tsx +2 -3
  14. package/src/blocks/image.js +88 -80
  15. package/src/blocks/image.lite.tsx +15 -14
  16. package/src/blocks/img.js +51 -28
  17. package/src/blocks/img.lite.tsx +6 -7
  18. package/src/blocks/input.js +100 -28
  19. package/src/blocks/input.lite.tsx +4 -5
  20. package/src/blocks/raw-text.js +16 -12
  21. package/src/blocks/raw-text.lite.tsx +2 -3
  22. package/src/blocks/section.js +71 -23
  23. package/src/blocks/section.lite.tsx +3 -4
  24. package/src/blocks/select.js +78 -28
  25. package/src/blocks/select.lite.tsx +4 -5
  26. package/src/blocks/submit-button.js +47 -21
  27. package/src/blocks/submit-button.lite.tsx +2 -3
  28. package/src/blocks/symbol.js +18 -16
  29. package/src/blocks/symbol.lite.tsx +5 -5
  30. package/src/blocks/text.js +41 -26
  31. package/src/blocks/text.lite.tsx +3 -4
  32. package/src/blocks/textarea.js +60 -24
  33. package/src/blocks/textarea.lite.tsx +2 -3
  34. package/src/blocks/video.js +72 -60
  35. package/src/blocks/video.lite.tsx +5 -6
  36. package/src/components/block-styles.js +2 -4
  37. package/src/components/block-styles.lite.tsx +2 -3
  38. package/src/components/error-boundary.js +11 -9
  39. package/src/components/error-boundary.lite.tsx +2 -3
  40. package/src/components/render-block.js +107 -43
  41. package/src/components/render-block.lite.tsx +19 -15
  42. package/src/components/render-blocks.js +58 -32
  43. package/src/components/render-blocks.lite.tsx +10 -11
  44. package/src/components/render-content.js +124 -52
  45. package/src/components/render-content.lite.tsx +27 -27
  46. package/src/constants/device-sizes.js +8 -11
  47. package/src/context/builder.context.js +2 -4
  48. package/src/functions/evaluate.js +18 -9
  49. package/src/functions/event-handler-name.js +6 -0
  50. package/src/functions/get-block-actions.js +13 -13
  51. package/src/functions/get-block-component-options.js +16 -9
  52. package/src/functions/get-block-properties.js +19 -15
  53. package/src/functions/get-block-styles.js +34 -17
  54. package/src/functions/get-block-tag.js +2 -4
  55. package/src/functions/get-content.js +48 -26
  56. package/src/functions/get-content.test.js +37 -26
  57. package/src/functions/get-fetch.js +5 -7
  58. package/src/functions/get-global-this.js +5 -7
  59. package/src/functions/get-processed-block.js +19 -13
  60. package/src/functions/get-processed-block.test.js +18 -14
  61. package/src/functions/get-target.js +2 -4
  62. package/src/functions/if-target.js +1 -3
  63. package/src/functions/is-browser.js +7 -5
  64. package/src/functions/is-editing.js +5 -5
  65. package/src/functions/is-iframe.js +2 -4
  66. package/src/functions/is-previewing.js +4 -6
  67. package/src/functions/is-react-native.js +2 -4
  68. package/src/functions/macro-eval.js +2 -5
  69. package/src/functions/on-change.js +4 -7
  70. package/src/functions/on-change.test.js +10 -10
  71. package/src/functions/previewing-model-name.js +3 -5
  72. package/src/functions/register-component.js +38 -27
  73. package/src/functions/register.js +8 -10
  74. package/src/functions/set-editor-settings.js +5 -7
  75. package/src/functions/set.js +14 -5
  76. package/src/functions/set.test.js +14 -14
  77. package/src/functions/track.js +6 -8
  78. package/src/functions/transform-block.js +40 -0
  79. package/src/index.js +23 -18
  80. package/src/scripts/init-editing.js +64 -40
  81. package/src/package.json +0 -18
@@ -1,17 +1,17 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
- import { useState, useContext, useEffect } from "react";
4
- import { isBrowser } from "../functions/is-browser";
5
- import RenderBlock from "./render-block.lite";
6
- import BuilderContext from "../context/builder.context.lite";
7
- import { track } from "../functions/track";
8
- import { ifTarget } from "../functions/if-target";
9
- import { onChange } from "../functions/on-change";
10
- import { isReactNative } from "../functions/is-react-native";
11
- import { isEditing } from "../functions/is-editing";
12
- import { isPreviewing } from "../functions/is-previewing";
13
- import { previewingModelName } from "../functions/previewing-model-name";
14
- import { getContent } from "../functions/get-content";
1
+ import * as React from 'react';
2
+ import { View, StyleSheet, Image, Text } from 'react-native';
3
+ import { useState, useContext, useEffect } from 'react';
4
+ import { isBrowser } from '../functions/is-browser';
5
+ import RenderBlock from './render-block.lite';
6
+ import BuilderContext from '../context/builder.context.lite';
7
+ import { track } from '../functions/track';
8
+ import { ifTarget } from '../functions/if-target';
9
+ import { onChange } from '../functions/on-change';
10
+ import { isReactNative } from '../functions/is-react-native';
11
+ import { isEditing } from '../functions/is-editing';
12
+ import { isPreviewing } from '../functions/is-previewing';
13
+ import { previewingModelName } from '../functions/previewing-model-name';
14
+ import { getContent } from '../functions/get-content';
15
15
 
16
16
  export default function RenderContent(props) {
17
17
  function useContent() {
@@ -30,10 +30,10 @@ export default function RenderContent(props) {
30
30
  // TODO: compute what font sizes are used and only load those.......
31
31
  const family =
32
32
  font.family +
33
- (font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
34
- const name = family.split(",")[0];
33
+ (font.kind && !font.kind.includes('#') ? ', ' + font.kind : '');
34
+ const name = family.split(',')[0];
35
35
  const url = font.fileUrl ? font.fileUrl : font.files && font.files.regular;
36
- let str = "";
36
+ let str = '';
37
37
 
38
38
  if (url && family && name) {
39
39
  str += `
@@ -83,8 +83,8 @@ export default function RenderContent(props) {
83
83
  data.customFonts.length &&
84
84
  data.customFonts
85
85
  .map((font) => this.getCssFromFont(font, data))
86
- .join(" ")) ||
87
- ""
86
+ .join(' ')) ||
87
+ ''
88
88
  );
89
89
  }
90
90
 
@@ -93,7 +93,7 @@ export default function RenderContent(props) {
93
93
 
94
94
  if (data) {
95
95
  switch (data.type) {
96
- case "builder.contentUpdate": {
96
+ case 'builder.contentUpdate': {
97
97
  const key =
98
98
  data.data.key ||
99
99
  data.data.alias ||
@@ -108,7 +108,7 @@ export default function RenderContent(props) {
108
108
  break;
109
109
  }
110
110
 
111
- case "builder.patchUpdates": {
111
+ case 'builder.patchUpdates': {
112
112
  // TODO
113
113
  break;
114
114
  }
@@ -119,11 +119,11 @@ export default function RenderContent(props) {
119
119
  useEffect(() => {
120
120
  if (isBrowser()) {
121
121
  if (isEditing()) {
122
- window.addEventListener("message", processMessage);
122
+ window.addEventListener('message', processMessage);
123
123
  }
124
124
 
125
125
  if (useContent() && !isEditing()) {
126
- track("impression", {
126
+ track('impression', {
127
127
  contentId: useContent().id,
128
128
  });
129
129
  }
@@ -132,13 +132,13 @@ export default function RenderContent(props) {
132
132
  if (props.model && previewingModelName() === props.model) {
133
133
  const options = {};
134
134
  const currentUrl = new URL(location.href);
135
- const apiKey = currentUrl.searchParams.get("apiKey");
135
+ const apiKey = currentUrl.searchParams.get('apiKey');
136
136
 
137
137
  if (apiKey) {
138
- const builderPrefix = "builder.";
138
+ const builderPrefix = 'builder.';
139
139
  currentUrl.searchParams.forEach((value, key) => {
140
140
  if (key.startsWith(builderPrefix)) {
141
- options[key.replace(builderPrefix, "")] = value;
141
+ options[key.replace(builderPrefix, '')] = value;
142
142
  }
143
143
  }); // TODO: need access to API key
144
144
 
@@ -178,7 +178,7 @@ export default function RenderContent(props) {
178
178
  <View
179
179
  onClick={(event) => {
180
180
  if (!isEditing()) {
181
- track("click", {
181
+ track('click', {
182
182
  contentId: useContent().id,
183
183
  });
184
184
  }
@@ -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,29 @@
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(
18
+ 'builder',
19
+ 'Builder',
20
+ 'state',
21
+ 'context',
22
+ 'event',
23
+ useCode
24
+ )(builder, builder, options.state, options.context, options.event);
14
25
  } catch (e) {
15
- console.warn("Builder custom code error", e);
26
+ console.warn('Builder custom code error: ', e);
16
27
  }
17
28
  }
18
- export {
19
- evaluate
20
- };
29
+ export { evaluate };
@@ -0,0 +1,6 @@
1
+ import * as React from 'react';
2
+ function capitalizeFirstLetter(string) {
3
+ return string.charAt(0).toUpperCase() + string.slice(1);
4
+ }
5
+ const getEventHandlerName = (key) => `on${capitalizeFirstLetter(key)}`;
6
+ export { getEventHandlerName };
@@ -1,23 +1,23 @@
1
1
  import * as React from 'react';
2
- import { evaluate } from "./evaluate";
3
- function capitalizeFirstLetter(string) {
4
- return string.charAt(0).toUpperCase() + string.slice(1);
5
- }
2
+ import { evaluate } from './evaluate';
3
+ import { getEventHandlerName } from './event-handler-name';
6
4
  function getBlockActions(options) {
7
5
  const obj = {};
8
6
  if (options.block.actions) {
9
7
  for (const key in options.block.actions) {
8
+ if (!options.block.actions.hasOwnProperty(key)) {
9
+ continue;
10
+ }
10
11
  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
- });
12
+ obj[getEventHandlerName(key)] = (event) =>
13
+ evaluate({
14
+ code: value,
15
+ context: options.context,
16
+ state: options.state,
17
+ event,
18
+ });
17
19
  }
18
20
  }
19
21
  return obj;
20
22
  }
21
- export {
22
- getBlockActions
23
- };
23
+ export { getBlockActions };
@@ -3,22 +3,29 @@ 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, {
9
+ enumerable: true,
10
+ configurable: true,
11
+ writable: true,
12
+ value,
13
+ })
14
+ : (obj[key] = value);
7
15
  var __spreadValues = (a, b) => {
8
16
  for (var prop in b || (b = {}))
9
- if (__hasOwnProp.call(b, prop))
10
- __defNormalProp(a, prop, b[prop]);
17
+ if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
11
18
  if (__getOwnPropSymbols)
12
19
  for (var prop of __getOwnPropSymbols(b)) {
13
- if (__propIsEnum.call(b, prop))
14
- __defNormalProp(a, prop, b[prop]);
20
+ if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
15
21
  }
16
22
  return a;
17
23
  };
18
24
  function getBlockComponentOptions(block) {
19
25
  var _a;
20
- return __spreadValues(__spreadValues({}, (_a = block.component) == null ? void 0 : _a.options), block.options);
26
+ return __spreadValues(
27
+ __spreadValues({}, (_a = block.component) == null ? void 0 : _a.options),
28
+ block.options
29
+ );
21
30
  }
22
- export {
23
- getBlockComponentOptions
24
- };
31
+ export { getBlockComponentOptions };
@@ -5,39 +5,43 @@ 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, {
11
+ enumerable: true,
12
+ configurable: true,
13
+ writable: true,
14
+ value,
15
+ })
16
+ : (obj[key] = value);
9
17
  var __spreadValues = (a, b) => {
10
18
  for (var prop in b || (b = {}))
11
- if (__hasOwnProp.call(b, prop))
12
- __defNormalProp(a, prop, b[prop]);
19
+ if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
13
20
  if (__getOwnPropSymbols)
14
21
  for (var prop of __getOwnPropSymbols(b)) {
15
- if (__propIsEnum.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
22
+ if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
17
23
  }
18
24
  return a;
19
25
  };
20
26
  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";
27
+ import { findDOMNode } from 'react-dom';
28
+ import { isBrowser } from './is-browser';
29
+ import { isReactNative } from './is-react-native';
24
30
  function getBlockProperties(block) {
25
31
  return __spreadProps(__spreadValues({}, block.properties), {
26
32
  ref: (ref) => {
27
33
  if (isBrowser() && !isReactNative()) {
28
34
  const el = findDOMNode(ref);
29
35
  if (el) {
30
- el.setAttribute("builder-id", block.id);
36
+ el.setAttribute('builder-id', block.id);
31
37
  el.classList.add(block.id);
32
38
  }
33
39
  }
34
40
  },
35
41
  dataSet: {
36
- "builder-id": block.id,
37
- class: [block.id, "builder-block", block.class].filter(Boolean).join(" ")
38
- }
42
+ 'builder-id': block.id,
43
+ class: [block.id, 'builder-block', block.class].filter(Boolean).join(' '),
44
+ },
39
45
  });
40
46
  }
41
- export {
42
- getBlockProperties
43
- };
47
+ export { getBlockProperties };
@@ -3,42 +3,55 @@ 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, {
9
+ enumerable: true,
10
+ configurable: true,
11
+ writable: true,
12
+ value,
13
+ })
14
+ : (obj[key] = value);
7
15
  var __spreadValues = (a, b) => {
8
16
  for (var prop in b || (b = {}))
9
- if (__hasOwnProp.call(b, prop))
10
- __defNormalProp(a, prop, b[prop]);
17
+ if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
11
18
  if (__getOwnPropSymbols)
12
19
  for (var prop of __getOwnPropSymbols(b)) {
13
- if (__propIsEnum.call(b, prop))
14
- __defNormalProp(a, prop, b[prop]);
20
+ if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
15
21
  }
16
22
  return a;
17
23
  };
18
- const propertiesThatMustBeNumber = new Set(["lineHeight"]);
19
- const displayValues = new Set(["flex", "none"]);
24
+ const propertiesThatMustBeNumber = new Set(['lineHeight']);
25
+ const displayValues = new Set(['flex', 'none']);
20
26
  const SHOW_WARNINGS = false;
21
27
  function validateReactNativeStyles(styles) {
22
28
  for (const key in styles) {
23
29
  const propertyValue = styles[key];
24
- if (key === "display" && !displayValues.has(propertyValue)) {
30
+ if (key === 'display' && !displayValues.has(propertyValue)) {
25
31
  if (SHOW_WARNINGS) {
26
- console.warn(`Style value for key "display" must be "flex" or "none" but had ${propertyValue}`);
32
+ console.warn(
33
+ `Style value for key "display" must be "flex" or "none" but had ${propertyValue}`
34
+ );
27
35
  }
28
36
  delete styles[key];
29
37
  }
30
- if (typeof propertyValue === "string" && propertyValue.match(/^\-?\d/)) {
38
+ if (typeof propertyValue === 'string' && propertyValue.match(/^\-?\d/)) {
31
39
  const newValue = parseFloat(propertyValue);
32
40
  if (!isNaN(newValue)) {
33
41
  styles[key] = newValue;
34
42
  }
35
- if (typeof newValue === "number" && newValue < 0) {
43
+ if (typeof newValue === 'number' && newValue < 0) {
36
44
  styles[key] = 0;
37
45
  }
38
46
  }
39
- if (propertiesThatMustBeNumber.has(key) && typeof styles[key] !== "number") {
47
+ if (
48
+ propertiesThatMustBeNumber.has(key) &&
49
+ typeof styles[key] !== 'number'
50
+ ) {
40
51
  if (SHOW_WARNINGS) {
41
- console.warn(`Style key ${key} must be a number, but had value \`${styles[key]}\``);
52
+ console.warn(
53
+ `Style key ${key} must be a number, but had value \`${styles[key]}\``
54
+ );
42
55
  }
43
56
  delete styles[key];
44
57
  }
@@ -46,7 +59,13 @@ function validateReactNativeStyles(styles) {
46
59
  }
47
60
  function getBlockStyles(block) {
48
61
  var _a, _b, _c;
49
- const styles = __spreadValues(__spreadValues({}, (_a = block.responsiveStyles) == null ? void 0 : _a.large), block.styles);
62
+ const styles = __spreadValues(
63
+ __spreadValues(
64
+ {},
65
+ (_a = block.responsiveStyles) == null ? void 0 : _a.large
66
+ ),
67
+ block.styles
68
+ );
50
69
  if ((_b = block.responsiveStyles) == null ? void 0 : _b.medium) {
51
70
  Object.assign(styles, block.responsiveStyles.medium);
52
71
  }
@@ -56,6 +75,4 @@ function getBlockStyles(block) {
56
75
  validateReactNativeStyles(styles);
57
76
  return styles;
58
77
  }
59
- export {
60
- getBlockStyles
61
- };
78
+ 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,15 +5,21 @@ 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, {
11
+ enumerable: true,
12
+ configurable: true,
13
+ writable: true,
14
+ value,
15
+ })
16
+ : (obj[key] = value);
9
17
  var __spreadValues = (a, b) => {
10
18
  for (var prop in b || (b = {}))
11
- if (__hasOwnProp.call(b, prop))
12
- __defNormalProp(a, prop, b[prop]);
19
+ if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
13
20
  if (__getOwnPropSymbols)
14
21
  for (var prop of __getOwnPropSymbols(b)) {
15
- if (__propIsEnum.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
22
+ if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
17
23
  }
18
24
  return a;
19
25
  };
@@ -34,38 +40,55 @@ var __async = (__this, __arguments, generator) => {
34
40
  reject(e);
35
41
  }
36
42
  };
37
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
43
+ var step = (x) =>
44
+ x.done
45
+ ? resolve(x.value)
46
+ : Promise.resolve(x.value).then(fulfilled, rejected);
38
47
  step((generator = generator.apply(__this, __arguments)).next());
39
48
  });
40
49
  };
41
- import { getFetch } from "./get-fetch";
50
+ import { getFetch } from './get-fetch';
42
51
  const fetch = getFetch();
43
- function flatten(object, path = null, separator = ".") {
52
+ function flatten(object, path = null, separator = '.') {
44
53
  return Object.keys(object).reduce((acc, key) => {
45
54
  const value = object[key];
46
55
  const newPath = [path, key].filter(Boolean).join(separator);
47
56
  const isObject = [
48
- typeof value === "object",
57
+ typeof value === 'object',
49
58
  value !== null,
50
- !(Array.isArray(value) && value.length === 0)
59
+ !(Array.isArray(value) && value.length === 0),
51
60
  ].every(Boolean);
52
- return isObject ? __spreadValues(__spreadValues({}, acc), flatten(value, newPath, separator)) : __spreadProps(__spreadValues({}, acc), { [newPath]: value });
61
+ return isObject
62
+ ? __spreadValues(
63
+ __spreadValues({}, acc),
64
+ flatten(value, newPath, separator)
65
+ )
66
+ : __spreadProps(__spreadValues({}, acc), { [newPath]: value });
53
67
  }, {});
54
68
  }
55
69
  function getContent(options) {
56
70
  return __async(this, null, function* () {
57
- return (yield getAllContent(__spreadProps(__spreadValues({}, options), { limit: 1 }))).results[0] || null;
71
+ return (
72
+ (yield getAllContent(
73
+ __spreadProps(__spreadValues({}, options), { limit: 1 })
74
+ )).results[0] || null
75
+ );
58
76
  });
59
77
  }
60
78
  function getAllContent(options) {
61
79
  return __async(this, null, function* () {
62
80
  const { model, apiKey } = options;
63
- const { limit, testGroups, userAttributes, query } = __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}`);
81
+ const { limit, testGroups, userAttributes, query } = __spreadValues(
82
+ {
83
+ limit: 1,
84
+ userAttributes: null,
85
+ testGroups: null,
86
+ },
87
+ options
88
+ );
89
+ const url = new URL(
90
+ `https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}`
91
+ );
69
92
  if (options.options) {
70
93
  const flattened = flatten(options.options);
71
94
  for (const key in flattened) {
@@ -73,7 +96,7 @@ function getAllContent(options) {
73
96
  }
74
97
  }
75
98
  if (userAttributes) {
76
- url.searchParams.set("userAttributes", JSON.stringify(userAttributes));
99
+ url.searchParams.set('userAttributes', JSON.stringify(userAttributes));
77
100
  }
78
101
  if (query) {
79
102
  const flattened = flatten({ query });
@@ -100,19 +123,21 @@ function getAllContent(options) {
100
123
  const testRatio = variation.testRatio;
101
124
  n += testRatio;
102
125
  if (random < n) {
103
- const variationName = variation.name || (variation.id === item.id ? "Default variation" : "");
126
+ const variationName =
127
+ variation.name ||
128
+ (variation.id === item.id ? 'Default variation' : '');
104
129
  set = true;
105
130
  Object.assign(item, {
106
131
  data: variation.data,
107
132
  testVariationId: variation.id,
108
- testVariationName: variationName
133
+ testVariationName: variationName,
109
134
  });
110
135
  }
111
136
  }
112
137
  if (!set) {
113
138
  Object.assign(item, {
114
139
  testVariationId: item.id,
115
- testVariationName: "Default"
140
+ testVariationName: 'Default',
116
141
  });
117
142
  }
118
143
  }
@@ -122,7 +147,4 @@ function getAllContent(options) {
122
147
  return content;
123
148
  });
124
149
  }
125
- export {
126
- getAllContent,
127
- getContent
128
- };
150
+ export { getAllContent, getContent };
@@ -15,33 +15,44 @@ var __async = (__this, __arguments, generator) => {
15
15
  reject(e);
16
16
  }
17
17
  };
18
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ var step = (x) =>
19
+ x.done
20
+ ? resolve(x.value)
21
+ : Promise.resolve(x.value).then(fulfilled, rejected);
19
22
  step((generator = generator.apply(__this, __arguments)).next());
20
23
  });
21
24
  };
22
- import fetchMock from "jest-fetch-mock";
25
+ import fetchMock from 'jest-fetch-mock';
23
26
  fetchMock.enableMocks();
24
- import { test, beforeEach, expect } from "@jest/globals";
25
- import { getContent } from "./get-content";
26
- const testKey = "YJIGb4i01jvw0SRdL5Bt";
27
- const testModel = "page";
28
- const testId = "c1b81bab59704599b997574eb0736def";
29
- beforeEach(() => {
30
- });
31
- test.skip("Get content", () => __async(void 0, null, function* () {
32
- var _a, _b;
33
- expect((_a = yield getContent({
34
- apiKey: testKey,
35
- model: testModel,
36
- query: {
37
- id: testId
38
- }
39
- })) == null ? void 0 : _a.id).toEqual(testId);
40
- expect((_b = yield getContent({
41
- apiKey: testKey,
42
- model: testModel,
43
- userAttributes: {
44
- urlPath: "/test-page"
45
- }
46
- })) == null ? void 0 : _b.id).toEqual(testId);
47
- }));
27
+ import { test, beforeEach, expect } from '@jest/globals';
28
+ import { getContent } from './get-content';
29
+ const testKey = 'YJIGb4i01jvw0SRdL5Bt';
30
+ const testModel = 'page';
31
+ const testId = 'c1b81bab59704599b997574eb0736def';
32
+ beforeEach(() => {});
33
+ test.skip('Get content', () =>
34
+ __async(void 0, null, function* () {
35
+ var _a, _b;
36
+ expect(
37
+ (_a = yield getContent({
38
+ apiKey: testKey,
39
+ model: testModel,
40
+ query: {
41
+ id: testId,
42
+ },
43
+ })) == null
44
+ ? void 0
45
+ : _a.id
46
+ ).toEqual(testId);
47
+ expect(
48
+ (_b = yield getContent({
49
+ apiKey: testKey,
50
+ model: testModel,
51
+ userAttributes: {
52
+ urlPath: '/test-page',
53
+ },
54
+ })) == null
55
+ ? void 0
56
+ : _b.id
57
+ ).toEqual(testId);
58
+ }));