@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/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import React, { useEffect, useRef, useState, useCallback, forwardRef, useLayoutE
|
|
|
3
3
|
import md5 from 'md5';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { BLOCKS } from '@contentful/rich-text-types';
|
|
6
|
-
import { isEqual, get as get$1, omit } from 'lodash-es';
|
|
6
|
+
import { isArray, isEqual, get as get$1, omit } from 'lodash-es';
|
|
7
7
|
import { create } from 'zustand';
|
|
8
8
|
import { Droppable, Draggable, DragDropContext } from '@hello-pangea/dnd';
|
|
9
9
|
import { produce } from 'immer';
|
|
@@ -736,6 +736,8 @@ const DefinitionPropertyTypeSchema = z.enum([
|
|
|
736
736
|
'Media',
|
|
737
737
|
'Object',
|
|
738
738
|
'Hyperlink',
|
|
739
|
+
'Array',
|
|
740
|
+
'Link',
|
|
739
741
|
]);
|
|
740
742
|
const DefinitionPropertyKeySchema = z
|
|
741
743
|
.string()
|
|
@@ -1139,19 +1141,61 @@ const transformMedia = (asset, variables, resolveDesignValue, variableName, path
|
|
|
1139
1141
|
return asset.fields.file?.url;
|
|
1140
1142
|
};
|
|
1141
1143
|
|
|
1144
|
+
function getResolvedEntryFromLink(entryOrAsset, path, entityStore) {
|
|
1145
|
+
if (entryOrAsset.sys.type === 'Asset') {
|
|
1146
|
+
return entryOrAsset;
|
|
1147
|
+
}
|
|
1148
|
+
const value = get(entryOrAsset, path.split('/').slice(2, -1));
|
|
1149
|
+
if (value?.sys.type !== 'Link') {
|
|
1150
|
+
console.warn(`Expected a link to a reference, but got: ${JSON.stringify(value)}`);
|
|
1151
|
+
return;
|
|
1152
|
+
}
|
|
1153
|
+
//Look up the reference in the entity store
|
|
1154
|
+
const resolvedEntity = entityStore.getEntityFromLink(value);
|
|
1155
|
+
return resolvedEntity;
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
function getArrayValue(entryOrAsset, path, entityStore) {
|
|
1159
|
+
if (entryOrAsset.sys.type === 'Asset') {
|
|
1160
|
+
return entryOrAsset;
|
|
1161
|
+
}
|
|
1162
|
+
const arrayValue = get(entryOrAsset, path.split('/').slice(2, -1));
|
|
1163
|
+
if (!isArray(arrayValue)) {
|
|
1164
|
+
console.warn(`Expected a value to be an array, but got: ${JSON.stringify(arrayValue)}`);
|
|
1165
|
+
return;
|
|
1166
|
+
}
|
|
1167
|
+
const result = arrayValue.map((value) => {
|
|
1168
|
+
if (typeof value === 'string') {
|
|
1169
|
+
return value;
|
|
1170
|
+
}
|
|
1171
|
+
else if (value?.sys?.type === 'Link') {
|
|
1172
|
+
return entityStore.getEntityFromLink(value);
|
|
1173
|
+
}
|
|
1174
|
+
else {
|
|
1175
|
+
console.warn(`Expected value to be a string or Link, but got: ${JSON.stringify(value)}`);
|
|
1176
|
+
return undefined;
|
|
1177
|
+
}
|
|
1178
|
+
});
|
|
1179
|
+
return result;
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1142
1182
|
const transformBoundContentValue = (variables, entityStore, binding, resolveDesignValue, variableName, variableDefinition, path) => {
|
|
1143
1183
|
const entityOrAsset = entityStore.getEntryOrAsset(binding, path);
|
|
1144
1184
|
if (!entityOrAsset)
|
|
1145
1185
|
return;
|
|
1146
1186
|
switch (variableDefinition.type) {
|
|
1147
1187
|
case 'Media':
|
|
1148
|
-
// If we bound a normal entry field to the media
|
|
1188
|
+
// If we bound a normal entry field to the media variable we just return the bound value
|
|
1149
1189
|
if (entityOrAsset.sys.type === 'Entry') {
|
|
1150
1190
|
return getBoundValue(entityOrAsset, path);
|
|
1151
1191
|
}
|
|
1152
1192
|
return transformMedia(entityOrAsset, variables, resolveDesignValue, variableName, path);
|
|
1153
1193
|
case 'RichText':
|
|
1154
1194
|
return transformRichText(entityOrAsset, path);
|
|
1195
|
+
case 'Array':
|
|
1196
|
+
return getArrayValue(entityOrAsset, path, entityStore);
|
|
1197
|
+
case 'Link':
|
|
1198
|
+
return getResolvedEntryFromLink(entityOrAsset, path, entityStore);
|
|
1155
1199
|
default:
|
|
1156
1200
|
return getBoundValue(entityOrAsset, path);
|
|
1157
1201
|
}
|
|
@@ -1837,8 +1881,8 @@ class EditorModeEntityStore extends EditorEntityStore {
|
|
|
1837
1881
|
async fetchEntities({ missingEntryIds, missingAssetIds, skipCache = false, }) {
|
|
1838
1882
|
// Entries and assets will be stored in entryMap and assetMap
|
|
1839
1883
|
await Promise.all([
|
|
1840
|
-
|
|
1841
|
-
|
|
1884
|
+
super.fetchEntries(missingEntryIds, skipCache),
|
|
1885
|
+
super.fetchAssets(missingAssetIds, skipCache),
|
|
1842
1886
|
]);
|
|
1843
1887
|
}
|
|
1844
1888
|
getMissingEntityIds(entityLinks) {
|