@builder.io/sdk-react-native 0.4.5 → 0.5.1

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 (251) hide show
  1. package/dist/blocks/button/button.js +6 -2
  2. package/dist/blocks/button/component-info.js +4 -8
  3. package/dist/blocks/columns/columns.js +17 -21
  4. package/dist/blocks/columns/component-info.js +27 -48
  5. package/dist/blocks/custom-code/component-info.js +4 -8
  6. package/dist/blocks/custom-code/custom-code.js +1 -1
  7. package/dist/blocks/embed/component-info.js +7 -11
  8. package/dist/blocks/embed/embed.js +1 -1
  9. package/dist/blocks/embed/helpers.js +2 -6
  10. package/dist/blocks/form/component-info.js +33 -69
  11. package/dist/blocks/form/form.js +2 -203
  12. package/dist/blocks/fragment/fragment.js +1 -1
  13. package/dist/blocks/helpers.js +33 -0
  14. package/dist/blocks/image/component-info.js +21 -47
  15. package/dist/blocks/image/image.helpers.js +2 -2
  16. package/dist/blocks/img/component-info.js +2 -4
  17. package/dist/blocks/img/img.js +2 -1
  18. package/dist/blocks/input/component-info.js +8 -34
  19. package/dist/blocks/input/input.js +2 -1
  20. package/dist/blocks/raw-text/component-info.js +2 -4
  21. package/dist/blocks/raw-text/raw-text.js +3 -2
  22. package/dist/blocks/section/component-info.js +5 -10
  23. package/dist/blocks/section/section.js +2 -1
  24. package/dist/blocks/select/component-info.js +12 -24
  25. package/dist/blocks/select/select.js +2 -1
  26. package/dist/blocks/submit-button/component-info.js +2 -4
  27. package/dist/blocks/submit-button/submit-button.js +2 -1
  28. package/dist/blocks/symbol/component-info.js +7 -12
  29. package/dist/blocks/symbol/symbol.helpers.js +66 -0
  30. package/dist/blocks/symbol/symbol.js +23 -52
  31. package/dist/blocks/text/component-info.js +3 -4
  32. package/dist/blocks/textarea/component-info.js +6 -12
  33. package/dist/blocks/textarea/textarea.js +2 -1
  34. package/dist/blocks/video/component-info.js +21 -41
  35. package/dist/components/block/block.helpers.js +12 -23
  36. package/dist/components/block/block.js +40 -70
  37. package/dist/components/block/components/block-styles.js +1 -1
  38. package/dist/components/block/components/block-wrapper/block-wrapper.js +41 -0
  39. package/dist/components/block/components/block-wrapper.js +56 -0
  40. package/dist/components/block/components/component-ref/component-ref.helpers.js +40 -0
  41. package/dist/components/block/components/component-ref/component-ref.js +63 -0
  42. package/dist/components/block/components/component-ref.js +81 -0
  43. package/dist/components/block/components/interactive-element/interactive-element.helpers.js +35 -0
  44. package/dist/components/block/components/interactive-element/interactive-element.js +36 -0
  45. package/dist/components/block/components/interactive-element.js +46 -0
  46. package/dist/components/block/components/repeated-block.js +4 -4
  47. package/dist/components/blocks/blocks-wrapper.js +5 -2
  48. package/dist/components/blocks/blocks.js +9 -3
  49. package/dist/components/content/builder-editing.js +32 -0
  50. package/dist/components/content/components/enable-editor.js +30 -33
  51. package/dist/components/content/components/styles.helpers.js +55 -0
  52. package/dist/components/content/components/styles.js +61 -0
  53. package/dist/components/content/content.helpers.js +10 -3
  54. package/dist/components/content/content.js +27 -40
  55. package/dist/components/content/wrap-component-ref.js +1 -1
  56. package/dist/components/content-variants/content-variants.js +38 -34
  57. package/dist/components/content-variants/content-variants.types.js +1 -0
  58. package/dist/components/content-variants/helpers.js +61 -25
  59. package/dist/components/inlined-script.js +1 -1
  60. package/dist/components/inlined-styles.js +1 -1
  61. package/dist/constants/device-sizes.js +2 -2
  62. package/dist/constants/sdk-version.js +1 -1
  63. package/dist/context/builder.context.js +1 -1
  64. package/dist/context/components.context.js +6 -0
  65. package/dist/functions/apply-patch-with-mutation.js +75 -0
  66. package/dist/functions/apply-patch-with-mutation.test.js +55 -0
  67. package/dist/functions/camel-to-kebab-case.js +1 -1
  68. package/dist/functions/evaluate/acorn.js +1691 -0
  69. package/dist/functions/evaluate/evaluate.js +72 -0
  70. package/dist/functions/evaluate/index.js +5 -0
  71. package/dist/functions/evaluate/interpreter.js +2903 -0
  72. package/dist/functions/evaluate/non-node-runtime.js +97 -0
  73. package/dist/functions/evaluate/types.js +1 -0
  74. package/dist/functions/evaluate.test.js +12 -6
  75. package/dist/functions/event-handler-name.js +1 -1
  76. package/dist/functions/extract-text-styles.js +3 -9
  77. package/dist/functions/fast-clone.js +1 -1
  78. package/dist/functions/get-block-actions-handler.js +2 -2
  79. package/dist/functions/get-block-actions.js +14 -1
  80. package/dist/functions/get-block-component-options.js +6 -1
  81. package/dist/functions/get-block-properties.js +21 -8
  82. package/dist/functions/get-builder-search-params/fn.test.js +3 -3
  83. package/dist/functions/get-builder-search-params/index.js +4 -4
  84. package/dist/functions/get-content/generate-content-url.js +12 -5
  85. package/dist/functions/get-content/generate-content-url.test.js +31 -17
  86. package/dist/functions/get-content/index.js +36 -12
  87. package/dist/functions/get-content/processCookies.js +7 -0
  88. package/dist/functions/get-processed-block.js +8 -3
  89. package/dist/functions/get-processed-block.test.js +3 -1
  90. package/dist/functions/get-react-native-block-styles.js +6 -1
  91. package/dist/functions/is-non-node-server.js +12 -0
  92. package/dist/functions/on-change.test.js +13 -3
  93. package/dist/functions/register-component.js +24 -19
  94. package/dist/functions/sanitize-react-native-block-styles.js +17 -6
  95. package/dist/functions/set.test.js +9 -3
  96. package/dist/functions/track/helpers.js +5 -5
  97. package/dist/functions/track/index.js +29 -18
  98. package/dist/functions/track/interaction.js +10 -4
  99. package/dist/functions/transform-block-properties.js +2 -0
  100. package/dist/helpers/ab-tests.js +35 -14
  101. package/dist/helpers/canTrack.js +2 -2
  102. package/dist/helpers/css.js +2 -2
  103. package/dist/helpers/flatten.js +10 -7
  104. package/dist/helpers/nullable.js +1 -1
  105. package/dist/helpers/preview-lru-cache/get.js +11 -0
  106. package/dist/helpers/preview-lru-cache/helpers.js +13 -0
  107. package/dist/helpers/preview-lru-cache/init.js +13 -0
  108. package/dist/helpers/preview-lru-cache/set.js +37 -0
  109. package/dist/helpers/preview-lru-cache/types.js +1 -0
  110. package/dist/helpers/sessionId.js +13 -6
  111. package/dist/helpers/url.js +1 -1
  112. package/dist/helpers/visitorId.js +4 -1
  113. package/dist/index-helpers/blocks-exports.js +2 -2
  114. package/dist/scripts/init-editing.js +61 -46
  115. package/package.json +2 -2
  116. package/src/blocks/button/button.jsx +11 -2
  117. package/src/blocks/button/component-info.js +16 -22
  118. package/src/blocks/columns/columns.jsx +27 -26
  119. package/src/blocks/columns/component-info.js +203 -226
  120. package/src/blocks/custom-code/component-info.js +19 -25
  121. package/src/blocks/custom-code/custom-code.jsx +1 -1
  122. package/src/blocks/embed/component-info.js +31 -37
  123. package/src/blocks/embed/embed.jsx +1 -1
  124. package/src/blocks/embed/helpers.js +3 -9
  125. package/src/blocks/form/component-info.js +174 -212
  126. package/src/blocks/form/form.jsx +3 -247
  127. package/src/blocks/fragment/component-info.js +1 -3
  128. package/src/blocks/fragment/fragment.jsx +1 -1
  129. package/src/blocks/helpers.js +27 -0
  130. package/src/blocks/image/component-info.js +105 -133
  131. package/src/blocks/image/image.helpers.js +3 -5
  132. package/src/blocks/img/component-info.js +8 -12
  133. package/src/blocks/img/img.jsx +3 -1
  134. package/src/blocks/input/component-info.js +29 -57
  135. package/src/blocks/input/input.jsx +3 -1
  136. package/src/blocks/raw-text/component-info.js +7 -11
  137. package/src/blocks/raw-text/raw-text.jsx +4 -2
  138. package/src/blocks/section/component-info.js +24 -31
  139. package/src/blocks/section/section.jsx +3 -1
  140. package/src/blocks/select/component-info.js +34 -48
  141. package/src/blocks/select/select.jsx +3 -1
  142. package/src/blocks/submit-button/component-info.js +6 -10
  143. package/src/blocks/submit-button/submit-button.jsx +3 -2
  144. package/src/blocks/symbol/component-info.js +30 -37
  145. package/src/blocks/symbol/symbol.helpers.js +60 -0
  146. package/src/blocks/symbol/symbol.jsx +33 -61
  147. package/src/blocks/text/component-info.js +10 -13
  148. package/src/blocks/textarea/component-info.js +22 -30
  149. package/src/blocks/textarea/textarea.jsx +3 -1
  150. package/src/blocks/video/component-info.js +74 -96
  151. package/src/components/{render-block/render-block.helpers.js → block/block.helpers.js} +26 -44
  152. package/src/components/{render-block/render-block.jsx → block/block.jsx} +68 -81
  153. package/src/components/{render-block → block/components}/block-styles.jsx +18 -17
  154. package/src/components/block/components/block-wrapper.jsx +58 -0
  155. package/src/components/block/components/component-ref/component-ref.helpers.js +41 -0
  156. package/src/components/block/components/component-ref/component-ref.jsx +72 -0
  157. package/src/components/block/components/interactive-element.jsx +37 -0
  158. package/src/components/{render-block/render-repeated-block.jsx → block/components/repeated-block.jsx} +10 -6
  159. package/src/components/blocks/blocks-wrapper.jsx +74 -0
  160. package/src/components/blocks/blocks.jsx +61 -0
  161. package/src/components/{render-content/render-content.jsx → content/components/enable-editor.jsx} +77 -163
  162. package/src/components/{render-content/components/render-styles.helpers.js → content/components/styles.helpers.js} +6 -7
  163. package/src/components/{render-content/components/render-styles.jsx → content/components/styles.jsx} +5 -5
  164. package/src/components/{render-content/render-content.helpers.js → content/content.helpers.js} +15 -15
  165. package/src/components/content/content.jsx +148 -0
  166. package/src/components/content/index.js +2 -0
  167. package/src/components/content/wrap-component-ref.js +2 -0
  168. package/src/components/{render-content-variants/render-content-variants.jsx → content-variants/content-variants.jsx} +20 -23
  169. package/src/components/{render-content-variants → content-variants}/helpers.js +28 -40
  170. package/src/components/inlined-script.jsx +1 -1
  171. package/src/components/inlined-styles.jsx +1 -1
  172. package/src/constants/device-sizes.js +6 -6
  173. package/src/constants/sdk-version.js +1 -1
  174. package/src/context/builder.context.js +1 -1
  175. package/src/context/components.context.js +5 -0
  176. package/src/functions/apply-patch-with-mutation.js +66 -0
  177. package/src/functions/camel-to-kebab-case.js +2 -4
  178. package/src/functions/evaluate/acorn.js +1595 -0
  179. package/src/functions/{evaluate.js → evaluate/evaluate.js} +36 -10
  180. package/src/functions/evaluate/index.js +2 -0
  181. package/src/functions/evaluate/interpreter.js +2801 -0
  182. package/src/functions/evaluate/non-node-runtime.js +92 -0
  183. package/src/functions/evaluate/types.js +0 -0
  184. package/src/functions/event-handler-name.js +2 -4
  185. package/src/functions/extract-text-styles.js +4 -12
  186. package/src/functions/fast-clone.js +2 -4
  187. package/src/functions/get-block-actions-handler.js +3 -5
  188. package/src/functions/get-block-actions.js +15 -4
  189. package/src/functions/get-block-component-options.js +11 -12
  190. package/src/functions/get-block-properties.js +29 -19
  191. package/src/functions/get-builder-search-params/index.js +5 -10
  192. package/src/functions/get-content/generate-content-url.js +17 -19
  193. package/src/functions/get-content/index.js +43 -29
  194. package/src/functions/get-fetch.js +1 -3
  195. package/src/functions/get-global-this.js +1 -3
  196. package/src/functions/get-processed-block.js +12 -13
  197. package/src/functions/get-react-native-block-styles.js +11 -12
  198. package/src/functions/if-target.js +1 -3
  199. package/src/functions/is-browser.js +1 -3
  200. package/src/functions/is-editing.js +1 -3
  201. package/src/functions/is-iframe.js +1 -3
  202. package/src/functions/is-non-node-server.js +9 -0
  203. package/src/functions/is-previewing.js +1 -3
  204. package/src/functions/on-change.js +1 -4
  205. package/src/functions/register-component.js +34 -42
  206. package/src/functions/register.js +1 -3
  207. package/src/functions/sanitize-react-native-block-styles.js +22 -17
  208. package/src/functions/set-editor-settings.js +1 -3
  209. package/src/functions/set.js +1 -3
  210. package/src/functions/track/helpers.js +3 -5
  211. package/src/functions/track/index.js +45 -43
  212. package/src/functions/track/interaction.js +11 -7
  213. package/src/functions/transform-block-properties.js +2 -0
  214. package/src/helpers/ab-tests.js +45 -28
  215. package/src/helpers/canTrack.js +3 -5
  216. package/src/helpers/css.js +3 -7
  217. package/src/helpers/flatten.js +15 -18
  218. package/src/helpers/localStorage.js +1 -4
  219. package/src/helpers/logger.js +1 -3
  220. package/src/helpers/nullable.js +2 -4
  221. package/src/helpers/preview-lru-cache/get.js +8 -0
  222. package/src/helpers/preview-lru-cache/helpers.js +10 -0
  223. package/src/helpers/preview-lru-cache/init.js +10 -0
  224. package/src/helpers/preview-lru-cache/set.js +35 -0
  225. package/src/helpers/preview-lru-cache/types.js +0 -0
  226. package/src/helpers/sessionId.js +14 -11
  227. package/src/helpers/time.js +1 -3
  228. package/src/helpers/url.js +2 -4
  229. package/src/helpers/uuid.js +4 -6
  230. package/src/helpers/visitorId.js +8 -7
  231. package/src/index-helpers/blocks-exports.js +1 -1
  232. package/src/index.js +2 -17
  233. package/src/scripts/init-editing.js +62 -48
  234. package/src/types/api-version.js +1 -3
  235. package/src/types/builder-props.js +0 -0
  236. package/src/blocks/util.js +0 -8
  237. package/src/components/render-block/render-component.jsx +0 -55
  238. package/src/components/render-blocks.jsx +0 -101
  239. package/src/components/render-content/builder-editing.jsx +0 -16
  240. package/src/components/render-content/index.js +0 -4
  241. package/src/components/render-content/wrap-component-ref.js +0 -4
  242. package/src/functions/evaluate.test.js +0 -17
  243. package/src/functions/get-builder-search-params/fn.test.js +0 -13
  244. package/src/functions/get-content/generate-content-url.test.js +0 -97
  245. package/src/functions/get-processed-block.test.js +0 -34
  246. package/src/functions/on-change.test.js +0 -19
  247. package/src/functions/set.test.js +0 -16
  248. package/src/helpers/url.test.js +0 -21
  249. /package/src/components/{render-block → block}/types.js +0 -0
  250. /package/src/components/{render-content/render-content.types.js → content/content.types.js} +0 -0
  251. /package/src/components/{render-content-variants/render-content-variants.types.js → content-variants/content-variants.types.js} +0 -0
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.runInNonNode = void 0;
7
+ var __defProp = Object.defineProperty;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
12
+ enumerable: true,
13
+ configurable: true,
14
+ writable: true,
15
+ value
16
+ }) : obj[key] = value;
17
+ var __spreadValues = (a, b) => {
18
+ for (var prop in b || (b = {}))
19
+ if (__hasOwnProp.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ if (__getOwnPropSymbols)
22
+ for (var prop of __getOwnPropSymbols(b)) {
23
+ if (__propIsEnum.call(b, prop))
24
+ __defNormalProp(a, prop, b[prop]);
25
+ }
26
+ return a;
27
+ };
28
+ const logger_1 = require("../../helpers/logger");
29
+ const set_1 = require("../set");
30
+ const interpreter_js_1 = __importDefault(require("./interpreter.js"));
31
+ const processCode = code => {
32
+ return code.split("\n").map(line => {
33
+ const trimmed = line.trim();
34
+ if (line.includes("__awaiter"))
35
+ return void 0;
36
+ const isStateSetter = trimmed.startsWith("state.");
37
+ if (!isStateSetter)
38
+ return line;
39
+ const [lhs, rhs] = trimmed.split("=");
40
+ const setStr = lhs.replace("state.", "").trim();
41
+ const setExpr = `setRootState('${setStr}', ${rhs.trim()})`;
42
+ return `
43
+ ${line}
44
+ ${setExpr}
45
+ `;
46
+ }).filter(Boolean).join("\n");
47
+ };
48
+ const getJSONValName = val => val + "JSON";
49
+ const runInNonNode = ({ builder, context, event, rootState, localState, rootSetState, useCode }) => {
50
+ const state = __spreadValues(__spreadValues({}, rootState), localState);
51
+ const properties = {
52
+ state,
53
+ Builder: builder,
54
+ builder,
55
+ context,
56
+ event
57
+ };
58
+ const prependedCode = Object.keys(properties).map(key => `var ${key} = JSON.parse(${getJSONValName(key)});`).join("\n");
59
+ const cleanedCode = processCode(useCode);
60
+ if (cleanedCode === "") {
61
+ logger_1.logger.warn("Skipping evaluation of empty code block.");
62
+ return;
63
+ }
64
+ const transformed = `
65
+ function theFunction() {
66
+ ${prependedCode}
67
+
68
+ ${cleanedCode}
69
+ }
70
+ theFunction();
71
+ `;
72
+ const setRootState = (prop, value) => {
73
+ const newState = (0, set_1.set)(state, prop, value);
74
+ rootSetState == null ? void 0 : rootSetState(newState);
75
+ };
76
+ const initFunc = function (interpreter, globalObject) {
77
+ Object.keys(properties).forEach(key => {
78
+ const val = properties[key] || {};
79
+ const jsonVal = JSON.stringify(val);
80
+ interpreter.setProperty(globalObject, getJSONValName(key), jsonVal);
81
+ });
82
+ interpreter.setProperty(globalObject, "setRootState", interpreter.createNativeFunction(setRootState));
83
+ };
84
+ try {
85
+ const myInterpreter = new interpreter_js_1.default(transformed, initFunc);
86
+ myInterpreter.run();
87
+ const output = myInterpreter.pseudoToNative(myInterpreter.value);
88
+ return output;
89
+ }
90
+ catch (e) {
91
+ logger_1.logger.warn("Custom code error in non-node runtime. SDK can only execute ES5 JavaScript.", {
92
+ e
93
+ });
94
+ return;
95
+ }
96
+ };
97
+ exports.runInNonNode = runInNonNode;
@@ -0,0 +1 @@
1
+ "use strict";
@@ -1,19 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const evaluate_1 = require("./evaluate");
3
+ const evaluate_js_1 = require("./evaluate.js");
4
4
  describe("flatten state", () => {
5
5
  it("should behave normally when no PROTO_STATE", () => {
6
6
  const localState = {};
7
- const rootState = { foo: "bar" };
8
- const flattened = (0, evaluate_1.flattenState)(rootState, localState, void 0);
7
+ const rootState = {
8
+ foo: "bar"
9
+ };
10
+ const flattened = (0, evaluate_js_1.flattenState)(rootState, localState, void 0);
9
11
  expect(flattened.foo).toEqual("bar");
10
12
  flattened.foo = "baz";
11
13
  expect(rootState.foo).toEqual("baz");
12
14
  });
13
15
  it("should shadow write ", () => {
14
- const rootState = { foo: "foo" };
15
- const localState = { foo: "baz" };
16
- const flattened = (0, evaluate_1.flattenState)(rootState, localState, void 0);
16
+ const rootState = {
17
+ foo: "foo"
18
+ };
19
+ const localState = {
20
+ foo: "baz"
21
+ };
22
+ const flattened = (0, evaluate_js_1.flattenState)(rootState, localState, void 0);
17
23
  expect(() => flattened.foo = "bar").toThrow("Writing to local state is not allowed as it is read-only.");
18
24
  });
19
25
  });
@@ -4,5 +4,5 @@ exports.getEventHandlerName = void 0;
4
4
  function capitalizeFirstLetter(string) {
5
5
  return string.charAt(0).toUpperCase() + string.slice(1);
6
6
  }
7
- const getEventHandlerName = (key) => `on${capitalizeFirstLetter(key)}`;
7
+ const getEventHandlerName = key => `on${capitalizeFirstLetter(key)}`;
8
8
  exports.getEventHandlerName = getEventHandlerName;
@@ -1,17 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.extractTextStyles = void 0;
4
- const TEXT_STYLE_KEYS = [
5
- "color",
6
- "whiteSpace",
7
- "direction",
8
- "hyphens",
9
- "overflowWrap"
10
- ];
11
- const isTextStyle = (key) => {
4
+ const TEXT_STYLE_KEYS = ["color", "whiteSpace", "direction", "hyphens", "overflowWrap"];
5
+ const isTextStyle = key => {
12
6
  return TEXT_STYLE_KEYS.includes(key) || key.startsWith("font") || key.startsWith("text") || key.startsWith("letter") || key.startsWith("line") || key.startsWith("word") || key.startsWith("writing");
13
7
  };
14
- const extractTextStyles = (styles) => {
8
+ const extractTextStyles = styles => {
15
9
  const textStyles = {};
16
10
  Object.entries(styles).forEach(([key, value]) => {
17
11
  if (isTextStyle(key)) {
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fastClone = void 0;
4
- const fastClone = (obj) => JSON.parse(JSON.stringify(obj));
4
+ const fastClone = obj => JSON.parse(JSON.stringify(obj));
5
5
  exports.fastClone = fastClone;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createEventHandler = void 0;
4
- const evaluate_js_1 = require("./evaluate.js");
5
- const createEventHandler = (value, options) => (event) => (0, evaluate_js_1.evaluate)({
4
+ const evaluate_1 = require("./evaluate");
5
+ const createEventHandler = (value, options) => event => (0, evaluate_1.evaluate)({
6
6
  code: value,
7
7
  context: options.context,
8
8
  localState: options.localState,
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getBlockActions = void 0;
4
+ const target_js_1 = require("../constants/target.js");
4
5
  const event_handler_name_js_1 = require("./event-handler-name.js");
5
6
  const get_block_actions_handler_js_1 = require("./get-block-actions-handler.js");
6
7
  function getBlockActions(options) {
@@ -12,7 +13,19 @@ function getBlockActions(options) {
12
13
  continue;
13
14
  }
14
15
  const value = optionActions[key];
15
- obj[(0, event_handler_name_js_1.getEventHandlerName)(key)] = (0, get_block_actions_handler_js_1.createEventHandler)(value, options);
16
+ let eventHandlerName = (0, event_handler_name_js_1.getEventHandlerName)(key);
17
+ if (options.stripPrefix) {
18
+ switch (target_js_1.TARGET) {
19
+ case "vue2":
20
+ case "vue3":
21
+ eventHandlerName = eventHandlerName.replace("v-on:", "");
22
+ break;
23
+ case "svelte":
24
+ eventHandlerName = eventHandlerName.replace("on:", "");
25
+ break;
26
+ }
27
+ }
28
+ obj[eventHandlerName] = (0, get_block_actions_handler_js_1.createEventHandler)(value, options);
16
29
  }
17
30
  return obj;
18
31
  }
@@ -7,7 +7,12 @@ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
7
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
9
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
11
+ enumerable: true,
12
+ configurable: true,
13
+ writable: true,
14
+ value
15
+ }) : obj[key] = value;
11
16
  var __spreadValues = (a, b) => {
12
17
  for (var prop in b || (b = {}))
13
18
  if (__hasOwnProp.call(b, prop))
@@ -7,7 +7,12 @@ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
7
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
9
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
11
+ enumerable: true,
12
+ configurable: true,
13
+ writable: true,
14
+ value
15
+ }) : obj[key] = value;
11
16
  var __spreadValues = (a, b) => {
12
17
  for (var prop in b || (b = {}))
13
18
  if (__hasOwnProp.call(b, prop))
@@ -22,24 +27,31 @@ var __spreadValues = (a, b) => {
22
27
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
28
  const target_js_1 = require("../constants/target.js");
24
29
  const css_js_1 = require("../helpers/css.js");
30
+ const get_react_native_block_styles_js_1 = require("./get-react-native-block-styles.js");
25
31
  const transform_block_properties_js_1 = require("./transform-block-properties.js");
26
- const extractRelevantRootBlockProperties = (block) => {
27
- return { href: block.href };
32
+ const extractRelevantRootBlockProperties = block => {
33
+ return {
34
+ href: block.href
35
+ };
28
36
  };
29
- function getBlockProperties(block) {
37
+ function getBlockProperties({ block, context }) {
30
38
  var _a;
31
39
  const properties = __spreadProps(__spreadValues(__spreadValues({}, extractRelevantRootBlockProperties(block)), block.properties), {
32
40
  "builder-id": block.id,
33
- style: getStyleAttribute(block.style),
41
+ style: block.style ? getStyleAttribute(block.style) : void 0,
34
42
  class: [block.id, "builder-block", block.class, (_a = block.properties) == null ? void 0 : _a.class].filter(Boolean).join(" ")
35
43
  });
44
+ if (target_js_1.TARGET === "reactNative") {
45
+ properties.style = (0, get_react_native_block_styles_js_1.getReactNativeBlockStyles)({
46
+ block,
47
+ context,
48
+ blockStyles: properties.style
49
+ });
50
+ }
36
51
  return (0, transform_block_properties_js_1.transformBlockProperties)(properties);
37
52
  }
38
53
  exports.getBlockProperties = getBlockProperties;
39
54
  function getStyleAttribute(style) {
40
- if (!style) {
41
- return void 0;
42
- }
43
55
  switch (target_js_1.TARGET) {
44
56
  case "svelte":
45
57
  case "vue2":
@@ -49,6 +61,7 @@ function getStyleAttribute(style) {
49
61
  case "qwik":
50
62
  case "reactNative":
51
63
  case "react":
64
+ case "rsc":
52
65
  return style;
53
66
  }
54
67
  }
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const _1 = require(".");
3
+ const index_js_1 = require("./index.js");
4
4
  const querystring = "someotherValue=jklsjfdal&abc=klfdjklgfds&builder.cachebust=true&builder.preview=page&builder.noCache=true&__builder_editing__=true&builder.overrides.page=037948e52eaf4743afed464f02c70da4&builder.overrides.037948e52eaf4743afed464f02c70da4=037948e52eaf4743afed464f02c70da4&builder.overrides.page%3A%2F=037948e52eaf4743afed464f02c70da4&preview_theme_id=128854393017";
5
5
  const url = new URL(`localhost:3000/about-us?${querystring}`);
6
6
  describe("Get Builder SearchParams", () => {
7
7
  test("correctly converts URLSearchParams to object", () => {
8
- const output = (0, _1.convertSearchParamsToQueryObject)(url.searchParams);
8
+ const output = (0, index_js_1.convertSearchParamsToQueryObject)(url.searchParams);
9
9
  expect(output).toMatchSnapshot();
10
10
  });
11
11
  test("correctly extracts all builder params from a query object", () => {
12
- const output = (0, _1.getBuilderSearchParams)((0, _1.convertSearchParamsToQueryObject)(url.searchParams));
12
+ const output = (0, index_js_1.getBuilderSearchParams)((0, index_js_1.convertSearchParamsToQueryObject)(url.searchParams));
13
13
  expect(output).toMatchSnapshot();
14
14
  });
15
15
  });
@@ -4,7 +4,7 @@ exports.normalizeSearchParams = exports.getBuilderSearchParamsFromWindow = expor
4
4
  const is_browser_js_1 = require("../is-browser.js");
5
5
  const BUILDER_SEARCHPARAMS_PREFIX = "builder.";
6
6
  const BUILDER_OPTIONS_PREFIX = "options.";
7
- const convertSearchParamsToQueryObject = (searchParams) => {
7
+ const convertSearchParamsToQueryObject = searchParams => {
8
8
  const options = {};
9
9
  searchParams.forEach((value, key) => {
10
10
  options[key] = value;
@@ -12,13 +12,13 @@ const convertSearchParamsToQueryObject = (searchParams) => {
12
12
  return options;
13
13
  };
14
14
  exports.convertSearchParamsToQueryObject = convertSearchParamsToQueryObject;
15
- const getBuilderSearchParams = (_options) => {
15
+ const getBuilderSearchParams = _options => {
16
16
  if (!_options) {
17
17
  return {};
18
18
  }
19
19
  const options = normalizeSearchParams(_options);
20
20
  const newOptions = {};
21
- Object.keys(options).forEach((key) => {
21
+ Object.keys(options).forEach(key => {
22
22
  if (key.startsWith(BUILDER_SEARCHPARAMS_PREFIX)) {
23
23
  const trimmedKey = key.replace(BUILDER_SEARCHPARAMS_PREFIX, "").replace(BUILDER_OPTIONS_PREFIX, "");
24
24
  newOptions[trimmedKey] = options[key];
@@ -35,5 +35,5 @@ const getBuilderSearchParamsFromWindow = () => {
35
35
  return getBuilderSearchParams(searchParams);
36
36
  };
37
37
  exports.getBuilderSearchParamsFromWindow = getBuilderSearchParamsFromWindow;
38
- const normalizeSearchParams = (searchParams) => searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams;
38
+ const normalizeSearchParams = searchParams => searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams;
39
39
  exports.normalizeSearchParams = normalizeSearchParams;
@@ -5,7 +5,12 @@ var __defProp = Object.defineProperty;
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) => key in obj ? __defProp(obj, key, {
9
+ enumerable: true,
10
+ configurable: true,
11
+ writable: true,
12
+ value
13
+ }) : obj[key] = value;
9
14
  var __spreadValues = (a, b) => {
10
15
  for (var prop in b || (b = {}))
11
16
  if (__hasOwnProp.call(b, prop))
@@ -19,9 +24,9 @@ var __spreadValues = (a, b) => {
19
24
  };
20
25
  const flatten_js_1 = require("../../helpers/flatten.js");
21
26
  const index_js_1 = require("../get-builder-search-params/index.js");
22
- const api_version_1 = require("../../types/api-version");
23
- const generateContentUrl = (options) => {
24
- const { limit = 30, userAttributes, query, noTraverse = false, model, apiKey, includeRefs = true, enrich, locale, apiVersion = api_version_1.DEFAULT_API_VERSION } = options;
27
+ const api_version_js_1 = require("../../types/api-version.js");
28
+ const generateContentUrl = options => {
29
+ const { limit = 30, userAttributes, query, noTraverse = false, model, apiKey, includeRefs = true, enrich, locale, apiVersion = api_version_js_1.DEFAULT_API_VERSION } = options;
25
30
  if (!apiKey) {
26
31
  throw new Error("Missing API key");
27
32
  }
@@ -38,7 +43,9 @@ const generateContentUrl = (options) => {
38
43
  url.searchParams.set("userAttributes", JSON.stringify(userAttributes));
39
44
  }
40
45
  if (query) {
41
- const flattened2 = (0, flatten_js_1.flatten)({ query });
46
+ const flattened2 = (0, flatten_js_1.flatten)({
47
+ query
48
+ });
42
49
  for (const key in flattened2) {
43
50
  url.searchParams.set(key, JSON.stringify(flattened2[key]));
44
51
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const generate_content_url_1 = require("./generate-content-url");
3
+ const generate_content_url_js_1 = require("./generate-content-url.js");
4
4
  const testKey = "YJIGb4i01jvw0SRdL5Bt";
5
5
  const testModel = "page";
6
6
  const testId = "c1b81bab59704599b997574eb0736def";
@@ -14,46 +14,56 @@ const options = {
14
14
  };
15
15
  describe("Generate Content URL", () => {
16
16
  test("generates the proper value for a simple query", () => {
17
- const output = (0, generate_content_url_1.generateContentUrl)({
17
+ const output = (0, generate_content_url_js_1.generateContentUrl)({
18
18
  apiKey: testKey,
19
19
  model: testModel,
20
- query: { id: testId }
20
+ query: {
21
+ id: testId
22
+ }
21
23
  });
22
24
  expect(output).toMatchSnapshot();
23
25
  });
24
26
  test("Handles overrides correctly", () => {
25
- const output = (0, generate_content_url_1.generateContentUrl)({
27
+ const output = (0, generate_content_url_js_1.generateContentUrl)({
26
28
  apiKey: testKey,
27
29
  model: testModel,
28
- query: { id: testId },
30
+ query: {
31
+ id: testId
32
+ },
29
33
  options
30
34
  });
31
35
  expect(output).toMatchSnapshot();
32
36
  });
33
37
  test("generate content url with apiVersion as default", () => {
34
- const output = (0, generate_content_url_1.generateContentUrl)({
38
+ const output = (0, generate_content_url_js_1.generateContentUrl)({
35
39
  apiKey: testKey,
36
40
  model: testModel,
37
- query: { id: testId },
41
+ query: {
42
+ id: testId
43
+ },
38
44
  options
39
45
  });
40
46
  expect(output).toMatchSnapshot();
41
47
  });
42
48
  test("generate content url with apiVersion as v2", () => {
43
- const output = (0, generate_content_url_1.generateContentUrl)({
49
+ const output = (0, generate_content_url_js_1.generateContentUrl)({
44
50
  apiKey: testKey,
45
51
  model: testModel,
46
- query: { id: testId },
52
+ query: {
53
+ id: testId
54
+ },
47
55
  options,
48
56
  apiVersion: "v2"
49
57
  });
50
58
  expect(output).toMatchSnapshot();
51
59
  });
52
60
  test("generate content url with apiVersion as v3", () => {
53
- const output = (0, generate_content_url_1.generateContentUrl)({
61
+ const output = (0, generate_content_url_js_1.generateContentUrl)({
54
62
  apiKey: testKey,
55
63
  model: testModel,
56
- query: { id: testId },
64
+ query: {
65
+ id: testId
66
+ },
57
67
  options,
58
68
  apiVersion: "v3"
59
69
  });
@@ -61,10 +71,12 @@ describe("Generate Content URL", () => {
61
71
  });
62
72
  test("throw error when trying to generate content url with apiVersion as v1", () => {
63
73
  expect(() => {
64
- (0, generate_content_url_1.generateContentUrl)({
74
+ (0, generate_content_url_js_1.generateContentUrl)({
65
75
  apiKey: testKey,
66
76
  model: testModel,
67
- query: { id: testId },
77
+ query: {
78
+ id: testId
79
+ },
68
80
  options,
69
81
  apiVersion: "v1"
70
82
  });
@@ -72,17 +84,19 @@ describe("Generate Content URL", () => {
72
84
  });
73
85
  test("throw error when trying to generate content url with an invalid apiVersion value", () => {
74
86
  expect(() => {
75
- (0, generate_content_url_1.generateContentUrl)({
87
+ (0, generate_content_url_js_1.generateContentUrl)({
76
88
  apiKey: testKey,
77
89
  model: testModel,
78
- query: { id: testId },
90
+ query: {
91
+ id: testId
92
+ },
79
93
  options,
80
94
  apiVersion: "INVALID_API_VERSION"
81
95
  });
82
96
  }).toThrow(`Invalid apiVersion: expected 'v2' or 'v3', received 'INVALID_API_VERSION'`);
83
97
  });
84
98
  test("generate content url with enrich option true", () => {
85
- const output = (0, generate_content_url_1.generateContentUrl)({
99
+ const output = (0, generate_content_url_js_1.generateContentUrl)({
86
100
  apiKey: testKey,
87
101
  model: testModel,
88
102
  enrich: true
@@ -90,7 +104,7 @@ describe("Generate Content URL", () => {
90
104
  expect(output).toMatchSnapshot();
91
105
  });
92
106
  test("generate content url with enrich option not present", () => {
93
- const output = (0, generate_content_url_1.generateContentUrl)({
107
+ const output = (0, generate_content_url_js_1.generateContentUrl)({
94
108
  apiKey: testKey,
95
109
  model: testModel
96
110
  });
@@ -7,7 +7,12 @@ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
7
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
9
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
11
+ enumerable: true,
12
+ configurable: true,
13
+ writable: true,
14
+ value
15
+ }) : obj[key] = value;
11
16
  var __spreadValues = (a, b) => {
12
17
  for (var prop in b || (b = {}))
13
18
  if (__hasOwnProp.call(b, prop))
@@ -22,7 +27,7 @@ var __spreadValues = (a, b) => {
22
27
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
28
  var __async = (__this, __arguments, generator) => {
24
29
  return new Promise((resolve, reject) => {
25
- var fulfilled = (value) => {
30
+ var fulfilled = value => {
26
31
  try {
27
32
  step(generator.next(value));
28
33
  }
@@ -30,7 +35,7 @@ var __async = (__this, __arguments, generator) => {
30
35
  reject(e);
31
36
  }
32
37
  };
33
- var rejected = (value) => {
38
+ var rejected = value => {
34
39
  try {
35
40
  step(generator.throw(value));
36
41
  }
@@ -38,7 +43,7 @@ var __async = (__this, __arguments, generator) => {
38
43
  reject(e);
39
44
  }
40
45
  };
41
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
46
+ var step = x => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
42
47
  step((generator = generator.apply(__this, __arguments)).next());
43
48
  });
44
49
  };
@@ -46,28 +51,40 @@ const target_js_1 = require("../../constants/target.js");
46
51
  const ab_tests_js_1 = require("../../helpers/ab-tests.js");
47
52
  const canTrack_js_1 = require("../../helpers/canTrack.js");
48
53
  const logger_js_1 = require("../../helpers/logger.js");
54
+ const get_js_1 = require("../../helpers/preview-lru-cache/get.js");
49
55
  const get_fetch_js_1 = require("../get-fetch.js");
50
56
  const is_browser_js_1 = require("../is-browser.js");
51
57
  const generate_content_url_js_1 = require("./generate-content-url.js");
52
- const checkContentHasResults = (content) => "results" in content;
58
+ const checkContentHasResults = content => "results" in content;
53
59
  function getContent(options) {
54
60
  return __async(this, null, function* () {
55
- const allContent = yield getAllContent(__spreadProps(__spreadValues({}, options), { limit: 1 }));
56
- if (allContent && checkContentHasResults(allContent)) {
61
+ const allContent = yield getAllContent(__spreadProps(__spreadValues({}, options), {
62
+ limit: 1
63
+ }));
64
+ if (allContent) {
57
65
  return allContent.results[0] || null;
58
66
  }
59
67
  return null;
60
68
  });
61
69
  }
62
70
  exports.getContent = getContent;
63
- const fetchContent = (options) => __async(void 0, null, function* () {
71
+ const fetchContent = options => __async(void 0, null, function* () {
64
72
  const url = (0, generate_content_url_js_1.generateContentUrl)(options);
65
73
  const res = yield (0, get_fetch_js_1.fetch)(url.href);
66
74
  const content = yield res.json();
67
75
  return content;
68
76
  });
69
- const processContentResult = (options, content) => __async(void 0, null, function* () {
77
+ const processContentResult = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (options, content, url = (0, generate_content_url_js_1.generateContentUrl)(options)) {
70
78
  const canTrack = (0, canTrack_js_1.getDefaultCanTrack)(options.canTrack);
79
+ const isPreviewing = url.search.includes(`preview=`);
80
+ if (target_js_1.TARGET === "rsc" && isPreviewing) {
81
+ const newResults = [];
82
+ for (const item of content.results) {
83
+ const previewContent = (0, get_js_1.getPreviewContent)(url.searchParams);
84
+ newResults.push(previewContent || item);
85
+ }
86
+ content.results = newResults;
87
+ }
71
88
  if (!canTrack)
72
89
  return content;
73
90
  if (!((0, is_browser_js_1.isBrowser)() || target_js_1.TARGET === "reactNative"))
@@ -75,7 +92,10 @@ const processContentResult = (options, content) => __async(void 0, null, functio
75
92
  try {
76
93
  const newResults = [];
77
94
  for (const item of content.results) {
78
- newResults.push(yield (0, ab_tests_js_1.handleABTesting)({ item, canTrack }));
95
+ newResults.push(yield (0, ab_tests_js_1.handleABTesting)({
96
+ item,
97
+ canTrack
98
+ }));
79
99
  }
80
100
  content.results = newResults;
81
101
  }
@@ -91,8 +111,12 @@ function getAllContent(options) {
91
111
  const url = (0, generate_content_url_js_1.generateContentUrl)(options);
92
112
  const content = yield fetchContent(options);
93
113
  if (!checkContentHasResults(content)) {
94
- logger_js_1.logger.error("Error fetching data. ", { url, content, options });
95
- return content;
114
+ logger_js_1.logger.error("Error fetching data. ", {
115
+ url,
116
+ content,
117
+ options
118
+ });
119
+ return null;
96
120
  }
97
121
  return processContentResult(options, content);
98
122
  }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.processCookies = void 0;
4
+ const processCookies = content => {
5
+ return content;
6
+ };
7
+ exports.processCookies = processCookies;
@@ -7,7 +7,12 @@ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
7
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
9
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
11
+ enumerable: true,
12
+ configurable: true,
13
+ writable: true,
14
+ value
15
+ }) : obj[key] = value;
11
16
  var __spreadValues = (a, b) => {
12
17
  for (var prop in b || (b = {}))
13
18
  if (__hasOwnProp.call(b, prop))
@@ -20,7 +25,7 @@ var __spreadValues = (a, b) => {
20
25
  return a;
21
26
  };
22
27
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
- const evaluate_js_1 = require("./evaluate.js");
28
+ const evaluate_1 = require("./evaluate");
24
29
  const fast_clone_js_1 = require("./fast-clone.js");
25
30
  const set_js_1 = require("./set.js");
26
31
  const transform_block_js_1 = require("./transform-block.js");
@@ -35,7 +40,7 @@ const evaluateBindings = ({ block, context, localState, rootState, rootSetState
35
40
  });
36
41
  for (const binding in block.bindings) {
37
42
  const expression = block.bindings[binding];
38
- const value = (0, evaluate_js_1.evaluate)({
43
+ const value = (0, evaluate_1.evaluate)({
39
44
  code: expression,
40
45
  localState,
41
46
  rootState,