@builder.io/sdk-solid 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.
@@ -255,29 +255,6 @@ var parseCode = (code, {
255
255
  const useCode = useReturn ? `return (${code});` : code;
256
256
  return useCode;
257
257
  };
258
-
259
- // src/functions/evaluate/browser-runtime/browser.ts
260
- var runInBrowser = ({
261
- code,
262
- builder,
263
- context,
264
- event,
265
- localState,
266
- rootSetState,
267
- rootState
268
- }) => {
269
- const functionArgs = getFunctionArguments({
270
- builder,
271
- context,
272
- event,
273
- state: flattenState({
274
- rootState,
275
- localState,
276
- rootSetState
277
- })
278
- });
279
- return new Function(...functionArgs.map(([name]) => name), code)(...functionArgs.map(([, value]) => value));
280
- };
281
258
  function flattenState({
282
259
  rootState,
283
260
  localState,
@@ -312,6 +289,29 @@ function flattenState({
312
289
  });
313
290
  }
314
291
 
292
+ // src/functions/evaluate/browser-runtime/browser.ts
293
+ var runInBrowser = ({
294
+ code,
295
+ builder,
296
+ context,
297
+ event,
298
+ localState,
299
+ rootSetState,
300
+ rootState
301
+ }) => {
302
+ const functionArgs = getFunctionArguments({
303
+ builder,
304
+ context,
305
+ event,
306
+ state: flattenState({
307
+ rootState,
308
+ localState,
309
+ rootSetState
310
+ })
311
+ });
312
+ return new Function(...functionArgs.map(([name]) => name), code)(...functionArgs.map(([, value]) => value));
313
+ };
314
+
315
315
  // src/helpers/nullable.ts
316
316
  var checkIsDefined = (maybeT) => maybeT !== null && maybeT !== void 0;
317
317
 
@@ -321,24 +321,30 @@ function isNodeRuntime() {
321
321
  }
322
322
 
323
323
  // src/functions/evaluate/should-force-browser-runtime-in-node.ts
324
- var shouldForceBrowserRuntimeInNode = () => {
324
+ var shouldForceBrowserRuntimeInNode = ({
325
+ shouldLogWarning
326
+ }) => {
325
327
  if (!isNodeRuntime())
326
328
  return false;
327
329
  const isArm64 = process.arch === "arm64";
328
330
  const isNode20 = process.version.startsWith("v20");
329
331
  const hasNoNodeSnapshotNodeOption = process.env.NODE_OPTIONS?.includes("--no-node-snapshot");
330
332
  if (isArm64 && isNode20 && !hasNoNodeSnapshotNodeOption) {
331
- logger.log(`Skipping usage of \`isolated-vm\` to avoid crashes in Node v20 on an arm64 machine.
333
+ if (shouldLogWarning) {
334
+ logger.log(`Skipping usage of \`isolated-vm\` to avoid crashes in Node v20 on an arm64 machine.
332
335
  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.
333
336
  See https://github.com/BuilderIO/builder/blob/main/packages/sdks/README.md#node-v20--m1-macs-apple-silicon-support for more information.
334
337
  `);
338
+ }
335
339
  return true;
336
340
  }
337
341
  return false;
338
342
  };
339
343
 
340
344
  // src/functions/evaluate/choose-eval.ts
341
- var chooseBrowserOrServerEval = (args) => isBrowser() || shouldForceBrowserRuntimeInNode() ? runInBrowser(args) : runInBrowser(args);
345
+ var chooseBrowserOrServerEval = (args) => isBrowser() || shouldForceBrowserRuntimeInNode({
346
+ shouldLogWarning: true
347
+ }) ? runInBrowser(args) : runInBrowser(args);
342
348
 
343
349
  // src/functions/evaluate/evaluate.ts
344
350
  var DISABLE_CACHE = true;
@@ -1096,6 +1102,14 @@ function BlockWrapper(props) {
1096
1102
  });
1097
1103
  }
1098
1104
  var block_wrapper_default = BlockWrapper;
1105
+ function Awaiter(props) {
1106
+ onMount(() => {
1107
+ });
1108
+ return memo(() => props.children);
1109
+ }
1110
+ var awaiter_default = Awaiter;
1111
+
1112
+ // src/components/block/components/interactive-element.tsx
1099
1113
  function InteractiveElement(props) {
1100
1114
  const attributes = createMemo(() => {
1101
1115
  return props.includeBlockProps ? {
@@ -1112,17 +1126,43 @@ function InteractiveElement(props) {
1112
1126
  })
1113
1127
  } : {};
1114
1128
  });
