@atlaskit/editor-synced-block-provider 2.11.2 → 2.11.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.11.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [`48a3dd84c602b`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/48a3dd84c602b) -
8
+ [EDITOR-3394] Decouple editorView from source manager
9
+ - Updated dependencies
10
+
3
11
  ## 2.11.2
4
12
 
5
13
  ### Patch Changes
@@ -12,10 +12,8 @@ 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");
16
- var _rebaseTransaction2 = require("../common/rebase-transaction");
17
15
  var _errorHandling = require("../utils/errorHandling");
18
- var _utils2 = require("../utils/utils");
16
+ var _utils = require("../utils/utils");
19
17
  // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
20
18
  // A store manager responsible for the lifecycle and state management of source sync blocks in an editor instance.
21
19
  // Designed to manage local in-memory state and synchronize with an external data provider.
@@ -59,7 +57,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
59
57
  if (!localId || !resourceId) {
60
58
  throw new Error('Local ID or resource ID is not set');
61
59
  }
62
- var syncBlockData = (0, _utils2.convertSyncBlockPMNodeToSyncBlockData)(syncBlockNode);
60
+ var syncBlockData = (0, _utils.convertSyncBlockPMNodeToSyncBlockData)(syncBlockNode);
63
61
  this.syncBlockCache.set(resourceId, syncBlockData);
64
62
  return true;
65
63
  } catch (error) {
@@ -155,11 +153,6 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
155
153
  }
156
154
  return flush;
157
155
  }())
