@builder.io/sdk-react 0.0.1-6 → 0.0.2

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 (56) hide show
  1. package/package.json +2 -1
  2. package/src/blocks/BaseText.jsx +12 -0
  3. package/src/blocks/button/{button.js → button.jsx} +3 -3
  4. package/src/blocks/columns/{columns.js → columns.jsx} +17 -11
  5. package/src/blocks/custom-code/{custom-code.js → custom-code.jsx} +1 -1
  6. package/src/blocks/embed/{embed.js → embed.jsx} +2 -0
  7. package/src/blocks/form/{form.js → form.jsx} +4 -4
  8. package/src/blocks/fragment/{fragment.js → fragment.jsx} +0 -0
  9. package/src/blocks/image/{image.js → image.jsx} +12 -15
  10. package/src/blocks/img/{img.js → img.jsx} +0 -0
  11. package/src/blocks/input/{input.js → input.jsx} +0 -0
  12. package/src/blocks/raw-text/{raw-text.js → raw-text.jsx} +0 -0
  13. package/src/blocks/section/{section.js → section.jsx} +0 -0
  14. package/src/blocks/select/{select.js → select.jsx} +0 -0
  15. package/src/blocks/submit-button/{submit-button.js → submit-button.jsx} +0 -0
  16. package/src/blocks/symbol/{symbol.js → symbol.jsx} +15 -19
  17. package/src/blocks/text/{text.js → text.jsx} +1 -1
  18. package/src/blocks/textarea/{textarea.js → textarea.jsx} +0 -0
  19. package/src/blocks/video/{video.js → video.jsx} +4 -1
  20. package/src/components/render-block/{block-styles.js → block-styles.jsx} +19 -12
  21. package/src/components/render-block/{render-block.js → render-block.jsx} +60 -37
  22. package/src/components/render-block/render-component-with-context.jsx +35 -0
  23. package/src/components/render-block/{render-component.js → render-component.jsx} +4 -3
  24. package/src/components/render-block/{render-repeated-block.js → render-repeated-block.jsx} +4 -1
  25. package/src/components/{render-blocks.js → render-blocks.jsx} +5 -4
  26. package/src/components/render-content/components/{render-styles.js → render-styles.jsx} +1 -1
  27. package/src/components/render-content/index.js +1 -1
  28. package/src/components/render-content/{render-content.js → render-content.jsx} +36 -40
  29. package/src/components/{render-inlined-styles.js → render-inlined-styles.jsx} +0 -0
  30. package/src/constants/builder-registered-components.js +14 -11
  31. package/src/context/builder.context.js +2 -1
  32. package/src/context/types.js +0 -0
  33. package/src/functions/evaluate.js +1 -1
  34. package/src/functions/extract-text-styles.js +22 -0
  35. package/src/functions/fast-clone.js +4 -0
  36. package/src/functions/get-block-actions-handler.js +12 -0
  37. package/src/functions/get-block-actions.js +2 -7
  38. package/src/functions/get-builder-search-params/index.js +6 -2
  39. package/src/functions/get-content/ab-testing.js +91 -30
  40. package/src/functions/get-content/index.js +5 -5
  41. package/src/functions/get-processed-block.js +5 -3
  42. package/src/functions/get-react-native-block-styles.js +32 -0
  43. package/src/functions/mark-mutable.js +10 -0
  44. package/src/functions/register-component.js +1 -1
  45. package/src/functions/sanitize-react-native-block-styles.js +66 -0
  46. package/src/functions/track.js +19 -14
  47. package/src/helpers/ab-tests.js +16 -0
  48. package/src/helpers/cookie.js +26 -6
  49. package/src/helpers/css.js +17 -1
  50. package/src/helpers/sessionId.js +26 -3
  51. package/src/index-helpers/blocks-exports.js +10 -10
  52. package/src/index.js +4 -0
  53. package/src/scripts/init-editing.js +36 -34
  54. package/src/functions/convert-style-object.js +0 -6
  55. package/src/functions/get-block-styles.js +0 -34
  56. package/src/functions/sanitize-styles.js +0 -5
@@ -1,4 +1,4 @@
1
- import { default as default2 } from "./render-content.js";
1
+ import { default as default2 } from "./render-content.jsx";
2
2
  export {
3
3
  default2 as default
4
4
  };