1115
- return createComponent(Dynamic, mergeProps(() => props.wrapperProps, {
1116
- get attributes() {
1117
- return attributes();
1129
+ return createComponent(Show, {
1130
+ get fallback() {
1131
+ return createComponent(Dynamic, mergeProps(() => props.wrapperProps, {
1132
+ get attributes() {
1133
+ return attributes();
1134
+ },
1135
+ get component() {
1136
+ return props.Wrapper;
1137
+ },
1138
+ get children() {
1139
+ return props.children;
1140
+ }
1141
+ }));
1118
1142
  },
1119
- get component() {
1120
- return props.Wrapper;
1143
+ get when() {
1144
+ return props.Wrapper.load;
1121
1145
  },
1122
1146
  get children() {
1123
- return props.children;
1147
+ return createComponent(awaiter_default, {
1148
+ get load() {
1149
+ return props.Wrapper.load;
1150
+ },
1151
+ get fallback() {
1152
+ return props.Wrapper.fallback;
1153
+ },
1154
+ get props() {
1155
+ return props.wrapperProps;
1156
+ },
1157
+ get attributes() {
1158
+ return attributes();
1159
+ },
1160
+ get children() {
1161
+ return props.children;
1162
+ }
1163
+ });
1124
1164
  }
1125
- }));
1165
+ });
1126
1166
  }
1127
1167
  var interactive_element_default = InteractiveElement;
1128
1168
 
@@ -1497,7 +1537,7 @@ function Block(props) {
1497
1537
  });
1498
1538
  }
1499
1539
  var block_default = Block;