158
- }, {
159
- key: "setEditorView",
160
- value: function setEditorView(editorView) {
161
- this.editorView = editorView;
162
- }
163
156
  }, {
164
157
  key: "registerPendingCreation",
165
158
  value: function registerPendingCreation(resourceId) {
@@ -247,7 +240,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
247
240
  }
248
241
  var resourceId = attrs.resourceId,
249
242
  blockInstanceId = attrs.localId;
250
- this.dataProvider.writeNodesData([(0, _utils2.createBodiedSyncBlockNode)(blockInstanceId, resourceId)], [{
243
+ this.dataProvider.writeNodesData([(0, _utils.createBodiedSyncBlockNode)(blockInstanceId, resourceId)], [{
251
244
  content: [],
252
245
  blockInstanceId: blockInstanceId,
253
246
  resourceId: resourceId
@@ -285,47 +278,40 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
285
278
  }, {
286
279
  key: "deleteSyncBlocksWithConfirmation",
287
280
  value: function () {
288
- var _deleteSyncBlocksWithConfirmation = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(tr, syncBlockIds) {
281
+ var _deleteSyncBlocksWithConfirmation = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(syncBlockIds, deleteCallback) {
289
282
  var _this5 = this;
290
- var confirmed, _this$editorView, trToDispatch, results, callback, _this$fireAnalyticsEv4;
283
+ var confirmed, results, callback, _this$fireAnalyticsEv4;
291
284
  return _regenerator.default.wrap(function _callee2$(_context2) {
292
285
  while (1) switch (_context2.prev = _context2.next) {
293
286
  case 0:
294
287
  if (!this.confirmationCallback) {
295
- _context2.next = 26;
288
+ _context2.next = 22;
296
289
  break;
297
290
  }
298
- this.confirmationTransaction = tr;
299
- _context2.next = 4;
291
+ _context2.next = 3;
300
292
  return this.confirmationCallback(syncBlockIds.length);
301
- case 4:
293
+ case 3:
302
294
  confirmed = _context2.sent;
303
295
  if (!confirmed) {
304
- _context2.next = 25;
296
+ _context2.next = 22;
305
297
  break;
306
298
  }
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;
299
+ deleteCallback();
300
+ _context2.prev = 6;
315
301
  if (this.dataProvider) {
316
- _context2.next = 12;
302
+ _context2.next = 9;
317
303
  break;
318
304
  }
319
305
  throw new Error('Data provider not set');
320
- case 12:
306
+ case 9:
321
307
  syncBlockIds.forEach(function (Ids) {
322
308
  _this5.setPendingDeletion(Ids, true);
323
309
  });
324
- _context2.next = 15;
310
+ _context2.next = 12;
325
311
  return this.dataProvider.deleteNodesData(syncBlockIds.map(function (attrs) {
326
312
  return attrs.resourceId;
327
313
  }));
328
- case 15:
314
+ case 12:
329
315
  results = _context2.sent;
330
316
  if (results.every(function (result) {
331
317
  return result.success;
@@ -345,11 +331,11 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
345
331
  });
346
332
  }
347
333
  syncBlockIds.forEach(callback);
348
- _context2.next = 25;
334
+ _context2.next = 22;
349
335
  break;
350
- case 20:
351
- _context2.prev = 20;
352
- _context2.t0 = _context2["catch"](9);
336
+ case 17:
337
+ _context2.prev = 17;
338
+ _context2.t0 = _context2["catch"](6);
353
339
  syncBlockIds.forEach(function (Ids) {
354
340
  _this5.setPendingDeletion(Ids, false);
355
341
  });
@@ -357,38 +343,25 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
357
343
  location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
358
344
  });
359
345
  (_this$fireAnalyticsEv4 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv4 === void 0 || _this$fireAnalyticsEv4.call(this, (0, _errorHandling.deleteErrorPayload)(_context2.t0.message));
360
- case 25:
361
- this.confirmationTransaction = undefined;
362
- case 26:
346
+ case 22:
363
347
  case "end":
364
348
  return _context2.stop();
365
349
  }
366
- }, _callee2, this, [[9, 20]]);
350
+ }, _callee2, this, [[6, 17]]);
367
351
  }));
368
352
  function deleteSyncBlocksWithConfirmation(_x, _x2) {
369
353
  return _deleteSyncBlocksWithConfirmation.apply(this, arguments);
370
354
  }
371
355
  return deleteSyncBlocksWithConfirmation;
372
356
  }()
373
- }, {
374
- key: "rebaseTransaction",
375
- value: function rebaseTransaction(incomingTr, state) {
376
- if (!this.confirmationTransaction) {
377
- return;
378
- }
379
- this.confirmationTransaction = (0, _rebaseTransaction2.rebaseTransaction)(this.confirmationTransaction, incomingTr, state);
380
- }
381
357
  }, {
382
358
  key: "destroy",
383
359
  value: function destroy() {
384
360
  this.syncBlockCache.clear();
385
361
  this.confirmationCallback = undefined;
386
- this.confirmationTransaction = undefined;
387
362
  this.pendingResourceId = undefined;
388
363
  this.creationCallback = undefined;
389
364
  this.dataProvider = undefined;
390
- this.editorView = undefined;
391
- this.fireAnalyticsEvent = undefined;
392
365
  }
393
366
  }]);
394
367
  }();
@@ -2,8 +2,6 @@ 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';
6
- import { rebaseTransaction } from '../common/rebase-transaction';
7
5
  import { updateErrorPayload, createErrorPayload, deleteErrorPayload, updateCacheErrorPayload } from '../utils/errorHandling';
8
6
  import { convertSyncBlockPMNodeToSyncBlockData, createBodiedSyncBlockNode } from '../utils/utils';
9
7
  // A store manager responsible for the lifecycle and state management of source sync blocks in an editor instance.
@@ -103,9 +101,6 @@ export class SourceSyncBlockStoreManager {
103
101
  return false;
104
102
  }
105
103
  }
106
- setEditorView(editorView) {
107
- this.editorView = editorView;
108
- }
109
104
  registerPendingCreation(resourceId) {
110
105
  this.pendingResourceId = resourceId;
111
106
  }
@@ -212,19 +207,11 @@ export class SourceSyncBlockStoreManager {
212
207
  (_this$fireAnalyticsEv6 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv6 === void 0 ? void 0 : _this$fireAnalyticsEv6.call(this, createErrorPayload(error.message));
213
208
  }
214
209
  }
