@builder.io/sdk-react-nextjs 0.5.8 → 0.6.0

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 (287) hide show
  1. package/lib/browser/USE_CLIENT_BUNDLE-29f9ac5c.js +23 -0
  2. package/lib/browser/USE_CLIENT_BUNDLE-dfa97c43.mjs +664 -0
  3. package/lib/browser/USE_SERVER_BUNDLE-25e181fa.js +1 -0
  4. package/lib/browser/USE_SERVER_BUNDLE-fcd44ecb.mjs +11 -0
  5. package/lib/browser/bundle-5cab6113.js +76 -0
  6. package/lib/browser/bundle-babbd573.mjs +2419 -0
  7. package/lib/browser/index.cjs +1 -0
  8. package/lib/browser/index.mjs +34 -0
  9. package/lib/edge/USE_CLIENT_BUNDLE-3cbb02d5.mjs +664 -0
  10. package/lib/edge/USE_CLIENT_BUNDLE-d0b99f60.js +23 -0
  11. package/lib/edge/USE_SERVER_BUNDLE-4eeb4634.mjs +11 -0
  12. package/lib/edge/USE_SERVER_BUNDLE-bbd89085.js +1 -0
  13. package/lib/edge/bundle-9ed99f98.mjs +4863 -0
  14. package/lib/edge/bundle-e4764e2a.js +96 -0
  15. package/lib/edge/index.cjs +1 -0
  16. package/lib/edge/index.mjs +34 -0
  17. package/lib/node/USE_CLIENT_BUNDLE-29f9ac5c.js +23 -0
  18. package/lib/node/USE_CLIENT_BUNDLE-dfa97c43.mjs +664 -0
  19. package/lib/node/USE_SERVER_BUNDLE-25e181fa.js +1 -0
  20. package/lib/node/USE_SERVER_BUNDLE-fcd44ecb.mjs +11 -0
  21. package/lib/node/bundle-5cab6113.js +76 -0
  22. package/lib/node/bundle-babbd573.mjs +2419 -0
  23. package/lib/node/index.cjs +1 -0
  24. package/lib/node/index.mjs +34 -0
  25. package/package.json +96 -13
  26. package/{dist → types}/components/content/content.types.d.ts +2 -2
  27. package/{dist → types}/components/content-variants/content-variants.d.ts +2 -2
  28. package/{dist → types}/components/content-variants/content-variants.types.d.ts +1 -1
  29. package/types/constants/sdk-version.d.ts +1 -0
  30. package/types/functions/deopt.d.ts +4 -0
  31. package/types/functions/evaluate/browser-runtime/browser.d.ts +4 -0
  32. package/types/functions/evaluate/browser-runtime/index.d.ts +1 -0
  33. package/types/functions/evaluate/evaluate.d.ts +6 -0
  34. package/types/functions/evaluate/helpers.d.ts +18 -0
  35. package/types/functions/evaluate/index.d.ts +1 -0
  36. package/{dist → types}/functions/fetch-builder-props.d.ts +4 -3
  37. package/{dist → types}/functions/get-content/index.d.ts +4 -5
  38. package/{dist → types}/index-helpers/blocks-exports.d.ts +2 -2
  39. package/types/index.d.ts +7 -0
  40. package/{dist/index.d.ts → types/server-index.d.ts} +0 -1
  41. package/dist/blocks/button/button.js +0 -12
  42. package/dist/blocks/button/component-info.js +0 -34
  43. package/dist/blocks/columns/columns.js +0 -119
  44. package/dist/blocks/columns/component-info.js +0 -219
  45. package/dist/blocks/custom-code/component-info.js +0 -23
  46. package/dist/blocks/custom-code/custom-code.js +0 -51
  47. package/dist/blocks/embed/component-info.js +0 -39
  48. package/dist/blocks/embed/embed.js +0 -42
  49. package/dist/blocks/embed/helpers.js +0 -2
  50. package/dist/blocks/fragment/component-info.js +0 -7
  51. package/dist/blocks/fragment/fragment.js +0 -6
  52. package/dist/blocks/helpers.js +0 -40
  53. package/dist/blocks/image/component-info.js +0 -122
  54. package/dist/blocks/image/image.helpers.js +0 -47
  55. package/dist/blocks/image/image.js +0 -82
  56. package/dist/blocks/img/component-info.js +0 -15
  57. package/dist/blocks/img/img.js +0 -10
  58. package/dist/blocks/section/component-info.js +0 -40
  59. package/dist/blocks/section/section.js +0 -17
  60. package/dist/blocks/symbol/component-info.js +0 -34
  61. package/dist/blocks/symbol/symbol.helpers.js +0 -31
  62. package/dist/blocks/symbol/symbol.js +0 -29
  63. package/dist/blocks/text/component-info.js +0 -19
  64. package/dist/blocks/text/text.js +0 -7
  65. package/dist/blocks/video/component-info.js +0 -82
  66. package/dist/blocks/video/video.js +0 -50
  67. package/dist/components/block/block.helpers.js +0 -69
  68. package/dist/components/block/block.js +0 -92
  69. package/dist/components/block/components/block-styles.js +0 -65
  70. package/dist/components/block/components/block-wrapper.js +0 -36
  71. package/dist/components/block/components/component-ref/component-ref.helpers.js +0 -22
  72. package/dist/components/block/components/component-ref/component-ref.js +0 -21
  73. package/dist/components/block/components/interactive-element.js +0 -20
  74. package/dist/components/block/components/repeated-block.js +0 -7
  75. package/dist/components/block/types.js +0 -1
  76. package/dist/components/blocks/blocks-wrapper.js +0 -38
  77. package/dist/components/blocks/blocks.js +0 -10
  78. package/dist/components/content/components/enable-editor.js +0 -250
  79. package/dist/components/content/components/styles.helpers.js +0 -58
  80. package/dist/components/content/components/styles.js +0 -30
  81. package/dist/components/content/content.helpers.js +0 -30
  82. package/dist/components/content/content.js +0 -74
  83. package/dist/components/content/content.types.js +0 -1
  84. package/dist/components/content/wrap-component-ref.js +0 -6
  85. package/dist/components/content-variants/content-variants.js +0 -45
  86. package/dist/components/content-variants/content-variants.types.js +0 -1
  87. package/dist/components/content-variants/helpers.js +0 -189
  88. package/dist/components/inlined-script.js +0 -5
  89. package/dist/components/inlined-styles.js +0 -5
  90. package/dist/constants/builder-registered-components.js +0 -60
  91. package/dist/constants/device-sizes.js +0 -45
  92. package/dist/constants/sdk-version.d.ts +0 -1
  93. package/dist/constants/sdk-version.js +0 -1
  94. package/dist/constants/target.js +0 -2
  95. package/dist/context/builder.context.js +0 -12
  96. package/dist/context/components.context.js +0 -2
  97. package/dist/context/types.js +0 -1
  98. package/dist/functions/camel-to-kebab-case.js +0 -1
  99. package/dist/functions/evaluate/acorn-interpreter.d.ts +0 -2
  100. package/dist/functions/evaluate/acorn-interpreter.js +0 -3111
  101. package/dist/functions/evaluate/evaluate.d.ts +0 -10
  102. package/dist/functions/evaluate/evaluate.js +0 -70
  103. package/dist/functions/evaluate/index.d.ts +0 -1
  104. package/dist/functions/evaluate/index.js +0 -1
  105. package/dist/functions/evaluate/non-node-runtime/index.d.ts +0 -1
  106. package/dist/functions/evaluate/non-node-runtime/index.js +0 -2
  107. package/dist/functions/evaluate/non-node-runtime/non-node-runtime.d.ts +0 -2
  108. package/dist/functions/evaluate/non-node-runtime/non-node-runtime.js +0 -84
  109. package/dist/functions/evaluate/types.d.ts +0 -11
  110. package/dist/functions/evaluate/types.js +0 -1
  111. package/dist/functions/event-handler-name.js +0 -4
  112. package/dist/functions/extract-text-styles.js +0 -22
  113. package/dist/functions/fast-clone.js +0 -4
  114. package/dist/functions/fetch-builder-props.js +0 -25
  115. package/dist/functions/get-block-actions-handler.js +0 -10
  116. package/dist/functions/get-block-actions.js +0 -28
  117. package/dist/functions/get-block-component-options.js +0 -10
  118. package/dist/functions/get-block-properties.js +0 -72
  119. package/dist/functions/get-builder-search-params/index.js +0 -38
  120. package/dist/functions/get-content/generate-content-url.js +0 -33
  121. package/dist/functions/get-content/index.js +0 -100
  122. package/dist/functions/get-content/types.js +0 -1
  123. package/dist/functions/get-fetch.js +0 -11
  124. package/dist/functions/get-global-this.js +0 -15
  125. package/dist/functions/get-processed-block.js +0 -46
  126. package/dist/functions/get-react-native-block-styles.js +0 -17
  127. package/dist/functions/is-browser.js +0 -3
  128. package/dist/functions/is-editing.js +0 -5
  129. package/dist/functions/is-iframe.js +0 -4
  130. package/dist/functions/is-non-node-server.d.ts +0 -4
  131. package/dist/functions/is-non-node-server.js +0 -8
  132. package/dist/functions/is-previewing.js +0 -11
  133. package/dist/functions/register-component.js +0 -38
  134. package/dist/functions/register.js +0 -27
  135. package/dist/functions/sanitize-react-native-block-styles.js +0 -61
  136. package/dist/functions/set-editor-settings.js +0 -12
  137. package/dist/functions/set.js +0 -14
  138. package/dist/functions/track/helpers.js +0 -51
  139. package/dist/functions/track/index.js +0 -71
  140. package/dist/functions/track/interaction.js +0 -53
  141. package/dist/functions/transform-block-properties.js +0 -5
  142. package/dist/functions/transform-block.js +0 -4
  143. package/dist/helpers/ab-tests.js +0 -122
  144. package/dist/helpers/canTrack.js +0 -2
  145. package/dist/helpers/cookie.js +0 -55
  146. package/dist/helpers/css.js +0 -27
  147. package/dist/helpers/flatten.js +0 -19
  148. package/dist/helpers/localStorage.js +0 -24
  149. package/dist/helpers/logger.js +0 -7
  150. package/dist/helpers/nullable.js +0 -1
  151. package/dist/helpers/preview-lru-cache/get.js +0 -9
  152. package/dist/helpers/preview-lru-cache/helpers.js +0 -9
  153. package/dist/helpers/preview-lru-cache/init.js +0 -15
  154. package/dist/helpers/preview-lru-cache/set.js +0 -7
  155. package/dist/helpers/preview-lru-cache/types.js +0 -6
  156. package/dist/helpers/sessionId.js +0 -30
  157. package/dist/helpers/url.js +0 -15
  158. package/dist/helpers/uuid.js +0 -15
  159. package/dist/helpers/visitorId.js +0 -30
  160. package/dist/index-helpers/blocks-exports.js +0 -19
  161. package/dist/index-helpers/top-of-file.js +0 -4
  162. package/dist/index.js +0 -11
  163. package/dist/scripts/init-editing.js +0 -110
  164. package/dist/types/api-version.js +0 -1
  165. package/dist/types/builder-block.js +0 -1
  166. package/dist/types/builder-content.js +0 -1
  167. package/dist/types/builder-props.js +0 -1
  168. package/dist/types/can-track.js +0 -1
  169. package/dist/types/components.js +0 -1
  170. package/dist/types/deep-partial.js +0 -1
  171. package/dist/types/element.js +0 -1
  172. package/dist/types/enforced-partials.js +0 -1
  173. package/dist/types/input.js +0 -1
  174. package/dist/types/targets.js +0 -1
  175. package/dist/types/typescript.js +0 -1
  176. /package/{dist → types}/blocks/button/button.d.ts +0 -0
  177. /package/{dist → types}/blocks/button/component-info.d.ts +0 -0
  178. /package/{dist → types}/blocks/columns/columns.d.ts +0 -0
  179. /package/{dist → types}/blocks/columns/component-info.d.ts +0 -0
  180. /package/{dist → types}/blocks/custom-code/component-info.d.ts +0 -0
  181. /package/{dist → types}/blocks/custom-code/custom-code.d.ts +0 -0
  182. /package/{dist → types}/blocks/embed/component-info.d.ts +0 -0
  183. /package/{dist → types}/blocks/embed/embed.d.ts +0 -0
  184. /package/{dist → types}/blocks/embed/helpers.d.ts +0 -0
  185. /package/{dist → types}/blocks/fragment/component-info.d.ts +0 -0
  186. /package/{dist → types}/blocks/fragment/fragment.d.ts +0 -0
  187. /package/{dist → types}/blocks/helpers.d.ts +0 -0
  188. /package/{dist → types}/blocks/image/component-info.d.ts +0 -0
  189. /package/{dist → types}/blocks/image/image.d.ts +0 -0
  190. /package/{dist → types}/blocks/image/image.helpers.d.ts +0 -0
  191. /package/{dist → types}/blocks/img/component-info.d.ts +0 -0
  192. /package/{dist → types}/blocks/img/img.d.ts +0 -0
  193. /package/{dist → types}/blocks/section/component-info.d.ts +0 -0
  194. /package/{dist → types}/blocks/section/section.d.ts +0 -0
  195. /package/{dist → types}/blocks/symbol/component-info.d.ts +0 -0
  196. /package/{dist → types}/blocks/symbol/symbol.d.ts +0 -0
  197. /package/{dist → types}/blocks/symbol/symbol.helpers.d.ts +0 -0
  198. /package/{dist → types}/blocks/text/component-info.d.ts +0 -0
  199. /package/{dist → types}/blocks/text/text.d.ts +0 -0
  200. /package/{dist → types}/blocks/video/component-info.d.ts +0 -0
  201. /package/{dist → types}/blocks/video/video.d.ts +0 -0
  202. /package/{dist → types}/components/block/block.d.ts +0 -0
  203. /package/{dist → types}/components/block/block.helpers.d.ts +0 -0
  204. /package/{dist → types}/components/block/components/block-styles.d.ts +0 -0
  205. /package/{dist → types}/components/block/components/block-wrapper.d.ts +0 -0
  206. /package/{dist → types}/components/block/components/component-ref/component-ref.d.ts +0 -0
  207. /package/{dist → types}/components/block/components/component-ref/component-ref.helpers.d.ts +0 -0
  208. /package/{dist → types}/components/block/components/interactive-element.d.ts +0 -0
  209. /package/{dist → types}/components/block/components/repeated-block.d.ts +0 -0
  210. /package/{dist → types}/components/block/types.d.ts +0 -0
  211. /package/{dist → types}/components/blocks/blocks-wrapper.d.ts +0 -0
  212. /package/{dist → types}/components/blocks/blocks.d.ts +0 -0
  213. /package/{dist → types}/components/content/components/enable-editor.d.ts +0 -0
  214. /package/{dist → types}/components/content/components/styles.d.ts +0 -0
  215. /package/{dist → types}/components/content/components/styles.helpers.d.ts +0 -0
  216. /package/{dist → types}/components/content/content.d.ts +0 -0
  217. /package/{dist → types}/components/content/content.helpers.d.ts +0 -0
  218. /package/{dist → types}/components/content/wrap-component-ref.d.ts +0 -0
  219. /package/{dist → types}/components/content-variants/helpers.d.ts +0 -0
  220. /package/{dist → types}/components/inlined-script.d.ts +0 -0
  221. /package/{dist → types}/components/inlined-styles.d.ts +0 -0
  222. /package/{dist → types}/constants/builder-registered-components.d.ts +0 -0
  223. /package/{dist → types}/constants/device-sizes.d.ts +0 -0
  224. /package/{dist → types}/constants/target.d.ts +0 -0
  225. /package/{dist → types}/context/builder.context.d.ts +0 -0
  226. /package/{dist → types}/context/components.context.d.ts +0 -0
  227. /package/{dist → types}/context/types.d.ts +0 -0
  228. /package/{dist → types}/functions/camel-to-kebab-case.d.ts +0 -0
  229. /package/{dist → types}/functions/event-handler-name.d.ts +0 -0
  230. /package/{dist → types}/functions/extract-text-styles.d.ts +0 -0
  231. /package/{dist → types}/functions/fast-clone.d.ts +0 -0
  232. /package/{dist → types}/functions/get-block-actions-handler.d.ts +0 -0
  233. /package/{dist → types}/functions/get-block-actions.d.ts +0 -0
  234. /package/{dist → types}/functions/get-block-component-options.d.ts +0 -0
  235. /package/{dist → types}/functions/get-block-properties.d.ts +0 -0
  236. /package/{dist → types}/functions/get-builder-search-params/index.d.ts +0 -0
  237. /package/{dist → types}/functions/get-content/generate-content-url.d.ts +0 -0
  238. /package/{dist → types}/functions/get-content/types.d.ts +0 -0
  239. /package/{dist → types}/functions/get-fetch.d.ts +0 -0
  240. /package/{dist → types}/functions/get-global-this.d.ts +0 -0
  241. /package/{dist → types}/functions/get-processed-block.d.ts +0 -0
  242. /package/{dist → types}/functions/get-react-native-block-styles.d.ts +0 -0
  243. /package/{dist → types}/functions/is-browser.d.ts +0 -0
  244. /package/{dist → types}/functions/is-editing.d.ts +0 -0
  245. /package/{dist → types}/functions/is-iframe.d.ts +0 -0
  246. /package/{dist → types}/functions/is-previewing.d.ts +0 -0
  247. /package/{dist → types}/functions/register-component.d.ts +0 -0
  248. /package/{dist → types}/functions/register.d.ts +0 -0
  249. /package/{dist → types}/functions/sanitize-react-native-block-styles.d.ts +0 -0
  250. /package/{dist → types}/functions/set-editor-settings.d.ts +0 -0
  251. /package/{dist → types}/functions/set.d.ts +0 -0
  252. /package/{dist → types}/functions/track/helpers.d.ts +0 -0
  253. /package/{dist → types}/functions/track/index.d.ts +0 -0
  254. /package/{dist → types}/functions/track/interaction.d.ts +0 -0
  255. /package/{dist → types}/functions/transform-block-properties.d.ts +0 -0
  256. /package/{dist → types}/functions/transform-block.d.ts +0 -0
  257. /package/{dist → types}/helpers/ab-tests.d.ts +0 -0
  258. /package/{dist → types}/helpers/canTrack.d.ts +0 -0
  259. /package/{dist → types}/helpers/cookie.d.ts +0 -0
  260. /package/{dist → types}/helpers/css.d.ts +0 -0
  261. /package/{dist → types}/helpers/flatten.d.ts +0 -0
  262. /package/{dist → types}/helpers/localStorage.d.ts +0 -0
  263. /package/{dist → types}/helpers/logger.d.ts +0 -0
  264. /package/{dist → types}/helpers/nullable.d.ts +0 -0
  265. /package/{dist → types}/helpers/preview-lru-cache/get.d.ts +0 -0
  266. /package/{dist → types}/helpers/preview-lru-cache/helpers.d.ts +0 -0
  267. /package/{dist → types}/helpers/preview-lru-cache/init.d.ts +0 -0
  268. /package/{dist → types}/helpers/preview-lru-cache/set.d.ts +0 -0
  269. /package/{dist → types}/helpers/preview-lru-cache/types.d.ts +0 -0
  270. /package/{dist → types}/helpers/sessionId.d.ts +0 -0
  271. /package/{dist → types}/helpers/url.d.ts +0 -0
  272. /package/{dist → types}/helpers/uuid.d.ts +0 -0
  273. /package/{dist → types}/helpers/visitorId.d.ts +0 -0
  274. /package/{dist → types}/index-helpers/top-of-file.d.ts +0 -0
  275. /package/{dist → types}/scripts/init-editing.d.ts +0 -0
  276. /package/{dist → types}/types/api-version.d.ts +0 -0
  277. /package/{dist → types}/types/builder-block.d.ts +0 -0
  278. /package/{dist → types}/types/builder-content.d.ts +0 -0
  279. /package/{dist → types}/types/builder-props.d.ts +0 -0
  280. /package/{dist → types}/types/can-track.d.ts +0 -0
  281. /package/{dist → types}/types/components.d.ts +0 -0
  282. /package/{dist → types}/types/deep-partial.d.ts +0 -0
  283. /package/{dist → types}/types/element.d.ts +0 -0
  284. /package/{dist → types}/types/enforced-partials.d.ts +0 -0
  285. /package/{dist → types}/types/input.d.ts +0 -0
  286. /package/{dist → types}/types/targets.d.ts +0 -0
  287. /package/{dist → types}/types/typescript.d.ts +0 -0
