@builder.io/sdk-solid 3.0.0 → 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.
@@ -95,7 +95,8 @@ var builder_context_default = createContext({
95
95
  inheritedStyles: {},
96
96
  BlocksWrapper: "div",
97
97
  BlocksWrapperProps: {},
98
- nonce: ""
98
+ nonce: "",
99
+ model: ""
99
100
  });
100
101
 
101
102
  // src/context/components.context.ts
@@ -111,23 +112,6 @@ import {
111
112
  createSignal as createSignal5
112
113
  } from "solid-js";
113
114
 
114
- // src/functions/get-block-component-options.ts
115
- function getBlockComponentOptions(block) {
116
- return {
117
- ...block.component?.options,
118
- ...block.options
119
- };
120
- }
121
-
122
- // src/helpers/omit.ts
123
- function omit(obj, ...values) {
124
- const newObject = Object.assign({}, obj);
125
- for (const key of values) {
126
- delete newObject[key];
127
- }
128
- return newObject;
129
- }
130
-
131
115
  // src/helpers/logger.ts
132
116
  var MSG_PREFIX = "[Builder.io]: ";
133
117
  var logger = {
@@ -394,6 +378,109 @@ function evaluate({
394
378
  }
395
379
  }
396
380
 
381
+ // src/functions/get-block-component-options.ts
382
+ function getBlockComponentOptions(block, context) {
383
+ return {
384
+ ...block.component?.options,
385
+ ...block.options,
386
+ ...evaluateTextComponentTextOption(block, context)
387
+ };
388
+ }
389
+ var evaluateTextComponentTextOption = (block, context) => {
390
+ if (block.component?.name === "Text" && block.component.options?.text && typeof block.component.options.text === "string") {
391
+ return {
392
+ ...block.component.options,
393
+ text: block.component.options.text.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({
394
+ code: group,
395
+ context,
396
+ localState: context.localState,
397
+ rootState: context.rootState,
398
+ rootSetState: context.rootSetState
399
+ }))
400
+ };
401
+ }
402
+ };
403
+
404
+ // src/helpers/omit.ts
405
+ function omit(obj, ...values) {
406
+ const newObject = Object.assign({}, obj);
407
+ for (const key of values) {
408
+ delete newObject[key];
409
+ }
410
+ return newObject;
411
+ }
412
+
413
+ // src/functions/traverse.ts
414
+ function traverse(obj, callback, parent2 = null, key = null, visited = /* @__PURE__ */ new WeakSet()) {
415
+ if (obj == null || typeof obj !== "object") {
416
+ callback(obj, (newValue) => {
417
+ if (parent2 !== null && key !== null) {
418
+ parent2[key] = newValue;
419
+ }
420
+ });
421
+ return;
422
+ }
423
+ if (visited.has(obj)) {
424
+ return;
425
+ }
426
+ visited.add(obj);
427
+ if (Array.isArray(obj)) {
428
+ obj.forEach((item, index) => {
429
+ const update = (newValue) => {
430
+ obj[index] = newValue;
431
+ };
432
+ callback(item, update);
433
+ traverse(item, callback, obj, index, visited);
434
+ });
435
+ } else {
436
+ Object.entries(obj).forEach(([key2, value]) => {
437
+ const update = (newValue) => {
438
+ obj[key2] = newValue;
439
+ };
440
+ callback(value, update);
441
+ traverse(value, callback, obj, key2, visited);
442
+ });
443
+ }
444
+ }
445
+
446
+ // src/functions/extract-localized-values.ts
447
+ function isLocalizedField(value) {
448
+ return value && typeof value === "object" && value["@type"] === "@builder.io/core:LocalizedValue";
449
+ }
450
+ function containsLocalizedValues(data) {
451
+ if (!data || !Object.getOwnPropertyNames(data).length) {
452
+ return false;
453
+ }
454
+ let hasLocalizedValues = false;
455
+ traverse(data, (value) => {
456
+ if (isLocalizedField(value)) {
457
+ hasLocalizedValues = true;
458
+ return;
459
+ }
460
+ });
461
+ return hasLocalizedValues;
462
+ }
463
+ function extractLocalizedValues(data, locale) {
464
+ if (!data || !Object.getOwnPropertyNames(data).length) {
465
+ return {};
466
+ }
467
+ traverse(data, (value, update) => {
468
+ if (isLocalizedField(value)) {
469
+ update(value[locale] ?? void 0);
470
+ }
471
+ });
472
+ return data;
473
+ }
474
+ function resolveLocalizedValues(block, locale) {
475
+ if (block.component?.options && containsLocalizedValues(block.component?.options)) {
476
+ if (!locale) {
477
+ console.warn("[Builder.io] In order to use localized fields in Builder, you must pass a locale prop to the BuilderComponent or to options object while fetching the content to resolve localized fields. Learn more: https://www.builder.io/c/docs/localization-inline#targeting-and-inline-localization");
478
+ }
479
+ block.component.options = extractLocalizedValues(block.component.options, locale ?? "Default");
480
+ }
481
+ return block;
482
+ }
483
+
397
484
  // src/functions/fast-clone.ts
398
485
  var fastClone = (obj) => JSON.parse(JSON.stringify(obj));
399
486
 
