@contentful/field-editor-rich-text 3.17.3 → 3.17.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.
@@ -151,16 +151,6 @@ function HyperlinkModal(props) {
151
151
  }
152
152
  };
153
153
  }
154
- function entityToResourceLink(entity) {
155
- const { urn } = entity.sys;
156
- return {
157
- sys: {
158
- urn,
159
- type: 'ResourceLink',
160
- linkType: 'Contentful:Entry'
161
- }
162
- };
163
- }
164
154
  function isResourceLink(link) {
165
155
  return !!link && !!link.sys.urn;
166
156
  }
@@ -185,10 +175,10 @@ function HyperlinkModal(props) {
185
175
  const options = {
186
176
  allowedResources: (0, _getAllowedResourcesForNodeType.default)(props.sdk.field, _richtexttypes.INLINES.RESOURCE_HYPERLINK)
187
177
  };
188
- const entry = await props.sdk.dialogs.selectSingleResourceEntry(options);
189
- if (entry) {
178
+ const entityLink = await props.sdk.dialogs.selectSingleResourceEntity(options);
179
+ if (entityLink) {
190
180
  setLinkTarget('');
191
- setLinkEntity(entityToResourceLink(entry));
181
+ setLinkEntity(entityLink);
192
182
  }
193
183
  }
194
184
  async function selectAsset() {
@@ -94,14 +94,14 @@ async function selectResourceEntityAndInsert(sdk, editor, logAction) {
94
94
  const { field, dialogs } = sdk;
95
95
  const config = (0, _config.newResourceEntitySelectorConfigFromRichTextField)(field, _richtexttypes.BLOCKS.EMBEDDED_RESOURCE);
96
96
  const { selection } = editor;
97
- const entity = await dialogs.selectSingleResourceEntry(config);
98
- if (!entity) {
97
+ const entityLink = await dialogs.selectSingleResourceEntity(config);
98
+ if (!entityLink) {
99
99
  logAction('cancelCreateEmbedDialog', {
100
100
  nodeType: _richtexttypes.BLOCKS.EMBEDDED_RESOURCE
101
101
  });
102
102
  } else {
103
103
  (0, _internal.select)(editor, selection);
104
- insertBlock(editor, _richtexttypes.BLOCKS.EMBEDDED_RESOURCE, entity);
104
+ insertBlock(editor, _richtexttypes.BLOCKS.EMBEDDED_RESOURCE, entityLink);
105
105
  ensureFollowingParagraph(editor, [
106
106
  _richtexttypes.BLOCKS.EMBEDDED_RESOURCE
107
107
  ]);
@@ -127,27 +127,20 @@ function ensureFollowingParagraph(editor, nodeTypes) {
127
127
  }
128
128
  (0, _editor.moveToTheNextChar)(editor);
129
129
  }
130
- const getLink = (nodeType, entity)=>{
131
- if (nodeType === _richtexttypes.BLOCKS.EMBEDDED_RESOURCE) {
132
- return {
133
- urn: entity.sys.urn,
134
- type: 'ResourceLink',
135
- linkType: 'Contentful:Entry'
136
- };
137
- }
130
+ const getLink = (entity)=>{
138
131
  return {
139
- id: entity.sys.id,
140
- type: 'Link',
141
- linkType: entity.sys.type
132
+ sys: {
133
+ id: entity.sys.id,
134
+ type: 'Link',
135
+ linkType: entity.sys.type
136
+ }
142
137
  };
143
138
  };
144
139
  const createNode = (nodeType, entity)=>{
145
140
  return {
146
141
  type: nodeType,
147
142
  data: {
148
- target: {
149
- sys: getLink(nodeType, entity)
150
- }
143
+ target: nodeType === _richtexttypes.BLOCKS.EMBEDDED_RESOURCE ? entity : getLink(entity)
151
144
  },
152
145
  children: [
153
146
  {
@@ -44,18 +44,13 @@ function getWithEmbeddedEntryInlineEvents(nodeType, sdk) {
44
44
  };
45
45
  };
46
46
  }
47
- const getLink = (nodeType, entity)=>{
48
- if (nodeType === _richtexttypes.INLINES.EMBEDDED_RESOURCE) {
49
- return {
50
- urn: entity.sys.urn,
51
- type: 'ResourceLink',
52
- linkType: 'Contentful:Entry'
53
- };
54
- }
47
+ const getLink = (entity)=>{
55
48
  return {
56
- id: entity.sys.id,
57
- type: 'Link',
58
- linkType: entity.sys.type
49
+ sys: {
50
+ id: entity.sys.id,
51
+ type: 'Link',
52
+ linkType: entity.sys.type
53
+ }
59
54
  };
60
55
  };
61
56
  const createInlineEntryNode = (nodeType, entity)=>{
@@ -67,9 +62,7 @@ const createInlineEntryNode = (nodeType, entity)=>{
67
62
  }
68
63
  ],
69
64
  data: {
70
- target: {
71
- sys: getLink(nodeType, entity)
72
- }
65
+ target: nodeType === _richtexttypes.INLINES.EMBEDDED_RESOURCE ? entity : getLink(entity)
73
66
  }
74
67
  };
75
68
  };
@@ -112,14 +105,14 @@ async function selectResourceEntityAndInsert(editor, sdk, logAction) {
112
105
  withCreate: true
113
106
  };
114
107
  const { selection } = editor;
115
- const entry = await dialogs.selectSingleResourceEntry(config);
116
- if (!entry) {
108
+ const entryLink = await dialogs.selectSingleResourceEntity(config);
109
+ if (!entryLink) {
117
110
  logAction('cancelCreateEmbedDialog', {
118
111
  nodeType
119
112
  });
120
113
  } else {
121
114
  (0, _transforms.select)(editor, selection);
122
- (0, _transforms.insertNodes)(editor, createInlineEntryNode(nodeType, entry));
115
+ (0, _transforms.insertNodes)(editor, createInlineEntryNode(nodeType, entryLink));
123
116
  logAction('insert', {
124
117
  nodeType
125
118
  });
@@ -87,16 +87,6 @@ export function HyperlinkModal(props) {
87
87
  }
88
88
  };
89
89
  }
90
- function entityToResourceLink(entity) {
91
- const { urn } = entity.sys;
92
- return {
93
- sys: {
94
- urn,
95
- type: 'ResourceLink',
96
- linkType: 'Contentful:Entry'
97
- }
98
- };
99
- }
100
90
  function isResourceLink(link) {
101
91
  return !!link && !!link.sys.urn;
102
92
  }
@@ -121,10 +111,10 @@ export function HyperlinkModal(props) {
121
111
  const options = {
122
112
  allowedResources: getAllowedResourcesForNodeType(props.sdk.field, INLINES.RESOURCE_HYPERLINK)
123
113
  };
124
- const entry = await props.sdk.dialogs.selectSingleResourceEntry(options);
125
- if (entry) {
114
+ const entityLink = await props.sdk.dialogs.selectSingleResourceEntity(options);
115
+ if (entityLink) {
126
116
  setLinkTarget('');
127
- setLinkEntity(entityToResourceLink(entry));
117
+ setLinkEntity(entityLink);
128
118
  }
129
119
  }
130
120
  async function selectAsset() {
@@ -68,14 +68,14 @@ export async function selectResourceEntityAndInsert(sdk, editor, logAction) {
68
68
  const { field, dialogs } = sdk;
69
69
  const config = newResourceEntitySelectorConfigFromRichTextField(field, BLOCKS.EMBEDDED_RESOURCE);
70
70
  const { selection } = editor;
71
- const entity = await dialogs.selectSingleResourceEntry(config);
72
- if (!entity) {
71
+ const entityLink = await dialogs.selectSingleResourceEntity(config);
72
+ if (!entityLink) {
73
73
  logAction('cancelCreateEmbedDialog', {
74
74
  nodeType: BLOCKS.EMBEDDED_RESOURCE
75
75
  });
76
76
  } else {
77
77
  select(editor, selection);
78
- insertBlock(editor, BLOCKS.EMBEDDED_RESOURCE, entity);
78
+ insertBlock(editor, BLOCKS.EMBEDDED_RESOURCE, entityLink);
79
79
  ensureFollowingParagraph(editor, [
80
80
  BLOCKS.EMBEDDED_RESOURCE
81
81
  ]);
@@ -101,27 +101,20 @@ function ensureFollowingParagraph(editor, nodeTypes) {
101
101
  }
102
102
  moveToTheNextChar(editor);
103
103
  }
104
- const getLink = (nodeType, entity)=>{
105
- if (nodeType === BLOCKS.EMBEDDED_RESOURCE) {
106
- return {
107
- urn: entity.sys.urn,
108
- type: 'ResourceLink',
109
- linkType: 'Contentful:Entry'
110
- };
111
- }
104
+ const getLink = (entity)=>{
112
105
  return {
113
- id: entity.sys.id,
114
- type: 'Link',
115
- linkType: entity.sys.type
106
+ sys: {
107
+ id: entity.sys.id,
108
+ type: 'Link',
109
+ linkType: entity.sys.type
110
+ }
116
111
  };
117
112
  };
118
113
  const createNode = (nodeType, entity)=>{
119
114
  return {
120
115
  type: nodeType,
121
116
  data: {
122
- target: {
123
- sys: getLink(nodeType, entity)
124
- }
117
+ target: nodeType === BLOCKS.EMBEDDED_RESOURCE ? entity : getLink(entity)
125
118
  },
126
119
  children: [
127
120
  {
@@ -18,18 +18,13 @@ export function getWithEmbeddedEntryInlineEvents(nodeType, sdk) {
18
18
  };
19
19
  };
20
20
  }
21
- const getLink = (nodeType, entity)=>{
22
- if (nodeType === INLINES.EMBEDDED_RESOURCE) {
23
- return {
24
- urn: entity.sys.urn,
25
- type: 'ResourceLink',
26
- linkType: 'Contentful:Entry'
27
- };
28
- }
21
+ const getLink = (entity)=>{
29
22
  return {
30
- id: entity.sys.id,
31
- type: 'Link',
32
- linkType: entity.sys.type
23
+ sys: {
24
+ id: entity.sys.id,
25
+ type: 'Link',
26
+ linkType: entity.sys.type
27
+ }
33
28
  };
34
29
  };
35
30
  const createInlineEntryNode = (nodeType, entity)=>{
@@ -41,9 +36,7 @@ const createInlineEntryNode = (nodeType, entity)=>{
41
36
  }
42
37
  ],
43
38
  data: {
44
- target: {
45
- sys: getLink(nodeType, entity)
46
- }
39
+ target: nodeType === INLINES.EMBEDDED_RESOURCE ? entity : getLink(entity)
47
40
  }
48
41
  };
49
42
  };
@@ -86,14 +79,14 @@ export async function selectResourceEntityAndInsert(editor, sdk, logAction) {
86
79
  withCreate: true
87
80
  };
88
81
  const { selection } = editor;
89
- const entry = await dialogs.selectSingleResourceEntry(config);
90
- if (!entry) {
82
+ const entryLink = await dialogs.selectSingleResourceEntity(config);
83
+ if (!entryLink) {
91
84
  logAction('cancelCreateEmbedDialog', {
92
85
  nodeType
93
86
  });
94
87
  } else {
95
88
  select(editor, selection);
96
- insertNodes(editor, createInlineEntryNode(nodeType, entry));
89
+ insertNodes(editor, createInlineEntryNode(nodeType, entryLink));
97
90
  logAction('insert', {
98
91
  nodeType
99
92
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-rich-text",
3
- "version": "3.17.3",
3
+ "version": "3.17.4",
4
4
  "source": "./src/index.tsx",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -44,7 +44,7 @@
44
44
  "@contentful/f36-icons": "^4.1.1",
45
45
  "@contentful/f36-tokens": "^4.0.0",
46
46
  "@contentful/f36-utils": "^4.19.0",
47
- "@contentful/field-editor-reference": "^5.22.2",
47
+ "@contentful/field-editor-reference": "^5.22.3",
48
48
  "@contentful/field-editor-shared": "^1.4.5",
49
49
  "@contentful/rich-text-plain-text-renderer": "^16.0.4",
50
50
  "@contentful/rich-text-types": "16.3.0",
@@ -86,5 +86,5 @@
86
86
  "publishConfig": {
87
87
  "registry": "https://npm.pkg.github.com/"
88
88
  },
89
- "gitHead": "2797489936a29588027974e35926cff9025cd897"
89
+ "gitHead": "87df8d557b8011b5bd1fcf1560762469683fa32e"
90
90
  }