@builder.io/sdk-solid 2.0.16 → 2.0.22

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/dist/index.d.ts CHANGED
@@ -221,7 +221,7 @@ interface Input {
221
221
  valueType?: {
222
222
  type?: string;
223
223
  };
224
- onChange?: ((options: Map<string, any>) => void | Promise<void>) | string;
224
+ onChange?: ((options: Map<string, any>, previousOptions?: Map<string, any>) => void | Promise<void>) | string;
225
225
  meta?: Record<string, any>;
226
226
  }
227
227
 
@@ -480,6 +480,11 @@ interface ComponentInfo {
480
480
  }
481
481
  type Permission = 'read' | 'publish' | 'editCode' | 'editDesigns' | 'admin' | 'create';
482
482
 
483
+ /**
484
+ * To be overriden to the correct `Component` type for each framework.
485
+ */
486
+ type ComponentReference = any;
487
+
483
488
  /**
484
489
  * no-op type for extra context types on a per-SDK basis
485
490
  * See `overrides/react-native/src/context/extra-context-types.ts` for an example
@@ -488,7 +493,7 @@ interface ExtraContextTypes {
488
493
  }
489
494
 
490
495
  type RegisteredComponent = ComponentInfo & {
491
- component: any;
496
+ component: ComponentReference;
492
497
  };
493
498
  type RegisteredComponents = Dictionary<RegisteredComponent>;
494
499
  type BuilderRenderState = Record<string, unknown>;
@@ -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/helpers/nullable.ts
318
318
  var checkIsDefined = (maybeT) => maybeT !== null && maybeT !== void 0;
319
319
 
@@ -1108,6 +1108,14 @@ function BlockWrapper(props) {
1108
1108
  });
1109
1109
  }
1110
1110
  var block_wrapper_default = BlockWrapper;
1111
+ function Awaiter(props) {
1112
+ onMount(() => {
1113
+ });
1114
+ return memo(() => props.children);
1115
+ }
1116
+ var awaiter_default = Awaiter;
1117
+
1118
+ // src/components/block/components/interactive-element.tsx
1111
1119
  function InteractiveElement(props) {
1112
1120
  const attributes = createMemo(() => {
1113
1121
  return props.includeBlockProps ? {
@@ -1124,17 +1132,43 @@ function InteractiveElement(props) {
1124
1132
  })
1125
1133
  } : {};
1126
1134
  });
1127
- return createComponent(Dynamic, mergeProps(() => props.wrapperProps, {
1128
- get attributes() {
1129
- return attributes();
1135
+ return createComponent(Show, {
1136
+ get fallback() {
1137
+ return createComponent(Dynamic, mergeProps(() => props.wrapperProps, {
1138
+ get attributes() {
1139
+ return attributes();
1140
+ },
1141
+ get component() {
1142
+ return props.Wrapper;
1143
+ },
1144
+ get children() {
1145
+ return props.children;
1146
+ }
1147
+ }));
1130
1148
  },
1131
- get component() {
1132
- return props.Wrapper;
1149
+ get when() {
1150
+ return props.Wrapper.load;
1133
1151
  },
1134
1152
  get children() {
1135
- return props.children;
1153
+ return createComponent(awaiter_default, {
1154
+ get load() {
1155
+ return props.Wrapper.load;
1156
+ },
1157
+ get fallback() {
1158
+ return props.Wrapper.fallback;
1159
+ },
1160
+ get props() {
1161
+ return props.wrapperProps;
1162
+ },
1163
+ get attributes() {
1164
+ return attributes();
1165
+ },
1166
+ get children() {
1167
+ return props.children;
1168
+ }
1169
+ });
1136
1170
  }
1137
- }));
1171
+ });
1138
1172
  }
1139
1173
  var interactive_element_default = InteractiveElement;
1140
1174
 
@@ -1509,7 +1543,7 @@ function Block(props) {
1509
1543
  });
1510
1544
  }
1511
1545
  var block_default = Block;
1512
- var _tmpl$2 = /* @__PURE__ */ template(`<style>.dynamic-4da8c6f4 {
1546
+ var _tmpl$2 = /* @__PURE__ */ template(`<style>.dynamic-68b2d7fe {
1513
1547
  display: flex;
1514
1548
  flex-direction: column;
1515
1549
  align-items: stretch;
@@ -1545,7 +1579,7 @@ function BlocksWrapper(props) {
1545
1579
  });
1546
1580
  return [createComponent(Dynamic, mergeProps({
1547
1581
  get ["class"]() {
1548
- return className() + " dynamic-4da8c6f4";
1582
+ return className() + " dynamic-68b2d7fe";
1549
1583
  },
1550
1584
  ref(r$) {
1551
1585
  const _ref$ = blocksWrapperRef;
@@ -1641,7 +1675,7 @@ var getColumnsClass = (id) => {
1641
1675
 
1642
1676
  // src/blocks/columns/columns.tsx
1643
1677
  var _tmpl$3 = /* @__PURE__ */ template(`<div>`);
1644
- var _tmpl$22 = /* @__PURE__ */ template(`<style>.div-3ff242de {
1678
+ var _tmpl$22 = /* @__PURE__ */ template(`<style>.div-46766f1c {
1645
1679
  display: flex;
1646
1680
  line-height: normal;
1647
1681
  }`);
@@ -1762,7 +1796,7 @@ function Columns(props) {
1762
1796
  const _el$ = _tmpl$3();
1763
1797
  spread(_el$, mergeProps({
1764
1798
  get ["class"]() {
1765
- return getColumnsClass(props.builderBlock?.id) + " div-3ff242de";
1799
+ return getColumnsClass(props.builderBlock?.id) + " div-46766f1c";
1766
1800
  },
1767
1801
  get style() {
1768
1802
  return columnsCssVars();
@@ -1887,16 +1921,16 @@ function getSrcSet(url) {
1887
1921
  // src/blocks/image/image.tsx
1888
1922
  var _tmpl$5 = /* @__PURE__ */ template(`<source type=image/webp>`);
1889
1923
  var _tmpl$23 = /* @__PURE__ */ template(`<picture><img>`);
1890
- var _tmpl$32 = /* @__PURE__ */ template(`<div class="builder-image-sizer div-4512e110">`);
1891
- var _tmpl$42 = /* @__PURE__ */ template(`<div class=div-4512e110-2>`);
1892
- var _tmpl$52 = /* @__PURE__ */ template(`<style>.img-4512e110 {
1924
+ var _tmpl$32 = /* @__PURE__ */ template(`<div class="builder-image-sizer div-7e6ffddc">`);
1925
+ var _tmpl$42 = /* @__PURE__ */ template(`<div class=div-7e6ffddc-2>`);
1926
+ var _tmpl$52 = /* @__PURE__ */ template(`<style>.img-7e6ffddc {
1893
1927
  opacity: 1;
1894
1928
  transition: opacity 0.2s ease-in-out;
1895
- }.div-4512e110 {
1929
+ }.div-7e6ffddc {
1896
1930
  width: 100%;
1897
1931
  pointer-events: none;
1898
1932
  font-size: 0;
1899
- }.div-4512e110-2 {
1933
+ }.div-7e6ffddc-2 {
1900
1934
  display: flex;
1901
1935
  flex-direction: column;
1902
1936
  align-items: stretch;
@@ -1961,7 +1995,7 @@ function Image(props) {
1961
1995
  }
1962
1996
  }), _el$3);
1963
1997
  effect((_p$) => {
1964
- 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 = {
1998
+ 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 = {
1965
1999
  "object-position": props.backgroundPosition || "center",
1966
2000
  "object-fit": props.backgroundSize || "cover",
1967
2001
  ...aspectRatioCss()
@@ -5251,7 +5285,7 @@ function isFromTrustedHost(trustedHosts, e) {
5251
5285
  }
5252
5286
 
5253
5287
  // src/constants/sdk-version.ts
5254
- var SDK_VERSION = "2.0.16";
5288
+ var SDK_VERSION = "2.0.22";
5255
5289
 
5256
5290
  // src/functions/register.ts
5257
5291
  var registry = {};
@@ -5605,22 +5639,6 @@ function EnableEditor(props) {
5605
5639
  }
5606
5640
  })(event);
5607
5641
  }
5608
- function evaluateJsCode() {
5609
- const jsCode = props.builderContextSignal.content?.data?.jsCode;
5610
- if (jsCode) {
5611
- evaluate({
5612
- code: jsCode,
5613
- context: props.context || {},
5614
- localState: void 0,
5615
- rootState: props.builderContextSignal.rootState,
5616
- rootSetState: props.builderContextSignal.rootSetState,
5617
- /**
5618
- * We don't want to cache the result of the JS code, since it's arbitrary side effect code.
5619
- */
5620
- enableCache: false
5621
- });
5622
- }
5623
- }
5624
5642
  function onClick(event) {
5625
5643
  if (props.builderContextSignal.content) {
5626
5644
  const variationId = props.builderContextSignal.content?.testVariationId;
@@ -5657,7 +5675,7 @@ function EnableEditor(props) {
5657
5675
  rootSetState: props.builderContextSignal.rootSetState,
5658
5676
  enableCache: true
5659
5677
  })));
5660
- fetch2(evaluatedUrl).then((response) => response.json()).then((json) => {
5678
+ fetch(evaluatedUrl).then((response) => response.json()).then((json) => {
5661
5679
  mergeNewRootState({
5662
5680
  [key]: json
5663
5681
  });
@@ -5682,6 +5700,8 @@ function EnableEditor(props) {
5682
5700
  }
5683
5701
  }
5684
5702
  let elementRef;
5703
+ runHttpRequests();
5704
+ emitStateUpdate();
5685
5705
  onMount(() => {
5686
5706
  if (isBrowser()) {
5687
5707
  if (isEditing()) {
@@ -5736,14 +5756,6 @@ function EnableEditor(props) {
5736
5756
  }
5737
5757
  }
5738
5758
  });
5739
- onMount(() => {
5740
- if (!props.apiKey) {
5741
- logger.error("No API key provided to `Content` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
5742
- }
5743
- evaluateJsCode();
5744
- runHttpRequests();
5745
- emitStateUpdate();
5746
- });
5747
5759
  const onUpdateFn_0_props_content = createMemo(() => props.content);
5748
5760
  function onUpdateFn_0() {
5749
5761
  if (props.content) {
@@ -5751,37 +5763,27 @@ function EnableEditor(props) {
5751
5763
  }
5752
5764
  }
5753
5765
  createEffect(on(() => [onUpdateFn_0_props_content()], onUpdateFn_0));
5754
- const onUpdateFn_1_props_builderContextSignal_content__data__jsCode = createMemo(() => props.builderContextSignal.content?.data?.jsCode);
5766
+ const onUpdateFn_1_props_builderContextSignal_rootState = createMemo(() => props.builderContextSignal.rootState);
5755
5767
  function onUpdateFn_1() {
5756
- evaluateJsCode();
5757
- }
5758
- createEffect(on(() => [onUpdateFn_1_props_builderContextSignal_content__data__jsCode()], onUpdateFn_1));
5759
- const onUpdateFn_2_props_builderContextSignal_content__data__httpRequests = createMemo(() => props.builderContextSignal.content?.data?.httpRequests);
5760
- function onUpdateFn_2() {
5761
- runHttpRequests();
5762
- }
5763
- createEffect(on(() => [onUpdateFn_2_props_builderContextSignal_content__data__httpRequests()], onUpdateFn_2));
5764
- const onUpdateFn_3_props_builderContextSignal_rootState = createMemo(() => props.builderContextSignal.rootState);
5765
- function onUpdateFn_3() {
5766
5768
  emitStateUpdate();
5767
5769
  }
5768
- createEffect(on(() => [onUpdateFn_3_props_builderContextSignal_rootState()], onUpdateFn_3));
5769
- const onUpdateFn_4_props_data = createMemo(() => props.data);
5770
- function onUpdateFn_4() {
5770
+ createEffect(on(() => [onUpdateFn_1_props_builderContextSignal_rootState()], onUpdateFn_1));
5771
+ const onUpdateFn_2_props_data = createMemo(() => props.data);
5772
+ function onUpdateFn_2() {
5771
5773
  if (props.data) {
5772
5774
  mergeNewRootState(props.data);
5773
5775
  }
5774
5776
  }
5775
- createEffect(on(() => [onUpdateFn_4_props_data()], onUpdateFn_4));
5776
- const onUpdateFn_5_props_locale = createMemo(() => props.locale);
5777
- function onUpdateFn_5() {
5777
+ createEffect(on(() => [onUpdateFn_2_props_data()], onUpdateFn_2));
5778
+ const onUpdateFn_3_props_locale = createMemo(() => props.locale);
5779
+ function onUpdateFn_3() {
5778
5780
  if (props.locale) {
5779
5781
  mergeNewRootState({
5780
5782
  locale: props.locale
5781
5783
  });
5782
5784
  }
5783
5785
  }
5784
- createEffect(on(() => [onUpdateFn_5_props_locale()], onUpdateFn_5));
5786
+ createEffect(on(() => [onUpdateFn_3_props_locale()], onUpdateFn_3));
5785
5787
  return createComponent(builder_context_default.Provider, {
5786
5788
  get value() {
5787
5789
  return props.builderContextSignal;
@@ -5949,6 +5951,29 @@ function ContentComponent(props) {
5949
5951
  rootState: newRootState
5950
5952
  }));
5951
5953
  }
5954
+ if (!props.apiKey) {
5955
+ logger.error("No API key provided to `Content` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
5956
+ }
5957
+ const jsCode = builderContextSignal().content?.data?.jsCode;
5958
+ if (jsCode) {
5959
+ evaluate({
5960
+ code: jsCode,
5961
+ context: props.context || {},
5962
+ localState: void 0,
5963
+ rootState: builderContextSignal().rootState,
5964
+ rootSetState: (newState) => {
5965
+ setBuilderContextSignal((PREVIOUS_VALUE) => ({
5966
+ ...PREVIOUS_VALUE,
5967
+ rootState: newState
5968
+ }));
5969
+ },
5970
+ isExpression: false,
5971
+ /**
5972
+ * We don't want to cache the result of the JS code, since it's arbitrary side effect code.
5973
+ */
5974
+ enableCache: false
5975
+ });
5976
+ }
5952
5977
  return createComponent(components_context_default.Provider, {
5953
5978
  get value() {
5954
5979
  return {