@atlaskit/editor-synced-block-provider 22.0.5 → 22.1.0

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.
@@ -1,7 +1,11 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
3
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
4
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
4
5
  import _createClass from "@babel/runtime/helpers/createClass";
6
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
7
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
8
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
5
9
  import _regeneratorRuntime from "@babel/runtime/regenerator";
6
10
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
7
11
  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; }
@@ -39,49 +43,80 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
39
43
  value: function isSyncBlock(node) {
40
44
  return this.sourceSyncBlockStoreManager.isSourceBlock(node) || this.referenceSyncBlockStoreManager.isReferenceBlock(node);
41
45
  }
46
+ }, {
47
+ key: "getDocumentReferenceIds",
48
+ value: function getDocumentReferenceIds(resourceId, doc) {
49
+ var _this = this;
50
+ if (!doc) {
51
+ return undefined;
52
+ }
53
+ var localIds = new Set();
54
+ doc.descendants(function (node) {
55
+ if (_this.referenceManager.isReferenceBlock(node) && node.attrs.resourceId === resourceId && node.attrs.localId) {
56
+ localIds.add(node.attrs.localId);
57
+ }
58
+ });
59
+ return localIds;
60
+ }
42
61
  }, {
43
62
  key: "fetchReferencesSourceInfo",
44
63
  value: function () {
45
- var _fetchReferencesSourceInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(resourceId, blockInstanceId, isSourceSyncBlock) {
46
- var _this = this;
47
- var _this$fetchReferences, _response$references, _this$fetchReferences3, _response$references2, response, _this$fetchReferences2, sourceInfoPromises, sourceInfos, sourceSyncBlockData, _this$fireAnalyticsEv, _t;
48
- return _regeneratorRuntime.wrap(function (_context2) {
49
- while (1) switch (_context2.prev = _context2.next) {
64
+ var _fetchReferencesSourceInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(resourceId, blockInstanceId, isSourceSyncBlock, doc) {
65
+ var _this2 = this;
66
+ var _this$fetchReferences, _response$references, _this$fetchReferences4, response, _this$fetchReferences2, patchEnabled, referenceResourceId, documentIds, localIds, references, _this$fetchReferences3, sourceInfoPromises, sourceInfos, sourceSyncBlockData, registeredLocalIds, _iterator, _step, reference, localSourceInfos, _this$fireAnalyticsEv, _t;
67
+ return _regeneratorRuntime.wrap(function (_context3) {
68
+ while (1) switch (_context3.prev = _context3.next) {
50
69
  case 0:
51
- _context2.prev = 0;
70
+ _context3.prev = 0;
52
71
  if (this.dataProvider) {
53
- _context2.next = 1;
72
+ _context3.next = 1;
54
73
  break;
55
74
  }
56
75
  throw new Error('Data provider not set');
57
76
  case 1:
58
77
  (_this$fetchReferences = this.fetchReferencesExperience) === null || _this$fetchReferences === void 0 || _this$fetchReferences.start();
59
- _context2.next = 2;
78
+ _context3.next = 2;
60
79
  return this.dataProvider.fetchReferences(resourceId, isSourceSyncBlock);
61
80
  case 2:
62
- response = _context2.sent;
81
+ response = _context3.sent;
63
82
  if (!response.error) {
64
- _context2.next = 3;
83
+ _context3.next = 3;
65
84
  break;
66
85
  }
67
86
  (_this$fetchReferences2 = this.fetchReferencesExperience) === null || _this$fetchReferences2 === void 0 || _this$fetchReferences2.failure({
68
87
  reason: response.error
69
88
  });
70
- return _context2.abrupt("return", {
89
+ return _context3.abrupt("return", {
71
90
  error: response.error
72
91
  });
73
92
  case 3:
74
- if (!(!response.references || ((_response$references = response.references) === null || _response$references === void 0 ? void 0 : _response$references.length) === 0)) {
75
- _context2.next = 4;
93
+ patchEnabled = isExperimentEnabled('platform_editor_blocks_patch_12');
94
+ referenceResourceId = patchEnabled && isSourceSyncBlock ? this.referenceSyncBlockStoreManager.generateResourceIdForReference(resourceId) : resourceId;
95
+ documentIds = patchEnabled ? this.getDocumentReferenceIds(referenceResourceId, doc) : undefined;
96
+ localIds = patchEnabled ? documentIds ? _toConsumableArray(documentIds) : this.referenceSyncBlockStoreManager.getSubscribedLocalIds(referenceResourceId) : []; // Saved references on this document can already have been removed in the editor.
97
+ references = ((_response$references = response.references) !== null && _response$references !== void 0 ? _response$references : []).filter(function (reference) {
98
+ return documentIds === undefined || !reference.onSameDocument || Boolean(reference.blockInstanceId && documentIds.has(reference.blockInstanceId));
99
+ });
100
+ if (!(references.length === 0 && localIds.length === 0)) {
101
+ _context3.next = 5;
102
+ break;
103
+ }
104
+ if (!(documentIds !== undefined)) {
105
+ _context3.next = 4;
76
106
  break;
77
107
  }
78
- return _context2.abrupt("return", this.getUnregisteredReferences(resourceId, blockInstanceId, isSourceSyncBlock));
79
- case 4:
80
108
  (_this$fetchReferences3 = this.fetchReferencesExperience) === null || _this$fetchReferences3 === void 0 || _this$fetchReferences3.success();
81
- sourceInfoPromises = ((_response$references2 = response.references) !== null && _response$references2 !== void 0 ? _response$references2 : []).map( /*#__PURE__*/function () {
109
+ return _context3.abrupt("return", {
110
+ references: []
111
+ });
112
+ case 4:
113
+ return _context3.abrupt("return", this.getUnregisteredReferences(resourceId, blockInstanceId, isSourceSyncBlock));
114
+ case 5:
115
+ (_this$fetchReferences4 = this.fetchReferencesExperience) === null || _this$fetchReferences4 === void 0 || _this$fetchReferences4.success();
116
+ sourceInfoPromises = references.map( /*#__PURE__*/function () {
82
117
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(reference) {
83
- var _this$fetchSourceInfo, _this$dataProvider, _this$fetchSourceInfo3;
84
- var sourceInfo, _this$fetchSourceInfo2;
118
+ var _this2$fetchSourceInf, _this2$dataProvider, _this2$fetchSourceInf3;
119
+ var sourceInfo, _this2$fetchSourceInf2;
85
120
  return _regeneratorRuntime.wrap(function (_context) {
86
121
  while (1) switch (_context.prev = _context.next) {
87
122
  case 0:
@@ -89,23 +124,23 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
89
124
  _context.next = 1;
90
125
  break;
91
126
  }
92
- return _context.abrupt("return", _this.fetchRestrictedReferenceInfo(reference.documentAri));
127
+ return _context.abrupt("return", _this2.fetchRestrictedReferenceInfo(reference.documentAri));
93
128
  case 1:
94
- (_this$fetchSourceInfo = _this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo === void 0 || _this$fetchSourceInfo.start();
129
+ (_this2$fetchSourceInf = _this2.fetchSourceInfoExperience) === null || _this2$fetchSourceInf === void 0 || _this2$fetchSourceInf.start();
95
130
  _context.next = 2;
96
- return (_this$dataProvider = _this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.fetchSyncBlockSourceInfo(reference.blockInstanceId || '', reference.documentAri, getProductFromSourceAri(reference.documentAri), reference.hasAccess);
131
+ return (_this2$dataProvider = _this2.dataProvider) === null || _this2$dataProvider === void 0 ? void 0 : _this2$dataProvider.fetchSyncBlockSourceInfo(reference.blockInstanceId || '', reference.documentAri, getProductFromSourceAri(reference.documentAri), reference.hasAccess);
97
132
  case 2:
98
133
  sourceInfo = _context.sent;
99
134
  if (sourceInfo) {
100
135
  _context.next = 3;
101
136
  break;
102
137
  }
103
- (_this$fetchSourceInfo2 = _this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo2 === void 0 || _this$fetchSourceInfo2.failure({
138
+ (_this2$fetchSourceInf2 = _this2.fetchSourceInfoExperience) === null || _this2$fetchSourceInf2 === void 0 || _this2$fetchSourceInf2.failure({
104
139
  reason: "no source info returned for ari: ".concat(reference.documentAri)
105
140
  });
106
141
  return _context.abrupt("return", undefined);
107
142
  case 3:
108
- (_this$fetchSourceInfo3 = _this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo3 === void 0 || _this$fetchSourceInfo3.success();
143
+ (_this2$fetchSourceInf3 = _this2.fetchSourceInfoExperience) === null || _this2$fetchSourceInf3 === void 0 || _this2$fetchSourceInf3.success();
109
144
  return _context.abrupt("return", _objectSpread(_objectSpread(_objectSpread({}, sourceInfo), {}, {
110
145
  onSameDocument: reference.onSameDocument
111
146
  }, reference.locationScope !== undefined && {
@@ -120,18 +155,18 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
120
155
  }
121
156
  }, _callee);
122
157
  }));
123
- return function (_x4) {
158
+ return function (_x5) {
124
159
  return _ref.apply(this, arguments);
125
160
  };
126
161
  }());
127
- _context2.next = 5;
162
+ _context3.next = 6;
128
163
  return Promise.all(sourceInfoPromises);
129
- case 5:
130
- sourceInfos = _context2.sent;
131
- _context2.next = 6;
132
- return isSourceSyncBlock ? this.sourceSyncBlockStoreManager.getSyncBlockSourceInfo(blockInstanceId) : this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfo(resourceId);
133
164
  case 6:
134
- sourceSyncBlockData = _context2.sent;
165
+ sourceInfos = _context3.sent;
166
+ _context3.next = 7;
167
+ return isSourceSyncBlock ? this.sourceSyncBlockStoreManager.getSyncBlockSourceInfo(blockInstanceId) : this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfo(resourceId);
168
+ case 7:
169
+ sourceSyncBlockData = _context3.sent;
135
170
  if (sourceSyncBlockData) {
136
171
  sourceInfos.push(_objectSpread(_objectSpread({}, sourceSyncBlockData), {}, {
137
172
  onSameDocument: Boolean(sourceSyncBlockData === null || sourceSyncBlockData === void 0 ? void 0 : sourceSyncBlockData.onSameDocument),
@@ -140,26 +175,74 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
140
175
  productType: sourceSyncBlockData === null || sourceSyncBlockData === void 0 ? void 0 : sourceSyncBlockData.productType
141
176
  }));
142
177
  }
143
- return _context2.abrupt("return", {
178
+
179
+ // Only instances in this editor belong to its unsaved document. A matching
180
+ // local ID on another document must not hide an unsaved copy here.
181
+ registeredLocalIds = new Set();
182
+ _iterator = _createForOfIteratorHelper(references);
183
+ try {
184
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
185
+ reference = _step.value;
186
+ if (reference.onSameDocument && reference.blockInstanceId) {
187
+ registeredLocalIds.add(reference.blockInstanceId);
188
+ }
189
+ }
190
+ } catch (err) {
191
+ _iterator.e(err);
192
+ } finally {
193
+ _iterator.f();
194
+ }
195
+ _context3.next = 8;
196
+ return Promise.all(localIds.filter(function (localId) {
197
+ return !registeredLocalIds.has(localId);
198
+ }).map( /*#__PURE__*/function () {
199
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(localId) {
200
+ var sourceInfo;
201
+ return _regeneratorRuntime.wrap(function (_context2) {
202
+ while (1) switch (_context2.prev = _context2.next) {
203
+ case 0:
204
+ _context2.next = 1;
205
+ return _this2.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfoByLocalId(localId);
206
+ case 1:
207
+ sourceInfo = _context2.sent;
208
+ return _context2.abrupt("return", sourceInfo ? _objectSpread(_objectSpread({}, sourceInfo), {}, {
209
+ onSameDocument: true,
210
+ hasAccess: true,
211
+ isSource: false
212
+ }) : undefined);
213
+ case 2:
214
+ case "end":
215
+ return _context2.stop();
216
+ }
217
+ }, _callee2);
218
+ }));
219
+ return function (_x6) {
220
+ return _ref2.apply(this, arguments);
221
+ };
222
+ }()));
223
+ case 8:
224
+ localSourceInfos = _context3.sent;
225
+ sourceInfos.push.apply(sourceInfos, _toConsumableArray(localSourceInfos));
226
+ return _context3.abrupt("return", {
144
227
  references: sourceInfos
145
228
  });
146
- case 7:
147
- _context2.prev = 7;
148
- _t = _context2["catch"](0);
229
+ case 9:
230
+ _context3.prev = 9;
231
+ _t = _context3["catch"](0);
149
232
  logException(_t, {
150
233
  location: 'editor-synced-block-provider/syncBlockStoreManager'
151
234
  });
152
235
  (_this$fireAnalyticsEv = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv === void 0 || _this$fireAnalyticsEv.call(this, fetchReferencesErrorPayload(_t.message, resourceId, getSourceProductFromResourceIdSafe(resourceId)));
153
- return _context2.abrupt("return", {
236
+ return _context3.abrupt("return", {
154
237
  error: SyncBlockError.Errored
155
238
  });
156
- case 8:
239
+ case 10:
157
240
  case "end":
158
- return _context2.stop();
241
+ return _context3.stop();
159
242
  }
160
- }, _callee2, this, [[0, 7]]);
243
+ }, _callee3, this, [[0, 9]]);
161
244
  }));
162
- function fetchReferencesSourceInfo(_x, _x2, _x3) {
245
+ function fetchReferencesSourceInfo(_x, _x2, _x3, _x4) {
163
246
  return _fetchReferencesSourceInfo.apply(this, arguments);
164
247
  }
165
248
  return fetchReferencesSourceInfo;
@@ -186,13 +269,13 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
186
269
  }, {
187
270
  key: "destroy",
188
271
  value: function destroy() {
189
- var _this$fetchReferences4, _this$fetchSourceInfo4;
272
+ var _this$fetchReferences5, _this$fetchSourceInfo;
190
273
  this.referenceSyncBlockStoreManager.destroy();
191
274
  this.sourceSyncBlockStoreManager.destroy();
192
- (_this$fetchReferences4 = this.fetchReferencesExperience) === null || _this$fetchReferences4 === void 0 || _this$fetchReferences4.abort({
275
+ (_this$fetchReferences5 = this.fetchReferencesExperience) === null || _this$fetchReferences5 === void 0 || _this$fetchReferences5.abort({
193
276
  reason: 'editorDestroyed'
194
277
  });
195
- (_this$fetchSourceInfo4 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo4 === void 0 || _this$fetchSourceInfo4.abort({
278
+ (_this$fetchSourceInfo = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo === void 0 || _this$fetchSourceInfo.abort({
196
279
  reason: 'editorDestroyed'
197
280
  });
198
281
  }
@@ -204,41 +287,41 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
204
287
  }, {
205
288
  key: "fetchRestrictedReferenceInfo",
206
289
  value: (function () {
207
- var _fetchRestrictedReferenceInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(documentAri) {
208
- var _this$fetchSourceInfo5;
209
- var productType, url, _this$dataProvider2, _this$fetchSourceInfo6, sourceInfo, _this$fetchSourceInfo7, _t2;
210
- return _regeneratorRuntime.wrap(function (_context3) {
211
- while (1) switch (_context3.prev = _context3.next) {
290
+ var _fetchRestrictedReferenceInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(documentAri) {
291
+ var _this$fetchSourceInfo2;
292
+ var productType, url, _this$dataProvider, _this$fetchSourceInfo3, sourceInfo, _this$fetchSourceInfo4, _t2;
293
+ return _regeneratorRuntime.wrap(function (_context4) {
294
+ while (1) switch (_context4.prev = _context4.next) {
212
295
  case 0:
213
296
  if (documentAri) {
214
- _context3.next = 1;
297
+ _context4.next = 1;
215
298
  break;
216
299
  }
217
- return _context3.abrupt("return", {
300
+ return _context4.abrupt("return", {
218
301
  sourceAri: '',
219
302
  hasAccess: false,
220
303
  onSameDocument: false
221
304
  });
222
305
  case 1:
223
306
  productType = getProductFromSourceAri(documentAri);
224
- (_this$fetchSourceInfo5 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo5 === void 0 || _this$fetchSourceInfo5.start();
225
- _context3.prev = 2;
226
- _context3.next = 3;
227
- return (_this$dataProvider2 = this.dataProvider) === null || _this$dataProvider2 === void 0 ? void 0 : _this$dataProvider2.fetchSyncBlockSourceInfo(undefined, documentAri, productType, false);
307
+ (_this$fetchSourceInfo2 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo2 === void 0 || _this$fetchSourceInfo2.start();
308
+ _context4.prev = 2;
309
+ _context4.next = 3;
310
+ return (_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.fetchSyncBlockSourceInfo(undefined, documentAri, productType, false);
228
311
  case 3:
229
- sourceInfo = _context3.sent;
312
+ sourceInfo = _context4.sent;
230
313
  url = sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.url;
231
- (_this$fetchSourceInfo6 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo6 === void 0 || _this$fetchSourceInfo6.success();
232
- _context3.next = 5;
314
+ (_this$fetchSourceInfo3 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo3 === void 0 || _this$fetchSourceInfo3.success();
315
+ _context4.next = 5;
233
316
  break;
234
317
  case 4:
235
- _context3.prev = 4;
236
- _t2 = _context3["catch"](2);
237
- (_this$fetchSourceInfo7 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo7 === void 0 || _this$fetchSourceInfo7.failure({
318
+ _context4.prev = 4;
319
+ _t2 = _context4["catch"](2);
320
+ (_this$fetchSourceInfo4 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo4 === void 0 || _this$fetchSourceInfo4.failure({
238
321
  reason: _t2.message
239
322
  });
240
323
  case 5:
241
- return _context3.abrupt("return", {
324
+ return _context4.abrupt("return", {
242
325
  sourceAri: documentAri,
243
326
  productType: productType,
244
327
  url: url,
@@ -247,11 +330,11 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
247
330
  });
248
331
  case 6:
249
332
  case "end":
250
- return _context3.stop();
333
+ return _context4.stop();
251
334
  }
252
- }, _callee3, this, [[2, 4]]);
335
+ }, _callee4, this, [[2, 4]]);
253
336
  }));
254
- function fetchRestrictedReferenceInfo(_x5) {
337
+ function fetchRestrictedReferenceInfo(_x7) {
255
338
  return _fetchRestrictedReferenceInfo.apply(this, arguments);
256
339
  }
257
340
  return fetchRestrictedReferenceInfo;
@@ -259,14 +342,14 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
259
342
  }, {
260
343
  key: "getUnregisteredReferences",
261
344
  value: function () {
262
- var _getUnregisteredReferences = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(resourceId, blockInstanceId, isSourceSyncBlock) {
263
- var _this$fetchReferences8;
264
- var _this$fetchReferences6, referenceResourceId, hasUnregisteredReferenceOnPage, _this$fetchReferences5, _sourceSyncBlockData, _references, sourceSyncBlockReference, referenceSyncBlockReference, references, sourceSyncBlockData, currentPageData, _this$fetchReferences7;
265
- return _regeneratorRuntime.wrap(function (_context4) {
266
- while (1) switch (_context4.prev = _context4.next) {
345
+ var _getUnregisteredReferences = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(resourceId, blockInstanceId, isSourceSyncBlock) {
346
+ var _this$fetchReferences9;
347
+ var _this$fetchReferences7, referenceResourceId, hasUnregisteredReferenceOnPage, _this$fetchReferences6, _sourceSyncBlockData, _references, sourceSyncBlockReference, referenceSyncBlockReference, references, sourceSyncBlockData, currentPageData, _this$fetchReferences8;
348
+ return _regeneratorRuntime.wrap(function (_context5) {
349
+ while (1) switch (_context5.prev = _context5.next) {
267
350
  case 0:
268
351
  if (!isSourceSyncBlock) {
269
- _context4.next = 3;
352
+ _context5.next = 3;
270
353
  break;
271
354
  }
272
355
  // Verify that a reference sync block for this specific source actually
@@ -275,13 +358,13 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
275
358
  referenceResourceId = this.referenceSyncBlockStoreManager.generateResourceIdForReference(resourceId);
276
359
  hasUnregisteredReferenceOnPage = this.referenceSyncBlockStoreManager.getSubscribedResourceIds().includes(referenceResourceId);
277
360
  if (!hasUnregisteredReferenceOnPage) {
278
- _context4.next = 2;
361
+ _context5.next = 2;
279
362
  break;
280
363
  }
281
- _context4.next = 1;
364
+ _context5.next = 1;
282
365
  return this.sourceSyncBlockStoreManager.getSyncBlockSourceInfo(blockInstanceId);
283
366
  case 1:
284
- _sourceSyncBlockData = _context4.sent;
367
+ _sourceSyncBlockData = _context5.sent;
285
368
  _references = [];
286
369
  if (_sourceSyncBlockData) {
287
370
  sourceSyncBlockReference = _objectSpread(_objectSpread({}, _sourceSyncBlockData), {}, {
@@ -296,14 +379,14 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
296
379
  });
297
380
  _references.push(sourceSyncBlockReference, referenceSyncBlockReference);
298
381
  }
299
- (_this$fetchReferences5 = this.fetchReferencesExperience) === null || _this$fetchReferences5 === void 0 || _this$fetchReferences5.success();
300
- return _context4.abrupt("return", {
382
+ (_this$fetchReferences6 = this.fetchReferencesExperience) === null || _this$fetchReferences6 === void 0 || _this$fetchReferences6.success();
383
+ return _context5.abrupt("return", {
301
384
  references: _references
302
385
  });
303
386
  case 2:
304
387
  // No remote or local reference exists — show info text with link to doco on how to use Synced Blocks
305
- (_this$fetchReferences6 = this.fetchReferencesExperience) === null || _this$fetchReferences6 === void 0 || _this$fetchReferences6.success();
306
- return _context4.abrupt("return", {
388
+ (_this$fetchReferences7 = this.fetchReferencesExperience) === null || _this$fetchReferences7 === void 0 || _this$fetchReferences7.success();
389
+ return _context5.abrupt("return", {
307
390
  references: []
308
391
  });
309
392
  case 3:
@@ -311,10 +394,10 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
311
394
  // still show the source and the current page itself since they are known
312
395
  // but not saved yet.
313
396
  references = [];
314
- _context4.next = 4;
397
+ _context5.next = 4;
315
398
  return this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfo(resourceId);
316
399
  case 4:
317
- sourceSyncBlockData = _context4.sent;
400
+ sourceSyncBlockData = _context5.sent;
318
401
  if (sourceSyncBlockData) {
319
402
  references.push(_objectSpread(_objectSpread({}, sourceSyncBlockData), {}, {
320
403
  onSameDocument: Boolean(sourceSyncBlockData === null || sourceSyncBlockData === void 0 ? void 0 : sourceSyncBlockData.onSameDocument),
@@ -322,10 +405,10 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
322
405
  isSource: true
323
406
  }));
324
407
  }
325
- _context4.next = 5;
408
+ _context5.next = 5;
326
409
  return this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfoByLocalId(blockInstanceId);
327
410
  case 5:
328
- currentPageData = _context4.sent;
411
+ currentPageData = _context5.sent;
329
412
  if (currentPageData) {
330
413
  references.push(_objectSpread(_objectSpread({}, currentPageData), {}, {
331
414
  onSameDocument: true,
@@ -334,27 +417,27 @@ export var SyncBlockStoreManager = /*#__PURE__*/function () {
334
417
  }));
335
418
  }
336
419
  if (!(references.length === 0)) {
337
- _context4.next = 6;
420
+ _context5.next = 6;
338
421
  break;
339
422
  }
340
- (_this$fetchReferences7 = this.fetchReferencesExperience) === null || _this$fetchReferences7 === void 0 || _this$fetchReferences7.failure({
423
+ (_this$fetchReferences8 = this.fetchReferencesExperience) === null || _this$fetchReferences8 === void 0 || _this$fetchReferences8.failure({
341
424
  reason: 'No references found for reference synced block'
342
425
  });
343
- return _context4.abrupt("return", {
426
+ return _context5.abrupt("return", {
344
427
  error: SyncBlockError.Errored
345
428
  });
346
429
  case 6:
347
- (_this$fetchReferences8 = this.fetchReferencesExperience) === null || _this$fetchReferences8 === void 0 || _this$fetchReferences8.success();
348
- return _context4.abrupt("return", {
430
+ (_this$fetchReferences9 = this.fetchReferencesExperience) === null || _this$fetchReferences9 === void 0 || _this$fetchReferences9.success();
431
+ return _context5.abrupt("return", {
349
432
  references: references
350
433
  });
351
434
  case 7:
352
435
  case "end":
353
- return _context4.stop();
436
+ return _context5.stop();
354
437
  }
355
- }, _callee4, this);
438
+ }, _callee5, this);
356
439
  }));
357
- function getUnregisteredReferences(_x6, _x7, _x8) {
440
+ function getUnregisteredReferences(_x8, _x9, _x0) {
358
441
  return _getUnregisteredReferences.apply(this, arguments);
359
442
  }
360
443
  return getUnregisteredReferences;
@@ -73,6 +73,7 @@ export declare class SyncedBlockProvider extends SyncBlockDataProviderInterface
73
73
  localId: BlockInstanceId;
74
74
  resourceId: ResourceId;
75
75
  };
76
+ canGenerateResourceIdForReference(): boolean;
76
77
  generateResourceIdForReference(sourceId: ResourceId): ResourceId;
77
78
  /**
78
79
  * Get the synced block renderer provider options
@@ -220,6 +220,7 @@ export declare abstract class SyncBlockDataProviderInterface extends NodeDataPro
220
220
  * @returns The generated resource ID
221
221
  */
222
222
  abstract generateResourceIdForReference(sourceId: ResourceId): ResourceId;
223
+ canGenerateResourceIdForReference?(): boolean;
223
224
  abstract updateReferenceData(blocks: SyncBlockAttrs[], noContent?: boolean): Promise<UpdateReferenceSyncBlockResult>;
224
225
  abstract fetchReferences(resourceId: string, isSource: boolean): Promise<ReferenceSyncBlockData>;
225
226
  /**
@@ -59,6 +59,7 @@ export declare class ReferenceSyncBlockStoreManager {
59
59
  * Used by React components to render subscription components.
60
60
  */
61
61
  getSubscribedResourceIds(): ResourceId[];
62
+ getSubscribedLocalIds(resourceId: ResourceId): BlockInstanceId[];
62
63
  /**
63
64
  * Registers a listener that will be called when subscriptions change.
64
65
  * @param listener - Callback function to invoke when subscriptions change
@@ -28,7 +28,8 @@ export declare class SyncBlockStoreManager {
28
28
  private fetchSourceInfoExperience;
29
29
  constructor(dataProvider?: SyncBlockDataProviderInterface, viewMode?: ViewMode, isLivePage?: boolean, options?: SyncBlockStoreManagerOptions);
30
30
  isSyncBlock(node: PMNode): boolean;
31
- fetchReferencesSourceInfo(resourceId: ResourceId, blockInstanceId: BlockInstanceId, isSourceSyncBlock: boolean): Promise<ReferencesSourceInfo>;
31
+ private getDocumentReferenceIds;
32
+ fetchReferencesSourceInfo(resourceId: ResourceId, blockInstanceId: BlockInstanceId, isSourceSyncBlock: boolean, doc?: PMNode): Promise<ReferencesSourceInfo>;
32
33
  setFireAnalyticsEvent(fireAnalyticsEvent?: (payload: SyncBlockEventPayload) => void): void;
33
34
  get referenceManager(): ReferenceSyncBlockStoreManager;
34
35
  get sourceManager(): SourceSyncBlockStoreManager;
package/package.json CHANGED
@@ -33,7 +33,7 @@
33
33
  "uuid": "^11.1.1"
34
34
  },
35
35
  "peerDependencies": {
36
- "@atlaskit/editor-common": "^130.3.0",
36
+ "@atlaskit/editor-common": "^130.4.0",
37
37
  "react": "^18.2.0 || ^19.2.0"
38
38
  },
39
39
  "devDependencies": {
@@ -42,7 +42,7 @@
42
42
  "react-dom": "^19.2.0"
43
43
  },
44
44
  "name": "@atlaskit/editor-synced-block-provider",
45
- "version": "22.0.5",
45
+ "version": "22.1.0",
46
46
  "description": "Synced Block Provider for @atlaskit/editor-plugin-synced-block",
47
47
  "author": "Atlassian Pty Ltd",
48
48
  "license": "Apache-2.0",