@builder.io/sdk-solid 3.0.1 → 3.0.3

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/dev.js CHANGED
@@ -120,23 +120,6 @@ var builder_context_default = createContext({
120
120
  });
121
121
  var components_context_default = createContext({ registeredComponents: {} });
122
122
 
123
- // src/functions/get-block-component-options.ts
124
- function getBlockComponentOptions(block) {
125
- return {
126
- ...block.component?.options,
127
- ...block.options
128
- };
129
- }
130
-
131
- // src/helpers/omit.ts
132
- function omit(obj, ...values) {
133
- const newObject = Object.assign({}, obj);
134
- for (const key of values) {
135
- delete newObject[key];
136
- }
137
- return newObject;
138
- }
139
-
140
123
  // src/helpers/logger.ts
141
124
  var MSG_PREFIX = "[Builder.io]: ";
142
125
  var logger = {
@@ -584,6 +567,38 @@ function evaluate({
584
567
  }
585
568
  }
586
569
 
570
+ // src/functions/get-block-component-options.ts
571
+ function getBlockComponentOptions(block, context) {
572
+ return {
573
+ ...block.component?.options,
574
+ ...block.options,
575
+ ...evaluateTextComponentTextOption(block, context)
576
+ };
577
+ }
578
+ var evaluateTextComponentTextOption = (block, context) => {
579
+ if (block.component?.name === "Text" && block.component.options?.text && typeof block.component.options.text === "string") {
580
+ return {
581
+ ...block.component.options,
582
+ text: block.component.options.text.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({
583
+ code: group,
584
+ context,
585
+ localState: context.localState,
586
+ rootState: context.rootState,
587
+ rootSetState: context.rootSetState
588
+ }))
589
+ };
590
+ }
591
+ };
592
+
593
+ // src/helpers/omit.ts
594
+ function omit(obj, ...values) {
595
+ const newObject = Object.assign({}, obj);
596
+ for (const key of values) {
597
+ delete newObject[key];
598
+ }
599
+ return newObject;
600
+ }
601
+
587
602
  // src/functions/traverse.ts
