@contentful/field-editor-reference 5.9.0 → 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.
Files changed (199) hide show
  1. package/dist/cjs/__fixtures__/FakeSdk.js +183 -0
  2. package/dist/cjs/__fixtures__/asset/index.js +37 -0
  3. package/dist/cjs/__fixtures__/content-type/index.js +16 -0
  4. package/dist/cjs/__fixtures__/entry/index.js +33 -0
  5. package/dist/cjs/__fixtures__/fixtures.js +71 -0
  6. package/dist/cjs/__fixtures__/locale/index.js +40 -0
  7. package/dist/cjs/__fixtures__/space/index.js +16 -0
  8. package/dist/cjs/assets/MultipleMediaEditor.js +86 -0
  9. package/dist/cjs/assets/SingleMediaEditor.js +69 -0
  10. package/dist/cjs/assets/WrappedAssetCard/AssetCardActions.js +125 -0
  11. package/dist/cjs/assets/WrappedAssetCard/FetchingWrappedAssetCard.js +171 -0
  12. package/dist/cjs/assets/WrappedAssetCard/WrappedAssetCard.js +159 -0
  13. package/dist/cjs/assets/WrappedAssetCard/WrappedAssetLink.js +130 -0
  14. package/dist/cjs/assets/index.js +24 -0
  15. package/dist/cjs/common/EntityStore.js +420 -0
  16. package/dist/cjs/common/MultipleReferenceEditor.js +164 -0
  17. package/dist/cjs/common/ReferenceEditor.js +74 -0
  18. package/dist/cjs/common/SingleReferenceEditor.js +118 -0
  19. package/dist/cjs/common/SortableLinkList.js +95 -0
  20. package/dist/cjs/common/customCardTypes.js +44 -0
  21. package/dist/cjs/common/useAccessApi.js +19 -0
  22. package/dist/cjs/common/useContentTypePermissions.js +54 -0
  23. package/dist/cjs/common/useEditorPermissions.js +77 -0
  24. package/dist/cjs/common/useEditorPermissions.spec.js +205 -0
  25. package/dist/cjs/components/AssetThumbnail/AssetThumbnail.js +62 -0
  26. package/dist/cjs/components/CreateEntryLinkButton/CreateEntryLinkButton.js +102 -0
  27. package/dist/cjs/components/CreateEntryLinkButton/CreateEntryLinkButton.spec.js +254 -0
  28. package/dist/cjs/components/CreateEntryLinkButton/CreateEntryMenuTrigger.js +199 -0
  29. package/dist/cjs/components/CreateEntryLinkButton/CreateEntryMenuTrigger.spec.js +190 -0
  30. package/dist/cjs/components/CreateEntryLinkButton/useGlobalMouseUp.js +19 -0
  31. package/dist/cjs/components/LinkActions/CombinedLinkActions.js +167 -0
  32. package/dist/cjs/components/LinkActions/LinkActions.js +123 -0
  33. package/dist/cjs/components/LinkActions/LinkEntityActions.js +186 -0
  34. package/dist/cjs/components/LinkActions/NoLinkPermissionsInfo.js +54 -0
  35. package/dist/cjs/components/LinkActions/helpers.js +78 -0
  36. package/dist/cjs/components/LinkActions/redesignStyles.js +44 -0
  37. package/dist/cjs/components/LinkActions/styles.js +33 -0
  38. package/dist/cjs/components/MissingEntityCard/MissingEntityCard.js +75 -0
  39. package/dist/cjs/components/MissingEntityCard/styles.js +29 -0
  40. package/dist/cjs/components/ScheduledIconWithTooltip/ScheduleTooltip.js +75 -0
  41. package/dist/cjs/components/ScheduledIconWithTooltip/ScheduledIconWithTooltip.js +81 -0
  42. package/dist/cjs/components/ScheduledIconWithTooltip/formatDateAndTime.js +45 -0
  43. package/dist/cjs/components/SpaceName/SpaceName.js +91 -0
  44. package/dist/cjs/components/index.js +44 -0
  45. package/dist/cjs/entries/MultipleEntryReferenceEditor.js +86 -0
  46. package/dist/cjs/entries/SingleEntryReferenceEditor.js +74 -0
  47. package/dist/cjs/entries/WrappedEntryCard/FetchingWrappedEntryCard.js +189 -0
  48. package/dist/cjs/entries/WrappedEntryCard/WrappedEntryCard.js +181 -0
  49. package/dist/cjs/entries/index.js +24 -0
  50. package/dist/cjs/index.js +92 -0
  51. package/dist/cjs/resources/Cards/ContentfulEntryCard.js +87 -0
  52. package/dist/cjs/resources/Cards/ResourceCard.js +111 -0
  53. package/dist/cjs/resources/Cards/UnsupportedEntityCard.js +64 -0
  54. package/dist/cjs/resources/MultipleResourceReferenceEditor.js +157 -0
  55. package/dist/cjs/resources/MultipleResourceReferenceEditor.spec.js +297 -0
  56. package/dist/cjs/resources/SingleResourceReferenceEditor.js +87 -0
  57. package/dist/cjs/resources/SingleResourceReferenceEditor.spec.js +161 -0
  58. package/dist/cjs/resources/index.js +19 -0
  59. package/dist/cjs/resources/testHelpers/resourceEditorHelpers.js +121 -0
  60. package/dist/cjs/resources/useResourceLinkActions.js +88 -0
  61. package/dist/cjs/types.js +22 -0
  62. package/dist/cjs/utils/fromFieldValidations.js +54 -0
  63. package/dist/esm/__fixtures__/FakeSdk.js +173 -0
  64. package/dist/esm/__fixtures__/asset/index.js +6 -0
  65. package/dist/esm/__fixtures__/content-type/index.js +2 -0
  66. package/dist/esm/__fixtures__/entry/index.js +5 -0
  67. package/dist/esm/__fixtures__/fixtures.js +6 -0
  68. package/dist/esm/__fixtures__/locale/index.js +15 -0
  69. package/dist/esm/__fixtures__/space/index.js +2 -0
  70. package/dist/esm/assets/MultipleMediaEditor.js +37 -0
  71. package/dist/esm/assets/SingleMediaEditor.js +20 -0
  72. package/dist/esm/assets/WrappedAssetCard/AssetCardActions.js +63 -0
  73. package/dist/esm/assets/WrappedAssetCard/FetchingWrappedAssetCard.js +122 -0
  74. package/dist/esm/assets/WrappedAssetCard/WrappedAssetCard.js +105 -0
  75. package/dist/esm/assets/WrappedAssetCard/WrappedAssetLink.js +76 -0
  76. package/dist/esm/assets/index.js +3 -0
  77. package/dist/esm/common/EntityStore.js +347 -0
  78. package/dist/esm/common/MultipleReferenceEditor.js +111 -0
  79. package/dist/esm/common/ReferenceEditor.js +20 -0
  80. package/dist/esm/common/SingleReferenceEditor.js +70 -0
  81. package/dist/esm/common/SortableLinkList.js +41 -0
  82. package/dist/esm/common/customCardTypes.js +1 -0
  83. package/dist/esm/common/useAccessApi.js +9 -0
  84. package/dist/esm/common/useContentTypePermissions.js +44 -0
  85. package/dist/esm/common/useEditorPermissions.js +67 -0
  86. package/dist/esm/common/useEditorPermissions.spec.js +201 -0
  87. package/dist/esm/components/AssetThumbnail/AssetThumbnail.js +13 -0
  88. package/dist/esm/components/CreateEntryLinkButton/CreateEntryLinkButton.js +48 -0
  89. package/dist/esm/components/CreateEntryLinkButton/CreateEntryLinkButton.spec.js +206 -0
  90. package/dist/esm/components/CreateEntryLinkButton/CreateEntryMenuTrigger.js +145 -0
  91. package/dist/esm/components/CreateEntryLinkButton/CreateEntryMenuTrigger.spec.js +142 -0
  92. package/dist/esm/components/CreateEntryLinkButton/useGlobalMouseUp.js +9 -0
  93. package/dist/esm/components/LinkActions/CombinedLinkActions.js +118 -0
  94. package/dist/esm/components/LinkActions/LinkActions.js +66 -0
  95. package/dist/esm/components/LinkActions/LinkEntityActions.js +127 -0
  96. package/dist/esm/components/LinkActions/NoLinkPermissionsInfo.js +5 -0
  97. package/dist/esm/components/LinkActions/helpers.js +57 -0
  98. package/dist/esm/components/LinkActions/redesignStyles.js +18 -0
  99. package/dist/esm/components/LinkActions/styles.js +10 -0
  100. package/dist/esm/components/MissingEntityCard/MissingEntityCard.js +26 -0
  101. package/dist/esm/components/MissingEntityCard/styles.js +11 -0
  102. package/dist/esm/components/ScheduledIconWithTooltip/ScheduleTooltip.js +18 -0
  103. package/dist/esm/components/ScheduledIconWithTooltip/ScheduledIconWithTooltip.js +32 -0
  104. package/dist/esm/components/ScheduledIconWithTooltip/formatDateAndTime.js +19 -0
  105. package/dist/esm/components/SpaceName/SpaceName.js +37 -0
  106. package/dist/esm/components/index.js +8 -0
  107. package/dist/esm/entries/MultipleEntryReferenceEditor.js +37 -0
  108. package/dist/esm/entries/SingleEntryReferenceEditor.js +25 -0
  109. package/dist/esm/entries/WrappedEntryCard/FetchingWrappedEntryCard.js +135 -0
  110. package/dist/esm/entries/WrappedEntryCard/WrappedEntryCard.js +127 -0
  111. package/dist/esm/entries/index.js +3 -0
  112. package/dist/esm/index.js +7 -0
  113. package/dist/esm/resources/Cards/ContentfulEntryCard.js +38 -0
  114. package/dist/esm/resources/Cards/ResourceCard.js +62 -0
  115. package/dist/esm/resources/Cards/UnsupportedEntityCard.js +15 -0
  116. package/dist/esm/resources/MultipleResourceReferenceEditor.js +104 -0
  117. package/dist/esm/resources/MultipleResourceReferenceEditor.spec.js +254 -0
  118. package/dist/esm/resources/SingleResourceReferenceEditor.js +33 -0
  119. package/dist/esm/resources/SingleResourceReferenceEditor.spec.js +118 -0
  120. package/dist/esm/resources/index.js +2 -0
  121. package/dist/esm/resources/testHelpers/resourceEditorHelpers.js +103 -0
  122. package/dist/esm/resources/useResourceLinkActions.js +78 -0
  123. package/dist/esm/types.js +1 -0
  124. package/dist/esm/utils/fromFieldValidations.js +39 -0
  125. package/dist/{__fixtures__ → types/__fixtures__}/FakeSdk.d.ts +8 -8
  126. package/dist/{__fixtures__ → types/__fixtures__}/asset/index.d.ts +6 -6
  127. package/dist/{__fixtures__ → types/__fixtures__}/content-type/index.d.ts +2 -2
  128. package/dist/{__fixtures__ → types/__fixtures__}/entry/index.d.ts +5 -5
  129. package/dist/{__fixtures__ → types/__fixtures__}/fixtures.d.ts +6 -6
  130. package/dist/{__fixtures__ → types/__fixtures__}/locale/index.d.ts +42 -42
  131. package/dist/{__fixtures__ → types/__fixtures__}/space/index.d.ts +2 -2
  132. package/dist/{assets → types/assets}/MultipleMediaEditor.d.ts +10 -10
  133. package/dist/types/assets/SingleMediaEditor.d.ts +10 -0
  134. package/dist/{assets → types/assets}/WrappedAssetCard/AssetCardActions.d.ts +11 -11
  135. package/dist/{assets → types/assets}/WrappedAssetCard/FetchingWrappedAssetCard.d.ts +17 -17
  136. package/dist/{assets → types/assets}/WrappedAssetCard/WrappedAssetCard.d.ts +24 -24
  137. package/dist/{assets → types/assets}/WrappedAssetCard/WrappedAssetLink.d.ts +16 -16
  138. package/dist/{assets → types/assets}/index.d.ts +3 -3
  139. package/dist/{common → types/common}/EntityStore.d.ts +62 -62
  140. package/dist/{common → types/common}/MultipleReferenceEditor.d.ts +25 -25
  141. package/dist/{common → types/common}/ReferenceEditor.d.ts +46 -46
  142. package/dist/{common → types/common}/SingleReferenceEditor.d.ts +24 -24
  143. package/dist/{common → types/common}/SortableLinkList.d.ts +19 -19
  144. package/dist/{common → types/common}/customCardTypes.d.ts +29 -29
  145. package/dist/types/common/useAccessApi.d.ts +16 -0
  146. package/dist/{common → types/common}/useContentTypePermissions.d.ts +17 -17
  147. package/dist/{common → types/common}/useEditorPermissions.d.ts +17 -17
  148. package/dist/types/common/useEditorPermissions.spec.d.ts +1 -0
  149. package/dist/{components → types/components}/AssetThumbnail/AssetThumbnail.d.ts +7 -7
  150. package/dist/{components → types/components}/CreateEntryLinkButton/CreateEntryLinkButton.d.ts +19 -19
  151. package/dist/types/components/CreateEntryLinkButton/CreateEntryLinkButton.spec.d.ts +1 -0
  152. package/dist/{components → types/components}/CreateEntryLinkButton/CreateEntryMenuTrigger.d.ts +31 -31
  153. package/dist/types/components/CreateEntryLinkButton/CreateEntryMenuTrigger.spec.d.ts +1 -0
  154. package/dist/{components → types/components}/CreateEntryLinkButton/useGlobalMouseUp.d.ts +1 -1
  155. package/dist/{components → types/components}/LinkActions/CombinedLinkActions.d.ts +10 -10
  156. package/dist/{components → types/components}/LinkActions/LinkActions.d.ts +26 -26
  157. package/dist/{components → types/components}/LinkActions/LinkEntityActions.d.ts +24 -24
  158. package/dist/types/components/LinkActions/NoLinkPermissionsInfo.d.ts +2 -0
  159. package/dist/{components → types/components}/LinkActions/helpers.d.ts +26 -26
  160. package/dist/{components → types/components}/LinkActions/redesignStyles.d.ts +3 -3
  161. package/dist/{components → types/components}/LinkActions/styles.d.ts +2 -2
  162. package/dist/{components → types/components}/MissingEntityCard/MissingEntityCard.d.ts +8 -8
  163. package/dist/{components → types/components}/MissingEntityCard/styles.d.ts +2 -2
  164. package/dist/{components → types/components}/ScheduledIconWithTooltip/ScheduleTooltip.d.ts +11 -11
  165. package/dist/{components → types/components}/ScheduledIconWithTooltip/ScheduledIconWithTooltip.d.ts +10 -10
  166. package/dist/{components → types/components}/ScheduledIconWithTooltip/formatDateAndTime.d.ts +15 -15
  167. package/dist/types/components/SpaceName/SpaceName.d.ts +6 -0
  168. package/dist/{components → types/components}/index.d.ts +9 -9
  169. package/dist/{entries → types/entries}/MultipleEntryReferenceEditor.d.ts +3 -3
  170. package/dist/{entries → types/entries}/SingleEntryReferenceEditor.d.ts +8 -8
  171. package/dist/{entries → types/entries}/WrappedEntryCard/FetchingWrappedEntryCard.d.ts +18 -18
  172. package/dist/{entries → types/entries}/WrappedEntryCard/WrappedEntryCard.d.ts +35 -35
  173. package/dist/{entries → types/entries}/index.d.ts +3 -3
  174. package/dist/{index.d.ts → types/index.d.ts} +9 -8
  175. package/dist/{resources → types/resources}/Cards/ContentfulEntryCard.d.ts +21 -21
  176. package/dist/{resources → types/resources}/Cards/ResourceCard.d.ts +12 -12
  177. package/dist/{resources → types/resources}/Cards/UnsupportedEntityCard.d.ts +4 -4
  178. package/dist/{resources → types/resources}/MultipleResourceReferenceEditor.d.ts +7 -7
  179. package/dist/types/resources/MultipleResourceReferenceEditor.spec.d.ts +1 -0
  180. package/dist/{resources → types/resources}/SingleResourceReferenceEditor.d.ts +7 -7
  181. package/dist/types/resources/SingleResourceReferenceEditor.spec.d.ts +1 -0
  182. package/dist/{resources → types/resources}/index.d.ts +2 -2
  183. package/dist/{resources → types/resources}/testHelpers/resourceEditorHelpers.d.ts +50 -50
  184. package/dist/{resources → types/resources}/useResourceLinkActions.d.ts +7 -7
  185. package/dist/{types.d.ts → types/types.d.ts} +104 -104
  186. package/dist/{utils → types/utils}/fromFieldValidations.d.ts +21 -21
  187. package/package.json +25 -11
  188. package/CHANGELOG.md +0 -860
  189. package/dist/assets/SingleMediaEditor.d.ts +0 -10
  190. package/dist/common/useAccessApi.d.ts +0 -16
  191. package/dist/components/LinkActions/NoLinkPermissionsInfo.d.ts +0 -2
  192. package/dist/components/SpaceName/SpaceName.d.ts +0 -6
  193. package/dist/field-editor-reference.cjs.development.js +0 -2753
  194. package/dist/field-editor-reference.cjs.development.js.map +0 -1
  195. package/dist/field-editor-reference.cjs.production.min.js +0 -2
  196. package/dist/field-editor-reference.cjs.production.min.js.map +0 -1
  197. package/dist/field-editor-reference.esm.js +0 -2727
  198. package/dist/field-editor-reference.esm.js.map +0 -1
  199. package/dist/index.js +0 -8
