@builder.io/sdk-solid 2.0.31 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/edge/index.js CHANGED
@@ -120,7 +120,8 @@ var builder_context_default = createContext({
120
120
  inheritedStyles: {},
121
121
  BlocksWrapper: "div",
122
122
  BlocksWrapperProps: {},
123
- nonce: ""
123
+ nonce: "",
124
+ model: ""
124
125
  });
125
126
  var components_context_default = createContext({ registeredComponents: {} });
126
127
 
@@ -3582,6 +3583,74 @@ function evaluate({
3582
3583
  }
3583
3584
  }
3584
3585
 
3586
+ // src/functions/traverse.ts
3587
+ function traverse(obj, callback, parent2 = null, key = null, visited = /* @__PURE__ */ new WeakSet()) {
3588
+ if (obj == null || typeof obj !== "object") {
3589
+ callback(obj, (newValue) => {
3590
+ if (parent2 !== null && key !== null) {
3591
+ parent2[key] = newValue;
3592
+ }
3593
+ });
3594
+ return;
3595
+ }
3596
+ if (visited.has(obj)) {
3597
+ return;
3598
+ }
3599
+ visited.add(obj);
3600
+ if (Array.isArray(obj)) {
3601
+ obj.forEach((item, index) => {
3602
+ const update = (newValue) => {
3603
+ obj[index] = newValue;
3604
+ };
3605
+ callback(item, update);
3606
+ traverse(item, callback, obj, index, visited);
3607
+ });
3608
+ } else {
3609
+ Object.entries(obj).forEach(([key2, value]) => {
3610
+ const update = (newValue) => {
3611
+ obj[key2] = newValue;
3612
+ };
3613
+ callback(value, update);
3614
+ traverse(value, callback, obj, key2, visited);
3615
+ });
3616
+ }
3617
+ }
3618
+
3619
+ // src/functions/extract-localized-values.ts
3620
+ function isLocalizedField(value) {
3621
+ return value && typeof value === "object" && value["@type"] === "@builder.io/core:LocalizedValue";
3622
+ }
3623
+ function containsLocalizedValues(data) {
3624
+ if (!data || !Object.getOwnPropertyNames(data).length) {
3625
+ return false;
3626
+ }
3627
+ let hasLocalizedValues = false;
3628
+ traverse(data, (value) => {
3629
+ if (isLocalizedField(value)) {
3630
+ hasLocalizedValues = true;
3631
+ return;
3632
+ }
3633
+ });
3634
+ return hasLocalizedValues;
3635
+ }
3636
+ function extractLocalizedValues(data, locale) {
3637
+ if (!data || !Object.getOwnPropertyNames(data).length) {
3638
+ return {};
3639
+ }
3640
+ traverse(data, (value, update) => {
3641
+ if (isLocalizedField(value)) {
3642
+ update(value[locale] ?? void 0);
3643
+ }
3644
+ });
3645
+ return data;
3646
+ }
3647
+ function resolveLocalizedValues(block, locale) {
3648
+ if (block.component?.options && containsLocalizedValues(block.component?.options)) {
3649
+ block.component.options = extractLocalizedValues(block.component.options, locale ?? "Default");
3650
+ }
3651
+ return block;
3652
+ }
3653
+
3585
3654
  // src/functions/fast-clone.ts
3586
3655
  var fastClone = (obj) => JSON.parse(JSON.stringify(obj));
3587
3656
 