588
603
  function traverse(obj, callback, parent2 = null, key = null, visited = /* @__PURE__ */ new WeakSet()) {
589
604
  if (obj == null || typeof obj !== "object") {
@@ -735,24 +750,19 @@ var evaluateBindings = ({
735
750
  function getProcessedBlock({
736
751
  block,
737
752
  context,
738
- shouldEvaluateBindings,
739
753
  localState,
740
754
  rootState,
741
755
  rootSetState
742
756
  }) {
743
757
  let transformedBlock = resolveLocalizedValues(block, rootState.locale);
744
758
  transformedBlock = transformBlock(transformedBlock);
745
- if (shouldEvaluateBindings) {
746
- return evaluateBindings({
747
- block: transformedBlock,
748
- localState,
749
- rootState,
750
- rootSetState,
751
- context
752
- });
753
- } else {
754
- return transformedBlock;
755
- }
759
+ return evaluateBindings({
760
+ block: transformedBlock,
761
+ localState,
762
+ rootState,
763
+ rootSetState,
764
+ context
765
+ });
756
766
  }
757
767
 
758
768
  // src/functions/camel-to-kebab-case.ts
@@ -1532,8 +1542,7 @@ function Block(props) {
1532
1542
  localState: props.context.localState,
1533
1543
  rootState: props.context.rootState,
1534
1544
  rootSetState: props.context.rootSetState,
1535
- context: props.context.context,
1536
- shouldEvaluateBindings: true
1545
+ context: props.context.context
1537
1546
  });
1538
1547
  return blockToUse;
1539
1548
  });
@@ -1570,7 +1579,7 @@ function Block(props) {
1570
1579
  blockChildren: processedBlock().children ?? [],
1571
1580
  componentRef: blockComponent()?.component,
1572
1581
  componentOptions: {
1573
- ...getBlockComponentOptions(processedBlock()),
1582
+ ...getBlockComponentOptions(processedBlock(), props.context),
1574
1583
  ...provideBuilderBlock(blockComponent(), processedBlock()),
1575
1584
  ...provideBuilderContext(blockComponent(), props.context),
1576
1585
  ...provideLinkComponent(blockComponent(), props.linkComponent),
@@ -1776,7 +1785,7 @@ function Block(props) {
1776
1785
  });
1777
1786
  }
1778
1787
  var block_default = Block;
1779
- var _tmpl$2 = /* @__PURE__ */ template(`<style>.dynamic-5b6a86b6 {
1788
+ var _tmpl$2 = /* @__PURE__ */ template(`<style>.dynamic-3c4beb0c {
1780
1789
  display: flex;
1781
1790
  flex-direction: column;
1782
1791
  align-items: stretch;
@@ -1819,7 +1828,7 @@ function BlocksWrapper(props) {
1819
1828
  });
1820
1829
  return [createComponent(Dynamic, mergeProps({
1821
1830
  get ["class"]() {
1822
- return className() + " dynamic-5b6a86b6";
1831
+ return className() + " dynamic-3c4beb0c";
1823
1832
  },
1824
1833
  ref(r$) {
1825
1834
  const _ref$ = blocksWrapperRef;
@@ -1918,7 +1927,7 @@ var getColumnsClass = (id) => {
1918
1927
 
1919
1928
  // src/blocks/columns/columns.tsx
1920
1929
  var _tmpl$3 = /* @__PURE__ */ template(`<div>`);
1921
- var _tmpl$22 = /* @__PURE__ */ template(`<style>.div-2ac94efa {
1930
+ var _tmpl$22 = /* @__PURE__ */ template(`<style>.div-3e5f33a4 {
1922
1931
  display: flex;
1923
1932
  line-height: normal;
1924
1933
  }`);
@@ -2047,7 +2056,7 @@ function Columns(props) {
2047
2056
  const _el$ = _tmpl$3();
2048
2057
  spread(_el$, mergeProps({
2049
2058
  get ["class"]() {
2050
- return getColumnsClass(props.builderBlock?.id) + " div-2ac94efa";
2059
+ return getColumnsClass(props.builderBlock?.id) + " div-3e5f33a4";
2051
2060
  },
2052
2061
  get style() {
2053
2062
  return columnsCssVars();
@@ -2172,16 +2181,16 @@ function getSrcSet(url) {
2172
2181
  // src/blocks/image/image.tsx
2173
2182
  var _tmpl$5 = /* @__PURE__ */ template(`<source type=image/webp>`);
2174
2183
  var _tmpl$23 = /* @__PURE__ */ template(`<picture><img>`);
2175
- var _tmpl$32 = /* @__PURE__ */ template(`<div class="builder-image-sizer div-070d7e88">`);
2176
- var _tmpl$42 = /* @__PURE__ */ template(`<div class=div-070d7e88-2>`);
2177
- var _tmpl$52 = /* @__PURE__ */ template(`<style>.img-070d7e88 {
2184
+ var _tmpl$32 = /* @__PURE__ */ template(`<div class="builder-image-sizer div-56e07140">`);
2185
+ var _tmpl$42 = /* @__PURE__ */ template(`<div class=div-56e07140-2>`);
2186
+ var _tmpl$52 = /* @__PURE__ */ template(`<style>.img-56e07140 {
2178
2187
  opacity: 1;
2179
2188
  transition: opacity 0.2s ease-in-out;
2180
- }.div-070d7e88 {
2189
+ }.div-56e07140 {
2181
2190
  width: 100%;
2182
2191
  pointer-events: none;
2183
2192
  font-size: 0;
2184
- }.div-070d7e88-2 {
2193
+ }.div-56e07140-2 {
2185
2194
  display: flex;
2186
2195
  flex-direction: column;
2187
2196
  align-items: stretch;
@@ -2246,7 +2255,7 @@ function Image(props) {
2246
2255
  }
2247
2256
  }), _el$3);
2248
2257
  effect((_p$) => {
2249
- const _v$ = "builder-image" + (props.className ? " " + props.className : "") + " img-070d7e88", _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 = {
2258
+ const _v$ = "builder-image" + (props.className ? " " + props.className : "") + " img-56e07140", _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 = {
2250
2259
  "object-position": props.backgroundPosition || "center",
2251
2260
  "object-fit": props.backgroundSize || "cover",
2252
2261
  ...aspectRatioCss()
@@ -3650,26 +3659,10 @@ var componentInfo10 = {
3650
3659
  };
3651
3660
  var _tmpl$10 = /* @__PURE__ */ template(`<div class=builder-text>`);
3652
3661
  function Text(props) {
3653
- const processedText = createMemo(() => {
3654
- const context = props.builderContext;
3655
- const {
3656
- context: contextContext,
3657
- localState,
3658
- rootState,
3659
- rootSetState
3660
- } = context;
3661
- return String(props.text?.toString() || "").replace(/{{([^}]+)}}/g, (match, group) => evaluate({
3662
- code: group,
3663
- context: contextContext,
3664
- localState,
3665
- rootState,
3666
- rootSetState
3667
- }));
3668
- });
3669
3662
  return (() => {
3670
3663
  const _el$ = _tmpl$10();
3671
3664
  _el$.style.setProperty("outline", "none");
3672
- effect(() => _el$.innerHTML = processedText());
3665
+ effect(() => _el$.innerHTML = props.text?.toString() || "");
3673
3666
  return _el$;
3674
3667
  })();
3675
3668
  }
@@ -4078,9 +4071,9 @@ function logFetch(url) {
4078
4071
  }
4079
4072
 
4080
4073
  // src/blocks/form/form/form.tsx
4081
- var _tmpl$13 = /* @__PURE__ */ template(`<pre class="builder-form-error-text pre-6210236e">`);
4074
+ var _tmpl$13 = /* @__PURE__ */ template(`<pre class="builder-form-error-text pre-27d18614">`);
4082
4075
  var _tmpl$26 = /* @__PURE__ */ template(`<form>`);
4083
- var _tmpl$34 = /* @__PURE__ */ template(`<style>.pre-6210236e {
4076
+ var _tmpl$34 = /* @__PURE__ */ template(`<style>.pre-27d18614 {
4084
4077
  padding: 10px;
4085
4078
  color: red;
4086
4079
  text-align: center;
@@ -5054,7 +5047,7 @@ function getPreviewContent(_searchParams) {
5054
5047
  }
5055
5048
 
5056
5049
  // src/constants/sdk-version.ts
5057
- var SDK_VERSION = "3.0.1";
5050
+ var SDK_VERSION = "3.0.3";
5058
5051
 
5059
5052
  // src/helpers/sdk-headers.ts
5060
5053
  var getSdkHeaders = () => ({
@@ -5119,6 +5112,23 @@ function flattenMongoQuery(obj, _current, _res = {}) {
5119
5112
  }
5120
5113
  return _res;
5121
5114
  }
5115
+ function unflatten(obj) {
5116
+ const result = {};
5117
+ for (const key in obj) {
5118
+ const parts = key.split(".");
5119
+ let current = result;
5120
+ for (let i = 0; i < parts.length; i++) {
5121
+ const part = parts[i];
5122
+ if (i === parts.length - 1) {
5123
+ current[part] = obj[key];
5124
+ } else {
5125
+ current[part] = current[part] || {};
5126
+ current = current[part];
5127
+ }
5128
+ }
5129
+ }
5130
+ return result;
5131
+ }
5122
5132
 
5123
5133
  // src/types/api-version.ts
5124
5134
  var DEFAULT_API_VERSION = "v3";
@@ -5183,7 +5193,7 @@ var generateContentUrl = (options) => {
5183
5193
  url.searchParams.set("noTraverse", String(noTraverse));
5184
5194
  url.searchParams.set("includeRefs", String(true));
5185
5195
  const finalLocale = locale || userAttributes?.locale;
5186
- let finalUserAttributes = userAttributes;
5196
+ let finalUserAttributes = userAttributes || {};
5187
5197
  if (finalLocale) {
5188
5198
  url.searchParams.set("locale", finalLocale);
5189
5199
  finalUserAttributes = {
@@ -5221,11 +5231,15 @@ var generateContentUrl = (options) => {
5221
5231
  ...getBuilderSearchParamsFromWindow(),
5222
5232
  ...normalizeSearchParams(options.options || {})
5223
5233
  };
5234
+ finalUserAttributes = {
5235
+ ...finalUserAttributes,
5236
+ ...getUserAttributesAsJSON(queryOptions)
5237
+ };
5224
5238
  const flattened = flatten(queryOptions);
5225
5239
  for (const key in flattened) {
5226
5240
  url.searchParams.set(key, String(flattened[key]));
5227
5241
  }
5228
- if (finalUserAttributes) {
5242
+ if (Object.keys(finalUserAttributes).length > 0) {
5229
5243
  url.searchParams.set("userAttributes", JSON.stringify(finalUserAttributes));
5230
5244
  }
5231
5245
  if (query) {
@@ -5238,6 +5252,28 @@ var generateContentUrl = (options) => {
5238
5252
  }
5239
5253
  return url;
5240
5254
  };
5255
+ var getUserAttributesFromQueryOptions = (queryOptions) => {
5256
+ const newUserAttributes = {};
5257
+ for (const key in queryOptions) {
5258
+ if (key.startsWith("userAttributes.")) {
5259
+ newUserAttributes[key] = queryOptions[key];
5260
+ delete queryOptions[key];
5261
+ }
5262
+ }
5263
+ return newUserAttributes;
5264
+ };
5265
+ var getUserAttributesAsJSON = (queryOptions) => {
5266
+ if (isBrowser() && queryOptions["preview"] === "BUILDER_STUDIO") {
5267
+ queryOptions["userAttributes.urlPath"] = window.location.pathname;
5268
+ queryOptions["userAttributes.host"] = window.location.host;
5269
+ const queryOptionsForUserAttributes = getUserAttributesFromQueryOptions(queryOptions);
5270
+ const {
5271
+ userAttributes
5272
+ } = unflatten(queryOptionsForUserAttributes);
5273
+ return userAttributes;
5274
+ }
5275
+ return {};
5276
+ };
5241
5277
 
5242
5278
  // src/functions/get-content/index.ts
5243
5279
  var checkContentHasResults = (content) => "results" in content;
@@ -6039,11 +6075,16 @@ function EnableEditor(props) {
6039
6075
  const searchParamPreviewModel = searchParams.get("builder.preview");
6040
6076
  const searchParamPreviewId = searchParams.get(`builder.overrides.${searchParamPreviewModel}`);
6041
6077
  const previewApiKey = searchParams.get("apiKey") || searchParams.get("builder.space");
6042
- if (searchParamPreviewModel === props.model && previewApiKey === props.apiKey && (!props.content || searchParamPreviewId === props.content.id)) {
6078
+ if (searchParamPreviewModel === "BUILDER_STUDIO" || searchParamPreviewModel === props.model && previewApiKey === props.apiKey && (!props.content || searchParamPreviewId === props.content.id)) {
6043
6079
  fetchOneEntry({
6044
- model: props.model,
6080
+ model: props.model || "",
6045
6081
  apiKey: props.apiKey,
6046
- apiVersion: props.builderContextSignal.apiVersion
6082
+ apiVersion: props.builderContextSignal.apiVersion,
6083
+ ...searchParamPreviewModel === "BUILDER_STUDIO" && props.context?.symbolId ? {
6084
+ query: {
6085
+ id: props.context.symbolId
6086
+ }
6087
+ } : {}
6047
6088
  }).then((content) => {
6048
6089
  if (content) {
6049
6090
  mergeNewContent(content);