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

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