@contentful/experiences-core 1.8.3-dev-20240628T0417-d61b95b.0 → 1.8.3-prerelease-20240708T2122-658393c.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.
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ContentfulClientApi, Entry, Asset } from 'contentful';
|
|
2
|
+
import { MinimalEntryCollection } from './gatherAutoFetchedReferentsFromIncludes.js';
|
|
3
|
+
|
|
4
|
+
declare const fetchAllEntries: ({ client, ids, locale, skip, limit, responseItems, responseIncludes, }: {
|
|
5
|
+
client: ContentfulClientApi<undefined>;
|
|
6
|
+
ids: string[];
|
|
7
|
+
locale?: string;
|
|
8
|
+
skip?: number;
|
|
9
|
+
limit?: number;
|
|
10
|
+
responseItems?: Entry[];
|
|
11
|
+
responseIncludes?: MinimalEntryCollection["includes"];
|
|
12
|
+
}) => Promise<{
|
|
13
|
+
items: Entry[];
|
|
14
|
+
includes: {
|
|
15
|
+
Entry: Entry[];
|
|
16
|
+
Asset: Asset[];
|
|
17
|
+
};
|
|
18
|
+
}>;
|
|
19
|
+
declare const fetchAllAssets: ({ client, ids, locale, skip, limit, responseItems, }: {
|
|
20
|
+
client: ContentfulClientApi<undefined>;
|
|
21
|
+
ids: string[];
|
|
22
|
+
locale?: string;
|
|
23
|
+
skip?: number;
|
|
24
|
+
limit?: number;
|
|
25
|
+
responseItems?: Asset[];
|
|
26
|
+
}) => Promise<{
|
|
27
|
+
items: Asset[];
|
|
28
|
+
}>;
|
|
29
|
+
|
|
30
|
+
export { fetchAllAssets, fetchAllEntries };
|
package/dist/index.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export { sendMessage } from './communication/sendMessage.js';
|
|
|
21
21
|
export { VisualEditorMode } from './enums.js';
|
|
22
22
|
export { fetchBySlug } from './fetchers/fetchBySlug.js';
|
|
23
23
|
export { fetchById } from './fetchers/fetchById.js';
|
|
24
|
+
export { fetchAllAssets, fetchAllEntries } from './fetchers/fetchAllEntities.js';
|
|
24
25
|
export { createExperience } from './fetchers/createExperience.js';
|
|
25
26
|
export { defineDesignTokens, designTokensRegistry, getDesignTokenRegistration, resetDesignTokenRegistry } from './registries/designTokenRegistry.js';
|
|
26
27
|
export { breakpointsRegistry, defineBreakpoints, getBreakpointRegistration, resetBreakpointsRegistry, runBreakpointsValidation } from './registries/breakpointsRegistry.js';
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import md5 from 'md5';
|
|
2
2
|
import { z, ZodIssueCode } from 'zod';
|
|
3
3
|
import { BLOCKS } from '@contentful/rich-text-types';
|
|
4
|
-
import { uniqBy } from 'lodash-es';
|
|
4
|
+
import { isArray, uniqBy } from 'lodash-es';
|
|
5
5
|
|
|
6
6
|
const INCOMING_EVENTS = {
|
|
7
7
|
RequestEditorMode: 'requestEditorMode',
|
|
@@ -1051,6 +1051,8 @@ const DefinitionPropertyTypeSchema = z.enum([
|
|
|
1051
1051
|
'Media',
|
|
1052
1052
|
'Object',
|
|
1053
1053
|
'Hyperlink',
|
|
1054
|
+
'Array',
|
|
1055
|
+
'Link',
|
|
1054
1056
|
]);
|
|
1055
1057
|
const DefinitionPropertyKeySchema = z
|
|
1056
1058
|
.string()
|
|
@@ -2028,19 +2030,62 @@ const transformMedia = (asset, variables, resolveDesignValue, variableName, path
|
|
|
2028
2030
|
return asset.fields.file?.url;
|
|
2029
2031
|
};
|
|
2030
2032
|
|
|
2033
|
+
function getResolvedEntryFromLink(entryOrAsset, path, entityStore) {
|
|
2034
|
+
if (entryOrAsset.sys.type === 'Asset') {
|
|
2035
|
+
return entryOrAsset;
|
|
2036
|
+
}
|
|
2037
|
+
const value = get(entryOrAsset, path.split('/').slice(2, -1));
|
|
2038
|
+
if (value?.sys.type !== 'Link') {
|
|
2039
|
+
console.warn(`Expected a link to a reference, but got: ${JSON.stringify(value)}`);
|
|
2040
|
+
return;
|
|
2041
|
+
}
|
|
2042
|
+
//Look up the reference in the entity store
|
|
2043
|
+
const resolvedEntity = entityStore.getEntityFromLink(value);
|
|
2044
|
+
return resolvedEntity;
|
|
2045
|
+
}
|
|
2046
|
+
|
|
2047
|
+
function getArrayValue(entryOrAsset, path, entityStore) {
|
|
2048
|
+
if (entryOrAsset.sys.type === 'Asset') {
|
|
2049
|
+
return entryOrAsset;
|
|
2050
|
+
}
|
|
2051
|
+
const arrayValue = get(entryOrAsset, path.split('/').slice(2, -1));
|
|
2052
|
+
if (!isArray(arrayValue)) {
|
|
2053
|
+
console.warn(`Expected a value to an array, but got: ${JSON.stringify(arrayValue)}`);
|
|
2054
|
+
return;
|
|
2055
|
+
}
|
|
2056
|
+
const result = arrayValue.map((value) => {
|
|
2057
|
+
if (typeof value === 'string') {
|
|
2058
|
+
return value;
|
|
2059
|
+
}
|
|
2060
|
+
else if (value?.sys?.type === 'Link') {
|
|
2061
|
+
return entityStore.getEntityFromLink(value);
|
|
2062
|
+
}
|
|
2063
|
+
else {
|
|
2064
|
+
console.warn(`Expected value to be a string or Link, but got: ${JSON.stringify(value)}`);
|
|
2065
|
+
return undefined;
|
|
2066
|
+
}
|
|
2067
|
+
});
|
|
2068
|
+
return result;
|
|
2069
|
+
}
|
|
2070
|
+
|
|
2031
2071
|
const transformBoundContentValue = (variables, entityStore, binding, resolveDesignValue, variableName, variableDefinition, path) => {
|
|
2032
2072
|
const entityOrAsset = entityStore.getEntryOrAsset(binding, path);
|
|
2033
2073
|
if (!entityOrAsset)
|
|
2034
2074
|
return;
|
|
2035
2075
|
switch (variableDefinition.type) {
|
|
2036
2076
|
case 'Media':
|
|
2037
|
-
// If we bound a normal entry field to the media
|
|
2077
|
+
// If we bound a normal entry field to the media variable we just return the bound value
|
|
2038
2078
|
if (entityOrAsset.sys.type === 'Entry') {
|
|
2039
2079
|
return getBoundValue(entityOrAsset, path);
|
|
2040
2080
|
}
|
|
2041
2081
|
return transformMedia(entityOrAsset, variables, resolveDesignValue, variableName, path);
|
|
2042
2082
|
case 'RichText':
|
|
2043
2083
|
return transformRichText(entityOrAsset, path);
|
|
2084
|
+
case 'Array':
|
|
2085
|
+
console.log('aaa', 'array type', entityOrAsset, path);
|
|
2086
|
+
return getArrayValue(entityOrAsset, path, entityStore);
|
|
2087
|
+
case 'Link':
|
|
2088
|
+
return getResolvedEntryFromLink(entityOrAsset, path, entityStore);
|
|
2044
2089
|
default:
|
|
2045
2090
|
return getBoundValue(entityOrAsset, path);
|
|
2046
2091
|
}
|
|
@@ -2808,8 +2853,8 @@ class EditorModeEntityStore extends EditorEntityStore {
|
|
|
2808
2853
|
async fetchEntities({ missingEntryIds, missingAssetIds, skipCache = false, }) {
|
|
2809
2854
|
// Entries and assets will be stored in entryMap and assetMap
|
|
2810
2855
|
await Promise.all([
|
|
2811
|
-
|
|
2812
|
-
|
|
2856
|
+
super.fetchEntries(missingEntryIds, skipCache),
|
|
2857
|
+
super.fetchAssets(missingAssetIds, skipCache),
|
|
2813
2858
|
]);
|
|
2814
2859
|
}
|
|
2815
2860
|
getMissingEntityIds(entityLinks) {
|
|
@@ -3250,13 +3295,16 @@ const fetchReferencedEntities = async ({ client, experienceEntry, locale, }) =>
|
|
|
3250
3295
|
// Using client getEntries resolves all linked entry references, so we do not need to resolve entries in usedComponents
|
|
3251
3296
|
const allResolvedEntries = [
|
|
3252
3297
|
...(entriesResponse?.items ?? []),
|
|
3298
|
+
...(entriesResponse.includes?.Entry ?? []),
|
|
3253
3299
|
...(experienceEntry.fields.usedComponents || []),
|
|
3254
3300
|
...autoFetchedReferentEntries,
|
|
3255
3301
|
];
|
|
3256
3302
|
const allResolvedAssets = [
|
|
3257
3303
|
...(assetsResponse.items ?? []),
|
|
3304
|
+
...(entriesResponse?.includes?.Asset ?? []),
|
|
3258
3305
|
...autoFetchedReferentAssets,
|
|
3259
3306
|
];
|
|
3307
|
+
//maybe depuping should happen here? The same asset can appear multiple times, maybe coming back in autoFetchedReferentAssets
|
|
3260
3308
|
return {
|
|
3261
3309
|
entries: allResolvedEntries,
|
|
3262
3310
|
assets: allResolvedAssets,
|
|
@@ -3366,5 +3414,5 @@ async function fetchById({ client, experienceTypeId, id, localeCode, }) {
|
|
|
3366
3414
|
}
|
|
3367
3415
|
}
|
|
3368
3416
|
|
|
3369
|
-
export { DeepReference, EditorModeEntityStore, EntityStore, EntityStoreBase, MEDIA_QUERY_REGEXP, VisualEditorMode, addLocale, breakpointsRegistry, buildCfStyles, buildStyleTag, buildTemplate, builtInStyles, calculateNodeDefaultHeight, checkIsAssembly, checkIsAssemblyDefinition, checkIsAssemblyEntry, checkIsAssemblyNode, columnsBuiltInStyles, columnsDefinition, containerBuiltInStyles, containerDefinition, createExperience, defineBreakpoints, defineDesignTokens, designTokensRegistry, detachExperienceStyles, dividerBuiltInStyles, dividerDefinition, doesMismatchMessageSchema, fetchById, fetchBySlug, findOutermostCoordinates, flattenDesignTokenRegistry, gatherDeepReferencesFromExperienceEntry, gatherDeepReferencesFromTree, generateRandomId, getActiveBreakpointIndex, getBreakpointRegistration, getDataFromTree, getDesignTokenRegistration, getElementCoordinates, getFallbackBreakpointIndex, getInsertionData, getTemplateValue, getValueForBreakpoint, indexByBreakpoint, isCfStyleAttribute, isComponentAllowedOnRoot, isContentfulStructureComponent, isDeepPath, isExperienceEntry, isLink, isLinkToAsset, isStructureWithRelativeHeight, lastPathNamedSegmentEq, maybePopulateDesignTokenValue, mediaQueryMatcher, optionalBuiltInStyles, parseDataSourcePathIntoFieldset, parseDataSourcePathWithL1DeepBindings, resetBreakpointsRegistry, resetDesignTokenRegistry, resolveBackgroundImageBinding, resolveHyperlinkPattern, runBreakpointsValidation, sectionBuiltInStyles, sectionDefinition, sendMessage, singleColumnBuiltInStyles, singleColumnDefinition, supportedModes, toCSSAttribute, toCSSString, toMediaQuery, transformBoundContentValue, tryParseMessage, validateExperienceBuilderConfig };
|
|
3417
|
+
export { DeepReference, EditorModeEntityStore, EntityStore, EntityStoreBase, MEDIA_QUERY_REGEXP, VisualEditorMode, addLocale, breakpointsRegistry, buildCfStyles, buildStyleTag, buildTemplate, builtInStyles, calculateNodeDefaultHeight, checkIsAssembly, checkIsAssemblyDefinition, checkIsAssemblyEntry, checkIsAssemblyNode, columnsBuiltInStyles, columnsDefinition, containerBuiltInStyles, containerDefinition, createExperience, defineBreakpoints, defineDesignTokens, designTokensRegistry, detachExperienceStyles, dividerBuiltInStyles, dividerDefinition, doesMismatchMessageSchema, fetchAllAssets, fetchAllEntries, fetchById, fetchBySlug, findOutermostCoordinates, flattenDesignTokenRegistry, gatherDeepReferencesFromExperienceEntry, gatherDeepReferencesFromTree, generateRandomId, getActiveBreakpointIndex, getBreakpointRegistration, getDataFromTree, getDesignTokenRegistration, getElementCoordinates, getFallbackBreakpointIndex, getInsertionData, getTemplateValue, getValueForBreakpoint, indexByBreakpoint, isCfStyleAttribute, isComponentAllowedOnRoot, isContentfulStructureComponent, isDeepPath, isExperienceEntry, isLink, isLinkToAsset, isStructureWithRelativeHeight, lastPathNamedSegmentEq, maybePopulateDesignTokenValue, mediaQueryMatcher, optionalBuiltInStyles, parseDataSourcePathIntoFieldset, parseDataSourcePathWithL1DeepBindings, resetBreakpointsRegistry, resetDesignTokenRegistry, resolveBackgroundImageBinding, resolveHyperlinkPattern, runBreakpointsValidation, sectionBuiltInStyles, sectionDefinition, sendMessage, singleColumnBuiltInStyles, singleColumnDefinition, supportedModes, toCSSAttribute, toCSSString, toMediaQuery, transformBoundContentValue, tryParseMessage, validateExperienceBuilderConfig };
|
|
3370
3418
|
//# sourceMappingURL=index.js.map
|