@contentful/experiences-core 1.37.1 → 1.37.2-dev-20250515T1505-4c9ed48.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.d.ts CHANGED
@@ -11,6 +11,7 @@ export { sanitizeNodeProps } from './utils/sanitizeNodeProps.js';
11
11
  export { addMinHeightForEmptyStructures, buildCfStyles, buildStyleTag, calculateNodeDefaultHeight, stringifyCssProperties, toCSSAttribute } from './utils/styleUtils/stylesUtils.js';
12
12
  export { detachExperienceStyles, flattenDesignTokenRegistry, indexByBreakpoint, isCfStyleAttribute, maybePopulateDesignTokenValue, resolveBackgroundImageBinding, toMediaQuery } from './utils/styleUtils/ssrStyles.js';
13
13
  export { transformBoundContentValue } from './utils/transformers/transformBoundContentValue.js';
14
+ export { treeMap, treeVisit } from './utils/treeTraversal.js';
14
15
  export { isExperienceEntry } from './utils/typeguards.js';
15
16
  export { checkIsAssembly, checkIsAssemblyDefinition, checkIsAssemblyEntry, checkIsAssemblyNode, generateRandomId, getDataFromTree, getInsertionData, getTargetValueInPixels, parseCSSValue } from './utils/utils.js';
16
17
  export { doesMismatchMessageSchema, tryParseMessage, validateExperienceBuilderConfig } from './utils/validations.js';
package/dist/index.js CHANGED
@@ -1758,6 +1758,7 @@ const transformVisibility = (value) => {
1758
1758
  // Don't explicitly set anything when visible to not overwrite values like `grid` or `flex`.
1759
1759
  return {};
1760
1760
  };
1761
+ // TODO: Remove in next major version v2 since the change is 17 months old
1761
1762
  // Keep this for backwards compatibility - deleting this would be a breaking change
1762
1763
  // because existing components on a users experience will have the width value as fill
1763
1764
  // rather than 100%
@@ -2176,10 +2177,11 @@ const detachExperienceStyles = (experience) => {
2176
2177
  /* [Data format] `generatedCss` is the minimized CSS string that will be added to the DOM:
2177
2178
  * generatedCss = "margin: 1px;width: 100%;..."
2178
2179
  */
2179
- // I create a hash of the object above because that would ensure hash stability
2180
- // Adding breakpointId to ensure not using the same IDs between breakpoints as this leads to
2180
+ // - Adding breakpointId to ensure not using the same IDs between breakpoints as this leads to
2181
2181
  // conflicts between different breakpoint values from multiple nodes where the hash would be equal
2182
- const styleHash = md5(breakpointId + generatedCss);
2182
+ // - Adding wrapping pattern nodes IDs to avoid conflicts between similar nested patterns as those
2183
+ // could override each others CSS for some breakpoints just through the order of `<style>` tags in the DOM.
2184
+ const styleHash = md5(currentPatternNodeIdsChain + breakpointId + generatedCss);
2183
2185
  // and prefix the className to make sure the value can be processed
2184
2186
  const className = `cf-${styleHash}`;
2185
2187
  // I save the generated hashes into an array to later save it in the tree node
@@ -2859,6 +2861,42 @@ const transformBoundContentValue = (variables, entityStore, binding, resolveDesi
2859
2861
  }
2860
2862
  };
2861
2863
 
