@atlaskit/editor-synced-block-provider 4.2.11 → 4.3.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,31 @@
1
1
  # @atlaskit/editor-synced-block-provider
2
2
 
3
+ ## 4.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 4.3.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [`5421779d09855`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/5421779d09855) -
14
+ [ux] Fix error state shown in the locations dropdown on a reference sync block when no references
15
+ are registered yet. When the block hasn't been saved, the dropdown now shows the source page and
16
+ the current page instead of an error. An 'Untitled' placeholder is shown when a page has no title.
17
+
18
+ ### Patch Changes
19
+
20
+ - [`f8922537e5ec8`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/f8922537e5ec8) -
21
+ Preserve node referential identity in replaceDocument to prevent ProseMirror view reconciliation
22
+ from unnecessarily destroying and recreating mark wrappers (and their React nodeviews), which
23
+ caused visible flicker on sync blocks and other wrapped nodeviews during collab initialization.
24
+
25
+ Fixes EDITOR-5277.
26
+
27
+ - Updated dependencies
28
+
3
29
  ## 4.2.11
4
30
 
5
31
  ### Patch Changes
@@ -251,6 +251,24 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
251
251
  return Promise.resolve(undefined);
252
252
  }
253
253
  }
254
+ }, {
255
+ key: "fetchSyncBlockSourceInfoByLocalId",
256
+ value: function fetchSyncBlockSourceInfoByLocalId(localId) {
257
+ var hasAccess = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
258
+ try {
259
+ if (!this.dataProvider) {
260
+ throw new Error('Data provider not set');
261
+ }
262
+ return this.dataProvider.fetchSyncBlockSourceInfo(localId, undefined, undefined, hasAccess);
263
+ } catch (error) {
264
+ var _this$fireAnalyticsEv2;
265
+ (0, _monitoring.logException)(error, {
266
+ location: 'editor-synced-block-provider/referenceSyncBlockStoreManager/fetchSyncBlockSourceInfoByLocalId'
267
+ });
268
+ (_this$fireAnalyticsEv2 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv2 === void 0 || _this$fireAnalyticsEv2.call(this, (0, _errorHandling.getSourceInfoErrorPayload)(error.message));
269
+ return Promise.resolve(undefined);
270
+ }
271
+ }
254
272
  }, {
255
273
  key: "fetchSyncBlockSourceInfo",
256
274
  value: function fetchSyncBlockSourceInfo(resourceId) {
@@ -288,8 +306,8 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
288
306
  });
289
307
  }
