@atlaskit/editor-synced-block-provider 2.11.0 → 2.11.1

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,12 @@
1
1
  # @atlaskit/editor-synced-block-provider
2
2
 
3
+ ## 2.11.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`99387f7d6303b`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/99387f7d6303b) -
8
+ [ux] [EDITOR-2767] Implement bodiedSyncBlock creation/deletion undo/redo
9
+
3
10
  ## 2.11.0
4
11
 
5
12
  ### Minor Changes
@@ -12,9 +12,10 @@ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/creat
12
12
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
13
  var _uuid = _interopRequireDefault(require("uuid"));
14
14
  var _monitoring = require("@atlaskit/editor-common/monitoring");
15
+ var _utils = require("@atlaskit/editor-common/utils");
15
16
  var _rebaseTransaction2 = require("../common/rebase-transaction");
16
17
  var _errorHandling = require("../utils/errorHandling");
17
- var _utils = require("../utils/utils");
18
+ var _utils2 = require("../utils/utils");
18
19
  // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
19
20
  // A store manager responsible for the lifecycle and state management of source sync blocks in an editor instance.
20
21
  // Designed to manage local in-memory state and synchronize with an external data provider.
@@ -58,7 +59,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
58
59
  if (!localId || !resourceId) {
59
60
  throw new Error('Local ID or resource ID is not set');
60
61
  }
61
- var syncBlockData = (0, _utils.convertSyncBlockPMNodeToSyncBlockData)(syncBlockNode);
62
+ var syncBlockData = (0, _utils2.convertSyncBlockPMNodeToSyncBlockData)(syncBlockNode);
62
63
  this.syncBlockCache.set(resourceId, syncBlockData);
63
64
  return true;
64
65
  } catch (error) {
@@ -246,7 +247,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
246
247
  }
247
248
  var resourceId = attrs.resourceId,
248
249
  blockInstanceId = attrs.localId;