215
- async deleteSyncBlocksWithConfirmation(tr, syncBlockIds) {
210
+ async deleteSyncBlocksWithConfirmation(syncBlockIds, deleteCallback) {
216
211
  if (this.confirmationCallback) {
217
- this.confirmationTransaction = tr;
218
212
  const confirmed = await this.confirmationCallback(syncBlockIds.length);
219
213
  if (confirmed) {
220
- var _this$editorView;
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);
214
+ deleteCallback();
228
215
  try {
229
216
  if (!this.dataProvider) {
230
217
  throw new Error('Data provider not set');
@@ -257,23 +244,13 @@ export class SourceSyncBlockStoreManager {
257
244
  (_this$fireAnalyticsEv8 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv8 === void 0 ? void 0 : _this$fireAnalyticsEv8.call(this, deleteErrorPayload(error.message));
258
245
  }
259
246
  }
260
- this.confirmationTransaction = undefined;
261
- }
262
- }
263
- rebaseTransaction(incomingTr, state) {
264
- if (!this.confirmationTransaction) {
265
- return;
266
247
  }
267
- this.confirmationTransaction = rebaseTransaction(this.confirmationTransaction, incomingTr, state);
268
248
  }
269
249
  destroy() {
270
250
  this.syncBlockCache.clear();
271
251
  this.confirmationCallback = undefined;
272
- this.confirmationTransaction = undefined;
273
252
  this.pendingResourceId = undefined;
274
253
  this.creationCallback = undefined;
275
254
  this.dataProvider = undefined;
276
- this.editorView = undefined;
277
- this.fireAnalyticsEvent = undefined;
278
255
  }
279
256
  }
@@ -6,8 +6,6 @@ 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';
10
- import { rebaseTransaction as _rebaseTransaction } from '../common/rebase-transaction';
11
9
  import { updateErrorPayload, createErrorPayload, deleteErrorPayload, updateCacheErrorPayload } from '../utils/errorHandling';
12
10
  import { convertSyncBlockPMNodeToSyncBlockData, createBodiedSyncBlockNode as _createBodiedSyncBlockNode } from '../utils/utils';
13
11
  // A store manager responsible for the lifecycle and state management of source sync blocks in an editor instance.
@@ -148,11 +146,6 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
148
146
  }
149
147
  return flush;
150
148
  }())
