@atlaskit/editor-synced-block-provider 2.6.0 → 2.7.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 (50) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/cjs/hooks/useFetchSyncBlockData.js +2 -2
  3. package/dist/cjs/index.js +9 -4
  4. package/dist/cjs/providers/confluence/confluenceContentAPI.js +86 -73
  5. package/dist/cjs/providers/syncBlockProvider.js +60 -36
  6. package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +4 -4
  7. package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +78 -17
  8. package/dist/cjs/store-manager/syncBlockStoreManager.js +41 -8
  9. package/dist/cjs/utils/errorHandling.js +13 -0
  10. package/dist/cjs/utils/utils.js +32 -1
  11. package/dist/es2019/hooks/useFetchSyncBlockData.js +1 -1
  12. package/dist/es2019/index.js +2 -3
  13. package/dist/es2019/providers/confluence/confluenceContentAPI.js +62 -40
  14. package/dist/es2019/providers/syncBlockProvider.js +15 -9
  15. package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +1 -1
  16. package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +64 -12
  17. package/dist/es2019/store-manager/syncBlockStoreManager.js +31 -8
  18. package/dist/es2019/utils/errorHandling.js +7 -0
  19. package/dist/es2019/utils/utils.js +31 -0
  20. package/dist/esm/hooks/useFetchSyncBlockData.js +1 -1
  21. package/dist/esm/index.js +2 -3
  22. package/dist/esm/providers/confluence/confluenceContentAPI.js +79 -66
  23. package/dist/esm/providers/syncBlockProvider.js +60 -36
  24. package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +1 -1
  25. package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +79 -18
  26. package/dist/esm/store-manager/syncBlockStoreManager.js +41 -8
  27. package/dist/esm/utils/errorHandling.js +7 -0
  28. package/dist/esm/utils/utils.js +31 -0
  29. package/dist/types/index.d.ts +1 -2
  30. package/dist/types/providers/confluence/confluenceContentAPI.d.ts +2 -2
  31. package/dist/types/providers/syncBlockProvider.d.ts +4 -3
  32. package/dist/types/providers/types.d.ts +6 -2
  33. package/dist/types/store-manager/sourceSyncBlockStoreManager.d.ts +15 -3
  34. package/dist/types/store-manager/syncBlockStoreManager.d.ts +20 -3
  35. package/dist/types/utils/errorHandling.d.ts +1 -0
  36. package/dist/types/utils/utils.d.ts +6 -1
  37. package/dist/types-ts4.5/index.d.ts +1 -2
  38. package/dist/types-ts4.5/providers/confluence/confluenceContentAPI.d.ts +2 -2
  39. package/dist/types-ts4.5/providers/syncBlockProvider.d.ts +4 -3
  40. package/dist/types-ts4.5/providers/types.d.ts +6 -2
  41. package/dist/types-ts4.5/store-manager/sourceSyncBlockStoreManager.d.ts +15 -3
  42. package/dist/types-ts4.5/store-manager/syncBlockStoreManager.d.ts +20 -3
  43. package/dist/types-ts4.5/utils/errorHandling.d.ts +1 -0
  44. package/dist/types-ts4.5/utils/utils.d.ts +6 -1
  45. package/package.json +2 -2
  46. package/dist/cjs/utils/createSyncBlock.js +0 -15
  47. package/dist/es2019/utils/createSyncBlock.js +0 -9
  48. package/dist/esm/utils/createSyncBlock.js +0 -9
  49. package/dist/types/utils/createSyncBlock.d.ts +0 -2
  50. package/dist/types-ts4.5/utils/createSyncBlock.d.ts +0 -2
@@ -7,4 +7,35 @@ export const convertSyncBlockPMNodeToSyncBlockData = node => {
7
7
  };
