@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 = {
@@ -576,6 +560,108 @@ function evaluate({
576
560
  }
577
561
  }
578
562
 
563
+ // src/functions/get-block-component-options.ts
564
+ function getBlockComponentOptions(block, context) {
565
+ return {
566
+ ...block.component?.options,
567
+ ...block.options,
568
+ ...evaluateTextComponentTextOption(block, context)
569
+ };
570
+ }
571
+ var evaluateTextComponentTextOption = (block, context) => {
572
+ if (block.component?.name === "Text" && block.component.options?.text && typeof block.component.options.text === "string") {
573
+ return {
574
+ ...block.component.options,
575
+ text: block.component.options.text.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({
576
+ code: group,
577
+ context,
578
+ localState: context.localState,
579
+ rootState: context.rootState,
580
+ rootSetState: context.rootSetState
581
+ }))
582
+ };
583
+ }
584
+ };
585
+
586
+ // src/helpers/omit.ts
587
+ function omit(obj, ...values) {
588
+ const newObject = Object.assign({}, obj);
589
+ for (const key of values) {
590
+ delete newObject[key];
591
+ }
592
+ return newObject;
593
+ }
594
+
595
+ // src/functions/traverse.ts
596
+ function traverse(obj, callback, parent2 = null, key = null, visited = /* @__PURE__ */ new WeakSet()) {
597
+ if (obj == null || typeof obj !== "object") {
598
+ callback(obj, (newValue) => {
599
+ if (parent2 !== null && key !== null) {
600
+ parent2[key] = newValue;
601
+ }
602
+ });
603
+ return;
604
+ }
605
+ if (visited.has(obj)) {
606
+ return;
607
+ }
608
+ visited.add(obj);
609
+ if (Array.isArray(obj)) {
610
+ obj.forEach((item, index) => {
611
+ const update = (newValue) => {
612
+ obj[index] = newValue;
613
+ };
614
+ callback(item, update);
615
+ traverse(item, callback, obj, index, visited);
616
+ });
617
+ } else {
618
+ Object.entries(obj).forEach(([key2, value]) => {
619
+ const update = (newValue) => {
620
+ obj[key2] = newValue;
621
+ };
622
+ callback(value, update);
623
+ traverse(value, callback, obj, key2, visited);
624
+ });
625
+ }
626
+ }
627
+
628
+ // src/functions/extract-localized-values.ts
629
+ function isLocalizedField(value) {
630
+ return value && typeof value === "object" && value["@type"] === "@builder.io/core:LocalizedValue";
631
+ }
632
+ function containsLocalizedValues(data) {
633
+ if (!data || !Object.getOwnPropertyNames(data).length) {
634
+ return false;
635
+ }
636
+ let hasLocalizedValues = false;
637
+ traverse(data, (value) => {
638
+ if (isLocalizedField(value)) {
639
+ hasLocalizedValues = true;
640
+ return;
641
+ }
642
+ });
643
+ return hasLocalizedValues;
644
+ }
645
+ function extractLocalizedValues(data, locale) {
646
+ if (!data || !Object.getOwnPropertyNames(data).length) {
647
+ return {};
648
+ }
649
+ traverse(data, (value, update) => {
650
+ if (isLocalizedField(value)) {
651
+ update(value[locale] ?? void 0);
652
+ }
653
+ });
654
+ return data;
655
+ }
656
+ function resolveLocalizedValues(block, locale) {
657
+ if (block.component?.options && containsLocalizedValues(block.component?.options)) {
658
+ if (!locale) {
659
+ }
660
+ block.component.options = extractLocalizedValues(block.component.options, locale ?? "Default");
661
+ }
662
+ return block;
663
+ }
664
+
579
665
  // src/functions/transform-block.ts
