@builder.io/sdk-solid 3.0.1 → 3.0.2

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.
@@ -119,23 +119,6 @@ var builder_context_default = createContext({
119
119
  });
120
120
  var components_context_default = createContext({ registeredComponents: {} });
121
121
 
122
- // src/functions/get-block-component-options.ts
123
- function getBlockComponentOptions(block) {
124
- return {
125
- ...block.component?.options,
126
- ...block.options
127
- };
128
- }
129
-
130
- // src/helpers/omit.ts
131
- function omit(obj, ...values) {
132
- const newObject = Object.assign({}, obj);
133
- for (const key of values) {
134
- delete newObject[key];
135
- }
136
- return newObject;
137
- }
138
-
139
122
  // src/helpers/logger.ts
140
123
  var logger = {
141
124
  log: (...message) => void 0,
@@ -400,6 +383,38 @@ function evaluate({
400
383
  }
401
384
  }
402
385
 
386
+ // src/functions/get-block-component-options.ts
387
+ function getBlockComponentOptions(block, context) {
388
+ return {
389
+ ...block.component?.options,
390
+ ...block.options,
391
+ ...evaluateTextComponentTextOption(block, context)
392
+ };
393
+ }
394
+ var evaluateTextComponentTextOption = (block, context) => {
395
+ if (block.component?.name === "Text" && block.component.options?.text && typeof block.component.options.text === "string") {
396
+ return {
397
+ ...block.component.options,
398
+ text: block.component.options.text.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({
399
+ code: group,
400
+ context,
401
+ localState: context.localState,
402
+ rootState: context.rootState,
403
+ rootSetState: context.rootSetState
404
+ }))
405
+ };
406
+ }
407
+ };
408
+
409
+ // src/helpers/omit.ts
410
+ function omit(obj, ...values) {
411
+ const newObject = Object.assign({}, obj);
412
+ for (const key of values) {
413
+ delete newObject[key];
414
+ }
415
+ return newObject;
416
+ }
417
+
403
418
  // src/functions/traverse.ts
