@atlaskit/editor-synced-block-provider 22.0.6 → 22.1.2

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,26 @@
1
1
  # @atlaskit/editor-synced-block-provider
2
2
 
3
+ ## 22.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 22.1.1
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
15
+ ## 22.1.0
16
+
17
+ ### Minor Changes
18
+
19
+ - [`63c2a47db7f66`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/63c2a47db7f66) -
20
+ Pass the current editor document into the lookup for synced locations behind
21
+ platform_editor_blocks_patch_12, including references added, removed, or unsynced before saving.
22
+ Reconcile saved references with the current document, preserving locations on other documents.
23
+
3
24
  ## 22.0.6
4
25
 
5
26
  ### Patch Changes
@@ -187,6 +187,12 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
187
187
  value: function getSubscribedResourceIds() {
188
188
  return this._subscriptionManager.getSubscribedResourceIds();
189
189
  }
190
+ }, {
191
+ key: "getSubscribedLocalIds",
192
+ value: function getSubscribedLocalIds(resourceId) {
193
+ var _this$_subscriptionMa;
194
+ return Object.keys((_this$_subscriptionMa = this._subscriptionManager.getSubscriptions().get(resourceId)) !== null && _this$_subscriptionMa !== void 0 ? _this$_subscriptionMa : {});
195
+ }
190
196
 
191
197
  /**
192
198
  * Registers a listener that will be called when subscriptions change.
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.useMemoizedSyncBlockStoreManager = exports.SyncBlockStoreManager = void 0;
8
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
11
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
11
12
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
12
13
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
@@ -20,6 +21,9 @@ var _experienceTracking = require("../utils/experienceTracking");
20
21
  var _utils = require("../utils/utils");
21
22
  var _referenceSyncBlockStoreManager = require("./referenceSyncBlockStoreManager");
22
23
  var _sourceSyncBlockStoreManager = require("./sourceSyncBlockStoreManager");
24
+ 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; } } }; }
25
+ 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; } }
26
+ 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; }
23
27
  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; }
24
28
  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) { (0, _defineProperty2.default)(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; }
25
29
  // A parent store manager responsible for the lifecycle and state management of sync blocks in an editor instance.
@@ -44,49 +48,80 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
44
48
  value: function isSyncBlock(node) {
45
49
  return this.sourceSyncBlockStoreManager.isSourceBlock(node) || this.referenceSyncBlockStoreManager.isReferenceBlock(node);
46
50
  }
51
+ }, {
52
+ key: "getDocumentReferenceIds",
53
+ value: function getDocumentReferenceIds(resourceId, doc) {
54
+ var _this = this;
55
+ if (!doc) {
56
+ return undefined;
57
+ }
58
+ var localIds = new Set();
59
+ doc.descendants(function (node) {
60
+ if (_this.referenceManager.isReferenceBlock(node) && node.attrs.resourceId === resourceId && node.attrs.localId) {
61
+ localIds.add(node.attrs.localId);
62
+ }
63
+ });
64
+ return localIds;
65
+ }
47
66
  }, {
48
67
  key: "fetchReferencesSourceInfo",
49
68
  value: function () {
50
- var _fetchReferencesSourceInfo = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(resourceId, blockInstanceId, isSourceSyncBlock) {
51
- var _this = this;
52
- var _this$fetchReferences, _response$references, _this$fetchReferences3, _response$references2, response, _this$fetchReferences2, sourceInfoPromises, sourceInfos, sourceSyncBlockData, _this$fireAnalyticsEv, _t;
53
- return _regenerator.default.wrap(function (_context2) {
54
- while (1) switch (_context2.prev = _context2.next) {
69
+ var _fetchReferencesSourceInfo = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(resourceId, blockInstanceId, isSourceSyncBlock, doc) {
70
+ var _this2 = this;
71
+ 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;
72
+ return _regenerator.default.wrap(function (_context3) {
73
+ while (1) switch (_context3.prev = _context3.next) {
55
74
  case 0:
56
- _context2.prev = 0;
75
+ _context3.prev = 0;
57
76
  if (this.dataProvider) {
58
- _context2.next = 1;
77
+ _context3.next = 1;
59
78
  break;
60
79
  }
61
80
  throw new Error('Data provider not set');
62
81
  case 1:
63
82
  (_this$fetchReferences = this.fetchReferencesExperience) === null || _this$fetchReferences === void 0 || _this$fetchReferences.start();
64
- _context2.next = 2;
83
+ _context3.next = 2;
65
84
  return this.dataProvider.fetchReferences(resourceId, isSourceSyncBlock);
66
85
  case 2:
67
- response = _context2.sent;
86
+ response = _context3.sent;
68
87
  if (!response.error) {
69
- _context2.next = 3;
88
+ _context3.next = 3;
70
89
  break;
71
90
  }
72
91
  (_this$fetchReferences2 = this.fetchReferencesExperience) === null || _this$fetchReferences2 === void 0 || _this$fetchReferences2.failure({
73
92
  reason: response.error
74
93
  });
75
- return _context2.abrupt("return", {
94
+ return _context3.abrupt("return", {
76
95
  error: response.error
77
96
  });
78
97
  case 3:
79
- if (!(!response.references || ((_response$references = response.references) === null || _response$references === void 0 ? void 0 : _response$references.length) === 0)) {
80
- _context2.next = 4;
98
+ patchEnabled = (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_blocks_patch_12');
99
+ referenceResourceId = patchEnabled && isSourceSyncBlock ? this.referenceSyncBlockStoreManager.generateResourceIdForReference(resourceId) : resourceId;
100
+ documentIds = patchEnabled ? this.getDocumentReferenceIds(referenceResourceId, doc) : undefined;
101
+ localIds = patchEnabled ? documentIds ? (0, _toConsumableArray2.default)(documentIds) : this.referenceSyncBlockStoreManager.getSubscribedLocalIds(referenceResourceId) : []; // Saved references on this document can already have been removed in the editor.
102
+ references = ((_response$references = response.references) !== null && _response$references !== void 0 ? _response$references : []).filter(function (reference) {
103
+ return documentIds === undefined || !reference.onSameDocument || Boolean(reference.blockInstanceId && documentIds.has(reference.blockInstanceId));
104
+ });
105
+ if (!(references.length === 0 && localIds.length === 0)) {
106
+ _context3.next = 5;
107
+ break;
108
+ }
109
+ if (!(documentIds !== undefined)) {
110
+ _context3.next = 4;
81
111
  break;
82
112
  }
83
- return _context2.abrupt("return", this.getUnregisteredReferences(resourceId, blockInstanceId, isSourceSyncBlock));
84
- case 4:
85
113
  (_this$fetchReferences3 = this.fetchReferencesExperience) === null || _this$fetchReferences3 === void 0 || _this$fetchReferences3.success();
86
- sourceInfoPromises = ((_response$references2 = response.references) !== null && _response$references2 !== void 0 ? _response$references2 : []).map( /*#__PURE__*/function () {
114
+ return _context3.abrupt("return", {
115
+ references: []
116
+ });
117
+ case 4:
118
+ return _context3.abrupt("return", this.getUnregisteredReferences(resourceId, blockInstanceId, isSourceSyncBlock));
119
+ case 5:
120
+ (_this$fetchReferences4 = this.fetchReferencesExperience) === null || _this$fetchReferences4 === void 0 || _this$fetchReferences4.success();
121
+ sourceInfoPromises = references.map( /*#__PURE__*/function () {
87
122
  var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(reference) {
88
- var _this$fetchSourceInfo, _this$dataProvider, _this$fetchSourceInfo3;
89
- var sourceInfo, _this$fetchSourceInfo2;
123
+ var _this2$fetchSourceInf, _this2$dataProvider, _this2$fetchSourceInf3;
124
+ var sourceInfo, _this2$fetchSourceInf2;
90
125
  return _regenerator.default.wrap(function (_context) {
91
126
  while (1) switch (_context.prev = _context.next) {
92
127
  case 0:
@@ -94,23 +129,23 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
94
129
  _context.next = 1;
95
130
  break;
96
131
  }
97
- return _context.abrupt("return", _this.fetchRestrictedReferenceInfo(reference.documentAri));
132
+ return _context.abrupt("return", _this2.fetchRestrictedReferenceInfo(reference.documentAri));
98
133
  case 1:
99
- (_this$fetchSourceInfo = _this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo === void 0 || _this$fetchSourceInfo.start();
134
+ (_this2$fetchSourceInf = _this2.fetchSourceInfoExperience) === null || _this2$fetchSourceInf === void 0 || _this2$fetchSourceInf.start();
100
135
  _context.next = 2;
101
- return (_this$dataProvider = _this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.fetchSyncBlockSourceInfo(reference.blockInstanceId || '', reference.documentAri, (0, _ari.getProductFromSourceAri)(reference.documentAri), reference.hasAccess);
136
+ return (_this2$dataProvider = _this2.dataProvider) === null || _this2$dataProvider === void 0 ? void 0 : _this2$dataProvider.fetchSyncBlockSourceInfo(reference.blockInstanceId || '', reference.documentAri, (0, _ari.getProductFromSourceAri)(reference.documentAri), reference.hasAccess);
102
137
  case 2:
103
138
  sourceInfo = _context.sent;
104
139
  if (sourceInfo) {
105
140
  _context.next = 3;
106
141
  break;
107
142
  }
108
- (_this$fetchSourceInfo2 = _this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo2 === void 0 || _this$fetchSourceInfo2.failure({
143
+ (_this2$fetchSourceInf2 = _this2.fetchSourceInfoExperience) === null || _this2$fetchSourceInf2 === void 0 || _this2$fetchSourceInf2.failure({
109
144
  reason: "no source info returned for ari: ".concat(reference.documentAri)
110
145
  });
111
146
  return _context.abrupt("return", undefined);
112
147
  case 3:
113
- (_this$fetchSourceInfo3 = _this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo3 === void 0 || _this$fetchSourceInfo3.success();
148
+ (_this2$fetchSourceInf3 = _this2.fetchSourceInfoExperience) === null || _this2$fetchSourceInf3 === void 0 || _this2$fetchSourceInf3.success();
114
149
  return _context.abrupt("return", _objectSpread(_objectSpread(_objectSpread({}, sourceInfo), {}, {
115
150
  onSameDocument: reference.onSameDocument
116
151
  }, reference.locationScope !== undefined && {
@@ -125,18 +160,18 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
125
160
  }
126
161
  }, _callee);
127
162
  }));
128
- return function (_x4) {
163
+ return function (_x5) {
129
164
  return _ref.apply(this, arguments);
130
165
  };
131
166
  }());
132
- _context2.next = 5;
167
+ _context3.next = 6;
133
168
  return Promise.all(sourceInfoPromises);
134
- case 5:
135
- sourceInfos = _context2.sent;
136
- _context2.next = 6;
137
- return isSourceSyncBlock ? this.sourceSyncBlockStoreManager.getSyncBlockSourceInfo(blockInstanceId) : this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfo(resourceId);
138
169
  case 6:
139
- sourceSyncBlockData = _context2.sent;
170
+ sourceInfos = _context3.sent;
171
+ _context3.next = 7;
172
+ return isSourceSyncBlock ? this.sourceSyncBlockStoreManager.getSyncBlockSourceInfo(blockInstanceId) : this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfo(resourceId);
173
+ case 7:
174
+ sourceSyncBlockData = _context3.sent;
140
175
  if (sourceSyncBlockData) {
141
176
  sourceInfos.push(_objectSpread(_objectSpread({}, sourceSyncBlockData), {}, {
142
177
  onSameDocument: Boolean(sourceSyncBlockData === null || sourceSyncBlockData === void 0 ? void 0 : sourceSyncBlockData.onSameDocument),
@@ -145,26 +180,74 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
145
180
  productType: sourceSyncBlockData === null || sourceSyncBlockData === void 0 ? void 0 : sourceSyncBlockData.productType
146
181
  }));
147
182
  }
148
- return _context2.abrupt("return", {
183
+
184
+ // Only instances in this editor belong to its unsaved document. A matching
185
+ // local ID on another document must not hide an unsaved copy here.
186
+ registeredLocalIds = new Set();
187
+ _iterator = _createForOfIteratorHelper(references);
188
+ try {
189
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
190
+ reference = _step.value;
191
+ if (reference.onSameDocument && reference.blockInstanceId) {
192
+ registeredLocalIds.add(reference.blockInstanceId);
193
+ }
194
+ }
195
+ } catch (err) {
196
+ _iterator.e(err);
197
+ } finally {
198
+ _iterator.f();
199
+ }
200
+ _context3.next = 8;
201
+ return Promise.all(localIds.filter(function (localId) {
202
+ return !registeredLocalIds.has(localId);
203
+ }).map( /*#__PURE__*/function () {
204
+ var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(localId) {
205
+ var sourceInfo;
206
+ return _regenerator.default.wrap(function (_context2) {
207
+ while (1) switch (_context2.prev = _context2.next) {
208
+ case 0:
209
+ _context2.next = 1;
210
+ return _this2.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfoByLocalId(localId);
211
+ case 1:
212
+ sourceInfo = _context2.sent;
213
+ return _context2.abrupt("return", sourceInfo ? _objectSpread(_objectSpread({}, sourceInfo), {}, {
214
+ onSameDocument: true,
215
+ hasAccess: true,
216
+ isSource: false
217
+ }) : undefined);
218
+ case 2:
219
+ case "end":
220
+ return _context2.stop();
221
+ }
222
+ }, _callee2);
223
+ }));
224
+ return function (_x6) {
225
+ return _ref2.apply(this, arguments);
226
+ };
227
+ }()));
228
+ case 8:
229
+ localSourceInfos = _context3.sent;
230
+ sourceInfos.push.apply(sourceInfos, (0, _toConsumableArray2.default)(localSourceInfos));
231
+ return _context3.abrupt("return", {
149
232
  references: sourceInfos
150
233
  });
151
- case 7:
152
- _context2.prev = 7;
153
- _t = _context2["catch"](0);
234
+ case 9:
235
+ _context3.prev = 9;
236
+ _t = _context3["catch"](0);
154
237
  (0, _error.logException)(_t, {
155
238
  location: 'editor-synced-block-provider/syncBlockStoreManager'
156
239
  });
157
240
  (_this$fireAnalyticsEv = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv === void 0 || _this$fireAnalyticsEv.call(this, (0, _errorHandling.fetchReferencesErrorPayload)(_t.message, resourceId, (0, _utils.getSourceProductFromResourceIdSafe)(resourceId)));
158
- return _context2.abrupt("return", {
241
+ return _context3.abrupt("return", {
159
242
  error: _types.SyncBlockError.Errored
160
243
  });
161
- case 8:
244
+ case 10:
162
245
  case "end":
163
- return _context2.stop();
246
+ return _context3.stop();
164
247
  }
165
- }, _callee2, this, [[0, 7]]);
248
+ }, _callee3, this, [[0, 9]]);
166
249
  }));
167
- function fetchReferencesSourceInfo(_x, _x2, _x3) {
250
+ function fetchReferencesSourceInfo(_x, _x2, _x3, _x4) {
168
251
  return _fetchReferencesSourceInfo.apply(this, arguments);
169
252
  }
170
253
  return fetchReferencesSourceInfo;
@@ -191,13 +274,13 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
191
274
  }, {
192
275
  key: "destroy",
193
276
  value: function destroy() {
194
- var _this$fetchReferences4, _this$fetchSourceInfo4;
277
+ var _this$fetchReferences5, _this$fetchSourceInfo;
195
278
  this.referenceSyncBlockStoreManager.destroy();
196
279
  this.sourceSyncBlockStoreManager.destroy();
197
- (_this$fetchReferences4 = this.fetchReferencesExperience) === null || _this$fetchReferences4 === void 0 || _this$fetchReferences4.abort({
280
+ (_this$fetchReferences5 = this.fetchReferencesExperience) === null || _this$fetchReferences5 === void 0 || _this$fetchReferences5.abort({
198
281
  reason: 'editorDestroyed'
199
282
  });
200
- (_this$fetchSourceInfo4 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo4 === void 0 || _this$fetchSourceInfo4.abort({
283
+ (_this$fetchSourceInfo = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo === void 0 || _this$fetchSourceInfo.abort({
201
284
  reason: 'editorDestroyed'
202
285
  });
203
286
  }
@@ -209,41 +292,41 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
209
292
  }, {
210
293
  key: "fetchRestrictedReferenceInfo",
211
294
  value: (function () {
212
- var _fetchRestrictedReferenceInfo = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(documentAri) {
213
- var _this$fetchSourceInfo5;
214
- var productType, url, _this$dataProvider2, _this$fetchSourceInfo6, sourceInfo, _this$fetchSourceInfo7, _t2;
215
- return _regenerator.default.wrap(function (_context3) {
216
- while (1) switch (_context3.prev = _context3.next) {
295
+ var _fetchRestrictedReferenceInfo = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(documentAri) {
296
+ var _this$fetchSourceInfo2;
297
+ var productType, url, _this$dataProvider, _this$fetchSourceInfo3, sourceInfo, _this$fetchSourceInfo4, _t2;
298
+ return _regenerator.default.wrap(function (_context4) {
299
+ while (1) switch (_context4.prev = _context4.next) {
217
300
  case 0:
218
301
  if (documentAri) {
219
- _context3.next = 1;
302
+ _context4.next = 1;
220
303
  break;
221
304
  }
222
- return _context3.abrupt("return", {
305
+ return _context4.abrupt("return", {
223
306
  sourceAri: '',
224
307
  hasAccess: false,
225
308
  onSameDocument: false
226
309
  });
227
310
  case 1:
228
311
  productType = (0, _ari.getProductFromSourceAri)(documentAri);
229
- (_this$fetchSourceInfo5 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo5 === void 0 || _this$fetchSourceInfo5.start();
230
- _context3.prev = 2;
231
- _context3.next = 3;
232
- return (_this$dataProvider2 = this.dataProvider) === null || _this$dataProvider2 === void 0 ? void 0 : _this$dataProvider2.fetchSyncBlockSourceInfo(undefined, documentAri, productType, false);
312
+ (_this$fetchSourceInfo2 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo2 === void 0 || _this$fetchSourceInfo2.start();
313
+ _context4.prev = 2;
314
+ _context4.next = 3;
315
+ return (_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : _this$dataProvider.fetchSyncBlockSourceInfo(undefined, documentAri, productType, false);
233
316
  case 3:
234
- sourceInfo = _context3.sent;
317
+ sourceInfo = _context4.sent;
235
318
  url = sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.url;
236
- (_this$fetchSourceInfo6 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo6 === void 0 || _this$fetchSourceInfo6.success();
237
- _context3.next = 5;
319
+ (_this$fetchSourceInfo3 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo3 === void 0 || _this$fetchSourceInfo3.success();
320
+ _context4.next = 5;
238
321
  break;
239
322
  case 4:
240
- _context3.prev = 4;
241
- _t2 = _context3["catch"](2);
242
- (_this$fetchSourceInfo7 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo7 === void 0 || _this$fetchSourceInfo7.failure({
323
+ _context4.prev = 4;
324
+ _t2 = _context4["catch"](2);
325
+ (_this$fetchSourceInfo4 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo4 === void 0 || _this$fetchSourceInfo4.failure({
243
326
  reason: _t2.message
244
327
  });
245
328
  case 5:
246
- return _context3.abrupt("return", {
329
+ return _context4.abrupt("return", {
247
330
  sourceAri: documentAri,
248
331
  productType: productType,
249
332
  url: url,
@@ -252,11 +335,11 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
252
335
  });
253
336
  case 6:
254
337
  case "end":
255
- return _context3.stop();
338
+ return _context4.stop();
256
339
  }
257
- }, _callee3, this, [[2, 4]]);
340
+ }, _callee4, this, [[2, 4]]);
258
341
  }));
259
- function fetchRestrictedReferenceInfo(_x5) {
342
+ function fetchRestrictedReferenceInfo(_x7) {
260
343
  return _fetchRestrictedReferenceInfo.apply(this, arguments);
261
344
  }
262
345
  return fetchRestrictedReferenceInfo;
@@ -264,14 +347,14 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
264
347
  }, {
265
348
  key: "getUnregisteredReferences",
266
349
  value: function () {
267
- var _getUnregisteredReferences = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(resourceId, blockInstanceId, isSourceSyncBlock) {
268
- var _this$fetchReferences8;
269
- var _this$fetchReferences6, referenceResourceId, hasUnregisteredReferenceOnPage, _this$fetchReferences5, _sourceSyncBlockData, _references, sourceSyncBlockReference, referenceSyncBlockReference, references, sourceSyncBlockData, currentPageData, _this$fetchReferences7;
270
- return _regenerator.default.wrap(function (_context4) {
271
- while (1) switch (_context4.prev = _context4.next) {
350
+ var _getUnregisteredReferences = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(resourceId, blockInstanceId, isSourceSyncBlock) {
351
+ var _this$fetchReferences9;
352
+ var _this$fetchReferences7, referenceResourceId, hasUnregisteredReferenceOnPage, _this$fetchReferences6, _sourceSyncBlockData, _references, sourceSyncBlockReference, referenceSyncBlockReference, references, sourceSyncBlockData, currentPageData, _this$fetchReferences8;
353
+ return _regenerator.default.wrap(function (_context5) {
354
+ while (1) switch (_context5.prev = _context5.next) {
272
355
  case 0:
273
356
  if (!isSourceSyncBlock) {
274
- _context4.next = 3;
357
+ _context5.next = 3;
275
358
  break;
276
359
  }
277
360
  // Verify that a reference sync block for this specific source actually
@@ -280,13 +363,13 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
280
363
  referenceResourceId = this.referenceSyncBlockStoreManager.generateResourceIdForReference(resourceId);
281
364
  hasUnregisteredReferenceOnPage = this.referenceSyncBlockStoreManager.getSubscribedResourceIds().includes(referenceResourceId);
282
365
  if (!hasUnregisteredReferenceOnPage) {
283
- _context4.next = 2;
366
+ _context5.next = 2;
284
367
  break;
285
368
  }
286
- _context4.next = 1;
369
+ _context5.next = 1;
287
370
  return this.sourceSyncBlockStoreManager.getSyncBlockSourceInfo(blockInstanceId);
288
371
  case 1:
289
- _sourceSyncBlockData = _context4.sent;
372
+ _sourceSyncBlockData = _context5.sent;
290
373
  _references = [];
291
374
  if (_sourceSyncBlockData) {
292
375
  sourceSyncBlockReference = _objectSpread(_objectSpread({}, _sourceSyncBlockData), {}, {
@@ -301,14 +384,14 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
301
384
  });
302
385
  _references.push(sourceSyncBlockReference, referenceSyncBlockReference);
303
386
  }
304
- (_this$fetchReferences5 = this.fetchReferencesExperience) === null || _this$fetchReferences5 === void 0 || _this$fetchReferences5.success();
305
- return _context4.abrupt("return", {
387
+ (_this$fetchReferences6 = this.fetchReferencesExperience) === null || _this$fetchReferences6 === void 0 || _this$fetchReferences6.success();
388
+ return _context5.abrupt("return", {
306
389
  references: _references
307
390
  });
308
391
  case 2:
309
392
  // No remote or local reference exists — show info text with link to doco on how to use Synced Blocks
310
- (_this$fetchReferences6 = this.fetchReferencesExperience) === null || _this$fetchReferences6 === void 0 || _this$fetchReferences6.success();
311
- return _context4.abrupt("return", {
393
+ (_this$fetchReferences7 = this.fetchReferencesExperience) === null || _this$fetchReferences7 === void 0 || _this$fetchReferences7.success();
394
+ return _context5.abrupt("return", {
312
395
  references: []
313
396
  });
314
397
  case 3:
@@ -316,10 +399,10 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
316
399
  // still show the source and the current page itself since they are known
317
400
  // but not saved yet.
318
401
  references = [];
319
- _context4.next = 4;
402
+ _context5.next = 4;
320
403
  return this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfo(resourceId);
321
404
  case 4:
322
- sourceSyncBlockData = _context4.sent;
405
+ sourceSyncBlockData = _context5.sent;
323
406
  if (sourceSyncBlockData) {
324
407
  references.push(_objectSpread(_objectSpread({}, sourceSyncBlockData), {}, {
325
408
  onSameDocument: Boolean(sourceSyncBlockData === null || sourceSyncBlockData === void 0 ? void 0 : sourceSyncBlockData.onSameDocument),
@@ -327,10 +410,10 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
327
410
  isSource: true
328
411
  }));
329
412
  }
330
- _context4.next = 5;
413
+ _context5.next = 5;
331
414
  return this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfoByLocalId(blockInstanceId);
332
415
  case 5:
333
- currentPageData = _context4.sent;
416
+ currentPageData = _context5.sent;
334
417
  if (currentPageData) {
335
418
  references.push(_objectSpread(_objectSpread({}, currentPageData), {}, {
336
419
  onSameDocument: true,
@@ -339,27 +422,27 @@ var SyncBlockStoreManager = exports.SyncBlockStoreManager = /*#__PURE__*/functio
339
422
  }));
340
423
  }
341
424
  if (!(references.length === 0)) {
342
- _context4.next = 6;
425
+ _context5.next = 6;
343
426
  break;
344
427
  }
345
- (_this$fetchReferences7 = this.fetchReferencesExperience) === null || _this$fetchReferences7 === void 0 || _this$fetchReferences7.failure({
428
+ (_this$fetchReferences8 = this.fetchReferencesExperience) === null || _this$fetchReferences8 === void 0 || _this$fetchReferences8.failure({
346
429
  reason: 'No references found for reference synced block'
347
430
  });
348
- return _context4.abrupt("return", {
431
+ return _context5.abrupt("return", {
349
432
  error: _types.SyncBlockError.Errored
350
433
  });
351
434
  case 6:
352
- (_this$fetchReferences8 = this.fetchReferencesExperience) === null || _this$fetchReferences8 === void 0 || _this$fetchReferences8.success();
353
- return _context4.abrupt("return", {
435
+ (_this$fetchReferences9 = this.fetchReferencesExperience) === null || _this$fetchReferences9 === void 0 || _this$fetchReferences9.success();
436
+ return _context5.abrupt("return", {
354
437
  references: references
355
438
  });
356
439
  case 7:
357
440
  case "end":
358
- return _context4.stop();
441
+ return _context5.stop();
359
442
  }
360
- }, _callee4, this);
443
+ }, _callee5, this);
361
444
  }));
362
- function getUnregisteredReferences(_x6, _x7, _x8) {
445
+ function getUnregisteredReferences(_x8, _x9, _x0) {
363
446
  return _getUnregisteredReferences.apply(this, arguments);
364
447
  }
365
448
  return getUnregisteredReferences;
@@ -127,6 +127,10 @@ export class ReferenceSyncBlockStoreManager {
127
127
  getSubscribedResourceIds() {
128
128
  return this._subscriptionManager.getSubscribedResourceIds();
129
129
  }
130
+ getSubscribedLocalIds(resourceId) {
131
+ var _this$_subscriptionMa;
132
+ return Object.keys((_this$_subscriptionMa = this._subscriptionManager.getSubscriptions().get(resourceId)) !== null && _this$_subscriptionMa !== void 0 ? _this$_subscriptionMa : {});
133
+ }
130
134
 
131
135
  /**
132
136
  * Registers a listener that will be called when subscriptions change.
@@ -29,9 +29,21 @@ export class SyncBlockStoreManager {
29
29
  isSyncBlock(node) {
30
30
  return this.sourceSyncBlockStoreManager.isSourceBlock(node) || this.referenceSyncBlockStoreManager.isReferenceBlock(node);
31
31
  }
32
- async fetchReferencesSourceInfo(resourceId, blockInstanceId, isSourceSyncBlock) {
32
+ getDocumentReferenceIds(resourceId, doc) {
33
+ if (!doc) {
34
+ return undefined;
35
+ }
36
+ const localIds = new Set();
37
+ doc.descendants(node => {
38
+ if (this.referenceManager.isReferenceBlock(node) && node.attrs.resourceId === resourceId && node.attrs.localId) {
39
+ localIds.add(node.attrs.localId);
40
+ }
41
+ });
42
+ return localIds;
43
+ }
44
+ async fetchReferencesSourceInfo(resourceId, blockInstanceId, isSourceSyncBlock, doc) {
33
45
  try {
34
- var _this$fetchReferences, _response$references, _this$fetchReferences3, _response$references2;
46
+ var _this$fetchReferences, _response$references, _this$fetchReferences4;
35
47
  if (!this.dataProvider) {
36
48
  throw new Error('Data provider not set');
37
49
  }
@@ -46,11 +58,24 @@ export class SyncBlockStoreManager {
46
58
  error: response.error
47
59
  };
48
60
  }
49
- if (!response.references || ((_response$references = response.references) === null || _response$references === void 0 ? void 0 : _response$references.length) === 0) {
61
+ const patchEnabled = isExperimentEnabled('platform_editor_blocks_patch_12');
62
+ const referenceResourceId = patchEnabled && isSourceSyncBlock ? this.referenceSyncBlockStoreManager.generateResourceIdForReference(resourceId) : resourceId;
63
+ const documentIds = patchEnabled ? this.getDocumentReferenceIds(referenceResourceId, doc) : undefined;
64
+ const localIds = patchEnabled ? documentIds ? [...documentIds] : this.referenceSyncBlockStoreManager.getSubscribedLocalIds(referenceResourceId) : [];
65
+ // Saved references on this document can already have been removed in the editor.
66
+ const references = ((_response$references = response.references) !== null && _response$references !== void 0 ? _response$references : []).filter(reference => documentIds === undefined || !reference.onSameDocument || Boolean(reference.blockInstanceId && documentIds.has(reference.blockInstanceId)));
67
+ if (references.length === 0 && localIds.length === 0) {
68
+ if (documentIds !== undefined) {
69
+ var _this$fetchReferences3;
70
+ (_this$fetchReferences3 = this.fetchReferencesExperience) === null || _this$fetchReferences3 === void 0 ? void 0 : _this$fetchReferences3.success();
71
+ return {
72
+ references: []
73
+ };
74
+ }
50
75
  return this.getUnregisteredReferences(resourceId, blockInstanceId, isSourceSyncBlock);
51
76
  }
52
- (_this$fetchReferences3 = this.fetchReferencesExperience) === null || _this$fetchReferences3 === void 0 ? void 0 : _this$fetchReferences3.success();
53
- const sourceInfoPromises = ((_response$references2 = response.references) !== null && _response$references2 !== void 0 ? _response$references2 : []).map(async reference => {
77
+ (_this$fetchReferences4 = this.fetchReferencesExperience) === null || _this$fetchReferences4 === void 0 ? void 0 : _this$fetchReferences4.success();
78
+ const sourceInfoPromises = references.map(async reference => {
54
79
  var _this$fetchSourceInfo, _this$dataProvider, _this$fetchSourceInfo3;
55
80
  if (!reference.hasAccess && isExperimentEnabled('platform_editor_blocks_patch_11')) {
56
81
  return this.fetchRestrictedReferenceInfo(reference.documentAri);
@@ -86,6 +111,25 @@ export class SyncBlockStoreManager {
86
111
  productType: sourceSyncBlockData === null || sourceSyncBlockData === void 0 ? void 0 : sourceSyncBlockData.productType
87
112
  });
88
113
  }
114
+
115
+ // Only instances in this editor belong to its unsaved document. A matching
116
+ // local ID on another document must not hide an unsaved copy here.
117
+ const registeredLocalIds = new Set();
118
+ for (const reference of references) {
119
+ if (reference.onSameDocument && reference.blockInstanceId) {
120
+ registeredLocalIds.add(reference.blockInstanceId);
121
+ }
122
+ }
123
+ const localSourceInfos = await Promise.all(localIds.filter(localId => !registeredLocalIds.has(localId)).map(async localId => {
124
+ const sourceInfo = await this.referenceSyncBlockStoreManager.fetchSyncBlockSourceInfoByLocalId(localId);
125
+ return sourceInfo ? {
126
+ ...sourceInfo,
127
+ onSameDocument: true,
128
+ hasAccess: true,
129
+ isSource: false
130
+ } : undefined;
131
+ }));
132
+ sourceInfos.push(...localSourceInfos);
89
133
  return {
90
134
  references: sourceInfos
91
135
  };
@@ -114,10 +158,10 @@ export class SyncBlockStoreManager {
114
158
  return this.sourceSyncBlockStoreManager;
115
159
  }
116
160
  destroy() {
117
- var _this$fetchReferences4, _this$fetchSourceInfo4;
161
+ var _this$fetchReferences5, _this$fetchSourceInfo4;
118
162
  this.referenceSyncBlockStoreManager.destroy();
119
163
  this.sourceSyncBlockStoreManager.destroy();
120
- (_this$fetchReferences4 = this.fetchReferencesExperience) === null || _this$fetchReferences4 === void 0 ? void 0 : _this$fetchReferences4.abort({
164
+ (_this$fetchReferences5 = this.fetchReferencesExperience) === null || _this$fetchReferences5 === void 0 ? void 0 : _this$fetchReferences5.abort({
121
165
  reason: 'editorDestroyed'
122
166
  });
123
167
  (_this$fetchSourceInfo4 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo4 === void 0 ? void 0 : _this$fetchSourceInfo4.abort({
@@ -161,17 +205,17 @@ export class SyncBlockStoreManager {
161
205
  };
162
206
  }
163
207
  async getUnregisteredReferences(resourceId, blockInstanceId, isSourceSyncBlock) {
164
- var _this$fetchReferences8;
208
+ var _this$fetchReferences9;
165
209
  // No reference found
166
210
  if (isSourceSyncBlock) {
167
- var _this$fetchReferences6;
211
+ var _this$fetchReferences7;
168
212
  // Verify that a reference sync block for this specific source actually
169
213
  // exists on the current page by checking if the reference manager has
170
214
  // an active subscription for the derived reference resourceId.
171
215
  const referenceResourceId = this.referenceSyncBlockStoreManager.generateResourceIdForReference(resourceId);
172
216
  const hasUnregisteredReferenceOnPage = this.referenceSyncBlockStoreManager.getSubscribedResourceIds().includes(referenceResourceId);
173
217
  if (hasUnregisteredReferenceOnPage) {
174
- var _this$fetchReferences5;
218
+ var _this$fetchReferences6;
175
219
  // This is current page data. It is the same for data for source and reference
176
220
  const sourceSyncBlockData = await this.sourceSyncBlockStoreManager.getSyncBlockSourceInfo(blockInstanceId);
177
221
  const references = [];
@@ -190,14 +234,14 @@ export class SyncBlockStoreManager {
190
234
  };
191
235
  references.push(sourceSyncBlockReference, referenceSyncBlockReference);
192
236
  }
193
- (_this$fetchReferences5 = this.fetchReferencesExperience) === null || _this$fetchReferences5 === void 0 ? void 0 : _this$fetchReferences5.success();
237
+ (_this$fetchReferences6 = this.fetchReferencesExperience) === null || _this$fetchReferences6 === void 0 ? void 0 : _this$fetchReferences6.success();
194
238
  return {
195
239
  references
196
240
  };
197
241
  }
198
242
 
199
243
  // No remote or local reference exists — show info text with link to doco on how to use Synced Blocks
200
- (_this$fetchReferences6 = this.fetchReferencesExperience) === null || _this$fetchReferences6 === void 0 ? void 0 : _this$fetchReferences6.success();
244
+ (_this$fetchReferences7 = this.fetchReferencesExperience) === null || _this$fetchReferences7 === void 0 ? void 0 : _this$fetchReferences7.success();
201
245
  return {
202
246
  references: []
203
247
  };
@@ -226,15 +270,15 @@ export class SyncBlockStoreManager {
226
270
  });
227
271
  }
228
272
  if (references.length === 0) {
229
- var _this$fetchReferences7;
230
- (_this$fetchReferences7 = this.fetchReferencesExperience) === null || _this$fetchReferences7 === void 0 ? void 0 : _this$fetchReferences7.failure({
273
+ var _this$fetchReferences8;
274
+ (_this$fetchReferences8 = this.fetchReferencesExperience) === null || _this$fetchReferences8 === void 0 ? void 0 : _this$fetchReferences8.failure({
231
275
  reason: 'No references found for reference synced block'
232
276
  });
233
277
  return {
234
278
  error: SyncBlockError.Errored
235
279
  };
236
280
  }
237
- (_this$fetchReferences8 = this.fetchReferencesExperience) === null || _this$fetchReferences8 === void 0 ? void 0 : _this$fetchReferences8.success();
281
+ (_this$fetchReferences9 = this.fetchReferencesExperience) === null || _this$fetchReferences9 === void 0 ? void 0 : _this$fetchReferences9.success();
238
282
  return {
239
283
  references
240
284
  };
@@ -180,6 +180,12 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
180
180
  value: function getSubscribedResourceIds() {
181
181
  return this._subscriptionManager.getSubscribedResourceIds();
182
182
  }
183
+ }, {
184
+ key: "getSubscribedLocalIds",
185
+ value: function getSubscribedLocalIds(resourceId) {
186
+ var _this$_subscriptionMa;
187
+ return Object.keys((_this$_subscriptionMa = this._subscriptionManager.getSubscriptions().get(resourceId)) !== null && _this$_subscriptionMa !== void 0 ? _this$_subscriptionMa : {});
188
+ }
183
189
 
184
190
  /**
185
191
  * Registers a listener that will be called when subscriptions change.
@@ -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;
@@ -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
@@ -23,7 +23,7 @@
23
23
  "@atlaskit/node-data-provider": "^27.0.0",
24
24
  "@atlaskit/platform-feature-experiments": "^0.3.0",
25
25
  "@atlaskit/platform-feature-flags": "^2.2.0",
26
- "@atlaskit/tmp-editor-statsig": "^232.0.0",
26
+ "@atlaskit/tmp-editor-statsig": "^234.0.0",
27
27
  "@babel/runtime": "^7.0.0",
28
28
  "@compiled/react": "^1.0.2",
29
29
  "bind-event-listener": "^3.0.0",
@@ -33,7 +33,7 @@
33
33
  "uuid": "^11.1.1"
34
34
  },
35
35
  "peerDependencies": {
36
- "@atlaskit/editor-common": "^130.4.0",
36
+ "@atlaskit/editor-common": "^130.5.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.6",
45
+ "version": "22.1.2",
46
46
  "description": "Synced Block Provider for @atlaskit/editor-plugin-synced-block",
47
47
  "author": "Atlassian Pty Ltd",
48
48
  "license": "Apache-2.0",