@contentful/experiences-core 1.37.1-dev-20250430T0833-06bfee1.0 → 1.37.1-dev-20250513T0700-6e8c057.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 +1 -0
- package/dist/index.js +37 -18
- package/dist/index.js.map +1 -1
- package/dist/utils/treeTraversal.d.ts +17 -0
- package/package.json +3 -3
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
|
@@ -2860,6 +2860,42 @@ const transformBoundContentValue = (variables, entityStore, binding, resolveDesi
|
|
|
2860
2860
|
}
|
|
2861
2861
|
};
|
|
2862
2862
|
|
|
2863
|
+
function treeVisit(initialNode, onNode) {
|
|
2864
|
+
// returns last used index
|
|
2865
|
+
const _treeVisit = (currentNode, currentIndex, currentDepth) => {
|
|
2866
|
+
// Copy children in case of onNode removing it as we pass the node by reference
|
|
2867
|
+
const children = [...currentNode.children];
|
|
2868
|
+
onNode(currentNode, currentIndex, currentDepth);
|
|
2869
|
+
let nextAvailableIndex = currentIndex + 1;
|
|
2870
|
+
const lastUsedIndex = currentIndex;
|
|
2871
|
+
for (const child of children) {
|
|
2872
|
+
const lastUsedIndex = _treeVisit(child, nextAvailableIndex, currentDepth + 1);
|
|
2873
|
+
nextAvailableIndex = lastUsedIndex + 1;
|
|
2874
|
+
}
|
|
2875
|
+
return lastUsedIndex;
|
|
2876
|
+
};
|
|
2877
|
+
_treeVisit(initialNode, 0, 0);
|
|
2878
|
+
}
|
|
2879
|
+
/**
|
|
2880
|
+
* Traverses all nodes of a tree and maps all of them.
|
|
2881
|
+
* Intuitively works similarly to Array.map().
|
|
2882
|
+
* When returning mapped object from the mapper function
|
|
2883
|
+
* you _do not_ need to return about `.children[]` field.
|
|
2884
|
+
* This field is automatically managed by the treeMap() function.
|
|
2885
|
+
*
|
|
2886
|
+
* You can map each node to whatever you want, but shouldn't
|
|
2887
|
+
* modify the structure of the tree from the mapping function.
|
|
2888
|
+
*/
|
|
2889
|
+
function treeMap(node, onNode) {
|
|
2890
|
+
// Copy children in case of onNode removing it as we pass the node by reference
|
|
2891
|
+
const children = [...node.children];
|
|
2892
|
+
const newNode = {
|
|
2893
|
+
...onNode(node),
|
|
2894
|
+
children: children.map((child) => treeMap(child, onNode)),
|
|
2895
|
+
};
|
|
2896
|
+
return newNode;
|
|
2897
|
+
}
|
|
2898
|
+
|
|
2863
2899
|
const isExperienceEntry = (entry) => {
|
|
2864
2900
|
return (entry?.sys?.type === 'Entry' &&
|
|
2865
2901
|
!!entry.fields?.title &&
|
|
@@ -3613,23 +3649,6 @@ const fetchExperienceEntry = async ({ client, experienceTypeId, locale, identifi
|
|
|
3613
3649
|
return entries.items[0];
|
|
3614
3650
|
};
|
|
3615
3651
|
|
|
3616
|
-
function treeVisit(initialNode, onNode) {
|
|
3617
|
-
// returns last used index
|
|
3618
|
-
const _treeVisit = (currentNode, currentIndex, currentDepth) => {
|
|
3619
|
-
// Copy children in case of onNode removing it as we pass the node by reference
|
|
3620
|
-
const children = [...currentNode.children];
|
|
3621
|
-
onNode(currentNode, currentIndex, currentDepth);
|
|
3622
|
-
let nextAvailableIndex = currentIndex + 1;
|
|
3623
|
-
const lastUsedIndex = currentIndex;
|
|
3624
|
-
for (const child of children) {
|
|
3625
|
-
const lastUsedIndex = _treeVisit(child, nextAvailableIndex, currentDepth + 1);
|
|
3626
|
-
nextAvailableIndex = lastUsedIndex + 1;
|
|
3627
|
-
}
|
|
3628
|
-
return lastUsedIndex;
|
|
3629
|
-
};
|
|
3630
|
-
_treeVisit(initialNode, 0, 0);
|
|
3631
|
-
}
|
|
3632
|
-
|
|
3633
3652
|
class DeepReference {
|
|
3634
3653
|
constructor({ path, dataSource }) {
|
|
3635
3654
|
const { key, field, referentField } = parseDataSourcePathWithL1DeepBindings(path);
|
|
@@ -4095,5 +4114,5 @@ async function fetchById({ client, experienceTypeId, id, localeCode, isEditorMod
|
|
|
4095
4114
|
}
|
|
4096
4115
|
}
|
|
4097
4116
|
|
|
4098
|
-
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 };
|
|
4117
|
+
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 };
|
|
4099
4118
|
//# sourceMappingURL=index.js.map
|