249
- this.dataProvider.writeNodesData([(0, _utils.createBodiedSyncBlockNode)(blockInstanceId, resourceId)], [{
250
+ this.dataProvider.writeNodesData([(0, _utils2.createBodiedSyncBlockNode)(blockInstanceId, resourceId)], [{
250
251
  content: [],
251
252
  blockInstanceId: blockInstanceId,
252
253
  resourceId: resourceId
@@ -286,12 +287,12 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
286
287
  value: function () {
287
288
  var _deleteSyncBlocksWithConfirmation = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(tr, syncBlockIds) {
288
289
  var _this5 = this;
289
- var confirmed, _this$editorView, results, callback, _this$fireAnalyticsEv4;
290
+ var confirmed, _this$editorView, trToDispatch, results, callback, _this$fireAnalyticsEv4;
290
291
  return _regenerator.default.wrap(function _callee2$(_context2) {
291
292
  while (1) switch (_context2.prev = _context2.next) {
292
293
  case 0:
293
294
  if (!this.confirmationCallback) {
294
- _context2.next = 24;
295
+ _context2.next = 26;
295
296
  break;
296
297
  }
297
298
  this.confirmationTransaction = tr;
@@ -300,25 +301,31 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
300
301
  case 4:
301
302
  confirmed = _context2.sent;
302
303
  if (!confirmed) {
303
- _context2.next = 23;
304
+ _context2.next = 25;
304
305
  break;
305
306
  }
306
- (_this$editorView = this.editorView) === null || _this$editorView === void 0 || _this$editorView.dispatch(this.confirmationTransaction.setMeta('isConfirmedSyncBlockDeletion', true));
307
- _context2.prev = 7;
307
+ trToDispatch = this.confirmationTransaction.setMeta('isConfirmedSyncBlockDeletion', true);
308
+ if (!trToDispatch.getMeta(_utils.pmHistoryPluginKey)) {
309
+ // bodiedSyncBlock deletion is expected to be permanent (cannot be undo)
310
+ // For a normal delete (not triggered by undo), remove it from history so that it cannot be undone
311
+ trToDispatch.setMeta('addToHistory', false);
312
+ }
313
+ (_this$editorView = this.editorView) === null || _this$editorView === void 0 || _this$editorView.dispatch(trToDispatch);
314
+ _context2.prev = 9;
308
315
  if (this.dataProvider) {
309
- _context2.next = 10;
316
+ _context2.next = 12;
310
317
  break;
311
318
  }
312
319
  throw new Error('Data provider not set');
313
- case 10:
320
+ case 12:
314
321
  syncBlockIds.forEach(function (Ids) {
315
322
  _this5.setPendingDeletion(Ids, true);
316
323
  });
317
- _context2.next = 13;
324
+ _context2.next = 15;
318
325
  return this.dataProvider.deleteNodesData(syncBlockIds.map(function (attrs) {
319
326
  return attrs.resourceId;
320
327
  }));
321
- case 13:
328
+ case 15:
322
329
  results = _context2.sent;
323
330
  if (results.every(function (result) {
324
331
  return result.success;
@@ -338,11 +345,11 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
338
345
  });
339
346
  }
340
347
  syncBlockIds.forEach(callback);
341
- _context2.next = 23;
348
+ _context2.next = 25;
342
349
  break;
343
- case 18:
344
- _context2.prev = 18;
345
- _context2.t0 = _context2["catch"](7);
350
+ case 20:
351
+ _context2.prev = 20;
352
+ _context2.t0 = _context2["catch"](9);
346
353
  syncBlockIds.forEach(function (Ids) {
347
354
  _this5.setPendingDeletion(Ids, false);
348
355
  });
@@ -350,13 +357,13 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
350
357
  location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
351
358
  });
352
359
  (_this$fireAnalyticsEv4 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv4 === void 0 || _this$fireAnalyticsEv4.call(this, (0, _errorHandling.deleteErrorPayload)(_context2.t0.message));
353
- case 23:
360
+ case 25:
354
361
  this.confirmationTransaction = undefined;
355
- case 24:
362
+ case 26:
356
363
  case "end":
357
364
  return _context2.stop();
358
365
  }
359
- }, _callee2, this, [[7, 18]]);
366
+ }, _callee2, this, [[9, 20]]);
360
367
  }));
361
368
  function deleteSyncBlocksWithConfirmation(_x, _x2) {
362
369
  return _deleteSyncBlocksWithConfirmation.apply(this, arguments);
@@ -2,6 +2,7 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
3
3
  import uuid from 'uuid';
4
4
  import { logException } from '@atlaskit/editor-common/monitoring';
5
+ import { pmHistoryPluginKey } from '@atlaskit/editor-common/utils';
5
6
  import { rebaseTransaction } from '../common/rebase-transaction';
6
7
  import { updateErrorPayload, createErrorPayload, deleteErrorPayload, updateCacheErrorPayload } from '../utils/errorHandling';
7
8
  import { convertSyncBlockPMNodeToSyncBlockData, createBodiedSyncBlockNode } from '../utils/utils';
@@ -217,7 +218,13 @@ export class SourceSyncBlockStoreManager {
217
218
  const confirmed = await this.confirmationCallback(syncBlockIds.length);
218
219
  if (confirmed) {
219
220
  var _this$editorView;
220
- (_this$editorView = this.editorView) === null || _this$editorView === void 0 ? void 0 : _this$editorView.dispatch(this.confirmationTransaction.setMeta('isConfirmedSyncBlockDeletion', true));
221
+ const trToDispatch = this.confirmationTransaction.setMeta('isConfirmedSyncBlockDeletion', true);
222
+ if (!trToDispatch.getMeta(pmHistoryPluginKey)) {
223
+ // bodiedSyncBlock deletion is expected to be permanent (cannot be undo)
224
+ // For a normal delete (not triggered by undo), remove it from history so that it cannot be undone
225
+ trToDispatch.setMeta('addToHistory', false);
226
+ }
227
+ (_this$editorView = this.editorView) === null || _this$editorView === void 0 ? void 0 : _this$editorView.dispatch(trToDispatch);
221
228
  try {
222
229
  if (!this.dataProvider) {
223
230
  throw new Error('Data provider not set');
@@ -6,6 +6,7 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
6
6
  // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
7
7
  import uuid from 'uuid';
8
8
  import { logException } from '@atlaskit/editor-common/monitoring';
9
+ import { pmHistoryPluginKey } from '@atlaskit/editor-common/utils';
9
10
  import { rebaseTransaction as _rebaseTransaction } from '../common/rebase-transaction';
10
11
  import { updateErrorPayload, createErrorPayload, deleteErrorPayload, updateCacheErrorPayload } from '../utils/errorHandling';
11
12
  import { convertSyncBlockPMNodeToSyncBlockData, createBodiedSyncBlockNode as _createBodiedSyncBlockNode } from '../utils/utils';
@@ -279,12 +280,12 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
279
280
  value: function () {
280
281
  var _deleteSyncBlocksWithConfirmation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(tr, syncBlockIds) {
281
282
  var _this5 = this;
282
- var confirmed, _this$editorView, results, callback, _this$fireAnalyticsEv4;
283
+ var confirmed, _this$editorView, trToDispatch, results, callback, _this$fireAnalyticsEv4;
283
284
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
284
285
  while (1) switch (_context2.prev = _context2.next) {
285
286
  case 0:
286
287
  if (!this.confirmationCallback) {
287
- _context2.next = 24;
288
+ _context2.next = 26;
288
289
  break;
289
290
  }
290
291
  this.confirmationTransaction = tr;
@@ -293,25 +294,31 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
293
294
  case 4:
294
295
  confirmed = _context2.sent;
295
296
  if (!confirmed) {
296
- _context2.next = 23;
297
+ _context2.next = 25;
297
298
  break;
298
299
  }
299
- (_this$editorView = this.editorView) === null || _this$editorView === void 0 || _this$editorView.dispatch(this.confirmationTransaction.setMeta('isConfirmedSyncBlockDeletion', true));
300
- _context2.prev = 7;
300
+ trToDispatch = this.confirmationTransaction.setMeta('isConfirmedSyncBlockDeletion', true);
301
+ if (!trToDispatch.getMeta(pmHistoryPluginKey)) {
302
+ // bodiedSyncBlock deletion is expected to be permanent (cannot be undo)
303
+ // For a normal delete (not triggered by undo), remove it from history so that it cannot be undone
304
+ trToDispatch.setMeta('addToHistory', false);
305
+ }
306
+ (_this$editorView = this.editorView) === null || _this$editorView === void 0 || _this$editorView.dispatch(trToDispatch);
307
+ _context2.prev = 9;
301
308
  if (this.dataProvider) {
302
- _context2.next = 10;
309
+ _context2.next = 12;
303
310
  break;
304
311
  }
305
312
  throw new Error('Data provider not set');
306
- case 10:
313
+ case 12:
307
314
  syncBlockIds.forEach(function (Ids) {
308
315
  _this5.setPendingDeletion(Ids, true);
309
316
  });
310
- _context2.next = 13;
317
+ _context2.next = 15;
311
318
  return this.dataProvider.deleteNodesData(syncBlockIds.map(function (attrs) {
312
319
  return attrs.resourceId;
313
320
  }));
314
- case 13:
321
+ case 15:
315
322
  results = _context2.sent;
316
323
  if (results.every(function (result) {
317
324
  return result.success;
@@ -331,11 +338,11 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
331
338
  });
332
339
  }
333
340
  syncBlockIds.forEach(callback);
334
- _context2.next = 23;
341
+ _context2.next = 25;
335
342
  break;
336
- case 18:
337
- _context2.prev = 18;
338
- _context2.t0 = _context2["catch"](7);
343
+ case 20:
344
+ _context2.prev = 20;
345
+ _context2.t0 = _context2["catch"](9);
339
346
  syncBlockIds.forEach(function (Ids) {
340
347
  _this5.setPendingDeletion(Ids, false);
341
348
  });
@@ -343,13 +350,13 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
343
350
  location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
344
351
  });
345
352
  (_this$fireAnalyticsEv4 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv4 === void 0 || _this$fireAnalyticsEv4.call(this, deleteErrorPayload(_context2.t0.message));
346
- case 23:
353
+ case 25:
347
354
  this.confirmationTransaction = undefined;
348
- case 24:
355
+ case 26:
349
356
  case "end":
350
357
  return _context2.stop();
351
358
  }
352
- }, _callee2, this, [[7, 18]]);
359
+ }, _callee2, this, [[9, 20]]);
353
360
  }));
354
361
  function deleteSyncBlocksWithConfirmation(_x, _x2) {
355
362
  return _deleteSyncBlocksWithConfirmation.apply(this, arguments);
package/package.json CHANGED
@@ -77,7 +77,7 @@
77
77
  }
78
78
  },
79
79
  "name": "@atlaskit/editor-synced-block-provider",
80
- "version": "2.11.0",
80
+ "version": "2.11.1",
81
81
  "description": "Synced Block Provider for @atlaskit/editor-plugin-synced-block",
82
82
  "author": "Atlassian Pty Ltd",
83
83
  "license": "Apache-2.0",