@@ -0,0 +1,118 @@
1
+ import * as React from 'react';
2
+ import '@testing-library/jest-dom/extend-expect';
3
+ import { fireEvent, render, screen } from '@testing-library/react';
4
+ import { useResource } from '../common/EntityStore';
5
+ import { SingleResourceReferenceEditor } from './SingleResourceReferenceEditor';
6
+ import { createFakeEntryResource, mockSdkForField } from './testHelpers/resourceEditorHelpers';
7
+ const mockedResources = {};
8
+ jest.mock('../common/EntityStore', ()=>{
9
+ const module = jest.requireActual('../common/EntityStore');
10
+ return {
11
+ ...module,
12
+ useResource: jest.fn((linkType, urn)=>({
13
+ data: mockedResources[`${linkType}.${urn}`],
14
+ status: 'success'
15
+ }))
16
+ };
17
+ });
18
+ jest.mock('react-intersection-observer', ()=>{
19
+ const module = jest.requireActual('react-intersection-observer');
20
+ return {
21
+ ...module,
22
+ useInView: ()=>({
23
+ inView: true
24
+ })
25
+ };
26
+ });
27
+ const fieldDefinition = {
28
+ type: 'ResourceLink',
29
+ id: 'foo',
30
+ name: 'Foo',
31
+ allowedResources: [
32
+ {
33
+ source: 'foo',
34
+ contentTypes: [
35
+ 'bar'
36
+ ]
37
+ }
38
+ ],
39
+ required: true,
40
+ validations: []
41
+ };
42
+ describe('Single resource editor', ()=>{
43
+ it('renders the action button when no value is set', async ()=>{
44
+ const sdk = mockSdkForField(fieldDefinition);
45
+ render(React.createElement(SingleResourceReferenceEditor, {
46
+ isInitiallyDisabled: false,
47
+ sdk: sdk,
48
+ hasCardEditActions: true,
49
+ viewType: "card",
50
+ parameters: {}
51
+ }));
52
+ const button = await screen.findByText('Add existing content');
53
+ expect(button).toBeDefined();
54
+ fireEvent.click(button);
55
+ const dialogFn = sdk.dialogs.selectSingleResourceEntry;
56
+ expect(dialogFn).toHaveBeenCalledTimes(1);
57
+ const options = dialogFn.mock.calls[0][0];
58
+ expect(options).toEqual({
59
+ allowedResources: fieldDefinition.allowedResources
60
+ });
61
+ });
62
+ it('renders custom actions when passed', async ()=>{
63
+ const sdk = mockSdkForField(fieldDefinition);
64
+ render(React.createElement(SingleResourceReferenceEditor, {
65
+ isInitiallyDisabled: false,
66
+ sdk: sdk,
67
+ hasCardEditActions: true,
68
+ viewType: "card",
69
+ parameters: {},
70
+ renderCustomActions: ()=>React.createElement("div", {
71
+ "data-testid": "custom-actions"
72
+ })
73
+ }));
74
+ const customActions = await screen.findByTestId('custom-actions');
75
+ expect(customActions).toBeDefined();
76
+ });
77
+ it('renders the card button when the value is set', async ()=>{
78
+ const sdk = mockSdkForField(fieldDefinition, {
79
+ sys: {
80
+ type: 'Link',
81
+ linkType: 'Contentful:Entry',
82
+ urn: 'crn:test:::content:spaces/x-space/entries/linkedEntryId'
83
+ }
84
+ });
85
+ const info = createFakeEntryResource({
86
+ title: 'Title of linked entry',
87
+ id: 'linkedEntryId',
88
+ space: {
89
+ id: 'x-space',
90
+ name: 'X Space'
91
+ }
92
+ });
93
+ mockedResources[`Contentful:Entry.crn:test:::content:spaces/x-space/entries/linkedEntryId`] = info;
94
+ render(React.createElement(SingleResourceReferenceEditor, {
95
+ isInitiallyDisabled: false,
96
+ sdk: sdk,
97
+ hasCardEditActions: true,
98
+ viewType: "card",
99
+ apiUrl: "test-contentful",
100
+ getEntryRouteHref: jest.fn(),
101
+ parameters: {}
102
+ }));
103
+ expect(useResource).toHaveBeenCalled();
104
+ const title = await screen.findByText('Title of linked entry');
105
+ await screen.findByText('X Space');
106
+ const theCard = title.closest('[data-test-id="cf-ui-entry-card"]');
107
+ const actionsBtn = theCard?.querySelector('[data-test-id="cf-ui-card-actions"]');
108
+ expect(actionsBtn).toBeDefined();
109
+ fireEvent.click(actionsBtn);
110
+ const removeBtn = await screen.findByText('Remove', {
111
+ selector: '[role="menuitem"]'
112
+ });
113
+ fireEvent.click(removeBtn);
114
+ expect(sdk.field.removeValue).toHaveBeenCalledWith();
115
+ const linkExistingBtn = screen.queryByText('Add existing content');
116
+ expect(linkExistingBtn).not.toBeInTheDocument();
117
+ });
118
+ });
@@ -0,0 +1,2 @@
1
+ export * from './MultipleResourceReferenceEditor';
2
+ export * from './SingleResourceReferenceEditor';
@@ -0,0 +1,103 @@
1
+ export function mockSdkForField(fieldDefinition, fieldValue) {
2
+ return {
3
+ field: {
4
+ getValue: jest.fn(()=>fieldValue),
5
+ setValue: jest.fn(()=>Promise.resolve(undefined)),
6
+ removeValue: jest.fn(),
7
+ onSchemaErrorsChanged: ()=>{},
8
+ onIsDisabledChanged: ()=>{},
9
+ onValueChanged: ()=>{},
10
+ ...fieldDefinition,
11
+ locale: 'en'
12
+ },
13
+ dialogs: {
14
+ selectSingleResourceEntry: jest.fn().mockResolvedValue({
15
+ sys: {
16
+ type: 'Entry',
17
+ id: 'linkedEntryId',
18
+ space: {
19
+ sys: {
20
+ type: 'Link',
21
+ linkType: 'Space',
22
+ id: 'x-space'
23
+ }
24
+ }
25
+ }
26
+ }),
27
+ selectMultipleResourceEntries: jest.fn().mockResolvedValue([
28
+ {
29
+ sys: {
30
+ type: 'Entry',
31
+ id: 'linkedEntryId',
32
+ space: {
33
+ sys: {
34
+ type: 'Link',
35
+ linkType: 'Space',
36
+ id: 'x-space'
37
+ }
38
+ }
39
+ }
40
+ }
41
+ ])
42
+ },
43
+ ids: {
44
+ space: 'myTestSpace',
45
+ environment: 'master',
46
+ organization: 'acme',
47
+ user: 'norris_chuck',
48
+ field: fieldDefinition.id,
49
+ entry: 'testEntry',
50
+ contentType: 'testCT'
51
+ },
52
+ space: {
53
+ onEntityChanged: ()=>{}
54
+ },
55
+ navigator: {
56
+ onSlideInNavigation: ()=>()=>({})
57
+ }
58
+ };
59
+ }
60
+ export const createFakeEntryResource = ({ title , id , space })=>{
61
+ const { id: spaceId , name: spaceName } = space;
62
+ return {
63
+ resource: {
64
+ sys: {
65
+ id,
66
+ type: 'Entry',
67
+ space: {
68
+ sys: {
69
+ id: spaceId
70
+ }
71
+ },
72
+ environment: {
73
+ sys: {
74
+ id: `${spaceId}-environment`
75
+ }
76
+ }
77
+ },
78
+ fields: {
79
+ title: {
80
+ en: title
81
+ }
82
+ }
83
+ },
84
+ contentType: {
85
+ sys: {
86
+ id: 'xTestCT'
87
+ },
88
+ displayField: 'title',
89
+ fields: [
90
+ {
91
+ type: 'Symbol',
92
+ id: 'title',
93
+ name: 'The title'
94
+ }
95
+ ]
96
+ },
97
+ localeCode: 'en',
98
+ defaultLocaleCode: 'en',
99
+ space: {
100
+ name: spaceName
101
+ }
102
+ };
103
+ };
@@ -0,0 +1,78 @@
1
+ import { useCallback, useMemo } from 'react';
2
+ const toLinkItem = (entry, apiUrl)=>({
3
+ sys: {
4
+ type: 'ResourceLink',
5
+ linkType: 'Contentful:Entry',
6
+ urn: entry.sys.urn ?? `crn:${apiUrl}:::content:spaces/${entry.sys.space.sys.id}/entries/${entry.sys.id}`
7
+ }
8
+ });
9
+ const getUpdatedValue = (field, entries, apiUrl)=>{
10
+ const multiple = field.type === 'Array';
11
+ if (multiple) {
12
+ const linkItems = entries.map((entry)=>toLinkItem(entry, apiUrl));
13
+ const prevValue = field.getValue() || [];
14
+ return [
15
+ ...prevValue,
16
+ ...linkItems
17
+ ];
18
+ } else {
19
+ return toLinkItem(entries[0], apiUrl);
20
+ }
21
+ };
22
+ export function useResourceLinkActions({ dialogs , field , onAfterLink , apiUrl }) {
23
+ const handleAfterLink = useCallback((entries)=>{
24
+ if (!onAfterLink) {
25
+ return;
26
+ }
27
+ entries.forEach(onAfterLink);
28
+ }, [
29
+ onAfterLink
30
+ ]);
31
+ const onLinkedExisting = useMemo(()=>{
32
+ return (entries)=>{
33
+ const updatedValue = getUpdatedValue(field, entries, apiUrl);
34
+ field.setValue(updatedValue);
35
+ handleAfterLink(entries);
36
+ };
37
+ }, [
38
+ field,
39
+ handleAfterLink,
40
+ apiUrl
41
+ ]);
42
+ const multiple = field.type === 'Array';
43
+ const onLinkExisting = useMemo(()=>{
44
+ const promptSelection = multiple ? async ()=>await dialogs.selectMultipleResourceEntries({
45
+ allowedResources: field.allowedResources
46
+ }) : async ()=>[
47
+ await dialogs.selectSingleResourceEntry({
48
+ allowedResources: field.allowedResources
49
+ })
50
+ ];
51
+ return async ()=>{
52
+ const res = await promptSelection();
53
+ if (!res) {
54
+ return;
55
+ }
56
+ onLinkedExisting(res);
57
+ };
58
+ }, [
59
+ dialogs,
60
+ field.allowedResources,
61
+ multiple,
62
+ onLinkedExisting
63
+ ]);
64
+ return {
65
+ onLinkExisting,
66
+ onLinkedExisting,
67
+ entityType: 'Entry',
68
+ contentTypes: [],
69
+ canCreateEntity: false,
70
+ canLinkMultiple: multiple,
71
+ canLinkEntity: true,
72
+ isDisabled: false,
73
+ isEmpty: false,
74
+ isFull: false,
75
+ onCreate: async ()=>{},
76
+ onCreated: ()=>{}
77
+ };
78
+ }
@@ -0,0 +1 @@
1
+ export { Entry, File, Asset } from '@contentful/field-editor-shared';
@@ -0,0 +1,39 @@
1
+ import isNumber from 'lodash/isNumber';
2
+ export function fromFieldValidations(field) {
3
+ const validations = [
4
+ ...field.validations,
5
+ ...field.items?.validations ?? []
6
+ ];
7
+ const linkContentTypeValidations = validations.find((v)=>'linkContentType' in v);
8
+ const linkMimetypeGroupValidations = validations.find((v)=>'linkMimetypeGroup' in v);
9
+ const sizeValidations = validations.find((v)=>'size' in v);
10
+ const size = sizeValidations && sizeValidations.size || {};
11
+ const min = size.min;
12
+ const max = size.max;
13
+ let numberOfLinks = undefined;
14
+ if (isNumber(min) && isNumber(max)) {
15
+ numberOfLinks = {
16
+ type: 'min-max',
17
+ min,
18
+ max
19
+ };
20
+ } else if (isNumber(min)) {
21
+ numberOfLinks = {
22
+ type: 'min',
23
+ min,
24
+ max: undefined
25
+ };
26
+ } else if (isNumber(max)) {
27
+ numberOfLinks = {
28
+ type: 'max',
29
+ max,
30
+ min: undefined
31
+ };
32
+ }
33
+ const result = {
34
+ contentTypes: linkContentTypeValidations?.linkContentType ?? undefined,
35
+ mimetypeGroups: linkMimetypeGroupValidations?.linkMimetypeGroup ?? undefined,
36
+ numberOfLinks
37
+ };
38
+ return result;
39
+ }
@@ -1,8 +1,8 @@
1
- import { FieldExtensionSDK } from '@contentful/app-sdk';
2
- import { Emitter } from 'mitt';
3
- export declare type ReferenceEditorSdkProps = {
4
- initialValue?: any;
5
- validations?: any;
6
- fetchDelay?: number;
7
- };
8
- export declare function newReferenceEditorFakeSdk(props?: ReferenceEditorSdkProps): [FieldExtensionSDK, Emitter];
1
+ import { FieldExtensionSDK } from '@contentful/app-sdk';
2
+ import { Emitter } from 'mitt';
3
+ export type ReferenceEditorSdkProps = {
4
+ initialValue?: any;
5
+ validations?: any;
6
+ fetchDelay?: number;
7
+ };
8
+ export declare function newReferenceEditorFakeSdk(props?: ReferenceEditorSdkProps): [FieldExtensionSDK, Emitter];
@@ -1,6 +1,6 @@
1
- import changed from './changed_asset.json';
2
- import created from './created_asset.json';
3
- import empty from './empty_asset.json';
4
- import invalid from './invalid_asset.json';
5
- import published from './published_asset.json';
6
- export { changed, empty, published, invalid, created };
1
+ import changed from './changed_asset.json';
2
+ import created from './created_asset.json';
3
+ import empty from './empty_asset.json';
4
+ import invalid from './invalid_asset.json';
5
+ import published from './published_asset.json';
6
+ export { changed, empty, published, invalid, created };
@@ -1,2 +1,2 @@
1
- import published from './published_content_type.json';
2
- export { published };
1
+ import published from './published_content_type.json';
2
+ export { published };
@@ -1,5 +1,5 @@
1
- import changed from './changed_entry.json';
2
- import empty from './empty_entry.json';
3
- import invalid from './invalid_entry.json';
4
- import published from './published_entry.json';
5
- export { changed, empty, published, invalid };
1
+ import changed from './changed_entry.json';
2
+ import empty from './empty_entry.json';
3
+ import invalid from './invalid_entry.json';
4
+ import published from './published_entry.json';
5
+ export { changed, empty, published, invalid };
@@ -1,6 +1,6 @@
1
- import * as assets from './asset';
2
- import * as contentTypes from './content-type';
3
- import * as entries from './entry';
4
- import * as locales from './locale';
5
- import * as spaces from './space';
6
- export { assets, contentTypes, entries, locales, spaces };
1
+ import * as assets from './asset';
2
+ import * as contentTypes from './content-type';
3
+ import * as entries from './entry';
4
+ import * as locales from './locale';
5
+ import * as spaces from './space';
6
+ export { assets, contentTypes, entries, locales, spaces };
@@ -1,42 +1,42 @@
1
- import englishDefault from './english_default_locale.json';
2
- import german from './german_locale.json';
3
- declare const list: {
4
- sys: {
5
- type: string;
6
- };
7
- total: number;
8
- skip: number;
9
- limit: number;
10
- items: {
11
- sys: {
12
- id: string;
13
- type: string;
14
- createdAt: string;
15
- updatedAt: string;
16
- version: number;
17
- space: {
18
- sys: {
19
- type: string;
20
- linkType: string;
21
- id: string;
22
- };
23
- };
24
- environment: {
25
- sys: {
26
- id: string;
27
- type: string;
28
- linkType: string;
29
- };
30
- };
31
- };
32
- name: string;
33
- code: string;
34
- internal_code: string;
35
- fallbackCode: null;
36
- contentDeliveryApi: boolean;
37
- contentManagementApi: boolean;
38
- default: boolean;
39
- optional: boolean;
40
- }[];
41
- };
42
- export { englishDefault, german, list };
1
+ import englishDefault from './english_default_locale.json';
2
+ import german from './german_locale.json';
3
+ declare const list: {
4
+ sys: {
5
+ type: string;
6
+ };
7
+ total: number;
8
+ skip: number;
9
+ limit: number;
10
+ items: {
11
+ sys: {
12
+ id: string;
13
+ type: string;
14
+ createdAt: string;
15
+ updatedAt: string;
16
+ version: number;
17
+ space: {
18
+ sys: {
19
+ type: string;
20
+ linkType: string;
21
+ id: string;
22
+ };
23
+ };
24
+ environment: {
25
+ sys: {
26
+ id: string;
27
+ type: string;
28
+ linkType: string;
29
+ };
30
+ };
31
+ };
32
+ name: string;
33
+ code: string;
34
+ internal_code: string;
35
+ fallbackCode: null;
36
+ contentDeliveryApi: boolean;
37
+ contentManagementApi: boolean;
38
+ default: boolean;
39
+ optional: boolean;
40
+ }[];
41
+ };
42
+ export { englishDefault, german, list };
@@ -1,2 +1,2 @@
1
- import indifferent from './indifferent_space.json';
2
- export { indifferent };
1
+ import indifferent from './indifferent_space.json';
2
+ export { indifferent };
@@ -1,10 +1,10 @@
1
- /// <reference types="react" />
2
- import { ReferenceEditorProps } from '../common/ReferenceEditor';
3
- declare type EditorProps = Pick<ReferenceEditorProps, Exclude<keyof ReferenceEditorProps, 'hasCardEditActions'>>;
4
- export declare function MultipleMediaEditor(props: EditorProps): JSX.Element;
5
- export declare namespace MultipleMediaEditor {
6
- var defaultProps: {
7
- isInitiallyDisabled: boolean;
8
- };
9
- }
10
- export {};
1
+ import * as React from 'react';
2
+ import { ReferenceEditorProps } from '../common/ReferenceEditor';
3
+ type EditorProps = Pick<ReferenceEditorProps, Exclude<keyof ReferenceEditorProps, 'hasCardEditActions'>>;
4
+ export declare function MultipleMediaEditor(props: EditorProps): React.JSX.Element;
5
+ export declare namespace MultipleMediaEditor {
6
+ var defaultProps: {
7
+ isInitiallyDisabled: boolean;
8
+ };
9
+ }
10
+ export {};
@@ -0,0 +1,10 @@
1
+ import * as React from 'react';
2
+ import { ReferenceEditorProps } from '../common/ReferenceEditor';
3
+ type EditorProps = Pick<ReferenceEditorProps, Exclude<keyof ReferenceEditorProps, 'hasCardEditActions'>>;
4
+ export declare function SingleMediaEditor(props: EditorProps): React.JSX.Element;
5
+ export declare namespace SingleMediaEditor {
6
+ var defaultProps: {
7
+ isInitiallyDisabled: boolean;
8
+ };
9
+ }
10
+ export {};
@@ -1,11 +1,11 @@
1
- /// <reference types="react" />
2
- import { File } from '../../types';
3
- export declare function renderAssetInfo(props: {
4
- entityFile: File;
5
- }): any[];
6
- export declare function renderActions(props: {
7
- onEdit?: () => void;
8
- onRemove?: () => void;
9
- isDisabled: boolean;
10
- entityFile?: File;
11
- }): (JSX.Element | null)[];
1
+ import * as React from 'react';
2
+ import { File } from '../../types';
3
+ export declare function renderAssetInfo(props: {
4
+ entityFile: File;
5
+ }): any[];
6
+ export declare function renderActions(props: {
7
+ onEdit?: () => void;
8
+ onRemove?: () => void;
9
+ isDisabled: boolean;
10
+ entityFile?: File;
11
+ }): (React.JSX.Element | null)[];
@@ -1,17 +1,17 @@
1
- /// <reference types="react" />
2
- import { CustomCardRenderer, RenderCustomMissingEntityCard } from '../../common/customCardTypes';
3
- import { Action, FieldExtensionSDK, ViewType, RenderDragFn } from '../../types';
4
- declare type FetchingWrappedAssetCardProps = {
5
- assetId: string;
6
- isDisabled: boolean;
7
- sdk: FieldExtensionSDK;
8
- viewType: ViewType | 'big_card';
9
- onRemove: () => void;
10
- getEntityUrl?: (id: string) => string;
11
- onAction?: (action: Action) => void;
12
- renderDragHandle?: RenderDragFn;
13
- renderCustomCard?: CustomCardRenderer;
14
- renderCustomMissingEntityCard?: RenderCustomMissingEntityCard;
15
- };
16
- export declare function FetchingWrappedAssetCard(props: FetchingWrappedAssetCardProps): JSX.Element;
17
- export {};
1
+ import * as React from 'react';
2
+ import { CustomCardRenderer, RenderCustomMissingEntityCard } from '../../common/customCardTypes';
3
+ import { Action, FieldExtensionSDK, ViewType, RenderDragFn } from '../../types';
4
+ type FetchingWrappedAssetCardProps = {
5
+ assetId: string;
6
+ isDisabled: boolean;
7
+ sdk: FieldExtensionSDK;
8
+ viewType: ViewType | 'big_card';
9
+ onRemove: () => void;
10
+ getEntityUrl?: (id: string) => string;
11
+ onAction?: (action: Action) => void;
12
+ renderDragHandle?: RenderDragFn;
13
+ renderCustomCard?: CustomCardRenderer;
14
+ renderCustomMissingEntityCard?: RenderCustomMissingEntityCard;
15
+ };
16
+ export declare function FetchingWrappedAssetCard(props: FetchingWrappedAssetCardProps): React.JSX.Element;
17
+ export {};
@@ -1,24 +1,24 @@
1
- /// <reference types="react" />
2
- import { SpaceAPI } from '@contentful/app-sdk';
3
- import { Asset, RenderDragFn } from '../../types';
4
- export interface WrappedAssetCardProps {
5
- getEntityScheduledActions: SpaceAPI['getEntityScheduledActions'];
6
- asset: Asset;
7
- localeCode: string;
8
- defaultLocaleCode: string;
9
- getAssetUrl?: (assetId: string) => string;
10
- className?: string;
11
- isSelected?: boolean;
12
- isDisabled: boolean;
13
- onEdit?: () => void;
14
- onRemove?: () => void;
15
- size: 'default' | 'small';
16
- renderDragHandle?: RenderDragFn;
17
- isClickable: boolean;
18
- }
19
- export declare const WrappedAssetCard: {
20
- (props: WrappedAssetCardProps): JSX.Element;
21
- defaultProps: {
22
- isClickable: boolean;
23
- };
24
- };
1
+ import * as React from 'react';
2
+ import { SpaceAPI } from '@contentful/app-sdk';
3
+ import { Asset, RenderDragFn } from '../../types';
4
+ export interface WrappedAssetCardProps {
5
+ getEntityScheduledActions: SpaceAPI['getEntityScheduledActions'];
6
+ asset: Asset;
7
+ localeCode: string;
8
+ defaultLocaleCode: string;
9
+ getAssetUrl?: (assetId: string) => string;
10
+ className?: string;
11
+ isSelected?: boolean;
12
+ isDisabled: boolean;
13
+ onEdit?: () => void;
14
+ onRemove?: () => void;
15
+ size: 'default' | 'small';
16
+ renderDragHandle?: RenderDragFn;
17
+ isClickable: boolean;
18
+ }
19
+ export declare const WrappedAssetCard: {
20
+ (props: WrappedAssetCardProps): React.JSX.Element;
21
+ defaultProps: {
22
+ isClickable: boolean;
23
+ };
24
+ };