8
8
  export const isBlogPageType = pageType => {
9
9
  return pageType === 'blogpost';
10
+ };
11
+ export const createSyncBlockNode = (localId, resourceId) => {
12
+ return {
13
+ type: 'syncBlock',
14
+ attrs: {
15
+ localId,
16
+ resourceId
17
+ }
18
+ };
19
+ };
20
+ export const createBodiedSyncBlockNode = (localId, resourceId) => {
21
+ return {
22
+ type: 'bodiedSyncBlock',
23
+ attrs: {
24
+ localId,
25
+ resourceId
26
+ }
27
+ };
28
+ };
29
+ export const convertSyncBlockJSONNodeToSyncBlockNode = node => {
30
+ if (node.type !== 'syncBlock' || !node.attrs || !('localId' in node.attrs) || !('resourceId' in node.attrs) || typeof node.attrs.localId !== 'string' || typeof node.attrs.resourceId !== 'string') {
31
+ return undefined;
32
+ }
33
+ return createSyncBlockNode(node.attrs.localId, node.attrs.resourceId);
34
+ };
35
+ export const convertPMNodeToSyncBlockNode = node => {
36
+ var _node$attrs, _node$attrs2;
37
+ if (node.type.name !== 'syncBlock' || !((_node$attrs = node.attrs) !== null && _node$attrs !== void 0 && _node$attrs.localId) || !((_node$attrs2 = node.attrs) !== null && _node$attrs2 !== void 0 && _node$attrs2.resourceId) || typeof node.attrs.localId !== 'string' || typeof node.attrs.resourceId !== 'string') {
38
+ return undefined;
39
+ }
40
+ return createSyncBlockNode(node.attrs.localId, node.attrs.resourceId);
10
41
  };
@@ -3,7 +3,7 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
  import _regeneratorRuntime from "@babel/runtime/regenerator";
4
4
  import { useCallback, useEffect, useState } from 'react';
5
5
  import { SyncBlockError } from '../common/types';