580
666
  function transformBlock(block) {
581
667
  return block;
@@ -656,23 +742,19 @@ var evaluateBindings = ({
656
742
  function getProcessedBlock({
657
743
  block,
658
744
  context,
659
- shouldEvaluateBindings,
660
745
  localState,
661
746
  rootState,
662
747
  rootSetState
663
748
  }) {
664
- const transformedBlock = transformBlock(block);
665
- if (shouldEvaluateBindings) {
666
- return evaluateBindings({
667
- block: transformedBlock,
668
- localState,
669
- rootState,
670
- rootSetState,
671
- context
672
- });
673
- } else {
674
- return transformedBlock;
675
- }
749
+ let transformedBlock = resolveLocalizedValues(block, rootState.locale);
750
+ transformedBlock = transformBlock(transformedBlock);
751
+ return evaluateBindings({
752
+ block: transformedBlock,
753
+ localState,
754
+ rootState,
755
+ rootSetState,
756
+ context
757
+ });
676
758
  }
677
759
 
678
760
  // src/functions/camel-to-kebab-case.ts
@@ -918,16 +1000,24 @@ function mapStyleObjToStrIfNeeded(style) {
918
1000
  }
919
1001
 
920
1002
  // src/components/block/block.helpers.ts
1003
+ var checkIsComponentRestricted = (component, model) => {
1004
+ if (!component)
1005
+ return true;
1006
+ if (!model)
1007
+ return false;
1008
+ return component.models && component.models.length > 0 && !component.models.includes(model);
1009
+ };
921
1010
  var getComponent = ({
922
1011
  block,
923
- registeredComponents
1012
+ registeredComponents,
1013
+ model
924
1014
  }) => {
925
1015
  const componentName = block.component?.name;
926
1016
  if (!componentName) {
927
1017
  return null;
928
1018
  }
929
1019
  const ref = registeredComponents[componentName];
930
- if (!ref) {
1020
+ if (!ref || checkIsComponentRestricted(ref, model)) {
931
1021
  return void 0;
932
1022
  } else {
933
1023
  return ref;
@@ -978,11 +1068,15 @@ var provideLinkComponent = (block, linkComponent) => {
978
1068
  };
979
1069
  return {};
980
1070
  };
981
- var provideRegisteredComponents = (block, registeredComponents) => {
982
- if (block?.shouldReceiveBuilderProps?.builderComponents)
1071
+ var provideRegisteredComponents = (block, registeredComponents, model) => {
1072
+ if (block?.shouldReceiveBuilderProps?.builderComponents) {
1073
+ const filteredRegisteredComponents = Object.fromEntries(Object.entries(registeredComponents).filter(([_, component]) => {
1074
+ return !checkIsComponentRestricted(component, model);
1075
+ }));
983
1076
  return {
984
- builderComponents: registeredComponents
1077
+ builderComponents: filteredRegisteredComponents
985
1078
  };
1079
+ }
986
1080
  return {};
987
1081
  };
988
1082
  var provideBuilderBlock = (block, builderBlock) => {
@@ -1378,15 +1472,15 @@ function Block(props) {
1378
1472
  localState: props.context.localState,
1379
1473
  rootState: props.context.rootState,
1380
1474
  rootSetState: props.context.rootSetState,
1381
- context: props.context.context,
1382
- shouldEvaluateBindings: true
1475
+ context: props.context.context
1383
1476
  });
1384
1477
  return blockToUse;
1385
1478
  });
1386
1479
  const blockComponent = createMemo5(() => {
1387
1480
  return getComponent({
1388
1481
  block: processedBlock(),
1389
- registeredComponents: props.registeredComponents
1482
+ registeredComponents: props.registeredComponents,
1483
+ model: props.context.model
1390
1484
  });
1391
1485
  });
1392
1486
  const Tag = createMemo5(() => {
@@ -1415,13 +1509,14 @@ function Block(props) {
1415
1509
  blockChildren: processedBlock().children ?? [],
1416
1510
  componentRef: blockComponent()?.component,
1417
1511
  componentOptions: {
1418
- ...getBlockComponentOptions(processedBlock()),
1512
+ ...getBlockComponentOptions(processedBlock(), props.context),
1419
1513
  ...provideBuilderBlock(blockComponent(), processedBlock()),
1420
1514
  ...provideBuilderContext(blockComponent(), props.context),
1421
1515
  ...provideLinkComponent(blockComponent(), props.linkComponent),
1422
1516
  ...provideRegisteredComponents(
1423
1517
  blockComponent(),
1424
- props.registeredComponents
1518
+ props.registeredComponents,
1519
+ props.context.model
1425
1520
  )
1426
1521
  },
1427
1522
  context: props.context,
@@ -1845,7 +1940,7 @@ function Image(props) {
1845
1940
  const url = imageToUse;
1846
1941
  if (!url || // We can auto add srcset for cdn.builder.io and shopify
1847
1942
  // images, otherwise you can supply this prop manually
1848
- !(url.match(/builder\.io/) || url.match(/cdn\.shopify\.com/))) {
1943
+ !(typeof url === "string" && (url.match(/builder\.io/) || url.match(/cdn\.shopify\.com/)))) {
1849
1944
  return props.srcset;
1850
1945
  }
1851
1946
  if (props.noWebp) {
@@ -1885,7 +1980,7 @@ function Image(props) {
1885
1980
  <picture>
1886
1981
  <Show8 when={webpSrcSet()}><source type="image/webp" srcset={webpSrcSet()} /></Show8>
1887
1982
  <img
1888
- class={"builder-image" + (props.className ? " " + props.className : "") + " img-7e6ffddc"}
1983
+ class={"builder-image" + (props.className ? " " + props.className : "") + " img-070d7e88"}
1889
1984
  loading={props.highPriority ? "eager" : "lazy"}
1890
1985
  fetchpriority={props.highPriority ? "high" : "auto"}
1891
1986
  alt={props.altText}
@@ -1903,22 +1998,22 @@ function Image(props) {
1903
1998
  <Show8
1904
1999
  when={props.aspectRatio && !(props.builderBlock?.children?.length && props.fitContent)}
1905
2000
  ><div
1906
- class="builder-image-sizer div-7e6ffddc"
2001
+ class="builder-image-sizer div-070d7e88"
1907
2002
  style={{
1908
2003
  "padding-top": props.aspectRatio * 100 + "%"
1909
2004
  }}
1910
2005
  /></Show8>
1911
2006
  <Show8 when={props.builderBlock?.children?.length && props.fitContent}>{props.children}</Show8>
1912
- <Show8 when={!props.fitContent && props.builderBlock?.children?.length}><div class="div-7e6ffddc-2">{props.children}</div></Show8>
2007
+ <Show8 when={!props.fitContent && props.builderBlock?.children?.length}><div class="div-070d7e88-2">{props.children}</div></Show8>
1913
2008
  </>
1914
- <style>{`.img-7e6ffddc {
2009
+ <style>{`.img-070d7e88 {
1915
2010
  opacity: 1;
1916
2011
  transition: opacity 0.2s ease-in-out;
1917
- }.div-7e6ffddc {
2012
+ }.div-070d7e88 {
1918
2013
  width: 100%;
1919
2014
  pointer-events: none;
1920
2015
  font-size: 0;
1921
- }.div-7e6ffddc-2 {
2016
+ }.div-070d7e88-2 {
1922
2017
  display: flex;
1923
2018
  flex-direction: column;
1924
2019
  align-items: stretch;
@@ -1954,10 +2049,10 @@ function SectionComponent(props) {
1954
2049
  var section_default = SectionComponent;
1955
2050
 
1956
2051
  // src/blocks/symbol/symbol.tsx
1957
- import { onMount as onMount8, on as on4, createEffect as createEffect4, createMemo as createMemo20, createSignal as createSignal20 } from "solid-js";
2052
+ import { onMount as onMount8, on as on4, createEffect as createEffect4, createMemo as createMemo19, createSignal as createSignal19 } from "solid-js";
1958
2053
 
1959
2054
  // src/components/content-variants/content-variants.tsx
1960
- import { Show as Show15, For as For9, onMount as onMount7, createSignal as createSignal19, createMemo as createMemo19 } from "solid-js";
2055
+ import { Show as Show15, For as For9, onMount as onMount7, createSignal as createSignal18, createMemo as createMemo18 } from "solid-js";
1961
2056
 
1962
2057
  // src/helpers/url.ts
1963
2058
  var getTopLevelDomain = (host) => {
@@ -2151,7 +2246,7 @@ var handleABTesting = async ({
2151
2246
  var getDefaultCanTrack = (canTrack) => checkIsDefined(canTrack) ? canTrack : true;
2152
2247
 
2153
2248
  // src/components/content/content.tsx
2154
- import { Show as Show14, createSignal as createSignal18 } from "solid-js";
2249
+ import { Show as Show14, createSignal as createSignal17 } from "solid-js";
2155
2250
 
2156
2251
  // src/blocks/accordion/component-info.ts
2157
2252
  var defaultTitle = {
@@ -2711,6 +2806,10 @@ var componentInfo4 = {
2711
2806
  noWrap: true
2712
2807
  };
2713
2808
 
2809
+ // src/constants/file-types.ts
2810
+ 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"];
2811
+ 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"];
2812
+
2714
2813
  // src/blocks/image/component-info.ts
2715
2814
  var componentInfo5 = {
2716
2815
  name: "Image",
@@ -2727,7 +2826,7 @@ var componentInfo5 = {
2727
2826
  name: "image",
2728
2827
  type: "file",
2729
2828
  bubble: true,
2730
- allowedFileTypes: ["jpeg", "jpg", "png", "svg", "webp"],
2829
+ allowedFileTypes: IMAGE_FILE_TYPES,
2731
2830
  required: true,
2732
2831
  defaultValue: "https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F72c80f114dc149019051b6852a9e3b7a",
2733
2832
  onChange: (options) => {
@@ -3191,30 +3290,10 @@ var componentInfo10 = {
3191
3290
  };
3192
3291
 
3193
3292
  // src/blocks/text/text.tsx
3194
- import { createMemo as createMemo11 } from "solid-js";
3195
3293
  function Text(props) {
3196
- const processedText = createMemo11(() => {
3197
- const context = props.builderContext;
3198
- const {
3199
- context: contextContext,
3200
- localState,
3201
- rootState,
3202
- rootSetState
3203
- } = context;
3204
- return String(props.text?.toString() || "").replace(
3205
- /{{([^}]+)}}/g,
3206
- (match, group) => evaluate({
3207
- code: group,
3208
- context: contextContext,
3209
- localState,
3210
- rootState,
3211
- rootSetState
3212
- })
3213
- );
3214
- });
3215
3294
  return <><div
3216
3295
  class="builder-text"
3217
- innerHTML={processedText()}
3296
+ innerHTML={props.text?.toString() || ""}
3218
3297
  style={{
3219
3298
  outline: "none"
3220
3299
  }}
@@ -3248,10 +3327,10 @@ var componentInfo11 = {
3248
3327
  };
3249
3328
 
3250
3329
  // src/blocks/custom-code/custom-code.tsx
3251
- import { onMount as onMount5, createSignal as createSignal12 } from "solid-js";
3330
+ import { onMount as onMount5, createSignal as createSignal11 } from "solid-js";
3252
3331
  function CustomCode(props) {
3253
- const [scriptsInserted, setScriptsInserted] = createSignal12([]);
3254
- const [scriptsRun, setScriptsRun] = createSignal12([]);
3332
+ const [scriptsInserted, setScriptsInserted] = createSignal11([]);
3333
+ const [scriptsRun, setScriptsRun] = createSignal11([]);
3255
3334
  let elementRef;
3256
3335
  onMount5(() => {
3257
3336
  if (!elementRef?.getElementsByTagName || typeof window === "undefined") {
@@ -3312,7 +3391,7 @@ var componentInfo12 = {
3312
3391
  };
3313
3392
 
3314
3393
  // src/blocks/embed/embed.tsx
3315
- import { on as on2, createEffect as createEffect2, createMemo as createMemo13, createSignal as createSignal13 } from "solid-js";
3394
+ import { on as on2, createEffect as createEffect2, createMemo as createMemo12, createSignal as createSignal12 } from "solid-js";
3316
3395
 
3317
3396
  // src/blocks/embed/helpers.ts
3318
3397
  var SCRIPT_MIME_TYPES = ["text/javascript", "application/javascript", "application/ecmascript"];
@@ -3320,9 +3399,9 @@ var isJsScript = (script) => SCRIPT_MIME_TYPES.includes(script.type);
3320
3399
 
3321
3400
  // src/blocks/embed/embed.tsx
3322
3401
  function Embed(props) {
3323
- const [scriptsInserted, setScriptsInserted] = createSignal13([]);
3324
- const [scriptsRun, setScriptsRun] = createSignal13([]);
3325
- const [ranInitFn, setRanInitFn] = createSignal13(false);
3402
+ const [scriptsInserted, setScriptsInserted] = createSignal12([]);
3403
+ const [scriptsRun, setScriptsRun] = createSignal12([]);
3404
+ const [ranInitFn, setRanInitFn] = createSignal12(false);
3326
3405
  function findAndRunScripts() {
3327
3406
  if (!elem || !elem.getElementsByTagName)
3328
3407
  return;
@@ -3345,8 +3424,8 @@ function Embed(props) {
3345
3424
  }
3346
3425
  }
3347
3426
  let elem;
3348
- const onUpdateFn_0_elem = createMemo13(() => elem);
3349
- const onUpdateFn_0_ranInitFn__ = createMemo13(() => ranInitFn());
3427
+ const onUpdateFn_0_elem = createMemo12(() => elem);
3428
+ const onUpdateFn_0_ranInitFn__ = createMemo12(() => ranInitFn());
3350
3429
  function onUpdateFn_0() {
3351
3430
  if (elem && !ranInitFn()) {
3352
3431
  setRanInitFn(true);
@@ -3601,7 +3680,7 @@ var componentInfo13 = {
3601
3680
  };
3602
3681
 
3603
3682
  // src/blocks/form/form/form.tsx
3604
- import { Show as Show11, For as For7, createSignal as createSignal14 } from "solid-js";
3683
+ import { Show as Show11, For as For7, createSignal as createSignal13 } from "solid-js";
3605
3684
 
3606
3685
  // src/functions/get-env.ts
3607
3686
  var validEnvList = ["production", "qa", "test", "development", "dev", "cdn-qa", "cloud", "fast", "cdn2", "cdn-prod"];
@@ -3621,9 +3700,9 @@ function logFetch(url) {
3621
3700
 
3622
3701
  // src/blocks/form/form/form.tsx
3623
3702
  function FormComponent(props) {
3624
- const [formState, setFormState] = createSignal14("unsubmitted");
3625
- const [responseData, setResponseData] = createSignal14(null);
3626
- const [formErrorMessage, setFormErrorMessage] = createSignal14("");
3703
+ const [formState, setFormState] = createSignal13("unsubmitted");
3704
+ const [responseData, setResponseData] = createSignal13(null);
3705
+ const [formErrorMessage, setFormErrorMessage] = createSignal13("");
3627
3706
  function mergeNewRootState(newData) {
3628
3707
  const combinedState = {
3629
3708
  ...props.builderContext.rootState,
@@ -4084,7 +4163,7 @@ var componentInfo18 = {
4084
4163
  name: "image",
4085
4164
  bubble: true,
4086
4165
  type: "file",
4087
- allowedFileTypes: ["jpeg", "jpg", "png", "svg", "gif", "webp"],
4166
+ allowedFileTypes: IMAGE_FILE_TYPES,
4088
4167
  required: true
4089
4168
  }],
4090
4169
  noWrap: true,
@@ -4119,14 +4198,14 @@ var componentInfo19 = {
4119
4198
  inputs: [{
4120
4199
  name: "video",
4121
4200
  type: "file",
4122
- allowedFileTypes: ["mp4"],
4201
+ allowedFileTypes: VIDEO_FILE_TYPES,
4123
4202
  bubble: true,
4124
4203
  defaultValue: "https://cdn.builder.io/o/assets%2FYJIGb4i01jvw0SRdL5Bt%2Fd27731a526464deba0016216f5f9e570%2Fcompressed?apiKey=YJIGb4i01jvw0SRdL5Bt&token=d27731a526464deba0016216f5f9e570&alt=media&optimized=true",
4125
4204
  required: true
4126
4205
  }, {
4127
4206
  name: "posterImage",
4128
4207
  type: "file",
4129
- allowedFileTypes: ["jpeg", "png"],
4208
+ allowedFileTypes: IMAGE_FILE_TYPES,
4130
4209
  helperText: "Image to show before the video plays"
4131
4210
  }, {
4132
4211
  name: "autoPlay",
@@ -4195,9 +4274,9 @@ var componentInfo19 = {
4195
4274
  };
4196
4275
 
4197
4276
  // src/blocks/video/video.tsx
4198
- import { Show as Show12, createMemo as createMemo15 } from "solid-js";
4277
+ import { Show as Show12, createMemo as createMemo14 } from "solid-js";
4199
4278
  function Video(props) {
4200
- const videoProps = createMemo15(() => {
4279
+ const videoProps = createMemo14(() => {
4201
4280
  return {
4202
4281
  ...props.autoPlay === true ? {
4203
4282
  autoPlay: true
@@ -4216,7 +4295,7 @@ function Video(props) {
4216
4295
  } : {}
4217
4296
  };
4218
4297
  });
4219
- const spreadProps = createMemo15(() => {
4298
+ const spreadProps = createMemo14(() => {
4220
4299
  return {
4221
4300
  ...videoProps()
4222
4301
  };
@@ -4352,7 +4431,7 @@ var createRegisterComponentMessage = (info) => ({
4352
4431
  var serializeFn = (fnValue) => {
4353
4432
  const fnStr = fnValue.toString().trim();
4354
4433
  const isArrowWithoutParens = /^[a-zA-Z0-9_]+\s*=>/i.test(fnStr);
4355
- const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("(") && !isArrowWithoutParens;
4434
+ const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("async") && !fnStr.startsWith("(") && !isArrowWithoutParens;
4356
4435
  return `return (${appendFunction ? "function " : ""}${fnStr}).apply(this, arguments)`;
4357
4436
  };
4358
4437
  function serializeIncludingFunctions(info) {
@@ -4426,8 +4505,8 @@ import {
4426
4505
  onMount as onMount6,
4427
4506
  on as on3,
4428
4507
  createEffect as createEffect3,
4429
- createMemo as createMemo16,
4430
- createSignal as createSignal16
4508
+ createMemo as createMemo15,
4509
+ createSignal as createSignal15
4431
4510
  } from "solid-js";
4432
4511
  import { Dynamic as Dynamic5 } from "solid-js/web";
4433
4512
 
@@ -4437,7 +4516,7 @@ function getPreviewContent(_searchParams) {
4437
4516
  }
4438
4517
 
4439
4518
  // src/constants/sdk-version.ts
4440
- var SDK_VERSION = "3.0.0";
4519
+ var SDK_VERSION = "3.0.2";
4441
4520
 
4442
4521
  // src/helpers/sdk-headers.ts
4443
4522
  var getSdkHeaders = () => ({
@@ -4500,6 +4579,23 @@ function flattenMongoQuery(obj, _current, _res = {}) {
4500
4579
  }
4501
4580
  return _res;
4502
4581
  }
4582
+ function unflatten(obj) {
4583
+ const result = {};
4584
+ for (const key in obj) {
4585
+ const parts = key.split(".");
4586
+ let current = result;
4587
+ for (let i = 0; i < parts.length; i++) {
4588
+ const part = parts[i];
4589
+ if (i === parts.length - 1) {
4590
+ current[part] = obj[key];
4591
+ } else {
4592
+ current[part] = current[part] || {};
4593
+ current = current[part];
4594
+ }
4595
+ }
4596
+ }
4597
+ return result;
4598
+ }
4503
4599
 
4504
4600
  // src/types/api-version.ts
4505
4601
  var DEFAULT_API_VERSION = "v3";
@@ -4564,7 +4660,7 @@ var generateContentUrl = (options) => {
4564
4660
  url.searchParams.set("noTraverse", String(noTraverse));
4565
4661
  url.searchParams.set("includeRefs", String(true));
4566
4662
  const finalLocale = locale || userAttributes?.locale;
4567
- let finalUserAttributes = userAttributes;
4663
+ let finalUserAttributes = userAttributes || {};
4568
4664
  if (finalLocale) {
4569
4665
  url.searchParams.set("locale", finalLocale);
4570
4666
  finalUserAttributes = {
@@ -4602,11 +4698,15 @@ var generateContentUrl = (options) => {
4602
4698
  ...getBuilderSearchParamsFromWindow(),
4603
4699
  ...normalizeSearchParams(options.options || {})
4604
4700
  };
4701
+ finalUserAttributes = {
4702
+ ...finalUserAttributes,
4703
+ ...getUserAttributesAsJSON(queryOptions)
4704
+ };
4605
4705
  const flattened = flatten(queryOptions);
4606
4706
  for (const key in flattened) {
4607
4707
  url.searchParams.set(key, String(flattened[key]));
4608
4708
  }
4609
- if (finalUserAttributes) {
4709
+ if (Object.keys(finalUserAttributes).length > 0) {
4610
4710
  url.searchParams.set("userAttributes", JSON.stringify(finalUserAttributes));
4611
4711
  }
4612
4712
  if (query) {
@@ -4619,6 +4719,28 @@ var generateContentUrl = (options) => {
4619
4719
  }
4620
4720
  return url;
4621
4721
  };
4722
+ var getUserAttributesFromQueryOptions = (queryOptions) => {
4723
+ const newUserAttributes = {};
4724
+ for (const key in queryOptions) {
4725
+ if (key.startsWith("userAttributes.")) {
4726
+ newUserAttributes[key] = queryOptions[key];
4727
+ delete queryOptions[key];
4728
+ }
4729
+ }
4730
+ return newUserAttributes;
4731
+ };
4732
+ var getUserAttributesAsJSON = (queryOptions) => {
4733
+ if (isBrowser() && queryOptions["preview"] === "BUILDER_STUDIO") {
4734
+ queryOptions["userAttributes.urlPath"] = window.location.pathname;
4735
+ queryOptions["userAttributes.host"] = window.location.host;
4736
+ const queryOptionsForUserAttributes = getUserAttributesFromQueryOptions(queryOptions);
4737
+ const {
4738
+ userAttributes
4739
+ } = unflatten(queryOptionsForUserAttributes);
4740
+ return userAttributes;
4741
+ }
4742
+ return {};
4743
+ };
4622
4744
 
4623
4745
  // src/functions/get-content/index.ts
4624
4746
  var checkContentHasResults = (content) => "results" in content;
@@ -5149,6 +5271,12 @@ var subscribeToEditor = (model, callback, options) => {
5149
5271
  };
5150
5272
  };
5151
5273
 
5274
+ // src/components/content/components/enable-editor.helpers.ts
5275
+ var SDKS_USING_ELEMENT_REF_APPROACH = ["svelte", "qwik", "vue"];
5276
+ var needsElementRefDivForEditing = () => {
5277
+ return SDKS_USING_ELEMENT_REF_APPROACH.includes(TARGET) && (isEditing() || isPreviewing());
5278
+ };
5279
+
5152
5280
  // src/components/content/components/styles.helpers.ts
5153
5281
  var getCssFromFont = (font) => {
5154
5282
  const family = font.family + (font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
@@ -5230,12 +5358,12 @@ var getWrapperClassName = (variationId) => {
5230
5358
 
5231
5359
  // src/components/content/components/enable-editor.tsx
5232
5360
  function EnableEditor(props) {
5233
- const [ContentWrapper, setContentWrapper] = createSignal16(
5361
+ const [ContentWrapper, setContentWrapper] = createSignal15(
5234
5362
  props.contentWrapper || "div"
5235
5363
  );
5236
- const [httpReqsData, setHttpReqsData] = createSignal16({});
5237
- const [httpReqsPending, setHttpReqsPending] = createSignal16({});
5238
- const [clicked, setClicked] = createSignal16(false);
5364
+ const [httpReqsData, setHttpReqsData] = createSignal15({});
5365
+ const [httpReqsPending, setHttpReqsPending] = createSignal15({});
5366
+ const [clicked, setClicked] = createSignal15(false);
5239
5367
  function mergeNewRootState(newData) {
5240
5368
  const combinedState = {
5241
5369
  ...props.builderContextSignal.rootState,
@@ -5269,7 +5397,7 @@ function EnableEditor(props) {
5269
5397
  content: newContentValue
5270
5398
  }));
5271
5399
  }
5272
- const showContentProps = createMemo16(() => {
5400
+ const showContentProps = createMemo15(() => {
5273
5401
  return props.showContent ? {} : {
5274
5402
  hidden: true,
5275
5403
  "aria-hidden": true
@@ -5394,8 +5522,10 @@ function EnableEditor(props) {
5394
5522
  Object.values(
5395
5523
  props.builderContextSignal.componentInfos
5396
5524
  ).forEach((registeredComponent) => {
5397
- const message = createRegisterComponentMessage(registeredComponent);
5398
- window.parent?.postMessage(message, "*");
5525
+ if (!props.model || !registeredComponent.models?.length || registeredComponent.models.includes(props.model)) {
5526
+ const message = createRegisterComponentMessage(registeredComponent);
5527
+ window.parent?.postMessage(message, "*");
5528
+ }
5399
5529
  });
5400
5530
  window.addEventListener(
5401
5531
  "builder:component:stateChangeListenerActivated",
@@ -5423,11 +5553,16 @@ function EnableEditor(props) {
5423
5553
  `builder.overrides.${searchParamPreviewModel}`
5424
5554
  );
5425
5555
  const previewApiKey = searchParams.get("apiKey") || searchParams.get("builder.space");
5426
- if (searchParamPreviewModel === props.model && previewApiKey === props.apiKey && (!props.content || searchParamPreviewId === props.content.id)) {
5556
+ if (searchParamPreviewModel === "BUILDER_STUDIO" || searchParamPreviewModel === props.model && previewApiKey === props.apiKey && (!props.content || searchParamPreviewId === props.content.id)) {
5427
5557
  fetchOneEntry({
5428
- model: props.model,
5558
+ model: props.model || "",
5429
5559
  apiKey: props.apiKey,
5430
- apiVersion: props.builderContextSignal.apiVersion
5560
+ apiVersion: props.builderContextSignal.apiVersion,
5561
+ ...searchParamPreviewModel === "BUILDER_STUDIO" && props.context?.symbolId ? {
5562
+ query: {
5563
+ id: props.context.symbolId
5564
+ }
5565
+ } : {}
5431
5566
  }).then((content) => {
5432
5567
  if (content) {
5433
5568
  mergeNewContent(content);
@@ -5437,14 +5572,14 @@ function EnableEditor(props) {
5437
5572
  }
5438
5573
  }
5439
5574
  });
5440
- const onUpdateFn_0_props_content = createMemo16(() => props.content);
5575
+ const onUpdateFn_0_props_content = createMemo15(() => props.content);
5441
5576
  function onUpdateFn_0() {
5442
5577
  if (props.content) {
5443
5578
  mergeNewContent(props.content);
5444
5579
  }
5445
5580
  }
5446
5581
  createEffect3(on3(() => [onUpdateFn_0_props_content()], onUpdateFn_0));
5447
- const onUpdateFn_1_props_builderContextSignal_rootState = createMemo16(
5582
+ const onUpdateFn_1_props_builderContextSignal_rootState = createMemo15(
5448
5583
  () => props.builderContextSignal.rootState
5449
5584
  );
5450
5585
  function onUpdateFn_1() {
@@ -5456,14 +5591,14 @@ function EnableEditor(props) {
5456
5591
  onUpdateFn_1
5457
5592
  )
5458
5593
  );
5459
- const onUpdateFn_2_props_data = createMemo16(() => props.data);
5594
+ const onUpdateFn_2_props_data = createMemo15(() => props.data);
5460
5595
  function onUpdateFn_2() {
5461
5596
  if (props.data) {
5462
5597
  mergeNewRootState(props.data);
5463
5598
  }
5464
5599
  }
5465
5600
  createEffect3(on3(() => [onUpdateFn_2_props_data()], onUpdateFn_2));
5466
- const onUpdateFn_3_props_locale = createMemo16(() => props.locale);
5601
+ const onUpdateFn_3_props_locale = createMemo15(() => props.locale);
5467
5602
  function onUpdateFn_3() {
5468
5603
  if (props.locale) {
5469
5604
  mergeNewRootState({
@@ -5472,7 +5607,9 @@ function EnableEditor(props) {
5472
5607
  }
5473
5608
  }
5474
5609
  createEffect3(on3(() => [onUpdateFn_3_props_locale()], onUpdateFn_3));
5475
- return <><builder_context_default.Provider value={props.builderContextSignal}><Show13 when={props.builderContextSignal.content}><Dynamic5
5610
+ return <><builder_context_default.Provider value={props.builderContextSignal}><Show13
5611
+ when={props.builderContextSignal.content || needsElementRefDivForEditing()}
5612
+ ><Dynamic5
5476
5613
  class={getWrapperClassName(
5477
5614
  props.content?.testVariationId || props.content?.id
5478
5615
  )}
@@ -5481,6 +5618,9 @@ function EnableEditor(props) {
5481
5618
  onClick={(event) => onClick(event)}
5482
5619
  builder-content-id={props.builderContextSignal.content?.id}
5483
5620
  builder-model={props.model}
5621
+ style={{
5622
+ display: !props.builderContextSignal.content && needsElementRefDivForEditing() ? "none" : void 0
5623
+ }}
5484
5624
  {...{}}
5485
5625
  {...showContentProps()}
5486
5626
  {...props.contentWrapperProps}
@@ -5490,9 +5630,9 @@ function EnableEditor(props) {
5490
5630
  var Enable_editor_default = EnableEditor;
5491
5631
 
5492
5632
  // src/components/content/components/styles.tsx
5493
- import { createSignal as createSignal17 } from "solid-js";
5633
+ import { createSignal as createSignal16 } from "solid-js";
5494
5634
  function ContentStyles(props) {
5495
- const [injectedStyles, setInjectedStyles] = createSignal17(
5635
+ const [injectedStyles, setInjectedStyles] = createSignal16(
5496
5636
  `
5497
5637
  ${getCss({
5498
5638
  cssCode: props.cssCode,
@@ -5550,7 +5690,7 @@ var getContentInitialValue = ({
5550
5690
 
5551
5691
  // src/components/content/content.tsx
5552
5692
  function ContentComponent(props) {
5553
- const [scriptStr, setScriptStr] = createSignal18(
5693
+ const [scriptStr, setScriptStr] = createSignal17(
5554
5694
  getUpdateVariantVisibilityScript({
5555
5695
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
5556
5696
  variationId: props.content?.testVariationId,
@@ -5558,16 +5698,10 @@ function ContentComponent(props) {
5558
5698
  contentId: props.content?.id
5559
5699
  })
5560
5700
  );
5561
- const [registeredComponents, setRegisteredComponents] = createSignal18(
5701
+ const [registeredComponents, setRegisteredComponents] = createSignal17(
5562
5702
  [
5563
5703
  ...getDefaultRegisteredComponents(),
5564
- ...props.customComponents?.filter(({ models }) => {
5565
- if (!models?.length)
5566
- return true;
5567
- if (!props.model)
5568
- return true;
5569
- return models.includes(props.model);
5570
- }) || []
5704
+ ...props.customComponents || []
5571
5705
  ].reduce(
5572
5706
  (acc, { component, ...info }) => ({
5573
5707
  ...acc,
@@ -5579,7 +5713,7 @@ function ContentComponent(props) {
5579
5713
  {}
5580
5714
  )
5581
5715
  );
5582
- const [builderContextSignal, setBuilderContextSignal] = createSignal18({
5716
+ const [builderContextSignal, setBuilderContextSignal] = createSignal17({
5583
5717
  content: getContentInitialValue({
5584
5718
  content: props.content,
5585
5719
  data: props.data
@@ -5597,13 +5731,7 @@ function ContentComponent(props) {
5597
5731
  apiVersion: props.apiVersion,
5598
5732
  componentInfos: [
5599
5733
  ...getDefaultRegisteredComponents(),
5600
- ...props.customComponents?.filter(({ models }) => {
5601
- if (!models?.length)
5602
- return true;
5603
- if (!props.model)
5604
- return true;
5605
- return models.includes(props.model);
5606
- }) || []
5734
+ ...props.customComponents || []
5607
5735
  ].reduce(
5608
5736
  (acc, { component: _, ...info }) => ({
5609
5737
  ...acc,
@@ -5614,7 +5742,8 @@ function ContentComponent(props) {
5614
5742
  inheritedStyles: {},
5615
5743
  BlocksWrapper: props.blocksWrapper || "div",
5616
5744
  BlocksWrapperProps: props.blocksWrapperProps || {},
5617
- nonce: props.nonce || ""
5745
+ nonce: props.nonce || "",
5746
+ model: props.model || ""
5618
5747
  });
5619
5748
  function contentSetState(newRootState) {
5620
5749
  setBuilderContextSignal((PREVIOUS_VALUE) => ({
@@ -5692,13 +5821,13 @@ var Content_default = ContentComponent;
5692
5821
 
5693
5822
  // src/components/content-variants/content-variants.tsx
5694
5823
  function ContentVariants(props) {
5695
- const [shouldRenderVariants, setShouldRenderVariants] = createSignal19(
5824
+ const [shouldRenderVariants, setShouldRenderVariants] = createSignal18(
5696
5825
  checkShouldRenderVariants({
5697
5826
  canTrack: getDefaultCanTrack(props.canTrack),
5698
5827
  content: props.content
5699
5828
  })
5700
5829
  );
5701
- const updateCookieAndStylesScriptStr = createMemo19(() => {
5830
+ const updateCookieAndStylesScriptStr = createMemo18(() => {
5702
5831
  return getUpdateCookieAndStylesScript(
5703
5832
  getVariants(props.content).map((value) => ({
5704
5833
  id: value.testVariationId,
@@ -5707,10 +5836,10 @@ function ContentVariants(props) {
5707
5836
  props.content?.id || ""
5708
5837
  );
5709
5838
  });
5710
- const hideVariantsStyleString = createMemo19(() => {
5839
+ const hideVariantsStyleString = createMemo18(() => {
5711
5840
  return getVariants(props.content).map((value) => `.variant-${value.testVariationId} { display: none; } `).join("");
5712
5841
  });
5713
- const defaultContent = createMemo19(() => {
5842
+ const defaultContent = createMemo18(() => {
5714
5843
  return shouldRenderVariants() ? {
5715
5844
  ...props.content,
5716
5845
  testVariationId: props.content?.id
@@ -5822,14 +5951,14 @@ var fetchSymbolContent = async ({
5822
5951
 
5823
5952
  // src/blocks/symbol/symbol.tsx
5824
5953
  function Symbol(props) {
5825
- const [contentToUse, setContentToUse] = createSignal20(props.symbol?.content);
5826
- const blocksWrapper = createMemo20(() => {
5954
+ const [contentToUse, setContentToUse] = createSignal19(props.symbol?.content);
5955
+ const blocksWrapper = createMemo19(() => {
5827
5956
  return "div";
5828
5957
  });
5829
- const contentWrapper = createMemo20(() => {
5958
+ const contentWrapper = createMemo19(() => {
5830
5959
  return "div";
5831
5960
  });
5832
- const className = createMemo20(() => {
5961
+ const className = createMemo19(() => {
5833
5962
  return [
5834
5963
  ...[props.attributes[getClassPropName()]],
5835
5964
  "builder-symbol",
@@ -5851,7 +5980,7 @@ function Symbol(props) {
5851
5980
  }
5852
5981
  onMount8(() => {
5853
5982
  });
5854
- const onUpdateFn_0_props_symbol = createMemo20(() => props.symbol);
5983
+ const onUpdateFn_0_props_symbol = createMemo19(() => props.symbol);
5855
5984
  function onUpdateFn_0() {
5856
5985
  setContent();
5857
5986
  }