@@ -487,23 +574,19 @@ var evaluateBindings = ({
487
574
  function getProcessedBlock({
488
575
  block,
489
576
  context,
490
- shouldEvaluateBindings,
491
577
  localState,
492
578
  rootState,
493
579
  rootSetState
494
580
  }) {
495
- const transformedBlock = transformBlock(block);
496
- if (shouldEvaluateBindings) {
497
- return evaluateBindings({
498
- block: transformedBlock,
499
- localState,
500
- rootState,
501
- rootSetState,
502
- context
503
- });
504
- } else {
505
- return transformedBlock;
506
- }
581
+ let transformedBlock = resolveLocalizedValues(block, rootState.locale);
582
+ transformedBlock = transformBlock(transformedBlock);
583
+ return evaluateBindings({
584
+ block: transformedBlock,
585
+ localState,
586
+ rootState,
587
+ rootSetState,
588
+ context
589
+ });
507
590
  }
508
591
 
509
592
  // src/functions/camel-to-kebab-case.ts
@@ -750,16 +833,24 @@ function mapStyleObjToStrIfNeeded(style) {
750
833
  }
751
834
 
752
835
  // src/components/block/block.helpers.ts
836
+ var checkIsComponentRestricted = (component, model) => {
837
+ if (!component)
838
+ return true;
839
+ if (!model)
840
+ return false;
841
+ return component.models && component.models.length > 0 && !component.models.includes(model);
842
+ };
753
843
  var getComponent = ({
754
844
  block,
755
- registeredComponents
845
+ registeredComponents,
846
+ model
756
847
  }) => {
757
848
  const componentName = block.component?.name;
758
849
  if (!componentName) {
759
850
  return null;
760
851
  }
761
852
  const ref = registeredComponents[componentName];
762
- if (!ref) {
853
+ if (!ref || checkIsComponentRestricted(ref, model)) {
763
854
  console.warn(`
764
855
  Could not find a registered component named "${componentName}".
765
856
  If you registered it, is the file that registered it imported by the file that needs to render it?`);
@@ -813,11 +904,15 @@ var provideLinkComponent = (block, linkComponent) => {
813
904
  };
814
905
  return {};
815
906
  };
816
- var provideRegisteredComponents = (block, registeredComponents) => {
817
- if (block?.shouldReceiveBuilderProps?.builderComponents)
907
+ var provideRegisteredComponents = (block, registeredComponents, model) => {
908
+ if (block?.shouldReceiveBuilderProps?.builderComponents) {
909
+ const filteredRegisteredComponents = Object.fromEntries(Object.entries(registeredComponents).filter(([_, component]) => {
910
+ return !checkIsComponentRestricted(component, model);
911
+ }));
818
912
  return {
819
- builderComponents: registeredComponents
913
+ builderComponents: filteredRegisteredComponents
820
914
  };
915
+ }
821
916
  return {};
822
917
  };
823
918
  var provideBuilderBlock = (block, builderBlock) => {
@@ -1213,15 +1308,15 @@ function Block(props) {
1213
1308
  localState: props.context.localState,
1214
1309
  rootState: props.context.rootState,
1215
1310
  rootSetState: props.context.rootSetState,
1216
- context: props.context.context,
1217
- shouldEvaluateBindings: true
1311
+ context: props.context.context
1218
1312
  });
1219
1313
  return blockToUse;
1220
1314
  });
1221
1315
  const blockComponent = createMemo5(() => {
1222
1316
  return getComponent({
1223
1317
  block: processedBlock(),
1224
- registeredComponents: props.registeredComponents
1318
+ registeredComponents: props.registeredComponents,
1319
+ model: props.context.model
1225
1320
  });
1226
1321
  });
1227
1322
  const Tag = createMemo5(() => {
@@ -1250,13 +1345,14 @@ function Block(props) {
1250
1345
  blockChildren: processedBlock().children ?? [],
1251
1346
  componentRef: blockComponent()?.component,
1252
1347
  componentOptions: {
1253
- ...getBlockComponentOptions(processedBlock()),
1348
+ ...getBlockComponentOptions(processedBlock(), props.context),
1254
1349
  ...provideBuilderBlock(blockComponent(), processedBlock()),
1255
1350
  ...provideBuilderContext(blockComponent(), props.context),
1256
1351
  ...provideLinkComponent(blockComponent(), props.linkComponent),
1257
1352
  ...provideRegisteredComponents(
1258
1353
  blockComponent(),
1259
- props.registeredComponents
1354
+ props.registeredComponents,
1355
+ props.context.model
1260
1356
  )
1261
1357
  },
1262
1358
  context: props.context,
@@ -1680,7 +1776,7 @@ function Image(props) {
1680
1776
  const url = imageToUse;
1681
1777
  if (!url || // We can auto add srcset for cdn.builder.io and shopify
1682
1778
  // images, otherwise you can supply this prop manually
1683
- !(url.match(/builder\.io/) || url.match(/cdn\.shopify\.com/))) {
1779
+ !(typeof url === "string" && (url.match(/builder\.io/) || url.match(/cdn\.shopify\.com/)))) {
1684
1780
  return props.srcset;
1685
1781
  }
1686
1782
  if (props.noWebp) {
@@ -1721,7 +1817,7 @@ function Image(props) {
1721
1817
  <picture>
1722
1818
  <Show8 when={webpSrcSet()}><source type="image/webp" srcset={webpSrcSet()} /></Show8>
1723
1819
  <img
1724
- class={"builder-image" + (props.className ? " " + props.className : "") + " img-7e6ffddc"}
1820
+ class={"builder-image" + (props.className ? " " + props.className : "") + " img-070d7e88"}
1725
1821
  loading={props.highPriority ? "eager" : "lazy"}
1726
1822
  fetchpriority={props.highPriority ? "high" : "auto"}
1727
1823
  alt={props.altText}
@@ -1739,22 +1835,22 @@ function Image(props) {
1739
1835
  <Show8
1740
1836
  when={props.aspectRatio && !(props.builderBlock?.children?.length && props.fitContent)}
1741
1837
  ><div
1742
- class="builder-image-sizer div-7e6ffddc"
1838
+ class="builder-image-sizer div-070d7e88"
1743
1839
  style={{
1744
1840
  "padding-top": props.aspectRatio * 100 + "%"
1745
1841
  }}
1746
1842
  /></Show8>
1747
1843
  <Show8 when={props.builderBlock?.children?.length && props.fitContent}>{props.children}</Show8>
1748
- <Show8 when={!props.fitContent && props.builderBlock?.children?.length}><div class="div-7e6ffddc-2">{props.children}</div></Show8>
1844
+ <Show8 when={!props.fitContent && props.builderBlock?.children?.length}><div class="div-070d7e88-2">{props.children}</div></Show8>
1749
1845
  </>
1750
- <style>{`.img-7e6ffddc {
1846
+ <style>{`.img-070d7e88 {
1751
1847
  opacity: 1;
1752
1848
  transition: opacity 0.2s ease-in-out;
1753
- }.div-7e6ffddc {
1849
+ }.div-070d7e88 {
1754
1850
  width: 100%;
1755
1851
  pointer-events: none;
1756
1852
  font-size: 0;
1757
- }.div-7e6ffddc-2 {
1853
+ }.div-070d7e88-2 {
1758
1854
  display: flex;
1759
1855
  flex-direction: column;
1760
1856
  align-items: stretch;
@@ -1790,10 +1886,10 @@ function SectionComponent(props) {
1790
1886
  var section_default = SectionComponent;
1791
1887
 
1792
1888
  // src/blocks/symbol/symbol.tsx
1793
- import { onMount as onMount8, on as on4, createEffect as createEffect4, createMemo as createMemo20, createSignal as createSignal20 } from "solid-js";
1889
+ import { onMount as onMount8, on as on4, createEffect as createEffect4, createMemo as createMemo19, createSignal as createSignal19 } from "solid-js";
1794
1890
 
1795
1891
  // src/components/content-variants/content-variants.tsx
1796
- import { Show as Show15, For as For9, onMount as onMount7, createSignal as createSignal19, createMemo as createMemo19 } from "solid-js";
1892
+ import { Show as Show15, For as For9, onMount as onMount7, createSignal as createSignal18, createMemo as createMemo18 } from "solid-js";
1797
1893
 
1798
1894
  // src/helpers/url.ts
1799
1895
  var getTopLevelDomain = (host) => {
@@ -1987,7 +2083,7 @@ var handleABTesting = async ({
1987
2083
  var getDefaultCanTrack = (canTrack) => checkIsDefined(canTrack) ? canTrack : true;
1988
2084
 
1989
2085
  // src/components/content/content.tsx
1990
- import { Show as Show14, createSignal as createSignal18 } from "solid-js";
2086
+ import { Show as Show14, createSignal as createSignal17 } from "solid-js";
1991
2087
 
1992
2088
  // src/blocks/accordion/component-info.ts
1993
2089
  var defaultTitle = {
@@ -2547,6 +2643,10 @@ var componentInfo4 = {
2547
2643
  noWrap: true
2548
2644
  };
2549
2645
 
2646
+ // src/constants/file-types.ts
2647
+ var IMAGE_FILE_TYPES = ["jpeg", "jpg", "png", "svg", "webp", "gif", "jfif", "pjpeg", "pjp", "apng", "avif", "tif", "tiff", "heif", "bmp", "eps", "raw", "cr2", "nef", "orf", "sr2", "psd", "heic", "dib", "ai"];
2648
+ var VIDEO_FILE_TYPES = ["mp4", "webm", "mkv", "flv", "vob", "ogv", "ogg", "drc", "gif", "gifv", "mng", "avi", "mov", "qt", "mts", "m2ts", "ts", "wmv", "yuv", "rm", "rmvb", "viv", "asf", "amv", "m4p", "mpeg", "mpe", "m2v", "m4v", "svi", "3gp", "3g2", "mxf", "roq", "nsv", "f4v", "f4p", "f4a", "f4b"];
2649
+
2550
2650
  // src/blocks/image/component-info.ts
2551
2651
  var componentInfo5 = {
2552
2652
  name: "Image",
@@ -2563,7 +2663,7 @@ var componentInfo5 = {
2563
2663
  name: "image",
2564
2664
  type: "file",
2565
2665
  bubble: true,
2566
- allowedFileTypes: ["jpeg", "jpg", "png", "svg", "webp"],
2666
+ allowedFileTypes: IMAGE_FILE_TYPES,
2567
2667
  required: true,
2568
2668
  defaultValue: "https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F72c80f114dc149019051b6852a9e3b7a",
2569
2669
  onChange: (options) => {
@@ -3028,30 +3128,10 @@ var componentInfo10 = {
3028
3128
  };
3029
3129
 
3030
3130
  // src/blocks/text/text.tsx
3031
- import { createMemo as createMemo11 } from "solid-js";
3032
3131
  function Text(props) {
3033
- const processedText = createMemo11(() => {
3034
- const context = props.builderContext;
3035
- const {
3036
- context: contextContext,
3037
- localState,
3038
- rootState,
3039
- rootSetState
3040
- } = context;
3041
- return String(props.text?.toString() || "").replace(
3042
- /{{([^}]+)}}/g,
3043
- (match, group) => evaluate({
3044
- code: group,
3045
- context: contextContext,
3046
- localState,
3047
- rootState,
3048
- rootSetState
3049
- })
3050
- );
3051
- });
3052
3132
  return <><div
3053
3133
  class="builder-text"
3054
- innerHTML={processedText()}
3134
+ innerHTML={props.text?.toString() || ""}
3055
3135
  style={{
3056
3136
  outline: "none"
3057
3137
  }}
@@ -3085,10 +3165,10 @@ var componentInfo11 = {
3085
3165
  };
3086
3166
 
3087
3167
  // src/blocks/custom-code/custom-code.tsx
3088
- import { onMount as onMount5, createSignal as createSignal12 } from "solid-js";
3168
+ import { onMount as onMount5, createSignal as createSignal11 } from "solid-js";
3089
3169
  function CustomCode(props) {
3090
- const [scriptsInserted, setScriptsInserted] = createSignal12([]);
3091
- const [scriptsRun, setScriptsRun] = createSignal12([]);
3170
+ const [scriptsInserted, setScriptsInserted] = createSignal11([]);
3171
+ const [scriptsRun, setScriptsRun] = createSignal11([]);
3092
3172
  let elementRef;
3093
3173
  onMount5(() => {
3094
3174
  if (!elementRef?.getElementsByTagName || typeof window === "undefined") {
@@ -3150,7 +3230,7 @@ var componentInfo12 = {
3150
3230
  };
3151
3231
 
3152
3232
  // src/blocks/embed/embed.tsx
3153
- import { on as on2, createEffect as createEffect2, createMemo as createMemo13, createSignal as createSignal13 } from "solid-js";
3233
+ import { on as on2, createEffect as createEffect2, createMemo as createMemo12, createSignal as createSignal12 } from "solid-js";
3154
3234
 
3155
3235
  // src/blocks/embed/helpers.ts
3156
3236
  var SCRIPT_MIME_TYPES = ["text/javascript", "application/javascript", "application/ecmascript"];
@@ -3158,9 +3238,9 @@ var isJsScript = (script) => SCRIPT_MIME_TYPES.includes(script.type);
3158
3238
 
3159
3239
  // src/blocks/embed/embed.tsx
3160
3240
  function Embed(props) {
3161
- const [scriptsInserted, setScriptsInserted] = createSignal13([]);
3162
- const [scriptsRun, setScriptsRun] = createSignal13([]);
3163
- const [ranInitFn, setRanInitFn] = createSignal13(false);
3241
+ const [scriptsInserted, setScriptsInserted] = createSignal12([]);
3242
+ const [scriptsRun, setScriptsRun] = createSignal12([]);
3243
+ const [ranInitFn, setRanInitFn] = createSignal12(false);
3164
3244
  function findAndRunScripts() {
3165
3245
  if (!elem || !elem.getElementsByTagName)
3166
3246
  return;
@@ -3184,8 +3264,8 @@ function Embed(props) {
3184
3264
  }
3185
3265
  }
3186
3266
  let elem;
3187
- const onUpdateFn_0_elem = createMemo13(() => elem);
3188
- const onUpdateFn_0_ranInitFn__ = createMemo13(() => ranInitFn());
3267
+ const onUpdateFn_0_elem = createMemo12(() => elem);
3268
+ const onUpdateFn_0_ranInitFn__ = createMemo12(() => ranInitFn());
3189
3269
  function onUpdateFn_0() {
3190
3270
  if (elem && !ranInitFn()) {
3191
3271
  setRanInitFn(true);
@@ -3440,7 +3520,7 @@ var componentInfo13 = {
3440
3520
  };
3441
3521
 
3442
3522
  // src/blocks/form/form/form.tsx
3443
- import { Show as Show11, For as For7, createSignal as createSignal14 } from "solid-js";
3523
+ import { Show as Show11, For as For7, createSignal as createSignal13 } from "solid-js";
3444
3524
 
3445
3525
  // src/functions/get-env.ts
3446
3526
  var validEnvList = ["production", "qa", "test", "development", "dev", "cdn-qa", "cloud", "fast", "cdn2", "cdn-prod"];
@@ -3460,9 +3540,9 @@ function logFetch(url) {
3460
3540
 
3461
3541
  // src/blocks/form/form/form.tsx
3462
3542
  function FormComponent(props) {
3463
- const [formState, setFormState] = createSignal14("unsubmitted");
3464
- const [responseData, setResponseData] = createSignal14(null);
3465
- const [formErrorMessage, setFormErrorMessage] = createSignal14("");
3543
+ const [formState, setFormState] = createSignal13("unsubmitted");
3544
+ const [responseData, setResponseData] = createSignal13(null);
3545
+ const [formErrorMessage, setFormErrorMessage] = createSignal13("");
3466
3546
  function mergeNewRootState(newData) {
3467
3547
  const combinedState = {
3468
3548
  ...props.builderContext.rootState,
@@ -3923,7 +4003,7 @@ var componentInfo18 = {
3923
4003
  name: "image",
3924
4004
  bubble: true,
3925
4005
  type: "file",
3926
- allowedFileTypes: ["jpeg", "jpg", "png", "svg", "gif", "webp"],
4006
+ allowedFileTypes: IMAGE_FILE_TYPES,
3927
4007
  required: true
3928
4008
  }],
3929
4009
  noWrap: true,
@@ -3958,14 +4038,14 @@ var componentInfo19 = {
3958
4038
  inputs: [{
3959
4039
  name: "video",
3960
4040
  type: "file",
3961
- allowedFileTypes: ["mp4"],
4041
+ allowedFileTypes: VIDEO_FILE_TYPES,
3962
4042
  bubble: true,
3963
4043
  defaultValue: "https://cdn.builder.io/o/assets%2FYJIGb4i01jvw0SRdL5Bt%2Fd27731a526464deba0016216f5f9e570%2Fcompressed?apiKey=YJIGb4i01jvw0SRdL5Bt&token=d27731a526464deba0016216f5f9e570&alt=media&optimized=true",
3964
4044
  required: true
3965
4045
  }, {
3966
4046
  name: "posterImage",
3967
4047
  type: "file",
3968
- allowedFileTypes: ["jpeg", "png"],
4048
+ allowedFileTypes: IMAGE_FILE_TYPES,
3969
4049
  helperText: "Image to show before the video plays"
3970
4050
  }, {
3971
4051
  name: "autoPlay",
@@ -4034,9 +4114,9 @@ var componentInfo19 = {
4034
4114
  };
4035
4115
 
4036
4116
  // src/blocks/video/video.tsx
4037
- import { Show as Show12, createMemo as createMemo15 } from "solid-js";
4117
+ import { Show as Show12, createMemo as createMemo14 } from "solid-js";
4038
4118
  function Video(props) {
4039
- const videoProps = createMemo15(() => {
4119
+ const videoProps = createMemo14(() => {
4040
4120
  return {
4041
4121
  ...props.autoPlay === true ? {
4042
4122
  autoPlay: true
@@ -4055,7 +4135,7 @@ function Video(props) {
4055
4135
  } : {}
4056
4136
  };
4057
4137
  });
4058
- const spreadProps = createMemo15(() => {
4138
+ const spreadProps = createMemo14(() => {
4059
4139
  return {
4060
4140
  ...videoProps()
4061
4141
  };
@@ -4191,7 +4271,7 @@ var createRegisterComponentMessage = (info) => ({
4191
4271
  var serializeFn = (fnValue) => {
4192
4272
  const fnStr = fnValue.toString().trim();
4193
4273
  const isArrowWithoutParens = /^[a-zA-Z0-9_]+\s*=>/i.test(fnStr);
4194
- const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("(") && !isArrowWithoutParens;
4274
+ const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("async") && !fnStr.startsWith("(") && !isArrowWithoutParens;
4195
4275
  return `return (${appendFunction ? "function " : ""}${fnStr}).apply(this, arguments)`;
4196
4276
  };
4197
4277
  function serializeIncludingFunctions(info) {
@@ -4265,8 +4345,8 @@ import {
4265
4345
  onMount as onMount6,
4266
4346
  on as on3,
4267
4347
  createEffect as createEffect3,
4268
- createMemo as createMemo16,
4269
- createSignal as createSignal16
4348
+ createMemo as createMemo15,
4349
+ createSignal as createSignal15
4270
4350
  } from "solid-js";
4271
4351
  import { Dynamic as Dynamic5 } from "solid-js/web";
4272
4352
 
@@ -4276,7 +4356,7 @@ function getPreviewContent(_searchParams) {
4276
4356
  }
4277
4357
 
4278
4358
  // src/constants/sdk-version.ts
4279
- var SDK_VERSION = "3.0.0";
4359
+ var SDK_VERSION = "3.0.2";
4280
4360
 
4281
4361
  // src/helpers/sdk-headers.ts
4282
4362
  var getSdkHeaders = () => ({
@@ -4341,6 +4421,23 @@ function flattenMongoQuery(obj, _current, _res = {}) {
4341
4421
  }
4342
4422
  return _res;
4343
4423
  }
4424
+ function unflatten(obj) {
4425
+ const result = {};
4426
+ for (const key in obj) {
4427
+ const parts = key.split(".");
4428
+ let current = result;
4429
+ for (let i = 0; i < parts.length; i++) {
4430
+ const part = parts[i];
4431
+ if (i === parts.length - 1) {
4432
+ current[part] = obj[key];
4433
+ } else {
4434
+ current[part] = current[part] || {};
4435
+ current = current[part];
4436
+ }
4437
+ }
4438
+ }
4439
+ return result;
4440
+ }
4344
4441
 
4345
4442
  // src/types/api-version.ts
4346
4443
  var DEFAULT_API_VERSION = "v3";
@@ -4405,7 +4502,7 @@ var generateContentUrl = (options) => {
4405
4502
  url.searchParams.set("noTraverse", String(noTraverse));
4406
4503
  url.searchParams.set("includeRefs", String(true));
4407
4504
  const finalLocale = locale || userAttributes?.locale;
4408
- let finalUserAttributes = userAttributes;
4505
+ let finalUserAttributes = userAttributes || {};
4409
4506
  if (finalLocale) {
4410
4507
  url.searchParams.set("locale", finalLocale);
4411
4508
  finalUserAttributes = {
@@ -4443,11 +4540,15 @@ var generateContentUrl = (options) => {
4443
4540
  ...getBuilderSearchParamsFromWindow(),
4444
4541
  ...normalizeSearchParams(options.options || {})
4445
4542
  };
4543
+ finalUserAttributes = {
4544
+ ...finalUserAttributes,
4545
+ ...getUserAttributesAsJSON(queryOptions)
4546
+ };
4446
4547
  const flattened = flatten(queryOptions);
4447
4548
  for (const key in flattened) {
4448
4549
  url.searchParams.set(key, String(flattened[key]));
4449
4550
  }
4450
- if (finalUserAttributes) {
4551
+ if (Object.keys(finalUserAttributes).length > 0) {
4451
4552
  url.searchParams.set("userAttributes", JSON.stringify(finalUserAttributes));
4452
4553
  }
4453
4554
  if (query) {
@@ -4460,6 +4561,28 @@ var generateContentUrl = (options) => {
4460
4561
  }
4461
4562
  return url;
4462
4563
  };
4564
+ var getUserAttributesFromQueryOptions = (queryOptions) => {
4565
+ const newUserAttributes = {};
4566
+ for (const key in queryOptions) {
4567
+ if (key.startsWith("userAttributes.")) {
4568
+ newUserAttributes[key] = queryOptions[key];
4569
+ delete queryOptions[key];
4570
+ }
4571
+ }
4572
+ return newUserAttributes;
4573
+ };
4574
+ var getUserAttributesAsJSON = (queryOptions) => {
4575
+ if (isBrowser() && queryOptions["preview"] === "BUILDER_STUDIO") {
4576
+ queryOptions["userAttributes.urlPath"] = window.location.pathname;
4577
+ queryOptions["userAttributes.host"] = window.location.host;
4578
+ const queryOptionsForUserAttributes = getUserAttributesFromQueryOptions(queryOptions);
4579
+ const {
4580
+ userAttributes
4581
+ } = unflatten(queryOptionsForUserAttributes);
4582
+ return userAttributes;
4583
+ }
4584
+ return {};
4585
+ };
4463
4586
 
4464
4587
  // src/functions/get-content/index.ts
4465
4588
  var checkContentHasResults = (content) => "results" in content;
@@ -4994,6 +5117,12 @@ var subscribeToEditor = (model, callback, options) => {
4994
5117
  };
4995
5118
  };
4996
5119
 
5120
+ // src/components/content/components/enable-editor.helpers.ts
5121
+ var SDKS_USING_ELEMENT_REF_APPROACH = ["svelte", "qwik", "vue"];
5122
+ var needsElementRefDivForEditing = () => {
5123
+ return SDKS_USING_ELEMENT_REF_APPROACH.includes(TARGET) && (isEditing() || isPreviewing());
5124
+ };
5125
+
4997
5126
  // src/components/content/components/styles.helpers.ts
4998
5127
  var getCssFromFont = (font) => {
4999
5128
  const family = font.family + (font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
@@ -5075,12 +5204,12 @@ var getWrapperClassName = (variationId) => {
5075
5204
 
5076
5205
  // src/components/content/components/enable-editor.tsx
5077
5206
  function EnableEditor(props) {
5078
- const [ContentWrapper, setContentWrapper] = createSignal16(
5207
+ const [ContentWrapper, setContentWrapper] = createSignal15(
5079
5208
  props.contentWrapper || "div"
5080
5209
  );
5081
- const [httpReqsData, setHttpReqsData] = createSignal16({});
5082
- const [httpReqsPending, setHttpReqsPending] = createSignal16({});
5083
- const [clicked, setClicked] = createSignal16(false);
5210
+ const [httpReqsData, setHttpReqsData] = createSignal15({});
5211
+ const [httpReqsPending, setHttpReqsPending] = createSignal15({});
5212
+ const [clicked, setClicked] = createSignal15(false);
5084
5213
  function mergeNewRootState(newData) {
5085
5214
  const combinedState = {
5086
5215
  ...props.builderContextSignal.rootState,
@@ -5114,7 +5243,7 @@ function EnableEditor(props) {
5114
5243
  content: newContentValue
5115
5244
  }));
5116
5245
  }
5117
- const showContentProps = createMemo16(() => {
5246
+ const showContentProps = createMemo15(() => {
5118
5247
  return props.showContent ? {} : {
5119
5248
  hidden: true,
5120
5249
  "aria-hidden": true
@@ -5240,8 +5369,10 @@ function EnableEditor(props) {
5240
5369
  Object.values(
5241
5370
  props.builderContextSignal.componentInfos
5242
5371
  ).forEach((registeredComponent) => {
5243
- const message = createRegisterComponentMessage(registeredComponent);
5244
- window.parent?.postMessage(message, "*");
5372
+ if (!props.model || !registeredComponent.models?.length || registeredComponent.models.includes(props.model)) {
5373
+ const message = createRegisterComponentMessage(registeredComponent);
5374
+ window.parent?.postMessage(message, "*");
5375
+ }
5245
5376
  });
5246
5377
  window.addEventListener(
5247
5378
  "builder:component:stateChangeListenerActivated",
@@ -5269,11 +5400,16 @@ function EnableEditor(props) {
5269
5400
  `builder.overrides.${searchParamPreviewModel}`
5270
5401
  );
5271
5402
  const previewApiKey = searchParams.get("apiKey") || searchParams.get("builder.space");
5272
- if (searchParamPreviewModel === props.model && previewApiKey === props.apiKey && (!props.content || searchParamPreviewId === props.content.id)) {
5403
+ if (searchParamPreviewModel === "BUILDER_STUDIO" || searchParamPreviewModel === props.model && previewApiKey === props.apiKey && (!props.content || searchParamPreviewId === props.content.id)) {
5273
5404
  fetchOneEntry({
5274
- model: props.model,
5405
+ model: props.model || "",
5275
5406
  apiKey: props.apiKey,
5276
- apiVersion: props.builderContextSignal.apiVersion
5407
+ apiVersion: props.builderContextSignal.apiVersion,
5408
+ ...searchParamPreviewModel === "BUILDER_STUDIO" && props.context?.symbolId ? {
5409
+ query: {
5410
+ id: props.context.symbolId
5411
+ }
5412
+ } : {}
5277
5413
  }).then((content) => {
5278
5414
  if (content) {
5279
5415
  mergeNewContent(content);
@@ -5283,14 +5419,14 @@ function EnableEditor(props) {
5283
5419
  }
5284
5420
  }
5285
5421
  });
5286
- const onUpdateFn_0_props_content = createMemo16(() => props.content);
5422
+ const onUpdateFn_0_props_content = createMemo15(() => props.content);
5287
5423
  function onUpdateFn_0() {
5288
5424
  if (props.content) {
5289
5425
  mergeNewContent(props.content);
5290
5426
  }
5291
5427
  }
5292
5428
  createEffect3(on3(() => [onUpdateFn_0_props_content()], onUpdateFn_0));
5293
- const onUpdateFn_1_props_builderContextSignal_rootState = createMemo16(
5429
+ const onUpdateFn_1_props_builderContextSignal_rootState = createMemo15(
5294
5430
  () => props.builderContextSignal.rootState
5295
5431
  );
5296
5432
  function onUpdateFn_1() {
@@ -5302,14 +5438,14 @@ function EnableEditor(props) {
5302
5438
  onUpdateFn_1
5303
5439
  )
5304
5440
  );
5305
- const onUpdateFn_2_props_data = createMemo16(() => props.data);
5441
+ const onUpdateFn_2_props_data = createMemo15(() => props.data);
5306
5442
  function onUpdateFn_2() {
5307
5443
  if (props.data) {
5308
5444
  mergeNewRootState(props.data);
5309
5445
  }
5310
5446
  }
5311
5447
  createEffect3(on3(() => [onUpdateFn_2_props_data()], onUpdateFn_2));
5312
- const onUpdateFn_3_props_locale = createMemo16(() => props.locale);
5448
+ const onUpdateFn_3_props_locale = createMemo15(() => props.locale);
5313
5449
  function onUpdateFn_3() {
5314
5450
  if (props.locale) {
5315
5451
  mergeNewRootState({
@@ -5318,7 +5454,9 @@ function EnableEditor(props) {
5318
5454
  }
5319
5455
  }
5320
5456
  createEffect3(on3(() => [onUpdateFn_3_props_locale()], onUpdateFn_3));
5321
- return <><builder_context_default.Provider value={props.builderContextSignal}><Show13 when={props.builderContextSignal.content}><Dynamic5
5457
+ return <><builder_context_default.Provider value={props.builderContextSignal}><Show13
5458
+ when={props.builderContextSignal.content || needsElementRefDivForEditing()}
5459
+ ><Dynamic5
5322
5460
  class={getWrapperClassName(
5323
5461
  props.content?.testVariationId || props.content?.id
5324
5462
  )}
@@ -5327,6 +5465,9 @@ function EnableEditor(props) {
5327
5465
  onClick={(event) => onClick(event)}
5328
5466
  builder-content-id={props.builderContextSignal.content?.id}
5329
5467
  builder-model={props.model}
5468
+ style={{
5469
+ display: !props.builderContextSignal.content && needsElementRefDivForEditing() ? "none" : void 0
5470
+ }}
5330
5471
  {...{}}
5331
5472
  {...showContentProps()}
5332
5473
  {...props.contentWrapperProps}
@@ -5336,9 +5477,9 @@ function EnableEditor(props) {
5336
5477
  var Enable_editor_default = EnableEditor;
5337
5478
 
5338
5479
  // src/components/content/components/styles.tsx
5339
- import { createSignal as createSignal17 } from "solid-js";
5480
+ import { createSignal as createSignal16 } from "solid-js";
5340
5481
  function ContentStyles(props) {
5341
- const [injectedStyles, setInjectedStyles] = createSignal17(
5482
+ const [injectedStyles, setInjectedStyles] = createSignal16(
5342
5483
  `
5343
5484
  ${getCss({
5344
5485
  cssCode: props.cssCode,
@@ -5396,7 +5537,7 @@ var getContentInitialValue = ({
5396
5537
 
5397
5538
  // src/components/content/content.tsx
5398
5539
  function ContentComponent(props) {
5399
- const [scriptStr, setScriptStr] = createSignal18(
5540
+ const [scriptStr, setScriptStr] = createSignal17(
5400
5541
  getUpdateVariantVisibilityScript({
5401
5542
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
5402
5543
  variationId: props.content?.testVariationId,
@@ -5404,16 +5545,10 @@ function ContentComponent(props) {
5404
5545
  contentId: props.content?.id
5405
5546
  })
5406
5547
  );
5407
- const [registeredComponents, setRegisteredComponents] = createSignal18(
5548
+ const [registeredComponents, setRegisteredComponents] = createSignal17(
5408
5549
  [
5409
5550
  ...getDefaultRegisteredComponents(),
5410
- ...props.customComponents?.filter(({ models }) => {
5411
- if (!models?.length)
5412
- return true;
5413
- if (!props.model)
5414
- return true;
5415
- return models.includes(props.model);
5416
- }) || []
5551
+ ...props.customComponents || []
5417
5552
  ].reduce(
5418
5553
  (acc, { component, ...info }) => ({
5419
5554
  ...acc,
@@ -5425,7 +5560,7 @@ function ContentComponent(props) {
5425
5560
  {}
5426
5561
  )
5427
5562
  );
5428
- const [builderContextSignal, setBuilderContextSignal] = createSignal18({
5563
+ const [builderContextSignal, setBuilderContextSignal] = createSignal17({
5429
5564
  content: getContentInitialValue({
5430
5565
  content: props.content,
5431
5566
  data: props.data
@@ -5443,13 +5578,7 @@ function ContentComponent(props) {
5443
5578
  apiVersion: props.apiVersion,
5444
5579
  componentInfos: [
5445
5580
  ...getDefaultRegisteredComponents(),
5446
- ...props.customComponents?.filter(({ models }) => {
5447
- if (!models?.length)
5448
- return true;
5449
- if (!props.model)
5450
- return true;
5451
- return models.includes(props.model);
5452
- }) || []
5581
+ ...props.customComponents || []
5453
5582
  ].reduce(
5454
5583
  (acc, { component: _, ...info }) => ({
5455
5584
  ...acc,
@@ -5460,7 +5589,8 @@ function ContentComponent(props) {
5460
5589
  inheritedStyles: {},
5461
5590
  BlocksWrapper: props.blocksWrapper || "div",
5462
5591
  BlocksWrapperProps: props.blocksWrapperProps || {},
5463
- nonce: props.nonce || ""
5592
+ nonce: props.nonce || "",
5593
+ model: props.model || ""
5464
5594
  });
5465
5595
  function contentSetState(newRootState) {
5466
5596
  setBuilderContextSignal((PREVIOUS_VALUE) => ({
@@ -5538,13 +5668,13 @@ var Content_default = ContentComponent;
5538
5668
 
5539
5669
  // src/components/content-variants/content-variants.tsx
5540
5670
  function ContentVariants(props) {
5541
- const [shouldRenderVariants, setShouldRenderVariants] = createSignal19(
5671
+ const [shouldRenderVariants, setShouldRenderVariants] = createSignal18(
5542
5672
  checkShouldRenderVariants({
5543
5673
  canTrack: getDefaultCanTrack(props.canTrack),
5544
5674
  content: props.content
5545
5675
  })
5546
5676
  );
5547
- const updateCookieAndStylesScriptStr = createMemo19(() => {
5677
+ const updateCookieAndStylesScriptStr = createMemo18(() => {
5548
5678
  return getUpdateCookieAndStylesScript(
5549
5679
  getVariants(props.content).map((value) => ({
5550
5680
  id: value.testVariationId,
@@ -5553,10 +5683,10 @@ function ContentVariants(props) {
5553
5683
  props.content?.id || ""
5554
5684
  );
5555
5685
  });
5556
- const hideVariantsStyleString = createMemo19(() => {
5686
+ const hideVariantsStyleString = createMemo18(() => {
5557
5687
  return getVariants(props.content).map((value) => `.variant-${value.testVariationId} { display: none; } `).join("");
5558
5688
  });
5559
- const defaultContent = createMemo19(() => {
5689
+ const defaultContent = createMemo18(() => {
5560
5690
  return shouldRenderVariants() ? {
5561
5691
  ...props.content,
5562
5692
  testVariationId: props.content?.id
@@ -5668,14 +5798,14 @@ var fetchSymbolContent = async ({
5668
5798
 
5669
5799
  // src/blocks/symbol/symbol.tsx
5670
5800
  function Symbol(props) {
5671
- const [contentToUse, setContentToUse] = createSignal20(props.symbol?.content);
5672
- const blocksWrapper = createMemo20(() => {
5801
+ const [contentToUse, setContentToUse] = createSignal19(props.symbol?.content);
5802
+ const blocksWrapper = createMemo19(() => {
5673
5803
  return "div";
5674
5804
  });
5675
- const contentWrapper = createMemo20(() => {
5805
+ const contentWrapper = createMemo19(() => {
5676
5806
  return "div";
5677
5807
  });
5678
- const className = createMemo20(() => {
5808
+ const className = createMemo19(() => {
5679
5809
  return [
5680
5810
  ...[props.attributes[getClassPropName()]],
5681
5811
  "builder-symbol",
@@ -5697,7 +5827,7 @@ function Symbol(props) {
5697
5827
  }
5698
5828
  onMount8(() => {
5699
5829
  });
5700
- const onUpdateFn_0_props_symbol = createMemo20(() => props.symbol);
5830
+ const onUpdateFn_0_props_symbol = createMemo19(() => props.symbol);
5701
5831
  function onUpdateFn_0() {
5702
5832
  setContent();
5703
5833
  }