@@ -1,10 +0,0 @@
1
- import type { BuilderContextInterface, BuilderRenderState } from '../../context/types.js';
2
- import type { ExecutorArgs } from './types.js';
3
- export declare function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression }: {
4
- code: string;
5
- event?: Event;
6
- isExpression?: boolean;
7
- } & Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>): any;
8
- export declare const runInBrowser: ({ useCode, builder, context, event, localState, rootSetState, rootState }: ExecutorArgs) => any;
9
- export declare const runInNode: (args: ExecutorArgs) => any;
10
- export declare function flattenState(rootState: Record<string | symbol, any>, localState: Record<string | symbol, any> | undefined, rootSetState: ((rootState: BuilderRenderState) => void) | undefined): BuilderRenderState;
@@ -1,70 +0,0 @@
1
- import { logger } from '../../helpers/logger.js';
2
- import { isBrowser } from '../is-browser.js';
3
- import { isEditing } from '../is-editing.js';
4
- import { isNonNodeServer } from '../is-non-node-server.js';
5
- import { runInNonNode } from './non-node-runtime/index.js';
6
- export function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true }) {
7
- if (code === '') {
8
- logger.warn('Skipping evaluation of empty code block.');
9
- return;
10
- }
11
- const builder = {
12
- isEditing: isEditing(),
13
- isBrowser: isBrowser(),
14
- isServer: !isBrowser()
15
- };
16
- // Be able to handle simple expressions like "state.foo" or "1 + 1"
17
- // as well as full blocks like "var foo = "bar"; return foo"
18
- const useReturn =
19
- // we disable this for cases where we definitely don't want a return
20
- isExpression && !(code.includes(';') || code.includes(' return ') || code.trim().startsWith('return '));
21
- const useCode = useReturn ? `return (${code});` : code;
22
- const args = {
23
- useCode,
24
- builder,
25
- context,
26
- event,
27
- rootSetState,
28
- rootState,
29
- localState
30
- };
31
- if (isBrowser())
32
- return runInBrowser(args);
33
- if (isNonNodeServer())
34
- return runInNonNode(args);
35
- return runInNode(args);
36
- }
37
- export const runInBrowser = ({ useCode, builder, context, event, localState, rootSetState, rootState }) => {
38
- const state = flattenState(rootState, localState, rootSetState);
39
- try {
40
- return new Function('builder', 'Builder' /* <- legacy */, 'state', 'context', 'event', useCode)(builder, builder, state, context, event);
41
- }
42
- catch (e) {
43
- logger.warn('Builder custom code error: \n While Evaluating: \n ', useCode, '\n', e);
44
- }
45
- };
46
- export const runInNode = (args) => {
47
- // TO-DO: use vm-isolate
48
- return runInBrowser(args);
49
- };
50
- export function flattenState(rootState, localState, rootSetState) {
51
- if (rootState === localState) {
52
- throw new Error('rootState === localState');
53
- }
54
- return new Proxy(rootState, {
55
- get: (_, prop) => {
56
- if (localState && prop in localState) {
57
- return localState[prop];
58
- }
59
- return rootState[prop];
60
- },
61
- set: (_, prop, value) => {
62
- if (localState && prop in localState) {
63
- throw new Error('Writing to local state is not allowed as it is read-only.');
64
- }
65
- rootState[prop] = value;
66
- rootSetState?.(rootState);
67
- return true;
68
- }
69
- });
70
- }
@@ -1 +0,0 @@
1
- export { evaluate } from './evaluate';
@@ -1 +0,0 @@
1
- export { evaluate } from './evaluate';
@@ -1 +0,0 @@
1
- export { runInNonNode } from './non-node-runtime.js';
@@ -1,2 +0,0 @@
1
- // TEMPORARY FIX UNTIL we fix dynamic imports
2
- export { runInNonNode } from './non-node-runtime.js';
@@ -1,2 +0,0 @@
1
- import type { ExecutorArgs } from '../types';
2
- export declare const runInNonNode: ({ builder, context, event, rootState, localState, rootSetState, useCode }: ExecutorArgs) => any;
@@ -1,84 +0,0 @@
1
- import { logger } from '../../../helpers/logger';
2
- import { set } from '../../set';
3
- import Interpreter from '../acorn-interpreter.js';
4
- const processCode = (code) => {
5
- return code.split('\n').map(line => {
6
- const trimmed = line.trim();
7
- // this async wrapper doesn't work in JS-interpreter, so we drop it.
8
- if (line.includes('__awaiter'))
9
- return undefined;
10
- // we find all state setter expressions and append a call to setRootState afterwards
11
- const isStateSetter = trimmed.startsWith('state.');
12
- if (!isStateSetter)
13
- return line;
14
- const [lhs, rhs] = trimmed.split('=');
15
- const setStr = lhs.replace('state.', '').trim();
16
- const setExpr = `setRootState('${setStr}', ${rhs.trim()})`;
17
- return `
18
- ${line}
19
- ${setExpr}
20
- `;
21
- }).filter(Boolean).join('\n');
22
- };
23
- const getJSONValName = (val) => val + 'JSON';
24
- export const runInNonNode = ({ builder, context, event, rootState, localState, rootSetState, useCode }) => {
25
- const state = {
26
- ...rootState,
27
- ...localState
28
- };
29
- const properties = {
30
- state,
31
- Builder: builder,
32
- builder,
33
- context,
34
- event
35
- };
36
- /**
37
- * Deserialize all properties from JSON strings to JS objects
38
- */
39
- const prependedCode = Object.keys(properties).map(key => `var ${key} = JSON.parse(${getJSONValName(key)});`).join('\n');
40
- const cleanedCode = processCode(useCode);
41
- if (cleanedCode === '') {
42
- logger.warn('Skipping evaluation of empty code block.');
43
- return;
44
- }
45
- const transformed = `
46
- function theFunction() {
47
- ${prependedCode}
48
-
49
- ${cleanedCode}
50
- }
51
- theFunction();
52
- `;
53
- const setRootState = (prop, value) => {
54
- const newState = set(state, prop, value);
55
- rootSetState?.(newState);
56
- };
57
- const initFunc = function (interpreter, globalObject) {
58
- /**
59
- * serialize all function args to JSON strings
60
- */
61
- Object.keys(properties).forEach(key => {
62
- const val = properties[key] || {};
63
- const jsonVal = JSON.stringify(val);
64
- interpreter.setProperty(globalObject, getJSONValName(key), jsonVal);
65
- });
66
- /**
67
- * Add a JavaScript function "setRootState" to the interpreter's global object, that will be called whenever a
68
- * state property is set. This function will update the state object.
69
- */
70
- interpreter.setProperty(globalObject, 'setRootState', interpreter.createNativeFunction(setRootState));
71
- };
72
- try {
73
- const myInterpreter = new Interpreter(transformed, initFunc);
74
- myInterpreter.run();
75
- const output = myInterpreter.pseudoToNative(myInterpreter.value);
76
- return output;
77
- }
78
- catch (e) {
79
- logger.warn('Custom code error in non-node runtime. SDK can only execute ES5 JavaScript.', {
80
- e
81
- });
82
- return;
83
- }
84
- };
@@ -1,11 +0,0 @@
1
- import type { BuilderContextInterface } from '../../context/types';
2
- export type ExecutorArgs = Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'> & {
3
- useCode: string;
4
- builder: {
5
- isEditing: boolean | undefined;
6
- isBrowser: boolean | undefined;
7
- isServer: boolean | undefined;
8
- };
9
- event: Event | undefined;
10
- };
11
- export type Executor = (args: ExecutorArgs) => any;
@@ -1 +0,0 @@
1
- export {};
@@ -1,4 +0,0 @@
1
- function capitalizeFirstLetter(string) {
2
- return string.charAt(0).toUpperCase() + string.slice(1);
3
- }
4
- export const getEventHandlerName = (key) => `on${capitalizeFirstLetter(key)}`;
@@ -1,22 +0,0 @@
1
- const TEXT_STYLE_KEYS = ['color', 'whiteSpace', 'direction', 'hyphens', 'overflowWrap'];
2
- /**
3
- * Check if the key represent a CSS style property that applies to text
4
- * See MDN docs for refrence of what properties apply to text.
5
- * https://developer.mozilla.org/en-US/docs/Learn/CSS/Styling_text/Fundamentals#summary
6
- */
7
- const isTextStyle = (key) => {
8
- return TEXT_STYLE_KEYS.includes(key) || key.startsWith('font') || key.startsWith('text') || key.startsWith('letter') || key.startsWith('line') || key.startsWith('word') || key.startsWith('writing');
9
- };
10
- /**
11
- * Extract styles that apply to text from a style object.
12
- */
13
- export const extractTextStyles = (styles) => {
14
- const textStyles = {};
15
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
- Object.entries(styles).forEach(([key, value]) => {
17
- if (isTextStyle(key)) {
18
- textStyles[key] = value;
19
- }
20
- });
21
- return textStyles;
22
- };
@@ -1,4 +0,0 @@
1
- /**
2
- * We need to serialize values to a string in case there are Proxy values, as is the case with SolidJS etc.
3
- */
4
- export const fastClone = (obj) => JSON.parse(JSON.stringify(obj));
@@ -1,25 +0,0 @@
1
- import { getBuilderSearchParams } from './get-builder-search-params/index.js';
2
- import { fetchOneEntry } from './get-content/index.js';
3
- /**
4
- * Fetches builder content, and returns it along with sensible defaults for other props that `Content` needs to render.
5
- */
6
- export const fetchBuilderProps = async (_args) => {
7
- const urlPath = _args.path || _args.url?.pathname || _args.userAttributes?.urlPath;
8
- const getContentArgs = {
9
- ..._args,
10
- apiKey: _args.apiKey,
11
- model: _args.model || 'page',
12
- userAttributes: {
13
- ..._args.userAttributes,
14
- ...(urlPath ? {
15
- urlPath
16
- } : {})
17
- },
18
- options: getBuilderSearchParams(_args.searchParams || _args.url?.searchParams || _args.options)
19
- };
20
- return {
21
- apiKey: getContentArgs.apiKey,
22
- model: getContentArgs.model,
23
- content: await fetchOneEntry(getContentArgs)
24
- };
25
- };
@@ -1,10 +0,0 @@
1
- import { evaluate } from './evaluate';
2
- export const createEventHandler = (value, options) => event => evaluate({
3
- code: value,
4
- context: options.context,
5
- localState: options.localState,
6
- rootState: options.rootState,
7
- rootSetState: options.rootSetState,
8
- event,
9
- isExpression: false
10
- });
@@ -1,28 +0,0 @@
1
- import { TARGET } from '../constants/target.js';
2
- import { getEventHandlerName } from './event-handler-name.js';
3
- import { createEventHandler } from './get-block-actions-handler.js';
4
- export function getBlockActions(options) {
5
- const obj = {};
6
- const optionActions = options.block.actions ?? {};
7
- for (const key in optionActions) {
8
- // eslint-disable-next-line no-prototype-builtins
9
- if (!optionActions.hasOwnProperty(key)) {
10
- continue;
11
- }
12
- const value = optionActions[key];
13
- let eventHandlerName = getEventHandlerName(key);
14
- if (options.stripPrefix) {
15
- switch (TARGET) {
16
- case 'vue2':
17
- case 'vue3':
18
- eventHandlerName = eventHandlerName.replace('v-on:', '');
19
- break;
20
- case 'svelte':
21
- eventHandlerName = eventHandlerName.replace('on:', '');
22
- break;
23
- }
24
- }
25
- obj[eventHandlerName] = createEventHandler(value, options);
26
- }
27
- return obj;
28
- }
@@ -1,10 +0,0 @@
1
- export function getBlockComponentOptions(block) {
2
- return {
3
- ...block.component?.options,
4
- ...block.options,
5
- /**
6
- * Our built-in components frequently make use of the block, so we provide all of it under `builderBlock`
7
- */
8
- builderBlock: block
9
- };
10
- }
@@ -1,72 +0,0 @@
1
- import { TARGET } from '../constants/target.js';
2
- import { convertStyleMapToCSSArray } from '../helpers/css.js';
3
- import { getReactNativeBlockStyles } from './get-react-native-block-styles.js';
4
- import { transformBlockProperties } from './transform-block-properties.js';
5
- const extractRelevantRootBlockProperties = (block) => {
6
- // currently we are only spreading the `href` property
7
- // TO-DO: potentially spread all properties from block, but only if they are not already defined by BuilderBlock
8
- // const {
9
- // '@type': _type,
10
- // '@version': _version,
11
- // id: _id,
12
- // tagName: _tagName,
13
- // layerName: _layerName,
14
- // groupLocked: _groupLocked,
15
- // layerLocked: _layerLocked,
16
- // class: _class,
17
- // children: _children,
18
- // responsiveStyles: _responsiveStyles,
19
- // component: _component,
20
- // bindings: _bindings,
21
- // meta: _meta,
22
- // actions: _actions,
23
- // properties: _properties,
24
- // code: _code,
25
- // repeat: _repeat,
26
- // animations: _animations,
27
- // style: _style,
28
- // hide: _hide,
29
- // show: _show,
30
- // // anything set by dynamic bindings outside of predefined `BuilderBlock` properties
31
- // ...remainingBlockProperties
32
- // } = block;
33
- return {
34
- href: block.href
35
- };
36
- };
37
- export function getBlockProperties({ block, context }) {
38
- const properties = {
39
- ...extractRelevantRootBlockProperties(block),
40
- ...block.properties,
41
- 'builder-id': block.id,
42
- style: block.style ? getStyleAttribute(block.style) : undefined,
43
- class: [block.id, 'builder-block', block.class, block.properties?.class].filter(Boolean).join(' ')
44
- };
45
- if (TARGET === 'reactNative') {
46
- properties.style = getReactNativeBlockStyles({
47
- block,
48
- context,
49
- blockStyles: properties.style
50
- });
51
- }
52
- return transformBlockProperties(properties);
53
- }
54
- /**
55
- * Svelte does not support style attribute as an object so we need to flatten it.
56
- *
57
- * Additionally, Svelte, Vue and other frameworks use kebab-case styles, so we need to convert them.
58
- */
59
- function getStyleAttribute(style) {
60
- switch (TARGET) {
61
- case 'svelte':
62
- case 'vue2':
63
- case 'vue3':
64
- case 'solid':
65
- return convertStyleMapToCSSArray(style).join(' ');
66
- case 'qwik':
67
- case 'reactNative':
68
- case 'react':
69
- case 'rsc':
70
- return style;
71
- }
72
- }
@@ -1,38 +0,0 @@
1
- import { isBrowser } from '../is-browser.js';
2
- const BUILDER_SEARCHPARAMS_PREFIX = 'builder.';
3
- const BUILDER_OPTIONS_PREFIX = 'options.';
4
- export const convertSearchParamsToQueryObject = (searchParams) => {
5
- const options = {};
6
- searchParams.forEach((value, key) => {
7
- options[key] = value;
8
- });
9
- return options;
10
- };
11
- /**
12
- * Receives a `URLSearchParams` object or a regular query object, and returns the subset of query params that are
13
- * relevant to the Builder SDK.
14
- *
15
- * @returns
16
- */
17
- export const getBuilderSearchParams = (_options) => {
18
- if (!_options) {
19
- return {};
20
- }
21
- const options = normalizeSearchParams(_options);
22
- const newOptions = {};
23
- Object.keys(options).forEach(key => {
24
- if (key.startsWith(BUILDER_SEARCHPARAMS_PREFIX)) {
25
- const trimmedKey = key.replace(BUILDER_SEARCHPARAMS_PREFIX, '').replace(BUILDER_OPTIONS_PREFIX, '');
26
- newOptions[trimmedKey] = options[key];
27
- }
28
- });
29
- return newOptions;
30
- };
31
- export const getBuilderSearchParamsFromWindow = () => {
32
- if (!isBrowser()) {
33
- return {};
34
- }
35
- const searchParams = new URLSearchParams(window.location.search);
36
- return getBuilderSearchParams(searchParams);
37
- };
38
- export const normalizeSearchParams = (searchParams) => searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams;
@@ -1,33 +0,0 @@
1
- import { flatten } from '../../helpers/flatten.js';
2
- import { getBuilderSearchParamsFromWindow, normalizeSearchParams } from '../get-builder-search-params/index.js';
3
- import { DEFAULT_API_VERSION } from '../../types/api-version.js';
4
- export const generateContentUrl = (options) => {
5
- const { limit = 30, userAttributes, query, noTraverse = false, model, apiKey, includeRefs = true, enrich, locale, apiVersion = DEFAULT_API_VERSION } = options;
6
- if (!apiKey) {
7
- throw new Error('Missing API key');
8
- }
9
- if (!['v2', 'v3'].includes(apiVersion)) {
10
- throw new Error(`Invalid apiVersion: expected 'v2' or 'v3', received '${apiVersion}'`);
11
- }
12
- const url = new URL(`https://cdn.builder.io/api/${apiVersion}/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}${locale ? `&locale=${locale}` : ''}${enrich ? `&enrich=${enrich}` : ''}`);
13
- const queryOptions = {
14
- ...getBuilderSearchParamsFromWindow(),
15
- ...normalizeSearchParams(options.options || {})
16
- };
17
- const flattened = flatten(queryOptions);
18
- for (const key in flattened) {
19
- url.searchParams.set(key, String(flattened[key]));
20
- }
21
- if (userAttributes) {
22
- url.searchParams.set('userAttributes', JSON.stringify(userAttributes));
23
- }
24
- if (query) {
25
- const flattened = flatten({
26
- query
27
- });
28
- for (const key in flattened) {
29
- url.searchParams.set(key, JSON.stringify(flattened[key]));
30
- }
31
- }
32
- return url;
33
- };
@@ -1,100 +0,0 @@
1
- import { TARGET } from '../../constants/target.js';
2
- import { handleABTesting } from '../../helpers/ab-tests.js';
3
- import { getDefaultCanTrack } from '../../helpers/canTrack.js';
4
- import { logger } from '../../helpers/logger.js';
5
- import { getPreviewContent } from '../../helpers/preview-lru-cache/get.js';
6
- import { fetch } from '../get-fetch.js';
7
- import { isBrowser } from '../is-browser.js';
8
- import { generateContentUrl } from './generate-content-url.js';
9
- const checkContentHasResults = (content) => 'results' in content;
10
- /**
11
- * Returns a the first entry that matches the given options.
12
- */
13
- export async function fetchOneEntry(options) {
14
- const allContent = await fetchEntries({
15
- ...options,
16
- limit: 1
17
- });
18
- if (allContent) {
19
- return allContent.results[0] || null;
20
- }
21
- return null;
22
- }
23
- /**
24
- * @deprecated
25
- * Consider using `fetchBuilderProps` instead for easier setup.
26
- *
27
- * NOTE: `getContent` was renamed to `fetchOneEntry` and will be removed in a future release.
28
- */
29
- export const getContent = fetchOneEntry;
30
- const _fetchContent = async (options) => {
31
- const url = generateContentUrl(options);
32
- const res = await fetch(url.href);
33
- const content = await res.json();
34
- return content;
35
- };
36
- /**
37
- * Exported only for testing purposes. Should not be used directly.
38
- */
39
- export const _processContentResult = async (options, content, url = generateContentUrl(options)) => {
40
- const canTrack = getDefaultCanTrack(options.canTrack);
41
- const isPreviewing = url.search.includes(`preview=`);
42
- if (TARGET === 'rsc' && isPreviewing) {
43
- const newResults = [];
44
- for (const item of content.results) {
45
- const previewContent = getPreviewContent(url.searchParams);
46
- newResults.push(previewContent || item);
47
- }
48
- content.results = newResults;
49
- }
50
- if (!canTrack)
51
- return content;
52
- if (!(isBrowser() || TARGET === 'reactNative'))
53
- return content;
54
- /**
55
- * For client-side navigations, it is ideal to handle AB testing at this point instead of using our
56
- * complex multi-rendering variants approach, which is only needed for SSR'd content.
57
- *
58
- * This is also where react-native would handle AB testing.
59
- */
60
- try {
61
- const newResults = [];
62
- for (const item of content.results) {
63
- newResults.push(await handleABTesting({
64
- item,
65
- canTrack
66
- }));
67
- }
68
- content.results = newResults;
69
- }
70
- catch (e) {
71
- logger.error('Could not process A/B tests. ', e);
72
- }
73
- return content;
74
- };
75
- /**
76
- * Returns a paginated array of entries that match the given options.
77
- */
78
- export async function fetchEntries(options) {
79
- try {
80
- const url = generateContentUrl(options);
81
- const content = await _fetchContent(options);
82
- if (!checkContentHasResults(content)) {
83
- logger.error('Error fetching data. ', {
84
- url,
85
- content,
86
- options
87
- });
88
- return null;
89
- }
90
- return _processContentResult(options, content);
91
- }
92
- catch (error) {
93
- logger.error('Error fetching data. ', error);
94
- return null;
95
- }
96
- }
97
- /**
98
- * @deprecated Use `fetchEntries` instead.
99
- */
100
- export const getAllContent = fetchEntries;
@@ -1 +0,0 @@
1
- export {};
@@ -1,11 +0,0 @@
1
- import { getGlobalThis } from './get-global-this.js';
2
- function getFetch() {
3
- const globalFetch = getGlobalThis().fetch;
4
- if (typeof globalFetch === 'undefined') {
5
- console.warn(`Builder SDK could not find a global fetch function. Make sure you have a polyfill for fetch in your project.
6
- For more information, read https://github.com/BuilderIO/this-package-uses-fetch`);
7
- throw new Error('Builder SDK could not find a global `fetch` function');
8
- }
9
- return globalFetch;
10
- }
11
- export const fetch = getFetch();
@@ -1,15 +0,0 @@
1
- export function getGlobalThis() {
2
- if (typeof globalThis !== 'undefined') {
3
- return globalThis;
4
- }
5
- if (typeof window !== 'undefined') {
6
- return window;
7
- }
8
- if (typeof global !== 'undefined') {
9
- return global;
10
- }
11
- if (typeof self !== 'undefined') {
12
- return self;
13
- }
14
- return globalThis;
15
- }
@@ -1,46 +0,0 @@
1
- import { evaluate } from './evaluate/index.js';
2
- import { fastClone } from './fast-clone.js';
3
- import { set } from './set.js';
4
- import { transformBlock } from './transform-block.js';
5
- const evaluateBindings = ({ block, context, localState, rootState, rootSetState }) => {
6
- if (!block.bindings) {
7
- return block;
8
- }
9
- const copy = fastClone(block);
10
- const copied = {
11
- ...copy,
12
- properties: {
13
- ...copy.properties
14
- },
15
- actions: {
16
- ...copy.actions
17
- }
18
- };
19
- for (const binding in block.bindings) {
20
- const expression = block.bindings[binding];
21
- const value = evaluate({
22
- code: expression,
23
- localState,
24
- rootState,
25
- rootSetState,
26
- context
27
- });
28
- set(copied, binding, value);
29
- }
30
- return copied;
31
- };
32
- export function getProcessedBlock({ block, context, shouldEvaluateBindings, localState, rootState, rootSetState }) {
33
- const transformedBlock = transformBlock(block);
34
- if (shouldEvaluateBindings) {
35
- return evaluateBindings({
36
- block: transformedBlock,
37
- localState,
38
- rootState,
39
- rootSetState,
40
- context
41
- });
42
- }
43
- else {
44
- return transformedBlock;
45
- }
46
- }
@@ -1,17 +0,0 @@
1
- import { sanitizeReactNativeBlockStyles } from './sanitize-react-native-block-styles.js';
2
- export function getReactNativeBlockStyles({ block, context, blockStyles }) {
3
- const responsiveStyles = block.responsiveStyles;
4
- if (!responsiveStyles) {
5
- return {};
6
- }
7
- const styles = {
8
- // recursively apply inherited styles so that they can be passed down to children `Text` blocks
9
- ...context.inheritedStyles,
10
- ...(responsiveStyles.large || {}),
11
- ...(responsiveStyles.medium || {}),
12
- ...(responsiveStyles.small || {}),
13
- ...blockStyles
14
- };
15
- const newStyles = sanitizeReactNativeBlockStyles(styles);
16
- return newStyles;
17
- }
@@ -1,3 +0,0 @@
1
- export function isBrowser() {
2
- return typeof window !== 'undefined' && typeof document !== 'undefined';
3
- }