6
- import { createSyncBlockNode } from '../utils/createSyncBlock';
6
+ import { createSyncBlockNode } from '../utils/utils';
7
7
  export var useFetchSyncBlockData = function useFetchSyncBlockData(manager, resourceId, localId) {
8
8
  var _useState = useState(null),
9
9
  _useState2 = _slicedToArray(_useState, 2),
package/dist/esm/index.js CHANGED
@@ -11,6 +11,5 @@ export { SyncBlockProvider as SyncedBlockProvider, useMemoizedSyncedBlockProvide
11
11
  export { ReferenceSyncBlockStoreManager } from './store-manager/referenceSyncBlockStoreManager';
12
12
  export { SyncBlockStoreManager } from './store-manager/syncBlockStoreManager';
13
13
  export { getConfluencePageAri, getPageIdAndTypeFromAri } from './utils/ari';
14
- export { createSyncBlockNode } from './utils/createSyncBlock';
15
- export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
16
- export { convertSyncBlockPMNodeToSyncBlockData } from './utils/utils';
14
+ export { createSyncBlockNode, convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockJSONNodeToSyncBlockNode } from './utils/utils';
15
+ export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
@@ -8,6 +8,7 @@ import { useMemo } from 'react';
8
8
  import { SyncBlockError } from '../../common/types';
9
9
  import { getLocalIdFromAri, getPageIdAndTypeFromAri } from '../../utils/ari';
10
10
  import { getContentProperty, createContentProperty, updateContentProperty, deleteContentProperty } from '../../utils/contentProperty';
11
+ import { stringifyError } from '../../utils/errorHandling';
11
12
  import { isBlogPageType } from '../../utils/utils';
12
13
 
13
14
  /**
@@ -163,7 +164,7 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
163
164
  }
164
165
  return _context2.abrupt("return", key);
165
166
  case 9:
166
- throw new Error('Failed to create blog post content property');
167
+ return _context2.abrupt("return", Promise.reject('Failed to create blog post content property'));
167
168
  case 10:
168
169
  _context2.next = 20;
169
170
  break;
@@ -178,7 +179,7 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
178
179
  }
179
180
  return _context2.abrupt("return", key);
180
181
  case 19:
181
- throw new Error('Failed to create page content property');
182
+ return _context2.abrupt("return", Promise.reject('Failed to create page content property'));
182
183
  case 20:
183
184
  case "end":
184
185
  return _context2.stop();
@@ -195,17 +196,26 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
195
196
  key: "writeData",
196
197
  value: function () {
197
198
  var _writeData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(data) {
198
- var _getPageIdAndTypeFrom2, pageId, pageType, localId, key, options, _contentProperty$data4, contentProperty, _contentProperty3$dat, _contentProperty3, _key;
199
+ var match, resourceId, _match, pageId, pageType, localId, key, options, updatePayload, updateResult;
199
200
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
200
201
  while (1) switch (_context3.prev = _context3.next) {
201
202
  case 0:
202
- _getPageIdAndTypeFrom2 = getPageIdAndTypeFromAri(data.resourceId), pageId = _getPageIdAndTypeFrom2.id, pageType = _getPageIdAndTypeFrom2.type;
203
- if (!data.resourceId) {
204
- _context3.next = 34;
205
- break;
206
- }
203
+ resourceId = data.resourceId;
204
+ _context3.prev = 1;
205
+ match = getPageIdAndTypeFromAri(data.resourceId);
206
+ _context3.next = 8;
207
+ break;
208
+ case 5:
209
+ _context3.prev = 5;
210
+ _context3.t0 = _context3["catch"](1);
211
+ return _context3.abrupt("return", {
212
+ error: stringifyError(_context3.t0)
213
+ });
214
+ case 8:
215
+ _match = match, pageId = _match.id, pageType = _match.type;
216
+ _context3.prev = 9;
207
217
  // Update existing content property
208
- localId = getLocalIdFromAri(data.resourceId);
218
+ localId = getLocalIdFromAri(resourceId);
209
219
  key = getContentPropertyKey(this.config.contentPropertyKey, localId);
210
220
  options = {
211
221
  pageId: pageId,
@@ -214,60 +224,50 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
214
224
  cloudId: this.config.cloudId,
215
225
  pageType: pageType
216
226
  };
217
- if (!isBlogPageType(pageType)) {
218
- _context3.next = 20;
219
- break;
220
- }
221
- _context3.next = 8;
227
+ _context3.next = 15;
222
228
  return updateContentProperty(options);
223
- case 8:
224
- contentProperty = _context3.sent;
225
- if (!(((_contentProperty$data4 = contentProperty.data.confluence.updateValueBlogPostProperty.blogPostProperty) === null || _contentProperty$data4 === void 0 ? void 0 : _contentProperty$data4.key) === key)) {
226
- _context3.next = 13;
229
+ case 15:
230
+ updatePayload = _context3.sent;
231
+ updateResult = isBlogPageType(pageType) ? updatePayload.data.confluence.updateValueBlogPostProperty.blogPostProperty : updatePayload.data.confluence.updateValuePageProperty.pageProperty;
232
+ if (!((updateResult === null || updateResult === void 0 ? void 0 : updateResult.key) === key)) {
233
+ _context3.next = 21;
227
234
  break;
228
235
  }
229
- return _context3.abrupt("return", key);
230
- case 13:
231
- if (!(contentProperty.data.confluence.updateValueBlogPostProperty.blogPostProperty === null)) {
232
- _context3.next = 17;
236
+ return _context3.abrupt("return", {
237
+ resourceId: resourceId
238
+ });
239
+ case 21:
240
+ if (updateResult) {
241
+ _context3.next = 25;
233
242
  break;
234
243
  }
235
- return _context3.abrupt("return", this.createNewContentProperty(pageId, key, data, pageType));
236
- case 17:
237
- throw new Error('Failed to update blog post content property');
238
- case 18:
239
- _context3.next = 32;
244
+ return _context3.abrupt("return", this.createNewContentProperty(pageId, key, data, pageType).then(function () {
245
+ return {
246
+ resourceId: resourceId
247
+ };
248
+ }, function (error) {
249
+ return {
250
+ error: error
251
+ };
252
+ }));
253
+ case 25:
254
+ return _context3.abrupt("return", {
255
+ error: "Failed to update ".concat(pageType, " content property")
256
+ });
257
+ case 26:
258
+ _context3.next = 31;
240
259
  break;
241
- case 20:
242
- _context3.next = 22;
243
- return updateContentProperty(options);
244
- case 22:
245
- _contentProperty3 = _context3.sent;
246
- if (!(((_contentProperty3$dat = _contentProperty3.data.confluence.updateValuePageProperty.pageProperty) === null || _contentProperty3$dat === void 0 ? void 0 : _contentProperty3$dat.key) === key)) {
247
- _context3.next = 27;
248
- break;
249
- }
250
- return _context3.abrupt("return", key);
251
- case 27:
252
- if (!(_contentProperty3.data.confluence.updateValuePageProperty.pageProperty === null)) {
253
- _context3.next = 31;
254
- break;
255
- }
256
- return _context3.abrupt("return", this.createNewContentProperty(pageId, key, data, pageType));
260
+ case 28:
261
+ _context3.prev = 28;
262
+ _context3.t1 = _context3["catch"](9);
263
+ return _context3.abrupt("return", {
264
+ error: "Failed to write ".concat(pageType)
265
+ });
257
266
  case 31:
258
- throw new Error('Failed to update content property');
259
- case 32:
260
- _context3.next = 36;
261
- break;
262
- case 34:
263
- // Create new content property
264
- _key = getContentPropertyKey(this.config.contentPropertyKey, data.blockInstanceId);
265
- return _context3.abrupt("return", this.createNewContentProperty(pageId, _key, data, pageType));
266
- case 36:
267
267
  case "end":
268
268
  return _context3.stop();
269
269
  }
270
- }, _callee3, this);
270
+ }, _callee3, this, [[1, 5], [9, 28]]);
271
271
  }));
272
272
  function writeData(_x6) {
273
273
  return _writeData.apply(this, arguments);
@@ -278,11 +278,25 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
278
278
  key: "deleteData",
279
279
  value: function () {
280
280
  var _deleteData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(resourceId) {
281
- var _getPageIdAndTypeFrom3, pageId, pageType, localId, key, options, deletePayload, deleteResult;
281
+ var deletePayload, deleteResult, match, _match2, pageId, pageType, localId, key, options, _stringifyError;
282
282
  return _regeneratorRuntime.wrap(function _callee4$(_context4) {
283
283
  while (1) switch (_context4.prev = _context4.next) {
284
284
  case 0:
285
- _getPageIdAndTypeFrom3 = getPageIdAndTypeFromAri(resourceId), pageId = _getPageIdAndTypeFrom3.id, pageType = _getPageIdAndTypeFrom3.type;
285
+ _context4.prev = 0;
286
+ match = getPageIdAndTypeFromAri(resourceId);
287
+ _context4.next = 7;
288
+ break;
289
+ case 4:
290
+ _context4.prev = 4;
291
+ _context4.t0 = _context4["catch"](0);
292
+ return _context4.abrupt("return", {
293
+ resourceId: resourceId,
294
+ success: false,
295
+ error: stringifyError(_context4.t0)
296
+ });
297
+ case 7:
298
+ _match2 = match, pageId = _match2.id, pageType = _match2.type;
299
+ _context4.prev = 8;
286
300
  localId = getLocalIdFromAri(resourceId);
287
301
  key = getContentPropertyKey(this.config.contentPropertyKey, localId);
288
302
  options = {
@@ -291,33 +305,32 @@ var ConfluenceADFWriteProvider = /*#__PURE__*/function () {
291
305
  cloudId: this.config.cloudId,
292
306
  pageType: pageType
293
307
  };
294
- _context4.prev = 4;
295
- _context4.next = 7;
308
+ _context4.next = 14;
296
309
  return deleteContentProperty(options);
297
- case 7:
310
+ case 14:
298
311
  deletePayload = _context4.sent;
299
312
  deleteResult = isBlogPageType(pageType) ? deletePayload.data.confluence.deleteBlogPostProperty : deletePayload.data.confluence.deletePageProperty;
300
- _context4.next = 14;
313
+ _context4.next = 21;
301
314
  break;
302
- case 11:
303
- _context4.prev = 11;
304
- _context4.t0 = _context4["catch"](4);
315
+ case 18:
316
+ _context4.prev = 18;
317
+ _context4.t1 = _context4["catch"](8);
305
318
  return _context4.abrupt("return", {
306
319
  resourceId: resourceId,
307
320
  success: false,
308
- error: "Fail to delete ".concat(pageType, " content property")
321
+ error: (_stringifyError = stringifyError(_context4.t1)) !== null && _stringifyError !== void 0 ? _stringifyError : "Fail to delete ".concat(pageType, " content property")
309
322
  });
310
- case 14:
323
+ case 21:
311
324
  return _context4.abrupt("return", {
312
325
  resourceId: resourceId,
313
326
  success: deleteResult.success,
314
327
  error: deleteResult.errors.join()
315
328
  });
316
- case 15:
329
+ case 22:
317
330
  case "end":
318
331
  return _context4.stop();
319
332
  }
320
- }, _callee4, this, [[4, 11]]);
333
+ }, _callee4, this, [[0, 4], [8, 18]]);
321
334
  }));
