@builder.io/sdk-react-native 2.0.15 → 2.0.21

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 (216) hide show
  1. package/lib/browser/commonjs/components/awaiter.js +21 -0
  2. package/lib/browser/commonjs/components/awaiter.js.map +1 -0
  3. package/lib/browser/commonjs/components/block/components/interactive-element.js +9 -2
  4. package/lib/browser/commonjs/components/block/components/interactive-element.js.map +1 -1
  5. package/lib/browser/commonjs/components/content/components/enable-editor.js +17 -45
  6. package/lib/browser/commonjs/components/content/components/enable-editor.js.map +1 -1
  7. package/lib/browser/commonjs/components/content/content.js +37 -5
  8. package/lib/browser/commonjs/components/content/content.js.map +1 -1
  9. package/lib/browser/commonjs/constants/sdk-version.js +1 -1
  10. package/lib/browser/commonjs/context/component-reference-types.js +2 -0
  11. package/lib/browser/commonjs/context/component-reference-types.js.map +1 -0
  12. package/lib/browser/commonjs/functions/evaluate/browser-runtime/browser.js +1 -35
  13. package/lib/browser/commonjs/functions/evaluate/browser-runtime/browser.js.map +1 -1
  14. package/lib/browser/commonjs/functions/evaluate/choose-eval.js +3 -1
  15. package/lib/browser/commonjs/functions/evaluate/choose-eval.js.map +1 -1
  16. package/lib/browser/commonjs/functions/evaluate/edge-runtime/edge-runtime.js +71 -34
  17. package/lib/browser/commonjs/functions/evaluate/edge-runtime/edge-runtime.js.map +1 -1
  18. package/lib/browser/commonjs/functions/evaluate/helpers.js +34 -0
  19. package/lib/browser/commonjs/functions/evaluate/helpers.js.map +1 -1
  20. package/lib/browser/commonjs/functions/evaluate/node-runtime/init.js +9 -0
  21. package/lib/browser/commonjs/functions/evaluate/node-runtime/init.js.map +1 -1
  22. package/lib/browser/commonjs/functions/evaluate/node-runtime/node-runtime.js +1 -1
  23. package/lib/browser/commonjs/functions/evaluate/node-runtime/node-runtime.js.map +1 -1
  24. package/lib/browser/commonjs/functions/evaluate/should-force-browser-runtime-in-node.js +6 -2
  25. package/lib/browser/commonjs/functions/evaluate/should-force-browser-runtime-in-node.js.map +1 -1
  26. package/lib/browser/module/components/awaiter.js +14 -0
  27. package/lib/browser/module/components/awaiter.js.map +1 -0
  28. package/lib/browser/module/components/block/components/interactive-element.js +8 -2
  29. package/lib/browser/module/components/block/components/interactive-element.js.map +1 -1
  30. package/lib/browser/module/components/content/components/enable-editor.js +16 -44
  31. package/lib/browser/module/components/content/components/enable-editor.js.map +1 -1
  32. package/lib/browser/module/components/content/content.js +38 -6
  33. package/lib/browser/module/components/content/content.js.map +1 -1
  34. package/lib/browser/module/constants/sdk-version.js +1 -1
  35. package/lib/browser/module/context/component-reference-types.js +2 -0
  36. package/lib/browser/module/context/component-reference-types.js.map +1 -0
  37. package/lib/browser/module/functions/evaluate/browser-runtime/browser.js +1 -34
  38. package/lib/browser/module/functions/evaluate/browser-runtime/browser.js.map +1 -1
  39. package/lib/browser/module/functions/evaluate/choose-eval.js +3 -1
  40. package/lib/browser/module/functions/evaluate/choose-eval.js.map +1 -1
  41. package/lib/browser/module/functions/evaluate/edge-runtime/edge-runtime.js +73 -35
  42. package/lib/browser/module/functions/evaluate/edge-runtime/edge-runtime.js.map +1 -1
  43. package/lib/browser/module/functions/evaluate/helpers.js +33 -0
  44. package/lib/browser/module/functions/evaluate/helpers.js.map +1 -1
  45. package/lib/browser/module/functions/evaluate/node-runtime/init.js +9 -0
  46. package/lib/browser/module/functions/evaluate/node-runtime/init.js.map +1 -1
  47. package/lib/browser/module/functions/evaluate/node-runtime/node-runtime.js +1 -1
  48. package/lib/browser/module/functions/evaluate/node-runtime/node-runtime.js.map +1 -1
  49. package/lib/browser/module/functions/evaluate/should-force-browser-runtime-in-node.js +6 -2
  50. package/lib/browser/module/functions/evaluate/should-force-browser-runtime-in-node.js.map +1 -1
  51. package/lib/browser/typescript/components/awaiter.d.ts +15 -0
  52. package/lib/browser/typescript/components/awaiter.d.ts.map +1 -0
  53. package/lib/browser/typescript/components/block/components/interactive-element.d.ts.map +1 -1
  54. package/lib/browser/typescript/components/content/components/enable-editor.d.ts.map +1 -1
  55. package/lib/browser/typescript/components/content/content.d.ts.map +1 -1
  56. package/lib/browser/typescript/constants/sdk-version.d.ts +1 -1
  57. package/lib/browser/typescript/context/component-reference-types.d.ts +5 -0
  58. package/lib/browser/typescript/context/component-reference-types.d.ts.map +1 -0
  59. package/lib/browser/typescript/context/types.d.ts +2 -1
  60. package/lib/browser/typescript/context/types.d.ts.map +1 -1
  61. package/lib/browser/typescript/functions/evaluate/browser-runtime/browser.d.ts +0 -6
  62. package/lib/browser/typescript/functions/evaluate/browser-runtime/browser.d.ts.map +1 -1
  63. package/lib/browser/typescript/functions/evaluate/choose-eval.d.ts.map +1 -1
  64. package/lib/browser/typescript/functions/evaluate/helpers.d.ts +5 -0
  65. package/lib/browser/typescript/functions/evaluate/helpers.d.ts.map +1 -1
  66. package/lib/browser/typescript/functions/evaluate/should-force-browser-runtime-in-node.d.ts +3 -1
  67. package/lib/browser/typescript/functions/evaluate/should-force-browser-runtime-in-node.d.ts.map +1 -1
  68. package/lib/edge/commonjs/components/awaiter.js +21 -0
  69. package/lib/edge/commonjs/components/awaiter.js.map +1 -0
  70. package/lib/edge/commonjs/components/block/components/interactive-element.js +9 -2
  71. package/lib/edge/commonjs/components/block/components/interactive-element.js.map +1 -1
  72. package/lib/edge/commonjs/components/content/components/enable-editor.js +17 -45
  73. package/lib/edge/commonjs/components/content/components/enable-editor.js.map +1 -1
  74. package/lib/edge/commonjs/components/content/content.js +37 -5
  75. package/lib/edge/commonjs/components/content/content.js.map +1 -1
  76. package/lib/edge/commonjs/constants/sdk-version.js +1 -1
  77. package/lib/edge/commonjs/context/component-reference-types.js +2 -0
  78. package/lib/edge/commonjs/context/component-reference-types.js.map +1 -0
  79. package/lib/edge/commonjs/functions/evaluate/browser-runtime/browser.js +1 -35
  80. package/lib/edge/commonjs/functions/evaluate/browser-runtime/browser.js.map +1 -1
  81. package/lib/edge/commonjs/functions/evaluate/choose-eval.js +3 -1
  82. package/lib/edge/commonjs/functions/evaluate/choose-eval.js.map +1 -1
  83. package/lib/edge/commonjs/functions/evaluate/edge-runtime/edge-runtime.js +71 -34
  84. package/lib/edge/commonjs/functions/evaluate/edge-runtime/edge-runtime.js.map +1 -1
  85. package/lib/edge/commonjs/functions/evaluate/helpers.js +34 -0
  86. package/lib/edge/commonjs/functions/evaluate/helpers.js.map +1 -1
  87. package/lib/edge/commonjs/functions/evaluate/node-runtime/init.js +9 -0
  88. package/lib/edge/commonjs/functions/evaluate/node-runtime/init.js.map +1 -1
  89. package/lib/edge/commonjs/functions/evaluate/node-runtime/node-runtime.js +1 -1
  90. package/lib/edge/commonjs/functions/evaluate/node-runtime/node-runtime.js.map +1 -1
  91. package/lib/edge/commonjs/functions/evaluate/should-force-browser-runtime-in-node.js +6 -2
  92. package/lib/edge/commonjs/functions/evaluate/should-force-browser-runtime-in-node.js.map +1 -1
  93. package/lib/edge/module/components/awaiter.js +14 -0
  94. package/lib/edge/module/components/awaiter.js.map +1 -0
  95. package/lib/edge/module/components/block/components/interactive-element.js +8 -2
  96. package/lib/edge/module/components/block/components/interactive-element.js.map +1 -1
  97. package/lib/edge/module/components/content/components/enable-editor.js +16 -44
  98. package/lib/edge/module/components/content/components/enable-editor.js.map +1 -1
  99. package/lib/edge/module/components/content/content.js +38 -6
  100. package/lib/edge/module/components/content/content.js.map +1 -1
  101. package/lib/edge/module/constants/sdk-version.js +1 -1
  102. package/lib/edge/module/context/component-reference-types.js +2 -0
  103. package/lib/edge/module/context/component-reference-types.js.map +1 -0
  104. package/lib/edge/module/functions/evaluate/browser-runtime/browser.js +1 -34
  105. package/lib/edge/module/functions/evaluate/browser-runtime/browser.js.map +1 -1
  106. package/lib/edge/module/functions/evaluate/choose-eval.js +3 -1
  107. package/lib/edge/module/functions/evaluate/choose-eval.js.map +1 -1
  108. package/lib/edge/module/functions/evaluate/edge-runtime/edge-runtime.js +73 -35
  109. package/lib/edge/module/functions/evaluate/edge-runtime/edge-runtime.js.map +1 -1
  110. package/lib/edge/module/functions/evaluate/helpers.js +33 -0
  111. package/lib/edge/module/functions/evaluate/helpers.js.map +1 -1
  112. package/lib/edge/module/functions/evaluate/node-runtime/init.js +9 -0
  113. package/lib/edge/module/functions/evaluate/node-runtime/init.js.map +1 -1
  114. package/lib/edge/module/functions/evaluate/node-runtime/node-runtime.js +1 -1
  115. package/lib/edge/module/functions/evaluate/node-runtime/node-runtime.js.map +1 -1
  116. package/lib/edge/module/functions/evaluate/should-force-browser-runtime-in-node.js +6 -2
  117. package/lib/edge/module/functions/evaluate/should-force-browser-runtime-in-node.js.map +1 -1
  118. package/lib/edge/typescript/components/awaiter.d.ts +15 -0
  119. package/lib/edge/typescript/components/awaiter.d.ts.map +1 -0
  120. package/lib/edge/typescript/components/block/components/interactive-element.d.ts.map +1 -1
  121. package/lib/edge/typescript/components/content/components/enable-editor.d.ts.map +1 -1
  122. package/lib/edge/typescript/components/content/content.d.ts.map +1 -1
  123. package/lib/edge/typescript/constants/sdk-version.d.ts +1 -1
  124. package/lib/edge/typescript/context/component-reference-types.d.ts +5 -0
  125. package/lib/edge/typescript/context/component-reference-types.d.ts.map +1 -0
  126. package/lib/edge/typescript/context/types.d.ts +2 -1
  127. package/lib/edge/typescript/context/types.d.ts.map +1 -1
  128. package/lib/edge/typescript/functions/evaluate/browser-runtime/browser.d.ts +0 -6
  129. package/lib/edge/typescript/functions/evaluate/browser-runtime/browser.d.ts.map +1 -1
  130. package/lib/edge/typescript/functions/evaluate/choose-eval.d.ts.map +1 -1
  131. package/lib/edge/typescript/functions/evaluate/helpers.d.ts +5 -0
  132. package/lib/edge/typescript/functions/evaluate/helpers.d.ts.map +1 -1
  133. package/lib/edge/typescript/functions/evaluate/should-force-browser-runtime-in-node.d.ts +3 -1
  134. package/lib/edge/typescript/functions/evaluate/should-force-browser-runtime-in-node.d.ts.map +1 -1
  135. package/lib/node/commonjs/components/awaiter.js +21 -0
  136. package/lib/node/commonjs/components/awaiter.js.map +1 -0
  137. package/lib/node/commonjs/components/block/components/interactive-element.js +9 -2
  138. package/lib/node/commonjs/components/block/components/interactive-element.js.map +1 -1
  139. package/lib/node/commonjs/components/content/components/enable-editor.js +17 -45
  140. package/lib/node/commonjs/components/content/components/enable-editor.js.map +1 -1
  141. package/lib/node/commonjs/components/content/content.js +37 -5
  142. package/lib/node/commonjs/components/content/content.js.map +1 -1
  143. package/lib/node/commonjs/constants/sdk-version.js +1 -1
  144. package/lib/node/commonjs/context/component-reference-types.js +2 -0
  145. package/lib/node/commonjs/context/component-reference-types.js.map +1 -0
  146. package/lib/node/commonjs/functions/evaluate/browser-runtime/browser.js +1 -35
  147. package/lib/node/commonjs/functions/evaluate/browser-runtime/browser.js.map +1 -1
  148. package/lib/node/commonjs/functions/evaluate/choose-eval.js +3 -1
  149. package/lib/node/commonjs/functions/evaluate/choose-eval.js.map +1 -1
  150. package/lib/node/commonjs/functions/evaluate/edge-runtime/edge-runtime.js +71 -34
  151. package/lib/node/commonjs/functions/evaluate/edge-runtime/edge-runtime.js.map +1 -1
  152. package/lib/node/commonjs/functions/evaluate/helpers.js +34 -0
  153. package/lib/node/commonjs/functions/evaluate/helpers.js.map +1 -1
  154. package/lib/node/commonjs/functions/evaluate/node-runtime/init.js +9 -0
  155. package/lib/node/commonjs/functions/evaluate/node-runtime/init.js.map +1 -1
  156. package/lib/node/commonjs/functions/evaluate/node-runtime/node-runtime.js +1 -1
  157. package/lib/node/commonjs/functions/evaluate/node-runtime/node-runtime.js.map +1 -1
  158. package/lib/node/commonjs/functions/evaluate/should-force-browser-runtime-in-node.js +6 -2
  159. package/lib/node/commonjs/functions/evaluate/should-force-browser-runtime-in-node.js.map +1 -1
  160. package/lib/node/module/components/awaiter.js +14 -0
  161. package/lib/node/module/components/awaiter.js.map +1 -0
  162. package/lib/node/module/components/block/components/interactive-element.js +8 -2
  163. package/lib/node/module/components/block/components/interactive-element.js.map +1 -1
  164. package/lib/node/module/components/content/components/enable-editor.js +16 -44
  165. package/lib/node/module/components/content/components/enable-editor.js.map +1 -1
  166. package/lib/node/module/components/content/content.js +38 -6
  167. package/lib/node/module/components/content/content.js.map +1 -1
  168. package/lib/node/module/constants/sdk-version.js +1 -1
  169. package/lib/node/module/context/component-reference-types.js +2 -0
  170. package/lib/node/module/context/component-reference-types.js.map +1 -0
  171. package/lib/node/module/functions/evaluate/browser-runtime/browser.js +1 -34
  172. package/lib/node/module/functions/evaluate/browser-runtime/browser.js.map +1 -1
  173. package/lib/node/module/functions/evaluate/choose-eval.js +3 -1
  174. package/lib/node/module/functions/evaluate/choose-eval.js.map +1 -1
  175. package/lib/node/module/functions/evaluate/edge-runtime/edge-runtime.js +73 -35
  176. package/lib/node/module/functions/evaluate/edge-runtime/edge-runtime.js.map +1 -1
  177. package/lib/node/module/functions/evaluate/helpers.js +33 -0
  178. package/lib/node/module/functions/evaluate/helpers.js.map +1 -1
  179. package/lib/node/module/functions/evaluate/node-runtime/init.js +9 -0
  180. package/lib/node/module/functions/evaluate/node-runtime/init.js.map +1 -1
  181. package/lib/node/module/functions/evaluate/node-runtime/node-runtime.js +1 -1
  182. package/lib/node/module/functions/evaluate/node-runtime/node-runtime.js.map +1 -1
  183. package/lib/node/module/functions/evaluate/should-force-browser-runtime-in-node.js +6 -2
  184. package/lib/node/module/functions/evaluate/should-force-browser-runtime-in-node.js.map +1 -1
  185. package/lib/node/typescript/components/awaiter.d.ts +15 -0
  186. package/lib/node/typescript/components/awaiter.d.ts.map +1 -0
  187. package/lib/node/typescript/components/block/components/interactive-element.d.ts.map +1 -1
  188. package/lib/node/typescript/components/content/components/enable-editor.d.ts.map +1 -1
  189. package/lib/node/typescript/components/content/content.d.ts.map +1 -1
  190. package/lib/node/typescript/constants/sdk-version.d.ts +1 -1
  191. package/lib/node/typescript/context/component-reference-types.d.ts +5 -0
  192. package/lib/node/typescript/context/component-reference-types.d.ts.map +1 -0
  193. package/lib/node/typescript/context/types.d.ts +2 -1
  194. package/lib/node/typescript/context/types.d.ts.map +1 -1
  195. package/lib/node/typescript/functions/evaluate/browser-runtime/browser.d.ts +0 -6
  196. package/lib/node/typescript/functions/evaluate/browser-runtime/browser.d.ts.map +1 -1
  197. package/lib/node/typescript/functions/evaluate/choose-eval.d.ts.map +1 -1
  198. package/lib/node/typescript/functions/evaluate/helpers.d.ts +5 -0
  199. package/lib/node/typescript/functions/evaluate/helpers.d.ts.map +1 -1
  200. package/lib/node/typescript/functions/evaluate/should-force-browser-runtime-in-node.d.ts +3 -1
  201. package/lib/node/typescript/functions/evaluate/should-force-browser-runtime-in-node.d.ts.map +1 -1
  202. package/package.json +1 -1
  203. package/src/components/awaiter.tsx +36 -0
  204. package/src/components/block/components/interactive-element.tsx +19 -3
  205. package/src/components/content/components/enable-editor.tsx +7 -36
  206. package/src/components/content/content.tsx +71 -36
  207. package/src/constants/sdk-version.ts +1 -1
  208. package/src/context/component-reference-types.ts +4 -0
  209. package/src/context/types.ts +2 -1
  210. package/src/functions/evaluate/browser-runtime/browser.ts +1 -39
  211. package/src/functions/evaluate/choose-eval.ts +3 -1
  212. package/src/functions/evaluate/edge-runtime/edge-runtime.ts +73 -35
  213. package/src/functions/evaluate/helpers.ts +37 -0
  214. package/src/functions/evaluate/node-runtime/init.ts +9 -0
  215. package/src/functions/evaluate/node-runtime/node-runtime.ts +1 -1
  216. package/src/functions/evaluate/should-force-browser-runtime-in-node.ts +8 -2