404
419
  function traverse(obj, callback, parent2 = null, key = null, visited = /* @__PURE__ */ new WeakSet()) {
405
420
  if (obj == null || typeof obj !== "object") {
@@ -561,24 +576,19 @@ var evaluateBindings = ({
561
576
  function getProcessedBlock({
562
577
  block,
563
578
  context,
564
- shouldEvaluateBindings,
565
579
  localState,
566
580
  rootState,
567
581
  rootSetState
568
582
  }) {
569
583
  let transformedBlock = resolveLocalizedValues(block, rootState.locale);
570
584
  transformedBlock = transformBlock(transformedBlock);
571
- if (shouldEvaluateBindings) {
572
- return evaluateBindings({
573
- block: transformedBlock,
574
- localState,
575
- rootState,
576
- rootSetState,
577
- context
578
- });
579
- } else {
580
- return transformedBlock;
581
- }
585
+ return evaluateBindings({
586
+ block: transformedBlock,
587
+ localState,
588
+ rootState,
589
+ rootSetState,
590
+ context
591
+ });
582
592
  }
583
593
 
584
594
  // src/functions/camel-to-kebab-case.ts
@@ -1354,8 +1364,7 @@ function Block(props) {
1354
1364
  localState: props.context.localState,
1355
1365
  rootState: props.context.rootState,
1356
1366
  rootSetState: props.context.rootSetState,
1357
- context: props.context.context,
1358
- shouldEvaluateBindings: true
1367
+ context: props.context.context
1359
1368
  });
1360
1369
  return blockToUse;
1361
1370
  });
@@ -1392,7 +1401,7 @@ function Block(props) {
1392
1401
  blockChildren: processedBlock().children ?? [],
1393
1402
  componentRef: blockComponent()?.component,
1394
1403
  componentOptions: {
1395
- ...getBlockComponentOptions(processedBlock()),
1404
+ ...getBlockComponentOptions(processedBlock(), props.context),
1396
1405
  ...provideBuilderBlock(blockComponent(), processedBlock()),
1397
1406
  ...provideBuilderContext(blockComponent(), props.context),
1398
1407
  ...provideLinkComponent(blockComponent(), props.linkComponent),
@@ -3470,26 +3479,10 @@ var componentInfo10 = {
3470
3479
  };
3471
3480
  var _tmpl$10 = /* @__PURE__ */ template(`<div class=builder-text>`);
3472
3481
  function Text(props) {
3473
- const processedText = createMemo(() => {
3474
- const context = props.builderContext;
3475
- const {
3476
- context: contextContext,
3477
- localState,
3478
- rootState,
3479
- rootSetState
3480
- } = context;
3481
- return String(props.text?.toString() || "").replace(/{{([^}]+)}}/g, (match, group) => evaluate({
3482
- code: group,
3483
- context: contextContext,
3484
- localState,
3485
- rootState,
3486
- rootSetState
3487
- }));
3488
- });
3489
3482
  return (() => {
3490
3483
  const _el$ = _tmpl$10();
3491
3484
  _el$.style.setProperty("outline", "none");
3492
- effect(() => _el$.innerHTML = processedText());
3485
+ effect(() => _el$.innerHTML = props.text?.toString() || "");
3493
3486
  return _el$;
3494
3487
  })();
3495
3488
  }
@@ -4872,7 +4865,7 @@ function getPreviewContent(_searchParams) {
4872
4865
  }
4873
4866
 
4874
4867
  // src/constants/sdk-version.ts
4875
- var SDK_VERSION = "3.0.1";
4868
+ var SDK_VERSION = "3.0.2";
4876
4869
 
4877
4870
  // src/helpers/sdk-headers.ts
4878
4871
  var getSdkHeaders = () => ({
@@ -4935,6 +4928,23 @@ function flattenMongoQuery(obj, _current, _res = {}) {
4935
4928
  }
4936
4929
  return _res;
4937
4930
  }
4931
+ function unflatten(obj) {
4932
+ const result = {};
4933
+ for (const key in obj) {
4934
+ const parts = key.split(".");
4935
+ let current = result;
4936
+ for (let i = 0; i < parts.length; i++) {
4937
+ const part = parts[i];
4938
+ if (i === parts.length - 1) {
4939
+ current[part] = obj[key];
4940
+ } else {
4941
+ current[part] = current[part] || {};
4942
+ current = current[part];
4943
+ }
4944
+ }
4945
+ }
4946
+ return result;
4947
+ }
4938
4948
 
4939
4949
  // src/types/api-version.ts
4940
4950
  var DEFAULT_API_VERSION = "v3";
@@ -4999,7 +5009,7 @@ var generateContentUrl = (options) => {
4999
5009
  url.searchParams.set("noTraverse", String(noTraverse));
5000
5010
  url.searchParams.set("includeRefs", String(true));
5001
5011
  const finalLocale = locale || userAttributes?.locale;
5002
- let finalUserAttributes = userAttributes;
5012
+ let finalUserAttributes = userAttributes || {};
5003
5013
  if (finalLocale) {
5004
5014
  url.searchParams.set("locale", finalLocale);
5005
5015
  finalUserAttributes = {
@@ -5037,11 +5047,15 @@ var generateContentUrl = (options) => {
5037
5047
  ...getBuilderSearchParamsFromWindow(),
5038
5048
  ...normalizeSearchParams(options.options || {})
5039
5049
  };
5050
+ finalUserAttributes = {
5051
+ ...finalUserAttributes,
5052
+ ...getUserAttributesAsJSON(queryOptions)
5053
+ };
5040
5054
  const flattened = flatten(queryOptions);
5041
5055
  for (const key in flattened) {
5042
5056
  url.searchParams.set(key, String(flattened[key]));
5043
5057
  }
5044
- if (finalUserAttributes) {
5058
+ if (Object.keys(finalUserAttributes).length > 0) {
5045
5059
  url.searchParams.set("userAttributes", JSON.stringify(finalUserAttributes));
5046
5060
  }
5047
5061
  if (query) {
@@ -5054,6 +5068,28 @@ var generateContentUrl = (options) => {
5054
5068
  }
5055
5069
  return url;
5056
5070
  };
5071
+ var getUserAttributesFromQueryOptions = (queryOptions) => {
5072
+ const newUserAttributes = {};
5073
+ for (const key in queryOptions) {
5074
+ if (key.startsWith("userAttributes.")) {
5075
+ newUserAttributes[key] = queryOptions[key];
5076
+ delete queryOptions[key];
5077
+ }
5078
+ }
5079
+ return newUserAttributes;
5080
+ };
5081
+ var getUserAttributesAsJSON = (queryOptions) => {
5082
+ if (isBrowser() && queryOptions["preview"] === "BUILDER_STUDIO") {
5083
+ queryOptions["userAttributes.urlPath"] = window.location.pathname;
5084
+ queryOptions["userAttributes.host"] = window.location.host;
5085
+ const queryOptionsForUserAttributes = getUserAttributesFromQueryOptions(queryOptions);
5086
+ const {
5087
+ userAttributes
5088
+ } = unflatten(queryOptionsForUserAttributes);
5089
+ return userAttributes;
5090
+ }
5091
+ return {};
5092
+ };
5057
5093
 
5058
5094
  // src/functions/get-content/index.ts
5059
5095
  var checkContentHasResults = (content) => "results" in content;
@@ -5850,11 +5886,16 @@ function EnableEditor(props) {
5850
5886
  const searchParamPreviewModel = searchParams.get("builder.preview");
5851
5887
  const searchParamPreviewId = searchParams.get(`builder.overrides.${searchParamPreviewModel}`);
5852
5888
  const previewApiKey = searchParams.get("apiKey") || searchParams.get("builder.space");
5853
- if (searchParamPreviewModel === props.model && previewApiKey === props.apiKey && (!props.content || searchParamPreviewId === props.content.id)) {
5889
+ if (searchParamPreviewModel === "BUILDER_STUDIO" || searchParamPreviewModel === props.model && previewApiKey === props.apiKey && (!props.content || searchParamPreviewId === props.content.id)) {
5854
5890
  fetchOneEntry({
5855
- model: props.model,
5891
+ model: props.model || "",
5856
5892
  apiKey: props.apiKey,
5857
- apiVersion: props.builderContextSignal.apiVersion
5893
+ apiVersion: props.builderContextSignal.apiVersion,
5894
+ ...searchParamPreviewModel === "BUILDER_STUDIO" && props.context?.symbolId ? {
5895
+ query: {
5896
+ id: props.context.symbolId
5897
+ }
5898
+ } : {}
5858
5899
  }).then((content) => {
5859
5900
  if (content) {
5860
5901
  mergeNewContent(content);