322
335
  function deleteData(_x7) {
323
336
  return _deleteData.apply(this, arguments);
@@ -66,39 +66,63 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
66
66
  * @param nodes
67
67
  * @param data
68
68
  *
69
- * @returns the resource ids of the nodes that were written
69
+ * @returns Array of {resourceId?: string, error?: string}.
70
+ * resourceId: resource id of the node if write successfully , error: reason for when write failed
70
71
  */
71
72
  }, {
72
73
  key: "writeNodesData",
73
- value: function writeNodesData(nodes, data) {
74
- var _this3 = this;
75
- var resourceIds = [];
76
- nodes.forEach(function (_node, index) {
77
- if (!data[index].content) {
78
- resourceIds.push(Promise.reject('No Synced Block content to write'));
79
- return;
80
- }
81
- var resourceId = _this3.writeProvider.writeData(data[index]);
82
- resourceIds.push(resourceId);
83
- });
84
- return Promise.all(resourceIds);
85
- }
74
+ value: (function () {
75
+ var _writeNodesData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(nodes, data) {
76
+ var _this3 = this;
77
+ var results;
78
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
79
+ while (1) switch (_context.prev = _context.next) {
80
+ case 0:
81
+ _context.next = 2;
82
+ return Promise.allSettled(nodes.map(function (_node, index) {
83
+ if (!data[index].content) {
84
+ return Promise.reject('No Synced Block content to write');
85
+ }
86
+ return _this3.writeProvider.writeData(data[index]);
87
+ }));
88
+ case 2:
89
+ results = _context.sent;
90
+ return _context.abrupt("return", results.map(function (result) {
91
+ if (result.status === 'fulfilled') {
92
+ return result.value;
93
+ } else {
94
+ return {
95
+ error: result.reason
96
+ };
97
+ }
98
+ }));
99
+ case 4:
100
+ case "end":
101
+ return _context.stop();
102
+ }
103
+ }, _callee);
104
+ }));
105
+ function writeNodesData(_x, _x2) {
106
+ return _writeNodesData.apply(this, arguments);
107
+ }
108
+ return writeNodesData;
109
+ }())
86
110
  }, {
87
111
  key: "deleteNodesData",
88
112
  value: function () {
89
- var _deleteNodesData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(resourceIds) {
113
+ var _deleteNodesData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(resourceIds) {
90
114
  var _this4 = this;
91
115
  var results;
92
- return _regeneratorRuntime.wrap(function _callee$(_context) {
93
- while (1) switch (_context.prev = _context.next) {
116
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
117
+ while (1) switch (_context2.prev = _context2.next) {
94
118
  case 0:
95
- _context.next = 2;
119
+ _context2.next = 2;
96
120
  return Promise.allSettled(resourceIds.map(function (resourceId) {
97
121
  return _this4.writeProvider.deleteData(resourceId);
98
122
  }));
99
123
  case 2:
100
- results = _context.sent;
101
- return _context.abrupt("return", results.map(function (result, index) {
124
+ results = _context2.sent;
125
+ return _context2.abrupt("return", results.map(function (result, index) {
102
126
  if (result.status === 'fulfilled') {
103
127
  return result.value;
104
128
  } else {
@@ -111,11 +135,11 @@ export var SyncBlockProvider = /*#__PURE__*/function (_SyncBlockDataProvide) {
111
135
  }));
112
136
  case 4:
113
137
  case "end":
114
- return _context.stop();
138
+ return _context2.stop();
115
139
  }
116
- }, _callee);
140
+ }, _callee2);
117
141
  }));
118
- function deleteNodesData(_x) {
142
+ function deleteNodesData(_x3) {
119
143
  return _deleteNodesData.apply(this, arguments);
120
144
  }
121
145
  return deleteNodesData;
@@ -153,12 +177,12 @@ export var useMemoizedSyncedBlockProvider = function useMemoizedSyncedBlockProvi
153
177
  }, [fetchProvider, writeProvider, sourceId]);
154
178
  };
155
179
  var fetchURLandTitlefromARI = /*#__PURE__*/function () {
156
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(ari, sourceLocalId) {
180
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(ari, sourceLocalId) {
157
181
  var response, _payload$data, _payload$data2, payload, url, title;
158
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
159
- while (1) switch (_context2.prev = _context2.next) {
182
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
183
+ while (1) switch (_context3.prev = _context3.next) {
160
184
  case 0:
161
- _context2.next = 2;
185
+ _context3.next = 2;
162
186
  return fetch('/gateway/api/object-resolver/resolve/ari', {
163
187
  method: 'POST',
164
188
  headers: {
@@ -170,18 +194,18 @@ var fetchURLandTitlefromARI = /*#__PURE__*/function () {
170
194
  })
171
195
  });
172
196
  case 2:
173
- response = _context2.sent;
197
+ response = _context3.sent;
174
198
  if (!response.ok) {
175
- _context2.next = 12;
199
+ _context3.next = 12;
176
200
  break;
177
201
  }
178
- _context2.next = 6;
202
+ _context3.next = 6;
179
203
  return response.json();
180
204
  case 6:
181
- payload = _context2.sent;
205
+ payload = _context3.sent;
182
206
  url = payload === null || payload === void 0 || (_payload$data = payload.data) === null || _payload$data === void 0 ? void 0 : _payload$data.url;
183
207
  title = payload === null || payload === void 0 || (_payload$data2 = payload.data) === null || _payload$data2 === void 0 ? void 0 : _payload$data2.name;
184
- return _context2.abrupt("return", {
208
+ return _context3.abrupt("return", {
185
209
  url: typeof url === 'string' ? sourceLocalId ? url + "?block=".concat(sourceLocalId) : url : undefined,
186
210
  title: typeof title === 'string' ? title : undefined
187
211
  });
@@ -189,14 +213,14 @@ var fetchURLandTitlefromARI = /*#__PURE__*/function () {
189
213
  //eslint-disable-next-line no-console
190
214
  console.error('Failed to fetch URL and title from ARI', response.statusText);
191
215
  case 13:
192
- return _context2.abrupt("return", undefined);
216
+ return _context3.abrupt("return", undefined);
193
217
  case 14:
194
218
  case "end":
195
- return _context2.stop();
219
+ return _context3.stop();
196
220
  }
197
- }, _callee2);
221
+ }, _callee3);
198
222
  }));
199
- return function fetchURLandTitlefromARI(_x2, _x3) {
223
+ return function fetchURLandTitlefromARI(_x4, _x5) {
200
224
  return _ref.apply(this, arguments);
201
225
  };
202
226
  }();
@@ -9,8 +9,8 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
9
9
  function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
10
10
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
11
11
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
12
- import { createSyncBlockNode } from '../utils/createSyncBlock';
13
12
  import { resolveSyncBlockInstance } from '../utils/resolveSyncBlockInstance';
13
+ import { createSyncBlockNode } from '../utils/utils';
14
14
  export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
15
15
  function ReferenceSyncBlockStoreManager(dataProvider) {
16
16
  _classCallCheck(this, ReferenceSyncBlockStoreManager);
@@ -5,7 +5,7 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
5
5
  import uuid from 'uuid';
6
6
  import { rebaseTransaction as _rebaseTransaction } from '../common/rebase-transaction';
7
7
  import { resourceIdFromSourceAndLocalId } from '../utils/ari';
8
- import { convertSyncBlockPMNodeToSyncBlockData } from '../utils/utils';
8
+ import { convertSyncBlockPMNodeToSyncBlockData, createBodiedSyncBlockNode as _createBodiedSyncBlockNode } from '../utils/utils';
9
9
  export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
10
10
  function SourceSyncBlockStoreManager(dataProvider) {
11
11
  _classCallCheck(this, SourceSyncBlockStoreManager);
@@ -40,7 +40,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
40
40
  key: "flushBodiedSyncBlocks",
41
41
  value: (function () {
42
42
  var _flushBodiedSyncBlocks = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
43
- var bodiedSyncBlockNodes, bodiedSyncBlockData, resourceIds;
43
+ var bodiedSyncBlockNodes, bodiedSyncBlockData, writeResults;
44
44
  return _regeneratorRuntime.wrap(function _callee$(_context) {
45
45
  while (1) switch (_context.prev = _context.next) {
46
46
  case 0:
@@ -72,9 +72,9 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
72
72
  _context.next = 10;
73
73
  return this.dataProvider.writeNodesData(bodiedSyncBlockNodes, bodiedSyncBlockData);
74
74
  case 10:
75
- resourceIds = _context.sent;
76
- return _context.abrupt("return", resourceIds.every(function (resourceId) {
77
- return resourceId !== undefined;
75
+ writeResults = _context.sent;
76
+ return _context.abrupt("return", writeResults.every(function (result) {
77
+ return result.resourceId !== undefined;
78
78
  }));
79
79
  case 14:
80
80
  _context.prev = 14;
@@ -96,6 +96,35 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
96
96
  value: function setEditorView(editorView) {
97
97
  this.editorView = editorView;
98
98
  }
99
+ }, {
100
+ key: "registerPendingCreation",
101
+ value: function registerPendingCreation(resourceId) {
102
+ this.pendingResourceId = resourceId;
103
+ }
104
+ }, {
105
+ key: "registerCreationCallback",
106
+ value: function registerCreationCallback(callback) {
107
+ this.creationCallback = callback;
108
+ }
109
+
110
+ /**
111
+ * Fires callback to insert node (if creation is successful) and clears pending creation data
112
+ * @param success
113
+ */
114
+ }, {
115
+ key: "commitPendingCreation",
116
+ value: function commitPendingCreation(success) {
117
+ if (success && this.creationCallback) {
118
+ this.creationCallback();
119
+ }
120
+ this.pendingResourceId = undefined;
121
+ this.creationCallback = undefined;
122
+ }
123
+ }, {
124
+ key: "hasPendingCreation",
125
+ value: function hasPendingCreation() {
126
+ return !!this.pendingResourceId;
127
+ }
99
128
  }, {
100
129
  key: "registerConfirmationCallback",
101
130
  value: function registerConfirmationCallback(callback) {
@@ -111,31 +140,63 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
111
140
  return !!this.confirmationCallback;
112
141
  }
113
142
  }, {
114
- key: "createSyncBlockNode",
115
- value: function createSyncBlockNode() {
143
+ key: "generateBodiedSyncBlockAttrs",
144
+ value: function generateBodiedSyncBlockAttrs() {
116
145
  var _this$dataProvider;
117
- var blockInstanceId = uuid();
146
+ var localId = uuid();
118
147
  var sourceId = (_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.getSourceId();
119
148
  if (!sourceId) {
120
149
  throw new Error('Provider of sync block plugin is not set');
121
150
  }
122
151
 
123
152
  // This should be generated by the data provider implementation as it differs between data providers
124
- var resourceId = resourceIdFromSourceAndLocalId(sourceId, blockInstanceId);
125
- var syncBlockNode = {
126
- attrs: {
127
- resourceId: resourceId,
128
- localId: blockInstanceId
129
- },
130
- type: 'bodiedSyncBlock'
153
+ var resourceId = resourceIdFromSourceAndLocalId(sourceId, localId);
154
+ return {
155
+ resourceId: resourceId,
156
+ localId: localId
131
157
  };
132
- return syncBlockNode;
158
+ }
159
+ }, {
160
+ key: "createBodiedSyncBlockNode",
161
+ value: function createBodiedSyncBlockNode(attrs) {
162
+ var _this2 = this;
163
+ try {
164
+ if (!this.dataProvider) {
165
+ throw new Error('Data provider not set');
166
+ }
167
+ var resourceId = attrs.resourceId,
168
+ blockInstanceId = attrs.localId;
169
+ this.dataProvider.writeNodesData([_createBodiedSyncBlockNode(blockInstanceId, resourceId)], [{
170
+ content: [],
171
+ blockInstanceId: blockInstanceId,
172
+ resourceId: resourceId
173
+ }]).then(function (results) {
174
+ results.forEach(function (result) {
175
+ var resourceId = result.resourceId;
176
+ if (resourceId) {
177
+ _this2.commitPendingCreation(true);
178
+ } else {
179
+ _this2.commitPendingCreation(false);
180
+ // TODO: EDITOR-1921 - add error analytics
181
+ }
182
+ });
183
+ }).catch(function (_reason) {
184
+ _this2.commitPendingCreation(false);
185
+ // TODO: EDITOR-1921 - add error analytics
186
+ });
187
+ this.registerPendingCreation(resourceId);
188
+ } catch (error) {
189
+ if (this.hasPendingCreation()) {
190
+ this.commitPendingCreation(false);
191
+ }
192
+ // TODO: EDITOR-1921 - add error analytics
193
+ }
133
194
  }
134
195
  }, {
135
196
  key: "deleteSyncBlocksWithConfirmation",
136
197
  value: function () {
137
198
  var _deleteSyncBlocksWithConfirmation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(tr, syncBlockIds) {
138
- var _this2 = this;
199
+ var _this3 = this;
139
200
  var confirmed, _this$editorView, results;
140
201
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
141
202
  while (1) switch (_context2.prev = _context2.next) {
@@ -170,7 +231,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
170
231
  results.forEach(function (result) {
171
232
  if (result.success) {
172
233
  // Only delete when it's deleted successfully in backend
173
- _this2.syncBlockCache.delete(result.resourceId);
234
+ _this3.syncBlockCache.delete(result.resourceId);
174
235
  } else {
175
236
  // TODO: EDITOR-1921 - add error analytics with result.error
176
237
  }