@@ -1 +1 @@
1
- {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../../../../../src/functions/evaluate/browser-runtime/browser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,eAAO,MAAM,YAAY,2EAQtB,YAAY,QAYd,CAAC;AACF,wBAAgB,YAAY,CAAC,EAC3B,SAAS,EACT,UAAU,EACV,YAAY,EACb,EAAE;IACD,SAAS,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC;IACxC,UAAU,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAAC;IACrD,YAAY,EAAE,CAAC,CAAC,SAAS,EAAE,kBAAkB,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;CACrE,GAAG,kBAAkB,CA4BrB"}
1
+ {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../../../../../src/functions/evaluate/browser-runtime/browser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,eAAO,MAAM,YAAY,2EAQtB,YAAY,QAYd,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"choose-eval.d.ts","sourceRoot":"","sources":["../../../../../src/functions/evaluate/choose-eval.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAgB9C;;;GAGG;AACH,eAAO,MAAM,yBAAyB,SAAU,YAAY,QAA4F,CAAA"}
1
+ {"version":3,"file":"choose-eval.d.ts","sourceRoot":"","sources":["../../../../../src/functions/evaluate/choose-eval.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAgB9C;;;GAGG;AACH,eAAO,MAAM,yBAAyB,SAAU,YAAY,QAEnB,CAAA"}
@@ -23,4 +23,9 @@ export declare const getFunctionArguments: ({ builder, context, event, state }:
23
23
  }) => [string, Event | BuilderRenderState | import("../../context/types").BuilderRenderContext | BuilderGlobals][];
24
24
  export declare const getBuilderGlobals: () => BuilderGlobals;
25
25
  export declare const parseCode: (code: string, { isExpression }: Pick<EvaluatorArgs, 'isExpression'>) => string;
26
+ export declare function flattenState({ rootState, localState, rootSetState }: {
27
+ rootState: Record<string | symbol, any>;
28
+ localState: Record<string | symbol, any> | undefined;
29
+ rootSetState: ((rootState: BuilderRenderState) => void) | undefined;
30
+ }): BuilderRenderState;
26
31
  //# sourceMappingURL=helpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../../../src/functions/evaluate/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAGvF,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,YAAY,EAAE,SAAS,GAAG,OAAO,CAAC,GAAG;IACpE,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC;AACF,MAAM,MAAM,cAAc,GAAG;IAC3B,SAAS,EAAE,OAAO,GAAG,SAAS,CAAC;IAC/B,SAAS,EAAE,OAAO,GAAG,SAAS,CAAC;IAC/B,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAC;IAC9B,iBAAiB,EAAE,OAAO,iBAAiB,CAAC;CAC7C,CAAC;AACF,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,uBAAuB,EAAE,YAAY,GAAG,SAAS,GAAG,WAAW,GAAG,cAAc,CAAC,GAAG;IAClH,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,cAAc,CAAC;IACxB,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;CAC1B,CAAC;AACF,MAAM,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,YAAY,KAAK,GAAG,CAAC;AACnD,MAAM,MAAM,iBAAiB,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC;AACxE,eAAO,MAAM,oBAAoB;WAMxB,kBAAkB;kHAU1B,CAAC;AACF,eAAO,MAAM,iBAAiB,QAAO,cAKnC,CAAC;AACH,eAAO,MAAM,SAAS,SAAU,MAAM,oBAEnC,KAAK,aAAa,EAAE,cAAc,CAAC,WAQrC,CAAA"}
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../../../src/functions/evaluate/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAGvF,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,YAAY,EAAE,SAAS,GAAG,OAAO,CAAC,GAAG;IACpE,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC;AACF,MAAM,MAAM,cAAc,GAAG;IAC3B,SAAS,EAAE,OAAO,GAAG,SAAS,CAAC;IAC/B,SAAS,EAAE,OAAO,GAAG,SAAS,CAAC;IAC/B,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAC;IAC9B,iBAAiB,EAAE,OAAO,iBAAiB,CAAC;CAC7C,CAAC;AACF,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,uBAAuB,EAAE,YAAY,GAAG,SAAS,GAAG,WAAW,GAAG,cAAc,CAAC,GAAG;IAClH,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,cAAc,CAAC;IACxB,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;CAC1B,CAAC;AACF,MAAM,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,YAAY,KAAK,GAAG,CAAC;AACnD,MAAM,MAAM,iBAAiB,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC;AACxE,eAAO,MAAM,oBAAoB;WAMxB,kBAAkB;kHAU1B,CAAC;AACF,eAAO,MAAM,iBAAiB,QAAO,cAKnC,CAAC;AACH,eAAO,MAAM,SAAS,SAAU,MAAM,oBAEnC,KAAK,aAAa,EAAE,cAAc,CAAC,WAQrC,CAAC;AACF,wBAAgB,YAAY,CAAC,EAC3B,SAAS,EACT,UAAU,EACV,YAAY,EACb,EAAE;IACD,SAAS,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC;IACxC,UAAU,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAAC;IACrD,YAAY,EAAE,CAAC,CAAC,SAAS,EAAE,kBAAkB,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;CACrE,GAAG,kBAAkB,CA4BrB"}
@@ -1,2 +1,4 @@
1
- export declare const shouldForceBrowserRuntimeInNode: () => boolean;
1
+ export declare const shouldForceBrowserRuntimeInNode: ({ shouldLogWarning }: {
2
+ shouldLogWarning: boolean;
3
+ }) => boolean;
2
4
  //# sourceMappingURL=should-force-browser-runtime-in-node.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"should-force-browser-runtime-in-node.d.ts","sourceRoot":"","sources":["../../../../../src/functions/evaluate/should-force-browser-runtime-in-node.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,+BAA+B,eAa3C,CAAA"}
1
+ {"version":3,"file":"should-force-browser-runtime-in-node.d.ts","sourceRoot":"","sources":["../../../../../src/functions/evaluate/should-force-browser-runtime-in-node.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,+BAA+B;sBAGxB,OAAO;aAgB1B,CAAA"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-react-native",
3
3
  "description": "Builder.io SDK for React Native",
4
- "version": "2.0.15",
4
+ "version": "2.0.21",
5
5
  "homepage": "https://github.com/BuilderIO/builder/tree/main/packages/sdks/output/react-native",
6
6
  "repository": {
7
7
  "type": "git",
@@ -0,0 +1,36 @@
1
+ import * as React from "react";
2
+ import {
3
+ FlatList,
4
+ ScrollView,
5
+ View,
6
+ StyleSheet,
7
+ Image,
8
+ Text,
9
+ Pressable,
10
+ TextInput,
11
+ TouchableOpacity,
12
+ Button,
13
+ Linking,
14
+ } from "react-native";
15
+ import { useEffect } from "react";
16
+
17
+ /**
18
+ * Placeholder component to be overridden by specific SDKs.
19
+ * Allows to dynamically import components.
20
+ */
21
+
22
+ type AwaiterProps = {
23
+ load: () => Promise<any>;
24
+ props?: any;
25
+ attributes?: any;
26
+ fallback?: any;
27
+ children?: any;
28
+ };
29
+
30
+ function Awaiter(props: AwaiterProps) {
31
+ useEffect(() => {}, []);
32
+
33
+ return <>{props.children}</>;
34
+ }
35
+
36
+ export default Awaiter;
@@ -26,6 +26,7 @@ import { getBlockActions } from "../../../functions/get-block-actions";
26
26
  import { getBlockProperties } from "../../../functions/get-block-properties";
27
27
  import type { BuilderBlock } from "../../../types/builder-block";
28
28
  import type { Dictionary } from "../../../types/typescript";
29
+ import Awaiter from "../../awaiter";
29
30
 
30
31
  function InteractiveElement(props: InteractiveElementProps) {
31
32
  function attributes() {
@@ -47,9 +48,24 @@ function InteractiveElement(props: InteractiveElementProps) {
47
48
  }
48
49
 
49
50
  return (
50
- <props.Wrapper {...props.wrapperProps} attributes={attributes()}>
51
- {props.children}
52
- </props.Wrapper>
51
+ <>
52
+ {props.Wrapper.load ? (
53
+ <>
54
+ <Awaiter
55
+ load={props.Wrapper.load}
56
+ fallback={props.Wrapper.fallback}
57
+ props={props.wrapperProps}
58
+ attributes={attributes()}
59
+ >
60
+ {props.children}
61
+ </Awaiter>
62
+ </>
63
+ ) : (
64
+ <props.Wrapper {...props.wrapperProps} attributes={attributes()}>
65
+ {props.children}
66
+ </props.Wrapper>
67
+ )}
68
+ </>
53
69
  );
54
70
  }
55
71
 
@@ -33,7 +33,6 @@ import type { BuilderContextInterface } from "../../../context/types";
33
33
  import { evaluate } from "../../../functions/evaluate/index";
34
34
  import { fastClone } from "../../../functions/fast-clone";
35
35
  import { fetchOneEntry } from "../../../functions/get-content/index";
36
- import { fetch } from "../../../functions/get-fetch";
37
36
  import { isBrowser } from "../../../functions/is-browser";
38
37
  import { isEditing } from "../../../functions/is-editing";
39
38
  import { isPreviewing } from "../../../functions/is-previewing";
@@ -41,7 +40,6 @@ import { createRegisterComponentMessage } from "../../../functions/register-comp
41
40
  import { _track } from "../../../functions/track/index";
42
41
  import { getInteractionPropertiesForEvent } from "../../../functions/track/interaction";
43
42
  import { getDefaultCanTrack } from "../../../helpers/canTrack";
44
- import { logger } from "../../../helpers/logger";
45
43
  import { postPreviewContent } from "../../../helpers/preview-lru-cache/set";
46
44
  import { createEditorListener } from "../../../helpers/subscribe-to-editor";
47
45
  import {
@@ -142,24 +140,6 @@ function EnableEditor(props: BuilderEditorProps) {
142
140
  })(event);
143
141
  }
144
142
 
145
- function evaluateJsCode() {
146
- // run any dynamic JS code attached to content
147
- const jsCode = props.builderContextSignal.content?.data?.jsCode;
148
- if (jsCode) {
149
- evaluate({
150
- code: jsCode,
151
- context: props.context || {},
152
- localState: undefined,
153
- rootState: props.builderContextSignal.rootState,
154
- rootSetState: props.builderContextSignal.rootSetState,
155
- /**
156
- * We don't want to cache the result of the JS code, since it's arbitrary side effect code.
157
- */
158
- enableCache: false,
159
- });
160
- }
161
- }
162
-
163
143
  const [httpReqsData, setHttpReqsData] = useState(() => ({}));
164
144
 
165
145
  const [httpReqsPending, setHttpReqsPending] = useState(() => ({}));
@@ -310,6 +290,13 @@ function EnableEditor(props: BuilderEditorProps) {
310
290
  }
311
291
  }
312
292
 
293
+ const hasInitialized = useRef(false);
294
+ if (!hasInitialized.current) {
295
+ runHttpRequests();
296
+ emitStateUpdate();
297
+ hasInitialized.current = true;
298
+ }
299
+
313
300
  useEffect(() => {
314
301
  if (isBrowser()) {
315
302
  if (isEditing()) {
@@ -397,28 +384,12 @@ function EnableEditor(props: BuilderEditorProps) {
397
384
  }
398
385
  }
399
386
  }, []);
400
- useEffect(() => {
401
- if (!props.apiKey) {
402
- logger.error(
403
- "No API key provided to `Content` component. This can cause issues. Please provide an API key using the `apiKey` prop."
404
- );
405
- }
406
- evaluateJsCode();
407
- runHttpRequests();
408
- emitStateUpdate();
409
- }, []);
410
387
 
411
388
  useEffect(() => {
412
389
  if (props.content) {
413
390
  mergeNewContent(props.content);
414
391
  }
415
392
  }, [props.content]);
416
- useEffect(() => {
417
- evaluateJsCode();
418
- }, [props.builderContextSignal.content?.data?.jsCode]);
419
- useEffect(() => {
420
- runHttpRequests();
421
- }, [props.builderContextSignal.content?.data?.httpRequests]);
422
393
  useEffect(() => {
423
394
  emitStateUpdate();
424
395
  }, [props.builderContextSignal.rootState]);
@@ -12,7 +12,7 @@ import {
12
12
  Button,
13
13
  Linking,
14
14
  } from "react-native";
15
- import { useState, useContext } from "react";
15
+ import { useState, useContext, useRef } from "react";
16
16
  import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components";
17
17
  import { TARGET } from "../../constants/target";
18
18
  import ComponentsContext from "../../context/components.context";
@@ -21,7 +21,9 @@ import type {
21
21
  BuilderRenderState,
22
22
  RegisteredComponents,
23
23
  } from "../../context/types";
24
+ import { evaluate } from "../../functions/evaluate/evaluate";
24
25
  import { serializeIncludingFunctions } from "../../functions/register-component";
26
+ import { logger } from "../../helpers/logger";
25
27
  import type { ComponentInfo } from "../../types/components";
26
28
  import type { Dictionary } from "../../types/typescript";
27
29
  import Blocks from "../blocks/blocks";
@@ -74,42 +76,75 @@ function ContentComponent(props: ContentProps) {
74
76
  )
75
77
  );
76
78
 
77
- const [builderContextSignal, setBuilderContextSignal] = useState(() => ({
78
- strictStyleMode: props.strictStyleMode,
79
- content: getContentInitialValue({
80
- content: props.content,
81
- data: props.data,
82
- }),
83
- localState: undefined,
84
- rootState: getRootStateInitialValue({
85
- content: props.content,
86
- data: props.data,
87
- locale: props.locale,
88
- }),
89
- rootSetState: contentSetState,
90
- context: props.context || {},
91
- canTrack: props.canTrack,
92
- apiKey: props.apiKey,
93
- apiVersion: props.apiVersion,
94
- componentInfos: [
95
- ...getDefaultRegisteredComponents(),
96
- ...(props.customComponents?.filter(({ models }) => {
97
- if (!models?.length) return true;
98
- if (!props.model) return true;
99
- return models.includes(props.model);
100
- }) || []),
101
- ].reduce<Dictionary<ComponentInfo>>(
102
- (acc, { component: _, ...info }) => ({
103
- ...acc,
104
- [info.name]: serializeIncludingFunctions(info),
79
+ const [builderContextSignal, setBuilderContextSignal] =
80
+ useState<BuilderContextInterface>(() => ({
81
+ strictStyleMode: props.strictStyleMode,
82
+ content: getContentInitialValue({
83
+ content: props.content,
84
+ data: props.data,
105
85
  }),
106
- {}
107
- ),
108
- inheritedStyles: {},
109
- BlocksWrapper: props.blocksWrapper || ScrollView,
110
- BlocksWrapperProps: props.blocksWrapperProps || {},
111
- nonce: props.nonce || "",
112
- }));
86
+ localState: undefined,
87
+ rootState: getRootStateInitialValue({
88
+ content: props.content,
89
+ data: props.data,
90
+ locale: props.locale,
91
+ }),
92
+ rootSetState: contentSetState,
93
+ context: props.context || {},
94
+ canTrack: props.canTrack,
95
+ apiKey: props.apiKey,
96
+ apiVersion: props.apiVersion,
97
+ componentInfos: [
98
+ ...getDefaultRegisteredComponents(),
99
+ ...(props.customComponents?.filter(({ models }) => {
100
+ if (!models?.length) return true;
101
+ if (!props.model) return true;
102
+ return models.includes(props.model);
103
+ }) || []),
104
+ ].reduce<Dictionary<ComponentInfo>>(
105
+ (acc, { component: _, ...info }) => ({
106
+ ...acc,
107
+ [info.name]: serializeIncludingFunctions(info),
108
+ }),
109
+ {}
110
+ ),
111
+ inheritedStyles: {},
112
+ BlocksWrapper: props.blocksWrapper || ScrollView,
113
+ BlocksWrapperProps: props.blocksWrapperProps || {},
114
+ nonce: props.nonce || "",
115
+ }));
116
+
117
+ const hasInitialized = useRef(false);
118
+ if (!hasInitialized.current) {
119
+ if (!props.apiKey) {
120
+ logger.error(
121
+ "No API key provided to `Content` component. This can cause issues. Please provide an API key using the `apiKey` prop."
122
+ );
123
+ }
124
+
125
+ // run any dynamic JS code attached to content
126
+ const jsCode = builderContextSignal.content?.data?.jsCode;
127
+ if (jsCode) {
128
+ evaluate({
129
+ code: jsCode,
130
+ context: props.context || {},
131
+ localState: undefined,
132
+ rootState: builderContextSignal.rootState,
133
+ rootSetState: (newState) => {
134
+ setBuilderContextSignal((PREVIOUS_VALUE) => ({
135
+ ...PREVIOUS_VALUE,
136
+ rootState: newState,
137
+ }));
138
+ },
139
+ isExpression: false,
140
+ /**
141
+ * We don't want to cache the result of the JS code, since it's arbitrary side effect code.
142
+ */
143
+ enableCache: false,
144
+ });
145
+ }
146
+ hasInitialized.current = true;
147
+ }
113
148
 
114
149
  return (
115
150
  <ComponentsContext.Provider
@@ -1 +1 @@
1
- export const SDK_VERSION = "2.0.15"
1
+ export const SDK_VERSION = "2.0.21"
@@ -0,0 +1,4 @@
1
+ /**
2
+ * To be overriden to the correct `Component` type for each framework.
3
+ */
4
+ export type ComponentReference = any
@@ -3,9 +3,10 @@ import type { ApiVersion } from '../types/api-version';
3
3
  import type { BuilderContent } from '../types/builder-content';
4
4
  import type { ComponentInfo } from '../types/components';
5
5
  import type { Dictionary, Nullable } from '../types/typescript';
6
+ import type { ComponentReference } from './component-reference-types';
6
7
  import type { ExtraContextTypes } from './extra-context-types';
7
8
  export type RegisteredComponent = ComponentInfo & {
8
- component: any;
9
+ component: ComponentReference;
9
10
  };
10
11
  export type RegisteredComponents = Dictionary<RegisteredComponent>;
11
12
  export type BuilderRenderState = Record<string, unknown>;
@@ -1,6 +1,5 @@
1
- import type { BuilderRenderState } from '../../../context/types';
2
1
  import type { ExecutorArgs } from '../helpers';
3
- import { getFunctionArguments } from '../helpers';
2
+ import { flattenState, getFunctionArguments } from '../helpers';
4
3
  export const runInBrowser = ({
5
4
  code,
6
5
  builder,
@@ -21,41 +20,4 @@ export const runInBrowser = ({
21
20
  })
22
21
  });
23
22
  return new Function(...functionArgs.map(([name]) => name), code)(...functionArgs.map(([, value]) => value));
24
- };
25
- export function flattenState({
26
- rootState,
27
- localState,
28
- rootSetState
29
- }: {
30
- rootState: Record<string | symbol, any>;
31
- localState: Record<string | symbol, any> | undefined;
32
- rootSetState: ((rootState: BuilderRenderState) => void) | undefined;
33
- }): BuilderRenderState {
34
- return new Proxy(rootState, {
35
- get: (target, prop) => {
36
- if (localState && prop in localState) {
37
- return localState[prop];
38
- }
39
- const val = target[prop];
40
- if (typeof val === 'object' && val !== null) {
41
- return flattenState({
42
- rootState: val,
43
- localState: undefined,
44
- rootSetState: rootSetState ? subState => {
45
- target[prop] = subState;
46
- rootSetState(target);
47
- } : undefined
48
- });
49
- }
50
- return val;
51
- },
52
- set: (target, prop, value) => {
53
- if (localState && prop in localState) {
54
- throw new Error('Writing to local state is not allowed as it is read-only.');
55
- }
56
- target[prop] = value;
57
- rootSetState?.(target);
58
- return true;
59
- }
60
- });
61
23
  }
@@ -24,4 +24,6 @@ import { shouldForceBrowserRuntimeInNode } from './should-force-browser-runtime-
24
24
  * Even though we have separate runtimes for browser/node/edge, sometimes frameworks will
25
25
  * end up sending the server runtime code to the browser (most notably in dev mode).
26
26
  */
27
- export const chooseBrowserOrServerEval = (args: ExecutorArgs) => isBrowser() || shouldForceBrowserRuntimeInNode() ? runInBrowser(args) : evaluator(args)
27
+ export const chooseBrowserOrServerEval = (args: ExecutorArgs) => isBrowser() || shouldForceBrowserRuntimeInNode({
28
+ shouldLogWarning: true
29
+ }) ? runInBrowser(args) : evaluator(args)
@@ -1,26 +1,66 @@
1
1
  import { logger } from '../../../helpers/logger';
2
- import { set } from '../../set';
3
2
  import type { ExecutorArgs } from '../helpers';
4
- import { getFunctionArguments } from '../helpers';
3
+ import { flattenState, getFunctionArguments } from '../helpers';
5
4
  import Interpreter from './acorn-interpreter';
6
- const processCode = (code: string) => {
7
- return code.split('\n').map(line => {
8
- const trimmed = line.trim();
9
-
10
- // this async wrapper doesn't work in JS-interpreter, so we drop it.
11
- if (line.includes('__awaiter')) return undefined;
12
5
 
13
- // we find all state setter expressions and append a call to setRootState afterwards
14
- const isStateSetter = trimmed.startsWith('state.');
15
- if (!isStateSetter) return line;
16
- const [lhs, rhs] = trimmed.split('=');
17
- const setStr = lhs.replace('state.', '').trim();
18
- const setExpr = `setRootState('${setStr}', ${rhs.trim()})`;
19
- return `
20
- ${line}
21
- ${setExpr}
22
- `;
23
- }).filter(Boolean).join('\n');
6
+ /**
7
+ * https://stackoverflow.com/a/46503625
8
+ */
9
+ function patchInterpreter() {
10
+ const originalGetProperty = Interpreter.prototype.getProperty;
11
+ const originalSetProperty = Interpreter.prototype.setProperty;
12
+ function newGetProperty(this: typeof Interpreter, obj: any, name: any) {
13
+ if (obj == null || !obj._connected) {
14
+ return originalGetProperty.call(this, obj, name);
15
+ }
16
+ const value = obj._connected[name];
17
+ if (Array.isArray(value)) {
18
+ return this.nativeToPseudo(value);
19
+ }
20
+ if (typeof value === 'object') {
21
+ // if the value is an object itself, create another connected object
22
+ return this.createConnectedObject(value);
23
+ }
24
+ return value;
25
+ }
26
+ function newSetProperty(this: typeof Interpreter, obj: any, name: any, value: any, opt_descriptor: any) {
27
+ if (obj == null || !obj._connected) {
28
+ return originalSetProperty.call(this, obj, name, value, opt_descriptor);
29
+ }
30
+ obj._connected[name] = this.pseudoToNative(value);
31
+ }
32
+ const getKeys: string[] = [];
33
+ const setKeys: string[] = [];
34
+ for (const key of Object.keys(Interpreter.prototype)) {
35
+ if (Interpreter.prototype[key] === originalGetProperty) {
36
+ getKeys.push(key);
37
+ }
38
+ if (Interpreter.prototype[key] === originalSetProperty) {
39
+ setKeys.push(key);
40
+ }
41
+ }
42
+ for (const key of getKeys) {
43
+ Interpreter.prototype[key] = newGetProperty;
44
+ }
45
+ for (const key of setKeys) {
46
+ Interpreter.prototype[key] = newSetProperty;
47
+ }
48
+ Interpreter.prototype.createConnectedObject = function (obj: any) {
49
+ const connectedObject = this.createObject(this.OBJECT);
50
+ connectedObject._connected = obj;
51
+ return connectedObject;
52
+ };
53
+ }
54
+ patchInterpreter();
55
+ const processCode = (code: string) => {
56
+ return code
57
+ // strip async/await polyfill: remove anything before 'function main()'
58
+ .replace(/^.*?function main\(\)/, `
59
+ var __awaiter = function (e, t, n, r) {return r()},
60
+ __generator = function (e, t) { return t() };
61
+ function main()`)
62
+ // replace ?. with .
63
+ .replace(/\?\./g, '.');
24
64
  };
25
65
  const getJSONValName = (val: string) => val + 'JSON';
26
66
  export const runInEdge = ({
@@ -32,10 +72,11 @@ export const runInEdge = ({
32
72
  rootSetState,
33
73
  code
34
74
  }: ExecutorArgs) => {
35
- const state = {
36
- ...rootState,
37
- ...localState
38
- };
75
+ const state = flattenState({
76
+ rootState,
77
+ localState,
78
+ rootSetState
79
+ });
39
80
  const properties = getFunctionArguments({
40
81
  builder,
41
82
  context,
@@ -48,6 +89,9 @@ export const runInEdge = ({
48
89
  */
49
90
  const prependedCode = properties.map(([key]) => {
50
91
  const jsonValName = getJSONValName(key);
92
+ if (key === 'state') {
93
+ return ``;
94
+ }
51
95
  return `var ${key} = ${jsonValName} === undefined ? undefined : JSON.parse(${jsonValName});`;
52
96
  }).join('\n');
53
97
  const cleanedCode = processCode(code);
@@ -63,24 +107,18 @@ function theFunction() {
63
107
  }
64
108
  theFunction();
65
109
  `;
66
- const setRootState = (prop: string, value: any) => {
67
- const newState = set(state, prop, value);
68
- rootSetState?.(newState);
69
- };
70
110
  const initFunc = function (interpreter: any, globalObject: any) {
71
111
  /**
72
112
  * serialize all function args to JSON strings
73
113
  */
74
114
  properties.forEach(([key, val]) => {
75
- const jsonVal = JSON.stringify(val);
76
- interpreter.setProperty(globalObject, getJSONValName(key), jsonVal);
115
+ if (key === 'state') {
116
+ interpreter.setProperty(globalObject, key, interpreter.createConnectedObject(val), interpreter.READONLY_DESCRIPTOR);
117
+ } else {
118
+ const jsonVal = JSON.stringify(val);
119
+ interpreter.setProperty(globalObject, getJSONValName(key), jsonVal);
120
+ }
77
121
  });
78
-
79
- /**
80
- * Add a JavaScript function "setRootState" to the interpreter's global object, that will be called whenever a
81
- * state property is set. This function will update the state object.
82
- */
83
- interpreter.setProperty(globalObject, 'setRootState', interpreter.createNativeFunction(setRootState));
84
122
  };
85
123
  const myInterpreter = new Interpreter(transformed, initFunc);
86
124
  myInterpreter.run();
@@ -53,4 +53,41 @@ export const parseCode = (code: string, {
53
53
  isExpression && !(code.includes(';') || code.includes(' return ') || code.trim().startsWith('return '));
54
54
  const useCode = useReturn ? `return (${code});` : code;
55
55
  return useCode;
56
+ };
57
+ export function flattenState({
58
+ rootState,
59
+ localState,
60
+ rootSetState
61
+ }: {
62
+ rootState: Record<string | symbol, any>;
63
+ localState: Record<string | symbol, any> | undefined;
64
+ rootSetState: ((rootState: BuilderRenderState) => void) | undefined;
65
+ }): BuilderRenderState {
66
+ return new Proxy(rootState, {
67
+ get: (target, prop) => {
68
+ if (localState && prop in localState) {
69
+ return localState[prop];
70
+ }
71
+ const val = target[prop];
72
+ if (typeof val === 'object' && val !== null) {
73
+ return flattenState({
74
+ rootState: val,
75
+ localState: undefined,
76
+ rootSetState: rootSetState ? subState => {
77
+ target[prop] = subState;
78
+ rootSetState(target);
79
+ } : undefined
80
+ });
81
+ }
82
+ return val;
83
+ },
84
+ set: (target, prop, value) => {
85
+ if (localState && prop in localState) {
86
+ throw new Error('Writing to local state is not allowed as it is read-only.');
87
+ }
88
+ target[prop] = value;
89
+ rootSetState?.(target);
90
+ return true;
91
+ }
92
+ });
56
93
  }
@@ -1,3 +1,4 @@
1
+ import { shouldForceBrowserRuntimeInNode } from '../should-force-browser-runtime-in-node';
1
2
  /**
2
3
  * This file:
3
4
  * - imports `isolated-vm`, which can only be made from a file that never runs
@@ -27,6 +28,14 @@ import type { IsolateOptions } from 'isolated-vm';
27
28
  export const initializeNodeRuntime = (args?: {
28
29
  ivmIsolateOptions?: IsolateOptions;
29
30
  }) => {
31
+ /**
32
+ * skip initialization if we are on an arm64 machine and running node 20
33
+ */
34
+ if (shouldForceBrowserRuntimeInNode({
35
+ shouldLogWarning: true
36
+ })) {
37
+ return;
38
+ }
30
39
  const {
31
40
  ivmIsolateOptions
32
41
  } = args || {};
@@ -80,7 +80,7 @@ export const setIvm = (ivm: IsolatedVMImport, options: IsolateOptions = {}) => {
80
80
  };
81
81
 
82
82
  // only mention the script for SDKs that have it.
83
- const SHOULD_MENTION_INITIALIZE_SCRIPT = SDK_NAME === '@builder.io/sdk-react-nextjs' || SDK_NAME === '@builder.io/sdk-react' || SDK_NAME === '@builder.io/sdk-qwik';
83
+ const SHOULD_MENTION_INITIALIZE_SCRIPT = SDK_NAME === '@builder.io/sdk-react-nextjs' || SDK_NAME === '@builder.io/sdk-react' || SDK_NAME === '@builder.io/sdk-qwik' || SDK_NAME === '@builder.io/sdk-vue';
84
84
  const getIvm = (): IsolatedVMImport => {
85
85
  try {
86
86
  if (IVM_INSTANCE) return IVM_INSTANCE;
@@ -1,15 +1,21 @@
1
1
  import { logger } from '../../helpers/logger';
2
2
  import { isNodeRuntime } from '../is-node-runtime';
3
- export const shouldForceBrowserRuntimeInNode = () => {
3
+ export const shouldForceBrowserRuntimeInNode = ({
4
+ shouldLogWarning
5
+ }: {
6
+ shouldLogWarning: boolean;
7
+ }) => {
4
8
  if (!isNodeRuntime()) return false;
5
9
  const isArm64 = process.arch === 'arm64';
6
10
  const isNode20 = process.version.startsWith('v20');
7
11
  const hasNoNodeSnapshotNodeOption = process.env.NODE_OPTIONS?.includes('--no-node-snapshot');
8
12
  if (isArm64 && isNode20 && !hasNoNodeSnapshotNodeOption) {
9
- logger.log(`Skipping usage of \`isolated-vm\` to avoid crashes in Node v20 on an arm64 machine.
13
+ if (shouldLogWarning) {
14
+ logger.log(`Skipping usage of \`isolated-vm\` to avoid crashes in Node v20 on an arm64 machine.
10
15
  If you would like to use the \`isolated-vm\` package on this machine, please provide the \`NODE_OPTIONS=--no-node-snapshot\` config to your Node process.
11
16
  See https://github.com/BuilderIO/builder/blob/main/packages/sdks/README.md#node-v20--m1-macs-apple-silicon-support for more information.
12
17
  `);
18
+ }
13
19
  return true;
14
20
  }
15
21
  return false;