151
- }, {
152
- key: "setEditorView",
153
- value: function setEditorView(editorView) {
154
- this.editorView = editorView;
155
- }
156
149
  }, {
157
150
  key: "registerPendingCreation",
158
151
  value: function registerPendingCreation(resourceId) {
@@ -278,47 +271,40 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
278
271
  }, {
279
272
  key: "deleteSyncBlocksWithConfirmation",
280
273
  value: function () {
281
- var _deleteSyncBlocksWithConfirmation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(tr, syncBlockIds) {
274
+ var _deleteSyncBlocksWithConfirmation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(syncBlockIds, deleteCallback) {
282
275
  var _this5 = this;
283
- var confirmed, _this$editorView, trToDispatch, results, callback, _this$fireAnalyticsEv4;
276
+ var confirmed, results, callback, _this$fireAnalyticsEv4;
284
277
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
285
278
  while (1) switch (_context2.prev = _context2.next) {
286
279
  case 0:
287
280
  if (!this.confirmationCallback) {
288
- _context2.next = 26;
281
+ _context2.next = 22;
289
282
  break;
290
283
  }
291
- this.confirmationTransaction = tr;
292
- _context2.next = 4;
284
+ _context2.next = 3;
293
285
  return this.confirmationCallback(syncBlockIds.length);
294
- case 4:
286
+ case 3:
295
287
  confirmed = _context2.sent;
296
288
  if (!confirmed) {
297
- _context2.next = 25;
289
+ _context2.next = 22;
298
290
  break;
299
291
  }
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;
292
+ deleteCallback();
293
+ _context2.prev = 6;
308
294
  if (this.dataProvider) {
309
- _context2.next = 12;
295
+ _context2.next = 9;
310
296
  break;
311
297
  }
312
298
  throw new Error('Data provider not set');
313
- case 12:
299
+ case 9:
314
300
  syncBlockIds.forEach(function (Ids) {
315
301
  _this5.setPendingDeletion(Ids, true);
316
302
  });
317
- _context2.next = 15;
303
+ _context2.next = 12;
318
304
  return this.dataProvider.deleteNodesData(syncBlockIds.map(function (attrs) {
319
305
  return attrs.resourceId;
320
306
  }));
321
- case 15:
307
+ case 12:
322
308
  results = _context2.sent;
323
309
  if (results.every(function (result) {
324
310
  return result.success;
@@ -338,11 +324,11 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
338
324
  });
339
325
  }
340
326
  syncBlockIds.forEach(callback);
341
- _context2.next = 25;
327
+ _context2.next = 22;
342
328
  break;
343
- case 20:
344
- _context2.prev = 20;
345
- _context2.t0 = _context2["catch"](9);
329
+ case 17:
330
+ _context2.prev = 17;
331
+ _context2.t0 = _context2["catch"](6);
346
332
  syncBlockIds.forEach(function (Ids) {
347
333
  _this5.setPendingDeletion(Ids, false);
348
334
  });
@@ -350,38 +336,25 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
350
336
  location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
351
337
  });
352
338
  (_this$fireAnalyticsEv4 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv4 === void 0 || _this$fireAnalyticsEv4.call(this, deleteErrorPayload(_context2.t0.message));
353
- case 25:
354
- this.confirmationTransaction = undefined;
355
- case 26:
339
+ case 22:
356
340
  case "end":
357
341
  return _context2.stop();
358
342
  }
359
- }, _callee2, this, [[9, 20]]);
343
+ }, _callee2, this, [[6, 17]]);
360
344
  }));
361
345
  function deleteSyncBlocksWithConfirmation(_x, _x2) {
362
346
  return _deleteSyncBlocksWithConfirmation.apply(this, arguments);
363
347
  }
364
348
  return deleteSyncBlocksWithConfirmation;
365
349
  }()
366
- }, {
367
- key: "rebaseTransaction",
368
- value: function rebaseTransaction(incomingTr, state) {
369
- if (!this.confirmationTransaction) {
370
- return;
371
- }
372
- this.confirmationTransaction = _rebaseTransaction(this.confirmationTransaction, incomingTr, state);
373
- }
374
350
  }, {
375
351
  key: "destroy",
376
352
  value: function destroy() {
377
353
  this.syncBlockCache.clear();
378
354
  this.confirmationCallback = undefined;
379
- this.confirmationTransaction = undefined;
380
355
  this.pendingResourceId = undefined;
381
356
  this.creationCallback = undefined;
382
357
  this.dataProvider = undefined;
383
- this.editorView = undefined;
384
- this.fireAnalyticsEvent = undefined;
385
358
  }
386
359
  }]);
387
360
  }();
@@ -1,18 +1,14 @@
1
1
  import { type SyncBlockEventPayload } from '@atlaskit/editor-common/analytics';
2
2
  import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
3
- import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
4
- import type { EditorView } from '@atlaskit/editor-prosemirror/view';
5
3
  import type { ResourceId, SyncBlockAttrs } from '../common/types';
6
4
  import type { SyncBlockDataProvider } from '../providers/types';
7
5
  export type ConfirmationCallback = (syncBlockCount: number) => Promise<boolean>;
8
6
  export type CreationCallback = () => void;
