@atlaskit/editor-synced-block-provider 2.7.2 → 2.7.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atlaskit/editor-synced-block-provider
2
2
 
3
+ ## 2.7.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [`2ccc83663f44b`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/2ccc83663f44b) -
8
+ [EDITOR-2744] Fix deleting source sync block re-creates the node in live page
9
+ - Updated dependencies
10
+
3
11
  ## 2.7.2
4
12
 
5
13
  ### Patch Changes
@@ -11,6 +11,7 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
11
11
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
12
12
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
13
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
14
+ var _types = require("../common/types");
14
15
  var _resolveSyncBlockInstance = require("../utils/resolveSyncBlockInstance");
15
16
  var _utils = require("../utils/utils");
16
17
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
@@ -146,7 +147,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
146
147
  value: function () {
147
148
  var _fetchSyncBlocksData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(syncBlockNodes) {
148
149
  var _this2 = this;
149
- var data, resolvedData;
150
+ var nodesToFetch, blocksWithNotFoundError, data, resolvedData;
150
151
  return _regenerator.default.wrap(function _callee2$(_context3) {
151
152
  while (1) switch (_context3.prev = _context3.next) {
152
153
  case 0:
@@ -156,22 +157,37 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
156
157
  }
157
158
  throw new Error('Data provider not set');
158
159
  case 2:
159
- _context3.next = 4;
160
- return this.dataProvider.fetchNodesData(syncBlockNodes);
161
- case 4:
160
+ // Don't fetch for not_found error since the source is already deleted
161
+ nodesToFetch = [], blocksWithNotFoundError = [];
162
+ syncBlockNodes.forEach(function (node) {
163
+ var existingSyncBlock = _this2.getFromCache(node.attrs.resourceId);
164
+ if ((existingSyncBlock === null || existingSyncBlock === void 0 ? void 0 : existingSyncBlock.error) === _types.SyncBlockError.NotFound) {
165
+ blocksWithNotFoundError.push(existingSyncBlock);
166
+ } else {
167
+ nodesToFetch.push(node);
168
+ }
169
+ });
170
+ _context3.next = 6;
171
+ return this.dataProvider.fetchNodesData(nodesToFetch);
172
+ case 6:
162
173
  data = _context3.sent;
163
174
  if (data) {
164
- _context3.next = 7;
175
+ _context3.next = 9;
165
176
  break;
166
177
  }
167
178
  throw new Error('Failed to fetch sync block node data');
168
- case 7:
179
+ case 9:
169
180
  resolvedData = [];
170
181
  data.forEach(function (syncBlockInstance) {
171
182
  var _resolvedSyncBlockIns, _resolvedSyncBlockIns2;
172
183
  if (!syncBlockInstance.resourceId) {
173
184
  return;
174
185
  }
186
+ if (syncBlockInstance.error) {
187
+ _this2.updateCache(syncBlockInstance);
188
+ resolvedData.push(syncBlockInstance);
189
+ return;
190
+ }
175
191
  var existingSyncBlock = _this2.getFromCache(syncBlockInstance.resourceId);
176
192
  var resolvedSyncBlockInstance = existingSyncBlock ? (0, _resolveSyncBlockInstance.resolveSyncBlockInstance)(existingSyncBlock, syncBlockInstance) : syncBlockInstance;
177
193
  _this2.updateCache(resolvedSyncBlockInstance);
@@ -182,8 +198,8 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
182
198
  _this2.retrieveSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
183
199
  }
184
200
  });
185
- return _context3.abrupt("return", resolvedData);
186
- case 10:
201
+ return _context3.abrupt("return", [].concat(resolvedData, blocksWithNotFoundError));
202
+ case 12:
187
203
  case "end":
188
204
  return _context3.stop();
189
205
  }
@@ -9,13 +9,22 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"))
9
9
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
10
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
11
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
12
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
12
13
  var _uuid = _interopRequireDefault(require("uuid"));
13
14
  var _rebaseTransaction2 = require("../common/rebase-transaction");
14
15
  var _ari = require("../utils/ari");
15
16
  var _utils = require("../utils/utils");
17
+ // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
16
18
  var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PURE__*/function () {
17
19
  function SourceSyncBlockStoreManager(dataProvider) {
20
+ var _this = this;
18
21
  (0, _classCallCheck2.default)(this, SourceSyncBlockStoreManager);
22
+ (0, _defineProperty2.default)(this, "setPendingDeletion", function (Ids, value) {
23
+ var syncBlock = _this.syncBlockCache.get(Ids.resourceId);
24
+ if (syncBlock) {
25
+ syncBlock.pendingDeletion = value;
26
+ }
27
+ });
19
28
  this.dataProvider = dataProvider;
20
29
  this.syncBlockCache = new Map();
21
30
  }
@@ -34,7 +43,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
34
43
  throw new Error('Local ID or resource ID is not set');
35
44
  }
36
45
  var syncBlockData = (0, _utils.convertSyncBlockPMNodeToSyncBlockData)(syncBlockNode);
37
- this.syncBlockCache.set(localId, syncBlockData);
46
+ this.syncBlockCache.set(resourceId, syncBlockData);
38
47
  return true;
39
48
  }
40
49
 
@@ -61,14 +70,17 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
61
70
  bodiedSyncBlockNodes = [];
62
71
  bodiedSyncBlockData = [];
63
72
  Array.from(this.syncBlockCache.values()).forEach(function (syncBlockData) {
64
- bodiedSyncBlockNodes.push({
65
- type: 'bodiedSyncBlock',
66
- attrs: {
67
- localId: syncBlockData.blockInstanceId,
68
- resourceId: syncBlockData.resourceId
69
- }
70
- });
71
- bodiedSyncBlockData.push(syncBlockData);
73
+ // Don't flush nodes that are waiting to be deleted to avoid nodes being re-created
74
+ if (!syncBlockData.pendingDeletion) {
75
+ bodiedSyncBlockNodes.push({
76
+ type: 'bodiedSyncBlock',
77
+ attrs: {
78
+ localId: syncBlockData.blockInstanceId,
79
+ resourceId: syncBlockData.resourceId
80
+ }
81
+ });
82
+ bodiedSyncBlockData.push(syncBlockData);
83
+ }
72
84
  });
73
85
  if (!(bodiedSyncBlockNodes.length === 0)) {
74
86
  _context.next = 8;
@@ -135,10 +147,10 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
135
147
  }, {
136
148
  key: "registerConfirmationCallback",
137
149
  value: function registerConfirmationCallback(callback) {
138
- var _this = this;
150
+ var _this2 = this;
139
151
  this.confirmationCallback = callback;
140
152
  return function () {
141
- _this.confirmationCallback = undefined;
153
+ _this2.confirmationCallback = undefined;
142
154
  };
143
155
  }
144
156
  }, {
@@ -150,6 +162,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
150
162
  key: "generateBodiedSyncBlockAttrs",
151
163
  value: function generateBodiedSyncBlockAttrs() {
152
164
  var _this$dataProvider;
165
+ // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
153
166
  var localId = (0, _uuid.default)();
154
167
  var sourceId = (_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.getSourceId();
155
168
  if (!sourceId) {
@@ -166,7 +179,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
166
179
  }, {
167
180
  key: "createBodiedSyncBlockNode",
168
181
  value: function createBodiedSyncBlockNode(attrs) {
169
- var _this2 = this;
182
+ var _this3 = this;
170
183
  try {
171
184
  if (!this.dataProvider) {
172
185
  throw new Error('Data provider not set');
@@ -181,14 +194,14 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
181
194
  results.forEach(function (result) {
182
195
  var resourceId = result.resourceId;
183
196
  if (resourceId) {
184
- _this2.commitPendingCreation(true);
197
+ _this3.commitPendingCreation(true);
185
198
  } else {
186
- _this2.commitPendingCreation(false);
199
+ _this3.commitPendingCreation(false);
187
200
  // TODO: EDITOR-1921 - add error analytics
188
201
  }
189
202
  });
190
203
  }).catch(function (_reason) {
191
- _this2.commitPendingCreation(false);
204
+ _this3.commitPendingCreation(false);
192
205
  // TODO: EDITOR-1921 - add error analytics
193
206
  });
194
207
  this.registerPendingCreation(resourceId);
@@ -203,13 +216,13 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
203
216
  key: "deleteSyncBlocksWithConfirmation",
204
217
  value: function () {
205
218
  var _deleteSyncBlocksWithConfirmation = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(tr, syncBlockIds) {
206
- var _this3 = this;
207
- var confirmed, _this$editorView, results;
219
+ var _this4 = this;
220
+ var confirmed, _this$editorView, results, callback;
208
221
  return _regenerator.default.wrap(function _callee2$(_context2) {
209
222
  while (1) switch (_context2.prev = _context2.next) {
210
223
  case 0:
211
224
  if (!this.confirmationCallback) {
212
- _context2.next = 19;
225
+ _context2.next = 22;
213
226
  break;
214
227
  }
215
228
  this.confirmationTransaction = tr;
@@ -218,7 +231,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
218
231
  case 4:
219
232
  confirmed = _context2.sent;
220
233
  if (!confirmed) {
221
- _context2.next = 18;
234
+ _context2.next = 21;
222
235
  break;
223
236
  }
224
237
  (_this$editorView = this.editorView) === null || _this$editorView === void 0 || _this$editorView.dispatch(this.confirmationTransaction.setMeta('isConfirmedSyncBlockDeletion', true));
@@ -229,32 +242,44 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
229
242
  }
230
243
  throw new Error('Data provider not set');
231
244
  case 10:
232
- _context2.next = 12;
245
+ syncBlockIds.forEach(function (Ids) {
246
+ _this4.setPendingDeletion(Ids, true);
247
+ });
248
+ _context2.next = 13;
233
249
  return this.dataProvider.deleteNodesData(syncBlockIds.map(function (attrs) {
234
250
  return attrs.resourceId;
235
251
  }));
236
- case 12:
252
+ case 13:
237
253
  results = _context2.sent;
238
- results.forEach(function (result) {
239
- if (result.success) {
240
- // Only delete when it's deleted successfully in backend
241
- _this3.syncBlockCache.delete(result.resourceId);
242
- } else {
243
- // TODO: EDITOR-1921 - add error analytics with result.error
244
- }
245
- });
246
- _context2.next = 18;
254
+ if (results.every(function (result) {
255
+ return result.success;
256
+ })) {
257
+ callback = function callback(Ids) {
258
+ return _this4.syncBlockCache.delete(Ids.resourceId);
259
+ };
260
+ } else {
261
+ callback = function callback(Ids) {
262
+ _this4.setPendingDeletion(Ids, false);
263
+ };
264
+ // TODO: EDITOR-1921 - add error analytics
265
+ }
266
+ syncBlockIds.forEach(callback);
267
+ _context2.next = 21;
247
268
  break;
248
- case 16:
249
- _context2.prev = 16;
250
- _context2.t0 = _context2["catch"](7);
251
269
  case 18:
270
+ _context2.prev = 18;
271
+ _context2.t0 = _context2["catch"](7);
272
+ syncBlockIds.forEach(function (Ids) {
273
+ _this4.setPendingDeletion(Ids, false);
274
+ });
275
+ // TODO: EDITOR-1921 - add error analytics
276
+ case 21:
252
277
  this.confirmationTransaction = undefined;
253
- case 19:
278
+ case 22:
254
279
  case "end":
255
280
  return _context2.stop();
256
281
  }
257
- }, _callee2, this, [[7, 16]]);
282
+ }, _callee2, this, [[7, 18]]);
258
283
  }));
259
284
  function deleteSyncBlocksWithConfirmation(_x, _x2) {
260
285
  return _deleteSyncBlocksWithConfirmation.apply(this, arguments);
@@ -1,4 +1,5 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import { SyncBlockError } from '../common/types';
2
3
  import { resolveSyncBlockInstance } from '../utils/resolveSyncBlockInstance';
3
4
  import { createSyncBlockNode } from '../utils/utils';
4
5
  export class ReferenceSyncBlockStoreManager {
@@ -67,7 +68,19 @@ export class ReferenceSyncBlockStoreManager {
67
68
  if (!this.dataProvider) {
68
69
  throw new Error('Data provider not set');
69
70
  }
70
- const data = await this.dataProvider.fetchNodesData(syncBlockNodes);
71
+
72
+ // Don't fetch for not_found error since the source is already deleted
73
+ const nodesToFetch = [],
74
+ blocksWithNotFoundError = [];
75
+ syncBlockNodes.forEach(node => {
76
+ const existingSyncBlock = this.getFromCache(node.attrs.resourceId);
77
+ if ((existingSyncBlock === null || existingSyncBlock === void 0 ? void 0 : existingSyncBlock.error) === SyncBlockError.NotFound) {
78
+ blocksWithNotFoundError.push(existingSyncBlock);
79
+ } else {
80
+ nodesToFetch.push(node);
81
+ }
82
+ });
83
+ const data = await this.dataProvider.fetchNodesData(nodesToFetch);
71
84
  if (!data) {
72
85
  throw new Error('Failed to fetch sync block node data');
73
86
  }
@@ -77,6 +90,11 @@ export class ReferenceSyncBlockStoreManager {
77
90
  if (!syncBlockInstance.resourceId) {
78
91
  return;
79
92
  }
93
+ if (syncBlockInstance.error) {
94
+ this.updateCache(syncBlockInstance);
95
+ resolvedData.push(syncBlockInstance);
96
+ return;
97
+ }
80
98
  const existingSyncBlock = this.getFromCache(syncBlockInstance.resourceId);
81
99
  const resolvedSyncBlockInstance = existingSyncBlock ? resolveSyncBlockInstance(existingSyncBlock, syncBlockInstance) : syncBlockInstance;
82
100
  this.updateCache(resolvedSyncBlockInstance);
@@ -87,7 +105,7 @@ export class ReferenceSyncBlockStoreManager {
87
105
  this.retrieveSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
88
106
  }
89
107
  });
90
- return resolvedData;
108
+ return [...resolvedData, ...blocksWithNotFoundError];
91
109
  }
92
110
  updateCache(syncBlock) {
93
111
  const {
@@ -1,9 +1,17 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
1
3
  import uuid from 'uuid';
2
4
  import { rebaseTransaction } from '../common/rebase-transaction';
3
5
  import { resourceIdFromSourceAndLocalId } from '../utils/ari';
4
6
  import { convertSyncBlockPMNodeToSyncBlockData, createBodiedSyncBlockNode } from '../utils/utils';
5
7
  export class SourceSyncBlockStoreManager {
6
8
  constructor(dataProvider) {
9
+ _defineProperty(this, "setPendingDeletion", (Ids, value) => {
10
+ const syncBlock = this.syncBlockCache.get(Ids.resourceId);
11
+ if (syncBlock) {
12
+ syncBlock.pendingDeletion = value;
13
+ }
14
+ });
7
15
  this.dataProvider = dataProvider;
8
16
  this.syncBlockCache = new Map();
9
17
  }
@@ -21,7 +29,7 @@ export class SourceSyncBlockStoreManager {
21
29
  throw new Error('Local ID or resource ID is not set');
22
30
  }
23
31
  const syncBlockData = convertSyncBlockPMNodeToSyncBlockData(syncBlockNode);
24
- this.syncBlockCache.set(localId, syncBlockData);
32
+ this.syncBlockCache.set(resourceId, syncBlockData);
25
33
  return true;
26
34
  }
27
35
 
@@ -38,14 +46,17 @@ export class SourceSyncBlockStoreManager {
38
46
  const bodiedSyncBlockNodes = [];
39
47
  const bodiedSyncBlockData = [];
40
48
  Array.from(this.syncBlockCache.values()).forEach(syncBlockData => {
41
- bodiedSyncBlockNodes.push({
42
- type: 'bodiedSyncBlock',
43
- attrs: {
44
- localId: syncBlockData.blockInstanceId,
45
- resourceId: syncBlockData.resourceId
46
- }
47
- });
48
- bodiedSyncBlockData.push(syncBlockData);
49
+ // Don't flush nodes that are waiting to be deleted to avoid nodes being re-created
50
+ if (!syncBlockData.pendingDeletion) {
51
+ bodiedSyncBlockNodes.push({
52
+ type: 'bodiedSyncBlock',
53
+ attrs: {
54
+ localId: syncBlockData.blockInstanceId,
55
+ resourceId: syncBlockData.resourceId
56
+ }
57
+ });
58
+ bodiedSyncBlockData.push(syncBlockData);
59
+ }
49
60
  });
50
61
  if (bodiedSyncBlockNodes.length === 0) {
51
62
  return Promise.resolve(true);
@@ -92,6 +103,7 @@ export class SourceSyncBlockStoreManager {
92
103
  }
93
104
  generateBodiedSyncBlockAttrs() {
94
105
  var _this$dataProvider;
106
+ // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
95
107
  const localId = uuid();
96
108
  const sourceId = (_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.getSourceId();
97
109
  if (!sourceId) {
@@ -151,16 +163,24 @@ export class SourceSyncBlockStoreManager {
151
163
  if (!this.dataProvider) {
152
164
  throw new Error('Data provider not set');
153
165
  }
154
- const results = await this.dataProvider.deleteNodesData(syncBlockIds.map(attrs => attrs.resourceId));
155
- results.forEach(result => {
156
- if (result.success) {
157
- // Only delete when it's deleted successfully in backend
158
- this.syncBlockCache.delete(result.resourceId);
159
- } else {
160
- // TODO: EDITOR-1921 - add error analytics with result.error
161
- }
166
+ syncBlockIds.forEach(Ids => {
167
+ this.setPendingDeletion(Ids, true);
162
168
  });
169
+ const results = await this.dataProvider.deleteNodesData(syncBlockIds.map(attrs => attrs.resourceId));
170
+ let callback;
171
+ if (results.every(result => result.success)) {
172
+ callback = Ids => this.syncBlockCache.delete(Ids.resourceId);
173
+ } else {
174
+ callback = Ids => {
175
+ this.setPendingDeletion(Ids, false);
176
+ };
177
+ // TODO: EDITOR-1921 - add error analytics
178
+ }
179
+ syncBlockIds.forEach(callback);
163
180
  } catch (_error) {
181
+ syncBlockIds.forEach(Ids => {
182
+ this.setPendingDeletion(Ids, false);
183
+ });
164
184
  // TODO: EDITOR-1921 - add error analytics
165
185
  }
166
186
  }
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable require-unicode-regexp */
2
2
 
3
- import { getPageIdAndTypeFromAri } from "./ari";
4
- import { isBlogPageType } from "./utils";
3
+ import { getPageIdAndTypeFromAri } from './ari';
4
+ import { isBlogPageType } from './utils';
5
5
  const COMMON_HEADERS = {
6
6
  'Content-Type': 'application/json',
7
7
  Accept: 'application/json'
@@ -9,6 +9,7 @@ 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 { SyncBlockError } from '../common/types';
12
13
  import { resolveSyncBlockInstance } from '../utils/resolveSyncBlockInstance';
13
14
  import { createSyncBlockNode } from '../utils/utils';
14
15
  export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
@@ -139,7 +140,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
139
140
  value: function () {
140
141
  var _fetchSyncBlocksData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(syncBlockNodes) {
141
142
  var _this2 = this;
142
- var data, resolvedData;
143
+ var nodesToFetch, blocksWithNotFoundError, data, resolvedData;
143
144
  return _regeneratorRuntime.wrap(function _callee2$(_context3) {
144
145
  while (1) switch (_context3.prev = _context3.next) {
145
146
  case 0:
@@ -149,22 +150,37 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
149
150
  }
150
151
  throw new Error('Data provider not set');
151
152
  case 2:
152
- _context3.next = 4;
153
- return this.dataProvider.fetchNodesData(syncBlockNodes);
154
- case 4:
153
+ // Don't fetch for not_found error since the source is already deleted
154
+ nodesToFetch = [], blocksWithNotFoundError = [];
155
+ syncBlockNodes.forEach(function (node) {
156
+ var existingSyncBlock = _this2.getFromCache(node.attrs.resourceId);
157
+ if ((existingSyncBlock === null || existingSyncBlock === void 0 ? void 0 : existingSyncBlock.error) === SyncBlockError.NotFound) {
158
+ blocksWithNotFoundError.push(existingSyncBlock);
159
+ } else {
160
+ nodesToFetch.push(node);
161
+ }
162
+ });
163
+ _context3.next = 6;
164
+ return this.dataProvider.fetchNodesData(nodesToFetch);
165
+ case 6:
155
166
  data = _context3.sent;
156
167
  if (data) {
157
- _context3.next = 7;
168
+ _context3.next = 9;
158
169
  break;
159
170
  }
160
171
  throw new Error('Failed to fetch sync block node data');
161
- case 7:
172
+ case 9:
162
173
  resolvedData = [];
163
174
  data.forEach(function (syncBlockInstance) {
164
175
  var _resolvedSyncBlockIns, _resolvedSyncBlockIns2;
165
176
  if (!syncBlockInstance.resourceId) {
166
177
  return;
167
178
  }
179
+ if (syncBlockInstance.error) {
180
+ _this2.updateCache(syncBlockInstance);
181
+ resolvedData.push(syncBlockInstance);
182
+ return;
183
+ }
168
184
  var existingSyncBlock = _this2.getFromCache(syncBlockInstance.resourceId);
169
185
  var resolvedSyncBlockInstance = existingSyncBlock ? resolveSyncBlockInstance(existingSyncBlock, syncBlockInstance) : syncBlockInstance;
170
186
  _this2.updateCache(resolvedSyncBlockInstance);
@@ -175,8 +191,8 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
175
191
  _this2.retrieveSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
176
192
  }
177
193
  });
178
- return _context3.abrupt("return", resolvedData);
179
- case 10:
194
+ return _context3.abrupt("return", [].concat(resolvedData, blocksWithNotFoundError));
195
+ case 12:
180
196
  case "end":
181
197
  return _context3.stop();
182
198
  }
@@ -1,14 +1,23 @@
1
1
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
2
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
3
  import _createClass from "@babel/runtime/helpers/createClass";
4
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
5
  import _regeneratorRuntime from "@babel/runtime/regenerator";
6
+ // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
5
7
  import uuid from 'uuid';
6
8
  import { rebaseTransaction as _rebaseTransaction } from '../common/rebase-transaction';
7
9
  import { resourceIdFromSourceAndLocalId } from '../utils/ari';
8
10
  import { convertSyncBlockPMNodeToSyncBlockData, createBodiedSyncBlockNode as _createBodiedSyncBlockNode } from '../utils/utils';
9
11
  export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
10
12
  function SourceSyncBlockStoreManager(dataProvider) {
13
+ var _this = this;
11
14
  _classCallCheck(this, SourceSyncBlockStoreManager);
15
+ _defineProperty(this, "setPendingDeletion", function (Ids, value) {
16
+ var syncBlock = _this.syncBlockCache.get(Ids.resourceId);
17
+ if (syncBlock) {
18
+ syncBlock.pendingDeletion = value;
19
+ }
20
+ });
12
21
  this.dataProvider = dataProvider;
13
22
  this.syncBlockCache = new Map();
14
23
  }
@@ -27,7 +36,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
27
36
  throw new Error('Local ID or resource ID is not set');
28
37
  }
29
38
  var syncBlockData = convertSyncBlockPMNodeToSyncBlockData(syncBlockNode);
30
- this.syncBlockCache.set(localId, syncBlockData);
39
+ this.syncBlockCache.set(resourceId, syncBlockData);
31
40
  return true;
32
41
  }
33
42
 
@@ -54,14 +63,17 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
54
63
  bodiedSyncBlockNodes = [];
55
64
  bodiedSyncBlockData = [];
56
65
  Array.from(this.syncBlockCache.values()).forEach(function (syncBlockData) {
57
- bodiedSyncBlockNodes.push({
58
- type: 'bodiedSyncBlock',
59
- attrs: {
60
- localId: syncBlockData.blockInstanceId,
61
- resourceId: syncBlockData.resourceId
62
- }
63
- });
64
- bodiedSyncBlockData.push(syncBlockData);
66
+ // Don't flush nodes that are waiting to be deleted to avoid nodes being re-created
67
+ if (!syncBlockData.pendingDeletion) {
68
+ bodiedSyncBlockNodes.push({
69
+ type: 'bodiedSyncBlock',
70
+ attrs: {
71
+ localId: syncBlockData.blockInstanceId,
72
+ resourceId: syncBlockData.resourceId
73
+ }
74
+ });
75
+ bodiedSyncBlockData.push(syncBlockData);
76
+ }
65
77
  });
66
78
  if (!(bodiedSyncBlockNodes.length === 0)) {
67
79
  _context.next = 8;
@@ -128,10 +140,10 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
128
140
  }, {
129
141
  key: "registerConfirmationCallback",
130
142
  value: function registerConfirmationCallback(callback) {
131
- var _this = this;
143
+ var _this2 = this;
132
144
  this.confirmationCallback = callback;
133
145
  return function () {
134
- _this.confirmationCallback = undefined;
146
+ _this2.confirmationCallback = undefined;
135
147
  };
136
148
  }
137
149
  }, {
@@ -143,6 +155,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
143
155
  key: "generateBodiedSyncBlockAttrs",
144
156
  value: function generateBodiedSyncBlockAttrs() {
145
157
  var _this$dataProvider;
158
+ // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
146
159
  var localId = uuid();
147
160
  var sourceId = (_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.getSourceId();
148
161
  if (!sourceId) {
@@ -159,7 +172,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
159
172
  }, {
160
173
  key: "createBodiedSyncBlockNode",
161
174
  value: function createBodiedSyncBlockNode(attrs) {
162
- var _this2 = this;
175
+ var _this3 = this;
163
176
  try {
164
177
  if (!this.dataProvider) {
165
178
  throw new Error('Data provider not set');
@@ -174,14 +187,14 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
174
187
  results.forEach(function (result) {
175
188
  var resourceId = result.resourceId;
176
189
  if (resourceId) {
177
- _this2.commitPendingCreation(true);
190
+ _this3.commitPendingCreation(true);
178
191
  } else {
179
- _this2.commitPendingCreation(false);
192
+ _this3.commitPendingCreation(false);
180
193
  // TODO: EDITOR-1921 - add error analytics
181
194
  }
182
195
  });
183
196
  }).catch(function (_reason) {
184
- _this2.commitPendingCreation(false);
197
+ _this3.commitPendingCreation(false);
185
198
  // TODO: EDITOR-1921 - add error analytics
186
199
  });
187
200
  this.registerPendingCreation(resourceId);
@@ -196,13 +209,13 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
196
209
  key: "deleteSyncBlocksWithConfirmation",
197
210
  value: function () {
198
211
  var _deleteSyncBlocksWithConfirmation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(tr, syncBlockIds) {
199
- var _this3 = this;
200
- var confirmed, _this$editorView, results;
212
+ var _this4 = this;
213
+ var confirmed, _this$editorView, results, callback;
201
214
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
202
215
  while (1) switch (_context2.prev = _context2.next) {
203
216
  case 0:
204
217
  if (!this.confirmationCallback) {
205
- _context2.next = 19;
218
+ _context2.next = 22;
206
219
  break;
207
220
  }
208
221
  this.confirmationTransaction = tr;
@@ -211,7 +224,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
211
224
  case 4:
212
225
  confirmed = _context2.sent;
213
226
  if (!confirmed) {
214
- _context2.next = 18;
227
+ _context2.next = 21;
215
228
  break;
216
229
  }
217
230
  (_this$editorView = this.editorView) === null || _this$editorView === void 0 || _this$editorView.dispatch(this.confirmationTransaction.setMeta('isConfirmedSyncBlockDeletion', true));
@@ -222,32 +235,44 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
222
235
  }
223
236
  throw new Error('Data provider not set');
224
237
  case 10:
225
- _context2.next = 12;
238
+ syncBlockIds.forEach(function (Ids) {
239
+ _this4.setPendingDeletion(Ids, true);
240
+ });
241
+ _context2.next = 13;
226
242
  return this.dataProvider.deleteNodesData(syncBlockIds.map(function (attrs) {
227
243
  return attrs.resourceId;
228
244
  }));
229
- case 12:
245
+ case 13:
230
246
  results = _context2.sent;
231
- results.forEach(function (result) {
232
- if (result.success) {
233
- // Only delete when it's deleted successfully in backend
234
- _this3.syncBlockCache.delete(result.resourceId);
235
- } else {
236
- // TODO: EDITOR-1921 - add error analytics with result.error
237
- }
238
- });
239
- _context2.next = 18;
247
+ if (results.every(function (result) {
248
+ return result.success;
249
+ })) {
250
+ callback = function callback(Ids) {
251
+ return _this4.syncBlockCache.delete(Ids.resourceId);
252
+ };
253
+ } else {
254
+ callback = function callback(Ids) {
255
+ _this4.setPendingDeletion(Ids, false);
256
+ };
257
+ // TODO: EDITOR-1921 - add error analytics
258
+ }
259
+ syncBlockIds.forEach(callback);
260
+ _context2.next = 21;
240
261
  break;
241
- case 16:
242
- _context2.prev = 16;
243
- _context2.t0 = _context2["catch"](7);
244
262
  case 18:
263
+ _context2.prev = 18;
264
+ _context2.t0 = _context2["catch"](7);
265
+ syncBlockIds.forEach(function (Ids) {
266
+ _this4.setPendingDeletion(Ids, false);
267
+ });
268
+ // TODO: EDITOR-1921 - add error analytics
269
+ case 21:
245
270
  this.confirmationTransaction = undefined;
246
- case 19:
271
+ case 22:
247
272
  case "end":
248
273
  return _context2.stop();
249
274
  }
250
- }, _callee2, this, [[7, 16]]);
275
+ }, _callee2, this, [[7, 18]]);
251
276
  }));
252
277
  function deleteSyncBlocksWithConfirmation(_x, _x2) {
253
278
  return _deleteSyncBlocksWithConfirmation.apply(this, arguments);
@@ -5,8 +5,8 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
5
5
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
6
6
  /* eslint-disable require-unicode-regexp */
7
7
 
8
- import { getPageIdAndTypeFromAri } from "./ari";
9
- import { isBlogPageType } from "./utils";
8
+ import { getPageIdAndTypeFromAri } from './ari';
9
+ import { isBlogPageType } from './utils';
10
10
  var COMMON_HEADERS = {
11
11
  'Content-Type': 'application/json',
12
12
  Accept: 'application/json'
@@ -1,5 +1,5 @@
1
1
  import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
- import type { ResourceId, SyncBlockNode } from '../common/types';
2
+ import { type ResourceId, type SyncBlockNode } from '../common/types';
3
3
  import type { SyncBlockInstance, SubscriptionCallback, SyncBlockDataProvider, TitleSubscriptionCallback } from '../providers/types';
4
4
  export declare class ReferenceSyncBlockStoreManager {
5
5
  private dataProvider?;
@@ -38,6 +38,7 @@ export declare class SourceSyncBlockStoreManager {
38
38
  requireConfirmationBeforeDelete(): boolean;
39
39
  generateBodiedSyncBlockAttrs(): SyncBlockAttrs;
40
40
  createBodiedSyncBlockNode(attrs: SyncBlockAttrs): void;
41
+ private setPendingDeletion;
41
42
  deleteSyncBlocksWithConfirmation(tr: Transaction, syncBlockIds: SyncBlockAttrs[]): Promise<void>;
42
43
  rebaseTransaction(incomingTr: Transaction, state: EditorState): void;
43
44
  }
@@ -1,2 +1,2 @@
1
- import type { SyncBlockSourceInfo } from "../providers/types";
1
+ import type { SyncBlockSourceInfo } from '../providers/types';
2
2
  export declare const fetchSourceInfo: (ari: string, localId?: string) => Promise<SyncBlockSourceInfo | undefined>;
@@ -1,5 +1,5 @@
1
1
  import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
- import type { ResourceId, SyncBlockNode } from '../common/types';
2
+ import { type ResourceId, type SyncBlockNode } from '../common/types';
3
3
  import type { SyncBlockInstance, SubscriptionCallback, SyncBlockDataProvider, TitleSubscriptionCallback } from '../providers/types';
4
4
  export declare class ReferenceSyncBlockStoreManager {
5
5
  private dataProvider?;
@@ -38,6 +38,7 @@ export declare class SourceSyncBlockStoreManager {
38
38
  requireConfirmationBeforeDelete(): boolean;
39
39
  generateBodiedSyncBlockAttrs(): SyncBlockAttrs;
40
40
  createBodiedSyncBlockNode(attrs: SyncBlockAttrs): void;
41
+ private setPendingDeletion;
41
42
  deleteSyncBlocksWithConfirmation(tr: Transaction, syncBlockIds: SyncBlockAttrs[]): Promise<void>;
42
43
  rebaseTransaction(incomingTr: Transaction, state: EditorState): void;
43
44
  }
@@ -1,2 +1,2 @@
1
- import type { SyncBlockSourceInfo } from "../providers/types";
1
+ import type { SyncBlockSourceInfo } from '../providers/types';
2
2
  export declare const fetchSourceInfo: (ari: string, localId?: string) => Promise<SyncBlockSourceInfo | undefined>;
package/package.json CHANGED
@@ -31,7 +31,7 @@
31
31
  "@atlaskit/editor-prosemirror": "7.0.0",
32
32
  "@atlaskit/node-data-provider": "^7.5.0",
33
33
  "@atlaskit/primitives": "^16.1.0",
34
- "@atlaskit/tokens": "^7.1.0",
34
+ "@atlaskit/tokens": "^8.0.0",
35
35
  "@babel/runtime": "^7.0.0",
36
36
  "@compiled/react": "^0.18.6",
37
37
  "uuid": "^3.1.0"
@@ -82,7 +82,7 @@
82
82
  }
83
83
  },
84
84
  "name": "@atlaskit/editor-synced-block-provider",
85
- "version": "2.7.2",
85
+ "version": "2.7.3",
86
86
  "description": "Synced Block Provider for @atlaskit/editor-plugin-synced-block",
87
87
  "author": "Atlassian Pty Ltd",
88
88
  "license": "Apache-2.0",