@@ -3680,7 +3749,8 @@ function getProcessedBlock({
3680
3749
  rootState,
3681
3750
  rootSetState
3682
3751
  }) {
3683
- const transformedBlock = transformBlock(block);
3752
+ let transformedBlock = resolveLocalizedValues(block, rootState.locale);
3753
+ transformedBlock = transformBlock(transformedBlock);
3684
3754
  if (shouldEvaluateBindings) {
3685
3755
  return evaluateBindings({
3686
3756
  block: transformedBlock,
@@ -3937,16 +4007,24 @@ function mapStyleObjToStrIfNeeded(style) {
3937
4007
  }
3938
4008
 
3939
4009
  // src/components/block/block.helpers.ts
4010
+ var checkIsComponentRestricted = (component, model) => {
4011
+ if (!component)
4012
+ return true;
4013
+ if (!model)
4014
+ return false;
4015
+ return component.models && component.models.length > 0 && !component.models.includes(model);
4016
+ };
3940
4017
  var getComponent = ({
3941
4018
  block,
3942
- registeredComponents
4019
+ registeredComponents,
4020
+ model
3943
4021
  }) => {
3944
4022
  const componentName = block.component?.name;
3945
4023
  if (!componentName) {
3946
4024
  return null;
3947
4025
  }
3948
4026
  const ref = registeredComponents[componentName];
3949
- if (!ref) {
4027
+ if (!ref || checkIsComponentRestricted(ref, model)) {
3950
4028
  return void 0;
3951
4029
  } else {
3952
4030
  return ref;
@@ -3997,11 +4075,15 @@ var provideLinkComponent = (block, linkComponent) => {
3997
4075
  };
3998
4076
  return {};
3999
4077
  };
4000
- var provideRegisteredComponents = (block, registeredComponents) => {
4001
- if (block?.shouldReceiveBuilderProps?.builderComponents)
4078
+ var provideRegisteredComponents = (block, registeredComponents, model) => {
4079
+ if (block?.shouldReceiveBuilderProps?.builderComponents) {
4080
+ const filteredRegisteredComponents = Object.fromEntries(Object.entries(registeredComponents).filter(([_, component]) => {
4081
+ return !checkIsComponentRestricted(component, model);
4082
+ }));
4002
4083
  return {
4003
- builderComponents: registeredComponents
4084
+ builderComponents: filteredRegisteredComponents
4004
4085
  };
4086
+ }
4005
4087
  return {};
4006
4088
  };
4007
4089
  var provideBuilderBlock = (block, builderBlock) => {
@@ -4463,7 +4545,8 @@ function Block(props) {
4463
4545
  const blockComponent = createMemo(() => {
4464
4546
  return getComponent({
4465
4547
  block: processedBlock(),
4466
- registeredComponents: props.registeredComponents
4548
+ registeredComponents: props.registeredComponents,
4549
+ model: props.context.model
4467
4550
  });
4468
4551
  });
4469
4552
  const Tag = createMemo(() => {
@@ -4496,7 +4579,7 @@ function Block(props) {
4496
4579
  ...provideBuilderBlock(blockComponent(), processedBlock()),
4497
4580
  ...provideBuilderContext(blockComponent(), props.context),
4498
4581
  ...provideLinkComponent(blockComponent(), props.linkComponent),
4499
- ...provideRegisteredComponents(blockComponent(), props.registeredComponents)
4582
+ ...provideRegisteredComponents(blockComponent(), props.registeredComponents, props.context.model)
4500
4583
  },
4501
4584
  context: props.context,
4502
4585
  linkComponent: props.linkComponent,
@@ -5094,16 +5177,16 @@ function getSrcSet(url) {
5094
5177
  // src/blocks/image/image.tsx
5095
5178
  var _tmpl$5 = /* @__PURE__ */ template(`<source type=image/webp>`);
5096
5179
  var _tmpl$23 = /* @__PURE__ */ template(`<picture><img>`);
5097
- var _tmpl$32 = /* @__PURE__ */ template(`<div class="builder-image-sizer div-7e6ffddc">`);
5098
- var _tmpl$42 = /* @__PURE__ */ template(`<div class=div-7e6ffddc-2>`);
5099
- var _tmpl$52 = /* @__PURE__ */ template(`<style>.img-7e6ffddc {
5180
+ var _tmpl$32 = /* @__PURE__ */ template(`<div class="builder-image-sizer div-070d7e88">`);
5181
+ var _tmpl$42 = /* @__PURE__ */ template(`<div class=div-070d7e88-2>`);
5182
+ var _tmpl$52 = /* @__PURE__ */ template(`<style>.img-070d7e88 {
5100
5183
  opacity: 1;
5101
5184
  transition: opacity 0.2s ease-in-out;
5102
- }.div-7e6ffddc {
5185
+ }.div-070d7e88 {
5103
5186
  width: 100%;
5104
5187
  pointer-events: none;
5105
5188
  font-size: 0;
5106
- }.div-7e6ffddc-2 {
5189
+ }.div-070d7e88-2 {
5107
5190
  display: flex;
5108
5191
  flex-direction: column;
5109
5192
  align-items: stretch;
@@ -5119,7 +5202,7 @@ function Image(props) {
5119
5202
  const url = imageToUse;
5120
5203
  if (!url || // We can auto add srcset for cdn.builder.io and shopify
5121
5204
  // images, otherwise you can supply this prop manually
5122
- !(url.match(/builder\.io/) || url.match(/cdn\.shopify\.com/))) {
5205
+ !(typeof url === "string" && (url.match(/builder\.io/) || url.match(/cdn\.shopify\.com/)))) {
5123
5206
  return props.srcset;
5124
5207
  }
5125
5208
  if (props.noWebp) {
@@ -5167,7 +5250,7 @@ function Image(props) {
5167
5250
  }
5168
5251
  }), _el$3);
5169
5252
  effect((_p$) => {
5170
- const _v$ = "builder-image" + (props.className ? " " + props.className : "") + " img-7e6ffddc", _v$2 = props.highPriority ? "eager" : "lazy", _v$3 = props.highPriority ? "high" : "auto", _v$4 = props.altText, _v$5 = props.altText ? void 0 : "presentation", _v$6 = {
5253
+ const _v$ = "builder-image" + (props.className ? " " + props.className : "") + " img-070d7e88", _v$2 = props.highPriority ? "eager" : "lazy", _v$3 = props.highPriority ? "high" : "auto", _v$4 = props.altText, _v$5 = props.altText ? void 0 : "presentation", _v$6 = {
5171
5254
  "object-position": props.backgroundPosition || "center",
5172
5255
  "object-fit": props.backgroundSize || "cover",
5173
5256
  ...aspectRatioCss()
@@ -6033,6 +6116,10 @@ var componentInfo4 = {
6033
6116
  noWrap: true
6034
6117
  };
6035
6118
 
6119
+ // src/constants/file-types.ts
6120
+ 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"];
6121
+ 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"];
6122
+
6036
6123
  // src/blocks/image/component-info.ts
6037
6124
  var componentInfo5 = {
6038
6125
  name: "Image",
@@ -6049,7 +6136,7 @@ var componentInfo5 = {
6049
6136
  name: "image",
6050
6137
  type: "file",
6051
6138
  bubble: true,
6052
- allowedFileTypes: ["jpeg", "jpg", "png", "svg", "webp"],
6139
+ allowedFileTypes: IMAGE_FILE_TYPES,
6053
6140
  required: true,
6054
6141
  defaultValue: "https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F72c80f114dc149019051b6852a9e3b7a",
6055
6142
  onChange: (options) => {
@@ -7578,7 +7665,7 @@ var componentInfo18 = {
7578
7665
  name: "image",
7579
7666
  bubble: true,
7580
7667
  type: "file",
7581
- allowedFileTypes: ["jpeg", "jpg", "png", "svg", "gif", "webp"],
7668
+ allowedFileTypes: IMAGE_FILE_TYPES,
7582
7669
  required: true
7583
7670
  }],
7584
7671
  noWrap: true,
@@ -7622,14 +7709,14 @@ var componentInfo19 = {
7622
7709
  inputs: [{
7623
7710
  name: "video",
7624
7711
  type: "file",
7625
- allowedFileTypes: ["mp4"],
7712
+ allowedFileTypes: VIDEO_FILE_TYPES,
7626
7713
  bubble: true,
7627
7714
  defaultValue: "https://cdn.builder.io/o/assets%2FYJIGb4i01jvw0SRdL5Bt%2Fd27731a526464deba0016216f5f9e570%2Fcompressed?apiKey=YJIGb4i01jvw0SRdL5Bt&token=d27731a526464deba0016216f5f9e570&alt=media&optimized=true",
7628
7715
  required: true
7629
7716
  }, {
7630
7717
  name: "posterImage",
7631
7718
  type: "file",
7632
- allowedFileTypes: ["jpeg", "png"],
7719
+ allowedFileTypes: IMAGE_FILE_TYPES,
7633
7720
  helperText: "Image to show before the video plays"
7634
7721
  }, {
7635
7722
  name: "autoPlay",
@@ -7885,7 +7972,7 @@ var createRegisterComponentMessage = (info) => ({
7885
7972
  var serializeFn = (fnValue) => {
7886
7973
  const fnStr = fnValue.toString().trim();
7887
7974
  const isArrowWithoutParens = /^[a-zA-Z0-9_]+\s*=>/i.test(fnStr);
7888
- const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("(") && !isArrowWithoutParens;
7975
+ const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("async") && !fnStr.startsWith("(") && !isArrowWithoutParens;
7889
7976
  return `return (${appendFunction ? "function " : ""}${fnStr}).apply(this, arguments)`;
7890
7977
  };
7891
7978
  function serializeIncludingFunctions(info) {
@@ -7968,7 +8055,7 @@ function getPreviewContent(_searchParams) {
7968
8055
  }
7969
8056
 
7970
8057
  // src/constants/sdk-version.ts
7971
- var SDK_VERSION = "2.0.31";
8058
+ var SDK_VERSION = "3.0.1";
7972
8059
 
7973
8060
  // src/helpers/sdk-headers.ts
7974
8061
  var getSdkHeaders = () => ({
@@ -8207,22 +8294,17 @@ var _processContentResult = async (options, content, url = generateContentUrl(op
8207
8294
  return content.results;
8208
8295
  };
8209
8296
  async function fetchEntries(options) {
8210
- try {
8211
- const url = generateContentUrl(options);
8212
- const content = await _fetchContent(options);
8213
- if (!checkContentHasResults(content)) {
8214
- logger.error("Error fetching data. ", {
8215
- url,
8216
- content,
8217
- options
8218
- });
8219
- return null;
8220
- }
8221
- return _processContentResult(options, content);
8222
- } catch (error) {
8223
- logger.error("Error fetching data. ", error);
8224
- return null;
8297
+ const url = generateContentUrl(options);
8298
+ const content = await _fetchContent(options);
8299
+ if (!checkContentHasResults(content)) {
8300
+ logger.error("Error fetching data. ", {
8301
+ url,
8302
+ content,
8303
+ options
8304
+ });
8305
+ throw content;
8225
8306
  }
8307
+ return _processContentResult(options, content);
8226
8308
  }
8227
8309
 
8228
8310
  // src/functions/is-previewing.ts
@@ -8685,6 +8767,12 @@ var subscribeToEditor = (model, callback, options) => {
8685
8767
  };
8686
8768
  };
8687
8769
 
8770
+ // src/components/content/components/enable-editor.helpers.ts
8771
+ var SDKS_USING_ELEMENT_REF_APPROACH = ["svelte", "qwik", "vue"];
8772
+ var needsElementRefDivForEditing = () => {
8773
+ return SDKS_USING_ELEMENT_REF_APPROACH.includes(TARGET) && (isEditing() || isPreviewing());
8774
+ };
8775
+
8688
8776
  // src/components/content/components/styles.helpers.ts
8689
8777
  var getCssFromFont = (font) => {
8690
8778
  const family = font.family + (font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
@@ -8919,8 +9007,10 @@ function EnableEditor(props) {
8919
9007
  } : {}
8920
9008
  });
8921
9009
  Object.values(props.builderContextSignal.componentInfos).forEach((registeredComponent) => {
8922
- const message = createRegisterComponentMessage(registeredComponent);
8923
- window.parent?.postMessage(message, "*");
9010
+ if (!props.model || !registeredComponent.models?.length || registeredComponent.models.includes(props.model)) {
9011
+ const message = createRegisterComponentMessage(registeredComponent);
9012
+ window.parent?.postMessage(message, "*");
9013
+ }
8924
9014
  });
8925
9015
  window.addEventListener("builder:component:stateChangeListenerActivated", emitStateUpdate);
8926
9016
  }
@@ -8992,7 +9082,7 @@ function EnableEditor(props) {
8992
9082
  get children() {
8993
9083
  return createComponent(Show, {
8994
9084
  get when() {
8995
- return props.builderContextSignal.content;
9085
+ return props.builderContextSignal.content || needsElementRefDivForEditing();
8996
9086
  },
8997
9087
  get children() {
8998
9088
  return createComponent(Dynamic, mergeProps({
@@ -9010,6 +9100,11 @@ function EnableEditor(props) {
9010
9100
  },
9011
9101
  get ["builder-model"]() {
9012
9102
  return props.model;
9103
+ },
9104
+ get style() {
9105
+ return {
9106
+ display: !props.builderContextSignal.content && needsElementRefDivForEditing() ? "none" : void 0
9107
+ };
9013
9108
  }
9014
9109
  }, {}, showContentProps, () => props.contentWrapperProps, {
9015
9110
  get component() {
@@ -9092,15 +9187,7 @@ function ContentComponent(props) {
9092
9187
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
9093
9188
  contentId: props.content?.id
9094
9189
  }));
9095
- const [registeredComponents, setRegisteredComponents] = createSignal([...getDefaultRegisteredComponents(), ...props.customComponents?.filter(({
9096
- models
9097
- }) => {
9098
- if (!models?.length)
9099
- return true;
9100
- if (!props.model)
9101
- return true;
9102
- return models.includes(props.model);
9103
- }) || []].reduce((acc, {
9190
+ const [registeredComponents, setRegisteredComponents] = createSignal([...getDefaultRegisteredComponents(), ...props.customComponents || []].reduce((acc, {
9104
9191
  component,
9105
9192
  ...info
9106
9193
  }) => ({
@@ -9126,15 +9213,7 @@ function ContentComponent(props) {
9126
9213
  canTrack: props.canTrack,
9127
9214
  apiKey: props.apiKey,
9128
9215
  apiVersion: props.apiVersion,
9129
- componentInfos: [...getDefaultRegisteredComponents(), ...props.customComponents?.filter(({
9130
- models
9131
- }) => {
9132
- if (!models?.length)
9133
- return true;
9134
- if (!props.model)
9135
- return true;
9136
- return models.includes(props.model);
9137
- }) || []].reduce((acc, {
9216
+ componentInfos: [...getDefaultRegisteredComponents(), ...props.customComponents || []].reduce((acc, {
9138
9217
  component: _,
9139
9218
  ...info
9140
9219
  }) => ({
@@ -9144,7 +9223,8 @@ function ContentComponent(props) {
9144
9223
  inheritedStyles: {},
9145
9224
  BlocksWrapper: props.blocksWrapper || "div",
9146
9225
  BlocksWrapperProps: props.blocksWrapperProps || {},
9147
- nonce: props.nonce || ""
9226
+ nonce: props.nonce || "",
9227
+ model: props.model || ""
9148
9228
  });
9149
9229
  function contentSetState(newRootState) {
9150
9230
  setBuilderContextSignal((PREVIOUS_VALUE) => ({