9
7
  export declare class SourceSyncBlockStoreManager {
10
8
  private dataProvider?;
11
- private editorView?;
12
9
  private fireAnalyticsEvent?;
13
10
  private syncBlockCache;
14
11
  private confirmationCallback?;
15
- private confirmationTransaction?;
16
12
  private pendingResourceId?;
17
13
  private creationCallback?;
18
14
  constructor(dataProvider?: SyncBlockDataProvider, fireAnalyticsEvent?: (payload: SyncBlockEventPayload) => void);
@@ -28,7 +24,6 @@ export declare class SourceSyncBlockStoreManager {
28
24
  * @returns true if saving all nodes successfully, false if fail to save some/all nodes
29
25
  */
30
26
  flush(): Promise<boolean>;
31
- setEditorView(editorView: EditorView | undefined): void;
32
27
  registerPendingCreation(resourceId: ResourceId): void;
33
28
  /**
34
29
  * Register callback function (which inserts node, handles focus etc) to be used later when creation to backend succeed
@@ -56,7 +51,6 @@ export declare class SourceSyncBlockStoreManager {
56
51
  */
57
52
  createBodiedSyncBlockNode(attrs: SyncBlockAttrs): void;
58
53
  private setPendingDeletion;
59
- deleteSyncBlocksWithConfirmation(tr: Transaction, syncBlockIds: SyncBlockAttrs[]): Promise<void>;
60
- rebaseTransaction(incomingTr: Transaction, state: EditorState): void;
54
+ deleteSyncBlocksWithConfirmation(syncBlockIds: SyncBlockAttrs[], deleteCallback: () => void): Promise<void>;
61
55
  destroy(): void;
62
56
  }
@@ -1,18 +1,14 @@
1
1
  import { type SyncBlockEventPayload } from '@atlaskit/editor-common/analytics';
2
2
  import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
3
- import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
4
- import type { EditorView } from '@atlaskit/editor-prosemirror/view';
5
3
  import type { ResourceId, SyncBlockAttrs } from '../common/types';
6
4
  import type { SyncBlockDataProvider } from '../providers/types';
7
5
  export type ConfirmationCallback = (syncBlockCount: number) => Promise<boolean>;
8
6
  export type CreationCallback = () => void;
9
7
  export declare class SourceSyncBlockStoreManager {
10
8
  private dataProvider?;
11
- private editorView?;
12
9
  private fireAnalyticsEvent?;
13
10
  private syncBlockCache;
14
11
  private confirmationCallback?;
15
- private confirmationTransaction?;
16
12
  private pendingResourceId?;
17
13
  private creationCallback?;
18
14
  constructor(dataProvider?: SyncBlockDataProvider, fireAnalyticsEvent?: (payload: SyncBlockEventPayload) => void);
@@ -28,7 +24,6 @@ export declare class SourceSyncBlockStoreManager {
28
24
  * @returns true if saving all nodes successfully, false if fail to save some/all nodes
29
25
  */
30
26
  flush(): Promise<boolean>;
31
- setEditorView(editorView: EditorView | undefined): void;
32
27
  registerPendingCreation(resourceId: ResourceId): void;
33
28
  /**
34
29
  * Register callback function (which inserts node, handles focus etc) to be used later when creation to backend succeed
@@ -56,7 +51,6 @@ export declare class SourceSyncBlockStoreManager {
56
51
  */
57
52
  createBodiedSyncBlockNode(attrs: SyncBlockAttrs): void;
58
53
  private setPendingDeletion;
59
- deleteSyncBlocksWithConfirmation(tr: Transaction, syncBlockIds: SyncBlockAttrs[]): Promise<void>;
60
- rebaseTransaction(incomingTr: Transaction, state: EditorState): void;
54
+ deleteSyncBlocksWithConfirmation(syncBlockIds: SyncBlockAttrs[], deleteCallback: () => void): Promise<void>;
61
55
  destroy(): void;
62
56
  }
package/package.json CHANGED
@@ -77,7 +77,7 @@
77
77
  }
78
78
  },
79
79
  "name": "@atlaskit/editor-synced-block-provider",
80
- "version": "2.11.2",
80
+ "version": "2.11.3",
81
81
  "description": "Synced Block Provider for @atlaskit/editor-plugin-synced-block",
82
82
  "author": "Atlassian Pty Ltd",
83
83
  "license": "Apache-2.0",