@contentful/field-editor-reference 5.21.2 → 5.21.4
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/cjs/__fixtures__/FakeSdk.js +3 -3
- package/dist/cjs/__fixtures__/asset/index.js +10 -10
- package/dist/cjs/__fixtures__/content-type/index.js +1 -1
- package/dist/cjs/__fixtures__/entry/index.js +7 -7
- package/dist/cjs/__fixtures__/fixtures.js +6 -8
- package/dist/cjs/__fixtures__/locale/index.js +2 -2
- package/dist/cjs/__fixtures__/space/index.js +1 -1
- package/dist/cjs/assets/MultipleMediaEditor.js +5 -7
- package/dist/cjs/assets/SingleMediaEditor.js +4 -6
- package/dist/cjs/assets/WrappedAssetCard/AssetCardActions.js +19 -21
- package/dist/cjs/assets/WrappedAssetCard/FetchingWrappedAssetCard.js +11 -18
- package/dist/cjs/assets/WrappedAssetCard/WrappedAssetCard.js +11 -20
- package/dist/cjs/assets/WrappedAssetCard/WrappedAssetLink.js +9 -12
- package/dist/cjs/assets/index.js +3 -3
- package/dist/cjs/common/EntityStore.js +32 -51
- package/dist/cjs/common/MultipleReferenceEditor.js +11 -20
- package/dist/cjs/common/ReferenceEditor.js +5 -7
- package/dist/cjs/common/SingleReferenceEditor.js +7 -11
- package/dist/cjs/common/SortableLinkList.js +14 -14
- package/dist/cjs/common/customCardTypes.js +2 -4
- package/dist/cjs/common/queryClient.js +9 -14
- package/dist/cjs/common/useContentTypePermissions.js +1 -3
- package/dist/cjs/common/useEditorPermissions.js +3 -15
- package/dist/cjs/common/useEditorPermissions.spec.js +11 -12
- package/dist/cjs/components/AssetThumbnail/AssetThumbnail.js +3 -5
- package/dist/cjs/components/CreateEntryLinkButton/CreateEntryLinkButton.js +9 -13
- package/dist/cjs/components/CreateEntryLinkButton/CreateEntryLinkButton.spec.js +15 -17
- package/dist/cjs/components/CreateEntryLinkButton/CreateEntryMenuTrigger.js +19 -29
- package/dist/cjs/components/CreateEntryLinkButton/CreateEntryMenuTrigger.spec.js +12 -14
- package/dist/cjs/components/LinkActions/CombinedLinkActions.js +21 -28
- package/dist/cjs/components/LinkActions/LinkActions.js +15 -17
- package/dist/cjs/components/LinkActions/LinkEntityActions.js +17 -26
- package/dist/cjs/components/LinkActions/NoLinkPermissionsInfo.js +3 -5
- package/dist/cjs/components/LinkActions/helpers.js +5 -14
- package/dist/cjs/components/LinkActions/redesignStyles.js +4 -4
- package/dist/cjs/components/LinkActions/styles.js +1 -1
- package/dist/cjs/components/MissingEntityCard/MissingEntityCard.js +9 -11
- package/dist/cjs/components/ResourceEntityErrorCard/ResourceEntityErrorCard.js +4 -6
- package/dist/cjs/components/ResourceEntityErrorCard/UnsupportedEntityCard.js +4 -6
- package/dist/cjs/components/ScheduledIconWithTooltip/ScheduleTooltip.js +8 -10
- package/dist/cjs/components/ScheduledIconWithTooltip/ScheduledIconWithTooltip.js +4 -9
- package/dist/cjs/components/ScheduledIconWithTooltip/formatDateAndTime.js +4 -5
- package/dist/cjs/components/SpaceName/SpaceName.js +7 -9
- package/dist/cjs/components/index.js +12 -12
- package/dist/cjs/entries/MultipleEntryReferenceEditor.js +7 -9
- package/dist/cjs/entries/SingleEntryReferenceEditor.js +5 -7
- package/dist/cjs/entries/WrappedEntryCard/FetchingWrappedEntryCard.js +11 -20
- package/dist/cjs/entries/WrappedEntryCard/WrappedEntryCard.js +17 -23
- package/dist/cjs/entries/index.js +3 -3
- package/dist/cjs/index.js +37 -37
- package/dist/cjs/resources/Cards/ContentfulEntryCard.js +4 -13
- package/dist/cjs/resources/Cards/ResourceCard.js +12 -16
- package/dist/cjs/resources/Cards/ResourceCard.spec.js +17 -20
- package/dist/cjs/resources/MultipleResourceReferenceEditor.js +17 -20
- package/dist/cjs/resources/MultipleResourceReferenceEditor.spec.js +13 -34
- package/dist/cjs/resources/SingleResourceReferenceEditor.js +9 -11
- package/dist/cjs/resources/SingleResourceReferenceEditor.spec.js +6 -13
- package/dist/cjs/resources/testHelpers/resourceEditorHelpers.js +5 -12
- package/dist/cjs/resources/useResourceLinkActions.js +2 -11
- package/dist/cjs/types.js +3 -3
- package/dist/cjs/utils/fromFieldValidations.js +1 -2
- package/dist/cjs/utils/useSortIDs.js +4 -6
- package/dist/esm/__fixtures__/FakeSdk.js +3 -3
- package/dist/esm/assets/MultipleMediaEditor.js +3 -3
- package/dist/esm/assets/SingleMediaEditor.js +2 -2
- package/dist/esm/assets/WrappedAssetCard/AssetCardActions.js +12 -12
- package/dist/esm/assets/WrappedAssetCard/FetchingWrappedAssetCard.js +9 -14
- package/dist/esm/assets/WrappedAssetCard/WrappedAssetCard.js +7 -15
- package/dist/esm/assets/WrappedAssetCard/WrappedAssetLink.js +6 -7
- package/dist/esm/common/EntityStore.js +22 -39
- package/dist/esm/common/MultipleReferenceEditor.js +9 -16
- package/dist/esm/common/ReferenceEditor.js +2 -2
- package/dist/esm/common/SingleReferenceEditor.js +5 -7
- package/dist/esm/common/SortableLinkList.js +12 -12
- package/dist/esm/common/queryClient.js +3 -10
- package/dist/esm/common/useContentTypePermissions.js +1 -3
- package/dist/esm/common/useEditorPermissions.js +3 -15
- package/dist/esm/common/useEditorPermissions.spec.js +11 -12
- package/dist/esm/components/AssetThumbnail/AssetThumbnail.js +1 -1
- package/dist/esm/components/CreateEntryLinkButton/CreateEntryLinkButton.js +5 -7
- package/dist/esm/components/CreateEntryLinkButton/CreateEntryLinkButton.spec.js +12 -12
- package/dist/esm/components/CreateEntryLinkButton/CreateEntryMenuTrigger.js +15 -23
- package/dist/esm/components/CreateEntryLinkButton/CreateEntryMenuTrigger.spec.js +8 -9
- package/dist/esm/components/LinkActions/CombinedLinkActions.js +19 -30
- package/dist/esm/components/LinkActions/LinkActions.js +9 -9
- package/dist/esm/components/LinkActions/LinkEntityActions.js +11 -18
- package/dist/esm/components/LinkActions/NoLinkPermissionsInfo.js +1 -1
- package/dist/esm/components/LinkActions/helpers.js +2 -11
- package/dist/esm/components/MissingEntityCard/MissingEntityCard.js +6 -6
- package/dist/esm/components/ResourceEntityErrorCard/ResourceEntityErrorCard.js +2 -2
- package/dist/esm/components/ResourceEntityErrorCard/UnsupportedEntityCard.js +2 -2
- package/dist/esm/components/ScheduledIconWithTooltip/ScheduleTooltip.js +3 -3
- package/dist/esm/components/ScheduledIconWithTooltip/ScheduledIconWithTooltip.js +2 -5
- package/dist/esm/components/ScheduledIconWithTooltip/formatDateAndTime.js +2 -11
- package/dist/esm/components/SpaceName/SpaceName.js +4 -4
- package/dist/esm/entries/MultipleEntryReferenceEditor.js +5 -5
- package/dist/esm/entries/SingleEntryReferenceEditor.js +3 -3
- package/dist/esm/entries/WrappedEntryCard/FetchingWrappedEntryCard.js +8 -15
- package/dist/esm/entries/WrappedEntryCard/WrappedEntryCard.js +14 -18
- package/dist/esm/resources/Cards/ContentfulEntryCard.js +2 -9
- package/dist/esm/resources/Cards/ResourceCard.js +10 -12
- package/dist/esm/resources/Cards/ResourceCard.spec.js +11 -12
- package/dist/esm/resources/MultipleResourceReferenceEditor.js +13 -14
- package/dist/esm/resources/MultipleResourceReferenceEditor.spec.js +11 -30
- package/dist/esm/resources/SingleResourceReferenceEditor.js +6 -6
- package/dist/esm/resources/SingleResourceReferenceEditor.spec.js +4 -9
- package/dist/esm/resources/testHelpers/resourceEditorHelpers.js +2 -9
- package/dist/esm/resources/useResourceLinkActions.js +2 -11
- package/dist/esm/utils/fromFieldValidations.js +0 -1
- package/dist/esm/utils/useSortIDs.js +2 -2
- package/dist/types/assets/MultipleMediaEditor.d.ts +2 -2
- package/dist/types/assets/SingleMediaEditor.d.ts +2 -2
- package/dist/types/assets/WrappedAssetCard/AssetCardActions.d.ts +3 -3
- package/dist/types/assets/WrappedAssetCard/FetchingWrappedAssetCard.d.ts +2 -2
- package/dist/types/assets/WrappedAssetCard/WrappedAssetCard.d.ts +2 -2
- package/dist/types/assets/WrappedAssetCard/WrappedAssetLink.d.ts +2 -2
- package/dist/types/common/EntityStore.d.ts +1 -1
- package/dist/types/common/MultipleReferenceEditor.d.ts +1 -1
- package/dist/types/common/ReferenceEditor.d.ts +1 -1
- package/dist/types/common/SingleReferenceEditor.d.ts +1 -1
- package/dist/types/common/SortableLinkList.d.ts +1 -1
- package/dist/types/common/queryClient.d.ts +1 -1
- package/dist/types/components/AssetThumbnail/AssetThumbnail.d.ts +2 -2
- package/dist/types/components/CreateEntryLinkButton/CreateEntryLinkButton.d.ts +1 -1
- package/dist/types/components/CreateEntryLinkButton/CreateEntryMenuTrigger.d.ts +1 -1
- package/dist/types/components/LinkActions/CombinedLinkActions.d.ts +2 -2
- package/dist/types/components/LinkActions/LinkActions.d.ts +1 -1
- package/dist/types/components/LinkActions/LinkEntityActions.d.ts +2 -2
- package/dist/types/components/LinkActions/NoLinkPermissionsInfo.d.ts +2 -2
- package/dist/types/components/MissingEntityCard/MissingEntityCard.d.ts +2 -2
- package/dist/types/components/ResourceEntityErrorCard/ResourceEntityErrorCard.d.ts +2 -2
- package/dist/types/components/ResourceEntityErrorCard/UnsupportedEntityCard.d.ts +2 -2
- package/dist/types/components/ScheduledIconWithTooltip/ScheduleTooltip.d.ts +1 -1
- package/dist/types/components/ScheduledIconWithTooltip/ScheduledIconWithTooltip.d.ts +1 -1
- package/dist/types/components/SpaceName/SpaceName.d.ts +2 -2
- package/dist/types/entries/MultipleEntryReferenceEditor.d.ts +2 -2
- package/dist/types/entries/SingleEntryReferenceEditor.d.ts +2 -2
- package/dist/types/entries/WrappedEntryCard/FetchingWrappedEntryCard.d.ts +2 -2
- package/dist/types/entries/WrappedEntryCard/WrappedEntryCard.d.ts +1 -1
- package/dist/types/resources/Cards/ContentfulEntryCard.d.ts +2 -2
- package/dist/types/resources/Cards/ResourceCard.d.ts +2 -2
- package/dist/types/resources/MultipleResourceReferenceEditor.d.ts +2 -2
- package/dist/types/resources/SingleResourceReferenceEditor.d.ts +2 -2
- package/package.json +7 -4
|
@@ -9,11 +9,11 @@ function _export(target, all) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
createFakeEntryResource: function() {
|
|
13
|
-
return createFakeEntryResource;
|
|
14
|
-
},
|
|
15
12
|
mockSdkForField: function() {
|
|
16
13
|
return mockSdkForField;
|
|
14
|
+
},
|
|
15
|
+
createFakeEntryResource: function() {
|
|
16
|
+
return createFakeEntryResource;
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
19
|
function mockSdkForField(fieldDefinition, fieldValue) {
|
|
@@ -22,17 +22,13 @@ function mockSdkForField(fieldDefinition, fieldValue) {
|
|
|
22
22
|
getValue: jest.fn(()=>fieldValue),
|
|
23
23
|
setValue: jest.fn(()=>Promise.resolve(undefined)),
|
|
24
24
|
removeValue: jest.fn(),
|
|
25
|
-
// eslint-disable-next-line -- test helper
|
|
26
25
|
onSchemaErrorsChanged: ()=>{},
|
|
27
|
-
// eslint-disable-next-line -- test helper
|
|
28
26
|
onIsDisabledChanged: ()=>{},
|
|
29
|
-
// eslint-disable-next-line -- test helper
|
|
30
27
|
onValueChanged: ()=>{},
|
|
31
28
|
...fieldDefinition,
|
|
32
29
|
locale: 'en'
|
|
33
30
|
},
|
|
34
31
|
dialogs: {
|
|
35
|
-
// @ts-expect-error wait app-sdk version update
|
|
36
32
|
selectSingleResourceEntry: jest.fn().mockResolvedValue({
|
|
37
33
|
sys: {
|
|
38
34
|
type: 'Entry',
|
|
@@ -72,18 +68,15 @@ function mockSdkForField(fieldDefinition, fieldValue) {
|
|
|
72
68
|
contentType: 'testCT'
|
|
73
69
|
},
|
|
74
70
|
space: {
|
|
75
|
-
// @ts-expect-error wait app-sdk version update
|
|
76
|
-
// eslint-disable-next-line -- test helper
|
|
77
71
|
onEntityChanged: ()=>{}
|
|
78
72
|
},
|
|
79
|
-
// @ts-expect-error
|
|
80
73
|
navigator: {
|
|
81
74
|
onSlideInNavigation: ()=>()=>({})
|
|
82
75
|
}
|
|
83
76
|
};
|
|
84
77
|
}
|
|
85
|
-
const createFakeEntryResource = ({ title, id, space
|
|
86
|
-
const { id: spaceId, name: spaceName
|
|
78
|
+
const createFakeEntryResource = ({ title , id , space })=>{
|
|
79
|
+
const { id: spaceId , name: spaceName } = space;
|
|
87
80
|
return {
|
|
88
81
|
resource: {
|
|
89
82
|
sys: {
|
|
@@ -29,7 +29,7 @@ const getUpdatedValue = (field, entries, apiUrl)=>{
|
|
|
29
29
|
return toLinkItem(entries[0], apiUrl);
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
|
-
function useResourceLinkActions({ dialogs, field, onAfterLink, apiUrl
|
|
32
|
+
function useResourceLinkActions({ dialogs , field , onAfterLink , apiUrl }) {
|
|
33
33
|
const handleAfterLink = (0, _react.useCallback)((entries)=>{
|
|
34
34
|
if (!onAfterLink) {
|
|
35
35
|
return;
|
|
@@ -51,14 +51,10 @@ function useResourceLinkActions({ dialogs, field, onAfterLink, apiUrl }) {
|
|
|
51
51
|
]);
|
|
52
52
|
const multiple = field.type === 'Array';
|
|
53
53
|
const onLinkExisting = (0, _react.useMemo)(()=>{
|
|
54
|
-
const promptSelection = multiple ? async ()
|
|
55
|
-
await dialogs.selectMultipleResourceEntries({
|
|
56
|
-
// @ts-expect-error wait for update of app-sdk version
|
|
54
|
+
const promptSelection = multiple ? async ()=>await dialogs.selectMultipleResourceEntries({
|
|
57
55
|
allowedResources: field.allowedResources
|
|
58
56
|
}) : async ()=>[
|
|
59
|
-
// @ts-expect-error wait for update of app-sdk version
|
|
60
57
|
await dialogs.selectSingleResourceEntry({
|
|
61
|
-
// @ts-expect-error wait for update of app-sdk version
|
|
62
58
|
allowedResources: field.allowedResources
|
|
63
59
|
})
|
|
64
60
|
];
|
|
@@ -69,7 +65,6 @@ function useResourceLinkActions({ dialogs, field, onAfterLink, apiUrl }) {
|
|
|
69
65
|
}
|
|
70
66
|
onLinkedExisting(res);
|
|
71
67
|
};
|
|
72
|
-
// @ts-expect-error wait for update of app-sdk version
|
|
73
68
|
}, [
|
|
74
69
|
dialogs,
|
|
75
70
|
field.allowedResources,
|
|
@@ -78,9 +73,7 @@ function useResourceLinkActions({ dialogs, field, onAfterLink, apiUrl }) {
|
|
|
78
73
|
]);
|
|
79
74
|
return {
|
|
80
75
|
onLinkExisting,
|
|
81
|
-
// @ts-expect-error
|
|
82
76
|
onLinkedExisting,
|
|
83
|
-
// hardcoded values to match interface for standard reference field actions
|
|
84
77
|
entityType: 'Entry',
|
|
85
78
|
contentTypes: [],
|
|
86
79
|
canCreateEntity: false,
|
|
@@ -89,9 +82,7 @@ function useResourceLinkActions({ dialogs, field, onAfterLink, apiUrl }) {
|
|
|
89
82
|
isDisabled: false,
|
|
90
83
|
isEmpty: false,
|
|
91
84
|
isFull: false,
|
|
92
|
-
// eslint-disable-next-line -- hardcoded values to match interface for standard reference field actions
|
|
93
85
|
onCreate: async ()=>{},
|
|
94
|
-
// eslint-disable-next-line -- hardcoded values to match interface for standard reference field actions
|
|
95
86
|
onCreated: ()=>{}
|
|
96
87
|
};
|
|
97
88
|
}
|
package/dist/cjs/types.js
CHANGED
|
@@ -9,14 +9,14 @@ function _export(target, all) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
Asset: function() {
|
|
13
|
-
return _fieldeditorshared.Asset;
|
|
14
|
-
},
|
|
15
12
|
Entry: function() {
|
|
16
13
|
return _fieldeditorshared.Entry;
|
|
17
14
|
},
|
|
18
15
|
File: function() {
|
|
19
16
|
return _fieldeditorshared.File;
|
|
17
|
+
},
|
|
18
|
+
Asset: function() {
|
|
19
|
+
return _fieldeditorshared.Asset;
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
22
|
const _fieldeditorshared = require("@contentful/field-editor-shared");
|
|
@@ -8,14 +8,13 @@ Object.defineProperty(exports, "fromFieldValidations", {
|
|
|
8
8
|
return fromFieldValidations;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const _isNumber =
|
|
11
|
+
const _isNumber = _interop_require_default(require("lodash/isNumber"));
|
|
12
12
|
function _interop_require_default(obj) {
|
|
13
13
|
return obj && obj.__esModule ? obj : {
|
|
14
14
|
default: obj
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
17
|
function fromFieldValidations(field) {
|
|
18
|
-
// eslint-disable-next-line -- TODO: describe this disable @typescript-eslint/no-explicit-any
|
|
19
18
|
const validations = [
|
|
20
19
|
...field.validations,
|
|
21
20
|
...field.type === 'Array' ? field.items?.validations ?? [] : []
|
|
@@ -8,7 +8,7 @@ Object.defineProperty(exports, "useSortIDs", {
|
|
|
8
8
|
return useSortIDs;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const _react =
|
|
11
|
+
const _react = _interop_require_wildcard(require("react"));
|
|
12
12
|
const _sortable = require("@dnd-kit/sortable");
|
|
13
13
|
function _getRequireWildcardCache(nodeInterop) {
|
|
14
14
|
if (typeof WeakMap !== "function") return null;
|
|
@@ -31,9 +31,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
31
31
|
if (cache && cache.has(obj)) {
|
|
32
32
|
return cache.get(obj);
|
|
33
33
|
}
|
|
34
|
-
var newObj = {
|
|
35
|
-
__proto__: null
|
|
36
|
-
};
|
|
34
|
+
var newObj = {};
|
|
37
35
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
38
36
|
for(var key in obj){
|
|
39
37
|
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
@@ -53,7 +51,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
53
51
|
}
|
|
54
52
|
const useSortIDs = (items)=>{
|
|
55
53
|
const ids = (items || []).map((item, index)=>{
|
|
56
|
-
const { type
|
|
54
|
+
const { type } = item.sys;
|
|
57
55
|
return {
|
|
58
56
|
id: type === 'ResourceLink' ? `${item.sys.urn}-${index}` : `${item.sys.id}-${index}`
|
|
59
57
|
};
|
|
@@ -62,7 +60,7 @@ const useSortIDs = (items)=>{
|
|
|
62
60
|
_react.default.useEffect(()=>{
|
|
63
61
|
if (items.length !== sortIDs.length) {
|
|
64
62
|
const ids = items.map((item, index)=>{
|
|
65
|
-
const { type
|
|
63
|
+
const { type } = item.sys;
|
|
66
64
|
return {
|
|
67
65
|
id: type === 'ResourceLink' ? `${item.sys.urn}-${index}` : `${item.sys.id}-${index}`
|
|
68
66
|
};
|
|
@@ -49,7 +49,7 @@ export function newReferenceEditorFakeSdk(props) {
|
|
|
49
49
|
locales,
|
|
50
50
|
cmaAdapter: createFakeCMAAdapter({
|
|
51
51
|
Entry: {
|
|
52
|
-
get: async ({ entryId
|
|
52
|
+
get: async ({ entryId })=>{
|
|
53
53
|
if (props?.fetchDelay) {
|
|
54
54
|
await delay(props.fetchDelay);
|
|
55
55
|
}
|
|
@@ -66,7 +66,7 @@ export function newReferenceEditorFakeSdk(props) {
|
|
|
66
66
|
}
|
|
67
67
|
},
|
|
68
68
|
Asset: {
|
|
69
|
-
get: async ({ assetId
|
|
69
|
+
get: async ({ assetId })=>{
|
|
70
70
|
if (props?.fetchDelay) {
|
|
71
71
|
await delay(props.fetchDelay);
|
|
72
72
|
}
|
|
@@ -91,7 +91,7 @@ export function newReferenceEditorFakeSdk(props) {
|
|
|
91
91
|
}
|
|
92
92
|
},
|
|
93
93
|
ContentType: {
|
|
94
|
-
get: async ({ contentTypeId
|
|
94
|
+
get: async ({ contentTypeId })=>{
|
|
95
95
|
if (contentTypeId === contentTypes.published.sys.id) {
|
|
96
96
|
return contentTypes.published;
|
|
97
97
|
}
|
|
@@ -12,16 +12,16 @@ const styles = {
|
|
|
12
12
|
})
|
|
13
13
|
};
|
|
14
14
|
export function MultipleMediaEditor(props) {
|
|
15
|
-
return
|
|
15
|
+
return React.createElement(MultipleReferenceEditor, {
|
|
16
16
|
...props,
|
|
17
17
|
entityType: "Asset"
|
|
18
|
-
}, (childrenProps)
|
|
18
|
+
}, (childrenProps)=>React.createElement(SortableLinkList, {
|
|
19
19
|
...childrenProps,
|
|
20
20
|
sortingStrategy: childrenProps.viewType === 'card' ? rectSortingStrategy : verticalListSortingStrategy,
|
|
21
21
|
className: cx({
|
|
22
22
|
[styles.gridContainer]: childrenProps.viewType === 'card'
|
|
23
23
|
})
|
|
24
|
-
}, ({ items, item, index, isDisabled, DragHandle
|
|
24
|
+
}, ({ items , item , index , isDisabled , DragHandle })=>React.createElement(FetchingWrappedAssetCard, {
|
|
25
25
|
...childrenProps,
|
|
26
26
|
isDisabled: isDisabled,
|
|
27
27
|
key: `${item.sys.id}-${index}`,
|
|
@@ -2,10 +2,10 @@ import * as React from 'react';
|
|
|
2
2
|
import { SingleReferenceEditor } from '../common/SingleReferenceEditor';
|
|
3
3
|
import { FetchingWrappedAssetCard } from './WrappedAssetCard/FetchingWrappedAssetCard';
|
|
4
4
|
export function SingleMediaEditor(props) {
|
|
5
|
-
return
|
|
5
|
+
return React.createElement(SingleReferenceEditor, {
|
|
6
6
|
...props,
|
|
7
7
|
entityType: "Asset"
|
|
8
|
-
}, ({ entityId, isDisabled, setValue
|
|
8
|
+
}, ({ entityId , isDisabled , setValue })=>React.createElement(FetchingWrappedAssetCard, {
|
|
9
9
|
...props,
|
|
10
10
|
viewType: "big_card",
|
|
11
11
|
assetId: entityId,
|
|
@@ -42,42 +42,42 @@ function downloadAsset(url) {
|
|
|
42
42
|
window.open(url, '_blank', 'noopener,noreferrer');
|
|
43
43
|
}
|
|
44
44
|
export function renderAssetInfo(props) {
|
|
45
|
-
const { entityFile
|
|
45
|
+
const { entityFile } = props;
|
|
46
46
|
const fileName = get(entityFile, 'fileName');
|
|
47
47
|
const mimeType = get(entityFile, 'contentType');
|
|
48
48
|
const fileSize = get(entityFile, 'details.size');
|
|
49
49
|
const image = get(entityFile, 'details.image');
|
|
50
50
|
return [
|
|
51
|
-
|
|
51
|
+
React.createElement(Menu.SectionTitle, {
|
|
52
52
|
key: "file-section"
|
|
53
53
|
}, "File info"),
|
|
54
|
-
|
|
54
|
+
React.createElement(Menu.Item, {
|
|
55
55
|
key: "file-information",
|
|
56
56
|
className: styles.fileInformation.menuItem,
|
|
57
57
|
isDisabled: true
|
|
58
|
-
},
|
|
58
|
+
}, React.createElement("dl", {
|
|
59
59
|
className: styles.fileInformation.dl
|
|
60
|
-
}, fileName &&
|
|
60
|
+
}, fileName && React.createElement(React.Fragment, null, React.createElement("dt", null, "File Name:"), React.createElement(Text, {
|
|
61
61
|
as: "dd",
|
|
62
62
|
isTruncated: true
|
|
63
|
-
}, fileName)), mimeType &&
|
|
63
|
+
}, fileName)), mimeType && React.createElement(React.Fragment, null, React.createElement("dt", null, "File Type:"), React.createElement(Text, {
|
|
64
64
|
as: "dd",
|
|
65
65
|
isTruncated: true
|
|
66
|
-
}, mimeType)), fileSize &&
|
|
66
|
+
}, mimeType)), fileSize && React.createElement(React.Fragment, null, React.createElement("dt", null, "Size:"), React.createElement("dd", null, shortenStorageUnit(fileSize, 'B'))), image && React.createElement(React.Fragment, null, React.createElement("dt", null, "Dimensions:"), React.createElement("dd", null, `${image.width} × ${image.height}`))))
|
|
67
67
|
];
|
|
68
68
|
}
|
|
69
69
|
export function renderActions(props) {
|
|
70
|
-
const { entityFile, isDisabled, onEdit, onRemove
|
|
70
|
+
const { entityFile , isDisabled , onEdit , onRemove } = props;
|
|
71
71
|
return [
|
|
72
|
-
|
|
72
|
+
React.createElement(Menu.SectionTitle, {
|
|
73
73
|
key: "section-title"
|
|
74
74
|
}, "Actions"),
|
|
75
|
-
onEdit ?
|
|
75
|
+
onEdit ? React.createElement(Menu.Item, {
|
|
76
76
|
key: "edit",
|
|
77
77
|
onClick: onEdit,
|
|
78
78
|
testId: "card-action-edit"
|
|
79
79
|
}, "Edit") : null,
|
|
80
|
-
entityFile ?
|
|
80
|
+
entityFile ? React.createElement(Menu.Item, {
|
|
81
81
|
key: "download",
|
|
82
82
|
onClick: ()=>{
|
|
83
83
|
if (typeof entityFile.url === 'string') {
|
|
@@ -86,7 +86,7 @@ export function renderActions(props) {
|
|
|
86
86
|
},
|
|
87
87
|
testId: "card-action-download"
|
|
88
88
|
}, "Download") : null,
|
|
89
|
-
onRemove ?
|
|
89
|
+
onRemove ? React.createElement(Menu.Item, {
|
|
90
90
|
key: "remove",
|
|
91
91
|
disabled: isDisabled,
|
|
92
92
|
onClick: onRemove,
|
|
@@ -5,8 +5,8 @@ import { MissingEntityCard } from '../../components';
|
|
|
5
5
|
import { WrappedAssetCard } from './WrappedAssetCard';
|
|
6
6
|
import { WrappedAssetLink } from './WrappedAssetLink';
|
|
7
7
|
export function FetchingWrappedAssetCard(props) {
|
|
8
|
-
const { data: asset, status
|
|
9
|
-
const { getEntityScheduledActions
|
|
8
|
+
const { data: asset , status } = useEntity('Asset', props.assetId);
|
|
9
|
+
const { getEntityScheduledActions } = useEntityLoader();
|
|
10
10
|
const loadEntityScheduledActions = React.useCallback(()=>getEntityScheduledActions('Asset', props.assetId), [
|
|
11
11
|
getEntityScheduledActions,
|
|
12
12
|
props.assetId
|
|
@@ -18,12 +18,11 @@ export function FetchingWrappedAssetCard(props) {
|
|
|
18
18
|
entity: 'Asset'
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
|
|
22
21
|
}, [
|
|
23
22
|
asset
|
|
24
23
|
]);
|
|
25
24
|
const onEdit = async ()=>{
|
|
26
|
-
const { slide
|
|
25
|
+
const { slide } = await props.sdk.navigator.openAsset(props.assetId, {
|
|
27
26
|
slideIn: true
|
|
28
27
|
});
|
|
29
28
|
props.onAction && props.onAction({
|
|
@@ -45,7 +44,7 @@ export function FetchingWrappedAssetCard(props) {
|
|
|
45
44
|
};
|
|
46
45
|
return React.useMemo(()=>{
|
|
47
46
|
if (status === 'error') {
|
|
48
|
-
const card =
|
|
47
|
+
const card = React.createElement(MissingEntityCard, {
|
|
49
48
|
entityType: "Asset",
|
|
50
49
|
asSquare: props.viewType !== 'link',
|
|
51
50
|
isDisabled: props.isDisabled,
|
|
@@ -62,7 +61,7 @@ export function FetchingWrappedAssetCard(props) {
|
|
|
62
61
|
}
|
|
63
62
|
return card;
|
|
64
63
|
}
|
|
65
|
-
const { getEntityUrl
|
|
64
|
+
const { getEntityUrl } = props;
|
|
66
65
|
const size = props.viewType === 'big_card' ? 'default' : 'small';
|
|
67
66
|
const commonProps = {
|
|
68
67
|
asset,
|
|
@@ -77,25 +76,24 @@ export function FetchingWrappedAssetCard(props) {
|
|
|
77
76
|
};
|
|
78
77
|
if (props.viewType === 'link') {
|
|
79
78
|
if (status === 'loading') {
|
|
80
|
-
return
|
|
79
|
+
return React.createElement(EntryCard, {
|
|
81
80
|
size: "small",
|
|
82
81
|
isLoading: true
|
|
83
82
|
});
|
|
84
83
|
}
|
|
85
|
-
return
|
|
84
|
+
return React.createElement(WrappedAssetLink, {
|
|
86
85
|
...commonProps,
|
|
87
86
|
href: commonProps.entityUrl,
|
|
88
87
|
getEntityScheduledActions: loadEntityScheduledActions
|
|
89
88
|
});
|
|
90
89
|
}
|
|
91
90
|
if (status === 'loading') {
|
|
92
|
-
return
|
|
91
|
+
return React.createElement(AssetCard, {
|
|
93
92
|
size: size,
|
|
94
93
|
isLoading: true
|
|
95
94
|
});
|
|
96
95
|
}
|
|
97
96
|
function renderDefaultCard(props) {
|
|
98
|
-
// isClickable has a default value, so omit it from the props
|
|
99
97
|
const builtinCardProps = {
|
|
100
98
|
...commonProps,
|
|
101
99
|
...props,
|
|
@@ -103,22 +101,19 @@ export function FetchingWrappedAssetCard(props) {
|
|
|
103
101
|
asset: (props?.entity) || commonProps.asset,
|
|
104
102
|
getAssetUrl: getEntityUrl
|
|
105
103
|
};
|
|
106
|
-
return
|
|
104
|
+
return React.createElement(WrappedAssetCard, builtinCardProps);
|
|
107
105
|
}
|
|
108
106
|
if (props.renderCustomCard) {
|
|
109
107
|
const customProps = {
|
|
110
108
|
...commonProps,
|
|
111
109
|
entity: commonProps.asset
|
|
112
110
|
};
|
|
113
|
-
// LinkActionsProps are injected higher SingleReferenceEditor/MultipleReferenceEditor
|
|
114
111
|
const renderedCustomCard = props.renderCustomCard(customProps, {}, renderDefaultCard);
|
|
115
|
-
// Only `false` indicates to render the original card. E.g. `null` would result in no card.
|
|
116
112
|
if (renderedCustomCard !== false) {
|
|
117
113
|
return renderedCustomCard;
|
|
118
114
|
}
|
|
119
115
|
}
|
|
120
116
|
return renderDefaultCard();
|
|
121
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps -- TODO: Evaluate the dependencies
|
|
122
117
|
}, [
|
|
123
118
|
props,
|
|
124
119
|
status,
|
|
@@ -3,7 +3,6 @@ import { AssetCard } from '@contentful/f36-components';
|
|
|
3
3
|
import { ClockIcon } from '@contentful/f36-icons';
|
|
4
4
|
import tokens from '@contentful/f36-tokens';
|
|
5
5
|
import { entityHelpers } from '@contentful/field-editor-shared';
|
|
6
|
-
// @ts-expect-error
|
|
7
6
|
import mimetype from '@contentful/mimetype';
|
|
8
7
|
import { css } from 'emotion';
|
|
9
8
|
import { MissingEntityCard, ScheduledIconWithTooltip } from '../../components';
|
|
@@ -29,7 +28,6 @@ const styles = {
|
|
|
29
28
|
const defaultProps = {
|
|
30
29
|
isClickable: true
|
|
31
30
|
};
|
|
32
|
-
// eslint-disable-next-line -- TODO: describe this disable @typescript-eslint/no-explicit-any
|
|
33
31
|
function getFileType(file) {
|
|
34
32
|
if (!file) {
|
|
35
33
|
return 'archive';
|
|
@@ -41,11 +39,10 @@ function getFileType(file) {
|
|
|
41
39
|
return groupToIconMap[groupName] || 'archive';
|
|
42
40
|
}
|
|
43
41
|
export const WrappedAssetCard = (props)=>{
|
|
44
|
-
const { className, onEdit, getAssetUrl, onRemove, size, isDisabled, isSelected, isClickable
|
|
45
|
-
// @ts-expect-error
|
|
42
|
+
const { className , onEdit , getAssetUrl , onRemove , size , isDisabled , isSelected , isClickable } = props;
|
|
46
43
|
const status = entityHelpers.getEntryStatus(props.asset.sys);
|
|
47
44
|
if (status === 'deleted') {
|
|
48
|
-
return
|
|
45
|
+
return React.createElement(MissingEntityCard, {
|
|
49
46
|
entityType: "Asset",
|
|
50
47
|
asSquare: true,
|
|
51
48
|
isDisabled: props.isDisabled,
|
|
@@ -60,7 +57,7 @@ export const WrappedAssetCard = (props)=>{
|
|
|
60
57
|
});
|
|
61
58
|
const entityFile = props.asset.fields.file ? props.asset.fields.file[props.localeCode] || props.asset.fields.file[props.defaultLocaleCode] : undefined;
|
|
62
59
|
const href = getAssetUrl ? getAssetUrl(props.asset.sys.id) : undefined;
|
|
63
|
-
return
|
|
60
|
+
return React.createElement(AssetCard, {
|
|
64
61
|
as: href ? 'a' : 'article',
|
|
65
62
|
type: getFileType(entityFile),
|
|
66
63
|
title: entityTitle,
|
|
@@ -68,27 +65,22 @@ export const WrappedAssetCard = (props)=>{
|
|
|
68
65
|
isSelected: isSelected,
|
|
69
66
|
href: href,
|
|
70
67
|
status: status,
|
|
71
|
-
icon:
|
|
68
|
+
icon: React.createElement(ScheduledIconWithTooltip, {
|
|
72
69
|
getEntityScheduledActions: props.getEntityScheduledActions,
|
|
73
70
|
entityType: "Asset",
|
|
74
71
|
entityId: props.asset.sys.id
|
|
75
|
-
},
|
|
72
|
+
}, React.createElement(ClockIcon, {
|
|
76
73
|
className: styles.scheduleIcon,
|
|
77
74
|
size: "small",
|
|
78
75
|
variant: "muted",
|
|
79
76
|
testId: "schedule-icon"
|
|
80
77
|
})),
|
|
81
78
|
src: entityFile && entityFile.url ? size === 'small' ? `${entityFile.url}?w=150&h=150&fit=thumb` : `${entityFile.url}?h=300` : '',
|
|
82
|
-
onClick:
|
|
83
|
-
// features e.g. pressing ENTER on a card to add a new paragraph
|
|
84
|
-
// underneath. It's crucial not to pass a custom handler when
|
|
85
|
-
// isClickable is disabled which in the case of RT it's.
|
|
86
|
-
isClickable ? (e)=>{
|
|
79
|
+
onClick: isClickable ? (e)=>{
|
|
87
80
|
e.preventDefault();
|
|
88
81
|
onEdit && onEdit();
|
|
89
82
|
} : undefined,
|
|
90
|
-
|
|
91
|
-
// @ts-expect-error */ onKeyDown: isClickable ? (e)=>{
|
|
83
|
+
onKeyDown: isClickable ? (e)=>{
|
|
92
84
|
if (e.key === 'Enter' && onEdit) {
|
|
93
85
|
e.preventDefault();
|
|
94
86
|
onEdit();
|
|
@@ -12,11 +12,10 @@ const styles = {
|
|
|
12
12
|
})
|
|
13
13
|
};
|
|
14
14
|
export const WrappedAssetLink = (props)=>{
|
|
15
|
-
const { className, href, onEdit, onRemove, isDisabled
|
|
16
|
-
// @ts-expect-error
|
|
15
|
+
const { className , href , onEdit , onRemove , isDisabled } = props;
|
|
17
16
|
const status = entityHelpers.getEntryStatus(props.asset.sys);
|
|
18
17
|
if (status === 'deleted') {
|
|
19
|
-
return
|
|
18
|
+
return React.createElement(MissingEntityCard, {
|
|
20
19
|
entityType: "Asset",
|
|
21
20
|
isDisabled: props.isDisabled,
|
|
22
21
|
onRemove: props.onRemove
|
|
@@ -29,7 +28,7 @@ export const WrappedAssetLink = (props)=>{
|
|
|
29
28
|
defaultTitle: 'Untitled'
|
|
30
29
|
});
|
|
31
30
|
const entityFile = props.asset.fields.file ? props.asset.fields.file[props.localeCode] || props.asset.fields.file[props.defaultLocaleCode] : undefined;
|
|
32
|
-
return
|
|
31
|
+
return React.createElement(EntryCard, {
|
|
33
32
|
as: href ? 'a' : 'article',
|
|
34
33
|
contentType: "Asset",
|
|
35
34
|
title: entityTitle,
|
|
@@ -37,14 +36,14 @@ export const WrappedAssetLink = (props)=>{
|
|
|
37
36
|
href: href,
|
|
38
37
|
size: "small",
|
|
39
38
|
status: status,
|
|
40
|
-
thumbnailElement: entityFile && isValidImage(entityFile) ?
|
|
39
|
+
thumbnailElement: entityFile && isValidImage(entityFile) ? React.createElement(AssetThumbnail, {
|
|
41
40
|
file: entityFile
|
|
42
41
|
}) : undefined,
|
|
43
|
-
icon:
|
|
42
|
+
icon: React.createElement(ScheduledIconWithTooltip, {
|
|
44
43
|
getEntityScheduledActions: props.getEntityScheduledActions,
|
|
45
44
|
entityType: "Asset",
|
|
46
45
|
entityId: props.asset.sys.id
|
|
47
|
-
},
|
|
46
|
+
}, React.createElement(ClockIcon, {
|
|
48
47
|
className: styles.scheduleIcon,
|
|
49
48
|
size: "small",
|
|
50
49
|
variant: "muted",
|