2864
+ function treeVisit(initialNode, onNode) {
2865
+ // returns last used index
2866
+ const _treeVisit = (currentNode, currentIndex, currentDepth) => {
2867
+ // Copy children in case of onNode removing it as we pass the node by reference
2868
+ const children = [...currentNode.children];
2869
+ onNode(currentNode, currentIndex, currentDepth);
2870
+ let nextAvailableIndex = currentIndex + 1;
2871
+ const lastUsedIndex = currentIndex;
2872
+ for (const child of children) {
2873
+ const lastUsedIndex = _treeVisit(child, nextAvailableIndex, currentDepth + 1);
2874
+ nextAvailableIndex = lastUsedIndex + 1;
2875
+ }
2876
+ return lastUsedIndex;
2877
+ };
2878
+ _treeVisit(initialNode, 0, 0);
2879
+ }
2880
+ /**
2881
+ * Traverses all nodes of a tree and maps all of them.
2882
+ * Intuitively works similarly to Array.map().
2883
+ * When returning mapped object from the mapper function
2884
+ * you _do not_ need to return about `.children[]` field.
2885
+ * This field is automatically managed by the treeMap() function.
2886
+ *
2887
+ * You can map each node to whatever you want, but shouldn't
2888
+ * modify the structure of the tree from the mapping function.
2889
+ */
2890
+ function treeMap(node, onNode) {
2891
+ // Copy children in case of onNode removing it as we pass the node by reference
2892
+ const children = [...node.children];
2893
+ const newNode = {
2894
+ ...onNode(node),
2895
+ children: children.map((child) => treeMap(child, onNode)),
2896
+ };
2897
+ return newNode;
2898
+ }
2899
+
2862
2900
  const isExperienceEntry = (entry) => {
2863
2901
  return (entry?.sys?.type === 'Entry' &&
2864
2902
  !!entry.fields?.title &&
@@ -3612,23 +3650,6 @@ const fetchExperienceEntry = async ({ client, experienceTypeId, locale, identifi
3612
3650
  return entries.items[0];
3613
3651
  };
3614
3652
 
3615
- function treeVisit(initialNode, onNode) {
3616
- // returns last used index
3617
- const _treeVisit = (currentNode, currentIndex, currentDepth) => {
3618
- // Copy children in case of onNode removing it as we pass the node by reference
3619
- const children = [...currentNode.children];
3620
- onNode(currentNode, currentIndex, currentDepth);
3621
- let nextAvailableIndex = currentIndex + 1;
3622
- const lastUsedIndex = currentIndex;
3623
- for (const child of children) {
3624
- const lastUsedIndex = _treeVisit(child, nextAvailableIndex, currentDepth + 1);
3625
- nextAvailableIndex = lastUsedIndex + 1;
3626
- }
3627
- return lastUsedIndex;
3628
- };
3629
- _treeVisit(initialNode, 0, 0);
3630
- }
3631
-
3632
3653
  class DeepReference {
3633
3654
  constructor({ path, dataSource }) {
3634
3655
  const { key, field, referentField } = parseDataSourcePathWithL1DeepBindings(path);
@@ -4094,5 +4115,5 @@ async function fetchById({ client, experienceTypeId, id, localeCode, isEditorMod
4094
4115
  }
4095
4116
  }
4096
4117
 
4097
- export { DebugLogger, DeepReference, EditorModeEntityStore, EntityStore, EntityStoreBase, MEDIA_QUERY_REGEXP, VisualEditorMode, addLocale, addMinHeightForEmptyStructures, breakpointsRegistry, buildCfStyles, buildStyleTag, buildTemplate, builtInStyles, calculateNodeDefaultHeight, checkIsAssembly, checkIsAssemblyDefinition, checkIsAssemblyEntry, checkIsAssemblyNode, columnsBuiltInStyles, containerBuiltInStyles, createExperience, debug, defineBreakpoints, defineDesignTokens, designTokensRegistry, detachExperienceStyles, disableDebug, dividerBuiltInStyles, doesMismatchMessageSchema, enableDebug, fetchAllAssets, fetchAllEntries, fetchById, fetchBySlug, fetchExperienceEntry, fetchReferencedEntities, findOutermostCoordinates, flattenDesignTokenRegistry, gatherDeepReferencesFromExperienceEntry, gatherDeepReferencesFromTree, generateRandomId, getActiveBreakpointIndex, getBreakpointRegistration, getDataFromTree, getDesignTokenRegistration, getElementCoordinates, getFallbackBreakpointIndex, getInsertionData, getTargetValueInPixels, getTemplateValue, getValueForBreakpoint, indexByBreakpoint, isCfStyleAttribute, isComponentAllowedOnRoot, isContentfulComponent, isContentfulStructureComponent, isDeepPath, isExperienceEntry, isLink, isLinkToAsset, isPatternComponent, isStructureWithRelativeHeight, isValidBreakpointValue, lastPathNamedSegmentEq, localizeEntity, maybePopulateDesignTokenValue, mediaQueryMatcher, optionalBuiltInStyles, parseCSSValue, parseDataSourcePathIntoFieldset, parseDataSourcePathWithL1DeepBindings, resetBreakpointsRegistry, resetDesignTokenRegistry, resolveBackgroundImageBinding, resolveHyperlinkPattern, runBreakpointsValidation, sanitizeNodeProps, sectionBuiltInStyles, sendMessage, singleColumnBuiltInStyles, stringifyCssProperties, toCSSAttribute, toMediaQuery, transformBoundContentValue, tryParseMessage, validateExperienceBuilderConfig };
4118
+ export { DebugLogger, DeepReference, EditorModeEntityStore, EntityStore, EntityStoreBase, MEDIA_QUERY_REGEXP, VisualEditorMode, addLocale, addMinHeightForEmptyStructures, breakpointsRegistry, buildCfStyles, buildStyleTag, buildTemplate, builtInStyles, calculateNodeDefaultHeight, checkIsAssembly, checkIsAssemblyDefinition, checkIsAssemblyEntry, checkIsAssemblyNode, columnsBuiltInStyles, containerBuiltInStyles, createExperience, debug, defineBreakpoints, defineDesignTokens, designTokensRegistry, detachExperienceStyles, disableDebug, dividerBuiltInStyles, doesMismatchMessageSchema, enableDebug, fetchAllAssets, fetchAllEntries, fetchById, fetchBySlug, fetchExperienceEntry, fetchReferencedEntities, findOutermostCoordinates, flattenDesignTokenRegistry, gatherDeepReferencesFromExperienceEntry, gatherDeepReferencesFromTree, generateRandomId, getActiveBreakpointIndex, getBreakpointRegistration, getDataFromTree, getDesignTokenRegistration, getElementCoordinates, getFallbackBreakpointIndex, getInsertionData, getTargetValueInPixels, getTemplateValue, getValueForBreakpoint, indexByBreakpoint, isCfStyleAttribute, isComponentAllowedOnRoot, isContentfulComponent, isContentfulStructureComponent, isDeepPath, isExperienceEntry, isLink, isLinkToAsset, isPatternComponent, isStructureWithRelativeHeight, isValidBreakpointValue, lastPathNamedSegmentEq, localizeEntity, maybePopulateDesignTokenValue, mediaQueryMatcher, optionalBuiltInStyles, parseCSSValue, parseDataSourcePathIntoFieldset, parseDataSourcePathWithL1DeepBindings, resetBreakpointsRegistry, resetDesignTokenRegistry, resolveBackgroundImageBinding, resolveHyperlinkPattern, runBreakpointsValidation, sanitizeNodeProps, sectionBuiltInStyles, sendMessage, singleColumnBuiltInStyles, stringifyCssProperties, toCSSAttribute, toMediaQuery, transformBoundContentValue, treeMap, treeVisit, tryParseMessage, validateExperienceBuilderConfig };
4098
4119
  //# sourceMappingURL=index.js.map