1500
- var _tmpl$2 = /* @__PURE__ */ template(`<style>.dynamic-4da8c6f4 {
1540
+ var _tmpl$2 = /* @__PURE__ */ template(`<style>.dynamic-68b2d7fe {
1501
1541
  display: flex;
1502
1542
  flex-direction: column;
1503
1543
  align-items: stretch;
@@ -1533,7 +1573,7 @@ function BlocksWrapper(props) {
1533
1573
  });
1534
1574
  return [createComponent(Dynamic, mergeProps({
1535
1575
  get ["class"]() {
1536
- return className() + " dynamic-4da8c6f4";
1576
+ return className() + " dynamic-68b2d7fe";
1537
1577
  },
1538
1578
  ref(r$) {
1539
1579
  const _ref$ = blocksWrapperRef;
@@ -1629,7 +1669,7 @@ var getColumnsClass = (id) => {
1629
1669
 
1630
1670
  // src/blocks/columns/columns.tsx
1631
1671
  var _tmpl$3 = /* @__PURE__ */ template(`<div>`);
1632
- var _tmpl$22 = /* @__PURE__ */ template(`<style>.div-3ff242de {
1672
+ var _tmpl$22 = /* @__PURE__ */ template(`<style>.div-46766f1c {
1633
1673
  display: flex;
1634
1674
  line-height: normal;
1635
1675
  }`);
@@ -1750,7 +1790,7 @@ function Columns(props) {
1750
1790
  const _el$ = _tmpl$3();
1751
1791
  spread(_el$, mergeProps({
1752
1792
  get ["class"]() {
1753
- return getColumnsClass(props.builderBlock?.id) + " div-3ff242de";
1793
+ return getColumnsClass(props.builderBlock?.id) + " div-46766f1c";
1754
1794
  },
1755
1795
  get style() {
1756
1796
  return columnsCssVars();
@@ -1875,16 +1915,16 @@ function getSrcSet(url) {
1875
1915
  // src/blocks/image/image.tsx
1876
1916
  var _tmpl$5 = /* @__PURE__ */ template(`<source type=image/webp>`);
1877
1917
  var _tmpl$23 = /* @__PURE__ */ template(`<picture><img>`);
1878
- var _tmpl$32 = /* @__PURE__ */ template(`<div class="builder-image-sizer div-4512e110">`);
1879
- var _tmpl$42 = /* @__PURE__ */ template(`<div class=div-4512e110-2>`);
1880
- var _tmpl$52 = /* @__PURE__ */ template(`<style>.img-4512e110 {
1918
+ var _tmpl$32 = /* @__PURE__ */ template(`<div class="builder-image-sizer div-7e6ffddc">`);
1919
+ var _tmpl$42 = /* @__PURE__ */ template(`<div class=div-7e6ffddc-2>`);
1920
+ var _tmpl$52 = /* @__PURE__ */ template(`<style>.img-7e6ffddc {
1881
1921
  opacity: 1;
1882
1922
  transition: opacity 0.2s ease-in-out;
1883
- }.div-4512e110 {
1923
+ }.div-7e6ffddc {
1884
1924
  width: 100%;
1885
1925
  pointer-events: none;
1886
1926
  font-size: 0;
1887
- }.div-4512e110-2 {
1927
+ }.div-7e6ffddc-2 {
1888
1928
  display: flex;
1889
1929
  flex-direction: column;
1890
1930
  align-items: stretch;
@@ -1948,7 +1988,7 @@ function Image(props) {
1948
1988
  }
1949
1989
  }), _el$3);
1950
1990
  effect((_p$) => {
1951
- const _v$ = "builder-image" + (props.className ? " " + props.className : "") + " img-4512e110", _v$2 = props.highPriority ? "eager" : "lazy", _v$3 = props.highPriority ? "high" : "auto", _v$4 = props.altText, _v$5 = props.altText ? void 0 : "presentation", _v$6 = {
1991
+ const _v$ = "builder-image" + (props.className ? " " + props.className : "") + " img-7e6ffddc", _v$2 = props.highPriority ? "eager" : "lazy", _v$3 = props.highPriority ? "high" : "auto", _v$4 = props.altText, _v$5 = props.altText ? void 0 : "presentation", _v$6 = {
1952
1992
  "object-position": props.backgroundPosition || "center",
1953
1993
  "object-fit": props.backgroundSize || "cover",
1954
1994
  ...aspectRatioCss()
@@ -5230,7 +5270,7 @@ function isFromTrustedHost(trustedHosts, e) {
5230
5270
  }
5231
5271
 
5232
5272
  // src/constants/sdk-version.ts
5233
- var SDK_VERSION = "2.0.15";
5273
+ var SDK_VERSION = "2.0.21";
5234
5274
 
5235
5275
  // src/functions/register.ts
5236
5276
  var registry = {};
@@ -5583,22 +5623,6 @@ function EnableEditor(props) {
5583
5623
  }
5584
5624
  })(event);
5585
5625
  }
5586
- function evaluateJsCode() {
5587
- const jsCode = props.builderContextSignal.content?.data?.jsCode;
5588
- if (jsCode) {
5589
- evaluate({
5590
- code: jsCode,
5591
- context: props.context || {},
5592
- localState: void 0,
5593
- rootState: props.builderContextSignal.rootState,
5594
- rootSetState: props.builderContextSignal.rootSetState,
5595
- /**
5596
- * We don't want to cache the result of the JS code, since it's arbitrary side effect code.
5597
- */
5598
- enableCache: false
5599
- });
5600
- }
5601
- }
5602
5626
  function onClick(event) {
5603
5627
  if (props.builderContextSignal.content) {
5604
5628
  const variationId = props.builderContextSignal.content?.testVariationId;
@@ -5635,7 +5659,7 @@ function EnableEditor(props) {
5635
5659
  rootSetState: props.builderContextSignal.rootSetState,
5636
5660
  enableCache: true
5637
5661
  })));
5638
- fetch2(evaluatedUrl).then((response) => response.json()).then((json) => {
5662
+ fetch(evaluatedUrl).then((response) => response.json()).then((json) => {
5639
5663
  mergeNewRootState({
5640
5664
  [key]: json
5641
5665
  });
@@ -5659,6 +5683,8 @@ function EnableEditor(props) {
5659
5683
  }
5660
5684
  }
5661
5685
  let elementRef;
5686
+ runHttpRequests();
5687
+ emitStateUpdate();
5662
5688
  onMount(() => {
5663
5689
  if (isBrowser()) {
5664
5690
  if (isEditing()) {
@@ -5713,14 +5739,6 @@ function EnableEditor(props) {
5713
5739
  }
5714
5740
  }
5715
5741
  });
5716
- onMount(() => {
5717
- if (!props.apiKey) {
5718
- logger.error("No API key provided to `Content` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
5719
- }
5720
- evaluateJsCode();
5721
- runHttpRequests();
5722
- emitStateUpdate();
5723
- });
5724
5742
  const onUpdateFn_0_props_content = createMemo(() => props.content);
5725
5743
  function onUpdateFn_0() {
5726
5744
  if (props.content) {
@@ -5728,37 +5746,27 @@ function EnableEditor(props) {
5728
5746
  }
5729
5747
  }
5730
5748
  createEffect(on(() => [onUpdateFn_0_props_content()], onUpdateFn_0));
5731
- const onUpdateFn_1_props_builderContextSignal_content__data__jsCode = createMemo(() => props.builderContextSignal.content?.data?.jsCode);
5749
+ const onUpdateFn_1_props_builderContextSignal_rootState = createMemo(() => props.builderContextSignal.rootState);
5732
5750
  function onUpdateFn_1() {
5733
- evaluateJsCode();
5734
- }
5735
- createEffect(on(() => [onUpdateFn_1_props_builderContextSignal_content__data__jsCode()], onUpdateFn_1));
5736
- const onUpdateFn_2_props_builderContextSignal_content__data__httpRequests = createMemo(() => props.builderContextSignal.content?.data?.httpRequests);
5737
- function onUpdateFn_2() {
5738
- runHttpRequests();
5739
- }
5740
- createEffect(on(() => [onUpdateFn_2_props_builderContextSignal_content__data__httpRequests()], onUpdateFn_2));
5741
- const onUpdateFn_3_props_builderContextSignal_rootState = createMemo(() => props.builderContextSignal.rootState);
5742
- function onUpdateFn_3() {
5743
5751
  emitStateUpdate();
5744
5752
  }
5745
- createEffect(on(() => [onUpdateFn_3_props_builderContextSignal_rootState()], onUpdateFn_3));
5746
- const onUpdateFn_4_props_data = createMemo(() => props.data);
5747
- function onUpdateFn_4() {
5753
+ createEffect(on(() => [onUpdateFn_1_props_builderContextSignal_rootState()], onUpdateFn_1));
5754
+ const onUpdateFn_2_props_data = createMemo(() => props.data);
5755
+ function onUpdateFn_2() {
5748
5756
  if (props.data) {
5749
5757
  mergeNewRootState(props.data);
5750
5758
  }
5751
5759
  }
5752
- createEffect(on(() => [onUpdateFn_4_props_data()], onUpdateFn_4));
5753
- const onUpdateFn_5_props_locale = createMemo(() => props.locale);
5754
- function onUpdateFn_5() {
5760
+ createEffect(on(() => [onUpdateFn_2_props_data()], onUpdateFn_2));
5761
+ const onUpdateFn_3_props_locale = createMemo(() => props.locale);
5762
+ function onUpdateFn_3() {
5755
5763
  if (props.locale) {
5756
5764
  mergeNewRootState({
5757
5765
  locale: props.locale
5758
5766
  });
5759
5767
  }
5760
5768
  }
5761
- createEffect(on(() => [onUpdateFn_5_props_locale()], onUpdateFn_5));
5769
+ createEffect(on(() => [onUpdateFn_3_props_locale()], onUpdateFn_3));
5762
5770
  return createComponent(builder_context_default.Provider, {
5763
5771
  get value() {
5764
5772
  return props.builderContextSignal;
@@ -5926,6 +5934,29 @@ function ContentComponent(props) {
5926
5934
  rootState: newRootState
5927
5935
  }));
5928
5936
  }
5937
+ if (!props.apiKey) {
5938
+ logger.error("No API key provided to `Content` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
5939
+ }
5940
+ const jsCode = builderContextSignal().content?.data?.jsCode;
5941
+ if (jsCode) {
5942
+ evaluate({
5943
+ code: jsCode,
5944
+ context: props.context || {},
5945
+ localState: void 0,
5946
+ rootState: builderContextSignal().rootState,
5947
+ rootSetState: (newState) => {
5948
+ setBuilderContextSignal((PREVIOUS_VALUE) => ({
5949
+ ...PREVIOUS_VALUE,
5950
+ rootState: newState
5951
+ }));
5952
+ },
5953
+ isExpression: false,
5954
+ /**
5955
+ * We don't want to cache the result of the JS code, since it's arbitrary side effect code.
5956
+ */
5957
+ enableCache: false
5958
+ });
5959
+ }
5929
5960
  return createComponent(components_context_default.Provider, {
5930
5961
  get value() {
5931
5962
  return {