@contentful/experiences-visual-editor-react 1.40.3-dev-20250611T0948-7389339.0 → 1.41.0-beta.0

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.js CHANGED
@@ -724,7 +724,6 @@ const ComponentPropertyValueSchema$1 = z.discriminatedUnion('type', [
724
724
  const PatternPropertySchema$1 = z.object({
725
725
  type: z.literal('BoundValue'),
726
726
  path: z.string(),
727
- contentType: z.string(),
728
727
  });
729
728
  const PatternPropertiesSchema$1 = z.record(propertyKeySchema$1, PatternPropertySchema$1);
730
729
  const BreakpointSchema$1 = z
@@ -1575,7 +1574,6 @@ const buildStyleTag = ({ styles, nodeId }) => {
1575
1574
  */
1576
1575
  const buildCfStyles = (values) => {
1577
1576
  const cssProperties = {
1578
- boxSizing: 'border-box',
1579
1577
  margin: values.cfMargin,
1580
1578
  padding: values.cfPadding,
1581
1579
  backgroundColor: values.cfBackgroundColor,
@@ -1844,18 +1842,41 @@ const transformMedia = (asset, variables, resolveDesignValue, variableName, path
1844
1842
  return asset.fields.file?.url;
1845
1843
  };
1846
1844
 
1845
+ const isAsset = (value) => {
1846
+ return (null !== value &&
1847
+ typeof value === 'object' &&
1848
+ 'sys' in value &&
1849
+ value.sys?.type === 'Asset');
1850
+ };
1851
+ const isEntry = (value) => {
1852
+ return (null !== value &&
1853
+ typeof value === 'object' &&
1854
+ 'sys' in value &&
1855
+ value.sys?.type === 'Entry');
1856
+ };
1857
+
1847
1858
  function getResolvedEntryFromLink(entryOrAsset, path, entityStore) {
1848
- if (entryOrAsset.sys.type === 'Asset') {
1859
+ if (isAsset(entryOrAsset)) {
1849
1860
  return entryOrAsset;
1850
1861
  }
1862
+ else if (!isEntry(entryOrAsset)) {
1863
+ throw new Error(`Expected an Entry or Asset, but got: ${JSON.stringify(entryOrAsset)}`);
1864
+ }
1851
1865
  const value = get(entryOrAsset, path.split('/').slice(2, -1));
1852
- if (value?.sys.type !== 'Link') {
1853
- console.warn(`Expected a link to a reference, but got: ${JSON.stringify(value)}`);
1854
- return;
1866
+ let resolvedEntity;
1867
+ if (isAsset(value) || isEntry(value)) {
1868
+ // In some cases, reference fields are already resolved
1869
+ resolvedEntity = value;
1870
+ }
1871
+ else if (value?.sys.type === 'Link') {
1872
+ // Look up the reference in the entity store
1873
+ resolvedEntity = entityStore.getEntityFromLink(value);
1874
+ if (!resolvedEntity) {
1875
+ return;
1876
+ }
1855
1877
  }
1856
- //Look up the reference in the entity store
1857
- const resolvedEntity = entityStore.getEntityFromLink(value);
1858
- if (!resolvedEntity) {
1878
+ else {
1879
+ console.warn(`Expected a link to a reference, but got: ${JSON.stringify(value)}`);
1859
1880
  return;
1860
1881
  }
1861
1882
  //resolve any embedded links - we currently only support 2 levels deep
@@ -2110,10 +2131,13 @@ class EntityStoreBase {
2110
2131
  }
2111
2132
  entity = resolvedEntity;
2112
2133
  }
2113
- else {
2134
+ else if (isAsset(linkOrEntryOrAsset) || isEntry(linkOrEntryOrAsset)) {
2114
2135
  // We already have the complete entity in preview & delivery (resolved by the CMA client)
2115
2136
  entity = linkOrEntryOrAsset;
2116
2137
  }
2138
+ else {
2139
+ throw new Error(`Unexpected object when resolving entity: ${JSON.stringify(linkOrEntryOrAsset)}`);
2140
+ }
2117
2141
  return entity;
2118
2142
  }
2119
2143
  /**
@@ -2159,14 +2183,14 @@ class EntityStoreBase {
2159
2183
  };
2160
2184
  }
2161
2185
  addEntity(entity) {
2162
- if (this.isAsset(entity)) {
2186
+ if (isAsset(entity)) {
2163
2187
  this.assetMap.set(entity.sys.id, entity);
2164
2188
  }
2165
- else if (this.isEntry(entity)) {
2189
+ else if (isEntry(entity)) {
2166
2190
  this.entryMap.set(entity.sys.id, entity);
2167
2191
  }
2168
2192
  else {
2169
- console.warn('Attempted to add an entity that is neither Asset nor Entry:', entity);
2193
+ throw new Error(`Attempted to add an entity to the store that is neither Asset nor Entry: '${JSON.stringify(entity)}'`);
2170
2194
  }
2171
2195
  }
2172
2196
  async fetchAsset(id) {
@@ -2236,7 +2260,7 @@ class EntityStoreBase {
2236
2260
  resolvedFieldset.push([entityToResolveFieldsFrom, field, _localeQualifier]);
2237
2261
  entityToResolveFieldsFrom = entity; // we move up
2238
2262
  }
2239
- else if (this.isAsset(fieldValue) || this.isEntry(fieldValue)) {
2263
+ else if (isAsset(fieldValue) || isEntry(fieldValue)) {
2240
2264
  resolvedFieldset.push([entityToResolveFieldsFrom, field, _localeQualifier]);
2241
2265
  entityToResolveFieldsFrom = fieldValue; // we move up
2242
2266
  }
@@ -2272,18 +2296,6 @@ class EntityStoreBase {
2272
2296
  const [leafEntity] = resolvedFieldset[resolvedFieldset.length - 1];
2273
2297
  return leafEntity;
2274
2298
  }
2275
- isAsset(value) {
2276
- return (null !== value &&
2277
- typeof value === 'object' &&
2278
- 'sys' in value &&
2279
- value.sys?.type === 'Asset');
2280
- }
2281
- isEntry(value) {
2282
- return (null !== value &&
2283
- typeof value === 'object' &&
2284
- 'sys' in value &&
2285
- value.sys?.type === 'Entry');
2286
- }
2287
2299
  getEntity(type, id) {
2288
2300
  if (type === 'Asset') {
2289
2301
  return this.assetMap.get(id);
@@ -3569,7 +3581,6 @@ const ComponentPropertyValueSchema = z.discriminatedUnion('type', [
3569
3581
  const PatternPropertySchema = z.object({
3570
3582
  type: z.literal('BoundValue'),
3571
3583
  path: z.string(),
3572
- contentType: z.string(),
3573
3584
  });
3574
3585
  const PatternPropertiesSchema = z.record(propertyKeySchema, PatternPropertySchema);
3575
3586
  const BreakpointSchema = z
@@ -3901,7 +3912,7 @@ var VisualEditorMode;
3901
3912
  VisualEditorMode["InjectScript"] = "injectScript";
3902
3913
  })(VisualEditorMode || (VisualEditorMode = {}));
3903
3914
 
3904
- var css_248z$2$1 = ".contentful-container {\n position: relative;\n display: flex;\n box-sizing: border-box;\n pointer-events: all;\n}\n\n.contentful-container::-webkit-scrollbar {\n display: none; /* Safari and Chrome */\n}\n\n.cf-single-column-wrapper {\n position: relative;\n}\n\n.cf-container-wrapper {\n position: relative;\n width: 100%;\n}\n\n.contentful-container:after {\n content: '';\n display: block;\n position: absolute;\n pointer-events: none;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n display: flex;\n justify-content: center;\n align-items: center;\n overflow-x: clip;\n font-family: var(--exp-builder-font-stack-primary);\n font-size: 12px;\n color: var(--exp-builder-gray400);\n z-index: 1;\n}\n\n.contentful-section-label:after {\n content: 'Section';\n}\n\n.contentful-container-label:after {\n content: 'Container';\n}\n\n/* used by ContentfulSectionAsHyperlink.tsx */\n\n.contentful-container-link,\n.contentful-container-link:active,\n.contentful-container-link:visited,\n.contentful-container-link:hover,\n.contentful-container-link:read-write,\n.contentful-container-link:focus-visible {\n color: inherit;\n text-decoration: unset;\n outline: unset;\n}\n";
3915
+ var css_248z$2$1 = ".contentful-container {\n position: relative;\n display: flex;\n pointer-events: all;\n}\n\n.contentful-container::-webkit-scrollbar {\n display: none; /* Safari and Chrome */\n}\n\n.cf-single-column-wrapper {\n position: relative;\n}\n\n.cf-container-wrapper {\n position: relative;\n width: 100%;\n}\n\n.contentful-container:after {\n content: '';\n display: block;\n position: absolute;\n pointer-events: none;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n display: flex;\n justify-content: center;\n align-items: center;\n overflow-x: clip;\n font-family: var(--exp-builder-font-stack-primary);\n font-size: 12px;\n color: var(--exp-builder-gray400);\n z-index: 1;\n}\n\n.contentful-section-label:after {\n content: 'Section';\n}\n\n.contentful-container-label:after {\n content: 'Container';\n}\n\n/* used by ContentfulSectionAsHyperlink.tsx */\n\n.contentful-container-link,\n.contentful-container-link:active,\n.contentful-container-link:visited,\n.contentful-container-link:hover,\n.contentful-container-link:read-write,\n.contentful-container-link:focus-visible {\n color: inherit;\n text-decoration: unset;\n outline: unset;\n}\n";
3905
3916
  styleInject(css_248z$2$1);
3906
3917
 
3907
3918
  const Flex = forwardRef(({ id, children, onMouseEnter, onMouseUp, onMouseLeave, onMouseDown, onClick, flex, flexBasis, flexShrink, flexDirection, gap, justifyContent, justifyItems, justifySelf, alignItems, alignSelf, alignContent, order, flexWrap, flexGrow, className, cssStyles, ...props }, ref) => {
@@ -5510,7 +5521,7 @@ function useSingleColumn(node, resolveDesignValue) {
5510
5521
  return false;
5511
5522
  }
5512
5523
  const { cfWrapColumns } = parentNode.data.props;
5513
- if (cfWrapColumns.type !== 'DesignValue') {
5524
+ if (cfWrapColumns?.type !== 'DesignValue') {
5514
5525
  return false;
5515
5526
  }
5516
5527
  return resolveDesignValue(cfWrapColumns.valuesByBreakpoint);