@atlaskit/editor-synced-block-provider 4.3.1 → 4.3.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.
@@ -26,17 +26,21 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
26
26
  // Handles caching, debouncing updates, and publish/subscribe for local changes.
27
27
  // Ensures consistency between local and remote state, and can be used in both editor and renderer contexts.
28
28
  var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PURE__*/function () {
29
- function SourceSyncBlockStoreManager(dataProvider) {
29
+ function SourceSyncBlockStoreManager(dataProvider, viewMode) {
30
30
  var _this = this;
31
31
  (0, _classCallCheck2.default)(this, SourceSyncBlockStoreManager);
32
32
  (0, _defineProperty2.default)(this, "hasReceivedContentChange", false);
33
33
  (0, _defineProperty2.default)(this, "setPendingDeletion", function (Ids, value) {
34
+ if (_this.viewMode === 'view' && (0, _platformFeatureFlags.fg)('platform_synced_block_patch_8')) {
35
+ return;
36
+ }
34
37
  var syncBlock = _this.syncBlockCache.get(Ids.resourceId);
35
38
  if (syncBlock) {
36
39
  syncBlock.pendingDeletion = value;
37
40
  }
38
41
  });
39
42
  this.dataProvider = dataProvider;
43
+ this.viewMode = viewMode;
40
44
  this.syncBlockCache = new Map();
41
45
  this.creationCompletionCallbacks = new Map();
42
46
  }
@@ -74,6 +78,9 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
74
78
  key: "updateSyncBlockData",
75
79
  value: function updateSyncBlockData(syncBlockNode) {
76
80
  try {
81
+ if (this.viewMode === 'view' && (0, _platformFeatureFlags.fg)('platform_synced_block_patch_8')) {
82
+ return false;
83
+ }
77
84
  if (!this.isSourceBlock(syncBlockNode)) {
78
85
  throw new Error('Invalid sync block node type provided for updateSyncBlockData');
79
86
  }
@@ -134,6 +141,12 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
134
141
  while (1) switch (_context.prev = _context.next) {
135
142
  case 0:
136
143
  _context.prev = 0;
144
+ if (!(this.viewMode === 'view' && (0, _platformFeatureFlags.fg)('platform_synced_block_patch_8'))) {
145
+ _context.next = 3;
146
+ break;
147
+ }
148
+ return _context.abrupt("return", false);
149
+ case 3:
137
150
  bodiedSyncBlockNodes = [];
138
151
  bodiedSyncBlockData = [];
139
152
  Array.from(this.syncBlockCache.values()).forEach(function (syncBlockData) {
@@ -163,21 +176,21 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
163
176
  }
164
177
  });
165
178
  if (!(bodiedSyncBlockNodes.length === 0)) {
166
- _context.next = 6;
179
+ _context.next = 8;
167
180
  break;
168
181
  }
169
182
  return _context.abrupt("return", Promise.resolve(true));
170
- case 6:
183
+ case 8:
171
184
  if (this.dataProvider) {
172
- _context.next = 8;
185
+ _context.next = 10;
173
186
  break;
174
187
  }
175
188
  throw new Error('Data provider not set');
176
- case 8:
189
+ case 10:
177
190
  (_this$saveExperience = this.saveExperience) === null || _this$saveExperience === void 0 || _this$saveExperience.start({});
178
- _context.next = 11;
191
+ _context.next = 13;
179
192
  return this.dataProvider.writeNodesData(bodiedSyncBlockNodes, bodiedSyncBlockData);
180
- case 11:
193
+ case 13:
181
194
  writeResults = _context.sent;
182
195
  writeResults.forEach(function (result) {
183
196
  // set isDirty to true for cases where it failed to save the sync block to the BE
@@ -191,7 +204,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
191
204
  if (!writeResults.every(function (result) {
192
205
  return result.resourceId && !result.error;
193
206
  })) {
194
- _context.next = 19;
207
+ _context.next = 21;
195
208
  break;
196
209
  }
197
210
  (_this$saveExperience2 = this.saveExperience) === null || _this$saveExperience2 === void 0 || _this$saveExperience2.success();
@@ -202,7 +215,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
202
215
  }
203
216
  });
204
217
  return _context.abrupt("return", true);
205
- case 19:
218
+ case 21:
206
219
  (_this$saveExperience3 = this.saveExperience) === null || _this$saveExperience3 === void 0 || _this$saveExperience3.failure();
207
220
  writeResults.filter(function (result) {
208
221
  return !result.resourceId || result.error;
@@ -211,28 +224,28 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
211
224
  (_this2$fireAnalyticsE2 = _this2.fireAnalyticsEvent) === null || _this2$fireAnalyticsE2 === void 0 || _this2$fireAnalyticsE2.call(_this2, (0, _errorHandling.updateErrorPayload)(result.error || 'Failed to write data', result.resourceId));
212
225
  });
213
226
  return _context.abrupt("return", false);
214
- case 22:
215
- _context.next = 29;
216
- break;
217
227
  case 24:
218
- _context.prev = 24;
228
+ _context.next = 31;
229
+ break;
230
+ case 26:
231
+ _context.prev = 26;
219
232
  _context.t0 = _context["catch"](0);
220
233
  (0, _monitoring.logException)(_context.t0, {
221
234
  location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
222
235
  });
223
236
  (_this$fireAnalyticsEv2 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv2 === void 0 || _this$fireAnalyticsEv2.call(this, (0, _errorHandling.updateErrorPayload)(_context.t0.message));
224
237
  return _context.abrupt("return", false);
225
- case 29:
226
- _context.prev = 29;
238
+ case 31:
239
+ _context.prev = 31;
227
240
  if ((0, _platformFeatureFlags.fg)('platform_synced_block_patch_7')) {
228
241
  (_this$flushCompletion = this.flushCompletionCallback) === null || _this$flushCompletion === void 0 || _this$flushCompletion.call(this);
229
242
  }
230
- return _context.finish(29);
231
- case 32:
243
+ return _context.finish(31);
244
+ case 34:
232
245
  case "end":
233
246
  return _context.stop();
234
247
  }
235
- }, _callee, this, [[0, 24, 29, 32]]);
248
+ }, _callee, this, [[0, 26, 31, 34]]);
236
249
  }));
