@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/edge/index.js CHANGED
@@ -261,29 +261,6 @@ var parseCode = (code, {
261
261
  const useCode = useReturn ? `return (${code});` : code;
262
262
  return useCode;
263
263
  };
264
-
265
- // src/functions/evaluate/browser-runtime/browser.ts
266
- var runInBrowser = ({
267
- code,
268
- builder,
269
- context,
270
- event,
271
- localState,
272
- rootSetState,
273
- rootState
274
- }) => {
275
- const functionArgs = getFunctionArguments({
276
- builder,
277
- context,
278
- event,
279
- state: flattenState({
280
- rootState,
281
- localState,
282
- rootSetState
283
- })
284
- });
285
- return new Function(...functionArgs.map(([name]) => name), code)(...functionArgs.map(([, value]) => value));
286
- };
287
264
  function flattenState({
288
265
  rootState,
289
266
  localState,
@@ -318,14 +295,27 @@ function flattenState({
318
295
  });
319
296
  }
320
297
 
321
- // src/functions/set.ts
322
- var set = (obj, _path, value) => {
323
- if (Object(obj) !== obj) {
324
- return obj;
325
- }
326
- const path = Array.isArray(_path) ? _path : _path.toString().match(/[^.[\]]+/g);
327
- path.slice(0, -1).reduce((a, c, i) => Object(a[c]) === a[c] ? a[c] : a[c] = Math.abs(Number(path[i + 1])) >> 0 === +path[i + 1] ? [] : {}, obj)[path[path.length - 1]] = value;
328
- return obj;
298
+ // src/functions/evaluate/browser-runtime/browser.ts
299
+ var runInBrowser = ({
300
+ code,
301
+ builder,
302
+ context,
303
+ event,
304
+ localState,
305
+ rootSetState,
306
+ rootState
307
+ }) => {
308
+ const functionArgs = getFunctionArguments({
309
+ builder,
310
+ context,
311
+ event,
312
+ state: flattenState({
313
+ rootState,
314
+ localState,
315
+ rootSetState
316
+ })
317
+ });
318
+ return new Function(...functionArgs.map(([name]) => name), code)(...functionArgs.map(([, value]) => value));
329
319
  };
330
320
 
331
321
  // src/functions/evaluate/edge-runtime/acorn-interpreter.ts
@@ -3397,22 +3387,56 @@ t.VALUE_IN_DESCRIPTOR = Ia;
3397
3387
  var acorn_interpreter_default = t;
3398
3388
 
3399
3389
  // src/functions/evaluate/edge-runtime/edge-runtime.ts
3390
+ function patchInterpreter() {
3391
+ const originalGetProperty = acorn_interpreter_default.prototype.getProperty;
3392
+ const originalSetProperty = acorn_interpreter_default.prototype.setProperty;
3393
+ function newGetProperty(obj, name) {
3394
+ if (obj == null || !obj._connected) {
3395
+ return originalGetProperty.call(this, obj, name);
3396
+ }
3397
+ const value = obj._connected[name];
3398
+ if (Array.isArray(value)) {
3399
+ return this.nativeToPseudo(value);
3400
+ }
3401
+ if (typeof value === "object") {
3402
+ return this.createConnectedObject(value);
3403
+ }
3404
+ return value;
3405
+ }
3406
+ function newSetProperty(obj, name, value, opt_descriptor) {
3407
+ if (obj == null || !obj._connected) {
3408
+ return originalSetProperty.call(this, obj, name, value, opt_descriptor);
3409
+ }
3410
+ obj._connected[name] = this.pseudoToNative(value);
3411
+ }
3412
+ const getKeys = [];
3413
+ const setKeys = [];
3414
+ for (const key of Object.keys(acorn_interpreter_default.prototype)) {
3415
+ if (acorn_interpreter_default.prototype[key] === originalGetProperty) {
3416
+ getKeys.push(key);
3417
+ }
3418
+ if (acorn_interpreter_default.prototype[key] === originalSetProperty) {
3419
+ setKeys.push(key);
3420
+ }
3421
+ }
3422
+ for (const key of getKeys) {
3423
+ acorn_interpreter_default.prototype[key] = newGetProperty;
3424
+ }
3425
+ for (const key of setKeys) {
3426
+ acorn_interpreter_default.prototype[key] = newSetProperty;
3427
+ }
3428
+ acorn_interpreter_default.prototype.createConnectedObject = function(obj) {
3429
+ const connectedObject = this.createObject(this.OBJECT);
3430
+ connectedObject._connected = obj;
3431
+ return connectedObject;
3432
+ };
3433
+ }
3434
+ patchInterpreter();
3400
3435
  var processCode = (code) => {
3401
- return code.split("\n").map((line) => {
3402
- const trimmed = line.trim();
3403
- if (line.includes("__awaiter"))
3404
- return void 0;
3405
- const isStateSetter = trimmed.startsWith("state.");
3406
- if (!isStateSetter)
3407
- return line;
3408
- const [lhs, rhs] = trimmed.split("=");
3409
- const setStr = lhs.replace("state.", "").trim();
3410
- const setExpr = `setRootState('${setStr}', ${rhs.trim()})`;
3411
- return `
3412
- ${line}
3413
- ${setExpr}
3414
- `;
3415
- }).filter(Boolean).join("\n");
3436
+ return code.replace(/^.*?function main\(\)/, `
3437
+ var __awaiter = function (e, t, n, r) {return r()},
3438
+ __generator = function (e, t) { return t() };
3439
+ function main()`).replace(/\?\./g, ".");
3416
3440
  };
3417
3441
  var getJSONValName = (val) => val + "JSON";
3418
3442
  var runInEdge = ({
@@ -3424,10 +3448,11 @@ var runInEdge = ({
3424
3448
  rootSetState,
3425
3449
  code
3426
3450
  }) => {
3427
- const state = {
3428
- ...rootState,
3429
- ...localState
3430
- };
3451
+ const state = flattenState({
3452
+ rootState,
3453
+ localState,
3454
+ rootSetState
3455
+ });
3431
3456
  const properties = getFunctionArguments({
3432
3457
  builder,
3433
3458
  context,
@@ -3436,6 +3461,9 @@ var runInEdge = ({
3436
3461
  });
3437
3462
  const prependedCode = properties.map(([key]) => {
3438
3463
  const jsonValName = getJSONValName(key);
3464
+ if (key === "state") {
3465
+ return ``;
3466
+ }
3439
3467
  return `var ${key} = ${jsonValName} === undefined ? undefined : JSON.parse(${jsonValName});`;
3440
3468
  }).join("\n");
3441
3469
  const cleanedCode = processCode(code);
@@ -3451,16 +3479,15 @@ function theFunction() {
3451
3479
  }
3452
3480
  theFunction();
3453
3481
  `;
3454
- const setRootState = (prop, value) => {
3455
- const newState = set(state, prop, value);
3456
- rootSetState?.(newState);
3457
- };
3458
3482
  const initFunc = function(interpreter, globalObject) {
3459
3483
  properties.forEach(([key, val]) => {
3460
- const jsonVal = JSON.stringify(val);
3461
- interpreter.setProperty(globalObject, getJSONValName(key), jsonVal);
3484
+ if (key === "state") {
3485
+ interpreter.setProperty(globalObject, key, interpreter.createConnectedObject(val), interpreter.READONLY_DESCRIPTOR);
3486
+ } else {
3487
+ const jsonVal = JSON.stringify(val);
3488
+ interpreter.setProperty(globalObject, getJSONValName(key), jsonVal);
3489
+ }
3462
3490
  });
3463
- interpreter.setProperty(globalObject, "setRootState", interpreter.createNativeFunction(setRootState));
3464
3491
  };
3465
3492
  const myInterpreter = new acorn_interpreter_default(transformed, initFunc);
3466
3493
  myInterpreter.run();
@@ -3477,24 +3504,30 @@ function isNodeRuntime() {
3477
3504
  }
3478
3505
 
3479
3506
  // src/functions/evaluate/should-force-browser-runtime-in-node.ts
3480
- var shouldForceBrowserRuntimeInNode = () => {
3507
+ var shouldForceBrowserRuntimeInNode = ({
3508
+ shouldLogWarning
3509
+ }) => {
3481
3510
  if (!isNodeRuntime())
3482
3511
  return false;
3483
3512
  const isArm64 = process.arch === "arm64";
3484
3513
  const isNode20 = process.version.startsWith("v20");
3485
3514
  const hasNoNodeSnapshotNodeOption = process.env.NODE_OPTIONS?.includes("--no-node-snapshot");
3486
3515
  if (isArm64 && isNode20 && !hasNoNodeSnapshotNodeOption) {
3487
- logger.log(`Skipping usage of \`isolated-vm\` to avoid crashes in Node v20 on an arm64 machine.
3516
+ if (shouldLogWarning) {
3517
+ logger.log(`Skipping usage of \`isolated-vm\` to avoid crashes in Node v20 on an arm64 machine.
3488
3518
  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.
3489
3519
  See https://github.com/BuilderIO/builder/blob/main/packages/sdks/README.md#node-v20--m1-macs-apple-silicon-support for more information.
3490
3520
  `);
3521
+ }
3491
3522
  return true;
3492
3523
  }
3493
3524
  return false;
3494
3525
  };
3495
3526
 
3496
3527
  // src/functions/evaluate/choose-eval.ts
3497
- var chooseBrowserOrServerEval = (args) => isBrowser() || shouldForceBrowserRuntimeInNode() ? runInBrowser(args) : runInEdge(args);
3528
+ var chooseBrowserOrServerEval = (args) => isBrowser() || shouldForceBrowserRuntimeInNode({
3529
+ shouldLogWarning: true
3530
+ }) ? runInBrowser(args) : runInEdge(args);
3498
3531
 
3499
3532
  // src/functions/evaluate/evaluate.ts
3500
3533
  var DISABLE_CACHE = true;
@@ -3571,6 +3604,16 @@ function evaluate({
3571
3604
  // src/functions/fast-clone.ts
3572
3605
  var fastClone = (obj) => JSON.parse(JSON.stringify(obj));
3573
3606
 
3607
+ // src/functions/set.ts
3608
+ var set = (obj, _path, value) => {
3609
+ if (Object(obj) !== obj) {
3610
+ return obj;
3611
+ }
3612
+ const path = Array.isArray(_path) ? _path : _path.toString().match(/[^.[\]]+/g);
3613
+ path.slice(0, -1).reduce((a, c, i) => Object(a[c]) === a[c] ? a[c] : a[c] = Math.abs(Number(path[i + 1])) >> 0 === +path[i + 1] ? [] : {}, obj)[path[path.length - 1]] = value;
3614
+ return obj;
3615
+ };
3616
+
3574
3617
  // src/functions/transform-block.ts
3575
3618
  function transformBlock(block) {
3576
3619
  return block;
@@ -4242,6 +4285,14 @@ function BlockWrapper(props) {
4242
4285
  });
4243
4286
  }
4244
4287
  var block_wrapper_default = BlockWrapper;
4288
+ function Awaiter(props) {
4289
+ onMount(() => {
4290
+ });
4291
+ return memo(() => props.children);
4292
+ }
4293
+ var awaiter_default = Awaiter;
4294
+
4295
+ // src/components/block/components/interactive-element.tsx
4245
4296
  function InteractiveElement(props) {
4246
4297
  const attributes = createMemo(() => {
4247
4298
  return props.includeBlockProps ? {
@@ -4258,17 +4309,43 @@ function InteractiveElement(props) {
4258
4309
  })
4259
4310
  } : {};
4260
4311
  });
4261
- return createComponent(Dynamic, mergeProps(() => props.wrapperProps, {
4262
- get attributes() {
4263
- return attributes();
4312
+ return createComponent(Show, {
4313
+ get fallback() {
4314
+ return createComponent(Dynamic, mergeProps(() => props.wrapperProps, {
4315
+ get attributes() {
4316
+ return attributes();
4317
+ },
4318
+ get component() {
4319
+ return props.Wrapper;
4320
+ },
4321
+ get children() {
4322
+ return props.children;
4323
+ }
4324
+ }));
4264
4325
  },
4265
- get component() {
4266
- return props.Wrapper;
4326
+ get when() {
4327
+ return props.Wrapper.load;
4267
4328
  },
4268
4329
  get children() {
4269
- return props.children;
4330
+ return createComponent(awaiter_default, {
4331
+ get load() {
4332
+ return props.Wrapper.load;
4333
+ },
4334
+ get fallback() {
4335
+ return props.Wrapper.fallback;
4336
+ },
4337
+ get props() {
4338
+ return props.wrapperProps;
4339
+ },
4340
+ get attributes() {
4341
+ return attributes();
4342
+ },
4343
+ get children() {
4344
+ return props.children;
4345
+ }
4346
+ });
4270
4347
  }
4271
- }));
4348
+ });
4272
4349
  }
4273
4350
  var interactive_element_default = InteractiveElement;
4274
4351
 
@@ -4643,7 +4720,7 @@ function Block(props) {
4643
4720
  });
4644
4721
  }
4645
4722
  var block_default = Block;
4646
- var _tmpl$2 = /* @__PURE__ */ template(`<style>.dynamic-4da8c6f4 {
4723
+ var _tmpl$2 = /* @__PURE__ */ template(`<style>.dynamic-68b2d7fe {
4647
4724
  display: flex;
4648
4725
  flex-direction: column;
4649
4726
  align-items: stretch;
@@ -4679,7 +4756,7 @@ function BlocksWrapper(props) {
4679
4756
  });
4680
4757
  return [createComponent(Dynamic, mergeProps({
4681
4758
  get ["class"]() {
4682
- return className() + " dynamic-4da8c6f4";
4759
+ return className() + " dynamic-68b2d7fe";
4683
4760
  },
4684
4761
  ref(r$) {
4685
4762
  const _ref$ = blocksWrapperRef;
@@ -4775,7 +4852,7 @@ var getColumnsClass = (id2) => {
4775
4852
 
4776
4853
  // src/blocks/columns/columns.tsx
4777
4854
  var _tmpl$3 = /* @__PURE__ */ template(`<div>`);
4778
- var _tmpl$22 = /* @__PURE__ */ template(`<style>.div-3ff242de {
4855
+ var _tmpl$22 = /* @__PURE__ */ template(`<style>.div-46766f1c {
4779
4856
  display: flex;
4780
4857
  line-height: normal;
4781
4858
  }`);
@@ -4896,7 +4973,7 @@ function Columns(props) {
4896
4973
  const _el$ = _tmpl$3();
4897
4974
  spread(_el$, mergeProps({
4898
4975
  get ["class"]() {
4899
- return getColumnsClass(props.builderBlock?.id) + " div-3ff242de";
4976
+ return getColumnsClass(props.builderBlock?.id) + " div-46766f1c";
4900
4977
  },
4901
4978
  get style() {
4902
4979
  return columnsCssVars();
@@ -5021,16 +5098,16 @@ function getSrcSet(url) {
5021
5098
  // src/blocks/image/image.tsx
5022
5099
  var _tmpl$5 = /* @__PURE__ */ template(`<source type=image/webp>`);
5023
5100
  var _tmpl$23 = /* @__PURE__ */ template(`<picture><img>`);
5024
- var _tmpl$32 = /* @__PURE__ */ template(`<div class="builder-image-sizer div-4512e110">`);
5025
- var _tmpl$42 = /* @__PURE__ */ template(`<div class=div-4512e110-2>`);
5026
- var _tmpl$52 = /* @__PURE__ */ template(`<style>.img-4512e110 {
5101
+ var _tmpl$32 = /* @__PURE__ */ template(`<div class="builder-image-sizer div-7e6ffddc">`);
5102
+ var _tmpl$42 = /* @__PURE__ */ template(`<div class=div-7e6ffddc-2>`);
5103
+ var _tmpl$52 = /* @__PURE__ */ template(`<style>.img-7e6ffddc {
5027
5104
  opacity: 1;
5028
5105
  transition: opacity 0.2s ease-in-out;
5029
- }.div-4512e110 {
5106
+ }.div-7e6ffddc {
5030
5107
  width: 100%;
5031
5108
  pointer-events: none;
5032
5109
  font-size: 0;
5033
- }.div-4512e110-2 {
5110
+ }.div-7e6ffddc-2 {
5034
5111
  display: flex;
5035
5112
  flex-direction: column;
5036
5113
  align-items: stretch;
@@ -5094,7 +5171,7 @@ function Image(props) {
5094
5171
  }
5095
5172
  }), _el$3);
5096
5173
  effect((_p$) => {
5097
- 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 = {
5174
+ 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 = {
5098
5175
  "object-position": props.backgroundPosition || "center",
5099
5176
  "object-fit": props.backgroundSize || "cover",
5100
5177
  ...aspectRatioCss()
@@ -8376,7 +8453,7 @@ function isFromTrustedHost(trustedHosts, e) {
8376
8453
  }
8377
8454
 
8378
8455
  // src/constants/sdk-version.ts
8379
- var SDK_VERSION = "2.0.15";
8456
+ var SDK_VERSION = "2.0.21";
8380
8457
 
8381
8458
  // src/functions/register.ts
8382
8459
  var registry = {};
@@ -8729,22 +8806,6 @@ function EnableEditor(props) {
8729
8806
  }
8730
8807
  })(event);
8731
8808
  }
8732
- function evaluateJsCode() {
8733
- const jsCode = props.builderContextSignal.content?.data?.jsCode;
8734
- if (jsCode) {
8735
- evaluate({
8736
- code: jsCode,
8737
- context: props.context || {},
8738
- localState: void 0,
8739
- rootState: props.builderContextSignal.rootState,
8740
- rootSetState: props.builderContextSignal.rootSetState,
8741
- /**
8742
- * We don't want to cache the result of the JS code, since it's arbitrary side effect code.
8743
- */
8744
- enableCache: false
8745
- });
8746
- }
8747
- }
8748
8809
  function onClick(event) {
8749
8810
  if (props.builderContextSignal.content) {
8750
8811
  const variationId = props.builderContextSignal.content?.testVariationId;
@@ -8781,7 +8842,7 @@ function EnableEditor(props) {
8781
8842
  rootSetState: props.builderContextSignal.rootSetState,
8782
8843
  enableCache: true
8783
8844
  })));
8784
- fetch2(evaluatedUrl).then((response) => response.json()).then((json) => {
8845
+ fetch(evaluatedUrl).then((response) => response.json()).then((json) => {
8785
8846
  mergeNewRootState({
8786
8847
  [key]: json
8787
8848
  });
@@ -8805,6 +8866,8 @@ function EnableEditor(props) {
8805
8866
  }
8806
8867
  }
8807
8868
  let elementRef;
8869
+ runHttpRequests();
8870
+ emitStateUpdate();
8808
8871
  onMount(() => {
8809
8872
  if (isBrowser()) {
8810
8873
  if (isEditing()) {
@@ -8859,14 +8922,6 @@ function EnableEditor(props) {
8859
8922
  }
8860
8923
  }
8861
8924
  });
8862
- onMount(() => {
8863
- if (!props.apiKey) {
8864
- logger.error("No API key provided to `Content` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
8865
- }
8866
- evaluateJsCode();
8867
- runHttpRequests();
8868
- emitStateUpdate();
8869
- });
8870
8925
  const onUpdateFn_0_props_content = createMemo(() => props.content);
8871
8926
  function onUpdateFn_0() {
8872
8927
  if (props.content) {
@@ -8874,37 +8929,27 @@ function EnableEditor(props) {
8874
8929
  }
8875
8930
  }
8876
8931
  createEffect(on(() => [onUpdateFn_0_props_content()], onUpdateFn_0));
8877
- const onUpdateFn_1_props_builderContextSignal_content__data__jsCode = createMemo(() => props.builderContextSignal.content?.data?.jsCode);
8932
+ const onUpdateFn_1_props_builderContextSignal_rootState = createMemo(() => props.builderContextSignal.rootState);
8878
8933
  function onUpdateFn_1() {
8879
- evaluateJsCode();
8880
- }
8881
- createEffect(on(() => [onUpdateFn_1_props_builderContextSignal_content__data__jsCode()], onUpdateFn_1));
8882
- const onUpdateFn_2_props_builderContextSignal_content__data__httpRequests = createMemo(() => props.builderContextSignal.content?.data?.httpRequests);
8883
- function onUpdateFn_2() {
8884
- runHttpRequests();
8885
- }
8886
- createEffect(on(() => [onUpdateFn_2_props_builderContextSignal_content__data__httpRequests()], onUpdateFn_2));
8887
- const onUpdateFn_3_props_builderContextSignal_rootState = createMemo(() => props.builderContextSignal.rootState);
8888
- function onUpdateFn_3() {
8889
8934
  emitStateUpdate();
8890
8935
  }
8891
- createEffect(on(() => [onUpdateFn_3_props_builderContextSignal_rootState()], onUpdateFn_3));
8892
- const onUpdateFn_4_props_data = createMemo(() => props.data);
8893
- function onUpdateFn_4() {
8936
+ createEffect(on(() => [onUpdateFn_1_props_builderContextSignal_rootState()], onUpdateFn_1));
8937
+ const onUpdateFn_2_props_data = createMemo(() => props.data);
8938
+ function onUpdateFn_2() {
8894
8939
  if (props.data) {
8895
8940
  mergeNewRootState(props.data);
8896
8941
  }
8897
8942
  }
8898
- createEffect(on(() => [onUpdateFn_4_props_data()], onUpdateFn_4));
8899
- const onUpdateFn_5_props_locale = createMemo(() => props.locale);
8900
- function onUpdateFn_5() {
8943
+ createEffect(on(() => [onUpdateFn_2_props_data()], onUpdateFn_2));
8944
+ const onUpdateFn_3_props_locale = createMemo(() => props.locale);
8945
+ function onUpdateFn_3() {
8901
8946
  if (props.locale) {
8902
8947
  mergeNewRootState({
8903
8948
  locale: props.locale
8904
8949
  });
8905
8950
  }
8906
8951
  }
8907
- createEffect(on(() => [onUpdateFn_5_props_locale()], onUpdateFn_5));
8952
+ createEffect(on(() => [onUpdateFn_3_props_locale()], onUpdateFn_3));
8908
8953
  return createComponent(builder_context_default.Provider, {
8909
8954
  get value() {
8910
8955
  return props.builderContextSignal;
@@ -9072,6 +9117,29 @@ function ContentComponent(props) {
9072
9117
  rootState: newRootState
9073
9118
  }));
9074
9119
  }
9120
+ if (!props.apiKey) {
9121
+ logger.error("No API key provided to `Content` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
9122
+ }
9123
+ const jsCode = builderContextSignal().content?.data?.jsCode;
9124
+ if (jsCode) {
9125
+ evaluate({
9126
+ code: jsCode,
9127
+ context: props.context || {},
9128
+ localState: void 0,
9129
+ rootState: builderContextSignal().rootState,
9130
+ rootSetState: (newState) => {
9131
+ setBuilderContextSignal((PREVIOUS_VALUE) => ({
9132
+ ...PREVIOUS_VALUE,
9133
+ rootState: newState
9134
+ }));
9135
+ },
9136
+ isExpression: false,
9137
+ /**
9138
+ * We don't want to cache the result of the JS code, since it's arbitrary side effect code.
9139
+ */
9140
+ enableCache: false
9141
+ });
9142
+ }
9075
9143
  return createComponent(components_context_default.Provider, {
9076
9144
  get value() {
9077
9145
  return {