@@ -17,26 +17,6 @@ var __spreadValues = (a, b) => {
17
17
  return a;
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- var __async = (__this, __arguments, generator) => {
21
- return new Promise((resolve, reject) => {
22
- var fulfilled = (value) => {
23
- try {
24
- step(generator.next(value));
25
- } catch (e) {
26
- reject(e);
27
- }
28
- };
29
- var rejected = (value) => {
30
- try {
31
- step(generator.throw(value));
32
- } catch (e) {
33
- reject(e);
34
- }
35
- };
36
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
37
- step((generator = generator.apply(__this, __arguments)).next());
38
- });
39
- };
40
20
  import * as React from "react";
41
21
  import { useState, useRef, useEffect } from "react";
42
22
  import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
@@ -52,19 +32,23 @@ import {
52
32
  components,
53
33
  createRegisterComponentMessage
54
34
  } from "../../functions/register-component.js";
55
- import { track } from "../../functions/track.js";
56
- import RenderBlocks from "../render-blocks.js";
57
- import RenderContentStyles from "./components/render-styles.js";
35
+ import { _track } from "../../functions/track.js";
36
+ import RenderBlocks from "../render-blocks.jsx";
37
+ import RenderContentStyles from "./components/render-styles.jsx";
58
38
  import {
59
39
  registerInsertMenu,
60
40
  setupBrowserForEditing
61
41
  } from "../../scripts/init-editing.js";
42
+ import { markMutable } from "../../functions/mark-mutable.js";
62
43
  function RenderContent(props) {
63
44
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
64
45
  const elementRef = useRef(null);
65
46
  const [forceReRenderCount, setForceReRenderCount] = useState(() => 0);
66
47
  function useContent() {
67
48
  var _a2;
49
+ if (!props.content && !overrideContent) {
50
+ return void 0;
51
+ }
68
52
  const mergedContent = __spreadProps(__spreadValues(__spreadValues({}, props.content), overrideContent), {
69
53
  data: __spreadValues(__spreadValues(__spreadValues({}, (_a2 = props.content) == null ? void 0 : _a2.data), props.data), overrideContent == null ? void 0 : overrideContent.data)
70
54
  });
@@ -89,7 +73,9 @@ function RenderContent(props) {
89
73
  ...components,
90
74
  ...props.customComponents || []
91
75
  ];
92
- const allComponents = allComponentsArray.reduce((acc, curr) => __spreadProps(__spreadValues({}, acc), { [curr.name]: curr }), {});
76
+ const allComponents = allComponentsArray.reduce((acc, curr) => __spreadProps(__spreadValues({}, acc), {
77
+ [curr.name]: curr
78
+ }), {});
93
79
  return allComponents;
94
80
  }
95
81
  function processMessage(event) {
@@ -102,6 +88,7 @@ function RenderContent(props) {
102
88
  const contentData = messageContent.data;
103
89
  if (key === props.model) {
104
90
  setOverrideContent(contentData);
91
+ setForceReRenderCount(forceReRenderCount + 1);
105
92
  }
106
93
  break;
107
94
  }
@@ -126,12 +113,16 @@ function RenderContent(props) {
126
113
  return {};
127
114
  }
128
115
  function onClick(_event) {
116
+ var _a2, _b2;
129
117
  if (useContent()) {
130
- track({
118
+ const variationId = (_a2 = useContent == null ? void 0 : useContent()) == null ? void 0 : _a2.testVariationId;
119
+ const contentId = (_b2 = useContent == null ? void 0 : useContent()) == null ? void 0 : _b2.id;
120
+ _track({
131
121
  type: "click",
132
122
  canTrack: canTrackToUse(),
133
- contentId: useContent().id,
134
- orgId: props.apiKey
123
+ contentId,
124
+ apiKey: props.apiKey,
125
+ variationId: variationId !== contentId ? variationId : void 0
135
126
  });
136
127
  }
137
128
  }
@@ -143,14 +134,14 @@ function RenderContent(props) {
143
134
  }));
144
135
  }
145
136
  function handleRequest({ url, key }) {
146
- const fetchAndSetState = () => __async(this, null, function* () {
147
- const fetch = yield getFetch();
148
- const response = yield fetch(url);
149
- const json = yield response.json();
150
- const newOverrideState = __spreadProps(__spreadValues({}, overrideState), { [key]: json });
137
+ getFetch().then((fetch) => fetch(url)).then((response) => response.json()).then((json) => {
138
+ const newOverrideState = __spreadProps(__spreadValues({}, overrideState), {
139
+ [key]: json
140
+ });
151
141
  setOverrideState(newOverrideState);
142
+ }).catch((err) => {
143
+ console.log("error fetching dynamic data", url, err);
152
144
  });
153
- fetchAndSetState();
154
145
  }
155
146
  function runHttpRequests() {
156
147
  var _a2, _b2, _c2;
@@ -182,25 +173,29 @@ function RenderContent(props) {
182
173
  return Boolean((((_b2 = (_a2 = useContent == null ? void 0 : useContent()) == null ? void 0 : _a2.data) == null ? void 0 : _b2.cssCode) || ((_e2 = (_d2 = (_c2 = useContent == null ? void 0 : useContent()) == null ? void 0 : _c2.data) == null ? void 0 : _d2.customFonts) == null ? void 0 : _e2.length)) && TARGET !== "reactNative");
183
174
  }
184
175
  useEffect(() => {
176
+ var _a2, _b2;
185
177
  if (isBrowser()) {
186
178
  if (isEditing()) {
187
179
  setForceReRenderCount(forceReRenderCount + 1);
188
180
  registerInsertMenu();
189
181
  setupBrowserForEditing();
190
182
  Object.values(allRegisteredComponents()).forEach((registeredComponent) => {
191
- var _a2;
183
+ var _a3;
192
184
  const message = createRegisterComponentMessage(registeredComponent);
193
- (_a2 = window.parent) == null ? void 0 : _a2.postMessage(message, "*");
185
+ (_a3 = window.parent) == null ? void 0 : _a3.postMessage(message, "*");
194
186
  });
195
187
  window.addEventListener("message", processMessage);
196
188
  window.addEventListener("builder:component:stateChangeListenerActivated", emitStateUpdate);
197
189
  }
198
190
  if (useContent()) {
199
- track({
191
+ const variationId = (_a2 = useContent == null ? void 0 : useContent()) == null ? void 0 : _a2.testVariationId;
192
+ const contentId = (_b2 = useContent == null ? void 0 : useContent()) == null ? void 0 : _b2.id;
193
+ _track({
200
194
  type: "impression",
201
195
  canTrack: canTrackToUse(),
202
- contentId: useContent().id,
203
- orgId: props.apiKey
196
+ contentId,
197
+ apiKey: props.apiKey,
198
+ variationId: variationId !== contentId ? variationId : void 0
204
199
  });
205
200
  }
206
201
  if (isPreviewing()) {
@@ -262,12 +257,13 @@ function RenderContent(props) {
262
257
  }, useContent() ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
263
258
  ref: elementRef,
264
259
  onClick: (event) => onClick(event),
265
- "builder-content-id": (_e = useContent == null ? void 0 : useContent()) == null ? void 0 : _e.id
260
+ "builder-content-id": (_e = useContent == null ? void 0 : useContent()) == null ? void 0 : _e.id,
261
+ "builder-model": props.model
266
262
  }, shouldRenderContentStyles() ? /* @__PURE__ */ React.createElement(RenderContentStyles, {
267
263
  cssCode: (_g = (_f = useContent == null ? void 0 : useContent()) == null ? void 0 : _f.data) == null ? void 0 : _g.cssCode,
268
264
  customFonts: (_i = (_h = useContent == null ? void 0 : useContent()) == null ? void 0 : _h.data) == null ? void 0 : _i.customFonts
269
265
  }) : null, /* @__PURE__ */ React.createElement(RenderBlocks, {
270
- blocks: (_k = (_j = useContent == null ? void 0 : useContent()) == null ? void 0 : _j.data) == null ? void 0 : _k.blocks,
266
+ blocks: markMutable((_k = (_j = useContent == null ? void 0 : useContent()) == null ? void 0 : _j.data) == null ? void 0 : _k.blocks),
271
267
  key: forceReRenderCount
272
268
  }))) : null);
273
269
  }
@@ -14,26 +14,28 @@ var __spreadValues = (a, b) => {
14
14
  }
15
15
  return a;
16
16
  };
17
- import { default as Button } from "../blocks/button/button.js";
17
+ import { default as Button } from "../blocks/button/button.jsx";
18
18
  import { componentInfo as buttonComponentInfo } from "../blocks/button/component-info.js";
19
- import { default as Columns } from "../blocks/columns/columns.js";
19
+ import { default as Columns } from "../blocks/columns/columns.jsx";
20
20
  import { componentInfo as columnsComponentInfo } from "../blocks/columns/component-info.js";
21
21
  import { componentInfo as fragmentComponentInfo } from "../blocks/fragment/component-info.js";
22
- import { default as Fragment } from "../blocks/fragment/fragment.js";
22
+ import { default as Fragment } from "../blocks/fragment/fragment.jsx";
23
23
  import { componentInfo as imageComponentInfo } from "../blocks/image/component-info.js";
24
- import { default as Image } from "../blocks/image/image.js";
24
+ import { default as Image } from "../blocks/image/image.jsx";
25
25
  import { componentInfo as sectionComponentInfo } from "../blocks/section/component-info.js";
26
- import { default as Section } from "../blocks/section/section.js";
26
+ import { default as Section } from "../blocks/section/section.jsx";
27
27
  import { componentInfo as symbolComponentInfo } from "../blocks/symbol/component-info.js";
28
- import { default as Symbol } from "../blocks/symbol/symbol.js";
28
+ import { default as Symbol } from "../blocks/symbol/symbol.jsx";
29
29
  import { componentInfo as textComponentInfo } from "../blocks/text/component-info.js";
30
- import { default as Text } from "../blocks/text/text.js";
30
+ import { default as Text } from "../blocks/text/text.jsx";
31
31
  import { componentInfo as videoComponentInfo } from "../blocks/video/component-info.js";
32
- import { default as Video } from "../blocks/video/video.js";
32
+ import { default as Video } from "../blocks/video/video.jsx";
33
33
  import { componentInfo as embedComponentInfo } from "../blocks/embed/component-info.js";
34
- import { default as embed } from "../blocks/embed/embed.js";
35
- import { default as Img } from "../blocks/img/img.js";
34
+ import { default as embed } from "../blocks/embed/embed.jsx";
35
+ import { default as Img } from "../blocks/img/img.jsx";
36
36
  import { componentInfo as imgComponentInfo } from "../blocks/img/component-info.js";
37
+ import { default as customCode } from "../blocks/custom-code/custom-code.jsx";
38
+ import { componentInfo as customCodeInfo } from "../blocks/custom-code/component-info.js";
37
39
  const getDefaultRegisteredComponents = () => [
38
40
  __spreadValues({ component: Columns }, columnsComponentInfo),
39
41
  __spreadValues({ component: Image }, imageComponentInfo),
@@ -44,7 +46,8 @@ const getDefaultRegisteredComponents = () => [
44
46
  __spreadValues({ component: Button }, buttonComponentInfo),
45
47
  __spreadValues({ component: Section }, sectionComponentInfo),
46
48
  __spreadValues({ component: Fragment }, fragmentComponentInfo),
47
- __spreadValues({ component: embed }, embedComponentInfo)
49
+ __spreadValues({ component: embed }, embedComponentInfo),
50
+ __spreadValues({ component: customCode }, customCodeInfo)
48
51
  ];
49
52
  export {
50
53
  getDefaultRegisteredComponents
@@ -4,7 +4,8 @@ var stdin_default = createContext({
4
4
  context: {},
5
5
  state: {},
6
6
  apiKey: null,
7
- registeredComponents: {}
7
+ registeredComponents: {},
8
+ inheritedStyles: {}
8
9
  });
9
10
  export {
10
11
  stdin_default as default
File without changes
@@ -20,7 +20,7 @@ function evaluate({
20
20
  try {
21
21
  return new Function("builder", "Builder", "state", "context", "event", useCode)(builder, builder, state, context, event);
22
22
  } catch (e) {
23
- console.warn("Builder custom code error: ", e);
23
+ console.warn("Builder custom code error: \n While Evaluating: \n ", useCode, "\n", e.message || e);
24
24
  }
25
25
  }
26
26
  export {
@@ -0,0 +1,22 @@
1
+ const TEXT_STYLE_KEYS = [
2
+ "color",
3
+ "whiteSpace",
4
+ "direction",
5
+ "hyphens",
6
+ "overflowWrap"
7
+ ];
8
+ const isTextStyle = (key) => {
9
+ return TEXT_STYLE_KEYS.includes(key) || key.startsWith("font") || key.startsWith("text") || key.startsWith("letter") || key.startsWith("line") || key.startsWith("word") || key.startsWith("writing");
10
+ };
11
+ const extractTextStyles = (styles) => {
12
+ const textStyles = {};
13
+ Object.entries(styles).forEach(([key, value]) => {
14
+ if (isTextStyle(key)) {
15
+ textStyles[key] = value;
16
+ }
17
+ });
18
+ return textStyles;
19
+ };
20
+ export {
21
+ extractTextStyles
22
+ };
@@ -0,0 +1,4 @@
1
+ const fastClone = (obj) => JSON.parse(JSON.stringify(obj));
2
+ export {
3
+ fastClone
4
+ };
@@ -0,0 +1,12 @@
1
+ import { evaluate } from "./evaluate.js";
2
+ function crateEventHandler(value, options) {
3
+ return (event) => evaluate({
4
+ code: value,
5
+ context: options.context,
6
+ state: options.state,
7
+ event
8
+ });
9
+ }
10
+ export {
11
+ crateEventHandler
12
+ };
@@ -1,5 +1,5 @@
1
- import { evaluate } from "./evaluate.js";
2
1
  import { getEventHandlerName } from "./event-handler-name.js";
2
+ import { crateEventHandler } from "./get-block-actions-handler.js";
3
3
  function getBlockActions(options) {
4
4
  var _a;
5
5
  const obj = {};
@@ -9,12 +9,7 @@ function getBlockActions(options) {
9
9
  continue;
10
10
  }
11
11
  const value = optionActions[key];
12
- obj[getEventHandlerName(key)] = (event) => evaluate({
13
- code: value,
14
- context: options.context,
15
- state: options.state,
16
- event
17
- });
12
+ obj[getEventHandlerName(key)] = crateEventHandler(value, options);
18
13
  }
19
14
  return obj;
20
15
  }
@@ -7,7 +7,11 @@ const convertSearchParamsToQueryObject = (searchParams) => {
7
7
  });
8
8
  return options;
9
9
  };
10
- const getBuilderSearchParams = (options) => {
10
+ const getBuilderSearchParams = (_options) => {
11
+ if (!_options) {
12
+ return {};
13
+ }
14
+ const options = normalizeSearchParams(_options);
11
15
  const newOptions = {};
12
16
  Object.keys(options).forEach((key) => {
13
17
  if (key.startsWith(BUILDER_SEARCHPARAMS_PREFIX)) {
@@ -22,7 +26,7 @@ const getBuilderSearchParamsFromWindow = () => {
22
26
  return {};
23
27
  }
24
28
  const searchParams = new URLSearchParams(window.location.search);
25
- return getBuilderSearchParams(convertSearchParamsToQueryObject(searchParams));
29
+ return getBuilderSearchParams(searchParams);
26
30
  };
27
31
  const normalizeSearchParams = (searchParams) => searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams;
28
32
  export {
@@ -1,38 +1,99 @@
1
- const handleABTesting = (item, testGroups) => {
2
- if (item.variations && Object.keys(item.variations).length) {
3
- const testGroup = item.id ? testGroups[item.id] : void 0;
4
- const variationValue = testGroup ? item.variations[testGroup] : void 0;
5
- if (testGroup && variationValue) {
6
- item.data = variationValue.data;
7
- item.testVariationId = variationValue.id;
8
- item.testVariationName = variationValue.name;
9
- } else {
10
- let n = 0;
11
- const random = Math.random();
12
- let set = false;
13
- for (const id in item.variations) {
14
- const variation = item.variations[id];
15
- const testRatio = variation.testRatio;
16
- n += testRatio;
17
- if (random < n) {
18
- const variationName = variation.name || (variation.id === item.id ? "Default variation" : "");
19
- set = true;
20
- Object.assign(item, {
21
- data: variation.data,
22
- testVariationId: variation.id,
23
- testVariationName: variationName
24
- });
25
- }
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
26
8
  }
27
- if (!set) {
28
- Object.assign(item, {
29
- testVariationId: item.id,
30
- testVariationName: "Default"
31
- });
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
32
15
  }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+ import {
22
+ getContentVariationCookie,
23
+ setContentVariationCookie
24
+ } from "../../helpers/ab-tests.js";
25
+ import { checkIsDefined } from "../../helpers/nullable.js";
26
+ const checkIsBuilderContentWithVariations = (item) => checkIsDefined(item.id) && checkIsDefined(item.variations) && Object.keys(item.variations).length > 0;
27
+ const getRandomVariationId = ({
28
+ id,
29
+ variations
30
+ }) => {
31
+ var _a;
32
+ let n = 0;
33
+ const random = Math.random();
34
+ for (const id2 in variations) {
35
+ const testRatio = (_a = variations[id2]) == null ? void 0 : _a.testRatio;
36
+ n += testRatio;
37
+ if (random < n) {
38
+ return id2;
33
39
  }
34
40
  }
41
+ return id;
42
+ };
43
+ const getTestFields = ({
44
+ item,
45
+ testGroupId
46
+ }) => {
47
+ const variationValue = item.variations[testGroupId];
48
+ if (testGroupId === item.id || !variationValue) {
49
+ return {
50
+ testVariationId: item.id,
51
+ testVariationName: "Default"
52
+ };
53
+ } else {
54
+ return {
55
+ data: variationValue.data,
56
+ testVariationId: variationValue.id,
57
+ testVariationName: variationValue.name || (variationValue.id === item.id ? "Default" : "")
58
+ };
59
+ }
35
60
  };
61
+ const getContentVariation = (_0) => __async(void 0, [_0], function* ({
62
+ item,
63
+ canTrack
64
+ }) {
65
+ const testGroupId = yield getContentVariationCookie({
66
+ canTrack,
67
+ contentId: item.id
68
+ });
69
+ const testFields = testGroupId ? getTestFields({ item, testGroupId }) : void 0;
70
+ if (testFields) {
71
+ return testFields;
72
+ } else {
73
+ const randomVariationId = getRandomVariationId({
74
+ variations: item.variations,
75
+ id: item.id
76
+ });
77
+ setContentVariationCookie({
78
+ contentId: item.id,
79
+ value: randomVariationId,
80
+ canTrack
81
+ }).catch((err) => {
82
+ console.error("could not store A/B test variation: ", err);
83
+ });
84
+ return getTestFields({ item, testGroupId: randomVariationId });
85
+ }
86
+ });
87
+ const handleABTesting = (_0) => __async(void 0, [_0], function* ({
88
+ item,
89
+ canTrack
90
+ }) {
91
+ if (!checkIsBuilderContentWithVariations(item)) {
92
+ return;
93
+ }
94
+ const variationValue = yield getContentVariation({ item, canTrack });
95
+ Object.assign(item, variationValue);
96
+ });
36
97
  export {
37
98
  handleABTesting
38
99
  };
@@ -44,7 +44,6 @@ import {
44
44
  } from "../get-builder-search-params/index.js";
45
45
  import { getFetch } from "../get-fetch.js";
46
46
  import { handleABTesting } from "./ab-testing.js";
47
- const fetch$ = getFetch();
48
47
  function getContent(options) {
49
48
  return __async(this, null, function* () {
50
49
  return (yield getAllContent(__spreadProps(__spreadValues({}, options), { limit: 1 }))).results[0] || null;
@@ -52,7 +51,7 @@ function getContent(options) {
52
51
  }
53
52
  const generateContentUrl = (options) => {
54
53
  const {
55
- limit = 1,
54
+ limit = 30,
56
55
  userAttributes,
57
56
  query,
58
57
  noTraverse = false,
@@ -79,11 +78,12 @@ const generateContentUrl = (options) => {
79
78
  function getAllContent(options) {
80
79
  return __async(this, null, function* () {
81
80
  const url = generateContentUrl(options);
82
- const fetch = yield fetch$;
81
+ const fetch = yield getFetch();
83
82
  const content = yield fetch(url.href).then((res) => res.json());
84
- if (options.testGroups) {
83
+ const canTrack = options.canTrack !== false;
84
+ if (canTrack) {
85
85
  for (const item of content.results) {
86
- handleABTesting(item, options.testGroups);
86
+ yield handleABTesting({ item, canTrack });
87
87
  }
88
88
  }
89
89
  return content;
@@ -18,6 +18,7 @@ var __spreadValues = (a, b) => {
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
20
  import { evaluate } from "./evaluate.js";
21
+ import { fastClone } from "./fast-clone.js";
21
22
  import { set } from "./set.js";
22
23
  import { transformBlock } from "./transform-block.js";
23
24
  const evaluateBindings = ({
@@ -28,9 +29,10 @@ const evaluateBindings = ({
28
29
  if (!block.bindings) {
29
30
  return block;
30
31
  }
31
- const copied = __spreadProps(__spreadValues({}, block), {
32
- properties: __spreadValues({}, block.properties),
33
- actions: __spreadValues({}, block.actions)
32
+ const copy = fastClone(block);
33
+ const copied = __spreadProps(__spreadValues({}, copy), {
34
+ properties: __spreadValues({}, copy.properties),
35
+ actions: __spreadValues({}, copy.actions)
34
36
  });
35
37
  for (const binding in block.bindings) {
36
38
  const expression = block.bindings[binding];
@@ -0,0 +1,32 @@
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
+ };
17
+ import { sanitizeReactNativeBlockStyles } from "./sanitize-react-native-block-styles.js";
18
+ function getReactNativeBlockStyles({
19
+ block,
20
+ context
21
+ }) {
22
+ const responsiveStyles = block.responsiveStyles;
23
+ if (!responsiveStyles) {
24
+ return {};
25
+ }
26
+ const styles = __spreadValues(__spreadValues(__spreadValues(__spreadValues({}, context.inheritedStyles), responsiveStyles.large || {}), responsiveStyles.medium || {}), responsiveStyles.small || {});
27
+ const newStyles = sanitizeReactNativeBlockStyles(styles);
28
+ return newStyles;
29
+ }
30
+ export {
31
+ getReactNativeBlockStyles
32
+ };
@@ -0,0 +1,10 @@
1
+ function markMutable(value) {
2
+ return value;
3
+ }
4
+ function markPropsMutable(props) {
5
+ return props;
6
+ }
7
+ export {
8
+ markMutable,
9
+ markPropsMutable
10
+ };
@@ -29,6 +29,7 @@ var __objRest = (source, exclude) => {
29
29
  }
30
30
  return target;
31
31
  };
32
+ import { fastClone } from "./fast-clone.js";
32
33
  const components = [];
33
34
  function registerComponent(component, info) {
34
35
  components.push(__spreadValues({ component }, info));
@@ -46,7 +47,6 @@ const createRegisterComponentMessage = (_a) => {
46
47
  data: prepareComponentInfoToSend(info)
47
48
  };
48
49
  };
49
- const fastClone = (obj) => JSON.parse(JSON.stringify(obj));
50
50
  const serializeValue = (value) => typeof value === "function" ? serializeFn(value) : fastClone(value);
51
51
  const serializeFn = (fnValue) => {
52
52
  const fnStr = fnValue.toString().trim();
@@ -0,0 +1,66 @@
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));
20
+ const propertiesThatMustBeNumber = new Set(["lineHeight"]);
21
+ const displayValues = new Set(["flex", "none"]);
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
+ };
32
+ const sanitizeReactNativeBlockStyles = (styles) => {
33
+ return Object.keys(styles).reduce((acc, key) => {
34
+ const propertyValue = styles[key];
35
+ if (key === "display" && !displayValues.has(propertyValue)) {
36
+ if (SHOW_WARNINGS) {
37
+ console.warn(`Style value for key "display" must be "flex" or "none" but had ${propertyValue}`);
38
+ }
39
+ return acc;
40
+ }
41
+ if (propertiesThatMustBeNumber.has(key) && typeof propertyValue !== "number") {
42
+ if (SHOW_WARNINGS) {
43
+ console.warn(`Style key ${key} must be a number, but had value \`${styles[key]}\``);
44
+ }
45
+ return acc;
46
+ }
47
+ if (typeof propertyValue === "string") {
48
+ const isPixelUnit = propertyValue.match(/^-?(\d*)(\.?)(\d*)*px$/);
49
+ if (isPixelUnit) {
50
+ const newValue = parseFloat(propertyValue);
51
+ const normalizedValue = normalizeNumber(newValue);
52
+ if (normalizedValue) {
53
+ return __spreadProps(__spreadValues({}, acc), { [key]: normalizedValue });
54
+ } else {
55
+ return acc;
56
+ }
57
+ } else if (propertyValue === "0") {
58
+ return __spreadProps(__spreadValues({}, acc), { [key]: 0 });
59
+ }
60
+ }
61
+ return __spreadProps(__spreadValues({}, acc), { [key]: propertyValue });
62
+ }, {});
63
+ };
64
+ export {
65
+ sanitizeReactNativeBlockStyles
66
+ };