@contentful/experiences-visual-editor-react 1.9.1-dev-20240702T1452-263f331.0 → 1.10.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 +48 -4
- package/dist/index.js.map +1 -1
- package/dist/renderApp.js +47 -3
- package/dist/renderApp.js.map +1 -1
- package/package.json +4 -4
package/dist/renderApp.js
CHANGED
|
@@ -42868,6 +42868,8 @@ const DefinitionPropertyTypeSchema = z.enum([
|
|
|
42868
42868
|
'Media',
|
|
42869
42869
|
'Object',
|
|
42870
42870
|
'Hyperlink',
|
|
42871
|
+
'Array',
|
|
42872
|
+
'Link',
|
|
42871
42873
|
]);
|
|
42872
42874
|
const DefinitionPropertyKeySchema = z
|
|
42873
42875
|
.string()
|
|
@@ -43271,19 +43273,61 @@ const transformMedia = (asset, variables, resolveDesignValue, variableName, path
|
|
|
43271
43273
|
return asset.fields.file?.url;
|
|
43272
43274
|
};
|
|
43273
43275
|
|
|
43276
|
+
function getResolvedEntryFromLink(entryOrAsset, path, entityStore) {
|
|
43277
|
+
if (entryOrAsset.sys.type === 'Asset') {
|
|
43278
|
+
return entryOrAsset;
|
|
43279
|
+
}
|
|
43280
|
+
const value = get(entryOrAsset, path.split('/').slice(2, -1));
|
|
43281
|
+
if (value?.sys.type !== 'Link') {
|
|
43282
|
+
console.warn(`Expected a link to a reference, but got: ${JSON.stringify(value)}`);
|
|
43283
|
+
return;
|
|
43284
|
+
}
|
|
43285
|
+
//Look up the reference in the entity store
|
|
43286
|
+
const resolvedEntity = entityStore.getEntityFromLink(value);
|
|
43287
|
+
return resolvedEntity;
|
|
43288
|
+
}
|
|
43289
|
+
|
|
43290
|
+
function getArrayValue(entryOrAsset, path, entityStore) {
|
|
43291
|
+
if (entryOrAsset.sys.type === 'Asset') {
|
|
43292
|
+
return entryOrAsset;
|
|
43293
|
+
}
|
|
43294
|
+
const arrayValue = get(entryOrAsset, path.split('/').slice(2, -1));
|
|
43295
|
+
if (!isArray(arrayValue)) {
|
|
43296
|
+
console.warn(`Expected a value to be an array, but got: ${JSON.stringify(arrayValue)}`);
|
|
43297
|
+
return;
|
|
43298
|
+
}
|
|
43299
|
+
const result = arrayValue.map((value) => {
|
|
43300
|
+
if (typeof value === 'string') {
|
|
43301
|
+
return value;
|
|
43302
|
+
}
|
|
43303
|
+
else if (value?.sys?.type === 'Link') {
|
|
43304
|
+
return entityStore.getEntityFromLink(value);
|
|
43305
|
+
}
|
|
43306
|
+
else {
|
|
43307
|
+
console.warn(`Expected value to be a string or Link, but got: ${JSON.stringify(value)}`);
|
|
43308
|
+
return undefined;
|
|
43309
|
+
}
|
|
43310
|
+
});
|
|
43311
|
+
return result;
|
|
43312
|
+
}
|
|
43313
|
+
|
|
43274
43314
|
const transformBoundContentValue = (variables, entityStore, binding, resolveDesignValue, variableName, variableDefinition, path) => {
|
|
43275
43315
|
const entityOrAsset = entityStore.getEntryOrAsset(binding, path);
|
|
43276
43316
|
if (!entityOrAsset)
|
|
43277
43317
|
return;
|
|
43278
43318
|
switch (variableDefinition.type) {
|
|
43279
43319
|
case 'Media':
|
|
43280
|
-
// If we bound a normal entry field to the media
|
|
43320
|
+
// If we bound a normal entry field to the media variable we just return the bound value
|
|
43281
43321
|
if (entityOrAsset.sys.type === 'Entry') {
|
|
43282
43322
|
return getBoundValue(entityOrAsset, path);
|
|
43283
43323
|
}
|
|
43284
43324
|
return transformMedia(entityOrAsset, variables, resolveDesignValue, variableName, path);
|
|
43285
43325
|
case 'RichText':
|
|
43286
43326
|
return transformRichText(entityOrAsset, path);
|
|
43327
|
+
case 'Array':
|
|
43328
|
+
return getArrayValue(entityOrAsset, path, entityStore);
|
|
43329
|
+
case 'Link':
|
|
43330
|
+
return getResolvedEntryFromLink(entityOrAsset, path, entityStore);
|
|
43287
43331
|
default:
|
|
43288
43332
|
return getBoundValue(entityOrAsset, path);
|
|
43289
43333
|
}
|
|
@@ -43969,8 +44013,8 @@ class EditorModeEntityStore extends EditorEntityStore {
|
|
|
43969
44013
|
async fetchEntities({ missingEntryIds, missingAssetIds, skipCache = false, }) {
|
|
43970
44014
|
// Entries and assets will be stored in entryMap and assetMap
|
|
43971
44015
|
await Promise.all([
|
|
43972
|
-
|
|
43973
|
-
|
|
44016
|
+
super.fetchEntries(missingEntryIds, skipCache),
|
|
44017
|
+
super.fetchAssets(missingAssetIds, skipCache),
|
|
43974
44018
|
]);
|
|
43975
44019
|
}
|
|
43976
44020
|
getMissingEntityIds(entityLinks) {
|