@contentful/field-editor-reference 5.8.6 → 5.10.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/cjs/__fixtures__/FakeSdk.js +183 -0
- package/dist/cjs/__fixtures__/asset/index.js +37 -0
- package/dist/cjs/__fixtures__/content-type/index.js +16 -0
- package/dist/cjs/__fixtures__/entry/index.js +33 -0
- package/dist/cjs/__fixtures__/fixtures.js +71 -0
- package/dist/cjs/__fixtures__/locale/index.js +40 -0
- package/dist/cjs/__fixtures__/space/index.js +16 -0
- package/dist/cjs/assets/MultipleMediaEditor.js +86 -0
- package/dist/cjs/assets/SingleMediaEditor.js +69 -0
- package/dist/cjs/assets/WrappedAssetCard/AssetCardActions.js +125 -0
- package/dist/cjs/assets/WrappedAssetCard/FetchingWrappedAssetCard.js +171 -0
- package/dist/cjs/assets/WrappedAssetCard/WrappedAssetCard.js +159 -0
- package/dist/cjs/assets/WrappedAssetCard/WrappedAssetLink.js +130 -0
- package/dist/cjs/assets/index.js +24 -0
- package/dist/cjs/common/EntityStore.js +420 -0
- package/dist/cjs/common/MultipleReferenceEditor.js +164 -0
- package/dist/cjs/common/ReferenceEditor.js +74 -0
- package/dist/cjs/common/SingleReferenceEditor.js +118 -0
- package/dist/cjs/common/SortableLinkList.js +95 -0
- package/dist/cjs/common/customCardTypes.js +44 -0
- package/dist/cjs/common/useAccessApi.js +19 -0
- package/dist/cjs/common/useContentTypePermissions.js +54 -0
- package/dist/cjs/common/useEditorPermissions.js +77 -0
- package/dist/cjs/common/useEditorPermissions.spec.js +205 -0
- package/dist/cjs/components/AssetThumbnail/AssetThumbnail.js +62 -0
- package/dist/cjs/components/CreateEntryLinkButton/CreateEntryLinkButton.js +102 -0
- package/dist/cjs/components/CreateEntryLinkButton/CreateEntryLinkButton.spec.js +254 -0
- package/dist/cjs/components/CreateEntryLinkButton/CreateEntryMenuTrigger.js +199 -0
- package/dist/cjs/components/CreateEntryLinkButton/CreateEntryMenuTrigger.spec.js +190 -0
- package/dist/cjs/components/CreateEntryLinkButton/useGlobalMouseUp.js +19 -0
- package/dist/cjs/components/LinkActions/CombinedLinkActions.js +167 -0
- package/dist/cjs/components/LinkActions/LinkActions.js +123 -0
- package/dist/cjs/components/LinkActions/LinkEntityActions.js +186 -0
- package/dist/cjs/components/LinkActions/NoLinkPermissionsInfo.js +54 -0
- package/dist/cjs/components/LinkActions/helpers.js +78 -0
- package/dist/cjs/components/LinkActions/redesignStyles.js +44 -0
- package/dist/cjs/components/LinkActions/styles.js +33 -0
- package/dist/cjs/components/MissingEntityCard/MissingEntityCard.js +75 -0
- package/dist/cjs/components/MissingEntityCard/styles.js +29 -0
- package/dist/cjs/components/ScheduledIconWithTooltip/ScheduleTooltip.js +75 -0
- package/dist/cjs/components/ScheduledIconWithTooltip/ScheduledIconWithTooltip.js +81 -0
- package/dist/cjs/components/ScheduledIconWithTooltip/formatDateAndTime.js +45 -0
- package/dist/cjs/components/SpaceName/SpaceName.js +91 -0
- package/dist/cjs/components/index.js +44 -0
- package/dist/cjs/entries/MultipleEntryReferenceEditor.js +86 -0
- package/dist/cjs/entries/SingleEntryReferenceEditor.js +74 -0
- package/dist/cjs/entries/WrappedEntryCard/FetchingWrappedEntryCard.js +189 -0
- package/dist/cjs/entries/WrappedEntryCard/WrappedEntryCard.js +181 -0
- package/dist/cjs/entries/index.js +24 -0
- package/dist/cjs/index.js +92 -0
- package/dist/cjs/resources/Cards/ContentfulEntryCard.js +87 -0
- package/dist/cjs/resources/Cards/ResourceCard.js +111 -0
- package/dist/cjs/resources/Cards/UnsupportedEntityCard.js +64 -0
- package/dist/cjs/resources/MultipleResourceReferenceEditor.js +157 -0
- package/dist/cjs/resources/MultipleResourceReferenceEditor.spec.js +297 -0
- package/dist/cjs/resources/SingleResourceReferenceEditor.js +87 -0
- package/dist/cjs/resources/SingleResourceReferenceEditor.spec.js +161 -0
- package/dist/cjs/resources/index.js +19 -0
- package/dist/cjs/resources/testHelpers/resourceEditorHelpers.js +121 -0
- package/dist/cjs/resources/useResourceLinkActions.js +88 -0
- package/dist/cjs/types.js +22 -0
- package/dist/cjs/utils/fromFieldValidations.js +54 -0
- package/dist/esm/__fixtures__/FakeSdk.js +173 -0
- package/dist/esm/__fixtures__/asset/index.js +6 -0
- package/dist/esm/__fixtures__/content-type/index.js +2 -0
- package/dist/esm/__fixtures__/entry/index.js +5 -0
- package/dist/esm/__fixtures__/fixtures.js +6 -0
- package/dist/esm/__fixtures__/locale/index.js +15 -0
- package/dist/esm/__fixtures__/space/index.js +2 -0
- package/dist/esm/assets/MultipleMediaEditor.js +37 -0
- package/dist/esm/assets/SingleMediaEditor.js +20 -0
- package/dist/esm/assets/WrappedAssetCard/AssetCardActions.js +63 -0
- package/dist/esm/assets/WrappedAssetCard/FetchingWrappedAssetCard.js +122 -0
- package/dist/esm/assets/WrappedAssetCard/WrappedAssetCard.js +105 -0
- package/dist/esm/assets/WrappedAssetCard/WrappedAssetLink.js +76 -0
- package/dist/esm/assets/index.js +3 -0
- package/dist/esm/common/EntityStore.js +347 -0
- package/dist/esm/common/MultipleReferenceEditor.js +111 -0
- package/dist/esm/common/ReferenceEditor.js +20 -0
- package/dist/esm/common/SingleReferenceEditor.js +70 -0
- package/dist/esm/common/SortableLinkList.js +41 -0
- package/dist/esm/common/customCardTypes.js +1 -0
- package/dist/esm/common/useAccessApi.js +9 -0
- package/dist/esm/common/useContentTypePermissions.js +44 -0
- package/dist/esm/common/useEditorPermissions.js +67 -0
- package/dist/esm/common/useEditorPermissions.spec.js +201 -0
- package/dist/esm/components/AssetThumbnail/AssetThumbnail.js +13 -0
- package/dist/esm/components/CreateEntryLinkButton/CreateEntryLinkButton.js +48 -0
- package/dist/esm/components/CreateEntryLinkButton/CreateEntryLinkButton.spec.js +206 -0
- package/dist/esm/components/CreateEntryLinkButton/CreateEntryMenuTrigger.js +145 -0
- package/dist/esm/components/CreateEntryLinkButton/CreateEntryMenuTrigger.spec.js +142 -0
- package/dist/esm/components/CreateEntryLinkButton/useGlobalMouseUp.js +9 -0
- package/dist/esm/components/LinkActions/CombinedLinkActions.js +118 -0
- package/dist/esm/components/LinkActions/LinkActions.js +66 -0
- package/dist/esm/components/LinkActions/LinkEntityActions.js +127 -0
- package/dist/esm/components/LinkActions/NoLinkPermissionsInfo.js +5 -0
- package/dist/esm/components/LinkActions/helpers.js +57 -0
- package/dist/esm/components/LinkActions/redesignStyles.js +18 -0
- package/dist/esm/components/LinkActions/styles.js +10 -0
- package/dist/esm/components/MissingEntityCard/MissingEntityCard.js +26 -0
- package/dist/esm/components/MissingEntityCard/styles.js +11 -0
- package/dist/esm/components/ScheduledIconWithTooltip/ScheduleTooltip.js +18 -0
- package/dist/esm/components/ScheduledIconWithTooltip/ScheduledIconWithTooltip.js +32 -0
- package/dist/esm/components/ScheduledIconWithTooltip/formatDateAndTime.js +19 -0
- package/dist/esm/components/SpaceName/SpaceName.js +37 -0
- package/dist/esm/components/index.js +8 -0
- package/dist/esm/entries/MultipleEntryReferenceEditor.js +37 -0
- package/dist/esm/entries/SingleEntryReferenceEditor.js +25 -0
- package/dist/esm/entries/WrappedEntryCard/FetchingWrappedEntryCard.js +135 -0
- package/dist/esm/entries/WrappedEntryCard/WrappedEntryCard.js +127 -0
- package/dist/esm/entries/index.js +3 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/resources/Cards/ContentfulEntryCard.js +38 -0
- package/dist/esm/resources/Cards/ResourceCard.js +62 -0
- package/dist/esm/resources/Cards/UnsupportedEntityCard.js +15 -0
- package/dist/esm/resources/MultipleResourceReferenceEditor.js +104 -0
- package/dist/esm/resources/MultipleResourceReferenceEditor.spec.js +254 -0
- package/dist/esm/resources/SingleResourceReferenceEditor.js +33 -0
- package/dist/esm/resources/SingleResourceReferenceEditor.spec.js +118 -0
- package/dist/esm/resources/index.js +2 -0
- package/dist/esm/resources/testHelpers/resourceEditorHelpers.js +103 -0
- package/dist/esm/resources/useResourceLinkActions.js +78 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/utils/fromFieldValidations.js +39 -0
- package/dist/{__fixtures__ → types/__fixtures__}/FakeSdk.d.ts +8 -8
- package/dist/{__fixtures__ → types/__fixtures__}/asset/index.d.ts +6 -6
- package/dist/{__fixtures__ → types/__fixtures__}/content-type/index.d.ts +2 -2
- package/dist/{__fixtures__ → types/__fixtures__}/entry/index.d.ts +5 -5
- package/dist/{__fixtures__ → types/__fixtures__}/fixtures.d.ts +6 -6
- package/dist/{__fixtures__ → types/__fixtures__}/locale/index.d.ts +42 -42
- package/dist/{__fixtures__ → types/__fixtures__}/space/index.d.ts +2 -2
- package/dist/{assets → types/assets}/MultipleMediaEditor.d.ts +10 -10
- package/dist/types/assets/SingleMediaEditor.d.ts +10 -0
- package/dist/{assets → types/assets}/WrappedAssetCard/AssetCardActions.d.ts +11 -11
- package/dist/{assets → types/assets}/WrappedAssetCard/FetchingWrappedAssetCard.d.ts +17 -17
- package/dist/{assets → types/assets}/WrappedAssetCard/WrappedAssetCard.d.ts +24 -24
- package/dist/{assets → types/assets}/WrappedAssetCard/WrappedAssetLink.d.ts +16 -16
- package/dist/{assets → types/assets}/index.d.ts +3 -3
- package/dist/{common → types/common}/EntityStore.d.ts +62 -62
- package/dist/{common → types/common}/MultipleReferenceEditor.d.ts +25 -25
- package/dist/{common → types/common}/ReferenceEditor.d.ts +46 -46
- package/dist/{common → types/common}/SingleReferenceEditor.d.ts +24 -24
- package/dist/{common → types/common}/SortableLinkList.d.ts +19 -19
- package/dist/{common → types/common}/customCardTypes.d.ts +29 -29
- package/dist/types/common/useAccessApi.d.ts +16 -0
- package/dist/{common → types/common}/useContentTypePermissions.d.ts +17 -17
- package/dist/{common → types/common}/useEditorPermissions.d.ts +17 -17
- package/dist/types/common/useEditorPermissions.spec.d.ts +1 -0
- package/dist/{components → types/components}/AssetThumbnail/AssetThumbnail.d.ts +7 -7
- package/dist/{components → types/components}/CreateEntryLinkButton/CreateEntryLinkButton.d.ts +19 -19
- package/dist/types/components/CreateEntryLinkButton/CreateEntryLinkButton.spec.d.ts +1 -0
- package/dist/{components → types/components}/CreateEntryLinkButton/CreateEntryMenuTrigger.d.ts +31 -31
- package/dist/types/components/CreateEntryLinkButton/CreateEntryMenuTrigger.spec.d.ts +1 -0
- package/dist/{components → types/components}/CreateEntryLinkButton/useGlobalMouseUp.d.ts +1 -1
- package/dist/{components → types/components}/LinkActions/CombinedLinkActions.d.ts +10 -10
- package/dist/{components → types/components}/LinkActions/LinkActions.d.ts +26 -26
- package/dist/{components → types/components}/LinkActions/LinkEntityActions.d.ts +24 -24
- package/dist/types/components/LinkActions/NoLinkPermissionsInfo.d.ts +2 -0
- package/dist/{components → types/components}/LinkActions/helpers.d.ts +26 -26
- package/dist/{components → types/components}/LinkActions/redesignStyles.d.ts +3 -3
- package/dist/{components → types/components}/LinkActions/styles.d.ts +2 -2
- package/dist/{components → types/components}/MissingEntityCard/MissingEntityCard.d.ts +8 -8
- package/dist/{components → types/components}/MissingEntityCard/styles.d.ts +2 -2
- package/dist/{components → types/components}/ScheduledIconWithTooltip/ScheduleTooltip.d.ts +11 -11
- package/dist/{components → types/components}/ScheduledIconWithTooltip/ScheduledIconWithTooltip.d.ts +10 -10
- package/dist/{components → types/components}/ScheduledIconWithTooltip/formatDateAndTime.d.ts +15 -15
- package/dist/types/components/SpaceName/SpaceName.d.ts +6 -0
- package/dist/{components → types/components}/index.d.ts +9 -9
- package/dist/{entries → types/entries}/MultipleEntryReferenceEditor.d.ts +3 -3
- package/dist/{entries → types/entries}/SingleEntryReferenceEditor.d.ts +8 -8
- package/dist/{entries → types/entries}/WrappedEntryCard/FetchingWrappedEntryCard.d.ts +18 -18
- package/dist/{entries → types/entries}/WrappedEntryCard/WrappedEntryCard.d.ts +35 -35
- package/dist/{entries → types/entries}/index.d.ts +3 -3
- package/dist/{index.d.ts → types/index.d.ts} +9 -8
- package/dist/{resources → types/resources}/Cards/ContentfulEntryCard.d.ts +21 -21
- package/dist/{resources → types/resources}/Cards/ResourceCard.d.ts +12 -12
- package/dist/{resources → types/resources}/Cards/UnsupportedEntityCard.d.ts +4 -4
- package/dist/{resources → types/resources}/MultipleResourceReferenceEditor.d.ts +7 -7
- package/dist/types/resources/MultipleResourceReferenceEditor.spec.d.ts +1 -0
- package/dist/{resources → types/resources}/SingleResourceReferenceEditor.d.ts +7 -7
- package/dist/types/resources/SingleResourceReferenceEditor.spec.d.ts +1 -0
- package/dist/{resources → types/resources}/index.d.ts +2 -2
- package/dist/{resources → types/resources}/testHelpers/resourceEditorHelpers.d.ts +50 -50
- package/dist/{resources → types/resources}/useResourceLinkActions.d.ts +7 -7
- package/dist/{types.d.ts → types/types.d.ts} +104 -104
- package/dist/{utils → types/utils}/fromFieldValidations.d.ts +21 -21
- package/package.json +25 -11
- package/CHANGELOG.md +0 -854
- package/dist/assets/SingleMediaEditor.d.ts +0 -10
- package/dist/common/useAccessApi.d.ts +0 -16
- package/dist/components/LinkActions/NoLinkPermissionsInfo.d.ts +0 -2
- package/dist/components/SpaceName/SpaceName.d.ts +0 -6
- package/dist/field-editor-reference.cjs.development.js +0 -4395
- package/dist/field-editor-reference.cjs.development.js.map +0 -1
- package/dist/field-editor-reference.cjs.production.min.js +0 -2
- package/dist/field-editor-reference.cjs.production.min.js.map +0 -1
- package/dist/field-editor-reference.esm.js +0 -4369
- package/dist/field-editor-reference.esm.js.map +0 -1
- package/dist/index.js +0 -8
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { AssetCard } from '@contentful/f36-components';
|
|
3
|
+
import { ClockIcon } from '@contentful/f36-icons';
|
|
4
|
+
import tokens from '@contentful/f36-tokens';
|
|
5
|
+
import { entityHelpers } from '@contentful/field-editor-shared';
|
|
6
|
+
import mimetype from '@contentful/mimetype';
|
|
7
|
+
import { css } from 'emotion';
|
|
8
|
+
import { MissingEntityCard, ScheduledIconWithTooltip } from '../../components';
|
|
9
|
+
import { renderActions, renderAssetInfo } from './AssetCardActions';
|
|
10
|
+
const groupToIconMap = {
|
|
11
|
+
image: 'image',
|
|
12
|
+
video: 'video',
|
|
13
|
+
audio: 'audio',
|
|
14
|
+
richtext: 'richtext',
|
|
15
|
+
presentation: 'presentation',
|
|
16
|
+
spreadsheet: 'spreadsheet',
|
|
17
|
+
pdfdocument: 'pdf',
|
|
18
|
+
archive: 'archive',
|
|
19
|
+
plaintext: 'plaintext',
|
|
20
|
+
code: 'code',
|
|
21
|
+
markup: 'markup'
|
|
22
|
+
};
|
|
23
|
+
const styles = {
|
|
24
|
+
scheduleIcon: css({
|
|
25
|
+
marginRight: tokens.spacing2Xs
|
|
26
|
+
})
|
|
27
|
+
};
|
|
28
|
+
const defaultProps = {
|
|
29
|
+
isClickable: true
|
|
30
|
+
};
|
|
31
|
+
function getFileType(file) {
|
|
32
|
+
if (!file) {
|
|
33
|
+
return 'archive';
|
|
34
|
+
}
|
|
35
|
+
const groupName = mimetype.getGroupLabel({
|
|
36
|
+
type: file.contentType,
|
|
37
|
+
fallbackFileName: file.fileName
|
|
38
|
+
});
|
|
39
|
+
return groupToIconMap[groupName] || 'archive';
|
|
40
|
+
}
|
|
41
|
+
export const WrappedAssetCard = (props)=>{
|
|
42
|
+
const { className , onEdit , getAssetUrl , onRemove , size , isDisabled , isSelected , isClickable } = props;
|
|
43
|
+
const status = entityHelpers.getEntryStatus(props.asset.sys);
|
|
44
|
+
if (status === 'deleted') {
|
|
45
|
+
return React.createElement(MissingEntityCard, {
|
|
46
|
+
entityType: "Asset",
|
|
47
|
+
asSquare: true,
|
|
48
|
+
isDisabled: props.isDisabled,
|
|
49
|
+
onRemove: props.onRemove
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const entityTitle = entityHelpers.getAssetTitle({
|
|
53
|
+
asset: props.asset,
|
|
54
|
+
localeCode: props.localeCode,
|
|
55
|
+
defaultLocaleCode: props.defaultLocaleCode,
|
|
56
|
+
defaultTitle: 'Untitled'
|
|
57
|
+
});
|
|
58
|
+
const entityFile = props.asset.fields.file ? props.asset.fields.file[props.localeCode] || props.asset.fields.file[props.defaultLocaleCode] : undefined;
|
|
59
|
+
const href = getAssetUrl ? getAssetUrl(props.asset.sys.id) : undefined;
|
|
60
|
+
return React.createElement(AssetCard, {
|
|
61
|
+
as: href ? 'a' : 'article',
|
|
62
|
+
type: getFileType(entityFile),
|
|
63
|
+
title: entityTitle,
|
|
64
|
+
className: className,
|
|
65
|
+
isSelected: isSelected,
|
|
66
|
+
href: href,
|
|
67
|
+
status: status,
|
|
68
|
+
icon: React.createElement(ScheduledIconWithTooltip, {
|
|
69
|
+
getEntityScheduledActions: props.getEntityScheduledActions,
|
|
70
|
+
entityType: "Asset",
|
|
71
|
+
entityId: props.asset.sys.id
|
|
72
|
+
}, React.createElement(ClockIcon, {
|
|
73
|
+
className: styles.scheduleIcon,
|
|
74
|
+
size: "small",
|
|
75
|
+
variant: "muted",
|
|
76
|
+
testId: "schedule-icon"
|
|
77
|
+
})),
|
|
78
|
+
src: entityFile && entityFile.url ? size === 'small' ? `${entityFile.url}?w=150&h=150&fit=thumb` : `${entityFile.url}?h=300` : '',
|
|
79
|
+
onClick: isClickable ? (e)=>{
|
|
80
|
+
e.preventDefault();
|
|
81
|
+
onEdit && onEdit();
|
|
82
|
+
} : undefined,
|
|
83
|
+
onKeyDown: isClickable ? (e)=>{
|
|
84
|
+
if (e.key === 'Enter' && onEdit) {
|
|
85
|
+
e.preventDefault();
|
|
86
|
+
onEdit();
|
|
87
|
+
}
|
|
88
|
+
} : undefined,
|
|
89
|
+
dragHandleRender: props.renderDragHandle,
|
|
90
|
+
withDragHandle: !!props.renderDragHandle,
|
|
91
|
+
actions: [
|
|
92
|
+
...renderActions({
|
|
93
|
+
entityFile,
|
|
94
|
+
isDisabled: isDisabled,
|
|
95
|
+
onEdit,
|
|
96
|
+
onRemove
|
|
97
|
+
}),
|
|
98
|
+
...entityFile ? renderAssetInfo({
|
|
99
|
+
entityFile
|
|
100
|
+
}) : []
|
|
101
|
+
].filter((item)=>item),
|
|
102
|
+
size: size
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
WrappedAssetCard.defaultProps = defaultProps;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { EntryCard } from '@contentful/f36-components';
|
|
3
|
+
import { ClockIcon } from '@contentful/f36-icons';
|
|
4
|
+
import tokens from '@contentful/f36-tokens';
|
|
5
|
+
import { entityHelpers, isValidImage } from '@contentful/field-editor-shared';
|
|
6
|
+
import { css } from 'emotion';
|
|
7
|
+
import { AssetThumbnail, MissingEntityCard, ScheduledIconWithTooltip } from '../../components';
|
|
8
|
+
import { renderActions, renderAssetInfo } from './AssetCardActions';
|
|
9
|
+
const styles = {
|
|
10
|
+
scheduleIcon: css({
|
|
11
|
+
marginRight: tokens.spacing2Xs
|
|
12
|
+
})
|
|
13
|
+
};
|
|
14
|
+
export const WrappedAssetLink = (props)=>{
|
|
15
|
+
const { className , href , onEdit , onRemove , isDisabled } = props;
|
|
16
|
+
const status = entityHelpers.getEntryStatus(props.asset.sys);
|
|
17
|
+
if (status === 'deleted') {
|
|
18
|
+
return React.createElement(MissingEntityCard, {
|
|
19
|
+
entityType: "Asset",
|
|
20
|
+
isDisabled: props.isDisabled,
|
|
21
|
+
onRemove: props.onRemove
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
const entityTitle = entityHelpers.getAssetTitle({
|
|
25
|
+
asset: props.asset,
|
|
26
|
+
localeCode: props.localeCode,
|
|
27
|
+
defaultLocaleCode: props.defaultLocaleCode,
|
|
28
|
+
defaultTitle: 'Untitled'
|
|
29
|
+
});
|
|
30
|
+
const entityFile = props.asset.fields.file ? props.asset.fields.file[props.localeCode] || props.asset.fields.file[props.defaultLocaleCode] : undefined;
|
|
31
|
+
return React.createElement(EntryCard, {
|
|
32
|
+
as: href ? 'a' : 'article',
|
|
33
|
+
contentType: "Asset",
|
|
34
|
+
title: entityTitle,
|
|
35
|
+
className: className,
|
|
36
|
+
href: href,
|
|
37
|
+
size: "small",
|
|
38
|
+
status: status,
|
|
39
|
+
thumbnailElement: entityFile && isValidImage(entityFile) ? React.createElement(AssetThumbnail, {
|
|
40
|
+
file: entityFile
|
|
41
|
+
}) : undefined,
|
|
42
|
+
icon: React.createElement(ScheduledIconWithTooltip, {
|
|
43
|
+
getEntityScheduledActions: props.getEntityScheduledActions,
|
|
44
|
+
entityType: "Asset",
|
|
45
|
+
entityId: props.asset.sys.id
|
|
46
|
+
}, React.createElement(ClockIcon, {
|
|
47
|
+
className: styles.scheduleIcon,
|
|
48
|
+
size: "small",
|
|
49
|
+
variant: "muted",
|
|
50
|
+
testId: "schedule-icon"
|
|
51
|
+
})),
|
|
52
|
+
onClick: (e)=>{
|
|
53
|
+
e.preventDefault();
|
|
54
|
+
onEdit();
|
|
55
|
+
},
|
|
56
|
+
onKeyDown: (e)=>{
|
|
57
|
+
if (e.key === 'Enter' && onEdit) {
|
|
58
|
+
e.preventDefault();
|
|
59
|
+
onEdit();
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
dragHandleRender: props.renderDragHandle,
|
|
63
|
+
withDragHandle: !!props.renderDragHandle,
|
|
64
|
+
actions: [
|
|
65
|
+
renderActions({
|
|
66
|
+
entityFile,
|
|
67
|
+
isDisabled: isDisabled,
|
|
68
|
+
onEdit,
|
|
69
|
+
onRemove
|
|
70
|
+
}),
|
|
71
|
+
entityFile ? renderAssetInfo({
|
|
72
|
+
entityFile
|
|
73
|
+
}) : null
|
|
74
|
+
].filter((item)=>item)
|
|
75
|
+
});
|
|
76
|
+
};
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
import React, { useCallback, useEffect, useMemo, useRef } from 'react';
|
|
15
|
+
import { QueryCache, QueryClient, QueryClientProvider, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
16
|
+
import constate from 'constate';
|
|
17
|
+
import { createClient } from 'contentful-management';
|
|
18
|
+
import PQueue from 'p-queue';
|
|
19
|
+
const globalQueue = new PQueue({
|
|
20
|
+
concurrency: 50
|
|
21
|
+
});
|
|
22
|
+
export class UnsupportedError extends Error {
|
|
23
|
+
constructor(message){
|
|
24
|
+
super(message);
|
|
25
|
+
_define_property(this, "isUnsupportedError", void 0);
|
|
26
|
+
this.isUnsupportedError = true;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function isUnsupportedError(value) {
|
|
30
|
+
return typeof value === 'object' && value?.isUnsupportedError === true;
|
|
31
|
+
}
|
|
32
|
+
const isEntityQueryKey = (queryKey)=>{
|
|
33
|
+
return Array.isArray(queryKey) && (queryKey[0] === 'Entry' || queryKey[0] === 'Asset') && queryKey.length === 4;
|
|
34
|
+
};
|
|
35
|
+
async function fetchContentfulEntry(params) {
|
|
36
|
+
const { urn , fetch , options } = params;
|
|
37
|
+
const resourceId = urn.split(':', 6)[5];
|
|
38
|
+
const [, spaceId, , entryId] = resourceId.split('/');
|
|
39
|
+
const environmentId = 'master';
|
|
40
|
+
const [space, entry] = await Promise.all([
|
|
41
|
+
fetch([
|
|
42
|
+
'space',
|
|
43
|
+
spaceId
|
|
44
|
+
], ({ cmaClient })=>cmaClient.space.get({
|
|
45
|
+
spaceId
|
|
46
|
+
}), options),
|
|
47
|
+
fetch([
|
|
48
|
+
'entry',
|
|
49
|
+
spaceId,
|
|
50
|
+
environmentId,
|
|
51
|
+
entryId
|
|
52
|
+
], ({ cmaClient })=>cmaClient.entry.get({
|
|
53
|
+
spaceId,
|
|
54
|
+
environmentId,
|
|
55
|
+
entryId
|
|
56
|
+
}), options)
|
|
57
|
+
]);
|
|
58
|
+
const contentTypeId = entry.sys.contentType.sys.id;
|
|
59
|
+
const [contentType, defaultLocaleCode] = await Promise.all([
|
|
60
|
+
fetch([
|
|
61
|
+
'contentType',
|
|
62
|
+
spaceId,
|
|
63
|
+
environmentId,
|
|
64
|
+
contentTypeId
|
|
65
|
+
], ({ cmaClient })=>cmaClient.contentType.get({
|
|
66
|
+
contentTypeId,
|
|
67
|
+
spaceId,
|
|
68
|
+
environmentId
|
|
69
|
+
}), options),
|
|
70
|
+
fetch([
|
|
71
|
+
'defaultLocale',
|
|
72
|
+
spaceId,
|
|
73
|
+
environmentId
|
|
74
|
+
], async ({ cmaClient })=>{
|
|
75
|
+
const locales = await cmaClient.locale.getMany({
|
|
76
|
+
spaceId,
|
|
77
|
+
environmentId,
|
|
78
|
+
query: {
|
|
79
|
+
limit: 100
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
const defaultLocaleCode = locales.items.find((locale)=>locale.default)?.code;
|
|
83
|
+
return defaultLocaleCode;
|
|
84
|
+
}, options)
|
|
85
|
+
]);
|
|
86
|
+
return {
|
|
87
|
+
defaultLocaleCode,
|
|
88
|
+
resource: entry,
|
|
89
|
+
space: space,
|
|
90
|
+
contentType: contentType
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
const [InternalServiceProvider, useFetch, useEntityLoader, useCurrentIds] = constate(function useInitServices(props) {
|
|
94
|
+
const currentSpaceId = props.sdk.ids.space;
|
|
95
|
+
const currentEnvironmentId = props.sdk.ids.environmentAlias ?? props.sdk.ids.environment;
|
|
96
|
+
const environmentIds = useMemo(()=>[
|
|
97
|
+
props.sdk.ids.environmentAlias,
|
|
98
|
+
props.sdk.ids.environment
|
|
99
|
+
], [
|
|
100
|
+
props.sdk.ids.environmentAlias,
|
|
101
|
+
props.sdk.ids.environment
|
|
102
|
+
]);
|
|
103
|
+
const queryClient = useQueryClient();
|
|
104
|
+
const queryCache = queryClient.getQueryCache();
|
|
105
|
+
const entityChangeUnsubscribers = useRef({});
|
|
106
|
+
const cmaClient = useMemo(()=>createClient({
|
|
107
|
+
apiAdapter: props.sdk.cmaAdapter
|
|
108
|
+
}, {
|
|
109
|
+
type: 'plain'
|
|
110
|
+
}), [
|
|
111
|
+
props.sdk.cmaAdapter
|
|
112
|
+
]);
|
|
113
|
+
const queryQueue = useMemo(()=>{
|
|
114
|
+
if (props.queryConcurrency) {
|
|
115
|
+
return new PQueue({
|
|
116
|
+
concurrency: props.queryConcurrency
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
return globalQueue;
|
|
120
|
+
}, [
|
|
121
|
+
props.queryConcurrency
|
|
122
|
+
]);
|
|
123
|
+
const fetch = useCallback(function fetch(queryKey, fn, options = {}) {
|
|
124
|
+
const { priority , ...queryOptions } = options;
|
|
125
|
+
return queryClient.fetchQuery(queryKey, ()=>queryQueue.add(()=>fn({
|
|
126
|
+
cmaClient
|
|
127
|
+
}), {
|
|
128
|
+
priority
|
|
129
|
+
}), queryOptions);
|
|
130
|
+
}, [
|
|
131
|
+
queryClient,
|
|
132
|
+
queryQueue,
|
|
133
|
+
cmaClient
|
|
134
|
+
]);
|
|
135
|
+
const getEntity = useCallback(function getEntity(entityType, entityId, options) {
|
|
136
|
+
const spaceId = options?.spaceId ?? currentSpaceId;
|
|
137
|
+
const environmentId = options?.environmentId ?? currentEnvironmentId;
|
|
138
|
+
const queryKey = [
|
|
139
|
+
entityType,
|
|
140
|
+
entityId,
|
|
141
|
+
spaceId,
|
|
142
|
+
environmentId
|
|
143
|
+
];
|
|
144
|
+
return fetch(queryKey, ({ cmaClient })=>{
|
|
145
|
+
if (entityType === 'Entry') {
|
|
146
|
+
return cmaClient.entry.get({
|
|
147
|
+
entryId: entityId,
|
|
148
|
+
spaceId,
|
|
149
|
+
environmentId
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
if (entityType === 'Asset') {
|
|
153
|
+
return cmaClient.asset.get({
|
|
154
|
+
assetId: entityId,
|
|
155
|
+
spaceId,
|
|
156
|
+
environmentId
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
throw new UnsupportedError('Unsupported entity type');
|
|
160
|
+
}, options);
|
|
161
|
+
}, [
|
|
162
|
+
fetch,
|
|
163
|
+
currentSpaceId,
|
|
164
|
+
currentEnvironmentId
|
|
165
|
+
]);
|
|
166
|
+
const getEntityScheduledActions = useCallback(function getEntityScheduledActions(entityType, entityId, options) {
|
|
167
|
+
const fixedEntityCacheId = 'scheduledActionEntityId';
|
|
168
|
+
const maxScheduledActions = 500;
|
|
169
|
+
const spaceId = options?.spaceId ?? currentSpaceId;
|
|
170
|
+
const environmentId = options?.environmentId ?? currentEnvironmentId;
|
|
171
|
+
const queryKey = [
|
|
172
|
+
'scheduled-actions',
|
|
173
|
+
entityType,
|
|
174
|
+
fixedEntityCacheId,
|
|
175
|
+
spaceId,
|
|
176
|
+
environmentId
|
|
177
|
+
];
|
|
178
|
+
return fetch(queryKey, async ({ cmaClient })=>{
|
|
179
|
+
const response = await cmaClient.scheduledActions.getMany({
|
|
180
|
+
spaceId,
|
|
181
|
+
query: {
|
|
182
|
+
'environment.sys.id': environmentId,
|
|
183
|
+
'sys.status[in]': 'scheduled',
|
|
184
|
+
order: 'scheduledFor.datetime',
|
|
185
|
+
limit: maxScheduledActions
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
return response.items;
|
|
189
|
+
}, options).then((items)=>items.filter((action)=>action.entity.sys.id === entityId));
|
|
190
|
+
}, [
|
|
191
|
+
fetch,
|
|
192
|
+
currentSpaceId,
|
|
193
|
+
currentEnvironmentId
|
|
194
|
+
]);
|
|
195
|
+
const getResource = useCallback(function getResource(resourceType, urn, options) {
|
|
196
|
+
const queryKey = [
|
|
197
|
+
'Resource',
|
|
198
|
+
resourceType,
|
|
199
|
+
urn
|
|
200
|
+
];
|
|
201
|
+
return fetch(queryKey, ()=>{
|
|
202
|
+
if (resourceType === 'Contentful:Entry') {
|
|
203
|
+
return fetchContentfulEntry({
|
|
204
|
+
fetch,
|
|
205
|
+
urn,
|
|
206
|
+
options
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
throw new UnsupportedError('Unsupported resource type');
|
|
210
|
+
}, options);
|
|
211
|
+
}, [
|
|
212
|
+
fetch
|
|
213
|
+
]);
|
|
214
|
+
const isSameSpaceEntityQueryKey = useCallback((queryKey)=>{
|
|
215
|
+
const isEntityKey = isEntityQueryKey(queryKey);
|
|
216
|
+
const isSameSpaceEntityKey = isEntityKey && queryKey[2] === currentSpaceId && environmentIds.includes(queryKey[3]);
|
|
217
|
+
return isSameSpaceEntityKey;
|
|
218
|
+
}, [
|
|
219
|
+
currentSpaceId,
|
|
220
|
+
environmentIds
|
|
221
|
+
]);
|
|
222
|
+
const onEntityChanged = props.sdk.space.onEntityChanged;
|
|
223
|
+
const onSlideInNavigation = props.sdk.navigator.onSlideInNavigation;
|
|
224
|
+
useEffect(()=>{
|
|
225
|
+
function findSameSpaceQueries() {
|
|
226
|
+
return queryCache.findAll({
|
|
227
|
+
type: 'active',
|
|
228
|
+
predicate: (query)=>isSameSpaceEntityQueryKey(query.queryKey)
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
if (typeof onEntityChanged !== 'function') {
|
|
232
|
+
return onSlideInNavigation(({ oldSlideLevel , newSlideLevel })=>{
|
|
233
|
+
if (oldSlideLevel > newSlideLevel) {
|
|
234
|
+
findSameSpaceQueries().forEach((query)=>{
|
|
235
|
+
void queryClient.invalidateQueries(query.queryKey);
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
const subscribeQuery = ({ queryKey , queryHash })=>{
|
|
241
|
+
const [entityType, entityId] = queryKey;
|
|
242
|
+
entityChangeUnsubscribers.current[queryHash] = onEntityChanged(entityType, entityId, (data)=>{
|
|
243
|
+
queryClient.setQueryData(queryKey, data);
|
|
244
|
+
});
|
|
245
|
+
};
|
|
246
|
+
findSameSpaceQueries().forEach(subscribeQuery);
|
|
247
|
+
const unsubscribe = queryCache.subscribe((event)=>{
|
|
248
|
+
if (!event) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
const { type , query } = event;
|
|
252
|
+
const { queryKey , queryHash } = query;
|
|
253
|
+
if (!isSameSpaceEntityQueryKey(queryKey)) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
if (type === 'added') {
|
|
257
|
+
subscribeQuery(query);
|
|
258
|
+
}
|
|
259
|
+
if (type === 'removed') {
|
|
260
|
+
entityChangeUnsubscribers.current[queryHash]?.();
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
return ()=>{
|
|
264
|
+
unsubscribe();
|
|
265
|
+
Object.values(entityChangeUnsubscribers.current).forEach((off)=>off());
|
|
266
|
+
entityChangeUnsubscribers.current = {};
|
|
267
|
+
};
|
|
268
|
+
}, [
|
|
269
|
+
onEntityChanged,
|
|
270
|
+
queryCache,
|
|
271
|
+
isSameSpaceEntityQueryKey,
|
|
272
|
+
queryClient,
|
|
273
|
+
getEntity,
|
|
274
|
+
onSlideInNavigation
|
|
275
|
+
]);
|
|
276
|
+
return {
|
|
277
|
+
ids: props.sdk.ids,
|
|
278
|
+
cmaClient,
|
|
279
|
+
fetch,
|
|
280
|
+
getResource,
|
|
281
|
+
getEntity,
|
|
282
|
+
getEntityScheduledActions
|
|
283
|
+
};
|
|
284
|
+
}, ({ fetch })=>fetch, ({ getResource , getEntity , getEntityScheduledActions })=>({
|
|
285
|
+
getResource,
|
|
286
|
+
getEntity,
|
|
287
|
+
getEntityScheduledActions
|
|
288
|
+
}), ({ ids })=>({
|
|
289
|
+
environment: ids.environmentAlias ?? ids.environment,
|
|
290
|
+
space: ids.space
|
|
291
|
+
}));
|
|
292
|
+
export function useEntity(entityType, entityId, options) {
|
|
293
|
+
const { space , environment } = useCurrentIds();
|
|
294
|
+
const { getEntity } = useEntityLoader();
|
|
295
|
+
const queryKey = [
|
|
296
|
+
entityType,
|
|
297
|
+
entityId,
|
|
298
|
+
options?.spaceId ?? space,
|
|
299
|
+
options?.environmentId ?? environment
|
|
300
|
+
];
|
|
301
|
+
const { status , data } = useQuery(queryKey, ()=>getEntity(entityType, entityId, options), {
|
|
302
|
+
enabled: options?.enabled
|
|
303
|
+
});
|
|
304
|
+
return {
|
|
305
|
+
status,
|
|
306
|
+
data
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
export function useResource(resourceType, urn, options) {
|
|
310
|
+
const queryKey = [
|
|
311
|
+
'Resource',
|
|
312
|
+
resourceType,
|
|
313
|
+
urn
|
|
314
|
+
];
|
|
315
|
+
const { getResource } = useEntityLoader();
|
|
316
|
+
const { status , data , error } = useQuery(queryKey, ()=>getResource(resourceType, urn, options), {
|
|
317
|
+
enabled: options?.enabled
|
|
318
|
+
});
|
|
319
|
+
return {
|
|
320
|
+
status,
|
|
321
|
+
data,
|
|
322
|
+
error
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
function EntityProvider({ children , ...props }) {
|
|
326
|
+
const reactQueryClient = useMemo(()=>{
|
|
327
|
+
const queryCache = new QueryCache();
|
|
328
|
+
const queryClient = new QueryClient({
|
|
329
|
+
queryCache,
|
|
330
|
+
defaultOptions: {
|
|
331
|
+
queries: {
|
|
332
|
+
useErrorBoundary: false,
|
|
333
|
+
refetchOnWindowFocus: false,
|
|
334
|
+
refetchOnReconnect: true,
|
|
335
|
+
refetchOnMount: false,
|
|
336
|
+
staleTime: Infinity,
|
|
337
|
+
retry: false
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
return queryClient;
|
|
342
|
+
}, []);
|
|
343
|
+
return React.createElement(QueryClientProvider, {
|
|
344
|
+
client: reactQueryClient
|
|
345
|
+
}, React.createElement(InternalServiceProvider, props, children));
|
|
346
|
+
}
|
|
347
|
+
export { EntityProvider, useEntityLoader };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
|
+
import arrayMove from 'array-move';
|
|
4
|
+
import { LinkEntityActions } from '../components';
|
|
5
|
+
import { useLinkActionsProps } from '../components/LinkActions/LinkEntityActions';
|
|
6
|
+
import { ReferenceEditor } from './ReferenceEditor';
|
|
7
|
+
import { useEditorPermissions } from './useEditorPermissions';
|
|
8
|
+
function onLinkOrCreate(setValue, entityType, items, ids, index = items.length) {
|
|
9
|
+
const links = ids.map((id)=>({
|
|
10
|
+
sys: {
|
|
11
|
+
type: 'Link',
|
|
12
|
+
linkType: entityType,
|
|
13
|
+
id
|
|
14
|
+
}
|
|
15
|
+
}));
|
|
16
|
+
const newItems = Array.from(items);
|
|
17
|
+
newItems.splice(index, 0, ...links);
|
|
18
|
+
setValue(newItems);
|
|
19
|
+
}
|
|
20
|
+
const emptyArray = [];
|
|
21
|
+
const nullableValue = {
|
|
22
|
+
sys: {
|
|
23
|
+
id: 'null-value'
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
function Editor(props) {
|
|
27
|
+
const { setValue , entityType , setIndexToUpdate } = props;
|
|
28
|
+
const editorPermissions = useEditorPermissions(props);
|
|
29
|
+
const items = React.useMemo(()=>{
|
|
30
|
+
return (props.items || []).map((link)=>link || nullableValue);
|
|
31
|
+
}, [
|
|
32
|
+
props.items
|
|
33
|
+
]);
|
|
34
|
+
const onSortStart = useCallback((_, event)=>{
|
|
35
|
+
if (event instanceof MouseEvent) {
|
|
36
|
+
document.body.classList.add('grabbing');
|
|
37
|
+
}
|
|
38
|
+
event.preventDefault();
|
|
39
|
+
}, []);
|
|
40
|
+
const onSortEnd = useCallback(({ oldIndex , newIndex })=>{
|
|
41
|
+
props.onSortingEnd && props.onSortingEnd({
|
|
42
|
+
oldIndex,
|
|
43
|
+
newIndex
|
|
44
|
+
});
|
|
45
|
+
const newItems = arrayMove(items, oldIndex, newIndex);
|
|
46
|
+
setValue(newItems);
|
|
47
|
+
setIndexToUpdate && setIndexToUpdate(undefined);
|
|
48
|
+
document.body.classList.remove('grabbing');
|
|
49
|
+
}, [
|
|
50
|
+
items,
|
|
51
|
+
props,
|
|
52
|
+
setIndexToUpdate,
|
|
53
|
+
setValue
|
|
54
|
+
]);
|
|
55
|
+
const onMove = useCallback((oldIndex, newIndex)=>{
|
|
56
|
+
const newItems = arrayMove(items, oldIndex, newIndex);
|
|
57
|
+
setValue(newItems);
|
|
58
|
+
}, [
|
|
59
|
+
items,
|
|
60
|
+
setValue
|
|
61
|
+
]);
|
|
62
|
+
const onCreate = useCallback((id, index)=>onLinkOrCreate(setValue, entityType, items, [
|
|
63
|
+
id
|
|
64
|
+
], index), [
|
|
65
|
+
setValue,
|
|
66
|
+
items,
|
|
67
|
+
entityType
|
|
68
|
+
]);
|
|
69
|
+
const onLink = useCallback((ids, index)=>onLinkOrCreate(setValue, entityType, items, ids, index), [
|
|
70
|
+
setValue,
|
|
71
|
+
items,
|
|
72
|
+
entityType
|
|
73
|
+
]);
|
|
74
|
+
const linkActionsProps = useLinkActionsProps({
|
|
75
|
+
...props,
|
|
76
|
+
canLinkMultiple: true,
|
|
77
|
+
editorPermissions,
|
|
78
|
+
onCreate,
|
|
79
|
+
onLink,
|
|
80
|
+
itemsLength: items.length
|
|
81
|
+
});
|
|
82
|
+
const customCardRenderer = useCallback((cardProps, _, renderDefaultCard)=>props.renderCustomCard ? props.renderCustomCard(cardProps, linkActionsProps, renderDefaultCard) : false, [
|
|
83
|
+
linkActionsProps
|
|
84
|
+
]);
|
|
85
|
+
return React.createElement(React.Fragment, null, props.children({
|
|
86
|
+
...props,
|
|
87
|
+
onSortStart: onSortStart,
|
|
88
|
+
onSortEnd: onSortEnd,
|
|
89
|
+
onMove,
|
|
90
|
+
renderCustomCard: props.renderCustomCard && customCardRenderer
|
|
91
|
+
}), React.createElement(LinkEntityActions, {
|
|
92
|
+
renderCustomActions: props.renderCustomActions,
|
|
93
|
+
...linkActionsProps
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
export function MultipleReferenceEditor(props) {
|
|
97
|
+
const allContentTypes = props.sdk.space.getCachedContentTypes();
|
|
98
|
+
return React.createElement(ReferenceEditor, props, ({ value , disabled , setValue , externalReset })=>{
|
|
99
|
+
return React.createElement(Editor, {
|
|
100
|
+
...props,
|
|
101
|
+
items: value || emptyArray,
|
|
102
|
+
isDisabled: disabled,
|
|
103
|
+
setValue: setValue,
|
|
104
|
+
key: `${externalReset}-list`,
|
|
105
|
+
allContentTypes: allContentTypes
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
MultipleReferenceEditor.defaultProps = {
|
|
110
|
+
hasCardEditActions: true
|
|
111
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { FieldConnector } from '@contentful/field-editor-shared';
|
|
3
|
+
import deepEqual from 'deep-equal';
|
|
4
|
+
import { EntityProvider } from './EntityStore';
|
|
5
|
+
export function ReferenceEditor(props) {
|
|
6
|
+
return React.createElement(EntityProvider, {
|
|
7
|
+
sdk: props.sdk
|
|
8
|
+
}, React.createElement(FieldConnector, {
|
|
9
|
+
throttle: 0,
|
|
10
|
+
field: props.sdk.field,
|
|
11
|
+
isInitiallyDisabled: props.isInitiallyDisabled,
|
|
12
|
+
isEqualValues: (value1, value2)=>{
|
|
13
|
+
return deepEqual(value1, value2);
|
|
14
|
+
}
|
|
15
|
+
}, props.children));
|
|
16
|
+
}
|
|
17
|
+
ReferenceEditor.defaultProps = {
|
|
18
|
+
isInitiallyDisabled: true,
|
|
19
|
+
hasCardEditActions: true
|
|
20
|
+
};
|