@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.
package/dist/index.d.ts CHANGED
@@ -1093,4 +1093,4 @@ declare const _processContentResult: (options: GetContentOptions, content: Conte
1093
1093
  */
1094
1094
  declare function fetchEntries(options: GetContentOptions): Promise<BuilderContent[]>;
1095
1095
 
1096
- export { Blocks, BlocksProps, BuilderBlock, BuilderContent, _default as BuilderContext, Button, ButtonProps, ColumnProps, Columns, ComponentInfo, ContentVariants as Content, ContentVariantsPrps as ContentProps, FragmentComponent as Fragment, FragmentProps, GetContentOptions, Image, ImageProps, InsertMenuConfig, InsertMenuItem, RegisteredComponent, SectionComponent as Section, SectionProps, Settings, Symbol, SymbolProps, Text, TextProps, Video, VideoProps, _processContentResult, createRegisterComponentMessage, fetchBuilderProps, fetchEntries, fetchOneEntry, getBuilderSearchParams, isEditing, isPreviewing, register, setEditorSettings, subscribeToEditor, track };
1096
+ export { Blocks, BlocksProps, BuilderBlock, BuilderContent, _default as BuilderContext, BuilderContextInterface, Button, ButtonProps, ColumnProps, Columns, ComponentInfo, ContentVariants as Content, ContentVariantsPrps as ContentProps, FragmentComponent as Fragment, FragmentProps, GetContentOptions, Image, ImageProps, InsertMenuConfig, InsertMenuItem, RegisteredComponent, RegisteredComponents, SectionComponent as Section, SectionProps, Settings, Symbol, SymbolProps, Text, TextProps, Video, VideoProps, _processContentResult, createRegisterComponentMessage, fetchBuilderProps, fetchEntries, fetchOneEntry, getBuilderSearchParams, isEditing, isPreviewing, register, setEditorSettings, subscribeToEditor, track };
@@ -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 MSG_PREFIX = "[Builder.io]: ";
141
124
  var logger = {
@@ -402,6 +385,38 @@ function evaluate({
402
385
  }
403
386
  }
404
387
 
388
+ // src/functions/get-block-component-options.ts
389
+ function getBlockComponentOptions(block, context) {
390
+ return {
391
+ ...block.component?.options,
392
+ ...block.options,
393
+ ...evaluateTextComponentTextOption(block, context)
394
+ };
395
+ }
396
+ var evaluateTextComponentTextOption = (block, context) => {
397
+ if (block.component?.name === "Text" && block.component.options?.text && typeof block.component.options.text === "string") {
398
+ return {
399
+ ...block.component.options,
400
+ text: block.component.options.text.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({
401
+ code: group,
402
+ context,
403
+ localState: context.localState,
404
+ rootState: context.rootState,
405
+ rootSetState: context.rootSetState
406
+ }))
407
+ };
408
+ }
409
+ };
410
+
411
+ // src/helpers/omit.ts
412
+ function omit(obj, ...values) {
413
+ const newObject = Object.assign({}, obj);
414
+ for (const key of values) {
415
+ delete newObject[key];
416
+ }
417
+ return newObject;
418
+ }
419
+
405
420
  // src/functions/traverse.ts
406
421
  function traverse(obj, callback, parent2 = null, key = null, visited = /* @__PURE__ */ new WeakSet()) {
407
422
  if (obj == null || typeof obj !== "object") {
@@ -566,24 +581,19 @@ var evaluateBindings = ({
566
581
  function getProcessedBlock({
567
582
  block,
568
583
  context,
569
- shouldEvaluateBindings,
570
584
  localState,
571
585
  rootState,
572
586
  rootSetState
573
587
  }) {
574
588
  let transformedBlock = resolveLocalizedValues(block, rootState.locale);
575
589
  transformedBlock = transformBlock(transformedBlock);
576
- if (shouldEvaluateBindings) {
577
- return evaluateBindings({
578
- block: transformedBlock,
579
- localState,
580
- rootState,
581
- rootSetState,
582
- context
583
- });
584
- } else {
585
- return transformedBlock;
586
- }
590
+ return evaluateBindings({
591
+ block: transformedBlock,
592
+ localState,
593
+ rootState,
594
+ rootSetState,
595
+ context
596
+ });
587
597
  }
588
598
 
589
599
  // src/functions/camel-to-kebab-case.ts
@@ -1363,8 +1373,7 @@ function Block(props) {
1363
1373
  localState: props.context.localState,
1364
1374
  rootState: props.context.rootState,
1365
1375
  rootSetState: props.context.rootSetState,
1366
- context: props.context.context,
1367
- shouldEvaluateBindings: true
1376
+ context: props.context.context
1368
1377
  });
1369
1378
  return blockToUse;
1370
1379
  });
@@ -1401,7 +1410,7 @@ function Block(props) {
1401
1410
  blockChildren: processedBlock().children ?? [],
1402
1411
  componentRef: blockComponent()?.component,
1403
1412
  componentOptions: {
1404
- ...getBlockComponentOptions(processedBlock()),
1413
+ ...getBlockComponentOptions(processedBlock(), props.context),
1405
1414
  ...provideBuilderBlock(blockComponent(), processedBlock()),
1406
1415
  ...provideBuilderContext(blockComponent(), props.context),
1407
1416
  ...provideLinkComponent(blockComponent(), props.linkComponent),
@@ -3481,26 +3490,10 @@ var componentInfo10 = {
3481
3490
  };
3482
3491
  var _tmpl$10 = /* @__PURE__ */ template(`<div class=builder-text>`);
3483
3492
  function Text(props) {
3484
- const processedText = createMemo(() => {
3485
- const context = props.builderContext;
3486
- const {
3487
- context: contextContext,
3488
- localState,
3489
- rootState,
3490
- rootSetState
3491
- } = context;
3492
- return String(props.text?.toString() || "").replace(/{{([^}]+)}}/g, (match, group) => evaluate({
3493
- code: group,
3494
- context: contextContext,
3495
- localState,
3496
- rootState,
3497
- rootSetState
3498
- }));
3499
- });
3500
3493
  return (() => {
3501
3494
  const _el$ = _tmpl$10();
3502
3495
  _el$.style.setProperty("outline", "none");
3503
- effect(() => _el$.innerHTML = processedText());
3496
+ effect(() => _el$.innerHTML = props.text?.toString() || "");
3504
3497
  return _el$;
3505
3498
  })();
3506
3499
  }
@@ -4885,7 +4878,7 @@ function getPreviewContent(_searchParams) {
4885
4878
  }
4886
4879
 
4887
4880
  // src/constants/sdk-version.ts
4888
- var SDK_VERSION = "3.0.1";
4881
+ var SDK_VERSION = "3.0.2";
4889
4882
 
4890
4883
  // src/helpers/sdk-headers.ts
4891
4884
  var getSdkHeaders = () => ({
@@ -4950,6 +4943,23 @@ function flattenMongoQuery(obj, _current, _res = {}) {
4950
4943
  }
4951
4944
  return _res;
4952
4945
  }
4946
+ function unflatten(obj) {
4947
+ const result = {};
4948
+ for (const key in obj) {
4949
+ const parts = key.split(".");
4950
+ let current = result;
4951
+ for (let i = 0; i < parts.length; i++) {
4952
+ const part = parts[i];
4953
+ if (i === parts.length - 1) {
4954
+ current[part] = obj[key];
4955
+ } else {
4956
+ current[part] = current[part] || {};
4957
+ current = current[part];
4958
+ }
4959
+ }
4960
+ }
4961
+ return result;
4962
+ }
4953
4963
 
4954
4964
  // src/types/api-version.ts
4955
4965
  var DEFAULT_API_VERSION = "v3";
@@ -5014,7 +5024,7 @@ var generateContentUrl = (options) => {
5014
5024
  url.searchParams.set("noTraverse", String(noTraverse));
5015
5025
  url.searchParams.set("includeRefs", String(true));
5016
5026
  const finalLocale = locale || userAttributes?.locale;
5017
- let finalUserAttributes = userAttributes;
5027
+ let finalUserAttributes = userAttributes || {};
5018
5028
  if (finalLocale) {
5019
5029
  url.searchParams.set("locale", finalLocale);
5020
5030
  finalUserAttributes = {
@@ -5052,11 +5062,15 @@ var generateContentUrl = (options) => {
5052
5062
  ...getBuilderSearchParamsFromWindow(),
5053
5063
  ...normalizeSearchParams(options.options || {})
5054
5064
  };
5065
+ finalUserAttributes = {
5066
+ ...finalUserAttributes,
5067
+ ...getUserAttributesAsJSON(queryOptions)
5068
+ };
5055
5069
  const flattened = flatten(queryOptions);
5056
5070
  for (const key in flattened) {
5057
5071
  url.searchParams.set(key, String(flattened[key]));
5058
5072
  }
5059
- if (finalUserAttributes) {
5073
+ if (Object.keys(finalUserAttributes).length > 0) {
5060
5074
  url.searchParams.set("userAttributes", JSON.stringify(finalUserAttributes));
5061
5075
  }
5062
5076
  if (query) {
@@ -5069,6 +5083,28 @@ var generateContentUrl = (options) => {
5069
5083
  }
5070
5084
  return url;
5071
5085
  };
5086
+ var getUserAttributesFromQueryOptions = (queryOptions) => {
5087
+ const newUserAttributes = {};
5088
+ for (const key in queryOptions) {
5089
+ if (key.startsWith("userAttributes.")) {
5090
+ newUserAttributes[key] = queryOptions[key];
5091
+ delete queryOptions[key];
5092
+ }
5093
+ }
5094
+ return newUserAttributes;
5095
+ };
5096
+ var getUserAttributesAsJSON = (queryOptions) => {
5097
+ if (isBrowser() && queryOptions["preview"] === "BUILDER_STUDIO") {
5098
+ queryOptions["userAttributes.urlPath"] = window.location.pathname;
5099
+ queryOptions["userAttributes.host"] = window.location.host;
5100
+ const queryOptionsForUserAttributes = getUserAttributesFromQueryOptions(queryOptions);
5101
+ const {
5102
+ userAttributes
5103
+ } = unflatten(queryOptionsForUserAttributes);
5104
+ return userAttributes;
5105
+ }
5106
+ return {};
5107
+ };
5072
5108
 
5073
5109
  // src/functions/get-content/index.ts
5074
5110
  var checkContentHasResults = (content) => "results" in content;
@@ -5870,11 +5906,16 @@ function EnableEditor(props) {
5870
5906
  const searchParamPreviewModel = searchParams.get("builder.preview");
5871
5907
  const searchParamPreviewId = searchParams.get(`builder.overrides.${searchParamPreviewModel}`);
5872
5908
  const previewApiKey = searchParams.get("apiKey") || searchParams.get("builder.space");
5873
- if (searchParamPreviewModel === props.model && previewApiKey === props.apiKey && (!props.content || searchParamPreviewId === props.content.id)) {
5909
+ if (searchParamPreviewModel === "BUILDER_STUDIO" || searchParamPreviewModel === props.model && previewApiKey === props.apiKey && (!props.content || searchParamPreviewId === props.content.id)) {
5874
5910
  fetchOneEntry({
5875
- model: props.model,
5911
+ model: props.model || "",
5876
5912
  apiKey: props.apiKey,
5877
- apiVersion: props.builderContextSignal.apiVersion
5913
+ apiVersion: props.builderContextSignal.apiVersion,
5914
+ ...searchParamPreviewModel === "BUILDER_STUDIO" && props.context?.symbolId ? {
5915
+ query: {
5916
+ id: props.context.symbolId
5917
+ }
5918
+ } : {}
5878
5919
  }).then((content) => {
5879
5920
  if (content) {
5880
5921
  mergeNewContent(content);