237
250
  function flush() {
238
251
  return _flush.apply(this, arguments);
@@ -242,6 +255,9 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
242
255
  }, {
243
256
  key: "hasUnsavedChanges",
244
257
  value: function hasUnsavedChanges() {
258
+ if (this.viewMode === 'view' && (0, _platformFeatureFlags.fg)('platform_synced_block_patch_8')) {
259
+ return false;
260
+ }
245
261
  return this.hasReceivedContentChange && Array.from(this.syncBlockCache.values()).some(function (syncBlockData) {
246
262
  return syncBlockData.isDirty;
247
263
  });
@@ -259,6 +275,9 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
259
275
  }, {
260
276
  key: "commitPendingCreation",
261
277
  value: function commitPendingCreation(success, resourceId) {
278
+ if (this.viewMode === 'view' && (0, _platformFeatureFlags.fg)('platform_synced_block_patch_8')) {
279
+ return;
280
+ }
262
281
  var onCompletion = this.creationCompletionCallbacks.get(resourceId);
263
282
  if (onCompletion) {
264
283
  this.creationCompletionCallbacks.delete(resourceId);
@@ -320,11 +339,16 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
320
339
  /**
321
340
  * Create a bodiedSyncBlock node with empty content to backend
322
341
  * @param attrs attributes Ids of the node
342
+ * @param node the ProseMirror node to cache
343
+ * @param onCompletion callback invoked when creation completes
323
344
  */
324
345
  }, {
325
346
  key: "createBodiedSyncBlockNode",
326
- value: function createBodiedSyncBlockNode(attrs, onCompletion) {
347
+ value: function createBodiedSyncBlockNode(attrs, node, onCompletion) {
327
348
  var _this4 = this;
349
+ if (this.viewMode === 'view' && (0, _platformFeatureFlags.fg)('platform_synced_block_patch_8')) {
350
+ return;
351
+ }
328
352
  var resourceId = attrs.resourceId,
329
353
  blockInstanceId = attrs.localId;
330
354
  try {
@@ -332,6 +356,10 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
332
356
  if (!this.dataProvider) {
333
357
  throw new Error('Data provider not set');
334
358
  }
359
+ if ((0, _platformFeatureFlags.fg)('platform_synced_block_update_refactor')) {
360
+ // add the node to the cache
361
+ this.updateSyncBlockData(node);
362
+ }
335
363
  this.creationCompletionCallbacks.set(resourceId, onCompletion);
336
364
  (_this$createExperienc = this.createExperience) === null || _this$createExperienc === void 0 || _this$createExperienc.start({});
337
365
  this.dataProvider.createNodeData({
@@ -384,21 +412,27 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
384
412
  while (1) switch (_context2.prev = _context2.next) {
385
413
  case 0:
386
414
  _context2.prev = 0;
387
- if (this.dataProvider) {
415
+ if (!(this.viewMode === 'view' && (0, _platformFeatureFlags.fg)('platform_synced_block_patch_8'))) {
388
416
  _context2.next = 3;
389
417
  break;
390
418
  }
391
- throw new Error('Data provider not set');
419
+ return _context2.abrupt("return", false);
392
420
  case 3:
421
+ if (this.dataProvider) {
422
+ _context2.next = 5;
423
+ break;
424
+ }
425
+ throw new Error('Data provider not set');
426
+ case 5:
393
427
  syncBlockIds.forEach(function (Ids) {
394
428
  _this5.setPendingDeletion(Ids, true);
395
429
  });
396
430
  (_this$deleteExperienc = this.deleteExperience) === null || _this$deleteExperienc === void 0 || _this$deleteExperienc.start({});
397
- _context2.next = 7;
431
+ _context2.next = 9;
398
432
  return this.dataProvider.deleteNodesData(syncBlockIds.map(function (attrs) {
399
433
  return attrs.resourceId;
400
434
  }), reason);
401
- case 7:
435
+ case 9:
402
436
  results = _context2.sent;
403
437
  isDeleteSuccessful = results.every(function (result) {
404
438
  return result.success;
@@ -432,8 +466,8 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
432
466
  }
433
467
  syncBlockIds.forEach(callback);
434
468
  return _context2.abrupt("return", isDeleteSuccessful);
435
- case 15:
436
- _context2.prev = 15;
469
+ case 17:
470
+ _context2.prev = 17;
437
471
  _context2.t0 = _context2["catch"](0);
438
472
  syncBlockIds.forEach(function (Ids) {
439
473
  var _this5$fireAnalyticsE4;
@@ -445,11 +479,11 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
445
479
  });
446
480
  onDeleteCompleted(false);
447
481
  return _context2.abrupt("return", false);
448
- case 21:
482
+ case 23:
449
483
  case "end":
450
484
  return _context2.stop();
451
485
  }
452
- }, _callee2, this, [[0, 15]]);
486
+ }, _callee2, this, [[0, 17]]);
453
487
  }));
454
488
  function _delete(_x, _x2, _x3, _x4) {
455
489
  return _delete2.apply(this, arguments);
@@ -469,20 +503,26 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
469
503
  return _regenerator.default.wrap(function _callee3$(_context3) {
470
504
  while (1) switch (_context3.prev = _context3.next) {
471
505
  case 0:
472
- if (this.deletionRetryInfo) {
506
+ if (!(this.viewMode === 'view' && (0, _platformFeatureFlags.fg)('platform_synced_block_patch_8'))) {
473
507
  _context3.next = 2;
474
508
  break;
475
509
  }
476
510
  return _context3.abrupt("return", Promise.resolve());
477
511
  case 2:
512
+ if (this.deletionRetryInfo) {
513
+ _context3.next = 4;
514
+ break;
515
+ }
516
+ return _context3.abrupt("return", Promise.resolve());
517
+ case 4:
478
518
  _this$deletionRetryIn = this.deletionRetryInfo, syncBlockIds = _this$deletionRetryIn.syncBlockIds, onDelete = _this$deletionRetryIn.onDelete, onDeleteCompleted = _this$deletionRetryIn.onDeleteCompleted, deletionReason = _this$deletionRetryIn.deletionReason;
479
519
  if (!this.confirmationCallback) {
480
- _context3.next = 6;
520
+ _context3.next = 8;
481
521
  break;
482
522
  }
483
- _context3.next = 6;
523
+ _context3.next = 8;
484
524
  return this.delete(syncBlockIds, onDelete, onDeleteCompleted, deletionReason);
485
- case 6:
525
+ case 8:
486
526
  case "end":
487
527
  return _context3.stop();
488
528
  }
@@ -516,21 +556,27 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
516
556
  return _regenerator.default.wrap(function _callee4$(_context4) {
517
557
  while (1) switch (_context4.prev = _context4.next) {
518
558
  case 0:
559
+ if (!(this.viewMode === 'view' && (0, _platformFeatureFlags.fg)('platform_synced_block_patch_8'))) {
560
+ _context4.next = 2;
561
+ break;
562
+ }
563
+ return _context4.abrupt("return", Promise.resolve());
564
+ case 2:
519
565
  if (!this.confirmationCallback) {
520
- _context4.next = 12;
566
+ _context4.next = 14;
521
567
  break;
522
568
  }
523
- _context4.next = 3;
569
+ _context4.next = 5;
524
570
  return this.confirmationCallback(syncBlockIds, deletionReason);
525
- case 3:
571
+ case 5:
526
572
  confirmed = _context4.sent;
527
573
  if (!confirmed) {
528
- _context4.next = 11;
574
+ _context4.next = 13;
529
575
  break;
530
576
  }
531
- _context4.next = 7;
577
+ _context4.next = 9;
532
578
  return this.delete(syncBlockIds, onDelete, onDeleteCompleted, deletionReason);
533
- case 7:
579
+ case 9:
534
580
  isDeleteSuccessful = _context4.sent;
535
581
  if (!isDeleteSuccessful) {
536
582
  // If deletion failed, save deletion info for potential retry
@@ -544,11 +590,11 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
544
590
  } else {
545
591
  destroyCallback();
546
592
  }
547
- _context4.next = 12;
593
+ _context4.next = 14;
548
594
  break;
549
- case 11:
595
+ case 13:
550
596
  destroyCallback();
551
- case 12:
597
+ case 14:
552
598
  case "end":
553
599
  return _context4.stop();
554
600
  }
@@ -27,12 +27,12 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
27
27
  // SourceSyncBlockStoreManager is responsible for the lifecycle and state management of source sync blocks in an editor instance.
28
28
  // Can be used in both editor and renderer contexts.
29
29
  var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/function () {
30
- function SyncBlockStoreManager(dataProvider) {
30
+ function SyncBlockStoreManager(dataProvider, viewMode) {
31
31
  (0, _classCallCheck2.default)(this, SyncBlockStoreManager);
32
32
  // In future, if reference manager needs to reach to source manager and read its current in memory cache
33
33
  // we can pass the source manager as a parameter to the reference manager constructor
34
- this.sourceSyncBlockStoreManager = new _sourceSyncBlockStoreManager.SourceSyncBlockStoreManager(dataProvider);
35
- this.referenceSyncBlockStoreManager = new _referenceSyncBlockStoreManager.ReferenceSyncBlockStoreManager(dataProvider);
34
+ this.sourceSyncBlockStoreManager = new _sourceSyncBlockStoreManager.SourceSyncBlockStoreManager(dataProvider, viewMode);
35
+ this.referenceSyncBlockStoreManager = new _referenceSyncBlockStoreManager.ReferenceSyncBlockStoreManager(dataProvider, viewMode);
36
36
  this.dataProvider = dataProvider;
37
37
  this.referenceSyncBlockStoreManager.setRealTimeSubscriptionsEnabled(true);
38
38
  }
@@ -41,7 +41,7 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
41
41
  value: function () {
42
42
  var _fetchReferencesSourceInfo = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(resourceId, blockInstanceId, isSourceSyncBlock) {
43
43
  var _this = this;
44
- var _this$fetchReferences, _response$references, _this$fetchReferences9, _response$references2, response, _this$fetchReferences2, _this$fetchReferences4, referenceResourceId, hasUnregisteredReferenceOnPage, _this$fetchReferences3, _sourceSyncBlockData, references, unregisteredReferenceData, _this$fetchReferences6, _references, _sourceSyncBlockData2, currentPageData, _this$fetchReferences5, _this$fetchReferences7, _this$fetchReferences8, sourceInfoPromises, sourceInfos, sourceSyncBlockData, _this$fireAnalyticsEv;
44
+ var _this$fetchReferences, _response$references, _this$fetchReferences5, _response$references2, response, _this$fetchReferences2, _this$fetchReferences3, _this$fetchReferences4, sourceInfoPromises, sourceInfos, sourceSyncBlockData, _this$fireAnalyticsEv;
45
45
  return _regenerator.default.wrap(function _callee2$(_context2) {
46
46
  while (1) switch (_context2.prev = _context2.next) {
47
47
  case 0:
@@ -69,114 +69,20 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
69
69
  });
70
70
  case 10:
71
71
  if (!(!response.references || ((_response$references = response.references) === null || _response$references === void 0 ? void 0 : _response$references.length) === 0)) {
72
- _context2.next = 48;
72
+ _context2.next = 17;
73
73
  break;
74
74
  }
75
75
  if (!(0, _platformFeatureFlags.fg)('platform_synced_block_patch_8')) {
76
- _context2.next = 46;
76
+ _context2.next = 15;
77
77
  break;
78
78
  }
79
- if (!isSourceSyncBlock) {
80
- _context2.next = 29;
81
- break;
82
- }
83
- // Verify that a reference sync block for this specific source actually
84
- // exists on the current page by checking if the reference manager has
85
- // an active subscription for the derived reference resourceId.
86
- referenceResourceId = this.referenceSyncBlockStoreManager.generateResourceIdForReference(resourceId);
87
- hasUnregisteredReferenceOnPage = this.referenceSyncBlockStoreManager.getSubscribedResourceIds().includes(referenceResourceId);
88
- if (!hasUnregisteredReferenceOnPage) {
89
- _context2.next = 27;
90
- break;
91
- }
92
- _context2.next = 18;
93
- return this.sourceSyncBlockStoreManager.getSyncBlockSourceInfo(blockInstanceId);
94
- case 18:
95
- _sourceSyncBlockData = _context2.sent;
96
- references = [];
97
- if (_sourceSyncBlockData) {
98
- references.push(_objectSpread(_objectSpread({}, _sourceSyncBlockData), {}, {
99
- onSameDocument: Boolean(_sourceSyncBlockData === null || _sourceSyncBlockData === void 0 ? void 0 : _sourceSyncBlockData.onSameDocument),
100
- hasAccess: true,
101
- isSource: true
102
- }));
103
- }
104
- _context2.next = 23;
105
- return this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfo(referenceResourceId);
106
- case 23:
107
- unregisteredReferenceData = _context2.sent;
108
- if (unregisteredReferenceData) {
109
- references.push(_objectSpread(_objectSpread({}, unregisteredReferenceData), {}, {
110
- onSameDocument: true,
111
- hasAccess: true,
112
- isSource: false
113
- }));
114
- }
115
- (_this$fetchReferences3 = this.fetchReferencesExperience) === null || _this$fetchReferences3 === void 0 || _this$fetchReferences3.success();
116
- return _context2.abrupt("return", {
117
- references: references
118
- });
119
- case 27:
120
- // No remote or local reference exists — show info text with link to doco on how to use Synced Blocks
121
- (_this$fetchReferences4 = this.fetchReferencesExperience) === null || _this$fetchReferences4 === void 0 || _this$fetchReferences4.success();
122
- return _context2.abrupt("return", {
123
- references: []
124
- });
125
- case 29:
126
- if (isSourceSyncBlock) {
127
- _context2.next = 44;
128
- break;
129
- }
130
- // Though no references registered yet for this reference sync block,
131
- // still show the source and the current page itself since they are known
132
- // but not saved yet.
133
- _references = [];
134
- _context2.next = 33;
135
- return this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfo(resourceId);
136
- case 33:
137
- _sourceSyncBlockData2 = _context2.sent;
138
- if (_sourceSyncBlockData2) {
139
- _references.push(_objectSpread(_objectSpread({}, _sourceSyncBlockData2), {}, {
140
- onSameDocument: Boolean(_sourceSyncBlockData2 === null || _sourceSyncBlockData2 === void 0 ? void 0 : _sourceSyncBlockData2.onSameDocument),
141
- hasAccess: true,
142
- isSource: true
143
- }));
144
- }
145
- _context2.next = 37;
146
- return this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfoByLocalId(blockInstanceId);
147
- case 37:
148
- currentPageData = _context2.sent;
149
- if (currentPageData) {
150
- _references.push(_objectSpread(_objectSpread({}, currentPageData), {}, {
151
- onSameDocument: true,
152
- hasAccess: true,
153
- isSource: false
154
- }));
155
- }
156
- if (!(_references.length === 0)) {
157
- _context2.next = 42;
158
- break;
159
- }
160
- (_this$fetchReferences5 = this.fetchReferencesExperience) === null || _this$fetchReferences5 === void 0 || _this$fetchReferences5.failure({
161
- reason: 'No references found for reference synced block'
162
- });
163
- return _context2.abrupt("return", {
164
- error: _types.SyncBlockError.Errored
165
- });
166
- case 42:
167
- (_this$fetchReferences6 = this.fetchReferencesExperience) === null || _this$fetchReferences6 === void 0 || _this$fetchReferences6.success();
168
- return _context2.abrupt("return", {
169
- references: _references
170
- });
171
- case 44:
172
- _context2.next = 48;
173
- break;
174
- case 46:
79
+ return _context2.abrupt("return", this.getUnregisteredReferences(resourceId, blockInstanceId, isSourceSyncBlock));
80
+ case 15:
175
81
  // No reference found
176
82
  if (isSourceSyncBlock) {
177
- (_this$fetchReferences7 = this.fetchReferencesExperience) === null || _this$fetchReferences7 === void 0 || _this$fetchReferences7.success();
83
+ (_this$fetchReferences3 = this.fetchReferencesExperience) === null || _this$fetchReferences3 === void 0 || _this$fetchReferences3.success();
178
84
  } else {
179
- (_this$fetchReferences8 = this.fetchReferencesExperience) === null || _this$fetchReferences8 === void 0 || _this$fetchReferences8.failure({
85
+ (_this$fetchReferences4 = this.fetchReferencesExperience) === null || _this$fetchReferences4 === void 0 || _this$fetchReferences4.failure({
180
86
  reason: 'No references found for reference synced block'
181
87
  });
182
88
  }
@@ -185,8 +91,8 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
185
91
  } : {
186
92
  error: _types.SyncBlockError.Errored
187
93
  });
188
- case 48:
189
- (_this$fetchReferences9 = this.fetchReferencesExperience) === null || _this$fetchReferences9 === void 0 || _this$fetchReferences9.success();
94
+ case 17:
95
+ (_this$fetchReferences5 = this.fetchReferencesExperience) === null || _this$fetchReferences5 === void 0 || _this$fetchReferences5.success();
190
96
  sourceInfoPromises = ((_response$references2 = response.references) !== null && _response$references2 !== void 0 ? _response$references2 : []).map( /*#__PURE__*/function () {
191
97
  var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(reference) {
192
98
  var _this$fetchSourceInfo, _this$dataProvider, _this$fetchSourceInfo3;
@@ -224,13 +130,13 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
224
130
  return _ref.apply(this, arguments);
225
131
  };
226
132
  }());
227
- _context2.next = 52;
133
+ _context2.next = 21;
228
134
  return Promise.all(sourceInfoPromises);
229
- case 52:
135
+ case 21:
230
136
  sourceInfos = _context2.sent;
231
- _context2.next = 55;
137
+ _context2.next = 24;
232
138
  return isSourceSyncBlock ? this.sourceSyncBlockStoreManager.getSyncBlockSourceInfo(blockInstanceId) : this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfo(resourceId);
233
- case 55:
139
+ case 24:
234
140
  sourceSyncBlockData = _context2.sent;
235
141
  if (sourceSyncBlockData) {
236
142
  sourceInfos.push(_objectSpread(_objectSpread({}, sourceSyncBlockData), {}, {
@@ -243,8 +149,8 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
243
149
  return _context2.abrupt("return", {
244
150
  references: sourceInfos
245
151
  });
246
- case 60:
247
- _context2.prev = 60;
152
+ case 29:
153
+ _context2.prev = 29;
248
154
  _context2.t0 = _context2["catch"](0);
249
155
  (0, _monitoring.logException)(_context2.t0, {
250
156
  location: 'editor-synced-block-provider/syncBlockStoreManager'
@@ -253,11 +159,11 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
253
159
  return _context2.abrupt("return", {
254
160
  error: _types.SyncBlockError.Errored
255
161
  });
256
- case 65:
162
+ case 34:
257
163
  case "end":
258
164
  return _context2.stop();
259
165
  }
260
- }, _callee2, this, [[0, 60]]);
166
+ }, _callee2, this, [[0, 29]]);
261
167
  }));
262
168
  function fetchReferencesSourceInfo(_x, _x2, _x3) {
263
169
  return _fetchReferencesSourceInfo.apply(this, arguments);
@@ -286,16 +192,119 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
286
192
  }, {
287
193
  key: "destroy",
288
194
  value: function destroy() {
289
- var _this$fetchReferences0, _this$fetchSourceInfo4;
195
+ var _this$fetchReferences6, _this$fetchSourceInfo4;
290
196
  this.referenceSyncBlockStoreManager.destroy();
291
197
  this.sourceSyncBlockStoreManager.destroy();
292
- (_this$fetchReferences0 = this.fetchReferencesExperience) === null || _this$fetchReferences0 === void 0 || _this$fetchReferences0.abort({
198
+ (_this$fetchReferences6 = this.fetchReferencesExperience) === null || _this$fetchReferences6 === void 0 || _this$fetchReferences6.abort({
293
199
  reason: 'editorDestroyed'
294
200
  });
295
201
  (_this$fetchSourceInfo4 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo4 === void 0 || _this$fetchSourceInfo4.abort({
296
202
  reason: 'editorDestroyed'
297
203
  });
298
204
  }
205
+ }, {
206
+ key: "getUnregisteredReferences",
207
+ value: function () {
208
+ var _getUnregisteredReferences = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(resourceId, blockInstanceId, isSourceSyncBlock) {
209
+ var _this$fetchReferences0;
210
+ var _this$fetchReferences8, referenceResourceId, hasUnregisteredReferenceOnPage, _this$fetchReferences7, _sourceSyncBlockData, _references, sourceSyncBlockReference, referenceSyncBlockReference, references, sourceSyncBlockData, currentPageData, _this$fetchReferences9;
211
+ return _regenerator.default.wrap(function _callee3$(_context3) {
212
+ while (1) switch (_context3.prev = _context3.next) {
213
+ case 0:
214
+ if (!isSourceSyncBlock) {
215
+ _context3.next = 13;
216
+ break;
217
+ }
218
+ // Verify that a reference sync block for this specific source actually
219
+ // exists on the current page by checking if the reference manager has
220
+ // an active subscription for the derived reference resourceId.
221
+ referenceResourceId = this.referenceSyncBlockStoreManager.generateResourceIdForReference(resourceId);
222
+ hasUnregisteredReferenceOnPage = this.referenceSyncBlockStoreManager.getSubscribedResourceIds().includes(referenceResourceId);
223
+ if (!hasUnregisteredReferenceOnPage) {
224
+ _context3.next = 11;
225
+ break;
226
+ }
227
+ _context3.next = 6;
228
+ return this.sourceSyncBlockStoreManager.getSyncBlockSourceInfo(blockInstanceId);
229
+ case 6:
230
+ _sourceSyncBlockData = _context3.sent;
231
+ _references = [];
232
+ if (_sourceSyncBlockData) {
233
+ sourceSyncBlockReference = _objectSpread(_objectSpread({}, _sourceSyncBlockData), {}, {
234
+ onSameDocument: true,
235
+ hasAccess: true,
236
+ isSource: true
237
+ });
238
+ referenceSyncBlockReference = _objectSpread(_objectSpread({}, _sourceSyncBlockData), {}, {
239
+ onSameDocument: true,
240
+ hasAccess: true,
241
+ isSource: false
242
+ });
243
+ _references.push(sourceSyncBlockReference, referenceSyncBlockReference);
244
+ }
245
+ (_this$fetchReferences7 = this.fetchReferencesExperience) === null || _this$fetchReferences7 === void 0 || _this$fetchReferences7.success();
246
+ return _context3.abrupt("return", {
247
+ references: _references
248
+ });
249
+ case 11:
250
+ // No remote or local reference exists — show info text with link to doco on how to use Synced Blocks
251
+ (_this$fetchReferences8 = this.fetchReferencesExperience) === null || _this$fetchReferences8 === void 0 || _this$fetchReferences8.success();
252
+ return _context3.abrupt("return", {
253
+ references: []
254
+ });
255
+ case 13:
256
+ // Though no references registered yet for this reference sync block,
257
+ // still show the source and the current page itself since they are known
258
+ // but not saved yet.
259
+ references = [];
260
+ _context3.next = 16;
261
+ return this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfo(resourceId);
262
+ case 16:
263
+ sourceSyncBlockData = _context3.sent;
264
+ if (sourceSyncBlockData) {
265
+ references.push(_objectSpread(_objectSpread({}, sourceSyncBlockData), {}, {
266
+ onSameDocument: Boolean(sourceSyncBlockData === null || sourceSyncBlockData === void 0 ? void 0 : sourceSyncBlockData.onSameDocument),
267
+ hasAccess: true,
268
+ isSource: true
269
+ }));
270
+ }
271
+ _context3.next = 20;
272
+ return this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfoByLocalId(blockInstanceId);
273
+ case 20:
274
+ currentPageData = _context3.sent;
275
+ if (currentPageData) {
276
+ references.push(_objectSpread(_objectSpread({}, currentPageData), {}, {
277
+ onSameDocument: true,
278
+ hasAccess: true,
279
+ isSource: false
280
+ }));
281
+ }
282
+ if (!(references.length === 0)) {
283
+ _context3.next = 25;
284
+ break;
285
+ }
286
+ (_this$fetchReferences9 = this.fetchReferencesExperience) === null || _this$fetchReferences9 === void 0 || _this$fetchReferences9.failure({
287
+ reason: 'No references found for reference synced block'
288
+ });
289
+ return _context3.abrupt("return", {
290
+ error: _types.SyncBlockError.Errored
291
+ });
292
+ case 25:
293
+ (_this$fetchReferences0 = this.fetchReferencesExperience) === null || _this$fetchReferences0 === void 0 || _this$fetchReferences0.success();
294
+ return _context3.abrupt("return", {
295
+ references: references
296
+ });
297
+ case 27:
298
+ case "end":
299
+ return _context3.stop();
300
+ }
301
+ }, _callee3, this);
302
+ }));
303
+ function getUnregisteredReferences(_x5, _x6, _x7) {
304
+ return _getUnregisteredReferences.apply(this, arguments);
305
+ }
306
+ return getUnregisteredReferences;
307
+ }()
299
308
  }]);
300
309
  }();
301
310
  var createSyncBlockStoreManager = function createSyncBlockStoreManager(dataProvider) {
@@ -1,6 +1,7 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import isEqual from 'lodash/isEqual';
3
3
  import { logException } from '@atlaskit/editor-common/monitoring';
4
+ import { fg } from '@atlaskit/platform-feature-flags';
4
5
  import { SyncBlockError } from '../common/types';
5
6
  import { fetchErrorPayload, fetchSuccessPayload, getSourceInfoErrorPayload, updateReferenceErrorPayload } from '../utils/errorHandling';
6
7
  import { getFetchExperience, getFetchSourceInfoExperience, getSaveReferenceExperience } from '../utils/experienceTracking';
@@ -20,7 +21,7 @@ const CACHE_KEY_PREFIX = 'sync-block-data-';
20
21
  export class ReferenceSyncBlockStoreManager {
21
22
  // Track the setTimeout handle for queued flush so we can cancel it on destroy
22
23
 
23
- constructor(dataProvider) {
24
+ constructor(dataProvider, viewMode) {
24
25
  var _this$dataProvider;
25
26
  // Keeps track of addition and deletion of reference synced blocks on the document
26
27
  // This starts as true to always flush the cache when document is saved for the first time
@@ -33,6 +34,7 @@ export class ReferenceSyncBlockStoreManager {
33
34
  // Track if another flush is needed after the current one completes
34
35
  _defineProperty(this, "flushNeededAfterCurrent", false);
35
36
  this.dataProvider = dataProvider;
37
+ this.viewMode = viewMode;
36
38
  this.syncBlockFetchDataRequests = new Map();
37
39
  this.syncBlockSourceInfoRequests = new Map();
38
40
  this.newlyAddedSyncBlocks = new Set();
@@ -549,6 +551,9 @@ export class ReferenceSyncBlockStoreManager {
549
551
  * @returns true if the reference synced blocks are updated successfully, false otherwise
550
552
  */
551
553
  async flush() {
554
+ if (this.viewMode === 'view' && fg('platform_synced_block_patch_8')) {
555
+ return false;
556
+ }
552
557
  if (!this.isCacheDirty) {
553
558
  // we use the isCacheDirty flag as a quick check.
554
559
  return true;