@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.
package/lib/node/index.js CHANGED
@@ -257,29 +257,6 @@ var parseCode = (code, {
257
257
  const useCode = useReturn ? `return (${code});` : code;
258
258
  return useCode;
259
259
  };
260
-
261
- // src/functions/evaluate/browser-runtime/browser.ts
262
- var runInBrowser = ({
263
- code,
264
- builder,
265
- context,
266
- event,
267
- localState,
268
- rootSetState,
269
- rootState
270
- }) => {
271
- const functionArgs = getFunctionArguments({
272
- builder,
273
- context,
274
- event,
275
- state: flattenState({
276
- rootState,
277
- localState,
278
- rootSetState
279
- })
280
- });
281
- return new Function(...functionArgs.map(([name]) => name), code)(...functionArgs.map(([, value]) => value));
282
- };
283
260
  function flattenState({
284
261
  rootState,
285
262
  localState,
@@ -314,6 +291,29 @@ function flattenState({
314
291
  });
315
292
  }
316
293
 
294
+ // src/functions/evaluate/browser-runtime/browser.ts
295
+ var runInBrowser = ({
296
+ code,
297
+ builder,
298
+ context,
299
+ event,
300
+ localState,
301
+ rootSetState,
302
+ rootState
303
+ }) => {
304
+ const functionArgs = getFunctionArguments({
305
+ builder,
306
+ context,
307
+ event,
308
+ state: flattenState({
309
+ rootState,
310
+ localState,
311
+ rootSetState
312
+ })
313
+ });
314
+ return new Function(...functionArgs.map(([name]) => name), code)(...functionArgs.map(([, value]) => value));
315
+ };
316
+
317
317
  // src/constants/sdk-name.ts
318
318
  var SDK_NAME_FOR_TARGET = (() => {
319
319
  switch (TARGET) {
@@ -405,7 +405,7 @@ if (typeof output === 'object' && output !== null) {
405
405
  };
406
406
  var IVM_INSTANCE = null;
407
407
  var IVM_CONTEXT = null;
408
- var SHOULD_MENTION_INITIALIZE_SCRIPT = SDK_NAME === "@builder.io/sdk-react-nextjs" || SDK_NAME === "@builder.io/sdk-react" || SDK_NAME === "@builder.io/sdk-qwik";
408
+ var 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";
409
409
  var getIvm = () => {
410
410
  try {
411
411
  if (IVM_INSTANCE)
@@ -504,24 +504,30 @@ function isNodeRuntime() {
504
504
  }
505
505
 
506
506
  // src/functions/evaluate/should-force-browser-runtime-in-node.ts
507
- var shouldForceBrowserRuntimeInNode = () => {
507
+ var shouldForceBrowserRuntimeInNode = ({
508
+ shouldLogWarning
509
+ }) => {
508
510
  if (!isNodeRuntime())
509
511
  return false;
510
512
  const isArm64 = process.arch === "arm64";
511
513
  const isNode20 = process.version.startsWith("v20");
512
514
  const hasNoNodeSnapshotNodeOption = process.env.NODE_OPTIONS?.includes("--no-node-snapshot");
513
515
  if (isArm64 && isNode20 && !hasNoNodeSnapshotNodeOption) {
514
- logger.log(`Skipping usage of \`isolated-vm\` to avoid crashes in Node v20 on an arm64 machine.
516
+ if (shouldLogWarning) {
517
+ logger.log(`Skipping usage of \`isolated-vm\` to avoid crashes in Node v20 on an arm64 machine.
515
518
  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.
516
519
  See https://github.com/BuilderIO/builder/blob/main/packages/sdks/README.md#node-v20--m1-macs-apple-silicon-support for more information.
517
520
  `);
521
+ }
518
522
  return true;
519
523
  }
520
524
  return false;
521
525
  };
522
526
 
523
527
  // src/functions/evaluate/choose-eval.ts
524
- var chooseBrowserOrServerEval = (args) => isBrowser() || shouldForceBrowserRuntimeInNode() ? runInBrowser(args) : runInNode(args);
528
+ var chooseBrowserOrServerEval = (args) => isBrowser() || shouldForceBrowserRuntimeInNode({
529
+ shouldLogWarning: true
530
+ }) ? runInBrowser(args) : runInNode(args);
525
531
 
526
532
  // src/functions/evaluate/evaluate.ts
527
533
  var DISABLE_CACHE = true;
@@ -1266,6 +1272,14 @@ function BlockWrapper(props) {
1266
1272
  });
1267
1273
  }
1268
1274
  var block_wrapper_default = BlockWrapper;
1275
+ function Awaiter(props) {
1276
+ onMount(() => {
1277
+ });
1278
+ return memo(() => props.children);
1279
+ }
1280
+ var awaiter_default = Awaiter;
1281
+
1282
+ // src/components/block/components/interactive-element.tsx
1269
1283
  function InteractiveElement(props) {
1270
1284
  const attributes = createMemo(() => {
1271
1285
  return props.includeBlockProps ? {
@@ -1282,17 +1296,43 @@ function InteractiveElement(props) {
1282
1296
  })
1283
1297
  } : {};
1284
1298
  });
1285
- return createComponent(Dynamic, mergeProps(() => props.wrapperProps, {
1286
- get attributes() {
1287
- return attributes();
1299
+ return createComponent(Show, {
1300
+ get fallback() {
1301
+ return createComponent(Dynamic, mergeProps(() => props.wrapperProps, {
1302
+ get attributes() {
1303
+ return attributes();
1304
+ },
1305
+ get component() {
1306
+ return props.Wrapper;
1307
+ },
1308
+ get children() {
1309
+ return props.children;
1310
+ }
1311
+ }));
1288
1312
  },
1289
- get component() {
1290
- return props.Wrapper;
1313
+ get when() {
1314
+ return props.Wrapper.load;
1291
1315
  },
1292
1316
  get children() {
1293
- return props.children;
1317
+ return createComponent(awaiter_default, {
1318
+ get load() {
1319
+ return props.Wrapper.load;
1320
+ },
1321
+ get fallback() {
1322
+ return props.Wrapper.fallback;
1323
+ },
1324
+ get props() {
1325
+ return props.wrapperProps;
1326
+ },
1327
+ get attributes() {
1328
+ return attributes();
1329
+ },
1330
+ get children() {
1331
+ return props.children;
1332
+ }
1333
+ });
1294
1334
  }
1295
- }));
1335
+ });
1296
1336
  }
1297
1337
  var interactive_element_default = InteractiveElement;
1298
1338
 
@@ -1667,7 +1707,7 @@ function Block(props) {
1667
1707
  });
1668
1708
  }
1669
1709
  var block_default = Block;
1670
- var _tmpl$2 = /* @__PURE__ */ template(`<style>.dynamic-4da8c6f4 {
1710
+ var _tmpl$2 = /* @__PURE__ */ template(`<style>.dynamic-68b2d7fe {
1671
1711
  display: flex;
1672
1712
  flex-direction: column;
1673
1713
  align-items: stretch;
@@ -1703,7 +1743,7 @@ function BlocksWrapper(props) {
1703
1743
  });
1704
1744
  return [createComponent(Dynamic, mergeProps({
1705
1745
  get ["class"]() {
1706
- return className() + " dynamic-4da8c6f4";
1746
+ return className() + " dynamic-68b2d7fe";
1707
1747
  },
1708
1748
  ref(r$) {
1709
1749
  const _ref$ = blocksWrapperRef;
@@ -1799,7 +1839,7 @@ var getColumnsClass = (id) => {
1799
1839
 
1800
1840
  // src/blocks/columns/columns.tsx
1801
1841
  var _tmpl$3 = /* @__PURE__ */ template(`<div>`);
1802
- var _tmpl$22 = /* @__PURE__ */ template(`<style>.div-3ff242de {
1842
+ var _tmpl$22 = /* @__PURE__ */ template(`<style>.div-46766f1c {
1803
1843
  display: flex;
1804
1844
  line-height: normal;
1805
1845
  }`);
@@ -1920,7 +1960,7 @@ function Columns(props) {
1920
1960
  const _el$ = _tmpl$3();
1921
1961
  spread(_el$, mergeProps({
1922
1962
  get ["class"]() {
1923
- return getColumnsClass(props.builderBlock?.id) + " div-3ff242de";
1963
+ return getColumnsClass(props.builderBlock?.id) + " div-46766f1c";
1924
1964
  },
1925
1965
  get style() {
1926
1966
  return columnsCssVars();
@@ -2045,16 +2085,16 @@ function getSrcSet(url) {
2045
2085
  // src/blocks/image/image.tsx
2046
2086
  var _tmpl$5 = /* @__PURE__ */ template(`<source type=image/webp>`);
2047
2087
  var _tmpl$23 = /* @__PURE__ */ template(`<picture><img>`);
2048
- var _tmpl$32 = /* @__PURE__ */ template(`<div class="builder-image-sizer div-4512e110">`);
2049
- var _tmpl$42 = /* @__PURE__ */ template(`<div class=div-4512e110-2>`);
2050
- var _tmpl$52 = /* @__PURE__ */ template(`<style>.img-4512e110 {
2088
+ var _tmpl$32 = /* @__PURE__ */ template(`<div class="builder-image-sizer div-7e6ffddc">`);
2089
+ var _tmpl$42 = /* @__PURE__ */ template(`<div class=div-7e6ffddc-2>`);
2090
+ var _tmpl$52 = /* @__PURE__ */ template(`<style>.img-7e6ffddc {
2051
2091
  opacity: 1;
2052
2092
  transition: opacity 0.2s ease-in-out;
2053
- }.div-4512e110 {
2093
+ }.div-7e6ffddc {
2054
2094
  width: 100%;
2055
2095
  pointer-events: none;
2056
2096
  font-size: 0;
2057
- }.div-4512e110-2 {
2097
+ }.div-7e6ffddc-2 {
2058
2098
  display: flex;
2059
2099
  flex-direction: column;
2060
2100
  align-items: stretch;
@@ -2118,7 +2158,7 @@ function Image(props) {
2118
2158
  }
2119
2159
  }), _el$3);
2120
2160
  effect((_p$) => {
2121
- 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 = {
2161
+ 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 = {
2122
2162
  "object-position": props.backgroundPosition || "center",
2123
2163
  "object-fit": props.backgroundSize || "cover",
2124
2164
  ...aspectRatioCss()
@@ -5400,7 +5440,7 @@ function isFromTrustedHost(trustedHosts, e) {
5400
5440
  }
5401
5441
 
5402
5442
  // src/constants/sdk-version.ts
5403
- var SDK_VERSION = "2.0.15";
5443
+ var SDK_VERSION = "2.0.21";
5404
5444
 
5405
5445
  // src/functions/register.ts
5406
5446
  var registry = {};
@@ -5753,22 +5793,6 @@ function EnableEditor(props) {
5753
5793
  }
5754
5794
  })(event);
5755
5795
  }
5756
- function evaluateJsCode() {
5757
- const jsCode = props.builderContextSignal.content?.data?.jsCode;
5758
- if (jsCode) {
5759
- evaluate({
5760
- code: jsCode,
5761
- context: props.context || {},
5762
- localState: void 0,
5763
- rootState: props.builderContextSignal.rootState,
5764
- rootSetState: props.builderContextSignal.rootSetState,
5765
- /**
5766
- * We don't want to cache the result of the JS code, since it's arbitrary side effect code.
5767
- */
5768
- enableCache: false
5769
- });
5770
- }
5771
- }
5772
5796
  function onClick(event) {
5773
5797
  if (props.builderContextSignal.content) {
5774
5798
  const variationId = props.builderContextSignal.content?.testVariationId;
@@ -5805,7 +5829,7 @@ function EnableEditor(props) {
5805
5829
  rootSetState: props.builderContextSignal.rootSetState,
5806
5830
  enableCache: true
5807
5831
  })));
5808
- fetch2(evaluatedUrl).then((response) => response.json()).then((json) => {
5832
+ fetch(evaluatedUrl).then((response) => response.json()).then((json) => {
5809
5833
  mergeNewRootState({
5810
5834
  [key]: json
5811
5835
  });
@@ -5829,6 +5853,8 @@ function EnableEditor(props) {
5829
5853
  }
5830
5854
  }
5831
5855
  let elementRef;
5856
+ runHttpRequests();
5857
+ emitStateUpdate();
5832
5858
  onMount(() => {
5833
5859
  if (isBrowser()) {
5834
5860
  if (isEditing()) {
@@ -5883,14 +5909,6 @@ function EnableEditor(props) {
5883
5909
  }
5884
5910
  }
5885
5911
  });
5886
- onMount(() => {
5887
- if (!props.apiKey) {
5888
- logger.error("No API key provided to `Content` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
5889
- }
5890
- evaluateJsCode();
5891
- runHttpRequests();
5892
- emitStateUpdate();
5893
- });
5894
5912
  const onUpdateFn_0_props_content = createMemo(() => props.content);
5895
5913
  function onUpdateFn_0() {
5896
5914
  if (props.content) {
@@ -5898,37 +5916,27 @@ function EnableEditor(props) {
5898
5916
  }
5899
5917
  }
5900
5918
  createEffect(on(() => [onUpdateFn_0_props_content()], onUpdateFn_0));
5901
- const onUpdateFn_1_props_builderContextSignal_content__data__jsCode = createMemo(() => props.builderContextSignal.content?.data?.jsCode);
5919
+ const onUpdateFn_1_props_builderContextSignal_rootState = createMemo(() => props.builderContextSignal.rootState);
5902
5920
  function onUpdateFn_1() {
5903
- evaluateJsCode();
5904
- }
5905
- createEffect(on(() => [onUpdateFn_1_props_builderContextSignal_content__data__jsCode()], onUpdateFn_1));
5906
- const onUpdateFn_2_props_builderContextSignal_content__data__httpRequests = createMemo(() => props.builderContextSignal.content?.data?.httpRequests);
5907
- function onUpdateFn_2() {
5908
- runHttpRequests();
5909
- }
5910
- createEffect(on(() => [onUpdateFn_2_props_builderContextSignal_content__data__httpRequests()], onUpdateFn_2));
5911
- const onUpdateFn_3_props_builderContextSignal_rootState = createMemo(() => props.builderContextSignal.rootState);
5912
- function onUpdateFn_3() {
5913
5921
  emitStateUpdate();
5914
5922
  }
5915
- createEffect(on(() => [onUpdateFn_3_props_builderContextSignal_rootState()], onUpdateFn_3));
5916
- const onUpdateFn_4_props_data = createMemo(() => props.data);
5917
- function onUpdateFn_4() {
5923
+ createEffect(on(() => [onUpdateFn_1_props_builderContextSignal_rootState()], onUpdateFn_1));
5924
+ const onUpdateFn_2_props_data = createMemo(() => props.data);
5925
+ function onUpdateFn_2() {
5918
5926
  if (props.data) {
5919
5927
  mergeNewRootState(props.data);
5920
5928
  }
5921
5929
  }
5922
- createEffect(on(() => [onUpdateFn_4_props_data()], onUpdateFn_4));
5923
- const onUpdateFn_5_props_locale = createMemo(() => props.locale);
5924
- function onUpdateFn_5() {
5930
+ createEffect(on(() => [onUpdateFn_2_props_data()], onUpdateFn_2));
5931
+ const onUpdateFn_3_props_locale = createMemo(() => props.locale);
5932
+ function onUpdateFn_3() {
5925
5933
  if (props.locale) {
5926
5934
  mergeNewRootState({
5927
5935
  locale: props.locale
5928
5936
  });
5929
5937
  }
5930
5938
  }
5931
- createEffect(on(() => [onUpdateFn_5_props_locale()], onUpdateFn_5));
5939
+ createEffect(on(() => [onUpdateFn_3_props_locale()], onUpdateFn_3));
5932
5940
  return createComponent(builder_context_default.Provider, {
5933
5941
  get value() {
5934
5942
  return props.builderContextSignal;
@@ -6096,6 +6104,29 @@ function ContentComponent(props) {
6096
6104
  rootState: newRootState
6097
6105
  }));
6098
6106
  }
6107
+ if (!props.apiKey) {
6108
+ logger.error("No API key provided to `Content` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
6109
+ }
6110
+ const jsCode = builderContextSignal().content?.data?.jsCode;
6111
+ if (jsCode) {
6112
+ evaluate({
6113
+ code: jsCode,
6114
+ context: props.context || {},
6115
+ localState: void 0,
6116
+ rootState: builderContextSignal().rootState,
6117
+ rootSetState: (newState) => {
6118
+ setBuilderContextSignal((PREVIOUS_VALUE) => ({
6119
+ ...PREVIOUS_VALUE,
6120
+ rootState: newState
6121
+ }));
6122
+ },
6123
+ isExpression: false,
6124
+ /**
6125
+ * We don't want to cache the result of the JS code, since it's arbitrary side effect code.
6126
+ */
6127
+ enableCache: false
6128
+ });
6129
+ }
6099
6130
  return createComponent(components_context_default.Provider, {
6100
6131
  get value() {
6101
6132
  return {