290
308
  if (!sourceAri || !product || !blockInstanceId) {
291
- var _this$fireAnalyticsEv2;
292
- (_this$fireAnalyticsEv2 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv2 === void 0 || _this$fireAnalyticsEv2.call(this, (0, _errorHandling.getSourceInfoErrorPayload)('SourceAri, product or blockInstanceId missing', resourceId));
309
+ var _this$fireAnalyticsEv3;
310
+ (_this$fireAnalyticsEv3 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv3 === void 0 || _this$fireAnalyticsEv3.call(this, (0, _errorHandling.getSourceInfoErrorPayload)('SourceAri, product or blockInstanceId missing', resourceId));
293
311
  return Promise.resolve(undefined);
294
312
  }
295
313
  (_this$fetchSourceInfo = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo === void 0 || _this$fetchSourceInfo.start({});
@@ -331,11 +349,11 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
331
349
  this.syncBlockSourceInfoRequests.set(resourceId, sourceInfoPromise);
332
350
  return sourceInfoPromise;
333
351
  } catch (error) {
334
- var _this$fireAnalyticsEv3;
352
+ var _this$fireAnalyticsEv4;
335
353
  (0, _monitoring.logException)(error, {
336
354
  location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
337
355
  });
338
- (_this$fireAnalyticsEv3 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv3 === void 0 || _this$fireAnalyticsEv3.call(this, (0, _errorHandling.getSourceInfoErrorPayload)(error.message, resourceId));
356
+ (_this$fireAnalyticsEv4 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv4 === void 0 || _this$fireAnalyticsEv4.call(this, (0, _errorHandling.getSourceInfoErrorPayload)(error.message, resourceId));
339
357
  }
340
358
  return Promise.resolve(undefined);
341
359
  }
@@ -635,11 +653,11 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
635
653
  }
636
654
  return this._subscriptionManager.subscribeToSyncBlock(resourceId, localId, callback);
637
655
  } catch (error) {
638
- var _this$fireAnalyticsEv4;
656
+ var _this$fireAnalyticsEv5;
639
657
  (0, _monitoring.logException)(error, {
640
658
  location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
641
659
  });
642
- (_this$fireAnalyticsEv4 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv4 === void 0 || _this$fireAnalyticsEv4.call(this, (0, _errorHandling.fetchErrorPayload)(error.message));
660
+ (_this$fireAnalyticsEv5 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv5 === void 0 || _this$fireAnalyticsEv5.call(this, (0, _errorHandling.fetchErrorPayload)(error.message));
643
661
  return function () {};
644
662
  }
645
663
  }
@@ -680,7 +698,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
680
698
  value: (function () {
681
699
  var _flush = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
682
700
  var _this7 = this;
683
- var success, syncedBlocksToFlush, _this$saveExperience, blocks, _iterator, _step, _loop, updateResult, _this$saveExperience2, _this$fireAnalyticsEv5, _this$saveExperience3, _this$fireAnalyticsEv6, _this$saveExperience4;
701
+ var success, syncedBlocksToFlush, _this$saveExperience, blocks, _iterator, _step, _loop, updateResult, _this$saveExperience2, _this$fireAnalyticsEv6, _this$saveExperience3, _this$fireAnalyticsEv7, _this$saveExperience4;
684
702
  return _regenerator.default.wrap(function _callee3$(_context4) {
685
703
  while (1) switch (_context4.prev = _context4.next) {
686
704
  case 0:
@@ -780,7 +798,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
780
798
  (_this$saveExperience2 = this.saveExperience) === null || _this$saveExperience2 === void 0 || _this$saveExperience2.failure({
781
799
  reason: updateResult.error || 'Failed to update reference synced blocks on the document'
782
800
  });
783
- (_this$fireAnalyticsEv5 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv5 === void 0 || _this$fireAnalyticsEv5.call(this, (0, _errorHandling.updateReferenceErrorPayload)(updateResult.error || 'Failed to update reference synced blocks on the document'));
801
+ (_this$fireAnalyticsEv6 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv6 === void 0 || _this$fireAnalyticsEv6.call(this, (0, _errorHandling.updateReferenceErrorPayload)(updateResult.error || 'Failed to update reference synced blocks on the document'));
784
802
  }
785
803
  _context4.next = 47;
786
804
  break;
@@ -794,7 +812,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
794
812
  (_this$saveExperience3 = this.saveExperience) === null || _this$saveExperience3 === void 0 || _this$saveExperience3.failure({
795
813
  reason: _context4.t2.message
796
814
  });
797
- (_this$fireAnalyticsEv6 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv6 === void 0 || _this$fireAnalyticsEv6.call(this, (0, _errorHandling.updateReferenceErrorPayload)(_context4.t2.message));
815
+ (_this$fireAnalyticsEv7 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv7 === void 0 || _this$fireAnalyticsEv7.call(this, (0, _errorHandling.updateReferenceErrorPayload)(_context4.t2.message));
798
816
  case 47:
799
817
  _context4.prev = 47;
800
818
  if (!success) {
@@ -12,6 +12,7 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl
12
12
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
13
  var _react = require("react");
14
14
  var _monitoring = require("@atlaskit/editor-common/monitoring");
15
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
15
16
  var _ari = require("../clients/block-service/ari");
16
17
  var _types = require("../common/types");
17
18
  var _errorHandling = require("../utils/errorHandling");
@@ -40,7 +41,7 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
40
41
  value: function () {
41
42
  var _fetchReferencesSourceInfo = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(resourceId, blockInstanceId, isSourceSyncBlock) {
42
43
  var _this = this;
43
- var _this$fetchReferences, _response$references, _this$fetchReferences5, response, _this$fetchReferences2, _this$fetchReferences3, _this$fetchReferences4, sourceInfoPromises, sourceInfos, sourceSyncBlockData, _this$fireAnalyticsEv;
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
45
  return _regenerator.default.wrap(function _callee2$(_context2) {
45
46
  while (1) switch (_context2.prev = _context2.next) {
46
47
  case 0:
@@ -68,14 +69,114 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
68
69
  });
69
70
  case 10:
70
71
  if (!(!response.references || ((_response$references = response.references) === null || _response$references === void 0 ? void 0 : _response$references.length) === 0)) {
71
- _context2.next = 13;
72
+ _context2.next = 48;
72
73
  break;
73
74
  }
75
+ if (!(0, _platformFeatureFlags.fg)('platform_synced_block_patch_8')) {
76
+ _context2.next = 46;
77
+ break;
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:
74
175
  // No reference found
75
176
  if (isSourceSyncBlock) {
76
- (_this$fetchReferences3 = this.fetchReferencesExperience) === null || _this$fetchReferences3 === void 0 || _this$fetchReferences3.success();
177
+ (_this$fetchReferences7 = this.fetchReferencesExperience) === null || _this$fetchReferences7 === void 0 || _this$fetchReferences7.success();
77
178
  } else {
78
- (_this$fetchReferences4 = this.fetchReferencesExperience) === null || _this$fetchReferences4 === void 0 || _this$fetchReferences4.failure({
179
+ (_this$fetchReferences8 = this.fetchReferencesExperience) === null || _this$fetchReferences8 === void 0 || _this$fetchReferences8.failure({
79
180
  reason: 'No references found for reference synced block'
80
181
  });
81
182
  }
@@ -84,9 +185,9 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
84
185
  } : {
85
186
  error: _types.SyncBlockError.Errored
86
187
  });
87
- case 13:
88
- (_this$fetchReferences5 = this.fetchReferencesExperience) === null || _this$fetchReferences5 === void 0 || _this$fetchReferences5.success();
89
- sourceInfoPromises = response.references.map( /*#__PURE__*/function () {
188
+ case 48:
189
+ (_this$fetchReferences9 = this.fetchReferencesExperience) === null || _this$fetchReferences9 === void 0 || _this$fetchReferences9.success();
190
+ sourceInfoPromises = ((_response$references2 = response.references) !== null && _response$references2 !== void 0 ? _response$references2 : []).map( /*#__PURE__*/function () {
90
191
  var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(reference) {
91
192
  var _this$fetchSourceInfo, _this$dataProvider, _this$fetchSourceInfo3;
92
193
  var sourceInfo, _this$fetchSourceInfo2;
@@ -123,13 +224,13 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
123
224
  return _ref.apply(this, arguments);
124
225
  };
125
226
  }());
126
- _context2.next = 17;
227
+ _context2.next = 52;
127
228
  return Promise.all(sourceInfoPromises);
128
- case 17:
229
+ case 52:
129
230
  sourceInfos = _context2.sent;
130
- _context2.next = 20;
231
+ _context2.next = 55;
131
232
  return isSourceSyncBlock ? this.sourceSyncBlockStoreManager.getSyncBlockSourceInfo(blockInstanceId) : this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfo(resourceId);
132
- case 20:
233
+ case 55:
133
234
  sourceSyncBlockData = _context2.sent;
134
235
  if (sourceSyncBlockData) {
135
236
  sourceInfos.push(_objectSpread(_objectSpread({}, sourceSyncBlockData), {}, {
@@ -142,8 +243,8 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
142
243
  return _context2.abrupt("return", {
143
244
  references: sourceInfos
144
245
  });
145
- case 25:
146
- _context2.prev = 25;
246
+ case 60:
247
+ _context2.prev = 60;
147
248
  _context2.t0 = _context2["catch"](0);
148
249
  (0, _monitoring.logException)(_context2.t0, {
149
250
  location: 'editor-synced-block-provider/syncBlockStoreManager'
@@ -152,11 +253,11 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
152
253
  return _context2.abrupt("return", {
153
254
  error: _types.SyncBlockError.Errored
154
255
  });
155
- case 30:
256
+ case 65:
156
257
  case "end":
157
258
  return _context2.stop();
158
259
  }
159
- }, _callee2, this, [[0, 25]]);
260
+ }, _callee2, this, [[0, 60]]);
160
261
  }));
161
262
  function fetchReferencesSourceInfo(_x, _x2, _x3) {
162
263
  return _fetchReferencesSourceInfo.apply(this, arguments);
@@ -185,10 +286,10 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
185
286
  }, {
186
287
  key: "destroy",
187
288
  value: function destroy() {
188
- var _this$fetchReferences6, _this$fetchSourceInfo4;
289
+ var _this$fetchReferences0, _this$fetchSourceInfo4;
189
290
  this.referenceSyncBlockStoreManager.destroy();
190
291
  this.sourceSyncBlockStoreManager.destroy();
191
- (_this$fetchReferences6 = this.fetchReferencesExperience) === null || _this$fetchReferences6 === void 0 || _this$fetchReferences6.abort({
292
+ (_this$fetchReferences0 = this.fetchReferencesExperience) === null || _this$fetchReferences0 === void 0 || _this$fetchReferences0.abort({
192
293
  reason: 'editorDestroyed'
193
294
  });
194
295
  (_this$fetchSourceInfo4 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo4 === void 0 || _this$fetchSourceInfo4.abort({
@@ -177,6 +177,21 @@ export class ReferenceSyncBlockStoreManager {
177
177
  return Promise.resolve(undefined);
178
178
  }
179
179
  }
180
+ fetchSyncBlockSourceInfoByLocalId(localId, hasAccess = true) {
181
+ try {
182
+ if (!this.dataProvider) {
183
+ throw new Error('Data provider not set');
184
+ }
185
+ return this.dataProvider.fetchSyncBlockSourceInfo(localId, undefined, undefined, hasAccess);
186
+ } catch (error) {
187
+ var _this$fireAnalyticsEv2;
188
+ logException(error, {
189
+ location: 'editor-synced-block-provider/referenceSyncBlockStoreManager/fetchSyncBlockSourceInfoByLocalId'
190
+ });
191
+ (_this$fireAnalyticsEv2 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv2 === void 0 ? void 0 : _this$fireAnalyticsEv2.call(this, getSourceInfoErrorPayload(error.message));
192
+ return Promise.resolve(undefined);
193
+ }
194
+ }
180
195
  fetchSyncBlockSourceInfo(resourceId) {
181
196
  try {
182
197
  var _this$fetchSourceInfo;
@@ -212,19 +227,19 @@ export class ReferenceSyncBlockStoreManager {
212
227
  });
213
228
  }
214
229
  if (!sourceAri || !product || !blockInstanceId) {
215
- var _this$fireAnalyticsEv2;
216
- (_this$fireAnalyticsEv2 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv2 === void 0 ? void 0 : _this$fireAnalyticsEv2.call(this, getSourceInfoErrorPayload('SourceAri, product or blockInstanceId missing', resourceId));
230
+ var _this$fireAnalyticsEv3;
231
+ (_this$fireAnalyticsEv3 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv3 === void 0 ? void 0 : _this$fireAnalyticsEv3.call(this, getSourceInfoErrorPayload('SourceAri, product or blockInstanceId missing', resourceId));
217
232
  return Promise.resolve(undefined);
218
233
  }
219
234
  (_this$fetchSourceInfo = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo === void 0 ? void 0 : _this$fetchSourceInfo.start({});
220
235
  const sourceInfoPromise = this.dataProvider.fetchSyncBlockSourceInfo(blockInstanceId, sourceAri, product, true // hasAccess
221
236
  ).then(sourceInfo => {
222
237
  if (!sourceInfo) {
223
- var _this$fetchSourceInfo2, _this$fireAnalyticsEv3;
238
+ var _this$fetchSourceInfo2, _this$fireAnalyticsEv4;
224
239
  (_this$fetchSourceInfo2 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo2 === void 0 ? void 0 : _this$fetchSourceInfo2.failure({
225
240
  reason: 'No source info returned'
226
241
  });
227
- (_this$fireAnalyticsEv3 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv3 === void 0 ? void 0 : _this$fireAnalyticsEv3.call(this, getSourceInfoErrorPayload('No source info returned', resourceId));
242
+ (_this$fireAnalyticsEv4 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv4 === void 0 ? void 0 : _this$fireAnalyticsEv4.call(this, getSourceInfoErrorPayload('No source info returned', resourceId));
228
243
  return undefined;
229
244
  }
230
245
  this.updateCacheWithSourceInfo(resourceId, sourceInfo);
@@ -235,19 +250,19 @@ export class ReferenceSyncBlockStoreManager {
235
250
  var _this$fetchSourceInfo3;
236
251
  (_this$fetchSourceInfo3 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo3 === void 0 ? void 0 : _this$fetchSourceInfo3.success();
237
252
  } else {
238
- var _this$fetchSourceInfo4, _this$fireAnalyticsEv4;
253
+ var _this$fetchSourceInfo4, _this$fireAnalyticsEv5;
239
254
  (_this$fetchSourceInfo4 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo4 === void 0 ? void 0 : _this$fetchSourceInfo4.failure({
240
255
  reason: 'Missing title or url'
241
256
  });
242
- (_this$fireAnalyticsEv4 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv4 === void 0 ? void 0 : _this$fireAnalyticsEv4.call(this, getSourceInfoErrorPayload('Missing title or url', resourceId));
257
+ (_this$fireAnalyticsEv5 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv5 === void 0 ? void 0 : _this$fireAnalyticsEv5.call(this, getSourceInfoErrorPayload('Missing title or url', resourceId));
243
258
  }
244
259
  return sourceInfo;
245
260
  }).catch(error => {
246
- var _this$fetchSourceInfo5, _this$fireAnalyticsEv5;
261
+ var _this$fetchSourceInfo5, _this$fireAnalyticsEv6;
247
262
  (_this$fetchSourceInfo5 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo5 === void 0 ? void 0 : _this$fetchSourceInfo5.failure({
248
263
  reason: error.message
249
264
  });
250
- (_this$fireAnalyticsEv5 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv5 === void 0 ? void 0 : _this$fireAnalyticsEv5.call(this, getSourceInfoErrorPayload(error.message, resourceId));
265
+ (_this$fireAnalyticsEv6 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv6 === void 0 ? void 0 : _this$fireAnalyticsEv6.call(this, getSourceInfoErrorPayload(error.message, resourceId));
251
266
  return undefined;
252
267
  }).finally(() => {
253
268
  this.syncBlockSourceInfoRequests.delete(resourceId);
@@ -255,11 +270,11 @@ export class ReferenceSyncBlockStoreManager {
255
270
  this.syncBlockSourceInfoRequests.set(resourceId, sourceInfoPromise);
256
271
  return sourceInfoPromise;
257
272
  } catch (error) {
258
- var _this$fireAnalyticsEv6;
273
+ var _this$fireAnalyticsEv7;
259
274
  logException(error, {
260
275
  location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
261
276
  });
262
- (_this$fireAnalyticsEv6 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv6 === void 0 ? void 0 : _this$fireAnalyticsEv6.call(this, getSourceInfoErrorPayload(error.message, resourceId));
277
+ (_this$fireAnalyticsEv7 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv7 === void 0 ? void 0 : _this$fireAnalyticsEv7.call(this, getSourceInfoErrorPayload(error.message, resourceId));
263
278
  }
264
279
  return Promise.resolve(undefined);
265
280
  }
@@ -385,9 +400,9 @@ export class ReferenceSyncBlockStoreManager {
385
400
  data.forEach(syncBlockInstance => {
386
401
  var _resolvedSyncBlockIns;
387
402
  if (!syncBlockInstance.resourceId) {
388
- var _syncBlockInstance$er, _syncBlockInstance$er2, _this$fireAnalyticsEv7;
403
+ var _syncBlockInstance$er, _syncBlockInstance$er2, _this$fireAnalyticsEv8;
389
404
  const payload = ((_syncBlockInstance$er = syncBlockInstance.error) === null || _syncBlockInstance$er === void 0 ? void 0 : _syncBlockInstance$er.reason) || ((_syncBlockInstance$er2 = syncBlockInstance.error) === null || _syncBlockInstance$er2 === void 0 ? void 0 : _syncBlockInstance$er2.type) || 'Returned sync block instance does not have resource id';
390
- (_this$fireAnalyticsEv7 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv7 === void 0 ? void 0 : _this$fireAnalyticsEv7.call(this, fetchErrorPayload(payload));
405
+ (_this$fireAnalyticsEv8 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv8 === void 0 ? void 0 : _this$fireAnalyticsEv8.call(this, fetchErrorPayload(payload));
391
406
  return;
392
407
  }
393
408
  const existingSyncBlock = this.getFromCache(syncBlockInstance.resourceId);
@@ -405,8 +420,8 @@ export class ReferenceSyncBlockStoreManager {
405
420
  this.newlyAddedSyncBlocks.delete(syncBlockInstance.resourceId);
406
421
  }
407
422
  if (syncBlockInstance.error) {
408
- var _this$fireAnalyticsEv8;
409
- (_this$fireAnalyticsEv8 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv8 === void 0 ? void 0 : _this$fireAnalyticsEv8.call(this, fetchErrorPayload(syncBlockInstance.error.reason || syncBlockInstance.error.type, syncBlockInstance.resourceId));
423
+ var _this$fireAnalyticsEv9;
424
+ (_this$fireAnalyticsEv9 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv9 === void 0 ? void 0 : _this$fireAnalyticsEv9.call(this, fetchErrorPayload(syncBlockInstance.error.reason || syncBlockInstance.error.type, syncBlockInstance.resourceId));
410
425
  if (syncBlockInstance.error.type === SyncBlockError.NotFound || syncBlockInstance.error.type === SyncBlockError.Forbidden) {
411
426
  hasExpectedError = true;
412
427
  } else if (syncBlockInstance.error) {
@@ -417,8 +432,8 @@ export class ReferenceSyncBlockStoreManager {
417
432
  const callbacks = this._subscriptionManager.getSubscriptions().get(syncBlockInstance.resourceId);
418
433
  const localIds = callbacks ? Object.keys(callbacks) : [];
419
434
  localIds.forEach(localId => {
420
- var _this$fireAnalyticsEv9, _syncBlockInstance$da;
421
- (_this$fireAnalyticsEv9 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv9 === void 0 ? void 0 : _this$fireAnalyticsEv9.call(this, fetchSuccessPayload(syncBlockInstance.resourceId, localId, (_syncBlockInstance$da = syncBlockInstance.data) === null || _syncBlockInstance$da === void 0 ? void 0 : _syncBlockInstance$da.product));
435
+ var _this$fireAnalyticsEv0, _syncBlockInstance$da;
436
+ (_this$fireAnalyticsEv0 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv0 === void 0 ? void 0 : _this$fireAnalyticsEv0.call(this, fetchSuccessPayload(syncBlockInstance.resourceId, localId, (_syncBlockInstance$da = syncBlockInstance.data) === null || _syncBlockInstance$da === void 0 ? void 0 : _syncBlockInstance$da.product));
422
437
  });
423
438
  this.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
424
439
  });
@@ -499,11 +514,11 @@ export class ReferenceSyncBlockStoreManager {
499
514
  }
500
515
  return this._subscriptionManager.subscribeToSyncBlock(resourceId, localId, callback);
501
516
  } catch (error) {
502
- var _this$fireAnalyticsEv0;
517
+ var _this$fireAnalyticsEv1;
503
518
  logException(error, {
504
519
  location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
505
520
  });
506
- (_this$fireAnalyticsEv0 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv0 === void 0 ? void 0 : _this$fireAnalyticsEv0.call(this, fetchErrorPayload(error.message));
521
+ (_this$fireAnalyticsEv1 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv1 === void 0 ? void 0 : _this$fireAnalyticsEv1.call(this, fetchErrorPayload(error.message));
507
522
  return () => {};
508
523
  }
509
524
  }
@@ -590,15 +605,15 @@ export class ReferenceSyncBlockStoreManager {
590
605
  (_this$saveExperience = this.saveExperience) === null || _this$saveExperience === void 0 ? void 0 : _this$saveExperience.start();
591
606
  const updateResult = await this.dataProvider.updateReferenceData(blocks);
592
607
  if (!updateResult.success) {
593
- var _this$saveExperience2, _this$fireAnalyticsEv1;
608
+ var _this$saveExperience2, _this$fireAnalyticsEv10;
594
609
  success = false;
595
610
  (_this$saveExperience2 = this.saveExperience) === null || _this$saveExperience2 === void 0 ? void 0 : _this$saveExperience2.failure({
596
611
  reason: updateResult.error || 'Failed to update reference synced blocks on the document'
597
612
  });
598
- (_this$fireAnalyticsEv1 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv1 === void 0 ? void 0 : _this$fireAnalyticsEv1.call(this, updateReferenceErrorPayload(updateResult.error || 'Failed to update reference synced blocks on the document'));
613
+ (_this$fireAnalyticsEv10 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv10 === void 0 ? void 0 : _this$fireAnalyticsEv10.call(this, updateReferenceErrorPayload(updateResult.error || 'Failed to update reference synced blocks on the document'));
599
614
  }
600
615
  } catch (error) {
601
- var _this$saveExperience3, _this$fireAnalyticsEv10;
616
+ var _this$saveExperience3, _this$fireAnalyticsEv11;
602
617
  success = false;
603
618
  logException(error, {
604
619
  location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
@@ -606,7 +621,7 @@ export class ReferenceSyncBlockStoreManager {
606
621
  (_this$saveExperience3 = this.saveExperience) === null || _this$saveExperience3 === void 0 ? void 0 : _this$saveExperience3.failure({
607
622
  reason: error.message
608
623
  });
609
- (_this$fireAnalyticsEv10 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv10 === void 0 ? void 0 : _this$fireAnalyticsEv10.call(this, updateReferenceErrorPayload(error.message));
624
+ (_this$fireAnalyticsEv11 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv11 === void 0 ? void 0 : _this$fireAnalyticsEv11.call(this, updateReferenceErrorPayload(error.message));
610
625
  } finally {
611
626
  if (!success) {
612
627
  // set isCacheDirty back to true for cases where it failed to update the reference synced blocks on the BE
@@ -1,5 +1,6 @@
1
1
  import { useMemo, useRef } from 'react';
2
2
  import { logException } from '@atlaskit/editor-common/monitoring';
3
+ import { fg } from '@atlaskit/platform-feature-flags';
3
4
  import { getProductFromSourceAri } from '../clients/block-service/ari';
4
5
  import { SyncBlockError } from '../common/types';
5
6
  import { fetchReferencesErrorPayload } from '../utils/errorHandling';
@@ -23,7 +24,7 @@ export class SyncBlockStoreManager {
23
24
  }
24
25
  async fetchReferencesSourceInfo(resourceId, blockInstanceId, isSourceSyncBlock) {
25
26
  try {
26
- var _this$fetchReferences, _response$references, _this$fetchReferences5;
27
+ var _this$fetchReferences, _response$references, _this$fetchReferences9, _response$references2;
27
28
  if (!this.dataProvider) {
28
29
  throw new Error('Data provider not set');
29
30
  }
@@ -39,24 +40,107 @@ export class SyncBlockStoreManager {
39
40
  };
40
41
  }
41
42
  if (!response.references || ((_response$references = response.references) === null || _response$references === void 0 ? void 0 : _response$references.length) === 0) {
42
- // No reference found
43
- if (isSourceSyncBlock) {
44
- var _this$fetchReferences3;
45
- (_this$fetchReferences3 = this.fetchReferencesExperience) === null || _this$fetchReferences3 === void 0 ? void 0 : _this$fetchReferences3.success();
43
+ if (fg('platform_synced_block_patch_8')) {
44
+ // No reference found
45
+ if (isSourceSyncBlock) {
46
+ var _this$fetchReferences4;
47
+ // Verify that a reference sync block for this specific source actually
48
+ // exists on the current page by checking if the reference manager has
49
+ // an active subscription for the derived reference resourceId.
50
+ const referenceResourceId = this.referenceSyncBlockStoreManager.generateResourceIdForReference(resourceId);
51
+ const hasUnregisteredReferenceOnPage = this.referenceSyncBlockStoreManager.getSubscribedResourceIds().includes(referenceResourceId);
52
+ if (hasUnregisteredReferenceOnPage) {
53
+ var _this$fetchReferences3;
54
+ // This is current page data. It is the same for data for source and reference
55
+ const sourceSyncBlockData = await this.sourceSyncBlockStoreManager.getSyncBlockSourceInfo(blockInstanceId);
56
+ const references = [];
57
+ if (sourceSyncBlockData) {
58
+ references.push({
59
+ ...sourceSyncBlockData,
60
+ onSameDocument: Boolean(sourceSyncBlockData === null || sourceSyncBlockData === void 0 ? void 0 : sourceSyncBlockData.onSameDocument),
61
+ hasAccess: true,
62
+ isSource: true
63
+ });
64
+ }
65
+ const unregisteredReferenceData = await this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfo(referenceResourceId);
66
+ if (unregisteredReferenceData) {
67
+ references.push({
68
+ ...unregisteredReferenceData,
69
+ onSameDocument: true,
70
+ hasAccess: true,
71
+ isSource: false
72
+ });
73
+ }
74
+ (_this$fetchReferences3 = this.fetchReferencesExperience) === null || _this$fetchReferences3 === void 0 ? void 0 : _this$fetchReferences3.success();
75
+ return {
76
+ references
77
+ };
78
+ }
79
+
80
+ // No remote or local reference exists — show info text with link to doco on how to use Synced Blocks
81
+ (_this$fetchReferences4 = this.fetchReferencesExperience) === null || _this$fetchReferences4 === void 0 ? void 0 : _this$fetchReferences4.success();
82
+ return {
83
+ references: []
84
+ };
85
+ }
86
+ if (!isSourceSyncBlock) {
87
+ var _this$fetchReferences6;
88
+ // Though no references registered yet for this reference sync block,
89
+ // still show the source and the current page itself since they are known
90
+ // but not saved yet.
91
+ const references = [];
92
+ const sourceSyncBlockData = await this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfo(resourceId);
93
+ if (sourceSyncBlockData) {
94
+ references.push({
95
+ ...sourceSyncBlockData,
96
+ onSameDocument: Boolean(sourceSyncBlockData === null || sourceSyncBlockData === void 0 ? void 0 : sourceSyncBlockData.onSameDocument),
97
+ hasAccess: true,
98
+ isSource: true
99
+ });
100
+ }
101
+ const currentPageData = await this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfoByLocalId(blockInstanceId);
102
+ if (currentPageData) {
103
+ references.push({
104
+ ...currentPageData,
105
+ onSameDocument: true,
106
+ hasAccess: true,
107
+ isSource: false
108
+ });
109
+ }
110
+ if (references.length === 0) {
111
+ var _this$fetchReferences5;
112
+ (_this$fetchReferences5 = this.fetchReferencesExperience) === null || _this$fetchReferences5 === void 0 ? void 0 : _this$fetchReferences5.failure({
113
+ reason: 'No references found for reference synced block'
114
+ });
115
+ return {
116
+ error: SyncBlockError.Errored
117
+ };
118
+ }
119
+ (_this$fetchReferences6 = this.fetchReferencesExperience) === null || _this$fetchReferences6 === void 0 ? void 0 : _this$fetchReferences6.success();
120
+ return {
121
+ references
122
+ };
123
+ }
46
124
  } else {
47
- var _this$fetchReferences4;
48
- (_this$fetchReferences4 = this.fetchReferencesExperience) === null || _this$fetchReferences4 === void 0 ? void 0 : _this$fetchReferences4.failure({
49
- reason: 'No references found for reference synced block'
50
- });
125
+ // No reference found
126
+ if (isSourceSyncBlock) {
127
+ var _this$fetchReferences7;
128
+ (_this$fetchReferences7 = this.fetchReferencesExperience) === null || _this$fetchReferences7 === void 0 ? void 0 : _this$fetchReferences7.success();
129
+ } else {
130
+ var _this$fetchReferences8;
131
+ (_this$fetchReferences8 = this.fetchReferencesExperience) === null || _this$fetchReferences8 === void 0 ? void 0 : _this$fetchReferences8.failure({
132
+ reason: 'No references found for reference synced block'
133
+ });
134
+ }
135
+ return isSourceSyncBlock ? {
136
+ references: []
137
+ } : {
138
+ error: SyncBlockError.Errored
139
+ };
51
140
  }
52
- return isSourceSyncBlock ? {
53
- references: []
54
- } : {
55
- error: SyncBlockError.Errored
56
- };
57
141
  }
58
- (_this$fetchReferences5 = this.fetchReferencesExperience) === null || _this$fetchReferences5 === void 0 ? void 0 : _this$fetchReferences5.success();
59
- const sourceInfoPromises = response.references.map(async reference => {
142
+ (_this$fetchReferences9 = this.fetchReferencesExperience) === null || _this$fetchReferences9 === void 0 ? void 0 : _this$fetchReferences9.success();
143
+ const sourceInfoPromises = ((_response$references2 = response.references) !== null && _response$references2 !== void 0 ? _response$references2 : []).map(async reference => {
60
144
  var _this$fetchSourceInfo, _this$dataProvider, _this$fetchSourceInfo3;
61
145
  (_this$fetchSourceInfo = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo === void 0 ? void 0 : _this$fetchSourceInfo.start();
62
146
  const sourceInfo = await ((_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.fetchSyncBlockSourceInfo(reference.blockInstanceId || '', reference.documentAri, getProductFromSourceAri(reference.documentAri), reference.hasAccess));
@@ -114,10 +198,10 @@ export class SyncBlockStoreManager {
114
198
  return this.sourceSyncBlockStoreManager;
115
199
  }
116
200
  destroy() {
117
- var _this$fetchReferences6, _this$fetchSourceInfo4;
201
+ var _this$fetchReferences0, _this$fetchSourceInfo4;
118
202
  this.referenceSyncBlockStoreManager.destroy();
119
203
  this.sourceSyncBlockStoreManager.destroy();
120
- (_this$fetchReferences6 = this.fetchReferencesExperience) === null || _this$fetchReferences6 === void 0 ? void 0 : _this$fetchReferences6.abort({
204
+ (_this$fetchReferences0 = this.fetchReferencesExperience) === null || _this$fetchReferences0 === void 0 ? void 0 : _this$fetchReferences0.abort({
121
205
  reason: 'editorDestroyed'
122
206
  });
123
207
  (_this$fetchSourceInfo4 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo4 === void 0 ? void 0 : _this$fetchSourceInfo4.abort({
@@ -244,6 +244,24 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
244
244
  return Promise.resolve(undefined);
245
245
  }
246
246
  }
247
+ }, {
248
+ key: "fetchSyncBlockSourceInfoByLocalId",
249
+ value: function fetchSyncBlockSourceInfoByLocalId(localId) {
250
+ var hasAccess = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
251
+ try {
252
+ if (!this.dataProvider) {
253
+ throw new Error('Data provider not set');
254
+ }
255
+ return this.dataProvider.fetchSyncBlockSourceInfo(localId, undefined, undefined, hasAccess);
256
+ } catch (error) {
257
+ var _this$fireAnalyticsEv2;
258
+ logException(error, {
259
+ location: 'editor-synced-block-provider/referenceSyncBlockStoreManager/fetchSyncBlockSourceInfoByLocalId'
260
+ });
261
+ (_this$fireAnalyticsEv2 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv2 === void 0 || _this$fireAnalyticsEv2.call(this, getSourceInfoErrorPayload(error.message));
262
+ return Promise.resolve(undefined);
263
+ }
264
+ }
247
265
  }, {
248
266
  key: "fetchSyncBlockSourceInfo",
249
267
  value: function fetchSyncBlockSourceInfo(resourceId) {
@@ -281,8 +299,8 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
281
299
  });
282
300
  }
283
301
  if (!sourceAri || !product || !blockInstanceId) {
284
- var _this$fireAnalyticsEv2;
285
- (_this$fireAnalyticsEv2 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv2 === void 0 || _this$fireAnalyticsEv2.call(this, getSourceInfoErrorPayload('SourceAri, product or blockInstanceId missing', resourceId));
302
+ var _this$fireAnalyticsEv3;
303
+ (_this$fireAnalyticsEv3 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv3 === void 0 || _this$fireAnalyticsEv3.call(this, getSourceInfoErrorPayload('SourceAri, product or blockInstanceId missing', resourceId));
286
304
  return Promise.resolve(undefined);
287
305
  }
288
306
  (_this$fetchSourceInfo = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo === void 0 || _this$fetchSourceInfo.start({});
@@ -324,11 +342,11 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
324
342
  this.syncBlockSourceInfoRequests.set(resourceId, sourceInfoPromise);
325
343
  return sourceInfoPromise;
326
344
  } catch (error) {
327
- var _this$fireAnalyticsEv3;
345
+ var _this$fireAnalyticsEv4;
328
346
  logException(error, {
329
347
  location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
330
348
  });
331
- (_this$fireAnalyticsEv3 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv3 === void 0 || _this$fireAnalyticsEv3.call(this, getSourceInfoErrorPayload(error.message, resourceId));
349
+ (_this$fireAnalyticsEv4 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv4 === void 0 || _this$fireAnalyticsEv4.call(this, getSourceInfoErrorPayload(error.message, resourceId));
332
350
  }
333
351
  return Promise.resolve(undefined);
334
352
  }
@@ -628,11 +646,11 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
628
646
  }
629
647
  return this._subscriptionManager.subscribeToSyncBlock(resourceId, localId, callback);
630
648
  } catch (error) {
631
- var _this$fireAnalyticsEv4;
649
+ var _this$fireAnalyticsEv5;
632
650
  logException(error, {
633
651
  location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
634
652
  });
635
- (_this$fireAnalyticsEv4 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv4 === void 0 || _this$fireAnalyticsEv4.call(this, fetchErrorPayload(error.message));
653
+ (_this$fireAnalyticsEv5 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv5 === void 0 || _this$fireAnalyticsEv5.call(this, fetchErrorPayload(error.message));
636
654
  return function () {};
637
655
  }
638
656
  }
@@ -673,7 +691,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
673
691
  value: (function () {
674
692
  var _flush = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
675
693
  var _this7 = this;
676
- var success, syncedBlocksToFlush, _this$saveExperience, blocks, _iterator, _step, _loop, updateResult, _this$saveExperience2, _this$fireAnalyticsEv5, _this$saveExperience3, _this$fireAnalyticsEv6, _this$saveExperience4;
694
+ var success, syncedBlocksToFlush, _this$saveExperience, blocks, _iterator, _step, _loop, updateResult, _this$saveExperience2, _this$fireAnalyticsEv6, _this$saveExperience3, _this$fireAnalyticsEv7, _this$saveExperience4;
677
695
  return _regeneratorRuntime.wrap(function _callee3$(_context4) {
678
696
  while (1) switch (_context4.prev = _context4.next) {
679
697
  case 0:
@@ -773,7 +791,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
773
791
  (_this$saveExperience2 = this.saveExperience) === null || _this$saveExperience2 === void 0 || _this$saveExperience2.failure({
774
792
  reason: updateResult.error || 'Failed to update reference synced blocks on the document'
775
793
  });
776
- (_this$fireAnalyticsEv5 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv5 === void 0 || _this$fireAnalyticsEv5.call(this, updateReferenceErrorPayload(updateResult.error || 'Failed to update reference synced blocks on the document'));
794
+ (_this$fireAnalyticsEv6 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv6 === void 0 || _this$fireAnalyticsEv6.call(this, updateReferenceErrorPayload(updateResult.error || 'Failed to update reference synced blocks on the document'));
777
795
  }
778
796
  _context4.next = 47;
779
797
  break;
@@ -787,7 +805,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
787
805
  (_this$saveExperience3 = this.saveExperience) === null || _this$saveExperience3 === void 0 || _this$saveExperience3.failure({
788
806
  reason: _context4.t2.message
789
807
  });
790
- (_this$fireAnalyticsEv6 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv6 === void 0 || _this$fireAnalyticsEv6.call(this, updateReferenceErrorPayload(_context4.t2.message));
808
+ (_this$fireAnalyticsEv7 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv7 === void 0 || _this$fireAnalyticsEv7.call(this, updateReferenceErrorPayload(_context4.t2.message));
791
809
  case 47:
792
810
  _context4.prev = 47;
793
811
  if (!success) {
@@ -7,6 +7,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
7
7
  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; }
8
8
  import { useMemo, useRef } from 'react';
9
9
  import { logException } from '@atlaskit/editor-common/monitoring';
10
+ import { fg } from '@atlaskit/platform-feature-flags';
10
11
  import { getProductFromSourceAri } from '../clients/block-service/ari';
11
12
  import { SyncBlockError } from '../common/types';
12
13
  import { fetchReferencesErrorPayload } from '../utils/errorHandling';
@@ -34,7 +35,7 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
34
35
  value: function () {
35
36
  var _fetchReferencesSourceInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(resourceId, blockInstanceId, isSourceSyncBlock) {
36
37
  var _this = this;
37
- var _this$fetchReferences, _response$references, _this$fetchReferences5, response, _this$fetchReferences2, _this$fetchReferences3, _this$fetchReferences4, sourceInfoPromises, sourceInfos, sourceSyncBlockData, _this$fireAnalyticsEv;
38
+ 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;
38
39
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
39
40
  while (1) switch (_context2.prev = _context2.next) {
40
41
  case 0:
@@ -62,14 +63,114 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
62
63
  });
63
64
  case 10:
64
65
  if (!(!response.references || ((_response$references = response.references) === null || _response$references === void 0 ? void 0 : _response$references.length) === 0)) {
65
- _context2.next = 13;
66
+ _context2.next = 48;
66
67
  break;
67
68
  }
69
+ if (!fg('platform_synced_block_patch_8')) {
70
+ _context2.next = 46;
71
+ break;
72
+ }
73
+ if (!isSourceSyncBlock) {
74
+ _context2.next = 29;
75
+ break;
76
+ }
77
+ // Verify that a reference sync block for this specific source actually
78
+ // exists on the current page by checking if the reference manager has
79
+ // an active subscription for the derived reference resourceId.
80
+ referenceResourceId = this.referenceSyncBlockStoreManager.generateResourceIdForReference(resourceId);
81
+ hasUnregisteredReferenceOnPage = this.referenceSyncBlockStoreManager.getSubscribedResourceIds().includes(referenceResourceId);
82
+ if (!hasUnregisteredReferenceOnPage) {
83
+ _context2.next = 27;
84
+ break;
85
+ }
86
+ _context2.next = 18;
87
+ return this.sourceSyncBlockStoreManager.getSyncBlockSourceInfo(blockInstanceId);
88
+ case 18:
89
+ _sourceSyncBlockData = _context2.sent;
90
+ references = [];
91
+ if (_sourceSyncBlockData) {
92
+ references.push(_objectSpread(_objectSpread({}, _sourceSyncBlockData), {}, {
93
+ onSameDocument: Boolean(_sourceSyncBlockData === null || _sourceSyncBlockData === void 0 ? void 0 : _sourceSyncBlockData.onSameDocument),
94
+ hasAccess: true,
95
+ isSource: true
96
+ }));
97
+ }
98
+ _context2.next = 23;
99
+ return this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfo(referenceResourceId);
100
+ case 23:
101
+ unregisteredReferenceData = _context2.sent;
102
+ if (unregisteredReferenceData) {
103
+ references.push(_objectSpread(_objectSpread({}, unregisteredReferenceData), {}, {
104
+ onSameDocument: true,
105
+ hasAccess: true,
106
+ isSource: false
107
+ }));
108
+ }
109
+ (_this$fetchReferences3 = this.fetchReferencesExperience) === null || _this$fetchReferences3 === void 0 || _this$fetchReferences3.success();
110
+ return _context2.abrupt("return", {
111
+ references: references
112
+ });
113
+ case 27:
114
+ // No remote or local reference exists — show info text with link to doco on how to use Synced Blocks
115
+ (_this$fetchReferences4 = this.fetchReferencesExperience) === null || _this$fetchReferences4 === void 0 || _this$fetchReferences4.success();
116
+ return _context2.abrupt("return", {
117
+ references: []
118
+ });
119
+ case 29:
120
+ if (isSourceSyncBlock) {
121
+ _context2.next = 44;
122
+ break;
123
+ }
124
+ // Though no references registered yet for this reference sync block,
125
+ // still show the source and the current page itself since they are known
126
+ // but not saved yet.
127
+ _references = [];
128
+ _context2.next = 33;
129
+ return this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfo(resourceId);
130
+ case 33:
131
+ _sourceSyncBlockData2 = _context2.sent;
132
+ if (_sourceSyncBlockData2) {
133
+ _references.push(_objectSpread(_objectSpread({}, _sourceSyncBlockData2), {}, {
134
+ onSameDocument: Boolean(_sourceSyncBlockData2 === null || _sourceSyncBlockData2 === void 0 ? void 0 : _sourceSyncBlockData2.onSameDocument),
135
+ hasAccess: true,
136
+ isSource: true
137
+ }));
138
+ }
139
+ _context2.next = 37;
140
+ return this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfoByLocalId(blockInstanceId);
141
+ case 37:
142
+ currentPageData = _context2.sent;
143
+ if (currentPageData) {
144
+ _references.push(_objectSpread(_objectSpread({}, currentPageData), {}, {
145
+ onSameDocument: true,
146
+ hasAccess: true,
147
+ isSource: false
148
+ }));
149
+ }
150
+ if (!(_references.length === 0)) {
151
+ _context2.next = 42;
152
+ break;
153
+ }
154
+ (_this$fetchReferences5 = this.fetchReferencesExperience) === null || _this$fetchReferences5 === void 0 || _this$fetchReferences5.failure({
155
+ reason: 'No references found for reference synced block'
156
+ });
157
+ return _context2.abrupt("return", {
158
+ error: SyncBlockError.Errored
159
+ });
160
+ case 42:
161
+ (_this$fetchReferences6 = this.fetchReferencesExperience) === null || _this$fetchReferences6 === void 0 || _this$fetchReferences6.success();
162
+ return _context2.abrupt("return", {
163
+ references: _references
164
+ });
165
+ case 44:
166
+ _context2.next = 48;
167
+ break;
168
+ case 46:
68
169
  // No reference found
69
170
  if (isSourceSyncBlock) {
70
- (_this$fetchReferences3 = this.fetchReferencesExperience) === null || _this$fetchReferences3 === void 0 || _this$fetchReferences3.success();
171
+ (_this$fetchReferences7 = this.fetchReferencesExperience) === null || _this$fetchReferences7 === void 0 || _this$fetchReferences7.success();
71
172
  } else {
72
- (_this$fetchReferences4 = this.fetchReferencesExperience) === null || _this$fetchReferences4 === void 0 || _this$fetchReferences4.failure({
173
+ (_this$fetchReferences8 = this.fetchReferencesExperience) === null || _this$fetchReferences8 === void 0 || _this$fetchReferences8.failure({
73
174
  reason: 'No references found for reference synced block'
74
175
  });
75
176
  }
@@ -78,9 +179,9 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
78
179
  } : {
79
180
  error: SyncBlockError.Errored
80
181
  });
81
- case 13:
82
- (_this$fetchReferences5 = this.fetchReferencesExperience) === null || _this$fetchReferences5 === void 0 || _this$fetchReferences5.success();
83
- sourceInfoPromises = response.references.map( /*#__PURE__*/function () {
182
+ case 48:
183
+ (_this$fetchReferences9 = this.fetchReferencesExperience) === null || _this$fetchReferences9 === void 0 || _this$fetchReferences9.success();
184
+ sourceInfoPromises = ((_response$references2 = response.references) !== null && _response$references2 !== void 0 ? _response$references2 : []).map( /*#__PURE__*/function () {
84
185
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(reference) {
85
186
  var _this$fetchSourceInfo, _this$dataProvider, _this$fetchSourceInfo3;
86
187
  var sourceInfo, _this$fetchSourceInfo2;
@@ -117,13 +218,13 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
117
218
  return _ref.apply(this, arguments);
118
219
  };
119
220
  }());
120
- _context2.next = 17;
221
+ _context2.next = 52;
121
222
  return Promise.all(sourceInfoPromises);
122
- case 17:
223
+ case 52:
123
224
  sourceInfos = _context2.sent;
124
- _context2.next = 20;
225
+ _context2.next = 55;
125
226
  return isSourceSyncBlock ? this.sourceSyncBlockStoreManager.getSyncBlockSourceInfo(blockInstanceId) : this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfo(resourceId);
126
- case 20:
227
+ case 55:
127
228
  sourceSyncBlockData = _context2.sent;
128
229
  if (sourceSyncBlockData) {
129
230
  sourceInfos.push(_objectSpread(_objectSpread({}, sourceSyncBlockData), {}, {
@@ -136,8 +237,8 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
136
237
  return _context2.abrupt("return", {
137
238
  references: sourceInfos
138
239
  });
139
- case 25:
140
- _context2.prev = 25;
240
+ case 60:
241
+ _context2.prev = 60;
141
242
  _context2.t0 = _context2["catch"](0);
142
243
  logException(_context2.t0, {
143
244
  location: 'editor-synced-block-provider/syncBlockStoreManager'
@@ -146,11 +247,11 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
146
247
  return _context2.abrupt("return", {
147
248
  error: SyncBlockError.Errored
148
249
  });
149
- case 30:
250
+ case 65:
150
251
  case "end":
151
252
  return _context2.stop();
152
253
  }
153
- }, _callee2, this, [[0, 25]]);
254
+ }, _callee2, this, [[0, 60]]);
154
255
  }));
155
256
  function fetchReferencesSourceInfo(_x, _x2, _x3) {
156
257
  return _fetchReferencesSourceInfo.apply(this, arguments);
@@ -179,10 +280,10 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
179
280
  }, {
180
281
  key: "destroy",
181
282
  value: function destroy() {
182
- var _this$fetchReferences6, _this$fetchSourceInfo4;
283
+ var _this$fetchReferences0, _this$fetchSourceInfo4;
183
284
  this.referenceSyncBlockStoreManager.destroy();
184
285
  this.sourceSyncBlockStoreManager.destroy();
185
- (_this$fetchReferences6 = this.fetchReferencesExperience) === null || _this$fetchReferences6 === void 0 || _this$fetchReferences6.abort({
286
+ (_this$fetchReferences0 = this.fetchReferencesExperience) === null || _this$fetchReferences0 === void 0 || _this$fetchReferences0.abort({
186
287
  reason: 'editorDestroyed'
187
288
  });
188
289
  (_this$fetchSourceInfo4 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo4 === void 0 || _this$fetchSourceInfo4.abort({
@@ -2,7 +2,7 @@ import type { RendererSyncBlockEventPayload } from '@atlaskit/editor-common/anal
2
2
  import type { Experience } from '@atlaskit/editor-common/experiences';
3
3
  import type { ProviderFactory, MediaProvider } from '@atlaskit/editor-common/provider-factory';
4
4
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
5
- import type { ResourceId, SyncBlockNode, SyncBlockPrefetchData } from '../common/types';
5
+ import type { BlockInstanceId, ResourceId, SyncBlockNode, SyncBlockPrefetchData } from '../common/types';
6
6
  import type { SyncBlockInstance, SubscriptionCallback, SyncBlockDataProviderInterface, TitleSubscriptionCallback, SyncBlockSourceInfo } from '../providers/types';
7
7
  export declare class ReferenceSyncBlockStoreManager {
8
8
  private dataProvider?;
@@ -65,6 +65,7 @@ export declare class ReferenceSyncBlockStoreManager {
65
65
  private updateSessionCache;
66
66
  private getFromSessionCache;
67
67
  fetchSyncBlockSourceInfoBySourceAri(sourceAri: string, hasAccess?: boolean): Promise<SyncBlockSourceInfo | undefined>;
68
+ fetchSyncBlockSourceInfoByLocalId(localId: BlockInstanceId, hasAccess?: boolean): Promise<SyncBlockSourceInfo | undefined>;
68
69
  fetchSyncBlockSourceInfo(resourceId: ResourceId): Promise<SyncBlockSourceInfo | undefined>;
69
70
  /**
70
71
  * Processes prefetched data and updates the cache.
@@ -2,7 +2,7 @@ import type { RendererSyncBlockEventPayload } from '@atlaskit/editor-common/anal
2
2
  import type { Experience } from '@atlaskit/editor-common/experiences';
3
3
  import type { ProviderFactory, MediaProvider } from '@atlaskit/editor-common/provider-factory';
4
4
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
5
- import type { ResourceId, SyncBlockNode, SyncBlockPrefetchData } from '../common/types';
5
+ import type { BlockInstanceId, ResourceId, SyncBlockNode, SyncBlockPrefetchData } from '../common/types';
6
6
  import type { SyncBlockInstance, SubscriptionCallback, SyncBlockDataProviderInterface, TitleSubscriptionCallback, SyncBlockSourceInfo } from '../providers/types';
7
7
  export declare class ReferenceSyncBlockStoreManager {
8
8
  private dataProvider?;
@@ -65,6 +65,7 @@ export declare class ReferenceSyncBlockStoreManager {
65
65
  private updateSessionCache;
66
66
  private getFromSessionCache;
67
67
  fetchSyncBlockSourceInfoBySourceAri(sourceAri: string, hasAccess?: boolean): Promise<SyncBlockSourceInfo | undefined>;
68
+ fetchSyncBlockSourceInfoByLocalId(localId: BlockInstanceId, hasAccess?: boolean): Promise<SyncBlockSourceInfo | undefined>;
68
69
  fetchSyncBlockSourceInfo(resourceId: ResourceId): Promise<SyncBlockSourceInfo | undefined>;
69
70
  /**
70
71
  * Processes prefetched data and updates the cache.
package/package.json CHANGED
@@ -29,7 +29,7 @@
29
29
  "@atlaskit/editor-prosemirror": "^7.3.0",
30
30
  "@atlaskit/node-data-provider": "^9.0.0",
31
31
  "@atlaskit/platform-feature-flags": "^1.1.0",
32
- "@atlaskit/tmp-editor-statsig": "^53.0.0",
32
+ "@atlaskit/tmp-editor-statsig": "^54.0.0",
33
33
  "@babel/runtime": "^7.0.0",
34
34
  "@compiled/react": "^0.20.0",
35
35
  "graphql-ws": "^5.14.2",
@@ -38,7 +38,7 @@
38
38
  "uuid": "^3.1.0"
39
39
  },
40
40
  "peerDependencies": {
41
- "@atlaskit/editor-common": "^112.15.0",
41
+ "@atlaskit/editor-common": "^112.16.0",
42
42
  "react": "^18.2.0"
43
43
  },
44
44
  "devDependencies": {
@@ -81,7 +81,7 @@
81
81
  }
82
82
  },
83
83
  "name": "@atlaskit/editor-synced-block-provider",
84
- "version": "4.2.11",
84
+ "version": "4.3.1",
85
85
  "description": "Synced Block Provider for @atlaskit/editor-plugin-synced-block",
86
86
  "author": "Atlassian Pty Ltd",
87
87
  "license": "Apache-2.0",